]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Make shorturls in notice content point to AttachmentAction urls
authorZach Copley <zach@controlyourself.ca>
Thu, 25 Jun 2009 22:42:17 +0000 (15:42 -0700)
committerZach Copley <zach@controlyourself.ca>
Thu, 25 Jun 2009 22:42:17 +0000 (15:42 -0700)
actions/attachment.php
actions/newnotice.php

index e4dc0e054e27be9a238ad842eb823a8575e8d989..ee4cd9640d971d1b0b19bbe1cdbfa6b1ee5be67b 100644 (file)
@@ -111,7 +111,16 @@ class AttachmentAction extends Action
     function handle($args)
     {
         parent::handle($args);
-        $this->showPage();
+
+        if (empty($this->attachment->filename)) {
+
+            // if it's not a local file, gtfo
+
+            common_redirect($this->attachment->url, 303);
+
+        } else {
+            $this->showPage();
+        }
     }
 
     /**
index 15caff6eaab0042783314c8cc1e6d80e7f9977cc..5f44a32a96a5601a2582a9dbdb66f39b3f27e6d0 100644 (file)
@@ -229,14 +229,25 @@ class NewnoticeAction extends Action
             if (empty($filename)) {
                 $this->clientError(_('Couldn\'t save file.'));
             }
-            $fileurl = File::url($filename);
+
+            $fileRecord = $this->storeFile($filename, $mimetype);
+
+            $fileurl = common_local_url('attachment',
+                array('attachment' => $fileRecord->id));
+
+            // not sure this is necessary -- Zach
+            $this->maybeAddRedir($fileRecord->id, $fileurl);
+
             $short_fileurl = common_shorten_url($fileurl);
             $content_shortened .= ' ' . $short_fileurl;
+
             if (mb_strlen($content_shortened) > 140) {
                 $this->deleteFile($filename);
                 $this->clientError(_('Max notice size is 140 chars, including attachment URL.'));
             }
-            $fileRecord = $this->rememberFile($filename, $mimetype, $short_fileurl);
+
+            // Also, not sure this is necessary -- Zach
+            $this->maybeAddRedir($fileRecord->id, $short_fileurl);
         }
 
         $notice = Notice::saveNew($user->id, $content_shortened, 'web', 1,
@@ -305,8 +316,8 @@ class NewnoticeAction extends Action
         @unlink($filepath);
     }
 
-    function rememberFile($filename, $mimetype, $short)
-    {
+    function storeFile($filename, $mimetype) {
+
         $file = new File;
         $file->filename = $filename;
 
@@ -325,11 +336,14 @@ class NewnoticeAction extends Action
             $this->clientError(_('There was a database error while saving your file. Please try again.'));
         }
 
-        $this->maybeAddRedir($file_id, $short);
-
         return $file;
     }
 
+    function rememberFile($file, $short)
+    {
+        $this->maybeAddRedir($file->id, $short);
+    }
+
     function maybeAddRedir($file_id, $url)
     {
         $file_redir = File_redirection::staticGet('url', $url);