Example #1
0
function traiter_math($letexte, $source = '')
{
    $texte_a_voir = $letexte;
    while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
        if (!($fin = strpos($texte_a_voir, "</math>"))) {
            $fin = strlen($texte_a_voir);
        }
        $texte_debut = substr($texte_a_voir, 0, $debut);
        $texte_milieu = substr($texte_a_voir, $debut + strlen("<math>"), $fin - $debut - strlen("<math>"));
        $texte_fin = substr($texte_a_voir, $fin + strlen("</math>"), strlen($texte_a_voir));
        // Les doubles $$x^2$$ en mode 'div'
        while (preg_match(",[\$][\$]([^\$]+)[\$][\$],", $texte_milieu, $regs)) {
            $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($regs[1]) . "</p>\n";
            $pos = strpos($texte_milieu, $regs[0]);
            $texte_milieu = substr($texte_milieu, 0, $pos) . code_echappement($echap, $source) . substr($texte_milieu, $pos + strlen($regs[0]));
        }
        // Les simples $x^2$ en mode 'span'
        while (preg_match(",[\$]([^\$]+)[\$],", $texte_milieu, $regs)) {
            $echap = produire_image_math($regs[1]);
            $pos = strpos($texte_milieu, $regs[0]);
            $texte_milieu = substr($texte_milieu, 0, $pos) . code_echappement($echap, $source) . substr($texte_milieu, $pos + strlen($regs[0]));
        }
        $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin;
    }
    return $texte_a_voir;
}
Example #2
0
function extraire_multi($letexte, $lang = null, $echappe_span = false)
{
    if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
        if (!$lang) {
            $lang = $GLOBALS['spip_lang'];
        }
        foreach ($regs as $reg) {
            // chercher la version de la langue courante
            $trads = extraire_trads($reg[1]);
            if ($l = approcher_langue($trads, $lang)) {
                $trad = $trads[$l];
            } else {
                include_spip('inc/texte');
                // langue absente, prendre la premiere dispo
                // mais typographier le texte selon les regles de celle-ci
                // Attention aux blocs multi sur plusieurs lignes
                $l = key($trads);
                $trad = $trads[$l];
                $typographie = charger_fonction(lang_typo($l), 'typographie');
                $trad = $typographie($trad);
                include_spip('inc/texte');
                // Tester si on echappe en span ou en div
                // il ne faut pas echapper en div si propre produit un seul paragraphe
                $trad_propre = preg_replace(",(^<p[^>]*>|</p>\$),Uims", "", propre($trad));
                $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
                $trad = code_echappement($trad, 'multi', false, $mode);
                $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
                if (lang_dir($l) !== lang_dir($lang)) {
                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
                }
                if (!$echappe_span) {
                    $trad = echappe_retour($trad, 'multi');
                }
            }
            $letexte = str_replace($reg[0], $trad, $letexte);
        }
    }
    return $letexte;
}
Example #3
0
function traiter_modeles($texte, $doublons=false, $echap='', $connect='', $liens = null) {
	// preserver la compatibilite : true = recherche des documents
	if ($doublons===true)
		$doublons = array('documents'=>array('doc','emb','img'));
	// detecter les modeles (rapide)
	if (strpos($texte,"<")!==false AND
	  preg_match_all('/<[a-z_-]{3,}\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)) {
		include_spip('public/assembler');
		foreach ($matches as $match) {
			// Recuperer l'appel complet (y compris un eventuel lien)

			$a = strpos($texte,$match[0]);
			preg_match(_RACCOURCI_MODELE_DEBUT,
			substr($texte, $a), $regs);
			$regs[]=""; // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
			list(,$mod, $type, $id, $params, $fin) = $regs;
			if ($fin AND
			preg_match('/<a\s[^<>]*>\s*$/i',
					substr($texte, 0, $a), $r)) {
				$lien = array(
					'href' => extraire_attribut($r[0],'href'),
					'class' => extraire_attribut($r[0],'class'),
					'mime' => extraire_attribut($r[0],'type')
				);
				$n = strlen($r[0]);
				$a -= $n;
				$cherche = $n + strlen($regs[0]);
			} else {
				$lien = false;
				$cherche = strlen($mod);
			}

			// calculer le modele
			# hack articles_edit, breves_edit, indexation
			if ($doublons)
				$texte .= preg_replace(',[|][^|=]*,s',' ',$params);
			# version normale
			else {
				// si un tableau de liens a ete passe, reinjecter le contenu d'origine
				// dans les parametres, plutot que les liens echappes
				if (!is_null($liens))
					$params = str_replace($liens[0], $liens[1], $params);
			  $modele = inclure_modele($type, $id, $params, $lien, $connect);
				// en cas d'echec, 
				// si l'objet demande a une url, 
				// creer un petit encadre vers elle
				if ($modele === false) {
					if (!$lien)
						$lien = traiter_lien_implicite("$type$id", '', 'tout', $connect);
					if ($lien)
						$modele = '<a href="'
						  .$lien['url']
						  .'" class="spip_modele'
						  . '">'
						  .sinon($lien['titre'], _T('ecrire:info_sans_titre'))
						  ."</a>";
					else {
						$modele = "";
						if (test_espace_prive()) {
							$modele = entites_html(substr($texte,$a,$cherche));
							if (!is_null($liens))
								$modele = "<pre>".str_replace($liens[0], $liens[1], $modele)."</pre>";
						}
					}
				}
				// le remplacer dans le texte
				if ($modele !== false) {
					$modele = protege_js_modeles($modele);
					$rempl = code_echappement($modele, $echap);
					$texte = substr($texte, 0, $a)
						. $rempl
						. substr($texte, $a+$cherche);
				}
			}

			// hack pour tout l'espace prive
			if (((!_DIR_RESTREINT) OR ($doublons)) AND ($id)){
				foreach($doublons?$doublons:array('documents'=>array('doc','emb','img')) as $quoi=>$modeles)
					if (in_array($type,$modeles))
						$GLOBALS["doublons_{$quoi}_inclus"][] = $id;
			}
		}
	}

	return $texte;
}
Example #4
0
function protege_js_modeles($t)
{
    if (isset($GLOBALS['visiteur_session'])) {
        if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) {
            if (!defined('_PROTEGE_JS_MODELES')) {
                include_spip('inc/acces');
                define('_PROTEGE_JS_MODELES', creer_uniqid());
            }
            foreach ($r as $regs) {
                $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t);
            }
        }
        if (preg_match_all(',<\\?php.*?($|\\?' . '>),isS', $t, $r, PREG_SET_ORDER)) {
            if (!defined('_PROTEGE_PHP_MODELES')) {
                include_spip('inc/acces');
                define('_PROTEGE_PHP_MODELES', creer_uniqid());
            }
            foreach ($r as $regs) {
                $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t);
            }
        }
    }
    return $t;
}
Example #5
0
function traiter_modeles($texte, $doublons = false, $echap = '', $connect = '', $liens = null, $env = array())
{
    // preserver la compatibilite : true = recherche des documents
    if ($doublons === true) {
        $doublons = array('documents' => array('doc', 'emb', 'img'));
    }
    // detecter les modeles (rapide)
    if (strpos($texte, "<") !== false and preg_match_all('/<[a-z_-]{3,}\\s*[0-9|]+/iS', $texte, $matches, PREG_SET_ORDER)) {
        include_spip('public/assembler');
        foreach ($matches as $match) {
            // Recuperer l'appel complet (y compris un eventuel lien)
            $a = strpos($texte, $match[0]);
            preg_match(_RACCOURCI_MODELE_DEBUT, substr($texte, $a), $regs);
            while (count($regs) < 6) {
                $regs[] = "";
            }
            // s'assurer qu'il y a toujours un 5e arg, eventuellement vide
            list(, $mod, $type, $id, $params, $fin) = $regs;
            if ($fin and preg_match('/<a\\s[^<>]*>\\s*$/i', substr($texte, 0, $a), $r)) {
                $lien = array('href' => extraire_attribut($r[0], 'href'), 'class' => extraire_attribut($r[0], 'class'), 'mime' => extraire_attribut($r[0], 'type'));
                $n = strlen($r[0]);
                $a -= $n;
                $cherche = $n + strlen($regs[0]);
            } else {
                $lien = false;
                $cherche = strlen($mod);
            }
            // calculer le modele
            # hack indexation
            if ($doublons) {
                $texte .= preg_replace(',[|][^|=]*,s', ' ', $params);
            } else {
                // si un tableau de liens a ete passe, reinjecter le contenu d'origine
                // dans les parametres, plutot que les liens echappes
                if (!is_null($liens)) {
                    $params = str_replace($liens[0], $liens[1], $params);
                }
                $modele = inclure_modele($type, $id, $params, $lien, $connect, $env);
                // en cas d'echec,
                // si l'objet demande a une url,
                // creer un petit encadre vers elle
                if ($modele === false) {
                    $modele = substr($texte, $a, $cherche);
                    if (!is_null($liens)) {
                        $modele = str_replace($liens[0], $liens[1], $modele);
                    }
                    $contexte = array_merge($env, array('id' => $id, 'type' => $type, 'modele' => $modele));
                    if ($lien) {
                        # un eventuel guillemet (") sera reechappe par #ENV
                        $contexte['lien'] = str_replace("&quot;", '"', $lien['href']);
                        $contexte['lien_class'] = $lien['class'];
                        $contexte['lien_mime'] = $lien['mime'];
                    }
                    $modele = recuperer_fond("modeles/dist", $contexte, array(), $connect);
                }
                // le remplacer dans le texte
                if ($modele !== false) {
                    $modele = protege_js_modeles($modele);
                    $rempl = code_echappement($modele, $echap);
                    $texte = substr($texte, 0, $a) . $rempl . substr($texte, $a + $cherche);
                }
            }
            // hack pour tout l'espace prive
            if ((!_DIR_RESTREINT or $doublons) and $id) {
                foreach ($doublons ? $doublons : array('documents' => array('doc', 'emb', 'img')) as $quoi => $modeles) {
                    if (in_array($type, $modeles)) {
                        $GLOBALS["doublons_{$quoi}_inclus"][] = $id;
                    }
                }
            }
        }
    }
    return $texte;
}
Example #6
0
function tw_traiter_les_notes($notes)
{
    global $ouvre_note, $ferme_note;
    $mes_notes = '';
    if ($notes) {
        $title = _T('info_notes');
        foreach ($notes as $r) {
            list($ancre, $nom, $texte) = $r;
            $atts = " href='#nh{$ancre}' class='spip_note' title='{$title} {$ancre}' rev='footnote'";
            $mes_notes .= "\n\n" . "<div id='nb{$ancre}'><p" . ($GLOBALS['class_spip'] ? " class='spip_note'" : "") . ">" . code_echappement($nom ? "{$ouvre_note}<a{$atts}>{$nom}</a>{$ferme_note}" : '') . $texte . '</div>';
        }
        $mes_notes = propre($mes_notes);
    }
    return $GLOBALS['les_notes'] .= $mes_notes;
}
Example #7
0
function traiter_les_notes($notes, $ignorer_autobr)
{
    $mes_notes = '';
    if ($notes) {
        $title = _T('info_notes');
        foreach ($notes as $r) {
            list($ancre, $nom, $texte) = $r;
            $atts = " href='#nh{$ancre}' class='spip_note' title='{$title} {$ancre}' rev='footnote'";
            $mes_notes .= "\n\n" . "<div id='nb{$ancre}'><p" . ($GLOBALS['class_spip'] ? " class='spip_note'" : "") . ">" . code_echappement($nom ? _NOTES_OUVRE_NOTE . "<a" . $atts . ">{$nom}</a>" . _NOTES_FERME_NOTE : '') . trim($texte) . '</div>';
        }
        if ($ignorer_autobr) {
            $mes_notes = _AUTOBR_IGNORER . $mes_notes;
        }
        $mes_notes = propre($mes_notes);
    }
    return $GLOBALS['les_notes'] .= $mes_notes;
}
Example #8
0
function extraire_multi($letexte, $lang=null, $echappe_span=false) {
	if (strpos($letexte, '<multi>') === false) return $letexte; // perf
	if (preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
		if (!$lang) $lang = $GLOBALS['spip_lang'];

		foreach ($regs as $reg) {
			// chercher la version de la langue courante
			$trads = extraire_trads($reg[1]);
			if ($l = approcher_langue($trads, $lang)) {
				$trad = $trads[$l];
			} else {
				include_spip('inc/texte');
				// langue absente, prendre la premiere dispo
				// mais typographier le texte selon les regles de celle-ci
				// Attention aux blocs multi sur plusieurs lignes
				$l = key($trads);
				$trad = $trads[$l];
				$typographie = charger_fonction(lang_typo($l), 'typographie');
				$trad = traiter_retours_chariots($typographie($trad));
				$trad = explode("\n", $trad);
				foreach($trad as $i => $ligne) {
					if (strlen($ligne)) {
						$ligne = code_echappement($ligne, 'multi');
						$ligne = str_replace("'", '"', inserer_attribut($ligne, 'lang', $l));
						if (lang_dir($l) !== lang_dir($lang))
							$ligne = str_replace("'", '"', inserer_attribut($ligne, 'dir', lang_dir($l)));
						$trad[$i] = $ligne;
					}
				}
				$trad = join("\n", $trad);
				if (!$echappe_span)
					$trad = echappe_retour($trad, 'multi');
			}
			$letexte = str_replace($reg[0], $trad, $letexte);
		}
	}

	return $letexte;
}
Example #9
0
function extraire_multi($letexte, $lang = null, $options = array())
{
    if ($letexte and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)) {
        if (!$lang) {
            $lang = $GLOBALS['spip_lang'];
        }
        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
        if (is_bool($options)) {
            $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT);
        }
        if (!isset($options['echappe_span'])) {
            $options = array_merge($options, array('echappe_span' => false));
        }
        if (!isset($options['lang_defaut'])) {
            $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT));
        }
        include_spip('inc/lang');
        foreach ($regs as $reg) {
            // chercher la version de la langue courante
            $trads = extraire_trads($reg[1]);
            if ($l = approcher_langue($trads, $lang)) {
                $trad = $trads[$l];
            } else {
                if ($options['lang_defaut'] == 'aucune') {
                    $trad = '';
                } else {
                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
                    // ou la premiere dispo
                    // mais typographier le texte selon les regles de celle-ci
                    // Attention aux blocs multi sur plusieurs lignes
                    if (!($l = approcher_langue($trads, $options['lang_defaut']))) {
                        $l = key($trads);
                    }
                    $trad = $trads[$l];
                    $typographie = charger_fonction(lang_typo($l), 'typographie');
                    $trad = $typographie($trad);
                    // Tester si on echappe en span ou en div
                    // il ne faut pas echapper en div si propre produit un seul paragraphe
                    include_spip('inc/texte');
                    $trad_propre = preg_replace(",(^<p[^>]*>|</p>\$),Uims", "", propre($trad));
                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
                    $trad = code_echappement($trad, 'multi', false, $mode);
                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
                    if (lang_dir($l) !== lang_dir($lang)) {
                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
                    }
                    if (!$options['echappe_span']) {
                        $trad = echappe_retour($trad, 'multi');
                    }
                }
            }
            $letexte = str_replace($reg[0], $trad, $letexte);
        }
    }
    return $letexte;
}
Example #10
0
function traiter_les_notes($notes) {
	global $ouvre_note, $ferme_note;

	$mes_notes = '';
	if ($notes) {
		$title =  _T('info_notes');
		foreach ($notes as $r) {
			list($ancre, $nom, $texte) = $r;
			$atts = " href='#nh$ancre' id='nb$ancre' class='spip_note' title='$title $ancre' rev='footnote'";
			$mes_notes .= "\n\n"
			. code_echappement($nom
				? "$ouvre_note<a$atts>$nom</a>$ferme_note"
				: '')
			. $texte;
		}
		$mes_notes = propre('<p>' . $mes_notes);
		if ($GLOBALS['class_spip'])
			$mes_notes = str_replace('<p class="spip">', '<p class="spip_note">', $mes_notes);
	}
	return ($GLOBALS['les_notes'] .= $mes_notes);
}