© Сделано на LiveStreet
Дизайн - ©2009 MODx RED Group
// vos paramètres :
$path = "assets/images/cache"; //... path to thumbnails
$prefix = "page_"; //... prefix for thumbnails
$r = 0; //... rule for resizing (0: based on w and h ; 1: based on w ; 2: based on h ; 3: w max et h max ; 4: img mini to fill a container of w x h)
$q_jpg = 90; //... image quality from 0 to 100 (big quality) for jpg
$q_png = 0; //... image quality from 0 (no compression) to 9 for png
$lien_base = "assets/images"; //... folder path where to resize images
$lien_plugin = "assets/plugins/directresize/directResize.php"; //... path to plugin file
$lightbox = 2; //... activation fo lightbox 0: non actived; 1: actived for img tag containing lightbox in their class; 2: activated for all images smaller than their original
$lightbox_w = 700; //... max width for lightbox
$lightbox_h = 500; //... max height for lighbox
// traitement des variables
//$path = str_replace("/","%2F",$path);
if (substr($prefix,-1) != "_") $prefix .= "_";
// inclusion de la fonction directResize
include $lien_plugin;
$e = &$modx->Event;
switch ($e->name) {
case "OnWebPagePrerender":
$o = $modx->documentOutput; //... récupère la totalité du code de la page
$reg = "/<img[^>]*>/"; //... pattern de recherche des balises d'image
preg_match_all($reg, $o, $imgs, PREG_PATTERN_ORDER); //... recherche toutes les occurances d'image
for($n=0;$n<count($imgs[0]);$n++){
//-----------------------
$lien_img = eregi_replace("^.+src=('|\")","",$imgs[0][$n]); //... récupère le lien de l'image
$lien_img = eregi_replace("('|\").*$","",$lien_img); //... récupère le lien de l'image
//-----------------------
if (substr($lien_img,0,strlen($lien_base)) == $lien_base){ //... si l'image est dans le bon dossier
$img = strtolower($imgs[0][$n]);
$verif_balise = sizeof(explode("width",$img)) + sizeof(explode("height",$img)) - 2;
if ($verif_balise > 0){ //... s'il y a au moins une valeur de height ou width
####################################### Miniature de la page ###############################################################
preg_match("/height *(:|=) *[\"']* *\d+ *[\"']*/",$img,$array); //... récupère la balise height et sa valeur
sizeof(explode(":",$array[0])) > 1 ? $style = true : $style = false; //... défini s'il s'agit d'une taille précisée dans le style ou dans les attributs d'image
$heigth = ereg_replace("[^0123456789]","",$array[0]); //... taille en height
//-------------------
preg_match("/width *(:|=) *[\"']* *\d+ *[\"']*/",$img,$array); //... récupère la balise width et sa valeur
$width = ereg_replace("[^0123456789]","",$array[0]); //... taille en width
//-------------------
if ($style) {
$imgf = eregi_replace("(height|HEIGHT|Height) *: *[0123456789]* *(px)* *","",$imgs[0][$n]); //... supprime les balise height
$imgf = eregi_replace("(width|WIDTH|Width) *: *[0123456789]* *(px)* *","",$imgf); //... supprime les balise width
} else {
$imgf = eregi_replace("(height|HEIGHT|Height) *= *[\"']* *[0123456789]* *(px)* *[\"']*","",$imgs[0][$n]);//... supprime les balise height
$imgf = eregi_replace("(width|WIDTH|Width) *= *[\"']* *[0123456789]* *(px)* *[\"']*","",$imgf); //... supprime les balise width
}
//-------------------
preg_match("/^.+(src|Src|SRC)=('|\")/",$imgf,$lien_g); //... récupère la partie gauche de la balise
$imgf = eregi_replace("^.+src=('|\")","",$imgf); //... récupère la partie droite de la balise
preg_match("/('|\").*$/",$imgf,$lien_d);
//-------------------
$lienRedim = directResize($lien_img,$path,$prefix,$width,$heigth,$r,$q_jpg,$q_png);
//-------------------
$nouvo_lien = $lien_g[0].$lienRedim.$lien_d[0]; //... formation du lien final
####################################### Traitement pour Lightbox ###############################################################
preg_match("/highslide/",strtolower($imgs[0][$n]),$verif_light);
if (($lightbox == 1 && $verif_light[0] == "highslide") || ($lightbox == 2 && substr($lien_img,0,strlen($lien_base)) == $lien_base)){ //... si lightbox activé pour cette image
$size = getimagesize($lien_img); //... récupère les tailles de l'image originale
$img_src_w = $size[0];
$img_src_h = $size[1];
$alt = "";
$title = "";
preg_match("/(alt|Alt|ALT) *= *[\"|'][^\"']*[\"']/",$imgs[0][$n],$array); //... vérifie si la balise alt est définie et récupération
if ($array[0] <> ""){
$alt = eregi_replace("alt *= *[\"|']","",$array[0]);
$alt = eregi_replace("[\"']*","",$alt);
$alt = trim($alt);
}
preg_match("/(title|Title|TITLE) *= *[\"|'][^\"']*[\"']/",$imgs[0][$n],$array); //... vérifie si la balise title est définie et récupération
if ($array[0] <> ""){
$title = eregi_replace("title *= *[\"|']","",$array[0]);
$title = eregi_replace("[\"']*","",$title);
$title = trim($title);
}
if ($alt <> "" || $title <> ""){
$legende = " title=\"$alt";
if ($alt <> "" && $title <> "") $legende .= "<br />";
if ($title <> "") $legende .= "<span style='font-weight:normal; font-size: 9px'>$title</span>";
$legende .= "\" ";
} else {
$legende = "";
}
if ($img_src_w > $width || $img_src_h > $height){ //... si l'image originale est plus grande que l'image affich?йe dans la page
if ($img_src_w > $lightbox_w || $img_src_h > $lightbox_h){ //... si l'image originale est plus grande que la taille de zoom demand?йe --> redimentionnement
$lienRedim = directResize($lien_img,$path,$prefix,$lightbox_w,$lightbox_h,3,$q_jpg,$q_png);
//$nouvo_lien = "<a rel=\"lightbox\" ".$legende." href='".$lienRedim."' >".$nouvo_lien."</a>";
$nouvo_lien = "<a class=\"highslide\" onclick=\"return hs.expand(this)\" ".$legende." href='".$lienRedim."' >".$nouvo_lien."</a>";
} else { //... sinon, lien vers l'image d'origine
//$nouvo_lien = "<a rel=\"lightbox\" ".$legende." href='".$lien_img."' >".$nouvo_lien."</a>";
$nouvo_lien = "<a class=\"highslide\" onclick=\"return hs.expand(this)\" ".$legende." href='".$lien_img."' >".$nouvo_lien."</a>";
}
}
}
####################################### Remplacement final du lien d'image ###############################################################
$o = str_replace($imgs[0][$n],$nouvo_lien,$o); //... remplacement dans le rendu global
}
}
}
$modx->documentOutput = $o;
break;
default :
return; // stop here - this is very important.
break;
}<script type="text/javascript" src="[(site_url)]assets/plugins/directresize/libs/highslide/highslide.packed.js"></script>
<script type="text/javascript">
hs.graphicsDir = '[(site_url)]assets/plugins/directresize/libs/highslide/graphics/';
hs.lang.creditsText = '';
</script>
Комментарии (10)
RSS свернуть / развернутьЯ думаю по завершении архива я приведу это описание (заодно будет и работающий пример). :)
burik
в DirectResize 0.9.0 было пару нерабочих версий теперь все как обычно
главное в конфиги не забыть отключить красивый адрес тогда вообще проблем нет.
Я просто в дистрибьютив его добавил и все установил а он уже сразу есть.
fobazzz
Carw
Carw
ikarushka
WebraumZ
Carw
пожалуйста, подскажите, очень нужно!
modx evo 1.02
OldHunterHank
OldHunterHank
* мне это не желательно (
doc555
Только зарегистрированные и авторизованные пользователи могут оставлять комментарии.