public function Display() { if (is_array($this->comments)) { $ret = '<div id="commentcollection">'; foreach ($this->comments as $value) { $ret .= $value->Display() . "\n"; } $ret .= '</div>'; return $ret; } elseif (!isset($this->comments)) { $ret = 'No Comments Posted Yet.'; try { //try to show a new comment form at end of list of comments: $ret = $ret . BusinessLogic_Comment_Comment::GetInstance()->NewComment($blogID, $postID); } catch (Exception $e) { //don't show new comment form if user lacks permission } return $ret; } else { throw new Exception("Contents of ViewCommentCollectionView must either be an array or unset."); } }
public function HandleRequest() { //Checks $_GET['Action'] to see if the action belongs to the Post class. If so, the appropriate function is called. Otherwise, Comment.HandleRequest() is called. $request = $_GET['Action']; $blogID = $_GET['blogID']; switch ($request) { case 'ViewPost': if (isset($_GET['postID'])) { return $this->ViewPostsByID($blogID, $_GET['postID']); } elseif (isset($_GET['date'])) { return $this->ViewPostsByDay($blogID, $_GET['year'], $_GET['month'], $_GET['date']); } elseif (isset($_GET['month'])) { return $this->ViewPostsByMonth($blogID, $_GET['year'], $_GET['month']); } elseif (isset($_GET['age'])) { $age = $_GET['age']; if ($age > 100) { $age = 100; } return $this->ViewPostsByDaysOld($blogID, $age); } elseif (isset($_GET['count'])) { $count = $_GET['count']; if ($count > 100) { $count = 100; } return $this->ViewPostsByRecentCount($blogID, $count); } else { //FALLBACK: default return count 10 return $this->ViewPostsByRecentCount($blogID, 10); } break; case 'NewPost': return $this->NewPost($blogID, '', '', true, ''); break; case 'ProcessNewPost': $authorID = BusinessLogic_User_User::GetInstance()->GetUserID(); $public = $_POST['public'] == 'on'; $errmsg = ''; $title = substr($_POST['title'], 0, 30); if (strlen($title) < 1) { $errmsg .= 'Post title cannot be empty. '; } if (strlen($_POST['content']) < 1) { $errmsg .= 'Post content cannot be empty. '; } if (strlen($errmsg) > 0) { return $this->NewPost($blogID, $title, $_POST['content'], $public, $errmsg); } $view = new Presentation_View_ViewPostView($blogID, 0, $authorID, $title, $public, 0, $_POST['content']); $this->ProcessNewPost($view); //forward user to viewing the blog that the post was just made in: $path = $_SERVER['DIRECTORY_ROOT'] . 'index.php?Action=ViewBlog&blogID=' . $blogID; header("Location: {$path}"); exit; case 'EditPost': $postID = $_GET['postID']; //2 = dont modify post's current public status return $this->EditPost($blogID, $postID, '', '', 2, ''); break; case 'ProcessEditPost': $authorID = BusinessLogic_User_User::GetInstance()->GetUserID(); $public = $_POST['public'] == 'on'; $errmsg = ''; if (strlen($_POST['title']) < 1) { $errmsg .= 'Post title cannot be empty. '; } if (strlen($_POST['content']) < 1) { $errmsg .= 'Post content cannot be empty. '; } if (strlen($_POST['postID'] < 1)) { throw new Exception("PostID must be set."); } $title = substr($_POST['title'], 0, 30); if (strlen($errmsg) > 0) { return $this->EditPost($blogID, $_POST['postID'], $title, $_POST['content'], $public, $errmsg); } $view = new Presentation_View_ViewPostView($blogID, $_POST['postID'], $authorID, $title, $public, 0, $_POST['content']); $updateTimestamp = $_POST['timestamp'] == 'now'; $this->ProcessEditPost($view, $updateTimestamp); //forward user to viewing newly edited post: $path = $_SERVER['DIRECTORY_ROOT'] . 'index.php?Action=ViewPost&blogID=' . $blogID . '&postID=' . $_POST['postID']; header("Location: {$path}"); exit; case 'DeletePost': $postID = $_GET['postID']; return $this->DeletePost($blogID, $postID); break; case 'ProcessDeletePost': $postID = $_POST['postID']; if (strlen($postID < 1)) { throw new Exception("PostID must be set."); } $this->ProcessDeletePost($blogID, $postID); //forward user to viewing posts in blog: $path = $_SERVER['DIRECTORY_ROOT'] . 'index.php?Action=ViewBlog&blogID=' . $blogID; header("Location: {$path}"); exit; default: return BusinessLogic_Comment_Comment::GetInstance()->HandleRequest(); } }