Пример #1
0
 public static function error($code = 'DATA_NOT_FOUND', $message = null)
 {
     $configs = Gio_Core_Config_Xml::getConfig('web');
     $request = Gio_Core_Request::getInstance();
     $request->setParam('code', $code);
     $request->setParam('message', $message);
     $request->setParam('__GIOCMS_ERROR__', true);
     $content = Gio_Core_Controller::getIntance()->setTemplate($configs->admin->template)->setLayout('message')->setModuleName('core')->setControllerName('exception')->setActionName('error')->dispatch(true);
     Gio_Core_Response::getInstance()->setBody($content);
 }
Пример #2
0
 public function showAction()
 {
     $json = new Services_JSON();
     $params = $this->_request->getParam('params');
     $params = (array) $json->decode($params);
     $this->view->uploadElementId = 'uploadFile_' . uniqid();
     $this->view->sessionId = Gio_Core_Session::getId();
     $this->view->editor = 'ckeditor';
     $this->view->currModule = Gio_Core_Controller::getIntance()->getModuleName();
 }
Пример #3
0
 public function run()
 {
     $request = Gio_Core_Request::getInstance();
     $configs = Gio_Core_Config_Xml::getConfig('web');
     $adminPrefixUrl = $configs->admin->url_prefix;
     $adminTemplate = $configs->admin->template;
     $adminSkin = isset($configs->admin->skin) ? $configs->admin->skin : 'default';
     $baseUrl = $request->getBaseUrl();
     $uri = $request->getRequestUri();
     $serverName = $request->getServerName();
     $serverPort = $request->getServerPort();
     $serverPort = $serverPort == 80 ? '' : ':' . $serverPort;
     $uri = 'http://' . $serverName . $serverPort . $uri;
     $currentUrl = str_replace($baseUrl, '', $uri);
     $currentUrl = '/' . rtrim(ltrim($currentUrl, '/'), '/') . '/';
     /**
      * 7 is length of /admin/
      */
     $length = strlen($adminPrefixUrl) + 2;
     if (!$adminPrefixUrl || substr($currentUrl, 0, $length) != "/{$adminPrefixUrl}/") {
         return;
     }
     $controllerFront = Gio_Core_Controller::getIntance();
     $controllerFront->setTemplate($adminTemplate);
     $view = Gio_Core_View::getInstance();
     $view->APP_TEMPLATE = $adminTemplate;
     $view->APP_SKIN = $adminSkin;
     $view->setAdminSection(true);
     /**
      * Check admin login
      */
     $phpSessionId = $request->getPost('PHPSESSID');
     $session = Gio_Core_Session::getSessionById($phpSessionId);
     $json = new Services_JSON();
     $user = null == $session || null == $session['data'] ? null : $json->decode($session['data']);
     $view->userLogin = $user;
     //return;
     $route = Gio_Core_Route::getCurrentRoute(true);
     if ((null == $user || !isset($user->username) || null == $user->username) && (null == $route || $route['name'] != 'core_auth_login')) {
         $return = $_SERVER['REQUEST_URI'];
         $return = $return ? rawurlencode(base64_encode($return)) : null;
         $link = $view->url('core_auth_login');
         if (strpos($link, '?') !== false) {
             $return = $return != null ? '&return=' . $return : null;
         } else {
             $return = $return != null ? '?return=' . $return : null;
         }
         header('Location: ' . $link . $return);
         exit;
     }
 }
Пример #4
0
 public function run()
 {
     $request = Gio_Core_Request::getInstance();
     $configs = Gio_Core_Config_Xml::getConfig('web');
     $adminPrefixUrl = $configs->admin->prefix_url;
     $currentUri = $request->getRequestUri();
     /**
      * 7 is length of /admin/
      */
     if (!$adminPrefixUrl || substr($currentUri, 0, 7) != "/{$adminPrefixUrl}/") {
         return;
     }
     //$ips = explode(',', $ips);
     //$ip = $request->getClientIp();
     //if (in_array($ip, $ips)) {
     $controllerFront = Gio_Core_Controller::getIntance();
     $controllerFront->setTemplate('admin');
     //}
 }
Пример #5
0
 public function run()
 {
     $controller = Gio_Core_Controller::getIntance();
     $view = Gio_Core_View::getInstance();
     $configs = Gio_Core_Config_Xml::getConfig('web');
     if ($view->APP_TEMPLATE != (string) $configs->admin->template) {
         return;
     }
     $moduleId = $controller->getModuleName();
     /**
      * Check Module Installed
      */
     if ($moduleId != $this->_coreModule && null == Modules_Core_Services_Module::getById($moduleId)) {
         Modules_Core_Services_Exception::error('PERMISSION_DENY');
         return;
     }
     $ruleChecker = Gio_Core_Acl::getIntance();
     $actionId = $controller->getActionName();
     $controllerId = $controller->getControllerName();
     if ($ruleChecker->isAllowed($actionId, $controllerId, $moduleId) === false) {
         Modules_Core_Services_Exception::error('PERMISSION_DENY');
     }
 }
Пример #6
0
 public function run()
 {
     /**
      * Run Permalink Plugin 
      */
     $permalink = new Modules_Core_Controllers_Plugins_Permalink();
     call_user_func(array($permalink, 'run'));
     /**
      * Run LocalizationRoute Plugin 
      */
     $localizationRoute = new Gio_Core_Plugins_LocalizationRoute();
     call_user_func(array($localizationRoute, 'run'));
     /**
      * Run Install Checker
      */
     $currentRoute = Gio_Core_Route::getCurrentRoute();
     self::$_route = $currentRoute;
     $controllerFront = Gio_Core_Controller::getIntance();
     if ($currentRoute && $currentRoute['name'] != 'core_install_step1' && self::_initInstallChecker() === false) {
         $controllerFront->redirect($this->_view->url('core_install_step1'));
         return;
     }
     if (isset($currentRoute['module']) && isset($currentRoute['controller']) && isset($currentRoute['action'])) {
         if (self::_initInstallChecker() == true) {
             $csrf = new Gio_Core_Csrf($currentRoute['name']);
             if (!$csrf->authentication()) {
                 return;
             }
             $csrf->appendElement();
         }
         $controllerFront->setModuleName($currentRoute['module'])->setControllerName($currentRoute['controller'])->setActionName($currentRoute['action']);
         /**
          * Run Plugins First
          */
         if (self::_initInstallChecker() == true) {
             $this->_runPlugin();
         }
         $this->_view->CURRENT_ROUTE = $currentRoute['name'];
         $content = $controllerFront->dispatch();
         $this->_view->setLayoutContent($content);
         if (!Gio_Core_Controller::getIntance()->getDisableLayout()) {
             $layout = isset($this->_view->APP_LAYOUT) && $this->_view->APP_LAYOUT ? $this->_view->APP_LAYOUT : $controllerFront->getLayout();
             $layoutFile = TEMPLATE_DIR . DS . $this->_view->APP_TEMPLATE . DS . 'layouts' . DS . $layout . '.phtml';
             $this->_view->fetch($layoutFile);
         } else {
             $this->_view->content($content);
         }
     }
 }
Пример #7
0
 public function dispatch()
 {
     $this->view = Gio_Core_View::getInstance();
     $controllerFront = Gio_Core_Controller::getIntance();
     /**
      * XML
      */
     $xmlFilename = array($this->_module, $this->_controller, $this->_action);
     $xmlFilename = implode('_', $xmlFilename);
     $blocksData = array();
     $xmlFile = TEMPLATE_DIR . DS . $this->view->APP_TEMPLATE . DS . 'data' . DS . $xmlFilename . '.xml';
     if ($this->view->getAdminSection()) {
         $xmlFile = TEMPLATE_DIR . DS . $this->view->APP_TEMPLATE . DS . 'data' . DS . $this->view->APP_TEMPLATE . '.xml';
     }
     if (file_exists($xmlFile)) {
         $xmlData = simplexml_load_file($xmlFile);
         $blocksData = $xmlData->block;
     }
     /**
      * Check file html cache 
      */
     $globalConfig = Gio_Core_Config_Xml::getConfig();
     $configs = Gio_Core_Config_Xml::getConfig('cache');
     $checkCache = false;
     if ($configs->enable == 'true' && !$this->view->getAdminSection()) {
         $cacheName = $xmlFilename;
         $postParams = $this->_request->getPostParams();
         $getParams = $this->_request->getParams();
         $json = new Services_JSON();
         $cacheParams = !empty($postParams) ? base64_encode($json->encodeUnsafe($postParams)) : null;
         $cacheParams .= !empty($getParams) ? base64_encode($json->encodeUnsafe($getParams)) : null;
         $cacheKey = md5($cacheName . $this->view->APP_TEMPLATE . $cacheParams . base64_encode($json->encodeUnsafe($globalConfig)));
         $cacheType = 'actions';
         $cacheTimeout = isset($configs->timeout) ? $configs->timeout : 3600;
         if ($blocksData) {
             foreach ($blocksData as $index => $block) {
                 if ($block->block_name == 'MAIN_CONTENT' && isset($block->cache->enable) && $block->cache->enable == 'true') {
                     $cacheTimeout = isset($block->cache->timeout) ? $block->cache->timeout : 3600;
                     /**
                      * Create html file cache
                      */
                     if ($checkCache = Gio_Core_Cache::isCached($cacheType, $cacheKey, $cacheTimeout)) {
                         $html = $this->view->render(Gio_Core_Cache::_generateFileName($cacheType, $cacheKey));
                         return $html;
                     }
                 }
             }
         }
     }
     $ucfModule = ucfirst($this->_module);
     $ucfController = ucfirst($this->_controller);
     $controllerClassName = array('Modules', $ucfModule, 'Controllers', $ucfController);
     $controllerClassName = implode('_', $controllerClassName);
     if (!class_exists($controllerClassName)) {
         Modules_Core_Services_Exception::error('CLASS_NOT_FOUND', $controllerClassName);
     }
     $controllerClass = new $controllerClassName();
     /**
      * Call init function
      */
     if (method_exists($controllerClass, 'init')) {
         $controllerClass->init();
     }
     self::$_instance = $controllerClass;
     if (!method_exists($controllerClass, $this->_action . 'Action')) {
         Modules_Core_Services_Exception::error('ACTION_NOT_FOUND', $controllerClassName . '::' . $this->_action . 'Action');
         return;
     }
     call_user_func(array($controllerClass, $this->_action . 'Action'));
     $actionCache = array('enable' => false, 'timeout' => 0);
     if (!Gio_Core_Controller::getIntance()->getDisableLayout()) {
         $widgetObject = Gio_Core_Widget::getIntance();
         if ($blocksData) {
             foreach ($blocksData as $index => $block) {
                 if (!isset($block->visible) || (string) $block->visible != 'false') {
                     if ($block->type == 'widget') {
                         /**
                          * Set Widget User Params
                          */
                         $userParams = isset($block->params) ? (array) $block->params : null;
                         $paramString = null;
                         if ($userParams) {
                             $request = $widgetObject->getRequest();
                             foreach ($userParams as $paramIndex => $param) {
                                 switch ($param) {
                                     case 'GLOBAL':
                                         $userParams[$paramIndex] = $request->getParam($paramIndex);
                                         $param = $request->getParam($paramIndex);
                                         break;
                                     default:
                                         //$request->setParam($paramIndex, $param);
                                         break;
                                 }
                                 $paramString .= $paramString ? '|' : null;
                                 $paramString .= $paramIndex . '=' . $param;
                             }
                         }
                         $userParams['module'] = $block->module;
                         $userParams['widget'] = $block->name;
                         if (isset($block->load) && $block->load == 'ajax') {
                             $this->view->module = $block->module;
                             $this->view->widget = $block->name;
                             $this->view->action = $block->action;
                             $this->view->cacheEnable = isset($block->cache->enable) && $block->cache->enable == 'true' ? true : false;
                             $this->view->cacheTimeout = isset($block->cache->timeout) && $block->cache->timeout > 0 ? $block->cache->timeout : 3600;
                             $this->view->params = $paramString;
                             $this->view->uuid = uniqid();
                             /**
                              * Loading Js & Css
                              */
                             $widgetViewFile = TEMPLATE_DIR . DS . $this->view->APP_TEMPLATE . DS . 'modules' . DS . $block->module . DS . 'widgets' . DS . $block->name . DS . $block->action . '.phtml';
                             if (file_exists($widgetViewFile)) {
                                 $jsCss = $this->view->render($widgetViewFile);
                             }
                             /**
                              * Render Ajax Script 
                              */
                             $widgetViewFile = ROOT_DIR . DS . 'modules' . DS . 'core' . DS . 'views' . DS . 'core' . DS . 'widgets' . DS . 'ajax.phtml';
                             $this->view->{$block->block_name} = $this->view->render($widgetViewFile);
                         } else {
                             $cacheEnable = isset($block->cache->enable) && $block->cache->enable == 'true' ? true : false;
                             $cacheTimeout = isset($block->cache->timeout) && $block->cache->timeout > 0 ? $block->cache->timeout : 0;
                             $widgetObject->setTemplate($this->view->APP_TEMPLATE)->setModuleName($block->module)->setWidgetName($block->name)->setActionName($block->action)->setCacheEnable($cacheEnable)->setCacheTimeout($cacheTimeout)->setParams($userParams);
                             $this->view->{$block->block_name} = $widgetObject->dispatch();
                         }
                     } elseif ($block->block_name == 'MAIN_CONTENT') {
                         $actionCache['enable'] = isset($block->cache->enable) && $block->cache->enable == 'true' ? true : false;
                         $actionCache['timeout'] = isset($block->cache->timeout) && $block->cache->timeout > 0 ? $block->cache->timeout : 0;
                     }
                 }
             }
         }
     }
     $actionViewFile = TEMPLATE_DIR . DS . $this->view->APP_TEMPLATE . DS . 'modules' . DS . $this->_module . DS . $this->_controller . DS . $this->_action . '.phtml';
     if (!file_exists($actionViewFile)) {
         /**
          * Default action view file
          */
         $actionViewFile = ROOT_DIR . DS . 'modules' . DS . $this->_module . DS . 'views' . DS . $this->_controller . DS . $this->_action . '.phtml';
     }
     if (!Gio_Core_Controller::getIntance()->getNoRender()) {
         $content = $controllerClass->view->render($actionViewFile);
         $this->view->MAIN_CONTENT = $content;
     }
     if (!Gio_Core_Controller::getIntance()->getDisableLayout()) {
         $xmlFilename = isset($this->view->APP_LAYOUT) && $this->view->APP_LAYOUT ? $this->view->APP_LAYOUT : $xmlFilename;
         $layoutFile = TEMPLATE_DIR . DS . $this->view->APP_TEMPLATE . DS . 'layouts' . DS . $xmlFilename . '.phtml';
         if ($this->view->getAdminSection()) {
             $layoutFile = TEMPLATE_DIR . DS . $this->view->APP_TEMPLATE . DS . 'layouts' . DS . $this->view->APP_TEMPLATE . '.phtml';
         }
         /**
          * Check param __GIOCMS_ERROR__
          */
         if (Gio_Core_Request::getInstance()->getParam('__GIOCMS_ERROR__') == true) {
             $layoutFile = TEMPLATE_DIR . DS . $this->_template . DS . 'layouts' . DS . $this->_layout . '.phtml';
         }
         $return = $this->view->render($layoutFile);
         if (!$checkCache && $configs->enable == 'true' && !$this->view->getAdminSection() && $actionCache['enable'] == true) {
             $cacheCompress = isset($configs->compress) && $configs->compress == 'true' ? true : false;
             $cacheContent = $this->view->generateTitle() . $this->view->generateScripts() . $this->view->generateStyles() . $return;
             Gio_Core_Cache::cache($cacheType, $cacheKey, $cacheContent, $cacheCompress);
         }
         return $return;
     } elseif (!Gio_Core_Controller::getIntance()->getNoRender()) {
         return $content;
     }
 }