You are here

function asset_search_fetch in Asset 6

Same name and namespace in other branches
  1. 5.2 contrib/asset_search/asset_search.module \asset_search_fetch()

Fetch a RSS feed and return its items as pseudo-assets

1 call to asset_search_fetch()
asset_search_wizard_results in contrib/asset_search/asset_search.module
Menu callback for asset/wizard/method/search/<type>/<value>

File

contrib/asset_search/asset_search.module, line 274

Code

function asset_search_fetch($type, $value, $reset = FALSE) {
  $cid = 'asset_search:' . $type . ':' . $value;
  if (!$reset && ($cache = cache_get($cid)) && !empty($cache->data)) {
    $channel = unserialize($cache->data);
  }
  else {
    include_once drupal_get_path('module', 'asset_search') . '/asset_search.parser.inc';
    $url = asset_search_url($type, $value);
    $result = drupal_http_request($url);

    // Process HTTP response code.
    switch ($result->code) {
      case 301:

      // redirect; update any stored url
      // fall through
      case 200:
      case 302:
      case 307:
        $channel = asset_search_parse_feed($result->data, $type, $value);

        // cache for 5 minute
        cache_set($cid, 'cache', serialize($channel), time() + 300);
        break;
      default:
        watchdog('asset', t('The feed at %url seems to be broken, due to "%error".', array(
          '%url' => $url,
          '%error' => $result->code . ' ' . $result->error,
        )), WATCHDOG_WARNING);
        drupal_set_message(t('The feed at %url seems to be broken, because of error "%error".', array(
          '%url' => $url,
          '%error' => $result->code . ' ' . $result->error,
        )));
        return array();
    }
  }
  return $channel;
}