function couper_intro3($texte, $long, $suite) { $texte = extraire_multi(preg_replace(",(</?)intro>,i", "\\1intro>", $texte)); // minuscules $intro = ''; while ($fin = strpos($texte, "</intro>")) { $zone = substr($texte, 0, $fin); $texte = substr($texte, $fin + strlen("</intro>")); if ($deb = strpos($zone, "<intro>") OR substr($zone, 0, 7) == "<intro>") $zone = substr($zone, $deb + 7); $intro .= $zone; } $texte = nettoyer_raccourcis_typo($intro ? $intro : $texte); return PtoBR(traiter_raccourcis(preg_replace(',([|]\s*)+,S', '; ', couper($texte, $long, _INTRODUCTION_CODE)))); }
function onglets_callback($matches) { // cas des onglets imbriques if (strpos($matches[2], '<onglets')!==false) $matches[2] = preg_replace_callback(_onglets_REGEXPR, 'onglets_callback', $matches[2]); // nettoyage apres les separateurs $matches[2] = preg_replace(','.preg_quote(_decoupe_SEPARATEUR,',').'\s+,', _decoupe_SEPARATEUR, $matches[2]); // au cas ou on ne veuille pas d'onglets, on remplace les '++++' par un filet et on entoure d'une classe. if (defined('_CS_PRINT')) { @define(_decoupe_FILET, '<p style="border-bottom:1px dashed #666; padding:0; margin:1em 20%; font-size:4pt;" > </p>'); $t = preg_split(',(\n\n|\r\n\r\n|\r\r),', $matches[2], 2); $texte = preg_replace(','.preg_quote(_decoupe_SEPARATEUR, ',').'(.*?)(\n\n|\r\n\r\n|\r\r),ms', _decoupe_FILET."<h4>$1</h4>\n\n", $t[1]); // on sait jamais... str_replace(_decoupe_SEPARATEUR, _decoupe_FILET, $texte); return '<div class="onglets_print"><h4>' . textebrut(echappe_retour($t[0],'CS')) . "</h4>\n\n$texte\n\n</div>"; } $onglets = $contenus = array(); $pages = explode(_decoupe_SEPARATEUR, $matches[2]); foreach ($pages as $p) { $t = preg_split(',(\n\n|\r\n\r\n|\r\r),', $p, 2); $t = array(trim(textebrut(nettoyer_raccourcis_typo(echappe_retour($t[0],'CS')))), cs_safebalises($t[1])); if(strlen($t[0].$t[1])) $contenus[] = _onglets_CONTENU.$t[0]._onglets_CONTENU2."<div>\n\n".$t[1]."\n\n</div></div>"; } return _onglets_DEBUT.join('', $contenus).'</div>'._onglets_FIN; }
function couper($texte, $taille = 50, $suite = ' (...)') { if (!($length = strlen($texte)) or $taille <= 0) { return ''; } $offset = 400 + 2 * $taille; while ($offset < $length and strlen(preg_replace(",<[^>]+>,Uims", "", substr($texte, 0, $offset))) < $taille) { $offset = 2 * $offset; } if ($offset < $length && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== NULL) { $p_tag_fermant = strpos($texte, '>', $offset); if ($p_tag_fermant && $p_tag_fermant < $p_tag_ouvrant) { $offset = $p_tag_fermant + 1; } // prolonger la coupe jusqu'au tag fermant suivant eventuel } $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ // on utilise les \r pour passer entre les gouttes $texte = str_replace("\r\n", "\n", $texte); $texte = str_replace("\r", "\n", $texte); // sauts de ligne et paragraphes $texte = preg_replace("/\n\n+/", "\r", $texte); $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/", "\r", $texte); // supprimer les traits, lignes etc $texte = preg_replace("/(^|\r|\n)(-[-#\\*]*|_ )/", "\r", $texte); // supprimer les tags $texte = supprimer_tags($texte); $texte = trim(str_replace("\n", " ", $texte)); $texte .= "\n"; // marquer la fin // travailler en accents charset $texte = unicode2charset(html2unicode($texte, true)); if (!function_exists('nettoyer_raccourcis_typo')) { include_spip('inc/lien'); } $texte = nettoyer_raccourcis_typo($texte); // corriger la longueur de coupe // en fonction de la presence de caracteres utf if ($GLOBALS['meta']['charset'] == 'utf-8') { $long = charset2unicode($texte); $long = spip_substr($long, 0, max($taille, 1)); $nbcharutf = preg_match_all('/(&#[0-9]{3,5};)/S', $long, $matches); $taille += $nbcharutf; } // couper au mot precedent $long = spip_substr($texte, 0, max($taille - 4, 1)); $u = $GLOBALS['meta']['pcre_u']; $court = preg_replace("/([^\\s][\\s]+)[^\\s]*\n?\$/" . $u, "\\1", $long); $points = $suite; // trop court ? ne pas faire de (...) if (spip_strlen($court) < max(0.75 * $taille, 2)) { $points = ''; $long = spip_substr($texte, 0, $taille); $texte = preg_replace("/([^\\s][\\s]+)[^\\s]*\n?\$/" . $u, "\\1", $long); // encore trop court ? couper au caractere if (spip_strlen($texte) < 0.75 * $taille) { $texte = $long; } } else { $texte = $court; } if (strpos($texte, "\n")) { // la fin est encore la : c'est qu'on n'a pas de texte de suite $points = ''; } // remettre les paragraphes $texte = preg_replace("/\r+/", "\n\n", $texte); // supprimer l'eventuelle entite finale mal coupee $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); return quote_amp(trim($texte)) . $points; }
function tw_traiter_raccourci_notes($letexte, $marqueur_notes) { global $compt_note, $les_notes, $notes_vues; global $ouvre_ref, $ferme_ref; if (strpos($letexte, '[[') === false or !preg_match_all(_RACCOURCI_NOTES_TW, $letexte, $m, PREG_SET_ORDER)) { return array($letexte, array()); } // quand il y a plusieurs series de notes sur une meme page $mn = !$marqueur_notes ? '' : $marqueur_notes . '-'; $mes_notes = array(); foreach ($m as $r) { list($note_source, $note_all, $ref, $nom, $note_texte) = $r; // reperer une note nommee, i.e. entre chevrons // On leve la Confusion avec une balise en regardant // si la balise fermante correspondante existe // Cas pathologique: [[ <a> <a href="x">x</a>]] if (!(isset($nom) and $ref and (strpos($note_texte, '</' . $nom . '>') === false or preg_match(",<{$nom}\\W.*</{$nom}>,", $note_texte)))) { $nom = ++$compt_note; $note_texte = $note_all; } // eliminer '%' pour l'attribut id $ancre = $mn . str_replace('%', '_', rawurlencode($nom)); // ne mettre qu'une ancre par appel de note (XHTML) $att = $notes_vues[$ancre]++ ? '' : " id='nh{$ancre}'"; // creer le popup 'title' sur l'appel de note ## attention : propre() est couteux ! ## utiliser nettoyer_raccourcis_typo() ? if ($title = supprimer_tags(nettoyer_raccourcis_typo($note_texte))) { $title = " title='" . couper($title, 80) . "'"; } // ajouter la note aux notes precedentes if ($note_texte) { $mes_notes[] = array($ancre, $nom, $note_texte); } // dans le texte, mettre l'appel de note a la place de la note if ($nom) { $nom = "{$ouvre_ref}<a href='#nb{$ancre}' class='spip_note' rel='footnote'{$title}{$att}>{$nom}</a>{$ferme_ref}"; } $pos = strpos($letexte, $note_source); $letexte = rtrim(substr($letexte, 0, $pos), ' ') . code_echappement($nom) . substr($letexte, $pos + strlen($note_source)); } return array($letexte, $mes_notes); }
function traiter_raccourci_lien_atts($texte) { $bulle = $hlang = false; // title et hreflang donnes par le raccourci ? if (strpbrk($texte, "|{") !== false and preg_match(_RACCOURCI_ATTRIBUTS, $texte, $m)) { $n = count($m); // |infobulle ? if ($n > 2) { $bulle = $m[3]; // {hreflang} ? if ($n > 4) { // si c'est un code de langue connu, on met un hreflang if (traduire_nom_langue($m[5]) != $m[5]) { $hlang = $m[5]; } elseif (!$m[5]) { $hlang = test_espace_prive() ? $GLOBALS['lang_objet'] : $GLOBALS['spip_lang']; // sinon c'est un italique ou un gras dans le title ou dans le texte du lien } else { if ($bulle) { $bulle .= $m[4]; } else { $m[1] .= $m[2] . $m[4]; } } } else { if (preg_match('/^[a-z_]+$/', $m[3])) { // si c'est un code de langue connu, on met un hreflang // mais on laisse le title (c'est arbitraire tout ca...) if (traduire_nom_langue($m[3]) != $m[3]) { $hlang = $m[3]; } } } } $texte = $m[1]; } if ($bulle) { $bulle = nettoyer_raccourcis_typo($bulle); $bulle = corriger_typo($bulle); } return array(trim($texte), $bulle, $hlang); }