'recent-comments', 'description' => _a('The most recent comments')); $control_ops = array('width' => 500); $this->WP_Widget('atom-recent-comments', _a('Recent Comments'), $widget_ops, $control_ops); atom_add('ajax_requests', array(&$this, 'ajax')); // run after the widget instance is properly registered (we only need to define the COUNTRY_FLAGS constant) add_action('widgets_init', array(&$this, 'set_country_flags'), 99); // include in jQuery(document).ready() atom_add('jquery_init', array(&$this, 'js')); // flush cache when comments are changed add_action('comment_post', array(&$this, 'flush_cache')); add_action('transition_comment_status', array(&$this, 'flush_cache')); } function set_country_flags(){ // we need to process all instances because this function gets to run only once $widget_settings = atom_get_options($this->option_name); foreach((array)$widget_settings as $instance => $options): // identify instance $id = "{$this->id_base}-{$instance}"; $block_id = "instance-{$id}"; // we need to set a custom margin value to the list text, if the widget shows avatars if(!defined('COUNTRY_FLAGS') && isset($options['country_flag']) && $options['country_flag'] && is_active_widget(false, $id, $this->id_base)) define('COUNTRY_FLAGS', TRUE); endforeach; } function flush_cache(){ wp_cache_delete('widget_recent_comments', 'widget'); } function js(){ // we need to process all instances because this function gets to run only once $widget_settings = atom_get_options($this->option_name); foreach((array)$widget_settings as $instance => $options): // identify instance $id = "{$this->id_base}-{$instance}"; $block_id = "instance-{$id}"; if (isset($options['more']) && $options['more'] && !$options['site_wide'] && is_active_widget(false, $id, $this->id_base)): ?> $("# a.more").click(function(event){ event.preventDefault(); $offset = parseInt($(this).attr('rel')); $.ajax({ type: "GET", url: "", data: { instance: , offset: $offset, _ajax_nonce: "", atom: 'get_recent_comments' }, dataType: 'json', context: this, beforeSend: function() { $(this).addClass("loading"); }, complete: function() { $(this).removeClass("loading"); }, success: function(response){ var link = $(this); // append to list & update tab container height (if we're inside a tabbed widget) if(response.output != '') $(response.output).appendTo("# ul").hide().each(function(i){ $(this).delay(333*i).animate( { "opacity": "show", "height": "show", "marginTop": "show", "marginBottom": "show", "paddingTop": "show", "paddingBottom": "show" }, { duration: 333, step: function(now, fx){ link.parents('li.block .sections').height((link.parents('#').height()) + 5); } }); }); link.attr('rel', response.offset); // no more data? if(!response.more) link.hide(); } }); }); option_name); $instance = intval($_GET['instance']); $settings = $settings[$instance]; $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; $output = $this->get_comments($settings, $next, $offset); $offset = $offset + $settings['number']; //$next = ($this->get_comments($settings, $offset)) ? true : false; echo json_encode(array('output' => $output, 'more' => $next, 'offset' => $offset)); exit(); endif; } function template(){ return "\n" ." {AVATAR}\n" ." \n" ." {FLAG}{AUTHOR}\n" ." {CONTENT}\n" ." {DATE}\n" ." \n" ."\n"; } function get_comments($args, &$more, $offset = 0){ extract($args); if($site_wide): global $wpdb; $selects = array(); foreach (atom_get_sites() as $blog) $selects[] = "(SELECT comment_ID, comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date_gmt, comment_content, post_title, {$blog['blog_id']} as blog_id FROM ".$wpdb->get_blog_prefix($blog['blog_id'])."comments LEFT JOIN ".$wpdb->get_blog_prefix($blog['blog_id'])."posts ON comment_post_id = id WHERE post_status = 'publish' AND post_password = '' AND comment_approved = '1' AND comment_type = '' ORDER BY comment_date_gmt DESC LIMIT {$number})"; // real number is (number * # of blogs) $comments = $wpdb->get_results(implode(" UNION ALL ", $selects)." ORDER BY comment_date_gmt DESC", OBJECT); else: $comments = get_comments(array('number' => $number+1, 'status' => 'approve', 'offset' => intval($offset))); endif; $more = count($comments) > $number ? true : false; $count = 1; $output = ''; foreach((array)$comments as $comment): if($count++ == $number+1) break; $output .= '
followRules />
get_field_id('word_count').'" name="'.$this->get_field_name('word_count').'" type="text" value="'.(isset($instance['word_count']) ? intval($instance['word_count']) : null).'" size="3" />'; ?>
/>
type="checkbox" id="get_field_id('more'); ?>" name="get_field_name('more'); ?>" followRules rules="CONFLICTS WITH get_field_name('site_wide'); ?>" />