From 6af37d4e4ec7d465bc6f71625abceb195aae4ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jer=C3=B4me=20Bakker?= Date: Wed, 5 Jun 2024 12:47:20 +0200 Subject: [PATCH] changed: updated for Elgg 6 --- .github/workflows/phpunit.yml | 4 +- README.md | 2 +- actions/pages/export.php | 4 +- actions/pages/reorder.php | 1 + .../ColdTrick/PagesTools/Menus/PagesNav.php | 6 +- classes/ColdTrick/PagesTools/PDFExport.php | 18 +- classes/ColdTrick/PagesTools/Widgets.php | 21 +-- composer.json | 4 +- composer.lock | 177 +++++++++--------- elgg-plugin.php | 2 +- views/default/forms/pages/export.php | 5 +- views/default/js/pages_tools/navigation.js | 45 ----- views/default/pages_tools/navigation.mjs | 45 +++++ .../default/plugins/pages_tools/settings.php | 1 + views/default/widgets/index_pages/content.php | 2 +- views/default/widgets/index_pages/edit.php | 1 + views/default/widgets/pages/content.php | 34 ---- 17 files changed, 172 insertions(+), 200 deletions(-) delete mode 100644 views/default/js/pages_tools/navigation.js create mode 100644 views/default/pages_tools/navigation.mjs delete mode 100644 views/default/widgets/pages/content.php 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 d8f392e..b13510e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Pages Tools -![Elgg 5.0](https://img.shields.io/badge/Elgg-5.0-green.svg) +![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg) ![Lint Checks](https://github.com/ColdTrick/pages_tools/actions/workflows/lint.yml/badge.svg?event=push) [![Latest Stable Version](https://poser.pugx.org/coldtrick/pages_tools/v/stable.svg)](https://packagist.org/packages/coldtrick/pages_tools) [![License](https://poser.pugx.org/coldtrick/pages_tools/license.svg)](https://packagist.org/packages/coldtrick/pages_tools) diff --git a/actions/pages/export.php b/actions/pages/export.php index 3b7aa0c..7a6c734 100644 --- a/actions/pages/export.php +++ b/actions/pages/export.php @@ -21,6 +21,6 @@ try { PDFExport::toPDF($page, $format, $include_subpages, $include_index); exit(); -} catch (Exception $e) { - return elgg_error_response($e->getMessage()); +} catch (\Throwable $t) { + return elgg_error_response($t->getMessage()); } diff --git a/actions/pages/reorder.php b/actions/pages/reorder.php index 0d2b1b6..06ebf01 100644 --- a/actions/pages/reorder.php +++ b/actions/pages/reorder.php @@ -33,6 +33,7 @@ return elgg_error_response(elgg_echo('pages_tools:actions:reorder:error:subpages')); } +/* @var $sub_page \ElggPage */ foreach ($sub_pages as $sub_page) { $pos = array_search($sub_page->guid, $order) + 1; diff --git a/classes/ColdTrick/PagesTools/Menus/PagesNav.php b/classes/ColdTrick/PagesTools/Menus/PagesNav.php index 9c5b55b..9c13e3a 100644 --- a/classes/ColdTrick/PagesTools/Menus/PagesNav.php +++ b/classes/ColdTrick/PagesTools/Menus/PagesNav.php @@ -2,6 +2,8 @@ namespace ColdTrick\PagesTools\Menus; +use Elgg\Menu\MenuItems; + /** * Add menu items to the pages_nav menu */ @@ -17,7 +19,7 @@ class PagesNav { public static function orderPagesNav(\Elgg\Event $event): void { $load_js = false; - /* @var $return_value = MenuItems */ + /* @var $return_value MenuItems */ $return_value = $event->getValue(); /* @var $item \ElggMenuItem */ @@ -40,7 +42,7 @@ public static function orderPagesNav(\Elgg\Event $event): void { } if ($load_js) { - elgg_require_js('pages_tools/navigation'); + elgg_import_esm('pages_tools/navigation'); } } } diff --git a/classes/ColdTrick/PagesTools/PDFExport.php b/classes/ColdTrick/PagesTools/PDFExport.php index 6842932..07090db 100644 --- a/classes/ColdTrick/PagesTools/PDFExport.php +++ b/classes/ColdTrick/PagesTools/PDFExport.php @@ -20,9 +20,9 @@ class PDFExport { * @param bool $include_index add a index page * @param bool $include_subpages include the subpages * - * @return string contents for PDF + * @return void but streams the contents of the PDF */ - public static function toPDF(\ElggPage $entity, string $format = 'a4', bool $include_index = false, bool $include_subpages = false) { + public static function toPDF(\ElggPage $entity, string $format = 'a4', bool $include_index = false, bool $include_subpages = false): void { // begin of output $html = ''; @@ -61,7 +61,9 @@ public static function toPDF(\ElggPage $entity, string $format = 'a4', bool $inc } // load library - $dompdf = new Dompdf(); + $dompdf = new Dompdf([ + 'enable_remote' => true, + ]); // set correct page format $dompdf->setPaper($format); // set contents @@ -72,13 +74,13 @@ public static function toPDF(\ElggPage $entity, string $format = 'a4', bool $inc } /** - * Get the ordered list sub pages + * Get the ordered list sub-pages * * @param \ElggPage $page the page to get subpages for * - * @return false|\ElggPage[] + * @return null|\ElggPage[] */ - protected static function getOrderedChildren(\ElggPage $page) { + protected static function getOrderedChildren(\ElggPage $page): ?array { $children = elgg_get_entities([ 'type' => 'object', 'subtype' => 'page', @@ -88,7 +90,7 @@ protected static function getOrderedChildren(\ElggPage $page) { ], ]); if (empty($children)) { - return false; + return null; } $result = []; @@ -119,7 +121,6 @@ protected static function getOrderedChildren(\ElggPage $page) { * @return string */ protected static function renderIndex(\ElggPage $page): string { - $children = self::getOrderedChildren($page); if (empty($children)) { return ''; @@ -153,7 +154,6 @@ protected static function renderIndex(\ElggPage $page): string { * @return string */ protected static function renderChildPages(\ElggPage $page): string { - $children = self::getOrderedChildren($page); if (empty($children)) { return ''; diff --git a/classes/ColdTrick/PagesTools/Widgets.php b/classes/ColdTrick/PagesTools/Widgets.php index 5f0778c..51471a0 100644 --- a/classes/ColdTrick/PagesTools/Widgets.php +++ b/classes/ColdTrick/PagesTools/Widgets.php @@ -13,28 +13,21 @@ class Widgets { /** * Add widget title url * - * @param \Elgg\Event $event 'register', 'menu:entity' + * @param \Elgg\Event $event 'entity:url', 'object:widget' * - * @return void|string + * @return null|string */ - public static function widgetURL(\Elgg\Event $event) { - + public static function widgetURL(\Elgg\Event $event): ?string { $return_value = $event->getValue(); if (!empty($return_value)) { - return; + return null; } $widget = $event->getEntityParam(); - if (!$widget instanceof \ElggWidget) { - return; + if (!$widget instanceof \ElggWidget || $widget->handler !== 'index_pages') { + return null; } - switch ($widget->handler) { - case 'pages': - $owner = $widget->getOwnerEntity(); - return $owner instanceof \ElggGroup ? 'pages/group/' . $owner->guid . '/all' : 'pages/owner/' . $owner->username; - case 'index_pages': - return 'pages/all'; - } + return elgg_generate_url('collection:object:pages:all'); } } diff --git a/composer.json b/composer.json index 9ec2af8..de2e24b 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,9 @@ "issues": "https://github.com/ColdTrick/pages_tools/issues" }, "require": { - "dompdf/dompdf" : "~2.0.0" + "dompdf/dompdf" : "~3.0.0" }, "conflict": { - "elgg/elgg": "<5.0" + "elgg/elgg": "<6.0" } } diff --git a/composer.lock b/composer.lock index 835b990..3a7ca7a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,36 +4,38 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5e780d2d44c74e7bc4f3875176f6f5e5", + "content-hash": "402968a83d451654d2c387b12e2404ef", "packages": [ { "name": "dompdf/dompdf", - "version": "v2.0.4", + "version": "v3.0.0", "source": { "type": "git", "url": "https://github.com/dompdf/dompdf.git", - "reference": "093f2d9739cec57428e39ddadedfd4f3ae862c0f" + "reference": "fbc7c5ee5d94f7a910b78b43feb7931b7f971b59" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dompdf/dompdf/zipball/093f2d9739cec57428e39ddadedfd4f3ae862c0f", - "reference": "093f2d9739cec57428e39ddadedfd4f3ae862c0f", + "url": "https://api.github.com/repos/dompdf/dompdf/zipball/fbc7c5ee5d94f7a910b78b43feb7931b7f971b59", + "reference": "fbc7c5ee5d94f7a910b78b43feb7931b7f971b59", "shasum": "" }, "require": { + "dompdf/php-font-lib": "^1.0.0", + "dompdf/php-svg-lib": "^1.0.0", "ext-dom": "*", "ext-mbstring": "*", "masterminds/html5": "^2.0", - "phenx/php-font-lib": ">=0.5.4 <1.0.0", - "phenx/php-svg-lib": ">=0.3.3 <1.0.0", "php": "^7.1 || ^8.0" }, "require-dev": { + "ext-gd": "*", "ext-json": "*", "ext-zip": "*", "mockery/mockery": "^1.3", - "phpunit/phpunit": "^7.5 || ^8 || ^9", - "squizlabs/php_codesniffer": "^3.5" + "phpunit/phpunit": "^7.5 || ^8 || ^9 || ^10", + "squizlabs/php_codesniffer": "^3.5", + "symfony/process": "^4.4 || ^5.4 || ^6.2 || ^7.0" }, "suggest": { "ext-gd": "Needed to process images", @@ -64,166 +66,167 @@ "homepage": "https://github.com/dompdf/dompdf", "support": { "issues": "https://github.com/dompdf/dompdf/issues", - "source": "https://github.com/dompdf/dompdf/tree/v2.0.4" + "source": "https://github.com/dompdf/dompdf/tree/v3.0.0" }, - "time": "2023-12-12T20:19:39+00:00" + "time": "2024-04-29T14:01:28+00:00" }, { - "name": "masterminds/html5", - "version": "2.8.1", + "name": "dompdf/php-font-lib", + "version": "1.0.0", "source": { "type": "git", - "url": "https://github.com/Masterminds/html5-php.git", - "reference": "f47dcf3c70c584de14f21143c55d9939631bc6cf" + "url": "https://github.com/dompdf/php-font-lib.git", + "reference": "991d6a954f6bbd7e41022198f00586b230731441" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/f47dcf3c70c584de14f21143c55d9939631bc6cf", - "reference": "f47dcf3c70c584de14f21143c55d9939631bc6cf", + "url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/991d6a954f6bbd7e41022198f00586b230731441", + "reference": "991d6a954f6bbd7e41022198f00586b230731441", "shasum": "" }, "require": { - "ext-dom": "*", - "php": ">=5.3.0" + "ext-mbstring": "*", + "php": "^7.1 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8" + "symfony/phpunit-bridge": "^3 || ^4 || ^5 || ^6" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, "autoload": { "psr-4": { - "Masterminds\\": "src" + "FontLib\\": "src/FontLib" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "LGPL-2.1-or-later" ], "authors": [ { - "name": "Matt Butcher", - "email": "technosophos@gmail.com" - }, - { - "name": "Matt Farina", - "email": "matt@mattfarina.com" - }, - { - "name": "Asmir Mustafic", - "email": "goetas@gmail.com" + "name": "The FontLib Community", + "homepage": "https://github.com/dompdf/php-font-lib/blob/master/AUTHORS.md" } ], - "description": "An HTML5 parser and serializer.", - "homepage": "http://masterminds.github.io/html5-php", - "keywords": [ - "HTML5", - "dom", - "html", - "parser", - "querypath", - "serializer", - "xml" - ], + "description": "A library to read, parse, export and make subsets of different types of font files.", + "homepage": "https://github.com/dompdf/php-font-lib", "support": { - "issues": "https://github.com/Masterminds/html5-php/issues", - "source": "https://github.com/Masterminds/html5-php/tree/2.8.1" + "issues": "https://github.com/dompdf/php-font-lib/issues", + "source": "https://github.com/dompdf/php-font-lib/tree/1.0.0" }, - "time": "2023-05-10T11:58:31+00:00" + "time": "2024-04-29T13:40:38+00:00" }, { - "name": "phenx/php-font-lib", - "version": "0.5.4", + "name": "dompdf/php-svg-lib", + "version": "1.0.0", "source": { "type": "git", - "url": "https://github.com/dompdf/php-font-lib.git", - "reference": "dd448ad1ce34c63d09baccd05415e361300c35b4" + "url": "https://github.com/dompdf/php-svg-lib.git", + "reference": "eb045e518185298eb6ff8d80d0d0c6b17aecd9af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/dd448ad1ce34c63d09baccd05415e361300c35b4", - "reference": "dd448ad1ce34c63d09baccd05415e361300c35b4", + "url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/eb045e518185298eb6ff8d80d0d0c6b17aecd9af", + "reference": "eb045e518185298eb6ff8d80d0d0c6b17aecd9af", "shasum": "" }, "require": { - "ext-mbstring": "*" + "ext-mbstring": "*", + "php": "^7.1 || ^8.0", + "sabberworm/php-css-parser": "^8.4" }, "require-dev": { - "symfony/phpunit-bridge": "^3 || ^4 || ^5" + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5" }, "type": "library", "autoload": { "psr-4": { - "FontLib\\": "src/FontLib" + "Svg\\": "src/Svg" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-3.0" + "LGPL-3.0-or-later" ], "authors": [ { - "name": "Fabien Ménager", - "email": "fabien.menager@gmail.com" + "name": "The SvgLib Community", + "homepage": "https://github.com/dompdf/php-svg-lib/blob/master/AUTHORS.md" } ], - "description": "A library to read, parse, export and make subsets of different types of font files.", - "homepage": "https://github.com/PhenX/php-font-lib", + "description": "A library to read, parse and export to PDF SVG files.", + "homepage": "https://github.com/dompdf/php-svg-lib", "support": { - "issues": "https://github.com/dompdf/php-font-lib/issues", - "source": "https://github.com/dompdf/php-font-lib/tree/0.5.4" + "issues": "https://github.com/dompdf/php-svg-lib/issues", + "source": "https://github.com/dompdf/php-svg-lib/tree/1.0.0" }, - "time": "2021-12-17T19:44:54+00:00" + "time": "2024-04-29T13:26:35+00:00" }, { - "name": "phenx/php-svg-lib", - "version": "0.5.2", + "name": "masterminds/html5", + "version": "2.9.0", "source": { "type": "git", - "url": "https://github.com/dompdf/php-svg-lib.git", - "reference": "732faa9fb4309221e2bd9b2fda5de44f947133aa" + "url": "https://github.com/Masterminds/html5-php.git", + "reference": "f5ac2c0b0a2eefca70b2ce32a5809992227e75a6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/732faa9fb4309221e2bd9b2fda5de44f947133aa", - "reference": "732faa9fb4309221e2bd9b2fda5de44f947133aa", + "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/f5ac2c0b0a2eefca70b2ce32a5809992227e75a6", + "reference": "f5ac2c0b0a2eefca70b2ce32a5809992227e75a6", "shasum": "" }, "require": { - "ext-mbstring": "*", - "php": "^7.1 || ^8.0", - "sabberworm/php-css-parser": "^8.4" + "ext-dom": "*", + "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5" + "phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8 || ^9" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, "autoload": { "psr-4": { - "Svg\\": "src/Svg" + "Masterminds\\": "src" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-3.0" + "MIT" ], "authors": [ { - "name": "Fabien Ménager", - "email": "fabien.menager@gmail.com" + "name": "Matt Butcher", + "email": "technosophos@gmail.com" + }, + { + "name": "Matt Farina", + "email": "matt@mattfarina.com" + }, + { + "name": "Asmir Mustafic", + "email": "goetas@gmail.com" } ], - "description": "A library to read, parse and export to PDF SVG files.", - "homepage": "https://github.com/PhenX/php-svg-lib", + "description": "An HTML5 parser and serializer.", + "homepage": "http://masterminds.github.io/html5-php", + "keywords": [ + "HTML5", + "dom", + "html", + "parser", + "querypath", + "serializer", + "xml" + ], "support": { - "issues": "https://github.com/dompdf/php-svg-lib/issues", - "source": "https://github.com/dompdf/php-svg-lib/tree/0.5.2" + "issues": "https://github.com/Masterminds/html5-php/issues", + "source": "https://github.com/Masterminds/html5-php/tree/2.9.0" }, - "time": "2024-02-07T12:49:40+00:00" + "time": "2024-03-31T07:05:07+00:00" }, { "name": "sabberworm/php-css-parser", diff --git a/elgg-plugin.php b/elgg-plugin.php index 1dd3d25..5ad8196 100644 --- a/elgg-plugin.php +++ b/elgg-plugin.php @@ -18,7 +18,7 @@ ], 'events' => [ 'entity:url' => [ - 'object' => [ + 'object:widget' => [ '\ColdTrick\PagesTools\Widgets::widgetURL' => [], ], ], diff --git a/views/default/forms/pages/export.php b/views/default/forms/pages/export.php index 5a318aa..ff249f8 100644 --- a/views/default/forms/pages/export.php +++ b/views/default/forms/pages/export.php @@ -1,6 +1,9 @@ 'select', @@ -41,7 +44,7 @@ $footer = elgg_view_field([ '#type' => 'submit', 'text' => elgg_echo('export'), - 'onclick' => '$.colorbox.close();', + 'onclick' => 'import("elgg/lightbox").then((lightbox) => {lightbox.default.close();});', ]); elgg_set_form_footer($footer); diff --git a/views/default/js/pages_tools/navigation.js b/views/default/js/pages_tools/navigation.js deleted file mode 100644 index b1816b5..0000000 --- a/views/default/js/pages_tools/navigation.js +++ /dev/null @@ -1,45 +0,0 @@ -define(['jquery', 'elgg/Ajax', 'jquery-ui/widgets/sortable'], function($, Ajax) { - var ajax = new Ajax(false); - - $('.elgg-menu-pages-nav > li ul').sortable({ - items: '> li', - revert: true, - connectWith: '.elgg-menu-pages-nav > li ul', - forcePlaceholderSize: true, - containment: 'parent', - tolerance: 'pointer', - start: function(event, ui) { - $(ui.item).find(' > a').addClass('dragged'); - }, - update: function(event, ui) { - - if (!$(this).is($(ui.item).parent())) { - // only trigger update on receiving sortable - return; - } - - var $parent = $(ui.item).parent().parent(); - var parent_guid = $parent.data('menuItem'); - var new_order = []; - - $parent.find('> ul > li').each(function(index, child) { - new_order[index] = $(child).data('menuItem'); - }); - - ajax.action('pages/reorder', { - data: { - guid: parent_guid, - order: new_order - } - }); - } - }); - - $('.elgg-menu-pages-nav li a').on('click', function(event) { - if ($(this).hasClass('dragged')) { - event.preventDefault(); - event.stopImmediatePropagation(); - $(this).removeClass('dragged'); - } - }); -}); diff --git a/views/default/pages_tools/navigation.mjs b/views/default/pages_tools/navigation.mjs new file mode 100644 index 0000000..79bfd4f --- /dev/null +++ b/views/default/pages_tools/navigation.mjs @@ -0,0 +1,45 @@ +import 'jquery'; +import 'jquery-ui'; +import Ajax from 'elgg/Ajax'; + +$('.elgg-menu-pages-nav > li ul').sortable({ + items: '> li', + revert: true, + connectWith: '.elgg-menu-pages-nav > li ul', + forcePlaceholderSize: true, + containment: 'parent', + tolerance: 'pointer', + start: function(event, ui) { + $(ui.item).find(' > a').addClass('dragged'); + }, + update: function(event, ui) { + if (!$(this).is($(ui.item).parent())) { + // only trigger update on receiving sortable + return; + } + + var $parent = $(ui.item).parent().parent(); + var parent_guid = $parent.data('menuItem'); + var new_order = []; + + $parent.find('> ul > li').each(function(index, child) { + new_order[index] = $(child).data('menuItem'); + }); + + var ajax = new Ajax(false); + ajax.action('pages/reorder', { + data: { + guid: parent_guid, + order: new_order + } + }); + } +}); + +$('.elgg-menu-pages-nav li a').on('click', function(event) { + if ($(this).hasClass('dragged')) { + event.preventDefault(); + event.stopImmediatePropagation(); + $(this).removeClass('dragged'); + } +}); diff --git a/views/default/plugins/pages_tools/settings.php b/views/default/plugins/pages_tools/settings.php index 2157e93..fbb0cdc 100644 --- a/views/default/plugins/pages_tools/settings.php +++ b/views/default/plugins/pages_tools/settings.php @@ -1,5 +1,6 @@ (int) $widget->pages_count ?: 8, 'pagination' => false, 'no_results' => elgg_echo('pages:none'), - 'widget_more' => elgg_view_url(elgg_generate_url('collection:object:page:all'), elgg_echo('pages:more')), + 'widget_more' => elgg_view_url($widget->getURL(), elgg_echo('pages:more')), ]); diff --git a/views/default/widgets/index_pages/edit.php b/views/default/widgets/index_pages/edit.php index 1e86a33..d1d8ec1 100644 --- a/views/default/widgets/index_pages/edit.php +++ b/views/default/widgets/index_pages/edit.php @@ -1,5 +1,6 @@ 'object', - 'subtype' => 'page', - 'container_guid' => $widget->owner_guid, - 'metadata_name_value_pairs' => [ - 'parent_guid' => 0, - ], - 'limit' => (int) $widget->pages_num ?: 4, - 'pagination' => false, - 'no_results' => elgg_echo('pages:none'), -]; - -$owner = $widget->getOwnerEntity(); -if ($owner instanceof \ElggGroup) { - $url = elgg_generate_url('collection:object:page:group', ['guid' => $owner->guid]); -} else { - $url = elgg_generate_url('collection:object:page:owner', ['username' => $owner->username]); -} - -if (!empty($url)) { - $options['widget_more'] = elgg_view_url($url, elgg_echo('pages:more')); -} - -echo elgg_list_entities($options);