'',
'number' => $this->number );
$cats_to_exclude = '';
$title = empty($options['title']) ? __('Recent Comments') : apply_filters('widget_title', $options['title']);
$number = $options['number'];
/* Here comes ACE patch ;) */
$targets = "";
switch(get_option('ace_settings_exclude_method'))
{
case "smart":
$cats_to_exclude = get_option("ace_categories_is_home");
if ($wp_query->is_single)
{
$cats = split(',',$cats_to_exclude);
/**
* If this is a single post, and the
*/
$c = count($cats);
for($i=0;$i<$c;$i++)
{
/**
* If the post is in one category that has been selected for exclusion
*/
if(in_category($cats[$i]))
{
unset($cats[$i]);
}
}
$cats_to_exclude = join(",",(array) $cats);
}
elseif ($wp_query->is_category)
{
$cats = split(',',$cats_to_exclude);
$c = count($cats);
for($i=0;$i<$c;$i++)
{
/**
* If this category is beeing listed
*/
if($cats[$i] == $wp_query->query_vars['cat'])
{
unset($cats[$i]);
}
}
$cats_to_exclude = join(",",(array) $cats);
unset($cats);
}
else
{
/**
* The same as in normal mode. Keep in sync
*/
foreach ($ace_targets as $key=>$val)
{
if ($wp_query->$key == 1) $filter = $key;
}
/**
* If this is empty is_home exclusion is in affect
*/
if (!empty($filter) && $filter != "")
{
$cats_to_exclude = get_option("ace_categories_".$filter);
}
}
break;
case "front":
$cats_to_exclude = get_option("ace_categories_is_home");
break;
case "none":
$cats_to_exclude = "";
break;
default:
case "normal":
foreach ($ace_targets as $key=>$val)
{
if ($wp_query->$key == 1) $filter = $key;
}
$cats_to_exclude = get_option("ace_categories_".$filter);
break;
}
if ( !$number = (int) $options['number'] )
$number = 5;
else if ( $number < 1 )
$number = 1;
else if ( $number > 15 )
$number = 15;
/* ACE hack... :( */
if (!empty($cats_to_exclude))
{
$CAT_FILTER = "";
/* Before WP 2.3 */
if (empty($wpdb->term_taxonomy))
{
foreach(explode(',',$cats_to_exclude) as $category )
{
if (strlen($CAT_FILTER)>1) $CAT_FILTER = ' AND ';
$CAT_FILTER.="AND category_id = '$category'";
}
$POST_QUERY = "SELECT post_id FROM $wpdb->post2cat WHERE $CAT_FILTER";
}
else
{
foreach(explode(',',$cats_to_exclude) as $category )
{
if (!empty($CAT_FILTER)) $CAT_FILTER .= ' OR ';
else $CAT_FILTER = ' WHERE ';
$CAT_FILTER.= " $wpdb->term_taxonomy.term_id = '$category'";
}
$POST_QUERY = "SELECT $wpdb->term_relationships.object_id as post_id FROM $wpdb->term_relationships LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id) $CAT_FILTER";
}
$posts = $wpdb->get_results($POST_QUERY);
$POST_FILTER = "";
/**
* Get a list of posts, that we don't want to list the related comments of
*/
foreach( $posts as $post )
{
if (!empty($POST_FILTER)) $POST_FILTER.= " AND ";
$POST_FILTER.=" comment_post_ID != '".$post->post_id."'";
}
if (!empty($POST_FILTER)) $POST_FILTER = " AND ( ".$POST_FILTER.") ";
}
if ( !$comments = wp_cache_get( 'ace_recent_comments_'.$cats_to_exclude, 'widget' ) )
{
$COMMENT_QUERY="SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' $POST_FILTER ORDER BY comment_date_gmt DESC LIMIT $number";
$comments = $wpdb->get_results($COMMENT_QUERY);
wp_cache_add( 'ace_recent_comments'.$cats_to_exclude, $comments, 'widget' );
}
?>