/** * Processes the opt:dynamic node. * @internal * @param Opt_Xml_Node $node The recognized node. */ public function processNode(Opt_Xml_Node $node) { // Add capturing the content for the caching purposes $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, '$this->_outputBuffer[] = ob_get_contents();'); $node->addAfter(Opt_Xml_Buffer::TAG_AFTER, ' ob_start(); '); // Inform the compiler to store this piece of compiled // template in an extra file, where it will be accessible // to the caching system. $node->set('dynamic', true); $this->_process($node); }
/** * Processes the opt:content attribute. * @internal * @param Opt_Xml_Node $node The node with the attribute * @param Opt_Xml_Attribute $attr The recognized attribute. */ public function processAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr) { $result = $this->_compiler->compileExpression($attr->getValue(), false, Opt_Compiler_Class::ESCAPE_BOTH); if ($result[2] == true) { // The expression is a single variable that can be handled in a simple way. $node->addAfter(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, 'if(empty(' . $result[3] . ')){ '); $node->addAfter(Opt_Xml_Buffer::TAG_CONTENT_AFTER, '} else { echo ' . $result[0] . '; } '); } else { // In more complex expressions, we store the result to a temporary variable. $node->addAfter(Opt_Xml_Buffer::TAG_CONTENT_BEFORE, ' $_cont' . $this->_nesting . ' = ' . $result[0] . '; if(empty($_cont' . $this->_nesting . ')){ '); $node->addAfter(Opt_Xml_Buffer::TAG_CONTENT_AFTER, '} else { echo $_cont' . $this->_nesting . '; } '); } $this->_nesting++; $attr->set('postprocess', true); }
/** * Adds the PHP code with dependencies to the code buffers in the tree * root node. * * @internal * @param Opt_Xml_Node $tree The tree root node. */ protected function _addDependencies($tree) { // OK, there is really some info to include! $list = ''; foreach ($this->_dependencies as $a) { $list .= '\'' . $a . '\','; } $tree->addBefore(Opt_Xml_Buffer::TAG_BEFORE, 'if(!$this->_massPreprocess($compileTime, array(' . $list . '))){ '); $tree->addAfter(Opt_Xml_Buffer::TAG_AFTER, ' }else{ $compileTime = $this->_compile($this->_template, $mode); require(__FILE__); } '); }
/** * Processes the opt:attributes-build and opt:attributes-ignore attributes. * @internal * @param Opt_Xml_Element $node The node * @param Opt_Xml_Attribute $attr The attribute to process */ public function processAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr) { if ($attr->getName() == 'attributes-build') { $ignoreList = $node->getAttribute('opt:attributes-ignore'); if ($ignoreList instanceof Opt_Xml_Attribute) { $ignore = $this->_compiler->compileExpression($ignoreList->getValue(), false, Opt_Compiler_Class::ESCAPE_OFF); $ignore = $ignore[0]; } else { $ignore = 'array()'; } $expression = $this->_compiler->compileExpression($attr->getValue(), false, Opt_Compiler_Class::ESCAPE_OFF); $node->addAfter(Opt_Xml_Buffer::TAG_ENDING_ATTRIBUTES, 'echo Opt_Function::buildAttributes(' . $expression[0] . ', ' . $ignore . ', \' \'); '); } }
/** * Finalizes the processing of the opt:if and opt:omit-tag attributes. * @internal * @param Opt_Xml_Node $node The node with the attribute * @param Opt_Xml_Attribute $attr The recognized attribute. */ public function postprocessAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr) { $expr = $this->_compiler->compileExpression((string) $attr, false, Opt_Compiler_Class::ESCAPE_OFF); $node->addBefore(Opt_Xml_Buffer::TAG_BEFORE, ' if(' . $expr[0] . '){ '); $node->addAfter(Opt_Xml_Buffer::TAG_AFTER, ' } '); }
/** * Processes the opt:capture attribute. * @internal * @param Opt_Xml_Node $node The node with the attribute * @param Opt_Xml_Attribute $attr The recognized attribute. */ public function processAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr) { if ($this->_compiler->isIdentifier($attr->getValue())) { $node->addAfter(Opt_Xml_Buffer::TAG_BEFORE, 'ob_start(); '); $node->addBefore(Opt_Xml_Buffer::TAG_AFTER, 'self::$_capture[\'' . $attr->getValue() . '\'] = ob_get_clean();'); $this->_process($node); } else { throw new Opt_InvalidAttributeType_Exception('opt:capture', 'identifier'); } }
/** * Processes the opt:empty-item tag. * @internal * @param Opt_Xml_Element $node The recognized node. */ protected function _processEmptyItem(Opt_Xml_Node $node) { if (is_null($node->get('priv:section'))) { throw new Opt_InstructionInvalidLocation_Exception('opt:item', 'opt:grid'); } $section = $node->get('priv:section'); $node->addAfter(Opt_Xml_Buffer::TAG_BEFORE, ' if($_' . $section['name'] . '_remain > 0 && !' . $section['format']->get('section:valid') . ') { for($_' . $section['name'] . '_k = 0; $_' . $section['name'] . '_k < $_' . $section['name'] . '_remain; $_' . $section['name'] . '_k++) { '); $node->addBefore(Opt_Xml_Buffer::TAG_AFTER, ' } } '); $this->_process($node); }