Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

clean_comment_tree()

Description

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.

Parameters

ColumnTypeDefaultDescription
$ref int Ref of the comment that is being deleted.

Return

int Number of child comments that are not hidden.

Location

include/comment_functions.php lines 148 to 173

Definition

 
function clean_comment_tree($ref)
    {
    
$all_comments ps_query("SELECT " columns_in("comment") . " FROM comment WHERE ref_parent = ?", ['i'$ref]);
    
$remaining 0;
    
    if(
count($all_comments) > 0)
        {
        foreach(
$all_comments as $comment)
            {
            
$remaining += clean_comment_tree($comment['ref']);
            if(
$remaining == && $comment['hide'] == 1)
                {
                
ps_query("DELETE FROM comment WHERE ref = ?", ['i'$comment['ref']]);
                }
            }
        }

    
$remaining += ps_value("SELECT count(*) as `value` FROM comment WHERE ref_parent = ? and hide = 0", ['i'$ref], 0);

    if(
$remaining == 0)
        {
        
ps_query("DELETE FROM comment WHERE hide = 1 and ref = ?", ['i'$ref]);
        }

    return 
$remaining;
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 17th May 2024 16:10 Europe/London time.