/** * 是否有权限 */ public static function checkRight($thisRoute = null) { // 用户资源 $userData = CSession::get('user'); if ($userData['groupId'] == 1) { return true; } $userRightList = isset($userData['rightAll']) ? $userData['rightAll'] : array(); // 附加公共资源 array_push($userRightList, 'system@welcome'); array_push($userRightList, 'system@navList'); array_push($userRightList, 'system@addNav'); array_push($userRightList, 'system@addNavHandle'); array_push($userRightList, 'system@ajaxAddNav'); array_push($userRightList, 'system@editNav'); array_push($userRightList, 'system@editNavHandle'); array_push($userRightList, 'system@delNav'); array_push($userRightList, 'system@changeMyPassword'); array_push($userRightList, 'system@changeMyPassHandle'); array_push($userRightList, 'adminRole@messageCenterForClient'); array_push($userRightList, 'system@seeHelp'); // 转小写 foreach ($userRightList as $key => $val) { $userRightList[$key] = strtolower($val); } // 获取当前请求的路由 if ($thisRoute == null) { $route = CRequest::getController() . '@' . str_replace(CConfig::getInstance()->load('ACTION_PREFIX'), '', CRequest::getAction()); } else { $route = $thisRoute; } return in_array(strtolower($route), $userRightList); }
public function display($templateName = '', $isCache = false, $num = '') { if (empty($templateName)) { $templateName = CRequest::getController() . '/' . str_replace(CConfig::getInstance()->load('ACTION_PREFIX'), '', CRequest::getAction()); } parent::display($templateName, $isCache, $num); }
/** * 构造函数,实列化存放路径 */ function __construct() { $configPath = CConfig::getInstance()->load('CACHE.FILE_PATH'); $this->_path = !empty($configPath) ? $configPath : $this->_path; if (!file_exists($this->_path)) { mkdir($this->_path, 0755, true); } }
/** * 查询单条 */ public function find($condition, $params, $asArray = true) { $this->condition = $condition; $this->params = $params; $dbConfig = CConfig::getInstance()->load('DB.main.slaves'); $tablePre = isset($dbConfig['tablePrefix']) ? $dbConfig['tablePrefix'] : ''; $findSql = 'SELECT * FROM ' . $tablePre . $this->_getTableName() . ' WHERE ' . $condition . ' LIMIT 1 '; $findObject = CDatabase::getInstance()->prepare($findSql)->execute($params); $this->arResult = $findObject->asArray(); return $this; }
/** * 判断是否内部IP */ public static function isInternalIP($ip = null) { if (empty($ip)) { $ip = CRequest::getIp(); } $internalIp = array('125.71.211.185'); //获取内部IP $setIP = CConfig::getInstance('site')->load('ipList'); if (!empty($setIP) && is_array($setIP)) { $internalIp = $setIP; } if (in_array($ip, $setIP)) { return true; } return false; }
/** * 设置基础数据 */ public static function setInitData($viewObject) { $prefix = CConfig::getInstance()->load('ACTION_PREFIX'); $viewObject->assign('thisUrl', urlencode(CRequest::getUrl())); $viewObject->assign('base64Url', CEncrypt::safe_b64encode(CRequest::getUrl())); $viewObject->assign('controller', CRequest::getController()); $viewObject->assign('action', CRequest::getAction()); $viewObject->assign('actionPre', $prefix); $viewObject->assign('ip', CRequest::getIp()); $viewObject->assign('module', CRequest::getModule()); $viewObject->assign('time', time()); $viewObject->assign('sessionID', session_id()); $viewObject->assign('path', CRequest::getPath()); $viewObject->assign('staticUrl', CConfig::getInstance('site')->load('staticUrl')); $viewObject->assign('uploadStaticUrl', CConfig::getInstance('site')->load('uploadStaticUrl')); $viewObject->assign('siteName', CConfig::getInstance('site')->load('siteName')); }
/** * 自动加载 */ public function load($className) { //优先使用映射集合 if (isset(self::$_loadMapp[$className])) { return CLoader::import($className, self::$_loadMapp[$className]); } else { if (file_exists($path = APP_PATH . '/modules/' . CRoute::getInstance()->getModule() . '/controllers/' . $className . '.php')) { return CLoader::importFile($path); } else { if (file_exists($path = APP_PATH . '/modules/' . CRoute::getInstance()->getModule() . '/classes/' . $className . '.php')) { return CLoader::importFile($path); } else { if (file_exists($path = CODE_PATH . '/controllers/' . $className . '.php')) { return CLoader::importFile($path); } else { if (file_exists($path = FRAME_PATH . '/components/' . $className . '.php')) { return CLoader::importFile($path); } else { $list = array(); $importList = CConfig::getInstance()->load('IMPORT'); if (!empty($importList)) { foreach ((array) $importList as $thisPath) { $list[] = APP_PATH . '/' . str_replace(array('.', '*'), array('/', ''), $thisPath); } } //查询指定的加载目录 foreach ($list as $val) { if (file_exists($path = $val . $className . '.php')) { return CLoader::importFile($path); } else { if (false !== strpos($className, '_')) { //处理类名中的路径 $path = str_replace('_', '/', $className); if (file_exists($path = trim($val, '/\\') . '/' . $path . '.php')) { return CLoader::importFile($path); } } } } } } } } } }
/** * 请求单列 */ public static function getInstance($type = null) { if (null == $type) { //默认使用memcahe $type = 'memcache'; //获取默认设置 $defaultCacheType = CConfig::getInstance()->load('CACHE.DEFAULT_CACHE'); if (!empty($defaultCacheType)) { $type = $defaultCacheType; } } if (!isset(self::$instance[$type]) || null == self::$instance[$type]) { //初始自身 self::$instance[$type] = new self($type); return self::$instance[$type]; } return self::$instance[$type]; }
/** * 加载插件 */ public static function loadPlugin() { $loadPlugin = CConfig::getInstance()->load('LOAD_PLUGIN'); $loadList = CConfig::getInstance()->load('LOAD_LIST'); if (false === $loadPlugin) { return false; } $pluginPath = APP_PATH . '/plugins/'; $confPath = CConfig::getInstance()->load('PLUGIN_PATH'); if (null != $confPath) { $pluginPath = APP_PATH . '/' . trim($confPath) . '/'; } //定义插件宏 define('CPLUGIN_PATH', $pluginPath); $hooksFile = self::_getPathFile($pluginPath, $loadList); foreach ($hooksFile as $val) { $pluginRegisterFilePath = $pluginPath . $val . '/' . $val . '.php'; if (!file_exists($pluginRegisterFilePath)) { self::$_failLoadPluginList[] = array('pluginName' => $val); continue; } CLoader::importFile($pluginRegisterFilePath); $thisPluginObject = new $val(); $thisPluginReflection = new ReflectionClass($thisPluginObject); $isSubCPlugin = $thisPluginReflection->isSubclassOf('CPlugin'); if (false == $isSubCPlugin) { self::$_failLoadPluginList[] = $val; continue; } $thisPluginObject->setHooks(); $thisPluginData['pluginName'] = isset($thisPluginObject->pluginName) ? $thisPluginObject->pluginName : ''; $thisPluginData['author'] = isset($thisPluginObject->author) ? $thisPluginObject->author : ''; $thisPluginData['version'] = isset($thisPluginObject->version) ? $thisPluginObject->version : ''; $thisPluginData['copyright'] = isset($thisPluginObject->copyright) ? $thisPluginObject->copyright : ''; $thisPluginData['date'] = isset($thisPluginObject->date) ? $thisPluginObject->date : ''; $thisPluginData['description'] = isset($thisPluginObject->description) ? $thisPluginObject->description : ''; self::$_pluginList[] = $thisPluginData; } }
/** * 创建Redis连接 */ private function _getRedisConnection() { //默认参数 $redisHost = '127.0.0.1'; $redisPort = 6379; $timeout = 3; //配置参数 $setRedisHost = CConfig::getInstance()->load('REDIS_HOST'); $setRedisPort = CConfig::getInstance()->load('REDIS_PORT'); $setTimeout = CConfig::getInstance()->load('REDIS_TIMEOUT'); if (!empty($setRedisHost)) { $redisHost = $setRedisHost; } if (!empty($setRedisPort)) { $redisPort = $setRedisPort; } if (!empty($setTimeout)) { $timeout = $setTimeout; } //连接Redis $redisObject = new Redis(); $redisObject->connect($redisHost, $redisPort, $timeout); return $redisObject; }
/** * 设置Session */ private function _initSession() { $sessionMemcache = CConfig::getInstance()->load('SESSION_MEMCACHE'); //使用memcacheSession if (extension_loaded('memcache') && $sessionMemcache == true) { $sessionHost = CConfig::getInstance()->load('SESSION_MEMCAHCE_HOST'); ini_set("session.save_handler", "memcache"); ini_set("session.save_path", "tcp://" . $sessionHost); } $autoSession = CConfig::getInstance()->load('AUTO_SESSION'); if (!empty($autoSession) && true == $autoSession) { session_start(); return true; } return false; }
/** * CMyFrame 默认错误呈现 */ public static function showErrorsView() { //调试配置项 $debug = CConfig::getInstance()->load('DEBUG'); //调试模式 if (true == $debug) { //获取视图对象 $view = CView::factory('smarty'); //克隆视图对象 $pluginView = clone $view; $pluginView->template_dir = FRAME_PATH . '/exception/'; //错误记录 $categoryError = self::_categoryError(); if (empty($categoryError)) { return false; } //加载文件 $includeFiles = get_included_files(); $pluginView->assign('errorloadfile', $includeFiles); $pluginView->assign('error', $categoryError); $pluginView->display('CErrorView.html'); } }
/** * 解析路由 */ public static function getRoute() { if (isset($_GET['c']) && isset($_GET['a'])) { if (!isset($_GET['m']) || empty($_GET['m'])) { $subdomain = self::getSubdomain(); $_GET['m'] = isset($subdomain['m']) ? $subdomain['m'] : $GLOBALS['CONF']['DEFAULT_MODLUE']; } $_GET[0] = $_GET['c']; $_GET[1] = $_GET['a']; return $_GET; } $URL = str_replace(array(':'), array('%3A'), self::requestURI()); $params = array(); //过滤检测 self::SQLInjectionCheck(); $urlArr = parse_url($URL); if (false == $urlArr) { throw new CException('[路由错误]服务器无法解析该次请求'); } if (isset($urlArr['query'])) { $paramsCut = explode('&', $urlArr['query']); foreach ($paramsCut as $val) { $paramMap = explode('=', $val); if (isset($paramMap[0]) && count($paramMap) == 2) { $params[$paramMap[0]] = isset($paramMap[1]) ? $paramMap[1] : null; } else { if (isset($paramMap[0]) && count($paramMap) > 2) { //当一个参数序列中含有多个= $firstEq = strpos($val, '='); $thisKey = substr($val, 0, $firstEq); $thisVal = substr($val, $firstEq + 1, strlen($val)); $params[$thisKey] = $thisVal; } } } } $urlPath = trim($urlArr['path'], '\\/'); $urlKey = $urlPath; if ($urlKey == '') { $urlKey = 'index'; } if ($urlPath == '/' || $urlPath == '' || in_array($urlPath, CConfig::getInstance()->load('ALLOW_INDEX'))) { $subdomain = self::getSubdomain(); $base = array('0' => CConfig::getInstance()->load('DEFAULT_CONTROLLER'), '1' => CConfig::getInstance()->load('DEFAULT_ACTION'), 'm' => isset($subdomain['m']) ? $subdomain['m'] : CConfig::getInstance()->load('DEFAULT_MODLUE')); $_GET = array_merge($base, $params); return array_merge($base, $params); } $rewriteArr = CConfig::getInstance()->load('URLRewrite.LIST'); foreach ($rewriteArr as $regPattern => $val) { $ControllerAction = explode('@', $val); $regPatternReplace = preg_replace("%<\\w+?:(.*?)>%", "(\$1)", $regPattern); if (strpos($regPatternReplace, '%') !== false) { $regPatternReplace = str_replace('%', '\\%', $regPatternReplace); } ///echo "%$regPatternReplace%".'-'.$urlPath.'<br>'; if (preg_match("%{$regPatternReplace}%", $urlPath, $matchValue)) { $matchAll = array_shift($matchValue); if ($matchAll != $urlPath) { continue; } if ($matchValue) { preg_match_all("%<\\w+?:.*?>%", $regPattern, $matchReg); foreach ($matchReg[0] as $key => $val) { $val = trim($val, '<>'); $tempArray = explode(':', $val, 2); $urlArray[$tempArray[0]] = isset($matchValue[$key]) ? $matchValue[$key] : ''; } } if (isset($urlArray[self::$UrlCtrlName]) && !preg_match("%^\\w+\$%", $urlArray[self::$UrlCtrlName]) || isset($urlArray[self::$UrlActionName]) && !preg_match("%^\\w+\$%", $urlArray[self::$UrlActionName])) { $urlArray = array(); continue; } foreach ($ControllerAction as $key => $val) { $paramName = trim($val, '<>'); if ($val != $paramName && isset($urlArray[$paramName])) { $ControllerAction[$key] = $urlArray[$paramName]; } } if (isset($urlArray) && is_array($urlArray)) { $urlResArr = array_merge($ControllerAction, $urlArray); } if (isset($urlResArr) && isset($params)) { $urlResArr = array_merge($urlResArr, $params); } $subdomain = self::getSubdomain(); if (!empty($urlResArr)) { $urlResArr = array_merge($urlResArr, $subdomain); self::_setCacheRoute($urlKey, $urlResArr); $_GET = $urlResArr; return isset($urlResArr) ? $urlResArr : array(); } else { if (!empty($ControllerAction)) { $urlResArr = array_merge($ControllerAction, $params); $urlResArr = array_merge($urlResArr, $subdomain); $_GET = $urlResArr; return isset($urlResArr) ? $urlResArr : array(); } } } } /** * 无路由规则 */ if (empty($urlResArr)) { $urlPathTemp = explode('.', $urlPath); $urlPath = isset($urlPathTemp[0]) ? $urlPathTemp[0] : $urlPath; $tempArr = explode('/', $urlPath); if (isset($tempArr[0]) && isset($tempArr[1])) { $urlResArr[0] = $tempArr[0]; $urlResArr[1] = $tempArr[1]; unset($tempArr[0]); unset($tempArr[1]); for ($i = 2; $i < count($tempArr) + 2; $i++) { $paramVal = $i + 1; if (isset($tempArr[$paramVal]) && $i % 2 == 0) { if ('null' == strtolower($tempArr[$paramVal])) { $tempArr[$paramVal] = ''; } $urlResArr[$tempArr[$i]] = $tempArr[$paramVal]; } } } else { if (isset($tempArr[0]) && !isset($tempArr[1])) { $urlResArr[0] = $tempArr[0]; $urlResArr[1] = CConfig::getInstance()->load('DEFAULT_ACTION'); } } $subdomain = self::getSubdomain(); $urlResArr['m'] = $subdomain['m']; if (is_array($params)) { $urlResArr = array_merge($urlResArr, $params); } if (!empty($urlResArr)) { self::_setCacheRoute($urlKey, $urlResArr); } $_GET = $urlResArr; return isset($urlResArr) ? $urlResArr : array(); } return array('0' => '', '1' => '', 'm' => ''); }
/** * 阻止敏感URL函数 */ static function StopAttack($StrFiltKey, $StrFiltValue, $ArrFiltReq) { if (is_array($StrFiltValue)) { $StrFiltValue = implode($StrFiltValue); } if (preg_match("/" . $ArrFiltReq . "/is", $StrFiltValue) == 1) { if (true != CConfig::getInstance()->load('ACCEPT_INJECTION_URI')) { throw new CRouteException('该请求地址可能存在安全隐含,已被管理员拒绝!'); } } }
/** * 执行路由 */ private function routeDoing($routeObject) { //检查模块 $defaultModule = CConfig::getInstance()->load('DEFAULT_MODLUE'); $routeModule = $routeObject->getModule(); $routeController = $routeObject->getController(); $module = !empty($routeModule) ? $routeObject->getModule() : $defaultModule; //实例化控制器 if (!empty($routeController)) { //是否使用子域名模块路由 $useModule = CConfig::getInstance()->load('USE_MODULE'); //非主模块时 if ($defaultModule == $module || $useModule == false) { if (file_exists($controllerPath = CODE_PATH . '/controllers/' . $routeController . '.php')) { $this->createController($controllerPath, $routeController); } else { if (isset($GLOBALS['CONF']['CONTROLLER_MAPPING'][$routeController])) { if (file_exists($controllerPath = APP_PATH . '/' . $GLOBALS['CONF']['CONTROLLER_MAPPING'][$routeController] . '/controllers/' . $routeController . '.php')) { $this->createController($controllerPath, $routeController); } } else { throw new CRouteException('[路由错误]未被定义的控制器: "' . $routeController . '"'); } } } else { if (is_dir($modulePath = APP_PATH . '/modules/' . $module)) { //检查模块内的控制器 if (file_exists($controllerPath = $modulePath . '/controllers/' . $routeController . '.php')) { $this->createController($controllerPath, $routeController); } else { throw new CRouteException('[路由错误]模块 (' . $module . ')中未定义的控制器: "' . $routeController . '"'); } } else { throw new CRouteException('[路由错误]请求不存在的模块: ' . $module); } } } else { throw new CRouteException('[路由错误]请求的路径、文件不存在或无访问权限'); } }
/** * 获取方法列表 */ private function _getActionList($controllerName) { // 控制器前缀 $actionPre = CConfig::getInstance()->load('ACTION_PREFIX'); // 获取该对象下的方法 $action = array(); $list = get_class_methods($controllerName); if (empty($actionPre)) { return $list; } foreach ((array) $list as $val) { if (false !== strpos($val, $actionPre)) { $action[] = str_replace($actionPre, '', $val); } } return $action; }
/** * 构造 */ public function __construct($viewName) { $this->_viewName = $viewName; $viewConfigs = CConfig::getInstance()->load('TEMPLATE'); if (!isset($viewConfigs[$viewName])) { trigger_error('[视图错误]使用配置中不存在的模板引擎:' . $viewName, E_USER_ERROR); } $thisViewConfig = $viewConfigs[$viewName]; $templatePath = isset($thisViewConfig['TEMPLATE_PATH']) ? $thisViewConfig['TEMPLATE_PATH'] : ''; $viewConfItem = isset($thisViewConfig['CONF_INFO']) ? $thisViewConfig['CONF_INFO'] : array(); if (!file_exists($templatePath)) { trigger_error('[视图错误]未能找到指定模板引擎[' . $viewName . ']的主文件:' . $templatePath, E_USER_ERROR); } CLoader::importFile($templatePath); $viewObject = new $viewName(); if ('smarty' == $viewName) { $viewObject->template_dir = $viewConfItem['template_dir']; //编译目录 $compile_dir = $viewConfItem['compile_dir']; if (!is_dir($compile_dir)) { if (false == mkdir($compile_dir, true, 0755)) { echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>[部署错误]CMyFrame无法创建缓存目录,请确定服务器权限'; exit; } chmod($compile_dir, 0777); } $viewObject->compile_dir = $compile_dir; //缓存目录 $cache_dir = $viewConfItem['cache_dir']; if (!is_dir($cache_dir)) { if (false == mkdir($cache_dir, true, 0755)) { echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>[部署错误]CMyFrame无法创建缓存目录,请确定服务器权限'; exit; } chmod($cache_dir, 0777); } $viewObject->cache_dir = $cache_dir; //分隔符 $viewObject->left_delimiter = $viewConfItem['left_delimiter']; $viewObject->right_delimiter = $viewConfItem['right_delimiter']; //使用PHP语法 $viewObject->allow_php_tag = $viewConfItem['allow_php_tag']; //缓冲 $viewObject->caching = $viewConfItem['caching']; $viewObject->cache_lifetime = $viewConfItem['cache_lifetime']; //注册函数 $viewObject->register_function('url', array('CRequest', 'createUrl')); $viewObject->register_function('PageInfo', array('CSmarty', 'showPageData')); $viewObject->register_function('substr', array('CSmarty', 'cn_substr')); $viewObject->register_function('sayTime', array('CSmarty', 'sayTime')); //注册块函数 $viewObject->register_block('checkRight', array('CSmarty', 'checkRight')); //设置默认数据 CSmarty::setInitData($viewObject); } else { //设置所有配置项 foreach ((array) $viewConfItem as $key => $val) { $viewObject->{$key} = $val; } } //第一次获取视图时 CHooks::callHooks(HOOKS_VIEW_GET, $viewObject); $this->_viewObject = $viewObject; }
/** * 获取PDO对象 */ public static function getDatabase($configName = 'main', $isMaster = true) { if (empty($configName)) { $configName = 'main'; } if (isset(self::$objectPdo[intval($isMaster) . $configName])) { return self::$objectPdo[intval($isMaster) . $configName]; } $dbConfig = CConfig::getInstance()->load('DB.' . $configName); if (!isset($dbConfig['master'])) { throw new CDbException('[配置错误]getDataBase方法尝试获取不存在的配置项:[Config->DB->master]'); } if (true == $isMaster) { $thisConfigData = $dbConfig['master']; self::$configData[intval($isMaster) . $configName] = $thisConfigData; self::$configData[intval(!$isMaster) . $configName] = $dbConfig['slaves']; } if (false == $isMaster) { $thisConfigData = !isset($dbConfig['slaves']) ? $dbConfig['master'] : $dbConfig['slaves']; self::$configData[intval($isMaster) . $configName] = $thisConfigData; self::$configData[intval(!$isMaster) . $configName] = $dbConfig['master']; } try { $pdoObject = new PDO($thisConfigData['connectionString'], $thisConfigData['username'], $thisConfigData['password']); $pdoObject->query('set names ' . $thisConfigData['charset']); } catch (PDOException $pdoException) { //尝试启用备用库 if (true == $isMaster) { //是否允许启用备库 $writeConf = self::$configData[intval($isMaster) . $configName]; if (isset($writeConf['slavesWrite']) && true == $writeConf['slavesWrite']) { //尝试连接备库 try { //从库配置 $slaverConf = self::$configData[intval(!$isMaster) . $configName]; $pdoObject = new PDO($slaverConf['connectionString'], $slaverConf['username'], $slaverConf['password']); $pdoObject->query('set names ' . $slaverConf['charset']); } catch (PDOException $pdoExceptionAgain) { $dbError = new CDBError(); $dbError->setSQLErrorCode('CMyFrame'); $dbError->setDriverErrorCode('CMyFrame'); $dbError->setErrorMessage('主库连接失败后,尝试连接从库,连接从库依旧失败'); CHooks::callHooks(HOOKS_EXECUTE_ERROR, $dbError); //切换数据依旧无法连接 throw new CDbException('[数据库错误]主库连接失败后,尝试连接从库依旧失败:' . $pdoExceptionAgain->getMessage()); } } else { //不允许使用备库 $dbError = new CDBError(); $dbError->setSQLErrorCode('CMyFrame'); $dbError->setDriverErrorCode('CMyFrame'); $dbError->setErrorMessage('主库连接失败后,不允许尝试连接从库'); CHooks::callHooks(HOOKS_EXECUTE_ERROR, $dbError); throw new CDbException('[数据库错误]连接主数据库失败,且不允许尝试使用从库:' . $pdoException->getMessage()); } } else { //是否使用主库进行读取 $readConf = self::$configData[intval($isMaster) . $configName]; if (isset($readConf['masterRead']) && true == $readConf['masterRead']) { $errorMessage = '从库连接失败后,尝试连接主库,主库连接成功'; try { //主库配置 $masterConf = self::$configData[intval(!$isMaster) . $configName]; $pdoObject = new PDO($masterConf['connectionString'], $masterConf['username'], $masterConf['password']); $pdoObject->query('set names ' . $masterConf['charset']); } catch (PDOException $pdoExceptionAgain) { $dbError = new CDBError(); $dbError->setSQLErrorCode('CMyFrame'); $dbError->setDriverErrorCode('CMyFrame'); $dbError->setErrorMessage('从库连接失败后,尝试连接主库,连接主库依旧失败'); CHooks::callHooks(HOOKS_EXECUTE_ERROR, $dbError); //切换数据依旧无法连接 throw new CDbException('[数据库错误]从库连接失败后,尝试连接主库依旧失败:' . $pdoExceptionAgain->getMessage()); } } else { //发生SQL错误时 触发钩子 $dbError = new CDBError(); $dbError->setSQLErrorCode('CMyFrame'); $dbError->setDriverErrorCode('CMyFrame'); $dbError->setErrorMessage('从库连接失败后,不允许尝试连接主库'); CHooks::callHooks(HOOKS_EXECUTE_ERROR, $dbError); throw new CDbException('[数据库错误]连接从数据库失败,且不允许尝试使用主库:' . $pdoException->getMessage()); } //发生SQL错误时 触发钩子 $dbError = new CDBError(); $dbError->setSQLErrorCode('CMyFrame'); $dbError->setDriverErrorCode('CMyFrame'); $dbError->setErrorMessage($errorMessage); CHooks::callHooks(HOOKS_EXECUTE_ERROR, $dbError); } } self::$objectPdo[intval($isMaster) . $configName] = $pdoObject; return $pdoObject; }
/** * Retrieves CConfig configuration object * @return object CConfig object * @param */ public static function getConfig() { return CConfig::getInstance(); }
/** * 设置默认控制器方法 */ public function __construct() { $this->setController(CConfig::getInstance()->load('DEFAULT_CONTROLLER')); $this->setAction(CConfig::getInstance()->load('DEFAULT_ACTION')); $this->setModule(CConfig::getInstance()->load('DEFAULT_MODLUE')); }
public function loadDefault() { $config = CConfig::getInstance(); //add default group $groups = array(); $groups['ADMIN'] = array('COM_COMMUNITY_EMAILGROUP_ADMIN', TRUE); $groups['PROFILE'] = array('COM_COMMUNITY_EMAILGROUP_PROFILE', FALSE); if ($config->get('enablegroups')) { $groups['GROUPS'] = array('COM_COMMUNITY_EMAILGROUP_GROUPS', FALSE); } if ($config->get('enableevents')) { $groups['EVENTS'] = array('COM_COMMUNITY_EMAILGROUP_EVENTS', FALSE); } if ($config->get('enablevideos')) { $groups['VIDEOS'] = array('COM_COMMUNITY_EMAILGROUP_VIDEOS', FALSE); } if ($config->get('enablephotos')) { $groups['PHOTOS'] = array('COM_COMMUNITY_EMAILGROUP_PHOTOS', FALSE); } $groups['OTHERS'] = array('COM_COMMUNITY_EMAILGROUP_OTHERS', FALSE); foreach ($groups as $key => $desc) { $this->addGroup($key, $desc[0], $desc[1]); } $types = array(); //Admin $types[] = array('ADMIN', 'etype_groups_notify_admin', 'COM_COMMUNITY_EMAILTYPE_GROUPS_CREATION_MODERATION_REQUIRED', 'COM_COMMUNITY_EMAILTYPE_GROUPS_CREATION_MODERATION_REQUIRED_TIPS', TRUE); $types[] = array('ADMIN', 'etype_user_profile_delete', 'COM_COMMUNITY_EMAILTYPE_PROFILE_DELETE', 'COM_COMMUNITY_EMAILTYPE_PROFILE_DELETE_TIPS', TRUE); $types[] = array('ADMIN', 'etype_system_reports_threshold', 'COM_COMMUNITY_EMAILTYPE_REPORTS_THRESHOLD', 'COM_COMMUNITY_EMAILTYPE_REPORTS_THRESHOLD_TIPS', TRUE); //Profile //$types[] = array('PROFILE','etype_profile_submit_wall_comment','COM_COMMUNITY_EMAILTYPE_PROFILE_WALLCOMMENT','COM_COMMUNITY_EMAILTYPE_PROFILE_WALLCOMMENT_TIPS'); $types[] = array('PROFILE', 'etype_profile_status_update', 'COM_COMMUNITY_EMAILTYPE_PROFILE_STATUSUPDATE', 'COM_COMMUNITY_EMAILTYPE_PROFILE_STATUSUPDATE_TIPS'); //Friends $types[] = array('PROFILE', 'etype_friends_request_connection', 'COM_COMMUNITY_EMAILTYPE_FRIENDS_INVITE', 'COM_COMMUNITY_EMAILTYPE_FRIENDS_INVITE_TIPS'); $types[] = array('PROFILE', 'etype_friends_create_connection', 'COM_COMMUNITY_EMAILTYPE_FRIENDS_CONNECTION', 'COM_COMMUNITY_EMAILTYPE_FRIENDS_CONNECTION_TIPS'); $types[] = array('PROFILE', 'etype_inbox_create_message', 'COM_COMMUNITY_EMAILTYPE_OTHERS_INBOXMSG', 'COM_COMMUNITY_EMAILTYPE_OTHERS_INBOXMSG_TIPS'); $types[] = array('PROFILE', ' etype_users_tagged', 'COM_COMMUNITY_EMAILTYPE_USER_TAGGED', 'COM_COMMUNITY_EMAILTYPE_USER_TAGGED_TIPS'); if ($config->get('enablegroups')) { //Groups // $types[] = array('GROUPS','etype_groups_submit_wall_comment','COM_COMMUNITY_EMAILTYPE_GROUPS_WALLCOMMENT','COM_COMMUNITY_EMAILTYPE_GROUPS_WALLCOMMENT_TIPS'); $types[] = array('GROUPS', 'etype_groups_invite', 'COM_COMMUNITY_EMAILTYPE_GROUPS_INVITE', 'COM_COMMUNITY_EMAILTYPE_GROUPS_INVITE_TIPS'); $types[] = array('GROUPS', 'etype_groups_discussion_reply', 'COM_COMMUNITY_EMAILTYPE_GROUPS_DISCUSSIONREPLY', 'COM_COMMUNITY_EMAILTYPE_GROUPS_DISCUSSIONREPLY_TIPS'); $types[] = array('GROUPS', 'etype_groups_wall_create', 'COM_COMMUNITY_EMAILTYPE_GROUPS_WALLUPDATE', 'COM_COMMUNITY_EMAILTYPE_GROUPS_WALLUPDATE_TIPS'); $types[] = array('GROUPS', 'etype_groups_create_discussion', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWDISCUSSION', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWDISCUSSION_TIPS'); $types[] = array('GROUPS', 'etype_groups_create_news', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWBULLETIN', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWBULLETIN_TIPS'); $types[] = array('GROUPS', 'etype_groups_create_album', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWALBUM', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWALBUM_TIPS'); $types[] = array('GROUPS', 'etype_groups_create_video', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWVIDEO', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWVIDEO_TIPS'); $types[] = array('GROUPS', 'etype_groups_create_event', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWEVENT', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWEVENT_TIPS'); $types[] = array('GROUPS', 'etype_groups_sendmail', 'COM_COMMUNITY_EMAILTYPE_GROUPS_MASSEMAIL', 'COM_COMMUNITY_EMAILTYPE_GROUPS_MASSEMAIL_TIPS'); $types[] = array('GROUPS', 'etype_groups_member_approved', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWMEMBER', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWMEMBER_TIPS'); $types[] = array('GROUPS', 'etype_groups_member_join', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWMEMBER_REQUEST', 'COM_COMMUNITY_EMAILTYPE_GROUPS_NEWMEMBER_REQUEST_TIPS'); $types[] = array('GROUPS', 'etype_groups_notify_creator', 'COM_COMMUNITY_EMAILTYPE_GROUPS_CREATION_APPROVED', 'COM_COMMUNITY_EMAILTYPE_GROUPS_CREATION_APPROVED_TIPS'); } if ($config->get('enableevents')) { //Events // $types[] = array('EVENTS','etype_events_submit_wall_comment','COM_COMMUNITY_EMAILTYPE_EVENTS_WALLCOMMENT','COM_COMMUNITY_EMAILTYPE_EVENTS_WALLCOMMENT_TIPS'); $types[] = array('EVENTS', 'etype_events_invite', 'COM_COMMUNITY_EMAILTYPE_EVENTS_INVITATION', 'COM_COMMUNITY_EMAILTYPE_EVENTS_INVITATION_TIPS'); $types[] = array('EVENTS', 'etype_events_invitation_approved', 'COM_COMMUNITY_EMAILTYPE_EVENTS_INVITATION_APPROVED', 'COM_COMMUNITY_EMAILTYPE_EVENTS_INVITATION_APPROVED_TIPS'); $types[] = array('EVENTS', 'etype_events_sendmail', 'COM_COMMUNITY_EMAILTYPE_EVENTS_MASSEMAIL', 'COM_COMMUNITY_EMAILTYPE_EVENTS_MASSEMAIL_TIPS'); $types[] = array('EVENTS', 'etype_events_notify_admin', 'COM_COMMUNITY_EMAILTYPE_EVENTS_CREATION_MODERATION_REQUIRED', 'COM_COMMUNITY_EMAILTYPE_EVENTS_CREATION_MODERATION_REQUIRED_TIPS'); $types[] = array('EVENTS', 'etype_events_wall_create', 'COM_COMMUNITY_EMAILTYPE_EVENTS_WALLUPDATE', 'COM_COMMUNITY_EMAILTYPE_EVENTS_WALLUPDATE_TIPS'); } if ($config->get('enablevideos')) { //Videos $types[] = array('VIDEOS', 'etype_videos_submit_wall', 'COM_COMMUNITY_EMAILTYPE_VIDEOS_WALLCOMMENT', 'COM_COMMUNITY_EMAILTYPE_VIDEOS_WALLCOMMENT_TIPS'); } if ($config->get('enablephotos')) { //Photos $types[] = array('PHOTOS', 'etype_photos_submit_wall', 'COM_COMMUNITY_EMAILTYPE_PHOTOS_WALLCOMMENT', 'COM_COMMUNITY_EMAILTYPE_PHOTOS_WALLCOMMENT_TIPS'); $types[] = array('PHOTOS', 'etype_photos_tagging', 'COM_COMMUNITY_EMAILTYPE_PHOTOS_TAG', 'COM_COMMUNITY_EMAILTYPE_PHOTOS_TAG_TIPS'); } //Others $types[] = array('OTHERS', 'etype_system_bookmarks_email', 'COM_COMMUNITY_EMAILTYPE_OTHERS_BOOKMARKS', 'COM_COMMUNITY_EMAILTYPE_OTHERS_BOOKMARKS_TIPS'); $types[] = array('OTHERS', 'etype_system_messaging', 'COM_COMMUNITY_EMAILTYPE_OTHERS_SYSTEMMSG', 'COM_COMMUNITY_EMAILTYPE_OTHERS_SYSTEMMSG_TIPS'); foreach ($types as $type) { $adminOnly = isset($type[4]) ? $type[4] : FALSE; $this->addEmailType($type[0], $type[1], $type[2], $config->get($type[1], 0), $type[3], $adminOnly); } }
function _isJSMultiPTypeEnabled() { return CConfig::getInstance()->get('profile_multiprofile', 0); }
/** * 查看缓存区状态 */ public function showStatus() { $list = CConfig::getInstance()->load('CACHE.MEMORY_LIST'); if (is_array($list)) { return $this->_cacheObject->getExtendedStats(); } else { return $this->_cacheObject->getStats(); } }
/** * Function used to convert notification types to params string */ public function convertToParamsString() { $config = CConfig::getInstance(); $ret = ""; foreach ($this->_notificationTypes as $group) { foreach ($group->child as $id => $type) { $emailTypeString = CNotificationTypesHelper::convertNotifId($id); $notiTypeString = CNotificationTypesHelper::convertEmailId($id); //email notification $ret .= $emailTypeString . "=" . $config->get($emailTypeString, 0) . "\n"; //internal notification $ret .= $notiTypeString . "=" . $config->get($notiTypeString, 0) . "\n"; } } return $ret; }