diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc1757c..d5ca91c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,3 +47,68 @@ jobs: - name: Unit tests run: composer test + + integration: + name: Integration, PHP ${{ matrix.php }}, ${{ matrix.db }} ${{ matrix.engine || 'default engine' }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + # oldest supported server; InnoDB there has no FULLTEXT + - php: '8.2' + db: 'mysql:5.5' + engine: '' + # servers without InnoDB + - php: '8.4' + db: 'mysql:5.7' + engine: 'MyISAM' + - php: '8.5' + db: 'mariadb:10.11' + engine: '' + services: + db: + image: ${{ matrix.db }} + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: icms_test + MYSQL_USER: icms + MYSQL_PASSWORD: icms + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot" + --health-interval=5s + --health-timeout=5s + --health-retries=20 + env: + ICMS_CORE_PATH: ${{ github.workspace }}/core/htdocs + IMFORUM_TEST_DB_HOST: 127.0.0.1 + IMFORUM_TEST_DB_NAME: icms_test + IMFORUM_TEST_DB_USER: icms + IMFORUM_TEST_DB_PASS: icms + IMFORUM_TEST_DB_ENGINE: ${{ matrix.engine }} + steps: + - name: Checkout module + uses: actions/checkout@v4 + + - name: Checkout ImpressCMS core + uses: actions/checkout@v4 + with: + repository: fiammybe/impresscms + ref: main + path: core + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: pdo_mysql + coverage: none + tools: composer:v2 + + - name: Install dev dependencies + run: composer install --no-interaction --no-progress --prefer-dist + + - name: Integration tests + run: composer test:integration diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b7a635..dfd50de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,3 +3,4 @@ ## 1.0.0 Alpha (unreleased) - Phase 0: module skeleton for ImpressCMS 2.0 in IPF mode, install and update routines, English and Dutch language files, CI on PHP 8.2 to 8.5. +- Phase 1: data model. 13 IPF objects with handlers (category, forum, moderator, topic, post, attachment, report, suspension, readmark, online, digest, archive, permtemplate), group permissions on categories and forums, counters and cascading deletes through handler events, indexes in `imforum_db_upgrade_1()`, labels in English and Dutch, integration tests against MySQL 5.5, MySQL 5.7 (MyISAM) and MariaDB 10.11. diff --git a/README.md b/README.md index 3f9a944..8032aa9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Community forum module for ImpressCMS 2.0, built on the ImpressCMS Persistable Framework (IPF). imforum is the successor of iForum: same features, new code, and an importer that takes over the data of a running iForum installation. -Status: phase 0 (foundation). The module installs and updates, but has no forum functions yet. +Status: phase 1 (data model). The module creates its tables and the data layer works, but there are no admin screens or forum pages yet. ## Requirements @@ -21,8 +21,11 @@ composer install composer lint # php -l on every file composer test # PHPUnit ICMS_CORE_PATH=/path/to/impresscms/htdocs composer analyse # PHPStan, needs a core checkout +ICMS_CORE_PATH=/path/to/impresscms/htdocs composer test:integration # needs a database, see below ``` +The integration tests install the module into an empty database with the core's own updater and then exercise the handlers. They need a core checkout and an empty MySQL or MariaDB database, set with `IMFORUM_TEST_DB_HOST`, `IMFORUM_TEST_DB_NAME`, `IMFORUM_TEST_DB_USER` and `IMFORUM_TEST_DB_PASS` (defaults: `127.0.0.1`, `icms_test`, `icms`, `icms`). Set `IMFORUM_TEST_DB_ENGINE=MyISAM` to test as on a server without InnoDB. Every run drops the tables with prefix `imft_` first, so never point it at a real site. + PHPStan reads the core classes from `ICMS_CORE_PATH`. Without that variable it stops with an error about a missing scan directory. For a local test site, copy `src/` to `modules/imforum`. A symlink or Windows junction does not work: PHP resolves `__DIR__` to the real folder, and the module takes its name from that folder. @@ -32,6 +35,8 @@ Conventions: - Classes are named `mod_imforum_` and `mod_imforum_Handler` and live in `src/class/.php` and `src/class/Handler.php`; the core autoloads them once `object_items` is set. - Form labels come from `_CO_IMFORUM__` in `language/*/common.php`. - English and Dutch ship with the module; other languages go through Crowdin. +- Object item names are single lower-case words that are not SQL reserved words: IPF uses them as table aliases (that is why read marks are called `readmark`). +- Counters such as `forum_posts` and `topic_replies` are recounted by `synchronise()` on the handlers after every change, never incremented by hand. - Never rename or remove an object var in one release. The core drops columns that are no longer declared before the upgrade functions run, so add the new var and copy the data first, and remove the old var one release later. ## License diff --git a/composer.json b/composer.json index a087a84..f8d9f71 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "scripts": { "lint": "find src tests -name '*.php' -print0 | xargs -0 -n1 php -l", "analyse": "phpstan analyse", - "test": "phpunit" + "test": "phpunit", + "test:integration": "phpunit -c phpunit.integration.xml.dist" }, "config": { "sort-packages": true diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a95e693..5f02f43 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -14,3 +14,23 @@ parameters: - %env.ICMS_CORE_PATH%/include/functions.php - %env.ICMS_CORE_PATH%/include/cp_functions.php - %env.ICMS_CORE_PATH%/libraries/icms.php + # Core docblocks that are narrower than the code they describe. The core + # itself passes these types everywhere; casting in the module would only + # hide that. + ignoreErrors: + - + # icms_db_criteria_Item::__construct() documents string, renders any scalar + message: '#^Parameter \#2 \$value of class icms_db_criteria_Item constructor expects string, int#' + identifier: argument.type + - + # icms_ipf_Object::initCommonVar() documents its parameters as "str" + message: '#^Parameter \#\d \$\w+ of method icms_ipf_Object::initCommonVar\(\) expects str, #' + identifier: argument.type + - + # icms_ipf_Tree::getFirstChild() documents string; the tree is keyed by integer ids + message: '#^Parameter \#1 \$key of method icms_ipf_Tree::getFirstChild\(\) expects string, int given\.$#' + identifier: argument.type + - + # icms_db_legacy_IDatabase::queryF() documents a resource, but returns false when the query fails + identifier: ternary.alwaysTrue + path: src/include/onupdate.php diff --git a/phpunit.integration.xml.dist b/phpunit.integration.xml.dist new file mode 100644 index 0000000..8948697 --- /dev/null +++ b/phpunit.integration.xml.dist @@ -0,0 +1,17 @@ + + + + + + tests/Integration + + + diff --git a/src/class/Archive.php b/src/class/Archive.php new file mode 100644 index 0000000..f69510f --- /dev/null +++ b/src/class/Archive.php @@ -0,0 +1,26 @@ +quickInitVar('archive_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('topic_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('post_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('post_text', XOBJ_DTYPE_TXTAREA); + $this->quickInitVar('archived_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + } +} diff --git a/src/class/ArchiveHandler.php b/src/class/ArchiveHandler.php new file mode 100644 index 0000000..6d433b9 --- /dev/null +++ b/src/class/ArchiveHandler.php @@ -0,0 +1,27 @@ +getVar('archived_time', 'e') === 0) { + $archive->setVar('archived_time', time()); + } + return true; + } +} diff --git a/src/class/Attachment.php b/src/class/Attachment.php new file mode 100644 index 0000000..e4bb66e --- /dev/null +++ b/src/class/Attachment.php @@ -0,0 +1,43 @@ +quickInitVar('attach_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('post_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('name_saved', XOBJ_DTYPE_TXTBOX, true); + $this->quickInitVar('name_display', XOBJ_DTYPE_TXTBOX, true); + $this->quickInitVar('mimetype', XOBJ_DTYPE_TXTBOX); + $this->quickInitVar('filesize', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('downloads', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('online', XOBJ_DTYPE_INT, false, '', '', 1); + $this->quickInitVar('attach_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + + $this->setControl('online', ['name' => 'yesno']); + } + + /** + * Absolute path of the stored file + * + * basename() keeps a tampered name_saved inside the upload folder. + */ + public function getFilePath(): string { + return IMFORUM_UPLOAD_PATH . basename((string) $this->getVar('name_saved', 'e')); + } +} diff --git a/src/class/AttachmentHandler.php b/src/class/AttachmentHandler.php new file mode 100644 index 0000000..e1b27b0 --- /dev/null +++ b/src/class/AttachmentHandler.php @@ -0,0 +1,37 @@ +getVar('attach_time', 'e') === 0) { + $attachment->setVar('attach_time', time()); + } + return true; + } + + /** + * Remove the file together with its record + * + * A file that is already gone is not an error. + */ + protected function afterDelete(mod_imforum_Attachment $attachment): bool { + $path = $attachment->getFilePath(); + return !is_file($path) || unlink($path); + } +} diff --git a/src/class/Category.php b/src/class/Category.php new file mode 100644 index 0000000..a1fdf35 --- /dev/null +++ b/src/class/Category.php @@ -0,0 +1,31 @@ +quickInitVar('cat_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('cat_title', XOBJ_DTYPE_TXTBOX, true); + $this->quickInitVar('cat_description', XOBJ_DTYPE_TXTAREA); + $this->quickInitVar('cat_image', XOBJ_DTYPE_IMAGE); + $this->quickInitVar('cat_url', XOBJ_DTYPE_TXTBOX); + $this->initCommonVar('weight'); + $this->initiateSEO(); + + $this->setControl('cat_description', ['name' => 'textarea', 'form_editor' => 'default']); + $this->setControl('cat_image', ['name' => 'image']); + } +} diff --git a/src/class/CategoryHandler.php b/src/class/CategoryHandler.php new file mode 100644 index 0000000..db9a687 --- /dev/null +++ b/src/class/CategoryHandler.php @@ -0,0 +1,49 @@ +addPermission('category_access', _CO_IMFORUM_PERM_CATEGORY_ACCESS, _CO_IMFORUM_PERM_CATEGORY_ACCESS_DSC); + } + + /** + * Options for a category select box, ordered as on the index page + * + * @return array + */ + public function getCategorySelectList(): array { + $criteria = new icms_db_criteria_Compo(); + $criteria->setSort('weight'); + $criteria->setOrder('ASC'); + return $this->getList($criteria); + } + + /** + * Refuse to delete a category that still holds forums + * + * Deleting forums takes their topics and posts with them, so that must be + * an explicit choice per forum rather than a side effect. + */ + protected function beforeDelete(mod_imforum_Category $category): bool { + $forums = icms_getModuleHandler('forum', IMFORUM_DIRNAME) + ->getCount(new icms_db_criteria_Item('cat_id', $category->id())); + if ($forums > 0) { + $category->setErrors(_CO_IMFORUM_CATEGORY_NOT_EMPTY); + return false; + } + return true; + } +} diff --git a/src/class/Digest.php b/src/class/Digest.php new file mode 100644 index 0000000..aa061dc --- /dev/null +++ b/src/class/Digest.php @@ -0,0 +1,24 @@ +quickInitVar('digest_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('digest_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + $this->quickInitVar('digest_content', XOBJ_DTYPE_TXTAREA); + } +} diff --git a/src/class/DigestHandler.php b/src/class/DigestHandler.php new file mode 100644 index 0000000..e8fdcb5 --- /dev/null +++ b/src/class/DigestHandler.php @@ -0,0 +1,36 @@ +db->queryF("SELECT MAX(digest_time) FROM {$this->table}"); + $row = $result ? $this->db->fetchRow($result) : false; + return $row ? (int) $row[0] : 0; + } + + protected function beforeInsert(mod_imforum_Digest $digest): bool { + if ((int) $digest->getVar('digest_time', 'e') === 0) { + $digest->setVar('digest_time', time()); + } + return true; + } +} diff --git a/src/class/Forum.php b/src/class/Forum.php new file mode 100644 index 0000000..c68e729 --- /dev/null +++ b/src/class/Forum.php @@ -0,0 +1,59 @@ +quickInitVar('forum_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('cat_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('parent_forum', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('forum_name', XOBJ_DTYPE_TXTBOX, true); + $this->quickInitVar('forum_desc', XOBJ_DTYPE_TXTAREA); + $this->quickInitVar('forum_active', XOBJ_DTYPE_INT, false, '', '', 1); + $this->initCommonVar('weight'); + $this->quickInitVar('allow_html', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('allow_sig', XOBJ_DTYPE_INT, false, '', '', 1); + $this->quickInitVar('allow_subject_prefix', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('hot_threshold', XOBJ_DTYPE_INT, false, '', '', 10); + $this->quickInitVar('attach_maxkb', XOBJ_DTYPE_INT, false, '', '', 1000); + $this->quickInitVar('attach_ext', XOBJ_DTYPE_TXTBOX, false, '', '', 'zip|gif|jpg|jpeg|png|pdf'); + + // Kept up to date by the handlers, never edited by hand + $this->quickInitVar('forum_topics', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('forum_posts', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('forum_last_post_id', XOBJ_DTYPE_INT, false, '', '', 0); + $this->hideFieldFromForm(['forum_topics', 'forum_posts', 'forum_last_post_id']); + + $this->initiateSEO(); + + $this->setControl('cat_id', ['itemHandler' => 'category', 'method' => 'getCategorySelectList', 'module' => IMFORUM_DIRNAME]); + $this->setControl('parent_forum', ['itemHandler' => 'forum', 'method' => 'getParentSelectList', 'module' => IMFORUM_DIRNAME]); + $this->setControl('forum_desc', ['name' => 'textarea', 'form_editor' => 'default']); + foreach (['forum_active', 'allow_html', 'allow_sig', 'allow_subject_prefix'] as $key) { + $this->setControl($key, ['name' => 'yesno']); + } + } + + /** + * File extensions that may be attached in this forum, lower case + * + * @return list + */ + public function getAllowedExtensions(): array { + $extensions = array_map('trim', explode('|', strtolower((string) $this->getVar('attach_ext', 'e')))); + return array_values(array_filter($extensions, static fn (string $ext): bool => $ext !== '')); + } +} diff --git a/src/class/ForumHandler.php b/src/class/ForumHandler.php new file mode 100644 index 0000000..0ba4f6b --- /dev/null +++ b/src/class/ForumHandler.php @@ -0,0 +1,151 @@ +addPermission($permission, constant($caption), constant($caption . '_DSC')); + } + } + + /** + * All forums, parents before their children, as a tree + */ + public function getTree(?icms_db_criteria_Element $criteria = null): icms_ipf_Tree { + $criteria ??= new icms_db_criteria_Compo(); + $criteria->setSort('weight'); + $criteria->setOrder('ASC'); + $forums = $this->getObjects($criteria, true); + return new icms_ipf_Tree($forums, 'forum_id', 'parent_forum'); + } + + /** + * Options for a forum select box, indented to show the tree + * + * @return array + */ + public function getForumSelectList(): array { + $tree = $this->getTree(); + $options = []; + $this->addTreeOptions($tree, 0, 0, $options); + return $options; + } + + /** + * Options for the parent forum field: the forum list plus "no parent" + * + * @return array + */ + public function getParentSelectList(): array { + return [0 => _CO_IMFORUM_FORUM_NO_PARENT] + $this->getForumSelectList(); + } + + /** + * @param array $options + */ + private function addTreeOptions(icms_ipf_Tree $tree, int $parent, int $depth, array &$options): void { + foreach ($tree->getFirstChild($parent) as $forum) { + $options[(int) $forum->id()] = str_repeat('-', $depth * 2) . ($depth ? ' ' : '') . $forum->getVar('forum_name', 'e'); + $this->addTreeOptions($tree, (int) $forum->id(), $depth + 1, $options); + } + } + + /** + * Recount topics, posts and the last post of a forum + * + * Only approved topics and posts count. Recounting instead of adding and + * subtracting keeps the numbers right after moves, merges and failed + * requests, and stays cheap thanks to the indexes from imforum_db_upgrade_1(). + */ + public function synchronise(int $forumId): bool { + $topics = $this->db->prefix(IMFORUM_DIRNAME . '_topic'); + $posts = $this->db->prefix(IMFORUM_DIRNAME . '_post'); + + [$topicCount] = $this->fetchRow("SELECT COUNT(*) FROM $topics WHERE forum_id = $forumId AND approved = 1"); + [$postCount, $lastPost] = $this->fetchRow("SELECT COUNT(*), MAX(post_id) FROM $posts WHERE forum_id = $forumId AND approved = 1"); + + // queryF: the counters follow a write that has already been allowed + return (bool) $this->db->queryF(sprintf( + 'UPDATE %s SET forum_topics = %d, forum_posts = %d, forum_last_post_id = %d WHERE forum_id = %d', + $this->table, (int) $topicCount, (int) $postCount, (int) $lastPost, $forumId + )); + } + + /** + * @return list + */ + private function fetchRow(string $sql): array { + $result = $this->db->queryF($sql); + $row = $result ? $this->db->fetchRow($result) : false; + return $row ? array_values($row) : [0, 0]; + } + + /** + * A forum may not become its own parent or the child of one of its children + */ + protected function beforeSave(mod_imforum_Forum $forum): bool { + $ownId = (int) $forum->id(); + $seen = []; + for ($id = (int) $forum->getVar('parent_forum', 'e'); $id !== 0; $id = $this->getParentId($id)) { + if ($id === $ownId || isset($seen[$id])) { + $forum->setErrors(_CO_IMFORUM_FORUM_PARENT_LOOP); + return false; + } + $seen[$id] = true; + } + return true; + } + + private function getParentId(int $forumId): int { + [$parent] = $this->fetchRow("SELECT parent_forum FROM {$this->table} WHERE forum_id = $forumId"); + return (int) $parent; + } + + /** + * Remove everything that belongs to a deleted forum + * + * Subforums move up one level instead of being deleted with it. + */ + protected function afterDelete(mod_imforum_Forum $forum): bool { + $forumId = (int) $forum->id(); + $byForum = new icms_db_criteria_Item('forum_id', $forumId); + + $topicHandler = icms_getModuleHandler('topic', IMFORUM_DIRNAME); + foreach ($topicHandler->getObjects($byForum) as $topic) { + $topicHandler->delete($topic, true); + } + icms_getModuleHandler('moderator', IMFORUM_DIRNAME)->deleteAll($byForum); + icms_getModuleHandler('suspension', IMFORUM_DIRNAME)->deleteAll($byForum); + icms_getModuleHandler('online', IMFORUM_DIRNAME)->deleteAll($byForum); + icms_getModuleHandler('readmark', IMFORUM_DIRNAME)->deleteByItem(mod_imforum_ReadmarkHandler::TYPE_FORUM, $forumId); + + return (bool) $this->db->queryF(sprintf( + 'UPDATE %s SET parent_forum = %d WHERE parent_forum = %d', + $this->table, (int) $forum->getVar('parent_forum', 'e'), $forumId + )); + } +} diff --git a/src/class/Moderator.php b/src/class/Moderator.php new file mode 100644 index 0000000..729aa0d --- /dev/null +++ b/src/class/Moderator.php @@ -0,0 +1,29 @@ +quickInitVar('moderator_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('forum_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('uid', XOBJ_DTYPE_INT, true); + + $this->setControl('forum_id', ['itemHandler' => 'forum', 'method' => 'getForumSelectList', 'module' => IMFORUM_DIRNAME]); + $this->setControl('uid', ['name' => 'user']); + } +} diff --git a/src/class/ModeratorHandler.php b/src/class/ModeratorHandler.php new file mode 100644 index 0000000..0b2701f --- /dev/null +++ b/src/class/ModeratorHandler.php @@ -0,0 +1,64 @@ + user ids of the moderators of a forum + */ + public function getModeratorIds(int $forumId): array { + $ids = []; + foreach ($this->getObjects(new icms_db_criteria_Item('forum_id', $forumId)) as $moderator) { + $ids[] = (int) $moderator->getVar('uid', 'e'); + } + return $ids; + } + + public function isModerator(int $uid, int $forumId): bool { + if ($uid < 1) { + return false; + } + $criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('forum_id', $forumId)); + $criteria->add(new icms_db_criteria_Item('uid', $uid)); + return $this->getCount($criteria) > 0; + } + + /** + * Make exactly these users the moderators of a forum + * + * @param list $uids + */ + public function setModerators(int $forumId, array $uids): bool { + $wanted = array_values(array_unique(array_filter(array_map('intval', $uids), static fn (int $uid): bool => $uid > 0))); + $current = $this->getModeratorIds($forumId); + + $ok = true; + foreach (array_diff($current, $wanted) as $uid) { + $criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('forum_id', $forumId)); + $criteria->add(new icms_db_criteria_Item('uid', $uid)); + $ok = $this->deleteAll($criteria) !== false && $ok; + } + foreach (array_diff($wanted, $current) as $uid) { + $moderator = $this->create(); + $moderator->setVar('forum_id', $forumId); + $moderator->setVar('uid', $uid); + $ok = $this->insert($moderator, true) && $ok; + } + return $ok; + } +} diff --git a/src/class/Online.php b/src/class/Online.php new file mode 100644 index 0000000..28e0bd4 --- /dev/null +++ b/src/class/Online.php @@ -0,0 +1,30 @@ +quickInitVar('online_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('forum_id', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('topic_id', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('uid', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('uname', XOBJ_DTYPE_TXTBOX); + $this->quickInitVar('ip', XOBJ_DTYPE_TXTBOX); + $this->quickInitVar('updated', XOBJ_DTYPE_LTIME, false, '', '', 0); + } +} diff --git a/src/class/OnlineHandler.php b/src/class/OnlineHandler.php new file mode 100644 index 0000000..427b880 --- /dev/null +++ b/src/class/OnlineHandler.php @@ -0,0 +1,27 @@ +db->queryF(sprintf('DELETE FROM %s WHERE updated < %d', $this->table, $time)); + } +} diff --git a/src/class/Permtemplate.php b/src/class/Permtemplate.php new file mode 100644 index 0000000..37c25a9 --- /dev/null +++ b/src/class/Permtemplate.php @@ -0,0 +1,28 @@ +quickInitVar('template_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('perm_name', XOBJ_DTYPE_TXTBOX, true); + $this->quickInitVar('groupid', XOBJ_DTYPE_INT, true); + + $this->setControl('groupid', ['name' => 'group']); + } +} diff --git a/src/class/PermtemplateHandler.php b/src/class/PermtemplateHandler.php new file mode 100644 index 0000000..fb1cea0 --- /dev/null +++ b/src/class/PermtemplateHandler.php @@ -0,0 +1,54 @@ + group ids + * + * @return array> + */ + public function getTemplate(): array { + $template = array_fill_keys(mod_imforum_ForumHandler::PERMISSIONS, []); + foreach ($this->getObjects() as $row) { + $name = (string) $row->getVar('perm_name', 'e'); + if (isset($template[$name])) { + $template[$name][] = (int) $row->getVar('groupid', 'e'); + } + } + return $template; + } + + /** + * Replace the whole template; unknown permission names are ignored + * + * @param array> $template + */ + public function saveTemplate(array $template): bool { + $ok = (bool) $this->db->queryF("DELETE FROM {$this->table}"); + foreach (array_intersect_key($template, array_flip(mod_imforum_ForumHandler::PERMISSIONS)) as $name => $groups) { + foreach (array_unique(array_map('intval', $groups)) as $groupId) { + $row = $this->create(); + $row->setVar('perm_name', $name); + $row->setVar('groupid', $groupId); + $ok = $this->insert($row, true) && $ok; + } + } + return $ok; + } +} diff --git a/src/class/Post.php b/src/class/Post.php new file mode 100644 index 0000000..1ac9b3c --- /dev/null +++ b/src/class/Post.php @@ -0,0 +1,70 @@ +quickInitVar('post_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('topic_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('forum_id', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('pid', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('uid', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('poster_name', XOBJ_DTYPE_TXTBOX); + // IPv4 or IPv6 as text; iForum stored IPv4 as an integer + $this->quickInitVar('poster_ip', XOBJ_DTYPE_TXTBOX); + $this->quickInitVar('post_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + $this->quickInitVar('subject', XOBJ_DTYPE_TXTBOX, true); + $this->quickInitVar('post_text', XOBJ_DTYPE_TXTAREA, true); + // JSON list of edits; not a PHP array var, so nothing is ever unserialised + $this->quickInitVar('post_edit', XOBJ_DTYPE_OTHER); + $this->quickInitVar('icon', XOBJ_DTYPE_TXTBOX); + $this->quickInitVar('attachsig', XOBJ_DTYPE_INT, false, '', '', 1); + $this->quickInitVar('approved', XOBJ_DTYPE_INT, false, '', '', 1); + $this->quickInitVar('post_karma', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('require_reply', XOBJ_DTYPE_INT, false, '', '', 0); + $this->initCommonVar('dohtml', false, 0); + $this->initCommonVar('dosmiley'); + $this->initCommonVar('doxcode'); + $this->initCommonVar('doimage'); + $this->initCommonVar('dobr'); + + $this->hideFieldFromForm(['topic_id', 'forum_id', 'pid', 'uid', 'poster_ip', 'post_time', 'post_edit', 'approved']); + + $this->setControl('post_text', ['name' => 'textarea', 'form_editor' => 'default']); + foreach (['attachsig', 'require_reply'] as $key) { + $this->setControl($key, ['name' => 'yesno']); + } + } + + /** + * Earlier edits, oldest first + * + * @return list + */ + public function getEditHistory(): array { + $edits = json_decode((string) $this->getVar('post_edit', 'n'), true); + return is_array($edits) ? array_values($edits) : []; + } + + public function addEdit(int $uid, string $name, ?int $time = null): void { + $edits = $this->getEditHistory(); + $edits[] = ['uid' => $uid, 'name' => $name, 'time' => $time ?? time()]; + $this->setVar('post_edit', json_encode($edits)); + } +} diff --git a/src/class/PostHandler.php b/src/class/PostHandler.php new file mode 100644 index 0000000..176a9b2 --- /dev/null +++ b/src/class/PostHandler.php @@ -0,0 +1,102 @@ +db->queryF("SELECT post_id FROM {$this->table} WHERE topic_id = $topicId"); + while ($result && ($row = $this->db->fetchRow($result))) { + $postIds[] = (int) $row[0]; + } + if (!$postIds) { + return true; + } + foreach (array_chunk($postIds, 500) as $chunk) { + $this->deletePostChildren($chunk); + } + return (bool) $this->db->queryF("DELETE FROM {$this->table} WHERE topic_id = $topicId"); + } + + /** + * Attachments (with their files) and reports of these posts + * + * @param list $postIds + */ + private function deletePostChildren(array $postIds): void { + $byPost = new icms_db_criteria_Item('post_id', '(' . implode(',', array_map('intval', $postIds)) . ')', 'IN'); + icms_getModuleHandler('attachment', IMFORUM_DIRNAME)->deleteAll($byPost); + icms_getModuleHandler('report', IMFORUM_DIRNAME)->deleteAll($byPost); + } + + protected function beforeInsert(mod_imforum_Post $post): bool { + if ((int) $post->getVar('post_time', 'e') === 0) { + $post->setVar('post_time', time()); + } + if ((int) $post->getVar('forum_id', 'e') === 0) { + $topic = icms_getModuleHandler('topic', IMFORUM_DIRNAME)->get((int) $post->getVar('topic_id', 'e')); + if ($topic->isNew()) { + $post->setErrors(_CO_IMFORUM_POST_NO_TOPIC); + return false; + } + $post->setVar('forum_id', (int) $topic->getVar('forum_id', 'e')); + } + return true; + } + + protected function afterSave(mod_imforum_Post $post): bool { + return $this->synchroniseParents($post); + } + + /** + * Clean up after one post + * + * Replies to the post move up to its parent, so the tree view stays whole. + * A topic without posts is deleted. + */ + protected function afterDelete(mod_imforum_Post $post): bool { + $postId = (int) $post->id(); + $this->deletePostChildren([$postId]); + $this->db->queryF(sprintf( + 'UPDATE %s SET pid = %d WHERE pid = %d', + $this->table, (int) $post->getVar('pid', 'e'), $postId + )); + + $topicId = (int) $post->getVar('topic_id', 'e'); + if ($this->getCount(new icms_db_criteria_Item('topic_id', $topicId)) === 0) { + $topicHandler = icms_getModuleHandler('topic', IMFORUM_DIRNAME); + $topic = $topicHandler->get($topicId); + if (!$topic->isNew()) { + return $topicHandler->delete($topic, true); + } + } + return $this->synchroniseParents($post); + } + + private function synchroniseParents(mod_imforum_Post $post): bool { + $topicOk = icms_getModuleHandler('topic', IMFORUM_DIRNAME)->synchronise((int) $post->getVar('topic_id', 'e')); + $forumOk = icms_getModuleHandler('forum', IMFORUM_DIRNAME)->synchronise((int) $post->getVar('forum_id', 'e')); + return $topicOk && $forumOk; + } +} diff --git a/src/class/Readmark.php b/src/class/Readmark.php new file mode 100644 index 0000000..7fac473 --- /dev/null +++ b/src/class/Readmark.php @@ -0,0 +1,32 @@ +quickInitVar('read_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('read_type', XOBJ_DTYPE_INT, true); + $this->quickInitVar('uid', XOBJ_DTYPE_INT, true); + $this->quickInitVar('item_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('post_id', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('read_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + } +} diff --git a/src/class/ReadmarkHandler.php b/src/class/ReadmarkHandler.php new file mode 100644 index 0000000..169cc90 --- /dev/null +++ b/src/class/ReadmarkHandler.php @@ -0,0 +1,86 @@ +getObjects($this->criteriaFor($type, $uid, $itemId)); + $read = $existing[0] ?? $this->create(); + $read->setVar('read_type', $type); + $read->setVar('uid', $uid); + $read->setVar('item_id', $itemId); + $read->setVar('post_id', $postId); + $read->setVar('read_time', $time ?? time()); + return $this->insert($read, true); + } + + /** + * Last read post per item for one member + * + * @param list $itemIds + * @return array item id => post id; unread items are left out + */ + public function getLastRead(int $type, int $uid, array $itemIds): array { + $itemIds = array_values(array_filter(array_map('intval', $itemIds))); + if ($uid < 1 || !$itemIds) { + return []; + } + $criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('read_type', $type)); + $criteria->add(new icms_db_criteria_Item('uid', $uid)); + $criteria->add(new icms_db_criteria_Item('item_id', '(' . implode(',', $itemIds) . ')', 'IN')); + + $ret = []; + foreach ($this->getObjects($criteria) as $read) { + $ret[(int) $read->getVar('item_id', 'e')] = (int) $read->getVar('post_id', 'e'); + } + return $ret; + } + + /** + * Forget all read marks for a forum or topic that is deleted + */ + public function deleteByItem(int $type, int $itemId): bool { + return (bool) $this->db->queryF(sprintf( + 'DELETE FROM %s WHERE read_type = %d AND item_id = %d', + $this->table, $type, $itemId + )); + } + + /** + * Drop read marks older than a moment; used by the cleanup task (phase 6) + */ + public function purgeOlderThan(int $time): bool { + return (bool) $this->db->queryF(sprintf('DELETE FROM %s WHERE read_time < %d', $this->table, $time)); + } + + private function criteriaFor(int $type, int $uid, int $itemId): icms_db_criteria_Compo { + $criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('read_type', $type)); + $criteria->add(new icms_db_criteria_Item('uid', $uid)); + $criteria->add(new icms_db_criteria_Item('item_id', $itemId)); + return $criteria; + } +} diff --git a/src/class/Report.php b/src/class/Report.php new file mode 100644 index 0000000..6072e58 --- /dev/null +++ b/src/class/Report.php @@ -0,0 +1,35 @@ +quickInitVar('report_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('post_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('reporter_uid', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('reporter_ip', XOBJ_DTYPE_TXTBOX); + $this->quickInitVar('report_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + $this->quickInitVar('report_text', XOBJ_DTYPE_TXTAREA, true); + $this->quickInitVar('report_result', XOBJ_DTYPE_INT, false, '', '', self::RESULT_OPEN); + $this->quickInitVar('report_memo', XOBJ_DTYPE_TXTAREA); + + $this->hideFieldFromForm(['post_id', 'reporter_uid', 'reporter_ip', 'report_time']); + $this->setControl('report_result', ['name' => 'yesno']); + } +} diff --git a/src/class/ReportHandler.php b/src/class/ReportHandler.php new file mode 100644 index 0000000..70541fb --- /dev/null +++ b/src/class/ReportHandler.php @@ -0,0 +1,31 @@ +getCount(new icms_db_criteria_Item('report_result', mod_imforum_Report::RESULT_OPEN)); + } + + protected function beforeInsert(mod_imforum_Report $report): bool { + if ((int) $report->getVar('report_time', 'e') === 0) { + $report->setVar('report_time', time()); + } + return true; + } +} diff --git a/src/class/Suspension.php b/src/class/Suspension.php new file mode 100644 index 0000000..c84f75f --- /dev/null +++ b/src/class/Suspension.php @@ -0,0 +1,32 @@ +quickInitVar('suspension_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('uid', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('ip', XOBJ_DTYPE_TXTBOX); + // 0 = every forum + $this->quickInitVar('forum_id', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('start_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + $this->quickInitVar('end_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + $this->quickInitVar('description', XOBJ_DTYPE_TXTAREA); + + $this->setControl('uid', ['name' => 'user']); + $this->setControl('forum_id', ['itemHandler' => 'forum', 'method' => 'getParentSelectList', 'module' => IMFORUM_DIRNAME]); + } +} diff --git a/src/class/SuspensionHandler.php b/src/class/SuspensionHandler.php new file mode 100644 index 0000000..e8f86d5 --- /dev/null +++ b/src/class/SuspensionHandler.php @@ -0,0 +1,56 @@ + 0) { + $who->add(new icms_db_criteria_Item('uid', $uid), 'OR'); + } + // criteria values are not escaped by the core, so only a valid address goes in + if (filter_var($ip, FILTER_VALIDATE_IP) !== false) { + $who->add(new icms_db_criteria_Item('ip', $ip), 'OR'); + } + if (!$who->criteriaElements) { + return false; + } + + $where = new icms_db_criteria_Compo(new icms_db_criteria_Item('forum_id', '(0, ' . $forumId . ')', 'IN')); + $where->add(new icms_db_criteria_Item('start_time', $now, '<=')); + $where->add(new icms_db_criteria_Item('end_time', $now, '>')); + $where->add($who); + + return $this->getCount($where) > 0; + } + + protected function beforeInsert(mod_imforum_Suspension $suspension): bool { + if ((int) $suspension->getVar('start_time', 'e') === 0) { + $suspension->setVar('start_time', time()); + } + return true; + } +} diff --git a/src/class/Topic.php b/src/class/Topic.php new file mode 100644 index 0000000..e41d234 --- /dev/null +++ b/src/class/Topic.php @@ -0,0 +1,52 @@ +quickInitVar('topic_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('forum_id', XOBJ_DTYPE_INT, true); + $this->quickInitVar('topic_title', XOBJ_DTYPE_TXTBOX, true); + $this->quickInitVar('topic_subject', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('topic_poster', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('poster_name', XOBJ_DTYPE_TXTBOX); + $this->quickInitVar('topic_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + $this->quickInitVar('topic_views', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('topic_status', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('topic_sticky', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('topic_digest', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('digest_time', XOBJ_DTYPE_LTIME, false, '', '', 0); + $this->quickInitVar('approved', XOBJ_DTYPE_INT, false, '', '', 1); + + // Kept up to date by the handlers, never edited by hand + $this->quickInitVar('topic_replies', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('topic_first_post_id', XOBJ_DTYPE_INT, false, '', '', 0); + $this->quickInitVar('topic_last_post_id', XOBJ_DTYPE_INT, false, '', '', 0); + $this->hideFieldFromForm(['topic_views', 'topic_replies', 'topic_first_post_id', 'topic_last_post_id', 'digest_time']); + + $this->initiateSEO(); + + $this->setControl('forum_id', ['itemHandler' => 'forum', 'method' => 'getForumSelectList', 'module' => IMFORUM_DIRNAME]); + $this->setControl('topic_poster', ['name' => 'user']); + foreach (['topic_status', 'topic_sticky', 'topic_digest', 'approved'] as $key) { + $this->setControl($key, ['name' => 'yesno']); + } + } + + public function isLocked(): bool { + return (int) $this->getVar('topic_status', 'e') === 1; + } +} diff --git a/src/class/TopicHandler.php b/src/class/TopicHandler.php new file mode 100644 index 0000000..02c2b88 --- /dev/null +++ b/src/class/TopicHandler.php @@ -0,0 +1,60 @@ +db->prefix(IMFORUM_DIRNAME . '_post'); + $result = $this->db->queryF("SELECT COUNT(*), MIN(post_id), MAX(post_id) FROM $posts WHERE topic_id = $topicId AND approved = 1"); + $row = $result ? $this->db->fetchRow($result) : false; + [$count, $first, $last] = $row ? array_values($row) : [0, 0, 0]; + + // queryF: the counters follow a write that has already been allowed + return (bool) $this->db->queryF(sprintf( + 'UPDATE %s SET topic_replies = %d, topic_first_post_id = %d, topic_last_post_id = %d WHERE topic_id = %d', + $this->table, max((int) $count - 1, 0), (int) $first, (int) $last, $topicId + )); + } + + protected function beforeInsert(mod_imforum_Topic $topic): bool { + if ((int) $topic->getVar('topic_time', 'e') === 0) { + $topic->setVar('topic_time', time()); + } + return true; + } + + protected function afterSave(mod_imforum_Topic $topic): bool { + return icms_getModuleHandler('forum', IMFORUM_DIRNAME)->synchronise((int) $topic->getVar('forum_id', 'e')); + } + + /** + * Remove the posts, read marks and archive copies of a deleted topic + */ + protected function afterDelete(mod_imforum_Topic $topic): bool { + $topicId = (int) $topic->id(); + $ok = icms_getModuleHandler('post', IMFORUM_DIRNAME)->deleteByTopic($topicId); + icms_getModuleHandler('readmark', IMFORUM_DIRNAME)->deleteByItem(mod_imforum_ReadmarkHandler::TYPE_TOPIC, $topicId); + icms_getModuleHandler('archive', IMFORUM_DIRNAME)->deleteAll(new icms_db_criteria_Item('topic_id', $topicId)); + return icms_getModuleHandler('forum', IMFORUM_DIRNAME)->synchronise((int) $topic->getVar('forum_id', 'e')) && $ok; + } +} diff --git a/src/icms_version.php b/src/icms_version.php index a367797..858be9d 100644 --- a/src/icms_version.php +++ b/src/icms_version.php @@ -40,10 +40,13 @@ 'submit_bug' => 'https://github.com/iForumModule/imforum/issues', 'submit_feature' => 'https://github.com/iForumModule/imforum/issues', - // IPF objects, filled in phase 1. An empty array already enables IPF mode - // (autoloading), but the core only runs the table sync and the - // imforum_db_upgrade_() steps once the array is not empty. - 'object_items' => [], + // IPF objects: one table _imforum_ each, classes in class/. + // Never remove or rename an item without a migration; the core would leave + // the old table behind and create an empty new one. + 'object_items' => [ + 'category', 'forum', 'moderator', 'topic', 'post', 'attachment', 'report', + 'suspension', 'readmark', 'online', 'digest', 'archive', 'permtemplate', + ], 'onInstall' => 'include/onupdate.php', 'onUpdate' => 'include/onupdate.php', diff --git a/src/include/common.php b/src/include/common.php index 30dfa73..d8fa2be 100644 --- a/src/include/common.php +++ b/src/include/common.php @@ -24,3 +24,9 @@ /** Raise by one for every release that needs an imforum_db_upgrade_() step */ define('IMFORUM_DB_VERSION', 1); } + +// Form labels and permission captions. The core does not load a module's +// common.php by itself, and the handlers need it as soon as they are built. +if (function_exists('icms_loadLanguageFile')) { + icms_loadLanguageFile(IMFORUM_DIRNAME, 'common'); +} diff --git a/src/include/onupdate.php b/src/include/onupdate.php index e6f0b8e..75703f6 100644 --- a/src/include/onupdate.php +++ b/src/include/onupdate.php @@ -5,10 +5,9 @@ * Order of events in the core (modules/system/admin/modulesadmin/modulesadmin.php): * 1. this file is included; * 2. moduleUpgrade($module, TRUE) creates or alters the tables of all object_items, - * then calls imforum_db_upgrade_() for every new database version. The core - * skips this step while object_items is empty (modulesadmin.php checks - * !empty()), so until phase 1 adds objects the stored dbversion stays 0 and - * imforum_db_upgrade_1() first runs on the update that adds them; + * then calls imforum_db_upgrade_() for every new database version. A site + * that installed phase 0 (empty object_items, dbversion 0) gets its tables and + * imforum_db_upgrade_1() on the first update to phase 1; * 3. icms_module_install_imforum() or icms_module_update_imforum() runs. * * Because the tables are synchronised before the upgrade functions run, a column @@ -29,10 +28,92 @@ /** * Database version 1: indexes that the IPF updater does not create * - * Filled in phase 1, once the objects exist. + * The updater only creates columns and the primary key. Every index here is + * on integer columns, so the 767-byte key limit of MySQL 5.5 never applies. + * The FULLTEXT index needs MyISAM, or InnoDB on MySQL 5.6 or newer; where the + * server cannot build it, the search falls back to LIKE (phase 3) and the + * install carries on. */ function imforum_db_upgrade_1(): bool { - return true; + $ok = true; + foreach (imforum_indexes() as $table => $indexes) { + foreach ($indexes as $name => $columns) { + $ok = imforum_add_index($table, $name, $columns) && $ok; + } + } + imforum_add_index('post', 'ft_post_text', ['subject', 'post_text'], 'FULLTEXT'); + return $ok; +} + +/** + * Regular indexes per table, by index name + * + * @return array>> + */ +function imforum_indexes(): array { + return [ + 'forum' => [ + 'idx_cat' => ['cat_id', 'weight'], + 'idx_parent' => ['parent_forum'], + ], + 'moderator' => [ + 'idx_forum_uid' => ['forum_id', 'uid'], + 'idx_uid' => ['uid'], + ], + 'topic' => [ + 'idx_forum_list' => ['forum_id', 'topic_sticky', 'topic_last_post_id'], + 'idx_poster' => ['topic_poster'], + 'idx_digest' => ['topic_digest', 'digest_time'], + ], + 'post' => [ + 'idx_topic' => ['topic_id', 'post_id'], + 'idx_forum_uid' => ['forum_id', 'uid'], + 'idx_uid_time' => ['uid', 'post_time'], + 'idx_pid' => ['pid'], + ], + 'attachment' => [ + 'idx_post' => ['post_id'], + ], + 'report' => [ + 'idx_post' => ['post_id'], + 'idx_result' => ['report_result'], + ], + 'suspension' => [ + 'idx_uid' => ['uid'], + 'idx_forum' => ['forum_id', 'end_time'], + ], + 'readmark' => [ + 'idx_user_item' => ['uid', 'read_type', 'item_id'], + 'idx_item' => ['read_type', 'item_id'], + 'idx_time' => ['read_time'], + ], + 'online' => [ + 'idx_forum' => ['forum_id', 'topic_id'], + 'idx_updated' => ['updated'], + ], + 'archive' => [ + 'idx_topic' => ['topic_id'], + ], + ]; +} + +/** + * Add an index unless one with that name exists already + * + * @param list $columns + * @param string $type '' for a regular index, 'UNIQUE' or 'FULLTEXT' + */ +function imforum_add_index(string $item, string $name, array $columns, string $type = ''): bool { + $db = icms::$xoopsDB; + $table = $db->prefix(IMFORUM_DIRNAME . '_' . $item); + + $result = $db->queryF("SHOW INDEX FROM `$table` WHERE Key_name = " . $db->quoteString($name)); + $exists = $result ? $db->getRowsNum($result) > 0 : false; + if ($exists) { + return true; + } + $sql = sprintf('ALTER TABLE `%s` ADD %s INDEX `%s` (`%s`)', $table, $type, $name, implode('`, `', $columns)); + return (bool) $db->queryF($sql); } /** diff --git a/src/language/english/common.php b/src/language/english/common.php index d47291e..6c2b2bc 100644 --- a/src/language/english/common.php +++ b/src/language/english/common.php @@ -1,8 +1,170 @@ _ and _CO_IMFORUM___DSC * automatically as caption and description (icms_ipf_Object::initVar). - * Filled in phase 1. + * Labels for weight, SEO and the do* display options come from the core. */ + +// category +define('_CO_IMFORUM_CATEGORY_CAT_ID', 'ID'); +define('_CO_IMFORUM_CATEGORY_CAT_TITLE', 'Title'); +define('_CO_IMFORUM_CATEGORY_CAT_DESCRIPTION', 'Description'); +define('_CO_IMFORUM_CATEGORY_CAT_IMAGE', 'Image'); +define('_CO_IMFORUM_CATEGORY_CAT_URL', 'Link'); +define('_CO_IMFORUM_CATEGORY_CAT_URL_DSC', 'Optional website shown with the category'); + +// forum +define('_CO_IMFORUM_FORUM_FORUM_ID', 'ID'); +define('_CO_IMFORUM_FORUM_CAT_ID', 'Category'); +define('_CO_IMFORUM_FORUM_PARENT_FORUM', 'Parent forum'); +define('_CO_IMFORUM_FORUM_FORUM_NAME', 'Name'); +define('_CO_IMFORUM_FORUM_FORUM_DESC', 'Description'); +define('_CO_IMFORUM_FORUM_FORUM_ACTIVE', 'Active'); +define('_CO_IMFORUM_FORUM_FORUM_ACTIVE_DSC', 'Inactive forums are hidden from everyone except administrators'); +define('_CO_IMFORUM_FORUM_ALLOW_HTML', 'Allow HTML'); +define('_CO_IMFORUM_FORUM_ALLOW_SIG', 'Allow signatures'); +define('_CO_IMFORUM_FORUM_ALLOW_SUBJECT_PREFIX', 'Allow subject prefixes'); +define('_CO_IMFORUM_FORUM_HOT_THRESHOLD', 'Hot topic threshold'); +define('_CO_IMFORUM_FORUM_HOT_THRESHOLD_DSC', 'Number of replies from which a topic is shown as hot'); +define('_CO_IMFORUM_FORUM_ATTACH_MAXKB', 'Maximum attachment size (KB)'); +define('_CO_IMFORUM_FORUM_ATTACH_EXT', 'Allowed attachment extensions'); +define('_CO_IMFORUM_FORUM_ATTACH_EXT_DSC', 'Separate extensions with |, for example zip|jpg|png'); +define('_CO_IMFORUM_FORUM_FORUM_TOPICS', 'Topics'); +define('_CO_IMFORUM_FORUM_FORUM_POSTS', 'Posts'); +define('_CO_IMFORUM_FORUM_FORUM_LAST_POST_ID', 'Last post'); + +// moderator +define('_CO_IMFORUM_MODERATOR_MODERATOR_ID', 'ID'); +define('_CO_IMFORUM_MODERATOR_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_MODERATOR_UID', 'Moderator'); + +// topic +define('_CO_IMFORUM_TOPIC_TOPIC_ID', 'ID'); +define('_CO_IMFORUM_TOPIC_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_TOPIC_TOPIC_TITLE', 'Title'); +define('_CO_IMFORUM_TOPIC_TOPIC_SUBJECT', 'Subject prefix'); +define('_CO_IMFORUM_TOPIC_TOPIC_POSTER', 'Started by'); +define('_CO_IMFORUM_TOPIC_POSTER_NAME', 'Guest name'); +define('_CO_IMFORUM_TOPIC_TOPIC_TIME', 'Started on'); +define('_CO_IMFORUM_TOPIC_TOPIC_VIEWS', 'Views'); +define('_CO_IMFORUM_TOPIC_TOPIC_STATUS', 'Locked'); +define('_CO_IMFORUM_TOPIC_TOPIC_STICKY', 'Sticky'); +define('_CO_IMFORUM_TOPIC_TOPIC_DIGEST', 'Featured'); +define('_CO_IMFORUM_TOPIC_DIGEST_TIME', 'Featured on'); +define('_CO_IMFORUM_TOPIC_APPROVED', 'Approved'); +define('_CO_IMFORUM_TOPIC_TOPIC_REPLIES', 'Replies'); +define('_CO_IMFORUM_TOPIC_TOPIC_FIRST_POST_ID', 'First post'); +define('_CO_IMFORUM_TOPIC_TOPIC_LAST_POST_ID', 'Last post'); + +// post +define('_CO_IMFORUM_POST_POST_ID', 'ID'); +define('_CO_IMFORUM_POST_TOPIC_ID', 'Topic'); +define('_CO_IMFORUM_POST_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_POST_PID', 'Reply to'); +define('_CO_IMFORUM_POST_UID', 'Author'); +define('_CO_IMFORUM_POST_POSTER_NAME', 'Guest name'); +define('_CO_IMFORUM_POST_POSTER_IP', 'IP address'); +define('_CO_IMFORUM_POST_POST_TIME', 'Posted on'); +define('_CO_IMFORUM_POST_SUBJECT', 'Subject'); +define('_CO_IMFORUM_POST_POST_TEXT', 'Message'); +define('_CO_IMFORUM_POST_POST_EDIT', 'Edits'); +define('_CO_IMFORUM_POST_ICON', 'Icon'); +define('_CO_IMFORUM_POST_ATTACHSIG', 'Attach signature'); +define('_CO_IMFORUM_POST_APPROVED', 'Approved'); +define('_CO_IMFORUM_POST_POST_KARMA', 'Required karma'); +define('_CO_IMFORUM_POST_POST_KARMA_DSC', 'Only members with at least this karma can read the post'); +define('_CO_IMFORUM_POST_REQUIRE_REPLY', 'Reply required to read'); +define('_CO_IMFORUM_POST_REQUIRE_REPLY_DSC', 'Members only see the message after they replied to the topic'); + +// attachment +define('_CO_IMFORUM_ATTACHMENT_ATTACH_ID', 'ID'); +define('_CO_IMFORUM_ATTACHMENT_POST_ID', 'Post'); +define('_CO_IMFORUM_ATTACHMENT_NAME_SAVED', 'Stored file name'); +define('_CO_IMFORUM_ATTACHMENT_NAME_DISPLAY', 'File name'); +define('_CO_IMFORUM_ATTACHMENT_MIMETYPE', 'MIME type'); +define('_CO_IMFORUM_ATTACHMENT_FILESIZE', 'Size (bytes)'); +define('_CO_IMFORUM_ATTACHMENT_DOWNLOADS', 'Downloads'); +define('_CO_IMFORUM_ATTACHMENT_ONLINE', 'Visible'); +define('_CO_IMFORUM_ATTACHMENT_ATTACH_TIME', 'Uploaded on'); + +// report +define('_CO_IMFORUM_REPORT_REPORT_ID', 'ID'); +define('_CO_IMFORUM_REPORT_POST_ID', 'Post'); +define('_CO_IMFORUM_REPORT_REPORTER_UID', 'Reported by'); +define('_CO_IMFORUM_REPORT_REPORTER_IP', 'IP address'); +define('_CO_IMFORUM_REPORT_REPORT_TIME', 'Reported on'); +define('_CO_IMFORUM_REPORT_REPORT_TEXT', 'Reason'); +define('_CO_IMFORUM_REPORT_REPORT_RESULT', 'Handled'); +define('_CO_IMFORUM_REPORT_REPORT_MEMO', 'Moderator note'); + +// suspension +define('_CO_IMFORUM_SUSPENSION_SUSPENSION_ID', 'ID'); +define('_CO_IMFORUM_SUSPENSION_UID', 'Member'); +define('_CO_IMFORUM_SUSPENSION_IP', 'IP address'); +define('_CO_IMFORUM_SUSPENSION_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_SUSPENSION_FORUM_ID_DSC', 'No forum means every forum'); +define('_CO_IMFORUM_SUSPENSION_START_TIME', 'From'); +define('_CO_IMFORUM_SUSPENSION_END_TIME', 'Until'); +define('_CO_IMFORUM_SUSPENSION_DESCRIPTION', 'Reason'); + +// readmark +define('_CO_IMFORUM_READMARK_READ_ID', 'ID'); +define('_CO_IMFORUM_READMARK_READ_TYPE', 'Type'); +define('_CO_IMFORUM_READMARK_UID', 'Member'); +define('_CO_IMFORUM_READMARK_ITEM_ID', 'Forum or topic'); +define('_CO_IMFORUM_READMARK_POST_ID', 'Last read post'); +define('_CO_IMFORUM_READMARK_READ_TIME', 'Read on'); + +// online +define('_CO_IMFORUM_ONLINE_ONLINE_ID', 'ID'); +define('_CO_IMFORUM_ONLINE_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_ONLINE_TOPIC_ID', 'Topic'); +define('_CO_IMFORUM_ONLINE_UID', 'Member'); +define('_CO_IMFORUM_ONLINE_UNAME', 'Name'); +define('_CO_IMFORUM_ONLINE_IP', 'IP address'); +define('_CO_IMFORUM_ONLINE_UPDATED', 'Last seen'); + +// digest +define('_CO_IMFORUM_DIGEST_DIGEST_ID', 'ID'); +define('_CO_IMFORUM_DIGEST_DIGEST_TIME', 'Sent on'); +define('_CO_IMFORUM_DIGEST_DIGEST_CONTENT', 'Content'); + +// archive +define('_CO_IMFORUM_ARCHIVE_ARCHIVE_ID', 'ID'); +define('_CO_IMFORUM_ARCHIVE_TOPIC_ID', 'Topic'); +define('_CO_IMFORUM_ARCHIVE_POST_ID', 'Post'); +define('_CO_IMFORUM_ARCHIVE_POST_TEXT', 'Message'); +define('_CO_IMFORUM_ARCHIVE_ARCHIVED_TIME', 'Archived on'); + +// permtemplate +define('_CO_IMFORUM_PERMTEMPLATE_TEMPLATE_ID', 'ID'); +define('_CO_IMFORUM_PERMTEMPLATE_PERM_NAME', 'Permission'); +define('_CO_IMFORUM_PERMTEMPLATE_GROUPID', 'Group'); + +// permissions +define('_CO_IMFORUM_PERM_CATEGORY_ACCESS', 'Can see the category'); +define('_CO_IMFORUM_PERM_CATEGORY_ACCESS_DSC', 'Groups that see this category and its forums on the index'); +define('_CO_IMFORUM_PERM_FORUM_ACCESS', 'Can see the forum'); +define('_CO_IMFORUM_PERM_FORUM_ACCESS_DSC', 'Groups that see this forum in the list'); +define('_CO_IMFORUM_PERM_FORUM_VIEW', 'Can read'); +define('_CO_IMFORUM_PERM_FORUM_VIEW_DSC', 'Groups that can open topics in this forum'); +define('_CO_IMFORUM_PERM_FORUM_POST', 'Can start topics'); +define('_CO_IMFORUM_PERM_FORUM_POST_DSC', 'Groups that can start a new topic'); +define('_CO_IMFORUM_PERM_FORUM_REPLY', 'Can reply'); +define('_CO_IMFORUM_PERM_FORUM_REPLY_DSC', 'Groups that can reply to topics'); +define('_CO_IMFORUM_PERM_FORUM_EDIT', 'Can edit own posts'); +define('_CO_IMFORUM_PERM_FORUM_EDIT_DSC', 'Groups that can edit their own posts'); +define('_CO_IMFORUM_PERM_FORUM_DELETE', 'Can delete own posts'); +define('_CO_IMFORUM_PERM_FORUM_DELETE_DSC', 'Groups that can delete their own posts'); +define('_CO_IMFORUM_PERM_FORUM_ATTACH', 'Can attach files'); +define('_CO_IMFORUM_PERM_FORUM_ATTACH_DSC', 'Groups that can add attachments'); +define('_CO_IMFORUM_PERM_FORUM_NOAPPROVE', 'Posts without approval'); +define('_CO_IMFORUM_PERM_FORUM_NOAPPROVE_DSC', 'Groups whose posts appear without moderator approval'); + +// messages +define('_CO_IMFORUM_CATEGORY_NOT_EMPTY', 'This category still holds forums. Move or delete them first.'); +define('_CO_IMFORUM_FORUM_NO_PARENT', 'None (top level)'); +define('_CO_IMFORUM_FORUM_PARENT_LOOP', 'A forum cannot be placed below itself or below one of its subforums.'); +define('_CO_IMFORUM_POST_NO_TOPIC', 'The topic of this post does not exist.'); diff --git a/src/language/nederlands/common.php b/src/language/nederlands/common.php index 65dc67b..b6cf921 100644 --- a/src/language/nederlands/common.php +++ b/src/language/nederlands/common.php @@ -1,8 +1,170 @@ _ en _CO_IMFORUM___DSC - * automatisch als label en omschrijving (icms_ipf_Object::initVar). - * Wordt gevuld in fase 1. + * automatisch als label en uitleg (icms_ipf_Object::initVar). + * Labels voor gewicht, SEO en de do*-weergaveopties komen uit de core. */ + +// category +define('_CO_IMFORUM_CATEGORY_CAT_ID', 'ID'); +define('_CO_IMFORUM_CATEGORY_CAT_TITLE', 'Titel'); +define('_CO_IMFORUM_CATEGORY_CAT_DESCRIPTION', 'Beschrijving'); +define('_CO_IMFORUM_CATEGORY_CAT_IMAGE', 'Afbeelding'); +define('_CO_IMFORUM_CATEGORY_CAT_URL', 'Link'); +define('_CO_IMFORUM_CATEGORY_CAT_URL_DSC', 'Optionele website die bij de categorie getoond wordt'); + +// forum +define('_CO_IMFORUM_FORUM_FORUM_ID', 'ID'); +define('_CO_IMFORUM_FORUM_CAT_ID', 'Categorie'); +define('_CO_IMFORUM_FORUM_PARENT_FORUM', 'Bovenliggend forum'); +define('_CO_IMFORUM_FORUM_FORUM_NAME', 'Naam'); +define('_CO_IMFORUM_FORUM_FORUM_DESC', 'Beschrijving'); +define('_CO_IMFORUM_FORUM_FORUM_ACTIVE', 'Actief'); +define('_CO_IMFORUM_FORUM_FORUM_ACTIVE_DSC', 'Inactieve forums zijn voor iedereen behalve beheerders verborgen'); +define('_CO_IMFORUM_FORUM_ALLOW_HTML', 'HTML toestaan'); +define('_CO_IMFORUM_FORUM_ALLOW_SIG', 'Handtekeningen toestaan'); +define('_CO_IMFORUM_FORUM_ALLOW_SUBJECT_PREFIX', 'Onderwerp-prefixen toestaan'); +define('_CO_IMFORUM_FORUM_HOT_THRESHOLD', 'Drempel populair onderwerp'); +define('_CO_IMFORUM_FORUM_HOT_THRESHOLD_DSC', 'Aantal reacties vanaf wanneer een onderwerp als populair getoond wordt'); +define('_CO_IMFORUM_FORUM_ATTACH_MAXKB', 'Maximale grootte bijlage (KB)'); +define('_CO_IMFORUM_FORUM_ATTACH_EXT', 'Toegestane extensies voor bijlagen'); +define('_CO_IMFORUM_FORUM_ATTACH_EXT_DSC', 'Scheid extensies met |, bijvoorbeeld zip|jpg|png'); +define('_CO_IMFORUM_FORUM_FORUM_TOPICS', 'Onderwerpen'); +define('_CO_IMFORUM_FORUM_FORUM_POSTS', 'Berichten'); +define('_CO_IMFORUM_FORUM_FORUM_LAST_POST_ID', 'Laatste bericht'); + +// moderator +define('_CO_IMFORUM_MODERATOR_MODERATOR_ID', 'ID'); +define('_CO_IMFORUM_MODERATOR_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_MODERATOR_UID', 'Moderator'); + +// topic +define('_CO_IMFORUM_TOPIC_TOPIC_ID', 'ID'); +define('_CO_IMFORUM_TOPIC_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_TOPIC_TOPIC_TITLE', 'Titel'); +define('_CO_IMFORUM_TOPIC_TOPIC_SUBJECT', 'Onderwerp-prefix'); +define('_CO_IMFORUM_TOPIC_TOPIC_POSTER', 'Gestart door'); +define('_CO_IMFORUM_TOPIC_POSTER_NAME', 'Naam gast'); +define('_CO_IMFORUM_TOPIC_TOPIC_TIME', 'Gestart op'); +define('_CO_IMFORUM_TOPIC_TOPIC_VIEWS', 'Weergaven'); +define('_CO_IMFORUM_TOPIC_TOPIC_STATUS', 'Gesloten'); +define('_CO_IMFORUM_TOPIC_TOPIC_STICKY', 'Vastgezet'); +define('_CO_IMFORUM_TOPIC_TOPIC_DIGEST', 'Uitgelicht'); +define('_CO_IMFORUM_TOPIC_DIGEST_TIME', 'Uitgelicht op'); +define('_CO_IMFORUM_TOPIC_APPROVED', 'Goedgekeurd'); +define('_CO_IMFORUM_TOPIC_TOPIC_REPLIES', 'Reacties'); +define('_CO_IMFORUM_TOPIC_TOPIC_FIRST_POST_ID', 'Eerste bericht'); +define('_CO_IMFORUM_TOPIC_TOPIC_LAST_POST_ID', 'Laatste bericht'); + +// post +define('_CO_IMFORUM_POST_POST_ID', 'ID'); +define('_CO_IMFORUM_POST_TOPIC_ID', 'Onderwerp'); +define('_CO_IMFORUM_POST_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_POST_PID', 'Reactie op'); +define('_CO_IMFORUM_POST_UID', 'Auteur'); +define('_CO_IMFORUM_POST_POSTER_NAME', 'Naam gast'); +define('_CO_IMFORUM_POST_POSTER_IP', 'IP-adres'); +define('_CO_IMFORUM_POST_POST_TIME', 'Geplaatst op'); +define('_CO_IMFORUM_POST_SUBJECT', 'Onderwerp'); +define('_CO_IMFORUM_POST_POST_TEXT', 'Bericht'); +define('_CO_IMFORUM_POST_POST_EDIT', 'Bewerkingen'); +define('_CO_IMFORUM_POST_ICON', 'Icoon'); +define('_CO_IMFORUM_POST_ATTACHSIG', 'Handtekening toevoegen'); +define('_CO_IMFORUM_POST_APPROVED', 'Goedgekeurd'); +define('_CO_IMFORUM_POST_POST_KARMA', 'Vereiste karma'); +define('_CO_IMFORUM_POST_POST_KARMA_DSC', 'Alleen leden met minstens deze karma kunnen het bericht lezen'); +define('_CO_IMFORUM_POST_REQUIRE_REPLY', 'Reageren verplicht om te lezen'); +define('_CO_IMFORUM_POST_REQUIRE_REPLY_DSC', 'Leden zien het bericht pas nadat ze op het onderwerp gereageerd hebben'); + +// attachment +define('_CO_IMFORUM_ATTACHMENT_ATTACH_ID', 'ID'); +define('_CO_IMFORUM_ATTACHMENT_POST_ID', 'Bericht'); +define('_CO_IMFORUM_ATTACHMENT_NAME_SAVED', 'Opgeslagen bestandsnaam'); +define('_CO_IMFORUM_ATTACHMENT_NAME_DISPLAY', 'Bestandsnaam'); +define('_CO_IMFORUM_ATTACHMENT_MIMETYPE', 'MIME-type'); +define('_CO_IMFORUM_ATTACHMENT_FILESIZE', 'Grootte (bytes)'); +define('_CO_IMFORUM_ATTACHMENT_DOWNLOADS', 'Downloads'); +define('_CO_IMFORUM_ATTACHMENT_ONLINE', 'Zichtbaar'); +define('_CO_IMFORUM_ATTACHMENT_ATTACH_TIME', 'Geüpload op'); + +// report +define('_CO_IMFORUM_REPORT_REPORT_ID', 'ID'); +define('_CO_IMFORUM_REPORT_POST_ID', 'Bericht'); +define('_CO_IMFORUM_REPORT_REPORTER_UID', 'Gemeld door'); +define('_CO_IMFORUM_REPORT_REPORTER_IP', 'IP-adres'); +define('_CO_IMFORUM_REPORT_REPORT_TIME', 'Gemeld op'); +define('_CO_IMFORUM_REPORT_REPORT_TEXT', 'Reden'); +define('_CO_IMFORUM_REPORT_REPORT_RESULT', 'Afgehandeld'); +define('_CO_IMFORUM_REPORT_REPORT_MEMO', 'Notitie moderator'); + +// suspension +define('_CO_IMFORUM_SUSPENSION_SUSPENSION_ID', 'ID'); +define('_CO_IMFORUM_SUSPENSION_UID', 'Lid'); +define('_CO_IMFORUM_SUSPENSION_IP', 'IP-adres'); +define('_CO_IMFORUM_SUSPENSION_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_SUSPENSION_FORUM_ID_DSC', 'Geen forum betekent alle forums'); +define('_CO_IMFORUM_SUSPENSION_START_TIME', 'Vanaf'); +define('_CO_IMFORUM_SUSPENSION_END_TIME', 'Tot'); +define('_CO_IMFORUM_SUSPENSION_DESCRIPTION', 'Reden'); + +// readmark +define('_CO_IMFORUM_READMARK_READ_ID', 'ID'); +define('_CO_IMFORUM_READMARK_READ_TYPE', 'Type'); +define('_CO_IMFORUM_READMARK_UID', 'Lid'); +define('_CO_IMFORUM_READMARK_ITEM_ID', 'Forum of onderwerp'); +define('_CO_IMFORUM_READMARK_POST_ID', 'Laatst gelezen bericht'); +define('_CO_IMFORUM_READMARK_READ_TIME', 'Gelezen op'); + +// online +define('_CO_IMFORUM_ONLINE_ONLINE_ID', 'ID'); +define('_CO_IMFORUM_ONLINE_FORUM_ID', 'Forum'); +define('_CO_IMFORUM_ONLINE_TOPIC_ID', 'Onderwerp'); +define('_CO_IMFORUM_ONLINE_UID', 'Lid'); +define('_CO_IMFORUM_ONLINE_UNAME', 'Naam'); +define('_CO_IMFORUM_ONLINE_IP', 'IP-adres'); +define('_CO_IMFORUM_ONLINE_UPDATED', 'Laatst gezien'); + +// digest +define('_CO_IMFORUM_DIGEST_DIGEST_ID', 'ID'); +define('_CO_IMFORUM_DIGEST_DIGEST_TIME', 'Verstuurd op'); +define('_CO_IMFORUM_DIGEST_DIGEST_CONTENT', 'Inhoud'); + +// archive +define('_CO_IMFORUM_ARCHIVE_ARCHIVE_ID', 'ID'); +define('_CO_IMFORUM_ARCHIVE_TOPIC_ID', 'Onderwerp'); +define('_CO_IMFORUM_ARCHIVE_POST_ID', 'Bericht'); +define('_CO_IMFORUM_ARCHIVE_POST_TEXT', 'Bericht'); +define('_CO_IMFORUM_ARCHIVE_ARCHIVED_TIME', 'Gearchiveerd op'); + +// permtemplate +define('_CO_IMFORUM_PERMTEMPLATE_TEMPLATE_ID', 'ID'); +define('_CO_IMFORUM_PERMTEMPLATE_PERM_NAME', 'Recht'); +define('_CO_IMFORUM_PERMTEMPLATE_GROUPID', 'Groep'); + +// permissions +define('_CO_IMFORUM_PERM_CATEGORY_ACCESS', 'Kan de categorie zien'); +define('_CO_IMFORUM_PERM_CATEGORY_ACCESS_DSC', 'Groepen die deze categorie en haar forums op de index zien'); +define('_CO_IMFORUM_PERM_FORUM_ACCESS', 'Kan het forum zien'); +define('_CO_IMFORUM_PERM_FORUM_ACCESS_DSC', 'Groepen die dit forum in de lijst zien'); +define('_CO_IMFORUM_PERM_FORUM_VIEW', 'Kan lezen'); +define('_CO_IMFORUM_PERM_FORUM_VIEW_DSC', 'Groepen die onderwerpen in dit forum kunnen openen'); +define('_CO_IMFORUM_PERM_FORUM_POST', 'Kan onderwerpen starten'); +define('_CO_IMFORUM_PERM_FORUM_POST_DSC', 'Groepen die een nieuw onderwerp kunnen starten'); +define('_CO_IMFORUM_PERM_FORUM_REPLY', 'Kan reageren'); +define('_CO_IMFORUM_PERM_FORUM_REPLY_DSC', 'Groepen die op onderwerpen kunnen reageren'); +define('_CO_IMFORUM_PERM_FORUM_EDIT', 'Kan eigen berichten bewerken'); +define('_CO_IMFORUM_PERM_FORUM_EDIT_DSC', 'Groepen die hun eigen berichten kunnen bewerken'); +define('_CO_IMFORUM_PERM_FORUM_DELETE', 'Kan eigen berichten verwijderen'); +define('_CO_IMFORUM_PERM_FORUM_DELETE_DSC', 'Groepen die hun eigen berichten kunnen verwijderen'); +define('_CO_IMFORUM_PERM_FORUM_ATTACH', 'Kan bestanden bijvoegen'); +define('_CO_IMFORUM_PERM_FORUM_ATTACH_DSC', 'Groepen die bijlagen kunnen toevoegen'); +define('_CO_IMFORUM_PERM_FORUM_NOAPPROVE', 'Berichten zonder goedkeuring'); +define('_CO_IMFORUM_PERM_FORUM_NOAPPROVE_DSC', 'Groepen waarvan berichten verschijnen zonder goedkeuring door een moderator'); + +// messages +define('_CO_IMFORUM_CATEGORY_NOT_EMPTY', 'Deze categorie bevat nog forums. Verplaats of verwijder die eerst.'); +define('_CO_IMFORUM_FORUM_NO_PARENT', 'Geen (hoogste niveau)'); +define('_CO_IMFORUM_FORUM_PARENT_LOOP', 'Een forum kan niet onder zichzelf of onder een van zijn subforums geplaatst worden.'); +define('_CO_IMFORUM_POST_NO_TOPIC', 'Het onderwerp van dit bericht bestaat niet.'); diff --git a/tests/Integration/CascadeTest.php b/tests/Integration/CascadeTest.php new file mode 100644 index 0000000..559aa44 --- /dev/null +++ b/tests/Integration/CascadeTest.php @@ -0,0 +1,102 @@ +id()); + $keep = self::topic((int) $forum->id(), 'Keep'); + $topic = self::topic((int) $forum->id(), 'Delete'); + $reply = self::post((int) $topic->id()); + $file = self::attachment((int) $reply->id()); + self::make('report', ['post_id' => (int) $reply->id(), 'report_text' => 'Spam']); + self::handler('readmark')->markRead(2, 5, (int) $topic->id(), (int) $reply->id()); + + self::assertTrue(self::handler('topic')->delete($topic, true)); + + self::assertSame(1, self::rows('topic')); + self::assertSame(1, self::rows('post')); + self::assertSame(0, self::rows('attachment')); + self::assertSame(0, self::rows('report')); + self::assertSame(0, self::rows('readmark')); + self::assertFileDoesNotExist($file); + $forum = self::reload('forum', (int) $forum->id()); + self::assertSame(1, (int) $forum->getVar('forum_topics')); + self::assertSame((int) $keep->getVar('topic_last_post_id'), (int) $forum->getVar('forum_last_post_id')); + } + + public function testDeletingTheLastPostDeletesTheTopic(): void + { + $forum = self::forum((int) self::category()->id()); + $topic = self::topic((int) $forum->id()); + $first = self::reload('post', (int) $topic->getVar('topic_first_post_id')); + + self::assertTrue(self::handler('post')->delete($first, true)); + + self::assertSame(0, self::rows('topic')); + self::assertSame(0, (int) self::reload('forum', (int) $forum->id())->getVar('forum_topics')); + } + + public function testRepliesToADeletedPostMoveUp(): void + { + $forum = self::forum((int) self::category()->id()); + $topic = self::topic((int) $forum->id()); + $firstId = (int) $topic->getVar('topic_first_post_id'); + $middle = self::post((int) $topic->id(), 'Middle', 1, $firstId); + $child = self::post((int) $topic->id(), 'Child', 1, (int) $middle->id()); + + self::assertTrue(self::handler('post')->delete($middle, true)); + + self::assertSame($firstId, (int) self::reload('post', (int) $child->id())->getVar('pid')); + } + + public function testDeletingAForumRemovesItsContentAndKeepsSubforums(): void + { + $catId = (int) self::category()->id(); + $parent = self::forum($catId, 'Parent'); + $forum = self::forum($catId, 'Doomed', (int) $parent->id()); + $sub = self::forum($catId, 'Sub', (int) $forum->id()); + self::topic((int) $forum->id()); + self::topic((int) $sub->id()); + self::handler('moderator')->setModerators((int) $forum->id(), [7]); + self::make('suspension', ['uid' => 8, 'forum_id' => (int) $forum->id(), 'end_time' => time() + 3600]); + + self::assertTrue(self::handler('forum')->delete($forum, true)); + + self::assertSame(1, self::rows('topic')); + self::assertSame(0, self::rows('moderator')); + self::assertSame(0, self::rows('suspension')); + self::assertSame((int) $parent->id(), (int) self::reload('forum', (int) $sub->id())->getVar('parent_forum')); + } + + public function testACategoryWithForumsCannotBeDeleted(): void + { + $category = self::category(); + self::forum((int) $category->id()); + + self::assertFalse(self::handler('category')->delete($category, true)); + self::assertSame(1, self::rows('category')); + } + + public function testAnEmptyCategoryCanBeDeleted(): void + { + self::assertTrue(self::handler('category')->delete(self::category(), true)); + self::assertSame(0, self::rows('category')); + } + + private static function attachment(int $postId): string + { + $name = 'test-' . uniqid() . '.txt'; + file_put_contents(IMFORUM_UPLOAD_PATH . $name, 'attachment'); + self::make('attachment', ['post_id' => $postId, 'name_saved' => $name, 'name_display' => 'notes.txt']); + self::assertFileExists(IMFORUM_UPLOAD_PATH . $name); + return IMFORUM_UPLOAD_PATH . $name; + } +} diff --git a/tests/Integration/CoreConfig.php b/tests/Integration/CoreConfig.php new file mode 100644 index 0000000..7320c28 --- /dev/null +++ b/tests/Integration/CoreConfig.php @@ -0,0 +1,26 @@ + + */ + public function getConfigsByCat(int $category, int $module = 0): array + { + return [ + 'censor_enable' => false, + 'censor_words' => [], + 'censor_replace' => '', + 'language' => 'english', + ]; + } +} diff --git a/tests/Integration/CountersTest.php b/tests/Integration/CountersTest.php new file mode 100644 index 0000000..4aeb23f --- /dev/null +++ b/tests/Integration/CountersTest.php @@ -0,0 +1,84 @@ +id()); + $topic = self::topic((int) $forum->id()); + + $forum = self::reload('forum', (int) $forum->id()); + self::assertSame(1, (int) $forum->getVar('forum_topics')); + self::assertSame(1, (int) $forum->getVar('forum_posts')); + self::assertSame((int) $topic->getVar('topic_first_post_id'), (int) $forum->getVar('forum_last_post_id')); + self::assertSame(0, (int) $topic->getVar('topic_replies')); + } + + public function testRepliesUpdateTopicAndForum(): void + { + $forum = self::forum((int) self::category()->id()); + $topic = self::topic((int) $forum->id()); + self::post((int) $topic->id()); + $last = self::post((int) $topic->id()); + + $topic = self::reload('topic', (int) $topic->id()); + self::assertSame(2, (int) $topic->getVar('topic_replies')); + self::assertSame((int) $last->id(), (int) $topic->getVar('topic_last_post_id')); + self::assertSame(3, (int) self::reload('forum', (int) $forum->id())->getVar('forum_posts')); + } + + public function testPostTakesItsForumFromTheTopic(): void + { + $forum = self::forum((int) self::category()->id()); + $topic = self::topic((int) $forum->id()); + + self::assertSame((int) $forum->id(), (int) self::post((int) $topic->id())->getVar('forum_id')); + } + + public function testPostForAMissingTopicIsRefused(): void + { + $handler = self::handler('post'); + $post = $handler->create(); + $post->setVar('topic_id', 999); + $post->setVar('subject', 'Lost'); + $post->setVar('post_text', 'Nobody reads this'); + + self::assertFalse($handler->insert($post, true)); + self::assertSame(0, self::rows('post')); + } + + public function testUnapprovedPostsDoNotCount(): void + { + $forum = self::forum((int) self::category()->id()); + $topic = self::topic((int) $forum->id()); + $waiting = self::post((int) $topic->id(), 'Waiting', 1, 0, 0); + + self::assertSame(0, (int) self::reload('topic', (int) $topic->id())->getVar('topic_replies')); + self::assertSame(1, (int) self::reload('forum', (int) $forum->id())->getVar('forum_posts')); + + $waiting->setVar('approved', 1); + self::assertTrue(self::handler('post')->insert($waiting, true)); + self::assertSame(1, (int) self::reload('topic', (int) $topic->id())->getVar('topic_replies')); + self::assertSame(2, (int) self::reload('forum', (int) $forum->id())->getVar('forum_posts')); + } + + public function testDeletingAReplyRecounts(): void + { + $forum = self::forum((int) self::category()->id()); + $topic = self::topic((int) $forum->id()); + $reply = self::post((int) $topic->id()); + + self::assertTrue(self::handler('post')->delete($reply, true)); + $topic = self::reload('topic', (int) $topic->id()); + self::assertSame(0, (int) $topic->getVar('topic_replies')); + self::assertSame((int) $topic->getVar('topic_first_post_id'), (int) $topic->getVar('topic_last_post_id')); + self::assertSame(1, (int) self::reload('forum', (int) $forum->id())->getVar('forum_posts')); + } +} diff --git a/tests/Integration/Database.php b/tests/Integration/Database.php new file mode 100644 index 0000000..f71d7c1 --- /dev/null +++ b/tests/Integration/Database.php @@ -0,0 +1,106 @@ +quoteString($engine)); + } + + foreach (self::tables('') as $table) { + self::exec("DROP TABLE `$table`"); + } + self::createCoreTables(); + self::exec(sprintf( + "INSERT INTO %s (name, version, isactive, dirname, hasmain, hasadmin, dbversion, modname, ipf)" + . " VALUES ('imforum', '1.0.0', 1, 'imforum', 1, 1, 0, 'imforum', 1)", + $db->prefix('modules') + )); + + // Same steps as modulesadmin.php: load the definition, register the + // class path, sync the tables and run the upgrade functions, then the + // install routine. + icms_loadLanguageFile('imforum', 'modinfo'); + $module = icms::handler('icms_module')->getByDirname('imforum'); + $module->loadInfoAsVar('imforum'); + $module->registerClassPath(); + include_once ICMS_ROOT_PATH . '/modules/imforum/include/onupdate.php'; + $updater = icms_db_legacy_Factory::getDatabaseUpdater(); + $updater->moduleUpgrade($module, true); + if (!icms_module_install_imforum($module)) { + throw new RuntimeException('icms_module_install_imforum() failed'); + } + } + + /** + * Empty every imforum table and the group permissions + */ + public static function reset(): void + { + foreach (self::tables('imforum_') as $table) { + self::exec("TRUNCATE TABLE `$table`"); + } + self::exec('TRUNCATE TABLE `' . icms::$xoopsDB->prefix('group_permission') . '`'); + } + + /** + * Tables with the test prefix + * + * @return list + */ + public static function tables(string $startingWith): array + { + $db = icms::$xoopsDB; + $like = str_replace('_', '\\_', $db->prefix($startingWith)) . '%'; + $result = self::exec('SHOW TABLES LIKE ' . $db->quoteString($like)); + $tables = []; + while ($row = $db->fetchRow($result)) { + $tables[] = (string) $row[0]; + } + return $tables; + } + + /** + * @return mixed the query result + */ + public static function exec(string $sql): mixed + { + $result = icms::$xoopsDB->queryF($sql); + if ($result === false) { + throw new RuntimeException(icms::$xoopsDB->error() . "\n" . $sql); + } + return $result; + } + + /** + * Copy the core tables from the core's own install script + */ + private static function createCoreTables(): void + { + $structure = (string) file_get_contents(ICMS_ROOT_PATH . '/install/sql/mysql.structure.sql'); + foreach (self::CORE_TABLES as $table) { + if (!preg_match('/CREATE TABLE ' . $table . ' \((.*?)\n\);/s', $structure, $match)) { + throw new RuntimeException("CREATE TABLE $table not found in mysql.structure.sql"); + } + self::exec('CREATE TABLE `' . icms::$xoopsDB->prefix($table) . '` (' . $match[1] . ')'); + } + } +} diff --git a/tests/Integration/ForumTreeTest.php b/tests/Integration/ForumTreeTest.php new file mode 100644 index 0000000..db70763 --- /dev/null +++ b/tests/Integration/ForumTreeTest.php @@ -0,0 +1,44 @@ +id(); + $a = self::forum($catId, 'A'); + $b = self::forum($catId, 'B', (int) $a->id()); + $c = self::forum($catId, 'C'); + + self::assertSame( + [(int) $a->id() => 'A', (int) $b->id() => '-- B', (int) $c->id() => 'C'], + self::handler('forum')->getForumSelectList() + ); + } + + public function testAForumCannotBecomeItsOwnAncestor(): void + { + $catId = (int) self::category()->id(); + $a = self::forum($catId, 'A'); + $b = self::forum($catId, 'B', (int) $a->id()); + + $a->setVar('parent_forum', (int) $b->id()); + self::assertFalse(self::handler('forum')->insert($a, true)); + + $a->setVar('parent_forum', (int) $a->id()); + self::assertFalse(self::handler('forum')->insert($a, true)); + + self::assertSame(0, (int) self::reload('forum', (int) $a->id())->getVar('parent_forum')); + } + + public function testAllowedExtensionsAreNormalised(): void + { + $forum = self::forum((int) self::category()->id()); + $forum->setVar('attach_ext', ' ZIP| png ||'); + + self::assertSame(['zip', 'png'], $forum->getAllowedExtensions()); + } +} diff --git a/tests/Integration/IntegrationTestCase.php b/tests/Integration/IntegrationTestCase.php new file mode 100644 index 0000000..aae4d9d --- /dev/null +++ b/tests/Integration/IntegrationTestCase.php @@ -0,0 +1,85 @@ + $values + */ + protected static function make(string $item, array $values): icms_ipf_Object + { + $handler = self::handler($item); + $object = $handler->create(); + foreach ($values as $key => $value) { + $object->setVar($key, $value); + } + self::assertTrue($handler->insert($object, true), $item . ': ' . implode(', ', $object->getErrors())); + return $object; + } + + protected static function category(string $title = 'General'): icms_ipf_Object + { + return self::make('category', ['cat_title' => $title]); + } + + protected static function forum(int $catId, string $name = 'Forum', int $parent = 0): icms_ipf_Object + { + return self::make('forum', ['cat_id' => $catId, 'forum_name' => $name, 'parent_forum' => $parent]); + } + + /** + * A topic with its first post, as phase 4 will create them + */ + protected static function topic(int $forumId, string $title = 'Hello', int $uid = 1): icms_ipf_Object + { + $topic = self::make('topic', ['forum_id' => $forumId, 'topic_title' => $title, 'topic_poster' => $uid]); + self::post((int) $topic->id(), $title, $uid); + return self::reload('topic', (int) $topic->id()); + } + + protected static function post(int $topicId, string $subject = 'Re: Hello', int $uid = 1, int $pid = 0, int $approved = 1): icms_ipf_Object + { + return self::make('post', [ + 'topic_id' => $topicId, + 'subject' => $subject, + 'post_text' => 'Text of ' . $subject, + 'uid' => $uid, + 'pid' => $pid, + 'approved' => $approved, + ]); + } + + protected static function reload(string $item, int $id): icms_ipf_Object + { + $object = self::handler($item)->get($id); + self::assertFalse($object->isNew(), "$item $id not found"); + return $object; + } + + protected static function rows(string $item): int + { + return (int) self::handler($item)->getCount(); + } +} diff --git a/tests/Integration/MembersTest.php b/tests/Integration/MembersTest.php new file mode 100644 index 0000000..73ea371 --- /dev/null +++ b/tests/Integration/MembersTest.php @@ -0,0 +1,94 @@ +id())->id(); + $handler = self::handler('moderator'); + + self::assertTrue($handler->setModerators($forumId, [3, 4, 4, 0])); + self::assertEqualsCanonicalizing([3, 4], $handler->getModeratorIds($forumId)); + + self::assertTrue($handler->setModerators($forumId, [4, 5])); + self::assertEqualsCanonicalizing([4, 5], $handler->getModeratorIds($forumId)); + self::assertTrue($handler->isModerator(5, $forumId)); + self::assertFalse($handler->isModerator(3, $forumId)); + self::assertFalse($handler->isModerator(0, $forumId)); + } + + public function testSuspensionsApplyPerForumOrEverywhere(): void + { + $now = time(); + self::make('suspension', ['uid' => 10, 'forum_id' => 2, 'start_time' => $now - 10, 'end_time' => $now + 3600]); + self::make('suspension', ['ip' => '192.0.2.7', 'forum_id' => 0, 'start_time' => $now - 10, 'end_time' => $now + 3600]); + self::make('suspension', ['uid' => 11, 'forum_id' => 0, 'start_time' => $now - 7200, 'end_time' => $now - 3600]); + $handler = self::handler('suspension'); + + self::assertTrue($handler->isSuspended(10, '', 2, $now)); + self::assertFalse($handler->isSuspended(10, '', 3, $now)); + self::assertTrue($handler->isSuspended(0, '192.0.2.7', 3, $now)); + self::assertFalse($handler->isSuspended(11, '', 3, $now), 'expired'); + self::assertFalse($handler->isSuspended(0, "' OR 1=1 --", 3, $now), 'invalid address'); + self::assertFalse($handler->isSuspended(0, '', 3, $now)); + } + + public function testMarkReadKeepsOneRowPerItem(): void + { + $handler = self::handler('readmark'); + + self::assertTrue($handler->markRead(2, 5, 100, 1000)); + self::assertTrue($handler->markRead(2, 5, 100, 1005)); + self::assertTrue($handler->markRead(2, 5, 101, 1010)); + self::assertTrue($handler->markRead(1, 5, 100, 999)); + + self::assertSame(3, self::rows('readmark')); + self::assertSame([100 => 1005, 101 => 1010], $handler->getLastRead(2, 5, [100, 101, 102])); + self::assertSame([], $handler->getLastRead(2, 0, [100])); + self::assertFalse($handler->markRead(2, 0, 100, 1)); + } + + public function testPermissionTemplateRoundTrip(): void + { + $handler = self::handler('permtemplate'); + + self::assertTrue($handler->saveTemplate(['forum_view' => [1, 2, 3, 3], 'forum_post' => [1, 2], 'forum_vote' => [2]])); + $template = $handler->getTemplate(); + + self::assertSame([1, 2, 3], $template['forum_view']); + self::assertSame([1, 2], $template['forum_post']); + self::assertSame([], $template['forum_attach']); + self::assertArrayNotHasKey('forum_vote', $template); + + self::assertTrue($handler->saveTemplate(['forum_view' => [2]])); + self::assertSame([2], $handler->getTemplate()['forum_view']); + } + + public function testEditHistoryIsStoredAsJson(): void + { + $forum = self::forum((int) self::category()->id()); + $post = self::reload('post', (int) self::topic((int) $forum->id())->getVar('topic_first_post_id')); + + $post->addEdit(3, 'admin', 1700000000); + self::assertTrue(self::handler('post')->insert($post, true)); + + self::assertSame( + [['uid' => 3, 'name' => 'admin', 'time' => 1700000000]], + self::reload('post', (int) $post->id())->getEditHistory() + ); + } + + public function testForumPermissionsAreDeclared(): void + { + $names = array_column(self::handler('forum')->getPermissions(), 'perm_name'); + self::assertSame(\mod_imforum_ForumHandler::PERMISSIONS, $names); + self::assertSame(['category_access'], array_column(self::handler('category')->getPermissions(), 'perm_name')); + } +} diff --git a/tests/Integration/SchemaTest.php b/tests/Integration/SchemaTest.php new file mode 100644 index 0000000..8418594 --- /dev/null +++ b/tests/Integration/SchemaTest.php @@ -0,0 +1,79 @@ + substr($table, strlen(icms::$xoopsDB->prefix('imforum_'))), Database::tables('imforum_')); + sort($tables); + self::assertSame($expected, $tables); + } + + public function testDbVersionIsStored(): void + { + $module = icms::handler('icms_module')->getByDirname('imforum'); + self::assertSame(IMFORUM_DB_VERSION, (int) $module->getVar('dbversion')); + } + + public function testEveryIndexExists(): void + { + foreach (imforum_indexes() as $item => $indexes) { + foreach ($indexes as $name => $columns) { + self::assertSame($columns, self::indexColumns($item, $name), "$item.$name"); + } + } + } + + public function testFulltextIndexExistsWhereTheEngineSupportsIt(): void + { + $columns = self::indexColumns('post', 'ft_post_text'); + if ($columns === [] && !self::engineSupportsFulltext()) { + $this->markTestSkipped('InnoDB before MySQL 5.6 has no FULLTEXT; the install carried on without it'); + } + self::assertSame(['subject', 'post_text'], $columns); + } + + public function testUpgradeFunctionCanRunTwice(): void + { + // an interrupted update may run it again + self::assertTrue(imforum_db_upgrade_1()); + } + + /** + * @return list + */ + private static function indexColumns(string $item, string $name): array + { + $db = icms::$xoopsDB; + $result = Database::exec('SHOW INDEX FROM `' . $db->prefix('imforum_' . $item) . '` WHERE Key_name = ' . $db->quoteString($name)); + $columns = []; + while ($row = $db->fetchArray($result)) { + $columns[(int) $row['Seq_in_index']] = (string) $row['Column_name']; + } + ksort($columns); + return array_values($columns); + } + + private static function engineSupportsFulltext(): bool + { + $db = icms::$xoopsDB; + $result = Database::exec("SHOW TABLE STATUS LIKE " . $db->quoteString($db->prefix('imforum_post'))); + $status = $db->fetchArray($result); + $version = $db->fetchRow(Database::exec('SELECT VERSION()'))[0]; + return strcasecmp((string) $status['Engine'], 'MyISAM') === 0 + || str_contains((string) $version, 'MariaDB') + || version_compare((string) $version, '5.6', '>='); + } +} diff --git a/tests/Unit/LabelsTest.php b/tests/Unit/LabelsTest.php new file mode 100644 index 0000000..a1bf6f0 --- /dev/null +++ b/tests/Unit/LabelsTest.php @@ -0,0 +1,57 @@ + */ + public static function items(): iterable + { + $modversion = []; + include IMFORUM_TEST_MODULE_PATH . '/icms_version.php'; + foreach ($modversion['object_items'] as $item) { + yield $item => [$item]; + } + } + + #[DataProvider('items')] + public function testEveryFieldHasALabel(string $item): void + { + $source = (string) file_get_contents(IMFORUM_TEST_MODULE_PATH . '/class/' . ucfirst($item) . '.php'); + preg_match_all("/quickInitVar\\('([a-z_]+)'/", $source, $matches); + self::assertNotEmpty($matches[1]); + + $missing = []; + foreach ($matches[1] as $field) { + $constant = strtoupper('_CO_IMFORUM_' . $item . '_' . $field); + if (!defined($constant)) { + $missing[] = $constant; + } + } + self::assertSame([], $missing); + } + + public function testEveryPermissionHasACaption(): void + { + $source = (string) file_get_contents(IMFORUM_TEST_MODULE_PATH . '/class/ForumHandler.php'); + preg_match("/PERMISSIONS = \\[(.*?)\\];/s", $source, $match); + preg_match_all("/'([a-z_]+)'/", $match[1] ?? '', $permissions); + self::assertCount(8, $permissions[1]); + + foreach ([...$permissions[1], 'category_access'] as $permission) { + self::assertTrue(defined(strtoupper('_CO_IMFORUM_PERM_' . $permission)), $permission); + self::assertTrue(defined(strtoupper('_CO_IMFORUM_PERM_' . $permission . '_DSC')), $permission); + } + } +} diff --git a/tests/Unit/ModuleDefinitionTest.php b/tests/Unit/ModuleDefinitionTest.php index fef906f..abea95b 100644 --- a/tests/Unit/ModuleDefinitionTest.php +++ b/tests/Unit/ModuleDefinitionTest.php @@ -30,8 +30,38 @@ public function testDirnameAndModnameMatch(): void public function testObjectItemsEnablesIpfMode(): void { - // icms_module_Object::loadInfo sets ipf = 1 only when object_items is an array. + // icms_module_Object::loadInfo sets ipf = 1 only when object_items is an array, + // and modulesadmin.php only builds tables when it is not empty. self::assertIsArray(self::$modversion['object_items']); + self::assertNotEmpty(self::$modversion['object_items']); + } + + public function testEveryObjectItemHasItsClasses(): void + { + // icms_ipf_Handler looks for mod__, the autoloader for class/.php + foreach (self::$modversion['object_items'] as $item) { + self::assertMatchesRegularExpression('/^[a-z]+$/', $item, 'item names are single lower-case words'); + foreach ([ucfirst($item), ucfirst($item) . 'Handler'] as $class) { + $file = IMFORUM_TEST_MODULE_PATH . '/class/' . $class . '.php'; + self::assertFileExists($file); + self::assertStringContainsString('class mod_imforum_' . $class . ' extends', (string) file_get_contents($file)); + } + } + } + + public function testNoObjectItemIsAReservedWord(): void + { + // IPF uses the item name as a table alias (SELECT ... FROM table AS ), + // so a reserved word breaks every query of that handler. + $reserved = ['add', 'all', 'alter', 'and', 'as', 'by', 'call', 'case', 'check', 'column', 'condition', + 'create', 'cross', 'current', 'database', 'default', 'delete', 'desc', 'distinct', 'drop', 'each', + 'else', 'exists', 'fetch', 'for', 'from', 'function', 'grant', 'group', 'having', 'ignore', 'in', + 'index', 'insert', 'interval', 'into', 'is', 'join', 'key', 'keys', 'kill', 'like', 'limit', 'lock', + 'match', 'not', 'option', 'or', 'order', 'out', 'range', 'read', 'reads', 'release', 'rename', + 'repeat', 'replace', 'require', 'return', 'select', 'set', 'show', 'signal', 'table', 'then', 'to', + 'trigger', 'union', 'unique', 'update', 'usage', 'use', 'using', 'values', 'when', 'where', 'while', + 'with', 'write', 'rank', 'rows', 'row', 'system', 'window', 'groups', 'member', 'role']; + self::assertSame([], array_values(array_intersect(self::$modversion['object_items'], $reserved))); } public function testReferencedFilesExist(): void diff --git a/tests/integration-bootstrap.php b/tests/integration-bootstrap.php new file mode 100644 index 0000000..fbd60be --- /dev/null +++ b/tests/integration-bootstrap.php @@ -0,0 +1,105 @@ +