public static function parse($file, $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">') { $tpl = new PXHTMLTemplate(); $xml = '<' . '?xml version="1.0"?' . '>'; $root_regex = '/<\\/?pxhtml:root.*?>/'; return str_replace($xml, $doctype, preg_replace($root_regex, '', PXHTMLTemplate::php()->apply($tpl->parse($file)->saveXML()))); }
public function handleMatch($node) { $attr = $node->getAttributeNS('http://xml.zope.org/namespaces/tal', 'attributes'); // mask ;;, explode on ;, inside loop restore $attr = str_replace(';;', '__DBLSEMI__', $attr); $attr_pieces = explode(';', $attr); foreach ($attr_pieces as $attr) { $attr = str_replace('__DBLSEMI__', ';', $attr); $attr = trim($attr); if (strpos($attr, ' ') === FALSE) { throw new Exception(' attr misdefined'); } list($attr, $as) = explode(' ', $attr, 2); $append = strpos($attr, '+') === FALSE ? '' : $node->getAttribute(trim($attr, '+')) . ' '; $attr = trim($attr, '+'); $c = $this->createLocalVariable(); // we can't put raw PHP into the dom, or it will get escaped $str = $this->processTales($as, $c . ' = %s;'); $php_inst = PXHTMLTemplate::php()->register($str . 'echo htmlspecialchars(' . $c . '); unset(' . $c . ');'); $node->setAttribute($attr, $append . $php_inst); } $node->removeAttributeNS('http://xml.zope.org/namespaces/tal', 'attributes'); }