function reviews() { $access = $this->cmsVersion == CMS_JOOMLA15 ? $this->Access->getAccessId() : $this->Access->getAccessLevels(); $feed_filename = PATH_ROOT . 'cache' . DS . 'jreviewsfeed_' . md5($access . $this->here) . '.xml'; $this->Feeds->useCached($feed_filename, 'reviews'); $extension = Sanitize::getString($this->params, 'extension', 'com_content'); $cat_id = Sanitize::getInt($this->params, 'cat'); $section_id = Sanitize::getInt($this->params, 'section'); $dir_id = Sanitize::getInt($this->params, 'dir'); $listing_id = Sanitize::getInt($this->params, 'id'); $this->encoding = cmsFramework::getCharset(); $feedPage = null; $this->EverywhereAfterFind = true; // Triggers the afterFind in the Observer Model $this->limit = $this->Config->rss_limit; $rss = array('title' => $this->Config->rss_title, 'link' => WWW_ROOT, 'description' => $this->Config->rss_description, 'image_url' => WWW_ROOT . "images/stories/" . $this->Config->rss_image, 'image_link' => WWW_ROOT); $queryData = array('conditions' => array('Review.published = 1', "Review.mode = '{$extension}'"), 'fields' => array('Review.mode AS `Review.extension`'), 'limit' => $this->limit, 'order' => array('Review.created DESC')); if ($extension == 'com_content') { $queryData['conditions'][] = 'Listing.state = 1'; $queryData['conditions'][] = '( Listing.publish_up = "' . NULL_DATE . '" OR Listing.publish_up <= "' . _CURRENT_SERVER_TIME . '" )'; $queryData['conditions'][] = '( Listing.publish_down = "' . NULL_DATE . '" OR Listing.publish_down >= "' . _CURRENT_SERVER_TIME . '" )'; # Shows only links users can access if ($this->cmsVersion == CMS_JOOMLA15) { $access_id = $this->Access->getAccessId(); $queryData['conditions'][] = 'Listing.access <= ' . $access_id; $queryData['conditions'][] = 'Category.access <= ' . $access_id; } else { $cat_id > 0 and $cat_id = array_keys($this->Category->getChildren($cat_id)); $access_id = $this->Access->getAccessLevels(); $queryData['conditions'][] = 'Listing.access IN ( ' . $access_id . ')'; $queryData['conditions'][] = 'Category.access IN ( ' . $access_id . ')'; } } if (!empty($cat_id) && $extension == 'com_content') { // Category feeds only supported for core content $queryData['conditions'][] = 'JreviewsCategory.id IN (' . $this->quote($cat_id) . ')'; $feedPage = 'category'; } elseif ($section_id > 0 && $extension == 'com_content') { $queryData['conditions'][] = 'Listing.sectionid= ' . $section_id; $feedPage = 'section'; } elseif ($dir_id > 0 && $extension == 'com_content') { $queryData['conditions'][] = 'JreviewsCategory.dirid= ' . $dir_id; $feedPage = 'directory'; } elseif ($extension != 'com_content') { unset($this->Review->joins['listings'], $this->Review->joins['jreviews_categories'], $this->Review->joins['listings']); $feedPage = 'everywhere'; } if ($listing_id > 0) { $queryData['conditions'][] = 'Review.pid = ' . $listing_id; $feedPage = 'listing'; } # Don't run it here because it's run in the Everywhere Observer Component $this->Review->runProcessRatings = false; $reviews = $this->Review->findAll($queryData); $this->set(array('feedPage' => $feedPage, 'encoding' => $this->encoding, 'rss' => $rss, 'reviews' => $reviews)); return $this->Feeds->saveFeed($feed_filename, 'reviews'); }
function startup(&$controller) { # Check feed cache if (Sanitize::getString($controller->params, 'action') == 'xml') { $this->useCached(PATH_ROOT . DS . 'cache' . DS . 'jreviewsfeed_' . md5($controller->here) . '.xml'); } $this->encoding = cmsFramework::getCharset(); $this->params =& $controller->params; $this->c =& $controller; }
function reviews() { $extension = Sanitize::getString($this->params, 'extension', 'com_content'); $cat_id = Sanitize::getInt($this->params, 'cat'); $section_id = Sanitize::getInt($this->params, 'section'); $dir_id = Sanitize::getInt($this->params, 'dir'); $listing_id = Sanitize::getInt($this->params, 'id'); $this->encoding = cmsFramework::getCharset(); $feedPage = null; $this->EverywhereAfterFind = true; // Triggers the afterFind in the Observer Model $this->limit = $this->Config->rss_limit; $rss = array('title' => $this->Config->rss_title, 'link' => WWW_ROOT, 'description' => $this->Config->rss_description, 'image_url' => WWW_ROOT . "images/stories/" . $this->Config->rss_image, 'image_link' => WWW_ROOT); $queryData = array('conditions' => array('Review.published = 1', "Review.mode = '{$extension}'"), 'fields' => array('Review.mode AS `Review.extension`'), 'limit' => $this->limit, 'order' => array('Review.created DESC')); if ($cat_id > 0 && $extension == 'com_content') { // Category feeds only supported for core content $queryData['conditions'][] = 'JreviewsCategory.id= ' . $cat_id; // $queryData['joins'] = $this->Listing->joinsReviews; $feedPage = 'category'; } elseif ($section_id > 0 && $extension == 'com_content') { $queryData['conditions'][] = 'Listing.sectionid= ' . $section_id; // $queryData['joins'] = $this->Listing->joinsReviews; $feedPage = 'section'; } elseif ($dir_id > 0 && $extension == 'com_content') { $queryData['conditions'][] = 'JreviewsCategory.dirid= ' . $dir_id; // $queryData['joins'] = $this->Listing->joinsReviews; $feedPage = 'directory'; } elseif ($extension != 'com_content') { unset($this->Review->joins['listings'], $this->Review->joins['jreviews_categories'], $this->Review->joins['listings']); $feedPage = 'everywhere'; } if ($listing_id > 0) { $queryData['conditions'][] = 'Review.pid = ' . $listing_id; $feedPage = 'listing'; } # Don't run it here because it's run in the Everywhere Observer Component $this->Review->runProcessRatings = false; $reviews = $this->Review->findAll($queryData); $this->set(array('feedPage' => $feedPage, 'encoding' => $this->encoding, 'rss' => $rss, 'reviews' => $reviews)); return $this->Feeds->saveFeed(PATH_ROOT . DS . 'cache' . DS . 'jreviewsfeed_' . md5($this->here) . '.xml', 'reviews'); }
function _send() { $recipient = ''; $error = array(); $response = array(); $this->components = array('security'); $this->__initComponents(); if ($this->invalidToken) { $error[] = 'jQuery("#jr_inquiryTokenValidation").show();'; return json_encode(array('error' => $this->makeJS($error))); } // Required fields $fields = array('name', 'email', 'text'); // $fields = array('name','email','phone','text'); foreach ($fields as $id) { $input_id = '#jr_inquiry' . Inflector::camelize($id) . 'Validation'; if ($this->data['Inquiry'][$id] == '') { $error[] = 'jQuery("' . $input_id . '").show();'; } else { $reponse[] = 'jQuery("' . $input_id . '").hide();'; } } # Validate user's email $this->Listing->validateInput($this->data['Inquiry']['email'], "email", "email", __t("You must fill in a valid email address.", true), 1); # Validate security code if ($this->Access->showCaptcha()) { if (!isset($this->data['Captcha']['code'])) { $this->Listing->validateSetError("code", __t("The security code you entered was invalid.", true)); } elseif ($this->data['Captcha']['code'] == '') { $this->Listing->validateSetError("code", __t("You must fill in the security code.", true)); } else { if (!$this->Captcha->checkCode($this->data['Captcha']['code'], $this->ipaddress)) { $this->Listing->validateSetError("code", __t("The security code you entered was invalid.", true)); } } } # Process validation errors $validation = $this->Listing->validateGetErrorArray(); $validation = is_array($validation) ? implode("<br />", $validation) : ''; if (!empty($error) || $validation != '') { // Reissue form token if (isset($this->Security)) { $error[] = "jQuery('#jr_inquiryToken').val('" . $this->Security->reissueToken() . "');"; } if ($this->Access->showCaptcha()) { // Replace captcha with new instance $captcha = $this->Captcha->displayCode(); $error[] = "jQuery('#captcha').attr('src','{$captcha['src']}');"; $error[] = "jQuery('#jr_inquiryCode').val('');"; } if ($validation != '') { $error[] = "jQuery('#jr_inquiryCodeValidation').html('{$validation}').show();"; } return json_encode(array('error' => $this->makeJS($error))); } // Now we can send the email # 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'); # Get the recipient email Configure::write('Cache.query', false); $listing = $this->Listing->findRow(array('fields' => array('User.email AS `Listing.email`'), 'conditions' => array('Listing.id = ' . (int) $this->data['Inquiry']['listing_id']))); $url = cmsFramework::makeAbsUrl($listing['Listing']['url'], array('sef' => true)); $link = '<a href="' . $url . '">' . $listing['Listing']['title'] . '</a>'; switch ($this->Config->inquiry_recipient) { case 'owner': $recipient = Sanitize::getString($listing['Listing'], 'email'); break; case 'admin': $recipient = $configMailFrom; break; case 'field': if (isset($listing['Field']['pairs'][$this->Config->inquiry_field])) { $recipient = $listing['Field']['pairs'][$this->Config->inquiry_field]['value'][0]; } break; } if ($recipient == '') { $recipient = $configMailFrom; } 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($this->data['Inquiry']['email']); $mail->AddAddress($recipient); $mail->Subject = sprintf(__t("New inquiry for: %s", true), $listing['Listing']['title']); $mail->Body = sprintf(__t("From: %s", true), Sanitize::getString($this->data['Inquiry'], 'name')) . "<br />"; $mail->Body .= sprintf(__t("Email: %s", true), Sanitize::getString($this->data['Inquiry'], 'email')) . "<br />"; // $mail->Body .= sprintf(__t("Phone number: %s",true),Sanitize::getString($this->data['Inquiry'],'phone')) . "<br />"; $mail->Body .= sprintf(__t("Listing: %s", true), $listing['Listing']['title']) . "<br />"; $mail->Body .= sprintf(__t("Listing link: %s", true), $link) . "<br />"; $mail->Body .= $this->data['Inquiry']['text']; if (!$mail->Send()) { unset($mail); $error[] = 'jQuery("#jr_inquiryTokenValidation").show();'; return json_encode(array('error' => $this->makeJS($error))); } $mail->ClearAddresses(); $bccAdmin = $this->Config->inquiry_bcc; if ($bccAdmin != '' && $bccAdmin != $recipient) { $mail->AddAddress($bccAdmin); $mail->Send(); } unset($mail); return json_encode(array('error' => $this->makeJS($response), 'html' => true)); }
/** * Dynamic form creation for custom fields using custom layout - {field tags} in view file * * @param unknown_type $formFields * @param unknown_type $fieldLocation * @param unknown_type $search * @param unknown_type $selectLabel * @return array of form inputs for each field */ function getFormFields(&$formFields, $fieldLocation = 'listing', $search = null, $selectLabel = 'Select') { if (!is_array($formFields)) { return ''; } $groupSet = array(); $fieldLocation = Inflector::camelize($fieldLocation); foreach ($formFields as $group => $fields) { $inputs = array(); foreach ($fields['Fields'] as $key => $value) { // Convert radio button to checkbox if multiple search is enabled in the config settings if ($search && $this->Config->search_field_conversion && $value['type'] == 'radiobuttons') { $value['type'] = 'checkboxes'; } $inputs["data[Field][{$fieldLocation}][{$key}]"] = array('id' => $value['name'] . $this->form_id, 'type' => $this->types[$value['type']]); // $inputs["data[Field][$fieldLocation][$key]"]['label'] = $value['title']; $inputs["data[Field][{$fieldLocation}][{$key}]"]['div'] = array(); # Add tooltip if (!$search && Sanitize::getString($value, 'description', null)) { $inputs["data[Field][{$fieldLocation}][{$key}]"]['label']['text'] .= '<span class="jr_infoTip" title="' . htmlspecialchars($value['description'], ENT_QUOTES, cmsFramework::getCharset()) . '"> </span>'; } // Assign field classes switch ($value['type']) { case 'decimal': case 'integer': $inputs["data[Field][{$fieldLocation}][{$key}]"]['class'] = 'shortField'; break; case 'website': $inputs["data[Field][{$fieldLocation}][{$key}]"]['class'] = 'mediumField'; break; case 'text': $inputs["data[Field][{$fieldLocation}][{$key}]"]['class'] = 'mediumField'; break; } if (in_array($value['type'], $this->multipleTypes)) { $inputs["data[Field][{$fieldLocation}][{$key}]"]['multiple'] = 'multiple'; $inputs["data[Field][{$fieldLocation}][{$key}]"]['size'] = $value['properties']['size']; } if (isset($value['optionList']) && $value['type'] == 'select') { $value['optionList'] = array('' => $selectLabel) + $value['optionList']; } if (isset($value['optionList'])) { $inputs["data[Field][{$fieldLocation}][{$key}]"]['options'] = $value['optionList']; } # Add click2add capability for select lists if ($fieldLocation == 'Listing' && !$search && $this->types[$value['type']] == 'select' && $value['properties']['click2add']) { $click2AddLink = $this->Html->link($this->Html->image($this->viewImages . 'option_add.png', array('border' => 0, 'style' => 'margin-left:5px;')), 'javascript:void(0);', array('sef' => false, 'onclick' => "jQuery('#click2Add_{$value['field_id']}').toggle('slow');")); $click2AddInput = $this->Form->text('option' . $value['field_id'], array('id' => 'option' . $value['field_id'])); $click2AddButton = $this->Form->button(__t("Submit", true), array('onclick' => "submitOption({$value['field_id']},'{$value['name']}');", 'div' => false, 'id' => 'submitButton' . $value['field_id'], 'class' => 'button')); $inputs["data[Field][{$fieldLocation}][{$key}]"]['after'] = $click2AddLink . "<div id='click2Add_{$value['field_id']}' class='jr_fieldDiv jr_newFieldOption'>" . $click2AddInput . ' ' . $click2AddButton . "<span id='spinner" . $value['field_id'] . "' style='display: none;'><img alt='loading' src='" . $this->viewImages . "loading.gif' /></span>" . '</div>'; } # Prefill values when editing if (isset($value['selected'])) { $inputs["data[Field][{$fieldLocation}][{$key}]"]['value'] = $value['selected']; } # Add search operator fields for date, decimal and integer fields if ($search && in_array($value['type'], $this->operatorTypes)) { $options = array('equal' => '=', 'higher' => '>=', 'lower' => '<=', 'between' => __t("between", true)); $inputs["data[Field][{$fieldLocation}][{$key}]"]['multiple'] = true; // convert field to array input for range searches $attributes = array('id' => $key . 'high', 'multiple' => true, 'class' => 'shortField'); $selected = ''; if ($this->types[$value['type']] == 'date') { $attributes['class'] = 'dateField datepicker'; } // This is the high value input in a range search $inputs["data[Field][{$fieldLocation}][{$key}]"]['after'] = '<span id="' . $key . 'highDiv" style="display:none;"> ' . $this->Form->text("data[Field][Listing][{$key}]", $attributes) . '</span>'; $inputs["data[Field][{$fieldLocation}][{$key}]"]['between'] = $this->Form->select("data[Field][Listing][{$key}_operator]", $options, $selected, array('class' => 'jr_dateOperator input', 'onchange' => "jreviews.search.showRange(this,'{$key}high');")); } # Input styling if ($this->types[$value['type']] == 'date') { $inputs["data[Field][{$fieldLocation}][{$key}]"]['class'] = 'dateField datepicker'; $inputs["data[Field][{$fieldLocation}][{$key}]"]['readonly'] = 'readonly'; } if (in_array($this->types[$value['type']], $this->legendTypes)) { // Input styling $inputs["data[Field][{$fieldLocation}][{$key}]"]['option_class'] = 'jr_fieldOption'; $inputs["data[Field][{$fieldLocation}][{$key}]"]['after'] = $this->Html->div('clr', ' '); // To break the float } } $groupSet[$group] = array('fieldset' => false, 'legend' => false); foreach ($inputs as $dataKey => $dataValue) { $groupSet[$group][$dataKey] = $dataValue; } } $output = array(); foreach ($groupSet as $group => $form) { $output = array_merge($output, $this->Form->inputs($form, null, null, true)); } return $output; }
function compareCheckbox($listing) { App::import('Helper', 'routes', 'jreviews'); $Routes = ClassRegistry::getClass('RoutesHelper'); $listing_title = htmlspecialchars($listing['Listing']['title'], ENT_QUOTES, cmsFramework::getCharset()); $listing_id = $listing['Listing']['listing_id']; $listing_url = $Routes->content($listing['Listing']['title'], $listing, array('return_url' => true)); $checkbox = '<input type="checkbox" class="checkListing" name="' . $listing_title . '" id="listing' . $listing_id . '" value="' . $listing_id . '" /> <label class="lbCompare" for="listing' . $listing_id . '">' . __t("Compare", true) . '</label>'; $listing_type = '<span id="listingID' . $listing_id . '" class="listingType' . $listing['Criteria']['criteria_id'] . '" style="display:none;">' . $listing['Criteria']['title'] . '</span>'; $url = '<span class="listingUrl' . $listing_id . '" style="display:none;">' . $listing_url . '</span>'; return '<span class="compareListing jrButton">' . $checkbox . $listing_type . $url . '</span>'; }
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; }
function _save() { /******************************************************************* * This method is processed inside an iframe * To access any of the DOM elements via jQuery it's necessary to prepend * all jQuery calls with $parentFrame (i.e. $parentFrame.jQuery) ********************************************************************/ $this->autoRender = false; $this->autoLayout = false; $response = array(); $parentFrame = 'window.parent'; $validation = ''; $listing_id = Sanitize::getInt($this->data['Listing'], 'id', 0); $isNew = $this->Listing->isNew = $listing_id == 0 ? true : false; $this->data['email'] = Sanitize::getString($this->data, 'email'); $this->data['name'] = Sanitize::getString($this->data, 'name'); $this->data['categoryid_hidden'] = Sanitize::getInt($this->data['Listing'], 'categoryid_hidden'); $cat_id = Sanitize::getVar($this->data['Listing'], 'catid'); $this->data['Listing']['catid'] = is_array($cat_id) ? (int) array_pop(array_filter($cat_id)) : (int) $cat_id; /*J16*/ $this->data['Listing']['title'] = Sanitize::getString($this->data['Listing'], 'title', ''); $this->data['Listing']['created_by_alias'] = Sanitize::getString($this->data, 'name', ''); if ($this->cmsVersion == CMS_JOOMLA15) { $this->data['sectionid_hidden'] = Sanitize::getInt($this->data['Listing'], 'sectionid_hidden'); $this->data['Listing']['sectionid'] = Sanitize::getInt($this->data['Listing'], 'sectionid'); } else { $this->data['Listing']['language'] = '*'; $this->data['Listing']['access'] = 1; } $category_id = $this->data['Listing']['catid'] ? $this->data['Listing']['catid'] : $this->data['categoryid_hidden']; # Get criteria info $criteria = $this->Criteria->findRow(array('conditions' => array('Criteria.id = (SELECT criteriaid FROM #__jreviews_categories WHERE id = ' . (int) $category_id . ' AND `option` = "com_content") '))); if (!$criteria) { $validation = __t("The category selected is invalid.", true, true); $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "{$parentFrame}.jQuery('.button').removeAttr('disabled');"; $response[] = "{$parentFrame}.jQuery('.jr_loadingSmall').hide();"; return $this->makeJS($response); } $this->data['Criteria']['id'] = $criteria['Criteria']['criteria_id']; # Override global configuration isset($criteria['ListingType']) and $this->Config->override($criteria['ListingType']['config']); # Perform access checks if ($isNew && !$this->Access->canAddListing()) { return $this->makeJS("{$parentFrame}.s2Alert('" . __t("You are not allowed to submit listings in this category.", true, true) . "')"); } elseif (!$isNew) { $query = "SELECT created_by FROM #__content WHERE id = " . $listing_id; $this->_db->setQuery($query); $listing_owner = $this->_db->loadResult(); if (!$this->Access->canEditListing($listing_owner)) { return $this->makeJS("{$parentFrame}.s2Alert('" . s2Messages::accessDenied() . "')"); } } # Load the notifications observer model component and initialize it. # Done here so it only loads on save and not for all controlller actions. $this->components = array('security', 'notifications'); $this->__initComponents(); if ($this->invalidToken == true) { return $this->makeJS("{$parentFrame}.s2Alert('" . s2Messages::invalidToken() . "')"); } # Override configuration $category = $this->Category->findRow(array('conditions' => array('Category.id = ' . $this->data['Listing']['catid']))); $this->Config->override($category['ListingType']['config']); if ($this->Access->loadWysiwygEditor()) { $this->data['Listing']['introtext'] = Sanitize::stripScripts(Sanitize::stripWhitespace(Sanitize::getVar($this->data['__raw']['Listing'], 'introtext'))); $this->data['Listing']['fulltext'] = Sanitize::stripScripts(Sanitize::stripWhitespace(Sanitize::getVar($this->data['__raw']['Listing'], 'fulltext'))); $this->data['Listing']['introtext'] = html_entity_decode($this->data['Listing']['introtext'], ENT_QUOTES, cmsFramework::getCharset()); $this->data['Listing']['fulltext'] = html_entity_decode($this->data['Listing']['fulltext'], ENT_QUOTES, cmsFramework::getCharset()); } else { $this->data['Listing']['introtext'] = Sanitize::stripAll($this->data['Listing'], 'introtext', ''); if (isset($this->data['Listing']['fulltext'])) { $this->data['Listing']['fulltext'] = Sanitize::stripAll($this->data['Listing'], 'fulltext', ''); } else { $this->data['Listing']['fulltext'] = ''; } } $this->data['Listing']['introtext'] = str_replace('<br>', '<br />', $this->data['Listing']['introtext']); $this->data['Listing']['fulltext'] = str_replace('<br>', '<br />', $this->data['Listing']['fulltext']); if ($this->Access->canAddMeta()) { $this->data['Listing']['metadesc'] = Sanitize::getString($this->data['Listing'], 'metadesc'); $this->data['Listing']['metakey'] = Sanitize::getString($this->data['Listing'], 'metakey'); } // Title alias handling $slug = ''; $alias = Sanitize::getString($this->data['Listing'], 'alias'); if ($isNew && $alias == '') { $slug = S2Router::sefUrlEncode($this->data['Listing']['title']); if (trim(str_replace('-', '', $slug)) == '') { $slug = date("Y-m-d-H-i-s"); } } elseif ($alias != '') { // Alias filled in so we convert it to a valid alias $slug = S2Router::sefUrlEncode($alias); if (trim(str_replace('-', '', $slug)) == '') { $slug = date("Y-m-d-H-i-s"); } } $slug != '' and $this->data['Listing']['alias'] = $slug; # Check for duplicates switch ($this->Config->content_title_duplicates) { case 'category': // Checks for duplicates in the same category $query = "\r\n SELECT \r\n count(*) \r\n FROM \r\n #__content AS Listing WHERE Listing.title = " . $this->_db->Quote($this->data['Listing']['title']) . "\r\n AND Listing.state >= 0 \r\n AND Listing.catid = " . $this->data['Listing']['catid'] . (!$isNew ? " AND Listing.id <> " . $listing_id : ''); $this->_db->setQuery($query); $titleExists = $this->_db->loadResult(); break; case 'no': // Checks for duplicates all over the place $query = "\r\n SELECT \r\n count(*) \r\n FROM \r\n #__content AS Listing\r\n WHERE \r\n Listing.title = " . $this->_db->Quote($this->data['Listing']['title']) . "\r\n AND Listing.state >= 0\r\n " . (!$isNew ? " AND Listing.id <> " . $listing_id : ''); $this->_db->setQuery($query); $titleExists = $this->_db->loadResult(); break; case 'yes': // Duplicates are allowed, no checking necessary $titleExists = false; break; } if ($titleExists && $this->data['Listing']['title'] != '') { // if listing exists $validation = '<span>' . __t("A listing with that title already exists.", true, true) . "</span>"; $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "{$parentFrame}.jQuery('.button').removeAttr('disabled');"; $response[] = "{$parentFrame}.jQuery('.jr_loadingSmall').hide();"; return $this->makeJS($response); } // Review form display check logic used several times below $revFormSetting = $this->Config->content_show_reviewform; if ($revFormSetting == 'noteditors' && !$this->Config->author_review) { $revFormSetting = 'all'; } $revFormEnabled = !isset($this->data['review_optional']) && $this->Access->canAddReview() && $isNew && ($revFormSetting == 'all' && ($this->Config->author_review || $this->Config->user_reviews) || $revFormSetting == 'authors' && $this->Access->isJreviewsEditor($this->_user->id) || $revFormSetting == 'noteditors' && !$this->Access->isJreviewsEditor($this->_user->id)); // Validation of content default input fields if ($this->cmsVersion == CMS_JOOMLA15) { if (!$this->data['Listing']['catid'] || !$this->data['Listing']['sectionid']) { $this->Listing->validateSetError("sec_cat", __t("You need to select both a section and a category.", true)); } } else { !$this->data['Listing']['catid'] and $this->Listing->validateSetError("sec_cat", __t("You need to select a category.", true)); } // Validate only if it's a new listing if ($isNew) { if (!$this->_user->id) { $this->Listing->validateInput($this->data['name'], "name", "text", __t("You must fill in your name.", true), $this->Config->content_name == "required" ? 1 : 0); $this->Listing->validateInput($this->data['email'], "email", "email", __t("You must fill in a valid email address.", true), $this->Config->content_email == "required" ? 1 : 0); $this->data['name'] = Sanitize::getString($this->data, 'name', ''); $this->data['email'] = Sanitize::getString($this->data, 'email', ''); } else { $this->data['name'] = $this->_user->name; $this->data['email'] = $this->_user->email; } } $this->Listing->validateInput($this->data['Listing']['title'], "title", "text", __t("You must fill in a title for the new listing.", true, true), 1); # Validate listing custom fields $listing_valid_fields =& $this->Field->validate($this->data, 'listing', $this->Access); $this->Listing->validateErrors = array_merge($this->Listing->validateErrors, $this->Field->validateErrors); $this->Listing->validateInput($this->data['Listing']['introtext'], "introtext", "text", __t("You must fill in a summary for the new listing.", true, true), $this->Config->content_summary == "required" ? 1 : 0); $this->Listing->validateInput($this->data['Listing']['fulltext'], "fulltext", "text", __t("You must fill in a description for the new listing.", true, true), $this->Config->content_description == "required" ? 1 : 0); # Validate review custom fields if ($revFormEnabled && $criteria['Criteria']['state']) { // Review inputs $this->data['Review']['userid'] = $this->_user->id; $this->data['Review']['email'] = $this->data['email']; $this->data['Review']['name'] = $this->data['name']; $this->data['Review']['username'] = Sanitize::getString($this->data, 'name', ''); $this->data['Review']['title'] = Sanitize::getString($this->data['Review'], 'title'); $this->data['Review']['location'] = Sanitize::getString($this->data['Review'], 'location'); // deprecated $this->data['Review']['comments'] = Sanitize::getString($this->data['Review'], 'comments'); // Review standard fields $this->Listing->validateInput($this->data['Review']['title'], "rev_title", "text", __t("You must fill in a title for the review.", true, true), $this->Config->reviewform_title == 'required' ? true : false); if ($criteria['Criteria']['state'] == 1) { $criteria_qty = $criteria['Criteria']['quantity']; $ratingErr = 0; if (!isset($this->data['Rating'])) { $ratingErr = $criteria_qty; } else { for ($i = 0; $i < $criteria_qty; $i++) { if (!isset($this->data['Rating']['ratings'][$i]) || (empty($this->data['Rating']['ratings'][$i]) || $this->data['Rating']['ratings'][$i] == 'undefined' || (double) $this->data['Rating']['ratings'][$i] > $this->Config->rating_scale)) { $ratingErr++; } } } $this->Listing->validateInput('', "rating", "text", sprintf(__t("You are missing a rating in %s criteria.", true, true), $ratingErr), $ratingErr); } // Review custom fields $this->Field->validateErrors = array(); // Clear any previous validation errors $review_valid_fields = $this->Field->validate($this->data, 'review', $this->Access); $this->Listing->validateErrors = array_merge($this->Listing->validateErrors, $this->Field->validateErrors); $this->Listing->validateInput($this->data['Review']['comments'], "comments", "text", __t("You must fill in your comment.", true, true), $this->Config->reviewform_comment == 'required' ? true : false); } // if ($revFormEnabled && $criteria['Criteria']['state']) # Validate image fields $this->Uploads->validateImages(); # Validate Captcha security code if ($isNew && $this->Access->showCaptcha()) { if (!isset($this->data['Captcha']['code'])) { $this->Listing->validateSetError("code", __t("The security code you entered was invalid.", true, true)); } elseif ($this->data['Captcha']['code'] == '') { $this->Listing->validateInput($this->data['Captcha']['code'], "code", "text", __t("You must fill in the security code.", true), 1); } else { if (!$this->Captcha->checkCode($this->data['Captcha']['code'], $this->ipaddress)) { $this->Listing->validateSetError("code", __t("The security code you entered was invalid.", true, true)); } } } # Get all validation messages $validation = $this->Listing->validateGetError() . $this->Uploads->getMsg(); # Validation failed if ($validation != '') { $response[] = "var parentForm = {$parentFrame}.jQuery('#jr_listingForm');"; $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "parentForm.find('.button').removeAttr('disabled');"; // Transform textareas into wysiwyg editors if ($this->Access->loadWysiwygEditor()) { App::import('Helper', 'Editor', 'jreviews'); $Editor = new EditorHelper(); $response[] = $parentFrame . '.' . $Editor->transform(true); } // Replace captcha with new instance if ($this->Access->in_groups($this->Config->security_image)) { $captcha = $this->Captcha->displayCode(); $response[] = "{$parentFrame}.jQuery('#captcha').attr('src','{$captcha['src']}');"; $response[] = "{$parentFrame}.jQuery('#jr_captchaCode').val('');"; } $response[] = "parentForm.find('.jr_loadingSmall').hide();"; return $this->makeJS($response); // Can't use ajaxResponse b/c we are in an iframe } # Validation passed, continue... if ($isNew) { $this->data['Listing']['created'] = _CURRENT_SERVER_TIME; //gmdate('Y-m-d H:i:s'); $this->data['Listing']['publish_up'] = _CURRENT_SERVER_TIME; //gmdate('Y-m-d H:i:s'); $this->data['Listing']['created_by'] = $this->_user->id; $this->data['Listing']['publish_down'] = NULL_DATE; $this->data['Field']['Listing']['email'] = $this->data['email']; // If visitor, assign name field to content Alias if (!$this->_user->id) { $this->data['Listing']['created_by_alias'] = $this->data['name']; } // Check moderation settings $this->data['Listing']['state'] = (int) (!$this->Access->moderateListing()); // If listing moderation is enabled, then the review is also moderated if (!$this->data['Listing']['state']) { $this->Config->moderation_reviews = $this->Config->moderation_editor_reviews = $this->Config->moderation_item; } } else { if ($this->Config->moderation_item_edit) { $this->data['Listing']['state'] = (int) (!$this->Access->moderateListing()); } $this->data['Listing']['modified'] = _CURRENT_SERVER_TIME; //gmdate('Y-m-d H:i:s'); $this->data['Listing']['modified_by'] = $this->_user->id; $query = 'SELECT images FROM #__content WHERE id = ' . $this->data['Listing']['id']; $this->_db->setQuery($query); $this->data['Listing']['images'] = $this->_db->loadResult(); // Check total number of images if (!$this->Uploads->checkImageCount($this->data['Listing']['images'])) { $validation .= '<span>' . sprintf(__t("The total number of images is limited to %s", true, true), $this->Config->content_images) . '</span><br />'; $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "{$parentFrame}.jQuery('.button').removeAttr('disabled');"; $response[] = "{$parentFrame}.jQuery('.jr_loadingSmall').hide();"; return $this->makeJS($response); } } // Process images and update data array if ($this->Uploads->success) { $imageUploadPath = PATH_ROOT . _JR_PATH_IMAGES . 'jreviews' . DS; $this->Uploads->uploadImages($this->data['Listing']['id'], $imageUploadPath); if ($isNew) { // New item $currImages = $this->Uploads->images; } elseif ($this->data['Listing']['images'] != '') { // Editing and there are existing images $currImages = array_merge(explode("\n", $this->data['Listing']['images']), $this->Uploads->images); } else { // Editing and there are no existing images $currImages = $this->Uploads->images; } $this->data['Listing']['images'] = implode("\n", $currImages); } # Save listing $savedListing = $this->Listing->store($this->data); $listing_id = $this->data['Listing']['id']; if (!$savedListing) { $validation .= __t("The was a problem saving the listing", true, true); } // Error on listing save if ($validation != '') { $response[] = "{$parentFrame}.jQuery('#jr_listingFormValidation').html('{$validation}');"; $response[] = "{$parentFrame}.jQuery('.button').removeAttr('disabled');"; $response[] = "{$parentFrame}.jQuery('.jr_loadingSmall').hide();"; return $this->makeJS($response); } # Save listing custom fields $this->data['Field']['Listing']['contentid'] = $this->data['Listing']['id']; $this->Field->save($this->data, 'listing', $isNew, $listing_valid_fields); # Begin insert review in table if ($revFormEnabled && $criteria['Criteria']['state']) { // Get reviewer type, for now editor reviews don't work in Everywhere components $this->data['Review']['author'] = (int) $this->Access->isJreviewsEditor($this->_user->id); $this->data['Review']['mode'] = 'com_content'; $this->data['Review']['pid'] = (int) $this->data['Listing']['id']; // Force plugin loading on Review model $this->_initPlugins('Review'); $this->Review->isNew = true; $savedReview = $this->Review->save($this->data, $this->Access, $review_valid_fields); } # Before render callback if ($isNew && isset($this->Listing->plgBeforeRenderListingSaveTrigger)) { $plgBeforeRenderListingSave = $this->Listing->plgBeforeRenderListingSave(); switch ($plgBeforeRenderListingSave) { case '0': $this->data['Listing']['state'] = 1; break; case '1': $this->data['Listing']['state'] = 0; break; case '': break; default: return $plgBeforeRenderListingSave; break; } } # Moderation disabled if (!isset($this->data['Listing']['state']) || $this->data['Listing']['state']) { $fields = array('Criteria.criteria AS `Criteria.criteria`', 'Criteria.tooltips AS `Criteria.tooltips`'); $listing = $this->Listing->findRow(array('fields' => $fields, 'conditions' => array('Listing.id = ' . $listing_id)), array('afterFind')); # Facebook wall integration $fb_checkbox = Sanitize::getBool($this->data, 'fb_publish'); $facebook_integration = Sanitize::getBool($this->Config, 'facebook_enable') && Sanitize::getBool($this->Config, 'facebook_listings') && $fb_checkbox; $token = cmsFramework::getCustomToken($listing_id); $facebook_integration and $response[] = $parentFrame . '.jQuery.get(' . $parentFrame . '.s2AjaxUri+' . $parentFrame . '.jreviews.ajax_params()+\'&url=facebook/_postListing/id:' . $listing_id . '&' . $token . '=1\'); '; $url = cmsFramework::route($listing['Listing']['url']); $update_text = $isNew ? __t("Thank you for your submission.", true, true) : __t("The listing was successfully saved.", true, true); //JOEYG CODE //THE FOLLOWING GETS THE LISTING TYPE FROM THE DB FOR THE NEWLY SAVED LISTING //IF THE TYPE IS BUSINESS PROFILE OR PROJECT LISTING THEN DISPLAY THE after_submit.thtml file //ELSE DISPLAY NORMAL MESSAGE //IF WE ONLY WANT TO ADD THE after_submit.thtml if the listing is new then add if ($isNew) { $query = "SELECT `listing_type` FROM `jos_vpbd_content_criteria` WHERE `jos_vpbd_content_criteria`.`listing_id` = " . $this->data['Listing']['id']; $this->_db->setQuery($query); $jg_listing_type = $this->_db->loadResult(); if ($jg_listing_type == 2 || $jg_listing_type == 7) { $update_html = $this->render('listings', 'after_submit'); } else { $update_html = "<a href=\"{$url}\">" . __t("Click here to view your listing", true) . "</a>"; } //ends if/else } else { //not new $update_html = "<a href=\"{$url}\">" . __t("Click here to view your listing", true) . "</a>"; } //ends if($isNew) //ENDS JOEYG ALTER CODE $jsonObject = json_encode(compact('target_id', 'update_text', 'update_html')); $response[] = ' var $parentForm = ' . $parentFrame . '.jQuery(\'#jr_listingForm\'); $parentForm.scrollTo({duration:400,offset:-100}); $parentForm.s2ShowUpdate(' . $jsonObject . '); '; return $this->makeJS($response); } # Moderation enabled $update_text = __t("Thank you for your submission. It will be published once it is verified.", true); $update_html = '<div id=\\"s2Msgjr_listingForm\\" class=\\"jr_postUpdate\\">' . $update_text . '</div>'; $response[] = ' var $parentForm = ' . $parentFrame . '.jQuery(\'#jr_listingForm\'); $parentForm.scrollTo({duration:400,offset:-100},function(){ $parentForm.fadeOut(250,function(){$parentForm.html("' . $update_html . '").show();}); }); '; return $this->makeJS($response); }
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 loadXajax() { // Prevents xajax from loading twice if already loaded by jReviews or BlueFlame Platform if (!class_exists('xajax') && !defined('XAJAX_LOADED') && !defined('XAJAX_VER')) { define('XAJAX_LOADED', 1); App::import('Vendor', 'xajax_05final' . DS . 'xajax_core' . DS . 'xajax.inc'); if (defined('MVC_FRAMEWORK_ADMIN')) { $xajax = new xajax('index2.php?option=' . S2Paths::get('jreviews', 'S2_CMSCOMP') . '&task=xajax&no_html=1'); } else { $xajax = new xajax(); } $xajax->setCharEncoding(strtoupper(cmsFramework::getCharset())); if (strtolower(cmsFramework::getCharset()) == 'utf-8') { $decodeUTF8 = false; } else { $decodeUTF8 = true; } /* Set defaults from params */ $this->xajax_statusMessage ? $xajax->setFlag('statusMessages', true) : $xajax->setFlag('statusMessages', false); $this->xajax_waitCursor ? $xajax->setFlag('waitCursor', true) : $xajax->setFlag('waitCursor', false); $this->xajax_debug ? $xajax->setFlag('debug', true) : $xajax->setFlag('debug', false); $decodeUTF8 ? $xajax->setFlag('decodeUTF8Input', true) : $xajax->setFlag('decodeUTF8Input', false); $xajax->registerFunction('xajaxDispatch'); // ob_start('ob_gzhandler'); // Results in wrong encoding error ni certain servers $xajax->processRequest(); $js = $xajax->getJavascript(S2_VENDORS_URL . 'xajax_05final' . _DS); cmsFramework::addScript($js); } }