source: trunk/spip/esqueleto-redcta/plugins/magusine/arty_header.php @ 79

Last change on this file since 79 was 79, checked in by guille, 15 years ago
File size: 4.5 KB
Line 
1<?php
2include_spip('inc/xml-parser');
3include_spip('inc/cherche-theme');
4
5function arty_ajouterHeader($flux) {
6        $theme=theme_actuel();
7        $head = generer_head($theme);
8        return $flux.=$head;
9}
10       
11function generer_head($theme) {
12        $morceaux=explode("|", $theme);
13        if (count($morceaux)==1) {
14                //le theme est un theme plein, pas de declinaison
15                $dossier=$morceaux[0];
16                $declinaison=FALSE;
17        } else {
18                // le theme est une declinaison
19                        $dossier=$morceaux[0];
20                        $declinaison=$morceaux[1];
21        }
22       
23        // scripts ie7
24        $inclusion_theme ="<!-- plugin magusine developpe par les corsaires asbl http://www.magusine.net-->\n";
25        $inclusion_theme .="<!-- compliance patch for microsoft browsers -->\n";
26        $inclusion_theme .="<!--[if lt IE 7]><script src='ie7/ie7-standard-p.js' type='text/javascript'></script><![endif]-->\n";
27
28        // fichier javascript de base
29        $print="";
30        $inclusion_theme .="\n";
31        $inclusion_theme .="<script src='"._DIR_PLUGIN_ARTY."javascript/javascript-public.js' type='text/javascript' language='javascript'></script>\n";
32        $inclusion_theme .="<script src='"._DIR_PLUGIN_ARTY."javascript/thickbox.js' type='text/javascript' language='javascript'></script>\n";
33       
34        // dans le theme
35        $inclusion_theme .=generejavacss(_DIR_PLUGIN_ARTY."themes/".$dossier);
36        // ajouter la declinaison
37        if ($declinaison) {
38        $inclusion_theme .= "<link href='"._DIR_PLUGIN_ARTY."themes/".$dossier."/declinaisons/".$declinaison."' rel='stylesheet' type='text/css' media='screen' />\n";
39        }
40        //dans le dossier pages-custom
41        $inclusion_theme .=generejavacss("pages-custom");
42       
43    if(!ereg("media='print'",$inclusion_theme)){
44        $inclusion_theme .="<link href='"._DIR_PLUGIN_ARTY."css/print.css' rel='stylesheet' type='text/css' media='print' />\n";
45        }
46 
47        $larubbandeau=trouvelarub();
48        $lebandeau=trouver_bandeau($larubbandeau);
49        if($lebandeau){
50                $lebandeau ="<style type='text/css'>
51  <!--
52  #bandeau { background-image: url(.$lebandeau); }
53  -->
54  </style>";
55               
56        $inclusion_theme .=$lebandeau;
57        }
58        return $inclusion_theme;
59        }
60       
61function trouver_bandeau($id_rubrique){
62  $url_bandeau = false;
63  $extensions = Array("jpg","png","gif");
64  $id_parent = $id_rubrique;
65  while($id_parent != 0) {
66    // un bandeau est-il présent pour cette rubrique?
67    foreach($extensions as $ext){
68      if (file_exists(_DIR_DOC."bandeau/bandeau-$id_rubrique.$ext")){
69        $url_bandeau = "/"._DIR_DOC."bandeau/bandeau-$id_rubrique.$ext";
70        return $url_bandeau;
71      }
72    }
73    // sinon, continuer et vérifier pour le parent
74    $result = spip_query("SELECT id_parent FROM spip_rubriques WHERE id_rubrique=$id_rubrique");
75    $row = spip_fetch_array($result);
76    $id_parent = $row['id_parent'];
77    $id_rubrique = $id_parent;
78  }
79  // aucun bandeau spécifique n'a été trouvé
80  foreach($extensions as $ext){
81    if (file_exists(_DIR_DOC."bandeau/bandeau.".$ext)){
82      $url_bandeau = "/"._DIR_DOC."bandeau/bandeau.".$ext;
83    }
84  }
85  return $url_bandeau;
86}
87
88function trouvelarub() {
89if (isset($GLOBALS['id_rubrique'])) {
90    // si c'est une page rubrique, trouver le thÚme de la rubrique ou des rubriques parentes
91    $id_rubrique = $GLOBALS['id_rubrique'];
92  } else if (isset($GLOBALS['id_article'])) {
93    // si c'est un article, trouver sa rubrique et ensuite son thÚme, ou le thÚme des rubriques parentes
94    $result = spip_query("SELECT id_rubrique FROM spip_articles WHERE id_article='".addslashes($GLOBALS['id_article'])."'");
95    $row = spip_fetch_array($result);
96    $id_rubrique = $row['id_rubrique'];
97  } else {
98        $id_rubrique=0;
99  }
100 
101  return $id_rubrique;
102}
103
104// lire le dossier, en extraire css et javascript
105function generejavacss($dossiertheme) {
106$inclusion_theme="";
107        if(is_dir($dossiertheme)){
108                $liste_ignore = Array(".","..",".DS_Store");
109                $handle = opendir($dossiertheme);
110                while ($fichier=readdir($handle)){ 
111                if (!in_array($fichier, $liste_ignore)){
112                if (eregi("^[a-zA-Z0-9_-]*\.css$",$fichier)) {
113                if ($fichier=="print.css") {
114                $inclusion_theme .="<link href='".$dossiertheme."/".$fichier."' rel='stylesheet' type='text/css' media='print' />\n";
115                } else {
116                $inclusion_theme .= "<link href='".$dossiertheme."/".$fichier."' rel='stylesheet' type='text/css' media='screen' />\n";
117                }
118                } elseif (eregi("\.js$",$fichier)) {
119                        $inclusion_theme .="<script src='".$dossiertheme."/".$fichier."' type='text/javascript' language='javascript'></script>\n";
120                } elseif (eregi("\.ico$",$fichier)) {
121                        $inclusion_theme .="<link rel='shortcut icon' href='".$dossiertheme."/".$fichier."' />\n";
122                }
123        }
124        }
125  }
126        return $inclusion_theme;
127}
128
129?>
Note: See TracBrowser for help on using the repository browser.