Esempio n. 1
0
 /**
  * Uses CURL to perform a GET request to the Github API v3.
  */
 public static function _fetch($url)
 {
     if (extension_loaded('curl')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_USERAGENT, 'Elefant CMS/' . ELEFANT_VERSION);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_VERBOSE, 0);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_FAILONERROR, 0);
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setproxy($ch, $url);
         $res = curl_exec($ch);
         curl_close($ch);
         return $res;
     }
     return file_get_contents($url);
 }
Esempio n. 2
0
 /**
  * Fetch a zip file from a link.
  */
 public static function fetch($url)
 {
     $path = parse_url($url, PHP_URL_PATH);
     if (strpos($path, '/zipball/') !== false) {
         // Fix zip file links from Github
         $path = current(explode('/zipball/', $path)) . '.zip';
     }
     $base = basename($path);
     $tmp = 'cache/zip/' . $base;
     if (!is_dir('cache/zip')) {
         mkdir('cache/zip');
         chmod('cache/zip', 0777);
     }
     if (extension_loaded('curl')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_VERBOSE, 0);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_FAILONERROR, 0);
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setproxy($ch, $url);
         $res = curl_exec($ch);
         curl_close($ch);
     } else {
         $res = file_get_contents($url);
     }
     if ($res === false) {
         self::$error = __('Failed to retrieve the file at the specified link.');
         return false;
     }
     if (!file_put_contents($tmp, $res)) {
         self::$error = __('Unable to write to cache folder.');
         return false;
     }
     chmod($tmp, 0777);
     return array('tmp_name' => $tmp, 'name' => $base);
 }
Esempio n. 3
0
/**
 * Fetch a remote URL using either cURL or fopen, depending
 * on which is available.
 */
function fetch_url($url)
{
    if (extension_loaded('curl')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_FAILONERROR, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setproxy($ch, $url);
        $res = curl_exec($ch);
        curl_close($ch);
        return $res;
    }
    return file_get_contents($url);
}