Commit 1f32b9ba authored by Bong Cosca's avatar Bong Cosca
Browse files

Redux: PHP globals passed by reference in hive() result (Issue #424)

parent a1956fb6
Loading
Loading
Loading
Loading
+16 −19
Original line number Diff line number Diff line
@@ -569,20 +569,18 @@ final class Base {
	*	Encode characters to equivalent HTML entities
	*	@return string
	*	@param $arg mixed
	*	@param $lvl int
	**/
	function esc($arg,$lvl=0) {
	function esc($arg) {
		if (is_string($arg))
			return $this->encode($arg);
		if (is_array($arg) || is_a($arg,'ArrayAccess'))
			foreach ($arg as $key=>&$val)
				if ($lvl || !preg_match('/'.self::GLOBALS.'/',$key)) {
					$val=$this->esc($val,$lvl+1);
			foreach ($arg as &$val) {
				$val=$this->esc($val);
				unset($val);
			}
		if (is_object($arg))
			foreach (get_object_vars($arg) as $key=>$val)
				$arg->$key=$this->esc($val,$lvl+1);
				$arg->$key=$this->esc($val);
		return $arg;
	}

@@ -590,14 +588,12 @@ final class Base {
	*	Decode HTML entities to equivalent characters
	*	@return string
	*	@param $arg mixed
	*	@param $lvl int
	**/
	function raw($arg,$lvl=0) {
	function raw($arg) {
		if (is_string($arg))
			return $this->decode($arg);
		if (is_array($arg) || is_a($arg,'ArrayAccess'))
			foreach ($arg as $key=>&$val)
				if ($lvl || !preg_match('/'.self::GLOBALS.'/',$key)) {
			foreach ($arg as &$val) {
				$val=$this->raw($val,$lvl+1);
				unset($val);
			}
@@ -1835,8 +1831,8 @@ class View extends Prefab {
	*	Create sandbox for template execution
	*	@return string
	**/
	protected function sandbox() {
		extract($this->hive);
	protected function sandbox($hive) {
		extract($hive);
		ob_start();
		require($this->view);
		return ob_get_clean();
@@ -1858,11 +1854,12 @@ class View extends Prefab {
				$fw->sync('SESSION');
				if (!$hive)
					$hive=$fw->hive();
				$this->hive=$fw->get('ESCAPE')?$hive=$fw->esc($hive):$hive;
				if ($fw->get('ESCAPE'))
					$hive=$fw->esc($hive);
				if (PHP_SAPI!='cli')
					header('Content-Type: '.$mime.'; '.
						'charset='.$fw->get('ENCODING'));
				return $this->sandbox();
				return $this->sandbox($hive);
			}
		user_error(sprintf(Base::E_Open,$file));
	}
+3 −2
Original line number Diff line number Diff line
@@ -378,11 +378,12 @@ class Template extends View {
				$fw->sync('SESSION');
				if (!$hive)
					$hive=$fw->hive();
				$this->hive=$fw->get('ESCAPE')?$fw->esc($hive):$hive;
				if ($fw->get('ESCAPE'))
					$hive=$fw->esc($hive);
				if (PHP_SAPI!='cli')
					header('Content-Type: '.($this->mime=$mime).'; '.
						'charset='.$fw->get('ENCODING'));
				return $this->sandbox();
				return $this->sandbox($hive);
			}
		user_error(sprintf(Base::E_Open,$file));
	}