Example #1
0
/**
 * Nettoie un texte, traite les raccourcis autre qu'URL, la typo, etc.
 *
 * http://code.spip.net/@traiter_raccourcis
 *
 * @param string $t
 * @param bool $show_autobr
 * @return string
 */
function traiter_raccourcis($t, $show_autobr = false)
{
    static $wheel, $notes;
    static $img_br_auto, $img_br_manuel, $img_br_no;
    // hack1: respecter le tag ignore br
    if (_AUTOBR_IGNORER and strncmp($t, _AUTOBR_IGNORER, strlen(_AUTOBR_IGNORER)) == 0) {
        $ignorer_autobr = true;
        $t = substr($t, strlen(_AUTOBR_IGNORER));
    } else {
        $ignorer_autobr = false;
    }
    // Appeler les fonctions de pre_traitement
    $t = pipeline('pre_propre', $t);
    if (!isset($wheel)) {
        $ruleset = SPIPTextWheelRuleset::loader($GLOBALS['spip_wheels']['raccourcis'], 'personnaliser_raccourcis');
        $wheel = new TextWheel($ruleset);
        if (_request('var_mode') == 'wheel' and autoriser('debug')) {
            $f = $wheel->compile();
            echo "<pre>\n" . spip_htmlspecialchars($f) . "</pre>\n";
            exit;
        }
        $notes = charger_fonction('notes', 'inc');
    }
    // Gerer les notes (ne passe pas dans le pipeline)
    list($t, $mes_notes) = $notes($t);
    $t = $wheel->text($t);
    // Appeler les fonctions de post-traitement
    $t = pipeline('post_propre', $t);
    if ($mes_notes) {
        $notes($mes_notes, 'traiter', $ignorer_autobr);
    }
    // hack2: wrap des autobr dans l'espace prive, pour affichage css
    // 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-10.png", _T("tw:retour_ligne_ignore"), "class='br-no'", _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-10.png", _T("tw:retour_ligne_manuel"), "class='br-manuel'", _T("tw:retour_ligne_manuel"));
        }
        if (is_null($img_br_auto)) {
            $img_br_auto = http_img_pack("br-auto-10.png", _T("tw:retour_ligne_auto"), "class='br-auto'", _T("tw:retour_ligne_auto"));
        }
        if (false !== strpos(strtolower($t), '<br')) {
            $t = preg_replace("/<br\\b.*>/UiS", "{$img_br_manuel}\\0", $t);
            $t = str_replace($img_br_manuel . _AUTOBR, $img_br_auto . _AUTOBR, $t);
        }
    }
    return $t;
}
Example #2
0
function tw_traiter_raccourcis($letexte)
{
    static $wheel;
    // Appeler les fonctions de pre_traitement
    #$letexte = pipeline('pre_propre', $letexte);
    $debug = _request('var_debug_wheel');
    if (!isset($wheel)) {
        if ($debug) {
            spip_timer('init');
        }
        $ruleset = SPIPTextWheelRuleset::loader($GLOBALS['spip_wheels']['raccourcis'], 'tw_personaliser_raccourcis');
        $wheel = new $GLOBALS['textWheel']($ruleset);
        if (_request('var_mode') == 'compile') {
            echo "<pre>";
            echo htmlspecialchars($wheel->compile());
            echo "</pre>\n";
        }
        if ($debug) {
            $GLOBALS['totaux']['tw_traiter_raccourcis:']['init'] += spip_timer('init', true);
        }
    }
    // Gerer les notes (ne passe pas dans le pipeline)
    if ($debug) {
        spip_timer('notes');
    }
    $notes = charger_fonction('notes', 'inc');
    list($letexte, $mes_notes) = $notes($letexte);
    if ($debug) {
        $GLOBALS['totaux']['tw_traiter_raccourcis:']['notes'] += spip_timer('notes', true);
    }
    if ($debug) {
        spip_timer('text');
    }
    $letexte = $wheel->text($letexte);
    if ($debug) {
        $GLOBALS['totaux']['tw_traiter_raccourcis:']['text'] += spip_timer('text', true);
    }
    // Appeler les fonctions de post-traitement
    if ($debug) {
        spip_timer('post_propre');
    }
    $letexte = pipeline('post_propre', $letexte);
    if ($debug) {
        $GLOBALS['totaux']['tw_traiter_raccourcis:']['post_propre'] += spip_timer('post_propre', true);
    }
    if ($debug) {
        spip_timer('mesnotes');
    }
    if ($mes_notes) {
        $notes($mes_notes);
    }
    if ($debug) {
        $GLOBALS['totaux']['tw_traiter_raccourcis:']['mesnotes'] += spip_timer('mesnotes', true);
    }
    return $letexte;
}