Ejemplo n.º 1
0
 /**
  * Method for submitting the post. Note AJAX suffix so it can take advantage of com_ajax
  *
  * @return   array  The details of the post created.
  *
  * @since   __DEPLOY_VERSION__
  * @throws  RuntimeException
  */
 public static function submitAjax()
 {
     $app = JFactory::getApplication();
     $post = $app->input->post->get('jjshout', array(), 'array');
     // Retrieve relevant parameters
     if (!isset($post['title'])) {
         throw new RuntimeException("Couldn't assemble the necessary parameters for the module");
     }
     $helper = new ModShoutboxHelper($post['title']);
     $helper->ajax = true;
     // Make sure someone pressed shout and the post message isn't empty
     if (!isset($post['shout'])) {
         throw new RuntimeException('There was an error processing the form.');
     }
     if (empty($post['message'])) {
         throw new InvalidArgumentException('The message body is empty');
     }
     $id = $helper->submitPost($post);
     $shout = $helper->getAShout($id);
     $htmlOutput = $helper->renderPost($shout);
     // Return the HTML represetation, the id and the message contents
     $result = array('html' => $htmlOutput, 'id' => $id, 'message' => $shout->msg);
     return $result;
 }