From 1ad67e2e2cf96876a8b31229df8c43519eb713ef Mon Sep 17 00:00:00 2001 From: William Jacoby Date: Mon, 19 Oct 2026 09:53:08 -0500 Subject: [PATCH 1/7] WIP: port Newspage to phpBB 3.3 with ACP settings Work in progress, not finished or tested: ACP settings module with a migration keeping existing settings, bundled message trimmer instead of nickvergessen/phpbb-tool-trimmessage, version 1.4.0-dev for phpBB 3.3.19+, updated tests and a phpBB 3.3 compatibility workflow. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/phpbb-33.yml | 71 +++ README.md | 3 + acp/main_info.php | 21 + acp/main_module.php | 60 +++ adm/style/acp_newspage_settings.html | 61 +++ composer.json | 17 +- composer.lock | 506 +----------------- config/newspage_routing.yml | 4 - config/services.yml | 67 +-- controller/main.php | 14 +- controller/settings.php | 17 +- event/menu_link_listener.php | 8 +- ext.php | 20 + language/en/info_acp_newspage.php | 21 + language/en/install.php | 10 + message_trimmer.php | 67 +++ migrations/v11x/acp_settings.php | 23 + newspage.php | 86 +-- phpunit.xml.dist | 19 +- .../event/overall_header_head_append.html | 2 +- .../overall_header_navigation_prepend.html | 2 +- styles/prosilver/template/newspage_body.html | 5 +- .../prosilver/template/newspage_settings.html | 74 --- .../prosilver/template/viewtopic_postrow.html | 21 +- tests/bootstrap.php | 20 + tests/compatibility.php | 37 ++ tests/controller/settings_test.php | 10 +- tests/event/menu_link_test.php | 20 +- tests/event/viewonline_test.php | 2 +- tests/helper/generate_route_test.php | 2 +- tests/prepare_board.php | 28 + tests/route/get_params_test.php | 2 +- tests/route/get_route_test.php | 2 +- tests/route/get_url_test.php | 2 +- tests/runtime.php | 48 ++ 35 files changed, 629 insertions(+), 743 deletions(-) create mode 100644 .github/workflows/phpbb-33.yml create mode 100644 acp/main_info.php create mode 100644 acp/main_module.php create mode 100644 adm/style/acp_newspage_settings.html create mode 100644 ext.php create mode 100644 language/en/info_acp_newspage.php create mode 100644 language/en/install.php create mode 100644 message_trimmer.php create mode 100644 migrations/v11x/acp_settings.php delete mode 100644 styles/prosilver/template/newspage_settings.html create mode 100644 tests/bootstrap.php create mode 100644 tests/compatibility.php create mode 100644 tests/prepare_board.php create mode 100644 tests/runtime.php diff --git a/.github/workflows/phpbb-33.yml b/.github/workflows/phpbb-33.yml new file mode 100644 index 0000000..72500cd --- /dev/null +++ b/.github/workflows/phpbb-33.yml @@ -0,0 +1,71 @@ +name: phpBB 3.3 compatibility + +on: + push: + branches: [main, phpbb-3.3] + pull_request: + branches: [main] + +permissions: + contents: read + +jobs: + compatibility: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - php: '7.2' + phpunit: '8.5' + - php: '8.4' + phpunit: '9.6' + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + - uses: shivammathur/setup-php@b604ade2a87db23f8871b7182e69ec5e75effb45 # v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, mbstring, sqlite3 + tools: composer:v2, phpunit:${{ matrix.phpunit }} + coverage: none + - name: Validate metadata + run: composer validate --strict --no-check-publish + - name: Prepare phpBB 3.3.19 + env: + BOARD_DIR: ${{ runner.temp }}/newspage-board + run: | + set -euo pipefail + mkdir -p "$BOARD_DIR" + cd "$BOARD_DIR" + release=https://download.phpbb.com/pub/release/3.3/3.3.19/phpBB-3.3.19.zip + curl --fail --location --max-time 180 -o phpBB-3.3.19.zip "$release" + curl --fail --location --max-time 30 -o phpBB-3.3.19.zip.sha256 "$release.sha256" + sha256sum --check phpBB-3.3.19.zip.sha256 + unzip -q phpBB-3.3.19.zip + mkdir -p phpBB3/ext/nickvergessen/newspage + git -C "$GITHUB_WORKSPACE" archive HEAD | tar -x -C phpBB3/ext/nickvergessen/newspage + echo "PHPBB_ROOT=$BOARD_DIR/phpBB3" >> "$GITHUB_ENV" + - name: Unit and trimming regression tests + run: | + phpunit -c phpunit.xml.dist + php tests/compatibility.php "$PHPBB_ROOT" + - name: Install disposable board + run: | + php tests/prepare_board.php "$PHPBB_ROOT" + cd "$PHPBB_ROOT" + php install/phpbbcli.php install store/newspage-install.yml -n + mv install install.disabled + - name: Extension lifecycle and rendering + run: | + set -euo pipefail + cli="$PHPBB_ROOT/bin/phpbbcli.php" + php "$cli" extension:enable nickvergessen/newspage + php tests/runtime.php "$PHPBB_ROOT" enabled + php "$cli" extension:disable nickvergessen/newspage + php "$cli" extension:enable nickvergessen/newspage + php tests/runtime.php "$PHPBB_ROOT" preserved + php "$cli" extension:disable nickvergessen/newspage + php "$cli" extension:purge nickvergessen/newspage + php tests/runtime.php "$PHPBB_ROOT" purged + php "$cli" extension:enable nickvergessen/newspage + php tests/runtime.php "$PHPBB_ROOT" enabled diff --git a/README.md b/README.md index 9e6f3a7..ab23586 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ Set up the dependencies: Go to "ACP" > "Customise" > "Extensions" and enable the "phpBB 3.1 NV Newspage Extension" extension. +Configure Newspage under "ACP" > "Extensions" > "Newspage" > "Settings". Existing news settings are preserved when upgrading. +The News navigation link defaults to the Font Awesome megaphone (`fa-bullhorn`). Its icon class can be changed on the same settings page. + ## List of events diff --git a/acp/main_info.php b/acp/main_info.php new file mode 100644 index 0000000..8870e59 --- /dev/null +++ b/acp/main_info.php @@ -0,0 +1,21 @@ + '\\nickvergessen\\newspage\\acp\\main_module', + 'title' => 'ACP_NEWSPAGE', + 'modes' => array( + 'settings' => array( + 'title' => 'ACP_NEWSPAGE_SETTINGS', + 'auth' => 'ext_nickvergessen/newspage && acl_a_board', + 'cat' => array('ACP_NEWSPAGE'), + ), + ), + ); + } +} diff --git a/acp/main_module.php b/acp/main_module.php new file mode 100644 index 0000000..3cf549c --- /dev/null +++ b/acp/main_module.php @@ -0,0 +1,60 @@ +add_lang_ext('nickvergessen/newspage', array('newspage', 'info_acp_newspage')); + $this->tpl_name = 'acp_newspage_settings'; + $this->page_title = 'ACP_NEWSPAGE_SETTINGS'; + + if (!$auth->acl_get('a_board')) + { + trigger_error($user->lang('NO_AUTH_OPERATION'), E_USER_WARNING); + } + + add_form_key('acp_newspage'); + + if ($request->is_set_post('submit')) + { + if (!check_form_key('acp_newspage')) + { + trigger_error($user->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); + } + + $icon = trim($request->variable('news_icon', 'fa-bullhorn')); + if (!preg_match('/\Afa-[a-z0-9]+(?:-[a-z0-9]+)*\z/', $icon)) + { + trigger_error($user->lang('NEWS_ICON_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); + } + + $phpbb_container->get('nickvergessen.newspage.controller.settings')->save_settings(); + $config->set('news_icon', $icon); + add_log('admin', 'LOG_NEWSPAGE_SETTINGS'); + trigger_error($user->lang('NEWS_SAVED') . adm_back_link($this->u_action)); + } + + $template->assign_vars(array( + 'U_ACTION' => $this->u_action, + 'SETTING_NEWS_ICON' => isset($config['news_icon']) ? $config['news_icon'] : 'fa-bullhorn', + 'SETTING_NEWS_FORUMS' => make_forum_select(explode(',', $config['news_forums']), false, false, true), + 'SETTING_NEWS_NUMBER' => (int) $config['news_number'], + 'SETTING_NEWS_PAGES' => (int) $config['news_pages'], + 'SETTING_NEWS_CHAR_LIMIT' => (int) $config['news_char_limit'], + 'SETTING_NEWS_CAT_SHOW' => (bool) $config['news_cat_show'], + 'SETTING_NEWS_ARCHIVE_SHOW' => (bool) $config['news_archive_show'], + 'SETTING_NEWS_SHADOW_SHOW' => (bool) $config['news_shadow'], + 'SETTING_NEWS_USER_INFO' => (bool) $config['news_user_info'], + 'SETTING_NEWS_POST_BUTTONS' => (bool) $config['news_post_buttons'], + 'SETTING_NEWS_ATTACH_SHOW' => (bool) $config['news_attach_show'], + )); + } +} diff --git a/adm/style/acp_newspage_settings.html b/adm/style/acp_newspage_settings.html new file mode 100644 index 0000000..f7c19f9 --- /dev/null +++ b/adm/style/acp_newspage_settings.html @@ -0,0 +1,61 @@ + + +

{L_ACP_NEWSPAGE}

+

{L_ACP_NEWSPAGE_SETTINGS_EXPLAIN}

+ +
+
+ {L_ACP_NEWSPAGE_SETTINGS} +
+

{L_NEWS_ICON_EXPLAIN}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

{L_NEWS_CHAR_LIMIT_EXPLAIN}
+
+
+
+
+
checked="checked" />
+
+
+
+
checked="checked" />
+
+
+
+
checked="checked" />
+
+
+

{L_NEWS_USER_INFO_EXPLAIN}
+
checked="checked" />
+
+
+

{L_NEWS_POST_BUTTONS_EXPLAIN}
+
checked="checked" />
+
+
+

{L_NEWS_ATTACH_SHOW_EXPLAIN}
+
checked="checked" />
+
+
+
+ + + {S_FORM_TOKEN} +
+
+ + diff --git a/composer.json b/composer.json index e3a0ab3..b1d2f85 100644 --- a/composer.json +++ b/composer.json @@ -2,9 +2,8 @@ "name": "nickvergessen/newspage", "type": "phpbb-extension", "description": "Adds a extra-page to the board where a switchable number of news are displayed. The text can be shorten to a certain number of chars. Also the Icons can be switched of (post icons, user icons)", - "homepage": "https://github.com/nickv-phpbb/phpbb-ext-newspage", - "version": "1.3", - "time": "2015-06-14", + "homepage": "https://github.com/phpbbmodders/phpbb-ext-newspage", + "version": "1.4.0-dev", "license": "GPL-2.0", "authors": [ { @@ -15,17 +14,13 @@ } ], "require": { - "nickvergessen/phpbb-tool-trimmessage": "1.3.*", - "php": ">=5.3.3" - }, - "require-dev": { - "phing/phing": "2.4.*", - "phpbb/epv": "dev-master" + "php": ">=7.2", + "ext-dom": "*" }, "extra": { - "display-name": "phpBB 3.1 - NV Newspage Extension", + "display-name": "NV Newspage Extension", "soft-require": { - "phpbb/phpbb": ">=3.1.3,<3.2.*@dev" + "phpbb/phpbb": ">=3.3.19,<4.0.0@dev" } } } diff --git a/composer.lock b/composer.lock index bde5580..cd44bb4 100644 --- a/composer.lock +++ b/composer.lock @@ -1,503 +1,21 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" - ], - "hash": "78a55812528c922938e844a03a288f46", - "packages": [ - { - "name": "nickvergessen/phpbb-tool-trimmessage", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/nickvergessen/phpbb-tool-trimmessage.git", - "reference": "2a3d8273dc1238dd06454688bcb6496f62f66c3b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nickvergessen/phpbb-tool-trimmessage/zipball/2a3d8273dc1238dd06454688bcb6496f62f66c3b", - "reference": "2a3d8273dc1238dd06454688bcb6496f62f66c3b", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "4.1.*" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0" - ], - "authors": [ - { - "name": "Joas Schilling", - "email": "nickvergessen@gmx.de", - "homepage": "https://github.com/nickvergessen", - "role": "Developer" - } - ], - "description": "This tool contains a class, that is able to trim a message from the phpbb message_parser to a maximum length without breaking the bbcodes/smilies and links.", - "homepage": "https://github.com/nickvergessen/phpbb-tool-trimmessage", - "time": "2014-07-06 19:42:34" - } - ], - "packages-dev": [ - { - "name": "gitonomy/gitlib", - "version": "v0.1.7", - "source": { - "type": "git", - "url": "https://github.com/gitonomy/gitlib.git", - "reference": "7a46107cfb8552b312101e0d5906e95d54d7ddc6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/gitonomy/gitlib/zipball/7a46107cfb8552b312101e0d5906e95d54d7ddc6", - "reference": "7a46107cfb8552b312101e0d5906e95d54d7ddc6", - "shasum": "" - }, - "require": { - "symfony/process": "~2.4" - }, - "require-dev": { - "psr/log": "~1" - }, - "suggest": { - "psr/log": "Add some log" - }, - "type": "library", - "autoload": { - "psr-0": { - "Gitonomy\\Git": [ - "src/", - "tests/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Alexandre Salomé", - "email": "alexandre.salome@gmail.com", - "homepage": "http://alexandre-salome.fr" - }, - { - "name": "Julien DIDIER", - "email": "genzo.wm@gmail.com", - "homepage": "http://www.jdidier.net" - } - ], - "description": "Library for accessing git", - "homepage": "http://gitonomy.com", - "time": "2014-07-13 19:02:31" - }, - { - "name": "nikic/php-parser", - "version": "v0.9.5", - "source": { - "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "ef70767475434bdb3615b43c327e2cae17ef12eb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/ef70767475434bdb3615b43c327e2cae17ef12eb", - "reference": "ef70767475434bdb3615b43c327e2cae17ef12eb", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.9-dev" - } - }, - "autoload": { - "psr-0": { - "PHPParser": "lib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov" - } - ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" - ], - "time": "2014-07-23 18:24:17" - }, - { - "name": "phing/phing", - "version": "2.4.14", - "source": { - "type": "git", - "url": "https://github.com/phingofficial/phing.git", - "reference": "41075d93ca254f1c90c79ec7ce81be2b2629e138" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phingofficial/phing/zipball/41075d93ca254f1c90c79ec7ce81be2b2629e138", - "reference": "41075d93ca254f1c90c79ec7ce81be2b2629e138", - "shasum": "" - }, - "require": { - "php": ">=5.2.0" - }, - "bin": [ - "bin/phing" - ], - "type": "library", - "autoload": { - "classmap": [ - "classes/phing/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "classes" - ], - "license": [ - "LGPL3" - ], - "authors": [ - { - "name": "Michiel Rook", - "email": "mrook@php.net", - "role": "Lead" - }, - { - "name": "Phing Community", - "homepage": "http://www.phing.info/trac/wiki/Development/Contributors" - } - ], - "description": "PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.", - "homepage": "http://www.phing.info/", - "keywords": [ - "build", - "task", - "tool" - ], - "time": "2012-11-29 21:23:47" - }, - { - "name": "phpbb/epv", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/phpbb/epv.git", - "reference": "c092d70a3ee6da3604464f3f8b4e5dbb34fd4f9d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpbb/epv/zipball/c092d70a3ee6da3604464f3f8b4e5dbb34fd4f9d", - "reference": "c092d70a3ee6da3604464f3f8b4e5dbb34fd4f9d", - "shasum": "" - }, - "require": { - "gitonomy/gitlib": "0.1.*@dev", - "nikic/php-parser": "0.9.*@dev", - "php": ">=5.3.3", - "sensiolabs/ansi-to-html": "~1.1", - "symfony/console": ">=2.3.0", - "symfony/finder": ">=2.3.0", - "symfony/yaml": ">=2.3.0|>=2.4.0|>=2.5.0" - }, - "require-dev": { - "phpunit/phpunit": "4.4.*", - "phpunit/phpunit-mock-objects": "2.3.*" - }, - "bin": [ - "src/EPV.php" - ], - "type": "library", - "autoload": { - "psr-4": { - "Phpbb\\Epv\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "GPL-2.0" - ], - "authors": [ - { - "name": "Paul Sohier", - "email": "paul@phpbb.com" - } - ], - "description": "A extension validator for phpBB extensions. Extensions are required to pass the validator when submitted to the extension database.", - "time": "2015-02-05 18:25:28" - }, - { - "name": "sensiolabs/ansi-to-html", - "version": "v1.1.0", - "source": { - "type": "git", - "url": "https://github.com/sensiolabs/ansi-to-html.git", - "reference": "92d2ef7ffba5418be060d8ba8adaf7223d741f93" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sensiolabs/ansi-to-html/zipball/92d2ef7ffba5418be060d8ba8adaf7223d741f93", - "reference": "92d2ef7ffba5418be060d8ba8adaf7223d741f93", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "suggest": { - "twig/twig": "Provides nice templating features" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } - }, - "autoload": { - "psr-0": { - "SensioLabs\\AnsiConverter": "." - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "A library to convert a text with ANSI codes to HTML", - "time": "2014-08-01 14:02:39" - }, - { - "name": "symfony/console", - "version": "v2.6.4", - "target-dir": "Symfony/Component/Console", - "source": { - "type": "git", - "url": "https://github.com/symfony/Console.git", - "reference": "e44154bfe3e41e8267d7a3794cd9da9a51cfac34" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/e44154bfe3e41e8267d7a3794cd9da9a51cfac34", - "reference": "e44154bfe3e41e8267d7a3794cd9da9a51cfac34", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/event-dispatcher": "~2.1", - "symfony/process": "~2.1" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/process": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Console\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony Console Component", - "homepage": "http://symfony.com", - "time": "2015-01-25 04:39:26" - }, - { - "name": "symfony/finder", - "version": "v2.6.4", - "target-dir": "Symfony/Component/Finder", - "source": { - "type": "git", - "url": "https://github.com/symfony/Finder.git", - "reference": "16513333bca64186c01609961a2bb1b95b5e1355" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Finder/zipball/16513333bca64186c01609961a2bb1b95b5e1355", - "reference": "16513333bca64186c01609961a2bb1b95b5e1355", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Finder\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony Finder Component", - "homepage": "http://symfony.com", - "time": "2015-01-03 08:01:59" - }, - { - "name": "symfony/process", - "version": "v2.6.4", - "target-dir": "Symfony/Component/Process", - "source": { - "type": "git", - "url": "https://github.com/symfony/Process.git", - "reference": "ecfc23e89d9967999fa5f60a1e9af7384396e9ae" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/ecfc23e89d9967999fa5f60a1e9af7384396e9ae", - "reference": "ecfc23e89d9967999fa5f60a1e9af7384396e9ae", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Process\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony Process Component", - "homepage": "http://symfony.com", - "time": "2015-01-25 04:39:26" - }, - { - "name": "symfony/yaml", - "version": "v2.6.4", - "target-dir": "Symfony/Component/Yaml", - "source": { - "type": "git", - "url": "https://github.com/symfony/Yaml.git", - "reference": "60ed7751671113cf1ee7d7778e691642c2e9acd8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/60ed7751671113cf1ee7d7778e691642c2e9acd8", - "reference": "60ed7751671113cf1ee7d7778e691642c2e9acd8", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.6-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "time": "2015-01-25 04:39:26" - } + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" ], + "content-hash": "b5922e7863eaf0387519fad39e6e969c", + "packages": [], + "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "phpbb/epv": 20 - }, + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, "platform": { - "php": ">=5.3.3" + "php": ">=7.2", + "ext-dom": "*" }, - "platform-dev": [] + "platform-dev": [], + "plugin-api-version": "2.2.0" } diff --git a/config/newspage_routing.yml b/config/newspage_routing.yml index 02db9bd..598962d 100644 --- a/config/newspage_routing.yml +++ b/config/newspage_routing.yml @@ -1,7 +1,3 @@ -nickvergessen_newspage_settings: - path: /settings - defaults: { _controller: nickvergessen.newspage.controller.settings:manage } - nickvergessen_newspage_page_controller: path: /page/{page} defaults: { _controller: nickvergessen.newspage.controller:newspage, forum_id: 0, year: 0, month: 0 } diff --git a/config/services.yml b/config/services.yml index 7f6a324..dfb3032 100644 --- a/config/services.yml +++ b/config/services.yml @@ -2,60 +2,61 @@ services: nickvergessen.newspage.controller: class: nickvergessen\newspage\controller\main arguments: - - @config - - @dispatcher - - @template - - @user - - @controller.helper - - @nickvergessen.newspage - - %core.root_path% - - %core.php_ext% + - "@config" + - "@dispatcher" + - "@template" + - "@user" + - "@controller.helper" + - "@nickvergessen.newspage" + - "%core.root_path%" + - "%core.php_ext%" nickvergessen.newspage.controller.settings: class: nickvergessen\newspage\controller\settings arguments: - - @auth - - @config - - @request - - @controller.helper - - @user + - "@auth" + - "@config" + - "@request" + - "@controller.helper" + - "@user" nickvergessen.newspage.helper: class: nickvergessen\newspage\helper arguments: - - @controller.helper - - @config + - "@controller.helper" + - "@config" nickvergessen.newspage: class: nickvergessen\newspage\newspage arguments: - - @auth - - @cache - - @config - - @dbal.conn - - @request - - @template - - @user - - @content.visibility - - @controller.helper - - @nickvergessen.newspage.helper - - @pagination - - %core.root_path% - - %core.php_ext% + - "@auth" + - "@cache" + - "@config" + - "@dbal.conn" + - "@request" + - "@template" + - "@user" + - "@content.visibility" + - "@controller.helper" + - "@nickvergessen.newspage.helper" + - "@pagination" + - "%core.root_path%" + - "%core.php_ext%" nickvergessen.newspage.menu_link_listener: class: nickvergessen\newspage\event\menu_link_listener arguments: - - @nickvergessen.newspage.helper - - @template + - "@nickvergessen.newspage.helper" + - "@template" + - "@config" tags: - { name: event.listener } nickvergessen.newspage.viewonline_listener: class: nickvergessen\newspage\event\viewonline_listener arguments: - - @nickvergessen.newspage.helper - - @user - - %core.php_ext% + - "@nickvergessen.newspage.helper" + - "@user" + - "%core.php_ext%" tags: - { name: event.listener } diff --git a/controller/main.php b/controller/main.php index c7008ca..800594e 100644 --- a/controller/main.php +++ b/controller/main.php @@ -72,11 +72,7 @@ public function __construct(\phpbb\config\config $config, \phpbb\event\dispatche $this->root_path = $root_path; $this->php_ext = $php_ext; - if (!class_exists('bbcode')) - { - include($this->root_path . 'includes/bbcode.' . $this->php_ext); - } - if (!function_exists('get_user_rank')) + if (!function_exists('phpbb_get_user_rank')) { include($this->root_path . 'includes/functions_display.' . $this->php_ext); } @@ -118,6 +114,11 @@ public function newspage($forum_id, $year, $month, $page) ); extract($this->dispatcher->trigger_event('nickvergessen.newspage.newspage', compact($vars))); + if ($page < 1 || $month < 0 || $month > 12 || ($year && !$month) || (!$year && $month)) + { + throw new \phpbb\exception\http_exception(404, 'NO_NEWS'); + } + $this->newspage->set_category($forum_id) ->set_archive($year, $month) ->set_start(($page - 1) * $this->config['news_number']); @@ -177,8 +178,7 @@ public function base($display_pagination = true) } $this->newspage->base(); - // $this->assign_images($this->config['news_user_info'], $this->config['news_post_buttons']); - $this->assign_images(true, true); + $this->assign_images($this->config['news_user_info'], $this->config['news_post_buttons']); $this->template->assign_vars(array( 'S_ON_NEWSPAGE' => true, diff --git a/controller/settings.php b/controller/settings.php index bb91cc4..ded73e5 100644 --- a/controller/settings.php +++ b/controller/settings.php @@ -76,6 +76,20 @@ public function manage() throw new http_exception(400, 'FORM_INVALID'); } + $this->save_settings(); + + $this->user->add_lang_ext('nickvergessen/newspage', 'newspage'); + return $this->helper->message('NEWS_SAVED'); + } + + /** Save settings after the calling administrator form validates its token. */ + public function save_settings() + { + if (!$this->auth->acl_get('a_board')) + { + throw new http_exception(403, 'NO_AUTH_OPERATION'); + } + if ($this->request->variable('news_char_limit', 0) !== 0) { $this->config->set('news_char_limit', max(100, $this->request->variable('news_char_limit', 0))); @@ -95,9 +109,6 @@ public function manage() $this->config->set('news_attach_show', $this->request->variable('news_attach_show', false)); $this->config->set('news_cat_show', $this->request->variable('news_cat_show', false)); $this->config->set('news_archive_show', $this->request->variable('news_archive_show', false)); - - $this->user->add_lang_ext('nickvergessen/newspage', 'newspage'); - return $this->helper->message('NEWS_SAVED'); } /** diff --git a/event/menu_link_listener.php b/event/menu_link_listener.php index 7b6b2a3..0e1fb95 100644 --- a/event/menu_link_listener.php +++ b/event/menu_link_listener.php @@ -28,6 +28,9 @@ class menu_link_listener implements EventSubscriberInterface /* @var \phpbb\template\template */ protected $template; + /** @var \phpbb\config\config */ + protected $config; + /** * Register to the events * @@ -46,11 +49,13 @@ static public function getSubscribedEvents() * * @param \nickvergessen\newspage\helper $helper * @param \phpbb\template\template $template + * @param \phpbb\config\config $config */ - public function __construct(\nickvergessen\newspage\helper $helper, \phpbb\template\template $template) + public function __construct(\nickvergessen\newspage\helper $helper, \phpbb\template\template $template, \phpbb\config\config $config) { $this->helper = $helper; $this->template = $template; + $this->config = $config; } /** @@ -74,6 +79,7 @@ public function add_page_header_link() { $this->template->assign_vars(array( 'U_NEWSPAGE' => $this->helper->generate_route()->get_url(), + 'NEWSPAGE_ICON' => isset($this->config['news_icon']) ? $this->config['news_icon'] : 'fa-bullhorn', )); } } diff --git a/ext.php b/ext.php new file mode 100644 index 0000000..124ac80 --- /dev/null +++ b/ext.php @@ -0,0 +1,20 @@ +=') && + phpbb_version_compare(PHPBB_VERSION, '4.0.0-dev', '<') && + PHP_VERSION_ID >= 70200 && extension_loaded('dom')) + { + return true; + } + + $language = $this->container->get('language'); + $language->add_lang('install', 'nickvergessen/newspage'); + return array($language->lang('NEWSPAGE_NOT_ENABLEABLE')); + } +} diff --git a/language/en/info_acp_newspage.php b/language/en/info_acp_newspage.php new file mode 100644 index 0000000..b34e976 --- /dev/null +++ b/language/en/info_acp_newspage.php @@ -0,0 +1,21 @@ + 'Newspage', + 'ACP_NEWSPAGE_SETTINGS' => 'Settings', + 'ACP_NEWSPAGE_SETTINGS_EXPLAIN' => 'Configure the news forums and how news is displayed.', + 'LOG_NEWSPAGE_SETTINGS' => 'Changed Newspage settings', + 'NEWS_ICON' => 'News navigation icon', + 'NEWS_ICON_EXPLAIN' => 'Font Awesome 4.7 icon class, for example fa-bullhorn, fa-newspaper-o, or fa-rss.', + 'NEWS_ICON_INVALID' => 'Enter a Font Awesome icon class in the format fa-bullhorn.', +)); diff --git a/language/en/install.php b/language/en/install.php new file mode 100644 index 0000000..61a5b4d --- /dev/null +++ b/language/en/install.php @@ -0,0 +1,10 @@ + 'NV Newspage requires phpBB 3.3.19 or later in the 3.3 series, PHP 7.2 or later, and the PHP DOM extension.', +)); diff --git a/message_trimmer.php b/message_trimmer.php new file mode 100644 index 0000000..0bbde3a --- /dev/null +++ b/message_trimmer.php @@ -0,0 +1,67 @@ +loadHTML('
' . $html . '
', LIBXML_NONET); + libxml_clear_errors(); + libxml_use_internal_errors($previous); + if (!$loaded) + { + return $html; + } + + $wrapper = $document->getElementsByTagName('div')->item(0); + if (utf8_strlen($wrapper->textContent) <= $limit) + { + return $html; + } + + $remaining = $limit; + $this->trim_children($wrapper, $remaining); + $wrapper->appendChild($document->createTextNode('...')); + $result = ''; + foreach ($wrapper->childNodes as $node) + { + $result .= $document->saveHTML($node); + } + return $result; + } + + protected function trim_children(\DOMNode $parent, &$remaining) + { + foreach (iterator_to_array($parent->childNodes) as $node) + { + if ($remaining === 0) + { + $parent->removeChild($node); + } + else if ($node instanceof \DOMText) + { + $length = utf8_strlen($node->nodeValue); + $node->nodeValue = utf8_substr($node->nodeValue, 0, $remaining); + $remaining -= min($remaining, $length); + } + else if ($node->hasChildNodes()) + { + $this->trim_children($node, $remaining); + } + } + } +} diff --git a/migrations/v11x/acp_settings.php b/migrations/v11x/acp_settings.php new file mode 100644 index 0000000..9412a36 --- /dev/null +++ b/migrations/v11x/acp_settings.php @@ -0,0 +1,23 @@ + '\\nickvergessen\\newspage\\acp\\main_module', + 'modes' => array('settings'), + ))), + ); + } +} diff --git a/newspage.php b/newspage.php index d206a21..c93c10b 100644 --- a/newspage.php +++ b/newspage.php @@ -12,8 +12,6 @@ namespace nickvergessen\newspage; -use Nickvergessen\TrimMessage\TrimMessage; - /** * Class newspage * @@ -54,13 +52,13 @@ class newspage /** @var string */ protected $page_title; /** @var int */ - protected $start; + protected $start = 0; /** @var int */ - protected $news; + protected $news = 0; /** @var array */ - protected $archive; + protected $archive = array('y' => 0, 'm' => 0); /** @var int */ - protected $category; + protected $category = 0; const ARCHIVE_SHOW = 1; const ARCHIVE_PER_YEAR = 2; @@ -107,10 +105,6 @@ public function __construct(\phpbb\auth\auth $auth, \phpbb\cache\service $cache, $this->root_path = $root_path; $this->php_ext = $php_ext; - if (!class_exists('bbcode')) - { - include($this->root_path . 'includes/bbcode.' . $this->php_ext); - } if (!function_exists('phpbb_get_user_rank')) { include($this->root_path . 'includes/functions_display.' . $this->php_ext); @@ -247,11 +241,6 @@ public function get_news_ids() public function base() { - if ($this->auth->acl_get('a_board')) - { - $this->display_newspage_settings(); - } - $this->get_news_ids(); if (empty($this->topic_ids)) @@ -309,15 +298,14 @@ public function base() { $this->page_title = censor_text($row['post_subject']); } - else if (((int) $this->config['news_char_limit']) !== 0 && class_exists('\Nickvergessen\TrimMessage\TrimMessage')) - { - $trim = new TrimMessage($row['post_text'], $row['bbcode_uid'], $this->config['news_char_limit']); - $row['post_text'] = $trim->message(); - unset($trim); - } - $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES; + $parse_flags = ($row['enable_bbcode'] ? OPTION_FLAG_BBCODE : 0) | ($row['enable_smilies'] ? OPTION_FLAG_SMILIES : 0) | ($row['enable_magic_url'] ? OPTION_FLAG_LINKS : 0); $message = generate_text_for_display($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags, true); + if (!$this->news && (int) $this->config['news_char_limit'] > 0) + { + $trimmer = new message_trimmer(); + $message = $trimmer->trim($message, (int) $this->config['news_char_limit']); + } if (!$this->auth->acl_get('f_download', $forum_id)) { @@ -349,8 +337,6 @@ public function base() $this->db->sql_freeresult($result2); } - $l_edit_time_total = ($row['post_edit_count'] == 1) ? $this->user->lang['EDITED_TIME_TOTAL'] : $this->user->lang['EDITED_TIMES_TOTAL']; - if (!$row['post_edit_user'] || $row['post_edit_user'] == $poster_id) { $display_username = get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']); @@ -360,14 +346,7 @@ public function base() $display_username = get_username_string('full', $row['post_edit_user'], $post_edit_list[$row['post_edit_user']]['username'], $post_edit_list[$row['post_edit_user']]['user_colour']); } - if ($row['post_edit_reason']) - { - $l_edited_by = sprintf($l_edit_time_total, $display_username, $this->user->format_date($row['post_edit_time'], false, true), $row['post_edit_count']); - } - else - { - $l_edited_by = sprintf($l_edit_time_total, $display_username, $this->user->format_date($row['post_edit_time'], false, true), $row['post_edit_count']); - } + $l_edited_by = $this->user->lang('EDITED_TIMES_TOTAL', (int) $row['post_edit_count'], $display_username, $this->user->format_date($row['post_edit_time'], false, true)); } else { @@ -434,7 +413,7 @@ public function base() 'POST_ICON_IMG_WIDTH' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['width'] : '', 'POST_ICON_IMG_HEIGHT' => (!empty($row['icon_id'])) ? $icons[$row['icon_id']]['height'] : '', 'U_MINI_POST' => append_sid("{$this->root_path}viewtopic.{$this->php_ext}", 'p=' . $row['post_id']) . (($row['topic_type'] == POST_GLOBAL) ? '&f=' . $forum_id : '') . '#p' . $row['post_id'], - 'POST_SUBJECT' => censor_text($row['post_subject']), + 'POST_SUBJECT' => htmlspecialchars(censor_text($row['post_subject']), ENT_QUOTES, 'UTF-8', false), 'MINI_POST_IMG' => ($post_unread) ? $this->user->img('icon_post_target_unread', 'NEW_POST') : $this->user->img('icon_post_target', 'POST'), 'POST_AUTHOR_FULL' => get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), 'POST_DATE' => $this->user->format_date($row['post_time']), @@ -447,11 +426,11 @@ public function base() 'MESSAGE' => $row['post_text'], 'S_HAS_POLL' => (!empty($row['poll_start'])) ? true : false, - 'POLL_QUESTION' => $row['poll_title'], + 'POLL_QUESTION' => htmlspecialchars(censor_text($row['poll_title']), ENT_QUOTES, 'UTF-8', false), 'S_HAS_ATTACHMENTS' => (!empty($attachments[$row['post_id']]) && $this->config['news_attach_show']) ? true : false, 'S_DISPLAY_NOTICE' => $display_notice && $row['post_attachment'], 'EDITED_MESSAGE' => $l_edited_by, - 'EDIT_REASON' => $row['post_edit_reason'], + 'EDIT_REASON' => htmlspecialchars($row['post_edit_reason'], ENT_QUOTES, 'UTF-8', false), 'SIGNATURE' => ($row['enable_sig']) ? $row['user_sig'] : '', 'NEWS_COMMENTS' => $this->content_visibility->get_count('topic_posts', $row, $forum_id) - 1, @@ -462,9 +441,10 @@ public function base() 'RANK_IMG_SRC' => $row['rank_image_src'], 'POSTER_POSTS' => $row['user_posts'], 'POSTER_JOINED' => $this->user->format_date($row['user_regdate']), + 'U_SEARCH' => $this->auth->acl_get('u_search') ? append_sid("{$this->root_path}search.{$this->php_ext}", 'author_id=' . $poster_id . '&sr=posts') : '', - 'U_PM' => ($poster_id != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && ($row['user_allow_pm'] || $this->auth->acl_gets('a_', 'm_') || $this->auth->acl_getf_global('m_'))) ? append_sid("{$this->root_path}ucp.{$this->php_ext}", 'i=pm&mode=compose&action=quotepost&p=' . $row['post_id']) : '', - 'U_EMAIL' => $row['user_email'], + 'U_PM' => $u_pm, + 'U_EMAIL' => $u_email, 'U_JABBER' => $row['user_jabber'], )); @@ -526,8 +506,8 @@ public function base() // Specify some images $this->template->assign_vars(array( - 'NEWS_USER_INFO' => true, // $this->config['news_user_info'], - 'NEWS_POST_BUTTONS' => true, // $this->config['news_post_buttons'], + 'NEWS_USER_INFO' => (bool) $this->config['news_user_info'], + 'NEWS_POST_BUTTONS' => (bool) $this->config['news_post_buttons'], 'S_NEWS_ARCHIVE_PER_YEAR' => $this->config['news_archive_show'] == self::ARCHIVE_PER_YEAR, 'NEWS_ONLY' => $this->news, @@ -608,7 +588,9 @@ public function get_newstopic_sql() else if ($this->is_archive()) { $archive_start = $this->user->get_timestamp_from_format('Y-n-d H:i:s', $this->archive['y'] . '-' . $this->archive['m'] . '-01 0:00:00'); - $archive_end = $this->user->get_timestamp_from_format('Y-n-d H:i:s', $this->archive['y'] . '-' . ($this->archive['m'] + 1) . '-01 0:00:00') - 1; + $next_month = $this->archive['m'] == 12 ? 1 : $this->archive['m'] + 1; + $next_year = $this->archive['y'] + ($this->archive['m'] == 12 ? 1 : 0); + $archive_end = $this->user->get_timestamp_from_format('Y-n-d H:i:s', $next_year . '-' . $next_month . '-01 0:00:00') - 1; $archive_name = $this->user->lang('NEWS_ARCHIVE_OF', $this->user->format_date($archive_start, 'F Y')); $this->page_title = $archive_name; @@ -852,28 +834,4 @@ public function generate_pagination() )); } - protected function display_newspage_settings() - { - if (!function_exists('make_forum_select')) - { - include($this->root_path . 'includes/functions_admin.' . $this->php_ext); - } - - add_form_key('newspage'); - $this->template->assign_vars(array( - 'U_SETTING_ACTION' => $this->helper->route('nickvergessen_newspage_settings'), - 'SETTING_NEWS_CHAR_LIMIT' => (int) $this->config['news_char_limit'], - 'SETTING_NEWS_NUMBER' => (int) $this->config['news_number'], - 'SETTING_NEWS_PAGES' => (int) $this->config['news_pages'], - 'SETTING_NEWS_SHADOW_SHOW' => (bool) $this->config['news_shadow'], - 'SETTING_NEWS_ATTACH_SHOW' => (bool) $this->config['news_attach_show'], - 'SETTING_NEWS_CAT_SHOW' => (bool) $this->config['news_cat_show'], - 'SETTING_NEWS_ARCHIVE_SHOW' => (bool) $this->config['news_archive_show'], - 'SETTING_NEWS_FORUMS' => make_forum_select(explode(',', $this->config['news_forums'])), - - 'SETTING_BUTTON_RESPONSIVE_FIXED' => false, - 'SETTING_NEWS_USER_INFO' => (bool) $this->config['news_user_info'], - 'SETTING_NEWS_POST_BUTTONS' => (bool) $this->config['news_post_buttons'], - )); - } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 289449d..bd7e754 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -8,31 +8,14 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" verbose="true" - bootstrap="../../../../tests/bootstrap.php" + bootstrap="tests/bootstrap.php" > ./tests ./tests/functional - - ./tests/functional/ - - - - ./tests/ - - - ./ - - ./language/ - ./migrations/ - ./tests/ - - - diff --git a/styles/prosilver/template/event/overall_header_head_append.html b/styles/prosilver/template/event/overall_header_head_append.html index 4b8b36b..312ed68 100644 --- a/styles/prosilver/template/event/overall_header_head_append.html +++ b/styles/prosilver/template/event/overall_header_head_append.html @@ -1,4 +1,4 @@ - + diff --git a/styles/prosilver/template/event/overall_header_navigation_prepend.html b/styles/prosilver/template/event/overall_header_navigation_prepend.html index e7fc41b..761d0f8 100644 --- a/styles/prosilver/template/event/overall_header_navigation_prepend.html +++ b/styles/prosilver/template/event/overall_header_navigation_prepend.html @@ -1 +1 @@ -
  • {L_NEWSPAGE}
  • +
  • {L_NEWSPAGE}
  • diff --git a/styles/prosilver/template/newspage_body.html b/styles/prosilver/template/newspage_body.html index ee6fa6a..9d94982 100644 --- a/styles/prosilver/template/newspage_body.html +++ b/styles/prosilver/template/newspage_body.html @@ -2,16 +2,15 @@ -

    {NEWS_TITLE}{L_NEWS}

    +

    {NEWS_TITLE}{L_NEWS}

    - +
    -