[198] | 1 | <?php |
---|
| 2 | /***************************************************************************\ |
---|
| 3 | Plugin : magusine |
---|
| 4 | Licence : GPL |
---|
| 5 | Auteurs : Stéphane Noël, Philippe Vanderlinden |
---|
| 6 | Infos : http://www.spip-contrib.net/Le-plugin-Magusine |
---|
| 7 | http://www.magunews.net/spip.php?rubrique645 |
---|
| 8 | |
---|
| 9 | $LastChangedRevision: 12345 $ |
---|
| 10 | $LastChangedBy: bubu $ |
---|
| 11 | $LastChangedDate: 2008-03-21 15:50:47 +0100 (ven, 21 mar 2008) $ |
---|
| 12 | \***************************************************************************/ |
---|
| 13 | |
---|
| 14 | include_spip('inc/xml-parser'); |
---|
| 15 | include_spip('inc/cherche-theme'); |
---|
| 16 | |
---|
| 17 | function arty_ajouterHeader($flux) { |
---|
| 18 | |
---|
| 19 | $theme=theme_actuel(); |
---|
| 20 | $head = generer_head($theme); |
---|
| 21 | return $flux.=$head; |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | function generer_head($theme) { |
---|
| 25 | $morceaux=explode("|", $theme); |
---|
| 26 | if (count($morceaux)==1) { |
---|
| 27 | //le theme est un theme plein, pas de declinaison |
---|
| 28 | $dossier=$morceaux[0]; |
---|
| 29 | $declinaison=FALSE; |
---|
| 30 | } else { |
---|
| 31 | // le theme est une declinaison |
---|
| 32 | $dossier=$morceaux[0]; |
---|
| 33 | $declinaison=$morceaux[1]; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | // scripts ie7 |
---|
| 37 | $inclusion_theme ="<!-- plugin magusine developpe par les corsaires asbl http://www.magusine.net-->\n"; |
---|
| 38 | $inclusion_theme .="<!-- compliance patch for microsoft browsers -->\n"; |
---|
| 39 | $inclusion_theme .="<!--[if lt IE 7]><script src='ie7/ie7-standard-p.js' type='text/javascript'></script><![endif]-->\n"; |
---|
| 40 | |
---|
| 41 | // fichier javascript de base |
---|
| 42 | $print=""; |
---|
| 43 | $inclusion_theme .="\n"; |
---|
| 44 | $inclusion_theme .="<script src='"._DIR_PLUGIN_ARTY."javascript/javascript-public.js' type='text/javascript' language='javascript'></script>\n"; |
---|
| 45 | $inclusion_theme .="<script src='"._DIR_PLUGIN_ARTY."javascript/thickbox.js' type='text/javascript' language='javascript'></script>\n"; |
---|
| 46 | |
---|
| 47 | // dans le theme |
---|
| 48 | $inclusion_theme .=generejavacss(_DIR_PLUGIN_ARTY."themes/".$dossier); |
---|
| 49 | // ajouter la declinaison |
---|
| 50 | if ($declinaison) { |
---|
| 51 | $inclusion_theme .= "<link href='"._DIR_PLUGIN_ARTY."themes/".$dossier."/declinaisons/".$declinaison."' rel='stylesheet' type='text/css' media='screen' />\n"; |
---|
| 52 | } |
---|
| 53 | //dans le dossier pages-custom |
---|
| 54 | $inclusion_theme .=generejavacss("pages-custom"); |
---|
| 55 | |
---|
| 56 | if(!ereg("media='print'",$inclusion_theme)){ |
---|
| 57 | $inclusion_theme .="<link href='"._DIR_PLUGIN_ARTY."css/print.css' rel='stylesheet' type='text/css' media='print' />\n"; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | $larubbandeau=trouvelarub(); |
---|
| 61 | $lebandeau=trouver_bandeau($larubbandeau); |
---|
| 62 | if($lebandeau){ |
---|
| 63 | $lebandeau ="<style type='text/css'> |
---|
| 64 | <!-- |
---|
| 65 | #bandeau { background-image: url(.$lebandeau); } |
---|
| 66 | --> |
---|
| 67 | </style>"; |
---|
| 68 | |
---|
| 69 | $inclusion_theme .=$lebandeau; |
---|
| 70 | } |
---|
| 71 | return $inclusion_theme; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | function trouver_bandeau($id_rubrique){ |
---|
| 75 | $url_bandeau = false; |
---|
| 76 | $extensions = Array("jpg","png","gif"); |
---|
| 77 | $id_parent = $id_rubrique; |
---|
| 78 | |
---|
| 79 | // TODO : mazu Gestion db devrait alléger le processus |
---|
| 80 | if($id_parent >= 0){ |
---|
| 81 | foreach($extensions as $ext){ |
---|
| 82 | if (file_exists(_DIR_IMG."bandeau/bandeau-$id_rubrique.$ext")){ |
---|
| 83 | $url_bandeau = "/"._DIR_IMG."bandeau/bandeau-$id_rubrique.$ext"; |
---|
| 84 | return $url_bandeau; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | while($id_parent != 0) { |
---|
| 89 | // un bandeau est-il présent pour cette rubrique? |
---|
| 90 | foreach($extensions as $ext){ |
---|
| 91 | if (file_exists(_DIR_IMG."bandeau/bandeau-$id_rubrique.$ext")){ |
---|
| 92 | $url_bandeau = "/"._DIR_IMG."bandeau/bandeau-$id_rubrique.$ext"; |
---|
| 93 | return $url_bandeau; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | // sinon, continuer et vérifier pour le parent |
---|
| 97 | $result = spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$id_rubrique"); |
---|
| 98 | $row = spip_fetch_array($result); |
---|
| 99 | $id_parent = $row['id_parent']; |
---|
| 100 | $id_rubrique = $id_parent; |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | // aucun bandeau spécifique n'a été trouvé |
---|
| 104 | foreach($extensions as $ext){ |
---|
| 105 | if (file_exists(_DIR_IMG."bandeau/bandeau.".$ext)){ |
---|
| 106 | $url_bandeau = "/"._DIR_IMG."bandeau/bandeau.".$ext; |
---|
| 107 | } |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | return $url_bandeau; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | function trouvelarub() { |
---|
| 114 | if (isset($GLOBALS['contexte']['id_rubrique'])) { |
---|
| 115 | // si c'est une page rubrique, trouver le thÚme de la rubrique ou des rubriques parentes |
---|
| 116 | $id_rubrique = $GLOBALS['contexte']['id_rubrique']; |
---|
| 117 | } else if (isset($GLOBALS['contexte']['id_article'])) { |
---|
| 118 | // si c'est un article, trouver sa rubrique et ensuite son thÚme, ou le thÚme des rubriques parentes |
---|
| 119 | $result = spip_query("SELECT id_rubrique FROM spip_articles WHERE id_article='".addslashes($GLOBALS['contexte']['id_article'])."'"); |
---|
| 120 | $row = spip_fetch_array($result); |
---|
| 121 | $id_rubrique = $row['id_rubrique']; |
---|
| 122 | } else { |
---|
| 123 | $id_rubrique=0; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | return $id_rubrique; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | // lire le dossier, en extraire css et javascript |
---|
| 130 | function generejavacss($dossiertheme) { |
---|
| 131 | $inclusion_theme=""; |
---|
| 132 | if(is_dir($dossiertheme)){ |
---|
| 133 | $liste_ignore = Array(".","..",".DS_Store"); |
---|
| 134 | $handle = opendir($dossiertheme); |
---|
| 135 | while ($fichier=readdir($handle)){ |
---|
| 136 | if (!in_array($fichier, $liste_ignore)){ |
---|
| 137 | if (eregi("^[a-zA-Z0-9_-]*\.css$",$fichier)) { |
---|
| 138 | if ($fichier=="print.css") { |
---|
| 139 | $inclusion_theme .="<link href='".$dossiertheme."/".$fichier."' rel='stylesheet' type='text/css' media='print' />\n"; |
---|
| 140 | } else { |
---|
| 141 | $inclusion_theme .= "<link href='".$dossiertheme."/".$fichier."' rel='stylesheet' type='text/css' media='screen' />\n"; |
---|
| 142 | } |
---|
| 143 | } elseif (eregi("\.js$",$fichier)) { |
---|
| 144 | $inclusion_theme .="<script src='".$dossiertheme."/".$fichier."' type='text/javascript' language='javascript'></script>\n"; |
---|
| 145 | } elseif (eregi("\.ico$",$fichier)) { |
---|
| 146 | $inclusion_theme .="<link rel='shortcut icon' href='".$dossiertheme."/".$fichier."' />\n"; |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | return $inclusion_theme; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | ?> |
---|