static function fromFile(File $file) { $object = new ActivityObject(); if (Event::handle('StartActivityObjectFromFile', array($file, &$object))) { $object->type = self::mimeTypeToObjectType($file->mimetype); $object->id = TagURI::mint(sprintf("file:%d", $file->id)); $object->link = common_local_url('attachment', array('attachment' => $file->id)); if ($file->title) { $object->title = $file->title; } if ($file->date) { $object->date = $file->date; } try { $thumbnail = $file->getThumbnail(); $object->thumbnail = $thumbnail; } catch (UseFileAsThumbnailException $e) { $object->thumbnail = null; } catch (UnsupportedMediaException $e) { $object->thumbnail = null; } switch (self::canonicalType($object->type)) { case 'image': $object->largerImage = $file->getUrl(); break; case 'video': case 'audio': $object->stream = $file->getUrl(); break; } Event::handle('EndActivityObjectFromFile', array($file, &$object)); } return $object; }
/** * @param File $file * @return string */ protected function getThumbnailURLForFile(File $file) { if ($file->exists() && file_exists(Director::baseFolder() . '/' . $file->getFilename())) { $width = $this->getPreviewMaxWidth(); $height = $this->getPreviewMaxHeight(); if ($file->hasMethod('getThumbnail')) { return $file->getThumbnail($width, $height)->getURL(); } elseif ($file->hasMethod('getThumbnailURL')) { return $file->getThumbnailURL($width, $height); } elseif ($file->hasMethod('SetRatioSize')) { return $file->SetRatioSize($width, $height)->getURL(); } else { return $file->Icon(); } } return false; }
/** * @param File $file * @return string */ protected function getThumbnailURLForFile(File $file) { if ($file && $file->exists() && file_exists(Director::baseFolder() . '/' . $file->getFilename())) { if ($file->hasMethod('getThumbnail')) { return $file->getThumbnail($this->getConfig('previewMaxWidth'), $this->getConfig('previewMaxHeight'))->getURL(); } elseif ($file->hasMethod('getThumbnailURL')) { return $file->getThumbnailURL($this->getConfig('previewMaxWidth'), $this->getConfig('previewMaxHeight')); } elseif ($file->hasMethod('SetRatioSize')) { return $file->SetRatioSize($this->getConfig('previewMaxWidth'), $this->getConfig('previewMaxHeight'))->getURL(); } else { return $file->Icon(); } } return false; }