| 57 | | // Incoming Links Widget |
| 58 | | if ( is_blog_admin() && current_user_can('publish_posts') ) { |
| 59 | | if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) { |
| 60 | | $update = true; |
| 61 | | $num_items = isset($widget_options['dashboard_incoming_links']['items']) ? $widget_options['dashboard_incoming_links']['items'] : 10; |
| 62 | | $widget_options['dashboard_incoming_links'] = array( |
| 63 | | 'home' => get_option('home'), |
| 64 | | 'link' => apply_filters( 'dashboard_incoming_links_link', 'http://blogsearch.google.com/blogsearch?scoring=d&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ), |
| 65 | | 'url' => isset($widget_options['dashboard_incoming_links']['url']) ? apply_filters( 'dashboard_incoming_links_feed', $widget_options['dashboard_incoming_links']['url'] ) : apply_filters( 'dashboard_incoming_links_feed', 'http://blogsearch.google.com/blogsearch_feeds?scoring=d&ie=utf-8&num=' . $num_items . '&output=rss&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ), |
| 66 | | 'items' => $num_items, |
| 67 | | 'show_date' => isset($widget_options['dashboard_incoming_links']['show_date']) ? $widget_options['dashboard_incoming_links']['show_date'] : false |
| 68 | | ); |
| 69 | | } |
| 70 | | wp_add_dashboard_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_incoming_links', 'wp_dashboard_incoming_links_control' ); |
| 71 | | } |
| 72 | | |
| 787 | | function wp_dashboard_incoming_links() { |
| 788 | | wp_dashboard_cached_rss_widget( 'dashboard_incoming_links', 'wp_dashboard_incoming_links_output' ); |
| 789 | | } |
| 790 | | |
| 791 | | /** |
| 792 | | * Display incoming links dashboard widget content. |
| 793 | | * |
| 794 | | * @since 2.5.0 |
| 795 | | */ |
| 796 | | function wp_dashboard_incoming_links_output() { |
| 797 | | $widgets = get_option( 'dashboard_widget_options' ); |
| 798 | | @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP ); |
| 799 | | $rss = fetch_feed( $url ); |
| 800 | | |
| 801 | | if ( is_wp_error($rss) ) { |
| 802 | | if ( is_admin() || current_user_can('manage_options') ) { |
| 803 | | echo '<p>'; |
| 804 | | printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message()); |
| 805 | | echo '</p>'; |
| 806 | | } |
| 807 | | return; |
| 808 | | } |
| 809 | | |
| 810 | | if ( !$rss->get_item_quantity() ) { |
| 811 | | echo '<p>' . __('This dashboard widget queries <a href="http://blogsearch.google.com/">Google Blog Search</a> so that when another blog links to your site it will show up here. It has found no incoming links… yet. It’s okay — there is no rush.') . "</p>\n"; |
| 812 | | $rss->__destruct(); |
| 813 | | unset($rss); |
| 814 | | return; |
| 815 | | } |
| 816 | | |
| 817 | | echo "<ul>\n"; |
| 818 | | |
| 819 | | if ( !isset($items) ) |
| 820 | | $items = 10; |
| 821 | | |
| 822 | | foreach ( $rss->get_items(0, $items) as $item ) { |
| 823 | | $publisher = ''; |
| 824 | | $site_link = ''; |
| 825 | | $link = ''; |
| 826 | | $content = ''; |
| 827 | | $date = ''; |
| 828 | | $link = esc_url( strip_tags( $item->get_link() ) ); |
| 829 | | |
| 830 | | $author = $item->get_author(); |
| 831 | | if ( $author ) { |
| 832 | | $site_link = esc_url( strip_tags( $author->get_link() ) ); |
| 833 | | |
| 834 | | if ( !$publisher = esc_html( strip_tags( $author->get_name() ) ) ) |
| 835 | | $publisher = __( 'Somebody' ); |
| 836 | | } else { |
| 837 | | $publisher = __( 'Somebody' ); |
| 838 | | } |
| 839 | | if ( $site_link ) |
| 840 | | $publisher = "<a href='$site_link'>$publisher</a>"; |
| 841 | | else |
| 842 | | $publisher = "<strong>$publisher</strong>"; |
| 843 | | |
| 844 | | $content = $item->get_content(); |
| 845 | | $content = wp_html_excerpt($content, 50) . ' ...'; |
| 846 | | |
| 847 | | if ( $link ) |
| 848 | | /* translators: incoming links feed, %1$s is other person, %3$s is content */ |
| 849 | | $text = __( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"' ); |
| 850 | | else |
| 851 | | /* translators: incoming links feed, %1$s is other person, %3$s is content */ |
| 852 | | $text = __( '%1$s linked here saying, "%3$s"' ); |
| 853 | | |
| 854 | | if ( !empty($show_date) ) { |
| 855 | | if ( !empty($show_author) || !empty($show_summary) ) |
| 856 | | /* translators: incoming links feed, %4$s is the date */ |
| 857 | | $text .= ' ' . __( 'on %4$s' ); |
| 858 | | $date = esc_html( strip_tags( $item->get_date() ) ); |
| 859 | | $date = strtotime( $date ); |
| 860 | | $date = gmdate( get_option( 'date_format' ), $date ); |
| 861 | | } |
| 862 | | |
| 863 | | echo "\t<li>" . sprintf( $text, $publisher, $link, $content, $date ) . "</li>\n"; |
| 864 | | } |
| 865 | | |
| 866 | | echo "</ul>\n"; |
| 867 | | $rss->__destruct(); |
| 868 | | unset($rss); |
| 869 | | } |
| 870 | | |
| 871 | | function wp_dashboard_incoming_links_control() { |
| 872 | | wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) ); |
| 873 | | } |
| 874 | | |