/** * Add items to the file entity menu * * @param string $hook the name of the hook * @param string $type the type of the hook * @param ElggMenuItem[] $return_value current return value * @param array $params supplied params * * @return void|ElggMenuItem[] */ public static function registerFile($hook, $type, $return_value, $params) { $entity = elgg_extract('entity', $params); if (!$entity instanceof \ElggFile) { return; } $return_value[] = \ElggMenuItem::factory(['name' => 'download', 'text' => elgg_view_icon('download'), 'title' => elgg_echo('download'), 'href' => elgg_get_download_url($entity), 'priority' => 200]); return $return_value; }
/** * Get a URL to the alternative format of the video/audio file * * @param ElggFile $file File entity * @param string $format Video format (extension) * @return string */ function elgg_file_viewer_get_media_url($file, $format) { if (!$file instanceof ElggFile) { return ''; } $info = pathinfo($file->getFilenameOnFilestore()); $filename = $info['filename']; $output = new ElggFile(); $output->owner_guid = $file->owner_guid; $output->setFilename("projekktor/{$file->guid}/{$filename}.{$format}"); // if (!$output->exists() && elgg_get_plugin_setting('enable_ffmpeg', 'elgg_file_viewer')) { // $output = elgg_file_viewer_convert_file($file, $format); // } return elgg_get_download_url($output); }
<?php /** * Display an image * * @uses $vars['entity'] */ $file = $vars['entity']; $image_url = $file->getIconURL('large'); $image_url = elgg_format_url($image_url); $download_url = elgg_get_download_url($file); if ($vars['full_view']) { echo <<<HTML \t\t<div class="file-photo"> \t\t\t<a href="{$download_url}" class="elgg-lightbox-photo"><img class="elgg-photo" src="{$image_url}" /></a> \t\t</div> HTML; }
default: case 'video': $tag = 'video'; $mimes = array_unique([$entity_mime, 'video/mp4', 'video/webm', 'video/ogv']); $attr['poster'] = $entity->icontime ? $entity->getIconURL('master') : elgg_get_simplecache_url('elgg_file_viewer/video.jpg'); break; case 'audio': $tag = 'audio'; $mimes = array_unique([$entity_mime, 'audio/mpeg', 'audio/ogg', 'video/wav']); $attr['poster'] = $entity->icontime ? $entity->getIconURL('master') : elgg_get_simplecache_url('elgg_file_viewer/audio.jpg'); break; } $sources = ''; foreach ($mimes as $mime) { if ($mime == $entity_mime) { $url = elgg_get_download_url($entity); } else { list(, $ext) = explode('/', $mime); $url = elgg_file_viewer_get_media_url($entity, $ext); } if ($url) { $sources .= elgg_format_element('source', ['src' => $url, 'type' => $mime]); } } elgg_load_css('videojs'); ?> <div class="elgg-col elgg-col-1of1 clearfix"> <?php echo elgg_format_element($tag, $attr, $sources); ?> </div>
<?php /** * Display an image * * @uses $vars['entity'] */ $full = elgg_extract('full_view', $vars); $file = elgg_extract('entity', $vars); if (!$full || !$file instanceof ElggFile) { return; } elgg_load_js('lightbox'); elgg_load_css('lightbox'); $img = elgg_view('output/img', ['alt' => $file->getDisplayName(), 'src' => $file->getIconURL('master'), 'class' => 'elgg-photo']); $link = elgg_view('output/url', ['text' => $img, 'href' => elgg_get_download_url($file, true), 'class' => 'elgg-lightbox-photo']); echo elgg_format_element('div', ['class' => 'file-photo'], $link);
<?php $entity = elgg_extract('entity', $vars); if (!images()->isImage($entity)) { return; } ?> <div class="elgg-text-help"> <?php echo elgg_echo('images:crop:instructions'); ?> </div> <div> <?php echo elgg_view('input/cropper', ['src' => elgg_get_download_url($entity), 'name' => 'crop_coords', 'x1' => $entity->x1, 'y1' => $entity->y1, 'x2' => $entity->x2, 'y2' => $entity->y2]); ?> </div> <div class="elgg-foot"> <?php echo elgg_view('input/hidden', ['name' => 'guid', 'value' => $entity->guid]); echo elgg_view('input/submit', ['value' => elgg_echo('images:thumbs')]); ?> </div>
<?php /** * Link to download the file * * @uses $vars['entity'] */ if (elgg_instanceof($vars['entity'], 'object', 'file')) { $download_url = elgg_get_download_url($vars['entity']); $size = $vars['entity']->getSize(); $mime_type = $vars['entity']->getMimeType(); echo <<<END \t<enclosure url="{$download_url}" length="{$size}" type="{$mime_type}" /> END; }
<?php /** * View a file * * @package ElggFile */ $guid = elgg_extract('guid', $vars); elgg_entity_gatekeeper($guid, 'object', 'file'); $file = get_entity($guid); $owner = elgg_get_page_owner_entity(); elgg_group_gatekeeper(); elgg_push_breadcrumb(elgg_echo('file'), 'file/all'); $crumbs_title = $owner->name; if (elgg_instanceof($owner, 'group')) { elgg_push_breadcrumb($crumbs_title, "file/group/{$owner->guid}/all"); } else { elgg_push_breadcrumb($crumbs_title, "file/owner/{$owner->username}"); } $title = $file->title; elgg_push_breadcrumb($title); $content = elgg_view_entity($file, array('full_view' => true)); $content .= elgg_view_comments($file); elgg_register_menu_item('title', array('name' => 'download', 'text' => elgg_echo('download'), 'href' => elgg_get_download_url($file), 'link_class' => 'elgg-button elgg-button-action')); $body = elgg_view_layout('content', array('content' => $content, 'title' => $title, 'filter' => '')); echo elgg_view_page($title, $body);
/** * Get the download url for this export * * @return false|string */ public function getDownloadURL() { $fo = $this->getFileObject(); if (empty($fo) || !$fo->exists()) { return false; } return elgg_get_download_url($fo, true); }
<?php /** * Elgg file download. * * @package ElggFile * @deprecated since version 3.0 */ elgg_deprecated_notice('/file/download resource view has been deprecated and will be removed. Use elgg_get_download_url() to build download URLs', '3.0'); // Get the guid $file_guid = elgg_extract("guid", $vars); // Get the file $file = get_entity($file_guid); if (!elgg_instanceof($file, 'object', 'file')) { register_error(elgg_echo("file:downloadfailed")); forward(); } forward(elgg_get_download_url($file));
/** * {@inheritdoc} */ public function getDownloadUrl() { return elgg_get_download_url($this, true); }
echo elgg_view('output/url', array('text' => 'Open inline HTML lightbox', 'href' => '#lightbox-inline', 'class' => 'elgg-lightbox-inline mll')); elgg_require_js('theme_sandbox/javascript/lightbox'); ?> <div class="hidden"> <div id="lightbox-inline"> <?php echo elgg_view('developers/ipsum'); ?> </div> </div> <?php $files = elgg_get_entities_from_metadata(array('types' => 'object', 'subtypes' => 'file', 'metadata_name_value_paris' => ['name' => 'simpletype', 'value' => 'image'])); if (!$files) { return; } echo elgg_view('output/url', array('text' => 'Open photo lightbox', 'href' => elgg_get_download_url($files[0]), 'class' => 'elgg-lightbox-photo mll')); ?> <ul class="elgg-gallery elgg-gallery-fluid"> <?php foreach ($files as $file) { ?> <li class="pam"> <?php echo elgg_view('output/url', array('text' => elgg_view('output/img', array('src' => $file->getIconURL('small'), 'alt' => $file->getDisplayName())), 'href' => $file->getIconURL('large'), 'rel' => 'lightbox-gallery')); ?> </li> <?php } ?> </ul>
<?php $event = elgg_extract('entity', $vars); if (!$event) { return; } $files = json_decode($event->files); if (empty($files)) { return; } $rows = ''; $elggfile = new \ElggFile(); $elggfile->owner_guid = $event->guid; $use_cookie = $event->access_id !== ACCESS_PUBLIC; foreach ($files as $file) { $elggfile->setFilename("files/{$file->file}"); $link = elgg_view('output/url', ['href' => elgg_get_download_url($elggfile, $use_cookie), 'text' => $file->title]); $delete = elgg_view('output/url', ['href' => "action/event_manager/event/deletefile?guid={$event->getGUID()}&file={$file->file}", 'text' => elgg_view_icon('delete'), 'confirm' => true]); $rows .= "<tr><td>{$link}</td><td>{$delete}</td></tr>"; } $content = elgg_format_element('table', ['class' => 'elgg-table'], $rows); echo elgg_view_module('info', elgg_echo('event_manager:edit:form:files'), $content, ['class' => 'mtm']);
<?php elgg_push_context('images/view'); $guid = elgg_extract('guid', $vars); $entity = get_entity($guid); if (!images()->isImage($entity)) { forward('', '404'); } $container = $entity->getContainerEntity(); elgg_set_page_owner_guid($entity->container_guid); elgg_group_gatekeeper(); elgg_push_breadcrumb(elgg_echo('images'), '/images/all'); if ($container) { elgg_push_breadcrumb($container->getDisplayName(), "/images/all/{$entity->container_guid}"); } elgg_push_breadcrumb($entity->getDisplayName()); elgg_register_menu_item('title', ['name' => 'download', 'text' => elgg_echo('images:download'), 'href' => elgg_get_download_url($entity), 'class' => 'elgg-button elgg-button-action']); if ($entity->canEdit()) { elgg_register_menu_item('title', ['name' => 'edit', 'text' => elgg_echo('edit'), 'href' => "/images/edit/{$entity->guid}", 'class' => 'elgg-button elgg-button-action']); } $content = elgg_view('lists/images/item', ['entity' => $entity, 'full_view' => true]); if (elgg_is_xhr()) { echo $content; } else { $body = elgg_view_layout('content', ['content' => $content, 'title' => $entity->getDisplayName(), 'filter' => '', 'entity' => $entity]); echo elgg_view_page($title, $body, 'default', ['entity' => $entity]); }