| | 740 | /** |
| | 741 | * Process RSS feed widget data and optionally retrieve feed items. |
| | 742 | * |
| | 743 | * This method is a copy of the standalone function wp_widget_rss_process |
| | 744 | */ |
| | 745 | function rss_process( $widget_rss, $check_feed = true ) { |
| | 746 | $items = (int) $widget_rss['items']; |
| | 747 | if ( $items < 1 || 20 < $items ) |
| | 748 | $items = 10; |
| | 749 | $url = esc_url_raw(strip_tags( $widget_rss['url'] )); |
| | 750 | $title = trim(strip_tags( $widget_rss['title'] )); |
| | 751 | $show_summary = (int) $widget_rss['show_summary']; |
| | 752 | $show_author = (int) $widget_rss['show_author']; |
| | 753 | $show_date = (int) $widget_rss['show_date']; |
| | 754 | |
| | 755 | if ( $check_feed ) { |
| | 756 | $rss = fetch_feed($url); |
| | 757 | $error = false; |
| | 758 | $link = ''; |
| | 759 | if ( is_wp_error($rss) ) { |
| | 760 | $error = $rss->get_error_message(); |
| | 761 | } else { |
| | 762 | $link = esc_url(strip_tags($rss->get_permalink())); |
| | 763 | while ( stristr($link, 'http') != $link ) |
| | 764 | $link = substr($link, 1); |
| | 765 | } |
| | 766 | } |
| | 767 | |
| | 768 | return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' ); |
| | 769 | } |
| | 770 | |
| | 771 | |
| | 780 | |
| | 781 | |
| | 782 | function rss_form( $args, $inputs = null ) { |
| | 783 | |
| | 784 | $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true ); |
| | 785 | $inputs = wp_parse_args( $inputs, $default_inputs ); |
| | 786 | extract( $args ); |
| | 787 | extract( $inputs, EXTR_SKIP); |
| | 788 | |
| | 789 | $number = esc_attr( $number ); |
| | 790 | $title = esc_attr( $title ); |
| | 791 | $url = esc_url( $url ); |
| | 792 | $items = (int) $items; |
| | 793 | if ( $items < 1 || 20 < $items ) |
| | 794 | $items = 10; |
| | 795 | $show_summary = (int) $show_summary; |
| | 796 | $show_author = (int) $show_author; |
| | 797 | $show_date = (int) $show_date; |
| | 798 | |
| | 799 | if ( !empty($error) ) |
| | 800 | echo '<p class="widget-error"><strong>' . sprintf( __('RSS Error: %s'), $error) . '</strong></p>'; |
| | 801 | |
| | 802 | if ( $inputs['url'] ) : |
| | 803 | ?> |
| | 804 | <p><label for="<?php echo $this->get_field_id('url'); ?>"><?php _e('Enter the RSS feed URL here:'); ?></label> |
| | 805 | <input class="widefat" id="rss-url-<?php echo $this->get_field_id('url'); ?>" name="<?php echo $this->get_field_name('url'); ?>" type="text" value="<?php echo $url; ?>" /></p> |
| | 806 | <?php endif; if ( $inputs['title'] ) : ?> |
| | 807 | <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Give the feed a title (optional):'); ?></label> |
| | 808 | <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> |
| | 809 | <?php endif; if ( $inputs['items'] ) : ?> |
| | 810 | <p><label for="<?php echo $this->get_field_id('items'); ?>"><?php _e('How many items would you like to display?'); ?></label> |
| | 811 | <select id="<?php echo $this->get_field_id('items'); ?>" name="<?php echo $this->get_field_name('items'); ?>"> |
| | 812 | <?php |
| | 813 | for ( $i = 1; $i <= 20; ++$i ) |
| | 814 | echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>"; |
| | 815 | ?> |
| | 816 | </select></p> |
| | 817 | <?php endif; if ( $inputs['show_summary'] ) : ?> |
| | 818 | <p><input id="<?php echo $this->get_field_id('show-summary'); ?>" name="<?php echo $this->get_field_name('show_summary'); ?>" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/> |
| | 819 | <label for="<?php echo $this->get_field_id('show-summary'); ?>"><?php _e('Display item content?'); ?></label></p> |
| | 820 | <?php endif; if ( $inputs['show_author'] ) : ?> |
| | 821 | <p><input id="<?php echo $this->get_field_id('show-author'); ?>" name="<?php echo $this->get_field_name('show-author'); ?>" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/> |
| | 822 | <label for="<?php echo $this->get_field_id('show-author'); ?>"><?php _e('Display item author if available?'); ?></label></p> |
| | 823 | <?php endif; if ( $inputs['show_date'] ) : ?> |
| | 824 | <p><input id="<?php echo $this->get_field_id('show-date'); ?>" name="<?php echo $this->get_field_name('show_date'); ?>" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/> |
| | 825 | <label for="<?php echo $this->get_field_id('show-date'); ?>"><?php _e('Display item date?'); ?></label></p> |
| | 826 | <?php |
| | 827 | endif; |
| | 828 | foreach ( array_keys($default_inputs) as $input ) : |
| | 829 | if ( 'hidden' === $inputs[$input] ) : |
| | 830 | $id = str_replace( '_', '-', $input ); |
| | 831 | ?> |
| | 832 | <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="<?php echo $this->get_field_name('url'); ?>[<?php echo $input; ?>]" value="<?php echo $$input; ?>" /> |
| | 833 | <?php |
| | 834 | endif; |
| | 835 | endforeach; |
| | 836 | } |
| | 837 | |