diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f6fb500
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+/vendor/
+/composer.phar
+/composer.lock
+/phpcs.xml
+/phpstan.neon
+/.php_cs.cache
+/.php_cs.txt
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..889d1e4
--- /dev/null
+++ b/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"
+ }
+}
diff --git a/engine/textwheel.php b/engine/textwheel.php
index 9cb9b64..03aa99e 100644
--- a/engine/textwheel.php
+++ b/engine/textwheel.php
@@ -22,15 +22,15 @@ if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
-require_once dirname(__FILE__) . "/textwheelruleset.php";
+require_once dirname(__FILE__) . '/textwheelruleset.php';
class TextWheel {
protected $ruleset;
- protected static $subwheel = array();
+ protected static $subwheel = [];
// Experimental : projet de compilation PHP d'une wheel
// pour generation d'un fichier php execute a la place de ->text()
- protected $compiled = array();
+ protected $compiled = [];
/**
* Constructor
@@ -62,9 +62,8 @@ class TextWheel {
public function text($t) {
$rules = &$this->ruleset->getRules();
## apply each in order
- foreach ($rules as $name => $rule) #php4+php5
- {
- $this->apply($rules[$name], $t);
+ foreach ($rules as $name => $rule) { #php4+php5
+ $this->apply($rules[$name], $t);
}
#foreach ($this->rules as &$rule) #smarter &reference, but php5 only
# $this->apply($rule, $t);
@@ -79,20 +78,21 @@ class TextWheel {
$rules = &$this->ruleset->getRules();
## apply each in order
- $pre = array();
- $comp = array();
+ $pre = [];
+ $comp = [];
foreach ($rules as $name => $rule) {
$rule->name = $name;
$this->initRule($rule);
- if ($rule->replace
+ if (
+ $rule->replace
and $compiledEntry = $this->ruleCompiledEntryName($rule->replace)
and isset($this->compiled[$compiledEntry])
and $fun = $this->compiled[$compiledEntry]
) {
$pre[] = "\n###\n## $name\n###\n" . $fun;
preg_match(',function (\w+), ', $fun, $r);
- $rule->compilereplace = "'".$r[1]."'"; # ne pas modifier ->replace sinon on casse l'execution...
+ $rule->compilereplace = "'" . $r[1] . "'"; # ne pas modifier ->replace sinon on casse l'execution...
}
$r = "\t/* $name */\n";
@@ -226,7 +226,7 @@ class TextWheel {
elseif ($rule->is_wheel) {
$rule_number = count(TextWheel::$subwheel);
TextWheel::$subwheel[] = $this->createSubWheel($rule->replace);
- $cname = 'compiled_' . str_replace('-', '_', $rule->name) . '_' . substr(md5(spl_object_hash($rule)),0,7);
+ $cname = 'compiled_' . str_replace('-', '_', $rule->name) . '_' . substr(md5(spl_object_hash($rule)), 0, 7);
if ($rule->type == 'all' or $rule->type == 'str' or $rule->type == 'split' or !isset($rule->match)) {
$rule->replace = function ($m) use ($rule_number) {
return TextWheel::getSubWheel($rule_number)->text($m);
@@ -238,7 +238,7 @@ class TextWheel {
$rule->replace = function ($m) use ($rule_number, $pick_match) {
return TextWheel::getSubWheel($rule_number)->text($m[$pick_match]);
};
- $rule->compilereplace = 'function ($m) { return '.$cname.'($m['.$pick_match.']) }';
+ $rule->compilereplace = 'function ($m) { return ' . $cname . '($m[' . $pick_match . ']) }';
}
$rule->is_wheel = false;
$rule->is_callback = true;
@@ -256,7 +256,8 @@ class TextWheel {
case 'str':
$rule->func_replace = 'replace_str';
// test if quicker strtr usable
- if (!$rule->is_callback
+ if (
+ !$rule->is_callback
and is_array($rule->match) and is_array($rule->replace)
and $c = array_map('strlen', $rule->match)
and $c = array_unique($c)
@@ -274,7 +275,7 @@ class TextWheel {
break;
case 'split':
$rule->func_replace = 'replace_split';
- $rule->match = array($rule->match, is_null($rule->glue) ? $rule->match : $rule->glue);
+ $rule->match = [$rule->match, is_null($rule->glue) ? $rule->match : $rule->glue];
break;
case 'preg':
default:
@@ -285,7 +286,7 @@ class TextWheel {
$rule->func_replace .= '_cb';
}
}
- if (!method_exists("TextWheel", $rule->func_replace)) {
+ if (!method_exists('TextWheel', $rule->func_replace)) {
$rule->disabled = true;
$rule->func_replace = 'replace_identity';
}
@@ -512,11 +513,11 @@ class TextWheelDebug extends TextWheel {
if ($p < 1000) {
$s = '';
} else {
- $s = sprintf("%d ", $x = floor($p / 1000));
+ $s = sprintf('%d ', $x = floor($p / 1000));
$p -= ($x * 1000);
}
- return $s . sprintf("%.3f ms", $p);
+ return $s . sprintf('%.3f ms', $p);
}
}
@@ -529,11 +530,10 @@ class TextWheelDebug extends TextWheel {
public function text($t) {
$rules = &$this->ruleset->getRules();
## apply each in order
- foreach ($rules as $name => $rule) #php4+php5
- {
- if (is_int($name)) {
+ foreach ($rules as $name => $rule) { #php4+php5
+ if (is_int($name)) {
$name .= ' ' . $rule->match;
- }
+ }
$this->timer($name);
$b = $t;
$this->apply($rule, $t);
@@ -546,7 +546,6 @@ class TextWheelDebug extends TextWheel {
} else {
TextWheelDebug::$tnu[$name] += $v;
}
-
}
#foreach ($this->rules as &$rule) #smarter &reference, but php5 only
# $this->apply($rule, $t);
@@ -582,15 +581,19 @@ class TextWheelDebug extends TextWheel {
$total += $t;
if (intval($t * 10)) {
echo "
- " . number_format(round($t * 10) / 10, 1) . " | " . spip_htmlspecialchars($r) . " |
- " . $applications . "/" . intval(TextWheelDebug::$w[$r]) . " |
- " . ($applications ? number_format(round(TextWheelDebug::$tu[$r] / $applications * 100) / 100,
- 2) : "") . " |
- " . (($nu = intval(TextWheelDebug::$w[$r]) - $applications) ? number_format(round(TextWheelDebug::$tnu[$r] / $nu * 100) / 100,
- 2) : "") . " |
-
";
+ " . number_format(round($t * 10) / 10, 1) . ' | ' . spip_htmlspecialchars($r) . ' |
+ ' . $applications . '/' . intval(TextWheelDebug::$w[$r]) . " |
+ " . ($applications ? number_format(
+ round(TextWheelDebug::$tu[$r] / $applications * 100) / 100,
+ 2
+ ) : '') . " |
+ " . (($nu = intval(TextWheelDebug::$w[$r]) - $applications) ? number_format(
+ round(TextWheelDebug::$tnu[$r] / $nu * 100) / 100,
+ 2
+ ) : '') . ' |
+ ';
}
}
echo "\n";
@@ -601,9 +604,9 @@ class TextWheelDebug extends TextWheel {
temps | rule |
\n";
ksort($GLOBALS['totaux']);
TextWheelDebug::outputTotal($GLOBALS['totaux']);
- echo "";
+ echo '';
# somme des temps des rules, ne tient pas compte des subwheels
- echo "temps total rules: " . round($total) . " ms
\n";
+ echo 'temps total rules: ' . round($total) . " ms
\n";
echo "\n";
}
}
@@ -631,7 +634,6 @@ class TextWheelDebug extends TextWheel {
protected function &createSubWheel(&$rules) {
return new TextWheelDebug($rules);
}
-
}
diff --git a/engine/textwheelrule.php b/engine/textwheelrule.php
index 2f0efc2..ce8a553 100644
--- a/engine/textwheelrule.php
+++ b/engine/textwheelrule.php
@@ -103,5 +103,4 @@ class TextWheelRule {
}
}
}
-
}
diff --git a/engine/textwheelruleset.php b/engine/textwheelruleset.php
index 02d71a2..c19b4c0 100644
--- a/engine/textwheelruleset.php
+++ b/engine/textwheelruleset.php
@@ -28,11 +28,11 @@ if (!defined('_WHEELS_FORMAT_DEFAUT')) {
define('_WHEELS_FORMAT_DEFAUT', 'json');
}
-require_once dirname(__FILE__) . "/textwheelrule.php";
+require_once dirname(__FILE__) . '/textwheelrule.php';
abstract class TextWheelDataSet {
# list of data
- protected $data = array();
+ protected $data = [];
/**
* file finder : can be overloaded in order to use application dependant
@@ -76,7 +76,7 @@ abstract class TextWheelDataSet {
protected function loadFile(&$file, $default_path = '') {
if (!preg_match(',[.](yaml|json)$,i', $file, $matches)) {
// Le fichier est fourni sans son extension, on essaie avec le json puis le yaml sinon.
- $formats = (_WHEELS_FORMAT_DEFAUT === 'json') ? array('json', 'yaml') : array('yaml', 'json');
+ $formats = (_WHEELS_FORMAT_DEFAUT === 'json') ? ['json', 'yaml'] : ['yaml', 'json'];
$name = $file;
foreach ($formats as $format) {
$file = $name . '.' . $format;
@@ -92,7 +92,7 @@ abstract class TextWheelDataSet {
!$file
or (!$file = $this->findFile($file, $default_path))
) {
- return array();
+ return [];
}
defined('_YAML_EVAL_PHP') || define('_YAML_EVAL_PHP', false);
@@ -102,25 +102,25 @@ abstract class TextWheelDataSet {
include_spip('inc/yaml');
$dataset = yaml_decode(file_get_contents($file));
} else {
- $dataset = array();
+ $dataset = [];
}
if (is_null($dataset)) {
- $dataset = array();
+ $dataset = [];
}
# throw new DomainException('rule file is empty, unreadable or badly formed: '.$file.var_export($dataset,true));
// if a php file with same name exists
// include it as it contains callback functions
- if ($f = preg_replace(',[.](yaml|json)$,i', '.php', $file)
+ if (
+ $f = preg_replace(',[.](yaml|json)$,i', '.php', $file)
and file_exists($f)
) {
- $dataset[] = array('require' => $f, 'priority' => -1000);
+ $dataset[] = ['require' => $f, 'priority' => -1000];
}
return $dataset;
}
-
}
class TextWheelRuleSet extends TextWheelDataSet {
@@ -133,7 +133,7 @@ class TextWheelRuleSet extends TextWheelDataSet {
* @param array|string $ruleset
* @param string $filepath
*/
- public function __construct($ruleset = array(), $filepath = '') {
+ public function __construct($ruleset = [], $filepath = '') {
if ($ruleset) {
$this->addRules($ruleset, $filepath);
}
@@ -251,14 +251,14 @@ class TextWheelRuleSet extends TextWheelDataSet {
*/
protected function sort() {
if (!$this->sorted) {
- $rulz = array();
+ $rulz = [];
foreach ($this->data as $index => $rule) {
if (!$rule->disabled) {
$rulz[intval($rule->priority)][$index] = $rule;
}
}
ksort($rulz);
- $this->data = array();
+ $this->data = [];
foreach ($rulz as $rules) {
$this->data += $rules;
}
diff --git a/inc/autoliens.php b/inc/autoliens.php
index 28aeeb0..efe5742 100644
--- a/inc/autoliens.php
+++ b/inc/autoliens.php
@@ -1,6 +1,5 @@
url
// https://code.spip.net/@traiter_raccourci_liens
function tw_autoliens($t) {
@@ -10,7 +9,7 @@ function tw_autoliens($t) {
$t = preg_replace_callback(_EXTRAIRE_LIENS, 'tw_traiter_autoliens', $t);
// echapper les autoliens eventuellement inseres (en une seule fois)
- if (strpos($t, "") !== false) {
+ if (strpos($t, '') !== false) {
$t = echappe_html($t);
}
diff --git a/inc/lien.php b/inc/lien.php
index 2968487..a385fd2 100644
--- a/inc/lien.php
+++ b/inc/lien.php
@@ -42,7 +42,7 @@ function inc_lien_dist(
$hlang = '',
$rel = '',
$connect = '',
- $env = array()
+ $env = []
) {
static $u = null;
if (!$u) {
@@ -71,8 +71,11 @@ function inc_lien_dist(
$row = sql_fetsel('*', $table_objet_sql, "$id_table_objet=" . intval($id))
and isset($row['id_trad'])
and isset($row['lang'])
- and $id_dest = sql_getfetsel($id_table_objet, $table_objet_sql,
- "id_trad=" . intval($row['id_trad']) . " AND lang=" . sql_quote($hlang))
+ and $id_dest = sql_getfetsel(
+ $id_table_objet,
+ $table_objet_sql,
+ 'id_trad=' . intval($row['id_trad']) . ' AND lang=' . sql_quote($hlang)
+ )
and objet_test_si_publie($type, $id_dest)
) {
$lien = "$type$id_dest";
@@ -93,23 +96,23 @@ function inc_lien_dist(
$class = $lien['class'];
}
$lang = isset($lien['lang']) ? $lien['lang'] : '';
- $mime = isset($lien['mime']) ? " type='" . $lien['mime'] . "'" : "";
+ $mime = isset($lien['mime']) ? " type='" . $lien['mime'] . "'" : '';
$lien = $lien['url'];
}
$lien = trim($lien);
- if (strncmp($lien, "#", 1) == 0) { # ancres pures (internes a la page)
+ if (strncmp($lien, '#', 1) == 0) { # ancres pures (internes a la page)
$class = 'spip_ancre';
} elseif (strncasecmp($lien, 'mailto:', 7) == 0) { # pseudo URL de mail
- $class = "spip_mail";
+ $class = 'spip_mail';
} elseif (strncmp($texte, '', 6) == 0) { # cf traiter_lien_explicite
- $class = "spip_url";
+ $class = 'spip_url';
# spip_out sur les URLs externes
if (
preg_match(',^\w+://,iS', $lien)
and strncasecmp($lien, url_de_base(), strlen(url_de_base()))
) {
- $class .= " spip_out";
+ $class .= ' spip_out';
}
} elseif (!$class) {
# spip_out sur les URLs externes
@@ -117,7 +120,7 @@ function inc_lien_dist(
preg_match(',^\w+://,iS', $lien)
and strncasecmp($lien, url_de_base(), strlen(url_de_base()))
) {
- $class = "spip_out"; # si pas spip_in|spip_glossaire
+ $class = 'spip_out'; # si pas spip_in|spip_glossaire
}
}
if ($class) {
@@ -158,8 +161,11 @@ function inc_lien_dist(
// les rares cas de lien qui encapsule un modele passe en dessous, c'est plus lent
if (traiter_modeles($texte, false, '', $connect, null, $env) == $texte) {
$texte = typo($texte, true, $connect, $env);
- $lien = "$texte";
+ $lien = '$texte";
if ($lang_objet_prev !== '') {
if ($lang_objet_prev) {
$GLOBALS['lang_objet'] = $lang_objet_prev;
@@ -175,7 +181,7 @@ function inc_lien_dist(
# Attention, le texte initial est deja echappe mais pas forcement
# celui retourne par calculer_url.
# Penser au cas [->URL], qui exige typo('...')
- $lien = "$texte";
+ $lien = '$texte";
#$res = typo($lien, true, $connect, $env);
$p = $GLOBALS['toujours_paragrapher'];
$GLOBALS['toujours_paragrapher'] = false;
@@ -209,7 +215,7 @@ function inc_lien_dist(
* @return string
* Retourne une balise HTML de lien ou une chaîne vide.
*/
-function balise_a($args = array()) {
+function balise_a($args = []) {
$balise_a = '';
// Il faut soit au minimum un href OU un name pour réussir à générer quelque chose
@@ -248,14 +254,14 @@ function balise_a($args = array()) {
// Laisser passer des paires de crochets pour la balise multi
// mais refuser plus d'imbrications ou de mauvaises imbrications
// sinon les crochets ne peuvent plus servir qu'a ce type de raccourci
-define('_RACCOURCI_LIEN', "/\[([^][]*?([[][^]>-]*[]][^][]*)*)->(>?)([^]]*)\]/msS");
+define('_RACCOURCI_LIEN', '/\[([^][]*?([[][^]>-]*[]][^][]*)*)->(>?)([^]]*)\]/msS');
// https://code.spip.net/@expanser_liens
-function expanser_liens($t, $connect = '', $env = array()) {
+function expanser_liens($t, $connect = '', $env = []) {
$t = pipeline('pre_liens', $t);
if (strpos($t, '\[') !== false or strpos($t, '\]') !== false) {
- $t = str_replace(array('\[', '\]'), array("\x1\x5", "\x1\x6"), $t);
+ $t = str_replace(['\[', '\]'], ["\x1\x5", "\x1\x6"], $t);
}
expanser_un_lien($connect, 'init', $env);
@@ -269,7 +275,7 @@ function expanser_liens($t, $connect = '', $env = array()) {
$t = traiter_modeles($t, false, false, $connect, expanser_un_lien('', 'sources'), $env);
if (strpos($t, "\x1") !== false) {
- $t = str_replace(array("\x1\x5", "\x1\x6"), array('[', ']'), $t);
+ $t = str_replace(["\x1\x5", "\x1\x6"], ['[', ']'], $t);
}
$t = corriger_typo($t);
@@ -281,14 +287,14 @@ function expanser_liens($t, $connect = '', $env = array()) {
function expanser_un_lien($reg, $quoi = 'echappe', $env = null) {
- static $pile = array();
+ static $pile = [];
static $inserts;
static $sources;
static $regs;
static $k = 0;
static $lien;
static $connect = '';
- static $contexte = array();
+ static $contexte = [];
switch ($quoi) {
case 'init':
@@ -298,8 +304,8 @@ function expanser_un_lien($reg, $quoi = 'echappe', $env = null) {
if (!is_null($env)) {
$contexte = $env;
}
- array_push($pile, array($inserts, $sources, $regs, $connect, $k));
- $inserts = $sources = $regs = array();
+ array_push($pile, [$inserts, $sources, $regs, $connect, $k]);
+ $inserts = $sources = $regs = [];
$connect = $reg; // stocker le $connect pour les appels a inc_lien_dist
$k = 0;
@@ -335,7 +341,7 @@ function expanser_un_lien($reg, $quoi = 'echappe', $env = null) {
return $reg;
break;
case 'sources':
- return array($inserts, $sources);
+ return [$inserts, $sources];
break;
}
}
@@ -363,7 +369,7 @@ function nettoyer_raccourcis_typo($texte, $connect = '') {
$texte = preg_replace("/(^|\r|\n)(-[-#\*]*\s?|_ )/", "\n", $texte);
// travailler en accents charset
- $texte = unicode2charset(html2unicode($texte, true /* secure */ ));
+ $texte = unicode2charset(html2unicode($texte, true /* secure */));
if (preg_match_all(_RACCOURCI_LIEN, $texte, $regs, PREG_SET_ORDER)) {
include_spip('inc/texte');
@@ -391,13 +397,13 @@ function nettoyer_raccourcis_typo($texte, $connect = '') {
}
// supprimer les ancres
- $texte = preg_replace(_RACCOURCI_ANCRE, "", $texte);
+ $texte = preg_replace(_RACCOURCI_ANCRE, '', $texte);
// supprimer les notes
- $texte = preg_replace(",\[\[.*\]\],UimsS", "", $texte);
+ $texte = preg_replace(',\[\[.*\]\],UimsS', '', $texte);
// supprimer les codes typos
- $texte = str_replace(array('}', '{'), '', $texte);
+ $texte = str_replace(['}', '{'], '', $texte);
// supprimer les tableaux
$texte = preg_replace(",(?:^|\r|\n)\|.*\|(?:\r|\n|$),s", "\r", $texte);
@@ -427,7 +433,7 @@ function traiter_raccourci_lien_atts($texte) {
// title et hreflang donnes par le raccourci ?
if (
- strpbrk($texte, "|{") !== false
+ strpbrk($texte, '|{') !== false
and preg_match(_RACCOURCI_ATTRIBUTS, $texte, $m)
) {
$n = count($m);
@@ -473,7 +479,7 @@ function traiter_raccourci_lien_atts($texte) {
$bulle = corriger_typo($bulle);
}
- return array(trim($texte), $bulle, $hlang);
+ return [trim($texte), $bulle, $hlang];
}
define('_EXTRAIRE_DOMAINE', '/^(?:(?:[^\W_]((?:[^\W_]|-){0,61}[^\W_,])?\.)+[a-z0-9]{2,6}|localhost)\b/Si');
@@ -481,14 +487,14 @@ define('_RACCOURCI_CHAPO', '/^(\W*)(\W*)(\w*\d+([?#].*)?)$/');
/**
* Retourne la valeur d'un champ de redirection (articles virtuels)
- *
- * L'entrée accepte plusiers types d'écritures :
- * - une URL compète,
- * - un lien SPIP tel que `[Lien->article23]`,
+ *
+ * L'entrée accepte plusiers types d'écritures :
+ * - une URL compète,
+ * - un lien SPIP tel que `[Lien->article23]`,
* - ou un raccourcis SPIP comme `rub2` ou `rubrique2`
*
* @param string $virtuel
- * Texte qui définit la redirection, à analyser.
+ * Texte qui définit la redirection, à analyser.
* Plusieurs types peuvent être acceptés :
* - un raccourci Spip habituel, tel que `[texte->TYPEnnn]`
* - un ultra raccourci Spip, tel que `TYPEnnn`
@@ -531,12 +537,12 @@ function calculer_url($ref, $texte = '', $pour = 'url', $connect = '', $echappe_
return $r;
}
-define('_EXTRAIRE_LIEN', ",^\s*(http:?/?/?|mailto:?)\s*$,iS");
+define('_EXTRAIRE_LIEN', ',^\s*(http:?/?/?|mailto:?)\s*$,iS');
// https://code.spip.net/@traiter_lien_explicite
function traiter_lien_explicite($ref, $texte = '', $pour = 'url', $connect = '', $echappe_typo = true) {
if (preg_match(_EXTRAIRE_LIEN, $ref)) {
- return ($pour != 'tout') ? '' : array('', '', '', '');
+ return ($pour != 'tout') ? '' : ['', '', '', ''];
}
$lien = entites_html(trim($ref));
@@ -551,19 +557,19 @@ function traiter_lien_explicite($ref, $texte = '', $pour = 'url', $connect = '',
}
$texte = $lien_court($texte);
if ($echappe_typo) {
- $texte = "" . quote_amp($texte) . "";
+ $texte = '' . quote_amp($texte) . '';
}
}
// petites corrections d'URL
if (preg_match('/^www\.[^@]+$/S', $lien)) {
- $lien = "http://" . $lien;
+ $lien = 'http://' . $lien;
} else {
- if (strpos($lien, "@") && email_valide($lien)) {
+ if (strpos($lien, '@') && email_valide($lien)) {
if (!$texte) {
$texte = $lien;
}
- $lien = "mailto:" . $lien;
+ $lien = 'mailto:' . $lien;
}
}
@@ -575,7 +581,7 @@ function traiter_lien_explicite($ref, $texte = '', $pour = 'url', $connect = '',
return $texte;
}
- return array('url' => $lien, 'titre' => $texte);
+ return ['url' => $lien, 'titre' => $texte];
}
function liens_implicite_glose_dist($texte, $id, $type, $args, $ancre, $connect = '') {
@@ -619,7 +625,7 @@ function traiter_lien_implicite($ref, $texte = '', $pour = 'url', $connect = '')
# attention dans le cas des sites le lien doit pointer non pas sur
# la page locale du site, mais directement sur le site lui-meme
$url = '';
- if ($f = charger_fonction("implicite_$type", "liens", true)) {
+ if ($f = charger_fonction("implicite_$type", 'liens', true)) {
$url = $f($texte, $id, $type, $args, $ancre, $connect);
}
@@ -662,9 +668,16 @@ function traiter_lien_implicite($ref, $texte = '', $pour = 'url', $connect = '')
// dans le cas d'un lien vers un doc, ajouter le type='mime/type'
if (
$type == 'document'
- and $mime = sql_getfetsel('mime_type', 'spip_types_documents',
- "extension IN (" . sql_get_select("extension", "spip_documents", "id_document=" . sql_quote($id)) . ")",
- '', '', '', '', $connect)
+ and $mime = sql_getfetsel(
+ 'mime_type',
+ 'spip_types_documents',
+ 'extension IN (' . sql_get_select('extension', 'spip_documents', 'id_document=' . sql_quote($id)) . ')',
+ '',
+ '',
+ '',
+ '',
+ $connect
+ )
) {
$r['mime'] = $mime;
}
@@ -679,7 +692,7 @@ define('_RACCOURCI_URL', '/^\s*(\w*?)\s*(\d+)(\?(.*?))?(#([^\s]*))?\s*$/S');
// https://code.spip.net/@typer_raccourci
function typer_raccourci($lien) {
if (!preg_match(_RACCOURCI_URL, $lien, $match)) {
- return array();
+ return [];
}
$f = $match[1];
@@ -733,14 +746,14 @@ function traiter_raccourci_titre($id, $type, $connect = null) {
$desc = $trouver_table(table_objet($type));
if (!($desc and $s = $desc['titre'])) {
- return array();
+ return [];
}
$_id = $desc['key']['PRIMARY KEY'];
$r = sql_fetsel($s, $desc['table'], "$_id=$id", '', '', '', '', $connect);
if (!$r) {
- return array();
+ return [];
}
$r['titre'] = supprimer_numero($r['titre']);
@@ -763,14 +776,16 @@ function traiter_raccourci_titre($id, $type, $connect = null) {
// Si $doublons==true, on repere les documents sans calculer les modeles
// mais on renvoie les params (pour l'indexation par le moteur de recherche)
// https://code.spip.net/@traiter_modeles
-define('_PREG_MODELE',
+define(
+ '_PREG_MODELE',
'(<([a-z_-]{3,})' # ]*>|[^>])*?)?' # |arguments (y compris des tags <...>)
. '\s*/?' . '>)' # fin du modele >
);
-define('_RACCOURCI_MODELE',
+define(
+ '_RACCOURCI_MODELE',
_PREG_MODELE
. '\s*(<\/a>)?' # eventuel
);
@@ -778,19 +793,19 @@ define('_RACCOURCI_MODELE',
define('_RACCOURCI_MODELE_DEBUT', '@^' . _RACCOURCI_MODELE . '@isS');
// https://code.spip.net/@traiter_modeles
-function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '', $liens = null, $env = array()) {
+function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '', $liens = null, $env = []) {
// preserver la compatibilite : true = recherche des documents
if ($doublons === true) {
- $doublons = array('documents' => array('doc', 'emb', 'img'));
+ $doublons = ['documents' => ['doc', 'emb', 'img']];
}
// detecter les modeles (rapide)
if (
- strpos($texte, "<") !== false
+ strpos($texte, '<') !== false
and preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)
) {
include_spip('public/assembler');
- $wrap_embed_html = charger_fonction("wrap_embed_html", "inc", true);
+ $wrap_embed_html = charger_fonction('wrap_embed_html', 'inc', true);
// Recuperer l'appel complet (y compris un eventuel lien)
foreach ($matches as $match) {
@@ -799,7 +814,7 @@ function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '',
// s'assurer qu'il y a toujours un 5e arg, eventuellement vide
while (count($regs) < 6) {
- $regs[] = "";
+ $regs[] = '';
}
list(, $mod, $type, $id, $params, $fin) = $regs;
@@ -808,13 +823,13 @@ function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '',
$fin
and preg_match('/]*>\s*$/i', substr($texte, 0, $a), $r)
) {
- $lien = array(
+ $lien = [
'href' => extraire_attribut($r[0], 'href'),
'class' => extraire_attribut($r[0], 'class'),
'mime' => extraire_attribut($r[0], 'type'),
'title' => extraire_attribut($r[0], 'title'),
'hreflang' => extraire_attribut($r[0], 'hreflang')
- );
+ ];
$n = strlen($r[0]);
$a -= $n;
$cherche = $n + strlen($regs[0]);
@@ -847,18 +862,18 @@ function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '',
$modele = str_replace($liens[0], $liens[1], $modele);
}
- $contexte = array_merge($env, array('id' => $id, 'type' => $type, 'modele' => $modele));
+ $contexte = array_merge($env, ['id' => $id, 'type' => $type, 'modele' => $modele]);
if ($lien) {
# un eventuel guillemet (") sera reechappe par #ENV
- $contexte['lien'] = str_replace(""", '"', $lien['href']);
+ $contexte['lien'] = str_replace('"', '"', $lien['href']);
$contexte['lien_class'] = $lien['class'];
$contexte['lien_mime'] = $lien['mime'];
$contexte['lien_title'] = $lien['title'];
$contexte['lien_hreflang'] = $lien['hreflang'];
}
- $modele = recuperer_fond("modeles/dist", $contexte, array(), $connect);
+ $modele = recuperer_fond('modeles/dist', $contexte, [], $connect);
}
// le remplacer dans le texte
if ($modele !== false) {
@@ -875,7 +890,7 @@ function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '',
// hack pour tout l'espace prive
if (((!_DIR_RESTREINT) or ($doublons)) and ($id)) {
- foreach ($doublons ? $doublons : array('documents' => array('doc', 'emb', 'img')) as $quoi => $modeles) {
+ foreach ($doublons ? $doublons : ['documents' => ['doc', 'emb', 'img']] as $quoi => $modeles) {
if (in_array(strtolower($type), $modeles)) {
$GLOBALS["doublons_{$quoi}_inclus"][] = $id;
}
@@ -891,7 +906,7 @@ function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '',
// Raccourcis ancre [#ancre<-]
//
-define('_RACCOURCI_ANCRE', "/\[#?([^][]*)<-\]/S");
+define('_RACCOURCI_ANCRE', '/\[#?([^][]*)<-\]/S');
// https://code.spip.net/@traiter_raccourci_ancre
function traiter_raccourci_ancre($letexte) {
@@ -913,7 +928,7 @@ function traiter_raccourci_ancre($letexte) {
// Wikipedia par defaut, avec ses contraintes techniques
// cf. http://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Conventions_sur_les_titres
-define('_RACCOURCI_GLOSSAIRE', "/\[\?+\s*([^][<>]+)\]/S");
+define('_RACCOURCI_GLOSSAIRE', '/\[\?+\s*([^][<>]+)\]/S');
define('_RACCOURCI_GLOSES', '/^([^|#{]*\w[^|#{]*)([^#]*)(#([^|{}]*))?(.*)$/S');
// https://code.spip.net/@traiter_raccourci_glossaire
@@ -958,18 +973,18 @@ function glossaire_std($terme) {
if ($pcre === null) {
$pcre = isset($GLOBALS['meta']['pcre_u']) ? $GLOBALS['meta']['pcre_u'] : '';
- if (strpos($url_glossaire_externe, "%s") === false) {
+ if (strpos($url_glossaire_externe, '%s') === false) {
$url_glossaire_externe .= '%s';
}
}
$glosateur = str_replace(
- "@lang@",
+ '@lang@',
$GLOBALS['spip_lang'],
$GLOBALS['url_glossaire_externe']
);
$terme = rawurlencode(preg_replace(',\s+,' . $pcre, '_', $terme));
- return str_replace("%s", $terme, $glosateur);
+ return str_replace('%s', $terme, $glosateur);
}
diff --git a/inc/notes.php b/inc/notes.php
index 395e76a..7c1ae6a 100644
--- a/inc/notes.php
+++ b/inc/notes.php
@@ -16,7 +16,7 @@
* @package SPIP\Textwheel\Notes
**/
-if (!defined("_ECRIRE_INC_VERSION")) {
+if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
@@ -67,7 +67,7 @@ if (!defined('_NOTES_RACCOURCI')) {
* @return string|array
**/
function inc_notes_dist($arg, $operation = 'traiter', $ignorer_autobr = false) {
- static $pile = array();
+ static $pile = [];
static $next_marqueur = 1;
static $marqueur = 1;
global $les_notes, $compt_note, $notes_vues;
@@ -80,12 +80,11 @@ function inc_notes_dist($arg, $operation = 'traiter', $ignorer_autobr = false) {
}
break;
case 'empiler':
- if ($compt_note == 0) // si le marqueur n'a pas encore ete utilise, on le recycle dans la pile courante
- {
- array_push($pile, array(@$les_notes, @$compt_note, $notes_vues, 0));
+ if ($compt_note == 0) { // si le marqueur n'a pas encore ete utilise, on le recycle dans la pile courante
+ array_push($pile, [@$les_notes, @$compt_note, $notes_vues, 0]);
} else {
// sinon on le stocke au chaud, et on en cree un nouveau
- array_push($pile, array(@$les_notes, @$compt_note, $notes_vues, $marqueur));
+ array_push($pile, [@$les_notes, @$compt_note, $notes_vues, $marqueur]);
$next_marqueur++; // chaque fois qu'on rempile on incremente le marqueur general
$marqueur = $next_marqueur; // et on le prend comme marqueur courant
}
@@ -95,7 +94,7 @@ function inc_notes_dist($arg, $operation = 'traiter', $ignorer_autobr = false) {
case 'depiler':
#$prev_notes = $les_notes;
if (strlen($les_notes)) {
- spip_log("notes perdues");
+ spip_log('notes perdues');
}
// si le marqueur n'a pas servi, le liberer
if (!strlen($les_notes) and $marqueur == $next_marqueur) {
@@ -112,34 +111,33 @@ function inc_notes_dist($arg, $operation = 'traiter', $ignorer_autobr = false) {
break;
case 'sauver_etat':
if ($compt_note or $marqueur > 1 or $next_marqueur > 1) {
- return array($les_notes, $compt_note, $notes_vues, $marqueur, $next_marqueur);
+ return [$les_notes, $compt_note, $notes_vues, $marqueur, $next_marqueur];
} else {
return '';
} // rien a sauver
break;
case 'restaurer_etat':
- if ($arg and is_array($arg)) // si qqchose a restaurer
- {
- list($les_notes, $compt_note, $notes_vues, $marqueur, $next_marqueur) = $arg;
+ if ($arg and is_array($arg)) { // si qqchose a restaurer
+ list($les_notes, $compt_note, $notes_vues, $marqueur, $next_marqueur) = $arg;
}
break;
case 'contexter_cache':
if ($compt_note or $marqueur > 1 or $next_marqueur > 1) {
- return array("$compt_note:$marqueur:$next_marqueur");
+ return ["$compt_note:$marqueur:$next_marqueur"];
} else {
return '';
}
break;
case 'reset_all': // a n'utiliser qu'a fins de test
if (strlen($les_notes)) {
- spip_log("notes perdues [reset_all]");
+ spip_log('notes perdues [reset_all]');
}
- $pile = array();
+ $pile = [];
$next_marqueur = 1;
$marqueur = 1;
$les_notes = '';
$compt_note = 0;
- $notes_vues = array();
+ $notes_vues = [];
break;
}
}
@@ -148,15 +146,16 @@ function inc_notes_dist($arg, $operation = 'traiter', $ignorer_autobr = false) {
function traiter_raccourci_notes($letexte, $marqueur_notes) {
global $compt_note, $notes_vues;
- if (strpos($letexte, '[[') === false
+ if (
+ strpos($letexte, '[[') === false
or !preg_match_all(_NOTES_RACCOURCI, $letexte, $m, PREG_SET_ORDER)
) {
- return array($letexte, array());
+ return [$letexte, []];
}
// quand il y a plusieurs series de notes sur une meme page
$mn = !$marqueur_notes ? '' : ($marqueur_notes . '-');
- $mes_notes = array();
+ $mes_notes = [];
foreach ($m as $r) {
list($note_source, $note_all, $ref, $nom, $note_texte) = $r;
@@ -165,7 +164,8 @@ function traiter_raccourci_notes($letexte, $marqueur_notes) {
// si la balise fermante correspondante existe
// Cas pathologique: [[ x]]
- if (!(isset($nom) and $ref
+ if (
+ !(isset($nom) and $ref
and ((strpos($note_texte, '' . $nom . '>') === false)
or preg_match(",<$nom\W.*$nom>,", $note_texte)))
) {
@@ -190,7 +190,7 @@ function traiter_raccourci_notes($letexte, $marqueur_notes) {
// ajouter la note aux notes precedentes
if ($note_texte) {
- $mes_notes[] = array($ancre, $nom, $note_texte);
+ $mes_notes[] = [$ancre, $nom, $note_texte];
}
// dans le texte, mettre l'appel de note a la place de la note
@@ -202,10 +202,9 @@ function traiter_raccourci_notes($letexte, $marqueur_notes) {
$letexte = rtrim(substr($letexte, 0, $pos), ' ')
. code_echappement($nom)
. substr($letexte, $pos + strlen($note_source));
-
}
- return array($letexte, $mes_notes);
+ return [$letexte, $mes_notes];
}
@@ -218,9 +217,9 @@ function traiter_les_notes($notes, $ignorer_autobr) {
list($ancre, $nom, $texte) = $r;
$atts = " href='#nh$ancre' class='spip_note' title='$title $ancre' rev='appendix'";
$mes_notes .= "\n\n"
- . ""
+ . "
'
. code_echappement($nom
- ? _NOTES_OUVRE_NOTE . "$nom" . _NOTES_FERME_NOTE
+ ? _NOTES_OUVRE_NOTE . '$nom" . _NOTES_FERME_NOTE
: '')
. trim($texte)
. '
';
diff --git a/inc/ressource.php b/inc/ressource.php
index aa6b429..c60427e 100644
--- a/inc/ressource.php
+++ b/inc/ressource.php
@@ -2,7 +2,7 @@
/*
* transforme un raccourci de ressource en un lien minimaliste
- *
+ *
*
*/
@@ -24,7 +24,7 @@ function tw_pre_liens($t) {
$t = preg_replace_callback(_EXTRAIRE_RESSOURCES, 'tw_traiter_ressources', $t);
// echapper les autoliens eventuellement inseres (en une seule fois)
- if (strpos($t, "") !== false) {
+ if (strpos($t, '') !== false) {
$t = echappe_html($t);
}
}
@@ -40,21 +40,20 @@ function tw_traiter_ressources($r) {
$url = $url[0];
#
if (preg_match(',^https?://,i', $url)) {
- $html = PtoBR(propre("<[->" . $url . "]>"));
+ $html = PtoBR(propre("<[->" . $url . ']>'));
} #
else {
if (false !== strpos($url, '/')) {
- $html = PtoBR(propre("<[->" . $url . "]>"));
+ $html = PtoBR(propre("<[->" . $url . ']>'));
} #
else {
-
if (
preg_match(',\.([^.]+)$,', $url, $regs)
and file_exists($f = _DIR_IMG . $regs[1] . '/' . $url)
) {
- $html = PtoBR(propre("<[" . $url . "->" . $f . "]>"));
+ $html = PtoBR(propre("<[" . $url . '->' . $f . ']>'));
} else {
- $html = PtoBR(propre("<" . $url . ">"));
+ $html = PtoBR(propre("<" . $url . '>'));
}
}
}
diff --git a/inc/texte.php b/inc/texte.php
index c044174..0c9a1e8 100644
--- a/inc/texte.php
+++ b/inc/texte.php
@@ -29,10 +29,10 @@ include_spip('inc/textwheel');
defined('_AUTOBR') || define('_AUTOBR', "
");
-define('_AUTOBR_IGNORER', _AUTOBR ? "" : "");
+define('_AUTOBR_IGNORER', _AUTOBR ? '' : '');
// Avec cette surcharge, cette globale n'est plus définie, et du coup ça plante dans les plugins qui font un foreach dessus comme ZPIP
-$GLOBALS['spip_raccourcis_typo'] = array();
+$GLOBALS['spip_raccourcis_typo'] = [];
if (!isset($GLOBALS['toujours_paragrapher'])) {
$GLOBALS['toujours_paragrapher'] = true;
}
@@ -90,18 +90,19 @@ function echappe_js($t) {
* Texte paragraphé
*/
function paragrapher($t, $toujours_paragrapher = null) {
- static $wheel = array();
+ static $wheel = [];
if (is_null($toujours_paragrapher)) {
$toujours_paragrapher = $GLOBALS['toujours_paragrapher'];
}
if (!isset($wheel[$toujours_paragrapher])) {
$ruleset = SPIPTextWheelRuleset::loader($GLOBALS['spip_wheels']['paragrapher']);
- if (!$toujours_paragrapher
+ if (
+ !$toujours_paragrapher
and $rule = $ruleset->getRule('toujours-paragrapher')
) {
$rule->disabled = true;
- $ruleset->addRules(array('toujours-paragrapher' => $rule));
+ $ruleset->addRules(['toujours-paragrapher' => $rule]);
}
$wheel[$toujours_paragrapher] = new TextWheel($ruleset);
}
@@ -139,12 +140,12 @@ function paragrapher($t, $toujours_paragrapher = null) {
* @return string
* Code protégé
**/
-function interdire_scripts($arg, $mode_filtre=null) {
+function interdire_scripts($arg, $mode_filtre = null) {
// on memorise le resultat sur les arguments non triviaux
- static $dejavu = array();
- static $wheel = array();
+ static $dejavu = [];
+ static $wheel = [];
- if (is_null($mode_filtre) or !in_array($mode_filtre, array(-1, 0, 1))) {
+ if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) {
$mode_filtre = $GLOBALS['filtrer_javascript'];
}
@@ -162,10 +163,11 @@ function interdire_scripts($arg, $mode_filtre=null) {
);
// Pour le js, trois modes : parano (-1), prive (0), ok (1)
// desactiver la regle echappe-js si besoin
- if ($mode_filtre == 1
+ if (
+ $mode_filtre == 1
or ($mode_filtre == 0 and !test_espace_prive())
) {
- $ruleset->addRules(array('securite-js' => array('disabled' => true)));
+ $ruleset->addRules(['securite-js' => ['disabled' => true]]);
}
$wheel[$mode_filtre] = new TextWheel($ruleset);
}
@@ -180,10 +182,10 @@ function interdire_scripts($arg, $mode_filtre=null) {
// Reinserer les echappements des modeles
if (defined('_PROTEGE_JS_MODELES')) {
- $t = echappe_retour($t, "javascript" . _PROTEGE_JS_MODELES);
+ $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES);
}
if (defined('_PROTEGE_PHP_MODELES')) {
- $t = echappe_retour($t, "php" . _PROTEGE_PHP_MODELES);
+ $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES);
}
return $dejavu[$mode_filtre][$arg] = $t;
@@ -214,7 +216,7 @@ function interdire_scripts($arg, $mode_filtre=null) {
* @return string $t
* Texte transformé
**/
-function typo($letexte, $echapper = true, $connect = null, $env = array()) {
+function typo($letexte, $echapper = true, $connect = null, $env = []) {
// Plus vite !
if (!$letexte) {
return $letexte;
@@ -268,8 +270,10 @@ function typo($letexte, $echapper = true, $connect = null, $env = array()) {
// https://core.spip.net/issues/3371
// et aussi dans l'espace public si la globale filtrer_javascript = -1
// https://core.spip.net/issues/4166
- if ($GLOBALS['filtrer_javascript'] == -1
- or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)) {
+ if (
+ $GLOBALS['filtrer_javascript'] == -1
+ or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
+ ) {
$letexte = echapper_html_suspect($letexte);
}
@@ -281,7 +285,7 @@ function typo($letexte, $echapper = true, $connect = null, $env = array()) {
define('_TYPO_PROTEGER', "!':;?~%-");
define('_TYPO_PROTECTEUR', "\x1\x2\x3\x4\x5\x6\x7\x8");
-define('_TYPO_BALISE', ",?[a-z!][^<>]*[" . preg_quote(_TYPO_PROTEGER) . "][^<>]*>,imsS");
+define('_TYPO_BALISE', ',?[a-z!][^<>]*[' . preg_quote(_TYPO_PROTEGER) . '][^<>]*>,imsS');
/**
* Corrige la typographie
@@ -298,7 +302,7 @@ define('_TYPO_BALISE', ",?[a-z!][^<>]*[" . preg_quote(_TYPO_PROTEGER) . "][^<>
* @return string Texte
*/
function corriger_typo($t, $lang = '') {
- static $typographie = array();
+ static $typographie = [];
// Plus vite !
if (!$t) {
return $t;
@@ -374,14 +378,14 @@ function traiter_tableau($bloc) {
// Decouper le tableau en lignes
preg_match_all(',([|].*)[|]\n,UmsS', $bloc, $regs, PREG_PATTERN_ORDER);
- $lignes = array();
+ $lignes = [];
$debut_table = $summary = '';
$l = 0;
// Traiter chaque ligne
$reg_line1 = ',^(\|(' . _RACCOURCI_TH_SPAN . '))+$,sS';
$reg_line_all = ',^(' . _RACCOURCI_TH_SPAN . ')$,sS';
- $hc = $hl = array();
+ $hc = $hl = [];
$thead_ok = false;
foreach ($regs[1] as $ligne) {
$l++;
@@ -400,18 +404,18 @@ function traiter_tableau($bloc) {
$describedby = '';
}
else {
- $iddescribedby = 'dby'.$tabid;
- $summary = ' aria-describedby="'.$iddescribedby.'"';
+ $iddescribedby = 'dby' . $tabid;
+ $summary = ' aria-describedby="' . $iddescribedby . '"';
}
}
if ($caption = trim($cap[1])) {
if ($describedby) {
- $caption .= '
' . $describedby . '';
+ $caption .= '
' . $describedby . '';
}
- $debut_table .= "" . $caption . "\n";
+ $debut_table .= '' . $caption . "\n";
}
elseif ($describedby) {
- $debut_table .= '' . $describedby . "\n";
+ $debut_table .= '' . $describedby . "\n";
}
}
// - sous la forme |{{titre}}|{{titre}}|
@@ -432,7 +436,7 @@ function traiter_tableau($bloc) {
$colspan = 1;
}
// inutile de garder le strong qui n'a servi que de marqueur
- $cols[$c] = str_replace(array('{', '}'), '', $cols[$c]);
+ $cols[$c] = str_replace(['{', '}'], '', $cols[$c]);
$ligne = "$cols[$c] | $ligne";
$hc[$c] = "id{$tabid}_c$c"; // pour mettre dans les headers des td
}
@@ -461,7 +465,7 @@ function traiter_tableau($bloc) {
// Pas de paragraphes dans les cellules
foreach ($cols[1] as &$col) {
if (strlen($col = trim($col))) {
- $col = preg_replace("/\n{2,}/S", "
", $col);
+ $col = preg_replace("/\n{2,}/S", '
', $col);
if (_AUTOBR) {
$col = str_replace("\n", _AUTOBR . "\n", $col);
}
@@ -477,16 +481,16 @@ function traiter_tableau($bloc) {
// on prepare une liste de rowspan par defaut, a partir
// du nombre de colonnes dans la premiere ligne.
// Reperer egalement les colonnes numeriques pour les cadrer a droite
- $rowspans = $numeric = array();
+ $rowspans = $numeric = [];
$n = $lignes ? count($lignes[0]) : 0;
$k = count($lignes);
// distinguer les colonnes numeriques a point ou a virgule,
// pour les alignements eventuels sur "," ou "."
- $numeric_class = array(
+ $numeric_class = [
'.' => 'point',
',' => 'virgule',
true => ''
- );
+ ];
for ($i = 0; $i < $n; $i++) {
$align = true;
for ($j = 0; $j < $k; $j++) {
@@ -509,7 +513,7 @@ function traiter_tableau($bloc) {
}
}
if (!isset($hl[0])) {
- $hl = array();
+ $hl = [];
} // toute la colonne ou rien
// et on parcourt le tableau a l'envers pour ramasser les
@@ -526,10 +530,8 @@ function traiter_tableau($bloc) {
$cell = trim($cols[$c]);
if ($cell == '<') {
$colspan++;
-
} elseif ($cell == '^') {
$rowspans[$l - 1][$c] += $rowspans[$l][$c];
-
} else {
if ($colspan > 1) {
$attr .= " colspan='$colspan'";
@@ -546,7 +548,7 @@ function traiter_tableau($bloc) {
// inutile de garder le strong qui n'a servi que de marqueur
if ($b == 'th') {
$attr .= " id='" . $hl[$l] . "'";
- $cols[$c] = str_replace(array('{', '}'), '', $cols[$c]);
+ $cols[$c] = str_replace(['{', '}'], '', $cols[$c]);
}
$ligne = "\n<$b" . $attr . '>' . $cols[$c] . "$b>" . $ligne;
}
@@ -558,12 +560,12 @@ function traiter_tableau($bloc) {
}
$class = $GLOBALS['class_spip_plus'];
- if (!$class or strpos($GLOBALS['class_spip_plus'],'class=') === false) {
+ if (!$class or strpos($GLOBALS['class_spip_plus'], 'class=') === false) {
$class = ' ' . trim('class="table" ' . $class);
}
else {
- $class = str_replace('class="','class="table ', $class);
- $class = str_replace("class='","class='table ", $class);
+ $class = str_replace('class="', 'class="table ', $class);
+ $class = str_replace("class='", "class='table ", $class);
}
return "\n\n\n"
. $debut_table
@@ -604,10 +606,10 @@ function traiter_listes($t) {
// Ces deux constantes permettent de proteger certains caracteres
// en les remplacanat par des caracteres "illegaux". (cf corriger_caracteres)
-define('_RACCOURCI_PROTEGER', "{}_-");
+define('_RACCOURCI_PROTEGER', '{}_-');
define('_RACCOURCI_PROTECTEUR', "\x1\x2\x3\x4");
-define('_RACCOURCI_BALISE', ",?[a-z!][^<>]*[" . preg_quote(_RACCOURCI_PROTEGER) . "][^<>]*>,imsS");
+define('_RACCOURCI_BALISE', ',?[a-z!][^<>]*[' . preg_quote(_RACCOURCI_PROTEGER) . '][^<>]*>,imsS');
/**
* mais d'abord, une callback de reconfiguration des raccourcis
@@ -622,44 +624,46 @@ function personnaliser_raccourcis(&$ruleset) {
if (isset($GLOBALS['debut_intertitre']) and $rule = $ruleset->getRule('intertitres')) {
$rule->replace[0] = preg_replace(',<[^>]*>,Uims', $GLOBALS['debut_intertitre'], $rule->replace[0]);
$rule->replace[1] = preg_replace(',<[^>]*>,Uims', $GLOBALS['fin_intertitre'], $rule->replace[1]);
- $ruleset->addRules(array('intertitres' => $rule));
+ $ruleset->addRules(['intertitres' => $rule]);
if ($rule = $ruleset->getRule('intertitres-compliques')) {
$rule->replace[0] = preg_replace(',<[^>]*>,Uims', $GLOBALS['debut_intertitre'], $rule->replace[0]);
$rule->replace[1] = preg_replace(',<[^>]*>,Uims', $GLOBALS['fin_intertitre'], $rule->replace[1]);
- $ruleset->addRules(array('intertitres-compliques' => $rule));
+ $ruleset->addRules(['intertitres-compliques' => $rule]);
}
}
if (isset($GLOBALS['debut_gras']) and $rule = $ruleset->getRule('gras')) {
$rule->replace[0] = preg_replace(',<[^>]*>,Uims', $GLOBALS['debut_gras'], $rule->replace[0]);
$rule->replace[1] = preg_replace(',<[^>]*>,Uims', $GLOBALS['fin_gras'], $rule->replace[1]);
- $ruleset->addRules(array('gras' => $rule));
+ $ruleset->addRules(['gras' => $rule]);
}
if (isset($GLOBALS['debut_italique']) and $rule = $ruleset->getRule('italiques')) {
$rule->replace[0] = preg_replace(',<[^>]*>,Uims', $GLOBALS['debut_italique'], $rule->replace[0]);
$rule->replace[1] = preg_replace(',<[^>]*>,Uims', $GLOBALS['fin_italique'], $rule->replace[1]);
- $ruleset->addRules(array('italiques' => $rule));
+ $ruleset->addRules(['italiques' => $rule]);
}
if (isset($GLOBALS['ligne_horizontale']) and $rule = $ruleset->getRule('ligne-horizontale')) {
$rule->replace = preg_replace(',<[^>]*>,Uims', $GLOBALS['ligne_horizontale'], $rule->replace);
- $ruleset->addRules(array('ligne-horizontale' => $rule));
+ $ruleset->addRules(['ligne-horizontale' => $rule]);
}
- if (isset($GLOBALS['toujours_paragrapher']) and !$GLOBALS['toujours_paragrapher']
+ if (
+ isset($GLOBALS['toujours_paragrapher']) and !$GLOBALS['toujours_paragrapher']
and $rule = $ruleset->getRule('toujours-paragrapher')
) {
$rule->disabled = true;
- $ruleset->addRules(array('toujours-paragrapher' => $rule));
+ $ruleset->addRules(['toujours-paragrapher' => $rule]);
}
}
// retourner une signature de l'etat de la fonction, pour la mise en cache
- return implode("/",
- array(
- isset($GLOBALS['debut_intertitre']) ? $GLOBALS['debut_intertitre'] : "",
- isset($GLOBALS['debut_gras']) ? $GLOBALS['debut_gras'] : "",
- isset($GLOBALS['debut_italique']) ? $GLOBALS['debut_italique'] : "",
- isset($GLOBALS['ligne_horizontale']) ? $GLOBALS['ligne_horizontale'] : "",
+ return implode(
+ '/',
+ [
+ isset($GLOBALS['debut_intertitre']) ? $GLOBALS['debut_intertitre'] : '',
+ isset($GLOBALS['debut_gras']) ? $GLOBALS['debut_gras'] : '',
+ isset($GLOBALS['debut_italique']) ? $GLOBALS['debut_italique'] : '',
+ isset($GLOBALS['ligne_horizontale']) ? $GLOBALS['ligne_horizontale'] : '',
isset($GLOBALS['toujours_paragrapher']) ? $GLOBALS['toujours_paragrapher'] : 1,
- )
+ ]
);
}
@@ -674,12 +678,13 @@ function personnaliser_raccourcis(&$ruleset) {
* @return string
*/
function traiter_raccourcis($t, $show_autobr = false) {
- static $wheel = array(), $notes;
+ static $wheel = [], $notes;
static $img_br_auto, $img_br_manuel, $img_br_no;
global $spip_lang, $spip_lang_rtl;
// hack1: respecter le tag ignore br
- if (_AUTOBR_IGNORER
+ if (
+ _AUTOBR_IGNORER
and strncmp($t, _AUTOBR_IGNORER, strlen(_AUTOBR_IGNORER)) == 0
) {
$ignorer_autobr = true;
@@ -691,15 +696,17 @@ function traiter_raccourcis($t, $show_autobr = false) {
// Appeler les fonctions de pre_traitement
$t = pipeline('pre_propre', $t);
- $key = "";
+ $key = '';
$key = personnaliser_raccourcis($key);
if (!isset($wheel[$key])) {
$ruleset = SPIPTextWheelRuleset::loader(
- $GLOBALS['spip_wheels']['raccourcis'], 'personnaliser_raccourcis'
+ $GLOBALS['spip_wheels']['raccourcis'],
+ 'personnaliser_raccourcis'
);
$wheel[$key] = new TextWheel($ruleset);
- if (_request('var_mode') == 'wheel'
+ if (
+ _request('var_mode') == 'wheel'
and autoriser('debug')
) {
$f = $wheel->compile();
@@ -733,22 +740,34 @@ function traiter_raccourcis($t, $show_autobr = false) {
// car en css on ne sait pas styler l'element BR
if ($ignorer_autobr and _AUTOBR) {
if (is_null($img_br_no)) {
- $img_br_no = ($show_autobr ? http_img_pack("br-no" . aide_lang_dir($spip_lang, $spip_lang_rtl) . "-10.png", '',
- "class='br-no'", _T("tw:retour_ligne_ignore")) : "");
- $img_br_no = inserer_attribut($img_br_no, 'aria-label', _T("tw:retour_ligne_ignore"));
+ $img_br_no = ($show_autobr ? http_img_pack(
+ 'br-no' . aide_lang_dir($spip_lang, $spip_lang_rtl) . '-10.png',
+ '',
+ "class='br-no'",
+ _T('tw:retour_ligne_ignore')
+ ) : '');
+ $img_br_no = inserer_attribut($img_br_no, 'aria-label', _T('tw:retour_ligne_ignore'));
}
$t = str_replace(_AUTOBR, $img_br_no, $t);
}
if ($show_autobr and _AUTOBR) {
if (is_null($img_br_manuel)) {
- $img_br_manuel = http_img_pack("br-manuel" . aide_lang_dir($spip_lang, $spip_lang_rtl) . "-10.png", '' ,
- "class='br-manuel'", _T("tw:retour_ligne_manuel"));
- $img_br_manuel = inserer_attribut($img_br_manuel, 'aria-label', _T("tw:retour_ligne_manuel"));
+ $img_br_manuel = http_img_pack(
+ 'br-manuel' . aide_lang_dir($spip_lang, $spip_lang_rtl) . '-10.png',
+ '',
+ "class='br-manuel'",
+ _T('tw:retour_ligne_manuel')
+ );
+ $img_br_manuel = inserer_attribut($img_br_manuel, 'aria-label', _T('tw:retour_ligne_manuel'));
}
if (is_null($img_br_auto)) {
- $img_br_auto = http_img_pack("br-auto" . aide_lang_dir($spip_lang, $spip_lang_rtl) . "-10.png", '',
- "class='br-auto'", _T("tw:retour_ligne_auto"));
- $img_br_auto = inserer_attribut($img_br_auto, 'aria-label', _T("tw:retour_ligne_auto"));
+ $img_br_auto = http_img_pack(
+ 'br-auto' . aide_lang_dir($spip_lang, $spip_lang_rtl) . '-10.png',
+ '',
+ "class='br-auto'",
+ _T('tw:retour_ligne_auto')
+ );
+ $img_br_auto = inserer_attribut($img_br_auto, 'aria-label', _T('tw:retour_ligne_auto'));
}
if (false !== strpos(strtolower($t), '
/UiS", "$img_br_manuel\\0", $t);
@@ -781,7 +800,7 @@ function traiter_raccourcis($t, $show_autobr = false) {
* @return string $t
* Texte transformé
**/
-function propre($t, $connect = null, $env = array()) {
+function propre($t, $connect = null, $env = []) {
// les appels directs a cette fonction depuis le php de l'espace
// prive etant historiquement ecrits sans argment $connect
// on utilise la presence de celui-ci pour distinguer les cas
@@ -805,10 +824,12 @@ function propre($t, $connect = null, $env = array()) {
// https://core.spip.net/issues/3371
// et aussi dans l'espace public si la globale filtrer_javascript = -1
// https://core.spip.net/issues/4166
- if ($interdire_script
+ if (
+ $interdire_script
or $GLOBALS['filtrer_javascript'] == -1
- or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript']<=0)
- or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript']<=0)) {
+ or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0)
+ or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0)
+ ) {
$t = echapper_html_suspect($t, false);
}
$t = echappe_html($t);
diff --git a/inc/textwheel.php b/inc/textwheel.php
index 6d2a8a7..48e4e92 100644
--- a/inc/textwheel.php
+++ b/inc/textwheel.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;
}
@@ -26,21 +26,21 @@ if (!defined('_WHEELS_VERSION')) {
// Definition des principales wheels de SPIP
//
if (!isset($GLOBALS['spip_wheels'])) {
- $GLOBALS['spip_wheels'] = array();
+ $GLOBALS['spip_wheels'] = [];
}
// Si le tableau des raccourcis existe déjà
if (!isset($GLOBALS['spip_wheels']['raccourcis']) or !is_array($GLOBALS['spip_wheels']['raccourcis'])) {
- $GLOBALS['spip_wheels']['raccourcis'] = array(
+ $GLOBALS['spip_wheels']['raccourcis'] = [
'spip/spip',
'spip/spip-paragrapher'
- );
+ ];
} else {
$GLOBALS['spip_wheels']['raccourcis'] = array_merge(
- array(
+ [
'spip/spip',
'spip/spip-paragrapher'
- ),
+ ],
$GLOBALS['spip_wheels']['raccourcis']
);
}
@@ -49,21 +49,21 @@ if (test_espace_prive()) {
$GLOBALS['spip_wheels']['raccourcis'][] = 'spip/ecrire';
}
-$GLOBALS['spip_wheels']['interdire_scripts'] = array(
+$GLOBALS['spip_wheels']['interdire_scripts'] = [
'spip/interdire-scripts'
-);
+];
-$GLOBALS['spip_wheels']['echappe_js'] = array(
+$GLOBALS['spip_wheels']['echappe_js'] = [
'spip/echappe-js'
-);
+];
-$GLOBALS['spip_wheels']['paragrapher'] = array(
+$GLOBALS['spip_wheels']['paragrapher'] = [
'spip/spip-paragrapher'
-);
+];
-$GLOBALS['spip_wheels']['listes'] = array(
+$GLOBALS['spip_wheels']['listes'] = [
'spip/spip-listes'
-);
+];
//
// Methode de chargement d'une wheel SPIP
@@ -91,14 +91,15 @@ class SPIPTextWheelRuleset extends TextWheelRuleSet {
# memoization
# attention : le ruleset peut contenir apres loading des chemins relatifs
# il faut donc que le cache depende du chemin courant vers la racine de SPIP
- $key = "";
+ $key = '';
if ($callback) {
$key = $callback($key);
}
- $key = 'tw-' . md5(_WHEELS_VERSION . "-" . serialize($ruleset) . $key . $class . _DIR_RACINE);
+ $key = 'tw-' . md5(_WHEELS_VERSION . '-' . serialize($ruleset) . $key . $class . _DIR_RACINE);
# lecture du cache
- if ((!defined('_VAR_MODE') or _VAR_MODE != 'recalcul')
+ if (
+ (!defined('_VAR_MODE') or _VAR_MODE != 'recalcul')
and $cacheruleset = tw_cache_get($key)
) {
return $cacheruleset;
@@ -117,7 +118,7 @@ class SPIPTextWheelRuleset extends TextWheelRuleSet {
function tw_trig_purger($quoi) {
if ($quoi == 'cache') {
- purger_repertoire(_DIR_CACHE . "wheels");
+ purger_repertoire(_DIR_CACHE . 'wheels');
}
return $quoi;
@@ -137,7 +138,7 @@ function tw_cache_get($key) {
return cache_get($key);
}
- return @unserialize(file_get_contents(_DIR_CACHE . "wheels/" . $key . ".txt"));
+ return @unserialize(file_get_contents(_DIR_CACHE . 'wheels/' . $key . '.txt'));
}
/**
@@ -154,7 +155,7 @@ function tw_cache_set($key, $value, $ttl = null) {
if (function_exists('cache_set')) {
return cache_set($key, $value, $ttl);
}
- $dir = sous_repertoire(_DIR_CACHE, "wheels/");
+ $dir = sous_repertoire(_DIR_CACHE, 'wheels/');
- return ecrire_fichier($dir . $key . ".txt", serialize($value));
+ return ecrire_fichier($dir . $key . '.txt', serialize($value));
}
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
new file mode 100644
index 0000000..0ece990
--- /dev/null
+++ b/phpcs.xml.dist
@@ -0,0 +1,15 @@
+
+
+ .
+ vendor/*
+ lang/*
+ tests/*
+
+
+
+
+
+
+
+
+
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
new file mode 100644
index 0000000..8b09df3
--- /dev/null
+++ b/phpstan-baseline.neon
@@ -0,0 +1,442 @@
+parameters:
+ ignoreErrors:
+ -
+ message: "#^Function spip_htmlspecialchars not found\\.$#"
+ count: 2
+ path: engine/textwheel.php
+
+ -
+ message: "#^Method TextWheelDebug\\:\\:timer\\(\\) should return int but return statement is missing\\.$#"
+ count: 1
+ path: engine/textwheel.php
+
+ -
+ message: "#^Function include_spip not found\\.$#"
+ count: 1
+ path: engine/textwheelruleset.php
+
+ -
+ message: "#^Function yaml_decode not found\\.$#"
+ count: 1
+ path: engine/textwheelruleset.php
+
+ -
+ message: "#^Function charger_fonction not found\\.$#"
+ count: 1
+ path: inc/autoliens.php
+
+ -
+ message: "#^Function echappe_html not found\\.$#"
+ count: 1
+ path: inc/autoliens.php
+
+ -
+ message: "#^Function extraire_attribut not found\\.$#"
+ count: 1
+ path: inc/autoliens.php
+
+ -
+ message: "#^Function inserer_attribut not found\\.$#"
+ count: 1
+ path: inc/autoliens.php
+
+ -
+ message: "#^Function _T not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function attribut_html not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function charger_fonction not found\\.$#"
+ count: 8
+ path: inc/lien.php
+
+ -
+ message: "#^Function charset2unicode not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function code_echappement not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function echappe_html not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function email_valide not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function entites_html not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function extraire_attribut not found\\.$#"
+ count: 6
+ path: inc/lien.php
+
+ -
+ message: "#^Function generer_url_entite not found\\.$#"
+ count: 3
+ path: inc/lien.php
+
+ -
+ message: "#^Function html2unicode not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function html5_permis not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function include_spip not found\\.$#"
+ count: 5
+ path: inc/lien.php
+
+ -
+ message: "#^Function inclure_modele not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function objet_test_si_publie not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function pipeline not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function protege_js_modeles not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function quote_amp not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function recuperer_fond not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function sql_fetsel not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function sql_get_select not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function sql_getfetsel not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function sql_quote not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function supprimer_numero not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function supprimer_tags not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function table_objet not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function test_espace_prive not found\\.$#"
+ count: 1
+ path: inc/lien.php
+
+ -
+ message: "#^Function traduire_nom_langue not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function unicode2charset not found\\.$#"
+ count: 2
+ path: inc/lien.php
+
+ -
+ message: "#^Function url_de_base not found\\.$#"
+ count: 5
+ path: inc/lien.php
+
+ -
+ message: "#^Function _T not found\\.$#"
+ count: 1
+ path: inc/notes.php
+
+ -
+ message: "#^Function code_echappement not found\\.$#"
+ count: 2
+ path: inc/notes.php
+
+ -
+ message: "#^Function couper not found\\.$#"
+ count: 1
+ path: inc/notes.php
+
+ -
+ message: "#^Function inc_notes_dist\\(\\) should return array\\|string but return statement is missing\\.$#"
+ count: 1
+ path: inc/notes.php
+
+ -
+ message: "#^Function spip_log not found\\.$#"
+ count: 2
+ path: inc/notes.php
+
+ -
+ message: "#^Function supprimer_tags not found\\.$#"
+ count: 1
+ path: inc/notes.php
+
+ -
+ message: "#^Function include_spip not found\\.$#"
+ count: 1
+ path: inc/ressource-mini.php
+
+ -
+ message: "#^Function PtoBR not found\\.$#"
+ count: 4
+ path: inc/ressource.php
+
+ -
+ message: "#^Function echappe_html not found\\.$#"
+ count: 1
+ path: inc/ressource.php
+
+ -
+ message: "#^Function include_spip not found\\.$#"
+ count: 1
+ path: inc/ressource.php
+
+ -
+ message: "#^Function _T not found\\.$#"
+ count: 6
+ path: inc/texte.php
+
+ -
+ message: "#^Function _request not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function aide_lang_dir not found\\.$#"
+ count: 3
+ path: inc/texte.php
+
+ -
+ message: "#^Function alterner not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function autoriser not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function charger_fonction not found\\.$#"
+ count: 2
+ path: inc/texte.php
+
+ -
+ message: "#^Function corriger_caracteres not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function echappe_html not found\\.$#"
+ count: 2
+ path: inc/texte.php
+
+ -
+ message: "#^Function echappe_retour not found\\.$#"
+ count: 5
+ path: inc/texte.php
+
+ -
+ message: "#^Function echappe_retour_modeles not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function echapper_faux_tags not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function echapper_html_suspect not found\\.$#"
+ count: 2
+ path: inc/texte.php
+
+ -
+ message: "#^Function entites_html not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function erreur_squelette not found\\.$#"
+ count: 5
+ path: inc/texte.php
+
+ -
+ message: "#^Function extraire_idiome not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function extraire_multi not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function html5_permis not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function http_img_pack not found\\.$#"
+ count: 3
+ path: inc/texte.php
+
+ -
+ message: "#^Function include_spip not found\\.$#"
+ count: 4
+ path: inc/texte.php
+
+ -
+ message: "#^Function inserer_attribut not found\\.$#"
+ count: 3
+ path: inc/texte.php
+
+ -
+ message: "#^Function lang_typo not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function pipeline not found\\.$#"
+ count: 6
+ path: inc/texte.php
+
+ -
+ message: "#^Function spip_htmlspecialchars not found\\.$#"
+ count: 1
+ path: inc/texte.php
+
+ -
+ message: "#^Function test_espace_prive not found\\.$#"
+ count: 3
+ path: inc/texte.php
+
+ -
+ message: "#^Function textebrut not found\\.$#"
+ count: 2
+ path: inc/texte.php
+
+ -
+ message: "#^Function cache_get not found\\.$#"
+ count: 1
+ path: inc/textwheel.php
+
+ -
+ message: "#^Function cache_set not found\\.$#"
+ count: 1
+ path: inc/textwheel.php
+
+ -
+ message: "#^Function ecrire_fichier not found\\.$#"
+ count: 1
+ path: inc/textwheel.php
+
+ -
+ message: "#^Function find_in_path not found\\.$#"
+ count: 1
+ path: inc/textwheel.php
+
+ -
+ message: "#^Function include_spip not found\\.$#"
+ count: 1
+ path: inc/textwheel.php
+
+ -
+ message: "#^Function purger_repertoire not found\\.$#"
+ count: 1
+ path: inc/textwheel.php
+
+ -
+ message: "#^Function sous_repertoire not found\\.$#"
+ count: 1
+ path: inc/textwheel.php
+
+ -
+ message: "#^Function test_espace_prive not found\\.$#"
+ count: 1
+ path: inc/textwheel.php
+
+ -
+ message: "#^Function charger_fonction not found\\.$#"
+ count: 1
+ path: wheels/spip/echappe-js.php
+
+ -
+ message: "#^Function charger_fonction not found\\.$#"
+ count: 1
+ path: wheels/spip/spip-listes.php
+
+ -
+ message: "#^Function include_spip not found\\.$#"
+ count: 1
+ path: wheels/spip/spip-tableaux.php
+
+ -
+ message: "#^Function attribut_html not found\\.$#"
+ count: 1
+ path: wheels/spip/spip.php
+
+ -
+ message: "#^Function definir_puce not found\\.$#"
+ count: 1
+ path: wheels/spip/spip.php
+
+ -
+ message: "#^Function include_spip not found\\.$#"
+ count: 2
+ path: wheels/spip/spip.php
+
+ -
+ message: "#^Function traiter_math not found\\.$#"
+ count: 1
+ path: wheels/spip/spip.php
+
diff --git a/phpstan.neon.dist b/phpstan.neon.dist
new file mode 100644
index 0000000..7a3513c
--- /dev/null
+++ b/phpstan.neon.dist
@@ -0,0 +1,12 @@
+includes:
+ - phpstan-baseline.neon
+
+parameters:
+ paths:
+ - .
+ excludePaths:
+ analyseAndScan:
+ - vendor
+ - lang
+ - tests
+ level: 0
diff --git a/typographie/en.php b/typographie/en.php
index ac05523..9d474ba 100644
--- a/typographie/en.php
+++ b/typographie/en.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;
}
@@ -20,10 +20,10 @@ function typographie_en($t) {
static $trans;
if (!isset($trans)) {
- $trans = array(
- " " => '~',
+ $trans = [
+ ' ' => '~',
"'" => '’'
- );
+ ];
$charset = isset($GLOBALS['meta']['charset']) ? $GLOBALS['meta']['charset'] : '';
switch ($charset) {
case 'utf-8':
@@ -52,12 +52,12 @@ function typographie_en($t) {
}
if (strpos($t, '~') !== false) {
- $t = preg_replace("/ *~+ */S", "~", $t);
+ $t = preg_replace('/ *~+ */S', '~', $t);
}
- $t = preg_replace("/--([^-]|$)/S", "$pro—$1", $t, -1, $c);
+ $t = preg_replace('/--([^-]|$)/S', "$pro—$1", $t, -1, $c);
if ($c) {
- $t = preg_replace("/([-\n])$pro—/S", "$1--", $t);
+ $t = preg_replace("/([-\n])$pro—/S", '$1--', $t);
$t = str_replace($pro, '', $t);
}
diff --git a/typographie/fr.php b/typographie/fr.php
index 62b0bc7..2f7afbf 100644
--- a/typographie/fr.php
+++ b/typographie/fr.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,15 +21,15 @@ function typographie_fr($t) {
static $trans;
if (!isset($trans)) {
- $trans = array(
- " " => '~',
- "»" => '»',
- "«" => '«',
- "”" => '”',
- "“" => '“',
- "°" => '°',
+ $trans = [
+ ' ' => '~',
+ '»' => '»',
+ '«' => '«',
+ '”' => '”',
+ '“' => '“',
+ '°' => '°',
"'" => '’'
- );
+ ];
$charset = isset($GLOBALS['meta']['charset']) ? $GLOBALS['meta']['charset'] : '';
switch ($charset) {
case 'utf-8':
@@ -81,12 +81,12 @@ function typographie_fr($t) {
}
if (strpos($t, '~') !== false) {
- $t = preg_replace("/ *~+ */S", "~", $t);
+ $t = preg_replace('/ *~+ */S', '~', $t);
}
- $t = preg_replace("/--([^-]|$)/S", "$pro—$1", $t, -1, $c);
+ $t = preg_replace('/--([^-]|$)/S', "$pro—$1", $t, -1, $c);
if ($c) {
- $t = preg_replace("/([-\n])$pro—/S", "$1--", $t);
+ $t = preg_replace("/([-\n])$pro—/S", '$1--', $t);
$t = str_replace($pro, '', $t);
}
diff --git a/wheels/spip/echappe-js.php b/wheels/spip/echappe-js.php
index 06b5e7f..3bb6009 100644
--- a/wheels/spip/echappe-js.php
+++ b/wheels/spip/echappe-js.php
@@ -14,17 +14,19 @@ function echappe_anti_xss($match) {
static $safehtml;
if (!is_array($match) or !strlen($match[0])) {
- return "";
+ return '';
}
$texte = &$match[0];
// on echappe les urls data: javascript: et tout ce qui ressemble
- if (strpos($texte, ":") !== false
- and preg_match(",(data|script)\s*:,iS", $texte)
+ if (
+ strpos($texte, ':') !== false
+ and preg_match(',(data|script)\s*:,iS', $texte)
) {
$texte = nl2br(htmlspecialchars($texte));
} // on echappe si on a possiblement un attribut onxxx et que ca passe pas dans safehtml
- elseif (stripos($texte, "on") !== false
+ elseif (
+ stripos($texte, 'on') !== false
and preg_match(",\bon\w+\s*=,i", $texte)
) {
if (!isset($safehtml)) {
@@ -35,7 +37,7 @@ function echappe_anti_xss($match) {
}
}
- if (strpos($texte, "<") === false) {
+ if (strpos($texte, '<') === false) {
$texte = "$texte
";
}
diff --git a/wheels/spip/spip-listes.php b/wheels/spip/spip-listes.php
index ad61095..2524d26 100644
--- a/wheels/spip/spip-listes.php
+++ b/wheels/spip/spip-listes.php
@@ -25,8 +25,8 @@ function tw_liste_item($t, $quoi = 'item') {
switch ($quoi) {
case 'init':
$niveau = 0;
- $pile_li = array();
- $pile_type = array();
+ $pile_li = [];
+ $pile_type = [];
$type = '';
break;
case 'close':
@@ -86,7 +86,7 @@ function tw_liste_item($t, $quoi = 'item') {
$ajout .= "\n\n";
} elseif (!isset($pile_li[$niveau])) {
$ajout .= "";
- $pile_li[$niveau] = "";
+ $pile_li[$niveau] = '';
}
$niveau++;
$ajout .= "<$type$class_spip_plus>";
@@ -94,7 +94,7 @@ function tw_liste_item($t, $quoi = 'item') {
}
$ajout .= "";
- $pile_li[$profond] = "";
+ $pile_li[$profond] = '';
} else {
$ajout = $t[1]; // puce normale ou
}
diff --git a/wheels/spip/spip-paragrapher.php b/wheels/spip/spip-paragrapher.php
index 6c2f4be..2660939 100644
--- a/wheels/spip/spip-paragrapher.php
+++ b/wheels/spip/spip-paragrapher.php
@@ -11,8 +11,9 @@ if (!defined('_ECRIRE_INC_VERSION')) {
}
if (!defined('_BALISES_BLOCS')) {
- define('_BALISES_BLOCS',
- 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
+ define(
+ '_BALISES_BLOCS',
+ 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style'
);
}
@@ -26,8 +27,8 @@ if (!defined('_BALISES_BLOCS')) {
function detecter_liens_blocs($t) {
// si une balise bloc est dans le liens, on y a aussi ajoute un , il suffit donc de detecter ce dernier
- if (strpos($t[2], "
") !== false) {
- return "" . $t[1] . "" . $t[2] . "
" . $t[3] . "\n";
+ if (strpos($t[2], '
') !== false) {
+ return '' . $t[1] . '' . $t[2] . '
' . $t[3] . "\n";
}
return $t[0];
@@ -45,19 +46,26 @@ function fermer_para_mano($t) {
# match: ",
\n<$2$3"
- foreach (array('
"
\n", ' "") as $cut => $close) {
+ foreach ([' "
\n", ' ''] as $cut => $close) {
if (strpos($t, $cut) !== false) {
foreach (explode($cut, $t) as $c => $p) {
if ($c == 0) {
$t = $p;
} else {
$pi = strtolower($p);
- if (preg_match(
- ",?(?:stop p|" . _BALISES_BLOCS . ")\b,S",
- $pi, $r)) {
+ if (
+ preg_match(
+ ',?(?:stop p|' . _BALISES_BLOCS . ")\b,S",
+ $pi,
+ $r
+ )
+ ) {
$pos = strpos($pi, $r[0]);
- $t .= $cut . str_replace("\n", _AUTOBR . "\n",
- ($close ? rtrim(substr($p, 0, $pos)) : substr($p, 0, $pos))) . $close . substr($p, $pos);
+ $t .= $cut . str_replace(
+ "\n",
+ _AUTOBR . "\n",
+ ($close ? rtrim(substr($p, 0, $pos)) : substr($p, 0, $pos))
+ ) . $close . substr($p, $pos);
} else {
$t .= $cut . $p;
}
@@ -66,14 +74,14 @@ function fermer_para_mano($t) {
}
}
- if (strpos($t, "") !== false) {
- $t = str_replace("", "", $t); // pour respecter les non-retour lignes avant
- $t = str_replace("", "", $t); // pour respecter les non-retour lignes avant
- $t = str_replace("", "\n", $t);
+ if (strpos($t, '') !== false) {
+ $t = str_replace('', '', $t); // pour respecter les non-retour lignes avant
+ $t = str_replace('', '', $t); // pour respecter les non-retour lignes avant
+ $t = str_replace('', "\n", $t);
}
if (_AUTOBR) {
- $t = str_replace(_AUTOBR . "\n" . "
]*>\s*)' . preg_quote(_AUTOBR . "\n", ',') . ",iS";
+ $t = str_replace(_AUTOBR . "\n" . '
]*>\s*)' . preg_quote(_AUTOBR . "\n", ',') . ',iS';
$t = preg_replace($reg, '\1' . "\n", $t);
}
diff --git a/wheels/spip/spip.php b/wheels/spip/spip.php
index fb7c984..dc2b8c4 100644
--- a/wheels/spip/spip.php
+++ b/wheels/spip/spip.php
@@ -36,7 +36,7 @@ function replace_math($t) {
* Code HTML d'une puce
*/
function replace_puce() {
- $puce = "\n
" . definir_puce() . " ";
+ $puce = "\n
" . definir_puce() . ' ';
return $puce;
}
@@ -55,7 +55,7 @@ function replace_puce() {
*/
function inserer_abbr($m) {
$title = attribut_html($m[2]);
- $lang = (isset($m[3]) ? " lang=\"" . $m[3] . "\"" : "");
+ $lang = (isset($m[3]) ? ' lang="' . $m[3] . '"' : '');
- return "" . $m[1] . "";
+ return "" . $m[1] . '';
}