Location: PHPKode > projects > Mocovie web framework > webs/common/controls/variable.php
<?php
/**
 *  Copyright (C) 2010  Kai Dorschner
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Kai Dorschner <the-hide@address.com>
 * @copyright Copyright 2010, Kai Dorschner
 * @license http://www.gnu.org/licenses/gpl.html GPLv3
 * @package mocovi
 * @subpackage controls
 */

ControlFactory::load('inline');

/**
 * @package mocovi
 * @subpackage controls
 */
class variable_control extends inline_control
{

	protected $whitelist = array
	( 'GLOBALS'	=> array
		( 'page'
		, 'language'
		, 'media'
		//, 'user'
		, 'theme'
		)
	);

	protected $defaultOptions = array
	( 'name'	=> ''
	, 'key'		=> ''
	);

	/**
	 * @override
	 */
	protected function getText()
	{
		if(($name = $this->getOption('name')) && array_key_exists($name, $this->whitelist))
		{
			$var = ($name == 'GLOBALS' ? $GLOBALS : $$name);
			if($key = $this->getOption('key'))
			{
				if(in_array($key, $this->whitelist[$name]))
				{
					if(is_string($var[$key]))
						$return = $var[$key];
					elseif(is_array($var[$key]))
						$return = join($var[$key]);
					elseif(is_object($var[$key]))
						$return = get_class($var[$key]);
					return $this->dom->createTextNode($return);
				}
				else
					$this->error('Access to $'.$name.($key ? '['.$key.']':'').' is not permitted.');
			}
			elseif(empty($this->whitelist[$name]))
			{
				if(is_string($var))
					$return = $var;
				elseif(is_object($var))
					$return = get_class($var);
				elseif(is_array($var))
					$return = join($var);
				return $this->dom->createTextNode($return);
			}
			else
				$this->error('Direct access to array $'.$name.' is not permitted.');
		}
	}
}
Return current item: Mocovie web framework