示例#1
0
 /**
  * Test :toPlaceholder=`phName` filter
  *
  * @param string $toPlaceholder
  * @param mixed $value
  * @dataProvider providerToPlaceholder
  */
 public function testToPlaceholder($toPlaceholder, $value)
 {
     $this->modx->setPlaceholder('utp', $value);
     $this->tag->set('name', 'utp:toPlaceholder=`' . $toPlaceholder . '`');
     $this->tag->process();
     $this->assertArrayHasKey($toPlaceholder, $this->modx->placeholders);
     if (isset($this->modx->placeholders[$toPlaceholder])) {
         $this->assertEquals($value, $this->modx->placeholders[$toPlaceholder]);
     }
 }
示例#2
0
 /**
  * Processes a modElement tag and returns the result.
  *
  * @param string $tag A full tag string parsed from content.
  * @return mixed The output of the processed element represented by the
  * specified tag.
  */
 public function processTag($tag, $processUncacheable = true)
 {
     $element = null;
     $elementOutput = null;
     $outerTag = $tag[0];
     $innerTag = $tag[1];
     /* collect any nested element tags in the innerTag and process them */
     $this->processElementTags($outerTag, $innerTag, true);
     $outerTag = '[[' . $innerTag . ']]';
     $tagParts = xPDO::escSplit('?', $innerTag, '`', 2);
     $tagName = trim($tagParts[0]);
     $tagPropString = null;
     if (isset($tagParts[1])) {
         $tagPropString = trim($tagParts[1]);
     }
     $token = substr($tagName, 0, 1);
     $tokenOffset = 0;
     $cacheable = true;
     if ($token === '!') {
         if (!$processUncacheable) {
             return $outerTag;
         }
         $cacheable = false;
         $tokenOffset++;
         $token = substr($tagName, $tokenOffset, 1);
     }
     if ($cacheable && $token !== '+') {
         $elementOutput = $this->loadFromCache($outerTag);
     }
     if ($elementOutput === null) {
         switch ($token) {
             case '+':
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 $element = new modPlaceholderTag($this->modx);
                 $element->set('name', $tagName);
                 $element->setTag($outerTag);
                 $elementOutput = $element->process($tagPropString);
                 break;
             case '%':
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 $element = new modLexiconTag($this->modx);
                 $element->set('name', $tagName);
                 $element->setTag($outerTag);
                 $element->setCacheable($cacheable);
                 $elementOutput = $element->process($tagPropString);
                 break;
             case '~':
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 $element = new modLinkTag($this->modx);
                 $element->set('name', $tagName);
                 $element->setTag($outerTag);
                 $element->setCacheable($cacheable);
                 $elementOutput = $element->process($tagPropString);
                 break;
             case '$':
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 if ($element = $this->getElement('modChunk', $tagName)) {
                     $element->set('name', $tagName);
                     $element->setTag($outerTag);
                     $element->setCacheable($cacheable);
                     $elementOutput = $element->process($tagPropString);
                 }
                 break;
             case '*':
                 $tagName = substr($tagName, 1 + $tokenOffset);
                 $nextToken = substr($tagName, 0, 1);
                 if ($nextToken === '#') {
                     $tagName = substr($tagName, 1);
                 }
                 if (is_array($this->modx->resource->_fieldMeta) && in_array($this->realname($tagName), array_keys($this->modx->resource->_fieldMeta))) {
                     $element = new modFieldTag($this->modx);
                     $element->set('name', $tagName);
                     $element->setTag($outerTag);
                     $element->setCacheable($cacheable);
                     $elementOutput = $element->process($tagPropString);
                 } elseif ($element = $this->getElement('modTemplateVar', $tagName)) {
                     $element->set('name', $tagName);
                     $element->setTag($outerTag);
                     $element->setCacheable($cacheable);
                     $elementOutput = $element->process($tagPropString);
                 }
                 break;
             default:
                 $tagName = substr($tagName, $tokenOffset);
                 if ($element = $this->getElement('modSnippet', $tagName)) {
                     $element->set('name', $tagName);
                     $element->setTag($outerTag);
                     $element->setCacheable($cacheable);
                     $elementOutput = $element->process($tagPropString);
                 }
         }
     }
     if ($this->modx->getDebug() === true) {
         $this->modx->log(xPDO::LOG_LEVEL_DEBUG, "Processing {$outerTag} as {$innerTag} using tagname {$tagName}:\n" . print_r($elementOutput, 1) . "\n\n");
         /* $this->modx->cacheManager->writeFile(MODX_BASE_PATH . 'parser.log', "Processing {$outerTag} as {$innerTag}:\n" . print_r($elementOutput, 1) . "\n\n", 'a'); */
     }
     return $elementOutput;
 }