Exemplo n.º 1
0
 public function index()
 {
     $P = PVars::getObj('page');
     $vw = new ViewWrap($this->_view);
     $cw = new ViewWrap($this);
     // index is called when http request = ./blog
     if (PPostHandler::isHandling()) {
         return;
     }
     $request = PRequest::get()->request;
     $member = $this->_model->getLoggedInMember();
     //$User = A PP_User::login();
     if (!isset($request[1])) {
         $request[1] = '';
     }
     // user bar
     // show the userbar always for now:
     /*if ($User && $request[1] != 'tags') { */
     //            $P->newBar .= $vw->userbar();
     /*} */
     $bloguser = 0;
     $RSS = false;
     switch ($request[1]) {
         case 'ajax':
             if (!isset($request[2])) {
                 PPHP::PExit();
             }
             switch ($request[2]) {
                 case 'post':
                     $this->ajaxPost();
                     break;
             }
             break;
         case 'suggestTags':
             // ignore current request, so we can use the last request
             PRequest::ignoreCurrentRequest();
             if (!isset($request[2])) {
                 PPHP::PExit();
             }
             $new_tags = $this->_model->suggestTags($request[2]);
             echo $this->_view->generateClickableTagSuggestions($new_tags);
             PPHP::PExit();
             break;
         case 'suggestLocation':
             // ignore current request, so we can use the last request
             PRequest::ignoreCurrentRequest();
             if (!isset($request[2])) {
                 PPHP::PExit();
             }
             $locations = $this->_model->suggestLocation($request[2]);
             echo $this->_view->generateLocationOverview($locations);
             PPHP::PExit();
             break;
         case 'create':
             if (!$member) {
                 PRequest::home();
             }
             if (isset($request[2]) && $request[2] == 'finish' && isset($request[3]) && $this->_model->isPostId($request[3])) {
                 $page = new BlogSinglePostPage($this->_model);
                 $page->member = $member;
                 $page->post = $this->_model->getPost($request[3]);
             } else {
                 $page = new BlogCreatePage($this->_model);
             }
             return $page;
         case 'del':
             if (!$member || !isset($request[2]) || !$this->_model->isUserPost($member->id, $request[2])) {
                 PRequest::home();
             }
             $post = $this->_model->getPost($request[2]);
             $p = new BlogDeletePage($this->_model);
             $p->member = $member;
             $p->post = $post;
             return $p;
         case 'edit':
             if (!$member || !isset($request[2]) || !$this->_model->isUserPost($member->id, $request[2])) {
                 PRequest::home();
             }
             if (isset($request[3]) && $request[3] == 'finish') {
                 $p = new BlogSinglePostPage($this->_model);
                 $p->member = $member;
                 $p->post = $this->_model->getPost($request[2]);
                 return $p;
             } else {
                 //$callbackId = $this->editProcess((int)$request[2]);
                 //$vars =& PPostHandler::getVars($callbackId);
                 if (!isset($vars['errors']) || !is_array($vars['errors'])) {
                     $vars['errors'] = array();
                 }
                 $this->_editFill($request[2], $vars);
                 $p = new BlogEditPage($this->_model);
                 $p->post = $this->_model->getPost($request[2]);
                 $p->member = $member;
                 $p->vars = $vars;
                 return $p;
                 $P->content .= $vw->editForm((int) $request[2], $callbackId);
             }
             break;
         case 'search':
             if (!empty($this->args_vars->get['s']) && strlen($this->args_vars->get['s']) >= 3) {
                 $search = $this->args_vars->get['s'];
                 $tagsposts = $this->_model->getTaggedPostsIt($search);
                 $posts = $this->_model->searchPosts($search);
             } else {
                 $error = 'To few arguments';
                 $posts = false;
                 $tagsposts = false;
                 $search = '';
             }
             $p = new BlogSearchPage($this->_model);
             $p->posts = $posts;
             $p->tagged_posts = $tagsposts;
             $p->search = $search;
             return $p;
             $P->content .= $vw->searchPage($posts, $tagsposts);
             break;
             /* removed - references user app
                         case 'settings':
                             $p = new BlogSettingsPage($this->_model);
                             return $p;
                             $P->content .= $vw->settingsForm();
                             break;
             */
         /* removed - references user app
                     case 'settings':
                         $p = new BlogSettingsPage($this->_model);
                         return $p;
                         $P->content .= $vw->settingsForm();
                         break;
         */
         case 'tags':
             $p = new BlogTagsPage($this->_model);
             $p->tag = isset($request[2]) ? $request[2] : false;
             return $p;
             $P->content .= $vw->tags(isset($request[2]) ? $request[2] : false);
             break;
         case 'cat':
             $p = new BlogCategoriesPage($this->_model);
             return $p;
             break;
         default:
             $page = isset($this->args_vars->get['page']) && intval($this->args_vars->get['page']) ? intval($this->args_vars->get['page']) : 1;
             // display blogs of user $request[1]
             $memberBlog = $this->_model->getMemberByUsername($request[1]);
             if ($memberBlog) {
                 if (!isset($request[2])) {
                     $request[2] = '';
                 }
                 switch ($request[2]) {
                     case 'cat':
                         if (isset($request[3])) {
                             $p = new BlogPage($this->_model);
                             $p->page = $page;
                             $p->category = $request[3];
                             $p->member = $memberBlog;
                             $p->initPager($this->_model->countRecentPosts($memberBlog->id, $request[3]), $page);
                             $p->posts = $this->_model->getRecentPostsArray($memberBlog->id, $request[3], $page);
                             break;
                         }
                         // if we're not dealing with a category, fall through and hit the default
                     // if we're not dealing with a category, fall through and hit the default
                     case '':
                     default:
                         // show different blog layout for public visitors
                         if ($post = $this->_model->getPost($request[2])) {
                             $p = new BlogSinglePostPage($this->_model);
                             $p->member = $memberBlog;
                             $p->post = $post;
                         } else {
                             $p = new BlogPage($this->_model);
                             $p->page = $page;
                             $p->member = $memberBlog;
                             $p->initPager($this->_model->countRecentPosts($memberBlog->id, false), $page);
                             $p->posts = $this->_model->getRecentPostsArray($memberBlog->id, false, $page);
                         }
                         break;
                 }
             } else {
                 $p = new BlogPage($this->_model);
                 $p->page = $page;
                 $p->initPager($this->_model->countRecentPosts(false, false), $page);
                 $p->posts = $this->_model->getRecentPostsArray(false, false, $page);
             }
             return $p;
     }
 }
Exemplo n.º 2
0
 public function index()
 {
     // index is called when http request = ./trip
     $request = PRequest::get()->request;
     if (!isset($request[1])) {
         $request[1] = '';
     }
     // Enable ViewWrap for cleaner code
     $P = PVars::getObj('page');
     $vw = new ViewWrap($this->_view);
     // Show the teaser
     $this->showTeaser();
     // then include the col2-stylesheet
     $P->addStyles .= $vw->customStyles();
     $member = $this->_model->getLoggedInMember();
     switch ($request[1]) {
         case 'create':
             if (!$member) {
                 return false;
             }
             $P->content .= $vw->createForm();
             break;
         case 'show':
             if (isset($request[2]) && $request[2]) {
                 if ($request[2] == 'my') {
                     $this->showMyTrips();
                 } else {
                     $this->showTrips($request[2]);
                 }
             } else {
                 $this->showAllTrips();
             }
             break;
         case 'search':
             if (isset($_GET['s'])) {
                 $search = $_GET['s'];
                 if (strlen($_GET['s']) >= 3) {
                     //$tagsposts = $this->_model->getTaggedPostsIt($search);
                     $trip_data = $this->_model->getTripsDataForLocation($search);
                     $trips = $this->_model->getTripsForLocation();
                 } else {
                     $error = 'To few arguments';
                     $trip_data = array();
                     $trips = false;
                     //$tagsposts = false;
                 }
                 $P->content .= $vw->searchPage($trips, $trip_data);
             }
             break;
         case 'reorder':
             $this->reorder($_GET['triplist']);
             break;
         case 'edit':
             if (isset($request[2]) && $request[2]) {
                 $this->editTrip((int) $request[2]);
                 break;
             }
         case 'del':
             if (isset($request[2]) && $request[2]) {
                 $this->delTrip((int) $request[2]);
                 break;
             }
         default:
             if (intval($request[1])) {
                 return $this->showTrip($request[1]);
             } else {
                 if ($member) {
                     $this->showAllTrips();
                 } else {
                     $this->notLoggedIn();
                 }
                 break;
             }
     }
     // Show the user functions in the sidebar
     $P->newBar .= $vw->userbar();
 }