/** Get core application class @public **/ static function &getApplication() { static $app; // create if don't exists if (!is_object($app)) { // single app instance only if (isset($GLOBALS['_globalapp'])) { $app = $GLOBALS['_globalapp']; } else { $app = new Application(); // config $config =& Factory::getConfig(); $app->set('config', $config); // authentication $auth =& Factory::getAuth(); $app->set('auth', $auth); // set our timezone if (isset($config->timezone)) { @(list($tz_script, $tz_db) = explode('|', $config->timezone)); date_default_timezone_set($tz_script); } $GLOBALS['_globalapp'] = $app; } } return $app; }
/** Save session data @param $save_path string @param $sess_name string @abstract **/ function write($sess_id, $sess_data) { $auth =& Factory::getAuth(); // update expiry $expiry = time() + $this->__maxlife; // check if exists $sql = "SELECT count(*) as found" . "\n FROM {TABLE_PREFIX}_session" . "\n WHERE `sess_id` = " . $this->__db->Quote($sess_id); $this->__db->query($sql); $found = (int) $this->__db->result(); if ($found) { // update $sql = "UPDATE {TABLE_PREFIX}_session" . "\n SET `sess_expires` = " . $this->__db->Quote($expiry) . "\n ,`user_id` = " . $this->__db->Quote($auth->id) . "\n ,`sess_data` = " . $this->__db->Quote($sess_data) . "\n WHERE `sess_id` = " . $this->__db->Quote($sess_id); } else { $data = array('sess_expires' => $expiry, 'user_id' => $auth->id, 'sess_data' => $sess_data, 'sess_id' => $sess_id); $values = array(); foreach ($data as $k => &$v) { $k = $this->__db->NameQuote($k); $values[$k] = $this->__db->Quote($v); } $keys = implode(',', array_keys($values)); $values = implode(',', array_values($values)); // add $sql = "INSERT INTO {TABLE_PREFIX}_session({$keys})" . "\n VALUES({$values})"; } // commit $this->__db->query($sql); // get affected rows $result = $this->__db->affected_rows(); return $result; }
/** Check if currently-logged user has permission @param $task string @public **/ function hasPermission($task) { // get logged in user $auth =& Factory::getAuth(); if ($auth->level == 'admin') { return true; // always } if (isset($this->_perms['user'][$task][$auth->id])) { return $this->_perms['user'][$task][$auth->id]; } else { if (isset($this->_perms['role'][$task][$auth->level])) { return $this->_perms['role'][$task][$auth->level]; } } return false; }
/** Render module @param $module object @public **/ static function render($module, $custom = true) { $auth =& Factory::getAuth(); $config =& Factory::getConfig(); $html = ''; if (isset($module->access) && ($module->access && !$auth->loggedIn())) { // no access return $html; } if ($custom) { if ($module->id) { // get layout from current template $tpl_path = PATH_TEMPLATES . DS . $config->template . DS . 'module.php'; if (is_file($tpl_path)) { // set params $params = isset($module->params) ? $module->params : ''; $params = new Parameter($params); ob_start(); require $tpl_path; $html = ob_get_clean(); } else { // translate self::__translate($module); // just return the data $html = $module->data; // convert to SEF self::__getSEFURL($html); } } } else { $module_path = BASE_PATH . DS . 'templates' . DS . $config->template . DS . 'modules' . DS . @$module->name . DS . @$module->name . '.php'; // check admin $base_path = str_replace(DS . 'applications', '', PATH_APPLICATIONS); $base_path = str_replace(BASE_PATH, '', $base_path); $base_path = str_replace(DS, '/', $base_path); if ($base_path == $config->admin_path) { $module_path = null; } if (!is_file($module_path)) { $module_path = PATH_MODULES . DS . $module->name . DS . $module->name . '.php'; } if (is_file($module_path)) { ob_start(); // load module include $module_path; $html = ob_get_clean(); } } return $html; }