function index() { $reviews = array(); $this->params = $this->data; $conditions = array("OwnerReply.owner_reply_approved = 0", "OwnerReply.owner_reply_text<>''"); $replies = $this->OwnerReply->findAll(array('fields' => array('CASE WHEN CHAR_LENGTH(User.name) THEN User.name ELSE OwnerReply.name END AS `User.name`', 'OwnerReply.email AS `User.email`'), 'conditions' => $conditions, 'joins' => array('LEFT JOIN #__users AS User ON User.id = OwnerReply.userid'), 'offset' => $this->offset, 'limit' => $this->limit, 'order' => array('OwnerReply.owner_reply_created DESC'))); $total = $this->OwnerReply->findCount(array('conditions' => $conditions)); if (!empty($replies)) { $predefined_replies = $this->PredefinedReply->findAll(array('fields' => array('PredefinedReply.*'), 'conditions' => array('reply_type = "owner_reply"'))); $this->Review->runProcessRatings = false; $this->EverywhereAfterFind = true; // Triggers the afterFind in the Observer Model // Complete the owner info for each reply // Get the review info for each reply $reviews = $this->Review->findAll(array('conditions' => 'Review.id IN (' . implode(',', array_keys($replies)) . ')')); # Pre-process all urls to sef $this->_getListingSefUrls($reviews); $this->_getReviewSefUrls($reviews); foreach ($replies as $key => $reply) { // Automagically load and initialize Everywhere Model to check if user is listing owner if (!isset($this->__loaded[$reply['Review']['extension']])) { App::import('Model', 'everywhere_' . $reply['Review']['extension'], 'jreviews'); $class_name = inflector::camelize('everywhere_' . $reply['Review']['extension']) . 'Model'; if (class_exists($class_name)) { ${$reply['Review']['extension']} = new $class_name(); } } $replies[$key]['Owner'] = ${$reply['Review']['extension']}->getListingOwner($reply['Review']['listing_id']); isset($reviews[$reply['Review']['review_id']]) and $replies[$key] = array_merge($replies[$key], $reviews[$reply['Review']['review_id']]); } } $this->set(array('total' => $total, 'owner_replies' => $replies, 'predefined_replies' => !empty($predefined_replies) ? $predefined_replies : array())); return $this->render('owner_replies', 'moderation'); }
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 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 } } }
/** * Add a row to the current data set * * @param array $row */ public function add_row($row) { $keyed_row = array(); foreach ($row as $k => $v) { $keyed_row[inflector::camelize($this->columns[$k])] = $v; } $this->rows[] = $keyed_row; }
function __initModels($models = null) { $models = !empty($models) ? $models : $this->uses; if (!empty($models)) { App::import('Model', $models, $this->app); foreach ($models as $model) { $method_name = inflector::camelize($model); $class_name = $method_name . 'Model'; $this->{$method_name} = new $class_name(); } } }
function __initModels($models = null, $app = 'jreviews') { if (!empty($models)) { if (!empty($models)) { App::import('Model', $models, $app); foreach ($models as $model) { $method_name = inflector::camelize($model); $class_name = $method_name . 'Model'; $this->{$method_name} = new $class_name(); } } } }
function __construct($app = 'jreviews') { if (!empty($this->helpers)) { $this->app = $app; App::import('Helper', $this->helpers, $this->app); foreach ($this->helpers as $helper) { $method_name = inflector::camelize($helper); $class_name = $method_name . 'Helper'; if (!isset($this->loaded[$method_name])) { $this->{$method_name} = registerClass::getInstance($class_name); $this->loaded[$method_name] =& ${$method_name}; } } } }
function xajaxDispatch() { # MVC initalization script if (!defined('MVC_FRAMEWORK')) { require dirname(dirname(__FILE__)) . DS . 'com_jreviews' . DS . 'jreviews' . DS . 'framework.php'; } $objResponse = new xajaxResponse(); # Debug if (S2_DEBUG == 0) { error_reporting(0); } # Function parameters $args = func_get_args(); $controllerName = (string) array_shift($args); $action = (string) array_shift($args); $app = isset($args[0]) && is_string($args[0]) ? array_shift($args) : 'jreviews'; App::import('Controller', $controllerName, $app); # remove admin path from controller name $controllerClass = inflector::camelize(str_replace(MVC_ADMIN . _DS, '', $controllerName)) . 'Controller'; $controller = new $controllerClass($app); $controller->app = $app; $controller->passedArgs = array(); if (isset($args[0])) { $post = S2Dispatcher::parseParamsAjax($args[0]); if (isset($post['data'])) { // pass form inputs to controller variable $rawData = $post['data']; $data = Sanitize::clean($post['data']); $data['__raw'] = $rawData; $controller->data = $data; } $controller->passedArgs = $post; $controller->params = $post; } $controller->name = $controllerName; $controller->action = $action; $controller->autoLayout = false; $controller->autoRender = false; $controller->xajaxRequest = true; $controller->__initComponents(); if (method_exists($controller, 'beforeFilter')) { $controller->beforeFilter(); } $objResponse->loadCommands($controller->{$action}($args)); return $objResponse; }
/** * Dynamic Listing Model Loading for jReviewsEverywhere extensions * Detects which extension is being used to load the correct Listing model * * @param object $controller * @param string $extension */ function loadListingModel(&$controller, $extension = null) { if (in_array($controller->name, array('admin/reviews', 'reviews')) && $controller->action == '_save') { $extension = Sanitize::getString($controller->data['Review'], 'mode'); !$extension and isset($controller->data['Listing']) and $extension = Sanitize::getString($controller->data['Listing'], 'extension'); } else { $extension = $extension ? $extension : Sanitize::getString($controller->params, 'extension', Sanitize::getString($controller->data, 'extension')); } if (!$extension && isset($controller->params['module'])) { // Final check for module parameter $extension = Sanitize::getString($controller->params['module'], 'extension'); } $extension == '' and $controller->name != 'facebook' and $controller->name != 'reviews' and $controller->name != 'community_reviews' and $controller->name != 'module_reviews' and $controller->name != 'discussions' and $controller->name != 'admin/reviews' and $controller->name != 'admin/admin_owner_replies' and $controller->name != 'admin/admin_reports' and $controller->name != 'admin/admin_discussions' and $extension = 'com_content'; // Check if in listing detail page and it's a 3rd party component to dynamically load it's Listing model if ($extension) { $name = $this->name . '_' . $extension; App::import('Model', $name, 'jreviews'); $class_name = inflector::camelize($this->name . '_' . $extension) . 'Model'; if ($extension != '' && class_exists($class_name)) { $controller->Listing = new $class_name($controller->params); if (isset($controller->Review) && $controller->action != '_save') { unset($controller->Review->joins['listings'], $controller->Review->joins['jreviews_categories'], $controller->Review->joins['criteria']); $controller->Review->joins = array_merge($controller->Review->joins, $controller->Listing->joinsReviews); } } else { // Extension used in url doesn't have a plugin so we redirect to 404 error page $controller->autoLayout = false; $controller->autoRender = true; cmsFramework::redirect(cmsFramework::route('index.php?option=com_jreviews&url=404')); } } }
function dispatch() { $args = func_get_args(); if (count($args) == 2) { $url = $args[0]; $additionalParams = $args[1]; } elseif (count($args) == 1) { $url = null; $additionalParams = $args[0]; } else { $url = null; $additionalParams = array(); } if ($url !== null) { $_GET['url'] = $url; } elseif (isset($_REQUEST['url'])) { $_GET['url'] = $_REQUEST['url']; // Non-latin characters are wrong in $_GET array } if (isset($_POST['url'])) { $_GET['url'] = $_POST['url']; } // For ajax calls via url param $this->params = array_insert($this->parseParams($_SERVER['REQUEST_URI']), $additionalParams); $this->controller = Sanitize::getString($this->params['data'], 'controller'); $this->action = Sanitize::getString($this->params['data'], 'action', 'index'); $cache_url = $this->getUrl(); $this->here = $this->base . '/' . $cache_url; if (!defined('MVC_FRAMEWORK_ADMIN') && ($cached = $this->cached($cache_url))) { return $cached; } if (!$this->controller || (!isset($_POST) || empty($_POST)) && $this->action[0] == '_' && !$this->isAjax()) { return $this->error404(); } else { App::import('Controller', $this->controller, $this->app); # remove admin path from controller name $controllerClass = inflector::camelize(str_replace(MVC_ADMIN . _DS, '', $this->controller)) . 'Controller'; $controller = new $controllerClass($this->app); $controller->app = $this->app; $controller->base = $this->base; $controller->here = $this->here; $controller->params =& $this->params; $controller->name = $this->controller; $controller->action = $this->action; $controller->ajaxRequest = $this->isAjax(); $controller->xajaxRequest = false; if (!method_exists($controller, $this->action)) { return $this->error404(); } $controller->passedArgs = $this->params['url']; # Copy post array to data array if (isset($this->params['data'])) { $rawData = $this->params['data']; $data = Sanitize::clean($this->params['data']); $data['__raw'] = $rawData; $controller->data = $data; } $controller->__initComponents(); if (in_array('return', array_keys($this->params)) && $this->params['return'] == 1 || $controller->ajaxRequest) { $controller->autoRender = false; } if (!empty($this->params['bare']) || $controller->ajaxRequest) { $controller->autoLayout = false; } if (isset($this->params['layout'])) { if ($this->params['layout'] === '') { $controller->autoLayout = false; } else { $controller->layout = $this->params['layout']; } } $controller->beforeFilter(); $output = $controller->{$controller->action}($this->params); } $controller->output =& $output; # Instantiate view class and let it handle ouput if ($controller->autoRender) { $controller->render($controller->name, $controller->action, $controller->layout); $controller->afterFilter(); } else { $controller->afterFilter(); return $controller->output; } }
/** * Saves totals for the listing after any kind of reviews update (save, publish, delete, change weights etc.) * @return boolean */ function saveListingTotals($listing_id, $extension, $weights = array()) { if (empty($weights)) { // Load listings' Everywhere model $file_name = 'everywhere' . '_' . $extension; $class_name = inflector::camelize($file_name) . 'Model'; App::import('Model', $file_name, 'jreviews'); $ListingModel = new $class_name(); $weights = $ListingModel->findRow(array('fields' => 'Criteria.weights AS `Criteria.weights`', 'conditions' => "Listing.{$ListingModel->realKey} = {$listing_id}"), array()); unset($ListingModel); $weights = explode("\n", trim($weights['Criteria']['weights'])); } $reviewTypes['user'] = 0; # user reviews # editor reviews only in com_content if ($extension == 'com_content') { $reviewTypes['editor'] = 1; } # initiate the results array now moved before the foreach $data['Totals'] = array('listing_id' => $listing_id, 'extension' => $extension); # encompassing all calculations with foreach (procedures like changing the review type can affect both averages) foreach ($reviewTypes as $reviewType => $reviewTypeValue) { # count comments $query = "\n SELECT COUNT(*)\n FROM #__jreviews_comments\n WHERE\n pid = {$listing_id}\n AND mode = '{$extension}'\n AND published = 1\n AND author = {$reviewTypeValue}\n "; $this->_db->setQuery($query); $data['Totals'][$reviewType . '_comment_count'] = $this->_db->loadResult(); if (empty($data['Totals'][$reviewType . '_comment_count'])) { # listing deletion moved after the foreach. instead populate the relevant array elements with empty values and move on $data['Totals'] += array_fill_keys(array($reviewType . '_rating', $reviewType . '_rating_count', $reviewType . '_criteria_rating', $reviewType . '_criteria_rating_count'), ''); continue; } $reviewsExist = 1; # to be used after the foreach // Now, do ratings exist? $query = "SELECT Rating.ratings" . "\n FROM #__jreviews_comments AS Review" . "\n INNER JOIN #__jreviews_ratings AS Rating ON Review.id = Rating.reviewid" . "\n WHERE Review.pid = '{$listing_id}' AND Review.published = 1" . "\n AND Review.author = {$reviewTypeValue}" . "\n AND Review.mode = '{$extension}'"; $this->_db->setQuery($query); $rows = $this->_db->loadAssocList(); if (!empty($rows)) { // Ratings exist, begin calculations $weighted = is_array($weights) && array_sum($weights) == 100 ? 1 : 0; $reviewCount = 0; $sumRatings = array(); # must init so values from previous foreach iteration won't be used // This is used like reviewCount, but for each criterion separately. // Preparing the inital array here, see later on for its use $reviewCountForCriterion = array_fill(0, count(explode(',', $rows[0]['ratings'])), 0); foreach ($rows as $rating) { $ratings_array = explode(',', $rating['ratings']); // if all is N/A, do not count this review towards the average if (array_sum($ratings_array) != 0) { $reviewCount++; } // Calculates the totals for each criteria for ($j = 0; $j < count($ratings_array); $j++) { if (isset($sumRatings[$j])) { $sumRatings[$j] += $ratings_array[$j]; } else { $sumRatings[$j] = $ratings_array[$j]; } /// If value is N/A, do not count this review towards the criterion average. if (isset($reviewCountForCriterion[$j]) && $ratings_array[$j] != 0) { $reviewCountForCriterion[$j]++; } } } # creates criteria averages. $ratings = array_map(create_function('$el, $revCount', 'return empty($revCount) ? "na" : number_format($el / $revCount, 4);'), $sumRatings, $reviewCountForCriterion); $userRating = 'na'; if ($reviewCount > 0) { if ($weighted) { # calculate sum of valid weights (=whose ratings aren't n/a) $sumWeights = array_sum(array_intersect_key($weights, array_filter($sumRatings, create_function('$el', 'return !empty($el) && $el != "na";')))); if ($sumWeights > 0) { foreach ($ratings as $k => $v) { $userRating += $v * $weights[$k] / $sumWeights; } } } else { # calculate the average, count criteria averages without the n/a ones $userRating = array_sum($ratings) / count(array_filter($ratings, create_function('$el', 'return !empty($el) && $el != "na";'))); } } # if ( $reviewCount > 0 ) // populate saving array for jreviews_listing_totals table $data['Totals'] += array($reviewType . '_rating' => is_numeric($userRating) ? number_format($userRating, 4) : $userRating, $reviewType . '_rating_count' => $reviewCount, $reviewType . '_criteria_rating' => implode(',', $ratings), $reviewType . '_criteria_rating_count' => implode(',', $reviewCountForCriterion)); } # if ($rows) } # foreach ( $reviewTypes as $reviewType ) // ready to update database! # reviews exist (user or editor). delete listing row if (empty($reviewsExist)) { appLogMessage('*******Deleting listing totals for listing ID ' . $listing_id . ' extension ' . $extension, 'database'); # not using s2 db function since it will use the wrong table $query = "\n DELETE FROM #__jreviews_listing_totals\n WHERE\n listing_id = {$listing_id}\n AND extension = '{$extension}'\n "; $this->_db->setQuery($query); if (!$this->_db->query()) { appLogMessage('*******There was a problem deleting listing totals for listing ID ' . $listing_id . ' extension ' . $extension, 'database'); return false; } return true; } // Reviews exist, proceed to save appLogMessage('*******Save listing totals for listing ID ' . $listing_id . ' extension ' . $extension, 'database'); if (!$this->replace('#__jreviews_listing_totals', 'Totals', $data, 'listing_id')) { appLogMessage('*******There was a problem saving the listing totals for listing ID ' . $listing_id . ' extension ' . $extension, 'database'); return false; } return true; }
function validate(&$data, $fieldLocation, $Access) { if (!isset($data['Field'])) { return; } $location = $fieldLocation == 'listing' ? 'content' : 'review'; $query = "\n SELECT \n groupid \n FROM \n #__jreviews_criteria \n WHERE \n id = " . (int) $data['Criteria']['id']; $this->_db->setQuery($query); $groupids = $this->_db->loadResult(); if ($groupids) { appLogMessage("*********Validate fields", 'database'); # PaidListings integration to remove hidden fields from validation $plan_fields = isset($data['Paid']) ? explode(",", Sanitize::getString($data['Paid'], 'fields')) : ''; !empty($plan_fields) and $plan_fields = "'" . implode("','", $plan_fields) . "'"; $queryData = array('conditions' => array('Field.groupid IN (' . $groupids . ')', 'Field.published = 1', "Field.location = '{$location}'")); $plan_fields != '' and $queryData['conditions'][] = "Field.name IN (" . $plan_fields . ")"; $fields = $this->findAll($queryData); if (!$fields) { return; } $valid_fields = array(); $fieldLocation = inflector::camelize($fieldLocation); foreach ($fields as $field) { // Check validation only for displayed fields *access rights* if (in_array($Access->gid, explode(",", $field['Field']['access']))) { $value = Sanitize::getVar($data['Field'][$fieldLocation], $field['Field']['name'], ''); // $value = isset($data['Field'][$fieldLocation][$field['Field']['name']]) ? $data['Field'][$fieldLocation][$field['Field']['name']] : ''; $label = sprintf(__t("You must fill in a valid value for %s.", true), $field['Field']['title']); $name = $field['Field']['name']; $type = $field['Field']['type']; $required = $field['Field']['required']; $valid_fields[] = $field['Field']; $regex = ''; if (!isset($field['Field']['_params']['valid_regex'])) { switch ($field['Field']['type']) { case 'integer': $regex = "^[0-9]+\$"; break; case 'decimal': $regex = "^(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)\$"; break; case 'website': $regex = "^(ftp|http|https)+(:\\/\\/)+[a-z0-9_-]+\\.+[a-z0-9_-]"; break; case 'email': $regex = ".+@.*"; break; default: $regex = ''; break; } } elseif ($type != 'date') { $regex = $field['Field']['_params']['valid_regex']; } if (!is_array($value)) { $value = array($value); } elseif ($type == 'selectmultiple' && is_array($value[0])) { $data['Field'][$fieldLocation][$field['Field']['name']] = $data['Field'][$fieldLocation][$field['Field']['name']][0]; $value = $value[0]; } $value = trim(implode(',', $value)); $this->validateInput($value, $name, $type, $label, $required, $regex); } } return $valid_fields; } }
function plgAfterSave(&$model) { appLogMessage('**** BEGIN Notifications Plugin AfterSave', 'database'); # Read cms mail config settings $configSendmailPath = cmsFramework::getConfig('sendmail'); $configSmtpAuth = cmsFramework::getConfig('smtpauth'); $configSmtpUser = cmsFramework::getConfig('smtpuser'); $configSmtpPass = cmsFramework::getConfig('smtppass'); $configSmtpHost = cmsFramework::getConfig('smtphost'); $configSmtpSecure = cmsFramework::getConfig('smtpsecure'); $configSmtpPort = cmsFramework::getConfig('smtpport'); $configMailFrom = cmsFramework::getConfig('mailfrom'); $configFromName = cmsFramework::getConfig('fromname'); $configMailer = cmsFramework::getConfig('mailer'); if (!class_exists('PHPMailer')) { App::import('Vendor', 'phpmailer' . DS . 'class.phpmailer'); } $mail = new PHPMailer(); $mail->CharSet = cmsFramework::getCharset(); $mail->SetLanguage('en', S2_VENDORS . 'PHPMailer' . DS . 'language' . DS); $mail->Mailer = $configMailer; // Mailer used mail,sendmail,smtp switch ($configMailer) { case 'smtp': $mail->Host = $configSmtpHost; $mail->SMTPAuth = $configSmtpAuth; $mail->Username = $configSmtpUser; $mail->Password = $configSmtpPass; $mail->SMTPSecure = $configSmtpSecure != '' ? $configSmtpSecure : ''; $mail->Port = $configSmtpPort; break; case 'sendmail': $mail->Sendmail = $configSendmailPath; break; default: break; } $mail->isHTML(true); $mail->From = $configMailFrom; $mail->FromName = $configFromName; # In this observer model we just use the existing data to send the email notification switch ($this->notifyModel->name) { # Notification for new/edited listings case 'Listing': if ($this->c->Config->notify_content || $this->c->Config->notify_user_listing) { $this->c->autoRender = false; $listing = $this->_getListing($model); $this->c->set(array('isNew' => isset($model->data['insertid']), 'User' => $this->c->_user, 'listing' => $listing)); } else { return; } // Admin listing email if ($this->c->Config->notify_content) { $mail->ClearAddresses(); $mail->ClearAllRecipients(); $mail->ClearBCCs(); # Process configuration emails if ($this->c->Config->notify_content_emails == '') { $mail->AddAddress($configMailFrom); } else { $recipient = explode("\n", $this->c->Config->notify_content_emails); foreach ($recipient as $to) { if (trim($to) != '') { $mail->AddAddress(trim($to)); } } } $subject = isset($model->data['insertid']) ? __t("New listing", true) . ": {$listing['Listing']['title']}" : __t("Edited listing", true) . ": {$listing['Listing']['title']}"; $guest = !$this->c->_user->id ? ' (Guest)' : " ({$this->c->_user->id})"; $author = $this->c->_user->id ? $this->c->_user->name : 'Guest'; $message = $this->c->render('email_templates', 'admin_listing_notification'); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->Send()) { appLogMessage(array("Admin listing message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications'); } } // End admin listing email // User listing email - to user submitting the listing as long as he is also the owner of the listing if ($this->c->Config->notify_user_listing) { $mail->ClearAddresses(); $mail->ClearAllRecipients(); $mail->ClearBCCs(); //Check if submitter and owner are the same or else email is not sent // This is to prevent the email from going out if admins are doing the editing if ($this->c->_user->id == $listing['User']['user_id']) { // Process configuration emails if ($this->c->Config->notify_user_listing_emails != '') { $recipient = explode("\n", $this->c->Config->notify_user_listing_emails); foreach ($recipient as $bcc) { if (trim($bcc) != '') { $mail->AddBCC(trim($bcc)); } } } $mail->AddAddress(trim($listing['User']['email'])); $subject = isset($model->data['insertid']) ? sprintf(__t("New listing: %s", true), $listing['Listing']['title']) : sprintf(__t("Edited listing: %s", true), $listing['Listing']['title']); $guest = !$this->c->_user->id ? ' (Guest)' : " ({$this->c->_user->id})"; $author = $this->c->_user->id ? $this->c->_user->name : 'Guest'; $message = $this->c->render('email_templates', 'user_listing_notification'); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->Send()) { appLogMessage(array("User listing message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications'); } } } // End user listing email break; # Notification for new/edited reviews # Notification for new/edited reviews case 'Review': // Perform common actions for all review notifications if ($this->c->Config->notify_review || $this->c->Config->notify_user_review || $this->c->Config->notify_owner_review) { $extension = $model->data['Review']['mode']; $review = $this->_getReview($model); $listing = $review; $entry_title = $listing['Listing']['title']; $this->c->autoRender = false; $this->c->set(array('isNew' => isset($model->data['insertid']), 'extension' => $extension, 'listing' => $listing, 'User' => $this->c->_user, 'review' => $review)); } else { return; } // Admin review email if ($this->c->Config->notify_review) { $mail->ClearAddresses(); $mail->ClearAllRecipients(); $mail->ClearBCCs(); # Process configuration emails if ($this->c->Config->notify_review_emails == '') { $mail->AddAddress($configMailFrom); } else { $recipient = explode("\n", $this->c->Config->notify_review_emails); foreach ($recipient as $to) { if (trim($to) != '') { $mail->AddAddress(trim($to)); } } } $subject = isset($model->data['insertid']) ? sprintf(__t("New review: %s", true), $entry_title) : sprintf(__t("Edited review: %s", true), $entry_title); $message = $this->c->render('email_templates', 'admin_review_notification'); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->Send()) { appLogMessage(array("Admin review message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications'); } } // User review email - sent to review submitter if ($this->c->Config->notify_user_review && $this->c->_user->id == $review['User']['user_id'] && !empty($review['User']['email'])) { $mail->ClearAddresses(); $mail->ClearAllRecipients(); $mail->ClearBCCs(); //Check if submitter and owner are the same or else email is not sent // This is to prevent the email from going out if admins are doing the editing if ($this->c->_user->id == $review['User']['user_id']) { // Process configuration emails if ($this->c->Config->notify_user_review_emails != '') { $recipient = explode("\n", $this->c->Config->notify_user_review_emails); foreach ($recipient as $bcc) { if (trim($bcc) != '') { $mail->AddBCC(trim($bcc)); } } } $mail->AddAddress(trim($review['User']['email'])); $subject = isset($model->data['insertid']) ? sprintf(__t("New review: %s", true), $entry_title) : sprintf(__t("Edited review: %s", true), $entry_title); $message = $this->c->render('email_templates', 'user_review_notification'); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->Send()) { appLogMessage(array("User review message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications'); } } } // Listing owner review email if ($this->c->Config->notify_owner_review && isset($listing['ListingUser']['email'])) { $mail->ClearAddresses(); $mail->ClearAllRecipients(); $mail->ClearBCCs(); // Process configuration emails if ($this->c->Config->notify_owner_review_emails != '') { $recipient = explode("\n", $this->c->Config->notify_owner_review_emails); foreach ($recipient as $bcc) { if (trim($bcc) != '') { $mail->AddBCC(trim($bcc)); } } } $mail->AddAddress(trim($listing['ListingUser']['email'])); $subject = isset($model->data['insertid']) ? sprintf(__t("New review: %s", true), $entry_title) : sprintf(__t("Edited review: %s", true), $entry_title); $message = $this->c->render('email_templates', 'owner_review_notification'); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->Send()) { appLogMessage(array("Listing owner review message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications'); } } break; # Notification for new owner replies to user reviews # Notification for new owner replies to user reviews case 'OwnerReply': if ($this->c->Config->notify_owner_reply) { # Process configuration emails if ($this->c->Config->notify_owner_reply_emails == '') { $mail->AddAddress($configMailFrom); } else { $recipient = explode("\n", $this->c->Config->notify_owner_reply_emails); foreach ($recipient as $to) { if (trim($to) != '') { $mail->AddAddress(trim($to)); } } } # Get review data $this->c->Review->runProcessRatings = false; $review = $this->c->Review->findRow(array('conditions' => array('Review.id = ' . (int) $model->data['OwnerReply']['id']))); $extension = $review['Review']['extension']; # Load jReviewsEverywhere extension model $name = 'everywhere_' . $extension; App::import('Model', $name, 'jreviews'); $class_name = inflector::camelize('everywhere_' . $extension) . 'Model'; $EverywhereListingModel = new $class_name(); # Get the listing title based on the extension being reviewed $listing = $EverywhereListingModel->findRow(array('conditions' => array("Listing.{$EverywhereListingModel->realKey} = " . $review['Review']['listing_id']))); $subject = sprintf(__t("Owner review reply submitted for listing %s", true), $listing['Listing']['title']); $this->c->autoRender = false; $this->c->set(array('User' => $this->c->_user, 'reply' => $model->data, 'review' => $review, 'listing' => $listing)); $message = $this->c->render('email_templates', 'admin_owner_reply_notification'); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->Send() && _MVC_DEBUG_ERR) { appLogMessage(array("Owner reply message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications'); } } break; # Notification for new review reports # Notification for new review reports case 'Report': if ($this->c->Config->notify_report) { # Process configuration emails if ($this->c->Config->notify_review_emails == '') { $mail->AddAddress($configMailFrom); } else { $recipient = explode("\n", $this->c->Config->notify_review_emails); foreach ($recipient as $to) { if (trim($to) != '') { $mail->AddAddress(trim($to)); } } } # Get review data $this->c->Review->runProcessRatings = false; $review = $this->c->Review->findRow(array('conditions' => array('Review.id = ' . (int) $model->data['Report']['review_id'])), array()); $extension = $review['Review']['extension']; # Load jReviewsEverywhere extension model $name = 'everywhere_' . $extension; App::import('Model', $name, 'jreviews'); $class_name = inflector::camelize('everywhere_' . $extension) . 'Model'; $EverywhereListingModel = new $class_name(); # Get the listing title based on the extension being reviewed $listing = $EverywhereListingModel->findRow(array('conditions' => array("Listing.{$EverywhereListingModel->realKey} = " . $review['Review']['listing_id']))); $subject = __t("A new report has been submitted", true); $this->c->autoRender = false; $this->c->set(array('User' => $this->c->_user, 'report' => $model->data, 'review' => $review, 'listing' => $listing)); $message = $this->c->render('email_templates', 'admin_report_notification'); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->Send() && _MVC_DEBUG_ERR) { appLogMessage(array("Review report message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications'); } } break; case 'Discussion': if ($this->c->Config->notify_review_post) { # Process configuration emails if ($this->c->Config->notify_review_post_emails == '') { $mail->AddAddress($configMailFrom); } else { $recipient = explode("\n", $this->c->Config->notify_review_post_emails); foreach ($recipient as $to) { if (trim($to) != '') { $mail->AddAddress(trim($to)); } } } # Get review data $this->c->Review->runProcessRatings = false; $review = $this->c->Review->findRow(array('conditions' => array('Review.id = ' . (int) $model->data['Discussion']['review_id']))); $extension = $review['Review']['extension']; # Load jReviewsEverywhere extension model $name = 'everywhere_' . $extension; App::import('Model', $name, 'jreviews'); $class_name = inflector::camelize('everywhere_' . $extension) . 'Model'; $EverywhereListingModel = new $class_name(); # Get the listing title based on the extension being reviewed $listing = $EverywhereListingModel->findRow(array('conditions' => array("Listing.{$EverywhereListingModel->realKey} = " . $review['Review']['listing_id']))); $subject = isset($model->data['insertid']) ? sprintf(__t("New comment for review: %s", true), $review['Review']['title']) : sprintf(__t("Edited comment for review: %s", true), $review['Review']['title']); $this->c->autoRender = false; $this->c->set(array('User' => $this->c->_user, 'post' => $model->data, 'review' => $review, 'listing' => $listing)); $message = $this->c->render('email_templates', 'admin_review_discussion_post'); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->Send() && _MVC_DEBUG_ERR) { appLogMessage(array("Review comment message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications'); } } break; case 'Claim': if ($this->c->Config->notify_claim) { # Process configuration emails if ($this->c->Config->notify_claim_emails == '') { $mail->AddAddress($configMailFrom); } else { $recipient = explode("\n", $this->c->Config->notify_claim_emails); foreach ($recipient as $to) { if (trim($to) != '') { $mail->AddAddress(trim($to)); } } } # Get claim data $callbacks = array(); $listing = $this->c->Listing->findRow(array('conditions' => array('Listing.id = ' . (int) $model->data['Claim']['listing_id'])), $callbacks); $subject = sprintf(__t("Listing claim submitted for %s", true), $listing['Listing']['title']); $this->c->autoRender = false; $this->c->set(array('User' => $this->c->_user, 'claim' => $model->data['Claim'], 'listing' => $listing)); $message = $this->c->render('email_templates', 'admin_listing_claim'); $mail->Subject = $subject; $mail->Body = $message; if (!$mail->Send() && _MVC_DEBUG_ERR) { appLogMessage(array("Listing claim message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications'); } } break; } $this->published = false; // Run once. With paid listings it is possible for a plugin to run a 2nd time when the order is processed together with the listing (free) return true; }
function replace($table, $alias, &$data, $keyName = null) { $fmtsql = "REPLACE INTO {$table} ( %s ) VALUES ( %s ) "; $alias = inflector::camelize($alias); $fields = array(); foreach ($data[$alias] as $k => $v) { if (is_array($v) or is_object($v) or $v === NULL or $k[0] == '_') { continue; } $fields[] = "`{$k}`"; $values[] = $this->Quote($v); } if (!isset($fields)) { die('class database method insertObject - no fields'); } $this->_db->setQuery(sprintf($fmtsql, implode(",", $fields), implode(",", $values))); $replace = $this->_db->query(); $message[] = '*********' . get_class($this) . ' | Replace'; $message[] = $this->_db->getQuery(); $message[] = $this->_db->getErrorMsg(); appLogMessage($message, 'database'); if (!$replace) { return false; } $id = $this->_db->insertid(); if ($keyName && $id) { $data[$alias][$keyName] = $id; } return true; }
function _getListingEverywhere($listing_id, $extension) { if (isset($this->c->viewVars['listing_' . $extension])) { $listing = $this->c->viewVars['listing_' . $extension]; } else { // Automagically load and initialize Everywhere Model App::import('Model', 'everywhere_' . $extension, 'jreviews'); $class_name = inflector::camelize('everywhere_' . $extension) . 'Model'; if (class_exists($class_name)) { $ListingModel = new $class_name(); $listing = $ListingModel->findRow(array('conditions' => array('Listing.' . $ListingModel->realKey . ' = ' . $listing_id))); $this->c->set('listing_' . $extension, $listing); } } return $listing; }
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 &_loadHelpers(&$loaded, $helpers, $parent = null) { App::import('Helper', $this->helpers, $this->app); foreach ($helpers as $helper) { $helper = str_replace(MVC_ADMIN . _DS, '', $helper); $method_name = inflector::camelize($helper); $class_name = $method_name . 'Helper'; if (!isset($this->loaded[$method_name])) { ${$method_name} = ClassRegistry::getClass($class_name); $loaded[$method_name] =& ${$method_name}; # Pass View vars to Helper Object foreach ($this->__helperVars as $helperVar) { if (isset($this->{$helperVar})) { $loaded[$method_name]->{$helperVar} = $this->{$helperVar}; } } } } return $loaded; }
/** * Write a cached version of the file * * @param string $file * @param sting $timestamp * @return cached view * @access private */ function __writeFile($content, $timestamp, $useCallbacks = false, $autoRender = true) { $now = time(); if (is_numeric($timestamp)) { $cacheTime = $now + $timestamp; } else { $cacheTime = strtotime($timestamp, $now); } $path = $this->here; if ($this->here == '/') { $path = 'home'; } $cache = Inflector::slug($path); if (empty($cache)) { return; } $cache = $cache . '.php'; $file = '<!--cachetime:' . $cacheTime . '--><?php'; if (!$autoRender) { $file .= ' defined(\'MVC_FRAMEWORK\') or die(\'Direct Access to this location is not allowed.\'); '; } elseif (empty($this->plugin)) { $file .= ' defined(\'MVC_FRAMEWORK\') or die(\'Direct Access to this location is not allowed.\'); App::import(\'Controller\', \'' . $this->controllerName . '\', \'' . $this->app . '\'); '; } else { // Not used because there are no plugins in jReviews $file .= ' defined(\'MVC_FRAMEWORK\') or die(\'Direct Access to this location is not allowed.\'); App::import(\'Controller\', \'' . $this->plugin . '.' . $this->controllerName . '\',\'' . $this->app . '\'); '; } if (!$autoRender) { $file .= ' $loadedHelpers = array(); $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); foreach (array_keys($loadedHelpers) as $helper) { $camelBackedHelper = Inflector::camelize($helper); ${$camelBackedHelper} =& $loadedHelpers[$helper]; $this->loaded[$helper] =& ${$camelBackedHelper}; } ?>'; } else { $file .= '$controller = new ' . inflector::camelize($this->controllerName) . 'Controller("' . $this->app . '"); $controller->helpers = $this->helpers = unserialize(\'' . serialize($this->helpers) . '\'); $controller->app = $this->app = \'' . $this->app . '\'; $controller->base = $this->base = \'' . $this->base . '\'; $controller->layout = $this->layout = \'' . $this->layout . '\'; $controller->here = $this->here = \'' . $this->here . '\'; $controller->ajaxRequest = $this->ajaxRequest = \'' . $this->ajaxRequest . '\'; $controller->viewSuffix = $this->viewSuffix = \'' . $this->viewSuffix . '\'; $controller->params = $this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\')); $controller->name = $this->name = unserialize(\'' . serialize($this->name) . '\'); $controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\'); $controller->data = $this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\')); $controller->assets = $this->assets = unserialize(stripslashes(\'' . addslashes(serialize($this->assets)) . '\')); '; $file .= ' $loadedHelpers = array(); $loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); foreach (array_keys($loadedHelpers) as $helper) { $camelBackedHelper = Inflector::camelize($helper); ${$camelBackedHelper} =& $loadedHelpers[$helper]; $this->loaded[$helper] =& ${$camelBackedHelper}; } '; /* if ($useCallbacks == true) { $file .= ' $controller->constructClasses(); $controller->Component->initialize($controller); $controller->beforeFilter(); $controller->Component->startup($controller); $controller->afterFilter(); '; } */ $file .= '$controller->afterFilter();'; $file .= '?>'; } $content = preg_replace("/(<\\?xml)/", "<?php echo '\$1';?>", $content); $file .= $content; return cache('views' . DS . $cache, $file, $timestamp); }
/** * Recalculates the rating sum based on the weights assigned to each rating * */ function refreshReviewRatings() { error_reporting(E_ALL); ini_set('display_errors', 'On'); ini_set('max_execution_time', 600); # 10 minutes // Get the list of category ids and weights $sql = "\n SELECT \n criteria.id, criteria.weights, cat.id AS catid, cat.option \n FROM \n #__jreviews_criteria AS criteria\n INNER JOIN \n #__jreviews_categories AS cat on cat.criteriaid = criteria.id\n "; $this->_db->setQuery($sql); $rows = $this->_db->loadObjectList(); foreach ($rows as $row) { $weights_check = trim($row->weights); if ($weights_check != '') { if ($row->catid > 0) { // Using $row->option, otherwise may overwrite values if there are dup catid's across components $weights[$row->catid . $row->option] = explode("\n", $row->weights); } } } # working in chunks to avoid memory overload $this->_db->setQuery("SELECT COUNT(*) FROM #__jreviews_comments"); $reviewCount = $this->_db->loadResult(); $leap = 1000; # configurable for ($offset = 0; $offset < $reviewCount; $offset += $leap) { // Get list of reviewids, category ids and ratings $sql = "\n SELECT \n Review.id, Review.pid AS lid, Review.mode, \n Rating.ratings, Rating.ratings_sum, Rating.ratings_qty\n FROM \n #__jreviews_comments AS Review\n LEFT JOIN \n #__jreviews_ratings AS Rating ON Rating.reviewid = Review.id\n ORDER BY\n Review.id\n LIMIT {$offset}, {$leap}\n "; # using left join, need comments table in any case for comment count $this->_db->setQuery($sql); $rows = $this->_db->loadObjectList(); // Recalculate the total rating sum foreach ($rows as $key => $row) { if (empty($row->ratings)) { continue; } // Load listings' Everywhere model $file_name = 'everywhere' . '_' . $row->mode; $class_name = inflector::camelize($file_name) . 'Model'; App::import('Model', $file_name, 'jreviews'); $this->Listing = new $class_name(); if (!isset($__listings[$row->mode . $row->lid])) { $listing = $this->Listing->findRow(array('conditions' => "Listing.{$this->Listing->realKey} = " . $row->lid), array()); $__listings[$row->mode . $row->lid] = $listing; } else { $listing = $__listings[$row->mode . $row->lid]; } if (!is_array($listing) || empty($listing) || !$listing) { continue; } $row->catid = array_key_exists('catid', $listing['Category']) ? $listing['Category']['cat_id'] : $listing['Listing']['cat_id']; $__listings[$row->mode . $row->lid]['cat_id'] = $row->catid; $ratings_sum = 0; $ratings = explode(",", $row->ratings); $quantity = $row->ratings_qty; if (@is_array($weights[$row->catid . $row->mode])) { $sumWeights = array_sum(array_intersect_key($weights[$row->catid . $row->mode], array_filter($ratings, create_function('$el', 'return is_numeric($el);')))); if ($sumWeights > 0) { foreach ($ratings as $key2 => $rating) { $ratings_sum += $rating * $weights[$row->catid . $row->mode][$key2] / $sumWeights; } $ratings_sum = $ratings_sum * $quantity; } $rows[$key]->ratings_sum = $ratings_sum; } else { $rows[$key]->ratings_sum = array_sum($ratings); } } // Update database records foreach ($rows as $row) { if (empty($row->ratings)) { continue; } $sql = "UPDATE #__jreviews_ratings SET ratings_sum = '{$row->ratings_sum}' WHERE reviewid = '{$row->id}'"; $this->_db->setQuery($sql); if (!$this->_db->query()) { # halting script on first error so to avoid possible further damage to the database data // Clear cache clearCache('', 'views'); clearCache('', '__data'); return "There was a problem updating the database for review ID {$row->id}.<br />Operation halted."; } } # unset before more db data is loaded into memory unset($rows); } $msg = 'Ratings averages update: Complete.<br /><br />'; // Update listing totals # reloading listing data for all listings. diving into chunks again $this->_db->setQuery("SELECT COUNT(DISTINCT pid) FROM #__jreviews_comments"); $listingCount = $this->_db->loadResult(); for ($offset = 0; $offset < $listingCount; $offset += $leap) { $sql = "\n SELECT DISTINCTROW\n Review.pid as lid, Review.mode\n FROM \n #__jreviews_comments AS Review\n ORDER BY\n Review.pid\n LIMIT {$offset}, {$leap}\n "; $this->_db->setQuery($sql); $rows = $this->_db->loadObjectList(); foreach ($rows as $row) { if (isset($__listings[$row->mode . $row->lid])) { $catid = $__listings[$row->mode . $row->lid]['cat_id']; if (!$this->Review->saveListingTotals($row->lid, $row->mode, !empty($weights[$catid . $row->mode]) ? $weights[$catid . $row->mode] : '')) { # halting script on first error so to avoid possible further damage to the database data // Clear cache clearCache('', 'views'); clearCache('', '__data'); return $msg . "There was an error recalculating totals for listing ID {}{$row->lid}}.<br />Operation halted."; } } } unset($rows); } // Clear cache clearCache('', 'views'); clearCache('', '__data'); return $msg . "Listings totals update: Complete."; }
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; } }