SubscriptCatForum Plugin for Cotonti CMF
User subscription to forum category updates
1. Functional Overview and Purpose
SubscriptCatForum is a plugin for Cotonti CMF that implements a system allowing users to subscribe to forum categories. After subscribing, the user receives email notifications when new events appear in the selected sections.
The main purpose of the plugin is to simplify tracking activity on the forum. Users do not need to regularly check the sections they are interested in: the system automatically sends notifications about new events.
Main Features
Subscription to forum categories
The user can select one or several forum categories and subscribe to their updates. Subscription management is performed through a separate plugin page.
After subscribing, the user will receive notifications about all new events in the selected sections.
Email notifications
When new events appear in a category, the plugin sends an email notification to subscribers. The message contains:
- topic title
- section title
- name of the message author
- text of the latest message (without HTML)
- link to the topic
- link to the specific post
Tracked events
The plugin reacts to forum events through the Cotonti hook system. Notifications are sent for the following actions:
- creation of a new topic in a category
- creation of a new post in a topic
- editing a message
- moving a topic between categories (handled in the notification logic)
User subscription management
The user can:
- subscribe to categories
- modify the list of subscriptions
- completely remove subscriptions
This is done through a separate plugin page available via the user account menu.
Administrative subscription management
The site administrator can:
- view subscribers of each category
- add a user to a subscription
- remove a user from a subscription
The administrative interface displays a list of forum categories and the users subscribed to them.
Advantages of using
- The user follows only the sections they are interested in.
- There is no need to subscribe to each topic individually.
- The chance of missing new discussions is reduced.
- The administrator can centrally manage subscriptions.
Current limitations
At the moment of implementation the plugin has the following limitations:
- notifications are sent immediately when an event occurs (without cron)
- pagination is not implemented
- debug logging is enabled
The plugin is intended for use on small Cotonti forums.
Requirements
The plugin was tested in the following configuration:
- Cotonti CMF (latest version from GitHub as of 25-02-2025)
- PHP 8.4
- MySQL 8.4
2. Technical part (plugin operation)
The plugin uses the Cotonti hook system, which allows it to react to forum events and send notifications.
Plugin architecture
Main components:
- subscription table
- forum event hooks
- standalone subscription management page
- administrative interface
- subscription management functions
Subscription table
The plugin creates a separate table:
CREATE TABLE IF NOT EXISTS `cot_subscriptcatforum` (
`id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`user_id` INT UNSIGNED NOT NULL,
`cat_forum_subs` text NOT NULL,
`created_at` INT UNSIGNED NOT NULL DEFAULT 0
);
Fields:
| field | description |
| id | unique record identifier |
| user_id | user ID |
| cat_forum_subs | forum category code |
| created_at | subscription creation time |
Forum hooks
The plugin reacts to several forum events.
1. New post
Hook:
Hooks=forums.posts.newpost.done
File:
subscriptcatforum.forums.posts.newpost.done.php
Main actions:
- determine the topic ID and category code
- retrieve the latest post
- find subscribers of the category
- compose the email
- send notifications
Retrieving subscribers:
$subscribers = $db->query("
SELECT u.user_email, u.user_id
FROM $db_subscriptcatforum s
JOIN $db_users u ON s.user_id = u.user_id
WHERE s.cat_forum_subs = ?
AND u.user_id != ?", [$section_code, $post_author_id])->fetchAll();
The post author is excluded from the recipients list.
2. Creating a new topic
Hook:
Hooks=forums.newtopic.newtopic.done
File:
subscriptcatforum.forums.newtopic.newtopic.done.php
Algorithm:
- determine the topic ID
- retrieve the topic title and category
- obtain the first post data
- compose the email
- send notifications to category subscribers
3. Editing a post
Hook:
Hooks=forums.editpost.update.done
File:
subscriptcatforum.forums.editpost.update.done.php
This handler:
- receives the category
- finds subscribers
- retrieves the updated post
- sends an edit notification
Link generation
Links to the topic and post are generated using standard Cotonti functions:
$topic_url = cot_url('forums', 'm=posts&q=' . $topic_id);
$post_url = cot_url('forums', "m=posts&id=" . $post_id . "&n=last", "#bottom");
Email sending
The built-in Cotonti function is used:
cot_mail($user_email, $subject, $message);
Logging
File logging is used for debugging:
function log_to_file_newpostdone($message) {
$logfile = __DIR__ . '/subscription_debug.log';
$date = date('Y-m-d H:i:s');
file_put_contents($logfile, "[$date] $message\n", FILE_APPEND);
}
The log records:
- handler start
- request parameters
- found subscribers
- sent emails
Subscription management functions
File:
subscriptcatforum.functions.php
Main functions:
Subscription check
function check_existing_subscription($user_id, $forum_id) {
return $db->query("SELECT COUNT(*) FROM $db_subscriptcatforum WHERE user_id = ? AND cat_forum_subs = ?", [$user_id, $forum_id])->fetchColumn() > 0;
}
User subscription
function subscribe_user($user_id, $forum_id) {
$db->query("INSERT INTO $db_subscriptcatforum (user_id, cat_forum_subs, created_at) VALUES (?, ?, ?)", [$user_id, $forum_id, time()]);
}
User unsubscription
function unsubscribe_user($user_id, $forum_id) {
$db->query("DELETE FROM $db_subscriptcatforum WHERE user_id = ? AND cat_forum_subs = ?", [$user_id, $forum_id]);
}
3. Installation, configuration and operation
Plugin installation
- Copy the plugin folder
subscriptcatforum
to the directory
/plugins/
- Open the Cotonti administrator panel.
- Find the SubscriptCatForum plugin.
- Install it.
During installation the table is automatically created:
cot_subscriptcatforum
Adding a link to the user menu
To access the subscription management page you need to add a link to the theme template.
Example fragment:
<!-- IF {PHP|cot_plugins_active('subscriptcatforum')} -->
<li><a href="{PHP|cot_url('subscriptcatforum')}">{PHP.L.subscriptcatforum_title_link}</a></li>
<!-- ENDIF -->
The link is usually placed in the user account menu.
Subscription management page
The plugin page displays:
- list of forum categories
- category hierarchy
- selection checkboxes
Example HTML structure:
<input type="checkbox"
class="form-check-input"
name="selected_categories[]"
value="{CATEGORY_CODE}"
{IS_SELECTED}>
After submitting the form:
- old user subscriptions are removed
- selected categories are written to the table
$db->query("DELETE FROM $db_subscriptcatforum WHERE user_id = ?", [$usr['id']]);
Then new records are added.
Subscription administration
The administrator can manage subscriptions via the tool:
admin → tools → subscriptcatforum
The interface displays:
- forum categories
- list of subscribers
- form for adding a user
Adding a user:
$db->insert($db_x . "subscriptcatforum", [
'user_id' => $user_id,
'cat_forum_subs' => $category_id,
'created_at' => time()
]);
Removing a user:
$db->delete($db_x . "subscriptcatforum", "user_id = ? AND cat_forum_subs = ?", [$user_id, $category_id]);
Operation
The plugin starts working immediately after installation.
Notifications are automatically sent when:
- a topic is created
- a post is published
- a message is edited
All events are recorded in logs, which allows diagnostics to be performed.
Plugin support topic, questions, discussions and suggestions
Download the plugin https://github.com/webitproff/cot-subscriptcatforum
Buy
SubscriptCatForum – User Subscription to Forum Updates at low prices. Online store offers to order SubscriptCatForum – User Subscription to Forum Updates, view full description, detailed specifications, product photos and current prices with discounts