'blogs', 'description' => _a('A list of site blogs')); $control_ops = array('width' => 500); $this->WP_Widget('atom-blogs', _a('Network Blogs'), $widget_ops, $control_ops); atom_add('ajax_requests', array(&$this, 'ajax')); // include in jQuery(document).ready() atom_add('jquery_init', array(&$this, 'js')); // flush cache when blog is updated add_action('wpmu_blog_updated', array(&$this, 'flush_cache')); } function flush_cache(){ wp_cache_delete('widget_blogs', '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'] && is_active_widget(false, $id, $this->id_base)): ?> $("#").delegate("a.more", "click", function(){ event.preventDefault(); $.ajax({ type: "GET", url: "", data: { instance: , offset: parseInt($(this).attr('rel')), _ajax_nonce: "", atom: "get_blogs" }, 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_blogs($settings, $next, $offset); $offset = $offset + $settings['number']; echo json_encode(array('output' => $output, 'more' => $next, 'offset' => $offset)); exit(); endif; } function template(){ return "\n" ." {AVATAR}\n" ." \n" ." {TITLE}\n" ." {DESCRIPTION}\n" ." Updated {UPDATED}\n" ." \n" ."\n"; } function get_blogs($args, &$more, $offset = 0){ extract($args); $sites = atom_get_sites(array( 'exclude_id' => $exclude, 'exclude_mature' => $exclude_mature, 'sort_column' => $order_by, 'order' => ($order_by == 'id') ? 'ASC' : 'DESC', 'limit_results' => $number + 1, 'start' => $offset )); // because mysql rand() is slowwwww if($order_by == 'rand') shuffle($sites); $more = count($sites) > $number ? true : false; $count = 1; $output = ''; foreach((array)$sites as $site): if($count++ == $number+1) break; $output .= '