~canonical-sysadmins/wordpress/3.9.x

« back to all changes in this revision

Viewing changes to wp-includes/default-widgets.php

  • Committer: Chris Jones
  • Date: 2010-01-19 13:17:33 UTC
  • Revision ID: cmsj@tenshu.net-20100119131733-rf31jv9k1v0xzo2h
[CJ] Import wordpress 2.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
376
376
 
377
377
        function widget( $args, $instance ) {
378
378
                extract($args);
379
 
                $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
380
 
                $text = apply_filters( 'widget_text', $instance['text'] );
 
379
                $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance );
 
380
                $text = apply_filters( 'widget_text', $instance['text'], $instance );
381
381
                echo $before_widget;
382
382
                if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
383
383
                        <div class="textwidget"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div>
391
391
                if ( current_user_can('unfiltered_html') )
392
392
                        $instance['text'] =  $new_instance['text'];
393
393
                else
394
 
                        $instance['text'] = wp_filter_post_kses( $new_instance['text'] );
 
394
                        $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
395
395
                $instance['filter'] = isset($new_instance['filter']);
396
396
                return $instance;
397
397
        }
406
406
 
407
407
                <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
408
408
 
409
 
                <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked($instance['filter']); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs.'); ?></label></p>
 
409
                <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs.'); ?></label></p>
410
410
<?php
411
411
        }
412
412
}
483
483
                //Defaults
484
484
                $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
485
485
                $title = esc_attr( $instance['title'] );
486
 
                $count = (bool) $instance['count'];
487
 
                $hierarchical = (bool) $instance['hierarchical'];
488
 
                $dropdown = (bool) $instance['dropdown'];
 
486
                $count = isset($instance['count']) ? (bool) $instance['count'] :false;
 
487
                $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
 
488
                $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
489
489
?>
490
490
                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
491
491
                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
579
579
        }
580
580
 
581
581
        function form( $instance ) {
582
 
                $title = esc_attr($instance['title']);
583
 
                if ( !$number = (int) $instance['number'] )
 
582
                $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
 
583
                if ( !isset($instance['number']) || !$number = (int) $instance['number'] )
584
584
                        $number = 5;
585
585
?>
586
586
                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
609
609
                        add_action( 'wp_head', array(&$this, 'recent_comments_style') );
610
610
 
611
611
                add_action( 'comment_post', array(&$this, 'flush_widget_cache') );
612
 
                add_action( 'wp_set_comment_status', array(&$this, 'flush_widget_cache') );
 
612
                add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') );
613
613
        }
614
614
 
615
615
        function recent_comments_style() { ?>
634
634
                        $number = 15;
635
635
 
636
636
                if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
637
 
                        $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 15");
 
637
                        $comments = $wpdb->get_results("SELECT $wpdb->comments.* FROM $wpdb->comments JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND post_status = 'publish' ORDER BY comment_date_gmt DESC LIMIT 15");
638
638
                        wp_cache_add( 'recent_comments', $comments, 'widget' );
639
639
                }
640
640
 
732
732
                        echo $before_title . $title . $after_title;
733
733
                wp_widget_rss_output( $rss, $instance );
734
734
                echo $after_widget;
 
735
 
 
736
                if ( ! is_wp_error($rss) )
 
737
                        $rss->__destruct();
 
738
                unset($rss);
735
739
        }
736
740
 
737
741
        function update($new_instance, $old_instance) {
770
774
        if ( is_wp_error($rss) ) {
771
775
                if ( is_admin() || current_user_can('manage_options') )
772
776
                        echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
773
 
 
774
777
                return;
775
778
        }
776
779
 
787
790
 
788
791
        if ( !$rss->get_item_quantity() ) {
789
792
                echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
 
793
                $rss->__destruct(); 
 
794
                unset($rss);
790
795
                return;
791
796
        }
792
797
 
838
843
                }
839
844
        }
840
845
        echo '</ul>';
 
846
        $rss->__destruct(); 
 
847
        unset($rss);
841
848
}
842
849
 
843
850
 
946
953
                        $link = esc_url(strip_tags($rss->get_permalink()));
947
954
                        while ( stristr($link, 'http') != $link )
948
955
                                $link = substr($link, 1);
 
956
 
 
957
                        $rss->__destruct();
 
958
                        unset($rss);
949
959
                }
950
960
        }
951
961
 
985
995
        function form( $instance ) {
986
996
?>
987
997
        <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
988
 
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" /></p>
 
998
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
989
999
<?php
990
1000
        }
991
1001
}