Пример #1
0
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->push(new TextField($this->attributes['index']));
     return $fields;
 }
Пример #2
0
 public function executeTag($tag, $token)
 {
     if ($tag->attributes) {
         foreach ($tag->attributes as $key => $value) {
             preg_match_all('/#\\s*([^#]+)\\s*#/', $value, $matches, PREG_SET_ORDER);
             foreach ($matches as $match) {
                 $var = $match[1];
                 if (isset(CFML::$variables[$match[1]])) {
                     $replacement =& CFML::$variables[$match[1]];
                 } elseif (CFML::$fallback instanceof ViewableData && CFML::$fallback->hasMethod($match[1])) {
                     $replacement = CFML::$fallback->{$var}();
                 } elseif (CFML::$fallback instanceof ViewableData && CFML::$fallback->hasField($var)) {
                     $replacement = CFML::$fallback->getField($var);
                 } else {
                     continue;
                     //throw new CFML_Parser_Exception("Undefined variable {$match[1]}");
                 }
                 if ($tag->attributes[$key] == $match[1]) {
                     $tag->attributes[$key] =& $replacement;
                 } else {
                     $tag->attributes[$key] = str_replace($match[0], $replacement, $tag->attributes[$key]);
                 }
             }
         }
     }
     switch ($token['mode']) {
         case 'start':
             CFMLTag::$current_tag = $tag;
             return $tag->open();
         case 'end':
             $ret = $tag->close();
             CFMLTag::$current_tag = null;
             return $ret;
         case 'selfclosing':
             CFMLTag::$current_tag = $tag;
             $ret = $tag->execute();
             CFMLTag::$current_tag = null;
             return $ret;
     }
 }
Пример #3
0
 public function parse($tokens, $mode = 'runtime')
 {
     if ($mode == 'admin') {
         $fields = new FieldSet();
     }
     if ($mode == 'tags') {
         $tags = array();
     }
     self::$tokens = $tokens;
     ob_start();
     while (self::$tokenIndex < count($tokens)) {
         if (isset($token)) {
             unset($token);
         }
         $token = $tokens[self::$tokenIndex];
         $tag = CFMLTag::createFromToken($token);
         if (!$tag) {
             throw new CFML_Method_Exception("Tag not recognised: {$token['tag']}");
         }
         if (($mode == 'admin' || $mode == 'tags') && $token['type'] == 'tag') {
             $token['type'] = 'admin';
             if ($token['mode'] == 'end') {
                 self::$tokenIndex++;
                 continue;
             }
         }
         if ($token['type'] == 'tag') {
             switch ($token['mode']) {
                 case 'start':
                     ob_start();
                     $tag->startIndex = self::$tokenIndex;
                     self::$tagStack[] = $tag;
                     break;
                 case 'end':
                     $tag->startTag = array_pop(self::$tagStack);
                     $tag->tagScope =& $tag->startTag->tagScope;
                     $tag->generatedContent = ob_get_clean();
                     if ($tag->startTag->name != $tag->name) {
                         throw new CFML_Syntax_Exception("Tag nesting error - Expected </{$token['startTag']['tag']}> but found </{$token['tag']}>");
                     }
                     break;
             }
             $this->executeTag($tag, $token);
             if ($tag->generatedContent) {
                 echo $tag->generatedContent;
             }
         } elseif ($token['type'] == 'admin') {
             if ($mode == 'tags') {
                 // Get all tags in the template for decoding by another script
                 $tags[] = $tag;
             } else {
                 // Get CMS form fields for all tags in the template
                 $tagFields = $tag->getCMSFields();
                 if ($tagFields && $tagFields->Count()) {
                     foreach ($tagFields as $tagField) {
                         $fields->push($tagField);
                     }
                 }
             }
         } else {
             preg_match_all('/#\\s*(\\w+)\\s*#/', $token['text'], $matches, PREG_SET_ORDER);
             foreach ($matches as $match) {
                 $var = $match[1];
                 $replacement = '';
                 if (isset(CFML::$variables[$match[1]])) {
                     $replacement =& CFML::$variables[$match[1]];
                 } elseif (is_a(CFML::$fallback, 'ViewableData') && CFML::$fallback->hasMethod($var)) {
                     $replacement = CFML::$fallback->{$var}();
                 } elseif (is_a(CFML::$fallback, 'ViewableData') && CFML::$fallback->hasField($var)) {
                     $replacement = CFML::$fallback->getField($var);
                 }
                 $token['text'] = str_replace($match[0], $replacement, $token['text']);
             }
             if ($this->suppressWhiteSpace) {
                 echo trim($token['text']);
             } else {
                 echo $token['text'];
             }
         }
         self::$tokenIndex++;
     }
     if ($mode == 'admin') {
         ob_end_clean();
         return $fields;
     } elseif ($mode == 'tags') {
         ob_end_clean();
         return $tags;
     } else {
         return ob_get_clean();
     }
 }
Пример #4
0
 public function parse($tokens, $mode = 'runtime')
 {
     if ($mode == 'admin') {
         $fields = new FieldSet();
     }
     self::$tokens = $tokens;
     ob_start();
     while (self::$tokenIndex < count($tokens)) {
         if (isset($token)) {
             unset($token);
         }
         $token = $tokens[self::$tokenIndex];
         $tag = CFMLTag::createFromToken($token);
         if (!$tag) {
             throw new CFML_Method_Exception("Tag not recognised: {$token['tag']}");
         }
         if ($mode == 'admin') {
             if ($token['type'] == 'tag') {
                 $token['type'] = 'admin';
             }
         }
         if ($token['type'] == 'tag') {
             switch ($token['mode']) {
                 case 'start':
                     ob_start();
                     $tag->startIndex = self::$tokenIndex;
                     self::$tagStack[] = $tag;
                     break;
                 case 'end':
                     $tag->parentTag = array_pop(self::$tagStack);
                     $tag->tagScope =& $tag->parentTag->tagScope;
                     $tag->generatedContent = ob_get_clean();
                     if ($tag->parentTag->name != $tag->name) {
                         throw new CFML_Syntax_Exception("Tag nesting error - Expected </{$token['parenttag']['tag']}> but found </{$token['tag']}>");
                     }
                     break;
             }
             $this->executeTag($tag, $token);
             if ($tag->generatedContent) {
                 echo $tag->generatedContent;
             }
         } elseif ($token['type'] == 'admin') {
             // Ghetto scaffolder
             $tagFields = $tag->getCMSFields();
             if ($tagFields && $tagFields->Count()) {
                 foreach ($tagFields as $tagField) {
                     $fields->push($tagField);
                 }
             }
         } else {
             preg_match_all('/#\\s*([^#]+)\\s*#/', $token['text'], $matches, PREG_SET_ORDER);
             foreach ($matches as $match) {
                 if (isset(CFML::$variables[$match[1]])) {
                     $replacement =& CFML::$variables[$match[1]];
                 } else {
                     throw new CFML_Parser_Exception("Undefined variable {$match[1]}");
                 }
                 $token['text'] = str_replace($match[0], $replacement, $token['text']);
             }
             if ($this->suppressWhiteSpace) {
                 echo trim($token['text']);
             } else {
                 echo $token['text'];
             }
         }
         self::$tokenIndex++;
     }
     if ($mode == 'admin') {
         return $fields;
     } else {
         return ob_get_clean();
     }
 }
Пример #5
0
 public function close()
 {
     self::$current_tag = null;
 }