Пример #1
0
 /**
  * @param  $comment JCommentsTableComment
  * @param boolean $isNew
  * @return
  */
 public static function sendToSubscribers(&$comment, $isNew = true)
 {
     if (!$comment->published) {
         return;
     }
     $app = JCommentsFactory::getApplication('site');
     $dbo = JCommentsFactory::getDBO();
     $config = JCommentsFactory::getConfig();
     $query = "SELECT DISTINCTROW js.`name`, js.`email`, js.`hash` " . "\n , jo.title AS object_title, jo.link AS object_link, jo.access AS object_access" . "\nFROM #__jcomments_subscriptions AS js" . "\nJOIN #__jcomments_objects AS jo ON js.object_id = jo.object_id AND js.object_group = jo.object_group" . "\nWHERE js.`object_group` = " . $dbo->Quote($comment->object_group) . "\nAND js.`object_id` = " . intval($comment->object_id) . "\nAND js.`published` = 1 " . (JCommentsMultilingual::isEnabled() ? "\nAND js.`lang` = " . $dbo->Quote($comment->lang) : '') . (JCommentsMultilingual::isEnabled() ? "\nAND jo.`lang` = " . $dbo->Quote($comment->lang) : '') . "\nAND js.`email` <> '" . $dbo->getEscaped($comment->email) . "'" . ($comment->userid ? "\nAND js.`userid` <> " . $comment->userid : '');
     $dbo->setQuery($query);
     $rows = $dbo->loadObjectList();
     if (count($rows)) {
         // getting object's information (title and link)
         $object_title = empty($rows[0]->object_title) ? JCommentsObjectHelper::getTitle($comment->object_id, $comment->object_group, $comment->lang) : $rows[0]->object_title;
         $object_link = empty($rows[0]->object_link) ? JCommentsObjectHelper::getLink($comment->object_id, $comment->object_group, $comment->lang) : $rows[0]->object_link;
         $object_link = JCommentsFactory::getAbsLink($object_link);
         if ($comment->title != '') {
             $comment->title = JCommentsText::censor($comment->title);
         }
         $commentText = $comment->comment;
         $bbcode = JCommentsFactory::getBBCode();
         $txt = JCommentsText::censor($comment->comment);
         $txt = $bbcode->replace($txt);
         if ($config->getInt('enable_custom_bbcode')) {
             $customBBCode = JCommentsFactory::getCustomBBCode();
             // TODO: add control for replacement mode from CustomBBCode parameters
             $txt = $customBBCode->replace($txt, true);
         }
         $comment->comment = trim(preg_replace('/(\\s){2,}/i', '\\1', $txt));
         $comment->author = JComments::getCommentAuthorName($comment);
         $tmpl = JCommentsFactory::getTemplate($comment->object_id, $comment->object_group);
         $tmpl->load('tpl_email');
         $tmpl->addVar('tpl_email', 'notification-type', 'subscription');
         $tmpl->addVar('tpl_email', 'comment-isnew', $isNew ? 1 : 0);
         $tmpl->addVar('tpl_email', 'comment-object_title', $object_title);
         $tmpl->addVar('tpl_email', 'comment-object_link', $object_link);
         $tmpl->addObject('tpl_email', 'comment', $comment);
         if ($isNew) {
             $subject = JText::sprintf('NOTIFICATION_SUBJECT_NEW', $object_title);
         } else {
             $subject = JText::sprintf('NOTIFICATION_SUBJECT_UPDATED', $object_title);
         }
         if (isset($subject)) {
             $mailFrom = $app->getCfg('mailfrom');
             $fromName = $app->getCfg('fromname');
             foreach ($rows as $row) {
                 $tmpl->addVar('tpl_email', 'hash', $row->hash);
                 $message = $tmpl->renderTemplate('tpl_email');
                 JCommentsMail::send($mailFrom, $fromName, $row->email, $subject, $message, true);
             }
         }
         $tmpl->freeTemplate('tpl_email');
         unset($rows);
         $comment->comment = $commentText;
     }
 }
Пример #2
0
 /**
  * @param  $comment JCommentsDB
  * @param boolean $isNew
  * @return
  */
 function sendToSubscribers(&$comment, $isNew = true)
 {
     global $mainframe;
     if (!$comment->published) {
         return;
     }
     $dbo =& JCommentsFactory::getDBO();
     $config =& JCommentsFactory::getConfig();
     $query = "SELECT DISTINCTROW `name`, `email`, `hash` " . "\nFROM #__jcomments_subscriptions " . "\nWHERE `object_group` = '" . $dbo->getEscaped($comment->object_group) . "'" . "\nAND `object_id`='" . intval($comment->object_id) . "'" . "\nAND `published`='1' " . (JCommentsMultilingual::isEnabled() ? "\nAND `lang` = '" . $dbo->getEscaped($comment->lang) . "'" : '') . "\nAND `email` <> '" . $dbo->getEscaped($comment->email) . "'" . ($comment->userid ? "\nAND `userid` <> '" . $comment->userid . "'" : '');
     $dbo->setQuery($query);
     $rows = $dbo->loadObjectList();
     if (count($rows)) {
         $object_title = JCommentsObjectHelper::getTitle($comment->object_id, $comment->object_group, $comment->lang);
         $object_link = JCommentsObjectHelper::getLink($comment->object_id, $comment->object_group);
         $object_link = JCommentsFactory::getAbsLink($object_link);
         $commentText = $comment->comment;
         $bbcode =& JCommentsFactory::getBBCode();
         $txt = JCommentsText::censor($comment->comment);
         $txt = $bbcode->replace($txt);
         if ($config->getInt('enable_custom_bbcode')) {
             $customBBCode =& JCommentsFactory::getCustomBBCode();
             // TODO: add control for replacement mode from CustomBBCode parameters
             $txt = $customBBCode->replace($txt, true);
         }
         $txt = trim(preg_replace('/(\\s){2,}/i', '\\1', $txt));
         $txt = str_replace('class="quotebody"', 'style="margin: 5px 0 0 0;padding: 8px; border: 1px dashed #aaa;"', $txt);
         $comment->comment = $txt;
         unset($bbcode);
         $comment->author = JComments::getCommentAuthorName($comment);
         $tmpl =& JCommentsFactory::getTemplate($comment->object_id, $comment->object_group);
         $tmpl->load('tpl_email');
         $tmpl->addVar('tpl_email', 'notification-type', 'subscription');
         $tmpl->addVar('tpl_email', 'comment-isnew', $isNew ? 1 : 0);
         $tmpl->addVar('tpl_email', 'comment-object_title', $object_title);
         $tmpl->addVar('tpl_email', 'comment-object_link', $object_link);
         $tmpl->addObject('tpl_email', 'comment', $comment);
         if ($isNew) {
             $subject = JText::sprintf('NOTIFICATION_SUBJECT_NEW', $object_title);
         } else {
             $subject = JText::sprintf('NOTIFICATION_SUBJECT_UPDATED', $object_title);
         }
         if (isset($subject)) {
             $mailFrom = $mainframe->getCfg('mailfrom');
             $fromName = $mainframe->getCfg('fromname');
             foreach ($rows as $row) {
                 $tmpl->addVar('tpl_email', 'hash', $row->hash);
                 $message = $tmpl->renderTemplate('tpl_email');
                 JCommentsMail::send($mailFrom, $fromName, $row->email, $subject, $message, true);
             }
         }
         $tmpl->freeTemplate('tpl_email');
         unset($rows);
         $comment->comment = $commentText;
     }
 }