From aeabf640516dbacec1357e4e7b8caebc181f5a3f Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Mon, 19 Apr 2021 18:51:05 +0000 Subject: [PATCH] [PLUGIN] Change base class from Module to Plugin for all plugins --- plugins/Cover/Cover.php | 4 +- plugins/Directory/Directory.php | 4 +- .../EmailNotifications/EmailNotifications.php | 4 +- plugins/Embed/Embed.php | 12 +- plugins/Favourite/Favourite.php | 4 +- plugins/Media/Controller/Attachment.php | 227 -------------- plugins/Media/media/AttachmentListItem.php | 291 ------------------ .../Media/media/AttachmentNoticeSection.php | 73 ----- plugins/Poll/Poll.php | 4 +- plugins/ProfileColor/ProfileColor.php | 4 +- plugins/Repeat/Repeat.php | 4 +- plugins/Reply/Reply.php | 4 +- plugins/StoreRemoteMedia/StoreRemoteMedia.php | 6 +- plugins/TreeNotes/TreeNotes.php | 4 +- .../XMPPNotifications/XMPPNotifications.php | 4 +- 15 files changed, 32 insertions(+), 617 deletions(-) delete mode 100644 plugins/Media/Controller/Attachment.php delete mode 100644 plugins/Media/media/AttachmentListItem.php delete mode 100644 plugins/Media/media/AttachmentNoticeSection.php diff --git a/plugins/Cover/Cover.php b/plugins/Cover/Cover.php index 20fb6144d4..20703fe4c8 100644 --- a/plugins/Cover/Cover.php +++ b/plugins/Cover/Cover.php @@ -22,7 +22,7 @@ namespace Plugin\Cover; use App\Core\DB\DB; use App\Core\Event; -use App\Core\Modules\Module; +use App\Core\Modules\Plugin; use App\Core\Router\RouteLoader; use App\Util\Common; @@ -36,7 +36,7 @@ use App\Util\Common; * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -class Cover extends Module +class Cover extends Plugin { /** * Map URLs to actions diff --git a/plugins/Directory/Directory.php b/plugins/Directory/Directory.php index 4ce9b45cdb..e21f344c97 100644 --- a/plugins/Directory/Directory.php +++ b/plugins/Directory/Directory.php @@ -22,10 +22,10 @@ namespace Plugin\Directory; use App\Core\Event; -use App\Core\Modules\Module; +use App\Core\Modules\Plugin; use App\Core\Router\RouteLoader; -class Directory extends Module +class Directory extends Plugin { /** * Map URLs to Controllers diff --git a/plugins/EmailNotifications/EmailNotifications.php b/plugins/EmailNotifications/EmailNotifications.php index 3fb4c70341..412c707336 100644 --- a/plugins/EmailNotifications/EmailNotifications.php +++ b/plugins/EmailNotifications/EmailNotifications.php @@ -33,9 +33,9 @@ namespace Plugin\EmailNotifications; use App\Core\Event; -use App\Core\Modules\Module; +use App\Core\Modules\Plugin; -class EmailNotifications extends Module +class EmailNotifications extends Plugin { public function onAddNotificationTransport(&$form_defs): bool { diff --git a/plugins/Embed/Embed.php b/plugins/Embed/Embed.php index 5740c9efc3..e9c0e86f78 100644 --- a/plugins/Embed/Embed.php +++ b/plugins/Embed/Embed.php @@ -1,4 +1,6 @@ . +// }}} /** * OEmbed and OpenGraph implementation for GNU social @@ -23,16 +26,17 @@ * @author Stephen Paul Weber * @author hannes * @author Mikael Nordfeldth - * @author Diogo Peralta Cordeiro * @author Miguel Dantas - * @author Diogo Peralta Cordeiro + * @author Diogo Peralta Cordeiro + * @authir Hugo Sales + * * @copyright 2014-2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ namespace Plugin\Embed; -use App\Core\Modules\Module; +use App\Core\Modules\Plugin; /** * Base class for the Embed plugin that does most of the heavy lifting to get @@ -41,7 +45,7 @@ use App\Core\Modules\Module; * @copyright 2014-2021 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ -class Embed extends Module +class Embed extends Plugin { const PLUGIN_VERSION = '2.1.0'; diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index 3ad8bc8009..a49dc13e66 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -22,7 +22,7 @@ namespace Plugin\Favourite; use App\Core\DB\DB; use App\Core\Event; use App\Core\Form; -use App\Core\Modules\Module; +use App\Core\Modules\Plugin; use App\Core\Router\RouteLoader; use App\Entity\Note; use App\Util\Common; @@ -32,7 +32,7 @@ use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; -class Favourite extends Module +class Favourite extends Plugin { /** * HTML rendering event that adds the favourite form as a note diff --git a/plugins/Media/Controller/Attachment.php b/plugins/Media/Controller/Attachment.php deleted file mode 100644 index 3dae26da9c..0000000000 --- a/plugins/Media/Controller/Attachment.php +++ /dev/null @@ -1,227 +0,0 @@ -. -// }}} - -namespace Plugin\Media\Controller; - -use App\Core\Controller; -use Symfony\Component\HttpFoundation\Request; - -/** - * Show note attachments - * - * @author Evan Prodromou - * @author Hugo Sales - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * - * @see http://status.net/ - */ -class Attachment extends Controller -{ - public function handle(Request $request) - { - return [ - '_template' => 'doc/tos.html.twig', - ]; - } - - /** - * Attachment File object to show - */ - public $attachment; - - public $filehash; - public $filepath; - public $filesize; - public $mimetype; - public $filename; - - /** - * Load attributes based on database arguments - * - * Loads all the DB stuff - * - * @param array $args $_REQUEST array - * - * @throws ClientException - * @throws FileNotFoundException - * @throws FileNotStoredLocallyException - * @throws InvalidFilenameException - * @throws ServerException - * - * @return bool flag - */ - protected function prepare(array $args = []) - { - // parent::prepare($args); - - try { - if (!empty($id = $this->trimmed('attachment'))) { - $this->attachment = File::getByID((int) $id); - } elseif (!empty($this->filehash = $this->trimmed('filehash'))) { - $file = File::getByHash($this->filehash); - $file->fetch(); - $this->attachment = $file; - } - } catch (Exception $e) { - // Not found - } - if (!$this->attachment instanceof File) { - // TRANS: Client error displayed trying to get a non-existing attachment. - $this->clientError(_m('No such attachment.'), 404); - } - - $this->filesize = $this->attachment->size; - $this->mimetype = $this->attachment->mimetype; - $this->filename = $this->attachment->filename; - - if ($this->attachment->isLocal() || $this->attachment->isFetchedRemoteFile()) { - $this->filesize = $this->attachment->getFileOrThumbnailSize(); - $this->mimetype = $this->attachment->getFileOrThumbnailMimetype(); - $this->filename = MediaFile::getDisplayName($this->attachment); - } - - return true; - } - - /** - * Is this action read-only? - * - * @param mixed $args - * - * @return bool true - */ - public function isReadOnly($args): bool - { - return true; - } - - /** - * Title of the page - * - * @return string title of the page - */ - public function title(): string - { - $a = new self($this->attachment); - return $a->title(); - } - - public function showPage(): void - { - if (empty($this->filepath)) { - // if it's not a local file, gtfo - common_redirect($this->attachment->getUrl(), 303); - } - - // parent::showPage(); - } - - /** - * Fill the content area of the page - * - * Shows a single notice list item. - * - * @return void - */ - public function showContent(): void - { - $ali = new self($this->attachment, $this); - $ali->show(); - } - - /** - * Don't show page notice - * - * @return void - */ - public function showPageNoticeBlock(): void - { - } - - /** - * Show aside: this attachments appears in what notices - * - * @return void - */ - public function showSections(): void - { - $ns = new AttachmentNoticeSection($this); - $ns->show(); - } - - /** - * Last-modified date for file - * - * @throws ServerException - * - * @return int last-modified date as unix timestamp - */ - public function lastModified(): ?int - { - if (common_config('site', 'use_x_sendfile')) { - return null; - } - $path = $this->filepath; - if (!empty($path)) { - return filemtime($path); - } else { - return null; - } - } - - /** - * etag header for file - * - * This returns the same data (inode, size, mtime) as Apache would, - * but in decimal instead of hex. - * - * @throws ServerException - * - * @return string etag http header - */ - public function etag(): ?string - { - if (common_config('site', 'use_x_sendfile')) { - return null; - } - - $path = $this->filepath; - - $cache = Cache::instance(); - if ($cache) { - if (empty($path)) { - return null; - } - $key = Cache::key('attachments:etag:' . $path); - $etag = $cache->get($key); - if ($etag === false) { - $etag = crc32(file_get_contents($path)); - $cache->set($key, $etag); - } - return $etag; - } - - if (!empty($path)) { - $stat = stat($path); - return '"' . $stat['ino'] . '-' . $stat['size'] . '-' . $stat['mtime'] . '"'; - } else { - return null; - } - } -} diff --git a/plugins/Media/media/AttachmentListItem.php b/plugins/Media/media/AttachmentListItem.php deleted file mode 100644 index 0ed38a4e15..0000000000 --- a/plugins/Media/media/AttachmentListItem.php +++ /dev/null @@ -1,291 +0,0 @@ -. - * - * @category UI - * @package StatusNet - * - * @author Evan Prodromou - * @author Sarven Capadisli - * @copyright 2008 StatusNet, Inc. - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * - * @see http://status.net/ - */ - -namespace Plugin\Media\media; - -/** - * widget for displaying a single notice - * - * This widget has the core smarts for showing a single notice: what to display, - * where, and under which circumstances. Its key method is show(); this is a recipe - * that calls all the other show*() methods to build up a single notice. The - * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip - * author info (since that's implicit by the data in the page). - * - * @category UI - * @package StatusNet - * - * @author Evan Prodromou - * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 - * - * @see http://status.net/ - * @see NoticeList - * @see ProfileNoticeListItem - */ -class AttachmentListItem -{ - /** The attachment this item will show. */ - public $attachment; - - /** - * @param File $attachment the attachment we will display - */ - // function __construct(File $attachment, $out=null) - // { - // // parent::__construct($out); - // $this->attachment = $attachment; - // } - - public function title() - { - return $this->attachment->getTitle() ?: MediaFile::getDisplayName($this->attachment); - } - - public function linkTitle() - { - return $this->title(); - } - - /** - * recipe function for displaying a single notice. - * - * This uses all the other methods to correctly display a notice. Override - * it or one of the others to fine-tune the output. - * - * @return void - */ - public function show() - { - $this->showStart(); - try { - $this->showNoticeAttachment(); - } catch (Exception $e) { - $this->element('div', ['class' => 'error'], $e->getMessage()); - common_debug($e->getMessage()); - } - $this->showEnd(); - } - - public function linkAttr() - { - return [ - 'class' => 'u-url', - 'href' => $this->attachment->getAttachmentDownloadUrl(), - 'title' => $this->linkTitle(), - ]; - } - - public function showNoticeAttachment() - { - $this->showRepresentation(); - } - - /** - * Show in HTML - */ - public function showRepresentation() - { - $enclosure = $this->attachment->getEnclosure(); - - if (Event::handle('StartShowAttachmentRepresentation', [$this->out, $this->attachment])) { - $this->out->elementStart('label'); - $this->out->element('a', ['rel' => 'external', 'href' => $this->attachment->getAttachmentUrl()], $this->title()); - $this->out->elementEnd('label'); - - $this->out->element('br'); - - try { - if (!empty($enclosure->mimetype)) { - // First, prepare a thumbnail if it exists. - try { - // Tell getThumbnail that we can show an animated image if it has one (4th arg, "force_still") - $thumb = File_thumbnail::fromFileObject($this->attachment, null, null, false, false); - } catch (UseFileAsThumbnailException | UnsupportedMediaException | FileNotFoundException | ServerException $e) { - common_debug("AttachmentListItem couldn't find a thumbnail for {$this->attachment->getID()} because {$e->getMessage()}"); - // This remote file has no local thumbnail. - $thumb = null; - } - - // Then get the kind of mediatype we're dealing with - $mediatype = common_get_mime_media($enclosure->mimetype); - - // FIXME: Get proper mime recognition of Ogg files! If system has 'mediainfo', this should do it: - // $ mediainfo --inform='General;%InternetMediaType%' - if ($this->attachment->mimetype === 'application/ogg') { - $mediatype = 'video'; // because this element can handle Ogg/Vorbis etc. on its own - } - - // Ugly hack to show text/html links which have a thumbnail (such as from oEmbed/OpenGraph image URLs) - if (!in_array($mediatype, ['image', 'audio', 'video']) && $thumb instanceof File_thumbnail) { - $mediatype = 'image'; - } - - switch ($mediatype) { - // Anything we understand as an image, if we need special treatment, do it in StartShowAttachmentRepresentation - case 'image': - if ($thumb instanceof File_thumbnail) { - $this->out->element('img', $thumb->getHtmlAttrs(['class' => 'u-photo', 'alt' => ''])); - } else { - try { - // getUrl(true) because we don't want to hotlink, could be made configurable - $this->out->element('img', ['class' => 'u-photo', - 'src' => $this->attachment->getUrl(true), - 'alt' => $this->attachment->getTitle(), ]); - } catch (FileNotStoredLocallyException $e) { - //$url = $e->file->getUrl(false); - $this->out->element('a', ['href' => $url, 'rel' => 'external'], $url); - } - } - unset($thumb); // there's no need carrying this along after this - break; - - // HTML5 media elements - case 'audio': - case 'video': - if ($thumb instanceof File_thumbnail) { - $poster = $thumb->getUrl(); - unset($thumb); // there's no need carrying this along after this - } else { - $poster = null; - } - - $this->out->elementStart($mediatype, - ['class' => "attachment_player u-{$mediatype}", - 'poster' => $poster, - 'controls' => 'controls', ]); - $this->out->element('source', - ['src' => $this->attachment->getUrl(), - 'type' => $this->attachment->mimetype, ]); - $this->out->elementEnd($mediatype); - break; - - default: - unset($thumb); // there's no need carrying this along - switch (common_bare_mime($this->attachment->mimetype)) { - case 'text/plain': - $this->element('div', ['class' => 'e-content plaintext'], - file_get_contents($this->attachment->getPath())); - break; - case 'text/html': - if (!empty($this->attachment->filename) - && (GNUsocial::isAjax() || common_config('attachments', 'show_html'))) { - // Locally-uploaded HTML. Scrub and display inline. - $this->showHtmlFile($this->attachment); - break; - } - // Fall through to default if it wasn't a _local_ text/html File object - // no break - default: - Event::handle('ShowUnsupportedAttachmentRepresentation', [$this->out, $this->attachment]); - } - } - } else { - Event::handle('ShowUnsupportedAttachmentRepresentation', [$this->out, $this->attachment]); - } - } catch (FileNotFoundException $e) { - if (!$this->attachment->isLocal()) { - throw $e; - } - } - } - Event::handle('EndShowAttachmentRepresentation', [$this->out, $this->attachment]); - } - - protected function showHtmlFile(File $attachment) - { - $body = $this->scrubHtmlFile($attachment); - if ($body) { - $this->out->raw($body); - } - } - - /** - * @return mixed false on failure, HTML fragment string on success - */ - protected function scrubHtmlFile(File $attachment) - { - $path = $attachment->getPath(); - $raw = file_get_contents($path); - - // Normalize... - $dom = new DOMDocument(); - if (!$dom->loadHTML($raw)) { - common_log(LOG_ERR, "Bad HTML in local HTML attachment {$path}"); - return false; - } - - // Remove