comment_functions.php
Table of Contents
Functions
- comments_submit() : void
- Write comments to the database, also deals with hiding and flagging comments
- clean_comment_tree() : int
- Check all comments that are children of the comment ref provided. If there is a branch made up entirely of hidden comments then remove the branch.
- find_root_comment() : int|null
- Find the root of a comment tree that the ref provided is a part of
- comments_tags_to_links() : string
- Parse a comment and replace and add links to any user, resource and collection tags
- comments_show() : void
- Display all comments for a resource or collection
- comments_notify_tagged() : void
- Notify anyone tagged when a new comment is posted
- get_comments_by_ref() : array<string|int, mixed>
- Return comments for a resource or collection. There are two options for the output: 1. A flat list of comments ordered by creation date, newest first. Config $comments_flat_view = true 2. A tree view of comments, top level ordered most recent first with lower levels also most recent first while respecting a hierarchy of nested comments. Config $comments_flat_view = false (default) User permissions are also checked to ensure users can view comments. $comments_responses_max_level limits the number of levels returned in the comments tree (only applies when $comments_flat_view = false).
- hide_delete_comment() : bool
- Hide or delete a comment or annotation. Comments will be hidden where they have comments below them.
Functions
comments_submit()
Write comments to the database, also deals with hiding and flagging comments
comments_submit() : void
clean_comment_tree()
Check all comments that are children of the comment ref provided. If there is a branch made up entirely of hidden comments then remove the branch.
clean_comment_tree(mixed $ref) : int
@param int $ref Ref of the comment that is being deleted.
Parameters
- $ref : mixed
Return values
int —Number of child comments that are not hidden.
find_root_comment()
Find the root of a comment tree that the ref provided is a part of
find_root_comment(int $ref) : int|null
Parameters
- $ref : int
-
ref of a comment
Return values
int|null —ref of the root comment or null if the comment tree has been completely removed / the comment being checked has already been deleted.
comments_tags_to_links()
Parse a comment and replace and add links to any user, resource and collection tags
comments_tags_to_links(string $text) : string
Parameters
- $text : string
-
The input text e.g. the body of the comment
Return values
stringcomments_show()
Display all comments for a resource or collection
comments_show(int $ref[, bool $bcollection_mode = false ]) : void
Parameters
- $ref : int
-
The reference of the resource or collection
- $bcollection_mode : bool = false
-
false == show comments for resources, true == show comments for collection
comments_notify_tagged()
Notify anyone tagged when a new comment is posted
comments_notify_tagged(string $comment, int $from_user[, int $resource = null ][, int $collection = null ]) : void
Parameters
- $comment : string
-
The comment body
- $from_user : int
-
Who posted the comment
- $resource : int = null
-
If commenting on a resource, the resource ID
- $collection : int = null
-
If commenting on a collection, the collection ID
get_comments_by_ref()
Return comments for a resource or collection. There are two options for the output: 1. A flat list of comments ordered by creation date, newest first. Config $comments_flat_view = true 2. A tree view of comments, top level ordered most recent first with lower levels also most recent first while respecting a hierarchy of nested comments. Config $comments_flat_view = false (default) User permissions are also checked to ensure users can view comments. $comments_responses_max_level limits the number of levels returned in the comments tree (only applies when $comments_flat_view = false).
get_comments_by_ref(int $ref[, bool $collection_mode = false ]) : array<string|int, mixed>
Parameters
- $ref : int
-
Resource or collection ID.
- $collection_mode : bool = false
-
True if the $ref provided is a collection ID. False if $ref providing resource ID (default)
Return values
array<string|int, mixed> —Array of comments sorted per $comments_flat_view. Empty array if user doesn't have permission to to view comments.
hide_delete_comment()
Hide or delete a comment or annotation. Comments will be hidden where they have comments below them.
hide_delete_comment(int $comment_to_hide[, bool $allow_annotations = true ]) : bool
If the comment has no comments below it will be deleted. Trees with all hidden comments will also be deleted. Option to disable deletion / hiding of comments created as annotations e.g. to prevent API use.
Parameters
- $comment_to_hide : int
-
Reference of the comment to be deleted / hidden.
- $allow_annotations : bool = true
-
Should comments created by annotations be deleted / hidden.
Return values
bool —True if successful else false.