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); }
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 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); }
/** * 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); }