summaryrefslogtreecommitdiffstats
path: root/system/libraries/Parser.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Parser.php')
-rwxr-xr-x[-rw-r--r--]system/libraries/Parser.php87
1 files changed, 63 insertions, 24 deletions
diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php
index 399b14b2d..d223da020 100644..100755
--- a/system/libraries/Parser.php
+++ b/system/libraries/Parser.php
@@ -2,11 +2,11 @@
/**
* CodeIgniter
*
- * An open source application development framework for PHP 4.3.2 or newer
+ * An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
+ * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
@@ -29,11 +29,11 @@ class CI_Parser {
var $l_delim = '{';
var $r_delim = '}';
var $object;
-
+
/**
* Parse a template
*
- * Parses pseudo-variables contained in the specified template,
+ * Parses pseudo-variables contained in the specified template view,
* replacing them with the data in the second param
*
* @access public
@@ -42,38 +42,77 @@ class CI_Parser {
* @param bool
* @return string
*/
- function parse($template, $data, $return = FALSE)
+ public function parse($template, $data, $return = FALSE)
{
$CI =& get_instance();
$template = $CI->load->view($template, $data, TRUE);
-
+
+ return $this->_parse($template, $data, $return);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Parse a String
+ *
+ * Parses pseudo-variables contained in the specified string,
+ * replacing them with the data in the second param
+ *
+ * @access public
+ * @param string
+ * @param array
+ * @param bool
+ * @return string
+ */
+ function parse_string($template, $data, $return = FALSE)
+ {
+ return $this->_parse($template, $data, $return);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Parse a template
+ *
+ * Parses pseudo-variables contained in the specified template,
+ * replacing them with the data in the second param
+ *
+ * @access public
+ * @param string
+ * @param array
+ * @param bool
+ * @return string
+ */
+ function _parse($template, $data, $return = FALSE)
+ {
if ($template == '')
{
return FALSE;
}
-
+
foreach ($data as $key => $val)
{
if (is_array($val))
{
- $template = $this->_parse_pair($key, $val, $template);
+ $template = $this->_parse_pair($key, $val, $template);
}
else
{
$template = $this->_parse_single($key, (string)$val, $template);
}
}
-
+
if ($return == FALSE)
{
+ $CI =& get_instance();
$CI->output->append_output($template);
}
-
+
return $template;
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Set the left/right variable delimiters
*
@@ -87,9 +126,9 @@ class CI_Parser {
$this->l_delim = $l;
$this->r_delim = $r;
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Parse a single key/value
*
@@ -103,9 +142,9 @@ class CI_Parser {
{
return str_replace($this->l_delim.$key.$this->r_delim, $val, $string);
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Parse a tag pair
*
@@ -118,7 +157,7 @@ class CI_Parser {
* @return string
*/
function _parse_pair($variable, $data, $string)
- {
+ {
if (FALSE === ($match = $this->_match_pair($string, $variable)))
{
return $string;
@@ -139,15 +178,15 @@ class CI_Parser {
$temp = $this->_parse_pair($key, $val, $temp);
}
}
-
+
$str .= $temp;
}
-
+
return str_replace($match['0'], $str, $string);
}
-
+
// --------------------------------------------------------------------
-
+
/**
* Matches a variable pair
*
@@ -158,11 +197,11 @@ class CI_Parser {
*/
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))
+ if ( ! preg_match("|" . preg_quote($this->l_delim) . $variable . preg_quote($this->r_delim) . "(.+?)". preg_quote($this->l_delim) . '/' . $variable . preg_quote($this->r_delim) . "|s", $string, $match))
{
return FALSE;
}
-
+
return $match;
}
@@ -170,4 +209,4 @@ class CI_Parser {
// END Parser Class
/* End of file Parser.php */
-/* Location: ./system/libraries/Parser.php */ \ No newline at end of file
+/* Location: ./system/libraries/Parser.php */