* @version 3.0 */ class FW{ private static $call = false; private static $cache = array('classes' => false); private static $current_lng = false; static $current_domain_whitelist = array(); public static function init(){ if(self::$call !== false) return false; // Already init define('IS_CLI', php_sapi_name() === 'cli'); if(IS_CLI) error_reporting(E_ALL ^ E_NOTICE); $user_agent = strtolower(@$_SERVER['HTTP_USER_AGENT']); if(strpos($user_agent, 'facebookexternal') !== false) define('CRAWLER', 'facebook'); elseif(strpos($user_agent, 'googlebot') !== false) define('CRAWLER', 'google'); elseif(strpos($user_agent, 'mozilla/5.0 (windows nt 6.1; rv:6.0) gecko/20110814 firefox/6.0') !== false) define('CRAWLER', 'google+'); else define('CRAWLER', FALSE); if(isset($_GET["_escaped_fragment_"]) && $_GET["_escaped_fragment_"] != '') define('FRAGMENT', $_GET["_escaped_fragment_"]); else define('FRAGMENT', FALSE); $basedir = explode(DS, dirname(__FILE__)); array_pop($basedir); $basedir = implode(DS, $basedir) . DS; $base = str_replace('framework/framework.php', '', $_SERVER['SCRIPT_NAME']); $baseurl = (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . $base; self::$call = current(explode('?', $_SERVER['REQUEST_URI'], 2)); if($base && strlen($base) > 1 && substr(self::$call, 0, strlen($base)) == $base) self::$call = substr(self::$call, strlen($base)); self::$call = array_filter(explode('/', self::$call)); self::$call = array_slice(self::$call, 0); define('PATH', $basedir); define('PATH_THEME', PATH . 'theme' . DS); define('PATH_AJAX', PATH_THEME . 'ajax' . DS); define('PATH_GFX', PATH_THEME . 'gfx' . DS); define('PATH_IMG', PATH_THEME . 'img' . DS); define('PATH_JS', PATH_THEME . 'js' . DS); define('PATH_CSS', PATH_THEME . 'css' . DS); define('PATH_UPLOADS', PATH_THEME . 'upload' . DS); define('PATH_FW', PATH . 'framework' . DS); define('PATH_FW_AJAX', PATH_FW . 'ajax' . DS); define('PATH_FW_GFX', PATH_FW . 'gfx' . DS); define('PATH_FW_IMG', PATH_FW . 'img' . DS); define('PATH_FW_JS', PATH_FW . 'js' . DS); define('PATH_FW_CSS', PATH_FW . 'css' . DS); define('PATH_FW_UPLOAD', PATH_FW . 'upload' . DS); // Don't allow every hostname the user is sending if(fs::exists(PATH_THEME . 'domain_whitelist.php')) require_once PATH_THEME . 'domain_whitelist.php'; else if(fs::exists(PATH_FW . 'domain_whitelist.php')) require_once PATH_FW . 'domain_whitelist.php'; if(isset($domain_whitelist) && $domain_whitelist) static::$current_domain_whitelist = $domain_whitelist; if(isset($domain_whitelist) && $domain_whitelist && self::call(0) != 'backend'){ $found = false; $first_non_wild = $baseurl; $if_found = $baseurl; $baseurl_l = strtolower(trim(@parse_url($baseurl, PHP_URL_HOST))); foreach($domain_whitelist as $dw){ if(trim($dw) == "*"){ $found = true; break; } $first_non_wild = $first_non_wild == $baseurl && trim($dw) != "*" ? $dw : $first_non_wild; $entry_l = strtolower(trim(@parse_url($dw, PHP_URL_HOST))); if(strpos($baseurl_l, $entry_l) !== false){ $found = true; $if_found = (substr($dw, -1) != "/") ? ($dw . $base) : ($dw . @substr($base, 1)); break; } } $baseurl = $found ? $if_found : $first_non_wild; if(substr($baseurl, -1) != "/") $baseurl = $baseurl . "/"; } define('URL', $baseurl); define('URL_THEME', URL . 'theme/'); define('URL_AJAX', URL_THEME . 'ajax/'); define('URL_GFX', URL_THEME . 'gfx/'); define('URL_IMG', URL_THEME . 'img/'); define('URL_JS', URL_THEME . 'js/'); define('URL_CSS', URL_THEME . 'css/'); define('URL_UPLOADS', URL_THEME . 'upload/'); define('URL_FW', URL . 'framework/'); define('URL_FW_AJAX', URL_FW . 'ajax/'); define('URL_FW_GFX', URL_FW . 'gfx/'); define('URL_FW_IMG', URL_FW . 'img/'); define('URL_FW_JS', URL_FW . 'js/'); define('URL_FW_CSS', URL_FW . 'css/'); define('URL_FW_UPLOAD', URL_FW . 'upload/'); define('URL_ssl', str_replace('http:', 'https:', $baseurl)); define('URL_ssl_THEME', URL_ssl . 'theme/'); define('URL_ssl_AJAX', URL_ssl_THEME . 'ajax/'); define('URL_ssl_GFX', URL_ssl_THEME . 'gfx/'); define('URL_ssl_IMG', URL_ssl_THEME . 'img/'); define('URL_ssl_JS', URL_ssl_THEME . 'js/'); define('URL_ssl_CSS', URL_ssl_THEME . 'css/'); define('URL_ssl_UPLOADS', URL_ssl_THEME . 'upload/'); define('URL_ssl_FW', URL_ssl . 'framework/'); define('URL_ssl_FW_GFX', URL_ssl_FW . 'gfx/'); define('URL_ssl_FW_JS', URL_ssl_FW . 'js/'); define('URL_ssl_FW_CSS', URL_ssl_FW . 'css/'); define('URL_ssl_FW_UPLOAD', URL_ssl_FW . 'upload/'); // Environment Check define('IS_IIS', (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false)); define('IS_SVN', self::call(0) == 'svn'); define('IS_CRON', self::call(0) == 'cron'); define('IS_TWITTER', self::call(0) == 'tw_callback'); define('IS_INSTAGRAM', self::call(0) == 'ig_callback'); define('IS_PIXEL', self::call(0) == 'c_pixel'); define('IS_FW', self::call(0) == 'framework'); if(IS_FW) array_shift(self::$call); define('IS_GFX', self::call(0) == 'gfx' || (self::call(0) == 'theme' && self::call(1) == 'gfx')); define('IS_CSS', self::call(0) == 'css' || (self::call(0) == 'theme' && self::call(1) == 'css')); define('IS_JS', self::call(0) == 'js' || (self::call(0) == 'theme' && self::call(1) == 'js')); define('IS_MOBILE', self::call(0) == 'mobile' || is_mobile()); define('IS_TABLET', self::call(0) == 'tablet' || is_tablet()); if(self::call(0) == 'mobile') array_shift(self::$call); define('IS_BACKEND', self::call(0) == 'backend'); define('IS_SITEMAP', self::call(0) == 'sitemap' || self::call(0) == 'sitemap.xml'); if(IS_SITEMAP) array_shift(self::$call); define('IS_FACEBOOK', self::call(0) == 'facebook' || self::call(0) == 'fb'); define('IS_FB', IS_FACEBOOK); if(IS_FB) array_shift(self::$call); define('IS_FB_APP', (IS_FB && self::call(0) == 'app')); if(IS_FB_APP) array_shift(self::$call); define('IS_FB_TAB', (IS_FB && self::call(0) == 'tab')); if(IS_FB_TAB) array_shift(self::$call); self::require_class("ajax"); define('IS_AJAX', ajax::is()); return true; } public static function call($index = false, $case_sensetive = false){ if(is_int($index)){ $ret = M(self::$call, $index, ''); return $case_sensetive ? $ret : strtolower($ret); } elseif(is_string($index)){ $index = strtolower($index); $ret = false; if($index == 'last') $ret = count($ret > 0) ? end(self::$call) : ''; if($ret === false) return self::$call; return $case_sensetive ? $ret : strtolower($ret); } elseif(is_array($index) && $case_sensetive) self::$call = $index; return self::$call; } public static function require_class($name, $force = true){ if(!self::$cache['classes']){ self::$cache['classes'] = []; $class_paths = array(PATH_FW . 'class' . DS); if(file_exists(PATH_THEME . 'class')) $class_paths[] = PATH_THEME . 'class' . DS; if(file_exists(PATH_THEME . 'classes')) $class_paths[] = PATH_THEME . 'classes' . DS; foreach($class_paths as $path){ $folders = ls('*', $path, false, array('return_folders')); foreach($folders as $folder){ $folder = str_replace(DS, '', $folder); if(fs::exists($path . $folder . DS . $folder . '.php')) self::$cache['classes'][strtolower($folder)] = $path . $folder . DS . $folder . '.php'; elseif(fs::exists($path . $folder . DS . $folder . '.class.php')) self::$cache['classes'][strtolower($folder)] = $path . $folder . DS . $folder . '.class.php'; } $files = ls('*.php', $path, false, array('return_files')); foreach($files as $file){ $filename = preg_replace('/(\.class|)\.php$/', '', $file); self::$cache['classes'][strtolower($filename)] = $path . $file; } } } $name = strtolower($name); if(key_exists($name, self::$cache['classes'])){ require_once self::$cache['classes'][$name]; return true; } if($force === true){ print_pre(array_keys(self::$cache['classes']), 'valide classes'); throw new Exception("Try to include class: $name", 1); } return false; } public static function hash($string, $iterations = 10, $salt = '319ebf7ebd1e97ae07654bce826e715c8b8'){ return crypto::hash($string, $iterations, $salt); } static $log_list = array(); /** * Log variable to Firebug.FirePHP if FirePHP exists otherwise do nothing. * @link http://www.firephp.org/HQ/Use.htm * * @param mixed $Object The variable to be logged * * @return true Return TRUE if message was added to headers, FALSE otherwise * @throws Exception */ static $debug_cached = null; public static function log(){ return true; if(IS_CLI){ echo implode(" ", $args = func_get_args()) . PHP_EOL; return true; } if(static::$debug_cached === null && defined("FW_DEBUG")) static::$debug_cached = FW_DEBUG; if(static::$debug_cached !== null && !static::$debug_cached) return false; if(M($_SESSION, "name") != "admin"){ if(!M($_SESSION, "name") || !M($_SESSION, "pass") || !isset($_SESSION['svn_update_user']) || !isset($_SESSION['svn_update_pass'])) return false; // don't display logs for non logged in backend users } if(function_exists('fb')){ $instance = FirePHP::getInstance(true); // Output pre-buffered logs before full init if(static::$log_list){ foreach(static::$log_list as $log_entry) call_user_func_array(array($instance, 'fb'), $log_entry); static::$log_list = array(); } $args = func_get_args(); return call_user_func_array(array($instance, 'fb'), $args); } else{ static::$log_list[] = func_get_args(); return true; } } /** * Save to the log * * @param string $label *, Label of the item to log (should be used to group the log items) * @param mixed $value *, The value to save to (could be a string or array/json) * @param string $type , Is the group of the group (user, error, warning, ....) * * @return integer or false , the unique id of the log entry or false on error */ public static function save_log($label, $value, $type = 'general'){ if($type == '*') $type = '*'; $data = array('label' => $label, 'value' => $value, 'type' => $type); if(M($value, "mail_type")) $data["mail_type"] = @$value["mail_type"]; return SQ::insert($data, 'fw_log'); } /** * get a log array or a single entry * * @param string $label , the label of the log * @param string $type , Is the group of the group (user, error, warning, ....) * @param bool $single , select only one row directly * * @return array of array(logionfos) OR array(loginfos) OR empy array */ public static function get_log($label = NULL, $type = NULL, $single = false){ $where = array(); if(is_string($label) && $label != '') $where[] = '`label`=' . SQ::esc($label, "'"); if(is_string($type) && $type != '') $where[] = '`type`=' . SQ::esc($type, "'"); if(count($where) < 1) throw new Exception('framework->get_log: one or both parameter should be a string!'); if(!is_bool($single)) throw new Exception('framework->get_log: $single should be a boolean!'); return SQ::assoc("SELECT * FROM `fw_log` WHERE " . implode(' AND ', $where) . " ORDER BY `date` DESC", $single); } /** * Redirects the user (for facebook iframe, http and https) * * @param $location string required The new location * @param $iframe bool default=false indicates on true that the page is a iframe so we have to redirect via javascript * @param $status int default=301 the status code for the redirect * * @return TRUE or FALSE */ public static function redirect($location, $iframe = false, $status = 301){ if($iframe){ echo ''; echo 'Falls Sie nicht sofort weitergeleitet werden bitte klicken Sie hier!'; exit; } else{ if((strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false)) header("Refresh: 0;url=$location"); else{ header("Location: $location"); header("Refresh: 0;url=$location"); } echo ''; echo ''; die(); } } /** * Set the current language * * @param mixed $set , string => Value to set the current language (syntax "lg_CC", lg is lower case language and CC is the upper case country-code) * boolean => true result in returning the current language, false returns the country-code (both lower case) * null (default) => return current language option (syntax "lg_CC", lg is lower case language and CC is the upper case country-code) * * @return string, current lower case language, lower case country-code or as default both in "lg_CC" syntax */ public static function lng($set = null){ if($set === true) return strtolower(current(explode('_', self::$current_lng))); if($set === false) return strtolower(end(explode('_', self::$current_lng))); if(is_string($set) && $set != ''){ date_default_timezone_set('Europe/Berlin'); $crater = @explode("_", $set); $set = M($crater, 0) . "_" . strtoupper(M($crater, 1)); self::$current_lng = $set; setlocale(LC_ALL, $set); } return self::$current_lng; } public static function install(){ if(!SQ::table('fw_setting') || !SQ::table('fw_log')): SQ::q("ALTER DATABASE `" . SQ::db() . "` charset=utf8;"); // The database needs to be UTF-8 $content = file_get_contents(PATH_FW . 'framework.sql'); SQ::q(SQ::prepare_sql_file($content)); endif; self::lng(M($_SESSION, 'user_language', 'de_DE')); define('CURRENT_GAME', cache::easy_cache("fws_general.current_game", function (){ return FW::s('general.current_game', 'default'); })); if(true): $lng = self::lng(); $game_e = SQ::esc(CURRENT_GAME, ''); $settings = SQ::assoc_easy_cache("SELECT * FROM `fw_setting` WHERE `game` = '' OR `game` LIKE 'TXT.{$lng}.{$game_e}' OR `game` LIKE 'GAME.{$game_e}.%'"); foreach($settings ? $settings : array() AS $s) cache::rt($s['game'], $s['key'], unserialize($s['value'])); endif; } public static function s($key, $default = false, $force = false){ if(!is_string($key) || !$key) return false; $game = ''; // Game '' is reserved to general settings if($default === null){ // Check if setting is set $game_e = SQ::esc($game); $key_e = SQ::esc($key); return (SQ::val("SELECT COUNT(*) FROM `fw_setting` WHERE `game` = $game_e AND `key` = $key_e LIMIT 1") > 0); } if($force) FW::log($default, 'Save setting ' . $key); return self::setting($key, $game, $default, $force, $default); } public static function t($key, $default = '', $game = null, $force = false, $infos = ''){ if(!is_string($key) || !$key) return false; if(!is_string($default)) return false; if(strpos($key, '.') === false) $key = "nogroup." . $key; if($default == '') $default = 'TBD: ' . $key; if($game === null) $game = CURRENT_GAME; if(!is_string($game)) return false; if(strpos($game, 'TXT') !== 0) $game = 'TXT.' . self::lng() . '.' . $game; // Games TXT_% are reserved to text elements return self::setting($key, $game, $default, $force, $infos); } public static function gs($key, $default, $game = null, $force = false){ if(!is_string($key) || !$key) return false; if($game === null) $game = CURRENT_GAME; if(!is_string($game)) return false; $game = 'GAME.' . $game; return self::setting($key, $game, $default, $force, $default); } private static function setting($key, $game, $default, $force = false, $infos = ''){ if(!is_string($key) || !$key) return false; if(!is_string($game)) return false; if($default === NULL) return false; $key_e = SQ::esc($key); $game_e = SQ::esc($game); $val = null; if(!$force){ $val = cache::rt($game, $key); if($val === null){ $data = SQ::val("SELECT `value` FROM `fw_setting` WHERE `game` = $game_e AND `key` = $key_e LIMIT 1"); $val = is_string($data) ? unserialize($data) : null; cache::rt($game, $key, $val); } } if($val === null){ $val = $default; $data = serialize($val); $infos = serialize($infos); SQ::update(array('key' => $key, 'game' => $game, 'value' => $data, 'info' => $infos), 'fw_setting'); cache::rt($game, $key, $val); cache::increment_change_rev(); } return $val; } /** * the string format'r * replaces values in %name% format inside of a given text with its corresponding value in an array * * @param string $format * the text you would like be checked/replaced * @param associativ $array * the values to replace * @param string $prefix !DO NOT USE! is needed for recursive function self calling * * @return string the formated text */ public static function sf($format, $array = null, $prefix = ''){ if(!$array) $array = self::env(false); if(is_array($array)){ $format = str_replace("%print_r%", print_r($array, true), $format); $format = str_replace("%print_json%", json_encode($array), $format); foreach($array as $key => $val) if(is_array($val)) $format = self::sf($format, $val, $prefix . $key . '.'); elseif(is_string($val) || is_numeric($val)) $format = str_ireplace("%{$prefix}{$key}%", $val, $format); } return $format; } public static function sf_t($key, $default, $data = array()){ if(!is_string($default)) $default = "TBD: $key"; return self::sf(self::t($key, $default, null, false, $data), $data); } // -- support functions for url values static function t_res_sf_lite($format, $array = null){ // Add env variables to array if(!static::$const_vars) static::$const_vars = get_defined_constants(true); $ret = M(static::$const_vars, 'user', array()); $array = $array = $array ? : array(); $array["URL"] = @$ret["URL"]; $array["URL_THEME"] = @$ret["URL_THEME"]; $array["URL_GFX"] = @$ret["URL_GFX"]; $array["URL_IMG"] = @$ret["URL_IMG"]; $array["URL_UPLOADS"] = @$ret["URL_UPLOADS"]; $array["URL_FW"] = @$ret["URL_FW"]; $array["URL_FW_GFX"] = @$ret["URL_FW_GFX"]; $array["URL_FW_IMG"] = @$ret["URL_FW_IMG"]; $array["URL_FW_UPLOAD"] = @$ret["URL_FW_UPLOAD"]; // Replace env occurrences within ret fwt string foreach($array as $key => $val) $format = str_replace("%" . $key . "%", $val, $format); return $format; } protected static function t_res_t($key, $default = '', $infos = ''){ // Handle 1 part keys $key = strpos($key, '.') === false ? "nogroup." : $key; return self::t_res_setting($key, ('TXT.' . self::lng() . '.' . CURRENT_GAME), $default, $infos); } protected static function t_res_setting($key, $game, $default, $infos = ''){ $val = null; $val = cache::rt($game, $key); // If not in runtime cache try fetch from db if($val === null){ $data = SQ::val("SELECT `value` FROM `fw_setting` WHERE `game` = " . SQ::esc($game) . " AND `key` = " . SQ::esc($key) . " LIMIT 1"); $val = is_string($data) ? unserialize($data) : null; cache::rt($game, $key, $val); } // Insert into db if not exist if($val === null){ $val = $default; $data = serialize($val); $infos = serialize($infos); SQ::update(array('key' => $key, 'game' => $game, 'value' => $data, 'info' => $infos), 'fw_setting'); cache::rt($game, $key, $val); cache::increment_change_rev(); } return $val; } // Does only work with 1 dimensional arrays public static function t_res($key, $default = false, $data = array()){ // Only works with key argument given return $key ? self::t_res_sf_lite(self::t_res_t($key, ($default ? $default : "TBD: $key"), $data), $data) : false; } // -- support functions for url values static $const_vars = array(); public static function env($url_only = false){ if(!static::$const_vars) static::$const_vars = get_defined_constants(true); $ret = M(static::$const_vars, 'user', array()); if($url_only) foreach($ret as $key => $value) if(strpos($key, 'PATH') === 0 || (strpos($key, 'URL') !== 0 && strpos($key, 'FB') !== 0 && strpos($key, 'IS') !== 0)) unset($ret[$key]); return $ret; } public static function infostack($message = null, $type = MSG_INFO){ //TODO: use the FW::save_log for this... if($message === false) return self::s('infostack', array(), true); $current_stack = self::s('infostack', array()); if(is_array($message)){ self::s('infostack', $current_stack = $message, true); } if(is_string($message) && FW_DEBUG){ $current_stack[] = array($message, $type, time()); self::s('infostack', $current_stack, true); } return $current_stack; } private static $template_name = 'index'; public static function use_template($template_name = null){ if($template_name === null) return self::$template_name; if(!template::exists($template_name)) return false; self::$template_name = $template_name; } public static function require_ob($path, $once = false){ if(!fs::exists($path)) return false; $content = ''; ob_start(); if($once) require_once $path; else require $path; $content = ob_get_contents(); ob_end_clean(); return $content; } public static function chk_route($name, $base = PATH_THEME){ $ret = false; $disabled = array('class', 'classes', 'module', 'modules', 'template', 'templates'); if(strpos($base, PATH_THEME) !== 0) return $ret; if(substr($base, -1) != DS) $base = $base . DS; if(is_array($name)){ $c_base = array($base); foreach($name as $n){ $r = self::chk_route($n, $base); if($r) $c_base[] = $base = $r; if(strpos($base, '.php') !== FALSE) return $base; } for($i = count($c_base) - 1; $i >= 0; $i--) if(fs::exists($c_base[$i] . 'index.php')) return $c_base[$i] . 'index.php'; return false; } else{ if(!is_string($name)) return false; $name = current(explode(DS, $name)); $name = current(explode('.', $name)); $name = filter::websafe_name($name); if(fs::exists($base . $name . '.php')) $ret = $base . $name . '.php'; elseif(fs::exists($base . $name . DS) && ($base != PATH_THEME || !in_array($name, $disabled))) $ret = $base . $name . DS; else $ret = false; } return $ret; } } FW::init(); FW::require_class('crypto'); FW::require_class('action'); FW::require_class('filter'); FW::require_class('enque'); FW::require_class('html'); if(M($_SESSION, 'hash') != md5(PATH) && !M($_SESSION, "ignore_path_check")){ // session is only allowed to the current path... session_unset(); $_SESSION['hash'] = md5(PATH); } if(!fs::exists(PATH . 'config.php')){ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'fixed' . DIRECTORY_SEPARATOR . 'setup.php'; die(); } require_once PATH . 'config.php'; define('FW_CONFIGURATED', true); if(!isset($config)) die('Connection-Error no config element!'); FW::require_class("cache"); FW::require_class("SQ"); if(!SQ::connect($config['db'])) die('Connection-Error: ' . SQ::connect_errno()); cache::init( PATH, 1800, "memcached", 11211 ); FW::require_class('template'); FW::require_class('storeable'); FW::install(); define('FW_DEBUG', FW::s('general.debug', true)); action::exec('post_init'); $firephp = false; if(FW_DEBUG && !IS_CLI) FW::require_class("FirePHPCore"); if(FW::s('general.facebook', false)) FW::require_class("ccFB"); if(FW::s("general.googleplus", false)) FW::require_class("ccGP"); if(FW::s("general.twitter", false)) FW::require_class("ccTW"); if(FW::s("general.instagram", false)) FW::require_class("ccIG"); if(FW::s('cache.enabled', TRUE)) ini_set('zlib_output_compression', 'On'); else ini_set('zlib_output_compression', 'Off'); unset($config); FW::require_class("cronjob"); FW::require_class("mail_demand"); FW::require_class("a_b_testing"); FW::require_class("crawler_info_dispenser"); FW::require_class("issue_post"); if(!FW_DEBUG || !M($_SESSION, "name") || !M($_SESSION, "pass")) error_reporting(0); FW::require_class("cli_cronjob_manager"); if(fs::exists(PATH_THEME . 'function.php')) require_once PATH_THEME . 'function.php'; if(fs::exists(PATH_THEME . 'functions.php')) require_once PATH_THEME . 'functions.php'; if(FW::s('users.enabled', false)){ FW::require_class('user'); action::exec('usermanagement'); } action::exec('pre_routing'); if(IS_CLI){ $fw_run_timer = number_format((microtime(true) - $fw_run_timer) * 1000, 4); FW::log("CLI Call took $fw_run_timer ms"); die(); } if(FW::s('devgate.enabled', false) || !issue_post::is_ready_for_live()){ FW::require_class("backend"); FW::require_class("deferred_task_queue"); FW::require_class("site_log"); } # dev gate bypass if(gethostname() == "devhost01" || gethostname() == "devhost03"){ if(isset($_GET['site_dev_preview']) && (md5(URL) == $_GET['site_dev_preview'])){ $_SESSION['devgate_user'] = FW::s('devgate.user'); $_SESSION['devgate_pass'] = FW::s('devgate.pass'); } } // Fw hooks action::add("backend_usr_login_success", function ($data){ FW::s("app.current_main_url_ssl", URL_ssl, true); FW::s("app.current_main_url", URL, true); }); action::add("backend_svn_update", function ($data){ FW::s("app.current_main_url_ssl", URL_ssl, true); FW::s("app.current_main_url", URL, true); }); if(FW::call(0) == "listunsub") FW::require_class("email_list_unsub"); if(IS_GFX || IS_JS || IS_CSS): FW::require_class('minifier'); elseif(IS_BACKEND || IS_SVN): FW::require_class('backend'); FW::require_class("deferred_task_queue"); FW::require_class("site_log"); if(IS_SVN) ajax_svn_update($_GET); if(IS_AJAX) ajax::init(); else template::out('backend'); elseif((FW::s('devgate.enabled', true) || !issue_post::is_ready_for_live()) && (FW::s('devgate.user', 'developer') != M($_SESSION, 'devgate_user') || FW::s('devgate.pass', gen_password(6)) != M($_SESSION, 'devgate_pass')) && backend::getUser() === false ): template::out('devgate'); elseif(IS_AJAX): ajax::init(); else: FW::use_template('index'); if(IS_TWITTER) template::out(FW::use_template(), template::get("tw_callback")); else if(IS_INSTAGRAM) template::out(FW::use_template(), template::get("ig_callback")); else if(IS_PIXEL) template::out(FW::use_template(), template::get("c_pixel")); else{ $rout_path = PATH_THEME . 'index.php'; $route = FW::call(); if(IS_FACEBOOK) array_unshift($route, 'fb'); if(IS_FACEBOOK) array_unshift($route, 'facebook'); if(IS_FB_APP) array_unshift($route, 'app'); if(IS_FB_TAB) array_unshift($route, 'tab'); if(IS_MOBILE) array_unshift($route, 'mobile'); $tmp = FW::chk_route($route); FW::log($route, $tmp); $rout_path = $tmp ? $tmp : $rout_path; $content = FW::require_ob($rout_path); template::out(FW::use_template(), $content); } endif; $fw_run_timer = number_format((microtime(true) - $fw_run_timer) * 1000, 4); echo ""; /* echo " "; */ action::exec("end_of_request");