Comments
The comments plugin adds a comment list and an add form to the pages of any user module: news, articles, profiles, your
own. Comments are stored in one table, comments, under an object name (usually the module name) and an
object id (the item). The module is module('comments') (yf_comments).
Comments on the pages of a module
Every user module that extends yf_module has the actions add_comment, edit_comment,
delete_comment and the helpers _view_comments() and _get_num_comments(). They read the module's
$_comments_params:
class my_recipes extends yf_module
{
public $_comments_params = [
'object_name' => 'recipes', // stored in comments.object_name (24 characters at most)
'return_action' => 'view', // where add / edit / delete go back to
];
public function view()
{
$id = (int) $_GET['id'];
return tpl()->parse('my_recipes/view', [
'comments' => $this->_view_comments(['object_id' => $id]),
'num_comments' => $this->_get_num_comments($id),
]);
}
// who may comment, edit and delete: the defaults of yf_module, override when needed
public function _comment_is_allowed($params = [])
{
return true;
}
}
Other keys: object_id (default $_GET['id']), stpl_main, stpl_item,
stpl_add (templates, default comments/main, comments/item, comments/add_form),
pager_path, add_form_action, return_path, allow_guests_posts (guests may add a
comment).
Who may edit and delete
The module the request is routed to decides through three hooks (the yf_module defaults in brackets):
_comment_is_allowed($params) (true), _comment_edit_allowed($params) and
_comment_delete_allowed($params) (the author only); they get user_id and object_id of the comment,
the delete hook also allow_author.
EDIT_LIMIT_TIME (a week) ends editing and deleting for users. ALLOW_DELETE_FOR_AUTHOR (default
true) lets authors delete on the user side: their own comments, and where the module's hook knows the owner of the
object, the comments under it (user_profile: the profile owner). With false the framework hooks and the
module without a hook refuse those deletes and hide the delete link; the admin side and silent_mode calls still delete.
A site's own _comment_delete_allowed() decides alone: read $params['allow_author'] there to follow the switch.
delete_comment is a POST-only action (core_blocks.POST_ONLY_ACTIONS, delete_*): with
core_blocks.CSRF_CHECK_POST_FOR['user'] on, a GET gets the confirm page and a POST needs the session token
(CSRF). _comment_on_update($params) of the module runs after each add,
edit and delete.
Since 2026-12-01 edit_comment and delete_comment act only on comments of the
routed module's own object: comments.object_name must be the given object name, the routed object, the module's
$_comments_params['object_name'], or a COMMENT_LINKS name whose link opens the routed object. Otherwise the
answer is "No such comment!". A hook that judges by object_id alone can no longer be tricked with the id of a comment
of another module whose object has the same id. Admin deletes and silent_mode are unchanged. A module whose comments are
stored under another name sets $_comments_params['object_name'] or a COMMENT_LINKS entry.
Guests and e-mail
- Guests comment only where the module passes
allow_guests_posts; the module'sUSE_CAPTCHAadds a captcha (a reply of a logged-in user in tree mode has none). - The e-mail field of the add form shows only to guests and only with
comments.VIEW_EMAIL_FIELD(defaulttrue; the templatecomments/add_formtestsview_user_email). Members never see it, and no address is stored with their comments. - A guest e-mail must pass
validate()->valid_email()and fit the column (64 characters): long TLDs such as.onlineand+addresses are accepted. - The address is shown with a comment only when
CHECK_ALLOW_TO_VIEW_USER_EMAILis on and the module's_comment_view_email_allowed()says yes.
Text, flood and spam
- Text is cut at
MAX_POST_TEXT_LENGTH(10000), filtered (AUTO_FILTER_INPUT_TEXT) and, withUSE_BB_CODES, its BB codes are closed. BB code links allow only safe URL schemes:[url=javascript:...]becomes#. ANTI_FLOOD_TIME(60 seconds) between two comments of one user, or of one IP address for guests. Theipcolumn isvarchar(45), so IPv6 addresses are stored whole; an existing table is widened by the migration20261201_comments_ip_varchar45(database migrations).ANTI_SPAM_DETECT(off) refuses a text with more than one link from a guest or more than three from a member; a user banned from comments (ban_comments) cannot add or delete.- New comments are stored active;
PROCESS_STATUS_FIELDshows only active ones, and an admin hides a comment on the admin comments page.
Tree mode, links and events
USE_TREE_MODE: replies under a comment (parent_id); deleting a comment with replies keeps its place as "comment was deleted".COMMENT_LINKS: object name => link of its item (news,articles,blog,gallery), used by the newest-comments block of the home page and the RSS; add your own objects there.- The event
comment.added(comment id, object name and id, parent id, user id) fires after a comment is stored (events).