| 85 | | // Primary feed (Dev Blog) Widget |
| 86 | | if ( !isset( $widget_options['dashboard_primary'] ) ) { |
| 87 | | $update = true; |
| 88 | | $widget_options['dashboard_primary'] = array( |
| 89 | | 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ), |
| 90 | | 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ), |
| 91 | | 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ), |
| 92 | | 'items' => 2, |
| 93 | | 'show_summary' => 1, |
| 94 | | 'show_author' => 0, |
| 95 | | 'show_date' => 1, |
| 96 | | ); |
| 97 | | } |
| 98 | | wp_add_dashboard_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_primary', 'wp_dashboard_primary_control' ); |
| | 85 | // WordPress Feed Widget |
| | 86 | wp_add_dashboard_widget( 'dashboard_wp_newsfeed', __( 'WordPress News' ), 'wp_dashboard_newsfeed', 'wp_dashboard_newsfeed_control' ); |
| 100 | | // Secondary Feed (Planet) Widget |
| 101 | | if ( !isset( $widget_options['dashboard_secondary'] ) ) { |
| 102 | | $update = true; |
| 103 | | $widget_options['dashboard_secondary'] = array( |
| 104 | | 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ), |
| 105 | | 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ), |
| 106 | | 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ), |
| 107 | | 'items' => 5, |
| 108 | | 'show_summary' => 0, |
| 109 | | 'show_author' => 0, |
| 110 | | 'show_date' => 0, |
| 111 | | ); |
| 112 | | } |
| 113 | | wp_add_dashboard_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_secondary', 'wp_dashboard_secondary_control' ); |
| 114 | | |
| 885 | | function wp_dashboard_secondary() { |
| 886 | | wp_dashboard_cached_rss_widget( 'dashboard_secondary', 'wp_dashboard_secondary_output' ); |
| | 850 | /** |
| | 851 | * Display (cached) dashboard widget for WordPress news and Planet WordPress |
| | 852 | * |
| | 853 | * @since 3.6.0 |
| | 854 | */ |
| | 855 | function wp_dashboard_newsfeed() { |
| | 856 | wp_dashboard_cached_rss_widget( |
| | 857 | 'wp_dashboard_newsfeed', |
| | 858 | 'wp_dashboard_newsfeed_output', |
| | 859 | array( |
| | 860 | 'http://wordpress.org/news/feed/', |
| | 861 | 'http://planet.wordpress.org/feed/' |
| | 862 | ) |
| | 863 | ); |
| 889 | | function wp_dashboard_secondary_control() { |
| 890 | | wp_dashboard_rss_control( 'dashboard_secondary' ); |
| | 866 | /** |
| | 867 | * Display options for the newsfeed widget. |
| | 868 | * |
| | 869 | * @since 3.6.0 |
| | 870 | */ |
| | 871 | function wp_dashboard_newsfeed_control() { |
| | 872 | if ( ! $widget_options = get_option( 'dashboard_widget_options' ) ) { |
| | 873 | $widget_options = array(); |
| | 874 | } |
| | 875 | |
| | 876 | if ( ! isset( $widget_options['dashboard_newsfeed'] ) ) { |
| | 877 | $widget_options['dashboard_newsfeed'] = array( |
| | 878 | 'news' => 'http://wordpress.org/news/feed/', |
| | 879 | 'planet' => 'http://planet.wordpress.org/feed/' |
| | 880 | ); |
| | 881 | } |
| | 882 | |
| | 883 | $news = $widget_options['dashboard_newsfeed']['news']; |
| | 884 | $planet = $widget_options['dashboard_newsfeed']['planet']; |
| | 885 | |
| | 886 | // Update options on postback |
| | 887 | if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-newsfeed'] ) ) { |
| | 888 | $news = esc_url( $_POST['widget-newsfeed']['news'] ); |
| | 889 | $planet = esc_url( $_POST['widget-newsfeed']['planet'] ); |
| | 890 | $widget_options['dashboard_newsfeed'] = array( |
| | 891 | 'news' => $news, |
| | 892 | 'planet' => $planet |
| | 893 | ); |
| | 894 | update_option( 'dashboard_widget_options', $widget_options ); |
| | 895 | |
| | 896 | // Force the cached feed to flush |
| | 897 | $cache_key = 'dash_' . md5( 'wp_dashboard_newsfeed' ); |
| | 898 | delete_transient( $cache_key ); |
| | 899 | } |
| | 900 | |
| | 901 | echo '<p><label for="wordpress-news-newsfeed">' . __( 'WordPress News Feed URL:' ) . '</label>'; |
| | 902 | echo '<input class="widefat" id="wordpress-news-newsfeed" name="widget-newsfeed[news]" type="text" value="' . esc_attr( $news ) . '"/></p>'; |
| | 903 | echo '<p><label for="wordpress-planet-newsfeed">' . __( 'Planet WordPress Feed URL:' ) . '</label>'; |
| | 904 | echo '<input class="widefat" id="wordpress-planet-newsfeed" name="widget-newsfeed[planet]" type="text" value="' . esc_attr( $planet ) . '"/></p>'; |
| 905 | | if ( is_wp_error($rss) ) { |
| 906 | | if ( is_admin() || current_user_can('manage_options') ) { |
| 907 | | echo '<div class="rss-widget"><p>'; |
| 908 | | printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message()); |
| 909 | | echo '</p></div>'; |
| | 917 | if ( ! isset( $widget_options['dashboard_newsfeed'] ) ) { |
| | 918 | $widget_options['dashboard_newsfeed'] = array( |
| | 919 | 'news' => 'http://wordpress.org/news/feed/', |
| | 920 | 'planet' => 'http://planet.wordpress.org/feed/' |
| | 921 | ); |
| | 922 | } |
| | 923 | |
| | 924 | $news = $widget_options['dashboard_newsfeed']['news']; |
| | 925 | $planet = $widget_options['dashboard_newsfeed']['planet']; |
| | 926 | |
| | 927 | $official = fetch_feed( $news ); |
| | 928 | $planet = fetch_feed( $planet ); |
| | 929 | |
| | 930 | foreach( array( 'official' => __( 'WordPress.org Official Blog' ), 'planet' => __( 'Planet WordPress' ) ) as $feed => $label ) { |
| | 931 | if ( is_wp_error( $$feed ) || ! $$feed->get_item_quantity() ) |
| | 932 | continue; |
| | 933 | switch( $feed ) { |
| | 934 | case 'official': |
| | 935 | $items = $$feed->get_items( 0, 2 ); |
| | 936 | break; |
| | 937 | default: |
| | 938 | $items = $$feed->get_items( 0, 5 ); |
| 911 | | } elseif ( !$rss->get_item_quantity() ) { |
| 912 | | $rss->__destruct(); |
| 913 | | unset($rss); |
| 914 | | return false; |
| 915 | | } else { |
| 916 | | echo '<div class="rss-widget">'; |
| 917 | | wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] ); |
| 918 | | echo '</div>'; |
| 919 | | $rss->__destruct(); |
| 920 | | unset($rss); |
| | 940 | |
| | 941 | echo "<p class='sub'>"; |
| | 942 | |
| | 943 | if ( 'official' == $feed ) { |
| | 944 | echo '<span class="wp-official"></span>'; |
| | 945 | } |
| | 946 | |
| | 947 | echo "$label</p>"; |
| | 948 | echo "<ul>"; |
| | 949 | |
| | 950 | foreach( $items as $item ) { |
| | 951 | $link = $item->get_link(); |
| | 952 | $title = $item->get_title(); |
| | 953 | $description = $item->get_description(); |
| | 954 | $date = 'official' == $feed ? $item->get_date( 'U' ) : ''; |
| | 955 | |
| | 956 | // Filter title |
| | 957 | $title = esc_attr( strip_tags( $title ) ); |
| | 958 | if ( empty( $title ) ) { |
| | 959 | $title = __( 'Untitled' ); |
| | 960 | } |
| | 961 | |
| | 962 | // Filter description |
| | 963 | $description = str_replace( array( "\n", "\r" ), ' ', esc_attr( strip_tags( @html_entity_decode( $description, ENT_QUOTES, get_option( 'blog_charset' ) ) ) ) ); |
| | 964 | $description = wp_html_excerpt( $description, 360 ); |
| | 965 | |
| | 966 | // Append ellipsis. Change existing [...] to […]. |
| | 967 | if ( '[...]' == substr( $description, -5 ) ) { |
| | 968 | $description = substr( $description, 0, -5 ) . '[…]'; |
| | 969 | } elseif ( '[…]' != substr( $description, -10 ) ) { |
| | 970 | $description .= ' […]'; |
| | 971 | } |
| | 972 | $description = esc_html( $description ); |
| | 973 | |
| | 974 | // Filter summary |
| | 975 | if ( 'official' == $feed ) { |
| | 976 | $summary = "<div class='rssSummary'>$description</div>"; |
| | 977 | } else { |
| | 978 | $summary = ''; |
| | 979 | } |
| | 980 | |
| | 981 | // Filter date |
| | 982 | if ( '' !== $date ) { |
| | 983 | $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>'; |
| | 984 | } |
| | 985 | |
| | 986 | if ( '' === $link ) { |
| | 987 | echo "<li>$title{$date}{$summary}</li>"; |
| | 988 | } else { |
| | 989 | echo "<li><a class='rsswidget' href='$link' title='$description'>$title</a>{$date}{$summary}</li>"; |
| | 990 | } |
| | 991 | } |
| | 992 | |
| | 993 | echo "</ul>"; |
| | 994 | |
| | 995 | $$feed->__destruct(); |
| | 996 | unset( $$feed ); |