]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
[CORE] Refactored attachement actions to remove duplicate code
authorMiguel Dantas <biodantasgs@gmail.com>
Wed, 26 Jun 2019 02:25:59 +0000 (03:25 +0100)
committerDiogo Cordeiro <diogo@fc.up.pt>
Sat, 3 Aug 2019 16:31:40 +0000 (17:31 +0100)
actions/attachment.php
actions/attachment_download.php
actions/attachment_view.php
lib/framework.php

index fb85a50d07efe09a5aa8778e5633cc44b7d04dc1..0e5c69d1a2606edb22e8d28d72ec526a803d662f 100644 (file)
@@ -132,4 +132,25 @@ class AttachmentAction extends ManagedAction
         $ns = new AttachmentNoticeSection($this);
         $ns->show();
     }
+
+    public function sendFile(string $filepath) {
+        if (common_config('site', 'use_x_sendfile')) {
+            header('X-Sendfile: ' . $filepath);
+        } else {
+            $filesize = $this->attachment->size;
+            // 'if available', it says, so ensure we have it
+            if (empty($filesize)) {
+                $filesize = filesize($filepath);
+            }
+            header("Content-Length: {$filesize}");
+            // header('Cache-Control: private, no-transform, no-store, must-revalidate');
+
+            $ret = @readfile($filepath);
+
+            if ($ret === false || $ret !== $filesize) {
+                common_log(LOG_ERR, "The lengths of the file as recorded on the DB (or on disk) for the file " .
+                           "{$filepath}, with id={$this->attachment->id} differ from what was sent to the user.");
+            }
+        }
+    }
 }
index e9a1667a5ae83e97bf1546db48ea84300c6dec4f..35c0ecb5d5f587f601943a356786e99beebdb183 100644 (file)
@@ -30,19 +30,7 @@ class Attachment_downloadAction extends AttachmentAction
         header("Content-Disposition: attachment; filename=\"{$filename}\"");
         header('Expires: 0');
         header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
-        $filesize = $this->attachment->size;
-        // 'if available', it says, so ensure we have it
-        if (empty($filesize)) {
-            $filesize = filesize($this->attachment->filename);
-        }
-        header("Content-Length: {$filesize}");
-        // header('Cache-Control: private, no-transform, no-store, must-revalidate');
 
-        $ret = @readfile($filepath);
-
-        if ($ret === false || $ret !== $filesize) {
-            common_log(LOG_ERR, "The lengths of the file as recorded on the DB (or on disk) for the file " .
-                       "{$filepath}, with id={$this->attachment->id} differ from what was sent to the user.");
-        }
+        $this->sendFile($filepath);
     }
 }
index 6a3b7df9f5bd905b36bbf21c43c3e579c0850598..d6a7c1c50d583f5908a5088d360b4331942adf21 100644 (file)
@@ -3,13 +3,11 @@
 if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
- * Download notice attachment
+ * View notice attachment
  *
- * @category Personal
  * @package  GNUsocial
- * @author   Mikael Nordfeldth <mmn@hethane.se>
+ * @author   Miguel Dantas <biodantasgs@gmail.com>
  * @license  https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     https:/gnu.io/social
  */
 class Attachment_viewAction extends AttachmentAction
 {
@@ -33,20 +31,8 @@ class Attachment_viewAction extends AttachmentAction
             header("Content-Disposition: attachment; filename=\"{$filename}\"");
         }
         header('Expires: 0');
-        header('Content-Transfer-Encoding: binary'); // FIXME? Can this be different?
-        $filesize = $this->attachment->size;
-        // 'if available', it says, so ensure we have it
-        if (empty($filesize)) {
-            $filesize = filesize($this->attachment->filename);
-        }
-        header("Content-Length: {$filesize}");
-        // header('Cache-Control: private, no-transform, no-store, must-revalidate');
-
-        $ret = @readfile($filepath);
+        header('Content-Transfer-Encoding: binary');
 
-        if ($ret === false || $ret !== $filesize) {
-            common_log(LOG_ERR, "The lengths of the file as recorded on the DB (or on disk) for the file " .
-                       "{$filepath}, with id={$this->attachment->id} differ from what was sent to the user.");
-        }
+        $this->sendFile($filepath);
     }
 }
index 1bbdaca3f1bb315f8dfd7cb252ad4e4b47475fe5..24ec1f7cd1131716de39fe418882b4835328e54c 100644 (file)
@@ -32,7 +32,7 @@ defined('GNUSOCIAL') || die();
 define('GNUSOCIAL_ENGINE', 'GNU social');
 define('GNUSOCIAL_ENGINE_URL', 'https://www.gnu.org/software/social/');
 
-define('GNUSOCIAL_BASE_VERSION', '1.24.0');
+define('GNUSOCIAL_BASE_VERSION', '1.24.1');
 define('GNUSOCIAL_LIFECYCLE', 'dev'); // 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release'
 
 define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE);