@@ -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 | include_spip('inc/boutons'); |
@@ -37,33 +37,33 @@ discard block |
||
| 37 | 37 | * Contexte |
| 38 | 38 | **/ |
| 39 | 39 | function definir_barre_contexte($contexte = null) { |
| 40 | - if (is_null($contexte)) { |
|
| 41 | - $contexte = $_GET; |
|
| 42 | - } elseif (is_string($contexte)) { |
|
| 43 | - $contexte = unserialize($contexte); |
|
| 44 | - } |
|
| 45 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | - if (!function_exists('trouver_objet_exec')) { |
|
| 47 | - include_spip('inc/pipelines_ecrire'); |
|
| 48 | - } |
|
| 49 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | - $_id = $e['id_table_objet']; |
|
| 51 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | - $table = $e['table_objet_sql']; |
|
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | - if (isset($row['id_rubrique'])) { |
|
| 55 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | - if (isset($row['id_secteur'])) { |
|
| 57 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | - } |
|
| 59 | - } elseif (isset($row['id_groupe'])) { |
|
| 60 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - return $contexte; |
|
| 40 | + if (is_null($contexte)) { |
|
| 41 | + $contexte = $_GET; |
|
| 42 | + } elseif (is_string($contexte)) { |
|
| 43 | + $contexte = unserialize($contexte); |
|
| 44 | + } |
|
| 45 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | + if (!function_exists('trouver_objet_exec')) { |
|
| 47 | + include_spip('inc/pipelines_ecrire'); |
|
| 48 | + } |
|
| 49 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | + $_id = $e['id_table_objet']; |
|
| 51 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | + $table = $e['table_objet_sql']; |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | + if (isset($row['id_rubrique'])) { |
|
| 55 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | + if (isset($row['id_secteur'])) { |
|
| 57 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | + } |
|
| 59 | + } elseif (isset($row['id_groupe'])) { |
|
| 60 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + return $contexte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -79,92 +79,92 @@ discard block |
||
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | 81 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 82 | - include_spip('inc/autoriser'); |
|
| 83 | - $boutons_admin = []; |
|
| 82 | + include_spip('inc/autoriser'); |
|
| 83 | + $boutons_admin = []; |
|
| 84 | 84 | |
| 85 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | - $liste_boutons = []; |
|
| 85 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | + $liste_boutons = []; |
|
| 87 | 87 | |
| 88 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | - if ( |
|
| 90 | - function_exists('boutons_plugins') |
|
| 91 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | - ) { |
|
| 93 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | - } |
|
| 88 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | + if ( |
|
| 90 | + function_exists('boutons_plugins') |
|
| 91 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | + ) { |
|
| 93 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - foreach ($liste_boutons as $id => $infos) { |
|
| 97 | - $parent = ''; |
|
| 98 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | - if ( |
|
| 100 | - !isset($infos['parent']) |
|
| 101 | - or !($parent = $infos['parent']) |
|
| 102 | - or !$autorise |
|
| 103 | - or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | - ) { |
|
| 105 | - if ( |
|
| 106 | - $parent |
|
| 107 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | - and isset($boutons_admin[$parent]) |
|
| 109 | - ) { |
|
| 110 | - if (!is_array($boutons_admin[$parent]->sousmenu)) { |
|
| 111 | - $boutons_admin[$parent]->sousmenu = []; |
|
| 112 | - } |
|
| 113 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 114 | - if ($position < 0) { |
|
| 115 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 116 | - } |
|
| 117 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 118 | - + [ |
|
| 119 | - $id => new Bouton( |
|
| 120 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 121 | - $infos['titre'], // titre |
|
| 122 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 123 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 124 | - ) |
|
| 125 | - ] |
|
| 126 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 127 | - } |
|
| 128 | - if ( |
|
| 129 | - !$parent |
|
| 130 | - // provisoire, eviter les vieux boutons |
|
| 131 | - and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 132 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 133 | - ) { |
|
| 134 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 135 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 136 | - + [ |
|
| 137 | - $id => new Bouton( |
|
| 138 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 139 | - $infos['titre'], // titre |
|
| 140 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 141 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 142 | - ) |
|
| 143 | - ] |
|
| 144 | - + array_slice($boutons_admin, $position, 100); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 96 | + foreach ($liste_boutons as $id => $infos) { |
|
| 97 | + $parent = ''; |
|
| 98 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | + if ( |
|
| 100 | + !isset($infos['parent']) |
|
| 101 | + or !($parent = $infos['parent']) |
|
| 102 | + or !$autorise |
|
| 103 | + or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | + ) { |
|
| 105 | + if ( |
|
| 106 | + $parent |
|
| 107 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | + and isset($boutons_admin[$parent]) |
|
| 109 | + ) { |
|
| 110 | + if (!is_array($boutons_admin[$parent]->sousmenu)) { |
|
| 111 | + $boutons_admin[$parent]->sousmenu = []; |
|
| 112 | + } |
|
| 113 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 114 | + if ($position < 0) { |
|
| 115 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 116 | + } |
|
| 117 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 118 | + + [ |
|
| 119 | + $id => new Bouton( |
|
| 120 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 121 | + $infos['titre'], // titre |
|
| 122 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 123 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 124 | + ) |
|
| 125 | + ] |
|
| 126 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 127 | + } |
|
| 128 | + if ( |
|
| 129 | + !$parent |
|
| 130 | + // provisoire, eviter les vieux boutons |
|
| 131 | + and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 132 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 133 | + ) { |
|
| 134 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 135 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 136 | + + [ |
|
| 137 | + $id => new Bouton( |
|
| 138 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 139 | + $infos['titre'], // titre |
|
| 140 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 141 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 142 | + ) |
|
| 143 | + ] |
|
| 144 | + + array_slice($boutons_admin, $position, 100); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 149 | 149 | |
| 150 | - // définir les favoris et positions d’origine |
|
| 151 | - if ($boutons_admin) { |
|
| 152 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 153 | - $i = 1; |
|
| 154 | - foreach ($boutons_admin as $key => $menu) { |
|
| 155 | - $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 156 | - $menu->position = $i++; |
|
| 157 | - if ($menu->sousmenu) { |
|
| 158 | - $j = 1; |
|
| 159 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 160 | - $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 161 | - $bouton->position = $j++; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 150 | + // définir les favoris et positions d’origine |
|
| 151 | + if ($boutons_admin) { |
|
| 152 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 153 | + $i = 1; |
|
| 154 | + foreach ($boutons_admin as $key => $menu) { |
|
| 155 | + $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 156 | + $menu->position = $i++; |
|
| 157 | + if ($menu->sousmenu) { |
|
| 158 | + $j = 1; |
|
| 159 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 160 | + $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 161 | + $bouton->position = $j++; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - return $boutons_admin; |
|
| 167 | + return $boutons_admin; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -176,22 +176,22 @@ discard block |
||
| 176 | 176 | * @return Bouton[] |
| 177 | 177 | */ |
| 178 | 178 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 179 | - foreach ($menus as $menu) { |
|
| 180 | - if ($menu->sousmenu) { |
|
| 181 | - $libelles = $isfavoris = $favoris = []; |
|
| 182 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 183 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 184 | - $isfavoris[$key] = (bool)$item->favori; |
|
| 185 | - $favoris[$key] = $item->favori; |
|
| 186 | - } |
|
| 187 | - if ($avec_favoris) { |
|
| 188 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | - } else { |
|
| 190 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - return $menus; |
|
| 179 | + foreach ($menus as $menu) { |
|
| 180 | + if ($menu->sousmenu) { |
|
| 181 | + $libelles = $isfavoris = $favoris = []; |
|
| 182 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 183 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 184 | + $isfavoris[$key] = (bool)$item->favori; |
|
| 185 | + $favoris[$key] = $item->favori; |
|
| 186 | + } |
|
| 187 | + if ($avec_favoris) { |
|
| 188 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | + } else { |
|
| 190 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + return $menus; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return Bouton[] |
| 203 | 203 | */ |
| 204 | 204 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 205 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 205 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -215,23 +215,23 @@ discard block |
||
| 215 | 215 | * @return string |
| 216 | 216 | */ |
| 217 | 217 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 218 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 219 | - $url = generer_url_ecrire($url, $args, true); |
|
| 220 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 221 | - // &truc=@machin@ |
|
| 222 | - // @machin@ etant remplace par _request('machin') |
|
| 223 | - $url = str_replace('&', '&', $url); |
|
| 224 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 225 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 226 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 227 | - } |
|
| 228 | - $val = _request($matches[2], $contexte); |
|
| 229 | - $url = parametre_url($url, $matches[1], $val ? $val : '', '&'); |
|
| 230 | - } |
|
| 231 | - $url = str_replace('&', '&', $url); |
|
| 232 | - } |
|
| 218 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 219 | + $url = generer_url_ecrire($url, $args, true); |
|
| 220 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 221 | + // &truc=@machin@ |
|
| 222 | + // @machin@ etant remplace par _request('machin') |
|
| 223 | + $url = str_replace('&', '&', $url); |
|
| 224 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 225 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 226 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 227 | + } |
|
| 228 | + $val = _request($matches[2], $contexte); |
|
| 229 | + $url = parametre_url($url, $matches[1], $val ? $val : '', '&'); |
|
| 230 | + } |
|
| 231 | + $url = str_replace('&', '&', $url); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - return $url; |
|
| 234 | + return $url; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * Code HTML du bandeau |
| 242 | 242 | */ |
| 243 | 243 | function inc_bandeau_dist() { |
| 244 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 244 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | function obtenir_menus_favoris() { |
| 253 | - if ( |
|
| 254 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 256 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 257 | - ) { |
|
| 258 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 259 | - } |
|
| 260 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 261 | - return $definir_menus_favoris(); |
|
| 253 | + if ( |
|
| 254 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 256 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 257 | + ) { |
|
| 258 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 259 | + } |
|
| 260 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 261 | + return $definir_menus_favoris(); |
|
| 262 | 262 | } |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | // |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | // |
@@ -22,54 +22,54 @@ discard block |
||
| 22 | 22 | // https://code.spip.net/@image_math |
| 23 | 23 | function produire_image_math($tex) { |
| 24 | 24 | |
| 25 | - switch ($GLOBALS['traiter_math']) { |
|
| 26 | - // Attention: mathml desactiv'e pour l'instant |
|
| 27 | - case 'mathml': |
|
| 28 | - $ext = '.xhtml'; |
|
| 29 | - $server = $GLOBALS['mathml_server']; |
|
| 30 | - break; |
|
| 31 | - case 'tex': |
|
| 32 | - $ext = '.png'; |
|
| 33 | - $server = $GLOBALS['tex_server']; |
|
| 34 | - break; |
|
| 35 | - default: |
|
| 36 | - return $tex; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 40 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 42 | - } |
|
| 43 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - if (!@file_exists($fichier)) { |
|
| 47 | - // Aller chercher l'image sur le serveur |
|
| 48 | - if ($server) { |
|
| 49 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 50 | - include_spip('inc/distant'); |
|
| 51 | - recuperer_url($url, ['file' => $fichier]); |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - // Composer la reponse selon presence ou non de l'image |
|
| 57 | - $tex = entites_html($tex); |
|
| 58 | - if (@file_exists($fichier)) { |
|
| 59 | - // MathML |
|
| 60 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 61 | - return implode('', file($fichier)); |
|
| 62 | - } // TeX |
|
| 63 | - else { |
|
| 64 | - list(, , , $size) = @spip_getimagesize($fichier); |
|
| 65 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 66 | - |
|
| 67 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 68 | - } |
|
| 69 | - } else // pas de fichier |
|
| 70 | - { |
|
| 71 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 72 | - } |
|
| 25 | + switch ($GLOBALS['traiter_math']) { |
|
| 26 | + // Attention: mathml desactiv'e pour l'instant |
|
| 27 | + case 'mathml': |
|
| 28 | + $ext = '.xhtml'; |
|
| 29 | + $server = $GLOBALS['mathml_server']; |
|
| 30 | + break; |
|
| 31 | + case 'tex': |
|
| 32 | + $ext = '.png'; |
|
| 33 | + $server = $GLOBALS['tex_server']; |
|
| 34 | + break; |
|
| 35 | + default: |
|
| 36 | + return $tex; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 40 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 42 | + } |
|
| 43 | + $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + if (!@file_exists($fichier)) { |
|
| 47 | + // Aller chercher l'image sur le serveur |
|
| 48 | + if ($server) { |
|
| 49 | + spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 50 | + include_spip('inc/distant'); |
|
| 51 | + recuperer_url($url, ['file' => $fichier]); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + // Composer la reponse selon presence ou non de l'image |
|
| 57 | + $tex = entites_html($tex); |
|
| 58 | + if (@file_exists($fichier)) { |
|
| 59 | + // MathML |
|
| 60 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 61 | + return implode('', file($fichier)); |
|
| 62 | + } // TeX |
|
| 63 | + else { |
|
| 64 | + list(, , , $size) = @spip_getimagesize($fichier); |
|
| 65 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 66 | + |
|
| 67 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 68 | + } |
|
| 69 | + } else // pas de fichier |
|
| 70 | + { |
|
| 71 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -104,52 +104,52 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 106 | 106 | |
| 107 | - $texte_a_voir = $letexte; |
|
| 108 | - while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 109 | - if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 110 | - $fin = strlen($texte_a_voir); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 114 | - $texte_milieu = substr( |
|
| 115 | - $texte_a_voir, |
|
| 116 | - $debut + strlen('<math>'), |
|
| 117 | - $fin - $debut - strlen('<math>') |
|
| 118 | - ); |
|
| 119 | - $texte_fin = substr( |
|
| 120 | - $texte_a_voir, |
|
| 121 | - $fin + strlen('</math>'), |
|
| 122 | - strlen($texte_a_voir) |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 126 | - while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 127 | - $expression = $regs[1]; |
|
| 128 | - if ($defaire_amp) { |
|
| 129 | - $expression = str_replace('&', '&', $expression); |
|
| 130 | - } |
|
| 131 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 132 | - $pos = strpos($texte_milieu, $regs[0]); |
|
| 133 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 134 | - . code_echappement($echap, $source) |
|
| 135 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // Les simples $x^2$ en mode 'span' |
|
| 139 | - while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 140 | - $expression = $regs[1]; |
|
| 141 | - if ($defaire_amp) { |
|
| 142 | - $expression = str_replace('&', '&', $expression); |
|
| 143 | - } |
|
| 144 | - $echap = produire_image_math($expression); |
|
| 145 | - $pos = strpos($texte_milieu, $regs[0]); |
|
| 146 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 147 | - . code_echappement($echap, $source) |
|
| 148 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $texte_a_voir; |
|
| 107 | + $texte_a_voir = $letexte; |
|
| 108 | + while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 109 | + if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 110 | + $fin = strlen($texte_a_voir); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 114 | + $texte_milieu = substr( |
|
| 115 | + $texte_a_voir, |
|
| 116 | + $debut + strlen('<math>'), |
|
| 117 | + $fin - $debut - strlen('<math>') |
|
| 118 | + ); |
|
| 119 | + $texte_fin = substr( |
|
| 120 | + $texte_a_voir, |
|
| 121 | + $fin + strlen('</math>'), |
|
| 122 | + strlen($texte_a_voir) |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 126 | + while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 127 | + $expression = $regs[1]; |
|
| 128 | + if ($defaire_amp) { |
|
| 129 | + $expression = str_replace('&', '&', $expression); |
|
| 130 | + } |
|
| 131 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 132 | + $pos = strpos($texte_milieu, $regs[0]); |
|
| 133 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 134 | + . code_echappement($echap, $source) |
|
| 135 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // Les simples $x^2$ en mode 'span' |
|
| 139 | + while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 140 | + $expression = $regs[1]; |
|
| 141 | + if ($defaire_amp) { |
|
| 142 | + $expression = str_replace('&', '&', $expression); |
|
| 143 | + } |
|
| 144 | + $echap = produire_image_math($expression); |
|
| 145 | + $pos = strpos($texte_milieu, $regs[0]); |
|
| 146 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 147 | + . code_echappement($echap, $source) |
|
| 148 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $texte_a_voir; |
|
| 155 | 155 | } |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ACTIVER_PUCE_RAPIDE')) { |
| 25 | - /** |
|
| 26 | - * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | - * |
|
| 28 | - * Peut ralentir un site sur des listes très longues. |
|
| 29 | - * |
|
| 30 | - * @var bool |
|
| 31 | - **/ |
|
| 32 | - define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 25 | + /** |
|
| 26 | + * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | + * |
|
| 28 | + * Peut ralentir un site sur des listes très longues. |
|
| 29 | + * |
|
| 30 | + * @var bool |
|
| 31 | + **/ |
|
| 32 | + define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -57,31 +57,31 @@ discard block |
||
| 57 | 57 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 58 | 58 | */ |
| 59 | 59 | function inc_puce_statut_dist( |
| 60 | - $id_objet, |
|
| 61 | - $statut, |
|
| 62 | - $id_parent, |
|
| 63 | - $type, |
|
| 64 | - $ajax = false, |
|
| 65 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 60 | + $id_objet, |
|
| 61 | + $statut, |
|
| 62 | + $id_parent, |
|
| 63 | + $type, |
|
| 64 | + $ajax = false, |
|
| 65 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 66 | 66 | ) { |
| 67 | - static $f_puce_statut = []; |
|
| 68 | - $type = objet_type($type); |
|
| 69 | - // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | - if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | - $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | - } |
|
| 73 | - if ($f_puce_statut[$type]) { |
|
| 74 | - return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | - // composer une puce, avec si possible changement rapide |
|
| 79 | - elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | - return $puce; |
|
| 81 | - } // sinon fausse puce avec le type de l'image |
|
| 82 | - else { |
|
| 83 | - return http_img_pack("$type-16.png", ''); |
|
| 84 | - } |
|
| 67 | + static $f_puce_statut = []; |
|
| 68 | + $type = objet_type($type); |
|
| 69 | + // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | + if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | + $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | + } |
|
| 73 | + if ($f_puce_statut[$type]) { |
|
| 74 | + return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | + // composer une puce, avec si possible changement rapide |
|
| 79 | + elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | + return $puce; |
|
| 81 | + } // sinon fausse puce avec le type de l'image |
|
| 82 | + else { |
|
| 83 | + return http_img_pack("$type-16.png", ''); |
|
| 84 | + } |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -110,41 +110,41 @@ discard block |
||
| 110 | 110 | * null si pas capable de déterminer l'image |
| 111 | 111 | */ |
| 112 | 112 | function statut_image($objet, $statut) { |
| 113 | - $src = null; |
|
| 114 | - $table = table_objet_sql($objet); |
|
| 115 | - $desc = lister_tables_objets_sql($table); |
|
| 116 | - if (isset($desc['statut_images'])) { |
|
| 117 | - // si une declaration statut_images |
|
| 118 | - // mais rien pour le statut demande, ne rien afficher |
|
| 119 | - $src = ''; |
|
| 120 | - if (isset($desc['statut_images'][$statut])) { |
|
| 121 | - $src = $desc['statut_images'][$statut]; |
|
| 122 | - } // sinon image par defaut ? |
|
| 123 | - elseif (isset($desc['statut_images'][0])) { |
|
| 124 | - $src = $desc['statut_images'][0]; |
|
| 125 | - } |
|
| 126 | - } else { |
|
| 127 | - switch ($statut) { |
|
| 128 | - case 'prepa': |
|
| 129 | - $src = 'puce-preparer-xx.svg?12px'; |
|
| 130 | - break; |
|
| 131 | - case 'prop': |
|
| 132 | - $src = 'puce-proposer-xx.svg?12px'; |
|
| 133 | - break; |
|
| 134 | - case 'publie': |
|
| 135 | - $src = 'puce-publier-xx.svg?12px'; |
|
| 136 | - break; |
|
| 137 | - case 'refuse': |
|
| 138 | - $src = 'puce-refuser-xx.svg?12px'; |
|
| 139 | - break; |
|
| 140 | - case 'poubelle': |
|
| 141 | - case 'poub': |
|
| 142 | - $src = 'puce-supprimer-xx.svg?12px'; |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return $src; |
|
| 113 | + $src = null; |
|
| 114 | + $table = table_objet_sql($objet); |
|
| 115 | + $desc = lister_tables_objets_sql($table); |
|
| 116 | + if (isset($desc['statut_images'])) { |
|
| 117 | + // si une declaration statut_images |
|
| 118 | + // mais rien pour le statut demande, ne rien afficher |
|
| 119 | + $src = ''; |
|
| 120 | + if (isset($desc['statut_images'][$statut])) { |
|
| 121 | + $src = $desc['statut_images'][$statut]; |
|
| 122 | + } // sinon image par defaut ? |
|
| 123 | + elseif (isset($desc['statut_images'][0])) { |
|
| 124 | + $src = $desc['statut_images'][0]; |
|
| 125 | + } |
|
| 126 | + } else { |
|
| 127 | + switch ($statut) { |
|
| 128 | + case 'prepa': |
|
| 129 | + $src = 'puce-preparer-xx.svg?12px'; |
|
| 130 | + break; |
|
| 131 | + case 'prop': |
|
| 132 | + $src = 'puce-proposer-xx.svg?12px'; |
|
| 133 | + break; |
|
| 134 | + case 'publie': |
|
| 135 | + $src = 'puce-publier-xx.svg?12px'; |
|
| 136 | + break; |
|
| 137 | + case 'refuse': |
|
| 138 | + $src = 'puce-refuser-xx.svg?12px'; |
|
| 139 | + break; |
|
| 140 | + case 'poubelle': |
|
| 141 | + case 'poub': |
|
| 142 | + $src = 'puce-supprimer-xx.svg?12px'; |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return $src; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -172,40 +172,40 @@ discard block |
||
| 172 | 172 | * @return string |
| 173 | 173 | */ |
| 174 | 174 | function statut_titre($objet, $statut) { |
| 175 | - $titre = ''; |
|
| 176 | - $table = table_objet_sql($objet); |
|
| 177 | - $desc = lister_tables_objets_sql($table); |
|
| 178 | - if (isset($desc['statut_titres'])) { |
|
| 179 | - // si une declaration statut_titres |
|
| 180 | - // mais rien pour le statut demande, ne rien afficher |
|
| 181 | - if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | - $titre = $desc['statut_titres'][$statut]; |
|
| 183 | - } // sinon image par defaut ? |
|
| 184 | - elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | - $titre = $desc['statut_titres'][0]; |
|
| 186 | - } |
|
| 187 | - } else { |
|
| 188 | - switch ($statut) { |
|
| 189 | - case 'prepa': |
|
| 190 | - $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | - break; |
|
| 192 | - case 'prop': |
|
| 193 | - $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | - break; |
|
| 195 | - case 'publie': |
|
| 196 | - $titre = 'texte_statut_publie'; |
|
| 197 | - break; |
|
| 198 | - case 'refuse': |
|
| 199 | - $titre = 'texte_statut_refuse'; |
|
| 200 | - break; |
|
| 201 | - case 'poubelle': |
|
| 202 | - case 'poub': |
|
| 203 | - $titre = 'texte_statut_poubelle'; |
|
| 204 | - break; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $titre ? _T($titre) : ''; |
|
| 175 | + $titre = ''; |
|
| 176 | + $table = table_objet_sql($objet); |
|
| 177 | + $desc = lister_tables_objets_sql($table); |
|
| 178 | + if (isset($desc['statut_titres'])) { |
|
| 179 | + // si une declaration statut_titres |
|
| 180 | + // mais rien pour le statut demande, ne rien afficher |
|
| 181 | + if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | + $titre = $desc['statut_titres'][$statut]; |
|
| 183 | + } // sinon image par defaut ? |
|
| 184 | + elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | + $titre = $desc['statut_titres'][0]; |
|
| 186 | + } |
|
| 187 | + } else { |
|
| 188 | + switch ($statut) { |
|
| 189 | + case 'prepa': |
|
| 190 | + $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | + break; |
|
| 192 | + case 'prop': |
|
| 193 | + $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | + break; |
|
| 195 | + case 'publie': |
|
| 196 | + $titre = 'texte_statut_publie'; |
|
| 197 | + break; |
|
| 198 | + case 'refuse': |
|
| 199 | + $titre = 'texte_statut_refuse'; |
|
| 200 | + break; |
|
| 201 | + case 'poubelle': |
|
| 202 | + case 'poub': |
|
| 203 | + $titre = 'texte_statut_poubelle'; |
|
| 204 | + break; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $titre ? _T($titre) : ''; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -225,37 +225,37 @@ discard block |
||
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | 227 | function statut_texte_instituer($objet, $statut) { |
| 228 | - $texte = ''; |
|
| 229 | - $table = table_objet_sql($objet); |
|
| 230 | - $desc = lister_tables_objets_sql($table); |
|
| 231 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | - // si une declaration statut_titres |
|
| 233 | - // mais rien pour le statut demande, ne rien afficher |
|
| 234 | - if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | - $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | - } |
|
| 237 | - } else { |
|
| 238 | - switch ($statut) { |
|
| 239 | - case 'prepa': |
|
| 240 | - $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | - break; |
|
| 242 | - case 'prop': |
|
| 243 | - $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | - break; |
|
| 245 | - case 'publie': |
|
| 246 | - $texte = 'texte_statut_publie'; |
|
| 247 | - break; |
|
| 248 | - case 'refuse': |
|
| 249 | - $texte = 'texte_statut_refuse'; |
|
| 250 | - break; |
|
| 251 | - case 'poubelle': |
|
| 252 | - case 'poub': |
|
| 253 | - $texte = 'texte_statut_poubelle'; |
|
| 254 | - break; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $texte ? _T($texte) : ''; |
|
| 228 | + $texte = ''; |
|
| 229 | + $table = table_objet_sql($objet); |
|
| 230 | + $desc = lister_tables_objets_sql($table); |
|
| 231 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | + // si une declaration statut_titres |
|
| 233 | + // mais rien pour le statut demande, ne rien afficher |
|
| 234 | + if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | + $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | + } |
|
| 237 | + } else { |
|
| 238 | + switch ($statut) { |
|
| 239 | + case 'prepa': |
|
| 240 | + $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | + break; |
|
| 242 | + case 'prop': |
|
| 243 | + $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | + break; |
|
| 245 | + case 'publie': |
|
| 246 | + $texte = 'texte_statut_publie'; |
|
| 247 | + break; |
|
| 248 | + case 'refuse': |
|
| 249 | + $texte = 'texte_statut_refuse'; |
|
| 250 | + break; |
|
| 251 | + case 'poubelle': |
|
| 252 | + case 'poub': |
|
| 253 | + $texte = 'texte_statut_poubelle'; |
|
| 254 | + break; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $texte ? _T($texte) : ''; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -275,16 +275,16 @@ discard block |
||
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | 277 | function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 278 | - $img = statut_image('auteur', $statut); |
|
| 279 | - if (!$img) { |
|
| 280 | - return ''; |
|
| 281 | - } |
|
| 282 | - $alt = statut_titre('auteur', $statut); |
|
| 278 | + $img = statut_image('auteur', $statut); |
|
| 279 | + if (!$img) { |
|
| 280 | + return ''; |
|
| 281 | + } |
|
| 282 | + $alt = statut_titre('auteur', $statut); |
|
| 283 | 283 | |
| 284 | - $fond = ''; |
|
| 285 | - $titre = ''; |
|
| 284 | + $fond = ''; |
|
| 285 | + $titre = ''; |
|
| 286 | 286 | |
| 287 | - /* |
|
| 287 | + /* |
|
| 288 | 288 | if ($type != 'auteur') { |
| 289 | 289 | $img2 = chemin_image('del-16.png'); |
| 290 | 290 | $titre = _T('titre_image_redacteur'); |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | } |
| 295 | 295 | */ |
| 296 | 296 | |
| 297 | - return http_img_pack($img, $alt, $fond, $alt); |
|
| 297 | + return http_img_pack($img, $alt, $fond, $alt); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
| 301 | 301 | function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 302 | - return http_img_pack('rubrique-16.png', ''); |
|
| 302 | + return http_img_pack('rubrique-16.png', ''); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -323,110 +323,110 @@ discard block |
||
| 323 | 323 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 324 | 324 | **/ |
| 325 | 325 | function puce_statut_changement_rapide( |
| 326 | - $id, |
|
| 327 | - $statut, |
|
| 328 | - $id_rubrique, |
|
| 329 | - $type = 'article', |
|
| 330 | - $ajax = false, |
|
| 331 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 326 | + $id, |
|
| 327 | + $statut, |
|
| 328 | + $id_rubrique, |
|
| 329 | + $type = 'article', |
|
| 330 | + $ajax = false, |
|
| 331 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 332 | 332 | ) { |
| 333 | - $src = statut_image($type, $statut); |
|
| 334 | - if (!$src) { |
|
| 335 | - return $src; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if ( |
|
| 339 | - !$id |
|
| 340 | - or !_SPIP_AJAX |
|
| 341 | - or !$menu_rapide |
|
| 342 | - ) { |
|
| 343 | - $ajax_node = ''; |
|
| 344 | - } else { |
|
| 345 | - $ajax_node = " class='imgstatut$type$id'"; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - $t = statut_titre($type, $statut); |
|
| 350 | - $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 351 | - |
|
| 352 | - if (!$ajax_node) { |
|
| 353 | - return $inser_puce; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $table = table_objet_sql($type); |
|
| 357 | - $desc = lister_tables_objets_sql($table); |
|
| 358 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 359 | - return $inser_puce; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if (!function_exists('autoriser')) { |
|
| 363 | - include_spip('inc/autoriser'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 367 | - if ($id_rubrique) { |
|
| 368 | - if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 369 | - return $inser_puce; |
|
| 370 | - } |
|
| 371 | - } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 372 | - else { |
|
| 373 | - if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 374 | - return $inser_puce; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 379 | - if (!isset($coord[$statut])) { |
|
| 380 | - return $inser_puce; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 384 | - ; |
|
| 385 | - $margin = 0; /* marge a gauche + droite */ |
|
| 386 | - $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 387 | - ; |
|
| 388 | - $clip = $zero + ($unit * $coord[$statut]); |
|
| 389 | - |
|
| 390 | - if ($ajax) { |
|
| 391 | - $width = $unit * count($desc['statut_textes_instituer']) + $margin; |
|
| 392 | - $out = "<span class='puce_objet_fixe $type'>" |
|
| 393 | - . $inser_puce |
|
| 394 | - . '</span>' |
|
| 395 | - . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 396 | - $i = 0; |
|
| 397 | - foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 398 | - $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 399 | - } |
|
| 400 | - $out .= '</span>'; |
|
| 401 | - |
|
| 402 | - return $out; |
|
| 403 | - } else { |
|
| 404 | - $nom = 'puce_statut_'; |
|
| 405 | - $action = generer_url_ecrire('puce_statut', '', true); |
|
| 406 | - $lang_dir = lang_dir(lang_typo()); |
|
| 407 | - |
|
| 408 | - return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 409 | - . $inser_puce |
|
| 410 | - . '</span>'; |
|
| 411 | - } |
|
| 333 | + $src = statut_image($type, $statut); |
|
| 334 | + if (!$src) { |
|
| 335 | + return $src; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if ( |
|
| 339 | + !$id |
|
| 340 | + or !_SPIP_AJAX |
|
| 341 | + or !$menu_rapide |
|
| 342 | + ) { |
|
| 343 | + $ajax_node = ''; |
|
| 344 | + } else { |
|
| 345 | + $ajax_node = " class='imgstatut$type$id'"; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + $t = statut_titre($type, $statut); |
|
| 350 | + $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 351 | + |
|
| 352 | + if (!$ajax_node) { |
|
| 353 | + return $inser_puce; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $table = table_objet_sql($type); |
|
| 357 | + $desc = lister_tables_objets_sql($table); |
|
| 358 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 359 | + return $inser_puce; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if (!function_exists('autoriser')) { |
|
| 363 | + include_spip('inc/autoriser'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 367 | + if ($id_rubrique) { |
|
| 368 | + if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 369 | + return $inser_puce; |
|
| 370 | + } |
|
| 371 | + } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 372 | + else { |
|
| 373 | + if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 374 | + return $inser_puce; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 379 | + if (!isset($coord[$statut])) { |
|
| 380 | + return $inser_puce; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 384 | + ; |
|
| 385 | + $margin = 0; /* marge a gauche + droite */ |
|
| 386 | + $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 387 | + ; |
|
| 388 | + $clip = $zero + ($unit * $coord[$statut]); |
|
| 389 | + |
|
| 390 | + if ($ajax) { |
|
| 391 | + $width = $unit * count($desc['statut_textes_instituer']) + $margin; |
|
| 392 | + $out = "<span class='puce_objet_fixe $type'>" |
|
| 393 | + . $inser_puce |
|
| 394 | + . '</span>' |
|
| 395 | + . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 396 | + $i = 0; |
|
| 397 | + foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 398 | + $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 399 | + } |
|
| 400 | + $out .= '</span>'; |
|
| 401 | + |
|
| 402 | + return $out; |
|
| 403 | + } else { |
|
| 404 | + $nom = 'puce_statut_'; |
|
| 405 | + $action = generer_url_ecrire('puce_statut', '', true); |
|
| 406 | + $lang_dir = lang_dir(lang_typo()); |
|
| 407 | + |
|
| 408 | + return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 409 | + . $inser_puce |
|
| 410 | + . '</span>'; |
|
| 411 | + } |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
| 415 | 415 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 416 | - $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 417 | - $t = supprimer_tags($titre); |
|
| 416 | + $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 417 | + $t = supprimer_tags($titre); |
|
| 418 | 418 | |
| 419 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 419 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // compat |
| 423 | 423 | // La couleur du statut |
| 424 | 424 | |
| 425 | 425 | function puce_statut($statut, $atts = '') { |
| 426 | - $src = statut_image('article', $statut); |
|
| 427 | - if (!$src) { |
|
| 428 | - return ''; |
|
| 429 | - } |
|
| 426 | + $src = statut_image('article', $statut); |
|
| 427 | + if (!$src) { |
|
| 428 | + return ''; |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 431 | + return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 432 | 432 | } |
@@ -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 | |
@@ -54,64 +54,64 @@ discard block |
||
| 54 | 54 | * true si le statut change effectivement |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $infos = [], $postdate = false) { |
| 57 | - $neuf = false; |
|
| 58 | - |
|
| 59 | - // Compat avec l'ancienne signature |
|
| 60 | - if (is_string($infos)) { |
|
| 61 | - $infos = ['statut_ancien' => $infos]; |
|
| 62 | - } |
|
| 63 | - if (!isset($infos['statut_ancien'])) { |
|
| 64 | - $infos['statut_ancien'] = ''; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // On recherche quels statuts tester |
|
| 68 | - if ( |
|
| 69 | - isset($infos['objet']) |
|
| 70 | - and include_spip('inc/filtres') |
|
| 71 | - and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 72 | - and is_array($declaration_statut) |
|
| 73 | - ) { |
|
| 74 | - foreach ($declaration_statut as $champ_statut) { |
|
| 75 | - if ($champ_statut['champ'] == 'statut') { |
|
| 76 | - $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 77 | - break; // stop on a trouvé le bon champ |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - else { |
|
| 82 | - $statuts_publies = ['publie']; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | - if ( |
|
| 87 | - isset($modifs['statut']) |
|
| 88 | - or isset($modifs['id_rubrique']) |
|
| 89 | - or ($postdate and strtotime($postdate) > time()) |
|
| 90 | - ) { |
|
| 91 | - $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | - } |
|
| 93 | - // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | - if ($postdate) { |
|
| 95 | - calculer_prochain_postdate(true); |
|
| 96 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | - } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | - $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | - } |
|
| 100 | - } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | - if ($postdate) { |
|
| 102 | - calculer_prochain_postdate(true); |
|
| 103 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | - } else { |
|
| 105 | - $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($neuf) { // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 110 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $langues = calculer_langues_utilisees(); |
|
| 114 | - ecrire_meta('langues_utilisees', $langues); |
|
| 57 | + $neuf = false; |
|
| 58 | + |
|
| 59 | + // Compat avec l'ancienne signature |
|
| 60 | + if (is_string($infos)) { |
|
| 61 | + $infos = ['statut_ancien' => $infos]; |
|
| 62 | + } |
|
| 63 | + if (!isset($infos['statut_ancien'])) { |
|
| 64 | + $infos['statut_ancien'] = ''; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // On recherche quels statuts tester |
|
| 68 | + if ( |
|
| 69 | + isset($infos['objet']) |
|
| 70 | + and include_spip('inc/filtres') |
|
| 71 | + and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 72 | + and is_array($declaration_statut) |
|
| 73 | + ) { |
|
| 74 | + foreach ($declaration_statut as $champ_statut) { |
|
| 75 | + if ($champ_statut['champ'] == 'statut') { |
|
| 76 | + $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 77 | + break; // stop on a trouvé le bon champ |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + else { |
|
| 82 | + $statuts_publies = ['publie']; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | + if ( |
|
| 87 | + isset($modifs['statut']) |
|
| 88 | + or isset($modifs['id_rubrique']) |
|
| 89 | + or ($postdate and strtotime($postdate) > time()) |
|
| 90 | + ) { |
|
| 91 | + $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | + } |
|
| 93 | + // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | + if ($postdate) { |
|
| 95 | + calculer_prochain_postdate(true); |
|
| 96 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | + } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | + $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | + } |
|
| 100 | + } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | + if ($postdate) { |
|
| 102 | + calculer_prochain_postdate(true); |
|
| 103 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | + } else { |
|
| 105 | + $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($neuf) { // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 110 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $langues = calculer_langues_utilisees(); |
|
| 114 | + ecrire_meta('langues_utilisees', $langues); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -129,22 +129,22 @@ discard block |
||
| 129 | 129 | * true si le statut change effectivement |
| 130 | 130 | */ |
| 131 | 131 | function publier_branche_rubrique($id_rubrique) { |
| 132 | - $id_pred = $id_rubrique; |
|
| 133 | - while (true) { |
|
| 134 | - sql_updateq( |
|
| 135 | - 'spip_rubriques', |
|
| 136 | - ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 137 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 138 | - ); |
|
| 139 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 140 | - if (!$id_parent) { |
|
| 141 | - break; |
|
| 142 | - } |
|
| 143 | - $id_rubrique = $id_parent; |
|
| 144 | - } |
|
| 132 | + $id_pred = $id_rubrique; |
|
| 133 | + while (true) { |
|
| 134 | + sql_updateq( |
|
| 135 | + 'spip_rubriques', |
|
| 136 | + ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 137 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 138 | + ); |
|
| 139 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 140 | + if (!$id_parent) { |
|
| 141 | + break; |
|
| 142 | + } |
|
| 143 | + $id_rubrique = $id_parent; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | 146 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 147 | - return $id_pred != $id_rubrique; |
|
| 147 | + return $id_pred != $id_rubrique; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -162,20 +162,20 @@ discard block |
||
| 162 | 162 | * true si le statut change effectivement |
| 163 | 163 | */ |
| 164 | 164 | function depublier_branche_rubrique_if($id_rubrique) { |
| 165 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 166 | - |
|
| 167 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 168 | - $id_pred = $id_rubrique; |
|
| 169 | - while ($id_pred) { |
|
| 170 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 171 | - return $id_pred != $id_rubrique; |
|
| 172 | - } |
|
| 173 | - // passer au parent si on a depublie |
|
| 174 | - $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 175 | - $id_pred = $r['id_parent']; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $id_pred != $id_rubrique; |
|
| 165 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 166 | + |
|
| 167 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 168 | + $id_pred = $id_rubrique; |
|
| 169 | + while ($id_pred) { |
|
| 170 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 171 | + return $id_pred != $id_rubrique; |
|
| 172 | + } |
|
| 173 | + // passer au parent si on a depublie |
|
| 174 | + $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 175 | + $id_pred = $r['id_parent']; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $id_pred != $id_rubrique; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -192,61 +192,61 @@ discard block |
||
| 192 | 192 | * true si la rubrique a été dépubliée |
| 193 | 193 | */ |
| 194 | 194 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 195 | - if (is_null($date)) { |
|
| 196 | - $date = date('Y-m-d H:i:s'); |
|
| 197 | - } |
|
| 198 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 199 | - ' AND date <= ' . sql_quote($date) : ''; |
|
| 200 | - |
|
| 201 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // verifier qu'elle existe et est bien publiee |
|
| 206 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 207 | - if (!$r or $r['statut'] !== 'publie') { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 212 | - // Le type de l'objet est au pluriel |
|
| 213 | - $compte = [ |
|
| 214 | - 'articles' => sql_countsel( |
|
| 215 | - 'spip_articles', |
|
| 216 | - 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 217 | - ), |
|
| 218 | - 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 219 | - 'documents' => sql_countsel( |
|
| 220 | - 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 221 | - 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 222 | - ) |
|
| 223 | - ]; |
|
| 224 | - |
|
| 225 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 226 | - $compte = pipeline( |
|
| 227 | - 'objet_compte_enfants', |
|
| 228 | - [ |
|
| 229 | - 'args' => [ |
|
| 230 | - 'objet' => 'rubrique', |
|
| 231 | - 'id_objet' => $id_rubrique, |
|
| 232 | - 'statut' => 'publie', |
|
| 233 | - 'date' => $date |
|
| 234 | - ], |
|
| 235 | - 'data' => $compte |
|
| 236 | - ] |
|
| 237 | - ); |
|
| 238 | - |
|
| 239 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 240 | - foreach ($compte as $objet => $n) { |
|
| 241 | - if ($n) { |
|
| 242 | - return false; |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 195 | + if (is_null($date)) { |
|
| 196 | + $date = date('Y-m-d H:i:s'); |
|
| 197 | + } |
|
| 198 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 199 | + ' AND date <= ' . sql_quote($date) : ''; |
|
| 200 | + |
|
| 201 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // verifier qu'elle existe et est bien publiee |
|
| 206 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 207 | + if (!$r or $r['statut'] !== 'publie') { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 212 | + // Le type de l'objet est au pluriel |
|
| 213 | + $compte = [ |
|
| 214 | + 'articles' => sql_countsel( |
|
| 215 | + 'spip_articles', |
|
| 216 | + 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 217 | + ), |
|
| 218 | + 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 219 | + 'documents' => sql_countsel( |
|
| 220 | + 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 221 | + 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 222 | + ) |
|
| 223 | + ]; |
|
| 224 | + |
|
| 225 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 226 | + $compte = pipeline( |
|
| 227 | + 'objet_compte_enfants', |
|
| 228 | + [ |
|
| 229 | + 'args' => [ |
|
| 230 | + 'objet' => 'rubrique', |
|
| 231 | + 'id_objet' => $id_rubrique, |
|
| 232 | + 'statut' => 'publie', |
|
| 233 | + 'date' => $date |
|
| 234 | + ], |
|
| 235 | + 'data' => $compte |
|
| 236 | + ] |
|
| 237 | + ); |
|
| 238 | + |
|
| 239 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 240 | + foreach ($compte as $objet => $n) { |
|
| 241 | + if ($n) { |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 247 | 247 | |
| 248 | 248 | # spip_log("depublier_rubrique $id_pred"); |
| 249 | - return true; |
|
| 249 | + return true; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -269,18 +269,18 @@ discard block |
||
| 269 | 269 | **/ |
| 270 | 270 | function calculer_rubriques() { |
| 271 | 271 | |
| 272 | - calculer_rubriques_publiees(); |
|
| 272 | + calculer_rubriques_publiees(); |
|
| 273 | 273 | |
| 274 | - // Apres chaque (de)publication |
|
| 275 | - // recalculer les langues utilisees sur le site |
|
| 276 | - $langues = calculer_langues_utilisees(); |
|
| 277 | - ecrire_meta('langues_utilisees', $langues); |
|
| 274 | + // Apres chaque (de)publication |
|
| 275 | + // recalculer les langues utilisees sur le site |
|
| 276 | + $langues = calculer_langues_utilisees(); |
|
| 277 | + ecrire_meta('langues_utilisees', $langues); |
|
| 278 | 278 | |
| 279 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 280 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 279 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 280 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 281 | 281 | |
| 282 | - // on calcule la date du prochain article post-date |
|
| 283 | - calculer_prochain_postdate(); |
|
| 282 | + // on calcule la date du prochain article post-date |
|
| 283 | + calculer_prochain_postdate(); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -297,61 +297,61 @@ discard block |
||
| 297 | 297 | **/ |
| 298 | 298 | function calculer_rubriques_publiees() { |
| 299 | 299 | |
| 300 | - // Mettre les compteurs a zero |
|
| 301 | - sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 302 | - |
|
| 303 | - // |
|
| 304 | - // Publier et dater les rubriques qui ont un article publie |
|
| 305 | - // |
|
| 306 | - |
|
| 307 | - // Afficher les articles post-dates ? |
|
| 308 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 309 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 310 | - |
|
| 311 | - $r = sql_select( |
|
| 312 | - 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 313 | - 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 314 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 315 | - 'R.id_rubrique' |
|
| 316 | - ); |
|
| 317 | - while ($row = sql_fetch($r)) { |
|
| 318 | - sql_updateq( |
|
| 319 | - 'spip_rubriques', |
|
| 320 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 321 | - 'id_rubrique=' . intval($row['id']) |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 326 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 327 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 328 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 329 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 330 | - pipeline('calculer_rubriques', null); |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 334 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 335 | - do { |
|
| 336 | - $continuer = false; |
|
| 337 | - $r = sql_select( |
|
| 338 | - 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 339 | - 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 340 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 341 | - 'R.id_rubrique' |
|
| 342 | - ); |
|
| 343 | - while ($row = sql_fetch($r)) { |
|
| 344 | - sql_updateq( |
|
| 345 | - 'spip_rubriques', |
|
| 346 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 347 | - 'id_rubrique=' . intval($row['id']) |
|
| 348 | - ); |
|
| 349 | - $continuer = true; |
|
| 350 | - } |
|
| 351 | - } while ($continuer); |
|
| 352 | - |
|
| 353 | - // Enregistrement des modifs |
|
| 354 | - sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 300 | + // Mettre les compteurs a zero |
|
| 301 | + sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 302 | + |
|
| 303 | + // |
|
| 304 | + // Publier et dater les rubriques qui ont un article publie |
|
| 305 | + // |
|
| 306 | + |
|
| 307 | + // Afficher les articles post-dates ? |
|
| 308 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 309 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 310 | + |
|
| 311 | + $r = sql_select( |
|
| 312 | + 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 313 | + 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 314 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 315 | + 'R.id_rubrique' |
|
| 316 | + ); |
|
| 317 | + while ($row = sql_fetch($r)) { |
|
| 318 | + sql_updateq( |
|
| 319 | + 'spip_rubriques', |
|
| 320 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 321 | + 'id_rubrique=' . intval($row['id']) |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 326 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 327 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 328 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 329 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 330 | + pipeline('calculer_rubriques', null); |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 334 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 335 | + do { |
|
| 336 | + $continuer = false; |
|
| 337 | + $r = sql_select( |
|
| 338 | + 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 339 | + 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 340 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 341 | + 'R.id_rubrique' |
|
| 342 | + ); |
|
| 343 | + while ($row = sql_fetch($r)) { |
|
| 344 | + sql_updateq( |
|
| 345 | + 'spip_rubriques', |
|
| 346 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 347 | + 'id_rubrique=' . intval($row['id']) |
|
| 348 | + ); |
|
| 349 | + $continuer = true; |
|
| 350 | + } |
|
| 351 | + } while ($continuer); |
|
| 352 | + |
|
| 353 | + // Enregistrement des modifs |
|
| 354 | + sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -366,123 +366,123 @@ discard block |
||
| 366 | 366 | * @return void |
| 367 | 367 | **/ |
| 368 | 368 | function propager_les_secteurs() { |
| 369 | - // Profondeur 0 |
|
| 370 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 371 | - // et fixer les id_secteur des rubriques racines |
|
| 372 | - sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 373 | - // Toute rubrique non racine est de profondeur >0 |
|
| 374 | - sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 375 | - |
|
| 376 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 377 | - $maxiter = sql_countsel('spip_rubriques'); |
|
| 378 | - |
|
| 379 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 380 | - // on fait profondeur par profondeur |
|
| 381 | - |
|
| 382 | - $prof = 0; |
|
| 383 | - do { |
|
| 384 | - $continuer = false; |
|
| 385 | - |
|
| 386 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 387 | - // on fixe le profondeur $prof+1 |
|
| 388 | - |
|
| 389 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 390 | - // on teste A.profondeur > $prof+1 car : |
|
| 391 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 392 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 393 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 394 | - $maxiter2 = $maxiter; |
|
| 395 | - while ( |
|
| 396 | - $maxiter2-- |
|
| 397 | - and $rows = sql_allfetsel( |
|
| 398 | - 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 399 | - 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 400 | - 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 401 | - '', |
|
| 402 | - 'R.id_secteur', |
|
| 403 | - '0,100' |
|
| 404 | - ) |
|
| 405 | - ) { |
|
| 406 | - $id_secteur = null; |
|
| 407 | - $ids = []; |
|
| 408 | - while ($row = array_shift($rows)) { |
|
| 409 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 410 | - if (count($ids)) { |
|
| 411 | - sql_updateq( |
|
| 412 | - 'spip_rubriques', |
|
| 413 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 414 | - sql_in('id_rubrique', $ids) |
|
| 415 | - ); |
|
| 416 | - } |
|
| 417 | - $id_secteur = $row['id_secteur']; |
|
| 418 | - $ids = []; |
|
| 419 | - } |
|
| 420 | - $ids[] = $row['id']; |
|
| 421 | - } |
|
| 422 | - if (count($ids)) { |
|
| 423 | - sql_updateq( |
|
| 424 | - 'spip_rubriques', |
|
| 425 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 426 | - sql_in('id_rubrique', $ids) |
|
| 427 | - ); |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 433 | - $maxiter2 = $maxiter; |
|
| 434 | - while ( |
|
| 435 | - $maxiter2-- |
|
| 436 | - and $rows = sql_allfetsel( |
|
| 437 | - 'id_rubrique as id', |
|
| 438 | - 'spip_rubriques', |
|
| 439 | - 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 440 | - 'zzz.id_rubrique', |
|
| 441 | - 'spip_rubriques AS zzz', |
|
| 442 | - 'zzz.profondeur=' . intval($prof) |
|
| 443 | - ) . ')', |
|
| 444 | - '', |
|
| 445 | - '', |
|
| 446 | - '0,100' |
|
| 447 | - ) |
|
| 448 | - ) { |
|
| 449 | - $rows = array_column($rows, 'id'); |
|
| 450 | - sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 454 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 455 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 456 | - // on arrete les frais |
|
| 457 | - if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 458 | - $prof++; |
|
| 459 | - $continuer = true; |
|
| 460 | - } |
|
| 461 | - } while ($continuer and $maxiter--); |
|
| 462 | - |
|
| 463 | - // loger si la table des rubriques semble foireuse |
|
| 464 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 465 | - if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 466 | - spip_log( |
|
| 467 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 468 | - _LOG_CRITIQUE |
|
| 469 | - ); |
|
| 470 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // reparer les articles |
|
| 474 | - $r = sql_select( |
|
| 475 | - 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 476 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 477 | - 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 478 | - ); |
|
| 479 | - |
|
| 480 | - while ($row = sql_fetch($r)) { |
|
| 481 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 485 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 369 | + // Profondeur 0 |
|
| 370 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 371 | + // et fixer les id_secteur des rubriques racines |
|
| 372 | + sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 373 | + // Toute rubrique non racine est de profondeur >0 |
|
| 374 | + sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 375 | + |
|
| 376 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 377 | + $maxiter = sql_countsel('spip_rubriques'); |
|
| 378 | + |
|
| 379 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 380 | + // on fait profondeur par profondeur |
|
| 381 | + |
|
| 382 | + $prof = 0; |
|
| 383 | + do { |
|
| 384 | + $continuer = false; |
|
| 385 | + |
|
| 386 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 387 | + // on fixe le profondeur $prof+1 |
|
| 388 | + |
|
| 389 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 390 | + // on teste A.profondeur > $prof+1 car : |
|
| 391 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 392 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 393 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 394 | + $maxiter2 = $maxiter; |
|
| 395 | + while ( |
|
| 396 | + $maxiter2-- |
|
| 397 | + and $rows = sql_allfetsel( |
|
| 398 | + 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 399 | + 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 400 | + 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 401 | + '', |
|
| 402 | + 'R.id_secteur', |
|
| 403 | + '0,100' |
|
| 404 | + ) |
|
| 405 | + ) { |
|
| 406 | + $id_secteur = null; |
|
| 407 | + $ids = []; |
|
| 408 | + while ($row = array_shift($rows)) { |
|
| 409 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 410 | + if (count($ids)) { |
|
| 411 | + sql_updateq( |
|
| 412 | + 'spip_rubriques', |
|
| 413 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 414 | + sql_in('id_rubrique', $ids) |
|
| 415 | + ); |
|
| 416 | + } |
|
| 417 | + $id_secteur = $row['id_secteur']; |
|
| 418 | + $ids = []; |
|
| 419 | + } |
|
| 420 | + $ids[] = $row['id']; |
|
| 421 | + } |
|
| 422 | + if (count($ids)) { |
|
| 423 | + sql_updateq( |
|
| 424 | + 'spip_rubriques', |
|
| 425 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 426 | + sql_in('id_rubrique', $ids) |
|
| 427 | + ); |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 433 | + $maxiter2 = $maxiter; |
|
| 434 | + while ( |
|
| 435 | + $maxiter2-- |
|
| 436 | + and $rows = sql_allfetsel( |
|
| 437 | + 'id_rubrique as id', |
|
| 438 | + 'spip_rubriques', |
|
| 439 | + 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 440 | + 'zzz.id_rubrique', |
|
| 441 | + 'spip_rubriques AS zzz', |
|
| 442 | + 'zzz.profondeur=' . intval($prof) |
|
| 443 | + ) . ')', |
|
| 444 | + '', |
|
| 445 | + '', |
|
| 446 | + '0,100' |
|
| 447 | + ) |
|
| 448 | + ) { |
|
| 449 | + $rows = array_column($rows, 'id'); |
|
| 450 | + sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 454 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 455 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 456 | + // on arrete les frais |
|
| 457 | + if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 458 | + $prof++; |
|
| 459 | + $continuer = true; |
|
| 460 | + } |
|
| 461 | + } while ($continuer and $maxiter--); |
|
| 462 | + |
|
| 463 | + // loger si la table des rubriques semble foireuse |
|
| 464 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 465 | + if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 466 | + spip_log( |
|
| 467 | + 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 468 | + _LOG_CRITIQUE |
|
| 469 | + ); |
|
| 470 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // reparer les articles |
|
| 474 | + $r = sql_select( |
|
| 475 | + 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 476 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 477 | + 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 478 | + ); |
|
| 479 | + |
|
| 480 | + while ($row = sql_fetch($r)) { |
|
| 481 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 485 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | |
@@ -497,23 +497,23 @@ discard block |
||
| 497 | 497 | * true si un changement a eu lieu |
| 498 | 498 | **/ |
| 499 | 499 | function calculer_langues_rubriques_etape() { |
| 500 | - $s = sql_select( |
|
| 501 | - 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 502 | - 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 503 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 504 | - ); |
|
| 505 | - |
|
| 506 | - $t = false; |
|
| 507 | - while ($row = sql_fetch($s)) { |
|
| 508 | - $id_rubrique = $row['id_rubrique']; |
|
| 509 | - $t = sql_updateq( |
|
| 510 | - 'spip_rubriques', |
|
| 511 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 512 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 513 | - ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - return $t; |
|
| 500 | + $s = sql_select( |
|
| 501 | + 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 502 | + 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 503 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 504 | + ); |
|
| 505 | + |
|
| 506 | + $t = false; |
|
| 507 | + while ($row = sql_fetch($s)) { |
|
| 508 | + $id_rubrique = $row['id_rubrique']; |
|
| 509 | + $t = sql_updateq( |
|
| 510 | + 'spip_rubriques', |
|
| 511 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 512 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 513 | + ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + return $t; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -533,38 +533,38 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function calculer_langues_rubriques() { |
| 535 | 535 | |
| 536 | - // rubriques (recursivite) |
|
| 537 | - sql_updateq( |
|
| 538 | - 'spip_rubriques', |
|
| 539 | - ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 540 | - "id_parent=0 AND langue_choisie != 'oui'" |
|
| 541 | - ); |
|
| 542 | - while (calculer_langues_rubriques_etape()) { |
|
| 543 | - ; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - // articles |
|
| 547 | - $s = sql_select( |
|
| 548 | - 'A.id_article AS id_article, R.lang AS lang', |
|
| 549 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 550 | - "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang" |
|
| 551 | - ); |
|
| 552 | - while ($row = sql_fetch($s)) { |
|
| 553 | - $id_article = $row['id_article']; |
|
| 554 | - sql_updateq( |
|
| 555 | - 'spip_articles', |
|
| 556 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 557 | - 'id_article=' . intval($id_article) |
|
| 558 | - ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 562 | - $langues = calculer_langues_utilisees(); |
|
| 563 | - ecrire_meta('langues_utilisees', $langues); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 567 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 536 | + // rubriques (recursivite) |
|
| 537 | + sql_updateq( |
|
| 538 | + 'spip_rubriques', |
|
| 539 | + ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 540 | + "id_parent=0 AND langue_choisie != 'oui'" |
|
| 541 | + ); |
|
| 542 | + while (calculer_langues_rubriques_etape()) { |
|
| 543 | + ; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + // articles |
|
| 547 | + $s = sql_select( |
|
| 548 | + 'A.id_article AS id_article, R.lang AS lang', |
|
| 549 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 550 | + "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang" |
|
| 551 | + ); |
|
| 552 | + while ($row = sql_fetch($s)) { |
|
| 553 | + $id_article = $row['id_article']; |
|
| 554 | + sql_updateq( |
|
| 555 | + 'spip_articles', |
|
| 556 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 557 | + 'id_article=' . intval($id_article) |
|
| 558 | + ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 562 | + $langues = calculer_langues_utilisees(); |
|
| 563 | + ecrire_meta('langues_utilisees', $langues); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 567 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
@@ -581,80 +581,80 @@ discard block |
||
| 581 | 581 | * Liste des langues utilisées séparées par des virgules |
| 582 | 582 | **/ |
| 583 | 583 | function calculer_langues_utilisees($serveur = '') { |
| 584 | - include_spip('public/interfaces'); |
|
| 585 | - include_spip('public/compiler'); |
|
| 586 | - include_spip('public/composer'); |
|
| 587 | - include_spip('public/phraser_html'); |
|
| 588 | - $langues = []; |
|
| 589 | - |
|
| 590 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 591 | - |
|
| 592 | - include_spip('base/objets'); |
|
| 593 | - $tables = lister_tables_objets_sql(); |
|
| 594 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 595 | - |
|
| 596 | - foreach (array_keys($tables) as $t) { |
|
| 597 | - $desc = $trouver_table($t, $serveur); |
|
| 598 | - // c'est une table avec des langues |
|
| 599 | - if ( |
|
| 600 | - $desc['exist'] |
|
| 601 | - and isset($desc['field']['lang']) |
|
| 602 | - and isset($desc['field']['langue_choisie']) |
|
| 603 | - ) { |
|
| 604 | - $boucle = new Boucle(); |
|
| 605 | - $boucle->show = $desc; |
|
| 606 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 607 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 608 | - $boucle->id_table = $desc['table_objet']; |
|
| 609 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 610 | - $boucle->sql_serveur = $serveur; |
|
| 611 | - $boucle->select[] = 'DISTINCT lang'; |
|
| 612 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 613 | - $boucle->separateur[] = ','; |
|
| 614 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 615 | - $boucle->iterateur = 'sql'; |
|
| 616 | - |
|
| 617 | - $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 618 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 619 | - $boucle->descr['gram'] = 'html'; |
|
| 620 | - |
|
| 621 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 622 | - |
|
| 623 | - if ( |
|
| 624 | - isset($desc['statut']) |
|
| 625 | - and $desc['statut'] |
|
| 626 | - ) { |
|
| 627 | - $boucles = [ |
|
| 628 | - 'calculer_langues_utilisees' => $boucle, |
|
| 629 | - ]; |
|
| 630 | - // generer un nom de fonction "anonyme" unique |
|
| 631 | - do { |
|
| 632 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 633 | - } while (function_exists($functionname)); |
|
| 634 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 635 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 636 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 637 | - $res = ''; |
|
| 638 | - eval($code); |
|
| 639 | - $res = explode(',', $res); |
|
| 640 | - foreach ($res as $lang) { |
|
| 641 | - $langues[$lang] = 1; |
|
| 642 | - } |
|
| 643 | - } else { |
|
| 644 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 645 | - while ($row = sql_fetch($res)) { |
|
| 646 | - $langues[$row['lang']] = 1; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - $langues = array_filter(array_keys($langues)); |
|
| 653 | - sort($langues); |
|
| 654 | - $langues = join(',', $langues); |
|
| 655 | - spip_log("langues utilisees: $langues"); |
|
| 656 | - |
|
| 657 | - return $langues; |
|
| 584 | + include_spip('public/interfaces'); |
|
| 585 | + include_spip('public/compiler'); |
|
| 586 | + include_spip('public/composer'); |
|
| 587 | + include_spip('public/phraser_html'); |
|
| 588 | + $langues = []; |
|
| 589 | + |
|
| 590 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 591 | + |
|
| 592 | + include_spip('base/objets'); |
|
| 593 | + $tables = lister_tables_objets_sql(); |
|
| 594 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 595 | + |
|
| 596 | + foreach (array_keys($tables) as $t) { |
|
| 597 | + $desc = $trouver_table($t, $serveur); |
|
| 598 | + // c'est une table avec des langues |
|
| 599 | + if ( |
|
| 600 | + $desc['exist'] |
|
| 601 | + and isset($desc['field']['lang']) |
|
| 602 | + and isset($desc['field']['langue_choisie']) |
|
| 603 | + ) { |
|
| 604 | + $boucle = new Boucle(); |
|
| 605 | + $boucle->show = $desc; |
|
| 606 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 607 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 608 | + $boucle->id_table = $desc['table_objet']; |
|
| 609 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 610 | + $boucle->sql_serveur = $serveur; |
|
| 611 | + $boucle->select[] = 'DISTINCT lang'; |
|
| 612 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 613 | + $boucle->separateur[] = ','; |
|
| 614 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 615 | + $boucle->iterateur = 'sql'; |
|
| 616 | + |
|
| 617 | + $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 618 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 619 | + $boucle->descr['gram'] = 'html'; |
|
| 620 | + |
|
| 621 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 622 | + |
|
| 623 | + if ( |
|
| 624 | + isset($desc['statut']) |
|
| 625 | + and $desc['statut'] |
|
| 626 | + ) { |
|
| 627 | + $boucles = [ |
|
| 628 | + 'calculer_langues_utilisees' => $boucle, |
|
| 629 | + ]; |
|
| 630 | + // generer un nom de fonction "anonyme" unique |
|
| 631 | + do { |
|
| 632 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 633 | + } while (function_exists($functionname)); |
|
| 634 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 635 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 636 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 637 | + $res = ''; |
|
| 638 | + eval($code); |
|
| 639 | + $res = explode(',', $res); |
|
| 640 | + foreach ($res as $lang) { |
|
| 641 | + $langues[$lang] = 1; |
|
| 642 | + } |
|
| 643 | + } else { |
|
| 644 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 645 | + while ($row = sql_fetch($res)) { |
|
| 646 | + $langues[$row['lang']] = 1; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + $langues = array_filter(array_keys($langues)); |
|
| 653 | + sort($langues); |
|
| 654 | + $langues = join(',', $langues); |
|
| 655 | + spip_log("langues utilisees: $langues"); |
|
| 656 | + |
|
| 657 | + return $langues; |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
@@ -671,9 +671,9 @@ discard block |
||
| 671 | 671 | * incluant les rubriques noeuds et toutes leurs descendances |
| 672 | 672 | */ |
| 673 | 673 | function calcul_branche_in($id) { |
| 674 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 674 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 675 | 675 | |
| 676 | - return $calcul_branche_in($id); |
|
| 676 | + return $calcul_branche_in($id); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | /** |
@@ -691,9 +691,9 @@ discard block |
||
| 691 | 691 | * incluant les rubriques transmises et toutes leurs parentées |
| 692 | 692 | */ |
| 693 | 693 | function calcul_hierarchie_in($id, $tout = true) { |
| 694 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 694 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 695 | 695 | |
| 696 | - return $calcul_hierarchie_in($id, $tout); |
|
| 696 | + return $calcul_hierarchie_in($id, $tout); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | |
@@ -714,40 +714,40 @@ discard block |
||
| 714 | 714 | * incluant les rubriques noeuds et toutes leurs descendances |
| 715 | 715 | */ |
| 716 | 716 | function inc_calcul_branche_in_dist($id) { |
| 717 | - static $b = []; |
|
| 718 | - |
|
| 719 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 720 | - if (!is_array($id)) { |
|
| 721 | - $id = explode(',', $id); |
|
| 722 | - } |
|
| 723 | - $id = join(',', array_map('intval', $id)); |
|
| 724 | - if (isset($b[$id])) { |
|
| 725 | - return $b[$id]; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - // Notre branche commence par la rubrique de depart |
|
| 729 | - $branche = $r = $id; |
|
| 730 | - |
|
| 731 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 732 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 733 | - $maxiter = 10000; |
|
| 734 | - while ( |
|
| 735 | - $maxiter-- and $filles = sql_allfetsel( |
|
| 736 | - 'id_rubrique', |
|
| 737 | - 'spip_rubriques', |
|
| 738 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 739 | - ) |
|
| 740 | - ) { |
|
| 741 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 742 | - $branche .= ',' . $r; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 746 | - if (strlen($branche) < 10000) { |
|
| 747 | - $b[$id] = $branche; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - return $branche; |
|
| 717 | + static $b = []; |
|
| 718 | + |
|
| 719 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 720 | + if (!is_array($id)) { |
|
| 721 | + $id = explode(',', $id); |
|
| 722 | + } |
|
| 723 | + $id = join(',', array_map('intval', $id)); |
|
| 724 | + if (isset($b[$id])) { |
|
| 725 | + return $b[$id]; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + // Notre branche commence par la rubrique de depart |
|
| 729 | + $branche = $r = $id; |
|
| 730 | + |
|
| 731 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 732 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 733 | + $maxiter = 10000; |
|
| 734 | + while ( |
|
| 735 | + $maxiter-- and $filles = sql_allfetsel( |
|
| 736 | + 'id_rubrique', |
|
| 737 | + 'spip_rubriques', |
|
| 738 | + sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 739 | + ) |
|
| 740 | + ) { |
|
| 741 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 742 | + $branche .= ',' . $r; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 746 | + if (strlen($branche) < 10000) { |
|
| 747 | + $b[$id] = $branche; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + return $branche; |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | |
@@ -769,45 +769,45 @@ discard block |
||
| 769 | 769 | * incluant les rubriques transmises et toutes leurs parentées |
| 770 | 770 | */ |
| 771 | 771 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 772 | - static $b = []; |
|
| 773 | - |
|
| 774 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 775 | - if (!is_array($id)) { |
|
| 776 | - $id = explode(',', $id); |
|
| 777 | - } |
|
| 778 | - $id = join(',', array_map('intval', $id)); |
|
| 779 | - |
|
| 780 | - if (isset($b[$id])) { |
|
| 781 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 782 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - $hier = ''; |
|
| 786 | - |
|
| 787 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 788 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 789 | - $ids_nouveaux_parents = $id; |
|
| 790 | - $maxiter = 10000; |
|
| 791 | - while ( |
|
| 792 | - $maxiter-- and $parents = sql_allfetsel( |
|
| 793 | - 'id_parent', |
|
| 794 | - 'spip_rubriques', |
|
| 795 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 796 | - ) |
|
| 797 | - ) { |
|
| 798 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 799 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 803 | - if (strlen($hier) < 10000) { |
|
| 804 | - $b[$id] = $hier; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 808 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 809 | - |
|
| 810 | - return $hier; |
|
| 772 | + static $b = []; |
|
| 773 | + |
|
| 774 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 775 | + if (!is_array($id)) { |
|
| 776 | + $id = explode(',', $id); |
|
| 777 | + } |
|
| 778 | + $id = join(',', array_map('intval', $id)); |
|
| 779 | + |
|
| 780 | + if (isset($b[$id])) { |
|
| 781 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 782 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + $hier = ''; |
|
| 786 | + |
|
| 787 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 788 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 789 | + $ids_nouveaux_parents = $id; |
|
| 790 | + $maxiter = 10000; |
|
| 791 | + while ( |
|
| 792 | + $maxiter-- and $parents = sql_allfetsel( |
|
| 793 | + 'id_parent', |
|
| 794 | + 'spip_rubriques', |
|
| 795 | + sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 796 | + ) |
|
| 797 | + ) { |
|
| 798 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 799 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 803 | + if (strlen($hier) < 10000) { |
|
| 804 | + $b[$id] = $hier; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 808 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 809 | + |
|
| 810 | + return $hier; |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | |
@@ -825,47 +825,47 @@ discard block |
||
| 825 | 825 | * @return void |
| 826 | 826 | **/ |
| 827 | 827 | function calculer_prochain_postdate($check = false) { |
| 828 | - include_spip('base/abstract_sql'); |
|
| 829 | - if ($check) { |
|
| 830 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 831 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 832 | - |
|
| 833 | - $r = sql_select( |
|
| 834 | - 'DISTINCT A.id_rubrique AS id', |
|
| 835 | - 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 836 | - "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 837 | - ); |
|
| 838 | - while ($row = sql_fetch($r)) { |
|
| 839 | - publier_branche_rubrique($row['id']); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - $t = sql_fetsel( |
|
| 846 | - 'date', |
|
| 847 | - 'spip_articles', |
|
| 848 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 849 | - '', |
|
| 850 | - 'date', |
|
| 851 | - '1' |
|
| 852 | - ); |
|
| 853 | - |
|
| 854 | - if ($t) { |
|
| 855 | - $t = $t['date']; |
|
| 856 | - if ( |
|
| 857 | - !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 858 | - or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 859 | - ) { |
|
| 860 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 861 | - ecrire_meta('derniere_modif', time()); |
|
| 862 | - } |
|
| 863 | - } else { |
|
| 864 | - effacer_meta('date_prochain_postdate'); |
|
| 865 | - ecrire_meta('derniere_modif', time()); |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - spip_log("prochain postdate: $t"); |
|
| 828 | + include_spip('base/abstract_sql'); |
|
| 829 | + if ($check) { |
|
| 830 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 831 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 832 | + |
|
| 833 | + $r = sql_select( |
|
| 834 | + 'DISTINCT A.id_rubrique AS id', |
|
| 835 | + 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 836 | + "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 837 | + ); |
|
| 838 | + while ($row = sql_fetch($r)) { |
|
| 839 | + publier_branche_rubrique($row['id']); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + $t = sql_fetsel( |
|
| 846 | + 'date', |
|
| 847 | + 'spip_articles', |
|
| 848 | + "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 849 | + '', |
|
| 850 | + 'date', |
|
| 851 | + '1' |
|
| 852 | + ); |
|
| 853 | + |
|
| 854 | + if ($t) { |
|
| 855 | + $t = $t['date']; |
|
| 856 | + if ( |
|
| 857 | + !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 858 | + or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 859 | + ) { |
|
| 860 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 861 | + ecrire_meta('derniere_modif', time()); |
|
| 862 | + } |
|
| 863 | + } else { |
|
| 864 | + effacer_meta('date_prochain_postdate'); |
|
| 865 | + ecrire_meta('derniere_modif', time()); |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + spip_log("prochain postdate: $t"); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | /** |
@@ -890,62 +890,62 @@ discard block |
||
| 890 | 890 | */ |
| 891 | 891 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 892 | 892 | |
| 893 | - // eclater l'arborescence demandee |
|
| 894 | - // echapper les </multi> et autres balises fermantes html |
|
| 895 | - $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 896 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 897 | - include_spip('base/abstract_sql'); |
|
| 898 | - foreach ($arbo as $titre) { |
|
| 899 | - // retablir les </multi> et autres balises fermantes html |
|
| 900 | - $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 901 | - $r = sql_getfetsel( |
|
| 902 | - 'id_rubrique', |
|
| 903 | - 'spip_rubriques', |
|
| 904 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 905 | - $groupby = [], |
|
| 906 | - $orderby = [], |
|
| 907 | - $limit = '', |
|
| 908 | - $having = [], |
|
| 909 | - $serveur |
|
| 910 | - ); |
|
| 911 | - if ($r !== null) { |
|
| 912 | - $id_parent = $r; |
|
| 913 | - } else { |
|
| 914 | - $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 915 | - 'titre' => $titre, |
|
| 916 | - 'id_parent' => $id_parent, |
|
| 917 | - 'statut' => 'prepa' |
|
| 918 | - ], $desc = [], $serveur); |
|
| 919 | - if ($id_parent > 0) { |
|
| 920 | - $data = sql_fetsel( |
|
| 921 | - 'id_secteur,lang', |
|
| 922 | - 'spip_rubriques', |
|
| 923 | - "id_rubrique=$id_parent", |
|
| 924 | - $groupby = [], |
|
| 925 | - $orderby = [], |
|
| 926 | - $limit = '', |
|
| 927 | - $having = [], |
|
| 928 | - $serveur |
|
| 929 | - ); |
|
| 930 | - $id_secteur = $data['id_secteur']; |
|
| 931 | - $lang = $data['lang']; |
|
| 932 | - } else { |
|
| 933 | - $id_secteur = $id_rubrique; |
|
| 934 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - sql_updateq( |
|
| 938 | - 'spip_rubriques', |
|
| 939 | - ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 940 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 941 | - $desc = '', |
|
| 942 | - $serveur |
|
| 943 | - ); |
|
| 944 | - |
|
| 945 | - // pour la recursion |
|
| 946 | - $id_parent = $id_rubrique; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - return intval($id_parent); |
|
| 893 | + // eclater l'arborescence demandee |
|
| 894 | + // echapper les </multi> et autres balises fermantes html |
|
| 895 | + $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 896 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 897 | + include_spip('base/abstract_sql'); |
|
| 898 | + foreach ($arbo as $titre) { |
|
| 899 | + // retablir les </multi> et autres balises fermantes html |
|
| 900 | + $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 901 | + $r = sql_getfetsel( |
|
| 902 | + 'id_rubrique', |
|
| 903 | + 'spip_rubriques', |
|
| 904 | + 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 905 | + $groupby = [], |
|
| 906 | + $orderby = [], |
|
| 907 | + $limit = '', |
|
| 908 | + $having = [], |
|
| 909 | + $serveur |
|
| 910 | + ); |
|
| 911 | + if ($r !== null) { |
|
| 912 | + $id_parent = $r; |
|
| 913 | + } else { |
|
| 914 | + $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 915 | + 'titre' => $titre, |
|
| 916 | + 'id_parent' => $id_parent, |
|
| 917 | + 'statut' => 'prepa' |
|
| 918 | + ], $desc = [], $serveur); |
|
| 919 | + if ($id_parent > 0) { |
|
| 920 | + $data = sql_fetsel( |
|
| 921 | + 'id_secteur,lang', |
|
| 922 | + 'spip_rubriques', |
|
| 923 | + "id_rubrique=$id_parent", |
|
| 924 | + $groupby = [], |
|
| 925 | + $orderby = [], |
|
| 926 | + $limit = '', |
|
| 927 | + $having = [], |
|
| 928 | + $serveur |
|
| 929 | + ); |
|
| 930 | + $id_secteur = $data['id_secteur']; |
|
| 931 | + $lang = $data['lang']; |
|
| 932 | + } else { |
|
| 933 | + $id_secteur = $id_rubrique; |
|
| 934 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + sql_updateq( |
|
| 938 | + 'spip_rubriques', |
|
| 939 | + ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 940 | + 'id_rubrique=' . intval($id_rubrique), |
|
| 941 | + $desc = '', |
|
| 942 | + $serveur |
|
| 943 | + ); |
|
| 944 | + |
|
| 945 | + // pour la recursion |
|
| 946 | + $id_parent = $id_rubrique; |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + return intval($id_parent); |
|
| 951 | 951 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Affichage |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @return string Code HTML |
| 26 | 26 | */ |
| 27 | 27 | function debut_grand_cadre() { |
| 28 | - return "\n<div class = 'table_page'>\n"; |
|
| 28 | + return "\n<div class = 'table_page'>\n"; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return string Code HTML |
| 35 | 35 | */ |
| 36 | 36 | function fin_grand_cadre() { |
| 37 | - return "\n</div>"; |
|
| 37 | + return "\n</div>"; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Debut de la colonne de gauche |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @return string Code HTML |
| 50 | 50 | */ |
| 51 | 51 | function debut_gauche() { |
| 52 | - return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 52 | + return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @return string Code HTML |
| 59 | 59 | */ |
| 60 | 60 | function fin_gauche() { |
| 61 | - return "</div></div><br class = 'nettoyeur' />"; |
|
| 61 | + return "</div></div><br class = 'nettoyeur' />"; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @return string Code HTML |
| 68 | 68 | */ |
| 69 | 69 | function creer_colonne_droite() { |
| 70 | - static $deja_colonne_droite; |
|
| 71 | - if ($deja_colonne_droite) { |
|
| 72 | - return ''; |
|
| 73 | - } |
|
| 74 | - $deja_colonne_droite = true; |
|
| 70 | + static $deja_colonne_droite; |
|
| 71 | + if ($deja_colonne_droite) { |
|
| 72 | + return ''; |
|
| 73 | + } |
|
| 74 | + $deja_colonne_droite = true; |
|
| 75 | 75 | |
| 76 | - return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 76 | + return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @return string Code HTML |
| 83 | 83 | */ |
| 84 | 84 | function debut_droite() { |
| 85 | - return liste_objets_bloques(_request('exec')) |
|
| 86 | - . creer_colonne_droite() |
|
| 87 | - . '</div>' |
|
| 88 | - . "\n<div id='contenu'>"; |
|
| 85 | + return liste_objets_bloques(_request('exec')) |
|
| 86 | + . creer_colonne_droite() |
|
| 87 | + . '</div>' |
|
| 88 | + . "\n<div id='contenu'>"; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -107,31 +107,31 @@ discard block |
||
| 107 | 107 | * Code HTML |
| 108 | 108 | **/ |
| 109 | 109 | function liste_objets_bloques($exec, $contexte = [], $auteur = null) { |
| 110 | - $res = ''; |
|
| 111 | - if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 112 | - include_spip('inc/drapeau_edition'); |
|
| 113 | - if (is_null($auteur)) { |
|
| 114 | - $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | - } |
|
| 116 | - if ( |
|
| 117 | - $en_cours = trouver_objet_exec($exec) |
|
| 118 | - and $en_cours['edition'] |
|
| 119 | - and $type = $en_cours['type'] |
|
| 120 | - and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 121 | - or $id = _request($en_cours['id_table_objet'])) |
|
| 122 | - ) { |
|
| 123 | - // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | - // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | - signale_edition($id, $auteur, $type); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | - if (count($objets_ouverts)) { |
|
| 130 | - $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $res; |
|
| 110 | + $res = ''; |
|
| 111 | + if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 112 | + include_spip('inc/drapeau_edition'); |
|
| 113 | + if (is_null($auteur)) { |
|
| 114 | + $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | + } |
|
| 116 | + if ( |
|
| 117 | + $en_cours = trouver_objet_exec($exec) |
|
| 118 | + and $en_cours['edition'] |
|
| 119 | + and $type = $en_cours['type'] |
|
| 120 | + and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 121 | + or $id = _request($en_cours['id_table_objet'])) |
|
| 122 | + ) { |
|
| 123 | + // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | + // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | + signale_edition($id, $auteur, $type); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | + if (count($objets_ouverts)) { |
|
| 130 | + $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $res; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -145,20 +145,20 @@ discard block |
||
| 145 | 145 | * @return string Code HTML |
| 146 | 146 | **/ |
| 147 | 147 | function fin_page() { |
| 148 | - include_spip('inc/pipelines'); |
|
| 149 | - // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | - $debug = ((_request('exec') !== 'valider_xml') |
|
| 151 | - and ((_request('var_mode') == 'debug') |
|
| 152 | - or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 153 | - and isset($_COOKIE['spip_admin']))); |
|
| 154 | - $t = '</div><div id="pied"><div class="largeur">' |
|
| 155 | - . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 156 | - . '</div>' |
|
| 157 | - . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 158 | - . ($debug ? erreur_squelette() : '') |
|
| 159 | - . "</body></html>\n"; |
|
| 160 | - |
|
| 161 | - return f_queue($t); |
|
| 148 | + include_spip('inc/pipelines'); |
|
| 149 | + // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | + $debug = ((_request('exec') !== 'valider_xml') |
|
| 151 | + and ((_request('var_mode') == 'debug') |
|
| 152 | + or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 153 | + and isset($_COOKIE['spip_admin']))); |
|
| 154 | + $t = '</div><div id="pied"><div class="largeur">' |
|
| 155 | + . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 156 | + . '</div>' |
|
| 157 | + . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 158 | + . ($debug ? erreur_squelette() : '') |
|
| 159 | + . "</body></html>\n"; |
|
| 160 | + |
|
| 161 | + return f_queue($t); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -173,22 +173,22 @@ discard block |
||
| 173 | 173 | * @return string Code HTML |
| 174 | 174 | **/ |
| 175 | 175 | function html_tests_js() { |
| 176 | - if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 177 | - // pour le pied de page (deja defini si on est validation XML) |
|
| 178 | - define( |
|
| 179 | - '_TESTER_NOSCRIPT', |
|
| 180 | - "<noscript>\n<div style='display:none;'><img src='" |
|
| 181 | - . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 182 | - . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 183 | - ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $rejouer = ''; |
|
| 187 | - if (defined('_SESSION_REJOUER')) { |
|
| 188 | - $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 176 | + if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 177 | + // pour le pied de page (deja defini si on est validation XML) |
|
| 178 | + define( |
|
| 179 | + '_TESTER_NOSCRIPT', |
|
| 180 | + "<noscript>\n<div style='display:none;'><img src='" |
|
| 181 | + . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 182 | + . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 183 | + ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $rejouer = ''; |
|
| 187 | + if (defined('_SESSION_REJOUER')) { |
|
| 188 | + $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -198,25 +198,25 @@ discard block |
||
| 198 | 198 | **/ |
| 199 | 199 | function info_maj_spip() { |
| 200 | 200 | |
| 201 | - $maj = isset($GLOBALS['meta']['info_maj_spip']) ? $GLOBALS['meta']['info_maj_spip'] : null; |
|
| 202 | - if (!$maj) { |
|
| 203 | - return ''; |
|
| 204 | - } |
|
| 201 | + $maj = isset($GLOBALS['meta']['info_maj_spip']) ? $GLOBALS['meta']['info_maj_spip'] : null; |
|
| 202 | + if (!$maj) { |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - $maj = explode('|', $maj); |
|
| 207 | - // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 208 | - if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 209 | - return ''; |
|
| 210 | - } |
|
| 206 | + $maj = explode('|', $maj); |
|
| 207 | + // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 208 | + if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 209 | + return ''; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - if (!autoriser('webmestre')) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 212 | + if (!autoriser('webmestre')) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - array_shift($maj); |
|
| 217 | - $maj = implode('|', $maj); |
|
| 216 | + array_shift($maj); |
|
| 217 | + $maj = implode('|', $maj); |
|
| 218 | 218 | |
| 219 | - return "$maj<br />"; |
|
| 219 | + return "$maj<br />"; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -227,47 +227,47 @@ discard block |
||
| 227 | 227 | **/ |
| 228 | 228 | function info_copyright() { |
| 229 | 229 | |
| 230 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 231 | - |
|
| 232 | - // |
|
| 233 | - // Mention, le cas echeant, de la revision SVN courante |
|
| 234 | - // |
|
| 235 | - if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 236 | - if ($vcs['vcs'] === 'GIT') { |
|
| 237 | - $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 238 | - } elseif ($vcs['vcs'] === 'SVN') { |
|
| 239 | - $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 240 | - } else { |
|
| 241 | - $url = ''; |
|
| 242 | - } |
|
| 243 | - // affichage "GIT [master: abcdef]" |
|
| 244 | - $commit = isset($vcs['commit_short']) ? $vcs['commit_short'] : $vcs['commit']; |
|
| 245 | - if ($url) { |
|
| 246 | - $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 247 | - } |
|
| 248 | - if ($vcs['branch']) { |
|
| 249 | - $commit = $vcs['branch'] . ': ' . $commit; |
|
| 250 | - } |
|
| 251 | - $version .= " {$vcs['vcs']} [$commit]"; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // et la version de l'ecran de securite |
|
| 255 | - $secu = defined('_ECRAN_SECURITE') |
|
| 256 | - ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 257 | - : ''; |
|
| 258 | - |
|
| 259 | - return _T( |
|
| 260 | - 'info_copyright', |
|
| 261 | - [ |
|
| 262 | - 'spip' => "<b>SPIP $version</b> ", |
|
| 263 | - 'lien_gpl' => |
|
| 264 | - "<a href='" . generer_url_ecrire( |
|
| 265 | - 'aide', |
|
| 266 | - 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 267 | - ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 268 | - ] |
|
| 269 | - ) |
|
| 270 | - . $secu; |
|
| 230 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 231 | + |
|
| 232 | + // |
|
| 233 | + // Mention, le cas echeant, de la revision SVN courante |
|
| 234 | + // |
|
| 235 | + if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 236 | + if ($vcs['vcs'] === 'GIT') { |
|
| 237 | + $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 238 | + } elseif ($vcs['vcs'] === 'SVN') { |
|
| 239 | + $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 240 | + } else { |
|
| 241 | + $url = ''; |
|
| 242 | + } |
|
| 243 | + // affichage "GIT [master: abcdef]" |
|
| 244 | + $commit = isset($vcs['commit_short']) ? $vcs['commit_short'] : $vcs['commit']; |
|
| 245 | + if ($url) { |
|
| 246 | + $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 247 | + } |
|
| 248 | + if ($vcs['branch']) { |
|
| 249 | + $commit = $vcs['branch'] . ': ' . $commit; |
|
| 250 | + } |
|
| 251 | + $version .= " {$vcs['vcs']} [$commit]"; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // et la version de l'ecran de securite |
|
| 255 | + $secu = defined('_ECRAN_SECURITE') |
|
| 256 | + ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 257 | + : ''; |
|
| 258 | + |
|
| 259 | + return _T( |
|
| 260 | + 'info_copyright', |
|
| 261 | + [ |
|
| 262 | + 'spip' => "<b>SPIP $version</b> ", |
|
| 263 | + 'lien_gpl' => |
|
| 264 | + "<a href='" . generer_url_ecrire( |
|
| 265 | + 'aide', |
|
| 266 | + 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 267 | + ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 268 | + ] |
|
| 269 | + ) |
|
| 270 | + . $secu; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -282,17 +282,17 @@ discard block |
||
| 282 | 282 | * @return string Code HTML |
| 283 | 283 | **/ |
| 284 | 284 | function formulaire_recherche($page, $complement = '') { |
| 285 | - $recherche = _request('recherche'); |
|
| 286 | - $recherche_aff = entites_html($recherche); |
|
| 287 | - if (!strlen($recherche)) { |
|
| 288 | - $recherche_aff = _T('info_rechercher'); |
|
| 289 | - $onfocus = " onfocus=\"this.value='';\""; |
|
| 290 | - } else { |
|
| 291 | - $onfocus = ''; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 295 | - $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 296 | - |
|
| 297 | - return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 285 | + $recherche = _request('recherche'); |
|
| 286 | + $recherche_aff = entites_html($recherche); |
|
| 287 | + if (!strlen($recherche)) { |
|
| 288 | + $recherche_aff = _T('info_rechercher'); |
|
| 289 | + $onfocus = " onfocus=\"this.value='';\""; |
|
| 290 | + } else { |
|
| 291 | + $onfocus = ''; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 295 | + $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 296 | + |
|
| 297 | + return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 298 | 298 | } |
@@ -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 | /** |
@@ -25,51 +25,51 @@ discard block |
||
| 25 | 25 | * privée ou dans un de ses sous menus |
| 26 | 26 | */ |
| 27 | 27 | class Bouton { |
| 28 | - /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | - public $icone; |
|
| 30 | - |
|
| 31 | - /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | - public $libelle; |
|
| 33 | - |
|
| 34 | - /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | - public $url = null; |
|
| 36 | - |
|
| 37 | - /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | - public $urlArg = null; |
|
| 39 | - |
|
| 40 | - /** @var null|string URL du javascript */ |
|
| 41 | - public $url2 = null; |
|
| 42 | - |
|
| 43 | - /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | - public $target = null; |
|
| 45 | - |
|
| 46 | - /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | - public $sousmenu = null; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Définit un bouton |
|
| 51 | - * |
|
| 52 | - * @param string $icone |
|
| 53 | - * L'icone à mettre dans le bouton |
|
| 54 | - * @param string $libelle |
|
| 55 | - * Le nom de l'entrée i18n associé |
|
| 56 | - * @param null|string $url |
|
| 57 | - * L'URL de la page |
|
| 58 | - * @param null|string|array $urlArg |
|
| 59 | - * Arguments supplémentaires de l'URL |
|
| 60 | - * @param null|string $url2 |
|
| 61 | - * URL du javascript |
|
| 62 | - * @param null|mixed $target |
|
| 63 | - * Pour ouvrir une fenêtre à part |
|
| 64 | - */ |
|
| 65 | - public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | - $this->icone = $icone; |
|
| 67 | - $this->libelle = $libelle; |
|
| 68 | - $this->url = $url; |
|
| 69 | - $this->urlArg = $urlArg; |
|
| 70 | - $this->url2 = $url2; |
|
| 71 | - $this->target = $target; |
|
| 72 | - } |
|
| 28 | + /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | + public $icone; |
|
| 30 | + |
|
| 31 | + /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | + public $libelle; |
|
| 33 | + |
|
| 34 | + /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | + public $url = null; |
|
| 36 | + |
|
| 37 | + /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | + public $urlArg = null; |
|
| 39 | + |
|
| 40 | + /** @var null|string URL du javascript */ |
|
| 41 | + public $url2 = null; |
|
| 42 | + |
|
| 43 | + /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | + public $target = null; |
|
| 45 | + |
|
| 46 | + /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | + public $sousmenu = null; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Définit un bouton |
|
| 51 | + * |
|
| 52 | + * @param string $icone |
|
| 53 | + * L'icone à mettre dans le bouton |
|
| 54 | + * @param string $libelle |
|
| 55 | + * Le nom de l'entrée i18n associé |
|
| 56 | + * @param null|string $url |
|
| 57 | + * L'URL de la page |
|
| 58 | + * @param null|string|array $urlArg |
|
| 59 | + * Arguments supplémentaires de l'URL |
|
| 60 | + * @param null|string $url2 |
|
| 61 | + * URL du javascript |
|
| 62 | + * @param null|mixed $target |
|
| 63 | + * Pour ouvrir une fenêtre à part |
|
| 64 | + */ |
|
| 65 | + public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | + $this->icone = $icone; |
|
| 67 | + $this->libelle = $libelle; |
|
| 68 | + $this->url = $url; |
|
| 69 | + $this->urlArg = $urlArg; |
|
| 70 | + $this->url2 = $url2; |
|
| 71 | + $this->target = $target; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -86,35 +86,35 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function definir_barre_onglets($script) { |
| 88 | 88 | |
| 89 | - $onglets = []; |
|
| 90 | - $liste_onglets = []; |
|
| 91 | - |
|
| 92 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | - if (function_exists('onglets_plugins')) { |
|
| 94 | - $liste_onglets = onglets_plugins(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - foreach ($liste_onglets as $id => $infos) { |
|
| 99 | - if ( |
|
| 100 | - ($parent = $infos['parent']) |
|
| 101 | - && $parent == $script |
|
| 102 | - && autoriser('onglet', "_$id") |
|
| 103 | - ) { |
|
| 104 | - $onglets[$id] = new Bouton( |
|
| 105 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | - $infos['titre'], // titre |
|
| 107 | - (isset($infos['action']) and $infos['action']) |
|
| 108 | - ? generer_url_ecrire( |
|
| 109 | - $infos['action'], |
|
| 110 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | - ) |
|
| 112 | - : null |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 89 | + $onglets = []; |
|
| 90 | + $liste_onglets = []; |
|
| 91 | + |
|
| 92 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | + if (function_exists('onglets_plugins')) { |
|
| 94 | + $liste_onglets = onglets_plugins(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + foreach ($liste_onglets as $id => $infos) { |
|
| 99 | + if ( |
|
| 100 | + ($parent = $infos['parent']) |
|
| 101 | + && $parent == $script |
|
| 102 | + && autoriser('onglet', "_$id") |
|
| 103 | + ) { |
|
| 104 | + $onglets[$id] = new Bouton( |
|
| 105 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | + $infos['titre'], // titre |
|
| 107 | + (isset($infos['action']) and $infos['action']) |
|
| 108 | + ? generer_url_ecrire( |
|
| 109 | + $infos['action'], |
|
| 110 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | + ) |
|
| 112 | + : null |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | 135 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 136 | - include_spip('inc/presentation'); |
|
| 136 | + include_spip('inc/presentation'); |
|
| 137 | 137 | |
| 138 | - $res = ''; |
|
| 138 | + $res = ''; |
|
| 139 | 139 | |
| 140 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | - $url = $onglet->url ? $onglet->url : generer_url_ecrire($exec); |
|
| 142 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | - } |
|
| 140 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | + $url = $onglet->url ? $onglet->url : generer_url_ecrire($exec); |
|
| 142 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 145 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 146 | 146 | } |
@@ -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 | /** |
@@ -26,41 +26,41 @@ discard block |
||
| 26 | 26 | * @return string Code HTML du cadre dépliable |
| 27 | 27 | **/ |
| 28 | 28 | function cadre_depliable($icone, $titre, $deplie, $contenu, $ids = '', $style_cadre = 'r') { |
| 29 | - $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | - |
|
| 31 | - return |
|
| 32 | - debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | - . debut_block_depliable($deplie, $ids) |
|
| 34 | - . "<div class='cadre_padding'>\n" |
|
| 35 | - . $contenu |
|
| 36 | - . "</div>\n" |
|
| 37 | - . fin_block() |
|
| 38 | - . fin_cadre(); |
|
| 29 | + $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | + |
|
| 31 | + return |
|
| 32 | + debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | + . debut_block_depliable($deplie, $ids) |
|
| 34 | + . "<div class='cadre_padding'>\n" |
|
| 35 | + . $contenu |
|
| 36 | + . "</div>\n" |
|
| 37 | + . fin_block() |
|
| 38 | + . fin_cadre(); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // https://code.spip.net/@block_parfois_visible |
| 42 | 42 | function block_parfois_visible($nom, $invite, $masque, $style = '', $visible = false) { |
| 43 | - return "\n" |
|
| 44 | - . bouton_block_depliable($invite, $visible, $nom) |
|
| 45 | - . debut_block_depliable($visible, $nom) |
|
| 46 | - . $masque |
|
| 47 | - . fin_block(); |
|
| 43 | + return "\n" |
|
| 44 | + . bouton_block_depliable($invite, $visible, $nom) |
|
| 45 | + . debut_block_depliable($visible, $nom) |
|
| 46 | + . $masque |
|
| 47 | + . fin_block(); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // https://code.spip.net/@debut_block_depliable |
| 51 | 51 | function debut_block_depliable($deplie, $id = '') { |
| 52 | - $class = ' blocdeplie'; |
|
| 53 | - // si on n'accepte pas js, ne pas fermer |
|
| 54 | - if (!$deplie) { |
|
| 55 | - $class = ' blocreplie'; |
|
| 56 | - } |
|
| 52 | + $class = ' blocdeplie'; |
|
| 53 | + // si on n'accepte pas js, ne pas fermer |
|
| 54 | + if (!$deplie) { |
|
| 55 | + $class = ' blocreplie'; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 58 | + return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // https://code.spip.net/@fin_block |
| 62 | 62 | function fin_block() { |
| 63 | - return "<div class='nettoyeur'></div>\n</div>"; |
|
| 63 | + return "<div class='nettoyeur'></div>\n</div>"; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // $texte : texte du bouton |
@@ -68,32 +68,32 @@ discard block |
||
| 68 | 68 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 69 | 69 | // https://code.spip.net/@bouton_block_depliable |
| 70 | 70 | function bouton_block_depliable($texte, $deplie, $ids = '') { |
| 71 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 72 | - |
|
| 73 | - $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 74 | - if (strlen($ids)) { |
|
| 75 | - $cible = explode(',', $ids); |
|
| 76 | - $cible = '#' . implode(',#', $cible); |
|
| 77 | - } else { |
|
| 78 | - $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 82 | - |
|
| 83 | - return "<$b " |
|
| 84 | - . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 85 | - . "class='titrem$class'" |
|
| 86 | - . (($deplie === -1) |
|
| 87 | - ? '' |
|
| 88 | - : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 89 | - ) |
|
| 90 | - . '>' |
|
| 91 | - // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 92 | - . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 93 | - . "$texte</$b>" |
|
| 94 | - . http_script(($deplie === 'incertain') |
|
| 95 | - ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 96 | - : ''); |
|
| 71 | + $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 72 | + |
|
| 73 | + $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 74 | + if (strlen($ids)) { |
|
| 75 | + $cible = explode(',', $ids); |
|
| 76 | + $cible = '#' . implode(',#', $cible); |
|
| 77 | + } else { |
|
| 78 | + $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 82 | + |
|
| 83 | + return "<$b " |
|
| 84 | + . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 85 | + . "class='titrem$class'" |
|
| 86 | + . (($deplie === -1) |
|
| 87 | + ? '' |
|
| 88 | + : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 89 | + ) |
|
| 90 | + . '>' |
|
| 91 | + // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 92 | + . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 93 | + . "$texte</$b>" |
|
| 94 | + . http_script(($deplie === 'incertain') |
|
| 95 | + ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 96 | + : ''); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // |
@@ -102,66 +102,66 @@ discard block |
||
| 102 | 102 | // https://code.spip.net/@verif_butineur |
| 103 | 103 | function verif_butineur() { |
| 104 | 104 | |
| 105 | - preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 106 | - $GLOBALS['browser_name'] = $match[1]; |
|
| 107 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 108 | - $GLOBALS['browser_description'] = $match[3]; |
|
| 109 | - $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 110 | - $GLOBALS['browser_barre'] = ''; |
|
| 111 | - |
|
| 112 | - if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 113 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 114 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 115 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 116 | - } else { |
|
| 117 | - if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 118 | - preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 119 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 120 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 121 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 122 | - } else { |
|
| 123 | - if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 124 | - preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 125 | - $GLOBALS['browser_name'] = 'MSIE'; |
|
| 126 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 127 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 128 | - } else { |
|
| 129 | - if ( |
|
| 130 | - preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 131 | - preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 132 | - ) { |
|
| 133 | - $GLOBALS['browser_name'] = 'Safari'; |
|
| 134 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 135 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 136 | - } else { |
|
| 137 | - if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 138 | - // Numero de version pour Mozilla "authentique" |
|
| 139 | - if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 140 | - $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 141 | - } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 142 | - else { |
|
| 143 | - if ( |
|
| 144 | - strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 145 | - $GLOBALS['browser_description'], |
|
| 146 | - 'KHTML' |
|
| 147 | - ) |
|
| 148 | - ) { |
|
| 149 | - $GLOBALS['browser_rev'] = 1.4; |
|
| 150 | - } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 151 | - else { |
|
| 152 | - $GLOBALS['browser_rev'] = 1.0; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if (!$GLOBALS['browser_name']) { |
|
| 163 | - $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 164 | - } |
|
| 105 | + preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 106 | + $GLOBALS['browser_name'] = $match[1]; |
|
| 107 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 108 | + $GLOBALS['browser_description'] = $match[3]; |
|
| 109 | + $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 110 | + $GLOBALS['browser_barre'] = ''; |
|
| 111 | + |
|
| 112 | + if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 113 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 114 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 115 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 116 | + } else { |
|
| 117 | + if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 118 | + preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 119 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 120 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 121 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 122 | + } else { |
|
| 123 | + if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 124 | + preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 125 | + $GLOBALS['browser_name'] = 'MSIE'; |
|
| 126 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 127 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 128 | + } else { |
|
| 129 | + if ( |
|
| 130 | + preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 131 | + preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 132 | + ) { |
|
| 133 | + $GLOBALS['browser_name'] = 'Safari'; |
|
| 134 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 135 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 136 | + } else { |
|
| 137 | + if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 138 | + // Numero de version pour Mozilla "authentique" |
|
| 139 | + if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 140 | + $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 141 | + } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 142 | + else { |
|
| 143 | + if ( |
|
| 144 | + strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 145 | + $GLOBALS['browser_description'], |
|
| 146 | + 'KHTML' |
|
| 147 | + ) |
|
| 148 | + ) { |
|
| 149 | + $GLOBALS['browser_rev'] = 1.4; |
|
| 150 | + } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 151 | + else { |
|
| 152 | + $GLOBALS['browser_rev'] = 1.0; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if (!$GLOBALS['browser_name']) { |
|
| 163 | + $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | verif_butineur(); |
@@ -16,10 +16,10 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Pipelines |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | if (test_espace_prive()) { |
| 22 | - include_spip('inc/pipelines_ecrire'); |
|
| 22 | + include_spip('inc/pipelines_ecrire'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -45,29 +45,29 @@ discard block |
||
| 45 | 45 | * @return string Contenu qui sera inséré dans le head HTML |
| 46 | 46 | **/ |
| 47 | 47 | function f_jQuery($texte) { |
| 48 | - $x = ''; |
|
| 49 | - $jquery_plugins = pipeline( |
|
| 50 | - 'jquery_plugins', |
|
| 51 | - [ |
|
| 52 | - 'javascript/jquery.js', |
|
| 53 | - 'javascript/jquery.form.js', |
|
| 54 | - 'javascript/jquery.autosave.js', |
|
| 55 | - 'javascript/jquery.placeholder-label.js', |
|
| 56 | - 'javascript/ajaxCallback.js', |
|
| 57 | - 'javascript/js.cookie.js', |
|
| 58 | - 'javascript/jquery.cookie.js' |
|
| 59 | - ] |
|
| 60 | - ); |
|
| 61 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 62 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 63 | - $script = timestamp($script); |
|
| 64 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 65 | - } |
|
| 66 | - } |
|
| 48 | + $x = ''; |
|
| 49 | + $jquery_plugins = pipeline( |
|
| 50 | + 'jquery_plugins', |
|
| 51 | + [ |
|
| 52 | + 'javascript/jquery.js', |
|
| 53 | + 'javascript/jquery.form.js', |
|
| 54 | + 'javascript/jquery.autosave.js', |
|
| 55 | + 'javascript/jquery.placeholder-label.js', |
|
| 56 | + 'javascript/ajaxCallback.js', |
|
| 57 | + 'javascript/js.cookie.js', |
|
| 58 | + 'javascript/jquery.cookie.js' |
|
| 59 | + ] |
|
| 60 | + ); |
|
| 61 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 62 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 63 | + $script = timestamp($script); |
|
| 64 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $texte = $x . $texte; |
|
| 68 | + $texte = $x . $texte; |
|
| 69 | 69 | |
| 70 | - return $texte; |
|
| 70 | + return $texte; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | |
@@ -86,28 +86,28 @@ discard block |
||
| 86 | 86 | * @return string Contenu de la page envoyée au navigateur |
| 87 | 87 | **/ |
| 88 | 88 | function f_surligne($texte) { |
| 89 | - if (!$GLOBALS['html']) { |
|
| 90 | - return $texte; |
|
| 91 | - } |
|
| 92 | - $rech = _request('var_recherche'); |
|
| 93 | - if ( |
|
| 94 | - !$rech |
|
| 95 | - and (!defined('_SURLIGNE_RECHERCHE_REFERERS') |
|
| 96 | - or !_SURLIGNE_RECHERCHE_REFERERS |
|
| 97 | - or !isset($_SERVER['HTTP_REFERER'])) |
|
| 98 | - ) { |
|
| 99 | - return $texte; |
|
| 100 | - } |
|
| 101 | - include_spip('inc/surligne'); |
|
| 89 | + if (!$GLOBALS['html']) { |
|
| 90 | + return $texte; |
|
| 91 | + } |
|
| 92 | + $rech = _request('var_recherche'); |
|
| 93 | + if ( |
|
| 94 | + !$rech |
|
| 95 | + and (!defined('_SURLIGNE_RECHERCHE_REFERERS') |
|
| 96 | + or !_SURLIGNE_RECHERCHE_REFERERS |
|
| 97 | + or !isset($_SERVER['HTTP_REFERER'])) |
|
| 98 | + ) { |
|
| 99 | + return $texte; |
|
| 100 | + } |
|
| 101 | + include_spip('inc/surligne'); |
|
| 102 | 102 | |
| 103 | - if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 104 | - $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']); |
|
| 105 | - } |
|
| 106 | - if ($rech) { |
|
| 107 | - $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech); |
|
| 108 | - } |
|
| 103 | + if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 104 | + $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']); |
|
| 105 | + } |
|
| 106 | + if ($rech) { |
|
| 107 | + $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - return surligner_mots($texte, $rech); |
|
| 110 | + return surligner_mots($texte, $rech); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -124,33 +124,33 @@ discard block |
||
| 124 | 124 | * @return string Contenu de la page envoyée au navigateur |
| 125 | 125 | **/ |
| 126 | 126 | function f_tidy($texte) { |
| 127 | - /** |
|
| 128 | - * Indentation à faire ? |
|
| 129 | - * |
|
| 130 | - * - true : actif. |
|
| 131 | - * - false par défaut. |
|
| 132 | - */ |
|
| 127 | + /** |
|
| 128 | + * Indentation à faire ? |
|
| 129 | + * |
|
| 130 | + * - true : actif. |
|
| 131 | + * - false par défaut. |
|
| 132 | + */ |
|
| 133 | 133 | |
| 134 | - if ( |
|
| 135 | - $GLOBALS['xhtml'] # tidy demande |
|
| 136 | - and $GLOBALS['html'] # verifie que la page avait l'entete text/html |
|
| 137 | - and strlen($texte) |
|
| 138 | - and !headers_sent() |
|
| 139 | - ) { |
|
| 140 | - # Compatibilite ascendante |
|
| 141 | - if (!is_string($GLOBALS['xhtml'])) { |
|
| 142 | - $GLOBALS['xhtml'] = 'tidy'; |
|
| 143 | - } |
|
| 134 | + if ( |
|
| 135 | + $GLOBALS['xhtml'] # tidy demande |
|
| 136 | + and $GLOBALS['html'] # verifie que la page avait l'entete text/html |
|
| 137 | + and strlen($texte) |
|
| 138 | + and !headers_sent() |
|
| 139 | + ) { |
|
| 140 | + # Compatibilite ascendante |
|
| 141 | + if (!is_string($GLOBALS['xhtml'])) { |
|
| 142 | + $GLOBALS['xhtml'] = 'tidy'; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 146 | - spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 147 | - $f = charger_fonction('sax', 'xml'); |
|
| 148 | - } |
|
| 145 | + if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 146 | + spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 147 | + $f = charger_fonction('sax', 'xml'); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - return $f($texte); |
|
| 151 | - } |
|
| 150 | + return $f($texte); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $texte; |
|
| 153 | + return $texte; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -169,21 +169,21 @@ discard block |
||
| 169 | 169 | * @return string Contenu de la page envoyée au navigateur |
| 170 | 170 | **/ |
| 171 | 171 | function f_insert_head($texte) { |
| 172 | - if (!$GLOBALS['html']) { |
|
| 173 | - return $texte; |
|
| 174 | - } |
|
| 175 | - include_spip('public/admin'); // pour strripos |
|
| 172 | + if (!$GLOBALS['html']) { |
|
| 173 | + return $texte; |
|
| 174 | + } |
|
| 175 | + include_spip('public/admin'); // pour strripos |
|
| 176 | 176 | |
| 177 | - ($pos = stripos($texte, '</head>')) |
|
| 178 | - || ($pos = stripos($texte, '<body>')) |
|
| 179 | - || ($pos = 0); |
|
| 177 | + ($pos = stripos($texte, '</head>')) |
|
| 178 | + || ($pos = stripos($texte, '<body>')) |
|
| 179 | + || ($pos = 0); |
|
| 180 | 180 | |
| 181 | - if (false === strpos(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 182 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 183 | - $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 184 | - } |
|
| 181 | + if (false === strpos(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 182 | + $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 183 | + $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - return $texte; |
|
| 186 | + return $texte; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | |
@@ -199,34 +199,34 @@ discard block |
||
| 199 | 199 | * @return string Contenu de la page envoyée au navigateur |
| 200 | 200 | **/ |
| 201 | 201 | function f_admin($texte) { |
| 202 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) { |
|
| 203 | - include_spip('inc/filtres'); // pour http_img_pack |
|
| 204 | - $x = "<div class='spip-previsu' " |
|
| 205 | - . http_style_background('preview-32.png', '', 32) |
|
| 206 | - . '>' |
|
| 207 | - . _T('previsualisation') |
|
| 208 | - . '</div>'; |
|
| 209 | - if (!$pos = stripos($texte, '</body>')) { |
|
| 210 | - $pos = strlen($texte); |
|
| 211 | - } |
|
| 212 | - $texte = substr_replace($texte, $x, $pos, 0); |
|
| 213 | - // pas de preview en fenetre enfant |
|
| 214 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 215 | - if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) { |
|
| 216 | - $pos = -1; |
|
| 217 | - } |
|
| 218 | - $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 219 | - } |
|
| 202 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) { |
|
| 203 | + include_spip('inc/filtres'); // pour http_img_pack |
|
| 204 | + $x = "<div class='spip-previsu' " |
|
| 205 | + . http_style_background('preview-32.png', '', 32) |
|
| 206 | + . '>' |
|
| 207 | + . _T('previsualisation') |
|
| 208 | + . '</div>'; |
|
| 209 | + if (!$pos = stripos($texte, '</body>')) { |
|
| 210 | + $pos = strlen($texte); |
|
| 211 | + } |
|
| 212 | + $texte = substr_replace($texte, $x, $pos, 0); |
|
| 213 | + // pas de preview en fenetre enfant |
|
| 214 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 215 | + if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) { |
|
| 216 | + $pos = -1; |
|
| 217 | + } |
|
| 218 | + $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) { |
|
| 222 | - include_spip('public/admin'); |
|
| 223 | - $texte = affiche_boutons_admin($texte); |
|
| 224 | - } |
|
| 225 | - if (_request('var_mode') == 'noajax') { |
|
| 226 | - $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 227 | - } |
|
| 221 | + if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) { |
|
| 222 | + include_spip('public/admin'); |
|
| 223 | + $texte = affiche_boutons_admin($texte); |
|
| 224 | + } |
|
| 225 | + if (_request('var_mode') == 'noajax') { |
|
| 226 | + $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return $texte; |
|
| 229 | + return $texte; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -244,11 +244,11 @@ discard block |
||
| 244 | 244 | * @return array $flux Description et contenu de l'inclusion |
| 245 | 245 | **/ |
| 246 | 246 | function f_recuperer_fond($flux) { |
| 247 | - if (!test_espace_prive()) { |
|
| 248 | - return $flux; |
|
| 249 | - } |
|
| 247 | + if (!test_espace_prive()) { |
|
| 248 | + return $flux; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - return f_afficher_blocs_ecrire($flux); |
|
| 251 | + return f_afficher_blocs_ecrire($flux); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -262,30 +262,30 @@ discard block |
||
| 262 | 262 | * @return string Contenu de la page envoyée au navigateur |
| 263 | 263 | */ |
| 264 | 264 | function f_queue($texte) { |
| 265 | - // eviter une inclusion si rien a faire |
|
| 266 | - if ( |
|
| 267 | - _request('action') == 'cron' |
|
| 268 | - or queue_sleep_time_to_next_job() > 0 |
|
| 269 | - or defined('_DEBUG_BLOCK_QUEUE') |
|
| 270 | - ) { |
|
| 271 | - return $texte; |
|
| 272 | - } |
|
| 265 | + // eviter une inclusion si rien a faire |
|
| 266 | + if ( |
|
| 267 | + _request('action') == 'cron' |
|
| 268 | + or queue_sleep_time_to_next_job() > 0 |
|
| 269 | + or defined('_DEBUG_BLOCK_QUEUE') |
|
| 270 | + ) { |
|
| 271 | + return $texte; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - include_spip('inc/queue'); |
|
| 275 | - $code = queue_affichage_cron(); |
|
| 274 | + include_spip('inc/queue'); |
|
| 275 | + $code = queue_affichage_cron(); |
|
| 276 | 276 | |
| 277 | - // si rien a afficher |
|
| 278 | - // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 279 | - if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) { |
|
| 280 | - return $texte; |
|
| 281 | - } |
|
| 277 | + // si rien a afficher |
|
| 278 | + // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 279 | + if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) { |
|
| 280 | + return $texte; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 284 | - if (($p = strpos($texte, '</body>')) !== false) { |
|
| 285 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 286 | - } else { |
|
| 287 | - $texte .= $code; |
|
| 288 | - } |
|
| 283 | + // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 284 | + if (($p = strpos($texte, '</body>')) !== false) { |
|
| 285 | + $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 286 | + } else { |
|
| 287 | + $texte .= $code; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - return $texte; |
|
| 290 | + return $texte; |
|
| 291 | 291 | } |
@@ -11,298 +11,298 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | // methodes sql |
| 19 | 19 | function inc_recherche_to_array_dist($recherche, $options = []) { |
| 20 | 20 | |
| 21 | - // options par defaut |
|
| 22 | - $options = array_merge( |
|
| 23 | - [ |
|
| 24 | - 'score' => true, |
|
| 25 | - 'champs' => false, |
|
| 26 | - 'toutvoir' => false, |
|
| 27 | - 'matches' => false, |
|
| 28 | - 'jointures' => false |
|
| 29 | - ], |
|
| 30 | - $options |
|
| 31 | - ); |
|
| 21 | + // options par defaut |
|
| 22 | + $options = array_merge( |
|
| 23 | + [ |
|
| 24 | + 'score' => true, |
|
| 25 | + 'champs' => false, |
|
| 26 | + 'toutvoir' => false, |
|
| 27 | + 'matches' => false, |
|
| 28 | + 'jointures' => false |
|
| 29 | + ], |
|
| 30 | + $options |
|
| 31 | + ); |
|
| 32 | 32 | |
| 33 | - include_spip('inc/rechercher'); |
|
| 34 | - include_spip('inc/autoriser'); |
|
| 33 | + include_spip('inc/rechercher'); |
|
| 34 | + include_spip('inc/autoriser'); |
|
| 35 | 35 | |
| 36 | - $requete = [ |
|
| 37 | - 'SELECT' => [], |
|
| 38 | - 'FROM' => [], |
|
| 39 | - 'WHERE' => [], |
|
| 40 | - 'GROUPBY' => [], |
|
| 41 | - 'ORDERBY' => [], |
|
| 42 | - 'LIMIT' => '', |
|
| 43 | - 'HAVING' => [] |
|
| 44 | - ]; |
|
| 36 | + $requete = [ |
|
| 37 | + 'SELECT' => [], |
|
| 38 | + 'FROM' => [], |
|
| 39 | + 'WHERE' => [], |
|
| 40 | + 'GROUPBY' => [], |
|
| 41 | + 'ORDERBY' => [], |
|
| 42 | + 'LIMIT' => '', |
|
| 43 | + 'HAVING' => [] |
|
| 44 | + ]; |
|
| 45 | 45 | |
| 46 | - $table = sinon($options['table'], 'article'); |
|
| 47 | - if ($options['champs']) { |
|
| 48 | - $champs = $options['champs']; |
|
| 49 | - } else { |
|
| 50 | - $l = liste_des_champs(); |
|
| 51 | - $champs = $l['article']; |
|
| 52 | - } |
|
| 53 | - $serveur = $options['serveur']; |
|
| 46 | + $table = sinon($options['table'], 'article'); |
|
| 47 | + if ($options['champs']) { |
|
| 48 | + $champs = $options['champs']; |
|
| 49 | + } else { |
|
| 50 | + $l = liste_des_champs(); |
|
| 51 | + $champs = $l['article']; |
|
| 52 | + } |
|
| 53 | + $serveur = $options['serveur']; |
|
| 54 | 54 | |
| 55 | - list($methode, $q, $preg) = expression_recherche($recherche, $options); |
|
| 55 | + list($methode, $q, $preg) = expression_recherche($recherche, $options); |
|
| 56 | 56 | |
| 57 | - $jointures = $options['jointures'] |
|
| 58 | - ? liste_des_jointures() |
|
| 59 | - : []; |
|
| 57 | + $jointures = $options['jointures'] |
|
| 58 | + ? liste_des_jointures() |
|
| 59 | + : []; |
|
| 60 | 60 | |
| 61 | - $_id_table = id_table_objet($table); |
|
| 61 | + $_id_table = id_table_objet($table); |
|
| 62 | 62 | |
| 63 | - // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | - // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | - if (strpos($_id_table, ',') !== false) { |
|
| 66 | - $_id_table = explode(',', $_id_table); |
|
| 67 | - $_id_table = reset($_id_table); |
|
| 68 | - } |
|
| 63 | + // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | + // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | + if (strpos($_id_table, ',') !== false) { |
|
| 66 | + $_id_table = explode(',', $_id_table); |
|
| 67 | + $_id_table = reset($_id_table); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | - $a = []; |
|
| 72 | - // Recherche fulltext |
|
| 73 | - foreach ($champs as $champ => $poids) { |
|
| 74 | - if (is_array($champ)) { |
|
| 75 | - spip_log('requetes imbriquees interdites'); |
|
| 76 | - } else { |
|
| 77 | - if (strpos($champ, '.') === false) { |
|
| 78 | - $champ = "t.$champ"; |
|
| 79 | - } |
|
| 80 | - $requete['SELECT'][] = $champ; |
|
| 81 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - if ($a) { |
|
| 85 | - $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | - } |
|
| 87 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 70 | + $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | + $a = []; |
|
| 72 | + // Recherche fulltext |
|
| 73 | + foreach ($champs as $champ => $poids) { |
|
| 74 | + if (is_array($champ)) { |
|
| 75 | + spip_log('requetes imbriquees interdites'); |
|
| 76 | + } else { |
|
| 77 | + if (strpos($champ, '.') === false) { |
|
| 78 | + $champ = "t.$champ"; |
|
| 79 | + } |
|
| 80 | + $requete['SELECT'][] = $champ; |
|
| 81 | + $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + if ($a) { |
|
| 85 | + $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | + } |
|
| 87 | + $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 88 | 88 | |
| 89 | - $results = []; |
|
| 89 | + $results = []; |
|
| 90 | 90 | |
| 91 | - $s = sql_select( |
|
| 92 | - $requete['SELECT'], |
|
| 93 | - $requete['FROM'], |
|
| 94 | - $requete['WHERE'], |
|
| 95 | - implode(' ', $requete['GROUPBY']), |
|
| 96 | - $requete['ORDERBY'], |
|
| 97 | - $requete['LIMIT'], |
|
| 98 | - $requete['HAVING'], |
|
| 99 | - $serveur |
|
| 100 | - ); |
|
| 91 | + $s = sql_select( |
|
| 92 | + $requete['SELECT'], |
|
| 93 | + $requete['FROM'], |
|
| 94 | + $requete['WHERE'], |
|
| 95 | + implode(' ', $requete['GROUPBY']), |
|
| 96 | + $requete['ORDERBY'], |
|
| 97 | + $requete['LIMIT'], |
|
| 98 | + $requete['HAVING'], |
|
| 99 | + $serveur |
|
| 100 | + ); |
|
| 101 | 101 | |
| 102 | - while ( |
|
| 103 | - $t = sql_fetch($s, $serveur) |
|
| 104 | - and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | - ) { |
|
| 106 | - $id = intval($t[$_id_table]); |
|
| 102 | + while ( |
|
| 103 | + $t = sql_fetch($s, $serveur) |
|
| 104 | + and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | + ) { |
|
| 106 | + $id = intval($t[$_id_table]); |
|
| 107 | 107 | |
| 108 | - if ( |
|
| 109 | - $options['toutvoir'] |
|
| 110 | - or autoriser('voir', $table, $id) |
|
| 111 | - ) { |
|
| 112 | - // indiquer les champs concernes |
|
| 113 | - $champs_vus = []; |
|
| 114 | - $score = 0; |
|
| 115 | - $matches = []; |
|
| 108 | + if ( |
|
| 109 | + $options['toutvoir'] |
|
| 110 | + or autoriser('voir', $table, $id) |
|
| 111 | + ) { |
|
| 112 | + // indiquer les champs concernes |
|
| 113 | + $champs_vus = []; |
|
| 114 | + $score = 0; |
|
| 115 | + $matches = []; |
|
| 116 | 116 | |
| 117 | - $vu = false; |
|
| 118 | - foreach ($champs as $champ => $poids) { |
|
| 119 | - $champ = explode('.', $champ); |
|
| 120 | - $champ = end($champ); |
|
| 121 | - // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | - $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | - if ( |
|
| 124 | - $n = |
|
| 125 | - ($options['score'] || $options['matches']) |
|
| 126 | - ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | - : preg_match($preg, $value) |
|
| 128 | - ) { |
|
| 129 | - $vu = true; |
|
| 117 | + $vu = false; |
|
| 118 | + foreach ($champs as $champ => $poids) { |
|
| 119 | + $champ = explode('.', $champ); |
|
| 120 | + $champ = end($champ); |
|
| 121 | + // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | + $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | + if ( |
|
| 124 | + $n = |
|
| 125 | + ($options['score'] || $options['matches']) |
|
| 126 | + ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | + : preg_match($preg, $value) |
|
| 128 | + ) { |
|
| 129 | + $vu = true; |
|
| 130 | 130 | |
| 131 | - if ($options['champs']) { |
|
| 132 | - $champs_vus[$champ] = $t[$champ]; |
|
| 133 | - } |
|
| 134 | - if ($options['score']) { |
|
| 135 | - // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | - $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | - } |
|
| 131 | + if ($options['champs']) { |
|
| 132 | + $champs_vus[$champ] = $t[$champ]; |
|
| 133 | + } |
|
| 134 | + if ($options['score']) { |
|
| 135 | + // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | + $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if ($options['matches']) { |
|
| 140 | - $matches[$champ] = $regs; |
|
| 141 | - } |
|
| 139 | + if ($options['matches']) { |
|
| 140 | + $matches[$champ] = $regs; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if ( |
|
| 144 | - !$options['champs'] |
|
| 145 | - and !$options['score'] |
|
| 146 | - and !$options['matches'] |
|
| 147 | - ) { |
|
| 148 | - break; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 143 | + if ( |
|
| 144 | + !$options['champs'] |
|
| 145 | + and !$options['score'] |
|
| 146 | + and !$options['matches'] |
|
| 147 | + ) { |
|
| 148 | + break; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - if ($vu) { |
|
| 154 | - if (!isset($results)) { |
|
| 155 | - $results = []; |
|
| 156 | - } |
|
| 157 | - $results[$id] = []; |
|
| 158 | - if ($champs_vus) { |
|
| 159 | - $results[$id]['champs'] = $champs_vus; |
|
| 160 | - } |
|
| 161 | - if ($score) { |
|
| 162 | - $results[$id]['score'] = $score; |
|
| 163 | - } |
|
| 164 | - if ($matches) { |
|
| 165 | - $results[$id]['matches'] = $matches; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 153 | + if ($vu) { |
|
| 154 | + if (!isset($results)) { |
|
| 155 | + $results = []; |
|
| 156 | + } |
|
| 157 | + $results[$id] = []; |
|
| 158 | + if ($champs_vus) { |
|
| 159 | + $results[$id]['champs'] = $champs_vus; |
|
| 160 | + } |
|
| 161 | + if ($score) { |
|
| 162 | + $results[$id]['score'] = $score; |
|
| 163 | + } |
|
| 164 | + if ($matches) { |
|
| 165 | + $results[$id]['matches'] = $matches; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - // Gerer les donnees associees |
|
| 173 | - // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | - // on ne sait passer que par table de laison en 1 coup |
|
| 175 | - if ( |
|
| 176 | - isset($jointures[$table]) |
|
| 177 | - and $joints = recherche_en_base( |
|
| 178 | - $recherche, |
|
| 179 | - $jointures[$table], |
|
| 180 | - array_merge($options, ['jointures' => false]) |
|
| 181 | - ) |
|
| 182 | - ) { |
|
| 183 | - include_spip('action/editer_liens'); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $cle_depart = id_table_objet($table); |
|
| 186 | - $table_depart = table_objet($table, $serveur); |
|
| 187 | - $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | - $depart_associable = objet_associable($table); |
|
| 189 | - foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | - // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | - if ( |
|
| 192 | - !( |
|
| 193 | - $rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true) |
|
| 194 | - or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true) |
|
| 195 | - or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true) |
|
| 196 | - ) |
|
| 197 | - ) { |
|
| 198 | - $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | - $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | - $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | - // cas simple : $cle_depart dans la table_liee |
|
| 202 | - if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | - $s = sql_select( |
|
| 204 | - "$cle_depart, $cle_arrivee", |
|
| 205 | - $desc_arrivee['table_sql'], |
|
| 206 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | - '', |
|
| 208 | - '', |
|
| 209 | - '', |
|
| 210 | - '', |
|
| 211 | - $serveur |
|
| 212 | - ); |
|
| 213 | - } // cas simple : $cle_arrivee dans la table |
|
| 214 | - elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | - $s = sql_select( |
|
| 216 | - "$cle_depart, $cle_arrivee", |
|
| 217 | - $desc_depart['table_sql'], |
|
| 218 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | - '', |
|
| 220 | - '', |
|
| 221 | - '', |
|
| 222 | - '', |
|
| 223 | - $serveur |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - // sinon cherchons une table de liaison |
|
| 227 | - // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | - elseif ($l = objet_associable($table_liee)) { |
|
| 229 | - list($primary, $table_liens) = $l; |
|
| 230 | - $s = sql_select( |
|
| 231 | - "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | - $table_liens, |
|
| 233 | - ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | - '', |
|
| 235 | - '', |
|
| 236 | - '', |
|
| 237 | - '', |
|
| 238 | - $serveur |
|
| 239 | - ); |
|
| 240 | - } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | - elseif ($l = $depart_associable) { |
|
| 242 | - list($primary, $table_liens) = $l; |
|
| 243 | - $s = sql_select( |
|
| 244 | - "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | - $table_liens, |
|
| 246 | - ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | - '', |
|
| 248 | - '', |
|
| 249 | - '', |
|
| 250 | - '', |
|
| 251 | - $serveur |
|
| 252 | - ); |
|
| 253 | - } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | - elseif ( |
|
| 255 | - $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | - or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | - ) { |
|
| 258 | - $s = sql_select( |
|
| 259 | - "$cle_depart,$cle_arrivee", |
|
| 260 | - $t['table_sql'], |
|
| 261 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | - '', |
|
| 263 | - '', |
|
| 264 | - '', |
|
| 265 | - '', |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } else { |
|
| 270 | - list($cle_depart, $cle_arrivee, $s) = $rechercher_joints( |
|
| 271 | - $table, |
|
| 272 | - $table_liee, |
|
| 273 | - array_keys($ids_trouves), |
|
| 274 | - $serveur |
|
| 275 | - ); |
|
| 276 | - } |
|
| 172 | + // Gerer les donnees associees |
|
| 173 | + // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | + // on ne sait passer que par table de laison en 1 coup |
|
| 175 | + if ( |
|
| 176 | + isset($jointures[$table]) |
|
| 177 | + and $joints = recherche_en_base( |
|
| 178 | + $recherche, |
|
| 179 | + $jointures[$table], |
|
| 180 | + array_merge($options, ['jointures' => false]) |
|
| 181 | + ) |
|
| 182 | + ) { |
|
| 183 | + include_spip('action/editer_liens'); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $cle_depart = id_table_objet($table); |
|
| 186 | + $table_depart = table_objet($table, $serveur); |
|
| 187 | + $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | + $depart_associable = objet_associable($table); |
|
| 189 | + foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | + // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | + if ( |
|
| 192 | + !( |
|
| 193 | + $rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true) |
|
| 194 | + or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true) |
|
| 195 | + or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true) |
|
| 196 | + ) |
|
| 197 | + ) { |
|
| 198 | + $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | + $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | + $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | + // cas simple : $cle_depart dans la table_liee |
|
| 202 | + if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | + $s = sql_select( |
|
| 204 | + "$cle_depart, $cle_arrivee", |
|
| 205 | + $desc_arrivee['table_sql'], |
|
| 206 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | + '', |
|
| 208 | + '', |
|
| 209 | + '', |
|
| 210 | + '', |
|
| 211 | + $serveur |
|
| 212 | + ); |
|
| 213 | + } // cas simple : $cle_arrivee dans la table |
|
| 214 | + elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | + $s = sql_select( |
|
| 216 | + "$cle_depart, $cle_arrivee", |
|
| 217 | + $desc_depart['table_sql'], |
|
| 218 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | + '', |
|
| 220 | + '', |
|
| 221 | + '', |
|
| 222 | + '', |
|
| 223 | + $serveur |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + // sinon cherchons une table de liaison |
|
| 227 | + // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | + elseif ($l = objet_associable($table_liee)) { |
|
| 229 | + list($primary, $table_liens) = $l; |
|
| 230 | + $s = sql_select( |
|
| 231 | + "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | + $table_liens, |
|
| 233 | + ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | + '', |
|
| 235 | + '', |
|
| 236 | + '', |
|
| 237 | + '', |
|
| 238 | + $serveur |
|
| 239 | + ); |
|
| 240 | + } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | + elseif ($l = $depart_associable) { |
|
| 242 | + list($primary, $table_liens) = $l; |
|
| 243 | + $s = sql_select( |
|
| 244 | + "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | + $table_liens, |
|
| 246 | + ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | + '', |
|
| 248 | + '', |
|
| 249 | + '', |
|
| 250 | + '', |
|
| 251 | + $serveur |
|
| 252 | + ); |
|
| 253 | + } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | + elseif ( |
|
| 255 | + $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | + or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | + ) { |
|
| 258 | + $s = sql_select( |
|
| 259 | + "$cle_depart,$cle_arrivee", |
|
| 260 | + $t['table_sql'], |
|
| 261 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | + '', |
|
| 263 | + '', |
|
| 264 | + '', |
|
| 265 | + '', |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } else { |
|
| 270 | + list($cle_depart, $cle_arrivee, $s) = $rechercher_joints( |
|
| 271 | + $table, |
|
| 272 | + $table_liee, |
|
| 273 | + array_keys($ids_trouves), |
|
| 274 | + $serveur |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | - $id = $t[$cle_depart]; |
|
| 280 | - $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | - if (!isset($results)) { |
|
| 282 | - $results = []; |
|
| 283 | - } |
|
| 284 | - if (!isset($results[$id])) { |
|
| 285 | - $results[$id] = []; |
|
| 286 | - } |
|
| 287 | - if (isset($joint['score']) and $joint['score']) { |
|
| 288 | - if (!isset($results[$id]['score'])) { |
|
| 289 | - $results[$id]['score'] = 0; |
|
| 290 | - } |
|
| 291 | - $results[$id]['score'] += $joint['score']; |
|
| 292 | - } |
|
| 293 | - if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | - foreach ($joint['champs'] as $c => $val) { |
|
| 295 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | - foreach ($joint['matches'] as $c => $val) { |
|
| 300 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 278 | + while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | + $id = $t[$cle_depart]; |
|
| 280 | + $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | + if (!isset($results)) { |
|
| 282 | + $results = []; |
|
| 283 | + } |
|
| 284 | + if (!isset($results[$id])) { |
|
| 285 | + $results[$id] = []; |
|
| 286 | + } |
|
| 287 | + if (isset($joint['score']) and $joint['score']) { |
|
| 288 | + if (!isset($results[$id]['score'])) { |
|
| 289 | + $results[$id]['score'] = 0; |
|
| 290 | + } |
|
| 291 | + $results[$id]['score'] += $joint['score']; |
|
| 292 | + } |
|
| 293 | + if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | + foreach ($joint['champs'] as $c => $val) { |
|
| 295 | + $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | + foreach ($joint['matches'] as $c => $val) { |
|
| 300 | + $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - return $results; |
|
| 307 | + return $results; |
|
| 308 | 308 | } |