Browse Source

feat(dev-tools): Mise en place phpcs+phpstan (#4807)

à titre d'exemple, mise en place des outils de développement pour un plugin, passe d'autofix et baseline pour phpstan.

Co-authored-by: JamesRezo <james@rezo.net>
Reviewed-on: #4807
Co-authored-by: JamesRezo <jamesrezo@noreply.git.spip.net>
Co-committed-by: JamesRezo <jamesrezo@noreply.git.spip.net>
master
JamesRezo 3 months ago
parent
commit
be5ab43101
  1. 7
      .gitignore
  2. 134
      action/editer_url.php
  3. 16
      action/supprimer_url.php
  4. 11
      action/urls_actualiser.php
  5. 30
      base/urls.php
  6. 7
      composer.json
  7. 22
      formulaires/configurer_urls.php
  8. 31
      formulaires/editer_url_objet.php
  9. 14
      phpcs.xml.dist
  10. 552
      phpstan-baseline.neon
  11. 11
      phpstan.neon.dist
  12. 5
      prive/squelettes/contenu/configurer_urls_fonctions.php
  13. 161
      urls/arbo.php
  14. 2
      urls/html.php
  15. 66
      urls/propres.php
  16. 7
      urls/simple.php
  17. 92
      urls_administrations.php
  18. 2
      urls_autoriser.php
  19. 4
      urls_fonctions.php
  20. 12
      urls_pipeline.php

7
.gitignore

@ -0,0 +1,7 @@
/vendor/
/composer.phar
/composer.lock
/phpcs.xml
/phpstan.neon
/.php_cs.cache
/.php_cs.txt

134
action/editer_url.php

@ -10,7 +10,7 @@
* Pour plus de détails voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
if (!defined("_ECRIRE_INC_VERSION")) {
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
@ -19,7 +19,6 @@ function action_editer_url_dist() {
// Rien a faire ici pour le moment
#$securiser_action = charger_fonction('securiser_action', 'inc');
#$arg = $securiser_action();
}
/**
@ -70,10 +69,14 @@ function url_nettoyer($titre, $longueur_maxi, $longueur_min = 0, $separateur = '
// S'il reste trop de caracteres non latins, les gerer comme wikipedia
// avec rawurlencode :
if (preg_match_all(",[^a-zA-Z0-9 _]+,", $url, $r, PREG_SET_ORDER)) {
if (preg_match_all(',[^a-zA-Z0-9 _]+,', $url, $r, PREG_SET_ORDER)) {
foreach ($r as $regs) {
$url = substr_replace($url, rawurlencode($regs[0]),
strpos($url, $regs[0]), strlen($regs[0]));
$url = substr_replace(
$url,
rawurlencode($regs[0]),
strpos($url, $regs[0]),
strlen($regs[0])
);
}
}
@ -83,7 +86,7 @@ function url_nettoyer($titre, $longueur_maxi, $longueur_min = 0, $separateur = '
}
// Sinon couper les mots et les relier par des $separateur
$mots = preg_split(",[^a-zA-Z0-9_%]+,", $url);
$mots = preg_split(',[^a-zA-Z0-9_%]+,', $url);
$url = '';
foreach ($mots as $mot) {
if (!strlen($mot)) {
@ -142,19 +145,18 @@ function url_insert(&$set, $confirmer, $separateur) {
# le separateur ne peut pas contenir de /
if (strpos($separateur, '/') !== false) {
$separateur = "-";
$separateur = '-';
}
// Si l'insertion echoue, c'est une violation d'unicite.
$where_urllike = 'url LIKE ' . url_sql_quote_like($set['url']) . " AND NOT(type=" . sql_quote($set['type']) . " AND id_objet=" . intval($set['id_objet']) . ")";
$where_thisurl = $where_urllike . ($has_parent ? " AND id_parent=" . intval($set['id_parent']) : "");
$where_urllike = 'url LIKE ' . url_sql_quote_like($set['url']) . ' AND NOT(type=' . sql_quote($set['type']) . ' AND id_objet=' . intval($set['id_objet']) . ')';
$where_thisurl = $where_urllike . ($has_parent ? ' AND id_parent=' . intval($set['id_parent']) : '');
if (
// si pas de parent defini, il faut que cette url soit unique, independamment de id_parent
// il faut utiliser un LIKE pour etre case unsensitive en sqlite
(!$has_parent and sql_countsel("spip_urls", $where_urllike))
(!$has_parent and sql_countsel('spip_urls', $where_urllike))
or @sql_insertq('spip_urls', $set) <= 0
) {
// On veut chiper une ancienne adresse ou prendre celle d'un repertoire deja present?
if (
(!is_dir(_DIR_RACINE . $set['url']) and !file_exists(_DIR_RACINE . $set['url']))
@ -163,51 +165,58 @@ function url_insert(&$set, $confirmer, $separateur) {
// qui n'est pas permanente
and !$vieux['perma']
// et dont l'objet a une url plus recente
and $courant = sql_fetsel('*', 'spip_urls',
and $courant = sql_fetsel(
'*',
'spip_urls',
'type=' . sql_quote($vieux['type']) . ' AND id_objet=' . sql_quote($vieux['id_objet'])
. ' AND url<>' . sql_quote($set['url'])
. ' AND date>' . sql_quote($vieux['date']), '', 'date DESC', 1)
. ' AND date>' . sql_quote($vieux['date']),
'',
'date DESC',
1
)
) {
if ($confirmer and !_request('ok2')) {
die("Vous voulez chiper l'URL de l'objet " . $courant['type'] . " "
die("Vous voulez chiper l'URL de l'objet " . $courant['type'] . ' '
. $courant['id_objet'] . " qui a maintenant l'url "
. $courant['url']);
}
$where_thisurl = "url=" . sql_quote($vieux['url']) . " AND id_parent=" . intval($vieux['id_parent']);
$where_thisurl = 'url=' . sql_quote($vieux['url']) . ' AND id_parent=' . intval($vieux['id_parent']);
// si oui on le chipe
sql_updateq('spip_urls', $set, $where_thisurl);
sql_updateq('spip_urls', array('date' => date('Y-m-d H:i:s')), $where_thisurl);
spip_log("reattribue url " . $vieux['url']
. " de " . $vieux['type'] . "#" . $vieux['id_objet'] . " (parent " . $vieux['id_parent'] . ")"
. " A " . $set['type'] . "#" . $set['id_objet'] . " (parent " . $set['id_parent'] . ")",
"urls" . _LOG_INFO_IMPORTANTE);
sql_updateq('spip_urls', ['date' => date('Y-m-d H:i:s')], $where_thisurl);
spip_log(
'reattribue url ' . $vieux['url']
. ' de ' . $vieux['type'] . '#' . $vieux['id_objet'] . ' (parent ' . $vieux['id_parent'] . ')'
. ' A ' . $set['type'] . '#' . $set['id_objet'] . ' (parent ' . $set['id_parent'] . ')',
'urls' . _LOG_INFO_IMPORTANTE
);
} // Sinon
else {
// Soit c'est un Come Back d'une ancienne url propre de l'objet
// Soit c'est un vrai conflit. Rajouter l'ID jusqu'a ce que ca passe,
// mais se casser avant que ca ne casse.
// il peut etre du a un changement de casse de l'url simplement
// pour ce cas, on reecrit systematiquement l'url en plus d'actualiser la date
$where = "type=" . sql_quote($set['type'])
. " AND id_objet=" . intval($set['id_objet'])
. " AND id_parent=" . intval($set['id_parent'])
. " AND url LIKE ";
$where = 'type=' . sql_quote($set['type'])
. ' AND id_objet=' . intval($set['id_objet'])
. ' AND id_parent=' . intval($set['id_parent'])
. ' AND url LIKE ';
if (
!is_dir(_DIR_RACINE . $set['url']) and !file_exists(_DIR_RACINE . $set['url'])
and $existing = sql_fetsel('*','spip_urls', $where . url_sql_quote_like($set['url']))
and $existing = sql_fetsel('*', 'spip_urls', $where . url_sql_quote_like($set['url']))
) {
$refresh = array(
$refresh = [
'url' => $set['url'],
'date' => date('Y-m-d H:i:s'),
);
];
// si c'est une URL avec langue est qu'ici on a pas de langue, on ecrase
if ($existing['langue']) {
if (!$set['langue']){
if (!$set['langue']) {
$refresh['langue'] = '';
}
elseif($set['langue'] !== $existing['langue']) {
elseif ($set['langue'] !== $existing['langue']) {
$set['url'] .= $separateur . $set['langue'];
return url_insert_replay($set, $confirmer, $separateur, $has_parent, $perma);
}
@ -224,7 +233,7 @@ function url_insert(&$set, $confirmer, $separateur) {
}
}
sql_updateq('spip_urls', $refresh, $where . url_sql_quote_like($set['url']));
spip_log("refresh " . $set['type'] . " " . $set['id_objet'].' refresh:'.serialize($refresh), "urls");
spip_log('refresh ' . $set['type'] . ' ' . $set['id_objet'] . ' refresh:' . serialize($refresh), 'urls');
$redate = false;
} else {
$set['url'] .= $separateur . $set['id_objet'];
@ -233,15 +242,19 @@ function url_insert(&$set, $confirmer, $separateur) {
}
}
$reset = array();
$reset = [];
// si on a fixe une langue pour cette URL mais qu'il n'y a pas d'URL generique pour cet objet (avec langue='')
// on retire la langue car c'est l'URL generique par defaut
if (!empty($set['langue'])) {
if (!sql_countsel('spip_urls',
"type=" . sql_quote($set['type'])
. " AND id_objet=" . intval($set['id_objet'])
. " AND id_parent=" . intval($set['id_parent'])
. " AND langue=" . sql_quote(''))){
if (
!sql_countsel(
'spip_urls',
'type=' . sql_quote($set['type'])
. ' AND id_objet=' . intval($set['id_objet'])
. ' AND id_parent=' . intval($set['id_parent'])
. ' AND langue=' . sql_quote('')
)
) {
$set['langue'] = $reset['langue'] = '';
}
} else {
@ -251,20 +264,23 @@ function url_insert(&$set, $confirmer, $separateur) {
$reset['date'] = date('Y-m-d H:i:s');
}
$where_thisurl = 'url=' . sql_quote($set['url']) . " AND id_parent=" . intval($set['id_parent']); // maj
$where_thisurl = 'url=' . sql_quote($set['url']) . ' AND id_parent=' . intval($set['id_parent']); // maj
if ($reset) {
sql_updateq('spip_urls', $reset, $where_thisurl);
}
// si url perma, poser le flag sur la seule url qu'on vient de mettre (au sein de celles qui ont la meme langue)
if ($perma) {
sql_update('spip_urls', array('perma' => "($where_thisurl)"),
"type=" . sql_quote($set['type']) . " AND id_objet=" . intval($set['id_objet'])." AND langue=" . sql_quote($set['langue']));
sql_update(
'spip_urls',
['perma' => "($where_thisurl)"],
'type=' . sql_quote($set['type']) . ' AND id_objet=' . intval($set['id_objet']) . ' AND langue=' . sql_quote($set['langue'])
);
}
spip_log("Creation de l'url propre '" . $set['url'] . "' pour "
. $set['type'] . " " . $set['id_objet']
. " (parent [" . $set['id_parent'] . "] langue [" . $set['langue'] . "] perma [" . ($perma ? "1" : "0") . "])", "urls");
. $set['type'] . ' ' . $set['id_objet']
. ' (parent [' . $set['id_parent'] . '] langue [' . $set['langue'] . '] perma [' . ($perma ? '1' : '0') . '])', 'urls');
return true;
}
@ -281,8 +297,7 @@ function url_insert(&$set, $confirmer, $separateur) {
*/
function url_insert_replay($set, $confirmer, $separateur, $has_parent, $perma) {
//var_dump('url_insert_replay');
if (strlen($set['url']) > 200) //serveur out ? retourner au mieux
{
if (strlen($set['url']) > 200) { //serveur out ? retourner au mieux
return false;
}
else {
@ -304,7 +319,7 @@ function url_insert_replay($set, $confirmer, $separateur, $has_parent, $perma) {
* @return string
*/
function url_sql_quote_like($url) {
return sql_quote(str_replace(array("%", "_"), array("\\%", "\\_"), $url)) . " ESCAPE " . sql_quote('\\');
return sql_quote(str_replace(['%', '_'], ['\\%', '\\_'], $url)) . ' ESCAPE ' . sql_quote('\\');
}
/**
@ -316,14 +331,17 @@ function url_sql_quote_like($url) {
* @param int $id_parent
* @param $url
*/
function url_verrouiller($url, $id_parent=0) {
$where_thisurl = 'url=' . sql_quote($url) . " AND id_parent=" . intval($id_parent);
$row = sql_fetsel('*','spip_urls',$where_thisurl);
function url_verrouiller($url, $id_parent = 0) {
$where_thisurl = 'url=' . sql_quote($url) . ' AND id_parent=' . intval($id_parent);
$row = sql_fetsel('*', 'spip_urls', $where_thisurl);
// on fait un update unique pour changer toutes les URLs concernees d'un coup
if ($row) {
sql_update('spip_urls', array('perma' => "($where_thisurl)"),
"type=" . sql_quote($row['type']) . " AND id_objet=" . intval($row['id_objet'])." AND langue=" . sql_quote($row['langue']));
sql_update(
'spip_urls',
['perma' => "($where_thisurl)"],
'type=' . sql_quote($row['type']) . ' AND id_objet=' . intval($row['id_objet']) . ' AND langue=' . sql_quote($row['langue'])
);
}
}
@ -334,19 +352,19 @@ function url_verrouiller($url, $id_parent=0) {
* @param string $url
* @param int $id_parent
*/
function url_delete($objet, $id_objet, $url = "", $id_parent=0) {
$where = "id_objet=" . intval($id_objet) . " AND type=" . sql_quote($objet);
function url_delete($objet, $id_objet, $url = '', $id_parent = 0) {
$where = 'id_objet=' . intval($id_objet) . ' AND type=' . sql_quote($objet);
if (strlen($url)) {
$where .= " AND url=" . sql_quote($url) . " AND id_parent=" . intval($id_parent);
$where .= ' AND url=' . sql_quote($url) . ' AND id_parent=' . intval($id_parent);
}
sql_delete("spip_urls", $where);
sql_delete('spip_urls', $where);
// si on a supprime une seule URL, s'assurer qu'on a toujours au moins une URL avec lang=''
$where = "id_objet=" . intval($id_objet) . " AND type=" . sql_quote($objet);
if (!$nb = sql_countsel('spip_urls',$where .' AND langue=\'\'')) {
if ($last = sql_fetsel('*','spip_urls',$where,'','perma=1 DESC, langue=\'\' DESC, id_parent=0 DESC, date DESC','0,1')) {
sql_updateq('spip_urls',array('langue'=>''),'url='.sql_quote($last['url']) . ' AND id_parent='.intval($last['id_parent']));
$where = 'id_objet=' . intval($id_objet) . ' AND type=' . sql_quote($objet);
if (!$nb = sql_countsel('spip_urls', $where . ' AND langue=\'\'')) {
if ($last = sql_fetsel('*', 'spip_urls', $where, '', 'perma=1 DESC, langue=\'\' DESC, id_parent=0 DESC, date DESC', '0,1')) {
sql_updateq('spip_urls', ['langue' => ''], 'url=' . sql_quote($last['url']) . ' AND id_parent=' . intval($last['id_parent']));
}
}
}

16
action/supprimer_url.php

@ -10,7 +10,7 @@
* Pour plus de détails voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
if (!defined("_ECRIRE_INC_VERSION")) {
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
@ -21,7 +21,7 @@ function action_supprimer_url_dist($arg = null) {
$securiser_action = charger_fonction('securiser_action', 'inc');
$arg = $securiser_action();
}
if (strncmp($arg, "-1-", 3) == 0) {
if (strncmp($arg, '-1-', 3) == 0) {
$id_parent = -1;
$url = substr($arg, 3);
} else {
@ -30,20 +30,16 @@ function action_supprimer_url_dist($arg = null) {
$url = implode('-', $arg);
}
$where = 'id_parent=' . intval($id_parent) . " AND url=" . sql_quote($url);
$where = 'id_parent=' . intval($id_parent) . ' AND url=' . sql_quote($url);
if ($row = sql_fetsel('*', 'spip_urls', $where)) {
if (autoriser('modifierurl', $row['type'], $row['id_objet'])) {
include_spip('action/editer_url');
url_delete($row['type'], $row['id_objet'], $url, $id_parent);
spip_log('on supprime l\'url ' . $url. ' pour ' . $row['type'] .'/'.$row['id_objet']."/$id_parent", "urls");
spip_log('on supprime l\'url ' . $url . ' pour ' . $row['type'] . '/' . $row['id_objet'] . "/$id_parent", 'urls');
} else {
spip_log('supprimer sans autorisation l\'URL ' . $id_parent . "://" . $url, "urls." . _LOG_ERREUR);
spip_log('supprimer sans autorisation l\'URL ' . $id_parent . '://' . $url, 'urls.' . _LOG_ERREUR);
}
} else {
spip_log('Impossible de supprimer une URL inconnue ' . $id_parent . "://" . $url, "urls." . _LOG_INFO_IMPORTANTE);
spip_log('Impossible de supprimer une URL inconnue ' . $id_parent . '://' . $url, 'urls.' . _LOG_INFO_IMPORTANTE);
}
}

11
action/urls_actualiser.php

@ -16,7 +16,7 @@
* @package SPIP\Urls_etendues\Action
**/
if (!defined("_ECRIRE_INC_VERSION")) {
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
@ -38,15 +38,16 @@ function action_urls_actualiser_dist() {
if (!defined('_VAR_URLS')) {
define('_VAR_URLS', true);
}
$type = $id = "";
$res = sql_select("type,id_objet", "spip_urls", "", "", "type,id_objet");
$type = $id = '';
$res = sql_select('type,id_objet', 'spip_urls', '', '', 'type,id_objet');
while ($row = sql_fetch($res)) {
if ($row['id_objet'] !== $id
if (
$row['id_objet'] !== $id
or $row['type'] !== $type
) {
$id = $row['id_objet'];
$type = $row['type'];
generer_url_entite($id, $type, "", "", true);
generer_url_entite($id, $type, '', '', true);
}
}
}

30
base/urls.php

@ -34,39 +34,39 @@ function urls_declarer_tables_interfaces($interfaces) {
*/
function urls_declarer_tables_auxiliaires($tables_auxiliaires) {
$spip_urls = array(
$spip_urls = [
// un id parent eventuel, pour discriminer les doublons arborescents
"id_parent" => "bigint(21) DEFAULT '0' NOT NULL",
"url" => "VARCHAR(255) NOT NULL",
'id_parent' => "bigint(21) DEFAULT '0' NOT NULL",
'url' => 'VARCHAR(255) NOT NULL',
// la table cible
"type" => "varchar(25) DEFAULT 'article' NOT NULL",
'type' => "varchar(25) DEFAULT 'article' NOT NULL",
// l'id dans la table
"id_objet" => "bigint(21) NOT NULL",
'id_objet' => 'bigint(21) NOT NULL',
// pour connaitre la plus recente.
// ATTENTION, pas on update CURRENT_TIMESTAMP implicite
// et pas le nom maj, surinterprete par inc/import_1_3
"date" => "DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL",
'date' => "DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL",
// nombre de segments dans url
"segments" => "SMALLINT(3) DEFAULT '1' NOT NULL",
'segments' => "SMALLINT(3) DEFAULT '1' NOT NULL",
// URL permanente, prioritaire
"perma" => "TINYINT(1) DEFAULT '0' NOT NULL",
'perma' => "TINYINT(1) DEFAULT '0' NOT NULL",
// langue des urls : on le nomme langue et pas lang pour eviter les ambiguites avec le champ lang des objets
// qui apparait dans les jointures sans prefixe de table, via le champ titre "titre, lang"
'langue' => "VARCHAR(10) DEFAULT '' NOT NULL",
);
];
$spip_urls_key = array(
"PRIMARY KEY" => "id_parent, url",
"KEY type" => "type, id_objet",
$spip_urls_key = [
'PRIMARY KEY' => 'id_parent, url',
'KEY type' => 'type, id_objet',
'KEY langue' => 'langue',
'KEY url' => 'url',
);
];
$tables_auxiliaires['spip_urls'] = array(
$tables_auxiliaires['spip_urls'] = [
'field' => &$spip_urls,
'key' => &$spip_urls_key
);
];
return $tables_auxiliaires;
}

7
composer.json

@ -0,0 +1,7 @@
{
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"spip/coding-standards": "^1.2",
"phpstan/phpstan": "^0.12.98"
}
}

22
formulaires/configurer_urls.php

@ -10,45 +10,43 @@
* Pour plus de détails voir le fichier COPYING.txt ou l'aide en ligne. *
\***************************************************************************/
if (!defined("_ECRIRE_INC_VERSION")) {
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function formulaires_configurer_urls_charger_dist() {
if (isset($GLOBALS['type_urls'])) // priorité au fichier d'options
{
return "<p>" . _T('urls:erreur_config_url_forcee') . "</p>";
if (isset($GLOBALS['type_urls'])) { // priorité au fichier d'options
return '<p>' . _T('urls:erreur_config_url_forcee') . '</p>';
}
$valeurs = array(
$valeurs = [
'type_urls' => $GLOBALS['meta']['type_urls'],
'urls_activer_controle' => (isset($GLOBALS['meta']['urls_activer_controle']) ? $GLOBALS['meta']['urls_activer_controle'] : ''),
'_urls_dispos' => type_urls_lister(),
);
];
return $valeurs;
}
function formulaires_configurer_urls_traiter_dist() {
ecrire_meta('type_urls', _request('type_urls'));
ecrire_meta('urls_activer_controle', _request('urls_activer_controle') ? 'oui' : 'non');
return array('message_ok' => _T('config_info_enregistree'), 'editable' => true);
return ['message_ok' => _T('config_info_enregistree'), 'editable' => true];
}
function type_urls_lister() {
$dispo = array();
foreach (find_all_in_path('urls/', '\w+\.php$', array()) as $f) {
$dispo = [];
foreach (find_all_in_path('urls/', '\w+\.php$', []) as $f) {
$r = basename($f, '.php');
if ($r == 'index' or strncmp('generer_', $r, 8) == 0 or $r == "standard") {
if ($r == 'index' or strncmp('generer_', $r, 8) == 0 or $r == 'standard') {
continue;
}
include_once $f;
$exemple = 'URLS_' . strtoupper($r) . '_EXEMPLE';
$exemple = defined($exemple) ? constant($exemple) : '?';
$dispo[_T("urls:titre_type_$r")] = array($r, _T("urls:titre_type_$r"), $exemple);
$dispo[_T("urls:titre_type_$r")] = [$r, _T("urls:titre_type_$r"), $exemple];
}
ksort($dispo);

31
formulaires/editer_url_objet.php

@ -22,7 +22,7 @@ if (!defined('_ECRIRE_INC_VERSION')) {
* @return array
*/
function formulaires_editer_url_objet_charger_dist($type, $id) {
$valeurs = array('url' => '', '_objet' => $type, '_id_objet' => $id);
$valeurs = ['url' => '', '_objet' => $type, '_id_objet' => $id];
return $valeurs;
}
@ -38,14 +38,16 @@ function formulaires_editer_url_objet_charger_dist($type, $id) {
* @return array
*/
function formulaires_editer_url_objet_verifier_dist($type, $id) {
$erreurs = array();
$erreurs = [];
include_spip('action/editer_url');
$langue = '';
if (!$url = _request('url')) {
$erreurs['url'] = _T('info_obligatoire');
} else {
if (preg_match(";^([a-z_]{2,9}):;", $url, $m)
and url_verifier_langue($m[1])) {
if (
preg_match(';^([a-z_]{2,9}):;', $url, $m)
and url_verifier_langue($m[1])
) {
$langue = trim($m[1]);
$url = substr($url, strlen($m[0]));
}
@ -66,7 +68,7 @@ function formulaires_editer_url_objet_verifier_dist($type, $id) {
$url_clean = url_nettoyer($url, 255);
}
if (!isset($erreurs['url']) and $url != $url_clean) {
set_request('url', ($langue?"$langue:":"") . $url_clean);
set_request('url', ($langue ? "$langue:" : '') . $url_clean);
$erreurs['url'] = _T('urls:verifier_url_nettoyee');
}
}
@ -82,22 +84,25 @@ function formulaires_editer_url_objet_verifier_dist($type, $id) {
* @return array
*/
function formulaires_editer_url_objet_traiter_dist($type, $id) {
$valeurs = array('editable' => true);
$valeurs = ['editable' => true];
include_spip('action/editer_url');
$url = _request('url');
$langue = '';
if (preg_match(";^([a-z_]{2,9}):;", $url, $m)
and url_verifier_langue($m[1])) {
if (
preg_match(';^([a-z_]{2,9}):;', $url, $m)
and url_verifier_langue($m[1])
) {
$langue = trim($m[1]);
$url = substr($url, strlen($m[0]));
}
// les urls manuelles sont toujours permanentes
$set = array('url' => $url, 'type' => $type, 'id_objet' => $id, 'perma' => 1, 'langue' => $langue);
$set = ['url' => $url, 'type' => $type, 'id_objet' => $id, 'perma' => 1, 'langue' => $langue];
$type_urls = (isset($GLOBALS['type_urls']) ? $GLOBALS['type_urls'] : $GLOBALS['meta']['type_urls']);
if (include_spip("urls/$type_urls")
if (
include_spip("urls/$type_urls")
and function_exists($renseigner_url = "renseigner_url_$type_urls")
and $r = $renseigner_url($type, $id)
and isset($r['parent'])
@ -105,16 +110,16 @@ function formulaires_editer_url_objet_traiter_dist($type, $id) {
$set['id_parent'] = $r['parent'];
}
$separateur = "-";
$separateur = '-';
if (defined('_url_sep_id')) {
$separateur = _url_sep_id;
}
if (url_insert($set, false, $separateur)) {
set_request('url');
$valeurs['message_ok'] = _T("urls:url_ajoutee");
$valeurs['message_ok'] = _T('urls:url_ajoutee');
} else {
$valeurs['message_erreur'] = _T("urls:url_ajout_impossible");
$valeurs['message_erreur'] = _T('urls:url_ajout_impossible');
}
return $valeurs;

14
phpcs.xml.dist

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<ruleset>
<file>.</file>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>lang/*</exclude-pattern>
<rule ref="SPIP41"/>
<config name="ignore_warnings_on_exit" value="1"/>
<arg name="cache" value=".php_cs.cache"/>
<arg name="report-full" value=".php_cs.txt"/>
<arg name="report-summary"/>
<arg value="s"/>
</ruleset>

552
phpstan-baseline.neon

@ -0,0 +1,552 @@
parameters:
ignoreErrors:
-
message: "#^Function _request not found\\.$#"
count: 1
path: action/editer_url.php
-
message: "#^Function extraire_multi not found\\.$#"
count: 1
path: action/editer_url.php
-
message: "#^Function include_spip not found\\.$#"
count: 2
path: action/editer_url.php
-
message: "#^Function match_langue not found\\.$#"
count: 1
path: action/editer_url.php
-
message: "#^Function spip_log not found\\.$#"
count: 3
path: action/editer_url.php
-
message: "#^Function sql_countsel not found\\.$#"
count: 3
path: action/editer_url.php
-
message: "#^Function sql_delete not found\\.$#"
count: 1
path: action/editer_url.php
-
message: "#^Function sql_fetsel not found\\.$#"
count: 5
path: action/editer_url.php
-
message: "#^Function sql_insertq not found\\.$#"
count: 1
path: action/editer_url.php
-
message: "#^Function sql_quote not found\\.$#"
count: 21
path: action/editer_url.php
-
message: "#^Function sql_update not found\\.$#"
count: 2
path: action/editer_url.php
-
message: "#^Function sql_updateq not found\\.$#"
count: 5
path: action/editer_url.php
-
message: "#^Function supprimer_numero not found\\.$#"
count: 1
path: action/editer_url.php
-
message: "#^Function supprimer_tags not found\\.$#"
count: 1
path: action/editer_url.php
-
message: "#^Function translitteration not found\\.$#"
count: 1
path: action/editer_url.php
-
message: "#^Function autoriser not found\\.$#"
count: 1
path: action/supprimer_url.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 1
path: action/supprimer_url.php
-
message: "#^Function include_spip not found\\.$#"
count: 1
path: action/supprimer_url.php
-
message: "#^Function spip_log not found\\.$#"
count: 3
path: action/supprimer_url.php
-
message: "#^Function sql_fetsel not found\\.$#"
count: 1
path: action/supprimer_url.php
-
message: "#^Function sql_quote not found\\.$#"
count: 1
path: action/supprimer_url.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 1
path: action/urls_actualiser.php
-
message: "#^Function generer_url_entite not found\\.$#"
count: 1
path: action/urls_actualiser.php
-
message: "#^Function sql_fetch not found\\.$#"
count: 1
path: action/urls_actualiser.php
-
message: "#^Function sql_select not found\\.$#"
count: 1
path: action/urls_actualiser.php
-
message: "#^Function _T not found\\.$#"
count: 4
path: formulaires/configurer_urls.php
-
message: "#^Function _request not found\\.$#"
count: 2
path: formulaires/configurer_urls.php
-
message: "#^Function ecrire_meta not found\\.$#"
count: 2
path: formulaires/configurer_urls.php
-
message: "#^Function find_all_in_path not found\\.$#"
count: 1
path: formulaires/configurer_urls.php
-
message: "#^Function include_spip not found\\.$#"
count: 1
path: formulaires/configurer_urls_arbo_fonctions.php
-
message: "#^Function include_spip not found\\.$#"
count: 1
path: formulaires/configurer_urls_propres_fonctions.php
-
message: "#^Function _T not found\\.$#"
count: 5
path: formulaires/editer_url_objet.php
-
message: "#^Function _request not found\\.$#"
count: 2
path: formulaires/editer_url_objet.php
-
message: "#^Function include_spip not found\\.$#"
count: 3
path: formulaires/editer_url_objet.php
-
message: "#^Function set_request not found\\.$#"
count: 2
path: formulaires/editer_url_objet.php
-
message: "#^Function include_spip not found\\.$#"
count: 1
path: prive/squelettes/contenu/configurer_urls_fonctions.php
-
message: "#^Function _request not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function autoriser not found\\.$#"
count: 2
path: urls/arbo.php
-
message: "#^Function changer_langue not found\\.$#"
count: 2
path: urls/arbo.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 4
path: urls/arbo.php
-
message: "#^Function extraire_multi not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function generer_url_entite not found\\.$#"
count: 3
path: urls/arbo.php
-
message: "#^Function get_spip_script not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function id_table_objet not found\\.$#"
count: 4
path: urls/arbo.php
-
message: "#^Function include_spip not found\\.$#"
count: 12
path: urls/arbo.php
-
message: "#^Function nettoyer_url_page not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function objet_test_si_publie not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function objet_type not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function pipeline not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function sql_fetsel not found\\.$#"
count: 2
path: urls/arbo.php
-
message: "#^Function sql_in not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function sql_quote not found\\.$#"
count: 3
path: urls/arbo.php
-
message: "#^Function table_objet not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function textebrut not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function url_absolue not found\\.$#"
count: 2
path: urls/arbo.php
-
message: "#^Function urls_liste_objets not found\\.$#"
count: 1
path: urls/arbo.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 3
path: urls/html.php
-
message: "#^Function include_spip not found\\.$#"
count: 1
path: urls/html.php
-
message: "#^Function nettoyer_url_page not found\\.$#"
count: 1
path: urls/html.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 1
path: urls/libres.php
-
message: "#^Function _T not found\\.$#"
count: 1
path: urls/propres.php
-
message: "#^Function _request not found\\.$#"
count: 1
path: urls/propres.php
-
message: "#^Function autoriser not found\\.$#"
count: 2
path: urls/propres.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 3
path: urls/propres.php
-
message: "#^Function generer_url_entite not found\\.$#"
count: 2
path: urls/propres.php
-
message: "#^Function get_spip_script not found\\.$#"
count: 1
path: urls/propres.php
-
message: "#^Function id_table_objet not found\\.$#"
count: 3
path: urls/propres.php
-
message: "#^Function include_spip not found\\.$#"
count: 9
path: urls/propres.php
-
message: "#^Function nettoyer_url_page not found\\.$#"
count: 1
path: urls/propres.php
-
message: "#^Function objet_test_si_publie not found\\.$#"
count: 1
path: urls/propres.php
-
message: "#^Function objet_type not found\\.$#"
count: 1
path: urls/propres.php
-
message: "#^Function pipeline not found\\.$#"
count: 1
path: urls/propres.php
-
message: "#^Function sql_fetsel not found\\.$#"
count: 4
path: urls/propres.php
-
message: "#^Function sql_quote not found\\.$#"
count: 2
path: urls/propres.php
-
message: "#^Function table_objet not found\\.$#"
count: 1
path: urls/propres.php
-
message: "#^Function urls_liste_objets not found\\.$#"
count: 1
path: urls/propres.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 1
path: urls/propres2.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 1
path: urls/propres_qs.php
-
message: "#^Function _request not found\\.$#"
count: 2
path: urls/simple.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 3
path: urls/simple.php
-
message: "#^Function get_spip_script not found\\.$#"
count: 1
path: urls/simple.php
-
message: "#^Function id_table_objet not found\\.$#"
count: 2
path: urls/simple.php
-
message: "#^Function include_spip not found\\.$#"
count: 2
path: urls/simple.php
-
message: "#^Function nettoyer_url_page not found\\.$#"
count: 1
path: urls/simple.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 1
path: urls_administrations.php
-
message: "#^Function ecrire_meta not found\\.$#"
count: 2
path: urls_administrations.php
-
message: "#^Function effacer_meta not found\\.$#"
count: 1
path: urls_administrations.php
-
message: "#^Function include_spip not found\\.$#"
count: 1
path: urls_administrations.php
-
message: "#^Function maj_plugin not found\\.$#"
count: 1
path: urls_administrations.php
-
message: "#^Function spip_log not found\\.$#"
count: 2
path: urls_administrations.php
-
message: "#^Function sql_countsel not found\\.$#"
count: 1
path: urls_administrations.php
-
message: "#^Function sql_delete not found\\.$#"
count: 1
path: urls_administrations.php
-
message: "#^Function sql_drop_table not found\\.$#"
count: 1
path: urls_administrations.php
-
message: "#^Function sql_fetch not found\\.$#"
count: 2
path: urls_administrations.php
-
message: "#^Function sql_free not found\\.$#"
count: 2
path: urls_administrations.php
-
message: "#^Function sql_quote not found\\.$#"
count: 6
path: urls_administrations.php
-
message: "#^Function sql_select not found\\.$#"
count: 2
path: urls_administrations.php
-
message: "#^Function sql_updateq not found\\.$#"
count: 3
path: urls_administrations.php
-
message: "#^Function autoriser not found\\.$#"
count: 4
path: urls_autoriser.php
-
message: "#^Function id_table_objet not found\\.$#"
count: 1
path: urls_autoriser.php
-
message: "#^Function sql_countsel not found\\.$#"
count: 1
path: urls_autoriser.php
-
message: "#^Function table_objet_sql not found\\.$#"
count: 1
path: urls_autoriser.php
-
message: "#^Function generer_info_entite not found\\.$#"
count: 1
path: urls_fonctions.php
-
message: "#^Function include_spip not found\\.$#"
count: 1
path: urls_fonctions.php
-
message: "#^Function objet_test_si_publie not found\\.$#"
count: 1
path: urls_fonctions.php
-
message: "#^Function sql_countsel not found\\.$#"
count: 1
path: urls_fonctions.php
-
message: "#^Function sql_quote not found\\.$#"
count: 1
path: urls_fonctions.php
-
message: "#^Function _T not found\\.$#"
count: 1
path: urls_ieconfig.php
-
message: "#^Function objet_info not found\\.$#"
count: 1
path: urls_pipeline.php
-
message: "#^Function recuperer_fond not found\\.$#"
count: 1
path: urls_pipeline.php

11
phpstan.neon.dist

@ -0,0 +1,11 @@
includes:
- phpstan-baseline.neon
parameters:
paths:
- .
excludePaths:
analyseAndScan:
- vendor
- lang
level: 0

5
prive/squelettes/contenu/configurer_urls_fonctions.php

@ -5,10 +5,11 @@ if (!defined('_ECRIRE_INC_VERSION')) {
}
function choisir_form_configuration($type_url) {
if (include_spip("urls/$type_url")
if (
include_spip("urls/$type_url")
and defined($c = 'URLS_' . strtoupper($type_url) . '_CONFIG')
) {
return "configurer_urls_" . strtolower(constant($c));
return 'configurer_urls_' . strtolower(constant($c));
}
return '';

161
urls/arbo.php

@ -78,7 +78,7 @@ defined('CONFIRMER_MODIFIER_URL') || define('CONFIRMER_MODIFIER_URL', false);
*
*/
$config_urls_arbo = isset($GLOBALS['meta']['urls_arbo']) ? unserialize($GLOBALS['meta']['urls_arbo']) : array();
$config_urls_arbo = isset($GLOBALS['meta']['urls_arbo']) ? unserialize($GLOBALS['meta']['urls_arbo']) : [];
if (!defined('_debut_urls_arbo')) {
define('_debut_urls_arbo', '');
}
@ -117,7 +117,7 @@ if (!defined('_url_sep_id')) {
// define('_url_arbo_multilang',true);
if (!defined('_url_arbo_multilang')) {
define('_url_arbo_multilang',false);
define('_url_arbo_multilang', false);
}
@ -141,12 +141,12 @@ if (!defined('_MARQUEUR_URL')) {
function url_arbo_parent($type) {
static $parents = null;
if (is_null($parents)) {
$parents = array(
'article' => array('id_rubrique', 'rubrique'),
'rubrique' => array('id_parent', 'rubrique'),
'breve' => array('id_rubrique', 'rubrique'),
'site' => array('id_rubrique', 'rubrique')
);
$parents = [
'article' => ['id_rubrique', 'rubrique'],
'rubrique' => ['id_parent', 'rubrique'],
'breve' => ['id_rubrique', 'rubrique'],
'site' => ['id_rubrique', 'rubrique']
];
if (isset($GLOBALS['url_arbo_parents']) and !isset($_REQUEST['url_arbo_parents'])) {
$parents = array_merge($parents, $GLOBALS['url_arbo_parents']);
}
@ -166,11 +166,11 @@ function url_arbo_parent($type) {
function url_arbo_terminaison($type) {
static $terminaison_types = null;
if ($terminaison_types == null) {
$terminaison_types = array(
$terminaison_types = [
'rubrique' => '/',
'mot' => '',
'defaut' => defined('_terminaison_urls_arbo') ? _terminaison_urls_arbo : '.html'
);
];
if (isset($GLOBALS['url_arbo_terminaisons'])) {
$terminaison_types = array_merge($terminaison_types, $GLOBALS['url_arbo_terminaisons']);
}
@ -199,7 +199,7 @@ function url_arbo_terminaison($type) {
function url_arbo_type($type) {
static $synonymes_types = null;
if (!$synonymes_types) {
$synonymes_types = array('rubrique' => '');
$synonymes_types = ['rubrique' => ''];
if (isset($GLOBALS['url_arbo_types']) and is_array($GLOBALS['url_arbo_types'])) {
$synonymes_types = array_merge($synonymes_types, $GLOBALS['url_arbo_types']);
}
@ -232,13 +232,15 @@ function urls_arbo_creer_chaine_url($x) {
include_spip('inc/filtres');
include_spip('action/editer_url');
if (!$url = url_nettoyer(
$objet['titre'],
_URLS_ARBO_MAX,
_URLS_ARBO_MIN,
'-',
_url_arbo_minuscules ? 'spip_strtolower' : ''
)) {
if (
!$url = url_nettoyer(
$objet['titre'],
_URLS_ARBO_MAX,
_URLS_ARBO_MIN,
'-',
_url_arbo_minuscules ? 'spip_strtolower' : ''
)
) {
$url = $objet['id_objet'];
}
@ -264,7 +266,7 @@ function urls_arbo_creer_chaine_url($x) {
* @param array $contexte
* @return string
*/
function declarer_url_arbo_rec($url, $type, $parent, $type_parent, $contexte = array()) {
function declarer_url_arbo_rec($url, $type, $parent, $type_parent, $contexte = []) {
if (is_null($parent)) {
return $url;
}
@ -291,24 +293,24 @@ function declarer_url_arbo_rec($url, $type, $parent, $type_parent, $contexte = a
* id_parent : rubrique parent
* @return bool|null|array
*/
function renseigner_url_arbo($type, $id_objet, $contexte = array()) {
$urls = array();
function renseigner_url_arbo($type, $id_objet, $contexte = []) {
$urls = [];
$trouver_table = charger_fonction('trouver_table', 'base');
$desc = $trouver_table(table_objet($type));
// Quand $type ne reference pas une table
if (!$desc) {
return false;
}
}
$table = $desc['table'];
$col_id = $desc['key']['PRIMARY KEY'] ?? null;
if (!$col_id) {
return false;
}
}
$id_objet = intval($id_objet);
$id_parent = (isset($contexte['id_parent'])?$contexte['id_parent']:null);
$langue = (isset($contexte['langue'])?$contexte['langue']:'');
$id_parent = (isset($contexte['id_parent']) ? $contexte['id_parent'] : null);
$langue = (isset($contexte['langue']) ? $contexte['langue'] : '');
$champ_titre = $desc['titre'] ? $desc['titre'] : 'titre';
@ -318,13 +320,15 @@ function renseigner_url_arbo($type, $id_objet, $contexte = array()) {
$order_by_parent = '';
if ($champ_parent) {
// si un parent est fourni est qu'il est legitime, on recherche une URL pour ce parent
if ($id_parent
if (
$id_parent
and $type_parent = end($champ_parent)
and $url_verifier_parent_objet = charger_fonction('url_verifier_parent_objet', 'inc', true)
and $url_verifier_parent_objet($type, $id_objet, $type_parent, $id_parent)) {
$sel_parent = ', '.intval($id_parent) . ' as parent';
and $url_verifier_parent_objet($type, $id_objet, $type_parent, $id_parent)
) {
$sel_parent = ', ' . intval($id_parent) . ' as parent';
// trouver l'url qui matche le parent en premier
$order_by_parent = 'U.id_parent='.intval($id_parent).' DESC, ';
$order_by_parent = 'U.id_parent=' . intval($id_parent) . ' DESC, ';
} else {
// sinon on prend son parent direct fourni par $champ_parent
$sel_parent = ', O.' . reset($champ_parent) . ' as parent';
@ -334,7 +338,7 @@ function renseigner_url_arbo($type, $id_objet, $contexte = array()) {
}
$order_by_langue = "U.langue='' DESC, ";
if ($langue) {
$order_by_langue = 'U.langue='.sql_quote($langue).' DESC, ' . $order_by_langue;
$order_by_langue = 'U.langue=' . sql_quote($langue) . ' DESC, ' . $order_by_langue;
}
// Recuperer une URL propre correspondant a l'objet.
@ -366,8 +370,8 @@ function renseigner_url_arbo($type, $id_objet, $contexte = array()) {
* langue : langue courante pour laquelle on veut l'URL
* @return string
*/
function declarer_url_arbo($type, $id_objet, $contexte = array()) {
static $urls = array();
function declarer_url_arbo($type, $id_objet, $contexte = []) {
static $urls = [];
// contexte de langue si pas defini, en fonction de la configuration
if (!isset($contexte['langue'])) {
@ -412,7 +416,8 @@ function declarer_url_arbo($type, $id_objet, $contexte = array()) {
// si on a trouve l'url
// et que le parent est bon
// et (permanente ou pas de demande de modif)
if (!is_null($url_propre)
if (
!is_null($url_propre)
and $u['id_parent'] == $u['parent']
and ($u['perma'] or !$modifier_url)
) {
@ -427,9 +432,9 @@ function declarer_url_arbo($type, $id_objet, $contexte = array()) {
// Si URL inconnue ou maj forcee sur une url non permanente, recreer une url
$url = $url_propre;
$urls_langues = array();
$urls_langues = [];
if (is_null($url_propre) or ($modifier_url and !$u['perma'])) {
$langues = array();
$langues = [];
if (_url_arbo_multilang === true) {
include_spip('inc/lang');
$langues = (isset($GLOBALS['meta']['langues_multilingue']) ? $GLOBALS['meta']['langues_multilingue'] : '');
@ -455,15 +460,16 @@ function declarer_url_arbo($type, $id_objet, $contexte = array()) {
}
$urls_langues[$l] = pipeline(
'arbo_creer_chaine_url',
array(
[
'data' => $url_propre, // le vieux url_propre
'objet' => array_merge($u, array('type' => $type, 'id_objet' => $id_objet))
)
'objet' => array_merge($u, ['type' => $type, 'id_objet' => $id_objet])
]
);
// Eviter de tamponner les URLs a l'ancienne (cas d'un article
// intitule "auteur2")
if (preg_match(',^(' . $objets . ')[0-9]*$,', $urls_langues[$l], $r)
if (
preg_match(',^(' . $objets . ')[0-9]*$,', $urls_langues[$l], $r)
and $r[1] != $type
) {
$urls_langues[$l] = $urls_langues[$l] . _url_arbo_sep_id . $id_objet;
@ -477,7 +483,8 @@ function declarer_url_arbo($type, $id_objet, $contexte = array()) {
// Pas de changement d'url ni de parent
if ($url == $url_propre
if (
$url == $url_propre
and $u['id_parent'] == $u['parent']
) {
return declarer_url_arbo_rec($url_propre, $type, $u['parent'], $u['type_parent'], $contexte);
@ -489,7 +496,8 @@ function declarer_url_arbo($type, $id_objet, $contexte = array()) {
$modifier_url = autoriser('modifierurl', $type, $id_objet);
}
// Verifier si l'utilisateur veut effectivement changer l'URL
if ($modifier_url
if (
$modifier_url
and CONFIRMER_MODIFIER_URL
and $url_propre
// on essaye pas de regenerer une url en -xxx (suffixe id anti collision)
@ -507,14 +515,14 @@ function declarer_url_arbo($type, $id_objet, $contexte = array()) {
// on enregistre toutes les langues
include_spip('action/editer_url');
foreach ($urls_langues as $langue => $url) {
$set = array(
$set = [
'url' => $url,
'type' => $type,
'id_objet' => $id_objet,
'id_parent' => $u['parent'],
'langue' => $langue,
'perma' => intval($u['perma'])
);
];
$res = url_insert($set, $confirmer, _url_arbo_sep_id);
if ($langue == $contexte['langue']) {
if ($res) {
@ -553,7 +561,7 @@ function _generer_url_arbo($type, $id, $args = '', $ancre = '') {
$debut_langue = '';
// Mode propre
$c = array();
$c = [];
parse_str($args, $contexte);
// choisir le contexte de langue en fonction de la configuration
@ -561,12 +569,12 @@ function _generer_url_arbo($type, $id, $args = '', $ancre = '') {
if (_url_arbo_multilang === true) {
if (isset($contexte['lang']) and $contexte['lang']) {
$c['langue'] = $contexte['lang'];
$debut_langue = $c['langue'] .'/';
$debut_langue = $c['langue'] . '/';
unset($contexte['lang']);
$args = http_build_query($contexte);
} elseif (isset($GLOBALS['spip_lang']) and $GLOBALS['spip_lang']) {
$c['langue'] = $GLOBALS['spip_lang'];
$debut_langue = $c['langue'] .'/';
$debut_langue = $c['langue'] . '/';
}
} elseif (_url_arbo_multilang) {
$c['langue'] = _url_arbo_multilang;
@ -575,9 +583,11 @@ function _generer_url_arbo($type, $id, $args = '', $ancre = '') {
// si le parent est fourni en contexte dans le $args, verifier si l'URL relative a ce parent est la meme ou non
$champ_parent = url_arbo_parent($type);
if ($champ_parent
and $champ_parent = reset($champ_parent)
and isset($contexte[$champ_parent]) and $contexte[$champ_parent]) {
if (
$champ_parent
and $champ_parent = reset($champ_parent)
and isset($contexte[$champ_parent]) and $contexte[$champ_parent]
) {
$c['id_parent'] = $contexte[$champ_parent];
$propre_contexte = declarer_url_arbo($type, $id, $c);
// si l'URL est differente on la prend et on enleve l'argument de l'URL (redondance puisque parent defini par l'URL elle meme)
@ -656,7 +666,8 @@ function urls_arbo_dist($i, $entite, $args = '', $ancre = '') {
// Migration depuis anciennes URLs ?
// traiter les injections domain.tld/spip.php/n/importe/quoi/rubrique23
if ($GLOBALS['profondeur_url'] <= 0
if (
$GLOBALS['profondeur_url'] <= 0
and $_SERVER['REQUEST_METHOD'] != 'POST'
) {
include_spip('inc/urls');
@ -666,15 +677,16 @@ function urls_arbo_dist($i, $entite, $args = '', $ancre = '') {
$_id = id_table_objet($type);
$id_objet = $contexte[$_id];
$url_propre = generer_url_entite($id_objet, $type);
if (strlen($url_propre)
if (
strlen($url_propre)
and !strstr($url, $url_propre)
and (
objet_test_si_publie($type, $id_objet)
OR (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet))
or (defined('_VAR_PREVIEW') and _VAR_PREVIEW and autoriser('voir', $type, $id_objet))
)
) {
list(, $hash) = array_pad(explode('#', $url_propre), 2, null);
$args = array();
$args = [];
foreach (array_filter(explode('&', $suite)) as $fragment) {
if ($fragment != "$_id=$id_objet") {
$args[] = $fragment;
@ -682,7 +694,7 @@ function urls_arbo_dist($i, $entite, $args = '', $ancre = '') {
}
$url_redirect = generer_url_entite($id_objet, $type, join('&', array_filter($args)), $hash);
return array($contexte, $type, $url_redirect, $type);
return [$contexte, $type, $url_redirect, $type];
}
}
}
@ -692,13 +704,15 @@ function urls_arbo_dist($i, $entite, $args = '', $ancre = '') {
$url_propre = preg_replace(',[?].*,', '', $url);
// Mode Query-String ?
if (!$url_propre
if (
!$url_propre
and preg_match(',[?]([^=/?&]+)(&.*)?$,', $url, $r)
) {
$url_propre = $r[1];
}
if (!$url_propre
if (
!$url_propre
or $url_propre == _DIR_RESTREINT_ABS
or $url_propre == _SPIP_SCRIPT
) {
@ -712,20 +726,20 @@ function urls_arbo_dist($i, $entite, $args = '', $ancre = '') {
$url_propre = rawurldecode($url_propre);
// Compatibilite avec .htm/.html et autres terminaisons
$t = array_diff(array_unique(array_merge(array('.html', '.htm', '/'), url_arbo_terminaison(''))), array(''));
$t = array_diff(array_unique(array_merge(['.html', '.htm', '/'], url_arbo_terminaison(''))), ['']);
if (count($t)) {
$url_propre = preg_replace('{('
. implode('|',