Plugin unifie de correction ortho-typographique
- regroupe les plugins http://zone.spip.org/trac/spip-zone/browser/_plugins_/typo_exposants http://zone.spip.org/trac/spip-zone/browser/_plugins_/typo_guillemets http://zone.spip.org/trac/spip-zone/browser/_plugins_/typo_mois http://zone.spip.org/trac/spip-zone/browser/_plugins_/typo_caps - inclue egalement une fonciton de correction automatique basee sur des regles perso indiquees par le webmestre, comme dans un traitement de texte (fonction tiree de la lame correction du CS) - Credit des auteurs des differents plugins - Formulaire de config permettant de desactiver les differentes corrections (actives par defaut)svn/root/tags/v1.5.2
commit
ab0cbf7108
@ -0,0 +1,10 @@
|
||||
* text=auto !eol
|
||||
css/typo_guillemets.css -text
|
||||
formulaires/configurer_orthotypo.html -text
|
||||
lang/orthotypo_fr.php -text
|
||||
lang/paquet-orthotypo_fr.php -text
|
||||
/orthotypo_fonctions.php -text
|
||||
/paquet.xml -text
|
||||
prive/squelettes/contenu/configurer_orthotypo.html -text
|
||||
prive/themes/spip/images/orthotypo-32.png -text
|
||||
prive/themes/spip/images/orthotypo.png -text
|
@ -0,0 +1,19 @@
|
||||
/* Specifie des paires de guillemets sur plusieurs niveaux pour chaque langue */
|
||||
/* Cf.: http://www.yoyodesign.org/doc/w3c/css2/generate.html#quotes-specify */
|
||||
q { quotes: '"' '"' "'" "'" }
|
||||
:lang(fr) q { quotes: "\00AB\A0" "\A0\00BB" "\201C" "\201D" "\2018" "\2019"; }
|
||||
:lang(en) q { quotes: "\201C" "\201D" "\2018" "\2019" }
|
||||
:lang(es) q { quotes: "\00AB" "\00BB" "\201C" "\201D"; }
|
||||
:lang(it) q { quotes: "\00AB\A0" "\A0\00BB" "\201C" "\201D"; }
|
||||
:lang(de) q { quotes: "\00BB" "\00AB" ">" "<" }
|
||||
:lang(no) q { quotes: "\00AB\A0" "\A0\00BB" "<" ">" }
|
||||
|
||||
/* Insere des guillemets avant et apres le contenu d'un element Q */
|
||||
q:before { content: open-quote; }
|
||||
q:after { content: close-quote; }
|
||||
|
||||
/* Pour IE, qui n'y comprend rien, on se contente d'italique */
|
||||
* html q { font-style: italic; }
|
||||
*+html q { font-style: italic; }
|
||||
|
||||
/* end */
|
@ -0,0 +1,98 @@
|
||||
<div class="formulaire_spip formulaire_configurer formulaire_#FORM">
|
||||
|
||||
<h3 class="titrem"><:orthotypo:cfg_titre_parametrages:></h3>
|
||||
|
||||
[<p class="reponse_formulaire reponse_formulaire_ok">(#ENV*{message_ok})</p>]
|
||||
[<p class="reponse_formulaire reponse_formulaire_erreur">(#ENV*{message_erreur})</p>]
|
||||
|
||||
<form method="post" action="#ENV{action}">
|
||||
<div>
|
||||
#ACTION_FORMULAIRE{#ENV{action}}
|
||||
#SET{fl,orthotypo}
|
||||
<ul>
|
||||
#SET{name,guillemets}#SET{obli,''}#SET{defaut,'1'}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
|
||||
<li class="editer pleine_largeur editer_[(#GET{name})][ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">[
|
||||
<span class='erreur_message'>(#GET{erreurs})</span>
|
||||
]
|
||||
#SET{val,0}
|
||||
<input type="hidden" name="#GET{name}" value="#GET{val}" />
|
||||
#SET{val,1}
|
||||
<div class="choix">
|
||||
<input type="checkbox" name="#GET{name}" class="checkbox" id="#GET{name}_#GET{val}" value="#GET{val}"[(#ENV{#GET{name},#GET{defaut}}|=={#GET{val}}|oui)checked="checked"] />
|
||||
<label for="#GET{name}_#GET{val}">[(#GET{fl}|concat{':label_',#GET{name},'_',#GET{val}}|_T)]</label>
|
||||
</div>
|
||||
<p class="explication"><:orthotypo:explication_guillemets:></p>
|
||||
</li>
|
||||
#SET{name,exposants}#SET{obli,''}#SET{defaut,'1'}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
|
||||
<li class="editer pleine_largeur editer_[(#GET{name})][ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">[
|
||||
<span class='erreur_message'>(#GET{erreurs})</span>
|
||||
]
|
||||
#SET{val,0}
|
||||
<input type="hidden" name="#GET{name}" value="#GET{val}" />
|
||||
#SET{val,1}
|
||||
<div class="choix">
|
||||
<input type="checkbox" name="#GET{name}" class="checkbox" id="#GET{name}_#GET{val}" value="#GET{val}"[(#ENV{#GET{name},#GET{defaut}}|=={#GET{val}}|oui)checked="checked"] />
|
||||
<label for="#GET{name}_#GET{val}">[(#GET{fl}|concat{':label_',#GET{name},'_',#GET{val}}|_T)]</label>
|
||||
</div>
|
||||
<p class="explication"><:orthotypo:explication_exposants:></p>
|
||||
</li>
|
||||
#SET{name,mois}#SET{obli,''}#SET{defaut,'1'}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
|
||||
<li class="editer pleine_largeur editer_[(#GET{name})][ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">[
|
||||
<span class='erreur_message'>(#GET{erreurs})</span>
|
||||
]
|
||||
#SET{val,0}
|
||||
<input type="hidden" name="#GET{name}" value="#GET{val}" />
|
||||
#SET{val,1}
|
||||
<div class="choix">
|
||||
<input type="checkbox" name="#GET{name}" class="checkbox" id="#GET{name}_#GET{val}" value="#GET{val}"[(#ENV{#GET{name},#GET{defaut}}|=={#GET{val}}|oui)checked="checked"] />
|
||||
<label for="#GET{name}_#GET{val}">[(#GET{fl}|concat{':label_',#GET{name},'_',#GET{val}}|_T)]</label>
|
||||
</div>
|
||||
<p class="explication"><:orthotypo:explication_mois:></p>
|
||||
</li>
|
||||
#SET{name,caps}#SET{obli,''}#SET{defaut,'1'}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
|
||||
<li class="editer pleine_largeur editer_[(#GET{name})][ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">[
|
||||
<span class='erreur_message'>(#GET{erreurs})</span>
|
||||
]
|
||||
#SET{val,0}
|
||||
<input type="hidden" name="#GET{name}" value="#GET{val}" />
|
||||
#SET{val,1}
|
||||
<div class="choix">
|
||||
<input type="checkbox" name="#GET{name}" class="checkbox" id="#GET{name}_#GET{val}" value="#GET{val}"[(#ENV{#GET{name},#GET{defaut}}|=={#GET{val}}|oui)checked="checked"] />
|
||||
<label for="#GET{name}_#GET{val}">[(#GET{fl}|concat{':label_',#GET{name},'_',#GET{val}}|_T)]</label>
|
||||
</div>
|
||||
<p class="explication"><:orthotypo:explication_caps:></p>
|
||||
</li>
|
||||
<li class="fieldset">
|
||||
<fieldset>
|
||||
<legend><:orthotypo:legend_corrections:></legend>
|
||||
<ul>
|
||||
#SET{name,corrections}#SET{obli,''}#SET{defaut,'1'}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
|
||||
<li class="editer pleine_largeur editer_[(#GET{name})][ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">[
|
||||
<span class='erreur_message'>(#GET{erreurs})</span>
|
||||
]
|
||||
#SET{val,0}
|
||||
<input type="hidden" name="#GET{name}" value="#GET{val}" />
|
||||
#SET{val,1}
|
||||
<div class="choix">
|
||||
<input type="checkbox" name="#GET{name}" class="checkbox" id="#GET{name}_#GET{val}" value="#GET{val}"[(#ENV{#GET{name},#GET{defaut}}|=={#GET{val}}|oui)checked="checked"] />
|
||||
<label for="#GET{name}_#GET{val}">[(#GET{fl}|concat{':label_',#GET{name},'_',#GET{val}}|_T)]</label>
|
||||
</div>
|
||||
<p class="explication"><:orthotypo:explication_corrections:></p>
|
||||
</li>
|
||||
#SET{name,corrections_regles}#SET{obli,''}#SET{defaut,''}#SET{erreurs,#ENV**{erreurs}|table_valeur{#GET{name}}}
|
||||
<li class="editer pleine_largeur editer_[(#GET{name})][ (#GET{obli})][ (#GET{erreurs}|oui)erreur]">
|
||||
<label for="#GET{name}">[(#GET{fl}|concat{':label_',#GET{name}}|_T)]</label>[
|
||||
<span class='erreur_message'>(#GET{erreurs})</span>
|
||||
]<textarea name="#GET{name}" class="textarea" rows="10">
|
||||
#ENV*{#GET{name},#GET{defaut}}</textarea>
|
||||
<p class="explication"><:orthotypo:explication_corrections_regles:></p>
|
||||
</li>
|
||||
</ul>
|
||||
</fieldset>
|
||||
</li>
|
||||
</ul>
|
||||
<input type="hidden" name="_meta_casier" value="orthotypo" />
|
||||
<p class="boutons"><span class="image_loading"> </span><input type="submit" class="submit" value="<:bouton_enregistrer:>" /></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// This is a SPIP language file -- Ceci est un fichier langue de SPIP
|
||||
|
||||
if (!defined('_ECRIRE_INC_VERSION')) return;
|
||||
|
||||
$GLOBALS[$GLOBALS['idx_lang']] = array(
|
||||
|
||||
// O
|
||||
'orthotypo_titre' => 'Ortho-Typographie',
|
||||
|
||||
// C
|
||||
'cfg_exemple' => 'Exemple',
|
||||
'cfg_exemple_explication' => 'Explication de cet exemple',
|
||||
'cfg_titre_parametrages' => 'Paramétrages',
|
||||
|
||||
'label_guillemets_1' => 'Correction automatique des guillemets, selon la langue',
|
||||
'explication_guillemets' => 'Remplacer automatiquement les guillemets droits (") par les guillemets typographiques («»“”„) de la langue de composition et guillemette correctement la balise <tt><q></tt>. Les liens automatiques <code>[->1]</code> vers des articles dont le titre contient des «guillemets français» passent en guillemets “de second niveau”. Le remplacement, transparent pour l\'utilisateur, ne modifie pas le texte mais seulement l\'affichage final.',
|
||||
|
||||
'label_exposants_1' => 'Amélioration typographique des abréviations avec exposants',
|
||||
'explication_exposants' => 'Améliorer le rendu typographique d\'abréviations fréquentes par la mise en exposant de leurs éléments et/ou leur correction. Les abréviations obtenues sont conformes à celles de l\'Imprimerie nationale telles qu\'indiquées dans le {Lexique des règles typographiques en usage à l\'Imprimerie nationale} (article « Abréviations », presses de l\'Imprimerie nationale, Paris, 2002).',
|
||||
|
||||
'label_mois_1' => 'Eviter de couper les dates en fin de ligne',
|
||||
'explication_mois' => 'Corriger les dates au format "10 Mars" en remplaçant l\'espace entre le jour et le mois par un espace insécable.',
|
||||
|
||||
'label_caps_1' => 'Styler les mots en lettres capitales',
|
||||
'explication_caps' => 'Encadrer les mots écrits en lettres capitales dans une balise <code><span class="caps"></code>. Par exemple, <code>ONU</code> devient <code><span class="caps">ONU</span></code>. De ce fait, les mots en lettres capitales peuvent être stylés en css',
|
||||
|
||||
'legend_corrections' => 'Corrections automatiques',
|
||||
'label_corrections_1' => 'Activer les corrections automatiques',
|
||||
'explication_corrections' => 'Corriger automatiquement le texte selon les règles ci-dessous.',
|
||||
'label_corrections_regles' => 'Règles de correction',
|
||||
'explication_corrections_regles' => 'Indiquez une règle par ligne sous la forme <br/><code>mot = remplacement</code><br/> pour un simple remplacement, ou <br/><code>/m[ao]t/ = m$1t</code><br/> pour un remplacement par expression régulière',
|
||||
|
||||
// T
|
||||
'titre_page_configurer_orthotypo' => 'Typographie et remplacements',
|
||||
);
|
||||
|
||||
?>
|
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// This is a SPIP language file -- Ceci est un fichier langue de SPIP
|
||||
|
||||
if (!defined('_ECRIRE_INC_VERSION')) return;
|
||||
|
||||
$GLOBALS[$GLOBALS['idx_lang']] = array(
|
||||
|
||||
// O
|
||||
'orthotypo_description' => 'Typographe des guillemets, exposants, mois, majuscules.
|
||||
Remplacement automatique configurable.',
|
||||
'orthotypo_nom' => 'Ortho-Typographie',
|
||||
'orthotypo_slogan' => 'Typographie améliorée et remplacements automatiques.',
|
||||
);
|
||||
|
||||
?>
|
@ -0,0 +1,477 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Ortho-Typographie
|
||||
* (c) 2013 cedric
|
||||
* Licence GNU/GPL
|
||||
*/
|
||||
|
||||
if (!defined('_ECRIRE_INC_VERSION')) return;
|
||||
include_spip("inc/config");
|
||||
|
||||
/**
|
||||
* Ajouter la CSS des guillemets si active
|
||||
* @param $flux
|
||||
* @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";
|
||||
return $flux;
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-typo : corrections selon les fonctions activees
|
||||
* @param $texte
|
||||
* @return mixed|string
|
||||
*/
|
||||
function orthotypo_post_typo($texte){
|
||||
static $config;
|
||||
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'])
|
||||
$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'])
|
||||
$texte = orthotypo_exposants_post_typo($texte);
|
||||
if (!isset($config['caps']) OR $config['caps'])
|
||||
$texte = orthotypo_caps_post_typo($texte);
|
||||
|
||||
return $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']
|
||||
){
|
||||
$texte = orthotypo_corrections_pre_propre($texte);
|
||||
}
|
||||
|
||||
return $texte;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* evite les transformations typo dans les balises $balises
|
||||
* par exemple pour <html>, <cadre>, <code>, <frame>, <script>, <acronym> et <cite>, $balises = 'html|code|cadre|frame|script|acronym|cite'
|
||||
*
|
||||
* @param $balises
|
||||
* balises concernees par l'echappement
|
||||
* si $balises = '' alors la protection par defaut est : html|code|cadre|frame|script
|
||||
* si $balises = false alors le texte est utilise tel quel
|
||||
* @param $fonction
|
||||
* la fonction prevue pour transformer $texte
|
||||
* si $fonction = false, alors le texte est retourne simplement protege
|
||||
* @param $texte
|
||||
* $texte a filtree
|
||||
* @param null $arg
|
||||
* @return string
|
||||
*/
|
||||
function orthotypo_echappe_balises($balises, $fonction, $texte, $arg=NULL){
|
||||
if(!strlen($texte)) return '';
|
||||
if (($fonction!==false) && !function_exists($fonction)) {
|
||||
spip_log("orthotypo_echappe_balises() : $fonction() non definie","orthotypo"._LOG_ERREUR);
|
||||
return $texte;
|
||||
}
|
||||
|
||||
// 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'))
|
||||
include_spip('inc/texte_mini');
|
||||
$texte = echappe_html($texte, 'ORTHOTYPO', true, $balises);
|
||||
}
|
||||
// retour du texte simplement protege
|
||||
if ($fonction===false) return $texte;
|
||||
// transformation par $fonction
|
||||
$texte = (is_null($arg)?$fonction($texte):$fonction($texte, $arg));
|
||||
|
||||
// deprotection en abime, notamment des modeles...
|
||||
return echappe_retour($texte, 'ORTHOTYPO');
|
||||
}
|
||||
|
||||
|
||||
/* *********************************************************************************************************************
|
||||
* Guillemets
|
||||
* merge de
|
||||
* - http://zone.spip.org/trac/spip-zone/browser/_plugins_/typo_guillemets/typo_guillemets_fonctions.php?rev=54676
|
||||
* - http://zone.spip.org/trac/spip-zone/browser/_plugins_/couteau_suisse/outils/guillemets.php?rev=64721
|
||||
*/
|
||||
|
||||
/*
|
||||
Fichier de formatage typographique des guillemets, par Vincent Ramos
|
||||
<www-lansargues AD kailaasa POINT net>, sous licence GNU/GPL.
|
||||
|
||||
Ne sont touchees que les paires de guillemets.
|
||||
|
||||
Le formatage des guillemets est tire de
|
||||
<http://en.wikipedia.org/wiki/Quotation_mark%2C_non-English_usage>
|
||||
Certains des usages indiques ne correspondent pas a ceux que la
|
||||
barre d'insertion de caracteres speciaux de SPIP propose.
|
||||
|
||||
Les variables suivies du commentaire LRTEUIN sont confirmees par le
|
||||
_Lexique des regles typographiques en usage a l'Imprimerie nationale_.
|
||||
|
||||
Les variables entierement commentees sont celles pour lesquelles
|
||||
aucune information n'a ete trouvee. Par defaut, les guillements sont alors
|
||||
de la forme “mot”, sauf si la barre d'insertion de SPIP proposait
|
||||
deja une autre forme.
|
||||
|
||||
Version optimisee par Patrice Vanneufville (2007) cf http://www.spip-contrib.net/?article1592
|
||||
*/
|
||||
|
||||
// voir aussi : http://trac.rezo.net/trac/spip/changeset/9429
|
||||
|
||||
// definitions des chaines de remplacement
|
||||
define('_GUILLEMETS_defaut', '“$1”');
|
||||
define('_GUILLEMETS_fr', '« $1 »'); //LRTEUIN
|
||||
//define('_GUILLEMETS_ar', '');
|
||||
define('_GUILLEMETS_bg', '„$1“');
|
||||
//define('_GUILLEMETS_br', '');
|
||||
//define('_GUILLEMETS_bs', '');
|
||||
define('_GUILLEMETS_ca', '«$1»');
|
||||
define('_GUILLEMETS_cpf', '« $1 »');
|
||||
//define('_GUILLEMETS_cpf_hat', '');
|
||||
define('_GUILLEMETS_cs', '„$1“');
|
||||
define('_GUILLEMETS_da', '»$1«');
|
||||
define('_GUILLEMETS_de', '„$1“'); //ou "»$1«" // LRTEUIN
|
||||
define('_GUILLEMETS_en', '“$1”'); //LRTEUIN
|
||||
define('_GUILLEMETS_eo', '«$1»');
|
||||
define('_GUILLEMETS_es', '«$1»');
|
||||
//define('_GUILLEMETS_eu', '');
|
||||
//define('_GUILLEMETS_fa', '');
|
||||
//define('_GUILLEMETS_fon', '');
|
||||
//define('_GUILLEMETS_gl', '');
|
||||
define('_GUILLEMETS_hu', '„$1”');
|
||||
define('_GUILLEMETS_it', '«$1»');
|
||||
define('_GUILLEMETS_it_fem', '«$1»');
|
||||
define('_GUILLEMETS_ja', '「$1」');
|
||||
//define('_GUILLEMETS_lb', '');
|
||||
define('_GUILLEMETS_nl', '„$1”');
|
||||
//define('_GUILLEMETS_oc_auv', '');
|
||||
//define('_GUILLEMETS_oc_gsc', '');
|
||||
//define('_GUILLEMETS_oc_lms', '');
|
||||
//define('_GUILLEMETS_oc_lnc', '');
|
||||
//define('_GUILLEMETS_oc_ni', '');
|
||||
//define('_GUILLEMETS_oc_ni_la', '');
|
||||
//define('_GUILLEMETS_oc_prv', '');
|
||||
//define('_GUILLEMETS_oc_va', '');
|
||||
define('_GUILLEMETS_pl', '„$1”');
|
||||
define('_GUILLEMETS_pt', '«$1»');
|
||||
define('_GUILLEMETS_pt_br', '«$1»');
|
||||
define('_GUILLEMETS_ro', '„$1”');
|
||||
define('_GUILLEMETS_ru', '«$1»');
|
||||
define('_GUILLEMETS_tr', '«$1»');
|
||||
//define('_GUILLEMETS_vi', '');
|
||||
define('_GUILLEMETS_zh', '「$1」'); // ou "“$1”" 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]);
|
||||
}
|
||||
|
||||
function orthotypo_guillemets_rempl($texte){
|
||||
// on s'en va si pas de guillemets...
|
||||
if (strpos($texte, '"')===false) return $texte;
|
||||
// prudence : on protege TOUTES les balises contenant des doubles guillemets droits
|
||||
if (strpos($texte, '<')!==false){
|
||||
$texte = preg_replace_callback('/(<[^>]+"[^>]*>)/Ums', 'orthotypo_guillemets_echappe_balises_callback', $texte);
|
||||
}
|
||||
if (strpos($texte, '"')!==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;
|
||||
|
||||
// Remplacement des autres paires de guillemets (et suppression des espaces apres/avant)
|
||||
// Et retour des balises contenant des doubles guillemets droits
|
||||
$texte = preg_replace('/"\s*(.*?)\s*"/', $guilles, $texte);
|
||||
}
|
||||
$texte = echappe_retour($texte, 'GUILL');
|
||||
|
||||
return $texte;
|
||||
}
|
||||
|
||||
function orthotypo_guillemets_post_typo($texte){
|
||||
if (strpos($texte, '"')!==false)
|
||||
$texte = orthotypo_echappe_balises('html|code|cadre|frame|script|acronym|cite', 'orthotypo_guillemets_rempl', $texte);
|
||||
return $texte;
|
||||
}
|
||||
|
||||
|
||||
/* *********************************************************************************************************************
|
||||
* Exposants
|
||||
* Merge de
|
||||
* - http://zone.spip.org/trac/spip-zone/browser/_plugins_/typo_exposants/typo_exposants_fonctions.php?rev=61523
|
||||
* - http://zone.spip.org/trac/spip-zone/browser/_plugins_/couteau_suisse/outils/typo_exposants.php?rev=63425
|
||||
*/
|
||||
|
||||
// Filtre typographique exposants pour langue francaise
|
||||
// serieuse refonte 2006 : Patrice Vanneufville
|
||||
// Toutes les infos sur : http://www.spip-contrib.net/?article1564
|
||||
|
||||
// TODO : raccourci pour les exposants et indices (Pouce^2 ou Pouce^2^, H_2O ou H_2_O ou H,,2,,O
|
||||
// exemple : http://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>');
|
||||
|
||||
// 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){
|
||||
static $typo;
|
||||
if(!$typo) {
|
||||
$typo = array( array(
|
||||
',(?<=1)(st)\b,',
|
||||
',(?<=2)(nd)\b,',
|
||||
',(?<=3)(rd)\b,',
|
||||
',(?<=\d)(th)\b,',
|
||||
), array(
|
||||
_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){
|
||||
static $typo = null;
|
||||
static $egrave; static $eaigu1; static $eaigu2; static $accents;
|
||||
if (is_null($typo)) {
|
||||
// en principe, pas besoin de : caractere_utf_8(232)
|
||||
$egrave = unicode2charset('è').'|è|è';
|
||||
$eaigu1 = unicode2charset('é').'|é|é';
|
||||
$eaigu2 = unicode2charset('É').'|É|É';
|
||||
$accents = unicode2charset('àáâäåæèéêëìíîïòóôöùúûü');
|
||||
$typo = array(
|
||||
// Mlle(s), Mme(s) et erreurs Melle(s)
|
||||
// Mme(s) et Mgr
|
||||
'/\b(M)(?:(gr)|(mes?)|(?:e?(lles?)))\b/u' => _TYPO_sup2,
|
||||
// Dr, Pr suivis d'un espace d'un point ou d'un tiret
|
||||
'/(?<=\b[DP])(r)(?=[\s\.-])/u' => _TYPO_sup,
|
||||
|
||||
// m≤
|
||||
'/\bm≤\b/' => 'm<sup class="typo_exposants">2</sup>',
|
||||
// m2, m3
|
||||
'/\bm([23])\b/u' => 'm'._TYPO_sup,
|
||||
|
||||
// millions, milliards
|
||||
'/\b([Mm])([nd]s?)\b/u' => _TYPO_sup2,
|
||||
|
||||
// Vve
|
||||
'/\bV(ve)\b/' => 'V'._TYPO_sup,
|
||||
// Cie(s)
|
||||
'/\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" => 'É'._TYPO_class.'ts</sup>',
|
||||
|
||||
// 1er(s), Erreurs 1ier(s), 1ier(s)
|
||||
'/(?<=\b[1I])i?(ers?)\b/u' => _TYPO_sup,
|
||||
"/(?<=\b[1I])i?(?:e|$egrave)(res?)\b/u" => _TYPO_sup, // Erreurs 1(i)ere(s) + accents
|
||||
'/(?<=\b1)(r?es?)\b/u' => _TYPO_sup, // 1e(s), 1re(s)
|
||||
'/(?<=\b2)(nde?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>',
|
||||
// 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>',
|
||||
// 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));
|
||||
|
||||
}
|
||||
return preg_replace($typo[0], $typo[1], $texte);
|
||||
}
|
||||
|
||||
function orthotypo_exposants_echappe_balises_callback($matches) {
|
||||
return code_echappement($matches[1], 'EXPO',true,'span');
|
||||
}
|
||||
|
||||
function orthotypo_exposants_post_typo($texte){
|
||||
if (!$lang = $GLOBALS['lang_objet']) $lang = $GLOBALS['spip_lang'];
|
||||
if(function_exists($fonction = 'orthotypo_exposants_'.lang_typo($lang))){
|
||||
// prudence : on protege les balises <a> et <img>
|
||||
if (strpos($texte, '<')!==false)
|
||||
$texte = preg_replace_callback('/(<(a|img)\s[^>]+>)/Uims', 'orthotypo_exposants_echappe_balises_callback', $texte);
|
||||
$texte = orthotypo_echappe_balises('html|code|cadre|frame|script|acronym|cite', $fonction, $texte);
|
||||
return echappe_retour($texte, 'EXPO');
|
||||
}
|
||||
return $texte;
|
||||
}
|
||||
|
||||
/* *********************************************************************************************************************
|
||||
* Typo des Mois : espace insecable entre le numero du jour et le mois : 12 Mars => 12 Mars
|
||||
* Tire de
|
||||
* - http://zone.spip.org/trac/spip-zone/browser/_plugins_/typo_mois/typo_mois_fonctions.php?rev=43239
|
||||
* avec ameliorations :
|
||||
* - prise en compte des echappements de balise
|
||||
* - prise en compte de la langue
|
||||
*/
|
||||
|
||||
function orthotypo_mois_rempl($texte){
|
||||
static $typo = array();
|
||||
$lang = $GLOBALS['spip_lang'];
|
||||
if(!isset($typo[$lang])) {
|
||||
$typo[$lang] = array();
|
||||
for ($m=1; $m<=12; $m++)
|
||||
$typo[$lang][] = _T('date_mois_'.$m);
|
||||
$pre1 = _T('date_jnum1');
|
||||
$pre2 = _T('date_jnum2');
|
||||
$pre3 = _T('date_jnum3');
|
||||
$typo[$lang] = ",([1-3]?[0-9]|$pre1|$pre2|$pre3)\s+(".join('|', $typo[$lang]).'),UimsS';
|
||||
include_spip('inc/charsets');
|
||||
$typo[$lang] = unicode2charset(html2unicode($typo[$lang]));
|
||||
}
|
||||
|
||||
return preg_replace($typo[$lang], '\1 \2', $texte);
|
||||
}
|
||||
|
||||
function orthotypo_mois_post_typo($texte){
|
||||
if (strpbrk($texte,"123456789")!==false){
|
||||
$texte = orthotypo_echappe_balises('html|code|cadre|frame|script|acronym|cite', "orthotypo_mois_rempl", $texte);
|
||||
}
|
||||
return $texte;
|
||||
}
|
||||
|
||||
/* *********************************************************************************************************************
|
||||
* Typo des Caps : espace insecable entre le numero du jour et le mois : 12 Mars => 12 Mars
|
||||
* Tire de
|
||||
* - http://zone.spip.org/trac/spip-zone/browser/_plugins_/typo_caps/typo_caps_fonctions.php?rev=43238
|
||||
* avec ameliorations :
|
||||
* - prise en compte des echappements de balise
|
||||
*/
|
||||
|
||||
/* code tire de typogrify
|
||||
* http://jeffcroft.com/sidenotes/2007/may/29/typogrify-easily-produce-web-typography-doesnt-suc/
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 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_rempl($texte){
|
||||
static $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 much at least include two caps (but they can have digits between them)
|
||||
[A-Z\d]*\b) # Any amount of caps and digits
|
||||
| (\b[A-Z]+\.\s? # OR: Group 3: Some caps, followed by a '.' and an optional space
|
||||
(?:[A-Z]+\.\s?)+) # Followed by the same thing at least once more
|
||||
(?:\s|\b|$))/xS";
|
||||
}
|
||||
return preg_replace_callback($cap_finder, 'orthotypo_caps_replace_callback', $texte);
|
||||
}
|
||||
|
||||
function orthotypo_caps_post_typo($texte){
|
||||
$texte = orthotypo_echappe_balises('html|code|cadre|frame|script|acronym|cite', "orthotypo_caps_rempl", $texte);
|
||||
return $texte;
|
||||
}
|
||||
|
||||
|
||||
/* *********************************************************************************************************************
|
||||
* Outil Correction auto tiree de la lame insertion du CS
|
||||
*/
|
||||
|
||||
|
||||
// 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)){
|
||||
$liste = preg_split("/[\r\n]+/", $regles);
|
||||
foreach ($liste as $l) {
|
||||
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;
|
||||
} elseif (preg_match('/^(\/.+\/[imsxuADSUX]*)$/', $a)) {
|
||||
// expressions regulieres
|
||||
$preg[0][] = $a; $preg[1][] = $b;
|
||||
} elseif (strlen($a)) {
|
||||
// simples remplacements
|
||||
$str[0][] = $a; $str[1][] = $b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array($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)){
|
||||
list($str,$preg) = orthotypo_corrections_regles();
|
||||
}
|
||||
// prudence : on protege les urls dans les raccourcis de liens SPIP
|
||||
if (strpos($texte, '[')!==false)
|
||||
$texte = preg_replace_callback(',(\[[^][]*->>?)([^]]*)(?=\]),msS', 'orthotypo_corrections_echappe_liens', $texte);
|
||||
|
||||
if (count($str))
|
||||
$texte = str_replace($str[0], $str[1], $texte);
|
||||
if (count($preg))
|
||||
$texte = preg_replace($preg[0], $preg[1], $texte);
|
||||
|
||||
return echappe_retour($texte, 'CORRECTIONS');
|
||||
}
|
||||
|
||||
function orthotypo_corrections_echappe_liens($m) {
|
||||
return $m[1].code_echappement($m[2], 'CORRECTIONS');
|
||||
}
|
||||
|
||||
// Fonctions de traitement sur #TEXTE
|
||||
function orthotypo_corrections_pre_propre($texte) {
|
||||
return orthotypo_echappe_balises('', 'orthotypo_corrections_rempl', $texte);
|
||||
}
|
||||
|
||||
?>
|
@ -0,0 +1,25 @@
|
||||
<paquet
|
||||
prefix="orthotypo"
|
||||
categorie="edition"
|
||||
version="1.1.0"
|
||||
etat="test"
|
||||
compatibilite="[3.0.0;3.0.*]"
|
||||
logo="prive/themes/spip/images/orthotypo-32.png"
|
||||
documentation=""
|
||||
>
|
||||
|
||||
<nom>Ortho-Typographie</nom>
|
||||
|
||||
<auteur lien="http://contrib.spip.net/auteur7639">Vincent Ramos</auteur>
|
||||
<auteur lien="http://contrib.spip.net/auteur5053">Raphaël Meyssan</auteur>
|
||||
<auteur lien="http://contrib.spip.net/auteur4">Fil</auteur>
|
||||
<auteur lien="http://contrib.spip.net/auteur5714">Patrice Vanneufville</auteur>
|
||||
<auteur lien="http://contrib.spip.net/auteur6809">tetue</auteur>
|
||||
|
||||
<licence>GNU/GPL</licence>
|
||||
|
||||
<pipeline nom="insert_head_css" inclure="orthotypo_fonctions.php" />
|
||||
<pipeline nom="post_typo" inclure="orthotypo_fonctions.php" />
|
||||
<pipeline nom="pre_propre" inclure="orthotypo_fonctions.php" />
|
||||
|
||||
</paquet>
|
@ -0,0 +1,7 @@
|
||||
[(#AUTORISER{configurer,_orthotypo}|sinon_interdire_acces)]
|
||||
|
||||
<h1 class="grostitre"><:orthotypo:titre_page_configurer_orthotypo:></h1>
|
||||
|
||||
<div class="ajax">
|
||||
#FORMULAIRE_CONFIGURER_ORTHOTYPO
|
||||
</div>
|
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
Loading…
Reference in New Issue