public function execute() { $this->uploads = hypeApps()->uploader->handle('dropzone', array('subtype' => $this->subtype, 'container_guid' => $this->container_guid, 'access_id' => ACCESS_PRIVATE)); $output = array(); foreach ($this->uploads as $upload) { $messages = array(); $success = true; if ($upload->error) { $messages[] = $upload->error; $success = false; $guid = false; } else { $file = $upload->file; if (!$file instanceof \ElggEntity) { $messages[] = elgg_echo('dropzone:file_not_entity'); $success = false; } else { $guid = $file->getGUID(); $html = elgg_view('input/hidden', array('name' => $this->input_name, 'value' => $file->getGUID())); } } $file_output = array('messages' => $messages, 'success' => $success, 'guid' => $guid, 'html' => $html); $output[] = elgg_trigger_plugin_hook('upload:after', 'dropzone', array('upload' => $upload), $file_output); } $this->result->output = json_encode($output); }
/** * {@inheritdoc} */ public function handle(ElggEntity $entity) { $shortname = $this->getShortname(); $future_value = $_FILES[$shortname]; $value = $_FILES[$shortname]; $error_type = elgg_extract('error', $value); $has_uploaded_file = $error_type != UPLOAD_ERR_NO_FILE; if (!$has_uploaded_file) { return $entity; } $params = array('field' => $this, 'entity' => $entity, 'upload_name' => $shortname, 'future_value' => $future_value); // Allow plugins to prevent files from being uploaded if (!elgg_trigger_plugin_hook('handle:upload:before', 'prototyper', $params, true)) { return $entity; } $previous_upload = $this->getValues($entity); if ($previous_upload instanceof ElggFile) { $previous_upload->delete(); } $result = hypeApps()->uploader->handle($shortname, array('container_guid' => $entity->guid, 'origin' => 'prototyper', 'prototyper_field' => $shortname, 'access_id' => $entity->access_id)); /* @var $result ElggFile[] */ $future_value = $result[0]; $params = array('field' => $this, 'entity' => $entity, 'upload_name' => $shortname, 'value' => $future_value); elgg_trigger_plugin_hook('handle:upload:after', 'prototyper', $params, $result); return $entity; }
public static function setIcon(PropertyInterface $prop, \ElggEntity $entity, $value = null, array $params = null) { $prop_id = $prop->getIdentifier(); if (!is_array($value) || !isset($value)) { $value = elgg_extract($prop_id, $_FILES, array()); } $name = elgg_extract('name', $value); $tmp_name = elgg_extract('tmp_name', $value); $error_type = elgg_extract('error', $value); $has_uploaded_file = $error_type != UPLOAD_ERR_NO_FILE && $name && $tmp_name; if (!$has_uploaded_file) { return; } $icon_sizes = hypeApps()->iconFactory->getSizes($entity); $custom_icon_sizes = (array) $prop->{"icon_sizes"}; $icon_sizes = array_merge($icon_sizes, $custom_icon_sizes); if (empty($icon_sizes)) { return; } $image_upload_crop_coords = (array) elgg_extract('image_upload_crop_coords', $params, array()); $ratio_coords = (array) elgg_extract($prop_id, $image_upload_crop_coords, array()); list($master_width, $master_height) = getimagesize($_FILES[$prop_id]['tmp_name']); foreach ($icon_sizes as $icon_name => $icon_size) { $ratio = (int) $icon_size['w'] / (int) $icon_size['h']; $coords = (array) elgg_extract("{$ratio}", $ratio_coords, array()); $x1 = (int) elgg_extract('x1', $coords); $x2 = (int) elgg_extract('x2', $coords); $y1 = (int) elgg_extract('y1', $coords); $y2 = (int) elgg_extract('y2', $coords); if ($x2 <= $x1 || $y2 <= $y1) { // do not crop $this->tmp_coords = false; } else { $this->tmp_coords = $coords; $this->tmp_coords['master_width'] = $master_width; $this->tmp_coords['master_height'] = $master_height; } if (!isset($icon_size['name'])) { $icon_size['name'] = $icon_name; } $this->tmp_icon_sizes = array($icon_size['name'] => $icon_size); $options = array('icon_sizes' => $this->tmp_icon_sizes, 'coords' => $this->tmp_coords); elgg_register_plugin_hook_handler('entity:icon:sizes', 'object', array($this, 'resetIconSizesHook'), 999); if (hypeApps()->iconFactory->create($entity, $_FILES[$prop_id]['tmp_name'], $options)) { foreach (array('x1', 'x2', 'y1', 'y2') as $c) { $entity->{"_coord_{$ratio}_{$coord}"} = elgg_extract($c, $coords, 0); if ($ratio === 1) { $entity->{$c} = elgg_extract($c, $coords, 0); } } } elgg_unregister_plugin_hook_handler('entity:icon:sizes', 'object', array($this, 'resetIconSizesHook')); } return $entity; }
/** * {@inheritdoc} */ public function handle(\ElggEntity $entity) { $this->tmp_icon_sizes = array(); // make sure we do not duplicate icon creation elgg_register_plugin_hook_handler('entity:icon:sizes', 'object', array($this, 'getIconSizes'), 999); $result = parent::handle($entity); elgg_unregister_plugin_hook_handler('entity:icon:sizes', 'object', array($this, 'getIconSizes')); if (!$result) { return $entity; } $shortname = $this->getShortname(); $upload = $this->getValues($entity); $icon_sizes = hypeApps()->iconFactory->getSizes($upload); $custom_icon_sizes = (array) $this->input_vars->{"icon_sizes"}; $icon_sizes = array_merge($icon_sizes, $custom_icon_sizes); if (empty($icon_sizes)) { return $entity; } $image_upload_crop_coords = (array) get_input('image_upload_crop_coords', array()); $ratio_coords = (array) elgg_extract($shortname, $image_upload_crop_coords, array()); list($master_width, $master_height) = getimagesize($_FILES[$shortname]['tmp_name']); foreach ($icon_sizes as $icon_name => $icon_size) { $ratio = (int) $icon_size['w'] / (int) $icon_size['h']; $coords = (array) elgg_extract("{$ratio}", $ratio_coords, array()); $x1 = (int) elgg_extract('x1', $coords); $x2 = (int) elgg_extract('x2', $coords); $y1 = (int) elgg_extract('y1', $coords); $y2 = (int) elgg_extract('y2', $coords); if ($x2 <= $x1 || $y2 <= $y1) { // do not crop $this->tmp_coords = false; } else { $this->tmp_coords = $coords; $this->tmp_coords['master_width'] = $master_width; $this->tmp_coords['master_height'] = $master_height; } if (!isset($icon_size['name'])) { $icon_size['name'] = $icon_name; } $this->tmp_icon_sizes = array($icon_size['name'] => $icon_size); $options = array('icon_sizes' => $this->tmp_icon_sizes, 'coords' => $this->tmp_coords); elgg_register_plugin_hook_handler('entity:icon:sizes', 'object', array($this, 'getIconSizes'), 999); if (hypeApps()->iconFactory->create($upload, $_FILES[$shortname]['tmp_name'], $options)) { foreach (array('x1', 'x2', 'y1', 'y2') as $c) { $upload->{"_coord_{$ratio}_{$coord}"} = elgg_extract($c, $coords, 0); if ($ratio === 1) { $upload->{$c} = elgg_extract($c, $coords, 0); } } } elgg_unregister_plugin_hook_handler('entity:icon:sizes', 'object', array($this, 'getIconSizes')); } $upload->icontime = time(); return $entity; }
/** * {@inheritdoc} */ public function handle(ElggEntity $entity) { $value = get_input($this->getShortname()); if (!$entity->guid) { return $entity; } $old_owner_guid = $entity->owner_guid; $new_owner_guid = $value === null ? $old_owner_guid : (int) $value; $owner_has_changed = false; $old_icontime = null; if (!$new_owner_guid || $new_owner_guid == $old_owner_guid) { return $entity; } $user = elgg_get_logged_in_user_entity(); // verify new owner is member and old owner/admin is logged in if ($entity->isMember(get_user($new_owner_guid)) && ($old_owner_guid == $user->guid || $user->isAdmin())) { $entity->owner_guid = $new_owner_guid; if ($entity->container_guid == $old_owner_guid) { // Even though this action defaults container_guid to the logged in user guid, // the group may have initially been created with a custom script that assigned // a different container entity. We want to make sure we preserve the original // container if it the group is not contained by the original owner. $entity->container_guid = $new_owner_guid; } $metadata = elgg_get_metadata(['guid' => $entity->guid, 'limit' => false]); if ($metadata) { foreach ($metadata as $md) { if ($md->owner_guid == $old_owner_guid) { $md->owner_guid = $new_owner_guid; $md->save(); } } } // @todo Remove this when #4683 fixed $owner_has_changed = true; $old_icontime = $entity->icontime; } $must_move_icons = $owner_has_changed && $old_icontime; if ($must_move_icons) { $filehandler = new ElggFile(); $filehandler->setFilename('groups'); $filehandler->owner_guid = $old_owner_guid; $old_path = $filehandler->getFilenameOnFilestore(); $icon_sizes = hypeApps()->iconFactory->getSizes($entity); $sizes = array_keys($icon_sizes); array_unshift($sizes, ''); // move existing to new owner $filehandler->owner_guid = $entity->owner_guid; $new_path = $filehandler->getFilenameOnFilestore(); foreach ($sizes as $size) { rename("{$old_path}/{$entity->guid}{$size}.jpg", "{$new_path}/{$entity->guid}{$size}.jpg"); } } return $entity; }
/** * Saves uploaded file to ElggFile with given attributes * * @param array $attributes New file attributes and metadata * @apara string $prefix Filestore prefix * @return \Upload */ public function save(array $attributes = array(), $prefix = self::DEFAULT_FILESTORE_PREFIX) { $this->error_code = $this->error; $this->error = $this->getError(); $this->filesize = $this->size; $this->path = $this->tmp_name; $this->mimetype = $this->detectMimeType(); $this->simpletype = $this->parseSimpleType(); if (!$this->isSuccessful()) { return $this; } $prefix = trim($prefix, '/'); if (!$prefix) { $prefix = self::DEFAULT_FILESTORE_PREFIX; } $id = elgg_strtolower(time() . $this->name); $filename = implode('/', array($prefix, $id)); $type = elgg_extract('type', $attributes, 'object'); $subtype = elgg_extract('subtype', $attributes, 'file'); $class = get_subtype_class($type, $subtype); if (!$class) { $class = '\\ElggFile'; } try { $filehandler = new $class(); foreach ($attributes as $key => $value) { $filehandler->{$key} = $value; } $filehandler->setFilename($filename); $filehandler->title = $this->name; $filehandler->originalfilename = $this->name; $filehandler->filesize = $this->size; $filehandler->mimetype = $this->mimetype; $filehandler->simpletype = $this->simpletype; $filehandler->open("write"); $filehandler->close(); if ($this->simpletype == 'image') { $img = new \hypeJunction\Files\Image($this->tmp_name); $img->save($filehandler->getFilenameOnFilestore(), hypeApps()->config->getSrcCompressionOpts()); } else { move_uploaded_file($this->tmp_name, $filehandler->getFilenameOnFilestore()); } if ($filehandler->save()) { $this->guid = $filehandler->getGUID(); $this->file = $filehandler; } } catch (\Exception $ex) { elgg_log($ex->getMessage(), 'ERROR'); $this->error = elgg_echo('upload:error:unknown'); } return $this; }
public function init() { hypeApps()->actions->register('dropzone/upload', \hypeJunction\Dropzone\Actions\uploadAction::CLASSNAME); /** * JS, CSS and Views */ elgg_extend_view('css/elgg', 'css/dropzone/stylesheet'); if (\hypeJunction\Integration::isElggVersionAbove('1.9.0')) { elgg_define_js('dropzone/lib', array('src' => '/mod/hypeDropzone/vendors/dropzone/dropzone-amd-module.min.js', 'deps' => array('jquery'), 'exports' => 'dropzone')); } else { elgg_register_js('dropzone.min.js', '/mod/hypeDropzone/vendors/dropzone/dropzone.min.js', 'footer'); elgg_register_simplecache_view('js/dropzone/legacy/lib'); elgg_register_js('dropzone', elgg_get_simplecache_url('js', 'dropzone/legacy/dropzone')); } }
<?php use hypeJunction\Categories\Actions\SavePluginSettings; $result = hypeApps()->actions->execute(new SavePluginSettings()); forward($result->getForwardURL());
<?php use hypeJunction\Controllers\DeleteAction; $result = hypeApps()->actions->execute(new DeleteAction()); forward($result->getForwardURL());
<?php use hypeJunction\Categories\Actions\ManageCategories; $result = hypeApps()->actions->execute(new ManageCategories()); forward($result->getForwardURL());
<?php use hypeJunction\Inbox\Actions\DeleteMessage; $result = hypeApps()->actions->execute(new DeleteMessage()); forward($result->getForwardURL());
<?php use hypeJunction\Inbox\Actions\MarkAsUnread; $result = hypeApps()->actions->execute(new MarkAsUnread()); forward($result->getForwardURL());
/** * {@inheritdoc} * * @tip: if you are extending the category form, use can access these values in the volatileData of the category */ public function execute() { $nodes = array(); $config = $this->input_categories; foreach ($config['hierarchy'] as $key => $node_id) { $node_id = (int) $node_id; $guid = (int) $config['guid'][$key]; $title = $config['title'][$key]; $desc = $config['description'][$key]; $access_id = $config['access_id'][$key]; $subtype = $config['subtype'][$key]; $category = get_entity($guid); if (!$category) { $class = get_subtype_class('object', $subtype) ?: get_class(new ElggObject()); $category = new $class(); $category->subtype = $subtype ? $subtype : hypeCategories()->config->get('subtype'); $category->owner_guid = elgg_get_logged_in_user_guid(); $category->container_guid = $this->root_guid; } if (!$category) { $nodes[$node_id] = false; continue; } if (!$title) { $category->delete(); $nodes[$node_id] = false; continue; } else { $category->title = $title; $category->description = $desc; $category->access_id = $access_id; $category->priority = $key + 1; // we don't want 0 $form_values = array(); foreach ($config as $param_name => $entity_params) { $form_values[$param_name] = $entity_params[$key]; } $category->setVolatileData('formValues', $form_values); $category->save(); } if ($_FILES['categories']['error']['icon'][$key] == UPLOAD_ERR_OK) { hypeApps()->iconFactory->create($category, $_FILES['categories']['tmp_name']['icon'][$key]); } $nodes[$node_id] = $category; } $this->nodes = $nodes; foreach ($this->hierarchy as $key => $root) { $this->updateHierarchy((int) $root['id'], $root['children']); } $this->result->addMessage(elgg_echo('categories:manage:success')); }
/** * Static counterpart of makeFiles, but returns data for processed uploads * * @param string $input Name of the file input * @param array $attributes Key value pairs, such as subtype, owner_guid, metadata. * @param array $config Additional config * @return Upload[] An array of file entities created */ public static function handle($input, array $attributes = array(), array $config = array()) { return hypeApps()->uploader->handle($input, $attributes, $config); }
/** * {@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')); } }
<?php use hypeJunction\Wall\Actions\SavePost; $result = hypeApps()->actions->execute(new SavePost()); forward($result->getForwardURL());
<?php // $action might be defined in context $result = hypeApps()->actions->execute($action); if (elgg_is_xhr()) { echo $result->output; } forward($result->getForwardURL(), $result->getForwardReason());
<?php $result = hypeApps()->actions->execute(new \hypeJunction\Dropzone\Actions\uploadAction()); if (elgg_is_xhr()) { echo $result->output; } forward($result->getForwardURL());
<?php /** * Bootstrap for hypeJunction plugins * * @author Ismayil Khayredinov <*****@*****.**> * @copyright Copyright (c) 2015, Ismayil Khayredinov * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ try { require_once __DIR__ . '/lib/autoloader.php'; hypeApps()->boot(); } catch (Exception $ex) { register_error($ex->getMessage()); }
function hypeFilestore() { return hypeApps(); }
public static function getIcon(PropertyInterface $prop, $object, array $params = array()) { $icon = array(); if (!is_callable(array($object, 'getIconURL'))) { return $icon; } $icon_sizes = hypeApps()->iconFactory->getSizes($object); $size = elgg_extract('size', $params); if ($size && array_key_exists($size, $icon_sizes)) { $icon = $icon_sizes[$size]; $icon['url'] = $object->getIconURL(array('size' => $size, 'name' => $prop->getAttributeName())); $icon['size'] = $size; } else { foreach ($icon_sizes as $size => $params) { $icon[$size] = $object->getIconURL($size); } } return $icon; }
/** * Outputs raw icon * * @param int $entity_guid GUID of an entity * @param string $size Icon size * @return void */ public static function outputRawIcon($entity_guid = 0, $size = null) { return hypeApps()->iconFactory->outputRawIcon($entity_guid, $size); }
<?php use hypeJunction\Wall\Actions\UpdateGeopositioning; $result = hypeApps()->actions->execute(new UpdateGeopositioning()); forward($result->getForwardURL());
<?php use hypeJunction\Inbox\Actions\SendMessage; $result = hypeApps()->actions->execute(new SendMessage()); forward($result->getForwardURL());