]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/oembed.php
Merge branch 'master' into 0.9.x
[quix0rs-gnu-social.git] / actions / oembed.php
index 11d814583701a78a23392042b8dd861618e8f532..0d8be55656a0899c80cd0ac6d87c654a468a245f 100644 (file)
@@ -61,7 +61,7 @@ class OembedAction extends Action
             $proxy_args = $r->map($path);
 
             if (!$proxy_args) {
-                $this->serverError(_("$path not found."), 404);
+                $this->serverError(sprintf(_('"%s" not found.'),$path), 404);
             }
             $oembed=array();
             $oembed['version']='1.0';
@@ -73,7 +73,7 @@ class OembedAction extends Action
                     $id = $proxy_args['notice'];
                     $notice = Notice::staticGet($id);
                     if(empty($notice)){
-                        $this->serverError(_("Notice $id not found."), 404);
+                        $this->serverError(sprintf(_("Notice %s not found."),$id), 404);
                     }
                     $profile = $notice->getProfile();
                     if (empty($profile)) {
@@ -92,7 +92,7 @@ class OembedAction extends Action
                     $id = $proxy_args['attachment'];
                     $attachment = File::staticGet($id);
                     if(empty($attachment)){
-                        $this->serverError(_("Attachment $id not found."), 404);
+                        $this->serverError(sprintf(_('Attachment %s not found.'),$id), 404);
                     }
                     if(empty($attachment->filename) && $file_oembed = File_oembed::staticGet('file_id', $attachment->id)){
                         // Proxy the existing oembed information
@@ -108,9 +108,16 @@ class OembedAction extends Action
                         $oembed['url']=$file_oembed->url;
                     }else if(substr($attachment->mimetype,0,strlen('image/'))=='image/'){
                         $oembed['type']='photo';
-                        //TODO set width and height
-                        //$oembed['width']=
-                        //$oembed['height']=
+                        if ($attachment->filename) {
+                            $filepath = File::path($attachment->filename);
+                            $gis = @getimagesize($filepath);
+                            if ($gis) {
+                                $oembed['width'] = $gis[0];
+                                $oembed['height'] = $gis[1];
+                            } else {
+                                // TODO Either throw an error or find a fallback?
+                            }
+                        }
                         $oembed['url']=$attachment->url;
                         $thumb = $attachment->getThumbnail();
                         if ($thumb) {
@@ -126,7 +133,7 @@ class OembedAction extends Action
                     if($attachment->title) $oembed['title']=$attachment->title;
                     break;
                 default:
-                    $this->serverError(_("$path not supported for oembed requests."), 501);
+                    $this->serverError(sprintf(_('"%s" not supported for oembed requests.'),$path), 501);
             }
             switch($args['format']){
                 case 'xml':
@@ -208,4 +215,15 @@ class OembedAction extends Action
         return;
     }
 
+    /**
+     * Is this action read-only?
+     *
+     * @param array $args other arguments
+     *
+     * @return boolean is read only action?
+     */
+    function isReadOnly($args)
+    {
+        return true;
+    }
 }