コード例 #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
 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);
 }
コード例 #4
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;
 }
コード例 #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
 /**
  * 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);
 }
コード例 #7
0
ファイル: parse.php プロジェクト: Bferreira5/Theme-Example
 /**
  * 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;
 }
コード例 #8
0
 /**
  * Injects noparse extractions.
  *
  * This is so that multiple parses can store noparse
  * extractions and all noparse can then be injected right
  * before data is displayed.
  *
  * @param   string    $text    Text to inject into
  * @return  string
  */
 public static function inject_noparse($text)
 {
     return parent::injectNoparse($text);
 }
コード例 #9
0
ファイル: view.php プロジェクト: zane-insight/WhiteLaceInn
 /**
  * _render_layout
  * Renders the page
  *
  * @param string $_html HTML of the template to use
  * @param string $template_type Content type of the template
  * @return string
  */
 public function _render_layout($_html, $template_type = 'html')
 {
     if (self::$_layout) {
         $this->data['layout_content'] = $_html;
         if ($template_type != 'html' or self::$_control_panel) {
             extract($this->data);
             ob_start();
             require self::$_layout . ".php";
             $html = ob_get_clean();
         } else {
             if (!File::exists(self::$_layout . ".html")) {
                 Log::fatal("Can't find the specified theme.", 'core', 'template');
                 return '<p style="text-align:center; font-size:28px; font-style:italic; padding-top:50px;">We can\'t find your theme files. Please check your settings.';
             }
             $this->appendNewData($this->data);
             // Fetch layout and parse any front matter
             $layout = Parse::frontMatter(File::get(self::$_layout . '.html'), false);
             $html = Parse::template($layout['content'], Statamic_View::$_dataStore, array($this, 'callback'));
             $html = Lex\Parser::injectNoparse($html);
         }
     } else {
         $html = $_html;
     }
     // post-render hook
     $html = \Hook::run('_render', 'after', 'replace', $html, $html);
     return $html;
 }
コード例 #10
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);
 }
コード例 #11
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);
 }
コード例 #12
0
 /**
  * Sets up all the global regex to use the correct Scope Glue.
  *
  * @return void
  */
 public function setupRegex()
 {
     return parent::setupRegex();
 }
コード例 #13
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));
 }
コード例 #14
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;
 }
コード例 #15
0
ファイル: view.php プロジェクト: jeffreyDcreative/gkp
 /**
  * _render_layout
  * Renders the page
  *
  * @param string $_html HTML of the template to use
  * @param string $template_type Content type of the template
  * @return string
  */
 public function _render_layout($_html, $template_type = 'html')
 {
     if (self::$_layout != '') {
         $this->data['layout_content'] = $_html;
         $layout_path = Path::assemble(BASE_PATH, Config::getTemplatesPath(), self::$_layout);
         if ($template_type != 'html' or self::$_control_panel) {
             extract($this->data);
             ob_start();
             require $layout_path . ".php";
             $html = ob_get_clean();
         } else {
             if (!File::exists($layout_path . ".html")) {
                 Log::fatal("Can't find the specified theme.", 'core', 'template');
                 return '<p style="text-align:center; font-size:28px; font-style:italic; padding-top:50px;">We can\'t find your theme files. Please check your settings.';
             }
             $this->mergeNewData($this->data);
             $html = Parse::template(File::get($layout_path . ".html"), Statamic_View::$_dataStore, array($this, 'callback'));
             $html = Lex\Parser::injectNoparse($html);
         }
     } else {
         $html = $_html;
     }
     // post-render hook
     $html = \Hook::run('_render', 'after', 'replace', $html, $html);
     return $html;
 }