Skip to content
Extraits de code Groupes Projets
Valider 75c25ec5 rédigé par Fil's avatar Fil
Parcourir les fichiers

Images réduites, suite :

- insertion du 'onmouseover' dans le tag <img...> (#LOGO_XXX)
- le filtre image_reduite s'applique désormais aussi aux textes (Renato Formato)
- les images réduites apparaissent de nouveau dans la page articles_edit.php3 (signalé par Renato)
- possibilité de donner une taille {0,300} pour ne réduire qu'en hauteur (Renato toujours !)
- debuguage
- un nouveau filtre, |lignes_longues{longueur} permet de "couper" les mots trop longs (utile si on a des urls à caser dans une colonne étroite). Par défaut coupe à 70 caractères (anticonstitutionnellement)
- petite amélioration du portfolio dans article.html
parent 3b1cb694
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -191,6 +191,7 @@ ...@@ -191,6 +191,7 @@
<BOUCLE_afficher_document(DOCUMENTS){id_document}{mode=document}{extension==(png|jpg|gif)$}{doublons}> <BOUCLE_afficher_document(DOCUMENTS){id_document}{mode=document}{extension==(png|jpg|gif)$}{doublons}>
<hr>
[<h3 class="spip">(#TITRE)</h3>] [<h3 class="spip">(#TITRE)</h3>]
[<div>(#DESCRIPTIF)</div>] [<div>(#DESCRIPTIF)</div>]
...@@ -201,9 +202,8 @@ ...@@ -201,9 +202,8 @@
<div><hr> <div><hr>
<BOUCLE_documents_portfolio(DOCUMENTS){id_article}{mode=document}{extension==(png|jpg|gif)$}{doublons}> <BOUCLE_documents_portfolio(DOCUMENTS){id_article}{mode=document}{extension==(png|jpg|gif)$}{doublons}>
<div style="float: left;"> <div style="float: left;">
[<a href="#URL_ARTICLE[(#URL_ARTICLE|strpos{?}|?{&amp;,?})]id_document=#ID_DOCUMENT">(#LOGO_DOCUMENT{500,60})</a>]
[<a href="#URL_ARTICLE[(#URL_ARTICLE|strpos{'?'}|?{'&amp;','?'})]id_document=#ID_DOCUMENT">(#LOGO_DOCUMENT{500,60})</a>] [<div style="clear: both;"><b>(#TITRE)</b></div>][<div style="clear: both;">(#DESCRIPTIF)</div>]
[<div><b>(#TITRE)</b></div>][<div>(#DESCRIPTIF)</div>]
</div> </div>
</BOUCLE_documents_portfolio> </BOUCLE_documents_portfolio>
</div> </div>
...@@ -212,9 +212,9 @@ ...@@ -212,9 +212,9 @@
<B_documents_joints> <B_documents_joints>
<div><hr> <div><hr>
<BOUCLE_documents_joints(DOCUMENTS) {id_article} {mode=document} {doublons} {"<br />"}> <BOUCLE_documents_joints(DOCUMENTS) {id_article} {mode=document} {doublons}>
<div style="float: left;"> <div style="float: left;">
[(#LOGO_DOCUMENT|#URL_DOCUMENT)][<div><b>(#TITRE)</b></div>][<div>(#DESCRIPTIF)</div>] [(#LOGO_DOCUMENT|#URL_DOCUMENT)][<div style="clear: both;"><b>(#TITRE)</b></div>][<div style="clear: both;">(#DESCRIPTIF)</div>]
</div> </div>
</BOUCLE_documents_joints> </BOUCLE_documents_joints>
</div> </div>
......
...@@ -1485,6 +1485,7 @@ else { ...@@ -1485,6 +1485,7 @@ else {
} }
echo "<div $dir_lang style='font-size: small;'>"; echo "<div $dir_lang style='font-size: small;'>";
# echo reduire_image(propre($texte), 500,10000);
echo propre($texte); echo propre($texte);
echo "<br clear='both' />"; echo "<br clear='both' />";
echo "</div>"; echo "</div>";
......
...@@ -1093,7 +1093,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d ...@@ -1093,7 +1093,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d
// //
if ($mode == 'document') { if ($mode == 'document') {
$titre_cadre = typo($titre).typo($titre_fichier); $titre_cadre = lignes_longues(typo($titre).typo($titre_fichier), 30);
debut_cadre_enfonce("doc-24.gif", false, "", $titre_cadre); debut_cadre_enfonce("doc-24.gif", false, "", $titre_cadre);
echo "<div style='float: $spip_lang_left;'>"; echo "<div style='float: $spip_lang_left;'>";
...@@ -1106,31 +1106,16 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d ...@@ -1106,31 +1106,16 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d
// //
// Affichage de la vignette // Affichage de la vignette
// //
echo "<div align='center'>\n";
if ($id_vignette) $vignette = spip_fetch_array(spip_query("SELECT * FROM spip_documents WHERE id_document = $id_vignette"));; if ($id_vignette
if ($vignette) { AND $vignette = spip_fetch_array(spip_query("SELECT * FROM spip_documents WHERE id_document = $id_vignette"))) {
$fichier_vignette = generer_url_document($id_vignette); echo document_et_vignette($vignette, $url);
$largeur_vignette = $vignette['largeur'];
$hauteur_vignette = $vignette['hauteur'];
$taille_vignette = $vignette['taille'];
}
if ($fichier_vignette) {
echo "<div align='center'>";
echo texte_vignette_document($largeur_vignette, $hauteur_vignette, $fichier_vignette, $url);
echo "</div>";
} }
else { else {
// pas de vignette echo document_et_vignette($document, $url);
echo "<div align='center'>\n";
$block = "doc_vignette $id_document";
list($icone, $largeur_icone, $hauteur_icone) =
vignette_par_defaut($type_extension);
if ($icone) {
echo "<a href='$url'><img src='$icone' style='border-width: 0px' width='$largeur_icone' align='top' height='$hauteur_icone' alt='" . basename($icone) ."' /></a>\n";
}
echo "</div>\n";
} }
echo "</div\n";
// Affichage du raccourci <doc...> correspondant // Affichage du raccourci <doc...> correspondant
if (!ereg(",$id_document,", $doublons)) { if (!ereg(",$id_document,", $doublons)) {
...@@ -1251,7 +1236,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d ...@@ -1251,7 +1236,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d
// //
else if ($mode == 'vignette') { else if ($mode == 'vignette') {
$block = "image $id_document"; $block = "image $id_document";
$titre_cadre = typo($titre).typo($titre_fichier); $titre_cadre = lignes_longues(typo($titre).typo($titre_fichier), 30);
debut_cadre_relief("image-24.gif", false, "", $titre_cadre); debut_cadre_relief("image-24.gif", false, "", $titre_cadre);
......
...@@ -210,6 +210,31 @@ function PtoBR($texte){ ...@@ -210,6 +210,31 @@ function PtoBR($texte){
return $texte; return $texte;
} }
// Couper les "mots" de plus de $l caracteres (souvent des URLs)
function lignes_longues($texte, $l = 70) {
// echapper les tags (on ne veut pas casser les a href=...)
$tags = array();
if (preg_match_all('/<.*>/Ums', $texte, $t, PREG_SET_ORDER)) {
foreach ($t as $n => $tag) {
$tags[$n] = $tag[0];
$texte = str_replace($tag[0], " @@SPIPTAG$n@@ ", $texte);
}
}
// casser les mots longs qui restent
if (preg_match_all("/\S{".$l."}/ms", $texte, $longs, PREG_SET_ORDER)) {
foreach ($longs as $long) {
$texte = str_replace($long[0], $long[0].' ', $texte);
}
}
// retablir les tags
foreach ($tags as $n=>$tag) {
$texte = str_replace(" @@SPIPTAG$n@@ ", $tag, $texte);
}
return $texte;
}
// Majuscules y compris accents, en HTML // Majuscules y compris accents, en HTML
function majuscules($texte) { function majuscules($texte) {
// Cas du turc // Cas du turc
...@@ -650,32 +675,54 @@ function date_iso($date_heure) { ...@@ -650,32 +675,54 @@ function date_iso($date_heure) {
// Fonctions graphiques // Fonctions graphiques
// //
function extraire_fichier($img) { // Accepte en entree un tag <img ...>
if (eregi("img src=['\"]([^'\"]+)['\"]", $img, $regs)) $logo = $regs[1]; function reduire_une_image($img, $taille, $taille_y) {
if (!$logo) $logo = $img;
return $logo;
}
function reduire_image($img, $taille = 0, $taille_y=0) {
if (!$img) return;
include_ecrire('inc_logos.php3'); include_ecrire('inc_logos.php3');
if (!$taille) // Cas du mouseover genere par les logos de survol de #LOGO_ARTICLE
$taille = lire_meta('taille_preview'); if (eregi("onmouseover=\"this\.src=\'([^']+)\'\"", $img, $match)) {
$mouseover = extraire_attribut(
if (eregi("onmouseover=\"this\.firstChild\.src=\'([^']+)\'\"", $img, $match)) { reduire_image_logo($match[1], $taille, $taille_y),
$mouseover = extraire_fichier(reduire_image_logo($match[1], $taille, $taille_y)); 'src');
} }
$image = reduire_image_logo($img, $taille, $taille_y); $image = reduire_image_logo($img, $taille, $taille_y);
if ($mouseover) { if ($mouseover) {
$mouseout = extraire_fichier($image); $mouseout = extraire_attribut($image, 'src');
return "<div onmouseover=\"this.firstChild.src='$mouseover'\"" $js_mouseover = "onmouseover=\"this.src='$mouseover'\""
." onmouseout=\"this.firstChild.src='$mouseout'\">" ." onmouseout=\"this.src='$mouseout'\" />";
.$image."</div>"; $image = preg_replace(",( /)?".">,", $js_mouseover, $image);
}
return $image;
}
// accepte en entree un texte complet, un img-log (produit par #LOGO_XX),
// un tag <img ...> complet, ou encore un nom de fichier *local* (passer
// le filtre |copie_locale si on veut l'appliquer a un document)
function reduire_image($texte, $taille = 0, $taille_y=0) {
if (!$texte) return;
// Cas du nom de fichier local
if (preg_match(',^'._DIR_IMG.',', $texte)) {
if (!@file_exists($texte)) {
spip_log("Image absente : $texte");
return '';
} else {
return reduire_une_image("<img src='$texte' />", $taille, $taille_y);
}
}
// Cas general : trier toutes les images
if (preg_match_all(',<img\s.*>,Uims', $texte, $tags, PREG_SET_ORDER)) {
foreach ($tags as $tag) {
if ($reduit = reduire_une_image($tag[0], $taille, $taille_y))
$texte = str_replace($tag[0], $reduit, $texte);
}
} }
else return $image;
return $texte;
} }
function largeur($img) { function largeur($img) {
...@@ -885,11 +932,12 @@ function alterner($i) { ...@@ -885,11 +932,12 @@ function alterner($i) {
function extraire_attribut($balise, $attribut) { function extraire_attribut($balise, $attribut) {
# la mise en facteur ne marche pas.... # la mise en facteur ne marche pas....
# if (preg_match("/<[^>]*\s+$attribut=(['\"])([^\\1]*)\\1/i", $balise, $r)) # if (preg_match("/<[^>]*\s+$attribut=(['\"])([^\\1]*)\\1/i", $balise, $r))
if (preg_match("/<[^>]*\s+$attribut='([^']*)'/i", $balise, $r)) if (preg_match("/<[^>]*\s+$attribut='([^']*)'/i", $balise, $r))
return $r[1]; return $r[1];
else if (preg_match("/<[^>]*\s+$attribut=\"([^\"]*)\"/i", $balise, $r)) else if (preg_match("/<[^>]*\s+$attribut=\"([^\"]*)\"/i", $balise, $r))
return $r[1]; return $r[1];
else return ''; else
return '';
} }
// fabrique un bouton de type $t de Name $n, de Value $v et autres attributs $a // fabrique un bouton de type $t de Name $n, de Value $v et autres attributs $a
......
...@@ -445,32 +445,54 @@ function taille_image($img) { ...@@ -445,32 +445,54 @@ function taille_image($img) {
// [(#LOGO_ARTICLE||reduire_image{100,60})] // [(#LOGO_ARTICLE||reduire_image{100,60})]
// //
// Cette fonction accepte en entree un nom de fichier ou un tag <img ...>
function reduire_image_logo($img, $taille = 0, $taille_y=0) { function reduire_image_logo($img, $taille = 0, $taille_y=0) {
if (!$taille) $taille = lire_meta('taille_preview');
if (!$taille) $taille = 150; // Determiner la taille x,y maxi
if (!$taille_y) $taille_y = $taille; if (!$taille) {
if ($taille_y>0)
$taille = 100000; # {0,300} -> c'est 300 qui compte
else {
$taille = lire_meta('taille_preview');
if (!$taille)
$taille = 150;
}
}
if (!$taille_y)
$taille_y = $taille;
// recuperer le nom du fichier // recuperer le nom du fichier
if (eregi("img src=['\"]([^'\"]+)['\"]", $img, $regs)) $logo = $regs[1]; if ($src = extraire_attribut($img, 'src'))
if (!$logo) $logo = $img; $logo = $src;
else
$logo = $img;
if (!$logo) return '';
// Si c'est une image distante, la recuperer (si possible)
if (!$local = copie_locale($logo)) {
spip_log("pas de version locale de $logo");
return $img;
}
$logo = $local;
$attributs = ''; $attributs = '';
// encore utilise ? // preserver le name='...' et le mettre en alt le cas echant
if (eregi("name='([^']+)'", $img, $regs)) $name = $regs[1]; if ($name = extraire_attribut($img, 'name'))
if ($name) $attributs .= " name='$name'"; $attributs .= " name='$name'";
$attributs .= " alt='$name'";
// attributs deprecies. Transformer en CSS // attributs deprecies. Transformer en CSS
if (eregi("hspace='([^']+)'", $img, $regs)) $espace = $regs[1]; if ($espace = extraire_attribut($img, 'hspace'))
if ($espace) $attributs .= " style='margin: $espace" . "px; border-width: 0px;'";
$attributs .= " style='margin: $espace" . "px; border-width: 0px;'";
else else
$attributs .= " style='border-width: 0px;' class='spip_logos'"; $attributs .= " style='border-width: 0px;' class='spip_logos'";
// attribut deprecie mais equivalent CSS pas clair // attribut deprecie mais equivalent CSS pas clair
if (eregi("align='([^']+)'", $img, $regs)) $align = $regs[1]; if ($align = extraire_attribut($img, 'align'))
if ($align) $attributs .= " align='$align'"; $attributs .= " align='$align'";
$attributs .= " alt='$name'";
if (eregi("(.*)\.(jpg|gif|png)$", $logo, $regs)) { if (eregi("(.*)\.(jpg|gif|png)$", $logo, $regs)) {
if ($i = cherche_image_nommee($regs[1], array($regs[2]))) { if ($i = cherche_image_nommee($regs[1], array($regs[2]))) {
list(,$nom,$format) = $i; list(,$nom,$format) = $i;
...@@ -485,9 +507,10 @@ function reduire_image_logo($img, $taille = 0, $taille_y=0) { ...@@ -485,9 +507,10 @@ function reduire_image_logo($img, $taille = 0, $taille_y=0) {
return "<img src='$vignette$date' width='$width' height='$height'$attributs />"; return "<img src='$vignette$date' width='$width' height='$height'$attributs />";
} }
else if ($taille_origine = @getimagesize($logo)) { else if ($taille_origine = @getimagesize($logo)) {
$date = filemtime($logo);
list ($destWidth,$destHeight) = image_ratio($taille_origine[0], $taille_origine[1], $taille, $taille_y); list ($destWidth,$destHeight) = image_ratio($taille_origine[0], $taille_origine[1], $taille, $taille_y);
return "<img src='$logo?date=$date' width='$destWidth' height='$destHeight'$attributs />"; if (!_DIR_ECRIRE)
$date = '?date='.filemtime($logo);
return "<img src='$logo$date' width='$destWidth' height='$destHeight'$attributs />";
} }
} }
} }
......
...@@ -43,17 +43,21 @@ function affiche_logos($logos, $lien, $align, $alt='logo') { ...@@ -43,17 +43,21 @@ function affiche_logos($logos, $lien, $align, $alt='logo') {
if (!$arton) return $artoff; if (!$arton) return $artoff;
if ($taille = @getimagesize($arton)) {
$taille = " ".$taille[3];
}
if ($artoff)
$mouseover = " onmouseover=\"this.src='$artoff'\" "
."onmouseout=\"this.src='$arton'\"";
$milieu = "<img src='$arton'\nalt='$alt'" $milieu = "<img src='$arton'\nalt='$alt'"
. ($align ? " align='$align'" : '') . ($align ? " align='$align'" : '')
. $taille
. $mouseover
. " style='border-width: 0px;' class='spip_logos' />"; . " style='border-width: 0px;' class='spip_logos' />";
if (!$artoff) return ($lien ? http_href($lien, $milieu) : $milieu); return ($lien ? http_href($lien, $milieu) : $milieu);
$att = "onmouseover=\"this.firstChild.src='$artoff'\"
onmouseout=\"this.firstChild.src='$arton'\"";
return ($lien ? "<a href='$lien' $att>$milieu</a>" : "<div $att>$milieu</div>");
} }
// //
...@@ -260,7 +264,7 @@ function calcule_logo_document($id_document, $doubdoc, &$doublons, $flag_fichier ...@@ -260,7 +264,7 @@ function calcule_logo_document($id_document, $doubdoc, &$doublons, $flag_fichier
list($id_type, $id_vignette, $fichier, $mode) = spip_abstract_fetch($row); list($id_type, $id_vignette, $fichier, $mode) = spip_abstract_fetch($row);
// Lien par defaut = l'adresse du document // Lien par defaut = l'adresse du document
if (!$lien) $lien = $fichier; ## if (!$lien) $lien = $fichier;
// Y a t il une vignette personnalisee ? // Y a t il une vignette personnalisee ?
if ($id_vignette) { if ($id_vignette) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter