示例#1
0
文件: WG.php 项目: 318io/318-io
 public static function fetch_url($url, $cache = true, $cache_fn = false, $reset = false)
 {
     if ($cache) {
         if ($cache === true && $cache_fn === false) {
             $cache_fn = 'public://cache/';
         } else {
             $cache_fn = $cache;
         }
         if (DT::endsWith($cache_fn, '/')) {
             $cache_path = $cache_fn;
             $cache_fn = $cache_path . DT::sanitize($url);
         } else {
             $cache_path = dirname($cache_fn) . '/';
         }
         file_prepare_directory($cache_path, FILE_CREATE_DIRECTORY);
         if (!file_exists($cache_fn) || $reset) {
             $data = DT::_fetch_url_data($url);
             file_put_contents($cache_fn, $data);
         } else {
             $data = file_get_contents($cache_fn);
         }
     } else {
         $data = DT::_fetch_url_data($url);
     }
     return $data;
 }