Exemplo n.º 1
0
 /**
  * Compiles the XML attribute which may contain some dynamic data.
  * The method automatically recognizes the registered expression
  * engine and launches it.
  *
  * @param Opt_Xml_Attribute $attr The attribute to parse.
  */
 public function compileAttribute(Opt_Xml_Attribute $attr)
 {
     $value = $attr->getValue();
     if (preg_match('/^([a-zA-Z0-9\\_]+)\\:([^\\:].*)$/', $value, $found)) {
         switch ($found[1]) {
             case 'parse':
                 $result = $this->parseExpression($found[2], $found[1], self::ESCAPE_ON, $this->_tpl->attributeModifier);
                 $attr->addAfter(Opt_Xml_Buffer::ATTRIBUTE_VALUE, 'echo ' . $result['expression'] . '; ');
                 break;
             case 'str':
                 $result = $this->parseExpression($found[2], $found[1], self::ESCAPE_ON, $this->_tpl->attributeModifier);
                 $attr->addAfter(Opt_Xml_Buffer::ATTRIBUTE_VALUE, 'echo ' . $result['escaped'] . '; ');
                 break;
             case null:
                 $attr->setValue($found[2]);
                 break;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * 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 . ', \' \'); ');
     }
 }
Exemplo n.º 4
0
 /**
  * Creates a new section record, using the information from the specified node.
  * If the node is not a valid OPT instruction, the method scans the ancestors
  * to find a free opt:show node.
  *
  * The method can also initialize the attributed section, if we provide the
  * opt:section attribute object as the second argument.
  *
  * The method initializes also the neighbourhood of the section by parsing the
  * opt:show tag, if necessary and creating the enter condition. Note that it
  * does not start the section - the record is neither put onto the section stack
  * nor opt:use integration is not made. You have to use _sectionStart() in order
  * to fully initialize the section.
  *
  * @param Opt_Xml_Element $node
  * @param Opt_Xml_Attribute $attr optional
  * @param Array $extraAttributes optional
  * @return Array The section record.
  */
 protected function _sectionCreate(Opt_Xml_Element $node, $attr = NULL, $extraAttributes = NULL)
 {
     /* First, we need to determine, whether the section is associated with
      * opt:show. In case of tag sections, this is done only if the node
      * does not contain any section attributes.
      */
     $show = NULL;
     if ($attr instanceof Opt_Xml_Attribute) {
         $show = $this->_findShowNode($node, $attr->getValue());
         if (!is_null($show)) {
             // In this case we can obtain the attributes from opt:show.
             $section = $this->_extractSectionAttributes($show, $extraAttributes);
             $section['show'] = $show;
             $section['node'] = $node;
             $section['attribute'] = $attr;
         } else {
             // Generate a default section record, using the $attr value and
             // optionally checking for the "separator" attribute in the current node.
             $_params = array('separator' => array(0 => self::OPTIONAL, self::EXPRESSION, NULL));
             $this->_extractAttributes($node, $_params);
             $section = array('name' => $attr->getValue(), 'order' => 'asc', 'parent' => NULL, 'datasource' => NULL, 'display' => NULL, 'separator' => $_params['separator'], 'show' => null, 'node' => $node, 'attribute' => $attr);
         }
     } else {
         if (is_null($node->getAttribute('name'))) {
             // We must look for opt:show
             $show = $this->_findShowNode($node);
             if (is_null($show)) {
                 throw new Opt_AttributeNotDefined_Exception('name', $node->getXmlName());
             }
             $section = $this->_extractSectionAttributes($show, $extraAttributes);
             $section['show'] = $show;
             $section['node'] = $node;
             $section['attribute'] = null;
         } else {
             $section = $this->_extractSectionAttributes($node, $extraAttributes);
             $section['show'] = null;
             $section['node'] = $node;
             $section['attribute'] = null;
         }
     }
     $this->_validateSection($section);
     if (is_null($section['show'])) {
         $this->_createShowCondition($node, $section);
     } elseif (is_null($section['show']->get('priv:initialized'))) {
         $this->_createShowCondition($section['show'], $section);
     }
     // A faster way to obtain the section name associated with this section.
     $node->set('priv:section', $section['name']);
     return $section;
 }
Exemplo n.º 5
0
 /**
  * Processes the opt:use attribute.
  *
  * @internal
  * @param Opt_Xml_Node $node The node the attribute is added to
  * @param Opt_Xml_Attribute $attr The found attribute.
  */
 public function processAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr)
 {
     if (isset($this->_snippets[$attr->getValue()])) {
         array_push($this->_current, $attr->getValue());
         $snippet =& $this->_snippets[$attr->getValue()];
         // Move all the stuff to the fake node.
         if ($node->hasChildren()) {
             $newNode = new Opt_Xml_Element('opt:_');
             $newNode->moveChildren($node);
             $size = sizeof($snippet);
             $snippet[$size] = $newNode;
             $attr->set('snippetObj', $snippet);
             $attr->set('size', $size);
         }
         $node->removeChildren();
         // Process the snippets
         $node->set('escaping', $this->_compiler->get('escaping'));
         $this->_compiler->set('escaping', $snippet[0]->get('escaping'));
         foreach ($snippet[0] as $subnode) {
             $node->appendChild(clone $subnode);
         }
         $node->set('call:use', $attr->getValue());
         $attr->set('postprocess', true);
     }
 }
Exemplo n.º 6
0
 /**
  * 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');
     }
 }
Exemplo n.º 7
0
 /**
  * Postprocesses the opt:single instruction attribute.
  *
  * @internal
  * @param Opt_Xml_Node $node XML node.
  * @param Opt_Xml_Attribute $attr XML attribute.
  */
 public function postprocessAttribute(Opt_Xml_Node $node, Opt_Xml_Attribute $attr)
 {
     if ($attr->getValue() == 'yes') {
         $node->set('single', true);
         $node->removeChildren();
     }
 }