Esempio n. 1
0
File: Uploader.php Progetto: n8b/VMN
 /**
  * Create new ElggFile entities from uploaded files
  *
  * @param string $input      Name of the file input
  * @param array  $attributes Attributes and metadata for saving files
  * @param array  $options    Additional factory options (including entity attributes such as type, subtype, owner_guid, container_guid, access_id etc
  *                             'icon_sizes'            ARR Optional. An array of icon sizes to create (for image uploads)
  *                             'coords'                ARR Optional. Coordinates for icon cropping
  *                             'filestore_prefix'      STR Optional. Custom prefix on Elgg filestore
  *                             'icon_filestore_prefix' STR Optional. Custom prefix for created icons on Elgg filestore
  * @return \ElggFile[]
  */
 public function handle($input = '', array $attributes = array(), array $options = array())
 {
     $result = array();
     $uploads = $this->getUploads($input);
     $filestore_prefix = elgg_extract('filestore_prefix', $options, $this->config->getDefaultFilestorePrefix());
     unset($options['filestore_prefix']);
     foreach ($uploads as $props) {
         $upload = new \hypeJunction\Files\Upload($props);
         $upload->save($attributes, $filestore_prefix);
         if ($upload->file instanceof \ElggEntity && $upload->simpletype == 'image') {
             $this->iconFactory->create($upload->file, null, $options);
         }
         $result[] = $upload;
     }
     return $result;
 }
Esempio n. 2
0
 /**
  * Determines and normalizes the directory in which the icon is stored
  *
  * @param \ElggEntity $entity    Entity
  * @param string     $size      Icon size
  * @param string     $directory Default directory
  * @return string
  */
 public function getIconDirectory(\ElggEntity $entity, $size = null, $directory = null)
 {
     $sizes = $this->getSizes($entity);
     if (isset($sizes[$size]['metadata_name'])) {
         $md_name = $sizes[$size]['metadata_name'];
         if ($entity->{$md_name}) {
             $directory = '';
         }
     }
     if ($directory === null) {
         $directory = $directory ?: $entity->icon_directory;
         if ($entity instanceof \ElggUser) {
             $directory = 'profile';
         } else {
             if ($entity instanceof \ElggGroup) {
                 $directory = 'groups';
             } else {
                 $directory = $this->config->getDefaultIconDirectory();
             }
         }
     }
     $directory = elgg_trigger_plugin_hook('entity:icon:directory', $entity->getType(), array('entity' => $entity, 'size' => $size), $directory);
     return trim($directory, '/');
 }