Exemplo 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)
 {
     // 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;
 }
 /**
  * Streams content parse
  *
  * Special content parser for streams. This accomplishes the following
  * important functions:
  *
  * a. Takes care of legacy multiple relationship parsing
  * b. Finds and formats special plugin fields
  *
  * @access	public
  * @param	string - the tag content
  * @param	array - the return data
  * @param	string - stream slug
  * @param 	string - stream namespace
  * @param 	[bool - whether or not to loop through the results or not]
  * @param 	[mixed - null or obj - stream fields. If they are availble, it will
  * 				save a mysql query.]
  * @param 	string [$id_name] The name of the id we want to pass via 'row_id'. This is almost alway 'id'
  * @return 	string - the parsed data
  */
 public function parse_tag_content($content, $data, $stream_slug, $stream_namespace, $loop = false, $fields = null, $id_name = 'id')
 {
     // -------------------------------------
     // Legacy multiple relationship provision
     // -------------------------------------
     // We should respect our elders. This makes
     // sure older instances of multiple
     // relationships won't break. We can probably
     // remove this after PyroCMS 2.2
     // -------------------------------------
     $rep = array('{{ streams_core:related', '{{streams_core:related');
     $content = str_replace($rep, '{{ streams:related stream="' . $stream_slug . '" base_namespace="' . $stream_namespace . '" entry=id ', $content);
     $rep = array('{{ streams_core:multiple', '{{streams_core:multiple');
     $content = str_replace($rep, '{{ streams_core:multiple stream="' . $stream_slug . '" base_namespace="' . $stream_namespace . '" entry=id ', $content);
     // -------------------------------------
     // Make sure we have our stream fields
     // -------------------------------------
     if (is_null($fields)) {
         $stream = $this->stream_obj($stream_slug, $stream_namespace);
         $fields = $this->CI->streams_m->get_stream_fields($stream->id);
     }
     // -------------------------------------
     // Custom Call Provision
     // -------------------------------------
     // Go through the fields for this stream, and
     // see if any of them have the magic 'plugin_override'
     // function. This will allow us to call functions
     // from within the field type itself.
     // -------------------------------------
     if ($fields) {
         foreach ($fields as $field) {
             if (method_exists($this->CI->type->types->{$field->field_type}, 'plugin_override')) {
                 $content = preg_replace('/\\{\\{\\s?' . $field->field_slug . '\\s?/', '{{ streams_core:field row_id="{{ ' . $id_name . ' }}" stream_slug="' . $stream_slug . '" field_slug="' . $field->field_slug . '" namespace="' . $stream_namespace . '" field_type="' . $field->field_type . '" ', $content);
                 $content = preg_replace('/\\{\\{\\s?\\/' . $field->field_slug . '\\s?\\}\\}/', '{{ /streams_core:field }}', $content);
             }
         }
     }
     // -------------------------------------
     // Parse
     // -------------------------------------
     $parser = new Lex_Parser();
     $parser->scope_glue(':');
     $parser->cumulative_noparse(true);
     if (!$loop) {
         return $parser->parse($content, $data, array($this->CI->parser, 'parser_callback'));
     }
     $out = '';
     foreach ($data as $item) {
         $out .= $parser->parse($content, $item, array($this->CI->parser, 'parser_callback'));
     }
     return $out;
 }
Exemplo 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, $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;
 }