/** * 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; }
/** * Apply all rules of RuleSet to a text * * @param string $t * @return string */ public function &test() { $tests =& $this->testset->getTests(); $results = array(); ## apply each in order foreach ($tests as $i => $test) { #php4+php5 if (!$test->disabled) { $results[$i] = array('test' => &$tests[$i]); $w = new TextWheel($test->ruleset); $output = $w->text($test->input); if ($output == $test->output) { $results[$i]['result'] = true; } else { $results[$i]['result'] = false; $results[$i]['output'] = $output; } } } return $results; }