/** * Display a comment form to post new comments * and display the whole comment thread * @param int $pos_id */ function display_comment_thread($post_id) { $output = false; $count = 0; if (post_exist((int) $post_id)) { $coms = get_comments_byPOST((int) $post_id); $count += count($coms['comment_parent']); $count += count($coms['comment_children']); $output = '<div id="comments-post-' . $post_id . '" class="post-comments">'; $output .= '<div class="post-comment-head">'; $output .= '<h2>Discussion</h2>'; $output .= $count > 0 ? sprintf('<h4>%s Comments</h4>', $count) : '<h4>Be the first to comment</h4>'; $output .= '</div>'; $output .= '<div class="comment-form-box">'; $output .= display_comment_box((int) $post_id); $output .= '</div>'; if (is_array($coms) && isset($coms['comment_parent']) && !empty($coms['comment_parent'])) { $output .= markup_comment($post_id, $coms['comment_parent'], $coms['comment_children']); } else { $output .= '<ul class="comment-thread"><li id="post-thread-' . $post_id . '"></li></ul>'; } $output .= '</div>'; } return $output; }
/** * Delete post completely from the system * @param int $post_id pass the post id as an integer * @return bool true on success, false on fail */ function delete_post($post_id) { $output = false; $i = 0; if (post_exist((int) $post_id)) { $posts_list = get_json_content(CONTENTPATH . 'content.json'); $posts =& $posts_list['posts']; while ($i < count($posts)) { if ($posts[$i]['id'] === (int) $post_id) { if (delete_content($posts[$i]['content'])) { unset($posts[$i]); $posts = array_values($posts); if (write_to_json(CONTENTPATH . 'content.json', $posts_list)) { $output = true; } } break; } $i++; } } return $output; }