Changeset 93626 in spip-zone for _core_/plugins/statistiques/stats_pipelines.php
- Timestamp:
- Dec 13, 2015, 11:56:49 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_core_/plugins/statistiques/stats_pipelines.php
r93100 r93626 3 3 /** 4 4 * Déclarations d'autorisations et utilisations de pipelines 5 * 5 * 6 6 * @plugin Statistiques pour SPIP 7 7 * @license GNU/GPL 8 8 * @package SPIP\Stats\Pipelines 9 **/ 10 11 if (!defined('_ECRIRE_INC_VERSION')) return; 9 **/ 10 11 if (!defined('_ECRIRE_INC_VERSION')) { 12 return; 13 } 12 14 13 15 … … 25 27 * @param array $entetes liste des entêtes de la page 26 28 * @return array 27 **/28 function stats_affichage_entetes_final($entetes) {29 **/ 30 function stats_affichage_entetes_final($entetes) { 29 31 if (isset($GLOBALS['meta']["activer_statistiques"]) and $GLOBALS['meta']["activer_statistiques"] != "non") { 30 32 $html = preg_match(',^\s*text/html,', $entetes['Content-Type']); … … 32 34 // decomptage des visites, on peut forcer a oui ou non avec le header X-Spip-Visites 33 35 // par defaut on ne compte que les pages en html (ce qui exclue les js,css et flux rss) 34 $spip_compter_visites = $html ?'oui':'non';35 if (isset($entetes['X-Spip-Visites'])) {36 $spip_compter_visites = in_array($entetes['X-Spip-Visites'], array('oui','non'))37 ? $entetes['X-Spip-Visites']38 : $spip_compter_visites;36 $spip_compter_visites = $html ? 'oui' : 'non'; 37 if (isset($entetes['X-Spip-Visites'])) { 38 $spip_compter_visites = in_array($entetes['X-Spip-Visites'], array('oui', 'non')) 39 ? $entetes['X-Spip-Visites'] 40 : $spip_compter_visites; 39 41 unset($entetes['X-Spip-Visites']); 40 42 } 41 43 42 44 // Gestion des statistiques du site public 43 if ($spip_compter_visites !='non') {45 if ($spip_compter_visites != 'non') { 44 46 $stats = charger_fonction('stats', 'public'); 45 47 $stats(); 46 48 } 47 49 } 50 48 51 return $entetes; 49 52 } … … 57 60 * 58 61 * @pipeline affiche_milieu 59 * @param array $flux 62 * @param array $flux Données du pipeline 60 63 * @return array Données du pipeline 61 **/62 function stats_affiche_milieu($flux) {64 **/ 65 function stats_affiche_milieu($flux) { 63 66 // afficher le formulaire de configuration (activer ou desactiver les statistiques). 64 67 if ($flux['args']['exec'] == 'configurer_avancees') { 65 $flux['data'] .= recuperer_fond('prive/squelettes/inclure/configurer',array('configurer'=>'configurer_compteur')); 68 $flux['data'] .= recuperer_fond('prive/squelettes/inclure/configurer', 69 array('configurer' => 'configurer_compteur')); 66 70 } 67 71 68 72 // afficher le formulaire de suppression des visites (configuration > maintenance du site). 69 73 if ($flux['args']['exec'] == 'admin_tech') { 70 $flux['data'] .= recuperer_fond('prive/squelettes/inclure/admin_effacer_stats',array()); 71 } 74 $flux['data'] .= recuperer_fond('prive/squelettes/inclure/admin_effacer_stats', array()); 75 } 76 72 77 return $flux; 73 78 } … … 79 84 * @uses admin_stats() 80 85 * @pipeline formulaire_admin 81 * @param array $flux 86 * @param array $flux Données du pipeline 82 87 * @return array Données du pipeline 83 **/88 **/ 84 89 function stats_formulaire_admin($flux) { 85 90 if ( 86 87 88 89 90 91 isset($flux['args']['contexte']['objet']) 92 AND $objet = $flux['args']['contexte']['objet'] 93 AND isset($flux['args']['contexte']['id_objet']) 94 AND $id_objet = $flux['args']['contexte']['id_objet'] 95 ) { 91 96 if ($l = admin_stats($objet, $id_objet, defined('_VAR_PREVIEW') ? _VAR_PREVIEW : '')) { 92 97 $btn = recuperer_fond('prive/bouton/statistiques', array( … … 95 100 'statistiques' => $l[2], 96 101 )); 97 $flux['data'] = preg_replace('%(<!--extra-->)%is', $btn.'$1', $flux['data']); 98 } 99 } 102 $flux['data'] = preg_replace('%(<!--extra-->)%is', $btn . '$1', $flux['data']); 103 } 104 } 105 100 106 return $flux; 101 107 } … … 107 113 * Actuellement uniquement valable pour les articles. 108 114 * 109 * @param string $objet 110 * @param int $id_objet 115 * @param string $objet 116 * @param int $id_objet 111 117 * @param string $var_preview 112 118 * Indique si on est en prévisualisation : pas de statistiques dans ce cas. … … 114 120 * - false : pas de statistiques disponibles 115 121 * - array : Tableau les stats `[visites, popularité, url]` 116 **/ 117 function admin_stats($objet, $id_objet, $var_preview = "") 118 { 119 if ($GLOBALS['meta']["activer_statistiques"] != "non" 120 AND $objet == 'article' 121 AND !$var_preview 122 AND autoriser('voirstats') 122 **/ 123 function admin_stats($objet, $id_objet, $var_preview = "") { 124 if ($GLOBALS['meta']["activer_statistiques"] != "non" 125 AND $objet == 'article' 126 AND !$var_preview 127 AND autoriser('voirstats') 123 128 ) { 124 129 $row = sql_fetsel("visites, popularite", "spip_articles", "id_article=$id_objet AND statut='publie'"); 125 130 126 131 if ($row) { 127 return array(intval($row['visites']), 128 ceil($row['popularite']), 129 str_replace('&', '&', generer_url_ecrire_statistiques($id_objet))); 130 } 131 } 132 return array( 133 intval($row['visites']), 134 ceil($row['popularite']), 135 str_replace('&', '&', generer_url_ecrire_statistiques($id_objet)) 136 ); 137 } 138 } 139 132 140 return false; 133 141 } … … 138 146 * @param int $id_article 139 147 * @return string URL 140 **/148 **/ 141 149 function generer_url_ecrire_statistiques($id_article) { 142 150 return generer_url_ecrire('stats_visites', "id_article=$id_article"); 143 151 } 144 145 152 146 153 … … 153 160 * @return array 154 161 * Tableau `[nom de la tache => intervalle en secondes]` 155 **/156 function stats_taches_generales_cron($taches_generales) {162 **/ 163 function stats_taches_generales_cron($taches_generales) { 157 164 158 165 // stats : toutes les 5 minutes on peut vider un panier de visites 159 166 if (isset($GLOBALS['meta']["activer_statistiques"]) 160 AND $GLOBALS['meta']["activer_statistiques"] == "oui" )161 {162 $taches_generales['visites'] = 300; 167 AND $GLOBALS['meta']["activer_statistiques"] == "oui" 168 ) { 169 $taches_generales['visites'] = 300; 163 170 $taches_generales['popularites'] = 7200; # calcul lourd 164 171 } … … 176 183 * Couples nom de la méta => valeur par défaut 177 184 */ 178 function stats_configurer_liste_metas($metas){ 179 $metas['activer_statistiques']='non'; 180 $metas['activer_captures_referers']='non'; 185 function stats_configurer_liste_metas($metas) { 186 $metas['activer_statistiques'] = 'non'; 187 $metas['activer_captures_referers'] = 'non'; 188 181 189 return $metas; 182 190 } … … 186 194 * 187 195 * @pipeline boite_infos 188 * @param array $flux 196 * @param array $flux Données du pipeline 189 197 * @return array Données du pipeline 190 198 */ 191 function stats_boite_infos($flux) {199 function stats_boite_infos($flux) { 192 200 if ($GLOBALS['meta']["activer_statistiques"] == "oui") { 193 if ($flux['args']['type']=='article' 194 AND $id_article=$flux['args']['id'] 195 AND autoriser('voirstats','article',$id_article)){ 196 $visites = sql_getfetsel('visites','spip_articles','id_article='.intval($id_article)); 197 if ($visites>0){ 198 $icone_horizontale=chercher_filtre('icone_horizontale'); 199 $flux['data'].=$icone_horizontale(generer_url_ecrire("stats_visites","id_article=$id_article"),_T('statistiques:icone_evolution_visites', array('visites' => $visites)),"statistique-24.png"); 201 if ($flux['args']['type'] == 'article' 202 AND $id_article = $flux['args']['id'] 203 AND autoriser('voirstats', 'article', $id_article) 204 ) { 205 $visites = sql_getfetsel('visites', 'spip_articles', 'id_article=' . intval($id_article)); 206 if ($visites > 0) { 207 $icone_horizontale = chercher_filtre('icone_horizontale'); 208 $flux['data'] .= $icone_horizontale(generer_url_ecrire("stats_visites", "id_article=$id_article"), 209 _T('statistiques:icone_evolution_visites', array('visites' => $visites)), "statistique-24.png"); 200 210 } 201 211 } 202 212 } 203 return $flux; 213 214 return $flux; 204 215 } 205 216
Note: See TracChangeset
for help on using the changeset viewer.