From 1c861a27650ef16d51031678ff5d198736902882 Mon Sep 17 00:00:00 2001 From: splitbrain Date: Sun, 3 Sep 2023 17:18:31 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Automatic=20code=20style=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GalleryNode.php | 3 +-- action/prosemirror.php | 18 ++++++++++-------- classes/BasicFormatter.php | 14 +++++++------- classes/FeedGallery.php | 9 ++++++--- classes/Image.php | 2 +- classes/NamespaceGallery.php | 1 - classes/Options.php | 20 +++++++++----------- classes/XHTMLFormatter.php | 8 +++----- conf/default.php | 1 + conf/metadata.php | 2 +- syntax/list.php | 2 -- syntax/main.php | 18 +++++++----------- 12 files changed, 46 insertions(+), 52 deletions(-) diff --git a/GalleryNode.php b/GalleryNode.php index 5af9edc..09d82e0 100644 --- a/GalleryNode.php +++ b/GalleryNode.php @@ -6,7 +6,6 @@ use dokuwiki\plugin\prosemirror\parser\Node; class GalleryNode extends Node { - protected $parent; protected $data; @@ -77,7 +76,7 @@ class GalleryNode extends Node $alignLeft = $attrs['align'] === 'left' ? ' ' : ''; $alignRight = $attrs['align'] === 'right' ? ' ' : ''; $result = '{{gallery>' . $alignRight . $attrs['namespace']; - if (!empty($query)) { + if ($query !== []) { $result .= '?' . implode('&', $query); } $result .= $alignLeft . '}}'; diff --git a/action/prosemirror.php b/action/prosemirror.php index 5d21232..69f30c9 100644 --- a/action/prosemirror.php +++ b/action/prosemirror.php @@ -1,10 +1,13 @@ data['name'] !== 'gallery') { return; @@ -110,7 +113,7 @@ class action_plugin_gallery_prosemirror extends DokuWiki_Action_Plugin if ($data['align'] === 1) { $data['align'] = 'right'; - } else if ($data['align'] === 2) { + } elseif ($data['align'] === 2) { $data['align'] = 'left'; } else { $data['align'] = 'center'; @@ -133,7 +136,7 @@ class action_plugin_gallery_prosemirror extends DokuWiki_Action_Plugin * * @return void */ - public function parseToSyntax(Doku_Event $event, $param) + public function parseToSyntax(Event $event, $param) { if ($event->data['node']['type'] !== 'dwplugin_gallery') { return; @@ -155,7 +158,7 @@ class action_plugin_gallery_prosemirror extends DokuWiki_Action_Plugin * * @return void */ - public function renderAttributesToHTML(Doku_Event $event, $param) + public function renderAttributesToHTML(Event $event, $param) { if ($event->data !== 'plugin_gallery_prosemirror') { return; @@ -170,4 +173,3 @@ class action_plugin_gallery_prosemirror extends DokuWiki_Action_Plugin echo $html; } } - diff --git a/classes/BasicFormatter.php b/classes/BasicFormatter.php index 521cfcc..dde1272 100644 --- a/classes/BasicFormatter.php +++ b/classes/BasicFormatter.php @@ -2,7 +2,6 @@ namespace dokuwiki\plugin\gallery\classes; - /** * Formats the gallery * @@ -10,8 +9,8 @@ namespace dokuwiki\plugin\gallery\classes; * good, but will work with any renderer. Specialized formatters can be created for each renderer to make * use of their special features. */ -class BasicFormatter { - +class BasicFormatter +{ protected Options $options; protected \Doku_Renderer $renderer; @@ -47,8 +46,9 @@ class BasicFormatter { * @param Image $image * @return void */ - protected function renderImage(Image $image) { - list($w, $h) = $this->getThumbnailSize($image); + protected function renderImage(Image $image) + { + [$w, $h] = $this->getThumbnailSize($image); $link = $image->getDetaillink() ?: $image->getSrc(); $imgdata = [ @@ -60,7 +60,7 @@ class BasicFormatter { 'cache' => '' ]; - if($image->isExternal()) { + if ($image->isExternal()) { $this->renderer->externallink($link, $imgdata); } else { $this->renderer->internalmedia(":$link", $imgdata); // prefix with : to ensure absolute src @@ -80,7 +80,7 @@ class BasicFormatter { $crop = true; } if (!$crop) { - list($thumbWidth, $thumbHeight) = $this->fitBoundingBox( + [$thumbWidth, $thumbHeight] = $this->fitBoundingBox( $image->getWidth(), $image->getHeight(), $this->options->thumbnailWidth, diff --git a/classes/FeedGallery.php b/classes/FeedGallery.php index 7db0cbd..44045e1 100644 --- a/classes/FeedGallery.php +++ b/classes/FeedGallery.php @@ -2,6 +2,7 @@ namespace dokuwiki\plugin\gallery\classes; +use SimplePie\Enclosure; use FeedParser; class FeedGallery extends AbstractGallery @@ -27,15 +28,17 @@ class FeedGallery extends AbstractGallery * @return void * @throws \Exception */ - protected function parseFeed($url) { + protected function parseFeed($url) + { $feed = new FeedParser(); $feed->set_feed_url($url); + $ok = $feed->init(); if (!$ok) throw new \Exception($feed->error()); foreach ($feed->get_items() as $item) { $enclosure = $item->get_enclosure(); - if (!$enclosure) continue; + if (!$enclosure instanceof Enclosure) continue; // skip non-image enclosures if ($enclosure->get_type() && substr($enclosure->get_type(), 0, 5) != 'image') { @@ -87,7 +90,7 @@ class FeedGallery extends AbstractGallery protected function initBaseUrl($url) { $main = parse_url($url); - $this->feedHost = $main['scheme'] . '://' . $main['host'] . (!empty($main['port']) ? ':' . $main['port'] : ''); + $this->feedHost = $main['scheme'] . '://' . $main['host'] . (empty($main['port']) ? '' : ':' . $main['port']); $this->feedPath = dirname($main['path']) . '/'; } } diff --git a/classes/Image.php b/classes/Image.php index 1d11417..079efe1 100644 --- a/classes/Image.php +++ b/classes/Image.php @@ -6,7 +6,7 @@ use dokuwiki\Utf8\PhpString; class Image { - const IMG_REGEX = '/\.(jpe?g|gif|png|svg|webp)$/i'; + public const IMG_REGEX = '/\.(jpe?g|gif|png|svg|webp)$/i'; protected $isExternal = false; protected $src; diff --git a/classes/NamespaceGallery.php b/classes/NamespaceGallery.php index de13606..298e18a 100644 --- a/classes/NamespaceGallery.php +++ b/classes/NamespaceGallery.php @@ -4,7 +4,6 @@ namespace dokuwiki\plugin\gallery\classes; class NamespaceGallery extends AbstractGallery { - /** @inheritdoc */ public function __construct($ns, $options) { diff --git a/classes/Options.php b/classes/Options.php index 06aa788..bdc87ee 100644 --- a/classes/Options.php +++ b/classes/Options.php @@ -4,17 +4,16 @@ namespace dokuwiki\plugin\gallery\classes; class Options { + public const SORT_FILE = 'file'; + public const SORT_CTIME = 'date'; + public const SORT_MTIME = 'mod'; + public const SORT_TITLE = 'title'; + public const SORT_RANDOM = 'random'; - const SORT_FILE = 'file'; - const SORT_CTIME = 'date'; - const SORT_MTIME = 'mod'; - const SORT_TITLE = 'title'; - const SORT_RANDOM = 'random'; - - const ALIGN_FULL = 0; - const ALIGN_LEFT = 1; - const ALIGN_RIGHT = 2; - const ALIGN_CENTER = 3; + public const ALIGN_FULL = 0; + public const ALIGN_LEFT = 1; + public const ALIGN_RIGHT = 2; + public const ALIGN_CENTER = 3; // defaults public string $galleryID = ''; @@ -116,5 +115,4 @@ class Options } } } - } diff --git a/classes/XHTMLFormatter.php b/classes/XHTMLFormatter.php index 6aff433..48a4f28 100644 --- a/classes/XHTMLFormatter.php +++ b/classes/XHTMLFormatter.php @@ -2,10 +2,8 @@ namespace dokuwiki\plugin\gallery\classes; - class XHTMLFormatter extends BasicFormatter { - // region Main Render Functions /** @inheritdoc */ @@ -105,7 +103,7 @@ class XHTMLFormatter extends BasicFormatter global $ID; // thumbnail image properties - list($w, $h) = $this->getThumbnailSize($image); + [$w, $h] = $this->getThumbnailSize($image); $w *= 2; // retina $h *= 2; $img = []; @@ -122,7 +120,7 @@ class XHTMLFormatter extends BasicFormatter if ($this->options->lightbox) { // double escape for lightbox: - $a['data-caption'] = join(' – ', array_filter([ + $a['data-caption'] = implode(' – ', array_filter([ '' . hsc($image->getTitle()) . '', hsc($image->getDescription()) ])); @@ -210,7 +208,7 @@ class XHTMLFormatter extends BasicFormatter } // fit into bounding box - list($width, $height) = $this->fitBoundingBox( + [$width, $height] = $this->fitBoundingBox( $image->getWidth(), $image->getHeight(), $this->options->lightboxWidth, diff --git a/conf/default.php b/conf/default.php index bc94c48..248fa53 100644 --- a/conf/default.php +++ b/conf/default.php @@ -1,4 +1,5 @@ array( 'showname', 'showtitle', )); - diff --git a/syntax/list.php b/syntax/list.php index b832a88..3af8cb0 100644 --- a/syntax/list.php +++ b/syntax/list.php @@ -10,7 +10,6 @@ use dokuwiki\plugin\gallery\classes\Options; */ class syntax_plugin_gallery_list extends syntax_plugin_gallery_main { - /** @inheritDoc */ public function connectTo($mode) { @@ -33,4 +32,3 @@ class syntax_plugin_gallery_list extends syntax_plugin_gallery_main return [$list, $options]; } } - diff --git a/syntax/main.php b/syntax/main.php index bd4d1e5..ed99804 100644 --- a/syntax/main.php +++ b/syntax/main.php @@ -1,5 +1,6 @@ * @author Dave Doyle */ -class syntax_plugin_gallery_main extends DokuWiki_Syntax_Plugin +class syntax_plugin_gallery_main extends SyntaxPlugin { - /** @inheritdoc */ public function getType() { @@ -59,7 +59,7 @@ class syntax_plugin_gallery_main extends DokuWiki_Syntax_Plugin if (substr($match, -1, 1) == ' ') $options->align += Options::ALIGN_LEFT; // extract src and params - list($src, $params) = sexplode('?', $match, 2); + [$src, $params] = sexplode('?', $match, 2); $src = trim($src); // resolve relative namespace @@ -82,7 +82,6 @@ class syntax_plugin_gallery_main extends DokuWiki_Syntax_Plugin [$src, $options] = $data; try { - if (is_array($src)) { $gallery = new ListGallery($src, $options); } elseif (preg_match('/^https?:\/\//i', $src)) { @@ -92,13 +91,10 @@ class syntax_plugin_gallery_main extends DokuWiki_Syntax_Plugin } $R->info['cache'] = $options->cache; - switch ($mode) { - case 'xhtml': - $formatter = new XHTMLFormatter($R, $options); - break; - // FIXME additional specialized Formatters could be added here (PDF, ODT) - default: - $formatter = new BasicFormatter($R, $options); + if ($mode == 'xhtml') { + $formatter = new XHTMLFormatter($R, $options); + } else { + $formatter = new BasicFormatter($R, $options); } $formatter->render($gallery); } catch (Exception $e) {