CNN

"edition_africa.rss", "All Stories [MONEY]" => "money_latest.rss", "Apple 2.0 [MONEY]" => "https://rss.cnn.com/fortuneapple20", "Americas [INTL]" => "edition_americas.rss", "Asia [INTL]" => "edition_asia.rss", "Ask Annie [MONEY]" => "https://rss.cnn.com/fortuneaskannieblog", "Ask The Expert [MONEY]" => "https://rss.cnn.com/moneyasktheexpert", "Autos [MONEY]" => "money_autos.rss", "Bonds [MONEY]" => "money_markets_bondcenter.rss", "Business 360 [INTL]" => "edition_business360.rss", "C-Suite [MONEY]" => "https://rss.cnn.com/fortunecsuiteblog", "CNN.com Behind the Scenes Blog" => "cnn_behindthescenes.rss", "Companies [MONEY]" => "money_news_companies.rss", "College [MONEY]" => "money_pf_college.rss", "Connect The World [INTL]" => "edition_connecttheworld.rss", "Crime" => "cnn_crime.rss", "Do The Right Thing [MONEY]" => "https://rss.cnn.com/moneyethics", "Economy [MONEY]" => "money_news_economy.rss", "Entertainment" => "cnn_showbiz.rss", "Entertainment [INTL]" => "edition_entertainment.rss", "Europe [INTL]" => "edition_europe.rss", "Fantasy [SI]" => "si_fantasy.rss", "Football [INTL]" => "edition_football.rss", "FORTUNE [MONEY]" => "magazines_fortune.rss", "FORTUNE Small Business [MONEY]" => "magazines_fsb.rss", "FORTUNE International [MONEY]" => "magazines_fortuneintl.rss", "Fortune Finance [MONEY]" => "https://rss.cnn.com/fortunefinance.rss", "Fortune Tech [MONEY]" => "https://rss.cnn.com/fortunetech.rss", "Funds [MONEY]" => "money_funds.rss", "Golf [INTL]" => "edition_golf.rss", "Golf [SI]" => "https://feeds.feedburner.com/GolfToursNews", "Google 24/7 [MONEY]" => "https://rss.cnn.com/fortunegoogle247", "Health" => "cnn_health.rss", "High School [SI]" => "si_highschool.rss", "In the Field [INTL]" => "edition_inthefield.rss", "Inside the Middle East [INTL]" => "edition_ime.rss", "Insurance [MONEY]" => "money_pf_insurance.rss", "International [MONEY]" => "money_news_international.rss", "International Desk [INTL]" => "edition_idesk.rss", "iReports on CNN" => "https://rss.ireport.com/feeds/oncnn.rss", "Lifestyle [MONEY]" => "money_lifestyle.rss", "Living" => "cnn_living.rss", "Management and Career [MONEY]" => "https://rss.cnn.com/fortunemanagement", "Markets [MONEY]" => "money_markets.rss", "Middle East [INTL]" => "edition_meast.rss", "MLB [SI]" => "si_mlb.rss", "MMA [SI]" => "si_mma.rss", "Money Helps [MONEY]" => "https://rss.cnn.com/moneyhelps", "Money Magazine [MONEY]" => "magazines_moneymag.rss", "More Sports [SI]" => "si_more.rss", "Most Popular" => "cnn_mostpopular.rss", "Most Popular [MONEY]" => "money_mostpopular.rss", "Most Popular [SI]" => "si_mostpopular.rss", "Most Recent" => "cnn_latest.rss", "Motorsport [INTL]" => "edition_motorsport.rss", "NBA [SI]" => "si_nba.rss", "NCAAB [SI]" => "si_ncaab.rss", "NCAAF [SI]" => "si_ncaaf.rss", "NFL [SI]" => "si_nfl.rss", "NHL [SI]" => "si_hockey.rss", "Personal Finance [MONEY]" => "money_pf.rss", "Personal Tech [MONEY]" => "money_technology_personaltech.rss", "Politics" => "cnn_allpolitics.rss", "Postcards [MONEY]" => "https://rss.cnn.com/fortunepostcards", "Prism [INTL]" => "edition_prismblog.rss", "Quest Means Business [INTL]" => "edition_questmeansbusiness.rss", "Real Estate [MONEY]" => "money_realestate.rss", "Racing [SI]" => "si_motorsports.rss", "Retirement [MONEY]" => "money_retirement.rss", "Science & Space [INTL]" => "edition_space.rss", "Small Business [MONEY]" => "money_smbusiness.rss", "SI Writers [SI]" => "si_writers.rss", "Soccer [SI]" => "si_soccer.rss", "Sports (SI.com)" => "si_topstories.rss", "SportsBiz [MONEY]" => "money_commentary_columnsportsbiz.rss", "Street Sweep [MONEY]" => "https://rss.cnn.com/fortunestreetsweep", "Student News" => "cnn_studentnews.rss", "Taxes [MONEY]" => "money_pf_taxes.rss", "Technology" => "cnn_tech.rss", "Technology [INTL]" => "edition_technology.rss", "Technology [MONEY]" => "money_technology.rss", "Tennis [INTL]" => "edition_tennis.rss", "Tennis [SI]" => "si_tennis.rss", "Term Sheet [MONEY]" => "https://rss.cnn.com/fortunetermsheet", "The Buzz [MONEY]" => "https://rss.cnn.com/cnnmoneymorningbuzz", "The Mole [MONEY]" => "https://rss.cnn.com/AskTheMole", "The Screening Room [INTL]" => "edition_screeningroom.rss", "The Wheel Deal [MONEY]" => "https://rss.cnn.com/fortunewheeldeal", "Top Stories" => "cnn_topstories.rss", "Top Stories [INTL]" => "edition.rss", "Top Stories [SI]" => "si_topstories.rss", "Top Tips [MONEY]" => "money_pf_saving.rss", "Travel" => "cnn_travel.rss", "Travel [INTL]" => "edition_travel.rss", "U.S." => "cnn_us.rss", "U.S. [INTL]" => "edition_us.rss", "Video" => "cnn_freevideo.rss", "Video [MONEY]" => "money_video_business.rss", "World" => "cnn_world.rss", "World [INTL]" => "edition_world.rss", "World Business [INTL]" => "edition_business.rss", "World Sport [INTL]" => "edition_sport.rss", ); var $desctypes = array( 'Short' => '', 'Long' => 'l', ); // Constructor function cnn_news_plugin() { // Form POSTs dealt with elsewhere if ( is_array($_POST) ) { if ( $_POST['cnn_news-widget-submit'] ) { $tmp = $_POST['cnn_news-widget-feed']; $alloptions = get_option('cnn_news'); if ( $alloptions['widget-1'] != $tmp ) { if ( $tmp == '*DEFAULT*' ) { $alloptions['widget-1'] = ''; } else { $alloptions['widget-1'] = $tmp; } update_option('cnn_news', $alloptions); } } else if ( $_POST['cnn_news-options-submit'] ) { // noop } else if ( $_POST['cnn_news-submit'] ) { // noop } } add_filter('the_content', array(&$this, 'insert_news')); add_action('admin_menu', array(&$this, 'admin_menu')); add_action('plugins_loaded', array(&$this, 'widget_init')); // Hook for theme coders/hackers add_action('cnn_news', array(&$this, 'display_feed')); // Makes it backwards compat pre-2.5 I hope if ( function_exists('add_shortcode') ) { add_shortcode('cnn-news', array(&$this, 'my_shortcode_handler')); } } // *************** Admin interface ****************** // Callback for admin menu function admin_menu() { add_options_page('CNN News Options', 'CNN News', 'administrator', __FILE__, array(&$this, 'plugin_options')); add_management_page('CNN News', 'CNN News', 'administrator', __FILE__, array(&$this, 'admin_manage')); } // Settings -> CNN News function plugin_options() { if (get_bloginfo('version') >= '2.7') { $manage_page = 'tools.php'; } else { $manage_page = 'edit.php'; } print <<

CNN News

This plugin allows you to define a number of CNN News feeds and have them displayed anywhere in content, in a widget or in a theme. Any number of inline replacements or theme inserts can be made, but only one widget instance is permitted in this release. To use the feeds insert one or more of the following special html comments or Shortcodes anywhere in user content. Note that Shortcodes, i.e. the ones using square brackets, are only available in WordPress 2.5 and above.

  • <--cnn-news--> (for default feed)
  • <--cnn-news#feedname-->
  • [cnn-news] (also for default feed)
  • [cnn-news name="feedname"]

To insert in a theme call do_action('cnn_news'); or alternatively do_action('cnn_news', 'feedname');

To manage feeds, go to Manage -> CNN News, where you will also find more information.

Donations Page... ;-)

Widget Home Page, leave a comment if you have questions etc.

CNN Terms Of Use

EOT; } // Manage -> CNN News function admin_manage() { // Edit/delete links $mode = trim($_GET['mode']); $id = trim($_GET['id']); $this->upgrade_options(); $alloptions = get_option('cnn_news'); $flipcnnfeeds = array_flip($this->cnnfeeds); $flipdesctypes = array_flip($this->desctypes); if ( is_array($_POST) && $_POST['cnn_news-submit'] ) { $newoptions = array(); $id = $_POST['cnn_news-id']; $newoptions['name'] = $_POST['cnn_news-name']; $newoptions['title'] = $_POST['cnn_news-title']; $newoptions['feedurl'] = $_POST['cnn_news-feedurl']; $newoptions['numnews'] = $_POST['cnn_news-numnews']; $newoptions['desctype'] = $_POST['cnn_news-desctype']; $newoptions['feedtype'] = $flipcnnfeeds[$newoptions['feedurl']]; if ( $alloptions['feeds'][$id] == $newoptions ) { $text = 'No change...'; $mode = 'main'; } else { $alloptions['feeds'][$id] = $newoptions; update_option('cnn_news', $alloptions); $mode = 'save'; } } else if ( is_array($_POST) && $_POST['cnn_news-options-cachetime-submit'] ) { if ( $_POST['cnn_news-options-cachetime'] != $alloptions['cachetime'] ) { $alloptions['cachetime'] = $_POST['cnn_news-options-cachetime']; update_option('cnn_news', $alloptions); $text = "Cache time changed to {$alloptions[cachetime]} seconds."; } else { $text = "No change in cache time..."; } $mode = 'main'; } if ( $mode == 'newfeed' ) { $newfeed = 0; foreach ($alloptions['feeds'] as $k => $v) { if ( $k > $newfeed ) { $newfeed = $k; } } $newfeed += 1; $text = "Please configure new feed and press Save."; $mode = 'main'; } if ( $mode == 'save' ) { $text = "Saved feed {$alloptions[feeds][$id][name]} [$id]."; $mode = 'main'; } if ( $mode == 'edit' ) { if ( ! empty($text) ) { echo '

'.$text.'

'; } $text = "Editing feed {$alloptions[feeds][$id][name]} [$id]."; $edit_id = $id; $mode = 'main'; } if ( $mode == 'delete' ) { $text = "Deleted feed {$alloptions[feeds][$id][name]} [$id]."; unset($alloptions['feeds'][$id]); update_option('cnn_news', $alloptions); $mode = 'main'; } // main if ( empty($mode) or ($mode == 'main') ) { if ( ! empty($text) ) { echo '

'.$text.'

'; } print '
'; print '

'; print _e('Manage CNN News Feeds','cnn_news'); print '

'; print ' '; print ' '; print ' '; print ' '; print ' '; print ' '; print ' '; print ' '; print ' '; print ' '; print ' '; print ' '; if (get_bloginfo('version') >= '2.7') { $manage_page = 'tools.php'; } else { $manage_page = 'edit.php'; } if ( $alloptions['feeds'] || $newfeed ) { $i = 0; foreach ($alloptions['feeds'] as $key => $val) { if ( $i % 2 == 0 ) { print ''; } else { print ''; } if ( isset($edit_id) && $edit_id == $key ) { print ""; print ""; print ''; print ''; print ''; print ''; print ''; print '"; print ""; print ""; print ""; } else { print ""; print ""; print ""; print ""; print ""; print ""; print "\n"; print "\n"; } print ''; $i++; } if ( $newfeed ) { print ""; print ""; print ''; print ''; print ''; print ''; print ''; print ''; print '"; print ""; print ""; print ""; print ""; } else { print ""; } } else { print ''; print ""; } print '
'; print _e('Key','cnn_news'); print ''; print _e('Name','cnn_news'); print ''; print _e('Admin-defined title','cnn_news'); print ''; print _e('Feed','cnn_news'); print ''; print _e('Item length','cnn_news'); print ''; print _e('Max items','cnn_news'); print ''; print _e('Action','cnn_news'); print '
".$key."'; print "".$key."".$val['name']."".$val['title']."".$flipcnnfeeds[$val['feedurl']]."".$flipdesctypes[$val['desctype']]."".$val['numnews'].""; print __('Edit','cnn_news'); print ""; print __('Delete', 'cnn_news'); print "
".$newfeed."'; print "
"; print __('Add extra feed','cnn_news'); print "
'; print __('No feeds found(!)','cnn_news'); print '
"; print __('Add feed','cnn_news'); print "
'; print '

'; print _e('Global configuration parameters','cnn_news'); print '

'; print '
'; print ' '; print ''; print ''; print ''; print ''; print '
Cache time: seconds
'; print '
'; print '

'; print _e('Information','cnn_news'); print '

'; print ' '; print ''; print ''; print ''; print ''; print ''; print ''; print '
KeyUnique identifier used internally.
NameOptional name to be able to reference a specific feed as e.g. '; print ' <!--cnn-news#myname-->. '; print ' If more than one feed shares the same name, a random among these will be picked each time. '; print ' The one(s) without a name will be treated as the default feed(s), i.e. used for <!--cnn-news--> '; print ' or widget feed type *DEFAULT*. If you have Wordpress 2.5 '; print ' or above, you can also use Shortcodes on the form [cnn-news] '; print ' (for default feed) or [cnn-news name="feedname"]. And finally '; print ' you can use do_action(\'cnn_news\'); or do_action(\'cnn_news\', \'feedname\'); '; print ' in themes.
Admin-defined titleOptional feed title. If not set, a reasonable title based on '; print 'Region and Type will be used. Note CNN Terms of Service require you to show that the feeds come from '; print 'CNN News.
FeedThe actual feed to use.
Max itemsMaximum number of news items to show for this feed. If the feed contains '; print 'less than the requested items, only the number of items in the feed will obviously be displayed.
Cache timeMinimum number of seconds that WordPress should cache a CNN News feed before fetching it again.
'; print '
'; } } // ************* Output ***************** // The function that gets called from themes function display_feed($data) { global $settings; $settings = get_option('cnn_news'); print $this->random_feed($data); unset($settings); } // Callback for inline replacement function insert_news($data) { global $settings; // Allow for multi-feed sites $tag = '//'; // We may have old style options $this->upgrade_options(); // Avoid getting this for each callback $settings = get_option('cnn_news'); $result = preg_replace_callback($tag, array(&$this, 'inline_replace_callback'), $data); unset($settings); return $result; } // *********** Widget support ************** function widget_init() { // Check for the required plugin functions. This will prevent fatal // errors occurring when you deactivate the dynamic-sidebar plugin. if ( !function_exists('register_sidebar_widget') ) return; register_widget_control('CNN News', array(&$this, 'widget_control'), 200, 100); // wp_* has more features, presumably fixed at a later date register_sidebar_widget('CNN News', array(&$this, 'widget_output')); } function widget_control() { // We may have old style options $this->upgrade_options(); $alloptions = get_option('cnn_news'); $thisfeed = $alloptions['widget-1']; print '

'; print '

'; print ''; } // Called every time we want to display ourselves as a sidebar widget function widget_output($args) { extract($args); // Gives us $before_ and $after_ I presume // We may have old style options $this->upgrade_options(); $alloptions = get_option('cnn_news'); $matching_feeds = array(); foreach ($alloptions['feeds'] as $k => $v) { if ( (string)$v['name'] == $alloptions['widget-1'] ) { $matching_feeds[] = $k; } } if ( ! count($matching_feeds) ) { if ( ! strlen($alloptions['widget-1']) ) { $content = '

    No default feed available
'; } else { $content = "
    Unknown feed name {$alloptions[widget-1]} used
"; } echo $before_widget; echo $before_title . __('CNN News
Error','cnn_news') . $after_title . '
'; echo $content; echo '
' . $after_widget; return; } $feed_id = $matching_feeds[rand(0, count($matching_feeds)-1)]; $options = $alloptions['feeds'][$feed_id]; $feedtype = $options['feedtype']; $cachetime = $alloptions['cachetime']; if ( strlen($options['title']) ) { $title = $options['title']; } else { $title = 'CNN News
'.$feedtype; } echo $before_widget; echo $before_title . $title . $after_title . '
'; echo $this->get_feed($options, $cachetime); echo '
' . $after_widget; } // ************** The actual work **************** function get_feed(&$options, $cachetime) { if ( ! isset($options['feedurl']) ) { return 'Options not set, visit plugin configuation screen.'; } $feedurl = $options['feedurl'] ? $options['feedurl'] : 'cnn_topstories.rss'; $numnews = $options['numnews'] ? $options['numnews'] : 5; $desctype = $options['desctype']; $result = '
    '; // Support non-rss.cnn.com urls if ( substr($feedurl, 0, 5) != "http:" ) { $rssurl = 'https://rss.cnn.com/rss/'.$feedurl; } else { $rssurl = $feedurl; } // Using the WP RSS fetcher (MagpieRSS). It has serious // GC problems though. define('MAGPIE_CACHE_AGE', $cachetime); define('MAGPIE_CACHE_ON', 1); define('MAGPIE_DEBUG', 1); $rss = fetch_rss($rssurl); if ( ! is_object($rss) ) { return 'CNN News unavailable
'; } $rss->items = array_slice($rss->items, 0, $numnews); foreach ( $rss->items as $item ) { $description = $this->html_decode($item['description']); // Bunch of useless links after first

in desc $bloc = strpos($description, '

'); if ( $bloc ) { $description = substr($description, 0, $bloc); } // No markup in tooltips $tooltip = preg_replace('/<[^>]+>/','',$description); $tooltip = preg_replace('/"/','\'',$tooltip); $title = $this->html_decode($item['title']); $date = $item['pubdate']; $link = $item['link']; if ( strlen($desctype) ) { $result .= "

  • $title
    $description
  • "; } else { $result .= "
  • $title
  • "; } } return $result.''; } // *********** Shortcode support ************** function my_shortcode_handler($atts, $content=null) { global $settings; $settings = get_option('cnn_news'); return $this->random_feed($atts['name']); unset($settings); } // *********** inline replacement callback support ************** function inline_replace_callback($matches) { if ( ! strlen($matches[1]) ) { // Default $feedname = ''; } else { $feedname = substr($matches[1], 1); // Skip # } return $this->random_feed($feedname); } // ************** Support functions **************** function random_feed($name) { global $settings; $matching_feeds = array(); foreach ($settings['feeds'] as $k => $v) { if ( (string)$v['name'] == $name ) { $matching_feeds[] = $k; } } if ( ! count($matching_feeds) ) { if ( ! strlen($name) ) { return '
      No default feed available
    '; } else { return "
      Unknown feed name $name used
    "; } } $feed_id = $matching_feeds[rand(0, count($matching_feeds)-1)]; $feed = $settings['feeds'][$feed_id]; if ( strlen($feed['title']) ) { $title = $feed['title']; } else { $title = 'CNN News : '.$feed['feedtype']; } $result = ''; $result .= "

    $title

    "; $result .= $this->get_feed($feed, $settings['cachetime']); $result .= '
    '; return $result; } function html_decode($in) { $patterns = array( '/&/', '/"/', '/</', '/>/', ); $replacements = array( '&', '"', '<', '>', ); $tmp = preg_replace($patterns, $replacements, $in); return preg_replace('/'/','\'',$tmp); } // Unfortunately, we didn't finalize on a data structure // until version 2.1ish of the plugin so we need to upgrade // if needed function upgrade_options() { $options = get_option('cnn_news'); if ( !is_array($options) ) { // a:6:{s:5:"title";s:0:"";s:8:"feedname";s:13:"CNN.com: U.S.";s:7:"feedurl";s:33:"https://rss.cnn.com/rss/cnn_us.rss";s:7:"numnews";s:1:"5";s:11:"usefeedname";b:1;s:8:"getfeeds";b:0;} // From 1.0 $oldoptions = get_option('widget_cnn_news_widget'); if ( is_array($oldoptions) ) { $flipcnnfeeds = array_flip($this->cnnfeeds); $tmpfeed = array(); $tmpfeed['title'] = $oldoptions['title']; $tmpfeed['name'] = ''; $tmpfeed['numnews'] = $oldoptions['numnews']; $tmpfeed['feedurl'] = $oldoptions['feedurl']; $tmpfeed['feedtype'] = $flipcnnfeeds[substr($tmpfeed['feedurl'], 23)]; $options = array(); $options['feeds'] = array( $tmpfeed ); $options['widget-1'] = 0; $options['cachetime'] = 300; delete_option('widget_cnn_news_widget'); update_option('cnn_news', $options); } else { // First time ever $options = array(); $options['feeds'] = array( $this->default_feed() ); $options['widget-1'] = 0; $options['cachetime'] = 300; update_option('cnn_news', $options); } } } function default_feed() { return array( 'numnews' => 5, 'feedurl' => 'cnn_topstories.rss', 'name' => '', 'feedtype' => 'Top Stories'); } } // Instantiate $cnn_news_instance &= new cnn_news_plugin(); } ?>