Esempio n. 1
0
File: sax.php Progetto: nursit/SPIP
function xml_sax_dist($page, $apply = false, $phraseur = NULL, $doctype = '', $charset = null)
{
    if (is_null($charset)) {
        $charset = $GLOBALS['meta']['charset'];
    }
    if ($apply) {
        ob_start();
        if (is_array($apply)) {
            $r = call_user_func_array($page, $apply);
        } else {
            $r = $page();
        }
        $page = ob_get_contents();
        ob_end_clean();
        // fonction sans aucun "echo", ca doit etre le resultat
        if (!$page) {
            $page = $r;
        }
    }
    if (!$page) {
        return '';
    }
    // charger la DTD et transcoder les entites,
    // et escamoter le doctype que sax mange en php5 mais pas en  php4
    if (!$doctype) {
        if (!($r = analyser_doctype($page))) {
            $page = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE . preg_replace(_REGEXP_DOCTYPE, '', $page);
            $r = analyser_doctype($page);
        }
        list($entete, $avail, $grammaire, $rotlvl) = array_pad($r, 4, null);
        $page = substr($page, strlen($entete));
    } else {
        $avail = 'SYSTEM';
        $grammaire = $doctype;
        $rotlvl = basename($grammaire);
    }
    include_spip('xml/analyser_dtd');
    $dtc = charger_dtd($grammaire, $avail, $rotlvl);
    $page = sax_bug($page, $dtc, $charset);
    // compatibilite Tidy espace public
    if (!$phraseur) {
        $indenter_xml = charger_fonction('indenter', 'xml');
        return $indenter_xml($page, $apply);
    }
    $xml_parser = xml_parser_create($charset);
    xml_set_element_handler($xml_parser, array($phraseur, "debutElement"), array($phraseur, "finElement"));
    xml_set_character_data_handler($xml_parser, array($phraseur, "textElement"));
    xml_set_processing_instruction_handler($xml_parser, array($phraseur, 'piElement'));
    xml_set_default_handler($xml_parser, array($phraseur, "defaultElement"));
    xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
    $phraseur->sax = $xml_parser;
    if (isset($entete)) {
        $phraseur->entete = $entete;
    }
    $phraseur->page = $page;
    $phraseur->dtc = $dtc;
    $phraseur->phraserTout($xml_parser, $page);
    xml_parser_free($xml_parser);
    $phraseur->sax = '';
    return $phraseur;
}
Esempio n. 2
0
File: sax.php Progetto: rhertzog/lcs
function sax_bug($data)
{
	$r = analyser_doctype($data);

	if (!$r) {
		$data = _MESSAGE_DOCTYPE . _DOCTYPE_ECRIRE
		. preg_replace(_REGEXP_DOCTYPE, '', $data);
		$r =  analyser_doctype($data);
	}

	list($doctype, $topelement, $avail, $grammaire, $rotlvl, $len) = $r;

	include_spip('xml/analyser_dtd');
	$dtc = charger_dtd($grammaire, $avail, $rotlvl);

	// l'entete contient eventuellement < ? xml... ? >, le Doctype, 
	// et des commentaires autour d'eux
	$entete = ltrim(substr($data,0,$len));

	if ($dtc) {
		$trans = array();
		
		foreach($dtc->entites as $k => $v) {
			if (!strpos(" amp lt gt quot ", $k))
			    $trans["&$k;"] = $v;
		}
		$data = strtr(substr($data,$len), $trans);
	} else {
		$data = html2unicode(substr($data,$len), true);
	}
	return array($entete,unicode2charset($data), $dtc);
}