Image functions.
Constantes
Text ImgTagFunciones
Set ImgGetSet(Text htmCod)Text ImgNormalize(Text imgCod)Text ImgGetSrc(Text imgCod)Text ImgGetAlt(Text imgCod)Text ImgGetTit(Text imgCod)Text Img2Htm(Text imgSrc, Text imgAlt, Text imgTit, Text imgCla, Text imgDef)Text Img2Div(Text imgSrc, Text imgAlt, Text imgTit, Text imgLnk, Text imgLst, Text imgCla, Text imgDef)Text ImgMap(Set ctrPdb, Text txtPat, Text namCla, Text txtDef)//////////////////////////////////////////////////////////////////////////////
Text ImgTag = "<img ";
//////////////////////////////////////////////////////////////////////////////
PutDescription("Tag inicial para imagenes.", ImgTag);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set ImgGetSet(Text htmCod)
//////////////////////////////////////////////////////////////////////////////
{
Text imgTxt = Compact(TxtInside2TagPlus(htmCod, ImgTag, ">"));
If(imgTxt == "", Empty,
{
Text imgRep = Replace(imgTxt, "><", ">"+Char(7)+"<");
Tokenizer(imgRep, Char(7))
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el conjunto de imagenes de una pieza de codigo Html.",
ImgGetSet);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgNormalize(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{
Text imgCmp = Compact(imgCod);
ReplaceTable(imgCmp,
[[
[["= ", "="]],
[[" =", "="]],
[[".'", "'"]], // Elimina los puntos finales
[[Char(34), "'"]]
]])
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de una imagen normalizado.",
ImgNormalize);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgGetSrc(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{ TxtBetween2Tag(ImgNormalize(imgCod), "src='", "'", TRUE) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna de un codigo Html de una imagen la url de la imagen.",
ImgGetSrc);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgGetAlt(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{ TxtBetween2Tag(ImgNormalize(imgCod), "alt='", "'", TRUE) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna de un codigo Html de una imagen el texto alt de la imagen.",
ImgGetAlt);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgGetTit(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{ TxtBetween2Tag(ImgNormalize(imgCod), "title='", "'", TRUE) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna de un codigo Html de una imagen el texto title de la imagen.",
ImgGetTit);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Img2Htm(Text imgSrc, // Image path
Text imgAlt, // Alternate text, mandatory
Text imgTit, // Image title
Text imgCla, // Image class
Text imgDef) // Para cuando no hay textos
//////////////////////////////////////////////////////////////////////////////
{
Text htmSrc = " src="+Q(imgSrc);
Text htmCla = " class="+Q(imgCla);
Text htmAlt = If(imgAlt!="", " alt="+Q(imgAlt), // Hay alt
If(imgTit!="", " alt="+Q(imgTit), // Sin alt pero si title
" alt="+Q(imgDef))); // Sin nada
Text htmTit = If(imgTit!="", " title="+Q(imgTit), // Hay title
If(imgAlt!="", " title="+Q(imgAlt), // Sin title pero si alt
" title="+Q(imgDef))); // Sin nada
Text htmImg = "\n <img" + htmSrc +
"\n " + htmCla +
"\n " + htmAlt +
"\n " + htmTit + " />";
htmImg
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de una imagen con sus atributos completos rellenando
aquellos que faltan.",
Img2Htm);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Img2Div(Text imgSrc, // Image path
Text imgAlt, // Alternate text, mandatory
Text imgTit, // Image title
Text imgLnk, // Main link
Text imgLst, // List of links
Text imgCla, // Image class
Text imgDef) // Para cuando no hay textos
//////////////////////////////////////////////////////////////////////////////
{
Text htmImg = Img2Htm(imgSrc, imgAlt, imgTit, imgCla, imgDef);
Text htmTxt = Case
(
And(imgAlt != "", imgTit == ""), imgAlt,
And(imgAlt == "", imgTit != ""), imgTit,
And(imgAlt == "", imgTit == ""), imgDef,
imgAlt == imgTit, imgAlt,
TRUE, imgTit+": "+imgAlt
)+". ";
Text htmDes = "<p>"+htmTxt+imgLst+"</p>";
"\n<div class="+Q(imgCla)+">" +
"\n " + imgLnk + htmImg + "</a>" +
"\n " + htmDes +
"\n</div><div style="+Q("clear:both")+"></div>\n"
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de una imagen con sus atributos completos rellenando
aquellos que faltan y todo dentro de una estructura Html div.",
Img2Div);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgMap(Set ctrPdb, // Set of post from a post database
Text txtPat, // Text pattern for seleccion in alts and title
Text namCla, // Name for image class
Text txtDef) // Para cuando no hay textos
//////////////////////////////////////////////////////////////////////////////
{
Set imgPdb = EvalSet(ctrPdb, Set(Set objPst)
{// Si se crean imágenes dinámicas no las ve, sería recursivo en este post
Set imgSel = ImgGetSet(objPst->pstHtm);
EvalSet(imgSel, Set(Text imgCod)
{
Text imgSrc = ImgGetSrc(imgCod);
Text imgAlt = ImgGetAlt(imgCod);
Text imgTit = ImgGetTit(imgCod);
Text imgLnk = PhtLinkPost(objPst);
// Text WriteLn(imgSrc+"\n"+imgAlt+"\n"+imgTit+"\n"+imgLnk+"\n");
SetOfText(imgSrc, imgAlt, imgTit, imgLnk)
})
});
Set imgGrp = BinGroup("<<", imgPdb);
Text lowPat = Compact(ToLower(txtPat));
Set imgSel = If(lowPat == "", imgGrp, // Todas las imagenes
{
Select(imgGrp, Real(Set imgSet)
{ Or(TextFind(Compact(ToLower(imgSet[2])), lowPat), // Busca en alt
TextFind(Compact(ToLower(imgSet[3])), lowPat)) }) // Busca en title
});
// Clasifica por el path de la imagen reverse
Set imgCla = Classify(imgSel, Real(Set a, Set b) { Compare(b[1], a[1]) });
Set imgCic = EvalSet (imgCla, Text(Set imgSet)
{
Text imgSrc = imgSet[1][1];
Text imgAlt = imgSet[1][2];
// Solo si title es diferente al alt
Text imgTit = If(imgAlt == imgSet[1][3], "", imgSet[1][3]);
// El primer link
Text imgLnk = "<"+TxtBetween2Tag(imgSet[1][4], "<", ">", TRUE)+">";
Text imgLst = Set2Txt(Traspose(imgSet)[4],
"En ", ".", ", ", " y ", "", "", "", ""); // Todos los links
Img2Div(imgSrc, imgAlt, imgTit, imgLnk, imgLst, namCla, txtDef)
});
SetSum(imgCic)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de un mapa o indice de imagenes extraidas de un
conjunto de post en Html.",
ImgMap);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FILE : img.tol
// AUTHOR : http://www.asolver.com
// PURPOSE : Image functions.
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// CONSTANTS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgTag = "<img ";
//////////////////////////////////////////////////////////////////////////////
PutDescription("Tag inicial para imagenes.", ImgTag);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set ImgGetSet(Text htmCod)
//////////////////////////////////////////////////////////////////////////////
{
Text imgTxt = Compact(TxtInside2TagPlus(htmCod, ImgTag, ">"));
If(imgTxt == "", Empty,
{
Text imgRep = Replace(imgTxt, "><", ">"+Char(7)+"<");
Tokenizer(imgRep, Char(7))
})
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el conjunto de imagenes de una pieza de codigo Html.",
ImgGetSet);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgNormalize(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{
Text imgCmp = Compact(imgCod);
ReplaceTable(imgCmp,
[[
[["= ", "="]],
[[" =", "="]],
[[".'", "'"]], // Elimina los puntos finales
[[Char(34), "'"]]
]])
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de una imagen normalizado.",
ImgNormalize);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgGetSrc(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{ TxtBetween2Tag(ImgNormalize(imgCod), "src='", "'", TRUE) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna de un codigo Html de una imagen la url de la imagen.",
ImgGetSrc);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgGetAlt(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{ TxtBetween2Tag(ImgNormalize(imgCod), "alt='", "'", TRUE) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna de un codigo Html de una imagen el texto alt de la imagen.",
ImgGetAlt);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgGetTit(Text imgCod)
//////////////////////////////////////////////////////////////////////////////
{ TxtBetween2Tag(ImgNormalize(imgCod), "title='", "'", TRUE) };
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna de un codigo Html de una imagen el texto title de la imagen.",
ImgGetTit);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Img2Htm(Text imgSrc, // Image path
Text imgAlt, // Alternate text, mandatory
Text imgTit, // Image title
Text imgCla, // Image class
Text imgDef) // Para cuando no hay textos
//////////////////////////////////////////////////////////////////////////////
{
Text htmSrc = " src="+Q(imgSrc);
Text htmCla = " class="+Q(imgCla);
Text htmAlt = If(imgAlt!="", " alt="+Q(imgAlt), // Hay alt
If(imgTit!="", " alt="+Q(imgTit), // Sin alt pero si title
" alt="+Q(imgDef))); // Sin nada
Text htmTit = If(imgTit!="", " title="+Q(imgTit), // Hay title
If(imgAlt!="", " title="+Q(imgAlt), // Sin title pero si alt
" title="+Q(imgDef))); // Sin nada
Text htmImg = "\n <img" + htmSrc +
"\n " + htmCla +
"\n " + htmAlt +
"\n " + htmTit + " />";
htmImg
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de una imagen con sus atributos completos rellenando
aquellos que faltan.",
Img2Htm);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Img2Div(Text imgSrc, // Image path
Text imgAlt, // Alternate text, mandatory
Text imgTit, // Image title
Text imgLnk, // Main link
Text imgLst, // List of links
Text imgCla, // Image class
Text imgDef) // Para cuando no hay textos
//////////////////////////////////////////////////////////////////////////////
{
Text htmImg = Img2Htm(imgSrc, imgAlt, imgTit, imgCla, imgDef);
Text htmTxt = Case
(
And(imgAlt != "", imgTit == ""), imgAlt,
And(imgAlt == "", imgTit != ""), imgTit,
And(imgAlt == "", imgTit == ""), imgDef,
imgAlt == imgTit, imgAlt,
TRUE, imgTit+": "+imgAlt
)+". ";
Text htmDes = "<p>"+htmTxt+imgLst+"</p>";
"\n<div class="+Q(imgCla)+">" +
"\n " + imgLnk + htmImg + "</a>" +
"\n " + htmDes +
"\n</div><div style="+Q("clear:both")+"></div>\n"
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de una imagen con sus atributos completos rellenando
aquellos que faltan y todo dentro de una estructura Html div.",
Img2Div);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text ImgMap(Set ctrPdb, // Set of post from a post database
Text txtPat, // Text pattern for seleccion in alts and title
Text namCla, // Name for image class
Text txtDef) // Para cuando no hay textos
//////////////////////////////////////////////////////////////////////////////
{
Set imgPdb = EvalSet(ctrPdb, Set(Set objPst)
{// Si se crean imágenes dinámicas no las ve, sería recursivo en este post
Set imgSel = ImgGetSet(objPst->pstHtm);
EvalSet(imgSel, Set(Text imgCod)
{
Text imgSrc = ImgGetSrc(imgCod);
Text imgAlt = ImgGetAlt(imgCod);
Text imgTit = ImgGetTit(imgCod);
Text imgLnk = PhtLinkPost(objPst);
// Text WriteLn(imgSrc+"\n"+imgAlt+"\n"+imgTit+"\n"+imgLnk+"\n");
SetOfText(imgSrc, imgAlt, imgTit, imgLnk)
})
});
Set imgGrp = BinGroup("<<", imgPdb);
Text lowPat = Compact(ToLower(txtPat));
Set imgSel = If(lowPat == "", imgGrp, // Todas las imagenes
{
Select(imgGrp, Real(Set imgSet)
{ Or(TextFind(Compact(ToLower(imgSet[2])), lowPat), // Busca en alt
TextFind(Compact(ToLower(imgSet[3])), lowPat)) }) // Busca en title
});
// Clasifica por el path de la imagen reverse
Set imgCla = Classify(imgSel, Real(Set a, Set b) { Compare(b[1], a[1]) });
Set imgCic = EvalSet (imgCla, Text(Set imgSet)
{
Text imgSrc = imgSet[1][1];
Text imgAlt = imgSet[1][2];
// Solo si title es diferente al alt
Text imgTit = If(imgAlt == imgSet[1][3], "", imgSet[1][3]);
// El primer link
Text imgLnk = "<"+TxtBetween2Tag(imgSet[1][4], "<", ">", TRUE)+">";
Text imgLst = Set2Txt(Traspose(imgSet)[4],
"En ", ".", ", ", " y ", "", "", "", ""); // Todos los links
Img2Div(imgSrc, imgAlt, imgTit, imgLnk, imgLst, namCla, txtDef)
});
SetSum(imgCic)
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el codigo Html de un mapa o indice de imagenes extraidas de un
conjunto de post en Html.",
ImgMap);
//////////////////////////////////////////////////////////////////////////////
con-Q.tv construye las páginas del sitio y newsletter Con-Q.tv
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio