style: un passage de phpcbf

v2
Maïeul 2 months ago
parent 7251344d3a
commit d942597d0a

@ -1,12 +1,15 @@
<?php
/**
* Plugin Ortho-Typographie
* (c) 2013 cedric
* Licence GNU/GPL
*/
if (!defined('_ECRIRE_INC_VERSION')) return;
include_spip("inc/config");
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
include_spip('inc/config');
/**
* Ajouter la CSS des guillemets si active
@ -14,9 +17,10 @@ include_spip("inc/config");
* @return string
*/
function orthotypo_insert_head_css($flux) {
$config = lire_config("orthotypo/");
if (!isset($config['guillemets']) OR $config['guillemets'])
$flux .= '<link rel="stylesheet" type="text/css" href="'.find_in_path('css/typo_guillemets.css').'" media="all" />'."\n";
$config = lire_config('orthotypo/');
if (!isset($config['guillemets']) or $config['guillemets']) {
$flux .= '<link rel="stylesheet" type="text/css" href="' . find_in_path('css/typo_guillemets.css') . '" media="all" />' . "\n";
}
return $flux;
}
@ -25,22 +29,28 @@ function orthotypo_insert_head_css($flux) {
* @param $texte
* @return mixed|string
*/
function orthotypo_post_typo($texte){
function orthotypo_post_typo($texte) {
static $config;
if (is_null($config))
$config = lire_config("orthotypo/");
if (!isset($config['guillemets']) OR $config['guillemets'])
if (is_null($config)) {
$config = lire_config('orthotypo/');
}
if (!isset($config['guillemets']) or $config['guillemets']) {
$texte = orthotypo_guillemets_post_typo($texte);
}
// mois avant les exposants car on y match des "1er mars"
if (!isset($config['mois']) OR $config['mois'])
if (!isset($config['mois']) or $config['mois']) {
$texte = orthotypo_mois_post_typo($texte);
}
// a optimiser : represente +60% du temps de calcul total des 4 fonctions
if (!isset($config['exposants']) OR $config['exposants'])
if (!isset($config['exposants']) or $config['exposants']) {
$texte = orthotypo_exposants_post_typo($texte);
if (!isset($config['caps']) OR $config['caps'])
}
if (!isset($config['caps']) or $config['caps']) {
$texte = orthotypo_caps_post_typo($texte);
if (!isset($config['fines']) OR $config['fines'])
}
if (!isset($config['fines']) or $config['fines']) {
$texte = orthotypo_espaces_fines_post_typo($texte);
}
return $texte;
}
@ -48,13 +58,15 @@ function orthotypo_post_typo($texte){
// Fonctions de traitement sur #TEXTE
function orthotypo_pre_propre($texte) {
static $config;
if (is_null($config))
$config = lire_config("orthotypo/");
if (isset($config['corrections'])
AND $config['corrections']
AND isset($config['corrections_regles'])
AND $config['corrections_regles']
){
if (is_null($config)) {
$config = lire_config('orthotypo/');
}
if (
isset($config['corrections'])
and $config['corrections']
and isset($config['corrections_regles'])
and $config['corrections_regles']
) {
$texte = orthotypo_corrections_pre_propre($texte);
}
@ -78,34 +90,40 @@ function orthotypo_pre_propre($texte) {
* arguments supplementaires a passer au filtre
* @return string
*/
function orthotypo_filtre_texte_echappe($texte, $filtre, $balises='', $args=NULL){
if(!strlen($texte)) return '';
function orthotypo_filtre_texte_echappe($texte, $filtre, $balises = '', $args = null) {
if (!strlen($texte)) { return '';
}
if ($filtre!==false){
$fonction = chercher_filtre($filtre,false);
if ($filtre !== false) {
$fonction = chercher_filtre($filtre, false);
if (!$fonction) {
spip_log("orthotypo_filtre_texte_echappe() : $filtre() non definie",_LOG_ERREUR);
spip_log("orthotypo_filtre_texte_echappe() : $filtre() non definie", _LOG_ERREUR);
return $texte;
}
$filtre = $fonction;
}
// protection du texte
if($balises!==false) {
if(!strlen($balises)) $balises = _PROTEGE_BLOCS;//'html|code|cadre|frame|script';
else $balises = ',<('.$balises.')(\s[^>]*)?>(.*)</\1>,UimsS';
if (!function_exists('echappe_html'))
if ($balises !== false) {
if (!strlen($balises)) { $balises = _PROTEGE_BLOCS;//'html|code|cadre|frame|script';
} else { $balises = ',<(' . $balises . ')(\s[^>]*)?>(.*)</\1>,UimsS';
}
if (!function_exists('echappe_html')) {
include_spip('inc/texte_mini');
}
$texte = echappe_html($texte, 'FILTRETEXTECHAPPE', true, $balises);
}
// retour du texte simplement protege
if ($filtre===false) return $texte;
if ($filtre === false) { return $texte;
}
// transformation par $fonction : on split le texte pour ne pas filtrer les <balises ...> ou </balises> html elle meme
if (strpos($texte, "<") !== false
and $parts = preg_split(",(</?\w+>|<\w+\s[^>]*>),Uims",$texte, -1, PREG_SPLIT_DELIM_CAPTURE)) {
for ($i=0;$i<count($parts);$i+=2) {
if ($parts[$i] !== "") {
if (
strpos($texte, '<') !== false
and $parts = preg_split(',(</?\w+>|<\w+\s[^>]*>),Uims', $texte, -1, PREG_SPLIT_DELIM_CAPTURE)
) {
for ($i = 0; $i < count($parts); $i += 2) {
if ($parts[$i] !== '') {
if (!$args) {
$parts[$i] = $filtre($parts[$i]);
}
@ -119,11 +137,11 @@ function orthotypo_filtre_texte_echappe($texte, $filtre, $balises='', $args=NULL
$texte = implode($parts);
}
else {
if (!$args){
if (!$args) {
$texte = $filtre($texte);
}
else {
array_unshift($args,$texte);
array_unshift($args, $texte);
$texte = call_user_func_array($filtre, $args);
}
}
@ -133,9 +151,9 @@ function orthotypo_filtre_texte_echappe($texte, $filtre, $balises='', $args=NULL
return echappe_retour($texte, 'FILTRETEXTECHAPPE');
}
function orthotypo_echappe_balises_html($texte){
function orthotypo_echappe_balises_html($texte) {
// prudence : on protege le contenu de toute balise html
if (strpos($texte, '<')!==false){
if (strpos($texte, '<') !== false) {
// tout
#$texte = preg_replace_callback(',<[^>]*>,UmsS', 'orthotypo_echappe_balise_html', $texte);
// dangereux uniquement
@ -145,8 +163,9 @@ function orthotypo_echappe_balises_html($texte){
}
function orthotypo_echappe_balise_html($m) {
if (strpos($m[0],'class="base64')!==false) return $m[0];
return code_echappement($m[0], 'FILTRETEXTECHAPPE',true,'span');
if (strpos($m[0], 'class="base64') !== false) { return $m[0];
}
return code_echappement($m[0], 'FILTRETEXTECHAPPE', true, 'span');
}
@ -225,32 +244,35 @@ define('_GUILLEMETS_tr', '&#171;$1&#187;');
define('_GUILLEMETS_zh', '&#12300;$1&#12301;'); // ou "&ldquo;$1&rdquo;" en chinois simplifie
function orthotypo_guillemets_echappe_balises_callback($matches) {
if (strpos($matches[1],'class="base64')===false)
$matches[1] = code_echappement($matches[1], 'GUILL',true,'span');
return str_replace('"',"'",$matches[1]);
if (strpos($matches[1], 'class="base64') === false) {
$matches[1] = code_echappement($matches[1], 'GUILL', true, 'span');
}
return str_replace('"', "'", $matches[1]);
}
function orthotypo_guillemets_rempl($texte){
function orthotypo_guillemets_rempl($texte) {
// on s'en va si pas de guillemets...
if (strpos($texte, '"')===false) return $texte;
if (strpos($texte, '"') === false) { return $texte;
}
// prudence : on protege TOUTES les balises contenant des doubles guillemets droits
if (strpos($texte, '<')!==false){
if (strpos($texte, '<') !== false) {
$texte = preg_replace_callback('/(<[^>]+"[^>]*>)/Ums', 'orthotypo_guillemets_echappe_balises_callback', $texte);
}
// si le texte ne contient pas de guillemets droits
// ou s'il contient deja des guillemets élaborés
// on ne touche pas
if (strpos($texte, '"')!==false
AND (strpos($texte, '&#171;') === false)
AND (strpos($texte, '&#187;') === false)
AND (strpos($texte, '&#8220;') === false)
AND (strpos($texte, '&#8221;') === false)
){
if (
strpos($texte, '"') !== false
and (strpos($texte, '&#171;') === false)
and (strpos($texte, '&#187;') === false)
and (strpos($texte, '&#8220;') === false)
and (strpos($texte, '&#8221;') === false)
) {
// choix de la langue, de la constante et de la chaine de remplacement
$lang = isset($GLOBALS['lang_objet'])?$GLOBALS['lang_objet']:$GLOBALS['spip_lang'];
$constante = '_GUILLEMETS_'.$lang;
$guilles = defined($constante)?constant($constante):_GUILLEMETS_defaut;
$lang = isset($GLOBALS['lang_objet']) ? $GLOBALS['lang_objet'] : $GLOBALS['spip_lang'];
$constante = '_GUILLEMETS_' . $lang;
$guilles = defined($constante) ? constant($constante) : _GUILLEMETS_defaut;
// Remplacement des autres paires de guillemets (et suppression des espaces apres/avant)
// Et retour des balises contenant des doubles guillemets droits
@ -261,17 +283,19 @@ function orthotypo_guillemets_rempl($texte){
return $texte;
}
function orthotypo_guillemets_post_typo($texte){
if (strpos($texte, '"')!==false)
$texte = orthotypo_filtre_texte_echappe($texte,'orthotypo_guillemets_rempl','html|code|cadre|frame|script|acronym|cite');
function orthotypo_guillemets_post_typo($texte) {
if (strpos($texte, '"') !== false) {
$texte = orthotypo_filtre_texte_echappe($texte, 'orthotypo_guillemets_rempl', 'html|code|cadre|frame|script|acronym|cite');
}
return $texte;
}
function orthotypo_espaces_fines_post_typo($t='') {
function orthotypo_espaces_fines_post_typo($t = '') {
$nbsp = "\xc2\xa0";
$fine = '<small class="fine d-inline">'.$nbsp.'</small>';
$fine = '<small class="fine d-inline">' . $nbsp . '</small>';
$t = str_replace(array(
$t = str_replace(
[
'&nbsp;&#187;',
'&#171;&nbsp;',
'&nbsp;?',
@ -279,8 +303,8 @@ function orthotypo_espaces_fines_post_typo($t='') {
'&nbsp;!',
'&nbsp;%',
'&nbsp;',
),
array(
],
[
"$fine\xc2\xbb",
"\xc2\xab$fine",
"$fine?",
@ -288,12 +312,13 @@ function orthotypo_espaces_fines_post_typo($t='') {
"$fine!",
"$fine%",
$nbsp,
),
$t);
],
$t
);
// CKEditor double les fines chaque fois que l'on passe en mode source puis retour
while (strpos($t, $fine.$fine) !== false) {
$t = str_replace($fine.$fine, $fine, $t);
while (strpos($t, $fine . $fine) !== false) {
$t = str_replace($fine . $fine, $fine, $t);
}
return $t;
@ -314,67 +339,75 @@ function orthotypo_espaces_fines_post_typo($t='') {
// exemple : https://zone.spip.org/trac/spip-zone/wiki/WikiFormatting
include_spip('inc/charsets');
if (!defined('_TYPO_class')) define('_TYPO_class', '<sup class="typo_exposants">');
if (!defined('_TYPO_sup')) define('_TYPO_sup', _TYPO_class.'\\1</sup>');
if (!defined('_TYPO_sup2')) define('_TYPO_sup2', '\\1'._TYPO_class.'\\2</sup>');
if (!defined('_TYPO_class')) {
define('_TYPO_class', '<sup class="typo_exposants">');
}
if (!defined('_TYPO_sup')) {
define('_TYPO_sup', _TYPO_class . '\\1</sup>');
}
if (!defined('_TYPO_sup2')) {
define('_TYPO_sup2', '\\1' . _TYPO_class . '\\2</sup>');
}
// cette fonction ne fonctionne que pour l'anglais
// elle n'est pas appelee dans les balises html : html|code|cadre|frame|script|acronym|cite
function orthotypo_exposants_en($texte){
function orthotypo_exposants_en($texte) {
static $typo;
if(!$typo) {
$typo = array( array(
if (!$typo) {
$typo = [ [
',(?<=1)(st)\b,',
',(?<=2)(nd)\b,',
',(?<=3)(rd)\b,',
',(?<=\d)(th)\b,',
',(?<=m)([23])\b,', // m² m³
), array(
], [
_TYPO_sup, _TYPO_sup, _TYPO_sup, _TYPO_sup, _TYPO_sup,
));
]];
}
return preg_replace($typo[0], $typo[1], $texte);
}
// cette fonction ne fonctionne que pour le francais
// elle n'est pas appelee dans les balises html : html|code|cadre|frame|script|acronym|cite
function orthotypo_exposants_fr($texte){
function orthotypo_exposants_fr($texte) {
static $typo = null;
static $egrave; static $eaigu1; static $eaigu2; static $accents;
static $egrave;
static $eaigu1;
static $eaigu2;
static $accents;
if (is_null($typo)) {
$u = isset($GLOBALS['meta']['charset']) ? ($GLOBALS['meta']['charset']=="utf-8"?"u":"") : '';
$u = isset($GLOBALS['meta']['charset']) ? ($GLOBALS['meta']['charset'] == 'utf-8' ? 'u' : '') : '';
// en principe, pas besoin de : caractere_utf_8(232)
$carre = unicode2charset('&#178;').'|&#178;|&sup2;';
$egrave = unicode2charset('&#232;').'|&#232;|&egrave;';
$eaigu1 = unicode2charset('&#233;').'|&#233;|&eacute;';
$eaigu2 = unicode2charset('&#201;').'|&#201;|&Eacute;';
$carre = unicode2charset('&#178;') . '|&#178;|&sup2;';
$egrave = unicode2charset('&#232;') . '|&#232;|&egrave;';
$eaigu1 = unicode2charset('&#233;') . '|&#233;|&eacute;';
$eaigu2 = unicode2charset('&#201;') . '|&#201;|&Eacute;';
$accents = unicode2charset('&#224;&#225;&#226;&#228;&#229;&#230;&#232;&#233;&#234;&#235;&#236;&#237;&#238;&#239;&#242;&#243;&#244;&#246;&#249;&#250;&#251;&#252;');
$typo = array(
$typo = [
// Mlle(s), Mme(s)
// Mme(s) et Mgr
'/\bM(gr|mes?)\b/u' => 'M'._TYPO_sup,
'/\bM(lles?)\b/u' => 'M'._TYPO_sup,
'/\bM(gr|mes?)\b/u' => 'M' . _TYPO_sup,
'/\bM(lles?)\b/u' => 'M' . _TYPO_sup,
// Dr, Pr suivis d'un espace d'un point ou d'un tiret
'/\b([DP])(r)(?=[\s\.-])/u' => _TYPO_sup2,
// m2
"/\bm(?:$carre)\b/" => 'm'._TYPO_class.'2</sup>',
"/\bm(?:$carre)\b/" => 'm' . _TYPO_class . '2</sup>',
// m2, m3
'/\bm([23])\b/u' => 'm'._TYPO_sup,
'/\bm([23])\b/u' => 'm' . _TYPO_sup,
// millions, milliards
'/\b([\s\d][Mm])([nd]s?)\b/u' => _TYPO_sup2,
// Vve
'/\bV(ve)\b/' => 'V'._TYPO_sup,
'/\bV(ve)\b/' => 'V' . _TYPO_sup,
// Cie(s)
'/\bC(ies?)\b/u' => 'C'._TYPO_sup,
'/\bC(ies?)\b/u' => 'C' . _TYPO_sup,
// Societes(s), Etablissements
"/\bS(t(?:$eaigu1)s?)(?=\W)/$u" => 'S'._TYPO_sup,
"/(?<=\W)(?:E|$eaigu2)ts\b/$u" => '&#201;'._TYPO_class.'ts</sup>',
"/\bS(t(?:$eaigu1)s?)(?=\W)/$u" => 'S' . _TYPO_sup,
"/(?<=\W)(?:E|$eaigu2)ts\b/$u" => '&#201;' . _TYPO_class . 'ts</sup>',
// 1er(s), Erreurs 1ier(s), 1ier(s)
'/(?<=\b[1I])i?(ers?)\b/u' => _TYPO_sup,
@ -383,32 +416,31 @@ function orthotypo_exposants_fr($texte){
'/(?<=\b2)n?(de?s?)\b/u' => _TYPO_sup, // 2nd(e)(s)
// Erreurs (i)(e)me(s) + accents
"/(\b[0-9IVX]+)i?(?:e|$egrave)?me(s?)\b/$u" => '$1'._TYPO_class.'e$2</sup>',
"/(\b[0-9IVX]+)i?(?:e|$egrave)?me(s?)\b/$u" => '$1' . _TYPO_class . 'e$2</sup>',
// 2e(s), IIIe(s)... (les 1(e?r?s?) ont deja ete remplaces)
'/\b([0-9IVX]+)(es?)\b/u' => _TYPO_sup2,
// recto, verso, primo, secondo, etc.
"/(?<![;$accents])\b(\d+|r|v)o\b/$u" => '$1'._TYPO_class.'o</sup>',
"/(?<![;$accents])\b(\d+|r|v)o\b/$u" => '$1' . _TYPO_class . 'o</sup>',
// Maitre (suivi d'un espace et d'une majuscule)
'/\bM(e)(?= [A-Z])/u' => 'M'._TYPO_sup,
);
$typo = array(array_keys($typo),array_values($typo));
'/\bM(e)(?= [A-Z])/u' => 'M' . _TYPO_sup,
];
$typo = [array_keys($typo),array_values($typo)];
}
return preg_replace($typo[0], $typo[1], $texte);
}
function orthotypo_exposants_echappe_balises_callback($matches) {
return code_echappement($matches[1], 'EXPO',true,'span');
return code_echappement($matches[1], 'EXPO', true, 'span');
}
function orthotypo_exposants_post_typo($texte){
function orthotypo_exposants_post_typo($texte) {
if (!empty($GLOBALS['lang_objet'])) {
$lang = $GLOBALS['lang_objet'];
} else {
$lang = $GLOBALS['spip_lang'];
}
if(function_exists($fonction = 'orthotypo_exposants_'.lang_typo($lang))){
$texte = orthotypo_filtre_texte_echappe($texte,$fonction,'html|code|cadre|frame|script|acronym|cite');
if (function_exists($fonction = 'orthotypo_exposants_' . lang_typo($lang))) {
$texte = orthotypo_filtre_texte_echappe($texte, $fonction, 'html|code|cadre|frame|script|acronym|cite');
return echappe_retour($texte, 'EXPO');
}
return $texte;
@ -423,20 +455,21 @@ function orthotypo_exposants_post_typo($texte){
* - prise en compte de la langue
*/
function orthotypo_mois_rempl($texte){
static $typo = array();
function orthotypo_mois_rempl($texte) {
static $typo = [];
$lang = $GLOBALS['spip_lang'];
if(!isset($typo[$lang])) {
$typo[$lang] = array();
for ($m=1; $m<=12; $m++)
$typo[$lang][] = _T('date_mois_'.$m);
if (!isset($typo[$lang])) {
$typo[$lang] = [];
for ($m = 1; $m <= 12; $m++) {
$typo[$lang][] = _T('date_mois_' . $m);
}
$pre1 = _T('date_jnum1');
$pre2 = _T('date_jnum2');
$pre3 = _T('date_jnum3');
// si on est en _AUTOBR desactive, on accepte un retour ligne entre le chiffre et le mois (mais pas 2=paragraphe)
// sinon on accepte pas de retours lignes du tout
$space = ((defined('_AUTOBR')&&!_AUTOBR)?"(?:[ \t]*(?:\r\n|\r|\n))?[ \t]*":"[ \t]+");
$typo[$lang] = ",([1-3]?[0-9]|$pre1|$pre2|$pre3)$space+(".join('|', $typo[$lang]).')\b,UimsS';
$space = ((defined('_AUTOBR') && !_AUTOBR) ? "(?:[ \t]*(?:\r\n|\r|\n))?[ \t]*" : "[ \t]+");
$typo[$lang] = ",([1-3]?[0-9]|$pre1|$pre2|$pre3)$space+(" . join('|', $typo[$lang]) . ')\b,UimsS';
include_spip('inc/charsets');
$typo[$lang] = unicode2charset(html2unicode($typo[$lang]));
}
@ -444,9 +477,9 @@ function orthotypo_mois_rempl($texte){
return preg_replace($typo[$lang], '\1&nbsp;\2', $texte);
}
function orthotypo_mois_post_typo($texte){
if (strpbrk($texte,"123456789")!==false){
$texte = orthotypo_filtre_texte_echappe($texte,'orthotypo_mois_rempl','html|code|cadre|frame|script|acronym|cite');
function orthotypo_mois_post_typo($texte) {
if (strpbrk($texte, '123456789') !== false) {
$texte = orthotypo_filtre_texte_echappe($texte, 'orthotypo_mois_rempl', 'html|code|cadre|frame|script|acronym|cite');
}
return $texte;
}
@ -468,32 +501,27 @@ function orthotypo_mois_post_typo($texte){
* This is necessary to keep dotted cap strings to pick up extra spaces
* used in preg_replace_callback later on
*/
function orthotypo_caps_replace_callback($matchobj)
{
if ( !empty($matchobj[2]) )
{
return sprintf('<span class="caps">%s</span>', $matchobj[2]);
}
else
{
$mthree = $matchobj[3];
if ( ($mthree[strlen($mthree)-1]) == " " )
{
$caps = substr($mthree, 0, -1);
$tail = ' ';
}
else
{
$caps = $mthree;
$tail = '';
}
return sprintf('<span class="caps">%s</span>%s', $caps, $tail);
}
function orthotypo_caps_replace_callback($matchobj) {
if (!empty($matchobj[2])) {
return sprintf('<span class="caps">%s</span>', $matchobj[2]);
}
else {
$mthree = $matchobj[3];
if (($mthree[strlen($mthree) - 1]) == ' ') {
$caps = substr($mthree, 0, -1);
$tail = ' ';
}
else {
$caps = $mthree;
$tail = '';
}
return sprintf('<span class="caps">%s</span>%s', $caps, $tail);
}
}
function orthotypo_caps_rempl($texte){
function orthotypo_caps_rempl($texte) {
static $cap_finder;
if (is_null($cap_finder)){
if (is_null($cap_finder)) {
$cap_finder = "/(
(\b[A-Z\d]* # Group 2: Any amount of caps and digits
[A-Z]\d*[A-Z] # A cap string must at least include two caps (but they can have digits between them)
@ -506,8 +534,8 @@ function orthotypo_caps_rempl($texte){
return preg_replace_callback($cap_finder, 'orthotypo_caps_replace_callback', $texte);
}
function orthotypo_caps_post_typo($texte){
$texte = orthotypo_filtre_texte_echappe($texte,'orthotypo_caps_rempl','html|code|cadre|frame|script|acronym|cite');
function orthotypo_caps_post_typo($texte) {
$texte = orthotypo_filtre_texte_echappe($texte, 'orthotypo_caps_rempl', 'html|code|cadre|frame|script|acronym|cite');
return $texte;
}
@ -519,50 +547,56 @@ function orthotypo_caps_post_typo($texte){
// cette fonction appelee automatiquement a chaque affichage de la page privee du Couteau Suisse renvoie un tableau
function orthotypo_corrections_regles() {
$str = array();
$preg = array();
$regles = trim(lire_config("orthotypo/corrections_regles"));
if (strlen($regles)){
$str = [];
$preg = [];
$regles = trim(lire_config('orthotypo/corrections_regles'));
if (strlen($regles)) {
$liste = preg_split("/[\r\n]+/", $regles);
foreach ($liste as $l) {
list($a, $b) = explode("=", $l, 2);
$a = trim($a); $b = trim($b);
list($a, $b) = explode('=', $l, 2);
$a = trim($a);
$b = trim($b);
if (!strlen($a) || preg_match('/^(#|\/\/)/', $a)) {
// remarques ou vide
} elseif (preg_match('/^\((.+)\)$/', $a, $reg)) {
// les mots seuls
$preg[0][] = '/\b'.$reg[1].'\b/'; $preg[1][] = $b;
$preg[0][] = '/\b' . $reg[1] . '\b/';
$preg[1][] = $b;
} elseif (preg_match('/^(\/.+\/[imsxuADSUX]*)$/', $a)) {
// expressions regulieres
$preg[0][] = $a; $preg[1][] = $b;
$preg[0][] = $a;
$preg[1][] = $b;
} elseif (strlen($a)) {
// simples remplacements
$str[0][] = $a; $str[1][] = $b;
$str[0][] = $a;
$str[1][] = $b;
}
}
}
return array($str, $preg);
return [$str, $preg];
}
// cette fonction n'est pas appelee dans les balises html : html|code|cadre|frame|script
function orthotypo_corrections_rempl($texte) {
static $str,$preg;
if (is_null($str)){
if (is_null($str)) {
list($str,$preg) = orthotypo_corrections_regles();
}
$texte = orthotypo_echappe_balises_html($texte);
if (count($str))
if (count($str)) {
$texte = str_replace($str[0], $str[1], $texte);
if (count($preg))
}
if (count($preg)) {
$texte = preg_replace($preg[0], $preg[1], $texte);
}
return $texte;
}
// Fonctions de traitement sur #TEXTE
function orthotypo_corrections_pre_propre($texte) {
return orthotypo_filtre_texte_echappe($texte,'orthotypo_corrections_rempl');
}
return orthotypo_filtre_texte_echappe($texte, 'orthotypo_corrections_rempl');
}

@ -4,10 +4,10 @@ if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function orthotypo_ieconfig_metas($table){
function orthotypo_ieconfig_metas($table) {
$table['orthotypo']['titre'] = _T('orthotypo:orthotypo_titre');
$table['orthotypo']['icone'] = 'orthotypo-16.png';
$table['orthotypo']['metas_serialize'] = 'orthotypo';
return $table;
}
}

@ -1,13 +1,16 @@
<?php
/**
* Plugin Ortho-Typographie
* (c) 2013 cedric
* Licence GNU/GPL
*/
if (!defined("_ECRIRE_INC_VERSION")) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
if (!function_exists('inc_lien')){
if (!function_exists('inc_lien')) {
/**
* pour les liens, on transforme les guill francais &laquo; &raquo; des titres en guill de second niveau
*
@ -15,23 +18,25 @@ if (!function_exists('inc_lien')){
*/
function inc_lien() {
static $config;
if (is_null($config))
$config = lire_config("orthotypo/");
if (is_null($config)) {
$config = lire_config('orthotypo/');
}
if (!function_exists('inc_lien_dist')){
if (!function_exists('inc_lien_dist')) {
include_spip('inc/lien');
}
// recuperer le resultat normal
$args = func_get_args();
$typo = call_user_func_array('inc_lien_dist', $args);
if (!isset($config['guillemets']) OR $config['guillemets']){
if (!isset($config['guillemets']) or $config['guillemets']) {
// si on n'avait pas precise de titre, changer les guill du titre auto
if ($args[1] === '' AND strpos($typo,"&#171;")!==false)
if ($args[1] === '' and strpos($typo, '&#171;') !== false) {
$typo = preg_replace(',&#171;(&nbsp;)?(.*?)(&nbsp;)?&#187;,S', '&#8220;\2&#8221;', $typo);
}
}
// et hop
return $typo;
}
}
}

Loading…
Cancel
Save