Exemplo n.º 1
0
 public function publish(&$pks, $value = 1)
 {
     $pks = (array) $pks;
     $user = JFactory::getUser();
     $language = JFactory::getLanguage();
     $table = $this->getTable();
     $lastLanguage = '';
     foreach ($pks as $i => $pk) {
         if ($table->load($pk)) {
             if (!$this->canEditState($table)) {
                 unset($pks[$i]);
                 JLog::add(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), JLog::WARNING, 'jerror');
                 return false;
             }
             if ($table->published != $value) {
                 $result = JCommentsEventHelper::trigger('onJCommentsCommentBeforePublish', array(&$table));
                 if (!in_array(false, $result, true)) {
                     if (!$table->publish($pk, $value, $user->get('id'))) {
                         $this->setError($table->getError());
                         return false;
                     }
                     JCommentsEventHelper::trigger('onJCommentsCommentAfterPublish', array(&$table));
                     if ($table->published) {
                         if ($lastLanguage != $table->lang) {
                             $lastLanguage = $table->lang;
                             $language->load('com_jcomments', JPATH_SITE, $table->lang);
                         }
                         JCommentsNotificationHelper::push(array('comment' => $table), 'comment-new');
                     }
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 2
0
 public static function prepareComment(&$comment)
 {
     if (isset($comment->_skip_prepare) && $comment->_skip_prepare == 1) {
         return;
     }
     JCommentsEventHelper::trigger('onJCommentsCommentBeforePrepare', array(&$comment));
     $config = JCommentsFactory::getConfig();
     $acl = JCommentsFactory::getACL();
     // run autocensor
     if ($acl->check('enable_autocensor')) {
         $comment->comment = JCommentsText::censor($comment->comment);
         if ($comment->title != '') {
             $comment->title = JCommentsText::censor($comment->title);
         }
     }
     // replace deleted comment text with predefined message
     if ($comment->deleted == 1) {
         $comment->comment = JText::_('COMMENT_TEXT_COMMENT_HAS_BEEN_DELETED');
         $comment->username = '';
         $comment->name = '';
         $comment->email = '';
         $comment->homepage = '';
         $comment->userid = 0;
         $comment->isgood = 0;
         $comment->ispoor = 0;
     }
     // replace BBCode tags
     $comment->comment = JCommentsFactory::getBBCode()->replace($comment->comment);
     if ($config->getInt('enable_custom_bbcode')) {
         $comment->comment = JCommentsFactory::getCustomBBCode()->replace($comment->comment);
     }
     // fix long words problem
     $word_maxlength = $config->getInt('word_maxlength');
     if ($word_maxlength > 0) {
         $comment->comment = JCommentsText::fixLongWords($comment->comment, $word_maxlength);
         if ($comment->title != '') {
             $comment->title = JCommentsText::fixLongWords($comment->title, $word_maxlength);
         }
     }
     if ($acl->check('emailprotection')) {
         $comment->comment = JComments::maskEmail($comment->id, $comment->comment);
     }
     // autolink urls
     if ($acl->check('autolinkurls')) {
         $comment->comment = preg_replace_callback(_JC_REGEXP_LINK, array('JComments', 'urlProcessor'), $comment->comment);
         if ($acl->check('emailprotection') != 1) {
             $comment->comment = preg_replace(_JC_REGEXP_EMAIL, '<a href="mailto:\\1@\\2">\\1@\\2</a>', $comment->comment);
         }
     }
     // replace smilies' codes with images
     if ($config->get('enable_smilies') == '1') {
         $comment->comment = JCommentsFactory::getSmilies()->replace($comment->comment);
     }
     $comment->author = JComments::getCommentAuthorName($comment);
     // Gravatar support
     $comment->gravatar = md5(strtolower($comment->email));
     if (empty($comment->avatar)) {
         $comment->avatar = '<img src="http://www.gravatar.com/avatar/' . $comment->gravatar . '?d=' . urlencode(JCommentsFactory::getLink('noavatar')) . '" alt="' . htmlspecialchars($comment->author) . '" />';
     }
     JCommentsEventHelper::trigger('onJCommentsCommentAfterPrepare', array(&$comment));
 }
Exemplo n.º 3
0
 public static function BanIP($id)
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $acl = JCommentsFactory::getACL();
     $response = JCommentsFactory::getAjaxResponse();
     if ($acl->canBan()) {
         $config = JCommentsFactory::getConfig();
         if ($config->getInt('enable_blacklist') == 1) {
             $id = (int) $id;
             $comment = JTable::getInstance('Comment', 'JCommentsTable');
             if ($comment->load($id)) {
                 // we will not ban own IP ;)
                 if ($comment->ip != $acl->getUserIP()) {
                     $options = array();
                     $options['ip'] = $comment->ip;
                     // check if this IP already banned
                     if (JCommentsSecurity::checkBlacklist($options)) {
                         $result = JCommentsEventHelper::trigger('onJCommentsUserBeforeBan', array(&$comment, &$options));
                         if (!in_array(false, $result, true)) {
                             $blacklist = JTable::getInstance('Blacklist', 'JCommentsTable');
                             $blacklist->ip = $comment->ip;
                             $blacklist->created = JFactory::getDate()->toSql();
                             $blacklist->created_by = $acl->getUserId();
                             if ($blacklist->store()) {
                                 JCommentsEventHelper::trigger('onJCommentsUserAfterBan', array(&$comment, $options));
                                 self::showInfoMessage(JText::_('SUCCESSFULLY_BANNED'), 'comment-item-' . $id);
                             }
                         }
                     } else {
                         self::showErrorMessage(JText::_('ERROR_IP_ALREADY_BANNED'), '', 'comment-item-' . $id);
                     }
                 } else {
                     self::showErrorMessage(JText::_('ERROR_YOU_CAN_NOT_BAN_YOUR_IP'), '', 'comment-item-' . $id);
                 }
             }
         }
     }
     return $response;
 }