コード例 #1
0
ファイル: parse.php プロジェクト: nob/joi
 /**
  * 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);
 }
コード例 #2
0
 public function route($uri)
 {
     $uri = '/' . uri_string();
     /* if it's the home page then change url to /home-page */
     if ($uri == '/') {
         $uri = '/' . setting('cms-page.Home Page', 'home-page');
     }
     ci()->load->model('c_page_model');
     /* catalog caches the data */
     $catalog = ci()->c_page_model->active_urls();
     $record = null;
     $routes = array_keys($catalog);
     foreach ($routes as $route) {
         $pattern = '#^' . str_replace('*', '(.*)', $route) . '$#';
         if (preg_match($pattern, $uri)) {
             $record = $catalog[$route];
             break;
         }
     }
     if (!$record) {
         show_404($uri, true);
     }
     /* load the template model so we can find the templates html */
     ci()->load->model('c_templates_model');
     ci()->load->library('lex_plugin');
     ci()->load->helper('cms');
     /* we send it into the lex parser */
     $parser = new Lex\Parser();
     /* final output */
     ci()->output->set_output($parser->parse(ci()->c_templates_model->get_by_id($record->template_id), ci()->load->get_vars(), 'lex_plugin::_callback'));
 }
コード例 #3
0
ファイル: content.php プロジェクト: nob/joi
 /**
  * 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;
 }
コード例 #4
0
 public function parse($template, $extra = [])
 {
     /* parse with lex */
     $parser = new Lex\Parser();
     $data = $this->get_variables($extra);
     /* first round */
     foreach ($data as $key => $value) {
         if (is_scalar($value)) {
             $template = str_replace('{{' . $key . '}}', $value, $template);
         }
     }
     /* heavy lifter */
     return $parser->parse($template, $data);
 }
コード例 #5
0
ファイル: semantic.php プロジェクト: Excellerate/plg_semantic
 /**
  * Accordian Module
  *
  * Use within article:
  *
  * {{ accordion }}
  * {{ title active="true" }} What Are Weevils title? {{/title}}
  * {{ content active="true" }} This is what are Weevils content {{/content}}
  * {{ /accordion }}
  *
  */
 private function accordion($text)
 {
     // Fire up new lex
     $parser = new Lex\Parser();
     $data[] = $parser->parse($text, array(), function ($name, $attrs, $content) {
         // Check for active accordian
         if (isset($attrs['active']) and $attrs['active'] == true) {
             $active = "active ";
         }
         // Switch between title and content
         switch ($name) {
             case 'title':
                 return '<div class="' . (isset($active) ? $active : null) . 'title"><i class="dropdown icon"></i>' . strip_tags(trim($content)) . '</div>';
             case 'content':
                 return '<div class="' . (isset($active) ? $active : null) . 'content">' . trim($content) . '</div>';
         }
     });
     // Join each accordian
     $data = array('<div class="ui accordion">', implode($data), '</div>');
     // Return combined data
     return implode($data);
 }
コード例 #6
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)
 {
     return parent::parse($text, $data, $callback, $allow_php);
 }
コード例 #7
0
ファイル: theme.php プロジェクト: nob/joi
 /**
  * Returns a given $template parsed with given $data
  *
  * @param string  $template  Template to parse
  * @param array  $data  Associative array of data to fill into template
  * @return string
  */
 public static function getParsedTemplate($template, array $data = array())
 {
     $parser = new Lex\Parser();
     $template_path = Config::getTemplatesPath() . '/templates/' . ltrim($template, '/') . '.html';
     return $parser->parse(File::get($template_path, ""), $data, FALSE);
 }
コード例 #8
0
 protected function merge($file, $data)
 {
     $parser = new Lex\Parser();
     $template = $parser->parse(file_get_contents(__DIR__ . '/../../views/' . $file . '.tmpl'), $data);
     return str_replace('&lt;?php', '<?php', $template);
 }
コード例 #9
0
ファイル: theme.php プロジェクト: Synergy23/blackandwhite
 /**
  * Returns a given $template parsed with given $data
  *
  * @param string  $template  Template to parse
  * @param array  $data  Associative array of data to fill into template
  * @return string
  */
 public static function getParsedTemplate($template, array $data = array())
 {
     $parser = new Lex\Parser();
     $template_path = Config::getTemplatesPath() . '/templates/' . ltrim($template, '/') . '.html';
     return $parser->parse(File::get($template_path, ""), $data, array('statamic_view', 'callback'), Config::get('_allow_php', false));
 }
コード例 #10
0
ファイル: view.php プロジェクト: nob/joi
 /**
  * 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;
 }