control_options['width'])) $widget_width = $widget->control_options['width']; else $widget_width = 0; // prepare matches $matches = array(); foreach($wp_registered_widgets as $i => $w) if($w['name'] == $widget->name) $matches[] = $w['id']; // find out if the widget is in the arbitrary area, and it's position (number) $number = 0; $is_arbitrary = false; if(!empty($sidebars_widgets['arbitrary'])) foreach($sidebars_widgets['arbitrary'] as $i => $value): if(in_array($value, $matches) && !$is_arbitrary) $number = $number +1; if($value == $widget->id) $is_arbitrary = true; endforeach; $wp_page_types = array( 'home' => __('Blog Home (Posts)', ATOM), 'single' => __('Single Post Pages', ATOM), 'category' => __('Category Archives', ATOM), 'tag' => __('Tag Archives', ATOM), 'author' => __('Author Archives', ATOM), 'date' => __('Date-based Archives', ATOM), 'search' => __('Search Results', ATOM)); $classes = array('visibility-options'); if(!isset($instance['visibility']) || !$instance['visibility']) $classes[] = 'hidden'; if(!is_numeric($widget->number)) $classes[] = 'needfix'; ?> " />
number)): ?>

$label): ?> id="get_field_id("page-$key"); ?>" name="get_field_name("page-$key"); ?>" />
'page', 'post_status' => 'published', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC')); $pages = get_pages(); foreach ($pages as $page): $instance["page-$page->ID"] = isset($instance["page-$page->ID"]) ? $instance["page-$page->ID"] : false; ?> ID"], true) ?> id="get_field_id("page-$page->ID"); ?>" name="get_field_name("page-$page->ID"); ?>" />

id="get_field_id('user-visitor'); ?>" name="get_field_name('user-visitor'); ?>" />
id="get_field_id('user-registered'); ?>" name="get_field_name('user-registered'); ?>" />

'.__('To include this widget into your posts or pages use one of the following shortcodes: %s', ATOM).'
', '[widget '.substr(md5($widget->id), 0, 8).'][widget "'.$widget->name.'"'.(($number > 1) ? ' number='.$number : null).']'); ?>

'page', 'post_status' => 'published', 'numberposts' => -1, 'order_by' => 'post_title', 'order' => 'ASC')); foreach ($pages as $page) $instance['page-'.$page->ID] = isset($new_instance['page-'.$page->ID]) ? 1 : 0; $instance['user-visitor'] = isset($new_instance['user-visitor']) ? 1 : 0; $instance['user-registered'] = isset($new_instance['user-registered']) ? 1 : 0; return $instance; } /** * Sets up widgets below * * @since 1.0 */ function atom_widgets_init(){ // disable some of the default Wordpress widgets, we'll replace them with better ones unregister_widget('WP_Widget_Pages'); unregister_widget('WP_Widget_Text'); unregister_widget('WP_Widget_Tag_Cloud'); unregister_widget('WP_Widget_Recent_Comments'); unregister_widget('WP_Widget_Recent_Posts'); unregister_widget('WP_Widget_Calendar'); unregister_widget('WP_Widget_Categories'); unregister_widget('WP_Widget_Archives'); unregister_widget('WP_Widget_Links'); // set up new widgets register_widget('atom_widget_pages'); register_widget('atom_widget_text'); register_widget('atom_widget_tags'); register_widget('atom_widget_authors'); register_widget('atom_widget_top_commenters'); register_widget('atom_widget_recent_comments'); register_widget('atom_widget_posts'); register_widget('atom_widget_twitter'); // register_widget('atom_widget_lifestream'); register_widget('atom_widget_login'); register_widget('atom_widget_calendar'); register_widget('atom_widget_tabs'); register_widget('atom_widget_categories'); register_widget('atom_widget_archives'); register_widget('atom_widget_links'); } /** * Alternative Pages Widget * Can also display sub-pages only * * @since 1.0 */ class atom_widget_pages extends WP_Widget{ function atom_widget_pages(){ $widget_ops = array('description' => __('Your site’s WordPress Pages', ATOM)); $this->WP_Widget(false, __('Sub/Pages', ATOM), $widget_ops); } function widget($args, $instance){ extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $sortby = empty($instance['sortby']) ? 'menu_order' : $instance['sortby']; $exclude = empty($instance['exclude']) ? '' : $instance['exclude']; $type = (empty($instance['type']) ? 'all' : strip_tags($instance['type'])); $root = (bool)$instance['root']; $depth = intval($instance['depth']); $order = 'ASC'; if ($sortby == 'menu_order') $sortby = 'menu_order, post_title'; // newest dates first if ($sortby == 'post_date' || $sortby == 'post_modified') $order = 'DESC'; $parent = 0; if ($type == 'sub'): global $post; $parent = $post; if($root): while ($parent->post_parent != 0) $parent = &get_post($parent->post_parent); $title = ''.$parent->post_title.''; endif; $parent = $parent->ID; endif; $out = wp_list_pages(apply_filters('widget_pages_args', array( 'title_li' => '', 'echo' => 0, 'sort_order' => $order, 'sort_column' => $sortby, 'depth' => $depth, 'exclude' => $exclude, 'child_of' => $parent))); if (!empty($out)){ echo $before_widget; if ($title) echo $before_title.$title.$after_title; ?> 'all', 'root' => true, 'sortby' => 'menu_order', 'title' => __("Pages", ATOM), 'exclude' => '', 'depth' => 0))); ?>





(current_user_can('edit_themes') ? __('Arbitrary text, HTML, shortcodes or PHP code', ATOM) : __('Arbitrary text, HTML or shortcodes', ATOM))); $control_ops = array('width' => 500); $this->WP_Widget(false, __('Text', ATOM), $widget_ops, $control_ops); add_action('admin_print_scripts-widgets.php', array(&$this, 'js')); } function mce_init($tinyMCEEditorID, $elementID){ // add the custom init array $initSettingsArray = array ( 'mode' => 'exact', 'elements' => $elementID, 'cleanup_on_startup' => true, 'language' => 'en', 'theme' => 'advanced', 'skin' => "wp_theme", // 'plugins' => '-table', 'content_css' => THEME_URL.'/editor-style.css', // 'editor_css' => $admin_css, // 'theme_advanced_buttons1' => 'bold,italic,underline,strikethrough,separator,bullist,numlist,link,image,hr,separator,justifyleft,justifycenter,justifyright,justifyfull', // 'theme_advanced_buttons2' => 'styleselect,fontsizeselect,charmap,forecolor,backcolor', theme_advanced_buttons1 => "bold,italic,strikethrough,|,bullist,numlist,blockquote,hr,|,justifyleft,justifycenter,justifyright,|,link,unlink,image", theme_advanced_buttons2 => "formatselect,underline,justifyfull,forecolor,backcolor,|,removeformat,|,charmap,|,outdent,indent,|,undo,redo", 'theme_advanced_buttons3' => '', 'theme_advanced_toolbar_location' => 'top', 'theme_advanced_toolbar_align' => 'left', 'theme_advanced_path' => true, 'theme_advanced_statusbar_location' => 'bottom', 'fix_list_elements' => true, 'verify_css_classes' => true, 'convert_fonts_to_spans' => true, 'inline_styles' => true, 'relative_urls' => false, 'remove_script_host' => false, 'entity_encoding' => 'raw', 'add_form_submit_trigger' => true, 'height' =>"280px", 'width' =>"500px" // 'save_callback' => 'switchEditors.saveCallback', // ,'setup' => "function(ed){ed.onSubmit.add(function(ed){ed.triggerSave(); alert('balh');});}" // 'setup' => 'function(ed){ed.onSubmit.add(function(ed){alert();});}' ); add_filter("tiny_mce_before_init", $initSettingsArray); $mce_options = ''; foreach ($initSettingsArray as $k => $v) $mce_options .= $k.':"'.$v.'", '; $mce_options = rtrim(trim($mce_options), '\n\r,'); return $mce_options; } function js(){ wp_enqueue_script('tinymce', get_bloginfo('wpurl') . "/wp-includes/js/tinymce/tiny_mce.js", array('common', 'admin-widgets', 'jquery','wp-ajax-response', 'jquery-color')); wp_enqueue_script('about-me-widget-admin-langs', get_bloginfo('wpurl') . "/wp-includes/js/tinymce/langs/wp-langs-en.js", array('tinymce')); } function widget($args, $instance){ extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $text = apply_filters('widget_text', $instance['text'], $instance); echo $before_widget; if (!empty($title)) echo $before_title.$title.$after_title; // evaluate php code if the user can edit themes if ($instance['php']): ob_start(); eval('?>'.$text); $text = ob_get_contents(); ob_end_clean(); endif; ?>
'', 'visual' => 0, 'text' => '', 'php' => true))); $title = strip_tags($instance['title']); $visual = intval($instance['visual']); $text = format_to_edit($instance['text']); $seed = rand(1, 999); ?>

class="hidden" id="text-options-">

number)): $mce_options = $this->mce_init('tinyMCEPreInit_'.$seed, $this->get_field_id('text')); ?> __("Your most used tags in cloud format", ATOM)); $this->WP_Widget(false, __('Tag Cloud', ATOM), $widget_ops); } // calculate the tag color based on tag importance, start & end gradient colors (props to konforce from StackOverflow) function get_tag_color($weight, $mincolor, $maxcolor){ $weight = $weight/100; $mincolor = hexdec($mincolor); $maxcolor = hexdec($maxcolor); $r1 = ($mincolor >> 16) & 0xff; $g1 = ($mincolor >> 8) & 0xff; $b1 = $mincolor & 0xff; $r2 = ($maxcolor >> 16) & 0xff; $g2 = ($maxcolor >> 8) & 0xff; $b2 = $maxcolor & 0xff; $r = $r1 + ($r2 - $r1) * $weight; $g = $g1 + ($g2 - $g1) * $weight; $b = $b1 + ($b2 - $b1) * $weight; return sprintf("%06x", (($r << 16) | ($g << 8) | $b)); } // almost the same as WP's function, only added color styles & removed irrelevant arguments function generate_tag_cloud($tags, $args = ''){ $defaults = array( 'smallest' => 8, 'largest' => 22, 'number' => 45, 'gradient_start' => false, 'gradient_end' => false, 'order' => 'ASC', 'topic_count_text_callback' => 'default_topic_count_text', 'topic_count_scale_callback' => 'default_topic_count_scale' ); if (!isset($args['topic_count_text_callback']) && isset($args['single_text']) && isset($args['multiple_text'])): $body = 'return sprintf(_n('.var_export($args['single_text'], true).', '.var_export($args['multiple_text'], true).', $count), number_format_i18n($count));'; $args['topic_count_text_callback'] = create_function('$count', $body); endif; $args = wp_parse_args($args, $defaults); extract($args); if (empty($tags)) return; $tags_sorted = apply_filters('tag_cloud_sort', $tags, $args); if ($tags_sorted != $tags) { // the tags have been sorted by a plugin $tags = $tags_sorted; unset($tags_sorted); } else { if ('RAND' == $order){ shuffle($tags); } else { // SQL cannot save you; this is a second (potentially different) sort on a subset of data. uasort($tags, create_function('$a, $b', 'return strnatcasecmp($a->name, $b->name);')); if ('DESC' == $order) $tags = array_reverse($tags, true); } } if ($number > 0) $tags = array_slice($tags, 0, $number); $counts = array(); $real_counts = array(); // For the alt tag foreach ((array) $tags as $key => $tag): $real_counts[$key] = $tag->count; $counts[$key] = $topic_count_scale_callback($tag->count); endforeach; $min_count = min($counts); $spread = max($counts) - $min_count; if ($spread <= 0) $spread = 1; $font_spread = $largest - $smallest; if ($font_spread < 0) $font_spread = 1; $font_step = $font_spread / $spread; $a = array(); foreach ($tags as $key => $tag): $count = $counts[$key]; $real_count = $real_counts[$key]; if($gradient_start && $gradient_end): if ($largest == $smallest) $tag_weight = $largest; else $tag_weight = ($smallest+(($count-$min_count)*$font_step)); $diff = $largest-$smallest; if ($diff <= 0) $diff = 1; $color_weight = round(99*($tag_weight-$smallest)/($diff)+1); $tag_color = $this->get_tag_color($color_weight, $gradient_start, $gradient_end); endif; $tag_link = '#' != $tag->link ? esc_url($tag->link) : '#'; //$tag_id = isset($tags[$key]->id) ? $tags[$key]->id : $key; $size = ($smallest+(($count-$min_count)*$font_step)); $name = $tags[$key]->name; if($size > 15) $name = ''.$name.''; // bold if size > 15pt $a[] = "slug."\" title=\"".esc_attr($topic_count_text_callback($real_count))."\" style=\"font-size:".sprintf("%01.1f", $size)."pt;".(isset($tag_color) ? "color:#$tag_color;" : null)."\">".$name.""; endforeach; return apply_filters('wp_generate_tag_cloud', join("\n", $a), $tags, $args); } function tag_cloud($args = ''){ $defaults = array( 'smallest' => 8, 'largest' => 22, 'number' => 45, 'order' => 'ASC', // ASC/DESC/RAND -- @todo: maybe add a option for this? 'exclude' => '', 'include' => '', 'taxonomy' => 'post_tag'); $args = wp_parse_args($args, $defaults); $tags = get_terms($args['taxonomy'], array_merge($args, array('orderby' => 'count', 'order' => 'DESC'))); // Always query top tags if (empty($tags)) return; foreach ($tags as $key => $tag): $link = get_term_link(intval($tag->term_id), $args['taxonomy']); if (is_wp_error($link)) return false; $tags[$key]->link = $link; $tags[$key]->id = $tag->term_id; endforeach; $output = $this->generate_tag_cloud($tags, $args); // Here's where those top tags get sorted according to $args $output = apply_filters('wp_tag_cloud', $output, $args); return $output; } function widget($args, $instance){ extract($args); $current_taxonomy = $this->_get_current_taxonomy($instance); $number = empty($instance['number']) ? 45 : $instance['number']; $smallest = empty($instance['smallest']) ? 8 : $instance['smallest']; $largest = empty($instance['largest']) ? 22 : $instance['largest']; $gradient_start = esc_attr($instance['gradient_start']); $gradient_end = esc_attr($instance['gradient_end']); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); echo $before_widget; if ($title) echo $before_title.$title.$after_title; echo '
'; echo $this->tag_cloud(apply_filters('widget_tag_cloud_args', array( 'taxonomy' => $current_taxonomy, 'number' => $number, 'smallest' => $smallest, 'largest' => $largest, 'gradient_start' => $gradient_start, 'gradient_end' => $gradient_end ))); echo "
\n"; echo $after_widget; } function update($new_instance, $old_instance) { $instance['title'] = strip_tags(stripslashes($new_instance['title'])); $instance['taxonomy'] = stripslashes($new_instance['taxonomy']); $instance['number'] = intval($new_instance['number']); $instance['smallest'] = intval($new_instance['smallest']); $instance['largest'] = intval($new_instance['largest']); $instance['gradient_start'] = strip_tags($new_instance['gradient_start']); $instance['gradient_end'] = strip_tags($new_instance['gradient_end']); return $instance; } function form($instance){ $instance = wp_parse_args((array)$instance, apply_filters('atom_widget_tags_defaults', array( 'title' => __("Tags"), 'number' => 45, 'smallest' => 8, 'largest' => 22, 'gradient_start' => 'cccccc', 'gradient_end' => '333333'))); $current_taxonomy = $this->_get_current_taxonomy($instance); ?>


pt

pt

__("A list of authors from your blog", ATOM)); $this->WP_Widget(false, __('Authors', ATOM), $widget_ops); // flush cache when posts are changed add_action('save_post', array(&$this, 'flush_cache')); add_action('deleted_post', array(&$this, 'flush_cache')); add_action('switch_theme', array(&$this, 'flush_cache')); } function get_authors($exclude_admin = true) { global $wpdb; /** @todo Move select to get_authors(). */ $users = get_users_of_blog(); $author_ids = array(); foreach ((array) $users as $user) $author_ids[] = $user->user_id; if (count($author_ids) > 0): $author_ids = implode(',', $author_ids); $authors = $wpdb->get_results($wpdb->prepare("SELECT ID, user_nicename from $wpdb->users WHERE ID IN($author_ids) ".($exclude_admin ? "AND user_login <> 'admin' " : '')."ORDER BY display_name")); else: $authors = array(); endif; $author_count = array(); foreach ((array)$wpdb->get_results($wpdb->prepare("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND ".get_private_posts_cap_sql('post')." GROUP BY post_author")) as $row) $author_count[$row->post_author] = $row->count; $output = array(); $i = 0; foreach ((array)$authors as $author): $output[$i] = (array)get_userdata($author->ID); // add another field with the number of posts $output[$i]['post_count'] = (isset($author_count[$author->ID])) ? $author_count[$author->ID] : 0; $i++; endforeach; return $output; } function flush_cache(){ wp_cache_delete('widget_authors', 'widget'); } function widget($args, $instance){ $cache = wp_cache_get('widget_authors', 'widget'); if (!is_array($cache)) $cache = array(); if (isset($cache[$args['widget_id']])): echo $cache[$args['widget_id']]; return; endif; extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $output = $before_widget; if ($title) $output .= $before_title.$title.$after_title; $show_avatars = ($instance['mode'] != 'brief' && $instance['mode'] != 'detailed'); $details = ($instance['mode'] == 'detailed' || $instance['mode'] == 'full'); $sort = $instance['sort_by']; $authors = $this->get_authors($instance['exclude_admin']); if(!empty($authors)): $authors = atom_sort_array($authors, $sort, ($sort == 'display_name' ? 'ASC' : 'DESC')); $output .= ''; else: $output = '

'.__("No Authors Found", ATOM).'

'; endif; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('widget_authors', $cache, 'widget'); } function update($new_instance, $old_instance){ $instance['title'] = strip_tags(stripslashes($new_instance['title'])); $instance['mode'] = stripslashes($new_instance['mode']); $instance['hide_empty'] = !empty($new_instance['hide_empty']) ? 1 : 0; $instance['sort_by'] = stripslashes($new_instance['sort_by']); $instance['exclude_admin'] = !empty($new_instance['exclude_admin']) ? 1 : 0; $instance['avatar_size'] = intval($new_instance['avatar_size']); $this->flush_cache(); return $instance; } function form($instance){ $instance = wp_parse_args((array)$instance, apply_filters('atom_widget_authors_defaults', array( 'title' => __("Authors", ATOM), 'mode' => 'full', 'avatar_size' => 48, 'sort_by' => 'post_count', 'hide_empty' => true, 'exclude_admin' => false))); ?>

__("People who frequently comment the blog", ATOM)); $this->WP_Widget(false, __('Top Commenters', ATOM), $widget_ops); // 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); // 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 = get_option($this->option_name); foreach($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((isset($options['country_flag'])) && is_active_widget(false, $id, $this->id_base) && !defined('COUNTRY_FLAGS')) define('COUNTRY_FLAGS', TRUE); endforeach; } function flush_cache(){ wp_cache_delete('widget_top_commenters', 'widget'); } function widget($args, $instance){ global $wpdb; $cache = wp_cache_get('widget_top_commenters', 'widget'); if (!is_array($cache)) $cache = array(); if (isset($cache[$args['widget_id']])): echo $cache[$args['widget_id']]; return; endif; extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $output = $before_widget; $sql = "SELECT comment_author, comment_author_email, comment_author_url, comment_author_IP, count(1) as counter from $wpdb->comments WHERE comment_approved = '1' AND comment_type != 'pingback'"; // group by (only the first two are used): // - comment_author (name, default) // - comment_author_email (same users may have different emails) // - comment_author_url (people can have multiple sites) // - comment_author_IP (really useless, lots of people have dynamic IPs) $sql .= " GROUP BY comment_author, comment_author_email ORDER BY counter DESC, comment_date DESC LIMIT ".intval($instance['number']); $commenters = $wpdb->get_results($wpdb->prepare($sql)); if ($title) $output .= $before_title.$title.$after_title; if ($commenters): $output .= ''; else: $output .= '

'.__('Nobody left any comments :(', ATOM).'

'; endif; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('widget_top_commenters', $cache, 'widget'); } function update($new_instance, $old_instance){ $instance['title'] = strip_tags(stripslashes($new_instance['title'])); $instance['number'] = intval($new_instance['number']); $instance['mode'] = stripslashes($new_instance['mode']); $instance['avatar_size'] = intval($new_instance['avatar_size']); $instance['country_flag'] = !empty($new_instance['country_flag']) ? 1 : 0; $instance['nofollow'] = !empty($new_instance['nofollow']) ? 1 : 0; if($instance['number'] < 1) $instance['number'] = 1; if($instance['number'] > 50) $instance['number'] = 50; $this->flush_cache(); return $instance; } function form($instance){ $instance = wp_parse_args((array)$instance, apply_filters('atom_widget_top_commenters_defaults', array( 'title' => __("Top Commenters", ATOM), 'number' => 12, 'mode' => 'avatars', 'avatar_size' => 72, 'country_flag' => false, 'nofollow' => false))); ?>

__('The most recent comments', ATOM)); $this->WP_Widget(false, __('Recent Comments', ATOM), $widget_ops); add_action('init', array(&$this, 'ajax'), 99); // 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() add_action('atom_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 = get_option($this->option_name); foreach($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(($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 = get_option($this->option_name); foreach($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)): ?> jQuery("# a.more").click(function(){ $link = jQuery(this); $offset = parseInt($link.attr('rel')); jQuery.ajax({ type: "GET", url: "", data: { id: "", number: , avatars: , avatar_size: , word_count: , country_flag: , offset: $offset, atom_get_comments: 1 }, beforeSend: function() { $link.addClass("loading"); }, complete: function() { $link.removeClass("loading"); }, success: function(response){ var obj = eval('('+response+')'); // append to list & update tab container height (if we're inside a tabbed widget) if(obj.output != '') jQuery(obj.output).appendTo("# ul").hide().animate({ "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', obj.offset); // no more data? if(!obj.more) $link.hide(); } }); return false; }); get_comments($number, $avatars, $avatar_size, $word_count, $flags, $offset); $offset = $offset + $number; $next = ($this->get_comments($number, $avatars, $avatar_size, $word_count, $flags, $offset)) ? true : false; echo json_encode(array('output' => $output, 'more' => $next, 'offset' => $offset)); exit(); endif; } function get_comments($number, $avatars, $avatar_size, $word_count, $flags, $offset = 0){ $comments = get_comments(array('number' => $number, 'status' => 'approve', 'offset' => intval($offset))); $count = 0; $output = ''; foreach ((array)$comments as $comment): $count++; $output .= ''; if($avatars) $output .= atom_get_avatar($comment->comment_author_email, $avatar_size, '', $comment->comment_author); $output .= ''; if($flags) if(!$country = atom_get_country($comment->comment_author_IP)) $flags = false; $output .= ''.($flags ? ' ' : null).$comment->comment_author.''; if($word_count != 0): // only allow a few tags, since all the content goes inside a link - needs more testing $content = atom_filter_content($comment->comment_content, false, false, $word_count, array('abbr', 'b', 'em', 'i', 'strong'), true, true); $output .= ''.convert_smilies($content).''; endif; $output .= ''.atom_time_since(abs(strtotime($comment->comment_date . " GMT"))).''; $output .= ''; $output .= ''; endforeach; return $output; } function widget($args, $instance){ global $comments, $comment; $cache = wp_cache_get('widget_recent_comments', 'widget'); if (!is_array($cache)) $cache = array(); if (isset($cache[$args['widget_id']])): echo $cache[$args['widget_id']]; return; endif; extract($args, EXTR_SKIP); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $number = intval($instance['number']); $avatars = $instance['avatars']; $avatar_size = intval($instance['avatar_size']); $word_count = intval($instance['word_count']); $flags = $instance['country_flag']; $output = $before_widget; if ($title) $output .= $before_title.$title.$after_title; $id = "instance-".$this->id; $comments = $this->get_comments($number, $avatars, $avatar_size, $word_count, $flags); if ($comments): $next = false; $next = ($this->get_comments($number, $avatars, $avatar_size, $word_count, $flags, $number) != ''); $output .= ''; if($instance['more'] && $next): $output .= '
'.__("Show More", ATOM).'
'; endif; else: $output .= '

'.__("Nothing to show :(", ATOM).'

'; endif; $output .= $after_widget; echo $output; $cache[$args['widget_id']] = $output; wp_cache_set('widget_recent_comments', $cache, 'widget'); } function update($new_instance, $old_instance){ $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['number'] = intval($new_instance['number']); if ($instance['number'] < 1) $instance['number'] = 1; if ($instance['number'] > 20) $instance['number'] = 20; $instance['word_count'] = intval($new_instance['word_count']); $instance['avatars'] = !empty($new_instance['avatars']) ? 1 : 0; $instance['avatar_size'] = intval($new_instance['avatar_size']); $instance['country_flag'] = !empty($new_instance['country_flag']) ? 1 : 0; $instance['more'] = !empty($new_instance['more']) ? 1 : 0; $this->flush_cache(); return $instance; } function form($instance){ $instance = wp_parse_args((array)$instance, apply_filters('atom_widget_recent_comments_defaults', array( 'title' => __("Recent Comments", ATOM), 'number' => 5, 'word_count' => 20, 'avatars' => true, 'avatar_size' => 48, 'country_flag' => false, 'more' => true))); ?>

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" />'; ?>

__('List posts based on filters you choose', ATOM)); $control_ops = array('width' => 500); $this->WP_Widget(false, __('Posts', ATOM), $widget_ops, $control_ops); add_action('init', array(&$this, 'ajax'), 99); add_action('atom_set_thumb_sizes', array(&$this, 'set_thumb_size')); // include in jQuery(document).ready() add_action('atom_jquery_init', array(&$this, 'js')); // flush cache when posts are changed add_action('save_post', array(&$this, 'flush_cache')); add_action('deleted_post', array(&$this, 'flush_cache')); add_action('switch_theme', array(&$this, 'flush_cache')); } function set_thumb_size(){ // we need to process all instances because this function gets to run only once $widget_settings = get_option($this->option_name); foreach($widget_settings as $instance => $options): // identify instance $id = $this->id_base.'-'.$instance; // register thumb size if the widget is active if(is_active_widget(false, $id, $this->id_base)) add_image_size($id, $options['thumb_size'], $options['thumb_size'], true); endforeach; } function js(){ // we need to process all instances because this function gets to run only once $widget_settings = get_option($this->option_name); foreach($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)): ?> $("# a.more").click(function(){ $link = $(this); $offset = parseInt($link.attr('rel')); $.ajax({ type: "GET", url: "", data: { id: "", post_type: "", mode: "", order: "", category: , number: , thumb_size: , word_count: , offset: $offset, atom_get_posts: 1 }, beforeSend: function() { $link.addClass("loading"); }, complete: function() { $link.removeClass("loading"); }, success: function(response){ var obj = eval('('+response+')'); // append to list & update tab container height (if we're inside a tabbed widget) if(obj.output != '') $(obj.output).appendTo("# ul").hide().animate({ "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', obj.offset); // no more data? if(!obj.more) $link.hide(); } }); return false; }); get_posts($id, $number, $post_type, $mode, $order, $category, $thumb_size, $word_count, $offset); $offset = $offset + $number; $next = ($this->get_posts($id, $number, $post_type, $mode, $order, $category, $thumb_size, $word_count, $offset)) ? true : false; echo json_encode(array('output' => $output, 'more' => $next, 'offset' => $offset)); exit(); endif; } function flush_cache(){ wp_cache_delete('widget_posts', 'widget'); } function get_posts($id, $number, $post_type, $mode, $order, $category, $thumb_size, $word_count, $offset = 0){ global $post; // build query $posts = new WP_Query(); $query = array('orderby' => $order, 'post_type' => $post_type, 'caller_get_posts' => 1, 'posts_per_page' => $number, 'offset' => $offset); if($category != 0) $query['cat'] = $category; $posts->query($query); $output = ''; $show_thumbs = ($mode == 'images' || $mode == 'full') ? true : false; $count = 0; while ($posts->have_posts()): $posts->the_post(); $count++; if($mode != 'images') $title = sprintf(__('%s comments', ATOM), get_comments_number()); else $title = the_title('', '', false).' ('.get_comments_number().')'; $output .= ''; if($show_thumbs) $output .= atom_get_post_thumb($post->ID, str_replace('instance-', '', $id)); if($mode != 'images'): // trim the excerpt to $word_count and retrieve it //add_filter("excerpt_length", create_function("", "return $word_count; ")); //$content = get_the_excerpt(); // better build the content ourselves, since get_the_excerpt() can return manually made excerpts with all kind of weird things inside them $content = atom_filter_content(get_the_content(), false, false, $word_count, array('abbr', 'b', 'em', 'i', 'strong'), false, true); $output .= ''; $output .= ''.the_title('', '', false).''; if($mode != 'brief'): if($word_count != 0) $output .= ''.convert_smilies($content).''; $output .= ''.atom_get_post_date().''; endif; $output .= ''; endif; $output .= ''; endwhile; wp_reset_query(); return $output; } function widget($args, $instance){ $cache = wp_cache_get('widget_posts', 'widget'); if (!is_array($cache)) $cache = array(); if (isset($cache[$args['widget_id']])): echo $cache[$args['widget_id']]; return; endif; extract($args, EXTR_SKIP); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $post_type = esc_attr($instance['post_type']); $mode = esc_attr($instance['mode']); $order = esc_attr($instance['order_by']); $category = intval($instance['category']); $number = intval($instance['number']); $thumb_size = intval($instance['thumb_size']); $word_count = intval($instance['word_count']); $output = $before_widget; if ($title) $output .= $before_title.$title.$after_title; $id = "instance-".$this->id; $posts = $this->get_posts($this->id, $number, $post_type, $mode, $order, $category, $thumb_size, $word_count); if($posts): $next = false; $next = ($this->get_posts($this->id, $number, $post_type, $mode, $order, $category, $thumb_size, $word_count, $number) != ''); $output .= ''; if($instance['more'] && $next): $output .= ''; endif; else: $output .= '

'.__("Nothing to show :(", ATOM).'

'; endif; $output .= $after_widget; echo $output; if($order != 'rand'): // we can't cache random posts (they wouldn't be random :) $cache[$args['widget_id']] = $output; wp_cache_set('widget_posts', $cache, 'widget'); endif; } function update($new_instance, $old_instance){ $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['post_type'] = stripslashes($new_instance['post_type']); $instance['mode'] = stripslashes($new_instance['mode']); $instance['category'] = intval($new_instance['category']); $instance['order_by'] = stripslashes($new_instance['order_by']); $instance['number'] = intval($new_instance['number']); if ($instance['number'] < 1) $instance['number'] = 1; if ($instance['number'] > 20) $instance['number'] = 20; $instance['word_count'] = intval($new_instance['word_count']); $instance['thumb_size'] = intval($new_instance['thumb_size']); $instance['more'] = !empty($new_instance['more']) ? 1 : 0; $this->flush_cache(); return $instance; } function form($instance){ $instance = wp_parse_args((array)$instance, apply_filters('atom_widget_posts_defaults', array( 'title' => __("Recent Posts", ATOM), 'post_type' => 'post', 'mode' => 'full', 'order_by' => 'date', 'category' => 0, 'number' => 5, 'word_count' => 20, 'thumb_size' => 48, 'more' => true))); ?>

$this->get_field_name('category'), 'selected' => intval($instance['category']), 'show_option_all' => __('-- All categories --', ATOM), 'hide_empty' => 0, 'orderby' => 'name', 'show_count' => 1, 'echo' => 0, 'class' => 'widefat', 'hierarchical' => 1)); ?>


'; ?>



Important: %1$s sized thumbnails have to be created if you just added this widget, or if you\'re changing the thumbnail size. Read more about thumbnail sizes %2$s', ATOM), intval($instance['thumb_size']).'x'.intval($instance['thumb_size']), ''.__("here", ATOM).''); ?>

__("Your latest Twitter updates", ATOM)); $this->WP_Widget(false, __('Twitter', ATOM), $widget_ops); add_action('init', array(&$this, 'ajax'), 99); // include in jQuery(document).ready() add_action('atom_jquery_init', array(&$this, 'js')); } function ajax(){ if(isset($_GET['atom_get_twitter_data'])): $this->display_tweets(strip_tags(stripslashes($_GET['widget_id'])), strip_tags(stripslashes(($_GET['twituser']))), intval($_GET['twitcount']), false, $_GET['showinfo']); exit(); endif; } function js(){ // we need to process all instances because this function gets to run only once $widget_settings = get_option($this->option_name); foreach($widget_settings as $instance => $options): // identify instance $id = $this->id_base.'-'.$instance; $block_id = 'instance-'.$id; if (false === ($data = get_transient($block_id)) && is_active_widget(false, $id, $this->id_base)): ?> jQuery.ajax({ type: "GET", url: "", data: { widget_id: '', twituser: '', twitcount: , showinfo: , atom_get_twitter_data: 1 }, beforeSend: function() { }, complete: function() { }, success: function(response){ jQuery("# .latest-tweets").hide().html(response).slideDown(333); } }); '; if(is_string($error)) printf(__("Twitter returned error: %s", ATOM), $error); else _e("Could not retrieve tweets. Possible reasons:", ATOM); echo '

'; if(!is_string($error)): echo '