Attachments popups for supported files are now embedded with the object xhtml tag.

This commit is contained in:
Robin Millette 2009-06-01 14:02:59 -04:00
parent f8dae2bbc9
commit 683b835c3e
3 changed files with 51 additions and 36 deletions

View File

@ -113,12 +113,12 @@ class NewnoticeAction extends Action
} }
} }
function isSupportedFileType() { function getUploadedFileType() {
require_once 'MIME/Type.php'; require_once 'MIME/Type.php';
$filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']); $filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']);
if (in_array($filetype, common_config('attachments', 'supported'))) { if (in_array($filetype, common_config('attachments', 'supported'))) {
return true; return $filetype;
} }
$media = MIME_Type::getMedia($filetype); $media = MIME_Type::getMedia($filetype);
if ('application' !== $media) { if ('application' !== $media) {
@ -188,16 +188,12 @@ class NewnoticeAction extends Action
if (isset($_FILES['attach']['error'])) { if (isset($_FILES['attach']['error'])) {
switch ($_FILES['attach']['error']) { switch ($_FILES['attach']['error']) {
case UPLOAD_ERR_NO_FILE: case UPLOAD_ERR_NO_FILE:
// no file uploaded // no file uploaded, nothing to do
// nothing to do
break; break;
case UPLOAD_ERR_OK: case UPLOAD_ERR_OK:
// file was uploaded alright $mimetype = $this->getUploadedFileType();
// lets check if we really support its format if (!$this->isRespectsQuota($user)) {
// and it doesn't go over quotas
if (!$this->isSupportedFileType() || !$this->isRespectsQuota($user)) {
die('clientError() should trigger an exception before reaching here.'); die('clientError() should trigger an exception before reaching here.');
} }
break; break;
@ -232,7 +228,9 @@ class NewnoticeAction extends Action
$this->clientError($notice); $this->clientError($notice);
} }
$this->storeFile($notice); if (isset($mimetype)) {
$this->storeFile($notice, $mimetype);
}
$this->saveUrls($notice); $this->saveUrls($notice);
common_broadcast_notice($notice); common_broadcast_notice($notice);
@ -259,8 +257,7 @@ class NewnoticeAction extends Action
} }
} }
function storeFile($notice) { function storeFile($notice, $mimetype) {
if (UPLOAD_ERR_NO_FILE === $_FILES['attach']['error']) return;
$filename = basename($_FILES['attach']['name']); $filename = basename($_FILES['attach']['name']);
$destination = "file/{$notice->id}-$filename"; $destination = "file/{$notice->id}-$filename";
if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) { if (move_uploaded_file($_FILES['attach']['tmp_name'], INSTALLDIR . "/$destination")) {
@ -268,7 +265,7 @@ class NewnoticeAction extends Action
$file->url = common_local_url('file', array('notice' => $notice->id)); $file->url = common_local_url('file', array('notice' => $notice->id));
$file->size = filesize(INSTALLDIR . "/$destination"); $file->size = filesize(INSTALLDIR . "/$destination");
$file->date = time(); $file->date = time();
$file->mimetype = $_FILES['attach']['type']; $file->mimetype = $mimetype;
if ($file_id = $file->insert()) { if ($file_id = $file->insert()) {
$file_redir = new File_redirection; $file_redir = new File_redirection;
$file_redir->url = common_path($destination); $file_redir->url = common_path($destination);
@ -285,7 +282,6 @@ class NewnoticeAction extends Action
} }
} }
/** save all urls in the notice to the db /** save all urls in the notice to the db
* *
* follow redirects and save all available file information * follow redirects and save all available file information
@ -408,3 +404,4 @@ class NewnoticeAction extends Action
$nli->show(); $nli->show();
} }
} }

View File

@ -268,6 +268,23 @@ class Attachment extends AttachmentListItem
case 'image/jpeg': case 'image/jpeg':
$this->out->element('img', array('src' => $this->attachment->url, 'alt' => 'alt')); $this->out->element('img', array('src' => $this->attachment->url, 'alt' => 'alt'));
break; break;
case 'application/ogg':
case 'audio/x-speex':
case 'video/mpeg':
case 'audio/mpeg':
case 'video/mp4':
case 'video/quicktime':
$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;
} }
} }
} else { } else {

View File

@ -169,6 +169,7 @@ $config =
'image/gif', 'image/gif',
'image/svg+xml', 'image/svg+xml',
'audio/mpeg', 'audio/mpeg',
'audio/x-speex',
'application/ogg', 'application/ogg',
'application/pdf', 'application/pdf',
'application/vnd.oasis.opendocument.text', 'application/vnd.oasis.opendocument.text',