public function newReply($fields=array(), $user=null) { $user = KunenaUserHelper::get($user); $topic = $this->getTopic(); $category = $this->getCategory(); $message = new KunenaForumMessage(); $message->setTopic($topic); $message->parent = $this->id; $message->thread = $topic->id; $message->catid = $topic->category_id; $message->name = $user->getName(''); $message->userid = $user->userid; $message->subject = $this->subject; $message->ip = $_SERVER ["REMOTE_ADDR"]; if ($topic->hold) { // If topic was unapproved or deleted, use the same state for the new message $message->hold = $topic->hold; } else { // Otherwise message is either unapproved or published depending if the category is moderated or not $message->hold = $category->review ? (int)!$category->authorise ('moderate', $user, true) : 0; } if ($fields === true) { $user = KunenaFactory::getUser($this->userid); $text = preg_replace('/\[confidential\](.*?)\[\/confidential\]/su', '', $this->message ); $message->message = "[quote=\"{$user->getName($this->name)}\" post={$this->id}]" . $text . "[/quote]"; } elseif (is_array($fields)) { $message->bind($fields, array ('name', 'email', 'subject', 'message' ), true); } return array($topic, $message); }
/** * Prepare report message form. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $id = $this->input->getInt('id'); $mesid = $this->input->getInt('mesid'); $me = KunenaUserHelper::getMyself(); if (!$this->config->reportmsg) { // Deny access if report feature has been disabled. throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 404); } if (!$me->exists()) { // Deny access if user is guest. throw new KunenaExceptionAuthorise(JText::_('COM_KUNENA_NO_ACCESS'), 401); } if (!$mesid) { $this->topic = KunenaForumTopicHelper::get($id); $this->topic->tryAuthorise(); } else { $this->message = KunenaForumMessageHelper::get($mesid); $this->message->tryAuthorise(); $this->topic = $this->message->getTopic(); } $this->category = $this->topic->getCategory(); $this->uri = "index.php?option=com_kunena&view=topic&layout=report&catid={$this->category->id}" . "&id={$this->topic->id}" . ($this->message ? "&mesid={$this->message->id}" : ''); }
/** * returns the forum post url * * @return null|string */ public function url() { if ( ! $this->_post ) { return null; } return $this->_post->getUrl(); }
/** * Prepare topic moderate display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $catid = $this->input->getInt('catid'); $id = $this->input->getInt('id'); $mesid = $this->input->getInt('mesid'); if (!$mesid) { $this->topic = KunenaForumTopicHelper::get($id); $this->topic->tryAuthorise('move'); } else { $this->message = KunenaForumMessageHelper::get($mesid); $this->message->tryAuthorise('move'); $this->topic = $this->message->getTopic(); } $this->category = $this->topic->getCategory(); $this->uri = "index.php?option=com_kunena&view=topic&layout=moderate" . "&catid={$this->category->id}&id={$this->topic->id}" . ($this->message ? "&mesid={$this->message->id}" : ''); $this->title = !$this->message ? JText::_('COM_KUNENA_TITLE_MODERATE_TOPIC') : JText::_('COM_KUNENA_TITLE_MODERATE_MESSAGE'); // Load topic icons if available. if ($this->config->topicicons) { $this->template = KunenaTemplate::getInstance(); $this->template->setCategoryIconset(); $this->topicIcons = $this->template->getTopicIcons(false); } // Have a link to moderate user as well. if (isset($this->message)) { $user = $this->message->getAuthor(); if ($user->exists()) { $username = $user->getName(); $this->userLink = $this->message->userid ? JHtml::_('kunenaforum.link', 'index.php?option=com_kunena&view=user&layout=moderate&userid=' . $this->message->userid, $username . ' (' . $this->message->userid . ')', $username . ' (' . $this->message->userid . ')') : null; } } if ($this->message) { $this->banHistory = KunenaUserBan::getUserHistory($this->message->userid); $this->me = KunenaFactory::getUser(); // Get thread and reply count from current message: $db = JFactory::getDbo(); $query = "SELECT COUNT(mm.id) AS replies FROM #__kunena_messages AS m\r\n\t\t\t\tINNER JOIN #__kunena_messages AS t ON m.thread=t.id\r\n\t\t\t\tLEFT JOIN #__kunena_messages AS mm ON mm.thread=m.thread AND mm.time > m.time\r\n\t\t\t\tWHERE m.id={$db->Quote($this->message->id)}"; $db->setQuery($query, 0, 1); $this->replies = $db->loadResult(); if (KunenaError::checkDatabaseError()) { return; } } $this->banInfo = KunenaUserBan::getInstanceByUserid(JFactory::getUser()->id, true); }
public function createParent($messageId = null) { $parent = new stdClass(); $parent->forceSecure = true; $parent->forceMinimal = false; if ($messageId) { $message = KunenaForumMessage::getInstance($messageId); $parent->attachments = $message->getAttachments(); } return $parent; }
public function newTopic($fields=array(), $user=null) { kimport ('kunena.forum.topic'); kimport ('kunena.forum.message'); $catid = $this->getNewTopicCategory()->id; $user = KunenaUserHelper::get($user); $message = new KunenaForumMessage(); $message->catid = $catid; $message->name = $user->getName(''); $message->userid = $user->userid; $message->ip = $_SERVER ["REMOTE_ADDR"]; $message->hold = $this->review ? (int)!$this->authorise ('moderate', $user, true) : 0; $message->bind($fields, array ('name', 'email', 'subject', 'message')); $topic = new KunenaForumTopic(); $topic->category_id = $catid; $topic->hold = $message->hold; $topic->bind($fields, array ('subject','icon_id')); $message->setTopic($topic); return array($topic, $message); }
/** * @param int $topic_id * @param int $start * @param int $limit * @param string $ordering * @param int $hold * @param bool $orderbyid * * @return array */ protected static function loadMessagesByTopic($topic_id, $start = 0, $limit = 0, $ordering = 'ASC', $hold = 0, $orderbyid = false) { $db = JFactory::getDBO(); $query = "SELECT m.*, t.message\n\t\t\tFROM #__kunena_messages AS m\n\t\t\tINNER JOIN #__kunena_messages_text AS t ON m.id=t.mesid\n\t\t\tWHERE m.thread={$db->quote($topic_id)} AND m.hold IN ({$hold}) ORDER BY m.time {$ordering}"; $db->setQuery($query, $start, $limit); $results = (array) $db->loadAssocList('id'); KunenaError::checkDatabaseError(); $location = $orderbyid || $ordering == 'ASC' ? $start : KunenaForumTopicHelper::get($topic_id)->getTotal($hold) - $start - 1; $order = $ordering == 'ASC' ? 1 : -1; $list = array(); foreach ($results as $id => $result) { $instance = new KunenaForumMessage($result); $instance->exists(true); self::$_instances[$id] = $instance; $list[$orderbyid ? $id : $location] = $instance; $location += $order; } unset($results); return $list; }
/** * Prepare message actions display. * * @return void */ protected function before() { parent::before(); $mesid = $this->input->getInt('mesid'); $me = KunenaUserHelper::getMyself(); $this->message = KunenaForumMessage::getInstance($mesid); $this->topic = $this->message->getTopic(); $id = $this->message->thread; $catid = $this->message->catid; $token = JSession::getFormToken(); $task = "index.php?option=com_kunena&view=topic&task=%s&catid={$catid}&id={$id}&mesid={$mesid}&{$token}=1"; $layout = "index.php?option=com_kunena&view=topic&layout=%s&catid={$catid}&id={$id}&mesid={$mesid}"; $this->template = KunenaFactory::getTemplate(); $this->messageButtons = new JObject(); $this->message_closed = null; if ($this->message->isAuthorised('reply')) { if (version_compare(JVERSION, '3.4', '<') && $me->canDoCaptcha()) { $this->quickreply = false; } elseif (version_compare(JVERSION, '3.4', '>') && $me->canDoCaptcha()) { $this->quickreply = true; } else { $this->quickreply = true; } } else { $this->quickreply = false; } // Reply / Quote if ($this->message->isAuthorised('reply')) { $this->messageButtons->set('reply', $this->getButton(sprintf($layout, 'reply'), 'reply', 'message', 'communication', null, true)); if ($me->exists() && !KunenaSpamRecaptcha::getInstance()->enabled()) { $this->messageButtons->set('quickreply', $this->getButton(sprintf($layout, 'reply'), 'quickreply', 'message', 'communication', "kreply{$mesid}")); } $this->messageButtons->set('quote', $this->getButton(sprintf($layout, 'reply"e=1'), 'quote', 'message', 'communication')); } elseif (!$me->isModerator($this->topic->getCategory())) { // User is not allowed to write a post. $this->message_closed = $this->topic->locked ? JText::_('COM_KUNENA_POST_LOCK_SET') : ($me->exists() ? JText::_('COM_KUNENA_REPLY_USER_REPLY_DISABLED') : ' '); } $login = KunenaLogin::getInstance(); if (!$this->message->isAuthorised('reply') && !$this->message_closed && $login->enabled() || !$this->message->isAuthorised('reply') && !$this->topic->locked && $login->enabled() && !$me->userid) { $logintext = '<a class="btn-link" href="#klogin" rel="nofollow"> ' . JText::_('JLOGIN') . '</a>'; if ($login->getRegistrationUrl()) { $register = ' ' . JText::_('COM_KUNENA_LOGIN_OR') . ' <a class="btn-link" href="' . $login->getRegistrationUrl() . '">' . JText::_('COM_KUNENA_PROFILEBOX_CREATE_ACCOUNT') . '</a>'; } else { $register = ''; } echo '<p>' . JText::sprintf('COM_KUNENA_LOGIN_PLEASE', $logintext, $register) . '</p>'; } // Thank you. if (isset($this->message->thankyou)) { if ($this->message->isAuthorised('thankyou') && !array_key_exists($me->userid, $this->message->thankyou)) { $this->messageButtons->set('thankyou', $this->getButton(sprintf($task, 'thankyou'), 'thankyou', 'message', 'user', null, false)); } } // Unthank you if ($this->message->isAuthorised('unthankyou') && array_key_exists($me->userid, $this->message->thankyou)) { $this->messageButtons->set('unthankyou', $this->getButton(sprintf($task, 'unthankyou&userid=' . $me->userid), 'unthankyou', 'message', 'user', null, false)); } // Report this. if (KunenaFactory::getConfig()->reportmsg && $me->exists()) { $this->messageButtons->set('report', $this->getButton(sprintf($layout, 'report'), 'report', 'message', 'user')); } // Moderation and own post actions. if ($this->message->isAuthorised('edit')) { $this->messageButtons->set('edit', $this->getButton(sprintf($layout, 'edit'), 'edit', 'message', 'moderation')); } if ($this->message->isAuthorised('move')) { $this->messageButtons->set('moderate', $this->getButton(sprintf($layout, 'moderate'), 'moderate', 'message', 'moderation')); } if ($this->message->hold == 1) { if ($this->message->isAuthorised('approve')) { $this->messageButtons->set('publish', $this->getButton(sprintf($task, 'approve'), 'approve', 'message', 'moderation')); } if ($this->message->isAuthorised('delete')) { $this->messageButtons->set('delete', $this->getButton(sprintf($task, 'delete'), 'delete', 'message', 'moderation')); } } elseif ($this->message->hold == 2 || $this->message->hold == 3) { if ($this->message->isAuthorised('undelete')) { $this->messageButtons->set('undelete', $this->getButton(sprintf($task, 'undelete'), 'undelete', 'message', 'moderation')); } if ($this->message->isAuthorised('permdelete')) { $this->messageButtons->set('permdelete', $this->getButton(sprintf($task, 'permdelete'), 'permdelete', 'message', 'permanent')); } } elseif ($this->message->isAuthorised('delete')) { $this->messageButtons->set('delete', $this->getButton(sprintf($task, 'delete'), 'delete', 'message', 'moderation')); } JPluginHelper::importPlugin('kunena'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onKunenaGetButtons', array('message.action', $this->messageButtons, $this)); }
public function displayUnread($tpl = null) { // Redirect unread layout to the page that contains the first unread message $category = $this->get('Category'); $topic = $this->get('Topic'); KunenaForumTopicHelper::fetchNewStatus(array($topic->id => $topic)); $message = KunenaForumMessage::getInstance($topic->lastread ? $topic->lastread : $topic->last_post_id); while (@ob_end_clean()) { } $this->app->redirect($topic->getUrl($category, false, $message)); }
/** * @param KunenaForumMessage $message * @param int $postdelta * * @return bool */ public function update($message = null, $postdelta = 0) { // Update post count $this->posts += $postdelta; $exists = $message && $message->exists(); if (!$this->exists()) { if (!$exists) { $this->setError(JText::_('COM_KUNENA_LIB_TOPIC_NOT_EXISTS')); return false; } $this->id = $message->id; } if ($exists && $message->thread == $this->id && $message->hold == $this->hold) { // If message belongs into this topic and has same state, we may need to update cache $this->updatePostInfo($message->id, $message->time, $message->userid, $message->message, $message->name); } elseif (!$this->moved_id) { if (!isset($this->hold)) { $this->hold = KunenaForum::TOPIC_DELETED; } // If message isn't visible anymore, check if we need to update cache if (!$exists || $this->first_post_id == $message->id) { // If message got deleted and was cached, we need to find new first post $db = JFactory::getDBO(); $query = "SELECT * FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON t.mesid=m.id\n\t\t\t\t\tWHERE m.thread={$db->quote($this->id)} AND m.hold={$this->hold} ORDER BY m.time ASC, m.id ASC"; $db->setQuery($query, 0, 1); $first = $db->loadObject(); KunenaError::checkDatabaseError(); if ($first) { $this->first_post_time = 0; $this->updatePostInfo($first->id, $first->time, $first->userid, $first->message, $first->name); } else { $this->updatePostInfo(false); } } if (!$exists || $this->last_post_id == $message->id) { // If topic got deleted and was cached, we need to find new last post $db = JFactory::getDBO(); $query = "SELECT * FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON t.mesid=m.id\n\t\t\t\t\tWHERE m.thread={$db->quote($this->id)} AND m.hold={$this->hold} ORDER BY m.time DESC, m.id DESC"; $db->setQuery($query, 0, 1); $last = $db->loadObject(); KunenaError::checkDatabaseError(); if ($last) { $this->last_post_time = 0; $this->updatePostInfo($last->id, $last->time, $last->userid, $last->message, $last->name); } else { $this->updatePostInfo(false); } } } if (!$this->first_post_id || !$this->last_post_id) { // If topic has no visible posts, mark it deleted and recount $this->hold = $exists ? $message->hold : KunenaForum::TOPIC_DELETED; $this->recount(); } if (!($message && $message->exists()) && !$this->posts) { return $this->delete(); } if (!$this->save()) { return false; } if ($exists && $message->userid && abs($postdelta) <= 1) { // Update user topic $usertopic = $this->getUserTopic($message->userid); if (!$usertopic->update($message, $postdelta)) { $this->setError($usertopic->getError()); } // Update post count from user $user = KunenaUserHelper::get($message->userid); $user->posts += $postdelta; if (!$user->save()) { $this->setError($user->getError()); } } else { KunenaForumTopicUserHelper::recount($this->id); // FIXME: optimize KunenaUserHelper::recount(); } return true; }
public static function getMessageUrl(KunenaForumMessage $message, $xhtml = true, KunenaForumTopic $topic = null, KunenaForumCategory $category = null) { // FIXME: not yet fully implemented... if (!$category) { $category = $message->getCategory(); } if (!$topic) { $topic = $message->getTopic(); } return KunenaRoute::_("index.php?option=com_kunena&view=topic&catid={$category->id}&id={$topic->id}", $xhtml); }
/** * @param array $fields * @param mixed $user * @param array $safefields * * @return array */ public function newTopic(array $fields = null, $user = null, array $safefields = null) { $catid = isset($safefields['category_id']) ? $safefields['category_id'] : $this->getNewTopicCategory($user)->id; $user = KunenaUserHelper::get($user); $message = new KunenaForumMessage(); $message->catid = $catid; $message->name = $user->getName(''); $message->userid = $user->userid; $message->ip = !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $message->hold = $this->review ? (int) (!$this->authorise('moderate', $user, true)) : 0; if ($safefields) { $message->bind($safefields); } if ($fields) { $message->bind($fields, array('name', 'email', 'subject', 'message'), true); } $topic = new KunenaForumTopic(); $topic->category_id = $catid; $topic->hold = KunenaForum::TOPIC_CREATION; if ($safefields) { $topic->bind($safefields); } if ($fields) { $topic->bind($fields, array('subject', 'icon_id'), true); } $message->setTopic($topic); return array($topic, $message); }
static protected function loadMessagesByTopic($topic_id, $start=0, $limit=0, $ordering='ASC', $hold=0, $orderbyid = false) { $db = JFactory::getDBO (); $query = "SELECT m.*, t.message FROM #__kunena_messages AS m INNER JOIN #__kunena_messages_text AS t ON m.id=t.mesid WHERE m.thread={$db->quote($topic_id)} AND m.hold IN ({$hold}) ORDER BY m.time {$ordering}"; $db->setQuery ( $query, $start, $limit ); $results = (array) $db->loadAssocList ('id'); KunenaError::checkDatabaseError (); $list = array(); foreach ( $results as $id=>$result ) { $instance = new KunenaForumMessage (false); $instance->setProperties ( $result ); $instance->exists(true); self::$_instances [$id] = $instance; $list[$orderbyid ? $id : $start++] = $instance; } unset ($results); return $list; }
public function onAfterThankyou($actor, $target, KunenaForumMessage $message) { CFactory::load ( 'libraries', 'userpoints' ); CUserPoints::assignPoint ( 'com_kunena.thread.thankyou', $target ); $actor = CFactory::getUser($actor); $target = CFactory::getUser($target); //Create CParameter use for params $params = new CParameter(''); $params->set('actorName', $actor->getDisplayName()); $params->set('recipientName', $target->getDisplayName()); $params->set('recipientUrl', 'index.php?option=com_community&view=profile&userid=' . $target->id); // Actor Link $params->set('url', JUri::getInstance()->toString(array('scheme', 'host', 'port')) . $message->getPermaUrl(null)); // {url} tag for activity. Used when hovering over avatar in notification window, as well as in email notification $params->set('title', $message->displayField('subject')); // (title) tag in language file $params->set('title_url' , $message->getPermaUrl() ); // Make the title in notification - linkable $params->set('message', $message->message); // (message) tag in language file $params->set('actor', $actor->getDisplayName()); // Actor in the stream $params->set('actor_url', 'index.php?option=com_community&view=profile&userid=' . $actor->id); // Actor Link // Finally, send notifications CNotificationLibrary::add('kunena_thankyou' , $actor->id , $target->id , JText::sprintf('PLG_KUNENA_COMMUNITY_ACTIVITY_THANKYOU_TITLE_ACT') , JText::sprintf('PLG_KUNENA_COMMUNITY_ACTIVITY_THANKYOU_TEXT') , '' , $params ); $act = new stdClass (); $act->cmd = 'wall.write'; $act->actor = $actor->id; $act->target = $target->id; $act->title = JText::sprintf('PLG_KUNENA_COMMUNITY_ACTIVITY_THANKYOU_WALL', $params->get('actor_url'),$params->get('actor'),$params->get('recipientUrl'),$params->get('recipientName'),$params->get('url'),$params->get('title')); $act->content = NULL; $act->app = 'kunena.message.thankyou'; $act->cid = $target->id; $act->access = $this->getAccess($message->getCategory()); // Comments and like support $act->comment_id = $target->id; $act->comment_type = 'kunena.message.thankyou'; $act->like_id = $target->id; $act->like_type = 'kunena.message.thankyou'; // Do not add private activities if ($act->access > 20) return; CFactory::load ( 'libraries', 'activities' ); $table = CActivityStream::add($act); if(is_object($table)) { $table->like_id = $table->id; $table->store(); } }
/** * Post to Kunena 3.x * * @return void */ protected function post3x() { // Load front end language file as well $lang = $this->lang; $lang->load('com_kunena', JPATH_SITE . '/components/com_kunena'); $params = $this->getParams(); $app = $this->app; $formModel = $this->getModel(); $input = $app->input; $user = $this->user; $now = $this->date; $w = new FabrikWorker(); $catid = $params->get('kunena_category', 0); // Added action in request $msg = $w->parseMessageForPlaceHolder($params->get('kunena_content'), $formModel->fullFormData); $subject = $params->get('kunena_title'); $subject = $w->parseMessageForPlaceHolder($subject, $formModel->fullFormData); // Added subject in request $origId = $input->get('id'); $input->set('id', 0); $topic = new KunenaForumTopic(); $topic->category_id = $catid; $topic->subject = $subject; $topic->first_post_time = $topic->last_post_time = $now->toUnix(); $topic->first_post_userid = $topic->last_post_userid = $user->get('id'); $topic->first_post_message = $topic->last_post_message = $msg; $topic->posts = 1; if ($topic->save()) { $message = new KunenaForumMessage(); $message->setTopic($topic); $message->subject = $subject; $message->catid = $catid; $message->name = $user->get('name'); $message->time = $now->toUnix(); $message->message = $msg; if (!$message->save()) { $app->enqueueMessage(FText::_('PLG_FORM_KUNENA_ERR_DIDNT_SAVE_MESSAGE') . ': ' . $message->getError(), 'error'); } } else { $app->enqueueMessage(FText::_('PLG_FORM_KUNENA_ERR_DIDNT_SAVE_TOPIC') . ': ' . $topic->getError(), 'error'); } $input->set('id', $origId); }
/** * Gets an URL to a post or a category * * @param int|null $forum Forum category * @param int|null $post Forum post * @return null|string URL */ public static function getForumURL($forum = null, $post = null) { if (!class_exists('KunenaForumTopic') || !class_exists('KunenaForumMessage')) { return null; } if ($post) { $url = KunenaForumTopic::getInstance((int) $post)->getUrl(); if (!$url) { $url = KunenaForumMessage::getInstance((int) $post)->getUrl(); } } else { $url = cbforumsModel::getCategory((int) $forum)->getUrl(); } return $url; }