function save(&$data) { $isNew = Sanitize::getInt($data['FieldOption'], 'optionid') ? false : true; $field_id = Sanitize::getInt($data['FieldOption'], 'fieldid'); if ($isNew) { // Remove non alphanumeric characters from option value $data['FieldOption']['value'] = Sanitize::translate($data['FieldOption']['value']); $data['FieldOption']['value'] = str_replace($this->blackList, '', $data['FieldOption']['value']); $data['FieldOption']['value'] = str_replace($this->dashReplacements, '-', $data['FieldOption']['value']); $data['FieldOption']['value'] = preg_replace(array('/[-]+/'), array('-'), $data['FieldOption']['value']); $data['FieldOption']['value'] = mb_strtolower($data['FieldOption']['value'], 'UTF-8'); // If is new checks for duplicate value $query = "SELECT count(fieldid) FROM #__jreviews_fieldoptions WHERE fieldid = '{$field_id}' AND value = " . $this->_db->Quote($data['FieldOption']['value']); $this->_db->setQuery($query); if ($this->_db->loadResult()) { return 'duplicate'; } // Find last option $this->_db->setQuery("select max(ordering) FROM #__jreviews_fieldoptions WHERE fieldid = '" . $field_id . "'"); $max = $this->_db->loadResult(); if ($max > 0) { $data['FieldOption']['ordering'] = $max + 1; } else { $data['FieldOption']['ordering'] = 1; } } # store it in the db if (!$this->store($data)) { return 'db_error'; } return 'success'; }
function _addOption() { $this->autoRender = false; $this->autoLayout = false; $response = array(); $option = $this->data['FieldOption']['text'] = Sanitize::getString($this->data, 'text'); $value = $this->data['FieldOption']['value'] = Sanitize::stripAll($this->data, 'text'); $fieldid = $this->data['FieldOption']['fieldid'] = Sanitize::getInt($this->data, 'field_id'); $fieldName = Sanitize::getString($this->data, 'name'); // Begin validation if ($value == '') { $validation = __t("The field is empty.", true); $response[] = "jQuery('#jr_fieldOption{$fieldid}').siblings('.jr_loadingSmall').after('<span class=\"jr_validation\"> " . $validation . "</span>');"; return $this->ajaxResponse($response); } // Save $result = $this->FieldOption->save($this->data); switch ($result) { case 'success': // Begin update display $option = $this->data['FieldOption']['text']; $value = $this->data['FieldOption']['value']; $response = "\n jQuery('#{$fieldName}').addOption('{$value}','" . addslashes($option) . "');\n jQuery('#jr_fieldOption{$fieldid}').val(''); \n jQuery('#submitButton{$fieldid}').removeAttr('disabled');\n "; return $this->ajaxResponse($response); case 'duplicate': $validation = sprintf(__t("%s already exists", true), $value); break; case 'db_error': $validation = s2Messages::submitErrorGeneric(); break; } $response[] = "jQuery('#{$fieldName}').selectOptions('" . addslashes($option) . "');"; $response[] = "jQuery('#jr_fieldOption{$fieldid}').siblings('.jr_loadingSmall').after('<span class=\"jr_validation\"> " . $validation . "</span>');"; return $this->ajaxResponse($response); }
function overallRatings($listing, $page, $type = '') { $editor_reviews = $this->Config->getOverride('author_review', $listing['ListingType']['config']); $user_reviews = $this->Config->getOverride('user_reviews', $listing['ListingType']['config']); if (!($listing['Criteria']['state'] == 1 && ($editor_reviews || $user_reviews))) { return ''; } $ratings = '<div class="overall_ratings">'; // editor ratings if ($editor_reviews && $type != 'user') { $editor_rating = Sanitize::getVar($listing['Review'], 'editor_rating'); $editor_rating_count = Sanitize::getInt($listing['Review'], 'editor_rating_count'); $rating_stars = $this->drawStars($editor_rating, $this->Config->rating_scale, 'editor'); $rating_value = $this->round($editor_rating, $this->Config->rating_scale); $rating_count = $editor_rating_count > 1 ? ' (' . $editor_rating_count . ')' : ''; $ratings .= '<div class="overall_editor" title="' . __t("Editor rating", true) . '">'; $ratings .= '<span class="rating_label jrIcon jrIconEditorReview">' . __t("Editor rating", true) . '</span>'; $ratings .= '<div class="rating_stars">' . $rating_stars . '</div>'; $ratings .= '<span class="rating_value">' . $rating_value . $rating_count . '</span>'; $ratings .= '</div>'; } // user ratings if ($page == 'content' && $user_reviews && $type != 'editor') { $user_rating = Sanitize::getVar($listing['Review'], 'user_rating'); $rating_stars = $this->drawStars($user_rating, $this->Config->rating_scale, 'user'); $rating_value = $this->round($user_rating, $this->Config->rating_scale); $rating_count = Sanitize::getInt($listing['Review'], 'user_rating_count'); $review_s = ""; if ($rating_count > 1) { $review_s = "reviews"; } else { $review_s = "review"; } $ratings .= '<div class="overall_user rating" title="' . __t("User rating", true) . '">'; $ratings .= '<span class="rating_label jrIcon jrIconUserReviews">' . __t("User rating", true) . '</span>'; $ratings .= '<div class="rating_stars">' . $rating_stars . '</div>'; $ratings .= '<span class="rating_value average">' . $rating_value . '<span class="best"><span class="value-title" title="' . $this->Config->rating_scale . '"></span></span> (<span class="count">' . $rating_count . '</span> ' . $review_s . ')</span>'; $ratings .= '</div>'; } else { if ($page == 'list' && $user_reviews && $this->Config->list_show_user_rating && $type != 'editor') { $user_rating = Sanitize::getVar($listing['Review'], 'user_rating'); $rating_stars = $this->drawStars($user_rating, $this->Config->rating_scale, 'user'); $rating_value = $this->round($user_rating, $this->Config->rating_scale); $rating_count = Sanitize::getInt($listing['Review'], 'user_rating_count'); $review_s = ""; if ($rating_count > 1) { $review_s = "reviews"; } else { $review_s = "review"; } $ratings .= '<div class="overall_user" title="' . __t("User rating", true) . '">'; $ratings .= '<span class="rating_label jrIcon jrIconUserReviews">' . __t("User rating", true) . '</span>'; $ratings .= '<div class="rating_stars">' . $rating_stars . '</div>'; $ratings .= '<span class="rating_value">' . $rating_value . ' (<span class="count">' . $rating_count . '</span> ' . $review_s . ')</span>'; $ratings .= '</div>'; } } $ratings .= '</div>'; return $ratings; }
/** * Method used in Everywhere extensions detail pages * * @return array with html output, listing, reviews, rating summary */ function index() { $listing_id = Sanitize::getInt($this->data, 'listing_id'); $listing = $this->Listing->findRow(array('conditions' => "Listing.{$this->Listing->realKey} = {$listing_id}")); if (!is_array($listing) || empty($listing)) { return false; } $listing['Criteria']['required'] = explode("\n", $listing['Criteria']['required']); $extension = isset($this->Listing->extension_alias) ? $this->Listing->extension_alias : $this->Listing->extension; $fields = array('Criteria.id AS `Criteria.criteria_id`', 'Criteria.criteria AS `Criteria.criteria`', 'Criteria.tooltips AS `Criteria.tooltips`', 'Criteria.weights AS `Criteria.weights`', 'Criteria.state AS `Criteria.state`', 'Criteria.required AS `Criteria.required`'); $conditions = array('Review.pid= ' . $listing_id, 'Review.author = 0', 'Review.published = 1', "Review.mode = " . $this->quote($extension), "JreviewsCategory.`option` = " . $this->quote($extension)); $this->limit = Sanitize::getInt($this->data, 'limit_special', $this->Config->user_limit); $queryData = array('fields' => $fields, 'conditions' => $conditions, 'offset' => 0, 'limit' => $this->limit, 'order' => array('Review.created DESC')); $reviews = $this->Review->findAll($queryData); // Remove unnecessary query parameters for findCount $this->Review->joins = array(); // Only need to query comments table unset($conditions[4]); // JreviewsCategory join above $queryData = array('conditions' => $conditions); $review_count = $this->Review->findCount($queryData); // prepare ratings_summary array $query = "\n SELECT\n user_rating, user_criteria_rating, user_rating_count, user_criteria_rating_count\n FROM\n #__jreviews_listing_totals\n WHERE\n listing_id = {$listing_id}\n AND extension = " . $this->quote($extension); $this->_db->setQuery($query); $totals = current($this->_db->loadAssocList()); $ratings_summary = array('Rating' => array('average_rating' => $totals['user_rating'], 'ratings' => explode(',', $totals['user_criteria_rating']), 'criteria_rating_count' => explode(',', $totals['user_criteria_rating_count'])), 'Criteria' => $listing['Criteria'], 'summary' => 1); $ratings_summary['Criteria']['required'] = $listing['Criteria']['required']; $review_fields = $this->review_fields = $this->Field->getFieldsArrayNew($listing['Criteria']['criteria_id'], 'review'); $security_code = ''; if ($this->Access->showCaptcha()) { $captcha = $this->Captcha->displayCode(); $security_code = $captcha['image']; } # Initialize review array and set Criteria and extension keys $review = $this->Review->init(); $review['Review']['extension'] = $extension; $review = array_merge($review, $ratings_summary); // Adds the missing required criteria array # check for duplicate reviews $this->_user->duplicate_review = false; // It's a guest so we only care about checking the IP address if this feature is not disabled and // server is not localhost if (!$this->_user->id) { if (!$this->Config->review_ipcheck_disable && $this->ipaddress != '127.0.0.1') { // Do the ip address check everywhere except in localhost $this->_user->duplicate_review = (bool) $this->Review->findCount(array('conditions' => array('Review.pid = ' . $listing_id, "Review.ipaddress = '{$this->ipaddress}'", "Review.mode = '{$extension}'", "Review.author = 0", "Review.published >= 0"))); } } else { if (!$this->Config->user_multiple_reviews) { $this->_user->duplicate_review = (bool) $this->Review->findCount(array('conditions' => array('Review.pid = ' . $listing_id, "(Review.userid = {$this->_user->id}" . ($this->ipaddress != '127.0.0.1' && !$this->Config->review_ipcheck_disable ? " OR Review.ipaddress = '{$this->ipaddress}') " : ')'), "Review.mode = '{$extension}'", "Review.author = 0", "Review.published >= 0"))); } } $this->set(array('Access' => $this->Access, 'User' => $this->_user, 'listing' => $listing, 'reviews' => $reviews, 'ratings_summary' => $ratings_summary, 'reviewType' => 'user', 'review_count' => $review_count, 'user_rating_count' => $totals['user_rating_count'], 'review_fields' => $review_fields, 'review' => $review, 'captcha' => $security_code)); if (!class_exists('RatingHelper')) { App::import('Helper', 'rating', 'jreviews'); } $Rating = ClassRegistry::getClass('RatingHelper'); $output = array('output' => $this->render($this->name, 'reviews'), 'summary' => $Rating->overallRatings($listing, 'content'), 'detailed_ratings' => $Rating->detailedRatings($review, 'user'), 'listing' => $listing, 'reviews' => $reviews, 'review_count' => $review_count, 'ratings' => $ratings_summary); return $output; }
function beforeFilter() { parent::beforeFilter(); if (Sanitize::getInt($this->data, 'OwnerReply')) { $this->review_id = Sanitize::getInt($this->data['OwnerReply'], 'id'); } else { $this->review_id = Sanitize::getInt($this->params, 'review_id'); } if (!$this->Config->owner_replies || $this->review_id == 0 || $this->_user->id == 0) { $this->denyAccess = true; return; } // Get the listing id and extension $this->_db->setQuery("\n SELECT \n Review.pid AS listing_id, Review.`mode` AS extension\n FROM \n #__jreviews_comments AS Review\n WHERE \n Review.id = " . $this->review_id); // Get listing owner id and check if it matches the current user if ($listing = current($this->_db->loadAssocList())) { // Automagically load and initialize Everywhere Model to check if user is listing owner App::import('Model', 'everywhere_' . $listing['extension'], 'jreviews'); $class_name = inflector::camelize('everywhere_' . $listing['extension']) . 'Model'; if (class_exists($class_name)) { $this->Listing = new $class_name(); $owner = $this->Listing->getListingOwner($listing['listing_id']); if ($this->_user->id != $owner['user_id']) { $this->denyAccess = true; return; } $this->data['Listing']['created_by'] = $owner['user_id']; // Used in the Activities component $this->data['Listing']['listing_id'] = $listing['listing_id']; // Used in the Activities component $this->data['Listing']['extension'] = $listing['extension']; // Used in the Activities component } } }
function _getMarkerTooltip() { $listing_id = Sanitize::getInt($this->params, 'listing_id'); $listing = $this->Listing->findRow(array('conditions' => array('Listing.id = ' . $listing_id))); $this->set('listing', $listing); return $this->render('geomaps', 'map_infowindow'); }
function getListingFavorites($listing_id, $user_id, $passedArgs) { $conditions = array(); $avatar = Sanitize::getInt($passedArgs['module'], 'avatar', 1); // Only show users with avatars $count = Sanitize::getInt($passedArgs['module'], 'module_limit', 5); $module_id = Sanitize::getInt($passedArgs, 'module_id'); $rand = Sanitize::getFloat($passedArgs, 'rand'); $fields = array('Community.' . $this->realKey . ' AS `User.user_id`', 'User.name AS `User.name`', 'User.username AS `User.username`'); if ($avatar) { $conditions[] = 'Community.thumb <> "components/com_community/assets/default_thumb.jpg"'; } if ($listing_id) { $conditions[] = 'Community.' . $this->realKey . ' in (SELECT user_id FROM #__jreviews_favorites WHERE content_id = ' . $listing_id . ')'; } $order = array('RAND(' . $rand . ')'); $joins = array('LEFT JOIN #__users AS User ON Community.' . $this->realKey . ' = User.id'); $profiles = $this->findAll(array('fields' => $fields, 'conditions' => $conditions, 'order' => $order, 'joins' => $joins)); if (Sanitize::getInt($passedArgs['module'], 'ajax_nav', 1)) { $fields = array('count(Community.' . $this->realKey . ')'); $group = array('Community.' . $this->realKey); $this->count = $this->findCount(array('fields' => $fields, 'conditions' => $conditions, 'group' => $group, 'joins' => $joins)); } else { $this->count = Sanitize::getInt($passedArgs['module'], 'module_limit', 5); } return $this->addProfileInfo($profiles, 'User', 'user_id'); }
function findChildOptions() { $response = array(); $childField = Sanitize::getString($this->data, 'childField'); $childSelected = Sanitize::getString($this->data, 'childSelected'); $parentValue = Sanitize::getString($this->data, 'parentValue'); $module_id = Sanitize::getInt($this->data, 'module_id'); if ($parentValue == '') { $ret = '<option value="">' . __t("Select", true, true) . '</option>'; $response[] = "jQuery(\"#{$childField}{$module_id}\").html('{$ret}').attr('disabled','disabled');"; return implode(' ', $response); } $query = " \r\n SELECT \r\n FieldOption.optionid, FieldOption.text, FieldOption.value\r\n FROM #__jreviews_fieldoptions AS FieldOption\r\n INNER JOIN #__jreviews_fields AS Field ON FieldOption.fieldid = Field.fieldid AND Field.name = '" . $childField . "'\r\n WHERE FieldOption.value LIKE '" . $parentValue . "-%'\r\n "; $this->_db->setQuery($query); $options = $this->_db->loadAssocList(); $ret = '<option value="">' . __t("Select", true, true) . '</option>'; foreach ($options as $option) { if ($childSelected != '' && $option['value'] == $childSelected) { $ret .= '<option selected="selected" value="' . $option['value'] . '">' . $option['text'] . '</option>'; } else { $ret .= '<option value="' . $option['value'] . '">' . $option['text'] . '</option>'; } } $response[] = "jQuery(\"#{$childField}{$module_id}\").html('{$ret}').removeAttr('disabled');"; return implode(' ', $response); }
function index($params) { $this->action = 'directory'; // Set view file # Read module params $dir_id = cleanIntegerCommaList(Sanitize::getString($this->params['module'], 'dir_ids')); $conditions = array(); $order = array(); $cat_id = ''; $section_id = ''; $directories = $this->Directory->getTree($dir_id, true); if ($menu_id = Sanitize::getInt($this->params, 'Itemid')) { $menuParams = $this->Menu->getMenuParams($menu_id); } # Category auto detect $ids = CommonController::_discoverIDs($this); extract($ids); if ($cat_id != '' && $section_id == '') { $cat_id = cleanIntegerCommaList($cat_id); $sql = "SELECT section FROM #__categories WHERE id IN (" . $cat_id . ")"; $this->_db->setQuery($sql); $section_id = $this->_db->loadResult(); } $this->set(array('directories' => $directories, 'cat_id' => is_numeric($cat_id) && $cat_id > 0 ? $cat_id : false, 'section_id' => $section_id)); return $this->render('modules', 'directories'); }
function index($params) { $this->action = 'directory'; // Trigger assets helper method if ($this->_user->id === 0) { $this->cacheAction = Configure::read('Cache.expires'); } $page = array('title' => '', 'show_title' => 0); $conditions = array(); $order = array(); if ($menu_id = Sanitize::getInt($this->params, 'Itemid')) { $menuParams = $this->Menu->getMenuParams($menu_id); $page['title'] = Sanitize::getString($menuParams, 'title'); $page['show_title'] = Sanitize::getString($menuParams, 'dirtitle', 0); } $override_keys = array('dir_show_alphaindex', 'dir_cat_images', 'dir_columns', 'dir_cat_num_entries', 'dir_category_hide_empty', 'dir_category_levels', 'dir_cat_format'); if (Sanitize::getBool($menuParams, 'dir_overrides')) { $overrides = array_intersect_key($menuParams, array_flip($override_keys)); $this->Config->override($overrides); } if ($this->cmsVersion == CMS_JOOMLA15) { $directories = $this->Directory->getTree(Sanitize::getString($this->params, 'dir')); } else { $directories = $this->Category->findTree(array('level' => $this->Config->dir_cat_format === 0 ? 2 : $this->Config->dir_category_levels, 'menu_id' => true, 'dir_id' => Sanitize::getString($this->params, 'dir'), 'pad_char' => '')); } $this->set(array('page' => $page, 'directories' => $directories)); return $this->render('directories', 'directory'); }
function index() { $module_id = Sanitize::getInt($this->params, 'module_id', Sanitize::getInt($this->data, 'module_id')); $this->viewSuffix = Sanitize::getString($this->params['module'], 'tmpl_suffix'); $cache_file = 'modules_totals_' . $module_id . '_' . md5(serialize($this->params['module'])); $page = $this->cached($cache_file); if ($page) { return $page; } // Initialize variables $extension = Sanitize::getString($this->params['module'], 'extension'); // Automagically load and initialize Everywhere Model App::import('Model', 'everywhere_' . $extension, 'jreviews'); $class_name = inflector::camelize('everywhere_' . $extension) . 'Model'; $conditions_reviews = array('Review.published = 1'); $extension == 'com_content' and $conditions_listings = array('Listing.state = 1'); $extension != '' and $conditions_reviews[] = "Review.mode = " . $this->quote($extension); if (class_exists($class_name)) { $this->Listing = new $class_name(); $this->Listing->_user = $this->_user; $listings = $this->Listing->findCount(array('conditions' => $conditions_listings), 'DISTINCT Listing.' . $this->Listing->realKey); $reviews = $this->Review->findCount(array('conditions' => $conditions_reviews), 'DISTINCT Review.id'); } # Send variables to view template $this->set(array('listing_count' => isset($listings) ? $listings : 0, 'review_count' => isset($reviews) ? $reviews : 0)); $page = $this->render('modules', 'totals'); # Save cached version $this->cacheView('modules', 'totals', $cache_file, $page); return $page; }
function index($params) { /* if($this->_user->id === 0) { $this->cacheAction = Configure::read('Cache.expires'); }*/ $this->action = 'directory'; // Set view file # Read module params $dir_id = isset($this->params['module']) ? cleanIntegerCommaList(Sanitize::getString($this->params['module'], 'dir_ids')) : ''; $conditions = array(); $order = array(); $cat_id = ''; $section_id = ''; if ($this->cmsVersion == CMS_JOOMLA15) { $directories = $this->Directory->getTree($dir_id, true); } else { $directories = $this->Category->findTree(array('level' => $this->Config->dir_category_levels, 'menu_id' => true, 'dir_id' => $dir_id, 'pad_char' => '')); } if ($menu_id = Sanitize::getInt($this->params, 'Itemid')) { $menuParams = $this->Menu->getMenuParams($menu_id); } # Category auto detect $ids = CommonController::_discoverIDs($this); extract($ids); if ($this->cmsVersion == CMS_JOOMLA15 && ($cat_id != '' && $section_id == '')) { $cat_id = cleanIntegerCommaList($cat_id); $sql = "SELECT section FROM #__categories WHERE id IN (" . $cat_id . ")"; $this->_db->setQuery($sql); $section_id = $this->_db->loadResult(); } $this->set(array('directories' => $directories, 'dir_id' => $dir_id, 'cat_id' => is_numeric($cat_id) && $cat_id > 0 ? $cat_id : false, 'section_id' => $section_id)); return $this->render('modules', 'directories'); }
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 reviews() { $access = $this->cmsVersion == CMS_JOOMLA15 ? $this->Access->getAccessId() : $this->Access->getAccessLevels(); $feed_filename = PATH_ROOT . 'cache' . DS . 'jreviewsfeed_' . md5($access . $this->here) . '.xml'; $this->Feeds->useCached($feed_filename, 'reviews'); $extension = Sanitize::getString($this->params, 'extension', 'com_content'); $cat_id = Sanitize::getInt($this->params, 'cat'); $section_id = Sanitize::getInt($this->params, 'section'); $dir_id = Sanitize::getInt($this->params, 'dir'); $listing_id = Sanitize::getInt($this->params, 'id'); $this->encoding = cmsFramework::getCharset(); $feedPage = null; $this->EverywhereAfterFind = true; // Triggers the afterFind in the Observer Model $this->limit = $this->Config->rss_limit; $rss = array('title' => $this->Config->rss_title, 'link' => WWW_ROOT, 'description' => $this->Config->rss_description, 'image_url' => WWW_ROOT . "images/stories/" . $this->Config->rss_image, 'image_link' => WWW_ROOT); $queryData = array('conditions' => array('Review.published = 1', "Review.mode = '{$extension}'"), 'fields' => array('Review.mode AS `Review.extension`'), 'limit' => $this->limit, 'order' => array('Review.created DESC')); if ($extension == 'com_content') { $queryData['conditions'][] = 'Listing.state = 1'; $queryData['conditions'][] = '( Listing.publish_up = "' . NULL_DATE . '" OR Listing.publish_up <= "' . _CURRENT_SERVER_TIME . '" )'; $queryData['conditions'][] = '( Listing.publish_down = "' . NULL_DATE . '" OR Listing.publish_down >= "' . _CURRENT_SERVER_TIME . '" )'; # Shows only links users can access if ($this->cmsVersion == CMS_JOOMLA15) { $access_id = $this->Access->getAccessId(); $queryData['conditions'][] = 'Listing.access <= ' . $access_id; $queryData['conditions'][] = 'Category.access <= ' . $access_id; } else { $cat_id > 0 and $cat_id = array_keys($this->Category->getChildren($cat_id)); $access_id = $this->Access->getAccessLevels(); $queryData['conditions'][] = 'Listing.access IN ( ' . $access_id . ')'; $queryData['conditions'][] = 'Category.access IN ( ' . $access_id . ')'; } } if (!empty($cat_id) && $extension == 'com_content') { // Category feeds only supported for core content $queryData['conditions'][] = 'JreviewsCategory.id IN (' . $this->quote($cat_id) . ')'; $feedPage = 'category'; } elseif ($section_id > 0 && $extension == 'com_content') { $queryData['conditions'][] = 'Listing.sectionid= ' . $section_id; $feedPage = 'section'; } elseif ($dir_id > 0 && $extension == 'com_content') { $queryData['conditions'][] = 'JreviewsCategory.dirid= ' . $dir_id; $feedPage = 'directory'; } elseif ($extension != 'com_content') { unset($this->Review->joins['listings'], $this->Review->joins['jreviews_categories'], $this->Review->joins['listings']); $feedPage = 'everywhere'; } if ($listing_id > 0) { $queryData['conditions'][] = 'Review.pid = ' . $listing_id; $feedPage = 'listing'; } # Don't run it here because it's run in the Everywhere Observer Component $this->Review->runProcessRatings = false; $reviews = $this->Review->findAll($queryData); $this->set(array('feedPage' => $feedPage, 'encoding' => $this->encoding, 'rss' => $rss, 'reviews' => $reviews)); return $this->Feeds->saveFeed($feed_filename, 'reviews'); }
function _deleteModeration() { $response = array(); $entry_id = Sanitize::getInt($this->data, 'entry_id'); $deleted = $this->Claim->delete('claim_id', $entry_id); if ($deleted) { $response[] = "jreviews_admin.dialog.close();"; $response[] = "jQuery('#jr_moderateForm" . $entry_id . "').fadeOut(1500,function(){jQuery(this).html('');});"; $response[] = "jreviews_admin.menu.moderation_counter('claim_count');"; } return $this->ajaxResponse($response); }
/** * Cleans the JReviews cache * */ function cacheCleaner() { if (isset($this->c->Config->cache_cleanup) && $this->c->name != 'about') { $last_clean = Sanitize::getInt($this->c->Config, 'last_cache_clean'); $now = time(); if ($last_clean == 0 || $now - $last_clean > Sanitize::getInt($this->c->Config, 'cache_cleanup')) { $this->c->Config->store(array('last_cache_clean' => $now)); clearCache('', 'views'); clearCache('', '__data'); } } }
function index() { global $Itemid; $cat_id = null; $conditions = array(); $joins = array(); $order = array(); $menu_id = ''; // Read module params $dir_id = Sanitize::getString($this->params['module'], 'dir'); $section_id = Sanitize::getString($this->params, 'section'); $cat_id = Sanitize::getString($this->params['module'], 'cat'); $criteria_id = Sanitize::getString($this->params['module'], 'criteria'); $itemid_options = Sanitize::getString($this->params['module'], 'itemid_options'); $itemid_hc = Sanitize::getInt($this->params['module'], 'hc_itemid'); $field = Sanitize::getString($this->params['module'], 'field'); $option_length = Sanitize::getInt($this->params['module'], 'fieldoption_length'); $custom_params = Sanitize::getString($this->params['module'], 'custom_params'); $sort = Sanitize::getString($this->params['module'], 'fieldoption_order'); # Set menu id switch ($itemid_options) { case 'none': $menu_id = ''; break; case 'current': break; case 'hardcode': $menu_id = $itemid_hc; break; } # Category auto detect if (Sanitize::getInt($this->params['module'], 'catauto')) { $ids = CommonController::_discoverIDs($this); extract($ids); } $this->FieldOption->modelUnbind(array('FieldOption.value AS `FieldOption.value`', 'FieldOption.fieldid AS `FieldOption.fieldid`', 'FieldOption.image AS `FieldOption.image`', 'FieldOption.ordering AS `FieldOption.ordering`', 'FieldOption.optionid AS `FieldOption.optionid`', 'FieldOption.text AS `FieldOption.text`')); $fields[] = 'FieldOption.optionid AS `FieldOption.optionid`'; $fields[] = 'FieldOption.value AS `FieldOption.value`'; if ($option_length) { $fields[] = 'IF(CHAR_LENGTH(FieldOption.text)>' . $option_length . ',CONCAT(SUBSTR(FieldOption.text,1,' . $option_length . '),"..."),FieldOption.text) AS `FieldOption.text`'; } else { $fields[] = 'FieldOption.text AS `FieldOption.text`'; } $joins[] = 'INNER JOIN #__jreviews_fields AS Field ON Field.fieldid = FieldOption.fieldid'; $order[] = 'FieldOption.' . $sort; $field_options = $this->FieldOption->findAll(array('fields' => $fields, 'conditions' => 'Field.name = "' . $field . '"', 'joins' => $joins, 'order' => $order)); # Send variables to view template $this->set(array('field' => $field, 'field_options' => $field_options, 'section_ids' => $section_id, 'category_ids' => $cat_id, 'criteria_id' => $criteria_id, 'menu_id' => $menu_id, 'custom_params' => $custom_params)); return $this->render('modules', 'fields'); }
function saveInPlace() { $column = Sanitize::getString($this->data, 'column'); $fieldid = Sanitize::getInt($this->data, 'fieldid'); $value = Sanitize::getString($this->data, 'text'); $this->_db->setQuery("\n UPDATE \n #__jreviews_fields \n SET {$column} = " . $this->quote($value) . "\n\t\t WHERE fieldid = {$fieldid}\n\t\t"); if (!$this->_db->query()) { return false; } // Clear cache clearCache('', 'views'); clearCache('', '__data'); return true; }
function getListingFavorites($listing_id, $user_id, $passedArgs) { $avatar = Sanitize::getInt($passedArgs['module'], 'avatar', 1); // Only show users with avatars $module_id = Sanitize::getInt($passedArgs, 'module_id'); $rand = Sanitize::getFloat($passedArgs, 'rand'); $limit = Sanitize::getInt($passedArgs['module'], 'module_total', 10); $fields = array('Community.id AS `User.user_id`', 'User.name AS `User.name`', 'User.username AS `User.username`'); $conditions = array('Community.approved = 1', 'Community.confirmed = 1'); $avatar and $conditions[] = 'Community.avatar IS NOT NULL'; $listing_id and $conditions[] = 'Community.id in (SELECT user_id FROM #__jreviews_favorites WHERE content_id = ' . $listing_id . ')'; $order = array('RAND(' . $rand . ')'); $joins = array('LEFT JOIN #__users AS User ON Community.id = User.id'); $profiles = $this->findAll(array('fields' => $fields, 'conditions' => $conditions, 'order' => $order, 'joins' => $joins, 'limit' => $limit)); return $this->addProfileInfo($profiles, 'User', 'user_id'); }
function getListingFavorites($listing_id, $user_id, $passedArgs) { $conditions = array(); $avatar = Sanitize::getInt($passedArgs['module'], 'avatar', 1); // Only show users with avatars $module_id = Sanitize::getInt($passedArgs, 'module_id'); $rand = Sanitize::getFloat($passedArgs, 'rand'); $limit = Sanitize::getInt($passedArgs['module'], 'module_total', 10); $fields = array('Community.' . $this->realKey . ' AS `User.user_id`', 'User.name AS `User.name`', 'User.username AS `User.username`'); $avatar and $conditions[] = 'Community.thumb <> "components/com_community/assets/default_thumb.jpg" AND Community.thumb <> "components/com_community/assets/user_thumb.png" AND Community.thumb <> ""'; $listing_id and $conditions[] = 'Community.' . $this->realKey . ' in (SELECT user_id FROM #__jreviews_favorites WHERE content_id = ' . $listing_id . ')'; $order = array('RAND(' . $rand . ')'); $joins = array('LEFT JOIN #__users AS User ON Community.' . $this->realKey . ' = User.id'); $profiles = $this->findAll(array('fields' => $fields, 'conditions' => $conditions, 'order' => $order, 'joins' => $joins, 'limit' => $limit)); return $this->addProfileInfo($profiles, 'User', 'user_id'); }
/** * Geocoding using the Google http access * * @param array $address * @return array with geocoding info */ function geocode($address) { if (empty($this->_API)) { return false; } foreach ($this->_API as $service => $api) { $response = $this->{$service}($address); if ($response && Sanitize::getInt($response, 'status') == 200) { return $response; } // Status is error, unset this service from the API and use only the remaining ones if (isset($this->_API[$service]) && (!$response || $response['status'] != 200 && $response['status'] != 620)) { unset($this->_API[$service]); } } }
function _deleteModeration() { $entry_id = Sanitize::getInt($this->data, 'entry_id'); $this->data['OwnerReply']['id'] = $entry_id; $this->data['OwnerReply']['owner_reply_text'] = ''; $this->data['OwnerReply']['owner_reply_note'] = ''; $this->data['OwnerReply']['owner_reply_created'] = NULL_DATE; $this->data['OwnerReply']['owner_reply_approved'] = 0; # Delete listing and all associated records and images $deleted = $this->OwnerReply->store($this->data); if ($deleted) { $this->response[] = "jreviews_admin.dialog.close();"; $this->response[] = "jQuery('#jr_moderateForm" . $entry_id . "').slideUp('slow',function(){jQuery(this).html('');});"; $this->response[] = "jreviews_admin.menu.moderation_counter('owner_count');"; } return $this->ajaxResponse($this->response); }
function index($params) { if ($this->_user->id === 0) { $this->cacheAction = Configure::read('Cache.expires'); } $this->action = 'directory'; // Set view file $page = array('title' => '', 'show_title' => 0); $conditions = array(); $order = array(); $directories = $this->Directory->getTree(Sanitize::getString($this->params, 'dir')); if ($menu_id = Sanitize::getInt($this->params, 'Itemid')) { $menuParams = $this->Menu->getMenuParams($menu_id); $page['title'] = Sanitize::getString($menuParams, 'title'); $page['show_title'] = Sanitize::getString($menuParams, 'dirtitle', 0); } $this->set(array('page' => $page, 'directories' => $directories)); }
function _save() { $this->autoRender = false; $this->autoLayout = false; $response = array(); # Validate form token $this->components = array('security'); $this->__initComponents(); if ($this->invalidToken) { return $this->ajaxError(s2messages::invalidToken()); } if ($this->Config->user_report) { $this->data['Report']['report_text'] = Sanitize::getString($this->data['Report'], 'report_text'); $listing_id = $this->data['Report']['listing_id'] = Sanitize::getInt($this->data['Report'], 'listing_id'); $review_id = $this->data['Report']['review_id'] = Sanitize::getInt($this->data['Report'], 'review_id'); $post_id = $this->data['Report']['post_id'] = Sanitize::getInt($this->data['Report'], 'post_id'); $extension = $this->data['Report']['extension'] = Sanitize::getString($this->data['Report'], 'extension'); if ($this->data['Report']['report_text'] != '') { $this->data['Report']['user_id'] = $this->_user->id; $this->data['Report']['ipaddress'] = $this->ipaddress; $this->data['Report']['created'] = date('Y-m-d H:i:s'); $this->data['Report']['approved'] = 0; if ($this->_user->id) { $this->data['Report']['name'] = $this->_user->name; $this->data['Report']['username'] = $this->_user->username; $this->data['Report']['email'] = $this->_user->email; } else { $this->data['Report']['name'] = 'Guest'; $this->data['Report']['username'] = '******'; } if ($this->Report->store($this->data)) { $update_text = __t("Your report was submitted, thank you.", true); $response[] = "jQuery('#jr_reportLink" . ($post_id > 0 ? $post_id : $review_id) . "').remove();"; return $this->ajaxUpdateDialog($update_text, $response); } return $this->ajaxError(s2Messages::submitErrorDb()); } # Validation failed if (isset($this->Security)) { $reponse[] = "jQuery('jr_reportToken').val('" . $this->Security->reissueToken() . "')"; } return $this->ajaxValidation(__t("The message is empty.", true), $response); } }
function delete() { $id = Sanitize::getInt($this->data, 'entry_id'); $response = array(); if (!$id) { return $this->ajaxResponse($response, false); } // Check if the criteria is being used by a category $this->_db->setQuery("SELECT count(*) FROM #__jreviews_categories WHERE dirid IN ({$id})"); if ($this->_db->loadResult()) { $response[] = "jreviews_admin.dialog.close();s2Alert('You have categories using this directory, first you need to delete them or change the directory they have been assigned to.');"; return $this->ajaxResponse($response); } if (!$this->Directory->delete('id', $id)) { $response[] = "jreviews_admin.dialog.close();s2Alert('" . $this->_db->getErrorMsg() . "');"; return $this->ajaxResponse($response); } $response[] = "jreviews_admin.dialog.close();jreviews_admin.tools.removeRow('directory{$id}');"; return $this->ajaxResponse($response); }
function _save() { $response = array(); $this->data['Vote']['user_id'] = $this->_user->id; $this->data['Vote']['review_id'] = (int) $this->data['Vote']['review_id']; # Exact vote check to prevent form tampering. User can cheat the js and enter any interger, thus increasing the count $this->data['Vote']['vote_yes'] = Sanitize::getInt($this->data['Vote'], 'vote_yes') ? 1 : 0; $this->data['Vote']['vote_no'] = Sanitize::getInt($this->data['Vote'], 'vote_no') ? 1 : 0; $this->data['Vote']['created'] = gmdate('Y-m-d H:i:s'); $this->data['Vote']['ipaddress'] = $this->ipaddress; if (!$this->data['Vote']['review_id']) { return $this->ajaxError(s2Messages::submitErrorGeneric()); } // Find duplicates $duplicate = $this->Vote->findCount(array('conditions' => array('review_id = ' . $this->data['Vote']['review_id'], 'ipaddress = ' . $this->Vote->Quote($this->data['Vote']['ipaddress'])))); // It's a guest so we only care about checking the IP address if this feature is not disabled and // server is not localhost if (!$this->_user->id) { if (!$this->Config->vote_ipcheck_disable && $this->ipaddress != '127.0.0.1') { // Do the ip address check everywhere except in localhost $duplicate = $this->Vote->findCount(array('conditions' => array('review_id = ' . $this->data['Vote']['review_id'], 'ipaddress = ' . $this->Vote->Quote($this->ipaddress)))); } } else { $duplicate = $this->Vote->findCount(array('conditions' => array('review_id = ' . $this->data['Vote']['review_id'], "(user_id = {$this->_user->id}" . ($this->ipaddress != '127.0.0.1' && !$this->Config->vote_ipcheck_disable ? " OR ipaddress = " . $this->Vote->Quote($this->ipaddress) . ") " : ')')))); } if ($duplicate > 0) { # Hides vote buttons and shows message alert $response[] = "jQuery('#jr_reviewVote{$this->data['Vote']['review_id']}').fadeOut('medium',function(){\n jQuery(this).html('" . __t("You already voted.", true, true) . "').fadeIn();\n });"; return $this->ajaxResponse($response); } if ($this->Vote->store($this->data)) { # Hides vote buttons and shows message alert $response[] = "jQuery('#jr_reviewVote{$this->data['Vote']['review_id']}').fadeOut('medium',function(){\n jQuery(this).html('" . __t("Thank you for your vote.", true, true) . "').fadeIn();\n });"; # Facebook wall integration only for positive votes $facebook_integration = Sanitize::getBool($this->Config, 'facebook_enable') && Sanitize::getBool($this->Config, 'facebook_votes'); $token = cmsFramework::getCustomToken($this->data['Vote']['review_id']); $facebook_integration and $this->data['Vote']['vote_yes'] and $response[] = "\n jQuery.ajax({url:s2AjaxUri+jreviews.ajax_params()+'&url=facebook/_postVote/id:{$this->data['Vote']['review_id']}&{$token}=1',dataType:'script'});\n "; return $this->ajaxResponse($response); } return $this->ajaxError(s2Messages::submitErrorDb()); }
function reviews() { $extension = Sanitize::getString($this->params, 'extension', 'com_content'); $cat_id = Sanitize::getInt($this->params, 'cat'); $section_id = Sanitize::getInt($this->params, 'section'); $dir_id = Sanitize::getInt($this->params, 'dir'); $listing_id = Sanitize::getInt($this->params, 'id'); $this->encoding = cmsFramework::getCharset(); $feedPage = null; $this->EverywhereAfterFind = true; // Triggers the afterFind in the Observer Model $this->limit = $this->Config->rss_limit; $rss = array('title' => $this->Config->rss_title, 'link' => WWW_ROOT, 'description' => $this->Config->rss_description, 'image_url' => WWW_ROOT . "images/stories/" . $this->Config->rss_image, 'image_link' => WWW_ROOT); $queryData = array('conditions' => array('Review.published = 1', "Review.mode = '{$extension}'"), 'fields' => array('Review.mode AS `Review.extension`'), 'limit' => $this->limit, 'order' => array('Review.created DESC')); if ($cat_id > 0 && $extension == 'com_content') { // Category feeds only supported for core content $queryData['conditions'][] = 'JreviewsCategory.id= ' . $cat_id; // $queryData['joins'] = $this->Listing->joinsReviews; $feedPage = 'category'; } elseif ($section_id > 0 && $extension == 'com_content') { $queryData['conditions'][] = 'Listing.sectionid= ' . $section_id; // $queryData['joins'] = $this->Listing->joinsReviews; $feedPage = 'section'; } elseif ($dir_id > 0 && $extension == 'com_content') { $queryData['conditions'][] = 'JreviewsCategory.dirid= ' . $dir_id; // $queryData['joins'] = $this->Listing->joinsReviews; $feedPage = 'directory'; } elseif ($extension != 'com_content') { unset($this->Review->joins['listings'], $this->Review->joins['jreviews_categories'], $this->Review->joins['listings']); $feedPage = 'everywhere'; } if ($listing_id > 0) { $queryData['conditions'][] = 'Review.pid = ' . $listing_id; $feedPage = 'listing'; } # Don't run it here because it's run in the Everywhere Observer Component $this->Review->runProcessRatings = false; $reviews = $this->Review->findAll($queryData); $this->set(array('feedPage' => $feedPage, 'encoding' => $this->encoding, 'rss' => $rss, 'reviews' => $reviews)); return $this->Feeds->saveFeed(PATH_ROOT . DS . 'cache' . DS . 'jreviewsfeed_' . md5($this->here) . '.xml', 'reviews'); }
function _save() { $this->autoRender = false; $this->autoLayout = false; $this->components = array('security'); $this->__initComponents(); $listing_id = Sanitize::getInt($this->data['Claim'], 'listing_id'); $response = array(); # Validate form token if ($this->invalidToken) { return $this->ajaxError(s2Messages::invalidToken()); } if (!$listing_id) { return $this->ajaxError(s2Messages::accessDenied()); } if ($this->Config->claims_enable && $this->_user->id) { $this->data['Claim']['claim_text'] = Sanitize::getString($this->data['Claim'], 'claim_text'); if ($this->data['Claim']['claim_text'] != '') { // Check if this user already has a claim for this listing to update it $claim_id = $this->Claim->findOne(array('fields' => array('Claim.claim_id AS `Claim.claim_id`'), 'conditions' => array('Claim.user_id = ' . (int) $this->_user->id, 'Claim.listing_id = ' . $listing_id, 'Claim.approved <= 0'))); if ($claim_id > 0) { $this->data['Claim']['claim_id'] = $claim_id; } $this->data['Claim']['user_id'] = $this->_user->id; $this->data['Claim']['created'] = date('Y-m-d H:i:s'); $this->data['Claim']['approved'] = 0; if ($this->Claim->store($this->data)) { $update_text = __t("Your claim was submitted, thank you.", true); $response[] = "jQuery('#jr_claimImg{$listing_id}').remove();"; return $this->ajaxUpdateDialog($update_text, $response); } } else { # Validation failed if (isset($this->Security)) { $response[] = "jQuery('#jr_claimToken').val('" . $this->Security->reissueToken() . "');"; } return $this->ajaxValidation(__t("The message is empty.", true), $response); } } return $this->ajaxError(s2Messages::submitErrorDb()); }
function toggleIcon() { $id = Sanitize::getInt($this->data, 'id'); if (!$id) { return '{}'; } $field = Sanitize::getString($this->data, 'column'); $table = Sanitize::getString($this->data, 'table'); $key = Sanitize::getString($this->data, 'key'); $this->_db->setQuery("SELECT {$field} FROM `{$table}` WHERE {$key} = '{$id}'"); $state = $this->_db->loadResult(); $state = $state ? 0 : 1; $this->_db->setQuery("UPDATE `{$table}` SET `{$field}` = '{$state}' WHERE {$key} = '{$id}'"); if (!$this->_db->query()) { return '{}'; } // Clear cache clearCache('', 'views'); clearCache('', '__data'); return json_encode(array('state' => $state)); }
/** * Returns criteria set * * @param array $data has extension, cat_id or criteria_id keys=>values */ function getCriteria($data) { if (isset($data['criteria_id'])) { $conditions = array('Criteria.id = ' . Sanitize::getInt($data, 'criteria_id')); $joins = array(); } elseif (isset($data['cat_id'])) { $conditions = array('JreviewCategory.id = ' . Sanitize::getInt($data, 'cat_id')); $joins = array("INNER JOIN #__jreviews_categories AS JreviewCategory ON Criteria.id = JreviewCategory.criteriaid AND JreviewCategory.`option` = '{$data['extension']}'"); } $queryData = array('conditions' => $conditions, 'joins' => $joins); $results = $this->findRow($queryData); if (isset($results['Criteria']['criteria']) && $results['Criteria']['criteria'] != '') { $results['Criteria']['criteria'] = explode("\n", $results['Criteria']['criteria']); } if (isset($results['Criteria']['tooltips']) && $results['Criteria']['tooltips'] != '') { $results['Criteria']['tooltips'] = explode("\n", $results['Criteria']['tooltips']); } if (isset($results['Criteria']['weights']) && $results['Criteria']['weights'] != '') { $results['Criteria']['weights'] = explode("\n", $results['Criteria']['weights']); } return $results; }