public static function show($articleId = null) { $view = Gio_Core_View::getInstance(); $relateArticles = Modules_News_Services_ArticleRelate::getArticles($articleId); $view->relateArticles = $relateArticles; $viewFile = TEMPLATE_DIR . DS . $view->APP_TEMPLATE . DS . 'modules' . DS . 'news' . DS . '_partial' . DS . '_articleRelate.phtml'; echo $view->render($viewFile, true); }
/** * @return Gio_Core_Application */ public function __construct() { /** * Run Plugin Localization */ Gio_Core_Plugins_LocalizationRoute::getInstance()->run(); $this->_view = Gio_Core_View::getInstance(); return $this; }
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; } }
/** * @param array $links * @param string $lang * @return array */ public static function filter($links, $lang) { /** * Get the view instance */ $view = Gio_Core_View::getInstance(); $pages = Modules_Page_Services_Page::getTree($lang); if (count($pages) > 0) { foreach ($pages as $page) { $links['page_page_details'][] = array('title' => $page['name'], 'text' => str_repeat('---', $page['depth']) . ' ' . $page['name'], 'href' => $view->url('page_page_details', $page)); } } return $links; }
public static function show($itemName, $routeName, $detailsRouteName, $itemId = null) { $view = Gio_Core_View::getInstance(); if ($itemId) { $item = array('item_id' => $itemId, 'item_name' => $itemName, 'route_name' => $routeName, 'details_route_name' => $detailsRouteName); $tags = Modules_Tag_Services_Tag::getByItem($item); $view->tags = $tags; } $view->tagItemName = $itemName; $view->tagItemRouteName = $routeName; $view->tagDetailsRouteName = $detailsRouteName; $viewFile = TEMPLATE_DIR . DS . $view->APP_TEMPLATE . DS . 'modules' . DS . 'tag' . DS . '_partial' . DS . '_tagger.phtml'; echo $view->render($viewFile, true); }
public static function moduleSelect($attributes = array()) { $json = new Services_JSON(); $view = Gio_Core_View::getInstance(); $selectedId = isset($attributes['selected']) ? $attributes['selected'] : null; $disableId = isset($attributes['disable']) ? $attributes['disable'] : null; $elementDisabled = isset($attributes['disabled']) && $attributes['disabled'] === true ? ' disabled="disabled"' : ''; $output = sprintf("<select name='%s' id='%s' viewHelperClass='%s' viewHelperAttributes='%s'%s>", $attributes['name'], $attributes['id'], 'Modules_Core_Services_Module', $json->encodeUnsafe($attributes), $elementDisabled) . self::EOL . '<option value="">---</option>' . self::EOL; $modules = self::getModulesInstalled(); foreach ($modules as $module) { $selected = $selectedId == null || $selectedId != $module['module_id'] ? '' : ' selected="selected"'; $disable = $disableId == null || $disableId != $module['module_id'] ? '' : ' disabled'; $output .= sprintf('<option value="%s"%s%s>%s</option>', $module['module_id'], $selected, $disable, $view->TRANSLATOR->translator('about_' . $module['description'] . '_title', $module['module_id'])) . self::EOL; } $output .= '</select>' . self::EOL; return $output; }
public static function filter($content) { $view = Gio_Core_View::getInstance(); $path = $view->APP_STATIC_SERVER . '/js/jquery.nyroModal'; $append = <<<END \t\t<script type="text/javascript"> \t\t\$(document).ready(function() { \t\t\t\$('<link rel="stylesheet" type="text/css" href="{$path}/jquery.nyroModal.css" />').appendTo('head'); \t\t\t\$('<script type="text/javascript" src="{$path}/jquery.nyroModal-1.6.2.pack.js"><' + '/script>').prependTo('body'); \t\t\t \t\t\t\$('.news-article-content').find('img').each(function() { \t\t\t\t\$(this).removeAttr('onclick'); \t\$(this).wrap('<a href="' + \$(this).attr("src") + '" class="nyroModal" rel="gal" />'); \t}); \t\t\t\$('.news-article-content a.nyroModal').nyroModal();\t\t\t \t}); \t\t</script> END; return $content . $append; }
public static function load($module, $name, $action, $params = array(), $cacheEnable = false, $cacheTimeout = 0) { $configs = Gio_Core_Config_Xml::getConfig('web'); $widgetContent = Gio_Core_Widget::getIntance()->setTemplate($configs->template)->setModuleName($module)->setWidgetName($name)->setActionName($action)->setCacheEnable($cacheEnable)->setCacheTimeout($cacheTimeout)->setParams($params)->dispatch(); $view = Gio_Core_View::getInstance(); $return = array('title' => '', 'cssFiles' => array(), 'jsFiles' => array(), 'jsScripts' => array(), 'content' => ''); $search = array('{APP_WEB_URL}', '{APP_STATIC_SERVER}', '{WIDGET_URL}'); $replace = array($view->APP_WEB_URL, $view->APP_STATIC_SERVER, $view->APP_STATIC_SERVER . '/modules/' . strtolower($module) . '/widgets/' . strtolower($name)); if ($action != 'config') { /** * Gets widget resources that are defined in widget information file */ $file = ROOT_DIR . DS . 'modules' . DS . strtolower($module) . DS . 'widgets' . DS . strtolower($name) . DS . 'about.xml'; if (file_exists($file)) { $config = @simplexml_load_file($file); if ($resources = $config->resources) { if ($resources = $resources->resource) { foreach ($resources as $resource) { $attr = $resource->attributes(); switch ((string) $attr['type']) { case 'css': $return['cssFiles'][] = str_replace($search, $replace, (string) $attr['src']); break; case 'javascript': $return['jsFiles'][] = str_replace($search, $replace, (string) $attr['src']); break; } } } } } } $return['content'] = $widgetContent; $pattern = '/<script[^>]*>(.*)<\\/script>$/is'; if (preg_match_all($pattern, $widgetContent, $matches)) { $return['jsScripts'] = $matches[1]; $return['content'] = str_replace($matches[1], '', $widgetContent); } return $return; }
/** * @param array $links * @param string $lang * @return array */ public static function filter($links, $lang) { /** * Get the view instance */ $view = Gio_Core_View::getInstance(); /** * Get most recently activated articles * TODO: Make this variable configurable */ $limit = 10; // $articles = Modules_News_Services_Article::find(0, $limit, array('status' => 'active')); // // if (count($articles) > 0) { // foreach ($articles as $article) { // $links['news_article_details'][] = array( // 'title' => $article['title'], // 'text' => $article['title'], // 'href' => $view->url('news_article_details', $article), // ); // } // } /** * Get categories links */ $categories = Modules_Category_Services_Category::getTree($lang, 'news'); if (count($categories) > 0) { foreach ($categories as $category) { $links['news_article_category'][] = array('title' => $category['name'], 'text' => str_repeat('---', $category['depth']) . ' ' . $category['name'], 'href' => $view->url('news_article_category', $category)); $links['news_rss_category'][] = array('title' => $category['name'], 'text' => str_repeat('---', $category['depth']) . ' ' . $category['name'], 'href' => $view->url('news_rss_category', $category)); } } /** * RSS links for latest articles */ $links['news_rss_index'][] = array('href' => $view->url('news_rss_index', array('language' => $lang))); return $links; }
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'); } }
public static function getLinks($lang = null) { if (null == $lang) { $lang = Gio_Core_Config_Xml::getConfig('web')->language; } $view = Gio_Core_View::getInstance(); $router = Gio_Core_Route::getInstance(); $results = array(); $links = array(); /** * Add the homepage link */ $links['core_index_index'][] = array('href' => $view->url('core_index_index', array('language' => $lang))); $links = Gio_Core_Hook_Registry::getInstance()->executeFilter('Core_LinkProvider', $links, array($lang)); foreach ($links as $routeName => $value) { /** * Get route description */ $defaults = $router->getRoute($routeName); $description = isset($defaults['langKey']) ? $view->TRANSLATOR->translator($defaults['langKey'], $defaults['module'], $lang) : $routeName; $results[$routeName] = array('description' => $description, 'links' => $value); } return $results; }
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; } }
public function appendElement() { if ($this->_csrfEnable) { $element = sprintf('<input type="hidden" name="%s" value="%s" />', $this->_name, $this->getToken()); $view = Gio_Core_View::getInstance(); $view->tokenElement = $element; } }
/** * Perform install actions * * @param bool $importSampleData * @return bool */ public static function install($importSampleData = false, $adminInfo = array()) { try { $view = Gio_Core_View::getInstance(); $moduleDirs = Gio_Core_File::getSubDir(ROOT_DIR . DS . 'modules'); /** * Install modules */ $modules = array(); foreach ($moduleDirs as $module) { $modules[] = Modules_Core_Services_Module::install($module); } foreach ($modules as $module) { if ($module) { Modules_Core_Services_Module::add($module); } } /** * Install widgets */ foreach ($moduleDirs as $module) { /** * Load all widgets from module */ $widgetDirs = Gio_Core_File::getSubDir(ROOT_DIR . DS . 'modules' . DS . $module . DS . 'widgets'); foreach ($widgetDirs as $widgetName) { $widget = array('module_id' => $module, 'widget_id' => $widgetName, 'title' => $view->TRANSLATOR->widget('about_title', $module, $widgetName), 'description' => $view->TRANSLATOR->widget('about_description', $module, $widgetName), 'created_date' => date('Y-m-d H:i:s')); Modules_Core_Services_Widget::add($widget); } } /** * Create resources and previleges */ foreach ($moduleDirs as $module) { $file = ROOT_DIR . DS . 'modules' . DS . $module . DS . 'configs' . DS . 'permissions.xml'; if (!file_exists($file)) { continue; } $xml = simplexml_load_file($file); foreach ($xml->controller as $res) { $attr = $res->attributes(); $langKey = (string) $attr['langKey']; $description = $view->TRANSLATOR->translator($langKey, $module); $description = $description == $langKey ? (string) $attr['description'] : $description; $resource = array('controller_id' => $attr['name'], 'description' => $description, 'module_id' => $module, 'created_date' => date('Y-m-d H:i:s')); /** * Add resource */ Modules_Core_Services_Controller::add($resource); if ($res->action) { foreach ($res->action as $pri) { $attr2 = $pri->attributes(); $langKey = (string) $attr2['langKey']; $description = $view->TRANSLATOR->translator($langKey, $module); $description = $description == $langKey ? (string) $attr2['description'] : $description; $privilege = array('controller_id' => $attr['name'], 'description' => $description, 'module_id' => $module, 'action_id' => $attr2['name'], 'created_date' => date('Y-m-d H:i:s')); Modules_Core_Services_Action::add($privilege); } } } } /** * Finally, init data */ $dbFile = ROOT_DIR . DS . 'install' . DS . 'db.xml'; if (file_exists($dbFile)) { $xml = simplexml_load_file($dbFile); $xpath = $xml->xpath('module/query'); if (is_array($xpath) && count($xpath) > 0) { $conn = Gio_Db_Connection::getConnection(); foreach ($xpath as $query) { $q = str_replace('###table_prefix###', $conn->_tablePrefix, (string) $query); $conn->query($q); } } } /** * Allows user to import sample data */ if ($importSampleData) { $file = ROOT_DIR . DS . 'install' . DS . 'giocms_sample_db.sql'; $importer = Gio_Core_Import_Importer::getInstance(); if ($importer != null && $file != null) { $importer->import($file); } } /** * Create admin user */ $salt = md5(time()); $user = array('username' => $adminInfo['username'], 'password' => md5(md5($adminInfo['password']) . $salt), 'email' => $adminInfo['email'], 'fullname' => $adminInfo['fullname'], 'salt' => $salt, 'status' => 'active', 'created_date' => date('Y-m-d H:i:s'), 'role_id' => 1); Modules_Core_Services_User::add($user); } catch (Exception $ex) { return false; } return true; }
/** * Display select box listing all articles * which haven't been translated from the default language * * @param $attributes array * @param string $lang * @return string */ public static function translatableArticle($attributes = array(), $lang = null) { $limit = isset($attributes['limit']) ? $attributes['limit'] + 10 : 10; $attributes['limit'] = $limit; $view = Gio_Core_View::getInstance(); $json = new Services_JSON(); $defaultLang = (string) Gio_Core_Config_Xml::getConfig('web')->language; $lang = null == $lang ? $defaultLang : $lang; $elementDisabled = null == $lang || $lang == $defaultLang ? ' disabled="disabled"' : ''; $attributes['selected'] = isset($attributes['selected']) ? $attributes['selected'] : null; $attributes['disabled'] = isset($attributes['disabled']) ? $attributes['disabled'] : null; $articles = self::getTranslatable($lang, $limit, $attributes['selected']); $output = sprintf("<select name='%s' id='%s' viewHelperClass='%s' viewHelperAttributes='%s'%s>", $attributes['name'], $attributes['id'], 'Modules_News_Services_Article::translatableArticle', $json->encodeUnsafe($attributes), $elementDisabled) . self::EOL . '<option value=\'{"id": "", "language": ""}\'>---</option>' . self::EOL; foreach ($articles as $article) { $disabled = 0 == (int) $article['translatable'] && (0 == (int) $attributes['disabled'] && $article['article_id'] != (int) $attributes['selected'] || (int) $attributes['disabled'] == (int) $attributes['selected']) ? ' disabled="disabled"' : ''; $selected = $elementDisabled == '' && $disabled == '' && (int) $article['article_id'] == (int) $attributes['selected'] ? ' selected="selected"' : ''; $output .= sprintf("<option value='%s'%s%s>%s</option>", $json->encodeUnsafe(array('id' => $article['article_id'], 'language' => $defaultLang)), $selected, $disabled, $article['title']) . self::EOL; } $output .= '<option value="">' . $view->TRANSLATOR->translator('helper_translatable_article_more', 'news') . '</option>'; $output .= '</select>' . self::EOL; $id = $attributes['id']; $url = $view->url('core_locale_viewhelper'); $scripts = <<<END \t\t<script type="text/javascript"> \t\t\t\$(document).ready(function() { \t\t\t\t\$('#{$id}').change(function() { \t\t\t\t\tif (\$(this).val() != '') { \t\t\t\t\t\treturn; \t\t\t\t\t} \t\t\t \t\t\t\t\t/** \t\t\t\t\t * Load more articles \t\t\t\t\t */ \t\t\t\t\tvar self = this; \t\t\t\t\tvar parent = \$(self).parent(); \t\t\t\t\t\$(parent).addClass('g_a_ajax_loading'); \t\t\t\t\t \t\t\t\t\t\$.ajaxq('Core_View_Helper_LanguageSelector', { \t\t\t\t\t\turl: '{$url}', \t\t\t\t\t\ttype: 'POST', \t\t\t\t\t\tdata: { \t\t\t\t\t\t\tid: \$(self).attr('id'), \t\t\t\t\t\t\tname: \$(self).attr('name'), \t\t\t\t\t\t\tlanguage: '{$lang}', \t\t\t\t\t\t\tviewHelperClass: \$(self).attr('viewHelperClass'), \t\t\t\t\t\t\tviewHelperAttributes: \$(self).attr('viewHelperAttributes') \t\t\t\t\t\t}, \t\t\t\t\t\tsuccess: function(response) { \t\t\t\t\t\t\t\$(parent).html(response).removeClass('g_a_ajax_loading'); \t\t\t \t\t\t\t\t\t\t/** \t\t\t\t\t\t\t * Disable source items element if user select the default language \t\t\t\t\t\t\t */ \t\t\t\t\t\t\tif ('{$lang}' == '{$defaultLang}') { \t\t\t\t\t\t\t\t\$(self).attr('disabled', 'disabled').find('option:selected').removeAttr('selected'); \t\t\t\t\t\t\t} else { \t\t\t\t\t\t\t\t\$(self).removeAttr('disabled'); \t\t\t\t\t\t\t} \t\t\t\t\t\t} \t\t\t\t\t}); \t\t\t\t}); \t\t\t}); \t\t</script> END; return $output . $scripts; }
/** * Reset the user's password * * @param string $link The encoded link * @return bool */ public static function resetPassword($link) { $json = new Services_JSON(); $criteria = (array) $json->decode(urldecode(base64_decode($link))); if (!isset($criteria['username']) || null == $criteria['username'] || !isset($criteria['email']) || null == $criteria['email'] || !isset($criteria['code']) || null == $criteria['code']) { return false; } $users = Modules_Core_Services_User::find($criteria, null, null); if ($users == null || count($users) == 0) { return false; } /** * Send the confirmation link to reset password via email */ $user = $users[0]; /** * Reset the password */ $password = self::generatePassword(); $passwordEncrypt = self::encryptPassword($password, $user['salt']); self::updatePasswordFor($user['username'], $passwordEncrypt); $template = Modules_Mail_Services_Template::getByName(Modules_Mail_Models_Template::TEMPLATE_NEW_PASSWORD); if ($template == null) { return; } $view = Gio_Core_View::getInstance(); $search = array(Modules_Mail_Models_Mail::MAIL_VARIABLE_EMAIL, Modules_Mail_Models_Mail::MAIL_VARIABLE_USERNAME); $replace = array($user['email'], $user['username']); $subject = str_replace($search, $replace, $template['subject']); $content = str_replace($search, $replace, $template['body']); $content = str_replace('%new_password%', $password, $content); $content = str_replace('%link%', $view->url('core_auth_login'), $content); /** * Get mail transport instance */ $mailer = Modules_Mail_Services_Mailer::getMailTransport(); $mailer->From = $template['from_mail']; $mailer->FromName = $template['from_name']; $mailer->AddAddress($user['email'], $user['username']); $mailer->AddReplyTo($template['reply_to_mail'], $template['reply_to_name']); $mailer->WordWrap = 50; // set word wrap $mailer->IsHTML(true); // send as HTML $mailer->Subject = $subject; $mailer->Body = $content; //HTML Body $mailer->AltBody = ""; //Text Body if (!$mailer->Send()) { return false; } else { return true; } }
public function dispatch() { $cacheType = 'widgets'; $request = $this->_request; /** * XML */ $xmlFilename = array($this->_module, $this->_widget, $this->_action); $xmlFilename = implode('_', $xmlFilename); /** * Check file html cache */ $globalConfig = Gio_Core_Config_Xml::getConfig(); $configs = Gio_Core_Config_Xml::getConfig('cache'); $checkCache = false; if ($configs->enable == 'true' && $this->_cacheEnable == true) { $cacheName = $xmlFilename; $postParams = $request->getPostParams(); $getParams = $request->getParams(); $widgetParams = $this->_params; $json = new Services_JSON(); $cacheParams = !empty($postParams) ? base64_encode($json->encodeUnsafe($postParams)) : null; $cacheParams = !empty($getParams) ? base64_encode($json->encodeUnsafe($getParams)) : null; $cacheParams = !empty($widgetParams) ? base64_encode($json->encodeUnsafe($widgetParams)) : null; $cacheKey = md5($cacheName . $this->_template . $cacheParams . base64_encode($json->encodeUnsafe($globalConfig))); $cacheTimeout = $this->_cacheTimeout ? $this->_cacheTimeout : 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; } } /** * Localization config */ $aboutFile = ROOT_DIR . DS . 'modules' . DS . $this->_module . DS . 'widgets' . DS . $this->_widget . DS . 'about.xml'; if (file_exists($aboutFile)) { $info = @simplexml_load_file($aboutFile); $localization = $info->localization['enable']; if ($localization != null && 'true' == (string) $localization) { $idClass = (string) $info->localization->identifier['class']; $idParam = (string) $info->localization->identifier['param']; $this->_params[$idParam] = isset($this->_params[$idParam]) ? $this->_params[$idParam] : null; $conn = Gio_Db_Connection::getConnection(); $this->_translationDao->setConnection($conn); $items = $this->_translationDao->getItems($this->_params[$idParam], $idClass, $request->getParam('lang')); if ($items != null && 1 == count($items)) { $this->_params[$idParam] = $items[0]['item_id']; } } } $ucfModule = ucfirst($this->_module); $ucfWidget = ucfirst($this->_widget); $widgetClassName = array('Modules', $ucfModule, 'Widgets', $ucfWidget, 'Widget'); $widgetClassName = implode('_', $widgetClassName); $widgetClass = new $widgetClassName(); if (!method_exists($widgetClass, $this->_action . 'Action')) { return; } $widgetClass->setParams($this->_params); call_user_func(array($widgetClass, $this->_action . 'Action')); $widgetDefaultViewFile = MOD_DIR . DS . $this->_module . DS . 'widgets' . DS . $this->_widget . DS . $this->_action . '.phtml'; $widgetViewFile = TEMPLATE_DIR . DS . $this->_template . DS . 'modules' . DS . $this->_module . DS . 'widgets' . DS . $this->_widget . DS . $this->_action . '.phtml'; $widgetViewFile = file_exists($widgetViewFile) ? $widgetViewFile : $widgetDefaultViewFile; $widgetClass->view->cacheEnable = $this->_cacheEnable; $widgetClass->view->cacheTimeout = $this->_cacheTimeout; $return = $widgetClass->view->render($widgetViewFile); if (!isset($this->_params['load']) || $this->_params['load'] != 'ajax') { $jsCss = array('cssFiles' => array(), 'jsFiles' => array()); $search = array('{APP_WEB_URL}', '{APP_STATIC_SERVER}', '{WIDGET_URL}'); $replace = array($this->view->APP_WEB_URL, $this->view->APP_STATIC_SERVER, $this->view->APP_STATIC_SERVER . DS . 'modules' . DS . strtolower($this->_module) . DS . 'widgets' . DS . strtolower($this->_widget)); $configFile = ROOT_DIR . DS . 'modules' . DS . strtolower($this->_module) . DS . 'widgets' . DS . strtolower($this->_widget) . DS . 'about.xml'; if (file_exists($configFile)) { $widgetConfig = @simplexml_load_file($configFile); if ($resources = $widgetConfig->resources) { if ($resources = $resources->resource) { foreach ($resources as $resource) { $attr = $resource->attributes(); switch ((string) $attr['type']) { case 'css': $jsCss['cssFiles'][] = str_replace($search, $replace, (string) $attr['src']); break; case 'javascript': $jsCss['jsFiles'][] = str_replace($search, $replace, (string) $attr['src']); break; } } } } } if ($jsCss['cssFiles']) { foreach ($jsCss['cssFiles'] as $index => $file) { Gio_Core_View::getInstance()->headStyle($file); } } if ($jsCss['jsFiles']) { foreach ($jsCss['jsFiles'] as $index => $file) { Gio_Core_View::getInstance()->headScript($file); } } } if (!$checkCache && $configs->enable == 'true' && $this->_cacheEnable == true) { $cacheCompress = isset($configs->compress) && $configs->compress == 'true' ? true : false; $cacheContent = Gio_Core_View::getInstance()->generateScripts() . Gio_Core_View::getInstance()->generateStyles() . $return; /** * HTML Compress */ if (isset($configs->compress) && $configs->compress == 'true') { $cacheContent = Gio_Core_HtmlCompress::compress($cacheContent); } Gio_Core_Cache::cache($cacheType, $cacheKey, $cacheContent, $cacheCompress); } return $return; }
/** * 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); }