'.$this->links($comment->comment_ID,true).'
';
$comments = $this->comments($comment->comment_ID);
if(!$comments)
return $text;
$depth[$id]++;
ob_start();
include(TEMPLATEPATH . '/comments.php');
$response = ob_get_contents();
ob_end_clean();
if(stripos($response,'<') && stripos($response,'>')){
preg_match('@((\<\!--AWP_inlinecomments[^>]*--\>\<[^>]*\>)([\S\s]*)(\<\/[^>]*\>\<\!--AWP_inlinecomments[^>]*--\>))@',$response,$children);
}else{
preg_match('@((\]*\>)([\S\s]*)(\<\/ol\>))@',$response,$children);
}
if($children[1]){
if($depth[$id] < $awpall['comment_threaded_depth']){
$text .= $children[1];
}else{ echo $depth[$id];
$text .= $children[3];
}
}
$depth[$id]--;
return $text;
}
function filter_comments($acomments){
global $AWP_inlinecomments;
remove_filter('comments_array', array(&$this,'filter_comments'));
if(class_exists('AWP_inlinecomments'))
$acomments = $AWP_inlinecomments->get_comments();
$comments = $this->comments(0,$acomments);
add_filter('comments_array', array(&$this,'filter_comments'));
return $comments;
}
function comments($parent=0,$acomments=false){
static $noparents = array();
static $parents = array();
if($acomments){
$parents = null;
$noparents = null;
foreach($acomments as $comment){
if(!$comment->comment_parent){
$noparents[] = $comment;
}else{
$parents[$comment->comment_parent][] = $comment;
}
}
}
if($parent == 0)
return $noparents;
return $parents[$parent];
}
function start_thread(){
global $AWP_inlinecomments;
if($AWP_inlinecomments)
$acomments = $AWP_inlinecomments->get_comments();
$comments = $this->comments(0,$acomments);
$this->thread();
}
function thread($comment_parent_id=0) {
global $id, $comment,$awpall;
static $depth = array();
static $crawl_up;
$comments = $this->comments($comment_parent_id);
if(is_array($comments)){
if($awpall['hide_old_child_comments'] == 1){
if(strtotime($comment->comment_date_gmt) < (time()-(60*60*24*$awpall['old_comment_days'])) ){
$old=1;
}
}
if(($awpall['hide_child_comments'] == 1 || $old== 1) && $comment_parent_id > 0){
echo "\n" . '';
//echo "\n".'';
echo str_replace('>','id="awpcomment_children_'.$comment->comment_ID.'" style="display:none;">',$awpall['comment_reply_tag']).$awpall['comment_reply_tag_end'];
}else{
$depth[$id]++;
$temp = new AWP_threader;
$temp->template($comments, $depth[$id]);
}
if($depth[$id] >1)
$depth[$id]--;
$comments = null;
$crawl_up = null;
}
}
//loads children for comment. AJAX function.
function comment_children(){
global $awpall,$post;
if(is_numeric($_POST['comment_parent'])){
$awpall['hide_old_child_comments'] = $awpall['hide_child_comments'] = 0; /*Disable temporarily*/
ob_start();
$this->thread($_POST['comment_parent']);
$response = ob_get_contents();
ob_end_clean();
$actions[] = '_p[i].show = _d[i].show;_p[i].hide = _d[i].hide;';
AWP::make_response($response, $vars,$actions);
}else{
die(__('Invalid parent', 'awp'));
}
}
function get_parent($id,$reset_parent=false,$new_parent=0) {
global $wpdb;
if(!$reset_parent){
$comment_parent = $_POST['comment_post_parent'];
}else{
$comment_parent = $new_parent;
}
if(is_numeric($comment_parent) || $reset_parent == 1) {
$result = $wpdb->query("UPDATE $wpdb->comments SET comment_parent = '$comment_parent' WHERE comment_ID = '$id'");
}
}
function set_parent($commentdata){
$comment_parent = (int) $_POST['comment_parent'];
if(is_numeric($comment_parent) && empty($commentdata['comment_parent'])){
$commentdata['comment_parent'] = $comment_parent;
}
return $commentdata;
}
function delete_parent($parent_ID, $mode='delete'){
global $wpdb,$awpall,$id,$AWP_inlinecomments;
static $loaded = 0;
if($mode != 'delete')
return;
$comment = get_commentdata($parent_ID,1,true);
$id = $comment['comment_post_ID'];
$parent = $comment['comment_parent'];
if(is_numeric($parent_ID)){
if(!$loaded)
$loaded = $this->comments(0,$AWP_inlinecomments->get_comments());
$comments = $this->comments($parent_ID);
if(!is_array($comments))
return;
if($awpall['on_parent_delete'] == 'delete'){
foreach($comments as $c){
wp_delete_comment($c->comment_ID);
}
}elseif($awpall['on_parent_delete'] == 'reset'){
foreach($comments as $c){
$this->get_parent($c->comment_ID,1);
}
}elseif($awpall['on_parent_delete'] == 'shift'){
foreach($comments as $c){
$this->get_parent($c->comment_ID,1,$parent);
}
}
}
}
function thread_links($depth){
global $awpall, $comment, $aWP;
if($depth <= $awpall['comment_threaded_depth'] || 1 == 1){
$this->links($comment->comment_ID);
}
}
function thread_next($depth){
global $awpall, $comment, $aWP;
$no_end = 0;
if($depth <= $awpall['comment_threaded_depth'] || 1 == 1){
if($depth > $awpall['comment_threaded_depth']-1){
echo $awpall['comment_tag_end']; $no_end = 1;
}
}else{
echo $awpall['comment_tag_end']; $no_end = 1;
}
$this->thread($comment->comment_ID);
return $no_end;
}
function get_link_texts($extra=''){
global $awpall;
$texts = array();
$defaults = array();
$texts[show] = $awpall['commentform_reply_open'];
$texts[hide] = $awpall['commentform_reply_hide'];
$defaults[show] = __('Add a Comment','awp');
$defaults[hide] = __('Cancel reply','awp');
return AWP::link_texts($texts,$defaults,'comment');
}
function links($extra='',$return=false){
global $id,$awpall,$awp_link_count;
global $is_page, $is_single;
if ( !comments_open() || (!is_user_logged_in() && get_option('comment_registration')))
return;
if(!$awp_link_count[$id]){
$awp_link_count[$id] = 10;
}
$links = $this->get_link_texts($extra);
$show2 = $links[show];
$show = $links[show];
$link = '';
$ops[_class] = "commentform_link";
$ops[id] = 'awpcommentform_link'.$awp_link_count[$id].'_'.$id;
$ops[anchor] = stripslashes($links[show]);
$ops[URL] = get_permalink($id).'#respond';
$ops[doit] = "'id': '$id', 'type': 'commentform', 'show': '".js_escape($links[show])."', 'hide': '".js_escape($links[hide])."', 'link_num': '$awp_link_count[$id]' ";
if($awpall[nomove] || !is_singular())
$ops[doit] .= ", 'nomove' : 1";
$ops[doit] .= ", 'com_parent': '$extra'";
$ops[anchor] = $links[show];
$awp_link_count[$id]++;
$link = AWP::links($ops,$return);
if($return){
return $link;
}else{
echo $link;
}
}
function threaded_comments(){
global $awpall,$id;
?>
-
-
*/
$menu = ob_get_contents();
ob_end_clean();
do_action('awp_build_menu',$menu);
}
function awp_get_options($j){
$j[texts][] = 'comment_threaded_depth';
$j[texts][] = 'old_comment_days';
$j[checkboxes][] = 'hide_old_child_comments';
$j[checkboxes][] = 'hide_child_comments';
$j[checkboxes][] = 'simple_threading';
$j[selects][] = 'threadedcomments';
$i[texts][] = 'commentform_reply_open';
$i[texts][] = 'commentform_reply_close';
$j[radios][] = array('on_parent_delete','shift');
return $j;
}
function set_defaults(){
global $awpall;
$awpall[threadedcomments] = 'Enabled';
$awpall[comment_threaded_depth] = 4;
update_option('awp',$awpall);
}
}
class AWP_threader{
function template($comments,$depth){
global $awpall,$comment, $post,$id, $aWP;
include(AWP::template('inlinecomments','comments'));
}
}
?>