Exemplo n.º 1
0
 function publishComment($id)
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $acl =& JCommentsFactory::getACL();
     $db =& JCommentsFactory::getDBO();
     $config =& JCommentsFactory::getConfig();
     $response =& JCommentsFactory::getAjaxResponse();
     $comment = new JCommentsDB($db);
     if ($comment->load((int) $id)) {
         if ($acl->isLocked($comment)) {
             $response->addAlert(JText::_('ERROR_BEING_EDITTED'));
         } else {
             if ($acl->canPublish()) {
                 $object_id = $comment->object_id;
                 $object_group = $comment->object_group;
                 $page = JComments::getCommentPage($object_id, $object_group, $comment->id);
                 $comment->published = !$comment->published;
                 $result = false;
                 if ($config->getInt('enable_mambots') == 1) {
                     $allowed = true;
                     require_once JCOMMENTS_HELPERS . DS . 'plugin.php';
                     JCommentsPluginHelper::importPlugin('jcomments');
                     JCommentsPluginHelper::trigger('onBeforeCommentPublished', array(&$comment, &$response, &$allowed));
                     if ($allowed === false) {
                         return $response;
                     }
                     $result = $comment->store();
                     JCommentsPluginHelper::trigger('onAfterCommentPublished', array(&$comment, &$response));
                 } else {
                     $result = $comment->store();
                 }
                 if ($result) {
                     if ($comment->published) {
                         // send notification to comment subscribers
                         JComments::sendToSubscribers($comment, true);
                     }
                     JCommentsAJAX::updateCommentsList($response, $object_id, $object_group, $page);
                 }
             } else {
                 $response->addAlert(JText::_('ERROR_CANT_PUBLISH'));
             }
         }
     }
     unset($comment);
     return $response;
 }
Exemplo n.º 2
0
 public static function publish($value)
 {
     JCommentsSecurity::checkToken();
     $pks = JCommentsInput::getVar('cid', array());
     if (is_array($pks)) {
         $db = JCommentsFactory::getDBO();
         $language = JCommentsFactory::getLanguage();
         $config = JCommentsFactory::getConfig();
         $config->set('enable_mambots', 1);
         require_once JCOMMENTS_BASE . '/jcomments.php';
         $lastLanguage = '';
         foreach ($pks as $pk) {
             $comment = new JCommentsTableComment($db);
             if ($comment->load($pk)) {
                 if ($comment->published != $value) {
                     $comment->published = $value;
                     $result = JCommentsEvent::trigger('onJCommentsCommentBeforePublish', array(&$comment));
                     if (!in_array(false, $result, true)) {
                         if ($comment->store()) {
                             JCommentsEvent::trigger('onJCommentsCommentAfterPublish', array(&$comment));
                             if ($comment->published) {
                                 if ($lastLanguage != $comment->lang) {
                                     $lastLanguage = $comment->lang;
                                     $language->load('com_jcomments', JOOMLATUNE_JPATH_SITE, $comment->lang);
                                 }
                                 // TODO: add separate message for just published comments
                                 JComments::sendToSubscribers($comment, true);
                             }
                         }
                     }
                 }
             }
         }
     }
     JCommentsRedirect(JCOMMENTS_INDEX . '?option=com_jcomments&task=comments');
 }
Exemplo n.º 3
0
 public static function executeCmd()
 {
     $app = JFactory::getApplication('site');
     $cmd = strtolower($app->input->get('cmd', ''));
     $hash = $app->input->get('hash', '');
     $id = $app->input->getInt('id', 0);
     $message = '';
     $link = str_replace('/administrator', '', JURI::root()) . 'index.php';
     $checkHash = JCommentsFactory::getCmdHash($cmd, $id);
     if ($hash == $checkHash) {
         $config = JCommentsFactory::getConfig();
         if ($config->getInt('enable_quick_moderation') == 1) {
             JTable::addIncludePath(JCOMMENTS_TABLES);
             $comment = JTable::getInstance('Comment', 'JCommentsTable');
             if ($comment->load($id)) {
                 $link = JCommentsObjectHelper::getLink($comment->object_id, $comment->object_group, $comment->lang);
                 $link = str_replace('&', '&', $link);
                 switch ($cmd) {
                     case 'publish':
                         $comment->published = 1;
                         $comment->store();
                         // send notification to comment subscribers
                         JComments::sendToSubscribers($comment, true);
                         $link .= '#comment-' . $comment->id;
                         break;
                     case 'unpublish':
                         $comment->published = 0;
                         $comment->store();
                         $acl = JCommentsFactory::getACL();
                         if ($acl->canPublish()) {
                             $link .= '#comment-' . $comment->id;
                         } else {
                             $link .= '#comments';
                         }
                         break;
                     case 'delete':
                         if ($config->getInt('delete_mode') == 0) {
                             $comment->delete();
                             $link .= '#comments';
                         } else {
                             $comment->markAsDeleted();
                             $link .= '#comment-' . $comment->id;
                         }
                         break;
                     case 'ban':
                         if ($config->getInt('enable_blacklist') == 1) {
                             $acl = JCommentsFactory::getACL();
                             // 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)) {
                                     $blacklist = JTable::getInstance('Blacklist', 'JCommentsTable');
                                     $blacklist->ip = $comment->ip;
                                     $blacklist->store();
                                     $message = JText::_('SUCCESSFULLY_BANNED');
                                 } else {
                                     $message = JText::_('ERROR_IP_ALREADY_BANNED');
                                 }
                             } else {
                                 $message = JText::_('ERROR_YOU_CAN_NOT_BAN_YOUR_IP');
                             }
                         }
                         break;
                 }
                 JCommentsNotificationHelper::send();
             } else {
                 $message = JText::_('ERROR_NOT_FOUND');
             }
         } else {
             $message = JText::_('ERROR_QUICK_MODERATION_DISABLED');
         }
     } else {
         $message = JText::_('ERROR_QUICK_MODERATION_INCORRECT_HASH');
     }
     $app->redirect($link, $message);
 }
Exemplo n.º 4
0
 public static function publishComment($id)
 {
     if (JCommentsSecurity::badRequest() == 1) {
         JCommentsSecurity::notAuth();
     }
     $acl = JCommentsFactory::getACL();
     $db = JCommentsFactory::getDBO();
     $response = JCommentsFactory::getAjaxResponse();
     $comment = new JCommentsTableComment($db);
     if ($comment->load((int) $id)) {
         if ($acl->isLocked($comment)) {
             $response->addAlert(JText::_('ERROR_BEING_EDITTED'));
         } else {
             if ($acl->canPublish($comment)) {
                 $object_id = $comment->object_id;
                 $object_group = $comment->object_group;
                 $page = JComments::getCommentPage($object_id, $object_group, $comment->id);
                 $comment->published = !$comment->published;
                 $result = JCommentsEvent::trigger('onJCommentsCommentBeforePublish', array(&$comment));
                 if (!in_array(false, $result, true)) {
                     if ($comment->store()) {
                         JCommentsEvent::trigger('onJCommentsCommentAfterPublish', array(&$comment));
                         if ($comment->published) {
                             JComments::sendToSubscribers($comment, true);
                         }
                         self::updateCommentsList($response, $object_id, $object_group, $page);
                     }
                 }
             } else {
                 $response->addAlert(JText::_('ERROR_CANT_PUBLISH'));
             }
         }
     }
     return $response;
 }