コード例 #1
0
 /**
  * Download a list of assets (img,css,js) that are used by a page
  * @param $assets array of strings of relative paths of assets
  * @param $url string path to the page from which the assets are referenced
  * @return array where keys are asset paths, and values are body/header dictionaries returned from open_url, along with
  *         another key containing the absolute path to the asset
  */
 private function download_assets($assets, $url = '')
 {
     $result = array();
     /* Commented out code is the one-asset-at-a-time version */
     // foreach ($assets as $key => $asset) {
     //   $f = AmberNetworkUtils::open_url($asset['url'], array(CURLOPT_REFERER => $url));
     //   if ($f) {
     //     $result[$key] = array_merge($f,$asset);
     //   }
     // }
     $urls = array();
     $keys = array();
     foreach ($assets as $key => $asset) {
         $urls[] = $asset['url'];
         $keys[$asset['url']] = $key;
     }
     $response = AmberNetworkUtils::open_multi_url($urls, array(CURLOPT_REFERER => $url));
     foreach ($assets as $key => $asset) {
         if (is_array($response[$asset['url']])) {
             $result[$key] = array_merge($response[$asset['url']], $asset);
         }
     }
     return $result;
 }
コード例 #2
0
 /**
  * Open a URL, and return an array with dictionary of header information and the contents of the URL
  * @param $url string of resource to download
  * @return array dictionary of header information and a stream to the contents of the URL
  */
 public static function open_url($url, $additional_options = array())
 {
     $result = AmberNetworkUtils::open_multi_url(array($url), $additional_options);
     if (count($result) == 1) {
         return array_pop($result);
     } else {
         return FALSE;
     }
 }