コード例 #1
0
ファイル: Csrf.php プロジェクト: piratevn/cms-gio
 public function authentication()
 {
     if ($this->_csrfEnable) {
         $session = $this->_getSession();
         $json = new Services_JSON();
         $data = $json->decode($session['data']);
         $user = array();
         if ($data) {
             while (list($key, $value) = each($data)) {
                 $user[$key] = $value;
             }
         }
         $request = Gio_Core_Request::getInstance();
         $isValid = null;
         if ($request->isPost() && $this->_csrfRequestMethod == 'POST' || $this->_csrfRequestMethod == 'GET') {
             switch ($this->_csrfRetriveMethod) {
                 case 'POST':
                     $token = $request->getPost($this->_name);
                     break;
                 case 'GET':
                     $token = $request->getParam($this->_name);
                     break;
             }
             $isValid = $this->isValidToken($token);
         }
         if ($isValid === false) {
             //throw new RuntimeException('Token does not match');
             Modules_Core_Services_Exception::error('DATA_NOT_FOUND');
             return;
         }
     }
     return true;
 }
コード例 #2
0
ファイル: Widget.php プロジェクト: piratevn/cms-gio
 protected function showAction()
 {
     $request = Gio_Core_Request::getInstance();
     $lang = $this->getParam('lang');
     $links = Modules_Core_Services_LinkProvider::getLinks($lang);
     $this->view->links = $links;
 }
コード例 #3
0
ファイル: Widget.php プロジェクト: piratevn/cms-gio
 public function __construct()
 {
     $this->view = clone Gio_Core_View::getInstance();
     $this->_request = Gio_Core_Request::getInstance();
     $this->_response = Gio_Core_Response::getInstance();
     $this->_translationDao = new Modules_Core_Models_Mysql_Translation();
 }
コード例 #4
0
ファイル: Request.php プロジェクト: piratevn/cms-gio
 /**
  * @return Gio_Core_Request
  */
 public static function getInstance()
 {
     if (null == self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #5
0
ファイル: Model.php プロジェクト: piratevn/cms-gio
 public function getLang()
 {
     $request = Gio_Core_Request::getInstance();
     $lang = $request->getParam('lang');
     $this->_lang = $lang;
     $this->_lang = null == $this->_lang ? Gio_Core_Config_Xml::getConfig('web')->language : $this->_lang;
     return $this->_lang;
 }
コード例 #6
0
ファイル: Hook.php プロジェクト: piratevn/cms-gio
 public static function add($articleId)
 {
     $request = Gio_Core_Request::getInstance();
     $articleRelateIds = $request->getParam('relateArticleIds');
     if ($articleId && !empty($articleRelateIds)) {
         $conn = Gio_Db_Connection::getConnection();
         $dao = new Modules_News_Models_Mysql_Article();
         $dao->addToRelateArticles($articleId, $articleRelateIds);
     }
 }
コード例 #7
0
ファイル: Exception.php プロジェクト: piratevn/cms-gio
 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);
 }
コード例 #8
0
ファイル: AdminAuth.php プロジェクト: piratevn/cms-gio
 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;
     }
 }
コード例 #9
0
ファイル: Hook.php プロジェクト: piratevn/cms-gio
 public static function add($itemId)
 {
     $request = Gio_Core_Request::getInstance();
     $itemName = $request->getParam('tagItemName');
     $itemRouteName = $request->getParam('tagItemRouteName');
     $detailsRoute = $request->getParam('tagDetailsRouteName');
     $tagIds = $request->getParam('tagIds');
     if ($tagIds) {
         Modules_Tag_Services_TagItem::delete(array('item_id' => $itemId, 'item_name' => $itemName, 'route_name' => $itemRouteName, 'details_route_name' => $detailsRoute));
         foreach ($tagIds as $tagId) {
             Modules_Tag_Services_TagItem::add(array('tag_id' => $tagId, 'item_id' => $itemId, 'item_name' => $itemName, 'route_name' => $itemRouteName, 'details_route_name' => $detailsRoute, 'params' => $itemName . ':' . $itemId));
         }
     }
 }
コード例 #10
0
ファイル: View.php プロジェクト: piratevn/cms-gio
 public function __construct($blocks = array())
 {
     $this->setBlocks($blocks);
     $configs = Gio_Core_Config_Xml::getConfig();
     /**
      * Not installed GioCMS
      */
     if (!Gio_Core_Application::_initInstallChecker()) {
         $request = Gio_Core_Request::getInstance();
         $configs->server->static = $request->getBaseUrl();
         $configs->server->resource = $request->getBaseUrl();
         $configs->web->url = $request->getBaseUrl();
     }
     $this->APP_STATIC_SERVER = (string) $configs->server->static;
     $this->APP_RESOURCE_SERVER = (string) $configs->server->resource;
     $this->APP_WEB_URL = (string) $configs->web->url;
     $this->APP_WEB_NAME = (string) $configs->web->name;
     $this->APP_TEMPLATE = (string) $configs->web->template;
     $this->APP_SKIN = (string) $configs->web->skin;
     $this->APP_META_KEYWORD = (string) $configs->web->meta->keyword;
     $this->APP_META_DESCRIPTION = (string) $configs->web->meta->description;
     $defaultLanguage = (string) $configs->web->language;
     //$lang						= Gio_Core_Request::getInstance()->getParam('lang');
     //$this->APP_LANG				= ($lang && $defaultLanguage != $lang) ? $lang : $defaultLanguage;
     $this->APP_LANG = $defaultLanguage;
     $routes = Gio_Core_Route::getInstance();
     $this->routes = $routes;
     $string = Gio_Core_String::getInstance();
     $this->STRING = $string;
     $translator = new Gio_Core_Translator();
     $this->TRANSLATOR = $translator;
     if (Gio_Core_Application::_initInstallChecker() == true) {
         $acl = Gio_Core_Acl::getIntance();
         $this->ACL = $acl;
     }
     $messenger = Gio_Core_Messenger::getInstance();
     $this->MESSENGER = $messenger;
     if (Gio_Core_Application::_initInstallChecker()) {
         $user = Gio_Core_Session::getUser();
         $this->USER = $user;
     }
     /**
      * JSON
      */
     $json = new Services_JSON();
     $this->JSON = $json;
     $this->CONFIG = $configs;
 }
コード例 #11
0
ファイル: Page.php プロジェクト: piratevn/cms-gio
 public static function factory()
 {
     $request = Gio_Core_Request::getInstance();
     $config = Gio_Core_Module::getConfig('page');
     $param = isset($config['url']['param']) ? $config['url']['param'] : 'page_id';
     $category = null;
     switch ($param) {
         case 'slug':
             $page = Modules_Page_Services_Page::getBySlug($request->getParam($param));
             break;
     }
     if (null == $page) {
         $page = Modules_Page_Services_Page::getById($request->getParam('page_id'));
     }
     return $page;
 }
コード例 #12
0
ファイル: Category.php プロジェクト: piratevn/cms-gio
 public static function factory()
 {
     $request = Gio_Core_Request::getInstance();
     $config = Gio_Core_Module::getConfig('category');
     $param = isset($config['url']['param']) ? $config['url']['param'] : 'category_id';
     $category = null;
     switch ($param) {
         case 'category_path':
             $category = Modules_Category_Services_Category::getByPath($request->getParam($param));
             break;
     }
     if (null == $category) {
         $category = Modules_Category_Services_Category::getById($request->getParam('category_id'));
     }
     return $category;
 }
コード例 #13
0
ファイル: Widget.php プロジェクト: piratevn/cms-gio
 protected function showAction()
 {
     $currRoute = Gio_Core_Route::getCurrentRoute();
     $routeName = $currRoute['name'];
     $defaults = $currRoute;
     $request = $this->getRequest();
     $this->view->lang = $request->getParam('lang');
     $links = array();
     if (isset($defaults['localization']['enable']) && 'true' == $defaults['localization']['enable'] && isset($defaults['localization']['identifier']['class'])) {
         $class = $defaults['localization']['identifier']['class'];
         $name = $defaults['localization']['identifier']['param'];
         /**
          * The DAO method used to get the model instance
          */
         $method = isset($defaults['localization']['identifier']['method']) ? $defaults['localization']['identifier']['method'] : 'getById';
         $id = Gio_Core_Request::getInstance()->getParam($name);
         $conn = Gio_Db_Connection::getConnection();
         $translationDao = new Modules_Core_Models_Mysql_Translation();
         $translationDao->setConnection($conn);
         $items = $translationDao->getItems($id, $class);
         $array = explode('_', $class);
         $array[] = $array[count($array) - 1];
         $array[count($array) - 2] = 'Mysql';
         $daoClass = implode('_', $array);
         $daoInstance = new $daoClass();
         $daoInstance->setConnection($conn);
         if ($items != null) {
             $config = Gio_Core_Config_Xml::getConfig('localization');
             $languages = $config->languages->details;
             foreach ($items as $item) {
                 if ($item['item_id'] == $id) {
                     continue;
                 }
                 $object = $daoInstance->{$method}($item['item_id']);
                 if ($object != null) {
                     $language = $item['language'];
                     if (isset($languages[$item['language']])) {
                         $info = explode('|', $languages[$item['language']]);
                         $language = $info[1];
                     }
                     $links[] = array('url' => $this->view->url($routeName, $object), 'label' => $language);
                 }
             }
         }
     }
     $this->view->assign('links', $links);
 }
コード例 #14
0
ファイル: Auth.php プロジェクト: piratevn/cms-gio
 public function myopenidAction()
 {
     $this->disableLayout();
     $this->setNoRender();
     $request = Gio_Core_Request::getInstance();
     $this->setLayout('login');
     require_once LIB_DIR . DS . 'openid' . DS . 'class.openid.v2.php';
     if ($request->isPost()) {
         $openidUrl = $request->getPost('openid_url');
         $openidUrl = rtrim($openidUrl, '/');
         $openid = new OpenIDService();
         $openid->SetIdentity($openidUrl);
         $openid->SetTrustRoot($request->getBaseUrl());
         $openid->SetRequiredFields(array('email', 'fullname'));
         $openid->SetOptionalFields(array('dob', 'gender', 'country'));
         if ($openid->GetOpenIDServer()) {
             $openid->SetApprovedURL($this->view->url('core_auth_myopenid'));
             $openid->Redirect();
         } else {
             $error = $openid->GetError();
             $error_code = $error["code"];
             $error_string = $error["description"];
         }
     } elseif ($request->getParam('openid_mode') == 'id_res') {
         $openid = new OpenIDService();
         $openidUrl = $request->getParam('openid_identity');
         $openidUrl = rtrim($openidUrl, '/');
         $openid->SetIdentity($openidUrl);
         $openid_validation_result = $openid->ValidateWithServer();
         /**
          * Login success
          */
         if ($openid_validation_result == true) {
             $user = Modules_Core_Services_User::getByOpenID($openidUrl);
             if ($user) {
                 $user['last_login'] = date('Y-m-d H:i:s');
                 Modules_Core_Services_User::setLastLogin($user);
                 $configs = Gio_Core_Config_Xml::getConfig('session');
                 $json = new Services_JSON();
                 $sessionId = session_id();
                 $session = array('session_id' => $sessionId, 'created_date' => strtotime(date('Y-m-d H:i:s')), 'last_update' => strtotime(date('Y-m-d H:i:s')), 'lifetime' => isset($configs->lifetime) ? $configs->lifetime : 3600, 'inactive_time' => isset($configs->inactive_time) ? $configs->inactive_time : 120, 'data' => $json->encodeUnsafe($user), 'status' => 'active');
                 Gio_Core_Session::add($session);
                 $this->redirect($this->view->url('core_dashboard_index'));
             }
         }
     }
 }
コード例 #15
0
 public function run()
 {
     $request = Gio_Core_Request::getInstance();
     $configs = Gio_Core_Config_Xml::getConfig();
     $adminUrlPrefix = $configs->web->admin->url_prefix;
     $currentUri = $request->getRedirectUrl();
     $baseUrl = $request->getBaseUrl();
     $webUrl = Gio_Core_Application::_initInstallChecker() ? $configs->web->url : $baseUrl;
     $temp = str_replace($baseUrl, '', $webUrl);
     $rewrite = '';
     $uri = $request->getRequestUri();
     $serverName = $request->getServerName();
     $serverPort = $request->getServerPort();
     $serverPort = $serverPort == 80 ? '' : ':' . $serverPort;
     $uri = 'http://' . $serverName . $serverPort . $uri;
     $currentUrl = str_replace($webUrl, '', $uri);
     $uri = '/' . rtrim(ltrim($currentUrl, '/'), '/');
     /**
      * We are in the front-end section
      * 7 is length of /admin/
      */
     if (!$adminUrlPrefix || substr($uri, 0, strlen($adminUrlPrefix) + 2) != "/{$adminUrlPrefix}/") {
         $paths = explode('/', ltrim($uri, '/'));
         $currLang = array_shift($paths);
     } else {
         $paths = explode('/', rtrim($uri, '/'));
         $currLang = array_pop($paths);
     }
     /**
      * Add language parameter.
      * Set the request URI if there is language in URI
      */
     $languages = isset($configs->localization->languages->list) ? explode(',', $configs->localization->languages->list) : array($configs->localization->languages->default);
     if (in_array($currLang, explode(',', (string) $configs->localization->languages->list))) {
         $request->setParam('lang', $currLang);
         $path = implode('/', $paths);
         if ('' == $path) {
             $path = '/';
         }
         $currentUri = str_replace('/' . $currLang, '', $currentUri);
         $request->setRedirectUrl(rtrim($currentUri, '/'));
     } else {
         $lang = $request->getParam('lang') != null ? $request->getParam('lang') : (string) $configs->web->language;
         $request->setParam('lang', $lang);
     }
 }
コード例 #16
0
ファイル: Plugin.php プロジェクト: piratevn/cms-gio
 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');
     //}
 }
コード例 #17
0
ファイル: Acl.php プロジェクト: piratevn/cms-gio
 public function isAllowed($actionId, $controllerId = null, $moduleId = null)
 {
     if (null == $this->_user) {
         return null;
     }
     $request = Gio_Core_Request::getInstance();
     $moduleId = null == $moduleId ? $request->getParam('module') : $moduleId;
     $controllerId = null == $controllerId ? $request->getParam('controller') : $controllerId;
     $action = Modules_Core_Services_Action::getByMCA($moduleId, $controllerId, $actionId);
     if (null == $action) {
         return true;
     }
     if ($this->_rules) {
         $roleId = isset($this->_user->role_id) ? $this->_user->role_id : null;
         $roleName = 'role_' . $roleId;
         $userId = isset($this->_user->user_id) ? $this->_user->user_id : null;
         $userRoleName = 'user_' . $userId;
         $moduleController = $moduleId . ':' . $controllerId;
         $pattern = array('role_name' => $roleName, 'allow' => 0, 'module_controller' => $moduleController, 'action_id' => $actionId);
         $userPattern = array('role_name' => $userRoleName, 'allow' => 0, 'module_controller' => $moduleController, 'action_id' => $actionId);
         if (in_array($pattern, $this->_rules) || in_array($userPattern, $this->_rules)) {
             return false;
         } else {
             $pattern['allow'] = 1;
             $userPattern['allow'] = 1;
             if (in_array($pattern, $this->_rules) || in_array($userPattern, $this->_rules)) {
                 return true;
             } else {
                 $pattern['module_controller'] = null;
                 $pattern['action_id'] = null;
                 $userPattern['module_controller'] = null;
                 $userPattern['action_id'] = null;
                 if (in_array($pattern, $this->_rules) || in_array($userPattern, $this->_rules)) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
コード例 #18
0
ファイル: Permalink.php プロジェクト: piratevn/cms-gio
 public function run()
 {
     $request = Gio_Core_Request::getInstance();
     $configs = Gio_Core_Config_Xml::getConfig('web');
     /**
      * Do nothing if we are in page of managing permalink
      */
     $uri = $request->getRequestUri();
     $uri = strtolower($uri);
     $uri = rtrim($uri, '/') . '/';
     $adminPrefix = $configs->admin->url_prefix;
     $adminPrefix = rtrim(ltrim($adminPrefix, '/'), '/');
     if (is_int(strpos($uri, '/' . $adminPrefix . '/core/permalink'))) {
         return;
     }
     $defaultFile = ROOT_DIR . DS . 'configs' . DS . 'permalink.xml';
     $host = $request->getServerName();
     $host = substr($host, 0, 3) == 'www' ? substr($host, 4) : $host;
     $file = ROOT_DIR . DS . 'configs' . DS . $host . '.' . 'permalink.xml';
     $file = file_exists($file) ? $file : $defaultFile;
     if (!file_exists($file)) {
         return;
     }
     $route = Gio_Core_Route::getInstance();
     $config = @simplexml_load_file($file);
     if (!isset($config->item) || empty($config->item)) {
         return;
     }
     $categoryConfig = Gio_Core_Module::getConfig('category');
     $param = isset($categoryConfig['url']['param']) ? $categoryConfig['url']['param'] : 'category_id';
     foreach ($config->item as $index => $item) {
         $item = (array) $item;
         if (!in_array($item['name'], $this->_inArray)) {
             $route->setRoute($item['name'], $item);
         } elseif ($param == 'category_path' && in_array($item['name'], $this->_inArray)) {
             $route->setRoute($item['name'], $item);
         }
     }
 }
コード例 #19
0
ファイル: Widget.php プロジェクト: piratevn/cms-gio
 public function showAction()
 {
     $perPage = $this->getParam('limit', 10);
     $this->view->limit = $perPage;
     $pageIndex = $this->getParam('pageIndex', 1);
     $offset = ($pageIndex - 1) * $perPage;
     $request = Gio_Core_Request::getInstance();
     $json = new Services_JSON();
     $params = $request->getParams();
     $paramString = base64_encode($json->encodeUnsafe($params));
     $this->view->paramString = $paramString;
     /**
      * Get comments by paramString
      */
     $numComments = Modules_Comment_Services_Comment::countThreadComments($paramString, 'active');
     $comments = Modules_Comment_Services_Comment::getThreadComments($offset, $perPage, $paramString, 'active');
     $this->view->comments = $comments;
     $this->view->numComments = $numComments;
     // Pager
     require_once LIB_DIR . DS . 'PEAR' . DS . 'Pager' . DS . 'Sliding.php';
     $pagerOptions = array('mode' => 'Sliding', 'append' => false, 'perPage' => $perPage, 'delta' => 3, 'urlVar' => 'page', 'path' => '', 'fileName' => 'javascript: Comment.Widgets.Comment.loadComments(%d)', 'separator' => '', 'nextImg' => '<small class="icon arrow_right"></small>', 'prevImg' => '<small class="icon arrow_left"></small>', 'altNext' => '', 'altPrev' => '', 'altPage' => '', 'totalItems' => $numComments, 'currentPage' => $pageIndex, 'urlSeparator' => '/', 'spacesBeforeSeparator' => 0, 'spacesAfterSeparator' => 0, 'curPageSpanPre' => '<a href="javascript: void();" class="current">', 'curPageSpanPost' => '</a>');
     $pager = new Pager_Sliding($pagerOptions);
     $this->view->pager = $pager;
 }
コード例 #20
0
ファイル: OfflineMessage.php プロジェクト: piratevn/cms-gio
 public function run()
 {
     $request = Gio_Core_Request::getInstance();
     $configs = Gio_Core_Config_Xml::getConfig('web');
     $adminPrefixUrl = $configs->admin->url_prefix;
     $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}/") {
         if (isset($configs->offline->enable) && (string) $configs->offline->enable == 'true') {
             $message = isset($configs->offline->message) ? $configs->offline->message : null;
             Modules_Core_Services_Exception::error('OFFLINE_MESSAGE');
         }
     }
 }
コード例 #21
0
ファイル: Route.php プロジェクト: piratevn/cms-gio
 public static function getCurrentRoute($return = false)
 {
     $routes = self::getInstance()->getRoutes();
     $request = Gio_Core_Request::getInstance();
     $configs = Gio_Core_Config_Xml::getConfig();
     $baseUrl = $request->getBaseUrl();
     $webUrl = Gio_Core_Application::_initInstallChecker() ? $configs->web->url : $baseUrl;
     $temp = str_replace($baseUrl, '', $webUrl);
     $rewrite = '';
     $uri = $request->getRequestUri();
     if (null == $uri) {
         $currentUrl = '';
     } else {
         $serverName = $request->getServerName();
         $serverPort = $request->getServerPort();
         $serverPort = $serverPort == 80 ? '' : ':' . $serverPort;
         $uri = 'http://' . $serverName . $serverPort . $uri;
         $currentUrl = str_replace($webUrl, '', $uri);
         $currentUrl = rtrim(ltrim($currentUrl, '/'), '/');
     }
     foreach ($routes as $index => $route) {
         if (isset($route['url' . $rewrite])) {
             if (strtolower($route['type']) == 'regex') {
                 $pattern = '/' . str_replace('/', '\\/', '^' . $route['url' . $rewrite]) . '$/';
                 $pattern = str_replace('?', '\\?', $pattern);
                 $pattern = str_replace('###admin_url_prefix###', $configs->web->admin->url_prefix, $pattern);
                 if (preg_match($pattern, $currentUrl, $matches)) {
                     /**
                      * Set params
                      */
                     $params = isset($route['params']) ? (array) $route['params'] : null;
                     if (!empty($params)) {
                         foreach ($params as $key => $value) {
                             $request->setParam($key, $matches[$value]);
                         }
                     }
                     return $route;
                 } else {
                     continue;
                 }
             } else {
                 if (rtrim(str_replace('###admin_url_prefix###', $configs->web->admin->url_prefix, $route['url' . $rewrite]), '/') == $currentUrl) {
                     return $route;
                     break;
                 }
             }
         } else {
             continue;
         }
     }
     if ($return) {
         return null;
     }
     Modules_Core_Services_Exception::error('ROUTE_NOT_FOUND');
 }
コード例 #22
0
ファイル: Translator.php プロジェクト: piratevn/cms-gio
 private static function _getLang()
 {
     $route = Gio_Core_Route::getCurrentRoute(true);
     $configs = Gio_Core_Config_Xml::getConfig('web');
     $lang = $configs->language;
     if (isset($route['localization']['enable']) && $route['localization']['enable'] == true) {
         $request = Gio_Core_Request::getInstance();
         $lang = $request->getParam('lang');
     }
     return $lang;
 }
コード例 #23
0
ファイル: Language.php プロジェクト: piratevn/cms-gio
 /**
  * Show the links that allows user to switch to other language
  * 
  * @param string $style    Can take one of following values:
  * - locale: Show the locale (en_US, for example)
  * - language: Show the language name (English)
  * - flag: Show the flag image
  * 
  * @param string $separate
  * @return string
  */
 public static function languageSwitcher($style = 'locale', $separate = ' | ')
 {
     $view = Gio_Core_View::getInstance();
     $request = Gio_Core_Request::getInstance();
     $baseUrl = $view->APP_WEB_URL;
     $label = '%s';
     switch ($style) {
         case 'flag':
             $label = '<img src="' . $view->APP_STATIC_SERVER . '/images/flags/%s.png"%s />';
             break;
         case 'locale':
         default:
             $label = '%s';
             break;
     }
     $configs = Gio_Core_Config_Xml::getConfig();
     $languages = isset($configs->localization->languages->list) ? explode(',', $configs->localization->languages->list) : array($configs->localization->languages->default);
     $paramLang = $request->getParam('lang', $configs->localization->languages->default);
     foreach ($languages as $lang) {
         $className = $lang == $paramLang ? ' class="g_a_language_flag_active"' : ' class="g_a_language_flag"';
         $output[] = '<a href="' . $request->getRequestUri() . '/' . $lang . '">' . sprintf($label, $lang, $className) . '</a>';
     }
     return implode($separate, $output);
 }
コード例 #24
0
ファイル: Install.php プロジェクト: piratevn/cms-gio
 public function step1Action()
 {
     /**
      * Remove all plugins
      */
     Gio_Core_Application::getInstance()->removePlugins();
     if (Gio_Core_Application::_initInstallChecker()) {
         $this->redirect($this->view->url('core_index_index'));
     }
     $this->setTemplate('admin');
     $this->setLayout('install');
     $request = $this->getRequest();
     $configs = Gio_Core_Config_Xml::getConfig();
     $request = Gio_Core_Request::getInstance();
     if ((string) $configs->web->url != $request->getBaseUrl()) {
         $configs->server->static = $request->getBaseUrl();
         $configs->server->resource = $request->getBaseUrl();
         $configs->web->url = $request->getBaseUrl();
     }
     $this->view->configs = $configs;
     $timezone = array('timezone' => array('date' => (string) $configs->timezone->date, 'datetime' => (string) $configs->timezone->datetime));
     $localization = array('localization' => array('enable' => (string) $configs->localization->enable, 'languages' => array('default' => (string) $configs->localization->languages->default, 'list' => (string) $configs->localization->languages->list, 'details' => array())));
     if ($configs->localization->languages->list != null) {
         $list = explode(',', $configs->localization->languages->list);
         foreach ($list as $value) {
             $localization['localization']['languages']['details'][$value] = (string) $configs->localization->languages->details->{$value};
         }
     }
     $languagesFile = ROOT_DIR . DS . 'configs' . DS . 'languages.xml';
     if (!file_exists($languagesFile)) {
         return;
     }
     $languagesXml = @simplexml_load_file($languagesFile);
     if (null == $languagesXml) {
         return;
     }
     $locales = array();
     foreach ($languagesXml->language as $language) {
         $arr = explode('|', $language);
         $locales[$arr[0]] = array('code' => $arr[0], 'localName' => $arr[1], 'englishName' => $arr[2]);
     }
     $this->view->locales = $locales;
     if ($request->isPost()) {
         $act = $request->getPost('act');
         switch ($act) {
             case 'testdbconn':
                 $this->setNoRender();
                 $this->disableLayout();
                 $this->_testdbconn();
                 break;
             case '':
             default:
                 $configs = $request->getPost('configs');
                 $data = Modules_Core_Services_Installer::validate($configs);
                 if (isset($data['messages_error']) && $data['messages_error']) {
                     $this->view->errorMessages = $data['messages'];
                     $configs = Gio_Core_Array::toObject($configs);
                     $this->view->configs = $configs;
                     return;
                 }
                 $install = array('install' => array('version' => Gio_Core_Cms::getVersion(), 'date' => date('Y-m-d H:i:s'), 'author' => Gio_Core_Cms::getAuthor()));
                 $configs = array_merge($configs, $install);
                 $configs = array_merge($configs, $localization);
                 $configs = array_merge($configs, $timezone);
                 $content = utf8_decode(Gio_Core_Array::toXml($configs, 'config'));
                 $fileName = Gio_Core_Config_Xml::getConfigFile();
                 Gio_Core_File::writeToFile($fileName, $content);
                 $adminInfo = array('username' => 'admin', 'password' => '123456', 'email' => '*****@*****.**', 'fullname' => 'Ninhgio');
                 Modules_Core_Services_Installer::install(false, $adminInfo);
                 $this->redirect($this->view->url('core_index_index'));
                 break;
         }
     }
 }
コード例 #25
0
ファイル: Cron.php プロジェクト: piratevn/cms-gio
    public function autopro($linkId)
    {
        ini_set("memory_limit", "256M");
        $conn = Gio_Db_Connection::getConnection();
        if ($linkId) {
            $ext = $linkId == -1 ? null : ' AND cron_id = ' . (int) $linkId;
            $sql = 'SELECT * FROM ' . $conn->_tablePrefix . 'news_cron WHERE website_name="autopro" 
						AND is_locked = 0 AND status = "active"' . $ext;
        } else {
            $numCategories = isset($this->_configs['auto_update_num_category']) ? $this->_configs['auto_update_num_category'] : 5;
            $sql = 'SELECT * FROM ' . $conn->_tablePrefix . 'news_cron
					WHERE status = "active" AND TIMESTAMPDIFF(SECOND, last_update, "' . date('Y-m-d H:i:s') . '") > frequency
						AND website_name = "autopro" AND is_locked = 0 
					ORDER BY priority
					LIMIT ' . (int) $numCategories;
        }
        $rsSql = $conn->query($sql);
        $addArticles = array();
        $addCategories = array();
        $request = new Gio_Core_Request();
        $articleDao = new Modules_News_Models_Mysql_Article();
        $articleDao->setConnection($conn);
        while ($row = $conn->fetchAll($rsSql)) {
            $pageIndex = $request->getParam('page_index');
            $pageIndex = $pageIndex > 0 ? '/trang-' . $pageIndex . '.chn' : null;
            if ($pageIndex) {
                $row['source'] = str_replace('.chn', $pageIndex, $row['source']);
            }
            /**
             * Check time
             */
            if (($htmlString = @file_get_contents($row['source'])) === false) {
                continue;
            }
            $html = str_get_html($htmlString);
            $container = $html->find('div.divCMTC', 0);
            $categories = explode('-', $row['category_ids']);
            $articles = $container->find('div[id=smallava2]');
            foreach ($articles as $index => $item) {
                $linkSource = $item->find('a', 0)->href;
                $link = $row['website'] . $linkSource;
                $title = $item->find('h1', 0)->plaintext;
                $image = $item->find('img', 0);
                $description = $item->find('h2', 0)->plaintext;
                $description = str_replace('Xem tiếp', '', $description);
                /**
                 * Check article exists
                 */
                $existsArticle = $articleDao->getBySlug(Gio_Core_String::removeSign(trim($title), '-', true));
                if (null == $existsArticle) {
                    $article = array('title' => trim($title), 'slug' => Gio_Core_String::removeSign($title, '-', true), 'description' => trim($description), 'created_date' => date('Y-m-d H:i:s'), 'link_source' => $link, 'image_url' => isset($image->src) ? $image->src : null, 'category_ids' => $row['category_ids'], 'website' => 'autopro');
                    $addArticles[] = $article;
                    $addCategories[] = $categories;
                }
            }
            /**
             * Update time for cron
             */
            $sql = 'UPDATE ' . $conn->_tablePrefix . 'news_cron SET last_update = "' . date('Y-m-d H:i:s') . '"
						WHERE cron_id = ' . $conn->escape($row['cron_id']);
            $rsUpdate = $conn->query($sql);
            $conn->freeResult($rsUpdate);
        }
        $conn->freeResult($rsSql);
        /**
         * Add articles, Add Categories
         */
        if ($addArticles && $addCategories) {
            $this->addArticles[] = $addArticles;
            $this->addCategories[] = $addCategories;
        }
    }
コード例 #26
0
ファイル: Session.php プロジェクト: piratevn/cms-gio
    public static function getSessionById($sessionId = null, $session = null)
    {
        $configs = Gio_Core_Config_Xml::getConfig('session');
        $sessionId = $sessionId ? $sessionId : self::getId();
        $mysql = new Gio_Db_Mysql();
        /**
         * Clear Session Expried
         */
        $sql = 'DELETE FROM ' . $mysql->_tablePrefix . 'core_session
					WHERE last_update + lifetime < ' . strtotime(date('Y-m-d H:i:s'));
        $rs = $mysql->query($sql);
        $mysql->freeResult($rs);
        /**
         * Update Session Status
         */
        $sql = 'UPDATE ' . $mysql->_tablePrefix . 'core_session
				SET status = "inactive"
				WHERE last_update + inactive_time < ' . strtotime(date('Y-m-d H:i:s'));
        $rs = $mysql->query($sql);
        $mysql->freeResult($rs);
        /**
         * 
         */
        $sql = 'SELECT * FROM ' . $mysql->_tablePrefix . 'core_session 
						WHERE session_id = "' . $mysql->escape($sessionId) . '" LIMIT 1';
        $rs = $mysql->query($sql);
        $row = 0 == $mysql->count($rs) ? null : $mysql->fetchAll($rs);
        $json = new Services_JSON();
        if (null == $row) {
            $request = Gio_Core_Request::getInstance();
            $session = array('session_id' => $sessionId, 'data' => null, 'created_date' => time(), 'last_update' => time(), 'lifetime' => isset($configs->lifetime) ? $configs->lifetime : 3600, 'inactive_time' => isset($configs->inactive) ? $configs->inactive : 120, 'ip' => $request->getRemoteIp());
            $mysql->insert($session, $mysql->_tablePrefix . 'core_session');
            return $session;
        }
        self::lastUpdate(time(), $row['session_id']);
        if ($session != null) {
            self::update($session['data'], $session['session_id']);
            return $session;
        }
        return $row;
    }
コード例 #27
0
ファイル: Controller.php プロジェクト: piratevn/cms-gio
 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;
     }
 }