Beispiel #1
0
 /**
  * The main Lex parser method.  Essentially acts as dispatcher to
  * all of the helper parser methods.
  *
  * @param  string       $text     Text to parse
  * @param  array|object $data     Array or object to use
  * @param  mixed        $callback Callback to use for Callback Tags
  * @return string
  */
 public function parse($text, $data = array(), $callback = false, $allowPhp = false)
 {
     $this->setupRegex();
     $this->allowPhp = $allowPhp;
     // Is this the first time parse() is called?
     if (self::$data === null) {
         // Let's store the local data array for later use.
         self::$data = $data;
     } else {
         // Let's merge the current data array with the local scope variables
         // So you can call local variables from within blocks.
         $data = array_merge(self::$data, $data);
         // Since this is not the first time parse() is called, it's most definately a callback,
         // let's store the current callback data with the the local data
         // so we can use it straight after a callback is called.
         self::$callbackData = $data;
     }
     // The parseConditionals method executes any PHP in the text, so clean it up.
     if (!$allowPhp) {
         $text = str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $text);
     }
     $text = $this->extractNoparse($text);
     $text = $this->parseComments($text);
     $text = $this->extractLoopedTags($text, $data, $callback);
     // Order is important here.  We parse conditionals first as to avoid
     // unnecessary code from being parsed and executed.
     $text = $this->parseConditionals($text, $data, $callback);
     $text = $this->injectExtractions($text, 'looped_tags');
     $text = $this->parseVariables($text, $data, $callback);
     $text = $this->injectExtractions($text, 'callback_blocks');
     if ($callback) {
         $text = $this->parseCallbackTags($text, $data, $callback);
     }
     // To ensure that {{ noparse }} is never parsed even during consecutive parse calls
     // set $cumulativeNoparse to true and use self::injectNoparse($text); immediately
     // before the final output is sent to the browser
     if (!$this->cumulativeNoparse) {
         $text = $this->injectExtractions($text);
     }
     // no callback callback, hack to get tag pairs with parameters to work
     if (strstr($text, "{{")) {
         $text = $this->parseCallbackTags($text, $data, null);
     }
     return $text;
 }
 /**
  * The main Lex parser method.  Essentially acts as dispatcher to
  * all of the helper parser methods.
  *
  * @param  string        $text      Text to parse
  * @param  array|object  $data      Array or object to use
  * @param  mixed         $callback  Callback to use for Callback Tags
  * @param  boolean       $allowPhp  Should we allow PHP?
  * @return string
  */
 public function parse($text, $data = array(), $callback = false, $allowPhp = false)
 {
     // <statamic>
     // before we get started, make sure there are tags that need parsing
     if (strpos($text, '{{') === false) {
         return $text;
     }
     // </statamic>
     // <statamic>
     // use : as scope-glue
     $this->scopeGlue = ':';
     // </statamic>
     $this->setupRegex();
     $this->allowPhp = $allowPhp;
     // Is this the first time parse() is called?
     if (self::$data === null) {
         // Let's store the local data array for later use.
         self::$data = $data;
     } else {
         // Let's merge the current data array with the local scope variables
         // So you can call local variables from within blocks.
         // <statamic>
         // data should never have numeric keys, so using union operator as it's faster
         $data = $data + self::$data;
         // </statamic>
         // Since this is not the first time parse() is called, it's most definitely a callback,
         // let's store the current callback data with the the local data
         // so we can use it straight after a callback is called.
         self::$callbackData = $data;
         // <statamic>
         // Save the original text coming in so that we can parse it recursively
         // later on without this needing to be within a callback
         self::$original_text = $text;
         // </statamic>
     }
     // The parseConditionals method executes any PHP in the text, so clean it up.
     if (!$allowPhp) {
         $text = str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $text);
     }
     // <statamic>
     // reverse the order of no-parse and commenting
     $text = $this->extractNoparse($text);
     $text = $this->parseComments($text);
     // </statamic>
     $text = $this->extractLoopedTags($text, $data, $callback);
     // Order is important here.  We parse conditionals first as to avoid
     // unnecessary code from being parsed and executed.
     $text = $this->parseConditionals($text, $data, $callback);
     $text = $this->injectExtractions($text, 'looped_tags');
     $text = $this->parseVariables($text, $data, $callback);
     $text = $this->injectExtractions($text, 'callback_blocks');
     if ($callback) {
         $text = $this->parseCallbackTags($text, $data, $callback);
     }
     // To ensure that {{ noparse }} is never parsed even during consecutive parse calls
     // set $cumulativeNoparse to true and use self::injectNoparse($text); immediately
     // before the final output is sent to the browser
     if (!$this->cumulativeNoparse) {
         $text = $this->injectExtractions($text);
     }
     // <statamic>
     // get tag-pairs with parameters to work
     if (strpos($text, "{{") !== false) {
         $text = $this->parseCallbackTags($text, $data, null);
     }
     // </statamic>
     return $text;
 }