public function displayCaptcha() { return KunenaCaptcha::display(); }
public function post() { $this->id = JRequest::getInt('parentid', 0); $app = JFactory::getApplication (); if (! JRequest::checkToken ()) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' ); $this->redirectBack (); } if (! KunenaCaptcha::verify () ) { $this->redirectBack (); } $fields = array ( '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 )); if (!$this->id) { $category = KunenaForumCategoryHelper::get($this->catid); if (!$category->authorise('topic.create')) { $app->enqueueMessage ( $category->getError(), 'notice' ); $this->redirectBack (); } $fields['icon_id'] = JRequest::getInt ( 'topic_emoticon', 0 ); list ($topic, $message) = $category->newTopic($fields); } else { $parent = KunenaForumMessageHelper::get($this->id); if (!$parent->authorise('reply')) { $app->enqueueMessage ( $parent->getError(), 'notice' ); $this->redirectBack (); } list ($topic, $message) = $parent->newReply($fields); $category = $topic->getCategory(); } // Flood protection if ($this->config->floodprotection && ! KunenaFactory::getUser()->isModerator($category->id)) { $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) { $app->enqueueMessage ( JText::sprintf ( 'COM_KUNENA_POST_TOPIC_FLOOD', $this->config->floodprotection) ); $this->redirectBack (); } } // If requested: Make message to be anonymous if (JRequest::getInt ( 'anonymous', 0 ) && $message->getCategory()->allow_anonymous) { $message->makeAnonymous(); } // 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) { $app->enqueueMessage ( $message->getError (), 'error' ); $this->redirectBack (); } // Display possible warnings (upload failed etc) foreach ( $message->getErrors () as $warning ) { $app->enqueueMessage ( $warning, 'notice' ); } // Create Poll $polltitle = JRequest::getString ( 'poll_title', '' ); $polloptions = JRequest::getVar('polloptionsID', array (), 'post', 'array'); //$optionsnumbers = JRequest::getInt ( 'number_total_options', '' ); if (! empty ( $polloptions ) && ! empty ( $polltitle )) { if ($topic->authorise('poll.create', null, false)) { $poll = $topic->getPoll(); $poll->title = $polltitle; $poll->polltimetolive = JRequest::getString ( 'poll_time_to_live', 0 ); $poll->setOptions($polloptions); if (!$poll->save()) { $app->enqueueMessage ( $poll->getError(), 'notice' ); } else { $topic->poll_id = $poll->id; $topic->save(); $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POLL_CREATED' ) ); } } else { $app->enqueueMessage ( $topic->getError(), 'notice' ); } } // Update Tags $globalTags = JRequest::getString ( 'tags', null ); $userTags = JRequest::getString ( 'mytags', null ); $this->updateTags($message->thread, $globalTags, $userTags); $message->sendNotification(); //now try adding any new subscriptions if asked for by the poster if (JRequest::getInt ( 'subscribeMe', 0 )) { if ($topic->subscribe(1)) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUBSCRIBED_TOPIC' ) ); // Activity integration $activity = KunenaFactory::getActivityIntegration(); $activity->onAfterSubscribe($topic, 1); } else { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_NO_SUBSCRIBED_TOPIC' ) ); } } if ($message->hold == 1) { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUCCES_REVIEW' ) ); } else { $app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUCCESS_POSTED' ) ); } $app->redirect ( CKunenaLink::GetMessageURL ( $message->id, $this->return, 0, false ) ); }