/** * 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 Image($this->tmp_name); $img->save($filehandler->getFilenameOnFilestore(), hypeFilestore()->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; }
/** * 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 hypeFilestore()->iconFactory->outputRawIcon($entity_guid, $size); }
<?php /** * File and image handling utilities * * @author Ismayil Khayredinov <*****@*****.**> * @copyright Copyright (c) 2011-2015, Ismayil Khayredinov * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 */ require_once __DIR__ . '/lib/autoloader.php'; elgg_register_event_handler('init', 'system', function () { hypeFilestore()->hooks->init(); /** * JS/CSS */ elgg_register_css('cropper', '/mod/hypeFilestore/vendors/cropper/dist/cropper.min.css'); elgg_define_js('cropper', array('src' => '/mod/hypeFilestore/vendors/cropper/dist/cropper.min.js', 'deps' => array('jquery'))); });
/** * 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 hypeFilestore()->uploader->handle($input, $attributes, $config); }