danixland

problem with wp_dashboard_cached_rss_widget

Jun 18th, 2013
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Add widget to the dashboard
  3.  * @since 0.1
  4.  */
  5. function dnxsc_feed_display() {
  6.     wp_add_dashboard_widget('dnxsc-dashboard-feed', __('Slackware Security Advisories', 'dnxsc'), 'dnxsc_feed');
  7. }
  8. add_action('wp_dashboard_setup', 'dnxsc_feed_display' );
  9.  
  10. /**
  11.  * check the feed for a chached version
  12.  * @since 0.1
  13.  */
  14. function dnxsc_feed() {
  15.     $url = array(
  16.         'http://dev.slackware.it/rss/slackware-security.xml'
  17.     );
  18.     wp_dashboard_cached_rss_widget( 'dnxsc-dashboard-feed', dnxsc_feed_output(), $url );
  19. }
  20.  
  21. function dnxsc_feed_output() {
  22.     $url = 'http://dev.slackware.it/rss/slackware-security.xml';
  23.     $rss = fetch_feed($url);
  24.  
  25.     if ( is_wp_error($rss) ) {
  26.         if ( is_admin() || current_user_can('manage_options') ) {
  27.             echo '<p>';
  28.             printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
  29.             echo '</p>';
  30.         }
  31.         return;
  32.     }
  33.  
  34.     if ( ! $rss->get_item_quantity() ) {
  35.         echo '<p>' . __('Weird, but there are no items in the Slackware Security Announcements Feed') . "</p>\n";
  36.         $rss->__destruct();
  37.         unset($rss);
  38.         return;
  39.     }
  40.  
  41.     if ( ! isset($items) )
  42.         $items = 10;
  43. ?>
  44. <div class="dnxsc_container">
  45.     <p class="dnxsc_list_desc">
  46.         <img class="dnxsc_tux alignright" src="<?php echo plugins_url() . '/danixland-slackcheck/inc/images/tux512x594.png'; ?>" alt="got slack?" />
  47.         <?php _e("These are the last 10 entries in the Slackware Security Announcements Mailing List.", "dnxsc"); ?>
  48.     </p>
  49.     <div class="clear">
  50.         <ul>
  51.  
  52. <?php
  53.  
  54.     foreach ( $rss->get_items(0, $items) as $item ) {
  55.         $title = $item->get_title();
  56.  
  57.         $content_data = explode('+--------------------------+', $item->get_description());
  58.         $content = html_entity_decode( $content_data[1], ENT_QUOTES, get_option('blog_charset') );
  59.  
  60.         $links_data = $item->get_item_tags(SIMPLEPIE_NAMESPACE_RSS_20, link);
  61.         $link = esc_url($links_data[0]['child']['']['p'][0]['data']);
  62. ?>
  63.             <li>
  64.                 <p class="dnxsc_item_link"><a href="<?php echo $link; ?>" title="<?php echo $title; ?>" target="_blank"><?php echo $title; ?></a></p>
  65.                 <p class="dnxsc_item_desc"><?php echo $content; ?></p>
  66.             </li>
  67. <?php } // endforeach ?>
  68.    
  69.         </ul>
  70.     </div>
  71.     <br class="clear" />
  72.     <div class="dnxsc_buttons">
  73.         <p class="dnxsc_list_desc"><?php _e("For more info about the List please check out the links below.", "dnxsc"); ?></p>
  74.         <div class="alignright"><a class="button-primary" href="http://www.slackware.com/security/"><?php _e('View all SSA', 'dnxsc'); ?></a></div>
  75.         <div class="alignright" style="width:7px">&nbsp;</div>
  76.         <div class="alignleft"><a class="button" href="mailto:majordomo@slackware.com?subject=list%20subscription&body=subscribe%20slackware-security"><?php _e('Subscribe to SSA', 'dnxsc'); ?></a></div>
  77.         <br class="clear" />
  78.     </div>
  79.  
  80. </div><!-- end .dnxsc_container -->
  81.  
  82. <?php
  83.     $rss->__destruct();
  84.     unset($rss);
  85. } // end dnxsc_feed_output()
RAW Paste Data