コード例 #1
0
ファイル: Attributes.php プロジェクト: rafalenden/KioCMS
 private function prepareAttribute(PHPTAL_Php_CodeWriter $codewriter, $qname, $expression)
 {
     $tales_code = $this->extractEchoType($expression);
     $code = $codewriter->evaluateExpression($tales_code);
     // XHTML boolean attribute does not appear when empty or false
     if (PHPTAL_Dom_Defs::getInstance()->isBooleanAttribute($qname)) {
         // I don't want to mix code for boolean with chained executor
         // so compile it again to simple expression
         if (is_array($code)) {
             $code = PHPTAL_Php_TalesInternal::compileToPHPExpression($tales_code);
         }
         return $this->prepareBooleanAttribute($codewriter, $qname, $code);
     }
     // if $code is an array then the attribute value is decided by a
     // tales chained expression
     if (is_array($code)) {
         return $this->prepareChainedAttribute($codewriter, $qname, $code);
     }
     // i18n needs to read replaced value of the attribute, which is not possible if attribute is completely replaced with conditional code
     if ($this->phpelement->hasAttributeNS('http://xml.zope.org/namespaces/i18n', 'attributes')) {
         $this->prepareAttributeUnconditional($codewriter, $qname, $code);
     } else {
         $this->prepareAttributeConditional($codewriter, $qname, $code);
     }
 }
コード例 #2
0
ファイル: Defs.php プロジェクト: indynagpal/MateCat
 /**
  * this is a singleton
  */
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new PHPTAL_Dom_Defs();
     }
     return self::$_instance;
 }
コード例 #3
0
ファイル: XmlnsState.php プロジェクト: jeko/pksworld
 /** 
  * Returns a new XmlnsState inheriting of $currentState if $nodeAttributes contains 
  * xmlns attributes, returns $currentState otherwise.
  *
  * This method is used by the PHPTAL parser to keep track of xmlns fluctuation for
  * each encountered node.
  */
 public static function newElement(PHPTAL_Dom_XmlnsState $currentState, $nodeAttributes)
 {
     $aliases = array();
     foreach ($nodeAttributes as $att => $value) {
         if (PHPTAL_Dom_Defs::getInstance()->isHandledXmlNs($att, $value)) {
             preg_match('/^xmlns:(.*?)$/', $att, $m);
             list(, $alias) = $m;
             $aliases[$alias] = PHPTAL_Dom_Defs::getInstance()->xmlnsToLocalName($value);
         }
     }
     if (count($aliases) > 0) {
         // inherit aliases with maybe an overwrite
         $aliases = array_merge($currentState->_aliases, $aliases);
         return new PHPTAL_Dom_XmlnsState($aliases);
     }
     return $currentState;
 }
コード例 #4
0
ファイル: CDATASection.php プロジェクト: ShaeS/Pine-Birch
 public function generateCode(PHPTAL_Php_CodeWriter $codewriter)
 {
     $mode = $codewriter->getOutputMode();
     $value = $this->getValueEscaped();
     $inCDATAelement = PHPTAL_Dom_Defs::getInstance()->isCDATAElementInHTML($this->parentNode->getNamespaceURI(), $this->parentNode->getLocalName());
     // in HTML5 must limit it to <script> and <style>
     if ($mode === PHPTAL::HTML5 && $inCDATAelement) {
         $codewriter->pushHTML($codewriter->interpolateCDATA(str_replace('</', '<\\/', $value)));
     } elseif ($mode === PHPTAL::XHTML && $inCDATAelement || $mode === PHPTAL::XML && preg_match('/[<>&]/', $value) || $mode !== PHPTAL::HTML5 && preg_match('/<\\?|\\${structure/', $value)) {
         // in text/html "</" is dangerous and the only sensible way to escape is ECMAScript string escapes.
         if ($mode === PHPTAL::XHTML) {
             $value = str_replace('</', '<\\/', $value);
         }
         $codewriter->pushHTML($codewriter->interpolateCDATA('<![CDATA[' . $value . ']]>'));
     } else {
         $codewriter->pushHTML($codewriter->interpolateHTML(htmlspecialchars($value, ENT_QUOTES, $codewriter->getEncoding())));
     }
 }
コード例 #5
0
 function filterDOM(PHPTAL_Dom_Element $element)
 {
     $defs = PHPTAL_Dom_Defs::getInstance();
     foreach ($element->childNodes as $node) {
         if ($node instanceof PHPTAL_Dom_Comment) {
             if ($defs->isCDATAElementInHTML($element->getNamespaceURI(), $element->getLocalName())) {
                 $textNode = new PHPTAL_Dom_CDATASection($node->getValueEscaped(), $node->getEncoding());
                 $node->parentNode->replaceChild($textNode, $node);
             } else {
                 $node->parentNode->removeChild($node);
             }
         } else {
             if ($node instanceof PHPTAL_Dom_Element) {
                 $this->filterDOM($node);
             }
         }
     }
 }
コード例 #6
0
ファイル: Attributes.php プロジェクト: jeko/pksworld
 private function prepareAttribute($attribute, $expression)
 {
     $code = $this->extractEchoType(trim($expression));
     $code = $this->tag->generator->evaluateExpression($code);
     // if $code is an array then the attribute value is decided by a
     // tales chained expression
     if (is_array($code)) {
         return $this->prepareChainedAttribute2($attribute, $code);
     }
     // XHTML boolean attribute does not appear when empty of false
     if (PHPTAL_Dom_Defs::getInstance()->isBooleanAttribute($attribute)) {
         return $this->prepareBooleanAttribute($attribute, $code);
     }
     // i18n needs to read replaced value of the attribute, which is not possible if attribute is completely replaced with conditional code
     if ($this->tag->hasAttribute('i18n:attributes')) {
         $this->prepareAttributeUnconditional($attribute, $code);
     } else {
         $this->prepareAttributeConditional($attribute, $code);
     }
 }
コード例 #7
0
ファイル: Attributes.php プロジェクト: alicam/vanilla-theme
 private function prepareAttribute($attribute, $expression)
 {
     $code = $this->extractEchoType(trim($expression));
     $code = $this->tag->generator->evaluateExpression($code);
     // if $code is an array then the attribute value is decided by a
     // tales chained expression
     if (is_array($code)) {
         return $this->prepareChainedAttribute2($attribute, $code);
     }
     // XHTML boolean attribute does not appear when empty of false
     if (PHPTAL_Dom_Defs::getInstance()->isBooleanAttribute($attribute)) {
         return $this->prepareBooleanAttribute($attribute, $code);
     }
     // regular attribute which value is the evaluation of $code
     $attkey = self::ATT_VALUE_REPLACE . $this->getVarName($attribute);
     if ($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE) {
         $value = $code;
     } else {
         $value = $this->tag->generator->escapeCode($code);
     }
     $this->tag->generator->doSetVar($attkey, $value);
     $this->tag->overwriteAttributeWithPhpValue($attribute, $attkey);
 }
コード例 #8
0
ファイル: Element.php プロジェクト: indynagpal/MateCat
 private function orderTalAttributes(array $talAttributes)
 {
     $temp = array();
     foreach ($talAttributes as $key => $domattr) {
         $nsattr = PHPTAL_Dom_Defs::getInstance()->getNamespaceAttribute($domattr->getNamespaceURI(), $domattr->getLocalName());
         if (array_key_exists($nsattr->getPriority(), $temp)) {
             throw new PHPTAL_TemplateException(sprintf("Attribute conflict in < %s > '%s' cannot appear with '%s'", $this->qualifiedName, $key, $temp[$nsattr->getPriority()][0]->getNamespace()->getPrefix() . ':' . $temp[$nsattr->getPriority()][0]->getLocalName()), $this->getSourceFile(), $this->getSourceLine());
         }
         $temp[$nsattr->getPriority()] = array($nsattr, $domattr);
     }
     ksort($temp);
     $this->talHandlers = array();
     foreach ($temp as $prio => $dat) {
         list($nsattr, $domattr) = $dat;
         $handler = $nsattr->createAttributeHandler($this, $domattr->getValue());
         $this->talHandlers[$prio] = $handler;
         if ($nsattr instanceof PHPTAL_NamespaceAttributeSurround) {
             $this->surroundAttributes[] = $handler;
         } else {
             if ($nsattr instanceof PHPTAL_NamespaceAttributeReplace) {
                 $this->replaceAttributes[] = $handler;
             } else {
                 if ($nsattr instanceof PHPTAL_NamespaceAttributeContent) {
                     $this->contentAttributes[] = $handler;
                 } else {
                     throw new PHPTAL_ParserException("Unknown namespace attribute class " . get_class($nsattr), $this->getSourceFile(), $this->getSourceLine());
                 }
             }
         }
     }
 }
コード例 #9
0
ファイル: Defs.php プロジェクト: jeko/pksworld
 public static function setInstance(PHPTAL_Dom_Defs $instance)
 {
     self::$_instance = $instance;
 }
コード例 #10
0
ファイル: TAL.php プロジェクト: jeko/pksworld
require_once PHPTAL_DIR . 'PHPTAL/Namespace.php';
require_once PHPTAL_DIR . 'PHPTAL/Php/Attribute/TAL/Comment.php';
require_once PHPTAL_DIR . 'PHPTAL/Php/Attribute/TAL/Replace.php';
require_once PHPTAL_DIR . 'PHPTAL/Php/Attribute/TAL/Content.php';
require_once PHPTAL_DIR . 'PHPTAL/Php/Attribute/TAL/Condition.php';
require_once PHPTAL_DIR . 'PHPTAL/Php/Attribute/TAL/Attributes.php';
require_once PHPTAL_DIR . 'PHPTAL/Php/Attribute/TAL/Repeat.php';
require_once PHPTAL_DIR . 'PHPTAL/Php/Attribute/TAL/Define.php';
require_once PHPTAL_DIR . 'PHPTAL/Php/Attribute/TAL/OnError.php';
require_once PHPTAL_DIR . 'PHPTAL/Php/Attribute/TAL/OmitTag.php';
/**
 * @package phptal.namespace
 */
class PHPTAL_Namespace_TAL extends PHPTAL_BuiltinNamespace
{
    public function __construct()
    {
        parent::__construct('tal', 'http://xml.zope.org/namespaces/tal');
        $this->addAttribute(new PHPTAL_NamespaceAttributeSurround('define', 4));
        $this->addAttribute(new PHPTAL_NamespaceAttributeSurround('condition', 6));
        $this->addAttribute(new PHPTAL_NamespaceAttributeSurround('repeat', 8));
        $this->addAttribute(new PHPTAL_NamespaceAttributeContent('content', 11));
        $this->addAttribute(new PHPTAL_NamespaceAttributeReplace('replace', 9));
        $this->addAttribute(new PHPTAL_NamespaceAttributeSurround('attributes', 9));
        $this->addAttribute(new PHPTAL_NamespaceAttributeSurround('omit-tag', 0));
        $this->addAttribute(new PHPTAL_NamespaceAttributeSurround('comment', 12));
        $this->addAttribute(new PHPTAL_NamespaceAttributeSurround('on-error', 2));
    }
}
PHPTAL_Dom_Defs::getInstance()->registerNamespace(new PHPTAL_Namespace_TAL());
コード例 #11
0
ファイル: XmlnsState.php プロジェクト: jo-m/ecamp3
 public function isHandledNamespace($namespace_uri)
 {
     return PHPTAL_Dom_Defs::getInstance()->isHandledNamespace($namespace_uri);
 }
コード例 #12
0
ファイル: Node.php プロジェクト: jeko/pksworld
 private function orderTalAttributes()
 {
     $attributes = array();
     foreach ($this->talAttributes as $key => $exp) {
         $name = $this->xmlns->unAliasAttribute($key);
         $att = PHPTAL_Dom_Defs::getInstance()->getNamespaceAttribute($name);
         if (array_key_exists($att->getPriority(), $attributes)) {
             $err = sprintf(self::ERR_ATTRIBUTES_CONFLICT, $this->name, $this->getSourceLine(), $key, $attributes[$att->getPriority()][0]);
             throw new PHPTAL_TemplateException($err);
         }
         $attributes[$att->getPriority()] = array($key, $att, $exp);
     }
     ksort($attributes);
     $this->talHandlers = array();
     foreach ($attributes as $prio => $dat) {
         list($key, $att, $exp) = $dat;
         $handler = $att->createAttributeHandler($this, $exp);
         $this->talHandlers[$prio] = $handler;
         if ($att instanceof PHPTAL_NamespaceAttributeSurround) {
             $this->surroundAttributes[] = $handler;
         } else {
             if ($att instanceof PHPTAL_NamespaceAttributeReplace) {
                 $this->replaceAttributes[] = $handler;
             } else {
                 if ($att instanceof PHPTAL_NamespaceAttributeContent) {
                     $this->contentAttributes[] = $handler;
                 } else {
                     throw new PHPTAL_ParserException("Unknown namespace attribute class " . get_class($att));
                 }
             }
         }
     }
 }
コード例 #13
0
ファイル: Ztal.php プロジェクト: namesco/ztal
 /**
  * Called after an action is dispatched by Zend_Controller_Dispatcher.
  *
  * @param Zend_Controller_Request_Abstract $request The request object.
  *
  * @return void
  */
 public function preDispatch(\Zend_Controller_Request_Abstract $request)
 {
     parent::preDispatch($request);
     // register the ztal namespace
     \PHPTAL_Dom_Defs::getInstance()->registerNamespace(new \Ztal\Tal\Ns\ZTAL());
 }
コード例 #14
0
 /**
  * register cake namespace
  */
 protected function _registerNamespace()
 {
     $defs = PHPTAL_Dom_Defs::getInstance();
     /* @var $defs PHPTAL_Dom_Defs */
     if (isset($this->_namespaceCake) || $defs->isHandledNamespace(Cake_PHPTAL_Namespace_Cake::NAMESPACE_URI)) {
         return;
     }
     $this->_namespaceCake = new Cake_PHPTAL_Namespace_Cake();
     $defs->registerNamespace($this->_namespaceCake);
 }