]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/oembed.php
Mark OembedAction, XrdAction, and (plugin) AutocompleteAction as read-only. Tweaked...
[quix0rs-gnu-social.git] / actions / oembed.php
index 4a11a85e097300866175f53c35fac1a7cd14d80f..bef707f92adeb8c1cec8e8cbd81fd536ee8ddc4b 100644 (file)
@@ -23,6 +23,7 @@
  * @package   StatusNet
  * @author    Evan Prodromou <evan@status.net>
  * @copyright 2008 StatusNet, Inc.
+ * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -60,7 +61,7 @@ class OembedAction extends Action
             $proxy_args = $r->map($path);
 
             if (!$proxy_args) {
-                $this->serverError(_("$path not found"), 404);
+                $this->serverError(_("$path not found."), 404);
             }
             $oembed=array();
             $oembed['version']='1.0';
@@ -72,17 +73,13 @@ class OembedAction extends Action
                     $id = $proxy_args['notice'];
                     $notice = Notice::staticGet($id);
                     if(empty($notice)){
-                        $this->serverError(_("notice $id not found"), 404);
+                        $this->serverError(_("Notice $id not found."), 404);
                     }
                     $profile = $notice->getProfile();
                     if (empty($profile)) {
-                        $this->serverError(_('Notice has no profile'), 500);
-                    }
-                    if (!empty($profile->fullname)) {
-                        $authorname = $profile->fullname . ' (' . $profile->nickname . ')';
-                    } else {
-                        $authorname = $profile->nickname;
+                        $this->serverError(_('Notice has no profile.'), 500);
                     }
+                    $authorname = $profile->getFancyName();
                     $oembed['title'] = sprintf(_('%1$s\'s status on %2$s'),
                         $authorname,
                         common_exact_date($notice->created));
@@ -95,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(_("Attachment $id not found."), 404);
                     }
                     if(empty($attachment->filename) && $file_oembed = File_oembed::staticGet('file_id', $attachment->id)){
                         // Proxy the existing oembed information
@@ -111,10 +108,23 @@ 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) {
+                            $oembed['thumbnail_url'] = $thumb->url;
+                            $oembed['thumbnail_width'] = $thumb->width;
+                            $oembed['thumbnail_height'] = $thumb->height;
+                        }
                     }else{
                         $oembed['type']='link';
                         $oembed['url']=common_local_url('attachment',
@@ -123,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(_("$path not supported for oembed requests."), 501);
             }
             switch($args['format']){
                 case 'xml':
@@ -155,11 +165,11 @@ class OembedAction extends Action
                     break;
                 default:
                     // TRANS: Error message displaying attachments. %s is a raw MIME type (eg 'image/png')
-                    $this->serverError(sprintf(_('content type %s not supported'), $apidata['content-type']), 501);
+                    $this->serverError(sprintf(_('Content type %s not supported.'), $apidata['content-type']), 501);
             }
         }else{
             // TRANS: Error message displaying attachments. %s is the site's base URL.
-            $this->serverError(sprintf(_('Only %s urls over plain http please'), common_root_url()), 404);
+            $this->serverError(sprintf(_('Only %s URLs over plain HTTP please.'), common_root_url()), 404);
         }
     }
 
@@ -205,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;
+    }
 }