function showRepresentation() {
if (Event::handle('StartShowAttachmentRepresentation', array($this->out, $this->attachment))) {
if (!empty($this->attachment->mimetype)) {
- switch ($this->attachment->mimetype) {
- case 'image/gif':
- case 'image/png':
- case 'image/jpg':
- case 'image/jpeg':
+ $mediatype = common_get_mime_media($this->attachment->mimetype);
+ switch ($mediatype) {
+ // Anything we understand as an image, if we need special treatment, do it in StartShowAttachmentRepresentation
+ case 'image':
try {
// Tell getThumbnail that we can show an animated image if it has one (4th arg, "force_still")
$thumb = $this->attachment->getThumbnail(null, null, false, false);
}
break;
- case 'application/ogg':
- $arr = array('type' => $this->attachment->mimetype,
- 'data' => $this->attachment->url,
- 'width' => 320,
- 'height' => 240
- );
- $this->out->elementStart('object', $arr);
- $this->out->element('param', array('name' => 'src', 'value' => $this->attachment->url));
- $this->out->element('param', array('name' => 'autoStart', 'value' => 1));
- $this->out->elementEnd('object');
- break;
-
- case 'audio/ogg':
- case 'audio/x-speex':
- case 'video/mpeg':
- case 'audio/mpeg':
- case 'video/mp4':
- case 'video/ogg':
- case 'video/quicktime':
- case 'video/webm':
- $mediatype = common_get_mime_media($this->attachment->mimetype);
+ // HTML5 media elements
+ case 'audio':
+ case 'video':
try {
$thumb = $this->attachment->getThumbnail();
$poster = $thumb->getUrl();
'poster'=>$poster,
'controls'=>'controls'));
$this->out->element('source',
- array('src'=>$this->attachment->url,
+ array('src'=>$this->attachment->getUrl(),
'type'=>$this->attachment->mimetype));
$this->out->elementEnd($mediatype);
break;
- case 'text/html':
- if (!empty($this->attachment->filename)
- && (GNUsocial::isAjax() || common_config('attachments', 'show_html'))) {
- // Locally-uploaded HTML. Scrub and display inline.
- $this->showHtmlFile($this->attachment);
+ default:
+ switch ($this->attachment->mimetype) {
+ // Ogg media that we're not really sure what it is...
+ case 'application/ogg':
+ $arr = array('type' => $this->attachment->mimetype,
+ 'data' => $this->attachment->getUrl(),
+ 'width' => 320,
+ 'height' => 240
+ );
+ $this->out->elementStart('object', $arr);
+ $this->out->element('param', array('name' => 'src', 'value' => $this->attachment->getUrl()));
+ $this->out->element('param', array('name' => 'autoStart', 'value' => 1));
+ $this->out->elementEnd('object');
break;
+ case 'text/html':
+ if (!empty($this->attachment->filename)
+ && (GNUsocial::isAjax() || common_config('attachments', 'show_html'))) {
+ // Locally-uploaded HTML. Scrub and display inline.
+ $this->showHtmlFile($this->attachment);
+ break;
+ }
+ // Fall through to default if it wasn't a _local_ text/html File object
+ default:
+ Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment));
}
- // Fall through to default.
-
- default:
- Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment));
}
} else {
Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment));
$scripts[] = $script;
}
foreach ($scripts as $script) {
- common_log(LOG_DEBUG, $script->textContent);
+ common_debug($script->textContent);
$script->parentNode->removeChild($script);
}
{
$this->id = $id;
if (!empty($this->id)) {
- $this->fileRecord = File::getKV('id', $this->id);
- if (!$this->fileRecord instanceof File) {
- throw new ServerException('Expected File object did not exist.');
+ $this->fileRecord = new File();
+ $this->fileRecord->id = $this->id;
+ if (!$this->fileRecord->find(true)) {
+ // If we have set an ID, we need that ID to exist!
+ throw new NoResultException($this->fileRecord);
}
}
+
+ // These do not have to be the same as fileRecord->filename for example,
+ // since we may have generated an image source file from something else!
$this->filepath = $filepath;
$this->filename = basename($filepath);
$info = @getimagesize($this->filepath);
- if (!(
- ($info[2] == IMAGETYPE_GIF && function_exists('imagecreatefromgif')) ||
- ($info[2] == IMAGETYPE_JPEG && function_exists('imagecreatefromjpeg')) ||
- $info[2] == IMAGETYPE_BMP ||
- ($info[2] == IMAGETYPE_WBMP && function_exists('imagecreatefromwbmp')) ||
- ($info[2] == IMAGETYPE_XBM && function_exists('imagecreatefromxbm')) ||
- ($info[2] == IMAGETYPE_PNG && function_exists('imagecreatefrompng')))) {
+ if (
+ ($info[2] == IMAGETYPE_GIF && !function_exists('imagecreatefromgif')) ||
+ ($info[2] == IMAGETYPE_JPEG && !function_exists('imagecreatefromjpeg')) ||
+ ($info[2] == IMAGETYPE_WBMP && !function_exists('imagecreatefromwbmp')) ||
+ ($info[2] == IMAGETYPE_XBM && !function_exists('imagecreatefromxbm')) ||
+ ($info[2] == IMAGETYPE_PNG && !function_exists('imagecreatefrompng'))) {
// TRANS: Exception thrown when trying to upload an unsupported image file format.
throw new UnsupportedMediaException(_('Unsupported image format.'), $this->filepath);
if (empty($file->filename)) {
throw new UnsupportedMediaException(_('File without filename could not get a thumbnail source.'));
}
+
+ // First some mimetype specific exceptions
+ switch ($file->mimetype) {
+ case 'image/svg+xml':
+ throw new UseFileAsThumbnailException($file->id);
+ }
+
+ // And we'll only consider it an image if it has such a media type
switch ($media) {
case 'image':
$imgPath = $file->getPath();
if ($this->rotate == 0) {
// No rotational difference, just copy it as-is
@copy($this->filepath, $outpath);
+
+ // And set chmod
+ @chmod($outpath, common_config('attachments', 'chmod'));
return $outpath;
} elseif (abs($this->rotate) == 90) {
// Box is rotated 90 degrees in either direction,
throw new Exception(_('Unknown file type'));
}
+ // Always chmod 0644 (default) to have other processes (e.g. queue daemon read it)
+ @chmod($outpath, common_config('attachments', 'chmod'));
+
imagedestroy($image_src);
imagedestroy($image_dest);
}