Esempio n. 1
0
 /**
  *  Parse
  *
  * Parses pseudo-variables contained in the specified template,
  * replacing them with the data in the second param
  *
  * @access	protected
  * @param	string
  * @param	array
  * @param	bool
  * @return	string
  */
 protected function _parse($string, $data, $return = false, $is_include = false, $streams_parse = array())
 {
     // Start benchmark
     $this->_ci->benchmark->mark('parse_start');
     // Convert from object to array
     is_array($data) or $data = (array) $data;
     $data = array_merge($data, $this->_ci->load->_ci_cached_vars);
     Lex_Autoloader::register();
     if ($streams_parse and isset($streams_parse['stream']) and isset($streams_parse['namespace'])) {
         // In some very rare cases (mainly in the pages module), we need to
         // change the field that is being passed to plugin_override() as row_id.
         // This is where that happens.
         $id_name = (isset($streams_parse['id_name']) and $streams_parse['id_name']) ? $streams_parse['id_name'] : 'id';
         $this->_ci->load->driver('Streams');
         $parsed = $this->_ci->streams->parse->parse_tag_content($string, $data, $streams_parse['stream'], $streams_parse['namespace'], false, null, $id_name);
     } else {
         $parser = new Lex_Parser();
         $parser->scope_glue(':');
         $parser->cumulative_noparse(true);
         $parsed = $parser->parse($string, $data, array($this, 'parser_callback'));
     }
     // Finish benchmark
     $this->_ci->benchmark->mark('parse_end');
     // Return results or not ?
     if (!$return) {
         $this->_ci->output->append_output($parsed);
         return;
     }
     return $parsed;
 }
Esempio n. 2
0
 /**
  * Parses Template or String and does the Mojo!
  *
  * @param  string  $template  View File or String to Parse
  * @param  array   $data      Array of Data to be Parsed
  * @param  boolean $return
  * @param  boolean $load_view
  * @return mixed
  */
 public function parse($template = '', $data = array(), $return = FALSE, $load_view = TRUE)
 {
     // Ready Set Go!
     $this->ci->benchmark->mark('parse_start');
     // Convert from object to array
     is_array($data) or $data = (array) $data;
     $data = array_merge($data, $this->ci->load->_ci_cached_vars);
     //if load_view is false, we parse the string
     $parseString = $template;
     //else load the view to parse
     if ($load_view) {
         $parseString = $this->ci->load->view($template, $data, TRUE);
     }
     Lex_Autoloader::register();
     $parser = new Lex_Parser();
     $parser->scopeGlue(':');
     $parsed = $parser->parse($parseString, $data, array($this, 'parser_callback'));
     // Time's Up!
     $this->ci->benchmark->mark('parse_end');
     if (!$return) {
         $this->ci->output->append_output($parsed);
         return;
     }
     return $parsed;
 }
Esempio n. 3
0
 /**
  *  Parse
  *
  * Parses pseudo-variables contained in the specified template,
  * replacing them with the data in the second param
  *
  * @access	protected
  * @param	string
  * @param	array
  * @param	bool
  * @return	string
  */
 protected function _parse($string, $data, $return = false, $is_include = false)
 {
     // Start benchmark
     $this->_ci->benchmark->mark('parse_start');
     // Convert from object to array
     is_array($data) or $data = (array) $data;
     $data = array_merge($data, $this->_ci->load->_ci_cached_vars);
     Lex_Autoloader::register();
     $parser = new Lex_Parser();
     $parser->scope_glue(':');
     $parser->cumulative_noparse(true);
     $parsed = $parser->parse($string, $data, array($this, 'parser_callback'));
     // Finish benchmark
     $this->_ci->benchmark->mark('parse_end');
     // Return results or not ?
     if (!$return) {
         $this->_ci->output->append_output($parsed);
         return;
     }
     return $parsed;
 }
Esempio n. 4
0
 /**
  * Registers the Autoloader
  *
  * @return  void
  */
 public static function register()
 {
     self::$load_path = dirname(dirname(__FILE__)) . '/';
     ini_set('unserialize_callback_func', 'spl_autoload_call');
     spl_autoload_register('Lex_Autoloader::load');
 }
Esempio n. 5
0
 /**
  * Main Fizl Function
  *
  * Routes and processes all page requests
  *
  * @access	public
  * @return	void
  */
 public function _remap()
 {
     $this->load->library('Plugin');
     $this->load->library('Parse');
     $this->load->config('fizl');
     include APPPATH . 'libraries/Lex/Autoloader.php';
     Lex_Autoloader::register();
     $this->load->helper(array('file', 'url'));
     // -------------------------------------
     // Site config load
     // -------------------------------------
     $raw_configs = (require_once FCPATH . 'config.php');
     foreach ($config as $key => $var) {
         $this->config->set_item($key, $var);
     }
     // -------------------------------------
     // Configs
     // -------------------------------------
     // We do this first since we need this
     // data
     // -------------------------------------
     $this->vars = array('segment_1' => $this->uri->segment(1), 'segment_2' => $this->uri->segment(2), 'segment_3' => $this->uri->segment(3), 'segment_4' => $this->uri->segment(4), 'segment_5' => $this->uri->segment(5), 'segment_6' => $this->uri->segment(6), 'segment_7' => $this->uri->segment(7), 'current_year' => date('Y'), 'current_url' => current_url(), 'site_url' => site_url(), 'base_url' => $this->config->item('base_url'));
     // Set the site folder as a constant
     define('SITE_FOLDER', $this->config->item('site_folder'));
     // -------------------------------------
     // Look for page
     // -------------------------------------
     // So... does this file exist?
     $segments = $this->uri->segment_array();
     $is_home = FALSE;
     // Blank mean it's the home page, ya hurd?
     if (empty($segments)) {
         $is_home = TRUE;
         $segments = array('index');
     }
     // -------------------------------------
     // Find filename
     // -------------------------------------
     // Is this a folder? If so we are looking for the index
     // file in the folder.
     if (is_dir(SITE_FOLDER . '/' . implode('/', $segments))) {
         $file = 'index';
     } else {
         // Okay let's take a look at the last element
         $file = array_pop($segments);
     }
     // Turn the URL into a file path
     $file_path = SITE_FOLDER;
     if ($segments) {
         $file_path .= '/' . implode('/', $segments);
     }
     // -------------------------------------
     // Find file
     // -------------------------------------
     // We just want two things
     $file_elems = array_slice(explode('.', $file), 0, 2);
     $supported_files = array('html', 'md', 'textile');
     $file_ext = NULL;
     // If there is a file extenison,
     // we just add it here.
     if (count($file_elems) == 2) {
         $file_ext = $file_elems[1];
         $file_path .= '/' . $file;
     } else {
         // Try and find a file to match
         // our URL
         foreach ($supported_files as $ext) {
             if (file_exists($file_path . '/' . $file . '.' . $ext)) {
                 $file_ext = $ext;
                 $file_path .= '/' . $file . '.' . $ext;
                 break;
             }
         }
     }
     // -------------------------------------
     // Set headers
     // -------------------------------------
     if (!$file_ext) {
         // No file for this? Set us a 404
         header('HTTP/1.0 404 Not Found');
         $is_404 = true;
     } else {
         $is_404 = false;
         $this->output->set_content_type('text/html');
     }
     // -------------------------------------
     // Set Template
     // -------------------------------------
     $template = FALSE;
     $template_path = FCPATH . $this->config->item('assets_folder') . '/templates/';
     if ($is_home and is_file($template_path . 'home.html')) {
         $template = read_file($template_path . 'home.html');
     } elseif ($is_404) {
         $template = read_file($template_path . '404.html');
         // Do we have a template for this folder?
     } elseif (is_file($template_path . implode('_', $segments) . '.html')) {
         $template = read_file($template_path . implode('_', $segments) . '.html');
     } elseif (is_file($template_path . 'sub.html')) {
         $template = read_file($template_path . 'sub.html');
     } elseif (is_file($template_path . 'default.html')) {
         $template = read_file($template_path . 'default.html');
     }
     // -------------------------------------
     // Get Content
     // -------------------------------------
     if (!$is_404) {
         $content = read_file($file_path);
         // -------------------------------------
         // Prep content by filetype
         // -------------------------------------
         // .md and .textile get formatted
         // automatically.
         // -------------------------------------
         if ($file_ext == 'md') {
             $content = '{{ format }}' . $content . '{{ /format }}';
         } elseif ($file_ext == 'textile') {
             $content = '{{ format method="textile" }}' . $content . '{{ /format }}';
         }
         // -------------------------------------
         // If we have no template, then
         // we just use the content.
         if (!$template) {
             $template = $content;
         } else {
             // If we have a template, let's be
             // sneakty and add in the content
             // variable manually.
             $template = str_replace(array('{{ content }}', '{{content}}'), $content, $template);
         }
         // Our content is avialble
         $this->vars['content'] = $content;
     }
     // -------------------------------------
     // Prep and Output Content
     // -------------------------------------
     $parser = new Lex_Parser();
     $parser->scope_glue(':');
     echo $parser->parse($template, $this->vars, array($this->parse, 'callback'), true);
 }
Esempio n. 6
0
 /**
  *  Parse
  *
  * Parses short tags contained in the specified template,
  * replacing them with the data in the second param
  *
  * @param string
  * @param array
  * @param bool
  * @return string
  */
 function _parse($string, $data, $return = FALSE, $inject_noparse = FALSE)
 {
     // Convert from object to array
     if (!is_array($data)) {
         $data = (array) $data;
     }
     // Global tags
     $data['site_url'] = trim(site_url(), '/');
     $data['base_url'] = trim(base_url(), '/');
     $data['theme_url'] = trim(theme_url(), '/');
     if ($this->_ci->config->item('global_tags') && is_array($this->_ci->config->item('global_tags'))) {
         $data = array_merge($data, $this->_ci->config->item('global_tags'));
     }
     // Not sure if needed
     // ALERT THIS MAY CAUSE INFINITE LOOP
     $data = array_merge($data, $this->_ci->load->_ci_cached_vars);
     // Lex processing
     Lex_Autoloader::register();
     $parser = new Lex_Parser();
     $parser->scopeGlue(':');
     $parsed = $parser->parse($string, $data, array($this, 'parser_callback'), TRUE);
     if ($inject_noparse) {
         $parsed = Lex_Parser::injectNoparse($parsed);
     }
     // Return results or not ?
     if (!$return) {
         $this->_ci->output->append_output($parsed);
         return;
     }
     return $parsed;
 }