X-Git-Url: http://git.onelab.eu/?p=www-register-wizard.git;a=blobdiff_plain;f=libraries%2FParser.php;h=3d379b2219c7399ec1002b63e2f19f614b381e5e;hp=e276a0d07a55d58e31d9984ab09e032a678c75f7;hb=4afb2fe256f094a1caf6bff14f51c6a88938cc9f;hpb=6907967d36358724c676a7998f55fc34e40c3b21 diff --git a/libraries/Parser.php b/libraries/Parser.php index e276a0d..3d379b2 100644 --- a/libraries/Parser.php +++ b/libraries/Parser.php @@ -1,173 +1,173 @@ -load->view($template, $data, TRUE); - - if ($template == '') - { - return FALSE; - } - - foreach ($data as $key => $val) - { - if (is_array($val)) - { - $template = $this->_parse_pair($key, $val, $template); - } - else - { - $template = $this->_parse_single($key, (string)$val, $template); - } - } - - if ($return == FALSE) - { - $CI->output->append_output($template); - } - - return $template; - } - - // -------------------------------------------------------------------- - - /** - * Set the left/right variable delimiters - * - * @access public - * @param string - * @param string - * @return void - */ - function set_delimiters($l = '{', $r = '}') - { - $this->l_delim = $l; - $this->r_delim = $r; - } - - // -------------------------------------------------------------------- - - /** - * Parse a single key/value - * - * @access private - * @param string - * @param string - * @param string - * @return string - */ - function _parse_single($key, $val, $string) - { - return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); - } - - // -------------------------------------------------------------------- - - /** - * Parse a tag pair - * - * Parses tag pairs: {some_tag} string... {/some_tag} - * - * @access private - * @param string - * @param array - * @param string - * @return string - */ - function _parse_pair($variable, $data, $string) - { - if (FALSE === ($match = $this->_match_pair($string, $variable))) - { - return $string; - } - - $str = ''; - foreach ($data as $row) - { - $temp = $match['1']; - foreach ($row as $key => $val) - { - if ( ! is_array($val)) - { - $temp = $this->_parse_single($key, $val, $temp); - } - else - { - $temp = $this->_parse_pair($key, $val, $temp); - } - } - - $str .= $temp; - } - - return str_replace($match['0'], $str, $string); - } - - // -------------------------------------------------------------------- - - /** - * Matches a variable pair - * - * @access private - * @param string - * @param string - * @return mixed - */ - function _match_pair($string, $variable) - { - if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+?)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) - { - return FALSE; - } - - return $match; - } - -} -// END Parser Class - -/* End of file Parser.php */ +load->view($template, $data, TRUE); + + if ($template == '') + { + return FALSE; + } + + foreach ($data as $key => $val) + { + if (is_array($val)) + { + $template = $this->_parse_pair($key, $val, $template); + } + else + { + $template = $this->_parse_single($key, (string)$val, $template); + } + } + + if ($return == FALSE) + { + $CI->output->append_output($template); + } + + return $template; + } + + // -------------------------------------------------------------------- + + /** + * Set the left/right variable delimiters + * + * @access public + * @param string + * @param string + * @return void + */ + function set_delimiters($l = '{', $r = '}') + { + $this->l_delim = $l; + $this->r_delim = $r; + } + + // -------------------------------------------------------------------- + + /** + * Parse a single key/value + * + * @access private + * @param string + * @param string + * @param string + * @return string + */ + function _parse_single($key, $val, $string) + { + return str_replace($this->l_delim.$key.$this->r_delim, $val, $string); + } + + // -------------------------------------------------------------------- + + /** + * Parse a tag pair + * + * Parses tag pairs: {some_tag} string... {/some_tag} + * + * @access private + * @param string + * @param array + * @param string + * @return string + */ + function _parse_pair($variable, $data, $string) + { + if (FALSE === ($match = $this->_match_pair($string, $variable))) + { + return $string; + } + + $str = ''; + foreach ($data as $row) + { + $temp = $match['1']; + foreach ($row as $key => $val) + { + if ( ! is_array($val)) + { + $temp = $this->_parse_single($key, $val, $temp); + } + else + { + $temp = $this->_parse_pair($key, $val, $temp); + } + } + + $str .= $temp; + } + + return str_replace($match['0'], $str, $string); + } + + // -------------------------------------------------------------------- + + /** + * Matches a variable pair + * + * @access private + * @param string + * @param string + * @return mixed + */ + function _match_pair($string, $variable) + { + if ( ! preg_match("|".$this->l_delim . $variable . $this->r_delim."(.+?)".$this->l_delim . '/' . $variable . $this->r_delim."|s", $string, $match)) + { + return FALSE; + } + + return $match; + } + +} +// END Parser Class + +/* End of file Parser.php */ /* Location: ./system/libraries/Parser.php */ \ No newline at end of file