@@ -15,53 +15,53 @@ |
||
| 15 | 15 | // mise a jour des donnees si envoi via formulaire |
| 16 | 16 | // http://doc.spip.org/@enregistre_modif_plugin |
| 17 | 17 | function enregistre_modif_plugin(){ |
| 18 | - include_spip('inc/plugin'); |
|
| 19 | - // recuperer les plugins dans l'ordre des $_POST |
|
| 20 | - $test = array(); |
|
| 21 | - foreach(liste_plugin_files() as $file){ |
|
| 22 | - $test['s'.substr(md5(_DIR_PLUGINS.$file),0,16)] = $file; |
|
| 23 | - } |
|
| 24 | - if (defined('_DIR_PLUGINS_SUPPL')) |
|
| 25 | - foreach(liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file){ |
|
| 26 | - $test['s'.substr(md5(_DIR_PLUGINS_SUPPL.$file),0,16)] = $file; |
|
| 27 | - } |
|
| 18 | + include_spip('inc/plugin'); |
|
| 19 | + // recuperer les plugins dans l'ordre des $_POST |
|
| 20 | + $test = array(); |
|
| 21 | + foreach(liste_plugin_files() as $file){ |
|
| 22 | + $test['s'.substr(md5(_DIR_PLUGINS.$file),0,16)] = $file; |
|
| 23 | + } |
|
| 24 | + if (defined('_DIR_PLUGINS_SUPPL')) |
|
| 25 | + foreach(liste_plugin_files(_DIR_PLUGINS_SUPPL) as $file){ |
|
| 26 | + $test['s'.substr(md5(_DIR_PLUGINS_SUPPL.$file),0,16)] = $file; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - $plugin=array(); |
|
| 29 | + $plugin=array(); |
|
| 30 | 30 | |
| 31 | - foreach($_POST as $choix=>$val){ |
|
| 32 | - if (isset($test[$choix])&&$val=='O') |
|
| 33 | - $plugin[]=$test[$choix]; |
|
| 34 | - } |
|
| 31 | + foreach($_POST as $choix=>$val){ |
|
| 32 | + if (isset($test[$choix])&&$val=='O') |
|
| 33 | + $plugin[]=$test[$choix]; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ": " . join(',', $plugin)); |
|
| 37 | - ecrire_plugin_actifs($plugin); |
|
| 36 | + spip_log("Changement des plugins actifs par l'auteur " . $GLOBALS['visiteur_session']['id_auteur'] . ": " . join(',', $plugin)); |
|
| 37 | + ecrire_plugin_actifs($plugin); |
|
| 38 | 38 | |
| 39 | - // Chaque fois que l'on valide des plugins, on memorise la liste de ces plugins comme etant "interessants", avec un score initial, qui sera decremente a chaque tour : ainsi un plugin active pourra reter visible a l'ecran, jusqu'a ce qu'il tombe dans l'oubli. |
|
| 40 | - $plugins_interessants = @unserialize($GLOBALS['meta']['plugins_interessants']); |
|
| 41 | - if (!is_array($plugins_interessants)) |
|
| 42 | - $plugins_interessants = array(); |
|
| 39 | + // Chaque fois que l'on valide des plugins, on memorise la liste de ces plugins comme etant "interessants", avec un score initial, qui sera decremente a chaque tour : ainsi un plugin active pourra reter visible a l'ecran, jusqu'a ce qu'il tombe dans l'oubli. |
|
| 40 | + $plugins_interessants = @unserialize($GLOBALS['meta']['plugins_interessants']); |
|
| 41 | + if (!is_array($plugins_interessants)) |
|
| 42 | + $plugins_interessants = array(); |
|
| 43 | 43 | |
| 44 | - $plugins_interessants2 = array(); |
|
| 44 | + $plugins_interessants2 = array(); |
|
| 45 | 45 | |
| 46 | - foreach($plugins_interessants as $plug => $score) |
|
| 47 | - if ($score > 1) |
|
| 48 | - $plugins_interessants2[$plug] = $score-1; |
|
| 49 | - foreach ($plugin as $plug) |
|
| 50 | - $plugins_interessants2[$plug] = 10; // score initial |
|
| 51 | - ecrire_meta('plugins_interessants', serialize($plugins_interessants2)); |
|
| 46 | + foreach($plugins_interessants as $plug => $score) |
|
| 47 | + if ($score > 1) |
|
| 48 | + $plugins_interessants2[$plug] = $score-1; |
|
| 49 | + foreach ($plugin as $plug) |
|
| 50 | + $plugins_interessants2[$plug] = 10; // score initial |
|
| 51 | + ecrire_meta('plugins_interessants', serialize($plugins_interessants2)); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | // http://doc.spip.org/@action_activer_plugins_dist |
| 55 | 55 | function action_activer_plugins_dist() { |
| 56 | 56 | |
| 57 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 58 | - $securiser_action(); |
|
| 57 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 58 | + $securiser_action(); |
|
| 59 | 59 | |
| 60 | - if (!autoriser('configurer', '_plugins')) |
|
| 61 | - die('erreur'); |
|
| 62 | - // forcer la maj des meta pour les cas de modif de numero de version base via phpmyadmin |
|
| 63 | - lire_metas(); |
|
| 64 | - enregistre_modif_plugin(); |
|
| 60 | + if (!autoriser('configurer', '_plugins')) |
|
| 61 | + die('erreur'); |
|
| 62 | + // forcer la maj des meta pour les cas de modif de numero de version base via phpmyadmin |
|
| 63 | + lire_metas(); |
|
| 64 | + enregistre_modif_plugin(); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | ?> |
@@ -13,16 +13,16 @@ |
||
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | 14 | |
| 15 | 15 | function action_ajouter_lien_dist($arg=null){ |
| 16 | - if (is_null($arg)){ |
|
| 17 | - $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 18 | - $arg = $securiser_action(); |
|
| 19 | - } |
|
| 16 | + if (is_null($arg)){ |
|
| 17 | + $securiser_action = charger_fonction('securiser_action','inc'); |
|
| 18 | + $arg = $securiser_action(); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - $arg = explode("-",$arg); |
|
| 22 | - list($objet_source,$ids,$objet_lie,$idl) = $arg; |
|
| 21 | + $arg = explode("-",$arg); |
|
| 22 | + list($objet_source,$ids,$objet_lie,$idl) = $arg; |
|
| 23 | 23 | |
| 24 | - include_spip('action/editer_liens'); |
|
| 25 | - objet_associer(array($objet_source=>$ids), array($objet_lie=>$idl)); |
|
| 24 | + include_spip('action/editer_liens'); |
|
| 25 | + objet_associer(array($objet_source=>$ids), array($objet_lie=>$idl)); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -28,16 +28,16 @@ discard block |
||
| 28 | 28 | // http://doc.spip.org/@_generer_url_page |
| 29 | 29 | function _generer_url_page($type,$id, $args='', $ancre='') { |
| 30 | 30 | |
| 31 | - if ($generer_url_externe = charger_fonction("generer_url_$type",'urls',true)) { |
|
| 32 | - $url = $generer_url_externe($id, $args, $ancre); |
|
| 33 | - if (NULL != $url) return $url; |
|
| 34 | - } |
|
| 31 | + if ($generer_url_externe = charger_fonction("generer_url_$type",'urls',true)) { |
|
| 32 | + $url = $generer_url_externe($id, $args, $ancre); |
|
| 33 | + if (NULL != $url) return $url; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - $url = _debut_urls_page . $type . _separateur_urls_page |
|
| 37 | - . $id . _terminaison_urls_page; |
|
| 36 | + $url = _debut_urls_page . $type . _separateur_urls_page |
|
| 37 | + . $id . _terminaison_urls_page; |
|
| 38 | 38 | |
| 39 | - if ($args) $args = strpos($url,'?') ? "&$args" : "?$args"; |
|
| 40 | - return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : ''); |
|
| 39 | + if ($args) $args = strpos($url,'?') ? "&$args" : "?$args"; |
|
| 40 | + return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : ''); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // retrouve le fond et les parametres d'une URL abregee |
@@ -45,51 +45,51 @@ discard block |
||
| 45 | 45 | // http://doc.spip.org/@urls_page_dist |
| 46 | 46 | function urls_page_dist($i, &$entite, $args='', $ancre='') |
| 47 | 47 | { |
| 48 | - if (is_numeric($i)) |
|
| 49 | - return _generer_url_page($entite, $i, $args, $ancre); |
|
| 48 | + if (is_numeric($i)) |
|
| 49 | + return _generer_url_page($entite, $i, $args, $ancre); |
|
| 50 | 50 | |
| 51 | - // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23 |
|
| 52 | - if ($GLOBALS['profondeur_url']>0 AND $entite=='sommaire'){ |
|
| 53 | - return array(array(),'404'); |
|
| 54 | - } |
|
| 51 | + // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23 |
|
| 52 | + if ($GLOBALS['profondeur_url']>0 AND $entite=='sommaire'){ |
|
| 53 | + return array(array(),'404'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - // voir s'il faut recuperer le id_* implicite et les &debut_xx; |
|
| 57 | - if (is_array($args)) |
|
| 58 | - $contexte = $args; |
|
| 59 | - else |
|
| 60 | - parse_str($args,$contexte); |
|
| 61 | - include_spip('inc/urls'); |
|
| 62 | - $r = nettoyer_url_page($i, $contexte); |
|
| 63 | - if ($r) { |
|
| 64 | - array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici |
|
| 65 | - return $r; |
|
| 66 | - } |
|
| 56 | + // voir s'il faut recuperer le id_* implicite et les &debut_xx; |
|
| 57 | + if (is_array($args)) |
|
| 58 | + $contexte = $args; |
|
| 59 | + else |
|
| 60 | + parse_str($args,$contexte); |
|
| 61 | + include_spip('inc/urls'); |
|
| 62 | + $r = nettoyer_url_page($i, $contexte); |
|
| 63 | + if ($r) { |
|
| 64 | + array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici |
|
| 65 | + return $r; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /* |
|
| 68 | + /* |
|
| 69 | 69 | * Le bloc qui suit sert a faciliter les transitions depuis |
| 70 | 70 | * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html' |
| 71 | 71 | * Il est inutile de le recopier si vous personnalisez vos URLs |
| 72 | 72 | * et votre .htaccess |
| 73 | 73 | */ |
| 74 | - // Si on est revenu en mode html, mais c'est une ancienne url_propre |
|
| 75 | - // on ne redirige pas, on assume le nouveau contexte (si possible) |
|
| 76 | - $url = $i; |
|
| 77 | - $url_propre = isset($url) |
|
| 78 | - ? $url |
|
| 79 | - : (isset($_SERVER['REDIRECT_url_propre']) |
|
| 80 | - ? $_SERVER['REDIRECT_url_propre'] |
|
| 81 | - : (isset($_ENV['url_propre']) |
|
| 82 | - ? $_ENV['url_propre'] |
|
| 83 | - : '' |
|
| 84 | - )); |
|
| 85 | - if ($url_propre) { |
|
| 86 | - if ($GLOBALS['profondeur_url']<=0) |
|
| 87 | - $urls_anciennes = charger_fonction('propres','urls',true); |
|
| 88 | - else |
|
| 89 | - $urls_anciennes = charger_fonction('arbo','urls',true); |
|
| 90 | - return $urls_anciennes?$urls_anciennes($url_propre, $entite, $contexte):''; |
|
| 91 | - } |
|
| 92 | - /* Fin du bloc compatibilite url-propres */ |
|
| 74 | + // Si on est revenu en mode html, mais c'est une ancienne url_propre |
|
| 75 | + // on ne redirige pas, on assume le nouveau contexte (si possible) |
|
| 76 | + $url = $i; |
|
| 77 | + $url_propre = isset($url) |
|
| 78 | + ? $url |
|
| 79 | + : (isset($_SERVER['REDIRECT_url_propre']) |
|
| 80 | + ? $_SERVER['REDIRECT_url_propre'] |
|
| 81 | + : (isset($_ENV['url_propre']) |
|
| 82 | + ? $_ENV['url_propre'] |
|
| 83 | + : '' |
|
| 84 | + )); |
|
| 85 | + if ($url_propre) { |
|
| 86 | + if ($GLOBALS['profondeur_url']<=0) |
|
| 87 | + $urls_anciennes = charger_fonction('propres','urls',true); |
|
| 88 | + else |
|
| 89 | + $urls_anciennes = charger_fonction('arbo','urls',true); |
|
| 90 | + return $urls_anciennes?$urls_anciennes($url_propre, $entite, $contexte):''; |
|
| 91 | + } |
|
| 92 | + /* Fin du bloc compatibilite url-propres */ |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | ?> |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | * @return |
| 24 | 24 | */ |
| 25 | 25 | function iterateur_DATA_dist($b) { |
| 26 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 27 | - $b->show = array( |
|
| 28 | - 'field' => array( |
|
| 29 | - 'cle' => 'STRING', |
|
| 30 | - 'valeur' => 'STRING', |
|
| 31 | - '*' => 'ALL' // Champ joker * |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 34 | - $b->select[] = '.valeur'; |
|
| 35 | - return $b; |
|
| 26 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 27 | + $b->show = array( |
|
| 28 | + 'field' => array( |
|
| 29 | + 'cle' => 'STRING', |
|
| 30 | + 'valeur' => 'STRING', |
|
| 31 | + '*' => 'ALL' // Champ joker * |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | + $b->select[] = '.valeur'; |
|
| 35 | + return $b; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
@@ -40,453 +40,453 @@ discard block |
||
| 40 | 40 | * IterateurDATA pour iterer sur des donnees |
| 41 | 41 | */ |
| 42 | 42 | class IterateurDATA implements Iterator { |
| 43 | - /** |
|
| 44 | - * tableau de donnees |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - protected $tableau = array(); |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Conditions de filtrage |
|
| 51 | - * ie criteres de selection |
|
| 52 | - * @var array |
|
| 53 | - */ |
|
| 54 | - protected $filtre = array(); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Cle courante |
|
| 59 | - * @var null |
|
| 60 | - */ |
|
| 61 | - protected $cle = null; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Valeur courante |
|
| 65 | - * @var null |
|
| 66 | - */ |
|
| 67 | - protected $valeur = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Erreur presente ? |
|
| 71 | - * |
|
| 72 | - * @var bool |
|
| 73 | - **/ |
|
| 74 | - public $err = false; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Calcul du total des elements |
|
| 78 | - * |
|
| 79 | - * @var int|null |
|
| 80 | - **/ |
|
| 81 | - public $total = null; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Constructeur |
|
| 85 | - * |
|
| 86 | - * @param $command |
|
| 87 | - * @param array $info |
|
| 88 | - */ |
|
| 89 | - public function __construct($command, $info=array()) { |
|
| 90 | - $this->type='DATA'; |
|
| 91 | - $this->command = $command; |
|
| 92 | - $this->info = $info; |
|
| 93 | - |
|
| 94 | - $this->select($command); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Revenir au depart |
|
| 99 | - * @return void |
|
| 100 | - */ |
|
| 101 | - public function rewind() { |
|
| 102 | - reset($this->tableau); |
|
| 103 | - list($this->cle, $this->valeur) = each($this->tableau); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Declarer les criteres exceptions |
|
| 108 | - * @return array |
|
| 109 | - */ |
|
| 110 | - public function exception_des_criteres() { |
|
| 111 | - return array('tableau'); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Recuperer depuis le cache si possible |
|
| 116 | - * @param $cle |
|
| 117 | - * @return |
|
| 118 | - */ |
|
| 119 | - protected function cache_get($cle) { |
|
| 120 | - if (!$cle) return; |
|
| 121 | - # utiliser memoization si dispo |
|
| 122 | - include_spip('inc/memoization'); |
|
| 123 | - if (!function_exists('cache_get')) return; |
|
| 124 | - return cache_get($cle); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Stocker en cache si possible |
|
| 129 | - * @param $cle |
|
| 130 | - * @param $ttl |
|
| 131 | - * @return |
|
| 132 | - */ |
|
| 133 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 134 | - if (!$cle) return; |
|
| 135 | - if (is_null($valeur)) { |
|
| 136 | - $valeur = $this->tableau; |
|
| 137 | - } |
|
| 138 | - # utiliser memoization si dispo |
|
| 139 | - include_spip('inc/memoization'); |
|
| 140 | - if (!function_exists('cache_set')) return; |
|
| 141 | - return cache_set($cle, |
|
| 142 | - array( |
|
| 143 | - 'data' => $valeur, |
|
| 144 | - 'time' => time(), |
|
| 145 | - 'ttl' => $ttl |
|
| 146 | - ), |
|
| 147 | - 3600 + $ttl); |
|
| 148 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 149 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Aller chercher les donnees de la boucle DATA |
|
| 154 | - * |
|
| 155 | - * @throws Exception |
|
| 156 | - * @param $command |
|
| 157 | - * @return void |
|
| 158 | - */ |
|
| 159 | - protected function select($command) { |
|
| 160 | - |
|
| 161 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 162 | - // le type se retrouve dans la commande 'from' |
|
| 163 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 164 | - if (isset($this->command['from'][0])) { |
|
| 165 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 166 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 167 | - } |
|
| 168 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 172 | - // les commandes connues pour l'iterateur DATA |
|
| 173 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 43 | + /** |
|
| 44 | + * tableau de donnees |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + protected $tableau = array(); |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Conditions de filtrage |
|
| 51 | + * ie criteres de selection |
|
| 52 | + * @var array |
|
| 53 | + */ |
|
| 54 | + protected $filtre = array(); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Cle courante |
|
| 59 | + * @var null |
|
| 60 | + */ |
|
| 61 | + protected $cle = null; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Valeur courante |
|
| 65 | + * @var null |
|
| 66 | + */ |
|
| 67 | + protected $valeur = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Erreur presente ? |
|
| 71 | + * |
|
| 72 | + * @var bool |
|
| 73 | + **/ |
|
| 74 | + public $err = false; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Calcul du total des elements |
|
| 78 | + * |
|
| 79 | + * @var int|null |
|
| 80 | + **/ |
|
| 81 | + public $total = null; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Constructeur |
|
| 85 | + * |
|
| 86 | + * @param $command |
|
| 87 | + * @param array $info |
|
| 88 | + */ |
|
| 89 | + public function __construct($command, $info=array()) { |
|
| 90 | + $this->type='DATA'; |
|
| 91 | + $this->command = $command; |
|
| 92 | + $this->info = $info; |
|
| 93 | + |
|
| 94 | + $this->select($command); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Revenir au depart |
|
| 99 | + * @return void |
|
| 100 | + */ |
|
| 101 | + public function rewind() { |
|
| 102 | + reset($this->tableau); |
|
| 103 | + list($this->cle, $this->valeur) = each($this->tableau); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Declarer les criteres exceptions |
|
| 108 | + * @return array |
|
| 109 | + */ |
|
| 110 | + public function exception_des_criteres() { |
|
| 111 | + return array('tableau'); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Recuperer depuis le cache si possible |
|
| 116 | + * @param $cle |
|
| 117 | + * @return |
|
| 118 | + */ |
|
| 119 | + protected function cache_get($cle) { |
|
| 120 | + if (!$cle) return; |
|
| 121 | + # utiliser memoization si dispo |
|
| 122 | + include_spip('inc/memoization'); |
|
| 123 | + if (!function_exists('cache_get')) return; |
|
| 124 | + return cache_get($cle); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Stocker en cache si possible |
|
| 129 | + * @param $cle |
|
| 130 | + * @param $ttl |
|
| 131 | + * @return |
|
| 132 | + */ |
|
| 133 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 134 | + if (!$cle) return; |
|
| 135 | + if (is_null($valeur)) { |
|
| 136 | + $valeur = $this->tableau; |
|
| 137 | + } |
|
| 138 | + # utiliser memoization si dispo |
|
| 139 | + include_spip('inc/memoization'); |
|
| 140 | + if (!function_exists('cache_set')) return; |
|
| 141 | + return cache_set($cle, |
|
| 142 | + array( |
|
| 143 | + 'data' => $valeur, |
|
| 144 | + 'time' => time(), |
|
| 145 | + 'ttl' => $ttl |
|
| 146 | + ), |
|
| 147 | + 3600 + $ttl); |
|
| 148 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 149 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Aller chercher les donnees de la boucle DATA |
|
| 154 | + * |
|
| 155 | + * @throws Exception |
|
| 156 | + * @param $command |
|
| 157 | + * @return void |
|
| 158 | + */ |
|
| 159 | + protected function select($command) { |
|
| 160 | + |
|
| 161 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 162 | + // le type se retrouve dans la commande 'from' |
|
| 163 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 164 | + if (isset($this->command['from'][0])) { |
|
| 165 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 166 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 167 | + } |
|
| 168 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 172 | + // les commandes connues pour l'iterateur DATA |
|
| 173 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 174 | 174 | |
| 175 | - // {source format, [URL], [arg2]...} |
|
| 176 | - if (isset($this->command['source']) |
|
| 177 | - AND isset($this->command['sourcemode'])) { |
|
| 178 | - $this->select_source(); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // Critere {liste X1, X2, X3} |
|
| 182 | - if (isset($this->command['liste'])) { |
|
| 183 | - $this->select_liste(); |
|
| 184 | - } |
|
| 185 | - if (isset($this->command['enum'])) { |
|
| 186 | - $this->select_enum(); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 190 | - if (!is_array($this->tableau)) { |
|
| 191 | - $this->err = true; |
|
| 192 | - spip_log("erreur datasource ".var_export($command,true)); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // {datapath query.results} |
|
| 196 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 197 | - if (!$this->err |
|
| 198 | - AND isset($this->command['datapath']) |
|
| 199 | - AND is_array($this->command['datapath'])) { |
|
| 200 | - $this->select_datapath(); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - // tri {par x} |
|
| 204 | - if ($this->command['orderby']) { |
|
| 205 | - $this->select_orderby(); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 209 | - if ($this->command['groupby']) { |
|
| 210 | - $this->select_groupby(); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $this->rewind(); |
|
| 214 | - #var_dump($this->tableau); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Aller chercher les donnees de la boucle DATA |
|
| 220 | - * depuis une source |
|
| 221 | - * {source format, [URL], [arg2]...} |
|
| 222 | - */ |
|
| 223 | - protected function select_source() { |
|
| 224 | - # un peu crado : avant de charger le cache il faut charger |
|
| 225 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 226 | - # l'objet en cache ; cf plugins/icalendar |
|
| 227 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 228 | - if (isset($this->command['sourcemode']) |
|
| 229 | - AND !in_array($this->command['sourcemode'],array('table', 'array', 'tableau'))) |
|
| 230 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 231 | - |
|
| 232 | - # le premier argument peut etre un array, une URL etc. |
|
| 233 | - $src = $this->command['source'][0]; |
|
| 234 | - |
|
| 235 | - # avons-nous un cache dispo ? |
|
| 236 | - $cle = null; |
|
| 237 | - if (is_string($src)) |
|
| 238 | - $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true)); |
|
| 239 | - |
|
| 240 | - $cache = $this->cache_get($cle); |
|
| 241 | - if (isset($this->command['datacache'])) |
|
| 242 | - $ttl = intval($this->command['datacache']); |
|
| 243 | - if ($cache |
|
| 244 | - AND ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 245 | - > time()) |
|
| 246 | - AND !(_request('var_mode') === 'recalcul' |
|
| 247 | - AND include_spip('inc/autoriser') |
|
| 248 | - AND autoriser('recalcul') |
|
| 249 | - )) { |
|
| 250 | - $this->tableau = $cache['data']; |
|
| 251 | - } |
|
| 252 | - else try { |
|
| 253 | - # dommage que ca ne soit pas une option de yql_to_array... |
|
| 254 | - if ($this->command['sourcemode'] == 'yql') |
|
| 255 | - if (!isset($ttl)) $ttl = 3600; |
|
| 256 | - |
|
| 257 | - if (isset($this->command['sourcemode']) |
|
| 258 | - AND in_array($this->command['sourcemode'], |
|
| 259 | - array('table', 'array', 'tableau')) |
|
| 260 | - ) { |
|
| 261 | - if (is_array($a = $src) |
|
| 262 | - OR (is_string($a) |
|
| 263 | - AND $a = str_replace('"', '"', $a) # fragile! |
|
| 264 | - AND is_array($a = @unserialize($a))) |
|
| 265 | - ) |
|
| 266 | - $this->tableau = $a; |
|
| 267 | - } |
|
| 268 | - else { |
|
| 269 | - if (preg_match(',^https?://,', $src)) { |
|
| 270 | - include_spip('inc/distant'); |
|
| 271 | - $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 272 | - if (!$u) |
|
| 273 | - throw new Exception("404"); |
|
| 274 | - if (!isset($ttl)) $ttl = 24*3600; |
|
| 275 | - } else if (@is_dir($src)) { |
|
| 276 | - $u = $src; |
|
| 277 | - if (!isset($ttl)) $ttl = 10; |
|
| 278 | - } else if (@is_readable($src) && @is_file($src)) { |
|
| 279 | - $u = spip_file_get_contents($src); |
|
| 280 | - if (!isset($ttl)) $ttl = 10; |
|
| 281 | - } else { |
|
| 282 | - $u = $src; |
|
| 283 | - if (!isset($ttl)) $ttl = 10; |
|
| 284 | - } |
|
| 285 | - if (!$this->err |
|
| 286 | - AND $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)) { |
|
| 287 | - $args = $this->command['source']; |
|
| 288 | - $args[0] = $u; |
|
| 289 | - if (is_array($a = call_user_func_array($g,$args))) { |
|
| 290 | - $this->tableau = $a; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - if (!is_array($this->tableau)) |
|
| 296 | - $this->err = true; |
|
| 297 | - |
|
| 298 | - if (!$this->err AND isset($ttl) and $ttl>0) |
|
| 299 | - $this->cache_set($cle, $ttl); |
|
| 300 | - |
|
| 301 | - } |
|
| 302 | - catch (Exception $e) { |
|
| 303 | - $e = $e->getMessage(); |
|
| 304 | - $err = sprintf("[%s, %s] $e", |
|
| 305 | - $src, |
|
| 306 | - $this->command['sourcemode']); |
|
| 307 | - erreur_squelette(array($err, array())); |
|
| 308 | - $this->err = true; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 312 | - if ($this->err |
|
| 313 | - AND $cache) { |
|
| 314 | - $this->tableau = $cache['data']; |
|
| 315 | - $this->err = false; |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Retourne un tableau donne depuis un critere liste |
|
| 322 | - * Critere {liste X1, X2, X3} |
|
| 323 | - * |
|
| 324 | - **/ |
|
| 325 | - protected function select_liste() { |
|
| 326 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 327 | - if (!isset($this->command['liste'][1])) { |
|
| 328 | - if (!is_array($this->command['liste'][0])) { |
|
| 329 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 330 | - } else { |
|
| 331 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - $this->tableau = $this->command['liste']; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Retourne un tableau donne depuis un critere liste |
|
| 339 | - * Critere {enum Xmin, Xmax} |
|
| 340 | - * |
|
| 341 | - **/ |
|
| 342 | - protected function select_enum() { |
|
| 343 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 344 | - if (!isset($this->command['enum'][1])) { |
|
| 345 | - if (!is_array($this->command['enum'][0])) { |
|
| 346 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 347 | - } else { |
|
| 348 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - if (count($this->command['enum'])>=3) |
|
| 352 | - $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']),array_shift($this->command['enum'])); |
|
| 353 | - else |
|
| 354 | - $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum'])); |
|
| 355 | - $this->tableau = $enum; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 361 | - * {datapath query.results} |
|
| 362 | - * |
|
| 363 | - **/ |
|
| 364 | - protected function select_datapath() { |
|
| 365 | - list(,$base) = each($this->command['datapath']); |
|
| 366 | - if (strlen($base = ltrim(trim($base),"/"))) { |
|
| 367 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 368 | - if (!is_array($this->tableau)) { |
|
| 369 | - $this->tableau = array(); |
|
| 370 | - $this->err = true; |
|
| 371 | - spip_log("datapath '$base' absent"); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Ordonner les resultats |
|
| 378 | - * {par x} |
|
| 379 | - * |
|
| 380 | - **/ |
|
| 381 | - protected function select_orderby() { |
|
| 382 | - $sortfunc = ''; |
|
| 383 | - $aleas = 0; |
|
| 384 | - foreach($this->command['orderby'] as $tri) { |
|
| 385 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 386 | - if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 387 | - // tri par cle |
|
| 388 | - if ($r[1] == 'cle'){ |
|
| 389 | - if (isset($r[2]) and $r[2]) |
|
| 390 | - krsort($this->tableau); |
|
| 391 | - else |
|
| 392 | - ksort($this->tableau); |
|
| 393 | - } |
|
| 394 | - # {par hasard} |
|
| 395 | - else if ($r[1] == 'alea') { |
|
| 396 | - $k = array_keys($this->tableau); |
|
| 397 | - shuffle($k); |
|
| 398 | - $v = array(); |
|
| 399 | - foreach($k as $cle) |
|
| 400 | - $v[$cle] = $this->tableau[$cle]; |
|
| 401 | - $this->tableau = $v; |
|
| 402 | - } |
|
| 403 | - else { |
|
| 404 | - # {par valeur} |
|
| 405 | - if ($r[1] == 'valeur') |
|
| 406 | - $tv = '%s'; |
|
| 407 | - # {par valeur/xx/yy} ?? |
|
| 408 | - else |
|
| 409 | - $tv = 'table_valeur(%s, '.var_export($r[1],true).')'; |
|
| 410 | - $sortfunc .= ' |
|
| 175 | + // {source format, [URL], [arg2]...} |
|
| 176 | + if (isset($this->command['source']) |
|
| 177 | + AND isset($this->command['sourcemode'])) { |
|
| 178 | + $this->select_source(); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // Critere {liste X1, X2, X3} |
|
| 182 | + if (isset($this->command['liste'])) { |
|
| 183 | + $this->select_liste(); |
|
| 184 | + } |
|
| 185 | + if (isset($this->command['enum'])) { |
|
| 186 | + $this->select_enum(); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 190 | + if (!is_array($this->tableau)) { |
|
| 191 | + $this->err = true; |
|
| 192 | + spip_log("erreur datasource ".var_export($command,true)); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // {datapath query.results} |
|
| 196 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 197 | + if (!$this->err |
|
| 198 | + AND isset($this->command['datapath']) |
|
| 199 | + AND is_array($this->command['datapath'])) { |
|
| 200 | + $this->select_datapath(); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + // tri {par x} |
|
| 204 | + if ($this->command['orderby']) { |
|
| 205 | + $this->select_orderby(); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 209 | + if ($this->command['groupby']) { |
|
| 210 | + $this->select_groupby(); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $this->rewind(); |
|
| 214 | + #var_dump($this->tableau); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Aller chercher les donnees de la boucle DATA |
|
| 220 | + * depuis une source |
|
| 221 | + * {source format, [URL], [arg2]...} |
|
| 222 | + */ |
|
| 223 | + protected function select_source() { |
|
| 224 | + # un peu crado : avant de charger le cache il faut charger |
|
| 225 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 226 | + # l'objet en cache ; cf plugins/icalendar |
|
| 227 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 228 | + if (isset($this->command['sourcemode']) |
|
| 229 | + AND !in_array($this->command['sourcemode'],array('table', 'array', 'tableau'))) |
|
| 230 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 231 | + |
|
| 232 | + # le premier argument peut etre un array, une URL etc. |
|
| 233 | + $src = $this->command['source'][0]; |
|
| 234 | + |
|
| 235 | + # avons-nous un cache dispo ? |
|
| 236 | + $cle = null; |
|
| 237 | + if (is_string($src)) |
|
| 238 | + $cle = 'datasource_'.md5($this->command['sourcemode'].':'.var_export($this->command['source'],true)); |
|
| 239 | + |
|
| 240 | + $cache = $this->cache_get($cle); |
|
| 241 | + if (isset($this->command['datacache'])) |
|
| 242 | + $ttl = intval($this->command['datacache']); |
|
| 243 | + if ($cache |
|
| 244 | + AND ($cache['time'] + (isset($ttl) ? $ttl : $cache['ttl']) |
|
| 245 | + > time()) |
|
| 246 | + AND !(_request('var_mode') === 'recalcul' |
|
| 247 | + AND include_spip('inc/autoriser') |
|
| 248 | + AND autoriser('recalcul') |
|
| 249 | + )) { |
|
| 250 | + $this->tableau = $cache['data']; |
|
| 251 | + } |
|
| 252 | + else try { |
|
| 253 | + # dommage que ca ne soit pas une option de yql_to_array... |
|
| 254 | + if ($this->command['sourcemode'] == 'yql') |
|
| 255 | + if (!isset($ttl)) $ttl = 3600; |
|
| 256 | + |
|
| 257 | + if (isset($this->command['sourcemode']) |
|
| 258 | + AND in_array($this->command['sourcemode'], |
|
| 259 | + array('table', 'array', 'tableau')) |
|
| 260 | + ) { |
|
| 261 | + if (is_array($a = $src) |
|
| 262 | + OR (is_string($a) |
|
| 263 | + AND $a = str_replace('"', '"', $a) # fragile! |
|
| 264 | + AND is_array($a = @unserialize($a))) |
|
| 265 | + ) |
|
| 266 | + $this->tableau = $a; |
|
| 267 | + } |
|
| 268 | + else { |
|
| 269 | + if (preg_match(',^https?://,', $src)) { |
|
| 270 | + include_spip('inc/distant'); |
|
| 271 | + $u = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE); |
|
| 272 | + if (!$u) |
|
| 273 | + throw new Exception("404"); |
|
| 274 | + if (!isset($ttl)) $ttl = 24*3600; |
|
| 275 | + } else if (@is_dir($src)) { |
|
| 276 | + $u = $src; |
|
| 277 | + if (!isset($ttl)) $ttl = 10; |
|
| 278 | + } else if (@is_readable($src) && @is_file($src)) { |
|
| 279 | + $u = spip_file_get_contents($src); |
|
| 280 | + if (!isset($ttl)) $ttl = 10; |
|
| 281 | + } else { |
|
| 282 | + $u = $src; |
|
| 283 | + if (!isset($ttl)) $ttl = 10; |
|
| 284 | + } |
|
| 285 | + if (!$this->err |
|
| 286 | + AND $g = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true)) { |
|
| 287 | + $args = $this->command['source']; |
|
| 288 | + $args[0] = $u; |
|
| 289 | + if (is_array($a = call_user_func_array($g,$args))) { |
|
| 290 | + $this->tableau = $a; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + if (!is_array($this->tableau)) |
|
| 296 | + $this->err = true; |
|
| 297 | + |
|
| 298 | + if (!$this->err AND isset($ttl) and $ttl>0) |
|
| 299 | + $this->cache_set($cle, $ttl); |
|
| 300 | + |
|
| 301 | + } |
|
| 302 | + catch (Exception $e) { |
|
| 303 | + $e = $e->getMessage(); |
|
| 304 | + $err = sprintf("[%s, %s] $e", |
|
| 305 | + $src, |
|
| 306 | + $this->command['sourcemode']); |
|
| 307 | + erreur_squelette(array($err, array())); |
|
| 308 | + $this->err = true; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 312 | + if ($this->err |
|
| 313 | + AND $cache) { |
|
| 314 | + $this->tableau = $cache['data']; |
|
| 315 | + $this->err = false; |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Retourne un tableau donne depuis un critere liste |
|
| 322 | + * Critere {liste X1, X2, X3} |
|
| 323 | + * |
|
| 324 | + **/ |
|
| 325 | + protected function select_liste() { |
|
| 326 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 327 | + if (!isset($this->command['liste'][1])) { |
|
| 328 | + if (!is_array($this->command['liste'][0])) { |
|
| 329 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 330 | + } else { |
|
| 331 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + $this->tableau = $this->command['liste']; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Retourne un tableau donne depuis un critere liste |
|
| 339 | + * Critere {enum Xmin, Xmax} |
|
| 340 | + * |
|
| 341 | + **/ |
|
| 342 | + protected function select_enum() { |
|
| 343 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 344 | + if (!isset($this->command['enum'][1])) { |
|
| 345 | + if (!is_array($this->command['enum'][0])) { |
|
| 346 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 347 | + } else { |
|
| 348 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + if (count($this->command['enum'])>=3) |
|
| 352 | + $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum']),array_shift($this->command['enum'])); |
|
| 353 | + else |
|
| 354 | + $enum = range(array_shift($this->command['enum']),array_shift($this->command['enum'])); |
|
| 355 | + $this->tableau = $enum; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 361 | + * {datapath query.results} |
|
| 362 | + * |
|
| 363 | + **/ |
|
| 364 | + protected function select_datapath() { |
|
| 365 | + list(,$base) = each($this->command['datapath']); |
|
| 366 | + if (strlen($base = ltrim(trim($base),"/"))) { |
|
| 367 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 368 | + if (!is_array($this->tableau)) { |
|
| 369 | + $this->tableau = array(); |
|
| 370 | + $this->err = true; |
|
| 371 | + spip_log("datapath '$base' absent"); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Ordonner les resultats |
|
| 378 | + * {par x} |
|
| 379 | + * |
|
| 380 | + **/ |
|
| 381 | + protected function select_orderby() { |
|
| 382 | + $sortfunc = ''; |
|
| 383 | + $aleas = 0; |
|
| 384 | + foreach($this->command['orderby'] as $tri) { |
|
| 385 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 386 | + if (preg_match(',^\.?([/\w]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 387 | + // tri par cle |
|
| 388 | + if ($r[1] == 'cle'){ |
|
| 389 | + if (isset($r[2]) and $r[2]) |
|
| 390 | + krsort($this->tableau); |
|
| 391 | + else |
|
| 392 | + ksort($this->tableau); |
|
| 393 | + } |
|
| 394 | + # {par hasard} |
|
| 395 | + else if ($r[1] == 'alea') { |
|
| 396 | + $k = array_keys($this->tableau); |
|
| 397 | + shuffle($k); |
|
| 398 | + $v = array(); |
|
| 399 | + foreach($k as $cle) |
|
| 400 | + $v[$cle] = $this->tableau[$cle]; |
|
| 401 | + $this->tableau = $v; |
|
| 402 | + } |
|
| 403 | + else { |
|
| 404 | + # {par valeur} |
|
| 405 | + if ($r[1] == 'valeur') |
|
| 406 | + $tv = '%s'; |
|
| 407 | + # {par valeur/xx/yy} ?? |
|
| 408 | + else |
|
| 409 | + $tv = 'table_valeur(%s, '.var_export($r[1],true).')'; |
|
| 410 | + $sortfunc .= ' |
|
| 411 | 411 | $a = '.sprintf($tv,'$aa').'; |
| 412 | 412 | $b = '.sprintf($tv,'$bb').'; |
| 413 | 413 | if ($a <> $b) |
| 414 | 414 | return ($a ' . ((isset($r[2]) and $r[2]) ? '>' : '<').' $b) ? -1 : 1;'; |
| 415 | - } |
|
| 416 | - } |
|
| 417 | - } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | 418 | |
| 419 | - if ($sortfunc) { |
|
| 420 | - uasort($this->tableau, create_function('$aa,$bb', |
|
| 421 | - $sortfunc.' |
|
| 419 | + if ($sortfunc) { |
|
| 420 | + uasort($this->tableau, create_function('$aa,$bb', |
|
| 421 | + $sortfunc.' |
|
| 422 | 422 | return 0;' |
| 423 | - )); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * Grouper les resultats |
|
| 430 | - * {fusion /x/y/z} |
|
| 431 | - * |
|
| 432 | - **/ |
|
| 433 | - protected function select_groupby() { |
|
| 434 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 435 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 436 | - $vu = array(); |
|
| 437 | - foreach($this->tableau as $k => $v) { |
|
| 438 | - $val = table_valeur($v, $fusion); |
|
| 439 | - if (isset($vu[$val])) |
|
| 440 | - unset($this->tableau[$k]); |
|
| 441 | - else |
|
| 442 | - $vu[$val] = true; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 423 | + )); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * Grouper les resultats |
|
| 430 | + * {fusion /x/y/z} |
|
| 431 | + * |
|
| 432 | + **/ |
|
| 433 | + protected function select_groupby() { |
|
| 434 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 435 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 436 | + $vu = array(); |
|
| 437 | + foreach($this->tableau as $k => $v) { |
|
| 438 | + $val = table_valeur($v, $fusion); |
|
| 439 | + if (isset($vu[$val])) |
|
| 440 | + unset($this->tableau[$k]); |
|
| 441 | + else |
|
| 442 | + $vu[$val] = true; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | 447 | |
| 448 | - /** |
|
| 449 | - * L'iterateur est-il encore valide ? |
|
| 450 | - * @return bool |
|
| 451 | - */ |
|
| 452 | - public function valid(){ |
|
| 453 | - return !is_null($this->cle); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Retourner la valeur |
|
| 458 | - * @return null |
|
| 459 | - */ |
|
| 460 | - public function current() { |
|
| 461 | - return $this->valeur; |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Retourner la cle |
|
| 466 | - * @return null |
|
| 467 | - */ |
|
| 468 | - public function key() { |
|
| 469 | - return $this->cle; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - /** |
|
| 473 | - * Passer a la valeur suivante |
|
| 474 | - * @return void |
|
| 475 | - */ |
|
| 476 | - public function next(){ |
|
| 477 | - if ($this->valid()) |
|
| 478 | - list($this->cle, $this->valeur) = each($this->tableau); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * Compter le nombre total de resultats |
|
| 483 | - * @return int |
|
| 484 | - */ |
|
| 485 | - public function count() { |
|
| 486 | - if (is_null($this->total)) |
|
| 487 | - $this->total = count($this->tableau); |
|
| 488 | - return $this->total; |
|
| 489 | - } |
|
| 448 | + /** |
|
| 449 | + * L'iterateur est-il encore valide ? |
|
| 450 | + * @return bool |
|
| 451 | + */ |
|
| 452 | + public function valid(){ |
|
| 453 | + return !is_null($this->cle); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Retourner la valeur |
|
| 458 | + * @return null |
|
| 459 | + */ |
|
| 460 | + public function current() { |
|
| 461 | + return $this->valeur; |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Retourner la cle |
|
| 466 | + * @return null |
|
| 467 | + */ |
|
| 468 | + public function key() { |
|
| 469 | + return $this->cle; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + /** |
|
| 473 | + * Passer a la valeur suivante |
|
| 474 | + * @return void |
|
| 475 | + */ |
|
| 476 | + public function next(){ |
|
| 477 | + if ($this->valid()) |
|
| 478 | + list($this->cle, $this->valeur) = each($this->tableau); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * Compter le nombre total de resultats |
|
| 483 | + * @return int |
|
| 484 | + */ |
|
| 485 | + public function count() { |
|
| 486 | + if (is_null($this->total)) |
|
| 487 | + $this->total = count($this->tableau); |
|
| 488 | + return $this->total; |
|
| 489 | + } |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /* |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | * @return array |
| 501 | 501 | */ |
| 502 | 502 | function inc_file_to_array_dist($u) { |
| 503 | - return preg_split('/\r?\n/', $u); |
|
| 503 | + return preg_split('/\r?\n/', $u); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
@@ -508,8 +508,8 @@ discard block |
||
| 508 | 508 | * @return unknown |
| 509 | 509 | */ |
| 510 | 510 | function inc_plugins_to_array_dist() { |
| 511 | - include_spip('inc/plugin'); |
|
| 512 | - return liste_chemin_plugin_actifs(); |
|
| 511 | + include_spip('inc/plugin'); |
|
| 512 | + return liste_chemin_plugin_actifs(); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | * @return array |
| 519 | 519 | */ |
| 520 | 520 | function inc_xml_to_array_dist($u) { |
| 521 | - return @XMLObjectToArray(new SimpleXmlIterator($u)); |
|
| 521 | + return @XMLObjectToArray(new SimpleXmlIterator($u)); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | /** |
@@ -546,14 +546,14 @@ discard block |
||
| 546 | 546 | * @return array|bool |
| 547 | 547 | */ |
| 548 | 548 | function inc_yql_to_array_dist($u) { |
| 549 | - define('_YQL_ENDPOINT', 'http://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
|
| 550 | - $v = recuperer_page($url = _YQL_ENDPOINT.urlencode($u).'&format=json'); |
|
| 551 | - $w = json_decode($v); |
|
| 552 | - if (!$w) { |
|
| 553 | - throw new Exception('YQL: réponse vide ou mal formée'); |
|
| 554 | - return false; |
|
| 555 | - } |
|
| 556 | - return inc_object_to_array($w); |
|
| 549 | + define('_YQL_ENDPOINT', 'http://query.yahooapis.com/v1/public/yql?&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q='); |
|
| 550 | + $v = recuperer_page($url = _YQL_ENDPOINT.urlencode($u).'&format=json'); |
|
| 551 | + $w = json_decode($v); |
|
| 552 | + if (!$w) { |
|
| 553 | + throw new Exception('YQL: réponse vide ou mal formée'); |
|
| 554 | + return false; |
|
| 555 | + } |
|
| 556 | + return inc_object_to_array($w); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | /** |
@@ -562,17 +562,17 @@ discard block |
||
| 562 | 562 | * @return array|bool |
| 563 | 563 | */ |
| 564 | 564 | function inc_sql_to_array_dist($u) { |
| 565 | - # sortir le connecteur de $u |
|
| 566 | - preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
|
| 567 | - $serveur = (string) $v[1]; |
|
| 568 | - $req = trim($v[2]); |
|
| 569 | - if ($s = sql_query($req, $serveur)) { |
|
| 570 | - $r = array(); |
|
| 571 | - while ($t = sql_fetch($s)) |
|
| 572 | - $r[] = $t; |
|
| 573 | - return $r; |
|
| 574 | - } |
|
| 575 | - return false; |
|
| 565 | + # sortir le connecteur de $u |
|
| 566 | + preg_match(',^(?:(\w+):)?(.*)$,S', $u, $v); |
|
| 567 | + $serveur = (string) $v[1]; |
|
| 568 | + $req = trim($v[2]); |
|
| 569 | + if ($s = sql_query($req, $serveur)) { |
|
| 570 | + $r = array(); |
|
| 571 | + while ($t = sql_fetch($s)) |
|
| 572 | + $r[] = $t; |
|
| 573 | + return $r; |
|
| 574 | + } |
|
| 575 | + return false; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -581,9 +581,9 @@ discard block |
||
| 581 | 581 | * @return array|bool |
| 582 | 582 | */ |
| 583 | 583 | function inc_json_to_array_dist($u) { |
| 584 | - if (is_array($json = json_decode($u)) |
|
| 585 | - OR is_object($json)) |
|
| 586 | - return (array) $json; |
|
| 584 | + if (is_array($json = json_decode($u)) |
|
| 585 | + OR is_object($json)) |
|
| 586 | + return (array) $json; |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
@@ -592,17 +592,17 @@ discard block |
||
| 592 | 592 | * @return array|bool |
| 593 | 593 | */ |
| 594 | 594 | function inc_csv_to_array_dist($u) { |
| 595 | - include_spip('inc/csv'); |
|
| 596 | - list($entete,$csv) = analyse_csv($u); |
|
| 597 | - array_unshift($csv,$entete); |
|
| 598 | - |
|
| 599 | - include_spip('inc/charsets'); |
|
| 600 | - foreach ($entete as $k => $v) { |
|
| 601 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 602 | - foreach ($csv as &$item) |
|
| 603 | - $item[$v] = &$item[$k]; |
|
| 604 | - } |
|
| 605 | - return $csv; |
|
| 595 | + include_spip('inc/csv'); |
|
| 596 | + list($entete,$csv) = analyse_csv($u); |
|
| 597 | + array_unshift($csv,$entete); |
|
| 598 | + |
|
| 599 | + include_spip('inc/charsets'); |
|
| 600 | + foreach ($entete as $k => $v) { |
|
| 601 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 602 | + foreach ($csv as &$item) |
|
| 603 | + $item[$v] = &$item[$k]; |
|
| 604 | + } |
|
| 605 | + return $csv; |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /** |
@@ -611,10 +611,10 @@ discard block |
||
| 611 | 611 | * @return array|bool |
| 612 | 612 | */ |
| 613 | 613 | function inc_rss_to_array_dist($u) { |
| 614 | - include_spip('inc/syndic'); |
|
| 615 | - if (is_array($rss = analyser_backend($u))) |
|
| 616 | - $tableau = $rss; |
|
| 617 | - return $tableau; |
|
| 614 | + include_spip('inc/syndic'); |
|
| 615 | + if (is_array($rss = analyser_backend($u))) |
|
| 616 | + $tableau = $rss; |
|
| 617 | + return $tableau; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -623,8 +623,8 @@ discard block |
||
| 623 | 623 | * @return array|bool |
| 624 | 624 | */ |
| 625 | 625 | function inc_atom_to_array_dist($u) { |
| 626 | - $g = charger_fonction('rss_to_array', 'inc'); |
|
| 627 | - return $g($u); |
|
| 626 | + $g = charger_fonction('rss_to_array', 'inc'); |
|
| 627 | + return $g($u); |
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | /** |
@@ -634,9 +634,9 @@ discard block |
||
| 634 | 634 | * @return array|bool |
| 635 | 635 | */ |
| 636 | 636 | function inc_glob_to_array_dist($u) { |
| 637 | - return (array) glob($u, |
|
| 638 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 639 | - ); |
|
| 637 | + return (array) glob($u, |
|
| 638 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 639 | + ); |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | /** |
@@ -646,13 +646,13 @@ discard block |
||
| 646 | 646 | * @throws Exception |
| 647 | 647 | */ |
| 648 | 648 | function inc_yaml_to_array_dist($u){ |
| 649 | - include_spip('inc/yaml-mini'); |
|
| 650 | - if (!function_exists("yaml_decode")){ |
|
| 651 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 652 | - return false; |
|
| 653 | - } |
|
| 649 | + include_spip('inc/yaml-mini'); |
|
| 650 | + if (!function_exists("yaml_decode")){ |
|
| 651 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 652 | + return false; |
|
| 653 | + } |
|
| 654 | 654 | |
| 655 | - return yaml_decode($u); |
|
| 655 | + return yaml_decode($u); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | * @return array|bool |
| 667 | 667 | */ |
| 668 | 668 | function inc_pregfiles_to_array_dist($dir, $regexp=-1, $limit=10000) { |
| 669 | - return (array) preg_files($dir, $regexp, $limit); |
|
| 669 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | /** |
@@ -677,19 +677,19 @@ discard block |
||
| 677 | 677 | * @return array|bool |
| 678 | 678 | */ |
| 679 | 679 | function inc_ls_to_array_dist($u) { |
| 680 | - $glob = charger_fonction('glob_to_array', 'inc'); |
|
| 681 | - $a = $glob($u); |
|
| 682 | - foreach ($a as &$v) { |
|
| 683 | - $b = (array) @stat($v); |
|
| 684 | - foreach ($b as $k => $ignore) |
|
| 685 | - if (is_numeric($k)) unset($b[$k]); |
|
| 686 | - $b['file'] = basename($v); |
|
| 687 | - $v = array_merge( |
|
| 688 | - pathinfo($v), |
|
| 689 | - $b |
|
| 690 | - ); |
|
| 691 | - } |
|
| 692 | - return $a; |
|
| 680 | + $glob = charger_fonction('glob_to_array', 'inc'); |
|
| 681 | + $a = $glob($u); |
|
| 682 | + foreach ($a as &$v) { |
|
| 683 | + $b = (array) @stat($v); |
|
| 684 | + foreach ($b as $k => $ignore) |
|
| 685 | + if (is_numeric($k)) unset($b[$k]); |
|
| 686 | + $b['file'] = basename($v); |
|
| 687 | + $v = array_merge( |
|
| 688 | + pathinfo($v), |
|
| 689 | + $b |
|
| 690 | + ); |
|
| 691 | + } |
|
| 692 | + return $a; |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -698,23 +698,23 @@ discard block |
||
| 698 | 698 | * @return array|bool |
| 699 | 699 | */ |
| 700 | 700 | function XMLObjectToArray($object){ |
| 701 | - $xml_array = array(); |
|
| 702 | - for( $object->rewind(); $object->valid(); $object->next() ) { |
|
| 703 | - if(array_key_exists($key = $object->key(), $xml_array)){ |
|
| 704 | - $key .= '-'.uniqid(); |
|
| 705 | - } |
|
| 706 | - $vars = get_object_vars($object->current()); |
|
| 707 | - if (isset($vars['@attributes'])) |
|
| 708 | - foreach($vars['@attributes'] as $k => $v) |
|
| 709 | - $xml_array[$key][$k] = $v; |
|
| 710 | - if($object->hasChildren()){ |
|
| 711 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 712 | - $object->current()); |
|
| 713 | - } |
|
| 714 | - else{ |
|
| 715 | - $xml_array[$key][] = strval($object->current()); |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - return $xml_array; |
|
| 701 | + $xml_array = array(); |
|
| 702 | + for( $object->rewind(); $object->valid(); $object->next() ) { |
|
| 703 | + if(array_key_exists($key = $object->key(), $xml_array)){ |
|
| 704 | + $key .= '-'.uniqid(); |
|
| 705 | + } |
|
| 706 | + $vars = get_object_vars($object->current()); |
|
| 707 | + if (isset($vars['@attributes'])) |
|
| 708 | + foreach($vars['@attributes'] as $k => $v) |
|
| 709 | + $xml_array[$key][$k] = $v; |
|
| 710 | + if($object->hasChildren()){ |
|
| 711 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 712 | + $object->current()); |
|
| 713 | + } |
|
| 714 | + else{ |
|
| 715 | + $xml_array[$key][] = strval($object->current()); |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + return $xml_array; |
|
| 719 | 719 | } |
| 720 | 720 | ?> |
@@ -18,174 +18,174 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class IterateurSQL implements Iterator { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * ressource sql |
|
| 23 | - * @var resource|bool |
|
| 24 | - */ |
|
| 25 | - protected $sqlresult = false; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * row sql courante |
|
| 29 | - * @var array|null |
|
| 30 | - */ |
|
| 31 | - protected $row = null; |
|
| 32 | - |
|
| 33 | - protected $firstseek = false; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Erreur presente ? |
|
| 37 | - * |
|
| 38 | - * @var bool |
|
| 39 | - **/ |
|
| 40 | - public $err = false; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Calcul du total des elements |
|
| 44 | - * |
|
| 45 | - * @var int|null |
|
| 46 | - **/ |
|
| 47 | - public $total = null; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * selectionner les donnees, ie faire la requete SQL |
|
| 51 | - * @return void |
|
| 52 | - */ |
|
| 53 | - protected function select() { |
|
| 54 | - $this->row = null; |
|
| 55 | - $v = &$this->command; |
|
| 56 | - $this->sqlresult = calculer_select($v['select'], $v['from'], $v['type'], $v['where'], $v['join'], $v['groupby'], $v['orderby'], $v['limit'], $v['having'], $v['table'], $v['id'], $v['connect'], $this->info); |
|
| 57 | - $this->err = !$this->sqlresult; |
|
| 58 | - $this->firstseek = false; |
|
| 59 | - $this->pos = -1; |
|
| 60 | - |
|
| 61 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 62 | - //$this->total = $this->count(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /* |
|
| 21 | + /** |
|
| 22 | + * ressource sql |
|
| 23 | + * @var resource|bool |
|
| 24 | + */ |
|
| 25 | + protected $sqlresult = false; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * row sql courante |
|
| 29 | + * @var array|null |
|
| 30 | + */ |
|
| 31 | + protected $row = null; |
|
| 32 | + |
|
| 33 | + protected $firstseek = false; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Erreur presente ? |
|
| 37 | + * |
|
| 38 | + * @var bool |
|
| 39 | + **/ |
|
| 40 | + public $err = false; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Calcul du total des elements |
|
| 44 | + * |
|
| 45 | + * @var int|null |
|
| 46 | + **/ |
|
| 47 | + public $total = null; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * selectionner les donnees, ie faire la requete SQL |
|
| 51 | + * @return void |
|
| 52 | + */ |
|
| 53 | + protected function select() { |
|
| 54 | + $this->row = null; |
|
| 55 | + $v = &$this->command; |
|
| 56 | + $this->sqlresult = calculer_select($v['select'], $v['from'], $v['type'], $v['where'], $v['join'], $v['groupby'], $v['orderby'], $v['limit'], $v['having'], $v['table'], $v['id'], $v['connect'], $this->info); |
|
| 57 | + $this->err = !$this->sqlresult; |
|
| 58 | + $this->firstseek = false; |
|
| 59 | + $this->pos = -1; |
|
| 60 | + |
|
| 61 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 62 | + //$this->total = $this->count(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /* |
|
| 66 | 66 | * array command: les commandes d'initialisation |
| 67 | 67 | * array info: les infos sur le squelette |
| 68 | 68 | */ |
| 69 | - public function __construct($command, $info=array()) { |
|
| 70 | - $this->type='SQL'; |
|
| 71 | - $this->command = $command; |
|
| 72 | - $this->info = $info; |
|
| 73 | - $this->select(); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Rembobiner |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 80 | - public function rewind() { |
|
| 81 | - return ($this->pos > 0) |
|
| 82 | - ? $this->seek(0) |
|
| 83 | - : true; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Verifier l'etat de l'iterateur |
|
| 88 | - * @return bool |
|
| 89 | - */ |
|
| 90 | - public function valid() { |
|
| 91 | - if ($this->err) |
|
| 92 | - return false; |
|
| 93 | - if (!$this->firstseek) |
|
| 94 | - $this->next(); |
|
| 95 | - return is_array($this->row); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Valeurs sur la position courante |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - public function current() { |
|
| 103 | - return $this->row; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function key() { |
|
| 107 | - return $this->pos; |
|
| 108 | - } |
|
| 69 | + public function __construct($command, $info=array()) { |
|
| 70 | + $this->type='SQL'; |
|
| 71 | + $this->command = $command; |
|
| 72 | + $this->info = $info; |
|
| 73 | + $this->select(); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Rembobiner |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | + public function rewind() { |
|
| 81 | + return ($this->pos > 0) |
|
| 82 | + ? $this->seek(0) |
|
| 83 | + : true; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Verifier l'etat de l'iterateur |
|
| 88 | + * @return bool |
|
| 89 | + */ |
|
| 90 | + public function valid() { |
|
| 91 | + if ($this->err) |
|
| 92 | + return false; |
|
| 93 | + if (!$this->firstseek) |
|
| 94 | + $this->next(); |
|
| 95 | + return is_array($this->row); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Valeurs sur la position courante |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + public function current() { |
|
| 103 | + return $this->row; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function key() { |
|
| 107 | + return $this->pos; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Sauter a une position absolue |
|
| 112 | - * @param int $n |
|
| 113 | - * @param null|string $continue |
|
| 114 | - * @return bool |
|
| 115 | - */ |
|
| 116 | - public function seek($n=0, $continue=null) { |
|
| 117 | - if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 118 | - // SQLite ne sait pas seek(), il faut relancer la query |
|
| 119 | - // si la position courante est apres la position visee |
|
| 120 | - // il faut relancer la requete |
|
| 121 | - if ($this->pos>$n){ |
|
| 122 | - $this->free(); |
|
| 123 | - $this->select(); |
|
| 124 | - $this->valid(); |
|
| 125 | - } |
|
| 126 | - // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 127 | - // (sera fait en cas d'echec de cette fonction) |
|
| 128 | - return false; |
|
| 129 | - } |
|
| 130 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 131 | - $this->pos = min($n,$this->count()); |
|
| 132 | - return true; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Avancer d'un cran |
|
| 137 | - * @return void |
|
| 138 | - */ |
|
| 139 | - public function next(){ |
|
| 140 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 141 | - $this->pos ++; |
|
| 142 | - $this->firstseek |= true; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Avancer et retourner les donnees pour le nouvel element |
|
| 147 | - * @return array|bool|null |
|
| 148 | - */ |
|
| 149 | - public function fetch(){ |
|
| 150 | - if ($this->valid()) { |
|
| 151 | - $r = $this->current(); |
|
| 152 | - $this->next(); |
|
| 153 | - } else |
|
| 154 | - $r = false; |
|
| 155 | - return $r; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * liberer les ressources |
|
| 160 | - * @return bool |
|
| 161 | - */ |
|
| 162 | - public function free(){ |
|
| 163 | - if (!$this->sqlresult) return true; |
|
| 164 | - $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 165 | - $this->sqlresult = null; |
|
| 166 | - return $a; |
|
| 167 | - } |
|
| 110 | + /** |
|
| 111 | + * Sauter a une position absolue |
|
| 112 | + * @param int $n |
|
| 113 | + * @param null|string $continue |
|
| 114 | + * @return bool |
|
| 115 | + */ |
|
| 116 | + public function seek($n=0, $continue=null) { |
|
| 117 | + if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 118 | + // SQLite ne sait pas seek(), il faut relancer la query |
|
| 119 | + // si la position courante est apres la position visee |
|
| 120 | + // il faut relancer la requete |
|
| 121 | + if ($this->pos>$n){ |
|
| 122 | + $this->free(); |
|
| 123 | + $this->select(); |
|
| 124 | + $this->valid(); |
|
| 125 | + } |
|
| 126 | + // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 127 | + // (sera fait en cas d'echec de cette fonction) |
|
| 128 | + return false; |
|
| 129 | + } |
|
| 130 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 131 | + $this->pos = min($n,$this->count()); |
|
| 132 | + return true; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Avancer d'un cran |
|
| 137 | + * @return void |
|
| 138 | + */ |
|
| 139 | + public function next(){ |
|
| 140 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 141 | + $this->pos ++; |
|
| 142 | + $this->firstseek |= true; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Avancer et retourner les donnees pour le nouvel element |
|
| 147 | + * @return array|bool|null |
|
| 148 | + */ |
|
| 149 | + public function fetch(){ |
|
| 150 | + if ($this->valid()) { |
|
| 151 | + $r = $this->current(); |
|
| 152 | + $this->next(); |
|
| 153 | + } else |
|
| 154 | + $r = false; |
|
| 155 | + return $r; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * liberer les ressources |
|
| 160 | + * @return bool |
|
| 161 | + */ |
|
| 162 | + public function free(){ |
|
| 163 | + if (!$this->sqlresult) return true; |
|
| 164 | + $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 165 | + $this->sqlresult = null; |
|
| 166 | + return $a; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Compter le nombre de resultats |
|
| 171 | - * @return int |
|
| 172 | - */ |
|
| 173 | - public function count() { |
|
| 174 | - if (is_null($this->total)) { |
|
| 175 | - if (!$this->sqlresult) { |
|
| 176 | - $this->total = 0; |
|
| 177 | - } else { |
|
| 178 | - # cas count(*) |
|
| 179 | - if (in_array('count(*)', $this->command['select'])) { |
|
| 180 | - $this->valid(); |
|
| 181 | - $s = $this->current(); |
|
| 182 | - $this->total = $s['count(*)']; |
|
| 183 | - } else |
|
| 184 | - $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - return $this->total; |
|
| 188 | - } |
|
| 169 | + /** |
|
| 170 | + * Compter le nombre de resultats |
|
| 171 | + * @return int |
|
| 172 | + */ |
|
| 173 | + public function count() { |
|
| 174 | + if (is_null($this->total)) { |
|
| 175 | + if (!$this->sqlresult) { |
|
| 176 | + $this->total = 0; |
|
| 177 | + } else { |
|
| 178 | + # cas count(*) |
|
| 179 | + if (in_array('count(*)', $this->command['select'])) { |
|
| 180 | + $this->valid(); |
|
| 181 | + $s = $this->current(); |
|
| 182 | + $this->total = $s['count(*)']; |
|
| 183 | + } else |
|
| 184 | + $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + return $this->total; |
|
| 188 | + } |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | ?> |
@@ -18,22 +18,22 @@ |
||
| 18 | 18 | // annonce au compilo les "champs" disponibles |
| 19 | 19 | // |
| 20 | 20 | function iterateur_php_dist($b, $iteratorName) { |
| 21 | - $b->iterateur = $iteratorName; # designe la classe d'iterateur |
|
| 22 | - $b->show = array( |
|
| 23 | - 'field' => array( |
|
| 24 | - 'cle' => 'STRING', |
|
| 25 | - 'valeur' => 'STRING', |
|
| 26 | - ) |
|
| 27 | - ); |
|
| 28 | - foreach (get_class_methods($iteratorName) as $method) { |
|
| 29 | - $b->show['field'][ strtolower($method) ] = 'METHOD'; |
|
| 30 | - } |
|
| 31 | - /* |
|
| 21 | + $b->iterateur = $iteratorName; # designe la classe d'iterateur |
|
| 22 | + $b->show = array( |
|
| 23 | + 'field' => array( |
|
| 24 | + 'cle' => 'STRING', |
|
| 25 | + 'valeur' => 'STRING', |
|
| 26 | + ) |
|
| 27 | + ); |
|
| 28 | + foreach (get_class_methods($iteratorName) as $method) { |
|
| 29 | + $b->show['field'][ strtolower($method) ] = 'METHOD'; |
|
| 30 | + } |
|
| 31 | + /* |
|
| 32 | 32 | foreach (get_class_vars($iteratorName) as $property) { |
| 33 | 33 | $b->show['field'][ strtolower($property) ] = 'PROPERTY'; |
| 34 | 34 | } |
| 35 | 35 | */ |
| 36 | - return $b; |
|
| 36 | + return $b; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | |
@@ -21,13 +21,13 @@ |
||
| 21 | 21 | // annonce au compilo les "champs" disponibles |
| 22 | 22 | // |
| 23 | 23 | function iterateur_POUR_dist($b) { |
| 24 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 25 | - $b->show = array( |
|
| 26 | - 'field' => array( |
|
| 27 | - 'cle' => 'STRING', |
|
| 28 | - 'valeur' => 'STRING', |
|
| 29 | - ) |
|
| 30 | - ); |
|
| 31 | - return $b; |
|
| 24 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 25 | + $b->show = array( |
|
| 26 | + 'field' => array( |
|
| 27 | + 'cle' => 'STRING', |
|
| 28 | + 'valeur' => 'STRING', |
|
| 29 | + ) |
|
| 30 | + ); |
|
| 31 | + return $b; |
|
| 32 | 32 | } |
| 33 | 33 | |
@@ -20,16 +20,16 @@ |
||
| 20 | 20 | // annonce au compilo les "champs" disponibles |
| 21 | 21 | // |
| 22 | 22 | function iterateur_CONDITION_dist($b) { |
| 23 | - $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 24 | - $b->show = array( |
|
| 25 | - 'field' => array() |
|
| 26 | - ); |
|
| 27 | - return $b; |
|
| 23 | + $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 24 | + $b->show = array( |
|
| 25 | + 'field' => array() |
|
| 26 | + ); |
|
| 27 | + return $b; |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | class IterateurCONDITION extends IterateurData { |
| 32 | - protected function select($command) { |
|
| 33 | - $this->tableau = array(0=>1); |
|
| 34 | - } |
|
| 32 | + protected function select($command) { |
|
| 33 | + $this->tableau = array(0=>1); |
|
| 34 | + } |
|
| 35 | 35 | } |
@@ -16,59 +16,59 @@ |
||
| 16 | 16 | // http://doc.spip.org/@genie_maintenance_dist |
| 17 | 17 | function genie_maintenance_dist ($t) { |
| 18 | 18 | |
| 19 | - // (re)mettre .htaccess avec deny from all |
|
| 20 | - // dans les deux repertoires dits inaccessibles par http |
|
| 21 | - include_spip('inc/acces'); |
|
| 22 | - verifier_htaccess(_DIR_ETC); |
|
| 23 | - verifier_htaccess(_DIR_TMP); |
|
| 19 | + // (re)mettre .htaccess avec deny from all |
|
| 20 | + // dans les deux repertoires dits inaccessibles par http |
|
| 21 | + include_spip('inc/acces'); |
|
| 22 | + verifier_htaccess(_DIR_ETC); |
|
| 23 | + verifier_htaccess(_DIR_TMP); |
|
| 24 | 24 | |
| 25 | - // Verifier qu'aucune table n'est crashee |
|
| 26 | - if (!_request('reinstall')) |
|
| 27 | - verifier_crash_tables(); |
|
| 25 | + // Verifier qu'aucune table n'est crashee |
|
| 26 | + if (!_request('reinstall')) |
|
| 27 | + verifier_crash_tables(); |
|
| 28 | 28 | |
| 29 | - return 1; |
|
| 29 | + return 1; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | // http://doc.spip.org/@verifier_crash_tables |
| 34 | 34 | function verifier_crash_tables() { |
| 35 | - if (spip_connect()) { |
|
| 36 | - include_spip('base/serial'); |
|
| 37 | - include_spip('base/auxiliaires'); |
|
| 38 | - $crash = array(); |
|
| 39 | - foreach (array('tables_principales', 'tables_auxiliaires') as $com) { |
|
| 40 | - foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 41 | - if (!sql_select('*', $table,'','','', 1) |
|
| 42 | - AND !defined('spip_interdire_cache')) # cas "LOST CONNECTION" |
|
| 43 | - $crash[] = $table; |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - #$crash[] = 'test'; |
|
| 47 | - if ($crash) { |
|
| 48 | - ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 49 | - spip_log('crash des tables', 'err'); |
|
| 50 | - spip_log($crash, 'err'); |
|
| 51 | - } else { |
|
| 52 | - effacer_meta('message_crash_tables'); |
|
| 53 | - } |
|
| 35 | + if (spip_connect()) { |
|
| 36 | + include_spip('base/serial'); |
|
| 37 | + include_spip('base/auxiliaires'); |
|
| 38 | + $crash = array(); |
|
| 39 | + foreach (array('tables_principales', 'tables_auxiliaires') as $com) { |
|
| 40 | + foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 41 | + if (!sql_select('*', $table,'','','', 1) |
|
| 42 | + AND !defined('spip_interdire_cache')) # cas "LOST CONNECTION" |
|
| 43 | + $crash[] = $table; |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + #$crash[] = 'test'; |
|
| 47 | + if ($crash) { |
|
| 48 | + ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 49 | + spip_log('crash des tables', 'err'); |
|
| 50 | + spip_log($crash, 'err'); |
|
| 51 | + } else { |
|
| 52 | + effacer_meta('message_crash_tables'); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - return $crash; |
|
| 56 | - } |
|
| 55 | + return $crash; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return false; |
|
| 58 | + return false; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // http://doc.spip.org/@message_crash_tables |
| 62 | 62 | function message_crash_tables() { |
| 63 | - if ($crash = verifier_crash_tables()) { |
|
| 64 | - return |
|
| 65 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 66 | - . ' <tt>'.join(', ', $crash).'</tt><br />' |
|
| 67 | - . generer_form_ecrire('base_repair', |
|
| 68 | - _T('texte_crash_base'), '', |
|
| 69 | - _T('bouton_tenter_recuperation')) |
|
| 70 | - ; |
|
| 71 | - } |
|
| 63 | + if ($crash = verifier_crash_tables()) { |
|
| 64 | + return |
|
| 65 | + '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 66 | + . ' <tt>'.join(', ', $crash).'</tt><br />' |
|
| 67 | + . generer_form_ecrire('base_repair', |
|
| 68 | + _T('texte_crash_base'), '', |
|
| 69 | + _T('bouton_tenter_recuperation')) |
|
| 70 | + ; |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | ?> |