示例#1
0
 function testOnBeforeDelete()
 {
     $thread = new ForumThread();
     $thread->write();
     $post = new Post();
     $post->ThreadID = $thread->ID;
     $post->write();
     $postID = $post->ID;
     $thread->delete();
     $this->assertFalse(DataObject::get_by_id('Post', $postID));
     $this->assertFalse(DataObject::get_by_id('ForumThread', $thread->ID));
 }
 public function storeComment($id)
 {
     $thread = ForumThread::find($id);
     if ($thread == null) {
         Redirect::route('forum')->with('fail', "That thread does not exist.");
     }
     $validator = Validator::make(Input::all(), array('body' => 'required|min:5'));
     if ($validator->fails()) {
         return Redirect::route('forum-thread', $id)->withInput()->withErrors($validator)->with('fail', "Please fill in the form correctly.");
     } else {
         $comment = new ForumComment();
         $comment->body = Input::get('body');
         $comment->author_id = Auth::user()->id;
         $comment->thread_id = $id;
         $comment->category_id = $thread->category->id;
         $comment->group_id = $thread->group->id;
         if ($comment->save()) {
             return Redirect::route('forum-thread', $id)->with('success', "The comment was saved.");
         } else {
             return Redirect::route('forum-thread', $id)->with('fail', "An error occured wile saving.");
         }
     }
 }
 /**
  * Exclude object from result
  *
  * @param     ForumThread $forumThread Object to remove from the list of results
  *
  * @return    ForumThreadQuery The current query, for fluid interface
  */
 public function prune($forumThread = null)
 {
     if ($forumThread) {
         $this->addUsingAlias(ForumThreadPeer::THREAD_ID, $forumThread->getThreadId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
 public function storeThreadComment($id)
 {
     $thread = ForumThread::find($id);
     if ($thread == null) {
         Redirect::route('forum-get-new-comment')->with('fail', "You posted to an invalid thread.");
     }
     $validator = Validator::make(Input::all(), array('body' => 'required|min:3|max:65000'));
     if ($validator->fails()) {
         return Redirect::route('forum-get-new-comment', $id)->withInput()->withErrors($validator)->with('fail', "Your Input doesn't match the requirements!");
     } else {
         $comment = new ForumComment();
         $comment->body = Input::get('body');
         $comment->thread_id = $id;
         $comment->category_id = $thread->category_id;
         $comment->group_id = $thread->group_id;
         $comment->author_id = Auth::user()->id;
         if ($comment->save()) {
             return Redirect::route('forum-thread', $thread->id)->with('success', "Your comment has been added.");
         } else {
             return Redirect::route('forum-get-new-comment', $id)->with('fail', "An error occured while adding your comment")->withInput();
         }
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      ForumThread $value A ForumThread object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(ForumThread $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getThreadId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 public function storeComment($id)
 {
     $thread = ForumThread::find($id);
     if ($thread == null) {
         # code...
         return Redirect::route('forum-thread', $id)->with('fail', "There is nothing to do with this");
     }
     $validator = Validator::make(Input::all(), ['comment' => 'required|min:4|max:65000']);
     if ($validator->fails()) {
         # code...
         return Redirect::route('forum-thread', $id)->withInput()->withErrors($validator)->with('fail', "please fix these errors");
     } else {
         $comment = new ForumComment();
         $comment->body = Input::get('comment');
         $comment->author_id = Auth::user()->id;
         $comment->thread_id = $id;
         $comment->category_id = $thread->category_id;
         $comment->group_id = $thread->group->id;
         if ($comment->save()) {
             # code...
             return Redirect::route('forum-thread', $id)->with('success', "The comment is saved");
         } else {
             return Redirect::route('forum-thread', $id)->with('fail', "An error occured while saving");
         }
     }
 }
 /**
  * Note: See {@link testCanModerate()} for detailed permission tests.
  */
 public function testMarkAsSpamLink()
 {
     $spampost = $this->objFromFixture('Post', 'SpamSecondPost');
     $this->assertFalse($spampost->isFirstPost());
     $forum = $spampost->Forum();
     $author = $spampost->Author();
     $moderator = $this->objFromFixture('Member', 'moderator');
     // moderator for "general" forum
     // without a logged-in moderator
     $this->assertFalse($spampost->MarkAsSpamLink(), 'Link not present by default');
     $c = new Forum_Controller($forum);
     $response = $c->handleRequest(new SS_HTTPRequest('GET', 'markasspam/' . $spampost->ID), DataModel::inst());
     $this->assertEquals(403, $response->getStatusCode());
     // with logged-in moderator
     $moderator->logIn();
     $this->assertNotEquals(false, $spampost->MarkAsSpamLink(), 'Link present for moderators on this forum');
     $this->assertNull($author->SuspendedUntil);
     $c = new Forum_Controller($forum);
     $response = $c->handleRequest(new SS_HTTPRequest('GET', 'markasspam/' . $spampost->ID), DataModel::inst());
     $this->assertFalse($response->isError());
     // removes the post
     $this->assertNull(Post::get()->byID($spampost->ID));
     // suspends the member
     $author = Member::get()->byID($author->ID);
     $this->assertNotNull($author->SuspendedUntil);
     // does not effect the thread
     $thread = ForumThread::get()->byID($spampost->Thread()->ID);
     $this->assertEquals('1', $thread->getNumPosts());
     // mark the first post in that now as spam
     $spamfirst = $this->objFromFixture('Post', 'SpamFirstPost');
     $response = $c->handleRequest(new SS_HTTPRequest('GET', 'markasspam/' . $spamfirst->ID), DataModel::inst());
     // removes the thread
     $this->assertNull(ForumThread::get()->byID($spamfirst->Thread()->ID));
 }
示例#8
0
 public function deleteThread($id)
 {
     $thread = ForumThread::find($id);
     if ($thread == null) {
         return Redirect::route('forum-home')->with('fail', "That thread doesn't exist.");
     }
     $category_id = $thread->category_id;
     $comments = $thread->comments;
     if ($comments->count() > 0) {
         if ($comments->delete() && $thread->delete()) {
             return Redirect::route('forum-category', $category_id)->with('success', "The thread was deleted.");
         } else {
             return Redirect::route('forum-category', $category_id)->with('fail', "An error occured while deleting the thread.");
         }
     } else {
         if ($thread->delete()) {
             return Redirect::route('forum-category', $category_id)->with('success', "The thread was deleted.");
         } else {
             return Redirect::route('forum-category', $category_id)->with('fail', "An error occured while deleting the thread.");
         }
     }
 }
 /** 
  * Are Forum Signatures on Member profiles allowed.
  * This only needs to be checked once, so we cache the initial value once per-request.
  * 
  * @return bool
  */
 function getDisplaySignatures()
 {
     if (isset(self::$_cache_displaysignatures) && self::$_cache_displaysignatures !== null) {
         return self::$_cache_displaysignatures;
     }
     $result = $this->Forum()->Parent()->DisplaySignatures;
     self::$_cache_displaysignatures = $result;
     return $result;
 }
示例#10
0
 /**
  * Post a message to the forum. This method is called whenever you want to make a
  * new post or edit an existing post on the forum
  *
  * @param Array - Data
  * @param Form - Submitted Form
  */
 function doPostMessageForm($data, $form)
 {
     $member = Member::currentUser();
     $content = isset($data['Content']) ? $this->filterLanguage($data["Content"]) : "";
     $title = isset($data['Title']) ? $this->filterLanguage($data["Title"]) : false;
     // If a thread id is passed append the post to the thread. Otherwise create
     // a new thread
     $thread = false;
     if (isset($data['ThreadID'])) {
         $thread = DataObject::get_by_id('ForumThread', $data['ThreadID']);
     }
     // If this is a simple edit the post then handle it here. Look up the correct post,
     // make sure we have edit rights to it then update the post
     $post = false;
     if (isset($data['ID'])) {
         $post = DataObject::get_by_id('Post', $data['ID']);
         if ($post && $post->isFirstPost()) {
             if ($title) {
                 $thread->Title = $title;
             }
         }
     }
     // Check permissions
     $messageSet = array('default' => _t('Forum.LOGINTOPOST', 'You\'ll need to login before you can post to that forum. Please do so below.'), 'alreadyLoggedIn' => _t('Forum.NOPOSTPERMISSION', 'I\'m sorry, but you do not have permission post to this forum.'), 'logInAgain' => _t('Forum.LOGINTOPOSTAGAIN', 'You have been logged out of the forums.  If you would like to log in again to post, enter a username and password below.'));
     // Creating new thread
     if (!$thread && !$this->canPost()) {
         Security::permissionFailure($this, $messageSet);
         return false;
     }
     // Replying to existing thread
     if ($thread && !$post && !$thread->canPost()) {
         Security::permissionFailure($this, $messageSet);
         return false;
     }
     // Editing existing post
     if ($thread && $post && !$post->canEdit()) {
         Security::permissionFailure($this, $messageSet);
         return false;
     }
     if (!$thread) {
         $thread = new ForumThread();
         $thread->ForumID = $this->ID;
         if ($title) {
             $thread->Title = $title;
         }
         $starting_thread = true;
     }
     // from now on the user has the correct permissions. save the current thread settings
     $thread->write();
     if (!$post || !$post->canEdit()) {
         $post = new Post();
         $post->AuthorID = $member ? $member->ID : 0;
         $post->ThreadID = $thread->ID;
     }
     $post->ForumID = $thread->ForumID;
     $post->Content = $content;
     $post->write();
     // Upload and Save all files attached to the field
     // Attachment will always be blank, If they had an image it will be at least in Attachment-0
     if (!empty($data['Attachment'])) {
         $id = 0;
         //
         // @todo this only supports ajax uploads. Needs to change the key (to simply Attachment).
         //
         while (isset($data['Attachment-' . $id])) {
             $image = $data['Attachment-' . $id];
             if ($image) {
                 // check to see if a file of same exists
                 $title = Convert::raw2sql($image['name']);
                 $file = DataObject::get_one("Post_Attachment", "\"Title\" = '{$title}' AND \"PostID\" = '{$post->ID}'");
                 if (!$file) {
                     $file = new Post_Attachment();
                     $file->PostID = $post->ID;
                     $file->OwnerID = Member::currentUserID();
                     $upload = new Upload();
                     $upload->loadIntoFile($image, $file);
                     $file->write();
                 }
             }
             $id++;
         }
     }
     // Add a topic subscription entry if required
     if (isset($data['TopicSubscription'])) {
         if (!ForumThread_Subscription::already_subscribed($thread->ID)) {
             // Create a new topic subscription for this member
             $obj = new ForumThread_Subscription();
             $obj->ThreadID = $thread->ID;
             $obj->MemberID = Member::currentUserID();
             $obj->write();
         }
     } else {
         // See if the member wanted to remove themselves
         if (ForumThread_Subscription::already_subscribed($post->TopicID)) {
             DB::query("DELETE FROM \"ForumThread_Subscription\" WHERE \"ThreadID\" = '{$post->ThreadID}' AND \"MemberID\" = '{$member->ID}'");
         }
     }
     // Send any notifications that need to be sent
     ForumThread_Subscription::notify($post);
     // Send any notifications to moderators of the forum
     if (Forum::$notify_moderators) {
         if (isset($starting_thread) && $starting_thread) {
             $this->notifyModerators($post, $thread, true);
         } else {
             $this->notifyModerators($post, $thread);
         }
     }
     return $this->redirect($post->Link());
 }
 /**
  * Return the GlobalAnnouncements from the individual forums
  *
  * @return DataObjectSet
  */
 function GlobalAnnouncements()
 {
     //dump(ForumHolder::baseForumTable());
     // Get all the forums with global sticky threads
     return ForumThread::get()->filter('IsGlobalSticky', 1)->innerJoin(ForumHolder::baseForumTable(), '"ForumThread"."ForumID"="ForumPage"."ID"', "ForumPage")->where('"ForumPage"."ParentID" = ' . $this->ID)->filterByCallback(function ($thread) {
         if ($thread->canView()) {
             $post = Post::get()->filter('ThreadID', $thread->ID)->sort('Post.Created DESC');
             $thread->Post = $post;
             return true;
         }
     });
 }
 function run($request)
 {
     set_time_limit(0);
     // check to see if this has been run before. If it has then we will have already
     // have removed the parentID field
     $checkForMigration = DB::query("SHOW COLUMNS FROM \"Post\"")->column();
     if (!in_array('ParentID', $checkForMigration)) {
         echo "Script has already ran. You can only run the migration script once.\n";
         return false;
     }
     // go through all the posts with a parent ID = 0 and create the new thread objects
     $oldThreads = DB::query("SELECT * FROM \"Post\" WHERE \"ParentID\" = '0'");
     if ($oldThreads) {
         $toCreateTotal = $oldThreads->numRecords();
         echo "Creating " . $toCreateTotal . " new Forum Threads \n";
         $holder = DataObject::get_one("ForumHolder");
         if (!$holder) {
             return user_error('No Forum Holder Found', E_USER_ERROR);
         }
         $failbackForum = new Forum();
         $failbackForum->Title = "Unimported Threads";
         $failbackForum->ParentID = $holder->ID;
         $failbackForum->write();
         $needsFailback = false;
         $totalThreadsSuccessfulCount = 0;
         $totalThreadsErroredCount = 0;
         while ($oldThread = $oldThreads->nextRecord()) {
             $hasError = false;
             $thread = new ForumThread();
             if (isset($oldThread['Title'])) {
                 $thread->Title = $oldThread['Title'];
             } else {
                 $hasError = true;
                 $thread->Title = "Question";
             }
             $thread->NumViews = isset($oldThread['NumViews']) ? $oldThread['NumViews'] : 0;
             $thread->IsSticky = isset($oldThread['IsSticky']) ? $oldThread['IsSticky'] : false;
             $thread->IsReadOnly = isset($oldThread['IsReadOnly']) ? $oldThread['IsReadOnly'] : false;
             $thread->IsGlobalSticky = isset($oldThread['IsGlobalSticky']) ? $oldThread['IsGlobalSticky'] : false;
             if (isset($oldThread['ForumID'])) {
                 $thread->ForumID = $oldThread['ForumID'];
             } else {
                 $hasError = true;
                 $needsFailback = true;
                 $thread->ForumID = $failbackForum->ID;
             }
             $thread->write();
             echo "Converted Thread: {$thread->ID} - {$thread->Title}. \n";
             // update all the children
             DB::query("\n\t\t\t\t\tUPDATE \"Post\" \n\t\t\t\t\tSET \"ThreadID\" = '{$thread->ID}', \"ForumID\" = '{$thread->ForumID}'\n\t\t\t\t\tWHERE \"TopicID\" = '" . $oldThread['ID'] . "'\n\t\t\t\t");
             if (!$hasError) {
                 $totalThreadsSuccessfulCount++;
             } else {
                 $totalThreadsErroredCount++;
             }
         }
     }
     echo "Converted {$totalThreadsSuccessfulCount} threads. Could not import {$totalThreadsErroredCount} threads.<br />";
     if (!$needsFailback) {
         $failbackForum->delete();
     } else {
         echo "Incorrectly imported threads are available to self moderate at <a href='" . $failbackForum->Link() . "'>here</a><br />";
     }
     // transfer subscriptions
     // was a rename table but mysql had locking issues.
     $subscriptions = DB::query("SELECT * FROM \"Post_Subscription\"");
     $subCount = 0;
     if ($subscriptions) {
         while ($sub = $subscriptions->nextRecord()) {
             // don't import really odd data
             if (isset($sub['TopicID']) && isset($sub['MemberID'])) {
                 $subCount++;
                 $threadSub = new ForumThread_Subscription();
                 $threadSub->ThreadID = $sub['TopicID'];
                 $threadSub->MemberID = $sub['MemberID'];
                 $threadSub->write();
             }
         }
     }
     echo "Transferred {$subCount} Thread Subscriptions<br />";
     // Update the permissions on the forums. The Posters, Viewers have changed from a int field
     // to an actual modelled relationship
     $forums = DataObject::get('Forum');
     if ($forums) {
         foreach ($forums as $forum) {
             $forum->ForumPostersGroupID = DB::query("SELECT \"ForumPostersGroup\" FROM \"Forum\" WHERE \"ID\" = '{$forum->ID}'")->value();
             if ($viewingGroup = DB::query("SELECT \"ForumViewersGroup\" FROM \"Forum\" WHERE \"ID\" = '{$forum->ID}'")->value()) {
                 $forum->ViewerGroups()->add(DataObject::get_by_id('Group', $viewingGroup));
             }
             $forum->write();
         }
     }
     // cleanup task. Delete old columns which are hanging round
     DB::dontRequireField('Post', 'ParentID');
     DB::dontRequireField('Post', 'TopicID');
     DB::dontRequireField('Post', 'Title');
     DB::dontRequireField('Post', 'NumViews');
     DB::dontRequireField('Post', 'IsSticky');
     DB::dontRequireField('Post', 'IsReadOnly');
     DB::dontRequireField('Post', 'IsGlobalSticky');
     DB::dontRequireTable('Post_Subscription');
     DB::dontRequireField('Forum', 'ForumViewersGroup');
     DB::dontRequireField('Forum', 'ForumViewersGroupID');
     DB::dontRequireField("Forum", 'ForumPostersGroup');
     echo "Renamed old data columns in Post and removed Post_Subscription table <br />";
     $this->attachLastPostIDs();
     echo "Set ForumThread last post and update LastEdited to the most recent post <br />";
     echo "Finished<br />";
 }
示例#13
0
 /**
  * Process's the moving of a given topic. Has to check for admin privledges,
  * passed an old topic id (post id in URL) and a new topic id
  */
 function doAdminFormFeatures($data, $form)
 {
     if (isset($data['ID'])) {
         $thread = ForumThread::get()->byID($data['ID']);
         if ($thread) {
             if (!$thread->canModerate()) {
                 return Security::permissionFailure($this);
             }
             $form->saveInto($thread);
             $thread->write();
         }
     }
     return $this->redirect($this->Link());
 }