Example #1
0
 /**
  * Filter icon URLs to route requests via a faster handler
  *
  * @param string $hook   "entity:icon:url"
  * @param string $type   "all"
  * @param string $return URL
  * @param array  $params Hook params
  * @return string
  */
 function handleEntityIconUrls($hook, $type, $return, $params)
 {
     if (!is_null($return)) {
         // another plugin has already replaced the icon URL
         return $return;
     }
     $entity = elgg_extract('entity', $params);
     $size = elgg_extract('size', $params, 'medium');
     if (!$entity->icontime || !array_key_exists($size, $this->iconFactory->getSizes($entity))) {
         // icon has not yet been created or the icon size is unknown
         return $return;
     }
     return $this->iconFactory->getURL($entity, $size);
 }
Example #2
0
 /**
  * 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 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;
 }