$Page = \cs\Page::instance(); $Comments = null; \cs\Event::instance()->fire( 'Comments/instance', [ 'Comments' => &$Comments ] ); /** * @var \cs\modules\Comments\Comments $Comments */ $Page->content( $Comments ? $Comments->block($id) : '' );
Where $id is integer identifier of article, page or anything else, that will be commented. $Comments - is object created by module, but you can use own object of class, which inherits cs\modules\Comments\Comments class.
$Comments = null; \cs\Event::instance()->fire( 'Comments\instance', [ 'Comments' => &$Comments ] ); /** * @var \cs\modules\Comments\Comments $Comments */ if ($Comments) { //Some work here }
For this module should support next triggers on comments module:
[ 'Comments' => &$Comments 'item' => item 'module' => module ]
Module should register this trigger, and if module parameter is equal to name of this module - check, whether user have access to add comments
Assign to Comments parameter object of cs\modules\Comments\Comments class or class, that inherits it, set module to current module, return false from closure.
But other conditions holds true - return false from closure
Example (Blogs module):
\cs\Event::instance()->on( 'api/Comments/add', function ($data) { $Comments = null; \cs\Event::instance()->fire( 'Comments\instance', [ 'Comments' => &$Comments ] ); /** * @var \cs\modules\Comments\Comments $Comments */ $User = \cs\User::instance(); if (!( $data['module'] == 'Blogs' && \cs\Config::instance()->module('Blogs')->enable_comments && $User->user() && $Comments )) { return true; } if (\cs\modules\Blogs\Posts::instance()->get($data['item'])) { $data['Comments']->set_module('Blogs'); } return false; } );
[ 'Comments' => &$Comments 'id' => id 'module' => module ]
Module should register this trigger, and if module parameter is equal to name of this module - check, whether user have access to edit comment
Assign to Comments parameter object of cs\modules\Comments\Comments class or class, that inherits it, set module to current module, return false from closure.
But other conditions holds true - return false from closure
Example (Blogs module):
\cs\Event::instance()->on( 'api/Comments/edit', function ($data) { $Comments = null; \cs\Event::instance()->fire( 'Comments\instance', [ 'Comments' => &$Comments ] ); /** * @var \cs\modules\Comments\Comments $Comments */ $Comments->set_module('Blogs'); $User = \cs\User::instance(); if (!( $data['module'] == 'Blogs' && \cs\Config::instance()->module('Blogs')->enable_comments && $User->user() && $Comments )) { return true; } $comment = $Comments->get($data['id']); if ($comment && ($comment['user'] == $User->id || $User->admin())) { $data['Comments'] = $Comments; } return false; } );
[ 'Comments' => &$Comments 'id' => id 'delete_parent' => &$delete_parent 'module' => module ]
Module should register this trigger, and if module parameter is equal to name of this module - check, whether user have access to delete comment
Assign to Comments parameter object of cs\modules\Comments\Comments class or class, that inherits it, set module to current module, return false from closure.
But other conditions holds true - return false from closure
Example (Blogs module):
\cs\Event::instance()->on( 'api/Comments/delete', function ($data) { $Comments = null; \cs\Event::instance()->fire( 'Comments\instance', [ 'Comments' => &$Comments ] ); /** * @var \cs\modules\Comments\Comments $Comments */ $User = \cs\User::instance(); if (!( $data['module'] == 'Blogs' && \cs\Config::instance()->module('Blogs')->enable_comments && $User->user() && $Comments )) { return true; } $Comments->set_module('Blogs'); $comment = $Comments->get($data['id']); if ($comment && ($comment['user'] == $User->id || $User->admin())) { $data['Comments'] = $Comments; if ( $comment['parent'] && ( $comment = $Comments->get($comment['parent']) ) && ( $comment['user'] == $User->id || $User->admin() ) ) { $data['delete_parent'] = true; } } return false; } );
Returns count of comments for specified item
There are several other methods, but they are used directly not so frequent, so, you can find them with description in source code and IDE suggestions.