Esempio n. 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, $allow_php = false)
 {
     $this->setup_regex();
     $this->allow_php = $allow_php;
     // Is this the first time parse() is called?
     if (Lex_Parser::$data === null) {
         // Let's store the local data array for later use.
         Lex_Parser::$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(Lex_Parser::$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.
         Lex_Parser::$callback_data = $data;
     }
     // The parse_conditionals method executes any PHP in the text, so clean it up.
     if (!$allow_php) {
         $text = str_replace(array('<?', '?>'), array('&lt;?', '?&gt;'), $text);
     }
     $text = $this->parse_comments($text);
     $text = $this->extract_noparse($text);
     $text = $this->extract_looped_tags($text, $data, $callback);
     // Order is important here.  We parse conditionals first as to avoid
     // unnecessary code from being parsed and executed.
     $text = $this->parse_conditionals($text, $data, $callback);
     $text = $this->inject_extractions($text, 'looped_tags');
     $text = $this->parse_variables($text, $data, $callback);
     $text = $this->inject_extractions($text, 'callback_blocks');
     if ($callback) {
         //$text = $this->parse_variables($text, $data, $callback);
         $text = $this->parse_callback_tags($text, $data, $callback);
     }
     // To ensure that {{ noparse }} is never parsed even during consecutive parse calls
     // set $cumulative_noparse to true and use Lex_Parser::inject_noparse($text); immediately
     // before the final output is sent to the browser
     if (!$this->cumulative_noparse) {
         $text = $this->inject_extractions($text);
     }
     return $text;
 }