/** * Parses a template, replacing variables with their values * * @param string $html HTML template to parse * @param array $variables List of variables ($key => $value) to replace into template * @param string $callback Callback to call when done * @return string */ public static function template($html, $variables, $callback = null) { $parser = new \Lex\Parser(); $parser->cumulativeNoparse(TRUE); $allow_php = Config::get('_allow_php', false); return $parser->parse($html, $variables, $callback, $allow_php); }
/** * Parses given $template_data with $data, converts content to $type * * @param string $template_data Template data to parse * @param array $data List of variables to fill in * @param mixed $type Optional content type to render * @return string */ public static function parse($template_data, $data, $type = NULL) { $app = \Slim\Slim::getInstance(); $data = array_merge($data, $app->config); $parser = new Lex\Parser(); $parser->cumulativeNoparse(TRUE); $parse_order = Config::getParseOrder(); if ($parse_order[0] == 'tags') { $output = $parser->parse($template_data, $data); $output = self::transform($output, $type); } else { $output = self::transform($template_data, $type); $output = $parser->parse($output, $data); } return $output; }
/** * Sets the noparse style. Immediate or cumulative. * * @param bool $mode * @return void */ public function cumulativeNoparse($mode) { $this->parser_options['cumulative_noparse'] = $mode; return parent::cumulativeNoparse($mode); }
/** * Parses a template, replacing variables with their values * * @param string $html HTML template to parse * @param array $variables List of variables ($key => $value) to replace into template * @param mixed $callback Callback to call when done * @param array $context Context to use when parsing * @return string */ public static function template($html, $variables, $callback = array('statamic_view', 'callback'), $context = array()) { // start measuring $hash = Debug::markStart('parsing', 'statamic_tmpl'); if (!isset(self::$parsers['template_parser'])) { $parser = new \Lex\Parser(); $parser->cumulativeNoparse(TRUE); self::$parsers['template_parser'] = $parser; } $result = self::$parsers['template_parser']->parse($html, $variables + $context, $callback, Config::get('_allow_php', false)); // end measuring Debug::markEnd($hash); Debug::increment('parses', 'statamic_tmpl'); return $result; }
/** * callback * Attempts to load a plugin? * * @param string $name * @param array $attributes * @param string $content * @return string */ public static function callback($name, $attributes, $content) { $parser = new Lex\Parser(); $parser->cumulativeNoparse(true); $output = null; # single function plugins if (strpos($name, ':') === FALSE) { $plugin = $name; $call = "index"; } else { $pieces = explode(':', $name, 2); # no function exists if (count($pieces) != 2) { return NULL; } $plugin = $pieces[0]; $call = $pieces[1]; } # check the plugin directories $plugin_folders = array('_add-ons/', '_app/core/tags/'); foreach ($plugin_folders as $folder) { if (is_dir($folder . $plugin) && is_file($folder . $plugin . '/pi.' . $plugin . '.php')) { $file = $folder . $plugin . '/pi.' . $plugin . '.php'; break; } elseif (is_file($folder . '/pi.' . $plugin . '.php')) { $file = $folder . '/pi.' . $plugin . '.php'; break; } } # plugin exists if (isset($file)) { require_once $file; $class = 'Plugin_' . $plugin; #formatted properly if (class_exists($class)) { $plug = new $class(); } $output = false; # function exists if (method_exists($plug, $call)) { $plug->attributes = $attributes; $plug->content = $content; $output = $plug->{$call}(); } elseif (class_exists($class) && !method_exists($plug, $call)) { $output = $class::$call(); } if (is_array($output)) { $output = $parser->parse($content, $output, array('Statamic_View', 'callback')); } } return $output; }