- foreach ( (array) $_POST['widget-text'] as $widget_number => $widget_text ) {
- if ( !isset($widget_text['text']) && isset($options[$widget_number]) ) // user clicked cancel
- continue;
- $title = strip_tags(stripslashes($widget_text['title']));
- if ( current_user_can('unfiltered_html') )
- $text = stripslashes( $widget_text['text'] );
- else
- $text = stripslashes(wp_filter_post_kses( $widget_text['text'] ));
- $options[$widget_number] = compact( 'title', 'text' );
- }
-
- update_option('widget_text', $options);
- $updated = true;
- }
-
- if ( -1 == $number ) {
- $title = '';
- $text = '';
- $number = '%i%';
- } else {
- $title = attribute_escape($options[$number]['title']);
- $text = format_to_edit($options[$number]['text']);
- }
-?>
- <p>
- <input class="widefat" id="text-title-<?php echo $number; ?>" name="widget-text[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
- <textarea class="widefat" rows="16" cols="20" id="text-text-<?php echo $number; ?>" name="widget-text[<?php echo $number; ?>][text]"><?php echo $text; ?></textarea>
- <input type="hidden" name="widget-text[<?php echo $number; ?>][submit]" value="1" />
- </p>
-<?php
-}
-
-function wp_widget_text_register() {
- if ( !$options = get_option('widget_text') )
- $options = array();
- $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
- $control_ops = array('width' => 400, 'height' => 350, 'id_base' => 'text');
- $name = __('Text');
-
- $id = false;
- foreach ( array_keys($options) as $o ) {
- // Old widgets can have null values for some reason
- if ( !isset($options[$o]['title']) || !isset($options[$o]['text']) )
- continue;
- $id = "text-$o"; // Never never never translate an id
- wp_register_sidebar_widget($id, $name, 'wp_widget_text', $widget_ops, array( 'number' => $o ));
- wp_register_widget_control($id, $name, 'wp_widget_text_control', $control_ops, array( 'number' => $o ));
- }
-
- // If there are none, we register the widget's existance with a generic template
- if ( !$id ) {
- wp_register_sidebar_widget( 'text-1', $name, 'wp_widget_text', $widget_ops, array( 'number' => -1 ) );
- wp_register_widget_control( 'text-1', $name, 'wp_widget_text_control', $control_ops, array( 'number' => -1 ) );
- }
-}
-
-// See large comment section at end of this file
-function wp_widget_categories($args, $widget_args = 1) {
- extract($args, EXTR_SKIP);
- if ( is_numeric($widget_args) )
- $widget_args = array( 'number' => $widget_args );
- $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
- extract($widget_args, EXTR_SKIP);
-
- $options = get_option('widget_categories');
- if ( !isset($options[$number]) )
- return;
-
- $c = $options[$number]['count'] ? '1' : '0';
- $h = $options[$number]['hierarchical'] ? '1' : '0';
- $d = $options[$number]['dropdown'] ? '1' : '0';
-
- $title = empty($options[$number]['title']) ? __('Categories') : apply_filters('widget_title', $options[$number]['title']);
-
- echo $before_widget;
- echo $before_title . $title . $after_title;
-
- $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
-
- if ( $d ) {
- $cat_args['show_option_none'] = __('Select Category');
- wp_dropdown_categories($cat_args);
-?>
-
-<script type='text/javascript'>
-/* <![CDATA[ */
- var dropdown = document.getElementById("cat");
- function onCatChange() {
- if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
- location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
- }
- }
- dropdown.onchange = onCatChange;
-/* ]]> */
-</script>
-
-<?php
- } else {
-?>
- <ul>
- <?php
- $cat_args['title_li'] = '';
- wp_list_categories($cat_args);
- ?>
- </ul>
-<?php
- }
-
- echo $after_widget;
-}
-
-function wp_widget_categories_control( $widget_args ) {
- global $wp_registered_widgets;
- static $updated = false;
-
- if ( is_numeric($widget_args) )
- $widget_args = array( 'number' => $widget_args );
- $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
- extract($widget_args, EXTR_SKIP);
-
- $options = get_option('widget_categories');
-
- if ( !is_array( $options ) )
- $options = array();
-
- if ( !$updated && !empty($_POST['sidebar']) ) {
- $sidebar = (string) $_POST['sidebar'];
-
- $sidebars_widgets = wp_get_sidebars_widgets();
- if ( isset($sidebars_widgets[$sidebar]) )
- $this_sidebar =& $sidebars_widgets[$sidebar];
- else
- $this_sidebar = array();
-
- foreach ( $this_sidebar as $_widget_id ) {
- if ( 'wp_widget_categories' == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) {
- $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
- if ( !in_array( "categories-$widget_number", $_POST['widget-id'] ) ) // the widget has been removed.
- unset($options[$widget_number]);
- }
- }
-
- foreach ( (array) $_POST['widget-categories'] as $widget_number => $widget_cat ) {
- if ( !isset($widget_cat['title']) && isset($options[$widget_number]) ) // user clicked cancel
- continue;
- $title = trim(strip_tags(stripslashes($widget_cat['title'])));
- $count = isset($widget_cat['count']);
- $hierarchical = isset($widget_cat['hierarchical']);
- $dropdown = isset($widget_cat['dropdown']);
- $options[$widget_number] = compact( 'title', 'count', 'hierarchical', 'dropdown' );
- }
-
- update_option('widget_categories', $options);
- $updated = true;
- }
-
- if ( -1 == $number ) {
- $title = '';
- $count = false;
- $hierarchical = false;
- $dropdown = false;
- $number = '%i%';
- } else {
- $title = attribute_escape( $options[$number]['title'] );
- $count = (bool) $options[$number]['count'];
- $hierarchical = (bool) $options[$number]['hierarchical'];
- $dropdown = (bool) $options[$number]['dropdown'];
- }
-?>
- <p>
- <label for="categories-title-<?php echo $number; ?>">
- <?php _e( 'Title:' ); ?>
- <input class="widefat" id="categories-title-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" />
- </label>
- </p>
-
- <p>
- <label for="categories-dropdown-<?php echo $number; ?>">
- <input type="checkbox" class="checkbox" id="categories-dropdown-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][dropdown]"<?php checked( $dropdown, true ); ?> />
- <?php _e( 'Show as dropdown' ); ?>
- </label>
- <br />
- <label for="categories-count-<?php echo $number; ?>">
- <input type="checkbox" class="checkbox" id="categories-count-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][count]"<?php checked( $count, true ); ?> />
- <?php _e( 'Show post counts' ); ?>
- </label>
- <br />
- <label for="categories-hierarchical-<?php echo $number; ?>">
- <input type="checkbox" class="checkbox" id="categories-hierarchical-<?php echo $number; ?>" name="widget-categories[<?php echo $number; ?>][hierarchical]"<?php checked( $hierarchical, true ); ?> />
- <?php _e( 'Show hierarchy' ); ?>
- </label>
- </p>
-
- <input type="hidden" name="widget-categories[<?php echo $number; ?>][submit]" value="1" />
-<?php
-}
-
-function wp_widget_categories_register() {
- if ( !$options = get_option( 'widget_categories' ) )
- $options = array();
-
- if ( isset($options['title']) )
- $options = wp_widget_categories_upgrade();
-
- $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
-
- $name = __( 'Categories' );
-
- $id = false;
- foreach ( array_keys($options) as $o ) {
- // Old widgets can have null values for some reason
- if ( !isset($options[$o]['title']) )
- continue;
- $id = "categories-$o";
- wp_register_sidebar_widget( $id, $name, 'wp_widget_categories', $widget_ops, array( 'number' => $o ) );
- wp_register_widget_control( $id, $name, 'wp_widget_categories_control', array( 'id_base' => 'categories' ), array( 'number' => $o ) );
- }
-
- // If there are none, we register the widget's existance with a generic template
- if ( !$id ) {
- wp_register_sidebar_widget( 'categories-1', $name, 'wp_widget_categories', $widget_ops, array( 'number' => -1 ) );
- wp_register_widget_control( 'categories-1', $name, 'wp_widget_categories_control', array( 'id_base' => 'categories' ), array( 'number' => -1 ) );
- }
-}
-
-function wp_widget_categories_upgrade() {
- $options = get_option( 'widget_categories' );
-
- if ( !isset( $options['title'] ) )
- return $options;
-
- $newoptions = array( 1 => $options );
-
- update_option( 'widget_categories', $newoptions );
-
- $sidebars_widgets = get_option( 'sidebars_widgets' );
- if ( is_array( $sidebars_widgets ) ) {
- foreach ( $sidebars_widgets as $sidebar => $widgets ) {
- if ( is_array( $widgets ) ) {
- foreach ( $widgets as $widget )
- $new_widgets[$sidebar][] = ( $widget == 'categories' ) ? 'categories-1' : $widget;
- } else {
- $new_widgets[$sidebar] = $widgets;
- }
- }
- if ( $new_widgets != $sidebars_widgets )
- update_option( 'sidebars_widgets', $new_widgets );
- }
-
- return $newoptions;
-}
-
-function wp_widget_recent_entries($args) {
- if ( '%BEG_OF_TITLE%' != $args['before_title'] ) {
- if ( $output = wp_cache_get('widget_recent_entries', 'widget') )
- return print($output);
- ob_start();
- }
-
- extract($args);
- $options = get_option('widget_recent_entries');
- $title = empty($options['title']) ? __('Recent Posts') : apply_filters('widget_title', $options['title']);
- if ( !$number = (int) $options['number'] )
- $number = 10;
- else if ( $number < 1 )
- $number = 1;
- else if ( $number > 15 )
- $number = 15;
-
- $r = new WP_Query(array('showposts' => $number, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish'));
- if ($r->have_posts()) :
-?>
- <?php echo $before_widget; ?>
- <?php echo $before_title . $title . $after_title; ?>
- <ul>
- <?php while ($r->have_posts()) : $r->the_post(); ?>
- <li><a href="<?php the_permalink() ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?> </a></li>
- <?php endwhile; ?>
- </ul>
- <?php echo $after_widget; ?>
-<?php
- wp_reset_query(); // Restore global post data stomped by the_post().
- endif;
-
- if ( '%BEG_OF_TITLE%' != $args['before_title'] )
- wp_cache_add('widget_recent_entries', ob_get_flush(), 'widget');
-}
-
-function wp_flush_widget_recent_entries() {
- wp_cache_delete('widget_recent_entries', 'widget');
-}
-
-add_action('save_post', 'wp_flush_widget_recent_entries');
-add_action('deleted_post', 'wp_flush_widget_recent_entries');
-add_action('switch_theme', 'wp_flush_widget_recent_entries');
-
-function wp_widget_recent_entries_control() {
- $options = $newoptions = get_option('widget_recent_entries');
- if ( $_POST["recent-entries-submit"] ) {
- $newoptions['title'] = strip_tags(stripslashes($_POST["recent-entries-title"]));
- $newoptions['number'] = (int) $_POST["recent-entries-number"];
- }
- if ( $options != $newoptions ) {
- $options = $newoptions;
- update_option('widget_recent_entries', $options);
- wp_flush_widget_recent_entries();
- }
- $title = attribute_escape($options['title']);
- if ( !$number = (int) $options['number'] )
- $number = 5;
-?>
-
- <p><label for="recent-entries-title"><?php _e('Title:'); ?> <input class="widefat" id="recent-entries-title" name="recent-entries-title" type="text" value="<?php echo $title; ?>" /></label></p>
- <p>
- <label for="recent-entries-number"><?php _e('Number of posts to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-entries-number" name="recent-entries-number" type="text" value="<?php echo $number; ?>" /></label>
- <br />
- <small><?php _e('(at most 15)'); ?></small>
- </p>
- <input type="hidden" id="recent-entries-submit" name="recent-entries-submit" value="1" />
-<?php
-}
-
-function wp_widget_recent_comments($args) {
- global $wpdb, $comments, $comment;
- extract($args, EXTR_SKIP);
- $options = get_option('widget_recent_comments');
- $title = empty($options['title']) ? __('Recent Comments') : apply_filters('widget_title', $options['title']);
- if ( !$number = (int) $options['number'] )
- $number = 5;
- else if ( $number < 1 )
- $number = 1;
- else if ( $number > 15 )
- $number = 15;
-
- if ( !$comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
- $comments = $wpdb->get_results("SELECT comment_author, comment_author_url, comment_ID, comment_post_ID FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number");
- wp_cache_add( 'recent_comments', $comments, 'widget' );
- }
-?>
-
- <?php echo $before_widget; ?>
- <?php echo $before_title . $title . $after_title; ?>
- <ul id="recentcomments"><?php
- if ( $comments ) : foreach ($comments as $comment) :
- echo '<li class="recentcomments">' . sprintf(__('%1$s on %2$s'), get_comment_author_link(), '<a href="'. get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
- endforeach; endif;?></ul>
- <?php echo $after_widget; ?>
-<?php
-}
-
-function wp_delete_recent_comments_cache() {
- wp_cache_delete( 'recent_comments', 'widget' );
-}
-add_action( 'comment_post', 'wp_delete_recent_comments_cache' );
-add_action( 'wp_set_comment_status', 'wp_delete_recent_comments_cache' );
-
-function wp_widget_recent_comments_control() {
- $options = $newoptions = get_option('widget_recent_comments');
- if ( $_POST["recent-comments-submit"] ) {
- $newoptions['title'] = strip_tags(stripslashes($_POST["recent-comments-title"]));
- $newoptions['number'] = (int) $_POST["recent-comments-number"];
- }
- if ( $options != $newoptions ) {
- $options = $newoptions;
- update_option('widget_recent_comments', $options);
- wp_delete_recent_comments_cache();
- }
- $title = attribute_escape($options['title']);
- if ( !$number = (int) $options['number'] )
- $number = 5;
-?>
- <p><label for="recent-comments-title"><?php _e('Title:'); ?> <input class="widefat" id="recent-comments-title" name="recent-comments-title" type="text" value="<?php echo $title; ?>" /></label></p>
- <p>
- <label for="recent-comments-number"><?php _e('Number of comments to show:'); ?> <input style="width: 25px; text-align: center;" id="recent-comments-number" name="recent-comments-number" type="text" value="<?php echo $number; ?>" /></label>
- <br />
- <small><?php _e('(at most 15)'); ?></small>
- </p>
- <input type="hidden" id="recent-comments-submit" name="recent-comments-submit" value="1" />
-<?php
-}
-
-function wp_widget_recent_comments_style() {
-?>
-<style type="text/css">.recentcomments a{display:inline !important;padding: 0 !important;margin: 0 !important;}</style>
-<?php
-}
-
-function wp_widget_recent_comments_register() {
- $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
- wp_register_sidebar_widget('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments', $widget_ops);
- wp_register_widget_control('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments_control');
-
- if ( is_active_widget('wp_widget_recent_comments') )
- add_action('wp_head', 'wp_widget_recent_comments_style');
-}
-
-// See large comment section at end of this file
-function wp_widget_rss($args, $widget_args = 1) {
- extract($args, EXTR_SKIP);
- if ( is_numeric($widget_args) )
- $widget_args = array( 'number' => $widget_args );
- $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
- extract($widget_args, EXTR_SKIP);
-
- $options = get_option('widget_rss');
-
- if ( !isset($options[$number]) )
- return;
-
- if ( isset($options[$number]['error']) && $options[$number]['error'] )
- return;
-
- $url = $options[$number]['url'];
- while ( strstr($url, 'http') != $url )
- $url = substr($url, 1);
- if ( empty($url) )
- return;
-
- require_once(ABSPATH . WPINC . '/rss.php');
-
- $rss = fetch_rss($url);
- $link = clean_url(strip_tags($rss->channel['link']));
- while ( strstr($link, 'http') != $link )
- $link = substr($link, 1);
- $desc = attribute_escape(strip_tags(html_entity_decode($rss->channel['description'], ENT_QUOTES)));
- $title = $options[$number]['title'];
- if ( empty($title) )
- $title = htmlentities(strip_tags($rss->channel['title']));
- if ( empty($title) )
- $title = $desc;
- if ( empty($title) )
- $title = __('Unknown Feed');
- $title = apply_filters('widget_title', $title );
- $url = clean_url(strip_tags($url));
- if ( file_exists(dirname(__FILE__) . '/rss.png') )
- $icon = str_replace(ABSPATH, site_url() . '/', dirname(__FILE__)) . '/rss.png';
- else
- $icon = includes_url('images/rss.png');
- $title = "<a class='rsswidget' href='$url' title='" . attribute_escape(__('Syndicate this content')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
-
- echo $before_widget;
- echo $before_title . $title . $after_title;
-
- wp_widget_rss_output( $rss, $options[$number] );
-
- echo $after_widget;
-}
-
-function wp_widget_rss_output( $rss, $args = array() ) {
- if ( is_string( $rss ) ) {
- require_once(ABSPATH . WPINC . '/rss.php');
- if ( !$rss = fetch_rss($rss) )
- return;
- } elseif ( is_array($rss) && isset($rss['url']) ) {
- require_once(ABSPATH . WPINC . '/rss.php');
- $args = $rss;
- if ( !$rss = fetch_rss($rss['url']) )
- return;
- } elseif ( !is_object($rss) ) {
- return;
- }
-
- extract( $args, EXTR_SKIP );
-
- $items = (int) $items;
- if ( $items < 1 || 20 < $items )
- $items = 10;
- $show_summary = (int) $show_summary;
- $show_author = (int) $show_author;
- $show_date = (int) $show_date;
-
- if ( is_array( $rss->items ) && !empty( $rss->items ) ) {
- $rss->items = array_slice($rss->items, 0, $items);
- echo '<ul>';
- foreach ($rss->items as $item ) {
- while ( strstr($item['link'], 'http') != $item['link'] )
- $item['link'] = substr($item['link'], 1);
- $link = clean_url(strip_tags($item['link']));
- $title = attribute_escape(strip_tags($item['title']));
- if ( empty($title) )
- $title = __('Untitled');
- $desc = '';
- $summary = '';
- if ( isset( $item['description'] ) && is_string( $item['description'] ) )
- $desc = $summary = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['description'], ENT_QUOTES))));
- elseif ( isset( $item['summary'] ) && is_string( $item['summary'] ) )
- $desc = $summary = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['summary'], ENT_QUOTES))));
-
- if ( $show_summary ) {
- $desc = '';
- $summary = wp_specialchars( $summary );
- $summary = "<div class='rssSummary'>$summary</div>";
- } else {
- $summary = '';
- }
-
- $date = '';
- if ( $show_date ) {
- if ( isset($item['pubdate']) )
- $date = $item['pubdate'];
- elseif ( isset($item['published']) )
- $date = $item['published'];
-
- if ( $date ) {
- if ( $date_stamp = strtotime( $date ) )
- $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>';
- else
- $date = '';