Example #1
0
File: Linker.php Project: paladox/2
 /**
  * Create a direct link to a given uploaded file.
  * This will make a broken link if $file is false.
  *
  * @param Title $title
  * @param File|bool $file File object or false
  * @param string $html Pre-sanitized HTML
  * @return string HTML
  *
  * @todo Handle invalid or missing images better.
  */
 public static function makeMediaLinkFile(Title $title, $file, $html = '')
 {
     if ($file && $file->exists()) {
         $url = $file->getURL();
         $class = 'internal';
     } else {
         $url = self::getUploadUrl($title);
         $class = 'new';
     }
     $alt = $title->getText();
     if ($html == '') {
         $html = $alt;
     }
     $ret = '';
     $attribs = array('href' => $url, 'class' => $class, 'title' => $alt);
     if (!Hooks::run('LinkerMakeMediaLinkFile', array($title, $file, &$html, &$attribs, &$ret))) {
         wfDebug("Hook LinkerMakeMediaLinkFile changed the output of link " . "with url {$url} and text {$html} to {$ret}\n", true);
         return $ret;
     }
     return Html::rawElement('a', $attribs, $html);
 }
 /**
  * Sends the given file by whatever method is appropriate. Uses php's
  * header() instead of silverstripe's HTTPResponse class to prevent other
  * headers from being added and so we can just use readfile() instead of
  * pulling the whole file into a string for setBody().
  *
  * @param File $file
  */
 protected function sendFile(File $file)
 {
     // this is for optional compatibility with markguinn/silverstripe-cloudassets
     if ($file->hasExtension('CloudFileExtension') && $file->CloudStatus === 'Live') {
         header('Location: ' . $file->getAbsoluteURL());
         exit;
     }
     // this is the normal way to send the files
     header('Content-Type: application/octet-stream');
     header('Content-Disposition: attachment; filename="' . $file->Name . '"');
     if (Config::inst()->get('Downloadable', 'use_xsendfile')) {
         header('X-Sendfile: ' . $file->getURL());
     } else {
         header('Content-Length: ' . $file->getAbsoluteSize());
         readfile($file->getFullPath());
     }
     exit;
 }
 /**
  * Get a ThumbnailImage that respresents an image that will be scaled
  * client side
  *
  * @param File $image File associated with this thumbnail
  * @param array $scalerParams Array with scaler params
  * @return ThumbnailImage
  *
  * @todo FIXME: No rotation support
  */
 protected function getClientScalingThumbnailImage($image, $scalerParams)
 {
     $params = array('width' => $scalerParams['clientWidth'], 'height' => $scalerParams['clientHeight']);
     return new ThumbnailImage($image, $image->getURL(), null, $params);
 }
Example #4
0
 /**
  * Adds some metadata to a {@link File} object that is used by the view. This function
  * allows us to avoid having to use a decorator on the {@link File} class.
  *
  * @param File
  * @return array
  */
 protected function getFields(File $f)
 {
     if ($f instanceof Folder) {
         return array('Link' => $this->Link($this->getBrowseAction() . '/' . $f->ID), 'Item' => $f);
     }
     $image = $f instanceof Image;
     $tooltipurl = "";
     if ($image) {
         if ($f->getHeight() > 64 || $f->getWidth() > 64) {
             if ($f->getOrientation() == Image::ORIENTATION_SQUARE || $f->getOrientation() == Image::ORIENTATION_LANDSCAPE) {
                 $tooltipurl = $f->getWidth() > self::$tooltip_size ? $f->SetWidth(self::$tooltip_size)->getURL() : $f->getURL();
             } else {
                 $tooltipurl = $f->getHeight() > self::$tooltip_size ? $f->setHeight(self::$tooltip_size)->getURL() : $f->getURL();
             }
         }
     }
     return array('Link' => '', 'Item' => $f, 'IconURL' => $image ? ($i = $f->SetHeight(64)) ? $i->getURL() : KickAssetUtil::get_icon($f) : KickAssetUtil::get_icon($f), 'Image' => $image, 'TooltipURL' => $tooltipurl);
 }
 public function getURL()
 {
     $this->createLocalIfNeeded();
     return $this->CloudStatus == 'Live' ? $this->getCloudURL() : parent::getURL();
 }
 /**
  * Gets the source image URL for this resource
  * 
  * @return string
  */
 public function getSourceURL()
 {
     return parent::getURL();
 }
Example #7
0
 /**
  * Create a direct link to a given uploaded file.
  * This will make a broken link if $file is false.
  *
  * @param Title $title
  * @param File|bool $file File object or false
  * @param string $html Pre-sanitized HTML
  * @return string HTML
  *
  * @todo Handle invalid or missing images better.
  */
 public static function makeMediaLinkFile(Title $title, $file, $html = '')
 {
     if ($file && $file->exists()) {
         $url = $file->getURL();
         $class = 'internal';
     } else {
         $url = self::getUploadUrl($title);
         $class = 'new';
     }
     $alt = htmlspecialchars($title->getText(), ENT_QUOTES);
     if ($html == '') {
         $html = $alt;
     }
     $u = htmlspecialchars($url);
     return "<a href=\"{$u}\" class=\"{$class}\" title=\"{$alt}\">{$html}</a>";
 }