public function save($data) { $table = $this->getTable(); $pkName = $table->getKeyName(); $pk = !empty($data[$pkName]) ? $data[$pkName] : (int) $this->getState($this->getName() . '.id'); try { if ($pk > 0) { $table->load($pk); } $prevPublished = $table->published; if (!$table->bind($data)) { $this->setError($table->getError()); return false; } if ($table->userid == 0) { $table->name = preg_replace('/[\'"\\>\\<\\(\\)\\[\\]]?+/i', '', $table->name); $table->username = $table->name; } else { $user = JFactory::getUser($table->userid); $table->name = $user->name; $table->username = $user->username; $table->email = $user->email; } if (get_magic_quotes_gpc() == 1) { $table->title = stripslashes($table->title); $table->comment = stripslashes($table->comment); } $table->comment = JCommentsText::nl2br($table->comment); $table->comment = JCommentsFactory::getBBCode()->filter($table->comment); if (!$table->check()) { $this->setError($table->getError()); return false; } if (!$table->store()) { $this->setError($table->getError()); return false; } if ($table->published && $prevPublished != $table->published) { JCommentsNotificationHelper::push(array('comment' => $table), 'comment-new'); } $this->cleanCache('com_jcomments'); } catch (Exception $e) { $this->setError($e->getMessage()); return false; } if (isset($table->{$pkName})) { $this->setState($this->getName() . '.id', $table->{$pkName}); } return true; }
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; }
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); }
/** * Returns link for canceling the user's subscription for notifications about new comments * * @param $hash * * @return string * @deprecated Use JCommentsNotificationHelper::getUnsubscribeLink instead. */ public static function getUnsubscribeLink($hash) { return JCommentsNotificationHelper::getUnsubscribeLink($hash); }