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; } }