예제 #1
0
 /**
  * Returns a reference to a language object.
  * 
  * @param string $language The language to use.
  * @param string $component The component name.
  * @return JCommentsCfg
  */
 public static function getInstance($language = '', $component = '')
 {
     static $instance = null;
     $app = JCommentsFactory::getApplication();
     if (JCOMMENTS_JVERSION == '1.7') {
         $multilingual_support = $app->isSite() && $app->getLanguageFilter();
     } else {
         $multilingual_support = $app->getCfg('multilingual_support') == 1;
     }
     if (!is_object($instance)) {
         $instance = new JCommentsCfg();
         if ($language == '') {
             $language = $multilingual_support ? JCommentsMultilingual::getLanguage() : '';
         }
         $instance->load($language, $component);
     } else {
         if ($language != $instance->_current && $instance->_current == '') {
             if ($language != '') {
                 $instance->load($language, $component);
             } else {
                 $language = $multilingual_support ? JCommentsMultilingual::getLanguage() : '';
                 if ($language != '') {
                     $instance->load($language, $component);
                 }
             }
         }
     }
     return $instance;
 }
예제 #2
0
 /**
  * Returns a reference to a language object.
  * 
  * @static
  * @access public
  * @param string $language The language to use.
  * @return JCommentsCfg
  */
 function &getInstance($language = '', $component = '')
 {
     static $instance = null;
     global $mainframe;
     if (!is_object($instance)) {
         $instance = new JCommentsCfg();
         if ($language == '') {
             $multilingual_support = $mainframe->getCfg('multilingual_support') == 1;
             $language = $multilingual_support ? JCommentsMultilingual::getLanguage() : '';
         }
         $instance->load($language, $component);
     } else {
         if ($language != $instance->_current && $instance->_current == '') {
             if ($language != '') {
                 $instance->load($language, $component);
             } else {
                 $multilingual_support = $mainframe->getCfg('multilingual_support') == 1;
                 $language = $multilingual_support ? JCommentsMultilingual::getLanguage() : '';
                 if ($language != '') {
                     $instance->load($language, $component);
                 }
             }
         }
     }
     return $instance;
 }
예제 #3
0
 function store($updateNulls = false)
 {
     if ($this->userid != 0 && empty($this->email)) {
         $user = JFactory::getUser($this->userid);
         $this->email = $user->email;
     }
     if ($this->userid == 0 && !empty($this->email)) {
         $db = JFactory::getDBO();
         $query = $db->getQuery(true);
         $query->select('*');
         $query->from($db->quoteName('#__users'));
         $query->where($db->quoteName('email') . ' = ' . $db->Quote($db->escape($this->email, true)));
         $db->setQuery($query);
         $users = $db->loadObjectList();
         if (count($users)) {
             $this->userid = $users[0]->id;
             $this->name = $users[0]->name;
         }
     }
     if (empty($this->lang)) {
         $this->lang = JCommentsMultilingual::getLanguage();
     }
     $this->hash = $this->getHash();
     return parent::store($updateNulls);
 }
예제 #4
0
 public static function checkFlood($ip)
 {
     $interval = JCommentsFactory::getConfig()->getInt('flood_time');
     if ($interval > 0) {
         $db = JFactory::getDbo();
         $now = JFactory::getDate()->toSql();
         $query = "SELECT COUNT(*) " . "\nFROM #__jcomments " . "\nWHERE ip = " . $db->Quote($ip) . "\nAND " . $db->Quote($now) . " < DATE_ADD(date, INTERVAL " . $interval . " SECOND)" . (JCommentsMultilingual::isEnabled() ? "\nAND lang = " . $db->Quote(JCommentsMultilingual::getLanguage()) : '');
         $db->setQuery($query);
         return $db->loadResult() == 0 ? 0 : 1;
     }
     return 0;
 }
예제 #5
0
 function store($updateNulls = false)
 {
     if ($this->userid != 0 && empty($this->email)) {
         $user = JCommentsFactory::getUser($this->userid);
         $this->email = $user->email;
         unset($user);
     }
     if (empty($this->lang)) {
         $this->lang = JCommentsMultilingual::getLanguage();
     }
     $this->hash = $this->getHash();
     return parent::store($updateNulls);
 }
예제 #6
0
 /**
  * Returns a reference to a JCommentsCfg object.
  *
  * @param string $language The language code.
  * @param string $component The component name.
  * @return JCommentsCfg
  */
 public static function getInstance($language = '', $component = '')
 {
     static $instance = null;
     if ($language == '' && JCommentsMultilingual::isEnabled()) {
         $language = JCommentsMultilingual::getLanguage();
     }
     if (!is_object($instance)) {
         $instance = new JCommentsCfg();
         $instance->load($language, $component);
     } else {
         if ($language != $instance->_current && $instance->_current == '') {
             if ($language != '') {
                 $instance->load($language, $component);
             }
         }
     }
     return $instance;
 }
예제 #7
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;
     }
 }
예제 #8
0
 public static function loadSettingsByLanguage($language = '')
 {
     $lang = '';
     $joomfish = JOOMLATUNE_JPATH_SITE . '/components/com_joomfish/joomfish.php';
     if (is_file($joomfish) || JCommentsMultilingual::isEnabled()) {
         $lang = $language;
         if ($lang == '') {
             $lang = JCommentsMultilingual::getLanguage();
         }
         // reload configuration
         JCommentsFactory::getConfig($lang);
     }
     return $lang;
 }
예제 #9
0
파일: helper.php 프로젝트: enjoy2000/smcd
 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;
 }
예제 #10
0
파일: helper.php 프로젝트: enjoy2000/smcd
 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);
     }
     $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[] = 'o.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 o.id, o.title, o.link" . ", COUNT(c.id) AS commentsCount, MAX(c.date) AS commentdate" . " FROM #__jcomments_objects AS o" . " JOIN #__jcomments AS c 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) : '') . " GROUP BY o.id, o.title, o.link" . " ORDER BY commentsCount DESC, c.date DESC";
     $db->setQuery($query, 0, $params->get('count'));
     $list = $db->loadObjectList();
     return $list;
 }
 function _isSubscribed($object_id, $object_group, $userid, $email = '', $language = '')
 {
     if (empty($language)) {
         $language = JCommentsMultilingual::getLanguage();
     }
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('COUNT(*)');
     $query->from($db->quoteName('#__jcomments_subscriptions'));
     $query->where($db->quoteName('object_id') . ' = ' . (int) $object_id);
     $query->where($db->quoteName('object_group') . ' = ' . $db->Quote($object_group));
     $query->where($db->quoteName('userid') . ' = ' . (int) $userid);
     if ($userid == 0) {
         $query->where($db->quoteName('email') . ' = ' . $db->Quote($email));
     }
     if (JCommentsMultilingual::isEnabled()) {
         $query->where($db->quoteName('lang') . ' = ' . $db->Quote($language));
     }
     $db->setQuery($query);
     $count = $db->loadResult();
     return $count > 0 ? 1 : 0;
 }
예제 #12
0
 /**
  * Returns list of subscribers for given object and subscription type
  *
  * @param int $object_id
  * @param string $object_group
  * @param string $lang The language
  * @param string $type The subscription type
  *
  * @return array
  */
 private static function getSubscribers($object_id, $object_group, $lang, $type)
 {
     $subscribers = array();
     switch ($type) {
         case 'moderate-new':
         case 'moderate-update':
         case 'report':
             $config = JCommentsFactory::getConfig();
             if ($config->get('notification_email') != '') {
                 $emails = explode(',', $config->get('notification_email'));
                 $db = JFactory::getDbo();
                 $db->setQuery('SELECT * FROM #__users WHERE email IN ("' . implode('", "', $emails) . '")');
                 $users = $db->loadObjectList('email');
                 foreach ($emails as $email) {
                     $email = trim($email);
                     $subscriber = new stdClass();
                     $subscriber->id = isset($users[$email]) ? $users[$email]->id : 0;
                     $subscriber->name = isset($users[$email]) ? $users[$email]->name : '';
                     $subscriber->email = $email;
                     $subscriber->hash = md5($email);
                     $subscribers[] = $subscriber;
                 }
             }
             break;
         case 'comment-new':
         case 'comment-reply':
         case 'comment-update':
         default:
             $db = JFactory::getDbo();
             $query = "SELECT DISTINCTROW js.`name`, js.`email`, js.`hash`, js.`userid` " . " FROM #__jcomments_subscriptions AS js" . " JOIN #__jcomments_objects AS jo ON js.object_id = jo.object_id AND js.object_group = jo.object_group" . " WHERE js.`object_group` = " . $db->Quote($object_group) . " AND js.`object_id` = " . intval($object_id) . " AND js.`published` = 1 " . (JCommentsMultilingual::isEnabled() ? " AND js.`lang` = " . $db->Quote($lang) : '') . (JCommentsMultilingual::isEnabled() ? " AND jo.`lang` = " . $db->Quote($lang) : '');
             $db->setQuery($query);
             $subscribers = $db->loadObjectList();
             break;
     }
     return is_array($subscribers) ? $subscribers : array();
 }
예제 #13
0
 function addComment($values = array())
 {
     global $my, $mainframe;
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $acl =& JCommentsFactory::getACL();
     $config =& JCommentsFactory::getConfig();
     $response =& JCommentsFactory::getAjaxResponse();
     if ($acl->canComment()) {
         $values = JCommentsAJAX::prepareValues($_POST);
         $userIP = $acl->getUserIP();
         if (!$my->id) {
             $noErrors = false;
             if (empty($values['name'])) {
                 JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_NAME'), 'name');
             } else {
                 if (JCommentsSecurity::checkIsRegisteredUsername($values['name']) == 1) {
                     JCommentsAJAX::showErrorMessage(JText::_('ERROR_NAME_EXISTS'), 'name');
                 } else {
                     if (JCommentsSecurity::checkIsForbiddenUsername($values['name']) == 1) {
                         JCommentsAJAX::showErrorMessage(JText::_('ERROR_FORBIDDEN_NAME'), 'name');
                     } else {
                         if (preg_match('/[\\"\'\\[\\]\\=\\<\\>\\(\\)\\;]+/', $values['name'])) {
                             JCommentsAJAX::showErrorMessage(JText::_('ERROR_INVALID_NAME'), 'name');
                         } else {
                             if ($config->get('username_maxlength') != 0 && JCommentsText::strlen($values['name']) > $config->get('username_maxlength')) {
                                 JCommentsAJAX::showErrorMessage(JText::_('ERROR_TOO_LONG_USERNAME'), 'name');
                             } else {
                                 if ($config->get('author_email') == 2 && empty($values['email'])) {
                                     JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_EMAIL'), 'email');
                                 } else {
                                     if (!empty($values['email']) && !preg_match(_JC_REGEXP_EMAIL2, $values['email'])) {
                                         JCommentsAJAX::showErrorMessage(JText::_('ERROR_INCORRECT_EMAIL'), 'email');
                                     } else {
                                         if ($config->get('author_email') != 0 && JCommentsSecurity::checkIsRegisteredEmail($values['email']) == 1) {
                                             // TODO: change this error message with more appropriate
                                             JCommentsAJAX::showErrorMessage(JText::_('ERROR_NAME_EXISTS'), 'email');
                                         } else {
                                             if (empty($values['homepage']) && $config->get('author_homepage') == 2) {
                                                 JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_HOMEPAGE'), 'homepage');
                                             } else {
                                                 $noErrors = true;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!$noErrors) {
                 return $response;
             }
         }
         if ($acl->check('floodprotection') == 1 && JCommentsSecurity::checkFlood($userIP)) {
             JCommentsAJAX::showErrorMessage(JText::_('ERROR_TOO_QUICK'));
         } else {
             if (empty($values['homepage']) && $config->get('author_homepage') == 3) {
                 JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_HOMEPAGE'), 'homepage');
             } else {
                 if (empty($values['title']) && $config->get('comment_title') == 3) {
                     JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_TITLE'), 'title');
                 } else {
                     if (empty($values['comment'])) {
                         JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_COMMENT'), 'comment');
                     } else {
                         if ($config->getInt('comment_maxlength') != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) > $config->get('comment_maxlength')) {
                             JCommentsAJAX::showErrorMessage(JText::_('Your comment is too long'), 'comment');
                         } else {
                             if ($config->getInt('comment_minlength', 0) != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($values['comment']) < $config->get('comment_minlength')) {
                                 JCommentsAJAX::showErrorMessage(JText::_('Your comment is too short'), 'comment');
                             } else {
                                 if ($acl->check('enable_captcha') == 1) {
                                     $captchaEngine = $config->get('captcha_engine', 'kcaptcha');
                                     if ($captchaEngine == 'kcaptcha') {
                                         require_once JCOMMENTS_BASE . DS . 'jcomments.captcha.php';
                                         if (!JCommentsCaptcha::check($values['captcha-refid'])) {
                                             JCommentsAJAX::showErrorMessage(JText::_('ERROR_CAPTCHA'), 'captcha');
                                             JCommentsCaptcha::destroy();
                                             $response->addScript("jcomments.clear('captcha');");
                                             return $response;
                                         }
                                     } else {
                                         if ($config->getInt('enable_mambots') == 1) {
                                             require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
                                             JCommentsPluginHelper::importPlugin('jcomments');
                                             $result = JCommentsPluginHelper::trigger('onJCommentsCaptchaVerify', array($values['captcha-refid'], &$response));
                                             // if all plugins returns false
                                             if (!in_array(true, $result, true)) {
                                                 JCommentsAJAX::showErrorMessage(JText::_('ERROR_CAPTCHA'));
                                                 return $response;
                                             }
                                         }
                                     }
                                 }
                                 $db =& JCommentsFactory::getDBO();
                                 // small fix (by default $my has empty 'name' and 'email' field)
                                 if ($my->id) {
                                     $currentUser = JCommentsFactory::getUser($my->id);
                                     $my->name = $currentUser->name;
                                     $my->username = $currentUser->username;
                                     $my->email = $currentUser->email;
                                     unset($currentUser);
                                 }
                                 $comment = new JCommentsDB($db);
                                 $comment->id = 0;
                                 $comment->name = $my->id ? $my->name : preg_replace("/[\\'\"\\>\\<\\(\\)\\[\\]]?+/i", '', $values['name']);
                                 $comment->username = $my->id ? $my->username : $comment->name;
                                 $comment->email = $my->id ? $my->email : (isset($values['email']) ? $values['email'] : '');
                                 if ($config->getInt('author_homepage') != 0 && !empty($values['homepage'])) {
                                     $comment->homepage = JCommentsText::url($values['homepage']);
                                 }
                                 $comment->comment = $values['comment'];
                                 //$comment->comment = JCommentsText::nl2br(stripslashes($values['comment']));
                                 // filter forbidden bbcodes
                                 $bbcode = JCommentsFactory::getBBCode();
                                 $comment->comment = $bbcode->filter($comment->comment);
                                 if ($comment->comment != '') {
                                     if ($config->getInt('enable_custom_bbcode')) {
                                         // filter forbidden custom bbcodes
                                         $commentLength = strlen($comment->comment);
                                         $customBBCode =& JCommentsFactory::getCustomBBCode();
                                         $comment->comment = $customBBCode->filter($comment->comment);
                                         if (strlen($comment->comment) == 0 && $commentLength > 0) {
                                             JCommentsAJAX::showErrorMessage(JText::_('You have no rights to use this tag'), 'comment');
                                             return $response;
                                         }
                                     }
                                 }
                                 if ($comment->comment == '') {
                                     JCommentsAJAX::showErrorMessage(JText::_('ERROR_EMPTY_COMMENT'), 'comment');
                                     return $response;
                                 }
                                 $commentWithoutQuotes = $bbcode->removeQuotes($comment->comment);
                                 if ($commentWithoutQuotes == '') {
                                     JCommentsAJAX::showErrorMessage(JText::_('ERROR_NOTHING_EXCEPT_QUOTES'), 'comment');
                                     return $response;
                                 } else {
                                     if ($config->getInt('comment_minlength', 0) != 0 && $acl->check('enable_comment_length_check') == 1 && JCommentsText::strlen($commentWithoutQuotes) < $config->get('comment_minlength')) {
                                         JCommentsAJAX::showErrorMessage(JText::_('Your comment is too short'), 'comment');
                                         return $response;
                                     }
                                 }
                                 unset($commentWithoutQuotes);
                                 $values['subscribe'] = isset($values['subscribe']) ? (int) $values['subscribe'] : 0;
                                 if ($values['subscribe'] == 1 && $comment->email == '') {
                                     JCommentsAJAX::showErrorMessage(JText::_('ERROR_SUBSCRIPTION_EMAIL'), 'email');
                                     return $response;
                                 }
                                 $object_group = trim(strip_tags($values['object_group']));
                                 $object_group = preg_replace('#[^0-9A-Za-z\\-\\_\\,\\.]#is', '', $object_group);
                                 $comment->object_id = (int) $values['object_id'];
                                 $comment->object_group = $object_group;
                                 $comment->title = isset($values['title']) ? $values['title'] : '';
                                 $comment->parent = isset($values['parent']) ? intval($values['parent']) : 0;
                                 $comment->lang = JCommentsMultilingual::getLanguage();
                                 $comment->ip = $userIP;
                                 $comment->userid = $my->id ? $my->id : 0;
                                 $comment->published = $acl->check('autopublish');
                                 if (JCOMMENTS_JVERSION == '1.5') {
                                     $dateNow =& JFactory::getDate();
                                     $comment->date = $dateNow->toMySQL();
                                 } else {
                                     $comment->date = date('Y-m-d H:i:s', time() + $mainframe->getCfg('offset') * 60 * 60);
                                 }
                                 $query = "SELECT COUNT(*) " . "\nFROM #__jcomments " . "\nWHERE comment = '" . $db->getEscaped($comment->comment) . "'" . "\n  AND ip = '" . $db->getEscaped($comment->ip) . "'" . "\n  AND name = '" . $db->getEscaped($comment->name) . "'" . "\n  AND userid = '" . $comment->userid . "'" . "\n  AND object_id = " . $comment->object_id . "\n  AND parent = " . $comment->parent . "\n  AND object_group = '" . $db->getEscaped($comment->object_group) . "'" . (JCommentsMultilingual::isEnabled() ? "\nAND lang = '" . JCommentsMultilingual::getLanguage() . "'" : "");
                                 $db->setQuery($query);
                                 $found = $db->loadResult();
                                 // if duplicates is not found
                                 if ($found == 0) {
                                     // trigger onBeforeCommentAdded event
                                     $allowed = true;
                                     if ($config->getInt('enable_mambots') == 1) {
                                         require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
                                         JCommentsPluginHelper::importPlugin('jcomments');
                                         JCommentsPluginHelper::trigger('onBeforeCommentAdded', array(&$comment, &$response, &$allowed));
                                     }
                                     if ($allowed === false) {
                                         return $response;
                                     }
                                     // save comments subscription
                                     if ($values['subscribe']) {
                                         require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
                                         $manager =& JCommentsSubscriptionManager::getInstance();
                                         $manager->subscribe($comment->object_id, $comment->object_group, $comment->userid, $comment->email, $comment->name, $comment->lang);
                                     }
                                     $merged = false;
                                     $merge_time = $config->getInt('merge_time', 0);
                                     // merge comments from same author
                                     if ($my->id && $merge_time > 0) {
                                         // load previous comment for same object and group
                                         $prevComment = JComments::getLastComment($comment->object_id, $comment->object_group, $comment->parent);
                                         if ($prevComment != null) {
                                             // if previous comment from same author and it currently not edited
                                             // by any user - we'll update comment, else - insert new record to database
                                             if ($prevComment->userid == $comment->userid && $prevComment->parent == $comment->parent && !$acl->isLocked($prevComment)) {
                                                 $newText = $prevComment->comment . '<br /><br />' . $comment->comment;
                                                 $timeDiff = strtotime($comment->date) - strtotime($prevComment->datetime);
                                                 if ($timeDiff < $merge_time) {
                                                     $maxlength = $config->getInt('comment_maxlength');
                                                     $needcheck = $acl->check('enable_comment_length_check');
                                                     // validate new comment text length and if it longer than specified -
                                                     // disable union current comment with previous
                                                     if ($needcheck == 0 || $needcheck == 1 && $maxlength != 0 && JCommentsText::strlen($newText) <= $maxlength) {
                                                         $comment->id = $prevComment->id;
                                                         $comment->comment = $newText;
                                                         $merged = true;
                                                     }
                                                 }
                                             }
                                             unset($prevComment);
                                         }
                                     }
                                     if ($comment->parent > 0) {
                                         $parent = new JCommentsDB($db);
                                         if ($parent->load($comment->parent)) {
                                             if ($config->getInt('comment_title') == 1 && $comment->title == '') {
                                                 if (!empty($parent->title)) {
                                                     $comment->title = JText::_('Re') . ' ' . $parent->title;
                                                 }
                                             }
                                             $comment->level = $parent->level + 1;
                                             $comment->path = $parent->path . ',' . $parent->id;
                                         }
                                     } else {
                                         if ($config->getInt('comment_title') == 1 && $comment->title == '') {
                                             $object_title = JCommentsObjectHelper::getTitle($comment->object_id, $comment->object_group, $comment->lang);
                                             $comment->title = JText::_('Re') . ' ' . $object_title;
                                         }
                                         $comment->path = '0';
                                     }
                                     // save new comment to database
                                     if (!$comment->store()) {
                                         $response->addScript("jcomments.clear('comment');");
                                         if ($acl->check('enable_captcha') == 1) {
                                             JCommentsCaptcha::destroy();
                                             $response->addScript("jcomments.clear('captcha');");
                                         }
                                         $errorMessage = $db->getErrorMsg();
                                         if ($errorMessage != '') {
                                             if ($my->usertype == 'Super Administrator') {
                                                 JCommentsAJAX::showErrorMessage($db->getErrorMsg());
                                             }
                                         }
                                         return $response;
                                     }
                                     // datetime field is used in prepareComment function
                                     $comment->datetime = $comment->date;
                                     if (is_string($comment->datetime)) {
                                         $comment->datetime = strtotime($comment->datetime);
                                     }
                                     if ($config->getInt('enable_mambots') == 1) {
                                         require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
                                         JCommentsPluginHelper::importPlugin('jcomments');
                                         JCommentsPluginHelper::trigger('onAfterCommentAdded', array(&$comment, &$response, &$allowed));
                                     }
                                     // send notification to administrators
                                     if ($config->getInt('enable_notification') == 1) {
                                         if ($config->check('notification_type', 1) == true) {
                                             JComments::sendNotification($comment, true);
                                         }
                                     }
                                     // if comment published we need update comments list
                                     if ($comment->published) {
                                         // send notification to comment subscribers
                                         JComments::sendToSubscribers($comment, true);
                                         $comment->usertype = $my->id != 0 ? str_replace(' ', '-', strtolower($my->usertype)) : 'guest';
                                         if ($merged) {
                                             $commentText = $comment->comment;
                                             JComments::prepareComment($comment);
                                             $tmpl =& JCommentsFactory::getTemplate();
                                             $tmpl->load('tpl_comment');
                                             $tmpl->addVar('tpl_comment', 'get_comment_body', 1);
                                             $tmpl->addObject('tpl_comment', 'comment', $comment);
                                             $html = $tmpl->renderTemplate('tpl_comment');
                                             $html = JCommentsText::jsEscape($html);
                                             $response->addScript("jcomments.updateComment(" . $comment->id . ", '{$html}');");
                                             $comment->comment = $commentText;
                                         } else {
                                             $count = JCommentsModel::getCommentsCount($comment->object_id, $comment->object_group);
                                             if ($config->get('template_view') == 'tree') {
                                                 if ($count > 1) {
                                                     $html = JComments::getCommentListItem($comment);
                                                     $html = JCommentsText::jsEscape($html);
                                                     $response->addScript("jcomments.updateTree('{$html}','{$comment->parent}');");
                                                 } else {
                                                     $html = JComments::getCommentsTree($comment->object_id, $comment->object_group);
                                                     $html = JCommentsText::jsEscape($html);
                                                     $response->addScript("jcomments.updateTree('{$html}',null);");
                                                 }
                                             } else {
                                                 // if pagination disabled and comments count > 1...
                                                 if ($config->getInt('comments_per_page') == 0 && $count > 1) {
                                                     // update only added comment
                                                     $html = JComments::getCommentListItem($comment);
                                                     $html = JCommentsText::jsEscape($html);
                                                     if ($config->get('comments_order') == 'DESC') {
                                                         $response->addScript("jcomments.updateList('{$html}','p');");
                                                     } else {
                                                         $response->addScript("jcomments.updateList('{$html}','a');");
                                                     }
                                                 } else {
                                                     // update comments list
                                                     $html = JComments::getCommentsList($comment->object_id, $comment->object_group, JComments::getCommentPage($comment->object_id, $comment->object_group, $comment->id));
                                                     $html = JCommentsText::jsEscape($html);
                                                     $response->addScript("jcomments.updateList('{$html}','r');");
                                                 }
                                                 // scroll to first comment
                                                 if ($config->get('comments_order') == 'DESC') {
                                                     $response->addScript("jcomments.scrollToList();");
                                                 }
                                             }
                                         }
                                         JCommentsAJAX::showInfoMessage(JText::_('Thank you for your submission!'));
                                     } else {
                                         JCommentsAJAX::showInfoMessage(JText::_('Thank you, your comment will be published once reviewed'));
                                     }
                                     // clear comments textarea & update comment length counter if needed
                                     $response->addScript("jcomments.clear('comment');");
                                     unset($comment);
                                     if ($acl->check('enable_captcha') == 1) {
                                         $captchaEngine = $config->get('captcha_engine', 'kcaptcha');
                                         if ($captchaEngine == 'kcaptcha') {
                                             require_once JCOMMENTS_BASE . DS . 'jcomments.captcha.php';
                                             JCommentsCaptcha::destroy();
                                             $response->addScript("jcomments.clear('captcha');");
                                         }
                                     }
                                 } else {
                                     JCommentsAJAX::showErrorMessage(JText::_('ERROR_DUPLICATE_COMMENT'), 'comment');
                                 }
                             }
                         }
                     }
                 }
             }
         }
     } else {
         $response->addAlert(JText::_('ERROR_CANT_COMMENT'));
     }
     return $response;
 }
예제 #14
0
/**
* Comments Search method
*
* The sql must return the following fields that are used in a common display
* routine: href, title, section, created, text, browsernav
* @param string Target search string
* @param string matching option, exact|any|all
* @param string ordering option, newest|oldest|popular|alpha|category
* @param mixed An array if restricted to areas, null if search all
*/
function plgSearchJComments($text, $phrase = '', $ordering = '', $areas = null)
{
    $text = trim($text);
    if ($text == '') {
        return array();
    }
    if (is_array($areas)) {
        if (!array_intersect($areas, array_keys(plgSearchJCommentsAreas()))) {
            return array();
        }
    }
    if (file_exists(JCOMMENTS_BASE . DS . 'jcomments.php')) {
        require_once JCOMMENTS_BASE . DS . 'jcomments.php';
        require_once JCOMMENTS_BASE . DS . 'jcomments.class.php';
        require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
        require_once JCOMMENTS_HELPERS . DS . 'content.php';
        require_once JCOMMENTS_HELPERS . DS . 'object.php';
        $db =& JCommentsFactory::getDBO();
        $pluginParams = JCommentsPluginHelper::getParams('jcomments', 'search');
        $limit = $pluginParams->def('search_limit', 50);
        switch ($phrase) {
            case 'exact':
                $where = "LOWER(comment) LIKE '%{$text}%' OR LOWER(title) LIKE '%{$text}%'";
                break;
            case 'all':
            case 'any':
            default:
                $words = explode(' ', $text);
                $wheres = array();
                foreach ($words as $word) {
                    $wheres2 = array();
                    $wheres2[] = "LOWER(name) LIKE '%{$word}%'";
                    $wheres2[] = "LOWER(comment) LIKE '%{$word}%'";
                    $wheres2[] = "LOWER(title) LIKE '%{$word}%'";
                    $wheres[] = implode(' OR ', $wheres2);
                }
                $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
                break;
        }
        switch ($ordering) {
            case 'oldest':
                $order = 'date ASC';
                break;
            case 'newest':
            default:
                $order = 'date DESC';
                break;
        }
        $query = "SELECT " . "\n  comment AS text" . "\n, date AS created" . "\n, '2' AS browsernav" . "\n, '" . JText::_('Comments') . "' AS section" . "\n, ''  AS href" . "\n, id" . "\n, object_id" . "\n, object_group" . "\nFROM #__jcomments " . "\nWHERE published='1'" . (JCommentsMultilingual::isEnabled() ? "\nAND lang = '" . JCommentsMultilingual::getLanguage() . "'" : "") . "\n AND ({$where}) " . "\nORDER BY object_id, {$order}";
        $db->setQuery($query, 0, $limit);
        $rows = $db->loadObjectList();
        $result = array();
        $cnt = count($rows);
        if ($cnt > 0) {
            $last_object_id = -1;
            $object_link = '';
            $acl =& JCommentsFactory::getACL();
            $lang = JCommentsMultilingual::isEnabled() ? JCommentsMultilingual::getLanguage() : null;
            for ($i = 0; $i < $cnt; $i++) {
                if ($rows[$i]->object_id != $last_object_id) {
                    $last_object_id = $rows[$i]->object_id;
                    $object_link = JCommentsObjectHelper::getLink($rows[$i]->object_id, $rows[$i]->object_group);
                    $object_title = JCommentsObjectHelper::getTitle($rows[$i]->object_id, $rows[$i]->object_group, $lang);
                }
                $rows[$i]->href = $object_link . '#comment-' . $rows[$i]->id;
                $comment = JCommentsText::cleanText($rows[$i]->text);
                if ($acl->check('enable_autocensor')) {
                    $comment = JCommentsText::censor($comment);
                }
                if ($comment != '') {
                    $rows[$i]->title = $object_title;
                    $rows[$i]->text = $comment;
                    $result[] = $rows[$i];
                }
            }
        }
        unset($rows);
        return $result;
    }
    return array();
}
예제 #15
0
 function _isSubscribed($object_id, $object_group, $userid, $email = '', $language = '')
 {
     if (empty($language)) {
         $language = JCommentsMultilingual::getLanguage();
     }
     $db = JCommentsFactory::getDBO();
     $query = "SELECT COUNT(*) " . " FROM #__jcomments_subscriptions" . " WHERE object_id = " . (int) $object_id . " AND object_group = " . $db->Quote($object_group) . " AND userid = " . (int) $userid . ($userid == 0 ? " AND email = " . $db->Quote($email) : '') . (JCommentsMultilingual::isEnabled() ? " AND lang = " . $db->Quote($language) : "");
     $db->setQuery($query);
     $cnt = $db->loadResult();
     return $cnt > 0 ? 1 : 0;
 }
예제 #16
0
 /**
  * Checks if given user is subscribed to new comments notifications for an object
  *
  * @param int $object_id	The object identifier
  * @param string $object_group	The object group (component name)
  * @param int $userid	The registered user identifier
  * @param string $email	The user email (for guests only)
  * @return int
  */
 function isSubscribed($object_id, $object_group, $userid, $email = '', $lang = '')
 {
     static $cache = null;
     if (isset($cache[$object_id . $object_group . $userid . $email])) {
         return $cache[$object_id . $object_group . $userid . $email];
     }
     $dbo =& JCommentsFactory::getDBO();
     if ($lang == '') {
         $lang = JCommentsMultilingual::getLanguage();
     }
     $query = "SELECT COUNT(*) " . "\n FROM #__jcomments_subscriptions" . "\n WHERE object_id = " . (int) $object_id . "\n AND object_group = '" . $dbo->getEscaped($object_group) . "'" . "\n AND userid = " . (int) $userid . ($userid == 0 ? "\n AND email = '" . $dbo->getEscaped($email) . "'" : '') . (JCommentsMultilingual::isEnabled() ? "\nAND lang = '" . $lang . "'" : "");
     $dbo->setQuery($query);
     $cnt = $dbo->loadResult();
     $cache[$object_id . $object_group . $userid . $email] = (int) $cnt > 0;
     return $cnt > 0 ? 1 : 0;
 }
예제 #17
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;
     }
 }
 /**
  * onJCommentsCommentBeforeAdd trigger
  * @access public
  * @param JCommentsDB $comment
  * @return bolean true
  * @since 1.5
  */
 public function onJCommentsCommentBeforeAdd(&$comment)
 {
     $config = $this->getCTConfig();
     $session = JFactory::getSession();
     $submit_time = $this->submit_time_test();
     // set new time because onJCommentsFormAfterDisplay worked only once
     // and formtime in session need to be renewed between ajax posts
     $session->set($this->form_load_label, time());
     $checkjs = $this->get_ct_checkjs(true);
     $sender_info = $this->get_sender_info();
     $sender_info = json_encode($sender_info);
     if ($sender_info === false) {
         $sender_info = '';
     }
     $post_info['comment_type'] = 'jcomments_comment';
     $post_info['post_url'] = $session->get($this->current_page);
     $post_info = json_encode($post_info);
     if ($post_info === false) {
         $post_info = '';
     }
     $plugin_groups = array();
     $param_groups = $this->params->get('groups');
     if (is_array($param_groups)) {
         foreach ($param_groups as $group) {
             array_push($plugin_groups, (int) $group);
         }
     } else {
         array_push($plugin_groups, (int) $param_groups);
     }
     $user = JFactory::getUser();
     if (method_exists($user, 'getAuthorisedGroups')) {
         // 1.6+
         $user_groups = $user->getAuthorisedGroups();
     } else {
         // 1.5
         $user_groups = array();
         if ($user->guest) {
             array_push($user_groups, 29);
         } else {
             array_push($user_groups, $user->gid);
         }
     }
     foreach ($user_groups as $group) {
         if (in_array($group, $plugin_groups)) {
             $example = null;
             if ($config['relevance_test'] !== '') {
                 switch ($comment->object_group) {
                     case 'com_content':
                         $article = JTable::getInstance('content');
                         $article->load($comment->object_id);
                         $baseText = $article->introtext . '<br>' . $article->fulltext;
                         break;
                     default:
                         $baseText = '';
                 }
                 $db = JCommentsFactory::getDBO();
                 $query = "SELECT comment " . "\nFROM #__jcomments " . "\nWHERE published = 1 " . "\n  AND object_group = '" . $db->getEscaped($comment->object_group) . "'" . "\n  AND object_id = " . $comment->object_id . (JCommentsMultilingual::isEnabled() ? "\nAND lang = '" . JCommentsMultilingual::getLanguage() . "'" : "") . " ORDER BY id DESC " . " LIMIT 10 ";
                 $db->setQuery($query);
                 $prevComments = $db->loadResultArray();
                 $prevComments = $prevComments == NULL ? '' : implode("\n\n", $prevComments);
                 $example = $baseText . "\n\n\n\n" . $prevComments;
             }
             self::getCleantalk();
             $ctResponse = self::ctSendRequest('check_message', array('example' => $example, 'message' => $comment->comment, 'sender_nickname' => $comment->name, 'sender_email' => $comment->email, 'sender_ip' => self::$CT->ct_session_ip($_SERVER['REMOTE_ADDR']), 'js_on' => $checkjs, 'submit_time' => $submit_time, 'sender_info' => $sender_info, 'post_info' => $post_info));
             if (!empty($ctResponse) && is_array($ctResponse)) {
                 if ($ctResponse['stop_queue'] == 1) {
                     JCommentsAJAX::showErrorMessage($ctResponse['comment'], 'comment');
                     return false;
                 } else {
                     if ($ctResponse['allow'] == 0) {
                         $comment->published = false;
                         // Send notification to administrator
                         if ($config['jcomments_unpublished_nofications'] != '') {
                             JComments::sendNotification($comment, true);
                         }
                     }
                 }
             }
             return true;
         }
         //if(in_array($group, $plugin_groups))
     }
     //foreach
 }
예제 #19
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;
     }
 }
예제 #20
0
 public static function refreshObjectsAjax()
 {
     $app = JFactory::getApplication();
     $hash = $app->input->post->get('hash', '');
     $step = $app->input->post->getInt('step');
     $lang = $app->input->post->get('lang', '');
     $count = 50;
     if ($hash === md5($app->getCfg('secret'))) {
         $db = JFactory::getDBO();
         if ($step == 0) {
             if ($app->getCfg('caching') != 0) {
                 // clean cache for all object groups
                 $db->setQuery('SELECT DISTINCT object_group FROM #__jcomments_objects');
                 $rows = $db->loadColumn();
                 foreach ($rows as $row) {
                     $cache = JFactory::getCache('com_jcomments_objects_' . strtolower($row));
                     $cache->clean();
                 }
             }
             $db->setQuery('TRUNCATE TABLE #__jcomments_objects');
             $db->execute();
         }
         $where = array();
         $where[] = 'IFNULL(c.lang, "") <> ""';
         // count objects without information
         $query = "SELECT COUNT(DISTINCT c.object_id, c.object_group, c.lang)" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "");
         $db->setQuery($query);
         $total = (int) $db->loadResult();
         $count = 0;
         if ($total > 0) {
             $where[] = 'NOT EXISTS (SELECT o.id FROM #__jcomments_objects AS o WHERE o.object_id = c.object_id AND o.object_group = c.object_group AND o.lang = c.lang)';
             // get list of first objects without information
             $query = "SELECT DISTINCT c.object_id, c.object_group, c.lang" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . " ORDER BY c.object_group, c.lang";
             $db->setQuery($query, 0, $count);
             $rows = $db->loadObjectList();
             $i = 0;
             $multilanguage = JCommentsMultilingual::isEnabled();
             $nextLanguage = $lang;
             if (count($rows)) {
                 foreach ($rows as $row) {
                     if ($nextLanguage != $row->lang && $multilanguage) {
                         $nextLanguage = $row->lang;
                         break;
                     }
                     // retrieve and store object information
                     JCommentsObjectHelper::storeObjectInfo($row->object_id, $row->object_group, $row->lang, false, true);
                     $i++;
                 }
             }
             if ($i > 0) {
                 $db->setQuery("SELECT COUNT(*) FROM #__jcomments_objects");
                 $count = (int) $db->loadResult();
             }
             $percent = ceil($count / $total * 100);
             $percent = min($percent, 100);
         } else {
             $percent = 100;
         }
         $step++;
         $lang_codes = JLanguageHelper::getLanguages('lang_code');
         $language_sef = isset($lang_codes[$nextLanguage]) ? $lang_codes[$nextLanguage]->sef : $nextLanguage;
         $data = array('count' => $count, 'total' => $total, 'percent' => $percent, 'step' => $step, 'hash' => $hash, 'object_group' => null, 'lang' => $nextLanguage, 'lang_sef' => $language_sef);
         echo json_encode($data);
     }
     $app->close();
 }
예제 #21
0
파일: object.php 프로젝트: ForAEdesWeb/AEW2
 /**
  * Stores object information (inserts new or updates existing)
  *
  * @param int $object_id
  * @param string $object_group
  * @param string $language 
  * @param boolean $cleanCache
  * @param boolean $allowEmpty
  * @return JCommentsObjectInfo
  */
 public static function storeObjectInfo($object_id, $object_group = 'com_content', $language = null, $cleanCache = false, $allowEmpty = false)
 {
     if (empty($language)) {
         $language = JCommentsMultilingual::getLanguage();
     }
     $app = JFactory::getApplication();
     // try to load object information from database
     $object = JCommentsModelObject::getObjectInfo($object_id, $object_group, $language);
     $objectId = $object === false ? 0 : $object->id;
     if ($objectId == 0 && $app->isAdmin()) {
         // return empty object because we can not create link in backend
         return new JCommentsObjectInfo();
     }
     // get object information via plugins
     $info = self::_loadObjectInfo($object_id, $object_group, $language);
     if (!JCommentsModelObject::IsEmpty($info) || $allowEmpty) {
         if ($app->isAdmin()) {
             // we do not have to update object's link from backend
             $info->link = null;
         }
         // insert/update object information
         JCommentsModelObject::setObjectInfo($objectId, $info);
         if ($cleanCache) {
             // clean cache for given object group
             $cache = JFactory::getCache('com_jcomments_objects_' . strtolower($object_group));
             $cache->clean();
         }
     }
     return $info;
 }
예제 #22
0
 public static function RefreshObjects($hash, $step = 0, $object_group = '', $lang = '')
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $response = JCommentsFactory::getAjaxResponse();
     $app = JCommentsFactory::getApplication();
     $count = 50;
     if ($hash === md5($app->getCfg('secret'))) {
         $db = JCommentsFactory::getDBO();
         if ($step == 0) {
             $db->setQuery('DELETE FROM #__jcomments_objects WHERE 1=1');
             $db->query();
         }
         $where = array();
         $where[] = 'IFNULL(c.lang, "") <> ""';
         if (!empty($object_group)) {
             $where[] = 'c.object_group = ' . $db->Quote($object_group);
         }
         // count objects without information
         $query = "SELECT COUNT(DISTINCT c.object_id, c.object_group, c.lang)" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "");
         $db->setQuery($query);
         $objectsCount = (int) $db->loadResult();
         $where[] = 'NOT EXISTS (SELECT o.id FROM #__jcomments_objects AS o WHERE o.object_id = c.object_id AND o.object_group = c.object_group AND o.lang = c.lang)';
         // get list of first objects without information
         $query = "SELECT DISTINCT c.object_id, c.object_group, c.lang" . " FROM #__jcomments AS c" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . " ORDER BY c.object_group, c.lang";
         $db->setQuery($query, 0, $count);
         $rows = $db->loadObjectList();
         $i = 0;
         $multilanguage = JCommentsMultilingual::isEnabled();
         $nextLanguage = $lang;
         if (count($rows)) {
             foreach ($rows as $row) {
                 if ($nextLanguage != $row->lang && $multilanguage) {
                     $nextLanguage = $row->lang;
                     break;
                 }
                 // retrieve and store object information
                 JCommentsObjectHelper::storeObjectInfo($row->object_id, $row->object_group, $row->lang, false, true);
                 $i++;
             }
         }
         $objectsRefreshed = 0;
         if ($i > 0) {
             $db->setQuery("SELECT COUNT(*) FROM #__jcomments_objects");
             $objectsRefreshed = (int) $db->loadResult();
             $response->addScript("JCommentsRefreshObjectsProgress({$objectsRefreshed}, {$objectsCount});");
         }
         if ($objectsCount > $objectsRefreshed && ($i > 0 || $lang != $nextLanguage)) {
             // we need continue refresh
             $step++;
             $response->addScript("JCommentsRefreshObjectsAJAX('{$hash}', '{$step}', '', '{$nextLanguage}');");
         } else {
             $response->addScript("JCommentsRefreshObjectsProgress({$objectsCount}, {$objectsCount});");
             if ($app->getCfg('caching')) {
                 // clean cache for all object groups
                 $db->setQuery('SELECT DISTINCT object_group FROM #__jcomments_objects');
                 $rows = $db->loadResultArray();
                 foreach ($rows as $row) {
                     $cache = JCommentsFactory::getCache('com_jcomments_objects_' . strtolower($row));
                     $cache->clean();
                 }
             }
         }
     }
     return $response;
 }
예제 #23
0
 function getCommentsTree($object_id, $object_group = 'com_content', $search_text = '')
 {
     global $my;
     $object_id = (int) $object_id;
     $object_group = trim($object_group);
     $acl =& JCommentsFactory::getACL();
     $dbo =& JCommentsFactory::getDBO();
     $config =& JCommentsFactory::getConfig();
     $canPublish = $acl->canPublish();
     $canComment = $acl->canComment();
     $where = '';
     if ($search_text) {
         $words = explode(' ', $search_text);
         $wheres = array();
         foreach ($words as $word) {
             $wheres2 = array();
             $wheres2[] = "LOWER(name) LIKE '%{$word}%'";
             $wheres2[] = "LOWER(comment) LIKE '%{$word}%'";
         }
         if (isset($wheres2) && count($wheres2)) {
             $where .= ' AND (';
             $where .= implode(' OR ', $wheres2);
             $where .= ' )';
         }
     }
     if ($canComment == 0) {
         $total = JLMS_JComments::getCommentsCount($object_id, $object_group, $where);
         if ($total == 0) {
             return '';
         }
     }
     $query = "SELECT c.id, c.parent, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment" . "\n , c.email, c.homepage, c.date as datetime, c.ip, c.published, c.checked_out, c.checked_out_time" . "\n , c.isgood, c.ispoor" . "\n , v.value as voted" . "\n FROM #__jcomments AS c" . "\n LEFT JOIN #__jcomments_votes AS v ON c.id = v.commentid " . ($my->id ? " AND  v.userid = " . $my->id : " AND  v.ip = '" . $acl->getUserIP() . "'") . "\n WHERE c.object_id = " . $object_id . "\n AND c.object_group = '" . $object_group . "'" . (JCommentsMultilingual::isEnabled() ? "\nAND c.lang = '" . JCommentsMultilingual::getLanguage() . "'" : "") . ($canPublish == 0 ? "\nAND c.published = 1" : "") . $where . "\n ORDER BY c.parent, c.date ASC";
     $dbo->setQuery($query);
     $rows = $dbo->loadObjectList();
     $tmpl =& JCommentsFactory::getTemplate($object_id, $object_group);
     $tmpl->load('tpl_tree');
     $tmpl->load('tpl_comment');
     if (count($rows)) {
         $isLocked = $config->getInt('object_locked', 0) == 1;
         $tmpl->addVar('tpl_tree', 'comments-refresh', intval(!$isLocked));
         $tmpl->addVar('tpl_tree', 'comments-rss', intval($config->getInt('enable_rss') && !$isLocked));
         $tmpl->addVar('tpl_tree', 'comments-can-subscribe', intval($my->id && $acl->check('enable_subscribe') && !$isLocked));
         if ($my->id && $acl->check('enable_subscribe')) {
             require_once JCOMMENTS_BASE . DS . 'jcomments.subscription.php';
             $manager =& JCommentsSubscriptionManager::getInstance();
             $isSubscribed = $manager->isSubscribed($object_id, $object_group, $my->id);
             $tmpl->addVar('tpl_tree', 'comments-user-subscribed', $isSubscribed);
         }
         $i = 1;
         if ($config->getInt('enable_mambots') == 1) {
             require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
             JCommentsPluginHelper::importPlugin('jcomments');
             JCommentsPluginHelper::trigger('onBeforeDisplayCommentsList', array(&$rows));
             if ($acl->check('enable_gravatar')) {
                 JCommentsPluginHelper::trigger('onPrepareAvatars', array(&$rows));
             }
         }
         require_once JCOMMENTS_LIBRARIES . DS . 'joomlatune' . DS . 'tree.php';
         $tree = new JoomlaTuneTree($rows);
         $items = $tree->get();
         foreach ($rows as $row) {
             if ($config->getInt('enable_mambots') == 1) {
                 JCommentsPluginHelper::trigger('onBeforeDisplayComment', array(&$row));
             }
             // run autocensor, replace quotes, smiles and other pre-view processing
             JComments::prepareComment($row);
             // setup toolbar
             if (!$acl->canModerate($row)) {
                 $tmpl->addVar('tpl_comment', 'comments-panel-visible', 0);
             } else {
                 $tmpl->addVar('tpl_comment', 'comments-panel-visible', 1);
                 $tmpl->addVar('tpl_comment', 'button-edit', $acl->canEdit($row));
                 $tmpl->addVar('tpl_comment', 'button-delete', $acl->canDelete($row));
                 $tmpl->addVar('tpl_comment', 'button-publish', $acl->canPublish($row));
                 $tmpl->addVar('tpl_comment', 'button-ip', $acl->canViewIP($row));
             }
             $tmpl->addVar('tpl_comment', 'comment-show-vote', $config->getInt('enable_voting'));
             $tmpl->addVar('tpl_comment', 'comment-show-email', $acl->canViewEmail($row));
             $tmpl->addVar('tpl_comment', 'comment-show-homepage', $acl->canViewHomepage($row));
             $tmpl->addVar('tpl_comment', 'comment-show-title', $config->getInt('comment_title'));
             $tmpl->addVar('tpl_comment', 'button-vote', $acl->canVote($row));
             $tmpl->addVar('tpl_comment', 'button-quote', $acl->canQuote($row));
             $tmpl->addVar('tpl_comment', 'button-reply', $acl->canReply($row));
             $tmpl->addVar('tpl_comment', 'avatar', $acl->check('enable_gravatar'));
             if (isset($items[$row->id])) {
                 $tmpl->addVar('tpl_comment', 'comment-number', '');
                 $tmpl->addObject('tpl_comment', 'comment', $row);
                 $items[$row->id]->html = $tmpl->renderTemplate('tpl_comment');
                 $i++;
             }
         }
         $tmpl->addObject('tpl_tree', 'comments-items', $items);
         unset($rows);
     }
     return $tmpl->renderTemplate('tpl_tree');
 }
예제 #24
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;
     }
 }
예제 #25
0
 protected static function _getCommentsQuery(&$options)
 {
     $acl = JCommentsFactory::getACL();
     $db = JFactory::getDbo();
     $object_id = @$options['object_id'];
     $object_group = @$options['object_group'];
     $parent = @$options['parent'];
     $level = @$options['level'];
     $published = @$options['published'];
     $userid = @$options['userid'];
     $filter = @$options['filter'];
     $orderBy = @$options['orderBy'];
     $limitStart = isset($options['limitStart']) ? $options['limitStart'] : 0;
     $limit = @$options['limit'];
     $votes = isset($options['votes']) ? $options['votes'] : true;
     $objectinfo = isset($options['objectinfo']) ? $options['objectinfo'] : false;
     $where = array();
     if (!empty($object_id)) {
         $where[] = "c.object_id = " . $object_id;
     }
     if (!empty($object_group)) {
         if (is_array($object_group)) {
             $where[] = "(c.object_group = '" . implode("' OR c.object_group = '", $object_group) . "')";
         } else {
             $where[] = "c.object_group = " . $db->Quote($object_group);
         }
     }
     if ($parent !== null) {
         $where[] = "c.parent = " . $parent;
     }
     if ($level !== null) {
         $where[] = "c.level = " . (int) $level;
     }
     if ($published !== null) {
         $where[] = "c.published = " . $published;
     }
     if ($userid !== null) {
         $where[] = "c.userid = " . $userid;
     }
     if (JCommentsMultilingual::isEnabled()) {
         $language = isset($options['lang']) ? $options['lang'] : JCommentsMultilingual::getLanguage();
         $where[] = "c.lang = " . $db->Quote($language);
     }
     if ($objectinfo && isset($options['access'])) {
         if (is_array($options['access'])) {
             $access = implode(',', $options['access']);
             $where[] = "jo.access IN (" . $access . ")";
         } else {
             $where[] = "jo.access <= " . (int) $options['access'];
         }
     }
     if ($filter != "") {
         $where[] = $filter;
     }
     $query = "SELECT c.id, c.parent, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment" . "\n, c.email, c.homepage, c.date, c.date as datetime, c.ip, c.published, c.deleted, c.checked_out, c.checked_out_time" . "\n, c.isgood, c.ispoor" . ($votes ? "\n, v.value as voted" : "\n, 1 as voted") . "\n, case when c.parent = 0 then unix_timestamp(c.date) else 0 end as threaddate" . ($objectinfo ? "\n, jo.title AS object_title, jo.link AS object_link, jo.access AS object_access" : ", '' AS object_title, '' AS object_link, 0 AS object_access, 0 AS object_owner") . "\nFROM #__jcomments AS c" . ($votes ? "\nLEFT JOIN #__jcomments_votes AS v ON c.id = v.commentid " . ($acl->getUserId() ? " AND  v.userid = " . $acl->getUserId() : " AND v.userid = 0 AND v.ip = '" . $acl->getUserIP() . "'") : "") . ($objectinfo ? "\n LEFT JOIN #__jcomments_objects AS jo ON jo.object_id = c.object_id AND jo.object_group = c.object_group AND jo.lang=c.lang" : "") . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . "\nORDER BY " . $orderBy . ($limit > 0 ? "\nLIMIT {$limitStart}, {$limit}" : "");
     return $query;
 }
예제 #26
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;
     }
 }
예제 #27
0
 /**
  * Comments Search method
  *
  * @param string $text Target search string
  * @param string $phrase mathcing option, exact|any|all
  * @param string $ordering ordering option, newest|oldest|popular|alpha|category
  * @param mixed $areas An array if the search it to be restricted to areas, null if search all
  * @return array
  */
 function onContentSearch($text, $phrase = '', $ordering = '', $areas = null)
 {
     $text = JString::strtolower(trim($text));
     $result = array();
     if ($text == '' || !defined('JCOMMENTS_JVERSION')) {
         return $result;
     }
     if (is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return $result;
         }
     }
     if (file_exists(JCOMMENTS_BASE . '/jcomments.php')) {
         require_once JCOMMENTS_BASE . '/jcomments.php';
         $db = JFactory::getDBO();
         $limit = $this->params->def('search_limit', 50);
         switch ($phrase) {
             case 'exact':
                 $text = $db->Quote('%' . $db->getEscaped($text, true) . '%', false);
                 $wheres2[] = "LOWER(c.name) LIKE " . $text;
                 $wheres2[] = "LOWER(c.comment) LIKE " . $text;
                 $wheres2[] = "LOWER(c.title) LIKE " . $text;
                 $where = '(' . implode(') OR (', $wheres2) . ')';
                 break;
             case 'all':
             case 'any':
             default:
                 $words = explode(' ', $text);
                 $wheres = array();
                 foreach ($words as $word) {
                     $word = $db->Quote('%' . $db->getEscaped($word, true) . '%', false);
                     $wheres2 = array();
                     $wheres2[] = "LOWER(c.name) LIKE " . $word;
                     $wheres2[] = "LOWER(c.comment) LIKE " . $word;
                     $wheres2[] = "LOWER(c.title) LIKE " . $word;
                     $wheres[] = implode(' OR ', $wheres2);
                 }
                 $where = '(' . implode($phrase == 'all' ? ') AND (' : ') OR (', $wheres) . ')';
                 break;
         }
         switch ($ordering) {
             case 'oldest':
                 $order = 'date ASC';
                 break;
             case 'newest':
             default:
                 $order = 'date DESC';
                 break;
         }
         $acl = JCommentsFactory::getACL();
         $access = $acl->getUserAccess();
         if (is_array($access)) {
             $accessCondition = "AND jo.access IN (" . implode(',', $access) . ")";
         } else {
             $accessCondition = "AND jo.access <= " . (int) $access;
         }
         $query = "SELECT " . "  c.comment AS text" . ", c.date AS created" . ", '2' AS browsernav" . ", '" . JText::_('PLG_SEARCH_JCOMMENTS_COMMENTS') . "' AS section" . ", ''  AS href" . ", c.id" . ", jo.title AS object_title, jo.link AS object_link" . " FROM #__jcomments AS c" . " INNER JOIN #__jcomments_objects AS jo ON jo.object_id = c.object_id AND jo.object_group = c.object_group and jo.lang=c.lang" . " WHERE c.published=1" . " AND c.deleted=0" . " AND jo.link <> ''" . (JCommentsMultilingual::isEnabled() ? " AND c.lang = '" . JCommentsMultilingual::getLanguage() . "'" : "") . " AND ({$where}) " . $accessCondition . " ORDER BY c.object_id, {$order}";
         $db->setQuery($query, 0, $limit);
         $rows = $db->loadObjectList();
         $cnt = count($rows);
         if ($cnt > 0) {
             $config = JCommentsFactory::getConfig();
             $enableCensor = $acl->check('enable_autocensor');
             $word_maxlength = $config->getInt('word_maxlength');
             for ($i = 0; $i < $cnt; $i++) {
                 $text = JCommentsText::cleanText($rows[$i]->text);
                 if ($enableCensor) {
                     $text = JCommentsText::censor($text);
                 }
                 if ($word_maxlength > 0) {
                     $text = JCommentsText::fixLongWords($text, $word_maxlength);
                 }
                 if ($text != '') {
                     $rows[$i]->title = $rows[$i]->object_title;
                     $rows[$i]->text = $text;
                     $rows[$i]->href = $rows[$i]->object_link . '#comment-' . $rows[$i]->id;
                     $result[] = $rows[$i];
                 }
             }
         }
         unset($rows);
     }
     return $result;
 }
예제 #28
0
 function _getCommentsQuery(&$options)
 {
     $acl =& JCommentsFactory::getACL();
     $db =& JCommentsFactory::getDBO();
     $object_id = @$options['object_id'];
     $object_group = @$options['object_group'];
     $parent = @$options['parent'];
     $published = @$options['published'];
     $orderBy = @$options['orderBy'];
     $limitStart = @$options['limitStart'];
     $limit = @$options['limit'];
     $where = array();
     if ($object_id) {
         $where[] = "c.object_id = " . $object_id;
     }
     if ($object_group != '') {
         $where[] = "c.object_group = '" . $db->getEscaped($object_group) . "'";
     }
     if ($parent !== null) {
         $where[] = "c.parent = " . $parent;
     }
     if ($published !== null) {
         $where[] = "c.published = " . $published;
     }
     if (JCommentsMultilingual::isEnabled()) {
         $where[] = "c.lang = '" . JCommentsMultilingual::getLanguage() . "'";
     }
     $query = "SELECT c.id, c.parent, c.object_id, c.object_group, c.userid, c.name, c.username, c.title, c.comment" . "\n, c.email, c.homepage, c.date as datetime, c.ip, c.published, c.checked_out, c.checked_out_time" . "\n, c.isgood, c.ispoor" . "\n, v.value as voted" . "\n, case when c.userid = 0 then 'guest' else replace(lower(u.usertype), ' ', '-') end as usertype" . "\nFROM #__jcomments AS c" . "\nLEFT JOIN #__jcomments_votes AS v ON c.id = v.commentid " . ($acl->getUserId() ? " AND  v.userid = " . $acl->getUserId() : " AND v.userid = 0 AND v.ip = '" . $acl->getUserIP() . "'") . "\nLEFT JOIN #__users AS u ON c.userid = u.id" . (count($where) ? "\nWHERE " . implode(' AND ', $where) : "") . "\nORDER BY " . $orderBy . ($limit > 0 ? "\nLIMIT {$limitStart}, {$limit}" : "");
     return $query;
 }
예제 #29
0
    public static function showImport($CommentSystems = array())
    {
        $app = JCommentsFactory::getApplication('administrator');
        $db = JCommentsFactory::getDBO();
        $db->setQuery("SHOW TABLES");
        $tables = $db->loadResultArray();
        foreach ($tables as $tableName) {
            for ($i = 0, $n = count($CommentSystems); $i < $n; $i++) {
                $tableMask = str_replace('#__', $app->getCfg('dbprefix'), $CommentSystems[$i]->table);
                if (preg_match('/' . $tableMask . '$/i', $tableName)) {
                    $CommentSystems[$i]->found = true;
                    $CommentSystems[$i]->UpdateCount();
                }
            }
        }
        $languages = JCommentsMultilingual::getLanguages();
        if (JCOMMENTS_JVERSION == '1.0') {
            $lang = JCommentsMultilingual::getLanguage();
        } else {
            $params = JComponentHelper::getParams('com_languages');
            $lang = $params->get("site", 'en-GB');
        }
        $ajaxUrl = JCommentsFactory::getLink('ajax-backend');
        ?>
<link rel="stylesheet" href="<?php 
        echo $app->getCfg('live_site');
        ?>
/administrator/components/com_jcomments/assets/style.css" type="text/css" />
<script type="text/javascript" src="<?php 
        echo $app->getCfg('live_site');
        ?>
/components/com_jcomments/libraries/joomlatune/ajax.js?v=2"></script>
<script type="text/javascript" src="<?php 
        echo $app->getCfg('live_site');
        ?>
/administrator/components/com_jcomments/assets/jcomments-backend-v2.1.js"></script>
<script type="text/javascript">
<!--
function JCommentsImportCommentsAJAX(source, language, start)
{
	try {
		jtajax.setup({url:'<?php 
        echo $ajaxUrl;
        ?>
'});
		return jtajax.call('JCommentsImportCommentsAjax', arguments, 'post');
	} catch (e) {
		return false;
	}
}

function startCommentsImport(source)
{
	var language = '';
	var e=document.getElementById(source.toLowerCase() + '_lang');
	if (e){for (var i=0;i<e.length;i++) {if (e.options[i].selected){language=e.options[i].value;break;}}}
	var b = document.getElementById('btnImport' + source);
	if (b) {b.disabled = true;}
	JCommentsImportCommentsAJAX(source, language, 0);
}

function finishCommentsImport(source) {
	var b=document.getElementById('btnImport'+source);if(b){b.disabled=false;}
}

<?php 
        if (JCOMMENTS_JVERSION == '1.7') {
            ?>
Joomla.submitbutton = function (task) {
	Joomla.submitform(task, document.getElementById('adminForm'));
};
<?php 
        } else {
            ?>
function submitbutton(task)
{
	submitform(task);
}
<?php 
        }
        ?>
//-->
</script>
<script type="text/javascript">
<!--
var jc_comments = new Array(
<?php 
        $jsArray = array();
        foreach ($CommentSystems as $CommentSystem) {
            if ($CommentSystem->found) {
                $jsArray[] = $CommentSystem->code;
            }
        }
        echo "'" . implode("', '", $jsArray) . "'";
        ?>
			);

function importMode( mode ) {
	if(document.getElementById) {
		for(var i=0;i<jc_comments.length;i++) {
			if (mode == jc_comments[i]) {
				document.getElementById('import' + jc_comments[i]).checked = true;
				document.getElementById('import' + jc_comments[i]+'Info').style.display = '';
			} else {
				document.getElementById('import' + jc_comments[i]).checked = false;
				document.getElementById('import' + jc_comments[i]+'Info').style.display = 'none';
			}
		}
	}
}
//-->
</script>

<style type="text/css">
#jcomments-message {padding: 0 0 0 25px;margin: 0; width: auto; float: right; font-size: 14px; font-weight: bold;}
.jcomments-message-error {background: transparent url(components/com_jcomments/assets/error.gif) no-repeat 4px 50%; color: red;}
.jcomments-message-info {background: transparent url(components/com_jcomments/assets/info.gif) no-repeat 4px 50%; color: green;}
.jcomments-message-wait {background: transparent url(components/com_jcomments/assets/wait.gif) no-repeat 4px 50%; color: green;}
.adminform fieldset { border: 1px #999 solid; }
.adminform fieldset input, fieldset select { float: none; }
.adminform span.note { color: #777; }
table.componentinfo td { color: #777; padding: 0; }
</style>

<div>
<form action="<?php 
        echo JCOMMENTS_INDEX;
        ?>
" method="post" name="adminForm" id="adminForm">
<input type="hidden" name="option" value="com_jcomments" />
<input type="hidden" name="task" value="" />
<?php 
        if (JCOMMENTS_JVERSION == '1.0') {
            ?>
<table class="adminheading">
<tr>
	<th style="background-image: none; padding: 0;"><img src="components/com_jcomments/assets/icon-48-import.png" width="48" height="48" align="middle" alt="<?php 
            echo JText::_('A_IMPORT');
            ?>
">&nbsp;<?php 
            echo JText::_('A_IMPORT');
            ?>
</th>
</tr>
</table>
<?php 
        }
        ?>

<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr valign="top">
		<td align="right">&nbsp;</td>
		<td width="50%" align="right"><div id="jcomments-message-holder"></div></td>
	</tr>
</table>

<table width="100%" border="0" cellpadding="4" cellspacing="2" class="adminform">
<tr>
	<td>
		<fieldset>
		<legend><?php 
        echo JText::_('A_IMPORT_SELECT_SOURCE');
        ?>
</legend>
		<table cellpadding="1" cellspacing="1" border="0">
<?php 
        $foundSources = 0;
        foreach ($CommentSystems as $CommentSystem) {
            if ($CommentSystem->found) {
                $foundSources++;
                ?>
		<tr valign="top" align="left">
			<td><input type="radio" id="import<?php 
                echo $CommentSystem->code;
                ?>
" name="vars[import]" value="<?php 
                echo $CommentSystem->code;
                ?>
" onclick="importMode('<?php 
                echo $CommentSystem->code;
                ?>
')" <?php 
                echo $CommentSystem->found ? '' : 'disabled';
                ?>
 /></td>
			<td><label for="import<?php 
                echo $CommentSystem->code;
                ?>
"><?php 
                echo $CommentSystem->name;
                ?>
</label></td>
			<td><div id="jcomments-message-<?php 
                echo strtolower($CommentSystem->code);
                ?>
"></div></td>
		</tr>
		<tr id="import<?php 
                echo $CommentSystem->code;
                ?>
Info" style="display: none;">
			<td>&nbsp;</td>
			<td>
				<table cellpadding="0" cellspacing="0" border="0" class="componentinfo">
				<tr>
					<td width="150px"><?php 
                echo JText::_('A_IMPORT_COMPONENT_AUTHOR');
                ?>
</td>
					<td><?php 
                echo $CommentSystem->author;
                ?>
</td>
				</tr>
				<tr>
					<td><?php 
                echo JText::_('A_IMPORT_COMPONENT_HOMEPAGE');
                ?>
</td>
					<td><a href="<?php 
                echo $CommentSystem->homepage;
                ?>
" target="_blank"><?php 
                echo str_replace('http://', '', $CommentSystem->homepage);
                ?>
</a></td>
				</tr>
				<tr>
					<td><?php 
                echo JText::_('A_IMPORT_COMPONENT_LICENSE');
                ?>
</td>
					<td>
<?php 
                if ($CommentSystem->license_url != '') {
                    ?>
						<a href="<?php 
                    echo $CommentSystem->license_url;
                    ?>
" target="_blank"><?php 
                    echo $CommentSystem->license;
                    ?>
</a>
<?php 
                } else {
                    ?>
					
						<?php 
                    echo $CommentSystem->license;
                }
                ?>
					</td>
				</tr>
				<tr>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr valign="top" align="left">
					<td>
						<?php 
                echo JText::_('A_IMPORT_COMPONENT_COMMENTS_COUNT');
                ?>
					</td>
					<td>
						<label for="import<?php 
                echo $CommentSystem->code;
                ?>
"><?php 
                echo $CommentSystem->count;
                ?>
</label>
					</td>
				</tr>

				<tr valign="top" align="left">
					<td>
					</td>
					<td>
<?php 
                if (count($languages)) {
                    echo JCommentsHTML::selectList($languages, strtolower($CommentSystem->code) . '_lang', 'class="inputbox" size="1"', 'value', 'name', $lang) . '&nbsp;';
                }
                ?>
						<input type="button" id="btnImport<?php 
                echo $CommentSystem->code;
                ?>
" name="btnImport<?php 
                echo $CommentSystem->code;
                ?>
" value="<?php 
                echo JText::_('A_IMPORT_BUTTON_IMPORT');
                ?>
" onclick="startCommentsImport('<?php 
                echo $CommentSystem->code;
                ?>
')" <?php 
                echo $CommentSystem->count ? '' : 'disabled';
                ?>
 />
					</td>
				</tr>

				<tr>
					<td colspan="2">&nbsp;</td>
				</tr>
				</table>
			</td>
		</tr>
<?php 
            }
        }
        if ($foundSources == 0) {
            ?>
		<tr>
			<td><?php 
            echo JText::_('A_IMPORT_NO_SOURCES');
            ?>
</td>
		</tr>
<?php 
        }
        ?>
		</table>
	</fieldset>
	</td>
</tr>
</table>
<?php 
        echo JCommentsSecurity::formToken();
        ?>
</form>
</div>
<?php 
    }
 public static function postInstall()
 {
     $app = JCommentsFactory::getApplication('administrator');
     $db = JCommentsFactory::getDBO();
     $installer = new HTML_JCommentsInstaller();
     JCommentsInstallerHelper::extractJCommentsPlugins();
     // create database tables
     if (JCOMMENTS_JVERSION == '1.0') {
         $sql = dirname(__FILE__) . DS . 'install' . DS . 'sql' . DS . 'install.mysql.nonutf8.sql';
         JCommentsInstaller::executeSQL($sql);
         // collation synchronization (for MySQL 4.1.2 or higher)
         if (version_compare(preg_replace('~\\-.+?$~', '', $db->getVersion()), '4.1.2') >= 0) {
             JCommentsInstallerDatabaseHelper::setupCollation();
         }
     } else {
         $config = JFactory::getConfig();
         $app = JFactory::getApplication();
         @ob_start();
         if ($config->getValue('config.legacy')) {
             $installSQL = dirname(__FILE__) . DS . 'install' . DS . 'sql' . DS . 'install.mysql.utf8.sql';
             JCommentsInstaller::executeSQL($installSQL);
         }
         jimport('joomla.filesystem.folder');
         jimport('joomla.filesystem.file');
         $jomSocialRuleSrc = dirname(__FILE__) . DS . 'install' . DS . 'xml' . DS . 'jomsocial_rule.xm';
         $jomSocialRuleDst = JCOMMENTS_BASE . DS . 'jomsocial_rule.xml';
         if (!is_file($jomSocialRuleDst)) {
             JFile::copy($jomSocialRuleSrc, $jomSocialRuleDst);
         }
         if (is_dir(JCOMMENTS_BASE . DS . 'languages')) {
             JFolder::delete(JCOMMENTS_BASE . DS . 'languages');
         }
         if (is_file(JCOMMENTS_BASE . DS . 'plugins' . DS . 'plugins.zip')) {
             JFile::delete(JCOMMENTS_BASE . DS . 'plugins' . DS . 'plugins.zip');
         }
         @ob_end_clean();
         $app->setUserState('com_installer.message', '');
         $app->setUserState('com_installer.extension_message', '');
         $app->setUserState('com_installer.redirect_url', '');
     }
     $jxml10 = dirname(__FILE__) . DS . 'jcomments10.xml';
     $jxml15 = dirname(__FILE__) . DS . 'jcomments15.xml';
     $jxml = dirname(__FILE__) . DS . 'jcomments.xml';
     if (is_file($jxml10)) {
         @rename($jxml10, $jxml);
     } else {
         if (is_file($jxml15)) {
             @rename($jxml15, $jxml);
             // fix version in xml manifest file
             if (JCOMMENTS_JVERSION == '1.7') {
                 $contents = str_replace('1.5.0', '1.7.0', implode('', file($jxml)));
                 $fh = fopen($jxml, 'w');
                 if ($fh) {
                     fputs($fh, $contents);
                     fclose($fh);
                 }
             }
         }
     }
     unset($jxml10, $jxml15, $jxml);
     if (JCOMMENTS_JVERSION != '1.7') {
         // remove files from previous version
         $files = array(dirname(__FILE__) . DS . 'admin.jcomments.subcription.php', dirname(__FILE__) . DS . 'table' . DS . 'custombbcodes.php', JCOMMENTS_BASE . DS . 'model' . DS . 'index.html', JCOMMENTS_BASE . DS . 'model' . DS . 'jcomments.php', JCOMMENTS_BASE . DS . 'model');
         foreach ($files as $file) {
             if (is_file($file)) {
                 @unlink($file);
             } else {
                 if (is_dir($file)) {
                     @rmdir($file);
                 }
             }
         }
     }
     // small stuff for future update system
     $db->setQuery('SELECT `version` FROM `#__jcomments_version`');
     $version = $db->loadResult();
     require_once dirname(__FILE__) . DS . 'version.php';
     $jcommentsVersion = new JCommentsVersion();
     $currentVersion = $jcommentsVersion->getVersion();
     $currentDate = date('Y-m-d H:i:s');
     if (empty($version)) {
         $db->setQuery("INSERT IGNORE INTO `#__jcomments_version` (`version`,`installed`) VALUES ('{$currentVersion}', '{$currentDate}')");
         @$db->query();
         // if version isn't specified - we think that it was 2.2.0.0 or earlier...
         $version = '2.2.0.0';
     } else {
         $db->setQuery("UPDATE `#__jcomments_version` SET `version` = '{$currentVersion}', `updated` = '{$currentDate}';");
         @$db->query();
     }
     // install content plugin
     $result = JCommentsInstallerHelper::installPlugin('Content - JComments', 'jcomments', 'content');
     $installer->addMessage(JText::_('A_INSTALL_PLUGIN_CONTENT'), $result);
     // install search plugin
     $result = JCommentsInstallerHelper::installPlugin('Search - JComments', 'jcomments', 'search');
     $installer->addMessage(JText::_('A_INSTALL_PLUGIN_SEARCH'), $result);
     // install system plugin
     $result = JCommentsInstallerHelper::installPlugin('System - JComments', 'jcomments', 'system');
     $installer->addMessage(JText::_('A_INSTALL_PLUGIN_SYSTEM'), $result);
     // install editor buttons
     $result = JCommentsInstallerHelper::installPlugin('Editor Button - JComments ON', 'jcommentson', 'editors-xtd', array('jcommentson.gif'));
     $result = $result && JCommentsInstallerHelper::installPlugin('Editor Button - JComments OFF', 'jcommentsoff', 'editors-xtd', array('jcommentsoff.gif'));
     $installer->addMessage(JText::_('A_INSTALL_PLUGIN_EDITORS_XTD'), $result);
     if (JCOMMENTS_JVERSION != '1.0') {
         // install user plugin
         $result = JCommentsInstallerHelper::installPlugin('User - JComments', 'jcomments', 'user');
         $installer->addMessage(JText::_('A_INSTALL_PLUGIN_USER'), $result);
     }
     // Fix component menu icon
     if (JCOMMENTS_JVERSION == '1.0') {
         $menuiconpath = $app->getCfg('absolute_path') . DS . 'includes' . DS . 'js' . DS . 'ThemeOffice';
         $adminIconsPath = '../administrator/components/com_jcomments/assets';
         if (is_writable($menuiconpath)) {
             $currentIconsPath = dirname(__FILE__) . DS . 'images';
             ob_start();
             $res1 = @copy($currentIconsPath . DS . 'icon-16-jcomments.png', $menuiconpath . DS . 'icon-16-jcomments.png');
             $res2 = @copy($currentIconsPath . DS . 'icon-16-import.png', $menuiconpath . DS . 'icon-16-import.png');
             $res3 = @copy($currentIconsPath . DS . 'icon-16-settings.png', $menuiconpath . DS . 'icon-16-settings.png');
             $res4 = @copy($currentIconsPath . DS . 'icon-16-smiles.png', $menuiconpath . DS . 'icon-16-smiles.png');
             $res5 = @copy($currentIconsPath . DS . 'icon-16-comments.png', $menuiconpath . DS . 'icon-16-comments.png');
             $res6 = @copy($currentIconsPath . DS . 'icon-16-subscriptions.png', $menuiconpath . DS . 'icon-16-subscriptions.png');
             $res7 = @copy($currentIconsPath . DS . 'icon-16-custombbcodes.png', $menuiconpath . DS . 'icon-16-custombbcodes.png');
             $res8 = @copy($currentIconsPath . DS . 'icon-16-blacklist.png', $menuiconpath . DS . 'icon-16-blacklist.png');
             ob_end_clean();
             $result = $res1 && $res2 && $res3 && $res4 && $res5 && $res6 && $res7 && $res8;
             if ($result && is_file($menuiconpath . DS . 'jcomments16x16.png')) {
                 $adminIconsPath = 'js/ThemeOffice';
             }
         }
         $db->setQuery("UPDATE #__components SET admin_menu_img='{$adminIconsPath}/icon-16-jcomments.png' " . "\n WHERE admin_menu_link='option=com_jcomments'");
         @$db->query();
         $db->setQuery("UPDATE #__components SET admin_menu_img='{$adminIconsPath}/icon-16-comments.png', name='" . JText::_('A_SUBMENU_COMMENTS') . "'" . "\n WHERE admin_menu_link='option=com_jcomments&task=comments'");
         @$db->query();
         $db->setQuery("UPDATE #__components SET admin_menu_img='{$adminIconsPath}/icon-16-settings.png', name='" . JText::_('A_SUBMENU_SETTINGS') . "'" . "\n WHERE admin_menu_link='option=com_jcomments&task=settings'");
         @$db->query();
         $db->setQuery("UPDATE #__components SET admin_menu_img='{$adminIconsPath}/icon-16-smiles.png', name='" . JText::_('A_SUBMENU_SMILES') . "'" . "\n WHERE admin_menu_link='option=com_jcomments&task=smiles'");
         @$db->query();
         $db->setQuery("UPDATE #__components SET admin_menu_img='{$adminIconsPath}/icon-16-subscriptions.png', name='" . JText::_('A_SUBMENU_SUBSCRIPTIONS') . "'" . "\n WHERE admin_menu_link='option=com_jcomments&task=subscriptions'");
         @$db->query();
         $db->setQuery("UPDATE #__components SET admin_menu_img='{$adminIconsPath}/icon-16-custombbcodes.png', name='" . JText::_('A_SUBMENU_CUSTOM_BBCODE') . "'" . "\n WHERE admin_menu_link='option=com_jcomments&task=custombbcodes'");
         @$db->query();
         $db->setQuery("UPDATE #__components SET admin_menu_img='{$adminIconsPath}/icon-16-blacklist.png', name='" . JText::_('A_SUBMENU_BLACKLIST') . "'" . "\n WHERE admin_menu_link='option=com_jcomments&task=blacklist'");
         @$db->query();
         $db->setQuery("UPDATE #__components SET admin_menu_img='{$adminIconsPath}/icon-16-import.png', name='" . JText::_('A_SUBMENU_IMPORT') . "'" . "\n WHERE admin_menu_link='option=com_jcomments&task=import'");
         @$db->query();
         $db->setQuery("UPDATE #__components SET admin_menu_img='{$adminIconsPath}/icon-16-jcomments.png', name='" . JText::_('A_SUBMENU_ABOUT') . "'" . "\n WHERE admin_menu_link='option=com_jcomments&task=about'");
         @$db->query();
     }
     if (version_compare($version, '2.3.0', 'le')) {
         // update db tables
         if (JCommentsInstallerDatabaseHelper::upgradeStructure()) {
             $installer->addMessage(JText::_('A_INSTALL_UPGRADE_TABLES'), true);
         }
         JCommentsInstallerDatabaseHelper::updateJoomGallery();
         if (JCOMMENTS_JVERSION != '1.7') {
             $db->setQuery("UPDATE `#__jcomments_settings` SET `value` = REPLACE(`value`, 'Unregistered', 'Public') ");
             $db->query();
             $db->setQuery("UPDATE `#__jcomments_settings` SET `value` = REPLACE(`value`, 'Super Administrator', 'Super Users') ");
             $db->query();
             $db->setQuery("UPDATE `#__jcomments_custom_bbcodes` SET `button_acl` = REPLACE(`button_acl`, 'Unregistered', 'Public') ");
             $db->query();
             $db->setQuery("UPDATE `#__jcomments_custom_bbcodes` SET `button_acl` = REPLACE(`button_acl`, 'Super Administrator', 'Super Users') ");
             $db->query();
         }
     }
     if (isset($_COOKIE['jcommentsadmin_group'])) {
         if (!headers_sent()) {
             setcookie('jcommentsadmin_group', '', time() - 3600, '/');
         }
         unset($_COOKIE['jcommentsadmin_group']);
     }
     $db->setQuery("SELECT `name`, `value` FROM `#__jcomments_settings`");
     $paramsList = $db->loadObjectList('name');
     if (count($paramsList) == 0) {
         $defaultSettings = dirname(__FILE__) . DS . 'install' . DS . 'sql' . DS . 'settings.sql';
         JCommentsInstaller::executeSQL($defaultSettings);
     } else {
         JCommentsInstaller::checkParam($paramsList, 'delete_mode', '0');
         JCommentsInstaller::checkParam($paramsList, 'can_publish_for_my_object', '');
         JCommentsInstaller::checkParam($paramsList, 'can_edit_for_my_object', '');
         JCommentsInstaller::checkParam($paramsList, 'can_delete_for_my_object', '');
         JCommentsInstaller::checkParam($paramsList, 'enable_blacklist', '0');
         JCommentsInstaller::checkParam($paramsList, 'can_ban', 'Administrator,Super Administrator');
         JCommentsInstaller::checkParam($paramsList, 'feed_limit', '100');
         JCommentsInstaller::checkParam($paramsList, 'report_reason_required', '1');
         if (version_compare($version, '2.2.0.0') <= 0) {
             $smilesPath = DS . 'components' . DS . 'com_jcomments' . DS . 'images' . DS . 'smiles' . DS;
             JCommentsInstaller::checkParam($paramsList, 'smiles_path', $smilesPath, true);
         }
     }
     unset($paramsList);
     if (JCOMMENTS_JVERSION == '1.7') {
         // TODO remove this hack
         JCommentsInstallerHelper::fixComponentName();
     }
     JCommentsInstallerHelper::fixUsergroups();
     $joomfish = $app->getCfg('absolute_path') . DS . 'components' . DS . 'com_joomfish' . DS . 'joomfish.php';
     if (is_file($joomfish) || JCommentsMultilingual::isEnabled()) {
         JCommentsInstaller::upgradeLanguages();
     }
     $db->setQuery("SELECT COUNT(*) FROM `#__jcomments_custom_bbcodes`;");
     $cnt = $db->loadResult();
     if ($cnt == 0) {
         $sql = dirname(__FILE__) . DS . 'install' . DS . 'sql' . DS . 'custom_bbcodes.sql';
         JCommentsInstaller::executeSQL($sql);
     }
     JCommentsInstallerHelper::fixCustomBBCodeACL();
     $installer->showInstallLog();
     $cache = JCommentsFactory::getCache('com_jcomments');
     $cache->clean();
 }