From aa5c6bbf08e9af2fa38b47f1677479a441e9e0d0 Mon Sep 17 00:00:00 2001 From: Miguel Dantas Date: Wed, 26 Jun 2019 03:27:51 +0100 Subject: [PATCH] [CORE][UI] Made attachment actions and its subactions be able to identify attachments by id and by filehash. Changed the url stored in the DB to be attachment//view --- README.md | 2 +- actions/attachment.php | 4 +++- classes/File.php | 2 +- lib/framework.php | 2 +- lib/mediafile.php | 2 +- lib/router.php | 26 +++++++++++--------------- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index f0bd960008..290c9eed34 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# GNU social 1.24.x +# GNU social 1.25.x (c) 2010-2019 Free Software Foundation, Inc This is the README file for GNU social, the free diff --git a/actions/attachment.php b/actions/attachment.php index 0e5c69d1a2..5fe801ad31 100644 --- a/actions/attachment.php +++ b/actions/attachment.php @@ -59,8 +59,10 @@ class AttachmentAction extends ManagedAction { parent::prepare($args); - if ($id = $this->trimmed('attachment')) { + if (!empty($id = $this->trimmed('attachment'))) { $this->attachment = File::getKV($id); + } elseif (!empty($filehash = $this->trimmed('filehash'))) { + $this->attachment = File::getByHash($filehash); } if (!$this->attachment instanceof File) { diff --git a/classes/File.php b/classes/File.php index 8df0c25e4e..8ccae352e8 100644 --- a/classes/File.php +++ b/classes/File.php @@ -614,7 +614,7 @@ class File extends Managed_DataObject if ($use_local !== false) { if (is_string($this->filename) || !empty($this->filename)) { // A locally stored file, so let's generate a URL for our instance. - return getAttachmentViewUrl(); + return $this->getAttachmentViewUrl(); } if ($use_local) { // if the file wasn't stored locally (has filename) and we require a local URL diff --git a/lib/framework.php b/lib/framework.php index 24ec1f7cd1..c42ccbda04 100644 --- a/lib/framework.php +++ b/lib/framework.php @@ -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.1'); +define('GNUSOCIAL_BASE_VERSION', '1.25.0'); define('GNUSOCIAL_LIFECYCLE', 'dev'); // 'dev', 'alpha[0-9]+', 'beta[0-9]+', 'rc[0-9]+', 'release' define('GNUSOCIAL_VERSION', GNUSOCIAL_BASE_VERSION . '-' . GNUSOCIAL_LIFECYCLE); diff --git a/lib/mediafile.php b/lib/mediafile.php index 76e5541ea0..bbd7e31b2e 100644 --- a/lib/mediafile.php +++ b/lib/mediafile.php @@ -161,7 +161,7 @@ class MediaFile // Well, let's just continue below. } - $fileurl = File::url($this->filename); + $fileurl = common_local_url('attachment_view', array('filehash' => $this->filehash)); $file = new File; diff --git a/lib/router.php b/lib/router.php index 2bffd84a3b..8b6e7b01f5 100644 --- a/lib/router.php +++ b/lib/router.php @@ -219,21 +219,17 @@ class Router array('q' => '.+')); $m->connect('search/notice/rss', array('action' => 'noticesearchrss')); - $m->connect('attachment/:attachment', - array('action' => 'attachment'), - array('attachment' => '[0-9]+')); - - $m->connect('attachment/:attachment/view', - array('action' => 'attachment_view'), - array('attachment' => '[0-9]+')); - - $m->connect('attachment/:attachment/download', - array('action' => 'attachment_download'), - array('attachment' => '[0-9]+')); - - $m->connect('attachment/:attachment/thumbnail', - array('action' => 'attachment_thumbnail'), - array('attachment' => '[0-9]+')); + foreach (['' => 'attachment', + '/view' => 'attachment_view', + '/download' => 'attachment_download', + '/thumbnail' => 'attachment_thumbnail'] as $postfix => $action) { + foreach (['attachment' => '[0-9]+', + 'filehash' => '[A-Za-z0-9._-]+'] as $type => $match) { + $m->connect("attachment/:{$type}{$postfix}", + ['action' => $action], + [$type => $match]); + } + } $m->connect('notice/new?replyto=:replyto&inreplyto=:inreplyto', array('action' => 'newnotice'),