Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

- 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.
- Phase 2: administration. Admin screens on `icms_ipf_view_Table` and `getSecureForm()` for categories and forums (moderators and group permissions on the forum form), a permission template that new forums start with and that can be applied to existing forums, reports, suspensions, digests, the archive, prune (with a preview and a confirmation) and a full recount. Every operation that writes runs only on POST with a valid security token, deletion confirmations included. Works around three core issues: a missing admin menu on the first request after the menu cache is rebuilt, `count(null)` when a permission select is left empty, and the date picker failing when a form is built before `icms_cp_header()`.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 1 (data model). The module creates its tables and the data layer works, but there are no admin screens or forum pages yet.
Status: phase 2 (administration). Categories, forums, moderators, group permissions, reports, suspensions, digests, the archive and pruning are managed from the admin area. There are no forum pages for visitors yet.

## Requirements

Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ parameters:
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, #'
# many core docblocks use "str" and "unknown_type", which are not types
message: '#^Parameter \#\d \$\w+ of (method|class) icms_\w+(::\w+\(\)| constructor) expects (str|unknown_type), #'
identifier: argument.type
-
# icms_ipf_Tree::getFirstChild() documents string; the tree is keyed by integer ids
Expand Down
16 changes: 16 additions & 0 deletions src/admin/admin_header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Common start of every admin script
*
* cp_header.php loads the core in admin mode, which refuses users who may not
* administer this module.
*
* @copyright The iForum project
* @license MIT, see LICENSE
* @package imforum
* @since 1.0
*/

include_once dirname(__DIR__, 3) . '/include/cp_header.php';
include_once dirname(__DIR__) . '/include/common.php';
include_once dirname(__DIR__) . '/include/admin.php';
43 changes: 43 additions & 0 deletions src/admin/archive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Archive: copies of posts kept when topics were archived, to read or delete
*
* Moderation (phase 5) writes them; there is no "add" here.
*
* @copyright The iForum project
* @license MIT, see LICENSE
* @package imforum
* @since 1.0
*/

include_once __DIR__ . '/admin_header.php';

$handler = icms_getModuleHandler('archive', IMFORUM_DIRNAME);
$op = imforum_admin_op([]);

switch ($op) {
case 'view':
$archive = $handler->get(imforum_admin_int('archive_id'));
if ($archive->isNew()) {
redirect_header(imforum_admin_url('archive.php'), 3, _CO_ICMS_NOT_SELECTED);
exit;
}
imforum_admin_page(7, $archive->getTopicTitle(), '<div class="imforum-archive">' . $archive->getVar('post_text') . '</div>');
break;

case 'del':
$controller = new icms_ipf_Controller($handler);
$controller->handleObjectDeletion();
break;

default:
$table = new icms_ipf_view_Table($handler, new icms_db_criteria_Compo(), ['delete']);
$table->addColumn(new icms_ipf_view_Column('topic_id', _GLOBAL_LEFT, false, 'getTopicTitle'));
$table->addColumn(new icms_ipf_view_Column('post_text', _GLOBAL_LEFT, false, 'getExcerpt'));
$table->addColumn(new icms_ipf_view_Column('archived_time', 'center', 140));
$table->addCustomAction('getViewLink');
$table->setDefaultSort('archived_time');
$table->setDefaultOrder('DESC');
imforum_admin_page(7, _AM_IMFORUM_ARCHIVE, $table->fetch(), _AM_IMFORUM_ARCHIVE_DSC);
break;
}
40 changes: 40 additions & 0 deletions src/admin/category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Categories: list, add, edit, delete
*
* @copyright The iForum project
* @license MIT, see LICENSE
* @package imforum
* @since 1.0
*/

include_once __DIR__ . '/admin_header.php';

$handler = icms_getModuleHandler('category', IMFORUM_DIRNAME);
$op = imforum_admin_op(['addcategory']);

switch ($op) {
case 'mod':
$category = $handler->get(imforum_admin_int('cat_id'));
$title = $category->isNew() ? _AM_IMFORUM_CATEGORY_ADD : _AM_IMFORUM_CATEGORY_EDIT;
imforum_admin_page(1, $title, static fn (): string => $category->getSecureForm($title, 'addcategory')->render());
break;

case 'addcategory':
imforum_admin_store($handler, _AM_IMFORUM_CATEGORY_CREATED, _AM_IMFORUM_CATEGORY_MODIFIED, imforum_admin_url('category.php'));
break;

case 'del':
$controller = new icms_ipf_Controller($handler);
$controller->handleObjectDeletion();
break;

default:
$table = new icms_ipf_view_Table($handler);
$table->addColumn(new icms_ipf_view_Column('cat_title', _GLOBAL_LEFT, false, 'getAdminLink'));
$table->addColumn(new icms_ipf_view_Column('weight', 'center', 80));
$table->setDefaultSort('weight');
$table->addIntroButton('addcategory', imforum_admin_url('category.php', 'op=mod'), _AM_IMFORUM_CATEGORY_ADD);
imforum_admin_page(1, _AM_IMFORUM_CATEGORIES, $table->fetch(), _AM_IMFORUM_CATEGORIES_DSC);
break;
}
43 changes: 43 additions & 0 deletions src/admin/digest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Digests: the mails sent so far, to read or delete
*
* The digest task (phase 6) writes them; there is no "add" here.
*
* @copyright The iForum project
* @license MIT, see LICENSE
* @package imforum
* @since 1.0
*/

include_once __DIR__ . '/admin_header.php';

$handler = icms_getModuleHandler('digest', IMFORUM_DIRNAME);
$op = imforum_admin_op([]);

switch ($op) {
case 'view':
$digest = $handler->get(imforum_admin_int('digest_id'));
if ($digest->isNew()) {
redirect_header(imforum_admin_url('digest.php'), 3, _CO_ICMS_NOT_SELECTED);
exit;
}
imforum_admin_page(6, sprintf(_AM_IMFORUM_DIGEST_OF, $digest->getVar('digest_time')),
'<div class="imforum-digest">' . $digest->getVar('digest_content') . '</div>');
break;

case 'del':
$controller = new icms_ipf_Controller($handler);
$controller->handleObjectDeletion();
break;

default:
$table = new icms_ipf_view_Table($handler, new icms_db_criteria_Compo(), ['delete']);
$table->addColumn(new icms_ipf_view_Column('digest_time', _GLOBAL_LEFT, 160));
$table->addColumn(new icms_ipf_view_Column('digest_content', _GLOBAL_LEFT, false, 'getExcerpt'));
$table->addCustomAction('getViewLink');
$table->setDefaultSort('digest_time');
$table->setDefaultOrder('DESC');
imforum_admin_page(6, _AM_IMFORUM_DIGESTS, $table->fetch(), _AM_IMFORUM_DIGESTS_DSC);
break;
}
64 changes: 64 additions & 0 deletions src/admin/forum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Forums: list, add, edit, delete, with group permissions and moderators
*
* @copyright The iForum project
* @license MIT, see LICENSE
* @package imforum
* @since 1.0
*/

include_once __DIR__ . '/admin_header.php';

$handler = icms_getModuleHandler('forum', IMFORUM_DIRNAME);
$op = imforum_admin_op(['addforum']);

switch ($op) {
case 'mod':
if (!icms_getModuleHandler('category', IMFORUM_DIRNAME)->getCategorySelectList()) {
redirect_header(imforum_admin_url('category.php', 'op=mod'), 3, _AM_IMFORUM_FORUM_NEEDS_CATEGORY);
exit;
}
$forum = $handler->get(imforum_admin_int('forum_id'));
$forum->setVar('moderators', icms_getModuleHandler('moderator', IMFORUM_DIRNAME)->getModeratorIds((int) $forum->id()));
if ($forum->isNew()) {
$forum->setVar('cat_id', imforum_admin_int('cat_id'));
}

$title = $forum->isNew() ? _AM_IMFORUM_FORUM_ADD : _AM_IMFORUM_FORUM_EDIT;
imforum_admin_page(2, $title, static function () use ($forum, $title): string {
$form = $forum->getSecureForm($title, 'addforum');
if ($forum->isNew()) {
// a new forum starts with the groups of the permission template
foreach (icms_getModuleHandler('permtemplate', IMFORUM_DIRNAME)->getTemplate() as $permission => $groups) {
$form->setElementValue($permission, $groups);
}
}
return $form->render();
});
break;

case 'addforum':
// no moderators is a choice too, so an unposted select clears them
imforum_admin_store($handler, _AM_IMFORUM_FORUM_CREATED, _AM_IMFORUM_FORUM_MODIFIED, imforum_admin_url('forum.php'), ['moderators']);
break;

case 'del':
$controller = new icms_ipf_Controller($handler);
$controller->handleObjectDeletion(_AM_IMFORUM_FORUM_DELETE_CONFIRM);
break;

default:
$table = new icms_ipf_view_Table($handler);
$table->addColumn(new icms_ipf_view_Column('forum_name', _GLOBAL_LEFT, false, 'getAdminLink'));
$table->addColumn(new icms_ipf_view_Column('cat_id', _GLOBAL_LEFT, false, 'getCategoryTitle'));
$table->addColumn(new icms_ipf_view_Column('forum_topics', 'center', 80));
$table->addColumn(new icms_ipf_view_Column('forum_posts', 'center', 80));
$table->addColumn(new icms_ipf_view_Column('forum_active', 'center', 60));
$table->addColumn(new icms_ipf_view_Column('weight', 'center', 60));
$table->setDefaultSort('cat_id');
$table->addIntroButton('addforum', imforum_admin_url('forum.php', 'op=mod'), _AM_IMFORUM_FORUM_ADD);
$table->addQuickSearch(['forum_name']);
imforum_admin_page(2, _AM_IMFORUM_FORUMS, $table->fetch(), _AM_IMFORUM_FORUMS_DSC);
break;
}
13 changes: 10 additions & 3 deletions src/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@
* @since 1.0
*/

include_once dirname(__DIR__, 3) . '/include/cp_header.php';
include_once dirname(__DIR__) . '/include/common.php';
include_once __DIR__ . '/admin_header.php';

icms_cp_header();
/** icms_cp_header() creates the admin template engine as a global */
global $icmsAdminTpl;
icms::$module->displayAdminMenu(0, _AM_IMFORUM_INDEX);
imforum_admin_menu(0, _AM_IMFORUM_INDEX);

$icmsAdminTpl->assign('imforum_version', icms::$module->getVar('version'));
$icmsAdminTpl->assign('imforum_dbversion', icms::$module->getDBVersion());
$icmsAdminTpl->assign('imforum_stats', [
_AM_IMFORUM_CATEGORIES => icms_getModuleHandler('category', IMFORUM_DIRNAME)->getCount(),
_AM_IMFORUM_FORUMS => icms_getModuleHandler('forum', IMFORUM_DIRNAME)->getCount(),
_AM_IMFORUM_TOPICS => icms_getModuleHandler('topic', IMFORUM_DIRNAME)->getCount(),
_AM_IMFORUM_POSTS => icms_getModuleHandler('post', IMFORUM_DIRNAME)->getCount(),
]);
$icmsAdminTpl->assign('imforum_open_reports', icms_getModuleHandler('report', IMFORUM_DIRNAME)->getOpenCount());
$icmsAdminTpl->assign('imforum_report_url', imforum_admin_url('report.php'));
$icmsAdminTpl->display('db:imforum_admin_index.html');

icms_cp_footer();
26 changes: 20 additions & 6 deletions src/admin/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@

defined('ICMS_ROOT_PATH') || die('ImpressCMS root path not defined');

// The position of each entry is the $menuIndex the admin scripts pass to
// imforum_admin_page(); keep both in step.
$adminmenu = [];
$adminmenu[] = [
'title' => _MI_IMFORUM_MENU_INDEX,
'link' => 'admin/index.php',
'icon' => 'images/imforum_iconbig.png',
'small' => 'images/imforum_iconsmall.png',
];
foreach ([
'index' => _MI_IMFORUM_MENU_INDEX,
'category' => _MI_IMFORUM_MENU_CATEGORIES,
'forum' => _MI_IMFORUM_MENU_FORUMS,
'permtemplate' => _MI_IMFORUM_MENU_PERMTEMPLATE,
'report' => _MI_IMFORUM_MENU_REPORTS,
'suspension' => _MI_IMFORUM_MENU_SUSPENSIONS,
'digest' => _MI_IMFORUM_MENU_DIGESTS,
'archive' => _MI_IMFORUM_MENU_ARCHIVE,
'prune' => _MI_IMFORUM_MENU_PRUNE,
] as $script => $title) {
$adminmenu[] = [
'title' => $title,
'link' => 'admin/' . $script . '.php',
'icon' => 'images/imforum_iconbig.png',
'small' => 'images/imforum_iconsmall.png',
];
}

// icms_module_Object::displayAdminMenu() counts the header menu without an
// isset check, so it must always be an array.
Expand Down
57 changes: 57 additions & 0 deletions src/admin/permtemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Permission template: the groups a new forum starts with
*
* Optionally applies the template to existing forums, replacing their
* permissions. iForum kept the template in a cache file; here it is a table.
*
* @copyright The iForum project
* @license MIT, see LICENSE
* @package imforum
* @since 1.0
*/

include_once __DIR__ . '/admin_header.php';

$handler = icms_getModuleHandler('permtemplate', IMFORUM_DIRNAME);
$forumHandler = icms_getModuleHandler('forum', IMFORUM_DIRNAME);
$op = imforum_admin_op(['save']);

if ($op === 'save') {
$template = [];
foreach (mod_imforum_ForumHandler::PERMISSIONS as $permission) {
$template[$permission] = array_map('intval', (array) ($_POST[$permission] ?? []));
}
$ok = $handler->saveTemplate($template);

$applyTo = array_map('intval', (array) ($_POST['apply_forums'] ?? []));
if ($applyTo) {
$permissions = new icms_ipf_permission_Handler($forumHandler);
foreach ($applyTo as $forumId) {
if ($forumHandler->get($forumId)->isNew()) {
continue;
}
foreach ($template as $permission => $groups) {
$ok = $permissions->saveItem_Permissions($groups, $forumId, $permission) && $ok;
}
}
}
redirect_header(imforum_admin_url('permtemplate.php'), 2, $ok ? _AM_IMFORUM_PERMTEMPLATE_SAVED : _AM_IMFORUM_PERMTEMPLATE_ERROR);
exit;
}

$form = new icms_form_Theme(_AM_IMFORUM_PERMTEMPLATE, 'permtemplate', imforum_admin_url('permtemplate.php'), 'post', true);
foreach ($handler->getTemplate() as $permission => $groups) {
$caption = '_CO_IMFORUM_PERM_' . strtoupper($permission);
$select = new icms_form_elements_select_Group(constant($caption), $permission, true, $groups, 5, true);
$select->setDescription(constant($caption . '_DSC'));
imforum_form_add($form, $select);
}
$forums = new icms_form_elements_Select(_AM_IMFORUM_PERMTEMPLATE_APPLY, 'apply_forums', null, 8, true);
$forums->addOptionArray($forumHandler->getForumSelectList());
$forums->setDescription(_AM_IMFORUM_PERMTEMPLATE_APPLY_DSC);
imforum_form_add($form, $forums);
imforum_form_add($form, new icms_form_elements_Hidden('op', 'save'));
imforum_form_add($form, new icms_form_elements_Button('', 'submit', _CO_ICMS_SUBMIT, 'submit'));

imforum_admin_page(3, _AM_IMFORUM_PERMTEMPLATE, $form->render(), _AM_IMFORUM_PERMTEMPLATE_DSC);
Loading
Loading