Example #1
0
 public function index()
 {
     $type = Param::get('type', self::TYPE_THREAD);
     $query = trim_collapse(Param::get('query'));
     $page = Param::get('page', 1);
     $pagination = new SimplePagination($page, self::RESULTS_PERPAGE);
     if (!$query) {
         redirect(APP_URL);
     }
     $results = new stdClass();
     switch ($type) {
         case self::TYPE_THREAD:
             $results = Thread::search($query, $pagination->start_index - 1, $pagination->count + 1);
             // Get other info for each thread
             foreach ($results->result as $thread) {
                 $thread->creator = User::getByID($thread->user_id);
                 $thread->category = Category::getName($thread->category_id);
                 $thread->replies_count = Comment::countAll($thread->id);
             }
             break;
         case self::TYPE_COMMENT:
             $results = Comment::search($query, $pagination->start_index - 1, $pagination->count + 1);
             break;
         case self::TYPE_USER:
             $results = User::search($query, $pagination->start_index - 1, $pagination->count + 1);
             break;
         default:
             throw new PageNotFoundException();
             break;
     }
     $pagination->checkLastPage($results->result);
     $pages = ceil($results->total_result / self::RESULTS_PERPAGE);
     $title = "Search: '{$query}'";
     $this->set(get_defined_vars());
 }
Example #2
0
 public function edit()
 {
     redirect_guest_user(LOGIN_URL);
     $page = Param::get('page_next', 'edit');
     $thread = Thread::get(Param::get('id'));
     $comment = Comment::getFirstInthread($thread);
     $auth_user = User::getAuthenticated();
     if (!$thread->isAuthor($auth_user)) {
         throw new PermissionException();
     }
     switch ($page) {
         case 'edit':
             break;
         case 'edit_end':
             $thread->title = trim_collapse(Param::get('title'));
             $thread->category_id = Param::get('category');
             $comment->body = trim(Param::get('body'));
             try {
                 $thread->update($comment);
                 redirect(VIEW_THREAD_URL, array('id' => $thread->id));
             } catch (ValidationException $e) {
                 $page = 'edit';
             } catch (CategoryException $e) {
                 $thread->validation_errors['category']['exists'] = true;
                 $page = 'edit';
             }
             break;
         default:
             throw new PageNotFoundException();
             break;
     }
     // set other variables needed by the view
     $categories = Category::getAll();
     $title = 'Edit thread';
     $this->set(get_defined_vars());
     $this->render($page);
 }
Example #3
0
 public function edit()
 {
     redirect_guest_user(LOGIN_URL);
     $page = Param::get('page_next', 'edit');
     $auth_user = User::getAuthenticated();
     switch ($page) {
         case 'edit':
             break;
         case 'edit_end':
             $auth_user->first_name = trim_collapse(Param::get('first_name'));
             $auth_user->last_name = trim_collapse(Param::get('last_name'));
             $auth_user->current_password = Param::get('password');
             $auth_user->new_password = Param::get('new_password');
             try {
                 $auth_user->update();
             } catch (ValidationException $e) {
                 $page = 'edit';
                 break;
             }
             break;
         default:
             throw new PageNotFoundException();
             break;
     }
     $title = 'Edit Profile';
     $this->set(get_defined_vars());
     $this->render($page);
 }