Пример #1
0
 function beforeFilter()
 {
     # These should be called in each controller where they are required instead of globally
     $this->_db = cmsFramework::getDB();
     $this->_user = cmsFramework::getUser();
     # Overcome host restrictions
     $query = "SET SQL_BIG_SELECTS=1";
     $this->_db->setQuery($query);
     $this->_db->query();
     # Fix Joomla bug when language filter is active with default language code hidden in url
     if (isset($this->params['lang'])) {
         $this->params['lang'] = cmsFramework::getUrlLanguageCode();
     }
     # Init Access
     if (isset($this->Access)) {
         $this->Access->init($this->Config);
     }
     App::import('Component', 'theming', 'jreviews');
     $this->Theming = ClassRegistry::getClass('ThemingComponent');
     $this->Theming->startup($this);
     # Set pagination vars
     // First check url, then menu parameter. Otherwise the limit list in pagination doesn't respond b/c menu params always wins
     $this->limit = Sanitize::getInt($this->params, 'limit', Sanitize::getInt($this->data, 'limit_special', Sanitize::getInt($this->data, 'limit')));
     //		$this->passedArgs['limit'] = $this->limit;
     $this->page = Sanitize::getInt($this->data, 'page', Sanitize::getInt($this->params, 'page', 1));
     if (!$this->limit) {
         if (Sanitize::getVar($this->params, 'action') == 'myreviews') {
             $this->limit = Sanitize::getInt($this->params, 'limit', $this->Config->user_limit);
             $this->params['default_limit'] = $this->Config->user_limit;
         } else {
             $this->limit = Sanitize::getInt($this->params, 'limit', $this->Config->list_limit);
             $this->params['default_limit'] = $this->Config->list_limit;
         }
     }
     if (Sanitize::getVar($this->params, 'action') == 'myreviews') {
         $this->params['default_limit'] = $this->Config->user_limit;
     } else {
         $this->params['default_limit'] = $this->Config->list_limit;
     }
     // Set a hard code limit to prevent abuse
     $this->limit = max(min($this->limit, 50), 1);
     // Need to normalize the limit var for modules
     if (isset($this->params['module'])) {
         $module_limit = Sanitize::getInt($this->params['module'], 'module_limit', 5);
     } else {
         $module_limit = 5;
     }
     $this->module_limit = Sanitize::getInt($this->data, 'module_limit', $module_limit);
     $this->module_page = Sanitize::getInt($this->data, 'module_page', 1);
     $this->module_page = $this->module_page === 0 ? 1 : $this->module_page;
     $this->module_offset = (int) ($this->module_page - 1) * $this->module_limit;
     if ($this->module_offset < 0) {
         $this->module_offset = 0;
     }
     $this->page = $this->page === 0 ? 1 : $this->page;
     $this->offset = (int) ($this->page - 1) * $this->limit;
     if ($this->offset < 0) {
         $this->offset = 0;
     }
     # Required further below for Community Model init
     if (!isset($this->Menu)) {
         App::import('Model', 'menu', 'jreviews');
         $this->Menu = ClassRegistry::getClass('MenuModel');
     }
     if (!$this->ajaxRequest) {
         if (!($menu_id = Configure::read('_public_menu_id'))) {
             # Find and set one public Itemid to use for Ajax requests
             $menu_id = '';
             $menu_id = $this->Menu->get('jreviews_public');
             $menu_id = $menu_id != '' ? $menu_id : 99999;
             Configure::write('_public_menu_id', $menu_id);
         }
         if (!($search_itemid = Configure::read('_search_itemid'))) {
             // Set search menu Itemid used in several of the controllers
             $option = Sanitize::getString($this->params, 'option');
             $auto_itemid = Sanitize::getBool($this->Config, 'search_itemid', false);
             $hc_itemid = Sanitize::getInt($this->Config, 'search_itemid_hc', '');
             $search_menuid = $this->Menu->get('jr_advsearch');
             $search_itemid = '';
             switch ($option) {
                 case 'com_jreviews':
                     // page Itemid is enabled
                     if (!$auto_itemid && $hc_itemid > 0) {
                         $search_itemid = $hc_itemid;
                     } elseif (!$auto_itemid & $search_menuid > 0) {
                         $search_itemid = $search_menuid;
                     }
                     break;
                 default:
                     // Non-JReviews pages - can't use current page Itemid
                     if ($hc_itemid > 0) {
                         $search_itemid = $hc_itemid;
                     } else {
                         $search_itemid = $search_menuid;
                     }
                     break;
             }
             $search_itemid == '' and $option == 'com_jreviews' and $search_itemid = Sanitize::getString($this->params, 'Itemid');
             Configure::write('_search_itemid', $search_itemid);
         }
         $this->set(array('search_itemid' => $search_itemid, 'public_menu_id' => $menu_id));
     }
     if (!defined('MVC_GLOBAL_JS_VARS') && !$this->ajaxRequest && $this->action != '_save') {
         # Add global javascript variables
         $this->assets['head-top'][] = '<script type="text/javascript">
         /* <![CDATA[ */
         var s2AjaxUri = "' . getAjaxUri() . '",
             jrLanguage = new Array(),
             jrVars = new Array(),
             datePickerImage = "' . $this->viewImages . 'calendar.gif",
             jrPublicMenu = ' . $menu_id . ';
         jrLanguage["cancel"] = "' . __t("Cancel", true) . '";
         jrLanguage["submit"] = "' . __t("Submit", true) . '";
         jrLanguage["clearDate"] = "' . __t("Clear", true) . '";
         jrLanguage["field.select"] = "' . __t("-- Select --", true) . '";
         jrLanguage["field.select_field"] = "' . __t("-- Select %s --", true) . '";
         jrLanguage["field.no_results"] = "' . __t("No results found, try a different spelling.", true) . '";
         jrLanguage["field.ui_help"] = "' . __t("Start typing for suggestions", true) . '";
         jrLanguage["field.ui_add"] = "' . __t("Add", true) . '";
         jrLanguage["compare.heading"] = "' . __t("Compare", true) . '";
         jrLanguage["compare.compare_all"] = "' . __t("Compare All", true) . '";
         jrLanguage["compare.remove_all"] = "' . __t("Remove All", true) . '";
         jrLanguage["compare.select_more"] = "' . __t("You need to select more than one listing for comparison.", true) . '";
         jrLanguage["compare.select_max"] = "' . __t("You selected maximum number of listings for comparison.", true) . '";
         jrVars["locale"] = "' . cmsFramework::getLocale() . '";
         /* ]]> */
         </script>';
         if ($item_id = Sanitize::getInt($this->params, 'Itemid')) {
             $menu = $this->Menu->getMenuParams($item_id);
             $meta_desc = Sanitize::getString($menu, 'menu-meta_description');
             $meta_keys = Sanitize::getString($menu, 'menu-meta_keywords');
             $meta_desc != '' and cmsFramework::meta('description', $meta_desc);
             $meta_keys != '' and cmsFramework::meta('keywords', $meta_keys);
         }
         define('MVC_GLOBAL_JS_VARS', 1);
     }
     # Dynamic Community integration loading
     $community_extension = Configure::read('Community.extension');
     $community_extension = $community_extension != '' ? $community_extension : 'community_builder';
     App::import('Model', $community_extension, 'jreviews');
     $this->Community = new CommunityModel();
     # Init plugin system
     $this->_initPlugins();
 }
Пример #2
0
/**
 * Returns the request uri for ajax requests for each application
 *
 * @param string $app
 * @return ajax request uri
 */
function getAjaxUri($app = 'jreviews')
{
    $lang = cmsFramework::getUrlLanguageCode();
    $language = Sanitize::getString($_REQUEST, 'language');
    $core_sef = cmsFramework::getConfig('sef') && !function_exists('sefEncode') && !class_exists('shRouter');
    $ie = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false;
    $lang_segment = $ie && $core_sef && $language != '' && $lang != '';
    if (defined('MVC_FRAMEWORK_ADMIN')) {
        $ajaxUri = WWW_ROOT . 'administrator' . _DS . 'index.php?option=' . S2Paths::get($app, 'S2_CMSCOMP') . '&format=raw&tmpl=component';
    } else {
        $ajaxUri = WWW_ROOT . ($lang_segment ? $lang . _DS : '') . 'index.php?option=' . S2Paths::get($app, 'S2_CMSCOMP') . '&format=raw&tmpl=component' . ($lang != '' ? '&lang=' . $lang : '');
    }
    if (defined('MVC_FRAMEWORK_ADMIN')) {
        return str_replace('&amp;', '&', $ajaxUri);
    }
    return $ajaxUri;
}