Since: 1.9.0
Inheritance: extends ElggObject
コード例 #1
0
ファイル: file.php プロジェクト: manlui/elgg_with_rest_api
/**
 * @param $guid
 * @param $text
 * @param $username
 * @return mixed
 * @throws InvalidParameterException
 */
function file_post_comment($guid, $text, $username)
{
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    if ($guid) {
        $entity = get_entity($guid);
    }
    if ($entity) {
        $return['success'] = false;
        if (empty($text)) {
            $return['message'] = elgg_echo("thefilecomment:blank");
            return $return;
        }
        if ($entity) {
            $comment = new ElggComment();
            $comment->description = $text;
            $comment->owner_guid = $user->guid;
            $comment->container_guid = $entity->guid;
            $comment->access_id = $entity->access_id;
            $guid_comment = $comment->save();
            if ($guid_comment) {
                $return['success'] = $guid_comment;
                elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $user->guid, 'object_guid' => $guid_comment, 'target_guid' => $entity->guid));
            }
        }
        return $return;
    } else {
        $return['success'] = false;
        $return['message'] = 'Require guid from post';
        return $return;
    }
}
コード例 #2
0
ファイル: save.php プロジェクト: ibou77/elgg
        if (elgg_is_xhr()) {
            // @todo move to its own view object/comment/content in 1.x
            echo elgg_view('output/longtext', array('value' => $comment->description, 'class' => 'elgg-inner', 'data-role' => 'comment-text'));
        }
    } else {
        register_error(elgg_echo('generic_comment:failure'));
    }
} else {
    // Create a new comment on the target entity
    $entity = get_entity($entity_guid);
    if (!$entity) {
        register_error(elgg_echo("generic_comment:notfound"));
        forward(REFERER);
    }
    $user = elgg_get_logged_in_user_entity();
    $comment = new ElggComment();
    $comment->description = $comment_text;
    $comment->owner_guid = $user->getGUID();
    $comment->container_guid = $entity->getGUID();
    $comment->access_id = $entity->access_id;
    $guid = $comment->save();
    if (!$guid) {
        register_error(elgg_echo("generic_comment:failure"));
        forward(REFERER);
    }
    // Notify if poster wasn't owner
    if ($entity->owner_guid != $user->guid) {
        $owner = $entity->getOwnerEntity();
        notify_user($owner->guid, $user->guid, elgg_echo('generic_comment:email:subject', array(), $owner->language), elgg_echo('generic_comment:email:body', array($entity->title, $user->name, $comment_text, $comment->getURL(), $user->name, $user->getURL()), $owner->language), array('object' => $comment, 'action' => 'create'));
    }
    // Add to river
コード例 #3
0
elgg_register_plugin_hook_handler('permissions_check', 'all', 'elgg_override_permissions');
elgg_register_plugin_hook_handler('container_permissions_check', 'all', 'elgg_override_permissions');
$success_count = 0;
$error_count = 0;
do {
    $annotations_to_delete = array();
    $container_guids = array();
    $annotations = elgg_get_annotations(array('annotation_names' => 'generic_comment', 'limit' => $limit, 'offset' => $offset, 'order_by' => 'n_table.id DESC'));
    if (!$annotations) {
        // no annotations left
        break;
    }
    $db_prefix = elgg_get_config('dbprefix');
    // Create a new object for each annotation
    foreach ($annotations as $annotation) {
        $object = new ElggComment();
        $object->owner_guid = $annotation->owner_guid;
        $object->container_guid = $annotation->entity_guid;
        $object->description = $annotation->value;
        $object->access_id = $annotation->access_id;
        // make sure disabled comments stay disabled
        $object->enabled = $annotation->enabled;
        $object->time_created = $annotation->time_created;
        $object->save(false);
        $guid = $object->getGUID();
        if ($guid) {
            /**
             * Update the entry in river table for this comment
             *
             * - Update the view path
             * - Remove annotation id
コード例 #4
0
ファイル: anon_add.php プロジェクト: lorea/Hydra-dev
        // spammer
        register_error(elgg_acho('AU_anonymous_comments:stopforumspam_fail'));
        forward(REFERER);
    }
}
// Create a new comment on the target entity
$entity = get_entity($entity_guid);
if (!$entity) {
    register_error(elgg_echo("generic_comment:notfound"));
    forward(REFERER);
}
$user = get_anon_user();
// custom context for write permissions
elgg_push_context("AU_anonymous_comments_permissions");
$comment_text .= "\n\n- " . $anon_name;
$comment = new \ElggComment();
$comment->description = $comment_text;
$comment->owner_guid = $user->getGUID();
$comment->container_guid = $entity->getGUID();
$comment->access_id = $entity->access_id;
$guid = $comment->save();
if (!$guid) {
    register_error(elgg_echo("generic_comment:failure"));
    forward(REFERER);
}
if (!is_moderated($entity)) {
    $owner = $entity->getOwnerEntity();
    notify_user($owner->guid, $user->guid, elgg_echo('generic_comment:email:subject', array(), $owner->language), elgg_echo('generic_comment:email:body', array($entity->title, $anon_name . " ({$anon_email})", $comment_text, $entity->getURL(), $user->name, $user->getURL()), $owner->language), array('object' => $comment, 'action' => 'create'));
} else {
    $token = get_token($comment);
    $approveURL = elgg_normalize_url("auac/approve/{$comment->guid}/{$token}");
コード例 #5
0
    }
    $comment->description = $comment_text;
    if ($comment->save()) {
        system_message(elgg_echo('generic_comment:updated'));
    } else {
        register_error(elgg_echo('generic_comment:failure'));
    }
} else {
    // Create a new comment on the target entity
    $entity = get_entity($entity_guid);
    if (!$entity) {
        register_error(elgg_echo("generic_comment:notfound"));
        forward(REFERER);
    }
    $user = elgg_get_logged_in_user_entity();
    $comment = new ElggComment();
    $comment->description = $comment_text;
    $comment->owner_guid = $user->getGUID();
    $comment->container_guid = $entity->getGUID();
    $comment->access_id = $entity->access_id;
    $guid = $comment->save();
    if (!$guid) {
        register_error(elgg_echo("generic_comment:failure"));
        forward(REFERER);
    }
    // Notify if poster wasn't owner
    if ($entity->owner_guid != $user->guid) {
        notify_user($entity->owner_guid, $user->guid, elgg_echo('generic_comment:email:subject'), elgg_echo('generic_comment:email:body', array($entity->title, $user->name, $comment_text, $entity->getURL(), $user->name, $user->getURL())), array('object' => $comment, 'action' => 'create'));
    }
    // Add to river
    elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $user->guid, 'object_guid' => $guid, 'target_guid' => $entity_guid));
コード例 #6
0
ファイル: ElggCommentTest.php プロジェクト: ibou77/elgg
 /**
  * Called after each test method.
  */
 public function tearDown()
 {
     $this->container->delete();
     $this->comment->delete();
 }
コード例 #7
0
 /**
  * Set subtype
  */
 protected function initializeAttributes()
 {
     parent::initializeAttributes();
     $this->attributes['subtype'] = "discussion_reply";
 }
コード例 #8
0
ファイル: UserCapabilitiesTest.php プロジェクト: elgg/elgg
 /**
  * @group UserCapabilities
  */
 public function testDefaultCanCommentPermissions()
 {
     $viewer = $this->mocks()->getUser();
     $owner = $this->mocks()->getUser();
     $group = $this->mocks()->getGroup(['owner_guid', $owner->guid]);
     $object = $this->mocks()->getObject(['owner_guid', $owner->guid]);
     $entity = $this->getMockBuilder(ElggEntity::class)->setMethods(['__get', 'getDisplayName', 'setDisplayName'])->disableOriginalConstructor()->getMock();
     $entity->expects($this->any())->method('__get')->will($this->returnValueMap([['owner_guid', $owner->guid]]));
     $this->assertFalse($owner->canComment($owner->guid));
     $this->assertTrue($object->canComment($owner->guid));
     $this->assertFalse($group->canComment($owner->guid));
     $this->assertNull($entity->canComment($owner->guid));
     $this->assertFalse($owner->canComment($viewer->guid));
     $this->assertTrue($object->canComment($viewer->guid));
     $this->assertFalse($group->canComment($viewer->guid));
     $this->assertNull($entity->canComment($viewer->guid));
     // can pass default value
     $this->assertTrue($object->canComment($viewer->guid, true));
     $this->assertFalse($object->canComment($viewer->guid, false));
     // can't comment on comment
     $comment = new \ElggComment();
     $comment->owner_guid = $owner->guid;
     $this->assertFalse($comment->canComment($owner->guid));
 }
コード例 #9
0
 }
 $comment = new \ElggComment();
 $comment->subtype = 'comment';
 $comment->owner_guid = $owner->guid;
 $comment->container_guid = $entity->guid;
 $comment->description = $faker->text(rand(25, 1000));
 $comment->access_id = $entity->access_id;
 $comment->time_created = rand($entity->time_created, time());
 $comment->__faker = true;
 if ($comment->save()) {
     $success++;
     elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $comment->owner_guid, 'object_guid' => $comment->guid, 'target_guid' => $entity->guid));
     for ($k = 0; $k < $reply_count; $k++) {
         $owner = $users[array_rand($users, 1)];
         if ($comment->canComment($owner->guid)) {
             $reply = new \ElggComment();
             $reply->subtype = 'comment';
             $reply->owner_guid = $owner->guid;
             $reply->container_guid = $comment->guid;
             $reply->description = $faker->text(rand(25, 1000));
             $reply->access_id = $entity->access_id;
             $reply->time_created = rand($comment->time_created, time());
             $reply->__faker = true;
             if ($reply->save()) {
                 $success++;
                 elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $reply->owner_guid, 'object_guid' => $reply->guid, 'target_guid' => $comment->guid));
             } else {
                 $error++;
             }
         }
     }