get() 공개 메소드

public get ( $key )
 protected function getOrCreateComment($wordpressID)
 {
     if ($wordpressID && ($comment = Comment::get()->filter(array('WordpressID' => $wordpressID))->first())) {
         return $comment;
     }
     return Comment::create();
 }
예제 #2
0
 /**
  * Delete Comment using Username
  */
 public function delete()
 {
     $comment_id = Param::get('comment_id');
     $comment = Comment::get(Param::get('comment_id'));
     $page = Param::get('page_next', 'delete');
     $status = "";
     switch ($page) {
         case 'delete':
             break;
         case 'delete_end':
             try {
                 if (Param::get('reply') == 'no') {
                     redirect(url('thread/index'));
                 } else {
                     $comment->delete($_SESSION['username']);
                 }
             } catch (ValidationException $e) {
                 $status = notify($e->getMessage(), "error");
                 $page = 'delete';
             }
             break;
         default:
             throw new PageNotFoundException("{$page} is not found");
             break;
     }
     $this->set(get_defined_vars());
     $this->render($page);
 }
예제 #3
0
 /**
  * @return Form
  */
 public function getEditForm($id = null, $fields = null)
 {
     if (!$id) {
         $id = $this->currentPageID();
     }
     $form = parent::getEditForm($id);
     $record = $this->getRecord($id);
     if ($record && !$record->canView()) {
         return Security::permissionFailure($this);
     }
     $newComments = Comment::get()->filter('Moderated', 0);
     $newGrid = new CommentsGridField('NewComments', _t('CommentsAdmin.NewComments', 'New'), $newComments, CommentsGridFieldConfig::create());
     $approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0);
     $approvedGrid = new CommentsGridField('ApprovedComments', _t('CommentsAdmin.ApprovedComments', 'Approved'), $approvedComments, CommentsGridFieldConfig::create());
     $spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1);
     $spamGrid = new CommentsGridField('SpamComments', _t('CommentsAdmin.SpamComments', 'Spam'), $spamComments, CommentsGridFieldConfig::create());
     $newCount = '(' . count($newComments) . ')';
     $approvedCount = '(' . count($approvedComments) . ')';
     $spamCount = '(' . count($spamComments) . ')';
     $fields = new FieldList($root = new TabSet('Root', new Tab('NewComments', _t('CommentAdmin.NewComments', 'New') . ' ' . $newCount, $newGrid), new Tab('ApprovedComments', _t('CommentAdmin.ApprovedComments', 'Approved') . ' ' . $approvedCount, $approvedGrid), new Tab('SpamComments', _t('CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount, $spamGrid)));
     $root->setTemplate('CMSTabSet');
     $actions = new FieldList();
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->addExtraClass('cms-edit-form');
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
         $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
     }
     $this->extend('updateEditForm', $form);
     return $form;
 }
 /**
  * Uses $this->owner->request (a {@link SS_HTTPRequest} object) to determine which comment we want to unsubscribe
  * the member from. If the current user isn't logged in, or is logged in as a different user, then we send them to
  * the login screen.
  */
 public function unsubscribenotification()
 {
     $request = $this->owner->getRequest();
     $commentID = $request->param('ID');
     $member = Member::currentUser();
     if (!$commentID) {
         $this->owner->httpError(403);
         return;
     }
     $comment = Comment::get()->byID($commentID);
     if (!$comment) {
         $this->owner->httpError(403);
         return;
     }
     if (!$member || $member->ID != $comment->AuthorID) {
         return Security::permissionFailure($this->owner, array('default' => _t('CommentingControllerUserNotificationsExtension.DEFAULTFAIL', 'You must login to unsubscribe.'), 'alreadyLoggedIn' => _t('CommentingControllerUserNotificationsExtension.ALREADYLOGGEDINFAIL', 'You must login as the correct user (the user who submitted the comment) to continue.'), 'logInAgain' => _t('CommentingControllerUserNotificationsExtension.LOGINAGAINFAIL', 'You have been logged out. If you would like to login again, enter your credentials below.')));
     }
     // Currently logged in Member's ID matches the author of the comment, so we can unsubscribe them
     // We want to find all comments posted to this object by this author, and unsubscribe all of them.
     $allComments = Comment::get()->filter(array('BaseClass' => $comment->BaseClass, 'ParentID' => $comment->ParentID, 'NotifyOfUpdates' => true));
     foreach ($allComments as $c) {
         $c->NotifyOfUpdates = false;
         $c->write();
     }
     // This sets a session var that can be queried on the page that we redirect the user back to, so that we can
     // display a nice message to let the user know their unsubscription was successful.
     Session::set('CommentUserNotificationsUnsubscribed', '1');
     $this->owner->redirectBack();
 }
 /**
  * Return an RSS feed of comments for a given set of comments or all 
  * comments on the website.
  *
  * To maintain backwards compatibility with 2.4 this supports mapping
  * of PageComment/rss?pageid= as well as the new RSS format for comments
  * of CommentingController/rss/{classname}/{id}
  *
  * @return RSS
  */
 public function rss()
 {
     $link = $this->Link('rss');
     $class = $this->urlParams['ID'];
     $id = $this->urlParams['OtherID'];
     if (isset($_GET['pageid'])) {
         $id = Convert::raw2sql($_GET['pageid']);
         $comments = Comment::get()->where(sprintf("BaseClass = 'SiteTree' AND ParentID = '%s' AND Moderated = 1 AND IsSpam = 0", $id));
         $link = $this->Link('rss', 'SiteTree', $id);
     } else {
         if ($class && $id) {
             if (Commenting::has_commenting($class)) {
                 $comments = Comment::get()->where(sprintf("BaseClass = '%s' AND ParentID = '%s' AND Moderated = 1 AND IsSpam = 0", Convert::raw2sql($class), Convert::raw2sql($id)));
                 $link = $this->Link('rss', Convert::raw2xml($class), (int) $id);
             } else {
                 return $this->httpError(404);
             }
         } else {
             if ($class) {
                 if (Commenting::has_commenting($class)) {
                     $comments = Comment::get()->where(sprintf("BaseClass = '%s' AND Moderated = 1 AND IsSpam = 0", Convert::raw2sql($class)));
                 } else {
                     return $this->httpError(404);
                 }
             } else {
                 $comments = Comment::get();
             }
         }
     }
     $title = _t('CommentingController.RSSTITLE', "Comments RSS Feed");
     $feed = new RSSFeed($comments, $link, $title, $link, 'Title', 'Comment', 'AuthorName');
     $feed->outputToBrowser();
 }
예제 #6
0
 /**
  * @return Form
  */
 public function getEditForm($id = null, $fields = null)
 {
     if (!$id) {
         $id = $this->currentPageID();
     }
     $form = parent::getEditForm($id);
     $record = $this->getRecord($id);
     if ($record && !$record->canView()) {
         return Security::permissionFailure($this);
     }
     $commentsConfig = GridFieldConfig::create()->addComponents(new GridFieldFilterHeader(), new GridFieldDataColumns(), new GridFieldSortableHeader(), new GridFieldPaginator(25), new GridFieldDeleteAction(), new GridFieldDetailForm(), new GridFieldExportButton(), new GridFieldEditButton(), new GridFieldDetailForm());
     $needs = new GridField('Comments', _t('CommentsAdmin.NeedsModeration', 'Needs Moderation'), Comment::get()->where('Moderated = 0'), $commentsConfig);
     $moderated = new GridField('CommentsModerated', _t('CommentsAdmin.CommentsModerated'), Comment::get()->where('Moderated = 1'), $commentsConfig);
     $fields = new FieldList($root = new TabSet('Root', new Tab('NeedsModeration', _t('CommentAdmin.NeedsModeration', 'Needs Moderation'), $needs), new Tab('Comments', _t('CommentAdmin.Moderated', 'Moderated'), $moderated)));
     $root->setTemplate('CMSTabSet');
     $actions = new FieldList();
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->addExtraClass('cms-edit-form');
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
         $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
     }
     $this->extend('updateEditForm', $form);
     return $form;
 }
 /**
  * This method is overly complex, because {@link Comment} doesn't have a standard 'Parent' has_one, as it can be
  * attached to multiple different object types.
  *
  * @todo Can we fix this method without losing the flexibility that {@link Comment} provides?
  *
  * @see the above CommentUserNotificationSubscriptions() method for documentation
  * @param Member $member The {@link Member} object to find comments posted by, where `NotifyOfUpdates` = 1
  * @return ArrayList The list of {@link ArrayData} objects that can be shown in the template
  */
 public function CommentUserNotificationSubscriptionsFor(Member $member)
 {
     if (!$member || !$member->isInDB()) {
         return null;
     }
     // No member (or no ID yet), so nothing to find
     $allComments = Comment::get()->filter(array('AuthorID' => $member->ID, 'NotifyOfUpdates' => true));
     if (!$allComments) {
         return null;
     }
     $allObjects = new ArrayList();
     $allAddedComments = new ArrayList();
     // @todo O(n^2) :(
     foreach ($allComments as $comment) {
         $alreadyAdded = false;
         foreach ($allAddedComments as $obj) {
             if ($comment->BaseClass == $obj->BaseClass && $comment->ParentID == $obj->ParentID) {
                 $alreadyAdded = true;
                 break;
             }
         }
         if (!$alreadyAdded) {
             $baseClass = $comment->BaseClass;
             $baseObject = $baseClass::get()->byID($comment->ParentID);
             if ($baseObject) {
                 // @todo This could return the actual DataObject that we're expecting (e.g. the SiteTree object),
                 // but we can't add the 'CommentUserNotificationUnsubscribeLink' easily to it
                 $allObjects->push(new ArrayData(array('CommentUserNotificationUnsubscribeLink' => Controller::join_links('CommentingController', 'unsubscribenotification', $comment->ID), 'Title' => $baseObject->Title)));
                 $allAddedComments->push($comment);
                 // Keep track of what we've already added
             }
         }
     }
     return $allObjects;
 }
예제 #8
0
 public function delete()
 {
     redirect_guest_user(LOGIN_URL);
     $id = Param::get('id');
     $comment = Comment::get($id);
     $auth_user = User::getAuthenticated();
     $page = Param::get('page_next', 'delete');
     if (!$comment->isAuthor($auth_user)) {
         throw new PermissionException();
     }
     if ($comment->isThreadBody()) {
         redirect(DELETE_THREAD_URL, array('id' => $comment->thread_id));
     }
     switch ($page) {
         case 'delete':
             break;
         case 'delete_end':
             $comment->delete();
             redirect(VIEW_THREAD_URL, array('id' => $comment->thread_id));
             break;
         default:
             throw new PageNotFoundException();
             break;
     }
     $title = 'Delete comment';
     $this->set(get_defined_vars());
 }
 /**
  * @return Comment
  */
 protected function findDuplicateByCid($cid, $record)
 {
     $page = $this->getPage($record);
     if (!$page) {
         return;
     }
     return Comment::get()->filter(array('DrupalCid' => $cid))->First();
 }
 protected function getComment(SS_HTTPRequest $request)
 {
     $id = $request->param('ID');
     if ($id != (int) $id && $id > 0) {
         return false;
     }
     return Comment::get()->byId($id);
 }
 /**
  * Returns a list of all the comments attached to this record.
  *
  * @return PaginatedList
  */
 public function Comments()
 {
     $order = Commenting::get_config_value($this->ownerBaseClass, 'order_comments_by');
     $list = new PaginatedList(Comment::get()->where(sprintf("ParentID = '%s' AND BaseClass = '%s'", $this->owner->ID, $this->ownerBaseClass))->sort($order));
     $list->setPageLength(Commenting::get_config_value($this->ownerBaseClass, 'comments_per_page'));
     $controller = Controller::curr();
     $list->setPageStart($controller->request->getVar("commentsstart" . $this->owner->ID));
     $list->setPaginationGetVar("commentsstart" . $this->owner->ID);
     $list->MoreThanOnePage();
     return $list;
 }
 public function CommentLink()
 {
     if (!Permission::check('BLOG_FRONTENDMANAGEMENT') || !class_exists('Comment')) {
         return false;
     }
     $unmoderated = Comment::get()->filter("Moderated", 0)->count();
     if ($unmoderated > 0) {
         return "admin/comments/unmoderated";
     } else {
         return "admin/comments";
     }
 }
예제 #13
0
 /**
  * Handles GET requests for an individual comment.
  */
 public function get_comment($update = false)
 {
     if (isset($this->handler_vars['id']) && ($comment = Comment::get($this->handler_vars['id']))) {
         $this->theme->comment = $comment;
         // Convenience array to output actions twice
         $actions = array('deleted' => 'delete', 'spam' => 'spam', 'unapproved' => 'unapprove', 'approved' => 'approve', 'saved' => 'save');
         $form = $this->form_comment($comment, $actions);
         if ($update) {
             // Get the $_POSTed values
             $form->process();
             foreach ($actions as $key => $action) {
                 $id_one = $action . '_1';
                 $id_two = $action . '_2';
                 if ($form->{$id_one}->value != null || $form->{$id_two}->value != null) {
                     if ($action == 'delete') {
                         $comment->delete();
                         Utils::redirect(URL::get('display_comments'));
                     }
                     if ($action != 'save') {
                         foreach (Comment::list_comment_statuses() as $status) {
                             if ($status == $key) {
                                 $comment->status = Comment::status_name($status);
                                 $set_status = true;
                             }
                         }
                     }
                 }
             }
             $comment->content = $form->content->value;
             $comment->name = $form->author_name->value;
             $comment->url = $form->author_url->value;
             $comment->email = $form->author_email->value;
             $comment->ip = $form->author_ip->value;
             $comment->date = DateTime::create($form->comment_date->value);
             $comment->post_id = $form->comment_post->value;
             if (!isset($set_status)) {
                 $comment->status = $form->comment_status->value;
             }
             $comment->update();
             Plugins::act('comment_edit', $comment, $form);
             Utils::redirect();
         }
         $comment->content = $form;
         $this->theme->form = $form;
         $this->display('comment');
     } else {
         Utils::redirect(URL::get('display_comments'));
     }
 }
예제 #14
0
 /**
  * {@inheritdoc}
  */
 public function handleAction(GridField $gridField, $actionName, $arguments, $data)
 {
     if ($actionName == 'spam') {
         $comment = Comment::get()->byID($arguments["RecordID"]);
         $comment->markSpam();
         // output a success message to the user
         Controller::curr()->getResponse()->setStatusCode(200, 'Comment marked as spam.');
     }
     if ($actionName == 'approve') {
         $comment = Comment::get()->byID($arguments["RecordID"]);
         $comment->markApproved();
         // output a success message to the user
         Controller::curr()->getResponse()->setStatusCode(200, 'Comment approved.');
     }
 }
예제 #15
0
 public function testCommentsForm()
 {
     SecurityToken::disable();
     $this->autoFollowRedirection = false;
     $parent = $this->objFromFixture('CommentableItem', 'first');
     // Test posting to base comment
     $response = $this->post('CommentingController/CommentsForm', array('Name' => 'Poster', 'Email' => '*****@*****.**', 'Comment' => 'My Comment', 'ParentID' => $parent->ID, 'BaseClass' => 'CommentableItem', 'action_doPostComment' => 'Post'));
     $this->assertEquals(302, $response->getStatusCode());
     $this->assertStringStartsWith('CommentableItem_Controller#comment-', $response->getHeader('Location'));
     $this->assertDOSEquals(array(array('Name' => 'Poster', 'Email' => '*****@*****.**', 'Comment' => 'My Comment', 'ParentID' => $parent->ID, 'BaseClass' => 'CommentableItem')), Comment::get()->filter('Email', '*****@*****.**'));
     // Test posting to parent comment
     $parentComment = $this->objFromFixture('Comment', 'firstComA');
     $this->assertEquals(0, $parentComment->ChildComments()->count());
     $response = $this->post('CommentingController/reply/' . $parentComment->ID, array('Name' => 'Test Author', 'Email' => '*****@*****.**', 'Comment' => 'Making a reply to firstComA', 'ParentID' => $parent->ID, 'BaseClass' => 'CommentableItem', 'ParentCommentID' => $parentComment->ID, 'action_doPostComment' => 'Post'));
     $this->assertEquals(302, $response->getStatusCode());
     $this->assertStringStartsWith('CommentableItem_Controller#comment-', $response->getHeader('Location'));
     $this->assertDOSEquals(array(array('Name' => 'Test Author', 'Email' => '*****@*****.**', 'Comment' => 'Making a reply to firstComA', 'ParentID' => $parent->ID, 'BaseClass' => 'CommentableItem', 'ParentCommentID' => $parentComment->ID)), $parentComment->ChildComments());
 }
 /**
  * Store it.
  * And also check if it's no double-post. Limited to 60 seconds, but it can be differed.
  * I wonder if this is XSS safe? The saveInto does this for me, right?
  * @param array $data Posted data as array
  * @param Form $form FormObject containing the entire Form as an Object.
  */
 public function CommentStore($data, $form)
 {
     /**
      * If the "Extra" field is filled, we have a bot.
      * Also, the nsas (<noscript> Anti Spam) is a bot. Bot's don't use javascript.
      * Note, a legitimate visitor that has JS disabled, will be unable to post!
      */
     if (!isset($data['Extra']) || $data['Extra'] == '' || isset($data['nsas'])) {
         $data['Comment'] = Convert::raw2sql($data['Comment']);
         $exists = Comment::get()->filter(array('Comment:PartialMatch' => $data['Comment']))->where('ABS(TIMEDIFF(NOW(), Created)) < 60');
         if (!$exists->count()) {
             $comment = Comment::create();
             $form->saveInto($comment);
             $comment->NewsID = $data['NewsID'];
             $comment->write();
         }
     }
     Controller::curr()->redirectBack();
 }
 /**
  * We hook into onAfterWrite() because we want to check this every time the comment is written - primarily because
  * of the test that we perform to ensure that the comment isn't currently moderated. Most sites will moderate
  * comments initially, and there's no point sending an email to a user if the comment is still awaiting moderation
  * (and therefore the user can't see it yet).
  *
  * @todo This will lead to multiple emails being sent if a comment is edited after being posted
  */
 public function onAfterWrite()
 {
     parent::onAfterWrite();
     $parentClass = $this->owner->BaseClass;
     $parentID = $this->owner->ParentID;
     // We only want to notify people if certain conditions are met:
     // - The comment has passed moderation (aka. if required, it has been approved by an admin)
     // - We are either seeing the Comment for the first time, or it has just passed moderation by an admin
     if ($this->shouldSendUserNotificationEmails()) {
         if (ClassInfo::exists($parentClass)) {
             $commentParent = $parentClass::get()->byID($parentID);
             // Get all comments attached to this page, which we have to do manually as the has_one relationship is
             // 'faked' by the Comment class (because it can be attached to multiple parent classes).
             if ($commentParent) {
                 $comments = Comment::get()->filter(array('BaseClass' => $parentClass, 'ParentID' => $parentID, 'NotifyOfUpdates' => true));
                 // If we have comments, iterate over them to build a unique list of all email addresses to notify
                 if ($comments) {
                     $emailList = array();
                     foreach ($comments as $c) {
                         $author = $c->Author();
                         if ($author) {
                             if (!in_array($author->Email, $emailList)) {
                                 $emailList[] = $author->Email;
                             }
                         }
                     }
                     // Send an email to everyone in the list
                     if (sizeof($emailList) > 0) {
                         foreach ($emailList as $emailAddress) {
                             $email = new Email();
                             $email->setSubject('New Comment on "' . $commentParent->dbObject('Title')->XML() . '"');
                             $email->setFrom(Email::getAdminEmail());
                             $email->setTo($emailAddress);
                             $email->populateTemplate($this->owner);
                             $email->send();
                         }
                     }
                 }
             }
         }
     }
 }
 public function action_comment_insert_after($comment)
 {
     if ($comment->type != Comment::COMMENT || $comment->status == Comment::STATUS_SPAM) {
         return;
     }
     $post = Post::get(array('id' => $comment->post_id));
     $author = User::get_by_id($post->user_id);
     $c = $comment;
     $sent = array();
     $sent[] = $author->email;
     $sent[] = $comment->email;
     while (isset($c->info->comment_parent)) {
         $cc = Comment::get($c->info->comment_parent);
         if (isset($cc->info->email_notify) && $cc->info->email_notify == 1) {
             if (!in_array($cc->email, $sent)) {
                 $sent[] = $cc->email;
                 $this->mail_notify($cc->email, $cc, $comment);
             }
         }
         $c = $cc;
     }
 }
 /**
  * Remove a Comment from this relation by clearing the foreign key. Does not actually delete the comment.
  *
  * @param Comment $item The Comment to be removed
  */
 public function remove($item)
 {
     // Check item given
     if (is_numeric($item)) {
         $item = Comment::get()->byID($item);
     }
     if (!$item instanceof Comment) {
         throw new InvalidArgumentException("CommentList::remove() expecting a Comment object, or ID", E_USER_ERROR);
     }
     // Don't remove item with unrelated class key
     $foreignClass = $this->getForeignClass();
     $classNames = ClassInfo::subclassesFor($foreignClass);
     if (!in_array($item->BaseClass, $classNames)) {
         return;
     }
     // Don't remove item which doesn't belong to this list
     $foreignID = $this->getForeignID();
     if (empty($foreignID) || is_array($foreignID) && in_array($item->ParentID, $foreignID) || $foreignID == $item->ParentID) {
         $item->ParentID = null;
         $item->BaseClass = null;
         $item->write();
     }
 }
 /**
  * Handles AJAX from /comments.
  * Used to edit comments inline.
  */
 public function action_auth_ajax_in_edit(ActionHandler $handler)
 {
     Utils::check_request_method(array('POST'));
     $handler_vars = $handler->handler_vars;
     $wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']);
     if ($handler_vars['digest'] != $wsse['digest']) {
         Session::error(_t('WSSE authentication failed.'));
         echo Session::messages_get(true, array('Format', 'json_messages'));
         return;
     }
     $comment = Comment::get($handler_vars['id']);
     if (!ACL::access_check($comment->get_access(), 'edit')) {
         Session::error(_t('You do not have permission to edit this comment.'));
         echo Session::messages_get(true, array('Format', 'json_messages'));
         return;
     }
     if (isset($handler_vars['author']) && $handler_vars['author'] != '') {
         $comment->name = $handler_vars['author'];
     }
     if (isset($handler_vars['url'])) {
         $comment->url = $handler_vars['url'];
     }
     if (isset($handler_vars['email']) && $handler_vars['email'] != '') {
         $comment->email = $handler_vars['email'];
     }
     if (isset($handler_vars['content']) && $handler_vars['content'] != '') {
         $comment->content = $handler_vars['content'];
     }
     if (isset($handler_vars['time']) && $handler_vars['time'] != '' && isset($handler_vars['date']) && $handler_vars['date'] != '') {
         $seconds = date('s', strtotime($comment->date));
         $date = date('Y-m-d H:i:s', strtotime($handler_vars['date'] . ' ' . $handler_vars['time'] . ':' . $seconds));
         $comment->date = $date;
     }
     $comment->update();
     Session::notice(_t('Updated 1 comment.'));
     echo Session::messages_get(true, array('Format', 'json_messages'));
 }
예제 #21
0
 public function Comments($PageID)
 {
     return Comment::get()->filter('ParentID', $PageID)->sort('Created', 'ASC');
 }
    }
    // Probably needs optimizing.
    $this_project = new Project();
    $this_project->get($query_data['project_id']);
    if ($query_data['evidence_id'] > 0) {
        $this_evidence = new Evidence();
        $this_evidence->get($query_data['evidence_id']);
    }
    if ($query_data['hypothesis_id'] > 0) {
        $this_hypothesis = new Hypothesis();
        $this_hypothesis->get($query_data['hypothesis_id']);
    }
    $this_user = new User();
    $this_user->get($query_data['user_id']);
    $this_reply_comment = new Comment();
    $this_reply_comment->get($query_data['reply_to_id']);
    $counter++;
    ?>

<div class="recentComment">

<p class="comment"><a href="<?php 
    echo $base_URL;
    ?>
profile/<?php 
    echo $this_user->username;
    ?>
"><?php 
    echo $this_user->name;
    ?>
</a> wrote: <i>"<?php 
예제 #23
0
 public function action_handler_comment_url_redirect($handler_vars)
 {
     $comment = Comment::get($handler_vars['id']);
     $hash = $this->get_hash($handler_vars['id']);
     if ($hash == $handler_vars['ccode']) {
         Utils::redirect($comment->url);
         exit;
     }
     header('HTTP/1.1 410 Gone');
     exit;
 }
 /**
  * Send back all comments as JSON
  *
  * @return Response
  */
 public function index()
 {
     return Response::json(Comment::get());
 }
예제 #25
0
			    OR comment_author_url LIKE ' . $DB->quote('%' . $keyword . '%') . '
			    OR comment_content LIKE ' . $DB->quote('%' . $keyword . '%') . '
			 ORDER BY comment_date ASC
			 LIMIT 500';
$res_affected_comments = $DB->get_results($sql, OBJECT, 'Find matching comments');
if ($DB->num_rows == 0) {
    // No matching hits.
    printf('<p>' . T_('No <strong>comments</strong> match the keyword [%s].') . '</p>', htmlspecialchars($keyword));
} else {
    // create comment arrays
    $comments_by_status = array('published' => array(), 'community' => array(), 'protected' => array(), 'private' => array(), 'draft' => array(), 'review' => array(), 'deprecated' => array());
    $no_perms_count = array('published' => 0, 'community' => 0, 'protected' => 0, 'private' => 0, 'draft' => 0, 'review' => 0, 'deprecated' => 0);
    foreach ($res_affected_comments as $row_stats) {
        // select comments
        $affected_Comment = new Comment($row_stats);
        $comment_status = $affected_Comment->get('status');
        if ($comment_status == 'trash') {
            // This comment was already deleted
            continue;
        }
        if (!$current_User->check_perm('comment!CURSTATUS', 'edit', false, $affected_Comment)) {
            // no permission to delete
            $no_perms_count[$comment_status] = $no_perms_count[$comment_status] + 1;
            continue;
        }
        // Add comment to the corresponding list
        $comments_by_status[$comment_status][] = $affected_Comment;
    }
    // show comments
    foreach ($comments_by_status as $status => $comments) {
        echo_affected_comments($comments, $status, $keyword, $no_perms_count[$status]);
예제 #26
0
 public function actionComment($topicId)
 {
     $topic = Topic::get($topicId);
     if (Rays::isPost()) {
         $validation = new RValidation(array(array('field' => 'content', 'label' => 'Content', 'rules' => 'trim|required')));
         if (!$validation->run()) {
             $this->flash("error", "Comment content cannot be empty!");
             $this->redirectAction('post', 'view', $topicId);
         }
         $form = $_POST;
         $topic->commentCount++;
         $topic->lastCommentTime = date('Y-m-d H:i:s');
         $topic->save();
         $user = Rays::user();
         $comment = new Comment();
         $comment->topicId = $topicId;
         $comment->userId = $user->id;
         $comment->createdTime = date('Y-m-d H:i:s');
         $comment->content = $form["content"];
         if (isset($form['replyTo'])) {
             $comment->pid = (int) $form['replyTo'];
         } else {
             $comment->pid = 0;
         }
         $comment->save();
         $cid = $comment->id;
         if (isset($form['replyTo'])) {
             $exactComment = Comment::get($form['exactReplyTo']);
             Message::sendMessage('user', $user->id, $exactComment->userId, 'New reply', $user->name . ' has replied to your comment ' . RHtml::linkAction('post', $topic->title, 'view', $topic->id . '?reply=' . $cid));
         } else {
             if ($topic->userId !== $user->id) {
                 //send message to topic author
                 Message::sendMessage('user', $user->id, $topic->userId, 'New Comment', $user->name . ' has replied to your topic ' . RHtml::linkAction('post', $topic->title, 'view', $topic->id . '?reply=' . $cid));
             }
         }
     }
     $this->redirectAction('post', 'view', $topicId);
 }
예제 #27
0
 public function testCreateCommentSuccess()
 {
     $_params = $this->_params;
     $_params['user_id'] = $this->_user_id;
     $response = $this->_getAuth($_params);
     //get created login information
     $comment_infor = Comment::get(array('user_id', 'rating_id', 'content', 'updated_at', 'created_at', 'id'))->last();
     $profile = Profile::where('user_id', $comment_infor->user_id)->first();
     if ($profile->image != null) {
         $comment_infor->avatar_user = URL::asset($profile->image);
     } else {
         $comment_infor->avatar_user = $profile->image;
     }
     $comment_infor->first_name = $profile->first_name;
     $comment_infor->last_name = $profile->last_name;
     $this->assertNotNull($comment_infor);
     $this->assertEquals(array("code" => ApiResponse::OK, "data" => $comment_infor->toArray()), json_decode($response->getContent(), true));
 }
예제 #28
0
 /**
  * Return an RSSFeed of comments for a given set of comments or all
  * comments on the website.
  *
  * To maintain backwards compatibility with 2.4 this supports mapping
  * of PageComment/rss?pageid= as well as the new RSS format for comments
  * of CommentingController/rss/{classname}/{id}
  *
  * @param SS_HTTPRequest
  *
  * @return RSSFeed
  */
 public function getFeed(SS_HTTPRequest $request)
 {
     $link = $this->Link('rss');
     $class = $request->param('ID');
     $id = $request->param('OtherID');
     // Support old pageid param
     if (!$id && !$class && ($id = $request->getVar('pageid'))) {
         $class = 'SiteTree';
     }
     $comments = Comment::get()->filter(array('Moderated' => 1, 'IsSpam' => 0));
     // Check if class filter
     if ($class) {
         if (!is_subclass_of($class, 'DataObject') || !$class::has_extension('CommentsExtension')) {
             return $this->httpError(404);
         }
         $this->setBaseClass($class);
         $comments = $comments->filter('BaseClass', $class);
         $link = Controller::join_links($link, $class);
         // Check if id filter
         if ($id) {
             $comments = $comments->filter('ParentID', $id);
             $link = Controller::join_links($link, $id);
             $this->setOwnerRecord(DataObject::get_by_id($class, $id));
         }
     }
     $title = _t('CommentingController.RSSTITLE', "Comments RSS Feed");
     $comments = new PaginatedList($comments, $request);
     $comments->setPageLength($this->getOption('comments_per_page'));
     return new RSSFeed($comments, $link, $title, $link, 'Title', 'EscapedComment', 'AuthorName');
 }
예제 #29
0
	/**
	 * 
	 */
	public function testCommentInfo()
	{
		// make sure adding info to comment works
		$this->comment->info->test = 'test';
		$this->assertEquals( 'test', $this->comment->info->test );
		$this->comment->update();
		$test_comment = Comment::get($this->comment->id);
		$this->assertEquals( $this->comment->info->test, $test_comment->info->test );
		unset($test_comment);

		// make sure construction works with info
		$new_comment = new Comment();
		$this->assertType( 'CommentInfo', $new_comment->info );
		$this->assertFalse( $new_comment->info->is_key_set() );
		$new_comment->info->test = 'test';
		$new_comment->insert();
		$this->assertTrue( $new_comment->info->is_key_set() );
		$test_comment = Comment::get($new_comment->id);
		$this->assertEquals( $new_comment->info->test, $test_comment->info->test );
		$new_comment->delete();
		unset($test_comment);
	}
 public function getComments()
 {
     return Comment::get()->filter(['ParentID' => 0, 'PostID' => $this->owner->ID]);
 }