]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Attachments popups for supported files are now embedded with the object xhtml tag.
authorRobin Millette <millette@controlyourself.ca>
Mon, 1 Jun 2009 18:02:59 +0000 (14:02 -0400)
committerRobin Millette <millette@controlyourself.ca>
Mon, 1 Jun 2009 18:02:59 +0000 (14:02 -0400)
actions/newnotice.php
lib/attachmentlist.php
lib/common.php

index a24d6268407aa455e3a50ebb59eda7feb4f947fa..3e6ff151895c4e9c57af20e74dee3b8f040372ed 100644 (file)
@@ -113,12 +113,12 @@ class NewnoticeAction extends Action
         }
     }
 
-    function isSupportedFileType() {
+    function getUploadedFileType() {
         require_once 'MIME/Type.php';
 
         $filetype = MIME_Type::autoDetect($_FILES['attach']['tmp_name']);
         if (in_array($filetype, common_config('attachments', 'supported'))) {
-            return true;
+            return $filetype;
         }
         $media = MIME_Type::getMedia($filetype);
         if ('application' !== $media) {
@@ -186,43 +186,39 @@ class NewnoticeAction extends Action
         }
 
         if (isset($_FILES['attach']['error'])) {
-        switch ($_FILES['attach']['error']) {
-            case UPLOAD_ERR_NO_FILE:
-                // no file uploaded
-                // nothing to do
-                break;
+            switch ($_FILES['attach']['error']) {
+                case UPLOAD_ERR_NO_FILE:
+                    // no file uploaded, nothing to do
+                    break;
 
-             case UPLOAD_ERR_OK:
-                // file was uploaded alright
-                // lets check if we really support its format
-                // and it doesn't go over quotas
+                case UPLOAD_ERR_OK:
+                    $mimetype = $this->getUploadedFileType();
+                    if (!$this->isRespectsQuota($user)) {
+                        die('clientError() should trigger an exception before reaching here.');
+                    }
+                    break;
 
-                if (!$this->isSupportedFileType() || !$this->isRespectsQuota($user)) {
-                    die('clientError() should trigger an exception before reaching here.');
-                }
-                break;
+                case UPLOAD_ERR_INI_SIZE:
+                    $this->clientError(_('The uploaded file exceeds the upload_max_filesize directive in php.ini.'));
 
-            case UPLOAD_ERR_INI_SIZE:
-                $this->clientError(_('The uploaded file exceeds the upload_max_filesize directive in php.ini.'));
+                case UPLOAD_ERR_FORM_SIZE:
+                    $this->clientError(_('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'));
 
-            case UPLOAD_ERR_FORM_SIZE:
-                $this->clientError(_('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.'));
+                case UPLOAD_ERR_PARTIAL:
+                    $this->clientError(_('The uploaded file was only partially uploaded.'));
 
-            case UPLOAD_ERR_PARTIAL:
-                $this->clientError(_('The uploaded file was only partially uploaded.'));
+                case  UPLOAD_ERR_NO_TMP_DIR:
+                    $this->clientError(_('Missing a temporary folder.'));
 
-            case  UPLOAD_ERR_NO_TMP_DIR:
-                $this->clientError(_('Missing a temporary folder.'));
+                case UPLOAD_ERR_CANT_WRITE:
+                    $this->clientError(_('Failed to write file to disk.'));
 
-            case UPLOAD_ERR_CANT_WRITE:
-                $this->clientError(_('Failed to write file to disk.'));
+                case UPLOAD_ERR_EXTENSION:
+                    $this->clientError(_('File upload stopped by extension.'));
 
-            case UPLOAD_ERR_EXTENSION:
-                $this->clientError(_('File upload stopped by extension.'));
-
-            default:
-                die('Should never reach here.');
-        }
+                default:
+                    die('Should never reach here.');
+            }
         }
 
         $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
@@ -232,7 +228,9 @@ class NewnoticeAction extends Action
             $this->clientError($notice);
         }
 
-        $this->storeFile($notice);
+        if (isset($mimetype)) {
+            $this->storeFile($notice, $mimetype);
+        }
         $this->saveUrls($notice);
         common_broadcast_notice($notice);
 
@@ -259,8 +257,7 @@ class NewnoticeAction extends Action
         }
     }
 
-    function storeFile($notice) {
-        if (UPLOAD_ERR_NO_FILE === $_FILES['attach']['error']) return;
+    function storeFile($notice, $mimetype) {
         $filename = basename($_FILES['attach']['name']);
         $destination = "file/{$notice->id}-$filename";
         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->size = filesize(INSTALLDIR . "/$destination");
             $file->date = time();
-            $file->mimetype = $_FILES['attach']['type'];
+            $file->mimetype = $mimetype;
             if ($file_id = $file->insert()) {
                 $file_redir = new File_redirection;
                 $file_redir->url = common_path($destination);
@@ -285,7 +282,6 @@ class NewnoticeAction extends Action
         }
     }
 
-
     /** save all urls in the notice to the db
      *
      * follow redirects and save all available file information
@@ -408,3 +404,4 @@ class NewnoticeAction extends Action
         $nli->show();
     }
 }
+
index 61749dca578a1cf0688bb2290b26217990b37dd1..45e4fa319687761ee9dc31d3b617b7cfc18a2e5e 100644 (file)
@@ -268,6 +268,23 @@ class Attachment extends AttachmentListItem
                 case 'image/jpeg':
                     $this->out->element('img', array('src' => $this->attachment->url, 'alt' => 'alt'));
                     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 {
index 838f52f9d54ab3448b02674a830876c3a5bea7c2..ceb50337ccf193232a86972836f19fef4a2cd8f4 100644 (file)
@@ -169,6 +169,7 @@ $config =
             'image/gif',
             'image/svg+xml',
             'audio/mpeg',
+            'audio/x-speex',
             'application/ogg',
             'application/pdf',
             'application/vnd.oasis.opendocument.text',