Exemple #1
0
 public static function showUserComments()
 {
     $config = JCommentsFactory::getConfig();
     if ($config->get('enable_rss') == '1') {
         $app = JFactory::getApplication('site');
         $acl = JCommentsFactory::getACL();
         $userid = $app->input->getInt('userid', 0);
         $limit = $app->input->getInt('limit', $config->getInt('feed_limit', 100));
         $user = JFactory::getUser($userid);
         if (!isset($user->id)) {
             self::showNotFound();
             return;
         }
         $lm = $limit != $config->getInt('feed_limit') ? '&limit=' . $limit : '';
         if (JCommentsMultilingual::isEnabled()) {
             $language = JCommentsMultilingual::getLanguage();
             $lp = '&lang=' . $language;
         } else {
             $language = null;
             $lp = '';
         }
         $liveSite = trim(str_replace(JURI::root(true), '', str_replace('/administrator', '', JURI::root())), '/');
         $syndicationURL = $liveSite . JRoute::_('index.php?option=com_jcomments&task=rss_user&userid=' . $userid . $lm . $lp . '&tmpl=raw');
         $user->userid = $user->id;
         $username = JComments::getCommentAuthorName($user);
         $rss = new JoomlaTuneFeed();
         $rss->title = JText::sprintf('USER_FEED_TITLE', $username);
         $rss->link = str_replace('/administrator', '', JURI::root());
         $rss->syndicationURL = $syndicationURL;
         $rss->description = JText::sprintf('USER_FEED_DESCRIPTION', $username);
         $options = array();
         $options['lang'] = $language;
         $options['userid'] = $userid;
         $options['published'] = 1;
         $options['filter'] = 'c.deleted = 0';
         $options['orderBy'] = 'c.date DESC';
         $options['votes'] = false;
         $options['limit'] = $limit;
         $options['limitStart'] = 0;
         $options['objectinfo'] = true;
         $options['access'] = $acl->getUserAccess();
         $rows = JCommentsModel::getCommentsList($options);
         $word_maxlength = $config->getInt('word_maxlength');
         foreach ($rows as $row) {
             $comment = JCommentsText::cleanText($row->comment);
             if ($comment != '') {
                 // getting object's information (title and link)
                 $object_title = $row->object_title;
                 $object_link = JCommentsFactory::getAbsLink(str_replace('amp;', '', $row->object_link));
                 // apply censor filter
                 $object_title = JCommentsText::censor($object_title);
                 $comment = JCommentsText::censor($comment);
                 // fix long words problem
                 if ($word_maxlength > 0) {
                     $comment = JCommentsText::fixLongWords($comment, $word_maxlength, ' ');
                     if ($object_title != '') {
                         $object_title = JCommentsText::fixLongWords($object_title, $word_maxlength, ' ');
                     }
                 }
                 $author = JComments::getCommentAuthorName($row);
                 $item = new JoomlaTuneFeedItem();
                 $item->title = $object_title;
                 $item->link = $object_link . '#comment-' . $row->id;
                 $item->description = JText::sprintf('USER_FEED_ITEM_DESCRIPTION', $author, $comment);
                 $item->source = $object_link;
                 $item->pubDate = $row->date;
                 $item->author = $author;
                 $rss->addItem($item);
             }
         }
         $rss->display();
         unset($rows, $rss);
         exit;
     }
 }
Exemple #2
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;
     }
 }
Exemple #3
0
 function feedLastCommentsGlobal()
 {
     global $mainframe;
     $object_group = trim(strip_tags(JCommentsInput::getVar('object_group', '')));
     $object_group = preg_replace('#[^0-9A-Za-z\\-\\_\\,\\.]#is', '', $object_group);
     $limit = (int) JCommentsInput::getVar('limit', 100);
     $config =& JCommentsFactory::getConfig();
     if ($config->get('enable_rss') == '1') {
         $iso = explode('=', _ISO);
         $charset = strtolower((string) $iso[1]);
         if (JCOMMENTS_JVERSION == '1.5') {
             $offset = $mainframe->getCfg('offset');
         } else {
             $offset = $mainframe->getCfg('offset') + date('O') / 100;
         }
         $object_group = preg_replace('#[\'\\"]#ism', '', $object_group);
         $og = $object_group ? '&amp;object_group=' . $object_group : '';
         $lm = $limit != 100 ? '&amp;limit=' . $limit : '';
         if (JCOMMENTS_JVERSION == '1.5') {
             $syndicationURL = JoomlaTuneRoute::_('index.php?option=com_jcomments&amp;task=rss_full' . $og . $lm . '&amp;tmpl=component');
         } else {
             $syndicationURL = $mainframe->getCfg('live_site') . '/index2.php?option=com_jcomments&amp;task=rss_full' . $og . $lm . '&amp;no_html=1';
         }
         $rss = new JoomlaTuneFeed();
         $rss->setOffset($offset);
         $rss->encoding = $charset;
         $rss->title = JText::_('Comments');
         $rss->link = $mainframe->getCfg('live_site');
         $rss->syndicationURL = $syndicationURL;
         $rss->description = JText::_('COMMENTS_FOR') . ' ' . $mainframe->getCfg('sitename');
         if ($object_group != '') {
             $groups = explode(',', $object_group);
         } else {
             $groups = array();
         }
         $db =& JCommentsFactory::getDBO();
         $query = "SELECT id, title, object_id, object_group, userid, name, username, date, UNIX_TIMESTAMP(date) as date_ts, comment" . "\nFROM #__jcomments " . "\nWHERE published = '1'" . (count($groups) > 0 ? "\n AND (object_group = '" . implode("' OR object_group='", $groups) . "')" : '') . (JCommentsMultilingual::isEnabled() ? "\nAND lang = '" . JCommentsMultilingual::getLanguage() . "'" : "") . "\nORDER BY date DESC";
         $db->setQuery($query, 0, $limit);
         $rows = $db->loadObjectList();
         $word_maxlength = $config->getInt('word_maxlength');
         $lang = JCommentsMultilingual::isEnabled() ? JCommentsMultilingual::getLanguage() : null;
         foreach ($rows as $row) {
             $comment = JCommentsText::cleanText($row->comment);
             $author = JComments::getCommentAuthorName($row);
             if ($comment != '') {
                 $object_title = JCommentsObjectHelper::getTitle($row->object_id, $row->object_group, $lang);
                 $object_link = JCommentsObjectHelper::getLink($row->object_id, $row->object_group);
                 $object_link = str_replace('amp;', '', $object_link);
                 $object_link = JCommentsFactory::getAbsLink($object_link);
                 // apply censor filter
                 $object_title = JCommentsText::censor($object_title);
                 $comment = JCommentsText::censor($comment);
                 // fix long words problem
                 if ($word_maxlength > 0) {
                     $comment = JCommentsText::fixLongWords($comment, $word_maxlength, ' ');
                     if ($comment != '') {
                         $comment = JCommentsText::fixLongWords($comment, $word_maxlength, ' ');
                     }
                 }
                 $item = new JoomlaTuneFeedItem();
                 $item->title = $object_title;
                 $item->link = $object_link . '#comment-' . $row->id;
                 $item->description = $author . ' ' . JText::_('Wrote') . ' &quot;' . $comment . '&quot;';
                 $item->source = $object_link;
                 if (JCOMMENTS_JVERSION == '1.5') {
                     $item->pubDate = $row->date;
                 } else {
                     $date = strtotime((string) $row->date) - $offset * 3600;
                     $item->pubDate = date('Y-m-d H:i:s', $date);
                 }
                 $item->author = $author;
                 $rss->addItem($item);
             }
         }
         $rss->display();
         unset($rows, $rss);
         exit;
     }
 }
Exemple #4
0
 public static function showUserComments()
 {
     $config = JCommentsFactory::getConfig();
     if ($config->get('enable_rss') == '1') {
         $app = JCommentsFactory::getApplication('site');
         $acl = JCommentsFactory::getACL();
         $userid = (int) JCommentsInput::getVar('userid', 0);
         $limit = (int) JCommentsInput::getVar('limit', $config->getInt('feed_limit', 100));
         $user = JCommentsFactory::getUser($userid);
         if (!isset($user->id)) {
             self::showNotFound();
             return;
         }
         if (JCOMMENTS_JVERSION == '1.0') {
             $offset = $app->getCfg('offset') + date('O') / 100;
         } else {
             $offset = $app->getCfg('offset');
         }
         $lm = $limit != $config->getInt('feed_limit') ? '&amp;limit=' . $limit : '';
         if (JCommentsMultilingual::isEnabled()) {
             $language = JCommentsMultilingual::getLanguage();
             $lp = '&amp;lang=' . $language;
         } else {
             $language = null;
             $lp = '';
         }
         if (JCOMMENTS_JVERSION == '1.0') {
             $syndicationURL = $app->getCfg('live_site') . '/index2.php?option=com_jcomments&amp;task=rss_user&amp;userid=' . $userid . $lm . $lp . '&amp;no_html=1';
         } else {
             $liveSite = str_replace(JURI::root(true), '', $app->getCfg('live_site'));
             $syndicationURL = $liveSite . JRoute::_('index.php?option=com_jcomments&amp;task=rss_user&amp;userid=' . $userid . $lm . $lp . '&amp;tmpl=raw');
         }
         $user->userid = $user->id;
         $username = JComments::getCommentAuthorName($user);
         $rss = new JoomlaTuneFeed();
         $rss->setOffset($offset);
         $rss->encoding = JCOMMENTS_ENCODING;
         $rss->title = JText::sprintf('USER_FEED_TITLE', $username);
         $rss->link = $app->getCfg('live_site');
         $rss->syndicationURL = $syndicationURL;
         $rss->description = JText::sprintf('USER_FEED_DESCRIPTION', $username);
         $options = array();
         $options['lang'] = $language;
         $options['userid'] = $userid;
         $options['published'] = 1;
         $options['filter'] = 'c.deleted = 0';
         $options['orderBy'] = 'c.date DESC';
         $options['votes'] = false;
         $options['limit'] = $limit;
         $options['limitStart'] = 0;
         $options['objectinfo'] = true;
         $options['access'] = $acl->getUserAccess();
         $rows = JCommentsModel::getCommentsList($options);
         $word_maxlength = $config->getInt('word_maxlength');
         $lang = JCommentsMultilingual::isEnabled() ? JCommentsMultilingual::getLanguage() : null;
         foreach ($rows as $row) {
             $comment = JCommentsText::cleanText($row->comment);
             if ($comment != '') {
                 // getting object's information (title and link)
                 $object_title = empty($row->object_title) ? JCommentsObjectHelper::getTitle($row->object_id, $row->object_group, $lang) : $row->object_title;
                 $object_link = empty($row->object_link) ? JCommentsObjectHelper::getLink($row->object_id, $row->object_group, $lang) : $row->object_link;
                 $object_link = JCommentsFactory::getAbsLink(str_replace('amp;', '', $object_link));
                 // apply censor filter
                 $object_title = JCommentsText::censor($object_title);
                 $comment = JCommentsText::censor($comment);
                 // fix long words problem
                 if ($word_maxlength > 0) {
                     $comment = JCommentsText::fixLongWords($comment, $word_maxlength, ' ');
                     if ($object_title != '') {
                         $object_title = JCommentsText::fixLongWords($object_title, $word_maxlength, ' ');
                     }
                 }
                 $author = JComments::getCommentAuthorName($row);
                 $item = new JoomlaTuneFeedItem();
                 $item->title = $object_title;
                 $item->link = $object_link . '#comment-' . $row->id;
                 $item->description = JText::sprintf('USER_FEED_ITEM_DESCRIPTION', $author, $comment);
                 $item->source = $object_link;
                 if (JCOMMENTS_JVERSION == '1.0') {
                     $date = strtotime((string) $row->date) - $offset * 3600;
                     $item->pubDate = date('Y-m-d H:i:s', $date);
                 } else {
                     $item->pubDate = $row->date;
                 }
                 $item->author = $author;
                 $rss->addItem($item);
             }
         }
         $rss->display();
         unset($rows, $rss);
         exit;
     }
 }
Exemple #5
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;
     }
 }
Exemple #6
0
 /**
  * Prepares data for notification
  *
  * @param array $data An associative array of notification data
  * @param string $type Type of notification
  *
  * @return mixed
  */
 private static function prepareData($data, $type)
 {
     require_once JPATH_ROOT . '/components/com_jcomments/jcomments.php';
     $object = JCommentsObjectHelper::getObjectInfo($data['comment']->object_id, $data['comment']->object_group, $data['comment']->lang);
     $data['notification-type'] = $type;
     $data['object_title'] = $object->title;
     $data['object_link'] = JCommentsFactory::getAbsLink($object->link);
     $data['comment']->author = JComments::getCommentAuthorName($data['comment']);
     $data['comment']->title = JCommentsText::censor($data['comment']->title);
     $data['comment']->comment = JCommentsText::censor($data['comment']->comment);
     $data['comment']->comment = JCommentsFactory::getBBCode()->replace($data['comment']->comment);
     if (JCommentsFactory::getConfig()->getInt('enable_custom_bbcode')) {
         $data['comment']->comment = JCommentsFactory::getCustomBBCode()->replace($data['comment']->comment, true);
     }
     $data['comment']->comment = trim(preg_replace('/(\\s){2,}/i', '\\1', $data['comment']->comment));
     return $data;
 }