/** * Sends notification about new or updated comment to subscribers * * @param JCommentsTableComment $comment The comment object * @param boolean $isNew True if the comment is new * @return void */ public static function sendToSubscribers(&$comment, $isNew = true) { if ($comment->published) { $data = array(); $data['comment'] = clone $comment; JCommentsNotificationHelper::push($data, $isNew ? 'comment-new' : 'comment-update'); } }
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; }