From d0f96ff4de189ead28e6cd4e80ee1c1128abf077 Mon Sep 17 00:00:00 2001 From: "Committo,Ergo:sum" <esj@rezo.net> Date: Wed, 27 Sep 2006 15:31:03 +0000 Subject: [PATCH] Interface de gestion des logos: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - la fonction inc_chercher_logo introduite en [6883] était souvent déjà chargée avant que l'on calcule la surcharge, ce qui rendait celle-ci inopérante; - le formulaire de gestion des logos (ci-devant afficher_boite_logo) devient une fonction surchargeable inc_iconifier_dist; - dans le cas de la suppression, ce formulaire est appelé en mode Ajax. - au passage, correction du bug qui empechait l'affichage du logo des rubriques dans l'affichage de la page d'accueil et autres; Et un peu de #587 dans le script articles. --- .gitattributes | 2 + ecrire/action/iconifier.php | 9 +- ecrire/exec/accueil.php | 9 +- ecrire/exec/articles.php | 121 ++++++++++++------------ ecrire/exec/auteurs_edit.php | 5 +- ecrire/exec/breves_voir.php | 6 +- ecrire/exec/configuration.php | 4 +- ecrire/exec/mots_edit.php | 4 +- ecrire/exec/naviguer.php | 4 +- ecrire/exec/sites.php | 4 +- ecrire/fragments/iconifier.php | 52 +++++++++++ ecrire/fragments/informer.php | 7 +- ecrire/inc/chercher_logo.php | 165 +-------------------------------- ecrire/inc/iconifier.php | 138 +++++++++++++++++++++++++++ ecrire/inc/logos.php | 46 +++++++++ ecrire/inc/presentation.php | 21 +++-- ecrire/inc/rubriques.php | 10 +- ecrire/inc/sites_voir.php | 7 +- 18 files changed, 355 insertions(+), 259 deletions(-) create mode 100644 ecrire/fragments/iconifier.php create mode 100644 ecrire/inc/iconifier.php diff --git a/.gitattributes b/.gitattributes index dc94438d6f..117b8722cd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -402,6 +402,7 @@ ecrire/fragments/documenter.php -text ecrire/fragments/editer_auteurs.php -text ecrire/fragments/editer_mot.php -text ecrire/fragments/grouper_mots.php -text +ecrire/fragments/iconifier.php -text ecrire/fragments/informer.php -text ecrire/fragments/legender.php -text ecrire/fragments/memoriser.php -text @@ -434,6 +435,7 @@ ecrire/inc/forum_insert.php -text ecrire/inc/gadgets.php -text ecrire/inc/grouper_mots.php -text ecrire/inc/headers.php -text +ecrire/inc/iconifier.php -text ecrire/inc/import_0_0.php -text ecrire/inc/import_1_2.php -text ecrire/inc/import_1_3.php -text diff --git a/ecrire/action/iconifier.php b/ecrire/action/iconifier.php index a5c90a136b..c4b38c9d63 100644 --- a/ecrire/action/iconifier.php +++ b/ecrire/action/iconifier.php @@ -21,15 +21,16 @@ function action_iconifier_dist() $arg = _request('arg'); $arg = rawurldecode($arg); - if (!preg_match(',^unlink\s,',$arg)) - action_spip_image_ajouter_dist($arg); - else action_spip_image_effacer_dist($arg); + if (!preg_match(',^\d*(\D)(.*)$,',$arg, $r)) + spip_log("action iconifier: $arg pas compris"); + elseif ($r[1] == '+') + action_spip_image_ajouter_dist($r[2]); + else action_spip_image_effacer_dist($r[2]); } // http://doc.spip.org/@action_spip_image_effacer_dist function action_spip_image_effacer_dist($arg) { - $arg = preg_replace(',^unlink\s*,','',rawurldecode($arg)); if (!strstr($arg, "..")) @unlink(_DIR_LOGOS . $arg); } diff --git a/ecrire/exec/accueil.php b/ecrire/exec/accueil.php index fbcb0e3ce5..1489de65c4 100644 --- a/ecrire/exec/accueil.php +++ b/ecrire/exec/accueil.php @@ -314,9 +314,12 @@ if ($spip_display != 4) { if ($spip_display != 1) { $logo_f = charger_fonction('chercher_logo', 'inc'); - if ($res = $logo_f(0, 'id_syndic', 'on')) - if ($res = decrire_logo("id_syndic", 'on', 0, 170, 170, $res)) - echo "<div style='text-align:center; margin-bottom: 5px;'>$res</div>"; + if ($res = $logo_f(0, 'id_syndic', 'on')) { + list($fid, $dir, $nom, $format) = $res; + $res = ratio_image($fid, $nom, $format, 170, 170, "alt=''"); + if ($res) + echo "<div style='text-align:center; margin-bottom: 5px;'>$res</div>"; + } } echo "<div class='verdana1'>"; diff --git a/ecrire/exec/articles.php b/ecrire/exec/articles.php index d8b271e73a..d031c378a1 100644 --- a/ecrire/exec/articles.php +++ b/ecrire/exec/articles.php @@ -59,6 +59,8 @@ function exec_articles_dist() $id_trad = $row["id_trad"]; $id_version = $row["id_version"]; + $virtuel = (substr($chapo, 0, 1) == '=') ? substr($chapo, 1) : ''; + $statut_rubrique = acces_rubrique($id_rubrique); $flag_auteur = spip_num_rows(spip_query("SELECT id_auteur FROM spip_auteurs_articles WHERE id_article=$id_article AND id_auteur=$connect_id_auteur LIMIT 1")); @@ -86,12 +88,10 @@ echo boite_info_articles($id_article, $statut_article, $visites, $id_version); // if ($flag_editable AND ($spip_display != 4)) { - include_spip('inc/chercher_logo'); - echo afficher_boite_logo('id_article', $id_article, _T('logo_article').aide ("logoart"), _T('logo_survol'), 'articles'); + $iconifier = charger_fonction('iconifier', 'inc'); + echo $iconifier('id_article', $id_article,'articles'); } -// pour l'affichage du virtuel - $virtuel = (substr($chapo, 0, 1) == '=') ? substr($chapo, 1) : ''; // Boites de configuration avancee @@ -117,10 +117,6 @@ creer_colonne_droite(); debut_droite(); -changer_typo('','article'.$id_article); - -debut_cadre_relief(); - // Est-ce que quelqu'un a deja ouvert l'article en edition ? $modif = array(); if ($GLOBALS['meta']['articles_modif'] != 'non') { @@ -130,6 +126,8 @@ debut_cadre_relief(); $modif = array(); } + // chargement prealable des fonctions produisant des formulaires + $dater = charger_fonction('dater', 'inc'); $auteurs = charger_fonction('editer_auteurs', 'inc'); @@ -142,7 +140,15 @@ debut_cadre_relief(); $traduction = charger_fonction('referencer_traduction', 'inc'); else $traduction =''; - echo titres_articles($titre, $statut_article,$surtitre, $soustitre, $descriptif, $url_site, $nom_site, $flag_editable, $id_article, $id_rubrique, $modif), + $discuter = charger_fonction('discuter', 'inc'); + + // affecter les globales dictant les regles de typographie de la langue + changer_typo('','article'.$id_article); + + // Envoi de tout le reste de la page + + echo debut_cadre_relief('', true), + titres_articles($titre, $statut_article,$surtitre, $soustitre, $descriptif, $url_site, $nom_site, $flag_editable, $id_article, $id_rubrique, $modif), "<div> </div>", "<div class='serif' align='$spip_lang_left'>", @@ -155,69 +161,66 @@ debut_cadre_relief(); (!$traduction ? '' : $traduction($id_article, $flag_editable, $id_rubrique, $id_trad, $trad_err)), - pipeline('affiche_milieu',array('args'=>array('exec'=>'articles','id_article'=>$id_article),'data'=>'')); + pipeline('affiche_milieu',array('args'=>array('exec'=>'articles','id_article'=>$id_article),'data'=>'')), - if ($statut_rubrique) - echo debut_cadre_relief('', true), - "\n<div id='instituer_article-$id_article'>", - formulaire_instituer_article($id_article, $statut_article, 'articles', "id_article=$id_article"), - '</div>', - fin_cadre_relief('', true); + (!$statut_rubrique ? '' + : (debut_cadre_relief('', true) + . "\n<div id='instituer_article-$id_article'>" + . formulaire_instituer_article($id_article, $statut_article, 'articles', "id_article=$id_article") + . '</div>' + . fin_cadre_relief(true))), - echo "\n\n<div align='justify' style='padding: 10px;'>", - afficher_corps_articles($virtuel, $chapo, $texte, $ps, $extra); + "\n\n<div align='justify' style='padding: 10px;'>", + afficher_corps_articles($virtuel, $chapo, $texte, $ps, $extra), - if ($flag_editable) { - echo "\n<div align='$spip_lang_right'><br />", - bouton_modifier_articles($id_article, $id_rubrique, $modif,_T('texte_travail_article', $modif), "warning-24.gif", ""), - "</div>"; -} - - if ($spip_display != 4) { - - if ($GLOBALS['meta']["documents_$type"]!='non' AND $flag_editable) { - - $f = charger_fonction('joindre', 'inc'); - $res = debut_cadre_relief("image-24.gif", true, "", _T('titre_joindre_document')) - . $f('articles', "id_article=$id_article", $id_article, _T('info_telecharger_ordinateur'), 'document', 'article') - . fin_cadre_relief(true); - - // eviter le formulaire upload qui se promene sur la page - // a cause des position:relative incompris de MSIE + (!$flag_editable ? '' + : ("\n<div align='$spip_lang_right'><br />" + . bouton_modifier_articles($id_article, $id_rubrique, $modif,_T('texte_travail_article', $modif), "warning-24.gif", "") + . "</div>")), + (($spip_display == 4) ? '' + : articles_documents($flag_editable, 'article', $id_article)), - if (!($align = $GLOBALS['browser_name']=="MSIE")) { - $res = "\n<table width='50%' cellpadding='0' cellspacing='0' border='0'>\n<tr><td style='text-align: $spip_lang_left;'>\n$res</td></tr></table>"; - $align = " align='right'"; - } - $res = "<div$align>$res</div>"; - } else $res =''; + (($flag_auteur AND $statut_article == 'prepa' AND !$statut_rubrique) + ? demande_publication($id_article) + : ''), + "</div></div>", - $f = charger_fonction('documenter', 'inc'); + fin_cadre_relief(true), - echo $f($id_article, 'article', 'portfolio', $flag_editable) - . $f($id_article, 'article', 'documents', $flag_editable) - . $res; - } + "<br /><br />\n<div align='center'>", + icone(_T('icone_poster_message'), generer_url_ecrire("forum_envoi","statut=prive&id_article=$id_article&titre_message=" .rawurlencode($titre) . "&url=" . generer_url_retour("articles","id_article=$id_article")), "forum-interne-24.gif", "creer.gif", '', false), + "</div><br />", + $discuter($id_article, false, $debut); - if ($flag_auteur AND $statut_article == 'prepa' AND !$statut_rubrique) - echo demande_publication($id_article); + fin_page(); +} - echo "</div></div>"; +function articles_documents($flag_editable, $type, $id) +{ + global $spip_lang_left; + if ($GLOBALS['meta']["documents_$type"]!='non' AND $flag_editable) { - fin_cadre_relief(); + $f = charger_fonction('joindre', 'inc'); - // forum interne + $res = debut_cadre_relief("image-24.gif", true, "", _T('titre_joindre_document')) + . $f('articles', "id_article=$id", $id, _T('info_telecharger_ordinateur'), 'document', 'article') + . fin_cadre_relief(true); - $tm = rawurlencode($titre); - $f = charger_fonction('discuter', 'inc'); + // eviter le formulaire upload qui se promene sur la page + // a cause des position:relative incompris de MSIE - echo "<br /><br />\n<div align='center'>", - icone(_T('icone_poster_message'), generer_url_ecrire("forum_envoi","statut=prive&id_article=$id_article&titre_message=$tm&url=" . generer_url_retour("articles","id_article=$id_article")), "forum-interne-24.gif", "creer.gif", '', false), - "</div><br />", - $f($id_article, false, $debut); + if (!($align = $GLOBALS['browser_name']=="MSIE")) { + $res = "\n<table width='50%' cellpadding='0' cellspacing='0' border='0'>\n<tr><td style='text-align: $spip_lang_left;'>\n$res</td></tr></table>"; + $align = " align='right'"; + } + $res = "<div$align>$res</div>"; + } else $res =''; - fin_page(); + $f = charger_fonction('documenter', 'inc'); + return $f($id_article, 'article', 'portfolio', $flag_editable) + . $f($id_article, 'article', 'documents', $flag_editable) + . $res; } // http://doc.spip.org/@demande_publication @@ -277,7 +280,6 @@ function boite_info_articles($id_article, $statut_article, $visites, $id_version // http://doc.spip.org/@boites_de_config_articles function boites_de_config_articles($id_article) { - $nb_forums = spip_fetch_array(spip_query("SELECT COUNT(*) AS count FROM spip_forum WHERE id_article=$id_article AND statut IN ('publie', 'off', 'prop')")); $nb_signatures = spip_fetch_array(spip_query("SELECT COUNT(*) AS count FROM spip_signatures WHERE id_article=$id_article AND statut IN ('publie', 'poubelle')")); @@ -429,7 +431,6 @@ function titres_articles($titre, $statut_article,$surtitre, $soustitre, $descrip . "</td>\n"; } - $res .= "</tr></table>\n"; return $res; } diff --git a/ecrire/exec/auteurs_edit.php b/ecrire/exec/auteurs_edit.php index 3e69bcfad2..5d9137e0cb 100644 --- a/ecrire/exec/auteurs_edit.php +++ b/ecrire/exec/auteurs_edit.php @@ -45,9 +45,8 @@ function exec_auteurs_edit_dist() cadre_auteur_infos($id_auteur, $auteur); if (statut_modifiable_auteur($id_auteur, $auteur) AND ($spip_display != 4)) { - include_spip('inc/chercher_logo'); - echo afficher_boite_logo('id_auteur', $id_auteur, - _T('logo_auteur').aide ("logoart"), _T('logo_survol'), 'auteurs_edit'); + $iconifier = charger_fonction('iconifier', 'inc'); + echo $iconifier('id_auteur', $id_auteur, 'auteurs_edit'); } echo pipeline('affiche_gauche', diff --git a/ecrire/exec/breves_voir.php b/ecrire/exec/breves_voir.php index 7b49db5f36..e612481bcc 100644 --- a/ecrire/exec/breves_voir.php +++ b/ecrire/exec/breves_voir.php @@ -71,10 +71,8 @@ fin_boite_info(); // if (($spip_display != 4) AND $id_breve>0 AND ($connect_statut == '0minirezo' AND acces_rubrique($id_rubrique))) { - include_spip('inc/chercher_logo'); - echo afficher_boite_logo('id_breve', $id_breve, - _T('logo_breve').aide ("breveslogo"), - _T('logo_survol'), 'breves_voir'); + $iconifier = charger_fonction('iconifier', 'inc'); + echo $iconifier('id_breve', $id_breve, 'breves_voir'); } debut_raccourcis(); diff --git a/ecrire/exec/configuration.php b/ecrire/exec/configuration.php index 1a0830f58f..1f354973f5 100644 --- a/ecrire/exec/configuration.php +++ b/ecrire/exec/configuration.php @@ -61,8 +61,8 @@ debut_gauche(); // Le logo de notre site, c'est site{on,off}0.{gif,png,jpg} // if ($spip_display != 4) { - include_spip('inc/chercher_logo'); - echo afficher_boite_logo('id_syndic', 0, _T('logo_site'), _T('logo_survol'), 'configuration'); + $iconifier = charger_fonction('iconifier', 'inc'); + echo $iconifier('id_syndic', 0, 'configuration'); } echo pipeline('affiche_gauche',array('args'=>array('exec'=>'configuration'),'data'=>'')); diff --git a/ecrire/exec/mots_edit.php b/ecrire/exec/mots_edit.php index 91a212c909..4dca6c01f1 100644 --- a/ecrire/exec/mots_edit.php +++ b/ecrire/exec/mots_edit.php @@ -133,8 +133,8 @@ if ($id_mot) { // if ($id_mot > 0 AND acces_mots() AND ($spip_display != 4)) { - include_spip('inc/chercher_logo'); - echo afficher_boite_logo('id_mot', $id_mot, _T('logo_mot_cle').aide("breveslogo"), _T('logo_survol'), 'mots_edit'); + $iconifier = charger_fonction('iconifier', 'inc'); + echo $iconifier('id_mot', $id_mot, 'mots_edit'); } // diff --git a/ecrire/exec/naviguer.php b/ecrire/exec/naviguer.php index 580487f60d..98ebf7e3d6 100644 --- a/ecrire/exec/naviguer.php +++ b/ecrire/exec/naviguer.php @@ -107,8 +107,8 @@ function exec_naviguer_dist() // Logos de la rubrique // if ($flag_editable AND ($spip_display != 4)) { - include_spip('inc/chercher_logo'); - echo afficher_boite_logo('id_rubrique', $id_rubrique, ($id_rubrique ? _T('logo_rubrique') : _T('logo_standard_rubrique'))." ".aide ("rublogo"), _T('logo_survol'), 'naviguer'); + $iconifier = charger_fonction('iconifier', 'inc'); + echo $iconifier('id_rubrique', $id_rubrique, 'naviguer'); } // diff --git a/ecrire/exec/sites.php b/ecrire/exec/sites.php index 5134164fc2..4ef3f654a8 100644 --- a/ecrire/exec/sites.php +++ b/ecrire/exec/sites.php @@ -255,8 +255,8 @@ echo "<p><center>"; echo "</center>"; if ($id_syndic AND $flag_administrable AND ($spip_display != 4)) { - include_spip('inc/chercher_logo'); - echo afficher_boite_logo('id_syndic', $id_syndic, _T('logo_site')." ".aide ("rublogo"), _T('logo_survol'), 'sites'); + $iconifier = charger_fonction('iconifier', 'inc'); + echo $iconifier('id_syndic', $id_syndic, 'sites'); } echo pipeline('affiche_gauche',array('args'=>array('exec'=>'sites','id_syndic'=>$id_syndic),'data'=>'')); diff --git a/ecrire/fragments/iconifier.php b/ecrire/fragments/iconifier.php new file mode 100644 index 0000000000..d5dbaa1de3 --- /dev/null +++ b/ecrire/fragments/iconifier.php @@ -0,0 +1,52 @@ +<?php + +/***************************************************************************\ + * SPIP, Systeme de publication pour l'internet * + * * + * Copyright (c) 2001-2006 * + * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * + * * + * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * + * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * +\***************************************************************************/ + +if (!defined("_ECRIRE_INC_VERSION")) return; + +include_spip('inc/presentation'); +include_spip('inc/texte'); + +function fragments_iconifier_dist() +{ + global $connect_id_auteur, $connect_toutes_rubriques;; + + $script = _request("script"); + $type = _request("type"); + $id = intval(_request($type)); + + if (!preg_match('/^\w+$/', "$type$script")) + die(_T('info_acces_interdit')); + + if ($type == 'id_rubrique') + $droit = acces_rubrique($id_rubrique); + elseif ($type == 'id_auteur') + $droit = (($id == $connect_id_auteur) OR $connect_toutes_rubriques); + elseif ($type == 'id_mot') + $droit = $connect_toutes_rubriques; + else { + $table=substr($type, 3) . (($type == 'id_syndic') ? '' : 's'); + $row = spip_fetch_array(spip_query("SELECT id_rubrique, statut FROM spip_$table WHERE $type=$id")); + $droit = acces_rubrique($row['id_rubrique']); + if (!$droit AND ($row['statut'] == 'prepa' OR $row['statut'] == 'prop' OR $row['statut'] == 'poubelle')) + $droit = spip_num_rows(spip_query("SELECT id_auteur FROM spip_auteurs_articles WHERE id_article=$id_article AND id_auteur=$connect_id_auteur LIMIT 1")); + } + + if (!$droit) { + spip_log("Tentative d'intrusion de " . $GLOBALS['auteur_session']['nom'] . " dans " . $GLOBALS['exec']); + include_spip('inc/minipres'); + minipres(_T('info_acces_interdit')); + } + + $f = charger_fonction('iconifier', 'inc'); + return $f($type, $id, $script); +} +?> diff --git a/ecrire/fragments/informer.php b/ecrire/fragments/informer.php index 72adaa1d1f..25b2005191 100644 --- a/ecrire/fragments/informer.php +++ b/ecrire/fragments/informer.php @@ -45,9 +45,12 @@ function fragments_informer_dist() $corps .= "<div class='arial2' style='padding: 5px; background-color: white; border: 1px solid $couleur_foncee; border-top: 0px;'>"; if ($type == "rubrique" AND $spip_display != 1 AND $spip_display!=4 AND $GLOBALS['meta']['image_process'] != "non") { $logo_f = charger_fonction('chercher_logo', 'inc'); - if ($res = $logo_f($id, 'id_rubrique', 'on')) - if ($res = decrire_logo("id_rubrique", 'on', $id, 100, 48, $res)) + if ($res = $logo_f($id, 'id_rubrique', 'on')) { + list($fid, $dir, $nom, $format) = $res; + $res = ratio_image($fid, $nom, $format, 100, 48, "alt=''"); + if ($res) $corps .= "<div style='float: $spip_lang_right; margin-$spip_lang_right: -5px; margin-top: -5px;'>$res</div>"; + } } $corps .= "<div><p><b>$titre</b></p></div>"; diff --git a/ecrire/inc/chercher_logo.php b/ecrire/inc/chercher_logo.php index c6119a5450..f2745cc9e1 100644 --- a/ecrire/inc/chercher_logo.php +++ b/ecrire/inc/chercher_logo.php @@ -12,7 +12,7 @@ if (!defined("_ECRIRE_INC_VERSION")) return; -include_spip('inc/actions'); +include_spip('inc/logos'); // http://doc.spip.org/@inc_chercher_logo_dist function inc_chercher_logo_dist($id, $type, $mode='on') { @@ -40,167 +40,4 @@ $table_logos = array( 'id_rubrique' => 'rub' ); -// http://doc.spip.org/@decrire_logo -function decrire_logo($id_objet, $mode, $id, $width, $height, $img, $titre="", $script="") { - - list($fid, $dir, $nom, $format) = $img; - - $res = ratio_image($fid, $nom, $format, $width, $height, "alt=''"); - if (!$titre) - return $res; - else { - if ($res) - $res = "<div><a href='" . $fid . "'>$res</a></div>"; - else - $res = "<img src='$fid' width='$width' height='$height' alt=\"" . htmlentities($titre) . '" />'; - if ($taille = @getimagesize($fid)) - $taille = _T('info_largeur_vignette', array('largeur_vignette' => $taille[0], 'hauteur_vignette' => $taille[1])); - return "<p><center>$res" . - debut_block_invisible($mode) . - "<font size='1'>" . - $taille . - "\n<br />[<a href='" . - redirige_action_auteur("iconifier", "unlink $nom.$format", $script, "$id_objet=$id") . - "'>". - _T('lien_supprimer') . - "</a>]</font>" . - fin_block() . - "</center></p>"; - } -} - - -// http://doc.spip.org/@afficher_boite_logo -function afficher_boite_logo($id_objet, $id, $texteon, $texteoff, $script) { - - $logo_f = charger_fonction('chercher_logo', 'inc'); - - $res = "<p>" . - debut_cadre_relief("image-24.gif", true) . - "<div class='verdana1' style='text-align: center;'>" . - bouton_block_invisible('on') . "<b>" . $texteon . "</b>"; - - if ($logo = $logo_f($id, $id_objet, 'on')) - $logo = decrire_logo($id_objet,'on',$id, 170, 170, $logo, $texteon, $script); - - if (!$logo) { - $res .= indiquer_logo($texteon, $id_objet, 'on', $id, $script); - - } else { - $res .= $logo; - if ($texteoff) { - $res .= "<br /><br />" . - bouton_block_invisible('off') . "<b>" . $texteoff . "</b>"; - if ($logo = $logo_f($id, $id_objet, 'off')) - $logo = decrire_logo($id_objet,'off',$id, 170, 170, $logo, $texteoff, $script); - if ($logo) { - $res .= $logo; - } - else $res .= indiquer_logo($texteoff, $id_objet, 'off', $id, $script); - } - } - - $res .= "</div>" . fin_cadre_relief(true) . "</p>"; - return $res; -} - -// http://doc.spip.org/@indiquer_logo -function indiquer_logo($titre, $id_objet, $mode, $id, $script) { - - global $formats_logos; - $dir_ftp = determine_upload(); - $afficher = ""; - $reg = '[.](' . join('|', $formats_logos) . ')$'; - - if ($dir_ftp - AND $fichiers = preg_files($dir_ftp, $reg)) { - foreach ($fichiers as $f) { - $f = substr($f, strlen($dir_ftp)); - $afficher .= "\n<option value='$f'>$f</option>"; - } - } - if (!$afficher) { - if ($dir_ftp) - $afficher = _T('info_installer_images_dossier', - array('upload' => '<b>' . joli_repertoire($dir_ftp) . '</b>')); - } else { - $afficher = "\n<div style='text-align: left'>" . - _T('info_selectionner_fichier', - array('upload' => '<b>' . joli_repertoire($dir_ftp) . '</b>')) . - ":</div>" . - "\n<select name='source' CLASS='forml' size='1'>$afficher\n</select>" . - "\n<div align='" . - $GLOBALS['spip_lang_right'] . - "'><input name='sousaction2' type='submit' value='". - _T('bouton_choisir') . - "' CLASS='fondo' style='font-size:9px' /></div>"; - } - $afficher = "\n" . - _T('info_telecharger_nouveau_logo') . - "<br />" . - "\n<input name='image' type='File' class='forml' style='font-size:9px;' size='15'>" . - "<div align='" . $GLOBALS['spip_lang_right'] . "'>" . - "\n<input name='sousaction1' type='submit' value='" . - _T('bouton_telecharger') . - "' class='fondo' style='font-size:9px' /></div>" . - $afficher; - - $type = $GLOBALS['table_logos'][$id_objet]; - return debut_block_invisible($mode) . - generer_action_auteur('iconifier', - "$type$mode$id", - generer_url_ecrire($script, "$id_objet=$id"), - $afficher, - " method='POST' ENCTYPE='multipart/form-data'") . - fin_block(); -} - - -// Calculer le ratio -// http://doc.spip.org/@image_ratio -function image_ratio ($srcWidth, $srcHeight, $maxWidth, $maxHeight) { - $ratioWidth = $srcWidth/$maxWidth; - $ratioHeight = $srcHeight/$maxHeight; - - if ($ratioWidth <=1 AND $ratioHeight <=1) { - $destWidth = $srcWidth; - $destHeight = $srcHeight; - } else if ($ratioWidth < $ratioHeight) { - $destWidth = $srcWidth/$ratioHeight; - $destHeight = $maxHeight; - } - else { - $destWidth = $maxWidth; - $destHeight = $srcHeight/$ratioWidth; - } - return array (ceil($destWidth), ceil($destHeight), - max($ratioWidth,$ratioHeight)); -} - -// http://doc.spip.org/@ratio_image -function ratio_image($logo, $nom, $format, $taille, $taille_y, $attributs) -{ - if (!$taille_origine = @getimagesize($logo)) return ''; - list ($destWidth,$destHeight, $ratio) = image_ratio($taille_origine[0], $taille_origine[1], $taille, $taille_y); - - // Creer effectivement la vignette reduite - - include_spip('inc/logos'); - $suffixe = '-'.$destWidth.'x'.$destHeight; - $preview = creer_vignette($logo, $taille, $taille_y, $format, ('cache'.$suffixe), $nom.$suffixe); - if ($preview) { - $logo = $preview['fichier']; - $destWidth = $preview['width']; - $destHeight = $preview['height']; - } - - // dans l'espace prive mettre un timestamp sur l'adresse - // de l'image, de facon a tromper le cache du navigateur - // quand on fait supprimer/reuploader un logo - // (pas de filemtime si SAFE MODE) - $date = _DIR_RESTREINT ? '' : ('?date='.@filemtime($logo)); - return "<img src='$logo$date' width='".$destWidth."' height='".$destHeight."'$attributs />"; -} - - ?> diff --git a/ecrire/inc/iconifier.php b/ecrire/inc/iconifier.php new file mode 100644 index 0000000000..5814a26810 --- /dev/null +++ b/ecrire/inc/iconifier.php @@ -0,0 +1,138 @@ +<?php + +/***************************************************************************\ + * SPIP, Systeme de publication pour l'internet * + * * + * Copyright (c) 2001-2006 * + * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * + * * + * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * + * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * +\***************************************************************************/ + +if (!defined("_ECRIRE_INC_VERSION")) return; + +include_spip('inc/actions'); + +function inc_iconifier_dist($id_objet, $id, $script) { + + $texteon = $GLOBALS['logo_libelles'][($id OR $id_objet != 'id_rubrique') ? $id_objet : 'id_racine']; + + $logo_f = charger_fonction('chercher_logo', 'inc'); + + $res = + debut_cadre_relief("image-24.gif", true) . + "<div class='verdana1' style='text-align: center;'>" . + bouton_block_invisible('on') . "<b>" . $texteon . "</b>"; + + if ($logo = $logo_f($id, $id_objet, 'on')) + $logo = decrire_logo($id_objet,'on',$id, 170, 170, $logo, $texteon, $script); + + if (!$logo) { + $res .= indiquer_logo($texteon, $id_objet, 'on', $id, $script); + + } else { + $texteoff = _T('logo_survol'); + $res .= $logo + . "<br /><br />" + . bouton_block_invisible('off') . "<b>" . $texteoff . "</b>"; + + if ($logo = $logo_f($id, $id_objet, 'off')) + $logo = decrire_logo($id_objet,'off',$id, 170, 170, $logo, $texteoff, $script); + if ($logo) + $res .= $logo; + else $res .= indiquer_logo(_T('logo_survol'), $id_objet, 'off', $id, $script); + } + + $res .= "</div>" . fin_cadre_relief(true); + + return (_request('var_ajaxcharset')) + ? $res + : "<div id='iconifier-$id'>$res</div>"; +} + +global $logo_libelles; +$logo_libelles = array( + 'id_article' => _T('logo_article').aide ("logoart"), + 'id_auteur' => _T('logo_auteur').aide ("logoart"), + 'id_breve' => _T('logo_breve').aide ("breveslogo"), + 'id_syndic' => _T('logo_site')." ".aide ("rublogo"), + 'id_mot' => _T('logo_mot_cle').aide("breveslogo"), + 'id_rubrique' => _T('logo_rubrique')." ".aide ("rublogo"), + 'id_racine' => _T('logo_standard_rubrique')." ".aide ("rublogo") + ); + +// http://doc.spip.org/@indiquer_logo +function indiquer_logo($titre, $id_objet, $mode, $id, $script) { + + global $formats_logos; + $dir_ftp = determine_upload(); + $afficher = ""; + $reg = '[.](' . join('|', $formats_logos) . ')$'; + + if ($dir_ftp + AND $fichiers = preg_files($dir_ftp, $reg)) { + foreach ($fichiers as $f) { + $f = substr($f, strlen($dir_ftp)); + $afficher .= "\n<option value='$f'>$f</option>"; + } + } + if (!$afficher) { + if ($dir_ftp) + $afficher = _T('info_installer_images_dossier', + array('upload' => '<b>' . joli_repertoire($dir_ftp) . '</b>')); + } else { + $afficher = "\n<div style='text-align: left'>" . + _T('info_selectionner_fichier', + array('upload' => '<b>' . joli_repertoire($dir_ftp) . '</b>')) . + ":</div>" . + "\n<select name='source' CLASS='forml' size='1'>$afficher\n</select>" . + "\n<div align='" . + $GLOBALS['spip_lang_right'] . + "'><input name='sousaction2' type='submit' value='". + _T('bouton_choisir') . + "' CLASS='fondo' style='font-size:9px' /></div>"; + } + $afficher = "\n" . + _T('info_telecharger_nouveau_logo') . + "<br />" . + "\n<input name='image' type='File' class='forml' style='font-size:9px;' size='15'>" . + "<div align='" . $GLOBALS['spip_lang_right'] . "'>" . + "\n<input name='sousaction1' type='submit' value='" . + _T('bouton_telecharger') . + "' class='fondo' style='font-size:9px' /></div>" . + $afficher; + + $type = $GLOBALS['table_logos'][$id_objet]; + return debut_block_invisible($mode) . + generer_action_auteur('iconifier', + "$id+$type$mode$id", + generer_url_ecrire($script, "$id_objet=$id"), + $afficher, + " method='POST' ENCTYPE='multipart/form-data'") . + fin_block(); +} + +// http://doc.spip.org/@decrire_logo +function decrire_logo($id_objet, $mode, $id, $width, $height, $img, $titre="", $script="") { + + list($fid, $dir, $nom, $format) = $img; + + $res = ratio_image($fid, $nom, $format, $width, $height, "alt=''"); + if ($res) + $res = "<div><a href='" . $fid . "'>$res</a></div>"; + else + $res = "<img src='$fid' width='$width' height='$height' alt=\"" . htmlentities($titre) . '" />'; + if ($taille = @getimagesize($fid)) + $taille = _T('info_largeur_vignette', array('largeur_vignette' => $taille[0], 'hauteur_vignette' => $taille[1])); + return "<p><center>$res" . + debut_block_invisible($mode) . + "<font size='1'>" . + $taille . + "\n<br />[" . + ajax_action_auteur("iconifier", "$id-$nom.$format", $script, "$id_objet=$id&type=$id_objet", array(_T('lien_supprimer'))) . + "]</font>" . + fin_block() . + "</center></p>"; +} +?> diff --git a/ecrire/inc/logos.php b/ecrire/inc/logos.php index 262e3e9c6c..615f0adf39 100644 --- a/ecrire/inc/logos.php +++ b/ecrire/inc/logos.php @@ -429,4 +429,50 @@ function reduire_image_logo($img, $taille = -1, $taille_y = -1, $cherche_image=t return "<img src='$logo$date'$attributs />"; } + +// Calculer le ratio +// http://doc.spip.org/@image_ratio +function image_ratio ($srcWidth, $srcHeight, $maxWidth, $maxHeight) { + $ratioWidth = $srcWidth/$maxWidth; + $ratioHeight = $srcHeight/$maxHeight; + + if ($ratioWidth <=1 AND $ratioHeight <=1) { + $destWidth = $srcWidth; + $destHeight = $srcHeight; + } else if ($ratioWidth < $ratioHeight) { + $destWidth = $srcWidth/$ratioHeight; + $destHeight = $maxHeight; + } + else { + $destWidth = $maxWidth; + $destHeight = $srcHeight/$ratioWidth; + } + return array (ceil($destWidth), ceil($destHeight), + max($ratioWidth,$ratioHeight)); +} + +// http://doc.spip.org/@ratio_image +function ratio_image($logo, $nom, $format, $taille, $taille_y, $attributs) +{ + if (!$taille_origine = @getimagesize($logo)) return ''; + list ($destWidth,$destHeight, $ratio) = image_ratio($taille_origine[0], $taille_origine[1], $taille, $taille_y); + + // Creer effectivement la vignette reduite + + $suffixe = '-'.$destWidth.'x'.$destHeight; + $preview = creer_vignette($logo, $taille, $taille_y, $format, ('cache'.$suffixe), $nom.$suffixe); + if ($preview) { + $logo = $preview['fichier']; + $destWidth = $preview['width']; + $destHeight = $preview['height']; + } + + // dans l'espace prive mettre un timestamp sur l'adresse + // de l'image, de facon a tromper le cache du navigateur + // quand on fait supprimer/reuploader un logo + // (pas de filemtime si SAFE MODE) + $date = _DIR_RESTREINT ? '' : ('?date='.@filemtime($logo)); + return "<img src='$logo$date' width='".$destWidth."' height='".$destHeight."'$attributs />"; +} + ?> diff --git a/ecrire/inc/presentation.php b/ecrire/inc/presentation.php index 36ab0b2530..4ed6572288 100644 --- a/ecrire/inc/presentation.php +++ b/ecrire/inc/presentation.php @@ -939,9 +939,12 @@ function afficher_articles_boucle($row, &$tous_id, $afficher_auteurs, $afficher_ if ($voir_logo) { $logo_f = charger_fonction('chercher_logo', 'inc'); - if ($logo = $logo_f($id_article, 'id_article', 'on')) - if ($logo = decrire_logo("id_article", 'on', $id_article, 26, 20, $logo)) + if ($logo = $logo_f($id_article, 'id_article', 'on')) { + list($fid, $dir, $nom, $format) = $logo; + $logo = ratio_image($fid, $nom, $format, 26, 20, "alt=''"); + if ($logo) $s .= "<div style='float: $spip_lang_right; margin-top: -2px; margin-bottom: -2px;'>$logo</div>"; + } } $s .= typo($titre); @@ -1229,9 +1232,12 @@ function afficher_breves_boucle($row, &$tous_id, $voir_logo, $own) if ($voir_logo) { $logo_f = charger_fonction('chercher_logo', 'inc'); - if ($logo = $logo_f($id_breve, 'id_breve', 'on')) - if ($logo = decrire_logo("id_breve", 'on', $id_breve, 26, 20, $logo)) + if ($logo = $logo_f($id_breve, 'id_breve', 'on')) { + list($fid, $dir, $nom, $format) = $logo; + $logo = ratio_image($fid, $nom, $format, 26, 20, "alt=''"); + if ($logo) $s .= "<div style='float: $spip_lang_right; margin-top: -2px; margin-bottom: -2px;'>$logo</div>"; + } } $s .= typo($titre); @@ -1504,9 +1510,12 @@ function afficher_forum_thread($row, $controle_id_article, $compteur_forum, $nb_ $titre_boite = ''; if ($id_auteur AND $voir_logo) { $logo_f = charger_fonction('chercher_logo', 'inc'); - if ($logo = $logo_f($id_auteur, 'id_auteur', 'on')) - if ($logo = decrire_logo("id_auteur", 'on', $id_auteur, 48, 48, $logo)) + if ($logo = $logo_f($id_auteur, 'id_auteur', 'on')) { + list($fid, $dir, $nom, $format) = $logo; + $logo = ratio_image($fid, $nom, $format, 48, 48, "alt=''"); + if ($logo) $titre_boite = "<div style='$voir_logo'>$logo</div>" ; + } } $titre_boite .= typo($titre); diff --git a/ecrire/inc/rubriques.php b/ecrire/inc/rubriques.php index a60f20ddb1..a58f598aa9 100644 --- a/ecrire/inc/rubriques.php +++ b/ecrire/inc/rubriques.php @@ -251,10 +251,14 @@ function enfant_rub($collection){ if ($spip_display == 4) $les_enfants .= "<li>"; + if ($voir_logo) { - if ($logo = $logo_f($id_rubrique, $id_rubrique, 'on')) - if ($logo = decrire_logo("id_rubrique", 'on', $id_rubrique, 48, 36, $logo)) - $logo = "<div style='$voir_logo'>$logo</div>"; + if ($logo = $logo_f($id_rubrique, 'id_rubrique', 'on')) { + list($fid, $dir, $nom, $format) = $logo; + $logo = ratio_image($fid, $nom, $format, 48, 36, "alt=''"); + if ($logo) + $logo = "<div style='$voir_logo'>$logo</div>"; + } } $les_enfants .= "<div class='enfants'>" . debut_cadre_sous_rub(($id_parent ? "rubrique-24.gif" : "secteur-24.gif"), true) . diff --git a/ecrire/inc/sites_voir.php b/ecrire/inc/sites_voir.php index 08a5101640..ca91fa994a 100644 --- a/ecrire/inc/sites_voir.php +++ b/ecrire/inc/sites_voir.php @@ -73,9 +73,12 @@ function afficher_sites_boucle($row, &$tous_id, $voir_logo, $bof) if ($voir_logo) { $logo_f = charger_fonction('chercher_logo', 'inc'); - if ($logo = $logo_f($id_syndic, $id_syndic, 'on')) - if ($logo = decrire_logo("id_syndic", 'on', $id_syndic, 26, 20, $logo)) + if ($logo = $logo_f($id_syndic, $id_syndic, 'on')) { + list($fid, $dir, $nom, $format) = $logo; + $logo = ratio_image($fid, $nom, $format, 26, 20, "alt=''"); + if ($logo) $s .= "<div style='float: $spip_lang_right; margin-top: -2px; margin-bottom: -2px;'>$logo</div>"; + } } $s .= http_img_pack($puce, $statut, "width='7' height='7'") ." "; -- GitLab