public function NewBlog()
 {
     //Returns true if the user has no blogs. Returns false otherwise.
     $userID = BusinessLogic_User_User::GetInstance()->GetUserID();
     $query = 'select Count(*) from [0] where UserID=[1] AND Auth="Owner"';
     $arguments = array('User_Auth', $userID);
     $DataAccess = DataAccess_DataAccessFactory::GetInstance();
     $result = $DataAccess->Select($query, $arguments);
     $numOfBlogs = $result[0]["Count(*)"];
     return $numOfBlogs == 0;
 }
 public function __construct($blogID, $postID, $authorID, $title, $public, $timestamp, $content)
 {
     $this->blogID = $blogID;
     $this->postID = $postID;
     $this->authorID = $authorID;
     $this->authorName = BusinessLogic_User_User::ConvertUserIDToName($authorID);
     $this->title = $title;
     $this->public = $public;
     $this->timestamp = $timestamp;
     $this->content = $content;
     $this->showcontrols = false;
 }
 public function __construct($blogID, $postID, $commentID, $authorID, $title, $timestamp, $content)
 {
     $this->blogID = $blogID;
     $this->postID = $postID;
     $this->commentID = $commentID;
     $this->authorID = $authorID;
     $this->authorName = BusinessLogic_User_User::ConvertUserIDToName($authorID);
     $this->title = $title;
     $this->timestamp = $timestamp;
     $this->content = $content;
     $this->controls = '';
     $this->linkprefix = explode('?', $_SERVER['REQUEST_URI'], 2);
     $this->linkprefix = $this->linkprefix[0];
 }
 public function ActivateControls($commentCollectionView, $blogID)
 {
     $permission = BusinessLogic_User_User::GetInstance()->GetPermissionForBlog($blogID);
     //Depending on the user's permission level, adds controls to posts that should have them.
     if ($permission == "Nobody" or $permission == "Author") {
         foreach ($commentCollectionView->GetComments() as $key => $value) {
             $value->SetControls(false);
         }
     } else {
         foreach ($commentCollectionView->GetComments() as $key => $value) {
             $value->SetControls(true);
         }
     }
 }
 public function ViewDashboard($userID)
 {
     $user = BusinessLogic_User_User::GetInstance();
     $DataAccess = DataAccess_DataAccessFactory::GetInstance();
     $ViewDashboardView = new Presentation_View_ViewDashboardView();
     //Get Invitations
     $query = 'select * from [0] where UserID="[1]"';
     $arguments = array('Invitations', $user->GetUserID());
     $invitationsResult = $DataAccess->Select($query, $arguments);
     if (count($invitationsResult) > 0) {
         $aViewDashboardInvitationCollectionView = new Presentation_View_ViewDashboardInvitationCollectionView();
         foreach ($invitationsResult as $key => $value) {
             $query = 'select Title from [0] where BlogID="[1]"';
             $arguments = array('Blogs', $value['BlogID']);
             $result = $DataAccess->Select($query, $arguments);
             $cBlogID = $_GET['blogID'];
             $blogID = $value['BlogID'];
             $rank = $value['Rank'];
             $title = $result[0]['Title'];
             $aViewDashboardInvitationCollectionView->AddView(new Presentation_View_ViewDashboardInvitationView($cBlogID, $blogID, $title, $rank));
         }
         $ViewDashboardView->AddView($aViewDashboardInvitationCollectionView);
     }
     //Get Associated Blog Information
     $query = 'select BlogID, Auth from [0] where UserID="[1]"';
     $arguments = array('User_Auth', $user->GetUserID());
     $associatedBlogResult = $DataAccess->Select($query, $arguments);
     $aViewAssociatedBlogCollectionView = new Presentation_View_ViewAssociatedBlogCollectionView(!$user->IsUserBlogOwner(), $_REQUEST['blogID']);
     if (count($associatedBlogResult) > 0) {
         foreach ($associatedBlogResult as $key => $value) {
             $query = 'select Title from [0] where BlogID="[1]"';
             $arguments = array('Blogs', $value['BlogID']);
             $result = $DataAccess->Select($query, $arguments);
             $cBlogID = $_GET['blogID'];
             $blogID = $value['BlogID'];
             $rank = $value['Auth'];
             $title = $result[0]['Title'];
             $aViewAssociatedBlogCollectionView->AddView(new Presentation_View_ViewAssociatedBlogView($cBlogID, $blogID, $title, $rank));
         }
     }
     $ViewDashboardView->AddView($aViewAssociatedBlogCollectionView);
     return $ViewDashboardView;
 }
示例#6
0
 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();
     }
 }
 public function ActivateControlsSingle($postView, $blogID, $permission)
 {
     //Same as above, except for a single ViewPostView rather than a ViewPostCollectionView.
     if ($permission == "Nobody") {
         return;
     } elseif ($permission == "Author") {
         $postView->GetPost()->ActivateControls($postView->GetPost()->GetAuthorID() == BusinessLogic_User_User::GetInstance()->GetUserID());
     } else {
         $postView->GetPost()->ActivateControls(true);
     }
 }
示例#8
0
 public function ProcessNewBlog($title, $about, $theme, $headerimg, $footerimg)
 {
     //Calls BlogSecurity to determine if the user can create a new blog. If so, it will process the form data in NewBlogView and call BlogDataAccess.ProcessNewBlog() to commit the new data to storage, and call User.NewBlog to add the user as an owner for this blog. Otherwise, an exception is thrown. Returns the blog ID of the new blog.
     if (!BusinessLogic_Blog_BlogSecurity::GetInstance()->ProcessNewBlog()) {
         throw new Exception('You are already the owner of another blog, you may not own two blogs at once.');
     }
     $newblogID = BusinessLogic_Blog_BlogDataAccess::GetInstance()->ProcessNewBlog($title, $about, $theme, $headerimg, $footerimg);
     BusinessLogic_User_User::GetInstance()->NewBlog($newblogID);
     return $newblogID;
 }
示例#9
0
 public function HandleRequest()
 {
     //Checks $_GET['action'] to see if the action belongs to the Comment class. If so, the appropriate function is called. Otherwise, User.HandleRequest() is called.
     $request = $_GET['Action'];
     $blogID = $_GET['blogID'];
     switch ($request) {
         case 'ProcessNewComment':
             $authorID = BusinessLogic_User_User::GetInstance()->GetUserID();
             $title = substr($_POST['title'], 0, 30);
             $errmsg = '';
             if (strlen($title) < 1) {
                 $errmsg .= 'Comment title cannot be empty. ';
             }
             if (strlen($_POST['content']) < 1) {
                 $errmsg .= 'Comment content cannot be empty. ';
             }
             if (strlen($_POST['postID'] < 1)) {
                 throw new Exception("PostID must be set.");
             }
             if (strlen($errmsg) > 0) {
                 return $this->NewComment($blogID, $_POST['postID'], $title, $_POST['content'], $errmsg);
             }
             //__construct($blogID, $postID, $commentID, $authorID, $title, $timestamp, $content)
             $view = new Presentation_View_ViewCommentView($blogID, $_POST['postID'], 0, $authorID, $title, 0, $_POST['content']);
             $this->ProcessNewComment($view);
             //forward user to viewing the post:
             $path = $_SERVER['DIRECTORY_ROOT'] . 'index.php?Action=ViewPost&blogID=' . $blogID . '&postID=' . $_POST['postID'];
             header("Location: {$path}");
             exit;
         case 'EditComment':
             $commentID = $_GET['commentID'];
             return $this->EditComment($blogID, $commentID, '', '', '');
             break;
         case 'ProcessEditComment':
             $authorID = BusinessLogic_User_User::GetInstance()->GetUserID();
             $title = substr($_POST['title'], 0, 30);
             $errmsg = '';
             if (strlen($title) < 1) {
                 $errmsg .= 'Comment title cannot be empty. ';
             }
             if (strlen($_POST['content']) < 1) {
                 $errmsg .= 'Comment content cannot be empty. ';
             }
             if (strlen($_POST['commentID'] < 1)) {
                 throw new Exception("CommentID must be set.");
             }
             if (strlen($errmsg) > 0) {
                 return $this->EditComment($blogID, $_POST['commentID'], $title, $_POST['content'], $errmsg);
             }
             $view = new Presentation_View_ViewCommentView($blogID, 0, $_POST['commentID'], $authorID, $title, 0, $_POST['content']);
             $this->ProcessEditComment($view);
             //forward user to viewing the post:
             $path = $_SERVER['DIRECTORY_ROOT'] . 'index.php?Action=ViewPost&blogID=' . $blogID . '&postID=' . $_POST['postID'];
             #header("Location: $path");
             #exit;
             break;
             //TODO: fix this when done
         //TODO: fix this when done
         case 'DeleteComment':
             $commentID = $_GET['commentID'];
             $comment = $this->DeleteComment($blogID, $commentID);
             return $comment;
             break;
         case 'ProcessDeleteComment':
             $commentID = $_POST['commentID'];
             if (strlen($commentID < 1)) {
                 throw new Exception("CommentID must be set.");
             }
             $this->ProcessDeleteComment($blogID, $commentID);
             //forward user to viewing the post:
             $path = $_SERVER['DIRECTORY_ROOT'] . 'index.php?Action=ViewPost&blogID=' . $blogID . '&postID=' . $_POST['postID'];
             header("Location: {$path}");
             exit;
         default:
             throw new Exception('Unknown Request.');
     }
 }