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 " 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 4th October 2022 16:35 Europe/London time based on the source file dated 1st July 2022 09:30 Europe/London time.