You are here

function sexybookmarks_get_file in Share Buttons, Related Posts, Content Analytics - Shareaholic 7

Same name and namespace in other branches
  1. 7.2 sexybookmarks.module \sexybookmarks_get_file()

Return cached version of request URL.

2 calls to sexybookmarks_get_file()
theme_sexybookmarks in ./sexybookmarks.module
Theme callback for SexyBookmarks.
theme_sexybookmarks_services in plugins/export_ui/sexybookmarks_profiles.inc

File

./sexybookmarks.module, line 219
Contains core functions for the SexyBookmarks module.

Code

function sexybookmarks_get_file($url, $destination = NULL) {
  $md5 = md5($url);
  $pathinfo = pathinfo($url);
  $destination = isset($destination) ? $destination : $pathinfo['basename'];
  $file = "public://sexybookmarks/{$destination}";
  if (!file_exists($file)) {
    $request = drupal_http_request($url);
    $pathinfo = pathinfo($file);
    if ($request->code == 200) {
      if (file_prepare_directory($pathinfo['dirname'], FILE_CREATE_DIRECTORY)) {
        file_unmanaged_save_data($request->data, $file);
      }
    }
    else {
      return $url;
    }
  }
  return $file;
}