Collections functions
General functions
Render functions
Theme permission functions
Resource 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 127 to 152

Definition

 
function clean_comment_tree($ref)
    {
    
$all_comments ps_query("SELECT * 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 26th June 2022 05:05 Europe/London time based on the source file dated 21st June 2022 10:00 Europe/London time.