/** * Create a new collection from data * * @param mixed $data Initial data set * @return AccessCollection */ public static function create($data) { $acl = new AccessCollection(); return $acl->add($data); }
/** * {@inheritdoc} */ public function execute() { if (!$this->post) { if ($this->subtype == 'thewire' && is_callable('thewire_save_post')) { $guid = thewire_save_post($this->status, $this->poster->guid, $this->access_id, 0, 'wall'); $this->post = get_entity($guid); } else { $this->post = new Post(); $this->post->subtype = $this->subtype; $this->post->owner_guid = $this->poster->guid; $this->post->container_guid = $this->container->guid; $guid = $this->post->save(); } } $this->post->title = $this->title; $this->post->description = $this->status; $this->post->access_id = $this->access_id; if (!$this->post->guid) { $this->result->addError(elgg_echo('wall:create:error')); return; } if (Integration::isElggVersionBelow('1.9.0')) { $river_id = add_to_river('river/object/hjwall/create', 'create', $this->poster->guid, $this->post->guid); } else { // Create a river entry for this wall post $river_id = elgg_create_river_item(array('view' => 'river/object/hjwall/create', 'action_type' => 'create', 'subject_guid' => $this->post->owner_guid, 'object_guid' => $this->post->guid, 'target_guid' => $this->post->container_guid)); } $river = elgg_get_river(array('ids' => $river_id)); $this->river = $river ? $river[0] : null; $this->post->origin = 'wall'; $qualifiers = elgg_trigger_plugin_hook('extract:qualifiers', 'wall', array('source' => $this->post->description), array()); if (count($qualifiers['hashtags'])) { $this->post->tags = $qualifiers['hashtags']; } if (count($qualifiers['usernames'])) { foreach ($qualifiers['usernames'] as $username) { $user = get_user_by_username($username); if (elgg_instanceof($user) && !in_array($user->guid, $this->friend_guids)) { $this->friend_guids[] = $user->guid; } } } // Add 'tagged_in' relationships // If the access level for the post is not set to private, also create a river item // with the access level specified in their settings by the tagged user if (!empty($this->friend_guids)) { foreach ($this->friend_guids as $friend_guid) { if (add_entity_relationship($friend_guid, 'tagged_in', $this->post->guid)) { if (!in_array($this->access_id, array(ACCESS_PRIVATE, ACCESS_LOGGED_IN, ACCESS_PUBLIC))) { $river_access_id = elgg_get_plugin_user_setting('river_access_id', $friend_guid, 'hypeWall'); if (!is_null($river_access_id) && $river_access_id !== ACCESS_PRIVATE) { $river_id = elgg_create_river_item(array('view' => 'river/relationship/tagged/create', 'action_type' => 'tagged', 'subject_guid' => $friend_guid, 'object_guid' => $this->post->getGUID(), 'target_guid' => $this->post->getContainerGUID(), 'access_id' => $river_access_id)); } } } } } // Wall post access id is set to private, which means it should be visible only to the poster and tagged users // Creating a new ACL for that if ($this->access_id == ACCESS_PRIVATE && count($this->friend_guids)) { $members = $this->friend_guids; $members[] = $this->poster->guid; $members[] = $this->container->guid; $acl_id = AccessCollection::create($members); $this->post->access_id = $acl_id; $this->post->save(); } if (!empty($this->attachment_guids)) { foreach ($this->attachment_guids as $attachment_guid) { add_entity_relationship($attachment_guid, 'attached', $this->post->guid); } } // files being uploaded via $_FILES $uploads = hypeApps()->uploader->handle('upload_guids'); $uploaded_file_guids = []; if ($uploads) { foreach ($uploads as $upload) { if ($upload instanceof \ElggFile) { $file_obj = $upload; } else { if ($upload instanceof \hypeJunction\Files\Upload) { $file_obj = $upload->file; } } if ($file_obj->guid) { $uploaded_file_guids[] = $file_obj->guid; } } } // Something is broken in the hypeApps setter, so doing this hack for now $this->upload_guids = array_merge($this->upload_guids, $uploaded_file_guids); if (!empty($this->upload_guids)) { foreach ($this->upload_guids as $upload_guid) { $upload = get_entity($upload_guid); if ($upload) { $upload->description = $this->post->description; $upload->origin = 'wall'; $upload->access_id = $this->post->access_id; $upload->container_guid = $this->container->canWriteToContainer($this->poster->guid, 'object', 'file') ? $this->container->guid : ELGG_ENTITIES_ANY_VALUE; if ($upload->save()) { add_entity_relationship($upload_guid, 'attached', $this->post->guid); } } } } $this->post->setLocation($this->location); $this->post->address = $this->address; if ($this->post->address && $this->make_bookmark) { $document = elgg_trigger_plugin_hook('extract:meta', 'wall', array('src' => $this->post->address)); $bookmark = new ElggObject(); $bookmark->subtype = "bookmarks"; $bookmark->container_guid = $this->container->canWriteToContainer($this->poster->guid, 'object', 'bookmarks') ? $this->container->guid : ELGG_ENTITIES_ANY_VALUE; $bookmark->address = $this->post->address; $bookmark->access_id = $this->post->access_id; $bookmark->origin = 'wall'; if (!$document) { $bookmark->title = $this->post->title; $bookmark->description = $this->post->description; $bookmark->tags = $this->post->tags; } else { $bookmark->title = filter_tags($document->meta->title); $bookmark->description = filter_tags($document->meta->description); $bookmark->tags = string_to_tag_array(filter_tags($document->meta->keywords)); } $bookmark->save(); $this->bookmark = $bookmark; } if ($this->post->save()) { $message = $this->post->formatMessage(); $params = array('entity' => $this->post, 'user' => $this->poster, 'message' => $message, 'url' => $this->post->getURL(), 'origin' => 'wall'); elgg_trigger_plugin_hook('status', 'user', $params); // Trigger a publish event, so that we can send out notifications elgg_trigger_event('publish', 'object', $this->post); if (get_input('widget')) { elgg_push_context('widgets'); } if (elgg_is_xhr()) { $this->result->output .= elgg_list_river(array('object_guids' => $this->post->guid, 'pagination' => false, 'pagination_type' => false, 'limit' => 0)); } $this->result->addMessage(elgg_echo('wall:create:success')); if ($this->container instanceof \ElggUser) { $this->result->setForwardURL(hypeWall()->router->normalize("owner/{$this->container->username}")); } else { $this->result->setForwardURL(hypeWall()->router->normalize("container/{$this->container->guid}")); } } else { $this->result->addError(elgg_echo('wall:create:error')); } }