function beforeFilter() { $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix'); # Set Theme $this->viewTheme = $this->Config->template; $this->viewImages = S2Paths::get($this->app, 'S2_THEMES_URL') . $this->viewTheme . _DS . 'theme_images' . _DS; }
function index() { $Session = RegisterClass::getInstance('MvcSession'); $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id')); if (!isset($this->params['module'])) { $this->params['module'] = array(); } // For direct calls to the controller if ($this->ajaxRequest) { $this->params = $Session->get('module_params' . $module_id, null, S2Paths::get('jreviews', 'S2_CMSCOMP')); } else { srand((double) microtime() * 1000000); $this->params['rand'] = rand(); $Session->set('module_rand' . $module_id, $this->params['rand'], S2Paths::get('jreviews', 'S2_CMSCOMP')); $Session->set('module_params' . $module_id, $this->params, S2Paths::get('jreviews', 'S2_CMSCOMP')); } $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix'); // Read the module parameters $img_width = Sanitize::getInt($this->params['module'], 'img_width', 50); $random_mode = Sanitize::getString($this->params['module'], 'random_mode', 'Random Users'); $favorites_mode = Sanitize::getString($this->params['module'], 'favorites_mode', 'Other users interested in {title}'); // Pagination $this->Community->limit = $this->module_limit; $this->Community->offset = $this->module_offset; # Get url params for current controller/action $url = Sanitize::getString($_REQUEST, 'url'); $route['url']['url'] = $url; $route['data'] = array(); $route = S2Router::parse($route, true, 'jreviews'); # Check if page is listing detail $detail = Sanitize::getString($route['url'], 'extension', 'com_content') == 'com_content' && isset($route['data']) && Sanitize::getString($route['data'], 'controller') == 'listings' && Sanitize::getString($route['data'], 'action') == 'detail' ? true : false; # Initialize variables $listing_id = $detail ? Sanitize::getInt($route, 'id') : Sanitize::getInt($this->params, 'id'); $option = Sanitize::getString($this->params, 'option'); $view = Sanitize::getString($this->params, 'view'); $task = Sanitize::getString($this->params, 'task'); $listing_title = ''; # Article auto-detect - only for com_content if ($detail || 'com_content' == $option && ('article' == $view || 'view' == $task)) { $query = "SELECT Listing.id, Listing.title FROM #__content AS Listing WHERE Listing.id = " . $listing_id; $this->_db->setQuery($query); $listing = current($this->_db->loadObjectList()); $listing_title = $listing->title; } else { $listing_id = null; } $profiles = $this->Community->getListingFavorites($listing_id, $this->_user->id, $this->params); $total = $this->Community->count; unset($this->Community->count); $this->set(array('profiles' => $profiles, 'listing_title' => $listing_title, 'total' => $total)); $page = $this->render('modules', 'favorite_cbusers'); if ($this->ajaxRequest) { return $this->ajaxResponse($page, false); } else { return $page; } }
function beforeFilter() { parent::beforeFilter(); $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix'); # Set Theme $this->viewTheme = $this->Config->template; $this->viewImages = S2Paths::get('jreviews', 'S2_THEMES_URL') . $this->viewTheme . _DS . 'theme_images' . _DS; # Set Theme Vars $search_itemid = Sanitize::getInt($this->params['module'], 'search_itemid'); if ($search_itemid) { $this->set('search_itemid', $search_itemid); } }
function startup(&$controller) { $this->c =& $controller; # Set Theme $controller->viewTheme = $controller->Config->template; $this->mobileDetect(); $controller->viewImages = S2Paths::get('jreviews', 'S2_THEMES_URL') . Sanitize::getString($controller->Config, 'fallback_theme') . _DS . 'theme_images' . _DS; # Dynamic theme setup if (isset($this->ignored_controllers[$controller->name]) && empty($this->ignored_controllers[$controller->name]) || isset($this->ignored_controllers[$controller->name]) && in_array($controller->action, $this->ignored_controllers[$controller->name])) { return; } $this->setSuffix(); }
/** * Initialize the Cache Engine * * Called automatically by the cache frontend * To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array()); * * @param array $setting array of setting for the engine * @return boolean True if the engine has been successfully initialized, false if not * @access public */ function init($settings = array()) { parent::init(array_merge(array('engine' => 'File', 'path' => S2Paths::get('jreviews', 'S2_CACHE'), 'prefix' => 's2_', 'lock' => false, 'serialize' => true, 'isWindows' => false), $settings)); if (!isset($this->__File)) { if (!class_exists('File')) { require LIBS . 'file.php'; } $this->__File = new File($this->settings['path'] . DS . 'cake'); } if (DIRECTORY_SEPARATOR === '\\') { $this->settings['isWindows'] = true; } $this->settings['path'] = $this->__File->Folder->cd($this->settings['path']); if (empty($this->settings['path'])) { return false; } return $this->__active(); }
function index() { // Required for ajax pagination to remember module settings $Session = RegisterClass::getInstance('MvcSession'); $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id')); if (!isset($this->params['module'])) { $this->params['module'] = array(); } // For direct calls to the controller if ($this->ajaxRequest) { $this->params = $Session->get('module_params' . $module_id, null, S2Paths::get('jreviews', 'S2_CMSCOMP')); } else { srand((double) microtime() * 1000000); $this->params['rand'] = rand(); $Session->set('module_rand' . $module_id, $this->params['rand'], S2Paths::get('jreviews', 'S2_CMSCOMP')); $Session->set('module_params' . $module_id, $this->params, S2Paths::get('jreviews', 'S2_CMSCOMP')); } # Prevent sql injection $token = Sanitize::getString($this->params, 'token'); $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false)); $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix'); $conditions = array(); $joins = array(); $order = array(); $having = array(); # Read module parameters $dir_id = Sanitize::getString($this->params['module'], 'dir'); $section_id = Sanitize::getString($this->params['module'], 'section'); $cat_id = Sanitize::getString($this->params['module'], 'category'); $listing_id = Sanitize::getString($this->params['module'], 'listing'); $criteria_id = Sanitize::getString($this->params['module'], 'criteria'); $limit = Sanitize::getString($this->params['module'], 'module_limit', 5); $extension = Sanitize::getString($this->params['module'], 'extension'); $extension = $extension != '' ? $extension : 'com_content'; if (isset($this->Listing)) { $this->Listing->_user = $this->_user; // This parameter determines the module mode $sort = Sanitize::getString($this->params['module'], 'listing_order'); $custom_order = Sanitize::getString($this->params['module'], 'custom_order'); $custom_where = Sanitize::getString($this->params['module'], 'custom_where'); if ($extension != 'com_content' && in_array($sort, array('topratededitor', 'featuredrandom', 'rhits'))) { echo "You have selected the {$sort} mode which is not supported for components other than com_content. Please read the tooltips in the module parameters for more info on allowed settings."; return; } # Category auto detect if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') { $ids = CommonController::_discoverIDs($this); extract($ids); } # Set conditionals based on configuration parameters if ($extension == 'com_content') { // Only works for core articles $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )', 'Listing.access <= ' . $this->_user->gid)); // Remove unnecessary fields from model query $this->Listing->modelUnbind(array('Listing.fulltext AS `Listing.description`', 'Listing.metakey AS `Listing.metakey`', 'Listing.metadesc AS `Listing.metadesc`', 'User.email AS `User.email`')); $cat_id != '' and $conditions[] = 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')'; $cat_id == '' and $section_id != '' and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')'; $cat_id == '' and $dir_id != '' and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')'; $cat_id == '' and $criteria_id != '' and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')'; } else { if (Sanitize::getInt($this->params['module'], 'cat_auto') && method_exists($this->Listing, 'catUrlParam')) { if ($cat_id = Sanitize::getInt($this->passedArgs, $this->Listing->catUrlParam())) { $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')'; } } elseif ($cat_id) { $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')'; } } $listing_id and $conditions[] = "Listing.{$this->Listing->realKey} IN (" . cleanIntegerCommaList($listing_id) . ")"; switch ($sort) { case 'random': $order[] = 'RAND(' . $this->params['rand'] . ')'; break; case 'featuredrandom': $conditions[] = 'featured > 0'; $order[] = 'RAND(' . $this->params['rand'] . ')'; break; case 'topratededitor': $conditions[] = 'Totals.editor_rating > 0'; break; // Editor rating sorting options dealt with in the Listing->processSorting method } # Custom WHERE $tokenMatch and $custom_where and $conditions[] = $custom_where; # Filtering options $having = array(); // Listings submitted in the past x days $entry_period = Sanitize::getInt($this->params['module'], 'filter_listing_period'); if ($entry_period > 0 && $this->Listing->dateKey) { $conditions[] = "Listing.{$this->Listing->dateKey} >= DATE_SUB('" . _CURRENT_SERVER_TIME . "', INTERVAL {$entry_period} DAY)"; } // Listings with reviews submitted in past x days $review_period = Sanitize::getInt($this->params['module'], 'filter_review_period'); if ($review_period > 0) { $conditions[] = "Review.created >= DATE_SUB(CURDATE(), INTERVAL {$review_period} DAY)"; $joins[] = 'LEFT JOIN #__jreviews_comments AS Review ON Listing.' . $this->Listing->realKey . ' = Review.pid'; } // Listings with review count higher than $filter_review_count = Sanitize::getInt($this->params['module'], 'filter_review_count'); $filter_review_count > 0 and $conditions[] = "Totals.user_rating_count >= " . $filter_review_count; // Listings with avg rating higher than $filter_avg_rating = Sanitize::getFloat($this->params['module'], 'filter_avg_rating'); $filter_avg_rating > 0 and $conditions[] = 'Totals.user_rating >= ' . $filter_avg_rating; $this->Listing->group = array(); // Exlude listings without ratings from the results $join_direction = in_array($sort, array('rating', 'rrating', 'topratededitor', 'reviews')) ? 'INNER' : 'LEFT'; $this->Listing->joins['Total'] = "{$join_direction} JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.{$this->Listing->realKey} AND Totals.extension = " . $this->quote($extension); # Modify query for correct ordering. Change FIELDS, ORDER BY and HAVING BY directly in Listing Model variables if ($tokenMatch and $custom_order) { $this->Listing->order[] = $custom_order; } elseif (empty($order) && $extension == 'com_content') { $this->Listing->processSorting($sort, ''); } elseif (empty($order) && ($order = $this->_processSorting($sort))) { $order = array($order); } $queryData = array('fields' => array('Totals.user_rating AS `Review.user_rating`', 'Totals.user_rating_count AS `Review.user_rating_count`', 'Totals.user_comment_count AS `Review.review_count`', 'Totals.editor_rating AS `Review.editor_rating`', 'Totals.editor_rating_count AS `Review.editor_rating_count`', 'Totals.editor_comment_count AS `Review.editor_review_count`'), 'joins' => $joins, 'conditions' => $conditions, 'limit' => $this->module_limit, 'offset' => $this->module_offset, 'having' => $having); isset($order) and !empty($order) and $queryData['order'] = $order; // Trigger addFields for $listing results. Checked in Everywhere model $this->Listing->addFields = true; $listings = $this->Listing->findAll($queryData); if (Sanitize::getInt($this->params['module'], 'ajax_nav', 1)) { unset($queryData['joins']['Section'], $queryData['joins']['Category'], $queryData['joins']['Directory'], $queryData['joins']['Criteria'], $queryData['joins']['User'], $queryData['order']); $count = $this->Listing->findCount($queryData, 'DISTINCT Listing.' . $this->Listing->realKey); } else { $count = $this->module_limit; } } else { $listings = array(); $count = 0; } unset($this->Listing); # Send variables to view template $this->set(array('Access' => $this->Access, 'User' => $this->_user, 'subclass' => 'listing', 'listings' => $listings, 'total' => $count)); $page = $this->render('modules', 'listings'); if ($this->ajaxRequest) { return $this->ajaxResponse($page, false); } else { return $page; } }
function click2searchLink() { if (!isset($this->params->click2searchlink) || $this->params->click2searchlink == '') { echo 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP') . '&Itemid={ITEMID}&url=tag/{FIELDNAME}/{FIELDTEXT}/criteria' . _PARAM_CHAR . '{CRITERIAID}/'; } else { echo $this->params->click2searchlink; } }
function cacheView($controller, $action, $path, $page) { if (Configure::read('Cache.enable') && Configure::read('Cache.view')) { if (file_exists(S2Paths::get($this->app, 'S2_THEMES') . $this->viewTheme . DS . $controller . DS . $action . $this->viewSuffix . '.thtml')) { $viewFileName = S2Paths::get($this->app, 'S2_THEMES') . $this->viewTheme . DS . $controller . DS . $action . $this->viewSuffix . '.thtml'; } elseif (file_exists(S2Paths::get($this->app, 'S2_THEMES') . $this->viewTheme . DS . $controller . DS . $action . '.thtml')) { $viewFileName = S2Paths::get($this->app, 'S2_THEMES') . $this->viewTheme . DS . $controller . DS . $action . '.thtml'; } elseif (file_exists(S2Paths::get($this->app, 'S2_THEMES') . 'default' . DS . $controller . DS . $action . $this->viewSuffix . '.thtml')) { $viewFileName = S2Paths::get($this->app, 'S2_THEMES') . $this->viewTheme . DS . $controller . DS . $action . '.thtml'; } elseif (file_exists(S2Paths::get($this->app, 'S2_THEMES') . 'default' . DS . $controller . DS . $action . '.thtml')) { $viewFileName = S2Paths::get($this->app, 'S2_THEMES') . 'default' . DS . $controller . DS . $action . '.thtml'; } App::import('Helper', 'Cache'); $Cache = new CacheHelper(); $Cache->app = $this->app; $Cache->here = $path; $Cache->cacheAction = Configure::read('Cache.expires'); $Cache->cache($viewFileName, $page, true, $this->autoRender); } }
S2Paths::set($s2_app, 'S2_APP_OVERRIDES', PATH_ROOT . 'templates' . DS . 'jreviews_overrides' . DS); S2Paths::set($s2_app, 'S2_APP_URL_OVERRIDES', WWW_ROOT . 'templates' . _DS . 'jreviews_overrides' . _DS); S2Paths::set($s2_app, 'S2_VIEWS_OVERRIDES', S2Paths::get($s2_app, 'S2_APP_OVERRIDES') . 'views' . DS); S2Paths::set($s2_app, 'S2_HELPERS_OVERRIDES', S2Paths::get($s2_app, 'S2_VIEWS_OVERRIDES') . 'helpers' . DS); S2Paths::set($s2_app, 'S2_THEMES_OVERRIDES', S2Paths::get($s2_app, 'S2_VIEWS_OVERRIDES') . 'themes' . DS); S2Paths::set($s2_app, 'S2_JS_OVERRIDES', S2Paths::get($s2_app, 'S2_VIEWS_OVERRIDES') . 'js' . DS); S2Paths::set($s2_app, 'S2_VIEWS_URL_OVERRIDES', S2Paths::get($s2_app, 'S2_APP_URL_OVERRIDES') . 'views' . _DS); S2Paths::set($s2_app, 'S2_THEMES_URL_OVERRIDES', S2Paths::get($s2_app, 'S2_VIEWS_URL_OVERRIDES') . 'themes' . _DS); S2Paths::set($s2_app, 'S2_IMAGES_URL_OVERRIDES', S2Paths::get($s2_app, 'S2_VIEWS_URL_OVERRIDES') . 'images' . _DS); S2Paths::set($s2_app, 'S2_CSS_URL_OVERRIDES', S2Paths::get($s2_app, 'S2_VIEWS_URL_OVERRIDES') . 'css' . _DS); S2Paths::set($s2_app, 'S2_JS_URL_OVERRIDES', S2Paths::get($s2_app, 'S2_VIEWS_URL_OVERRIDES') . 'js' . _DS); S2Paths::set($s2_app, 'S2_ADMIN_VIEWS_OVERRIDES', S2Paths::get($s2_app, 'S2_APP_OVERRIDES') . 'views' . DS . 'admin' . DS); S2Paths::set($s2_app, 'S2_ADMIN_HELPERS_OVERRIDES', S2Paths::get($s2_app, 'S2_ADMIN_VIEWS_OVERRIDES') . 'helpers' . DS); S2Paths::set($s2_app, 'S2_ADMIN_VIEWS_URL_OVERRIDES', S2Paths::get($s2_app, 'S2_VIEWS_URL_OVERRIDES') . 'admin' . _DS); S2Paths::set($s2_app, 'S2_CSS_ADMIN_URL_OVERRIDES', S2Paths::get($s2_app, 'S2_ADMIN_VIEWS_URL_OVERRIDES') . 'css' . _DS); S2Paths::set($s2_app, 'S2_JS_ADMIN_URL_OVERRIDES', S2Paths::get($s2_app, 'S2_ADMIN_VIEWS_URL_OVERRIDES') . 'js' . _DS); // Create the file registry $Configure =& Configure::getInstance($s2_app); $s2App =& App::getInstance($s2_app); require_once dirname(__FILE__) . DS . 'config' . DS . 'core.php'; # Set app variable in I18n class $import = App::import('Lib', 'I18n'); if (!$import) { $clear = clearCache('', 'core'); if (!$clear) { echo 'You need to delete the file registry in /components/com_s2framework/tmp/cache/core/'; exit; } $page = $_SERVER['PHP_SELF']; header("Location: index.php?option=com_jreviews"); exit;
$route = S2Router::parse($route, false, 'jreviews'); /******************************************************************* * ADMIN ROUTING ******************************************************************/ if (defined('MVC_FRAMEWORK_ADMIN')) { // Ensure user has access to this function switch (getCmsVersion()) { case 'CMS_JOOMLA15': $User =& cmsFramework::getUser(); $Acl =& cmsFramework::getACL(); if ($Acl->acl_check('administration', 'manage', 'users', $User->usertype, 'components', S2Paths::get('jreviews', 'S2_CMSCOMP'))) { cmsFramework::redirect('index.php', JText::_('ALERTNOTAUTH')); } break; case 'CMS_JOOMLA16': if (!JFactory::getUser()->authorise('core.manage', S2Paths::get('jreviews', 'S2_CMSCOMP'))) { return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); } break; default: die('Not authorized'); break; } // Controller routing $act = Sanitize::getString($_REQUEST, 'act'); if ($act == 'license') { $_GET['url'] = 'license'; } else { $_GET['url'] = Sanitize::getString($_GET, 'url', 'about'); } /*******************************************************************
/** * Returns the request uri for ajax requests for each application * * @param string $app * @return ajax request uri */ function getAjaxUri($app = 'jreviews') { 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 . 'index.php?option=' . S2Paths::get($app, 'S2_CMSCOMP') . '&format=raw&tmpl=component'; } // Required for Joomfish compat in ajax requests if ($lang = Sanitize::getString($_REQUEST, 'lang')) { $ajaxUri .= '&lang=' . $lang; } if (defined('MVC_FRAMEWORK_ADMIN')) { return str_replace('&', '&', $ajaxUri); } return $ajaxUri; }
/** * Binds the given domain to a file in the specified directory. * * @param string $domain Domain to bind * @return string Domain binded * @access private */ function __bindTextDomain($domain) { $this->__noLocale = true; $core = true; $merge = array(); $searchPaths[] = S2Paths::get($this->app, 'S2_APP_OVERRIDES') . 'locale'; $searchPaths[] = S2Paths::get($this->app, 'S2_APP') . 'locale'; // $plugins = Configure::listObjects('plugin'); if (!empty($plugins)) { $pluginPaths = Configure::read('pluginPaths'); foreach ($plugins as $plugin) { $plugin = Inflector::underscore($plugin); if ($plugin === $domain) { foreach ($pluginPaths as $pluginPath) { $searchPaths[] = $pluginPath . DS . $plugin . DS . 'locale'; } $searchPaths = array_reverse($searchPaths); break; } } } foreach ($searchPaths as $directory) { foreach ($this->l10n->languagePath as $lang) { $file = $directory . DS . $lang . DS . $this->category . DS . $domain; if ($core) { $app = $directory . DS . $lang . DS . $this->category . DS . 'core'; if (file_exists($fn = "{$app}.mo")) { $this->__loadMo($fn, $domain); $this->__noLocale = false; $merge[$this->category][$this->__lang][$domain] = $this->__domains[$this->category][$this->__lang][$domain]; $core = null; } elseif (file_exists($fn = "{$app}.po") && ($f = fopen($fn, "r"))) { $this->__loadPo($f, $domain); $this->__noLocale = false; $merge[$this->category][$this->__lang][$domain] = $this->__domains[$this->category][$this->__lang][$domain]; $core = null; } } if (file_exists($fn = "{$file}.mo")) { $this->__loadMo($fn, $domain); $this->__noLocale = false; break 2; } elseif (file_exists($fn = "{$file}.po") && ($f = fopen($fn, "r"))) { $this->__loadPo($f, $domain); $this->__noLocale = false; break 2; } } } if (empty($this->__domains[$this->category][$this->__lang][$domain])) { $this->__domains[$this->category][$this->__lang][$domain] = array(); return $domain; } if ($head = $this->__domains[$this->category][$this->__lang][$domain][""]) { foreach (explode("\n", $head) as $line) { $header = strtok($line, ":"); $line = trim(strtok("\n")); $this->__domains[$this->category][$this->__lang][$domain]["%po-header"][strtolower($header)] = $line; } if (isset($this->__domains[$this->category][$this->__lang][$domain]["%po-header"]["plural-forms"])) { $switch = preg_replace("/(?:[() {}\\[\\]^\\s*\\]]+)/", "", $this->__domains[$this->category][$this->__lang][$domain]["%po-header"]["plural-forms"]); $this->__domains[$this->category][$this->__lang][$domain]["%plural-c"] = $switch; unset($this->__domains[$this->category][$this->__lang][$domain]["%po-header"]); } $this->__domains = Set::pushDiff($this->__domains, $merge); if (isset($this->__domains[$this->category][$this->__lang][$domain][null])) { unset($this->__domains[$this->category][$this->__lang][$domain][null]); } } return $domain; }
function getRank($userid, $rank, $limit, $Itemid) { $pag_start = ''; $start = floor($rank / $limit) * $limit; switch ($rank) { case $rank == 1: $user_rank = _JR_RANK_TOP1; break; case $rank <= 10 && $rank > 0: $user_rank = _JR_RANK_TOP10; break; case $rank <= 50 && $rank > 10: $user_rank = _JR_RANK_TOP50; break; case $rank <= 100 && $rank > 50: $user_rank = _JR_RANK_TOP100; break; case $rank <= 500 && $rank > 100: $user_rank = _JR_RANK_TOP500; break; case $rank <= 1000 && $rank > 500: $user_rank = _JR_RANK_TOP1000; break; default: $user_rank = ''; } if ($start > 1) { $pag_start = "&limit={$limit}&limitstart={$start}"; } if ($user_rank != '') { $url = $this->link($user_rank, 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP') . '&task=reviewrank&user='******'#$userid'); return $url; } }
function index() { $this->EverywhereAfterFind = true; // Triggers the afterFind in the Observer Model // Required for ajax pagination to remember module settings $Session = RegisterClass::getInstance('MvcSession'); $module_id = Sanitize::getVar($this->params, 'module_id', Sanitize::getVar($this->data, 'module_id')); $cache_file = $module_id . '_' . md5(serialize($this->params)); if ($this->ajaxRequest) { $this->params = $Session->get($module_id, null, S2Paths::get('jreviews', 'S2_CMSCOMP')); } else { srand((double) microtime() * 1000000); $this->params['rand'] = rand(); // $Session->set($module_id.'_rand',$this->params['rand'],S2Paths::get('jreviews','S2_CMSCOMP')); $Session->set($module_id, $this->params, S2Paths::get('jreviews', 'S2_CMSCOMP')); } if (!Sanitize::getVar($this->params['module'], 'community')) { cmsFramework::noAccess(); return; } $conditions = array(); $joins = array(); $order = array(); // Initialize variables $id = Sanitize::getInt($this->params, 'id'); $option = Sanitize::getString($this->params, 'option'); $view = Sanitize::getString($this->params, 'view'); $task = Sanitize::getString($this->params, 'task'); $menu_id = Sanitize::getString($this->params, 'Itemid'); # Read module parameters $extension = Sanitize::getString($this->params['module'], 'extension'); $user_id = Sanitize::getInt($this->params, 'user', $this->_user->id); if (!$user_id && !$this->_user->id) { cmsFramework::noAccess(); return; } # Cached version /* if($this->_user->id ===0) { $page = $this->cached($cache_file); if($page && $this->xajaxRequest) { $xajax->assign('jr_modContainer'.$module_id,'innerHTML',$page); return $xajax; } elseif ($page) { return $page; } } */ $catids_url = Sanitize::getString($this->params['module'], 'category'); $listing_id = Sanitize::getString($this->params['module'], 'listing'); if ($extension == 'com_content') { $dir_id = Sanitize::getString($this->params['module'], 'dir'); $section_id = Sanitize::getString($this->params['module'], 'section'); $criteria_ids = Sanitize::getString($this->params['module'], 'criteria'); } else { $dir_id = null; $section_id = null; $criteria_ids = null; } $cat_autodetect = Sanitize::getInt($this->params['module'], 'cat_auto'); // This parameter determines the module mode $sort = Sanitize::getString($this->params['module'], 'reviews_order'); # Remove unnecessary fields from model query // $this->Review->modelUnbind(); if ($extension != '') { $conditions[] = "Review.mode = '{$extension}'"; } $conditions[] = "Review.userid = " . (int) $user_id; # Set conditionals based on configuration parameters if ($extension == 'com_content') { // Only works for core articles $conditions = array_merge($conditions, array('( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )', 'Listing.access <= ' . $this->_user->gid, 'Listing.catid > 0')); $conditions[] = $this->Access->canEditListing() ? 'Listing.state >= 0' : 'Listing.state = 1'; if ($dir_id) { $conditions[] = 'JreviewsCategory.dirid IN (' . $dir_id . ')'; } if ($section_id) { $conditions[] = 'Listing.sectionid IN (' . $section_id . ')'; } if ($catids_url) { $conditions[] = 'Listing.catid IN (' . $catids_url . ')'; } } else { if (Sanitize::getInt($this->params['module'], 'cat_auto') && method_exists($this->Listing, 'catUrlParam')) { if ($catids_url = Sanitize::getInt($this->passedArgs, $this->Listing->catUrlParam())) { $conditions[] = 'JreviewsCategory.id IN (' . $catids_url . ')'; } } elseif ($catids_url) { $conditions[] = 'JreviewsCategory.id IN (' . $catids_url . ')'; } } if ($listing_id) { $conditions[] = "Review.pid IN ({$listing_id})"; } $conditions[] = 'Review.published > 0'; switch ($sort) { case 'latest': $order[] = $this->Review->processSorting('rdate'); break; case 'helpful': $order[] = $this->Review->processSorting('helpful'); break; case 'random': $order[] = 'RAND(' . $this->params['rand'] . ')'; break; default: $order[] = $this->Review->processSorting('rdate'); break; } $queryData = array('fields' => array(), 'joins' => $joins, 'conditions' => $conditions, 'order' => $order, 'limit' => $this->module_limit, 'offset' => $this->module_offset); # Don't run it here because it's run in the Everywhere Observer Component $this->Review->runProcessRatings = false; // Excludes listing owner info in Everywhere component $this->Review->controller = 'module_reviews'; $reviews = $this->Review->findAll($queryData); if (Sanitize::getInt($this->params['module'], 'ajax_nav', 1)) { unset($queryData['order']); $count = $this->Review->findCount($queryData, 'DISTINCT Review.id'); } else { $count = $this->module_limit; } # Send variables to view template $this->set(array('Access' => $this->Access, 'User' => $this->_user, 'reviews' => $reviews, 'total' => $count, 'module_id' => $module_id)); $page = $this->render('community_plugins', 'community_myreviews'); # Save cached version /* if($this->_user->id ===0) { $this->cacheView('modules','reviews',$cache_file, $page); } */ if ($this->ajaxRequest) { return $this->ajaxResponse($page, false); } else { return $page; } }
function __construct() { parent::__construct(); # Check for cached version $cache_file = 'jreviews_menu_' . cmsFramework::locale() . '_' . md5(cmsFramework::getConfig('secret')); if ($cache = S2Cache::read($cache_file)) { $this->___menu_data = $cache['___menu_data']; return; } $menuList = array(); switch ($this->cmsVersion) { case CMS_JOOMLA15: $select = "\n SELECT \n id,\n name,\n link AS menu_type,\n link,\n componentid,\n params,\n access,\n published\n "; break; case CMS_JOOMLA16: $select = "\n SELECT \n id, \n title AS name,\n link AS menu_type,\n link,\n component_id AS componentid,\n params,\n access,\n published\n "; break; } // Get all com_content category/section menus and JReviews menus $sql = $select . "\n FROM #__menu\n WHERE published = 1\n ORDER BY link DESC\n "; $this->_db->setQuery($sql); $menuList = $this->_db->loadObjectList(); // Get itemid for each menu link and store it if (!empty($menuList)) { foreach ($menuList as $menu) { $params = stringToArray($menu->params); $m_name = Sanitize::getVar($params, 'sef_name') != '' ? Sanitize::getVar($params, 'sef_name') : $menu->name; function_exists("sefEncode") and $m_name = sefEncode($m_name); $m_action = Sanitize::getVar($params, 'action'); $m_dir_id = str_replace(",", "-", Sanitize::getVar($params, 'dirid')); $m_cat_id = str_replace(",", "-", Sanitize::getVar($params, 'catid')); $m_section_id = str_replace(",", "-", Sanitize::getVar($params, 'sectionid')); $m_criteria_id = str_replace(",", "-", Sanitize::getVar($params, 'criteriaid')); // Create a variable to get Menu Name from Itemid $this->set('jr_itemid_' . $menu->id, $m_name); $this->set('jr_menu_' . $m_name, $menu->id); if (strpos($menu->menu_type, 'option=com_content&view=section&id=') || strpos($menu->menu_type, 'option=com_content&view=section&layout=blog&id=')) { $menu->componentid = end(explode('id=', $menu->menu_type)); $menu->menu_type = 'content_section'; } elseif (strpos($menu->menu_type, 'option=com_content&view=category&id=') || strpos($menu->menu_type, 'option=com_content&view=category&layout=blog&id=')) { $menu->componentid = end(explode('id=', $menu->menu_type)); $menu->menu_type = 'content_category'; } elseif (strpos($menu->menu_type, 'option=com_content&view=article&id=') || strpos($menu->menu_type, 'option=com_content&task=view&id=')) { $menu->componentid = end(explode('id=', $menu->menu_type)); $menu->menu_type = 'content_item_link'; } switch ($menu->menu_type) { case 'content_section': case 'content_blog_section': if ($menu->componentid) { // Only one section id $this->set('core_section_menu_id_' . $menu->componentid, $menu->id); } else { $section_ids = explode(",", Sanitize::getVar($params, 'sectionid')); $this->set('jr_manyIds_' . $menu->id, 1); foreach ($section_ids as $section_id) { $this->set('core_section_menu_id_' . $section_id, $menu->id); } } break; case 'content_category': case 'content_blog_category': if ($menu->componentid) { // Only one category id $this->set('core_category_menu_id_' . $menu->componentid, $menu->id); } else { $cat_ids = explode(",", Sanitize::getVar($params, 'categoryid')); $this->set('jr_manyIds_' . $menu->id, 1); foreach ($cat_ids as $cat_id) { $this->set('core_category_menu_id_' . $cat_id, $menu->id); } } break; case 'content_item_link': $this->set('core_content_menu_id_' . $menu->componentid, $menu->id); break; default: if ($menu->componentid > 0 && strstr($menu->link, 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP'))) { // It's a JReviews menu $access = $this->cmsVersion == CMS_JOOMLA15 ? 0 : 1; // Get a JReviews menu with public access to use in ajax requests if ($menu->access == $access && $menu->published == 1) { $this->set('jreviews_public', $menu->id); } $this->set('jr_menu_action_' . $m_dir_id, $m_action); $this->set('menu_params_' . $menu->id, $params); switch ($m_action) { case '0': // Directory menu $this->set('jr_directory_menu_id_' . $m_dir_id, $menu->id); break; case '1': // Section menu $this->set('jr_section_menu_id_' . $m_section_id, $menu->id); break; case '2': // Category menu $this->set('jr_category_menu_id_' . $m_cat_id, $menu->id); break; case '10': $this->set('jr_myreviews', $menu->id); break; case '11': $m_criteria_id && $this->set('jr_advsearch_' . $m_criteria_id, $menu->id); !$m_criteria_id && $this->set('jr_advsearch', $menu->id); break; case '12': $this->set('jr_mylistings', $menu->id); break; case '18': $this->set('jr_reviewers', $menu->id); break; default: $this->set('jr_menu_id_action_' . $m_action, $menu->id); break; } } break; } } S2Cache::write($cache_file, array('___menu_data' => $this->___menu_data)); } // prx($this->___menu_data);exit; }
/** * Model observer adds listing information for reviews submitted from different extensions * Used in my reviews page */ function plgAfterFind(&$model, $results) { if (empty($results)) { return $results; } switch ($this->everywhereModel->name) { case 'Review': if (isset($this->c->EverywhereAfterFind) && $this->c->EverywhereAfterFind === true) { $this->c->action != '_save' and Configure::write('EverywhereReviewModel', true); $extensions = array(); $models = array(); # Build extension and listing_id array foreach ($results as $result) { $extensions[$result['Review']['extension']][] = $result['Review']['listing_id']; $models[$result['Review']['extension']] = $this->name . '_' . $result['Review']['extension']; } foreach ($extensions as $key => $value) { $extensions[$key] = array_unique($value); } # Verify model files exist or unset them foreach ($models as $extension => $EveryWhereModel) { if (!file_exists(S2Paths::get('jreviews', 'S2_MODELS') . $this->name . DS . $EveryWhereModel . '.php')) { unset($models[$extension]); } } $this->__initModels(array_values($models), $this->app); # Loop through extensions found in the current page foreach ($extensions as $extension => $listing_ids) { if (isset($models[$extension])) { if (!is_array($listing_ids)) { $listing_ids = array($listing_ids); } // Uses the current extension's model to get Listing info for the given listing ids $realKey = $this->{inflector::camelize($models[$extension])}->realKey; $listings[$extension] = $this->{inflector::camelize($models[$extension])}->findAll(array('conditions' => 'Listing.' . $realKey . ' IN (' . implode(',', $listing_ids) . ')')); } } # Merge the listing data to the Review Model results foreach ($results as $key => $result) { if (isset($listings[$result['Review']['extension']]) && isset($listings[$result['Review']['extension']][$result['Review']['listing_id']])) { // Second condition above excludes reviews when the listing is not found for the review (i.e. the category for the listing was removed) if (defined('MVC_FRAMEWORK_ADMIN') || $this->c->name == 'reviews' && in_array($this->c->action, array('myreviews', '_save', '_edit', 'latest', 'latest_editor', 'latest_user')) || $this->c->name == 'reviews' && $this->c->action == 'moderation' || $this->c->name == 'module_reviews' && $this->c->action == 'index' || $this->c->name == 'community_reviews' && $this->c->action == 'index' || $this->c->name == 'feeds' || $this->c->name == 'discussions' && $this->c->action == 'review') { // Exclude listing owner info because it replaces the reviewer info if (isset($listings[$result['Review']['extension']][$result['Review']['listing_id']]['User'])) { if (isset($listings[$result['Review']['extension']][$result['Review']['listing_id']]['User'])) { $listings[$result['Review']['extension']][$result['Review']['listing_id']]['ListingUser'] = $listings[$result['Review']['extension']][$result['Review']['listing_id']]['User']; unset($listings[$result['Review']['extension']][$result['Review']['listing_id']]['User']); } if (isset($listings[$result['Review']['extension']][$result['Review']['listing_id']]['Community'])) { $listings[$result['Review']['extension']][$result['Review']['listing_id']]['ListingCommunity'] = $listings[$result['Review']['extension']][$result['Review']['listing_id']]['Community']; unset($listings[$result['Review']['extension']][$result['Review']['listing_id']]['Community']); } } unset($listings[$result['Review']['extension']][$result['Review']['listing_id']]['Rating']); } # Merge listing and review arrays. When there are duplicates Review keys trump Listing keys (i.e. Review, Rating, Field, ...) $results[$key] = array_insert($listings[$result['Review']['extension']][$result['Review']['listing_id']], $results[$key]); } else { unset($results[$key]); // Removes reviews for extensions without Models } } # Preprocess criteria and rating information $rating_test = current($results); if (isset($rating_test['Rating'])) { $results = $this->c->Review->processRatings($results); } return $results; } break; case 'ReviewReport': $extensions = array(); $models = array(); # Build extension and listing_id array foreach ($results as $result) { $extensions[$result['Review']['extension']][] = $result['Review']['listing_id']; $models[$result['Review']['extension']] = $this->name . '_' . $result['Review']['extension']; } foreach ($extensions as $key => $value) { $extensions[$key] = array_unique($value); } # Verify model files exist or unset them foreach ($models as $extension => $EveryWhereModel) { if (!file_exists(S2Paths::get('jreviews', 'S2_MODELS') . $this->name . DS . $EveryWhereModel . '.php')) { unset($models[$extension]); } } $this->__initModels(array_values($models), $this->app); # Loop through extensions found in the current page foreach ($extensions as $extension => $listing_ids) { if (isset($models[$extension])) { if (!is_array($listing_ids)) { $listing_ids = array($listing_ids); } // Uses the current extension's model to get Listing info for the given listing ids $realKey = $this->{inflector::camelize($models[$extension])}->realKey; $listings[$extension] = $this->{inflector::camelize($models[$extension])}->findAll(array('conditions' => 'Listing.' . $realKey . ' IN (' . implode(',', $listing_ids) . ')')); } } # Merge the listing data to the Review Model results foreach ($results as $key => $result) { if (isset($listings[$result['Review']['extension']])) { $results[$key] = array_insert($results[$key], $listings[$result['Review']['extension']][$result['Review']['listing_id']]); } else { unset($results[$key]); // Removes reviews for extensions without Models } } # Preprocess criteria and rating information $rating_test = current($results); if (isset($rating_test['Rating'])) { $results = $this->c->Review->processRatings($results); } return $results; break; } return $results; }
function index() { $response = array(); if (Sanitize::getString($this->params, 'task') == 'upgrade') { // Where running the install script for upgrade we want a json object returned $this->autoLayout = false; $this->autoRender = false; } else { $this->autoLayout = true; $this->autoRender = true; } $this->name = 'install'; # Create database tables // Start db upgrade logic $action = array(); $action['db_install'] = true; $tables = $this->_db->getTableList(); $dbprefix = cmsFramework::getConfig('dbprefix'); $old_build = 0; if (is_array($tables) && in_array($dbprefix . 'jreviews_categories', array_values($tables))) { // Tables exist so we check the current build and upgrade accordingly, otherwise it's a clean install and no upgrade is necessary $query = "SELECT value FROM #__jreviews_config WHERE id = 'version'"; $this->_db->setQuery($query); $old_version = trim(strip_tags($this->_db->loadResult())); if ($old_version != '') { $version_parts = explode('.', $old_version); $old_build = array_pop($version_parts); } // Get current version number $xml = file(S2_CMS_ADMIN . 'jreviews.xml'); foreach ($xml as $xml_line) { if (strstr($xml_line, 'version')) { $new_version = trim(strip_tags($xml_line)); continue; } } $version_parts = explode('.', $new_version); $new_build = array_pop($version_parts); if (Sanitize::getBool($this->params, 'sql')) { $old_build = 0; } // prx($old_build . '<br/>' . $new_build) ; if ($new_build > $old_build) { $i = $old_build + 1; for ($i = $old_build + 1; $i <= $new_build; $i++) { // Run sql updates $sql_file = S2Paths::get('jreviews', 'S2_APP') . 'upgrades' . DS . 'upgrade_build' . $i . '.sql'; if (file_exists($sql_file)) { $action['db_install'] = $this->__parseMysqlDump($sql_file, $dbprefix) && $action['db_install']; } // Run php updates $php_file = S2Paths::get('jreviews', 'S2_APP') . 'upgrades' . DS . 'upgrade_build' . $i . '.php'; if (file_exists($php_file)) { include $php_file; } } } } else { // It's a clean install so we use the whole jReviews sql file $sql_file = S2Paths::get('jreviews', 'S2_APP') . 'upgrades' . DS . 'jreviews.sql'; $action['db_install'] = $this->__parseMysqlDump($sql_file, $dbprefix); } # Update component id in pre-existing jReviews menus if (getCmsVersion() == CMS_JOOMLA16) { $query = "\n SELECT \n extension_id AS id\n FROM \n #__extensions \n WHERE \n element = '" . S2Paths::get('jreviews', 'S2_CMSCOMP') . "' AND type = 'component'\n "; } else { $query = "\n SELECT \n id \n FROM \n #__components \n WHERE \n admin_menu_link = 'option=" . S2Paths::get('jreviews', 'S2_CMSCOMP') . "'\n "; } $this->_db->setQuery($query); if ($id = $this->_db->loadResult()) { if (getCmsVersion() == CMS_JOOMLA16) { $query = "\n UPDATE \n `#__menu` \n SET \n component_id = {$id} \n WHERE \n type IN ('component','components') \n AND \n link = 'index.php?option=" . S2Paths::get('jreviews', 'S2_CMSCOMP') . "'\n "; } else { $query = "\n UPDATE \n `#__menu` \n SET \n componentid = {$id} \n WHERE \n type IN ('component','components') \n AND \n link = 'index.php?option=" . S2Paths::get('jreviews', 'S2_CMSCOMP') . "'\n "; } $this->_db->setQuery($query); $this->_db->query(); } $result = false; // Install jReviews plugin $package = PATH_ROOT . 'administrator' . DS . 'components' . DS . 'com_jreviews' . DS . 'jreviews.plugin.s2'; if (getCmsVersion() == CMS_JOOMLA16) { @mkdir(PATH_ROOT . _PLUGIN_DIR_NAME . DS . 'content' . DS . 'jreviews'); $target = PATH_ROOT . _PLUGIN_DIR_NAME . DS . 'content' . DS . 'jreviews'; } else { $target = PATH_ROOT . _PLUGIN_DIR_NAME . DS . 'content'; } $target_file = $target . DS . 'jreviews.php'; $first_pass = false; jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.archive'); jimport('joomla.filesystem.path'); $adapter =& JArchive::getAdapter('zip'); $result = $adapter->extract($package, $target); if ($result) { $this->Config->version = $new_version; $this->Config->store(); } if (getCmsVersion() == CMS_JOOMLA15 && !file_exists($target_file)) { require_once PATH_ROOT . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclzip.lib.php'; require_once PATH_ROOT . 'administrator' . DS . 'includes' . DS . 'pcl' . DS . 'pclerror.lib.php'; $extract = new PclZip($package); if (substr(PHP_OS, 0, 3) == 'WIN') { if (!defined('OS_WINDOWS')) { define('OS_WINDOWS', 1); } } else { if (!defined('OS_WINDOWS')) { define('OS_WINDOWS', 0); } } $result = $extract->extract(PCLZIP_OPT_PATH, $target); } if (!file_exists($target_file)) { $action['plugin_install'] = false; } else { $action['plugin_install'] = true; if (getCmsVersion() == CMS_JOOMLA16) { // Add/create plugin db entry $query = "\n SELECT \n extension_id AS ud \n FROM \n #__extensions \n WHERE \n type = 'plugin' AND element = 'jreviews' AND folder = 'content'\n "; $this->_db->setQuery($query); $result = $this->_db->loadResult(); if (!$result || empty($result)) { $query = "\n INSERT INTO \n #__extensions \n (`name`, `type`,`element`, `folder`, `access`, `ordering`, `enabled`, `client_id`, `checked_out`, `checked_out_time`, `params`)\n VALUES \n ('JReviews Plugin', 'plugin', 'jreviews', 'content', 0, 0, 1, 0, 0, '0000-00-00 00:00:00', '');\n "; $this->_db->setQuery($query); if ($this->_db->query()) { $action['plugin_install'] = true; } else { $action['plugin_install'] = false; } } } else { // Add/create plugin db entry $query = "\n SELECT \n id \n FROM \n #__plugins \n WHERE \n element = 'jreviews' AND folder = 'content'\n "; $this->_db->setQuery($query); $result = $this->_db->loadResult(); if (!$result || empty($result)) { $query = "\n INSERT INTO #__plugins \n (`name`, `element`, `folder`, `access`, `ordering`, `published`, `iscore`, `client_id`, `checked_out`, `checked_out_time`, `params`)\n VALUES \n ('jReviews Comment Plugin', 'jreviews', 'content', 0, 0, 1, 0, 0, 0, '0000-00-00 00:00:00', '');\n "; $this->_db->setQuery($query); if ($this->_db->query()) { $action['plugin_install'] = true; } else { $action['plugin_install'] = false; } } } // end else } # Create image upload and thumbnail folders if (!is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS)) { $Config = new JConfig(); if (isset($Config->ftp_enable) && $Config->ftp_enable) { // set up basic connection $conn_id = ftp_connect($Config->ftp_host, $Config->ftp_port); // login with username and password $login_result = ftp_login($conn_id, $Config->ftp_user, $Config->ftp_pass); ftp_chdir($conn_id, $Config->ftp_root); ftp_mkdir($conn_id, _JR_PATH_IMAGES . 'jreviews'); ftp_mkdir($conn_id, _JR_PATH_IMAGES . 'jreviews' . DS . 'tn'); ftp_close($conn_id); @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'index.html'); @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS . 'index.html'); } } if (!is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS)) { $result = mkdir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS, 0755); if (!$result) { $action['thumbnail_dir'] = false; } else { @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'index.html'); $result = mkdir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn', 0755); if (!$result) { $action['thumbnail_dir'] = false; } else { @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS . 'index.html'); } } } if (!is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS)) { $result = mkdir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn', 0755); if (!$result) { $action['thumbnail_dir'] = false; } else { @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS . 'index.html'); } } if (is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS) && is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS)) { $action['thumbnail_dir'] = true; } // Clear data and core caches clearCache('', '__data'); clearCache('', 'core'); //var_dump($action); if (Sanitize::getString($this->params, 'task') == 'upgrade') { $response = array('error' => false, 'html' => ''); // {"db_install":true,"plugin_install":true,"thumbnail_dir":true} if (!$action['db_install']) { $response['error'] = true; $response['html'] = '<div style="color:red>There was a problem upgrading the database</div>'; } if (!$action['plugin_install']) { $response['error'] = true; $response['html'] .= '<div style="color:red>There was a problem upgrading the JReviews plugin</div>'; } return json_encode($response); } $this->set(array('action' => $action)); }
function constructRoute($passedArgs, $excludeParams = null, $app = 'jreviews') { $segments = $url_param = array(); $defaultExcludeParms = array('format', 'view', 'language', 'lang'); $excludeParams = !empty($excludeParams) ? array_merge($excludeParams, $defaultExcludeParms) : $defaultExcludeParms; if (defined('MVC_FRAMEWORK_ADMIN')) { $base_url = 'index.php?option=' . S2Paths::get($app, 'S2_CMSCOMP'); } else { $Itemid = Sanitize::getInt($passedArgs, 'Itemid') > 0 ? Sanitize::getInt($passedArgs, 'Itemid') : ''; $base_url = 'index.php?option=' . S2Paths::get($app, 'S2_CMSCOMP') . '&Itemid=' . $Itemid; } // Get segments without named params if (isset($passedArgs['url'])) { $parts = explode('/', $passedArgs['url']); foreach ($parts as $bit) { if (false === strpos($bit, _PARAM_CHAR) && $bit != 'index.php') { $segments[] = $bit; } } } unset($passedArgs['option'], $passedArgs['Itemid'], $passedArgs['url']); if (is_array($excludeParams)) { foreach ($excludeParams as $exclude) { unset($passedArgs[$exclude]); } } foreach ($passedArgs as $paramName => $paramValue) { if (is_string($paramValue) && !empty($paramValue)) { $paramValue == 'order' and $paramValue = array_shift(explode('.html', $paramValue)); $url_param[] = $paramName . _PARAM_CHAR . urlencodeParam($paramValue); } } empty($segments) and $segments[] = 'menu'; $new_route = $base_url . (!empty($segments) ? '&url=' . implode('/', $segments) . '/' . implode('/', $url_param) : ''); return $new_route; }
function constructRoute($passedArgs, $excludeParams = null, $app = 'jreviews') { $segments = ''; $url_param = array(); if (defined('MVC_FRAMEWORK_ADMIN')) { $base_url = 'index.php?option=' . S2Paths::get($app, 'S2_CMSCOMP'); } else { $Itemid = Sanitize::getInt($passedArgs, 'Itemid') > 0 ? Sanitize::getInt($passedArgs, 'Itemid') : ''; $base_url = 'index.php?option=' . S2Paths::get($app, 'S2_CMSCOMP') . '&Itemid=' . $Itemid; } // Get segments without named params if (isset($passedArgs['url'])) { $parts = explode('/', $passedArgs['url']); foreach ($parts as $bit) { if (false === strpos($bit, _PARAM_CHAR)) { $segments[] = $bit; } } } else { $segments[] = 'menu'; } unset($passedArgs['option'], $passedArgs['Itemid'], $passedArgs['url']); if (is_array($excludeParams)) { foreach ($excludeParams as $exclude) { unset($passedArgs[$exclude]); } } foreach ($passedArgs as $paramName => $paramValue) { if (is_string($paramValue)) { $url_param[] = $paramName . _PARAM_CHAR . urlencodeParam($paramValue); } } $new_route = $base_url . '&url=' . implode('/', $segments) . '/' . implode('/', $url_param); return $new_route; }
/** * Returns the request uri for xajax requests for each application * * @param string $app * @return xajax request uri */ function getXajaxUri($app = 'jreviews') { if (defined('MVC_FRAMEWORK_ADMIN')) { $ajaxUri = WWW_ROOT . 'administrator' . _DS . 'index.php?option=' . S2Paths::get($app, 'S2_CMSCOMP') . '&no_html=1&format=raw&tmpl=component&xajax=1'; } else { $ajaxUri = WWW_ROOT . 'index.php?option=' . S2Paths::get($app, 'S2_CMSCOMP'); } if (defined('MVC_FRAMEWORK_ADMIN')) { return str_replace('&', '&', $ajaxUri); } return $ajaxUri; }
function processCustomRoute(&$params) { $_this =& S2Router::getInstance(); $app = $_this->app; // Load app custom routes if (empty($_this->routes)) { include S2Paths::get($app, 'S2_APP_CONFIG') . 'routes.php'; } $url = rtrim($params['url']['url'], '/') . '/'; foreach ($_this->routes as $route) { if (preg_match($route[0], $url, $matches) == 1) { //prx($matches); if (isset($route[2]) && !empty($route[2])) { if (!is_array($route[2][0])) { $route[2] = array($route[2]); } foreach ($route[2] as $map) { // $map[0] this is the parameter name or names if it's an array // $map[1] this is the value or regex expression if ($map[1][0] == '/') { // It's a regex match $count = preg_match($map[1], $url, $match); // Only the first result from the match is used if ($count == 1 && !is_array($map[0])) { $params[$map[0]] = urldecode($match[1]); // An array of values from the match is used } elseif ($count == 1 && count($match) > 1) { if (is_array($map[0])) { unset($match[0]); $match = array_merge(array(), $match); // Reset keys foreach ($map[0] as $key => $named_param) { if (isset($map[2])) { $params[$map[2]][$named_param] = urldecode($match[$key]); } else { $params[$named_param] = urldecode($match[$key]); } } } } } else { // It's a straight value assignment $params[$map[0]] = $map[1]; } } } $params['data']['controller'] = $route[1]['controller']; $params['data']['action'] = isset($route[1]['action']) ? $route[1]['action'] : 'index'; break; } } //prx($params); exit; }
/** * 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('&', '&', $ajaxUri); } return $ajaxUri; }
/** * Constructor. * * @param string $path Path to folder * @param boolean $create Create folder if not found * @param mixed $mode Mode (CHMOD) to apply to created folder, false to ignore */ function __construct($path = false, $create = false, $mode = false) { parent::__construct(); if (empty($path)) { $path = S2Paths::get('jreviews', 'S2_TMP'); } if ($mode) { $this->mode = $mode; } if (!file_exists($path) && $create === true) { $this->create($path, $this->mode); } if (!Folder::isAbsolute($path)) { $path = realpath($path); } if (!empty($path)) { $this->cd($path); } }
/** * Creates the json object used for map rendering * * @param array $results listings * @param mixed $fields custom fields, required when using the GeoMaps module * @param mixed $options mapUI options to override globals when using GeoMaps module */ function makeJsonObject(&$results, &$fields = array(), $options = array()) { $www_base = array_shift(pathinfo(WWW_ROOT)); // Required for thumbnail path $paths = array(S2Paths::get('jreviews', 'S2_VIEWS_OVERRIDES') . 'themes' . DS . $this->c->Config->template . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS') . 'themes' . DS . $this->c->Config->template . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS_OVERRIDES') . 'themes' . DS . 'default' . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS') . 'themes' . DS . 'default' . DS . 'theme_images' . DS); $path = fileExistsInPath(array('name' => '', 'suffix' => '', 'ext' => ''), $paths); App::import('Helper', array('html', 'routes', 'custom_fields', 'thumbnail')); $Html = new HtmlHelper(); $Routes = new RoutesHelper(); $CustomFields = new CustomFieldsHelper(); $Thumbnail = new ThumbnailHelper(); $Thumbnail->app = 'jreviews'; $Thumbnail->name = $this->c->name; $Thumbnail->action = $this->c->action; $Routes->Config = $CustomFields->Config = $Thumbnail->Config = $this->c->Config; $Routes->Access = $CustomFields->Access = $Thumbnail->Access = $this->c->Access; $Routes->Html = $CustomFields->Html = $Thumbnail->Html = $Html; $CustomFields->viewTheme = $Thumbnail->viewTheme =& $this->c->viewTheme; $CustomFields->viewSuffix =& $this->c->viewSuffix; // Check format of results because we may need to re-format and add fields for Geomaps module $first = current($results); if (!isset($first['Listing'])) { $results = $this->buildListingArray($results, $fields); } // PaidListings - remove unpaid info Configure::read('PaidListings') and PaidListingsComponent::processPaidData($results); $marker_icons = array(); $infowindow_data = array(); $i = 1; $default_icon = $this->c->name == 'categories' ? 'numbered' : 'default'; // make sure we only have the numeric part of the id from request when checking against listing ids $request_id = explode(':', JRequest::getVar('id')); $request_id = $request_id[0]; if (!empty($results)) { foreach ($results as $key => $result) { $results[$key] = $this->injectDistanceGroup($result); // Add menu id if not already there if (!isset($result['Listing']['menu_id'])) { $results[$key]['Listing']['menu_id'] = $this->c->Menu->getCategory($result['Listing']['cat_id'], $result['Listing']['section_id'], $result['Directory']['dir_id'], $result['Listing']['listing_id']); } // Added to support extra coordinates //$coords = $result["Field"]["groups"]["Location Info"]["Fields"]["jr_extracoords"]["value"][0]; //$xtracoords = $CustomFields->field('jr_extracoords', $listing, false, false); if (isset($result["Field"]["groups"]["Location Info"]) && isset($result["Field"]["groups"]["Location Info"]["Fields"]["jr_extracoords"])) { $coords = $result["Field"]["groups"]["Location Info"]["Fields"]["jr_extracoords"]["value"][0]; if ($coords) { $coords = json_decode($coords); $results[$key]["ExtraCoords"] = $coords; if (JRequest::getString("option") != "com_content") { $results[$key]["ExtraCoords"] = 0; } // HTGMOD } } elseif (isset($result["Field"]["pairs"]["jr_extracoords"])) { //detail page $coords = $result["Field"]["pairs"]["jr_extracoords"]["value"][0]; if ($coords) { $coords = json_decode($coords); $results[$key]["ExtraCoords"] = $coords; if ($results[$key]["Listing"]["listing_id"] != $request_id) { // "if the current listing_id in the loop == the listing_id being viewed on the detail page...." $results[$key]["ExtraCoords"] = 0; } } } $listing_index = ($this->c->page - 1) * $this->c->limit + $i++; // Process and add icon info $icon = isset($result['Geomaps']) ? json_decode($result['Geomaps']['icon'], true) : array(); $results[$key]['Geomaps']['icon'] = ''; $icon_name = $default_icon; if (!empty($icon)) { $foundIcon = false; // Check if custom field assigned if ($icon['field'] != '' && substr($icon['field'], 0, 3) == 'jr_') { if (isset($result['Field']['pairs'][$icon['field']]) && isset($result['Field']['pairs'][$icon['field']]['image'][0])) { $icon_name = substr($result['Field']['pairs'][$icon['field']]['image'][0], 0, strpos($result['Field']['pairs'][$icon['field']]['image'][0], '.')); $marker_icons[$icon_name] = $results[$key]['Geomaps']['icon'] = $result['Field']['pairs'][$icon['field']]['image'][0]; $foundIcon = true; } } elseif ($icon['cat'] != '' && !$foundIcon) { $icon_name = substr($icon['cat'], 0, strpos($icon['cat'], '.')); if ($icon_name != 'default') { $marker_icons[$icon_name] = $results[$key]['Geomaps']['icon'] = $icon['cat']; } } } if (isset($result['Geomaps']) && $result['Geomaps']['lat'] != '' && $result['Geomaps']['lon'] != '' && $result['Geomaps']['lat'] != 0 && $result['Geomaps']['lon']) { # Create infowindow JSON object // start with standard fields $infowindow = array('id' => $result['Listing']['listing_id'], 'url' => str_replace(array($www_base, '&'), array('', '&'), $Routes->content('', $results[$key], array('return_url' => true))), 'index' => $listing_index, 'title' => $result['Listing']['title'], 'image' => str_replace($www_base, '', $Thumbnail->thumb($result, 0, 'scale', 'list', array($this->c->Config->list_image_resize), array('return_src' => 1))), 'featured' => $result['Listing']['featured'], 'rating_scale' => $this->c->Config->rating_scale, 'user_rating' => $result['Review']['user_rating'], 'user_rating_count' => $result['Review']['user_rating_count'], 'editor_rating' => $result['Review']['editor_rating'], 'editor_rating_count' => $result['Review']['editor_rating_count'], 'lat' => (double) $result['Geomaps']['lat'], 'lon' => (double) $result['Geomaps']['lon'], 'icon' => $icon_name); // Added for Hooked $infowindow['criteria_id'] = $result['Criteria']['criteria_id']; if (isset($results[$key]["ExtraCoords"])) { $infowindow['extracoords'] = $results[$key]["ExtraCoords"]; } if (isset($results[$key]['Listing']['relations'])) { $infowindow['relations'] = $results[$key]['Listing']['relations']; } if ($results[$key]['Listing']['section_id'] != 1) { $infowindow['hascontent'] = 1; } else { if (isset($results[$key]['Listing']['summary']) && $results[$key]['Listing']['summary'] != '') { $infowindow['hascontent'] = 1; } else { $infowindow['hascontent'] = 0; } } if (!empty($result['Field']['pairs'])) { foreach ($result['Field']['pairs'] as $name => $fieldArray) { $infowindow['field'][$name] = $CustomFields->field($name, $result); } } $infowindow_data['id' . $result['Listing']['listing_id']] = $infowindow; } } } $mapUI = array(); $zoom = ''; switch ($this->c->name) { case 'categories': $maptypes = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_list', 'buttons'); //buttons|menu|none $maptype_def = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_list', 'G_NORMAL_MAP'); $map = Sanitize::getBool($this->c->Config, 'geomaps.ui.map_list', 1); $hybrid = Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_list', 1); $satellite = Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_list', 1); $terrain = Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_list', 1); $panzoom = Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_list', 1); $scale = Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_list', 0); $scrollwheel = Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_list', 0); $doubleclick = Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_list', 1); $mapUI['title']['trim'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_list', 0); $mapUI['title']['trimchars'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_chars', 30); break; case 'com_content': $maptypes = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_detail', 'buttons'); //buttons|menu|none $maptype_def = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_detail', 'G_NORMAL_MAP'); $map = Sanitize::getBool($this->c->Config, 'geomaps.ui.map_detail', 1); $hybrid = Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_detail', 1); $satellite = Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_detail', 1); $terrain = Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_detail', 1); $panzoom = Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_detail', 1); $scale = Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_detail', 0); $scrollwheel = Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_detail', 0); $doubleclick = Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_detail', 1); $zoom = Sanitize::getInt($this->c->Config, 'geomaps.ui.zoom_detail', ''); $mapUI['title']['trim'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_detail', 0); $mapUI['title']['trimchars'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_chars', 30); break; case 'module_geomaps': $maptypes = Sanitize::getString($options, 'ui_maptype', 2) == '2' ? Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_module', 'buttons') : Sanitize::getString($options, 'ui_maptype'); //buttons|menu|none $maptype_def = Sanitize::getString($options, 'ui_maptype_def', 2) == '2' ? Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_module', 'G_NORMAL_MAP') : Sanitize::getString($options, 'ui_maptype_def', 'G_NORMAL_MAP'); $map = Sanitize::getInt($options, 'ui_map', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.map_module', 1) : Sanitize::getBool($options, 'ui_map'); $hybrid = Sanitize::getInt($options, 'ui_hybrid', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_module', 1) : Sanitize::getBool($options, 'ui_hybrid'); $satellite = Sanitize::getInt($options, 'ui_satellite', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_module', 1) : Sanitize::getBool($options, 'ui_satellite'); $terrain = Sanitize::getInt($options, 'ui_terrain', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_module', 1) : Sanitize::getBool($options, 'ui_terrain'); $panzoom = Sanitize::getInt($options, 'ui_panzoom', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_module', 1) : Sanitize::getBool($options, 'ui_panzoom'); $scale = Sanitize::getInt($options, 'ui_scale', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_module', 0) : Sanitize::getBool($options, 'ui_scale'); $scrollwheel = Sanitize::getInt($options, 'ui_scrollwheel', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_module', 0) : Sanitize::getBool($options, 'ui_scrollwheel'); $doubleclick = Sanitize::getInt($options, 'ui_doubleclick', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_module', 1) : Sanitize::getBool($options, 'ui_doubleclick'); $mapUI['title']['trim'] = Sanitize::getInt($options, 'ui_trimtitle_module', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.trimtitle_module', 30) : Sanitize::getBool($options, 'ui_trimtitle_module'); $mapUI['title']['trimchars'] = Sanitize::getInt($options, 'ui_trimtitle_chars', 2) == '2' ? Sanitize::getInt($this->c->Config, 'geomaps.ui.trimtitle_chars', 30) : Sanitize::getInt($options, 'ui_trimtitle_chars'); if (Sanitize::getString($options, 'detail_view', 1)) { $zoom = Sanitize::getInt($this->c->Config, 'geomaps.ui.zoom_detail', ''); } break; } switch ($maptypes) { case 'buttons': $mapUI['controls']['maptypecontrol'] = true; $mapUI['controls']['menumaptypecontrol'] = false; break; case 'menu': $mapUI['controls']['maptypecontrol'] = false; $mapUI['controls']['menumaptypecontrol'] = true; break; default: $mapUI['controls']['maptypecontrol'] = false; $mapUI['controls']['menumaptypecontrol'] = false; } $mapUI['maptypes']['def'] = $maptype_def; $mapUI['maptypes']['map'] = $map; $mapUI['maptypes']['hybrid'] = $hybrid; $mapUI['maptypes']['satellite'] = $satellite; $mapUI['maptypes']['terrain'] = $terrain; if ($panzoom) { $mapUI['controls']['smallzoomcontrol3d'] = true; $mapUI['controls']['largemapcontrol3d'] = true; } else { $mapUI['controls']['smallzoomcontrol3d'] = false; $mapUI['controls']['largemapcontrol3d'] = false; } $mapUI['controls']['scalecontrol'] = $scale; $mapUI['zoom']['scrollwheel'] = $scrollwheel; $mapUI['zoom']['doubleclick'] = $doubleclick; $mapUI['zoom']['start'] = $zoom; $mapUI['anchor']['x'] = Sanitize::getVar($this->c->Config, 'geomaps.infowindow_x', 0); $mapUI['anchor']['y'] = Sanitize::getVar($this->c->Config, 'geomaps.infowindow_y', 0); unset($Html, $Routes, $CustomFields, $Thumbnail); return json_encode(array('count' => count($infowindow_data), 'mapUI' => $mapUI, 'infowindow' => Sanitize::getString($this->c->Config, 'geomaps.infowindow', '_google'), 'icons' => $this->processIcons($marker_icons), 'payload' => $infowindow_data)); }
function click2Search($field, $criteriaid, $catid, $Itemid) { if (isset($field['properties']['click2search'])) { $Itemid = $Itemid ? $Itemid : ''; if (isset($field['properties']['click2searchlink']) && $field['properties']['click2searchlink'] != '') { $click2searchlink = $field['properties']['click2searchlink']; } else { $click2searchlink = 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP') . '&Itemid={ITEMID}&url=tag/{FIELDNAME}/{FIELDTEXT}/criteria' . _PARAM_CHAR . '{CRITERIAID}'; } foreach ($this->output as $key => $text) { if ($field['type'] == 'date') { $field['value'][$key] = str_replace(' 00:00:00', '', $field['value'][$key]); } $url = $click2searchlink; if ($Itemid > 0) { $url = str_replace('{ITEMID}', $Itemid, $url); } else { $url = str_replace(array('_m{ITEMID}', '&Itemid={ITEMID}'), '', $url); } $url = str_ireplace(array('{FIELDNAME}', '{FIELDTEXT}', '{CRITERIAID}', '{CATID}'), array(substr($field['name'], 3), urlencode($field['value'][$key]), urlencode($criteriaid), urlencode($catid)), $url); $url = s2ampReplace($url); $url = cmsFramework::route($url); $this->output[$key] = "<a href=\"{$url}\">{$text}</a>"; } } }
function __construct() { parent::__construct(); $menuList = array(); switch (getCmsVersion()) { case CMS_JOOMLA15: $select = 'SELECT id,name,link AS menu_type,link,componentid,params,access,published'; $type = "\n AND type = 'component'"; $link = "\n AND ( \n link LIKE '%option=com_content&view=section%' OR\n link LIKE '%option=com_content&view=section&layout=blog%' OR\n link LIKE '%option=com_content&view=category\\%' OR\n link LIKE '%option=com_content&view=category&layout=blog%' OR\n link LIKE '%option=com_content&view=article%' \n )"; break; case CMS_JOOMLA16: $select = "\n SELECT \n id, \n alias AS name,\n link AS menu_type,\n link,\n component_id AS componentid,\n params,\n access,\n published\n "; $type = "\n AND type = 'component'"; $link = "\n AND ( \n link LIKE '%option=com_content&view=section%' OR\n link LIKE '%option=com_content&view=section&layout=blog%' OR\n link LIKE '%option=com_content&view=category\\%' OR\n link LIKE '%option=com_content&view=category&layout=blog%' OR\n link LIKE '%option=com_content&view=article%' \n )"; break; } // Get all com_content category/section menus and jReviews menus $sql = $select . "\n FROM #__menu" . "\n WHERE published = 1" . (getCmsVersion() == CMS_MAMBO46 ? "\n ORDER BY link ASC" : "\n ORDER BY link DESC"); # Check for cached version $cache_prefix = 'menu_model'; $cache_key = $sql; if ($cache = S2cacheRead($cache_prefix, $cache_key)) { $menuList = $cache; } if (empty($menuList)) { // Mambo4.6, as opposed to Mambo4.5, does not allow using other components Itemids so jReviews // Sections and category lists cannot use the section/category table or blog list menu Itemids $this->_db->setQuery($sql); $menuList = $this->_db->loadObjectList(); # Send to cache S2cacheWrite($cache_prefix, $cache_key, $menuList); } // Get itemid for each menu link and store it if (is_array($menuList)) { foreach ($menuList as $menu) { $this->menues[$menu->id] = $menu; $params = stringToArray($menu->params); $paramsArray = explode("\n", $menu->params); if (Sanitize::getVar($params, 'sef_name') != '') { $m_name = Sanitize::getVar($params, 'sef_name'); } else { $m_name = $menu->name; } if (function_exists("sefEncode")) { $m_name = sefEncode($m_name); } $m_action = Sanitize::getVar($params, 'action'); $m_dir_id = str_replace(",", "-", Sanitize::getVar($params, 'dirid')); $m_cat_id = str_replace(",", "-", Sanitize::getVar($params, 'catid')); $m_section_id = str_replace(",", "-", Sanitize::getVar($params, 'sectionid')); $m_criteria_id = str_replace(",", "-", Sanitize::getVar($params, 'criteriaid')); // Create a variable to get Menu Name from Itemid $this->set('jr_itemid_' . $menu->id, $m_name); $this->set('jr_menu_' . $m_name, $menu->id); # Fix for change in menu structure in J1.5 if (getCmsVersion() == CMS_JOOMLA15) { if (strpos($menu->menu_type, 'option=com_content&view=section&id=') || strpos($menu->menu_type, 'option=com_content&view=section&layout=blog&id=')) { $menu->componentid = end(explode('id=', $menu->menu_type)); $menu->menu_type = 'content_section'; } elseif (strpos($menu->menu_type, 'option=com_content&view=category&id=') || strpos($menu->menu_type, 'option=com_content&view=category&layout=blog&id=')) { $menu->componentid = end(explode('id=', $menu->menu_type)); $menu->menu_type = 'content_category'; } elseif (strpos($menu->menu_type, 'option=com_content&view=article&id=') || strpos($menu->menu_type, 'option=com_content&task=view&id=')) { $menu->componentid = end(explode('id=', $menu->menu_type)); $menu->menu_type = 'content_item_link'; } } switch ($menu->menu_type) { case 'content_section': case 'content_blog_section': if ($menu->componentid) { // Only one section id $this->set('core_section_menu_id_' . $menu->componentid, $menu->id); // $this->set('jr_section_menu_id_'.$menu->componentid,$menu->id); } else { $section_ids = explode(",", Sanitize::getVar($params, 'sectionid')); $this->set('jr_manyIds_' . $menu->id, 1); foreach ($section_ids as $section_id) { $this->set('core_section_menu_id_' . $section_id, $menu->id); // $this->set('jr_section_menu_id_'.$section_id,$menu->id); } } break; case 'content_category': case 'content_blog_category': if ($menu->componentid) { // Only one category id $this->set('core_category_menu_id_' . $menu->componentid, $menu->id); // $this->set('jr_category_menu_id_'.$menu->componentid,$menu->id); } else { $cat_ids = explode(",", Sanitize::getVar($params, 'categoryid')); $this->set('jr_manyIds_' . $menu->id, 1); foreach ($cat_ids as $cat_id) { $this->set('core_category_menu_id_' . $cat_id, $menu->id); // $this->set('jr_category_menu_id_'.$cat_id,$menu->id); } } break; case 'content_item_link': $this->set('core_content_menu_id_' . $menu->componentid, $menu->id); break; default: if ($menu->link == 'index.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP')) { // It's a jReviews menu // Get a jReviews menu with public access to use in xajax requests if ($menu->access == 0 && $menu->published == 1) { $this->set('jreviews_public', $menu->id); } $menuParams = array(); foreach ($paramsArray as $parameter) { $menuParams[current(explode('=', $parameter))] = end(explode('=', $parameter)); } $this->set('jr_menu_action_' . $m_dir_id, $m_action); $this->set('menu_params_' . $menu->id, $menuParams); switch ($m_action) { case '0': // Directory menu $this->set('jr_directory_menu_id_' . $m_dir_id, $menu->id); break; case '1': // Section menu $this->set('jr_section_menu_id_' . $m_section_id, $menu->id); break; case '2': // Category menu $this->set('jr_category_menu_id_' . $m_cat_id, $menu->id); break; case '10': $this->set('jr_myreviews', $menu->id); break; case '11': $m_criteria_id && $this->set('jr_advsearch_' . $m_criteria_id, $menu->id); !$m_criteria_id && $this->set('jr_advsearch', $menu->id); break; case '12': $this->set('jr_mylistings', $menu->id); break; case '18': $this->set('jr_reviewers', $menu->id); break; default: $this->set('jr_menu_id_action_' . $m_action, $menu->id); break; } } break; } } } // prx($this->___menu_data); }
/** * Creates the json object used for map rendering * * @param array $results listings * @param mixed $fields custom fields, required when using the GeoMaps module * @param mixed $options mapUI options to override globals when using GeoMaps module */ function makeJsonObject(&$results, &$fields = array(), $options = array()) { $www_base = array_shift(pathinfo(WWW_ROOT)); // Required for thumbnail path $paths = array(S2Paths::get('jreviews', 'S2_VIEWS_OVERRIDES') . 'themes' . DS . $this->c->Config->template . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS') . 'themes' . DS . $this->c->Config->template . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS_OVERRIDES') . 'themes' . DS . 'default' . DS . 'theme_images' . DS, S2Paths::get('jreviews', 'S2_VIEWS') . 'themes' . DS . 'default' . DS . 'theme_images' . DS); $path = fileExistsInPath(array('name' => '', 'suffix' => '', 'ext' => ''), $paths); App::import('Helper', array('html', 'routes', 'custom_fields', 'thumbnail')); $Html = new HtmlHelper(); $Routes = new RoutesHelper(); $CustomFields = new CustomFieldsHelper(); $Thumbnail = new ThumbnailHelper(); $Thumbnail->app = 'jreviews'; $Thumbnail->name = $this->c->name; $Thumbnail->action = $this->c->action; $Routes->Config = $CustomFields->Config = $Thumbnail->Config = $this->c->Config; $Routes->Access = $CustomFields->Access = $Thumbnail->Access = $this->c->Access; $Routes->Html = $CustomFields->Html = $Thumbnail->Html = $Html; $CustomFields->viewTheme = $Thumbnail->viewTheme =& $this->c->viewTheme; $CustomFields->viewSuffix =& $this->c->viewSuffix; // Check format of results because we may need to re-format and add fields for Geomaps module $first = current($results); if (!isset($first['Listing'])) { $results = $this->buildListingArray($results, $fields); } // PaidListings - remove unpaid info Configure::read('PaidListings') and PaidListingsComponent::processPaidData($results); $marker_icons = array(); $infowindow_data = array(); $i = 1; $map_counter = 0; $default_icon = $this->c->name == 'categories' ? 'numbered' : 'default'; if (!empty($results)) { $infowindow_fields = str_replace(" ", "", Sanitize::getString($this->c->Config, 'geomaps.infowindow_fields')); $infowindow_fields = $infowindow_fields != '' ? explode(",", $infowindow_fields) : array(); foreach ($results as $key => $result) { $results[$key] = $this->injectDistanceGroup($result); // Override global setting for map display in lists if at least one listing has map enabled // For it's listing type and has valid coordinates if ($this->c->name == 'categories' && isset($result['ListingType']) && Sanitize::getBool($result['ListingType']['config'], 'geomaps.enable_map_list', true)) { if (isset($result['Geomaps']) && abs($result['Geomaps']['lat']) > 0 && abs($result['Geomaps']['lon']) > 0) { $map_counter++; } } // Add menu id if not already there if (!isset($result['Listing']['menu_id'])) { $results[$key]['Listing']['menu_id'] = $this->c->Menu->getCategory(array('cat_id' => $result['Listing']['cat_id'], 'dir_id' => $result['Directory']['dir_id'], 'section_id' => isset($result['Listing']['section_id']) ? $result['Listing']['section_id'] : null, 'listing' => $result['Listing']['listing_id'])); } $listing_index = ($this->c->page - 1) * $this->c->limit + $i++; // Process and add icon info $icon = isset($result['Geomaps']) ? json_decode($result['Geomaps']['icon'], true) : array(); $results[$key]['Geomaps']['icon'] = ''; $icon_name = $default_icon; if (!empty($icon)) { $foundIcon = false; // Check if custom field assigned if ($icon['field'] != '' && substr($icon['field'], 0, 3) == 'jr_') { if (isset($result['Field']['pairs'][$icon['field']]) && isset($result['Field']['pairs'][$icon['field']]['image'][0])) { $icon_name = substr($result['Field']['pairs'][$icon['field']]['image'][0], 0, strpos($result['Field']['pairs'][$icon['field']]['image'][0], '.')); $marker_icons[$icon_name] = $results[$key]['Geomaps']['icon'] = $result['Field']['pairs'][$icon['field']]['image'][0]; $foundIcon = true; } } elseif ($icon['cat'] != '' && !$foundIcon) { $icon_name = substr($icon['cat'], 0, strpos($icon['cat'], '.')); if ($icon_name != 'default') { $marker_icons[$icon_name] = $results[$key]['Geomaps']['icon'] = $icon['cat']; } } } if (isset($result['Geomaps']) && $result['Geomaps']['lat'] != '' && $result['Geomaps']['lon'] != '' && $result['Geomaps']['lat'] != 0 && $result['Geomaps']['lon']) { # Create infowindow JSON object // start with standard fields $infowindow = array('id' => $result['Listing']['listing_id'], 'url' => str_replace(array($www_base, '&'), array('', '&'), $Routes->content('', $results[$key], array('return_url' => true))), 'index' => $listing_index, 'title' => $result['Listing']['title'], 'image' => str_replace($www_base, '', $Thumbnail->thumb($result, 0, array('tn_mode' => $this->c->Config->list_thumb_mode, 'location' => 'list', 'dimensions' => array($this->c->Config->list_image_resize), 'return_src' => 1))), 'featured' => $result['Listing']['featured'], 'rating_scale' => $this->c->Config->rating_scale, 'user_rating' => $result['Review']['user_rating'], 'user_rating_count' => $result['Review']['user_rating_count'], 'editor_rating' => $result['Review']['editor_rating'], 'editor_rating_count' => $result['Review']['editor_rating_count'], 'lat' => (double) $result['Geomaps']['lat'], 'lon' => (double) $result['Geomaps']['lon'], 'icon' => $icon_name); if (!empty($result['Field']['pairs'])) { # Limit fields will included in the payload json object $result['Field']['pairs'] = array_intersect_key($result['Field']['pairs'], array_flip($infowindow_fields)); foreach ($result['Field']['pairs'] as $name => $fieldArray) { $infowindow['field'][$name] = $CustomFields->field($name, $result); } } $infowindow_data['id' . $result['Listing']['listing_id']] = $infowindow; } } } $this->c->Config->{'geomaps.enable_map_list'} = $map_counter; $mapUI = array(); $zoom = ''; switch ($this->c->name) { case 'categories': $maptypes = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_list', 'buttons'); //buttons|menu|none $maptype_def = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_list', 'G_NORMAL_MAP'); $map = Sanitize::getBool($this->c->Config, 'geomaps.ui.map_list', 1); $hybrid = Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_list', 1); $satellite = Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_list', 1); $terrain = Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_list', 1); $panzoom = Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_list', 1); $scale = Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_list', 0); $scrollwheel = Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_list', 0); $doubleclick = Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_list', 1); $mapUI['title']['trim'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_list', 0); $mapUI['title']['trimchars'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_chars', 30); break; case 'com_content': $maptypes = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_detail', 'buttons'); //buttons|menu|none $maptype_def = Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_detail', 'G_NORMAL_MAP'); $map = Sanitize::getBool($this->c->Config, 'geomaps.ui.map_detail', 1); $hybrid = Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_detail', 1); $satellite = Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_detail', 1); $terrain = Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_detail', 1); $panzoom = Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_detail', 1); $scale = Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_detail', 0); $scrollwheel = Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_detail', 0); $doubleclick = Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_detail', 1); $zoom = Sanitize::getInt($this->c->Config, 'geomaps.ui.zoom_detail', ''); $mapUI['title']['trim'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_detail', 0); $mapUI['title']['trimchars'] = Sanitize::getVar($this->c->Config, 'geomaps.ui.trimtitle_chars', 30); break; case 'module_geomaps': $maptypes = Sanitize::getString($options, 'ui_maptype', 2) == '2' ? Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_module', 'buttons') : Sanitize::getString($options, 'ui_maptype'); //buttons|menu|none $maptype_def = Sanitize::getString($options, 'ui_maptype_def', 2) == '2' ? Sanitize::getString($this->c->Config, 'geomaps.ui.maptype_def_module', 'G_NORMAL_MAP') : Sanitize::getString($options, 'ui_maptype_def', 'G_NORMAL_MAP'); $map = Sanitize::getInt($options, 'ui_map', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.map_module', 1) : Sanitize::getBool($options, 'ui_map'); $hybrid = Sanitize::getInt($options, 'ui_hybrid', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.hybrid_module', 1) : Sanitize::getBool($options, 'ui_hybrid'); $satellite = Sanitize::getInt($options, 'ui_satellite', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.satellite_module', 1) : Sanitize::getBool($options, 'ui_satellite'); $terrain = Sanitize::getInt($options, 'ui_terrain', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.terrain_module', 1) : Sanitize::getBool($options, 'ui_terrain'); $panzoom = Sanitize::getInt($options, 'ui_panzoom', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.panzoom_module', 1) : Sanitize::getBool($options, 'ui_panzoom'); $scale = Sanitize::getInt($options, 'ui_scale', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.scale_module', 0) : Sanitize::getBool($options, 'ui_scale'); $scrollwheel = Sanitize::getInt($options, 'ui_scrollwheel', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.scrollwheel_module', 0) : Sanitize::getBool($options, 'ui_scrollwheel'); $doubleclick = Sanitize::getInt($options, 'ui_doubleclick', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.doubleclick_module', 1) : Sanitize::getBool($options, 'ui_doubleclick'); $mapUI['title']['trim'] = Sanitize::getInt($options, 'ui_trimtitle_module', 2) == '2' ? Sanitize::getBool($this->c->Config, 'geomaps.ui.trimtitle_module', 30) : Sanitize::getBool($options, 'ui_trimtitle_module'); $mapUI['title']['trimchars'] = Sanitize::getInt($options, 'ui_trimtitle_chars', 2) == '2' ? Sanitize::getInt($this->c->Config, 'geomaps.ui.trimtitle_chars', 30) : Sanitize::getInt($options, 'ui_trimtitle_chars'); if (Sanitize::getString($options, 'detail_view', 1)) { $zoom = Sanitize::getInt($this->c->Config, 'geomaps.ui.zoom_detail', ''); } break; } switch ($maptypes) { case 'buttons': $mapUI['controls']['maptypecontrol'] = true; $mapUI['controls']['menumaptypecontrol'] = false; break; case 'menu': $mapUI['controls']['maptypecontrol'] = false; $mapUI['controls']['menumaptypecontrol'] = true; break; default: $mapUI['controls']['maptypecontrol'] = false; $mapUI['controls']['menumaptypecontrol'] = false; } $mapUI['maptypes']['def'] = $maptype_def; $mapUI['maptypes']['map'] = $map; $mapUI['maptypes']['hybrid'] = $hybrid; $mapUI['maptypes']['satellite'] = $satellite; $mapUI['maptypes']['terrain'] = $terrain; if ($panzoom) { $mapUI['controls']['smallzoomcontrol3d'] = true; $mapUI['controls']['largemapcontrol3d'] = true; } else { $mapUI['controls']['smallzoomcontrol3d'] = false; $mapUI['controls']['largemapcontrol3d'] = false; } $mapUI['controls']['scalecontrol'] = $scale; $mapUI['zoom']['scrollwheel'] = $scrollwheel; $mapUI['zoom']['doubleclick'] = $doubleclick; $mapUI['zoom']['start'] = $zoom; $mapUI['anchor']['x'] = Sanitize::getVar($this->c->Config, 'geomaps.infowindow_x', 0); $mapUI['anchor']['y'] = Sanitize::getVar($this->c->Config, 'geomaps.infowindow_y', 0); unset($Html, $Routes, $CustomFields, $Thumbnail); return json_encode(array('count' => count($infowindow_data), 'mapUI' => $mapUI, 'infowindow' => Sanitize::getString($this->c->Config, 'geomaps.infowindow', '_google'), 'icons' => $this->processIcons($marker_icons), 'payload' => $infowindow_data)); }
function index() { $this->EverywhereAfterFind = true; // Triggers the afterFind in the Observer Model if (!isset($this->params['module'])) { $this->params['module'] = array(); } // For direct calls to the controller // Required for ajax pagination to remember module settings $Session = RegisterClass::getInstance('MvcSession'); $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id')); if ($this->ajaxRequest) { $this->params = $Session->get('module_params' . $module_id, null, S2Paths::get('jreviews', 'S2_CMSCOMP')); } else { srand((double) microtime() * 1000000); $this->params['rand'] = rand(); $Session->set('module_rand' . $module_id, $this->params['rand'], S2Paths::get('jreviews', 'S2_CMSCOMP')); $Session->set('module_params' . $module_id, $this->params, S2Paths::get('jreviews', 'S2_CMSCOMP')); } # Prevent sql injection $token = Sanitize::getString($this->params, 'token'); $tokenMatch = 0 === strcmp($token, cmsFramework::formIntegrityToken($this->params, array('module', 'module_id', 'form', 'data'), false)); $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix'); $conditions = array(); $joins = array(); $order = array(); # Read module parameters $extension = Sanitize::getString($this->params['module'], 'extension'); $reviews_type = Sanitize::getString($this->params['module'], 'reviews_type'); $custom_where = Sanitize::getString($this->params['module'], 'custom_where'); $cat_id = Sanitize::getString($this->params['module'], 'category'); $listing_id = Sanitize::getString($this->params['module'], 'listing'); if ($extension == 'com_content') { $dir_id = Sanitize::getString($this->params['module'], 'dir'); $section_id = Sanitize::getString($this->params['module'], 'section'); $criteria_id = Sanitize::getString($this->params['module'], 'criteria'); } else { $dir_id = null; $section_id = null; $criteria_id = null; } // This parameter determines the module mode $sort = Sanitize::getString($this->params['module'], 'reviews_order'); # Category auto detect if (Sanitize::getInt($this->params['module'], 'cat_auto') && $extension == 'com_content') { $ids = CommonController::_discoverIDs($this); extract($ids); } $extension != '' and $conditions[] = "Review.mode = " . $this->quote($extension); # Set conditionals based on configuration parameters if ($extension == 'com_content') { $conditions = array_merge($conditions, array('Listing.state = 1', '( Listing.publish_up = "' . NULL_DATE . '" OR DATE(Listing.publish_up) <= DATE("' . _CURRENT_SERVER_TIME . '") )', '( Listing.publish_down = "' . NULL_DATE . '" OR DATE(Listing.publish_down) >= DATE("' . _CURRENT_SERVER_TIME . '") )', 'Listing.access <= ' . $this->_user->gid)); $cat_id != '' and $conditions[] = 'Listing.catid IN (' . cleanIntegerCommaList($cat_id) . ')'; $cat_id == '' and $section_id != '' and $conditions[] = 'Listing.sectionid IN (' . cleanIntegerCommaList($section_id) . ')'; $cat_id == '' and $dir_id != '' and $conditions[] = 'JreviewsCategory.dirid IN (' . cleanIntegerCommaList($dir_id) . ')'; $cat_id == '' and $criteria_id != '' and $conditions[] = 'JreviewsCategory.criteriaid IN (' . cleanIntegerCommaList($criteria_id) . ')'; } else { if (Sanitize::getInt($this->params['module'], 'cat_auto') && isset($this->Listing) && method_exists($this->Listing, 'catUrlParam')) { if ($cat_id = Sanitize::getInt($this->passedArgs, $this->Listing->catUrlParam())) { $conditions[] = 'JreviewsCategory.id IN (' . $cat_id . ')'; } } elseif ($cat_id) { $conditions[] = 'JreviewsCategory.id IN (' . cleanIntegerCommaList($cat_id) . ')'; } } $listing_id and $conditions[] = "Review.pid IN ( " . cleanIntegerCommaList($listing_id) . ")"; $conditions[] = 'Review.published > 0'; switch ($sort) { case 'latest': $order[] = $this->Review->processSorting('rdate'); break; case 'helpful': $order[] = $this->Review->processSorting('helpful'); break; case 'random': $order[] = 'RAND(' . $this->params['rand'] . ')'; break; default: $order[] = $this->Review->processSorting('rdate'); break; } switch ($reviews_type) { case 'all': break; case 'user': $conditions[] = 'Review.author = 0'; break; case 'editor': $conditions[] = 'Review.author = 1'; break; } # Custom WHERE $tokenMatch and $custom_where and $conditions[] = $custom_where; $queryData = array('joins' => $joins, 'conditions' => $conditions, 'order' => $order, 'limit' => $this->module_limit, 'offset' => $this->module_offset); # Don't run it here because it's run in the Everywhere Observer Component $this->Review->runProcessRatings = false; // Excludes listing owner info in Everywhere component $this->Review->controller = 'module_reviews'; $reviews = $this->Review->findAll($queryData); if (Sanitize::getInt($this->params['module'], 'ajax_nav', 1)) { unset($queryData['order']); $count = $this->Review->findCount($queryData, 'DISTINCT Review.id'); } else { $count = $this->module_limit; } # Send variables to view template $this->set(array('Access' => $this->Access, 'User' => $this->_user, 'reviews' => $reviews, 'total' => $count)); $page = $this->render('modules', 'reviews'); if ($this->ajaxRequest) { return $this->ajaxResponse($page, false); } else { return $page; } }
function index() { $response = array(); if (Sanitize::getString($this->params, 'task') == 'upgrade') { // Where running the install script for upgrade we want a json object returned $this->autoLayout = false; $this->autoRender = false; } else { $this->autoLayout = true; $this->autoRender = true; } $this->name = 'install'; # Remove views folder in J1.5 if ($this->cmsVersion == CMS_JOOMLA15) { $Folder = ClassRegistry::getClass('Folder'); $target = PATH_ROOT . 'components' . DS . 'com_jreviews' . DS . 'views'; $Folder->rm($target); } # Create database tables // Start db upgrade logic $action = array(); $action['db_install'] = true; $tables = $this->_db->getTableList(); $dbprefix = cmsFramework::getConfig('dbprefix'); $old_build = 0; // Get current version number $jreviewsxml = $this->cmsVersion == CMS_JOOMLA15 ? 'jreviews.xml' : 'jreviewg.xml'; $xml = file(S2_CMS_ADMIN . $jreviewsxml); foreach ($xml as $xml_line) { if (strstr($xml_line, 'version')) { $new_version = trim(strip_tags($xml_line)); continue; } } $version_parts = explode('.', $new_version); $new_build = array_pop($version_parts); if (is_array($tables) && in_array($dbprefix . 'jreviews_categories', array_values($tables))) { // Tables exist so we check the current build and upgrade accordingly, otherwise it's a clean install and no upgrade is necessary $query = "SELECT value FROM #__jreviews_config WHERE id = 'version'"; $this->_db->setQuery($query); $old_version = trim(strip_tags($this->_db->loadResult())); if ($old_version != '') { $version_parts = explode('.', $old_version); $old_build = array_pop($version_parts); } if (Sanitize::getBool($this->params, 'sql')) { $old_build = 0; } // prx($old_build . '<br/>' . $new_build) ; if ($new_build > $old_build) { $i = $old_build + 1; for ($i = $old_build + 1; $i <= $new_build; $i++) { // Run sql updates $sql_file = S2Paths::get('jreviews', 'S2_APP') . 'upgrades' . DS . 'upgrade_build' . $i . '.sql'; if (file_exists($sql_file)) { $action['db_install'] = $this->__parseMysqlDump($sql_file, $dbprefix) && $action['db_install']; } // Run php updates $php_file = S2Paths::get('jreviews', 'S2_APP') . 'upgrades' . DS . 'upgrade_build' . $i . '.php'; if (file_exists($php_file)) { include $php_file; } } } } else { // It's a clean install so we use the whole jReviews sql file $sql_file = S2Paths::get('jreviews', 'S2_APP') . 'upgrades' . DS . 'jreviews.sql'; $action['db_install'] = $this->__parseMysqlDump($sql_file, $dbprefix); } # Update component id in pre-existing jReviews menus if ($this->cmsVersion == CMS_JOOMLA16) { $query = "\n SELECT \n extension_id AS id\n FROM \n #__extensions \n WHERE \n element = '" . S2Paths::get('jreviews', 'S2_CMSCOMP') . "' AND type = 'component'\n "; } else { $query = "\n SELECT \n id \n FROM \n #__components \n WHERE \n admin_menu_link = 'option=" . S2Paths::get('jreviews', 'S2_CMSCOMP') . "'\n "; } $this->_db->setQuery($query); if ($id = $this->_db->loadResult()) { if ($this->cmsVersion == CMS_JOOMLA16) { $query = "\n UPDATE \n `#__menu` \n SET \n component_id = {$id} \n WHERE \n type IN ('component','components') \n AND \n link LIKE 'index.php?option=" . S2Paths::get('jreviews', 'S2_CMSCOMP') . "%'\n "; } else { $query = "\n UPDATE \n `#__menu` \n SET \n componentid = {$id} \n WHERE \n type IN ('component','components') \n AND \n link = 'index.php?option=" . S2Paths::get('jreviews', 'S2_CMSCOMP') . "'\n "; } $this->_db->setQuery($query); $this->_db->query(); } # Update version number in the database $this->Config->version = $new_version; $this->Config->store(); $action['plugin_install'] = $this->_installPlugin(); # Create image upload and thumbnail folders if (!is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS)) { $Config = new JConfig(); if (isset($Config->ftp_enable) && $Config->ftp_enable) { // set up basic connection $conn_id = ftp_connect($Config->ftp_host, $Config->ftp_port); // login with username and password $login_result = ftp_login($conn_id, $Config->ftp_user, $Config->ftp_pass); ftp_chdir($conn_id, $Config->ftp_root); ftp_mkdir($conn_id, _JR_PATH_IMAGES . 'jreviews'); ftp_mkdir($conn_id, _JR_PATH_IMAGES . 'jreviews' . DS . 'tn'); ftp_close($conn_id); @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'index.html'); @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS . 'index.html'); } } if (!is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS)) { $result = mkdir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS, 0755); if (!$result) { $action['thumbnail_dir'] = false; } else { @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'index.html'); $result = mkdir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn', 0755); if (!$result) { $action['thumbnail_dir'] = false; } else { @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS . 'index.html'); } } } if (!is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS)) { $result = mkdir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn', 0755); if (!$result) { $action['thumbnail_dir'] = false; } else { @copy(PATH_ROOT . _JR_PATH_IMAGES . 'index.html', PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS . 'index.html'); } } if (is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS) && is_dir(PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS . 'tn' . DS)) { $action['thumbnail_dir'] = true; } # Ensure that all field group names are slugs $query = "\n SELECT \n groupid, name\n FROM\n #__jreviews_groups\n "; $this->_db->setQuery($query); $groups = $this->_db->loadAssocList(); if (!empty($groups)) { foreach ($groups as $group) { if (strpos($group['name'], ' ') !== false) { $name = cmsFramework::StringTransliterate($group['name']) . $group['groupid']; $query = "\n UPDATE\n #__jreviews_groups\n SET \n name = " . $this->quote($name) . "\n WHERE\n groupid = " . $group['groupid']; $this->_db->setQuery($query); $this->_db->query(); } } } # Clear data and core caches clearCache('', '__data'); clearCache('', 'core'); //var_dump($action); if (Sanitize::getString($this->params, 'task') == 'upgrade') { $response = array('error' => false, 'html' => ''); // {"db_install":true,"plugin_install":true,"thumbnail_dir":true} if (!$action['db_install']) { $response['error'] = true; $response['html'] = '<div style="color:red>There was a problem upgrading the database</div>'; } if (!$action['plugin_install']) { $response['error'] = true; $response['html'] .= '<div style="color:red>There was a problem upgrading the JReviews plugin</div>'; } return json_encode($response); } $this->set(array('action' => $action)); }
function beforeFilter() { # Init Access if (isset($this->Access)) { $this->Access->init($this->Config); } # 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(); # Set Theme $this->viewTheme = $this->Config->template; $this->viewImages = S2Paths::get('jreviews', 'S2_THEMES_URL') . 'default' . _DS . 'theme_images' . _DS; # Set template type for lists and template suffix $this->__initTemplating(); # 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); } else { $this->limit = Sanitize::getInt($this->params, '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; } # Add global javascript variables if (!defined('MVC_GLOBAL_JS_VARS') && !$this->ajaxRequest && $this->action != '_save') { cmsFramework::addScript('<script type="text/javascript"> //<![CDATA[ var xajaxUri = "' . getXajaxUri() . '"; //]]> </script>'); cmsFramework::addScript('<script type="text/javascript"> //<![CDATA[ var s2AjaxUri = "' . getAjaxUri() . '"; //]]> </script>'); cmsFramework::addScript('<script type="text/javascript"> var jr_translate= new Array(); jr_translate["cancel"] = "' . __t("Cancel", true) . '"; jr_translate["submit"] = "' . __t("Submit", true) . '"; </script>'); $javascriptcode = '<script type="text/javascript">%s</script>'; # Set calendar image cmsFramework::addScript(sprintf($javascriptcode, 'var datePickerImage = "' . $this->viewImages . 'calendar.gif";')); # Find and set one public Itemid to use for Ajax requests $menu_id = ''; if (!defined('MVC_FRAMEWORK_ADMIN')) { App::import('Model', 'menu', 'jreviews'); $MenuModel = RegisterClass::getInstance('MenuModel'); $menu_id = $MenuModel->get('jreviews_public'); $menu_id = $menu_id != '' ? $menu_id : 99999; $this->set('public_menu_id', $menu_id); } # Set JReviews public menu cmsFramework::addScript(sprintf($javascriptcode, 'var jr_publicMenu = ' . $menu_id . ';')); define('MVC_GLOBAL_JS_VARS', 1); } # Init plugin system $this->_initPlugins(); }