Changeset 93629 in spip-zone
- Timestamp:
- Dec 13, 2015, 11:58:52 AM (5 years ago)
- Location:
- _core_/plugins/urls_etendues
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
_core_/plugins/urls_etendues/action/editer_url.php
r93092 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } 14 16 15 17 function action_editer_url_dist() { … … 22 24 23 25 24 function url_nettoyer($titre, $longueur_maxi, $longueur_min = 0, $separateur = '-', $filtre = '') {26 function url_nettoyer($titre, $longueur_maxi, $longueur_min = 0, $separateur = '-', $filtre = '') { 25 27 26 28 $titre = supprimer_tags(supprimer_numero(extraire_multi($titre))); 27 29 $url = translitteration(corriger_caracteres($titre)); 28 30 29 if ($filtre) 31 if ($filtre) { 30 32 $url = $filtre($url); 33 } 31 34 32 35 // on va convertir tous les caracteres de ponctuation et espaces … … 46 49 47 50 // S'il reste trop peu, renvoyer vide 48 if (strlen($url) < $longueur_min) 51 if (strlen($url) < $longueur_min) { 49 52 return ''; 53 } 50 54 51 55 // Sinon couper les mots et les relier par des $separateur … … 53 57 $url = ''; 54 58 foreach ($mots as $mot) { 55 if (!strlen($mot)) continue; 56 $url2 = $url.$separateur.$mot; 59 if (!strlen($mot)) { 60 continue; 61 } 62 $url2 = $url . $separateur . $mot; 57 63 58 64 // Si on depasse $longueur_maxi caracteres, s'arreter … … 70 76 $url = rawurldecode($url); 71 77 72 if (strlen($url) < $longueur_min) 78 if (strlen($url) < $longueur_min) { 73 79 return ''; 80 } 81 74 82 return $url; 75 83 } 76 84 77 function url_insert(&$set, $confirmer, $separateur) {85 function url_insert(&$set, $confirmer, $separateur) { 78 86 $has_parent = true; 79 87 # assurer la coherence des champs techniques si non fournis 80 if (!isset($set['id_parent'])) {88 if (!isset($set['id_parent'])) { 81 89 $has_parent = false; 82 90 $set['id_parent'] = 0; 83 91 } 84 if (!isset($set['segments'])) 85 $set['segments'] = count(explode('/',$set['url'])); 92 if (!isset($set['segments'])) { 93 $set['segments'] = count(explode('/', $set['url'])); 94 } 86 95 $perma = false; 87 if (isset($set['perma']) AND $set['perma']) {96 if (isset($set['perma']) AND $set['perma']) { 88 97 unset($set['perma']); 89 98 $perma = true; … … 92 101 93 102 # le separateur ne peut pas contenir de / 94 if (strpos($separateur, '/')!==false)103 if (strpos($separateur, '/') !== false) { 95 104 $separateur = "-"; 105 } 96 106 97 107 // Si l'insertion echoue, c'est une violation d'unicite. 98 $where_urllike = 'url LIKE ' .url_sql_quote_like($set['url'])." AND NOT(type=".sql_quote($set['type'])." AND id_objet=".intval($set['id_objet']).")";99 $where_thisurl = $where_urllike .($has_parent?" AND id_parent=".intval($set['id_parent']):"");108 $where_urllike = 'url LIKE ' . url_sql_quote_like($set['url']) . " AND NOT(type=" . sql_quote($set['type']) . " AND id_objet=" . intval($set['id_objet']) . ")"; 109 $where_thisurl = $where_urllike . ($has_parent ? " AND id_parent=" . intval($set['id_parent']) : ""); 100 110 if ( 101 111 // si pas de parent defini, il faut que cette url soit unique, independamment de id_parent 102 112 // il faut utiliser un LIKE pour etre case unsensitive en sqlite 103 (!$has_parent AND sql_countsel("spip_urls",$where_urllike)) 104 OR @sql_insertq('spip_urls', $set) <= 0) { 113 (!$has_parent AND sql_countsel("spip_urls", $where_urllike)) 114 OR @sql_insertq('spip_urls', $set) <= 0 115 ) { 105 116 106 117 // On veut chiper une ancienne adresse ou prendre celle d'un repertoire deja present? 107 118 if ( 108 (!is_dir(_DIR_RACINE .$set['url']) AND !file_exists(_DIR_RACINE.$set['url']))119 (!is_dir(_DIR_RACINE . $set['url']) AND !file_exists(_DIR_RACINE . $set['url'])) 109 120 // un vieux url 110 AND $vieux = sql_fetsel('*', 'spip_urls', $where_thisurl, '','perma DESC')121 AND $vieux = sql_fetsel('*', 'spip_urls', $where_thisurl, '', 'perma DESC') 111 122 // qui n'est pas permanente 112 123 AND !$vieux['perma'] 113 114 115 'type='.sql_quote($vieux['type']).' AND id_objet='.sql_quote($vieux['id_objet'])116 .' AND url<>'.sql_quote($set['url'])117 .' AND date>'.sql_quote($vieux['date']), '', 'date DESC', 1)118 124 // et dont l'objet a une url plus recente 125 AND $courant = sql_fetsel('*', 'spip_urls', 126 'type=' . sql_quote($vieux['type']) . ' AND id_objet=' . sql_quote($vieux['id_objet']) 127 . ' AND url<>' . sql_quote($set['url']) 128 . ' AND date>' . sql_quote($vieux['date']), '', 'date DESC', 1) 129 ) { 119 130 if ($confirmer AND !_request('ok2')) { 120 die ("Vous voulez chiper l'URL de l'objet " .$courant['type']." "121 . $courant['id_objet'] ." qui a maintenant l'url "131 die ("Vous voulez chiper l'URL de l'objet " . $courant['type'] . " " 132 . $courant['id_objet'] . " qui a maintenant l'url " 122 133 . $courant['url']); 123 134 } 124 $where_thisurl = "url=" .sql_quote($vieux['url'])." AND id_parent=".intval($vieux['id_parent']);135 $where_thisurl = "url=" . sql_quote($vieux['url']) . " AND id_parent=" . intval($vieux['id_parent']); 125 136 // si oui on le chipe 126 137 sql_updateq('spip_urls', $set, $where_thisurl); 127 138 sql_updateq('spip_urls', array('date' => date('Y-m-d H:i:s')), $where_thisurl); 128 spip_log("reattribue url ".$vieux['url'] 129 ." de ".$vieux['type']."#".$vieux['id_objet']." (parent ".$vieux['id_parent'].")" 130 ." A ".$set['type']."#".$set['id_objet']." (parent ".$set['id_parent'].")","urls"._LOG_INFO_IMPORTANTE); 131 } 132 133 // Sinon 139 spip_log("reattribue url " . $vieux['url'] 140 . " de " . $vieux['type'] . "#" . $vieux['id_objet'] . " (parent " . $vieux['id_parent'] . ")" 141 . " A " . $set['type'] . "#" . $set['id_objet'] . " (parent " . $set['id_parent'] . ")", 142 "urls" . _LOG_INFO_IMPORTANTE); 143 } // Sinon 134 144 else { 135 145 … … 140 150 // il peut etre du a un changement de casse de l'url simplement 141 151 // pour ce cas, on reecrit systematiquement l'url en plus d'actualiser la date 142 $where = "type=" .sql_quote($set['type'])143 ." AND id_objet=".intval($set['id_objet'])144 ." AND id_parent=".intval($set['id_parent'])145 ." AND url LIKE ";152 $where = "type=" . sql_quote($set['type']) 153 . " AND id_objet=" . intval($set['id_objet']) 154 . " AND id_parent=" . intval($set['id_parent']) 155 . " AND url LIKE "; 146 156 if ( 147 !is_dir(_DIR_RACINE.$set['url']) AND !file_exists(_DIR_RACINE.$set['url']) 148 AND sql_countsel('spip_urls', $where .url_sql_quote_like($set['url']))) { 149 sql_updateq('spip_urls', array('url'=>$set['url'], 'date' => date('Y-m-d H:i:s')), $where .url_sql_quote_like($set['url'])); 150 spip_log("reordonne ".$set['type']." ".$set['id_objet'],"urls"); 157 !is_dir(_DIR_RACINE . $set['url']) AND !file_exists(_DIR_RACINE . $set['url']) 158 AND sql_countsel('spip_urls', $where . url_sql_quote_like($set['url'])) 159 ) { 160 sql_updateq('spip_urls', array('url' => $set['url'], 'date' => date('Y-m-d H:i:s')), 161 $where . url_sql_quote_like($set['url'])); 162 spip_log("reordonne " . $set['type'] . " " . $set['id_objet'], "urls"); 151 163 $redate = false; 152 } 153 else { 154 $set['url'] .= $separateur.$set['id_objet']; 155 if (strlen($set['url']) > 200) 156 //serveur out ? retourner au mieux 164 } else { 165 $set['url'] .= $separateur . $set['id_objet']; 166 if (strlen($set['url']) > 200) //serveur out ? retourner au mieux 167 { 157 168 return false; 158 elseif (sql_countsel('spip_urls', $where . url_sql_quote_like($set['url']))) { 159 sql_updateq('spip_urls', array('url'=>$set['url'], 'date' => date('Y-m-d H:i:s')), $where .url_sql_quote_like($set['url'])); 169 } elseif (sql_countsel('spip_urls', $where . url_sql_quote_like($set['url']))) { 170 sql_updateq('spip_urls', array('url' => $set['url'], 'date' => date('Y-m-d H:i:s')), 171 $where . url_sql_quote_like($set['url'])); 160 172 $redate = false; 161 } 162 else { 173 } else { 163 174 // remettre id_parent et perma comme il faut si besoin 164 if (!$has_parent) unset($set['id_parent']); 165 if ($perma) $set['perma'] = true; 175 if (!$has_parent) { 176 unset($set['id_parent']); 177 } 178 if ($perma) { 179 $set['perma'] = true; 180 } 181 166 182 return url_insert($set, $confirmer, $separateur); 167 183 } … … 170 186 } 171 187 172 $where_thisurl = 'url=' .sql_quote($set['url'])." AND id_parent=".intval($set['id_parent']); // maj173 if ($redate) 188 $where_thisurl = 'url=' . sql_quote($set['url']) . " AND id_parent=" . intval($set['id_parent']); // maj 189 if ($redate) { 174 190 sql_updateq('spip_urls', array('date' => date('Y-m-d H:i:s')), $where_thisurl); 191 } 175 192 176 193 // si url perma, poser le flag sur la seule url qu'on vient de mettre 177 if ($perma) 178 sql_update('spip_urls', array('perma' => "($where_thisurl)"), "type=".sql_quote($set['type'])." AND id_objet=".intval($set['id_objet'])); 179 180 spip_log("Creation de l'url propre '" . $set['url'] . "' pour ".$set['type']." ".$set['id_objet']." (parent ".$set['id_parent']." perma ".($perma?"1":"0").")","urls"); 194 if ($perma) { 195 sql_update('spip_urls', array('perma' => "($where_thisurl)"), 196 "type=" . sql_quote($set['type']) . " AND id_objet=" . intval($set['id_objet'])); 197 } 198 199 spip_log("Creation de l'url propre '" . $set['url'] . "' pour " . $set['type'] . " " . $set['id_objet'] . " (parent " . $set['id_parent'] . " perma " . ($perma ? "1" : "0") . ")", 200 "urls"); 201 181 202 return true; 182 203 } 183 204 184 function url_sql_quote_like($url) {185 return sql_quote(str_replace(array("%", "_"),array("\\%","\\_"),$url))." ESCAPE ".sql_quote('\\');186 } 187 188 function url_verrouiller($objet, $id_objet, $url) {189 $where = "id_objet=" .intval($id_objet)." AND type=".sql_quote($objet);190 $where .= " AND url=" .sql_quote($url);205 function url_sql_quote_like($url) { 206 return sql_quote(str_replace(array("%", "_"), array("\\%", "\\_"), $url)) . " ESCAPE " . sql_quote('\\'); 207 } 208 209 function url_verrouiller($objet, $id_objet, $url) { 210 $where = "id_objet=" . intval($id_objet) . " AND type=" . sql_quote($objet); 211 $where .= " AND url=" . sql_quote($url); 191 212 192 213 // pour verrouiller une url, on fixe sa date dans le futur, dans 10 ans 193 sql_updateq('spip_urls', array('date' => date('Y-m-d H:i:s',time()+10*365.25*24*3600)), $where); 194 } 195 196 function url_delete($objet, $id_objet, $url = ""){ 197 $where = "id_objet=".intval($id_objet)." AND type=".sql_quote($objet); 198 if (strlen($url)) 199 $where .= " AND url=".sql_quote($url); 200 201 sql_delete("spip_urls",$where); 202 } 214 sql_updateq('spip_urls', array('date' => date('Y-m-d H:i:s', time()+10*365.25*24*3600)), $where); 215 } 216 217 function url_delete($objet, $id_objet, $url = "") { 218 $where = "id_objet=" . intval($id_objet) . " AND type=" . sql_quote($objet); 219 if (strlen($url)) { 220 $where .= " AND url=" . sql_quote($url); 221 } 222 223 sql_delete("spip_urls", $where); 224 } 225 203 226 ?> -
_core_/plugins/urls_etendues/action/supprimer_url.php
r93431 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } 14 16 15 17 function action_supprimer_url_dist($arg = null) { 16 18 17 if (is_null($arg)) {19 if (is_null($arg)) { 18 20 // Rien a faire ici pour le moment 19 21 $securiser_action = charger_fonction('securiser_action', 'inc'); 20 22 $arg = $securiser_action(); 21 23 } 22 if (strncmp($arg, "-1-",3)==0){24 if (strncmp($arg, "-1-", 3) == 0) { 23 25 $id_parent = -1; 24 $url = substr($arg,3); 25 } 26 else { 27 $arg = explode('-',$arg); 26 $url = substr($arg, 3); 27 } else { 28 $arg = explode('-', $arg); 28 29 $id_parent = array_shift($arg); 29 $url = implode('-', $arg);30 $url = implode('-', $arg); 30 31 } 31 32 32 $where = 'id_parent=' .intval($id_parent)." AND url=".sql_quote($url);33 if ($row = sql_fetsel('*','spip_urls',$where)){33 $where = 'id_parent=' . intval($id_parent) . " AND url=" . sql_quote($url); 34 if ($row = sql_fetsel('*', 'spip_urls', $where)) { 34 35 35 if (autoriser('modifierurl',$row['type'],$row['id_objet'])){ 36 sql_delete('spip_urls',$where); 36 if (autoriser('modifierurl', $row['type'], $row['id_objet'])) { 37 sql_delete('spip_urls', $where); 38 } else { 39 spip_log('supprimer sans autorisation l\'URL ' . $id_parent . "://" . $url, "urls." . _LOG_ERREUR); 37 40 } 38 else39 spip_log('supprimer sans autorisation l\'URL '.$id_parent."://".$url,"urls."._LOG_ERREUR);40 41 42 } else { 43 spip_log('Impossible de supprimer une URL inconnue ' . $id_parent . "://" . $url, "urls." . _LOG_INFO_IMPORTANTE); 41 44 } 42 else 43 spip_log('Impossible de supprimer une URL inconnue '.$id_parent."://".$url,"urls."._LOG_INFO_IMPORTANTE); 44 45 45 46 46 47 } -
_core_/plugins/urls_etendues/action/urls_actualiser.php
r89285 r93629 15 15 * 16 16 * @package SPIP\Urls_etendues\Action 17 **/17 **/ 18 18 19 if (!defined("_ECRIRE_INC_VERSION")) return; 19 if (!defined("_ECRIRE_INC_VERSION")) { 20 return; 21 } 20 22 21 23 /** … … 28 30 * Cette action ne supprime pas les anciennes urls. 29 31 * Elle n'invalide pas non plus les URLs «permanentes». 30 **/32 **/ 31 33 function action_urls_actualiser_dist() { 32 34 … … 34 36 $arg = $securiser_action(); 35 37 36 if (!defined('_VAR_URLS')) define('_VAR_URLS',true); 38 if (!defined('_VAR_URLS')) { 39 define('_VAR_URLS', true); 40 } 37 41 $type = $id = ""; 38 $res = sql_select("type,id_objet","spip_urls","","","type,id_objet"); 39 while ($row = sql_fetch($res)){ 40 if ($row['id_objet']!==$id 41 OR $row['type']!==$type){ 42 $res = sql_select("type,id_objet", "spip_urls", "", "", "type,id_objet"); 43 while ($row = sql_fetch($res)) { 44 if ($row['id_objet'] !== $id 45 OR $row['type'] !== $type 46 ) { 42 47 $id = $row['id_objet']; 43 48 $type = $row['type']; 44 generer_url_entite($id, $type,"","",true);49 generer_url_entite($id, $type, "", "", true); 45 50 } 46 51 } -
_core_/plugins/urls_etendues/action/urls_liberer.php
r93431 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } 14 16 15 17 // http://code.spip.net/@action_instituer_syndic_article_dist … … 20 22 21 23 include_spip('inc/autoriser'); 22 $arg = explode('-', $arg);24 $arg = explode('-', $arg); 23 25 $type = array_shift($arg); 24 26 $id = array_shift($arg); 25 $url = implode('-', $arg);26 if (autoriser('modifierurl', $type,$id)){27 $url = implode('-', $arg); 28 if (autoriser('modifierurl', $type, $id)) { 27 29 include_spip('action/editer_url'); 28 30 url_delete($type, $id, $url); -
_core_/plugins/urls_etendues/action/urls_verrouiller.php
r93431 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } 14 16 15 17 // http://code.spip.net/@action_instituer_syndic_article_dist … … 20 22 21 23 include_spip('inc/autoriser'); 22 $arg = explode('-', $arg);24 $arg = explode('-', $arg); 23 25 $type = array_shift($arg); 24 26 $id = array_shift($arg); 25 $url = implode('-', $arg);26 if (autoriser('modifierurl', $type,$id)){27 $url = implode('-', $arg); 28 if (autoriser('modifierurl', $type, $id)) { 27 29 include_spip('action/editer_url'); 28 30 url_verrouiller($type, $id, $url); -
_core_/plugins/urls_etendues/base/urls.php
r89285 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined('_ECRIRE_INC_VERSION')) return; 13 if (!defined('_ECRIRE_INC_VERSION')) { 14 return; 15 } 14 16 15 17 /** 16 18 * Declarer les interfaces 17 * 19 * 18 20 * @param array $interfaces 19 21 * @return array 20 22 */ 21 23 function urls_declarer_tables_interfaces($interfaces) { 22 $interfaces['table_des_tables']['urls']='urls'; 24 $interfaces['table_des_tables']['urls'] = 'urls'; 25 23 26 return $interfaces; 24 27 } 28 25 29 /** 26 30 * Tables de jointures … … 29 33 * @return array 30 34 */ 31 function urls_declarer_tables_auxiliaires($tables_auxiliaires) {35 function urls_declarer_tables_auxiliaires($tables_auxiliaires) { 32 36 33 37 $spip_urls = array( 34 38 // un id parent eventuel, pour discriminer les doublons arborescents 35 "id_parent" 36 "url" 39 "id_parent" => "bigint(21) DEFAULT '0' NOT NULL", 40 "url" => "VARCHAR(255) NOT NULL", 37 41 // la table cible 38 "type" 42 "type" => "varchar(25) DEFAULT 'article' NOT NULL", 39 43 // l'id dans la table 40 "id_objet" 44 "id_objet" => "bigint(21) NOT NULL", 41 45 // pour connaitre la plus recente. 42 46 // ATTENTION, pas on update CURRENT_TIMESTAMP implicite 43 47 // et pas le nom maj, surinterprete par inc/import_1_3 44 "date" 48 "date" => "DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL", 45 49 // nombre de segments dans url 46 "segments" 50 "segments" => "SMALLINT(3) DEFAULT '1' NOT NULL", 47 51 // URL permanente, prioritaire 48 "perma" 52 "perma" => "TINYINT(1) DEFAULT '0' NOT NULL", 49 53 ); 50 54 51 55 $spip_urls_key = array( 52 "PRIMARY KEY" => "id_parent, url", 53 "KEY type" => "type, id_objet"); 56 "PRIMARY KEY" => "id_parent, url", 57 "KEY type" => "type, id_objet" 58 ); 54 59 55 60 $tables_auxiliaires['spip_urls'] = array( 56 61 'field' => &$spip_urls, 57 'key' => &$spip_urls_key); 62 'key' => &$spip_urls_key 63 ); 58 64 59 65 return $tables_auxiliaires; -
_core_/plugins/urls_etendues/formulaires/configurer_urls.php
r93092 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } 14 16 15 function formulaires_configurer_urls_charger_dist() {17 function formulaires_configurer_urls_charger_dist() { 16 18 if (isset($GLOBALS['type_urls'])) // priorité au fichier d'options 17 return "<p>"._T('urls:erreur_config_url_forcee')."</p>"; 19 { 20 return "<p>" . _T('urls:erreur_config_url_forcee') . "</p>"; 21 } 18 22 19 23 $valeurs = array( 20 24 'type_urls' => $GLOBALS['meta']['type_urls'], 21 25 'urls_activer_controle' => (isset($GLOBALS['meta']['urls_activer_controle']) ? $GLOBALS['meta']['urls_activer_controle'] : ''), 22 '_urls_dispos' =>type_urls_lister(),26 '_urls_dispos' => type_urls_lister(), 23 27 ); 24 28 … … 27 31 } 28 32 29 function formulaires_configurer_urls_traiter_dist() {30 ecrire_meta('type_urls', _request('type_urls'));31 ecrire_meta('urls_activer_controle', _request('urls_activer_controle')?'oui':'non');33 function formulaires_configurer_urls_traiter_dist() { 34 ecrire_meta('type_urls', _request('type_urls')); 35 ecrire_meta('urls_activer_controle', _request('urls_activer_controle') ? 'oui' : 'non'); 32 36 33 return array('message_ok' =>_T('config_info_enregistree'),'editable'=>true);37 return array('message_ok' => _T('config_info_enregistree'), 'editable' => true); 34 38 } 35 39 36 function type_url_choisir($liste, $name, $selected) {40 function type_url_choisir($liste, $name, $selected) { 37 41 $res = '<dl class="choix">'; 38 foreach ($liste as $url){42 foreach ($liste as $url) { 39 43 $k = $url[0]; 40 44 $res .= '<dt>' 41 . '<input type="radio" name="'.$name.'" id="'.$name.'_'.$k.'" value="'.$k.'"'42 . ($selected==$k ? ' checked="checked"':'')43 . '/>'44 . '<label for="'.$name.'_'.$k.'">'.$url[1].'</label></dt>'45 .'<dd><tt>'.$url[2].'</tt></dd>'46 ."\n";45 . '<input type="radio" name="' . $name . '" id="' . $name . '_' . $k . '" value="' . $k . '"' 46 . ($selected == $k ? ' checked="checked"' : '') 47 . '/>' 48 . '<label for="' . $name . '_' . $k . '">' . $url[1] . '</label></dt>' 49 . '<dd><tt>' . $url[2] . '</tt></dd>' 50 . "\n"; 47 51 } 48 52 $res .= "</dl>"; 53 49 54 return $res; 50 55 } 51 56 52 function type_urls_lister() {57 function type_urls_lister() { 53 58 54 59 $dispo = array(); 55 60 foreach (find_all_in_path('urls/', '\w+\.php$', array()) as $f) { 56 61 $r = basename($f, '.php'); 57 if ($r == 'index' OR strncmp('generer_',$r,8)==0 OR $r=="standard") continue; 62 if ($r == 'index' OR strncmp('generer_', $r, 8) == 0 OR $r == "standard") { 63 continue; 64 } 58 65 include_once $f; 59 66 $exemple = 'URLS_' . strtoupper($r) . '_EXEMPLE'; 60 67 $exemple = defined($exemple) ? constant($exemple) : '?'; 61 $dispo[_T("urls:titre_type_$r")] = array($r, _T("urls:titre_type_$r"), $exemple);68 $dispo[_T("urls:titre_type_$r")] = array($r, _T("urls:titre_type_$r"), $exemple); 62 69 } 63 70 … … 66 73 return $dispo; 67 74 } 75 68 76 ?> -
_core_/plugins/urls_etendues/formulaires/configurer_urls_arbo_fonctions.php
r53218 r93629 1 1 <?php 2 2 3 if (!defined('_ECRIRE_INC_VERSION')) return; 3 if (!defined('_ECRIRE_INC_VERSION')) { 4 return; 5 } 4 6 5 7 include_spip('urls/arbo'); -
_core_/plugins/urls_etendues/formulaires/configurer_urls_propres_fonctions.php
r53218 r93629 1 1 <?php 2 2 3 if (!defined('_ECRIRE_INC_VERSION')) return; 3 if (!defined('_ECRIRE_INC_VERSION')) { 4 return; 5 } 4 6 5 7 include_spip('urls/propres'); -
_core_/plugins/urls_etendues/formulaires/editer_url_objet.php
r93092 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined('_ECRIRE_INC_VERSION')) return; 13 if (!defined('_ECRIRE_INC_VERSION')) { 14 return; 15 } 14 16 15 17 /** … … 20 22 * @return array 21 23 */ 22 function formulaires_editer_url_objet_charger($type, $id) {23 $valeurs = array('url' =>'','_objet'=>$type,'_id_objet'=>$id);24 function formulaires_editer_url_objet_charger($type, $id) { 25 $valeurs = array('url' => '', '_objet' => $type, '_id_objet' => $id); 24 26 25 27 return $valeurs; 26 28 } 27 29 28 function formulaires_editer_url_objet_verifier($type, $id) {30 function formulaires_editer_url_objet_verifier($type, $id) { 29 31 $erreurs = array(); 30 32 include_spip('action/editer_url'); 31 if (!$url = _request('url')) {33 if (!$url = _request('url')) { 32 34 $erreurs['url'] = _T('info_obligatoire'); 33 } 34 else { 35 $type_urls = (isset($GLOBALS['type_urls'])?$GLOBALS['type_urls']:$GLOBALS['meta']['type_urls']); 36 if ($type_urls=='arbo' AND strpos($url,'/')!==false){ 37 $url = explode('/',$url); 38 if (count($url)>2) 35 } else { 36 $type_urls = (isset($GLOBALS['type_urls']) ? $GLOBALS['type_urls'] : $GLOBALS['meta']['type_urls']); 37 if ($type_urls == 'arbo' AND strpos($url, '/') !== false) { 38 $url = explode('/', $url); 39 if (count($url) > 2) { 39 40 $erreurs['url'] = _T('urls:erreur_arbo_2_segments_max'); 40 else{41 foreach ($url as $u){41 } else { 42 foreach ($url as $u) { 42 43 $url_clean[] = url_nettoyer($u, 255); 43 44 } 44 $url = implode('/', $url);45 $url_clean = implode('/', $url_clean);45 $url = implode('/', $url); 46 $url_clean = implode('/', $url_clean); 46 47 } 48 } else { 49 $url_clean = url_nettoyer($url, 255); 47 50 } 48 else 49 $url_clean = url_nettoyer($url, 255); 50 if (!isset($erreurs['url']) AND $url!=$url_clean){ 51 set_request('url',$url_clean); 51 if (!isset($erreurs['url']) AND $url != $url_clean) { 52 set_request('url', $url_clean); 52 53 $erreurs['url'] = _T('urls:verifier_url_nettoyee'); 53 54 } … … 64 65 * @return array 65 66 */ 66 function formulaires_editer_url_objet_traiter($type, $id) {67 $valeurs = array('editable' =>true);67 function formulaires_editer_url_objet_traiter($type, $id) { 68 $valeurs = array('editable' => true); 68 69 69 70 include_spip('action/editer_url'); 70 71 // les urls manuelles sont toujours permanentes 71 $set = array('url' => _request('url'), 'type' => $type, 'id_objet' => $id, 'perma' =>1);72 $set = array('url' => _request('url'), 'type' => $type, 'id_objet' => $id, 'perma' => 1); 72 73 73 $type_urls = (isset($GLOBALS['type_urls']) ?$GLOBALS['type_urls']:$GLOBALS['meta']['type_urls']);74 $type_urls = (isset($GLOBALS['type_urls']) ? $GLOBALS['type_urls'] : $GLOBALS['meta']['type_urls']); 74 75 if (include_spip("urls/$type_urls") 75 76 AND function_exists($renseigner_url = "renseigner_url_$type_urls") 76 AND $r = $renseigner_url($type,$id) 77 AND isset($r['parent'])) 77 AND $r = $renseigner_url($type, $id) 78 AND isset($r['parent']) 79 ) { 78 80 $set['id_parent'] = $r['parent']; 81 } 79 82 80 83 $separateur = "-"; 81 if (defined('_url_sep_id')) $separateur = _url_sep_id; 84 if (defined('_url_sep_id')) { 85 $separateur = _url_sep_id; 86 } 82 87 83 if (url_insert($set, false,$separateur)) {88 if (url_insert($set, false, $separateur)) { 84 89 set_request('url'); 85 90 $valeurs['message_ok'] = _T("urls:url_ajoutee"); 91 } else { 92 $valeurs['message_erreur'] = _T("urls:url_ajout_impossible"); 86 93 } 87 else88 $valeurs['message_erreur'] = _T("urls:url_ajout_impossible");89 94 90 95 return $valeurs; -
_core_/plugins/urls_etendues/prive/squelettes/contenu/configurer_urls_fonctions.php
r53218 r93629 1 1 <?php 2 2 3 if (!defined('_ECRIRE_INC_VERSION')) return; 3 if (!defined('_ECRIRE_INC_VERSION')) { 4 return; 5 } 4 6 5 function choisir_form_configuration($type_url) {7 function choisir_form_configuration($type_url) { 6 8 if (include_spip("urls/$type_url") 7 AND defined($c='URLS_'.strtoupper($type_url).'_CONFIG')) 8 return "configurer_urls_".strtolower(constant($c)); 9 AND defined($c = 'URLS_' . strtoupper($type_url) . '_CONFIG') 10 ) { 11 return "configurer_urls_" . strtolower(constant($c)); 12 } 9 13 10 14 return ''; 11 15 } 16 12 17 ?> -
_core_/plugins/urls_etendues/urls/arbo.php
r93427 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; // securiser 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } // securiser 14 16 15 17 # donner un exemple d'url pour le formulaire de choix … … 29 31 * "sous-repertoire", vous devrez aussi editer la ligne "RewriteBase" ce fichier. 30 32 * Les URLs definies seront alors redirigees vers les fichiers de SPIP. 31 * 33 * 32 34 * Choisissez "arbo" dans les pages de configuration d'URL 33 35 * 34 36 * SPIP calculera alors ses liens sous la forme "Mon-titre-d-article". 35 37 * Variantes : 36 * 38 * 37 39 * Terminaison : 38 40 * les terminaisons ne *sont pas* stockees en base, elles servent juste … … 40 42 * pour avoir des url terminant par html 41 43 * define ('_terminaison_urls_arbo', '.html'); 42 * 44 * 43 45 * pour preciser des terminaisons particulieres pour certains types 44 46 * $GLOBALS['url_arbo_terminaisons']=array( … … 47 49 * 'groupe' => '/', 48 50 * 'defaut' => '.html'); 49 * 51 * 50 52 * pour avoir des url numeriques (id) du type 12/5/4/article/23 51 53 * define ('_URLS_ARBO_MIN',255); 52 * 53 * 54 * 55 * 54 56 * pour conserver la casse des titres dans les url 55 57 * define ('_url_arbo_minuscules',0); 56 * 57 * pour choisir le caractere de separation titre-id en cas de doublon 58 * 59 * pour choisir le caractere de separation titre-id en cas de doublon 58 60 * (ne pas utiliser '/') 59 61 * define ('_url_arbo_sep_id','-'); 60 * 62 * 61 63 * pour modifier la hierarchie apparente dans la constitution des urls 62 64 * ex pour que les mots soient classes par groupes 63 65 * $GLOBALS['url_arbo_parents']=array( 64 * 65 * 66 * 67 * 68 * 69 * 66 * 'article'=>array('id_rubrique','rubrique'), 67 * 'rubrique'=>array('id_parent','rubrique'), 68 * 'breve'=>array('id_rubrique','rubrique'), 69 * 'site'=>array('id_rubrique','rubrique'), 70 * 'mot'=>array('id_groupe','groupes_mot')); 71 * 70 72 * pour personaliser les types 71 73 * $GLOBALS['url_arbo_types']=array( … … 74 76 * 'mot'=>'tags' 75 77 * ); 76 * 78 * 77 79 */ 78 80 79 81 include_spip('inc/xcache'); 80 82 if (!function_exists('Cache')) { 81 function Cache(){return null;} 82 } 83 84 $config_urls_arbo = isset($GLOBALS['meta']['urls_arbo'])?unserialize($GLOBALS['meta']['urls_arbo']):array(); 85 if (!defined('_debut_urls_arbo')) define('_debut_urls_arbo', ''); 86 if (!defined('_terminaison_urls_arbo')) define('_terminaison_urls_arbo', ''); 83 function Cache() { return null; } 84 } 85 86 $config_urls_arbo = isset($GLOBALS['meta']['urls_arbo']) ? unserialize($GLOBALS['meta']['urls_arbo']) : array(); 87 if (!defined('_debut_urls_arbo')) { 88 define('_debut_urls_arbo', ''); 89 } 90 if (!defined('_terminaison_urls_arbo')) { 91 define('_terminaison_urls_arbo', ''); 92 } 87 93 // pour choisir le caractere de separation titre-id en cas de doublon 88 94 // (ne pas utiliser '/') 89 if (!defined('_url_arbo_sep_id')) define('_url_arbo_sep_id',isset($config_urls_arbo['url_arbo_sep_id'])?$config_urls_arbo['url_arbo_sep_id']:'-'); 95 if (!defined('_url_arbo_sep_id')) { 96 define('_url_arbo_sep_id', isset($config_urls_arbo['url_arbo_sep_id']) ? $config_urls_arbo['url_arbo_sep_id'] : '-'); 97 } 90 98 // option pour tout passer en minuscules 91 if (!defined('_url_arbo_minuscules')) define('_url_arbo_minuscules',isset($config_urls_arbo['url_arbo_minuscules'])?$config_urls_arbo['url_arbo_minuscules']:1); 92 if (!defined('_URLS_ARBO_MAX')) define('_URLS_ARBO_MAX', isset($config_urls_arbo['URLS_ARBO_MAX'])?$config_urls_arbo['URLS_ARBO_MAX']:80); 93 if (!defined('_URLS_ARBO_MIN')) define('_URLS_ARBO_MIN', isset($config_urls_arbo['URLS_ARBO_MIN'])?$config_urls_arbo['URLS_ARBO_MIN']:3); 94 95 if (!defined('_url_sep_id')) define('_url_sep_id',_url_arbo_sep_id); 99 if (!defined('_url_arbo_minuscules')) { 100 define('_url_arbo_minuscules', isset($config_urls_arbo['url_arbo_minuscules']) ? $config_urls_arbo['url_arbo_minuscules'] : 1); 101 } 102 if (!defined('_URLS_ARBO_MAX')) { 103 define('_URLS_ARBO_MAX', isset($config_urls_arbo['URLS_ARBO_MAX']) ? $config_urls_arbo['URLS_ARBO_MAX'] : 80); 104 } 105 if (!defined('_URLS_ARBO_MIN')) { 106 define('_URLS_ARBO_MIN', isset($config_urls_arbo['URLS_ARBO_MIN']) ? $config_urls_arbo['URLS_ARBO_MIN'] : 3); 107 } 108 109 if (!defined('_url_sep_id')) { 110 define('_url_sep_id', _url_arbo_sep_id); 111 } 96 112 97 113 // Ces chaines servaient de marqueurs a l'epoque ou les URL propres devaient … … 102 118 103 119 #define('_MARQUEUR_URL', serialize(array('rubrique1' => '-', 'rubrique2' => '-', 'breve1' => '+', 'breve2' => '+', 'site1' => '@', 'site2' => '@', 'auteur1' => '_', 'auteur2' => '_', 'mot1' => '+-', 'mot2' => '-+'))); 104 if (!defined('_MARQUEUR_URL')) define('_MARQUEUR_URL', false); 120 if (!defined('_MARQUEUR_URL')) { 121 define('_MARQUEUR_URL', false); 122 } 105 123 106 124 /** … … 110 128 * @return string 111 129 */ 112 function url_arbo_parent($type) {130 function url_arbo_parent($type) { 113 131 static $parents = null; 114 if (is_null($parents)) {132 if (is_null($parents)) { 115 133 $parents = array( 116 'article'=>array('id_rubrique','rubrique'), 117 'rubrique'=>array('id_parent','rubrique'), 118 'breve'=>array('id_rubrique','rubrique'), 119 'site'=>array('id_rubrique','rubrique')); 120 if (isset($GLOBALS['url_arbo_parents']) AND !isset($_REQUEST['url_arbo_parents'])){ 121 $parents = array_merge($parents,$GLOBALS['url_arbo_parents']); 122 } 123 } 124 return (isset($parents[$type])?$parents[$type]:''); 134 'article' => array('id_rubrique', 'rubrique'), 135 'rubrique' => array('id_parent', 'rubrique'), 136 'breve' => array('id_rubrique', 'rubrique'), 137 'site' => array('id_rubrique', 'rubrique') 138 ); 139 if (isset($GLOBALS['url_arbo_parents']) AND !isset($_REQUEST['url_arbo_parents'])) { 140 $parents = array_merge($parents, $GLOBALS['url_arbo_parents']); 141 } 142 } 143 144 return (isset($parents[$type]) ? $parents[$type] : ''); 125 145 } 126 146 … … 133 153 * @return string 134 154 */ 135 function url_arbo_terminaison($type) {155 function url_arbo_terminaison($type) { 136 156 static $terminaison_types = null; 137 if ($terminaison_types==null){ 138 $terminaison_types = array('rubrique' => '/','mot' => '','defaut' => defined('_terminaison_urls_arbo')?_terminaison_urls_arbo:'.html'); 139 if (isset($GLOBALS['url_arbo_terminaisons'])) 140 $terminaison_types = array_merge($terminaison_types,$GLOBALS['url_arbo_terminaisons']); 157 if ($terminaison_types == null) { 158 $terminaison_types = array( 159 'rubrique' => '/', 160 'mot' => '', 161 'defaut' => defined('_terminaison_urls_arbo') ? _terminaison_urls_arbo : '.html' 162 ); 163 if (isset($GLOBALS['url_arbo_terminaisons'])) { 164 $terminaison_types = array_merge($terminaison_types, $GLOBALS['url_arbo_terminaisons']); 165 } 141 166 } 142 167 // si c'est un appel avec type='' c'est pour avoir la liste des terminaisons 143 if (!$type) 168 if (!$type) { 144 169 return array_unique(array_values($terminaison_types)); 145 if (isset($terminaison_types[$type])) 170 } 171 if (isset($terminaison_types[$type])) { 146 172 return $terminaison_types[$type]; 147 elseif (isset($terminaison_types['defaut']))173 } elseif (isset($terminaison_types['defaut'])) { 148 174 return $terminaison_types['defaut']; 175 } 176 149 177 return ""; 150 178 } … … 158 186 * @return array|string 159 187 */ 160 function url_arbo_type($type) {188 function url_arbo_type($type) { 161 189 static $synonymes_types = null; 162 if (!$synonymes_types){ 163 $synonymes_types = array('rubrique'=>''); 164 if (isset($GLOBALS['url_arbo_types']) AND is_array($GLOBALS['url_arbo_types'])) 165 $synonymes_types = array_merge($synonymes_types,$GLOBALS['url_arbo_types']); 190 if (!$synonymes_types) { 191 $synonymes_types = array('rubrique' => ''); 192 if (isset($GLOBALS['url_arbo_types']) AND is_array($GLOBALS['url_arbo_types'])) { 193 $synonymes_types = array_merge($synonymes_types, $GLOBALS['url_arbo_types']); 194 } 166 195 } 167 196 // si c'est un appel avec type='' c'est pour avoir la liste inversee des synonymes 168 if (!$type) 197 if (!$type) { 169 198 return array_flip($synonymes_types); 170 return 171 ($t=(isset($synonymes_types[$type])?$synonymes_types[$type]:$type)) // le type ou son synonyme 172 . ($t?'/':''); // le / eventuel pour separer, si le synonyme n'est pas vide 199 } 200 201 return 202 ($t = (isset($synonymes_types[$type]) ? $synonymes_types[$type] : $type)) // le type ou son synonyme 203 . ($t ? '/' : ''); // le / eventuel pour separer, si le synonyme n'est pas vide 173 204 } 174 205 … … 191 222 192 223 include_spip('action/editer_url'); 193 if (!$url = url_nettoyer($objet['titre'],_URLS_ARBO_MAX,_URLS_ARBO_MIN,'-',_url_arbo_minuscules?'strtolower':'')) 224 if (!$url = url_nettoyer($objet['titre'], _URLS_ARBO_MAX, _URLS_ARBO_MIN, '-', 225 _url_arbo_minuscules ? 'strtolower' : '') 226 ) { 194 227 $url = $objet['id_objet']; 195 228 } 229 196 230 $x['data'] = 197 198 231 url_arbo_type($objet['type']) // le type ou son synonyme 232 . $url; // le titre 199 233 200 234 return $x; … … 211 245 * @return string 212 246 */ 213 function declarer_url_arbo_rec($url, $type, $parent, $type_parent) {214 if (is_null($parent)) {247 function declarer_url_arbo_rec($url, $type, $parent, $type_parent) { 248 if (is_null($parent)) { 215 249 return $url; 216 250 } 217 251 // Si pas de parent ou si son URL est vide, on ne renvoit que l'URL de l'objet en court 218 if ($parent==0 or !($url_parent = declarer_url_arbo($type_parent?$type_parent:'rubrique',$parent))){ 219 return rtrim($url,'/'); 220 } 221 // Sinon on renvoit l'URL de l'objet concaténée avec celle du parent 252 if ($parent == 0 or !($url_parent = declarer_url_arbo($type_parent ? $type_parent : 'rubrique', $parent))) { 253 return rtrim($url, '/'); 254 } // Sinon on renvoit l'URL de l'objet concaténée avec celle du parent 222 255 else { 223 return rtrim($url_parent, '/') . '/' . rtrim($url,'/');256 return rtrim($url_parent, '/') . '/' . rtrim($url, '/'); 224 257 } 225 258 } … … 228 261 * Renseigner les infos les plus recentes de l'url d'un objet 229 262 * et de quoi la (re)construire si besoin 263 * 230 264 * @param string $type 231 265 * @param int $id_objet 232 266 * @return bool|null|array 233 267 */ 234 function renseigner_url_arbo($type, $id_objet) {268 function renseigner_url_arbo($type, $id_objet) { 235 269 $urls = array(); 236 270 $trouver_table = charger_fonction('trouver_table', 'base'); 237 271 $desc = $trouver_table(table_objet($type)); 238 272 $table = $desc['table']; 239 $col_id = @$desc['key']["PRIMARY KEY"]; 240 if (!$col_id) return false; // Quand $type ne reference pas une table 273 $col_id = @$desc['key']["PRIMARY KEY"]; 274 if (!$col_id) { 275 return false; 276 } // Quand $type ne reference pas une table 241 277 $id_objet = intval($id_objet); 242 278 243 279 $champ_titre = $desc['titre'] ? $desc['titre'] : 'titre'; 244 280 245 281 // parent 246 282 $champ_parent = url_arbo_parent($type); 247 283 $sel_parent = ', 0 as parent'; 248 284 $order_by_parent = ""; 249 if ($champ_parent) {250 $sel_parent = ", O." .reset($champ_parent).' as parent';285 if ($champ_parent) { 286 $sel_parent = ", O." . reset($champ_parent) . ' as parent'; 251 287 // trouver l'url qui matche le parent en premier 252 $order_by_parent = "O." .reset($champ_parent)."=U.id_parent DESC, ";288 $order_by_parent = "O." . reset($champ_parent) . "=U.id_parent DESC, "; 253 289 } 254 290 // Recuperer une URL propre correspondant a l'objet. 255 291 $row = sql_fetsel("U.url, U.date, U.id_parent, U.perma, $champ_titre $sel_parent", 256 257 258 259 $order_by_parent.'U.perma DESC, U.date DESC', 1);260 if ($row) {292 "$table AS O LEFT JOIN spip_urls AS U ON (U.type='$type' AND U.id_objet=O.$col_id)", 293 "O.$col_id=$id_objet", 294 '', 295 $order_by_parent . 'U.perma DESC, U.date DESC', 1); 296 if ($row) { 261 297 $urls[$type][$id_objet] = $row; 262 $urls[$type][$id_objet]['type_parent'] = $champ_parent?end($champ_parent):''; 263 } 264 return isset($urls[$type][$id_objet])?$urls[$type][$id_objet]:null; 298 $urls[$type][$id_objet]['type_parent'] = $champ_parent ? end($champ_parent) : ''; 299 } 300 301 return isset($urls[$type][$id_objet]) ? $urls[$type][$id_objet] : null; 265 302 } 266 303 … … 275 312 */ 276 313 function declarer_url_arbo($type, $id_objet) { 277 static $urls =array();314 static $urls = array(); 278 315 // utiliser un cache memoire pour aller plus vite 279 if(!is_null($C=Cache())) return$C; 280 316 if (!is_null($C = Cache())) { 317 return $C; 318 } 319 281 320 // Se contenter de cette URL si elle existe ; 282 321 // sauf si on invoque par "voir en ligne" avec droit de modifier l'url … … 286 325 // qui requetent en base 287 326 $modifier_url = (defined('_VAR_URLS') AND _VAR_URLS); 288 327 289 328 if (!isset($urls[$type][$id_objet]) OR $modifier_url) { 290 $r = renseigner_url_arbo($type, $id_objet);329 $r = renseigner_url_arbo($type, $id_objet); 291 330 // Quand $type ne reference pas une table 292 if ($r ===false)331 if ($r === false) { 293 332 return false; 294 295 if (!is_null($r)) 333 } 334 335 if (!is_null($r)) { 296 336 $urls[$type][$id_objet] = $r; 297 } 298 299 if (!isset($urls[$type][$id_objet])) return ""; # objet inexistant 337 } 338 } 339 340 if (!isset($urls[$type][$id_objet])) { 341 return ""; 342 } # objet inexistant 300 343 301 344 $url_propre = $urls[$type][$id_objet]['url']; … … 305 348 // et (permanente ou pas de demande de modif) 306 349 if (!is_null($url_propre) 307 AND $urls[$type][$id_objet]['id_parent'] == $urls[$type][$id_objet]['parent'] 308 AND ($urls[$type][$id_objet]['perma'] OR !$modifier_url)) 309 return declarer_url_arbo_rec($url_propre,$type, 310 isset($urls[$type][$id_objet]['parent'])?$urls[$type][$id_objet]['parent']:0, 311 isset($urls[$type][$id_objet]['type_parent'])?$urls[$type][$id_objet]['type_parent']:null); 350 AND $urls[$type][$id_objet]['id_parent'] == $urls[$type][$id_objet]['parent'] 351 AND ($urls[$type][$id_objet]['perma'] OR !$modifier_url) 352 ) { 353 return declarer_url_arbo_rec($url_propre, $type, 354 isset($urls[$type][$id_objet]['parent']) ? $urls[$type][$id_objet]['parent'] : 0, 355 isset($urls[$type][$id_objet]['type_parent']) ? $urls[$type][$id_objet]['type_parent'] : null); 356 } 312 357 313 358 // Si URL inconnue ou maj forcee sur une url non permanente, recreer une url … … 327 372 include_spip('inc/urls'); 328 373 $objets = urls_liste_objets(); 329 if (preg_match(',^('.$objets.')[0-9]*$,', $url, $r) 330 AND $r[1] != $type) 331 $url = $url._url_arbo_sep_id.$id_objet; 374 if (preg_match(',^(' . $objets . ')[0-9]*$,', $url, $r) 375 AND $r[1] != $type 376 ) { 377 $url = $url . _url_arbo_sep_id . $id_objet; 378 } 332 379 } 333 380 … … 335 382 // Pas de changement d'url ni de parent 336 383 if ($url == $url_propre 337 AND $urls[$type][$id_objet]['id_parent'] == $urls[$type][$id_objet]['parent']) 338 return declarer_url_arbo_rec($url_propre,$type,$urls[$type][$id_objet]['parent'],$urls[$type][$id_objet]['type_parent']); 384 AND $urls[$type][$id_objet]['id_parent'] == $urls[$type][$id_objet]['parent'] 385 ) { 386 return declarer_url_arbo_rec($url_propre, $type, $urls[$type][$id_objet]['parent'], 387 $urls[$type][$id_objet]['type_parent']); 388 } 339 389 340 390 // verifier l'autorisation, maintenant qu'on est sur qu'on va agir … … 348 398 AND $url_propre 349 399 // on essaye pas de regenerer une url en -xxx (suffixe id anti collision) 350 AND $url != preg_replace('/'.preg_quote(_url_propres_sep_id,'/').'.*/', '', $url_propre)) 400 AND $url != preg_replace('/' . preg_quote(_url_propres_sep_id, '/') . '.*/', '', $url_propre) 401 ) { 351 402 $confirmer = true; 352 else403 } else { 353 404 $confirmer = false; 405 } 354 406 355 407 if ($confirmer AND !_request('ok')) { … … 357 409 } 358 410 359 $set = array('url' => $url, 'type' => $type, 'id_objet' => $id_objet, 'id_parent'=>$urls[$type][$id_objet]['parent'],'perma'=>intval($urls[$type][$id_objet]['perma'])); 411 $set = array( 412 'url' => $url, 413 'type' => $type, 414 'id_objet' => $id_objet, 415 'id_parent' => $urls[$type][$id_objet]['parent'], 416 'perma' => intval($urls[$type][$id_objet]['perma']) 417 ); 360 418 include_spip('action/editer_url'); 361 if (url_insert($set, $confirmer,_url_arbo_sep_id)){419 if (url_insert($set, $confirmer, _url_arbo_sep_id)) { 362 420 $urls[$type][$id_objet]['url'] = $set['url']; 363 421 $urls[$type][$id_objet]['id_parent'] = $set['id_parent']; 364 } 365 else { 422 } else { 366 423 // l'insertion a echoue, 367 424 //serveur out ? retourner au mieux 368 $urls[$type][$id_objet]['url']=$url_propre; 369 } 370 371 return declarer_url_arbo_rec($urls[$type][$id_objet]['url'],$type,$urls[$type][$id_objet]['parent'],$urls[$type][$id_objet]['type_parent']); 425 $urls[$type][$id_objet]['url'] = $url_propre; 426 } 427 428 return declarer_url_arbo_rec($urls[$type][$id_objet]['url'], $type, $urls[$type][$id_objet]['parent'], 429 $urls[$type][$id_objet]['type_parent']); 372 430 } 373 431 … … 385 443 function _generer_url_arbo($type, $id, $args = '', $ancre = '') { 386 444 387 if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls',true)) {445 if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) { 388 446 $url = $generer_url_externe($id, $args, $ancre); 389 if (NULL != $url) return $url; 447 if (null != $url) { 448 return $url; 449 } 390 450 } 391 451 … … 393 453 $propre = declarer_url_arbo($type, $id); 394 454 395 if ($propre === false) return ''; // objet inconnu. raccourci ? 455 if ($propre === false) { 456 return ''; 457 } // objet inconnu. raccourci ? 396 458 397 459 if ($propre) { 398 460 $url = _debut_urls_arbo 399 . rtrim($propre, '/')461 . rtrim($propre, '/') 400 462 . url_arbo_terminaison($type); 401 463 } else { … … 404 466 include_spip('base/connect_sql'); 405 467 $id_type = id_table_objet($type); 406 $url = get_spip_script('./') ."?"._SPIP_PAGE."=$type&$id_type=$id";468 $url = get_spip_script('./') . "?" . _SPIP_PAGE . "=$type&$id_type=$id"; 407 469 } 408 470 409 471 // Ajouter les args 410 if ($args) 411 $url .= ((strpos($url, '?')===false) ? '?' : '&') . $args; 472 if ($args) { 473 $url .= ((strpos($url, '?') === false) ? '?' : '&') . $args; 474 } 412 475 413 476 // Ajouter l'ancre 414 if ($ancre) 477 if ($ancre) { 415 478 $url .= "#$ancre"; 479 } 416 480 417 481 return _DIR_RACINE . $url; … … 433 497 */ 434 498 function urls_arbo_dist($i, $entite, $args = '', $ancre = '') { 435 if (is_numeric($i)) 499 if (is_numeric($i)) { 436 500 return _generer_url_arbo($entite, $i, $args, $ancre); 501 } 437 502 438 503 // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23 439 if ($GLOBALS['profondeur_url'] >0 AND $entite=='sommaire'){504 if ($GLOBALS['profondeur_url'] > 0 AND $entite == 'sommaire') { 440 505 $entite = 'type_urls'; 441 506 } 442 507 443 508 // recuperer les &debut_xx; 444 if (is_array($args)) 509 if (is_array($args)) { 445 510 $contexte = $args; 446 else 447 parse_str($args,$contexte); 511 } else { 512 parse_str($args, $contexte); 513 } 448 514 449 515 $url = $i; … … 453 519 // Migration depuis anciennes URLs ? 454 520 // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 455 if ($GLOBALS['profondeur_url']<=0 456 AND $_SERVER['REQUEST_METHOD'] != 'POST') { 521 if ($GLOBALS['profondeur_url'] <= 0 522 AND $_SERVER['REQUEST_METHOD'] != 'POST' 523 ) { 457 524 include_spip('inc/urls'); 458 525 $r = nettoyer_url_page($i, $contexte); 459 526 if ($r) { 460 list($contexte, $type, ,, $suite) = $r;527 list($contexte, $type, , , $suite) = $r; 461 528 $_id = id_table_objet($type); 462 529 $id_objet = $contexte[$_id]; 463 530 $url_propre = generer_url_entite($id_objet, $type); 464 531 if (strlen($url_propre) 465 AND !strstr($url,$url_propre)) { 466 list(,$hash) = array_pad(explode('#', $url_propre), 2, null); 532 AND !strstr($url, $url_propre) 533 ) { 534 list(, $hash) = array_pad(explode('#', $url_propre), 2, null); 467 535 $args = array(); 468 foreach (array_filter(explode('&', $suite)) as $fragment) {469 if ($fragment != "$_id=$id_objet") 536 foreach (array_filter(explode('&', $suite)) as $fragment) { 537 if ($fragment != "$_id=$id_objet") { 470 538 $args[] = $fragment; 539 } 471 540 } 472 $url_redirect = generer_url_entite($id_objet, $type, join('&', array_filter($args)), $hash);541 $url_redirect = generer_url_entite($id_objet, $type, join('&', array_filter($args)), $hash); 473 542 474 543 return array($contexte, $type, $url_redirect, $type); … … 483 552 // Mode Query-String ? 484 553 if (!$url_propre 485 AND preg_match(',[?]([^=/?&]+)(&.*)?$,', $url, $r)) { 554 AND preg_match(',[?]([^=/?&]+)(&.*)?$,', $url, $r) 555 ) { 486 556 $url_propre = $r[1]; 487 557 } 488 558 489 559 if (!$url_propre 490 OR $url_propre==_DIR_RESTREINT_ABS 491 OR $url_propre==_SPIP_SCRIPT) return; // qu'est-ce qu'il veut ??? 560 OR $url_propre == _DIR_RESTREINT_ABS 561 OR $url_propre == _SPIP_SCRIPT 562 ) { 563 return; 564 } // qu'est-ce qu'il veut ??? 492 565 493 566 … … 498 571 499 572 // Compatibilite avec .htm/.html et autres terminaisons 500 $t = array_diff(array_unique(array_merge(array('.html', '.htm','/'),url_arbo_terminaison(''))),array(''));501 if (count($t)) 573 $t = array_diff(array_unique(array_merge(array('.html', '.htm', '/'), url_arbo_terminaison(''))), array('')); 574 if (count($t)) { 502 575 $url_propre = preg_replace('{(' 503 .implode('|',array_map('preg_quote',$t)).')$}i', '', $url_propre); 504 505 if (strlen($url_propre) AND !preg_match(',^[^/]*[.]php,',$url_propre)){ 576 . implode('|', array_map('preg_quote', $t)) . ')$}i', '', $url_propre); 577 } 578 579 if (strlen($url_propre) AND !preg_match(',^[^/]*[.]php,', $url_propre)) { 506 580 $parents_vus = array(); 507 581 508 582 // recuperer tous les objets de larbo xxx/article/yyy/mot/zzzz 509 583 // on parcourt les segments de gauche a droite 510 584 // pour pouvoir contextualiser un segment par son parent 511 $url_arbo = explode('/', $url_propre);585 $url_arbo = explode('/', $url_propre); 512 586 $url_arbo_new = array(); 513 587 $dernier_parent_vu = false; 514 588 $objet_segments = 0; 515 while (count($url_arbo) >0){516 $type =null;517 if (count($url_arbo) >1)589 while (count($url_arbo) > 0) { 590 $type = null; 591 if (count($url_arbo) > 1) { 518 592 $type = array_shift($url_arbo); 593 } 519 594 $url_segment = array_shift($url_arbo); 520 595 // Rechercher le segment de candidat … … 522 597 // prefixer le segment recherche avec ce contexte 523 598 $cp = "0"; // par defaut : parent racine, id=0 524 if ($dernier_parent_vu) 599 if ($dernier_parent_vu) { 525 600 $cp = $parents_vus[$dernier_parent_vu]; 601 } 526 602 // d'abord recherche avec prefixe parent, en une requete car aucun risque de colision 527 $row =sql_fetsel('id_objet, type, url',528 529 530 ? "url=".sql_quote($url_segment, '', 'TEXT')531 : sql_in('url',array("$type/$url_segment",$type)),532 533 534 535 536 537 (intval($cp)?"id_parent=".intval($cp)." DESC, ":"id_parent>=0 DESC, ")."segments DESC, id_parent"603 $row = sql_fetsel('id_objet, type, url', 604 'spip_urls', 605 is_null($type) 606 ? "url=" . sql_quote($url_segment, '', 'TEXT') 607 : sql_in('url', array("$type/$url_segment", $type)), 608 '', 609 // en priorite celui qui a le bon parent et les deux segments 610 // puis le bon parent avec 1 segment 611 // puis un parent indefini (le 0 de preference) et les deux segments 612 // puis un parent indefini (le 0 de preference) et 1 segment 613 (intval($cp) ? "id_parent=" . intval($cp) . " DESC, " : "id_parent>=0 DESC, ") . "segments DESC, id_parent" 538 614 ); 539 if ($row) {540 if (!is_null($type) AND $row['url'] ==$type){541 array_unshift($url_arbo, $url_segment);615 if ($row) { 616 if (!is_null($type) AND $row['url'] == $type) { 617 array_unshift($url_arbo, $url_segment); 542 618 $url_segment = $type; 543 619 $type = null; … … 545 621 $type = $row['type']; 546 622 $col_id = id_table_objet($type); 547 623 548 624 // le plus a droite l'emporte pour des objets presents plusieurs fois dans l'url (ie rubrique) 549 625 $contexte[$col_id] = $row['id_objet']; 550 626 551 627 $type_parent = ''; 552 if ($p = url_arbo_parent($type)) 553 $type_parent=end($p); 628 if ($p = url_arbo_parent($type)) { 629 $type_parent = end($p); 630 } 554 631 // l'entite la plus a droite l'emporte, si le type de son parent a ete vu 555 632 // sinon c'est un segment contextuel supplementaire a ignorer 556 633 // ex : rub1/article/art1/mot1 : il faut ignorer le mot1, la vrai url est celle de l'article 557 634 if (!$entite 558 OR $dernier_parent_vu == $type_parent){ 559 if ($objet_segments==0) 635 OR $dernier_parent_vu == $type_parent 636 ) { 637 if ($objet_segments == 0) { 560 638 $entite = $type; 561 }562 // sinon on change d'objet concerne563 else {639 } 640 } // sinon on change d'objet concerne 641 else { 564 642 $objet_segments++; 565 643 } … … 571 649 // on note le dernier parent vu de chaque type 572 650 $parents_vus[$dernier_parent_vu = $type] = $row['id_objet']; 573 } 574 else { 651 } else { 575 652 // un segment est inconnu 576 if ($entite =='' OR $entite=='type_urls') {653 if ($entite == '' OR $entite == 'type_urls') { 577 654 // on genere une 404 comme il faut si on ne sait pas ou aller 578 return array(array(), '404');655 return array(array(), '404'); 579 656 } 580 657 // ici on a bien reconnu un segment en amont, mais le segment en cours est inconnu … … 582 659 // mais de fait l'url entiere est inconnu : 404 aussi 583 660 // mais conserver le contexte qui peut contenir un fond d'ou venait peut etre $entite (reecriture urls) 584 return array($contexte, '404');661 return array($contexte, '404'); 585 662 } 586 663 } 587 664 588 if (count($url_arbo_new)) {665 if (count($url_arbo_new)) { 589 666 $caller = debug_backtrace(); 590 667 $caller = $caller[1]['function']; … … 592 669 // ne pas regenerer des segments arbo, mais rediriger vers la nouvelle URL 593 670 // dans la nouvelle forme 594 if (strncmp($caller, "urls_",5)==0 AND $caller!=="urls_decoder_url"){671 if (strncmp($caller, "urls_", 5) == 0 AND $caller !== "urls_decoder_url") { 595 672 // en absolue, car assembler ne gere pas ce cas particulier 596 673 include_spip('inc/filtres_mini'); 597 674 $col_id = id_table_objet($entite); 598 $url_new = generer_url_entite($contexte[$col_id], $entite);675 $url_new = generer_url_entite($contexte[$col_id], $entite); 599 676 // securite contre redirection infinie 600 if ($url_new!==$url_propre 601 AND rtrim($url_new,"/")!==rtrim($url_propre,"/")) 677 if ($url_new !== $url_propre 678 AND rtrim($url_new, "/") !== rtrim($url_propre, "/") 679 ) { 602 680 $url_redirect = url_absolue($url_new); 603 }604 else {605 foreach ($url_arbo_new as $k=>$o)606 if ($s = declarer_url_arbo($o['objet'], $o['id_objet']))681 } 682 } else { 683 foreach ($url_arbo_new as $k => $o) { 684 if ($s = declarer_url_arbo($o['objet'], $o['id_objet'])) { 607 685 $url_arbo_new[$k] = $s; 608 else 609 $url_arbo_new[$k] = implode('/',$o['segment']); 610 $url_arbo_new = ltrim(implode('/',$url_arbo_new),'/'); 611 612 if ($url_arbo_new!==$url_propre){ 686 } else { 687 $url_arbo_new[$k] = implode('/', $o['segment']); 688 } 689 } 690 $url_arbo_new = ltrim(implode('/', $url_arbo_new), '/'); 691 692 if ($url_arbo_new !== $url_propre) { 613 693 $url_redirect = $url_arbo_new; 614 694 // en absolue, car assembler ne gere pas ce cas particulier … … 620 700 621 701 // gerer le retour depuis des urls propres 622 if (($entite=='' OR $entite=='type_urls') 623 AND $GLOBALS['profondeur_url']<=0){ 624 $urls_anciennes = charger_fonction('propres','urls'); 702 if (($entite == '' OR $entite == 'type_urls') 703 AND $GLOBALS['profondeur_url'] <= 0 704 ) { 705 $urls_anciennes = charger_fonction('propres', 'urls'); 706 625 707 return $urls_anciennes($url_propre, $entite, $contexte); 626 708 } 627 709 } 628 if ($entite =='' OR $entite=='type_urls' /* compat .htaccess 2.0 */) {629 if ($type) 630 $entite = objet_type 631 else {710 if ($entite == '' OR $entite == 'type_urls' /* compat .htaccess 2.0 */) { 711 if ($type) { 712 $entite = objet_type($type); 713 } else { 632 714 // Si ca ressemble a une URL d'objet, ce n'est pas la home 633 715 // et on provoque un 404 … … 638 720 } 639 721 } 640 define('_SET_HTML_BASE', 1);722 define('_SET_HTML_BASE', 1); 641 723 642 724 return array($contexte, $entite, $url_redirect, null); -
_core_/plugins/urls_etendues/urls/html.php
r93092 r93629 32 32 */ 33 33 34 if (!defined("_ECRIRE_INC_VERSION")) return; // securiser 34 if (!defined("_ECRIRE_INC_VERSION")) { 35 return; 36 } // securiser 35 37 36 38 # donner un exemple d'url pour le formulaire de choix … … 39 41 // http://code.spip.net/@_generer_url_html 40 42 function _generer_url_html($type, $id, $args = '', $ancre = '') { 41 if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls',true)) {43 if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) { 42 44 $url = $generer_url_externe($id, $args, $ancre); 43 if (NULL != $url) return $url; 45 if (null != $url) { 46 return $url; 47 } 44 48 } 45 49 46 return _DIR_RACINE . $type . $id . '.html' . ($args ? "?$args" : '') . ($ancre ? "#$ancre" : '');50 return _DIR_RACINE . $type . $id . '.html' . ($args ? "?$args" : '') . ($ancre ? "#$ancre" : ''); 47 51 } 48 52 … … 51 55 function urls_html_dist($i, $entite, $args = '', $ancre = '') { 52 56 53 if (is_numeric($i)) 57 if (is_numeric($i)) { 54 58 return _generer_url_html($entite, $i, $args, $ancre); 59 } 55 60 56 61 // recuperer les &debut_xx; 57 if (is_array($args)) 62 if (is_array($args)) { 58 63 $contexte = $args; 59 else 60 parse_str($args,$contexte); 64 } else { 65 parse_str($args, $contexte); 66 } 61 67 62 68 63 69 // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23 64 if ($GLOBALS['profondeur_url'] >0 AND $entite=='sommaire'){65 return array(array(), '404');70 if ($GLOBALS['profondeur_url'] > 0 AND $entite == 'sommaire') { 71 return array(array(), '404'); 66 72 } 67 73 … … 73 79 // il n'est pas necessaire de forcer le fond en 4eme arg car l'url n'est pas query string 74 80 // sauf si pas de fond connu 75 if ($entite) 81 if ($entite) { 76 82 array_pop($r); 83 } 84 77 85 return $r; 78 86 } … … 88 96 $url_propre = $i; 89 97 if ($url_propre) { 90 if ($GLOBALS['profondeur_url']<=0) 91 $urls_anciennes = charger_fonction('propres','urls'); 92 else 93 $urls_anciennes = charger_fonction('arbo','urls'); 98 if ($GLOBALS['profondeur_url'] <= 0) { 99 $urls_anciennes = charger_fonction('propres', 'urls'); 100 } else { 101 $urls_anciennes = charger_fonction('arbo', 'urls'); 102 } 103 94 104 return $urls_anciennes($url_propre, $entite, $contexte); 95 105 } -
_core_/plugins/urls_etendues/urls/libres.php
r93092 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; // securiser 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } // securiser 14 16 15 17 /* … … 23 25 define('URLS_LIBRES_CONFIG', 'propres'); 24 26 25 if (!defined('_MARQUEUR_URL')) 27 if (!defined('_MARQUEUR_URL')) { 26 28 define('_MARQUEUR_URL', false); 29 } 27 30 28 31 // http://code.spip.net/@urls_libres_dist 29 32 function urls_libres_dist($i, &$entite, $args = '', $ancre = '') { 30 33 $f = charger_fonction('propres', 'urls'); 34 31 35 return $f($i, $entite, $args, $ancre); 32 36 } -
_core_/plugins/urls_etendues/urls/propres.php
r93092 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; // securiser 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } // securiser 14 16 15 17 # donner un exemple d'url pour le formulaire de choix … … 45 47 */ 46 48 47 if (!defined('_terminaison_urls_propres')) define ('_terminaison_urls_propres', ''); 48 if (!defined('_debut_urls_propres')) define ('_debut_urls_propres', ''); 49 50 $config_urls_propres = isset($GLOBALS['meta']['urls_propres'])?unserialize($GLOBALS['meta']['urls_propres']):array(); 49 if (!defined('_terminaison_urls_propres')) { 50 define('_terminaison_urls_propres', ''); 51 } 52 if (!defined('_debut_urls_propres')) { 53 define('_debut_urls_propres', ''); 54 } 55 56 $config_urls_propres = isset($GLOBALS['meta']['urls_propres']) ? unserialize($GLOBALS['meta']['urls_propres']) : array(); 51 57 // pour choisir le caractere de separation titre-id en cas de doublon 52 58 // (ne pas utiliser '/') 53 if (!defined('_url_propres_sep_id')) define('_url_propres_sep_id',isset($config_urls_propres['url_propres_sep_id'])?$config_urls_propres['url_propres_sep_id']:'-'); 59 if (!defined('_url_propres_sep_id')) { 60 define('_url_propres_sep_id', isset($config_urls_propres['url_propres_sep_id']) ? $config_urls_propres['url_propres_sep_id'] : '-'); 61 } 54 62 // option pour tout passer en minuscules 55 if (!defined('_url_minuscules')) define('_url_minuscules',isset($config_urls_propres['url_minuscules'])?$config_urls_propres['url_minuscules']:0); 56 if (!defined('_URLS_PROPRES_MAX')) define('_URLS_PROPRES_MAX', isset($config_urls_propres['URLS_PROPRES_MAX'])?$config_urls_propres['URLS_PROPRES_MAX']:80); 57 if (!defined('_URLS_PROPRES_MIN')) define('_URLS_PROPRES_MIN', isset($config_urls_propres['URLS_PROPRES_MIN'])?$config_urls_propres['URLS_PROPRES_MIN']:3); 58 59 if (!defined('_url_sep_id')) define('_url_sep_id',_url_propres_sep_id); 63 if (!defined('_url_minuscules')) { 64 define('_url_minuscules', isset($config_urls_propres['url_minuscules']) ? $config_urls_propres['url_minuscules'] : 0); 65 } 66 if (!defined('_URLS_PROPRES_MAX')) { 67 define('_URLS_PROPRES_MAX', isset($config_urls_propres['URLS_PROPRES_MAX']) ? $config_urls_propres['URLS_PROPRES_MAX'] : 80); 68 } 69 if (!defined('_URLS_PROPRES_MIN')) { 70 define('_URLS_PROPRES_MIN', isset($config_urls_propres['URLS_PROPRES_MIN']) ? $config_urls_propres['URLS_PROPRES_MIN'] : 3); 71 } 72 73 if (!defined('_url_sep_id')) { 74 define('_url_sep_id', _url_propres_sep_id); 75 } 60 76 61 77 // Ces chaines servaient de marqueurs a l'epoque ou les URL propres devaient … … 65 81 // Les preg_match restent necessaires pour gerer les anciens signets. 66 82 67 if (!defined('_MARQUEUR_URL')) define('_MARQUEUR_URL', serialize(array('rubrique1' => '-', 'rubrique2' => '-', 'breve1' => '+', 'breve2' => '+', 'site1' => '@', 'site2' => '@', 'auteur1' => '_', 'auteur2' => '_', 'mot1' => '+-', 'mot2' => '-+'))); 83 if (!defined('_MARQUEUR_URL')) { 84 define('_MARQUEUR_URL', serialize(array( 85 'rubrique1' => '-', 86 'rubrique2' => '-', 87 'breve1' => '+', 88 'breve2' => '+', 89 'site1' => '@', 90 'site2' => '@', 91 'auteur1' => '_', 92 'auteur2' => '_', 93 'mot1' => '+-', 94 'mot2' => '-+' 95 ))); 96 } 68 97 69 98 // Retire les marqueurs de type dans une URL propre ancienne maniere … … 73 102 if (preg_match(',^[+][-](.*?)[-][+]$,', $url_propre, $regs)) { 74 103 return $regs[1]; 75 } 76 else if (preg_match(',^([-+_@])(.*?)\1?$,', $url_propre, $regs)) { 77 return $regs[2]; 78 } 104 } else { 105 if (preg_match(',^([-+_@])(.*?)\1?$,', $url_propre, $regs)) { 106 return $regs[2]; 107 } 108 } 109 79 110 // les articles n'ont pas de marqueur 80 111 return $url_propre; … … 95 126 96 127 include_spip('action/editer_url'); 97 if (!$url = url_nettoyer($objet['titre'],_URLS_PROPRES_MAX,_URLS_PROPRES_MIN,'-',_url_minuscules?'strtolower':'')) 98 $url = $objet['type'].$objet['id_objet']; 128 if (!$url = url_nettoyer($objet['titre'], _URLS_PROPRES_MAX, _URLS_PROPRES_MIN, '-', 129 _url_minuscules ? 'strtolower' : '') 130 ) { 131 $url = $objet['type'] . $objet['id_objet']; 132 } 99 133 100 134 $x['data'] = $url; … … 111 145 $table = $desc['table']; 112 146 $champ_titre = $desc['titre'] ? $desc['titre'] : 'titre'; 113 $col_id = @$desc['key']["PRIMARY KEY"]; 114 if (!$col_id) return false; // Quand $type ne reference pas une table 147 $col_id = @$desc['key']["PRIMARY KEY"]; 148 if (!$col_id) { 149 return false; 150 } // Quand $type ne reference pas une table 115 151 116 152 $id_objet = intval($id_objet); … … 121 157 // de preference avec id_parent=0, puis perma, puis par date desc 122 158 $row = sql_fetsel("U.url, U.date, U.id_parent, U.perma, $champ_titre", 123 "$table AS O LEFT JOIN spip_urls AS U ON (U.type='$type' AND U.id_objet=O.$col_id)", 124 "O.$col_id=$id_objet AND (U.segments IS NULL OR U.segments=1)", '', 'U.id_parent=0 DESC, U.perma DESC, U.date DESC', 1); 159 "$table AS O LEFT JOIN spip_urls AS U ON (U.type='$type' AND U.id_objet=O.$col_id)", 160 "O.$col_id=$id_objet AND (U.segments IS NULL OR U.segments=1)", '', 'U.id_parent=0 DESC, U.perma DESC, U.date DESC', 161 1); 125 162 126 163 // en SQLite le left join retourne du vide si il y a une url mais qui ne correspond pas pour la condition sur le segment 127 164 // on verifie donc que l'objet existe bien avant de sortir ou de creer une url pour cet objet 128 if (!$row) 165 if (!$row) { 129 166 $row = sql_fetsel("'' as url, '' as date, 0 as id_parent, 0 as perma, $champ_titre", 130 "$table AS O", 131 "O.$col_id=$id_objet"); 132 133 if (!$row) return ""; # Quand $id_objet n'est pas un numero connu 167 "$table AS O", 168 "O.$col_id=$id_objet"); 169 } 170 171 if (!$row) { 172 return ""; 173 } # Quand $id_objet n'est pas un numero connu 134 174 135 175 $url_propre = $row['url']; 136 176 137 177 // si url_propre connue mais avec id_parent non nul, essayer de reinserer tel quel avec id_parent=0 138 if ($url_propre AND $row['id_parent']) {178 if ($url_propre AND $row['id_parent']) { 139 179 include_spip('action/editer_url'); 140 180 $set = array('url' => $url_propre, 'type' => $type, 'id_objet' => $id_objet, 'perma' => $row['perma']); 141 181 // si on arrive pas a reinserer tel quel, on annule url_propre pour forcer un recalcul d'url 142 if (!url_insert($set, false,_url_propres_sep_id))182 if (!url_insert($set, false, _url_propres_sep_id)) { 143 183 $url_propre = ""; 144 else184 } else { 145 185 $url_propre = $row['url'] = $set['url']; 186 } 146 187 } 147 188 … … 153 194 // qui requetent en base 154 195 $modifier_url = (defined('_VAR_URLS') AND _VAR_URLS AND !$row['perma']); 155 if ($url_propre AND !$modifier_url) 196 if ($url_propre AND !$modifier_url) { 156 197 return $url_propre; 198 } 157 199 158 200 // Sinon, creer une URL … … 170 212 include_spip('inc/urls'); 171 213 $objets = urls_liste_objets(); 172 if (preg_match(',^('.$objets.')[0-9]+$,', $url, $r) 173 AND $r[1] != $type) 174 $url = $url._url_propres_sep_id.$id_objet; 214 if (preg_match(',^(' . $objets . ')[0-9]+$,', $url, $r) 215 AND $r[1] != $type 216 ) { 217 $url = $url . _url_propres_sep_id . $id_objet; 218 } 175 219 176 220 // Pas de changement d'url 177 if ($url == $url_propre) 221 if ($url == $url_propre) { 178 222 return $url_propre; 223 } 179 224 180 225 // verifier l'autorisation, maintenant qu'on est sur qu'on va agir … … 188 233 AND CONFIRMER_MODIFIER_URL 189 234 AND $url_propre 190 AND $url != preg_replace('/'.preg_quote(_url_propres_sep_id,'/').'.*/', '', $url_propre)) 235 AND $url != preg_replace('/' . preg_quote(_url_propres_sep_id, '/') . '.*/', '', $url_propre) 236 ) { 191 237 $confirmer = true; 192 else238 } else { 193 239 $confirmer = false; 240 } 194 241 195 242 if ($confirmer AND !_request('ok')) { … … 199 246 $set = array('url' => $url, 'type' => $type, 'id_objet' => $id_objet); 200 247 include_spip('action/editer_url'); 201 if (!url_insert($set,$confirmer,_url_propres_sep_id)) 202 return $url_propre; //serveur out ? retourner au mieux 248 if (!url_insert($set, $confirmer, _url_propres_sep_id)) { 249 return $url_propre; 250 } //serveur out ? retourner au mieux 203 251 204 252 return $set['url']; … … 208 256 function _generer_url_propre($type, $id, $args = '', $ancre = '') { 209 257 210 if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls',true)) {258 if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) { 211 259 $url = $generer_url_externe($id, $args, $ancre); 212 if (NULL != $url) return $url; 260 if (null != $url) { 261 return $url; 262 } 213 263 } 214 264 … … 216 266 if (_MARQUEUR_URL) { 217 267 $marqueur = unserialize(_MARQUEUR_URL); 218 $marqueur1 = isset($marqueur[$type .'1']) ? $marqueur[$type.'1'] : ''; // debut '+-'219 $marqueur2 = isset($marqueur[$type .'2']) ? $marqueur[$type.'2'] : ''; // fin '-+'220 } else 268 $marqueur1 = isset($marqueur[$type . '1']) ? $marqueur[$type . '1'] : ''; // debut '+-' 269 $marqueur2 = isset($marqueur[$type . '2']) ? $marqueur[$type . '2'] : ''; // fin '-+' 270 } else { 221 271 $marqueur1 = $marqueur2 = ''; 272 } 222 273 // fin 223 274 … … 225 276 $propre = declarer_url_propre($type, $id); 226 277 227 if ($propre === false) return ''; // objet inconnu. raccourci ? 278 if ($propre === false) { 279 return ''; 280 } // objet inconnu. raccourci ? 228 281 229 282 if ($propre) { … … 236 289 // les urls de type /1234 sont interpretees comme urls courte vers article 1234 237 290 // on les encadre d'un - : /-1234- 238 if (is_numeric($url)) {239 $url = "-" .$url."-";240 } 241 242 if (!defined('_SET_HTML_BASE') OR !_SET_HTML_BASE) 243 // Repositionne l'URL par rapport a la racine du site (#GLOBALS)244 $url = str_repeat('../', $GLOBALS['profondeur_url']) .$url;245 else291 if (is_numeric($url)) { 292 $url = "-" . $url . "-"; 293 } 294 295 if (!defined('_SET_HTML_BASE') OR !_SET_HTML_BASE) // Repositionne l'URL par rapport a la racine du site (#GLOBALS) 296 { 297 $url = str_repeat('../', $GLOBALS['profondeur_url']) . $url; 298 } else { 246 299 $url = _DIR_RACINE . $url; 300 } 247 301 } else { 248 302 … … 250 304 include_spip('base/connect_sql'); 251 305 $id_type = id_table_objet($type); 252 $url = _DIR_RACINE . get_spip_script('./') ."?"._SPIP_PAGE."=$type&$id_type=$id";306 $url = _DIR_RACINE . get_spip_script('./') . "?" . _SPIP_PAGE . "=$type&$id_type=$id"; 253 307 } 254 308 255 309 // Ajouter les args 256 if ($args) 257 $url .= ((strpos($url, '?')===false) ? '?' : '&') . $args; 310 if ($args) { 311 $url .= ((strpos($url, '?') === false) ? '?' : '&') . $args; 312 } 258 313 259 314 // Ajouter l'ancre 260 if ($ancre) 315 if ($ancre) { 261 316 $url .= "#$ancre"; 317 } 262 318 263 319 return $url; … … 270 326 function urls_propres_dist($i, $entite, $args = '', $ancre = '') { 271 327 272 if (is_numeric($i)) 328 if (is_numeric($i)) { 273 329 return _generer_url_propre($entite, $i, $args, $ancre); 330 } 274 331 275 332 $url = $i; … … 277 334 $url_redirect = null; 278 335 // recuperer les &debut_xx; 279 if (is_array($args)) 336 if (is_array($args)) { 280 337 $contexte = $args; 281 else 282 parse_str($args,$contexte); 338 } else { 339 parse_str($args, $contexte); 340 } 283 341 284 342 285 343 // Migration depuis anciennes URLs ? 286 344 // traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23 287 if ($GLOBALS['profondeur_url']<=0 288 AND $_SERVER['REQUEST_METHOD'] != 'POST') { 345 if ($GLOBALS['profondeur_url'] <= 0 346 AND $_SERVER['REQUEST_METHOD'] != 'POST' 347 ) { 289 348 include_spip('inc/urls'); 290 349 $r = nettoyer_url_page($i, $contexte); 291 350 if ($r) { 292 list($contexte, $type, ,, $suite) = $r;351 list($contexte, $type, , , $suite) = $r; 293 352 $_id = id_table_objet($type); 294 353 $id_objet = $contexte[$_id]; 295 354 $url_propre = generer_url_entite($id_objet, $type); 296 355 if (strlen($url_propre) 297 AND !strstr($url,$url_propre)) { 298 list(,$hash) = array_pad(explode('#', $url_propre), 2, null); 356 AND !strstr($url, $url_propre) 357 ) { 358 list(, $hash) = array_pad(explode('#', $url_propre), 2, null); 299 359 $args = array(); 300 foreach (array_filter(explode('&', $suite)) as $fragment) {301 if ($fragment != "$_id=$id_objet") 360 foreach (array_filter(explode('&', $suite)) as $fragment) { 361 if ($fragment != "$_id=$id_objet") { 302 362 $args[] = $fragment; 363 } 303 364 } 304 $url_redirect = generer_url_entite($id_objet, $type, join('&', array_filter($args)), $hash);365 $url_redirect = generer_url_entite($id_objet, $type, join('&', array_filter($args)), $hash); 305 366 306 367 return array($contexte, $type, $url_redirect, $type); … … 316 377 $is_qs = false; 317 378 if (!$url_propre 318 AND preg_match(',[?]([^=/?&]+)(&.*)?$,', $url, $r)) { 379 AND preg_match(',[?]([^=/?&]+)(&.*)?$,', $url, $r) 380 ) { 319 381 $url_propre = $r[1]; 320 382 $is_qs = true; … … 322 384 323 385 if (!$url_propre 324 OR $url_propre==_DIR_RESTREINT_ABS 325 OR $url_propre==_SPIP_SCRIPT) return; // qu'est-ce qu'il veut ??? 326 327 386 OR $url_propre == _DIR_RESTREINT_ABS 387 OR $url_propre == _SPIP_SCRIPT 388 ) { 389 return; 390 } // qu'est-ce qu'il veut ??? 391 392 328 393 // gerer le cas de retour depuis des urls arbos 329 394 // mais si url arbo ne trouve pas, on veut une 404 par securite 330 if ($GLOBALS['profondeur_url']>0 AND !defined('_FORCE_URLS_PROPRES')){ 331 $urls_anciennes = charger_fonction('arbo','urls'); 395 if ($GLOBALS['profondeur_url'] > 0 AND !defined('_FORCE_URLS_PROPRES')) { 396 $urls_anciennes = charger_fonction('arbo', 'urls'); 397 332 398 return $urls_anciennes($url_propre, $entite, $contexte); 333 399 } 334 400 335 401 include_spip('base/abstract_sql'); // chercher dans la table des URLS 336 402 … … 343 409 // Compatibilite avec les anciens marqueurs d'URL propres 344 410 // Tester l'entree telle quelle (avec 'url_libre' des sites ont pu avoir des entrees avec marqueurs dans la table spip_urls) 345 if (!$row = sql_fetsel('id_objet, type, date, url', 'spip_urls', 'url=' .sql_quote($url_propre, '', 'TEXT'))) {411 if (!$row = sql_fetsel('id_objet, type, date, url', 'spip_urls', 'url=' . sql_quote($url_propre, '', 'TEXT'))) { 346 412 // Sinon enlever les marqueurs eventuels 347 413 $url_propre2 = retirer_marqueurs_url_propre($url_propre); 348 414 349 $row = sql_fetsel('id_objet, type, date, url', 'spip_urls', 'url=' .sql_quote($url_propre2, '', 'TEXT'));415 $row = sql_fetsel('id_objet, type, date, url', 'spip_urls', 'url=' . sql_quote($url_propre2, '', 'TEXT')); 350 416 } 351 417 … … 358 424 // Si l'url est vieux, donner le nouveau 359 425 if ($recent = sql_fetsel('url, date', 'spip_urls', 360 'type='.sql_quote($row['type'], '', 'TEXT').' AND id_objet='.sql_quote($row['id_objet']) 361 .' AND date>'.sql_quote($row['date'], '', 'TEXT') 362 .' AND url<>'.sql_quote($row['url'], '', 'TEXT'), '', 'date DESC', 1)) { 426 'type=' . sql_quote($row['type'], '', 'TEXT') . ' AND id_objet=' . sql_quote($row['id_objet']) 427 . ' AND date>' . sql_quote($row['date'], '', 'TEXT') 428 . ' AND url<>' . sql_quote($row['url'], '', 'TEXT'), '', 'date DESC', 1) 429 ) { 363 430 // Mode compatibilite pour conserver la distinction -Rubrique- 364 431 if (_MARQUEUR_URL) { 365 432 $marqueur = unserialize(_MARQUEUR_URL); 366 $marqueur1 = $marqueur[$type .'1']; // debut '+-'367 $marqueur2 = $marqueur[$type .'2']; // fin '-+'368 } else 433 $marqueur1 = $marqueur[$type . '1']; // debut '+-' 434 $marqueur2 = $marqueur[$type . '2']; // fin '-+' 435 } else { 369 436 $marqueur1 = $marqueur2 = ''; 437 } 370 438 $url_redirect = $marqueur1 . $recent['url'] . $marqueur2; 371 439 } 372 440 } 373 441 374 if ($entite =='' OR $entite=='type_urls' /* compat .htaccess 2.0 */) {442 if ($entite == '' OR $entite == 'type_urls' /* compat .htaccess 2.0 */) { 375 443 if ($type) { 376 $entite = 444 $entite = objet_type($type); 377 445 } else { 378 446 // Si ca ressemble a une URL d'objet, ce n'est pas la home … … 388 456 $fmarqueur = @array_flip(unserialize(_MARQUEUR_URL)); 389 457 preg_match(',^([+][-]|[-+@_]),', $url_propre, $regs); 390 $objet = $regs ? substr($fmarqueur[$regs[1]], 0,n-1) : 'article';458 $objet = $regs ? substr($fmarqueur[$regs[1]], 0, n-1) : 'article'; 391 459 $contexte['erreur'] = _T( 392 ($objet =='rubrique' OR $objet=='breve')393 ? 'public:aucune_' .$objet394 : 'public:aucun_' .$objet460 ($objet == 'rubrique' OR $objet == 'breve') 461 ? 'public:aucune_' . $objet 462 : 'public:aucun_' . $objet 395 463 ); 396 464 } … … 399 467 } 400 468 401 return array($contexte, $entite, $url_redirect, $is_qs ?$entite:null);469 return array($contexte, $entite, $url_redirect, $is_qs ? $entite : null); 402 470 } 403 471 -
_core_/plugins/urls_etendues/urls/propres2.php
r93092 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; // securiser 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } // securiser 14 16 15 17 /* … … 23 25 define('URLS_PROPRES2_CONFIG', 'propres'); 24 26 25 if (!defined('_terminaison_urls_propres')) 26 define ('_terminaison_urls_propres', '.html'); 27 if (!defined('_terminaison_urls_propres')) { 28 define('_terminaison_urls_propres', '.html'); 29 } 27 30 28 31 // http://code.spip.net/@urls_propres2_dist 29 32 function urls_propres2_dist($i, &$entite, $args = '', $ancre = '') { 30 33 $f = charger_fonction('propres', 'urls'); 34 31 35 return $f($i, $entite, $args, $ancre); 32 36 } -
_core_/plugins/urls_etendues/urls/propres_qs.php
r93092 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined("_ECRIRE_INC_VERSION")) return; // securiser 13 if (!defined("_ECRIRE_INC_VERSION")) { 14 return; 15 } // securiser 14 16 15 17 /* … … 30 32 define('URLS_PROPRES_QS_CONFIG', 'propres'); 31 33 32 if (!defined('_terminaison_urls_propres')) 33 define ('_terminaison_urls_propres', ''); 34 if (!defined('_terminaison_urls_propres')) { 35 define('_terminaison_urls_propres', ''); 36 } 34 37 35 defined('_debut_urls_propres') || define 38 defined('_debut_urls_propres') || define('_debut_urls_propres', './?'); 36 39 37 40 // http://code.spip.net/@urls_propres_qs_dist 38 41 function urls_propres_qs_dist($i, &$entite, $args = '', $ancre = '') { 39 42 $f = charger_fonction('propres', 'urls'); 43 40 44 return $f($i, $entite, $args, $ancre); 41 45 } 46 42 47 ?> -
_core_/plugins/urls_etendues/urls/simple.php
r93092 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined('_ECRIRE_INC_VERSION')) return; 13 if (!defined('_ECRIRE_INC_VERSION')) { 14 return; 15 } 14 16 15 17 # donner un exemple d'url pour le formulaire de choix … … 18 20 ####### modifications possibles dans ecrire/mes_options 19 21 # on peut indiquer '.html' pour faire joli 20 define 21 define ('_debut_urls_simple', get_spip_script('./').'?'._SPIP_PAGE.'=');22 define('_terminaison_urls_simple', ''); 23 define('_debut_urls_simple', get_spip_script('./') . '?' . _SPIP_PAGE . '='); 22 24 ####### 23 25 … … 25 27 function _generer_url_simple($type, $id, $args = '', $ancre = '') { 26 28 27 if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls',true)) {29 if ($generer_url_externe = charger_fonction("generer_url_$type", 'urls', true)) { 28 30 $url = $generer_url_externe($id, $args, $ancre); 29 if (NULL != $url) return $url; 31 if (null != $url) { 32 return $url; 33 } 30 34 } 31 35 32 36 $url = _debut_urls_simple . $type 33 34 37 . "&" . id_table_objet($type) . "=" 38 . $id . _terminaison_urls_page; 35 39 36 if ($args) $args = strpos($url,'?') ? "&$args" : "?$args"; 40 if ($args) { 41 $args = strpos($url, '?') ? "&$args" : "?$args"; 42 } 43 37 44 return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : ''); 38 45 } … … 41 48 // le contexte deja existant est fourni dans args sous forme de tableau ou query string 42 49 // http://code.spip.net/@urls_page_dist 43 function urls_simple_dist($i, &$entite, $args = '', $ancre = '') 44 { 45 if (is_numeric($i)){ 50 function urls_simple_dist($i, &$entite, $args = '', $ancre = '') { 51 if (is_numeric($i)) { 46 52 include_spip('urls/page'); 53 47 54 return _generer_url_simple($entite, $i, $args, $ancre); 48 55 } 49 56 // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23 50 if ($GLOBALS['profondeur_url'] >0 AND $entite=='sommaire'){51 return array(array(), '404');57 if ($GLOBALS['profondeur_url'] > 0 AND $entite == 'sommaire') { 58 return array(array(), '404'); 52 59 } 53 60 54 61 // voir s'il faut recuperer le id_* implicite et les &debut_xx; 55 if (is_array($args)) 62 if (is_array($args)) { 56 63 $contexte = $args; 57 else 58 parse_str($args,$contexte); 64 } else { 65 parse_str($args, $contexte); 66 } 59 67 include_spip('inc/urls'); 60 68 $r = nettoyer_url_page($i, $contexte); … … 65 73 66 74 if ($type = _request(_SPIP_PAGE) 67 AND $_id = id_table_objet($type) 68 AND $id = _request($_id)){ 75 AND $_id = id_table_objet($type) 76 AND $id = _request($_id) 77 ) { 69 78 $contexte[$_id] = $id; 79 70 80 return array($contexte, $type, null, $type); 71 81 } … … 81 91 $url_propre = $i; 82 92 if ($url_propre) { 83 if ($GLOBALS['profondeur_url']<=0) 84 $urls_anciennes = charger_fonction('propres','urls',true); 85 else 86 $urls_anciennes = charger_fonction('arbo','urls',true); 87 return $urls_anciennes?$urls_anciennes($url_propre, $entite, $contexte):''; 93 if ($GLOBALS['profondeur_url'] <= 0) { 94 $urls_anciennes = charger_fonction('propres', 'urls', true); 95 } else { 96 $urls_anciennes = charger_fonction('arbo', 'urls', true); 97 } 98 99 return $urls_anciennes ? $urls_anciennes($url_propre, $entite, $contexte) : ''; 88 100 } 89 101 /* Fin du bloc compatibilite url-propres */ -
_core_/plugins/urls_etendues/urls_administrations.php
r93092 r93629 11 11 \***************************************************************************/ 12 12 13 if (!defined('_ECRIRE_INC_VERSION')) return; 13 if (!defined('_ECRIRE_INC_VERSION')) { 14 return; 15 } 14 16 15 17 /** … … 19 21 * @param string $version_cible 20 22 */ 21 function urls_upgrade($nom_meta_base_version, $version_cible) {23 function urls_upgrade($nom_meta_base_version, $version_cible) { 22 24 // cas particulier : 23 25 // si plugin pas installe mais que la table existe 24 26 // considerer que c'est un upgrade depuis v 1.0.0 25 27 // pour gerer l'historique des installations SPIP <=2.1 26 if (!isset($GLOBALS['meta'][$nom_meta_base_version])) {27 $trouver_table = charger_fonction('trouver_table', 'base');28 if (!isset($GLOBALS['meta'][$nom_meta_base_version])) { 29 $trouver_table = charger_fonction('trouver_table', 'base'); 28 30 if ($desc = $trouver_table('spip_urls') 29 AND isset($desc['exist']) AND $desc['exist'] 30 AND !isset($desc['field']['id_parent'])){ 31 ecrire_meta($nom_meta_base_version,'1.0.0'); 31 AND isset($desc['exist']) AND $desc['exist'] 32 AND !isset($desc['field']['id_parent']) 33 ) { 34 ecrire_meta($nom_meta_base_version, '1.0.0'); 32 35 } 33 36 // si pas de table en base, on fera une simple creation de base … … 36 39 $maj = array(); 37 40 $maj['create'] = array( 38 array('maj_tables', array('spip_urls')),41 array('maj_tables', array('spip_urls')), 39 42 ); 40 43 $maj['1.1.0'] = array( 41 array('sql_alter', "table spip_urls ADD id_parent bigint(21) DEFAULT '0' NOT NULL"),42 array('sql_alter', "table spip_urls DROP PRIMARY KEY"),43 array('sql_alter', "table spip_urls ADD PRIMARY KEY (id_parent, url)"),44 array('sql_alter', "table spip_urls ADD id_parent bigint(21) DEFAULT '0' NOT NULL"), 45 array('sql_alter', "table spip_urls DROP PRIMARY KEY"), 46 array('sql_alter', "table spip_urls ADD PRIMARY KEY (id_parent, url)"), 44 47 ); 45 48 $maj['1.1.1'] = array( … … 48 51 49 52 $maj['1.1.2'] = array( 50 array('sql_alter', "table spip_urls ADD segments SMALLINT(3) DEFAULT '1' NOT NULL"),53 array('sql_alter', "table spip_urls ADD segments SMALLINT(3) DEFAULT '1' NOT NULL"), 51 54 array('urls_migre_urls_segments'), 52 55 ); 53 56 $maj['1.1.3'] = array( 54 array('sql_alter', "table spip_urls ADD perma TINYINT(1) DEFAULT '0' NOT NULL"),57 array('sql_alter', "table spip_urls ADD perma TINYINT(1) DEFAULT '0' NOT NULL"), 55 58 ); 56 59 $maj['1.1.4'] = array( 57 array('sql_alter', "table spip_urls CHANGE `type` `type` varchar(25) DEFAULT 'article' NOT NULL"),60 array('sql_alter', "table spip_urls CHANGE `type` `type` varchar(25) DEFAULT 'article' NOT NULL"), 58 61 ); 59 62 … … 62 65 } 63 66 64 function urls_migre_arbo_prefixes(){ 65 $res = sql_select('*','spip_urls',"url REGEXP '\d+:\/\/'"); 66 while($row = sql_fetch($res)){ 67 $url = explode("://",$row['url']); 68 $set = array('id_parent'=>intval(reset($url)),'url'=>end($url)); 69 if (!sql_updateq('spip_urls',$set,"id_parent=".intval($row['id_parent'])." AND url=".sql_quote($row['url']))){ 70 if ($set['id_parent']==0 71 AND sql_countsel('spip_urls',"id_parent=".intval($set['id_parent'])." AND url=".sql_quote($set['url'])." AND type=".sql_quote($row['type'])." AND id_objet=".sql_quote($row['id_objet']))){ 72 spip_log('suppression url doublon '.var_export($row,1),'urls.'._LOG_INFO_IMPORTANTE); 73 sql_delete('spip_urls',"id_parent=".intval($row['id_parent'])." AND url=".sql_quote($row['url'])); 74 } 75 else { 76 spip_log('Impossible de convertir url doublon '.var_export($row,1),'urls.'._LOG_ERREUR); 77 echo "Impossible de convertir l'url ".$row['url'].". Verifiez manuellement dans spip_urls"; 67 function urls_migre_arbo_prefixes() { 68 $res = sql_select('*', 'spip_urls', "url REGEXP '\d+:\/\/'"); 69 while ($row = sql_fetch($res)) { 70 $url = explode("://", $row['url']); 71 $set = array('id_parent' => intval(reset($url)), 'url' => end($url)); 72 if (!sql_updateq('spip_urls', $set, 73 "id_parent=" . intval($row['id_parent']) . " AND url=" . sql_quote($row['url'])) 74 ) { 75 if ($set['id_parent'] == 0 76 AND sql_countsel('spip_urls', 77 "id_parent=" . intval($set['id_parent']) . " AND url=" . sql_quote($set['url']) . " AND type=" . sql_quote($row['type']) . " AND id_objet=" . sql_quote($row['id_objet'])) 78 ) { 79 spip_log('suppression url doublon ' . var_export($row, 1), 'urls.' . _LOG_INFO_IMPORTANTE); 80 sql_delete('spip_urls', "id_parent=" . intval($row['id_parent']) . " AND url=" . sql_quote($row['url'])); 81 } else { 82 spip_log('Impossible de convertir url doublon ' . var_export($row, 1), 'urls.' . _LOG_ERREUR); 83 echo "Impossible de convertir l'url " . $row['url'] . ". Verifiez manuellement dans spip_urls"; 78 84 } 79 85 } 80 if (time() >= _TIME_OUT) {86 if (time() >= _TIME_OUT) { 81 87 sql_free($res); 88 82 89 return; 83 90 } … … 85 92 } 86 93 87 function urls_migre_urls_segments() {88 sql_updateq('spip_urls', array('segments'=>1),"segments<1 OR NOT(url REGEXP '\/')");89 $res = sql_select('DISTINCT url', 'spip_urls',"url REGEXP '\/' AND segments=1");90 while ($row = sql_fetch($res)){91 $segments = count(explode('/', $row['url']));92 sql_updateq('spip_urls', array('segments'=>$segments),"url=".sql_quote($row['url']));93 if (time() >= _TIME_OUT) {94 function urls_migre_urls_segments() { 95 sql_updateq('spip_urls', array('segments' => 1), "segments<1 OR NOT(url REGEXP '\/')"); 96 $res = sql_select('DISTINCT url', 'spip_urls', "url REGEXP '\/' AND segments=1"); 97 while ($row = sql_fetch($res)) { 98 $segments = count(explode('/', $row['url'])); 99 sql_updateq('spip_urls', array('segments' => $segments), "url=" . sql_quote($row['url'])); 100 if (time() >= _TIME_OUT) { 94 101 sql_free($res); 102 95 103 return; 96 104 } … … 105 113 function urls_vider_tables($nom_meta_base_version) { 106 114 // repasser dans les urls par defaut 107 ecrire_meta('type_urls', 'page');115 ecrire_meta('type_urls', 'page'); 108 116 sql_drop_table("spip_urls"); 109 117 effacer_meta($nom_meta_base_version); -
_core_/plugins/urls_etendues/urls_ieconfig.php
r57808 r93629 1 1 <?php 2 2 3 if (!defined("_ECRIRE_INC_VERSION")) return; 3 if (!defined("_ECRIRE_INC_VERSION")) { 4 return; 5 } 4 6 5 function urls_ieconfig_metas($table) {7 function urls_ieconfig_metas($table) { 6 8 $table['urls']['titre'] = _T('urls:titre_type_urls'); 7 9 $table['urls']['icone'] = 'url-16.png'; 8 10 $table['urls']['metas_brutes'] = 'type_urls,urls_activer_controle'; 9 11 $table['urls']['metas_serialize'] = 'urls_propres,urls_arbo'; 10 12 11 13 return $table; 12 14 } -
_core_/plugins/urls_etendues/urls_pipeline.php
r93431 r93629 10 10 \***************************************************************************/ 11 11 12 if (!defined('_ECRIRE_INC_VERSION')) return; 12 if (!defined('_ECRIRE_INC_VERSION')) { 13 return; 14 } 13 15 14 function urls_autoriser($f) {return $f;}16 function urls_autoriser($f) { return $f; } 15 17 16 function autoriser_url_administrer($faire, $type = '', $id = 0, $qui = NULL, $opt = NULL){18 function autoriser_url_administrer($faire, $type = '', $id = 0, $qui = null, $opt = null) { 17 19 return ( 18 20 isset($GLOBALS['meta']['urls_activer_controle']) 19 AND $GLOBALS['meta']['urls_activer_controle'] =='oui'20 AND $qui['statut']=='0minirezo'21 21 AND $GLOBALS['meta']['urls_activer_controle'] == 'oui' 22 AND $qui['statut'] == '0minirezo' 23 AND !$qui['restreint']); 22 24 } 23 25 24 function autoriser_controlerurls_menu_dist($faire, $type = '', $id = 0, $qui = NULL, $opt = NULL){25 return autoriser('administrer', 'url');26 function autoriser_controlerurls_menu_dist($faire, $type = '', $id = 0, $qui = null, $opt = null) { 27 return autoriser('administrer', 'url'); 26 28 } 27 29 28 function autoriser_modifierurl($faire, $type ='', $id=0, $qui = NULL, $opt = NULL){29 if (autoriser('modifier', $type,$id,$qui,$opt)){30 function autoriser_modifierurl($faire, $type = '', $id = 0, $qui = null, $opt = null) { 31 if (autoriser('modifier', $type, $id, $qui, $opt)) { 30 32 return true; 31 33 } … … 38 40 $table_sql = table_objet_sql($type); 39 41 $primary = id_table_objet($type); 40 if (!sql_countsel($table_sql, "$primary=".intval($id))){41 return autoriser('administrer', 'url');42 if (!sql_countsel($table_sql, "$primary=" . intval($id))) { 43 return autoriser('administrer', 'url'); 42 44 } 45 43 46 return false; 44 47 } 45 48 46 function urls_afficher_fiche_objet($flux) {49 function urls_afficher_fiche_objet($flux) { 47 50 if (isset($GLOBALS['meta']['urls_activer_controle']) 48 AND $GLOBALS['meta']['urls_activer_controle'] =='oui'51 AND $GLOBALS['meta']['urls_activer_controle'] == 'oui' 49 52 AND $objet = $flux['args']['type'] 50 53 AND $id_objet = $flux['args']['id'] 51 AND objet_info($objet,'page')){ 52 $p = strpos($flux['data'],'fiche_objet'); 53 $p = strpos($flux['data'],'<!--/hd-->',$p); 54 AND objet_info($objet, 'page') 55 ) { 56 $p = strpos($flux['data'], 'fiche_objet'); 57 $p = strpos($flux['data'], '<!--/hd-->', $p); 54 58 //$p = strrpos(substr($flux['data'],0,$p),'<div'); 55 59 56 $res = recuperer_fond('prive/objets/editer/url',array('id_objet'=>$id_objet,'objet'=>$objet),array('ajax'=>true)); 57 $flux['data'] = substr_replace($flux['data'],$res, $p, 0); 60 $res = recuperer_fond('prive/objets/editer/url', array('id_objet' => $id_objet, 'objet' => $objet), 61 array('ajax' => true)); 62 $flux['data'] = substr_replace($flux['data'], $res, $p, 0); 58 63 } 64 59 65 return $flux; 60 66 } 67 61 68 ?>
Note: See TracChangeset
for help on using the changeset viewer.