diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 67fe092..6147873 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests on: [push, pull_request] jobs: - lint: + phpunit: name: Run PHPUnit test suites uses: ColdTrick/.github/.github/workflows/phpunit.yml@master + with: + elgg_major_version: 6 diff --git a/README.md b/README.md index 2645e0d..44a7356 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Blog Tools ========== -![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg) +![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg) ![Lint Checks](https://github.com/ColdTrick/blog_tools/actions/workflows/lint.yml/badge.svg?event=push) [![Latest Stable Version](https://poser.pugx.org/coldtrick/blog_tools/v/stable.svg)](https://packagist.org/packages/coldtrick/blog_tools) [![License](https://poser.pugx.org/coldtrick/blog_tools/license.svg)](https://packagist.org/packages/coldtrick/blog_tools) diff --git a/classes/ColdTrick/BlogTools/Cron.php b/classes/ColdTrick/BlogTools/Cron.php index d784041..2653401 100644 --- a/classes/ColdTrick/BlogTools/Cron.php +++ b/classes/ColdTrick/BlogTools/Cron.php @@ -14,7 +14,7 @@ class Cron { * * @return void */ - public static function publication(\Elgg\Event $event) { + public static function publication(\Elgg\Event $event): void { // only do if this is configured if (elgg_get_plugin_setting('advanced_publication', 'blog_tools') !== 'yes') { return; @@ -35,10 +35,9 @@ public static function publication(\Elgg\Event $event) { * * @return void */ - protected static function publishBlogs($time) { - + protected static function publishBlogs(int $time): void { // adjust for time drift of the cron start - // eg. CRON started @ 11:00:05 + // e.g. CRON started @ 11:00:05 $time_min = $time - 60; // - 1 minute $time_max = $time + 60; // + 1 minute diff --git a/classes/ColdTrick/BlogTools/Upgrades/MoveHeaderIcons.php b/classes/ColdTrick/BlogTools/Upgrades/MoveHeaderIcons.php deleted file mode 100644 index e45d4ad..0000000 --- a/classes/ColdTrick/BlogTools/Upgrades/MoveHeaderIcons.php +++ /dev/null @@ -1,83 +0,0 @@ -countItems()); - } - - /** - * {@inheritdoc} - */ - public function countItems(): int { - return elgg_count_entities($this->getOptions()); - } - - /** - * {@inheritdoc} - */ - public function run(Result $result, $offset): Result { - $blogs = elgg_get_entities($this->getOptions(['offset' => $offset])); - /* @var $blog \ElggBlog */ - foreach ($blogs as $blog) { - $old_icon = $blog->getIcon('master', 'icon'); - if ($old_icon->exists()) { - $coords = [ - 'x1' => $blog->x1, - 'y1' => $blog->y1, - 'x2' => $blog->x2, - 'y2' => $blog->y2, - ]; - - $blog->saveIconFromElggFile($old_icon, 'header', $coords); - } - - $blog->deleteIcon('icon'); - - $result->addSuccesses(); - } - - return $result; - } - - /** - * Get options for elgg_get_entities - * - * @param array $options additional options - * - * @return array - */ - protected function getOptions(array $options = []) { - $defaults = [ - 'type' => 'object', - 'subtype' => 'blog', - 'limit' => 50, - 'batch' => true, - 'metadata_name' => 'icontime', - ]; - - return array_merge($defaults, $options); - } -} diff --git a/classes/ColdTrick/BlogTools/Views.php b/classes/ColdTrick/BlogTools/Views.php index ad98069..d00e8e6 100644 --- a/classes/ColdTrick/BlogTools/Views.php +++ b/classes/ColdTrick/BlogTools/Views.php @@ -14,12 +14,11 @@ class Views { * * @param \Elgg\Event $event 'view_vars', 'blog/sidebar/archives' * - * @return void|array + * @return null|array */ - public static function preventBlogArchiveSidebar(\Elgg\Event $event) { - + public static function preventBlogArchiveSidebar(\Elgg\Event $event): ?array { if (!(bool) elgg_get_plugin_setting('archive_menu', 'blog_tools')) { - return; + return null; } $return = $event->getValue(); @@ -27,23 +26,4 @@ public static function preventBlogArchiveSidebar(\Elgg\Event $event) { return $return; } - - /** - * Prevent double submit of the blog/save form - * - * @param \Elgg\Event $event 'view_vars', 'input/form' - * - * @return null|array - * @todo remove in Elgg 5.1 - */ - public static function preventDoubleSubmit(\Elgg\Event $event): ?array { - $vars = $event->getValue(); - if (elgg_extract('action_name', $vars) !== 'blog/save') { - return null; - } - - $vars['prevent_double_submit'] = true; - - return $vars; - } } diff --git a/classes/ColdTrick/BlogTools/Widgets.php b/classes/ColdTrick/BlogTools/Widgets.php index 10ae3a3..c31d416 100644 --- a/classes/ColdTrick/BlogTools/Widgets.php +++ b/classes/ColdTrick/BlogTools/Widgets.php @@ -12,36 +12,20 @@ class Widgets { * * @param \Elgg\Event $event 'entity:url', 'object' * - * @return void|string + * @return null|string */ - public static function widgetUrl(\Elgg\Event $event) { - + public static function widgetUrl(\Elgg\Event $event): ?string { if (!empty($event->getValue())) { - return; + // url already provided + return null; } $widget = $event->getEntityParam(); - if (!$widget instanceof \ElggWidget) { - return; + if (!$widget instanceof \ElggWidget || $widget->handler !== 'index_blog') { + return null; } - switch ($widget->handler) { - case 'index_blog': - return elgg_generate_url('collection:object:blog:all'); - - case 'blog': - $owner = $widget->getOwnerEntity(); - if ($owner instanceof \ElggUser) { - return elgg_generate_url('collection:object:blog:owner', [ - 'username' => $owner->username, - ]); - } elseif ($owner instanceof \ElggGroup) { - return elgg_generate_url('collection:object:blog:group', [ - 'guid' => $owner->guid, - ]); - } - break; - } + return elgg_generate_url('collection:object:blog:all'); } /** @@ -52,7 +36,6 @@ public static function widgetUrl(\Elgg\Event $event) { * @return void|array */ public static function groupTools(\Elgg\Event $event) { - $entity = $event->getEntityParam(); if (!$entity instanceof \ElggGroup) { return; diff --git a/composer.json b/composer.json index 529d00b..e329096 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,6 @@ "issues": "https://github.com/ColdTrick/blog_tools/issues" }, "conflict": { - "elgg/elgg": "<5.1" + "elgg/elgg": "<6.0" } } diff --git a/composer.lock b/composer.lock index 50af82d..1bae678 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "03faf6ee6364abf15af03580ebe4c43e", + "content-hash": "d8c0c88e02e0181cf40002db5e1375bf", "packages": [], "packages-dev": [], "aliases": [], diff --git a/elgg-plugin.php b/elgg-plugin.php index a6e4770..08dd623 100644 --- a/elgg-plugin.php +++ b/elgg-plugin.php @@ -1,7 +1,5 @@ [ 'version' => '13.0.1', @@ -16,9 +14,6 @@ 'archive_menu' => false, 'advanced_publication' => 'no', ], - 'upgrades' => [ - MoveHeaderIcons::class, - ], 'actions' => [ 'blog/save' => [], 'blog_tools/toggle_featured' => [ @@ -74,9 +69,6 @@ 'blog/sidebar/archives' => [ '\ColdTrick\BlogTools\Views::preventBlogArchiveSidebar' => [], ], - 'input/form' => [ - '\ColdTrick\BlogTools\Views::preventDoubleSubmit' => [], - ], ], ], 'view_extensions' => [ diff --git a/languages/en.php b/languages/en.php index 172b99b..23b2e8d 100644 --- a/languages/en.php +++ b/languages/en.php @@ -58,7 +58,4 @@ 'blog_tools:widgets:index_blog:view_mode:preview' => "Preview", 'blog_tools:widgets:index_blog:view_mode:slider' => "Slider", 'blog_tools:widgets:index_blog:view_mode:simple' => "Simple", - - 'blog_tools:upgrade:2023032800:title' => "Move blog icons to header images", - 'blog_tools:upgrade:2023032800:description' => "In Elgg 5 there is built in header image support. This migration moves old icons uploaded with blogs to this new location.", ]; diff --git a/languages/nl.php b/languages/nl.php index 933ee53..a28c617 100644 --- a/languages/nl.php +++ b/languages/nl.php @@ -5,8 +5,6 @@ */ return array ( - 'blog_tools:upgrade:2023032800:title' => 'Verplaats blog iconen naar kopafbeeldingen', - 'blog_tools:upgrade:2023032800:description' => 'In Elgg 5 is ondersteuning voor kopafbeeldingen. Deze migratie verplaatst de oude iconen naar de nieuwe locatie.', 'collection:object:blog:tag' => 'Blogs met de tag: %s', 'blog_tools:label:publication_time' => 'Publicatie tijd', 'blog_tools:publication_time:description' => 'In combinatie met de publicatie datum, stelt dit de tijd van publicatie in', diff --git a/views/default/forms/blog/save.php b/views/default/forms/blog/save.php index 36a3b0d..a1b637c 100644 --- a/views/default/forms/blog/save.php +++ b/views/default/forms/blog/save.php @@ -7,7 +7,7 @@ * - status moved to blog_tools/edit/publication_options */ -elgg_require_js('forms/blog/save'); +elgg_import_esm('forms/blog/save'); $blog = elgg_extract('entity', $vars); diff --git a/views/default/widgets/blog/content.php b/views/default/widgets/blog/content.php index 191c194..0345764 100644 --- a/views/default/widgets/blog/content.php +++ b/views/default/widgets/blog/content.php @@ -3,8 +3,10 @@ * User blog widget display view */ -/* @var $widget \ElggWidget */ $widget = elgg_extract('entity', $vars); +if (!$widget instanceof \ElggWidget) { + return; +} $num_display = (int) $widget->num_display ?: 4; @@ -17,20 +19,17 @@ 'metadata_name_value_pairs' => [], 'metadata_case_sensitive' => false, 'no_results' => elgg_echo('blog:none'), + 'widget_more' => elgg_view_url($widget->getURL(), elgg_echo('blog:moreblogs')), ]; $owner = $widget->getOwnerEntity(); if ($owner instanceof \ElggUser) { $options['owner_guid'] = $owner->guid; - $url = elgg_generate_url('collection:object:blog:owner', ['username' => $owner->username]); } elseif ($owner instanceof \ElggGroup) { - $options['container_guid'] = $widget->owner_guid; - $url = elgg_generate_url('collection:object:blog:group', ['guid' => $owner->guid]); -} else { - $url = elgg_generate_url('collection:object:blog:all'); + $options['container_guid'] = $owner->guid; } -if (!elgg_is_admin_logged_in() && ($widget->owner_guid !== elgg_get_logged_in_user_guid())) { +if (!elgg_is_admin_logged_in() && ($owner->guid !== elgg_get_logged_in_user_guid())) { $options['metadata_name_value_pairs'][] = [ 'name' => 'status', 'value' => 'published', @@ -45,6 +44,4 @@ ]; } -$options['widget_more'] = elgg_view_url($url, elgg_echo('blog:moreblogs')); - echo elgg_list_entities($options); diff --git a/views/default/widgets/index_blog/blog/simple.php b/views/default/widgets/index_blog/blog/simple.php index 3f5634d..89d8509 100644 --- a/views/default/widgets/index_blog/blog/simple.php +++ b/views/default/widgets/index_blog/blog/simple.php @@ -28,6 +28,5 @@ 'subtitle' => false, 'show_social_menu' => false, ]; -$params + $vars; - +$params = $params + $vars; echo elgg_view('object/elements/summary', $params); diff --git a/views/default/widgets/index_blog/content.php b/views/default/widgets/index_blog/content.php index eb51ac7..33e9018 100644 --- a/views/default/widgets/index_blog/content.php +++ b/views/default/widgets/index_blog/content.php @@ -88,9 +88,9 @@ echo elgg_format_element('ul', $navigator_attr, implode(PHP_EOL, $lis)); ?> - diff --git a/views/default/widgets/index_blog/slider.js b/views/default/widgets/index_blog/slider.js deleted file mode 100644 index 732f5ae..0000000 --- a/views/default/widgets/index_blog/slider.js +++ /dev/null @@ -1,45 +0,0 @@ -define(['jquery'], function($) { - - function slider() { - - var that = this; - var timer; - var $widget_content; - var $navigator; - var $container; - - this.init = function(widget_guid) { - $widget_content = $('#elgg-widget-content-' + widget_guid); - $navigator = $widget_content.find('.blog-tools-widget-items-navigator'); - $container = $widget_content.find('.blog-tools-widget-items-container'); - - $navigator.on('click', 'li', this.clickNavigator); - timer = setTimeout(that.rotateItems, 10000); - }; - - this.clickNavigator = function() { - clearTimeout(timer); - - var $li = $(this); - var guid = $li.find('> span').eq(0).attr('rel'); - - $navigator.find('li').removeClass('elgg-state-selected'); - $li.addClass('elgg-state-selected'); - - $container.find('.elgg-item').hide(); - $container.find('#elgg-object-' + guid).show(); - - timer = setTimeout(that.rotateItems, 10000); - }; - - this.rotateItems = function() { - if ($navigator.find('li.elgg-state-selected').next().length) { - $navigator.find('li.elgg-state-selected').next().click(); - } else { - $navigator.find('li:first').click(); - } - }; - }; - - return slider; -}); diff --git a/views/default/widgets/index_blog/slider.mjs b/views/default/widgets/index_blog/slider.mjs new file mode 100644 index 0000000..7771c05 --- /dev/null +++ b/views/default/widgets/index_blog/slider.mjs @@ -0,0 +1,43 @@ +import 'jquery'; + +function Slider() { + var that = this; + var timer; + var $widget_content; + var $navigator; + var $container; + + this.init = function(widget_guid) { + $widget_content = $('#elgg-widget-content-' + widget_guid); + $navigator = $widget_content.find('.blog-tools-widget-items-navigator'); + $container = $widget_content.find('.blog-tools-widget-items-container'); + + $navigator.on('click', 'li', this.clickNavigator); + timer = setTimeout(that.rotateItems, 10000); + }; + + this.clickNavigator = function() { + clearTimeout(timer); + + var $li = $(this); + var guid = $li.find('> span').eq(0).attr('rel'); + + $navigator.find('li').removeClass('elgg-state-selected'); + $li.addClass('elgg-state-selected'); + + $container.find('.elgg-item').hide(); + $container.find('#elgg-object-' + guid).show(); + + timer = setTimeout(that.rotateItems, 10000); + }; + + this.rotateItems = function() { + if ($navigator.find('li.elgg-state-selected').next().length) { + $navigator.find('li.elgg-state-selected').next().click(); + } else { + $navigator.find('li:first').click(); + } + }; +} + +export default Slider;