function index() { $this->EverywhereAfterFind = true; // Triggers the afterFind in the Observer Model $module_id = Sanitize::getVar($this->params, 'module_id', Sanitize::getVar($this->data, 'module_id')); 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); $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5); $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10)); if (!$user_id && !$this->_user->id) { cmsFramework::noAccess(); return; } $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_ids = Sanitize::getString($this->params['module'], 'criteria'); } else { $dir_id = null; $section_id = null; $criteria_ids = null; } // This parameter determines the module mode $sort = Sanitize::getString($this->params['module'], 'reviews_order'); # Remove unnecessary fields from model query // $this->Review->modelUnbind(); !empty($extension) and $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.catid > 0')); if ($this->cmsVersion == CMS_JOOMLA15) { // $conditions[] = 'Section.access <= ' . $this->Access->getAccessId(); $conditions[] = 'Category.access <= ' . $this->Access->getAccessId(); $conditions[] = 'Listing.access <= ' . $this->Access->getAccessId(); } else { $conditions[] = 'Category.access IN (' . $this->Access->getAccessLevels() . ')'; $conditions[] = 'Listing.access IN ( ' . $this->Access->getAccessLevels() . ')'; } $conditions[] = $this->Access->canEditListing() ? 'Listing.state >= 0' : 'Listing.state = 1'; !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . $dir_id . ')'; !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . $section_id . ')'; if (!empty($cat_id)) { $conditions[] = $this->cmsVersion == CMS_JOOMLA15 ? 'Listing.catid IN (' . $cat_id . ')' : 'ParentCategory.id IN (' . $cat_id . ')'; } else { unset($this->Listing->joins['ParentCategory']); } } 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 (' . $cat_id . ')'; } } elseif ($cat_id) { $conditions[] = 'JreviewsCategory.id IN (' . $cat_id . ')'; } } !empty($listing_id) and $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': srand((double) microtime() * 1000000); $this->params['rand'] = rand(); $order[] = 'RAND(' . $this->params['rand'] . ')'; break; default: $order[] = $this->Review->processSorting('rdate'); break; } $queryData = array('fields' => array(), 'joins' => $joins, 'conditions' => $conditions, 'order' => $order, 'limit' => $total); # 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); $count = count($reviews); # Send variables to view template $this->set(array('module_id' => $module_id, 'reviews' => $reviews, 'total' => $count, 'limit' => $limit)); $this->_completeModuleParamsArray(); $page = $this->ajaxRequest && empty($reviews) ? '' : $this->render('community_plugins', 'community_myreviews'); return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page; }
function edit() { $this->autoRender = false; $listing_id = Sanitize::getInt($this->params, 'id'); $sections = array(); $categories = array(); Configure::write('ListingEdit', true); // Read in Fields model for PaidListings integration $listing = $this->Listing->findRow(array('fields' => array('Listing.metakey AS `Listing.metakey`', 'Listing.metadesc AS `Listing.metadesc`'), 'conditions' => 'Listing.id = ' . $listing_id)); # Override global configuration isset($listing['ListingType']) and $this->Config->override($listing['ListingType']['config']); if (!$this->Access->canEditListing($listing['Listing']['user_id'])) { cmsFramework::noAccess(); $this->autoRender = false; return; } # Get listing custom fields $listing_fields = $this->Field->getFieldsArrayNew($listing['Criteria']['criteria_id'], 'listing', $listing); // Editors and above have access to the category/section editing functionality $specialAccess = in_array($this->Access->gid, array(20, 21, 23, 24, 25)); // Show section/category lists if user is editor or above. if ($specialAccess) { // Limit sections/categories based on criteriaid of item being edited $query = "SELECT id FROM #__jreviews_categories" . "\n WHERE criteriaid = '{$listing['Criteria']['criteria_id']}' AND `option` = 'com_content'"; $this->_db->setQuery($query); $catids = implode(",", $this->_db->loadResultArray()); $sections = $this->Section->getList($catids); $categories = $this->Category->getList($listing['Listing']['section_id'], $catids); } // Needed to preserve line breaks when not using wysiwyg editor if (!$this->Access->loadWysiwygEditor()) { $listing['Listing']['summary'] = $listing['Listing']['summary']; $listing['Listing']['description '] = $listing['Listing']['description']; } $image_manager = ''; $image_count = count($listing['Listing']['images']); // Check if image limit is enforced and modify the number of image fields shown based on current image account. if ($this->Config->content_images_total_limit) { $this->Config->content_images = $this->Config->content_images - $image_count; } $this->set(array('submit_step' => array(1, 2), 'User' => $this->_user, 'Access' => $this->Access, 'listing' => $listing, 'sections' => $sections, 'categories' => $categories, 'listing_fields' => $listing_fields)); return $this->render('listings', 'create'); }
function edit() { $this->autoRender = false; $listing_id = Sanitize::getInt($this->params, 'id'); $sections = array(); $categories = array(); Configure::write('ListingEdit', true); // Read in Fields model for PaidListings integration $listing = $this->Listing->findRow(array('fields' => array('Listing.metakey AS `Listing.metakey`', 'Listing.metadesc AS `Listing.metadesc`'), 'conditions' => 'Listing.id = ' . $listing_id)); # Override global configuration isset($listing['ListingType']) and $this->Config->override($listing['ListingType']['config']); # Set the theme suffix $this->Theming->setSuffix(array('cat_id' => $listing['Category']['cat_id'])); if (!$this->Access->canEditListing($listing['Listing']['user_id'])) { cmsFramework::noAccess(); $this->autoRender = false; return; } # Get listing custom fields $listing_fields = $this->Field->getFieldsArrayNew($listing['Criteria']['criteria_id'], 'listing', $listing); // Show section/category lists if user is editor or above. if ($this->cmsVersion == CMS_JOOMLA15 && $this->Access->isEditor()) { // Limit sections/categories based on criteriaid of item being edited $query = "SELECT id FROM #__jreviews_categories" . "\n WHERE criteriaid = '{$listing['Criteria']['criteria_id']}' AND `option` = 'com_content'"; $this->_db->setQuery($query); $catids = implode(",", $this->_db->loadResultArray()); $sections = $this->Section->getList($catids); $categories = $this->Category->getList($listing['Listing']['section_id'], $catids); } elseif ($this->Access->isEditor() && Sanitize::getInt($listing['Criteria'], 'criteria_id')) { $categories = $this->Category->getCategoryList(array('disabled' => true, 'type_id' => array(0, $listing['Criteria']['criteria_id']), 'listing_type' => true)); if (!empty($categories)) { // Remove categories without submit access foreach ($categories as $key => $row) { $overrides = json_decode($row->config, true); if (!$this->Access->canAddListing($overrides['addnewaccess'])) { unset($categories[$key]); } } } } // Needed to preserve line breaks when not using wysiwyg editor if (!$this->Access->loadWysiwygEditor()) { $listing['Listing']['summary'] = $listing['Listing']['summary']; $listing['Listing']['description '] = $listing['Listing']['description']; } $image_manager = ''; $image_count = count($listing['Listing']['images']); // Check if image limit is enforced and modify the number of image fields shown based on current image account. if ($this->Config->content_images_total_limit) { $this->Config->content_images = $this->Config->content_images - $image_count; } $this->set(array('submit_step' => array(1, 2), 'User' => $this->_user, 'Access' => $this->Access, 'listing' => $listing, 'sections' => $sections, 'categories' => $categories, 'listing_fields' => $listing_fields, 'formTokenKeys' => $this->formTokenKeys)); return $this->render('listings', 'create'); }
function myreviews($params) { if ($this->_user->id === 0) { $this->cacheAction = Configure::read('Cache.expires'); } $page = array(); // Set layout $this->layout = 'reviews'; $this->autoRender = false; // Triggers the afterFind in the Observer Model $this->EverywhereAfterFind = true; $user_id = Sanitize::getInt($this->params, 'user'); if (!$user_id && !$this->_user->id) { echo cmsFramework::noAccess(); $this->autoRender = false; return; } if (!$user_id) { $user_id = $this->_user->id; } $queryData = array('conditions' => array('Review.userid= ' . $user_id, 'Review.published = 1'), 'fields' => array('Review.mode AS `Review.extension`'), 'offset' => $this->offset, 'limit' => $this->limit, 'order' => array('Review.created DESC')); # Don't run it here because it's run in the Everywhere Observer Component $this->Review->runProcessRatings = false; $reviews = $this->Review->findAll($queryData); if (empty($reviews)) { return __t("No reviews were found.", true); } $count = $this->Review->findCount($queryData); $review = current($reviews); App::import('Helper', 'community', 'jreviews'); $Community = RegisterClass::getInstance('CommunityHelper'); $Community->Config =& $this->Config; $page['title'] = $page['description'] = sprintf(__t("Reviews written by %s", true), $Community->screenName($review, false)); $this->set(array('Access' => $this->Access, 'User' => $this->_user, 'reviews' => $reviews, 'pagination' => array('total' => $count, 'offset' => ($this->page - 1) * $this->limit), 'page' => $page)); return $this->render('reviews', 'reviews'); }
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 listings() { $this->name = 'categories'; // Required for assets helper if ($this->_user->id === 0 && $this->action != 'search') { $this->cacheAction = Configure::read('Cache.expires'); } $this->autoRender = false; $action = Sanitize::paranoid($this->action); $dir_id = str_replace(array('_', ' '), array(',', ''), Sanitize::getString($this->params, 'dir')); $section_id = Sanitize::getString($this->params, 'section'); $cat_id = Sanitize::getString($this->params, 'cat'); $criteria_id = Sanitize::getString($this->params, 'criteria'); $user_id = Sanitize::getInt($this->params, 'user', $this->_user->id); $index = Sanitize::getString($this->params, 'index'); $sort = Sanitize::getString($this->params, 'order', Sanitize::getString($this->Config, 'list_order_field')); $sort == '' and $sort = Sanitize::getString($this->Config, 'list_order_default'); $menu_id = Sanitize::getInt($this->params, 'menu', Sanitize::getString($this->params, 'Itemid')); // Avoid running the listing query if in section page and listings disabled $query_listings = $this->action != 'section' || $this->action == 'section' && $this->Config->list_show_sectionlist; $listings = array(); $count = 0; switch ($action) { case 'section': !$section_id and $adminmsg[] = "Admin: You need to specify a valid section id in the menu parameters."; break; case 'category': if (!$cat_id) { $adminmsg[] = "Admin: You need to specify a valid category id in the menu parameters."; } else { // Find directory and section id $category = $this->Category->findRow(array('conditions' => array('Category.id = ' . $cat_id))); if ($category) { $section_id = $this->params['section'] = $category['Category']['section_id']; $dir_id = $this->params['dir'] = $category['Category']['dir_id']; # Override global configuration isset($category['ListingType']) and $this->Config->override($category['ListingType']['config']); $sort = Sanitize::getString($this->params, 'order', Sanitize::getString($this->Config, 'list_order_field')); $sort == '' and $sort = Sanitize::getString($this->Config, 'list_order_default'); } } break; case 'favorites': if (!$user_id && !$this->_user->id) { cmsFramework::noAccess(); return; } break; } if (isset($adminmsg) && !empty($adminmsg)) { echo implode("<br />", $adminmsg); return; } # Get section and category database information if (in_array($action, array('section', 'category'))) { $fields = array(); # Get all categories for page if ($this->Config->dir_cat_num_entries || $this->Config->dir_category_hide_empty) { $fields = array(' (SELECT count(*) FROM #__content AS Listing INNER JOIN #__jreviews_categories AS JreviewsCategory ON JreviewsCategory.id = Listing.catid AND JreviewsCategory.`option` = "com_content" WHERE Listing.sectionid = ' . $section_id . ' AND Listing.catid = Category.id AND Listing.state = 1 AND Listing.access <= ' . $this->_user->gid . ' AND ( Listing.publish_up = "' . NULL_DATE . '" OR Listing.publish_up <= "' . _CURRENT_SERVER_TIME . '" ) AND ( Listing.publish_down = "' . NULL_DATE . '" OR Listing.publish_down >= "' . _CURRENT_SERVER_TIME . '" ) ) AS `Category.listing_count` '); } $categories = $this->Category->findAll(array('fields' => $fields, 'conditions' => array('Category.section = ' . (int) $section_id, 'Category.published = 1'), 'order' => $this->Config->dir_category_order ? 'Category.title ASC' : 'Category.ordering ASC')); $category_tmp = current($categories); $dir_id = $category_tmp['Category']['dir_id']; $section = $this->Section->findRow(array('fields' => array((int) $dir_id . ' AS `Section.dir_id`'), 'conditions' => array('Section.id = ' . (int) $section_id))); } if (isset($section) && !empty($section) && ($section['Section']['access'] > $this->_user->gid || !$section['Section']['published']) || $this->action == 'category' && isset($category) && !empty($category) && (!$category['Category']['published'] || $category['Category']['access'] > $this->_user->gid)) { cmsFramework::noAccess(); return; } # Remove unnecessary fields from model query $this->Listing->modelUnbind('Listing.fulltext AS `Listing.description`'); $conditions = array(); $joins = array(); # Get listings # Modify and perform database query based on lisPage type if ($action == 'section' && $this->Config->list_show_sectionlist || $action != 'section') { // Build where statement switch ($action) { case 'alphaindex': // $index = isset($index{0}) ? $index{0} : ''; $conditions[] = $index == '0' ? 'Listing.title REGEXP "^[0-9]"' : 'Listing.title LIKE ' . $this->quote($index . '%'); break; case 'category': # Shows only links users can access $conditions[] = $category['Category']['access'] . ' <= ' . $this->_user->gid; break; case 'mylistings': if (!$user_id) { echo cmsFramework::noAccess(); $this->autoRender = false; return; } $conditions[] = 'Listing.created_by = ' . $user_id; break; case 'section': break; case 'favorites': if (!$user_id) { echo cmsFramework::noAccess(); $this->autoRender = false; return; } $joins[] = 'INNER JOIN #__jreviews_favorites AS Favorite ON Listing.id = Favorite.content_id AND Favorite.user_id = ' . $user_id; break; default: break; } $section_id = cleanIntegerCommaList($section_id); $cat_id = cleanIntegerCommaList($cat_id); $dir_id = cleanIntegerCommaList($dir_id); $criteria_id = cleanIntegerCommaList($criteria_id); $cat_id != '' and $conditions[] = 'Listing.catid IN (' . $cat_id . ')'; $cat_id == '' and $section_id != '' and $conditions[] = 'Listing.sectionid IN (' . $section_id . ')'; $cat_id == '' and $dir_id != '' and $conditions[] = 'JreviewsCategory.dirid IN (' . $dir_id . ')'; $cat_id == '' and $criteria_id != '' and $conditions[] = 'JreviewsCategory.criteriaid IN (' . $criteria_id . ')'; if ($this->action == 'mylistings' && $user_id == $this->_user->id || $this->Access->isPublisher()) { $conditions[] = 'Listing.state >= 0'; } else { $conditions[] = 'Listing.state = 1'; $conditions[] = '( Listing.publish_up = "' . NULL_DATE . '" OR Listing.publish_up <= "' . _CURRENT_SERVER_TIME . '" )'; $conditions[] = '( Listing.publish_down = "' . NULL_DATE . '" OR Listing.publish_down >= "' . _CURRENT_SERVER_TIME . '" )'; } # Shows only links users can access $conditions[] = 'Listing.access <= ' . $this->_user->gid; $queryData = array('joins' => $joins, 'conditions' => $conditions, 'limit' => $this->limit, 'offset' => $this->offset); # Modify query for correct ordering. Change FIELDS, ORDER BY and HAVING BY directly in Listing Model variables $this->Listing->processSorting($action, $sort); // This is used in Listings model to know whether this is a list page to remove the plugin tags $this->Listing->controller = 'categories'; // Check if review scope checked in advancd search $scope = explode('_', Sanitize::getString($this->params, 'scope')); if ($this->action == 'search' && in_array('reviews', $scope)) { $queryData['joins'][] = "LEFT JOIN #__jreviews_comments AS Review ON Listing.id = Review.pid AND Review.published = 1 AND Review.mode = 'com_content'"; $queryData['group'][] = "Listing.id"; // Group By required due to one to many relationship between listings => reviews table } $query_listings and $listings = $this->Listing->findAll($queryData); # If only one result then redirect to it if ($this->Config->search_one_result && count($listings) == 1 && $this->action == 'search' && $this->page == 1) { $listing = array_shift($listings); $url = cmsFramework::makeAbsUrl($listing['Listing']['url'], array('sef' => true)); cmsFramework::redirect($url); } # Get the listing count if (in_array($action, array('section', 'category'))) { unset($queryData['joins']); $this->Listing->joins = array("LEFT JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.id AND Totals.extension = 'com_content'", "LEFT JOIN #__jreviews_content AS Field ON Field.contentid = Listing.id", "INNER JOIN #__jreviews_categories AS JreviewsCategory ON Listing.catid = JreviewsCategory.id AND JreviewsCategory.`option` = 'com_content'", "LEFT JOIN #__jreviews_directories AS Directory ON JreviewsCategory.dirid = Directory.id"); } elseif ($action != 'favorites') { unset($queryData['joins']); $this->Listing->joins = array("LEFT JOIN #__jreviews_listing_totals AS Totals ON Totals.listing_id = Listing.id AND Totals.extension = 'com_content'", "LEFT JOIN #__jreviews_content AS Field ON Field.contentid = Listing.id", "INNER JOIN #__jreviews_categories AS JreviewsCategory ON Listing.catid = JreviewsCategory.id AND JreviewsCategory.`option` = 'com_content'", "LEFT JOIN #__jreviews_directories AS Directory ON JreviewsCategory.dirid = Directory.id"); if ($this->action == 'search' && in_array('reviews', $scope)) { $queryData['joins'][] = "LEFT JOIN #__jreviews_comments AS Review ON Listing.id = Review.pid AND Review.published = 1 AND Review.mode = 'com_content'"; } } // Need to add user table join for author searches if (isset($this->params['author'])) { $queryData['joins'][] = "LEFT JOIN #__users AS User ON User.id = Listing.created_by"; } if ($query_listings && !isset($this->Listing->count)) { $count = $this->Listing->findCount($queryData, $this->action == 'search' && in_array('reviews', $scope) ? 'DISTINCT Listing.id' : '*'); } else { $count = $this->Listing->count; } if (Sanitize::getInt($this->data, 'total_special') && Sanitize::getInt($this->data, 'total_special') < $count) { $count = Sanitize::getInt($this->data, 'total_special'); } } # Get directory info for breadcrumb if dir id is a url parameter $directory = array(); if (is_numeric($dir_id)) { $directory = $this->Directory->findRow(array('fields' => array('Directory.id AS `Directory.dir_id`', 'Directory.title AS `Directory.slug`', 'Directory.desc AS `Directory.title`'), 'conditions' => array('Directory.id = ' . $dir_id))); } /****************************************************************** * Process page title and description *******************************************************************/ $name_choice = $this->Config->name_choice == 'alias' ? 'username' : 'name'; $page['show_title'] = 1; $page['show_description'] = 1; switch ($action) { case 'section': $menuParams = $this->Menu->getMenuParams($menu_id); $page = $section['Section']; $page['title'] = trim(Sanitize::getString($menuParams, 'title')) != '' ? Sanitize::getString($menuParams, 'title') : $section['Section']['title']; $page['show_title'] = Sanitize::getInt($this->data, 'dirtitle', 1); $page['show_description'] = 1; break; case 'category': $menuParams = $this->Menu->getMenuParams($menu_id); $page = $category['Category']; $page['title'] = trim(Sanitize::getString($menuParams, 'title')) != '' ? Sanitize::getString($menuParams, 'title') : $category['Category']['title']; $page['show_title'] = Sanitize::getInt($this->data, 'dirtitle', 1); $page['show_description'] = 1; break; case 'alphaindex': $title = isset($directory['Directory']) ? Sanitize::getString($directory['Directory'], 'title', '') : ''; $page['title'] = $title != '' ? $title . ' - ' . ($index == '0' ? '0-9' : $index) : ($index == '0' ? '0-9' : $index); break; case 'mylistings': if ($user_id > 0) { $user_name = $this->User->findOne(array('fields' => array('User.' . $name_choice . ' AS `User.name`'), 'conditions' => array('User.id = ' . $user_id))); } elseif ($this->_user->id > 0) { $user_name = $this->_user->{$name_choice}; } $page['title'] = sprintf(__t("Listings by %s", true), $user_name); break; case 'favorites': // Not running from CB Plugin so we change the page title if (!isset($this->Config->in_cb)) { if ($user_id > 0) { $user_name = $this->User->findOne(array('fields' => array('User.' . $name_choice . ' AS `User.name`'), 'conditions' => array('User.id = ' . $user_id))); } elseif ($this->_user->id > 0) { $user_name = $this->_user->{$name_choice}; } $page['title'] = sprintf(__t("Favorites by %s", true), $user_name); } break; case 'list': case 'search': $this->__seo_fields($page); break; case 'featured': case 'latest': case 'mostreviews': case 'popular': case 'toprated': case 'topratededitor': $menuParams = $this->Menu->getMenuParams($menu_id); $page['show_title'] = Sanitize::getInt($menuParams, 'dirtitle'); $page['title'] = Sanitize::getString($menuParams, 'title'); if (!$page['title'] && isset($this->Menu->menues[$menu_id])) { $page['title'] = $this->Menu->menues[$menu_id]->name; } break; default: $page['title'] = $this->Menu->getMenuName($menu_id); break; } /****************************************************************** * Generate SEO titles for re-ordered pages (most reviews, top user rated, etc.) *******************************************************************/ # Category ids to be used for ordering list $cat_ids = array(); if (in_array($action, array('search', 'category'))) { $cat_ids = $cat_id; } elseif (!empty($categories)) { $cat_ids = implode(',', array_keys($categories)); } $field_order_array = $this->Field->getOrderList($cat_ids, 'listing', $this->action, array('section', 'category', 'search', 'alphaindex')); isset($page['title']) and $page['title_seo'] = $page['title']; if (($this->action != 'search' || Sanitize::getVar($this->params, 'tag')) && isset($this->params['order']) && $sort != '') { App::import('helper', 'jreviews', 'jreviews'); $ordering_options = JreviewsHelper::orderingOptions(); $tmp_order = str_replace('rjr', 'jr', $sort); if (isset($ordering_options[$sort])) { $page['title_seo'] .= ' ' . sprintf(__t("ordered by %s", true), mb_strtolower($ordering_options[$sort], 'UTF-8')); } elseif (isset($field_order_array[$tmp_order])) { if ($order[0] == 'r') { $page['title_seo'] .= ' ' . sprintf(__t("ordered by %s desc", true), mb_strtolower($field_order_array[$tmp_order]['text'], 'UTF-8')); } else { $page['title_seo'] .= ' ' . sprintf(__t("ordered by %s", true), mb_strtolower($field_order_array[$sort]['text'], 'UTF-8')); } } } $this->params['order'] = $sort; // This is the param read in the views so we need to update it /****************************************************************** * Set view (theme) vars *******************************************************************/ $this->set(array('Config' => $this->Config, 'Access' => $this->Access, 'User' => $this->_user, 'subclass' => 'listing', 'page' => $page, 'directory' => $directory, 'section' => isset($section) ? $section : array(), 'category' => isset($category) ? $category : array(), 'categories' => isset($categories) ? $categories : array(), 'listings' => $listings, 'pagination' => array('total' => $count))); $query_listings and $this->set('order_list', $field_order_array); /****************************************************************** * RSS Feed: caches and displays feed when xml action param is present *******************************************************************/ $this->Feeds->saveFeed(PATH_ROOT . DS . 'cache' . DS . 'jreviewsfeed_' . md5($this->here . $this->_user->gid) . '.xml', 'listings'); echo $this->render('listings', 'listings_' . $this->tmpl_list); }
function mylistings() { // Required for ajax pagination to remember module settings $module_id = Sanitize::getString($this->params, 'module_id', Sanitize::getString($this->data, 'module_id')); $extension = 'com_content'; if (!Sanitize::getVar($this->params['module'], 'community')) { cmsFramework::noAccess(); return; } // Automagically load and initialize Everywhere Model App::import('Model', 'everywhere_' . $extension, 'jreviews'); $class_name = inflector::camelize('everywhere_' . $extension) . 'Model'; $this->Listing = new $class_name(); $this->Listing->_user = $this->_user; $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'); $user_id = Sanitize::getInt($this->params, 'user', $this->_user->id); $sort = Sanitize::getString($this->params['module'], 'listings_order'); $limit = Sanitize::getInt($this->params['module'], 'module_limit', 5); $total = min(50, Sanitize::getInt($this->params['module'], 'module_total', 10)); if (!$user_id && !$this->_user->id) { cmsFramework::noAccess(); return; } # Remove unnecessary fields from model query $this->Listing->modelUnbind('Listing.fulltext AS `Listing.description`'); $conditions = array(); $joins = array(); # Get listings $conditions[] = 'Listing.created_by = ' . (int) $user_id; # Set conditionals based on configuration parameters if ($extension == 'com_content') { // Only works for core articles !empty($dir_id) and $conditions[] = 'JreviewsCategory.dirid IN (' . $dir_id . ')'; !empty($section_id) and $conditions[] = 'Listing.sectionid IN (' . $section_id . ')'; if (!empty($cat_id)) { $conditions[] = $this->cmsVersion == CMS_JOOMLA15 ? 'Listing.catid IN (' . $cat_id . ')' : 'ParentCategory.id IN (' . $cat_id . ')'; } else { unset($this->Listing->joins['ParentCategory']); } } !empty($listing_id) and $conditions[] = "Listing.id IN ({$listing_id})"; if ($extension == 'com_content') { // Only works for core articles if ($this->Access->canEditListing()) { $conditions[] = 'Listing.state >= 0'; } else { $conditions[] = 'Listing.state = 1'; $conditions[] = '( Listing.publish_up = "' . NULL_DATE . '" OR Listing.publish_up <= "' . _CURRENT_SERVER_TIME . '" )'; $conditions[] = '( Listing.publish_down = "' . NULL_DATE . '" OR Listing.publish_down >= "' . _CURRENT_SERVER_TIME . '" )'; } //Shows only links users can access if ($this->cmsVersion == CMS_JOOMLA15) { // $conditions[] = 'Section.access <= ' . $this->Access->getAccessId(); $conditions[] = 'Category.access <= ' . $this->Access->getAccessId(); $conditions[] = 'Listing.access <= ' . $this->Access->getAccessId(); } else { $conditions[] = 'Category.access IN (' . $this->Access->getAccessLevels() . ')'; $conditions[] = 'Listing.access IN (' . $this->Access->getAccessLevels() . ')'; } } switch ($sort) { case 'random': srand((double) microtime() * 1000000); $this->params['rand'] = rand(); $this->Listing->order = array(); $order[] = "RAND({$this->params['rand']})"; break; default: $this->Listing->order = array(); $order[] = "Listing.{$this->Listing->dateKey} DESC"; break; } $queryData = array('joins' => $joins, 'conditions' => $conditions, 'order' => $order, 'limit' => $total); // This is used in Listings model to know whether this is a list page to remove the plugin tags $this->Listing->controller = 'categories'; // Add custom fields to listings $this->Listing->addFields = true; $listings = $this->Listing->findAll($queryData); $count = count($listings); # Send variables to view template $this->set(array('module_id' => $module_id, 'listings' => $listings, 'total' => $count, 'limit' => $limit)); $this->_completeModuleParamsArray(); $page = $this->ajaxRequest && empty($listings) ? '' : $this->render('community_plugins', 'community_mylistings'); return $this->ajaxRequest ? $this->ajaxResponse($page, false) : $page; }
function mylistings() { // Required for ajax pagination to remember module settings $Session = RegisterClass::getInstance('MvcSession'); $module_id = Sanitize::getString($this->params, 'module_id', Sanitize::getString($this->data, 'module_id')); $extension = 'com_content'; $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, $this->params, S2Paths::get('jreviews', 'S2_CMSCOMP')); } if (!Sanitize::getVar($this->params['module'], 'community')) { cmsFramework::noAccess(); return; } if ($this->_user->id === 0) { $this->cacheAction = Configure::read('Cache.expires'); } // Automagically load and initialize Everywhere Model App::import('Model', 'everywhere_' . $extension, 'jreviews'); $class_name = inflector::camelize('everywhere_' . $extension) . 'Model'; $this->Listing = new $class_name(); $this->Listing->_user = $this->_user; $action = Sanitize::paranoid($this->action); $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'); $user_id = Sanitize::getInt($this->params, 'user', $this->_user->id); $index = Sanitize::getString($this->params, 'index'); $sort = Sanitize::getString($this->params['module'], 'listings_order'); $menu_id = Sanitize::getInt($this->params, 'menu', Sanitize::getString($this->params, 'Itemid')); $listings = array(); $count = 0; if (!$user_id && !$this->_user->id) { cmsFramework::noAccess(); return; } # Remove unnecessary fields from model query $this->Listing->modelUnbind('Listing.fulltext AS `Listing.description`'); $conditions = array(); $joins = array(); # Get listings $conditions[] = 'Listing.created_by = ' . (int) $user_id; # Set conditionals based on configuration parameters if ($extension == 'com_content') { // Only works for core articles if ($dir_id) { $conditions[] = 'JreviewsCategory.dirid IN (' . $dir_id . ')'; } if ($section_id) { $conditions[] = 'Listing.sectionid IN (' . $section_id . ')'; } if ($cat_id) { $conditions[] = 'Listing.catid IN (' . $cat_id . ')'; } } if ($listing_id) { $conditions[] = "Listing.id IN ({$listing_id})"; } if ($extension == 'com_content') { // Only works for core articles if ($this->Access->canEditListing()) { $conditions[] = 'Listing.state >= 0'; } else { $conditions[] = 'Listing.state = 1'; $conditions[] = '( Listing.publish_up = "' . NULL_DATE . '" OR Listing.publish_up <= "' . _CURRENT_SERVER_TIME . '" )'; $conditions[] = '( Listing.publish_down = "' . NULL_DATE . '" OR Listing.publish_down >= "' . _CURRENT_SERVER_TIME . '" )'; } //Shows only links users can access $conditions[] = 'Listing.access <= ' . $this->_user->gid; $conditions[] = 'Listing.catid > 0'; } switch ($sort) { case 'random': $this->Listing->order = array(); $order[] = "RAND({$this->params['rand']})"; break; default: $this->Listing->order = array(); $order[] = "Listing.{$this->Listing->dateKey} DESC"; break; } $queryData = array('joins' => $joins, 'conditions' => $conditions, 'order' => $order, 'limit' => $this->module_limit, 'offset' => $this->module_offset); // This is used in Listings model to know whether this is a list page to remove the plugin tags $this->Listing->controller = 'categories'; // Add custom fields to listings $this->Listing->addFields = true; $listings = $this->Listing->findAll($queryData); $count = 0; if (!empty($listings)) { unset($queryData['order']); $count = $this->Listing->findCount($queryData, 'DISTINCT Listing.id'); if (Sanitize::getInt($this->data, 'total_special') && Sanitize::getInt($this->data, 'total_special') < $count) { $count = Sanitize::getInt($this->data, 'total_special'); } } # Send variables to view template $this->set(array('Access' => $this->Access, 'User' => $this->_user, 'listings' => $listings, 'total' => $count, 'module_id' => $module_id)); $page = $this->render('community_plugins', 'community_mylistings'); if ($this->ajaxRequest) { return $this->ajaxResponse($page, false); } else { return $page; } }