@@ -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,112 +41,112 @@ 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 | - try { |
|
| 50 | - if ( |
|
| 51 | - $port and !is_numeric($socket = $port) |
|
| 52 | - and (!$host or $host === 'localhost') |
|
| 53 | - ) { |
|
| 54 | - $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 55 | - } elseif ($port) { |
|
| 56 | - $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 57 | - } else { |
|
| 58 | - $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | - } |
|
| 60 | - } catch (\mysqli_sql_exception $e) { |
|
| 61 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 62 | - $link = false; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if (!$link) { |
|
| 66 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 67 | - |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - $last = ''; |
|
| 71 | - if (!$db) { |
|
| 72 | - $ok = $link; |
|
| 73 | - $db = 'spip'; |
|
| 74 | - } else { |
|
| 75 | - $ok = mysqli_select_db($link, $db); |
|
| 76 | - if ( |
|
| 77 | - defined('_MYSQL_SET_SQL_MODE') |
|
| 78 | - or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 79 | - ) { |
|
| 80 | - mysqli_query($link, $last = "set sql_mode=''"); |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - spip_log( |
|
| 85 | - "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 86 | - _LOG_DEBUG |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - return !$ok ? false : [ |
|
| 90 | - 'db' => $db, |
|
| 91 | - 'last' => $last, |
|
| 92 | - 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 93 | - 'link' => $link, |
|
| 94 | - 'total_requetes' => 0, |
|
| 95 | - ]; |
|
| 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 | + try { |
|
| 50 | + if ( |
|
| 51 | + $port and !is_numeric($socket = $port) |
|
| 52 | + and (!$host or $host === 'localhost') |
|
| 53 | + ) { |
|
| 54 | + $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 55 | + } elseif ($port) { |
|
| 56 | + $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 57 | + } else { |
|
| 58 | + $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | + } |
|
| 60 | + } catch (\mysqli_sql_exception $e) { |
|
| 61 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 62 | + $link = false; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if (!$link) { |
|
| 66 | + spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 67 | + |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + $last = ''; |
|
| 71 | + if (!$db) { |
|
| 72 | + $ok = $link; |
|
| 73 | + $db = 'spip'; |
|
| 74 | + } else { |
|
| 75 | + $ok = mysqli_select_db($link, $db); |
|
| 76 | + if ( |
|
| 77 | + defined('_MYSQL_SET_SQL_MODE') |
|
| 78 | + or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 79 | + ) { |
|
| 80 | + mysqli_query($link, $last = "set sql_mode=''"); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + spip_log( |
|
| 85 | + "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 86 | + _LOG_DEBUG |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + return !$ok ? false : [ |
|
| 90 | + 'db' => $db, |
|
| 91 | + 'last' => $last, |
|
| 92 | + 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 93 | + 'link' => $link, |
|
| 94 | + 'total_requetes' => 0, |
|
| 95 | + ]; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | $GLOBALS['spip_mysql_functions_1'] = [ |
| 100 | - 'alter' => 'spip_mysql_alter', |
|
| 101 | - 'count' => 'spip_mysql_count', |
|
| 102 | - 'countsel' => 'spip_mysql_countsel', |
|
| 103 | - 'create' => 'spip_mysql_create', |
|
| 104 | - 'create_base' => 'spip_mysql_create_base', |
|
| 105 | - 'create_view' => 'spip_mysql_create_view', |
|
| 106 | - 'date_proche' => 'spip_mysql_date_proche', |
|
| 107 | - 'delete' => 'spip_mysql_delete', |
|
| 108 | - 'drop_table' => 'spip_mysql_drop_table', |
|
| 109 | - 'drop_view' => 'spip_mysql_drop_view', |
|
| 110 | - 'errno' => 'spip_mysql_errno', |
|
| 111 | - 'error' => 'spip_mysql_error', |
|
| 112 | - 'explain' => 'spip_mysql_explain', |
|
| 113 | - 'fetch' => 'spip_mysql_fetch', |
|
| 114 | - 'seek' => 'spip_mysql_seek', |
|
| 115 | - 'free' => 'spip_mysql_free', |
|
| 116 | - 'hex' => 'spip_mysql_hex', |
|
| 117 | - 'in' => 'spip_mysql_in', |
|
| 118 | - 'insert' => 'spip_mysql_insert', |
|
| 119 | - 'insertq' => 'spip_mysql_insertq', |
|
| 120 | - 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 121 | - 'listdbs' => 'spip_mysql_listdbs', |
|
| 122 | - 'multi' => 'spip_mysql_multi', |
|
| 123 | - 'optimize' => 'spip_mysql_optimize', |
|
| 124 | - 'query' => 'spip_mysql_query', |
|
| 125 | - 'quote' => 'spip_mysql_quote', |
|
| 126 | - 'replace' => 'spip_mysql_replace', |
|
| 127 | - 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 128 | - 'repair' => 'spip_mysql_repair', |
|
| 129 | - 'select' => 'spip_mysql_select', |
|
| 130 | - 'selectdb' => 'spip_mysql_selectdb', |
|
| 131 | - 'set_charset' => 'spip_mysql_set_charset', |
|
| 132 | - 'get_charset' => 'spip_mysql_get_charset', |
|
| 133 | - 'showbase' => 'spip_mysql_showbase', |
|
| 134 | - 'showtable' => 'spip_mysql_showtable', |
|
| 135 | - 'table_exists' => 'spip_mysql_table_exists', |
|
| 136 | - 'update' => 'spip_mysql_update', |
|
| 137 | - 'updateq' => 'spip_mysql_updateq', |
|
| 138 | - |
|
| 139 | - // association de chaque nom http d'un charset aux couples MySQL |
|
| 140 | - 'charsets' => [ |
|
| 141 | - 'cp1250' => ['charset' => 'cp1250', 'collation' => 'cp1250_general_ci'], |
|
| 142 | - 'cp1251' => ['charset' => 'cp1251', 'collation' => 'cp1251_general_ci'], |
|
| 143 | - 'cp1256' => ['charset' => 'cp1256', 'collation' => 'cp1256_general_ci'], |
|
| 144 | - 'iso-8859-1' => ['charset' => 'latin1', 'collation' => 'latin1_swedish_ci'], |
|
| 100 | + 'alter' => 'spip_mysql_alter', |
|
| 101 | + 'count' => 'spip_mysql_count', |
|
| 102 | + 'countsel' => 'spip_mysql_countsel', |
|
| 103 | + 'create' => 'spip_mysql_create', |
|
| 104 | + 'create_base' => 'spip_mysql_create_base', |
|
| 105 | + 'create_view' => 'spip_mysql_create_view', |
|
| 106 | + 'date_proche' => 'spip_mysql_date_proche', |
|
| 107 | + 'delete' => 'spip_mysql_delete', |
|
| 108 | + 'drop_table' => 'spip_mysql_drop_table', |
|
| 109 | + 'drop_view' => 'spip_mysql_drop_view', |
|
| 110 | + 'errno' => 'spip_mysql_errno', |
|
| 111 | + 'error' => 'spip_mysql_error', |
|
| 112 | + 'explain' => 'spip_mysql_explain', |
|
| 113 | + 'fetch' => 'spip_mysql_fetch', |
|
| 114 | + 'seek' => 'spip_mysql_seek', |
|
| 115 | + 'free' => 'spip_mysql_free', |
|
| 116 | + 'hex' => 'spip_mysql_hex', |
|
| 117 | + 'in' => 'spip_mysql_in', |
|
| 118 | + 'insert' => 'spip_mysql_insert', |
|
| 119 | + 'insertq' => 'spip_mysql_insertq', |
|
| 120 | + 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 121 | + 'listdbs' => 'spip_mysql_listdbs', |
|
| 122 | + 'multi' => 'spip_mysql_multi', |
|
| 123 | + 'optimize' => 'spip_mysql_optimize', |
|
| 124 | + 'query' => 'spip_mysql_query', |
|
| 125 | + 'quote' => 'spip_mysql_quote', |
|
| 126 | + 'replace' => 'spip_mysql_replace', |
|
| 127 | + 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 128 | + 'repair' => 'spip_mysql_repair', |
|
| 129 | + 'select' => 'spip_mysql_select', |
|
| 130 | + 'selectdb' => 'spip_mysql_selectdb', |
|
| 131 | + 'set_charset' => 'spip_mysql_set_charset', |
|
| 132 | + 'get_charset' => 'spip_mysql_get_charset', |
|
| 133 | + 'showbase' => 'spip_mysql_showbase', |
|
| 134 | + 'showtable' => 'spip_mysql_showtable', |
|
| 135 | + 'table_exists' => 'spip_mysql_table_exists', |
|
| 136 | + 'update' => 'spip_mysql_update', |
|
| 137 | + 'updateq' => 'spip_mysql_updateq', |
|
| 138 | + |
|
| 139 | + // association de chaque nom http d'un charset aux couples MySQL |
|
| 140 | + 'charsets' => [ |
|
| 141 | + 'cp1250' => ['charset' => 'cp1250', 'collation' => 'cp1250_general_ci'], |
|
| 142 | + 'cp1251' => ['charset' => 'cp1251', 'collation' => 'cp1251_general_ci'], |
|
| 143 | + 'cp1256' => ['charset' => 'cp1256', 'collation' => 'cp1256_general_ci'], |
|
| 144 | + 'iso-8859-1' => ['charset' => 'latin1', 'collation' => 'latin1_swedish_ci'], |
|
| 145 | 145 | //'iso-8859-6'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 146 | - 'iso-8859-9' => ['charset' => 'latin5', 'collation' => 'latin5_turkish_ci'], |
|
| 146 | + 'iso-8859-9' => ['charset' => 'latin5', 'collation' => 'latin5_turkish_ci'], |
|
| 147 | 147 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 148 | - 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'] |
|
| 149 | - ] |
|
| 148 | + 'utf-8' => ['charset' => 'utf8', 'collation' => 'utf8_general_ci'] |
|
| 149 | + ] |
|
| 150 | 150 | ]; |
| 151 | 151 | |
| 152 | 152 | |
@@ -157,9 +157,9 @@ discard block |
||
| 157 | 157 | * @return Object Information de connexion pour mysqli |
| 158 | 158 | */ |
| 159 | 159 | function _mysql_link($serveur = '') { |
| 160 | - $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 160 | + $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 161 | 161 | |
| 162 | - return $link; |
|
| 162 | + return $link; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | * @return resource Ressource de résultats pour fetch() |
| 173 | 173 | */ |
| 174 | 174 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 175 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 176 | - spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 175 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 176 | + spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 177 | 177 | |
| 178 | - return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 178 | + return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -188,11 +188,11 @@ discard block |
||
| 188 | 188 | * @return array Description du charset (son nom est dans 'charset') |
| 189 | 189 | */ |
| 190 | 190 | function spip_mysql_get_charset($charset = [], $serveur = '', $requeter = true) { |
| 191 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 192 | - $connexion['last'] = $c = 'SHOW CHARACTER SET' |
|
| 193 | - . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 191 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 192 | + $connexion['last'] = $c = 'SHOW CHARACTER SET' |
|
| 193 | + . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 194 | 194 | |
| 195 | - return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 195 | + return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -208,72 +208,72 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function spip_mysql_query($query, $serveur = '', $requeter = true) { |
| 210 | 210 | |
| 211 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 212 | - $prefixe = $connexion['prefixe']; |
|
| 213 | - $link = $connexion['link']; |
|
| 214 | - $db = $connexion['db']; |
|
| 215 | - |
|
| 216 | - $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 217 | - |
|
| 218 | - // renvoyer la requete inerte si demandee |
|
| 219 | - if (!$requeter) { |
|
| 220 | - return $query; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - if (isset($_GET['var_profile']) or (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES)) { |
|
| 224 | - include_spip('public/tracer'); |
|
| 225 | - $t = trace_query_start(); |
|
| 226 | - } else { |
|
| 227 | - $t = 0; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $connexion['last'] = $query; |
|
| 231 | - $connexion['total_requetes']++; |
|
| 232 | - |
|
| 233 | - // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 234 | - $debug = ''; |
|
| 235 | - if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 236 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 237 | - list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 238 | - $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . ' | '; |
|
| 239 | - } |
|
| 240 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 241 | - $debug .= $_SERVER['REQUEST_URI']; |
|
| 242 | - } |
|
| 243 | - if (!empty($GLOBALS['ip'])) { |
|
| 244 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 245 | - } |
|
| 246 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 247 | - } |
|
| 248 | - try { |
|
| 249 | - $r = mysqli_query($link, $query . $debug); |
|
| 250 | - } catch (\mysqli_sql_exception $e) { |
|
| 251 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 252 | - $r = false; |
|
| 253 | - // Todo: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 254 | - // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 258 | - if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 259 | - if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 260 | - //Fermer la connexion defaillante |
|
| 261 | - mysqli_close($connexion['link']); |
|
| 262 | - unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 263 | - //Relancer une connexion vierge |
|
| 264 | - spip_connect($serveur); |
|
| 265 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 266 | - $link = $connexion['link']; |
|
| 267 | - //On retente au cas où |
|
| 268 | - $r = mysqli_query($link, $query . $debug); |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // Log de l'erreur eventuelle |
|
| 273 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 274 | - $e .= spip_mysql_error($query, $serveur); |
|
| 275 | - } // et du fautif |
|
| 276 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 211 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 212 | + $prefixe = $connexion['prefixe']; |
|
| 213 | + $link = $connexion['link']; |
|
| 214 | + $db = $connexion['db']; |
|
| 215 | + |
|
| 216 | + $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 217 | + |
|
| 218 | + // renvoyer la requete inerte si demandee |
|
| 219 | + if (!$requeter) { |
|
| 220 | + return $query; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + if (isset($_GET['var_profile']) or (defined('_DEBUG_TRACE_QUERIES') and _DEBUG_TRACE_QUERIES)) { |
|
| 224 | + include_spip('public/tracer'); |
|
| 225 | + $t = trace_query_start(); |
|
| 226 | + } else { |
|
| 227 | + $t = 0; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $connexion['last'] = $query; |
|
| 231 | + $connexion['total_requetes']++; |
|
| 232 | + |
|
| 233 | + // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 234 | + $debug = ''; |
|
| 235 | + if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 236 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 237 | + list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 238 | + $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . ' | '; |
|
| 239 | + } |
|
| 240 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 241 | + $debug .= $_SERVER['REQUEST_URI']; |
|
| 242 | + } |
|
| 243 | + if (!empty($GLOBALS['ip'])) { |
|
| 244 | + $debug .= ' + ' . $GLOBALS['ip']; |
|
| 245 | + } |
|
| 246 | + $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 247 | + } |
|
| 248 | + try { |
|
| 249 | + $r = mysqli_query($link, $query . $debug); |
|
| 250 | + } catch (\mysqli_sql_exception $e) { |
|
| 251 | + spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 252 | + $r = false; |
|
| 253 | + // Todo: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
|
| 254 | + // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 258 | + if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 259 | + if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 260 | + //Fermer la connexion defaillante |
|
| 261 | + mysqli_close($connexion['link']); |
|
| 262 | + unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 263 | + //Relancer une connexion vierge |
|
| 264 | + spip_connect($serveur); |
|
| 265 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 266 | + $link = $connexion['link']; |
|
| 267 | + //On retente au cas où |
|
| 268 | + $r = mysqli_query($link, $query . $debug); |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // Log de l'erreur eventuelle |
|
| 273 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 274 | + $e .= spip_mysql_error($query, $serveur); |
|
| 275 | + } // et du fautif |
|
| 276 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -288,12 +288,12 @@ discard block |
||
| 288 | 288 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 289 | 289 | */ |
| 290 | 290 | function spip_mysql_alter($query, $serveur = '', $requeter = true) { |
| 291 | - // ici on supprime les ` entourant le nom de table pour permettre |
|
| 292 | - // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 293 | - // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 294 | - $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
|
| 291 | + // ici on supprime les ` entourant le nom de table pour permettre |
|
| 292 | + // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 293 | + // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 294 | + $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
|
| 295 | 295 | |
| 296 | - return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 296 | + return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
@@ -306,9 +306,9 @@ discard block |
||
| 306 | 306 | * @return bool Toujours true |
| 307 | 307 | */ |
| 308 | 308 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 309 | - spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 309 | + spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 310 | 310 | |
| 311 | - return true; |
|
| 311 | + return true; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
@@ -321,18 +321,18 @@ discard block |
||
| 321 | 321 | * @return array Tableau de l'explication |
| 322 | 322 | */ |
| 323 | 323 | function spip_mysql_explain($query, $serveur = '', $requeter = true) { |
| 324 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 325 | - return []; |
|
| 326 | - } |
|
| 327 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 328 | - $prefixe = $connexion['prefixe']; |
|
| 329 | - $link = $connexion['link']; |
|
| 330 | - $db = $connexion['db']; |
|
| 331 | - |
|
| 332 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 333 | - $r = mysqli_query($link, $query); |
|
| 334 | - |
|
| 335 | - return spip_mysql_fetch($r, null, $serveur); |
|
| 324 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 325 | + return []; |
|
| 326 | + } |
|
| 327 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 328 | + $prefixe = $connexion['prefixe']; |
|
| 329 | + $link = $connexion['link']; |
|
| 330 | + $db = $connexion['db']; |
|
| 331 | + |
|
| 332 | + $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 333 | + $r = mysqli_query($link, $query); |
|
| 334 | + |
|
| 335 | + return spip_mysql_fetch($r, null, $serveur); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | |
@@ -361,35 +361,35 @@ discard block |
||
| 361 | 361 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 362 | 362 | */ |
| 363 | 363 | function spip_mysql_select( |
| 364 | - $select, |
|
| 365 | - $from, |
|
| 366 | - $where = '', |
|
| 367 | - $groupby = '', |
|
| 368 | - $orderby = '', |
|
| 369 | - $limit = '', |
|
| 370 | - $having = '', |
|
| 371 | - $serveur = '', |
|
| 372 | - $requeter = true |
|
| 364 | + $select, |
|
| 365 | + $from, |
|
| 366 | + $where = '', |
|
| 367 | + $groupby = '', |
|
| 368 | + $orderby = '', |
|
| 369 | + $limit = '', |
|
| 370 | + $having = '', |
|
| 371 | + $serveur = '', |
|
| 372 | + $requeter = true |
|
| 373 | 373 | ) { |
| 374 | 374 | |
| 375 | 375 | |
| 376 | - $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 377 | - $query = |
|
| 378 | - calculer_mysql_expression('SELECT', $select, ', ') |
|
| 379 | - . calculer_mysql_expression('FROM', $from, ', ') |
|
| 380 | - . calculer_mysql_expression('WHERE', $where) |
|
| 381 | - . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 382 | - . calculer_mysql_expression('HAVING', $having) |
|
| 383 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 384 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 376 | + $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 377 | + $query = |
|
| 378 | + calculer_mysql_expression('SELECT', $select, ', ') |
|
| 379 | + . calculer_mysql_expression('FROM', $from, ', ') |
|
| 380 | + . calculer_mysql_expression('WHERE', $where) |
|
| 381 | + . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 382 | + . calculer_mysql_expression('HAVING', $having) |
|
| 383 | + . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 384 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 385 | 385 | |
| 386 | - // renvoyer la requete inerte si demandee |
|
| 387 | - if ($requeter === false) { |
|
| 388 | - return $query; |
|
| 389 | - } |
|
| 390 | - $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 386 | + // renvoyer la requete inerte si demandee |
|
| 387 | + if ($requeter === false) { |
|
| 388 | + return $query; |
|
| 389 | + } |
|
| 390 | + $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 391 | 391 | |
| 392 | - return $r ? $r : $query; |
|
| 392 | + return $r ? $r : $query; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | * @return string Texte du orderby préparé |
| 407 | 407 | */ |
| 408 | 408 | function spip_mysql_order($orderby) { |
| 409 | - return (is_array($orderby)) ? join(', ', $orderby) : $orderby; |
|
| 409 | + return (is_array($orderby)) ? join(', ', $orderby) : $orderby; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -429,26 +429,26 @@ discard block |
||
| 429 | 429 | * Contrainte pour clause WHERE |
| 430 | 430 | */ |
| 431 | 431 | function calculer_mysql_where($v) { |
| 432 | - if (!is_array($v)) { |
|
| 433 | - return $v; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - $op = array_shift($v); |
|
| 437 | - if (!($n = count($v))) { |
|
| 438 | - return $op; |
|
| 439 | - } else { |
|
| 440 | - $arg = calculer_mysql_where(array_shift($v)); |
|
| 441 | - if ($n == 1) { |
|
| 442 | - return "$op($arg)"; |
|
| 443 | - } else { |
|
| 444 | - $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 445 | - if ($n == 2) { |
|
| 446 | - return "($arg $op $arg2)"; |
|
| 447 | - } else { |
|
| 448 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - } |
|
| 432 | + if (!is_array($v)) { |
|
| 433 | + return $v; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + $op = array_shift($v); |
|
| 437 | + if (!($n = count($v))) { |
|
| 438 | + return $op; |
|
| 439 | + } else { |
|
| 440 | + $arg = calculer_mysql_where(array_shift($v)); |
|
| 441 | + if ($n == 1) { |
|
| 442 | + return "$op($arg)"; |
|
| 443 | + } else { |
|
| 444 | + $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 445 | + if ($n == 2) { |
|
| 446 | + return "($arg $op $arg2)"; |
|
| 447 | + } else { |
|
| 448 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -463,21 +463,21 @@ discard block |
||
| 463 | 463 | * @return string Texte de l'expression, une partie donc, du texte la requête. |
| 464 | 464 | */ |
| 465 | 465 | function calculer_mysql_expression($expression, $v, $join = 'AND') { |
| 466 | - if (empty($v)) { |
|
| 467 | - return ''; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $exp = "\n$expression "; |
|
| 471 | - |
|
| 472 | - if (!is_array($v)) { |
|
| 473 | - return $exp . $v; |
|
| 474 | - } else { |
|
| 475 | - if (strtoupper($join) === 'AND') { |
|
| 476 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 477 | - } else { |
|
| 478 | - return $exp . join($join, $v); |
|
| 479 | - } |
|
| 480 | - } |
|
| 466 | + if (empty($v)) { |
|
| 467 | + return ''; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $exp = "\n$expression "; |
|
| 471 | + |
|
| 472 | + if (!is_array($v)) { |
|
| 473 | + return $exp . $v; |
|
| 474 | + } else { |
|
| 475 | + if (strtoupper($join) === 'AND') { |
|
| 476 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 477 | + } else { |
|
| 478 | + return $exp . join($join, $v); |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | |
@@ -488,26 +488,26 @@ discard block |
||
| 488 | 488 | * @return string Sélection de colonnes pour une clause SELECT |
| 489 | 489 | */ |
| 490 | 490 | function spip_mysql_select_as($args) { |
| 491 | - $res = ''; |
|
| 492 | - foreach ($args as $k => $v) { |
|
| 493 | - if (substr($k, -1) == '@') { |
|
| 494 | - // c'est une jointure qui se refere au from precedent |
|
| 495 | - // pas de virgule |
|
| 496 | - $res .= ' ' . $v; |
|
| 497 | - } else { |
|
| 498 | - if (!is_numeric($k)) { |
|
| 499 | - $p = strpos($v, ' '); |
|
| 500 | - if ($p) { |
|
| 501 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 502 | - } else { |
|
| 503 | - $v .= " AS `$k`"; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - $res .= ', ' . $v; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - return substr($res, 2); |
|
| 491 | + $res = ''; |
|
| 492 | + foreach ($args as $k => $v) { |
|
| 493 | + if (substr($k, -1) == '@') { |
|
| 494 | + // c'est une jointure qui se refere au from precedent |
|
| 495 | + // pas de virgule |
|
| 496 | + $res .= ' ' . $v; |
|
| 497 | + } else { |
|
| 498 | + if (!is_numeric($k)) { |
|
| 499 | + $p = strpos($v, ' '); |
|
| 500 | + if ($p) { |
|
| 501 | + $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 502 | + } else { |
|
| 503 | + $v .= " AS `$k`"; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + $res .= ', ' . $v; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + return substr($res, 2); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | |
@@ -532,58 +532,58 @@ discard block |
||
| 532 | 532 | */ |
| 533 | 533 | function _mysql_traite_query($query, $db = '', $prefixe = '', $echappe_textes = true) { |
| 534 | 534 | |
| 535 | - if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 536 | - $pref = '`' . $db . '`.'; |
|
| 537 | - } else { |
|
| 538 | - $pref = ''; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - if ($prefixe) { |
|
| 542 | - $pref .= $prefixe . '_'; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 546 | - $suite = ''; |
|
| 547 | - } else { |
|
| 548 | - $suite = strstr($query, $regs[0]); |
|
| 549 | - $query = substr($query, 0, -strlen($suite)); |
|
| 550 | - // propager le prefixe en cas de requete imbriquee |
|
| 551 | - // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 552 | - // modifier une requete qui est en fait juste du texte dans un champ |
|
| 553 | - if (stripos($suite, 'SELECT') !== false) { |
|
| 554 | - if ($echappe_textes) { |
|
| 555 | - list($suite_echap, $textes) = query_echappe_textes($suite); |
|
| 556 | - } |
|
| 557 | - else { |
|
| 558 | - $suite_echap = $suite; |
|
| 559 | - } |
|
| 560 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
|
| 561 | - $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 562 | - if ($echappe_textes) { |
|
| 563 | - $suite = query_reinjecte_textes($suite_echap, $textes); |
|
| 564 | - } |
|
| 565 | - else { |
|
| 566 | - $suite = $suite_echap; |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 572 | - |
|
| 573 | - // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 574 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 575 | - if ( |
|
| 576 | - defined('_MYSQL_NOPLANES') |
|
| 577 | - and _MYSQL_NOPLANES |
|
| 578 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 579 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 580 | - ) { |
|
| 581 | - include_spip('inc/charsets'); |
|
| 582 | - $r = utf8_noplanes($r); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 586 | - return $r; |
|
| 535 | + if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 536 | + $pref = '`' . $db . '`.'; |
|
| 537 | + } else { |
|
| 538 | + $pref = ''; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + if ($prefixe) { |
|
| 542 | + $pref .= $prefixe . '_'; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 546 | + $suite = ''; |
|
| 547 | + } else { |
|
| 548 | + $suite = strstr($query, $regs[0]); |
|
| 549 | + $query = substr($query, 0, -strlen($suite)); |
|
| 550 | + // propager le prefixe en cas de requete imbriquee |
|
| 551 | + // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 552 | + // modifier une requete qui est en fait juste du texte dans un champ |
|
| 553 | + if (stripos($suite, 'SELECT') !== false) { |
|
| 554 | + if ($echappe_textes) { |
|
| 555 | + list($suite_echap, $textes) = query_echappe_textes($suite); |
|
| 556 | + } |
|
| 557 | + else { |
|
| 558 | + $suite_echap = $suite; |
|
| 559 | + } |
|
| 560 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
|
| 561 | + $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 562 | + if ($echappe_textes) { |
|
| 563 | + $suite = query_reinjecte_textes($suite_echap, $textes); |
|
| 564 | + } |
|
| 565 | + else { |
|
| 566 | + $suite = $suite_echap; |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 572 | + |
|
| 573 | + // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 574 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 575 | + if ( |
|
| 576 | + defined('_MYSQL_NOPLANES') |
|
| 577 | + and _MYSQL_NOPLANES |
|
| 578 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 579 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 580 | + ) { |
|
| 581 | + include_spip('inc/charsets'); |
|
| 582 | + $r = utf8_noplanes($r); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 586 | + return $r; |
|
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
@@ -601,13 +601,13 @@ discard block |
||
| 601 | 601 | * - False en cas d'erreur. |
| 602 | 602 | **/ |
| 603 | 603 | function spip_mysql_selectdb($db, $serveur = '', $requeter = true) { |
| 604 | - $link = _mysql_link($serveur); |
|
| 605 | - $ok = mysqli_select_db($link, $db); |
|
| 606 | - if (!$ok) { |
|
| 607 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 608 | - } |
|
| 604 | + $link = _mysql_link($serveur); |
|
| 605 | + $ok = mysqli_select_db($link, $db); |
|
| 606 | + if (!$ok) { |
|
| 607 | + spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 608 | + } |
|
| 609 | 609 | |
| 610 | - return $ok; |
|
| 610 | + return $ok; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | |
@@ -628,14 +628,14 @@ discard block |
||
| 628 | 628 | * Liste de noms de bases de données |
| 629 | 629 | **/ |
| 630 | 630 | function spip_mysql_listdbs($serveur = '', $requeter = true) { |
| 631 | - $dbs = []; |
|
| 632 | - if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 633 | - while ($row = mysqli_fetch_assoc($res)) { |
|
| 634 | - $dbs[] = $row['Database']; |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - return $dbs; |
|
| 631 | + $dbs = []; |
|
| 632 | + if ($res = spip_mysql_query('SHOW DATABASES', $serveur)) { |
|
| 633 | + while ($row = mysqli_fetch_assoc($res)) { |
|
| 634 | + $dbs[] = $row['Database']; |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + return $dbs; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | |
@@ -658,73 +658,73 @@ discard block |
||
| 658 | 658 | * - true si la requête réussie, false sinon. |
| 659 | 659 | */ |
| 660 | 660 | function spip_mysql_create( |
| 661 | - $nom, |
|
| 662 | - $champs, |
|
| 663 | - $cles, |
|
| 664 | - $autoinc = false, |
|
| 665 | - $temporary = false, |
|
| 666 | - $serveur = '', |
|
| 667 | - $requeter = true |
|
| 661 | + $nom, |
|
| 662 | + $champs, |
|
| 663 | + $cles, |
|
| 664 | + $autoinc = false, |
|
| 665 | + $temporary = false, |
|
| 666 | + $serveur = '', |
|
| 667 | + $requeter = true |
|
| 668 | 668 | ) { |
| 669 | 669 | |
| 670 | - $query = ''; |
|
| 671 | - $keys = ''; |
|
| 672 | - $s = ''; |
|
| 673 | - $p = ''; |
|
| 674 | - |
|
| 675 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 676 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 677 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 678 | - return; |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 682 | - if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 683 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - foreach ($cles as $k => $v) { |
|
| 687 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 688 | - if ($k == 'PRIMARY KEY') { |
|
| 689 | - $p = $v; |
|
| 690 | - } |
|
| 691 | - $s = ','; |
|
| 692 | - } |
|
| 693 | - $s = ''; |
|
| 694 | - |
|
| 695 | - $character_set = ''; |
|
| 696 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 697 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 698 | - } |
|
| 699 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 700 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - foreach ($champs as $k => $v) { |
|
| 704 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 705 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 706 | - if ( |
|
| 707 | - preg_match(',(char|text),i', $defs[1]) |
|
| 708 | - and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 709 | - ) { |
|
| 710 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 711 | - } |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - $query .= "$s\n\t\t$k $v" |
|
| 715 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 716 | - ? ' auto_increment' |
|
| 717 | - : '' |
|
| 718 | - ); |
|
| 719 | - $s = ','; |
|
| 720 | - } |
|
| 721 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 722 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 723 | - . ' ENGINE=MyISAM' |
|
| 724 | - . ($character_set ? " DEFAULT $character_set" : '') |
|
| 725 | - . "\n"; |
|
| 726 | - |
|
| 727 | - return spip_mysql_query($q, $serveur); |
|
| 670 | + $query = ''; |
|
| 671 | + $keys = ''; |
|
| 672 | + $s = ''; |
|
| 673 | + $p = ''; |
|
| 674 | + |
|
| 675 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 676 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 677 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 678 | + return; |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + $res = spip_mysql_query('SELECT version() as v', $serveur); |
|
| 682 | + if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 683 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + foreach ($cles as $k => $v) { |
|
| 687 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 688 | + if ($k == 'PRIMARY KEY') { |
|
| 689 | + $p = $v; |
|
| 690 | + } |
|
| 691 | + $s = ','; |
|
| 692 | + } |
|
| 693 | + $s = ''; |
|
| 694 | + |
|
| 695 | + $character_set = ''; |
|
| 696 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 697 | + $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 698 | + } |
|
| 699 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 700 | + $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + foreach ($champs as $k => $v) { |
|
| 704 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 705 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 706 | + if ( |
|
| 707 | + preg_match(',(char|text),i', $defs[1]) |
|
| 708 | + and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 709 | + ) { |
|
| 710 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + $query .= "$s\n\t\t$k $v" |
|
| 715 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 716 | + ? ' auto_increment' |
|
| 717 | + : '' |
|
| 718 | + ); |
|
| 719 | + $s = ','; |
|
| 720 | + } |
|
| 721 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 722 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 723 | + . ' ENGINE=MyISAM' |
|
| 724 | + . ($character_set ? " DEFAULT $character_set" : '') |
|
| 725 | + . "\n"; |
|
| 726 | + |
|
| 727 | + return spip_mysql_query($q, $serveur); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | |
@@ -737,25 +737,25 @@ discard block |
||
| 737 | 737 | * Définition SQL adaptée pour MySQL d'un champ de table |
| 738 | 738 | */ |
| 739 | 739 | function _mysql_remplacements_definitions_table($query) { |
| 740 | - // quelques remplacements |
|
| 741 | - $num = '(\s*\([0-9]*\))?'; |
|
| 742 | - $enum = '(\s*\([^\)]*\))?'; |
|
| 743 | - |
|
| 744 | - $remplace = [ |
|
| 745 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 746 | - '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 747 | - ]; |
|
| 748 | - |
|
| 749 | - if (is_string($query)) { |
|
| 750 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 751 | - } elseif (is_array($query)) { |
|
| 752 | - $keys = array_keys($remplace); |
|
| 753 | - foreach ($query as $k => $q) { |
|
| 754 | - $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - return $query; |
|
| 740 | + // quelques remplacements |
|
| 741 | + $num = '(\s*\([0-9]*\))?'; |
|
| 742 | + $enum = '(\s*\([^\)]*\))?'; |
|
| 743 | + |
|
| 744 | + $remplace = [ |
|
| 745 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 746 | + '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 747 | + ]; |
|
| 748 | + |
|
| 749 | + if (is_string($query)) { |
|
| 750 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 751 | + } elseif (is_array($query)) { |
|
| 752 | + $keys = array_keys($remplace); |
|
| 753 | + foreach ($query as $k => $q) { |
|
| 754 | + $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + return $query; |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | * @return bool true si la base est créee. |
| 769 | 769 | **/ |
| 770 | 770 | function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
| 771 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 771 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | |
@@ -789,19 +789,19 @@ discard block |
||
| 789 | 789 | * - string texte de la requête si $requeter vaut false |
| 790 | 790 | */ |
| 791 | 791 | function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 792 | - if (!$query_select) { |
|
| 793 | - return false; |
|
| 794 | - } |
|
| 795 | - // vue deja presente |
|
| 796 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 797 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 792 | + if (!$query_select) { |
|
| 793 | + return false; |
|
| 794 | + } |
|
| 795 | + // vue deja presente |
|
| 796 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 797 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 798 | 798 | |
| 799 | - return false; |
|
| 800 | - } |
|
| 799 | + return false; |
|
| 800 | + } |
|
| 801 | 801 | |
| 802 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 802 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 803 | 803 | |
| 804 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 804 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | |
@@ -817,11 +817,11 @@ discard block |
||
| 817 | 817 | * - true si la requête a réussie, false sinon |
| 818 | 818 | */ |
| 819 | 819 | function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 820 | - if ($exist) { |
|
| 821 | - $exist = ' IF EXISTS'; |
|
| 822 | - } |
|
| 820 | + if ($exist) { |
|
| 821 | + $exist = ' IF EXISTS'; |
|
| 822 | + } |
|
| 823 | 823 | |
| 824 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 824 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | /** |
@@ -836,11 +836,11 @@ discard block |
||
| 836 | 836 | * - true si la requête a réussie, false sinon |
| 837 | 837 | */ |
| 838 | 838 | function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 839 | - if ($exist) { |
|
| 840 | - $exist = ' IF EXISTS'; |
|
| 841 | - } |
|
| 839 | + if ($exist) { |
|
| 840 | + $exist = ' IF EXISTS'; |
|
| 841 | + } |
|
| 842 | 842 | |
| 843 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 843 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | /** |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | * Ressource à utiliser avec sql_fetch() |
| 858 | 858 | **/ |
| 859 | 859 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 860 | - return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 860 | + return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | * - true si la requête a réussie, false sinon |
| 874 | 874 | */ |
| 875 | 875 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 876 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 876 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 877 | 877 | } |
| 878 | 878 | |
| 879 | 879 | /** |
@@ -890,12 +890,12 @@ discard block |
||
| 890 | 890 | * Ressource à utiliser avec sql_fetch() |
| 891 | 891 | **/ |
| 892 | 892 | function spip_mysql_table_exists(string $table, $serveur = '', $requeter = true) { |
| 893 | - $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 894 | - if (!$requeter) { |
|
| 895 | - return $r; |
|
| 896 | - } |
|
| 897 | - $res = spip_mysql_fetch($r); |
|
| 898 | - return (bool) $res; |
|
| 893 | + $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 894 | + if (!$requeter) { |
|
| 895 | + return $r; |
|
| 896 | + } |
|
| 897 | + $res = spip_mysql_fetch($r); |
|
| 898 | + return (bool) $res; |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | define('_MYSQL_RE_SHOW_TABLE', '/^[^(),]*\(((?:[^()]*\((?:[^()]*\([^()]*\))?[^()]*\)[^()]*)*[^()]*)\)[^()]*$/'); |
@@ -918,86 +918,86 @@ discard block |
||
| 918 | 918 | * - array description de la table sinon |
| 919 | 919 | */ |
| 920 | 920 | function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) { |
| 921 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 922 | - if (!$s) { |
|
| 923 | - return ''; |
|
| 924 | - } |
|
| 925 | - if (!$requeter) { |
|
| 926 | - return $s; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 930 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 931 | - $desc = $r[1]; |
|
| 932 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 933 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 934 | - if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 935 | - $namedkeys = $r[2]; |
|
| 936 | - $desc = $r[1]; |
|
| 937 | - } else { |
|
| 938 | - $namedkeys = ''; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - $fields = []; |
|
| 942 | - foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 943 | - preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 944 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 945 | - } |
|
| 946 | - $keys = []; |
|
| 947 | - |
|
| 948 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 949 | - if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 950 | - $k = str_replace('`', '', trim($r[1])); |
|
| 951 | - $t = strtolower(str_replace('`', '', $r[2])); |
|
| 952 | - if ($k && !isset($keys[$k])) { |
|
| 953 | - $keys[$k] = $t; |
|
| 954 | - } else { |
|
| 955 | - $keys[] = $t; |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - spip_mysql_free($s); |
|
| 960 | - |
|
| 961 | - return ['field' => $fields, 'key' => $keys]; |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 965 | - if ($res) { |
|
| 966 | - $nfields = []; |
|
| 967 | - $nkeys = []; |
|
| 968 | - while ($val = spip_mysql_fetch($res)) { |
|
| 969 | - $nfields[$val['Field']] = $val['Type']; |
|
| 970 | - if ($val['Null'] == 'NO') { |
|
| 971 | - $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 972 | - } |
|
| 973 | - if ($val['Default'] === '0' || $val['Default']) { |
|
| 974 | - if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 975 | - $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 976 | - } else { |
|
| 977 | - $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - if ($val['Extra']) { |
|
| 981 | - $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 982 | - } |
|
| 983 | - if ($val['Key'] == 'PRI') { |
|
| 984 | - $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 985 | - } else { |
|
| 986 | - if ($val['Key'] == 'MUL') { |
|
| 987 | - $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 988 | - } else { |
|
| 989 | - if ($val['Key'] == 'UNI') { |
|
| 990 | - $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - spip_mysql_free($res); |
|
| 996 | - |
|
| 997 | - return ['field' => $nfields, 'key' => $nkeys]; |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - return ''; |
|
| 921 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 922 | + if (!$s) { |
|
| 923 | + return ''; |
|
| 924 | + } |
|
| 925 | + if (!$requeter) { |
|
| 926 | + return $s; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 930 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 931 | + $desc = $r[1]; |
|
| 932 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 933 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 934 | + if (preg_match('/^(.*?),([^,]*\sKEY[ (].*)$/s', $desc, $r)) { |
|
| 935 | + $namedkeys = $r[2]; |
|
| 936 | + $desc = $r[1]; |
|
| 937 | + } else { |
|
| 938 | + $namedkeys = ''; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + $fields = []; |
|
| 942 | + foreach (preg_split('/,\s*`/', $desc) as $v) { |
|
| 943 | + preg_match('/^\s*`?([^`]*)`\s*(.*)/', $v, $r); |
|
| 944 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 945 | + } |
|
| 946 | + $keys = []; |
|
| 947 | + |
|
| 948 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 949 | + if (preg_match('/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/', $v, $r)) { |
|
| 950 | + $k = str_replace('`', '', trim($r[1])); |
|
| 951 | + $t = strtolower(str_replace('`', '', $r[2])); |
|
| 952 | + if ($k && !isset($keys[$k])) { |
|
| 953 | + $keys[$k] = $t; |
|
| 954 | + } else { |
|
| 955 | + $keys[] = $t; |
|
| 956 | + } |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + spip_mysql_free($s); |
|
| 960 | + |
|
| 961 | + return ['field' => $fields, 'key' => $keys]; |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 965 | + if ($res) { |
|
| 966 | + $nfields = []; |
|
| 967 | + $nkeys = []; |
|
| 968 | + while ($val = spip_mysql_fetch($res)) { |
|
| 969 | + $nfields[$val['Field']] = $val['Type']; |
|
| 970 | + if ($val['Null'] == 'NO') { |
|
| 971 | + $nfields[$val['Field']] .= ' NOT NULL'; |
|
| 972 | + } |
|
| 973 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 974 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 975 | + $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 976 | + } else { |
|
| 977 | + $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + if ($val['Extra']) { |
|
| 981 | + $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 982 | + } |
|
| 983 | + if ($val['Key'] == 'PRI') { |
|
| 984 | + $nkeys['PRIMARY KEY'] = $val['Field']; |
|
| 985 | + } else { |
|
| 986 | + if ($val['Key'] == 'MUL') { |
|
| 987 | + $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 988 | + } else { |
|
| 989 | + if ($val['Key'] == 'UNI') { |
|
| 990 | + $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + spip_mysql_free($res); |
|
| 996 | + |
|
| 997 | + return ['field' => $nfields, 'key' => $nkeys]; |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + return ''; |
|
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | |
@@ -1013,12 +1013,12 @@ discard block |
||
| 1013 | 1013 | * @return array Ligne de résultat |
| 1014 | 1014 | */ |
| 1015 | 1015 | function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 1016 | - if (!$t) { |
|
| 1017 | - $t = MYSQLI_ASSOC; |
|
| 1018 | - } |
|
| 1019 | - if ($r) { |
|
| 1020 | - return mysqli_fetch_array($r, $t); |
|
| 1021 | - } |
|
| 1016 | + if (!$t) { |
|
| 1017 | + $t = MYSQLI_ASSOC; |
|
| 1018 | + } |
|
| 1019 | + if ($r) { |
|
| 1020 | + return mysqli_fetch_array($r, $t); |
|
| 1021 | + } |
|
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | /** |
@@ -1031,9 +1031,9 @@ discard block |
||
| 1031 | 1031 | * @return bool True si déplacement réussi, false sinon. |
| 1032 | 1032 | **/ |
| 1033 | 1033 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 1034 | - if ($r and mysqli_num_rows($r)) { |
|
| 1035 | - return mysqli_data_seek($r, $row_number); |
|
| 1036 | - } |
|
| 1034 | + if ($r and mysqli_num_rows($r)) { |
|
| 1035 | + return mysqli_data_seek($r, $row_number); |
|
| 1036 | + } |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | |
@@ -1051,26 +1051,26 @@ discard block |
||
| 1051 | 1051 | * - int Nombre de lignes (0 si la requête n'a pas réussie) |
| 1052 | 1052 | **/ |
| 1053 | 1053 | function spip_mysql_countsel( |
| 1054 | - $from = [], |
|
| 1055 | - $where = [], |
|
| 1056 | - $groupby = '', |
|
| 1057 | - $having = [], |
|
| 1058 | - $serveur = '', |
|
| 1059 | - $requeter = true |
|
| 1054 | + $from = [], |
|
| 1055 | + $where = [], |
|
| 1056 | + $groupby = '', |
|
| 1057 | + $having = [], |
|
| 1058 | + $serveur = '', |
|
| 1059 | + $requeter = true |
|
| 1060 | 1060 | ) { |
| 1061 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1062 | - |
|
| 1063 | - $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1064 | - if (!$requeter) { |
|
| 1065 | - return $r; |
|
| 1066 | - } |
|
| 1067 | - if (!$r instanceof mysqli_result) { |
|
| 1068 | - return 0; |
|
| 1069 | - } |
|
| 1070 | - list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1071 | - mysqli_free_result($r); |
|
| 1072 | - |
|
| 1073 | - return $c; |
|
| 1061 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1062 | + |
|
| 1063 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1064 | + if (!$requeter) { |
|
| 1065 | + return $r; |
|
| 1066 | + } |
|
| 1067 | + if (!$r instanceof mysqli_result) { |
|
| 1068 | + return 0; |
|
| 1069 | + } |
|
| 1070 | + list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1071 | + mysqli_free_result($r); |
|
| 1072 | + |
|
| 1073 | + return $c; |
|
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | |
@@ -1093,16 +1093,16 @@ discard block |
||
| 1093 | 1093 | * Erreur eventuelle |
| 1094 | 1094 | **/ |
| 1095 | 1095 | function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
| 1096 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1097 | - $s = mysqli_error($link); |
|
| 1098 | - if ($s) { |
|
| 1099 | - $trace = debug_backtrace(); |
|
| 1100 | - if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1101 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1102 | - } |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - return $s; |
|
| 1096 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1097 | + $s = mysqli_error($link); |
|
| 1098 | + if ($s) { |
|
| 1099 | + $trace = debug_backtrace(); |
|
| 1100 | + if ($trace[0]['function'] != 'spip_mysql_error') { |
|
| 1101 | + spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1102 | + } |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + return $s; |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | |
@@ -1117,18 +1117,18 @@ discard block |
||
| 1117 | 1117 | * 0, pas d'erreur. Autre, numéro de l'erreur. |
| 1118 | 1118 | **/ |
| 1119 | 1119 | function spip_mysql_errno($serveur = '', $requeter = true) { |
| 1120 | - $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1121 | - $s = mysqli_errno($link); |
|
| 1122 | - // 2006 MySQL server has gone away |
|
| 1123 | - // 2013 Lost connection to MySQL server during query |
|
| 1124 | - if (in_array($s, [2006, 2013])) { |
|
| 1125 | - define('spip_interdire_cache', true); |
|
| 1126 | - } |
|
| 1127 | - if ($s) { |
|
| 1128 | - spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - return $s; |
|
| 1120 | + $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1121 | + $s = mysqli_errno($link); |
|
| 1122 | + // 2006 MySQL server has gone away |
|
| 1123 | + // 2013 Lost connection to MySQL server during query |
|
| 1124 | + if (in_array($s, [2006, 2013])) { |
|
| 1125 | + define('spip_interdire_cache', true); |
|
| 1126 | + } |
|
| 1127 | + if ($s) { |
|
| 1128 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + return $s; |
|
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | 1134 | |
@@ -1142,9 +1142,9 @@ discard block |
||
| 1142 | 1142 | * @return int Nombre de lignes |
| 1143 | 1143 | */ |
| 1144 | 1144 | function spip_mysql_count($r, $serveur = '', $requeter = true) { |
| 1145 | - if ($r) { |
|
| 1146 | - return mysqli_num_rows($r); |
|
| 1147 | - } |
|
| 1145 | + if ($r) { |
|
| 1146 | + return mysqli_num_rows($r); |
|
| 1147 | + } |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | |
@@ -1160,7 +1160,7 @@ discard block |
||
| 1160 | 1160 | * @return bool True si réussi |
| 1161 | 1161 | */ |
| 1162 | 1162 | function spip_mysql_free($r, $serveur = '', $requeter = true) { |
| 1163 | - return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1163 | + return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | |
@@ -1188,49 +1188,49 @@ discard block |
||
| 1188 | 1188 | **/ |
| 1189 | 1189 | function spip_mysql_insert($table, $champs, $valeurs, $desc = [], $serveur = '', $requeter = true) { |
| 1190 | 1190 | |
| 1191 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1192 | - $link = $connexion['link']; |
|
| 1193 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1194 | - |
|
| 1195 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1196 | - if ( |
|
| 1197 | - defined('_MYSQL_NOPLANES') |
|
| 1198 | - and _MYSQL_NOPLANES |
|
| 1199 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1200 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1201 | - ) { |
|
| 1202 | - include_spip('inc/charsets'); |
|
| 1203 | - $valeurs = utf8_noplanes($valeurs); |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1207 | - if (!$requeter) { |
|
| 1208 | - return $query; |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - if (isset($_GET['var_profile'])) { |
|
| 1212 | - include_spip('public/tracer'); |
|
| 1213 | - $t = trace_query_start(); |
|
| 1214 | - $e = ''; |
|
| 1215 | - } else { |
|
| 1216 | - $t = 0; |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - $connexion['last'] = $query; |
|
| 1220 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1221 | - $r = false; |
|
| 1222 | - if (mysqli_query($link, $query)) { |
|
| 1223 | - $r = mysqli_insert_id($link); |
|
| 1224 | - } else { |
|
| 1225 | - // Log de l'erreur eventuelle |
|
| 1226 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 1227 | - $e .= spip_mysql_error($query, $serveur); |
|
| 1228 | - } // et du fautif |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1232 | - |
|
| 1233 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1191 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1192 | + $link = $connexion['link']; |
|
| 1193 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1194 | + |
|
| 1195 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1196 | + if ( |
|
| 1197 | + defined('_MYSQL_NOPLANES') |
|
| 1198 | + and _MYSQL_NOPLANES |
|
| 1199 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1200 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 1201 | + ) { |
|
| 1202 | + include_spip('inc/charsets'); |
|
| 1203 | + $valeurs = utf8_noplanes($valeurs); |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1207 | + if (!$requeter) { |
|
| 1208 | + return $query; |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + if (isset($_GET['var_profile'])) { |
|
| 1212 | + include_spip('public/tracer'); |
|
| 1213 | + $t = trace_query_start(); |
|
| 1214 | + $e = ''; |
|
| 1215 | + } else { |
|
| 1216 | + $t = 0; |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + $connexion['last'] = $query; |
|
| 1220 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1221 | + $r = false; |
|
| 1222 | + if (mysqli_query($link, $query)) { |
|
| 1223 | + $r = mysqli_insert_id($link); |
|
| 1224 | + } else { |
|
| 1225 | + // Log de l'erreur eventuelle |
|
| 1226 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 1227 | + $e .= spip_mysql_error($query, $serveur); |
|
| 1228 | + } // et du fautif |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1232 | + |
|
| 1233 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1234 | 1234 | } |
| 1235 | 1235 | |
| 1236 | 1236 | /** |
@@ -1255,26 +1255,26 @@ discard block |
||
| 1255 | 1255 | **/ |
| 1256 | 1256 | function spip_mysql_insertq($table, $couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1257 | 1257 | |
| 1258 | - if (!$desc) { |
|
| 1259 | - $desc = description_table($table, $serveur); |
|
| 1260 | - } |
|
| 1261 | - if (!$desc) { |
|
| 1262 | - $couples = []; |
|
| 1263 | - } |
|
| 1264 | - $fields = isset($desc['field']) ? $desc['field'] : []; |
|
| 1265 | - |
|
| 1266 | - foreach ($couples as $champ => $val) { |
|
| 1267 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - return spip_mysql_insert( |
|
| 1271 | - $table, |
|
| 1272 | - '(' . join(',', array_keys($couples)) . ')', |
|
| 1273 | - '(' . join(',', $couples) . ')', |
|
| 1274 | - $desc, |
|
| 1275 | - $serveur, |
|
| 1276 | - $requeter |
|
| 1277 | - ); |
|
| 1258 | + if (!$desc) { |
|
| 1259 | + $desc = description_table($table, $serveur); |
|
| 1260 | + } |
|
| 1261 | + if (!$desc) { |
|
| 1262 | + $couples = []; |
|
| 1263 | + } |
|
| 1264 | + $fields = isset($desc['field']) ? $desc['field'] : []; |
|
| 1265 | + |
|
| 1266 | + foreach ($couples as $champ => $val) { |
|
| 1267 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + return spip_mysql_insert( |
|
| 1271 | + $table, |
|
| 1272 | + '(' . join(',', array_keys($couples)) . ')', |
|
| 1273 | + '(' . join(',', $couples) . ')', |
|
| 1274 | + $desc, |
|
| 1275 | + $serveur, |
|
| 1276 | + $requeter |
|
| 1277 | + ); |
|
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | |
@@ -1299,34 +1299,34 @@ discard block |
||
| 1299 | 1299 | **/ |
| 1300 | 1300 | function spip_mysql_insertq_multi($table, $tab_couples = [], $desc = [], $serveur = '', $requeter = true) { |
| 1301 | 1301 | |
| 1302 | - if (!$desc) { |
|
| 1303 | - $desc = description_table($table, $serveur); |
|
| 1304 | - } |
|
| 1305 | - if (!$desc) { |
|
| 1306 | - $tab_couples = []; |
|
| 1307 | - } |
|
| 1308 | - $fields = isset($desc['field']) ? $desc['field'] : []; |
|
| 1309 | - |
|
| 1310 | - $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1311 | - $valeurs = []; |
|
| 1312 | - $r = false; |
|
| 1313 | - |
|
| 1314 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1315 | - foreach ($tab_couples as $couples) { |
|
| 1316 | - foreach ($couples as $champ => $val) { |
|
| 1317 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1318 | - } |
|
| 1319 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1320 | - if (count($valeurs) >= 100) { |
|
| 1321 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1322 | - $valeurs = []; |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1325 | - if (count($valeurs)) { |
|
| 1326 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1327 | - } |
|
| 1328 | - |
|
| 1329 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1302 | + if (!$desc) { |
|
| 1303 | + $desc = description_table($table, $serveur); |
|
| 1304 | + } |
|
| 1305 | + if (!$desc) { |
|
| 1306 | + $tab_couples = []; |
|
| 1307 | + } |
|
| 1308 | + $fields = isset($desc['field']) ? $desc['field'] : []; |
|
| 1309 | + |
|
| 1310 | + $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1311 | + $valeurs = []; |
|
| 1312 | + $r = false; |
|
| 1313 | + |
|
| 1314 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1315 | + foreach ($tab_couples as $couples) { |
|
| 1316 | + foreach ($couples as $champ => $val) { |
|
| 1317 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1318 | + } |
|
| 1319 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1320 | + if (count($valeurs) >= 100) { |
|
| 1321 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1322 | + $valeurs = []; |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | + if (count($valeurs)) { |
|
| 1326 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1327 | + } |
|
| 1328 | + |
|
| 1329 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1330 | 1330 | } |
| 1331 | 1331 | |
| 1332 | 1332 | /** |
@@ -1351,19 +1351,19 @@ discard block |
||
| 1351 | 1351 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1352 | 1352 | */ |
| 1353 | 1353 | function spip_mysql_update($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1354 | - $set = []; |
|
| 1355 | - foreach ($champs as $champ => $val) { |
|
| 1356 | - $set[] = $champ . "=$val"; |
|
| 1357 | - } |
|
| 1358 | - if (!empty($set)) { |
|
| 1359 | - return spip_mysql_query( |
|
| 1360 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1361 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1362 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1363 | - $serveur, |
|
| 1364 | - $requeter |
|
| 1365 | - ); |
|
| 1366 | - } |
|
| 1354 | + $set = []; |
|
| 1355 | + foreach ($champs as $champ => $val) { |
|
| 1356 | + $set[] = $champ . "=$val"; |
|
| 1357 | + } |
|
| 1358 | + if (!empty($set)) { |
|
| 1359 | + return spip_mysql_query( |
|
| 1360 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1361 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1362 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1363 | + $serveur, |
|
| 1364 | + $requeter |
|
| 1365 | + ); |
|
| 1366 | + } |
|
| 1367 | 1367 | } |
| 1368 | 1368 | |
| 1369 | 1369 | /** |
@@ -1396,29 +1396,29 @@ discard block |
||
| 1396 | 1396 | */ |
| 1397 | 1397 | function spip_mysql_updateq($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1398 | 1398 | |
| 1399 | - if (!$champs) { |
|
| 1400 | - return; |
|
| 1401 | - } |
|
| 1402 | - if (!$desc) { |
|
| 1403 | - $desc = description_table($table, $serveur); |
|
| 1404 | - } |
|
| 1405 | - if (!$desc) { |
|
| 1406 | - $champs = []; |
|
| 1407 | - } else { |
|
| 1408 | - $fields = $desc['field']; |
|
| 1409 | - } |
|
| 1410 | - $set = []; |
|
| 1411 | - foreach ($champs as $champ => $val) { |
|
| 1412 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1413 | - } |
|
| 1414 | - |
|
| 1415 | - return spip_mysql_query( |
|
| 1416 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1417 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1418 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1419 | - $serveur, |
|
| 1420 | - $requeter |
|
| 1421 | - ); |
|
| 1399 | + if (!$champs) { |
|
| 1400 | + return; |
|
| 1401 | + } |
|
| 1402 | + if (!$desc) { |
|
| 1403 | + $desc = description_table($table, $serveur); |
|
| 1404 | + } |
|
| 1405 | + if (!$desc) { |
|
| 1406 | + $champs = []; |
|
| 1407 | + } else { |
|
| 1408 | + $fields = $desc['field']; |
|
| 1409 | + } |
|
| 1410 | + $set = []; |
|
| 1411 | + foreach ($champs as $champ => $val) { |
|
| 1412 | + $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1413 | + } |
|
| 1414 | + |
|
| 1415 | + return spip_mysql_query( |
|
| 1416 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1417 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1418 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1419 | + $serveur, |
|
| 1420 | + $requeter |
|
| 1421 | + ); |
|
| 1422 | 1422 | } |
| 1423 | 1423 | |
| 1424 | 1424 | /** |
@@ -1434,22 +1434,22 @@ discard block |
||
| 1434 | 1434 | * - False en cas d'erreur. |
| 1435 | 1435 | **/ |
| 1436 | 1436 | function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 1437 | - $res = spip_mysql_query( |
|
| 1438 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1439 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1440 | - $serveur, |
|
| 1441 | - $requeter |
|
| 1442 | - ); |
|
| 1443 | - if (!$requeter) { |
|
| 1444 | - return $res; |
|
| 1445 | - } |
|
| 1446 | - if ($res) { |
|
| 1447 | - $link = _mysql_link($serveur); |
|
| 1448 | - |
|
| 1449 | - return mysqli_affected_rows($link); |
|
| 1450 | - } else { |
|
| 1451 | - return false; |
|
| 1452 | - } |
|
| 1437 | + $res = spip_mysql_query( |
|
| 1438 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1439 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1440 | + $serveur, |
|
| 1441 | + $requeter |
|
| 1442 | + ); |
|
| 1443 | + if (!$requeter) { |
|
| 1444 | + return $res; |
|
| 1445 | + } |
|
| 1446 | + if ($res) { |
|
| 1447 | + $link = _mysql_link($serveur); |
|
| 1448 | + |
|
| 1449 | + return mysqli_affected_rows($link); |
|
| 1450 | + } else { |
|
| 1451 | + return false; |
|
| 1452 | + } |
|
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | 1455 | |
@@ -1478,10 +1478,10 @@ discard block |
||
| 1478 | 1478 | * - False en cas d'erreur. |
| 1479 | 1479 | **/ |
| 1480 | 1480 | function spip_mysql_replace($table, $couples, $desc = [], $serveur = '', $requeter = true) { |
| 1481 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1482 | - ',', |
|
| 1483 | - array_map('_q', $couples) |
|
| 1484 | - ) . ')', $serveur, $requeter); |
|
| 1481 | + return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1482 | + ',', |
|
| 1483 | + array_map('_q', $couples) |
|
| 1484 | + ) . ')', $serveur, $requeter); |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | |
@@ -1510,14 +1510,14 @@ discard block |
||
| 1510 | 1510 | * - False en cas d'erreur. |
| 1511 | 1511 | **/ |
| 1512 | 1512 | function spip_mysql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1513 | - $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1514 | - $valeurs = []; |
|
| 1515 | - foreach ($tab_couples as $couples) { |
|
| 1516 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1517 | - } |
|
| 1518 | - $valeurs = implode(', ', $valeurs); |
|
| 1519 | - |
|
| 1520 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1513 | + $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1514 | + $valeurs = []; |
|
| 1515 | + foreach ($tab_couples as $couples) { |
|
| 1516 | + $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1517 | + } |
|
| 1518 | + $valeurs = implode(', ', $valeurs); |
|
| 1519 | + |
|
| 1520 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1521 | 1521 | } |
| 1522 | 1522 | |
| 1523 | 1523 | |
@@ -1532,32 +1532,32 @@ discard block |
||
| 1532 | 1532 | * @return string Texte de sélection pour la requête |
| 1533 | 1533 | */ |
| 1534 | 1534 | function spip_mysql_multi($objet, $lang) { |
| 1535 | - $lengthlang = strlen("[$lang]"); |
|
| 1536 | - $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1537 | - $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1538 | - $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1539 | - $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1540 | - $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1541 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1542 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1543 | - $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1544 | - $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1545 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1546 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1547 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1548 | - ' TRIM(' . $objet . '), ' . |
|
| 1549 | - ' CONCAT( ' . |
|
| 1550 | - " $debutchaine, " . |
|
| 1551 | - ' IF( ' . |
|
| 1552 | - " $poslang = 0, " . |
|
| 1553 | - " $chainemulti, " . |
|
| 1554 | - " $chainelang" . |
|
| 1555 | - ' ), ' . |
|
| 1556 | - " $finchaine" . |
|
| 1557 | - ' ) ' . |
|
| 1558 | - '))) AS multi'; |
|
| 1559 | - |
|
| 1560 | - return $retour; |
|
| 1535 | + $lengthlang = strlen("[$lang]"); |
|
| 1536 | + $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1537 | + $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1538 | + $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1539 | + $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1540 | + $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1541 | + $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1542 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1543 | + $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1544 | + $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1545 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1546 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1547 | + $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1548 | + ' TRIM(' . $objet . '), ' . |
|
| 1549 | + ' CONCAT( ' . |
|
| 1550 | + " $debutchaine, " . |
|
| 1551 | + ' IF( ' . |
|
| 1552 | + " $poslang = 0, " . |
|
| 1553 | + " $chainemulti, " . |
|
| 1554 | + " $chainelang" . |
|
| 1555 | + ' ), ' . |
|
| 1556 | + " $finchaine" . |
|
| 1557 | + ' ) ' . |
|
| 1558 | + '))) AS multi'; |
|
| 1559 | + |
|
| 1560 | + return $retour; |
|
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | /** |
@@ -1571,7 +1571,7 @@ discard block |
||
| 1571 | 1571 | * Valeur hexadécimale pour MySQL |
| 1572 | 1572 | **/ |
| 1573 | 1573 | function spip_mysql_hex($v) { |
| 1574 | - return '0x' . $v; |
|
| 1574 | + return '0x' . $v; |
|
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | 1577 | /** |
@@ -1587,15 +1587,15 @@ discard block |
||
| 1587 | 1587 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1588 | 1588 | */ |
| 1589 | 1589 | function spip_mysql_quote($v, $type = '') { |
| 1590 | - if (!is_array($v)) { |
|
| 1591 | - return spip_mysql_cite($v, $type); |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1595 | - foreach ($v as $k => $r) { |
|
| 1596 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1597 | - } |
|
| 1598 | - return implode(',', $v); |
|
| 1590 | + if (!is_array($v)) { |
|
| 1591 | + return spip_mysql_cite($v, $type); |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1595 | + foreach ($v as $k => $r) { |
|
| 1596 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1597 | + } |
|
| 1598 | + return implode(',', $v); |
|
| 1599 | 1599 | } |
| 1600 | 1600 | |
| 1601 | 1601 | /** |
@@ -1611,18 +1611,18 @@ discard block |
||
| 1611 | 1611 | * Expression SQL |
| 1612 | 1612 | **/ |
| 1613 | 1613 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1614 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1615 | - return '(' |
|
| 1616 | - . $champ |
|
| 1617 | - . (($interval <= 0) ? '>' : '<') |
|
| 1618 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1619 | - . '(' |
|
| 1620 | - . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1621 | - . ', INTERVAL ' |
|
| 1622 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1623 | - . ' ' |
|
| 1624 | - . $unite |
|
| 1625 | - . '))'; |
|
| 1614 | + $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1615 | + return '(' |
|
| 1616 | + . $champ |
|
| 1617 | + . (($interval <= 0) ? '>' : '<') |
|
| 1618 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1619 | + . '(' |
|
| 1620 | + . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1621 | + . ', INTERVAL ' |
|
| 1622 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1623 | + . ' ' |
|
| 1624 | + . $unite |
|
| 1625 | + . '))'; |
|
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | |
@@ -1646,7 +1646,7 @@ discard block |
||
| 1646 | 1646 | * Expression de requête SQL |
| 1647 | 1647 | **/ |
| 1648 | 1648 | function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1649 | - return "($val $not IN ($valeurs))"; |
|
| 1649 | + return "($val $not IN ($valeurs))"; |
|
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | 1652 | |
@@ -1658,39 +1658,39 @@ discard block |
||
| 1658 | 1658 | * @return string|number Texte ou nombre échappé |
| 1659 | 1659 | */ |
| 1660 | 1660 | function spip_mysql_cite($v, $type) { |
| 1661 | - if (!$type) { |
|
| 1662 | - if (is_bool($v)) { |
|
| 1663 | - return strval(intval($v)); |
|
| 1664 | - } elseif (is_numeric($v)) { |
|
| 1665 | - return strval($v); |
|
| 1666 | - } elseif ($v === null) { |
|
| 1667 | - return "''"; |
|
| 1668 | - } |
|
| 1669 | - return "'" . addslashes($v) . "'"; |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - if ($v === null) { |
|
| 1673 | - if (stripos($type, 'NOT NULL') === false) { |
|
| 1674 | - // null php se traduit en NULL SQL |
|
| 1675 | - return 'NULL'; |
|
| 1676 | - } else { |
|
| 1677 | - return "''"; |
|
| 1678 | - } |
|
| 1679 | - } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1680 | - return $v; |
|
| 1681 | - } elseif (sql_test_int($type)) { |
|
| 1682 | - if ( |
|
| 1683 | - is_numeric($v) |
|
| 1684 | - or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1685 | - ) { |
|
| 1686 | - return $v; |
|
| 1687 | - } else { |
|
| 1688 | - // si pas numerique, forcer le intval |
|
| 1689 | - return intval($v); |
|
| 1690 | - } |
|
| 1691 | - } |
|
| 1692 | - |
|
| 1693 | - return ("'" . addslashes($v) . "'"); |
|
| 1661 | + if (!$type) { |
|
| 1662 | + if (is_bool($v)) { |
|
| 1663 | + return strval(intval($v)); |
|
| 1664 | + } elseif (is_numeric($v)) { |
|
| 1665 | + return strval($v); |
|
| 1666 | + } elseif ($v === null) { |
|
| 1667 | + return "''"; |
|
| 1668 | + } |
|
| 1669 | + return "'" . addslashes($v) . "'"; |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + if ($v === null) { |
|
| 1673 | + if (stripos($type, 'NOT NULL') === false) { |
|
| 1674 | + // null php se traduit en NULL SQL |
|
| 1675 | + return 'NULL'; |
|
| 1676 | + } else { |
|
| 1677 | + return "''"; |
|
| 1678 | + } |
|
| 1679 | + } elseif (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1680 | + return $v; |
|
| 1681 | + } elseif (sql_test_int($type)) { |
|
| 1682 | + if ( |
|
| 1683 | + is_numeric($v) |
|
| 1684 | + or ($v and ctype_xdigit(substr($v, 2)) and $v[0] === '0' and $v[1] === 'x') |
|
| 1685 | + ) { |
|
| 1686 | + return $v; |
|
| 1687 | + } else { |
|
| 1688 | + // si pas numerique, forcer le intval |
|
| 1689 | + return intval($v); |
|
| 1690 | + } |
|
| 1691 | + } |
|
| 1692 | + |
|
| 1693 | + return ("'" . addslashes($v) . "'"); |
|
| 1694 | 1694 | } |
| 1695 | 1695 | |
| 1696 | 1696 | /** |
@@ -1700,7 +1700,7 @@ discard block |
||
| 1700 | 1700 | * True si on a les fonctions, false sinon |
| 1701 | 1701 | */ |
| 1702 | 1702 | function spip_versions_mysql() { |
| 1703 | - return function_exists('mysqli_query'); |
|
| 1703 | + return function_exists('mysqli_query'); |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | |
@@ -1713,20 +1713,20 @@ discard block |
||
| 1713 | 1713 | * - chaîne : code compilé pour le faire désactiver par SPIP sinon |
| 1714 | 1714 | */ |
| 1715 | 1715 | function test_rappel_nom_base_mysql($server_db) { |
| 1716 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1717 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1718 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1716 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1717 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1718 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1719 | 1719 | |
| 1720 | - if ($ok) { |
|
| 1721 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1720 | + if ($ok) { |
|
| 1721 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1722 | 1722 | |
| 1723 | - return ''; |
|
| 1724 | - } else { |
|
| 1725 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1723 | + return ''; |
|
| 1724 | + } else { |
|
| 1725 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1726 | 1726 | |
| 1727 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1728 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1729 | - } |
|
| 1727 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1728 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1729 | + } |
|
| 1730 | 1730 | } |
| 1731 | 1731 | |
| 1732 | 1732 | /** |
@@ -1740,13 +1740,13 @@ discard block |
||
| 1740 | 1740 | * - chaîne : code compilé pour l'indiquer le résultat du test à SPIP |
| 1741 | 1741 | */ |
| 1742 | 1742 | function test_sql_mode_mysql($server_db) { |
| 1743 | - $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1744 | - $row = sql_fetch($res, $server_db); |
|
| 1745 | - if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1746 | - defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1743 | + $res = sql_select('version() as v', '', '', '', '', '', '', $server_db); |
|
| 1744 | + $row = sql_fetch($res, $server_db); |
|
| 1745 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1746 | + defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1747 | 1747 | |
| 1748 | - return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1749 | - } |
|
| 1748 | + return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1749 | + } |
|
| 1750 | 1750 | |
| 1751 | - return ''; |
|
| 1751 | + return ''; |
|
| 1752 | 1752 | } |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | $link = @mysqli_connect($host, $login, $pass); |
| 59 | 59 | } |
| 60 | 60 | } catch (\mysqli_sql_exception $e) { |
| 61 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 61 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 62 | 62 | $link = false; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!$link) { |
| 66 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 66 | + spip_log('Echec mysqli_connect. Erreur : '.mysqli_connect_error(), 'mysql.'._LOG_HS); |
|
| 67 | 67 | |
| 68 | 68 | return false; |
| 69 | 69 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | spip_log( |
| 85 | - "Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? 'operationnelle' : 'impossible'), |
|
| 85 | + "Connexion MySQLi vers $host, base $db, prefixe $prefixe ".($ok ? 'operationnelle' : 'impossible'), |
|
| 86 | 86 | _LOG_DEBUG |
| 87 | 87 | ); |
| 88 | 88 | |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 175 | 175 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 176 | - spip_log('changement de charset sql : ' . 'SET NAMES ' . _q($charset), _LOG_DEBUG); |
|
| 176 | + spip_log('changement de charset sql : '.'SET NAMES '._q($charset), _LOG_DEBUG); |
|
| 177 | 177 | |
| 178 | - return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES ' . _q($charset)); |
|
| 178 | + return mysqli_query($connexion['link'], $connexion['last'] = 'SET NAMES '._q($charset)); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | function spip_mysql_get_charset($charset = [], $serveur = '', $requeter = true) { |
| 191 | 191 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 192 | 192 | $connexion['last'] = $c = 'SHOW CHARACTER SET' |
| 193 | - . (!$charset ? '' : (' LIKE ' . _q($charset['charset']))); |
|
| 193 | + . (!$charset ? '' : (' LIKE '._q($charset['charset']))); |
|
| 194 | 194 | |
| 195 | 195 | return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
| 196 | 196 | } |
@@ -234,21 +234,21 @@ discard block |
||
| 234 | 234 | $debug = ''; |
| 235 | 235 | if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
| 236 | 236 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 237 | - list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 238 | - $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . ' | '; |
|
| 237 | + list(, $id,, $infos) = $GLOBALS['debug']['aucasou']; |
|
| 238 | + $debug .= "BOUCLE$id @ ".(isset($infos[0]) ? $infos[0] : '').' | '; |
|
| 239 | 239 | } |
| 240 | 240 | if (isset($_SERVER['REQUEST_URI'])) { |
| 241 | 241 | $debug .= $_SERVER['REQUEST_URI']; |
| 242 | 242 | } |
| 243 | 243 | if (!empty($GLOBALS['ip'])) { |
| 244 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 244 | + $debug .= ' + '.$GLOBALS['ip']; |
|
| 245 | 245 | } |
| 246 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 246 | + $debug = ' /* '.mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)).' */'; |
|
| 247 | 247 | } |
| 248 | 248 | try { |
| 249 | - $r = mysqli_query($link, $query . $debug); |
|
| 249 | + $r = mysqli_query($link, $query.$debug); |
|
| 250 | 250 | } catch (\mysqli_sql_exception $e) { |
| 251 | - spip_log('mysqli_sql_exception: ' . $e->getMessage(), 'mysql.' . _LOG_DEBUG); |
|
| 251 | + spip_log('mysqli_sql_exception: '.$e->getMessage(), 'mysql.'._LOG_DEBUG); |
|
| 252 | 252 | $r = false; |
| 253 | 253 | // Todo: utiliser l’exception ensuite plutôt que les appels à spip_mysql_errno() |
| 254 | 254 | // mais il faut pour php < 8.1 forcer les exeptions via mysqli_report(). |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 266 | 266 | $link = $connexion['link']; |
| 267 | 267 | //On retente au cas où |
| 268 | - $r = mysqli_query($link, $query . $debug); |
|
| 268 | + $r = mysqli_query($link, $query.$debug); |
|
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | // d'utiliser ceux-ci, copie-colle de phpmyadmin |
| 294 | 294 | $query = preg_replace(',^TABLE\s*`([^`]*)`,i', "TABLE \\1", $query); |
| 295 | 295 | |
| 296 | - return spip_mysql_query('ALTER ' . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 296 | + return spip_mysql_query('ALTER '.$query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @return bool Toujours true |
| 307 | 307 | */ |
| 308 | 308 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 309 | - spip_mysql_query('OPTIMIZE TABLE ' . $table); |
|
| 309 | + spip_mysql_query('OPTIMIZE TABLE '.$table); |
|
| 310 | 310 | |
| 311 | 311 | return true; |
| 312 | 312 | } |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | $link = $connexion['link']; |
| 330 | 330 | $db = $connexion['db']; |
| 331 | 331 | |
| 332 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 332 | + $query = 'EXPLAIN '._mysql_traite_query($query, $db, $prefixe); |
|
| 333 | 333 | $r = mysqli_query($link, $query); |
| 334 | 334 | |
| 335 | 335 | return spip_mysql_fetch($r, null, $serveur); |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | . calculer_mysql_expression('WHERE', $where) |
| 381 | 381 | . calculer_mysql_expression('GROUP BY', $groupby, ',') |
| 382 | 382 | . calculer_mysql_expression('HAVING', $having) |
| 383 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 383 | + . ($orderby ? ("\nORDER BY ".spip_mysql_order($orderby)) : '') |
|
| 384 | 384 | . ($limit ? "\nLIMIT $limit" : ''); |
| 385 | 385 | |
| 386 | 386 | // renvoyer la requete inerte si demandee |
@@ -470,12 +470,12 @@ discard block |
||
| 470 | 470 | $exp = "\n$expression "; |
| 471 | 471 | |
| 472 | 472 | if (!is_array($v)) { |
| 473 | - return $exp . $v; |
|
| 473 | + return $exp.$v; |
|
| 474 | 474 | } else { |
| 475 | 475 | if (strtoupper($join) === 'AND') { |
| 476 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 476 | + return $exp.join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 477 | 477 | } else { |
| 478 | - return $exp . join($join, $v); |
|
| 478 | + return $exp.join($join, $v); |
|
| 479 | 479 | } |
| 480 | 480 | } |
| 481 | 481 | } |
@@ -493,17 +493,17 @@ discard block |
||
| 493 | 493 | if (substr($k, -1) == '@') { |
| 494 | 494 | // c'est une jointure qui se refere au from precedent |
| 495 | 495 | // pas de virgule |
| 496 | - $res .= ' ' . $v; |
|
| 496 | + $res .= ' '.$v; |
|
| 497 | 497 | } else { |
| 498 | 498 | if (!is_numeric($k)) { |
| 499 | 499 | $p = strpos($v, ' '); |
| 500 | 500 | if ($p) { |
| 501 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 501 | + $v = substr($v, 0, $p)." AS `$k`".substr($v, $p); |
|
| 502 | 502 | } else { |
| 503 | 503 | $v .= " AS `$k`"; |
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | - $res .= ', ' . $v; |
|
| 506 | + $res .= ', '.$v; |
|
| 507 | 507 | } |
| 508 | 508 | } |
| 509 | 509 | |
@@ -533,13 +533,13 @@ discard block |
||
| 533 | 533 | function _mysql_traite_query($query, $db = '', $prefixe = '', $echappe_textes = true) { |
| 534 | 534 | |
| 535 | 535 | if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
| 536 | - $pref = '`' . $db . '`.'; |
|
| 536 | + $pref = '`'.$db.'`.'; |
|
| 537 | 537 | } else { |
| 538 | 538 | $pref = ''; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | if ($prefixe) { |
| 542 | - $pref .= $prefixe . '_'; |
|
| 542 | + $pref .= $prefixe.'_'; |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | $suite_echap = $suite; |
| 559 | 559 | } |
| 560 | 560 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
| 561 | - $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 561 | + $suite_echap = $r[1]._mysql_traite_query($r[2], $db, $prefixe, false); |
|
| 562 | 562 | if ($echappe_textes) { |
| 563 | 563 | $suite = query_reinjecte_textes($suite_echap, $textes); |
| 564 | 564 | } |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | } |
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 571 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1'.$pref, $query).$suite; |
|
| 572 | 572 | |
| 573 | 573 | // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
| 574 | 574 | // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | $link = _mysql_link($serveur); |
| 605 | 605 | $ok = mysqli_select_db($link, $db); |
| 606 | 606 | if (!$ok) { |
| 607 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 607 | + spip_log('Echec mysqli_selectdb. Erreur : '.mysqli_error($link), 'mysql.'._LOG_CRITIQUE); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | return $ok; |
@@ -694,10 +694,10 @@ discard block |
||
| 694 | 694 | |
| 695 | 695 | $character_set = ''; |
| 696 | 696 | if (@$GLOBALS['meta']['charset_sql_base']) { |
| 697 | - $character_set .= ' CHARACTER SET ' . $GLOBALS['meta']['charset_sql_base']; |
|
| 697 | + $character_set .= ' CHARACTER SET '.$GLOBALS['meta']['charset_sql_base']; |
|
| 698 | 698 | } |
| 699 | 699 | if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
| 700 | - $character_set .= ' COLLATE ' . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 700 | + $character_set .= ' COLLATE '.$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | foreach ($champs as $k => $v) { |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | preg_match(',(char|text),i', $defs[1]) |
| 708 | 708 | and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
| 709 | 709 | ) { |
| 710 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 710 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 711 | 711 | } |
| 712 | 712 | } |
| 713 | 713 | |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | $s = ','; |
| 720 | 720 | } |
| 721 | 721 | $temporary = $temporary ? 'TEMPORARY' : ''; |
| 722 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ')' |
|
| 722 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query".($keys ? ",$keys" : '').')' |
|
| 723 | 723 | . ' ENGINE=MyISAM' |
| 724 | 724 | . ($character_set ? " DEFAULT $character_set" : '') |
| 725 | 725 | . "\n"; |
@@ -799,7 +799,7 @@ discard block |
||
| 799 | 799 | return false; |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 802 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 803 | 803 | |
| 804 | 804 | return spip_mysql_query($query, $serveur, $requeter); |
| 805 | 805 | } |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | * Ressource à utiliser avec sql_fetch() |
| 858 | 858 | **/ |
| 859 | 859 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 860 | - return spip_mysql_query('SHOW TABLES LIKE ' . _q($match), $serveur, $requeter); |
|
| 860 | + return spip_mysql_query('SHOW TABLES LIKE '._q($match), $serveur, $requeter); |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | /** |
@@ -890,7 +890,7 @@ discard block |
||
| 890 | 890 | * Ressource à utiliser avec sql_fetch() |
| 891 | 891 | **/ |
| 892 | 892 | function spip_mysql_table_exists(string $table, $serveur = '', $requeter = true) { |
| 893 | - $r = spip_mysql_query('SHOW TABLES LIKE ' . _q($table), $serveur, $requeter); |
|
| 893 | + $r = spip_mysql_query('SHOW TABLES LIKE '._q($table), $serveur, $requeter); |
|
| 894 | 894 | if (!$requeter) { |
| 895 | 895 | return $r; |
| 896 | 896 | } |
@@ -972,22 +972,22 @@ discard block |
||
| 972 | 972 | } |
| 973 | 973 | if ($val['Default'] === '0' || $val['Default']) { |
| 974 | 974 | if (preg_match('/[A-Z_]/', $val['Default'])) { |
| 975 | - $nfields[$val['Field']] .= ' DEFAULT ' . $val['Default']; |
|
| 975 | + $nfields[$val['Field']] .= ' DEFAULT '.$val['Default']; |
|
| 976 | 976 | } else { |
| 977 | - $nfields[$val['Field']] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 977 | + $nfields[$val['Field']] .= " DEFAULT '".$val['Default']."'"; |
|
| 978 | 978 | } |
| 979 | 979 | } |
| 980 | 980 | if ($val['Extra']) { |
| 981 | - $nfields[$val['Field']] .= ' ' . $val['Extra']; |
|
| 981 | + $nfields[$val['Field']] .= ' '.$val['Extra']; |
|
| 982 | 982 | } |
| 983 | 983 | if ($val['Key'] == 'PRI') { |
| 984 | 984 | $nkeys['PRIMARY KEY'] = $val['Field']; |
| 985 | 985 | } else { |
| 986 | 986 | if ($val['Key'] == 'MUL') { |
| 987 | - $nkeys['KEY ' . $val['Field']] = $val['Field']; |
|
| 987 | + $nkeys['KEY '.$val['Field']] = $val['Field']; |
|
| 988 | 988 | } else { |
| 989 | 989 | if ($val['Key'] == 'UNI') { |
| 990 | - $nkeys['UNIQUE KEY ' . $val['Field']] = $val['Field']; |
|
| 990 | + $nkeys['UNIQUE KEY '.$val['Field']] = $val['Field']; |
|
| 991 | 991 | } |
| 992 | 992 | } |
| 993 | 993 | } |
@@ -1058,7 +1058,7 @@ discard block |
||
| 1058 | 1058 | $serveur = '', |
| 1059 | 1059 | $requeter = true |
| 1060 | 1060 | ) { |
| 1061 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1061 | + $c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1062 | 1062 | |
| 1063 | 1063 | $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
| 1064 | 1064 | if (!$requeter) { |
@@ -1098,7 +1098,7 @@ discard block |
||
| 1098 | 1098 | if ($s) { |
| 1099 | 1099 | $trace = debug_backtrace(); |
| 1100 | 1100 | if ($trace[0]['function'] != 'spip_mysql_error') { |
| 1101 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1101 | + spip_log("$s - $query - ".sql_error_backtrace(), 'mysql.'._LOG_ERREUR); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | } |
| 1104 | 1104 | |
@@ -1269,8 +1269,8 @@ discard block |
||
| 1269 | 1269 | |
| 1270 | 1270 | return spip_mysql_insert( |
| 1271 | 1271 | $table, |
| 1272 | - '(' . join(',', array_keys($couples)) . ')', |
|
| 1273 | - '(' . join(',', $couples) . ')', |
|
| 1272 | + '('.join(',', array_keys($couples)).')', |
|
| 1273 | + '('.join(',', $couples).')', |
|
| 1274 | 1274 | $desc, |
| 1275 | 1275 | $serveur, |
| 1276 | 1276 | $requeter |
@@ -1307,7 +1307,7 @@ discard block |
||
| 1307 | 1307 | } |
| 1308 | 1308 | $fields = isset($desc['field']) ? $desc['field'] : []; |
| 1309 | 1309 | |
| 1310 | - $cles = '(' . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1310 | + $cles = '('.join(',', array_keys(reset($tab_couples))).')'; |
|
| 1311 | 1311 | $valeurs = []; |
| 1312 | 1312 | $r = false; |
| 1313 | 1313 | |
@@ -1316,7 +1316,7 @@ discard block |
||
| 1316 | 1316 | foreach ($couples as $champ => $val) { |
| 1317 | 1317 | $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
| 1318 | 1318 | } |
| 1319 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1319 | + $valeurs[] = '('.join(',', $couples).')'; |
|
| 1320 | 1320 | if (count($valeurs) >= 100) { |
| 1321 | 1321 | $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
| 1322 | 1322 | $valeurs = []; |
@@ -1353,7 +1353,7 @@ discard block |
||
| 1353 | 1353 | function spip_mysql_update($table, $champs, $where = '', $desc = [], $serveur = '', $requeter = true) { |
| 1354 | 1354 | $set = []; |
| 1355 | 1355 | foreach ($champs as $champ => $val) { |
| 1356 | - $set[] = $champ . "=$val"; |
|
| 1356 | + $set[] = $champ."=$val"; |
|
| 1357 | 1357 | } |
| 1358 | 1358 | if (!empty($set)) { |
| 1359 | 1359 | return spip_mysql_query( |
@@ -1409,7 +1409,7 @@ discard block |
||
| 1409 | 1409 | } |
| 1410 | 1410 | $set = []; |
| 1411 | 1411 | foreach ($champs as $champ => $val) { |
| 1412 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1412 | + $set[] = $champ.'='.spip_mysql_cite($val, @$fields[$champ]); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | 1415 | return spip_mysql_query( |
@@ -1478,10 +1478,10 @@ discard block |
||
| 1478 | 1478 | * - False en cas d'erreur. |
| 1479 | 1479 | **/ |
| 1480 | 1480 | function spip_mysql_replace($table, $couples, $desc = [], $serveur = '', $requeter = true) { |
| 1481 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join( |
|
| 1481 | + return spip_mysql_query("REPLACE $table (".join(',', array_keys($couples)).') VALUES ('.join( |
|
| 1482 | 1482 | ',', |
| 1483 | 1483 | array_map('_q', $couples) |
| 1484 | - ) . ')', $serveur, $requeter); |
|
| 1484 | + ).')', $serveur, $requeter); |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | |
@@ -1510,10 +1510,10 @@ discard block |
||
| 1510 | 1510 | * - False en cas d'erreur. |
| 1511 | 1511 | **/ |
| 1512 | 1512 | function spip_mysql_replace_multi($table, $tab_couples, $desc = [], $serveur = '', $requeter = true) { |
| 1513 | - $cles = '(' . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1513 | + $cles = '('.join(',', array_keys($tab_couples[0])).')'; |
|
| 1514 | 1514 | $valeurs = []; |
| 1515 | 1515 | foreach ($tab_couples as $couples) { |
| 1516 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1516 | + $valeurs[] = '('.join(',', array_map('_q', $couples)).')'; |
|
| 1517 | 1517 | } |
| 1518 | 1518 | $valeurs = implode(', ', $valeurs); |
| 1519 | 1519 | |
@@ -1533,28 +1533,28 @@ discard block |
||
| 1533 | 1533 | */ |
| 1534 | 1534 | function spip_mysql_multi($objet, $lang) { |
| 1535 | 1535 | $lengthlang = strlen("[$lang]"); |
| 1536 | - $posmulti = 'INSTR(' . $objet . ", '<multi>')"; |
|
| 1537 | - $posfinmulti = 'INSTR(' . $objet . ", '</multi>')"; |
|
| 1538 | - $debutchaine = 'LEFT(' . $objet . ", $posmulti-1)"; |
|
| 1539 | - $finchaine = 'RIGHT(' . $objet . ', CHAR_LENGTH(' . $objet . ") -(7+$posfinmulti))"; |
|
| 1540 | - $chainemulti = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1541 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1536 | + $posmulti = 'INSTR('.$objet.", '<multi>')"; |
|
| 1537 | + $posfinmulti = 'INSTR('.$objet.", '</multi>')"; |
|
| 1538 | + $debutchaine = 'LEFT('.$objet.", $posmulti-1)"; |
|
| 1539 | + $finchaine = 'RIGHT('.$objet.', CHAR_LENGTH('.$objet.") -(7+$posfinmulti))"; |
|
| 1540 | + $chainemulti = 'TRIM(SUBSTRING('.$objet.", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1541 | + $poslang = "INSTR($chainemulti,'[".$lang."]')"; |
|
| 1542 | 1542 | $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
| 1543 | - $chainelang = 'TRIM(SUBSTRING(' . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1544 | - $posfinlang = 'INSTR(' . $chainelang . ", '[')"; |
|
| 1543 | + $chainelang = 'TRIM(SUBSTRING('.$objet.", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1544 | + $posfinlang = 'INSTR('.$chainelang.", '[')"; |
|
| 1545 | 1545 | $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
| 1546 | 1546 | //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
| 1547 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1548 | - ' TRIM(' . $objet . '), ' . |
|
| 1549 | - ' CONCAT( ' . |
|
| 1550 | - " $debutchaine, " . |
|
| 1551 | - ' IF( ' . |
|
| 1552 | - " $poslang = 0, " . |
|
| 1553 | - " $chainemulti, " . |
|
| 1554 | - " $chainelang" . |
|
| 1555 | - ' ), ' . |
|
| 1556 | - " $finchaine" . |
|
| 1557 | - ' ) ' . |
|
| 1547 | + $retour = "(TRIM(IF($posmulti = 0 , ". |
|
| 1548 | + ' TRIM('.$objet.'), '. |
|
| 1549 | + ' CONCAT( '. |
|
| 1550 | + " $debutchaine, ". |
|
| 1551 | + ' IF( '. |
|
| 1552 | + " $poslang = 0, ". |
|
| 1553 | + " $chainemulti, ". |
|
| 1554 | + " $chainelang". |
|
| 1555 | + ' ), '. |
|
| 1556 | + " $finchaine". |
|
| 1557 | + ' ) '. |
|
| 1558 | 1558 | '))) AS multi'; |
| 1559 | 1559 | |
| 1560 | 1560 | return $retour; |
@@ -1571,7 +1571,7 @@ discard block |
||
| 1571 | 1571 | * Valeur hexadécimale pour MySQL |
| 1572 | 1572 | **/ |
| 1573 | 1573 | function spip_mysql_hex($v) { |
| 1574 | - return '0x' . $v; |
|
| 1574 | + return '0x'.$v; |
|
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | 1577 | /** |
@@ -1611,7 +1611,7 @@ discard block |
||
| 1611 | 1611 | * Expression SQL |
| 1612 | 1612 | **/ |
| 1613 | 1613 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1614 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1614 | + $use_now = (($champ === 'maj' or strpos($champ, '.maj')) ? true : false); |
|
| 1615 | 1615 | return '(' |
| 1616 | 1616 | . $champ |
| 1617 | 1617 | . (($interval <= 0) ? '>' : '<') |
@@ -1666,7 +1666,7 @@ discard block |
||
| 1666 | 1666 | } elseif ($v === null) { |
| 1667 | 1667 | return "''"; |
| 1668 | 1668 | } |
| 1669 | - return "'" . addslashes($v) . "'"; |
|
| 1669 | + return "'".addslashes($v)."'"; |
|
| 1670 | 1670 | } |
| 1671 | 1671 | |
| 1672 | 1672 | if ($v === null) { |
@@ -1690,7 +1690,7 @@ discard block |
||
| 1690 | 1690 | } |
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | - return ("'" . addslashes($v) . "'"); |
|
| 1693 | + return ("'".addslashes($v)."'"); |
|
| 1694 | 1694 | } |
| 1695 | 1695 | |
| 1696 | 1696 | /** |
@@ -1724,7 +1724,7 @@ discard block |
||
| 1724 | 1724 | } else { |
| 1725 | 1725 | $GLOBALS['mysql_rappel_nom_base'] = false; |
| 1726 | 1726 | |
| 1727 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1727 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; ". |
|
| 1728 | 1728 | "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
| 1729 | 1729 | } |
| 1730 | 1730 | } |
@@ -553,16 +553,14 @@ |
||
| 553 | 553 | if (stripos($suite, 'SELECT') !== false) { |
| 554 | 554 | if ($echappe_textes) { |
| 555 | 555 | list($suite_echap, $textes) = query_echappe_textes($suite); |
| 556 | - } |
|
| 557 | - else { |
|
| 556 | + } else { |
|
| 558 | 557 | $suite_echap = $suite; |
| 559 | 558 | } |
| 560 | 559 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite_echap, $r)) { |
| 561 | 560 | $suite_echap = $r[1] . _mysql_traite_query($r[2], $db, $prefixe, false); |
| 562 | 561 | if ($echappe_textes) { |
| 563 | 562 | $suite = query_reinjecte_textes($suite_echap, $textes); |
| 564 | - } |
|
| 565 | - else { |
|
| 563 | + } else { |
|
| 566 | 564 | $suite = $suite_echap; |
| 567 | 565 | } |
| 568 | 566 | } |
@@ -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 | include_spip('inc/filtres'); |
| 23 | 23 | include_spip('inc/lang'); |
@@ -39,21 +39,21 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function definir_puce() { |
| 41 | 41 | |
| 42 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 42 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 43 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 44 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 45 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 46 | 46 | |
| 47 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | - if ($dir == 'rtl') { |
|
| 49 | - $p .= '_rtl'; |
|
| 50 | - } |
|
| 47 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 48 | + if ($dir == 'rtl') { |
|
| 49 | + $p .= '_rtl'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - if (!isset($GLOBALS[$p])) { |
|
| 53 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | - } |
|
| 52 | + if (!isset($GLOBALS[$p])) { |
|
| 53 | + $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return $GLOBALS[$p]; |
|
| 56 | + return $GLOBALS[$p]; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 62 | 62 | |
| 63 | 63 | if (!defined('_BALISES_BLOCS')) { |
| 64 | - define( |
|
| 65 | - '_BALISES_BLOCS', |
|
| 66 | - 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 67 | - ); |
|
| 64 | + define( |
|
| 65 | + '_BALISES_BLOCS', |
|
| 66 | + 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 67 | + ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 71 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 71 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | // |
@@ -80,111 +80,111 @@ discard block |
||
| 80 | 80 | // echappe est un div ou un span |
| 81 | 81 | // https://code.spip.net/@code_echappement |
| 82 | 82 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 83 | - if (!strlen($rempl)) { |
|
| 84 | - return ''; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Tester si on echappe en span ou en div |
|
| 88 | - if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 89 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 93 | - $taille = 30000; |
|
| 94 | - $return = ''; |
|
| 95 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 96 | - // Convertir en base64 et cacher dans un attribut |
|
| 97 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 98 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 99 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - return $return; |
|
| 83 | + if (!strlen($rempl)) { |
|
| 84 | + return ''; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Tester si on echappe en span ou en div |
|
| 88 | + if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 89 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 93 | + $taille = 30000; |
|
| 94 | + $return = ''; |
|
| 95 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 96 | + // Convertir en base64 et cacher dans un attribut |
|
| 97 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 98 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 99 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + return $return; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
| 106 | 106 | // Echapper les <html>...</ html> |
| 107 | 107 | // https://code.spip.net/@traiter_echap_html_dist |
| 108 | 108 | function traiter_echap_html_dist($regs) { |
| 109 | - return $regs[3]; |
|
| 109 | + return $regs[3]; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | // Echapper les <pre>...</ pre> |
| 113 | 113 | function traiter_echap_pre_dist($regs) { |
| 114 | - // echapper les <code> dans <pre> |
|
| 115 | - $pre = $regs[3]; |
|
| 116 | - |
|
| 117 | - // echapper les < dans <code> |
|
| 118 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 119 | - if ( |
|
| 120 | - strpos($pre, '<') !== false |
|
| 121 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 122 | - ) { |
|
| 123 | - foreach ($matches as $m) { |
|
| 124 | - if ($m[1] === 'code') { |
|
| 125 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 126 | - $pre = str_replace($m[0], $code, $pre); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - return "<pre>$pre</pre>"; |
|
| 114 | + // echapper les <code> dans <pre> |
|
| 115 | + $pre = $regs[3]; |
|
| 116 | + |
|
| 117 | + // echapper les < dans <code> |
|
| 118 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 119 | + if ( |
|
| 120 | + strpos($pre, '<') !== false |
|
| 121 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 122 | + ) { |
|
| 123 | + foreach ($matches as $m) { |
|
| 124 | + if ($m[1] === 'code') { |
|
| 125 | + $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 126 | + $pre = str_replace($m[0], $code, $pre); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + return "<pre>$pre</pre>"; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // Echapper les <code>...</ code> |
| 134 | 134 | // https://code.spip.net/@traiter_echap_code_dist |
| 135 | 135 | function traiter_echap_code_dist($regs) { |
| 136 | - list(, , $att, $corps) = $regs; |
|
| 137 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 138 | - |
|
| 139 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 140 | - if (is_int(strpos($echap, "\n"))) { |
|
| 141 | - // supprimer les sauts de ligne debut/fin |
|
| 142 | - // (mais pas les espaces => ascii art). |
|
| 143 | - $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 144 | - $echap = nl2br($echap); |
|
| 145 | - $echap = "<div style='text-align: left;' " |
|
| 146 | - . "class='spip_code' dir='ltr'><code$att>" |
|
| 147 | - . $echap . '</code></div>'; |
|
| 148 | - } else { |
|
| 149 | - $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - $echap = str_replace("\t", ' ', $echap); |
|
| 153 | - $echap = str_replace(' ', ' ', $echap); |
|
| 154 | - |
|
| 155 | - return $echap; |
|
| 136 | + list(, , $att, $corps) = $regs; |
|
| 137 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 138 | + |
|
| 139 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 140 | + if (is_int(strpos($echap, "\n"))) { |
|
| 141 | + // supprimer les sauts de ligne debut/fin |
|
| 142 | + // (mais pas les espaces => ascii art). |
|
| 143 | + $echap = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $echap); |
|
| 144 | + $echap = nl2br($echap); |
|
| 145 | + $echap = "<div style='text-align: left;' " |
|
| 146 | + . "class='spip_code' dir='ltr'><code$att>" |
|
| 147 | + . $echap . '</code></div>'; |
|
| 148 | + } else { |
|
| 149 | + $echap = "<code$att class='spip_code' dir='ltr'>" . $echap . '</code>'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + $echap = str_replace("\t", ' ', $echap); |
|
| 153 | + $echap = str_replace(' ', ' ', $echap); |
|
| 154 | + |
|
| 155 | + return $echap; |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 159 | 159 | // https://code.spip.net/@traiter_echap_cadre_dist |
| 160 | 160 | function traiter_echap_cadre_dist($regs) { |
| 161 | - $echap = trim(entites_html($regs[3])); |
|
| 162 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 163 | - $lignes = explode("\n", trim($echap)); |
|
| 164 | - $n = 0; |
|
| 165 | - foreach ($lignes as $l) { |
|
| 166 | - $n += floor(strlen($l) / 60) + 1; |
|
| 167 | - } |
|
| 168 | - $n = max($n, 2); |
|
| 169 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 170 | - |
|
| 171 | - return $echap; |
|
| 161 | + $echap = trim(entites_html($regs[3])); |
|
| 162 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 163 | + $lignes = explode("\n", trim($echap)); |
|
| 164 | + $n = 0; |
|
| 165 | + foreach ($lignes as $l) { |
|
| 166 | + $n += floor(strlen($l) / 60) + 1; |
|
| 167 | + } |
|
| 168 | + $n = max($n, 2); |
|
| 169 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre' dir='ltr'>$echap</textarea>"; |
|
| 170 | + |
|
| 171 | + return $echap; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // https://code.spip.net/@traiter_echap_frame_dist |
| 175 | 175 | function traiter_echap_frame_dist($regs) { |
| 176 | - return traiter_echap_cadre_dist($regs); |
|
| 176 | + return traiter_echap_cadre_dist($regs); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // https://code.spip.net/@traiter_echap_script_dist |
| 180 | 180 | function traiter_echap_script_dist($regs) { |
| 181 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 182 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 183 | - return highlight_string($regs[0], true); |
|
| 184 | - } |
|
| 181 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 182 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 183 | + return highlight_string($regs[0], true); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - // Cas normal : le script passe tel quel |
|
| 187 | - return $regs[0]; |
|
| 186 | + // Cas normal : le script passe tel quel |
|
| 187 | + return $regs[0]; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\s[^>]*)?>(.*)</\1>,UimsS'); |
@@ -204,79 +204,79 @@ discard block |
||
| 204 | 204 | * @return string|string[] |
| 205 | 205 | */ |
| 206 | 206 | function echappe_html( |
| 207 | - $letexte, |
|
| 208 | - $source = '', |
|
| 209 | - $no_transform = false, |
|
| 210 | - $preg = '', |
|
| 211 | - $callback_prefix = '' |
|
| 207 | + $letexte, |
|
| 208 | + $source = '', |
|
| 209 | + $no_transform = false, |
|
| 210 | + $preg = '', |
|
| 211 | + $callback_prefix = '' |
|
| 212 | 212 | ) { |
| 213 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 214 | - return $letexte; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // si le texte recu est long PCRE risque d'exploser, on |
|
| 218 | - // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 219 | - if (($len = strlen($letexte)) > 100000) { |
|
| 220 | - if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 221 | - $old = 100000; |
|
| 222 | - } |
|
| 223 | - if ($len > $old) { |
|
| 224 | - $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 225 | - spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if ( |
|
| 230 | - ($preg or strpos($letexte, '<') !== false) |
|
| 231 | - and preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 232 | - ) { |
|
| 233 | - foreach ($matches as $regs) { |
|
| 234 | - // echappements tels quels ? |
|
| 235 | - if ($no_transform) { |
|
| 236 | - $echap = $regs[0]; |
|
| 237 | - } // sinon les traiter selon le cas |
|
| 238 | - else { |
|
| 239 | - if ( |
|
| 240 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 241 | - or function_exists($f = $f . '_dist') |
|
| 242 | - ) { |
|
| 243 | - $echap = $f($regs); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $p = strpos($letexte, $regs[0]); |
|
| 248 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - if ($no_transform) { |
|
| 253 | - return $letexte; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 257 | - // seulement si on a echappe les <script> |
|
| 258 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 259 | - // dans une callback autonommee |
|
| 260 | - if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
|
| 261 | - if ( |
|
| 262 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 263 | - ',<[?].*($|[?]>),UisS', |
|
| 264 | - $letexte, |
|
| 265 | - $matches, |
|
| 266 | - PREG_SET_ORDER |
|
| 267 | - ) |
|
| 268 | - ) { |
|
| 269 | - foreach ($matches as $regs) { |
|
| 270 | - $letexte = str_replace( |
|
| 271 | - $regs[0], |
|
| 272 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 273 | - $letexte |
|
| 274 | - ); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return $letexte; |
|
| 213 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 214 | + return $letexte; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // si le texte recu est long PCRE risque d'exploser, on |
|
| 218 | + // fait donc un mic-mac pour augmenter pcre.backtrack_limit |
|
| 219 | + if (($len = strlen($letexte)) > 100000) { |
|
| 220 | + if (!$old = @ini_get('pcre.backtrack_limit')) { |
|
| 221 | + $old = 100000; |
|
| 222 | + } |
|
| 223 | + if ($len > $old) { |
|
| 224 | + $a = @ini_set('pcre.backtrack_limit', $len); |
|
| 225 | + spip_log("ini_set pcre.backtrack_limit=$len ($old)"); |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if ( |
|
| 230 | + ($preg or strpos($letexte, '<') !== false) |
|
| 231 | + and preg_match_all($preg ? $preg : _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 232 | + ) { |
|
| 233 | + foreach ($matches as $regs) { |
|
| 234 | + // echappements tels quels ? |
|
| 235 | + if ($no_transform) { |
|
| 236 | + $echap = $regs[0]; |
|
| 237 | + } // sinon les traiter selon le cas |
|
| 238 | + else { |
|
| 239 | + if ( |
|
| 240 | + function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 241 | + or function_exists($f = $f . '_dist') |
|
| 242 | + ) { |
|
| 243 | + $echap = $f($regs); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $p = strpos($letexte, $regs[0]); |
|
| 248 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + if ($no_transform) { |
|
| 253 | + return $letexte; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 257 | + // seulement si on a echappe les <script> |
|
| 258 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 259 | + // dans une callback autonommee |
|
| 260 | + if (strpos($preg ? $preg : _PROTEGE_BLOCS, 'script') !== false) { |
|
| 261 | + if ( |
|
| 262 | + strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 263 | + ',<[?].*($|[?]>),UisS', |
|
| 264 | + $letexte, |
|
| 265 | + $matches, |
|
| 266 | + PREG_SET_ORDER |
|
| 267 | + ) |
|
| 268 | + ) { |
|
| 269 | + foreach ($matches as $regs) { |
|
| 270 | + $letexte = str_replace( |
|
| 271 | + $regs[0], |
|
| 272 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 273 | + $letexte |
|
| 274 | + ); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return $letexte; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | // |
@@ -285,58 +285,58 @@ discard block |
||
| 285 | 285 | // par propre() : exemple dans multi et dans typo() |
| 286 | 286 | // https://code.spip.net/@echappe_retour |
| 287 | 287 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 288 | - if (strpos($letexte, "base64$source")) { |
|
| 289 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 290 | - $max_prof = 5; |
|
| 291 | - while ( |
|
| 292 | - strpos($letexte, '<') !== false |
|
| 293 | - and |
|
| 294 | - preg_match_all( |
|
| 295 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 296 | - $letexte, |
|
| 297 | - $regs, |
|
| 298 | - PREG_SET_ORDER |
|
| 299 | - ) |
|
| 300 | - and $max_prof-- |
|
| 301 | - ) { |
|
| 302 | - foreach ($regs as $reg) { |
|
| 303 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 304 | - // recherche d'attributs supplementaires |
|
| 305 | - $at = []; |
|
| 306 | - foreach (['lang', 'dir'] as $attr) { |
|
| 307 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 308 | - $at[$attr] = $a; |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - if ($at) { |
|
| 312 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 313 | - foreach ($at as $attr => $a) { |
|
| 314 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - if ($filtre) { |
|
| 318 | - $rempl = $filtre($rempl); |
|
| 319 | - } |
|
| 320 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - return $letexte; |
|
| 288 | + if (strpos($letexte, "base64$source")) { |
|
| 289 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 290 | + $max_prof = 5; |
|
| 291 | + while ( |
|
| 292 | + strpos($letexte, '<') !== false |
|
| 293 | + and |
|
| 294 | + preg_match_all( |
|
| 295 | + ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 296 | + $letexte, |
|
| 297 | + $regs, |
|
| 298 | + PREG_SET_ORDER |
|
| 299 | + ) |
|
| 300 | + and $max_prof-- |
|
| 301 | + ) { |
|
| 302 | + foreach ($regs as $reg) { |
|
| 303 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 304 | + // recherche d'attributs supplementaires |
|
| 305 | + $at = []; |
|
| 306 | + foreach (['lang', 'dir'] as $attr) { |
|
| 307 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 308 | + $at[$attr] = $a; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + if ($at) { |
|
| 312 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 313 | + foreach ($at as $attr => $a) { |
|
| 314 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + if ($filtre) { |
|
| 318 | + $rempl = $filtre($rempl); |
|
| 319 | + } |
|
| 320 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + return $letexte; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // Reinserer le javascript de confiance (venant des modeles) |
| 329 | 329 | |
| 330 | 330 | // https://code.spip.net/@echappe_retour_modeles |
| 331 | 331 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 332 | - $letexte = echappe_retour($letexte); |
|
| 332 | + $letexte = echappe_retour($letexte); |
|
| 333 | 333 | |
| 334 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 335 | - if ($interdire_scripts) { |
|
| 336 | - $letexte = interdire_scripts($letexte); |
|
| 337 | - } |
|
| 334 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 335 | + if ($interdire_scripts) { |
|
| 336 | + $letexte = interdire_scripts($letexte); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - return trim($letexte); |
|
| 339 | + return trim($letexte); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | |
@@ -364,132 +364,132 @@ discard block |
||
| 364 | 364 | * Texte coupé |
| 365 | 365 | **/ |
| 366 | 366 | function couper($texte, $taille = 50, $suite = null) { |
| 367 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 368 | - return ''; |
|
| 369 | - } |
|
| 370 | - $offset = 400 + 2 * $taille; |
|
| 371 | - while ( |
|
| 372 | - $offset < $length |
|
| 373 | - and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 374 | - ) { |
|
| 375 | - $offset = 2 * $offset; |
|
| 376 | - } |
|
| 377 | - if ( |
|
| 378 | - $offset < $length |
|
| 379 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 380 | - ) { |
|
| 381 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 382 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 383 | - $offset = $p_tag_fermant + 1; |
|
| 384 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 385 | - } |
|
| 386 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 387 | - |
|
| 388 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 389 | - include_spip('inc/lien'); |
|
| 390 | - } |
|
| 391 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 392 | - |
|
| 393 | - // balises de sauts de ligne et paragraphe |
|
| 394 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 395 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 396 | - |
|
| 397 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 398 | - $texte = str_replace("\n\n", "\r", $texte); |
|
| 399 | - |
|
| 400 | - // supprimer les tags |
|
| 401 | - $texte = supprimer_tags($texte); |
|
| 402 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 403 | - $texte .= "\n"; // marquer la fin |
|
| 404 | - |
|
| 405 | - // corriger la longueur de coupe |
|
| 406 | - // en fonction de la presence de caracteres utf |
|
| 407 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 408 | - $long = charset2unicode($texte); |
|
| 409 | - $long = spip_substr($long, 0, max($taille, 1)); |
|
| 410 | - $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 411 | - $taille += $nbcharutf; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - // couper au mot precedent |
|
| 416 | - $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 417 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 418 | - $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 419 | - if (is_null($suite)) { |
|
| 420 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 421 | - } |
|
| 422 | - $points = $suite; |
|
| 423 | - |
|
| 424 | - // trop court ? ne pas faire de (...) |
|
| 425 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 426 | - $points = ''; |
|
| 427 | - $long = spip_substr($texte, 0, $taille); |
|
| 428 | - $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 429 | - // encore trop court ? couper au caractere |
|
| 430 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 431 | - $texte = $long; |
|
| 432 | - } |
|
| 433 | - } else { |
|
| 434 | - $texte = $court; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 438 | - $points = ''; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - // remettre les paragraphes |
|
| 442 | - $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 443 | - |
|
| 444 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 445 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 446 | - |
|
| 447 | - return quote_amp(trim($texte)) . $points; |
|
| 367 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 368 | + return ''; |
|
| 369 | + } |
|
| 370 | + $offset = 400 + 2 * $taille; |
|
| 371 | + while ( |
|
| 372 | + $offset < $length |
|
| 373 | + and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 374 | + ) { |
|
| 375 | + $offset = 2 * $offset; |
|
| 376 | + } |
|
| 377 | + if ( |
|
| 378 | + $offset < $length |
|
| 379 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 380 | + ) { |
|
| 381 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 382 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 383 | + $offset = $p_tag_fermant + 1; |
|
| 384 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 385 | + } |
|
| 386 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 387 | + |
|
| 388 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 389 | + include_spip('inc/lien'); |
|
| 390 | + } |
|
| 391 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 392 | + |
|
| 393 | + // balises de sauts de ligne et paragraphe |
|
| 394 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r", $texte); |
|
| 395 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 396 | + |
|
| 397 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 398 | + $texte = str_replace("\n\n", "\r", $texte); |
|
| 399 | + |
|
| 400 | + // supprimer les tags |
|
| 401 | + $texte = supprimer_tags($texte); |
|
| 402 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 403 | + $texte .= "\n"; // marquer la fin |
|
| 404 | + |
|
| 405 | + // corriger la longueur de coupe |
|
| 406 | + // en fonction de la presence de caracteres utf |
|
| 407 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 408 | + $long = charset2unicode($texte); |
|
| 409 | + $long = spip_substr($long, 0, max($taille, 1)); |
|
| 410 | + $nbcharutf = preg_match_all('/(&#[0-9]{3,6};)/S', $long, $matches); |
|
| 411 | + $taille += $nbcharutf; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + // couper au mot precedent |
|
| 416 | + $long = spip_substr($texte, 0, max($taille - 4, 1)); |
|
| 417 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 418 | + $court = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 419 | + if (is_null($suite)) { |
|
| 420 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 421 | + } |
|
| 422 | + $points = $suite; |
|
| 423 | + |
|
| 424 | + // trop court ? ne pas faire de (...) |
|
| 425 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 426 | + $points = ''; |
|
| 427 | + $long = spip_substr($texte, 0, $taille); |
|
| 428 | + $texte = preg_replace("/([^\s][\s]+)[^\s]*\n?$/" . $u, "\\1", $long); |
|
| 429 | + // encore trop court ? couper au caractere |
|
| 430 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 431 | + $texte = $long; |
|
| 432 | + } |
|
| 433 | + } else { |
|
| 434 | + $texte = $court; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite |
|
| 438 | + $points = ''; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + // remettre les paragraphes |
|
| 442 | + $texte = preg_replace("/\r+/", "\n\n", $texte); |
|
| 443 | + |
|
| 444 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 445 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 446 | + |
|
| 447 | + return quote_amp(trim($texte)) . $points; |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | |
| 451 | 451 | // https://code.spip.net/@protege_js_modeles |
| 452 | 452 | function protege_js_modeles($t) { |
| 453 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 454 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 455 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 456 | - include_spip('inc/acces'); |
|
| 457 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 458 | - } |
|
| 459 | - foreach ($r as $regs) { |
|
| 460 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 464 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 465 | - include_spip('inc/acces'); |
|
| 466 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 467 | - } |
|
| 468 | - foreach ($r as $regs) { |
|
| 469 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - return $t; |
|
| 453 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 454 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 455 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 456 | + include_spip('inc/acces'); |
|
| 457 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 458 | + } |
|
| 459 | + foreach ($r as $regs) { |
|
| 460 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 464 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 465 | + include_spip('inc/acces'); |
|
| 466 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 467 | + } |
|
| 468 | + foreach ($r as $regs) { |
|
| 469 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + return $t; |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | |
| 478 | 478 | function echapper_faux_tags($letexte) { |
| 479 | - if (strpos($letexte, '<') === false) { |
|
| 480 | - return $letexte; |
|
| 481 | - } |
|
| 482 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 483 | - |
|
| 484 | - $letexte = ''; |
|
| 485 | - while (count($textMatches)) { |
|
| 486 | - // un texte a echapper |
|
| 487 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 488 | - // un tag html qui a servit a faite le split |
|
| 489 | - $letexte .= array_shift($textMatches); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - return $letexte; |
|
| 479 | + if (strpos($letexte, '<') === false) { |
|
| 480 | + return $letexte; |
|
| 481 | + } |
|
| 482 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 483 | + |
|
| 484 | + $letexte = ''; |
|
| 485 | + while (count($textMatches)) { |
|
| 486 | + // un texte a echapper |
|
| 487 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 488 | + // un tag html qui a servit a faite le split |
|
| 489 | + $letexte .= array_shift($textMatches); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + return $letexte; |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -502,47 +502,47 @@ discard block |
||
| 502 | 502 | * @return string |
| 503 | 503 | */ |
| 504 | 504 | function echapper_html_suspect($texte, $strict = true) { |
| 505 | - static $echapper_html_suspect; |
|
| 506 | - if (!$texte or !is_string($texte)) { |
|
| 507 | - return $texte; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - if (!isset($echapper_html_suspect)) { |
|
| 511 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 512 | - } |
|
| 513 | - // si fonction personalisee, on delegue |
|
| 514 | - if ($echapper_html_suspect) { |
|
| 515 | - return $echapper_html_suspect($texte, $strict); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - if ( |
|
| 519 | - strpos($texte, '<') === false |
|
| 520 | - or strpos($texte, '=') === false |
|
| 521 | - ) { |
|
| 522 | - return $texte; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 526 | - // car sinon on declenche sur les modeles ou ressources |
|
| 527 | - if ( |
|
| 528 | - !$strict and |
|
| 529 | - (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 530 | - ) { |
|
| 531 | - return $texte; |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 535 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 536 | - // donc un test d'egalite est trop strict |
|
| 537 | - if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 538 | - $texte = str_replace('<', '<', $texte); |
|
| 539 | - if (!function_exists('attribut_html')) { |
|
| 540 | - include_spip('inc/filtres'); |
|
| 541 | - } |
|
| 542 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - return $texte; |
|
| 505 | + static $echapper_html_suspect; |
|
| 506 | + if (!$texte or !is_string($texte)) { |
|
| 507 | + return $texte; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + if (!isset($echapper_html_suspect)) { |
|
| 511 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 512 | + } |
|
| 513 | + // si fonction personalisee, on delegue |
|
| 514 | + if ($echapper_html_suspect) { |
|
| 515 | + return $echapper_html_suspect($texte, $strict); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + if ( |
|
| 519 | + strpos($texte, '<') === false |
|
| 520 | + or strpos($texte, '=') === false |
|
| 521 | + ) { |
|
| 522 | + return $texte; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 526 | + // car sinon on declenche sur les modeles ou ressources |
|
| 527 | + if ( |
|
| 528 | + !$strict and |
|
| 529 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 530 | + ) { |
|
| 531 | + return $texte; |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 535 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 536 | + // donc un test d'egalite est trop strict |
|
| 537 | + if (strlen(safehtml($texte)) !== strlen($texte)) { |
|
| 538 | + $texte = str_replace('<', '<', $texte); |
|
| 539 | + if (!function_exists('attribut_html')) { |
|
| 540 | + include_spip('inc/filtres'); |
|
| 541 | + } |
|
| 542 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + return $texte; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | |
@@ -563,30 +563,30 @@ discard block |
||
| 563 | 563 | * Texte sécurisé |
| 564 | 564 | **/ |
| 565 | 565 | function safehtml($t) { |
| 566 | - static $safehtml; |
|
| 567 | - |
|
| 568 | - if (!$t or !is_string($t)) { |
|
| 569 | - return $t; |
|
| 570 | - } |
|
| 571 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 572 | - if (strpos($t, '<') === false) { |
|
| 573 | - return str_replace("\x00", '', $t); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - if (!function_exists('interdire_scripts')) { |
|
| 577 | - include_spip('inc/texte'); |
|
| 578 | - } |
|
| 579 | - $t = interdire_scripts($t); // jolifier le php |
|
| 580 | - $t = echappe_js($t); |
|
| 581 | - |
|
| 582 | - if (!isset($safehtml)) { |
|
| 583 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 584 | - } |
|
| 585 | - if ($safehtml) { |
|
| 586 | - $t = $safehtml($t); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 566 | + static $safehtml; |
|
| 567 | + |
|
| 568 | + if (!$t or !is_string($t)) { |
|
| 569 | + return $t; |
|
| 570 | + } |
|
| 571 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 572 | + if (strpos($t, '<') === false) { |
|
| 573 | + return str_replace("\x00", '', $t); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + if (!function_exists('interdire_scripts')) { |
|
| 577 | + include_spip('inc/texte'); |
|
| 578 | + } |
|
| 579 | + $t = interdire_scripts($t); // jolifier le php |
|
| 580 | + $t = echappe_js($t); |
|
| 581 | + |
|
| 582 | + if (!isset($safehtml)) { |
|
| 583 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 584 | + } |
|
| 585 | + if ($safehtml) { |
|
| 586 | + $t = $safehtml($t); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | |
@@ -608,13 +608,13 @@ discard block |
||
| 608 | 608 | * Texte sans les modèles d'image |
| 609 | 609 | **/ |
| 610 | 610 | function supprime_img($letexte, $message = null) { |
| 611 | - if ($message === null) { |
|
| 612 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - return preg_replace( |
|
| 616 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 617 | - $message, |
|
| 618 | - $letexte |
|
| 619 | - ); |
|
| 611 | + if ($message === null) { |
|
| 612 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + return preg_replace( |
|
| 616 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 617 | + $message, |
|
| 618 | + $letexte |
|
| 619 | + ); |
|
| 620 | 620 | } |
@@ -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 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | 30 | function inc_config_dist() { |
| 31 | - actualise_metas(liste_metas()); |
|
| 31 | + actualise_metas(liste_metas()); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -45,34 +45,34 @@ discard block |
||
| 45 | 45 | * Liste (table, casier, sous_casier) |
| 46 | 46 | */ |
| 47 | 47 | function expliquer_config($cfg) { |
| 48 | - // par defaut, sur la table des meta |
|
| 49 | - $table = 'meta'; |
|
| 50 | - $casier = null; |
|
| 51 | - $sous_casier = []; |
|
| 52 | - $cfg = explode('/', $cfg); |
|
| 53 | - |
|
| 54 | - // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | - if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | - array_shift($cfg); |
|
| 57 | - $table = array_shift($cfg); |
|
| 58 | - if (!isset($GLOBALS[$table])) { |
|
| 59 | - lire_metas($table); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | - if (count($cfg)) { |
|
| 65 | - // pas sur un appel vide '' |
|
| 66 | - if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | - $casier = $c; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (count($cfg)) { |
|
| 72 | - $sous_casier = $cfg; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return [$table, $casier, $sous_casier]; |
|
| 48 | + // par defaut, sur la table des meta |
|
| 49 | + $table = 'meta'; |
|
| 50 | + $casier = null; |
|
| 51 | + $sous_casier = []; |
|
| 52 | + $cfg = explode('/', $cfg); |
|
| 53 | + |
|
| 54 | + // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | + if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | + array_shift($cfg); |
|
| 57 | + $table = array_shift($cfg); |
|
| 58 | + if (!isset($GLOBALS[$table])) { |
|
| 59 | + lire_metas($table); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | + if (count($cfg)) { |
|
| 65 | + // pas sur un appel vide '' |
|
| 66 | + if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | + $casier = $c; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (count($cfg)) { |
|
| 72 | + $sous_casier = $cfg; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return [$table, $casier, $sous_casier]; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -100,65 +100,65 @@ discard block |
||
| 100 | 100 | * Contenu de la configuration obtenue |
| 101 | 101 | */ |
| 102 | 102 | function lire_config($cfg = '', $def = null, $unserialize = true) { |
| 103 | - // lire le stockage sous la forme /table/valeur |
|
| 104 | - // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | - // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | - |
|
| 107 | - // traiter en priorite le cas simple et frequent |
|
| 108 | - // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | - if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | - $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | - ((!$unserialize |
|
| 112 | - // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | - or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | - // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | - or strpos($GLOBALS['meta'][$cfg], ':') === false |
|
| 116 | - or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | - : $def; |
|
| 118 | - |
|
| 119 | - return $r; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Brancher sur methodes externes si besoin |
|
| 123 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | - $methode = substr($cfg, 0, $p); |
|
| 125 | - $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | - |
|
| 127 | - return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - list($table, $casier, $sous_casier) = expliquer_config($cfg); |
|
| 131 | - |
|
| 132 | - if (!isset($GLOBALS[$table])) { |
|
| 133 | - return $def; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $r = $GLOBALS[$table]; |
|
| 137 | - |
|
| 138 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | - if (!$casier) { |
|
| 140 | - return $unserialize ? $r : serialize($r); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // casier principal : |
|
| 144 | - // le deserializer si demande |
|
| 145 | - // ou si on a besoin |
|
| 146 | - // d'un sous casier |
|
| 147 | - $r = $r[$casier] ?? null; |
|
| 148 | - if (($unserialize or count($sous_casier)) and $r and is_string($r)) { |
|
| 149 | - $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // aller chercher le sous_casier |
|
| 153 | - while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | - $r = $r[$casier] ?? null; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($r)) { |
|
| 158 | - return $def; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $r; |
|
| 103 | + // lire le stockage sous la forme /table/valeur |
|
| 104 | + // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | + // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | + |
|
| 107 | + // traiter en priorite le cas simple et frequent |
|
| 108 | + // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | + if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | + $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | + ((!$unserialize |
|
| 112 | + // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | + or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | + // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | + or strpos($GLOBALS['meta'][$cfg], ':') === false |
|
| 116 | + or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | + : $def; |
|
| 118 | + |
|
| 119 | + return $r; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Brancher sur methodes externes si besoin |
|
| 123 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | + $methode = substr($cfg, 0, $p); |
|
| 125 | + $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | + |
|
| 127 | + return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + list($table, $casier, $sous_casier) = expliquer_config($cfg); |
|
| 131 | + |
|
| 132 | + if (!isset($GLOBALS[$table])) { |
|
| 133 | + return $def; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $r = $GLOBALS[$table]; |
|
| 137 | + |
|
| 138 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | + if (!$casier) { |
|
| 140 | + return $unserialize ? $r : serialize($r); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // casier principal : |
|
| 144 | + // le deserializer si demande |
|
| 145 | + // ou si on a besoin |
|
| 146 | + // d'un sous casier |
|
| 147 | + $r = $r[$casier] ?? null; |
|
| 148 | + if (($unserialize or count($sous_casier)) and $r and is_string($r)) { |
|
| 149 | + $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // aller chercher le sous_casier |
|
| 153 | + while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | + $r = $r[$casier] ?? null; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($r)) { |
|
| 158 | + return $def; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $r; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return mixed |
| 173 | 173 | */ |
| 174 | 174 | function lire_config_metapack_dist($cfg = '', $def = null, $unserialize = true) { |
| 175 | - return lire_config($cfg, $def, $unserialize); |
|
| 175 | + return lire_config($cfg, $def, $unserialize); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -184,98 +184,98 @@ discard block |
||
| 184 | 184 | * @return bool |
| 185 | 185 | */ |
| 186 | 186 | function ecrire_config($cfg, $store) { |
| 187 | - // Brancher sur methodes externes si besoin |
|
| 188 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | - $methode = substr($cfg, 0, $p); |
|
| 190 | - $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | - |
|
| 192 | - return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - list($table, $casier, $sous_casier) = expliquer_config($cfg); |
|
| 196 | - // il faut au moins un casier pour ecrire |
|
| 197 | - if (!$casier) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // trouvons ou creons le pointeur sur le casier |
|
| 202 | - $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | - if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | - $st = unserialize($st); |
|
| 205 | - if ($st === false) { |
|
| 206 | - // ne rien creer si c'est une demande d'effacement |
|
| 207 | - if (is_null($store)) { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - $st = []; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // si on a affaire a un sous caiser |
|
| 215 | - // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 216 | - if ($c = $sous_casier) { |
|
| 217 | - $sc = &$st; |
|
| 218 | - $pointeurs = []; |
|
| 219 | - while (count($c) and $cc = array_shift($c)) { |
|
| 220 | - // creer l'entree si elle n'existe pas |
|
| 221 | - if (!isset($sc[$cc])) { |
|
| 222 | - // si on essaye d'effacer une config qui n'existe pas |
|
| 223 | - // ne rien creer mais sortir |
|
| 224 | - if (is_null($store)) { |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - $sc[$cc] = []; |
|
| 228 | - } |
|
| 229 | - $pointeurs[$cc] = &$sc; |
|
| 230 | - $sc = &$sc[$cc]; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // si c'est une demande d'effacement |
|
| 234 | - if (is_null($store)) { |
|
| 235 | - $c = $sous_casier; |
|
| 236 | - $sous = array_pop($c); |
|
| 237 | - // effacer, et remonter pour effacer les parents vides |
|
| 238 | - do { |
|
| 239 | - unset($pointeurs[$sous][$sous]); |
|
| 240 | - } while ($sous = array_pop($c) and !count($pointeurs[$sous][$sous])); |
|
| 241 | - |
|
| 242 | - // si on a vide tous les sous casiers, |
|
| 243 | - // et que le casier est vide |
|
| 244 | - // vider aussi la meta |
|
| 245 | - if (!$sous and !count($st)) { |
|
| 246 | - $st = null; |
|
| 247 | - } |
|
| 248 | - } // dans tous les autres cas, on ecrase |
|
| 249 | - else { |
|
| 250 | - $sc = $store; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - // Maintenant que $st est modifiee |
|
| 254 | - // reprenons la comme valeur a stocker dans le casier principal |
|
| 255 | - $store = $st; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - if (is_null($store)) { |
|
| 259 | - if (is_null($st) and !$sous_casier) { |
|
| 260 | - return false; |
|
| 261 | - } // la config n'existait deja pas ! |
|
| 262 | - effacer_meta($casier, $table); |
|
| 263 | - supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 264 | - } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 265 | - else { |
|
| 266 | - if (!isset($GLOBALS[$table])) { |
|
| 267 | - installer_table_meta($table); |
|
| 268 | - } |
|
| 269 | - // si ce n'est pas une chaine |
|
| 270 | - // il faut serializer |
|
| 271 | - if (!is_string($store)) { |
|
| 272 | - $store = serialize($store); |
|
| 273 | - } |
|
| 274 | - ecrire_meta($casier, $store, null, $table); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // verifier que lire_config($cfg)==$store ? |
|
| 278 | - return true; |
|
| 187 | + // Brancher sur methodes externes si besoin |
|
| 188 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | + $methode = substr($cfg, 0, $p); |
|
| 190 | + $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | + |
|
| 192 | + return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + list($table, $casier, $sous_casier) = expliquer_config($cfg); |
|
| 196 | + // il faut au moins un casier pour ecrire |
|
| 197 | + if (!$casier) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // trouvons ou creons le pointeur sur le casier |
|
| 202 | + $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | + if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | + $st = unserialize($st); |
|
| 205 | + if ($st === false) { |
|
| 206 | + // ne rien creer si c'est une demande d'effacement |
|
| 207 | + if (is_null($store)) { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + $st = []; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // si on a affaire a un sous caiser |
|
| 215 | + // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 216 | + if ($c = $sous_casier) { |
|
| 217 | + $sc = &$st; |
|
| 218 | + $pointeurs = []; |
|
| 219 | + while (count($c) and $cc = array_shift($c)) { |
|
| 220 | + // creer l'entree si elle n'existe pas |
|
| 221 | + if (!isset($sc[$cc])) { |
|
| 222 | + // si on essaye d'effacer une config qui n'existe pas |
|
| 223 | + // ne rien creer mais sortir |
|
| 224 | + if (is_null($store)) { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + $sc[$cc] = []; |
|
| 228 | + } |
|
| 229 | + $pointeurs[$cc] = &$sc; |
|
| 230 | + $sc = &$sc[$cc]; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // si c'est une demande d'effacement |
|
| 234 | + if (is_null($store)) { |
|
| 235 | + $c = $sous_casier; |
|
| 236 | + $sous = array_pop($c); |
|
| 237 | + // effacer, et remonter pour effacer les parents vides |
|
| 238 | + do { |
|
| 239 | + unset($pointeurs[$sous][$sous]); |
|
| 240 | + } while ($sous = array_pop($c) and !count($pointeurs[$sous][$sous])); |
|
| 241 | + |
|
| 242 | + // si on a vide tous les sous casiers, |
|
| 243 | + // et que le casier est vide |
|
| 244 | + // vider aussi la meta |
|
| 245 | + if (!$sous and !count($st)) { |
|
| 246 | + $st = null; |
|
| 247 | + } |
|
| 248 | + } // dans tous les autres cas, on ecrase |
|
| 249 | + else { |
|
| 250 | + $sc = $store; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + // Maintenant que $st est modifiee |
|
| 254 | + // reprenons la comme valeur a stocker dans le casier principal |
|
| 255 | + $store = $st; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + if (is_null($store)) { |
|
| 259 | + if (is_null($st) and !$sous_casier) { |
|
| 260 | + return false; |
|
| 261 | + } // la config n'existait deja pas ! |
|
| 262 | + effacer_meta($casier, $table); |
|
| 263 | + supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 264 | + } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 265 | + else { |
|
| 266 | + if (!isset($GLOBALS[$table])) { |
|
| 267 | + installer_table_meta($table); |
|
| 268 | + } |
|
| 269 | + // si ce n'est pas une chaine |
|
| 270 | + // il faut serializer |
|
| 271 | + if (!is_string($store)) { |
|
| 272 | + $store = serialize($store); |
|
| 273 | + } |
|
| 274 | + ecrire_meta($casier, $store, null, $table); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // verifier que lire_config($cfg)==$store ? |
|
| 278 | + return true; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | * @return bool |
| 290 | 290 | */ |
| 291 | 291 | function ecrire_config_metapack_dist($cfg, $store) { |
| 292 | - // cas particulier en metapack:: |
|
| 293 | - // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 294 | - // intacte en sortie ... |
|
| 295 | - if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 296 | - $store = serialize($store); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - return ecrire_config($cfg, $store); |
|
| 292 | + // cas particulier en metapack:: |
|
| 293 | + // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 294 | + // intacte en sortie ... |
|
| 295 | + if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 296 | + $store = serialize($store); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + return ecrire_config($cfg, $store); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -306,9 +306,9 @@ discard block |
||
| 306 | 306 | * @return bool |
| 307 | 307 | */ |
| 308 | 308 | function effacer_config($cfg) { |
| 309 | - ecrire_config($cfg, null); |
|
| 309 | + ecrire_config($cfg, null); |
|
| 310 | 310 | |
| 311 | - return true; |
|
| 311 | + return true; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -325,71 +325,71 @@ discard block |
||
| 325 | 325 | * @return array |
| 326 | 326 | */ |
| 327 | 327 | function lister_configurer($exclure = []) { |
| 328 | - return []; |
|
| 329 | - |
|
| 330 | - // lister les pages de config deja dans les menus |
|
| 331 | - $deja = []; |
|
| 332 | - foreach ($exclure as $id => $b) { |
|
| 333 | - $url = ($b['url'] ? $b['url'] : $id); |
|
| 334 | - if (!$b['url'] or !isset($exclure[$url])) { |
|
| 335 | - if (strncmp($url, 'configurer_', 11) == 0) { |
|
| 336 | - $deja[$url] = $b; |
|
| 337 | - } elseif ($b['url'] == 'configurer' and preg_match(',cfg=([a-z0-9_]+),i', $b['args'], $match)) { |
|
| 338 | - $deja['configurer_' . $match[1]] = $b; |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - $exclure = $exclure + $deja; |
|
| 343 | - |
|
| 344 | - $icone_defaut = 'images/configuration-16.png'; |
|
| 345 | - $liste = []; |
|
| 346 | - $skels = []; |
|
| 347 | - $forms = []; |
|
| 348 | - |
|
| 349 | - // trouver toutes les pages configurer_xxx de l'espace prive |
|
| 350 | - // et construire un tableau des entrees qui ne sont pas dans $deja |
|
| 351 | - $pages = find_all_in_path('prive/squelettes/contenu/', 'configurer_.*[.]' . _EXTENSION_SQUELETTES . '$'); |
|
| 352 | - |
|
| 353 | - foreach ($pages as $page) { |
|
| 354 | - $configurer = basename($page, '.' . _EXTENSION_SQUELETTES); |
|
| 355 | - if (!isset($exclure[$configurer])) { |
|
| 356 | - $liste[$configurer] = [ |
|
| 357 | - 'parent' => 'bando_configuration', |
|
| 358 | - 'url' => $configurer, |
|
| 359 | - 'titre' => _T("configurer:{$configurer}_titre"), |
|
| 360 | - 'icone' => find_in_theme($i = "images/{$configurer}-16.png") ? $i : $icone_defaut, |
|
| 361 | - ]; |
|
| 362 | - } |
|
| 363 | - $skels[$configurer] = $page; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // analyser la liste des $skels pour voir les #FORMULAIRE_CONFIGURER_ inclus |
|
| 367 | - foreach ($skels as $file) { |
|
| 368 | - $forms = array_merge($forms, lister_formulaires_configurer($file)); |
|
| 369 | - } |
|
| 370 | - $forms = array_flip($forms); |
|
| 371 | - |
|
| 372 | - // trouver tous les formulaires/configurer_ |
|
| 373 | - // et construire un tableau des entrees |
|
| 374 | - $pages = find_all_in_path('formulaires/', 'configurer_.*[.]' . _EXTENSION_SQUELETTES . '$'); |
|
| 375 | - foreach ($pages as $page) { |
|
| 376 | - $configurer = basename($page, '.' . _EXTENSION_SQUELETTES); |
|
| 377 | - if ( |
|
| 378 | - !isset($forms[$configurer]) |
|
| 379 | - and !isset($liste[$configurer]) |
|
| 380 | - and !isset($exclure[$configurer]) |
|
| 381 | - ) { |
|
| 382 | - $liste[$configurer] = [ |
|
| 383 | - 'parent' => 'bando_configuration', |
|
| 384 | - 'url' => 'configurer', |
|
| 385 | - 'args' => 'cfg=' . substr($configurer, 11), |
|
| 386 | - 'titre' => _T("configurer:{$configurer}_titre"), |
|
| 387 | - 'icone' => find_in_theme($i = "images/{$configurer}-16.png") ? $i : $icone_defaut, |
|
| 388 | - ]; |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $liste; |
|
| 328 | + return []; |
|
| 329 | + |
|
| 330 | + // lister les pages de config deja dans les menus |
|
| 331 | + $deja = []; |
|
| 332 | + foreach ($exclure as $id => $b) { |
|
| 333 | + $url = ($b['url'] ? $b['url'] : $id); |
|
| 334 | + if (!$b['url'] or !isset($exclure[$url])) { |
|
| 335 | + if (strncmp($url, 'configurer_', 11) == 0) { |
|
| 336 | + $deja[$url] = $b; |
|
| 337 | + } elseif ($b['url'] == 'configurer' and preg_match(',cfg=([a-z0-9_]+),i', $b['args'], $match)) { |
|
| 338 | + $deja['configurer_' . $match[1]] = $b; |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + $exclure = $exclure + $deja; |
|
| 343 | + |
|
| 344 | + $icone_defaut = 'images/configuration-16.png'; |
|
| 345 | + $liste = []; |
|
| 346 | + $skels = []; |
|
| 347 | + $forms = []; |
|
| 348 | + |
|
| 349 | + // trouver toutes les pages configurer_xxx de l'espace prive |
|
| 350 | + // et construire un tableau des entrees qui ne sont pas dans $deja |
|
| 351 | + $pages = find_all_in_path('prive/squelettes/contenu/', 'configurer_.*[.]' . _EXTENSION_SQUELETTES . '$'); |
|
| 352 | + |
|
| 353 | + foreach ($pages as $page) { |
|
| 354 | + $configurer = basename($page, '.' . _EXTENSION_SQUELETTES); |
|
| 355 | + if (!isset($exclure[$configurer])) { |
|
| 356 | + $liste[$configurer] = [ |
|
| 357 | + 'parent' => 'bando_configuration', |
|
| 358 | + 'url' => $configurer, |
|
| 359 | + 'titre' => _T("configurer:{$configurer}_titre"), |
|
| 360 | + 'icone' => find_in_theme($i = "images/{$configurer}-16.png") ? $i : $icone_defaut, |
|
| 361 | + ]; |
|
| 362 | + } |
|
| 363 | + $skels[$configurer] = $page; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // analyser la liste des $skels pour voir les #FORMULAIRE_CONFIGURER_ inclus |
|
| 367 | + foreach ($skels as $file) { |
|
| 368 | + $forms = array_merge($forms, lister_formulaires_configurer($file)); |
|
| 369 | + } |
|
| 370 | + $forms = array_flip($forms); |
|
| 371 | + |
|
| 372 | + // trouver tous les formulaires/configurer_ |
|
| 373 | + // et construire un tableau des entrees |
|
| 374 | + $pages = find_all_in_path('formulaires/', 'configurer_.*[.]' . _EXTENSION_SQUELETTES . '$'); |
|
| 375 | + foreach ($pages as $page) { |
|
| 376 | + $configurer = basename($page, '.' . _EXTENSION_SQUELETTES); |
|
| 377 | + if ( |
|
| 378 | + !isset($forms[$configurer]) |
|
| 379 | + and !isset($liste[$configurer]) |
|
| 380 | + and !isset($exclure[$configurer]) |
|
| 381 | + ) { |
|
| 382 | + $liste[$configurer] = [ |
|
| 383 | + 'parent' => 'bando_configuration', |
|
| 384 | + 'url' => 'configurer', |
|
| 385 | + 'args' => 'cfg=' . substr($configurer, 11), |
|
| 386 | + 'titre' => _T("configurer:{$configurer}_titre"), |
|
| 387 | + 'icone' => find_in_theme($i = "images/{$configurer}-16.png") ? $i : $icone_defaut, |
|
| 388 | + ]; |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $liste; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -403,35 +403,35 @@ discard block |
||
| 403 | 403 | * Liste des formulaires trouvés |
| 404 | 404 | **/ |
| 405 | 405 | function lister_formulaires_configurer($file) { |
| 406 | - $forms = []; |
|
| 407 | - |
|
| 408 | - lire_fichier($file, $skel); |
|
| 409 | - if (preg_match_all(',#FORMULAIRE_(CONFIGURER_[A-Z0-9_]*),', $skel, $matches, PREG_SET_ORDER)) { |
|
| 410 | - $matches = array_map('end', $matches); |
|
| 411 | - $matches = array_map('strtolower', $matches); |
|
| 412 | - $forms = array_merge($forms, $matches); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - // evaluer le fond en lui passant un exec coherent pour que les pipelines le reconnaissent |
|
| 416 | - // et reperer les formulaires CVT configurer_xx insereres par les plugins via pipeline |
|
| 417 | - $config = basename(substr($file, 0, -strlen('.' . _EXTENSION_SQUELETTES))); |
|
| 418 | - spip_log('Calcul de ' . "prive/squelettes/contenu/$config"); |
|
| 419 | - $fond = recuperer_fond("prive/squelettes/contenu/$config", ['exec' => $config]); |
|
| 420 | - |
|
| 421 | - // passer dans le pipeline affiche_milieu pour que les plugins puissent ajouter leur formulaires... |
|
| 422 | - // et donc que l'on puisse les referencer aussi ! |
|
| 423 | - $fond = pipeline('affiche_milieu', ['args' => ['exec' => $config], 'data' => $fond]); |
|
| 424 | - |
|
| 425 | - // recuperer les noms des formulaires presents. |
|
| 426 | - if (is_array($inputs = extraire_balises($fond, 'input'))) { |
|
| 427 | - foreach ($inputs as $i) { |
|
| 428 | - if (extraire_attribut($i, 'name') == 'formulaire_action') { |
|
| 429 | - $forms[] = ($c = extraire_attribut($i, 'value')); |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return $forms; |
|
| 406 | + $forms = []; |
|
| 407 | + |
|
| 408 | + lire_fichier($file, $skel); |
|
| 409 | + if (preg_match_all(',#FORMULAIRE_(CONFIGURER_[A-Z0-9_]*),', $skel, $matches, PREG_SET_ORDER)) { |
|
| 410 | + $matches = array_map('end', $matches); |
|
| 411 | + $matches = array_map('strtolower', $matches); |
|
| 412 | + $forms = array_merge($forms, $matches); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + // evaluer le fond en lui passant un exec coherent pour que les pipelines le reconnaissent |
|
| 416 | + // et reperer les formulaires CVT configurer_xx insereres par les plugins via pipeline |
|
| 417 | + $config = basename(substr($file, 0, -strlen('.' . _EXTENSION_SQUELETTES))); |
|
| 418 | + spip_log('Calcul de ' . "prive/squelettes/contenu/$config"); |
|
| 419 | + $fond = recuperer_fond("prive/squelettes/contenu/$config", ['exec' => $config]); |
|
| 420 | + |
|
| 421 | + // passer dans le pipeline affiche_milieu pour que les plugins puissent ajouter leur formulaires... |
|
| 422 | + // et donc que l'on puisse les referencer aussi ! |
|
| 423 | + $fond = pipeline('affiche_milieu', ['args' => ['exec' => $config], 'data' => $fond]); |
|
| 424 | + |
|
| 425 | + // recuperer les noms des formulaires presents. |
|
| 426 | + if (is_array($inputs = extraire_balises($fond, 'input'))) { |
|
| 427 | + foreach ($inputs as $i) { |
|
| 428 | + if (extraire_attribut($i, 'name') == 'formulaire_action') { |
|
| 429 | + $forms[] = ($c = extraire_attribut($i, 'value')); |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return $forms; |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | |
@@ -449,58 +449,58 @@ discard block |
||
| 449 | 449 | * Couples nom de la `meta` => valeur par défaut |
| 450 | 450 | */ |
| 451 | 451 | function liste_metas() { |
| 452 | - return pipeline('configurer_liste_metas', [ |
|
| 453 | - 'nom_site' => _T('info_mon_site_spip'), |
|
| 454 | - 'slogan_site' => '', |
|
| 455 | - 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 456 | - 'descriptif_site' => '', |
|
| 457 | - 'activer_logos' => 'oui', |
|
| 458 | - 'activer_logos_survol' => 'non', |
|
| 459 | - 'articles_surtitre' => 'non', |
|
| 460 | - 'articles_soustitre' => 'non', |
|
| 461 | - 'articles_descriptif' => 'non', |
|
| 462 | - 'articles_chapeau' => 'non', |
|
| 463 | - 'articles_texte' => 'oui', |
|
| 464 | - 'articles_ps' => 'non', |
|
| 465 | - 'articles_redac' => 'non', |
|
| 466 | - 'post_dates' => 'non', |
|
| 467 | - 'articles_urlref' => 'non', |
|
| 468 | - 'articles_redirection' => 'non', |
|
| 469 | - 'creer_preview' => 'non', |
|
| 470 | - 'taille_preview' => 150, |
|
| 471 | - 'articles_modif' => 'non', |
|
| 472 | - |
|
| 473 | - 'rubriques_descriptif' => 'non', |
|
| 474 | - 'rubriques_texte' => 'oui', |
|
| 475 | - |
|
| 476 | - 'accepter_inscriptions' => 'non', |
|
| 477 | - 'accepter_visiteurs' => 'non', |
|
| 478 | - 'prevenir_auteurs' => 'non', |
|
| 479 | - 'suivi_edito' => 'non', |
|
| 480 | - 'adresse_suivi' => '', |
|
| 481 | - 'adresse_suivi_inscription' => '', |
|
| 482 | - 'adresse_neuf' => '', |
|
| 483 | - 'jours_neuf' => '', |
|
| 484 | - 'quoi_de_neuf' => 'non', |
|
| 485 | - 'preview' => ',0minirezo,1comite,', |
|
| 486 | - |
|
| 487 | - 'syndication_integrale' => 'oui', |
|
| 488 | - 'charset' => _DEFAULT_CHARSET, |
|
| 489 | - 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 490 | - |
|
| 491 | - 'multi_rubriques' => 'non', |
|
| 492 | - 'multi_secteurs' => 'non', |
|
| 493 | - 'gerer_trad' => 'non', |
|
| 494 | - 'langues_multilingue' => '', |
|
| 495 | - |
|
| 496 | - 'version_html_max' => 'html4', |
|
| 497 | - |
|
| 498 | - 'type_urls' => 'page', |
|
| 499 | - |
|
| 500 | - 'email_envoi' => '', |
|
| 501 | - 'email_webmaster' => '', |
|
| 502 | - 'auto_compress_http' => 'non', |
|
| 503 | - ]); |
|
| 452 | + return pipeline('configurer_liste_metas', [ |
|
| 453 | + 'nom_site' => _T('info_mon_site_spip'), |
|
| 454 | + 'slogan_site' => '', |
|
| 455 | + 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 456 | + 'descriptif_site' => '', |
|
| 457 | + 'activer_logos' => 'oui', |
|
| 458 | + 'activer_logos_survol' => 'non', |
|
| 459 | + 'articles_surtitre' => 'non', |
|
| 460 | + 'articles_soustitre' => 'non', |
|
| 461 | + 'articles_descriptif' => 'non', |
|
| 462 | + 'articles_chapeau' => 'non', |
|
| 463 | + 'articles_texte' => 'oui', |
|
| 464 | + 'articles_ps' => 'non', |
|
| 465 | + 'articles_redac' => 'non', |
|
| 466 | + 'post_dates' => 'non', |
|
| 467 | + 'articles_urlref' => 'non', |
|
| 468 | + 'articles_redirection' => 'non', |
|
| 469 | + 'creer_preview' => 'non', |
|
| 470 | + 'taille_preview' => 150, |
|
| 471 | + 'articles_modif' => 'non', |
|
| 472 | + |
|
| 473 | + 'rubriques_descriptif' => 'non', |
|
| 474 | + 'rubriques_texte' => 'oui', |
|
| 475 | + |
|
| 476 | + 'accepter_inscriptions' => 'non', |
|
| 477 | + 'accepter_visiteurs' => 'non', |
|
| 478 | + 'prevenir_auteurs' => 'non', |
|
| 479 | + 'suivi_edito' => 'non', |
|
| 480 | + 'adresse_suivi' => '', |
|
| 481 | + 'adresse_suivi_inscription' => '', |
|
| 482 | + 'adresse_neuf' => '', |
|
| 483 | + 'jours_neuf' => '', |
|
| 484 | + 'quoi_de_neuf' => 'non', |
|
| 485 | + 'preview' => ',0minirezo,1comite,', |
|
| 486 | + |
|
| 487 | + 'syndication_integrale' => 'oui', |
|
| 488 | + 'charset' => _DEFAULT_CHARSET, |
|
| 489 | + 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 490 | + |
|
| 491 | + 'multi_rubriques' => 'non', |
|
| 492 | + 'multi_secteurs' => 'non', |
|
| 493 | + 'gerer_trad' => 'non', |
|
| 494 | + 'langues_multilingue' => '', |
|
| 495 | + |
|
| 496 | + 'version_html_max' => 'html4', |
|
| 497 | + |
|
| 498 | + 'type_urls' => 'page', |
|
| 499 | + |
|
| 500 | + 'email_envoi' => '', |
|
| 501 | + 'email_webmaster' => '', |
|
| 502 | + 'auto_compress_http' => 'non', |
|
| 503 | + ]); |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
@@ -511,43 +511,43 @@ discard block |
||
| 511 | 511 | * @return void |
| 512 | 512 | */ |
| 513 | 513 | function actualise_metas($liste_meta) { |
| 514 | - $meta_serveur = |
|
| 515 | - [ |
|
| 516 | - 'version_installee', |
|
| 517 | - 'adresse_site', |
|
| 518 | - 'alea_ephemere_ancien', |
|
| 519 | - 'alea_ephemere', |
|
| 520 | - 'alea_ephemere_date', |
|
| 521 | - 'langue_site', |
|
| 522 | - 'langues_proposees', |
|
| 523 | - 'date_calcul_rubriques', |
|
| 524 | - 'derniere_modif', |
|
| 525 | - 'optimiser_table', |
|
| 526 | - 'drapeau_edition', |
|
| 527 | - 'creer_preview', |
|
| 528 | - 'taille_preview', |
|
| 529 | - 'creer_htpasswd', |
|
| 530 | - 'creer_htaccess', |
|
| 531 | - 'gd_formats_read', |
|
| 532 | - 'gd_formats', |
|
| 533 | - 'netpbm_formats', |
|
| 534 | - 'formats_graphiques', |
|
| 535 | - 'image_process', |
|
| 536 | - 'plugin_header', |
|
| 537 | - 'plugin' |
|
| 538 | - ]; |
|
| 539 | - // verifier le impt=non |
|
| 540 | - sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 541 | - |
|
| 542 | - foreach ($liste_meta as $nom => $valeur) { |
|
| 543 | - if (empty($GLOBALS['meta'][$nom])) { |
|
| 544 | - ecrire_meta($nom, $valeur); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - include_spip('inc/rubriques'); |
|
| 549 | - $langues = calculer_langues_utilisees(); |
|
| 550 | - ecrire_meta('langues_utilisees', $langues); |
|
| 514 | + $meta_serveur = |
|
| 515 | + [ |
|
| 516 | + 'version_installee', |
|
| 517 | + 'adresse_site', |
|
| 518 | + 'alea_ephemere_ancien', |
|
| 519 | + 'alea_ephemere', |
|
| 520 | + 'alea_ephemere_date', |
|
| 521 | + 'langue_site', |
|
| 522 | + 'langues_proposees', |
|
| 523 | + 'date_calcul_rubriques', |
|
| 524 | + 'derniere_modif', |
|
| 525 | + 'optimiser_table', |
|
| 526 | + 'drapeau_edition', |
|
| 527 | + 'creer_preview', |
|
| 528 | + 'taille_preview', |
|
| 529 | + 'creer_htpasswd', |
|
| 530 | + 'creer_htaccess', |
|
| 531 | + 'gd_formats_read', |
|
| 532 | + 'gd_formats', |
|
| 533 | + 'netpbm_formats', |
|
| 534 | + 'formats_graphiques', |
|
| 535 | + 'image_process', |
|
| 536 | + 'plugin_header', |
|
| 537 | + 'plugin' |
|
| 538 | + ]; |
|
| 539 | + // verifier le impt=non |
|
| 540 | + sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 541 | + |
|
| 542 | + foreach ($liste_meta as $nom => $valeur) { |
|
| 543 | + if (empty($GLOBALS['meta'][$nom])) { |
|
| 544 | + ecrire_meta($nom, $valeur); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + include_spip('inc/rubriques'); |
|
| 549 | + $langues = calculer_langues_utilisees(); |
|
| 550 | + ecrire_meta('langues_utilisees', $langues); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -569,18 +569,18 @@ discard block |
||
| 569 | 569 | */ |
| 570 | 570 | function appliquer_modifs_config($purger_skel = false) { |
| 571 | 571 | |
| 572 | - foreach (liste_metas() as $i => $v) { |
|
| 573 | - if (($x = _request($i)) !== null) { |
|
| 574 | - ecrire_meta($i, $x); |
|
| 575 | - } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 576 | - ecrire_meta($i, $v); |
|
| 577 | - } |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - if ($purger_skel) { |
|
| 581 | - include_spip('inc/invalideur'); |
|
| 582 | - purger_repertoire(_DIR_SKELS); |
|
| 583 | - } |
|
| 572 | + foreach (liste_metas() as $i => $v) { |
|
| 573 | + if (($x = _request($i)) !== null) { |
|
| 574 | + ecrire_meta($i, $x); |
|
| 575 | + } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 576 | + ecrire_meta($i, $v); |
|
| 577 | + } |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + if ($purger_skel) { |
|
| 581 | + include_spip('inc/invalideur'); |
|
| 582 | + purger_repertoire(_DIR_SKELS); |
|
| 583 | + } |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -591,21 +591,21 @@ discard block |
||
| 591 | 591 | * @return string |
| 592 | 592 | */ |
| 593 | 593 | function appliquer_adresse_site($adresse_site) { |
| 594 | - if ($adresse_site !== null) { |
|
| 595 | - if (!strlen($adresse_site)) { |
|
| 596 | - $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 597 | - $adresse_site = url_de_base(); |
|
| 598 | - } |
|
| 599 | - $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 594 | + if ($adresse_site !== null) { |
|
| 595 | + if (!strlen($adresse_site)) { |
|
| 596 | + $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 597 | + $adresse_site = url_de_base(); |
|
| 598 | + } |
|
| 599 | + $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 600 | 600 | |
| 601 | - if (!tester_url_absolue($adresse_site)) { |
|
| 602 | - $adresse_site = "http://$adresse_site"; |
|
| 603 | - } |
|
| 601 | + if (!tester_url_absolue($adresse_site)) { |
|
| 602 | + $adresse_site = "http://$adresse_site"; |
|
| 603 | + } |
|
| 604 | 604 | |
| 605 | - $adresse_site = entites_html($adresse_site); |
|
| 605 | + $adresse_site = entites_html($adresse_site); |
|
| 606 | 606 | |
| 607 | - ecrire_meta('adresse_site', $adresse_site); |
|
| 608 | - } |
|
| 607 | + ecrire_meta('adresse_site', $adresse_site); |
|
| 608 | + } |
|
| 609 | 609 | |
| 610 | - return $adresse_site; |
|
| 610 | + return $adresse_site; |
|
| 611 | 611 | } |
@@ -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 | |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | * @return string URL nettoyée |
| 36 | 36 | **/ |
| 37 | 37 | function resolve_path($url) { |
| 38 | - list($url, $query) = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | - while ( |
|
| 40 | - preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | - or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | - or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | - ) { |
|
| 44 | - $url = str_replace($regs[0], '/', $url); |
|
| 45 | - } |
|
| 38 | + list($url, $query) = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | + while ( |
|
| 40 | + preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | + or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | + or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | + ) { |
|
| 44 | + $url = str_replace($regs[0], '/', $url); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if ($query) { |
|
| 48 | - $url .= '?' . $query; |
|
| 49 | - } |
|
| 47 | + if ($query) { |
|
| 48 | + $url .= '?' . $query; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/' . preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -69,41 +69,41 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function suivre_lien($url, $lien) { |
| 71 | 71 | |
| 72 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 73 | - return $lien; |
|
| 74 | - } |
|
| 75 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 76 | - $r = array_pad($r, 3, null); |
|
| 72 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 73 | + return $lien; |
|
| 74 | + } |
|
| 75 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 76 | + $r = array_pad($r, 3, null); |
|
| 77 | 77 | |
| 78 | - return $r[1] . resolve_path($r[2]); |
|
| 79 | - } |
|
| 78 | + return $r[1] . resolve_path($r[2]); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - # L'url site spip est un lien absolu aussi |
|
| 82 | - if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 83 | - return $lien; |
|
| 84 | - } |
|
| 81 | + # L'url site spip est un lien absolu aussi |
|
| 82 | + if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 83 | + return $lien; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - # lien relatif, il faut verifier l'url de base |
|
| 87 | - # commencer par virer la chaine de get de l'url de base |
|
| 88 | - $dir = '/'; |
|
| 89 | - $debut = ''; |
|
| 90 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 91 | - $debut = $regs[1]; |
|
| 92 | - $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 93 | - $mot = $regs[3]; |
|
| 94 | - $get = $regs[4] ?? ''; |
|
| 95 | - $hash = $regs[5] ?? ''; |
|
| 96 | - } |
|
| 97 | - switch (substr($lien, 0, 1)) { |
|
| 98 | - case '/': |
|
| 99 | - return $debut . resolve_path($lien); |
|
| 100 | - case '#': |
|
| 101 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 102 | - case '': |
|
| 103 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 104 | - default: |
|
| 105 | - return $debut . resolve_path($dir . $lien); |
|
| 106 | - } |
|
| 86 | + # lien relatif, il faut verifier l'url de base |
|
| 87 | + # commencer par virer la chaine de get de l'url de base |
|
| 88 | + $dir = '/'; |
|
| 89 | + $debut = ''; |
|
| 90 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 91 | + $debut = $regs[1]; |
|
| 92 | + $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 93 | + $mot = $regs[3]; |
|
| 94 | + $get = $regs[4] ?? ''; |
|
| 95 | + $hash = $regs[5] ?? ''; |
|
| 96 | + } |
|
| 97 | + switch (substr($lien, 0, 1)) { |
|
| 98 | + case '/': |
|
| 99 | + return $debut . resolve_path($lien); |
|
| 100 | + case '#': |
|
| 101 | + return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 102 | + case '': |
|
| 103 | + return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 104 | + default: |
|
| 105 | + return $debut . resolve_path($dir . $lien); |
|
| 106 | + } |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
@@ -126,14 +126,14 @@ discard block |
||
| 126 | 126 | * @return string Texte ou URL (en absolus) |
| 127 | 127 | **/ |
| 128 | 128 | function url_absolue($url, $base = '') { |
| 129 | - if (strlen($url = trim($url)) == 0) { |
|
| 130 | - return ''; |
|
| 131 | - } |
|
| 132 | - if (!$base) { |
|
| 133 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 134 | - } |
|
| 129 | + if (strlen($url = trim($url)) == 0) { |
|
| 130 | + return ''; |
|
| 131 | + } |
|
| 132 | + if (!$base) { |
|
| 133 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - return suivre_lien($base, $url); |
|
| 136 | + return suivre_lien($base, $url); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | 146 | function protocole_implicite($url_absolue) { |
| 147 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 147 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -155,16 +155,16 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 157 | 157 | |
| 158 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 159 | - $protocole = $m[1]; |
|
| 160 | - if ( |
|
| 161 | - in_array($protocole, $protocoles_autorises) |
|
| 162 | - or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 163 | - ) { |
|
| 164 | - return true; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - return false; |
|
| 158 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 159 | + $protocole = $m[1]; |
|
| 160 | + if ( |
|
| 161 | + in_array($protocole, $protocoles_autorises) |
|
| 162 | + or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 163 | + ) { |
|
| 164 | + return true; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + return false; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -181,27 +181,27 @@ discard block |
||
| 181 | 181 | * @return string Texte avec des URLs absolues |
| 182 | 182 | **/ |
| 183 | 183 | function liens_absolus($texte, $base = '') { |
| 184 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 185 | - if (!function_exists('extraire_attribut')) { |
|
| 186 | - include_spip('inc/filtres'); |
|
| 187 | - } |
|
| 188 | - foreach ($liens as $lien) { |
|
| 189 | - foreach (['href', 'src'] as $attr) { |
|
| 190 | - $href = extraire_attribut($lien[0], $attr); |
|
| 191 | - if (strlen($href) > 0) { |
|
| 192 | - if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 193 | - $abs = url_absolue($href, $base); |
|
| 194 | - if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 195 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 196 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 184 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 185 | + if (!function_exists('extraire_attribut')) { |
|
| 186 | + include_spip('inc/filtres'); |
|
| 187 | + } |
|
| 188 | + foreach ($liens as $lien) { |
|
| 189 | + foreach (['href', 'src'] as $attr) { |
|
| 190 | + $href = extraire_attribut($lien[0], $attr); |
|
| 191 | + if (strlen($href) > 0) { |
|
| 192 | + if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 193 | + $abs = url_absolue($href, $base); |
|
| 194 | + if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 195 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 196 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $texte; |
|
| 204 | + return $texte; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
@@ -217,11 +217,11 @@ discard block |
||
| 217 | 217 | * @return string Texte ou URL (en absolus) |
| 218 | 218 | **/ |
| 219 | 219 | function abs_url($texte, $base = '') { |
| 220 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 221 | - return url_absolue($texte, $base); |
|
| 222 | - } else { |
|
| 223 | - return liens_absolus($texte, $base); |
|
| 224 | - } |
|
| 220 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 221 | + return url_absolue($texte, $base); |
|
| 222 | + } else { |
|
| 223 | + return liens_absolus($texte, $base); |
|
| 224 | + } |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | 236 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 237 | - if (is_null($flags)) { |
|
| 238 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 239 | - } |
|
| 237 | + if (is_null($flags)) { |
|
| 238 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 241 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | * @return string |
| 252 | 252 | */ |
| 253 | 253 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 254 | - if (is_null($flags)) { |
|
| 255 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 256 | - } |
|
| 254 | + if (is_null($flags)) { |
|
| 255 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 258 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 259 | 259 | } |
@@ -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 | /** |
@@ -43,25 +43,25 @@ discard block |
||
| 43 | 43 | * @return string Code HTML |
| 44 | 44 | **/ |
| 45 | 45 | function inc_commencer_page_dist( |
| 46 | - $titre = '', |
|
| 47 | - $rubrique = 'accueil', |
|
| 48 | - $sous_rubrique = 'accueil', |
|
| 49 | - $id_rubrique = '', |
|
| 50 | - $menu = true, |
|
| 51 | - $minipres = false, |
|
| 52 | - $alertes = true |
|
| 46 | + $titre = '', |
|
| 47 | + $rubrique = 'accueil', |
|
| 48 | + $sous_rubrique = 'accueil', |
|
| 49 | + $id_rubrique = '', |
|
| 50 | + $menu = true, |
|
| 51 | + $minipres = false, |
|
| 52 | + $alertes = true |
|
| 53 | 53 | ) { |
| 54 | 54 | |
| 55 | - include_spip('inc/headers'); |
|
| 55 | + include_spip('inc/headers'); |
|
| 56 | 56 | |
| 57 | - http_no_cache(); |
|
| 57 | + http_no_cache(); |
|
| 58 | 58 | |
| 59 | - return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | - . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | - . "<div id='page'>" |
|
| 62 | - . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | - . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | - . '<div class="largeur">'; |
|
| 59 | + return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | + . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | + . "<div id='page'>" |
|
| 62 | + . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | + . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | + . '<div class="largeur">'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -82,21 +82,21 @@ discard block |
||
| 82 | 82 | * Entête du fichier HTML avec le DOCTYPE |
| 83 | 83 | */ |
| 84 | 84 | function init_entete($titre = '', $dummy = 0, $minipres = false) { |
| 85 | - include_spip('inc/texte'); |
|
| 86 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $titre = '[' |
|
| 91 | - . $nom_site_spip |
|
| 92 | - . ']' |
|
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | - |
|
| 95 | - return _DOCTYPE_ECRIRE |
|
| 96 | - . html_lang_attributes() |
|
| 97 | - . "<head>\n" |
|
| 98 | - . init_head($titre, $dummy, $minipres) |
|
| 99 | - . "</head>\n"; |
|
| 85 | + include_spip('inc/texte'); |
|
| 86 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $titre = '[' |
|
| 91 | + . $nom_site_spip |
|
| 92 | + . ']' |
|
| 93 | + . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | + |
|
| 95 | + return _DOCTYPE_ECRIRE |
|
| 96 | + . html_lang_attributes() |
|
| 97 | + . "<head>\n" |
|
| 98 | + . init_head($titre, $dummy, $minipres) |
|
| 99 | + . "</head>\n"; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function init_head($titre = '', $dummy = 0, $minipres = false) { |
| 113 | - return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 113 | + return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -132,20 +132,20 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | - $res = pipeline('body_prive', "<body class='" |
|
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | - . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | - . '>'); |
|
| 135 | + $res = pipeline('body_prive', "<body class='" |
|
| 136 | + . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | + . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | + . '>'); |
|
| 139 | 139 | |
| 140 | - if (!$menu) { |
|
| 141 | - return $res; |
|
| 142 | - } |
|
| 140 | + if (!$menu) { |
|
| 141 | + return $res; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | |
| 145 | - $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 145 | + $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 146 | 146 | |
| 147 | - return $res |
|
| 148 | - . $bandeau(); |
|
| 147 | + return $res |
|
| 148 | + . $bandeau(); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,25 +157,25 @@ discard block |
||
| 157 | 157 | * @return string Classes CSS (séparées par des espaces) |
| 158 | 158 | */ |
| 159 | 159 | function init_body_class() { |
| 160 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 160 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 161 | 161 | |
| 162 | - $GLOBALS['spip_display'] = intval($prefs['display'] ?? 2); |
|
| 163 | - $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 164 | - $spip_display_outils = ($prefs['display_outils'] ?? true) ? 'navigation_avec_outils' : 'navigation_sans_outils'; |
|
| 165 | - $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? spip_sanitize_classname($_COOKIE['spip_ecran']) : 'etroit'; |
|
| 162 | + $GLOBALS['spip_display'] = intval($prefs['display'] ?? 2); |
|
| 163 | + $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 164 | + $spip_display_outils = ($prefs['display_outils'] ?? true) ? 'navigation_avec_outils' : 'navigation_sans_outils'; |
|
| 165 | + $GLOBALS['spip_ecran'] = isset($_COOKIE['spip_ecran']) ? spip_sanitize_classname($_COOKIE['spip_ecran']) : 'etroit'; |
|
| 166 | 166 | |
| 167 | - $display_class = [ |
|
| 168 | - 0 => 'icones_img_texte' |
|
| 169 | - /*init*/, |
|
| 170 | - 1 => 'icones_texte', |
|
| 171 | - 2 => 'icones_img_texte', |
|
| 172 | - 3 => 'icones_img' |
|
| 173 | - ]; |
|
| 167 | + $display_class = [ |
|
| 168 | + 0 => 'icones_img_texte' |
|
| 169 | + /*init*/, |
|
| 170 | + 1 => 'icones_texte', |
|
| 171 | + 2 => 'icones_img_texte', |
|
| 172 | + 3 => 'icones_img' |
|
| 173 | + ]; |
|
| 174 | 174 | |
| 175 | - $couleur = intval($prefs['couleur'] ?? 2); |
|
| 175 | + $couleur = intval($prefs['couleur'] ?? 2); |
|
| 176 | 176 | |
| 177 | - $classes = $GLOBALS['spip_ecran'] . " spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils " . $display_class[$GLOBALS['spip_display']]; |
|
| 178 | - return spip_sanitize_classname($classes); |
|
| 177 | + $classes = $GLOBALS['spip_ecran'] . " spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils " . $display_class[$GLOBALS['spip_display']]; |
|
| 178 | + return spip_sanitize_classname($classes); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -186,5 +186,5 @@ discard block |
||
| 186 | 186 | * @return string |
| 187 | 187 | */ |
| 188 | 188 | function auteurs_recemment_connectes($id_auteur) { |
| 189 | - return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 189 | + return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 190 | 190 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $titre = '[' |
| 91 | 91 | . $nom_site_spip |
| 92 | 92 | . ']' |
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + . ($titre ? ' '.textebrut(typo($titre)) : ''); |
|
| 94 | 94 | |
| 95 | 95 | return _DOCTYPE_ECRIRE |
| 96 | 96 | . html_lang_attributes() |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | 135 | $res = pipeline('body_prive', "<body class='" |
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . init_body_class().' '._request('exec')."'" |
|
| 137 | 137 | . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
| 138 | 138 | . '>'); |
| 139 | 139 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $couleur = intval($prefs['couleur'] ?? 2); |
| 176 | 176 | |
| 177 | - $classes = $GLOBALS['spip_ecran'] . " spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils " . $display_class[$GLOBALS['spip_display']]; |
|
| 177 | + $classes = $GLOBALS['spip_ecran']." spip-theme-colors-$couleur $spip_display_navigation $spip_display_outils ".$display_class[$GLOBALS['spip_display']]; |
|
| 178 | 178 | return spip_sanitize_classname($classes); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('base/abstract_sql'); |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | // |
| 24 | 24 | |
| 25 | 25 | function inc_lien_dist( |
| 26 | - $lien, |
|
| 27 | - $texte = '', |
|
| 28 | - $class = '', |
|
| 29 | - $title = '', |
|
| 30 | - $hlang = '', |
|
| 31 | - $rel = '', |
|
| 32 | - string $connect = '', |
|
| 33 | - $env = [] |
|
| 26 | + $lien, |
|
| 27 | + $texte = '', |
|
| 28 | + $class = '', |
|
| 29 | + $title = '', |
|
| 30 | + $hlang = '', |
|
| 31 | + $rel = '', |
|
| 32 | + string $connect = '', |
|
| 33 | + $env = [] |
|
| 34 | 34 | ) { |
| 35 | - return $lien; |
|
| 35 | + return $lien; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // Regexp des raccourcis, aussi utilisee pour la fusion de sauvegarde Spip |
@@ -44,30 +44,30 @@ discard block |
||
| 44 | 44 | // https://code.spip.net/@expanser_liens |
| 45 | 45 | function expanser_liens($t, string $connect = '', $env = []) { |
| 46 | 46 | |
| 47 | - $t = pipeline('pre_liens', $t); |
|
| 47 | + $t = pipeline('pre_liens', $t); |
|
| 48 | 48 | |
| 49 | - // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 50 | - // de remettre le texte d'origine dans les parametres du modele |
|
| 51 | - $t = traiter_modeles($t, false, false, $connect); |
|
| 49 | + // on passe a traiter_modeles la liste des liens reperes pour lui permettre |
|
| 50 | + // de remettre le texte d'origine dans les parametres du modele |
|
| 51 | + $t = traiter_modeles($t, false, false, $connect); |
|
| 52 | 52 | |
| 53 | - return $t; |
|
| 53 | + return $t; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Meme analyse mais pour eliminer les liens |
| 57 | 57 | // et ne laisser que leur titre, a expliciter si ce n'est fait |
| 58 | 58 | // https://code.spip.net/@nettoyer_raccourcis_typo |
| 59 | 59 | function nettoyer_raccourcis_typo($texte, string $connect = '') { |
| 60 | - return $texte; |
|
| 60 | + return $texte; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // Repere dans la partie texte d'un raccourci [texte->...] |
| 64 | 64 | // la langue et la bulle eventuelles |
| 65 | 65 | // https://code.spip.net/@traiter_raccourci_lien_atts |
| 66 | 66 | function traiter_raccourci_lien_atts($texte) { |
| 67 | - $bulle = ''; |
|
| 68 | - $hlang = ''; |
|
| 67 | + $bulle = ''; |
|
| 68 | + $hlang = ''; |
|
| 69 | 69 | |
| 70 | - return [trim($texte), $bulle, $hlang]; |
|
| 70 | + return [trim($texte), $bulle, $hlang]; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/'); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | 85 | function virtuel_redirige($virtuel, $url = false) { |
| 86 | - return $virtuel; |
|
| 86 | + return $virtuel; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Cherche un lien du type [->raccourci 123] |
@@ -97,122 +97,122 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | // https://code.spip.net/@calculer_url |
| 99 | 99 | function calculer_url($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 100 | - $r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 100 | + $r = traiter_lien_implicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 101 | 101 | |
| 102 | - return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 102 | + return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS'); |
| 106 | 106 | |
| 107 | 107 | // https://code.spip.net/@traiter_lien_explicite |
| 108 | 108 | function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
| 109 | - if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 110 | - return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $lien = entites_html(trim($ref)); |
|
| 114 | - |
|
| 115 | - // Liens explicites |
|
| 116 | - if (!$texte) { |
|
| 117 | - $texte = str_replace('"', '', $lien); |
|
| 118 | - // evite l'affichage de trops longues urls. |
|
| 119 | - $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 120 | - $texte = $lien_court($texte); |
|
| 121 | - if ($echappe_typo) { |
|
| 122 | - $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // petites corrections d'URL |
|
| 127 | - if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 128 | - $lien = 'http://' . $lien; |
|
| 129 | - } else { |
|
| 130 | - if (strpos($lien, '@') && email_valide($lien)) { |
|
| 131 | - if (!$texte) { |
|
| 132 | - $texte = $lien; |
|
| 133 | - } |
|
| 134 | - $lien = 'mailto:' . $lien; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if ($pour == 'url') { |
|
| 139 | - return $lien; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - if ($pour == 'titre') { |
|
| 143 | - return $texte; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return ['url' => $lien, 'titre' => $texte]; |
|
| 109 | + if (preg_match(_EXTRAIRE_LIEN, $ref)) { |
|
| 110 | + return ($pour != 'tout') ? '' : ['', '', '', '']; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $lien = entites_html(trim($ref)); |
|
| 114 | + |
|
| 115 | + // Liens explicites |
|
| 116 | + if (!$texte) { |
|
| 117 | + $texte = str_replace('"', '', $lien); |
|
| 118 | + // evite l'affichage de trops longues urls. |
|
| 119 | + $lien_court = charger_fonction('lien_court', 'inc'); |
|
| 120 | + $texte = $lien_court($texte); |
|
| 121 | + if ($echappe_typo) { |
|
| 122 | + $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // petites corrections d'URL |
|
| 127 | + if (preg_match('/^www\.[^@]+$/S', $lien)) { |
|
| 128 | + $lien = 'http://' . $lien; |
|
| 129 | + } else { |
|
| 130 | + if (strpos($lien, '@') && email_valide($lien)) { |
|
| 131 | + if (!$texte) { |
|
| 132 | + $texte = $lien; |
|
| 133 | + } |
|
| 134 | + $lien = 'mailto:' . $lien; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if ($pour == 'url') { |
|
| 139 | + return $lien; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + if ($pour == 'titre') { |
|
| 143 | + return $texte; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return ['url' => $lien, 'titre' => $texte]; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') { |
| 150 | - if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 151 | - $url = $f($texte, $id); |
|
| 152 | - } else { |
|
| 153 | - $url = glossaire_std($texte); |
|
| 154 | - } |
|
| 150 | + if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 151 | + $url = $f($texte, $id); |
|
| 152 | + } else { |
|
| 153 | + $url = glossaire_std($texte); |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - return $url; |
|
| 156 | + return $url; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // https://code.spip.net/@traiter_lien_implicite |
| 160 | 160 | function traiter_lien_implicite($ref, $texte = '', $pour = 'url', string $connect = '') { |
| 161 | - if (!($match = typer_raccourci($ref))) { |
|
| 162 | - return false; |
|
| 163 | - } |
|
| 164 | - @list($type, , $id, , $args, , $ancre) = $match; |
|
| 165 | - // attention dans le cas des sites le lien doit pointer non pas sur |
|
| 166 | - // la page locale du site, mais directement sur le site lui-meme |
|
| 167 | - if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 168 | - $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 169 | - } |
|
| 170 | - if (!$url) { |
|
| 171 | - $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null); |
|
| 172 | - } |
|
| 173 | - if (!$url) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - if (is_array($url)) { |
|
| 177 | - @list($type, $id) = $url; |
|
| 178 | - $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null); |
|
| 179 | - } |
|
| 180 | - if ($pour === 'url') { |
|
| 181 | - return $url; |
|
| 182 | - } |
|
| 183 | - $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 184 | - if ($r) { |
|
| 185 | - $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 186 | - } |
|
| 187 | - if ($texte = trim($texte)) { |
|
| 188 | - $r['titre'] = $texte; |
|
| 189 | - } |
|
| 190 | - if (!@$r['titre']) { |
|
| 191 | - $r['titre'] = _T($type) . " $id"; |
|
| 192 | - } |
|
| 193 | - if ($pour == 'titre') { |
|
| 194 | - return $r['titre']; |
|
| 195 | - } |
|
| 196 | - $r['url'] = $url; |
|
| 197 | - |
|
| 198 | - // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 199 | - if ( |
|
| 200 | - $type == 'document' |
|
| 201 | - and $mime = sql_getfetsel( |
|
| 202 | - 'mime_type', |
|
| 203 | - 'spip_types_documents', |
|
| 204 | - 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 205 | - '', |
|
| 206 | - '', |
|
| 207 | - '', |
|
| 208 | - '', |
|
| 209 | - $connect |
|
| 210 | - ) |
|
| 211 | - ) { |
|
| 212 | - $r['mime'] = $mime; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - return $r; |
|
| 161 | + if (!($match = typer_raccourci($ref))) { |
|
| 162 | + return false; |
|
| 163 | + } |
|
| 164 | + @list($type, , $id, , $args, , $ancre) = $match; |
|
| 165 | + // attention dans le cas des sites le lien doit pointer non pas sur |
|
| 166 | + // la page locale du site, mais directement sur le site lui-meme |
|
| 167 | + if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
|
| 168 | + $url = $f($texte, $id, $type, $args, $ancre, $connect); |
|
| 169 | + } |
|
| 170 | + if (!$url) { |
|
| 171 | + $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null); |
|
| 172 | + } |
|
| 173 | + if (!$url) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + if (is_array($url)) { |
|
| 177 | + @list($type, $id) = $url; |
|
| 178 | + $url = generer_url_entite($id, $type, $args, $ancre, $connect ? $connect : null); |
|
| 179 | + } |
|
| 180 | + if ($pour === 'url') { |
|
| 181 | + return $url; |
|
| 182 | + } |
|
| 183 | + $r = traiter_raccourci_titre($id, $type, $connect); |
|
| 184 | + if ($r) { |
|
| 185 | + $r['class'] = ($type == 'site') ? 'spip_out' : 'spip_in'; |
|
| 186 | + } |
|
| 187 | + if ($texte = trim($texte)) { |
|
| 188 | + $r['titre'] = $texte; |
|
| 189 | + } |
|
| 190 | + if (!@$r['titre']) { |
|
| 191 | + $r['titre'] = _T($type) . " $id"; |
|
| 192 | + } |
|
| 193 | + if ($pour == 'titre') { |
|
| 194 | + return $r['titre']; |
|
| 195 | + } |
|
| 196 | + $r['url'] = $url; |
|
| 197 | + |
|
| 198 | + // dans le cas d'un lien vers un doc, ajouter le type='mime/type' |
|
| 199 | + if ( |
|
| 200 | + $type == 'document' |
|
| 201 | + and $mime = sql_getfetsel( |
|
| 202 | + 'mime_type', |
|
| 203 | + 'spip_types_documents', |
|
| 204 | + 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 205 | + '', |
|
| 206 | + '', |
|
| 207 | + '', |
|
| 208 | + '', |
|
| 209 | + $connect |
|
| 210 | + ) |
|
| 211 | + ) { |
|
| 212 | + $r['mime'] = $mime; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + return $r; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | // analyse des raccourcis issus de [TITRE->RACCOURCInnn] et connexes |
@@ -221,41 +221,41 @@ discard block |
||
| 221 | 221 | |
| 222 | 222 | // https://code.spip.net/@typer_raccourci |
| 223 | 223 | function typer_raccourci($lien) { |
| 224 | - if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 225 | - return []; |
|
| 226 | - } |
|
| 227 | - $f = $match[1]; |
|
| 228 | - // valeur par defaut et alias historiques |
|
| 229 | - if (!$f) { |
|
| 230 | - $f = 'article'; |
|
| 231 | - } else { |
|
| 232 | - if ($f == 'art') { |
|
| 233 | - $f = 'article'; |
|
| 234 | - } else { |
|
| 235 | - if ($f == 'br') { |
|
| 236 | - $f = 'breve'; |
|
| 237 | - } else { |
|
| 238 | - if ($f == 'rub') { |
|
| 239 | - $f = 'rubrique'; |
|
| 240 | - } else { |
|
| 241 | - if ($f == 'aut') { |
|
| 242 | - $f = 'auteur'; |
|
| 243 | - } else { |
|
| 244 | - if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 245 | - $f = 'document'; |
|
| 246 | - } else { |
|
| 247 | - if (preg_match('/^br..?ve$/S', $f)) { |
|
| 248 | - $f = 'breve'; |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - } # accents :( |
|
| 256 | - $match[0] = $f; |
|
| 257 | - |
|
| 258 | - return $match; |
|
| 224 | + if (!preg_match(_RACCOURCI_URL, $lien, $match)) { |
|
| 225 | + return []; |
|
| 226 | + } |
|
| 227 | + $f = $match[1]; |
|
| 228 | + // valeur par defaut et alias historiques |
|
| 229 | + if (!$f) { |
|
| 230 | + $f = 'article'; |
|
| 231 | + } else { |
|
| 232 | + if ($f == 'art') { |
|
| 233 | + $f = 'article'; |
|
| 234 | + } else { |
|
| 235 | + if ($f == 'br') { |
|
| 236 | + $f = 'breve'; |
|
| 237 | + } else { |
|
| 238 | + if ($f == 'rub') { |
|
| 239 | + $f = 'rubrique'; |
|
| 240 | + } else { |
|
| 241 | + if ($f == 'aut') { |
|
| 242 | + $f = 'auteur'; |
|
| 243 | + } else { |
|
| 244 | + if ($f == 'doc' or $f == 'im' or $f == 'img' or $f == 'image' or $f == 'emb') { |
|
| 245 | + $f = 'document'; |
|
| 246 | + } else { |
|
| 247 | + if (preg_match('/^br..?ve$/S', $f)) { |
|
| 248 | + $f = 'breve'; |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + } # accents :( |
|
| 256 | + $match[0] = $f; |
|
| 257 | + |
|
| 258 | + return $match; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -270,25 +270,25 @@ discard block |
||
| 270 | 270 | * } |
| 271 | 271 | **/ |
| 272 | 272 | function traiter_raccourci_titre($id, $type, $connect = null) { |
| 273 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 274 | - $desc = $trouver_table(table_objet($type)); |
|
| 275 | - if (!($desc and $s = $desc['titre'])) { |
|
| 276 | - return []; |
|
| 277 | - } |
|
| 278 | - $_id = $desc['key']['PRIMARY KEY']; |
|
| 279 | - $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 280 | - if (!$r) { |
|
| 281 | - return []; |
|
| 282 | - } |
|
| 283 | - $r['titre'] = supprimer_numero($r['titre']); |
|
| 284 | - if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 285 | - $r['titre'] = $r['surnom']; |
|
| 286 | - } |
|
| 287 | - if (!isset($r['lang'])) { |
|
| 288 | - $r['lang'] = ''; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return $r; |
|
| 273 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 274 | + $desc = $trouver_table(table_objet($type)); |
|
| 275 | + if (!($desc and $s = $desc['titre'])) { |
|
| 276 | + return []; |
|
| 277 | + } |
|
| 278 | + $_id = $desc['key']['PRIMARY KEY']; |
|
| 279 | + $r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect); |
|
| 280 | + if (!$r) { |
|
| 281 | + return []; |
|
| 282 | + } |
|
| 283 | + $r['titre'] = supprimer_numero($r['titre']); |
|
| 284 | + if (!$r['titre'] and !empty($r['surnom'])) { |
|
| 285 | + $r['titre'] = $r['surnom']; |
|
| 286 | + } |
|
| 287 | + if (!isset($r['lang'])) { |
|
| 288 | + $r['lang'] = ''; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return $r; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | // traite les modeles (dans la fonction typo), en remplacant |
@@ -300,124 +300,124 @@ discard block |
||
| 300 | 300 | // https://code.spip.net/@traiter_modeles |
| 301 | 301 | |
| 302 | 302 | define( |
| 303 | - '_RACCOURCI_MODELE', |
|
| 304 | - '(<([a-z_-]{3,})' # <modele |
|
| 305 | - . '\s*([0-9]*)\s*' # id |
|
| 306 | - . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 307 | - . '\s*/?' . '>)' # fin du modele > |
|
| 308 | - . '\s*(<\/a>)?' # eventuel </a> |
|
| 303 | + '_RACCOURCI_MODELE', |
|
| 304 | + '(<([a-z_-]{3,})' # <modele |
|
| 305 | + . '\s*([0-9]*)\s*' # id |
|
| 306 | + . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
|
| 307 | + . '\s*/?' . '>)' # fin du modele > |
|
| 308 | + . '\s*(<\/a>)?' # eventuel </a> |
|
| 309 | 309 | ); |
| 310 | 310 | |
| 311 | 311 | define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS'); |
| 312 | 312 | |
| 313 | 313 | // https://code.spip.net/@traiter_modeles |
| 314 | 314 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', $liens = null, $env = []) { |
| 315 | - // preserver la compatibilite : true = recherche des documents |
|
| 316 | - if ($doublons === true) { |
|
| 317 | - $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 318 | - } |
|
| 319 | - // detecter les modeles (rapide) |
|
| 320 | - if ( |
|
| 321 | - strpos($texte, '<') !== false and |
|
| 322 | - preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 323 | - ) { |
|
| 324 | - include_spip('public/assembler'); |
|
| 325 | - $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 326 | - foreach ($matches as $match) { |
|
| 327 | - // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 328 | - |
|
| 329 | - $a = strpos($texte, $match[0]); |
|
| 330 | - preg_match( |
|
| 331 | - _RACCOURCI_MODELE_DEBUT, |
|
| 332 | - substr($texte, $a), |
|
| 333 | - $regs |
|
| 334 | - ); |
|
| 335 | - $regs[] = ''; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 336 | - list(, $mod, $type, $id, $params, $fin) = $regs; |
|
| 337 | - if ( |
|
| 338 | - $fin and |
|
| 339 | - preg_match( |
|
| 340 | - '/<a\s[^<>]*>\s*$/i', |
|
| 341 | - substr($texte, 0, $a), |
|
| 342 | - $r |
|
| 343 | - ) |
|
| 344 | - ) { |
|
| 345 | - $lien = [ |
|
| 346 | - 'href' => extraire_attribut($r[0], 'href'), |
|
| 347 | - 'class' => extraire_attribut($r[0], 'class'), |
|
| 348 | - 'mime' => extraire_attribut($r[0], 'type'), |
|
| 349 | - 'title' => extraire_attribut($r[0], 'title'), |
|
| 350 | - 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 351 | - ]; |
|
| 352 | - $n = strlen($r[0]); |
|
| 353 | - $a -= $n; |
|
| 354 | - $cherche = $n + strlen($regs[0]); |
|
| 355 | - } else { |
|
| 356 | - $lien = false; |
|
| 357 | - $cherche = strlen($mod); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // calculer le modele |
|
| 361 | - # hack indexation |
|
| 362 | - if ($doublons) { |
|
| 363 | - $texte .= preg_replace(',[|][^|=]*,s', ' ', $params); |
|
| 364 | - } # version normale |
|
| 365 | - else { |
|
| 366 | - // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 367 | - // dans les parametres, plutot que les liens echappes |
|
| 368 | - if (!is_null($liens)) { |
|
| 369 | - $params = str_replace($liens[0], $liens[1], $params); |
|
| 370 | - } |
|
| 371 | - $modele = inclure_modele($type, $id, $params, $lien, $connect, $env); |
|
| 372 | - // en cas d'echec, |
|
| 373 | - // si l'objet demande a une url, |
|
| 374 | - // creer un petit encadre vers elle |
|
| 375 | - if ($modele === false) { |
|
| 376 | - if (!$lien) { |
|
| 377 | - $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect); |
|
| 378 | - } |
|
| 379 | - if ($lien) { |
|
| 380 | - $modele = '<a href="' |
|
| 381 | - . $lien['url'] |
|
| 382 | - . '" class="spip_modele' |
|
| 383 | - . '">' |
|
| 384 | - . sinon($lien['titre'], _T('ecrire:info_sans_titre')) |
|
| 385 | - . '</a>'; |
|
| 386 | - } else { |
|
| 387 | - $modele = ''; |
|
| 388 | - if (test_espace_prive()) { |
|
| 389 | - $modele = entites_html(substr($texte, $a, $cherche)); |
|
| 390 | - if (!is_null($liens)) { |
|
| 391 | - $modele = '<pre>' . str_replace($liens[0], $liens[1], $modele) . '</pre>'; |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - // le remplacer dans le texte |
|
| 397 | - if ($modele !== false) { |
|
| 398 | - $modele = protege_js_modeles($modele); |
|
| 399 | - if ($wrap_embed_html) { |
|
| 400 | - $modele = $wrap_embed_html($mod, $modele); |
|
| 401 | - } |
|
| 402 | - $rempl = code_echappement($modele, $echap); |
|
| 403 | - $texte = substr($texte, 0, $a) |
|
| 404 | - . $rempl |
|
| 405 | - . substr($texte, $a + $cherche); |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - // hack pour tout l'espace prive |
|
| 410 | - if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) { |
|
| 411 | - foreach ($doublons ? $doublons : ['documents' => ['doc', 'emb', 'img']] as $quoi => $modeles) { |
|
| 412 | - if (in_array($type, $modeles)) { |
|
| 413 | - $GLOBALS["doublons_{$quoi}_inclus"][] = $id; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - |
|
| 420 | - return $texte; |
|
| 315 | + // preserver la compatibilite : true = recherche des documents |
|
| 316 | + if ($doublons === true) { |
|
| 317 | + $doublons = ['documents' => ['doc', 'emb', 'img']]; |
|
| 318 | + } |
|
| 319 | + // detecter les modeles (rapide) |
|
| 320 | + if ( |
|
| 321 | + strpos($texte, '<') !== false and |
|
| 322 | + preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER) |
|
| 323 | + ) { |
|
| 324 | + include_spip('public/assembler'); |
|
| 325 | + $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true); |
|
| 326 | + foreach ($matches as $match) { |
|
| 327 | + // Recuperer l'appel complet (y compris un eventuel lien) |
|
| 328 | + |
|
| 329 | + $a = strpos($texte, $match[0]); |
|
| 330 | + preg_match( |
|
| 331 | + _RACCOURCI_MODELE_DEBUT, |
|
| 332 | + substr($texte, $a), |
|
| 333 | + $regs |
|
| 334 | + ); |
|
| 335 | + $regs[] = ''; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide |
|
| 336 | + list(, $mod, $type, $id, $params, $fin) = $regs; |
|
| 337 | + if ( |
|
| 338 | + $fin and |
|
| 339 | + preg_match( |
|
| 340 | + '/<a\s[^<>]*>\s*$/i', |
|
| 341 | + substr($texte, 0, $a), |
|
| 342 | + $r |
|
| 343 | + ) |
|
| 344 | + ) { |
|
| 345 | + $lien = [ |
|
| 346 | + 'href' => extraire_attribut($r[0], 'href'), |
|
| 347 | + 'class' => extraire_attribut($r[0], 'class'), |
|
| 348 | + 'mime' => extraire_attribut($r[0], 'type'), |
|
| 349 | + 'title' => extraire_attribut($r[0], 'title'), |
|
| 350 | + 'hreflang' => extraire_attribut($r[0], 'hreflang') |
|
| 351 | + ]; |
|
| 352 | + $n = strlen($r[0]); |
|
| 353 | + $a -= $n; |
|
| 354 | + $cherche = $n + strlen($regs[0]); |
|
| 355 | + } else { |
|
| 356 | + $lien = false; |
|
| 357 | + $cherche = strlen($mod); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // calculer le modele |
|
| 361 | + # hack indexation |
|
| 362 | + if ($doublons) { |
|
| 363 | + $texte .= preg_replace(',[|][^|=]*,s', ' ', $params); |
|
| 364 | + } # version normale |
|
| 365 | + else { |
|
| 366 | + // si un tableau de liens a ete passe, reinjecter le contenu d'origine |
|
| 367 | + // dans les parametres, plutot que les liens echappes |
|
| 368 | + if (!is_null($liens)) { |
|
| 369 | + $params = str_replace($liens[0], $liens[1], $params); |
|
| 370 | + } |
|
| 371 | + $modele = inclure_modele($type, $id, $params, $lien, $connect, $env); |
|
| 372 | + // en cas d'echec, |
|
| 373 | + // si l'objet demande a une url, |
|
| 374 | + // creer un petit encadre vers elle |
|
| 375 | + if ($modele === false) { |
|
| 376 | + if (!$lien) { |
|
| 377 | + $lien = traiter_lien_implicite("$type$id", '', 'tout', $connect); |
|
| 378 | + } |
|
| 379 | + if ($lien) { |
|
| 380 | + $modele = '<a href="' |
|
| 381 | + . $lien['url'] |
|
| 382 | + . '" class="spip_modele' |
|
| 383 | + . '">' |
|
| 384 | + . sinon($lien['titre'], _T('ecrire:info_sans_titre')) |
|
| 385 | + . '</a>'; |
|
| 386 | + } else { |
|
| 387 | + $modele = ''; |
|
| 388 | + if (test_espace_prive()) { |
|
| 389 | + $modele = entites_html(substr($texte, $a, $cherche)); |
|
| 390 | + if (!is_null($liens)) { |
|
| 391 | + $modele = '<pre>' . str_replace($liens[0], $liens[1], $modele) . '</pre>'; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + // le remplacer dans le texte |
|
| 397 | + if ($modele !== false) { |
|
| 398 | + $modele = protege_js_modeles($modele); |
|
| 399 | + if ($wrap_embed_html) { |
|
| 400 | + $modele = $wrap_embed_html($mod, $modele); |
|
| 401 | + } |
|
| 402 | + $rempl = code_echappement($modele, $echap); |
|
| 403 | + $texte = substr($texte, 0, $a) |
|
| 404 | + . $rempl |
|
| 405 | + . substr($texte, $a + $cherche); |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + // hack pour tout l'espace prive |
|
| 410 | + if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) { |
|
| 411 | + foreach ($doublons ? $doublons : ['documents' => ['doc', 'emb', 'img']] as $quoi => $modeles) { |
|
| 412 | + if (in_array($type, $modeles)) { |
|
| 413 | + $GLOBALS["doublons_{$quoi}_inclus"][] = $id; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + |
|
| 420 | + return $texte; |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | // |
@@ -425,15 +425,15 @@ discard block |
||
| 425 | 425 | // |
| 426 | 426 | // https://code.spip.net/@traiter_raccourci_ancre |
| 427 | 427 | function traiter_raccourci_ancre($letexte) { |
| 428 | - return $letexte; |
|
| 428 | + return $letexte; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | // https://code.spip.net/@traiter_raccourci_glossaire |
| 432 | 432 | function traiter_raccourci_glossaire($texte) { |
| 433 | - return $texte; |
|
| 433 | + return $texte; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // https://code.spip.net/@glossaire_std |
| 437 | 437 | function glossaire_std($terme) { |
| 438 | - return $terme; |
|
| 438 | + return $terme; |
|
| 439 | 439 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | return $r ? $r : traiter_lien_explicite($ref, $texte, $pour, $connect, $echappe_typo); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | -define('_EXTRAIRE_LIEN', ',^\s*(?:' . _PROTOCOLES_STD . '):?/?/?\s*$,iS'); |
|
| 105 | +define('_EXTRAIRE_LIEN', ',^\s*(?:'._PROTOCOLES_STD.'):?/?/?\s*$,iS'); |
|
| 106 | 106 | |
| 107 | 107 | // https://code.spip.net/@traiter_lien_explicite |
| 108 | 108 | function traiter_lien_explicite($ref, $texte = '', $pour = 'url', string $connect = '', $echappe_typo = true) { |
@@ -119,19 +119,19 @@ discard block |
||
| 119 | 119 | $lien_court = charger_fonction('lien_court', 'inc'); |
| 120 | 120 | $texte = $lien_court($texte); |
| 121 | 121 | if ($echappe_typo) { |
| 122 | - $texte = '<html>' . quote_amp($texte) . '</html>'; |
|
| 122 | + $texte = '<html>'.quote_amp($texte).'</html>'; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // petites corrections d'URL |
| 127 | 127 | if (preg_match('/^www\.[^@]+$/S', $lien)) { |
| 128 | - $lien = 'http://' . $lien; |
|
| 128 | + $lien = 'http://'.$lien; |
|
| 129 | 129 | } else { |
| 130 | 130 | if (strpos($lien, '@') && email_valide($lien)) { |
| 131 | 131 | if (!$texte) { |
| 132 | 132 | $texte = $lien; |
| 133 | 133 | } |
| 134 | - $lien = 'mailto:' . $lien; |
|
| 134 | + $lien = 'mailto:'.$lien; |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, string $connect = '') { |
| 150 | - if (function_exists($f = 'glossaire_' . $ancre)) { |
|
| 150 | + if (function_exists($f = 'glossaire_'.$ancre)) { |
|
| 151 | 151 | $url = $f($texte, $id); |
| 152 | 152 | } else { |
| 153 | 153 | $url = glossaire_std($texte); |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | if (!($match = typer_raccourci($ref))) { |
| 162 | 162 | return false; |
| 163 | 163 | } |
| 164 | - @list($type, , $id, , $args, , $ancre) = $match; |
|
| 164 | + @list($type,, $id,, $args,, $ancre) = $match; |
|
| 165 | 165 | // attention dans le cas des sites le lien doit pointer non pas sur |
| 166 | 166 | // la page locale du site, mais directement sur le site lui-meme |
| 167 | 167 | if ($f = charger_fonction("implicite_$type", 'liens', true)) { |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $r['titre'] = $texte; |
| 189 | 189 | } |
| 190 | 190 | if (!@$r['titre']) { |
| 191 | - $r['titre'] = _T($type) . " $id"; |
|
| 191 | + $r['titre'] = _T($type)." $id"; |
|
| 192 | 192 | } |
| 193 | 193 | if ($pour == 'titre') { |
| 194 | 194 | return $r['titre']; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | and $mime = sql_getfetsel( |
| 202 | 202 | 'mime_type', |
| 203 | 203 | 'spip_types_documents', |
| 204 | - 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')', |
|
| 204 | + 'extension IN ('.sql_get_select('extension', 'spip_documents', 'id_document='.sql_quote($id)).')', |
|
| 205 | 205 | '', |
| 206 | 206 | '', |
| 207 | 207 | '', |
@@ -304,11 +304,11 @@ discard block |
||
| 304 | 304 | '(<([a-z_-]{3,})' # <modele |
| 305 | 305 | . '\s*([0-9]*)\s*' # id |
| 306 | 306 | . '([|](?:<[^<>]*>|[^>])*?)?' # |arguments (y compris des tags <...>) |
| 307 | - . '\s*/?' . '>)' # fin du modele > |
|
| 307 | + . '\s*/?'.'>)' # fin du modele > |
|
| 308 | 308 | . '\s*(<\/a>)?' # eventuel </a> |
| 309 | 309 | ); |
| 310 | 310 | |
| 311 | -define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS'); |
|
| 311 | +define('_RACCOURCI_MODELE_DEBUT', '@^'._RACCOURCI_MODELE.'@isS'); |
|
| 312 | 312 | |
| 313 | 313 | // https://code.spip.net/@traiter_modeles |
| 314 | 314 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', $liens = null, $env = []) { |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | if (test_espace_prive()) { |
| 389 | 389 | $modele = entites_html(substr($texte, $a, $cherche)); |
| 390 | 390 | if (!is_null($liens)) { |
| 391 | - $modele = '<pre>' . str_replace($liens[0], $liens[1], $modele) . '</pre>'; |
|
| 391 | + $modele = '<pre>'.str_replace($liens[0], $liens[1], $modele).'</pre>'; |
|
| 392 | 392 | } |
| 393 | 393 | } |
| 394 | 394 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV['HTTP_HOST']) ? $_ENV['HTTP_HOST'] : '')); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV['HTTP_HOST']) ? $_ENV['HTTP_HOST'] : '')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = []; |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, '.php') !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, '.php') !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -330,25 +330,25 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - if ( |
|
| 338 | - $force |
|
| 339 | - or !file_exists($fichier) |
|
| 340 | - or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | - ) { |
|
| 342 | - if ($use_copy) { |
|
| 343 | - @copy($fichier_tmp, $fichier); |
|
| 344 | - } |
|
| 345 | - else { |
|
| 346 | - @rename($fichier_tmp, $fichier); |
|
| 347 | - } |
|
| 348 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | - clearstatcache(true, $fichier); |
|
| 350 | - } |
|
| 351 | - return true; |
|
| 333 | + $fichier_tmp = $fichier . '.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + if ( |
|
| 338 | + $force |
|
| 339 | + or !file_exists($fichier) |
|
| 340 | + or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | + ) { |
|
| 342 | + if ($use_copy) { |
|
| 343 | + @copy($fichier_tmp, $fichier); |
|
| 344 | + } |
|
| 345 | + else { |
|
| 346 | + @rename($fichier_tmp, $fichier); |
|
| 347 | + } |
|
| 348 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | + clearstatcache(true, $fichier); |
|
| 350 | + } |
|
| 351 | + return true; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -369,11 +369,11 @@ discard block |
||
| 369 | 369 | * true si l'opération a réussie, false sinon. |
| 370 | 370 | */ |
| 371 | 371 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 372 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | - } |
|
| 372 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | + $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $res; |
|
| 376 | + return $res; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * Chemin du fichier |
| 389 | 389 | **/ |
| 390 | 390 | function raler_fichier($fichier) { |
| 391 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | - spip_initialisation_suite(); |
|
| 393 | - } |
|
| 394 | - include_spip('inc/minipres'); |
|
| 395 | - $dir = dirname($fichier); |
|
| 396 | - http_response_code(401); |
|
| 397 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | - . " <a href='" |
|
| 400 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | - . "'>" |
|
| 402 | - . _T('texte_inc_meta_2') |
|
| 403 | - . '</a> ' |
|
| 404 | - . _T( |
|
| 405 | - 'texte_inc_meta_3', |
|
| 406 | - ['repertoire' => joli_repertoire($dir)] |
|
| 407 | - ) |
|
| 408 | - . "</h4>\n"); |
|
| 409 | - exit; |
|
| 391 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | + spip_initialisation_suite(); |
|
| 393 | + } |
|
| 394 | + include_spip('inc/minipres'); |
|
| 395 | + $dir = dirname($fichier); |
|
| 396 | + http_response_code(401); |
|
| 397 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | + . " <a href='" |
|
| 400 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | + . "'>" |
|
| 402 | + . _T('texte_inc_meta_2') |
|
| 403 | + . '</a> ' |
|
| 404 | + . _T( |
|
| 405 | + 'texte_inc_meta_3', |
|
| 406 | + ['repertoire' => joli_repertoire($dir)] |
|
| 407 | + ) |
|
| 408 | + . "</h4>\n"); |
|
| 409 | + exit; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | * - true si récent, false sinon |
| 422 | 422 | */ |
| 423 | 423 | function jeune_fichier($fichier, $n) { |
| 424 | - if (!file_exists($fichier)) { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - if (!$c = @filemtime($fichier)) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return (time() - $n <= $c); |
|
| 424 | + if (!file_exists($fichier)) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + if (!$c = @filemtime($fichier)) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return (time() - $n <= $c); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -443,22 +443,22 @@ discard block |
||
| 443 | 443 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 444 | 444 | */ |
| 445 | 445 | function supprimer_fichier($fichier, $lock = true) { |
| 446 | - if (!@file_exists($fichier)) { |
|
| 447 | - return true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - if ($lock) { |
|
| 451 | - // verrouiller le fichier destination |
|
| 452 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | - return false; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - // liberer le verrou |
|
| 457 | - spip_fclose_unlock($fp); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - // supprimer |
|
| 461 | - return @unlink($fichier); |
|
| 446 | + if (!@file_exists($fichier)) { |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + if ($lock) { |
|
| 451 | + // verrouiller le fichier destination |
|
| 452 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | + return false; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + // liberer le verrou |
|
| 457 | + spip_fclose_unlock($fp); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + // supprimer |
|
| 461 | + return @unlink($fichier); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -468,12 +468,12 @@ discard block |
||
| 468 | 468 | * Chemin du fichier |
| 469 | 469 | */ |
| 470 | 470 | function spip_unlink($f) { |
| 471 | - if (!is_dir($f)) { |
|
| 472 | - supprimer_fichier($f, false); |
|
| 473 | - } else { |
|
| 474 | - @unlink("$f/.ok"); |
|
| 475 | - @rmdir($f); |
|
| 476 | - } |
|
| 471 | + if (!is_dir($f)) { |
|
| 472 | + supprimer_fichier($f, false); |
|
| 473 | + } else { |
|
| 474 | + @unlink("$f/.ok"); |
|
| 475 | + @rmdir($f); |
|
| 476 | + } |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -487,26 +487,26 @@ discard block |
||
| 487 | 487 | * The absolute path of the PHP file to invalidate. |
| 488 | 488 | */ |
| 489 | 489 | function spip_clear_opcode_cache($filepath) { |
| 490 | - clearstatcache(true, $filepath); |
|
| 491 | - |
|
| 492 | - // Zend OPcache |
|
| 493 | - if (function_exists('opcache_invalidate')) { |
|
| 494 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | - // si l'invalidation a echoue lever un flag |
|
| 496 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | - } |
|
| 499 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | - } |
|
| 503 | - // APC. |
|
| 504 | - if (function_exists('apc_delete_file')) { |
|
| 505 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | - // not compiled yet. |
|
| 507 | - // @see http://php.net/apc-delete-file |
|
| 508 | - @apc_delete_file($filepath); |
|
| 509 | - } |
|
| 490 | + clearstatcache(true, $filepath); |
|
| 491 | + |
|
| 492 | + // Zend OPcache |
|
| 493 | + if (function_exists('opcache_invalidate')) { |
|
| 494 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | + // si l'invalidation a echoue lever un flag |
|
| 496 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | + } |
|
| 499 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | + } |
|
| 503 | + // APC. |
|
| 504 | + if (function_exists('apc_delete_file')) { |
|
| 505 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | + // not compiled yet. |
|
| 507 | + // @see http://php.net/apc-delete-file |
|
| 508 | + @apc_delete_file($filepath); |
|
| 509 | + } |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -529,25 +529,25 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | */ |
| 531 | 531 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 532 | - if ( |
|
| 533 | - function_exists('opcache_get_configuration') |
|
| 534 | - and @ini_get('opcache.enable') |
|
| 535 | - and @ini_get('opcache.validate_timestamps') |
|
| 536 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | - ) { |
|
| 539 | - $wait = $duree + 1; |
|
| 540 | - if ($timestamp) { |
|
| 541 | - $wait -= (time() - $timestamp); |
|
| 542 | - if ($wait < 0) { |
|
| 543 | - $wait = 0; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | - if ($wait) { |
|
| 548 | - sleep($duree + 1); |
|
| 549 | - } |
|
| 550 | - } |
|
| 532 | + if ( |
|
| 533 | + function_exists('opcache_get_configuration') |
|
| 534 | + and @ini_get('opcache.enable') |
|
| 535 | + and @ini_get('opcache.validate_timestamps') |
|
| 536 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | + ) { |
|
| 539 | + $wait = $duree + 1; |
|
| 540 | + if ($timestamp) { |
|
| 541 | + $wait -= (time() - $timestamp); |
|
| 542 | + if ($wait < 0) { |
|
| 543 | + $wait = 0; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | + if ($wait) { |
|
| 548 | + sleep($duree + 1); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -560,26 +560,26 @@ discard block |
||
| 560 | 560 | * @return bool Suppression reussie. |
| 561 | 561 | */ |
| 562 | 562 | function supprimer_repertoire($dir) { |
| 563 | - if (!file_exists($dir)) { |
|
| 564 | - return true; |
|
| 565 | - } |
|
| 566 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | - return @unlink($dir); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - foreach (scandir($dir) as $item) { |
|
| 571 | - if ($item == '.' || $item == '..') { |
|
| 572 | - continue; |
|
| 573 | - } |
|
| 574 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | - @chmod($dir . '/' . $item, 0777); |
|
| 576 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | - return false; |
|
| 578 | - } |
|
| 579 | - }; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - return @rmdir($dir); |
|
| 563 | + if (!file_exists($dir)) { |
|
| 564 | + return true; |
|
| 565 | + } |
|
| 566 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | + return @unlink($dir); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + foreach (scandir($dir) as $item) { |
|
| 571 | + if ($item == '.' || $item == '..') { |
|
| 572 | + continue; |
|
| 573 | + } |
|
| 574 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | + @chmod($dir . '/' . $item, 0777); |
|
| 576 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | + return false; |
|
| 578 | + } |
|
| 579 | + }; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + return @rmdir($dir); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
@@ -608,57 +608,57 @@ discard block |
||
| 608 | 608 | * Chemin du répertoire créé. |
| 609 | 609 | **/ |
| 610 | 610 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 611 | - static $dirs = []; |
|
| 612 | - |
|
| 613 | - $base = str_replace('//', '/', $base); |
|
| 614 | - |
|
| 615 | - # suppr le dernier caractere si c'est un / |
|
| 616 | - $base = rtrim($base, '/'); |
|
| 617 | - |
|
| 618 | - if (!strlen($subdir)) { |
|
| 619 | - $n = strrpos($base, '/'); |
|
| 620 | - if ($n === false) { |
|
| 621 | - return $nobase ? '' : ($base . '/'); |
|
| 622 | - } |
|
| 623 | - $subdir = substr($base, $n + 1); |
|
| 624 | - $base = substr($base, 0, $n + 1); |
|
| 625 | - } else { |
|
| 626 | - $base .= '/'; |
|
| 627 | - $subdir = str_replace('/', '', $subdir); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - $baseaff = $nobase ? '' : $base; |
|
| 631 | - if (isset($dirs[$base . $subdir])) { |
|
| 632 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | - |
|
| 637 | - if (file_exists("$path/.ok")) { |
|
| 638 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - @mkdir($path, _SPIP_CHMOD); |
|
| 642 | - @chmod($path, _SPIP_CHMOD); |
|
| 643 | - |
|
| 644 | - if (is_dir($path) && is_writable($path)) { |
|
| 645 | - @touch("$path/.ok"); |
|
| 646 | - spip_log("creation $base$subdir/"); |
|
| 647 | - |
|
| 648 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | - spip_log("echec creation $base${subdir}"); |
|
| 654 | - if ($tantpis) { |
|
| 655 | - return ''; |
|
| 656 | - } |
|
| 657 | - if (!_DIR_RESTREINT) { |
|
| 658 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | - } |
|
| 660 | - $base .= $subdir; |
|
| 661 | - raler_fichier($base . '/.ok'); |
|
| 611 | + static $dirs = []; |
|
| 612 | + |
|
| 613 | + $base = str_replace('//', '/', $base); |
|
| 614 | + |
|
| 615 | + # suppr le dernier caractere si c'est un / |
|
| 616 | + $base = rtrim($base, '/'); |
|
| 617 | + |
|
| 618 | + if (!strlen($subdir)) { |
|
| 619 | + $n = strrpos($base, '/'); |
|
| 620 | + if ($n === false) { |
|
| 621 | + return $nobase ? '' : ($base . '/'); |
|
| 622 | + } |
|
| 623 | + $subdir = substr($base, $n + 1); |
|
| 624 | + $base = substr($base, 0, $n + 1); |
|
| 625 | + } else { |
|
| 626 | + $base .= '/'; |
|
| 627 | + $subdir = str_replace('/', '', $subdir); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + $baseaff = $nobase ? '' : $base; |
|
| 631 | + if (isset($dirs[$base . $subdir])) { |
|
| 632 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | + |
|
| 637 | + if (file_exists("$path/.ok")) { |
|
| 638 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + @mkdir($path, _SPIP_CHMOD); |
|
| 642 | + @chmod($path, _SPIP_CHMOD); |
|
| 643 | + |
|
| 644 | + if (is_dir($path) && is_writable($path)) { |
|
| 645 | + @touch("$path/.ok"); |
|
| 646 | + spip_log("creation $base$subdir/"); |
|
| 647 | + |
|
| 648 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | + spip_log("echec creation $base${subdir}"); |
|
| 654 | + if ($tantpis) { |
|
| 655 | + return ''; |
|
| 656 | + } |
|
| 657 | + if (!_DIR_RESTREINT) { |
|
| 658 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | + } |
|
| 660 | + $base .= $subdir; |
|
| 661 | + raler_fichier($base . '/.ok'); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | |
@@ -691,56 +691,56 @@ discard block |
||
| 691 | 691 | * Chemins des fichiers trouvés. |
| 692 | 692 | **/ |
| 693 | 693 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 694 | - $nbfiles = 0; |
|
| 695 | - if ($pattern == -1) { |
|
| 696 | - $pattern = "^$dir"; |
|
| 697 | - } |
|
| 698 | - $fichiers = []; |
|
| 699 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | - if ($dir == '') { |
|
| 703 | - $dir = '.'; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | - if ( |
|
| 709 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | - and $f != 'CVS' |
|
| 711 | - and $f != 'remove.txt' |
|
| 712 | - and is_readable($f = "$dir/$f") |
|
| 713 | - ) { |
|
| 714 | - if (is_file($f)) { |
|
| 715 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | - $fichiers[] = $f; |
|
| 717 | - $nbfiles++; |
|
| 718 | - } |
|
| 719 | - } else { |
|
| 720 | - if (is_dir($f) and is_array($recurs)) { |
|
| 721 | - $rp = @realpath($f); |
|
| 722 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | - $rp = $f; |
|
| 724 | - } # realpath n'est peut etre pas autorise |
|
| 725 | - if (!isset($recurs[$rp])) { |
|
| 726 | - $recurs[$rp] = true; |
|
| 727 | - $beginning = $fichiers; |
|
| 728 | - $end = preg_files( |
|
| 729 | - "$f/", |
|
| 730 | - $pattern, |
|
| 731 | - $maxfiles - $nbfiles, |
|
| 732 | - $recurs |
|
| 733 | - ); |
|
| 734 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | - $nbfiles = count($fichiers); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - closedir($d); |
|
| 742 | - } |
|
| 743 | - sort($fichiers); |
|
| 744 | - |
|
| 745 | - return $fichiers; |
|
| 694 | + $nbfiles = 0; |
|
| 695 | + if ($pattern == -1) { |
|
| 696 | + $pattern = "^$dir"; |
|
| 697 | + } |
|
| 698 | + $fichiers = []; |
|
| 699 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | + if ($dir == '') { |
|
| 703 | + $dir = '.'; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | + if ( |
|
| 709 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | + and $f != 'CVS' |
|
| 711 | + and $f != 'remove.txt' |
|
| 712 | + and is_readable($f = "$dir/$f") |
|
| 713 | + ) { |
|
| 714 | + if (is_file($f)) { |
|
| 715 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | + $fichiers[] = $f; |
|
| 717 | + $nbfiles++; |
|
| 718 | + } |
|
| 719 | + } else { |
|
| 720 | + if (is_dir($f) and is_array($recurs)) { |
|
| 721 | + $rp = @realpath($f); |
|
| 722 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | + $rp = $f; |
|
| 724 | + } # realpath n'est peut etre pas autorise |
|
| 725 | + if (!isset($recurs[$rp])) { |
|
| 726 | + $recurs[$rp] = true; |
|
| 727 | + $beginning = $fichiers; |
|
| 728 | + $end = preg_files( |
|
| 729 | + "$f/", |
|
| 730 | + $pattern, |
|
| 731 | + $maxfiles - $nbfiles, |
|
| 732 | + $recurs |
|
| 733 | + ); |
|
| 734 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | + $nbfiles = count($fichiers); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + closedir($d); |
|
| 742 | + } |
|
| 743 | + sort($fichiers); |
|
| 744 | + |
|
| 745 | + return $fichiers; |
|
| 746 | 746 | } |
@@ -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,66 +48,66 @@ 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 = []; |
|
| 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 ( |
|
| 82 | - !$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 83 | - // si le fichier truc/machin/nom.php n'existe pas, |
|
| 84 | - // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 85 | - and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 86 | - ) { |
|
| 87 | - include_spip(substr($dossier, 0, -1)); |
|
| 88 | - } |
|
| 89 | - if (function_exists($f)) { |
|
| 90 | - return $f; |
|
| 91 | - } |
|
| 92 | - if (function_exists($g)) { |
|
| 93 | - return $g; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ($continue) { |
|
| 97 | - return $echecs[$f] = false; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Echec : message d'erreur |
|
| 101 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 102 | - ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 103 | - |
|
| 104 | - include_spip('inc/minipres'); |
|
| 105 | - echo minipres( |
|
| 106 | - _T('forum_titre_erreur'), |
|
| 107 | - _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']), |
|
| 108 | - ['all_inline' => true,'status' => 404] |
|
| 109 | - ); |
|
| 110 | - exit; |
|
| 51 | + static $echecs = []; |
|
| 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 ( |
|
| 82 | + !$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 83 | + // si le fichier truc/machin/nom.php n'existe pas, |
|
| 84 | + // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 85 | + and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 86 | + ) { |
|
| 87 | + include_spip(substr($dossier, 0, -1)); |
|
| 88 | + } |
|
| 89 | + if (function_exists($f)) { |
|
| 90 | + return $f; |
|
| 91 | + } |
|
| 92 | + if (function_exists($g)) { |
|
| 93 | + return $g; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ($continue) { |
|
| 97 | + return $echecs[$f] = false; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Echec : message d'erreur |
|
| 101 | + spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 102 | + ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 103 | + |
|
| 104 | + include_spip('inc/minipres'); |
|
| 105 | + echo minipres( |
|
| 106 | + _T('forum_titre_erreur'), |
|
| 107 | + _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']), |
|
| 108 | + ['all_inline' => true,'status' => 404] |
|
| 109 | + ); |
|
| 110 | + exit; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -117,17 +117,17 @@ discard block |
||
| 117 | 117 | * @return bool |
| 118 | 118 | */ |
| 119 | 119 | function include_once_check($file) { |
| 120 | - if (file_exists($file)) { |
|
| 121 | - include_once $file; |
|
| 120 | + if (file_exists($file)) { |
|
| 121 | + include_once $file; |
|
| 122 | 122 | |
| 123 | - return true; |
|
| 124 | - } |
|
| 125 | - $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 126 | - $crash = ($crash ? $crash : []); |
|
| 127 | - $crash[$file] = true; |
|
| 128 | - ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 123 | + return true; |
|
| 124 | + } |
|
| 125 | + $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 126 | + $crash = ($crash ? $crash : []); |
|
| 127 | + $crash[$file] = true; |
|
| 128 | + ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 129 | 129 | |
| 130 | - return false; |
|
| 130 | + return false; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * - string : chemin du fichier trouvé |
| 152 | 152 | **/ |
| 153 | 153 | function include_spip($f, $include = true) { |
| 154 | - return find_in_path($f . '.php', '', $include); |
|
| 154 | + return find_in_path($f . '.php', '', $include); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * - string : chemin du fichier trouvé |
| 172 | 172 | **/ |
| 173 | 173 | function require_spip($f) { |
| 174 | - return find_in_path($f . '.php', '', 'required'); |
|
| 174 | + return find_in_path($f . '.php', '', 'required'); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -180,27 +180,27 @@ discard block |
||
| 180 | 180 | * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis |
| 181 | 181 | */ |
| 182 | 182 | function include_fichiers_fonctions() { |
| 183 | - static $done = false; |
|
| 184 | - if (!$done) { |
|
| 185 | - include_spip('inc/lang'); |
|
| 186 | - |
|
| 187 | - // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 188 | - // donc il faut l'inclure "en globals" |
|
| 189 | - if ($f = find_in_path('mes_fonctions.php')) { |
|
| 190 | - global $dossier_squelettes; |
|
| 191 | - include_once(_ROOT_CWD . $f); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 195 | - // chargement optimise precompile |
|
| 196 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 197 | - } |
|
| 198 | - if (test_espace_prive()) { |
|
| 199 | - include_spip('inc/filtres_ecrire'); |
|
| 200 | - } |
|
| 201 | - include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 202 | - $done = true; |
|
| 203 | - } |
|
| 183 | + static $done = false; |
|
| 184 | + if (!$done) { |
|
| 185 | + include_spip('inc/lang'); |
|
| 186 | + |
|
| 187 | + // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 188 | + // donc il faut l'inclure "en globals" |
|
| 189 | + if ($f = find_in_path('mes_fonctions.php')) { |
|
| 190 | + global $dossier_squelettes; |
|
| 191 | + include_once(_ROOT_CWD . $f); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 195 | + // chargement optimise precompile |
|
| 196 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 197 | + } |
|
| 198 | + if (test_espace_prive()) { |
|
| 199 | + include_spip('inc/filtres_ecrire'); |
|
| 200 | + } |
|
| 201 | + include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 202 | + $done = true; |
|
| 203 | + } |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -226,23 +226,23 @@ discard block |
||
| 226 | 226 | * Les paramètres du pipeline modifiés |
| 227 | 227 | **/ |
| 228 | 228 | function minipipe($fonc, &$val) { |
| 229 | - // fonction |
|
| 230 | - if (function_exists($fonc)) { |
|
| 231 | - $val = call_user_func($fonc, $val); |
|
| 232 | - } // Class::Methode |
|
| 233 | - else { |
|
| 234 | - if ( |
|
| 235 | - preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 236 | - and $methode = [$regs[1], $regs[2]] |
|
| 237 | - and is_callable($methode) |
|
| 238 | - ) { |
|
| 239 | - $val = call_user_func($methode, $val); |
|
| 240 | - } else { |
|
| 241 | - spip_log("Erreur - '$fonc' non definie !"); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - return $val; |
|
| 229 | + // fonction |
|
| 230 | + if (function_exists($fonc)) { |
|
| 231 | + $val = call_user_func($fonc, $val); |
|
| 232 | + } // Class::Methode |
|
| 233 | + else { |
|
| 234 | + if ( |
|
| 235 | + preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 236 | + and $methode = [$regs[1], $regs[2]] |
|
| 237 | + and is_callable($methode) |
|
| 238 | + ) { |
|
| 239 | + $val = call_user_func($methode, $val); |
|
| 240 | + } else { |
|
| 241 | + spip_log("Erreur - '$fonc' non definie !"); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + return $val; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -273,46 +273,46 @@ discard block |
||
| 273 | 273 | * Résultat |
| 274 | 274 | */ |
| 275 | 275 | function pipeline($action, $val = null) { |
| 276 | - static $charger; |
|
| 277 | - |
|
| 278 | - // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 279 | - if (!$charger) { |
|
| 280 | - if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 281 | - include_spip('inc/plugin'); |
|
| 282 | - // generer les fichiers php precompiles |
|
| 283 | - // de chargement des plugins et des pipelines |
|
| 284 | - actualise_plugins_actifs(); |
|
| 285 | - if (!($ok = @is_readable($charger))) { |
|
| 286 | - spip_log("fichier $charger pas cree"); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - if ($ok) { |
|
| 291 | - include_once $charger; |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // appliquer notre fonction si elle existe |
|
| 296 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 297 | - if (function_exists($fonc)) { |
|
| 298 | - $val = $fonc($val); |
|
| 299 | - } // plantage ? |
|
| 300 | - else { |
|
| 301 | - spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // si le flux est une table avec 2 cle args&data |
|
| 305 | - // on ne ressort du pipe que les donnees dans 'data' |
|
| 306 | - // array_key_exists pour php 4.1.0 |
|
| 307 | - if ( |
|
| 308 | - is_array($val) |
|
| 309 | - and count($val) == 2 |
|
| 310 | - and (array_key_exists('data', $val)) |
|
| 311 | - ) { |
|
| 312 | - $val = $val['data']; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - return $val; |
|
| 276 | + static $charger; |
|
| 277 | + |
|
| 278 | + // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 279 | + if (!$charger) { |
|
| 280 | + if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 281 | + include_spip('inc/plugin'); |
|
| 282 | + // generer les fichiers php precompiles |
|
| 283 | + // de chargement des plugins et des pipelines |
|
| 284 | + actualise_plugins_actifs(); |
|
| 285 | + if (!($ok = @is_readable($charger))) { |
|
| 286 | + spip_log("fichier $charger pas cree"); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + if ($ok) { |
|
| 291 | + include_once $charger; |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // appliquer notre fonction si elle existe |
|
| 296 | + $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 297 | + if (function_exists($fonc)) { |
|
| 298 | + $val = $fonc($val); |
|
| 299 | + } // plantage ? |
|
| 300 | + else { |
|
| 301 | + spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // si le flux est une table avec 2 cle args&data |
|
| 305 | + // on ne ressort du pipe que les donnees dans 'data' |
|
| 306 | + // array_key_exists pour php 4.1.0 |
|
| 307 | + if ( |
|
| 308 | + is_array($val) |
|
| 309 | + and count($val) == 2 |
|
| 310 | + and (array_key_exists('data', $val)) |
|
| 311 | + ) { |
|
| 312 | + $val = $val['data']; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + return $val; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -356,38 +356,38 @@ discard block |
||
| 356 | 356 | * paramètre est planté pour cause de compatibilité ascendante. |
| 357 | 357 | */ |
| 358 | 358 | function spip_log($message = null, $name = null) { |
| 359 | - static $pre = []; |
|
| 360 | - static $log; |
|
| 361 | - preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 362 | - if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 363 | - $logname = null; |
|
| 364 | - } |
|
| 365 | - if (!isset($regs[2])) { |
|
| 366 | - $niveau = _LOG_INFO; |
|
| 367 | - } |
|
| 368 | - else { |
|
| 369 | - $niveau = intval($regs[2]); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 373 | - if (!$pre) { |
|
| 374 | - $pre = [ |
|
| 375 | - _LOG_HS => 'HS:', |
|
| 376 | - _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 377 | - _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 378 | - _LOG_ERREUR => 'ERREUR:', |
|
| 379 | - _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 380 | - _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 381 | - _LOG_INFO => 'info:', |
|
| 382 | - _LOG_DEBUG => 'debug:' |
|
| 383 | - ]; |
|
| 384 | - $log = charger_fonction('log', 'inc'); |
|
| 385 | - } |
|
| 386 | - if (!is_string($message)) { |
|
| 387 | - $message = print_r($message, true); |
|
| 388 | - } |
|
| 389 | - $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 390 | - } |
|
| 359 | + static $pre = []; |
|
| 360 | + static $log; |
|
| 361 | + preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 362 | + if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 363 | + $logname = null; |
|
| 364 | + } |
|
| 365 | + if (!isset($regs[2])) { |
|
| 366 | + $niveau = _LOG_INFO; |
|
| 367 | + } |
|
| 368 | + else { |
|
| 369 | + $niveau = intval($regs[2]); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 373 | + if (!$pre) { |
|
| 374 | + $pre = [ |
|
| 375 | + _LOG_HS => 'HS:', |
|
| 376 | + _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 377 | + _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 378 | + _LOG_ERREUR => 'ERREUR:', |
|
| 379 | + _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 380 | + _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 381 | + _LOG_INFO => 'info:', |
|
| 382 | + _LOG_DEBUG => 'debug:' |
|
| 383 | + ]; |
|
| 384 | + $log = charger_fonction('log', 'inc'); |
|
| 385 | + } |
|
| 386 | + if (!is_string($message)) { |
|
| 387 | + $message = print_r($message, true); |
|
| 388 | + } |
|
| 389 | + $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 390 | + } |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | /** |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | * @param array $opt Tableau d'options |
| 399 | 399 | **/ |
| 400 | 400 | function journal($phrase, $opt = []) { |
| 401 | - $journal = charger_fonction('journal', 'inc'); |
|
| 402 | - $journal($phrase, $opt); |
|
| 401 | + $journal = charger_fonction('journal', 'inc'); |
|
| 402 | + $journal($phrase, $opt); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -418,37 +418,37 @@ discard block |
||
| 418 | 418 | **/ |
| 419 | 419 | function _request($var, $c = false) { |
| 420 | 420 | |
| 421 | - if (is_array($c)) { |
|
| 422 | - return isset($c[$var]) ? $c[$var] : null; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - if (isset($_GET[$var])) { |
|
| 426 | - $a = $_GET[$var]; |
|
| 427 | - } elseif (isset($_POST[$var])) { |
|
| 428 | - $a = $_POST[$var]; |
|
| 429 | - } else { |
|
| 430 | - return null; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - // Si on est en ajax et en POST tout a ete encode |
|
| 434 | - // via encodeURIComponent, il faut donc repasser |
|
| 435 | - // dans le charset local... |
|
| 436 | - if ( |
|
| 437 | - defined('_AJAX') |
|
| 438 | - and _AJAX |
|
| 439 | - and isset($GLOBALS['meta']['charset']) |
|
| 440 | - and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 441 | - and is_string($a) |
|
| 442 | - // check rapide mais pas fiable |
|
| 443 | - and preg_match(',[\x80-\xFF],', $a) |
|
| 444 | - // check fiable |
|
| 445 | - and include_spip('inc/charsets') |
|
| 446 | - and is_utf8($a) |
|
| 447 | - ) { |
|
| 448 | - return importer_charset($a, 'utf-8'); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - return $a; |
|
| 421 | + if (is_array($c)) { |
|
| 422 | + return isset($c[$var]) ? $c[$var] : null; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + if (isset($_GET[$var])) { |
|
| 426 | + $a = $_GET[$var]; |
|
| 427 | + } elseif (isset($_POST[$var])) { |
|
| 428 | + $a = $_POST[$var]; |
|
| 429 | + } else { |
|
| 430 | + return null; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + // Si on est en ajax et en POST tout a ete encode |
|
| 434 | + // via encodeURIComponent, il faut donc repasser |
|
| 435 | + // dans le charset local... |
|
| 436 | + if ( |
|
| 437 | + defined('_AJAX') |
|
| 438 | + and _AJAX |
|
| 439 | + and isset($GLOBALS['meta']['charset']) |
|
| 440 | + and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 441 | + and is_string($a) |
|
| 442 | + // check rapide mais pas fiable |
|
| 443 | + and preg_match(',[\x80-\xFF],', $a) |
|
| 444 | + // check fiable |
|
| 445 | + and include_spip('inc/charsets') |
|
| 446 | + and is_utf8($a) |
|
| 447 | + ) { |
|
| 448 | + return importer_charset($a, 'utf-8'); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + return $a; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | |
@@ -466,22 +466,22 @@ discard block |
||
| 466 | 466 | * - false sinon |
| 467 | 467 | **/ |
| 468 | 468 | function set_request($var, $val = null, $c = false) { |
| 469 | - if (is_array($c)) { |
|
| 470 | - unset($c[$var]); |
|
| 471 | - if ($val !== null) { |
|
| 472 | - $c[$var] = $val; |
|
| 473 | - } |
|
| 469 | + if (is_array($c)) { |
|
| 470 | + unset($c[$var]); |
|
| 471 | + if ($val !== null) { |
|
| 472 | + $c[$var] = $val; |
|
| 473 | + } |
|
| 474 | 474 | |
| 475 | - return $c; |
|
| 476 | - } |
|
| 475 | + return $c; |
|
| 476 | + } |
|
| 477 | 477 | |
| 478 | - unset($_GET[$var]); |
|
| 479 | - unset($_POST[$var]); |
|
| 480 | - if ($val !== null) { |
|
| 481 | - $_GET[$var] = $val; |
|
| 482 | - } |
|
| 478 | + unset($_GET[$var]); |
|
| 479 | + unset($_POST[$var]); |
|
| 480 | + if ($val !== null) { |
|
| 481 | + $_GET[$var] = $val; |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | - return false; # n'affecte pas $c |
|
| 484 | + return false; # n'affecte pas $c |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | /** |
@@ -501,25 +501,25 @@ discard block |
||
| 501 | 501 | * @return array|mixed|string |
| 502 | 502 | */ |
| 503 | 503 | function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') { |
| 504 | - if (is_array($value)) { |
|
| 505 | - if ($key == '*') { |
|
| 506 | - $key = array_keys($value); |
|
| 507 | - } |
|
| 508 | - if (!is_array($key)) { |
|
| 509 | - $key = [$key]; |
|
| 510 | - } |
|
| 511 | - foreach ($key as $k) { |
|
| 512 | - if (!empty($value[$k])) { |
|
| 513 | - $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 514 | - } |
|
| 515 | - } |
|
| 516 | - return $value; |
|
| 517 | - } |
|
| 518 | - // si la valeur vient des GET ou POST on la sanitize |
|
| 519 | - if (!empty($value) and $value == _request($key)) { |
|
| 520 | - $value = $sanitize_function($value); |
|
| 521 | - } |
|
| 522 | - return $value; |
|
| 504 | + if (is_array($value)) { |
|
| 505 | + if ($key == '*') { |
|
| 506 | + $key = array_keys($value); |
|
| 507 | + } |
|
| 508 | + if (!is_array($key)) { |
|
| 509 | + $key = [$key]; |
|
| 510 | + } |
|
| 511 | + foreach ($key as $k) { |
|
| 512 | + if (!empty($value[$k])) { |
|
| 513 | + $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 514 | + } |
|
| 515 | + } |
|
| 516 | + return $value; |
|
| 517 | + } |
|
| 518 | + // si la valeur vient des GET ou POST on la sanitize |
|
| 519 | + if (!empty($value) and $value == _request($key)) { |
|
| 520 | + $value = $sanitize_function($value); |
|
| 521 | + } |
|
| 522 | + return $value; |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | /** |
@@ -527,23 +527,22 @@ discard block |
||
| 527 | 527 | * |
| 528 | 528 | * On est sur le web, on exclut certains protocoles, |
| 529 | 529 | * notamment 'file://', 'php://' et d'autres… |
| 530 | - |
|
| 531 | 530 | * @param string $url |
| 532 | 531 | * @return bool |
| 533 | 532 | */ |
| 534 | 533 | function tester_url_absolue($url) { |
| 535 | - $url = trim($url); |
|
| 536 | - if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 537 | - if ( |
|
| 538 | - isset($m[1]) |
|
| 539 | - and $p = strtolower(rtrim($m[1], ':')) |
|
| 540 | - and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 541 | - ) { |
|
| 542 | - return false; |
|
| 543 | - } |
|
| 544 | - return true; |
|
| 545 | - } |
|
| 546 | - return false; |
|
| 534 | + $url = trim($url); |
|
| 535 | + if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 536 | + if ( |
|
| 537 | + isset($m[1]) |
|
| 538 | + and $p = strtolower(rtrim($m[1], ':')) |
|
| 539 | + and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 540 | + ) { |
|
| 541 | + return false; |
|
| 542 | + } |
|
| 543 | + return true; |
|
| 544 | + } |
|
| 545 | + return false; |
|
| 547 | 546 | } |
| 548 | 547 | |
| 549 | 548 | /** |
@@ -565,95 +564,95 @@ discard block |
||
| 565 | 564 | * @return string URL |
| 566 | 565 | */ |
| 567 | 566 | function parametre_url($url, $c, $v = null, $sep = '&') { |
| 568 | - // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 569 | - if (strpos($c, '|') !== false and is_null($v)) { |
|
| 570 | - return null; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // lever l'#ancre |
|
| 574 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 575 | - $url = $r[1]; |
|
| 576 | - $ancre = $r[2]; |
|
| 577 | - } else { |
|
| 578 | - $ancre = ''; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - // eclater |
|
| 582 | - $url = preg_split(',[?]|&|&,', $url); |
|
| 583 | - |
|
| 584 | - // recuperer la base |
|
| 585 | - $a = array_shift($url); |
|
| 586 | - if (!$a) { |
|
| 587 | - $a = './'; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 591 | - $ajouts = array_flip(explode('|', $c)); |
|
| 592 | - $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 593 | - $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 594 | - $v_read = null; |
|
| 595 | - // lire les variables et agir |
|
| 596 | - foreach ($url as $n => $val) { |
|
| 597 | - if (preg_match($regexp, urldecode($val), $r)) { |
|
| 598 | - $r = array_pad($r, 3, null); |
|
| 599 | - if ($v === null) { |
|
| 600 | - // c'est un tableau, on memorise les valeurs |
|
| 601 | - if (substr($r[1], -2) == '[]') { |
|
| 602 | - if (!$v_read) { |
|
| 603 | - $v_read = []; |
|
| 604 | - } |
|
| 605 | - $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 606 | - } // c'est un scalaire, on retourne direct |
|
| 607 | - else { |
|
| 608 | - return $r[2] ? substr($r[2], 1) : ''; |
|
| 609 | - } |
|
| 610 | - } // suppression |
|
| 611 | - elseif (!$testv) { |
|
| 612 | - unset($url[$n]); |
|
| 613 | - } |
|
| 614 | - // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 615 | - // pour un tableau ce sera fait dans la prochaine boucle |
|
| 616 | - elseif (substr($r[1], -2) != '[]') { |
|
| 617 | - $url[$n] = $r[1] . '=' . $u; |
|
| 618 | - unset($ajouts[$r[1]]); |
|
| 619 | - } |
|
| 620 | - // Pour les tableaux on laisse tomber les valeurs de |
|
| 621 | - // départ, on remplira à l'étape suivante |
|
| 622 | - else { |
|
| 623 | - unset($url[$n]); |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // traiter les parametres pas encore trouves |
|
| 629 | - if ( |
|
| 630 | - $v === null |
|
| 631 | - and $args = func_get_args() |
|
| 632 | - and count($args) == 2 |
|
| 633 | - ) { |
|
| 634 | - return $v_read; // rien trouve ou un tableau |
|
| 635 | - } elseif ($testv) { |
|
| 636 | - foreach ($ajouts as $k => $n) { |
|
| 637 | - if (!is_array($v)) { |
|
| 638 | - $url[] = $k . '=' . $u; |
|
| 639 | - } else { |
|
| 640 | - $id = (substr($k, -2) == '[]') ? $k : ($k . '[]'); |
|
| 641 | - foreach ($v as $w) { |
|
| 642 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - // eliminer les vides |
|
| 649 | - $url = array_filter($url); |
|
| 650 | - |
|
| 651 | - // recomposer l'adresse |
|
| 652 | - if ($url) { |
|
| 653 | - $a .= '?' . join($sep, $url); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - return $a . $ancre; |
|
| 567 | + // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 568 | + if (strpos($c, '|') !== false and is_null($v)) { |
|
| 569 | + return null; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // lever l'#ancre |
|
| 573 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 574 | + $url = $r[1]; |
|
| 575 | + $ancre = $r[2]; |
|
| 576 | + } else { |
|
| 577 | + $ancre = ''; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + // eclater |
|
| 581 | + $url = preg_split(',[?]|&|&,', $url); |
|
| 582 | + |
|
| 583 | + // recuperer la base |
|
| 584 | + $a = array_shift($url); |
|
| 585 | + if (!$a) { |
|
| 586 | + $a = './'; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 590 | + $ajouts = array_flip(explode('|', $c)); |
|
| 591 | + $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 592 | + $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 593 | + $v_read = null; |
|
| 594 | + // lire les variables et agir |
|
| 595 | + foreach ($url as $n => $val) { |
|
| 596 | + if (preg_match($regexp, urldecode($val), $r)) { |
|
| 597 | + $r = array_pad($r, 3, null); |
|
| 598 | + if ($v === null) { |
|
| 599 | + // c'est un tableau, on memorise les valeurs |
|
| 600 | + if (substr($r[1], -2) == '[]') { |
|
| 601 | + if (!$v_read) { |
|
| 602 | + $v_read = []; |
|
| 603 | + } |
|
| 604 | + $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 605 | + } // c'est un scalaire, on retourne direct |
|
| 606 | + else { |
|
| 607 | + return $r[2] ? substr($r[2], 1) : ''; |
|
| 608 | + } |
|
| 609 | + } // suppression |
|
| 610 | + elseif (!$testv) { |
|
| 611 | + unset($url[$n]); |
|
| 612 | + } |
|
| 613 | + // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 614 | + // pour un tableau ce sera fait dans la prochaine boucle |
|
| 615 | + elseif (substr($r[1], -2) != '[]') { |
|
| 616 | + $url[$n] = $r[1] . '=' . $u; |
|
| 617 | + unset($ajouts[$r[1]]); |
|
| 618 | + } |
|
| 619 | + // Pour les tableaux on laisse tomber les valeurs de |
|
| 620 | + // départ, on remplira à l'étape suivante |
|
| 621 | + else { |
|
| 622 | + unset($url[$n]); |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + // traiter les parametres pas encore trouves |
|
| 628 | + if ( |
|
| 629 | + $v === null |
|
| 630 | + and $args = func_get_args() |
|
| 631 | + and count($args) == 2 |
|
| 632 | + ) { |
|
| 633 | + return $v_read; // rien trouve ou un tableau |
|
| 634 | + } elseif ($testv) { |
|
| 635 | + foreach ($ajouts as $k => $n) { |
|
| 636 | + if (!is_array($v)) { |
|
| 637 | + $url[] = $k . '=' . $u; |
|
| 638 | + } else { |
|
| 639 | + $id = (substr($k, -2) == '[]') ? $k : ($k . '[]'); |
|
| 640 | + foreach ($v as $w) { |
|
| 641 | + $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + // eliminer les vides |
|
| 648 | + $url = array_filter($url); |
|
| 649 | + |
|
| 650 | + // recomposer l'adresse |
|
| 651 | + if ($url) { |
|
| 652 | + $a .= '?' . join($sep, $url); |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + return $a . $ancre; |
|
| 657 | 656 | } |
| 658 | 657 | |
| 659 | 658 | /** |
@@ -671,21 +670,21 @@ discard block |
||
| 671 | 670 | * @return string |
| 672 | 671 | */ |
| 673 | 672 | function ancre_url($url, $ancre) { |
| 674 | - // lever l'#ancre |
|
| 675 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 676 | - $url = $r[1]; |
|
| 677 | - } |
|
| 678 | - if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 679 | - if (!function_exists('translitteration')) { |
|
| 680 | - include_spip('inc/charsets'); |
|
| 681 | - } |
|
| 682 | - $ancre = preg_replace( |
|
| 683 | - ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 684 | - ['', '-'], |
|
| 685 | - translitteration($ancre) |
|
| 686 | - ); |
|
| 687 | - } |
|
| 688 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 673 | + // lever l'#ancre |
|
| 674 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 675 | + $url = $r[1]; |
|
| 676 | + } |
|
| 677 | + if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 678 | + if (!function_exists('translitteration')) { |
|
| 679 | + include_spip('inc/charsets'); |
|
| 680 | + } |
|
| 681 | + $ancre = preg_replace( |
|
| 682 | + ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 683 | + ['', '-'], |
|
| 684 | + translitteration($ancre) |
|
| 685 | + ); |
|
| 686 | + } |
|
| 687 | + return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 689 | 688 | } |
| 690 | 689 | |
| 691 | 690 | /** |
@@ -695,16 +694,16 @@ discard block |
||
| 695 | 694 | * @return string |
| 696 | 695 | */ |
| 697 | 696 | function nettoyer_uri($reset = null) { |
| 698 | - static $done = false; |
|
| 699 | - static $propre = ''; |
|
| 700 | - if (!is_null($reset)) { |
|
| 701 | - return $propre = $reset; |
|
| 702 | - } |
|
| 703 | - if ($done) { |
|
| 704 | - return $propre; |
|
| 705 | - } |
|
| 706 | - $done = true; |
|
| 707 | - return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 697 | + static $done = false; |
|
| 698 | + static $propre = ''; |
|
| 699 | + if (!is_null($reset)) { |
|
| 700 | + return $propre = $reset; |
|
| 701 | + } |
|
| 702 | + if ($done) { |
|
| 703 | + return $propre; |
|
| 704 | + } |
|
| 705 | + $done = true; |
|
| 706 | + return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 708 | 707 | } |
| 709 | 708 | |
| 710 | 709 | /** |
@@ -716,16 +715,16 @@ discard block |
||
| 716 | 715 | * @return string |
| 717 | 716 | */ |
| 718 | 717 | function nettoyer_uri_var($request_uri) { |
| 719 | - $uri1 = $request_uri; |
|
| 720 | - do { |
|
| 721 | - $uri = $uri1; |
|
| 722 | - $uri1 = preg_replace( |
|
| 723 | - ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 724 | - '\1', |
|
| 725 | - $uri |
|
| 726 | - ); |
|
| 727 | - } while ($uri <> $uri1); |
|
| 728 | - return preg_replace(',[?&]$,', '', $uri1); |
|
| 718 | + $uri1 = $request_uri; |
|
| 719 | + do { |
|
| 720 | + $uri = $uri1; |
|
| 721 | + $uri1 = preg_replace( |
|
| 722 | + ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 723 | + '\1', |
|
| 724 | + $uri |
|
| 725 | + ); |
|
| 726 | + } while ($uri <> $uri1); |
|
| 727 | + return preg_replace(',[?&]$,', '', $uri1); |
|
| 729 | 728 | } |
| 730 | 729 | |
| 731 | 730 | |
@@ -739,48 +738,48 @@ discard block |
||
| 739 | 738 | * URL vers soi-même |
| 740 | 739 | **/ |
| 741 | 740 | function self($amp = '&', $root = false) { |
| 742 | - $url = nettoyer_uri(); |
|
| 743 | - if ( |
|
| 744 | - !$root |
|
| 745 | - and ( |
|
| 746 | - // si pas de profondeur on peut tronquer |
|
| 747 | - $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 748 | - // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 749 | - or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 750 | - ) { |
|
| 751 | - $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 752 | - } |
|
| 753 | - // ajouter le cas echeant les variables _POST['id_...'] |
|
| 754 | - foreach ($_POST as $v => $c) { |
|
| 755 | - if (substr($v, 0, 3) == 'id_') { |
|
| 756 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - // supprimer les variables sans interet |
|
| 761 | - if (test_espace_prive()) { |
|
| 762 | - $url = preg_replace(',([?&])(' |
|
| 763 | - . 'lang|show_docs|' |
|
| 764 | - . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 765 | - $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 766 | - $url = preg_replace(',[&]$,', '\1', $url); |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - // eviter les hacks |
|
| 770 | - include_spip('inc/filtres_mini'); |
|
| 771 | - $url = spip_htmlspecialchars($url); |
|
| 772 | - |
|
| 773 | - $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 774 | - |
|
| 775 | - // & ? |
|
| 776 | - if ($amp != '&') { |
|
| 777 | - $url = str_replace('&', $amp, $url); |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // Si ca demarre par ? ou vide, donner './' |
|
| 781 | - $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 782 | - |
|
| 783 | - return $url; |
|
| 741 | + $url = nettoyer_uri(); |
|
| 742 | + if ( |
|
| 743 | + !$root |
|
| 744 | + and ( |
|
| 745 | + // si pas de profondeur on peut tronquer |
|
| 746 | + $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 747 | + // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 748 | + or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 749 | + ) { |
|
| 750 | + $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 751 | + } |
|
| 752 | + // ajouter le cas echeant les variables _POST['id_...'] |
|
| 753 | + foreach ($_POST as $v => $c) { |
|
| 754 | + if (substr($v, 0, 3) == 'id_') { |
|
| 755 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 756 | + } |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + // supprimer les variables sans interet |
|
| 760 | + if (test_espace_prive()) { |
|
| 761 | + $url = preg_replace(',([?&])(' |
|
| 762 | + . 'lang|show_docs|' |
|
| 763 | + . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 764 | + $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 765 | + $url = preg_replace(',[&]$,', '\1', $url); |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + // eviter les hacks |
|
| 769 | + include_spip('inc/filtres_mini'); |
|
| 770 | + $url = spip_htmlspecialchars($url); |
|
| 771 | + |
|
| 772 | + $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 773 | + |
|
| 774 | + // & ? |
|
| 775 | + if ($amp != '&') { |
|
| 776 | + $url = str_replace('&', $amp, $url); |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + // Si ca demarre par ? ou vide, donner './' |
|
| 780 | + $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 781 | + |
|
| 782 | + return $url; |
|
| 784 | 783 | } |
| 785 | 784 | |
| 786 | 785 | |
@@ -791,7 +790,7 @@ discard block |
||
| 791 | 790 | * true si c'est le cas, false sinon. |
| 792 | 791 | */ |
| 793 | 792 | function test_espace_prive() { |
| 794 | - return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 793 | + return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 795 | 794 | } |
| 796 | 795 | |
| 797 | 796 | /** |
@@ -801,7 +800,7 @@ discard block |
||
| 801 | 800 | * @return bool |
| 802 | 801 | */ |
| 803 | 802 | function test_plugin_actif($plugin) { |
| 804 | - return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 803 | + return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 805 | 804 | } |
| 806 | 805 | |
| 807 | 806 | /** |
@@ -832,52 +831,52 @@ discard block |
||
| 832 | 831 | * Texte |
| 833 | 832 | */ |
| 834 | 833 | function _T($texte, $args = [], $options = []) { |
| 835 | - static $traduire = false; |
|
| 836 | - $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 837 | - if ($options) { |
|
| 838 | - // support de l'ancien argument $class |
|
| 839 | - if (is_string($options)) { |
|
| 840 | - $options = ['class' => $options]; |
|
| 841 | - } |
|
| 842 | - $o = array_merge($o, $options); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - if (!$traduire) { |
|
| 846 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 847 | - include_spip('inc/lang'); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - // On peut passer explicitement la langue dans le tableau |
|
| 851 | - // On utilise le même nom de variable que la globale |
|
| 852 | - if (isset($args['spip_lang'])) { |
|
| 853 | - $lang = $args['spip_lang']; |
|
| 854 | - // On l'enleve pour ne pas le passer au remplacement |
|
| 855 | - unset($args['spip_lang']); |
|
| 856 | - } // Sinon on prend la langue du contexte |
|
| 857 | - else { |
|
| 858 | - $lang = $GLOBALS['spip_lang']; |
|
| 859 | - } |
|
| 860 | - $text = $traduire($texte, $lang); |
|
| 861 | - |
|
| 862 | - if ($text === null || !strlen($text)) { |
|
| 863 | - if (!$o['force']) { |
|
| 864 | - return ''; |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - $text = $texte; |
|
| 868 | - |
|
| 869 | - // pour les chaines non traduites, assurer un service minimum |
|
| 870 | - if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 871 | - $n = strpos($text, ':'); |
|
| 872 | - if ($n !== false) { |
|
| 873 | - $text = substr($text, $n + 1); |
|
| 874 | - } |
|
| 875 | - $text = str_replace('_', ' ', $text); |
|
| 876 | - } |
|
| 877 | - $o['class'] = null; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - return _L($text, $args, $o); |
|
| 834 | + static $traduire = false; |
|
| 835 | + $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 836 | + if ($options) { |
|
| 837 | + // support de l'ancien argument $class |
|
| 838 | + if (is_string($options)) { |
|
| 839 | + $options = ['class' => $options]; |
|
| 840 | + } |
|
| 841 | + $o = array_merge($o, $options); |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + if (!$traduire) { |
|
| 845 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 846 | + include_spip('inc/lang'); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + // On peut passer explicitement la langue dans le tableau |
|
| 850 | + // On utilise le même nom de variable que la globale |
|
| 851 | + if (isset($args['spip_lang'])) { |
|
| 852 | + $lang = $args['spip_lang']; |
|
| 853 | + // On l'enleve pour ne pas le passer au remplacement |
|
| 854 | + unset($args['spip_lang']); |
|
| 855 | + } // Sinon on prend la langue du contexte |
|
| 856 | + else { |
|
| 857 | + $lang = $GLOBALS['spip_lang']; |
|
| 858 | + } |
|
| 859 | + $text = $traduire($texte, $lang); |
|
| 860 | + |
|
| 861 | + if ($text === null || !strlen($text)) { |
|
| 862 | + if (!$o['force']) { |
|
| 863 | + return ''; |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + $text = $texte; |
|
| 867 | + |
|
| 868 | + // pour les chaines non traduites, assurer un service minimum |
|
| 869 | + if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 870 | + $n = strpos($text, ':'); |
|
| 871 | + if ($n !== false) { |
|
| 872 | + $text = substr($text, $n + 1); |
|
| 873 | + } |
|
| 874 | + $text = str_replace('_', ' ', $text); |
|
| 875 | + } |
|
| 876 | + $o['class'] = null; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + return _L($text, $args, $o); |
|
| 881 | 880 | } |
| 882 | 881 | |
| 883 | 882 | |
@@ -904,53 +903,53 @@ discard block |
||
| 904 | 903 | * Texte |
| 905 | 904 | */ |
| 906 | 905 | function _L($text, $args = [], $options = []) { |
| 907 | - $f = $text; |
|
| 908 | - $defaut_options = [ |
|
| 909 | - 'class' => null, |
|
| 910 | - 'sanitize' => true, |
|
| 911 | - ]; |
|
| 912 | - // support de l'ancien argument $class |
|
| 913 | - if ($options and is_string($options)) { |
|
| 914 | - $options = ['class' => $options]; |
|
| 915 | - } |
|
| 916 | - if (is_array($options)) { |
|
| 917 | - $options += $defaut_options; |
|
| 918 | - } else { |
|
| 919 | - $options = $defaut_options; |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - if (is_array($args) and count($args)) { |
|
| 923 | - if (!function_exists('interdire_scripts')) { |
|
| 924 | - include_spip('inc/texte'); |
|
| 925 | - } |
|
| 926 | - if (!function_exists('echapper_html_suspect')) { |
|
| 927 | - include_spip('inc/texte_mini'); |
|
| 928 | - } |
|
| 929 | - foreach ($args as $name => $value) { |
|
| 930 | - if (strpos($text, "@$name@") !== false) { |
|
| 931 | - if ($options['sanitize']) { |
|
| 932 | - $value = echapper_html_suspect($value); |
|
| 933 | - $value = interdire_scripts($value, -1); |
|
| 934 | - } |
|
| 935 | - if (!empty($options['class'])) { |
|
| 936 | - $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 937 | - } |
|
| 938 | - $text = str_replace("@$name@", $value, $text); |
|
| 939 | - unset($args[$name]); |
|
| 940 | - } |
|
| 941 | - } |
|
| 942 | - // Si des variables n'ont pas ete inserees, le signaler |
|
| 943 | - // (chaines de langues pas a jour) |
|
| 944 | - if ($args) { |
|
| 945 | - spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 946 | - } |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 950 | - return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 951 | - } else { |
|
| 952 | - return $text; |
|
| 953 | - } |
|
| 906 | + $f = $text; |
|
| 907 | + $defaut_options = [ |
|
| 908 | + 'class' => null, |
|
| 909 | + 'sanitize' => true, |
|
| 910 | + ]; |
|
| 911 | + // support de l'ancien argument $class |
|
| 912 | + if ($options and is_string($options)) { |
|
| 913 | + $options = ['class' => $options]; |
|
| 914 | + } |
|
| 915 | + if (is_array($options)) { |
|
| 916 | + $options += $defaut_options; |
|
| 917 | + } else { |
|
| 918 | + $options = $defaut_options; |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + if (is_array($args) and count($args)) { |
|
| 922 | + if (!function_exists('interdire_scripts')) { |
|
| 923 | + include_spip('inc/texte'); |
|
| 924 | + } |
|
| 925 | + if (!function_exists('echapper_html_suspect')) { |
|
| 926 | + include_spip('inc/texte_mini'); |
|
| 927 | + } |
|
| 928 | + foreach ($args as $name => $value) { |
|
| 929 | + if (strpos($text, "@$name@") !== false) { |
|
| 930 | + if ($options['sanitize']) { |
|
| 931 | + $value = echapper_html_suspect($value); |
|
| 932 | + $value = interdire_scripts($value, -1); |
|
| 933 | + } |
|
| 934 | + if (!empty($options['class'])) { |
|
| 935 | + $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 936 | + } |
|
| 937 | + $text = str_replace("@$name@", $value, $text); |
|
| 938 | + unset($args[$name]); |
|
| 939 | + } |
|
| 940 | + } |
|
| 941 | + // Si des variables n'ont pas ete inserees, le signaler |
|
| 942 | + // (chaines de langues pas a jour) |
|
| 943 | + if ($args) { |
|
| 944 | + spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 949 | + return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 950 | + } else { |
|
| 951 | + return $text; |
|
| 952 | + } |
|
| 954 | 953 | } |
| 955 | 954 | |
| 956 | 955 | |
@@ -964,13 +963,13 @@ discard block |
||
| 964 | 963 | * @return string |
| 965 | 964 | */ |
| 966 | 965 | function joli_repertoire($rep) { |
| 967 | - $a = substr($rep, 0, 1); |
|
| 968 | - if ($a <> '.' and $a <> '/') { |
|
| 969 | - $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 970 | - } |
|
| 971 | - $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 966 | + $a = substr($rep, 0, 1); |
|
| 967 | + if ($a <> '.' and $a <> '/') { |
|
| 968 | + $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 969 | + } |
|
| 970 | + $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 972 | 971 | |
| 973 | - return $rep; |
|
| 972 | + return $rep; |
|
| 974 | 973 | } |
| 975 | 974 | |
| 976 | 975 | |
@@ -995,33 +994,33 @@ discard block |
||
| 995 | 994 | * @return float|int|string|void |
| 996 | 995 | */ |
| 997 | 996 | function spip_timer($t = 'rien', $raw = false) { |
| 998 | - static $time; |
|
| 999 | - $a = time(); |
|
| 1000 | - $b = microtime(); |
|
| 1001 | - // microtime peut contenir les microsecondes et le temps |
|
| 1002 | - $b = explode(' ', $b); |
|
| 1003 | - if (count($b) == 2) { |
|
| 1004 | - $a = end($b); |
|
| 1005 | - } // plus precis ! |
|
| 1006 | - $b = reset($b); |
|
| 1007 | - if (!isset($time[$t])) { |
|
| 1008 | - $time[$t] = $a + $b; |
|
| 1009 | - } else { |
|
| 1010 | - $p = ($a + $b - $time[$t]) * 1000; |
|
| 1011 | - unset($time[$t]); |
|
| 997 | + static $time; |
|
| 998 | + $a = time(); |
|
| 999 | + $b = microtime(); |
|
| 1000 | + // microtime peut contenir les microsecondes et le temps |
|
| 1001 | + $b = explode(' ', $b); |
|
| 1002 | + if (count($b) == 2) { |
|
| 1003 | + $a = end($b); |
|
| 1004 | + } // plus precis ! |
|
| 1005 | + $b = reset($b); |
|
| 1006 | + if (!isset($time[$t])) { |
|
| 1007 | + $time[$t] = $a + $b; |
|
| 1008 | + } else { |
|
| 1009 | + $p = ($a + $b - $time[$t]) * 1000; |
|
| 1010 | + unset($time[$t]); |
|
| 1012 | 1011 | # echo "'$p'";exit; |
| 1013 | - if ($raw) { |
|
| 1014 | - return $p; |
|
| 1015 | - } |
|
| 1016 | - if ($p < 1000) { |
|
| 1017 | - $s = ''; |
|
| 1018 | - } else { |
|
| 1019 | - $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1020 | - $p -= ($x * 1000); |
|
| 1021 | - } |
|
| 1012 | + if ($raw) { |
|
| 1013 | + return $p; |
|
| 1014 | + } |
|
| 1015 | + if ($p < 1000) { |
|
| 1016 | + $s = ''; |
|
| 1017 | + } else { |
|
| 1018 | + $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1019 | + $p -= ($x * 1000); |
|
| 1020 | + } |
|
| 1022 | 1021 | |
| 1023 | - return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1024 | - } |
|
| 1022 | + return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1023 | + } |
|
| 1025 | 1024 | } |
| 1026 | 1025 | |
| 1027 | 1026 | |
@@ -1029,21 +1028,21 @@ discard block |
||
| 1029 | 1028 | // sinon renvoie True et le date sauf si ca n'est pas souhaite |
| 1030 | 1029 | // https://code.spip.net/@spip_touch |
| 1031 | 1030 | function spip_touch($fichier, $duree = 0, $touch = true) { |
| 1032 | - if ($duree) { |
|
| 1033 | - clearstatcache(); |
|
| 1034 | - if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1035 | - return false; |
|
| 1036 | - } |
|
| 1037 | - } |
|
| 1038 | - if ($touch !== false) { |
|
| 1039 | - if (!@touch($fichier)) { |
|
| 1040 | - spip_unlink($fichier); |
|
| 1041 | - @touch($fichier); |
|
| 1042 | - }; |
|
| 1043 | - @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1044 | - } |
|
| 1031 | + if ($duree) { |
|
| 1032 | + clearstatcache(); |
|
| 1033 | + if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1034 | + return false; |
|
| 1035 | + } |
|
| 1036 | + } |
|
| 1037 | + if ($touch !== false) { |
|
| 1038 | + if (!@touch($fichier)) { |
|
| 1039 | + spip_unlink($fichier); |
|
| 1040 | + @touch($fichier); |
|
| 1041 | + }; |
|
| 1042 | + @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1043 | + } |
|
| 1045 | 1044 | |
| 1046 | - return true; |
|
| 1045 | + return true; |
|
| 1047 | 1046 | } |
| 1048 | 1047 | |
| 1049 | 1048 | |
@@ -1054,11 +1053,11 @@ discard block |
||
| 1054 | 1053 | * @uses cron() |
| 1055 | 1054 | **/ |
| 1056 | 1055 | function action_cron() { |
| 1057 | - include_spip('inc/headers'); |
|
| 1058 | - http_response_code(204); // No Content |
|
| 1059 | - header('Connection: close'); |
|
| 1060 | - define('_DIRECT_CRON_FORCE', true); |
|
| 1061 | - cron(); |
|
| 1056 | + include_spip('inc/headers'); |
|
| 1057 | + http_response_code(204); // No Content |
|
| 1058 | + header('Connection: close'); |
|
| 1059 | + define('_DIRECT_CRON_FORCE', true); |
|
| 1060 | + cron(); |
|
| 1062 | 1061 | } |
| 1063 | 1062 | |
| 1064 | 1063 | /** |
@@ -1074,26 +1073,26 @@ discard block |
||
| 1074 | 1073 | * True si la tache a pu être effectuée |
| 1075 | 1074 | */ |
| 1076 | 1075 | function cron($taches = [], $taches_old = []) { |
| 1077 | - // si pas en mode cron force, laisser tomber. |
|
| 1078 | - if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1079 | - return false; |
|
| 1080 | - } |
|
| 1081 | - if (!is_array($taches)) { |
|
| 1082 | - $taches = $taches_old; |
|
| 1083 | - } // compat anciens appels |
|
| 1084 | - // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1085 | - // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1086 | - // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1087 | - // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1088 | - if ($taches and count($taches) and !spip_connect()) { |
|
| 1089 | - return false; |
|
| 1090 | - } |
|
| 1091 | - spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1092 | - if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1093 | - return $genie($taches); |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - return false; |
|
| 1076 | + // si pas en mode cron force, laisser tomber. |
|
| 1077 | + if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1078 | + return false; |
|
| 1079 | + } |
|
| 1080 | + if (!is_array($taches)) { |
|
| 1081 | + $taches = $taches_old; |
|
| 1082 | + } // compat anciens appels |
|
| 1083 | + // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1084 | + // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1085 | + // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1086 | + // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1087 | + if ($taches and count($taches) and !spip_connect()) { |
|
| 1088 | + return false; |
|
| 1089 | + } |
|
| 1090 | + spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1091 | + if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1092 | + return $genie($taches); |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + return false; |
|
| 1097 | 1096 | } |
| 1098 | 1097 | |
| 1099 | 1098 | /** |
@@ -1125,17 +1124,17 @@ discard block |
||
| 1125 | 1124 | * Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté. |
| 1126 | 1125 | */ |
| 1127 | 1126 | function job_queue_add( |
| 1128 | - $function, |
|
| 1129 | - $description, |
|
| 1130 | - $arguments = [], |
|
| 1131 | - $file = '', |
|
| 1132 | - $no_duplicate = false, |
|
| 1133 | - $time = 0, |
|
| 1134 | - $priority = 0 |
|
| 1127 | + $function, |
|
| 1128 | + $description, |
|
| 1129 | + $arguments = [], |
|
| 1130 | + $file = '', |
|
| 1131 | + $no_duplicate = false, |
|
| 1132 | + $time = 0, |
|
| 1133 | + $priority = 0 |
|
| 1135 | 1134 | ) { |
| 1136 | - include_spip('inc/queue'); |
|
| 1135 | + include_spip('inc/queue'); |
|
| 1137 | 1136 | |
| 1138 | - return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1137 | + return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1139 | 1138 | } |
| 1140 | 1139 | |
| 1141 | 1140 | /** |
@@ -1146,9 +1145,9 @@ discard block |
||
| 1146 | 1145 | * @return bool |
| 1147 | 1146 | */ |
| 1148 | 1147 | function job_queue_remove($id_job) { |
| 1149 | - include_spip('inc/queue'); |
|
| 1148 | + include_spip('inc/queue'); |
|
| 1150 | 1149 | |
| 1151 | - return queue_remove_job($id_job); |
|
| 1150 | + return queue_remove_job($id_job); |
|
| 1152 | 1151 | } |
| 1153 | 1152 | |
| 1154 | 1153 | /** |
@@ -1161,9 +1160,9 @@ discard block |
||
| 1161 | 1160 | * or an array of simple array to link multiples objet in one time |
| 1162 | 1161 | */ |
| 1163 | 1162 | function job_queue_link($id_job, $objets) { |
| 1164 | - include_spip('inc/queue'); |
|
| 1163 | + include_spip('inc/queue'); |
|
| 1165 | 1164 | |
| 1166 | - return queue_link_job($id_job, $objets); |
|
| 1165 | + return queue_link_job($id_job, $objets); |
|
| 1167 | 1166 | } |
| 1168 | 1167 | |
| 1169 | 1168 | |
@@ -1183,36 +1182,36 @@ discard block |
||
| 1183 | 1182 | * - `null` si la queue n'est pas encore initialisée |
| 1184 | 1183 | */ |
| 1185 | 1184 | function queue_sleep_time_to_next_job($force = null) { |
| 1186 | - static $queue_next_job_time = -1; |
|
| 1187 | - if ($force === true) { |
|
| 1188 | - $queue_next_job_time = -1; |
|
| 1189 | - } elseif ($force) { |
|
| 1190 | - $queue_next_job_time = $force; |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - if ($queue_next_job_time == -1) { |
|
| 1194 | - if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1195 | - define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1196 | - } |
|
| 1197 | - // utiliser un cache memoire si dispo |
|
| 1198 | - if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1199 | - $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1200 | - } else { |
|
| 1201 | - $queue_next_job_time = null; |
|
| 1202 | - if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1203 | - $queue_next_job_time = intval($contenu); |
|
| 1204 | - } |
|
| 1205 | - } |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - if (is_null($queue_next_job_time)) { |
|
| 1209 | - return null; |
|
| 1210 | - } |
|
| 1211 | - if (!$_SERVER['REQUEST_TIME']) { |
|
| 1212 | - $_SERVER['REQUEST_TIME'] = time(); |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1185 | + static $queue_next_job_time = -1; |
|
| 1186 | + if ($force === true) { |
|
| 1187 | + $queue_next_job_time = -1; |
|
| 1188 | + } elseif ($force) { |
|
| 1189 | + $queue_next_job_time = $force; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + if ($queue_next_job_time == -1) { |
|
| 1193 | + if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1194 | + define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1195 | + } |
|
| 1196 | + // utiliser un cache memoire si dispo |
|
| 1197 | + if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1198 | + $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1199 | + } else { |
|
| 1200 | + $queue_next_job_time = null; |
|
| 1201 | + if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1202 | + $queue_next_job_time = intval($contenu); |
|
| 1203 | + } |
|
| 1204 | + } |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + if (is_null($queue_next_job_time)) { |
|
| 1208 | + return null; |
|
| 1209 | + } |
|
| 1210 | + if (!$_SERVER['REQUEST_TIME']) { |
|
| 1211 | + $_SERVER['REQUEST_TIME'] = time(); |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1216 | 1215 | } |
| 1217 | 1216 | |
| 1218 | 1217 | |
@@ -1224,11 +1223,11 @@ discard block |
||
| 1224 | 1223 | * @return string |
| 1225 | 1224 | */ |
| 1226 | 1225 | function quote_amp($u) { |
| 1227 | - return preg_replace( |
|
| 1228 | - '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1229 | - '&', |
|
| 1230 | - $u |
|
| 1231 | - ); |
|
| 1226 | + return preg_replace( |
|
| 1227 | + '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1228 | + '&', |
|
| 1229 | + $u |
|
| 1230 | + ); |
|
| 1232 | 1231 | } |
| 1233 | 1232 | |
| 1234 | 1233 | |
@@ -1251,27 +1250,27 @@ discard block |
||
| 1251 | 1250 | * Balise HTML `<script>` et son contenu |
| 1252 | 1251 | **/ |
| 1253 | 1252 | function http_script($script, $src = '', $noscript = '') { |
| 1254 | - static $done = []; |
|
| 1253 | + static $done = []; |
|
| 1255 | 1254 | |
| 1256 | - if ($src && !isset($done[$src])) { |
|
| 1257 | - $done[$src] = true; |
|
| 1258 | - $src = find_in_path($src, _JAVASCRIPT); |
|
| 1259 | - $src = " src='$src'"; |
|
| 1260 | - } else { |
|
| 1261 | - $src = ''; |
|
| 1262 | - } |
|
| 1263 | - if ($script) { |
|
| 1264 | - $script = ("/*<![CDATA[*/\n" . |
|
| 1265 | - preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1266 | - '/*]]>*/'); |
|
| 1267 | - } |
|
| 1268 | - if ($noscript) { |
|
| 1269 | - $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1270 | - } |
|
| 1255 | + if ($src && !isset($done[$src])) { |
|
| 1256 | + $done[$src] = true; |
|
| 1257 | + $src = find_in_path($src, _JAVASCRIPT); |
|
| 1258 | + $src = " src='$src'"; |
|
| 1259 | + } else { |
|
| 1260 | + $src = ''; |
|
| 1261 | + } |
|
| 1262 | + if ($script) { |
|
| 1263 | + $script = ("/*<![CDATA[*/\n" . |
|
| 1264 | + preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1265 | + '/*]]>*/'); |
|
| 1266 | + } |
|
| 1267 | + if ($noscript) { |
|
| 1268 | + $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1269 | + } |
|
| 1271 | 1270 | |
| 1272 | - return ($src or $script or $noscript) |
|
| 1273 | - ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1274 | - : ''; |
|
| 1271 | + return ($src or $script or $noscript) |
|
| 1272 | + ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1273 | + : ''; |
|
| 1275 | 1274 | } |
| 1276 | 1275 | |
| 1277 | 1276 | |
@@ -1306,7 +1305,7 @@ discard block |
||
| 1306 | 1305 | * Texte échappé |
| 1307 | 1306 | **/ |
| 1308 | 1307 | function texte_script(string $texte): string { |
| 1309 | - return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1308 | + return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1310 | 1309 | } |
| 1311 | 1310 | |
| 1312 | 1311 | |
@@ -1343,68 +1342,68 @@ discard block |
||
| 1343 | 1342 | * Liste des chemins, par ordre de priorité. |
| 1344 | 1343 | **/ |
| 1345 | 1344 | function _chemin($dir_path = null) { |
| 1346 | - static $path_base = null; |
|
| 1347 | - static $path_full = null; |
|
| 1348 | - if ($path_base == null) { |
|
| 1349 | - // Chemin standard depuis l'espace public |
|
| 1350 | - $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1351 | - _DIR_RACINE . ':' . |
|
| 1352 | - _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1353 | - _DIR_RACINE . 'prive/:' . |
|
| 1354 | - _DIR_RESTREINT; |
|
| 1355 | - // Ajouter squelettes/ |
|
| 1356 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1357 | - $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1358 | - } |
|
| 1359 | - foreach (explode(':', $path) as $dir) { |
|
| 1360 | - if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1361 | - $dir .= '/'; |
|
| 1362 | - } |
|
| 1363 | - $path_base[] = $dir; |
|
| 1364 | - } |
|
| 1365 | - $path_full = $path_base; |
|
| 1366 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1367 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1368 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1369 | - array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1372 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1373 | - } |
|
| 1374 | - if ($dir_path === null) { |
|
| 1375 | - return $path_full; |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1379 | - $tete = ''; |
|
| 1380 | - if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1381 | - $tete = array_shift($path_base); |
|
| 1382 | - } |
|
| 1383 | - $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1384 | - $dirs = array_reverse($dirs); |
|
| 1385 | - foreach ($dirs as $dir_path) { |
|
| 1386 | - if (substr($dir_path, -1) != '/') { |
|
| 1387 | - $dir_path .= '/'; |
|
| 1388 | - } |
|
| 1389 | - if (!in_array($dir_path, $path_base)) { |
|
| 1390 | - array_unshift($path_base, $dir_path); |
|
| 1391 | - } |
|
| 1392 | - } |
|
| 1393 | - if (strlen($tete)) { |
|
| 1394 | - array_unshift($path_base, $tete); |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - $path_full = $path_base; |
|
| 1398 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1399 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1400 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1401 | - array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1402 | - } |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1406 | - |
|
| 1407 | - return $path_full; |
|
| 1345 | + static $path_base = null; |
|
| 1346 | + static $path_full = null; |
|
| 1347 | + if ($path_base == null) { |
|
| 1348 | + // Chemin standard depuis l'espace public |
|
| 1349 | + $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1350 | + _DIR_RACINE . ':' . |
|
| 1351 | + _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1352 | + _DIR_RACINE . 'prive/:' . |
|
| 1353 | + _DIR_RESTREINT; |
|
| 1354 | + // Ajouter squelettes/ |
|
| 1355 | + if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1356 | + $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1357 | + } |
|
| 1358 | + foreach (explode(':', $path) as $dir) { |
|
| 1359 | + if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1360 | + $dir .= '/'; |
|
| 1361 | + } |
|
| 1362 | + $path_base[] = $dir; |
|
| 1363 | + } |
|
| 1364 | + $path_full = $path_base; |
|
| 1365 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1366 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1367 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1368 | + array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1369 | + } |
|
| 1370 | + } |
|
| 1371 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1372 | + } |
|
| 1373 | + if ($dir_path === null) { |
|
| 1374 | + return $path_full; |
|
| 1375 | + } |
|
| 1376 | + |
|
| 1377 | + if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1378 | + $tete = ''; |
|
| 1379 | + if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1380 | + $tete = array_shift($path_base); |
|
| 1381 | + } |
|
| 1382 | + $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1383 | + $dirs = array_reverse($dirs); |
|
| 1384 | + foreach ($dirs as $dir_path) { |
|
| 1385 | + if (substr($dir_path, -1) != '/') { |
|
| 1386 | + $dir_path .= '/'; |
|
| 1387 | + } |
|
| 1388 | + if (!in_array($dir_path, $path_base)) { |
|
| 1389 | + array_unshift($path_base, $dir_path); |
|
| 1390 | + } |
|
| 1391 | + } |
|
| 1392 | + if (strlen($tete)) { |
|
| 1393 | + array_unshift($path_base, $tete); |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + $path_full = $path_base; |
|
| 1397 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1398 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1399 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1400 | + array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1401 | + } |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1405 | + |
|
| 1406 | + return $path_full; |
|
| 1408 | 1407 | } |
| 1409 | 1408 | |
| 1410 | 1409 | /** |
@@ -1417,78 +1416,78 @@ discard block |
||
| 1417 | 1416 | * @return array Liste de chemins |
| 1418 | 1417 | **/ |
| 1419 | 1418 | function creer_chemin() { |
| 1420 | - $path_a = _chemin(); |
|
| 1421 | - static $c = ''; |
|
| 1419 | + $path_a = _chemin(); |
|
| 1420 | + static $c = ''; |
|
| 1422 | 1421 | |
| 1423 | - // on calcule le chemin si le dossier skel a change |
|
| 1424 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1425 | - // assurer le non plantage lors de la montee de version : |
|
| 1426 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1427 | - $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1428 | - } |
|
| 1422 | + // on calcule le chemin si le dossier skel a change |
|
| 1423 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1424 | + // assurer le non plantage lors de la montee de version : |
|
| 1425 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1426 | + $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1427 | + } |
|
| 1429 | 1428 | |
| 1430 | - return $path_a; |
|
| 1429 | + return $path_a; |
|
| 1431 | 1430 | } |
| 1432 | 1431 | |
| 1433 | 1432 | |
| 1434 | 1433 | function lister_themes_prives() { |
| 1435 | - static $themes = null; |
|
| 1436 | - if (is_null($themes)) { |
|
| 1437 | - // si pas encore definie |
|
| 1438 | - if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1439 | - define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1440 | - } |
|
| 1441 | - $themes = [_SPIP_THEME_PRIVE]; |
|
| 1442 | - // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1443 | - if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1444 | - $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1445 | - } else { |
|
| 1446 | - $prefs = []; |
|
| 1447 | - } |
|
| 1448 | - if (is_string($prefs)) { |
|
| 1449 | - $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1450 | - } |
|
| 1451 | - if ( |
|
| 1452 | - ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1453 | - or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1454 | - and $theme != _SPIP_THEME_PRIVE |
|
| 1455 | - ) { |
|
| 1456 | - array_unshift($themes, $theme); |
|
| 1457 | - } // placer le theme choisi en tete |
|
| 1458 | - } |
|
| 1459 | - |
|
| 1460 | - return $themes; |
|
| 1434 | + static $themes = null; |
|
| 1435 | + if (is_null($themes)) { |
|
| 1436 | + // si pas encore definie |
|
| 1437 | + if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1438 | + define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1439 | + } |
|
| 1440 | + $themes = [_SPIP_THEME_PRIVE]; |
|
| 1441 | + // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1442 | + if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1443 | + $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1444 | + } else { |
|
| 1445 | + $prefs = []; |
|
| 1446 | + } |
|
| 1447 | + if (is_string($prefs)) { |
|
| 1448 | + $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1449 | + } |
|
| 1450 | + if ( |
|
| 1451 | + ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1452 | + or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1453 | + and $theme != _SPIP_THEME_PRIVE |
|
| 1454 | + ) { |
|
| 1455 | + array_unshift($themes, $theme); |
|
| 1456 | + } // placer le theme choisi en tete |
|
| 1457 | + } |
|
| 1458 | + |
|
| 1459 | + return $themes; |
|
| 1461 | 1460 | } |
| 1462 | 1461 | |
| 1463 | 1462 | function find_in_theme($file, $subdir = '', $include = false) { |
| 1464 | - static $themefiles = []; |
|
| 1465 | - if (isset($themefiles["$subdir$file"])) { |
|
| 1466 | - return $themefiles["$subdir$file"]; |
|
| 1467 | - } |
|
| 1468 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1469 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1470 | - if ( |
|
| 1471 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1472 | - and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 1473 | - and $f = find_in_theme("$file_svg_generique") |
|
| 1474 | - ) { |
|
| 1475 | - if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) { |
|
| 1476 | - return $themefiles["$subdir$file"] = $fsize; |
|
| 1477 | - } |
|
| 1478 | - else { |
|
| 1479 | - return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1480 | - } |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - $themes = lister_themes_prives(); |
|
| 1484 | - foreach ($themes as $theme) { |
|
| 1485 | - if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1486 | - return $themefiles["$subdir$file"] = $f; |
|
| 1487 | - } |
|
| 1488 | - } |
|
| 1489 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1490 | - |
|
| 1491 | - return $themefiles["$subdir$file"] = ''; |
|
| 1463 | + static $themefiles = []; |
|
| 1464 | + if (isset($themefiles["$subdir$file"])) { |
|
| 1465 | + return $themefiles["$subdir$file"]; |
|
| 1466 | + } |
|
| 1467 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1468 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1469 | + if ( |
|
| 1470 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1471 | + and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 1472 | + and $f = find_in_theme("$file_svg_generique") |
|
| 1473 | + ) { |
|
| 1474 | + if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) { |
|
| 1475 | + return $themefiles["$subdir$file"] = $fsize; |
|
| 1476 | + } |
|
| 1477 | + else { |
|
| 1478 | + return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1479 | + } |
|
| 1480 | + } |
|
| 1481 | + |
|
| 1482 | + $themes = lister_themes_prives(); |
|
| 1483 | + foreach ($themes as $theme) { |
|
| 1484 | + if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1485 | + return $themefiles["$subdir$file"] = $f; |
|
| 1486 | + } |
|
| 1487 | + } |
|
| 1488 | + spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1489 | + |
|
| 1490 | + return $themefiles["$subdir$file"] = ''; |
|
| 1492 | 1491 | } |
| 1493 | 1492 | |
| 1494 | 1493 | |
@@ -1512,31 +1511,31 @@ discard block |
||
| 1512 | 1511 | * sinon chaîne vide. |
| 1513 | 1512 | **/ |
| 1514 | 1513 | function chemin_image($icone) { |
| 1515 | - static $icone_renommer; |
|
| 1516 | - if ($p = strpos($icone, '?')) { |
|
| 1517 | - $icone = substr($icone, 0, $p); |
|
| 1518 | - } |
|
| 1519 | - // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1520 | - if (strpos($icone, '/') !== false and file_exists($icone)) { |
|
| 1521 | - return $icone; |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1525 | - if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1526 | - return $f; |
|
| 1527 | - } |
|
| 1528 | - // sinon passer par le module de renommage |
|
| 1529 | - if (is_null($icone_renommer)) { |
|
| 1530 | - $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1531 | - } |
|
| 1532 | - if ($icone_renommer) { |
|
| 1533 | - list($icone, $fonction) = $icone_renommer($icone, ''); |
|
| 1534 | - if (file_exists($icone)) { |
|
| 1535 | - return $icone; |
|
| 1536 | - } |
|
| 1537 | - } |
|
| 1538 | - |
|
| 1539 | - return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1514 | + static $icone_renommer; |
|
| 1515 | + if ($p = strpos($icone, '?')) { |
|
| 1516 | + $icone = substr($icone, 0, $p); |
|
| 1517 | + } |
|
| 1518 | + // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1519 | + if (strpos($icone, '/') !== false and file_exists($icone)) { |
|
| 1520 | + return $icone; |
|
| 1521 | + } |
|
| 1522 | + |
|
| 1523 | + // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1524 | + if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1525 | + return $f; |
|
| 1526 | + } |
|
| 1527 | + // sinon passer par le module de renommage |
|
| 1528 | + if (is_null($icone_renommer)) { |
|
| 1529 | + $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1530 | + } |
|
| 1531 | + if ($icone_renommer) { |
|
| 1532 | + list($icone, $fonction) = $icone_renommer($icone, ''); |
|
| 1533 | + if (file_exists($icone)) { |
|
| 1534 | + return $icone; |
|
| 1535 | + } |
|
| 1536 | + } |
|
| 1537 | + |
|
| 1538 | + return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1540 | 1539 | } |
| 1541 | 1540 | |
| 1542 | 1541 | // |
@@ -1574,128 +1573,128 @@ discard block |
||
| 1574 | 1573 | * - false : fichier introuvable |
| 1575 | 1574 | **/ |
| 1576 | 1575 | function find_in_path($file, $dirname = '', $include = false) { |
| 1577 | - static $dirs = []; |
|
| 1578 | - static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1579 | - static $c = ''; |
|
| 1580 | - |
|
| 1581 | - if (!$file and !strlen($file)) { |
|
| 1582 | - return false; |
|
| 1583 | - } |
|
| 1584 | - |
|
| 1585 | - // on calcule le chemin si le dossier skel a change |
|
| 1586 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1587 | - // assurer le non plantage lors de la montee de version : |
|
| 1588 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1589 | - creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1593 | - if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1594 | - return false; |
|
| 1595 | - } |
|
| 1596 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1597 | - include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1598 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1599 | - } |
|
| 1600 | - |
|
| 1601 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - $a = strrpos($file, '/'); |
|
| 1605 | - if ($a !== false) { |
|
| 1606 | - $dirname .= substr($file, 0, ++$a); |
|
| 1607 | - $file = substr($file, $a); |
|
| 1608 | - } |
|
| 1609 | - |
|
| 1610 | - foreach (creer_chemin() as $dir) { |
|
| 1611 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1612 | - $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1613 | - } |
|
| 1614 | - if ($dirs[$a]) { |
|
| 1615 | - if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1616 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1617 | - include_once _ROOT_CWD . $a; |
|
| 1618 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1619 | - } |
|
| 1620 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1621 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1622 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1623 | - return $a; |
|
| 1624 | - } |
|
| 1625 | - define('_SAUVER_CHEMIN', true); |
|
| 1626 | - } |
|
| 1627 | - |
|
| 1628 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1629 | - } |
|
| 1630 | - } |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - if ($include) { |
|
| 1634 | - spip_log("include_spip $dirname$file non trouve"); |
|
| 1635 | - if ($include === 'required') { |
|
| 1636 | - echo '<pre>', |
|
| 1637 | - '<strong>Erreur Fatale</strong><br />'; |
|
| 1638 | - if (function_exists('debug_print_backtrace')) { |
|
| 1639 | - echo debug_print_backtrace(); |
|
| 1640 | - } |
|
| 1641 | - echo '</pre>'; |
|
| 1642 | - die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1643 | - } |
|
| 1644 | - } |
|
| 1645 | - |
|
| 1646 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1647 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1648 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1649 | - return false; |
|
| 1650 | - } |
|
| 1651 | - define('_SAUVER_CHEMIN', true); |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1576 | + static $dirs = []; |
|
| 1577 | + static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1578 | + static $c = ''; |
|
| 1579 | + |
|
| 1580 | + if (!$file and !strlen($file)) { |
|
| 1581 | + return false; |
|
| 1582 | + } |
|
| 1583 | + |
|
| 1584 | + // on calcule le chemin si le dossier skel a change |
|
| 1585 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1586 | + // assurer le non plantage lors de la montee de version : |
|
| 1587 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1588 | + creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1589 | + } |
|
| 1590 | + |
|
| 1591 | + if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1592 | + if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1593 | + return false; |
|
| 1594 | + } |
|
| 1595 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1596 | + include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1597 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1598 | + } |
|
| 1599 | + |
|
| 1600 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + $a = strrpos($file, '/'); |
|
| 1604 | + if ($a !== false) { |
|
| 1605 | + $dirname .= substr($file, 0, ++$a); |
|
| 1606 | + $file = substr($file, $a); |
|
| 1607 | + } |
|
| 1608 | + |
|
| 1609 | + foreach (creer_chemin() as $dir) { |
|
| 1610 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1611 | + $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1612 | + } |
|
| 1613 | + if ($dirs[$a]) { |
|
| 1614 | + if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1615 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1616 | + include_once _ROOT_CWD . $a; |
|
| 1617 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1618 | + } |
|
| 1619 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1620 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1621 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1622 | + return $a; |
|
| 1623 | + } |
|
| 1624 | + define('_SAUVER_CHEMIN', true); |
|
| 1625 | + } |
|
| 1626 | + |
|
| 1627 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1628 | + } |
|
| 1629 | + } |
|
| 1630 | + } |
|
| 1631 | + |
|
| 1632 | + if ($include) { |
|
| 1633 | + spip_log("include_spip $dirname$file non trouve"); |
|
| 1634 | + if ($include === 'required') { |
|
| 1635 | + echo '<pre>', |
|
| 1636 | + '<strong>Erreur Fatale</strong><br />'; |
|
| 1637 | + if (function_exists('debug_print_backtrace')) { |
|
| 1638 | + echo debug_print_backtrace(); |
|
| 1639 | + } |
|
| 1640 | + echo '</pre>'; |
|
| 1641 | + die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1642 | + } |
|
| 1643 | + } |
|
| 1644 | + |
|
| 1645 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1646 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1647 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1648 | + return false; |
|
| 1649 | + } |
|
| 1650 | + define('_SAUVER_CHEMIN', true); |
|
| 1651 | + } |
|
| 1652 | + |
|
| 1653 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1655 | 1654 | } |
| 1656 | 1655 | |
| 1657 | 1656 | function clear_path_cache() { |
| 1658 | - $GLOBALS['path_files'] = []; |
|
| 1659 | - spip_unlink(_CACHE_CHEMIN); |
|
| 1657 | + $GLOBALS['path_files'] = []; |
|
| 1658 | + spip_unlink(_CACHE_CHEMIN); |
|
| 1660 | 1659 | } |
| 1661 | 1660 | |
| 1662 | 1661 | function load_path_cache() { |
| 1663 | - // charger le path des plugins |
|
| 1664 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1665 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1666 | - } |
|
| 1667 | - $GLOBALS['path_files'] = []; |
|
| 1668 | - // si le visiteur est admin, |
|
| 1669 | - // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1670 | - if ( |
|
| 1671 | - // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1672 | - //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1673 | - // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1674 | - // on blinde par un second test au moment de la lecture de la session |
|
| 1675 | - // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1676 | - // et en ignorant ce cache en cas de recalcul explicite |
|
| 1677 | - !_request('var_mode') |
|
| 1678 | - ) { |
|
| 1679 | - // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1680 | - if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1681 | - // mais si semble corrompu on relit avec un verrou |
|
| 1682 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1683 | - lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1684 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1685 | - $GLOBALS['path_files'] = []; |
|
| 1686 | - } |
|
| 1687 | - } |
|
| 1688 | - } |
|
| 1689 | - } |
|
| 1662 | + // charger le path des plugins |
|
| 1663 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1664 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1665 | + } |
|
| 1666 | + $GLOBALS['path_files'] = []; |
|
| 1667 | + // si le visiteur est admin, |
|
| 1668 | + // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1669 | + if ( |
|
| 1670 | + // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1671 | + //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1672 | + // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1673 | + // on blinde par un second test au moment de la lecture de la session |
|
| 1674 | + // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1675 | + // et en ignorant ce cache en cas de recalcul explicite |
|
| 1676 | + !_request('var_mode') |
|
| 1677 | + ) { |
|
| 1678 | + // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1679 | + if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1680 | + // mais si semble corrompu on relit avec un verrou |
|
| 1681 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1682 | + lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1683 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1684 | + $GLOBALS['path_files'] = []; |
|
| 1685 | + } |
|
| 1686 | + } |
|
| 1687 | + } |
|
| 1688 | + } |
|
| 1690 | 1689 | } |
| 1691 | 1690 | |
| 1692 | 1691 | function save_path_cache() { |
| 1693 | - if ( |
|
| 1694 | - defined('_SAUVER_CHEMIN') |
|
| 1695 | - and _SAUVER_CHEMIN |
|
| 1696 | - ) { |
|
| 1697 | - ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1698 | - } |
|
| 1692 | + if ( |
|
| 1693 | + defined('_SAUVER_CHEMIN') |
|
| 1694 | + and _SAUVER_CHEMIN |
|
| 1695 | + ) { |
|
| 1696 | + ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1697 | + } |
|
| 1699 | 1698 | } |
| 1700 | 1699 | |
| 1701 | 1700 | |
@@ -1715,33 +1714,33 @@ discard block |
||
| 1715 | 1714 | * @return array |
| 1716 | 1715 | */ |
| 1717 | 1716 | function find_all_in_path($dir, $pattern, $recurs = false) { |
| 1718 | - $liste_fichiers = []; |
|
| 1719 | - $maxfiles = 10000; |
|
| 1720 | - |
|
| 1721 | - // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1722 | - // on a pas encore inclus flock.php |
|
| 1723 | - if (!function_exists('preg_files')) { |
|
| 1724 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1725 | - } |
|
| 1726 | - |
|
| 1727 | - // Parcourir le chemin |
|
| 1728 | - foreach (creer_chemin() as $d) { |
|
| 1729 | - $f = $d . $dir; |
|
| 1730 | - if (@is_dir($f)) { |
|
| 1731 | - $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1732 | - foreach ($liste as $chemin) { |
|
| 1733 | - $nom = basename($chemin); |
|
| 1734 | - // ne prendre que les fichiers pas deja trouves |
|
| 1735 | - // car find_in_path prend le premier qu'il trouve, |
|
| 1736 | - // les autres sont donc masques |
|
| 1737 | - if (!isset($liste_fichiers[$nom])) { |
|
| 1738 | - $liste_fichiers[$nom] = $chemin; |
|
| 1739 | - } |
|
| 1740 | - } |
|
| 1741 | - } |
|
| 1742 | - } |
|
| 1743 | - |
|
| 1744 | - return $liste_fichiers; |
|
| 1717 | + $liste_fichiers = []; |
|
| 1718 | + $maxfiles = 10000; |
|
| 1719 | + |
|
| 1720 | + // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1721 | + // on a pas encore inclus flock.php |
|
| 1722 | + if (!function_exists('preg_files')) { |
|
| 1723 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1724 | + } |
|
| 1725 | + |
|
| 1726 | + // Parcourir le chemin |
|
| 1727 | + foreach (creer_chemin() as $d) { |
|
| 1728 | + $f = $d . $dir; |
|
| 1729 | + if (@is_dir($f)) { |
|
| 1730 | + $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1731 | + foreach ($liste as $chemin) { |
|
| 1732 | + $nom = basename($chemin); |
|
| 1733 | + // ne prendre que les fichiers pas deja trouves |
|
| 1734 | + // car find_in_path prend le premier qu'il trouve, |
|
| 1735 | + // les autres sont donc masques |
|
| 1736 | + if (!isset($liste_fichiers[$nom])) { |
|
| 1737 | + $liste_fichiers[$nom] = $chemin; |
|
| 1738 | + } |
|
| 1739 | + } |
|
| 1740 | + } |
|
| 1741 | + } |
|
| 1742 | + |
|
| 1743 | + return $liste_fichiers; |
|
| 1745 | 1744 | } |
| 1746 | 1745 | |
| 1747 | 1746 | /** |
@@ -1753,17 +1752,17 @@ discard block |
||
| 1753 | 1752 | * @return bool |
| 1754 | 1753 | */ |
| 1755 | 1754 | function autoriser_sans_cookie($nom, $strict = false) { |
| 1756 | - static $autsanscookie = ['install', 'base_repair']; |
|
| 1755 | + static $autsanscookie = ['install', 'base_repair']; |
|
| 1757 | 1756 | |
| 1758 | - if (in_array($nom, $autsanscookie)) { |
|
| 1759 | - if (test_espace_prive()) { |
|
| 1760 | - include_spip('base/connect_sql'); |
|
| 1761 | - if (!$strict or !spip_connect()) { |
|
| 1762 | - return true; |
|
| 1763 | - } |
|
| 1764 | - } |
|
| 1765 | - } |
|
| 1766 | - return false; |
|
| 1757 | + if (in_array($nom, $autsanscookie)) { |
|
| 1758 | + if (test_espace_prive()) { |
|
| 1759 | + include_spip('base/connect_sql'); |
|
| 1760 | + if (!$strict or !spip_connect()) { |
|
| 1761 | + return true; |
|
| 1762 | + } |
|
| 1763 | + } |
|
| 1764 | + } |
|
| 1765 | + return false; |
|
| 1767 | 1766 | } |
| 1768 | 1767 | |
| 1769 | 1768 | /** |
@@ -1789,99 +1788,99 @@ discard block |
||
| 1789 | 1788 | * (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_url_spip et une fonction generer_url_ecrire_spip) |
| 1790 | 1789 | */ |
| 1791 | 1790 | function generer_url_entite($id = '', $entite = '', $args = '', $ancre = '', $public = null, $type = null) { |
| 1792 | - if ($public === null) { |
|
| 1793 | - $public = !test_espace_prive(); |
|
| 1794 | - } |
|
| 1795 | - $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1796 | - |
|
| 1797 | - if (!$public) { |
|
| 1798 | - if (!$entite) { |
|
| 1799 | - return ''; |
|
| 1800 | - } |
|
| 1801 | - if (!function_exists('generer_url_ecrire_objet')) { |
|
| 1802 | - include_spip('inc/urls'); |
|
| 1803 | - } |
|
| 1804 | - $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false); |
|
| 1805 | - } else { |
|
| 1806 | - if ($type === null) { |
|
| 1807 | - $type = (isset($GLOBALS['type_urls'])) |
|
| 1808 | - ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options |
|
| 1809 | - : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues |
|
| 1810 | - ? ($GLOBALS['meta']['type_urls']) : 'page'); // sinon type "page" par défaut |
|
| 1811 | - } |
|
| 1812 | - |
|
| 1813 | - $f = charger_fonction($type, 'urls', true); |
|
| 1814 | - // se rabattre sur les urls page si les urls perso non dispo |
|
| 1815 | - if (!$f) { |
|
| 1816 | - $f = charger_fonction('page', 'urls', true); |
|
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - // si $entite='', on veut la fonction de passage URL ==> id |
|
| 1820 | - // sinon on veut effectuer le passage id ==> URL |
|
| 1821 | - if (!$entite) { |
|
| 1822 | - return $f; |
|
| 1823 | - } |
|
| 1824 | - |
|
| 1825 | - // mais d'abord il faut tester le cas des urls sur une |
|
| 1826 | - // base distante |
|
| 1827 | - if ( |
|
| 1828 | - is_string($public) |
|
| 1829 | - and $g = charger_fonction('connect', 'urls', true) |
|
| 1830 | - ) { |
|
| 1831 | - $f = $g; |
|
| 1832 | - } |
|
| 1833 | - |
|
| 1834 | - $res = $f(intval($id), $entite, $args, $ancre, $public); |
|
| 1835 | - } |
|
| 1836 | - if ($res) { |
|
| 1837 | - return $res; |
|
| 1838 | - } |
|
| 1839 | - // Sinon c'est un raccourci ou compat SPIP < 2 |
|
| 1840 | - if (!function_exists($f = 'generer_url_' . $entite)) { |
|
| 1841 | - if (!function_exists($f .= '_dist')) { |
|
| 1842 | - $f = ''; |
|
| 1843 | - } |
|
| 1844 | - } |
|
| 1845 | - if ($f) { |
|
| 1846 | - $url = $f($id, $args, $ancre); |
|
| 1847 | - if (strlen($args)) { |
|
| 1848 | - $url .= strstr($url, '?') |
|
| 1849 | - ? '&' . $args |
|
| 1850 | - : '?' . $args; |
|
| 1851 | - } |
|
| 1852 | - |
|
| 1853 | - return $url; |
|
| 1854 | - } |
|
| 1855 | - // On a ete gentil mais la .... |
|
| 1856 | - spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public"); |
|
| 1857 | - |
|
| 1858 | - return ''; |
|
| 1791 | + if ($public === null) { |
|
| 1792 | + $public = !test_espace_prive(); |
|
| 1793 | + } |
|
| 1794 | + $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1795 | + |
|
| 1796 | + if (!$public) { |
|
| 1797 | + if (!$entite) { |
|
| 1798 | + return ''; |
|
| 1799 | + } |
|
| 1800 | + if (!function_exists('generer_url_ecrire_objet')) { |
|
| 1801 | + include_spip('inc/urls'); |
|
| 1802 | + } |
|
| 1803 | + $res = generer_url_ecrire_objet($entite, $id, $args, $ancre, false); |
|
| 1804 | + } else { |
|
| 1805 | + if ($type === null) { |
|
| 1806 | + $type = (isset($GLOBALS['type_urls'])) |
|
| 1807 | + ? $GLOBALS['type_urls'] // pour surcharge via fichier d'options |
|
| 1808 | + : ((isset($GLOBALS['meta']['type_urls'])) // sinon la config url_etendues |
|
| 1809 | + ? ($GLOBALS['meta']['type_urls']) : 'page'); // sinon type "page" par défaut |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + $f = charger_fonction($type, 'urls', true); |
|
| 1813 | + // se rabattre sur les urls page si les urls perso non dispo |
|
| 1814 | + if (!$f) { |
|
| 1815 | + $f = charger_fonction('page', 'urls', true); |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + // si $entite='', on veut la fonction de passage URL ==> id |
|
| 1819 | + // sinon on veut effectuer le passage id ==> URL |
|
| 1820 | + if (!$entite) { |
|
| 1821 | + return $f; |
|
| 1822 | + } |
|
| 1823 | + |
|
| 1824 | + // mais d'abord il faut tester le cas des urls sur une |
|
| 1825 | + // base distante |
|
| 1826 | + if ( |
|
| 1827 | + is_string($public) |
|
| 1828 | + and $g = charger_fonction('connect', 'urls', true) |
|
| 1829 | + ) { |
|
| 1830 | + $f = $g; |
|
| 1831 | + } |
|
| 1832 | + |
|
| 1833 | + $res = $f(intval($id), $entite, $args, $ancre, $public); |
|
| 1834 | + } |
|
| 1835 | + if ($res) { |
|
| 1836 | + return $res; |
|
| 1837 | + } |
|
| 1838 | + // Sinon c'est un raccourci ou compat SPIP < 2 |
|
| 1839 | + if (!function_exists($f = 'generer_url_' . $entite)) { |
|
| 1840 | + if (!function_exists($f .= '_dist')) { |
|
| 1841 | + $f = ''; |
|
| 1842 | + } |
|
| 1843 | + } |
|
| 1844 | + if ($f) { |
|
| 1845 | + $url = $f($id, $args, $ancre); |
|
| 1846 | + if (strlen($args)) { |
|
| 1847 | + $url .= strstr($url, '?') |
|
| 1848 | + ? '&' . $args |
|
| 1849 | + : '?' . $args; |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + return $url; |
|
| 1853 | + } |
|
| 1854 | + // On a ete gentil mais la .... |
|
| 1855 | + spip_log("generer_url_entite: entite $entite ($f) inconnue $type $public"); |
|
| 1856 | + |
|
| 1857 | + return ''; |
|
| 1859 | 1858 | } |
| 1860 | 1859 | |
| 1861 | 1860 | function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') { |
| 1862 | - $exec = objet_info($entite, 'url_edit'); |
|
| 1863 | - $url = generer_url_ecrire($exec, $args); |
|
| 1864 | - if (intval($id)) { |
|
| 1865 | - $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1866 | - } else { |
|
| 1867 | - $url = parametre_url($url, 'new', 'oui'); |
|
| 1868 | - } |
|
| 1869 | - if ($ancre) { |
|
| 1870 | - $url = ancre_url($url, $ancre); |
|
| 1871 | - } |
|
| 1861 | + $exec = objet_info($entite, 'url_edit'); |
|
| 1862 | + $url = generer_url_ecrire($exec, $args); |
|
| 1863 | + if (intval($id)) { |
|
| 1864 | + $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1865 | + } else { |
|
| 1866 | + $url = parametre_url($url, 'new', 'oui'); |
|
| 1867 | + } |
|
| 1868 | + if ($ancre) { |
|
| 1869 | + $url = ancre_url($url, $ancre); |
|
| 1870 | + } |
|
| 1872 | 1871 | |
| 1873 | - return $url; |
|
| 1872 | + return $url; |
|
| 1874 | 1873 | } |
| 1875 | 1874 | |
| 1876 | 1875 | // https://code.spip.net/@urls_connect_dist |
| 1877 | 1876 | function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) { |
| 1878 | - include_spip('base/connect_sql'); |
|
| 1879 | - $id_type = id_table_objet($entite, $public); |
|
| 1877 | + include_spip('base/connect_sql'); |
|
| 1878 | + $id_type = id_table_objet($entite, $public); |
|
| 1880 | 1879 | |
| 1881 | - return _DIR_RACINE . get_spip_script('./') |
|
| 1882 | - . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1883 | - . (!$args ? '' : "&$args") |
|
| 1884 | - . (!$ancre ? '' : "#$ancre"); |
|
| 1880 | + return _DIR_RACINE . get_spip_script('./') |
|
| 1881 | + . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1882 | + . (!$args ? '' : "&$args") |
|
| 1883 | + . (!$ancre ? '' : "#$ancre"); |
|
| 1885 | 1884 | } |
| 1886 | 1885 | |
| 1887 | 1886 | |
@@ -1892,32 +1891,32 @@ discard block |
||
| 1892 | 1891 | * @return string |
| 1893 | 1892 | */ |
| 1894 | 1893 | function urlencode_1738($url) { |
| 1895 | - if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1896 | - $uri = ''; |
|
| 1897 | - for ($i = 0; $i < strlen($url); $i++) { |
|
| 1898 | - if (ord($a = $url[$i]) > 127) { |
|
| 1899 | - $a = rawurlencode($a); |
|
| 1900 | - } |
|
| 1901 | - $uri .= $a; |
|
| 1902 | - } |
|
| 1903 | - $url = $uri; |
|
| 1904 | - } |
|
| 1894 | + if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1895 | + $uri = ''; |
|
| 1896 | + for ($i = 0; $i < strlen($url); $i++) { |
|
| 1897 | + if (ord($a = $url[$i]) > 127) { |
|
| 1898 | + $a = rawurlencode($a); |
|
| 1899 | + } |
|
| 1900 | + $uri .= $a; |
|
| 1901 | + } |
|
| 1902 | + $url = $uri; |
|
| 1903 | + } |
|
| 1905 | 1904 | |
| 1906 | - return quote_amp($url); |
|
| 1905 | + return quote_amp($url); |
|
| 1907 | 1906 | } |
| 1908 | 1907 | |
| 1909 | 1908 | // https://code.spip.net/@generer_url_entite_absolue |
| 1910 | 1909 | function generer_url_entite_absolue($id = '', $entite = '', $args = '', $ancre = '', $connect = null) { |
| 1911 | - if (!$connect) { |
|
| 1912 | - $connect = true; |
|
| 1913 | - } |
|
| 1914 | - $h = generer_url_entite($id, $entite, $args, $ancre, $connect); |
|
| 1915 | - if (!preg_match(',^\w+:,', $h)) { |
|
| 1916 | - include_spip('inc/filtres_mini'); |
|
| 1917 | - $h = url_absolue($h); |
|
| 1918 | - } |
|
| 1910 | + if (!$connect) { |
|
| 1911 | + $connect = true; |
|
| 1912 | + } |
|
| 1913 | + $h = generer_url_entite($id, $entite, $args, $ancre, $connect); |
|
| 1914 | + if (!preg_match(',^\w+:,', $h)) { |
|
| 1915 | + include_spip('inc/filtres_mini'); |
|
| 1916 | + $h = url_absolue($h); |
|
| 1917 | + } |
|
| 1919 | 1918 | |
| 1920 | - return $h; |
|
| 1919 | + return $h; |
|
| 1921 | 1920 | } |
| 1922 | 1921 | |
| 1923 | 1922 | |
@@ -1933,11 +1932,11 @@ discard block |
||
| 1933 | 1932 | * true si la valeur est considérée active ; false sinon. |
| 1934 | 1933 | **/ |
| 1935 | 1934 | function test_valeur_serveur($truc) { |
| 1936 | - if (!$truc) { |
|
| 1937 | - return false; |
|
| 1938 | - } |
|
| 1935 | + if (!$truc) { |
|
| 1936 | + return false; |
|
| 1937 | + } |
|
| 1939 | 1938 | |
| 1940 | - return (strtolower($truc) !== 'off'); |
|
| 1939 | + return (strtolower($truc) !== 'off'); |
|
| 1941 | 1940 | } |
| 1942 | 1941 | |
| 1943 | 1942 | // |
@@ -1965,82 +1964,82 @@ discard block |
||
| 1965 | 1964 | */ |
| 1966 | 1965 | function url_de_base($profondeur = null) { |
| 1967 | 1966 | |
| 1968 | - static $url = []; |
|
| 1969 | - if (is_array($profondeur)) { |
|
| 1970 | - return $url = $profondeur; |
|
| 1971 | - } |
|
| 1972 | - if ($profondeur === false) { |
|
| 1973 | - return $url; |
|
| 1974 | - } |
|
| 1975 | - |
|
| 1976 | - if (is_null($profondeur)) { |
|
| 1977 | - $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 1978 | - } |
|
| 1979 | - |
|
| 1980 | - if (isset($url[$profondeur])) { |
|
| 1981 | - return $url[$profondeur]; |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - $http = 'http'; |
|
| 1985 | - |
|
| 1986 | - if ( |
|
| 1987 | - isset($_SERVER['SCRIPT_URI']) |
|
| 1988 | - and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https' |
|
| 1989 | - ) { |
|
| 1990 | - $http = 'https'; |
|
| 1991 | - } elseif ( |
|
| 1992 | - isset($_SERVER['HTTPS']) |
|
| 1993 | - and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 1994 | - ) { |
|
| 1995 | - $http = 'https'; |
|
| 1996 | - } |
|
| 1997 | - |
|
| 1998 | - // note : HTTP_HOST contient le :port si necessaire |
|
| 1999 | - $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
|
| 2000 | - // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2001 | - if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2002 | - $host = $GLOBALS['meta']['adresse_site']; |
|
| 2003 | - if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2004 | - $http = $scheme; |
|
| 2005 | - $host = str_replace("{$scheme}://", '', $host); |
|
| 2006 | - } |
|
| 2007 | - } |
|
| 2008 | - if ( |
|
| 2009 | - isset($_SERVER['SERVER_PORT']) |
|
| 2010 | - and $port = $_SERVER['SERVER_PORT'] |
|
| 2011 | - and strpos($host, ':') == false |
|
| 2012 | - ) { |
|
| 2013 | - if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2014 | - define('_PORT_HTTP_STANDARD', '80'); |
|
| 2015 | - } |
|
| 2016 | - if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2017 | - define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2018 | - } |
|
| 2019 | - if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2020 | - $host .= ":$port"; |
|
| 2021 | - } |
|
| 2022 | - if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2023 | - $host .= ":$port"; |
|
| 2024 | - } |
|
| 2025 | - } |
|
| 2026 | - |
|
| 2027 | - if (!$GLOBALS['REQUEST_URI']) { |
|
| 2028 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2029 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2030 | - } else { |
|
| 2031 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2032 | - if ( |
|
| 2033 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2034 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2035 | - ) { |
|
| 2036 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2037 | - } |
|
| 2038 | - } |
|
| 2039 | - } |
|
| 2040 | - |
|
| 2041 | - $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2042 | - |
|
| 2043 | - return $url[$profondeur]; |
|
| 1967 | + static $url = []; |
|
| 1968 | + if (is_array($profondeur)) { |
|
| 1969 | + return $url = $profondeur; |
|
| 1970 | + } |
|
| 1971 | + if ($profondeur === false) { |
|
| 1972 | + return $url; |
|
| 1973 | + } |
|
| 1974 | + |
|
| 1975 | + if (is_null($profondeur)) { |
|
| 1976 | + $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 1977 | + } |
|
| 1978 | + |
|
| 1979 | + if (isset($url[$profondeur])) { |
|
| 1980 | + return $url[$profondeur]; |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + $http = 'http'; |
|
| 1984 | + |
|
| 1985 | + if ( |
|
| 1986 | + isset($_SERVER['SCRIPT_URI']) |
|
| 1987 | + and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https' |
|
| 1988 | + ) { |
|
| 1989 | + $http = 'https'; |
|
| 1990 | + } elseif ( |
|
| 1991 | + isset($_SERVER['HTTPS']) |
|
| 1992 | + and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 1993 | + ) { |
|
| 1994 | + $http = 'https'; |
|
| 1995 | + } |
|
| 1996 | + |
|
| 1997 | + // note : HTTP_HOST contient le :port si necessaire |
|
| 1998 | + $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null; |
|
| 1999 | + // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2000 | + if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2001 | + $host = $GLOBALS['meta']['adresse_site']; |
|
| 2002 | + if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2003 | + $http = $scheme; |
|
| 2004 | + $host = str_replace("{$scheme}://", '', $host); |
|
| 2005 | + } |
|
| 2006 | + } |
|
| 2007 | + if ( |
|
| 2008 | + isset($_SERVER['SERVER_PORT']) |
|
| 2009 | + and $port = $_SERVER['SERVER_PORT'] |
|
| 2010 | + and strpos($host, ':') == false |
|
| 2011 | + ) { |
|
| 2012 | + if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2013 | + define('_PORT_HTTP_STANDARD', '80'); |
|
| 2014 | + } |
|
| 2015 | + if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2016 | + define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2017 | + } |
|
| 2018 | + if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2019 | + $host .= ":$port"; |
|
| 2020 | + } |
|
| 2021 | + if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2022 | + $host .= ":$port"; |
|
| 2023 | + } |
|
| 2024 | + } |
|
| 2025 | + |
|
| 2026 | + if (!$GLOBALS['REQUEST_URI']) { |
|
| 2027 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2028 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2029 | + } else { |
|
| 2030 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2031 | + if ( |
|
| 2032 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2033 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2034 | + ) { |
|
| 2035 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2036 | + } |
|
| 2037 | + } |
|
| 2038 | + } |
|
| 2039 | + |
|
| 2040 | + $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2041 | + |
|
| 2042 | + return $url[$profondeur]; |
|
| 2044 | 2043 | } |
| 2045 | 2044 | |
| 2046 | 2045 | /** |
@@ -2053,26 +2052,26 @@ discard block |
||
| 2053 | 2052 | * @return string |
| 2054 | 2053 | */ |
| 2055 | 2054 | function url_de_($http, $host, $request, $prof = 0) { |
| 2056 | - $prof = max($prof, 0); |
|
| 2055 | + $prof = max($prof, 0); |
|
| 2057 | 2056 | |
| 2058 | - $myself = ltrim($request, '/'); |
|
| 2059 | - # supprimer la chaine de GET |
|
| 2060 | - list($myself) = explode('?', $myself); |
|
| 2061 | - // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2062 | - // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2063 | - if (strpos($myself, '://') !== false) { |
|
| 2064 | - $myself = explode('://', $myself); |
|
| 2065 | - array_shift($myself); |
|
| 2066 | - $myself = implode('://', $myself); |
|
| 2067 | - $myself = explode('/', $myself); |
|
| 2068 | - array_shift($myself); |
|
| 2069 | - $myself = implode('/', $myself); |
|
| 2070 | - } |
|
| 2071 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2057 | + $myself = ltrim($request, '/'); |
|
| 2058 | + # supprimer la chaine de GET |
|
| 2059 | + list($myself) = explode('?', $myself); |
|
| 2060 | + // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2061 | + // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2062 | + if (strpos($myself, '://') !== false) { |
|
| 2063 | + $myself = explode('://', $myself); |
|
| 2064 | + array_shift($myself); |
|
| 2065 | + $myself = implode('://', $myself); |
|
| 2066 | + $myself = explode('/', $myself); |
|
| 2067 | + array_shift($myself); |
|
| 2068 | + $myself = implode('/', $myself); |
|
| 2069 | + } |
|
| 2070 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2072 | 2071 | |
| 2073 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2072 | + $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2074 | 2073 | |
| 2075 | - return $url; |
|
| 2074 | + return $url; |
|
| 2076 | 2075 | } |
| 2077 | 2076 | |
| 2078 | 2077 | |
@@ -2107,26 +2106,26 @@ discard block |
||
| 2107 | 2106 | * @return string URL |
| 2108 | 2107 | **/ |
| 2109 | 2108 | function generer_url_ecrire($script = '', $args = '', $no_entities = false, $rel = false) { |
| 2110 | - if (!$rel) { |
|
| 2111 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2112 | - } else { |
|
| 2113 | - if (!is_string($rel)) { |
|
| 2114 | - $rel = _DIR_RESTREINT ? _DIR_RESTREINT : |
|
| 2115 | - ('./' . _SPIP_ECRIRE_SCRIPT); |
|
| 2116 | - } |
|
| 2117 | - } |
|
| 2118 | - |
|
| 2119 | - list($script, $ancre) = array_pad(explode('#', $script), 2, null); |
|
| 2120 | - if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2121 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2122 | - } elseif ($args) { |
|
| 2123 | - $args = "?$args"; |
|
| 2124 | - } |
|
| 2125 | - if ($ancre) { |
|
| 2126 | - $args .= "#$ancre"; |
|
| 2127 | - } |
|
| 2128 | - |
|
| 2129 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2109 | + if (!$rel) { |
|
| 2110 | + $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2111 | + } else { |
|
| 2112 | + if (!is_string($rel)) { |
|
| 2113 | + $rel = _DIR_RESTREINT ? _DIR_RESTREINT : |
|
| 2114 | + ('./' . _SPIP_ECRIRE_SCRIPT); |
|
| 2115 | + } |
|
| 2116 | + } |
|
| 2117 | + |
|
| 2118 | + list($script, $ancre) = array_pad(explode('#', $script), 2, null); |
|
| 2119 | + if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2120 | + $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2121 | + } elseif ($args) { |
|
| 2122 | + $args = "?$args"; |
|
| 2123 | + } |
|
| 2124 | + if ($ancre) { |
|
| 2125 | + $args .= "#$ancre"; |
|
| 2126 | + } |
|
| 2127 | + |
|
| 2128 | + return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2130 | 2129 | } |
| 2131 | 2130 | |
| 2132 | 2131 | // |
@@ -2148,15 +2147,15 @@ discard block |
||
| 2148 | 2147 | * Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut |
| 2149 | 2148 | **/ |
| 2150 | 2149 | function get_spip_script($default = '') { |
| 2151 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2152 | - return 'spip.php'; |
|
| 2153 | - } |
|
| 2154 | - # cas define('_SPIP_SCRIPT', ''); |
|
| 2155 | - if (_SPIP_SCRIPT) { |
|
| 2156 | - return _SPIP_SCRIPT; |
|
| 2157 | - } else { |
|
| 2158 | - return $default; |
|
| 2159 | - } |
|
| 2150 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2151 | + return 'spip.php'; |
|
| 2152 | + } |
|
| 2153 | + # cas define('_SPIP_SCRIPT', ''); |
|
| 2154 | + if (_SPIP_SCRIPT) { |
|
| 2155 | + return _SPIP_SCRIPT; |
|
| 2156 | + } else { |
|
| 2157 | + return $default; |
|
| 2158 | + } |
|
| 2160 | 2159 | } |
| 2161 | 2160 | |
| 2162 | 2161 | /** |
@@ -2185,39 +2184,39 @@ discard block |
||
| 2185 | 2184 | * @return string URL |
| 2186 | 2185 | **/ |
| 2187 | 2186 | function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') { |
| 2188 | - // si le script est une action (spip_pass, spip_inscription), |
|
| 2189 | - // standardiser vers la nouvelle API |
|
| 2190 | - |
|
| 2191 | - if (!$action) { |
|
| 2192 | - $action = get_spip_script(); |
|
| 2193 | - } |
|
| 2194 | - if ($script) { |
|
| 2195 | - $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2196 | - } |
|
| 2197 | - |
|
| 2198 | - if ($args) { |
|
| 2199 | - if (is_array($args)) { |
|
| 2200 | - $r = ''; |
|
| 2201 | - foreach ($args as $k => $v) { |
|
| 2202 | - $r .= '&' . $k . '=' . $v; |
|
| 2203 | - } |
|
| 2204 | - $args = substr($r, 1); |
|
| 2205 | - } |
|
| 2206 | - $action .= |
|
| 2207 | - (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2208 | - } |
|
| 2209 | - if (!$no_entities) { |
|
| 2210 | - $action = quote_amp($action); |
|
| 2211 | - } |
|
| 2212 | - |
|
| 2213 | - // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2214 | - return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2187 | + // si le script est une action (spip_pass, spip_inscription), |
|
| 2188 | + // standardiser vers la nouvelle API |
|
| 2189 | + |
|
| 2190 | + if (!$action) { |
|
| 2191 | + $action = get_spip_script(); |
|
| 2192 | + } |
|
| 2193 | + if ($script) { |
|
| 2194 | + $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2195 | + } |
|
| 2196 | + |
|
| 2197 | + if ($args) { |
|
| 2198 | + if (is_array($args)) { |
|
| 2199 | + $r = ''; |
|
| 2200 | + foreach ($args as $k => $v) { |
|
| 2201 | + $r .= '&' . $k . '=' . $v; |
|
| 2202 | + } |
|
| 2203 | + $args = substr($r, 1); |
|
| 2204 | + } |
|
| 2205 | + $action .= |
|
| 2206 | + (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2207 | + } |
|
| 2208 | + if (!$no_entities) { |
|
| 2209 | + $action = quote_amp($action); |
|
| 2210 | + } |
|
| 2211 | + |
|
| 2212 | + // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2213 | + return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2215 | 2214 | } |
| 2216 | 2215 | |
| 2217 | 2216 | // https://code.spip.net/@generer_url_prive |
| 2218 | 2217 | function generer_url_prive($script, $args = '', $no_entities = false) { |
| 2219 | 2218 | |
| 2220 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2219 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2221 | 2220 | } |
| 2222 | 2221 | |
| 2223 | 2222 | // Pour les formulaires en methode POST, |
@@ -2242,19 +2241,19 @@ discard block |
||
| 2242 | 2241 | **/ |
| 2243 | 2242 | function generer_form_ecrire($script, $corps, $atts = '', $submit = '') { |
| 2244 | 2243 | |
| 2245 | - $script1 = explode('&', $script); |
|
| 2246 | - $script1 = reset($script1); |
|
| 2244 | + $script1 = explode('&', $script); |
|
| 2245 | + $script1 = reset($script1); |
|
| 2247 | 2246 | |
| 2248 | - return "<form action='" |
|
| 2249 | - . ($script ? generer_url_ecrire($script) : '') |
|
| 2250 | - . "' " |
|
| 2251 | - . ($atts ? $atts : " method='post'") |
|
| 2252 | - . "><div>\n" |
|
| 2253 | - . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2254 | - . $corps |
|
| 2255 | - . (!$submit ? '' : |
|
| 2256 | - ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2257 | - . "</div></form>\n"; |
|
| 2247 | + return "<form action='" |
|
| 2248 | + . ($script ? generer_url_ecrire($script) : '') |
|
| 2249 | + . "' " |
|
| 2250 | + . ($atts ? $atts : " method='post'") |
|
| 2251 | + . "><div>\n" |
|
| 2252 | + . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2253 | + . $corps |
|
| 2254 | + . (!$submit ? '' : |
|
| 2255 | + ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2256 | + . "</div></form>\n"; |
|
| 2258 | 2257 | } |
| 2259 | 2258 | |
| 2260 | 2259 | /** |
@@ -2271,22 +2270,22 @@ discard block |
||
| 2271 | 2270 | * @return string |
| 2272 | 2271 | */ |
| 2273 | 2272 | function generer_form_action($script, $corps, $atts = '', $public = false) { |
| 2274 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2275 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2276 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2277 | - $h = (_DIR_RACINE and !$public) |
|
| 2278 | - ? generer_url_ecrire(_request('exec')) |
|
| 2279 | - : generer_url_public(); |
|
| 2273 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2274 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2275 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2276 | + $h = (_DIR_RACINE and !$public) |
|
| 2277 | + ? generer_url_ecrire(_request('exec')) |
|
| 2278 | + : generer_url_public(); |
|
| 2280 | 2279 | |
| 2281 | - return "\n<form action='" . |
|
| 2282 | - $h . |
|
| 2283 | - "'" . |
|
| 2284 | - $atts . |
|
| 2285 | - ">\n" . |
|
| 2286 | - '<div>' . |
|
| 2287 | - "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2288 | - $corps . |
|
| 2289 | - '</div></form>'; |
|
| 2280 | + return "\n<form action='" . |
|
| 2281 | + $h . |
|
| 2282 | + "'" . |
|
| 2283 | + $atts . |
|
| 2284 | + ">\n" . |
|
| 2285 | + '<div>' . |
|
| 2286 | + "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2287 | + $corps . |
|
| 2288 | + '</div></form>'; |
|
| 2290 | 2289 | } |
| 2291 | 2290 | |
| 2292 | 2291 | /** |
@@ -2305,22 +2304,22 @@ discard block |
||
| 2305 | 2304 | * URL |
| 2306 | 2305 | */ |
| 2307 | 2306 | function generer_url_action($script, $args = '', $no_entities = false, $public = false) { |
| 2308 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2309 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2310 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2311 | - $url = (_DIR_RACINE and !$public) |
|
| 2312 | - ? generer_url_ecrire(_request('exec')) |
|
| 2313 | - : generer_url_public('', '', false, false); |
|
| 2314 | - $url = parametre_url($url, 'action', $script); |
|
| 2315 | - if ($args) { |
|
| 2316 | - $url .= quote_amp('&' . $args); |
|
| 2317 | - } |
|
| 2307 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2308 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2309 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2310 | + $url = (_DIR_RACINE and !$public) |
|
| 2311 | + ? generer_url_ecrire(_request('exec')) |
|
| 2312 | + : generer_url_public('', '', false, false); |
|
| 2313 | + $url = parametre_url($url, 'action', $script); |
|
| 2314 | + if ($args) { |
|
| 2315 | + $url .= quote_amp('&' . $args); |
|
| 2316 | + } |
|
| 2318 | 2317 | |
| 2319 | - if ($no_entities) { |
|
| 2320 | - $url = str_replace('&', '&', $url); |
|
| 2321 | - } |
|
| 2318 | + if ($no_entities) { |
|
| 2319 | + $url = str_replace('&', '&', $url); |
|
| 2320 | + } |
|
| 2322 | 2321 | |
| 2323 | - return $url; |
|
| 2322 | + return $url; |
|
| 2324 | 2323 | } |
| 2325 | 2324 | |
| 2326 | 2325 | |
@@ -2333,8 +2332,8 @@ discard block |
||
| 2333 | 2332 | * @param string $ta Répertoire temporaire accessible |
| 2334 | 2333 | */ |
| 2335 | 2334 | function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2336 | - spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2337 | - spip_initialisation_suite(); |
|
| 2335 | + spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2336 | + spip_initialisation_suite(); |
|
| 2338 | 2337 | } |
| 2339 | 2338 | |
| 2340 | 2339 | /** |
@@ -2354,322 +2353,322 @@ discard block |
||
| 2354 | 2353 | * @param string $ta Répertoire temporaire accessible |
| 2355 | 2354 | */ |
| 2356 | 2355 | function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2357 | - static $too_late = 0; |
|
| 2358 | - if ($too_late++) { |
|
| 2359 | - return; |
|
| 2360 | - } |
|
| 2361 | - |
|
| 2362 | - // Declaration des repertoires |
|
| 2363 | - |
|
| 2364 | - // le nom du repertoire plugins/ activables/desactivables |
|
| 2365 | - if (!defined('_DIR_PLUGINS')) { |
|
| 2366 | - define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2367 | - } |
|
| 2368 | - |
|
| 2369 | - // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2370 | - if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2371 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2372 | - } |
|
| 2373 | - |
|
| 2374 | - // le nom du repertoire des librairies |
|
| 2375 | - if (!defined('_DIR_LIB')) { |
|
| 2376 | - define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2377 | - } |
|
| 2378 | - |
|
| 2379 | - if (!defined('_DIR_IMG')) { |
|
| 2380 | - define('_DIR_IMG', $pa); |
|
| 2381 | - } |
|
| 2382 | - if (!defined('_DIR_LOGOS')) { |
|
| 2383 | - define('_DIR_LOGOS', $pa); |
|
| 2384 | - } |
|
| 2385 | - if (!defined('_DIR_IMG_ICONES')) { |
|
| 2386 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2387 | - } |
|
| 2388 | - |
|
| 2389 | - if (!defined('_DIR_DUMP')) { |
|
| 2390 | - define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2391 | - } |
|
| 2392 | - if (!defined('_DIR_SESSIONS')) { |
|
| 2393 | - define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2394 | - } |
|
| 2395 | - if (!defined('_DIR_TRANSFERT')) { |
|
| 2396 | - define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2397 | - } |
|
| 2398 | - if (!defined('_DIR_CACHE')) { |
|
| 2399 | - define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2400 | - } |
|
| 2401 | - if (!defined('_DIR_CACHE_XML')) { |
|
| 2402 | - define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2403 | - } |
|
| 2404 | - if (!defined('_DIR_SKELS')) { |
|
| 2405 | - define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2406 | - } |
|
| 2407 | - if (!defined('_DIR_AIDE')) { |
|
| 2408 | - define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2409 | - } |
|
| 2410 | - if (!defined('_DIR_TMP')) { |
|
| 2411 | - define('_DIR_TMP', $ti); |
|
| 2412 | - } |
|
| 2413 | - |
|
| 2414 | - if (!defined('_DIR_VAR')) { |
|
| 2415 | - define('_DIR_VAR', $ta); |
|
| 2416 | - } |
|
| 2417 | - |
|
| 2418 | - if (!defined('_DIR_ETC')) { |
|
| 2419 | - define('_DIR_ETC', $pi); |
|
| 2420 | - } |
|
| 2421 | - if (!defined('_DIR_CONNECT')) { |
|
| 2422 | - define('_DIR_CONNECT', $pi); |
|
| 2423 | - } |
|
| 2424 | - if (!defined('_DIR_CHMOD')) { |
|
| 2425 | - define('_DIR_CHMOD', $pi); |
|
| 2426 | - } |
|
| 2427 | - |
|
| 2428 | - if (!isset($GLOBALS['test_dirs'])) { |
|
| 2429 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2430 | - // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2431 | - $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2432 | - } |
|
| 2433 | - |
|
| 2434 | - // Declaration des fichiers |
|
| 2435 | - |
|
| 2436 | - if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2437 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2438 | - } |
|
| 2439 | - if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2440 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2441 | - } |
|
| 2442 | - if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2443 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2444 | - } |
|
| 2445 | - if (!defined('_CACHE_PIPELINES')) { |
|
| 2446 | - define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2447 | - } |
|
| 2448 | - if (!defined('_CACHE_CHEMIN')) { |
|
| 2449 | - define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2450 | - } |
|
| 2451 | - |
|
| 2452 | - # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2453 | - if (!defined('_FILE_META')) { |
|
| 2454 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2455 | - } |
|
| 2456 | - if (!defined('_DIR_LOG')) { |
|
| 2457 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2458 | - } |
|
| 2459 | - if (!defined('_FILE_LOG')) { |
|
| 2460 | - define('_FILE_LOG', 'spip'); |
|
| 2461 | - } |
|
| 2462 | - if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2463 | - define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2464 | - } |
|
| 2465 | - |
|
| 2466 | - // Le fichier de connexion a la base de donnees |
|
| 2467 | - // tient compte des anciennes versions (inc_connect...) |
|
| 2468 | - if (!defined('_FILE_CONNECT_INS')) { |
|
| 2469 | - define('_FILE_CONNECT_INS', 'connect'); |
|
| 2470 | - } |
|
| 2471 | - if (!defined('_FILE_CONNECT')) { |
|
| 2472 | - define( |
|
| 2473 | - '_FILE_CONNECT', |
|
| 2474 | - (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2475 | - : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2476 | - : false)) |
|
| 2477 | - ); |
|
| 2478 | - } |
|
| 2479 | - |
|
| 2480 | - // Le fichier de reglages des droits |
|
| 2481 | - if (!defined('_FILE_CHMOD_INS')) { |
|
| 2482 | - define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2483 | - } |
|
| 2484 | - if (!defined('_FILE_CHMOD')) { |
|
| 2485 | - define( |
|
| 2486 | - '_FILE_CHMOD', |
|
| 2487 | - (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2488 | - : false) |
|
| 2489 | - ); |
|
| 2490 | - } |
|
| 2491 | - |
|
| 2492 | - if (!defined('_FILE_LDAP')) { |
|
| 2493 | - define('_FILE_LDAP', 'ldap.php'); |
|
| 2494 | - } |
|
| 2495 | - |
|
| 2496 | - if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2497 | - define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2498 | - } |
|
| 2499 | - if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2500 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2501 | - } |
|
| 2502 | - if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2503 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2504 | - } |
|
| 2505 | - |
|
| 2506 | - // Definition des droits d'acces en ecriture |
|
| 2507 | - if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2508 | - include_once _FILE_CHMOD; |
|
| 2509 | - } |
|
| 2510 | - |
|
| 2511 | - // Se mefier des fichiers mal remplis! |
|
| 2512 | - if (!defined('_SPIP_CHMOD')) { |
|
| 2513 | - define('_SPIP_CHMOD', 0777); |
|
| 2514 | - } |
|
| 2515 | - |
|
| 2516 | - if (!defined('_DEFAULT_CHARSET')) { |
|
| 2517 | - /** Le charset par défaut lors de l'installation */ |
|
| 2518 | - define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2519 | - } |
|
| 2520 | - if (!defined('_ROOT_PLUGINS')) { |
|
| 2521 | - define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2522 | - } |
|
| 2523 | - if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2524 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2525 | - } |
|
| 2526 | - if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2527 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2528 | - } |
|
| 2529 | - |
|
| 2530 | - // La taille des Log |
|
| 2531 | - if (!defined('_MAX_LOG')) { |
|
| 2532 | - define('_MAX_LOG', 100); |
|
| 2533 | - } |
|
| 2534 | - |
|
| 2535 | - // Sommes-nous dans l'empire du Mal ? |
|
| 2536 | - // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2537 | - if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2538 | - if (!defined('_OS_SERVEUR')) { |
|
| 2539 | - define('_OS_SERVEUR', 'windows'); |
|
| 2540 | - } |
|
| 2541 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2542 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2543 | - } // utiliser le flock php |
|
| 2544 | - } else { |
|
| 2545 | - if (!defined('_OS_SERVEUR')) { |
|
| 2546 | - define('_OS_SERVEUR', ''); |
|
| 2547 | - } |
|
| 2548 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2549 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2550 | - } // utiliser le flock php |
|
| 2551 | - #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2552 | - } |
|
| 2553 | - |
|
| 2554 | - // Langue par defaut |
|
| 2555 | - if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2556 | - define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2557 | - } |
|
| 2558 | - |
|
| 2559 | - // |
|
| 2560 | - // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2561 | - // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2562 | - // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2563 | - // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2564 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2565 | - |
|
| 2566 | - // charger tout de suite le path et son cache |
|
| 2567 | - load_path_cache(); |
|
| 2568 | - |
|
| 2569 | - // *********** traiter les variables ************ |
|
| 2570 | - |
|
| 2571 | - // |
|
| 2572 | - // Securite |
|
| 2573 | - // |
|
| 2574 | - |
|
| 2575 | - // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2576 | - if (isset($_REQUEST['GLOBALS'])) { |
|
| 2577 | - die(); |
|
| 2578 | - } |
|
| 2579 | - // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2580 | - spip_desinfecte($_GET); |
|
| 2581 | - spip_desinfecte($_POST); |
|
| 2582 | - spip_desinfecte($_COOKIE); |
|
| 2583 | - spip_desinfecte($_REQUEST); |
|
| 2584 | - |
|
| 2585 | - // appliquer le cookie_prefix |
|
| 2586 | - if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2587 | - include_spip('inc/cookie'); |
|
| 2588 | - recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2589 | - } |
|
| 2590 | - |
|
| 2591 | - // |
|
| 2592 | - // Capacites php (en fonction de la version) |
|
| 2593 | - // |
|
| 2594 | - $GLOBALS['flag_ob'] = (function_exists('ob_start') |
|
| 2595 | - && function_exists('ini_get') |
|
| 2596 | - && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2597 | - $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name'); |
|
| 2598 | - $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ''); |
|
| 2599 | - $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2600 | - (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2601 | - |
|
| 2602 | - |
|
| 2603 | - // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2604 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2605 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2606 | - } else { |
|
| 2607 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2608 | - if ( |
|
| 2609 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2610 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2611 | - ) { |
|
| 2612 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2613 | - } |
|
| 2614 | - } |
|
| 2615 | - |
|
| 2616 | - // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2617 | - if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2618 | - define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2619 | - } |
|
| 2620 | - if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2621 | - define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2622 | - } |
|
| 2623 | - |
|
| 2624 | - // charger les meta si possible et renouveller l'alea au besoin |
|
| 2625 | - // charge aussi effacer_meta et ecrire_meta |
|
| 2626 | - $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2627 | - $inc_meta(); |
|
| 2628 | - |
|
| 2629 | - // nombre de repertoires depuis la racine |
|
| 2630 | - // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2631 | - // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2632 | - // le calcul est faux) |
|
| 2633 | - if (!_DIR_RESTREINT) { |
|
| 2634 | - $GLOBALS['profondeur_url'] = 1; |
|
| 2635 | - } else { |
|
| 2636 | - $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2637 | - $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2638 | - if ( |
|
| 2639 | - !$uri_ref |
|
| 2640 | - // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2641 | - // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2642 | - // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2643 | - // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2644 | - or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2645 | - ) { |
|
| 2646 | - if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2647 | - $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2648 | - $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/'; |
|
| 2649 | - } else { |
|
| 2650 | - $uri_ref = ''; |
|
| 2651 | - } |
|
| 2652 | - } |
|
| 2653 | - if (!$uri or !$uri_ref) { |
|
| 2654 | - $GLOBALS['profondeur_url'] = 0; |
|
| 2655 | - } else { |
|
| 2656 | - $GLOBALS['profondeur_url'] = max( |
|
| 2657 | - 0, |
|
| 2658 | - substr_count($uri[0], '/') |
|
| 2659 | - - substr_count($uri_ref, '/') |
|
| 2660 | - ); |
|
| 2661 | - } |
|
| 2662 | - } |
|
| 2663 | - // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2664 | - if (_FILE_CONNECT) { |
|
| 2665 | - if ( |
|
| 2666 | - verifier_visiteur() == '0minirezo' |
|
| 2667 | - // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2668 | - and !isset($_COOKIE['spip_admin']) |
|
| 2669 | - ) { |
|
| 2670 | - clear_path_cache(); |
|
| 2671 | - } |
|
| 2672 | - } |
|
| 2356 | + static $too_late = 0; |
|
| 2357 | + if ($too_late++) { |
|
| 2358 | + return; |
|
| 2359 | + } |
|
| 2360 | + |
|
| 2361 | + // Declaration des repertoires |
|
| 2362 | + |
|
| 2363 | + // le nom du repertoire plugins/ activables/desactivables |
|
| 2364 | + if (!defined('_DIR_PLUGINS')) { |
|
| 2365 | + define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2366 | + } |
|
| 2367 | + |
|
| 2368 | + // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2369 | + if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2370 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2371 | + } |
|
| 2372 | + |
|
| 2373 | + // le nom du repertoire des librairies |
|
| 2374 | + if (!defined('_DIR_LIB')) { |
|
| 2375 | + define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2376 | + } |
|
| 2377 | + |
|
| 2378 | + if (!defined('_DIR_IMG')) { |
|
| 2379 | + define('_DIR_IMG', $pa); |
|
| 2380 | + } |
|
| 2381 | + if (!defined('_DIR_LOGOS')) { |
|
| 2382 | + define('_DIR_LOGOS', $pa); |
|
| 2383 | + } |
|
| 2384 | + if (!defined('_DIR_IMG_ICONES')) { |
|
| 2385 | + define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2386 | + } |
|
| 2387 | + |
|
| 2388 | + if (!defined('_DIR_DUMP')) { |
|
| 2389 | + define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2390 | + } |
|
| 2391 | + if (!defined('_DIR_SESSIONS')) { |
|
| 2392 | + define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2393 | + } |
|
| 2394 | + if (!defined('_DIR_TRANSFERT')) { |
|
| 2395 | + define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2396 | + } |
|
| 2397 | + if (!defined('_DIR_CACHE')) { |
|
| 2398 | + define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2399 | + } |
|
| 2400 | + if (!defined('_DIR_CACHE_XML')) { |
|
| 2401 | + define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2402 | + } |
|
| 2403 | + if (!defined('_DIR_SKELS')) { |
|
| 2404 | + define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2405 | + } |
|
| 2406 | + if (!defined('_DIR_AIDE')) { |
|
| 2407 | + define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2408 | + } |
|
| 2409 | + if (!defined('_DIR_TMP')) { |
|
| 2410 | + define('_DIR_TMP', $ti); |
|
| 2411 | + } |
|
| 2412 | + |
|
| 2413 | + if (!defined('_DIR_VAR')) { |
|
| 2414 | + define('_DIR_VAR', $ta); |
|
| 2415 | + } |
|
| 2416 | + |
|
| 2417 | + if (!defined('_DIR_ETC')) { |
|
| 2418 | + define('_DIR_ETC', $pi); |
|
| 2419 | + } |
|
| 2420 | + if (!defined('_DIR_CONNECT')) { |
|
| 2421 | + define('_DIR_CONNECT', $pi); |
|
| 2422 | + } |
|
| 2423 | + if (!defined('_DIR_CHMOD')) { |
|
| 2424 | + define('_DIR_CHMOD', $pi); |
|
| 2425 | + } |
|
| 2426 | + |
|
| 2427 | + if (!isset($GLOBALS['test_dirs'])) { |
|
| 2428 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2429 | + // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2430 | + $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2431 | + } |
|
| 2432 | + |
|
| 2433 | + // Declaration des fichiers |
|
| 2434 | + |
|
| 2435 | + if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2436 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2437 | + } |
|
| 2438 | + if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2439 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2440 | + } |
|
| 2441 | + if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2442 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2443 | + } |
|
| 2444 | + if (!defined('_CACHE_PIPELINES')) { |
|
| 2445 | + define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2446 | + } |
|
| 2447 | + if (!defined('_CACHE_CHEMIN')) { |
|
| 2448 | + define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2449 | + } |
|
| 2450 | + |
|
| 2451 | + # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2452 | + if (!defined('_FILE_META')) { |
|
| 2453 | + define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2454 | + } |
|
| 2455 | + if (!defined('_DIR_LOG')) { |
|
| 2456 | + define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2457 | + } |
|
| 2458 | + if (!defined('_FILE_LOG')) { |
|
| 2459 | + define('_FILE_LOG', 'spip'); |
|
| 2460 | + } |
|
| 2461 | + if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2462 | + define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2463 | + } |
|
| 2464 | + |
|
| 2465 | + // Le fichier de connexion a la base de donnees |
|
| 2466 | + // tient compte des anciennes versions (inc_connect...) |
|
| 2467 | + if (!defined('_FILE_CONNECT_INS')) { |
|
| 2468 | + define('_FILE_CONNECT_INS', 'connect'); |
|
| 2469 | + } |
|
| 2470 | + if (!defined('_FILE_CONNECT')) { |
|
| 2471 | + define( |
|
| 2472 | + '_FILE_CONNECT', |
|
| 2473 | + (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2474 | + : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2475 | + : false)) |
|
| 2476 | + ); |
|
| 2477 | + } |
|
| 2478 | + |
|
| 2479 | + // Le fichier de reglages des droits |
|
| 2480 | + if (!defined('_FILE_CHMOD_INS')) { |
|
| 2481 | + define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2482 | + } |
|
| 2483 | + if (!defined('_FILE_CHMOD')) { |
|
| 2484 | + define( |
|
| 2485 | + '_FILE_CHMOD', |
|
| 2486 | + (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2487 | + : false) |
|
| 2488 | + ); |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + if (!defined('_FILE_LDAP')) { |
|
| 2492 | + define('_FILE_LDAP', 'ldap.php'); |
|
| 2493 | + } |
|
| 2494 | + |
|
| 2495 | + if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2496 | + define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2497 | + } |
|
| 2498 | + if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2499 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2500 | + } |
|
| 2501 | + if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2502 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2503 | + } |
|
| 2504 | + |
|
| 2505 | + // Definition des droits d'acces en ecriture |
|
| 2506 | + if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2507 | + include_once _FILE_CHMOD; |
|
| 2508 | + } |
|
| 2509 | + |
|
| 2510 | + // Se mefier des fichiers mal remplis! |
|
| 2511 | + if (!defined('_SPIP_CHMOD')) { |
|
| 2512 | + define('_SPIP_CHMOD', 0777); |
|
| 2513 | + } |
|
| 2514 | + |
|
| 2515 | + if (!defined('_DEFAULT_CHARSET')) { |
|
| 2516 | + /** Le charset par défaut lors de l'installation */ |
|
| 2517 | + define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2518 | + } |
|
| 2519 | + if (!defined('_ROOT_PLUGINS')) { |
|
| 2520 | + define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2521 | + } |
|
| 2522 | + if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2523 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2524 | + } |
|
| 2525 | + if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2526 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2527 | + } |
|
| 2528 | + |
|
| 2529 | + // La taille des Log |
|
| 2530 | + if (!defined('_MAX_LOG')) { |
|
| 2531 | + define('_MAX_LOG', 100); |
|
| 2532 | + } |
|
| 2533 | + |
|
| 2534 | + // Sommes-nous dans l'empire du Mal ? |
|
| 2535 | + // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2536 | + if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2537 | + if (!defined('_OS_SERVEUR')) { |
|
| 2538 | + define('_OS_SERVEUR', 'windows'); |
|
| 2539 | + } |
|
| 2540 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2541 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2542 | + } // utiliser le flock php |
|
| 2543 | + } else { |
|
| 2544 | + if (!defined('_OS_SERVEUR')) { |
|
| 2545 | + define('_OS_SERVEUR', ''); |
|
| 2546 | + } |
|
| 2547 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2548 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2549 | + } // utiliser le flock php |
|
| 2550 | + #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2551 | + } |
|
| 2552 | + |
|
| 2553 | + // Langue par defaut |
|
| 2554 | + if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2555 | + define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2556 | + } |
|
| 2557 | + |
|
| 2558 | + // |
|
| 2559 | + // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2560 | + // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2561 | + // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2562 | + // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2563 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2564 | + |
|
| 2565 | + // charger tout de suite le path et son cache |
|
| 2566 | + load_path_cache(); |
|
| 2567 | + |
|
| 2568 | + // *********** traiter les variables ************ |
|
| 2569 | + |
|
| 2570 | + // |
|
| 2571 | + // Securite |
|
| 2572 | + // |
|
| 2573 | + |
|
| 2574 | + // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2575 | + if (isset($_REQUEST['GLOBALS'])) { |
|
| 2576 | + die(); |
|
| 2577 | + } |
|
| 2578 | + // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2579 | + spip_desinfecte($_GET); |
|
| 2580 | + spip_desinfecte($_POST); |
|
| 2581 | + spip_desinfecte($_COOKIE); |
|
| 2582 | + spip_desinfecte($_REQUEST); |
|
| 2583 | + |
|
| 2584 | + // appliquer le cookie_prefix |
|
| 2585 | + if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2586 | + include_spip('inc/cookie'); |
|
| 2587 | + recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2588 | + } |
|
| 2589 | + |
|
| 2590 | + // |
|
| 2591 | + // Capacites php (en fonction de la version) |
|
| 2592 | + // |
|
| 2593 | + $GLOBALS['flag_ob'] = (function_exists('ob_start') |
|
| 2594 | + && function_exists('ini_get') |
|
| 2595 | + && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2596 | + $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name'); |
|
| 2597 | + $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ''); |
|
| 2598 | + $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2599 | + (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2600 | + |
|
| 2601 | + |
|
| 2602 | + // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2603 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2604 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2605 | + } else { |
|
| 2606 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2607 | + if ( |
|
| 2608 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2609 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2610 | + ) { |
|
| 2611 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2612 | + } |
|
| 2613 | + } |
|
| 2614 | + |
|
| 2615 | + // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2616 | + if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2617 | + define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2618 | + } |
|
| 2619 | + if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2620 | + define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2621 | + } |
|
| 2622 | + |
|
| 2623 | + // charger les meta si possible et renouveller l'alea au besoin |
|
| 2624 | + // charge aussi effacer_meta et ecrire_meta |
|
| 2625 | + $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2626 | + $inc_meta(); |
|
| 2627 | + |
|
| 2628 | + // nombre de repertoires depuis la racine |
|
| 2629 | + // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2630 | + // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2631 | + // le calcul est faux) |
|
| 2632 | + if (!_DIR_RESTREINT) { |
|
| 2633 | + $GLOBALS['profondeur_url'] = 1; |
|
| 2634 | + } else { |
|
| 2635 | + $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2636 | + $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2637 | + if ( |
|
| 2638 | + !$uri_ref |
|
| 2639 | + // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2640 | + // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2641 | + // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2642 | + // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2643 | + or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2644 | + ) { |
|
| 2645 | + if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2646 | + $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2647 | + $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/'; |
|
| 2648 | + } else { |
|
| 2649 | + $uri_ref = ''; |
|
| 2650 | + } |
|
| 2651 | + } |
|
| 2652 | + if (!$uri or !$uri_ref) { |
|
| 2653 | + $GLOBALS['profondeur_url'] = 0; |
|
| 2654 | + } else { |
|
| 2655 | + $GLOBALS['profondeur_url'] = max( |
|
| 2656 | + 0, |
|
| 2657 | + substr_count($uri[0], '/') |
|
| 2658 | + - substr_count($uri_ref, '/') |
|
| 2659 | + ); |
|
| 2660 | + } |
|
| 2661 | + } |
|
| 2662 | + // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2663 | + if (_FILE_CONNECT) { |
|
| 2664 | + if ( |
|
| 2665 | + verifier_visiteur() == '0minirezo' |
|
| 2666 | + // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2667 | + and !isset($_COOKIE['spip_admin']) |
|
| 2668 | + ) { |
|
| 2669 | + clear_path_cache(); |
|
| 2670 | + } |
|
| 2671 | + } |
|
| 2673 | 2672 | } |
| 2674 | 2673 | |
| 2675 | 2674 | /** |
@@ -2678,190 +2677,190 @@ discard block |
||
| 2678 | 2677 | * |
| 2679 | 2678 | */ |
| 2680 | 2679 | function spip_initialisation_suite() { |
| 2681 | - static $too_late = 0; |
|
| 2682 | - if ($too_late++) { |
|
| 2683 | - return; |
|
| 2684 | - } |
|
| 2685 | - |
|
| 2686 | - // taille mini des login |
|
| 2687 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2688 | - define('_LOGIN_TROP_COURT', 4); |
|
| 2689 | - } |
|
| 2690 | - |
|
| 2691 | - // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2692 | - #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2693 | - #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2694 | - #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2695 | - |
|
| 2696 | - // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2697 | - #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2698 | - #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2699 | - #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2700 | - #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2701 | - |
|
| 2702 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2703 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 2704 | - } |
|
| 2705 | - |
|
| 2706 | - // largeur maximale des images dans l'administration |
|
| 2707 | - if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2708 | - define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2709 | - } |
|
| 2710 | - |
|
| 2711 | - // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2712 | - if (!defined('_IMG_QUALITE')) { |
|
| 2713 | - define('_IMG_QUALITE', 85); |
|
| 2714 | - } # valeur par defaut |
|
| 2715 | - if (!defined('_IMG_GD_QUALITE')) { |
|
| 2716 | - define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2717 | - } # surcharge pour la lib GD |
|
| 2718 | - if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2719 | - define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2720 | - } # surcharge pour imagick en ligne de commande |
|
| 2721 | - // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2722 | - if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2723 | - define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2724 | - } # surcharge pour imagick en PHP |
|
| 2725 | - |
|
| 2726 | - if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2727 | - define('_COPIE_LOCALE_MAX_SIZE', 33554432); |
|
| 2728 | - } // poids en octet |
|
| 2729 | - |
|
| 2730 | - // qq chaines standard |
|
| 2731 | - if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2732 | - define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2733 | - } |
|
| 2734 | - if (!defined('_AUTH_USER_FILE')) { |
|
| 2735 | - define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2736 | - } |
|
| 2737 | - if (!defined('_SPIP_DUMP')) { |
|
| 2738 | - define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2739 | - } |
|
| 2740 | - if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2741 | - /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2742 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2743 | - } |
|
| 2744 | - if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2745 | - /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2746 | - define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2747 | - } |
|
| 2748 | - |
|
| 2749 | - if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2750 | - /** |
|
| 2751 | - * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2752 | - * @var int Nombre de caractères */ |
|
| 2753 | - define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2754 | - } |
|
| 2755 | - |
|
| 2756 | - if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2757 | - define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2758 | - } |
|
| 2759 | - |
|
| 2760 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2761 | - /** Définit le doctype de l’espace privé */ |
|
| 2762 | - define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2763 | - } |
|
| 2764 | - if (!defined('_DOCTYPE_AIDE')) { |
|
| 2765 | - /** Définit le doctype de l’aide en ligne */ |
|
| 2766 | - define( |
|
| 2767 | - '_DOCTYPE_AIDE', |
|
| 2768 | - "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2769 | - ); |
|
| 2770 | - } |
|
| 2771 | - |
|
| 2772 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2773 | - /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2774 | - * le script de l'espace public, alias index.php */ |
|
| 2775 | - define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2776 | - } |
|
| 2777 | - if (!defined('_SPIP_PAGE')) { |
|
| 2778 | - /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2779 | - define('_SPIP_PAGE', 'page'); |
|
| 2780 | - } |
|
| 2781 | - |
|
| 2782 | - // le script de l'espace prive |
|
| 2783 | - // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2784 | - // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2785 | - // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2786 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2787 | - if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2788 | - define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2789 | - } else { |
|
| 2790 | - define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2791 | - } |
|
| 2792 | - } |
|
| 2793 | - |
|
| 2794 | - |
|
| 2795 | - if (!defined('_SPIP_AJAX')) { |
|
| 2796 | - define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2797 | - ? 1 |
|
| 2798 | - : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2799 | - } |
|
| 2800 | - |
|
| 2801 | - // La requete est-elle en ajax ? |
|
| 2802 | - if (!defined('_AJAX')) { |
|
| 2803 | - define( |
|
| 2804 | - '_AJAX', |
|
| 2805 | - (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2806 | - or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2807 | - or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2808 | - or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2809 | - ) |
|
| 2810 | - 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 |
|
| 2811 | - ); |
|
| 2812 | - } |
|
| 2813 | - |
|
| 2814 | - # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2815 | - # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2816 | - # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2817 | - if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2818 | - define( |
|
| 2819 | - '_IMG_GD_MAX_PIXELS', |
|
| 2820 | - (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2821 | - ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2822 | - : 0 |
|
| 2823 | - ); |
|
| 2824 | - } |
|
| 2825 | - |
|
| 2826 | - if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2827 | - define('_MEMORY_LIMIT_MIN', 16); |
|
| 2828 | - } // en Mo |
|
| 2829 | - // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2830 | - // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2831 | - // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2832 | - if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2833 | - if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2834 | - $unit = strtolower(substr($memory, -1)); |
|
| 2835 | - $memory = substr($memory, 0, -1); |
|
| 2836 | - switch ($unit) { |
|
| 2837 | - // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2838 | - case 'g': |
|
| 2839 | - $memory *= 1024; |
|
| 2840 | - case 'm': |
|
| 2841 | - $memory *= 1024; |
|
| 2842 | - case 'k': |
|
| 2843 | - $memory *= 1024; |
|
| 2844 | - } |
|
| 2845 | - if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2846 | - @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2847 | - if (trim(ini_get('memory_limit')) != $m) { |
|
| 2848 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2849 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2850 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2851 | - } |
|
| 2852 | - } |
|
| 2853 | - } else { |
|
| 2854 | - if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2855 | - define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2856 | - } |
|
| 2857 | - } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2858 | - } |
|
| 2859 | - // Protocoles a normaliser dans les chaines de langues |
|
| 2860 | - if (!defined('_PROTOCOLES_STD')) { |
|
| 2861 | - define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2862 | - } |
|
| 2863 | - |
|
| 2864 | - init_var_mode(); |
|
| 2680 | + static $too_late = 0; |
|
| 2681 | + if ($too_late++) { |
|
| 2682 | + return; |
|
| 2683 | + } |
|
| 2684 | + |
|
| 2685 | + // taille mini des login |
|
| 2686 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2687 | + define('_LOGIN_TROP_COURT', 4); |
|
| 2688 | + } |
|
| 2689 | + |
|
| 2690 | + // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2691 | + #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2692 | + #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2693 | + #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2694 | + |
|
| 2695 | + // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2696 | + #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2697 | + #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2698 | + #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2699 | + #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2700 | + |
|
| 2701 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2702 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 2703 | + } |
|
| 2704 | + |
|
| 2705 | + // largeur maximale des images dans l'administration |
|
| 2706 | + if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2707 | + define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2708 | + } |
|
| 2709 | + |
|
| 2710 | + // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2711 | + if (!defined('_IMG_QUALITE')) { |
|
| 2712 | + define('_IMG_QUALITE', 85); |
|
| 2713 | + } # valeur par defaut |
|
| 2714 | + if (!defined('_IMG_GD_QUALITE')) { |
|
| 2715 | + define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2716 | + } # surcharge pour la lib GD |
|
| 2717 | + if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2718 | + define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2719 | + } # surcharge pour imagick en ligne de commande |
|
| 2720 | + // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2721 | + if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2722 | + define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2723 | + } # surcharge pour imagick en PHP |
|
| 2724 | + |
|
| 2725 | + if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2726 | + define('_COPIE_LOCALE_MAX_SIZE', 33554432); |
|
| 2727 | + } // poids en octet |
|
| 2728 | + |
|
| 2729 | + // qq chaines standard |
|
| 2730 | + if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2731 | + define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2732 | + } |
|
| 2733 | + if (!defined('_AUTH_USER_FILE')) { |
|
| 2734 | + define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2735 | + } |
|
| 2736 | + if (!defined('_SPIP_DUMP')) { |
|
| 2737 | + define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2738 | + } |
|
| 2739 | + if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2740 | + /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2741 | + define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2742 | + } |
|
| 2743 | + if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2744 | + /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2745 | + define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2746 | + } |
|
| 2747 | + |
|
| 2748 | + if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2749 | + /** |
|
| 2750 | + * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2751 | + * @var int Nombre de caractères */ |
|
| 2752 | + define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2753 | + } |
|
| 2754 | + |
|
| 2755 | + if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2756 | + define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2757 | + } |
|
| 2758 | + |
|
| 2759 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2760 | + /** Définit le doctype de l’espace privé */ |
|
| 2761 | + define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2762 | + } |
|
| 2763 | + if (!defined('_DOCTYPE_AIDE')) { |
|
| 2764 | + /** Définit le doctype de l’aide en ligne */ |
|
| 2765 | + define( |
|
| 2766 | + '_DOCTYPE_AIDE', |
|
| 2767 | + "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2768 | + ); |
|
| 2769 | + } |
|
| 2770 | + |
|
| 2771 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2772 | + /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2773 | + * le script de l'espace public, alias index.php */ |
|
| 2774 | + define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2775 | + } |
|
| 2776 | + if (!defined('_SPIP_PAGE')) { |
|
| 2777 | + /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2778 | + define('_SPIP_PAGE', 'page'); |
|
| 2779 | + } |
|
| 2780 | + |
|
| 2781 | + // le script de l'espace prive |
|
| 2782 | + // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2783 | + // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2784 | + // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2785 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2786 | + if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2787 | + define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2788 | + } else { |
|
| 2789 | + define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2790 | + } |
|
| 2791 | + } |
|
| 2792 | + |
|
| 2793 | + |
|
| 2794 | + if (!defined('_SPIP_AJAX')) { |
|
| 2795 | + define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2796 | + ? 1 |
|
| 2797 | + : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2798 | + } |
|
| 2799 | + |
|
| 2800 | + // La requete est-elle en ajax ? |
|
| 2801 | + if (!defined('_AJAX')) { |
|
| 2802 | + define( |
|
| 2803 | + '_AJAX', |
|
| 2804 | + (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2805 | + or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2806 | + or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2807 | + or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2808 | + ) |
|
| 2809 | + 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 |
|
| 2810 | + ); |
|
| 2811 | + } |
|
| 2812 | + |
|
| 2813 | + # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2814 | + # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2815 | + # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2816 | + if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2817 | + define( |
|
| 2818 | + '_IMG_GD_MAX_PIXELS', |
|
| 2819 | + (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2820 | + ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2821 | + : 0 |
|
| 2822 | + ); |
|
| 2823 | + } |
|
| 2824 | + |
|
| 2825 | + if (!defined('_MEMORY_LIMIT_MIN')) { |
|
| 2826 | + define('_MEMORY_LIMIT_MIN', 16); |
|
| 2827 | + } // en Mo |
|
| 2828 | + // si on est dans l'espace prive et si le besoin est superieur a 8Mo (qui est vraiment le standard) |
|
| 2829 | + // on verifie que la memoire est suffisante pour le compactage css+js pour eviter la page blanche |
|
| 2830 | + // il y aura d'autres problemes et l'utilisateur n'ira pas tres loin, mais ce sera plus comprehensible qu'une page blanche |
|
| 2831 | + if (test_espace_prive() and _MEMORY_LIMIT_MIN > 8) { |
|
| 2832 | + if ($memory = trim(ini_get('memory_limit')) and $memory != -1) { |
|
| 2833 | + $unit = strtolower(substr($memory, -1)); |
|
| 2834 | + $memory = substr($memory, 0, -1); |
|
| 2835 | + switch ($unit) { |
|
| 2836 | + // Le modifieur 'G' est disponible depuis PHP 5.1.0 |
|
| 2837 | + case 'g': |
|
| 2838 | + $memory *= 1024; |
|
| 2839 | + case 'm': |
|
| 2840 | + $memory *= 1024; |
|
| 2841 | + case 'k': |
|
| 2842 | + $memory *= 1024; |
|
| 2843 | + } |
|
| 2844 | + if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
|
| 2845 | + @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2846 | + if (trim(ini_get('memory_limit')) != $m) { |
|
| 2847 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2848 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2849 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2850 | + } |
|
| 2851 | + } |
|
| 2852 | + } else { |
|
| 2853 | + if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
|
| 2854 | + define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
|
| 2855 | + } |
|
| 2856 | + } // evite une page blanche car on ne saura pas calculer la css dans ce hit |
|
| 2857 | + } |
|
| 2858 | + // Protocoles a normaliser dans les chaines de langues |
|
| 2859 | + if (!defined('_PROTOCOLES_STD')) { |
|
| 2860 | + define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2861 | + } |
|
| 2862 | + |
|
| 2863 | + init_var_mode(); |
|
| 2865 | 2864 | } |
| 2866 | 2865 | |
| 2867 | 2866 | /** |
@@ -2895,136 +2894,136 @@ discard block |
||
| 2895 | 2894 | * ` var_mode` (calcul ou recalcul). |
| 2896 | 2895 | */ |
| 2897 | 2896 | function init_var_mode() { |
| 2898 | - static $done = false; |
|
| 2899 | - if (!$done) { |
|
| 2900 | - if (isset($_GET['var_mode'])) { |
|
| 2901 | - $var_mode = explode(',', $_GET['var_mode']); |
|
| 2902 | - // tout le monde peut calcul/recalcul |
|
| 2903 | - if (!defined('_VAR_MODE')) { |
|
| 2904 | - if (in_array('recalcul', $var_mode)) { |
|
| 2905 | - define('_VAR_MODE', 'recalcul'); |
|
| 2906 | - } elseif (in_array('calcul', $var_mode)) { |
|
| 2907 | - define('_VAR_MODE', 'calcul'); |
|
| 2908 | - } |
|
| 2909 | - } |
|
| 2910 | - $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 2911 | - if ($var_mode) { |
|
| 2912 | - include_spip('inc/autoriser'); |
|
| 2913 | - // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 2914 | - if ( |
|
| 2915 | - autoriser( |
|
| 2916 | - ($_GET['var_mode'] == 'preview') |
|
| 2917 | - ? 'previsualiser' |
|
| 2918 | - : 'debug' |
|
| 2919 | - ) |
|
| 2920 | - ) { |
|
| 2921 | - if (in_array('traduction', $var_mode)) { |
|
| 2922 | - // forcer le calcul pour passer dans traduire |
|
| 2923 | - if (!defined('_VAR_MODE')) { |
|
| 2924 | - define('_VAR_MODE', 'calcul'); |
|
| 2925 | - } |
|
| 2926 | - // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 2927 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2928 | - define('_VAR_NOCACHE', true); |
|
| 2929 | - } |
|
| 2930 | - $var_mode = array_diff($var_mode, ['traduction']); |
|
| 2931 | - } |
|
| 2932 | - if (in_array('preview', $var_mode)) { |
|
| 2933 | - // basculer sur les criteres de preview dans les boucles |
|
| 2934 | - if (!defined('_VAR_PREVIEW')) { |
|
| 2935 | - define('_VAR_PREVIEW', true); |
|
| 2936 | - } |
|
| 2937 | - // forcer le calcul |
|
| 2938 | - if (!defined('_VAR_MODE')) { |
|
| 2939 | - define('_VAR_MODE', 'calcul'); |
|
| 2940 | - } |
|
| 2941 | - // et ne pas enregistrer de cache |
|
| 2942 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2943 | - define('_VAR_NOCACHE', true); |
|
| 2944 | - } |
|
| 2945 | - $var_mode = array_diff($var_mode, ['preview']); |
|
| 2946 | - } |
|
| 2947 | - if (in_array('inclure', $var_mode)) { |
|
| 2948 | - // forcer le compilo et ignorer les caches existants |
|
| 2949 | - if (!defined('_VAR_MODE')) { |
|
| 2950 | - define('_VAR_MODE', 'calcul'); |
|
| 2951 | - } |
|
| 2952 | - if (!defined('_VAR_INCLURE')) { |
|
| 2953 | - define('_VAR_INCLURE', true); |
|
| 2954 | - } |
|
| 2955 | - // et ne pas enregistrer de cache |
|
| 2956 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2957 | - define('_VAR_NOCACHE', true); |
|
| 2958 | - } |
|
| 2959 | - $var_mode = array_diff($var_mode, ['inclure']); |
|
| 2960 | - } |
|
| 2961 | - if (in_array('urls', $var_mode)) { |
|
| 2962 | - // forcer le compilo et ignorer les caches existants |
|
| 2963 | - if (!defined('_VAR_MODE')) { |
|
| 2964 | - define('_VAR_MODE', 'calcul'); |
|
| 2965 | - } |
|
| 2966 | - if (!defined('_VAR_URLS')) { |
|
| 2967 | - define('_VAR_URLS', true); |
|
| 2968 | - } |
|
| 2969 | - $var_mode = array_diff($var_mode, ['urls']); |
|
| 2970 | - } |
|
| 2971 | - if (in_array('images', $var_mode)) { |
|
| 2972 | - // forcer le compilo et ignorer les caches existants |
|
| 2973 | - if (!defined('_VAR_MODE')) { |
|
| 2974 | - define('_VAR_MODE', 'calcul'); |
|
| 2975 | - } |
|
| 2976 | - // indiquer qu'on doit recalculer les images |
|
| 2977 | - if (!defined('_VAR_IMAGES')) { |
|
| 2978 | - define('_VAR_IMAGES', true); |
|
| 2979 | - } |
|
| 2980 | - $var_mode = array_diff($var_mode, ['images']); |
|
| 2981 | - } |
|
| 2982 | - if (in_array('debug', $var_mode)) { |
|
| 2983 | - if (!defined('_VAR_MODE')) { |
|
| 2984 | - define('_VAR_MODE', 'debug'); |
|
| 2985 | - } |
|
| 2986 | - // et ne pas enregistrer de cache |
|
| 2987 | - if (!defined('_VAR_NOCACHE')) { |
|
| 2988 | - define('_VAR_NOCACHE', true); |
|
| 2989 | - } |
|
| 2990 | - $var_mode = array_diff($var_mode, ['debug']); |
|
| 2991 | - } |
|
| 2992 | - if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 2993 | - define('_VAR_MODE', reset($var_mode)); |
|
| 2994 | - } |
|
| 2995 | - if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 2996 | - spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 2997 | - . ' ' . _VAR_MODE); |
|
| 2998 | - } |
|
| 2999 | - } // pas autorise ? |
|
| 3000 | - else { |
|
| 3001 | - // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3002 | - if ( |
|
| 3003 | - !$GLOBALS['visiteur_session'] |
|
| 3004 | - and !empty($_SERVER['HTTP_HOST']) |
|
| 3005 | - and !empty($_SERVER['REQUEST_METHOD']) |
|
| 3006 | - and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3007 | - ) { |
|
| 3008 | - $self = self('&', true); |
|
| 3009 | - if (strpos($self, 'page=login') === false) { |
|
| 3010 | - include_spip('inc/headers'); |
|
| 3011 | - $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3012 | - redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3013 | - } |
|
| 3014 | - } |
|
| 3015 | - // sinon tant pis |
|
| 3016 | - } |
|
| 3017 | - } |
|
| 3018 | - } |
|
| 3019 | - if (!defined('_VAR_MODE')) { |
|
| 3020 | - /** |
|
| 3021 | - * Indique le mode de calcul ou d'affichage de la page. |
|
| 3022 | - * @see init_var_mode() |
|
| 3023 | - */ |
|
| 3024 | - define('_VAR_MODE', false); |
|
| 3025 | - } |
|
| 3026 | - $done = true; |
|
| 3027 | - } |
|
| 2897 | + static $done = false; |
|
| 2898 | + if (!$done) { |
|
| 2899 | + if (isset($_GET['var_mode'])) { |
|
| 2900 | + $var_mode = explode(',', $_GET['var_mode']); |
|
| 2901 | + // tout le monde peut calcul/recalcul |
|
| 2902 | + if (!defined('_VAR_MODE')) { |
|
| 2903 | + if (in_array('recalcul', $var_mode)) { |
|
| 2904 | + define('_VAR_MODE', 'recalcul'); |
|
| 2905 | + } elseif (in_array('calcul', $var_mode)) { |
|
| 2906 | + define('_VAR_MODE', 'calcul'); |
|
| 2907 | + } |
|
| 2908 | + } |
|
| 2909 | + $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 2910 | + if ($var_mode) { |
|
| 2911 | + include_spip('inc/autoriser'); |
|
| 2912 | + // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 2913 | + if ( |
|
| 2914 | + autoriser( |
|
| 2915 | + ($_GET['var_mode'] == 'preview') |
|
| 2916 | + ? 'previsualiser' |
|
| 2917 | + : 'debug' |
|
| 2918 | + ) |
|
| 2919 | + ) { |
|
| 2920 | + if (in_array('traduction', $var_mode)) { |
|
| 2921 | + // forcer le calcul pour passer dans traduire |
|
| 2922 | + if (!defined('_VAR_MODE')) { |
|
| 2923 | + define('_VAR_MODE', 'calcul'); |
|
| 2924 | + } |
|
| 2925 | + // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 2926 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2927 | + define('_VAR_NOCACHE', true); |
|
| 2928 | + } |
|
| 2929 | + $var_mode = array_diff($var_mode, ['traduction']); |
|
| 2930 | + } |
|
| 2931 | + if (in_array('preview', $var_mode)) { |
|
| 2932 | + // basculer sur les criteres de preview dans les boucles |
|
| 2933 | + if (!defined('_VAR_PREVIEW')) { |
|
| 2934 | + define('_VAR_PREVIEW', true); |
|
| 2935 | + } |
|
| 2936 | + // forcer le calcul |
|
| 2937 | + if (!defined('_VAR_MODE')) { |
|
| 2938 | + define('_VAR_MODE', 'calcul'); |
|
| 2939 | + } |
|
| 2940 | + // et ne pas enregistrer de cache |
|
| 2941 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2942 | + define('_VAR_NOCACHE', true); |
|
| 2943 | + } |
|
| 2944 | + $var_mode = array_diff($var_mode, ['preview']); |
|
| 2945 | + } |
|
| 2946 | + if (in_array('inclure', $var_mode)) { |
|
| 2947 | + // forcer le compilo et ignorer les caches existants |
|
| 2948 | + if (!defined('_VAR_MODE')) { |
|
| 2949 | + define('_VAR_MODE', 'calcul'); |
|
| 2950 | + } |
|
| 2951 | + if (!defined('_VAR_INCLURE')) { |
|
| 2952 | + define('_VAR_INCLURE', true); |
|
| 2953 | + } |
|
| 2954 | + // et ne pas enregistrer de cache |
|
| 2955 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2956 | + define('_VAR_NOCACHE', true); |
|
| 2957 | + } |
|
| 2958 | + $var_mode = array_diff($var_mode, ['inclure']); |
|
| 2959 | + } |
|
| 2960 | + if (in_array('urls', $var_mode)) { |
|
| 2961 | + // forcer le compilo et ignorer les caches existants |
|
| 2962 | + if (!defined('_VAR_MODE')) { |
|
| 2963 | + define('_VAR_MODE', 'calcul'); |
|
| 2964 | + } |
|
| 2965 | + if (!defined('_VAR_URLS')) { |
|
| 2966 | + define('_VAR_URLS', true); |
|
| 2967 | + } |
|
| 2968 | + $var_mode = array_diff($var_mode, ['urls']); |
|
| 2969 | + } |
|
| 2970 | + if (in_array('images', $var_mode)) { |
|
| 2971 | + // forcer le compilo et ignorer les caches existants |
|
| 2972 | + if (!defined('_VAR_MODE')) { |
|
| 2973 | + define('_VAR_MODE', 'calcul'); |
|
| 2974 | + } |
|
| 2975 | + // indiquer qu'on doit recalculer les images |
|
| 2976 | + if (!defined('_VAR_IMAGES')) { |
|
| 2977 | + define('_VAR_IMAGES', true); |
|
| 2978 | + } |
|
| 2979 | + $var_mode = array_diff($var_mode, ['images']); |
|
| 2980 | + } |
|
| 2981 | + if (in_array('debug', $var_mode)) { |
|
| 2982 | + if (!defined('_VAR_MODE')) { |
|
| 2983 | + define('_VAR_MODE', 'debug'); |
|
| 2984 | + } |
|
| 2985 | + // et ne pas enregistrer de cache |
|
| 2986 | + if (!defined('_VAR_NOCACHE')) { |
|
| 2987 | + define('_VAR_NOCACHE', true); |
|
| 2988 | + } |
|
| 2989 | + $var_mode = array_diff($var_mode, ['debug']); |
|
| 2990 | + } |
|
| 2991 | + if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 2992 | + define('_VAR_MODE', reset($var_mode)); |
|
| 2993 | + } |
|
| 2994 | + if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 2995 | + spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 2996 | + . ' ' . _VAR_MODE); |
|
| 2997 | + } |
|
| 2998 | + } // pas autorise ? |
|
| 2999 | + else { |
|
| 3000 | + // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3001 | + if ( |
|
| 3002 | + !$GLOBALS['visiteur_session'] |
|
| 3003 | + and !empty($_SERVER['HTTP_HOST']) |
|
| 3004 | + and !empty($_SERVER['REQUEST_METHOD']) |
|
| 3005 | + and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3006 | + ) { |
|
| 3007 | + $self = self('&', true); |
|
| 3008 | + if (strpos($self, 'page=login') === false) { |
|
| 3009 | + include_spip('inc/headers'); |
|
| 3010 | + $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3011 | + redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3012 | + } |
|
| 3013 | + } |
|
| 3014 | + // sinon tant pis |
|
| 3015 | + } |
|
| 3016 | + } |
|
| 3017 | + } |
|
| 3018 | + if (!defined('_VAR_MODE')) { |
|
| 3019 | + /** |
|
| 3020 | + * Indique le mode de calcul ou d'affichage de la page. |
|
| 3021 | + * @see init_var_mode() |
|
| 3022 | + */ |
|
| 3023 | + define('_VAR_MODE', false); |
|
| 3024 | + } |
|
| 3025 | + $done = true; |
|
| 3026 | + } |
|
| 3028 | 3027 | } |
| 3029 | 3028 | |
| 3030 | 3029 | // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ; |
@@ -3032,84 +3031,84 @@ discard block |
||
| 3032 | 3031 | // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal') |
| 3033 | 3032 | // https://code.spip.net/@spip_desinfecte |
| 3034 | 3033 | function spip_desinfecte(&$t, $deep = true) { |
| 3035 | - foreach ($t as $key => $val) { |
|
| 3036 | - if (is_string($t[$key])) { |
|
| 3037 | - $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3038 | - } // traiter aussi les "texte_plus" de article_edit |
|
| 3039 | - else { |
|
| 3040 | - if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3041 | - spip_desinfecte($t[$key], $deep); |
|
| 3042 | - } |
|
| 3043 | - } |
|
| 3044 | - } |
|
| 3034 | + foreach ($t as $key => $val) { |
|
| 3035 | + if (is_string($t[$key])) { |
|
| 3036 | + $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3037 | + } // traiter aussi les "texte_plus" de article_edit |
|
| 3038 | + else { |
|
| 3039 | + if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3040 | + spip_desinfecte($t[$key], $deep); |
|
| 3041 | + } |
|
| 3042 | + } |
|
| 3043 | + } |
|
| 3045 | 3044 | } |
| 3046 | 3045 | |
| 3047 | 3046 | // retourne le statut du visiteur s'il s'annonce |
| 3048 | 3047 | |
| 3049 | 3048 | // https://code.spip.net/@verifier_visiteur |
| 3050 | 3049 | function verifier_visiteur() { |
| 3051 | - // Rq: pour que cette fonction marche depuis mes_options |
|
| 3052 | - // il faut forcer l'init si ce n'est fait |
|
| 3053 | - // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3054 | - // certaines constantes |
|
| 3055 | - @spip_initialisation_core( |
|
| 3056 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3057 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3058 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3059 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3060 | - ); |
|
| 3061 | - |
|
| 3062 | - // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3063 | - // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3064 | - // Attention on separe bien session_nom et nom, pour eviter |
|
| 3065 | - // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3066 | - $variables_session = ['session_nom', 'session_email']; |
|
| 3067 | - foreach ($variables_session as $var) { |
|
| 3068 | - if (_request($var) !== null) { |
|
| 3069 | - $init = true; |
|
| 3070 | - break; |
|
| 3071 | - } |
|
| 3072 | - } |
|
| 3073 | - if (isset($init)) { |
|
| 3074 | - #@spip_initialisation_suite(); |
|
| 3075 | - $session = charger_fonction('session', 'inc'); |
|
| 3076 | - $session(); |
|
| 3077 | - include_spip('inc/texte'); |
|
| 3078 | - foreach ($variables_session as $var) { |
|
| 3079 | - if (($a = _request($var)) !== null) { |
|
| 3080 | - $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3081 | - } |
|
| 3082 | - } |
|
| 3083 | - if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3084 | - $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3085 | - } |
|
| 3086 | - $session($GLOBALS['visiteur_session']); |
|
| 3087 | - |
|
| 3088 | - return 0; |
|
| 3089 | - } |
|
| 3090 | - |
|
| 3091 | - $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3092 | - if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3093 | - $session = charger_fonction('session', 'inc'); |
|
| 3094 | - if ($session()) { |
|
| 3095 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3096 | - } |
|
| 3097 | - if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3098 | - include_spip('inc/auth'); |
|
| 3099 | - $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3100 | - } |
|
| 3101 | - if ($h) { |
|
| 3102 | - $GLOBALS['visiteur_session'] = $h; |
|
| 3103 | - |
|
| 3104 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3105 | - } |
|
| 3106 | - } |
|
| 3107 | - |
|
| 3108 | - // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3109 | - include_spip('inc/lang'); |
|
| 3110 | - utiliser_langue_visiteur(); |
|
| 3111 | - |
|
| 3112 | - return false; |
|
| 3050 | + // Rq: pour que cette fonction marche depuis mes_options |
|
| 3051 | + // il faut forcer l'init si ce n'est fait |
|
| 3052 | + // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3053 | + // certaines constantes |
|
| 3054 | + @spip_initialisation_core( |
|
| 3055 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3056 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3057 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3058 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3059 | + ); |
|
| 3060 | + |
|
| 3061 | + // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3062 | + // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3063 | + // Attention on separe bien session_nom et nom, pour eviter |
|
| 3064 | + // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3065 | + $variables_session = ['session_nom', 'session_email']; |
|
| 3066 | + foreach ($variables_session as $var) { |
|
| 3067 | + if (_request($var) !== null) { |
|
| 3068 | + $init = true; |
|
| 3069 | + break; |
|
| 3070 | + } |
|
| 3071 | + } |
|
| 3072 | + if (isset($init)) { |
|
| 3073 | + #@spip_initialisation_suite(); |
|
| 3074 | + $session = charger_fonction('session', 'inc'); |
|
| 3075 | + $session(); |
|
| 3076 | + include_spip('inc/texte'); |
|
| 3077 | + foreach ($variables_session as $var) { |
|
| 3078 | + if (($a = _request($var)) !== null) { |
|
| 3079 | + $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3080 | + } |
|
| 3081 | + } |
|
| 3082 | + if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3083 | + $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3084 | + } |
|
| 3085 | + $session($GLOBALS['visiteur_session']); |
|
| 3086 | + |
|
| 3087 | + return 0; |
|
| 3088 | + } |
|
| 3089 | + |
|
| 3090 | + $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3091 | + if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3092 | + $session = charger_fonction('session', 'inc'); |
|
| 3093 | + if ($session()) { |
|
| 3094 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3095 | + } |
|
| 3096 | + if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3097 | + include_spip('inc/auth'); |
|
| 3098 | + $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3099 | + } |
|
| 3100 | + if ($h) { |
|
| 3101 | + $GLOBALS['visiteur_session'] = $h; |
|
| 3102 | + |
|
| 3103 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3104 | + } |
|
| 3105 | + } |
|
| 3106 | + |
|
| 3107 | + // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3108 | + include_spip('inc/lang'); |
|
| 3109 | + utiliser_langue_visiteur(); |
|
| 3110 | + |
|
| 3111 | + return false; |
|
| 3113 | 3112 | } |
| 3114 | 3113 | |
| 3115 | 3114 | |
@@ -3132,21 +3131,21 @@ discard block |
||
| 3132 | 3131 | * - string Langue utilisée. |
| 3133 | 3132 | **/ |
| 3134 | 3133 | function lang_select($lang = null) { |
| 3135 | - static $pile_langues = []; |
|
| 3136 | - if (!function_exists('changer_langue')) { |
|
| 3137 | - include_spip('inc/lang'); |
|
| 3138 | - } |
|
| 3139 | - if ($lang === null) { |
|
| 3140 | - $lang = array_pop($pile_langues); |
|
| 3141 | - } else { |
|
| 3142 | - array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3143 | - } |
|
| 3144 | - if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3145 | - return $lang; |
|
| 3146 | - } |
|
| 3147 | - changer_langue($lang); |
|
| 3134 | + static $pile_langues = []; |
|
| 3135 | + if (!function_exists('changer_langue')) { |
|
| 3136 | + include_spip('inc/lang'); |
|
| 3137 | + } |
|
| 3138 | + if ($lang === null) { |
|
| 3139 | + $lang = array_pop($pile_langues); |
|
| 3140 | + } else { |
|
| 3141 | + array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3142 | + } |
|
| 3143 | + if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3144 | + return $lang; |
|
| 3145 | + } |
|
| 3146 | + changer_langue($lang); |
|
| 3148 | 3147 | |
| 3149 | - return $lang; |
|
| 3148 | + return $lang; |
|
| 3150 | 3149 | } |
| 3151 | 3150 | |
| 3152 | 3151 | /** |
@@ -3163,20 +3162,20 @@ discard block |
||
| 3163 | 3162 | * Identifiant de la session |
| 3164 | 3163 | **/ |
| 3165 | 3164 | function spip_session($force = false) { |
| 3166 | - static $session; |
|
| 3167 | - if ($force or !isset($session)) { |
|
| 3168 | - $s = pipeline( |
|
| 3169 | - 'definir_session', |
|
| 3170 | - $GLOBALS['visiteur_session'] |
|
| 3171 | - ? serialize($GLOBALS['visiteur_session']) |
|
| 3172 | - . '_' . @$_COOKIE['spip_session'] |
|
| 3173 | - : '' |
|
| 3174 | - ); |
|
| 3175 | - $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3176 | - } |
|
| 3165 | + static $session; |
|
| 3166 | + if ($force or !isset($session)) { |
|
| 3167 | + $s = pipeline( |
|
| 3168 | + 'definir_session', |
|
| 3169 | + $GLOBALS['visiteur_session'] |
|
| 3170 | + ? serialize($GLOBALS['visiteur_session']) |
|
| 3171 | + . '_' . @$_COOKIE['spip_session'] |
|
| 3172 | + : '' |
|
| 3173 | + ); |
|
| 3174 | + $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3175 | + } |
|
| 3177 | 3176 | |
| 3178 | - #spip_log('session: '.$session); |
|
| 3179 | - return $session; |
|
| 3177 | + #spip_log('session: '.$session); |
|
| 3178 | + return $session; |
|
| 3180 | 3179 | } |
| 3181 | 3180 | |
| 3182 | 3181 | |
@@ -3195,9 +3194,9 @@ discard block |
||
| 3195 | 3194 | * Lien sur une icone d'aide |
| 3196 | 3195 | **/ |
| 3197 | 3196 | function aider($aide = '', $distante = false) { |
| 3198 | - $aider = charger_fonction('aide', 'inc', true); |
|
| 3197 | + $aider = charger_fonction('aide', 'inc', true); |
|
| 3199 | 3198 | |
| 3200 | - return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3199 | + return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3201 | 3200 | } |
| 3202 | 3201 | |
| 3203 | 3202 | /** |
@@ -3207,24 +3206,24 @@ discard block |
||
| 3207 | 3206 | */ |
| 3208 | 3207 | function exec_info_dist() { |
| 3209 | 3208 | |
| 3210 | - include_spip('inc/autoriser'); |
|
| 3211 | - if (autoriser('phpinfos')) { |
|
| 3212 | - $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3213 | - $cookies_backup = []; |
|
| 3214 | - foreach ($cookies_masques as $k) { |
|
| 3215 | - if (!empty($_COOKIE[$k])) { |
|
| 3216 | - $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3217 | - $_COOKIE[$k] = '******************************'; |
|
| 3218 | - } |
|
| 3219 | - } |
|
| 3220 | - phpinfo(); |
|
| 3221 | - foreach ($cookies_backup as $k => $v) { |
|
| 3222 | - $_COOKIE[$k] = $v; |
|
| 3223 | - } |
|
| 3224 | - } else { |
|
| 3225 | - include_spip('inc/filtres'); |
|
| 3226 | - sinon_interdire_acces(); |
|
| 3227 | - } |
|
| 3209 | + include_spip('inc/autoriser'); |
|
| 3210 | + if (autoriser('phpinfos')) { |
|
| 3211 | + $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3212 | + $cookies_backup = []; |
|
| 3213 | + foreach ($cookies_masques as $k) { |
|
| 3214 | + if (!empty($_COOKIE[$k])) { |
|
| 3215 | + $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3216 | + $_COOKIE[$k] = '******************************'; |
|
| 3217 | + } |
|
| 3218 | + } |
|
| 3219 | + phpinfo(); |
|
| 3220 | + foreach ($cookies_backup as $k => $v) { |
|
| 3221 | + $_COOKIE[$k] = $v; |
|
| 3222 | + } |
|
| 3223 | + } else { |
|
| 3224 | + include_spip('inc/filtres'); |
|
| 3225 | + sinon_interdire_acces(); |
|
| 3226 | + } |
|
| 3228 | 3227 | } |
| 3229 | 3228 | |
| 3230 | 3229 | /** |
@@ -3244,13 +3243,13 @@ discard block |
||
| 3244 | 3243 | * - string si $message à false. |
| 3245 | 3244 | **/ |
| 3246 | 3245 | function erreur_squelette($message = '', $lieu = '') { |
| 3247 | - $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3248 | - if (is_array($lieu)) { |
|
| 3249 | - include_spip('public/compiler'); |
|
| 3250 | - $lieu = reconstruire_contexte_compil($lieu); |
|
| 3251 | - } |
|
| 3246 | + $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3247 | + if (is_array($lieu)) { |
|
| 3248 | + include_spip('public/compiler'); |
|
| 3249 | + $lieu = reconstruire_contexte_compil($lieu); |
|
| 3250 | + } |
|
| 3252 | 3251 | |
| 3253 | - return $debusquer($message, $lieu); |
|
| 3252 | + return $debusquer($message, $lieu); |
|
| 3254 | 3253 | } |
| 3255 | 3254 | |
| 3256 | 3255 | /** |
@@ -3287,108 +3286,108 @@ discard block |
||
| 3287 | 3286 | * - ou tableau d'information sur le squelette. |
| 3288 | 3287 | */ |
| 3289 | 3288 | function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') { |
| 3290 | - if (!function_exists('evaluer_fond')) { |
|
| 3291 | - include_spip('public/assembler'); |
|
| 3292 | - } |
|
| 3293 | - // assurer la compat avec l'ancienne syntaxe |
|
| 3294 | - // (trim etait le 3eme argument, par defaut a true) |
|
| 3295 | - if (!is_array($options)) { |
|
| 3296 | - $options = ['trim' => $options]; |
|
| 3297 | - } |
|
| 3298 | - if (!isset($options['trim'])) { |
|
| 3299 | - $options['trim'] = true; |
|
| 3300 | - } |
|
| 3301 | - |
|
| 3302 | - if (isset($contexte['connect'])) { |
|
| 3303 | - $connect = $contexte['connect']; |
|
| 3304 | - unset($contexte['connect']); |
|
| 3305 | - } |
|
| 3306 | - |
|
| 3307 | - $texte = ''; |
|
| 3308 | - $pages = []; |
|
| 3309 | - $lang_select = ''; |
|
| 3310 | - if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3311 | - // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3312 | - if (!isset($contexte['lang'])) { |
|
| 3313 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3314 | - } |
|
| 3315 | - |
|
| 3316 | - if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3317 | - $lang_select = lang_select($contexte['lang']); |
|
| 3318 | - } |
|
| 3319 | - } |
|
| 3320 | - |
|
| 3321 | - if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3322 | - $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3323 | - } |
|
| 3324 | - |
|
| 3325 | - $GLOBALS['_INC_PUBLIC']++; |
|
| 3326 | - |
|
| 3327 | - // fix #4235 |
|
| 3328 | - $cache_utilise_session_appelant = (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null); |
|
| 3329 | - |
|
| 3330 | - |
|
| 3331 | - foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3332 | - unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3333 | - |
|
| 3334 | - $page = evaluer_fond($f, $contexte, $connect); |
|
| 3335 | - if ($page === '') { |
|
| 3336 | - $c = isset($options['compil']) ? $options['compil'] : ''; |
|
| 3337 | - $a = ['fichier' => $f]; |
|
| 3338 | - $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3339 | - erreur_squelette($erreur, $c); |
|
| 3340 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3341 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3342 | - } |
|
| 3343 | - |
|
| 3344 | - $page = pipeline('recuperer_fond', [ |
|
| 3345 | - 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3346 | - 'data' => $page |
|
| 3347 | - ]); |
|
| 3348 | - if (isset($options['ajax']) and $options['ajax']) { |
|
| 3349 | - if (!function_exists('encoder_contexte_ajax')) { |
|
| 3350 | - include_spip('inc/filtres'); |
|
| 3351 | - } |
|
| 3352 | - $page['texte'] = encoder_contexte_ajax( |
|
| 3353 | - array_merge( |
|
| 3354 | - $contexte, |
|
| 3355 | - ['fond' => $f], |
|
| 3356 | - ($connect ? ['connect' => $connect] : []) |
|
| 3357 | - ), |
|
| 3358 | - '', |
|
| 3359 | - $page['texte'], |
|
| 3360 | - $options['ajax'] |
|
| 3361 | - ); |
|
| 3362 | - } |
|
| 3363 | - |
|
| 3364 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3365 | - $pages[] = $page; |
|
| 3366 | - } else { |
|
| 3367 | - $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3368 | - } |
|
| 3369 | - |
|
| 3370 | - // contamination de la session appelante, pour les inclusions statiques |
|
| 3371 | - if (isset($page['invalideurs']['session'])) { |
|
| 3372 | - $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3373 | - } |
|
| 3374 | - } |
|
| 3375 | - |
|
| 3376 | - // restaurer le sessionnement du contexte appelant, |
|
| 3377 | - // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3378 | - if (isset($cache_utilise_session_appelant)) { |
|
| 3379 | - $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3380 | - } |
|
| 3381 | - |
|
| 3382 | - $GLOBALS['_INC_PUBLIC']--; |
|
| 3383 | - |
|
| 3384 | - if ($lang_select) { |
|
| 3385 | - lang_select(); |
|
| 3386 | - } |
|
| 3387 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3388 | - return is_array($fond) ? $pages : reset($pages); |
|
| 3389 | - } else { |
|
| 3390 | - return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3391 | - } |
|
| 3289 | + if (!function_exists('evaluer_fond')) { |
|
| 3290 | + include_spip('public/assembler'); |
|
| 3291 | + } |
|
| 3292 | + // assurer la compat avec l'ancienne syntaxe |
|
| 3293 | + // (trim etait le 3eme argument, par defaut a true) |
|
| 3294 | + if (!is_array($options)) { |
|
| 3295 | + $options = ['trim' => $options]; |
|
| 3296 | + } |
|
| 3297 | + if (!isset($options['trim'])) { |
|
| 3298 | + $options['trim'] = true; |
|
| 3299 | + } |
|
| 3300 | + |
|
| 3301 | + if (isset($contexte['connect'])) { |
|
| 3302 | + $connect = $contexte['connect']; |
|
| 3303 | + unset($contexte['connect']); |
|
| 3304 | + } |
|
| 3305 | + |
|
| 3306 | + $texte = ''; |
|
| 3307 | + $pages = []; |
|
| 3308 | + $lang_select = ''; |
|
| 3309 | + if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3310 | + // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3311 | + if (!isset($contexte['lang'])) { |
|
| 3312 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3313 | + } |
|
| 3314 | + |
|
| 3315 | + if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3316 | + $lang_select = lang_select($contexte['lang']); |
|
| 3317 | + } |
|
| 3318 | + } |
|
| 3319 | + |
|
| 3320 | + if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3321 | + $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3322 | + } |
|
| 3323 | + |
|
| 3324 | + $GLOBALS['_INC_PUBLIC']++; |
|
| 3325 | + |
|
| 3326 | + // fix #4235 |
|
| 3327 | + $cache_utilise_session_appelant = (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null); |
|
| 3328 | + |
|
| 3329 | + |
|
| 3330 | + foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3331 | + unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3332 | + |
|
| 3333 | + $page = evaluer_fond($f, $contexte, $connect); |
|
| 3334 | + if ($page === '') { |
|
| 3335 | + $c = isset($options['compil']) ? $options['compil'] : ''; |
|
| 3336 | + $a = ['fichier' => $f]; |
|
| 3337 | + $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3338 | + erreur_squelette($erreur, $c); |
|
| 3339 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3340 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3341 | + } |
|
| 3342 | + |
|
| 3343 | + $page = pipeline('recuperer_fond', [ |
|
| 3344 | + 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3345 | + 'data' => $page |
|
| 3346 | + ]); |
|
| 3347 | + if (isset($options['ajax']) and $options['ajax']) { |
|
| 3348 | + if (!function_exists('encoder_contexte_ajax')) { |
|
| 3349 | + include_spip('inc/filtres'); |
|
| 3350 | + } |
|
| 3351 | + $page['texte'] = encoder_contexte_ajax( |
|
| 3352 | + array_merge( |
|
| 3353 | + $contexte, |
|
| 3354 | + ['fond' => $f], |
|
| 3355 | + ($connect ? ['connect' => $connect] : []) |
|
| 3356 | + ), |
|
| 3357 | + '', |
|
| 3358 | + $page['texte'], |
|
| 3359 | + $options['ajax'] |
|
| 3360 | + ); |
|
| 3361 | + } |
|
| 3362 | + |
|
| 3363 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3364 | + $pages[] = $page; |
|
| 3365 | + } else { |
|
| 3366 | + $texte .= $options['trim'] ? rtrim($page['texte']) : $page['texte']; |
|
| 3367 | + } |
|
| 3368 | + |
|
| 3369 | + // contamination de la session appelante, pour les inclusions statiques |
|
| 3370 | + if (isset($page['invalideurs']['session'])) { |
|
| 3371 | + $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3372 | + } |
|
| 3373 | + } |
|
| 3374 | + |
|
| 3375 | + // restaurer le sessionnement du contexte appelant, |
|
| 3376 | + // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3377 | + if (isset($cache_utilise_session_appelant)) { |
|
| 3378 | + $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3379 | + } |
|
| 3380 | + |
|
| 3381 | + $GLOBALS['_INC_PUBLIC']--; |
|
| 3382 | + |
|
| 3383 | + if ($lang_select) { |
|
| 3384 | + lang_select(); |
|
| 3385 | + } |
|
| 3386 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3387 | + return is_array($fond) ? $pages : reset($pages); |
|
| 3388 | + } else { |
|
| 3389 | + return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3390 | + } |
|
| 3392 | 3391 | } |
| 3393 | 3392 | |
| 3394 | 3393 | /** |
@@ -3398,7 +3397,7 @@ discard block |
||
| 3398 | 3397 | * @return string |
| 3399 | 3398 | */ |
| 3400 | 3399 | function trouve_modele($nom) { |
| 3401 | - return trouver_fond($nom, 'modeles/'); |
|
| 3400 | + return trouver_fond($nom, 'modeles/'); |
|
| 3402 | 3401 | } |
| 3403 | 3402 | |
| 3404 | 3403 | /** |
@@ -3414,21 +3413,21 @@ discard block |
||
| 3414 | 3413 | * @return array|string |
| 3415 | 3414 | */ |
| 3416 | 3415 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 3417 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3418 | - if (!$pathinfo) { |
|
| 3419 | - return $f; |
|
| 3420 | - } |
|
| 3421 | - // renvoyer un tableau detaille si $pathinfo==true |
|
| 3422 | - $p = pathinfo($f); |
|
| 3423 | - if (!isset($p['extension']) or !$p['extension']) { |
|
| 3424 | - $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3425 | - } |
|
| 3426 | - if (!isset($p['extension']) or !$p['filename']) { |
|
| 3427 | - $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3428 | - } |
|
| 3429 | - $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3416 | + $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3417 | + if (!$pathinfo) { |
|
| 3418 | + return $f; |
|
| 3419 | + } |
|
| 3420 | + // renvoyer un tableau detaille si $pathinfo==true |
|
| 3421 | + $p = pathinfo($f); |
|
| 3422 | + if (!isset($p['extension']) or !$p['extension']) { |
|
| 3423 | + $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3424 | + } |
|
| 3425 | + if (!isset($p['extension']) or !$p['filename']) { |
|
| 3426 | + $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3427 | + } |
|
| 3428 | + $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3430 | 3429 | |
| 3431 | - return $p; |
|
| 3430 | + return $p; |
|
| 3432 | 3431 | } |
| 3433 | 3432 | |
| 3434 | 3433 | /** |
@@ -3448,21 +3447,21 @@ discard block |
||
| 3448 | 3447 | * Nom de l'exec, sinon chaîne vide. |
| 3449 | 3448 | **/ |
| 3450 | 3449 | function tester_url_ecrire($nom) { |
| 3451 | - static $exec = []; |
|
| 3452 | - if (isset($exec[$nom])) { |
|
| 3453 | - return $exec[$nom]; |
|
| 3454 | - } |
|
| 3455 | - // tester si c'est une page en squelette |
|
| 3456 | - if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3457 | - return $exec[$nom] = 'fond'; |
|
| 3458 | - } // echafaudage d'un fond ! |
|
| 3459 | - elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3460 | - return $exec[$nom] = 'fond'; |
|
| 3461 | - } |
|
| 3462 | - // attention, il ne faut pas inclure l'exec ici |
|
| 3463 | - // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3464 | - // et des define intrusifs potentiels |
|
| 3465 | - return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3450 | + static $exec = []; |
|
| 3451 | + if (isset($exec[$nom])) { |
|
| 3452 | + return $exec[$nom]; |
|
| 3453 | + } |
|
| 3454 | + // tester si c'est une page en squelette |
|
| 3455 | + if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3456 | + return $exec[$nom] = 'fond'; |
|
| 3457 | + } // echafaudage d'un fond ! |
|
| 3458 | + elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3459 | + return $exec[$nom] = 'fond'; |
|
| 3460 | + } |
|
| 3461 | + // attention, il ne faut pas inclure l'exec ici |
|
| 3462 | + // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3463 | + // et des define intrusifs potentiels |
|
| 3464 | + return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3466 | 3465 | } |
| 3467 | 3466 | |
| 3468 | 3467 | /** |
@@ -3472,8 +3471,8 @@ discard block |
||
| 3472 | 3471 | * true si la constante _VERSION_HTML n'est pas définie ou égale à html5 |
| 3473 | 3472 | **/ |
| 3474 | 3473 | function html5_permis() { |
| 3475 | - return (!defined('_VERSION_HTML') |
|
| 3476 | - or _VERSION_HTML !== 'html4'); |
|
| 3474 | + return (!defined('_VERSION_HTML') |
|
| 3475 | + or _VERSION_HTML !== 'html4'); |
|
| 3477 | 3476 | } |
| 3478 | 3477 | |
| 3479 | 3478 | /** |
@@ -3483,30 +3482,30 @@ discard block |
||
| 3483 | 3482 | * @return array |
| 3484 | 3483 | */ |
| 3485 | 3484 | function formats_image_acceptables($gd = null, $svg_allowed = true) { |
| 3486 | - $formats = null; |
|
| 3487 | - if (!is_null($gd)) { |
|
| 3488 | - $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3489 | - if (isset($GLOBALS['meta'][$config])) { |
|
| 3490 | - $formats = $GLOBALS['meta'][$config]; |
|
| 3491 | - $formats = explode(',', $formats); |
|
| 3492 | - $formats = array_filter($formats); |
|
| 3493 | - $formats = array_map('trim', $formats); |
|
| 3494 | - } |
|
| 3495 | - } |
|
| 3496 | - if (is_null($formats)) { |
|
| 3497 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 3498 | - $formats = _image_extensions_acceptees_en_entree(); |
|
| 3499 | - } |
|
| 3500 | - |
|
| 3501 | - if ($svg_allowed) { |
|
| 3502 | - if (!in_array('svg', $formats)) { |
|
| 3503 | - $formats[] = 'svg'; |
|
| 3504 | - } |
|
| 3505 | - } |
|
| 3506 | - else { |
|
| 3507 | - $formats = array_diff($formats, ['svg']); |
|
| 3508 | - } |
|
| 3509 | - return $formats; |
|
| 3485 | + $formats = null; |
|
| 3486 | + if (!is_null($gd)) { |
|
| 3487 | + $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3488 | + if (isset($GLOBALS['meta'][$config])) { |
|
| 3489 | + $formats = $GLOBALS['meta'][$config]; |
|
| 3490 | + $formats = explode(',', $formats); |
|
| 3491 | + $formats = array_filter($formats); |
|
| 3492 | + $formats = array_map('trim', $formats); |
|
| 3493 | + } |
|
| 3494 | + } |
|
| 3495 | + if (is_null($formats)) { |
|
| 3496 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 3497 | + $formats = _image_extensions_acceptees_en_entree(); |
|
| 3498 | + } |
|
| 3499 | + |
|
| 3500 | + if ($svg_allowed) { |
|
| 3501 | + if (!in_array('svg', $formats)) { |
|
| 3502 | + $formats[] = 'svg'; |
|
| 3503 | + } |
|
| 3504 | + } |
|
| 3505 | + else { |
|
| 3506 | + $formats = array_diff($formats, ['svg']); |
|
| 3507 | + } |
|
| 3508 | + return $formats; |
|
| 3510 | 3509 | } |
| 3511 | 3510 | |
| 3512 | 3511 | /** |
@@ -3515,20 +3514,20 @@ discard block |
||
| 3515 | 3514 | * @return array|bool |
| 3516 | 3515 | */ |
| 3517 | 3516 | function spip_getimagesize($fichier) { |
| 3518 | - if (!$imagesize = @getimagesize($fichier)) { |
|
| 3519 | - include_spip('inc/svg'); |
|
| 3520 | - if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3521 | - list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 3522 | - $imagesize = [ |
|
| 3523 | - $width, |
|
| 3524 | - $height, |
|
| 3525 | - IMAGETYPE_SVG, |
|
| 3526 | - "width=\"{$width}\" height=\"{$height}\"", |
|
| 3527 | - 'mime' => 'image/svg+xml' |
|
| 3528 | - ]; |
|
| 3529 | - } |
|
| 3530 | - } |
|
| 3531 | - return $imagesize; |
|
| 3517 | + if (!$imagesize = @getimagesize($fichier)) { |
|
| 3518 | + include_spip('inc/svg'); |
|
| 3519 | + if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3520 | + list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 3521 | + $imagesize = [ |
|
| 3522 | + $width, |
|
| 3523 | + $height, |
|
| 3524 | + IMAGETYPE_SVG, |
|
| 3525 | + "width=\"{$width}\" height=\"{$height}\"", |
|
| 3526 | + 'mime' => 'image/svg+xml' |
|
| 3527 | + ]; |
|
| 3528 | + } |
|
| 3529 | + } |
|
| 3530 | + return $imagesize; |
|
| 3532 | 3531 | } |
| 3533 | 3532 | |
| 3534 | 3533 | /** |
@@ -3542,19 +3541,19 @@ discard block |
||
| 3542 | 3541 | * @param string $statut |
| 3543 | 3542 | */ |
| 3544 | 3543 | function avertir_auteurs($nom, $message, $statut = '') { |
| 3545 | - $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3546 | - if ( |
|
| 3547 | - !$alertes |
|
| 3548 | - or !is_array($alertes = unserialize($alertes)) |
|
| 3549 | - ) { |
|
| 3550 | - $alertes = []; |
|
| 3551 | - } |
|
| 3544 | + $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3545 | + if ( |
|
| 3546 | + !$alertes |
|
| 3547 | + or !is_array($alertes = unserialize($alertes)) |
|
| 3548 | + ) { |
|
| 3549 | + $alertes = []; |
|
| 3550 | + } |
|
| 3552 | 3551 | |
| 3553 | - if (!isset($alertes[$statut])) { |
|
| 3554 | - $alertes[$statut] = []; |
|
| 3555 | - } |
|
| 3556 | - $alertes[$statut][$nom] = $message; |
|
| 3557 | - ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3552 | + if (!isset($alertes[$statut])) { |
|
| 3553 | + $alertes[$statut] = []; |
|
| 3554 | + } |
|
| 3555 | + $alertes[$statut][$nom] = $message; |
|
| 3556 | + ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3558 | 3557 | } |
| 3559 | 3558 | |
| 3560 | 3559 | /** |
@@ -3568,10 +3567,10 @@ discard block |
||
| 3568 | 3567 | * @return string|string[] |
| 3569 | 3568 | */ |
| 3570 | 3569 | function spip_sanitize_classname($classes) { |
| 3571 | - if (is_array($classes)) { |
|
| 3572 | - return array_map('spip_sanitize_classname', $classes); |
|
| 3573 | - } |
|
| 3574 | - return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3570 | + if (is_array($classes)) { |
|
| 3571 | + return array_map('spip_sanitize_classname', $classes); |
|
| 3572 | + } |
|
| 3573 | + return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3575 | 3574 | } |
| 3576 | 3575 | |
| 3577 | 3576 | |
@@ -3596,32 +3595,32 @@ discard block |
||
| 3596 | 3595 | * Avec operateur : bool. |
| 3597 | 3596 | **/ |
| 3598 | 3597 | function spip_version_compare($v1, $v2, $op = null) { |
| 3599 | - $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3600 | - $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3601 | - $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3602 | - $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3603 | - |
|
| 3604 | - $v1 = explode('.', $v1); |
|
| 3605 | - $v2 = explode('.', $v2); |
|
| 3606 | - // $v1 est toujours une version, donc sans etoile |
|
| 3607 | - while (count($v1) < count($v2)) { |
|
| 3608 | - $v1[] = '0'; |
|
| 3609 | - } |
|
| 3610 | - |
|
| 3611 | - // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3612 | - $etoile = false; |
|
| 3613 | - foreach ($v1 as $k => $v) { |
|
| 3614 | - if (!isset($v2[$k])) { |
|
| 3615 | - $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3616 | - } else { |
|
| 3617 | - if ($v2[$k] == '*') { |
|
| 3618 | - $etoile = true; |
|
| 3619 | - $v2[$k] = $v; |
|
| 3620 | - } |
|
| 3621 | - } |
|
| 3622 | - } |
|
| 3623 | - $v1 = implode('.', $v1); |
|
| 3624 | - $v2 = implode('.', $v2); |
|
| 3625 | - |
|
| 3626 | - return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3598 | + $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3599 | + $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3600 | + $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3601 | + $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3602 | + |
|
| 3603 | + $v1 = explode('.', $v1); |
|
| 3604 | + $v2 = explode('.', $v2); |
|
| 3605 | + // $v1 est toujours une version, donc sans etoile |
|
| 3606 | + while (count($v1) < count($v2)) { |
|
| 3607 | + $v1[] = '0'; |
|
| 3608 | + } |
|
| 3609 | + |
|
| 3610 | + // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3611 | + $etoile = false; |
|
| 3612 | + foreach ($v1 as $k => $v) { |
|
| 3613 | + if (!isset($v2[$k])) { |
|
| 3614 | + $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3615 | + } else { |
|
| 3616 | + if ($v2[$k] == '*') { |
|
| 3617 | + $etoile = true; |
|
| 3618 | + $v2[$k] = $v; |
|
| 3619 | + } |
|
| 3620 | + } |
|
| 3621 | + } |
|
| 3622 | + $v1 = implode('.', $v1); |
|
| 3623 | + $v2 = implode('.', $v2); |
|
| 3624 | + |
|
| 3625 | + return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3627 | 3626 | } |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | if (strlen($dossier) and substr($dossier, -1) != '/') { |
| 54 | 54 | $dossier .= '/'; |
| 55 | 55 | } |
| 56 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 56 | + $f = str_replace('/', '_', $dossier).$nom; |
|
| 57 | 57 | |
| 58 | 58 | if (function_exists($f)) { |
| 59 | 59 | return $f; |
| 60 | 60 | } |
| 61 | - if (function_exists($g = $f . '_dist')) { |
|
| 61 | + if (function_exists($g = $f.'_dist')) { |
|
| 62 | 62 | return $g; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | // passer en minuscules (cf les balises de formulaires) |
| 80 | 80 | // et inclure le fichier |
| 81 | 81 | if ( |
| 82 | - !$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 82 | + !$inc = include_spip($dossier.($d = strtolower($nom))) |
|
| 83 | 83 | // si le fichier truc/machin/nom.php n'existe pas, |
| 84 | 84 | // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
| 85 | 85 | and strlen(dirname($dossier)) and dirname($dossier) != '.' |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Echec : message d'erreur |
| 101 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 101 | + spip_log("fonction $nom ($f ou $g) indisponible". |
|
| 102 | 102 | ($inc ? '' : " (fichier $d absent de $dossier)")); |
| 103 | 103 | |
| 104 | 104 | include_spip('inc/minipres'); |
| 105 | 105 | echo minipres( |
| 106 | 106 | _T('forum_titre_erreur'), |
| 107 | - _T('fichier_introuvable', ['fichier' => '<b>' . spip_htmlentities($d) . '</b>']), |
|
| 108 | - ['all_inline' => true,'status' => 404] |
|
| 107 | + _T('fichier_introuvable', ['fichier' => '<b>'.spip_htmlentities($d).'</b>']), |
|
| 108 | + ['all_inline' => true, 'status' => 404] |
|
| 109 | 109 | ); |
| 110 | 110 | exit; |
| 111 | 111 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | * - string : chemin du fichier trouvé |
| 152 | 152 | **/ |
| 153 | 153 | function include_spip($f, $include = true) { |
| 154 | - return find_in_path($f . '.php', '', $include); |
|
| 154 | + return find_in_path($f.'.php', '', $include); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | * - string : chemin du fichier trouvé |
| 172 | 172 | **/ |
| 173 | 173 | function require_spip($f) { |
| 174 | - return find_in_path($f . '.php', '', 'required'); |
|
| 174 | + return find_in_path($f.'.php', '', 'required'); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | // donc il faut l'inclure "en globals" |
| 189 | 189 | if ($f = find_in_path('mes_fonctions.php')) { |
| 190 | 190 | global $dossier_squelettes; |
| 191 | - include_once(_ROOT_CWD . $f); |
|
| 191 | + include_once(_ROOT_CWD.$f); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | if (@is_readable(_CACHE_PLUGINS_FCT)) { |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | // appliquer notre fonction si elle existe |
| 296 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 296 | + $fonc = 'execute_pipeline_'.strtolower($action); |
|
| 297 | 297 | if (function_exists($fonc)) { |
| 298 | 298 | $val = $fonc($val); |
| 299 | 299 | } // plantage ? |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | function spip_log($message = null, $name = null) { |
| 359 | 359 | static $pre = []; |
| 360 | 360 | static $log; |
| 361 | - preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 361 | + preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string) $name, $regs); |
|
| 362 | 362 | if (!isset($regs[1]) or !$logname = $regs[1]) { |
| 363 | 363 | $logname = null; |
| 364 | 364 | } |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | if (!is_string($message)) { |
| 387 | 387 | $message = print_r($message, true); |
| 388 | 388 | } |
| 389 | - $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 389 | + $log($pre[$niveau].' '.$message, $logname); |
|
| 390 | 390 | } |
| 391 | 391 | } |
| 392 | 392 | |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | $a = './'; |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | - $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 590 | + $regexp = ',^('.str_replace('[]', '\[\]', $c).'[[]?[]]?)(=.*)?$,'; |
|
| 591 | 591 | $ajouts = array_flip(explode('|', $c)); |
| 592 | 592 | $u = is_array($v) ? $v : rawurlencode((string) $v); |
| 593 | 593 | $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | // Ajout. Pour une variable, remplacer au meme endroit, |
| 615 | 615 | // pour un tableau ce sera fait dans la prochaine boucle |
| 616 | 616 | elseif (substr($r[1], -2) != '[]') { |
| 617 | - $url[$n] = $r[1] . '=' . $u; |
|
| 617 | + $url[$n] = $r[1].'='.$u; |
|
| 618 | 618 | unset($ajouts[$r[1]]); |
| 619 | 619 | } |
| 620 | 620 | // Pour les tableaux on laisse tomber les valeurs de |
@@ -635,11 +635,11 @@ discard block |
||
| 635 | 635 | } elseif ($testv) { |
| 636 | 636 | foreach ($ajouts as $k => $n) { |
| 637 | 637 | if (!is_array($v)) { |
| 638 | - $url[] = $k . '=' . $u; |
|
| 638 | + $url[] = $k.'='.$u; |
|
| 639 | 639 | } else { |
| 640 | - $id = (substr($k, -2) == '[]') ? $k : ($k . '[]'); |
|
| 640 | + $id = (substr($k, -2) == '[]') ? $k : ($k.'[]'); |
|
| 641 | 641 | foreach ($v as $w) { |
| 642 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 642 | + $url[] = $id.'='.(is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | } |
@@ -650,10 +650,10 @@ discard block |
||
| 650 | 650 | |
| 651 | 651 | // recomposer l'adresse |
| 652 | 652 | if ($url) { |
| 653 | - $a .= '?' . join($sep, $url); |
|
| 653 | + $a .= '?'.join($sep, $url); |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - return $a . $ancre; |
|
| 656 | + return $a.$ancre; |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | /** |
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | translitteration($ancre) |
| 686 | 686 | ); |
| 687 | 687 | } |
| 688 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 688 | + return $url.(strlen($ancre) ? '#'.$ancre : ''); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | * @return bool |
| 802 | 802 | */ |
| 803 | 803 | function test_plugin_actif($plugin) { |
| 804 | - return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 804 | + return ($plugin and defined('_DIR_PLUGIN_'.strtoupper($plugin))) ? true : false; |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | /** |
@@ -933,7 +933,7 @@ discard block |
||
| 933 | 933 | $value = interdire_scripts($value, -1); |
| 934 | 934 | } |
| 935 | 935 | if (!empty($options['class'])) { |
| 936 | - $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 936 | + $value = "<span class='".$options['class']."'>$value</span>"; |
|
| 937 | 937 | } |
| 938 | 938 | $text = str_replace("@$name@", $value, $text); |
| 939 | 939 | unset($args[$name]); |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | // Si des variables n'ont pas ete inserees, le signaler |
| 943 | 943 | // (chaines de langues pas a jour) |
| 944 | 944 | if ($args) { |
| 945 | - spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 945 | + spip_log("$f: variables inutilisees ".join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 946 | 946 | } |
| 947 | 947 | } |
| 948 | 948 | |
@@ -966,7 +966,7 @@ discard block |
||
| 966 | 966 | function joli_repertoire($rep) { |
| 967 | 967 | $a = substr($rep, 0, 1); |
| 968 | 968 | if ($a <> '.' and $a <> '/') { |
| 969 | - $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 969 | + $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS).$rep; |
|
| 970 | 970 | } |
| 971 | 971 | $rep = preg_replace(',(^\.\.\/),', '', $rep); |
| 972 | 972 | |
@@ -1020,7 +1020,7 @@ discard block |
||
| 1020 | 1020 | $p -= ($x * 1000); |
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | - return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1023 | + return $s.sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1024 | 1024 | } |
| 1025 | 1025 | } |
| 1026 | 1026 | |
@@ -1088,7 +1088,7 @@ discard block |
||
| 1088 | 1088 | if ($taches and count($taches) and !spip_connect()) { |
| 1089 | 1089 | return false; |
| 1090 | 1090 | } |
| 1091 | - spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1091 | + spip_log('cron !', 'jq'._LOG_DEBUG); |
|
| 1092 | 1092 | if ($genie = charger_fonction('genie', 'inc', true)) { |
| 1093 | 1093 | return $genie($taches); |
| 1094 | 1094 | } |
@@ -1192,7 +1192,7 @@ discard block |
||
| 1192 | 1192 | |
| 1193 | 1193 | if ($queue_next_job_time == -1) { |
| 1194 | 1194 | if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
| 1195 | - define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1195 | + define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP.'job_queue_next.txt'); |
|
| 1196 | 1196 | } |
| 1197 | 1197 | // utiliser un cache memoire si dispo |
| 1198 | 1198 | if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
@@ -1261,8 +1261,8 @@ discard block |
||
| 1261 | 1261 | $src = ''; |
| 1262 | 1262 | } |
| 1263 | 1263 | if ($script) { |
| 1264 | - $script = ("/*<![CDATA[*/\n" . |
|
| 1265 | - preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1264 | + $script = ("/*<![CDATA[*/\n". |
|
| 1265 | + preg_replace(',</([^>]*)>,', '<\/\1>', $script). |
|
| 1266 | 1266 | '/*]]>*/'); |
| 1267 | 1267 | } |
| 1268 | 1268 | if ($noscript) { |
@@ -1348,13 +1348,13 @@ discard block |
||
| 1348 | 1348 | if ($path_base == null) { |
| 1349 | 1349 | // Chemin standard depuis l'espace public |
| 1350 | 1350 | $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
| 1351 | - _DIR_RACINE . ':' . |
|
| 1352 | - _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1353 | - _DIR_RACINE . 'prive/:' . |
|
| 1351 | + _DIR_RACINE.':'. |
|
| 1352 | + _DIR_RACINE.'squelettes-dist/:'. |
|
| 1353 | + _DIR_RACINE.'prive/:'. |
|
| 1354 | 1354 | _DIR_RESTREINT; |
| 1355 | 1355 | // Ajouter squelettes/ |
| 1356 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1357 | - $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1356 | + if (@is_dir(_DIR_RACINE.'squelettes')) { |
|
| 1357 | + $path = _DIR_RACINE.'squelettes/:'.$path; |
|
| 1358 | 1358 | } |
| 1359 | 1359 | foreach (explode(':', $path) as $dir) { |
| 1360 | 1360 | if (strlen($dir) and substr($dir, -1) != '/') { |
@@ -1366,7 +1366,7 @@ discard block |
||
| 1366 | 1366 | // Et le(s) dossier(s) des squelettes nommes |
| 1367 | 1367 | if (strlen($GLOBALS['dossier_squelettes'])) { |
| 1368 | 1368 | foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
| 1369 | - array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1369 | + array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE).$d.'/'); |
|
| 1370 | 1370 | } |
| 1371 | 1371 | } |
| 1372 | 1372 | $GLOBALS['path_sig'] = md5(serialize($path_full)); |
@@ -1377,7 +1377,7 @@ discard block |
||
| 1377 | 1377 | |
| 1378 | 1378 | if (is_array($dir_path) or strlen($dir_path)) { |
| 1379 | 1379 | $tete = ''; |
| 1380 | - if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1380 | + if (reset($path_base) == _DIR_RACINE.'squelettes/') { |
|
| 1381 | 1381 | $tete = array_shift($path_base); |
| 1382 | 1382 | } |
| 1383 | 1383 | $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
@@ -1398,7 +1398,7 @@ discard block |
||
| 1398 | 1398 | // Et le(s) dossier(s) des squelettes nommes |
| 1399 | 1399 | if (strlen($GLOBALS['dossier_squelettes'])) { |
| 1400 | 1400 | foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
| 1401 | - array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1401 | + array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE).$d.'/'); |
|
| 1402 | 1402 | } |
| 1403 | 1403 | } |
| 1404 | 1404 | |
@@ -1469,14 +1469,14 @@ discard block |
||
| 1469 | 1469 | // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
| 1470 | 1470 | if ( |
| 1471 | 1471 | preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
| 1472 | - and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 1472 | + and $file_svg_generique = substr($file, 0, -strlen($m[0])).'-xx.svg' |
|
| 1473 | 1473 | and $f = find_in_theme("$file_svg_generique") |
| 1474 | 1474 | ) { |
| 1475 | - if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) { |
|
| 1475 | + if ($fsize = substr($f, 0, -6).$m[1].'.svg' and file_exists($fsize)) { |
|
| 1476 | 1476 | return $themefiles["$subdir$file"] = $fsize; |
| 1477 | 1477 | } |
| 1478 | 1478 | else { |
| 1479 | - return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1479 | + return $themefiles["$subdir$file"] = "$f?".$m[1].'px'; |
|
| 1480 | 1480 | } |
| 1481 | 1481 | } |
| 1482 | 1482 | |
@@ -1486,7 +1486,7 @@ discard block |
||
| 1486 | 1486 | return $themefiles["$subdir$file"] = $f; |
| 1487 | 1487 | } |
| 1488 | 1488 | } |
| 1489 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1489 | + spip_log("$file introuvable dans le theme prive ".reset($themes), 'theme'); |
|
| 1490 | 1490 | |
| 1491 | 1491 | return $themefiles["$subdir$file"] = ''; |
| 1492 | 1492 | } |
@@ -1594,8 +1594,8 @@ discard block |
||
| 1594 | 1594 | return false; |
| 1595 | 1595 | } |
| 1596 | 1596 | if ($include and !isset($inc[$dirname][$file])) { |
| 1597 | - include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1598 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1597 | + include_once _ROOT_CWD.$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1598 | + $inc[$dirname][$file] = $inc[''][$dirname.$file] = true; |
|
| 1599 | 1599 | } |
| 1600 | 1600 | |
| 1601 | 1601 | return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
@@ -1608,14 +1608,14 @@ discard block |
||
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | foreach (creer_chemin() as $dir) { |
| 1611 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1612 | - $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1611 | + if (!isset($dirs[$a = $dir.$dirname])) { |
|
| 1612 | + $dirs[$a] = (is_dir(_ROOT_CWD.$a) || !$a); |
|
| 1613 | 1613 | } |
| 1614 | 1614 | if ($dirs[$a]) { |
| 1615 | - if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1615 | + if (file_exists(_ROOT_CWD.($a .= $file))) { |
|
| 1616 | 1616 | if ($include and !isset($inc[$dirname][$file])) { |
| 1617 | - include_once _ROOT_CWD . $a; |
|
| 1618 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1617 | + include_once _ROOT_CWD.$a; |
|
| 1618 | + $inc[$dirname][$file] = $inc[''][$dirname.$file] = true; |
|
| 1619 | 1619 | } |
| 1620 | 1620 | if (!defined('_SAUVER_CHEMIN')) { |
| 1621 | 1621 | // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
@@ -1625,7 +1625,7 @@ discard block |
||
| 1625 | 1625 | define('_SAUVER_CHEMIN', true); |
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1628 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = $a; |
|
| 1629 | 1629 | } |
| 1630 | 1630 | } |
| 1631 | 1631 | } |
@@ -1651,7 +1651,7 @@ discard block |
||
| 1651 | 1651 | define('_SAUVER_CHEMIN', true); |
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1654 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname.$file] = false; |
|
| 1655 | 1655 | } |
| 1656 | 1656 | |
| 1657 | 1657 | function clear_path_cache() { |
@@ -1721,12 +1721,12 @@ discard block |
||
| 1721 | 1721 | // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
| 1722 | 1722 | // on a pas encore inclus flock.php |
| 1723 | 1723 | if (!function_exists('preg_files')) { |
| 1724 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1724 | + include_once _ROOT_RESTREINT.'inc/flock.php'; |
|
| 1725 | 1725 | } |
| 1726 | 1726 | |
| 1727 | 1727 | // Parcourir le chemin |
| 1728 | 1728 | foreach (creer_chemin() as $d) { |
| 1729 | - $f = $d . $dir; |
|
| 1729 | + $f = $d.$dir; |
|
| 1730 | 1730 | if (@is_dir($f)) { |
| 1731 | 1731 | $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
| 1732 | 1732 | foreach ($liste as $chemin) { |
@@ -1837,7 +1837,7 @@ discard block |
||
| 1837 | 1837 | return $res; |
| 1838 | 1838 | } |
| 1839 | 1839 | // Sinon c'est un raccourci ou compat SPIP < 2 |
| 1840 | - if (!function_exists($f = 'generer_url_' . $entite)) { |
|
| 1840 | + if (!function_exists($f = 'generer_url_'.$entite)) { |
|
| 1841 | 1841 | if (!function_exists($f .= '_dist')) { |
| 1842 | 1842 | $f = ''; |
| 1843 | 1843 | } |
@@ -1846,8 +1846,8 @@ discard block |
||
| 1846 | 1846 | $url = $f($id, $args, $ancre); |
| 1847 | 1847 | if (strlen($args)) { |
| 1848 | 1848 | $url .= strstr($url, '?') |
| 1849 | - ? '&' . $args |
|
| 1850 | - : '?' . $args; |
|
| 1849 | + ? '&'.$args |
|
| 1850 | + : '?'.$args; |
|
| 1851 | 1851 | } |
| 1852 | 1852 | |
| 1853 | 1853 | return $url; |
@@ -1878,8 +1878,8 @@ discard block |
||
| 1878 | 1878 | include_spip('base/connect_sql'); |
| 1879 | 1879 | $id_type = id_table_objet($entite, $public); |
| 1880 | 1880 | |
| 1881 | - return _DIR_RACINE . get_spip_script('./') |
|
| 1882 | - . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1881 | + return _DIR_RACINE.get_spip_script('./') |
|
| 1882 | + . '?'._SPIP_PAGE."=$entite&$id_type=$i&connect=$public" |
|
| 1883 | 1883 | . (!$args ? '' : "&$args") |
| 1884 | 1884 | . (!$ancre ? '' : "#$ancre"); |
| 1885 | 1885 | } |
@@ -2033,7 +2033,7 @@ discard block |
||
| 2033 | 2033 | !empty($_SERVER['QUERY_STRING']) |
| 2034 | 2034 | and !strpos($_SERVER['REQUEST_URI'], '?') |
| 2035 | 2035 | ) { |
| 2036 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2036 | + $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING']; |
|
| 2037 | 2037 | } |
| 2038 | 2038 | } |
| 2039 | 2039 | } |
@@ -2068,9 +2068,9 @@ discard block |
||
| 2068 | 2068 | array_shift($myself); |
| 2069 | 2069 | $myself = implode('/', $myself); |
| 2070 | 2070 | } |
| 2071 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2071 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)).'/'; |
|
| 2072 | 2072 | |
| 2073 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2073 | + $url = $http.'://'.rtrim($host, '/').'/'.ltrim($url, '/'); |
|
| 2074 | 2074 | |
| 2075 | 2075 | return $url; |
| 2076 | 2076 | } |
@@ -2108,17 +2108,17 @@ discard block |
||
| 2108 | 2108 | **/ |
| 2109 | 2109 | function generer_url_ecrire($script = '', $args = '', $no_entities = false, $rel = false) { |
| 2110 | 2110 | if (!$rel) { |
| 2111 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2111 | + $rel = url_de_base()._DIR_RESTREINT_ABS._SPIP_ECRIRE_SCRIPT; |
|
| 2112 | 2112 | } else { |
| 2113 | 2113 | if (!is_string($rel)) { |
| 2114 | 2114 | $rel = _DIR_RESTREINT ? _DIR_RESTREINT : |
| 2115 | - ('./' . _SPIP_ECRIRE_SCRIPT); |
|
| 2115 | + ('./'._SPIP_ECRIRE_SCRIPT); |
|
| 2116 | 2116 | } |
| 2117 | 2117 | } |
| 2118 | 2118 | |
| 2119 | 2119 | list($script, $ancre) = array_pad(explode('#', $script), 2, null); |
| 2120 | 2120 | if ($script and ($script <> 'accueil' or $rel)) { |
| 2121 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2121 | + $args = "?exec=$script".(!$args ? '' : "&$args"); |
|
| 2122 | 2122 | } elseif ($args) { |
| 2123 | 2123 | $args = "?$args"; |
| 2124 | 2124 | } |
@@ -2126,7 +2126,7 @@ discard block |
||
| 2126 | 2126 | $args .= "#$ancre"; |
| 2127 | 2127 | } |
| 2128 | 2128 | |
| 2129 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2129 | + return $rel.($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | 2132 | // |
@@ -2199,25 +2199,25 @@ discard block |
||
| 2199 | 2199 | if (is_array($args)) { |
| 2200 | 2200 | $r = ''; |
| 2201 | 2201 | foreach ($args as $k => $v) { |
| 2202 | - $r .= '&' . $k . '=' . $v; |
|
| 2202 | + $r .= '&'.$k.'='.$v; |
|
| 2203 | 2203 | } |
| 2204 | 2204 | $args = substr($r, 1); |
| 2205 | 2205 | } |
| 2206 | 2206 | $action .= |
| 2207 | - (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2207 | + (strpos($action, '?') !== false ? '&' : '?').$args; |
|
| 2208 | 2208 | } |
| 2209 | 2209 | if (!$no_entities) { |
| 2210 | 2210 | $action = quote_amp($action); |
| 2211 | 2211 | } |
| 2212 | 2212 | |
| 2213 | 2213 | // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
| 2214 | - return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2214 | + return ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/').preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2215 | 2215 | } |
| 2216 | 2216 | |
| 2217 | 2217 | // https://code.spip.net/@generer_url_prive |
| 2218 | 2218 | function generer_url_prive($script, $args = '', $no_entities = false) { |
| 2219 | 2219 | |
| 2220 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2220 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS.'prive.php'); |
|
| 2221 | 2221 | } |
| 2222 | 2222 | |
| 2223 | 2223 | // Pour les formulaires en methode POST, |
@@ -2252,8 +2252,7 @@ discard block |
||
| 2252 | 2252 | . "><div>\n" |
| 2253 | 2253 | . "<input type='hidden' name='exec' value='$script1' />" |
| 2254 | 2254 | . $corps |
| 2255 | - . (!$submit ? '' : |
|
| 2256 | - ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2255 | + . (!$submit ? '' : ("<div style='text-align: ".$GLOBALS['spip_lang_right']."'><input class='fondo submit btn' type='submit' value=\"".entites_html($submit).'" /></div>')) |
|
| 2257 | 2256 | . "</div></form>\n"; |
| 2258 | 2257 | } |
| 2259 | 2258 | |
@@ -2278,14 +2277,14 @@ discard block |
||
| 2278 | 2277 | ? generer_url_ecrire(_request('exec')) |
| 2279 | 2278 | : generer_url_public(); |
| 2280 | 2279 | |
| 2281 | - return "\n<form action='" . |
|
| 2282 | - $h . |
|
| 2283 | - "'" . |
|
| 2284 | - $atts . |
|
| 2285 | - ">\n" . |
|
| 2286 | - '<div>' . |
|
| 2287 | - "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2288 | - $corps . |
|
| 2280 | + return "\n<form action='". |
|
| 2281 | + $h. |
|
| 2282 | + "'". |
|
| 2283 | + $atts. |
|
| 2284 | + ">\n". |
|
| 2285 | + '<div>'. |
|
| 2286 | + "\n<input type='hidden' name='action' value='$script' />". |
|
| 2287 | + $corps. |
|
| 2289 | 2288 | '</div></form>'; |
| 2290 | 2289 | } |
| 2291 | 2290 | |
@@ -2313,7 +2312,7 @@ discard block |
||
| 2313 | 2312 | : generer_url_public('', '', false, false); |
| 2314 | 2313 | $url = parametre_url($url, 'action', $script); |
| 2315 | 2314 | if ($args) { |
| 2316 | - $url .= quote_amp('&' . $args); |
|
| 2315 | + $url .= quote_amp('&'.$args); |
|
| 2317 | 2316 | } |
| 2318 | 2317 | |
| 2319 | 2318 | if ($no_entities) { |
@@ -2363,17 +2362,17 @@ discard block |
||
| 2363 | 2362 | |
| 2364 | 2363 | // le nom du repertoire plugins/ activables/desactivables |
| 2365 | 2364 | if (!defined('_DIR_PLUGINS')) { |
| 2366 | - define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2365 | + define('_DIR_PLUGINS', _DIR_RACINE.'plugins/'); |
|
| 2367 | 2366 | } |
| 2368 | 2367 | |
| 2369 | 2368 | // le nom du repertoire des extensions/ permanentes du core, toujours actives |
| 2370 | 2369 | if (!defined('_DIR_PLUGINS_DIST')) { |
| 2371 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2370 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE.'plugins-dist/'); |
|
| 2372 | 2371 | } |
| 2373 | 2372 | |
| 2374 | 2373 | // le nom du repertoire des librairies |
| 2375 | 2374 | if (!defined('_DIR_LIB')) { |
| 2376 | - define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2375 | + define('_DIR_LIB', _DIR_RACINE.'lib/'); |
|
| 2377 | 2376 | } |
| 2378 | 2377 | |
| 2379 | 2378 | if (!defined('_DIR_IMG')) { |
@@ -2383,29 +2382,29 @@ discard block |
||
| 2383 | 2382 | define('_DIR_LOGOS', $pa); |
| 2384 | 2383 | } |
| 2385 | 2384 | if (!defined('_DIR_IMG_ICONES')) { |
| 2386 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2385 | + define('_DIR_IMG_ICONES', _DIR_LOGOS.'icones/'); |
|
| 2387 | 2386 | } |
| 2388 | 2387 | |
| 2389 | 2388 | if (!defined('_DIR_DUMP')) { |
| 2390 | - define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2389 | + define('_DIR_DUMP', $ti.'dump/'); |
|
| 2391 | 2390 | } |
| 2392 | 2391 | if (!defined('_DIR_SESSIONS')) { |
| 2393 | - define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2392 | + define('_DIR_SESSIONS', $ti.'sessions/'); |
|
| 2394 | 2393 | } |
| 2395 | 2394 | if (!defined('_DIR_TRANSFERT')) { |
| 2396 | - define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2395 | + define('_DIR_TRANSFERT', $ti.'upload/'); |
|
| 2397 | 2396 | } |
| 2398 | 2397 | if (!defined('_DIR_CACHE')) { |
| 2399 | - define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2398 | + define('_DIR_CACHE', $ti.'cache/'); |
|
| 2400 | 2399 | } |
| 2401 | 2400 | if (!defined('_DIR_CACHE_XML')) { |
| 2402 | - define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2401 | + define('_DIR_CACHE_XML', _DIR_CACHE.'xml/'); |
|
| 2403 | 2402 | } |
| 2404 | 2403 | if (!defined('_DIR_SKELS')) { |
| 2405 | - define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2404 | + define('_DIR_SKELS', _DIR_CACHE.'skel/'); |
|
| 2406 | 2405 | } |
| 2407 | 2406 | if (!defined('_DIR_AIDE')) { |
| 2408 | - define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2407 | + define('_DIR_AIDE', _DIR_CACHE.'aide/'); |
|
| 2409 | 2408 | } |
| 2410 | 2409 | if (!defined('_DIR_TMP')) { |
| 2411 | 2410 | define('_DIR_TMP', $ti); |
@@ -2434,27 +2433,27 @@ discard block |
||
| 2434 | 2433 | // Declaration des fichiers |
| 2435 | 2434 | |
| 2436 | 2435 | if (!defined('_CACHE_PLUGINS_PATH')) { |
| 2437 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2436 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE.'charger_plugins_chemins.php'); |
|
| 2438 | 2437 | } |
| 2439 | 2438 | if (!defined('_CACHE_PLUGINS_OPT')) { |
| 2440 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2439 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE.'charger_plugins_options.php'); |
|
| 2441 | 2440 | } |
| 2442 | 2441 | if (!defined('_CACHE_PLUGINS_FCT')) { |
| 2443 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2442 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE.'charger_plugins_fonctions.php'); |
|
| 2444 | 2443 | } |
| 2445 | 2444 | if (!defined('_CACHE_PIPELINES')) { |
| 2446 | - define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2445 | + define('_CACHE_PIPELINES', _DIR_CACHE.'charger_pipelines.php'); |
|
| 2447 | 2446 | } |
| 2448 | 2447 | if (!defined('_CACHE_CHEMIN')) { |
| 2449 | - define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2448 | + define('_CACHE_CHEMIN', _DIR_CACHE.'chemin.txt'); |
|
| 2450 | 2449 | } |
| 2451 | 2450 | |
| 2452 | 2451 | # attention .php obligatoire pour ecrire_fichier_securise |
| 2453 | 2452 | if (!defined('_FILE_META')) { |
| 2454 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2453 | + define('_FILE_META', $ti.'meta_cache.php'); |
|
| 2455 | 2454 | } |
| 2456 | 2455 | if (!defined('_DIR_LOG')) { |
| 2457 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2456 | + define('_DIR_LOG', _DIR_TMP.'log/'); |
|
| 2458 | 2457 | } |
| 2459 | 2458 | if (!defined('_FILE_LOG')) { |
| 2460 | 2459 | define('_FILE_LOG', 'spip'); |
@@ -2471,8 +2470,8 @@ discard block |
||
| 2471 | 2470 | if (!defined('_FILE_CONNECT')) { |
| 2472 | 2471 | define( |
| 2473 | 2472 | '_FILE_CONNECT', |
| 2474 | - (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2475 | - : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2473 | + (@is_readable($f = _DIR_CONNECT._FILE_CONNECT_INS.'.php') ? $f |
|
| 2474 | + : (@is_readable($f = _DIR_RESTREINT.'inc_connect.php') ? $f |
|
| 2476 | 2475 | : false)) |
| 2477 | 2476 | ); |
| 2478 | 2477 | } |
@@ -2484,7 +2483,7 @@ discard block |
||
| 2484 | 2483 | if (!defined('_FILE_CHMOD')) { |
| 2485 | 2484 | define( |
| 2486 | 2485 | '_FILE_CHMOD', |
| 2487 | - (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2486 | + (@is_readable($f = _DIR_CHMOD._FILE_CHMOD_INS.'.php') ? $f |
|
| 2488 | 2487 | : false) |
| 2489 | 2488 | ); |
| 2490 | 2489 | } |
@@ -2497,10 +2496,10 @@ discard block |
||
| 2497 | 2496 | define('_FILE_TMP_SUFFIX', '.tmp.php'); |
| 2498 | 2497 | } |
| 2499 | 2498 | if (!defined('_FILE_CONNECT_TMP')) { |
| 2500 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2499 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT._FILE_CONNECT_INS._FILE_TMP_SUFFIX); |
|
| 2501 | 2500 | } |
| 2502 | 2501 | if (!defined('_FILE_CHMOD_TMP')) { |
| 2503 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2502 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD._FILE_CHMOD_INS._FILE_TMP_SUFFIX); |
|
| 2504 | 2503 | } |
| 2505 | 2504 | |
| 2506 | 2505 | // Definition des droits d'acces en ecriture |
@@ -2518,13 +2517,13 @@ discard block |
||
| 2518 | 2517 | define('_DEFAULT_CHARSET', 'utf-8'); |
| 2519 | 2518 | } |
| 2520 | 2519 | if (!defined('_ROOT_PLUGINS')) { |
| 2521 | - define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2520 | + define('_ROOT_PLUGINS', _ROOT_RACINE.'plugins/'); |
|
| 2522 | 2521 | } |
| 2523 | 2522 | if (!defined('_ROOT_PLUGINS_DIST')) { |
| 2524 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2523 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE.'plugins-dist/'); |
|
| 2525 | 2524 | } |
| 2526 | 2525 | if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
| 2527 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2526 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE.str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2528 | 2527 | } |
| 2529 | 2528 | |
| 2530 | 2529 | // La taille des Log |
@@ -2561,7 +2560,7 @@ discard block |
||
| 2561 | 2560 | // (non surchargeable en l'etat ; attention si on utilise include_spip() |
| 2562 | 2561 | // pour le rendre surchargeable, on va provoquer un reecriture |
| 2563 | 2562 | // systematique du noyau ou une baisse de perfs => a etudier) |
| 2564 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2563 | + include_once _ROOT_RESTREINT.'inc/flock.php'; |
|
| 2565 | 2564 | |
| 2566 | 2565 | // charger tout de suite le path et son cache |
| 2567 | 2566 | load_path_cache(); |
@@ -2609,7 +2608,7 @@ discard block |
||
| 2609 | 2608 | !empty($_SERVER['QUERY_STRING']) |
| 2610 | 2609 | and !strpos($_SERVER['REQUEST_URI'], '?') |
| 2611 | 2610 | ) { |
| 2612 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2611 | + $GLOBALS['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING']; |
|
| 2613 | 2612 | } |
| 2614 | 2613 | } |
| 2615 | 2614 | |
@@ -2645,7 +2644,7 @@ discard block |
||
| 2645 | 2644 | ) { |
| 2646 | 2645 | if (isset($GLOBALS['meta']['adresse_site'])) { |
| 2647 | 2646 | $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
| 2648 | - $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '') . '/'; |
|
| 2647 | + $uri_ref = (isset($uri_ref['path']) ? $uri_ref['path'] : '').'/'; |
|
| 2649 | 2648 | } else { |
| 2650 | 2649 | $uri_ref = ''; |
| 2651 | 2650 | } |
@@ -2739,7 +2738,7 @@ discard block |
||
| 2739 | 2738 | } |
| 2740 | 2739 | if (!defined('_CACHE_RUBRIQUES')) { |
| 2741 | 2740 | /** Fichier cache pour le navigateur de rubrique du bandeau */ |
| 2742 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2741 | + define('_CACHE_RUBRIQUES', _DIR_TMP.'menu-rubriques-cache.txt'); |
|
| 2743 | 2742 | } |
| 2744 | 2743 | if (!defined('_CACHE_RUBRIQUES_MAX')) { |
| 2745 | 2744 | /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
@@ -2843,7 +2842,7 @@ discard block |
||
| 2843 | 2842 | $memory *= 1024; |
| 2844 | 2843 | } |
| 2845 | 2844 | if ($memory < _MEMORY_LIMIT_MIN * 1024 * 1024) { |
| 2846 | - @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN . 'M'); |
|
| 2845 | + @ini_set('memory_limit', $m = _MEMORY_LIMIT_MIN.'M'); |
|
| 2847 | 2846 | if (trim(ini_get('memory_limit')) != $m) { |
| 2848 | 2847 | if (!defined('_INTERDIRE_COMPACTE_HEAD_ECRIRE')) { |
| 2849 | 2848 | define('_INTERDIRE_COMPACTE_HEAD_ECRIRE', true); |
@@ -2994,7 +2993,7 @@ discard block |
||
| 2994 | 2993 | } |
| 2995 | 2994 | if (isset($GLOBALS['visiteur_session']['nom'])) { |
| 2996 | 2995 | spip_log($GLOBALS['visiteur_session']['nom'] |
| 2997 | - . ' ' . _VAR_MODE); |
|
| 2996 | + . ' '._VAR_MODE); |
|
| 2998 | 2997 | } |
| 2999 | 2998 | } // pas autorise ? |
| 3000 | 2999 | else { |
@@ -3009,7 +3008,7 @@ discard block |
||
| 3009 | 3008 | if (strpos($self, 'page=login') === false) { |
| 3010 | 3009 | include_spip('inc/headers'); |
| 3011 | 3010 | $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
| 3012 | - redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3011 | + redirige_par_entete(generer_url_public('login', 'url='.rawurlencode($redirect), true)); |
|
| 3013 | 3012 | } |
| 3014 | 3013 | } |
| 3015 | 3014 | // sinon tant pis |
@@ -3053,10 +3052,10 @@ discard block |
||
| 3053 | 3052 | // mais on risque de perturber des plugins en initialisant trop tot |
| 3054 | 3053 | // certaines constantes |
| 3055 | 3054 | @spip_initialisation_core( |
| 3056 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3057 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3058 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3059 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3055 | + (_DIR_RACINE._NOM_PERMANENTS_INACCESSIBLES), |
|
| 3056 | + (_DIR_RACINE._NOM_PERMANENTS_ACCESSIBLES), |
|
| 3057 | + (_DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3058 | + (_DIR_RACINE._NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3060 | 3059 | ); |
| 3061 | 3060 | |
| 3062 | 3061 | // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
@@ -3089,7 +3088,7 @@ discard block |
||
| 3089 | 3088 | } |
| 3090 | 3089 | |
| 3091 | 3090 | $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
| 3092 | - if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3091 | + if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'].'_session'])) { |
|
| 3093 | 3092 | $session = charger_fonction('session', 'inc'); |
| 3094 | 3093 | if ($session()) { |
| 3095 | 3094 | return $GLOBALS['visiteur_session']['statut']; |
@@ -3169,7 +3168,7 @@ discard block |
||
| 3169 | 3168 | 'definir_session', |
| 3170 | 3169 | $GLOBALS['visiteur_session'] |
| 3171 | 3170 | ? serialize($GLOBALS['visiteur_session']) |
| 3172 | - . '_' . @$_COOKIE['spip_session'] |
|
| 3171 | + . '_'.@$_COOKIE['spip_session'] |
|
| 3173 | 3172 | : '' |
| 3174 | 3173 | ); |
| 3175 | 3174 | $session = $s ? substr(md5($s), 0, 8) : ''; |
@@ -3325,11 +3324,11 @@ discard block |
||
| 3325 | 3324 | $GLOBALS['_INC_PUBLIC']++; |
| 3326 | 3325 | |
| 3327 | 3326 | // fix #4235 |
| 3328 | - $cache_utilise_session_appelant = (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null); |
|
| 3327 | + $cache_utilise_session_appelant = (isset($GLOBALS['cache_utilise_session']) ? $GLOBALS['cache_utilise_session'] : null); |
|
| 3329 | 3328 | |
| 3330 | 3329 | |
| 3331 | 3330 | foreach (is_array($fond) ? $fond : [$fond] as $f) { |
| 3332 | - unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3331 | + unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3333 | 3332 | |
| 3334 | 3333 | $page = evaluer_fond($f, $contexte, $connect); |
| 3335 | 3334 | if ($page === '') { |
@@ -3414,7 +3413,7 @@ discard block |
||
| 3414 | 3413 | * @return array|string |
| 3415 | 3414 | */ |
| 3416 | 3415 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 3417 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3416 | + $f = find_in_path($nom.'.'._EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/').'/' : ''); |
|
| 3418 | 3417 | if (!$pathinfo) { |
| 3419 | 3418 | return $f; |
| 3420 | 3419 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Autorisations |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('base/abstract_sql'); |
@@ -38,84 +38,84 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | if (!function_exists('autoriser')) { |
| 41 | - /** |
|
| 42 | - * Autoriser une action |
|
| 43 | - * |
|
| 44 | - * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 45 | - * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 46 | - * les autorisations. |
|
| 47 | - * |
|
| 48 | - * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 49 | - * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 50 | - * dans cet ordre : |
|
| 51 | - * |
|
| 52 | - * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 53 | - * - autoriser_{type}, sinon avec _dist |
|
| 54 | - * - autoriser_{faire}, sinon avec _dist |
|
| 55 | - * - autoriser_{defaut}, sinon avec _dist |
|
| 56 | - * |
|
| 57 | - * Seul le premier argument est obligatoire. |
|
| 58 | - * |
|
| 59 | - * @note |
|
| 60 | - * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 61 | - * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 62 | - * cette valeur. |
|
| 63 | - * |
|
| 64 | - * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 65 | - * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 66 | - * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 67 | - * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 68 | - * |
|
| 69 | - * @note |
|
| 70 | - * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 71 | - * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 72 | - * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 73 | - * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 74 | - * quel serait le type, quel serait l'action ? |
|
| 75 | - * |
|
| 76 | - * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 77 | - * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 78 | - * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 79 | - * |
|
| 80 | - * @api |
|
| 81 | - * @see autoriser_dist() |
|
| 82 | - * |
|
| 83 | - * @param string $faire |
|
| 84 | - * une action ('modifier', 'publier'...) |
|
| 85 | - * @param ?string $type |
|
| 86 | - * type d'objet ou nom de table ('article') |
|
| 87 | - * @param int $id |
|
| 88 | - * id de l'objet sur lequel on veut agir |
|
| 89 | - * Casté en int si différent. |
|
| 90 | - * @param null|int|array $qui |
|
| 91 | - * - si null on prend alors visiteur_session |
|
| 92 | - * - un id_auteur (on regarde dans la base) |
|
| 93 | - * - un tableau auteur complet, y compris [restreint] |
|
| 94 | - * @param array $opt |
|
| 95 | - * options sous forme de tableau associatif |
|
| 96 | - * @return bool |
|
| 97 | - * true si la personne peut effectuer l'action |
|
| 98 | - */ |
|
| 99 | - function autoriser(string $faire, ?string $type = '', $id = 0, $qui = null, array $opt = []): bool { |
|
| 100 | - // Charger les fonctions d'autorisation supplementaires |
|
| 101 | - static $pipe; |
|
| 102 | - if (!isset($pipe)) { |
|
| 103 | - $pipe = 1; |
|
| 104 | - pipeline('autoriser'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $args = func_get_args(); |
|
| 108 | - |
|
| 109 | - return call_user_func_array('autoriser_dist', $args); |
|
| 110 | - } |
|
| 41 | + /** |
|
| 42 | + * Autoriser une action |
|
| 43 | + * |
|
| 44 | + * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 45 | + * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 46 | + * les autorisations. |
|
| 47 | + * |
|
| 48 | + * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 49 | + * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 50 | + * dans cet ordre : |
|
| 51 | + * |
|
| 52 | + * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 53 | + * - autoriser_{type}, sinon avec _dist |
|
| 54 | + * - autoriser_{faire}, sinon avec _dist |
|
| 55 | + * - autoriser_{defaut}, sinon avec _dist |
|
| 56 | + * |
|
| 57 | + * Seul le premier argument est obligatoire. |
|
| 58 | + * |
|
| 59 | + * @note |
|
| 60 | + * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 61 | + * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 62 | + * cette valeur. |
|
| 63 | + * |
|
| 64 | + * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 65 | + * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 66 | + * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 67 | + * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 68 | + * |
|
| 69 | + * @note |
|
| 70 | + * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 71 | + * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 72 | + * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 73 | + * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 74 | + * quel serait le type, quel serait l'action ? |
|
| 75 | + * |
|
| 76 | + * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 77 | + * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 78 | + * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 79 | + * |
|
| 80 | + * @api |
|
| 81 | + * @see autoriser_dist() |
|
| 82 | + * |
|
| 83 | + * @param string $faire |
|
| 84 | + * une action ('modifier', 'publier'...) |
|
| 85 | + * @param ?string $type |
|
| 86 | + * type d'objet ou nom de table ('article') |
|
| 87 | + * @param int $id |
|
| 88 | + * id de l'objet sur lequel on veut agir |
|
| 89 | + * Casté en int si différent. |
|
| 90 | + * @param null|int|array $qui |
|
| 91 | + * - si null on prend alors visiteur_session |
|
| 92 | + * - un id_auteur (on regarde dans la base) |
|
| 93 | + * - un tableau auteur complet, y compris [restreint] |
|
| 94 | + * @param array $opt |
|
| 95 | + * options sous forme de tableau associatif |
|
| 96 | + * @return bool |
|
| 97 | + * true si la personne peut effectuer l'action |
|
| 98 | + */ |
|
| 99 | + function autoriser(string $faire, ?string $type = '', $id = 0, $qui = null, array $opt = []): bool { |
|
| 100 | + // Charger les fonctions d'autorisation supplementaires |
|
| 101 | + static $pipe; |
|
| 102 | + if (!isset($pipe)) { |
|
| 103 | + $pipe = 1; |
|
| 104 | + pipeline('autoriser'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $args = func_get_args(); |
|
| 108 | + |
|
| 109 | + return call_user_func_array('autoriser_dist', $args); |
|
| 110 | + } |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger |
| 115 | 115 | // mais apres la fonction autoriser() |
| 116 | 116 | if ($f = find_in_path('mes_fonctions.php')) { |
| 117 | - global $dossier_squelettes; |
|
| 118 | - include_once(_ROOT_CWD . $f); |
|
| 117 | + global $dossier_squelettes; |
|
| 118 | + include_once(_ROOT_CWD . $f); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -144,83 +144,83 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | function autoriser_dist(string $faire, ?string $type = '', $id = 0, $qui = null, array $opt = []): bool { |
| 146 | 146 | |
| 147 | - // Tolérance avec certains appels de $id (null, '', 'new', 'oui'). |
|
| 148 | - $id = (int) $id; |
|
| 149 | - if ($type === null) { |
|
| 150 | - $type = ''; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Qui ? visiteur_session ? |
|
| 154 | - // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 155 | - if ($qui === null or $qui === '') { |
|
| 156 | - $qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : []; |
|
| 157 | - $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 158 | - } elseif (is_numeric($qui)) { |
|
| 159 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // Admins restreints, on construit ici (pas generique mais...) |
|
| 163 | - // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 164 | - if (_ADMINS_RESTREINTS and is_array($qui)) { |
|
| 165 | - $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - spip_log( |
|
| 169 | - "autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?', |
|
| 170 | - 'autoriser' . _LOG_DEBUG |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - // passer par objet_type pour avoir les alias |
|
| 174 | - // sauf si _ est le premier caractère. |
|
| 175 | - if ($type and $type[0] !== '_') { |
|
| 176 | - $type = objet_type($type, false); |
|
| 177 | - } |
|
| 178 | - // et supprimer les _ |
|
| 179 | - $type = str_replace('_', '', (string) $type); |
|
| 180 | - |
|
| 181 | - // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 182 | - if ( |
|
| 183 | - (isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier')) |
|
| 184 | - or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier')) |
|
| 185 | - ) { |
|
| 186 | - spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 187 | - return true; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // Chercher une fonction d'autorisation |
|
| 191 | - // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 192 | - // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 193 | - $fonctions = $type |
|
| 194 | - ? [ |
|
| 195 | - 'autoriser_' . $type . '_' . $faire, |
|
| 196 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 197 | - 'autoriser_' . $type, |
|
| 198 | - 'autoriser_' . $type . '_dist', |
|
| 199 | - 'autoriser_' . $faire, |
|
| 200 | - 'autoriser_' . $faire . '_dist', |
|
| 201 | - 'autoriser_defaut', |
|
| 202 | - 'autoriser_defaut_dist' |
|
| 203 | - ] |
|
| 204 | - : [ |
|
| 205 | - 'autoriser_' . $faire, |
|
| 206 | - 'autoriser_' . $faire . '_dist', |
|
| 207 | - 'autoriser_defaut', |
|
| 208 | - 'autoriser_defaut_dist' |
|
| 209 | - ]; |
|
| 210 | - |
|
| 211 | - foreach ($fonctions as $f) { |
|
| 212 | - if (function_exists($f)) { |
|
| 213 | - $a = $f($faire, $type, $id, $qui, $opt); |
|
| 214 | - break; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - spip_log( |
|
| 219 | - "$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 220 | - 'autoriser' . _LOG_DEBUG |
|
| 221 | - ); |
|
| 222 | - |
|
| 223 | - return $a; |
|
| 147 | + // Tolérance avec certains appels de $id (null, '', 'new', 'oui'). |
|
| 148 | + $id = (int) $id; |
|
| 149 | + if ($type === null) { |
|
| 150 | + $type = ''; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Qui ? visiteur_session ? |
|
| 154 | + // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 155 | + if ($qui === null or $qui === '') { |
|
| 156 | + $qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : []; |
|
| 157 | + $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 158 | + } elseif (is_numeric($qui)) { |
|
| 159 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // Admins restreints, on construit ici (pas generique mais...) |
|
| 163 | + // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 164 | + if (_ADMINS_RESTREINTS and is_array($qui)) { |
|
| 165 | + $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + spip_log( |
|
| 169 | + "autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?', |
|
| 170 | + 'autoriser' . _LOG_DEBUG |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + // passer par objet_type pour avoir les alias |
|
| 174 | + // sauf si _ est le premier caractère. |
|
| 175 | + if ($type and $type[0] !== '_') { |
|
| 176 | + $type = objet_type($type, false); |
|
| 177 | + } |
|
| 178 | + // et supprimer les _ |
|
| 179 | + $type = str_replace('_', '', (string) $type); |
|
| 180 | + |
|
| 181 | + // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 182 | + if ( |
|
| 183 | + (isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier')) |
|
| 184 | + or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier')) |
|
| 185 | + ) { |
|
| 186 | + spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // Chercher une fonction d'autorisation |
|
| 191 | + // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 192 | + // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 193 | + $fonctions = $type |
|
| 194 | + ? [ |
|
| 195 | + 'autoriser_' . $type . '_' . $faire, |
|
| 196 | + 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 197 | + 'autoriser_' . $type, |
|
| 198 | + 'autoriser_' . $type . '_dist', |
|
| 199 | + 'autoriser_' . $faire, |
|
| 200 | + 'autoriser_' . $faire . '_dist', |
|
| 201 | + 'autoriser_defaut', |
|
| 202 | + 'autoriser_defaut_dist' |
|
| 203 | + ] |
|
| 204 | + : [ |
|
| 205 | + 'autoriser_' . $faire, |
|
| 206 | + 'autoriser_' . $faire . '_dist', |
|
| 207 | + 'autoriser_defaut', |
|
| 208 | + 'autoriser_defaut_dist' |
|
| 209 | + ]; |
|
| 210 | + |
|
| 211 | + foreach ($fonctions as $f) { |
|
| 212 | + if (function_exists($f)) { |
|
| 213 | + $a = $f($faire, $type, $id, $qui, $opt); |
|
| 214 | + break; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + spip_log( |
|
| 219 | + "$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 220 | + 'autoriser' . _LOG_DEBUG |
|
| 221 | + ); |
|
| 222 | + |
|
| 223 | + return $a; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // une globale pour aller au plus vite dans la fonction generique ci dessus |
@@ -238,33 +238,33 @@ discard block |
||
| 238 | 238 | * @return bool |
| 239 | 239 | */ |
| 240 | 240 | function autoriser_exception(string $faire, ?string $type = '', $id = 0, bool $autoriser = true): bool { |
| 241 | - // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 242 | - static $autorisation; |
|
| 243 | - // Tolérance avec certains appels |
|
| 244 | - if ($type === null) { |
|
| 245 | - $type = ''; |
|
| 246 | - } |
|
| 247 | - if ($id === null) { |
|
| 248 | - $id = 0; |
|
| 249 | - } |
|
| 250 | - if ($autoriser === 'verifier') { |
|
| 251 | - return isset($autorisation[$faire][$type][$id]); |
|
| 252 | - } |
|
| 253 | - if ($autoriser === true) { |
|
| 254 | - $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 255 | - } |
|
| 256 | - if ($autoriser === false) { |
|
| 257 | - if ($id === '*') { |
|
| 258 | - unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 259 | - unset($autorisation[$faire][$type]); |
|
| 260 | - } |
|
| 261 | - else { |
|
| 262 | - unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 263 | - unset($autorisation[$faire][$type][$id]); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return false; |
|
| 241 | + // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 242 | + static $autorisation; |
|
| 243 | + // Tolérance avec certains appels |
|
| 244 | + if ($type === null) { |
|
| 245 | + $type = ''; |
|
| 246 | + } |
|
| 247 | + if ($id === null) { |
|
| 248 | + $id = 0; |
|
| 249 | + } |
|
| 250 | + if ($autoriser === 'verifier') { |
|
| 251 | + return isset($autorisation[$faire][$type][$id]); |
|
| 252 | + } |
|
| 253 | + if ($autoriser === true) { |
|
| 254 | + $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 255 | + } |
|
| 256 | + if ($autoriser === false) { |
|
| 257 | + if ($id === '*') { |
|
| 258 | + unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 259 | + unset($autorisation[$faire][$type]); |
|
| 260 | + } |
|
| 261 | + else { |
|
| 262 | + unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 263 | + unset($autorisation[$faire][$type][$id]); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return false; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | |
@@ -281,9 +281,9 @@ discard block |
||
| 281 | 281 | * @return bool true s'il a le droit, false sinon |
| 282 | 282 | **/ |
| 283 | 283 | function autoriser_defaut_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 284 | - return |
|
| 285 | - $qui['statut'] == '0minirezo' |
|
| 286 | - and !$qui['restreint']; |
|
| 284 | + return |
|
| 285 | + $qui['statut'] == '0minirezo' |
|
| 286 | + and !$qui['restreint']; |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -299,10 +299,10 @@ discard block |
||
| 299 | 299 | * @return bool |
| 300 | 300 | */ |
| 301 | 301 | function autoriser_loger_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 302 | - if ($qui['statut'] == '5poubelle') { |
|
| 303 | - return false; |
|
| 304 | - } |
|
| 305 | - return true; |
|
| 302 | + if ($qui['statut'] == '5poubelle') { |
|
| 303 | + return false; |
|
| 304 | + } |
|
| 305 | + return true; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | * @return bool true s'il a le droit, false sinon |
| 317 | 317 | **/ |
| 318 | 318 | function autoriser_ecrire_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 319 | - return isset($qui['statut']) and in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 319 | + return isset($qui['statut']) and in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | * @return bool true s'il a le droit, false sinon |
| 334 | 334 | **/ |
| 335 | 335 | function autoriser_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 336 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 336 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -351,18 +351,18 @@ discard block |
||
| 351 | 351 | **/ |
| 352 | 352 | function autoriser_previsualiser_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 353 | 353 | |
| 354 | - // Le visiteur a-t-il un statut prevu par la config ? |
|
| 355 | - if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) { |
|
| 356 | - return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 357 | - } |
|
| 354 | + // Le visiteur a-t-il un statut prevu par la config ? |
|
| 355 | + if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) { |
|
| 356 | + return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - // A-t-on un token de prévisualisation valable ? |
|
| 360 | - include_spip('inc/securiser_action'); |
|
| 361 | - if (decrire_token_previsu()) { |
|
| 362 | - return true; |
|
| 363 | - } |
|
| 359 | + // A-t-on un token de prévisualisation valable ? |
|
| 360 | + include_spip('inc/securiser_action'); |
|
| 361 | + if (decrire_token_previsu()) { |
|
| 362 | + return true; |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | - return false; |
|
| 365 | + return false; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | /** |
@@ -390,58 +390,58 @@ discard block |
||
| 390 | 390 | */ |
| 391 | 391 | function test_previsualiser_objet_champ(string $type = '', int $id = 0, array $qui = [], array $opt = []): bool { |
| 392 | 392 | |
| 393 | - // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 394 | - if (!$type) { |
|
| 395 | - return true; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - include_spip('base/objets'); |
|
| 399 | - $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 400 | - if (isset($infos['statut'])) { |
|
| 401 | - foreach ($infos['statut'] as $c) { |
|
| 402 | - if (isset($c['publie'])) { |
|
| 403 | - if (!isset($c['previsu'])) { |
|
| 404 | - return false; |
|
| 405 | - } // pas de previsu definie => NIET |
|
| 406 | - $champ = $c['champ']; |
|
| 407 | - if (!isset($opt[$champ])) { |
|
| 408 | - return false; |
|
| 409 | - } // pas de champ passe a la demande => NIET |
|
| 410 | - $previsu = explode(',', $c['previsu']); |
|
| 411 | - // regarder si ce statut est autorise pour l'auteur |
|
| 412 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 413 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 414 | - // sinon l’auteur en session |
|
| 415 | - include_spip('inc/securiser_action'); |
|
| 416 | - if ($desc = decrire_token_previsu()) { |
|
| 417 | - $id_auteur = $desc['id_auteur']; |
|
| 418 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 419 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 420 | - } else { |
|
| 421 | - $id_auteur = null; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - if (!$id_auteur) { |
|
| 425 | - return false; |
|
| 426 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 427 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 428 | - } elseif ( |
|
| 429 | - !sql_countsel( |
|
| 430 | - 'spip_auteurs_liens', |
|
| 431 | - 'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id) |
|
| 432 | - ) |
|
| 433 | - ) { |
|
| 434 | - return false; |
|
| 435 | - } // pas auteur de cet objet => NIET |
|
| 436 | - } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 437 | - // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 438 | - return false; |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - return true; |
|
| 393 | + // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 394 | + if (!$type) { |
|
| 395 | + return true; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + include_spip('base/objets'); |
|
| 399 | + $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 400 | + if (isset($infos['statut'])) { |
|
| 401 | + foreach ($infos['statut'] as $c) { |
|
| 402 | + if (isset($c['publie'])) { |
|
| 403 | + if (!isset($c['previsu'])) { |
|
| 404 | + return false; |
|
| 405 | + } // pas de previsu definie => NIET |
|
| 406 | + $champ = $c['champ']; |
|
| 407 | + if (!isset($opt[$champ])) { |
|
| 408 | + return false; |
|
| 409 | + } // pas de champ passe a la demande => NIET |
|
| 410 | + $previsu = explode(',', $c['previsu']); |
|
| 411 | + // regarder si ce statut est autorise pour l'auteur |
|
| 412 | + if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 413 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 414 | + // sinon l’auteur en session |
|
| 415 | + include_spip('inc/securiser_action'); |
|
| 416 | + if ($desc = decrire_token_previsu()) { |
|
| 417 | + $id_auteur = $desc['id_auteur']; |
|
| 418 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 419 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 420 | + } else { |
|
| 421 | + $id_auteur = null; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + if (!$id_auteur) { |
|
| 425 | + return false; |
|
| 426 | + } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 427 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 428 | + } elseif ( |
|
| 429 | + !sql_countsel( |
|
| 430 | + 'spip_auteurs_liens', |
|
| 431 | + 'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id) |
|
| 432 | + ) |
|
| 433 | + ) { |
|
| 434 | + return false; |
|
| 435 | + } // pas auteur de cet objet => NIET |
|
| 436 | + } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 437 | + // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 438 | + return false; |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + return true; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | /** |
@@ -455,51 +455,51 @@ discard block |
||
| 455 | 455 | * @return bool true s'il a le droit, false sinon |
| 456 | 456 | **/ |
| 457 | 457 | function autoriser_changerlangue_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 458 | - $multi_objets = explode(',', lire_config('multi_objets')); |
|
| 459 | - $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets')); |
|
| 460 | - $table = table_objet_sql($type); |
|
| 461 | - if ( |
|
| 462 | - in_array($table, $multi_objets) |
|
| 463 | - or in_array($table, $gerer_trad_objets) |
|
| 464 | - ) { // affichage du formulaire si la configuration l'accepte |
|
| 465 | - $multi_secteurs = lire_config('multi_secteurs'); |
|
| 466 | - $champs = objet_info($type, 'field'); |
|
| 467 | - if ( |
|
| 468 | - $multi_secteurs == 'oui' |
|
| 469 | - and array_key_exists('id_rubrique', $champs) |
|
| 470 | - ) { |
|
| 471 | - // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 472 | - $primary = id_table_objet($type); |
|
| 473 | - if ($table != 'spip_rubriques') { |
|
| 474 | - $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id)); |
|
| 475 | - } else { |
|
| 476 | - $id_rubrique = $id; |
|
| 477 | - } |
|
| 478 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 479 | - if (!$id_secteur > 0) { |
|
| 480 | - $id_secteur = $id_rubrique; |
|
| 481 | - } |
|
| 482 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur)); |
|
| 483 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id)); |
|
| 484 | - if ($langue_secteur != $langue_objet) { |
|
| 485 | - // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 486 | - return true; |
|
| 487 | - } |
|
| 488 | - if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 489 | - return false; |
|
| 490 | - } else { |
|
| 491 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id)); |
|
| 492 | - if ($id_parent != 0) { |
|
| 493 | - // sous-rubriques : pas de choix de langue |
|
| 494 | - return false; |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - } else { |
|
| 499 | - return false; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 458 | + $multi_objets = explode(',', lire_config('multi_objets')); |
|
| 459 | + $gerer_trad_objets = explode(',', lire_config('gerer_trad_objets')); |
|
| 460 | + $table = table_objet_sql($type); |
|
| 461 | + if ( |
|
| 462 | + in_array($table, $multi_objets) |
|
| 463 | + or in_array($table, $gerer_trad_objets) |
|
| 464 | + ) { // affichage du formulaire si la configuration l'accepte |
|
| 465 | + $multi_secteurs = lire_config('multi_secteurs'); |
|
| 466 | + $champs = objet_info($type, 'field'); |
|
| 467 | + if ( |
|
| 468 | + $multi_secteurs == 'oui' |
|
| 469 | + and array_key_exists('id_rubrique', $champs) |
|
| 470 | + ) { |
|
| 471 | + // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 472 | + $primary = id_table_objet($type); |
|
| 473 | + if ($table != 'spip_rubriques') { |
|
| 474 | + $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id)); |
|
| 475 | + } else { |
|
| 476 | + $id_rubrique = $id; |
|
| 477 | + } |
|
| 478 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 479 | + if (!$id_secteur > 0) { |
|
| 480 | + $id_secteur = $id_rubrique; |
|
| 481 | + } |
|
| 482 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur)); |
|
| 483 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id)); |
|
| 484 | + if ($langue_secteur != $langue_objet) { |
|
| 485 | + // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 486 | + return true; |
|
| 487 | + } |
|
| 488 | + if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 489 | + return false; |
|
| 490 | + } else { |
|
| 491 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id)); |
|
| 492 | + if ($id_parent != 0) { |
|
| 493 | + // sous-rubriques : pas de choix de langue |
|
| 494 | + return false; |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + } else { |
|
| 499 | + return false; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | * @return bool true s'il a le droit, false sinon |
| 514 | 514 | **/ |
| 515 | 515 | function autoriser_changertraduction_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 516 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 516 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -527,41 +527,41 @@ discard block |
||
| 527 | 527 | * @return bool true s'il a le droit, false sinon |
| 528 | 528 | **/ |
| 529 | 529 | function autoriser_dater_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 530 | - $table = table_objet($type); |
|
| 531 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 532 | - $desc = $trouver_table($table); |
|
| 533 | - if (!$desc) { |
|
| 534 | - return false; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - if (!isset($opt['statut'])) { |
|
| 538 | - if (isset($desc['field']['statut'])) { |
|
| 539 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id)); |
|
| 540 | - } else { |
|
| 541 | - $statut = 'publie'; |
|
| 542 | - } // pas de statut => publie |
|
| 543 | - } else { |
|
| 544 | - $statut = $opt['statut']; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // Liste des statuts publiés pour cet objet |
|
| 548 | - if (isset($desc['statut'][0]['publie'])) { |
|
| 549 | - $statuts_publies = explode(',', $desc['statut'][0]['publie']); |
|
| 550 | - } |
|
| 551 | - // Sinon en dur le statut "publie" |
|
| 552 | - else { |
|
| 553 | - $statuts_publies = ['publie']; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - if ( |
|
| 557 | - in_array($statut, $statuts_publies) |
|
| 558 | - // Ou cas particulier géré en dur ici pour les articles |
|
| 559 | - or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non') |
|
| 560 | - ) { |
|
| 561 | - return autoriser('modifier', $type, $id); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - return false; |
|
| 530 | + $table = table_objet($type); |
|
| 531 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 532 | + $desc = $trouver_table($table); |
|
| 533 | + if (!$desc) { |
|
| 534 | + return false; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + if (!isset($opt['statut'])) { |
|
| 538 | + if (isset($desc['field']['statut'])) { |
|
| 539 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id)); |
|
| 540 | + } else { |
|
| 541 | + $statut = 'publie'; |
|
| 542 | + } // pas de statut => publie |
|
| 543 | + } else { |
|
| 544 | + $statut = $opt['statut']; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // Liste des statuts publiés pour cet objet |
|
| 548 | + if (isset($desc['statut'][0]['publie'])) { |
|
| 549 | + $statuts_publies = explode(',', $desc['statut'][0]['publie']); |
|
| 550 | + } |
|
| 551 | + // Sinon en dur le statut "publie" |
|
| 552 | + else { |
|
| 553 | + $statuts_publies = ['publie']; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + if ( |
|
| 557 | + in_array($statut, $statuts_publies) |
|
| 558 | + // Ou cas particulier géré en dur ici pour les articles |
|
| 559 | + or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non') |
|
| 560 | + ) { |
|
| 561 | + return autoriser('modifier', $type, $id); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + return false; |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | * @return bool true s'il a le droit, false sinon |
| 579 | 579 | **/ |
| 580 | 580 | function autoriser_instituer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 581 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 581 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -594,12 +594,12 @@ discard block |
||
| 594 | 594 | * @return bool true s'il a le droit, false sinon |
| 595 | 595 | **/ |
| 596 | 596 | function autoriser_rubrique_publierdans_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 597 | - return |
|
| 598 | - ($qui['statut'] == '0minirezo') |
|
| 599 | - and ( |
|
| 600 | - !$qui['restreint'] or !$id |
|
| 601 | - or in_array($id, $qui['restreint']) |
|
| 602 | - ); |
|
| 597 | + return |
|
| 598 | + ($qui['statut'] == '0minirezo') |
|
| 599 | + and ( |
|
| 600 | + !$qui['restreint'] or !$id |
|
| 601 | + or in_array($id, $qui['restreint']) |
|
| 602 | + ); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -615,12 +615,12 @@ discard block |
||
| 615 | 615 | * @return bool true s'il a le droit, false sinon |
| 616 | 616 | **/ |
| 617 | 617 | function autoriser_rubrique_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 618 | - if (!empty($opt['id_parent'])) { |
|
| 619 | - return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 620 | - } |
|
| 621 | - else { |
|
| 622 | - return autoriser('defaut', null, null, $qui, $opt); |
|
| 623 | - } |
|
| 618 | + if (!empty($opt['id_parent'])) { |
|
| 619 | + return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 620 | + } |
|
| 621 | + else { |
|
| 622 | + return autoriser('defaut', null, null, $qui, $opt); |
|
| 623 | + } |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -636,10 +636,10 @@ discard block |
||
| 636 | 636 | * @return bool true s'il a le droit, false sinon |
| 637 | 637 | **/ |
| 638 | 638 | function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 639 | - return |
|
| 640 | - ($id or ($qui['statut'] == '0minirezo' and !$qui['restreint'])) |
|
| 641 | - and autoriser('voir', 'rubrique', $id) |
|
| 642 | - and autoriser('publierdans', 'rubrique', $id); |
|
| 639 | + return |
|
| 640 | + ($id or ($qui['statut'] == '0minirezo' and !$qui['restreint'])) |
|
| 641 | + and autoriser('voir', 'rubrique', $id) |
|
| 642 | + and autoriser('publierdans', 'rubrique', $id); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | /** |
@@ -655,10 +655,10 @@ discard block |
||
| 655 | 655 | * @return bool true s'il a le droit, false sinon |
| 656 | 656 | **/ |
| 657 | 657 | function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 658 | - return |
|
| 659 | - $id |
|
| 660 | - and autoriser('voir', 'rubrique', $id) |
|
| 661 | - and autoriser('creer', 'article'); |
|
| 658 | + return |
|
| 659 | + $id |
|
| 660 | + and autoriser('voir', 'rubrique', $id) |
|
| 661 | + and autoriser('creer', 'article'); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | |
@@ -675,8 +675,8 @@ discard block |
||
| 675 | 675 | * @return bool true s'il a le droit, false sinon |
| 676 | 676 | **/ |
| 677 | 677 | function autoriser_rubrique_modifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 678 | - return |
|
| 679 | - autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 678 | + return |
|
| 679 | + autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | /** |
@@ -692,29 +692,29 @@ discard block |
||
| 692 | 692 | * @return bool true s'il a le droit, false sinon |
| 693 | 693 | **/ |
| 694 | 694 | function autoriser_rubrique_supprimer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 695 | - if (!$id = intval($id)) { |
|
| 696 | - return false; |
|
| 697 | - } |
|
| 695 | + if (!$id = intval($id)) { |
|
| 696 | + return false; |
|
| 697 | + } |
|
| 698 | 698 | |
| 699 | - if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) { |
|
| 700 | - return false; |
|
| 701 | - } |
|
| 699 | + if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) { |
|
| 700 | + return false; |
|
| 701 | + } |
|
| 702 | 702 | |
| 703 | - if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) { |
|
| 704 | - return false; |
|
| 705 | - } |
|
| 703 | + if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) { |
|
| 704 | + return false; |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - $compte = pipeline( |
|
| 708 | - 'objet_compte_enfants', |
|
| 709 | - ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 710 | - ); |
|
| 711 | - foreach ($compte as $objet => $n) { |
|
| 712 | - if ($n) { |
|
| 713 | - return false; |
|
| 714 | - } |
|
| 715 | - } |
|
| 707 | + $compte = pipeline( |
|
| 708 | + 'objet_compte_enfants', |
|
| 709 | + ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 710 | + ); |
|
| 711 | + foreach ($compte as $objet => $n) { |
|
| 712 | + if ($n) { |
|
| 713 | + return false; |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | - return autoriser('modifier', 'rubrique', $id); |
|
| 717 | + return autoriser('modifier', 'rubrique', $id); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | |
@@ -732,23 +732,23 @@ discard block |
||
| 732 | 732 | * @return bool true s'il a le droit, false sinon |
| 733 | 733 | **/ |
| 734 | 734 | function autoriser_article_modifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 735 | - if (!$id) { |
|
| 736 | - return false; |
|
| 737 | - } |
|
| 738 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 739 | - |
|
| 740 | - return |
|
| 741 | - $r |
|
| 742 | - and |
|
| 743 | - ( |
|
| 744 | - autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 745 | - or ( |
|
| 746 | - (!isset($opt['statut']) or $opt['statut'] !== 'publie') |
|
| 747 | - and in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 748 | - and in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 749 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 750 | - ) |
|
| 751 | - ); |
|
| 735 | + if (!$id) { |
|
| 736 | + return false; |
|
| 737 | + } |
|
| 738 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 739 | + |
|
| 740 | + return |
|
| 741 | + $r |
|
| 742 | + and |
|
| 743 | + ( |
|
| 744 | + autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 745 | + or ( |
|
| 746 | + (!isset($opt['statut']) or $opt['statut'] !== 'publie') |
|
| 747 | + and in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 748 | + and in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 749 | + and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 750 | + ) |
|
| 751 | + ); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /** |
@@ -764,13 +764,13 @@ discard block |
||
| 764 | 764 | * @return bool true s'il a le droit, false sinon |
| 765 | 765 | **/ |
| 766 | 766 | function autoriser_article_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 767 | - if (!empty($opt['id_parent'])) { |
|
| 768 | - // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 769 | - return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 770 | - } |
|
| 771 | - else { |
|
| 772 | - return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 773 | - } |
|
| 767 | + if (!empty($opt['id_parent'])) { |
|
| 768 | + // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 769 | + return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 770 | + } |
|
| 771 | + else { |
|
| 772 | + return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 773 | + } |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | /** |
@@ -790,28 +790,28 @@ discard block |
||
| 790 | 790 | * @return bool true s'il a le droit, false sinon |
| 791 | 791 | */ |
| 792 | 792 | function autoriser_article_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 793 | - if ($qui['statut'] == '0minirezo') { |
|
| 794 | - return true; |
|
| 795 | - } |
|
| 796 | - // cas des articles : depend du statut de l'article et de l'auteur |
|
| 797 | - if (isset($opt['statut'])) { |
|
| 798 | - $statut = $opt['statut']; |
|
| 799 | - } else { |
|
| 800 | - if (!$id) { |
|
| 801 | - return false; |
|
| 802 | - } |
|
| 803 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id)); |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - return |
|
| 807 | - // si on est pas auteur de l'article, |
|
| 808 | - // seuls les propose et publies sont visibles |
|
| 809 | - in_array($statut, ['prop', 'publie']) |
|
| 810 | - // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 811 | - or |
|
| 812 | - ($id |
|
| 813 | - and $qui['id_auteur'] |
|
| 814 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])); |
|
| 793 | + if ($qui['statut'] == '0minirezo') { |
|
| 794 | + return true; |
|
| 795 | + } |
|
| 796 | + // cas des articles : depend du statut de l'article et de l'auteur |
|
| 797 | + if (isset($opt['statut'])) { |
|
| 798 | + $statut = $opt['statut']; |
|
| 799 | + } else { |
|
| 800 | + if (!$id) { |
|
| 801 | + return false; |
|
| 802 | + } |
|
| 803 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id)); |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + return |
|
| 807 | + // si on est pas auteur de l'article, |
|
| 808 | + // seuls les propose et publies sont visibles |
|
| 809 | + in_array($statut, ['prop', 'publie']) |
|
| 810 | + // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 811 | + or |
|
| 812 | + ($id |
|
| 813 | + and $qui['id_auteur'] |
|
| 814 | + and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | |
@@ -828,24 +828,24 @@ discard block |
||
| 828 | 828 | * @return bool true s'il a le droit, false sinon |
| 829 | 829 | **/ |
| 830 | 830 | function autoriser_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 831 | - # securite, mais on aurait pas du arriver ici ! |
|
| 832 | - if ( |
|
| 833 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 834 | - or function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 835 | - ) { |
|
| 836 | - return $f($faire, $type, $id, $qui, $opt); |
|
| 837 | - } |
|
| 831 | + # securite, mais on aurait pas du arriver ici ! |
|
| 832 | + if ( |
|
| 833 | + function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 834 | + or function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 835 | + ) { |
|
| 836 | + return $f($faire, $type, $id, $qui, $opt); |
|
| 837 | + } |
|
| 838 | 838 | |
| 839 | - if ($qui['statut'] == '0minirezo') { |
|
| 840 | - return true; |
|
| 841 | - } |
|
| 842 | - // admins et redacteurs peuvent voir un auteur |
|
| 843 | - if ($type == 'auteur') { |
|
| 844 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 845 | - } |
|
| 846 | - // sinon par defaut tout est visible |
|
| 847 | - // sauf cas particuliers traites separemment (ie article) |
|
| 848 | - return true; |
|
| 839 | + if ($qui['statut'] == '0minirezo') { |
|
| 840 | + return true; |
|
| 841 | + } |
|
| 842 | + // admins et redacteurs peuvent voir un auteur |
|
| 843 | + if ($type == 'auteur') { |
|
| 844 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 845 | + } |
|
| 846 | + // sinon par defaut tout est visible |
|
| 847 | + // sauf cas particuliers traites separemment (ie article) |
|
| 848 | + return true; |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | |
@@ -866,12 +866,12 @@ discard block |
||
| 866 | 866 | * @return bool true s'il a le droit, false sinon |
| 867 | 867 | **/ |
| 868 | 868 | function autoriser_webmestre_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 869 | - return |
|
| 870 | - (defined('_ID_WEBMESTRES') ? |
|
| 871 | - in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES)) |
|
| 872 | - : $qui['webmestre'] == 'oui') |
|
| 873 | - and $qui['statut'] == '0minirezo' |
|
| 874 | - and !$qui['restreint']; |
|
| 869 | + return |
|
| 870 | + (defined('_ID_WEBMESTRES') ? |
|
| 871 | + in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES)) |
|
| 872 | + : $qui['webmestre'] == 'oui') |
|
| 873 | + and $qui['statut'] == '0minirezo' |
|
| 874 | + and !$qui['restreint']; |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | 877 | /** |
@@ -887,9 +887,9 @@ discard block |
||
| 887 | 887 | * @return bool true s'il a le droit, false sinon |
| 888 | 888 | **/ |
| 889 | 889 | function autoriser_configurer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 890 | - return |
|
| 891 | - $qui['statut'] == '0minirezo' |
|
| 892 | - and !$qui['restreint']; |
|
| 890 | + return |
|
| 891 | + $qui['statut'] == '0minirezo' |
|
| 892 | + and !$qui['restreint']; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -905,8 +905,8 @@ discard block |
||
| 905 | 905 | * @return bool true s'il a le droit, false sinon |
| 906 | 906 | **/ |
| 907 | 907 | function autoriser_sauvegarder_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 908 | - return |
|
| 909 | - $qui['statut'] == '0minirezo'; |
|
| 908 | + return |
|
| 909 | + $qui['statut'] == '0minirezo'; |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | /** |
@@ -922,7 +922,7 @@ discard block |
||
| 922 | 922 | * @return bool true s'il a le droit, false sinon |
| 923 | 923 | **/ |
| 924 | 924 | function autoriser_detruire_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 925 | - return autoriser('webmestre', null, null, $qui, $opt); |
|
| 925 | + return autoriser('webmestre', null, null, $qui, $opt); |
|
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | /** |
@@ -939,23 +939,23 @@ discard block |
||
| 939 | 939 | * @return bool true s'il a le droit, false sinon |
| 940 | 940 | **/ |
| 941 | 941 | function autoriser_auteur_previsualiser_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 942 | - // les admins peuvent "previsualiser" une page auteur |
|
| 943 | - if ( |
|
| 944 | - $qui['statut'] == '0minirezo' |
|
| 945 | - and !$qui['restreint'] |
|
| 946 | - ) { |
|
| 947 | - return true; |
|
| 948 | - } elseif ($id === 0) { |
|
| 949 | - return false; |
|
| 950 | - } |
|
| 951 | - // "Voir en ligne" si l'auteur a un article publie |
|
| 952 | - $n = sql_fetsel( |
|
| 953 | - 'A.id_article', |
|
| 954 | - 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 955 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 956 | - ); |
|
| 942 | + // les admins peuvent "previsualiser" une page auteur |
|
| 943 | + if ( |
|
| 944 | + $qui['statut'] == '0minirezo' |
|
| 945 | + and !$qui['restreint'] |
|
| 946 | + ) { |
|
| 947 | + return true; |
|
| 948 | + } elseif ($id === 0) { |
|
| 949 | + return false; |
|
| 950 | + } |
|
| 951 | + // "Voir en ligne" si l'auteur a un article publie |
|
| 952 | + $n = sql_fetsel( |
|
| 953 | + 'A.id_article', |
|
| 954 | + 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 955 | + "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 956 | + ); |
|
| 957 | 957 | |
| 958 | - return $n ? true : false; |
|
| 958 | + return $n ? true : false; |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | |
@@ -983,7 +983,7 @@ discard block |
||
| 983 | 983 | * @return bool true s'il a le droit, false sinon |
| 984 | 984 | **/ |
| 985 | 985 | function autoriser_auteur_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 986 | - return ($qui['statut'] == '0minirezo'); |
|
| 986 | + return ($qui['statut'] == '0minirezo'); |
|
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | |
@@ -1003,73 +1003,73 @@ discard block |
||
| 1003 | 1003 | **/ |
| 1004 | 1004 | function autoriser_auteur_modifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1005 | 1005 | |
| 1006 | - // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1007 | - // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1008 | - if (!in_array($qui['statut'], ['0minirezo'])) { |
|
| 1009 | - if ( |
|
| 1010 | - $id == $qui['id_auteur'] |
|
| 1011 | - && empty($opt['statut']) |
|
| 1012 | - && empty($opt['webmestre']) |
|
| 1013 | - && empty($opt['restreintes']) |
|
| 1014 | - && empty($opt['login']) |
|
| 1015 | - ) { |
|
| 1016 | - return true; |
|
| 1017 | - } |
|
| 1018 | - return false; |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1022 | - // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1023 | - if ($qui['restreint']) { |
|
| 1024 | - if (isset($opt['webmestre']) and $opt['webmestre']) { |
|
| 1025 | - return false; |
|
| 1026 | - } elseif ( |
|
| 1027 | - (isset($opt['statut']) and ($opt['statut'] == '0minirezo')) |
|
| 1028 | - or (isset($opt['restreintes']) and $opt['restreintes']) |
|
| 1029 | - ) { |
|
| 1030 | - return false; |
|
| 1031 | - } else { |
|
| 1032 | - if ($id == $qui['id_auteur']) { |
|
| 1033 | - if (isset($opt['statut']) and $opt['statut']) { |
|
| 1034 | - return false; |
|
| 1035 | - } else { |
|
| 1036 | - return true; |
|
| 1037 | - } |
|
| 1038 | - } else { |
|
| 1039 | - if ($id_auteur = intval($id)) { |
|
| 1040 | - $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1041 | - if ($t and $t['statut'] != '0minirezo') { |
|
| 1042 | - return true; |
|
| 1043 | - } else { |
|
| 1044 | - return false; |
|
| 1045 | - } |
|
| 1046 | - } // id = 0 => creation |
|
| 1047 | - else { |
|
| 1048 | - return true; |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1051 | - } |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - // Un admin complet fait ce qu'il veut |
|
| 1055 | - // sauf se degrader |
|
| 1056 | - if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) { |
|
| 1057 | - return false; |
|
| 1058 | - } elseif ( |
|
| 1059 | - isset($opt['webmestre']) |
|
| 1060 | - and $opt['webmestre'] |
|
| 1061 | - and (defined('_ID_WEBMESTRES') |
|
| 1062 | - or !autoriser('webmestre')) |
|
| 1063 | - ) { |
|
| 1064 | - // et toucher au statut webmestre si il ne l'est pas lui meme |
|
| 1065 | - // ou si les webmestres sont fixes par constante (securite) |
|
| 1066 | - return false; |
|
| 1067 | - } // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1068 | - elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) { |
|
| 1069 | - return false; |
|
| 1070 | - } else { |
|
| 1071 | - return true; |
|
| 1072 | - } |
|
| 1006 | + // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1007 | + // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1008 | + if (!in_array($qui['statut'], ['0minirezo'])) { |
|
| 1009 | + if ( |
|
| 1010 | + $id == $qui['id_auteur'] |
|
| 1011 | + && empty($opt['statut']) |
|
| 1012 | + && empty($opt['webmestre']) |
|
| 1013 | + && empty($opt['restreintes']) |
|
| 1014 | + && empty($opt['login']) |
|
| 1015 | + ) { |
|
| 1016 | + return true; |
|
| 1017 | + } |
|
| 1018 | + return false; |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1022 | + // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1023 | + if ($qui['restreint']) { |
|
| 1024 | + if (isset($opt['webmestre']) and $opt['webmestre']) { |
|
| 1025 | + return false; |
|
| 1026 | + } elseif ( |
|
| 1027 | + (isset($opt['statut']) and ($opt['statut'] == '0minirezo')) |
|
| 1028 | + or (isset($opt['restreintes']) and $opt['restreintes']) |
|
| 1029 | + ) { |
|
| 1030 | + return false; |
|
| 1031 | + } else { |
|
| 1032 | + if ($id == $qui['id_auteur']) { |
|
| 1033 | + if (isset($opt['statut']) and $opt['statut']) { |
|
| 1034 | + return false; |
|
| 1035 | + } else { |
|
| 1036 | + return true; |
|
| 1037 | + } |
|
| 1038 | + } else { |
|
| 1039 | + if ($id_auteur = intval($id)) { |
|
| 1040 | + $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1041 | + if ($t and $t['statut'] != '0minirezo') { |
|
| 1042 | + return true; |
|
| 1043 | + } else { |
|
| 1044 | + return false; |
|
| 1045 | + } |
|
| 1046 | + } // id = 0 => creation |
|
| 1047 | + else { |
|
| 1048 | + return true; |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | + } |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + // Un admin complet fait ce qu'il veut |
|
| 1055 | + // sauf se degrader |
|
| 1056 | + if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) { |
|
| 1057 | + return false; |
|
| 1058 | + } elseif ( |
|
| 1059 | + isset($opt['webmestre']) |
|
| 1060 | + and $opt['webmestre'] |
|
| 1061 | + and (defined('_ID_WEBMESTRES') |
|
| 1062 | + or !autoriser('webmestre')) |
|
| 1063 | + ) { |
|
| 1064 | + // et toucher au statut webmestre si il ne l'est pas lui meme |
|
| 1065 | + // ou si les webmestres sont fixes par constante (securite) |
|
| 1066 | + return false; |
|
| 1067 | + } // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1068 | + elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) { |
|
| 1069 | + return false; |
|
| 1070 | + } else { |
|
| 1071 | + return true; |
|
| 1072 | + } |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | |
@@ -1086,7 +1086,7 @@ discard block |
||
| 1086 | 1086 | * @return bool true s'il a le droit, false sinon |
| 1087 | 1087 | **/ |
| 1088 | 1088 | function autoriser_associerauteurs_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1089 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1089 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | |
@@ -1103,7 +1103,7 @@ discard block |
||
| 1103 | 1103 | * @return bool true s'il a le droit, false sinon |
| 1104 | 1104 | **/ |
| 1105 | 1105 | function autoriser_chargerftp_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1106 | - return $qui['statut'] == '0minirezo'; |
|
| 1106 | + return $qui['statut'] == '0minirezo'; |
|
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | 1109 | /** |
@@ -1119,7 +1119,7 @@ discard block |
||
| 1119 | 1119 | * @return bool true s'il a le droit, false sinon |
| 1120 | 1120 | **/ |
| 1121 | 1121 | function autoriser_debug_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1122 | - return $qui['statut'] == '0minirezo'; |
|
| 1122 | + return $qui['statut'] == '0minirezo'; |
|
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | /** |
@@ -1136,54 +1136,54 @@ discard block |
||
| 1136 | 1136 | * @return array Liste des rubriques |
| 1137 | 1137 | **/ |
| 1138 | 1138 | function liste_rubriques_auteur($id_auteur, $raz = false) { |
| 1139 | - static $restreint = []; |
|
| 1140 | - |
|
| 1141 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 1142 | - return []; |
|
| 1143 | - } |
|
| 1144 | - if ($raz) { |
|
| 1145 | - unset($restreint[$id_auteur]); |
|
| 1146 | - } elseif (isset($restreint[$id_auteur])) { |
|
| 1147 | - return $restreint[$id_auteur]; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - $rubriques = []; |
|
| 1151 | - if ( |
|
| 1152 | - (!isset($GLOBALS['meta']['version_installee']) |
|
| 1153 | - or $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1154 | - and $r = sql_allfetsel( |
|
| 1155 | - 'id_objet', |
|
| 1156 | - 'spip_auteurs_liens', |
|
| 1157 | - 'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0" |
|
| 1158 | - ) |
|
| 1159 | - and count($r) |
|
| 1160 | - ) { |
|
| 1161 | - $r = array_column($r, 'id_objet'); |
|
| 1162 | - |
|
| 1163 | - // recuperer toute la branche, au format chaine enumeration |
|
| 1164 | - include_spip('inc/rubriques'); |
|
| 1165 | - $r = calcul_branche_in($r); |
|
| 1166 | - $r = explode(',', $r); |
|
| 1167 | - |
|
| 1168 | - // passer les rubriques en index, elimine les doublons |
|
| 1169 | - $r = array_flip($r); |
|
| 1170 | - // recuperer les index seuls |
|
| 1171 | - $r = array_keys($r); |
|
| 1172 | - // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1173 | - // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1174 | - $rubriques = array_combine($r, $r); |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - // Affecter l'auteur session le cas echeant |
|
| 1178 | - if ( |
|
| 1179 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1180 | - and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1181 | - ) { |
|
| 1182 | - $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - |
|
| 1186 | - return $restreint[$id_auteur] = $rubriques; |
|
| 1139 | + static $restreint = []; |
|
| 1140 | + |
|
| 1141 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 1142 | + return []; |
|
| 1143 | + } |
|
| 1144 | + if ($raz) { |
|
| 1145 | + unset($restreint[$id_auteur]); |
|
| 1146 | + } elseif (isset($restreint[$id_auteur])) { |
|
| 1147 | + return $restreint[$id_auteur]; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + $rubriques = []; |
|
| 1151 | + if ( |
|
| 1152 | + (!isset($GLOBALS['meta']['version_installee']) |
|
| 1153 | + or $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1154 | + and $r = sql_allfetsel( |
|
| 1155 | + 'id_objet', |
|
| 1156 | + 'spip_auteurs_liens', |
|
| 1157 | + 'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0" |
|
| 1158 | + ) |
|
| 1159 | + and count($r) |
|
| 1160 | + ) { |
|
| 1161 | + $r = array_column($r, 'id_objet'); |
|
| 1162 | + |
|
| 1163 | + // recuperer toute la branche, au format chaine enumeration |
|
| 1164 | + include_spip('inc/rubriques'); |
|
| 1165 | + $r = calcul_branche_in($r); |
|
| 1166 | + $r = explode(',', $r); |
|
| 1167 | + |
|
| 1168 | + // passer les rubriques en index, elimine les doublons |
|
| 1169 | + $r = array_flip($r); |
|
| 1170 | + // recuperer les index seuls |
|
| 1171 | + $r = array_keys($r); |
|
| 1172 | + // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1173 | + // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1174 | + $rubriques = array_combine($r, $r); |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + // Affecter l'auteur session le cas echeant |
|
| 1178 | + if ( |
|
| 1179 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1180 | + and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1181 | + ) { |
|
| 1182 | + $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + |
|
| 1186 | + return $restreint[$id_auteur] = $rubriques; |
|
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | /** |
@@ -1199,7 +1199,7 @@ discard block |
||
| 1199 | 1199 | * @return bool true s'il a le droit, false sinon |
| 1200 | 1200 | **/ |
| 1201 | 1201 | function autoriser_rubrique_previsualiser_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1202 | - return autoriser('previsualiser'); |
|
| 1202 | + return autoriser('previsualiser'); |
|
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | 1205 | /** |
@@ -1215,7 +1215,7 @@ discard block |
||
| 1215 | 1215 | * @return bool true s'il a le droit, false sinon |
| 1216 | 1216 | **/ |
| 1217 | 1217 | function autoriser_rubrique_iconifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1218 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1218 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | /** |
@@ -1231,8 +1231,8 @@ discard block |
||
| 1231 | 1231 | * @return bool true s'il a le droit, false sinon |
| 1232 | 1232 | **/ |
| 1233 | 1233 | function autoriser_auteur_iconifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1234 | - return (($id == $qui['id_auteur']) or |
|
| 1235 | - (($qui['statut'] == '0minirezo') and !$qui['restreint'])); |
|
| 1234 | + return (($id == $qui['id_auteur']) or |
|
| 1235 | + (($qui['statut'] == '0minirezo') and !$qui['restreint'])); |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | /** |
@@ -1248,8 +1248,8 @@ discard block |
||
| 1248 | 1248 | * @return bool true s'il a le droit, false sinon |
| 1249 | 1249 | **/ |
| 1250 | 1250 | function autoriser_iconifier_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1251 | - // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1252 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1251 | + // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1252 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1253 | 1253 | } |
| 1254 | 1254 | |
| 1255 | 1255 | |
@@ -1267,7 +1267,7 @@ discard block |
||
| 1267 | 1267 | * @return bool true |
| 1268 | 1268 | **/ |
| 1269 | 1269 | function autoriser_ok_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1270 | - return true; |
|
| 1270 | + return true; |
|
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | 1273 | /** |
@@ -1284,7 +1284,7 @@ discard block |
||
| 1284 | 1284 | * @return bool false |
| 1285 | 1285 | **/ |
| 1286 | 1286 | function autoriser_niet_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1287 | - return false; |
|
| 1287 | + return false; |
|
| 1288 | 1288 | } |
| 1289 | 1289 | |
| 1290 | 1290 | /** |
@@ -1300,11 +1300,11 @@ discard block |
||
| 1300 | 1300 | * @return bool false |
| 1301 | 1301 | **/ |
| 1302 | 1302 | function autoriser_base_reparer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1303 | - if (!autoriser('detruire') or _request('reinstall')) { |
|
| 1304 | - return false; |
|
| 1305 | - } |
|
| 1303 | + if (!autoriser('detruire') or _request('reinstall')) { |
|
| 1304 | + return false; |
|
| 1305 | + } |
|
| 1306 | 1306 | |
| 1307 | - return true; |
|
| 1307 | + return true; |
|
| 1308 | 1308 | } |
| 1309 | 1309 | |
| 1310 | 1310 | /** |
@@ -1320,7 +1320,7 @@ discard block |
||
| 1320 | 1320 | * @return bool true s'il a le droit, false sinon |
| 1321 | 1321 | **/ |
| 1322 | 1322 | function autoriser_infosperso_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1323 | - return true; |
|
| 1323 | + return true; |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | /** |
@@ -1336,7 +1336,7 @@ discard block |
||
| 1336 | 1336 | * @return bool true s'il a le droit, false sinon |
| 1337 | 1337 | **/ |
| 1338 | 1338 | function autoriser_langage_configurer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1339 | - return true; |
|
| 1339 | + return true; |
|
| 1340 | 1340 | } |
| 1341 | 1341 | |
| 1342 | 1342 | /** |
@@ -1352,7 +1352,7 @@ discard block |
||
| 1352 | 1352 | * @return bool true s'il a le droit, false sinon |
| 1353 | 1353 | **/ |
| 1354 | 1354 | function autoriser_configurerlangage_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1355 | - return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1355 | + return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | 1358 | /** |
@@ -1368,7 +1368,7 @@ discard block |
||
| 1368 | 1368 | * @return bool true s'il a le droit, false sinon |
| 1369 | 1369 | **/ |
| 1370 | 1370 | function autoriser_preferences_configurer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1371 | - return true; |
|
| 1371 | + return true; |
|
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | 1374 | /** |
@@ -1384,7 +1384,7 @@ discard block |
||
| 1384 | 1384 | * @return bool true s'il a le droit, false sinon |
| 1385 | 1385 | **/ |
| 1386 | 1386 | function autoriser_configurerpreferences_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1387 | - return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1387 | + return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | 1390 | /** |
@@ -1400,8 +1400,8 @@ discard block |
||
| 1400 | 1400 | * @return bool true s'il a le droit, false sinon |
| 1401 | 1401 | **/ |
| 1402 | 1402 | function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1403 | - return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) |
|
| 1404 | - and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui'); |
|
| 1403 | + return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) |
|
| 1404 | + and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui'); |
|
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | 1407 | /** |
@@ -1418,7 +1418,7 @@ discard block |
||
| 1418 | 1418 | * @return bool true s'il a le droit, false sinon |
| 1419 | 1419 | **/ |
| 1420 | 1420 | function autoriser_menugrandeentree_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1421 | - return true; |
|
| 1421 | + return true; |
|
| 1422 | 1422 | } |
| 1423 | 1423 | |
| 1424 | 1424 | /** |
@@ -1434,7 +1434,7 @@ discard block |
||
| 1434 | 1434 | * @return bool true s'il a le droit, false sinon |
| 1435 | 1435 | **/ |
| 1436 | 1436 | function autoriser_auteurs_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1437 | - return true; |
|
| 1437 | + return true; |
|
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | 1440 | /** |
@@ -1450,7 +1450,7 @@ discard block |
||
| 1450 | 1450 | * @return bool true s'il a le droit, false sinon |
| 1451 | 1451 | **/ |
| 1452 | 1452 | function autoriser_auteurs_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1453 | - return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1453 | + return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | 1456 | /** |
@@ -1466,7 +1466,7 @@ discard block |
||
| 1466 | 1466 | * @return bool true s'il a le droit, false sinon |
| 1467 | 1467 | **/ |
| 1468 | 1468 | function autoriser_articles_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1469 | - return true; |
|
| 1469 | + return true; |
|
| 1470 | 1470 | } |
| 1471 | 1471 | |
| 1472 | 1472 | /** |
@@ -1482,7 +1482,7 @@ discard block |
||
| 1482 | 1482 | * @return bool true s'il a le droit, false sinon |
| 1483 | 1483 | **/ |
| 1484 | 1484 | function autoriser_articles_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1485 | - return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1485 | + return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | 1488 | /** |
@@ -1498,7 +1498,7 @@ discard block |
||
| 1498 | 1498 | * @return bool true s'il a le droit, false sinon |
| 1499 | 1499 | **/ |
| 1500 | 1500 | function autoriser_rubriques_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1501 | - return true; |
|
| 1501 | + return true; |
|
| 1502 | 1502 | } |
| 1503 | 1503 | |
| 1504 | 1504 | /** |
@@ -1514,7 +1514,7 @@ discard block |
||
| 1514 | 1514 | * @return bool true s'il a le droit, false sinon |
| 1515 | 1515 | **/ |
| 1516 | 1516 | function autoriser_rubriques_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1517 | - return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1517 | + return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1518 | 1518 | } |
| 1519 | 1519 | |
| 1520 | 1520 | /** |
@@ -1530,7 +1530,7 @@ discard block |
||
| 1530 | 1530 | * @return bool true s'il a le droit, false sinon |
| 1531 | 1531 | **/ |
| 1532 | 1532 | function autoriser_articlecreer_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1533 | - return verifier_table_non_vide(); |
|
| 1533 | + return verifier_table_non_vide(); |
|
| 1534 | 1534 | } |
| 1535 | 1535 | |
| 1536 | 1536 | |
@@ -1549,7 +1549,7 @@ discard block |
||
| 1549 | 1549 | * @return bool true s'il a le droit, false sinon |
| 1550 | 1550 | **/ |
| 1551 | 1551 | function autoriser_auteurcreer_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1552 | - return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1552 | + return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1553 | 1553 | } |
| 1554 | 1554 | |
| 1555 | 1555 | /** |
@@ -1565,13 +1565,13 @@ discard block |
||
| 1565 | 1565 | * @return bool true s'il a le droit, false sinon |
| 1566 | 1566 | **/ |
| 1567 | 1567 | function autoriser_visiteurs_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1568 | - include_spip('base/abstract_sql'); |
|
| 1569 | - return |
|
| 1570 | - $qui['statut'] == '0minirezo' and !$qui['restreint'] |
|
| 1571 | - and ( |
|
| 1572 | - $GLOBALS['meta']['accepter_visiteurs'] != 'non' |
|
| 1573 | - or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0 |
|
| 1574 | - ); |
|
| 1568 | + include_spip('base/abstract_sql'); |
|
| 1569 | + return |
|
| 1570 | + $qui['statut'] == '0minirezo' and !$qui['restreint'] |
|
| 1571 | + and ( |
|
| 1572 | + $GLOBALS['meta']['accepter_visiteurs'] != 'non' |
|
| 1573 | + or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0 |
|
| 1574 | + ); |
|
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | 1577 | /** |
@@ -1587,7 +1587,7 @@ discard block |
||
| 1587 | 1587 | * @return bool true s'il a le droit, false sinon |
| 1588 | 1588 | **/ |
| 1589 | 1589 | function autoriser_suiviedito_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1590 | - return $qui['statut'] == '0minirezo'; |
|
| 1590 | + return $qui['statut'] == '0minirezo'; |
|
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 1593 | 1593 | /** |
@@ -1603,7 +1603,7 @@ discard block |
||
| 1603 | 1603 | * @return bool true s'il a le droit, false sinon |
| 1604 | 1604 | **/ |
| 1605 | 1605 | function autoriser_synchro_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1606 | - return $qui['statut'] == '0minirezo'; |
|
| 1606 | + return $qui['statut'] == '0minirezo'; |
|
| 1607 | 1607 | } |
| 1608 | 1608 | |
| 1609 | 1609 | /** |
@@ -1619,7 +1619,7 @@ discard block |
||
| 1619 | 1619 | * @return bool true s'il a le droit, false sinon |
| 1620 | 1620 | **/ |
| 1621 | 1621 | function autoriser_configurerinteractions_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1622 | - return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1622 | + return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | 1625 | /** |
@@ -1635,7 +1635,7 @@ discard block |
||
| 1635 | 1635 | * @return bool true s'il a le droit, false sinon |
| 1636 | 1636 | **/ |
| 1637 | 1637 | function autoriser_configurerlangue_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1638 | - return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1638 | + return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | 1641 | /** |
@@ -1651,7 +1651,7 @@ discard block |
||
| 1651 | 1651 | * @return bool true s'il a le droit, false sinon |
| 1652 | 1652 | **/ |
| 1653 | 1653 | function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1654 | - return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1654 | + return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1655 | 1655 | } |
| 1656 | 1656 | |
| 1657 | 1657 | /** |
@@ -1667,7 +1667,7 @@ discard block |
||
| 1667 | 1667 | * @return bool true s'il a le droit, false sinon |
| 1668 | 1668 | **/ |
| 1669 | 1669 | function autoriser_configurercontenu_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1670 | - return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1670 | + return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1671 | 1671 | } |
| 1672 | 1672 | |
| 1673 | 1673 | /** |
@@ -1683,7 +1683,7 @@ discard block |
||
| 1683 | 1683 | * @return bool true s'il a le droit, false sinon |
| 1684 | 1684 | **/ |
| 1685 | 1685 | function autoriser_configureravancees_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1686 | - return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1686 | + return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1687 | 1687 | } |
| 1688 | 1688 | |
| 1689 | 1689 | /** |
@@ -1699,7 +1699,7 @@ discard block |
||
| 1699 | 1699 | * @return bool true s'il a le droit, false sinon |
| 1700 | 1700 | **/ |
| 1701 | 1701 | function autoriser_adminplugin_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1702 | - return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1702 | + return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | /** |
@@ -1715,7 +1715,7 @@ discard block |
||
| 1715 | 1715 | * @return bool true s'il a le droit, false sinon |
| 1716 | 1716 | **/ |
| 1717 | 1717 | function autoriser_admintech_menu_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1718 | - return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1718 | + return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1719 | 1719 | } |
| 1720 | 1720 | |
| 1721 | 1721 | /** |
@@ -1731,7 +1731,7 @@ discard block |
||
| 1731 | 1731 | * @return bool true s'il a le droit, false sinon |
| 1732 | 1732 | **/ |
| 1733 | 1733 | function autoriser_queue_purger_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1734 | - return autoriser('webmestre'); |
|
| 1734 | + return autoriser('webmestre'); |
|
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 1737 | 1737 | |
@@ -1749,11 +1749,11 @@ discard block |
||
| 1749 | 1749 | * @return bool true s'il a le droit, false sinon |
| 1750 | 1750 | **/ |
| 1751 | 1751 | function autoriser_echafauder_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1752 | - if (test_espace_prive()) { |
|
| 1753 | - return intval($qui['id_auteur']) ? true : false; |
|
| 1754 | - } else { |
|
| 1755 | - return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1756 | - } |
|
| 1752 | + if (test_espace_prive()) { |
|
| 1753 | + return intval($qui['id_auteur']) ? true : false; |
|
| 1754 | + } else { |
|
| 1755 | + return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1756 | + } |
|
| 1757 | 1757 | } |
| 1758 | 1758 | |
| 1759 | 1759 | |
@@ -1768,27 +1768,27 @@ discard block |
||
| 1768 | 1768 | * Identifiants d'auteurs |
| 1769 | 1769 | */ |
| 1770 | 1770 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1771 | - $objet = objet_type($objet); |
|
| 1772 | - $where = [ |
|
| 1773 | - 'objet=' . sql_quote($objet), |
|
| 1774 | - 'id_objet=' . intval($id_objet) |
|
| 1775 | - ]; |
|
| 1776 | - if (!empty($cond)) { |
|
| 1777 | - if (is_array($cond)) { |
|
| 1778 | - $where = array_merge($where, $cond); |
|
| 1779 | - } else { |
|
| 1780 | - $where[] = $cond; |
|
| 1781 | - } |
|
| 1782 | - } |
|
| 1783 | - $auteurs = sql_allfetsel( |
|
| 1784 | - 'id_auteur', |
|
| 1785 | - 'spip_auteurs_liens', |
|
| 1786 | - $where |
|
| 1787 | - ); |
|
| 1788 | - if (is_array($auteurs)) { |
|
| 1789 | - return array_column($auteurs, 'id_auteur'); |
|
| 1790 | - } |
|
| 1791 | - return []; |
|
| 1771 | + $objet = objet_type($objet); |
|
| 1772 | + $where = [ |
|
| 1773 | + 'objet=' . sql_quote($objet), |
|
| 1774 | + 'id_objet=' . intval($id_objet) |
|
| 1775 | + ]; |
|
| 1776 | + if (!empty($cond)) { |
|
| 1777 | + if (is_array($cond)) { |
|
| 1778 | + $where = array_merge($where, $cond); |
|
| 1779 | + } else { |
|
| 1780 | + $where[] = $cond; |
|
| 1781 | + } |
|
| 1782 | + } |
|
| 1783 | + $auteurs = sql_allfetsel( |
|
| 1784 | + 'id_auteur', |
|
| 1785 | + 'spip_auteurs_liens', |
|
| 1786 | + $where |
|
| 1787 | + ); |
|
| 1788 | + if (is_array($auteurs)) { |
|
| 1789 | + return array_column($auteurs, 'id_auteur'); |
|
| 1790 | + } |
|
| 1791 | + return []; |
|
| 1792 | 1792 | } |
| 1793 | 1793 | |
| 1794 | 1794 | /** |
@@ -1803,11 +1803,11 @@ discard block |
||
| 1803 | 1803 | * - false : serveur SQL indisponible |
| 1804 | 1804 | */ |
| 1805 | 1805 | function auteurs_article($id_article, $cond = '') { |
| 1806 | - return sql_allfetsel( |
|
| 1807 | - 'id_auteur', |
|
| 1808 | - 'spip_auteurs_liens', |
|
| 1809 | - "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '') |
|
| 1810 | - ); |
|
| 1806 | + return sql_allfetsel( |
|
| 1807 | + 'id_auteur', |
|
| 1808 | + 'spip_auteurs_liens', |
|
| 1809 | + "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '') |
|
| 1810 | + ); |
|
| 1811 | 1811 | } |
| 1812 | 1812 | |
| 1813 | 1813 | |
@@ -1821,7 +1821,7 @@ discard block |
||
| 1821 | 1821 | */ |
| 1822 | 1822 | function acces_restreint_rubrique($id_rubrique) { |
| 1823 | 1823 | |
| 1824 | - return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1824 | + return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1825 | 1825 | } |
| 1826 | 1826 | |
| 1827 | 1827 | |
@@ -1834,12 +1834,12 @@ discard block |
||
| 1834 | 1834 | * @return bool true si un parent existe |
| 1835 | 1835 | */ |
| 1836 | 1836 | function verifier_table_non_vide($table = 'spip_rubriques') { |
| 1837 | - static $done = []; |
|
| 1838 | - if (!isset($done[$table])) { |
|
| 1839 | - $done[$table] = sql_countsel($table) > 0; |
|
| 1840 | - } |
|
| 1837 | + static $done = []; |
|
| 1838 | + if (!isset($done[$table])) { |
|
| 1839 | + $done[$table] = sql_countsel($table) > 0; |
|
| 1840 | + } |
|
| 1841 | 1841 | |
| 1842 | - return $done[$table]; |
|
| 1842 | + return $done[$table]; |
|
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | 1845 | /** |
@@ -1864,15 +1864,15 @@ discard block |
||
| 1864 | 1864 | */ |
| 1865 | 1865 | function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) { |
| 1866 | 1866 | |
| 1867 | - $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1868 | - switch ($s) { |
|
| 1869 | - case 'info_redacteurs': |
|
| 1870 | - return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui'); |
|
| 1871 | - case 'info_visiteurs': |
|
| 1872 | - return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo'); |
|
| 1873 | - } |
|
| 1867 | + $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1868 | + switch ($s) { |
|
| 1869 | + case 'info_redacteurs': |
|
| 1870 | + return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui'); |
|
| 1871 | + case 'info_visiteurs': |
|
| 1872 | + return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo'); |
|
| 1873 | + } |
|
| 1874 | 1874 | |
| 1875 | - return false; |
|
| 1875 | + return false; |
|
| 1876 | 1876 | } |
| 1877 | 1877 | |
| 1878 | 1878 | /** |
@@ -1888,7 +1888,7 @@ discard block |
||
| 1888 | 1888 | * @return bool false |
| 1889 | 1889 | **/ |
| 1890 | 1890 | function autoriser_inscription_relancer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1891 | - return $qui['statut'] == '0minirezo' and !$qui['restreint']; |
|
| 1891 | + return $qui['statut'] == '0minirezo' and !$qui['restreint']; |
|
| 1892 | 1892 | } |
| 1893 | 1893 | |
| 1894 | 1894 | /** |
@@ -1904,5 +1904,5 @@ discard block |
||
| 1904 | 1904 | * @return bool true s'il a le droit, false sinon |
| 1905 | 1905 | **/ |
| 1906 | 1906 | function autoriser_phpinfos_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 1907 | - return autoriser('webmestre'); |
|
| 1907 | + return autoriser('webmestre'); |
|
| 1908 | 1908 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | // mais apres la fonction autoriser() |
| 116 | 116 | if ($f = find_in_path('mes_fonctions.php')) { |
| 117 | 117 | global $dossier_squelettes; |
| 118 | - include_once(_ROOT_CWD . $f); |
|
| 118 | + include_once(_ROOT_CWD.$f); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | $qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : []; |
| 157 | 157 | $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
| 158 | 158 | } elseif (is_numeric($qui)) { |
| 159 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 159 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$qui); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // Admins restreints, on construit ici (pas generique mais...) |
@@ -166,8 +166,8 @@ discard block |
||
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | spip_log( |
| 169 | - "autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?', |
|
| 170 | - 'autoriser' . _LOG_DEBUG |
|
| 169 | + "autoriser $faire $type $id (".(isset($qui['nom']) ? $qui['nom'] : '').') ?', |
|
| 170 | + 'autoriser'._LOG_DEBUG |
|
| 171 | 171 | ); |
| 172 | 172 | |
| 173 | 173 | // passer par objet_type pour avoir les alias |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | (isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) and autoriser_exception($faire, $type, $id, 'verifier')) |
| 184 | 184 | or (isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) and autoriser_exception($faire, $type, '*', 'verifier')) |
| 185 | 185 | ) { |
| 186 | - spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 186 | + spip_log("autoriser ($faire, $type, $id, ".(isset($qui['nom']) ? $qui['nom'] : '').') : OK Exception', 'autoriser'._LOG_DEBUG); |
|
| 187 | 187 | return true; |
| 188 | 188 | } |
| 189 | 189 | |
@@ -192,18 +192,18 @@ discard block |
||
| 192 | 192 | // autoriser_faire[_dist], autoriser_defaut[_dist] |
| 193 | 193 | $fonctions = $type |
| 194 | 194 | ? [ |
| 195 | - 'autoriser_' . $type . '_' . $faire, |
|
| 196 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 197 | - 'autoriser_' . $type, |
|
| 198 | - 'autoriser_' . $type . '_dist', |
|
| 199 | - 'autoriser_' . $faire, |
|
| 200 | - 'autoriser_' . $faire . '_dist', |
|
| 195 | + 'autoriser_'.$type.'_'.$faire, |
|
| 196 | + 'autoriser_'.$type.'_'.$faire.'_dist', |
|
| 197 | + 'autoriser_'.$type, |
|
| 198 | + 'autoriser_'.$type.'_dist', |
|
| 199 | + 'autoriser_'.$faire, |
|
| 200 | + 'autoriser_'.$faire.'_dist', |
|
| 201 | 201 | 'autoriser_defaut', |
| 202 | 202 | 'autoriser_defaut_dist' |
| 203 | 203 | ] |
| 204 | 204 | : [ |
| 205 | - 'autoriser_' . $faire, |
|
| 206 | - 'autoriser_' . $faire . '_dist', |
|
| 205 | + 'autoriser_'.$faire, |
|
| 206 | + 'autoriser_'.$faire.'_dist', |
|
| 207 | 207 | 'autoriser_defaut', |
| 208 | 208 | 'autoriser_defaut_dist' |
| 209 | 209 | ]; |
@@ -216,8 +216,8 @@ discard block |
||
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | spip_log( |
| 219 | - "$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 220 | - 'autoriser' . _LOG_DEBUG |
|
| 219 | + "$f($faire, $type, $id, ".(isset($qui['nom']) ? $qui['nom'] : '').') : '.($a ? 'OK' : 'niet'), |
|
| 220 | + 'autoriser'._LOG_DEBUG |
|
| 221 | 221 | ); |
| 222 | 222 | |
| 223 | 223 | return $a; |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | function autoriser_previsualiser_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 353 | 353 | |
| 354 | 354 | // Le visiteur a-t-il un statut prevu par la config ? |
| 355 | - if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) { |
|
| 355 | + if (strpos($GLOBALS['meta']['preview'], ','.$qui['statut'].',') !== false) { |
|
| 356 | 356 | return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
| 357 | 357 | } |
| 358 | 358 | |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | } // pas de champ passe a la demande => NIET |
| 410 | 410 | $previsu = explode(',', $c['previsu']); |
| 411 | 411 | // regarder si ce statut est autorise pour l'auteur |
| 412 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 412 | + if (in_array($opt[$champ].'/auteur', $previsu)) { |
|
| 413 | 413 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 414 | 414 | // sinon l’auteur en session |
| 415 | 415 | include_spip('inc/securiser_action'); |
@@ -423,12 +423,12 @@ discard block |
||
| 423 | 423 | |
| 424 | 424 | if (!$id_auteur) { |
| 425 | 425 | return false; |
| 426 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 426 | + } elseif (autoriser('previsualiser'.$opt[$champ], $type, 0, $id_auteur)) { |
|
| 427 | 427 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 428 | 428 | } elseif ( |
| 429 | 429 | !sql_countsel( |
| 430 | 430 | 'spip_auteurs_liens', |
| 431 | - 'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id) |
|
| 431 | + 'id_auteur='.intval($id_auteur).' AND objet='.sql_quote($type).' AND id_objet='.intval($id) |
|
| 432 | 432 | ) |
| 433 | 433 | ) { |
| 434 | 434 | return false; |
@@ -471,16 +471,16 @@ discard block |
||
| 471 | 471 | // multilinguisme par secteur et objet rattaché à une rubrique |
| 472 | 472 | $primary = id_table_objet($type); |
| 473 | 473 | if ($table != 'spip_rubriques') { |
| 474 | - $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id)); |
|
| 474 | + $id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=".intval($id)); |
|
| 475 | 475 | } else { |
| 476 | 476 | $id_rubrique = $id; |
| 477 | 477 | } |
| 478 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 478 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique)); |
|
| 479 | 479 | if (!$id_secteur > 0) { |
| 480 | 480 | $id_secteur = $id_rubrique; |
| 481 | 481 | } |
| 482 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur)); |
|
| 483 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id)); |
|
| 482 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique='.intval($id_secteur)); |
|
| 483 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=".intval($id)); |
|
| 484 | 484 | if ($langue_secteur != $langue_objet) { |
| 485 | 485 | // configuration incohérente, on laisse l'utilisateur corriger la situation |
| 486 | 486 | return true; |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
| 489 | 489 | return false; |
| 490 | 490 | } else { |
| 491 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id)); |
|
| 491 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id)); |
|
| 492 | 492 | if ($id_parent != 0) { |
| 493 | 493 | // sous-rubriques : pas de choix de langue |
| 494 | 494 | return false; |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | |
| 537 | 537 | if (!isset($opt['statut'])) { |
| 538 | 538 | if (isset($desc['field']['statut'])) { |
| 539 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id)); |
|
| 539 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type).'='.intval($id)); |
|
| 540 | 540 | } else { |
| 541 | 541 | $statut = 'publie'; |
| 542 | 542 | } // pas de statut => publie |
@@ -696,11 +696,11 @@ discard block |
||
| 696 | 696 | return false; |
| 697 | 697 | } |
| 698 | 698 | |
| 699 | - if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) { |
|
| 699 | + if (sql_countsel('spip_rubriques', 'id_parent='.intval($id))) { |
|
| 700 | 700 | return false; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | - if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) { |
|
| 703 | + if (sql_countsel('spip_articles', 'id_rubrique='.intval($id)." AND (statut<>'poubelle')")) { |
|
| 704 | 704 | return false; |
| 705 | 705 | } |
| 706 | 706 | |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | if (!$id) { |
| 736 | 736 | return false; |
| 737 | 737 | } |
| 738 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 738 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article='.sql_quote($id)); |
|
| 739 | 739 | |
| 740 | 740 | return |
| 741 | 741 | $r |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | (!isset($opt['statut']) or $opt['statut'] !== 'publie') |
| 747 | 747 | and in_array($qui['statut'], ['0minirezo', '1comite']) |
| 748 | 748 | and in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
| 749 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 749 | + and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']) |
|
| 750 | 750 | ) |
| 751 | 751 | ); |
| 752 | 752 | } |
@@ -800,7 +800,7 @@ discard block |
||
| 800 | 800 | if (!$id) { |
| 801 | 801 | return false; |
| 802 | 802 | } |
| 803 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id)); |
|
| 803 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article='.intval($id)); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | return |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | or |
| 812 | 812 | ($id |
| 813 | 813 | and $qui['id_auteur'] |
| 814 | - and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])); |
|
| 814 | + and auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur'])); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | |
@@ -830,8 +830,8 @@ discard block |
||
| 830 | 830 | function autoriser_voir_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 831 | 831 | # securite, mais on aurait pas du arriver ici ! |
| 832 | 832 | if ( |
| 833 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 834 | - or function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 833 | + function_exists($f = 'autoriser_'.$type.'_voir') |
|
| 834 | + or function_exists($f = 'autoriser_'.$type.'_voir_dist') |
|
| 835 | 835 | ) { |
| 836 | 836 | return $f($faire, $type, $id, $qui, $opt); |
| 837 | 837 | } |
@@ -952,7 +952,7 @@ discard block |
||
| 952 | 952 | $n = sql_fetsel( |
| 953 | 953 | 'A.id_article', |
| 954 | 954 | 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
| 955 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 955 | + "A.statut='publie' AND L.id_auteur=".sql_quote($id) |
|
| 956 | 956 | ); |
| 957 | 957 | |
| 958 | 958 | return $n ? true : false; |
@@ -1154,7 +1154,7 @@ discard block |
||
| 1154 | 1154 | and $r = sql_allfetsel( |
| 1155 | 1155 | 'id_objet', |
| 1156 | 1156 | 'spip_auteurs_liens', |
| 1157 | - 'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0" |
|
| 1157 | + 'id_auteur='.intval($id_auteur)." AND objet='rubrique' AND id_objet!=0" |
|
| 1158 | 1158 | ) |
| 1159 | 1159 | and count($r) |
| 1160 | 1160 | ) { |
@@ -1770,8 +1770,8 @@ discard block |
||
| 1770 | 1770 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1771 | 1771 | $objet = objet_type($objet); |
| 1772 | 1772 | $where = [ |
| 1773 | - 'objet=' . sql_quote($objet), |
|
| 1774 | - 'id_objet=' . intval($id_objet) |
|
| 1773 | + 'objet='.sql_quote($objet), |
|
| 1774 | + 'id_objet='.intval($id_objet) |
|
| 1775 | 1775 | ]; |
| 1776 | 1776 | if (!empty($cond)) { |
| 1777 | 1777 | if (is_array($cond)) { |
@@ -1806,7 +1806,7 @@ discard block |
||
| 1806 | 1806 | return sql_allfetsel( |
| 1807 | 1807 | 'id_auteur', |
| 1808 | 1808 | 'spip_auteurs_liens', |
| 1809 | - "objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '') |
|
| 1809 | + "objet='article' AND id_objet=".intval($id_article).($cond ? " AND $cond" : '') |
|
| 1810 | 1810 | ); |
| 1811 | 1811 | } |
| 1812 | 1812 | |
@@ -257,8 +257,7 @@ discard block |
||
| 257 | 257 | if ($id === '*') { |
| 258 | 258 | unset($GLOBALS['autoriser_exception'][$faire][$type]); |
| 259 | 259 | unset($autorisation[$faire][$type]); |
| 260 | - } |
|
| 261 | - else { |
|
| 260 | + } else { |
|
| 262 | 261 | unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
| 263 | 262 | unset($autorisation[$faire][$type][$id]); |
| 264 | 263 | } |
@@ -617,8 +616,7 @@ discard block |
||
| 617 | 616 | function autoriser_rubrique_creer_dist(string $faire, string $type, int $id, array $qui, array $opt): bool { |
| 618 | 617 | if (!empty($opt['id_parent'])) { |
| 619 | 618 | return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
| 620 | - } |
|
| 621 | - else { |
|
| 619 | + } else { |
|
| 622 | 620 | return autoriser('defaut', null, null, $qui, $opt); |
| 623 | 621 | } |
| 624 | 622 | } |
@@ -767,8 +765,7 @@ discard block |
||
| 767 | 765 | if (!empty($opt['id_parent'])) { |
| 768 | 766 | // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
| 769 | 767 | return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
| 770 | - } |
|
| 771 | - else { |
|
| 768 | + } else { |
|
| 772 | 769 | return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], ['0minirezo', '1comite'])); |
| 773 | 770 | } |
| 774 | 771 | } |