Exemplo n.º 1
0
 public static function getList($params)
 {
     $db = JFactory::getDBO();
     $db->setQuery("SELECT * FROM #__jcomments ORDER BY date DESC", 0, $params->get('count'));
     $items = $db->loadObjectList();
     if (!is_array($items)) {
         $items = array();
     }
     if (count($items)) {
         $config = JCommentsFactory::getConfig();
         $bbcode = JCommentsFactory::getBBCode();
         $limit_comment_text = (int) $params->get('limit_comment_text', 0);
         foreach ($items as &$item) {
             $item->link = 'index.php?option=com_jcomments&&view=comment&layout=edit&id=' . $item->id;
             $item->author = JComments::getCommentAuthorName($item);
             $text = JCommentsText::censor($item->comment);
             $text = $bbcode->filter($text, true);
             $text = JCommentsText::cleanText($text);
             if ($limit_comment_text && JString::strlen($text) > $limit_comment_text) {
                 $text = self::truncateText($text, $limit_comment_text - 1);
             }
             $item->comment = $text;
         }
     }
     return $items;
 }
Exemplo n.º 2
0
 function quoteComment($id, $loadForm = 0)
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $db =& JCommentsFactory::getDBO();
     $acl =& JCommentsFactory::getACL();
     $config =& JCommentsFactory::getConfig();
     $response =& JCommentsFactory::getAjaxResponse();
     $comment = new JCommentsDB($db);
     $id = (int) $id;
     if ($comment->load($id)) {
         $comment_name = JComments::getCommentAuthorName($comment);
         $comment_text = JCommentsText::br2nl($comment->comment);
         if ($config->getInt('enable_nested_quotes') == 0) {
             $bbcode =& JCommentsFactory::getBBCode();
             $comment_text = $bbcode->removeQuotes($comment_text);
         }
         if ($config->getInt('enable_custom_bbcode')) {
             $customBBCode =& JCommentsFactory::getCustomBBCode();
             $comment_text = $customBBCode->filter($comment_text, true);
         }
         if ($acl->getUserId() == 0) {
             $bbcode =& JCommentsFactory::getBBCode();
             $comment_text = $bbcode->removeHidden($comment_text);
         }
         if ($comment_text != '') {
             if ($acl->check('enable_autocensor')) {
                 $comment_text = JCommentsText::censor($comment_text);
             }
             if (intval($loadForm) == 1) {
                 $form = JComments::getCommentsForm($comment->object_id, $comment->object_group, true);
                 $response->addAssign('comments-form-link', 'innerHTML', $form);
             }
             $comment_text = JCommentsText::jsEscape($comment_text);
             $text = "[quote name=\"" . $comment_name . "\"]" . $comment_text . "[/quote]\\n";
             $response->addScript("jcomments.insertText('" . $text . "');");
         } else {
             $response->addAlert(JText::_('ERROR_NOTHING_TO_QUOTE'));
         }
     }
     unset($comment);
     return $response;
 }
Exemplo n.º 3
0
 public static function prepareComment(&$comment)
 {
     if (isset($comment->_skip_prepare) && $comment->_skip_prepare == 1) {
         return;
     }
     JCommentsEventHelper::trigger('onJCommentsCommentBeforePrepare', array(&$comment));
     $config = JCommentsFactory::getConfig();
     $acl = JCommentsFactory::getACL();
     // run autocensor
     if ($acl->check('enable_autocensor')) {
         $comment->comment = JCommentsText::censor($comment->comment);
         if ($comment->title != '') {
             $comment->title = JCommentsText::censor($comment->title);
         }
     }
     // replace deleted comment text with predefined message
     if ($comment->deleted == 1) {
         $comment->comment = JText::_('COMMENT_TEXT_COMMENT_HAS_BEEN_DELETED');
         $comment->username = '';
         $comment->name = '';
         $comment->email = '';
         $comment->homepage = '';
         $comment->userid = 0;
         $comment->isgood = 0;
         $comment->ispoor = 0;
     }
     // replace BBCode tags
     $comment->comment = JCommentsFactory::getBBCode()->replace($comment->comment);
     if ($config->getInt('enable_custom_bbcode')) {
         $comment->comment = JCommentsFactory::getCustomBBCode()->replace($comment->comment);
     }
     // fix long words problem
     $word_maxlength = $config->getInt('word_maxlength');
     if ($word_maxlength > 0) {
         $comment->comment = JCommentsText::fixLongWords($comment->comment, $word_maxlength);
         if ($comment->title != '') {
             $comment->title = JCommentsText::fixLongWords($comment->title, $word_maxlength);
         }
     }
     if ($acl->check('emailprotection')) {
         $comment->comment = JComments::maskEmail($comment->id, $comment->comment);
     }
     // autolink urls
     if ($acl->check('autolinkurls')) {
         $comment->comment = preg_replace_callback(_JC_REGEXP_LINK, array('JComments', 'urlProcessor'), $comment->comment);
         if ($acl->check('emailprotection') != 1) {
             $comment->comment = preg_replace(_JC_REGEXP_EMAIL, '<a href="mailto:\\1@\\2">\\1@\\2</a>', $comment->comment);
         }
     }
     // replace smilies' codes with images
     if ($config->get('enable_smilies') == '1') {
         $comment->comment = JCommentsFactory::getSmilies()->replace($comment->comment);
     }
     $comment->author = JComments::getCommentAuthorName($comment);
     // Gravatar support
     $comment->gravatar = md5(strtolower($comment->email));
     if (empty($comment->avatar)) {
         $comment->avatar = '<img src="http://www.gravatar.com/avatar/' . $comment->gravatar . '?d=' . urlencode(JCommentsFactory::getLink('noavatar')) . '" alt="' . htmlspecialchars($comment->author) . '" />';
     }
     JCommentsEventHelper::trigger('onJCommentsCommentAfterPrepare', array(&$comment));
 }
Exemplo n.º 4
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') ? '&amp;limit=' . $limit : '';
         if (JCommentsMultilingual::isEnabled()) {
             $language = JCommentsMultilingual::getLanguage();
             $lp = '&amp;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&amp;task=rss_user&amp;userid=' . $userid . $lm . $lp . '&amp;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;
     }
 }
Exemplo n.º 5
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;
     }
 }
Exemplo n.º 6
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;
     }
 }
Exemplo n.º 7
0
 function prepareComment(&$comment)
 {
     if (isset($comment->_skip_prepare) && $comment->_skip_prepare == 1) {
         return;
     }
     $config =& JCommentsFactory::getConfig();
     $bbcode =& JCommentsFactory::getBBCode();
     $acl =& JCommentsFactory::getACL();
     // convert to datetime if variable contains string value
     if (is_string($comment->datetime)) {
         $comment->datetime = strtotime($comment->datetime);
     }
     // run autocensor
     if ($acl->check('enable_autocensor')) {
         $comment->comment = JCommentsText::censor($comment->comment);
     }
     // replace BBCode tags
     $comment->comment = $bbcode->replace($comment->comment);
     if ($config->getInt('enable_custom_bbcode')) {
         $customBBCode =& JCommentsFactory::getCustomBBCode();
         $comment->comment = $customBBCode->replace($comment->comment);
     }
     // fix long words problem
     $word_maxlength = $config->getInt('word_maxlength');
     if ($word_maxlength > 0) {
         $comment->comment = JCommentsText::fixLongWords($comment->comment, $word_maxlength);
         if ($comment->title != '') {
             $comment->title = JCommentsText::fixLongWords($comment->title, $word_maxlength);
         }
     }
     if ($acl->check('emailprotection')) {
         $comment->comment = JComments::maskEmail($comment->id, $comment->comment);
     }
     // autolink urls
     if ($acl->check('autolinkurls')) {
         $comment->comment = preg_replace_callback(_JC_REGEXP_LINK, array('JComments', 'urlProcessor'), $comment->comment);
         if ($acl->check('emailprotection') != 1) {
             $comment->comment = preg_replace(_JC_REGEXP_EMAIL, '<a href="mailto:\\1@\\2">\\1@\\2</a>', $comment->comment);
         }
     }
     // replace smile codes with images
     if ($config->get('enable_smiles') == '1') {
         $smiles =& JCommentsFactory::getSmiles();
         $comment->comment = $smiles->replace($comment->comment);
     }
     // Gravatar support
     $comment->gravatar = md5(strtolower($comment->email));
     if (empty($comment->avatar)) {
         $comment->avatar = '<img src="http://www.gravatar.com/avatar.php?gravatar_id=' . $comment->gravatar . '&amp;default=' . urlencode(JCommentsFactory::getLink('noavatar')) . '" alt="" />';
     }
     $comment->author = JComments::getCommentAuthorName($comment);
     if ($config->getInt('enable_mambots') == 1) {
         JCommentsPluginHelper::trigger('onAfterPrepareComment', array(&$comment));
     }
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
0
 public static function getList(&$params)
 {
     $db = JFactory::getDBO();
     $user = JFactory::getUser();
     $source = $params->get('source', 'com_content');
     if (!is_array($source)) {
         $source = explode(',', $source);
     }
     $date = JFactory::getDate();
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $now = $date->toSql();
         $access = array_unique(JAccess::getAuthorisedViewLevels($user->get('id')));
         $access[] = 0;
         // for backward compability
     } else {
         $now = $date->toMySQL();
         $access = $user->get('aid', 0);
     }
     switch ($params->get('ordering', '')) {
         case 'vote':
             $orderBy = '(c.isgood-c.ispoor) DESC';
             break;
         case 'date':
         default:
             $orderBy = 'c.date DESC';
             break;
     }
     $where = array();
     $interval = $params->get('interval', '');
     if (!empty($interval)) {
         $timestamp = $date->toUnix();
         switch ($interval) {
             case '1-day':
                 $timestamp = strtotime('-1 day', $timestamp);
                 break;
             case '1-week':
                 $timestamp = strtotime('-1 week', $timestamp);
                 break;
             case '2-week':
                 $timestamp = strtotime('-2 week', $timestamp);
                 break;
             case '1-month':
                 $timestamp = strtotime('-1 month', $timestamp);
                 break;
             case '3-month':
                 $timestamp = strtotime('-3 month', $timestamp);
                 break;
             case '6-month':
                 $timestamp = strtotime('-6 month', $timestamp);
                 break;
             case '1-year':
                 $timestamp = strtotime('-1 year', $timestamp);
                 break;
             default:
                 $timestamp = NULL;
                 break;
         }
         if ($timestamp !== NULL) {
             $dateFrom = JFactory::getDate($timestamp);
             $dateTo = $date;
             if (version_compare(JVERSION, '1.6.0', 'ge')) {
                 $where[] = 'c.date BETWEEN ' . $db->Quote($dateFrom->toSQL()) . ' AND ' . $db->Quote($dateTo->toSQL());
             } else {
                 $where[] = 'c.date BETWEEN ' . $db->Quote($dateFrom->toMySQL()) . ' AND ' . $db->Quote($dateTo->toMySQL());
             }
         }
     }
     $where[] = 'c.published = 1';
     $where[] = 'c.deleted = 0';
     $where[] = "o.link <> ''";
     $where[] = is_array($access) ? "o.access IN (" . implode(',', $access) . ")" : " o.access <= " . (int) $access;
     if (JCommentsMultilingual::isEnabled()) {
         $where[] = 'c.lang = ' . $db->Quote(JCommentsMultilingual::getLanguage());
     }
     $joins = array();
     if (count($source) == 1 && $source[0] == 'com_content') {
         $joins[] = 'JOIN #__content AS cc ON cc.id = o.object_id';
         $joins[] = 'LEFT JOIN #__categories AS ct ON ct.id = cc.catid';
         $where[] = "c.object_group = " . $db->Quote($source[0]);
         $where[] = "(cc.publish_up = '0000-00-00 00:00:00' OR cc.publish_up <= '{$now}')";
         $where[] = "(cc.publish_down = '0000-00-00 00:00:00' OR cc.publish_down >= '{$now}')";
         $categories = $params->get('catid', array());
         if (!is_array($categories)) {
             $categories = explode(',', $categories);
         }
         JArrayHelper::toInteger($categories);
         $categories = implode(',', $categories);
         if (!empty($categories)) {
             $where[] = "cc.catid IN (" . $categories . ")";
         }
     } else {
         if (count($source)) {
             $where[] = "c.object_group in ('" . implode("','", $source) . "')";
         }
     }
     $query = "SELECT c.id, c.userid, c.comment, c.title, c.name, c.username, c.email, c.date, c.object_id, c.object_group, '' as avatar" . ", o.title AS object_title, o.link AS object_link, o.access AS object_access, o.userid AS object_owner" . " FROM #__jcomments AS c" . " JOIN #__jcomments_objects AS o ON c.object_id = o.object_id AND c.object_group = o.object_group AND c.lang = o.lang" . (count($joins) ? ' ' . implode(' ', $joins) : '') . (count($where) ? ' WHERE  ' . implode(' AND ', $where) : '') . " ORDER BY " . $orderBy;
     $db->setQuery($query, 0, $params->get('count'));
     $list = $db->loadObjectList();
     if (!is_array($list)) {
         $list = array();
     }
     if (count($list)) {
         $show_date = $params->get('show_comment_date', 0);
         $date_type = $params->get('date_type', '');
         $date_format = $params->get('date_format', 'd.m.Y H:i');
         $show_author = $params->get('show_comment_author', 0);
         $show_object_title = $params->get('show_object_title', 0);
         $show_comment_title = $params->get('show_comment_title', 0);
         $show_smiles = $params->get('show_smiles', 0);
         $show_avatar = $params->get('show_avatar', 0);
         $limit_comment_text = (int) $params->get('limit_comment_text', 0);
         $config = JCommentsFactory::getConfig();
         $bbcode = JCommentsFactory::getBBCode();
         $smiles = JCommentsFactory::getSmiles();
         $acl = JCommentsFactory::getACL();
         if ($show_avatar) {
             JPluginHelper::importPlugin('jcomments');
             if (version_compare(JVERSION, '3.0', 'ge')) {
                 $dispatcher = JEventDispatcher::getInstance();
             } else {
                 $dispatcher = JDispatcher::getInstance();
             }
             $dispatcher->trigger('onPrepareAvatars', array(&$list));
         }
         foreach ($list as &$item) {
             $item->displayDate = '';
             if ($show_date) {
                 if ($date_type == 'relative') {
                     $item->displayDate = modJCommentsLatestHelper::getRelativeDate($item->date);
                 } else {
                     $item->displayDate = JHTML::_('date', $item->date, $date_format);
                 }
             }
             $item->displayAuthorName = '';
             if ($show_author) {
                 $item->displayAuthorName = JComments::getCommentAuthorName($item);
             }
             $item->displayObjectTitle = '';
             if ($show_object_title) {
                 $item->displayObjectTitle = $item->object_title;
             }
             $item->displayCommentTitle = '';
             if ($show_comment_title) {
                 $item->displayCommentTitle = $item->title;
             }
             $item->displayCommentLink = $item->object_link . '#comment-' . $item->id;
             $text = JCommentsText::censor($item->comment);
             $text = preg_replace('#\\[quote[^\\]]*?\\](((?R)|.)*?)\\[\\/quote\\]#ismu', '', $text);
             $text = $bbcode->filter($text, true);
             $text = JCommentsText::fixLongWords($text, $config->getInt('word_maxlength'), ' ');
             if ($acl->check('autolinkurls')) {
                 $text = preg_replace_callback(_JC_REGEXP_LINK, array('JComments', 'urlProcessor'), $text);
             }
             $text = JCommentsText::cleanText($text);
             if ($limit_comment_text && JString::strlen($text) > $limit_comment_text) {
                 $text = self::truncateText($text, $limit_comment_text - 1);
             }
             switch ($show_smiles) {
                 case 1:
                     $text = $smiles->replace($text);
                     break;
                 case 2:
                     $text = $smiles->strip($text);
                     break;
             }
             $item->displayCommentText = $text;
             if ($show_avatar && empty($item->avatar)) {
                 $gravatar = md5(strtolower($item->email));
                 $item->avatar = '<img src="http://www.gravatar.com/avatar.php?gravatar_id=' . $gravatar . '&amp;default=' . urlencode(JCommentsFactory::getLink('noavatar')) . '" alt="' . htmlspecialchars(JComments::getCommentAuthorName($item)) . '" />';
             }
             $item->readmoreText = JText::_('MOD_JCOMMENTS_LATEST_READMORE');
         }
     }
     return $list;
 }
Exemplo n.º 10
0
	public function onPrepareAvatars(&$comments)
	{
		$db = JFactory::getDBO();

		$avatar_type = $this->params->get('avatar_type', 'gravatar');
		$avatar_default_avatar = $this->params->get('avatar_default_avatar');
		$avatar_custom_default_avatar = $this->params->get('avatar_custom_default_avatar');

		$avatar_link = $this->params->get('avatar_link', 0);
		$avatar_link_target = $this->params->get('avatar_link_target');
		$avatar_link_target = $avatar_link_target != '_self' ? ' target="' . $avatar_link_target . '"' : '';

		$users = array();
		foreach ($comments as &$comment) {
			if ($comment->userid != 0) {
				$users[] = (int)$comment->userid;
			}

			$comment->avatar = '';
		}

		$users = array_unique($users);

		$avatars = array();

		switch ($avatar_type) {
			case 'aup':
				if (count($users)) {
					$db->setQuery('SELECT userid, avatar, referreid FROM #__alpha_userpoints WHERE userid in (' . implode(',', $users) . ')');
					$avatars = $db->loadObjectList('userid');
				}

				$Itemid = self::getItemid('index.php?option=com_alphauserpoints&view=users');
				if (empty($Itemid)) {
					$Itemid = self::getItemid('index.php?option=com_alphauserpoints&view=account');
				}

				$avatarA = JPATH_SITE . '/components/com_alphauserpoints/assets/images/avatars/';
				$avatarL = JURI::base() . 'components/com_alphauserpoints/assets/images/avatars/';

				foreach ($comments as &$comment) {
					$uid = (int)$comment->userid;

					$comment->profileLink = $uid ? JRoute::_('index.php?option=com_alphauserpoints&view=account&userid=' . $avatars[$uid]->referreid . $Itemid) : '';

					if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
						if (is_file($avatarA . $avatars[$uid]->avatar)) {
							$comment->avatar = $avatarL . $avatars[$uid]->avatar;
						}
					}
				}
				break;

			case 'cb':
				if (count($users)) {
					$db->setQuery('SELECT user_id, avatar FROM #__comprofiler WHERE user_id in (' . implode(',', $users) . ') AND avatarapproved = 1');
					$avatars = $db->loadObjectList('user_id');
				}

				$Itemid = self::getItemid('index.php?option=com_comprofiler&task=profile');
				if (empty($Itemid)) {
					$Itemid = self::getItemid('index.php?option=com_comprofiler&task=userslist');
					if (empty($Itemid)) {
						$Itemid = self::getItemid('index.php?option=com_comprofiler');
					}
				}

				foreach ($comments as &$comment) {
					$uid = (int)$comment->userid;

					$comment->profileLink = $uid ? JRoute::_('index.php?option=com_comprofiler&task=userProfile&user='******'';

					if (isset($avatars[$uid]) && !empty($avatars[$uid]->avatar)) {
						$tn = strpos($avatars[$uid]->avatar, 'gallery') === 0 ? '' : 'tn';
						$comment->avatar = JURI::base() . 'images/comprofiler/' . $tn . $avatars[$uid]->avatar;
					}
				}
				break;

			case 'contacts':
				if (count($users)) {
					$query = 'SELECT cd.user_id as userid, cd.image as avatar'
						. ' , CASE WHEN CHAR_LENGTH(cd.alias) THEN CONCAT_WS(":", cd.id, cd.alias) ELSE cd.id END as slug'
						. ' , CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug'
						. ' FROM #__contact_details AS cd '
						. ' INNER JOIN #__categories AS cc on cd.catid = cc.id'
						. ' WHERE cd.user_id in (' . implode(',', $users) . ')';
					$db->setQuery($query);
					$avatars = $db->loadObjectList('userid');
				}

				foreach ($comments as &$comment) {
					$uid = (int)$comment->userid;

					$comment->profileLink = $uid ? JRoute::_('index.php?option=com_contact&view=contact&id=' . $avatars[$uid]->slug . '&catid=' . $avatars[$uid]->catslug) : '';

					if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
						$comment->avatar = JURI::base() . '/' . $avatars[$uid]->avatar;
					}
				}
				break;

			case 'discussions':
				if (count($users)) {
					$db->setQuery('SELECT id as userid, avatar FROM #__discussions_users WHERE id in (' . implode(',', $users) . ')');
					$avatars = $db->loadObjectList('userid');
				}

				$avatarA = JPATH_SITE . '/images/discussions/users/';
				$avatarL = JURI::base() . 'images/discussions/users/';

				foreach ($comments as &$comment) {
					$uid = (int)$comment->userid;

					$comment->profileLink = '';

					if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
						if (file_exists($avatarA . $uid . '/large/' . $avatars[$uid]->avatar)) {
							$comment->avatar = $avatarL . $uid . '/large/' . $avatars[$uid]->avatar;
						}
					}
				}
				break;

			case 'easyblog':
				$router = JPATH_SITE . '/components/com_easyblog/helpers/router.php';
				if (is_file($router)) {
					require_once($router);
					require_once(EBLOG_HELPERS . '/image.php');

					if (count($users)) {
						$db->setQuery('SELECT id as userid, avatar FROM #__easyblog_users WHERE id in (' . implode(',', $users) . ')');
						$avatars = $db->loadObjectList('userid');
					}

					$avatarA = JPATH_ROOT . DS . EasyImageHelper::getAvatarRelativePath() . DS;
					$avatarL = JURI::base() . EasyImageHelper::getAvatarRelativePath() . '/';

					foreach ($comments as &$comment) {
						$uid = (int)$comment->userid;

						$comment->profileLink = EasyBlogRouter::_('index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $uid, false);

						if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
							if (file_exists($avatarA . $avatars[$uid]->avatar)) {
								$comment->avatar = $avatarL . $avatars[$uid]->avatar;
							}
						}
					}
				}
				break;

			case 'easydiscuss':
				$router = JPATH_SITE . '/components/com_easydiscuss/helpers/router.php';
				if (is_file($router)) {
					require_once($router);
					require_once(JPATH_SITE . '/components/com_easydiscuss/helpers/helper.php');
					require_once(JPATH_SITE . '/components/com_easydiscuss/helpers/image.php');

					if (count($users)) {
						$db->setQuery('SELECT id as userid, avatar FROM #__discuss_users WHERE id in (' . implode(',', $users) . ')');
						$avatars = $db->loadObjectList('userid');
					}

					$avatarA = JPATH_ROOT . DS . DiscussImageHelper::getAvatarRelativePath() . DS;
					$avatarL = JURI::base() . DiscussImageHelper::getAvatarRelativePath() . '/';

					foreach ($comments as &$comment) {
						$uid = (int)$comment->userid;

						$comment->profileLink = DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&id=' . $uid, false);

						if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
							if (file_exists($avatarA . $avatars[$uid]->avatar)) {
								$comment->avatar = $avatarL . $avatars[$uid]->avatar;
							}
						}
					}
				}
				break;

			case 'jomsocial':
				if (count($users)) {
					$db->setQuery('SELECT userid, thumb as avatar FROM #__community_users WHERE userid in (' . implode(',', $users) . ')');
					$avatars = $db->loadObjectList('userid');
				}

				$avatarA = JPATH_SITE . DS;
				$avatarL = JURI::base() . '/';

				foreach ($comments as &$comment) {
					$uid = (int)$comment->userid;

					$comment->profileLink = $uid ? JRoute::_('index.php?option=com_community&view=profile&userid=' . $uid) : '';

					if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '' && $avatars[$uid]->avatar != 'components/com_community/assets/default_thumb.jpg') {
						if (file_exists($avatarA . $avatars[$uid]->avatar)) {
							$comment->avatar = $avatarL . $avatars[$uid]->avatar;
						}
					}
				}
				break;

			case 'joobb':
				$cfgFile = JPATH_SITE . '/components/com_joobb/system/joobbconfig.php';

				if (is_file($cfgFile)) {
					include_once($cfgFile);

					if (count($users)) {
						$db->setQuery('SELECT id, avatar_file as avatar FROM #__joobb_users WHERE id in (' . implode(',', $users) . ')');
						$avatars = $db->loadObjectList('id');
					}

					$Itemid = self::getItemid('index.php?option=com_joobb');

					$config = JoobbConfig::getInstance();
					$avatarsPath = $config->getAvatarSettings('avatar_path');

					$avatarA = JPATH_SITE . DS . $avatarsPath . DS;
					$avatarL = JURI::root() . '/' . $avatarsPath . '/';

					foreach ($comments as &$comment) {
						$uid = (int)$comment->userid;

						$comment->profileLink = $uid ? JRoute::_('index.php?option=com_joobb&view=profile&id=' . $avatars[$uid]->id . $Itemid) : '';

						if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
							if (file_exists($avatarA . $avatars[$uid]->avatar)) {
								$comment->avatar = $avatarL . $avatars[$uid]->avatar;
							}
						}
					}
				}
				break;

			case 'k2':
				$router = JPATH_SITE . '/components/com_k2/helpers/route.php';
				if (is_file($router)) {
					require_once($router);
					require_once(JPATH_SITE . '/components/com_k2/helpers/utilities.php');

					if (count($users)) {
						$db->setQuery('SELECT userid, image as avatar FROM #__k2_users WHERE userid in (' . implode(',', $users) . ')');
						$avatars = $db->loadObjectList('userid');
					}

					$avatarA = JPATH_SITE . '/media/k2/users/';
					$avatarL = JURI::base() . 'media/k2/users/';

					foreach ($comments as &$comment) {
						$uid = (int)$comment->userid;

						$comment->profileLink = $uid ? JRoute::_(K2HelperRoute::getUserRoute($uid)) : '';

						if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
							if (file_exists($avatarA . $avatars[$uid]->avatar)) {
								$comment->avatar = $avatarL . $avatars[$uid]->avatar;
							}
						}
					}
				}
				break;

			case 'kunena':
				$api = JPATH_ADMINISTRATOR . '/components/com_kunena/api.php';
				if (is_file($api)) {
					require_once($api);

					if (count($users)) {
						$db->setQuery('SELECT userid, avatar FROM #__kunena_users WHERE userid in (' . implode(',', $users) . ')');
						$avatars = $db->loadObjectList('userid');
					}

					$avatarA = JPATH_SITE . '/media/kunena/avatars/';
					$avatarL = JURI::base() . 'media/kunena/avatars/';

					foreach ($comments as &$comment) {
						$uid = (int)$comment->userid;

						$comment->profileLink = $uid ? KunenaRoute::_('index.php?option=com_kunena&func=profile&userid=' . $uid) : '';

						if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
							if (is_file($avatarA . $avatars[$uid]->avatar)) {
								$comment->avatar = $avatarL . $avatars[$uid]->avatar;
							}
						}
					}
				}
				break;

			case 'phocagallery':
				$helper = JPATH_SITE . '/components/com_phocagallery/libraries/phocagallery/path/path.php';
				if (is_file($helper)) {
					require_once($helper);

					if (count($users)) {
						$db->setQuery('SELECT userid, avatar FROM #__phocagallery_user WHERE userid in (' . implode(',', $users) . ')');
						$avatars = $db->loadObjectList('userid');
					}

					$path = PhocaGalleryPath::getPath();

					$avatarA = $path->avatar_abs;
					$avatarL = $path->avatar_rel;

					foreach ($comments as &$comment) {
						$uid = (int)$comment->userid;

						$comment->profileLink = '';

						if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
							if (is_file($avatarA . $avatars[$uid]->avatar)) {
								$comment->avatar = $avatarL . $avatars[$uid]->avatar;
							}
						}
					}
				}
				break;

			case 'slogin':
				$helper = JPATH_SITE . '/plugins/slogin_integration/profile/profile.php';
				if (is_file($helper)) {
					if (count($users)) {
						$db->setQuery('SELECT user_id as userid, social_profile_link as link, avatar FROM #__plg_slogin_profile WHERE current_profile = 1 AND user_id in (' . implode(',', $users) . ')');
						$avatars = $db->loadObjectList('userid');
					}

					$plugin = JPluginHelper::getPlugin('slogin_integration', 'profile');
					$pluginParams = new JRegistry();
					$pluginParams->loadString($plugin->params);
					$folder = $pluginParams->get('rootfolder', 'images/avatar');

					$avatarA = JPATH_SITE . '/' . $folder . '/';
					$avatarL = JURI::base() . $folder . '/';

					foreach ($comments as &$comment) {
						$uid = (int)$comment->userid;

						$comment->profileLink = $avatars[$uid]->link;

						if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
							if (file_exists($avatarA . $avatars[$uid]->avatar)) {
								$comment->avatar = $avatarL . $avatars[$uid]->avatar;
							}
						}
					}
				} else {
					$helper = JPATH_SITE . '/plugins/slogin_integration/slogin_avatar/slogin_avatar.php';
					if (is_file($helper)) {
						if (count($users)) {
							$db->setQuery('SELECT userid, photo_src as avatar FROM #__plg_slogin_avatar WHERE main = 1 AND userid in (' . implode(',', $users) . ')');
							$avatars = $db->loadObjectList('userid');
						}

						$plugin = JPluginHelper::getPlugin('slogin_integration', 'slogin_avatar');
						$pluginParams = new JRegistry();
						$pluginParams->loadString($plugin->params);
						$folder = $pluginParams->get('rootfolder', 'images/avatar');

						$avatarA = JPATH_SITE . '/' . $folder . '/';
						$avatarL = JURI::base() . $folder . '/';

						foreach ($comments as &$comment) {
							$uid = (int)$comment->userid;

							$comment->profileLink = '';

							if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
								if (file_exists($avatarA . $avatars[$uid]->avatar)) {
									$comment->avatar = $avatarL . $avatars[$uid]->avatar;
								}
							}
						}
					}
				}
				break;

			case 'easyprofile':
				$api = JPATH_ADMINISTRATOR . '/components/com_jsn/jsn.php';
				if (is_file($api)) {
					if (count($users)) {
						$db->setQuery('SELECT id as userid, avatar FROM #__jsn_users WHERE id in (' . implode(',', $users) . ')');
						$avatars = $db->loadObjectList('userid');
					}

					foreach ($comments as &$comment) {
						$uid = (int)$comment->userid;

						$comment->profileLink = $uid ? JRoute::_('index.php?option=com_jsn&view=profile&id=' . $uid) : '';

						if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') {
							if (is_file(JPATH_SITE . '/' . $avatars[$uid]->avatar)) {
								$comment->avatar = JURI::base() . $avatars[$uid]->avatar;
							}
						}
					}
				}
				break;

			case 'gravatar':
			default:
				foreach ($comments as &$comment) {
					$comment->profileLink = '';
					$comment->avatar = $this->getGravatar($comment->email);
				}
				break;
		}

		if ($avatar_default_avatar == 'custom' && empty($avatar_custom_default_avatar)) {
			$avatar_default_avatar = 'default';
		}

		foreach ($comments as &$comment) {
			if (empty($comment->avatar)) {
				switch ($avatar_default_avatar) {
					case 'gravatar':
						$comment->avatar = $this->getGravatar($comment->email);
						break;

					case 'custom':
						$comment->avatar = JURI::base() . ltrim($avatar_custom_default_avatar, '/');
						break;

					case 'default':
						$comment->avatar = JURI::base() . 'components/com_jcomments/images/no_avatar.png';
						break;
				}
			}

			$comment->avatar = self::createImg($comment->avatar, JComments::getCommentAuthorName($comment));

			if ($avatar_link && !empty($comment->profileLink)) {
				$comment->avatar = self::createLink($comment->avatar, $comment->profileLink, $avatar_link_target);
			}
		}

		return;
	}
Exemplo n.º 11
0
 static function getList(&$params)
 {
     $db = JFactory::getDBO();
     $interval = $params->get('interval', '');
     $where = array();
     if (!empty($interval)) {
         $date = JFactory::getDate();
         $timestamp = $date->toUnix();
         switch ($interval) {
             case '1-day':
                 $timestamp = strtotime('-1 day', $timestamp);
                 break;
             case '1-week':
                 $timestamp = strtotime('-1 week', $timestamp);
                 break;
             case '2-week':
                 $timestamp = strtotime('-2 week', $timestamp);
                 break;
             case '1-month':
                 $timestamp = strtotime('-1 month', $timestamp);
                 break;
             case '3-month':
                 $timestamp = strtotime('-3 month', $timestamp);
                 break;
             case '6-month':
                 $timestamp = strtotime('-6 month', $timestamp);
                 break;
             case '1-year':
                 $timestamp = strtotime('-1 year', $timestamp);
                 break;
             default:
                 $timestamp = NULL;
                 break;
         }
         if ($timestamp !== NULL) {
             if (version_compare(JVERSION, '1.6.0', 'ge')) {
                 $dateFrom = JFactory::getDate($timestamp)->toSql();
                 $dateTo = $date->toSql();
             } else {
                 $dateFrom = JFactory::getDate($timestamp)->toMySql();
                 $dateTo = $date->toMySQL();
             }
             $where[] = 'c.date BETWEEN ' . $db->Quote($dateFrom) . ' AND ' . $db->Quote($dateTo);
         }
     }
     switch ($params->get('ordering', '')) {
         case 'votes':
             $orderBy = 'votes DESC';
             break;
         case 'comments':
         default:
             $orderBy = 'commentsCount DESC';
             break;
     }
     $where[] = 'c.published = 1';
     $where[] = 'c.deleted = 0';
     $query = "SELECT c.userid, '' as avatar, '' as profileLink" . " , CASE WHEN c.userid = 0 THEN c.email ELSE u.email END AS email" . " , CASE WHEN c.userid = 0 THEN c.name ELSE u.name END AS name" . " , CASE WHEN c.userid = 0 THEN c.username ELSE u.username END AS username" . " , COUNT(c.userid) AS commentsCount" . " , SUM(c.isgood) AS isgood, SUM(c.ispoor) AS ispoor, SUM(c.isgood - c.ispoor) AS votes" . " FROM #__jcomments AS c" . " LEFT JOIN #__users AS u ON u.id = c.userid" . (count($where) ? ' WHERE  ' . implode(' AND ', $where) : '') . " GROUP BY c.userid, email, name, username, avatar, profileLink" . " ORDER BY " . $orderBy;
     $db->setQuery($query, 0, $params->get('count'));
     $list = $db->loadObjectList();
     $show_avatar = $params->get('show_avatar', 0);
     if ($show_avatar) {
         JPluginHelper::importPlugin('jcomments');
         if (version_compare(JVERSION, '3.0', 'ge')) {
             $dispatcher = JEventDispatcher::getInstance();
         } else {
             $dispatcher = JDispatcher::getInstance();
         }
         $dispatcher->trigger('onPrepareAvatars', array(&$list));
     }
     foreach ($list as &$item) {
         $item->displayAuthorName = JComments::getCommentAuthorName($item);
         if ($show_avatar && empty($item->avatar)) {
             $gravatar = md5(strtolower($item->email));
             $item->avatar = '<img src="http://www.gravatar.com/avatar.php?gravatar_id=' . $gravatar . '&amp;default=' . urlencode(JCommentsFactory::getLink('noavatar')) . '" alt="' . htmlspecialchars(JComments::getCommentAuthorName($item)) . '" />';
         }
     }
     return $list;
 }