/** * @internal Starts the session handler. */ function session_run() { global $CONFIG; // check for backwards compatibility if (isset($CONFIG['session']['usephpsession'])) { if ($CONFIG['session']['usephpsession'] && $CONFIG['session']['handler'] != "PhpSession" || !$CONFIG['session']['usephpsession'] && $CONFIG['session']['handler'] == "PhpSession") { WdfException::Raise('Do not use $CONFIG[\'session\'][\'usephpsession\'] anymore! See session_init() for details.'); } } $CONFIG['session']['handler'] = fq_class_name($CONFIG['session']['handler']); $GLOBALS['fw_session_handler'] = new $CONFIG['session']['handler'](); // if( system_is_ajax_call() && isset($_SESSION['object_id_storage']) ) if (isset($_SESSION['object_id_storage'])) { $GLOBALS['object_ids'] = $_SESSION['object_id_storage']; } }
function __initialize($title = "", $body_class = false) { global $CONFIG; // sometimes state-/UI-less sites (like APIs) trickout the AJAX detection by setting this. // as we need UI this must be reset here unset($GLOBALS['result_of_system_is_ajax_call']); header("Content-Type: text/html; charset=utf-8"); // overwrite previously set header to ensure we deliver HTML unset($CONFIG["use_compiled_js"]); unset($CONFIG["use_compiled_css"]); if (current_event(true) != 'login' && (!isset($_SESSION['admin_handler_username']) || !isset($_SESSION['admin_handler_password']) || $_SESSION['admin_handler_username'] != $CONFIG['system']['admin']['username'] || $_SESSION['admin_handler_password'] != $CONFIG['system']['admin']['password'])) { log_debug(current_event(true)); log_debug($_SESSION['admin_handler_username']); log_debug($_SESSION['admin_handler_password']); redirect('sysadmin', 'login'); } parent::__initialize("SysAdmin - {$title}", 'sysadmin'); $this->_translate = false; if (current_event(true) != 'login') { $nav = parent::content(new Control('div')); $nav->class = "navigation"; foreach ($CONFIG['system']['admin']['actions'] as $label => $def) { if (!class_exists(fq_class_name($def[0]))) { continue; } $nav->content(new Anchor(buildQuery($def[0], $def[1]), $label)); } $nav->content(new Anchor(buildQuery('sysadmin', 'cache'), 'Cache')); $nav->content(new Anchor(buildQuery('sysadmin', 'phpinfo'), 'PHP info')); $nav->content(new Anchor(buildQuery('translationadmin', 'newstrings'), 'Translations')); $nav->content(new Anchor(buildQuery('sysadmin', 'testing'), 'Testing')); $nav->content(new Anchor(buildQuery('', ''), 'Back to app')); $nav->content(new Anchor(buildQuery('sysadmin', 'logout'), 'Logout', 'logout')); $this->_subnav = parent::content(new Control('div')); } $this->_contentdiv = parent::content(new Control('div'))->addClass('content'); $copylink = new Anchor('http://www.scavix.com', '© 2012-' . date('Y') . ' Scavix® Software Ltd. & Co. KG'); $copylink->target = '_blank'; $footer = parent::content(new Control('div'))->addClass('footer'); $footer->content("<br class='clearer'/>"); $footer->content($copylink); if (current_event() == strtolower($CONFIG['system']['default_event']) && !system_method_exists($this, current_event())) { redirect('sysadmin', 'index'); } }
/** * @internal Collects dependencies from a file */ function minify_collect_from_file($kind, $f, $debug_path = '') { global $dependency_info, $res_file_storage, $ext_resources; if (!$f) { return; } $classname = fq_class_name(array_shift(explode('.', basename($f)))); if (isset($res_file_storage[$classname]) || minify_forbidden($classname)) { return; } $order = array('static', 'inherited', 'instanciated', 'self'); //:array('self','incontent','instanciated','inherited'); $res_file_storage[$classname] = array(); $content = file_get_contents($f); // remove block-comments $content = preg_replace("|/\\*.*\\*/|sU", "", $content); do { $c2 = preg_replace("|(.*)//.*\$|m", "\$1", $content); if ($content == $c2) { break; } $content = $c2; } while (true); foreach ($order as $o) { switch ($o) { case 'inherited': if (preg_match_all('/class\\s+[^\\s]+\\s+extends\\s+([^\\s]+)/', $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { $file_for_class = __search_file_for_class($m[1]); if (!$file_for_class) { continue; } $dependency_info[$classname][] = strtolower($m[1]); minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname); } } break; case 'instanciated': $matches = array(); if (preg_match_all('/new\\s+([^\\(]+)\\(/', $content, $by_new, PREG_SET_ORDER)) { $matches = array_merge($matches, $by_new); } if (preg_match_all('/\\s+([^:\\s\\(\\)]+)::Make\\(/Ui', $content, $by_make, PREG_SET_ORDER)) { $matches = array_merge($matches, $by_make); } if (count($matches) > 0) { foreach ($matches as $m) { $file_for_class = __search_file_for_class($m[1]); if (!$file_for_class) { continue; } $dependency_info[$classname][] = strtolower($m[1]); minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname); } } break; case 'self': $simplecls = array_pop(explode("\\", $classname)); if (resourceExists(strtolower("{$simplecls}.{$kind}"))) { $tmp = resFile(strtolower("{$simplecls}.{$kind}")); if (!in_array($tmp, $res_file_storage[$classname])) { $res_file_storage[$classname][] = $tmp; } } break; case 'static': try { foreach (ResourceAttribute::Collect($classname) as $resource) { $b = $resource->Resolve(); if ($resource instanceof \ScavixWDF\Reflection\ExternalResourceAttribute) { $ext_resources[] = $b; continue; } if (!ends_with($b, $kind)) { continue; } $b = strtolower($b); if (!in_array($b, $res_file_storage[$classname])) { $res_file_storage[$classname][] = $b; } } } catch (Exception $ex) { } break; } } }
/** * Parses the request and returns a controller/event pair (if present). * * Note that your .htaccess files must contain these lines: * <code> * SetEnv WDF_FEATURES_REWRITE on * RewriteCond %{REQUEST_FILENAME} !-f * RewriteCond %{REQUEST_FILENAME} !-d * RewriteCond %{REQUEST_URI} !index.php * RewriteRule (.*) index.php?wdf_route=$1 [L,QSA] * </code> * @return void */ function system_parse_request_path() { if (isset($_REQUEST['wdf_route'])) { // test for *.less request -> need to compile that to css if (ends_iwith($_REQUEST['wdf_route'], ".less")) { $GLOBALS['routing_args'] = array($_REQUEST['wdf_route']); unset($_REQUEST['wdf_route']); unset($_GET['wdf_route']); return array('ScavixWDF\\WdfResource', 'CompileLess'); } // now for the normal processing $wdf_route = $_REQUEST['wdf_route']; $GLOBALS['wdf_route'] = $path = explode("/", $_REQUEST['wdf_route'], 3); unset($_REQUEST['wdf_route']); unset($_GET['wdf_route']); if (count($path) > 0) { if ($path[0] == '~') { $path[0] = cfg_get('system', 'default_page'); } $path[0] = fq_class_name($path[0]); if (class_exists($path[0]) || in_object_storage($path[0])) { $controller = $path[0]; if (count($path) > 1) { $event = $path[1]; if (count($path) > 2) { foreach (array_slice($path, 2) as $ra) { if ($ra) { $GLOBALS['routing_args'][] = $ra; } } } } } } } if (!isset($controller) || !$controller) { $controller = Args::request('page', cfg_get('system', 'default_page')); } // really oldschool if (!isset($event) || !$event) { $event = Args::request('event', cfg_get('system', 'default_event')); } // really oldschool $pattern = '/[^A-Za-z0-9\\-_\\\\]/'; $controller = substr(preg_replace($pattern, "", $controller), 0, 256); $event = substr(preg_replace($pattern, "", $event), 0, 256); return array($controller, $event); }
private function __collectResourcesInternal($template) { $res = array(); if (is_object($template)) { $classname = get_class($template); // first collect statics from the class definitions $static = ResourceAttribute::ResolveAll(ResourceAttribute::Collect($classname)); $res = array_merge($res, $static); if ($template instanceof Renderable) { // then check all contents and collect theis includes foreach ($template->__getContentVars() as $varname) { $sub = array(); foreach ($template->{$varname} as $var) { if (is_object($var) || is_array($var)) { $sub = array_merge($sub, $this->__collectResourcesInternal($var)); } } $res = array_merge($res, $sub); } // for Template class check the template file too if ($template instanceof Template) { $fnl = strtolower(array_shift(explode(".", basename($template->file)))); if (get_class_simple($template, true) != $fnl) { if (resourceExists("{$fnl}.css")) { $res[] = resFile("{$fnl}.css"); } elseif (resourceExists("{$fnl}.less")) { $res[] = resFile("{$fnl}.less"); } if (resourceExists("{$fnl}.js")) { $res[] = resFile("{$fnl}.js"); } } } // finally include the 'self' stuff (<classname>.js,...) // Note: these can be forced to be loaded in static if they require to be loaded before the contents resources $classname = get_class_simple($template); $parents = array(); $cnl = strtolower($classname); do { if (resourceExists("{$cnl}.css")) { $parents[] = resFile("{$cnl}.css"); } elseif (resourceExists("{$cnl}.less")) { $parents[] = resFile("{$cnl}.less"); } if (resourceExists("{$cnl}.js")) { $parents[] = resFile("{$cnl}.js"); } $classname = array_pop(explode('\\', get_parent_class(fq_class_name($classname)))); $cnl = strtolower($classname); } while ($classname != ""); $res = array_merge($res, array_reverse($parents)); } } elseif (is_array($template)) { foreach ($template as $var) { if (is_object($var) || is_array($var)) { $res = array_merge($res, $this->__collectResourcesInternal($var)); } } } return array_unique($res); }
/** * Parses the request and returns a controller/event pair (if present). * * Note that your .htaccess files must contain these lines: * <code> * SetEnv WDF_FEATURES_REWRITE on * RewriteCond %{REQUEST_FILENAME} !-f * RewriteCond %{REQUEST_FILENAME} !-d * RewriteCond %{REQUEST_URI} !index.php * RewriteRule (.*) index.php?wdf_route=$1 [L,QSA] * </code> * @return void */ function system_parse_request_path() { if (isset($_REQUEST['wdf_route'])) { $GLOBALS['wdf_route'] = $path = explode("/", $_REQUEST['wdf_route'], 3); unset($_REQUEST['wdf_route']); unset($_GET['wdf_route']); if (count($path) > 0) { if ($path[0] == '~') { $path[0] = cfg_get('system', 'default_page'); } $path[0] = fq_class_name($path[0]); if (class_exists($path[0]) || in_object_storage($path[0])) { $controller = $path[0]; if (count($path) > 1) { $event = $path[1]; if (count($path) > 2) { foreach (array_slice($path, 2) as $ra) { if ($ra) { $GLOBALS['routing_args'][] = $ra; } } } } } } } if (!isset($controller) || !$controller) { $controller = Args::request('page', cfg_get('system', 'default_page')); } // really oldschool if (!isset($event) || !$event) { $event = Args::request('event', cfg_get('system', 'default_event')); } // really oldschool $pattern = '/[^A-Za-z0-9\\-_\\\\]/'; $controller = substr(preg_replace($pattern, "", $controller), 0, 256); $event = substr(preg_replace($pattern, "", $event), 0, 256); return array($controller, $event); }
/** * Get a database connection. * * @param string $name The datasource alias. * @return DataSource The database connection */ function &model_datasource($name) { global $MODEL_DATABASES; if (strpos($name, "DataSource::") !== false) { $name = explode("::", $name); $name = $name[1]; } if (!isset($MODEL_DATABASES[$name])) { if (function_exists('model_on_unknown_datasource')) { $res = model_on_unknown_datasource($name); return $res; } log_fatal("Unknown datasource '{$name}'!"); $res = null; return $res; } if (is_array($MODEL_DATABASES[$name])) { list($dstype, $constr) = $MODEL_DATABASES[$name]; $dstype = fq_class_name($dstype); $model_db = new $dstype($name, $constr); if (!$model_db) { WdfDbException::Raise("Unable to connect to database '{$name}'."); } $MODEL_DATABASES[$name] = $model_db; } return $MODEL_DATABASES[$name]; }
private function _getAttributes($comment, $filter, $object = false, $method = false, $field = false, $allowAttrInheritance = true) { $pattern = '/@attribute\\[([^\\]]*)\\]/im'; if (!preg_match_all($pattern, $comment, $matches)) { return array(); } if (!is_array($filter)) { $filter = array($filter); } foreach ($filter as $i => $f) { $filter[$i] = strtolower(str_replace("Attribute", "", $f)); } $res = array(); $pattern = '/([^\\(]*)\\((.*)\\)/im'; foreach ($matches[1] as $m) { $m = trim($m); if (preg_match_all($pattern, $m, $inner)) { $name = str_replace("Attribute", "", $inner[1][0]); $attr = $name . "Attribute({$inner[2][0]})"; } else { $name = str_replace("Attribute", "", $m); $attr = $name . "Attribute()"; } if (!__search_file_for_class($name . "Attribute")) { if ($name != 'NoMinify') { log_trace("Invalid Attribute: {$m} ({$name}Attribute) found in Comment '{$comment}'"); } continue; } $parts = explode("(", $attr, 2); $attr = fq_class_name($parts[0]) . "(" . $parts[1]; eval('$attr = new ' . $attr . ';'); $name = strtolower($name); $add = count($filter) == 0; foreach ($filter as $f) { if ($f == $name || $allowAttrInheritance && is_subclass_of($attr, $f . "Attribute")) { $add = true; break; } } if ($add) { $attr->Reflector = $this; $attr->Class = $this->Classname; if ($object && is_object($object)) { $attr->Object = $object; } if ($method) { $attr->Method = $method; } if ($field) { $attr->Field = $field; } $res[] = $attr; } } return $res; }
/** * Instanciates and return a <Logger> from a given config. * * @param array $config Logger configuration data * @return mixed The logger, may be of type <Logger> or whatever is specified in `$config['class']` */ public static function Get($config) { if (count(self::$FilenamePatterns) == 0) { foreach ($_SERVER as $k => $v) { self::$FilenamePatterns[$k] = $v; } } if (isset($config['class'])) { $log_cls = fq_class_name($config['class']); $res = new $log_cls($config); } else { $res = new Logger($config); } self::$Instances[] = $res; return $res; }