CORE
By: fruffl | Date: Jan 11 2010 00:42 | Format: PHP | Expires: never | Size: 17.6 KB | Hits: 1250
- <?PHP
- FINAL CLASS FRUFFL_ExceptionCore EXTENDS FRUFFL_Exception{}
- FINAL CLASS FRUFFL_Core extends FRUFFL_InstancieOpziener
- {
- public static function init(FRUFFL_BootConstructeur $FRUFFL_BootConstructeur)
- {
- return self::instance(__CLASS__);
- }
- public function run(FRUFFL_BootConstructeur $FRUFFL_BootConstructeur)
- {
- try
- {
- if(!FRUFFL::registryExists('FRUFFL_EXECUTED_FRUFFL_Store'))
- throw new FRUFFL_ExceptionDispatcher
- ('Unable to init Dispatcher. FRUFFL_Store not executed.');
- if(!FRUFFL::registryExists('FRUFFL_EXECUTED_FRUFFL_Instellingen'))
- throw new FRUFFL_ExceptionDispatcher
- ('Unable to init Dispatcher. FRUFFL_Instellingen not executed.');
- }
- catch(FRUFFL_Exception $e){FRUFFL_Exception::w($e);}
- $this->activate(__CLASS__);
- $this->execute();
- return $this;
- }
- protected function execute()
- {
- try
- {
- if
- (
- !$this->phpTest
- (
- FRUFFL::registryGet('FRUFFL_PHP_MIN_VERSION'),
- FRUFFL::registryGet('FRUFFL_PHP_MAX_VERSION')
- )
- )
- throw new FRUFFL_ExceptionCore
- ('Invalid PHP-Version.');
- if(!$this->requestTest())
- throw new FRUFFL_ExceptionCore
- ('haxx != rulez.');
- FRUFFL::registryAdd
- (
- 'FRUFFL_ENVIRONMENT_REMOTE_IP',
- $_SERVER['REMOTE_ADDR']
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_ENVIRONMENT',
- (
- FRUFFL::registryGet('FRUFFL_ENVIRONMENT_DEVELOPMENT_IP') == $_SERVER['REMOTE_ADDR']
- ? 'DEVELOPMENT'
- : 'PRODUCTION'
- )
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_ROUTING_TABLE',
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_ENVIRONMENT_URI',
- $this->getUri()
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_ENVIRONMENT_URIBASE',
- $this->getBase
- (
- FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URI'),
- FRUFFL::registryGet('FRUFFL_ENVIRONMENT_REWRITE_BASE_'.FRUFFL::registryGet('FRUFFL_ENVIRONMENT'))
- )
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_ENVIRONMENT_URIPATH',
- $this->getPath
- (
- FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URI'),
- FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URIBASE')
- )
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_COOKIE_GLOBAL_PREFIX',
- 'FRUFFL_COOKIE_'
- .'_'
- .sha1
- (
- $_SERVER['SERVER_NAME']
- .$_SERVER['SERVER_PORT']
- .FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URIBASE')
- )
- .'_'
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_COOKIE_LOCAL_PREFIX',
- 'FRUFFL_COOKIE_'
- .'_'
- .sha1
- (
- $_SERVER['SERVER_NAME']
- .$_SERVER['SERVER_PORT']
- .FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URIBASE')
- .FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URIPATH')
- )
- .'_'
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_SESSION_NAME',
- 'FRUFFL_SESSION_'
- .'_'
- .sha1
- (
- $_SERVER['SERVER_NAME']
- .$_SERVER['SERVER_PORT']
- .FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URIBASE')
- )
- .'_'
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_REQUEST_EXTRACTED_GET',
- $this->cleanup_incoming
- (
- $this->parse_incoming($_GET),
- FRUFFL::registryGet('FRUFFL_REQUEST_CLEANVARS_GET'),
- FRUFFL::registryGet('FRUFFL_REQUEST_CLEANVARS_GET_IGNORE'),
- FRUFFL::registryGet('FRUFFL_REQUEST_CLEANVARS_GET_UNSET_UNREGISTERED')
- )
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_REQUEST_EXTRACTED_POST',
- $this->cleanup_incoming
- (
- $this->parse_incoming($_POST),
- FRUFFL::registryGet('FRUFFL_REQUEST_CLEANVARS_POST'),
- FRUFFL::registryGet('FRUFFL_REQUEST_CLEANVARS_POST_IGNORE'),
- FRUFFL::registryGet('FRUFFL_REQUEST_CLEANVARS_POST_UNSET_UNREGISTERED')
- )
- );
- $tmp_cookie = $this->parse_incoming($_COOKIE);
- FRUFFL::registryAdd
- (
- 'FRUFFL_REQUEST_EXTRACTED_COOKIE_GLOBAL',
- $this->parse_incoming_cookie($tmp_cookie, FRUFFL::registryGet('FRUFFL_COOKIE_GLOBAL_PREFIX'))
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_REQUEST_EXTRACTED_COOKIE_LOCAL',
- $this->parse_incoming_cookie($tmp_cookie, FRUFFL::registryGet('FRUFFL_COOKIE_LOCAL_PREFIX'))
- );
- $this->ini
- (
- (
- FRUFFL::registryGet('FRUFFL_PHP_INI'),
- // auto-overwrites
- 'session.name' => FRUFFL::registryGet('FRUFFL_SESSION_NAME'),
- 'session.cookie_path' => FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URIBASE'),
- 'magic_quotes_gpc' => 0,
- 'magic_quotes_runtime' => 0,
- 'magic_quotes_sybase' => 0,
- 'register_globals' => 'off'
- )
- )
- );
- {
- FRUFFL::registryAdd
- (
- 'FRUFFL_SESSION_ID',
- $_COOKIE[FRUFFL::registryGet('FRUFFL_SESSION_NAME')]
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_SESSION_COOKIE',
- true
- );
- }
- else
- {
- FRUFFL::registryAdd
- (
- 'FRUFFL_SESSION_ID',
- NULL
- );
- FRUFFL::registryAdd
- (
- 'FRUFFL_SESSION_COOKIE',
- false
- );
- }
- // forward to valid uri
- if
- (
- $valide_uri = $this->get_cleanup
- (
- FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URIPATH'),
- FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URI'),
- FRUFFL::registryGet('FRUFFL_ENVIRONMENT_URIBASE'),
- FRUFFL::registryGet('FRUFFL_REQUEST_EXTRACTED_GET')
- )
- )
- {
- FRUFFL::registryAdd
- (
- 'FRUFFL_HEADER_FORWARDTO',
- $valide_uri
- );
- }
- else
- {
- // dump post-vars from session
- }
- }
- catch(FRUFFL_Exception $e){FRUFFL_Exception::w($e);}
- }
- {
- // repair broken uri-parts
- // mod_rewrite: last arg can't be a php-file
- // !mod_rewrite: last arg can't be a php-file; first arg must be index.php
- // create query-string from cleaned get-vars
- // kill query-string to compare it with path
- $uri = $env_uri;
- $valide_uri = $uri;
- $qry = '';
- {
- foreach($clean_query as $k => $v)
- {
- {
- }
- {
- $str .= $k.'='.$v;
- }
- if($v === NULL)
- {
- $str .= $k;
- }
- }
- $qry = '?'.$qry.$str;
- }
- // base ends never with '.php' if mod_rewrite is enabled: kill *.php
- {
- $valide_uri = str_replace('/'.substr($uri, (strlen(strtolower(pathinfo($uri, PATHINFO_FILENAME)).'.php') * -1)), NULL, $uri);
- }
- // mod_rewrite is disabled: kill all *.php-named args (ignore the location '{install_dir}/index.php')
- else
- {
- // if current loacation is "{install_dir}/" forward to {install_dir}/index.php[/?qry]
- if($env_path == $uri)
- $valide_uri = $env_base;
- // if path = '/' your current location is {install_dir}/index.php
- if($env_path != '/')
- // the last part in path can't be an php-file-name
- {
- // the base ({install_dir}/index.php)
- // + path without the last part
- //
- // {install_dir}/index.php/test.php, {install_dir}/index.php/site/test.php...
- // kill test.php and forward to the next parent
- if($uri != $env_base)
- $valide_uri = str_replace('/'.substr($uri, (strlen(strtolower(pathinfo($uri, PATHINFO_FILENAME)).'.php') * -1)), NULL, $uri);
- }
- }
- {
- }
- $valide_uri = $valide_uri.'/'.$qry;
- if($_SERVER['REQUEST_URI'] != $valide_uri)
- return $valide_uri;
- return false;
- }
- private function phpTest($min = '5', $max = '6')
- {
- return true;
- return false;
- }
- public function requestTest()
- {
- return false;
- return true;
- }
- {
- foreach($array as $k => $v)
- {
- }
- }
- {
- foreach($array as $k => $v)
- {
- global $$k;
- // Double unset to circumvent the
- // zend_hash_del_key_or_index hole in PHP <4.4.3 and <5.1.4 (by Tikitiki)
- }
- return $input;
- }
- {
- foreach($array as $key => $val)
- {
- if($p == $prefix)
- $input[$k] = $val;
- }
- return $input;
- }
- {
- foreach($clean_vars as $t => $k)
- {
- foreach($k as $v)
- {
- $temp[$v] = $vars[$v];
- continue;
- switch($t)
- {
- case 'url':
- // usefull for redirects: rawencode the given url
- // and add the http://-prefix
- {
- $temp[$v] = 'http://'.$temp[$v];
- }
- break;
- case 'path':
- // determine all crapy slashes and dot-slash-mixes from a path-var
- // and convert it into a clean '/dir/dir/n/'-path
- {
- }
- break;
- case 'numeric':
- // numeric-test only
- $temp[$v] = $temp[$v];
- break;
- case 'integer':
- // convert all keys in this case into an integer
- break;
- case 'integer_array':
- // same as 'integer'...
- // an integer-group is separated by pipe i. e. '89|654|1|5|1|sc|7'
- // this case sort the values by size and kill doublets;
- // the result is an array(0,1,5,7,89,654)
- {
- (
- (
- 'abs',
- (
- 'intval',
- (
- '|',
- $temp[$v]
- )
- )
- )
- );
- }
- break;
- case 'float':
- // convert all keys in this case into an integer
- break;
- case 'float_array':
- // same a integer-array for float-vars
- {
- (
- (
- 'abs',
- (
- 'floatval',
- (
- '|',
- $temp[$v]
- )
- )
- )
- );
- }
- break;
- case 'null':
- // those are keys without values. given values will be killed
- $temp[$v] = NULL;
- break;
- case 'bool':
- // allowes only 0 or 1
- break;
- case 'hex':
- // set all unallowed chars as 0
- break;
- }
- }
- }
- if($unset_on_unregistered)
- {
- return $temp;
- }
- return $vars;
- }
- private function getProtocol()
- {
- return ((is($https = $_SERVER['HTTPS']) && $https == 'on') ? 'https' : 'http');
- }
- private function getUri($uri = NULL)
- {
- if($uri === NULL)
- {
- if
- (
- )
- {
- }
- else
- if
- (
- &&
- )
- {
- }
- else
- if
- (
- )
- {
- $uri = $_SERVER['REQUEST_URI'];
- $url = ($protocol = $this->getProtocol()).'://'.
- (
- (
- is($server = $_SERVER['HTTP_HOST'])
- &&
- )
- ? $server
- : $protocol.
- (
- (
- ($protocol == 'http' && $port = $_SERVER['SERVER_PORT']) == 80
- ||
- ($protocol == 'https' && $port = 443)
- )
- ? $_SERVER['SERVER_NAME']
- : $_SERVER['SERVER_NAME'].':'.$_SERVER_['SERVER_PORT']
- )
- );
- }
- else
- if
- (
- )
- {
- $uri = $_SERVER['ORIG_PATH_INFO'];
- $uri .= '?'.$_SERVER['QUERY_STRING'];
- }
- else
- {
- }
- }
- }
- private function getBase($uri, $base = NULL)
- {
- return;
- if($base === NULL)
- {
- {
- $base = $_SERVER['SCRIPT_NAME'];
- }
- else
- {
- $base = $_SERVER['PHP_SELF'];
- }
- else
- {
- $base = $_SERVER['ORIG_SCRIPT_NAME'];
- }
- else
- {
- $base = '';
- $i = 0;
- do
- {
- $base = '/'.$dirs[$i].$base;
- ++$i;
- }
- }
- return $base;
- return '';
- }
- }
- private function getPath($uri = NULL, $base = NULL)
- {
- return;
- return;
- if($base == '/' || $base == '\')
- return;
- if (false !== ($i = strpos($uri, '?')))
- $uri = substr($uri, 0, ($i));
- $uri = rtrim($uri, '/');
- $path = str_replace($base, NULL, $uri);
- if(empty($path))
- $path = '/';
- return $path;
- }
- }
Latest pastes
1 days ago
2 days ago
5 days ago
6 days ago
6 days ago