]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'nightly' of gitorious.org:social/mainline into nightly
authorRoland Haeder <roland@mxchange.org>
Fri, 6 Mar 2015 00:43:25 +0000 (01:43 +0100)
committerRoland Haeder <roland@mxchange.org>
Fri, 6 Mar 2015 00:43:32 +0000 (01:43 +0100)
Signed-off-by: Roland Haeder <roland@mxchange.org>
actions/emailsettings.php
lib/action.php
lib/attachmentlistitem.php
lib/imagefile.php
lib/mediafile.php
plugins/ImageMagick/ImageMagickPlugin.php
plugins/VideoThumbnails/VideoThumbnailsPlugin.php

index 47c6fe54e513a738cedf12a7275d6e8edcbbf19a..dfdbe1bad066cac4dcb6f93156f3537fe1bcb699 100644 (file)
@@ -91,7 +91,7 @@ class EmailsettingsAction extends SettingsAction
      */
     function showContent()
     {
-        $user = common_current_user();
+        $user = $this->scoped->getUser();
 
         $this->elementStart('form', array('method' => 'post',
                                           'id' => 'form_settings_email',
@@ -316,12 +316,12 @@ class EmailsettingsAction extends SettingsAction
         $user = $this->scoped->getUser();
 
         if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
-            $emailnotifysub   = $this->boolean('emailnotifysub');
-            $emailnotifymsg   = $this->boolean('emailnotifymsg');
-            $emailnotifynudge = $this->boolean('emailnotifynudge');
-            $emailnotifyattn  = $this->boolean('emailnotifyattn');
-            $emailmicroid     = $this->boolean('emailmicroid');
-            $emailpost        = $this->boolean('emailpost');
+            $emailnotifysub   = $this->booleanintstring('emailnotifysub');
+            $emailnotifymsg   = $this->booleanintstring('emailnotifymsg');
+            $emailnotifynudge = $this->booleanintstring('emailnotifynudge');
+            $emailnotifyattn  = $this->booleanintstring('emailnotifyattn');
+            $emailmicroid     = $this->booleanintstring('emailmicroid');
+            $emailpost        = $this->booleanintstring('emailpost');
 
             $user->query('BEGIN');
 
index d4e14ab3447cc53d3cdd7d7d058e91c2efadc387..82dd34020440e42ddda3da6452f0060592ee15d6 100644 (file)
@@ -1356,6 +1356,19 @@ class Action extends HTMLOutputter // lawsuit
         }
     }
 
+    /**
+     * This is a cheap hack to avoid a bug in DB_DataObject
+     * where '' is non-type-aware compared to 0, which means it
+     * will always be true for values like false and 0 too...
+     *
+     * Upstream bug is::
+     * https://pear.php.net/bugs/bug.php?id=20291
+     */
+    function booleanintstring($key, $def)
+    {
+        return $this->boolean($key, $def) ? '1' : '0';
+    }
+
     /**
      * Integer value of an argument
      *
index 5127ced2ebf9b84416283a0963f3cf9841d0c740..99cb3c8da94356be0afa901d22644d2f71809838 100644 (file)
@@ -107,11 +107,10 @@ class AttachmentListItem extends Widget
     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);
@@ -123,27 +122,9 @@ class AttachmentListItem extends Widget
                     }
                     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();
@@ -156,22 +137,36 @@ class AttachmentListItem extends Widget
                                             '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));
index 674ba316eb70a53b2335ba315efaa740367f161e..cc8f8257ff7195e6c392a9c169919098bf30bb97 100644 (file)
@@ -61,11 +61,16 @@ class ImageFile
     {
         $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);
 
@@ -122,6 +127,14 @@ class ImageFile
             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();
index bcc8662f56f6e632895806794b6fcdacc7f387cf..546239ed7d3bf6de2bbf4b7421139a1d9c694690 100644 (file)
@@ -332,6 +332,7 @@ class MediaFile
         $unclearTypes = array('application/octet-stream',
                               'application/vnd.ms-office',
                               'application/zip',
+                              'text/html',  // Ironically, Wikimedia Commons' SVG_logo.svg is identified as text/html
                               // TODO: for XML we could do better content-based sniffing too
                               'text/xml');
 
index d6d4f1a1b8f0fae1ee81105b04e4a138624e1a0c..6e238ee8f2d26176c4620b809f33b254bc5387b3 100644 (file)
@@ -46,6 +46,9 @@ if (!defined('GNUSOCIAL')) { exit(1); }
 
 class ImageMagickPlugin extends Plugin
 {
+    public $preview_imageformat = 'PNG';    // Image format strings: http://www.imagemagick.org/script/formats.php#supported
+    public $rasterize_vectors = false;       // Whether we want to turn SVG into PNG etc.
+
     /**
      * @param ImageFile $file An ImageFile object we're getting metadata for
      * @param array $info The response from getimagesize()
@@ -95,6 +98,40 @@ class ImageMagickPlugin extends Plugin
         return !$success;
     }
 
+    public function onCreateFileImageThumbnailSource(File $file, &$imgPath, $media=null)
+    {
+        switch ($file->mimetype) {
+        case 'image/svg+xml':
+            if (!$this->rasterize_vectors) {
+                // ImageMagick seems to be hard to trick into scaling vector graphics...
+                return true;
+            }
+            break;
+        default:
+            // If we don't know the format, let's try not to mess with anything.
+            return true;
+        }
+
+        $imgPath = tempnam(sys_get_temp_dir(), 'socialthumb-');
+        if (!$this->createImagePreview($file, $imgPath)) {
+            common_debug('Could not create ImageMagick preview of File id=='.$file->id);
+            @unlink($imgPath);
+            $imgPath = null;
+            return true;
+        }
+        return false;
+    }
+
+    protected function createImagePreview(File $file, $outpath)
+    {
+        $magick = new Imagick($file->getPath());
+        $magick->setImageFormat($this->preview_imageformat);
+        $magick->writeImage($outpath);
+        $magick->destroy();
+
+        return getimagesize($outpath);  // Verify that we wrote an understandable image.
+    }
+
     public function onPluginVersion(&$versions)
     {
         $versions[] = array('name' => 'ImageMagick',
index c8fef72eb6fb0af221c5a9ad8e05b6efd05b5d14..32ce37c1cf2945d4286f6d0e9177ec0aa44f440a 100644 (file)
@@ -63,6 +63,7 @@ class VideoThumbnailsPlugin extends Plugin
         if (!getimagesize($imgPath)) {
             common_debug('exec of "avconv" produced a bad/nonexisting image it seems');
             @unlink($imgPath);
+            $imgPath = null;    // pretend we didn't touch it
             return true;
         }
         return false;