public function __construct()
 {
     gateKeeper();
     $topic = new Forumtopic();
     $topic->title = getInput("title");
     $topic->description = getInput("description");
     $topic->container_guid = getInput("container_guid");
     $topic->save();
     new SystemMessage("Your topic has been posted.");
     new Activity(getLoggedInUserGuid(), "forum:topic:posted", $params = array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $topic->getURL(), $topic->title, getEntity($topic->container_guid)->getURL(), getEntity($topic->container_guid)->title), getInput("container_guid"));
     forward("forum/category/" . getInput("container_guid"));
 }
 private function _isUnread()
 {
     if (Auth::guest()) {
         return false;
     }
     $markAsReadAfter = value(Config::get('forums::forums.mark_as_read_after'));
     if (!IoC::registered('topicsview')) {
         IoC::singleton('topicsview', function () use($markAsReadAfter) {
             return Forumview::where('updated_at', '>=', date('Y-m-d H:i:s', $markAsReadAfter))->where('user_id', '=', Auth::user()->id)->lists('topic_id');
         });
     }
     $tv = IoC::resolve('topicsview');
     $nb = count($tv);
     $view = Forumtopic::where('forumcategory_id', '=', $this->id)->where('updated_at', '>=', date('Y-m-d H:i:s', $markAsReadAfter));
     if ($nb > 0) {
         $view = $view->where_not_in('id', $tv);
     }
     $view = $view->count();
     if ($nb == 0 && $view > 0) {
         return true;
     }
     if ($view > 0) {
         return true;
     }
     return false;
 }
 public function action_index()
 {
     if (Auth::guest()) {
         return Event::first('404');
     }
     $topics = Forumtopic::getPosted();
     return View::make('forums::posted.index', array('topics' => $topics));
 }
 }
 /**
  * Enter description here...
  *
  * @author Povstyanoy
  * @param  array $slugs Array of action unnamed parameters array["pass"];
  * @return array $out
  *
  *         "forum" => id
  *         "topic" => id
  *         "post" => id
  */
 function findIdBySlug($slugs)
 {
     App::import('Model', 'Forumtopic');
     App::import('Model', 'Forumpost');
     $forumtopic = new Forumtopic();
     $forumpost = new Forumpost();
     //$slug = implode("/", $slugs);
     $out = array("Forum" => null, "Topic" => null, "Post" => null);
     if (empty($slugs)) {
         return $out;
     }
     //Find a post
     $post_id = (int) $slugs[count($slugs) - 1];
     // slug contain ID of post
     if ($post_id > 0) {
         // delete post from array
         unset($slugs[count($slugs) - 1]);
         $post = $forumpost->find('first', array('conditions' => array('Forumpost.is_deleted <> 1', 'Forumpost.id' => $post_id)));
         if (!empty($post['Forumpost']['id'])) {
             $out['Post'] = $post['Forumpost']['id'];
         }
     }
     //eof
     //if (!empty($out['Post'])) {
     $topic_slug = $slugs[count($slugs) - 1];
     //} else {
     //	$topic_slug = $slugs[ count($slugs) - 1 ];
     //}
     $forumtopic->contain();
     $topic_id = $forumtopic->find('first', array('conditions' => array('Forumtopic.is_deleted <> 1', 'Forumtopic.slug' => $topic_slug)));
     if (!empty($topic_id)) {
         $out['Topic'] = $topic_id['Forumtopic']['id'];
     }
     if (!empty($out['Topic'])) {
         unset($slugs[count($slugs) - 1]);
     }
     $forum_slug = $slugs[count($slugs) - 1];
     $this->contain();
     $forumbranch = $this->find('first', array('conditions' => array('Forumbranch.is_deleted <> 1', 'Forumbranch.slug' => $forum_slug)));
     if (!empty($forumbranch)) {
         $out['Forum'] = $forumbranch['Forumbranch']['id'];
     }
     return $out;
 public function action_rss()
 {
     $topics = Forumtopic::order_by('updated_at', 'DESC')->take(20)->get();
     return Response::make(View::make('forums::home.rss', array('topics' => $topics)), 200, array('content-type' => 'application/rss+xml'));
 }
 function nation()
 {
     $this->pageTitle = 'BPONG Nation - Beer Pong Tournaments, Beer Pong Forums, Beer Pong Community | BPONG.COM.';
     if (!class_exists("Pongtable")) {
         App::import("Model", "Pongtable");
     }
     if (!class_exists("Image")) {
         App::import("Model", "Image");
     }
     if (!class_exists("Forumtopic")) {
         App::import("Model", "Forumtopic");
     }
     $objTable = new Pongtable();
     $this->set("pongtable", $objTable->getRandomTable());
     $objTopics = new Forumtopic();
     /*
     $objTopics->contain( array("User", "Lastpost" => array("User")) );
     $lastTopics = $objTopics->find("all", array('conditions' => array(
     																		'Forumtopic.deleted IS NULL'
     																		)
     												  	, 'order' => 'Lastpost.id DESC'
     													, 'limit' => 10
     													, 'recursive' => 2));
     */
     $this->set("forumtopics", $objTopics->getLastTopicsForNationPage());
     /**
      * getting blog content
      */
     if (!class_exists("Blogpost")) {
         App::import("Model", "Blogpost");
     }
     $bpObject = new Blogpost();
     $post = $bpObject->find('first', array('recursive' => 0, 'order' => 'Blogpost.created DESC', 'conditions' => array("Blogpost.is_deleted ='0'")));
     $this->set('blogPost', $post);
 }
 /**
  * Generate the sequence of a slug field for nation page!!!
  *
  * @author Povstyanoy
  * @param array $slug
  * @return string
  */
 function generatetopicurl($slug = null)
 {
     $objTopic = new Forumtopic();
     $objTopic->contain();
     $topic = $objTopic->find('first', array('conditions' => array('Forumtopic.slug' => $slug)));
     $objBranch = new Forumbranch();
     $forum_path = $objBranch->getpath($topic['Forumtopic']['forumbranch_id']);
     if (empty($forum_path)) {
         return "";
     }
     $slugs = array();
     foreach ($forum_path as $index => $branch) {
         $slugs[$index] = $branch['Forumbranch']['slug'];
     }
     //last topic is not a link
     array_push($slugs, $slug);
     $forumurl = implode("/", $slugs);
     return $forumurl;
 }
 public function action_postedit($topic_slug, $topic_id, $message_id)
 {
     $topic = Forumtopic::find($topic_id);
     if (is_null($topic)) {
         return Event::first('404');
     }
     $category = $topic->category;
     $message = Forummessage::find($message_id);
     if (is_null($message)) {
         return Event::first('404');
     }
     if ($message->user->id != Auth::user()->id && !Auth::user()->is('Forumer')) {
         return Event::first('404');
     }
     $rules = array('content' => 'required|min:30');
     $content = trim(Input::get('content'));
     $toValidate = compact('content');
     $editTitle = false;
     if ($topic->messages[0]->id == $message->id && trim(Input::get('title')) != $topic->title) {
         $editTitle = true;
         $rules['title'] = 'required|min:2';
         $title = trim(Input::get('title'));
         $toValidate['title'] = $title;
     }
     $validator = Validator::make($toValidate, $rules);
     if ($validator->fails()) {
         return Redirect::back()->with_errors($validator)->with_input();
     }
     if ($editTitle) {
         $topic->title = $toValidate['title'];
         $topic->slug = Str::slug($toValidate['title']);
         $originalSlug = $topic->slug;
         $incSlug = 0;
         do {
             try {
                 $topic->save();
                 $incSlug = 0;
             } catch (Exception $e) {
                 if ($e->getCode() == 23000) {
                     $incSlug++;
                 }
                 $topic->slug = $originalSlug . '-' . $incSlug;
             }
         } while ($incSlug != 0);
     }
     $message->content = BBCodeParser::parse($content);
     $message->content_bbcode = $content;
     $message->save();
     $topic->touch();
     $topic_id = $topic->id;
     $topic_slug = $topic->slug;
     $url = URL::to_action('forums::topic@index', compact('topic_slug', 'topic_id')) . '?page=last#message' . $message->id;
     return Redirect::to($url);
 }