<?php class TalBlock_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//tal:block'; } public function handleMatch($node) { while ($node->firstChild) { $node->parentNode->insertBefore($node->firstChild, $node); } $node->parentNode->removeChild($node); } } PXHTML::registerNS('tal', 'http://xml.zope.org/namespaces/tal'); PXHTML::registerHandler('TalBlock_PXHTMLNode', PXHTMLTemplate::TAL_BLOCK);
<?php class MetalPxhtmlIsMacro_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//*[@metal:pxhtml-is-macro]'; } // remove attr public function handleMatch($node) { $node->removeAttributeNS('http://xml.zope.org/namespaces/metal', 'pxhtml-is-macro'); $node->removeAttributeNS('http://xml.zope.org/namespaces/metal', 'pxhtml-macro-id'); } } PXHTML::registerNS('metal', 'http://xml.zope.org/namespaces/metal'); PXHTML::registerHandler('MetalPxhtmlIsMacro_PXHTMLNode', PXHTMLTemplate::MACRO_ANALYSIS + 5);
$c = $this->createLocalVariable(); $str = $this->processTales($attr, $c . ' = (%s) ? TRUE : FALSE;', TRUE); $str .= 'if (' . $c . ') {'; $php_inst_st = $this->createProcessingInstruction($str); $php_inst_ed = $this->createProcessingInstruction('} unset(' . $c . ');'); // if around the opening omit tag $node->parentNode->insertBefore($php_inst_st, $node); if ($node->firstChild) { $node->insertBefore($php_inst_ed, $node->firstChild); } else { $node->appendChild($php_inst_ed); } // new pair of tags $c = $this->createLocalVariable(); $str = $this->processTales($attr, $c . ' = (%s) ? TRUE : FALSE;', TRUE); $str .= 'if (' . $c . ') {'; $php_inst_st_closing = $this->createProcessingInstruction($str); $php_inst_ed_closing = $this->createProcessingInstruction('} unset(' . $c . ');'); // if around the closing omit tag $node->appendChild($php_inst_st_closing); if ($node->nextSibling) { $node->parentNode->insertBefore($php_inst_ed_closing, $node->nextSibling); } else { $node->parentNode->appendChild($php_inst_ed_closing); } $node->removeAttributeNS('http://xml.zope.org/namespaces/tal', 'omit-tag'); } } PXHTML::registerNS('tal', 'http://xml.zope.org/namespaces/tal'); PXHTML::registerHandler('TalOmitTag_PXHTMLNode', PXHTMLTemplate::TAL_OMIT);
class ChipInclude_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//chip:include'; } public function handleMatch($node) { $PXHTMLTemplate = new PXHTMLTemplate(); $xtn = $node->getAttribute('xtn') ? '.' . $node->getAttribute('xtn') : '.php'; $cdata = $node->getAttribute('cdata') ? $node->getAttribute('cdata') : FALSE; $dom = $PXHTMLTemplate->parse(chip($node->getAttribute('file'))->getFilePath() . $xtn, TRUE, $cdata); // collect all things under the PXHTML root in new_dom, and // attach them as an appendChild statement $xpath = new DOMXPath($dom); $results = $xpath->query('/pxhtml:root'); $results = $results->item(0)->firstChild; // transfer all of the nodes from the include into the document at the include point while ($results) { $new_node = $this->importNode($results); $node->parentNode->insertBefore($new_node, $node); $results = $results->nextSibling; } $node->parentNode->removeChild($node); } } PXHTML::registerNS('pxhtml', 'http://xml.felocity.com/namespaces/pxhtml'); PXHTML::registerNS('chip', 'http://xml.felocity.com/namespaces/chip'); PXHTML::registerHandler('ChipInclude_PXHTMLNode', PXHTMLTemplate::PREPROCESSING_COMPLETE);
<?php class HTMLScript_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//script'; } public function handleMatch($node) { if (!$node->firstChild) { $node->appendChild($this->createTextNode('')); // empty text node creates w3c compliance } } } // PXHTML::registerNS('metal', 'http://xml.zope.org/namespaces/metal'); PXHTML::registerHandler('HTMLScript_PXHTMLNode', PXHTMLTemplate::HTML_COMPLIANCE);
public function handleMatch($node) { // $define_slot_results = $this->query('//*[@metal:define-slot]'); // for ($i = 0; $i < $define_slot_results->length; $i++) { // $define_slot = $define_slot_results->item($i); // $define_slot->setAttributeNS('http://xml.zope.org/namespaces/metal', // 'metal:define-slot', // $node->getAttribute('metal:define-macro').'-'.md5($node->getAttribute('metal:define-macro')).'-'.$define_slot->getAttribute('metal:define-slot') // ); // } $define_macro = ''; $p = $node->parentNode; while ($p && !$p instanceof DOMDocument) { if ($p->getAttributeNS('http://xml.zope.org/namespaces/metal', 'pxhtml-is-macro')) { $define_macro = $p->getAttributeNS('http://xml.zope.org/namespaces/metal', 'pxhtml-is-macro'); $p = FALSE; } else { $p = $p->parentNode; } } if (!$define_macro) { return; } $node->setAttributeNS('http://xml.zope.org/namespaces/metal', 'metal:define-slot', $define_macro . '---' . $node->getAttributeNS('http://xml.zope.org/namespaces/metal', 'define-slot')); // give the define slot a metal:chip-is-define-macro // $node->setAttributeNS('http://xml.zope.org/namespaces/metal', 'metal:pxhtml-is-define-macro', 'true'); } } PXHTML::registerNS('metal', 'http://xml.zope.org/namespaces/metal'); PXHTML::registerHandler('MetalDefineSlot_PXHTMLNode', PXHTMLTemplate::MACRO_ANALYSIS + 1);
<?php class HTMLTextArea_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//textarea'; } public function handleMatch($node) { if (!$node->firstChild) { $node->appendChild($this->createTextNode('')); // empty text node creates w3c compliance } } } // PXHTML::registerNS('metal', 'http://xml.zope.org/namespaces/metal'); PXHTML::registerHandler('HTMLTextArea_PXHTMLNode', PXHTMLTemplate::HTML_COMPLIANCE);
$local = FALSE; if (strpos($attr, 'local ') === 0) { $attr = trim(substr($attr, 6)); $local = TRUE; } elseif (strpos($attr, 'global ') === 0) { $attr = trim(substr($attr, 7)); } list($var, $as) = explode(' ', $attr, 2); if (!$local) { $as = $this->processTales($as, 'PXHTMLTemplate::ctx()->setRoot("' . $var . '", %s);'); $php_inst = $this->createProcessingInstruction($as); $node->parentNode->insertBefore($php_inst, $node); } else { $start = $this->processTales($as, 'PXHTMLTemplate::ctx()->set("' . $var . '", %s);'); $php_start = $this->createProcessingInstruction($start); $node->parentNode->insertBefore($php_start, $node); $end = 'PXHTMLTemplate::ctx()->delete("' . $var . '");'; $php_end = $this->createProcessingInstruction($end); if ($node->nextSibling) { $node->parentNode->insertBefore($php_end, $node->nextSibling); } else { $node->parentNode->appendChild($php_end); } } } $node->removeAttributeNS('http://xml.zope.org/namespaces/tal', 'define'); } } PXHTML::registerNS('tal', 'http://xml.zope.org/namespaces/tal'); PXHTML::registerHandler('TalDefine_PXHTMLNode', PXHTMLTemplate::TAL_DEFINE);
// if (stripos($attr, 'not:') === 0) { // $attr = trim(substr($attr, 4)); // $not = TRUE; // } // // // convert the tales expression into a php statement // $c = $this->createLocalVariable(); // $str = 'try {'; // $str .= $this->processTales($attr, $c.' = (%s) ? TRUE : FALSE;', TRUE); // $str .= '} catch (Exception $e) { '.$c.' = FALSE; }'; // // if ($not) { // $str .= 'if (!('.$c.')) {'; // } // else { // $str .= 'if ('.$c.') {'; // } // $php_inst_st = $this->createProcessingInstruction($str); // $php_inst_ed = $this->createProcessingInstruction('} unset('.$c.');'); $node->parentNode->insertBefore($php_inst_st, $node); if ($node->nextSibling) { $node->parentNode->insertBefore($php_inst_ed, $node->nextSibling); } else { $node->parentNode->appendChild($php_inst_ed); } $node->removeAttributeNS('http://xml.zope.org/namespaces/tal', 'tal:condition'); } } PXHTML::registerNS('tal', 'http://xml.zope.org/namespaces/tal'); PXHTML::registerHandler('TalCondition_PXHTMLNode', PXHTMLTemplate::TAL_CONDITION);
<?php class MetalDefineMacro_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//*[@metal:define-macro]'; } // inside of every define-macro, prefix all define-slot with // macro prefix public function handleMatch($node) { $node->parentNode->removeChild($node); } } PXHTML::registerNS('metal', 'http://xml.zope.org/namespaces/metal'); PXHTML::registerHandler('MetalDefineMacro_PXHTMLNode', PXHTMLTemplate::MACRO_ANALYSIS + 3);
if (strpos($param->getAttribute('value'), ' ') === FALSE) { $input_type = "string"; $key = $param->getAttribute('value'); } else { list($input_type, $key) = explode(' ', $param->getAttribute('value'), 2); } switch ($param->getAttribute('source')) { case 'request': $value = 'chipi("#Chippino/Request/GetRequest")->with(array("' . $key . '" => "' . $input_type . '"))->' . $key; // $value = '"'.$result[$key].'"'; break; case 'url': $value = '"' . (isset($this->route['segments'][$key]) ? $this->route['segments'][$key] : '') . '"'; break; case 'local': default: $value = '"' . $param->getAttribute('value') . '"'; break; } $params .= '"' . $param->getAttribute('name') . '" => ' . $value . ', '; } $reuse_suffix = $reuse ? 'i' : ''; $str = 'PXHTMLTemplate::ctx()->set("' . $as . '", chip' . $reuse_suffix . '("' . $type . '")->with(array(' . $params . ')));'; $php_inst = $this->createProcessingInstruction($str); $node->parentNode->insertBefore($php_inst, $node); $node->parentNode->removeChild($node); } } PXHTML::registerNS('chip', 'http://xml.felocity.com/namespaces/chip'); PXHTML::registerHandler('ChipComponent_PXHTMLNode', PXHTMLTemplate::PROCESSING_COMPLETE);
class ChipFilter_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//*[@chip:filter]'; } public function handleMatch($node) { $attr = $node->getAttributeNS('http://xml.felocity.com/namespaces/chip', 'filter'); // 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); $c = $this->createLocalVariable(); $php_inst_st = $this->createProcessingInstruction('ob_start();'); $php_inst_ed = $this->createProcessingInstruction($c . ' = ob_get_contents(); ob_end_clean(); echo chip("' . $attr . '")->with(array(\'content\' => ' . $c . ')); unset(' . $c . ');'); if ($node->firstChild) { $node->insertBefore($php_inst_st, $node->firstChild); } else { $node->appendChild($php_inst_st); } $node->appendChild($php_inst_ed); } $node->removeAttributeNS('http://xml.felocity.com/namespaces/chip', 'filter'); } } PXHTML::registerNS('chip', 'http://xml.felocity.com/namespaces/chip'); PXHTML::registerHandler('ChipFilter_PXHTMLNode', PXHTMLTemplate::TAL_OMIT);
$ct = 0; } return $ct++; } // inside of every define-macro, prefix all define-slot with // macro prefix public function handleMatch($node) { $node->setAttributeNS('http://xml.zope.org/namespaces/metal', 'metal:pxhtml-is-use-macro', 'true'); $count = $this->getMacroCount(); $node->setAttributeNS('http://xml.zope.org/namespaces/metal', 'metal:pxhtml-macro-id', $count); // collect matching define-macro $define_macro_results = $this->query('//*[@metal:define-macro="' . $node->getAttributeNS('http://xml.zope.org/namespaces/metal', 'use-macro') . '"]'); for ($i = 0; $i < $define_macro_results->length; $i++) { // clone the matching define-macro // strip the "define-macro" attribute // add a unique metal ns "_is-macro" $old_define_macro = $define_macro_results->item($i); $define_macro = $old_define_macro->cloneNode(TRUE); $define_macro->setAttributeNS('http://xml.zope.org/namespaces/metal', 'metal:pxhtml-is-macro', $define_macro->getAttributeNS('http://xml.zope.org/namespaces/metal', 'define-macro')); $define_macro->setAttributeNS('http://xml.zope.org/namespaces/metal', 'metal:pxhtml-macro-id', $count); $define_macro->removeAttributeNS('http://xml.zope.org/namespaces/metal', 'define-macro'); $define_macro->removeAttributeNS('http://xml.zope.org/namespaces/metal', 'pxhtml-is-define-macro'); // insert the new node right before the use-macro call $node->parentNode->insertBefore($define_macro, $node); } } } PXHTML::registerNS('metal', 'http://xml.zope.org/namespaces/metal'); PXHTML::registerHandler('MetalUseMacro_PXHTMLNode', PXHTMLTemplate::MACRO_ANALYSIS);
return '//*[@tal:content]'; } public function handleMatch($node) { if ($node->getAttributeNS('http://xml.zope.org/namespaces/tal', 'replace')) { throw new Exception('no content and replace'); } $attr = $node->getAttributeNS('http://xml.zope.org/namespaces/tal', 'content'); // clean the insides of the node while ($node->firstChild) { $node->removeChild($node->firstChild); } $c = $this->createLocalVariable(); $structure = false; if (strpos($attr, 'structure ') === 0) { $structure = true; $attr = trim(substr($attr, 9)); } $str = $this->processTales($attr, $c . ' = %s;'); if ($structure) { $php_inst = $this->createProcessingInstruction($str . 'echo ' . $c . '; unset(' . $c . ');'); } else { $php_inst = $this->createProcessingInstruction($str . 'echo htmlspecialchars(' . $c . '); unset(' . $c . ');'); } $node->appendChild($php_inst); $node->removeAttributeNS('http://xml.zope.org/namespaces/tal', 'content'); } } PXHTML::registerNS('tal', 'http://xml.zope.org/namespaces/tal'); PXHTML::registerHandler('TalContent_PXHTMLNode', PXHTMLTemplate::TAL_CONTENT_REPLACE);
{ public function getMatchXPath() { return '//*[@tal:replace]'; } public function handleMatch($node) { if ($node->getAttributeNS('http://xml.zope.org/namespaces/tal', 'content')) { throw new Exception('no content and replace'); } $attr = $node->getAttributeNS('http://xml.zope.org/namespaces/tal', 'replace'); $c = $this->createLocalVariable(); if (strpos($attr, ' ') === FALSE) { $str = $this->processTales($attr, $c . ' = %s;'); $php_inst = $this->createProcessingInstruction('echo htmlspecialchars(' . $c . '); unset(' . $c . ');'); } else { list($type, $attr) = explode(' ', $attr, 2); if (strtolower($type) === 'structure') { $str = $this->processTales($attr, $c . ' = %s;'); $php_inst = $this->createProcessingInstruction('echo ' . $c . '; unset(' . $c . ');'); } else { throw new Exception('unknown type for content/replace'); } } $node->parentNode->insertBefore($php_inst, $node); $node->parentNode->removeChild($node); } } PXHTML::registerNS('tal', 'http://xml.zope.org/namespaces/tal'); PXHTML::registerHandler('TalReplace_PXHTMLNode', PXHTMLTemplate::TAL_CONTENT_REPLACE);
<?php class ChipHeader_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//chip:header'; } public function handleMatch($node) { $replace = strtolower($node->getAttribute('replace')) == "false" ? FALSE : TRUE; while ($node->firstChild) { if ($node->firstChild->nodeType == XML_TEXT_NODE) { $str = 'header(trim("' . $node->firstChild->wholeText . '")."\\n\\n", ' . $replace . ');'; $php_inst_st = $this->createProcessingInstruction($str); $node->parentNode->insertBefore($php_inst_st, $node); } $node->removeChild($node->firstChild); } $node->parentNode->removeChild($node); } } PXHTML::registerNS('chip', 'http://xml.felocity.com/namespaces/chip'); PXHTML::registerHandler('ChipHeader_PXHTMLNode', PXHTMLTemplate::PROCESSING_COMPLETE);
} public function handleMatch($node) { $attr = $node->getAttributeNS('http://xml.zope.org/namespaces/tal', 'repeat'); if (strpos($attr, ' ') === FALSE) { throw new Exception(' attr misdefined'); } list($var, $as) = explode(' ', $attr, 2); $c = $this->createLocalVariable(); $str = $this->processTales($as, $c . ' = %s;'); $str .= 'PXHTMLTemplate::ctx()->stack(); PXHTMLTemplate::ctx()->set("COUNT", 1); if (is_array(' . $c . ')) foreach(' . $c . ' as $rc) {'; $str .= 'PXHTMLTemplate::ctx()->set("' . $var . '", $rc); unset($rc);'; $str .= 'PXHTMLTemplate::ctx()->set("EVEN", (PXHTMLTemplate::ctx()->resolve("COUNT") % 2 == 0) ? "even" : "");'; $str .= 'PXHTMLTemplate::ctx()->set("FIRST", (PXHTMLTemplate::ctx()->resolve("COUNT") === 1) ? "first" : "");'; $str .= 'PXHTMLTemplate::ctx()->set("LAST", (PXHTMLTemplate::ctx()->resolve("COUNT") === count(' . $c . ')) ? "last" : "");'; $str_ed = 'PXHTMLTemplate::ctx()->set("COUNT", PXHTMLTemplate::ctx()->resolve("COUNT") + 1);'; $str_ed .= '} unset(' . $c . '); PXHTMLTemplate::ctx()->unstack();'; $php_inst_st = $this->createProcessingInstruction($str); $php_inst_ed = $this->createProcessingInstruction($str_ed); $node->parentNode->insertBefore($php_inst_st, $node); if ($node->nextSibling) { $node->parentNode->insertBefore($php_inst_ed, $node->nextSibling); } else { $node->parentNode->appendChild($php_inst_ed); } $node->removeAttributeNS('http://xml.zope.org/namespaces/tal', 'repeat'); } } PXHTML::registerNS('tal', 'http://xml.zope.org/namespaces/tal'); PXHTML::registerHandler('TalRepeat_PXHTMLNode', PXHTMLTemplate::TAL_REPEAT);
<?php class ChipRedirect_PXHTMLNode extends PXHTMLNode { public function getMatchXPath() { return '//chip:redirect'; } public function handleMatch($node) { $url = $node->getAttribute('url') ? $node->getAttribute('url') : 'false'; $type = intval($node->getAttribute('type')) ? $node->getAttribute('type') : '302'; $c = $this->createLocalVariable(); $str = $this->processTales($url, $c . ' = %s;'); $str = $str . 'header("Location: ' . $c . '\\n\\n"); exit;'; $php_inst_st = $this->createProcessingInstruction($str); $node->parentNode->insertBefore($php_inst_st, $node); $node->parentNode->removeChild($node); } } PXHTML::registerNS('chip', 'http://xml.felocity.com/namespaces/chip'); PXHTML::registerHandler('ChipRedirect_PXHTMLNode', PXHTMLTemplate::PROCESSING_COMPLETE);
public function getMatchXPath() { return '//*[@tal:attributes]'; } 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'); } } PXHTML::registerNS('tal', 'http://xml.zope.org/namespaces/tal'); PXHTML::registerHandler('TalAttributes_PXHTMLNode', PXHTMLTemplate::TAL_ATTRIBUTES);
} if (!$parent->parentNode) { throw new Exception('no parent2'); } $parent = $parent->parentNode; } if (!$found) { throw new Exception('no use-macro found'); } $target = $parent->getAttributeNS('http://xml.zope.org/namespaces/metal', 'use-macro') . '---' . $node->getAttributeNS('http://xml.zope.org/namespaces/metal', 'fill-slot'); $macro_id = $parent->getAttributeNS('http://xml.zope.org/namespaces/metal', 'pxhtml-macro-id'); // now, find all matching chip-is-macro => metal-define-slot matches $q = '//*[@metal:pxhtml-is-macro][@metal:pxhtml-macro-id="' . $macro_id . '"]//*[@metal:define-slot="' . $target . '"]'; $results = $this->query($q); // for each match, replace the contents of define-slot with fill-slot // remove the define-slot attribute for ($i = 0; $i < $results->length; $i++) { $destination = $results->item($i); while ($destination->firstChild) { $destination->removeChild($destination->firstChild); } while ($node->firstChild) { $destination->appendChild($node->firstChild); } $destination->removeAttributeNS('http://xml.zope.org/namespaces/metal', 'define-slot'); } } } PXHTML::registerNS('metal', 'http://xml.zope.org/namespaces/metal'); PXHTML::registerHandler('MetalFillSlot_PXHTMLNode', PXHTMLTemplate::MACRO_ANALYSIS + 2);