Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | // Ce fichier est charge a chaque hit // | |
3 | ||
4 | // Compatibilites | |
5 | if (version_compare($GLOBALS['spip_version_code'],'1.9300','>=')) @define('_SPIP19300', 1); | |
6 | if (version_compare($GLOBALS['spip_version_code'],'1.9200','>=')) @define('_SPIP19200', 1); | |
7 | else @define('_SPIP19100', 1); | |
8 | ||
9 | // Pour forcer les logs du plugin, outil actif ou non : | |
10 | // define('_LOG_CS_FORCE', 'oui'); | |
11 | ||
12 | // Droits pour le Couteau Suisse | |
13 | function cout_autoriser() { | |
14 | return function_exists('autoriser') | |
15 | ?autoriser('configurer', 'plugins') | |
16 | :$GLOBALS['connect_statut'] == "0minirezo" && $GLOBALS["connect_toutes_rubriques"]; | |
17 | } | |
18 | ||
19 | // Logs de tmp/spip.log | |
20 | function cs_log($variable, $prefixe='', $stat='') { | |
21 | static $rand; | |
22 | if($stat) $rand = $stat; | |
23 | if((!defined('_LOG_CS') && !defined('_CS_REPORTALL')) || !strlen($variable)) return; | |
24 | if (!is_string($variable)) $variable = var_export($variable, true); | |
25 | spip_log($variable = $rand.$prefixe.$variable); | |
26 | if (defined('_CS_REPORTALL')) echo '<br/>',htmlentities($variable); | |
27 | } | |
28 | ||
29 | // liste des outils et des variables | |
30 | global $metas_vars, $metas_outils; | |
31 | if (!isset($GLOBALS['meta']['tweaks_actifs'])) { | |
32 | cs_log(" -- lecture metas"); | |
33 | include_spip('inc/meta'); | |
34 | lire_metas(); | |
35 | } | |
36 | $metas_outils = isset($GLOBALS['meta']['tweaks_actifs'])?unserialize($GLOBALS['meta']['tweaks_actifs']):array(); | |
37 | $metas_vars = isset($GLOBALS['meta']['tweaks_variables'])?unserialize($GLOBALS['meta']['tweaks_variables']):array(); | |
38 | ||
39 | // rss | |
40 | @define('_CS_RSS_SOURCE', 'http://zone.spip.org/trac/spip-zone/log/_plugins_/_stable_/couteau_suisse?format=rss&mode=stop_on_copy&limit=20'); | |
41 | // doc | |
42 | define('_URL_CONTRIB', 'http://www.spip-contrib.net/?article'); | |
43 | ||
44 | // chemin du fichier de fonctions | |
45 | define('_COUT_FONCTIONS_PHP', find_in_path('cout_fonctions.php')); | |
46 | $GLOBALS['cs_options'] = $GLOBALS['cs_fonctions'] = $GLOBALS['cs_fonctions_essai'] = $GLOBALS['cs_init'] = $GLOBALS['cs_verif'] = 0; | |
47 | ||
48 | // parametres concernant le plugin ? | |
49 | $GLOBALS['cs_params'] = isset($_GET['cs'])?explode(',', $_GET['cs']):array(); | |
50 | ||
51 | // pour voir les erreurs ? | |
52 | if (in_array('report', $GLOBALS['cs_params'])) | |
53 | { define('_CS_REPORT', 1); error_reporting(E_ALL ^ E_NOTICE); } | |
54 | elseif (in_array('reportall', $GLOBALS['cs_params']) && $auteur_session['statut']=='0minirezo') | |
55 | { define('_CS_REPORTALL', 1); error_reporting(E_ALL); } | |
56 | ||
57 | // on active tout de suite les logs, si l'outil est actif. | |
58 | if ($metas_outils['log_couteau_suisse']['actif'] || defined('_LOG_CS_FORCE') || in_array('log', $GLOBALS['cs_params'])) { | |
59 | define('_LOG_CS', 'oui'); | |
60 | cs_log(str_repeat('-', 80), '', sprintf('COUTEAU-SUISSE. [#%04X]. ', rand())); | |
61 | cs_log('INIT : cout_options, '.$_SERVER['REQUEST_URI']); | |
62 | } | |
63 | ||
64 | // fichiers/dossiers temporaires pour le Couteau Suisse | |
65 | @define('_DIR_CS_TMP', sous_repertoire(_DIR_TMP, "couteau-suisse")); | |
66 | ||
67 | // on passe son chemin si un reset general est demande | |
68 | $zap = (_request('cmd')=='resetall') | |
69 | // idem si la page est un css ou un js (sauf si le cache est desactive) | |
70 | || (!($metas_outils['spip_cache']['actif'] && $metas_vars['radio_desactive_cache3']) | |
71 | && (isset($_GET['page']) && preg_match(',(\.(css|js)$|style_prive(_ie)?),', $_GET['page']))); | |
72 | if($zap) { | |
73 | cs_log(' FIN : cout_options sans initialisation du plugin'); | |
74 | } else { | |
75 | // $cs_metas_pipelines ne sert qu'a l'execution et ne comporte que : | |
76 | // - le code pour <head></head> | |
77 | // - le code pour les pipelines utilises | |
78 | global $cs_metas_pipelines; | |
79 | $cs_metas_pipelines = array(); | |
80 | ||
81 | // alias pour passer en mode impression | |
82 | if ( in_array('print', $GLOBALS['cs_params']) || | |
83 | (isset($_GET['page']) && in_array($_GET['page'], array('print','imprimer','imprimir_articulo','imprimir_breve','article_pdf'))) | |
84 | ) define('_CS_PRINT', 1); | |
85 | ||
86 | // test sur le fichier a inclure ici | |
87 | $cs_exists = file_exists($f_cs = _DIR_CS_TMP.'mes_options.php'); | |
88 | ||
89 | // fonctions indispensables a l'execution | |
90 | include_spip('cout_lancement'); | |
91 | // lancer l'initialisation du plugin. on force la compilation si cs=calcul | |
92 | if(!$cs_exists) spip_log(" -- '$f_cs' introuvable !"); | |
93 | cs_initialisation(!$cs_exists || in_array('calcul', $GLOBALS['cs_params'])); | |
94 | cs_log("PUIS : cout_options, initialisation terminee"); | |
95 | ||
96 | // inclusion des options pre-compilees, si l'on n'est jamais passe par ici... | |
97 | if (!$GLOBALS['cs_options']) { | |
98 | ||
99 | if(file_exists($f_cs)) { | |
100 | cs_log(" -- inclusion de '$f_cs'"); | |
101 | include_once($f_cs); | |
102 | // verification des metas : reinitialisation si une erreur est detectee | |
103 | if (count($metas_outils)<>$GLOBALS['cs_verif']) { | |
104 | cs_log("ERREUR : metas incorrects - verif = $GLOBALS[cs_verif]"); | |
105 | cs_initialisation(true); | |
106 | if (!$GLOBALS['cs_verif']) include_once($f_cs); | |
107 | } | |
108 | } else { | |
109 | $GLOBALS['cs_utils'] = 0; | |
110 | cs_log(" -- fichier '$f_cs' toujours introuvable !!"); | |
111 | } | |
112 | } else cs_log(" -- pas d'inclusion de '$f_cs' ; on est deja passe par ici !?"); | |
113 | ||
114 | // si une recompilation a eu lieu avec succes... | |
115 | if ($GLOBALS['cs_utils']) { | |
116 | // lancer la procedure d'installation pour chaque outil | |
117 | cs_log(' -- cs_installe_outils...'); | |
118 | cs_installe_outils(); | |
119 | } | |
120 | ||
121 | // a-t-on voulu inclure cout_fonctions.php ? | |
122 | if ($GLOBALS['cs_fonctions_essai']) { | |
123 | cs_log(" -- inclusion de '"._COUT_FONCTIONS_PHP."'"); | |
124 | @include(_COUT_FONCTIONS_PHP); | |
125 | } | |
126 | ||
127 | cs_log(" FIN : cout_options, cs_options = $GLOBALS[cs_options], cs_fonctions_essai = $GLOBALS[cs_fonctions_essai]"); | |
128 | } | |
129 | ||
130 | ?> |