Example #1
0
 /**
  * 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);
 }