/** * 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 verifyCaptcha() { if (!$this->hasCaptcha()) { return; } $captcha = KunenaSpamRecaptcha::getInstance(); $success = $captcha->checkAnswer(); if (!$success) { $this->_app->setUserState('com_kunena.postfields', array('catid' => $this->catid, 'fields' => $this->fields, 'options' => $this->options)); $this->_app->enqueueMessage($captcha->getError(), 'error'); $this->redirectBack(); return false; } return true; }
protected function DisplayReply($tpl = null) { $this->setLayout('edit'); $captcha = KunenaSpamRecaptcha::getInstance(); if ($captcha->enabled()) { $this->captchaHtml = $captcha->getHtml(); if (!$this->captchaHtml) { $this->app->enqueueMessage($captcha->getError(), 'error'); $this->redirectBack(); return; } } $saved = $this->app->getUserState('com_kunena.postfields'); $this->catid = $this->state->get('item.catid'); $this->mesid = $this->state->get('item.mesid'); if (!$this->mesid) { $this->topic = KunenaForumTopicHelper::get($this->state->get('item.id')); $parent = KunenaForumMessageHelper::get($this->topic->first_post_id); } else { $parent = KunenaForumMessageHelper::get($this->mesid); $this->topic = $parent->getTopic(); } if (!$parent->authorise('reply')) { $this->app->enqueueMessage($parent->getError(), 'notice'); return false; } // Run events $params = new JRegistry(); $params->set('ksource', 'kunena'); $params->set('kunena_view', 'topic'); $params->set('kunena_layout', 'reply'); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('kunena'); $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0)); $quote = (bool) JRequest::getBool('quote', false); $this->category = $this->topic->getCategory(); if ($this->config->topicicons && $this->topic->authorise('edit', null, false)) { $this->topicIcons = $this->ktemplate->getTopicIcons(false, $saved ? $saved['icon_id'] : $this->topic->icon_id); } list($this->topic, $this->message) = $parent->newReply($saved ? $saved : $quote); $this->_prepareDocument('reply'); $this->action = 'post'; $this->allowedExtensions = KunenaAttachmentHelper::getExtensions($this->category); $this->post_anonymous = $saved ? $saved['anonymous'] : !empty($this->category->post_anonymous); $this->subscriptionschecked = $saved ? $saved['subscribe'] : $this->config->subscriptionschecked == 1; $this->app->setUserState('com_kunena.postfields', null); $this->render('Topic/Edit', $tpl); }
function display($mode = '') { $message = $this->msg; $this->id = $message->id; $this->catid = $message->catid; $this->thread = $message->thread; // Link to individual message if ($this->config->ordering_system == 'replyid') { $this->numLink = CKunenaLink::GetSamePageAnkerLink($this->id, '#' . $this->replynum); } else { $this->numLink = CKunenaLink::GetSamePageAnkerLink($this->id, '#' . $this->id); } // New post suffix for class if ($message->new) { $this->msgsuffix = '-new'; } // Add attachments if (!empty($message->attachments)) { $this->attachments = $message->attachments; } $subject = $message->subject; $this->resubject = JString::strtolower(JString::substr($subject, 0, JString::strlen(JText::_('COM_KUNENA_POST_RE')))) == JString::strtolower(JText::_('COM_KUNENA_POST_RE')) ? $subject : JText::_('COM_KUNENA_POST_RE') . ' ' . $subject; $this->subjectHtml = KunenaParser::parseText($subject); $this->messageHtml = KunenaParser::parseBBCode($message->message, $this); //Show admins the IP address of the user: if ($message->ip && (CKunenaTools::isAdmin() || CKunenaTools::isModerator($this->my->id, $this->catid) && !$this->config->hide_ip)) { $this->ipLink = CKunenaLink::GetMessageIPLink($message->ip); } $this->profile = KunenaFactory::getUser($message->userid); // Modify profile values by integration $triggerParams = array('userid' => $message->userid, 'userinfo' => &$this->profile); $integration = KunenaFactory::getProfile(); $integration->trigger('profileIntegration', $triggerParams); // Choose username $this->userid = $this->profile->userid; $this->username = $this->config->username ? $this->profile->username : $this->profile->name; if ((!$this->username || !$message->userid || $this->config->changename) && $message->name) { $this->username = $message->name; } if ($this->params->get('avatarPosition') == 'left' || $this->params->get('avatarPosition') == 'right') { $avatar = $this->profile->getAvatarLink('kavatar', 'post'); } else { $avatar = $this->profile->getAvatarLink('kavatar', 'welcome'); } if ($avatar) { $this->avatar = '<span class="kavatar">' . $avatar . '</span>'; } if ($this->config->showuserstats) { $activityIntegration = KunenaFactory::getActivityIntegration(); if ($this->config->userlist_usertype) { $this->usertype = $this->profile->getType($this->catid); } $this->userrankimage = $this->profile->getRank($this->catid, 'image'); $this->userranktitle = $this->profile->getRank($this->catid, 'title'); $this->userposts = $this->profile->posts; $this->userpoints = $activityIntegration->getUserPoints($this->profile->userid); $this->usermedals = $activityIntegration->getUserMedals($this->profile->userid); } //karma points and buttons $this->userkarma_minus = $this->userkarma_plus = ''; if ($this->config->showkarma && $this->profile->userid) { $this->userkarma = JText::_('COM_KUNENA_KARMA') . ": " . $this->profile->karma; if ($this->my->id && $this->my->id != $this->profile->userid) { $this->userkarma_minus = CKunenaLink::GetKarmaLink('decrease', $this->catid, $this->id, $this->userid, '<span class="kkarma-minus" alt="Karma-" border="0" title="' . JText::_('COM_KUNENA_KARMA_SMITE') . '"> </span>'); $this->userkarma_plus = CKunenaLink::GetKarmaLink('increase', $this->catid, $this->id, $this->userid, '<span class="kkarma-plus" alt="Karma+" border="0" title="' . JText::_('COM_KUNENA_KARMA_APPLAUD') . '"> </span>'); } } $this->profilelink = $this->profile->profileIcon('profile'); $this->personaltext = $this->profile->personalText; $this->signatureHtml = KunenaParser::parseBBCode($this->profile->signature); //Thankyou info and buttons if ($this->config->showthankyou && $this->profile->userid && $mode != 'threaded') { require_once KPATH_SITE . '/lib/kunena.thankyou.php'; $thankyou = new CKunenaThankyou(); $this->total_thankyou = $thankyou->getThankYouUser($this->id); $this->thankyou = array_slice($this->total_thankyou, 0, $this->config->thankyou_max); if ($this->my->id && $this->my->id != $this->profile->userid) { $this->message_thankyou = CKunenaLink::GetThankYouLink($this->catid, $this->id, $this->userid, CKunenaTools::showButton('thankyou', JText::_('COM_KUNENA_BUTTON_THANKYOU')), JText::_('COM_KUNENA_BUTTON_THANKYOU_LONG'), 'kicon-button kbuttonuser btn-left'); } } if (!$message->hold && (CKunenaTools::isModerator($this->my->id, $this->catid) || !$this->topicLocked)) { //user is allowed to reply/quote $this->captcha = KunenaSpamRecaptcha::getInstance(); if ($this->my->id && (CKunenaTools::isModerator($this->my->id, $this->catid) || $this->me->posts >= $this->config->captcha_post_limit)) { $this->message_quickreply = CKunenaLink::GetTopicPostReplyLink('reply', $this->catid, $this->id, CKunenaTools::showButton('reply', JText::_('COM_KUNENA_BUTTON_QUICKREPLY')), 'nofollow', 'kicon-button kbuttoncomm btn-left kqreply', JText::_('COM_KUNENA_BUTTON_QUICKREPLY_LONG'), ' id="kreply' . $this->id . '"'); } $this->message_reply = CKunenaLink::GetTopicPostReplyLink('reply', $this->catid, $this->id, CKunenaTools::showButton('reply', JText::_('COM_KUNENA_BUTTON_REPLY')), 'nofollow', 'kicon-button kbuttoncomm btn-left', JText::_('COM_KUNENA_BUTTON_REPLY_LONG')); $this->message_quote = CKunenaLink::GetTopicPostReplyLink('quote', $this->catid, $this->id, CKunenaTools::showButton('quote', JText::_('COM_KUNENA_BUTTON_QUOTE')), 'nofollow', 'kicon-button kbuttoncomm btn-left', JText::_('COM_KUNENA_BUTTON_QUOTE_LONG')); } else { //user is not allowed to write a post if ($this->topicLocked) { $this->message_closed = JText::_('COM_KUNENA_POST_LOCK_SET'); } else { $this->message_closed = JText::_('COM_KUNENA_VIEW_DISABLED'); } } $this->msgclass = 'kmsg'; //Offer an moderator a few tools if (CKunenaTools::isModerator($this->my->id, $this->catid)) { unset($this->message_closed); $this->message_edit = CKunenaLink::GetTopicPostReplyLink('edit', $this->catid, $this->id, CKunenaTools::showButton('edit', JText::_('COM_KUNENA_BUTTON_EDIT')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_EDIT_LONG')); $this->message_moderate = CKunenaLink::GetTopicPostReplyLink('moderate', $this->catid, $this->id, CKunenaTools::showButton('moderate', JText::_('COM_KUNENA_BUTTON_MODERATE')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_MODERATE_LONG')); if ($message->hold == 1) { $this->message_publish = CKunenaLink::GetTopicPostLink('approve', $this->catid, $this->id, CKunenaTools::showButton('approve', JText::_('COM_KUNENA_BUTTON_APPROVE')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_APPROVE_LONG')); $this->msgclass .= ' kunapproved'; } if ($message->hold == 2 || $message->hold == 3) { $this->msgclass .= ' kunapproved kdeleted'; $this->message_undelete = CKunenaLink::GetTopicPostLink('undelete', $this->catid, $this->id, CKunenaTools::showButton('undelete', JText::_('COM_KUNENA_BUTTON_UNDELETE')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_UNDELETE_LONG')); $this->message_permdelete = CKunenaLink::GetTopicPostLink('permdelete', $this->catid, $this->id, CKunenaTools::showButton('permdelete', JText::_('COM_KUNENA_BUTTON_PERMDELETE')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_PERMDELETE_LONG')); } else { $this->message_delete = CKunenaLink::GetTopicPostLink('delete', $this->catid, $this->id, CKunenaTools::showButton('delete', JText::_('COM_KUNENA_BUTTON_DELETE')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_DELETE_LONG')); } } else { if ($this->config->useredit && $this->my->id && $this->my->id == $this->profile->userid) { //Now, if the viewer==author and the viewer is allowed to edit his/her own post then offer an 'edit' link if ($message->hold != 2 && CKunenaTools::editTimeCheck($message->modified_time, $message->time)) { $this->message_edit = CKunenaLink::GetTopicPostReplyLink('edit', $this->catid, $this->id, CKunenaTools::showButton('edit', JText::_('COM_KUNENA_BUTTON_EDIT')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_EDIT_LONG')); if ($this->config->userdeletetmessage == '1') { if ($this->replynum == $this->replycnt) { $this->message_delete = CKunenaLink::GetTopicPostLink('delete', $this->catid, $this->id, CKunenaTools::showButton('delete', JText::_('COM_KUNENA_BUTTON_DELETE')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_DELETE_LONG')); } } else { if ($this->config->userdeletetmessage == '2') { $this->message_delete = CKunenaLink::GetTopicPostLink('delete', $this->catid, $this->id, CKunenaTools::showButton('delete', JText::_('COM_KUNENA_BUTTON_DELETE')), 'nofollow', 'kicon-button kbuttonmod btn-left', JText::_('COM_KUNENA_BUTTON_DELETE_LONG')); } } } } } $this->class = 'class="' . $this->msgclass . '"'; if (!$mode) { $templatefile = '/view/message.php'; } else { $templatefile = "/view/message.{$mode}.php"; } CKunenaTools::loadTemplate($templatefile, false, $this->templatepath); }
public function post() { $this->id = JRequest::getInt('parentid', 0); $fields = array('catid' => $this->catid, 'name' => JRequest::getString('authorname', $this->me->getName()), 'email' => JRequest::getString('email', null), 'subject' => JRequest::getVar('subject', null, 'POST', 'string', JREQUEST_ALLOWRAW), 'message' => JRequest::getVar('message', null, 'POST', 'string', JREQUEST_ALLOWRAW), 'icon_id' => JRequest::getInt('topic_emoticon', null), 'anonymous' => JRequest::getInt('anonymous', 0), 'poll_title' => JRequest::getString('poll_title', ''), 'poll_options' => JRequest::getVar('polloptionsID', array(), 'post', 'array'), 'poll_time_to_live' => JRequest::getString('poll_time_to_live', 0), 'tags' => JRequest::getString('tags', null), 'mytags' => JRequest::getString('mytags', null), 'subscribe' => JRequest::getInt('subscribeMe', 0)); $this->app->setUserState('com_kunena.postfields', $fields); if (!JRequest::checkToken()) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->redirectBack(); } $captcha = KunenaSpamRecaptcha::getInstance(); if ($captcha->enabled()) { $success = $captcha->verify(); if (!$success) { $this->app->enqueueMessage($captcha->getError(), 'error'); $this->redirectBack(); } } if (!$this->id) { // Create topic $category = KunenaForumCategoryHelper::get($this->catid); if (!$category->authorise('topic.create')) { $this->app->enqueueMessage($category->getError(), 'notice'); $this->redirectBack(); } list($topic, $message) = $category->newTopic($fields); } else { // Reply topic $parent = KunenaForumMessageHelper::get($this->id); if (!$parent->authorise('reply')) { $this->app->enqueueMessage($parent->getError(), 'notice'); $this->redirectBack(); } list($topic, $message) = $parent->newReply($fields); $category = $topic->getCategory(); } // Flood protection if ($this->config->floodprotection && !$this->me->isModerator($category)) { $timelimit = JFactory::getDate()->toUnix() - $this->config->floodprotection; $ip = $_SERVER["REMOTE_ADDR"]; $db = JFactory::getDBO(); $db->setQuery("SELECT COUNT(*) FROM #__kunena_messages WHERE ip={$db->Quote($ip)} AND time>{$db->quote($timelimit)}"); $count = $db->loadResult(); if (KunenaError::checkDatabaseError() || $count) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_POST_TOPIC_FLOOD', $this->config->floodprotection)); $this->redirectBack(); } } // Set topic icon if permitted if ($this->config->topicicons && isset($fields['icon_id']) && $topic->authorise('edit', null, false)) { $topic->icon_id = $fields['icon_id']; } // If requested: Make message to be anonymous if ($fields['anonymous'] && $message->getCategory()->allow_anonymous) { $message->makeAnonymous(); } // If configured: Hold posts from guests if (!$this->me->userid && $this->config->hold_guest_posts) { $message->hold = 1; } // If configured: Hold posts from users if (!$this->me->isModerator($category) && $this->me->posts < $this->config->hold_newusers_posts) { $message->hold = 1; } // Upload new attachments foreach ($_FILES as $key => $file) { $intkey = 0; if (preg_match('/\\D*(\\d+)/', $key, $matches)) { $intkey = (int) $matches[1]; } if ($file['error'] != UPLOAD_ERR_NO_FILE) { $message->uploadAttachment($intkey, $key); } } // Activity integration $activity = KunenaFactory::getActivityIntegration(); if ($message->hold == 0) { if (!$topic->exists()) { $activity->onBeforePost($message); } else { $activity->onBeforeReply($message); } } // Save message $success = $message->save(); if (!$success) { $this->app->enqueueMessage($message->getError(), 'error'); $this->redirectBack(); } // Message has been sent, we can now clear saved form $this->app->setUserState('com_kunena.postfields', null); // Display possible warnings (upload failed etc) foreach ($message->getErrors() as $warning) { $this->app->enqueueMessage($warning, 'notice'); } // Create Poll $poll_title = $fields['poll_title']; $poll_options = $fields['poll_options']; if (!empty($poll_options) && !empty($poll_title)) { if ($topic->authorise('poll.create', null, false)) { $poll = $topic->getPoll(); $poll->title = $poll_title; $poll->polltimetolive = $fields['poll_time_to_live']; $poll->setOptions($poll_options); if (!$poll->save()) { $this->app->enqueueMessage($poll->getError(), 'notice'); } else { $topic->poll_id = $poll->id; $topic->save(); $this->app->enqueueMessage(JText::_('COM_KUNENA_POLL_CREATED')); } } else { $this->app->enqueueMessage($topic->getError(), 'notice'); } } // Update Tags $this->updateTags($message->thread, $fields['tags'], $fields['mytags']); $message->sendNotification(); //now try adding any new subscriptions if asked for by the poster $usertopic = $topic->getUserTopic(); if ($fields['subscribe'] && !$usertopic->subscribed) { if ($topic->subscribe(1)) { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_SUBSCRIBED_TOPIC')); // Activity integration $activity = KunenaFactory::getActivityIntegration(); $activity->onAfterSubscribe($topic, 1); } else { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_NO_SUBSCRIBED_TOPIC') . ' ' . $topic->getError()); } } if ($message->hold == 1) { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_SUCCES_REVIEW')); } else { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_SUCCESS_POSTED')); } $category = KunenaForumCategoryHelper::get($this->return); if ($message->authorise('read', null, false)) { $this->setRedirect($message->getUrl($category, false)); } elseif ($topic->authorise('read', null, false)) { $this->setRedirect($topic->getUrl($category, false)); } else { $this->setRedirect($category->getUrl(null, false)); } }
/** * @return bool */ protected function verifyCaptcha() { $captcha = KunenaSpamRecaptcha::getInstance(); $result = $captcha->verify(); if (!$result) { $this->app->enqueueMessage($captcha->getError()); } return $result; }
public function post() { $this->id = JRequest::getInt('parentid', 0); $fields = array('catid' => $this->catid, 'name' => JRequest::getString('authorname', $this->me->getName()), 'email' => JRequest::getString('email', null), 'subject' => JRequest::getVar('subject', null, 'POST', 'string', JREQUEST_ALLOWRAW), 'message' => JRequest::getVar('message', null, 'POST', 'string', JREQUEST_ALLOWRAW), 'icon_id' => JRequest::getInt('topic_emoticon', null), 'anonymous' => JRequest::getInt('anonymous', 0), 'poll_title' => JRequest::getString('poll_title', ''), 'poll_options' => JRequest::getVar('polloptionsID', array(), 'post', 'array'), 'poll_time_to_live' => JRequest::getString('poll_time_to_live', 0), 'tags' => JRequest::getString('tags', null), 'mytags' => JRequest::getString('mytags', null), 'subscribe' => JRequest::getInt('subscribeMe', 0)); $this->app->setUserState('com_kunena.postfields', $fields); if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->setRedirectBack(); return; } $template = KunenaFactory::getTemplate(); // Load language file from the template. $template->loadLanguage(); if (!$this->id) { // Create topic $category = KunenaForumCategoryHelper::get($this->catid); if (!$category->authorise('topic.create')) { $this->app->enqueueMessage($category->getError(), 'notice'); $this->setRedirectBack(); return; } list($topic, $message) = $category->newTopic($fields); } else { // Reply topic $parent = KunenaForumMessageHelper::get($this->id); if (!$parent->authorise('reply')) { $this->app->enqueueMessage($parent->getError(), 'notice'); $this->setRedirectBack(); return; } list($topic, $message) = $parent->newReply($fields); $category = $topic->getCategory(); } $templates = KunenaTemplateHelper::parseXmlFiles(); // set dynamic template information foreach ($templates as $tmpl) { if (KunenaTemplateHelper::isDefault($tmpl->directory)) { $template = $tmpl; } } if ($this->me->canDoCaptcha()) { if ($template->kversion >= 4.0) { if (JPluginHelper::isEnabled('captcha')) { $plugin = JPluginHelper::getPlugin('captcha'); $params = new JRegistry($plugin[0]->params); $captcha_pubkey = $params->get('public_key'); $catcha_privkey = $params->get('private_key'); if (!empty($captcha_pubkey) && !empty($catcha_privkey)) { JPluginHelper::importPlugin('captcha'); $dispatcher = JDispatcher::getInstance(); $captcha_response = $this->app->input->getString('g-recaptcha-response'); if (!empty($captcha_response)) { // For ReCaptcha API 2.0 $res = $dispatcher->trigger('onCheckAnswer', $this->app->input->getString('g-recaptcha-response')); } else { // For ReCaptcha API 1.0 $res = $dispatcher->trigger('onCheckAnswer', $this->app->input->getString('recaptcha_response_field')); } if (!$res[0]) { $this->setRedirectBack(); return; } } } } else { $captcha = KunenaSpamRecaptcha::getInstance(); if ($captcha->enabled()) { $success = $captcha->verify(); if (!$success) { $this->app->enqueueMessage($captcha->getError(), 'error'); $this->setRedirectBack(); return; } } } } // Redirect to full reply instead. if (JRequest::getString('fullreply')) { $this->setRedirect(KunenaRoute::_("index.php?option=com_kunena&view=topic&layout=reply&catid={$fields->catid}&id={$parent->getTopic()->id}&mesid={$parent->id}", false)); return; } // Flood protection if ($this->config->floodprotection && !$this->me->isModerator($category)) { $timelimit = JFactory::getDate()->toUnix() - $this->config->floodprotection; $ip = $_SERVER["REMOTE_ADDR"]; $db = JFactory::getDBO(); $db->setQuery("SELECT COUNT(*) FROM #__kunena_messages WHERE ip={$db->Quote($ip)} AND time>{$db->quote($timelimit)}"); $count = $db->loadResult(); if (KunenaError::checkDatabaseError() || $count) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_POST_TOPIC_FLOOD', $this->config->floodprotection)); $this->setRedirectBack(); return; } } // Set topic icon if permitted if ($this->config->topicicons && isset($fields['icon_id']) && $topic->authorise('edit', null, false)) { $topic->icon_id = $fields['icon_id']; } // Remove IP address // TODO: Add administrator tool to remove all tracked IP addresses (from the database) if (!$this->config->iptracking) { $message->ip = ''; } // If requested: Make message to be anonymous if ($fields['anonymous'] && $message->getCategory()->allow_anonymous) { $message->makeAnonymous(); } // If configured: Hold posts from guests if (!$this->me->userid && $this->config->hold_guest_posts) { $message->hold = 1; } // If configured: Hold posts from users if ($this->me->userid && !$this->me->isModerator($category) && $this->me->posts < $this->config->hold_newusers_posts) { $message->hold = 1; } // Prevent user abort from this point in order to maintain data integrity. @ignore_user_abort(true); // Mark attachments to be added or deleted. $attachments = JRequest::getVar('attachments', array(), 'post', 'array'); $attachment = JRequest::getVar('attachment', array(), 'post', 'array'); $message->addAttachments(array_keys(array_intersect_key($attachments, $attachment))); $message->removeAttachments(array_keys(array_diff_key($attachments, $attachment))); // Upload new attachments foreach ($_FILES as $key => $file) { $intkey = 0; if (preg_match('/\\D*(\\d+)/', $key, $matches)) { $intkey = (int) $matches[1]; } if ($file['error'] != UPLOAD_ERR_NO_FILE) { $message->uploadAttachment($intkey, $key, $this->catid); } } // Make sure that message has visible content (text, images or objects) to be shown. $text = KunenaHtmlParser::parseBBCode($message->message); if (!preg_match('!(<img |<object |<iframe )!', $text)) { $text = trim(JFilterOutput::cleanText($text)); } if (!$text) { $this->app->enqueueMessage(JText::_('COM_KUNENA_LIB_TABLE_MESSAGES_ERROR_NO_MESSAGE'), 'error'); $this->setRedirectBack(); return; } $maxlinks = $this->checkMaxLinks($text, $topic); if (!$maxlinks) { $this->app->enqueueMessage(JText::_('COM_KUNENA_TOPIC_SPAM_LINK_PROTECTION'), 'error'); $this->setRedirectBack(); return; } // Activity integration $activity = KunenaFactory::getActivityIntegration(); if ($message->hold == 0) { if (!$topic->exists()) { $activity->onBeforePost($message); } else { $activity->onBeforeReply($message); } } // Save message $success = $message->save(); if (!$success) { $this->app->enqueueMessage($message->getError(), 'error'); $this->setRedirectBack(); return; } // Message has been sent, we can now clear saved form $this->app->setUserState('com_kunena.postfields', null); // Display possible warnings (upload failed etc) foreach ($message->getErrors() as $warning) { $this->app->enqueueMessage($warning, 'notice'); } // Create Poll $poll_title = $fields['poll_title']; $poll_options = $fields['poll_options']; if (!empty($poll_options) && !empty($poll_title)) { if ($topic->authorise('poll.create', null, false)) { $poll = $topic->getPoll(); $poll->title = $poll_title; $poll->polltimetolive = $fields['poll_time_to_live']; $poll->setOptions($poll_options); if (!$poll->save()) { $this->app->enqueueMessage($poll->getError(), 'notice'); } else { $topic->poll_id = $poll->id; $topic->save(); $this->app->enqueueMessage(JText::_('COM_KUNENA_POLL_CREATED')); } } else { $this->app->enqueueMessage($topic->getError(), 'notice'); } } // Update Tags $this->updateTags($message->thread, $fields['tags'], $fields['mytags']); $message->sendNotification(); //now try adding any new subscriptions if asked for by the poster $usertopic = $topic->getUserTopic(); if ($fields['subscribe'] && !$usertopic->subscribed) { if ($topic->subscribe(1)) { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_SUBSCRIBED_TOPIC')); // Activity integration $activity = KunenaFactory::getActivityIntegration(); $activity->onAfterSubscribe($topic, 1); } else { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_NO_SUBSCRIBED_TOPIC') . ' ' . $topic->getError()); } } if ($message->hold == 1) { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_SUCCES_REVIEW')); } else { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_SUCCESS_POSTED')); } $category = KunenaForumCategoryHelper::get($this->return); if ($message->authorise('read', null, false) && $this->id) { $this->setRedirect($message->getUrl($category, false)); } elseif ($topic->authorise('read', null, false)) { $this->setRedirect($topic->getUrl($category, false)); } else { $this->setRedirect($category->getUrl(null, false)); } }
protected function DisplayReply($tpl = null) { $captcha = KunenaSpamRecaptcha::getInstance(); if ($captcha->enabled()) { $this->captchaHtml = $captcha->getHtml(); if ( !$this->captchaHtml ) { $app = JFactory::getApplication(); $app->enqueueMessage ( $captcha->getError(), 'error' ); $this->redirectBack (); } } $saved = $this->app->getUserState('com_kunena.postfields'); $this->setLayout('edit'); $this->catid = $this->state->get('item.catid'); $this->my = JFactory::getUser(); $this->me = KunenaUserHelper::getMyself(); $this->config = KunenaFactory::getConfig(); $mesid = $this->state->get('item.mesid'); if (!$mesid) { $this->topic = KunenaForumTopicHelper::get($this->state->get('item.id')); $parent = KunenaForumMessageHelper::get($this->topic->first_post_id); } else { $parent = KunenaForumMessageHelper::get($mesid); $this->topic = $parent->getTopic(); } if (!$parent->authorise('reply')) { $app = JFactory::getApplication(); $app->enqueueMessage ( $parent->getError(), 'notice' ); return false; } $quote = JRequest::getBool ( 'quote', false ); $this->category = $this->topic->getCategory(); if ($this->config->topicicons && $this->topic->authorise('edit', null, false)) { $this->topicIcons = $this->template->getTopicIcons(false, $saved ? $saved['icon_id'] : 0); } list ($this->topic, $this->message) = $parent->newReply($quote, $saved); $this->title = JText::_ ( 'COM_KUNENA_POST_REPLY_TOPIC' ) . ' ' . $this->topic->subject; $this->action = 'post'; $this->allowedExtensions = KunenaForumMessageAttachmentHelper::getExtensions($this->category); $this->post_anonymous = $saved ? $saved['anonymous'] : ! empty ( $this->category->post_anonymous ); $this->subscriptionschecked = $saved ? $saved['subscribe'] : $this->config->subscriptionschecked == 1; $this->app->setUserState('com_kunena.postfields', null); $this->display($tpl); }
public function post() { $this->id = JRequest::getInt('parentid', 0); $fields = array('catid' => $this->catid, 'name' => JRequest::getString('authorname', $this->me->getName()), 'email' => JRequest::getString('email', null), 'subject' => JRequest::getVar('subject', null, 'POST', 'string', JREQUEST_ALLOWRAW), 'message' => JRequest::getVar('message', null, 'POST', 'string', JREQUEST_ALLOWRAW), 'icon_id' => JRequest::getInt('topic_emoticon', null), 'anonymous' => JRequest::getInt('anonymous', 0), 'poll_title' => JRequest::getString('poll_title', ''), 'poll_options' => JRequest::getVar('polloptionsID', array(), 'post', 'array'), 'poll_time_to_live' => JRequest::getString('poll_time_to_live', 0), 'tags' => JRequest::getString('tags', null), 'mytags' => JRequest::getString('mytags', null), 'subscribe' => JRequest::getInt('subscribeMe', 0)); $this->app->setUserState('com_kunena.postfields', $fields); if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->redirectBack(); } $captcha = KunenaSpamRecaptcha::getInstance(); if ($captcha->enabled()) { $success = $captcha->verify(); if (!$success) { $this->app->enqueueMessage($captcha->getError(), 'error'); $this->redirectBack(); } } if (!$this->id) { // Create topic $category = KunenaForumCategoryHelper::get($this->catid); if (!$category->authorise('topic.create')) { $this->app->enqueueMessage($category->getError(), 'notice'); $this->redirectBack(); } list($topic, $message) = $category->newTopic($fields); $cato = $this->getCategory()->name; $dept = ""; switch ($cato) { case "Civil": $dept = "CV"; break; case "Placement Forum": $dept = "ALL"; break; case "SWO Circulars": $dept = "ALL"; break; case "Mechanical": $dept = "ME"; break; case "EEE": $dept = "EE"; break; case "Automobile": $dept = "AU"; break; case "Departments": $dept = "ALL"; break; default: $dept = $this->getCategory()->name; break; } $total1 = $this->mobNotify($fields['subject'], $cato, 0, $dept, 0, 0, $this->mesid); } else { // Reply topic $parent = KunenaForumMessageHelper::get($this->id); if (!$parent->authorise('reply')) { $this->app->enqueueMessage($parent->getError(), 'notice'); $this->redirectBack(); } list($topic, $message) = $parent->newReply($fields); $category = $topic->getCategory(); } // Flood protection if ($this->config->floodprotection && !$this->me->isModerator($category)) { $timelimit = JFactory::getDate()->toUnix() - $this->config->floodprotection; $ip = $_SERVER["REMOTE_ADDR"]; $db = JFactory::getDBO(); $db->setQuery("SELECT COUNT(*) FROM #__kunena_messages WHERE ip={$db->Quote($ip)} AND time>{$db->quote($timelimit)}"); $count = $db->loadResult(); if (KunenaError::checkDatabaseError() || $count) { $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_POST_TOPIC_FLOOD', $this->config->floodprotection)); $this->redirectBack(); } } // Set topic icon if permitted if ($this->config->topicicons && isset($fields['icon_id']) && $topic->authorise('edit', null, false)) { $topic->icon_id = $fields['icon_id']; } // Remove IP address // TODO: Add administrator tool to remove all tracked IP addresses (from the database) if (!$this->config->iptracking) { $message->ip = ''; } // If requested: Make message to be anonymous if ($fields['anonymous'] && $message->getCategory()->allow_anonymous) { $message->makeAnonymous(); } // If configured: Hold posts from guests if (!$this->me->userid && $this->config->hold_guest_posts) { $message->hold = 1; } // If configured: Hold posts from users if ($this->me->userid && !$this->me->isModerator($category) && $this->me->posts < $this->config->hold_newusers_posts) { $message->hold = 1; } // Prevent user abort from this point in order to maintain data integrity. @ignore_user_abort(true); // Upload new attachments foreach ($_FILES as $key => $file) { $intkey = 0; if (preg_match('/\\D*(\\d+)/', $key, $matches)) { $intkey = (int) $matches[1]; } if ($file['error'] != UPLOAD_ERR_NO_FILE) { $message->uploadAttachment($intkey, $key, $this->catid); } } // Make sure that message has visible content (text, images or objects) to be shown. $text = KunenaHtmlParser::parseBBCode($message->message); if (!preg_match('!(<img |<object )!', $text)) { $text = trim(JFilterOutput::cleanText($text)); } if (!$text) { $this->app->enqueueMessage(JText::_('COM_KUNENA_LIB_TABLE_MESSAGES_ERROR_NO_MESSAGE'), 'error'); $this->redirectBack(); } // Activity integration $activity = KunenaFactory::getActivityIntegration(); if ($message->hold == 0) { if (!$topic->exists()) { $activity->onBeforePost($message); } else { $activity->onBeforeReply($message); } } // Save message $success = $message->save(); if (!$success) { $this->app->enqueueMessage($message->getError(), 'error'); $this->redirectBack(); } // Message has been sent, we can now clear saved form $this->app->setUserState('com_kunena.postfields', null); // Display possible warnings (upload failed etc) foreach ($message->getErrors() as $warning) { $this->app->enqueueMessage($warning, 'notice'); } // Create Poll $poll_title = $fields['poll_title']; $poll_options = $fields['poll_options']; if (!empty($poll_options) && !empty($poll_title)) { if ($topic->authorise('poll.create', null, false)) { $poll = $topic->getPoll(); $poll->title = $poll_title; $poll->polltimetolive = $fields['poll_time_to_live']; $poll->setOptions($poll_options); if (!$poll->save()) { $this->app->enqueueMessage($poll->getError(), 'notice'); } else { $topic->poll_id = $poll->id; $topic->save(); $this->app->enqueueMessage(JText::_('COM_KUNENA_POLL_CREATED')); } } else { $this->app->enqueueMessage($topic->getError(), 'notice'); } } // Update Tags $this->updateTags($message->thread, $fields['tags'], $fields['mytags']); $message->sendNotification(); //now try adding any new subscriptions if asked for by the poster $usertopic = $topic->getUserTopic(); if ($fields['subscribe'] && !$usertopic->subscribed) { if ($topic->subscribe(1)) { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_SUBSCRIBED_TOPIC')); // Activity integration $activity = KunenaFactory::getActivityIntegration(); $activity->onAfterSubscribe($topic, 1); } else { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_NO_SUBSCRIBED_TOPIC') . ' ' . $topic->getError()); } } if ($message->hold == 1) { $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_SUCCES_REVIEW')); } else { $cato = $this->getCategory()->name; $dept = ""; switch ($cato) { case "Civil": $dept = "CV"; break; case "Placement Forum": $dept = "ALL"; break; case "SWO Circulars": $dept = "ALL"; break; case "Mechanical": $dept = "ME"; break; case "EEE": $dept = "EE"; break; case "Automobile": $dept = "AU"; break; case "Departments": $dept = "ALL"; break; default: $dept = $this->getCategory()->name; break; } $total1 = $this->mobNotify($fields['subject'], $this->getCategory()->name, 0, $dept, 0, 0, $this->mesid); $this->app->enqueueMessage(JText::_('COM_KUNENA_POST_SUCCESS_POSTED') . " Notification sent to " . $total1 . " students."); } $category = KunenaForumCategoryHelper::get($this->return); if ($message->authorise('read', null, false)) { $this->setRedirect($message->getUrl($category, false)); } elseif ($topic->authorise('read', null, false)) { $this->setRedirect($topic->getUrl($category, false)); } else { $this->setRedirect($category->getUrl(null, false)); } }
/** * Prepare topic display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); $catid = $this->input->getInt('catid', 0); $id = $this->input->getInt('id', 0); $mesid = $this->input->getInt('mesid', 0); $start = $this->input->getInt('limitstart', 0); $limit = $this->input->getInt('limit', 0); if ($limit < 1 || $limit > 100) { $limit = $this->config->messages_per_page; } $this->me = KunenaUserHelper::getMyself(); // Load topic and message. if ($mesid) { // If message was set, use it to find the current topic. $this->message = KunenaForumMessageHelper::get($mesid); $this->topic = $this->message->getTopic(); } else { // Note that redirect loops throw RuntimeException because of we added KunenaForumTopic::getTopic() call! $this->topic = KunenaForumTopicHelper::get($id)->getTopic(); $this->message = KunenaForumMessageHelper::get($this->topic->first_post_id); } // Load also category (prefer the URI variable if available). if ($catid && $catid != $this->topic->category_id) { $this->category = KunenaForumCategoryHelper::get($catid); $this->category->tryAuthorise(); } else { $this->category = $this->topic->getCategory(); } // Access check. $this->message->tryAuthorise(); // Check if we need to redirect (category or topic mismatch, or resolve permanent URL). if ($this->primary) { $channels = $this->category->getChannels(); if ($this->message->thread != $this->topic->id || $this->topic->category_id != $this->category->id && !isset($channels[$this->topic->category_id]) || $mesid && $this->layout != 'threaded') { while (@ob_end_clean()) { } $this->app->redirect($this->message->getUrl(null, false)); } } // Load messages from the current page and set the pagination. $hold = KunenaAccess::getInstance()->getAllowedHold($this->me, $this->category->id, false); $finder = new KunenaForumMessageFinder(); $finder->where('thread', '=', $this->topic->id)->filterByHold($hold); $start = $mesid ? $this->topic->getPostLocation($mesid) : $start; $this->pagination = new KunenaPagination($finder->count(), $start, $limit); $this->messages = $finder->order('time', $this->me->getMessageOrdering() == 'asc' ? 1 : -1)->start($this->pagination->limitstart)->limit($this->pagination->limit)->find(); $this->prepareMessages($mesid); // Run events. $params = new JRegistry(); $params->set('ksource', 'kunena'); $params->set('kunena_view', 'topic'); $params->set('kunena_layout', 'default'); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('kunena'); $dispatcher->trigger('onKunenaPrepare', array('kunena.topic', &$this->topic, &$params, 0)); $dispatcher->trigger('onKunenaPrepare', array('kunena.messages', &$this->messages, &$params, 0)); // Get user data, captcha & quick reply. $this->userTopic = $this->topic->getUserTopic(); $this->captcha = KunenaSpamRecaptcha::getInstance(); $this->quickReply = $this->topic->isAuthorised('reply') && $this->me->exists() && !$this->captcha->enabled(); $this->headerText = JText::_('COM_KUNENA_TOPIC') . ' ' . html_entity_decode($this->topic->displayField('subject')); }