Esempio n. 1
0
 /**
  * 框架启动入口函数
  */
 public static function run()
 {
     self::_loadBaseLib();
     //加载框架核心类
     date_default_timezone_set(TIME_ZONE);
     //设置默认时区
     if (APP_DEBUG) {
         Debug::start();
         error_reporting(E_ALL);
         //设置捕获系统异常
         set_error_handler(array('herosphp\\core\\Debug', 'customError'));
     } else {
         error_reporting(0);
         ini_set("display_errors", "Off");
     }
     $configs = Loader::config('system');
     //加载系统全局配置
     $appConfigs = Loader::config('*', APP_NAME);
     //加载当前应用的配置信息
     //将应用的配置信息覆盖系统的全局配置信息
     $configs = array_merge($configs, $appConfigs);
     $application = WebApplication::getInstance();
     $application->execute($configs);
     //Debug::printMessage();
 }
Esempio n. 2
0
 /**
  * 初始化数据库连接
  * @param string $table 数据表
  * @param array $config 数据库配置信息
  */
 public function __construct($table, $config = null)
 {
     //加载数据表配置
     $dbConfigPath = 'db';
     if (DB_CFG_PATH != false) {
         $dbConfigPath = DB_CFG_PATH;
     }
     $tableConfig = Loader::config('table', $dbConfigPath);
     $this->table = $tableConfig[$table];
     //初始化数据库配置
     if (!$config) {
         //默认使用第一个数据库服务器配置
         $dbConfigs = Loader::config('hosts', $dbConfigPath);
         $db_config = $dbConfigs[DB_TYPE];
         if (DB_ACCESS == DB_ACCESS_SINGLE) {
             //单台服务器
             $config = $db_config[0];
         } else {
             if (DB_ACCESS == DB_ACCESS_CLUSTERS) {
                 //多台服务器
                 $config = $db_config;
             }
         }
     }
     //创建数据库
     $this->db = DBFactory::createDB(DB_ACCESS, $config);
 }
 /**
  * 初始化数据库连接
  * @param string $table 数据表
  * @param array $config 数据库配置信息
  */
 public function __construct($table, $config = null)
 {
     //初始化数据库配置
     if (!$config) {
         $congfig = Loader::config('db');
     }
     //创建数据库
     $this->db = DBFactory::createDB('mongo', $congfig['mongo']);
     $this->table = $table;
 }
 /**
  * @return bool|null|\Redis
  */
 public static function getInstance()
 {
     if (is_null(self::$redis)) {
         $configs = Loader::config('redis', 'cache');
         if (!$configs) {
             return false;
         }
         self::$redis = new \Redis();
         self::$redis->connect($configs['host'], $configs['port']);
     }
     return self::$redis;
 }
 /**
  * 更改角色权限
  * @param HttpRequest $request
  */
 public function permission(HttpRequest $request)
 {
     $id = $request->getParameter('id', 'intval');
     if ($id <= 0) {
         $this->showMessage('danger', '参数不合法!');
     }
     $service = Beans::get($this->getServiceBean());
     $item = $service->getItem($id);
     $permissions = cn_json_decode($item['permissions']);
     //加载权限选项
     $permissionOptions = Loader::config('admin', 'permission');
     $this->assign('permissions', $permissions);
     $this->assign('permissionOptions', $permissionOptions);
     $this->assign('item', $item);
     $this->setView('admin/role_permission');
 }
Esempio n. 6
0
 /**
  * 创建缓存
  * @param $key
  * @param bool $single 是否单例模式
  * @return \herosphp\cache\interfaces\ICache
  */
 public static function create($key = 'file', $single = true)
 {
     //如果缓存对象已经创建,则则直接返回
     if (isset(self::$CACHE_SET[$key]) && $single == false) {
         return self::$CACHE_SET[$key];
     }
     $configs = Loader::config($key, 'cache');
     $className = self::$CACHE_BEAN[$key]['class'];
     Loader::import(self::$CACHE_BEAN[$key]['path'], IMPORT_FRAME);
     if ($single) {
         self::$CACHE_SET[$key] = new $className($configs);
         return self::$CACHE_SET[$key];
     } else {
         return $className($configs);
     }
 }
Esempio n. 7
0
 /**
  * 开启session
  */
 public static function start()
 {
     //如果已经开启了SESSION则直接返回
     if (isset($_SESSION)) {
         return true;
     }
     //loading session configures
     $configs = Loader::config('session', 'session');
     switch (SESSION_HANDLER) {
         case 'file':
             FileSession::start($configs[SESSION_HANDLER]);
             break;
         case 'memo':
             MemSession::start($configs[SESSION_HANDLER]);
             break;
     }
 }
Esempio n. 8
0
 /**
  * 获取指定ID的Bean
  * @param string $key Bean的key
  * @param boolean $new 是否创建新的bean,新创建的Bean不会放到容器中,如果要放到容器中,请使用set方法。
  * @return Object 返回指定ID的Bean,如果Bean不存在则返回null
  */
 public static function get($key, $new = false)
 {
     if (empty(self::$CONFIGS)) {
         self::$CONFIGS = Loader::config('*', 'beans');
         if (!self::$CONFIGS) {
             return null;
         }
     }
     $beanConfig = self::$CONFIGS[$key];
     if ($new || $beanConfig['@single'] === false) {
         return self::build($beanConfig);
     }
     if (!isset(self::$BEAN_POOL[$key])) {
         self::$BEAN_POOL[$key] = self::build($beanConfig);
     }
     return self::$BEAN_POOL[$key];
 }
 /**
  * 编辑媒体管理员角色界面
  * @param HttpRequest $request
  */
 public function edit(HttpRequest $request)
 {
     parent::edit($request);
     $item = $this->getTemplateVar('item');
     //获取媒体类型
     $mediaTypeService = Beans::get('media.type.service');
     $mediaType = $mediaTypeService->getItem($item['media_type']);
     $permissionTpl = $mediaType['permission_tpl'];
     //加载权限选项
     $permissions = Loader::config($permissionTpl, 'permission');
     $this->assign('permissions', $permissions);
     $item['permission'] = cn_json_decode($item['permission']);
     $this->assign('item', $item);
     $this->assign("seoTitle", "媒体中心后台管理-角色编辑");
     $this->assign("seoDesc", "角色管理-角色编辑");
     $this->assign("seoKwords", "媒体中心后台管理 角色管理 角色编辑");
     $this->setView('role/add');
 }
Esempio n. 10
0
 /**
  * 初始化数据库连接
  * @param string $table 数据表
  * @param array $config 数据库配置信息
  */
 public function __construct($table, $config = null)
 {
     //初始化数据库配置
     if (!$config) {
         //默认使用第一个数据库服务器配置
         $dbConfigs = Loader::config('db');
         $db_config = $dbConfigs[DB_TYPE];
         if (DB_ACCESS == DB_ACCESS_SINGLE) {
             //单台服务器
             $config = $db_config[0];
         } else {
             if (DB_ACCESS == DB_ACCESS_CLUSTERS) {
                 //多台服务器
                 $config = $db_config;
             }
         }
     }
     $this->table = $config['table_prefix'] . $table;
     //创建数据库
     $this->db = DBFactory::createDB(DB_ACCESS, $config);
 }
Esempio n. 11
0
 /**
  * 开启session
  */
 public static function start()
 {
     //如果已经开启了SESSION则直接返回
     if (isset($_SESSION)) {
         return true;
     }
     //loading session configures
     $configs = Loader::config('session');
     $session_configs = $configs[$configs['session_handler']];
     switch ($configs['session_handler']) {
         case 'file':
             FileSession::start($session_configs);
             break;
         case 'memo':
             MemSession::start($session_configs);
             break;
         case 'redis':
             RedisSession::start($session_configs);
             break;
     }
 }
 /**
  * 文章推荐位列表
  * @param HttpRequest $request
  */
 public function index(HttpRequest $request)
 {
     $__configs = Loader::config('media', 'data');
     $service = Beans::get($this->getServiceBean());
     $condi = array('media_id' => $this->loginMedia['id']);
     $items = $service->getItems($condi);
     $items = ArrayUtils::changeArrayKey($items, 'position');
     $__configs = $__configs['media_article_rec'];
     $__items = array();
     foreach ($__configs as $key => $value) {
         $__items[$key]['name'] = $value;
         $__items[$key]['id'] = $key;
         //判断是否开启此推荐位
         if (!empty($items[$key])) {
             $__items[$key]['open'] = $items[$key]['status'];
         } else {
             $__items[$key]['open'] = 0;
         }
     }
     $this->assign('items', $__items);
     $this->assign("seoTitle", "媒体中心后台管理-文章推荐位");
     $this->setView('article/recommend_index');
 }
Esempio n. 13
0
 /**
  * 加载核心层库函数
  * @return void
  */
 private static function _loadBaseLib()
 {
     self::$LIB_CLASS = array('herosphp\\http\\HttpRequest' => 'http.HttpRequest', 'herosphp\\http\\HttpClient' => 'http.HttpClient', 'herosphp\\core\\WebApplication' => 'core.WebApplication', 'herosphp\\core\\Debug' => 'core.Debug', 'herosphp\\core\\Loader' => 'core.Loader', 'herosphp\\core\\AppError' => 'core.AppError', 'herosphp\\core\\Template' => 'core.Template', 'herosphp\\core\\Controller' => 'core.Controller', 'herosphp\\exception\\HeroException' => 'exception.HeroException', 'herosphp\\exception\\DBException' => 'exception.DBException', 'herosphp\\exception\\UnSupportedOperationException' => 'exception.UnSupportedOperationException', 'herosphp\\files\\FileUtils' => 'files.FileUtils', 'herosphp\\files\\FileUpload' => 'files.FileUpload', 'herosphp\\files\\PHPZip' => 'files.PHPZip', 'herosphp\\utils\\ArrayUtils' => 'utils.ArrayUtils', 'herosphp\\utils\\AjaxResult' => 'utils.AjaxResult', 'herosphp\\utils\\HashUtils' => 'utils.HashUtils', 'herosphp\\utils\\Page' => 'utils.Page', 'herosphp\\string\\StringBuffer' => 'string.StringBuffer', 'herosphp\\string\\StringUtils' => 'string.StringUtils', 'herosphp\\image\\ImageThumb' => 'image.ImageThumb', 'herosphp\\image\\ImageWater' => 'image.ImageWater', 'herosphp\\image\\VerifyCode' => 'image.VerifyCode', 'herosphp\\web\\Smtp' => 'web.Smtp', 'herosphp\\web\\WebUtils' => 'web.WebUtils', 'herosphp\\db\\DBFactory' => 'db.DBFactory', 'herosphp\\db\\mysql\\MysqlQueryBuilder' => 'db.mysql.MysqlQueryBuilder', 'herosphp\\db\\mongo\\MongoQueryBuilder' => 'db.mongo.MongoQueryBuilder', 'herosphp\\model\\C_Model' => 'model.C_Model', 'herosphp\\model\\MongoModel' => 'model.MongoModel', 'herosphp\\lock\\SemSynLock' => 'lock.SemSynLock', 'herosphp\\lock\\FileSynLock' => 'lock.FileSynLock', 'herosphp\\lock\\SynLockFactory' => 'lock.SynLockFactory', 'herosphp\\filter\\Filter' => 'filter.Filter', 'herosphp\\cache\\CacheFactory' => 'cache.CacheFactory', 'herosphp\\cache\\utils\\RedisUtils' => 'cache.utils.RedisUtils', 'herosphp\\bean\\Beans' => 'bean.Beans', 'herosphp\\listener\\WebApplicationListenerMatcher' => 'listener.WebApplicationListenerMatcher', 'herosphp\\session\\Session' => 'session.Session');
     //获取自动加载类配置
     self::$APP_CLASS = Loader::config("autoload");
 }
 /**
  * @see \media\service\interfaces\IMediaManagerService::hasPermission
  */
 public function hasPermission($opt, $userid)
 {
     //获取当前登录媒体的权限
     $mediaService = Beans::get('media.media.service');
     $loginMedia = $mediaService->getLoginMedia();
     //1. 如果是当前登录媒体的超级管理员(申请者)
     if ($loginMedia['userid'] == $userid) {
         return true;
     }
     //加载媒体所有权限选项
     $permissionOptions = Loader::config('media_permissions', 'permission');
     //2. 如果该该操作没有加入权限限制,则所有人都有权限操作
     $__opt = explode('@', $opt);
     if (!isset($permissionOptions[$__opt[0]]['methods'][$__opt[1]])) {
         return true;
     }
     //3. 判断操作权限
     $permissions = $loginMedia['permission'];
     return $permissions[$opt] == 1;
 }
 /**
  * @see \admin\service\interfaces\IAdminService::hasPermission()
  */
 public function hasPermission($opt, &$permissions)
 {
     $user = $this->getLoginUser();
     if ($this->isSuperManager($user)) {
         return true;
     }
     $__opt = explode('@', $opt);
     //加载权限选项
     $permissionOptions = Loader::config('admin', 'permission');
     if (!isset($permissionOptions[$__opt[0]]['methods'][$__opt[1]])) {
         //不需要进行权限验证
         return true;
     } else {
         return $permissions[$opt] == 1;
     }
 }
Esempio n. 16
0
 /**
  * 获取文章内容表的dao实例
  * @param int $aid 文章ID
  * @return \herosphp\model\C_Model
  */
 public function getDataDao($aid)
 {
     //获取文章数据表的节点
     $node = $aid % self::DATA_TABLE_NODES;
     $this->dataDao = Loader::model('ArticleData');
     $tableMapping = $this->dataDao->getTableMapping();
     //加载数据表配置
     $dbConfigPath = 'db';
     if (DB_CFG_PATH != false) {
         $dbConfigPath = DB_CFG_PATH;
     }
     $tableConfig = Loader::config('table', $dbConfigPath);
     $this->dataDao->setTable($tableConfig[$tableMapping[$node]]);
     return $this->dataDao;
 }