From 75c25ec5bfa34591e1c7fa8cd6b860553b50ce68 Mon Sep 17 00:00:00 2001 From: Fil <fil@rezo.net> Date: Sat, 30 Apr 2005 23:34:10 +0000 Subject: [PATCH] =?UTF-8?q?Images=20r=C3=A9duites,=20suite=20:=20-=20inser?= =?UTF-8?q?tion=20du=20'onmouseover'=20dans=20le=20tag=20<img...>=20(#LOGO?= =?UTF-8?q?=5FXXX)=20-=20le=20filtre=20image=5Freduite=20s'applique=20d?= =?UTF-8?q?=C3=A9sormais=20aussi=20aux=20textes=20(Renato=20Formato)=20-?= =?UTF-8?q?=20les=20images=20r=C3=A9duites=20apparaissent=20de=20nouveau?= =?UTF-8?q?=20dans=20la=20page=20articles=5Fedit.php3=20(signal=C3=A9=20pa?= =?UTF-8?q?r=20Renato)=20-=20possibilit=C3=A9=20de=20donner=20une=20taille?= =?UTF-8?q?=20{0,300}=20pour=20ne=20r=C3=A9duire=20qu'en=20hauteur=20(Rena?= =?UTF-8?q?to=20toujours=20!)=20-=20debuguage=20-=20un=20nouveau=20filtre,?= =?UTF-8?q?=20|lignes=5Flongues{longueur}=20permet=20de=20"couper"=20les?= =?UTF-8?q?=20mots=20trop=20longs=20(utile=20si=20on=20a=20des=20urls=20?= =?UTF-8?q?=C3=A0=20caser=20dans=20une=20colonne=20=C3=A9troite).=20Par=20?= =?UTF-8?q?d=C3=A9faut=20coupe=20=C3=A0=2070=20caract=C3=A8res=20(anticons?= =?UTF-8?q?titutionnellement)=20-=20petite=20am=C3=A9lioration=20du=20port?= =?UTF-8?q?folio=20dans=20article.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/article.html | 10 ++-- ecrire/articles.php3 | 1 + ecrire/inc_documents.php3 | 33 ++++--------- ecrire/inc_filtres.php3 | 98 +++++++++++++++++++++++++++++---------- ecrire/inc_logos.php3 | 57 ++++++++++++++++------- inc-calcul-outils.php3 | 20 ++++---- 6 files changed, 140 insertions(+), 79 deletions(-) diff --git a/dist/article.html b/dist/article.html index 614edcff09..f013bf3899 100644 --- a/dist/article.html +++ b/dist/article.html @@ -191,6 +191,7 @@ <BOUCLE_afficher_document(DOCUMENTS){id_document}{mode=document}{extension==(png|jpg|gif)$}{doublons}> +<hr> [<h3 class="spip">(#TITRE)</h3>] [<div>(#DESCRIPTIF)</div>] @@ -201,9 +202,8 @@ <div><hr> <BOUCLE_documents_portfolio(DOCUMENTS){id_article}{mode=document}{extension==(png|jpg|gif)$}{doublons}> <div style="float: left;"> - - [<a href="#URL_ARTICLE[(#URL_ARTICLE|strpos{'?'}|?{'&','?'})]id_document=#ID_DOCUMENT">(#LOGO_DOCUMENT{500,60})</a>] -[<div><b>(#TITRE)</b></div>][<div>(#DESCRIPTIF)</div>] + [<a href="#URL_ARTICLE[(#URL_ARTICLE|strpos{?}|?{&,?})]id_document=#ID_DOCUMENT">(#LOGO_DOCUMENT{500,60})</a>] +[<div style="clear: both;"><b>(#TITRE)</b></div>][<div style="clear: both;">(#DESCRIPTIF)</div>] </div> </BOUCLE_documents_portfolio> </div> @@ -212,9 +212,9 @@ <B_documents_joints> <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;"> - [(#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> </BOUCLE_documents_joints> </div> diff --git a/ecrire/articles.php3 b/ecrire/articles.php3 index 15086664ff..fdef9f82e1 100644 --- a/ecrire/articles.php3 +++ b/ecrire/articles.php3 @@ -1485,6 +1485,7 @@ else { } echo "<div $dir_lang style='font-size: small;'>"; +# echo reduire_image(propre($texte), 500,10000); echo propre($texte); echo "<br clear='both' />"; echo "</div>"; diff --git a/ecrire/inc_documents.php3 b/ecrire/inc_documents.php3 index 11b0a8696b..baa682ea3c 100644 --- a/ecrire/inc_documents.php3 +++ b/ecrire/inc_documents.php3 @@ -1093,7 +1093,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d // 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); echo "<div style='float: $spip_lang_left;'>"; @@ -1106,31 +1106,16 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d // // Affichage de la vignette // - - if ($id_vignette) $vignette = spip_fetch_array(spip_query("SELECT * FROM spip_documents WHERE id_document = $id_vignette"));; - if ($vignette) { - $fichier_vignette = generer_url_document($id_vignette); - $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>"; + echo "<div align='center'>\n"; + if ($id_vignette + AND $vignette = spip_fetch_array(spip_query("SELECT * FROM spip_documents WHERE id_document = $id_vignette"))) { + echo document_et_vignette($vignette, $url); } else { - // pas de vignette - 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 document_et_vignette($document, $url); } + echo "</div\n"; + // Affichage du raccourci <doc...> correspondant if (!ereg(",$id_document,", $doublons)) { @@ -1251,7 +1236,7 @@ function afficher_case_document($id_document, $image_url, $redirect_url = "", $d // else if ($mode == 'vignette') { $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); diff --git a/ecrire/inc_filtres.php3 b/ecrire/inc_filtres.php3 index e4cf1fbbd8..42a3492c77 100644 --- a/ecrire/inc_filtres.php3 +++ b/ecrire/inc_filtres.php3 @@ -210,6 +210,31 @@ function PtoBR($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 function majuscules($texte) { // Cas du turc @@ -650,32 +675,54 @@ function date_iso($date_heure) { // Fonctions graphiques // -function extraire_fichier($img) { - if (eregi("img src=['\"]([^'\"]+)['\"]", $img, $regs)) $logo = $regs[1]; - if (!$logo) $logo = $img; - return $logo; -} - -function reduire_image($img, $taille = 0, $taille_y=0) { - if (!$img) return; +// Accepte en entree un tag <img ...> +function reduire_une_image($img, $taille, $taille_y) { include_ecrire('inc_logos.php3'); - if (!$taille) - $taille = lire_meta('taille_preview'); - - if (eregi("onmouseover=\"this\.firstChild\.src=\'([^']+)\'\"", $img, $match)) { - $mouseover = extraire_fichier(reduire_image_logo($match[1], $taille, $taille_y)); + // Cas du mouseover genere par les logos de survol de #LOGO_ARTICLE + if (eregi("onmouseover=\"this\.src=\'([^']+)\'\"", $img, $match)) { + $mouseover = extraire_attribut( + reduire_image_logo($match[1], $taille, $taille_y), + 'src'); } - + $image = reduire_image_logo($img, $taille, $taille_y); - + if ($mouseover) { - $mouseout = extraire_fichier($image); - return "<div onmouseover=\"this.firstChild.src='$mouseover'\"" - ." onmouseout=\"this.firstChild.src='$mouseout'\">" - .$image."</div>"; + $mouseout = extraire_attribut($image, 'src'); + $js_mouseover = "onmouseover=\"this.src='$mouseover'\"" + ." onmouseout=\"this.src='$mouseout'\" />"; + $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) { @@ -885,11 +932,12 @@ function alterner($i) { function extraire_attribut($balise, $attribut) { # la mise en facteur ne marche pas.... # if (preg_match("/<[^>]*\s+$attribut=(['\"])([^\\1]*)\\1/i", $balise, $r)) - if (preg_match("/<[^>]*\s+$attribut='([^']*)'/i", $balise, $r)) - return $r[1]; - else if (preg_match("/<[^>]*\s+$attribut=\"([^\"]*)\"/i", $balise, $r)) - return $r[1]; - else return ''; + if (preg_match("/<[^>]*\s+$attribut='([^']*)'/i", $balise, $r)) + return $r[1]; + else if (preg_match("/<[^>]*\s+$attribut=\"([^\"]*)\"/i", $balise, $r)) + return $r[1]; + else + return ''; } // fabrique un bouton de type $t de Name $n, de Value $v et autres attributs $a diff --git a/ecrire/inc_logos.php3 b/ecrire/inc_logos.php3 index 3516283bdb..f6b2cbf2c2 100644 --- a/ecrire/inc_logos.php3 +++ b/ecrire/inc_logos.php3 @@ -445,32 +445,54 @@ function taille_image($img) { // [(#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) { - if (!$taille) $taille = lire_meta('taille_preview'); - if (!$taille) $taille = 150; - if (!$taille_y) $taille_y = $taille; + + // Determiner la taille x,y maxi + 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 - if (eregi("img src=['\"]([^'\"]+)['\"]", $img, $regs)) $logo = $regs[1]; - if (!$logo) $logo = $img; + if ($src = extraire_attribut($img, 'src')) + $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 = ''; - // encore utilise ? - if (eregi("name='([^']+)'", $img, $regs)) $name = $regs[1]; - if ($name) $attributs .= " name='$name'"; + // preserver le name='...' et le mettre en alt le cas echant + if ($name = extraire_attribut($img, 'name')) + $attributs .= " name='$name'"; + $attributs .= " alt='$name'"; // attributs deprecies. Transformer en CSS - if (eregi("hspace='([^']+)'", $img, $regs)) $espace = $regs[1]; - if ($espace) - $attributs .= " style='margin: $espace" . "px; border-width: 0px;'"; + if ($espace = extraire_attribut($img, 'hspace')) + $attributs .= " style='margin: $espace" . "px; border-width: 0px;'"; else - $attributs .= " style='border-width: 0px;' class='spip_logos'"; + $attributs .= " style='border-width: 0px;' class='spip_logos'"; // attribut deprecie mais equivalent CSS pas clair - if (eregi("align='([^']+)'", $img, $regs)) $align = $regs[1]; - if ($align) $attributs .= " align='$align'"; + if ($align = extraire_attribut($img, 'align')) + $attributs .= " align='$align'"; - $attributs .= " alt='$name'"; if (eregi("(.*)\.(jpg|gif|png)$", $logo, $regs)) { if ($i = cherche_image_nommee($regs[1], array($regs[2]))) { list(,$nom,$format) = $i; @@ -485,9 +507,10 @@ function reduire_image_logo($img, $taille = 0, $taille_y=0) { return "<img src='$vignette$date' width='$width' height='$height'$attributs />"; } else if ($taille_origine = @getimagesize($logo)) { - $date = filemtime($logo); 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 />"; } } } diff --git a/inc-calcul-outils.php3 b/inc-calcul-outils.php3 index 88460d451a..7d842baf2e 100644 --- a/inc-calcul-outils.php3 +++ b/inc-calcul-outils.php3 @@ -43,17 +43,21 @@ function affiche_logos($logos, $lien, $align, $alt='logo') { 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'" . ($align ? " align='$align'" : '') + . $taille + . $mouseover . " style='border-width: 0px;' class='spip_logos' />"; - if (!$artoff) 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>"); - + return ($lien ? http_href($lien, $milieu) : $milieu); } // @@ -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); // Lien par defaut = l'adresse du document - if (!$lien) $lien = $fichier; + ## if (!$lien) $lien = $fichier; // Y a t il une vignette personnalisee ? if ($id_vignette) { -- GitLab