[PLUGINS] ~maj globale
[lhc/web/www.git] / www / plugins / zen-garden-2 / zengarden_options.php
1 <?php
2 /**
3 * Plugin Zen-Garden pour Spip 3.0
4 * Licence GPL (c) 2006-2013 Cedric Morin
5 *
6 * Fichier des options du plugins
7 *
8 * @package SPIP\Zen-Garden\Options
9 */
10
11 if (!defined("_ECRIRE_INC_VERSION")) {
12 return;
13 }
14
15 if (!defined('_DIR_PLUGIN_THEME')){
16 // si on est en mode apercu, il suffit de repasser dans l'espace prive pour desactiver l'apercu
17 if (test_espace_prive()){
18 if (isset($_COOKIE['spip_zengarden_theme'])){
19 include_spip('inc/cookie');
20 spip_setcookie('spip_zengarden_theme',$_COOKIE['spip_zengarden_theme']='',-1);
21 }
22 }
23 // si le switcher est actif ou la globale var_theme
24 elseif(isset($GLOBALS['meta']['zengarden_switcher']) OR defined('_ZEN_VAR_THEME')){
25 if (!is_null($arg = _request('var_theme'))){
26 include_spip('inc/cookie');
27 if ($arg)
28 spip_setcookie('spip_zengarden_theme',$_COOKIE['spip_zengarden_theme'] = $arg);
29 else
30 spip_setcookie('spip_zengarden_theme',$_COOKIE['spip_zengarden_theme']='',-1);
31 }
32 }
33
34 // ajouter le theme au path
35 if (
36 (
37 // on est en mode apercu
38 (isset($_COOKIE['spip_zengarden_theme']) AND $t = $_COOKIE['spip_zengarden_theme'])
39 // ou avec le cookie du switcher
40 OR
41 // ou un theme est vraiment selectionne
42 (isset($GLOBALS['meta']['zengarden_theme']) AND $t = $GLOBALS['meta']['zengarden_theme'])
43 )
44 AND is_dir(_DIR_RACINE . $t)){
45 _chemin(_DIR_RACINE . $t);
46 $GLOBALS['marqueur'] = (isset($GLOBALS['marqueur'])?$GLOBALS['marqueur']:"").":theme-$t";
47 // @experimental : sauver le nom du repertoire theme utilise
48 // a defaut de connaitre le vrai prefixe
49 if (!defined('NOM_THEME')) { define('NOM_THEME', basename($t));}
50 }
51
52 // @experimental : balise #THEME qui retourne le nom du theme selectionne
53 function balise_THEME_dist($p){
54 $p->code = champ_sql('theme', $p,"(defined('NOM_THEME') ? NOM_THEME : '')");
55 return $p;
56 }
57 }
58
59 /**
60 * Insertion dans le pipeline affichage_final (SPIP)
61 *
62 * Ajoute le switcher de thème dans l'espace public
63 *
64 * @param string $texte
65 * Le contenu html de la page avant affichage au client
66 * @return string $texte
67 * Le contenu html de la page modifié
68 */
69 function zengarden_affichage_final($texte){
70 if ((!isset($GLOBALS['flag_preserver']) || $GLOBALS['flag_preserver'] != 1) && $GLOBALS['html'] and isset($GLOBALS['meta']['zengarden_switcher'])){
71 include_spip('prive/zengarden_theme_fonctions');
72 // on passe le theme selectionne en js pour ne pas polluer le cache du switcher
73 $theme = isset($_COOKIE['spip_zengarden_theme']) ? $_COOKIE['spip_zengarden_theme'] : '';
74 $code =
75 "<script type='text/javascript'>var theme_selected='$theme'</script>"
76 . recuperer_fond('inclure/zengarden_switcher');
77 // On rajoute le code du selecteur de squelettes avant la balise </body>
78 $texte=str_replace("</body>",$code."</body>",$texte);
79 }
80 return $texte;
81 }
82