Beispiel #1
0
	static function start() /// Launches whole the action after configuration read
	{
		error_reporting(core::$config['error-reporting-lo']);

		foreach ($_COOKIE as $var=>$val) core::$req[$var]= $val;
		if (isset(core::$config['cookie-vars'])) foreach (core::$config['cookie-vars'] as $var=>$config)
		{
			core::$req[$var]= core::filter(core::req($var),$config);
		}

		foreach ($_GET as $var=>$val) if ($var!==session_name()) core::$req[$var]= core::$reqUrl[$var]= $val;
		unset(core::$reqUrl[core::config('module-var')]);
		foreach ($_POST as $var=>$val) if ($var!==session_name()) core::$req[$var]= $val;
		foreach ($_FILES as $var=>$val)
		{
			if (is_string($val['name'])) core::$req[$var]= $val;  // <input type=file name=xxx ...>
			else  // <input type=file name=xxx[yyy] ...>
			{
				foreach ($val['name'] as $key=>$void)
				{
		 			core::$req[$var][$key]= array(
						'name'=>$val['name'][$key],
						'type'=>$val['type'][$key],
						'tmp_name'=>$val['tmp_name'][$key],
						'error'=>$val['error'][$key],
						'size'=>$val['size'][$key]
					);
				}
			}
		}

		if (isset(core::$config['cookie-vars'])) foreach (core::$config['cookie-vars'] as $name=>$config) 
		{
			if (isset(core::$req[$name]))
			{
				core::$req[$name]= core::filter(core::$req[$name], $config);
				if (!isset($_COOKIE[$name]) || $_COOKIE[$name]!=core::$req[$name])
				{
					setcookie($name, core::$req[$name], $config['expire']);
				}
				unset(core::$reqUrl[$name]);
			}
		}
		
		// apply required vars
		if (isset(core::$config['required'])) foreach (core::$config['required'] as $name=>$config)
		{
			core::$req[$name]=  core::filter(core::$req[$name],$comfig);
			core::$reqUrl[$name]= core::$req[$name];
		}
		
		if (!core::moduleName())
		{
			if (is_array(core::$config['default-module']))
			{
				$args= href::processArgs(core::$config['default-module']);
				core::$req[core::$config['module-var']]= $args['template'];
				array_merge(core::$reques,$args['req']);
			}
		}
		core::$req[core::$config['module-var']]= str_replace('..','(dot)(dot)',core::moduleName()); //secure upper directories
		core::$req[core::$config['module-var']]= str_replace("\0",'(0)',core::moduleName()); //secure
		core::$req[core::$config['module-var']]= str_replace('<','(lt)',core::moduleName()); //secure
		core::$req[core::$config['module-var']]= str_replace('>','(gt)',core::moduleName()); //secure

		// set session var
		if (core::req(session_name()) || isset(core::$config['session-vars']))
		{
			if (!session_id()) session_start();
			foreach ($_SESSION as $name=>$val) core::$req[$name]= $val;
			if (isset(core::$config['session-vars'])) foreach (core::$config['session-vars'] as $name=>$config)
			{
				core::$req[$name]= core::filter(core::req($name),$config);
				unset(core::$reqUrl[$name]);
			}
		}

		if (core::req('cms-oper')) cms::perform();
		elseif (core::req('core-module')=='cms-resource') cmsGui::forward(core::req('file'));

		ob_start();
		if (isset(core::$config['pre-models'])) foreach(core::$config['pre-models'] as $model) core::model($model);
		core::insert(core::moduleName());
		$buffer= ob_get_contents();
		ob_end_clean();

		// Process pre- and post-templates
		if (!core::reg('run-naked'))
		{
			ob_start();
			if (isset(core::$config['pre-module'])) core::insert(core::$config['pre-module']);
			echo $buffer;
			if (isset(core::$config['post-module'])) core::insert(core::$config['post-module']);
			if (isset(core::$config['post-models'])) foreach(core::$config['post-models'] as $model) core::model($model);
			$buffer= ob_get_contents();
			ob_end_clean();
		}
		
		// Output
		echo $buffer;
		//if (core::$prepend) core::error('one or more prepends were not utilized: '.implode(',',array_keys(core::$prepend)));
	}