Ejemplo 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();
 }
Ejemplo n.º 2
0
 /**
  * 初始化方法
  */
 public function C_start()
 {
     parent::C_start();
     $webApp = WebApplication::getInstance();
     $request = $webApp->getHttpRequest();
     //获取当前登录媒体
     $mediaService = Beans::get("media.media.service");
     $mediaId = $request->getParameter("media_id", 'intval');
     $this->loginMedia = $mediaService->getItem($mediaId);
     $this->mediaConfigs = cn_json_decode($this->loginMedia["configs"]);
     //注册媒体信息
     $this->assign('mediaConfigs', $this->mediaConfigs);
     $this->assign("loginMedia", $this->loginMedia);
     //获取媒体频道列表
     $chanelService = Beans::get("media.chanel.service");
     $chanels = $chanelService->getChanelCache($mediaId);
     $this->assign("chanels", $chanels);
     //底部单页导航
     $artoneService = Beans::get("artone.artone.service");
     $artoneMenu = $artoneService->getMediaArtone($this->loginMedia['id']);
     $this->assign("artoneMenu", $artoneMenu);
     //媒体底部友情链接列表
     $linkService = Beans::get("media.friendlink.service");
     $friendLinks = $linkService->getMediaFriendLinks($mediaId);
     $this->assign("friendLinks", $friendLinks);
     $this->getHotArticles($request);
 }
Ejemplo n.º 3
0
 public function C_start()
 {
     $webApp = WebApplication::getInstance();
     $request = $webApp->getHttpRequest();
     $page = $request->getParameter('page', 'intval');
     $this->setPage($page > 0 ? $page : 1);
 }
Ejemplo n.º 4
0
 public function C_start()
 {
     parent::C_start();
     $webApp = WebApplication::getInstance();
     $request = $webApp->getHttpRequest();
     $mediaService = Beans::get("media.media.service");
     $this->loginMedia = $mediaService->getLoginMedia();
     //获取当前操作
     $currentOpt = $request->getAction() . '@' . $request->getMethod();
     $this->assign("currentOpt", $currentOpt);
     //如果不是注册登录媒体操作,则需要做权限判断
     if ($currentOpt != 'media@index') {
         $managerService = Beans::get('media.manager.service');
         if (!$managerService->hasPermission($currentOpt, $this->loginUser['id'])) {
             //判断请求的类型,如果是ajax请求则使用ajax返回
             if (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
                 AjaxResult::ajaxResult('error', "您没有权限进行该操作,请联系管理员添加权限!");
             } else {
                 $this->showMessage('error', '您没有权限进行该操作,请联系管理员添加权限!');
             }
         }
     }
     $mediaInfo = $mediaService->getLoginMedia();
     $this->assign("loginMedia", $mediaInfo);
 }
 public function C_start()
 {
     parent::C_start();
     $webApp = WebApplication::getInstance();
     $request = $webApp->getHttpRequest();
     $currentOpt = $request->getAction() . '@' . $request->getMethod();
     $this->assign("currentOpt", $currentOpt);
     $this->articleService = Beans::get('article.article.service');
 }
Ejemplo n.º 6
0
 public function edit(HttpRequest $request)
 {
     parent::edit($request);
     //获取app配置文档
     $wepApp = WebApplication::getInstance();
     $groups = $wepApp->getConfig('system.config.group');
     $this->assign('groups', $groups);
     $this->setView('system/config_edit');
 }
Ejemplo n.º 7
0
 public function __construct()
 {
     parent::__construct();
     $this->assign("noRecords", "(⊙o⊙)抱歉,没有找到您要内容.");
     $request = WebApplication::getInstance()->getHttpRequest();
     $module = $request->getModule();
     $action = $request->getAction();
     $this->assign("index_url", "/{$module}/{$action}/index");
     $this->assign("insert_url", "/{$module}/{$action}/insert");
     $this->assign("update_url", "/{$module}/{$action}/update");
 }
Ejemplo n.º 8
0
 /**
  * 构造函数
  */
 public function __construct()
 {
     $webApp = WebApplication::getInstance();
     $this->configs = $webApp->getConfigs();
     $this->cache = $this->configs['temp_cache'];
     //添加用户自定义的模板编译规则
     $this->addRules($this->configs['temp_rules']);
     //初始化模板目录和编译目录
     $request = $webApp->getHttpRequest();
     $this->configs['module'] = $request->getModule();
     $this->configs['action'] = $request->getAction();
     $this->configs['method'] = $request->getMethod();
     $this->templateDir = APP_PATH . APP_NAME . '/' . $this->configs['module'] . '/template/' . $this->configs['template'] . '/';
     $this->compileDir = APP_RUNTIME_PATH . 'views/' . APP_NAME . '/' . $this->configs['module'] . '/';
 }
Ejemplo n.º 9
0
 public function C_start()
 {
     parent::C_start();
     $webApp = WebApplication::getInstance();
     $request = $webApp->getHttpRequest();
     $this->mediaId = $request->getParameter('mediaId', 'intval');
     if (!$this->mediaId) {
         page404();
     }
     $chanelService = Beans::get('media.chanel.service');
     $chanel = $chanelService->getItems("media_id={$this->mediaId}", 'id,name');
     $this->assign('chanel', $chanel);
     $mediaService = Beans::get("media.media.service");
     $mediaInfo = $mediaService->getItem($this->mediaId, 'id,name,logo');
     $mediaInfo['logo'] = getImageThumb($mediaInfo['logo'], '177x98');
     $this->assign('mediaInfo', $mediaInfo);
     $footer['pcUrl'] = url("/site_index_index/?media_id={$this->mediaId}");
     $footer['mobileUrl'] = url("/mobile_site_index/?mediaId={$this->mediaId}");
     $this->assign('footer', $footer);
 }
Ejemplo n.º 10
0
 /**
  * 初始化方法
  */
 public function C_start()
 {
     parent::C_start();
     $webApp = WebApplication::getInstance();
     $request = $webApp->getHttpRequest();
     //验证登录
     $adminService = Beans::get('admin.admin.service');
     $this->loginUser = $adminService->getLoginUser();
     if (!$this->loginUser) {
         $this->location(url("/admin_login_index"));
     } else {
         $this->assign('loginUser', $this->loginUser);
     }
     //获取菜单分组
     $groupService = Beans::get('admin.menuGroup.service');
     $menuService = Beans::get('admin.menu.service');
     $__menuGroups = ArrayUtils::changeArrayKey($groupService->getGroupCache(), 'id');
     //初始化左侧菜单的选中状态
     $currentOpt = '/' . $request->getModule() . '_' . $request->getAction() . '_' . $request->getMethod();
     Session::start();
     $mid = $request->getParameter('m', 'intval');
     if ($mid > 0) {
         $_SESSION['m'] = $mid;
         $menu = $menuService->getItem($mid);
         $mpid = $menu['pid'];
         $mgroup = $menu['groupkey'];
         $_SESSION['mpid'] = $mpid;
         $_SESSION['mgroup'] = $mgroup;
     } else {
         $mpid = $_SESSION['mpid'];
         $mgroup = $_SESSION['mgroup'];
         $mid = $_SESSION['m'];
     }
     //获取菜单数据
     $permissions = $adminService->getPermissions();
     $systemMenu = $menuService->getMenuByUser($this->loginUser);
     //__print($systemMenu);die();
     $this->assign('__menuGroups', $__menuGroups);
     $this->assign('systemMenu', $systemMenu);
     $this->assign('mpid', $mpid);
     $this->assign('mgroup', $mgroup);
     $this->assign('mid', $mid);
     $this->assign('currentOpt', $currentOpt);
     //权限认证
     $opt = $request->getAction() . '@' . $request->getMethod();
     if (!$adminService->hasPermission($opt, $permissions)) {
         //判断请求的类型,如果是ajax请求则使用ajax返回
         if (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
             AjaxResult::ajaxResult('error', "您没有权限进行该操作,请联系管理员添加权限!");
         } else {
             $this->showMessage('danger', '您没有权限进行该操作,请联系管理员添加权限!');
         }
     }
     //初始化url
     $insert_url = '/' . $request->getModule() . '_' . $request->getAction() . '_' . 'insert';
     $update_url = '/' . $request->getModule() . '_' . $request->getAction() . '_' . 'update';
     $add_url = '/' . $request->getModule() . '_' . $request->getAction() . '_' . 'add';
     $index_url = '/' . $request->getModule() . '_' . $request->getAction() . '_' . 'index';
     $quicksave_url = '/' . $request->getModule() . '_' . $request->getAction() . '_' . 'quicksave';
     $this->assign('insert_url', url($insert_url));
     $this->assign('update_url', url($update_url));
     $this->assign('add_url', url($add_url));
     $this->assign('index_url', url($index_url));
     $this->assign('quicksave_url', url($quicksave_url));
     //$this->assign('permissions', $permissions);
     $this->assign('emptyRecord', 'O(∩_∩)O~ 抱歉,暂无记录!');
 }
Ejemplo n.º 11
0
 /**
  * 获取过滤后的数据
  * @param $data
  * @return mixed
  */
 protected function loadFilterData(&$data)
 {
     $filterMap = $this->getFilterMap();
     if (empty($filterMap)) {
         return $data;
     }
     $error = null;
     $_data = Filter::loadFromModel($data, $filterMap, $error);
     if ($_data == false) {
         WebApplication::getInstance()->getAppError()->setCode(1);
         WebApplication::getInstance()->getAppError()->setMessage($error);
     }
     return $_data;
 }
Ejemplo n.º 12
0
/**
 * 获取应用的全不配置信息
 * @return array
 */
function getConfigs()
{
    if (defined("RUN_CLI")) {
        $appConfigs = Loader::config('app');
        //加载当前应用的配置信息
        return $appConfigs;
    } else {
        $webapp = \herosphp\core\WebApplication::getInstance();
        return $webapp->getConfigs();
    }
}
Ejemplo n.º 13
0
/**
 * 获取配置文档的值
 * @param $key
 * @return mixed
 */
function getConfig($key)
{
    $webapp = \herosphp\core\WebApplication::getInstance();
    return $webapp->getConfig($key);
}
Ejemplo n.º 14
0
 /**
  * 解析url成pathinfo形式,并获取参数
  * http://www.herosphp.my/admin/member-login-index.html?id=12
  */
 public function parseURL()
 {
     $webApp = WebApplication::getInstance();
     //获取系统配置信息
     $sysConfig = $webApp->getConfigs();
     self::$urlMappingRules = $sysConfig['url_mapping_rules'];
     //优先处理短链接映射
     $this->requestUri = self::url2source($this->requestUri);
     $_SERVER['REQUEST_URI'] = $this->requestUri;
     $defaultUrl = $sysConfig['default_url'];
     $urlInfo = parse_url($this->requestUri);
     echo "\n-----------";
     echo " class: " . __CLASS__ . "      method: " . __METHOD__ . "\n";
     echo " file:" . __FILE__ . "\n";
     print_r(array("urlInfo" => $urlInfo));
     if ($urlInfo['path'] && $urlInfo['path'] != '/') {
         $filename = str_replace(EXT_URI, '', $urlInfo['path']);
         $filename = rtrim($filename, "/");
         $pathInfo = explode('/', $filename);
         array_shift($pathInfo);
         print_r(array("pathInfo" => $pathInfo));
         if ($pathInfo[0]) {
             $this->setModule($pathInfo[0]);
         }
         if ($pathInfo[1]) {
             $this->setAction($pathInfo[1]);
         }
         if ($pathInfo[2]) {
             $this->setMethod($pathInfo[2]);
         }
         //提取pathinfo参数
         if (count($pathInfo) > 3) {
             if (isset($pathInfo[3])) {
                 $params = explode('-', $pathInfo[3]);
                 for ($i = 0; $i < count($params); $i++) {
                     if ($i % 2 == 0) {
                         if (trim($params[$i]) == '') {
                             continue;
                         }
                         $_GET[$params[$i]] = $params[$i + 1];
                     }
                 }
             }
         }
         echo "-----------\n";
         //提取query参数
         if (isset($urlInfo['query'])) {
             $params = explode('&', $urlInfo['query']);
             foreach ($params as $values) {
                 $__p = explode('=', $values);
                 if (trim($__p[0]) == '') {
                     continue;
                 }
                 $_GET[$__p[0]] = $__p[1];
             }
         }
     }
     //如果没有任何参数,则访问默认页面。如http://www.herosphp.my这种格式
     if (!$this->module) {
         $this->setModule($defaultUrl['module']);
     }
     if (!$this->action) {
         $this->setAction($defaultUrl['action']);
     }
     if (!$this->method) {
         $this->setMethod($defaultUrl['method']);
     }
     $this->setParameters($_GET + $_POST);
     //die();
 }
Ejemplo n.º 15
0
 /**
  * 解析url成pathinfo形式,并获取参数
  * http://www.herosphp.my/admin/member-login-index.html?id=12
  */
 public function parseURL()
 {
     $webApp = WebApplication::getInstance();
     //获取系统配置信息
     $sysConfig = $webApp->getConfigs();
     self::$urlMappingRules = $sysConfig['url_mapping_rules'];
     //优先处理短链接映射
     $this->requestUri = self::url2source($this->requestUri);
     $_SERVER['REQUEST_URI'] = $this->requestUri;
     $defaultUrl = $sysConfig['default_url'];
     $urlInfo = parse_url($this->requestUri);
     if ($urlInfo['path']) {
         $filename = str_replace(EXT_URI, '', $urlInfo['path']);
         $pathInfo = explode('/', $filename);
         if (isset($pathInfo[1])) {
             $actionMap = explode('_', $pathInfo[1]);
             if ($actionMap[0]) {
                 $this->setModule($actionMap[0]);
             }
             if ($actionMap[1]) {
                 $this->setAction($actionMap[1]);
             }
             if ($actionMap[2]) {
                 $this->setMethod($actionMap[2]);
             }
         }
         //提取pathinfo参数
         if (isset($pathInfo[2])) {
             $params = explode('-', $pathInfo[2]);
             for ($i = 0; $i < count($params); $i++) {
                 if ($i % 2 == 0) {
                     if (trim($params[$i]) == '') {
                         continue;
                     }
                     $_GET[$params[$i]] = $params[$i + 1];
                 }
             }
         }
         //提取query参数
         if (isset($urlInfo['query'])) {
             $params = explode('&', $urlInfo['query']);
             foreach ($params as $values) {
                 $__p = explode('=', $values);
                 if (trim($__p[0]) == '') {
                     continue;
                 }
                 $_GET[$__p[0]] = $__p[1];
             }
         }
     }
     //如果没有任何参数,则访问默认页面。如http://www.herosphp.my这种格式
     if (!$this->module) {
         $this->setModule($defaultUrl['module']);
     }
     if (!$this->action) {
         $this->setAction($defaultUrl['action']);
     }
     if (!$this->method) {
         $this->setMethod($defaultUrl['method']);
     }
     $this->setParameters($_GET + $_POST);
 }