Advertisement
tabvn

Untitled

Aug 29th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1.  <?php
  2.  
  3. $cache = cache_get('grp_latest_news');
  4.             if ($cache != FALSE) {
  5.                 $items = $cache->data;
  6.             } else {
  7.                 $feed_url = 'http://www.guthrie.org/rss.xml';
  8.                 try {
  9.                     $request = drupal_http_request($feed_url);
  10.                     if ($request->code == 200) {
  11.                         $xml = simplexml_load_string($request->data);
  12.                         foreach ($xml->channel->item as $item) {
  13.                             if ($limit > 0) {
  14.                                 $items[] = $item;
  15.                             }
  16.                             $limit--;
  17.                         }
  18.                         if (!empty($items)) {
  19.                             cache_set('cach', $items, 'cache', 3600);
  20.                             $items = $items;
  21.                         }
  22.                     }
  23.                 } catch (exception $e) {
  24.                     watchdog('guthrie feed', $e, array(), WATCHDOG_ERROR);
  25.                 }
  26.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement