Ejemplo n.º 1
0
 function plgAfterSave(&$model)
 {
     appLogMessage('**** BEGIN JomSocial Plugin AfterSave', 'database');
     if ($this->inAdmin && !in_array($this->c->action, array('_saveModeration', '_save'))) {
         return;
     }
     if ($this->c->_user->id == 0) {
         $this->activities = str_replace('{actor}', __t("A guest", true), $this->activities);
     }
     include_once PATH_ROOT . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'core.php';
     if ($this->points) {
         include_once PATH_ROOT . 'components' . DS . 'com_community' . DS . 'libraries' . DS . 'userpoints.php';
     }
     switch ($model->name) {
         case 'Discussion':
             $this->_plgDiscussionAfterSave($model);
             break;
         case 'Favorite':
             $this->_plgFavoriteAfterSave($model);
             break;
         case 'Listing':
             $this->_plgListingAfterSave($model);
             break;
         case 'Review':
             $this->_plgReviewAfterSave($model);
             break;
         case 'Vote':
             $this->_plgVoteAfterSave($model);
             break;
     }
 }
 function getListingOwner($result_id)
 {
     $query = "\n            SELECT \n                Listing.created_by AS user_id, User.name, User.email \n            FROM \n                #__content AS Listing \n            LEFT JOIN\n                #__users AS User ON Listing.created_by = User.id                \n            WHERE \n                Listing.id = " . (int) $result_id;
     $this->_db->setQuery($query);
     appLogMessage($this->_db->getErrorMsg(), 'owner_listing');
     return current($this->_db->loadAssocList());
 }
Ejemplo n.º 3
0
 function getList($type, $limitstart, $limit, &$total)
 {
     // get the total number of records
     $query = "SELECT COUNT(*) FROM `#__jreviews_groups` WHERE type='{$type}'";
     $this->_db->setQuery($query);
     $total = $this->_db->loadResult();
     $query = "\n            SELECT `Group`.*, count(Field.fieldid) AS field_count" . "\n FROM #__jreviews_groups AS `Group`" . "\n LEFT JOIN #__jreviews_fields AS Field ON `Group`.groupid = Field.groupid" . "\n WHERE Group.type='{$type}'" . "\n GROUP BY `Group`.groupid" . "\n ORDER BY ordering LIMIT {$limitstart}, {$limit}";
     $this->_db->setQuery($query);
     $rows = $this->_db->loadObjectList();
     // Log message
     $message[] = '*********' . get_class($this) . ' | getList';
     $message[] = $this->_db->getQuery();
     $message[] = $this->_db->getErrorMsg();
     appLogMessage($message, 'database');
     if (!$rows) {
         $rows = array();
     }
     return $rows;
 }
 function getUsedCategories()
 {
     $query = "SELECT Component.{$this->categoryPrimaryKey} AS `Component.cat_id`,Component.name as `Component.cat_title`, Criteria.title AS `Component.criteria_title`" . "\n FROM #__core_acl_aro_groups AS Component" . "\n INNER JOIN #__jreviews_categories AS JreviewCategory ON Component.{$this->categoryPrimaryKey} = JreviewCategory.id AND JreviewCategory.`option` = '{$this->extension_alias}'" . "\n LEFT JOIN #__jreviews_criteria AS Criteria ON JreviewCategory.criteriaid = Criteria.id" . "\n LIMIT {$this->offset},{$this->limit}";
     $this->_db->setQuery($query);
     appLogMessage("getUsedCategories\n" . $this->_db->getQuery(), 'everywhere');
     $results = $this->_db->loadObjectList();
     appLogMessage($this->_db->getErrorMsg(), 'everywhere');
     $results = $this->__reformatArray($results);
     $results = $this->changeKeys($results, 'Component', 'cat_id');
     $query = "SELECT count(JreviewCategory.id)" . "\n FROM #__jreviews_categories AS JreviewCategory" . "\n WHERE JreviewCategory.`option` = '{$this->extension_alias}'";
     $this->_db->setQuery($query);
     $count = $this->_db->loadResult();
     return array('rows' => $results, 'count' => $count);
 }
 function plgAfterSave(&$model)
 {
     if (!isset($model->data['Email']) || !Sanitize::getInt($model->data['Email'], 'send')) {
         return false;
     }
     # 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;
     $mail->AddReplyTo($configMailFrom, $configFromName);
     //    	$model->data[$this->notifyModel->name]['key'] = $value;
     $model->data['Email']['body'] = urldecode($model->data['__raw']['Email']['body']);
     // Send html email
     # In this observer model we just use the existing data to send the email notification
     switch ($this->notifyModel->name) {
         // Notification for claims moderation
         case 'Claim':
             if ($model->data['Email']['subject'] != '') {
                 $subject = $model->data['Email']['subject'];
                 $subject = str_ireplace('{name}', $model->data['Email']['name'], $subject);
                 $subject = str_ireplace('{listing_title}', $model->data['Email']['listing_title'], $subject);
             } else {
                 switch ($model->data['Claim']['approved']) {
                     case 1:
                         $subject = __a("Your claim has been approved", true);
                         break;
                     case -1:
                         $subject = __a("Your claim has been rejected", true);
                         break;
                     case 0:
                         $subject = __a("Your claim has been reviewed, but still pending moderation", true);
                         break;
                 }
             }
             // Get permalink
             $listing_id = $model->data['Listing']['id'];
             $listing = $this->controller->Listing->findRow(array('conditions' => 'Listing.id = ' . $listing_id), array('afterFind'));
             $permalink = cmsFramework::makeAbsUrl($listing['Listing']['url'], array('sef' => true));
             $message = $model->data['Email']['body'];
             $message = str_ireplace('{name}', $model->data['Email']['name'], $message);
             $message = str_ireplace('{listing_title}', $model->data['Email']['listing_title'], $message);
             $message = str_ireplace(array('{link}', '{url}'), $permalink, $message);
             if ($message != '') {
                 $mail->Subject = $subject;
                 // Convert line breaks to br tags if html code not found on the message body
                 $mail->Body = nl2br($message);
                 $mail->AddAddress($model->data['Email']['email']);
                 if (!$mail->Send()) {
                     appLogMessage(array("Admin claim moderation message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications');
                 }
             }
             break;
             # Notification for discussion post moderation
         # Notification for discussion post moderation
         case 'Discussion':
             if ($model->data['Email']['subject'] != '') {
                 $subject = $model->data['Email']['subject'];
                 $subject = str_ireplace('{name}', $model->data['Email']['name'], $subject);
                 $subject = str_ireplace('{review_title}', $model->data['Email']['review_title'], $subject);
             } else {
                 switch ($model->data['Discussion']['approved']) {
                     case 1:
                         $subject = __a("Your comment has been approved", true);
                         break;
                     case -1:
                         $subject = __a("Your comment has been rejected", true);
                         break;
                 }
             }
             // Get permalink
             $this->controller->EverywhereAfterFind = true;
             $this->controller->Review->runProcessRatings = false;
             $review = $this->controller->Review->findRow(array('conditions' => array('Review.id = ' . $model->data['Discussion']['review_id'])));
             $this->controller->viewVars['review'] = $review;
             // Make it available to other plugins
             App::import('helper', 'routes', 'jreviews');
             $Routes = ClassRegistry::getClass('RoutesHelper');
             $permalink = $Routes->reviewDiscuss('', $review, array('listing' => $review, 'return_url' => true));
             $permalink = cmsFramework::makeAbsUrl($permalink);
             $message = $model->data['Email']['body'];
             $message = str_ireplace('{name}', $model->data['Email']['name'], $message);
             $message = str_ireplace(array('{link}', '{url}'), $permalink, $message);
             $message = str_ireplace('{review_title}', $model->data['Email']['review_title'], $message);
             if ($message != '') {
                 $mail->Subject = $subject;
                 // Convert line breaks to br tags if html code not found on the message body
                 $mail->Body = nl2br($message);
                 $mail->AddAddress($model->data['Email']['email']);
                 if (!$mail->Send()) {
                     appLogMessage(array("Admin post discussion moderation message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications');
                 }
             }
             break;
             // Notification for listing moderation
         // Notification for listing moderation
         case 'Listing':
             if (Sanitize::getInt($model->data, 'moderation')) {
                 if ($model->data['Email']['subject'] != '') {
                     $subject = $model->data['Email']['subject'];
                     $subject = str_ireplace('{name}', $model->data['Email']['name'], $subject);
                     $subject = str_ireplace('{listing_title}', $model->data['Email']['listing_title'], $subject);
                 } else {
                     switch ($model->data['Listing']['state']) {
                         case 1:
                             $subject = __a("Your listing has been approved", true);
                             break;
                         case -2:
                             $subject = __a("Your listing has been rejected", true);
                             break;
                         case 0:
                             $subject = __a("Your listing has been reviewed, but it is still pending moderation", true);
                             break;
                     }
                 }
                 // Get permalink
                 $listing_id = $model->data['Listing']['id'];
                 $listing = $this->controller->Listing->findRow(array('conditions' => 'Listing.id = ' . $listing_id), array('afterFind'));
                 $permalink = cmsFramework::makeAbsUrl($listing['Listing']['url'], array('sef' => true));
                 $message = $model->data['Email']['body'];
                 $message = str_ireplace('{name}', $model->data['Email']['name'], $message);
                 $message = str_ireplace(array('{link}', '{url}'), $permalink, $message);
                 $message = str_ireplace('{listing_title}', $model->data['Email']['listing_title'], $message);
                 if ($message != '') {
                     $mail->Subject = $subject;
                     // Convert line breaks to br tags if html code not found on the message body
                     $mail->Body = nl2br($message);
                     $mail->AddAddress($model->data['Email']['email']);
                     if (!$mail->Send()) {
                         appLogMessage(array("Admin listing moderation message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications');
                     }
                 }
             }
             break;
             // Notification for reviews moderation
         // Notification for reviews moderation
         case 'Review':
             if (Sanitize::getInt($model->data, 'moderation')) {
                 if ($model->data['Email']['subject'] != '') {
                     $subject = $model->data['Email']['subject'];
                     $subject = str_ireplace('{name}', $model->data['Email']['name'], $subject);
                     $subject = str_ireplace('{listing_title}', $model->data['Email']['listing_title'], $subject);
                     $subject = str_ireplace('{review_title}', $model->data['Email']['review_title'], $subject);
                 } else {
                     switch ($model->data['Review']['published']) {
                         case 1:
                             $subject = __a("Your review has been approved", true);
                             break;
                         case -1:
                             $subject = __a("Your review has been rejected", true);
                             break;
                         case 0:
                             $subject = __a("Your review has been reviewed, but still pending moderation", true);
                             break;
                     }
                 }
                 // Get permalink
                 $this->controller->EverywhereAfterFind = true;
                 $this->controller->Review->runProcessRatings = false;
                 $review_id = $model->data['Review']['id'];
                 $review = $this->controller->Review->findRow(array('conditions' => array('Review.id = ' . $review_id)));
                 $this->controller->viewVars['review'] = $review;
                 // Make it available to other plugins
                 App::import('helper', 'routes', 'jreviews');
                 $Routes = ClassRegistry::getClass('RoutesHelper');
                 $permalink = $Routes->reviewDiscuss('', $review, array('listing' => $review, 'return_url' => true));
                 $permalink = cmsFramework::makeAbsUrl($permalink);
                 $message = $model->data['Email']['body'];
                 $message = str_ireplace('{name}', $model->data['Email']['name'], $message);
                 $message = str_ireplace(array('{link}', '{url}'), $permalink, $message);
                 $message = str_ireplace('{listing_title}', $model->data['Email']['listing_title'], $message);
                 $message = str_ireplace('{review_title}', $model->data['Email']['review_title'], $message);
                 if ($message != '') {
                     $mail->Subject = $subject;
                     // Convert line breaks to br tags if html code not found on the message body
                     $mail->Body = nl2br($message);
                     $mail->AddAddress($model->data['Email']['email']);
                     if (!$mail->Send()) {
                         appLogMessage(array("Admin review moderation message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications');
                     }
                 }
             }
             break;
             // Notification for owner reply to reviews moderation
         // Notification for owner reply to reviews moderation
         case 'OwnerReply':
             if ($model->data['Email']['subject'] != '') {
                 $subject = $model->data['Email']['subject'];
                 $subject = str_ireplace('{name}', $model->data['Email']['name'], $subject);
                 $subject = str_ireplace('{listing_title}', $model->data['Email']['listing_title'], $subject);
                 $subject = str_ireplace('{review_title}', $model->data['Email']['review_title'], $subject);
             } else {
                 switch ($model->data['OwnerReply']['owner_reply_approved']) {
                     case 1:
                         $subject = __a("Your reply has been approved", true);
                         break;
                     case -1:
                         $subject = __a("Your reply has been rejected", true);
                         break;
                     case 0:
                         $subject = __a("Your reply has been reviewed, but still pending moderation", true);
                         break;
                 }
             }
             // Get permalink
             $this->controller->EverywhereAfterFind = true;
             $this->controller->Review->runProcessRatings = false;
             $review_id = $model->data['OwnerReply']['id'];
             $review = $this->controller->Review->findRow(array('conditions' => array('Review.id = ' . $review_id)));
             $this->controller->viewVars['review'] = $review;
             // Make it available to other plugins
             App::import('helper', 'routes', 'jreviews');
             $Routes = ClassRegistry::getClass('RoutesHelper');
             $permalink = $Routes->reviewDiscuss('', $review, array('listing' => $review, 'return_url' => true));
             $permalink = cmsFramework::makeAbsUrl($permalink);
             $message = $model->data['Email']['body'];
             $message = str_ireplace('{name}', $model->data['Email']['name'], $message);
             $message = str_ireplace(array('{link}', '{url}'), $permalink, $message);
             $message = str_ireplace('{listing_title}', $model->data['Email']['listing_title'], $message);
             $message = str_ireplace('{review_title}', $model->data['Email']['review_title'], $message);
             if ($message != '') {
                 $mail->Subject = $subject;
                 // Convert line breaks to br tags if html code not found on the message body
                 $mail->Body = nl2br($message);
                 $mail->AddAddress($model->data['Email']['email']);
                 if (!$mail->Send()) {
                     appLogMessage(array("Admin owner reply moderation message was not sent.", "Mailer error: " . $mail->ErrorInfo), 'notifications');
                 }
             }
             break;
     }
     unset($mail);
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Saves review ratings, fields and recalculates listing totals
  * 
  * @param mixed $status
  */
 function afterSave($status)
 {
     $isNew = Sanitize::getBool($this->data, 'new');
     $ratings_col_empty = Sanitize::getBool($this->data, 'ratings_col_empty');
     $weights = '';
     if (isset($this->data['Criteria']) && Sanitize::getInt($this->data['Criteria'], 'state') == 1) {
         // Process rating data
         // to account for "n/a" values in the ratings and weights, changing the source arrays rather than the whole computation procedure.
         // init variables
         $applicableRatings = array_filter($this->data['Rating']['ratings'], create_function('$el', 'return is_numeric($el);'));
         $ratings_qty = count($applicableRatings);
         $this->data['average_rating'] = $ratings_sum = 'na';
         if ($ratings_qty > 0) {
             if (trim($this->data['Criteria']['weights']) != '') {
                 $weights = explode("\n", $this->data['Criteria']['weights']);
                 // we have to remove the irrelevant weights so to produce clean weights_sum to be used later for proportion calculations
                 $sumWeights = array_sum(array_intersect_key($weights, $applicableRatings));
                 if ($sumWeights > 0) {
                     foreach ($applicableRatings as $key => $rating) {
                         $ratings_sum += $rating * $weights[$key] / $sumWeights;
                     }
                     $ratings_sum = $ratings_sum * $ratings_qty;
                     // This is not the real sum, but it is divided again in the queries.
                 }
             } else {
                 $ratings_sum = array_sum($applicableRatings);
             }
             // Makes average rating easily available in Everywhere model afterSave method
             $this->data['average_rating'] = $ratings_sum / $ratings_qty;
             $this->data['Rating']['ratings_sum'] = $ratings_sum;
             $this->data['Rating']['ratings_qty'] = $ratings_qty;
         }
         # if ( $ratings_qty > 0  )i
         $this->data['Rating']['reviewid'] = $this->data['Review']['id'];
         $this->data['Rating']['ratings'] = implode(',', $this->data['Rating']['ratings']);
         # Save rating fields
         appLogMessage('*******Save standard rating fields', 'database');
         if ($isNew || !$isNew && $ratings_col_empty) {
             $save = $this->insert('#__jreviews_ratings', 'Rating', $this->data, 'reviewid');
         } else {
             $save = $this->update('#__jreviews_ratings', 'Rating', $this->data, 'reviewid');
         }
         if (!$save) {
             appLogMessage('*******There was a problem saving the ratings', 'database');
             return false;
         }
     }
     # if ( $criteria['Criteria']['state'] == 1 )
     // save listing totals
     if (!$this->saveListingTotals($this->data['Review']['pid'], $this->data['Review']['mode'], $weights)) {
         return false;
     }
     # Save custom fields
     appLogMessage('*******Save review custom fields', 'database');
     $this->data['Field']['Review']['reviewid'] = $this->data['Review']['id'];
     App::import('Model', 'field', 'jreviews');
     $FieldModel = ClassRegistry::getClass('FieldModel');
     if (count($this->data['Field']['Review']) > 1 && !$FieldModel->save($this->data, 'review', $isNew, $this->valid_fields)) {
         return false;
     }
 }
Ejemplo n.º 7
0
 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;
     }
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 function update($table, $alias, &$data, $keyName, $updateNulls = true)
 {
     $fmtsql = "UPDATE {$table} SET %s WHERE %s";
     $tmp = array();
     foreach ($data[$alias] as $k => $v) {
         if (is_array($v) or is_object($v) or $k[0] == '_' or $v === null and !$updateNulls) {
             continue;
         }
         // use primary key to locate update record
         if ($k == $keyName) {
             $where = "{$keyName}= " . $this->Quote($v);
             continue;
         }
         if ($v === null) {
             if ($updateNulls) {
                 $val = 'NULL';
             } else {
                 continue;
             }
         } else {
             $val = $this->Quote($v);
         }
         $tmp[] = "`{$k}`= {$val}";
     }
     if (!isset($tmp)) {
         return true;
     }
     if (!isset($where)) {
         die('Model class update method - no key value');
     }
     $this->_db->setQuery(sprintf($fmtsql, implode(",", $tmp), $where));
     $update = $this->_db->query();
     $message[] = '*********' . get_class($this) . ' | Update';
     $message[] = $this->_db->getQuery();
     $message[] = $this->_db->getErrorMsg();
     appLogMessage($message, 'database');
     if (!$update) {
         return false;
     }
     return true;
 }
Ejemplo n.º 10
0
 function query($query, $type = 'query', $param = '')
 {
     $message = array();
     $this->_db->setQuery($query);
     $message[] = '*********' . get_class($this) . ' | handwritten query';
     $message[] = $this->_db->getQuery();
     if ($param != '') {
         $result = $this->_db->{$type}($param);
     } else {
         $result = $this->_db->{$type}();
     }
     if ($this->_db->getErrorMsg()) {
         $message[] = '*********' . get_class($this) . ' | handwritten ERROR';
         $message[] = $this->_db->getErrorMsg();
     }
     appLogMessage($message, 'database');
     return $result;
 }