awp_live();
add_action('awp_die',array(&$this,'awp_die'));
add_action('awp_live',array(&$this,'awp_live'));
/*Template Functions*/
add_action('awp_comments', array(&$this,'div'));
add_action('awp_comments_link', array(&$this,'links'));
/*Internal Functions*/
add_action('awp_comments_do', array(&$this,'comments'));
add_action('awp_ajax_type_comments', array(&$this, 'AJAX'));
add_action('awp_js_start',array(&$this,'awp_js_start'));
add_action('awp_print_comments',array(&$this,'the_comments'));
}
$this->default_options();
}
function awp_die(){
global $awpall;
if($awpall['simple_comments'] == 1){
remove_filter('comments_template', array(&$this,'filter'),1);
}
}
function awp_live(){
global $awpall,$aWP;
static $started;
if(!$started || $aWP['die']){ /* We do not want to do this several times.*/
if($awpall['simple_comments'] == 1){
add_filter('comments_template', array(&$this,'filter'),1);
}
}
$started = 1;
}
function AJAX(){
global $awpall;
$awpall['split_comments'] = $awpall['split_inline_comments'];
ob_start();
do_action('awp_comments_do');
$response = ob_get_contents();
ob_end_clean();
$actions[] = '_p[i].show = _d[i].show';
$actions[] = '_p[i].hide = _d[i].hide';
$vars = $this->get_link_texts();
AWP::make_response($response, $vars,$actions);
}
function awp_js_start(){
?>
comments: function(postobj){
if(_d[i].show){
_p[i].show = _d[i].show;
}
if(_d[i].hide){
_p[i].hide = _d[i].hide;
}
return postobj;
},
0 || $awpall['comment_template'] == 2)){
echo "\n".'
';
}else{
echo "\n".'';
}
}
}
function get_link_texts(){
global $awpall;
$texts = array();
$defaults = array();
$texts[show] = $awpall['comment_open'];
$texts[hide] = $awpall['comment_hide'];
$defaults[show] = __('Show Posts Comments','awp');;
$defaults[hide] = __('Hide Post Comments','awp');
return AWP::link_texts($texts,$defaults,'comment');
}
function links($return=false){
global $id,$post,$awpall;
$links = $this->get_link_texts();
$comment_count = AWP::get_true_comment_count();
$show = $links[show];
// this is the most cheating way to do it, but it makes it Soooo easy.
if ( (is_single() && $awpall['show_comments_single']) || (is_page() && $awpall['show_comments_page']) || (is_home() && $awpall['show_comments_home'])){
$show = $links[hide];
$ops[doit] = "'show':'".js_escape($links[show])."', 'hide':'".js_escape($links[hide])."',";
}
$ops[doit] .= "'id': '$id', 'type': 'comments'" ;
$ops[_class] = "comments_link";
$ops[id] = 'awpcomments_link_'.$id;
$ops[anchor] = $show;
$ops[URL] = get_permalink($id).'#comments';
$ops[rel] = 'nofollow';
$ops = apply_filters('awp_link_array',$ops, 'comment');
$link = '';
if ($comment_count == 0 && comments_open() && $awpall['comment_template'] != 2){
$link .= "\n".' ';
$ops = apply_filters('awp_link_array',$ops, 'comment');
$ops[style] = "display:none;";
$ops[anchor] = $links[hide];
$link .= "\n".AWP::links($ops);
}elseif($comment_count == 0 && !comments_open()){
$link .= ($awpall['closed_comments'] == '')? __('Comments are closed','awp') : AWP::process_comment_text($awpall['closed_comments']);
}else{
$ops = apply_filters('awp_link_array',$ops, 'comment');
$link .= "\n".AWP::links($ops);
}
if($return){
return $link;
}else{
echo $link;
}
}
function filter($i){
global $id, $post,$awpall,$aWP;
$aWP[simplecomments] = 1;
return(AWP::template('inlinecomments','simplecomments'));
}
function comments(){
global $wpdb, $awpall,$id,$comments,$post,$comment,$user_ID,$user_identity;
if (!empty($post->post_password)) { // if there's a password
if ($_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie
echo '';
return;
}
}
if ( file_exists( TEMPLATEPATH . '/comments.php') && $awpall['comment_template'] == 2){
$comments = $this->get_comments();
include(TEMPLATEPATH . '/comments.php');
}elseif ( file_exists( TEMPLATEPATH . '/comments.php') && $awpall['comment_template'] == 4){
$comments = $this->get_comments();
ob_start();
include(TEMPLATEPATH . '/comments.php');
$response = ob_get_contents();
ob_end_clean();
if(strpos($response,'<') && strpos($response,'>')){
preg_match('@((\<\!--awp_comments[^>]*--\>\<[^>]*\>)([\S\s]*)(\<\/[^>]*\>\<\!--awp_comments[^>]*--\>))@',$response,$children);
}else{
preg_match('@((\]*\>)([\S\s]*)(\<\/ol\>))@',$response,$children);
}
echo $children[1];
}elseif ( file_exists( TEMPLATEPATH . '/awp-comments.php') && $awpall['comment_template'] == 3){
$comments = $this->get_comments();
include(TEMPLATEPATH . '/awp-comments.php');
}else{
$this->print_comments();
}
}
/* Modified comments_template() */
function get_comments(){
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $awpall,$aWP;
if(!$id){
$id=$post->ID;
}
$req = get_option('require_name_email');
$commenter = wp_get_current_commenter();
extract($commenter, EXTR_SKIP);
$order = 'ASC';
if($awpall[comment_order] == 1){ $order = 'DESC';}
$where = apply_filters('awp_comments_where','');
if ( $user_ID && !$aWP['basic_comments']) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$id' AND (comment_approved = '1' OR ( user_id = '$user_ID' AND comment_approved = '0' ) ) $where ORDER BY comment_date $order");
} else if ( empty($comment_author) || $aWP['basic_comments']) {
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$id' AND comment_approved = '1' $where ORDER BY comment_date $order");
} else {
$author_db = $wpdb->escape($comment_author);
$email_db = $wpdb->escape($comment_author_email);
$comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$id' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) $where ORDER BY comment_date $order");
}
// keep $comments for legacy's sake (remember $table*? ;) )
$comments = $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
$wp_query->comment_count = count($wp_query->comments);
if(function_exists('update_comment_cache')){
update_comment_cache($comments);
}
return $comments;
}
function print_comments(){
do_action('awp_print_comments'); //By default we use internal methods, but we want it to be pluggable.
}
function the_comments(){
global $awpall,$comment, $comments, $post,$id, $aWP;
$comments = $this->get_comments();
include(AWP::template('inlinecomments','comments'));
}
function admin(){
global $aWP, $awpall;
ob_start();
?>
';
$awpall['comment_reply_tag'] = ($awpall['comment_reply_tag'] != '') ? $awpall['comment_reply_tag'] : '';
$awpall['comment_tag'] = ($awpall['comment_tag'] != '') ? $awpall['comment_tag'] : '