@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @return string Le SHA de la chaîne |
| 12 | 12 | */ |
| 13 | 13 | function spip_sha256($str) { |
| 14 | - return hash('sha256', $str); |
|
| 14 | + return hash('sha256', $str); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -22,5 +22,5 @@ discard block |
||
| 22 | 22 | * @see spip_sha256() |
| 23 | 23 | */ |
| 24 | 24 | function _nano_sha256($str, $ig_func = true) { |
| 25 | - return spip_sha256($str); |
|
| 25 | + return spip_sha256($str); |
|
| 26 | 26 | } |
@@ -20,11 +20,11 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | if (!defined('_MYSQL_NOPLANES')) { |
| 27 | - define('_MYSQL_NOPLANES', true); |
|
| 27 | + define('_MYSQL_NOPLANES', true); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -41,104 +41,104 @@ discard block |
||
| 41 | 41 | * - tableau décrivant la connexion sinon |
| 42 | 42 | */ |
| 43 | 43 | function req_mysql_dist($host, $port, $login, $pass, $db = '', $prefixe = '') { |
| 44 | - if (!extension_loaded('mysqli')) { |
|
| 45 | - return false; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | - if ( |
|
| 50 | - $port and !is_numeric($socket = $port) |
|
| 51 | - and (!$host or $host=='localhost')) { |
|
| 52 | - $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 53 | - } |
|
| 54 | - elseif ($port) { |
|
| 55 | - $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | - } |
|
| 57 | - else { |
|
| 58 | - $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if (!$link) { |
|
| 62 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 63 | - |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 66 | - $last = ''; |
|
| 67 | - if (!$db) { |
|
| 68 | - $ok = $link; |
|
| 69 | - $db = 'spip'; |
|
| 70 | - } else { |
|
| 71 | - $ok = mysqli_select_db($link, $db); |
|
| 72 | - if (defined('_MYSQL_SET_SQL_MODE') |
|
| 73 | - or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 74 | - ) { |
|
| 75 | - mysqli_query($link, $last = "set sql_mode=''"); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 80 | - _LOG_DEBUG); |
|
| 81 | - |
|
| 82 | - return !$ok ? false : array( |
|
| 83 | - 'db' => $db, |
|
| 84 | - 'last' => $last, |
|
| 85 | - 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 86 | - 'link' => $link, |
|
| 87 | - 'total_requetes' => 0, |
|
| 88 | - ); |
|
| 44 | + if (!extension_loaded('mysqli')) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | + if ( |
|
| 50 | + $port and !is_numeric($socket = $port) |
|
| 51 | + and (!$host or $host=='localhost')) { |
|
| 52 | + $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 53 | + } |
|
| 54 | + elseif ($port) { |
|
| 55 | + $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | + } |
|
| 57 | + else { |
|
| 58 | + $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if (!$link) { |
|
| 62 | + spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 63 | + |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | + $last = ''; |
|
| 67 | + if (!$db) { |
|
| 68 | + $ok = $link; |
|
| 69 | + $db = 'spip'; |
|
| 70 | + } else { |
|
| 71 | + $ok = mysqli_select_db($link, $db); |
|
| 72 | + if (defined('_MYSQL_SET_SQL_MODE') |
|
| 73 | + or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 74 | + ) { |
|
| 75 | + mysqli_query($link, $last = "set sql_mode=''"); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 80 | + _LOG_DEBUG); |
|
| 81 | + |
|
| 82 | + return !$ok ? false : array( |
|
| 83 | + 'db' => $db, |
|
| 84 | + 'last' => $last, |
|
| 85 | + 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 86 | + 'link' => $link, |
|
| 87 | + 'total_requetes' => 0, |
|
| 88 | + ); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | $GLOBALS['spip_mysql_functions_1'] = array( |
| 93 | - 'alter' => 'spip_mysql_alter', |
|
| 94 | - 'count' => 'spip_mysql_count', |
|
| 95 | - 'countsel' => 'spip_mysql_countsel', |
|
| 96 | - 'create' => 'spip_mysql_create', |
|
| 97 | - 'create_base' => 'spip_mysql_create_base', |
|
| 98 | - 'create_view' => 'spip_mysql_create_view', |
|
| 99 | - 'date_proche' => 'spip_mysql_date_proche', |
|
| 100 | - 'delete' => 'spip_mysql_delete', |
|
| 101 | - 'drop_table' => 'spip_mysql_drop_table', |
|
| 102 | - 'drop_view' => 'spip_mysql_drop_view', |
|
| 103 | - 'errno' => 'spip_mysql_errno', |
|
| 104 | - 'error' => 'spip_mysql_error', |
|
| 105 | - 'explain' => 'spip_mysql_explain', |
|
| 106 | - 'fetch' => 'spip_mysql_fetch', |
|
| 107 | - 'seek' => 'spip_mysql_seek', |
|
| 108 | - 'free' => 'spip_mysql_free', |
|
| 109 | - 'hex' => 'spip_mysql_hex', |
|
| 110 | - 'in' => 'spip_mysql_in', |
|
| 111 | - 'insert' => 'spip_mysql_insert', |
|
| 112 | - 'insertq' => 'spip_mysql_insertq', |
|
| 113 | - 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 114 | - 'listdbs' => 'spip_mysql_listdbs', |
|
| 115 | - 'multi' => 'spip_mysql_multi', |
|
| 116 | - 'optimize' => 'spip_mysql_optimize', |
|
| 117 | - 'query' => 'spip_mysql_query', |
|
| 118 | - 'quote' => 'spip_mysql_quote', |
|
| 119 | - 'replace' => 'spip_mysql_replace', |
|
| 120 | - 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 121 | - 'repair' => 'spip_mysql_repair', |
|
| 122 | - 'select' => 'spip_mysql_select', |
|
| 123 | - 'selectdb' => 'spip_mysql_selectdb', |
|
| 124 | - 'set_charset' => 'spip_mysql_set_charset', |
|
| 125 | - 'get_charset' => 'spip_mysql_get_charset', |
|
| 126 | - 'showbase' => 'spip_mysql_showbase', |
|
| 127 | - 'showtable' => 'spip_mysql_showtable', |
|
| 128 | - 'update' => 'spip_mysql_update', |
|
| 129 | - 'updateq' => 'spip_mysql_updateq', |
|
| 130 | - |
|
| 131 | - // association de chaque nom http d'un charset aux couples MySQL |
|
| 132 | - 'charsets' => array( |
|
| 133 | - 'cp1250' => array('charset' => 'cp1250', 'collation' => 'cp1250_general_ci'), |
|
| 134 | - 'cp1251' => array('charset' => 'cp1251', 'collation' => 'cp1251_general_ci'), |
|
| 135 | - 'cp1256' => array('charset' => 'cp1256', 'collation' => 'cp1256_general_ci'), |
|
| 136 | - 'iso-8859-1' => array('charset' => 'latin1', 'collation' => 'latin1_swedish_ci'), |
|
| 93 | + 'alter' => 'spip_mysql_alter', |
|
| 94 | + 'count' => 'spip_mysql_count', |
|
| 95 | + 'countsel' => 'spip_mysql_countsel', |
|
| 96 | + 'create' => 'spip_mysql_create', |
|
| 97 | + 'create_base' => 'spip_mysql_create_base', |
|
| 98 | + 'create_view' => 'spip_mysql_create_view', |
|
| 99 | + 'date_proche' => 'spip_mysql_date_proche', |
|
| 100 | + 'delete' => 'spip_mysql_delete', |
|
| 101 | + 'drop_table' => 'spip_mysql_drop_table', |
|
| 102 | + 'drop_view' => 'spip_mysql_drop_view', |
|
| 103 | + 'errno' => 'spip_mysql_errno', |
|
| 104 | + 'error' => 'spip_mysql_error', |
|
| 105 | + 'explain' => 'spip_mysql_explain', |
|
| 106 | + 'fetch' => 'spip_mysql_fetch', |
|
| 107 | + 'seek' => 'spip_mysql_seek', |
|
| 108 | + 'free' => 'spip_mysql_free', |
|
| 109 | + 'hex' => 'spip_mysql_hex', |
|
| 110 | + 'in' => 'spip_mysql_in', |
|
| 111 | + 'insert' => 'spip_mysql_insert', |
|
| 112 | + 'insertq' => 'spip_mysql_insertq', |
|
| 113 | + 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 114 | + 'listdbs' => 'spip_mysql_listdbs', |
|
| 115 | + 'multi' => 'spip_mysql_multi', |
|
| 116 | + 'optimize' => 'spip_mysql_optimize', |
|
| 117 | + 'query' => 'spip_mysql_query', |
|
| 118 | + 'quote' => 'spip_mysql_quote', |
|
| 119 | + 'replace' => 'spip_mysql_replace', |
|
| 120 | + 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 121 | + 'repair' => 'spip_mysql_repair', |
|
| 122 | + 'select' => 'spip_mysql_select', |
|
| 123 | + 'selectdb' => 'spip_mysql_selectdb', |
|
| 124 | + 'set_charset' => 'spip_mysql_set_charset', |
|
| 125 | + 'get_charset' => 'spip_mysql_get_charset', |
|
| 126 | + 'showbase' => 'spip_mysql_showbase', |
|
| 127 | + 'showtable' => 'spip_mysql_showtable', |
|
| 128 | + 'update' => 'spip_mysql_update', |
|
| 129 | + 'updateq' => 'spip_mysql_updateq', |
|
| 130 | + |
|
| 131 | + // association de chaque nom http d'un charset aux couples MySQL |
|
| 132 | + 'charsets' => array( |
|
| 133 | + 'cp1250' => array('charset' => 'cp1250', 'collation' => 'cp1250_general_ci'), |
|
| 134 | + 'cp1251' => array('charset' => 'cp1251', 'collation' => 'cp1251_general_ci'), |
|
| 135 | + 'cp1256' => array('charset' => 'cp1256', 'collation' => 'cp1256_general_ci'), |
|
| 136 | + 'iso-8859-1' => array('charset' => 'latin1', 'collation' => 'latin1_swedish_ci'), |
|
| 137 | 137 | //'iso-8859-6'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 138 | - 'iso-8859-9' => array('charset' => 'latin5', 'collation' => 'latin5_turkish_ci'), |
|
| 138 | + 'iso-8859-9' => array('charset' => 'latin5', 'collation' => 'latin5_turkish_ci'), |
|
| 139 | 139 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 140 | - 'utf-8' => array('charset' => 'utf8', 'collation' => 'utf8_general_ci') |
|
| 141 | - ) |
|
| 140 | + 'utf-8' => array('charset' => 'utf8', 'collation' => 'utf8_general_ci') |
|
| 141 | + ) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | 144 | |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | * @return Object Information de connexion pour mysqli |
| 150 | 150 | */ |
| 151 | 151 | function _mysql_link($serveur = '') { |
| 152 | - $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 152 | + $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 153 | 153 | |
| 154 | - return $link; |
|
| 154 | + return $link; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | * @return resource Ressource de résultats pour fetch() |
| 165 | 165 | */ |
| 166 | 166 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 167 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 168 | - spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 167 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 168 | + spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 169 | 169 | |
| 170 | - return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 170 | + return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | * @return array Description du charset (son nom est dans 'charset') |
| 181 | 181 | */ |
| 182 | 182 | function spip_mysql_get_charset($charset = array(), $serveur = '', $requeter = true) { |
| 183 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 184 | - $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 185 | - . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 183 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 184 | + $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 185 | + . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 186 | 186 | |
| 187 | - return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 187 | + return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -200,66 +200,66 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | function spip_mysql_query($query, $serveur = '', $requeter = true) { |
| 202 | 202 | |
| 203 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 204 | - $prefixe = $connexion['prefixe']; |
|
| 205 | - $link = $connexion['link']; |
|
| 206 | - $db = $connexion['db']; |
|
| 207 | - |
|
| 208 | - $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 209 | - |
|
| 210 | - // renvoyer la requete inerte si demandee |
|
| 211 | - if (!$requeter) { |
|
| 212 | - return $query; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - if (isset($_GET['var_profile'])) { |
|
| 216 | - include_spip('public/tracer'); |
|
| 217 | - $t = trace_query_start(); |
|
| 218 | - } else { |
|
| 219 | - $t = 0; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $connexion['last'] = $query; |
|
| 223 | - $connexion['total_requetes']++; |
|
| 224 | - |
|
| 225 | - // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 226 | - $debug = ''; |
|
| 227 | - if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 228 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 229 | - list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 230 | - $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . " | "; |
|
| 231 | - } |
|
| 232 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 233 | - $debug .= $_SERVER['REQUEST_URI']; |
|
| 234 | - } |
|
| 235 | - if (!empty($GLOBALS['ip'])) { |
|
| 236 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 237 | - } |
|
| 238 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $r = mysqli_query($link, $query . $debug); |
|
| 242 | - |
|
| 243 | - //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 244 | - if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 245 | - if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 246 | - //Fermer la connexion defaillante |
|
| 247 | - mysqli_close($connexion['link']); |
|
| 248 | - unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 249 | - //Relancer une connexion vierge |
|
| 250 | - spip_connect($serveur); |
|
| 251 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 252 | - $link = $connexion['link']; |
|
| 253 | - //On retente au cas où |
|
| 254 | - $r = mysqli_query($link, $query . $debug); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // Log de l'erreur eventuelle |
|
| 259 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 260 | - $e .= spip_mysql_error($query, $serveur); |
|
| 261 | - } // et du fautif |
|
| 262 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 203 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 204 | + $prefixe = $connexion['prefixe']; |
|
| 205 | + $link = $connexion['link']; |
|
| 206 | + $db = $connexion['db']; |
|
| 207 | + |
|
| 208 | + $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 209 | + |
|
| 210 | + // renvoyer la requete inerte si demandee |
|
| 211 | + if (!$requeter) { |
|
| 212 | + return $query; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + if (isset($_GET['var_profile'])) { |
|
| 216 | + include_spip('public/tracer'); |
|
| 217 | + $t = trace_query_start(); |
|
| 218 | + } else { |
|
| 219 | + $t = 0; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $connexion['last'] = $query; |
|
| 223 | + $connexion['total_requetes']++; |
|
| 224 | + |
|
| 225 | + // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 226 | + $debug = ''; |
|
| 227 | + if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 228 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 229 | + list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 230 | + $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . " | "; |
|
| 231 | + } |
|
| 232 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 233 | + $debug .= $_SERVER['REQUEST_URI']; |
|
| 234 | + } |
|
| 235 | + if (!empty($GLOBALS['ip'])) { |
|
| 236 | + $debug .= ' + ' . $GLOBALS['ip']; |
|
| 237 | + } |
|
| 238 | + $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $r = mysqli_query($link, $query . $debug); |
|
| 242 | + |
|
| 243 | + //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 244 | + if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 245 | + if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 246 | + //Fermer la connexion defaillante |
|
| 247 | + mysqli_close($connexion['link']); |
|
| 248 | + unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 249 | + //Relancer une connexion vierge |
|
| 250 | + spip_connect($serveur); |
|
| 251 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 252 | + $link = $connexion['link']; |
|
| 253 | + //On retente au cas où |
|
| 254 | + $r = mysqli_query($link, $query . $debug); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // Log de l'erreur eventuelle |
|
| 259 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 260 | + $e .= spip_mysql_error($query, $serveur); |
|
| 261 | + } // et du fautif |
|
| 262 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -274,12 +274,12 @@ discard block |
||
| 274 | 274 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 275 | 275 | */ |
| 276 | 276 | function spip_mysql_alter($query, $serveur = '', $requeter = true) { |
| 277 | - // ici on supprime les ` entourant le nom de table pour permettre |
|
| 278 | - // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 279 | - // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 280 | - $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
|
| 277 | + // ici on supprime les ` entourant le nom de table pour permettre |
|
| 278 | + // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 279 | + // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 280 | + $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
|
| 281 | 281 | |
| 282 | - return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 282 | + return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -292,9 +292,9 @@ discard block |
||
| 292 | 292 | * @return bool Toujours true |
| 293 | 293 | */ |
| 294 | 294 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 295 | - spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 295 | + spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 296 | 296 | |
| 297 | - return true; |
|
| 297 | + return true; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -307,18 +307,18 @@ discard block |
||
| 307 | 307 | * @return array Tableau de l'explication |
| 308 | 308 | */ |
| 309 | 309 | function spip_mysql_explain($query, $serveur = '', $requeter = true) { |
| 310 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 311 | - return array(); |
|
| 312 | - } |
|
| 313 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 314 | - $prefixe = $connexion['prefixe']; |
|
| 315 | - $link = $connexion['link']; |
|
| 316 | - $db = $connexion['db']; |
|
| 317 | - |
|
| 318 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 319 | - $r = mysqli_query($link, $query); |
|
| 320 | - |
|
| 321 | - return spip_mysql_fetch($r, null, $serveur); |
|
| 310 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 311 | + return array(); |
|
| 312 | + } |
|
| 313 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 314 | + $prefixe = $connexion['prefixe']; |
|
| 315 | + $link = $connexion['link']; |
|
| 316 | + $db = $connexion['db']; |
|
| 317 | + |
|
| 318 | + $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 319 | + $r = mysqli_query($link, $query); |
|
| 320 | + |
|
| 321 | + return spip_mysql_fetch($r, null, $serveur); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
@@ -347,35 +347,35 @@ discard block |
||
| 347 | 347 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 348 | 348 | */ |
| 349 | 349 | function spip_mysql_select( |
| 350 | - $select, |
|
| 351 | - $from, |
|
| 352 | - $where = '', |
|
| 353 | - $groupby = '', |
|
| 354 | - $orderby = '', |
|
| 355 | - $limit = '', |
|
| 356 | - $having = '', |
|
| 357 | - $serveur = '', |
|
| 358 | - $requeter = true |
|
| 350 | + $select, |
|
| 351 | + $from, |
|
| 352 | + $where = '', |
|
| 353 | + $groupby = '', |
|
| 354 | + $orderby = '', |
|
| 355 | + $limit = '', |
|
| 356 | + $having = '', |
|
| 357 | + $serveur = '', |
|
| 358 | + $requeter = true |
|
| 359 | 359 | ) { |
| 360 | 360 | |
| 361 | 361 | |
| 362 | - $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 363 | - $query = |
|
| 364 | - calculer_mysql_expression('SELECT', $select, ', ') |
|
| 365 | - . calculer_mysql_expression('FROM', $from, ', ') |
|
| 366 | - . calculer_mysql_expression('WHERE', $where) |
|
| 367 | - . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 368 | - . calculer_mysql_expression('HAVING', $having) |
|
| 369 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 370 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 362 | + $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 363 | + $query = |
|
| 364 | + calculer_mysql_expression('SELECT', $select, ', ') |
|
| 365 | + . calculer_mysql_expression('FROM', $from, ', ') |
|
| 366 | + . calculer_mysql_expression('WHERE', $where) |
|
| 367 | + . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 368 | + . calculer_mysql_expression('HAVING', $having) |
|
| 369 | + . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 370 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 371 | 371 | |
| 372 | - // renvoyer la requete inerte si demandee |
|
| 373 | - if ($requeter === false) { |
|
| 374 | - return $query; |
|
| 375 | - } |
|
| 376 | - $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 372 | + // renvoyer la requete inerte si demandee |
|
| 373 | + if ($requeter === false) { |
|
| 374 | + return $query; |
|
| 375 | + } |
|
| 376 | + $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 377 | 377 | |
| 378 | - return $r ? $r : $query; |
|
| 378 | + return $r ? $r : $query; |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | * @return string Texte du orderby préparé |
| 393 | 393 | */ |
| 394 | 394 | function spip_mysql_order($orderby) { |
| 395 | - return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 395 | + return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | |
@@ -415,26 +415,26 @@ discard block |
||
| 415 | 415 | * Contrainte pour clause WHERE |
| 416 | 416 | */ |
| 417 | 417 | function calculer_mysql_where($v) { |
| 418 | - if (!is_array($v)) { |
|
| 419 | - return $v; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - $op = array_shift($v); |
|
| 423 | - if (!($n = count($v))) { |
|
| 424 | - return $op; |
|
| 425 | - } else { |
|
| 426 | - $arg = calculer_mysql_where(array_shift($v)); |
|
| 427 | - if ($n == 1) { |
|
| 428 | - return "$op($arg)"; |
|
| 429 | - } else { |
|
| 430 | - $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 431 | - if ($n == 2) { |
|
| 432 | - return "($arg $op $arg2)"; |
|
| 433 | - } else { |
|
| 434 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - } |
|
| 418 | + if (!is_array($v)) { |
|
| 419 | + return $v; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + $op = array_shift($v); |
|
| 423 | + if (!($n = count($v))) { |
|
| 424 | + return $op; |
|
| 425 | + } else { |
|
| 426 | + $arg = calculer_mysql_where(array_shift($v)); |
|
| 427 | + if ($n == 1) { |
|
| 428 | + return "$op($arg)"; |
|
| 429 | + } else { |
|
| 430 | + $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 431 | + if ($n == 2) { |
|
| 432 | + return "($arg $op $arg2)"; |
|
| 433 | + } else { |
|
| 434 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | /** |
@@ -449,21 +449,21 @@ discard block |
||
| 449 | 449 | * @return string Texte de l'expression, une partie donc, du texte la requête. |
| 450 | 450 | */ |
| 451 | 451 | function calculer_mysql_expression($expression, $v, $join = 'AND') { |
| 452 | - if (empty($v)) { |
|
| 453 | - return ''; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - $exp = "\n$expression "; |
|
| 457 | - |
|
| 458 | - if (!is_array($v)) { |
|
| 459 | - return $exp . $v; |
|
| 460 | - } else { |
|
| 461 | - if (strtoupper($join) === 'AND') { |
|
| 462 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 463 | - } else { |
|
| 464 | - return $exp . join($join, $v); |
|
| 465 | - } |
|
| 466 | - } |
|
| 452 | + if (empty($v)) { |
|
| 453 | + return ''; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + $exp = "\n$expression "; |
|
| 457 | + |
|
| 458 | + if (!is_array($v)) { |
|
| 459 | + return $exp . $v; |
|
| 460 | + } else { |
|
| 461 | + if (strtoupper($join) === 'AND') { |
|
| 462 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 463 | + } else { |
|
| 464 | + return $exp . join($join, $v); |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -474,26 +474,26 @@ discard block |
||
| 474 | 474 | * @return string Sélection de colonnes pour une clause SELECT |
| 475 | 475 | */ |
| 476 | 476 | function spip_mysql_select_as($args) { |
| 477 | - $res = ''; |
|
| 478 | - foreach ($args as $k => $v) { |
|
| 479 | - if (substr($k, -1) == '@') { |
|
| 480 | - // c'est une jointure qui se refere au from precedent |
|
| 481 | - // pas de virgule |
|
| 482 | - $res .= ' ' . $v; |
|
| 483 | - } else { |
|
| 484 | - if (!is_numeric($k)) { |
|
| 485 | - $p = strpos($v, " "); |
|
| 486 | - if ($p) { |
|
| 487 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 488 | - } else { |
|
| 489 | - $v .= " AS `$k`"; |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - $res .= ', ' . $v; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return substr($res, 2); |
|
| 477 | + $res = ''; |
|
| 478 | + foreach ($args as $k => $v) { |
|
| 479 | + if (substr($k, -1) == '@') { |
|
| 480 | + // c'est une jointure qui se refere au from precedent |
|
| 481 | + // pas de virgule |
|
| 482 | + $res .= ' ' . $v; |
|
| 483 | + } else { |
|
| 484 | + if (!is_numeric($k)) { |
|
| 485 | + $p = strpos($v, " "); |
|
| 486 | + if ($p) { |
|
| 487 | + $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 488 | + } else { |
|
| 489 | + $v .= " AS `$k`"; |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + $res .= ', ' . $v; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return substr($res, 2); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | |
@@ -517,46 +517,46 @@ discard block |
||
| 517 | 517 | */ |
| 518 | 518 | function _mysql_traite_query($query, $db = '', $prefixe = '') { |
| 519 | 519 | |
| 520 | - if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 521 | - $pref = '`' . $db . '`.'; |
|
| 522 | - } else { |
|
| 523 | - $pref = ''; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - if ($prefixe) { |
|
| 527 | - $pref .= $prefixe . "_"; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 531 | - $suite = ''; |
|
| 532 | - } else { |
|
| 533 | - $suite = strstr($query, $regs[0]); |
|
| 534 | - $query = substr($query, 0, -strlen($suite)); |
|
| 535 | - // propager le prefixe en cas de requete imbriquee |
|
| 536 | - // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 537 | - // modifier une requete qui est en fait juste du texte dans un champ |
|
| 538 | - if (stripos($suite, "SELECT") !== false) { |
|
| 539 | - list($suite, $textes) = query_echappe_textes($suite); |
|
| 540 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
|
| 541 | - $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 542 | - } |
|
| 543 | - $suite = query_reinjecte_textes($suite, $textes); |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 547 | - |
|
| 548 | - // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 549 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 550 | - if (defined('_MYSQL_NOPLANES') |
|
| 551 | - and _MYSQL_NOPLANES |
|
| 552 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 553 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8') { |
|
| 554 | - include_spip('inc/charsets'); |
|
| 555 | - $r = utf8_noplanes($r); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 559 | - return $r; |
|
| 520 | + if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 521 | + $pref = '`' . $db . '`.'; |
|
| 522 | + } else { |
|
| 523 | + $pref = ''; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + if ($prefixe) { |
|
| 527 | + $pref .= $prefixe . "_"; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 531 | + $suite = ''; |
|
| 532 | + } else { |
|
| 533 | + $suite = strstr($query, $regs[0]); |
|
| 534 | + $query = substr($query, 0, -strlen($suite)); |
|
| 535 | + // propager le prefixe en cas de requete imbriquee |
|
| 536 | + // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 537 | + // modifier une requete qui est en fait juste du texte dans un champ |
|
| 538 | + if (stripos($suite, "SELECT") !== false) { |
|
| 539 | + list($suite, $textes) = query_echappe_textes($suite); |
|
| 540 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
|
| 541 | + $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 542 | + } |
|
| 543 | + $suite = query_reinjecte_textes($suite, $textes); |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 547 | + |
|
| 548 | + // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 549 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 550 | + if (defined('_MYSQL_NOPLANES') |
|
| 551 | + and _MYSQL_NOPLANES |
|
| 552 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 553 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8') { |
|
| 554 | + include_spip('inc/charsets'); |
|
| 555 | + $r = utf8_noplanes($r); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 559 | + return $r; |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | /** |
@@ -574,13 +574,13 @@ discard block |
||
| 574 | 574 | * - False en cas d'erreur. |
| 575 | 575 | **/ |
| 576 | 576 | function spip_mysql_selectdb($db, $serveur = '', $requeter = true) { |
| 577 | - $link = _mysql_link($serveur); |
|
| 578 | - $ok = mysqli_select_db($link, $db); |
|
| 579 | - if (!$ok) { |
|
| 580 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 581 | - } |
|
| 577 | + $link = _mysql_link($serveur); |
|
| 578 | + $ok = mysqli_select_db($link, $db); |
|
| 579 | + if (!$ok) { |
|
| 580 | + spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 581 | + } |
|
| 582 | 582 | |
| 583 | - return $ok; |
|
| 583 | + return $ok; |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | |
@@ -601,14 +601,14 @@ discard block |
||
| 601 | 601 | * Liste de noms de bases de données |
| 602 | 602 | **/ |
| 603 | 603 | function spip_mysql_listdbs($serveur = '', $requeter = true) { |
| 604 | - $dbs = array(); |
|
| 605 | - if ($res = spip_mysql_query("SHOW DATABASES", $serveur)) { |
|
| 606 | - while ($row = mysqli_fetch_assoc($res)) { |
|
| 607 | - $dbs[] = $row['Database']; |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - return $dbs; |
|
| 604 | + $dbs = array(); |
|
| 605 | + if ($res = spip_mysql_query("SHOW DATABASES", $serveur)) { |
|
| 606 | + while ($row = mysqli_fetch_assoc($res)) { |
|
| 607 | + $dbs[] = $row['Database']; |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + return $dbs; |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | |
@@ -631,72 +631,72 @@ discard block |
||
| 631 | 631 | * - true si la requête réussie, false sinon. |
| 632 | 632 | */ |
| 633 | 633 | function spip_mysql_create( |
| 634 | - $nom, |
|
| 635 | - $champs, |
|
| 636 | - $cles, |
|
| 637 | - $autoinc = false, |
|
| 638 | - $temporary = false, |
|
| 639 | - $serveur = '', |
|
| 640 | - $requeter = true |
|
| 634 | + $nom, |
|
| 635 | + $champs, |
|
| 636 | + $cles, |
|
| 637 | + $autoinc = false, |
|
| 638 | + $temporary = false, |
|
| 639 | + $serveur = '', |
|
| 640 | + $requeter = true |
|
| 641 | 641 | ) { |
| 642 | 642 | |
| 643 | - $query = ''; |
|
| 644 | - $keys = ''; |
|
| 645 | - $s = ''; |
|
| 646 | - $p = ''; |
|
| 647 | - |
|
| 648 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 649 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 650 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 651 | - return; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - $res = spip_mysql_query("SELECT version() as v", $serveur); |
|
| 655 | - if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 656 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - foreach ($cles as $k => $v) { |
|
| 660 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 661 | - if ($k == "PRIMARY KEY") { |
|
| 662 | - $p = $v; |
|
| 663 | - } |
|
| 664 | - $s = ","; |
|
| 665 | - } |
|
| 666 | - $s = ''; |
|
| 667 | - |
|
| 668 | - $character_set = ""; |
|
| 669 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 670 | - $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 671 | - } |
|
| 672 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 673 | - $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - foreach ($champs as $k => $v) { |
|
| 677 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 678 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 679 | - if (preg_match(',(char|text),i', $defs[1]) |
|
| 680 | - and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 681 | - ) { |
|
| 682 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - $query .= "$s\n\t\t$k $v" |
|
| 687 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 688 | - ? " auto_increment" |
|
| 689 | - : '' |
|
| 690 | - ); |
|
| 691 | - $s = ","; |
|
| 692 | - } |
|
| 693 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 694 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 695 | - . " ENGINE=MyISAM" |
|
| 696 | - . ($character_set ? " DEFAULT $character_set" : "") |
|
| 697 | - . "\n"; |
|
| 698 | - |
|
| 699 | - return spip_mysql_query($q, $serveur); |
|
| 643 | + $query = ''; |
|
| 644 | + $keys = ''; |
|
| 645 | + $s = ''; |
|
| 646 | + $p = ''; |
|
| 647 | + |
|
| 648 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 649 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 650 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 651 | + return; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + $res = spip_mysql_query("SELECT version() as v", $serveur); |
|
| 655 | + if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 656 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + foreach ($cles as $k => $v) { |
|
| 660 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 661 | + if ($k == "PRIMARY KEY") { |
|
| 662 | + $p = $v; |
|
| 663 | + } |
|
| 664 | + $s = ","; |
|
| 665 | + } |
|
| 666 | + $s = ''; |
|
| 667 | + |
|
| 668 | + $character_set = ""; |
|
| 669 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 670 | + $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 671 | + } |
|
| 672 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 673 | + $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + foreach ($champs as $k => $v) { |
|
| 677 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 678 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 679 | + if (preg_match(',(char|text),i', $defs[1]) |
|
| 680 | + and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 681 | + ) { |
|
| 682 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + $query .= "$s\n\t\t$k $v" |
|
| 687 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 688 | + ? " auto_increment" |
|
| 689 | + : '' |
|
| 690 | + ); |
|
| 691 | + $s = ","; |
|
| 692 | + } |
|
| 693 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 694 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 695 | + . " ENGINE=MyISAM" |
|
| 696 | + . ($character_set ? " DEFAULT $character_set" : "") |
|
| 697 | + . "\n"; |
|
| 698 | + |
|
| 699 | + return spip_mysql_query($q, $serveur); |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | |
@@ -709,25 +709,25 @@ discard block |
||
| 709 | 709 | * Définition SQL adaptée pour MySQL d'un champ de table |
| 710 | 710 | */ |
| 711 | 711 | function _mysql_remplacements_definitions_table($query) { |
| 712 | - // quelques remplacements |
|
| 713 | - $num = "(\s*\([0-9]*\))?"; |
|
| 714 | - $enum = "(\s*\([^\)]*\))?"; |
|
| 715 | - |
|
| 716 | - $remplace = array( |
|
| 717 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 718 | - '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 719 | - ); |
|
| 720 | - |
|
| 721 | - if (is_string($query)) { |
|
| 722 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 723 | - } elseif (is_array($query)) { |
|
| 724 | - $keys = array_keys($remplace); |
|
| 725 | - foreach ($query as $k => $q) { |
|
| 726 | - $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - return $query; |
|
| 712 | + // quelques remplacements |
|
| 713 | + $num = "(\s*\([0-9]*\))?"; |
|
| 714 | + $enum = "(\s*\([^\)]*\))?"; |
|
| 715 | + |
|
| 716 | + $remplace = array( |
|
| 717 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 718 | + '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 719 | + ); |
|
| 720 | + |
|
| 721 | + if (is_string($query)) { |
|
| 722 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 723 | + } elseif (is_array($query)) { |
|
| 724 | + $keys = array_keys($remplace); |
|
| 725 | + foreach ($query as $k => $q) { |
|
| 726 | + $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + return $query; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | * @return bool true si la base est créee. |
| 741 | 741 | **/ |
| 742 | 742 | function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
| 743 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 743 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | |
@@ -761,19 +761,19 @@ discard block |
||
| 761 | 761 | * - string texte de la requête si $requeter vaut false |
| 762 | 762 | */ |
| 763 | 763 | function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 764 | - if (!$query_select) { |
|
| 765 | - return false; |
|
| 766 | - } |
|
| 767 | - // vue deja presente |
|
| 768 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 769 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 764 | + if (!$query_select) { |
|
| 765 | + return false; |
|
| 766 | + } |
|
| 767 | + // vue deja presente |
|
| 768 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 769 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 770 | 770 | |
| 771 | - return false; |
|
| 772 | - } |
|
| 771 | + return false; |
|
| 772 | + } |
|
| 773 | 773 | |
| 774 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 774 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 775 | 775 | |
| 776 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 776 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | |
@@ -789,11 +789,11 @@ discard block |
||
| 789 | 789 | * - true si la requête a réussie, false sinon |
| 790 | 790 | */ |
| 791 | 791 | function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 792 | - if ($exist) { |
|
| 793 | - $exist = " IF EXISTS"; |
|
| 794 | - } |
|
| 792 | + if ($exist) { |
|
| 793 | + $exist = " IF EXISTS"; |
|
| 794 | + } |
|
| 795 | 795 | |
| 796 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 796 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | /** |
@@ -808,11 +808,11 @@ discard block |
||
| 808 | 808 | * - true si la requête a réussie, false sinon |
| 809 | 809 | */ |
| 810 | 810 | function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 811 | - if ($exist) { |
|
| 812 | - $exist = " IF EXISTS"; |
|
| 813 | - } |
|
| 811 | + if ($exist) { |
|
| 812 | + $exist = " IF EXISTS"; |
|
| 813 | + } |
|
| 814 | 814 | |
| 815 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 815 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | /** |
@@ -829,7 +829,7 @@ discard block |
||
| 829 | 829 | * Ressource à utiliser avec sql_fetch() |
| 830 | 830 | **/ |
| 831 | 831 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 832 | - return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 832 | + return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | /** |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | * - true si la requête a réussie, false sinon |
| 846 | 846 | */ |
| 847 | 847 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 848 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 848 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | |
@@ -869,86 +869,86 @@ discard block |
||
| 869 | 869 | * - array description de la table sinon |
| 870 | 870 | */ |
| 871 | 871 | function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) { |
| 872 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 873 | - if (!$s) { |
|
| 874 | - return ''; |
|
| 875 | - } |
|
| 876 | - if (!$requeter) { |
|
| 877 | - return $s; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 881 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 882 | - $desc = $r[1]; |
|
| 883 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 884 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 885 | - if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 886 | - $namedkeys = $r[2]; |
|
| 887 | - $desc = $r[1]; |
|
| 888 | - } else { |
|
| 889 | - $namedkeys = ""; |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - $fields = array(); |
|
| 893 | - foreach (preg_split("/,\s*`/", $desc) as $v) { |
|
| 894 | - preg_match("/^\s*`?([^`]*)`\s*(.*)/", $v, $r); |
|
| 895 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 896 | - } |
|
| 897 | - $keys = array(); |
|
| 898 | - |
|
| 899 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 900 | - if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/", $v, $r)) { |
|
| 901 | - $k = str_replace("`", '', trim($r[1])); |
|
| 902 | - $t = strtolower(str_replace("`", '', $r[2])); |
|
| 903 | - if ($k && !isset($keys[$k])) { |
|
| 904 | - $keys[$k] = $t; |
|
| 905 | - } else { |
|
| 906 | - $keys[] = $t; |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - spip_mysql_free($s); |
|
| 911 | - |
|
| 912 | - return array('field' => $fields, 'key' => $keys); |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 916 | - if ($res) { |
|
| 917 | - $nfields = array(); |
|
| 918 | - $nkeys = array(); |
|
| 919 | - while ($val = spip_mysql_fetch($res)) { |
|
| 920 | - $nfields[$val["Field"]] = $val['Type']; |
|
| 921 | - if ($val['Null'] == 'NO') { |
|
| 922 | - $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 923 | - } |
|
| 924 | - if ($val['Default'] === '0' || $val['Default']) { |
|
| 925 | - if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 926 | - $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 927 | - } else { |
|
| 928 | - $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - if ($val['Extra']) { |
|
| 932 | - $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 933 | - } |
|
| 934 | - if ($val['Key'] == 'PRI') { |
|
| 935 | - $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 936 | - } else { |
|
| 937 | - if ($val['Key'] == 'MUL') { |
|
| 938 | - $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 939 | - } else { |
|
| 940 | - if ($val['Key'] == 'UNI') { |
|
| 941 | - $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - spip_mysql_free($res); |
|
| 947 | - |
|
| 948 | - return array('field' => $nfields, 'key' => $nkeys); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return ""; |
|
| 872 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 873 | + if (!$s) { |
|
| 874 | + return ''; |
|
| 875 | + } |
|
| 876 | + if (!$requeter) { |
|
| 877 | + return $s; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 881 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 882 | + $desc = $r[1]; |
|
| 883 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 884 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 885 | + if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 886 | + $namedkeys = $r[2]; |
|
| 887 | + $desc = $r[1]; |
|
| 888 | + } else { |
|
| 889 | + $namedkeys = ""; |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + $fields = array(); |
|
| 893 | + foreach (preg_split("/,\s*`/", $desc) as $v) { |
|
| 894 | + preg_match("/^\s*`?([^`]*)`\s*(.*)/", $v, $r); |
|
| 895 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 896 | + } |
|
| 897 | + $keys = array(); |
|
| 898 | + |
|
| 899 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 900 | + if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/", $v, $r)) { |
|
| 901 | + $k = str_replace("`", '', trim($r[1])); |
|
| 902 | + $t = strtolower(str_replace("`", '', $r[2])); |
|
| 903 | + if ($k && !isset($keys[$k])) { |
|
| 904 | + $keys[$k] = $t; |
|
| 905 | + } else { |
|
| 906 | + $keys[] = $t; |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + spip_mysql_free($s); |
|
| 911 | + |
|
| 912 | + return array('field' => $fields, 'key' => $keys); |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 916 | + if ($res) { |
|
| 917 | + $nfields = array(); |
|
| 918 | + $nkeys = array(); |
|
| 919 | + while ($val = spip_mysql_fetch($res)) { |
|
| 920 | + $nfields[$val["Field"]] = $val['Type']; |
|
| 921 | + if ($val['Null'] == 'NO') { |
|
| 922 | + $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 923 | + } |
|
| 924 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 925 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 926 | + $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 927 | + } else { |
|
| 928 | + $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + if ($val['Extra']) { |
|
| 932 | + $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 933 | + } |
|
| 934 | + if ($val['Key'] == 'PRI') { |
|
| 935 | + $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 936 | + } else { |
|
| 937 | + if ($val['Key'] == 'MUL') { |
|
| 938 | + $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 939 | + } else { |
|
| 940 | + if ($val['Key'] == 'UNI') { |
|
| 941 | + $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + spip_mysql_free($res); |
|
| 947 | + |
|
| 948 | + return array('field' => $nfields, 'key' => $nkeys); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return ""; |
|
| 952 | 952 | } |
| 953 | 953 | |
| 954 | 954 | |
@@ -964,12 +964,12 @@ discard block |
||
| 964 | 964 | * @return array Ligne de résultat |
| 965 | 965 | */ |
| 966 | 966 | function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 967 | - if (!$t) { |
|
| 968 | - $t = MYSQLI_ASSOC; |
|
| 969 | - } |
|
| 970 | - if ($r) { |
|
| 971 | - return mysqli_fetch_array($r, $t); |
|
| 972 | - } |
|
| 967 | + if (!$t) { |
|
| 968 | + $t = MYSQLI_ASSOC; |
|
| 969 | + } |
|
| 970 | + if ($r) { |
|
| 971 | + return mysqli_fetch_array($r, $t); |
|
| 972 | + } |
|
| 973 | 973 | } |
| 974 | 974 | |
| 975 | 975 | /** |
@@ -982,9 +982,9 @@ discard block |
||
| 982 | 982 | * @return bool True si déplacement réussi, false sinon. |
| 983 | 983 | **/ |
| 984 | 984 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 985 | - if ($r and mysqli_num_rows($r)) { |
|
| 986 | - return mysqli_data_seek($r, $row_number); |
|
| 987 | - } |
|
| 985 | + if ($r and mysqli_num_rows($r)) { |
|
| 986 | + return mysqli_data_seek($r, $row_number); |
|
| 987 | + } |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | |
@@ -1002,26 +1002,26 @@ discard block |
||
| 1002 | 1002 | * - int Nombre de lignes (0 si la requête n'a pas réussie) |
| 1003 | 1003 | **/ |
| 1004 | 1004 | function spip_mysql_countsel( |
| 1005 | - $from = array(), |
|
| 1006 | - $where = array(), |
|
| 1007 | - $groupby = '', |
|
| 1008 | - $having = array(), |
|
| 1009 | - $serveur = '', |
|
| 1010 | - $requeter = true |
|
| 1005 | + $from = array(), |
|
| 1006 | + $where = array(), |
|
| 1007 | + $groupby = '', |
|
| 1008 | + $having = array(), |
|
| 1009 | + $serveur = '', |
|
| 1010 | + $requeter = true |
|
| 1011 | 1011 | ) { |
| 1012 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1013 | - |
|
| 1014 | - $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1015 | - if (!$requeter) { |
|
| 1016 | - return $r; |
|
| 1017 | - } |
|
| 1018 | - if (!$r instanceof mysqli_result) { |
|
| 1019 | - return 0; |
|
| 1020 | - } |
|
| 1021 | - list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1022 | - mysqli_free_result($r); |
|
| 1023 | - |
|
| 1024 | - return $c; |
|
| 1012 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1013 | + |
|
| 1014 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1015 | + if (!$requeter) { |
|
| 1016 | + return $r; |
|
| 1017 | + } |
|
| 1018 | + if (!$r instanceof mysqli_result) { |
|
| 1019 | + return 0; |
|
| 1020 | + } |
|
| 1021 | + list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1022 | + mysqli_free_result($r); |
|
| 1023 | + |
|
| 1024 | + return $c; |
|
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | |
@@ -1044,16 +1044,16 @@ discard block |
||
| 1044 | 1044 | * Erreur eventuelle |
| 1045 | 1045 | **/ |
| 1046 | 1046 | function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
| 1047 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1048 | - $s = mysqli_error($link); |
|
| 1049 | - if ($s) { |
|
| 1050 | - $trace = debug_backtrace(); |
|
| 1051 | - if ($trace[0]['function'] != "spip_mysql_error") { |
|
| 1052 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - return $s; |
|
| 1047 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1048 | + $s = mysqli_error($link); |
|
| 1049 | + if ($s) { |
|
| 1050 | + $trace = debug_backtrace(); |
|
| 1051 | + if ($trace[0]['function'] != "spip_mysql_error") { |
|
| 1052 | + spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + return $s; |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | |
@@ -1068,18 +1068,18 @@ discard block |
||
| 1068 | 1068 | * 0, pas d'erreur. Autre, numéro de l'erreur. |
| 1069 | 1069 | **/ |
| 1070 | 1070 | function spip_mysql_errno($serveur = '', $requeter = true) { |
| 1071 | - $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1072 | - $s = mysqli_errno($link); |
|
| 1073 | - // 2006 MySQL server has gone away |
|
| 1074 | - // 2013 Lost connection to MySQL server during query |
|
| 1075 | - if (in_array($s, array(2006, 2013))) { |
|
| 1076 | - define('spip_interdire_cache', true); |
|
| 1077 | - } |
|
| 1078 | - if ($s) { |
|
| 1079 | - spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - return $s; |
|
| 1071 | + $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1072 | + $s = mysqli_errno($link); |
|
| 1073 | + // 2006 MySQL server has gone away |
|
| 1074 | + // 2013 Lost connection to MySQL server during query |
|
| 1075 | + if (in_array($s, array(2006, 2013))) { |
|
| 1076 | + define('spip_interdire_cache', true); |
|
| 1077 | + } |
|
| 1078 | + if ($s) { |
|
| 1079 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + return $s; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | |
@@ -1093,9 +1093,9 @@ discard block |
||
| 1093 | 1093 | * @return int Nombre de lignes |
| 1094 | 1094 | */ |
| 1095 | 1095 | function spip_mysql_count($r, $serveur = '', $requeter = true) { |
| 1096 | - if ($r) { |
|
| 1097 | - return mysqli_num_rows($r); |
|
| 1098 | - } |
|
| 1096 | + if ($r) { |
|
| 1097 | + return mysqli_num_rows($r); |
|
| 1098 | + } |
|
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | |
@@ -1111,7 +1111,7 @@ discard block |
||
| 1111 | 1111 | * @return bool True si réussi |
| 1112 | 1112 | */ |
| 1113 | 1113 | function spip_mysql_free($r, $serveur = '', $requeter = true) { |
| 1114 | - return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1114 | + return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | |
@@ -1139,47 +1139,47 @@ discard block |
||
| 1139 | 1139 | **/ |
| 1140 | 1140 | function spip_mysql_insert($table, $champs, $valeurs, $desc = array(), $serveur = '', $requeter = true) { |
| 1141 | 1141 | |
| 1142 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1143 | - $link = $connexion['link']; |
|
| 1144 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1145 | - |
|
| 1146 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1147 | - if (defined('_MYSQL_NOPLANES') |
|
| 1148 | - and _MYSQL_NOPLANES |
|
| 1149 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1150 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8') { |
|
| 1151 | - include_spip('inc/charsets'); |
|
| 1152 | - $valeurs = utf8_noplanes($valeurs); |
|
| 1153 | - } |
|
| 1154 | - |
|
| 1155 | - $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1156 | - if (!$requeter) { |
|
| 1157 | - return $query; |
|
| 1158 | - } |
|
| 1159 | - |
|
| 1160 | - if (isset($_GET['var_profile'])) { |
|
| 1161 | - include_spip('public/tracer'); |
|
| 1162 | - $t = trace_query_start(); |
|
| 1163 | - $e = ''; |
|
| 1164 | - } else { |
|
| 1165 | - $t = 0; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - $connexion['last'] = $query; |
|
| 1169 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1170 | - $r = false; |
|
| 1171 | - if (mysqli_query($link, $query)) { |
|
| 1172 | - $r = mysqli_insert_id($link); |
|
| 1173 | - } else { |
|
| 1174 | - // Log de l'erreur eventuelle |
|
| 1175 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 1176 | - $e .= spip_mysql_error($query, $serveur); |
|
| 1177 | - } // et du fautif |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1181 | - |
|
| 1182 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1142 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1143 | + $link = $connexion['link']; |
|
| 1144 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1145 | + |
|
| 1146 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1147 | + if (defined('_MYSQL_NOPLANES') |
|
| 1148 | + and _MYSQL_NOPLANES |
|
| 1149 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1150 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8') { |
|
| 1151 | + include_spip('inc/charsets'); |
|
| 1152 | + $valeurs = utf8_noplanes($valeurs); |
|
| 1153 | + } |
|
| 1154 | + |
|
| 1155 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1156 | + if (!$requeter) { |
|
| 1157 | + return $query; |
|
| 1158 | + } |
|
| 1159 | + |
|
| 1160 | + if (isset($_GET['var_profile'])) { |
|
| 1161 | + include_spip('public/tracer'); |
|
| 1162 | + $t = trace_query_start(); |
|
| 1163 | + $e = ''; |
|
| 1164 | + } else { |
|
| 1165 | + $t = 0; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + $connexion['last'] = $query; |
|
| 1169 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1170 | + $r = false; |
|
| 1171 | + if (mysqli_query($link, $query)) { |
|
| 1172 | + $r = mysqli_insert_id($link); |
|
| 1173 | + } else { |
|
| 1174 | + // Log de l'erreur eventuelle |
|
| 1175 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 1176 | + $e .= spip_mysql_error($query, $serveur); |
|
| 1177 | + } // et du fautif |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1181 | + |
|
| 1182 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | /** |
@@ -1204,20 +1204,20 @@ discard block |
||
| 1204 | 1204 | **/ |
| 1205 | 1205 | function spip_mysql_insertq($table, $couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 1206 | 1206 | |
| 1207 | - if (!$desc) { |
|
| 1208 | - $desc = description_table($table, $serveur); |
|
| 1209 | - } |
|
| 1210 | - if (!$desc) { |
|
| 1211 | - $couples = array(); |
|
| 1212 | - } |
|
| 1213 | - $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1207 | + if (!$desc) { |
|
| 1208 | + $desc = description_table($table, $serveur); |
|
| 1209 | + } |
|
| 1210 | + if (!$desc) { |
|
| 1211 | + $couples = array(); |
|
| 1212 | + } |
|
| 1213 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1214 | 1214 | |
| 1215 | - foreach ($couples as $champ => $val) { |
|
| 1216 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1217 | - } |
|
| 1215 | + foreach ($couples as $champ => $val) { |
|
| 1216 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1217 | + } |
|
| 1218 | 1218 | |
| 1219 | - return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1220 | - $serveur, $requeter); |
|
| 1219 | + return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1220 | + $serveur, $requeter); |
|
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | 1223 | |
@@ -1242,34 +1242,34 @@ discard block |
||
| 1242 | 1242 | **/ |
| 1243 | 1243 | function spip_mysql_insertq_multi($table, $tab_couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 1244 | 1244 | |
| 1245 | - if (!$desc) { |
|
| 1246 | - $desc = description_table($table, $serveur); |
|
| 1247 | - } |
|
| 1248 | - if (!$desc) { |
|
| 1249 | - $tab_couples = array(); |
|
| 1250 | - } |
|
| 1251 | - $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1252 | - |
|
| 1253 | - $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1254 | - $valeurs = array(); |
|
| 1255 | - $r = false; |
|
| 1256 | - |
|
| 1257 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1258 | - foreach ($tab_couples as $couples) { |
|
| 1259 | - foreach ($couples as $champ => $val) { |
|
| 1260 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1261 | - } |
|
| 1262 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1263 | - if (count($valeurs) >= 100) { |
|
| 1264 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1265 | - $valeurs = array(); |
|
| 1266 | - } |
|
| 1267 | - } |
|
| 1268 | - if (count($valeurs)) { |
|
| 1269 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1245 | + if (!$desc) { |
|
| 1246 | + $desc = description_table($table, $serveur); |
|
| 1247 | + } |
|
| 1248 | + if (!$desc) { |
|
| 1249 | + $tab_couples = array(); |
|
| 1250 | + } |
|
| 1251 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1252 | + |
|
| 1253 | + $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1254 | + $valeurs = array(); |
|
| 1255 | + $r = false; |
|
| 1256 | + |
|
| 1257 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1258 | + foreach ($tab_couples as $couples) { |
|
| 1259 | + foreach ($couples as $champ => $val) { |
|
| 1260 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1261 | + } |
|
| 1262 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1263 | + if (count($valeurs) >= 100) { |
|
| 1264 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1265 | + $valeurs = array(); |
|
| 1266 | + } |
|
| 1267 | + } |
|
| 1268 | + if (count($valeurs)) { |
|
| 1269 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | /** |
@@ -1294,17 +1294,17 @@ discard block |
||
| 1294 | 1294 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1295 | 1295 | */ |
| 1296 | 1296 | function spip_mysql_update($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1297 | - $set = array(); |
|
| 1298 | - foreach ($champs as $champ => $val) { |
|
| 1299 | - $set[] = $champ . "=$val"; |
|
| 1300 | - } |
|
| 1301 | - if (!empty($set)) { |
|
| 1302 | - return spip_mysql_query( |
|
| 1303 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1304 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1305 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1306 | - $serveur, $requeter); |
|
| 1307 | - } |
|
| 1297 | + $set = array(); |
|
| 1298 | + foreach ($champs as $champ => $val) { |
|
| 1299 | + $set[] = $champ . "=$val"; |
|
| 1300 | + } |
|
| 1301 | + if (!empty($set)) { |
|
| 1302 | + return spip_mysql_query( |
|
| 1303 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1304 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1305 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1306 | + $serveur, $requeter); |
|
| 1307 | + } |
|
| 1308 | 1308 | } |
| 1309 | 1309 | |
| 1310 | 1310 | /** |
@@ -1337,27 +1337,27 @@ discard block |
||
| 1337 | 1337 | */ |
| 1338 | 1338 | function spip_mysql_updateq($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1339 | 1339 | |
| 1340 | - if (!$champs) { |
|
| 1341 | - return; |
|
| 1342 | - } |
|
| 1343 | - if (!$desc) { |
|
| 1344 | - $desc = description_table($table, $serveur); |
|
| 1345 | - } |
|
| 1346 | - if (!$desc) { |
|
| 1347 | - $champs = array(); |
|
| 1348 | - } else { |
|
| 1349 | - $fields = $desc['field']; |
|
| 1350 | - } |
|
| 1351 | - $set = array(); |
|
| 1352 | - foreach ($champs as $champ => $val) { |
|
| 1353 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - return spip_mysql_query( |
|
| 1357 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1358 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1359 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1360 | - $serveur, $requeter); |
|
| 1340 | + if (!$champs) { |
|
| 1341 | + return; |
|
| 1342 | + } |
|
| 1343 | + if (!$desc) { |
|
| 1344 | + $desc = description_table($table, $serveur); |
|
| 1345 | + } |
|
| 1346 | + if (!$desc) { |
|
| 1347 | + $champs = array(); |
|
| 1348 | + } else { |
|
| 1349 | + $fields = $desc['field']; |
|
| 1350 | + } |
|
| 1351 | + $set = array(); |
|
| 1352 | + foreach ($champs as $champ => $val) { |
|
| 1353 | + $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + return spip_mysql_query( |
|
| 1357 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1358 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1359 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1360 | + $serveur, $requeter); |
|
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | 1363 | /** |
@@ -1373,20 +1373,20 @@ discard block |
||
| 1373 | 1373 | * - False en cas d'erreur. |
| 1374 | 1374 | **/ |
| 1375 | 1375 | function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 1376 | - $res = spip_mysql_query( |
|
| 1377 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1378 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1379 | - $serveur, $requeter); |
|
| 1380 | - if (!$requeter) { |
|
| 1381 | - return $res; |
|
| 1382 | - } |
|
| 1383 | - if ($res) { |
|
| 1384 | - $link = _mysql_link($serveur); |
|
| 1385 | - |
|
| 1386 | - return mysqli_affected_rows($link); |
|
| 1387 | - } else { |
|
| 1388 | - return false; |
|
| 1389 | - } |
|
| 1376 | + $res = spip_mysql_query( |
|
| 1377 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1378 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1379 | + $serveur, $requeter); |
|
| 1380 | + if (!$requeter) { |
|
| 1381 | + return $res; |
|
| 1382 | + } |
|
| 1383 | + if ($res) { |
|
| 1384 | + $link = _mysql_link($serveur); |
|
| 1385 | + |
|
| 1386 | + return mysqli_affected_rows($link); |
|
| 1387 | + } else { |
|
| 1388 | + return false; |
|
| 1389 | + } |
|
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | |
@@ -1415,8 +1415,8 @@ discard block |
||
| 1415 | 1415 | * - False en cas d'erreur. |
| 1416 | 1416 | **/ |
| 1417 | 1417 | function spip_mysql_replace($table, $couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1418 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1419 | - array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1418 | + return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1419 | + array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | 1422 | |
@@ -1445,14 +1445,14 @@ discard block |
||
| 1445 | 1445 | * - False en cas d'erreur. |
| 1446 | 1446 | **/ |
| 1447 | 1447 | function spip_mysql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1448 | - $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1449 | - $valeurs = array(); |
|
| 1450 | - foreach ($tab_couples as $couples) { |
|
| 1451 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1452 | - } |
|
| 1453 | - $valeurs = implode(', ', $valeurs); |
|
| 1454 | - |
|
| 1455 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1448 | + $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1449 | + $valeurs = array(); |
|
| 1450 | + foreach ($tab_couples as $couples) { |
|
| 1451 | + $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1452 | + } |
|
| 1453 | + $valeurs = implode(', ', $valeurs); |
|
| 1454 | + |
|
| 1455 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1456 | 1456 | } |
| 1457 | 1457 | |
| 1458 | 1458 | |
@@ -1467,32 +1467,32 @@ discard block |
||
| 1467 | 1467 | * @return string Texte de sélection pour la requête |
| 1468 | 1468 | */ |
| 1469 | 1469 | function spip_mysql_multi($objet, $lang) { |
| 1470 | - $lengthlang = strlen("[$lang]"); |
|
| 1471 | - $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1472 | - $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1473 | - $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1474 | - $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1475 | - $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1476 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1477 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1478 | - $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1479 | - $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1480 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1481 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1482 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1483 | - " TRIM(" . $objet . "), " . |
|
| 1484 | - " CONCAT( " . |
|
| 1485 | - " $debutchaine, " . |
|
| 1486 | - " IF( " . |
|
| 1487 | - " $poslang = 0, " . |
|
| 1488 | - " $chainemulti, " . |
|
| 1489 | - " $chainelang" . |
|
| 1490 | - " ), " . |
|
| 1491 | - " $finchaine" . |
|
| 1492 | - " ) " . |
|
| 1493 | - "))) AS multi"; |
|
| 1494 | - |
|
| 1495 | - return $retour; |
|
| 1470 | + $lengthlang = strlen("[$lang]"); |
|
| 1471 | + $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1472 | + $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1473 | + $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1474 | + $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1475 | + $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1476 | + $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1477 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1478 | + $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1479 | + $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1480 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1481 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1482 | + $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1483 | + " TRIM(" . $objet . "), " . |
|
| 1484 | + " CONCAT( " . |
|
| 1485 | + " $debutchaine, " . |
|
| 1486 | + " IF( " . |
|
| 1487 | + " $poslang = 0, " . |
|
| 1488 | + " $chainemulti, " . |
|
| 1489 | + " $chainelang" . |
|
| 1490 | + " ), " . |
|
| 1491 | + " $finchaine" . |
|
| 1492 | + " ) " . |
|
| 1493 | + "))) AS multi"; |
|
| 1494 | + |
|
| 1495 | + return $retour; |
|
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | /** |
@@ -1506,7 +1506,7 @@ discard block |
||
| 1506 | 1506 | * Valeur hexadécimale pour MySQL |
| 1507 | 1507 | **/ |
| 1508 | 1508 | function spip_mysql_hex($v) { |
| 1509 | - return "0x" . $v; |
|
| 1509 | + return "0x" . $v; |
|
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | 1512 | /** |
@@ -1522,15 +1522,15 @@ discard block |
||
| 1522 | 1522 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1523 | 1523 | */ |
| 1524 | 1524 | function spip_mysql_quote($v, $type = '') { |
| 1525 | - if (!is_array($v)) { |
|
| 1526 | - return spip_mysql_cite($v, $type); |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1530 | - foreach ($v as $k => $r) { |
|
| 1531 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1532 | - } |
|
| 1533 | - return implode(',', $v); |
|
| 1525 | + if (!is_array($v)) { |
|
| 1526 | + return spip_mysql_cite($v, $type); |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1530 | + foreach ($v as $k => $r) { |
|
| 1531 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1532 | + } |
|
| 1533 | + return implode(',', $v); |
|
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | 1536 | /** |
@@ -1546,18 +1546,18 @@ discard block |
||
| 1546 | 1546 | * Expression SQL |
| 1547 | 1547 | **/ |
| 1548 | 1548 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1549 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1550 | - return '(' |
|
| 1551 | - . $champ |
|
| 1552 | - . (($interval <= 0) ? '>' : '<') |
|
| 1553 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1554 | - . '(' |
|
| 1555 | - . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1556 | - . ', INTERVAL ' |
|
| 1557 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1558 | - . ' ' |
|
| 1559 | - . $unite |
|
| 1560 | - . '))'; |
|
| 1549 | + $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1550 | + return '(' |
|
| 1551 | + . $champ |
|
| 1552 | + . (($interval <= 0) ? '>' : '<') |
|
| 1553 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1554 | + . '(' |
|
| 1555 | + . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1556 | + . ', INTERVAL ' |
|
| 1557 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1558 | + . ' ' |
|
| 1559 | + . $unite |
|
| 1560 | + . '))'; |
|
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | |
@@ -1581,7 +1581,7 @@ discard block |
||
| 1581 | 1581 | * Expression de requête SQL |
| 1582 | 1582 | **/ |
| 1583 | 1583 | function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1584 | - return "($val $not IN ($valeurs))"; |
|
| 1584 | + return "($val $not IN ($valeurs))"; |
|
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | 1587 | |
@@ -1593,36 +1593,36 @@ discard block |
||
| 1593 | 1593 | * @return string|number Texte ou nombre échappé |
| 1594 | 1594 | */ |
| 1595 | 1595 | function spip_mysql_cite($v, $type) { |
| 1596 | - if (!$type) { |
|
| 1597 | - if (is_bool($v)) { |
|
| 1598 | - return strval(intval($v)); |
|
| 1599 | - } |
|
| 1600 | - elseif (is_numeric($v)) { |
|
| 1601 | - return strval($v); |
|
| 1602 | - } |
|
| 1603 | - return "'" . addslashes($v) . "'"; |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - if (is_null($v) |
|
| 1607 | - and stripos($type, "NOT NULL") === false |
|
| 1608 | - ) { |
|
| 1609 | - return 'NULL'; |
|
| 1610 | - } // null php se traduit en NULL SQL |
|
| 1611 | - if (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1612 | - return $v; |
|
| 1613 | - } |
|
| 1614 | - if (sql_test_int($type)) { |
|
| 1615 | - if (is_numeric($v) or (ctype_xdigit(substr($v, 2)) |
|
| 1616 | - and $v[0] == '0' and $v[1] == 'x') |
|
| 1617 | - ) { |
|
| 1618 | - return $v; |
|
| 1619 | - } // si pas numerique, forcer le intval |
|
| 1620 | - else { |
|
| 1621 | - return intval($v); |
|
| 1622 | - } |
|
| 1623 | - } |
|
| 1624 | - |
|
| 1625 | - return ("'" . addslashes($v) . "'"); |
|
| 1596 | + if (!$type) { |
|
| 1597 | + if (is_bool($v)) { |
|
| 1598 | + return strval(intval($v)); |
|
| 1599 | + } |
|
| 1600 | + elseif (is_numeric($v)) { |
|
| 1601 | + return strval($v); |
|
| 1602 | + } |
|
| 1603 | + return "'" . addslashes($v) . "'"; |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + if (is_null($v) |
|
| 1607 | + and stripos($type, "NOT NULL") === false |
|
| 1608 | + ) { |
|
| 1609 | + return 'NULL'; |
|
| 1610 | + } // null php se traduit en NULL SQL |
|
| 1611 | + if (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1612 | + return $v; |
|
| 1613 | + } |
|
| 1614 | + if (sql_test_int($type)) { |
|
| 1615 | + if (is_numeric($v) or (ctype_xdigit(substr($v, 2)) |
|
| 1616 | + and $v[0] == '0' and $v[1] == 'x') |
|
| 1617 | + ) { |
|
| 1618 | + return $v; |
|
| 1619 | + } // si pas numerique, forcer le intval |
|
| 1620 | + else { |
|
| 1621 | + return intval($v); |
|
| 1622 | + } |
|
| 1623 | + } |
|
| 1624 | + |
|
| 1625 | + return ("'" . addslashes($v) . "'"); |
|
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | |
@@ -1646,21 +1646,21 @@ discard block |
||
| 1646 | 1646 | */ |
| 1647 | 1647 | function spip_get_lock($nom, $timeout = 0) { |
| 1648 | 1648 | |
| 1649 | - define('_LOCK_TIME', intval(time() / 3600 - 316982)); |
|
| 1649 | + define('_LOCK_TIME', intval(time() / 3600 - 316982)); |
|
| 1650 | 1650 | |
| 1651 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1652 | - $bd = $connexion['db']; |
|
| 1653 | - $prefixe = $connexion['prefixe']; |
|
| 1654 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1651 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1652 | + $bd = $connexion['db']; |
|
| 1653 | + $prefixe = $connexion['prefixe']; |
|
| 1654 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1655 | 1655 | |
| 1656 | - $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1656 | + $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1657 | 1657 | |
| 1658 | - $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
|
| 1659 | - if (!$q) { |
|
| 1660 | - spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1661 | - } |
|
| 1658 | + $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
|
| 1659 | + if (!$q) { |
|
| 1660 | + spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1661 | + } |
|
| 1662 | 1662 | |
| 1663 | - return $q['n']; |
|
| 1663 | + return $q['n']; |
|
| 1664 | 1664 | } |
| 1665 | 1665 | |
| 1666 | 1666 | |
@@ -1677,13 +1677,13 @@ discard block |
||
| 1677 | 1677 | */ |
| 1678 | 1678 | function spip_release_lock($nom) { |
| 1679 | 1679 | |
| 1680 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1681 | - $bd = $connexion['db']; |
|
| 1682 | - $prefixe = $connexion['prefixe']; |
|
| 1683 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1680 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1681 | + $bd = $connexion['db']; |
|
| 1682 | + $prefixe = $connexion['prefixe']; |
|
| 1683 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1684 | 1684 | |
| 1685 | - $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1686 | - mysqli_query(_mysql_link(), $q); |
|
| 1685 | + $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1686 | + mysqli_query(_mysql_link(), $q); |
|
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | 1689 | |
@@ -1694,7 +1694,7 @@ discard block |
||
| 1694 | 1694 | * True si on a les fonctions, false sinon |
| 1695 | 1695 | */ |
| 1696 | 1696 | function spip_versions_mysql() { |
| 1697 | - return function_exists('mysqli_query'); |
|
| 1697 | + return function_exists('mysqli_query'); |
|
| 1698 | 1698 | } |
| 1699 | 1699 | |
| 1700 | 1700 | |
@@ -1707,20 +1707,20 @@ discard block |
||
| 1707 | 1707 | * - chaîne : code compilé pour le faire désactiver par SPIP sinon |
| 1708 | 1708 | */ |
| 1709 | 1709 | function test_rappel_nom_base_mysql($server_db) { |
| 1710 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1711 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1712 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1710 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1711 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1712 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1713 | 1713 | |
| 1714 | - if ($ok) { |
|
| 1715 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1714 | + if ($ok) { |
|
| 1715 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1716 | 1716 | |
| 1717 | - return ''; |
|
| 1718 | - } else { |
|
| 1719 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1717 | + return ''; |
|
| 1718 | + } else { |
|
| 1719 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1720 | 1720 | |
| 1721 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1722 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1723 | - } |
|
| 1721 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1722 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1723 | + } |
|
| 1724 | 1724 | } |
| 1725 | 1725 | |
| 1726 | 1726 | /** |
@@ -1734,13 +1734,13 @@ discard block |
||
| 1734 | 1734 | * - chaîne : code compilé pour l'indiquer le résultat du test à SPIP |
| 1735 | 1735 | */ |
| 1736 | 1736 | function test_sql_mode_mysql($server_db) { |
| 1737 | - $res = sql_select("version() as v", '', '', '', '', '', '', $server_db); |
|
| 1738 | - $row = sql_fetch($res, $server_db); |
|
| 1739 | - if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1740 | - defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1737 | + $res = sql_select("version() as v", '', '', '', '', '', '', $server_db); |
|
| 1738 | + $row = sql_fetch($res, $server_db); |
|
| 1739 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1740 | + defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1741 | 1741 | |
| 1742 | - return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1743 | - } |
|
| 1742 | + return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1743 | + } |
|
| 1744 | 1744 | |
| 1745 | - return ''; |
|
| 1745 | + return ''; |
|
| 1746 | 1746 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -37,43 +37,43 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function action_editer_auteur_dist($arg = null) { |
| 39 | 39 | |
| 40 | - if (is_null($arg)) { |
|
| 41 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | - $arg = $securiser_action(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | - if (!$id_auteur = intval($arg)) { |
|
| 48 | - |
|
| 49 | - if (($id_auteur = auteur_inserer()) > 0) { |
|
| 50 | - |
|
| 51 | - # cf. GROS HACK |
|
| 52 | - # recuperer l'eventuel logo charge avant la creation |
|
| 53 | - # ils ont un id = 0-id_auteur de la session |
|
| 54 | - $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 55 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 56 | - foreach (array('on', 'off') as $type) { |
|
| 57 | - if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 58 | - if ($logo = reset($logo)) { |
|
| 59 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // Enregistre l'envoi dans la BD |
|
| 67 | - $err = ""; |
|
| 68 | - if ($id_auteur > 0) { |
|
| 69 | - $err = auteur_modifier($id_auteur); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - if ($err) { |
|
| 73 | - spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - return array($id_auteur, $err); |
|
| 40 | + if (is_null($arg)) { |
|
| 41 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 42 | + $arg = $securiser_action(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + // si id_auteur n'est pas un nombre, c'est une creation |
|
| 47 | + if (!$id_auteur = intval($arg)) { |
|
| 48 | + |
|
| 49 | + if (($id_auteur = auteur_inserer()) > 0) { |
|
| 50 | + |
|
| 51 | + # cf. GROS HACK |
|
| 52 | + # recuperer l'eventuel logo charge avant la creation |
|
| 53 | + # ils ont un id = 0-id_auteur de la session |
|
| 54 | + $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 55 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 56 | + foreach (array('on', 'off') as $type) { |
|
| 57 | + if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 58 | + if ($logo = reset($logo)) { |
|
| 59 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // Enregistre l'envoi dans la BD |
|
| 67 | + $err = ""; |
|
| 68 | + if ($id_auteur > 0) { |
|
| 69 | + $err = auteur_modifier($id_auteur); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + if ($err) { |
|
| 73 | + spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + return array($id_auteur, $err); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -90,42 +90,42 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | function auteur_inserer($source = null, $set = null) { |
| 92 | 92 | |
| 93 | - // Ce qu'on va demander comme modifications |
|
| 94 | - $champs = array(); |
|
| 95 | - $champs['source'] = $source ? $source : 'spip'; |
|
| 96 | - |
|
| 97 | - $champs['login'] = ''; |
|
| 98 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 99 | - $champs['webmestre'] = 'non'; |
|
| 100 | - if (empty($champs['imessage'])) { |
|
| 101 | - $champs['imessage'] = 'oui'; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if ($set) { |
|
| 105 | - $champs = array_merge($champs, $set); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // Envoyer aux plugins |
|
| 109 | - $champs = pipeline('pre_insertion', |
|
| 110 | - array( |
|
| 111 | - 'args' => array( |
|
| 112 | - 'table' => 'spip_auteurs', |
|
| 113 | - ), |
|
| 114 | - 'data' => $champs |
|
| 115 | - ) |
|
| 116 | - ); |
|
| 117 | - $id_auteur = sql_insertq("spip_auteurs", $champs); |
|
| 118 | - pipeline('post_insertion', |
|
| 119 | - array( |
|
| 120 | - 'args' => array( |
|
| 121 | - 'table' => 'spip_auteurs', |
|
| 122 | - 'id_objet' => $id_auteur |
|
| 123 | - ), |
|
| 124 | - 'data' => $champs |
|
| 125 | - ) |
|
| 126 | - ); |
|
| 127 | - |
|
| 128 | - return $id_auteur; |
|
| 93 | + // Ce qu'on va demander comme modifications |
|
| 94 | + $champs = array(); |
|
| 95 | + $champs['source'] = $source ? $source : 'spip'; |
|
| 96 | + |
|
| 97 | + $champs['login'] = ''; |
|
| 98 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 99 | + $champs['webmestre'] = 'non'; |
|
| 100 | + if (empty($champs['imessage'])) { |
|
| 101 | + $champs['imessage'] = 'oui'; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if ($set) { |
|
| 105 | + $champs = array_merge($champs, $set); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // Envoyer aux plugins |
|
| 109 | + $champs = pipeline('pre_insertion', |
|
| 110 | + array( |
|
| 111 | + 'args' => array( |
|
| 112 | + 'table' => 'spip_auteurs', |
|
| 113 | + ), |
|
| 114 | + 'data' => $champs |
|
| 115 | + ) |
|
| 116 | + ); |
|
| 117 | + $id_auteur = sql_insertq("spip_auteurs", $champs); |
|
| 118 | + pipeline('post_insertion', |
|
| 119 | + array( |
|
| 120 | + 'args' => array( |
|
| 121 | + 'table' => 'spip_auteurs', |
|
| 122 | + 'id_objet' => $id_auteur |
|
| 123 | + ), |
|
| 124 | + 'data' => $champs |
|
| 125 | + ) |
|
| 126 | + ); |
|
| 127 | + |
|
| 128 | + return $id_auteur; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | |
@@ -150,66 +150,66 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
| 152 | 152 | |
| 153 | - include_spip('inc/modifier'); |
|
| 154 | - include_spip('inc/filtres'); |
|
| 155 | - $c = collecter_requests( |
|
| 156 | - // white list |
|
| 157 | - objet_info('auteur', 'champs_editables'), |
|
| 158 | - // black list |
|
| 159 | - $force_update ? array() : array('webmestre', 'pass', 'login'), |
|
| 160 | - // donnees eventuellement fournies |
|
| 161 | - $set |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - if ($err = objet_modifier_champs('auteur', $id_auteur, |
|
| 165 | - array( |
|
| 166 | - 'data' => $set, |
|
| 167 | - 'nonvide' => array('nom' => _T('ecrire:item_nouvel_auteur')) |
|
| 168 | - ), |
|
| 169 | - $c) |
|
| 170 | - ) { |
|
| 171 | - return $err; |
|
| 172 | - } |
|
| 173 | - $session = $c; |
|
| 174 | - |
|
| 175 | - $err = ''; |
|
| 176 | - if (!$force_update) { |
|
| 177 | - // Modification de statut, changement de rubrique ? |
|
| 178 | - $c = collecter_requests( |
|
| 179 | - // white list |
|
| 180 | - array( |
|
| 181 | - 'statut', |
|
| 182 | - 'new_login', |
|
| 183 | - 'new_pass', |
|
| 184 | - 'login', |
|
| 185 | - 'pass', |
|
| 186 | - 'webmestre', |
|
| 187 | - 'restreintes', |
|
| 188 | - 'id_parent' |
|
| 189 | - ), |
|
| 190 | - // black list |
|
| 191 | - array(), |
|
| 192 | - // donnees eventuellement fournies |
|
| 193 | - $set |
|
| 194 | - ); |
|
| 195 | - if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 196 | - $c['login'] = $c['new_login']; |
|
| 197 | - } |
|
| 198 | - if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 199 | - $c['pass'] = $c['new_pass']; |
|
| 200 | - } |
|
| 201 | - $err = auteur_instituer($id_auteur, $c); |
|
| 202 | - $session = array_merge($session, $c); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // .. mettre a jour les sessions de cet auteur |
|
| 206 | - include_spip('inc/session'); |
|
| 207 | - $session['id_auteur'] = $id_auteur; |
|
| 208 | - unset($session['new_login']); |
|
| 209 | - unset($session['new_pass']); |
|
| 210 | - actualiser_sessions($session); |
|
| 211 | - |
|
| 212 | - return $err; |
|
| 153 | + include_spip('inc/modifier'); |
|
| 154 | + include_spip('inc/filtres'); |
|
| 155 | + $c = collecter_requests( |
|
| 156 | + // white list |
|
| 157 | + objet_info('auteur', 'champs_editables'), |
|
| 158 | + // black list |
|
| 159 | + $force_update ? array() : array('webmestre', 'pass', 'login'), |
|
| 160 | + // donnees eventuellement fournies |
|
| 161 | + $set |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + if ($err = objet_modifier_champs('auteur', $id_auteur, |
|
| 165 | + array( |
|
| 166 | + 'data' => $set, |
|
| 167 | + 'nonvide' => array('nom' => _T('ecrire:item_nouvel_auteur')) |
|
| 168 | + ), |
|
| 169 | + $c) |
|
| 170 | + ) { |
|
| 171 | + return $err; |
|
| 172 | + } |
|
| 173 | + $session = $c; |
|
| 174 | + |
|
| 175 | + $err = ''; |
|
| 176 | + if (!$force_update) { |
|
| 177 | + // Modification de statut, changement de rubrique ? |
|
| 178 | + $c = collecter_requests( |
|
| 179 | + // white list |
|
| 180 | + array( |
|
| 181 | + 'statut', |
|
| 182 | + 'new_login', |
|
| 183 | + 'new_pass', |
|
| 184 | + 'login', |
|
| 185 | + 'pass', |
|
| 186 | + 'webmestre', |
|
| 187 | + 'restreintes', |
|
| 188 | + 'id_parent' |
|
| 189 | + ), |
|
| 190 | + // black list |
|
| 191 | + array(), |
|
| 192 | + // donnees eventuellement fournies |
|
| 193 | + $set |
|
| 194 | + ); |
|
| 195 | + if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 196 | + $c['login'] = $c['new_login']; |
|
| 197 | + } |
|
| 198 | + if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 199 | + $c['pass'] = $c['new_pass']; |
|
| 200 | + } |
|
| 201 | + $err = auteur_instituer($id_auteur, $c); |
|
| 202 | + $session = array_merge($session, $c); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // .. mettre a jour les sessions de cet auteur |
|
| 206 | + include_spip('inc/session'); |
|
| 207 | + $session['id_auteur'] = $id_auteur; |
|
| 208 | + unset($session['new_login']); |
|
| 209 | + unset($session['new_pass']); |
|
| 210 | + actualiser_sessions($session); |
|
| 211 | + |
|
| 212 | + return $err; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | * @return string |
| 231 | 231 | */ |
| 232 | 232 | function auteur_associer($id_auteur, $objets, $qualif = null) { |
| 233 | - include_spip('action/editer_liens'); |
|
| 233 | + include_spip('action/editer_liens'); |
|
| 234 | 234 | |
| 235 | - return objet_associer(array('auteur' => $id_auteur), $objets, $qualif); |
|
| 235 | + return objet_associer(array('auteur' => $id_auteur), $objets, $qualif); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | * @return string |
| 252 | 252 | */ |
| 253 | 253 | function auteur_dissocier($id_auteur, $objets) { |
| 254 | - include_spip('action/editer_liens'); |
|
| 254 | + include_spip('action/editer_liens'); |
|
| 255 | 255 | |
| 256 | - return objet_dissocier(array('auteur' => $id_auteur), $objets); |
|
| 256 | + return objet_dissocier(array('auteur' => $id_auteur), $objets); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -274,9 +274,9 @@ discard block |
||
| 274 | 274 | * @return bool|int |
| 275 | 275 | */ |
| 276 | 276 | function auteur_qualifier($id_auteur, $objets, $qualif) { |
| 277 | - include_spip('action/editer_liens'); |
|
| 277 | + include_spip('action/editer_liens'); |
|
| 278 | 278 | |
| 279 | - return objet_qualifier_liens(array('auteur' => $id_auteur), $objets, $qualif); |
|
| 279 | + return objet_qualifier_liens(array('auteur' => $id_auteur), $objets, $qualif); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | |
@@ -295,132 +295,132 @@ discard block |
||
| 295 | 295 | * @return bool|string |
| 296 | 296 | */ |
| 297 | 297 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 298 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 299 | - return false; |
|
| 300 | - } |
|
| 301 | - $erreurs = array(); // contiendra les differentes erreurs a traduire par _T() |
|
| 302 | - $champs = array(); |
|
| 303 | - |
|
| 304 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 305 | - if (isset($c['login']) and strlen($c['login'])) { |
|
| 306 | - $champs['login'] = $c['login']; |
|
| 307 | - } |
|
| 308 | - if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 309 | - $champs['pass'] = $c['pass']; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 313 | - |
|
| 314 | - if (isset($c['statut']) |
|
| 315 | - and (autoriser('modifier', 'auteur', $id_auteur, null, array('statut' => $c['statut']))) |
|
| 316 | - ) { |
|
| 317 | - $statut = $champs['statut'] = $c['statut']; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - // Restreindre avant de declarer l'auteur |
|
| 321 | - // (section critique sur les droits) |
|
| 322 | - if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 323 | - if (is_array($c['restreintes'])) { |
|
| 324 | - $c['restreintes'][] = $c['id_parent']; |
|
| 325 | - } else { |
|
| 326 | - $c['restreintes'] = array($c['id_parent']); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - if (isset($c['webmestre']) |
|
| 331 | - and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, array('webmestre' => '?'))) |
|
| 332 | - ) { |
|
| 333 | - $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 337 | - if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 338 | - $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // Envoyer aux plugins |
|
| 342 | - $champs = pipeline('pre_edition', |
|
| 343 | - array( |
|
| 344 | - 'args' => array( |
|
| 345 | - 'table' => 'spip_auteurs', |
|
| 346 | - 'id_objet' => $id_auteur, |
|
| 347 | - 'action' => 'instituer', |
|
| 348 | - 'statut_ancien' => $statut_ancien, |
|
| 349 | - ), |
|
| 350 | - 'data' => $champs |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - |
|
| 354 | - if (isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 355 | - and autoriser('modifier', 'auteur', $id_auteur, null, array('restreint' => $c['restreintes'])) |
|
| 356 | - ) { |
|
| 357 | - $rubriques = array_map('intval', $c['restreintes']); |
|
| 358 | - $rubriques = array_unique($rubriques); |
|
| 359 | - $rubriques = array_diff($rubriques, array(0)); |
|
| 360 | - auteur_dissocier($id_auteur, array('rubrique' => '*')); |
|
| 361 | - auteur_associer($id_auteur, array('rubrique' => $rubriques)); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $flag_ecrire_acces = false; |
|
| 365 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 366 | - // avant les autres ecritures en base |
|
| 367 | - if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 368 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 369 | - include_spip('inc/auth'); |
|
| 370 | - if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 371 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 372 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 376 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 378 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - unset($champs['login']); |
|
| 382 | - unset($champs['pass']); |
|
| 383 | - $flag_ecrire_acces = true; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - if (!count($champs)) { |
|
| 387 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 388 | - } |
|
| 389 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 390 | - |
|
| 391 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 392 | - if ($flag_ecrire_acces |
|
| 393 | - or isset($champs['statut']) |
|
| 394 | - ) { |
|
| 395 | - include_spip('inc/acces'); |
|
| 396 | - ecrire_acces(); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - // Invalider les caches |
|
| 400 | - include_spip('inc/invalideur'); |
|
| 401 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 402 | - |
|
| 403 | - // Pipeline |
|
| 404 | - pipeline('post_edition', |
|
| 405 | - array( |
|
| 406 | - 'args' => array( |
|
| 407 | - 'table' => 'spip_auteurs', |
|
| 408 | - 'id_objet' => $id_auteur, |
|
| 409 | - 'action' => 'instituer', |
|
| 410 | - 'statut_ancien' => $statut_ancien, |
|
| 411 | - ), |
|
| 412 | - 'data' => $champs |
|
| 413 | - ) |
|
| 414 | - ); |
|
| 415 | - |
|
| 416 | - |
|
| 417 | - // Notifications |
|
| 418 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 419 | - $notifications('instituerauteur', $id_auteur, |
|
| 420 | - array('statut' => $statut, 'statut_ancien' => $statut_ancien) |
|
| 421 | - ); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 298 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 299 | + return false; |
|
| 300 | + } |
|
| 301 | + $erreurs = array(); // contiendra les differentes erreurs a traduire par _T() |
|
| 302 | + $champs = array(); |
|
| 303 | + |
|
| 304 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 305 | + if (isset($c['login']) and strlen($c['login'])) { |
|
| 306 | + $champs['login'] = $c['login']; |
|
| 307 | + } |
|
| 308 | + if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 309 | + $champs['pass'] = $c['pass']; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 313 | + |
|
| 314 | + if (isset($c['statut']) |
|
| 315 | + and (autoriser('modifier', 'auteur', $id_auteur, null, array('statut' => $c['statut']))) |
|
| 316 | + ) { |
|
| 317 | + $statut = $champs['statut'] = $c['statut']; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + // Restreindre avant de declarer l'auteur |
|
| 321 | + // (section critique sur les droits) |
|
| 322 | + if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 323 | + if (is_array($c['restreintes'])) { |
|
| 324 | + $c['restreintes'][] = $c['id_parent']; |
|
| 325 | + } else { |
|
| 326 | + $c['restreintes'] = array($c['id_parent']); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + if (isset($c['webmestre']) |
|
| 331 | + and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, array('webmestre' => '?'))) |
|
| 332 | + ) { |
|
| 333 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 337 | + if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 338 | + $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // Envoyer aux plugins |
|
| 342 | + $champs = pipeline('pre_edition', |
|
| 343 | + array( |
|
| 344 | + 'args' => array( |
|
| 345 | + 'table' => 'spip_auteurs', |
|
| 346 | + 'id_objet' => $id_auteur, |
|
| 347 | + 'action' => 'instituer', |
|
| 348 | + 'statut_ancien' => $statut_ancien, |
|
| 349 | + ), |
|
| 350 | + 'data' => $champs |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + |
|
| 354 | + if (isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 355 | + and autoriser('modifier', 'auteur', $id_auteur, null, array('restreint' => $c['restreintes'])) |
|
| 356 | + ) { |
|
| 357 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 358 | + $rubriques = array_unique($rubriques); |
|
| 359 | + $rubriques = array_diff($rubriques, array(0)); |
|
| 360 | + auteur_dissocier($id_auteur, array('rubrique' => '*')); |
|
| 361 | + auteur_associer($id_auteur, array('rubrique' => $rubriques)); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $flag_ecrire_acces = false; |
|
| 365 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 366 | + // avant les autres ecritures en base |
|
| 367 | + if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 368 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 369 | + include_spip('inc/auth'); |
|
| 370 | + if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 371 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 372 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 376 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 377 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 378 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + unset($champs['login']); |
|
| 382 | + unset($champs['pass']); |
|
| 383 | + $flag_ecrire_acces = true; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + if (!count($champs)) { |
|
| 387 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 388 | + } |
|
| 389 | + sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 390 | + |
|
| 391 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 392 | + if ($flag_ecrire_acces |
|
| 393 | + or isset($champs['statut']) |
|
| 394 | + ) { |
|
| 395 | + include_spip('inc/acces'); |
|
| 396 | + ecrire_acces(); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + // Invalider les caches |
|
| 400 | + include_spip('inc/invalideur'); |
|
| 401 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 402 | + |
|
| 403 | + // Pipeline |
|
| 404 | + pipeline('post_edition', |
|
| 405 | + array( |
|
| 406 | + 'args' => array( |
|
| 407 | + 'table' => 'spip_auteurs', |
|
| 408 | + 'id_objet' => $id_auteur, |
|
| 409 | + 'action' => 'instituer', |
|
| 410 | + 'statut_ancien' => $statut_ancien, |
|
| 411 | + ), |
|
| 412 | + 'data' => $champs |
|
| 413 | + ) |
|
| 414 | + ); |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + // Notifications |
|
| 418 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 419 | + $notifications('instituerauteur', $id_auteur, |
|
| 420 | + array('statut' => $statut, 'statut_ancien' => $statut_ancien) |
|
| 421 | + ); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 425 | 425 | |
| 426 | 426 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | require_once _ROOT_RESTREINT . 'base/objets.php'; |
| 22 | 22 | |
@@ -42,118 +42,118 @@ discard block |
||
| 42 | 42 | **/ |
| 43 | 43 | function spip_connect($serveur = '', $version = '') { |
| 44 | 44 | |
| 45 | - $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | - $index = $serveur ? $serveur : 0; |
|
| 47 | - if (!$version) { |
|
| 48 | - $version = $GLOBALS['spip_sql_version']; |
|
| 49 | - } |
|
| 50 | - if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | - return $GLOBALS['connexions'][$index]; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - include_spip('base/abstract_sql'); |
|
| 55 | - $install = (_request('exec') == 'install'); |
|
| 56 | - |
|
| 57 | - // Premiere connexion ? |
|
| 58 | - if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | - $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | - ? '' // nom de serveur mal ecrit |
|
| 61 | - : ($serveur ? |
|
| 62 | - (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | - : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
|
| 64 | - : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 65 | - : ''))); // installation pas faite |
|
| 66 | - |
|
| 67 | - unset($GLOBALS['db_ok']); |
|
| 68 | - unset($GLOBALS['spip_connect_version']); |
|
| 69 | - if ($f) { |
|
| 70 | - if (is_readable($f)) { |
|
| 71 | - include($f); |
|
| 72 | - } elseif ($serveur and !$install) { |
|
| 73 | - // chercher une declaration de serveur dans le path |
|
| 74 | - // qui pourra un jour servir a declarer des bases sqlite |
|
| 75 | - // par des plugins. Et sert aussi aux boucles POUR. |
|
| 76 | - find_in_path("$serveur.php", 'connect/', true); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 80 | - // fera mieux la prochaine fois |
|
| 81 | - if ($install) { |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 84 | - if ($f and is_readable($f)) { |
|
| 85 | - spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 86 | - } else { |
|
| 87 | - spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 88 | - } |
|
| 89 | - spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 90 | - |
|
| 91 | - // ne plus reessayer si ce n'est pas l'install |
|
| 92 | - return $GLOBALS['connexions'][$index] = false; |
|
| 93 | - } |
|
| 94 | - $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 95 | - } |
|
| 96 | - // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 97 | - if (!$GLOBALS['connexions'][$index]) { |
|
| 98 | - return false; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // la connexion a reussi ou etait deja faite. |
|
| 102 | - // chargement de la version du jeu de fonctions |
|
| 103 | - // si pas dans le fichier par defaut |
|
| 104 | - $type = $GLOBALS['db_ok']['type']; |
|
| 105 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 106 | - if (!isset($GLOBALS[$jeu])) { |
|
| 107 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 108 | - spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 109 | - |
|
| 110 | - // ne plus reessayer |
|
| 111 | - return $GLOBALS['connexions'][$index][$version] = array(); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 115 | - if ($old) { |
|
| 116 | - return $GLOBALS['connexions'][$index]; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0; |
|
| 120 | - |
|
| 121 | - // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 122 | - // si l'installation l'a determine. |
|
| 123 | - // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 124 | - // s'ils le connaissent |
|
| 125 | - |
|
| 126 | - if (!$serveur) { |
|
| 127 | - $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 128 | - if (!$charset) { |
|
| 129 | - unset($GLOBALS['connexions'][$index]); |
|
| 130 | - spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT); |
|
| 131 | - |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 134 | - } else { |
|
| 135 | - if ($GLOBALS['db_ok']['charset']) { |
|
| 136 | - $charset = $GLOBALS['db_ok']['charset']; |
|
| 137 | - } |
|
| 138 | - // spip_meta n'existe pas toujours dans la base |
|
| 139 | - // C'est le cas d'un dump sqlite par exemple |
|
| 140 | - elseif ($GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | - and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | - and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | - ) { |
|
| 144 | - $charset = $r; |
|
| 145 | - } else { |
|
| 146 | - $charset = -1; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - if ($charset != -1) { |
|
| 150 | - $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | - if (function_exists($f)) { |
|
| 152 | - $f($charset, $serveur); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $GLOBALS['connexions'][$index]; |
|
| 45 | + $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | + $index = $serveur ? $serveur : 0; |
|
| 47 | + if (!$version) { |
|
| 48 | + $version = $GLOBALS['spip_sql_version']; |
|
| 49 | + } |
|
| 50 | + if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | + return $GLOBALS['connexions'][$index]; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + include_spip('base/abstract_sql'); |
|
| 55 | + $install = (_request('exec') == 'install'); |
|
| 56 | + |
|
| 57 | + // Premiere connexion ? |
|
| 58 | + if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | + $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | + ? '' // nom de serveur mal ecrit |
|
| 61 | + : ($serveur ? |
|
| 62 | + (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | + : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
|
| 64 | + : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 65 | + : ''))); // installation pas faite |
|
| 66 | + |
|
| 67 | + unset($GLOBALS['db_ok']); |
|
| 68 | + unset($GLOBALS['spip_connect_version']); |
|
| 69 | + if ($f) { |
|
| 70 | + if (is_readable($f)) { |
|
| 71 | + include($f); |
|
| 72 | + } elseif ($serveur and !$install) { |
|
| 73 | + // chercher une declaration de serveur dans le path |
|
| 74 | + // qui pourra un jour servir a declarer des bases sqlite |
|
| 75 | + // par des plugins. Et sert aussi aux boucles POUR. |
|
| 76 | + find_in_path("$serveur.php", 'connect/', true); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 80 | + // fera mieux la prochaine fois |
|
| 81 | + if ($install) { |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | + if ($f and is_readable($f)) { |
|
| 85 | + spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 86 | + } else { |
|
| 87 | + spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 88 | + } |
|
| 89 | + spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 90 | + |
|
| 91 | + // ne plus reessayer si ce n'est pas l'install |
|
| 92 | + return $GLOBALS['connexions'][$index] = false; |
|
| 93 | + } |
|
| 94 | + $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 95 | + } |
|
| 96 | + // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 97 | + if (!$GLOBALS['connexions'][$index]) { |
|
| 98 | + return false; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // la connexion a reussi ou etait deja faite. |
|
| 102 | + // chargement de la version du jeu de fonctions |
|
| 103 | + // si pas dans le fichier par defaut |
|
| 104 | + $type = $GLOBALS['db_ok']['type']; |
|
| 105 | + $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 106 | + if (!isset($GLOBALS[$jeu])) { |
|
| 107 | + if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 108 | + spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 109 | + |
|
| 110 | + // ne plus reessayer |
|
| 111 | + return $GLOBALS['connexions'][$index][$version] = array(); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 115 | + if ($old) { |
|
| 116 | + return $GLOBALS['connexions'][$index]; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0; |
|
| 120 | + |
|
| 121 | + // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 122 | + // si l'installation l'a determine. |
|
| 123 | + // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 124 | + // s'ils le connaissent |
|
| 125 | + |
|
| 126 | + if (!$serveur) { |
|
| 127 | + $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 128 | + if (!$charset) { |
|
| 129 | + unset($GLOBALS['connexions'][$index]); |
|
| 130 | + spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT); |
|
| 131 | + |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + } else { |
|
| 135 | + if ($GLOBALS['db_ok']['charset']) { |
|
| 136 | + $charset = $GLOBALS['db_ok']['charset']; |
|
| 137 | + } |
|
| 138 | + // spip_meta n'existe pas toujours dans la base |
|
| 139 | + // C'est le cas d'un dump sqlite par exemple |
|
| 140 | + elseif ($GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | + and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | + and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | + ) { |
|
| 144 | + $charset = $r; |
|
| 145 | + } else { |
|
| 146 | + $charset = -1; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + if ($charset != -1) { |
|
| 150 | + $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | + if (function_exists($f)) { |
|
| 152 | + $f($charset, $serveur); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $GLOBALS['connexions'][$index]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | * @param string $serveur Nom du connecteur de bdd utilisé |
| 163 | 163 | **/ |
| 164 | 164 | function spip_sql_erreur($serveur = '') { |
| 165 | - $connexion = spip_connect($serveur); |
|
| 166 | - $e = sql_errno($serveur); |
|
| 167 | - $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
|
| 168 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | - $f = $t . $serveur; |
|
| 170 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 165 | + $connexion = spip_connect($serveur); |
|
| 166 | + $e = sql_errno($serveur); |
|
| 167 | + $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
|
| 168 | + $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | + $f = $t . $serveur; |
|
| 170 | + spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -189,19 +189,19 @@ discard block |
||
| 189 | 189 | * - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion |
| 190 | 190 | **/ |
| 191 | 191 | function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) { |
| 192 | - $desc = spip_connect($serveur, $version); |
|
| 193 | - if (function_exists($f = @$desc[$version][$ins])) { |
|
| 194 | - return $f; |
|
| 195 | - } |
|
| 196 | - if ($continue) { |
|
| 197 | - return $desc; |
|
| 198 | - } |
|
| 199 | - if ($ins) { |
|
| 200 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 201 | - } |
|
| 202 | - include_spip('inc/minipres'); |
|
| 203 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503)); |
|
| 204 | - exit; |
|
| 192 | + $desc = spip_connect($serveur, $version); |
|
| 193 | + if (function_exists($f = @$desc[$version][$ins])) { |
|
| 194 | + return $f; |
|
| 195 | + } |
|
| 196 | + if ($continue) { |
|
| 197 | + return $desc; |
|
| 198 | + } |
|
| 199 | + if ($ins) { |
|
| 200 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 201 | + } |
|
| 202 | + include_spip('inc/minipres'); |
|
| 203 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503)); |
|
| 204 | + exit; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -227,70 +227,70 @@ discard block |
||
| 227 | 227 | * @return array Description de la connexion |
| 228 | 228 | */ |
| 229 | 229 | function spip_connect_db( |
| 230 | - $host, |
|
| 231 | - $port, |
|
| 232 | - $login, |
|
| 233 | - $pass, |
|
| 234 | - $db = '', |
|
| 235 | - $type = 'mysql', |
|
| 236 | - $prefixe = '', |
|
| 237 | - $auth = '', |
|
| 238 | - $charset = '' |
|
| 230 | + $host, |
|
| 231 | + $port, |
|
| 232 | + $login, |
|
| 233 | + $pass, |
|
| 234 | + $db = '', |
|
| 235 | + $type = 'mysql', |
|
| 236 | + $prefixe = '', |
|
| 237 | + $auth = '', |
|
| 238 | + $charset = '' |
|
| 239 | 239 | ) { |
| 240 | - // temps avant nouvelle tentative de connexion |
|
| 241 | - // suite a une connection echouee |
|
| 242 | - if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 243 | - define('_CONNECT_RETRY_DELAY', 30); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $f = ""; |
|
| 247 | - // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 248 | - // pour ne pas declarer tout indisponible d'un coup |
|
| 249 | - // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 250 | - // car c'est un test de connexion |
|
| 251 | - if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") { |
|
| 252 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 253 | - } elseif ($db == '@test@') { |
|
| 254 | - $db = ''; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ($f |
|
| 258 | - and @file_exists($f) |
|
| 259 | - and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 260 | - ) { |
|
| 261 | - spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 262 | - |
|
| 263 | - return; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - if (!$prefixe) { |
|
| 267 | - $prefixe = isset($GLOBALS['table_prefix']) |
|
| 268 | - ? $GLOBALS['table_prefix'] : $db; |
|
| 269 | - } |
|
| 270 | - $h = charger_fonction($type, 'req', true); |
|
| 271 | - if (!$h) { |
|
| 272 | - spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 273 | - |
|
| 274 | - return; |
|
| 275 | - } |
|
| 276 | - if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 277 | - |
|
| 278 | - if (!is_array($auth)) { |
|
| 279 | - // compatibilite version 0.7 initiale |
|
| 280 | - $g['ldap'] = $auth; |
|
| 281 | - $auth = array('ldap' => $auth); |
|
| 282 | - } |
|
| 283 | - $g['authentification'] = $auth; |
|
| 284 | - $g['type'] = $type; |
|
| 285 | - $g['charset'] = $charset; |
|
| 286 | - |
|
| 287 | - return $GLOBALS['db_ok'] = $g; |
|
| 288 | - } |
|
| 289 | - // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 290 | - if ($f) { |
|
| 291 | - @touch($f); |
|
| 292 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 293 | - } |
|
| 240 | + // temps avant nouvelle tentative de connexion |
|
| 241 | + // suite a une connection echouee |
|
| 242 | + if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 243 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $f = ""; |
|
| 247 | + // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 248 | + // pour ne pas declarer tout indisponible d'un coup |
|
| 249 | + // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 250 | + // car c'est un test de connexion |
|
| 251 | + if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") { |
|
| 252 | + $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 253 | + } elseif ($db == '@test@') { |
|
| 254 | + $db = ''; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ($f |
|
| 258 | + and @file_exists($f) |
|
| 259 | + and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 260 | + ) { |
|
| 261 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 262 | + |
|
| 263 | + return; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + if (!$prefixe) { |
|
| 267 | + $prefixe = isset($GLOBALS['table_prefix']) |
|
| 268 | + ? $GLOBALS['table_prefix'] : $db; |
|
| 269 | + } |
|
| 270 | + $h = charger_fonction($type, 'req', true); |
|
| 271 | + if (!$h) { |
|
| 272 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 273 | + |
|
| 274 | + return; |
|
| 275 | + } |
|
| 276 | + if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 277 | + |
|
| 278 | + if (!is_array($auth)) { |
|
| 279 | + // compatibilite version 0.7 initiale |
|
| 280 | + $g['ldap'] = $auth; |
|
| 281 | + $auth = array('ldap' => $auth); |
|
| 282 | + } |
|
| 283 | + $g['authentification'] = $auth; |
|
| 284 | + $g['type'] = $type; |
|
| 285 | + $g['charset'] = $charset; |
|
| 286 | + |
|
| 287 | + return $GLOBALS['db_ok'] = $g; |
|
| 288 | + } |
|
| 289 | + // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 290 | + if ($f) { |
|
| 291 | + @touch($f); |
|
| 292 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 293 | + } |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -322,31 +322,31 @@ discard block |
||
| 322 | 322 | * - nom du charset sinon |
| 323 | 323 | **/ |
| 324 | 324 | function spip_connect_main($connexion, $charset_sql_connexion = '') { |
| 325 | - if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 326 | - include_spip('inc/headers'); |
|
| 327 | - redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - if (!($f = $connexion['select'])) { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - // si le charset est fourni, l'utiliser |
|
| 334 | - if ($charset_sql_connexion) { |
|
| 335 | - return $charset_sql_connexion; |
|
| 336 | - } |
|
| 337 | - // sinon on regarde la table spip_meta |
|
| 338 | - // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 339 | - if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 340 | - or is_string($r) |
|
| 341 | - ) { |
|
| 342 | - return false; |
|
| 343 | - } |
|
| 344 | - if (!($f = $connexion['fetch'])) { |
|
| 345 | - return false; |
|
| 346 | - } |
|
| 347 | - $r = $f($r); |
|
| 348 | - |
|
| 349 | - return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 325 | + if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 326 | + include_spip('inc/headers'); |
|
| 327 | + redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + if (!($f = $connexion['select'])) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + // si le charset est fourni, l'utiliser |
|
| 334 | + if ($charset_sql_connexion) { |
|
| 335 | + return $charset_sql_connexion; |
|
| 336 | + } |
|
| 337 | + // sinon on regarde la table spip_meta |
|
| 338 | + // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 339 | + if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 340 | + or is_string($r) |
|
| 341 | + ) { |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 344 | + if (!($f = $connexion['fetch'])) { |
|
| 345 | + return false; |
|
| 346 | + } |
|
| 347 | + $r = $f($r); |
|
| 348 | + |
|
| 349 | + return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -361,9 +361,9 @@ discard block |
||
| 361 | 361 | * @return array |
| 362 | 362 | */ |
| 363 | 363 | function spip_connect_ldap($serveur = '') { |
| 364 | - include_spip('auth/ldap'); |
|
| 364 | + include_spip('auth/ldap'); |
|
| 365 | 365 | |
| 366 | - return auth_ldap_connect($serveur); |
|
| 366 | + return auth_ldap_connect($serveur); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | /** |
@@ -379,9 +379,9 @@ discard block |
||
| 379 | 379 | * @return string Valeur échappée. |
| 380 | 380 | **/ |
| 381 | 381 | function _q($a) { |
| 382 | - return (is_numeric($a)) ? strval($a) : |
|
| 383 | - (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 384 | - : join(",", array_map('_q', $a))); |
|
| 382 | + return (is_numeric($a)) ? strval($a) : |
|
| 383 | + (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 384 | + : join(",", array_map('_q', $a))); |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
@@ -397,41 +397,41 @@ discard block |
||
| 397 | 397 | * @return array |
| 398 | 398 | */ |
| 399 | 399 | function query_echappe_textes($query) { |
| 400 | - static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3"); |
|
| 401 | - $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 402 | - if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) { |
|
| 403 | - $textes = reset($textes); // indice 0 du match |
|
| 404 | - switch (count($textes)) { |
|
| 405 | - case 0: |
|
| 406 | - $replace = array(); |
|
| 407 | - break; |
|
| 408 | - case 1: |
|
| 409 | - $replace = array('%1$s'); |
|
| 410 | - break; |
|
| 411 | - case 2: |
|
| 412 | - $replace = array('%1$s', '%2$s'); |
|
| 413 | - break; |
|
| 414 | - case 3: |
|
| 415 | - $replace = array('%1$s', '%2$s', '%3$s'); |
|
| 416 | - break; |
|
| 417 | - case 4: |
|
| 418 | - $replace = array('%1$s', '%2$s', '%3$s', '%4$s'); |
|
| 419 | - break; |
|
| 420 | - case 5: |
|
| 421 | - $replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s'); |
|
| 422 | - break; |
|
| 423 | - default: |
|
| 424 | - $replace = range(1, count($textes)); |
|
| 425 | - $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 426 | - $replace = explode(',', $replace); |
|
| 427 | - break; |
|
| 428 | - } |
|
| 429 | - $query = str_replace($textes, $replace, $query); |
|
| 430 | - } else { |
|
| 431 | - $textes = array(); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return array($query, $textes); |
|
| 400 | + static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3"); |
|
| 401 | + $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 402 | + if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) { |
|
| 403 | + $textes = reset($textes); // indice 0 du match |
|
| 404 | + switch (count($textes)) { |
|
| 405 | + case 0: |
|
| 406 | + $replace = array(); |
|
| 407 | + break; |
|
| 408 | + case 1: |
|
| 409 | + $replace = array('%1$s'); |
|
| 410 | + break; |
|
| 411 | + case 2: |
|
| 412 | + $replace = array('%1$s', '%2$s'); |
|
| 413 | + break; |
|
| 414 | + case 3: |
|
| 415 | + $replace = array('%1$s', '%2$s', '%3$s'); |
|
| 416 | + break; |
|
| 417 | + case 4: |
|
| 418 | + $replace = array('%1$s', '%2$s', '%3$s', '%4$s'); |
|
| 419 | + break; |
|
| 420 | + case 5: |
|
| 421 | + $replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s'); |
|
| 422 | + break; |
|
| 423 | + default: |
|
| 424 | + $replace = range(1, count($textes)); |
|
| 425 | + $replace = '%' . implode('$s,%', $replace) . '$s'; |
|
| 426 | + $replace = explode(',', $replace); |
|
| 427 | + break; |
|
| 428 | + } |
|
| 429 | + $query = str_replace($textes, $replace, $query); |
|
| 430 | + } else { |
|
| 431 | + $textes = array(); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return array($query, $textes); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -445,40 +445,40 @@ discard block |
||
| 445 | 445 | * @return string |
| 446 | 446 | */ |
| 447 | 447 | function query_reinjecte_textes($query, $textes) { |
| 448 | - static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3"); |
|
| 449 | - # debug de la substitution |
|
| 450 | - #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){ |
|
| 451 | - # spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR); |
|
| 452 | - # spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR); |
|
| 453 | - # spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR); |
|
| 454 | - #} |
|
| 455 | - switch (count($textes)) { |
|
| 456 | - case 0: |
|
| 457 | - break; |
|
| 458 | - case 1: |
|
| 459 | - $query = sprintf($query, $textes[0]); |
|
| 460 | - break; |
|
| 461 | - case 2: |
|
| 462 | - $query = sprintf($query, $textes[0], $textes[1]); |
|
| 463 | - break; |
|
| 464 | - case 3: |
|
| 465 | - $query = sprintf($query, $textes[0], $textes[1], $textes[2]); |
|
| 466 | - break; |
|
| 467 | - case 4: |
|
| 468 | - $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]); |
|
| 469 | - break; |
|
| 470 | - case 5: |
|
| 471 | - $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]); |
|
| 472 | - break; |
|
| 473 | - default: |
|
| 474 | - array_unshift($textes, $query); |
|
| 475 | - $query = call_user_func_array('sprintf', $textes); |
|
| 476 | - break; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 480 | - |
|
| 481 | - return $query; |
|
| 448 | + static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3"); |
|
| 449 | + # debug de la substitution |
|
| 450 | + #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){ |
|
| 451 | + # spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR); |
|
| 452 | + # spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR); |
|
| 453 | + # spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR); |
|
| 454 | + #} |
|
| 455 | + switch (count($textes)) { |
|
| 456 | + case 0: |
|
| 457 | + break; |
|
| 458 | + case 1: |
|
| 459 | + $query = sprintf($query, $textes[0]); |
|
| 460 | + break; |
|
| 461 | + case 2: |
|
| 462 | + $query = sprintf($query, $textes[0], $textes[1]); |
|
| 463 | + break; |
|
| 464 | + case 3: |
|
| 465 | + $query = sprintf($query, $textes[0], $textes[1], $textes[2]); |
|
| 466 | + break; |
|
| 467 | + case 4: |
|
| 468 | + $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]); |
|
| 469 | + break; |
|
| 470 | + case 5: |
|
| 471 | + $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]); |
|
| 472 | + break; |
|
| 473 | + default: |
|
| 474 | + array_unshift($textes, $query); |
|
| 475 | + $query = call_user_func_array('sprintf', $textes); |
|
| 476 | + break; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 480 | + |
|
| 481 | + return $query; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | **/ |
| 498 | 498 | function spip_query($query, $serveur = '') { |
| 499 | 499 | |
| 500 | - $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 500 | + $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 501 | 501 | |
| 502 | - return function_exists($f) ? $f($query, $serveur) : false; |
|
| 502 | + return function_exists($f) ? $f($query, $serveur) : false; |
|
| 503 | 503 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -39,28 +39,28 @@ discard block |
||
| 39 | 39 | * Tableau des champs et valeurs collectées |
| 40 | 40 | */ |
| 41 | 41 | function collecter_requests($white_list, $black_list = array(), $set = null, $tous = false) { |
| 42 | - $c = $set; |
|
| 43 | - if (!$c) { |
|
| 44 | - $c = array(); |
|
| 45 | - foreach ($white_list as $champ) { |
|
| 46 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | - $val = _request($champ); |
|
| 49 | - if ($tous or $val !== null) { |
|
| 50 | - $c[$champ] = $val; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - // on ajoute toujours la lang en saisie possible |
|
| 54 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | - if ($l = _request('changer_lang')) { |
|
| 56 | - $c['lang'] = $l; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - foreach ($black_list as $champ) { |
|
| 60 | - unset($c[$champ]); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return $c; |
|
| 42 | + $c = $set; |
|
| 43 | + if (!$c) { |
|
| 44 | + $c = array(); |
|
| 45 | + foreach ($white_list as $champ) { |
|
| 46 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | + $val = _request($champ); |
|
| 49 | + if ($tous or $val !== null) { |
|
| 50 | + $c[$champ] = $val; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + // on ajoute toujours la lang en saisie possible |
|
| 54 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | + if ($l = _request('changer_lang')) { |
|
| 56 | + $c['lang'] = $l; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + foreach ($black_list as $champ) { |
|
| 60 | + unset($c[$champ]); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return $c; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -97,211 +97,211 @@ discard block |
||
| 97 | 97 | * - chaîne : Texte d'un message d'erreur |
| 98 | 98 | */ |
| 99 | 99 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 100 | - if (!$id_objet = intval($id_objet)) { |
|
| 101 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | - |
|
| 103 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/filtres'); |
|
| 107 | - |
|
| 108 | - $table_objet = table_objet($objet, $serveur); |
|
| 109 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | - |
|
| 114 | - // Appels incomplets (sans $c) |
|
| 115 | - if (!is_array($c)) { |
|
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | - |
|
| 118 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | - // il faut passer par instituer_XX() |
|
| 124 | - // TODO: faut-il passer ces variables interdites |
|
| 125 | - // dans un fichier de description separe ? |
|
| 126 | - unset($c['statut']); |
|
| 127 | - unset($c['id_parent']); |
|
| 128 | - unset($c['id_rubrique']); |
|
| 129 | - unset($c['id_secteur']); |
|
| 130 | - |
|
| 131 | - // Gerer les champs non vides |
|
| 132 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | - if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | - $c[$champ] = $sinon; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - // N'accepter que les champs qui existent |
|
| 142 | - // TODO: ici aussi on peut valider les contenus |
|
| 143 | - // en fonction du type |
|
| 144 | - $champs = array(); |
|
| 145 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 146 | - if (isset($c[$champ])) { |
|
| 147 | - $champs[$champ] = $c[$champ]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Nettoyer les valeurs |
|
| 152 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 153 | - |
|
| 154 | - // Envoyer aux plugins |
|
| 155 | - $champs = pipeline('pre_edition', |
|
| 156 | - array( |
|
| 157 | - 'args' => array( |
|
| 158 | - 'table' => $spip_table_objet, // compatibilite |
|
| 159 | - 'table_objet' => $table_objet, |
|
| 160 | - 'spip_table_objet' => $spip_table_objet, |
|
| 161 | - 'desc' => $desc, |
|
| 162 | - 'type' => $objet, |
|
| 163 | - 'id_objet' => $id_objet, |
|
| 164 | - 'data' => isset($options['data']) ? $options['data'] : null, |
|
| 165 | - 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 166 | - 'serveur' => $serveur, |
|
| 167 | - 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 168 | - ), |
|
| 169 | - 'data' => $champs |
|
| 170 | - ) |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - if (!$champs) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 179 | - if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 180 | - include_spip('inc/drapeau_edition'); |
|
| 181 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 185 | - include_spip('inc/editer'); |
|
| 186 | - if (!isset($options['data']) or is_null($options['data'])){ |
|
| 187 | - $options['data'] = &$_POST; |
|
| 188 | - } |
|
| 189 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 190 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 191 | - // et gere l'interface |
|
| 192 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 193 | - if ($conflits) { |
|
| 194 | - return _T('titre_conflit_edition'); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if ($champs) { |
|
| 198 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 199 | - if (isset($champs['lang'])) { |
|
| 200 | - if ($changer_lang = $champs['lang']) { |
|
| 201 | - $id_rubrique = 0; |
|
| 202 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 203 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 204 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 205 | - } |
|
| 206 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 207 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 208 | - } |
|
| 209 | - // on laisse 'lang' dans $champs, |
|
| 210 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 211 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 212 | - // deja pris en compte |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // la modif peut avoir lieu |
|
| 216 | - |
|
| 217 | - // faut-il ajouter date_modif ? |
|
| 218 | - if (isset($options['date_modif']) and $options['date_modif'] |
|
| 219 | - and !isset($champs[$options['date_modif']]) |
|
| 220 | - ) { |
|
| 221 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - // allez on commit la modif |
|
| 225 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur); |
|
| 226 | - |
|
| 227 | - // on verifie si elle est bien passee |
|
| 228 | - $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(), |
|
| 229 | - '', array(), $serveur); |
|
| 230 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 231 | - if ($moof != $champs) { |
|
| 232 | - $liste = array(); |
|
| 233 | - foreach ($moof as $k => $v) { |
|
| 234 | - if ($v !== $champs[$k] |
|
| 235 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 236 | - and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 237 | - // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 238 | - and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 239 | - ) { |
|
| 240 | - $liste[] = $k; |
|
| 241 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 242 | - $conflits[$k]['save'] = $v; |
|
| 243 | - |
|
| 244 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 245 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 246 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 247 | - include_spip('inc/charsets'); |
|
| 248 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 249 | - array_pop($liste); |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 255 | - // c'est un cas exceptionnel |
|
| 256 | - if (count($liste)) { |
|
| 257 | - spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 258 | - 'modifier.' . _LOG_CRITIQUE); |
|
| 259 | - |
|
| 260 | - return _T('erreur_technique_enregistrement_champs', |
|
| 261 | - array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>")); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - // Invalider les caches |
|
| 266 | - if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 267 | - include_spip('inc/invalideur'); |
|
| 268 | - if (is_array($options['invalideur'])) { |
|
| 269 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 270 | - } else { |
|
| 271 | - suivre_invalideur($options['invalideur']); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Notifications, gestion des revisions... |
|
| 276 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 277 | - pipeline('post_edition', |
|
| 278 | - array( |
|
| 279 | - 'args' => array( |
|
| 280 | - 'table' => $spip_table_objet, |
|
| 281 | - 'table_objet' => $table_objet, |
|
| 282 | - 'spip_table_objet' => $spip_table_objet, |
|
| 283 | - 'desc' => $desc, |
|
| 284 | - 'type' => $objet, |
|
| 285 | - 'id_objet' => $id_objet, |
|
| 286 | - 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] kesako ? |
|
| 287 | - 'serveur' => $serveur, |
|
| 288 | - 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 289 | - ), |
|
| 290 | - 'data' => $champs |
|
| 291 | - ) |
|
| 292 | - ); |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // journaliser l'affaire |
|
| 296 | - // message a affiner :-) |
|
| 297 | - include_spip('inc/filtres_mini'); |
|
| 298 | - $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip']; |
|
| 299 | - journal(_L($qui . ' a édité l’' . $objet . ' ' . $id_objet . ' (' . join('+', |
|
| 300 | - array_diff(array_keys($champs), array('date_modif'))) . ')'), array( |
|
| 301 | - 'faire' => 'modifier', |
|
| 302 | - 'quoi' => $objet, |
|
| 303 | - 'id' => $id_objet |
|
| 304 | - )); |
|
| 305 | - |
|
| 306 | - return ''; |
|
| 100 | + if (!$id_objet = intval($id_objet)) { |
|
| 101 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | + |
|
| 103 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/filtres'); |
|
| 107 | + |
|
| 108 | + $table_objet = table_objet($objet, $serveur); |
|
| 109 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | + |
|
| 114 | + // Appels incomplets (sans $c) |
|
| 115 | + if (!is_array($c)) { |
|
| 116 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | + |
|
| 118 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | + // il faut passer par instituer_XX() |
|
| 124 | + // TODO: faut-il passer ces variables interdites |
|
| 125 | + // dans un fichier de description separe ? |
|
| 126 | + unset($c['statut']); |
|
| 127 | + unset($c['id_parent']); |
|
| 128 | + unset($c['id_rubrique']); |
|
| 129 | + unset($c['id_secteur']); |
|
| 130 | + |
|
| 131 | + // Gerer les champs non vides |
|
| 132 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | + if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | + $c[$champ] = $sinon; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + // N'accepter que les champs qui existent |
|
| 142 | + // TODO: ici aussi on peut valider les contenus |
|
| 143 | + // en fonction du type |
|
| 144 | + $champs = array(); |
|
| 145 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 146 | + if (isset($c[$champ])) { |
|
| 147 | + $champs[$champ] = $c[$champ]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Nettoyer les valeurs |
|
| 152 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 153 | + |
|
| 154 | + // Envoyer aux plugins |
|
| 155 | + $champs = pipeline('pre_edition', |
|
| 156 | + array( |
|
| 157 | + 'args' => array( |
|
| 158 | + 'table' => $spip_table_objet, // compatibilite |
|
| 159 | + 'table_objet' => $table_objet, |
|
| 160 | + 'spip_table_objet' => $spip_table_objet, |
|
| 161 | + 'desc' => $desc, |
|
| 162 | + 'type' => $objet, |
|
| 163 | + 'id_objet' => $id_objet, |
|
| 164 | + 'data' => isset($options['data']) ? $options['data'] : null, |
|
| 165 | + 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 166 | + 'serveur' => $serveur, |
|
| 167 | + 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 168 | + ), |
|
| 169 | + 'data' => $champs |
|
| 170 | + ) |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + if (!$champs) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 179 | + if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 180 | + include_spip('inc/drapeau_edition'); |
|
| 181 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 185 | + include_spip('inc/editer'); |
|
| 186 | + if (!isset($options['data']) or is_null($options['data'])){ |
|
| 187 | + $options['data'] = &$_POST; |
|
| 188 | + } |
|
| 189 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 190 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 191 | + // et gere l'interface |
|
| 192 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 193 | + if ($conflits) { |
|
| 194 | + return _T('titre_conflit_edition'); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if ($champs) { |
|
| 198 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 199 | + if (isset($champs['lang'])) { |
|
| 200 | + if ($changer_lang = $champs['lang']) { |
|
| 201 | + $id_rubrique = 0; |
|
| 202 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 203 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 204 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 205 | + } |
|
| 206 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 207 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 208 | + } |
|
| 209 | + // on laisse 'lang' dans $champs, |
|
| 210 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 211 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 212 | + // deja pris en compte |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // la modif peut avoir lieu |
|
| 216 | + |
|
| 217 | + // faut-il ajouter date_modif ? |
|
| 218 | + if (isset($options['date_modif']) and $options['date_modif'] |
|
| 219 | + and !isset($champs[$options['date_modif']]) |
|
| 220 | + ) { |
|
| 221 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + // allez on commit la modif |
|
| 225 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur); |
|
| 226 | + |
|
| 227 | + // on verifie si elle est bien passee |
|
| 228 | + $moof = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=" . intval($id_objet), array(), array(), |
|
| 229 | + '', array(), $serveur); |
|
| 230 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 231 | + if ($moof != $champs) { |
|
| 232 | + $liste = array(); |
|
| 233 | + foreach ($moof as $k => $v) { |
|
| 234 | + if ($v !== $champs[$k] |
|
| 235 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 236 | + and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 237 | + // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 238 | + and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 239 | + ) { |
|
| 240 | + $liste[] = $k; |
|
| 241 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 242 | + $conflits[$k]['save'] = $v; |
|
| 243 | + |
|
| 244 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 245 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 246 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 247 | + include_spip('inc/charsets'); |
|
| 248 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 249 | + array_pop($liste); |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 255 | + // c'est un cas exceptionnel |
|
| 256 | + if (count($liste)) { |
|
| 257 | + spip_log("Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 258 | + 'modifier.' . _LOG_CRITIQUE); |
|
| 259 | + |
|
| 260 | + return _T('erreur_technique_enregistrement_champs', |
|
| 261 | + array('champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>")); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + // Invalider les caches |
|
| 266 | + if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 267 | + include_spip('inc/invalideur'); |
|
| 268 | + if (is_array($options['invalideur'])) { |
|
| 269 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 270 | + } else { |
|
| 271 | + suivre_invalideur($options['invalideur']); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Notifications, gestion des revisions... |
|
| 276 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 277 | + pipeline('post_edition', |
|
| 278 | + array( |
|
| 279 | + 'args' => array( |
|
| 280 | + 'table' => $spip_table_objet, |
|
| 281 | + 'table_objet' => $table_objet, |
|
| 282 | + 'spip_table_objet' => $spip_table_objet, |
|
| 283 | + 'desc' => $desc, |
|
| 284 | + 'type' => $objet, |
|
| 285 | + 'id_objet' => $id_objet, |
|
| 286 | + 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] kesako ? |
|
| 287 | + 'serveur' => $serveur, |
|
| 288 | + 'action' => isset($options['action']) ? $options['action'] : 'modifier' |
|
| 289 | + ), |
|
| 290 | + 'data' => $champs |
|
| 291 | + ) |
|
| 292 | + ); |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // journaliser l'affaire |
|
| 296 | + // message a affiner :-) |
|
| 297 | + include_spip('inc/filtres_mini'); |
|
| 298 | + $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip']; |
|
| 299 | + journal(_L($qui . ' a édité l’' . $objet . ' ' . $id_objet . ' (' . join('+', |
|
| 300 | + array_diff(array_keys($champs), array('date_modif'))) . ')'), array( |
|
| 301 | + 'faire' => 'modifier', |
|
| 302 | + 'quoi' => $objet, |
|
| 303 | + 'id' => $id_objet |
|
| 304 | + )); |
|
| 305 | + |
|
| 306 | + return ''; |
|
| 307 | 307 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -48,63 +48,63 @@ discard block |
||
| 48 | 48 | * Nom de la fonction, ou false. |
| 49 | 49 | */ |
| 50 | 50 | function charger_fonction($nom, $dossier = 'exec', $continue = false) { |
| 51 | - static $echecs = array(); |
|
| 52 | - |
|
| 53 | - if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | - $dossier .= '/'; |
|
| 55 | - } |
|
| 56 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | - |
|
| 58 | - if (function_exists($f)) { |
|
| 59 | - return $f; |
|
| 60 | - } |
|
| 61 | - if (function_exists($g = $f . '_dist')) { |
|
| 62 | - return $g; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if (isset($echecs[$f])) { |
|
| 66 | - return $echecs[$f]; |
|
| 67 | - } |
|
| 68 | - // Sinon charger le fichier de declaration si plausible |
|
| 69 | - |
|
| 70 | - if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | - if ($continue) { |
|
| 72 | - return false; |
|
| 73 | - } //appel interne, on passe |
|
| 74 | - include_spip('inc/minipres'); |
|
| 75 | - echo minipres(); |
|
| 76 | - exit; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // passer en minuscules (cf les balises de formulaires) |
|
| 80 | - // et inclure le fichier |
|
| 81 | - if (!$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 82 | - // si le fichier truc/machin/nom.php n'existe pas, |
|
| 83 | - // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 84 | - and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 85 | - ) { |
|
| 86 | - include_spip(substr($dossier, 0, -1)); |
|
| 87 | - } |
|
| 88 | - if (function_exists($f)) { |
|
| 89 | - return $f; |
|
| 90 | - } |
|
| 91 | - if (function_exists($g)) { |
|
| 92 | - return $g; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if ($continue) { |
|
| 96 | - return $echecs[$f] = false; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // Echec : message d'erreur |
|
| 100 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 101 | - ($inc ? "" : " (fichier $d absent de $dossier)")); |
|
| 102 | - |
|
| 103 | - include_spip('inc/minipres'); |
|
| 104 | - echo minipres(_T('forum_titre_erreur'), |
|
| 105 | - _T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')), |
|
| 106 | - array('all_inline'=>true,'status'=>404)); |
|
| 107 | - exit; |
|
| 51 | + static $echecs = array(); |
|
| 52 | + |
|
| 53 | + if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | + $dossier .= '/'; |
|
| 55 | + } |
|
| 56 | + $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | + |
|
| 58 | + if (function_exists($f)) { |
|
| 59 | + return $f; |
|
| 60 | + } |
|
| 61 | + if (function_exists($g = $f . '_dist')) { |
|
| 62 | + return $g; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if (isset($echecs[$f])) { |
|
| 66 | + return $echecs[$f]; |
|
| 67 | + } |
|
| 68 | + // Sinon charger le fichier de declaration si plausible |
|
| 69 | + |
|
| 70 | + if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | + if ($continue) { |
|
| 72 | + return false; |
|
| 73 | + } //appel interne, on passe |
|
| 74 | + include_spip('inc/minipres'); |
|
| 75 | + echo minipres(); |
|
| 76 | + exit; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // passer en minuscules (cf les balises de formulaires) |
|
| 80 | + // et inclure le fichier |
|
| 81 | + if (!$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 82 | + // si le fichier truc/machin/nom.php n'existe pas, |
|
| 83 | + // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 84 | + and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 85 | + ) { |
|
| 86 | + include_spip(substr($dossier, 0, -1)); |
|
| 87 | + } |
|
| 88 | + if (function_exists($f)) { |
|
| 89 | + return $f; |
|
| 90 | + } |
|
| 91 | + if (function_exists($g)) { |
|
| 92 | + return $g; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if ($continue) { |
|
| 96 | + return $echecs[$f] = false; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // Echec : message d'erreur |
|
| 100 | + spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 101 | + ($inc ? "" : " (fichier $d absent de $dossier)")); |
|
| 102 | + |
|
| 103 | + include_spip('inc/minipres'); |
|
| 104 | + echo minipres(_T('forum_titre_erreur'), |
|
| 105 | + _T('fichier_introuvable', array('fichier' => '<b>' . spip_htmlentities($d) . '</b>')), |
|
| 106 | + array('all_inline'=>true,'status'=>404)); |
|
| 107 | + exit; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -114,17 +114,17 @@ discard block |
||
| 114 | 114 | * @return bool |
| 115 | 115 | */ |
| 116 | 116 | function include_once_check($file) { |
| 117 | - if (file_exists($file)) { |
|
| 118 | - include_once $file; |
|
| 117 | + if (file_exists($file)) { |
|
| 118 | + include_once $file; |
|
| 119 | 119 | |
| 120 | - return true; |
|
| 121 | - } |
|
| 122 | - $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 123 | - $crash = ($crash ? $crash : array()); |
|
| 124 | - $crash[$file] = true; |
|
| 125 | - ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 120 | + return true; |
|
| 121 | + } |
|
| 122 | + $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 123 | + $crash = ($crash ? $crash : array()); |
|
| 124 | + $crash[$file] = true; |
|
| 125 | + ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 126 | 126 | |
| 127 | - return false; |
|
| 127 | + return false; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * - string : chemin du fichier trouvé |
| 149 | 149 | **/ |
| 150 | 150 | function include_spip($f, $include = true) { |
| 151 | - return find_in_path($f . '.php', '', $include); |
|
| 151 | + return find_in_path($f . '.php', '', $include); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * - string : chemin du fichier trouvé |
| 169 | 169 | **/ |
| 170 | 170 | function require_spip($f) { |
| 171 | - return find_in_path($f . '.php', '', 'required'); |
|
| 171 | + return find_in_path($f . '.php', '', 'required'); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -177,27 +177,27 @@ discard block |
||
| 177 | 177 | * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis |
| 178 | 178 | */ |
| 179 | 179 | function include_fichiers_fonctions() { |
| 180 | - static $done = false; |
|
| 181 | - if (!$done) { |
|
| 182 | - include_spip('inc/lang'); |
|
| 183 | - |
|
| 184 | - // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 185 | - // donc il faut l'inclure "en globals" |
|
| 186 | - if ($f = find_in_path('mes_fonctions.php')) { |
|
| 187 | - global $dossier_squelettes; |
|
| 188 | - include_once(_ROOT_CWD . $f); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 192 | - // chargement optimise precompile |
|
| 193 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 194 | - } |
|
| 195 | - if (test_espace_prive()) { |
|
| 196 | - include_spip('inc/filtres_ecrire'); |
|
| 197 | - } |
|
| 198 | - include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 199 | - $done = true; |
|
| 200 | - } |
|
| 180 | + static $done = false; |
|
| 181 | + if (!$done) { |
|
| 182 | + include_spip('inc/lang'); |
|
| 183 | + |
|
| 184 | + // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 185 | + // donc il faut l'inclure "en globals" |
|
| 186 | + if ($f = find_in_path('mes_fonctions.php')) { |
|
| 187 | + global $dossier_squelettes; |
|
| 188 | + include_once(_ROOT_CWD . $f); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 192 | + // chargement optimise precompile |
|
| 193 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 194 | + } |
|
| 195 | + if (test_espace_prive()) { |
|
| 196 | + include_spip('inc/filtres_ecrire'); |
|
| 197 | + } |
|
| 198 | + include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 199 | + $done = true; |
|
| 200 | + } |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -223,22 +223,22 @@ discard block |
||
| 223 | 223 | * Les paramètres du pipeline modifiés |
| 224 | 224 | **/ |
| 225 | 225 | function minipipe($fonc, &$val) { |
| 226 | - // fonction |
|
| 227 | - if (function_exists($fonc)) { |
|
| 228 | - $val = call_user_func($fonc, $val); |
|
| 229 | - } // Class::Methode |
|
| 230 | - else { |
|
| 231 | - if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs) |
|
| 232 | - and $methode = array($regs[1], $regs[2]) |
|
| 233 | - and is_callable($methode) |
|
| 234 | - ) { |
|
| 235 | - $val = call_user_func($methode, $val); |
|
| 236 | - } else { |
|
| 237 | - spip_log("Erreur - '$fonc' non definie !"); |
|
| 238 | - } |
|
| 239 | - } |
|
| 226 | + // fonction |
|
| 227 | + if (function_exists($fonc)) { |
|
| 228 | + $val = call_user_func($fonc, $val); |
|
| 229 | + } // Class::Methode |
|
| 230 | + else { |
|
| 231 | + if (preg_match("/^(\w*)::(\w*)$/S", $fonc, $regs) |
|
| 232 | + and $methode = array($regs[1], $regs[2]) |
|
| 233 | + and is_callable($methode) |
|
| 234 | + ) { |
|
| 235 | + $val = call_user_func($methode, $val); |
|
| 236 | + } else { |
|
| 237 | + spip_log("Erreur - '$fonc' non definie !"); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - return $val; |
|
| 241 | + return $val; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -269,45 +269,45 @@ discard block |
||
| 269 | 269 | * Résultat |
| 270 | 270 | */ |
| 271 | 271 | function pipeline($action, $val = null) { |
| 272 | - static $charger; |
|
| 273 | - |
|
| 274 | - // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 275 | - if (!$charger) { |
|
| 276 | - if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 277 | - include_spip('inc/plugin'); |
|
| 278 | - // generer les fichiers php precompiles |
|
| 279 | - // de chargement des plugins et des pipelines |
|
| 280 | - actualise_plugins_actifs(); |
|
| 281 | - if (!($ok = @is_readable($charger))) { |
|
| 282 | - spip_log("fichier $charger pas cree"); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - if ($ok) { |
|
| 287 | - include_once $charger; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // appliquer notre fonction si elle existe |
|
| 292 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 293 | - if (function_exists($fonc)) { |
|
| 294 | - $val = $fonc($val); |
|
| 295 | - } // plantage ? |
|
| 296 | - else { |
|
| 297 | - spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // si le flux est une table avec 2 cle args&data |
|
| 301 | - // on ne ressort du pipe que les donnees dans 'data' |
|
| 302 | - // array_key_exists pour php 4.1.0 |
|
| 303 | - if (is_array($val) |
|
| 304 | - and count($val) == 2 |
|
| 305 | - and (array_key_exists('data', $val)) |
|
| 306 | - ) { |
|
| 307 | - $val = $val['data']; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - return $val; |
|
| 272 | + static $charger; |
|
| 273 | + |
|
| 274 | + // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 275 | + if (!$charger) { |
|
| 276 | + if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 277 | + include_spip('inc/plugin'); |
|
| 278 | + // generer les fichiers php precompiles |
|
| 279 | + // de chargement des plugins et des pipelines |
|
| 280 | + actualise_plugins_actifs(); |
|
| 281 | + if (!($ok = @is_readable($charger))) { |
|
| 282 | + spip_log("fichier $charger pas cree"); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + if ($ok) { |
|
| 287 | + include_once $charger; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // appliquer notre fonction si elle existe |
|
| 292 | + $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 293 | + if (function_exists($fonc)) { |
|
| 294 | + $val = $fonc($val); |
|
| 295 | + } // plantage ? |
|
| 296 | + else { |
|
| 297 | + spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // si le flux est une table avec 2 cle args&data |
|
| 301 | + // on ne ressort du pipe que les donnees dans 'data' |
|
| 302 | + // array_key_exists pour php 4.1.0 |
|
| 303 | + if (is_array($val) |
|
| 304 | + and count($val) == 2 |
|
| 305 | + and (array_key_exists('data', $val)) |
|
| 306 | + ) { |
|
| 307 | + $val = $val['data']; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + return $val; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
@@ -351,38 +351,38 @@ discard block |
||
| 351 | 351 | * paramètre est planté pour cause de compatibilité ascendante. |
| 352 | 352 | */ |
| 353 | 353 | function spip_log($message = null, $name = null) { |
| 354 | - static $pre = array(); |
|
| 355 | - static $log; |
|
| 356 | - preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 357 | - if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 358 | - $logname = null; |
|
| 359 | - } |
|
| 360 | - if (!isset($regs[2])) { |
|
| 361 | - $niveau = _LOG_INFO; |
|
| 362 | - } |
|
| 363 | - else { |
|
| 364 | - $niveau = intval($regs[2]); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 368 | - if (!$pre) { |
|
| 369 | - $pre = array( |
|
| 370 | - _LOG_HS => 'HS:', |
|
| 371 | - _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 372 | - _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 373 | - _LOG_ERREUR => 'ERREUR:', |
|
| 374 | - _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 375 | - _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 376 | - _LOG_INFO => 'info:', |
|
| 377 | - _LOG_DEBUG => 'debug:' |
|
| 378 | - ); |
|
| 379 | - $log = charger_fonction('log', 'inc'); |
|
| 380 | - } |
|
| 381 | - if (!is_string($message)) { |
|
| 382 | - $message = print_r($message, true); |
|
| 383 | - } |
|
| 384 | - $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 385 | - } |
|
| 354 | + static $pre = array(); |
|
| 355 | + static $log; |
|
| 356 | + preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 357 | + if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 358 | + $logname = null; |
|
| 359 | + } |
|
| 360 | + if (!isset($regs[2])) { |
|
| 361 | + $niveau = _LOG_INFO; |
|
| 362 | + } |
|
| 363 | + else { |
|
| 364 | + $niveau = intval($regs[2]); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 368 | + if (!$pre) { |
|
| 369 | + $pre = array( |
|
| 370 | + _LOG_HS => 'HS:', |
|
| 371 | + _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 372 | + _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 373 | + _LOG_ERREUR => 'ERREUR:', |
|
| 374 | + _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 375 | + _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 376 | + _LOG_INFO => 'info:', |
|
| 377 | + _LOG_DEBUG => 'debug:' |
|
| 378 | + ); |
|
| 379 | + $log = charger_fonction('log', 'inc'); |
|
| 380 | + } |
|
| 381 | + if (!is_string($message)) { |
|
| 382 | + $message = print_r($message, true); |
|
| 383 | + } |
|
| 384 | + $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 385 | + } |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -393,8 +393,8 @@ discard block |
||
| 393 | 393 | * @param array $opt Tableau d'options |
| 394 | 394 | **/ |
| 395 | 395 | function journal($phrase, $opt = array()) { |
| 396 | - $journal = charger_fonction('journal', 'inc'); |
|
| 397 | - $journal($phrase, $opt); |
|
| 396 | + $journal = charger_fonction('journal', 'inc'); |
|
| 397 | + $journal($phrase, $opt); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | |
@@ -413,36 +413,36 @@ discard block |
||
| 413 | 413 | **/ |
| 414 | 414 | function _request($var, $c = false) { |
| 415 | 415 | |
| 416 | - if (is_array($c)) { |
|
| 417 | - return isset($c[$var]) ? $c[$var] : null; |
|
| 418 | - } |
|
| 416 | + if (is_array($c)) { |
|
| 417 | + return isset($c[$var]) ? $c[$var] : null; |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | - if (isset($_GET[$var])) { |
|
| 421 | - $a = $_GET[$var]; |
|
| 422 | - } elseif (isset($_POST[$var])) { |
|
| 423 | - $a = $_POST[$var]; |
|
| 424 | - } else { |
|
| 425 | - return null; |
|
| 426 | - } |
|
| 420 | + if (isset($_GET[$var])) { |
|
| 421 | + $a = $_GET[$var]; |
|
| 422 | + } elseif (isset($_POST[$var])) { |
|
| 423 | + $a = $_POST[$var]; |
|
| 424 | + } else { |
|
| 425 | + return null; |
|
| 426 | + } |
|
| 427 | 427 | |
| 428 | - // Si on est en ajax et en POST tout a ete encode |
|
| 429 | - // via encodeURIComponent, il faut donc repasser |
|
| 430 | - // dans le charset local... |
|
| 431 | - if (defined('_AJAX') |
|
| 432 | - and _AJAX |
|
| 433 | - and isset($GLOBALS['meta']['charset']) |
|
| 434 | - and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 435 | - and is_string($a) |
|
| 436 | - // check rapide mais pas fiable |
|
| 437 | - and preg_match(',[\x80-\xFF],', $a) |
|
| 438 | - // check fiable |
|
| 439 | - and include_spip('inc/charsets') |
|
| 440 | - and is_utf8($a) |
|
| 441 | - ) { |
|
| 442 | - return importer_charset($a, 'utf-8'); |
|
| 443 | - } |
|
| 428 | + // Si on est en ajax et en POST tout a ete encode |
|
| 429 | + // via encodeURIComponent, il faut donc repasser |
|
| 430 | + // dans le charset local... |
|
| 431 | + if (defined('_AJAX') |
|
| 432 | + and _AJAX |
|
| 433 | + and isset($GLOBALS['meta']['charset']) |
|
| 434 | + and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 435 | + and is_string($a) |
|
| 436 | + // check rapide mais pas fiable |
|
| 437 | + and preg_match(',[\x80-\xFF],', $a) |
|
| 438 | + // check fiable |
|
| 439 | + and include_spip('inc/charsets') |
|
| 440 | + and is_utf8($a) |
|
| 441 | + ) { |
|
| 442 | + return importer_charset($a, 'utf-8'); |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | - return $a; |
|
| 445 | + return $a; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | |
@@ -460,22 +460,22 @@ discard block |
||
| 460 | 460 | * - false sinon |
| 461 | 461 | **/ |
| 462 | 462 | function set_request($var, $val = null, $c = false) { |
| 463 | - if (is_array($c)) { |
|
| 464 | - unset($c[$var]); |
|
| 465 | - if ($val !== null) { |
|
| 466 | - $c[$var] = $val; |
|
| 467 | - } |
|
| 463 | + if (is_array($c)) { |
|
| 464 | + unset($c[$var]); |
|
| 465 | + if ($val !== null) { |
|
| 466 | + $c[$var] = $val; |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | - return $c; |
|
| 470 | - } |
|
| 469 | + return $c; |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | - unset($_GET[$var]); |
|
| 473 | - unset($_POST[$var]); |
|
| 474 | - if ($val !== null) { |
|
| 475 | - $_GET[$var] = $val; |
|
| 476 | - } |
|
| 472 | + unset($_GET[$var]); |
|
| 473 | + unset($_POST[$var]); |
|
| 474 | + if ($val !== null) { |
|
| 475 | + $_GET[$var] = $val; |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - return false; # n'affecte pas $c |
|
| 478 | + return false; # n'affecte pas $c |
|
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | /** |
@@ -495,25 +495,25 @@ discard block |
||
| 495 | 495 | * @return array|mixed|string |
| 496 | 496 | */ |
| 497 | 497 | function spip_sanitize_from_request($value, $key, $sanitize_function='entites_html') { |
| 498 | - if (is_array($value)) { |
|
| 499 | - if ($key=='*') { |
|
| 500 | - $key = array_keys($value); |
|
| 501 | - } |
|
| 502 | - if (!is_array($key)) { |
|
| 503 | - $key = [$key]; |
|
| 504 | - } |
|
| 505 | - foreach ($key as $k) { |
|
| 506 | - if (!empty($value[$k])) { |
|
| 507 | - $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - return $value; |
|
| 511 | - } |
|
| 512 | - // si la valeur vient des GET ou POST on la sanitize |
|
| 513 | - if (!empty($value) and $value == _request($key)) { |
|
| 514 | - $value = $sanitize_function($value); |
|
| 515 | - } |
|
| 516 | - return $value; |
|
| 498 | + if (is_array($value)) { |
|
| 499 | + if ($key=='*') { |
|
| 500 | + $key = array_keys($value); |
|
| 501 | + } |
|
| 502 | + if (!is_array($key)) { |
|
| 503 | + $key = [$key]; |
|
| 504 | + } |
|
| 505 | + foreach ($key as $k) { |
|
| 506 | + if (!empty($value[$k])) { |
|
| 507 | + $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + return $value; |
|
| 511 | + } |
|
| 512 | + // si la valeur vient des GET ou POST on la sanitize |
|
| 513 | + if (!empty($value) and $value == _request($key)) { |
|
| 514 | + $value = $sanitize_function($value); |
|
| 515 | + } |
|
| 516 | + return $value; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -521,23 +521,22 @@ discard block |
||
| 521 | 521 | * |
| 522 | 522 | * On est sur le web, on exclut certains protocoles, |
| 523 | 523 | * notamment 'file://', 'php://' et d'autres… |
| 524 | - |
|
| 525 | 524 | * @param string $url |
| 526 | 525 | * @return bool |
| 527 | 526 | */ |
| 528 | 527 | function tester_url_absolue($url) { |
| 529 | - $url = trim($url); |
|
| 530 | - if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) { |
|
| 531 | - if ( |
|
| 532 | - isset($m[1]) |
|
| 533 | - and $p = strtolower(rtrim($m[1], ':')) |
|
| 534 | - and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip')) |
|
| 535 | - ) { |
|
| 536 | - return false; |
|
| 537 | - } |
|
| 538 | - return true; |
|
| 539 | - } |
|
| 540 | - return false; |
|
| 528 | + $url = trim($url); |
|
| 529 | + if (preg_match(";^([a-z]{3,7}:)?//;Uims", $url, $m)) { |
|
| 530 | + if ( |
|
| 531 | + isset($m[1]) |
|
| 532 | + and $p = strtolower(rtrim($m[1], ':')) |
|
| 533 | + and in_array($p, array('file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip')) |
|
| 534 | + ) { |
|
| 535 | + return false; |
|
| 536 | + } |
|
| 537 | + return true; |
|
| 538 | + } |
|
| 539 | + return false; |
|
| 541 | 540 | } |
| 542 | 541 | |
| 543 | 542 | /** |
@@ -559,94 +558,94 @@ discard block |
||
| 559 | 558 | * @return string URL |
| 560 | 559 | */ |
| 561 | 560 | function parametre_url($url, $c, $v = null, $sep = '&') { |
| 562 | - // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 563 | - if (strpos($c, "|") !== false and is_null($v)) { |
|
| 564 | - return null; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - // lever l'#ancre |
|
| 568 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 569 | - $url = $r[1]; |
|
| 570 | - $ancre = $r[2]; |
|
| 571 | - } else { |
|
| 572 | - $ancre = ''; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - // eclater |
|
| 576 | - $url = preg_split(',[?]|&|&,', $url); |
|
| 577 | - |
|
| 578 | - // recuperer la base |
|
| 579 | - $a = array_shift($url); |
|
| 580 | - if (!$a) { |
|
| 581 | - $a = './'; |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 585 | - $ajouts = array_flip(explode('|', $c)); |
|
| 586 | - $u = is_array($v) ? $v : rawurlencode($v); |
|
| 587 | - $testv = (is_array($v) ? count($v) : strlen($v)); |
|
| 588 | - $v_read = null; |
|
| 589 | - // lire les variables et agir |
|
| 590 | - foreach ($url as $n => $val) { |
|
| 591 | - if (preg_match($regexp, urldecode($val), $r)) { |
|
| 592 | - $r = array_pad($r, 3, null); |
|
| 593 | - if ($v === null) { |
|
| 594 | - // c'est un tableau, on memorise les valeurs |
|
| 595 | - if (substr($r[1], -2) == "[]") { |
|
| 596 | - if (!$v_read) { |
|
| 597 | - $v_read = array(); |
|
| 598 | - } |
|
| 599 | - $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 600 | - } // c'est un scalaire, on retourne direct |
|
| 601 | - else { |
|
| 602 | - return $r[2] ? substr($r[2], 1) : ''; |
|
| 603 | - } |
|
| 604 | - } // suppression |
|
| 605 | - elseif (!$testv) { |
|
| 606 | - unset($url[$n]); |
|
| 607 | - } |
|
| 608 | - // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 609 | - // pour un tableau ce sera fait dans la prochaine boucle |
|
| 610 | - elseif (substr($r[1], -2) != '[]') { |
|
| 611 | - $url[$n] = $r[1] . '=' . $u; |
|
| 612 | - unset($ajouts[$r[1]]); |
|
| 613 | - } |
|
| 614 | - // Pour les tableaux on laisse tomber les valeurs de |
|
| 615 | - // départ, on remplira à l'étape suivante |
|
| 616 | - else { |
|
| 617 | - unset($url[$n]); |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - // traiter les parametres pas encore trouves |
|
| 623 | - if ($v === null |
|
| 624 | - and $args = func_get_args() |
|
| 625 | - and count($args) == 2 |
|
| 626 | - ) { |
|
| 627 | - return $v_read; // rien trouve ou un tableau |
|
| 628 | - } elseif ($testv) { |
|
| 629 | - foreach ($ajouts as $k => $n) { |
|
| 630 | - if (!is_array($v)) { |
|
| 631 | - $url[] = $k . '=' . $u; |
|
| 632 | - } else { |
|
| 633 | - $id = (substr($k, -2) == '[]') ? $k : ($k . "[]"); |
|
| 634 | - foreach ($v as $w) { |
|
| 635 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : $w); |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - // eliminer les vides |
|
| 642 | - $url = array_filter($url); |
|
| 643 | - |
|
| 644 | - // recomposer l'adresse |
|
| 645 | - if ($url) { |
|
| 646 | - $a .= '?' . join($sep, $url); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - return $a . $ancre; |
|
| 561 | + // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 562 | + if (strpos($c, "|") !== false and is_null($v)) { |
|
| 563 | + return null; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + // lever l'#ancre |
|
| 567 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 568 | + $url = $r[1]; |
|
| 569 | + $ancre = $r[2]; |
|
| 570 | + } else { |
|
| 571 | + $ancre = ''; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + // eclater |
|
| 575 | + $url = preg_split(',[?]|&|&,', $url); |
|
| 576 | + |
|
| 577 | + // recuperer la base |
|
| 578 | + $a = array_shift($url); |
|
| 579 | + if (!$a) { |
|
| 580 | + $a = './'; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 584 | + $ajouts = array_flip(explode('|', $c)); |
|
| 585 | + $u = is_array($v) ? $v : rawurlencode($v); |
|
| 586 | + $testv = (is_array($v) ? count($v) : strlen($v)); |
|
| 587 | + $v_read = null; |
|
| 588 | + // lire les variables et agir |
|
| 589 | + foreach ($url as $n => $val) { |
|
| 590 | + if (preg_match($regexp, urldecode($val), $r)) { |
|
| 591 | + $r = array_pad($r, 3, null); |
|
| 592 | + if ($v === null) { |
|
| 593 | + // c'est un tableau, on memorise les valeurs |
|
| 594 | + if (substr($r[1], -2) == "[]") { |
|
| 595 | + if (!$v_read) { |
|
| 596 | + $v_read = array(); |
|
| 597 | + } |
|
| 598 | + $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 599 | + } // c'est un scalaire, on retourne direct |
|
| 600 | + else { |
|
| 601 | + return $r[2] ? substr($r[2], 1) : ''; |
|
| 602 | + } |
|
| 603 | + } // suppression |
|
| 604 | + elseif (!$testv) { |
|
| 605 | + unset($url[$n]); |
|
| 606 | + } |
|
| 607 | + // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 608 | + // pour un tableau ce sera fait dans la prochaine boucle |
|
| 609 | + elseif (substr($r[1], -2) != '[]') { |
|
| 610 | + $url[$n] = $r[1] . '=' . $u; |
|
| 611 | + unset($ajouts[$r[1]]); |
|
| 612 | + } |
|
| 613 | + // Pour les tableaux on laisse tomber les valeurs de |
|
| 614 | + // départ, on remplira à l'étape suivante |
|
| 615 | + else { |
|
| 616 | + unset($url[$n]); |
|
| 617 | + } |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + // traiter les parametres pas encore trouves |
|
| 622 | + if ($v === null |
|
| 623 | + and $args = func_get_args() |
|
| 624 | + and count($args) == 2 |
|
| 625 | + ) { |
|
| 626 | + return $v_read; // rien trouve ou un tableau |
|
| 627 | + } elseif ($testv) { |
|
| 628 | + foreach ($ajouts as $k => $n) { |
|
| 629 | + if (!is_array($v)) { |
|
| 630 | + $url[] = $k . '=' . $u; |
|
| 631 | + } else { |
|
| 632 | + $id = (substr($k, -2) == '[]') ? $k : ($k . "[]"); |
|
| 633 | + foreach ($v as $w) { |
|
| 634 | + $url[] = $id . '=' . (is_array($w) ? 'Array' : $w); |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + // eliminer les vides |
|
| 641 | + $url = array_filter($url); |
|
| 642 | + |
|
| 643 | + // recomposer l'adresse |
|
| 644 | + if ($url) { |
|
| 645 | + $a .= '?' . join($sep, $url); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + return $a . $ancre; |
|
| 650 | 649 | } |
| 651 | 650 | |
| 652 | 651 | /** |
@@ -664,21 +663,21 @@ discard block |
||
| 664 | 663 | * @return string |
| 665 | 664 | */ |
| 666 | 665 | function ancre_url($url, $ancre) { |
| 667 | - // lever l'#ancre |
|
| 668 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 669 | - $url = $r[1]; |
|
| 670 | - } |
|
| 671 | - if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 672 | - if (!function_exists('translitteration')) { |
|
| 673 | - include_spip('inc/charsets'); |
|
| 674 | - } |
|
| 675 | - $ancre = preg_replace( |
|
| 676 | - array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'), |
|
| 677 | - array('', '-'), |
|
| 678 | - translitteration($ancre) |
|
| 679 | - ); |
|
| 680 | - } |
|
| 681 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 666 | + // lever l'#ancre |
|
| 667 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 668 | + $url = $r[1]; |
|
| 669 | + } |
|
| 670 | + if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 671 | + if (!function_exists('translitteration')) { |
|
| 672 | + include_spip('inc/charsets'); |
|
| 673 | + } |
|
| 674 | + $ancre = preg_replace( |
|
| 675 | + array('/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'), |
|
| 676 | + array('', '-'), |
|
| 677 | + translitteration($ancre) |
|
| 678 | + ); |
|
| 679 | + } |
|
| 680 | + return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 682 | 681 | } |
| 683 | 682 | |
| 684 | 683 | /** |
@@ -688,16 +687,16 @@ discard block |
||
| 688 | 687 | * @return string |
| 689 | 688 | */ |
| 690 | 689 | function nettoyer_uri($reset = null) { |
| 691 | - static $done = false; |
|
| 692 | - static $propre = ''; |
|
| 693 | - if (!is_null($reset)) { |
|
| 694 | - return $propre = $reset; |
|
| 695 | - } |
|
| 696 | - if ($done) { |
|
| 697 | - return $propre; |
|
| 698 | - } |
|
| 699 | - $done = true; |
|
| 700 | - return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 690 | + static $done = false; |
|
| 691 | + static $propre = ''; |
|
| 692 | + if (!is_null($reset)) { |
|
| 693 | + return $propre = $reset; |
|
| 694 | + } |
|
| 695 | + if ($done) { |
|
| 696 | + return $propre; |
|
| 697 | + } |
|
| 698 | + $done = true; |
|
| 699 | + return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 701 | 700 | } |
| 702 | 701 | |
| 703 | 702 | /** |
@@ -709,13 +708,13 @@ discard block |
||
| 709 | 708 | * @return string |
| 710 | 709 | */ |
| 711 | 710 | function nettoyer_uri_var($request_uri) { |
| 712 | - $uri1 = $request_uri; |
|
| 713 | - do { |
|
| 714 | - $uri = $uri1; |
|
| 715 | - $uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 716 | - '\1', $uri); |
|
| 717 | - } while ($uri <> $uri1); |
|
| 718 | - return preg_replace(',[?&]$,', '', $uri1); |
|
| 711 | + $uri1 = $request_uri; |
|
| 712 | + do { |
|
| 713 | + $uri = $uri1; |
|
| 714 | + $uri1 = preg_replace(',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 715 | + '\1', $uri); |
|
| 716 | + } while ($uri <> $uri1); |
|
| 717 | + return preg_replace(',[?&]$,', '', $uri1); |
|
| 719 | 718 | } |
| 720 | 719 | |
| 721 | 720 | |
@@ -729,47 +728,47 @@ discard block |
||
| 729 | 728 | * URL vers soi-même |
| 730 | 729 | **/ |
| 731 | 730 | function self($amp = '&', $root = false) { |
| 732 | - $url = nettoyer_uri(); |
|
| 733 | - if (!$root |
|
| 734 | - and ( |
|
| 735 | - // si pas de profondeur on peut tronquer |
|
| 736 | - $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 737 | - // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 738 | - or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 739 | - ) { |
|
| 740 | - $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 741 | - } |
|
| 742 | - // ajouter le cas echeant les variables _POST['id_...'] |
|
| 743 | - foreach ($_POST as $v => $c) { |
|
| 744 | - if (substr($v, 0, 3) == 'id_') { |
|
| 745 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 746 | - } |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - // supprimer les variables sans interet |
|
| 750 | - if (test_espace_prive()) { |
|
| 751 | - $url = preg_replace(',([?&])(' |
|
| 752 | - . 'lang|show_docs|' |
|
| 753 | - . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 754 | - $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 755 | - $url = preg_replace(',[&]$,', '\1', $url); |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - // eviter les hacks |
|
| 759 | - include_spip('inc/filtres_mini'); |
|
| 760 | - $url = spip_htmlspecialchars($url); |
|
| 731 | + $url = nettoyer_uri(); |
|
| 732 | + if (!$root |
|
| 733 | + and ( |
|
| 734 | + // si pas de profondeur on peut tronquer |
|
| 735 | + $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 736 | + // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 737 | + or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 738 | + ) { |
|
| 739 | + $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 740 | + } |
|
| 741 | + // ajouter le cas echeant les variables _POST['id_...'] |
|
| 742 | + foreach ($_POST as $v => $c) { |
|
| 743 | + if (substr($v, 0, 3) == 'id_') { |
|
| 744 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + // supprimer les variables sans interet |
|
| 749 | + if (test_espace_prive()) { |
|
| 750 | + $url = preg_replace(',([?&])(' |
|
| 751 | + . 'lang|show_docs|' |
|
| 752 | + . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 753 | + $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 754 | + $url = preg_replace(',[&]$,', '\1', $url); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + // eviter les hacks |
|
| 758 | + include_spip('inc/filtres_mini'); |
|
| 759 | + $url = spip_htmlspecialchars($url); |
|
| 761 | 760 | |
| 762 | - $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url); |
|
| 761 | + $url = str_replace(array("'", '"', '<', '[', ']', ':'), array('%27', '%22', '%3C', '%5B', '%5D', '%3A'), $url); |
|
| 763 | 762 | |
| 764 | - // & ? |
|
| 765 | - if ($amp != '&') { |
|
| 766 | - $url = str_replace('&', $amp, $url); |
|
| 767 | - } |
|
| 763 | + // & ? |
|
| 764 | + if ($amp != '&') { |
|
| 765 | + $url = str_replace('&', $amp, $url); |
|
| 766 | + } |
|
| 768 | 767 | |
| 769 | - // Si ca demarre par ? ou vide, donner './' |
|
| 770 | - $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 768 | + // Si ca demarre par ? ou vide, donner './' |
|
| 769 | + $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 771 | 770 | |
| 772 | - return $url; |
|
| 771 | + return $url; |
|
| 773 | 772 | } |
| 774 | 773 | |
| 775 | 774 | |
@@ -780,7 +779,7 @@ discard block |
||
| 780 | 779 | * true si c'est le cas, false sinon. |
| 781 | 780 | */ |
| 782 | 781 | function test_espace_prive() { |
| 783 | - return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 782 | + return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 784 | 783 | } |
| 785 | 784 | |
| 786 | 785 | /** |
@@ -790,7 +789,7 @@ discard block |
||
| 790 | 789 | * @return bool |
| 791 | 790 | */ |
| 792 | 791 | function test_plugin_actif($plugin) { |
| 793 | - return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 792 | + return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 794 | 793 | } |
| 795 | 794 | |
| 796 | 795 | /** |
@@ -821,51 +820,51 @@ discard block |
||
| 821 | 820 | * Texte |
| 822 | 821 | */ |
| 823 | 822 | function _T($texte, $args = array(), $options = array()) { |
| 824 | - static $traduire = false; |
|
| 825 | - $o = array('class' => '', 'force' => true, 'sanitize' => true); |
|
| 826 | - if ($options) { |
|
| 827 | - // support de l'ancien argument $class |
|
| 828 | - if (is_string($options)) { |
|
| 829 | - $options = array('class' => $options); |
|
| 830 | - } |
|
| 831 | - $o = array_merge($o, $options); |
|
| 832 | - } |
|
| 823 | + static $traduire = false; |
|
| 824 | + $o = array('class' => '', 'force' => true, 'sanitize' => true); |
|
| 825 | + if ($options) { |
|
| 826 | + // support de l'ancien argument $class |
|
| 827 | + if (is_string($options)) { |
|
| 828 | + $options = array('class' => $options); |
|
| 829 | + } |
|
| 830 | + $o = array_merge($o, $options); |
|
| 831 | + } |
|
| 833 | 832 | |
| 834 | - if (!$traduire) { |
|
| 835 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 836 | - include_spip('inc/lang'); |
|
| 837 | - } |
|
| 833 | + if (!$traduire) { |
|
| 834 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 835 | + include_spip('inc/lang'); |
|
| 836 | + } |
|
| 838 | 837 | |
| 839 | - // On peut passer explicitement la langue dans le tableau |
|
| 840 | - // On utilise le même nom de variable que la globale |
|
| 841 | - if (isset($args['spip_lang'])) { |
|
| 842 | - $lang = $args['spip_lang']; |
|
| 843 | - // On l'enleve pour ne pas le passer au remplacement |
|
| 844 | - unset($args['spip_lang']); |
|
| 845 | - } // Sinon on prend la langue du contexte |
|
| 846 | - else { |
|
| 847 | - $lang = $GLOBALS['spip_lang']; |
|
| 848 | - } |
|
| 849 | - $text = $traduire($texte, $lang); |
|
| 838 | + // On peut passer explicitement la langue dans le tableau |
|
| 839 | + // On utilise le même nom de variable que la globale |
|
| 840 | + if (isset($args['spip_lang'])) { |
|
| 841 | + $lang = $args['spip_lang']; |
|
| 842 | + // On l'enleve pour ne pas le passer au remplacement |
|
| 843 | + unset($args['spip_lang']); |
|
| 844 | + } // Sinon on prend la langue du contexte |
|
| 845 | + else { |
|
| 846 | + $lang = $GLOBALS['spip_lang']; |
|
| 847 | + } |
|
| 848 | + $text = $traduire($texte, $lang); |
|
| 850 | 849 | |
| 851 | - if (!strlen($text)) { |
|
| 852 | - if (!$o['force']) { |
|
| 853 | - return ''; |
|
| 854 | - } |
|
| 850 | + if (!strlen($text)) { |
|
| 851 | + if (!$o['force']) { |
|
| 852 | + return ''; |
|
| 853 | + } |
|
| 855 | 854 | |
| 856 | - $text = $texte; |
|
| 855 | + $text = $texte; |
|
| 857 | 856 | |
| 858 | - // pour les chaines non traduites, assurer un service minimum |
|
| 859 | - if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 860 | - $text = str_replace('_', ' ', |
|
| 861 | - (($n = strpos($text, ':')) === false ? $texte : |
|
| 862 | - substr($texte, $n + 1))); |
|
| 863 | - } |
|
| 864 | - $o['class'] = null; |
|
| 857 | + // pour les chaines non traduites, assurer un service minimum |
|
| 858 | + if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 859 | + $text = str_replace('_', ' ', |
|
| 860 | + (($n = strpos($text, ':')) === false ? $texte : |
|
| 861 | + substr($texte, $n + 1))); |
|
| 862 | + } |
|
| 863 | + $o['class'] = null; |
|
| 865 | 864 | |
| 866 | - } |
|
| 865 | + } |
|
| 867 | 866 | |
| 868 | - return _L($text, $args, $o); |
|
| 867 | + return _L($text, $args, $o); |
|
| 869 | 868 | |
| 870 | 869 | } |
| 871 | 870 | |
@@ -893,53 +892,53 @@ discard block |
||
| 893 | 892 | * Texte |
| 894 | 893 | */ |
| 895 | 894 | function _L($text, $args = array(), $options = array()) { |
| 896 | - $f = $text; |
|
| 897 | - $defaut_options = array( |
|
| 898 | - 'class' => null, |
|
| 899 | - 'sanitize' => true, |
|
| 900 | - ); |
|
| 901 | - // support de l'ancien argument $class |
|
| 902 | - if ($options and is_string($options)) { |
|
| 903 | - $options = array('class' => $options); |
|
| 904 | - } |
|
| 905 | - if (is_array($options)) { |
|
| 906 | - $options += $defaut_options; |
|
| 907 | - } else { |
|
| 908 | - $options = $defaut_options; |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - if (is_array($args) and count($args)) { |
|
| 912 | - if (!function_exists('interdire_scripts')) { |
|
| 913 | - include_spip('inc/texte'); |
|
| 914 | - } |
|
| 915 | - if (!function_exists('echapper_html_suspect')) { |
|
| 916 | - include_spip('inc/texte_mini'); |
|
| 917 | - } |
|
| 918 | - foreach ($args as $name => $value) { |
|
| 919 | - if (strpos($text, "@$name@") !== false) { |
|
| 920 | - if ($options['sanitize']) { |
|
| 921 | - $value = echapper_html_suspect($value); |
|
| 922 | - $value = interdire_scripts($value, -1); |
|
| 923 | - } |
|
| 924 | - if (!empty($options['class'])) { |
|
| 925 | - $value = "<span class='".$options['class']."'>$value</span>"; |
|
| 926 | - } |
|
| 927 | - $text = str_replace("@$name@", $value, $text); |
|
| 928 | - unset($args[$name]); |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - // Si des variables n'ont pas ete inserees, le signaler |
|
| 932 | - // (chaines de langues pas a jour) |
|
| 933 | - if ($args) { |
|
| 934 | - spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 935 | - } |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 939 | - return "<span class=debug-traduction-erreur>$text</span>"; |
|
| 940 | - } else { |
|
| 941 | - return $text; |
|
| 942 | - } |
|
| 895 | + $f = $text; |
|
| 896 | + $defaut_options = array( |
|
| 897 | + 'class' => null, |
|
| 898 | + 'sanitize' => true, |
|
| 899 | + ); |
|
| 900 | + // support de l'ancien argument $class |
|
| 901 | + if ($options and is_string($options)) { |
|
| 902 | + $options = array('class' => $options); |
|
| 903 | + } |
|
| 904 | + if (is_array($options)) { |
|
| 905 | + $options += $defaut_options; |
|
| 906 | + } else { |
|
| 907 | + $options = $defaut_options; |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + if (is_array($args) and count($args)) { |
|
| 911 | + if (!function_exists('interdire_scripts')) { |
|
| 912 | + include_spip('inc/texte'); |
|
| 913 | + } |
|
| 914 | + if (!function_exists('echapper_html_suspect')) { |
|
| 915 | + include_spip('inc/texte_mini'); |
|
| 916 | + } |
|
| 917 | + foreach ($args as $name => $value) { |
|
| 918 | + if (strpos($text, "@$name@") !== false) { |
|
| 919 | + if ($options['sanitize']) { |
|
| 920 | + $value = echapper_html_suspect($value); |
|
| 921 | + $value = interdire_scripts($value, -1); |
|
| 922 | + } |
|
| 923 | + if (!empty($options['class'])) { |
|
| 924 | + $value = "<span class='".$options['class']."'>$value</span>"; |
|
| 925 | + } |
|
| 926 | + $text = str_replace("@$name@", $value, $text); |
|
| 927 | + unset($args[$name]); |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + // Si des variables n'ont pas ete inserees, le signaler |
|
| 931 | + // (chaines de langues pas a jour) |
|
| 932 | + if ($args) { |
|
| 933 | + spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 938 | + return "<span class=debug-traduction-erreur>$text</span>"; |
|
| 939 | + } else { |
|
| 940 | + return $text; |
|
| 941 | + } |
|
| 943 | 942 | } |
| 944 | 943 | |
| 945 | 944 | |
@@ -953,13 +952,13 @@ discard block |
||
| 953 | 952 | * @return string |
| 954 | 953 | */ |
| 955 | 954 | function joli_repertoire($rep) { |
| 956 | - $a = substr($rep, 0, 1); |
|
| 957 | - if ($a <> '.' and $a <> '/') { |
|
| 958 | - $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 959 | - } |
|
| 960 | - $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 955 | + $a = substr($rep, 0, 1); |
|
| 956 | + if ($a <> '.' and $a <> '/') { |
|
| 957 | + $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 958 | + } |
|
| 959 | + $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 961 | 960 | |
| 962 | - return $rep; |
|
| 961 | + return $rep; |
|
| 963 | 962 | } |
| 964 | 963 | |
| 965 | 964 | |
@@ -984,33 +983,33 @@ discard block |
||
| 984 | 983 | * @return float|int|string|void |
| 985 | 984 | */ |
| 986 | 985 | function spip_timer($t = 'rien', $raw = false) { |
| 987 | - static $time; |
|
| 988 | - $a = time(); |
|
| 989 | - $b = microtime(); |
|
| 990 | - // microtime peut contenir les microsecondes et le temps |
|
| 991 | - $b = explode(' ', $b); |
|
| 992 | - if (count($b) == 2) { |
|
| 993 | - $a = end($b); |
|
| 994 | - } // plus precis ! |
|
| 995 | - $b = reset($b); |
|
| 996 | - if (!isset($time[$t])) { |
|
| 997 | - $time[$t] = $a + $b; |
|
| 998 | - } else { |
|
| 999 | - $p = ($a + $b - $time[$t]) * 1000; |
|
| 1000 | - unset($time[$t]); |
|
| 986 | + static $time; |
|
| 987 | + $a = time(); |
|
| 988 | + $b = microtime(); |
|
| 989 | + // microtime peut contenir les microsecondes et le temps |
|
| 990 | + $b = explode(' ', $b); |
|
| 991 | + if (count($b) == 2) { |
|
| 992 | + $a = end($b); |
|
| 993 | + } // plus precis ! |
|
| 994 | + $b = reset($b); |
|
| 995 | + if (!isset($time[$t])) { |
|
| 996 | + $time[$t] = $a + $b; |
|
| 997 | + } else { |
|
| 998 | + $p = ($a + $b - $time[$t]) * 1000; |
|
| 999 | + unset($time[$t]); |
|
| 1001 | 1000 | # echo "'$p'";exit; |
| 1002 | - if ($raw) { |
|
| 1003 | - return $p; |
|
| 1004 | - } |
|
| 1005 | - if ($p < 1000) { |
|
| 1006 | - $s = ''; |
|
| 1007 | - } else { |
|
| 1008 | - $s = sprintf("%d ", $x = floor($p / 1000)); |
|
| 1009 | - $p -= ($x * 1000); |
|
| 1010 | - } |
|
| 1001 | + if ($raw) { |
|
| 1002 | + return $p; |
|
| 1003 | + } |
|
| 1004 | + if ($p < 1000) { |
|
| 1005 | + $s = ''; |
|
| 1006 | + } else { |
|
| 1007 | + $s = sprintf("%d ", $x = floor($p / 1000)); |
|
| 1008 | + $p -= ($x * 1000); |
|
| 1009 | + } |
|
| 1011 | 1010 | |
| 1012 | - return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p); |
|
| 1013 | - } |
|
| 1011 | + return $s . sprintf($s ? "%07.3f ms" : "%.3f ms", $p); |
|
| 1012 | + } |
|
| 1014 | 1013 | } |
| 1015 | 1014 | |
| 1016 | 1015 | |
@@ -1018,21 +1017,21 @@ discard block |
||
| 1018 | 1017 | // sinon renvoie True et le date sauf si ca n'est pas souhaite |
| 1019 | 1018 | // https://code.spip.net/@spip_touch |
| 1020 | 1019 | function spip_touch($fichier, $duree = 0, $touch = true) { |
| 1021 | - if ($duree) { |
|
| 1022 | - clearstatcache(); |
|
| 1023 | - if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1024 | - return false; |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1027 | - if ($touch !== false) { |
|
| 1028 | - if (!@touch($fichier)) { |
|
| 1029 | - spip_unlink($fichier); |
|
| 1030 | - @touch($fichier); |
|
| 1031 | - }; |
|
| 1032 | - @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1033 | - } |
|
| 1020 | + if ($duree) { |
|
| 1021 | + clearstatcache(); |
|
| 1022 | + if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1023 | + return false; |
|
| 1024 | + } |
|
| 1025 | + } |
|
| 1026 | + if ($touch !== false) { |
|
| 1027 | + if (!@touch($fichier)) { |
|
| 1028 | + spip_unlink($fichier); |
|
| 1029 | + @touch($fichier); |
|
| 1030 | + }; |
|
| 1031 | + @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1032 | + } |
|
| 1034 | 1033 | |
| 1035 | - return true; |
|
| 1034 | + return true; |
|
| 1036 | 1035 | } |
| 1037 | 1036 | |
| 1038 | 1037 | |
@@ -1044,11 +1043,11 @@ discard block |
||
| 1044 | 1043 | * @uses cron() |
| 1045 | 1044 | **/ |
| 1046 | 1045 | function action_cron() { |
| 1047 | - include_spip('inc/headers'); |
|
| 1048 | - http_status(204); // No Content |
|
| 1049 | - header("Connection: close"); |
|
| 1050 | - define('_DIRECT_CRON_FORCE', true); |
|
| 1051 | - cron(); |
|
| 1046 | + include_spip('inc/headers'); |
|
| 1047 | + http_status(204); // No Content |
|
| 1048 | + header("Connection: close"); |
|
| 1049 | + define('_DIRECT_CRON_FORCE', true); |
|
| 1050 | + cron(); |
|
| 1052 | 1051 | } |
| 1053 | 1052 | |
| 1054 | 1053 | /** |
@@ -1064,26 +1063,26 @@ discard block |
||
| 1064 | 1063 | * True si la tache a pu être effectuée |
| 1065 | 1064 | */ |
| 1066 | 1065 | function cron($taches = array(), $taches_old = array()) { |
| 1067 | - // si pas en mode cron force, laisser tomber. |
|
| 1068 | - if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1069 | - return false; |
|
| 1070 | - } |
|
| 1071 | - if (!is_array($taches)) { |
|
| 1072 | - $taches = $taches_old; |
|
| 1073 | - } // compat anciens appels |
|
| 1074 | - // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1075 | - // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1076 | - // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1077 | - // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1078 | - if ($taches and count($taches) and !spip_connect()) { |
|
| 1079 | - return false; |
|
| 1080 | - } |
|
| 1081 | - spip_log("cron !", 'jq' . _LOG_DEBUG); |
|
| 1082 | - if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1083 | - return $genie($taches); |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - return false; |
|
| 1066 | + // si pas en mode cron force, laisser tomber. |
|
| 1067 | + if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1068 | + return false; |
|
| 1069 | + } |
|
| 1070 | + if (!is_array($taches)) { |
|
| 1071 | + $taches = $taches_old; |
|
| 1072 | + } // compat anciens appels |
|
| 1073 | + // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1074 | + // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1075 | + // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1076 | + // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1077 | + if ($taches and count($taches) and !spip_connect()) { |
|
| 1078 | + return false; |
|
| 1079 | + } |
|
| 1080 | + spip_log("cron !", 'jq' . _LOG_DEBUG); |
|
| 1081 | + if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1082 | + return $genie($taches); |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + return false; |
|
| 1087 | 1086 | } |
| 1088 | 1087 | |
| 1089 | 1088 | /** |
@@ -1115,17 +1114,17 @@ discard block |
||
| 1115 | 1114 | * Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté. |
| 1116 | 1115 | */ |
| 1117 | 1116 | function job_queue_add( |
| 1118 | - $function, |
|
| 1119 | - $description, |
|
| 1120 | - $arguments = array(), |
|
| 1121 | - $file = '', |
|
| 1122 | - $no_duplicate = false, |
|
| 1123 | - $time = 0, |
|
| 1124 | - $priority = 0 |
|
| 1117 | + $function, |
|
| 1118 | + $description, |
|
| 1119 | + $arguments = array(), |
|
| 1120 | + $file = '', |
|
| 1121 | + $no_duplicate = false, |
|
| 1122 | + $time = 0, |
|
| 1123 | + $priority = 0 |
|
| 1125 | 1124 | ) { |
| 1126 | - include_spip('inc/queue'); |
|
| 1125 | + include_spip('inc/queue'); |
|
| 1127 | 1126 | |
| 1128 | - return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1127 | + return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1129 | 1128 | } |
| 1130 | 1129 | |
| 1131 | 1130 | /** |
@@ -1136,9 +1135,9 @@ discard block |
||
| 1136 | 1135 | * @return bool |
| 1137 | 1136 | */ |
| 1138 | 1137 | function job_queue_remove($id_job) { |
| 1139 | - include_spip('inc/queue'); |
|
| 1138 | + include_spip('inc/queue'); |
|
| 1140 | 1139 | |
| 1141 | - return queue_remove_job($id_job); |
|
| 1140 | + return queue_remove_job($id_job); |
|
| 1142 | 1141 | } |
| 1143 | 1142 | |
| 1144 | 1143 | /** |
@@ -1151,9 +1150,9 @@ discard block |
||
| 1151 | 1150 | * or an array of simple array to link multiples objet in one time |
| 1152 | 1151 | */ |
| 1153 | 1152 | function job_queue_link($id_job, $objets) { |
| 1154 | - include_spip('inc/queue'); |
|
| 1153 | + include_spip('inc/queue'); |
|
| 1155 | 1154 | |
| 1156 | - return queue_link_job($id_job, $objets); |
|
| 1155 | + return queue_link_job($id_job, $objets); |
|
| 1157 | 1156 | } |
| 1158 | 1157 | |
| 1159 | 1158 | |
@@ -1173,36 +1172,36 @@ discard block |
||
| 1173 | 1172 | * - `null` si la queue n'est pas encore initialisée |
| 1174 | 1173 | */ |
| 1175 | 1174 | function queue_sleep_time_to_next_job($force = null) { |
| 1176 | - static $queue_next_job_time = -1; |
|
| 1177 | - if ($force === true) { |
|
| 1178 | - $queue_next_job_time = -1; |
|
| 1179 | - } elseif ($force) { |
|
| 1180 | - $queue_next_job_time = $force; |
|
| 1181 | - } |
|
| 1182 | - |
|
| 1183 | - if ($queue_next_job_time == -1) { |
|
| 1184 | - if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1185 | - define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt"); |
|
| 1186 | - } |
|
| 1187 | - // utiliser un cache memoire si dispo |
|
| 1188 | - if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1189 | - $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1190 | - } else { |
|
| 1191 | - $queue_next_job_time = null; |
|
| 1192 | - if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1193 | - $queue_next_job_time = intval($contenu); |
|
| 1194 | - } |
|
| 1195 | - } |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - if (is_null($queue_next_job_time)) { |
|
| 1199 | - return null; |
|
| 1200 | - } |
|
| 1201 | - if (!$_SERVER['REQUEST_TIME']) { |
|
| 1202 | - $_SERVER['REQUEST_TIME'] = time(); |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1175 | + static $queue_next_job_time = -1; |
|
| 1176 | + if ($force === true) { |
|
| 1177 | + $queue_next_job_time = -1; |
|
| 1178 | + } elseif ($force) { |
|
| 1179 | + $queue_next_job_time = $force; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + if ($queue_next_job_time == -1) { |
|
| 1183 | + if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1184 | + define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . "job_queue_next.txt"); |
|
| 1185 | + } |
|
| 1186 | + // utiliser un cache memoire si dispo |
|
| 1187 | + if (function_exists("cache_get") and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1188 | + $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1189 | + } else { |
|
| 1190 | + $queue_next_job_time = null; |
|
| 1191 | + if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1192 | + $queue_next_job_time = intval($contenu); |
|
| 1193 | + } |
|
| 1194 | + } |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + if (is_null($queue_next_job_time)) { |
|
| 1198 | + return null; |
|
| 1199 | + } |
|
| 1200 | + if (!$_SERVER['REQUEST_TIME']) { |
|
| 1201 | + $_SERVER['REQUEST_TIME'] = time(); |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1206 | 1205 | } |
| 1207 | 1206 | |
| 1208 | 1207 | |
@@ -1214,9 +1213,9 @@ discard block |
||
| 1214 | 1213 | * @return string |
| 1215 | 1214 | */ |
| 1216 | 1215 | function quote_amp($u) { |
| 1217 | - return preg_replace( |
|
| 1218 | - "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i", |
|
| 1219 | - "&", $u); |
|
| 1216 | + return preg_replace( |
|
| 1217 | + "/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i", |
|
| 1218 | + "&", $u); |
|
| 1220 | 1219 | } |
| 1221 | 1220 | |
| 1222 | 1221 | |
@@ -1239,27 +1238,27 @@ discard block |
||
| 1239 | 1238 | * Balise HTML `<script>` et son contenu |
| 1240 | 1239 | **/ |
| 1241 | 1240 | function http_script($script, $src = '', $noscript = '') { |
| 1242 | - static $done = array(); |
|
| 1241 | + static $done = array(); |
|
| 1243 | 1242 | |
| 1244 | - if ($src && !isset($done[$src])) { |
|
| 1245 | - $done[$src] = true; |
|
| 1246 | - $src = find_in_path($src, _JAVASCRIPT); |
|
| 1247 | - $src = " src='$src'"; |
|
| 1248 | - } else { |
|
| 1249 | - $src = ''; |
|
| 1250 | - } |
|
| 1251 | - if ($script) { |
|
| 1252 | - $script = ("/*<![CDATA[*/\n" . |
|
| 1253 | - preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1254 | - "/*]]>*/"); |
|
| 1255 | - } |
|
| 1256 | - if ($noscript) { |
|
| 1257 | - $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1258 | - } |
|
| 1243 | + if ($src && !isset($done[$src])) { |
|
| 1244 | + $done[$src] = true; |
|
| 1245 | + $src = find_in_path($src, _JAVASCRIPT); |
|
| 1246 | + $src = " src='$src'"; |
|
| 1247 | + } else { |
|
| 1248 | + $src = ''; |
|
| 1249 | + } |
|
| 1250 | + if ($script) { |
|
| 1251 | + $script = ("/*<![CDATA[*/\n" . |
|
| 1252 | + preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1253 | + "/*]]>*/"); |
|
| 1254 | + } |
|
| 1255 | + if ($noscript) { |
|
| 1256 | + $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1257 | + } |
|
| 1259 | 1258 | |
| 1260 | - return ($src or $script or $noscript) |
|
| 1261 | - ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1262 | - : ''; |
|
| 1259 | + return ($src or $script or $noscript) |
|
| 1260 | + ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1261 | + : ''; |
|
| 1263 | 1262 | } |
| 1264 | 1263 | |
| 1265 | 1264 | |
@@ -1294,7 +1293,7 @@ discard block |
||
| 1294 | 1293 | * Texte échappé |
| 1295 | 1294 | **/ |
| 1296 | 1295 | function texte_script($texte) { |
| 1297 | - return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1296 | + return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1298 | 1297 | } |
| 1299 | 1298 | |
| 1300 | 1299 | |
@@ -1331,68 +1330,68 @@ discard block |
||
| 1331 | 1330 | * Liste des chemins, par ordre de priorité. |
| 1332 | 1331 | **/ |
| 1333 | 1332 | function _chemin($dir_path = null) { |
| 1334 | - static $path_base = null; |
|
| 1335 | - static $path_full = null; |
|
| 1336 | - if ($path_base == null) { |
|
| 1337 | - // Chemin standard depuis l'espace public |
|
| 1338 | - $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1339 | - _DIR_RACINE . ':' . |
|
| 1340 | - _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1341 | - _DIR_RACINE . 'prive/:' . |
|
| 1342 | - _DIR_RESTREINT; |
|
| 1343 | - // Ajouter squelettes/ |
|
| 1344 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1345 | - $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1346 | - } |
|
| 1347 | - foreach (explode(':', $path) as $dir) { |
|
| 1348 | - if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1349 | - $dir .= "/"; |
|
| 1350 | - } |
|
| 1351 | - $path_base[] = $dir; |
|
| 1352 | - } |
|
| 1353 | - $path_full = $path_base; |
|
| 1354 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1355 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1356 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1357 | - array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1358 | - } |
|
| 1359 | - } |
|
| 1360 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1361 | - } |
|
| 1362 | - if ($dir_path === null) { |
|
| 1363 | - return $path_full; |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1367 | - $tete = ""; |
|
| 1368 | - if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1369 | - $tete = array_shift($path_base); |
|
| 1370 | - } |
|
| 1371 | - $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1372 | - $dirs = array_reverse($dirs); |
|
| 1373 | - foreach ($dirs as $dir_path) { |
|
| 1374 | - if (substr($dir_path, -1) != '/') { |
|
| 1375 | - $dir_path .= "/"; |
|
| 1376 | - } |
|
| 1377 | - if (!in_array($dir_path, $path_base)) { |
|
| 1378 | - array_unshift($path_base, $dir_path); |
|
| 1379 | - } |
|
| 1380 | - } |
|
| 1381 | - if (strlen($tete)) { |
|
| 1382 | - array_unshift($path_base, $tete); |
|
| 1383 | - } |
|
| 1384 | - } |
|
| 1385 | - $path_full = $path_base; |
|
| 1386 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1387 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1388 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1389 | - array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1390 | - } |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1394 | - |
|
| 1395 | - return $path_full; |
|
| 1333 | + static $path_base = null; |
|
| 1334 | + static $path_full = null; |
|
| 1335 | + if ($path_base == null) { |
|
| 1336 | + // Chemin standard depuis l'espace public |
|
| 1337 | + $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1338 | + _DIR_RACINE . ':' . |
|
| 1339 | + _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1340 | + _DIR_RACINE . 'prive/:' . |
|
| 1341 | + _DIR_RESTREINT; |
|
| 1342 | + // Ajouter squelettes/ |
|
| 1343 | + if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1344 | + $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1345 | + } |
|
| 1346 | + foreach (explode(':', $path) as $dir) { |
|
| 1347 | + if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1348 | + $dir .= "/"; |
|
| 1349 | + } |
|
| 1350 | + $path_base[] = $dir; |
|
| 1351 | + } |
|
| 1352 | + $path_full = $path_base; |
|
| 1353 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1354 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1355 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1356 | + array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1360 | + } |
|
| 1361 | + if ($dir_path === null) { |
|
| 1362 | + return $path_full; |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1366 | + $tete = ""; |
|
| 1367 | + if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1368 | + $tete = array_shift($path_base); |
|
| 1369 | + } |
|
| 1370 | + $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1371 | + $dirs = array_reverse($dirs); |
|
| 1372 | + foreach ($dirs as $dir_path) { |
|
| 1373 | + if (substr($dir_path, -1) != '/') { |
|
| 1374 | + $dir_path .= "/"; |
|
| 1375 | + } |
|
| 1376 | + if (!in_array($dir_path, $path_base)) { |
|
| 1377 | + array_unshift($path_base, $dir_path); |
|
| 1378 | + } |
|
| 1379 | + } |
|
| 1380 | + if (strlen($tete)) { |
|
| 1381 | + array_unshift($path_base, $tete); |
|
| 1382 | + } |
|
| 1383 | + } |
|
| 1384 | + $path_full = $path_base; |
|
| 1385 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1386 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1387 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1388 | + array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1389 | + } |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1393 | + |
|
| 1394 | + return $path_full; |
|
| 1396 | 1395 | } |
| 1397 | 1396 | |
| 1398 | 1397 | /** |
@@ -1405,76 +1404,76 @@ discard block |
||
| 1405 | 1404 | * @return array Liste de chemins |
| 1406 | 1405 | **/ |
| 1407 | 1406 | function creer_chemin() { |
| 1408 | - $path_a = _chemin(); |
|
| 1409 | - static $c = ''; |
|
| 1407 | + $path_a = _chemin(); |
|
| 1408 | + static $c = ''; |
|
| 1410 | 1409 | |
| 1411 | - // on calcule le chemin si le dossier skel a change |
|
| 1412 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1413 | - // assurer le non plantage lors de la montee de version : |
|
| 1414 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1415 | - $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1416 | - } |
|
| 1410 | + // on calcule le chemin si le dossier skel a change |
|
| 1411 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1412 | + // assurer le non plantage lors de la montee de version : |
|
| 1413 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1414 | + $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1415 | + } |
|
| 1417 | 1416 | |
| 1418 | - return $path_a; |
|
| 1417 | + return $path_a; |
|
| 1419 | 1418 | } |
| 1420 | 1419 | |
| 1421 | 1420 | |
| 1422 | 1421 | function lister_themes_prives() { |
| 1423 | - static $themes = null; |
|
| 1424 | - if (is_null($themes)) { |
|
| 1425 | - // si pas encore definie |
|
| 1426 | - if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1427 | - define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1428 | - } |
|
| 1429 | - $themes = array(_SPIP_THEME_PRIVE); |
|
| 1430 | - // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1431 | - if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1432 | - $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1433 | - } else { |
|
| 1434 | - $prefs = array(); |
|
| 1435 | - } |
|
| 1436 | - if (is_string($prefs)) { |
|
| 1437 | - $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1438 | - } |
|
| 1439 | - if ( |
|
| 1440 | - ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1441 | - or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1442 | - and $theme != _SPIP_THEME_PRIVE |
|
| 1443 | - ) { |
|
| 1444 | - array_unshift($themes, $theme); |
|
| 1445 | - } // placer le theme choisi en tete |
|
| 1446 | - } |
|
| 1447 | - |
|
| 1448 | - return $themes; |
|
| 1422 | + static $themes = null; |
|
| 1423 | + if (is_null($themes)) { |
|
| 1424 | + // si pas encore definie |
|
| 1425 | + if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1426 | + define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1427 | + } |
|
| 1428 | + $themes = array(_SPIP_THEME_PRIVE); |
|
| 1429 | + // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1430 | + if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1431 | + $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1432 | + } else { |
|
| 1433 | + $prefs = array(); |
|
| 1434 | + } |
|
| 1435 | + if (is_string($prefs)) { |
|
| 1436 | + $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1437 | + } |
|
| 1438 | + if ( |
|
| 1439 | + ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1440 | + or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1441 | + and $theme != _SPIP_THEME_PRIVE |
|
| 1442 | + ) { |
|
| 1443 | + array_unshift($themes, $theme); |
|
| 1444 | + } // placer le theme choisi en tete |
|
| 1445 | + } |
|
| 1446 | + |
|
| 1447 | + return $themes; |
|
| 1449 | 1448 | } |
| 1450 | 1449 | |
| 1451 | 1450 | function find_in_theme($file, $subdir = '', $include = false) { |
| 1452 | - static $themefiles = array(); |
|
| 1453 | - if (isset($themefiles["$subdir$file"])) { |
|
| 1454 | - return $themefiles["$subdir$file"]; |
|
| 1455 | - } |
|
| 1456 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1457 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1458 | - if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1459 | - and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg" |
|
| 1460 | - and $f = find_in_theme("$file_svg_generique")) { |
|
| 1461 | - if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) { |
|
| 1462 | - return $themefiles["$subdir$file"] = $fsize; |
|
| 1463 | - } |
|
| 1464 | - else { |
|
| 1465 | - return $themefiles["$subdir$file"] = "$f?".$m[1]."px"; |
|
| 1466 | - } |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - $themes = lister_themes_prives(); |
|
| 1470 | - foreach ($themes as $theme) { |
|
| 1471 | - if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1472 | - return $themefiles["$subdir$file"] = $f; |
|
| 1473 | - } |
|
| 1474 | - } |
|
| 1475 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1476 | - |
|
| 1477 | - return $themefiles["$subdir$file"] = ""; |
|
| 1451 | + static $themefiles = array(); |
|
| 1452 | + if (isset($themefiles["$subdir$file"])) { |
|
| 1453 | + return $themefiles["$subdir$file"]; |
|
| 1454 | + } |
|
| 1455 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1456 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1457 | + if (preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1458 | + and $file_svg_generique = substr($file,0, -strlen($m[0])) . "-xx.svg" |
|
| 1459 | + and $f = find_in_theme("$file_svg_generique")) { |
|
| 1460 | + if ($fsize = substr($f,0,-6) . $m[1] . ".svg" and file_exists($fsize)) { |
|
| 1461 | + return $themefiles["$subdir$file"] = $fsize; |
|
| 1462 | + } |
|
| 1463 | + else { |
|
| 1464 | + return $themefiles["$subdir$file"] = "$f?".$m[1]."px"; |
|
| 1465 | + } |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + $themes = lister_themes_prives(); |
|
| 1469 | + foreach ($themes as $theme) { |
|
| 1470 | + if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1471 | + return $themefiles["$subdir$file"] = $f; |
|
| 1472 | + } |
|
| 1473 | + } |
|
| 1474 | + spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1475 | + |
|
| 1476 | + return $themefiles["$subdir$file"] = ""; |
|
| 1478 | 1477 | } |
| 1479 | 1478 | |
| 1480 | 1479 | |
@@ -1498,31 +1497,31 @@ discard block |
||
| 1498 | 1497 | * sinon chaîne vide. |
| 1499 | 1498 | **/ |
| 1500 | 1499 | function chemin_image($icone) { |
| 1501 | - static $icone_renommer; |
|
| 1502 | - if ($p = strpos($icone, '?')) { |
|
| 1503 | - $icone = substr($icone,0, $p); |
|
| 1504 | - } |
|
| 1505 | - // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1506 | - if (strpos($icone, "/") !== false and file_exists($icone)) { |
|
| 1507 | - return $icone; |
|
| 1508 | - } |
|
| 1509 | - |
|
| 1510 | - // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1511 | - if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1512 | - return $f; |
|
| 1513 | - } |
|
| 1514 | - // sinon passer par le module de renommage |
|
| 1515 | - if (is_null($icone_renommer)) { |
|
| 1516 | - $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1517 | - } |
|
| 1518 | - if ($icone_renommer) { |
|
| 1519 | - list($icone, $fonction) = $icone_renommer($icone, ""); |
|
| 1520 | - if (file_exists($icone)) { |
|
| 1521 | - return $icone; |
|
| 1522 | - } |
|
| 1523 | - } |
|
| 1524 | - |
|
| 1525 | - return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1500 | + static $icone_renommer; |
|
| 1501 | + if ($p = strpos($icone, '?')) { |
|
| 1502 | + $icone = substr($icone,0, $p); |
|
| 1503 | + } |
|
| 1504 | + // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1505 | + if (strpos($icone, "/") !== false and file_exists($icone)) { |
|
| 1506 | + return $icone; |
|
| 1507 | + } |
|
| 1508 | + |
|
| 1509 | + // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1510 | + if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1511 | + return $f; |
|
| 1512 | + } |
|
| 1513 | + // sinon passer par le module de renommage |
|
| 1514 | + if (is_null($icone_renommer)) { |
|
| 1515 | + $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1516 | + } |
|
| 1517 | + if ($icone_renommer) { |
|
| 1518 | + list($icone, $fonction) = $icone_renommer($icone, ""); |
|
| 1519 | + if (file_exists($icone)) { |
|
| 1520 | + return $icone; |
|
| 1521 | + } |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1526 | 1525 | } |
| 1527 | 1526 | |
| 1528 | 1527 | // |
@@ -1560,127 +1559,127 @@ discard block |
||
| 1560 | 1559 | * - false : fichier introuvable |
| 1561 | 1560 | **/ |
| 1562 | 1561 | function find_in_path($file, $dirname = '', $include = false) { |
| 1563 | - static $dirs = array(); |
|
| 1564 | - static $inc = array(); # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1565 | - static $c = ''; |
|
| 1566 | - |
|
| 1567 | - if (!$file and !strlen($file)) { |
|
| 1568 | - return false; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - // on calcule le chemin si le dossier skel a change |
|
| 1572 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1573 | - // assurer le non plantage lors de la montee de version : |
|
| 1574 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1575 | - creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1576 | - } |
|
| 1577 | - |
|
| 1578 | - if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1579 | - if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1580 | - return false; |
|
| 1581 | - } |
|
| 1582 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1583 | - include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1584 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - $a = strrpos($file, '/'); |
|
| 1591 | - if ($a !== false) { |
|
| 1592 | - $dirname .= substr($file, 0, ++$a); |
|
| 1593 | - $file = substr($file, $a); |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - foreach (creer_chemin() as $dir) { |
|
| 1597 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1598 | - $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1599 | - } |
|
| 1600 | - if ($dirs[$a]) { |
|
| 1601 | - if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1602 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1603 | - include_once _ROOT_CWD . $a; |
|
| 1604 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1605 | - } |
|
| 1606 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1607 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1608 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1609 | - return $a; |
|
| 1610 | - } |
|
| 1611 | - define('_SAUVER_CHEMIN', true); |
|
| 1612 | - } |
|
| 1613 | - |
|
| 1614 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1615 | - } |
|
| 1616 | - } |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - if ($include) { |
|
| 1620 | - spip_log("include_spip $dirname$file non trouve"); |
|
| 1621 | - if ($include === 'required') { |
|
| 1622 | - echo '<pre>', |
|
| 1623 | - "<strong>Erreur Fatale</strong><br />"; |
|
| 1624 | - if (function_exists('debug_print_backtrace')) { |
|
| 1625 | - echo debug_print_backtrace(); |
|
| 1626 | - } |
|
| 1627 | - echo '</pre>'; |
|
| 1628 | - die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1629 | - } |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1633 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1634 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1635 | - return false; |
|
| 1636 | - } |
|
| 1637 | - define('_SAUVER_CHEMIN', true); |
|
| 1638 | - } |
|
| 1639 | - |
|
| 1640 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1562 | + static $dirs = array(); |
|
| 1563 | + static $inc = array(); # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1564 | + static $c = ''; |
|
| 1565 | + |
|
| 1566 | + if (!$file and !strlen($file)) { |
|
| 1567 | + return false; |
|
| 1568 | + } |
|
| 1569 | + |
|
| 1570 | + // on calcule le chemin si le dossier skel a change |
|
| 1571 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1572 | + // assurer le non plantage lors de la montee de version : |
|
| 1573 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1574 | + creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1575 | + } |
|
| 1576 | + |
|
| 1577 | + if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1578 | + if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1579 | + return false; |
|
| 1580 | + } |
|
| 1581 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1582 | + include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1583 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1587 | + } |
|
| 1588 | + |
|
| 1589 | + $a = strrpos($file, '/'); |
|
| 1590 | + if ($a !== false) { |
|
| 1591 | + $dirname .= substr($file, 0, ++$a); |
|
| 1592 | + $file = substr($file, $a); |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + foreach (creer_chemin() as $dir) { |
|
| 1596 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1597 | + $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1598 | + } |
|
| 1599 | + if ($dirs[$a]) { |
|
| 1600 | + if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1601 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1602 | + include_once _ROOT_CWD . $a; |
|
| 1603 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1604 | + } |
|
| 1605 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1606 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1607 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1608 | + return $a; |
|
| 1609 | + } |
|
| 1610 | + define('_SAUVER_CHEMIN', true); |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1614 | + } |
|
| 1615 | + } |
|
| 1616 | + } |
|
| 1617 | + |
|
| 1618 | + if ($include) { |
|
| 1619 | + spip_log("include_spip $dirname$file non trouve"); |
|
| 1620 | + if ($include === 'required') { |
|
| 1621 | + echo '<pre>', |
|
| 1622 | + "<strong>Erreur Fatale</strong><br />"; |
|
| 1623 | + if (function_exists('debug_print_backtrace')) { |
|
| 1624 | + echo debug_print_backtrace(); |
|
| 1625 | + } |
|
| 1626 | + echo '</pre>'; |
|
| 1627 | + die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1628 | + } |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1632 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1633 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1634 | + return false; |
|
| 1635 | + } |
|
| 1636 | + define('_SAUVER_CHEMIN', true); |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1641 | 1640 | } |
| 1642 | 1641 | |
| 1643 | 1642 | function clear_path_cache() { |
| 1644 | - $GLOBALS['path_files'] = array(); |
|
| 1645 | - spip_unlink(_CACHE_CHEMIN); |
|
| 1643 | + $GLOBALS['path_files'] = array(); |
|
| 1644 | + spip_unlink(_CACHE_CHEMIN); |
|
| 1646 | 1645 | } |
| 1647 | 1646 | |
| 1648 | 1647 | function load_path_cache() { |
| 1649 | - // charger le path des plugins |
|
| 1650 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1651 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1652 | - } |
|
| 1653 | - $GLOBALS['path_files'] = array(); |
|
| 1654 | - // si le visiteur est admin, |
|
| 1655 | - // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1656 | - if ( |
|
| 1657 | - // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1658 | - //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1659 | - // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1660 | - // on blinde par un second test au moment de la lecture de la session |
|
| 1661 | - // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1662 | - // et en ignorant ce cache en cas de recalcul explicite |
|
| 1663 | - !_request('var_mode') |
|
| 1664 | - ) { |
|
| 1665 | - // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1666 | - if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1667 | - // mais si semble corrompu on relit avec un verrou |
|
| 1668 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1669 | - lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1670 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1671 | - $GLOBALS['path_files'] = array(); |
|
| 1672 | - } |
|
| 1673 | - } |
|
| 1674 | - } |
|
| 1675 | - } |
|
| 1648 | + // charger le path des plugins |
|
| 1649 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1650 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1651 | + } |
|
| 1652 | + $GLOBALS['path_files'] = array(); |
|
| 1653 | + // si le visiteur est admin, |
|
| 1654 | + // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1655 | + if ( |
|
| 1656 | + // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1657 | + //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1658 | + // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1659 | + // on blinde par un second test au moment de la lecture de la session |
|
| 1660 | + // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1661 | + // et en ignorant ce cache en cas de recalcul explicite |
|
| 1662 | + !_request('var_mode') |
|
| 1663 | + ) { |
|
| 1664 | + // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1665 | + if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1666 | + // mais si semble corrompu on relit avec un verrou |
|
| 1667 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1668 | + lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1669 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1670 | + $GLOBALS['path_files'] = array(); |
|
| 1671 | + } |
|
| 1672 | + } |
|
| 1673 | + } |
|
| 1674 | + } |
|
| 1676 | 1675 | } |
| 1677 | 1676 | |
| 1678 | 1677 | function save_path_cache() { |
| 1679 | - if (defined('_SAUVER_CHEMIN') |
|
| 1680 | - and _SAUVER_CHEMIN |
|
| 1681 | - ) { |
|
| 1682 | - ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1683 | - } |
|
| 1678 | + if (defined('_SAUVER_CHEMIN') |
|
| 1679 | + and _SAUVER_CHEMIN |
|
| 1680 | + ) { |
|
| 1681 | + ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1682 | + } |
|
| 1684 | 1683 | } |
| 1685 | 1684 | |
| 1686 | 1685 | |
@@ -1700,33 +1699,33 @@ discard block |
||
| 1700 | 1699 | * @return array |
| 1701 | 1700 | */ |
| 1702 | 1701 | function find_all_in_path($dir, $pattern, $recurs = false) { |
| 1703 | - $liste_fichiers = array(); |
|
| 1704 | - $maxfiles = 10000; |
|
| 1705 | - |
|
| 1706 | - // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1707 | - // on a pas encore inclus flock.php |
|
| 1708 | - if (!function_exists('preg_files')) { |
|
| 1709 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1710 | - } |
|
| 1711 | - |
|
| 1712 | - // Parcourir le chemin |
|
| 1713 | - foreach (creer_chemin() as $d) { |
|
| 1714 | - $f = $d . $dir; |
|
| 1715 | - if (@is_dir($f)) { |
|
| 1716 | - $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs); |
|
| 1717 | - foreach ($liste as $chemin) { |
|
| 1718 | - $nom = basename($chemin); |
|
| 1719 | - // ne prendre que les fichiers pas deja trouves |
|
| 1720 | - // car find_in_path prend le premier qu'il trouve, |
|
| 1721 | - // les autres sont donc masques |
|
| 1722 | - if (!isset($liste_fichiers[$nom])) { |
|
| 1723 | - $liste_fichiers[$nom] = $chemin; |
|
| 1724 | - } |
|
| 1725 | - } |
|
| 1726 | - } |
|
| 1727 | - } |
|
| 1728 | - |
|
| 1729 | - return $liste_fichiers; |
|
| 1702 | + $liste_fichiers = array(); |
|
| 1703 | + $maxfiles = 10000; |
|
| 1704 | + |
|
| 1705 | + // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1706 | + // on a pas encore inclus flock.php |
|
| 1707 | + if (!function_exists('preg_files')) { |
|
| 1708 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + // Parcourir le chemin |
|
| 1712 | + foreach (creer_chemin() as $d) { |
|
| 1713 | + $f = $d . $dir; |
|
| 1714 | + if (@is_dir($f)) { |
|
| 1715 | + $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? array() : $recurs); |
|
| 1716 | + foreach ($liste as $chemin) { |
|
| 1717 | + $nom = basename($chemin); |
|
| 1718 | + // ne prendre que les fichiers pas deja trouves |
|
| 1719 | + // car find_in_path prend le premier qu'il trouve, |
|
| 1720 | + // les autres sont donc masques |
|
| 1721 | + if (!isset($liste_fichiers[$nom])) { |
|
| 1722 | + $liste_fichiers[$nom] = $chemin; |
|
| 1723 | + } |
|
| 1724 | + } |
|
| 1725 | + } |
|
| 1726 | + } |
|
| 1727 | + |
|
| 1728 | + return $liste_fichiers; |
|
| 1730 | 1729 | } |
| 1731 | 1730 | |
| 1732 | 1731 | /** |
@@ -1738,17 +1737,17 @@ discard block |
||
| 1738 | 1737 | * @return bool |
| 1739 | 1738 | */ |
| 1740 | 1739 | function autoriser_sans_cookie($nom, $strict = false) { |
| 1741 | - static $autsanscookie = array('install', 'base_repair'); |
|
| 1740 | + static $autsanscookie = array('install', 'base_repair'); |
|
| 1742 | 1741 | |
| 1743 | - if (in_array($nom, $autsanscookie)) { |
|
| 1744 | - if (test_espace_prive()){ |
|
| 1745 | - include_spip('base/connect_sql'); |
|
| 1746 | - if (!$strict or !spip_connect()){ |
|
| 1747 | - return true; |
|
| 1748 | - } |
|
| 1749 | - } |
|
| 1750 | - } |
|
| 1751 | - return false; |
|
| 1742 | + if (in_array($nom, $autsanscookie)) { |
|
| 1743 | + if (test_espace_prive()){ |
|
| 1744 | + include_spip('base/connect_sql'); |
|
| 1745 | + if (!$strict or !spip_connect()){ |
|
| 1746 | + return true; |
|
| 1747 | + } |
|
| 1748 | + } |
|
| 1749 | + } |
|
| 1750 | + return false; |
|
| 1752 | 1751 | } |
| 1753 | 1752 | |
| 1754 | 1753 | /** |
@@ -1774,99 +1773,99 @@ discard block |
||
| 1774 | 1773 | * (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip) |
| 1775 | 1774 | */ |
| 1776 | 1775 | function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) { |
| 1777 | - if ($public === null) { |
|
| 1778 | - $public = !test_espace_prive(); |
|
| 1779 | - } |
|
| 1780 | - $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1781 | - |
|
| 1782 | - if (!$public) { |
|
| 1783 | - if (!$entite) { |
|
| 1784 | - return ''; |
|
| 1785 | - } |
|
| 1786 | - if (!function_exists('generer_url_ecrire_objet')) { |
|
| 1787 | - include_spip('inc/urls'); |
|
| 1788 | - } |
|
| 1789 | - $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false); |
|
| 1790 | - } else { |
|
| 1791 | - if ($type === null) { |
|
| 1792 | - $type = (isset($GLOBALS['type_urls'])) |
|
| 1793 | - ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options |
|
| 1794 | - : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues |
|
| 1795 | - ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut |
|
| 1796 | - } |
|
| 1797 | - |
|
| 1798 | - $f = charger_fonction($type, 'urls', true); |
|
| 1799 | - // se rabattre sur les urls page si les urls perso non dispo |
|
| 1800 | - if (!$f) { |
|
| 1801 | - $f = charger_fonction('page', 'urls', true); |
|
| 1802 | - } |
|
| 1803 | - |
|
| 1804 | - // si $entite='', on veut la fonction de passage URL ==> id |
|
| 1805 | - // sinon on veut effectuer le passage id ==> URL |
|
| 1806 | - if (!$entite) { |
|
| 1807 | - return $f; |
|
| 1808 | - } |
|
| 1809 | - |
|
| 1810 | - // mais d'abord il faut tester le cas des urls sur une |
|
| 1811 | - // base distante |
|
| 1812 | - if (is_string($public) |
|
| 1813 | - and $g = charger_fonction('connect', 'urls', true) |
|
| 1814 | - ) { |
|
| 1815 | - $f = $g; |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - $res = $f(intval($id), $entite, $args, $ancre, $public); |
|
| 1819 | - |
|
| 1820 | - } |
|
| 1821 | - if ($res) { |
|
| 1822 | - return $res; |
|
| 1823 | - } |
|
| 1824 | - // Sinon c'est un raccourci ou compat SPIP < 2 |
|
| 1825 | - if (!function_exists($f = 'generer_url_' . $entite)) { |
|
| 1826 | - if (!function_exists($f .= '_dist')) { |
|
| 1827 | - $f = ''; |
|
| 1828 | - } |
|
| 1829 | - } |
|
| 1830 | - if ($f) { |
|
| 1831 | - $url = $f($id, $args, $ancre); |
|
| 1832 | - if (strlen($args)) { |
|
| 1833 | - $url .= strstr($url, '?') |
|
| 1834 | - ? '&' . $args |
|
| 1835 | - : '?' . $args; |
|
| 1836 | - } |
|
| 1837 | - |
|
| 1838 | - return $url; |
|
| 1839 | - } |
|
| 1840 | - // On a ete gentil mais la .... |
|
| 1841 | - spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public"); |
|
| 1842 | - |
|
| 1843 | - return ''; |
|
| 1776 | + if ($public === null) { |
|
| 1777 | + $public = !test_espace_prive(); |
|
| 1778 | + } |
|
| 1779 | + $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1780 | + |
|
| 1781 | + if (!$public) { |
|
| 1782 | + if (!$entite) { |
|
| 1783 | + return ''; |
|
| 1784 | + } |
|
| 1785 | + if (!function_exists('generer_url_ecrire_objet')) { |
|
| 1786 | + include_spip('inc/urls'); |
|
| 1787 | + } |
|
| 1788 | + $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false); |
|
| 1789 | + } else { |
|
| 1790 | + if ($type === null) { |
|
| 1791 | + $type = (isset($GLOBALS['type_urls'])) |
|
| 1792 | + ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options |
|
| 1793 | + : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues |
|
| 1794 | + ? ($GLOBALS['meta']['type_urls']) : "page"); // sinon type "page" par défaut |
|
| 1795 | + } |
|
| 1796 | + |
|
| 1797 | + $f = charger_fonction($type, 'urls', true); |
|
| 1798 | + // se rabattre sur les urls page si les urls perso non dispo |
|
| 1799 | + if (!$f) { |
|
| 1800 | + $f = charger_fonction('page', 'urls', true); |
|
| 1801 | + } |
|
| 1802 | + |
|
| 1803 | + // si $entite='', on veut la fonction de passage URL ==> id |
|
| 1804 | + // sinon on veut effectuer le passage id ==> URL |
|
| 1805 | + if (!$entite) { |
|
| 1806 | + return $f; |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + // mais d'abord il faut tester le cas des urls sur une |
|
| 1810 | + // base distante |
|
| 1811 | + if (is_string($public) |
|
| 1812 | + and $g = charger_fonction('connect', 'urls', true) |
|
| 1813 | + ) { |
|
| 1814 | + $f = $g; |
|
| 1815 | + } |
|
| 1816 | + |
|
| 1817 | + $res = $f(intval($id), $entite, $args, $ancre, $public); |
|
| 1818 | + |
|
| 1819 | + } |
|
| 1820 | + if ($res) { |
|
| 1821 | + return $res; |
|
| 1822 | + } |
|
| 1823 | + // Sinon c'est un raccourci ou compat SPIP < 2 |
|
| 1824 | + if (!function_exists($f = 'generer_url_' . $entite)) { |
|
| 1825 | + if (!function_exists($f .= '_dist')) { |
|
| 1826 | + $f = ''; |
|
| 1827 | + } |
|
| 1828 | + } |
|
| 1829 | + if ($f) { |
|
| 1830 | + $url = $f($id, $args, $ancre); |
|
| 1831 | + if (strlen($args)) { |
|
| 1832 | + $url .= strstr($url, '?') |
|
| 1833 | + ? '&' . $args |
|
| 1834 | + : '?' . $args; |
|
| 1835 | + } |
|
| 1836 | + |
|
| 1837 | + return $url; |
|
| 1838 | + } |
|
| 1839 | + // On a ete gentil mais la .... |
|
| 1840 | + spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public"); |
|
| 1841 | + |
|
| 1842 | + return ''; |
|
| 1844 | 1843 | } |
| 1845 | 1844 | |
| 1846 | 1845 | function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') { |
| 1847 | - $exec = objet_info($entite, 'url_edit'); |
|
| 1848 | - $url = generer_url_ecrire($exec, $args); |
|
| 1849 | - if (intval($id)) { |
|
| 1850 | - $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1851 | - } else { |
|
| 1852 | - $url = parametre_url($url, 'new', 'oui'); |
|
| 1853 | - } |
|
| 1854 | - if ($ancre) { |
|
| 1855 | - $url = ancre_url($url, $ancre); |
|
| 1856 | - } |
|
| 1846 | + $exec = objet_info($entite, 'url_edit'); |
|
| 1847 | + $url = generer_url_ecrire($exec, $args); |
|
| 1848 | + if (intval($id)) { |
|
| 1849 | + $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1850 | + } else { |
|
| 1851 | + $url = parametre_url($url, 'new', 'oui'); |
|
| 1852 | + } |
|
| 1853 | + if ($ancre) { |
|
| 1854 | + $url = ancre_url($url, $ancre); |
|
| 1855 | + } |
|
| 1857 | 1856 | |
| 1858 | - return $url; |
|
| 1857 | + return $url; |
|
| 1859 | 1858 | } |
| 1860 | 1859 | |
| 1861 | 1860 | // https://code.spip.net/@urls_connect_dist |
| 1862 | 1861 | function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) { |
| 1863 | - include_spip('base/connect_sql'); |
|
| 1864 | - $id_type = id_table_objet($entite, $public); |
|
| 1862 | + include_spip('base/connect_sql'); |
|
| 1863 | + $id_type = id_table_objet($entite, $public); |
|
| 1865 | 1864 | |
| 1866 | - return _DIR_RACINE . get_spip_script('./') |
|
| 1867 | - . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1868 | - . (!$args ? '' : "&$args") |
|
| 1869 | - . (!$ancre ? '' : "#$ancre"); |
|
| 1865 | + return _DIR_RACINE . get_spip_script('./') |
|
| 1866 | + . "?" . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1867 | + . (!$args ? '' : "&$args") |
|
| 1868 | + . (!$ancre ? '' : "#$ancre"); |
|
| 1870 | 1869 | } |
| 1871 | 1870 | |
| 1872 | 1871 | |
@@ -1877,32 +1876,32 @@ discard block |
||
| 1877 | 1876 | * @return string |
| 1878 | 1877 | */ |
| 1879 | 1878 | function urlencode_1738($url) { |
| 1880 | - if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1881 | - $uri = ''; |
|
| 1882 | - for ($i = 0; $i < strlen($url); $i++) { |
|
| 1883 | - if (ord($a = $url[$i]) > 127) { |
|
| 1884 | - $a = rawurlencode($a); |
|
| 1885 | - } |
|
| 1886 | - $uri .= $a; |
|
| 1887 | - } |
|
| 1888 | - $url = $uri; |
|
| 1889 | - } |
|
| 1879 | + if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1880 | + $uri = ''; |
|
| 1881 | + for ($i = 0; $i < strlen($url); $i++) { |
|
| 1882 | + if (ord($a = $url[$i]) > 127) { |
|
| 1883 | + $a = rawurlencode($a); |
|
| 1884 | + } |
|
| 1885 | + $uri .= $a; |
|
| 1886 | + } |
|
| 1887 | + $url = $uri; |
|
| 1888 | + } |
|
| 1890 | 1889 | |
| 1891 | - return quote_amp($url); |
|
| 1890 | + return quote_amp($url); |
|
| 1892 | 1891 | } |
| 1893 | 1892 | |
| 1894 | 1893 | // https://code.spip.net/@generer_url_entite_absolue |
| 1895 | 1894 | function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) { |
| 1896 | - if (!$connect) { |
|
| 1897 | - $connect = true; |
|
| 1898 | - } |
|
| 1899 | - $h = generer_url_entite($id, $entite, $args, $ancre, $connect); |
|
| 1900 | - if (!preg_match(',^\w+:,', $h)) { |
|
| 1901 | - include_spip('inc/filtres_mini'); |
|
| 1902 | - $h = url_absolue($h); |
|
| 1903 | - } |
|
| 1895 | + if (!$connect) { |
|
| 1896 | + $connect = true; |
|
| 1897 | + } |
|
| 1898 | + $h = generer_url_entite($id, $entite, $args, $ancre, $connect); |
|
| 1899 | + if (!preg_match(',^\w+:,', $h)) { |
|
| 1900 | + include_spip('inc/filtres_mini'); |
|
| 1901 | + $h = url_absolue($h); |
|
| 1902 | + } |
|
| 1904 | 1903 | |
| 1905 | - return $h; |
|
| 1904 | + return $h; |
|
| 1906 | 1905 | } |
| 1907 | 1906 | |
| 1908 | 1907 | |
@@ -1918,11 +1917,11 @@ discard block |
||
| 1918 | 1917 | * true si la valeur est considérée active ; false sinon. |
| 1919 | 1918 | **/ |
| 1920 | 1919 | function test_valeur_serveur($truc) { |
| 1921 | - if (!$truc) { |
|
| 1922 | - return false; |
|
| 1923 | - } |
|
| 1920 | + if (!$truc) { |
|
| 1921 | + return false; |
|
| 1922 | + } |
|
| 1924 | 1923 | |
| 1925 | - return (strtolower($truc) !== 'off'); |
|
| 1924 | + return (strtolower($truc) !== 'off'); |
|
| 1926 | 1925 | } |
| 1927 | 1926 | |
| 1928 | 1927 | // |
@@ -1950,80 +1949,80 @@ discard block |
||
| 1950 | 1949 | */ |
| 1951 | 1950 | function url_de_base($profondeur = null) { |
| 1952 | 1951 | |
| 1953 | - static $url = array(); |
|
| 1954 | - if (is_array($profondeur)) { |
|
| 1955 | - return $url = $profondeur; |
|
| 1956 | - } |
|
| 1957 | - if ($profondeur === false) { |
|
| 1958 | - return $url; |
|
| 1959 | - } |
|
| 1960 | - |
|
| 1961 | - if (is_null($profondeur)) { |
|
| 1962 | - $profondeur = $GLOBALS['profondeur_url']; |
|
| 1963 | - } |
|
| 1964 | - |
|
| 1965 | - if (isset($url[$profondeur])) { |
|
| 1966 | - return $url[$profondeur]; |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - $http = 'http'; |
|
| 1970 | - |
|
| 1971 | - if ( |
|
| 1972 | - isset($_SERVER["SCRIPT_URI"]) |
|
| 1973 | - and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https' |
|
| 1974 | - ) { |
|
| 1975 | - $http = 'https'; |
|
| 1976 | - } elseif ( |
|
| 1977 | - isset($_SERVER['HTTPS']) |
|
| 1978 | - and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 1979 | - ) { |
|
| 1980 | - $http = 'https'; |
|
| 1981 | - } |
|
| 1982 | - |
|
| 1983 | - // note : HTTP_HOST contient le :port si necessaire |
|
| 1984 | - $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
|
| 1985 | - // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 1986 | - if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 1987 | - $host = $GLOBALS['meta']['adresse_site']; |
|
| 1988 | - if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 1989 | - $http = $scheme; |
|
| 1990 | - $host = str_replace("{$scheme}://", '', $host); |
|
| 1991 | - } |
|
| 1992 | - } |
|
| 1993 | - if (isset($_SERVER['SERVER_PORT']) |
|
| 1994 | - and $port = $_SERVER['SERVER_PORT'] |
|
| 1995 | - and strpos($host, ":") == false |
|
| 1996 | - ) { |
|
| 1997 | - if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 1998 | - define('_PORT_HTTP_STANDARD', '80'); |
|
| 1999 | - } |
|
| 2000 | - if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2001 | - define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2002 | - } |
|
| 2003 | - if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2004 | - $host .= ":$port"; |
|
| 2005 | - } |
|
| 2006 | - if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2007 | - $host .= ":$port"; |
|
| 2008 | - } |
|
| 2009 | - } |
|
| 2010 | - |
|
| 2011 | - if (!$GLOBALS['REQUEST_URI']) { |
|
| 2012 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2013 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2014 | - } else { |
|
| 2015 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2016 | - if (!empty($_SERVER['QUERY_STRING']) |
|
| 2017 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2018 | - ) { |
|
| 2019 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2020 | - } |
|
| 2021 | - } |
|
| 2022 | - } |
|
| 2023 | - |
|
| 2024 | - $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2025 | - |
|
| 2026 | - return $url[$profondeur]; |
|
| 1952 | + static $url = array(); |
|
| 1953 | + if (is_array($profondeur)) { |
|
| 1954 | + return $url = $profondeur; |
|
| 1955 | + } |
|
| 1956 | + if ($profondeur === false) { |
|
| 1957 | + return $url; |
|
| 1958 | + } |
|
| 1959 | + |
|
| 1960 | + if (is_null($profondeur)) { |
|
| 1961 | + $profondeur = $GLOBALS['profondeur_url']; |
|
| 1962 | + } |
|
| 1963 | + |
|
| 1964 | + if (isset($url[$profondeur])) { |
|
| 1965 | + return $url[$profondeur]; |
|
| 1966 | + } |
|
| 1967 | + |
|
| 1968 | + $http = 'http'; |
|
| 1969 | + |
|
| 1970 | + if ( |
|
| 1971 | + isset($_SERVER["SCRIPT_URI"]) |
|
| 1972 | + and substr($_SERVER["SCRIPT_URI"], 0, 5) == 'https' |
|
| 1973 | + ) { |
|
| 1974 | + $http = 'https'; |
|
| 1975 | + } elseif ( |
|
| 1976 | + isset($_SERVER['HTTPS']) |
|
| 1977 | + and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 1978 | + ) { |
|
| 1979 | + $http = 'https'; |
|
| 1980 | + } |
|
| 1981 | + |
|
| 1982 | + // note : HTTP_HOST contient le :port si necessaire |
|
| 1983 | + $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
|
| 1984 | + // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 1985 | + if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 1986 | + $host = $GLOBALS['meta']['adresse_site']; |
|
| 1987 | + if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 1988 | + $http = $scheme; |
|
| 1989 | + $host = str_replace("{$scheme}://", '', $host); |
|
| 1990 | + } |
|
| 1991 | + } |
|
| 1992 | + if (isset($_SERVER['SERVER_PORT']) |
|
| 1993 | + and $port = $_SERVER['SERVER_PORT'] |
|
| 1994 | + and strpos($host, ":") == false |
|
| 1995 | + ) { |
|
| 1996 | + if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 1997 | + define('_PORT_HTTP_STANDARD', '80'); |
|
| 1998 | + } |
|
| 1999 | + if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2000 | + define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2001 | + } |
|
| 2002 | + if ($http == "http" and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2003 | + $host .= ":$port"; |
|
| 2004 | + } |
|
| 2005 | + if ($http == "https" and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2006 | + $host .= ":$port"; |
|
| 2007 | + } |
|
| 2008 | + } |
|
| 2009 | + |
|
| 2010 | + if (!$GLOBALS['REQUEST_URI']) { |
|
| 2011 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2012 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2013 | + } else { |
|
| 2014 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2015 | + if (!empty($_SERVER['QUERY_STRING']) |
|
| 2016 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2017 | + ) { |
|
| 2018 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2019 | + } |
|
| 2020 | + } |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2024 | + |
|
| 2025 | + return $url[$profondeur]; |
|
| 2027 | 2026 | } |
| 2028 | 2027 | |
| 2029 | 2028 | /** |
@@ -2036,26 +2035,26 @@ discard block |
||
| 2036 | 2035 | * @return string |
| 2037 | 2036 | */ |
| 2038 | 2037 | function url_de_($http, $host, $request, $prof = 0) { |
| 2039 | - $prof = max($prof, 0); |
|
| 2038 | + $prof = max($prof, 0); |
|
| 2040 | 2039 | |
| 2041 | - $myself = ltrim($request, '/'); |
|
| 2042 | - # supprimer la chaine de GET |
|
| 2043 | - list($myself) = explode('?', $myself); |
|
| 2044 | - // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2045 | - // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2046 | - if (strpos($myself,'://') !== false) { |
|
| 2047 | - $myself = explode('://',$myself); |
|
| 2048 | - array_shift($myself); |
|
| 2049 | - $myself = implode('://',$myself); |
|
| 2050 | - $myself = explode('/',$myself); |
|
| 2051 | - array_shift($myself); |
|
| 2052 | - $myself = implode('/',$myself); |
|
| 2053 | - } |
|
| 2054 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2040 | + $myself = ltrim($request, '/'); |
|
| 2041 | + # supprimer la chaine de GET |
|
| 2042 | + list($myself) = explode('?', $myself); |
|
| 2043 | + // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2044 | + // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2045 | + if (strpos($myself,'://') !== false) { |
|
| 2046 | + $myself = explode('://',$myself); |
|
| 2047 | + array_shift($myself); |
|
| 2048 | + $myself = implode('://',$myself); |
|
| 2049 | + $myself = explode('/',$myself); |
|
| 2050 | + array_shift($myself); |
|
| 2051 | + $myself = implode('/',$myself); |
|
| 2052 | + } |
|
| 2053 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2055 | 2054 | |
| 2056 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2055 | + $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2057 | 2056 | |
| 2058 | - return $url; |
|
| 2057 | + return $url; |
|
| 2059 | 2058 | } |
| 2060 | 2059 | |
| 2061 | 2060 | |
@@ -2090,26 +2089,26 @@ discard block |
||
| 2090 | 2089 | * @return string URL |
| 2091 | 2090 | **/ |
| 2092 | 2091 | function generer_url_ecrire($script = '', $args = "", $no_entities = false, $rel = false) { |
| 2093 | - if (!$rel) { |
|
| 2094 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2095 | - } else { |
|
| 2096 | - if (!is_string($rel)) { |
|
| 2097 | - $rel = _DIR_RESTREINT ? _DIR_RESTREINT : |
|
| 2098 | - ('./' . _SPIP_ECRIRE_SCRIPT); |
|
| 2099 | - } |
|
| 2100 | - } |
|
| 2101 | - |
|
| 2102 | - list($script, $ancre) = array_pad(explode('#', $script), 2, null); |
|
| 2103 | - if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2104 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2105 | - } elseif ($args) { |
|
| 2106 | - $args = "?$args"; |
|
| 2107 | - } |
|
| 2108 | - if ($ancre) { |
|
| 2109 | - $args .= "#$ancre"; |
|
| 2110 | - } |
|
| 2111 | - |
|
| 2112 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2092 | + if (!$rel) { |
|
| 2093 | + $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2094 | + } else { |
|
| 2095 | + if (!is_string($rel)) { |
|
| 2096 | + $rel = _DIR_RESTREINT ? _DIR_RESTREINT : |
|
| 2097 | + ('./' . _SPIP_ECRIRE_SCRIPT); |
|
| 2098 | + } |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + list($script, $ancre) = array_pad(explode('#', $script), 2, null); |
|
| 2102 | + if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2103 | + $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2104 | + } elseif ($args) { |
|
| 2105 | + $args = "?$args"; |
|
| 2106 | + } |
|
| 2107 | + if ($ancre) { |
|
| 2108 | + $args .= "#$ancre"; |
|
| 2109 | + } |
|
| 2110 | + |
|
| 2111 | + return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2113 | 2112 | } |
| 2114 | 2113 | |
| 2115 | 2114 | // |
@@ -2131,12 +2130,12 @@ discard block |
||
| 2131 | 2130 | * Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut |
| 2132 | 2131 | **/ |
| 2133 | 2132 | function get_spip_script($default = '') { |
| 2134 | - # cas define('_SPIP_SCRIPT', ''); |
|
| 2135 | - if (_SPIP_SCRIPT) { |
|
| 2136 | - return _SPIP_SCRIPT; |
|
| 2137 | - } else { |
|
| 2138 | - return $default; |
|
| 2139 | - } |
|
| 2133 | + # cas define('_SPIP_SCRIPT', ''); |
|
| 2134 | + if (_SPIP_SCRIPT) { |
|
| 2135 | + return _SPIP_SCRIPT; |
|
| 2136 | + } else { |
|
| 2137 | + return $default; |
|
| 2138 | + } |
|
| 2140 | 2139 | } |
| 2141 | 2140 | |
| 2142 | 2141 | /** |
@@ -2165,39 +2164,39 @@ discard block |
||
| 2165 | 2164 | * @return string URL |
| 2166 | 2165 | **/ |
| 2167 | 2166 | function generer_url_public($script = '', $args = "", $no_entities = false, $rel = true, $action = '') { |
| 2168 | - // si le script est une action (spip_pass, spip_inscription), |
|
| 2169 | - // standardiser vers la nouvelle API |
|
| 2170 | - |
|
| 2171 | - if (!$action) { |
|
| 2172 | - $action = get_spip_script(); |
|
| 2173 | - } |
|
| 2174 | - if ($script) { |
|
| 2175 | - $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2176 | - } |
|
| 2177 | - |
|
| 2178 | - if ($args) { |
|
| 2179 | - if (is_array($args)) { |
|
| 2180 | - $r = ''; |
|
| 2181 | - foreach ($args as $k => $v) { |
|
| 2182 | - $r .= '&' . $k . '=' . $v; |
|
| 2183 | - } |
|
| 2184 | - $args = substr($r, 1); |
|
| 2185 | - } |
|
| 2186 | - $action .= |
|
| 2187 | - (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2188 | - } |
|
| 2189 | - if (!$no_entities) { |
|
| 2190 | - $action = quote_amp($action); |
|
| 2191 | - } |
|
| 2192 | - |
|
| 2193 | - // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2194 | - return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action")); |
|
| 2167 | + // si le script est une action (spip_pass, spip_inscription), |
|
| 2168 | + // standardiser vers la nouvelle API |
|
| 2169 | + |
|
| 2170 | + if (!$action) { |
|
| 2171 | + $action = get_spip_script(); |
|
| 2172 | + } |
|
| 2173 | + if ($script) { |
|
| 2174 | + $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2175 | + } |
|
| 2176 | + |
|
| 2177 | + if ($args) { |
|
| 2178 | + if (is_array($args)) { |
|
| 2179 | + $r = ''; |
|
| 2180 | + foreach ($args as $k => $v) { |
|
| 2181 | + $r .= '&' . $k . '=' . $v; |
|
| 2182 | + } |
|
| 2183 | + $args = substr($r, 1); |
|
| 2184 | + } |
|
| 2185 | + $action .= |
|
| 2186 | + (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2187 | + } |
|
| 2188 | + if (!$no_entities) { |
|
| 2189 | + $action = quote_amp($action); |
|
| 2190 | + } |
|
| 2191 | + |
|
| 2192 | + // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2193 | + return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(",^/[.]/,", "/", "/$action")); |
|
| 2195 | 2194 | } |
| 2196 | 2195 | |
| 2197 | 2196 | // https://code.spip.net/@generer_url_prive |
| 2198 | 2197 | function generer_url_prive($script, $args = "", $no_entities = false) { |
| 2199 | 2198 | |
| 2200 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2199 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2201 | 2200 | } |
| 2202 | 2201 | |
| 2203 | 2202 | // Pour les formulaires en methode POST, |
@@ -2222,19 +2221,19 @@ discard block |
||
| 2222 | 2221 | **/ |
| 2223 | 2222 | function generer_form_ecrire($script, $corps, $atts = '', $submit = '') { |
| 2224 | 2223 | |
| 2225 | - $script1 = explode('&', $script); |
|
| 2226 | - $script1 = reset($script1); |
|
| 2224 | + $script1 = explode('&', $script); |
|
| 2225 | + $script1 = reset($script1); |
|
| 2227 | 2226 | |
| 2228 | - return "<form action='" |
|
| 2229 | - . ($script ? generer_url_ecrire($script) : '') |
|
| 2230 | - . "' " |
|
| 2231 | - . ($atts ? $atts : " method='post'") |
|
| 2232 | - . "><div>\n" |
|
| 2233 | - . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2234 | - . $corps |
|
| 2235 | - . (!$submit ? '' : |
|
| 2236 | - ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . "\" /></div>")) |
|
| 2237 | - . "</div></form>\n"; |
|
| 2227 | + return "<form action='" |
|
| 2228 | + . ($script ? generer_url_ecrire($script) : '') |
|
| 2229 | + . "' " |
|
| 2230 | + . ($atts ? $atts : " method='post'") |
|
| 2231 | + . "><div>\n" |
|
| 2232 | + . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2233 | + . $corps |
|
| 2234 | + . (!$submit ? '' : |
|
| 2235 | + ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . "\" /></div>")) |
|
| 2236 | + . "</div></form>\n"; |
|
| 2238 | 2237 | } |
| 2239 | 2238 | |
| 2240 | 2239 | /** |
@@ -2251,22 +2250,22 @@ discard block |
||
| 2251 | 2250 | * @return string |
| 2252 | 2251 | */ |
| 2253 | 2252 | function generer_form_action($script, $corps, $atts = '', $public = false) { |
| 2254 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2255 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2256 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2257 | - $h = (_DIR_RACINE and !$public) |
|
| 2258 | - ? generer_url_ecrire(_request('exec')) |
|
| 2259 | - : generer_url_public(); |
|
| 2253 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2254 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2255 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2256 | + $h = (_DIR_RACINE and !$public) |
|
| 2257 | + ? generer_url_ecrire(_request('exec')) |
|
| 2258 | + : generer_url_public(); |
|
| 2260 | 2259 | |
| 2261 | - return "\n<form action='" . |
|
| 2262 | - $h . |
|
| 2263 | - "'" . |
|
| 2264 | - $atts . |
|
| 2265 | - ">\n" . |
|
| 2266 | - "<div>" . |
|
| 2267 | - "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2268 | - $corps . |
|
| 2269 | - "</div></form>"; |
|
| 2260 | + return "\n<form action='" . |
|
| 2261 | + $h . |
|
| 2262 | + "'" . |
|
| 2263 | + $atts . |
|
| 2264 | + ">\n" . |
|
| 2265 | + "<div>" . |
|
| 2266 | + "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2267 | + $corps . |
|
| 2268 | + "</div></form>"; |
|
| 2270 | 2269 | } |
| 2271 | 2270 | |
| 2272 | 2271 | /** |
@@ -2285,22 +2284,22 @@ discard block |
||
| 2285 | 2284 | * URL |
| 2286 | 2285 | */ |
| 2287 | 2286 | function generer_url_action($script, $args = "", $no_entities = false, $public = false) { |
| 2288 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2289 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2290 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2291 | - $url = (_DIR_RACINE and !$public) |
|
| 2292 | - ? generer_url_ecrire(_request('exec')) |
|
| 2293 | - : generer_url_public('', '', false, false); |
|
| 2294 | - $url = parametre_url($url, 'action', $script); |
|
| 2295 | - if ($args) { |
|
| 2296 | - $url .= quote_amp('&' . $args); |
|
| 2297 | - } |
|
| 2287 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2288 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2289 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2290 | + $url = (_DIR_RACINE and !$public) |
|
| 2291 | + ? generer_url_ecrire(_request('exec')) |
|
| 2292 | + : generer_url_public('', '', false, false); |
|
| 2293 | + $url = parametre_url($url, 'action', $script); |
|
| 2294 | + if ($args) { |
|
| 2295 | + $url .= quote_amp('&' . $args); |
|
| 2296 | + } |
|
| 2298 | 2297 | |
| 2299 | - if ($no_entities) { |
|
| 2300 | - $url = str_replace('&', '&', $url); |
|
| 2301 | - } |
|
| 2298 | + if ($no_entities) { |
|
| 2299 | + $url = str_replace('&', '&', $url); |
|
| 2300 | + } |
|
| 2302 | 2301 | |
| 2303 | - return $url; |
|
| 2302 | + return $url; |
|
| 2304 | 2303 | } |
| 2305 | 2304 | |
| 2306 | 2305 | |
@@ -2313,8 +2312,8 @@ discard block |
||
| 2313 | 2312 | * @param string $ta Répertoire temporaire accessible |
| 2314 | 2313 | */ |
| 2315 | 2314 | function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2316 | - spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2317 | - spip_initialisation_suite(); |
|
| 2315 | + spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2316 | + spip_initialisation_suite(); |
|
| 2318 | 2317 | } |
| 2319 | 2318 | |
| 2320 | 2319 | /** |
@@ -2334,315 +2333,315 @@ discard block |
||
| 2334 | 2333 | * @param string $ta Répertoire temporaire accessible |
| 2335 | 2334 | */ |
| 2336 | 2335 | function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2337 | - static $too_late = 0; |
|
| 2338 | - if ($too_late++) { |
|
| 2339 | - return; |
|
| 2340 | - } |
|
| 2341 | - |
|
| 2342 | - // Declaration des repertoires |
|
| 2343 | - |
|
| 2344 | - // le nom du repertoire plugins/ activables/desactivables |
|
| 2345 | - if (!defined('_DIR_PLUGINS')) { |
|
| 2346 | - define('_DIR_PLUGINS', _DIR_RACINE . "plugins/"); |
|
| 2347 | - } |
|
| 2348 | - |
|
| 2349 | - // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2350 | - if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2351 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/"); |
|
| 2352 | - } |
|
| 2353 | - |
|
| 2354 | - // le nom du repertoire des librairies |
|
| 2355 | - if (!defined('_DIR_LIB')) { |
|
| 2356 | - define('_DIR_LIB', _DIR_RACINE . "lib/"); |
|
| 2357 | - } |
|
| 2358 | - |
|
| 2359 | - if (!defined('_DIR_IMG')) { |
|
| 2360 | - define('_DIR_IMG', $pa); |
|
| 2361 | - } |
|
| 2362 | - if (!defined('_DIR_LOGOS')) { |
|
| 2363 | - define('_DIR_LOGOS', $pa); |
|
| 2364 | - } |
|
| 2365 | - if (!defined('_DIR_IMG_ICONES')) { |
|
| 2366 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/"); |
|
| 2367 | - } |
|
| 2368 | - |
|
| 2369 | - if (!defined('_DIR_DUMP')) { |
|
| 2370 | - define('_DIR_DUMP', $ti . "dump/"); |
|
| 2371 | - } |
|
| 2372 | - if (!defined('_DIR_SESSIONS')) { |
|
| 2373 | - define('_DIR_SESSIONS', $ti . "sessions/"); |
|
| 2374 | - } |
|
| 2375 | - if (!defined('_DIR_TRANSFERT')) { |
|
| 2376 | - define('_DIR_TRANSFERT', $ti . "upload/"); |
|
| 2377 | - } |
|
| 2378 | - if (!defined('_DIR_CACHE')) { |
|
| 2379 | - define('_DIR_CACHE', $ti . "cache/"); |
|
| 2380 | - } |
|
| 2381 | - if (!defined('_DIR_CACHE_XML')) { |
|
| 2382 | - define('_DIR_CACHE_XML', _DIR_CACHE . "xml/"); |
|
| 2383 | - } |
|
| 2384 | - if (!defined('_DIR_SKELS')) { |
|
| 2385 | - define('_DIR_SKELS', _DIR_CACHE . "skel/"); |
|
| 2386 | - } |
|
| 2387 | - if (!defined('_DIR_AIDE')) { |
|
| 2388 | - define('_DIR_AIDE', _DIR_CACHE . "aide/"); |
|
| 2389 | - } |
|
| 2390 | - if (!defined('_DIR_TMP')) { |
|
| 2391 | - define('_DIR_TMP', $ti); |
|
| 2392 | - } |
|
| 2393 | - |
|
| 2394 | - if (!defined('_DIR_VAR')) { |
|
| 2395 | - define('_DIR_VAR', $ta); |
|
| 2396 | - } |
|
| 2397 | - |
|
| 2398 | - if (!defined('_DIR_ETC')) { |
|
| 2399 | - define('_DIR_ETC', $pi); |
|
| 2400 | - } |
|
| 2401 | - if (!defined('_DIR_CONNECT')) { |
|
| 2402 | - define('_DIR_CONNECT', $pi); |
|
| 2403 | - } |
|
| 2404 | - if (!defined('_DIR_CHMOD')) { |
|
| 2405 | - define('_DIR_CHMOD', $pi); |
|
| 2406 | - } |
|
| 2407 | - |
|
| 2408 | - if (!isset($GLOBALS['test_dirs'])) |
|
| 2409 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2410 | - // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2411 | - { |
|
| 2412 | - $GLOBALS['test_dirs'] = array($pa, $ti, $ta); |
|
| 2413 | - } |
|
| 2414 | - |
|
| 2415 | - // Declaration des fichiers |
|
| 2416 | - |
|
| 2417 | - if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2418 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php"); |
|
| 2419 | - } |
|
| 2420 | - if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2421 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php"); |
|
| 2422 | - } |
|
| 2423 | - if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2424 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php"); |
|
| 2425 | - } |
|
| 2426 | - if (!defined('_CACHE_PIPELINES')) { |
|
| 2427 | - define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php"); |
|
| 2428 | - } |
|
| 2429 | - if (!defined('_CACHE_CHEMIN')) { |
|
| 2430 | - define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt"); |
|
| 2431 | - } |
|
| 2432 | - |
|
| 2433 | - # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2434 | - if (!defined('_FILE_META')) { |
|
| 2435 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2436 | - } |
|
| 2437 | - if (!defined('_DIR_LOG')) { |
|
| 2438 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2439 | - } |
|
| 2440 | - if (!defined('_FILE_LOG')) { |
|
| 2441 | - define('_FILE_LOG', 'spip'); |
|
| 2442 | - } |
|
| 2443 | - if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2444 | - define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2445 | - } |
|
| 2446 | - |
|
| 2447 | - // Le fichier de connexion a la base de donnees |
|
| 2448 | - // tient compte des anciennes versions (inc_connect...) |
|
| 2449 | - if (!defined('_FILE_CONNECT_INS')) { |
|
| 2450 | - define('_FILE_CONNECT_INS', 'connect'); |
|
| 2451 | - } |
|
| 2452 | - if (!defined('_FILE_CONNECT')) { |
|
| 2453 | - define('_FILE_CONNECT', |
|
| 2454 | - (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2455 | - : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2456 | - : false))); |
|
| 2457 | - } |
|
| 2458 | - |
|
| 2459 | - // Le fichier de reglages des droits |
|
| 2460 | - if (!defined('_FILE_CHMOD_INS')) { |
|
| 2461 | - define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2462 | - } |
|
| 2463 | - if (!defined('_FILE_CHMOD')) { |
|
| 2464 | - define('_FILE_CHMOD', |
|
| 2465 | - (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2466 | - : false)); |
|
| 2467 | - } |
|
| 2468 | - |
|
| 2469 | - if (!defined('_FILE_LDAP')) { |
|
| 2470 | - define('_FILE_LDAP', 'ldap.php'); |
|
| 2471 | - } |
|
| 2472 | - |
|
| 2473 | - if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2474 | - define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2475 | - } |
|
| 2476 | - if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2477 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2478 | - } |
|
| 2479 | - if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2480 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2481 | - } |
|
| 2482 | - |
|
| 2483 | - // Definition des droits d'acces en ecriture |
|
| 2484 | - if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2485 | - include_once _FILE_CHMOD; |
|
| 2486 | - } |
|
| 2487 | - |
|
| 2488 | - // Se mefier des fichiers mal remplis! |
|
| 2489 | - if (!defined('_SPIP_CHMOD')) { |
|
| 2490 | - define('_SPIP_CHMOD', 0777); |
|
| 2491 | - } |
|
| 2492 | - |
|
| 2493 | - if (!defined('_DEFAULT_CHARSET')) { |
|
| 2494 | - /** Le charset par défaut lors de l'installation */ |
|
| 2495 | - define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2496 | - } |
|
| 2497 | - if (!defined('_ROOT_PLUGINS')) { |
|
| 2498 | - define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/"); |
|
| 2499 | - } |
|
| 2500 | - if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2501 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/"); |
|
| 2502 | - } |
|
| 2503 | - if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2504 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2505 | - } |
|
| 2506 | - |
|
| 2507 | - // La taille des Log |
|
| 2508 | - if (!defined('_MAX_LOG')) { |
|
| 2509 | - define('_MAX_LOG', 100); |
|
| 2510 | - } |
|
| 2511 | - |
|
| 2512 | - // Sommes-nous dans l'empire du Mal ? |
|
| 2513 | - // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2514 | - if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2515 | - if (!defined('_OS_SERVEUR')) { |
|
| 2516 | - define('_OS_SERVEUR', 'windows'); |
|
| 2517 | - } |
|
| 2518 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2519 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2520 | - } // utiliser le flock php |
|
| 2521 | - } else { |
|
| 2522 | - if (!defined('_OS_SERVEUR')) { |
|
| 2523 | - define('_OS_SERVEUR', ''); |
|
| 2524 | - } |
|
| 2525 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2526 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2527 | - } // utiliser le flock php |
|
| 2528 | - #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2529 | - } |
|
| 2530 | - |
|
| 2531 | - // Langue par defaut |
|
| 2532 | - if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2533 | - define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2534 | - } |
|
| 2535 | - |
|
| 2536 | - // |
|
| 2537 | - // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2538 | - // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2539 | - // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2540 | - // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2541 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2542 | - |
|
| 2543 | - // charger tout de suite le path et son cache |
|
| 2544 | - load_path_cache(); |
|
| 2545 | - |
|
| 2546 | - // *********** traiter les variables ************ |
|
| 2547 | - |
|
| 2548 | - // |
|
| 2549 | - // Securite |
|
| 2550 | - // |
|
| 2551 | - |
|
| 2552 | - // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2553 | - if (isset($_REQUEST['GLOBALS'])) { |
|
| 2554 | - die(); |
|
| 2555 | - } |
|
| 2556 | - // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2557 | - spip_desinfecte($_GET); |
|
| 2558 | - spip_desinfecte($_POST); |
|
| 2559 | - spip_desinfecte($_COOKIE); |
|
| 2560 | - spip_desinfecte($_REQUEST); |
|
| 2561 | - |
|
| 2562 | - // appliquer le cookie_prefix |
|
| 2563 | - if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2564 | - include_spip('inc/cookie'); |
|
| 2565 | - recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2566 | - } |
|
| 2567 | - |
|
| 2568 | - // |
|
| 2569 | - // Capacites php (en fonction de la version) |
|
| 2570 | - // |
|
| 2571 | - $GLOBALS['flag_ob'] = (function_exists("ob_start") |
|
| 2572 | - && function_exists("ini_get") |
|
| 2573 | - && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2574 | - $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name"); |
|
| 2575 | - $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ""); |
|
| 2576 | - $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2577 | - (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2578 | - |
|
| 2579 | - |
|
| 2580 | - // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2581 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2582 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2583 | - } else { |
|
| 2584 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2585 | - if (!empty($_SERVER['QUERY_STRING']) |
|
| 2586 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2587 | - ) { |
|
| 2588 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2589 | - } |
|
| 2590 | - } |
|
| 2591 | - |
|
| 2592 | - // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2593 | - if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2594 | - define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2595 | - } |
|
| 2596 | - if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2597 | - define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2598 | - } |
|
| 2599 | - |
|
| 2600 | - // charger les meta si possible et renouveller l'alea au besoin |
|
| 2601 | - // charge aussi effacer_meta et ecrire_meta |
|
| 2602 | - $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2603 | - $inc_meta(); |
|
| 2604 | - |
|
| 2605 | - // nombre de repertoires depuis la racine |
|
| 2606 | - // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2607 | - // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2608 | - // le calcul est faux) |
|
| 2609 | - if (!_DIR_RESTREINT) { |
|
| 2610 | - $GLOBALS['profondeur_url'] = 1; |
|
| 2611 | - } else { |
|
| 2612 | - $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2613 | - $uri_ref = $_SERVER["SCRIPT_NAME"]; |
|
| 2614 | - if (!$uri_ref |
|
| 2615 | - // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2616 | - // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2617 | - // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2618 | - // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2619 | - or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2620 | - ) { |
|
| 2621 | - |
|
| 2622 | - if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2623 | - $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2624 | - $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/'; |
|
| 2625 | - } else { |
|
| 2626 | - $uri_ref = ""; |
|
| 2627 | - } |
|
| 2628 | - } |
|
| 2629 | - if (!$uri or !$uri_ref) { |
|
| 2630 | - $GLOBALS['profondeur_url'] = 0; |
|
| 2631 | - } else { |
|
| 2632 | - $GLOBALS['profondeur_url'] = max(0, |
|
| 2633 | - substr_count($uri[0], '/') |
|
| 2634 | - - substr_count($uri_ref, '/')); |
|
| 2635 | - } |
|
| 2636 | - } |
|
| 2637 | - // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2638 | - if (_FILE_CONNECT) { |
|
| 2639 | - if (verifier_visiteur() == '0minirezo' |
|
| 2640 | - // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2641 | - and !isset($_COOKIE['spip_admin']) |
|
| 2642 | - ) { |
|
| 2643 | - clear_path_cache(); |
|
| 2644 | - } |
|
| 2645 | - } |
|
| 2336 | + static $too_late = 0; |
|
| 2337 | + if ($too_late++) { |
|
| 2338 | + return; |
|
| 2339 | + } |
|
| 2340 | + |
|
| 2341 | + // Declaration des repertoires |
|
| 2342 | + |
|
| 2343 | + // le nom du repertoire plugins/ activables/desactivables |
|
| 2344 | + if (!defined('_DIR_PLUGINS')) { |
|
| 2345 | + define('_DIR_PLUGINS', _DIR_RACINE . "plugins/"); |
|
| 2346 | + } |
|
| 2347 | + |
|
| 2348 | + // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2349 | + if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2350 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE . "plugins-dist/"); |
|
| 2351 | + } |
|
| 2352 | + |
|
| 2353 | + // le nom du repertoire des librairies |
|
| 2354 | + if (!defined('_DIR_LIB')) { |
|
| 2355 | + define('_DIR_LIB', _DIR_RACINE . "lib/"); |
|
| 2356 | + } |
|
| 2357 | + |
|
| 2358 | + if (!defined('_DIR_IMG')) { |
|
| 2359 | + define('_DIR_IMG', $pa); |
|
| 2360 | + } |
|
| 2361 | + if (!defined('_DIR_LOGOS')) { |
|
| 2362 | + define('_DIR_LOGOS', $pa); |
|
| 2363 | + } |
|
| 2364 | + if (!defined('_DIR_IMG_ICONES')) { |
|
| 2365 | + define('_DIR_IMG_ICONES', _DIR_LOGOS . "icones/"); |
|
| 2366 | + } |
|
| 2367 | + |
|
| 2368 | + if (!defined('_DIR_DUMP')) { |
|
| 2369 | + define('_DIR_DUMP', $ti . "dump/"); |
|
| 2370 | + } |
|
| 2371 | + if (!defined('_DIR_SESSIONS')) { |
|
| 2372 | + define('_DIR_SESSIONS', $ti . "sessions/"); |
|
| 2373 | + } |
|
| 2374 | + if (!defined('_DIR_TRANSFERT')) { |
|
| 2375 | + define('_DIR_TRANSFERT', $ti . "upload/"); |
|
| 2376 | + } |
|
| 2377 | + if (!defined('_DIR_CACHE')) { |
|
| 2378 | + define('_DIR_CACHE', $ti . "cache/"); |
|
| 2379 | + } |
|
| 2380 | + if (!defined('_DIR_CACHE_XML')) { |
|
| 2381 | + define('_DIR_CACHE_XML', _DIR_CACHE . "xml/"); |
|
| 2382 | + } |
|
| 2383 | + if (!defined('_DIR_SKELS')) { |
|
| 2384 | + define('_DIR_SKELS', _DIR_CACHE . "skel/"); |
|
| 2385 | + } |
|
| 2386 | + if (!defined('_DIR_AIDE')) { |
|
| 2387 | + define('_DIR_AIDE', _DIR_CACHE . "aide/"); |
|
| 2388 | + } |
|
| 2389 | + if (!defined('_DIR_TMP')) { |
|
| 2390 | + define('_DIR_TMP', $ti); |
|
| 2391 | + } |
|
| 2392 | + |
|
| 2393 | + if (!defined('_DIR_VAR')) { |
|
| 2394 | + define('_DIR_VAR', $ta); |
|
| 2395 | + } |
|
| 2396 | + |
|
| 2397 | + if (!defined('_DIR_ETC')) { |
|
| 2398 | + define('_DIR_ETC', $pi); |
|
| 2399 | + } |
|
| 2400 | + if (!defined('_DIR_CONNECT')) { |
|
| 2401 | + define('_DIR_CONNECT', $pi); |
|
| 2402 | + } |
|
| 2403 | + if (!defined('_DIR_CHMOD')) { |
|
| 2404 | + define('_DIR_CHMOD', $pi); |
|
| 2405 | + } |
|
| 2406 | + |
|
| 2407 | + if (!isset($GLOBALS['test_dirs'])) |
|
| 2408 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2409 | + // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2410 | + { |
|
| 2411 | + $GLOBALS['test_dirs'] = array($pa, $ti, $ta); |
|
| 2412 | + } |
|
| 2413 | + |
|
| 2414 | + // Declaration des fichiers |
|
| 2415 | + |
|
| 2416 | + if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2417 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE . "charger_plugins_chemins.php"); |
|
| 2418 | + } |
|
| 2419 | + if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2420 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE . "charger_plugins_options.php"); |
|
| 2421 | + } |
|
| 2422 | + if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2423 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE . "charger_plugins_fonctions.php"); |
|
| 2424 | + } |
|
| 2425 | + if (!defined('_CACHE_PIPELINES')) { |
|
| 2426 | + define('_CACHE_PIPELINES', _DIR_CACHE . "charger_pipelines.php"); |
|
| 2427 | + } |
|
| 2428 | + if (!defined('_CACHE_CHEMIN')) { |
|
| 2429 | + define('_CACHE_CHEMIN', _DIR_CACHE . "chemin.txt"); |
|
| 2430 | + } |
|
| 2431 | + |
|
| 2432 | + # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2433 | + if (!defined('_FILE_META')) { |
|
| 2434 | + define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2435 | + } |
|
| 2436 | + if (!defined('_DIR_LOG')) { |
|
| 2437 | + define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2438 | + } |
|
| 2439 | + if (!defined('_FILE_LOG')) { |
|
| 2440 | + define('_FILE_LOG', 'spip'); |
|
| 2441 | + } |
|
| 2442 | + if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2443 | + define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2444 | + } |
|
| 2445 | + |
|
| 2446 | + // Le fichier de connexion a la base de donnees |
|
| 2447 | + // tient compte des anciennes versions (inc_connect...) |
|
| 2448 | + if (!defined('_FILE_CONNECT_INS')) { |
|
| 2449 | + define('_FILE_CONNECT_INS', 'connect'); |
|
| 2450 | + } |
|
| 2451 | + if (!defined('_FILE_CONNECT')) { |
|
| 2452 | + define('_FILE_CONNECT', |
|
| 2453 | + (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2454 | + : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2455 | + : false))); |
|
| 2456 | + } |
|
| 2457 | + |
|
| 2458 | + // Le fichier de reglages des droits |
|
| 2459 | + if (!defined('_FILE_CHMOD_INS')) { |
|
| 2460 | + define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2461 | + } |
|
| 2462 | + if (!defined('_FILE_CHMOD')) { |
|
| 2463 | + define('_FILE_CHMOD', |
|
| 2464 | + (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2465 | + : false)); |
|
| 2466 | + } |
|
| 2467 | + |
|
| 2468 | + if (!defined('_FILE_LDAP')) { |
|
| 2469 | + define('_FILE_LDAP', 'ldap.php'); |
|
| 2470 | + } |
|
| 2471 | + |
|
| 2472 | + if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2473 | + define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2474 | + } |
|
| 2475 | + if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2476 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2477 | + } |
|
| 2478 | + if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2479 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2480 | + } |
|
| 2481 | + |
|
| 2482 | + // Definition des droits d'acces en ecriture |
|
| 2483 | + if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2484 | + include_once _FILE_CHMOD; |
|
| 2485 | + } |
|
| 2486 | + |
|
| 2487 | + // Se mefier des fichiers mal remplis! |
|
| 2488 | + if (!defined('_SPIP_CHMOD')) { |
|
| 2489 | + define('_SPIP_CHMOD', 0777); |
|
| 2490 | + } |
|
| 2491 | + |
|
| 2492 | + if (!defined('_DEFAULT_CHARSET')) { |
|
| 2493 | + /** Le charset par défaut lors de l'installation */ |
|
| 2494 | + define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2495 | + } |
|
| 2496 | + if (!defined('_ROOT_PLUGINS')) { |
|
| 2497 | + define('_ROOT_PLUGINS', _ROOT_RACINE . "plugins/"); |
|
| 2498 | + } |
|
| 2499 | + if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2500 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . "plugins-dist/"); |
|
| 2501 | + } |
|
| 2502 | + if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2503 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2504 | + } |
|
| 2505 | + |
|
| 2506 | + // La taille des Log |
|
| 2507 | + if (!defined('_MAX_LOG')) { |
|
| 2508 | + define('_MAX_LOG', 100); |
|
| 2509 | + } |
|
| 2510 | + |
|
| 2511 | + // Sommes-nous dans l'empire du Mal ? |
|
| 2512 | + // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2513 | + if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2514 | + if (!defined('_OS_SERVEUR')) { |
|
| 2515 | + define('_OS_SERVEUR', 'windows'); |
|
| 2516 | + } |
|
| 2517 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2518 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2519 | + } // utiliser le flock php |
|
| 2520 | + } else { |
|
| 2521 | + if (!defined('_OS_SERVEUR')) { |
|
| 2522 | + define('_OS_SERVEUR', ''); |
|
| 2523 | + } |
|
| 2524 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2525 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2526 | + } // utiliser le flock php |
|
| 2527 | + #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2528 | + } |
|
| 2529 | + |
|
| 2530 | + // Langue par defaut |
|
| 2531 | + if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2532 | + define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2533 | + } |
|
| 2534 | + |
|
| 2535 | + // |
|
| 2536 | + // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2537 | + // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2538 | + // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2539 | + // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2540 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2541 | + |
|
| 2542 | + // charger tout de suite le path et son cache |
|
| 2543 | + load_path_cache(); |
|
| 2544 | + |
|
| 2545 | + // *********** traiter les variables ************ |
|
| 2546 | + |
|
| 2547 | + // |
|
| 2548 | + // Securite |
|
| 2549 | + // |
|
| 2550 | + |
|
| 2551 | + // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2552 | + if (isset($_REQUEST['GLOBALS'])) { |
|
| 2553 | + die(); |
|
| 2554 | + } |
|
| 2555 | + // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2556 | + spip_desinfecte($_GET); |
|
| 2557 | + spip_desinfecte($_POST); |
|
| 2558 | + spip_desinfecte($_COOKIE); |
|
| 2559 | + spip_desinfecte($_REQUEST); |
|
| 2560 | + |
|
| 2561 | + // appliquer le cookie_prefix |
|
| 2562 | + if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2563 | + include_spip('inc/cookie'); |
|
| 2564 | + recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2565 | + } |
|
| 2566 | + |
|
| 2567 | + // |
|
| 2568 | + // Capacites php (en fonction de la version) |
|
| 2569 | + // |
|
| 2570 | + $GLOBALS['flag_ob'] = (function_exists("ob_start") |
|
| 2571 | + && function_exists("ini_get") |
|
| 2572 | + && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2573 | + $GLOBALS['flag_sapi_name'] = function_exists("php_sapi_name"); |
|
| 2574 | + $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ""); |
|
| 2575 | + $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2576 | + (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2577 | + |
|
| 2578 | + |
|
| 2579 | + // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2580 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2581 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2582 | + } else { |
|
| 2583 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2584 | + if (!empty($_SERVER['QUERY_STRING']) |
|
| 2585 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2586 | + ) { |
|
| 2587 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2588 | + } |
|
| 2589 | + } |
|
| 2590 | + |
|
| 2591 | + // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2592 | + if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2593 | + define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2594 | + } |
|
| 2595 | + if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2596 | + define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2597 | + } |
|
| 2598 | + |
|
| 2599 | + // charger les meta si possible et renouveller l'alea au besoin |
|
| 2600 | + // charge aussi effacer_meta et ecrire_meta |
|
| 2601 | + $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2602 | + $inc_meta(); |
|
| 2603 | + |
|
| 2604 | + // nombre de repertoires depuis la racine |
|
| 2605 | + // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2606 | + // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2607 | + // le calcul est faux) |
|
| 2608 | + if (!_DIR_RESTREINT) { |
|
| 2609 | + $GLOBALS['profondeur_url'] = 1; |
|
| 2610 | + } else { |
|
| 2611 | + $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2612 | + $uri_ref = $_SERVER["SCRIPT_NAME"]; |
|
| 2613 | + if (!$uri_ref |
|
| 2614 | + // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2615 | + // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2616 | + // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2617 | + // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2618 | + or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2619 | + ) { |
|
| 2620 | + |
|
| 2621 | + if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2622 | + $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2623 | + $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/'; |
|
| 2624 | + } else { |
|
| 2625 | + $uri_ref = ""; |
|
| 2626 | + } |
|
| 2627 | + } |
|
| 2628 | + if (!$uri or !$uri_ref) { |
|
| 2629 | + $GLOBALS['profondeur_url'] = 0; |
|
| 2630 | + } else { |
|
| 2631 | + $GLOBALS['profondeur_url'] = max(0, |
|
| 2632 | + substr_count($uri[0], '/') |
|
| 2633 | + - substr_count($uri_ref, '/')); |
|
| 2634 | + } |
|
| 2635 | + } |
|
| 2636 | + // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2637 | + if (_FILE_CONNECT) { |
|
| 2638 | + if (verifier_visiteur() == '0minirezo' |
|
| 2639 | + // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2640 | + and !isset($_COOKIE['spip_admin']) |
|
| 2641 | + ) { |
|
| 2642 | + clear_path_cache(); |
|
| 2643 | + } |
|
| 2644 | + } |
|
| 2646 | 2645 | |
| 2647 | 2646 | } |
| 2648 | 2647 | |
@@ -2652,181 +2651,181 @@ discard block |
||
| 2652 | 2651 | * |
| 2653 | 2652 | */ |
| 2654 | 2653 | function spip_initialisation_suite() { |
| 2655 | - static $too_late = 0; |
|
| 2656 | - if ($too_late++) { |
|
| 2657 | - return; |
|
| 2658 | - } |
|
| 2659 | - |
|
| 2660 | - // taille mini des login |
|
| 2661 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2662 | - define('_LOGIN_TROP_COURT', 4); |
|
| 2663 | - } |
|
| 2664 | - |
|
| 2665 | - // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2666 | - #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2667 | - #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2668 | - #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2669 | - |
|
| 2670 | - // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2671 | - #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2672 | - #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2673 | - #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2674 | - #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2675 | - |
|
| 2676 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2677 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 2678 | - } |
|
| 2679 | - |
|
| 2680 | - |
|
| 2681 | - // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2682 | - if (!defined('_IMG_QUALITE')) { |
|
| 2683 | - define('_IMG_QUALITE', 85); |
|
| 2684 | - } # valeur par defaut |
|
| 2685 | - if (!defined('_IMG_GD_QUALITE')) { |
|
| 2686 | - define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2687 | - } # surcharge pour la lib GD |
|
| 2688 | - if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2689 | - define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2690 | - } # surcharge pour imagick en ligne de commande |
|
| 2691 | - // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2692 | - if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2693 | - define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2694 | - } # surcharge pour imagick en PHP |
|
| 2695 | - |
|
| 2696 | - if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2697 | - define('_COPIE_LOCALE_MAX_SIZE', 33554432); |
|
| 2698 | - } // poids en octet |
|
| 2699 | - |
|
| 2700 | - // qq chaines standard |
|
| 2701 | - if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2702 | - define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2703 | - } |
|
| 2704 | - if (!defined('_AUTH_USER_FILE')) { |
|
| 2705 | - define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2706 | - } |
|
| 2707 | - if (!defined('_SPIP_DUMP')) { |
|
| 2708 | - define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2709 | - } |
|
| 2710 | - if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2711 | - /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2712 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2713 | - } |
|
| 2714 | - if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2715 | - /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2716 | - define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2717 | - } |
|
| 2718 | - |
|
| 2719 | - if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2720 | - /** |
|
| 2721 | - * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2722 | - * @var int Nombre de caractères */ |
|
| 2723 | - define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2724 | - } |
|
| 2725 | - |
|
| 2726 | - if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2727 | - define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2728 | - } |
|
| 2729 | - |
|
| 2730 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2731 | - /** Définit le doctype de l’espace privé */ |
|
| 2732 | - define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2733 | - } |
|
| 2734 | - if (!defined('_DOCTYPE_AIDE')) { |
|
| 2735 | - /** Définit le doctype de l’aide en ligne */ |
|
| 2736 | - define('_DOCTYPE_AIDE', |
|
| 2737 | - "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"); |
|
| 2738 | - } |
|
| 2739 | - |
|
| 2740 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2741 | - /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2742 | - * le script de l'espace public, alias index.php */ |
|
| 2743 | - define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2744 | - } |
|
| 2745 | - if (!defined('_SPIP_PAGE')) { |
|
| 2746 | - /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2747 | - define('_SPIP_PAGE', 'page'); |
|
| 2748 | - } |
|
| 2749 | - |
|
| 2750 | - // le script de l'espace prive |
|
| 2751 | - // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2752 | - // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2753 | - // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2754 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2755 | - if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2756 | - define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2757 | - } else { |
|
| 2758 | - define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2759 | - } |
|
| 2760 | - } |
|
| 2761 | - |
|
| 2762 | - |
|
| 2763 | - if (!defined('_SPIP_AJAX')) { |
|
| 2764 | - define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2765 | - ? 1 |
|
| 2766 | - : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2767 | - } |
|
| 2768 | - |
|
| 2769 | - // La requete est-elle en ajax ? |
|
| 2770 | - if (!defined('_AJAX')) { |
|
| 2771 | - define('_AJAX', |
|
| 2772 | - (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2773 | - or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2774 | - or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2775 | - or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2776 | - ) |
|
| 2777 | - and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2778 | - ); |
|
| 2779 | - } |
|
| 2780 | - |
|
| 2781 | - # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2782 | - # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2783 | - # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2784 | - if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2785 | - define('_IMG_GD_MAX_PIXELS', |
|
| 2786 | - (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2787 | - ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2788 | - : 0); |
|
| 2789 | - } |
|
| 2790 | - |
|
| 2791 | - if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2792 | - define('_MEMORY_LIMIT_MIN', 16); |
|
| 2793 | - } // en Mo |
|
| 2794 | - // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2795 | - // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2796 | - // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2797 | - if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2798 | - if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2799 | - $unit = strtolower(substr($memory, -1)); |
|
| 2800 | - $memory = substr($memory, 0, -1); |
|
| 2801 | - switch ($unit) { |
|
| 2802 | - // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2803 | - case 'g': |
|
| 2804 | - $memory *= 1024; |
|
| 2805 | - case 'm': |
|
| 2806 | - $memory *= 1024; |
|
| 2807 | - case 'k': |
|
| 2808 | - $memory *= 1024; |
|
| 2809 | - } |
|
| 2810 | - if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2811 | - @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2812 | - if (trim(ini_get('memory_limit')) != $m) { |
|
| 2813 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2814 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2815 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2816 | - } |
|
| 2817 | - } |
|
| 2818 | - } else { |
|
| 2819 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2820 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2821 | - } |
|
| 2822 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2823 | - } |
|
| 2824 | - // Protocoles a normaliser dans les chaines de langues |
|
| 2825 | - if (!defined('_PROTOCOLES_STD')) { |
|
| 2826 | - define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2827 | - } |
|
| 2828 | - |
|
| 2829 | - init_var_mode(); |
|
| 2654 | + static $too_late = 0; |
|
| 2655 | + if ($too_late++) { |
|
| 2656 | + return; |
|
| 2657 | + } |
|
| 2658 | + |
|
| 2659 | + // taille mini des login |
|
| 2660 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2661 | + define('_LOGIN_TROP_COURT', 4); |
|
| 2662 | + } |
|
| 2663 | + |
|
| 2664 | + // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2665 | + #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2666 | + #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2667 | + #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2668 | + |
|
| 2669 | + // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2670 | + #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2671 | + #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2672 | + #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2673 | + #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2674 | + |
|
| 2675 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2676 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 2677 | + } |
|
| 2678 | + |
|
| 2679 | + |
|
| 2680 | + // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2681 | + if (!defined('_IMG_QUALITE')) { |
|
| 2682 | + define('_IMG_QUALITE', 85); |
|
| 2683 | + } # valeur par defaut |
|
| 2684 | + if (!defined('_IMG_GD_QUALITE')) { |
|
| 2685 | + define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2686 | + } # surcharge pour la lib GD |
|
| 2687 | + if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2688 | + define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2689 | + } # surcharge pour imagick en ligne de commande |
|
| 2690 | + // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2691 | + if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2692 | + define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2693 | + } # surcharge pour imagick en PHP |
|
| 2694 | + |
|
| 2695 | + if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2696 | + define('_COPIE_LOCALE_MAX_SIZE', 33554432); |
|
| 2697 | + } // poids en octet |
|
| 2698 | + |
|
| 2699 | + // qq chaines standard |
|
| 2700 | + if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2701 | + define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2702 | + } |
|
| 2703 | + if (!defined('_AUTH_USER_FILE')) { |
|
| 2704 | + define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2705 | + } |
|
| 2706 | + if (!defined('_SPIP_DUMP')) { |
|
| 2707 | + define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2708 | + } |
|
| 2709 | + if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2710 | + /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2711 | + define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2712 | + } |
|
| 2713 | + if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2714 | + /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2715 | + define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2716 | + } |
|
| 2717 | + |
|
| 2718 | + if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2719 | + /** |
|
| 2720 | + * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2721 | + * @var int Nombre de caractères */ |
|
| 2722 | + define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2723 | + } |
|
| 2724 | + |
|
| 2725 | + if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2726 | + define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2727 | + } |
|
| 2728 | + |
|
| 2729 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2730 | + /** Définit le doctype de l’espace privé */ |
|
| 2731 | + define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2732 | + } |
|
| 2733 | + if (!defined('_DOCTYPE_AIDE')) { |
|
| 2734 | + /** Définit le doctype de l’aide en ligne */ |
|
| 2735 | + define('_DOCTYPE_AIDE', |
|
| 2736 | + "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"); |
|
| 2737 | + } |
|
| 2738 | + |
|
| 2739 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2740 | + /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2741 | + * le script de l'espace public, alias index.php */ |
|
| 2742 | + define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2743 | + } |
|
| 2744 | + if (!defined('_SPIP_PAGE')) { |
|
| 2745 | + /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2746 | + define('_SPIP_PAGE', 'page'); |
|
| 2747 | + } |
|
| 2748 | + |
|
| 2749 | + // le script de l'espace prive |
|
| 2750 | + // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2751 | + // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2752 | + // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2753 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2754 | + if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2755 | + define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2756 | + } else { |
|
| 2757 | + define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2758 | + } |
|
| 2759 | + } |
|
| 2760 | + |
|
| 2761 | + |
|
| 2762 | + if (!defined('_SPIP_AJAX')) { |
|
| 2763 | + define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2764 | + ? 1 |
|
| 2765 | + : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2766 | + } |
|
| 2767 | + |
|
| 2768 | + // La requete est-elle en ajax ? |
|
| 2769 | + if (!defined('_AJAX')) { |
|
| 2770 | + define('_AJAX', |
|
| 2771 | + (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2772 | + or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2773 | + or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2774 | + or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2775 | + ) |
|
| 2776 | + and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2777 | + ); |
|
| 2778 | + } |
|
| 2779 | + |
|
| 2780 | + # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2781 | + # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2782 | + # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2783 | + if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2784 | + define('_IMG_GD_MAX_PIXELS', |
|
| 2785 | + (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2786 | + ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2787 | + : 0); |
|
| 2788 | + } |
|
| 2789 | + |
|
| 2790 | + if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2791 | + define('_MEMORY_LIMIT_MIN', 16); |
|
| 2792 | + } // en Mo |
|
| 2793 | + // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2794 | + // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2795 | + // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2796 | + if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2797 | + if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2798 | + $unit = strtolower(substr($memory, -1)); |
|
| 2799 | + $memory = substr($memory, 0, -1); |
|
| 2800 | + switch ($unit) { |
|
| 2801 | + // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2802 | + case 'g': |
|
| 2803 | + $memory *= 1024; |
|
| 2804 | + case 'm': |
|
| 2805 | + $memory *= 1024; |
|
| 2806 | + case 'k': |
|
| 2807 | + $memory *= 1024; |
|
| 2808 | + } |
|
| 2809 | + if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2810 | + @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2811 | + if (trim(ini_get('memory_limit')) != $m) { |
|
| 2812 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2813 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2814 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2815 | + } |
|
| 2816 | + } |
|
| 2817 | + } else { |
|
| 2818 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2819 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2820 | + } |
|
| 2821 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2822 | + } |
|
| 2823 | + // Protocoles a normaliser dans les chaines de langues |
|
| 2824 | + if (!defined('_PROTOCOLES_STD')) { |
|
| 2825 | + define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2826 | + } |
|
| 2827 | + |
|
| 2828 | + init_var_mode(); |
|
| 2830 | 2829 | } |
| 2831 | 2830 | |
| 2832 | 2831 | /** |
@@ -2860,133 +2859,133 @@ discard block |
||
| 2860 | 2859 | * ` var_mode` (calcul ou recalcul). |
| 2861 | 2860 | */ |
| 2862 | 2861 | function init_var_mode() { |
| 2863 | - static $done = false; |
|
| 2864 | - if (!$done) { |
|
| 2865 | - |
|
| 2866 | - if (isset($_GET['var_mode'])) { |
|
| 2867 | - $var_mode = explode(',', $_GET['var_mode']); |
|
| 2868 | - // tout le monde peut calcul/recalcul |
|
| 2869 | - if (!defined('_VAR_MODE')) { |
|
| 2870 | - if (in_array('recalcul', $var_mode)) { |
|
| 2871 | - define('_VAR_MODE', 'recalcul'); |
|
| 2872 | - } elseif (in_array('calcul', $var_mode)) { |
|
| 2873 | - define('_VAR_MODE', 'calcul'); |
|
| 2874 | - } |
|
| 2875 | - } |
|
| 2876 | - $var_mode = array_diff($var_mode, array('calcul', 'recalcul')); |
|
| 2877 | - if ($var_mode) { |
|
| 2878 | - include_spip('inc/autoriser'); |
|
| 2879 | - // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 2880 | - if (autoriser( |
|
| 2881 | - ($_GET['var_mode'] == 'preview') |
|
| 2882 | - ? 'previsualiser' |
|
| 2883 | - : 'debug' |
|
| 2884 | - )) { |
|
| 2885 | - if (in_array('traduction', $var_mode)) { |
|
| 2886 | - // forcer le calcul pour passer dans traduire |
|
| 2887 | - if (!defined('_VAR_MODE')) { |
|
| 2888 | - define('_VAR_MODE', 'calcul'); |
|
| 2889 | - } |
|
| 2890 | - // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 2891 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2892 | - define('_VAR_NOCACHE', true); |
|
| 2893 | - } |
|
| 2894 | - $var_mode = array_diff($var_mode, array('traduction')); |
|
| 2895 | - } |
|
| 2896 | - if (in_array('preview', $var_mode)) { |
|
| 2897 | - // basculer sur les criteres de preview dans les boucles |
|
| 2898 | - if (!defined('_VAR_PREVIEW')) { |
|
| 2899 | - define('_VAR_PREVIEW', true); |
|
| 2900 | - } |
|
| 2901 | - // forcer le calcul |
|
| 2902 | - if (!defined('_VAR_MODE')) { |
|
| 2903 | - define('_VAR_MODE', 'calcul'); |
|
| 2904 | - } |
|
| 2905 | - // et ne pas enregistrer de cache |
|
| 2906 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2907 | - define('_VAR_NOCACHE', true); |
|
| 2908 | - } |
|
| 2909 | - $var_mode = array_diff($var_mode, array('preview')); |
|
| 2910 | - } |
|
| 2911 | - if (in_array('inclure', $var_mode)) { |
|
| 2912 | - // forcer le compilo et ignorer les caches existants |
|
| 2913 | - if (!defined('_VAR_MODE')) { |
|
| 2914 | - define('_VAR_MODE', 'calcul'); |
|
| 2915 | - } |
|
| 2916 | - if (!defined('_VAR_INCLURE')) { |
|
| 2917 | - define('_VAR_INCLURE', true); |
|
| 2918 | - } |
|
| 2919 | - // et ne pas enregistrer de cache |
|
| 2920 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2921 | - define('_VAR_NOCACHE', true); |
|
| 2922 | - } |
|
| 2923 | - $var_mode = array_diff($var_mode, array('inclure')); |
|
| 2924 | - } |
|
| 2925 | - if (in_array('urls', $var_mode)) { |
|
| 2926 | - // forcer le compilo et ignorer les caches existants |
|
| 2927 | - if (!defined('_VAR_MODE')) { |
|
| 2928 | - define('_VAR_MODE', 'calcul'); |
|
| 2929 | - } |
|
| 2930 | - if (!defined('_VAR_URLS')) { |
|
| 2931 | - define('_VAR_URLS', true); |
|
| 2932 | - } |
|
| 2933 | - $var_mode = array_diff($var_mode, array('urls')); |
|
| 2934 | - } |
|
| 2935 | - if (in_array('images', $var_mode)) { |
|
| 2936 | - // forcer le compilo et ignorer les caches existants |
|
| 2937 | - if (!defined('_VAR_MODE')) { |
|
| 2938 | - define('_VAR_MODE', 'calcul'); |
|
| 2939 | - } |
|
| 2940 | - // indiquer qu'on doit recalculer les images |
|
| 2941 | - if (!defined('_VAR_IMAGES')) { |
|
| 2942 | - define('_VAR_IMAGES', true); |
|
| 2943 | - } |
|
| 2944 | - $var_mode = array_diff($var_mode, array('images')); |
|
| 2945 | - } |
|
| 2946 | - if (in_array('debug', $var_mode)) { |
|
| 2947 | - if (!defined('_VAR_MODE')) { |
|
| 2948 | - define('_VAR_MODE', 'debug'); |
|
| 2949 | - } |
|
| 2950 | - // et ne pas enregistrer de cache |
|
| 2951 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2952 | - define('_VAR_NOCACHE', true); |
|
| 2953 | - } |
|
| 2954 | - $var_mode = array_diff($var_mode, array('debug')); |
|
| 2955 | - } |
|
| 2956 | - if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 2957 | - define('_VAR_MODE', reset($var_mode)); |
|
| 2958 | - } |
|
| 2959 | - if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 2960 | - spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 2961 | - . " " . _VAR_MODE); |
|
| 2962 | - } |
|
| 2963 | - } // pas autorise ? |
|
| 2964 | - else { |
|
| 2965 | - // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 2966 | - if (!$GLOBALS['visiteur_session'] |
|
| 2967 | - and !empty($_SERVER['HTTP_HOST']) |
|
| 2968 | - and !empty($_SERVER['REQUEST_METHOD']) |
|
| 2969 | - and $_SERVER['REQUEST_METHOD'] === 'GET') { |
|
| 2970 | - $self = self('&', true); |
|
| 2971 | - if (strpos($self, 'page=login') === false) { |
|
| 2972 | - include_spip('inc/headers'); |
|
| 2973 | - $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 2974 | - redirige_par_entete(generer_url_public('login','url=' . rawurlencode($redirect), true)); |
|
| 2975 | - } |
|
| 2976 | - } |
|
| 2977 | - // sinon tant pis |
|
| 2978 | - } |
|
| 2979 | - } |
|
| 2980 | - } |
|
| 2981 | - if (!defined('_VAR_MODE')) { |
|
| 2982 | - /** |
|
| 2983 | - * Indique le mode de calcul ou d'affichage de la page. |
|
| 2984 | - * @see init_var_mode() |
|
| 2985 | - */ |
|
| 2986 | - define('_VAR_MODE', false); |
|
| 2987 | - } |
|
| 2988 | - $done = true; |
|
| 2989 | - } |
|
| 2862 | + static $done = false; |
|
| 2863 | + if (!$done) { |
|
| 2864 | + |
|
| 2865 | + if (isset($_GET['var_mode'])) { |
|
| 2866 | + $var_mode = explode(',', $_GET['var_mode']); |
|
| 2867 | + // tout le monde peut calcul/recalcul |
|
| 2868 | + if (!defined('_VAR_MODE')) { |
|
| 2869 | + if (in_array('recalcul', $var_mode)) { |
|
| 2870 | + define('_VAR_MODE', 'recalcul'); |
|
| 2871 | + } elseif (in_array('calcul', $var_mode)) { |
|
| 2872 | + define('_VAR_MODE', 'calcul'); |
|
| 2873 | + } |
|
| 2874 | + } |
|
| 2875 | + $var_mode = array_diff($var_mode, array('calcul', 'recalcul')); |
|
| 2876 | + if ($var_mode) { |
|
| 2877 | + include_spip('inc/autoriser'); |
|
| 2878 | + // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 2879 | + if (autoriser( |
|
| 2880 | + ($_GET['var_mode'] == 'preview') |
|
| 2881 | + ? 'previsualiser' |
|
| 2882 | + : 'debug' |
|
| 2883 | + )) { |
|
| 2884 | + if (in_array('traduction', $var_mode)) { |
|
| 2885 | + // forcer le calcul pour passer dans traduire |
|
| 2886 | + if (!defined('_VAR_MODE')) { |
|
| 2887 | + define('_VAR_MODE', 'calcul'); |
|
| 2888 | + } |
|
| 2889 | + // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 2890 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2891 | + define('_VAR_NOCACHE', true); |
|
| 2892 | + } |
|
| 2893 | + $var_mode = array_diff($var_mode, array('traduction')); |
|
| 2894 | + } |
|
| 2895 | + if (in_array('preview', $var_mode)) { |
|
| 2896 | + // basculer sur les criteres de preview dans les boucles |
|
| 2897 | + if (!defined('_VAR_PREVIEW')) { |
|
| 2898 | + define('_VAR_PREVIEW', true); |
|
| 2899 | + } |
|
| 2900 | + // forcer le calcul |
|
| 2901 | + if (!defined('_VAR_MODE')) { |
|
| 2902 | + define('_VAR_MODE', 'calcul'); |
|
| 2903 | + } |
|
| 2904 | + // et ne pas enregistrer de cache |
|
| 2905 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2906 | + define('_VAR_NOCACHE', true); |
|
| 2907 | + } |
|
| 2908 | + $var_mode = array_diff($var_mode, array('preview')); |
|
| 2909 | + } |
|
| 2910 | + if (in_array('inclure', $var_mode)) { |
|
| 2911 | + // forcer le compilo et ignorer les caches existants |
|
| 2912 | + if (!defined('_VAR_MODE')) { |
|
| 2913 | + define('_VAR_MODE', 'calcul'); |
|
| 2914 | + } |
|
| 2915 | + if (!defined('_VAR_INCLURE')) { |
|
| 2916 | + define('_VAR_INCLURE', true); |
|
| 2917 | + } |
|
| 2918 | + // et ne pas enregistrer de cache |
|
| 2919 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2920 | + define('_VAR_NOCACHE', true); |
|
| 2921 | + } |
|
| 2922 | + $var_mode = array_diff($var_mode, array('inclure')); |
|
| 2923 | + } |
|
| 2924 | + if (in_array('urls', $var_mode)) { |
|
| 2925 | + // forcer le compilo et ignorer les caches existants |
|
| 2926 | + if (!defined('_VAR_MODE')) { |
|
| 2927 | + define('_VAR_MODE', 'calcul'); |
|
| 2928 | + } |
|
| 2929 | + if (!defined('_VAR_URLS')) { |
|
| 2930 | + define('_VAR_URLS', true); |
|
| 2931 | + } |
|
| 2932 | + $var_mode = array_diff($var_mode, array('urls')); |
|
| 2933 | + } |
|
| 2934 | + if (in_array('images', $var_mode)) { |
|
| 2935 | + // forcer le compilo et ignorer les caches existants |
|
| 2936 | + if (!defined('_VAR_MODE')) { |
|
| 2937 | + define('_VAR_MODE', 'calcul'); |
|
| 2938 | + } |
|
| 2939 | + // indiquer qu'on doit recalculer les images |
|
| 2940 | + if (!defined('_VAR_IMAGES')) { |
|
| 2941 | + define('_VAR_IMAGES', true); |
|
| 2942 | + } |
|
| 2943 | + $var_mode = array_diff($var_mode, array('images')); |
|
| 2944 | + } |
|
| 2945 | + if (in_array('debug', $var_mode)) { |
|
| 2946 | + if (!defined('_VAR_MODE')) { |
|
| 2947 | + define('_VAR_MODE', 'debug'); |
|
| 2948 | + } |
|
| 2949 | + // et ne pas enregistrer de cache |
|
| 2950 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2951 | + define('_VAR_NOCACHE', true); |
|
| 2952 | + } |
|
| 2953 | + $var_mode = array_diff($var_mode, array('debug')); |
|
| 2954 | + } |
|
| 2955 | + if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 2956 | + define('_VAR_MODE', reset($var_mode)); |
|
| 2957 | + } |
|
| 2958 | + if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 2959 | + spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 2960 | + . " " . _VAR_MODE); |
|
| 2961 | + } |
|
| 2962 | + } // pas autorise ? |
|
| 2963 | + else { |
|
| 2964 | + // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 2965 | + if (!$GLOBALS['visiteur_session'] |
|
| 2966 | + and !empty($_SERVER['HTTP_HOST']) |
|
| 2967 | + and !empty($_SERVER['REQUEST_METHOD']) |
|
| 2968 | + and $_SERVER['REQUEST_METHOD'] === 'GET') { |
|
| 2969 | + $self = self('&', true); |
|
| 2970 | + if (strpos($self, 'page=login') === false) { |
|
| 2971 | + include_spip('inc/headers'); |
|
| 2972 | + $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 2973 | + redirige_par_entete(generer_url_public('login','url=' . rawurlencode($redirect), true)); |
|
| 2974 | + } |
|
| 2975 | + } |
|
| 2976 | + // sinon tant pis |
|
| 2977 | + } |
|
| 2978 | + } |
|
| 2979 | + } |
|
| 2980 | + if (!defined('_VAR_MODE')) { |
|
| 2981 | + /** |
|
| 2982 | + * Indique le mode de calcul ou d'affichage de la page. |
|
| 2983 | + * @see init_var_mode() |
|
| 2984 | + */ |
|
| 2985 | + define('_VAR_MODE', false); |
|
| 2986 | + } |
|
| 2987 | + $done = true; |
|
| 2988 | + } |
|
| 2990 | 2989 | } |
| 2991 | 2990 | |
| 2992 | 2991 | // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ; |
@@ -2994,85 +2993,85 @@ discard block |
||
| 2994 | 2993 | // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal') |
| 2995 | 2994 | // https://code.spip.net/@spip_desinfecte |
| 2996 | 2995 | function spip_desinfecte(&$t, $deep = true) { |
| 2997 | - foreach ($t as $key => $val) { |
|
| 2998 | - if (is_string($t[$key])) { |
|
| 2999 | - $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3000 | - } // traiter aussi les "texte_plus" de article_edit |
|
| 3001 | - else { |
|
| 3002 | - if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3003 | - spip_desinfecte($t[$key], $deep); |
|
| 3004 | - } |
|
| 3005 | - } |
|
| 3006 | - } |
|
| 2996 | + foreach ($t as $key => $val) { |
|
| 2997 | + if (is_string($t[$key])) { |
|
| 2998 | + $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 2999 | + } // traiter aussi les "texte_plus" de article_edit |
|
| 3000 | + else { |
|
| 3001 | + if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3002 | + spip_desinfecte($t[$key], $deep); |
|
| 3003 | + } |
|
| 3004 | + } |
|
| 3005 | + } |
|
| 3007 | 3006 | } |
| 3008 | 3007 | |
| 3009 | 3008 | // retourne le statut du visiteur s'il s'annonce |
| 3010 | 3009 | |
| 3011 | 3010 | // https://code.spip.net/@verifier_visiteur |
| 3012 | 3011 | function verifier_visiteur() { |
| 3013 | - // Rq: pour que cette fonction marche depuis mes_options |
|
| 3014 | - // il faut forcer l'init si ce n'est fait |
|
| 3015 | - // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3016 | - // certaines constantes |
|
| 3017 | - @spip_initialisation_core( |
|
| 3018 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3019 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3020 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3021 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3022 | - ); |
|
| 3023 | - |
|
| 3024 | - // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3025 | - // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3026 | - // Attention on separe bien session_nom et nom, pour eviter |
|
| 3027 | - // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3028 | - $variables_session = array('session_nom', 'session_email'); |
|
| 3029 | - foreach ($variables_session as $var) { |
|
| 3030 | - if (_request($var) !== null) { |
|
| 3031 | - $init = true; |
|
| 3032 | - break; |
|
| 3033 | - } |
|
| 3034 | - } |
|
| 3035 | - if (isset($init)) { |
|
| 3036 | - #@spip_initialisation_suite(); |
|
| 3037 | - $session = charger_fonction('session', 'inc'); |
|
| 3038 | - $session(); |
|
| 3039 | - include_spip('inc/texte'); |
|
| 3040 | - foreach ($variables_session as $var) { |
|
| 3041 | - if (($a = _request($var)) !== null) { |
|
| 3042 | - $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3043 | - } |
|
| 3044 | - } |
|
| 3045 | - if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3046 | - $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3047 | - } |
|
| 3048 | - $session($GLOBALS['visiteur_session']); |
|
| 3049 | - |
|
| 3050 | - return 0; |
|
| 3051 | - } |
|
| 3052 | - |
|
| 3053 | - $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3054 | - if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3055 | - |
|
| 3056 | - $session = charger_fonction('session', 'inc'); |
|
| 3057 | - if ($session()) { |
|
| 3058 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3059 | - } |
|
| 3060 | - if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3061 | - include_spip('inc/auth'); |
|
| 3062 | - $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3063 | - } |
|
| 3064 | - if ($h) { |
|
| 3065 | - $GLOBALS['visiteur_session'] = $h; |
|
| 3066 | - |
|
| 3067 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3068 | - } |
|
| 3069 | - } |
|
| 3070 | - |
|
| 3071 | - // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3072 | - include_spip('inc/lang'); |
|
| 3073 | - utiliser_langue_visiteur(); |
|
| 3074 | - |
|
| 3075 | - return false; |
|
| 3012 | + // Rq: pour que cette fonction marche depuis mes_options |
|
| 3013 | + // il faut forcer l'init si ce n'est fait |
|
| 3014 | + // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3015 | + // certaines constantes |
|
| 3016 | + @spip_initialisation_core( |
|
| 3017 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3018 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3019 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3020 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3021 | + ); |
|
| 3022 | + |
|
| 3023 | + // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3024 | + // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3025 | + // Attention on separe bien session_nom et nom, pour eviter |
|
| 3026 | + // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3027 | + $variables_session = array('session_nom', 'session_email'); |
|
| 3028 | + foreach ($variables_session as $var) { |
|
| 3029 | + if (_request($var) !== null) { |
|
| 3030 | + $init = true; |
|
| 3031 | + break; |
|
| 3032 | + } |
|
| 3033 | + } |
|
| 3034 | + if (isset($init)) { |
|
| 3035 | + #@spip_initialisation_suite(); |
|
| 3036 | + $session = charger_fonction('session', 'inc'); |
|
| 3037 | + $session(); |
|
| 3038 | + include_spip('inc/texte'); |
|
| 3039 | + foreach ($variables_session as $var) { |
|
| 3040 | + if (($a = _request($var)) !== null) { |
|
| 3041 | + $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3042 | + } |
|
| 3043 | + } |
|
| 3044 | + if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3045 | + $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3046 | + } |
|
| 3047 | + $session($GLOBALS['visiteur_session']); |
|
| 3048 | + |
|
| 3049 | + return 0; |
|
| 3050 | + } |
|
| 3051 | + |
|
| 3052 | + $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3053 | + if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3054 | + |
|
| 3055 | + $session = charger_fonction('session', 'inc'); |
|
| 3056 | + if ($session()) { |
|
| 3057 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3058 | + } |
|
| 3059 | + if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3060 | + include_spip('inc/auth'); |
|
| 3061 | + $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3062 | + } |
|
| 3063 | + if ($h) { |
|
| 3064 | + $GLOBALS['visiteur_session'] = $h; |
|
| 3065 | + |
|
| 3066 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3067 | + } |
|
| 3068 | + } |
|
| 3069 | + |
|
| 3070 | + // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3071 | + include_spip('inc/lang'); |
|
| 3072 | + utiliser_langue_visiteur(); |
|
| 3073 | + |
|
| 3074 | + return false; |
|
| 3076 | 3075 | } |
| 3077 | 3076 | |
| 3078 | 3077 | |
@@ -3095,21 +3094,21 @@ discard block |
||
| 3095 | 3094 | * - string Langue utilisée. |
| 3096 | 3095 | **/ |
| 3097 | 3096 | function lang_select($lang = null) { |
| 3098 | - static $pile_langues = array(); |
|
| 3099 | - if (!function_exists('changer_langue')) { |
|
| 3100 | - include_spip('inc/lang'); |
|
| 3101 | - } |
|
| 3102 | - if ($lang === null) { |
|
| 3103 | - $lang = array_pop($pile_langues); |
|
| 3104 | - } else { |
|
| 3105 | - array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3106 | - } |
|
| 3107 | - if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3108 | - return $lang; |
|
| 3109 | - } |
|
| 3110 | - changer_langue($lang); |
|
| 3097 | + static $pile_langues = array(); |
|
| 3098 | + if (!function_exists('changer_langue')) { |
|
| 3099 | + include_spip('inc/lang'); |
|
| 3100 | + } |
|
| 3101 | + if ($lang === null) { |
|
| 3102 | + $lang = array_pop($pile_langues); |
|
| 3103 | + } else { |
|
| 3104 | + array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3105 | + } |
|
| 3106 | + if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3107 | + return $lang; |
|
| 3108 | + } |
|
| 3109 | + changer_langue($lang); |
|
| 3111 | 3110 | |
| 3112 | - return $lang; |
|
| 3111 | + return $lang; |
|
| 3113 | 3112 | } |
| 3114 | 3113 | |
| 3115 | 3114 | /** |
@@ -3126,19 +3125,19 @@ discard block |
||
| 3126 | 3125 | * Identifiant de la session |
| 3127 | 3126 | **/ |
| 3128 | 3127 | function spip_session($force = false) { |
| 3129 | - static $session; |
|
| 3130 | - if ($force or !isset($session)) { |
|
| 3131 | - $s = pipeline('definir_session', |
|
| 3132 | - $GLOBALS['visiteur_session'] |
|
| 3133 | - ? serialize($GLOBALS['visiteur_session']) |
|
| 3134 | - . '_' . @$_COOKIE['spip_session'] |
|
| 3135 | - : '' |
|
| 3136 | - ); |
|
| 3137 | - $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3138 | - } |
|
| 3128 | + static $session; |
|
| 3129 | + if ($force or !isset($session)) { |
|
| 3130 | + $s = pipeline('definir_session', |
|
| 3131 | + $GLOBALS['visiteur_session'] |
|
| 3132 | + ? serialize($GLOBALS['visiteur_session']) |
|
| 3133 | + . '_' . @$_COOKIE['spip_session'] |
|
| 3134 | + : '' |
|
| 3135 | + ); |
|
| 3136 | + $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3137 | + } |
|
| 3139 | 3138 | |
| 3140 | - #spip_log('session: '.$session); |
|
| 3141 | - return $session; |
|
| 3139 | + #spip_log('session: '.$session); |
|
| 3140 | + return $session; |
|
| 3142 | 3141 | } |
| 3143 | 3142 | |
| 3144 | 3143 | |
@@ -3157,9 +3156,9 @@ discard block |
||
| 3157 | 3156 | * Lien sur une icone d'aide |
| 3158 | 3157 | **/ |
| 3159 | 3158 | function aider($aide = '', $distante = false) { |
| 3160 | - $aider = charger_fonction('aide', 'inc', true); |
|
| 3159 | + $aider = charger_fonction('aide', 'inc', true); |
|
| 3161 | 3160 | |
| 3162 | - return $aider ? $aider($aide, '', array(), $distante) : ''; |
|
| 3161 | + return $aider ? $aider($aide, '', array(), $distante) : ''; |
|
| 3163 | 3162 | } |
| 3164 | 3163 | |
| 3165 | 3164 | /** |
@@ -3169,24 +3168,24 @@ discard block |
||
| 3169 | 3168 | */ |
| 3170 | 3169 | function exec_info_dist() { |
| 3171 | 3170 | |
| 3172 | - include_spip('inc/autoriser'); |
|
| 3173 | - if (autoriser('phpinfos')) { |
|
| 3174 | - $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3175 | - $cookies_backup = []; |
|
| 3176 | - foreach ($cookies_masques as $k) { |
|
| 3177 | - if (!empty($_COOKIE[$k])) { |
|
| 3178 | - $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3179 | - $_COOKIE[$k] = '******************************'; |
|
| 3180 | - } |
|
| 3181 | - } |
|
| 3182 | - phpinfo(); |
|
| 3183 | - foreach ($cookies_backup as $k => $v) { |
|
| 3184 | - $_COOKIE[$k] = $v; |
|
| 3185 | - } |
|
| 3186 | - } else { |
|
| 3187 | - include_spip('inc/filtres'); |
|
| 3188 | - sinon_interdire_acces(); |
|
| 3189 | - } |
|
| 3171 | + include_spip('inc/autoriser'); |
|
| 3172 | + if (autoriser('phpinfos')) { |
|
| 3173 | + $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3174 | + $cookies_backup = []; |
|
| 3175 | + foreach ($cookies_masques as $k) { |
|
| 3176 | + if (!empty($_COOKIE[$k])) { |
|
| 3177 | + $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3178 | + $_COOKIE[$k] = '******************************'; |
|
| 3179 | + } |
|
| 3180 | + } |
|
| 3181 | + phpinfo(); |
|
| 3182 | + foreach ($cookies_backup as $k => $v) { |
|
| 3183 | + $_COOKIE[$k] = $v; |
|
| 3184 | + } |
|
| 3185 | + } else { |
|
| 3186 | + include_spip('inc/filtres'); |
|
| 3187 | + sinon_interdire_acces(); |
|
| 3188 | + } |
|
| 3190 | 3189 | } |
| 3191 | 3190 | |
| 3192 | 3191 | /** |
@@ -3206,13 +3205,13 @@ discard block |
||
| 3206 | 3205 | * - string si $message à false. |
| 3207 | 3206 | **/ |
| 3208 | 3207 | function erreur_squelette($message = '', $lieu = '') { |
| 3209 | - $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3210 | - if (is_array($lieu)) { |
|
| 3211 | - include_spip('public/compiler'); |
|
| 3212 | - $lieu = reconstruire_contexte_compil($lieu); |
|
| 3213 | - } |
|
| 3208 | + $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3209 | + if (is_array($lieu)) { |
|
| 3210 | + include_spip('public/compiler'); |
|
| 3211 | + $lieu = reconstruire_contexte_compil($lieu); |
|
| 3212 | + } |
|
| 3214 | 3213 | |
| 3215 | - return $debusquer($message, $lieu); |
|
| 3214 | + return $debusquer($message, $lieu); |
|
| 3216 | 3215 | } |
| 3217 | 3216 | |
| 3218 | 3217 | /** |
@@ -3249,109 +3248,109 @@ discard block |
||
| 3249 | 3248 | * - ou tableau d'information sur le squelette. |
| 3250 | 3249 | */ |
| 3251 | 3250 | function recuperer_fond($fond, $contexte = array(), $options = array(), $connect = '') { |
| 3252 | - if (!function_exists('evaluer_fond')) { |
|
| 3253 | - include_spip('public/assembler'); |
|
| 3254 | - } |
|
| 3255 | - // assurer la compat avec l'ancienne syntaxe |
|
| 3256 | - // (trim etait le 3eme argument, par defaut a true) |
|
| 3257 | - if (!is_array($options)) { |
|
| 3258 | - $options = array('trim' => $options); |
|
| 3259 | - } |
|
| 3260 | - if (!isset($options['trim'])) { |
|
| 3261 | - $options['trim'] = true; |
|
| 3262 | - } |
|
| 3263 | - |
|
| 3264 | - if (isset($contexte['connect'])) { |
|
| 3265 | - $connect = $contexte['connect']; |
|
| 3266 | - unset($contexte['connect']); |
|
| 3267 | - } |
|
| 3268 | - |
|
| 3269 | - $texte = ""; |
|
| 3270 | - $pages = array(); |
|
| 3271 | - $lang_select = ''; |
|
| 3272 | - if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3273 | - // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3274 | - if (!isset($contexte['lang'])) { |
|
| 3275 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3276 | - } |
|
| 3277 | - |
|
| 3278 | - if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3279 | - $lang_select = lang_select($contexte['lang']); |
|
| 3280 | - } |
|
| 3281 | - } |
|
| 3282 | - |
|
| 3283 | - if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3284 | - $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3285 | - } |
|
| 3286 | - |
|
| 3287 | - $GLOBALS['_INC_PUBLIC']++; |
|
| 3288 | - |
|
| 3289 | - // fix #4235 |
|
| 3290 | - $cache_utilise_session_appelant = (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null); |
|
| 3291 | - |
|
| 3292 | - |
|
| 3293 | - foreach (is_array($fond) ? $fond : array($fond) as $f) { |
|
| 3251 | + if (!function_exists('evaluer_fond')) { |
|
| 3252 | + include_spip('public/assembler'); |
|
| 3253 | + } |
|
| 3254 | + // assurer la compat avec l'ancienne syntaxe |
|
| 3255 | + // (trim etait le 3eme argument, par defaut a true) |
|
| 3256 | + if (!is_array($options)) { |
|
| 3257 | + $options = array('trim' => $options); |
|
| 3258 | + } |
|
| 3259 | + if (!isset($options['trim'])) { |
|
| 3260 | + $options['trim'] = true; |
|
| 3261 | + } |
|
| 3262 | + |
|
| 3263 | + if (isset($contexte['connect'])) { |
|
| 3264 | + $connect = $contexte['connect']; |
|
| 3265 | + unset($contexte['connect']); |
|
| 3266 | + } |
|
| 3267 | + |
|
| 3268 | + $texte = ""; |
|
| 3269 | + $pages = array(); |
|
| 3270 | + $lang_select = ''; |
|
| 3271 | + if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3272 | + // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3273 | + if (!isset($contexte['lang'])) { |
|
| 3274 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3275 | + } |
|
| 3276 | + |
|
| 3277 | + if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3278 | + $lang_select = lang_select($contexte['lang']); |
|
| 3279 | + } |
|
| 3280 | + } |
|
| 3281 | + |
|
| 3282 | + if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3283 | + $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3284 | + } |
|
| 3285 | + |
|
| 3286 | + $GLOBALS['_INC_PUBLIC']++; |
|
| 3287 | + |
|
| 3288 | + // fix #4235 |
|
| 3289 | + $cache_utilise_session_appelant = (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null); |
|
| 3290 | + |
|
| 3291 | + |
|
| 3292 | + foreach (is_array($fond) ? $fond : array($fond) as $f) { |
|
| 3294 | 3293 | |
| 3295 | - unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3296 | - |
|
| 3297 | - $page = evaluer_fond($f, $contexte, $connect); |
|
| 3298 | - if ($page === '') { |
|
| 3299 | - $c = isset($options['compil']) ? $options['compil'] : ''; |
|
| 3300 | - $a = array('fichier' => $f); |
|
| 3301 | - $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3302 | - erreur_squelette($erreur, $c); |
|
| 3303 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3304 | - $page = array('texte' => '', 'erreur' => $erreur); |
|
| 3305 | - } |
|
| 3306 | - |
|
| 3307 | - $page = pipeline('recuperer_fond', array( |
|
| 3308 | - 'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect), |
|
| 3309 | - 'data' => $page |
|
| 3310 | - )); |
|
| 3311 | - if (isset($options['ajax']) and $options['ajax']) { |
|
| 3312 | - if (!function_exists('encoder_contexte_ajax')) { |
|
| 3313 | - include_spip('inc/filtres'); |
|
| 3314 | - } |
|
| 3315 | - $page['texte'] = encoder_contexte_ajax( |
|
| 3316 | - array_merge( |
|
| 3317 | - $contexte, |
|
| 3318 | - array('fond' => $f), |
|
| 3319 | - ($connect ? array('connect' => $connect) : array()) |
|
| 3320 | - ), |
|
| 3321 | - '', |
|
| 3322 | - $page['texte'], |
|
| 3323 | - $options['ajax'] |
|
| 3324 | - ); |
|
| 3325 | - } |
|
| 3326 | - |
|
| 3327 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3328 | - $pages[] = $page; |
|
| 3329 | - } else { |
|
| 3330 | - $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3331 | - } |
|
| 3294 | + unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3295 | + |
|
| 3296 | + $page = evaluer_fond($f, $contexte, $connect); |
|
| 3297 | + if ($page === '') { |
|
| 3298 | + $c = isset($options['compil']) ? $options['compil'] : ''; |
|
| 3299 | + $a = array('fichier' => $f); |
|
| 3300 | + $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3301 | + erreur_squelette($erreur, $c); |
|
| 3302 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3303 | + $page = array('texte' => '', 'erreur' => $erreur); |
|
| 3304 | + } |
|
| 3305 | + |
|
| 3306 | + $page = pipeline('recuperer_fond', array( |
|
| 3307 | + 'args' => array('fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect), |
|
| 3308 | + 'data' => $page |
|
| 3309 | + )); |
|
| 3310 | + if (isset($options['ajax']) and $options['ajax']) { |
|
| 3311 | + if (!function_exists('encoder_contexte_ajax')) { |
|
| 3312 | + include_spip('inc/filtres'); |
|
| 3313 | + } |
|
| 3314 | + $page['texte'] = encoder_contexte_ajax( |
|
| 3315 | + array_merge( |
|
| 3316 | + $contexte, |
|
| 3317 | + array('fond' => $f), |
|
| 3318 | + ($connect ? array('connect' => $connect) : array()) |
|
| 3319 | + ), |
|
| 3320 | + '', |
|
| 3321 | + $page['texte'], |
|
| 3322 | + $options['ajax'] |
|
| 3323 | + ); |
|
| 3324 | + } |
|
| 3325 | + |
|
| 3326 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3327 | + $pages[] = $page; |
|
| 3328 | + } else { |
|
| 3329 | + $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3330 | + } |
|
| 3332 | 3331 | |
| 3333 | - // contamination de la session appelante, pour les inclusions statiques |
|
| 3334 | - if (isset($page['invalideurs']['session'])){ |
|
| 3335 | - $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3336 | - } |
|
| 3337 | - } |
|
| 3332 | + // contamination de la session appelante, pour les inclusions statiques |
|
| 3333 | + if (isset($page['invalideurs']['session'])){ |
|
| 3334 | + $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3335 | + } |
|
| 3336 | + } |
|
| 3338 | 3337 | |
| 3339 | - // restaurer le sessionnement du contexte appelant, |
|
| 3340 | - // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3341 | - if (isset($cache_utilise_session_appelant)) { |
|
| 3342 | - $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3343 | - } |
|
| 3338 | + // restaurer le sessionnement du contexte appelant, |
|
| 3339 | + // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3340 | + if (isset($cache_utilise_session_appelant)) { |
|
| 3341 | + $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3342 | + } |
|
| 3344 | 3343 | |
| 3345 | - $GLOBALS['_INC_PUBLIC']--; |
|
| 3344 | + $GLOBALS['_INC_PUBLIC']--; |
|
| 3346 | 3345 | |
| 3347 | - if ($lang_select) { |
|
| 3348 | - lang_select(); |
|
| 3349 | - } |
|
| 3350 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3351 | - return is_array($fond) ? $pages : reset($pages); |
|
| 3352 | - } else { |
|
| 3353 | - return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3354 | - } |
|
| 3346 | + if ($lang_select) { |
|
| 3347 | + lang_select(); |
|
| 3348 | + } |
|
| 3349 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3350 | + return is_array($fond) ? $pages : reset($pages); |
|
| 3351 | + } else { |
|
| 3352 | + return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3353 | + } |
|
| 3355 | 3354 | } |
| 3356 | 3355 | |
| 3357 | 3356 | /** |
@@ -3361,7 +3360,7 @@ discard block |
||
| 3361 | 3360 | * @return string |
| 3362 | 3361 | */ |
| 3363 | 3362 | function trouve_modele($nom) { |
| 3364 | - return trouver_fond($nom, 'modeles/'); |
|
| 3363 | + return trouver_fond($nom, 'modeles/'); |
|
| 3365 | 3364 | } |
| 3366 | 3365 | |
| 3367 | 3366 | /** |
@@ -3377,21 +3376,21 @@ discard block |
||
| 3377 | 3376 | * @return array|string |
| 3378 | 3377 | */ |
| 3379 | 3378 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 3380 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3381 | - if (!$pathinfo) { |
|
| 3382 | - return $f; |
|
| 3383 | - } |
|
| 3384 | - // renvoyer un tableau detaille si $pathinfo==true |
|
| 3385 | - $p = pathinfo($f); |
|
| 3386 | - if (!isset($p['extension']) or !$p['extension']) { |
|
| 3387 | - $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3388 | - } |
|
| 3389 | - if (!isset($p['extension']) or !$p['filename']) { |
|
| 3390 | - $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3391 | - } |
|
| 3392 | - $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3379 | + $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3380 | + if (!$pathinfo) { |
|
| 3381 | + return $f; |
|
| 3382 | + } |
|
| 3383 | + // renvoyer un tableau detaille si $pathinfo==true |
|
| 3384 | + $p = pathinfo($f); |
|
| 3385 | + if (!isset($p['extension']) or !$p['extension']) { |
|
| 3386 | + $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3387 | + } |
|
| 3388 | + if (!isset($p['extension']) or !$p['filename']) { |
|
| 3389 | + $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3390 | + } |
|
| 3391 | + $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3393 | 3392 | |
| 3394 | - return $p; |
|
| 3393 | + return $p; |
|
| 3395 | 3394 | } |
| 3396 | 3395 | |
| 3397 | 3396 | /** |
@@ -3411,21 +3410,21 @@ discard block |
||
| 3411 | 3410 | * Nom de l'exec, sinon chaîne vide. |
| 3412 | 3411 | **/ |
| 3413 | 3412 | function tester_url_ecrire($nom) { |
| 3414 | - static $exec = array(); |
|
| 3415 | - if (isset($exec[$nom])) { |
|
| 3416 | - return $exec[$nom]; |
|
| 3417 | - } |
|
| 3418 | - // tester si c'est une page en squelette |
|
| 3419 | - if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3420 | - return $exec[$nom] = 'fond'; |
|
| 3421 | - } // echafaudage d'un fond ! |
|
| 3422 | - elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3423 | - return $exec[$nom] = 'fond'; |
|
| 3424 | - } |
|
| 3425 | - // attention, il ne faut pas inclure l'exec ici |
|
| 3426 | - // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3427 | - // et des define intrusifs potentiels |
|
| 3428 | - return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3413 | + static $exec = array(); |
|
| 3414 | + if (isset($exec[$nom])) { |
|
| 3415 | + return $exec[$nom]; |
|
| 3416 | + } |
|
| 3417 | + // tester si c'est une page en squelette |
|
| 3418 | + if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3419 | + return $exec[$nom] = 'fond'; |
|
| 3420 | + } // echafaudage d'un fond ! |
|
| 3421 | + elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3422 | + return $exec[$nom] = 'fond'; |
|
| 3423 | + } |
|
| 3424 | + // attention, il ne faut pas inclure l'exec ici |
|
| 3425 | + // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3426 | + // et des define intrusifs potentiels |
|
| 3427 | + return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3429 | 3428 | } |
| 3430 | 3429 | |
| 3431 | 3430 | /** |
@@ -3435,8 +3434,8 @@ discard block |
||
| 3435 | 3434 | * true si la constante _VERSION_HTML n'est pas définie ou égale à html5 |
| 3436 | 3435 | **/ |
| 3437 | 3436 | function html5_permis() { |
| 3438 | - return (!defined('_VERSION_HTML') |
|
| 3439 | - or _VERSION_HTML !== 'html4'); |
|
| 3437 | + return (!defined('_VERSION_HTML') |
|
| 3438 | + or _VERSION_HTML !== 'html4'); |
|
| 3440 | 3439 | } |
| 3441 | 3440 | |
| 3442 | 3441 | /** |
@@ -3446,30 +3445,30 @@ discard block |
||
| 3446 | 3445 | * @return array |
| 3447 | 3446 | */ |
| 3448 | 3447 | function formats_image_acceptables($gd = null, $svg_allowed = true) { |
| 3449 | - $formats = null; |
|
| 3450 | - if (!is_null($gd)) { |
|
| 3451 | - $config = ($gd ? "gd_formats" : "formats_graphiques"); |
|
| 3452 | - if (isset($GLOBALS['meta'][$config])) { |
|
| 3453 | - $formats = $GLOBALS['meta'][$config]; |
|
| 3454 | - $formats = explode(',', $formats); |
|
| 3455 | - $formats = array_filter($formats); |
|
| 3456 | - $formats = array_map('trim', $formats); |
|
| 3457 | - } |
|
| 3458 | - } |
|
| 3459 | - if (is_null($formats)) { |
|
| 3460 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 3461 | - $formats = _image_extensions_acceptees_en_entree(); |
|
| 3462 | - } |
|
| 3463 | - |
|
| 3464 | - if ($svg_allowed) { |
|
| 3465 | - if (!in_array('svg', $formats)) { |
|
| 3466 | - $formats[] = 'svg'; |
|
| 3467 | - } |
|
| 3468 | - } |
|
| 3469 | - else { |
|
| 3470 | - $formats = array_diff($formats, ['svg']); |
|
| 3471 | - } |
|
| 3472 | - return $formats; |
|
| 3448 | + $formats = null; |
|
| 3449 | + if (!is_null($gd)) { |
|
| 3450 | + $config = ($gd ? "gd_formats" : "formats_graphiques"); |
|
| 3451 | + if (isset($GLOBALS['meta'][$config])) { |
|
| 3452 | + $formats = $GLOBALS['meta'][$config]; |
|
| 3453 | + $formats = explode(',', $formats); |
|
| 3454 | + $formats = array_filter($formats); |
|
| 3455 | + $formats = array_map('trim', $formats); |
|
| 3456 | + } |
|
| 3457 | + } |
|
| 3458 | + if (is_null($formats)) { |
|
| 3459 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 3460 | + $formats = _image_extensions_acceptees_en_entree(); |
|
| 3461 | + } |
|
| 3462 | + |
|
| 3463 | + if ($svg_allowed) { |
|
| 3464 | + if (!in_array('svg', $formats)) { |
|
| 3465 | + $formats[] = 'svg'; |
|
| 3466 | + } |
|
| 3467 | + } |
|
| 3468 | + else { |
|
| 3469 | + $formats = array_diff($formats, ['svg']); |
|
| 3470 | + } |
|
| 3471 | + return $formats; |
|
| 3473 | 3472 | } |
| 3474 | 3473 | |
| 3475 | 3474 | /** |
@@ -3478,21 +3477,21 @@ discard block |
||
| 3478 | 3477 | * @return array|bool |
| 3479 | 3478 | */ |
| 3480 | 3479 | function spip_getimagesize($fichier) { |
| 3481 | - if (!$imagesize = @getimagesize($fichier)) { |
|
| 3480 | + if (!$imagesize = @getimagesize($fichier)) { |
|
| 3482 | 3481 | |
| 3483 | - include_spip("inc/svg"); |
|
| 3484 | - if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3485 | - list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 3486 | - $imagesize = [ |
|
| 3487 | - $width, |
|
| 3488 | - $height, |
|
| 3489 | - IMAGETYPE_SVG, |
|
| 3490 | - "width=\"{$width}\" height=\"{$height}\"", |
|
| 3491 | - "mime" => "image/svg+xml" |
|
| 3492 | - ]; |
|
| 3493 | - } |
|
| 3494 | - } |
|
| 3495 | - return $imagesize; |
|
| 3482 | + include_spip("inc/svg"); |
|
| 3483 | + if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3484 | + list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 3485 | + $imagesize = [ |
|
| 3486 | + $width, |
|
| 3487 | + $height, |
|
| 3488 | + IMAGETYPE_SVG, |
|
| 3489 | + "width=\"{$width}\" height=\"{$height}\"", |
|
| 3490 | + "mime" => "image/svg+xml" |
|
| 3491 | + ]; |
|
| 3492 | + } |
|
| 3493 | + } |
|
| 3494 | + return $imagesize; |
|
| 3496 | 3495 | } |
| 3497 | 3496 | |
| 3498 | 3497 | |
@@ -3512,7 +3511,7 @@ discard block |
||
| 3512 | 3511 | * @return mixed Valeur de la meta. |
| 3513 | 3512 | **/ |
| 3514 | 3513 | function lire_meta($nom) { |
| 3515 | - return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null; |
|
| 3514 | + return isset($GLOBALS['meta'][$nom]) ? $GLOBALS['meta'][$nom] : null; |
|
| 3516 | 3515 | } |
| 3517 | 3516 | |
| 3518 | 3517 | /** |
@@ -3526,18 +3525,18 @@ discard block |
||
| 3526 | 3525 | * @param string $statut |
| 3527 | 3526 | */ |
| 3528 | 3527 | function avertir_auteurs($nom, $message, $statut = '') { |
| 3529 | - $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3530 | - if (!$alertes |
|
| 3531 | - or !is_array($alertes = unserialize($alertes)) |
|
| 3532 | - ) { |
|
| 3533 | - $alertes = array(); |
|
| 3534 | - } |
|
| 3528 | + $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3529 | + if (!$alertes |
|
| 3530 | + or !is_array($alertes = unserialize($alertes)) |
|
| 3531 | + ) { |
|
| 3532 | + $alertes = array(); |
|
| 3533 | + } |
|
| 3535 | 3534 | |
| 3536 | - if (!isset($alertes[$statut])) { |
|
| 3537 | - $alertes[$statut] = array(); |
|
| 3538 | - } |
|
| 3539 | - $alertes[$statut][$nom] = $message; |
|
| 3540 | - ecrire_meta("message_alertes_auteurs", serialize($alertes)); |
|
| 3535 | + if (!isset($alertes[$statut])) { |
|
| 3536 | + $alertes[$statut] = array(); |
|
| 3537 | + } |
|
| 3538 | + $alertes[$statut][$nom] = $message; |
|
| 3539 | + ecrire_meta("message_alertes_auteurs", serialize($alertes)); |
|
| 3541 | 3540 | } |
| 3542 | 3541 | |
| 3543 | 3542 | /** |
@@ -3551,10 +3550,10 @@ discard block |
||
| 3551 | 3550 | * @return string|string[] |
| 3552 | 3551 | */ |
| 3553 | 3552 | function spip_sanitize_classname($classes) { |
| 3554 | - if (is_array($classes)) { |
|
| 3555 | - return array_map('spip_sanitize_classname', $classes); |
|
| 3556 | - } |
|
| 3557 | - return preg_replace("/[^ 0-9a-z_\-+@]/i", "", $classes); |
|
| 3553 | + if (is_array($classes)) { |
|
| 3554 | + return array_map('spip_sanitize_classname', $classes); |
|
| 3555 | + } |
|
| 3556 | + return preg_replace("/[^ 0-9a-z_\-+@]/i", "", $classes); |
|
| 3558 | 3557 | } |
| 3559 | 3558 | |
| 3560 | 3559 | |
@@ -3579,32 +3578,32 @@ discard block |
||
| 3579 | 3578 | * Avec operateur : bool. |
| 3580 | 3579 | **/ |
| 3581 | 3580 | function spip_version_compare($v1, $v2, $op = null) { |
| 3582 | - $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3583 | - $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3584 | - $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3585 | - $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3586 | - |
|
| 3587 | - $v1 = explode('.', $v1); |
|
| 3588 | - $v2 = explode('.', $v2); |
|
| 3589 | - // $v1 est toujours une version, donc sans etoile |
|
| 3590 | - while (count($v1) < count($v2)) { |
|
| 3591 | - $v1[] = '0'; |
|
| 3592 | - } |
|
| 3593 | - |
|
| 3594 | - // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3595 | - $etoile = false; |
|
| 3596 | - foreach ($v1 as $k => $v) { |
|
| 3597 | - if (!isset($v2[$k])) { |
|
| 3598 | - $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3599 | - } else { |
|
| 3600 | - if ($v2[$k] == '*') { |
|
| 3601 | - $etoile = true; |
|
| 3602 | - $v2[$k] = $v; |
|
| 3603 | - } |
|
| 3604 | - } |
|
| 3605 | - } |
|
| 3606 | - $v1 = implode('.', $v1); |
|
| 3607 | - $v2 = implode('.', $v2); |
|
| 3608 | - |
|
| 3609 | - return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3581 | + $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3582 | + $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3583 | + $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3584 | + $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3585 | + |
|
| 3586 | + $v1 = explode('.', $v1); |
|
| 3587 | + $v2 = explode('.', $v2); |
|
| 3588 | + // $v1 est toujours une version, donc sans etoile |
|
| 3589 | + while (count($v1) < count($v2)) { |
|
| 3590 | + $v1[] = '0'; |
|
| 3591 | + } |
|
| 3592 | + |
|
| 3593 | + // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3594 | + $etoile = false; |
|
| 3595 | + foreach ($v1 as $k => $v) { |
|
| 3596 | + if (!isset($v2[$k])) { |
|
| 3597 | + $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3598 | + } else { |
|
| 3599 | + if ($v2[$k] == '*') { |
|
| 3600 | + $etoile = true; |
|
| 3601 | + $v2[$k] = $v; |
|
| 3602 | + } |
|
| 3603 | + } |
|
| 3604 | + } |
|
| 3605 | + $v1 = implode('.', $v1); |
|
| 3606 | + $v2 = implode('.', $v2); |
|
| 3607 | + |
|
| 3608 | + return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3610 | 3609 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Notifications |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function inc_notifications_dist($quoi, $id = 0, $options = array()) { |
| 35 | 35 | |
| 36 | - // charger les fichiers qui veulent ajouter des definitions |
|
| 37 | - // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 38 | - pipeline('notifications', array('args' => array('quoi' => $quoi, 'id' => $id, 'options' => $options))); |
|
| 36 | + // charger les fichiers qui veulent ajouter des definitions |
|
| 37 | + // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 38 | + pipeline('notifications', array('args' => array('quoi' => $quoi, 'id' => $id, 'options' => $options))); |
|
| 39 | 39 | |
| 40 | - if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 41 | - spip_log("$notification($quoi,$id" |
|
| 42 | - . ($options ? "," . serialize($options) : "") |
|
| 43 | - . ")", 'notifications'); |
|
| 44 | - $notification($quoi, $id, $options); |
|
| 45 | - } |
|
| 40 | + if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 41 | + spip_log("$notification($quoi,$id" |
|
| 42 | + . ($options ? "," . serialize($options) : "") |
|
| 43 | + . ")", 'notifications'); |
|
| 44 | + $notification($quoi, $id, $options); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | * @param array $exclure |
| 57 | 57 | */ |
| 58 | 58 | function notifications_nettoyer_emails(&$emails, $exclure = array()) { |
| 59 | - // filtrer et unifier |
|
| 60 | - $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 61 | - if ($exclure and count($exclure)) { |
|
| 62 | - // nettoyer les exclusions d'abord |
|
| 63 | - notifications_nettoyer_emails($exclure); |
|
| 64 | - // faire un diff |
|
| 65 | - $emails = array_diff($emails, $exclure); |
|
| 66 | - } |
|
| 59 | + // filtrer et unifier |
|
| 60 | + $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 61 | + if ($exclure and count($exclure)) { |
|
| 62 | + // nettoyer les exclusions d'abord |
|
| 63 | + notifications_nettoyer_emails($exclure); |
|
| 64 | + // faire un diff |
|
| 65 | + $emails = array_diff($emails, $exclure); |
|
| 66 | + } |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -78,86 +78,86 @@ discard block |
||
| 78 | 78 | * @param string $headers |
| 79 | 79 | */ |
| 80 | 80 | function notifications_envoyer_mails($emails, $texte, $sujet = "", $from = "", $headers = "") { |
| 81 | - // rien a faire si pas de texte ! |
|
| 82 | - if (!strlen($texte)) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 87 | - if (!is_array($emails)) { |
|
| 88 | - $emails = explode(',', $emails); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - notifications_nettoyer_emails($emails); |
|
| 92 | - |
|
| 93 | - // tester si le mail est deja en html |
|
| 94 | - if (strpos($texte, "<") !== false // eviter les tests suivants si possible |
|
| 95 | - and $ttrim = trim($texte) |
|
| 96 | - and substr($ttrim, 0, 1) == "<" |
|
| 97 | - and substr($ttrim, -1, 1) == ">" |
|
| 98 | - and stripos($ttrim, "</html>") !== false |
|
| 99 | - ) { |
|
| 100 | - |
|
| 101 | - if (!strlen($sujet)) { |
|
| 102 | - // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 103 | - if (preg_match(",<title>(.*)</title>,Uims", $texte, $m)) { |
|
| 104 | - $sujet = $m[1]; |
|
| 105 | - } else { |
|
| 106 | - // fallback, on prend le body si on le trouve |
|
| 107 | - if (preg_match(",<body[^>]*>(.*)</body>,Uims", $texte, $m)) { |
|
| 108 | - $ttrim = $m[1]; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // et on extrait la premiere ligne de vrai texte... |
|
| 112 | - // nettoyer le html et les retours chariots |
|
| 113 | - $ttrim = textebrut($ttrim); |
|
| 114 | - $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 115 | - $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 116 | - // decouper |
|
| 117 | - $ttrim = explode("\n", trim($ttrim)); |
|
| 118 | - // extraire la premiere ligne de texte brut |
|
| 119 | - $sujet = array_shift($ttrim); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // si besoin on ajoute le content-type dans les headers |
|
| 124 | - if (stripos($headers, "Content-Type") === false) { |
|
| 125 | - $headers .= "Content-Type: text/html\n"; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // si le sujet est vide, extraire la premiere ligne du corps |
|
| 130 | - // du mail qui est donc du texte |
|
| 131 | - if (!strlen($sujet)) { |
|
| 132 | - // nettoyer un peu les retours chariots |
|
| 133 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 134 | - $texte = str_replace("\r", "\n", $texte); |
|
| 135 | - // decouper |
|
| 136 | - $texte = explode("\n", trim($texte)); |
|
| 137 | - // extraire la premiere ligne |
|
| 138 | - $sujet = array_shift($texte); |
|
| 139 | - $texte = trim(implode("\n", $texte)); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 143 | - foreach ($emails as $email) { |
|
| 144 | - // passer dans un pipeline qui permet un ajout eventuel |
|
| 145 | - // (url de suivi des notifications par exemple) |
|
| 146 | - $envoi = pipeline( |
|
| 147 | - 'notifications_envoyer_mails', |
|
| 148 | - array( |
|
| 149 | - 'email' => $email, |
|
| 150 | - 'sujet' => $sujet, |
|
| 151 | - 'texte' => $texte, |
|
| 152 | - 'from' => $from, |
|
| 153 | - 'headers' => $headers, |
|
| 154 | - ) |
|
| 155 | - ); |
|
| 156 | - $email = $envoi['email']; |
|
| 157 | - |
|
| 158 | - job_queue_add('envoyer_mail', ">$email : " . $envoi['sujet'], |
|
| 159 | - array($email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']), 'inc/'); |
|
| 160 | - } |
|
| 81 | + // rien a faire si pas de texte ! |
|
| 82 | + if (!strlen($texte)) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 87 | + if (!is_array($emails)) { |
|
| 88 | + $emails = explode(',', $emails); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + notifications_nettoyer_emails($emails); |
|
| 92 | + |
|
| 93 | + // tester si le mail est deja en html |
|
| 94 | + if (strpos($texte, "<") !== false // eviter les tests suivants si possible |
|
| 95 | + and $ttrim = trim($texte) |
|
| 96 | + and substr($ttrim, 0, 1) == "<" |
|
| 97 | + and substr($ttrim, -1, 1) == ">" |
|
| 98 | + and stripos($ttrim, "</html>") !== false |
|
| 99 | + ) { |
|
| 100 | + |
|
| 101 | + if (!strlen($sujet)) { |
|
| 102 | + // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 103 | + if (preg_match(",<title>(.*)</title>,Uims", $texte, $m)) { |
|
| 104 | + $sujet = $m[1]; |
|
| 105 | + } else { |
|
| 106 | + // fallback, on prend le body si on le trouve |
|
| 107 | + if (preg_match(",<body[^>]*>(.*)</body>,Uims", $texte, $m)) { |
|
| 108 | + $ttrim = $m[1]; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // et on extrait la premiere ligne de vrai texte... |
|
| 112 | + // nettoyer le html et les retours chariots |
|
| 113 | + $ttrim = textebrut($ttrim); |
|
| 114 | + $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 115 | + $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 116 | + // decouper |
|
| 117 | + $ttrim = explode("\n", trim($ttrim)); |
|
| 118 | + // extraire la premiere ligne de texte brut |
|
| 119 | + $sujet = array_shift($ttrim); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // si besoin on ajoute le content-type dans les headers |
|
| 124 | + if (stripos($headers, "Content-Type") === false) { |
|
| 125 | + $headers .= "Content-Type: text/html\n"; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // si le sujet est vide, extraire la premiere ligne du corps |
|
| 130 | + // du mail qui est donc du texte |
|
| 131 | + if (!strlen($sujet)) { |
|
| 132 | + // nettoyer un peu les retours chariots |
|
| 133 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 134 | + $texte = str_replace("\r", "\n", $texte); |
|
| 135 | + // decouper |
|
| 136 | + $texte = explode("\n", trim($texte)); |
|
| 137 | + // extraire la premiere ligne |
|
| 138 | + $sujet = array_shift($texte); |
|
| 139 | + $texte = trim(implode("\n", $texte)); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 143 | + foreach ($emails as $email) { |
|
| 144 | + // passer dans un pipeline qui permet un ajout eventuel |
|
| 145 | + // (url de suivi des notifications par exemple) |
|
| 146 | + $envoi = pipeline( |
|
| 147 | + 'notifications_envoyer_mails', |
|
| 148 | + array( |
|
| 149 | + 'email' => $email, |
|
| 150 | + 'sujet' => $sujet, |
|
| 151 | + 'texte' => $texte, |
|
| 152 | + 'from' => $from, |
|
| 153 | + 'headers' => $headers, |
|
| 154 | + ) |
|
| 155 | + ); |
|
| 156 | + $email = $envoi['email']; |
|
| 157 | + |
|
| 158 | + job_queue_add('envoyer_mail', ">$email : " . $envoi['sujet'], |
|
| 159 | + array($email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']), 'inc/'); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | } |
| 163 | 163 | |
@@ -174,10 +174,10 @@ discard block |
||
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | 176 | function email_notification_objet($id_objet, $type_objet, $modele) { |
| 177 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 178 | - $id_type = id_table_objet($type_objet); |
|
| 177 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 178 | + $id_type = id_table_objet($type_objet); |
|
| 179 | 179 | |
| 180 | - return recuperer_fond($modele, array($id_type => $id_objet, "id" => $id_objet)); |
|
| 180 | + return recuperer_fond($modele, array($id_type => $id_objet, "id" => $id_objet)); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | 194 | function email_notification_article($id_article, $modele) { |
| 195 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 195 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 196 | 196 | |
| 197 | - return recuperer_fond($modele, array('id_article' => $id_article)); |
|
| 197 | + return recuperer_fond($modele, array('id_article' => $id_article)); |
|
| 198 | 198 | } |