function cmtx_get_comment_and_replies($id) { global $cmtx_mysql_table_prefix, $cmtx_page_id, $cmtx_loop_counter, $cmtx_comment_counter, $cmtx_offset, $cmtx_exit_loop; //globalise variables $cmtx_loop_counter++; //increase loop counter by 1 if (!cmtx_setting('enabled_pagination')) { //if pagination is disabled if ($cmtx_comment_counter != 0) { //don't display on first run echo '<div class="cmtx_height_between_comments"></div>'; } //switch box number each time if ($cmtx_comment_counter % 2 == 0) { $alternate = 1; } else { $alternate = 2; } //get the details of the comment $comments_q = cmtx_db_query("SELECT * FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE `id` = '{$id}'"); $comments = cmtx_db_fetch_assoc($comments_q); //display comment echo cmtx_generate_comment(false, $alternate, $comments['id'], $comments['name'], $comments['email'], $comments['website'], $comments['town'], $comments['country'], $comments['rating'], $comments['reply_to'], $comments['comment'], $comments['reply'], $comments['is_admin'], $comments['likes'], $comments['dislikes'], $comments['is_sticky'], $comments['is_locked'], $comments['dated']); $cmtx_comment_counter++; //increase comment counter by 1 } else { //apply pagination if ($cmtx_loop_counter > $cmtx_offset + (cmtx_setting('comments_per_page') + 1)) { //if the page's comments have already been displayed $cmtx_exit_loop = true; //exit the loop to save on performance } if ($cmtx_loop_counter > $cmtx_offset && $cmtx_loop_counter < $cmtx_offset + (cmtx_setting('comments_per_page') + 1)) { //skip unwanted comments if ($cmtx_comment_counter != 0) { //don't display on first run echo '<div class="cmtx_height_between_comments"></div>'; } //switch box number each time if ($cmtx_comment_counter % 2 == 0) { $alternate = 1; } else { $alternate = 2; } //get the details of the comment $comments_q = cmtx_db_query("SELECT * FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE `id` = '{$id}'"); $comments = cmtx_db_fetch_assoc($comments_q); //display comment echo cmtx_generate_comment(false, $alternate, $comments['id'], $comments['name'], $comments['email'], $comments['website'], $comments['town'], $comments['country'], $comments['rating'], $comments['reply_to'], $comments['comment'], $comments['reply'], $comments['is_admin'], $comments['likes'], $comments['dislikes'], $comments['is_sticky'], $comments['is_locked'], $comments['dated']); $cmtx_comment_counter++; //increase comment counter by 1 } } if (cmtx_comment_has_reply($id)) { //if the comment has a reply //get all of its replies $reply_q = cmtx_db_query("SELECT `id` FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE `reply_to` = '{$id}' AND `is_approved` = '1' AND `page_id` = '{$cmtx_page_id}' ORDER BY `dated` ASC"); while ($replies = cmtx_db_fetch_assoc($reply_q)) { //while there are replies cmtx_get_comment_and_replies($replies['id']); //re-call this function to display the reply AND any replies it may have } } }
} echo '</div>'; } echo '</div>'; echo '<div style="clear: both;"></div>'; /* *** Comments *** */ echo '<div class="cmtx_height_above_comment_boxes"></div>'; $cmtx_sort = cmtx_get_sort_by(); $cmtx_comments_query = cmtx_db_query("SELECT `id` FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE `reply_to` = '0' AND `is_approved` = '1' AND `page_id` = '{$cmtx_page_id}' ORDER BY {$cmtx_sort};"); //get comments from database $cmtx_loop_counter = 0; $cmtx_comment_counter = 0; $cmtx_exit_loop = false; while ($cmtx_comments = cmtx_db_fetch_assoc($cmtx_comments_query)) { //while there are comments cmtx_get_comment_and_replies($cmtx_comments['id']); if ($cmtx_exit_loop) { break; } } echo '<div class="cmtx_height_below_comment_boxes"></div>'; /* *** RSS *** */ echo '<div class="cmtx_rss_block">'; if (cmtx_setting('show_rss')) { ?> <a href="<?php echo cmtx_commentics_url() . 'rss.php?id=' . $cmtx_page_id; ?> " rel="nofollow"><img src="<?php echo cmtx_commentics_url() . 'images/misc/rss.png'; ?>