Example #1
0
/**
 * Image icon URL handler
 *
 * @param string $hook   "entity:icon:url"
 * @param string $type   "object"
 * @param string $return URL
 * @param array  $params Hook params
 * @return array
 */
function images_entity_icon_url($hook, $type, $return, $params)
{
    $size = elgg_extract('size', $params, 'medium');
    $entity = elgg_extract('entity', $params);
    if (!$entity instanceof ElggEntity || !$entity->icontime) {
        return;
    }
    if ($entity->getSubtype() == 'file' && !elgg_get_plugin_setting('override_file_thumb_dimensions', 'images')) {
        return;
    }
    if (elgg_images_is_image($entity)) {
        $thumb = elgg_images_get_thumb($entity, $size);
    } else {
        $avatar = elgg_images_get_avatar($entity);
        if ($avatar) {
            $thumb = elgg_images_get_thumb($avatar, $size);
        }
    }
    if (!$thumb instanceof ElggFile) {
        return;
    }
    $url = elgg_get_inline_url($thumb, true);
    if (!$url) {
        return;
    }
    return $url;
}
Example #2
0
 /**
  * (non-PHPdoc)
  * @see ElggEntity::getIconURL()
  */
 public function getIconURL($params = array())
 {
     if (is_array($params)) {
         $size = elgg_extract('size', $params, 'medium');
     } else {
         $size = is_string($params) ? $params : 'medium';
     }
     if ($this->icontime) {
         $file = new \ElggFile();
         $file->owner_guid = $this->guid;
         $file->setFilename("thumb{$size}.jpg");
         return elgg_get_inline_url($file);
     }
 }
Example #3
0
/**
 * User avatar icon URL handler
 *
 * @param string $hook   "entity:icon:url"
 * @param string $type   "object"
 * @param string $return URL
 * @param array  $params Hook params
 * @return array
 */
function avatars_user_icon_url($hook, $type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    $size = elgg_extract('size', $params);
    $avatar = avatars_get_avatar($entity);
    if (!$avatar) {
        return;
    }
    $thumb = images()->getThumb($avatar, $size);
    if (!$thumb) {
        return;
    }
    return elgg_get_inline_url($thumb, false);
}
Example #4
0
/**
 * Handle video file icon URLs
 * 
 * @param string $hook   "entity:icon:url"
 * @param string $type   "object"
 * @param string $return URL
 * @param array  $params Hook params
 * @return string
 */
function elgg_file_view_set_video_icon_url($hook, $type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    if (!$entity instanceof ElggFile || !$entity->icontime || !$entity->ffmpeg_thumb) {
        return;
    }
    $size = elgg_extract('size', $params, 'medium');
    switch ($size) {
        case "small":
            $thumbfile = $entity->thumbnail;
            break;
        case "medium":
            $thumbfile = $entity->smallthumb;
            break;
        case "large":
        default:
            $thumbfile = $entity->largethumb;
            break;
    }
    $icon = new ElggFile();
    $icon->owner_guid = $entity->owner_guid;
    $icon->setFilename($thumbfile);
    $url = elgg_get_inline_url($icon);
    if ($url) {
        return $url;
    }
}
Example #5
0
 /**
  * Return the events icon url
  *
  * @param string $size size of the icon
  *
  * @return void|string
  *
  * @see ElggEntity::getIconURL()
  */
 public function getIconURL($size = 'medium')
 {
     $size = strtolower($size);
     $iconsizes = elgg_get_icon_sizes('object', 'event');
     if (!array_key_exists($size, $iconsizes)) {
         $size = 'medium';
     }
     $icontime = $this->icontime;
     if (!$icontime) {
         return;
     }
     $file = new \ElggFile();
     $file->owner_guid = $this->guid;
     $file->setFilename("{$size}.jpg");
     if ($size === 'event_banner' && !$file->exists()) {
         $file->setFilename("master.jpg");
     }
     return elgg_get_inline_url($file);
 }
Example #6
0
$file_guid = (int) get_input('file_guid', 0);
// Get file thumbnail size
$size = get_input('size', 'small');
$file = get_entity($file_guid);
$thumb_url = false;
// thumbnails get first priority
if ($file && $file->thumbnail) {
    switch ($size) {
        case "small":
            $thumbfile = $file->thumbnail;
            break;
        case "medium":
            $thumbfile = $file->smallthumb;
            break;
        case "large":
        default:
            $thumbfile = $file->largethumb;
            break;
    }
    if (!empty($thumbfile)) {
        $readfile = new ElggFile();
        $readfile->owner_guid = $file->owner_guid;
        $readfile->setFilename($thumbfile);
        $thumb_url = elgg_get_inline_url($readfile, true);
    }
}
if ($thumb_url) {
    forward($thumb_url);
}
header('HTTP/1.1 404 Not found');
exit;
Example #7
0
 /**
  * Add menu items listing of event files
  *
  * @param string $hook        hook name
  * @param string $entity_type hook type
  * @param array  $returnvalue current return value
  * @param array  $params      parameters
  *
  * @return array
  */
 public static function registerEventFiles($hook, $entity_type, $returnvalue, $params)
 {
     $event = elgg_extract('entity', $params);
     if (!$event instanceof \Event) {
         return;
     }
     $files = $event->hasFiles();
     if (empty($files)) {
         return;
     }
     $elggfile = new \ElggFile();
     $elggfile->owner_guid = $event->guid;
     $use_cookie = $event->access_id !== ACCESS_PUBLIC;
     foreach ($files as $file) {
         $elggfile->setFilename("files/{$file->file}");
         $returnvalue[] = \ElggMenuItem::factory(['name' => $file->title, 'text' => elgg_view_icon('download', 'mrs') . $file->title, 'href' => elgg_get_inline_url($elggfile, $use_cookie)]);
     }
     return $returnvalue;
 }
Example #8
0
File: users.php Project: elgg/elgg
/**
 * Set user avatar URL
 * Replaces user avatar URL with a public URL when walled garden is disabled
 *
 * @param string $hook   "entity:icon:url"
 * @param string $type   "user"
 * @param string $return Icon URL
 * @param array  $params Hook params
 * @return string
 * @access private
 */
function user_avatar_hook($hook, $type, $return, $params)
{
    $user = elgg_extract('entity', $params);
    $size = elgg_extract('size', $params, 'medium');
    if (!$user instanceof ElggUser) {
        return;
    }
    if (elgg_get_config('walled_garden')) {
        return;
    }
    if (!$user->hasIcon($size, 'icon')) {
        return;
    }
    $icon = $user->getIcon($size, 'icon');
    return elgg_get_inline_url($icon, false);
}
Example #9
0
 /**
  * @group IconService
  */
 public function testCanResolveDefaultIconURL()
 {
     $service = $this->createService();
     $local_file = $this->config()->get('dataroot') . '1/1/400x300.png';
     $service->saveIconFromLocalFile($this->entity, $local_file);
     $this->assertTrue($service->hasIcon($this->entity, 'small'));
     $icon = $service->getIcon($this->entity, 'small');
     $this->assertEquals(elgg_get_inline_url($icon, true), $service->getIconURL($this->entity, 'small'));
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function getInlineUrl()
 {
     return elgg_get_inline_url($this, true);
 }
Example #11
0
 public function getInlineURL()
 {
     return elgg_get_inline_url($this, false, false);
 }
Example #12
0
File: start.php Project: elgg/elgg
/**
 * Override the default entity icon for files
 *
 * Plugins can override or extend the icons using the plugin hook: 'file:icon:url', 'override'
 *
 * @param string $hook
 * @param string $type
 * @param string $url
 * @param array  $params
 * @return string Relative URL
 */
function file_set_icon_url($hook, $type, $url, $params)
{
    $file = $params['entity'];
    $size = elgg_extract('size', $params, 'large');
    if (elgg_instanceof($file, 'object', 'file')) {
        // thumbnails get first priority
        $thumbnail = $file->getIcon($size);
        $thumb_url = elgg_get_inline_url($thumbnail, true);
        if ($thumb_url) {
            return $thumb_url;
        }
        $mapping = array('application/excel' => 'excel', 'application/msword' => 'word', 'application/ogg' => 'music', 'application/pdf' => 'pdf', 'application/powerpoint' => 'ppt', 'application/vnd.ms-excel' => 'excel', 'application/vnd.ms-powerpoint' => 'ppt', 'application/vnd.oasis.opendocument.text' => 'openoffice', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'word', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'excel', 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'ppt', 'application/x-gzip' => 'archive', 'application/x-rar-compressed' => 'archive', 'application/x-stuffit' => 'archive', 'application/zip' => 'archive', 'text/directory' => 'vcard', 'text/v-card' => 'vcard', 'application' => 'application', 'audio' => 'music', 'text' => 'text', 'video' => 'video');
        $mime = $file->getMimeType();
        if ($mime) {
            $base_type = substr($mime, 0, strpos($mime, '/'));
        } else {
            $mime = 'none';
            $base_type = 'none';
        }
        if (isset($mapping[$mime])) {
            $type = $mapping[$mime];
        } elseif (isset($mapping[$base_type])) {
            $type = $mapping[$base_type];
        } else {
            $type = 'general';
        }
        if ($size == 'large') {
            $ext = '_lrg';
        } else {
            $ext = '';
        }
        $url = elgg_get_simplecache_url("file/icons/{$type}{$ext}.gif");
        $url = elgg_trigger_plugin_hook('file:icon:url', 'override', $params, $url);
        return $url;
    }
}
Example #13
0
 /**
  * Get the URL for this entity's icon
  *
  * Plugins can register for the 'entity:icon:url', <type> plugin hook to customize the icon for an entity.
  *
  * @param ElggEntity $entity Entity that owns the icon
  * @param mixed      $params A string defining the size of the icon (e.g. tiny, small, medium, large)
  *                           or an array of parameters including 'size'
  * @return string|void
  */
 public function getIconURL(ElggEntity $entity, $params = array())
 {
     if (is_array($params)) {
         $size = elgg_extract('size', $params, 'medium');
     } else {
         $size = is_string($params) ? $params : 'medium';
         $params = array();
     }
     $size = elgg_strtolower($size);
     $params['entity'] = $entity;
     $params['size'] = $size;
     $type = elgg_extract('type', $params) ?: 'icon';
     $entity_type = $entity->getType();
     $url = $this->hooks->trigger("entity:{$type}:url", $entity_type, $params, null);
     if ($url == null) {
         if ($this->hasIcon($entity, $size, $type)) {
             $icon = $this->getIcon($entity, $size, $type);
             $url = elgg_get_inline_url($icon, true);
         } else {
             $url = $this->getFallbackIconUrl($entity, $params);
         }
     }
     if ($url) {
         return elgg_normalize_url($url);
     }
 }
 /**
  * Parse and scrape a URL
  *
  * @param string $url   URL
  * @param bool   $flush Flush existing URL data
  * @return array|false
  * @throws \InvalidArgumentException
  */
 public function parse($url, $flush = false)
 {
     if (!filter_var($url, FILTER_VALIDATE_URL)) {
         throw new \InvalidArgumentException(__METHOD__ . ' expects a valid URL');
     }
     if ($flush) {
         $this->delete($url);
     } else {
         $data = $this->get($url);
         if (isset($data)) {
             return $data;
         }
     }
     $response = $this->parser->request($url);
     if (!$response instanceof \GuzzleHttp\Psr7\Response || $response->getStatusCode() != 200) {
         $this->save($url, false);
         return false;
     }
     $post_max_size = elgg_get_ini_setting_in_bytes('post_max_size');
     $upload_max_filesize = elgg_get_ini_setting_in_bytes('upload_max_filesize');
     $max_upload = $upload_max_filesize > $post_max_size ? $post_max_size : $upload_max_filesize;
     if ((int) $response->getHeader('Content-Length') > $max_upload) {
         // Large images eat up memory
         $this->save($url, false);
         return false;
     }
     $data = $this->parser->parse($url);
     if (!$data) {
         $this->save($url, false);
         return false;
     }
     $type = elgg_extract('type', $data);
     switch ($type) {
         case 'photo':
         case 'image':
             $image = $this->saveImageFromUrl($url);
             if ($image instanceof ElggFile) {
                 $data['width'] = $image->natural_width;
                 $data['height'] = $image->natural_height;
                 $data['filename'] = $image->getFilename();
                 $data['owner_guid'] = $image->owner_guid;
                 $data['thumbnail_url'] = elgg_get_inline_url($image);
             }
             break;
         default:
             $assets = [];
             $thumbnails = (array) elgg_extract('thumbnails', $data, []);
             $icons = (array) elgg_extract('icons', $data, []);
             // Try 3 images and choose the one with highest dimensions
             $thumbnails = $thumbnails + $icons;
             $thumbs_parse = 0;
             foreach ($thumbnails as $thumbnail) {
                 if ($thumbnail == $url) {
                     continue;
                 }
                 $thumbnail = elgg_normalize_url($thumbnail);
                 if (filter_var($thumbnail, FILTER_VALIDATE_URL)) {
                     $asset = $this->parse($thumbnail, $flush);
                     if ($asset) {
                         $thumbs_parsed++;
                         $assets[] = $asset;
                     }
                 }
                 if ($thubms_parsed == 3) {
                     break;
                 }
             }
             $data['assets'] = array_values(array_filter($assets));
             usort($data['assets'], function ($a, $b) {
                 if ($a['width'] == $b['width'] && $a['height'] == $b['height']) {
                     return 0;
                 }
                 return $a['width'] > $b['width'] || $a['height'] > $b['height'] ? -1 : 1;
             });
             if (isset($data['assets'][0]['thumbnail_url'])) {
                 $data['thumbnail_url'] = $data['assets'][0]['thumbnail_url'];
             }
             break;
     }
     $data = elgg_trigger_plugin_hook('parse', 'framework:scraper', array('url' => $url), $data);
     $this->save($url, $data);
     return $data;
 }