private function saveFileFromWeb($fieldName) { if ($this->has($fieldName) && (substr(strtolower($this->get($fieldName)), 0, 7) === 'http://' || substr(strtolower($this->get($fieldName)), 0, 8) === 'https://')) { // load file from web $image = Ajde_Http_Curl::get($this->get($fieldName)); // extract filename (without extension) $basename = basename(parse_url($this->get($fieldName), PHP_URL_PATH)); $filename = preg_replace('/[^A-Za-z0-9_\\-]/', '_', $this->get($this->usernameField)) . '_' . pathinfo($basename, PATHINFO_FILENAME); // save to tmp directory $tmp_path = TMP_DIR . $filename; $fh = fopen($tmp_path, 'wb'); fwrite($fh, $image); fclose($fh); // get mime type $mimeType = Ajde_Fs_File::getMimeType($tmp_path); // unlink tmp file unlink($tmp_path); // get default extension $extension = Ajde_Fs_File::getExtensionFromMime($mimeType); // don't overwrite previous files that were uploaded while (is_file(LOCAL_ROOT . AVATAR_DIR . $filename . '.' . $extension)) { $filename .= rand(10, 99); } // save to avatar directory $path = AVATAR_DIR . $filename . '.' . $extension; $fh = fopen($path, 'wb'); fwrite($fh, $image); fclose($fh); $this->set($fieldName, $filename . '.' . $extension); } }
/** * @param string $html * * @return mixed */ public static function inlineCss($html) { $url = 'http://premailer.dialect.ca/api/0.1/documents'; $data = ['html' => $html, 'preserve_styles' => 'false']; $json = Ajde_Http_Curl::post($url, $data); $result = @json_decode($json); if (is_object($result) && isset($result->documents)) { $url = $result->documents->html; return Ajde_Http_Curl::get($url); } return $html; }
public function getThumbnail() { $vmid = $this->_getVimeoId(); if ($vmid) { $response = Ajde_Http_Curl::get("http://vimeo.com/api/v2/video/{$vmid}.php"); try { $hash = unserialize($response); } catch (Exception $e) { Ajde_Exception_Log::logException(new Ajde_Exception('Could not parse result from Vimeo')); return; } return $hash[0]['thumbnail_large']; } }
public function getThumbnail() { $url = $this->_getMixcloudUrl(); if ($url) { $html = Ajde_Http_Curl::get($url); $matches = []; preg_match('%og:image\\" content=\\"(.+?)\\"%', $html, $matches); // we get .png, we want .jpg if (isset($matches[1])) { return $matches[1]; } return; } }
public function getThumbnail() { if (substr($this->_code, 0, 7) == 'http://' || substr($this->_code, 0, 8) == 'https://') { $apiUrl = 'http://api.soundcloud.com/resolve.json?url=' . urlencode($this->_code) . '&client_id=' . $this->_key(); $hash = json_decode(Ajde_Http_Curl::get($apiUrl)); return str_replace('large.jpg', 't300x300.jpg', $hash->artwork_url); } else { $url = $this->_getSoundcloudUrl(); if ($url) { $apiUrl = $url . '.json?client_id=' . $this->_key(); $hash = json_decode(Ajde_Http_Curl::get($apiUrl)); return str_replace('large.jpg', 't300x300.jpg', $hash->artwork_url); } } }
#!/usr/bin/php <?php include 'private/lib/Ajde/Http/Curl.php'; $e = Ajde_Http_Curl::get('http://updatemybrowser.org/admin/cron.html'); echo $e;
public function saveFileFromDrive($filename, $oauthToken) { if ($filename && $oauthToken && $this->has('pointer') && substr(strtolower($this->pointer), 0, 24) === 'https://drive.google.com') { $basename = basename(parse_url($filename, PHP_URL_PATH)); $filename = pathinfo($basename, PATHINFO_FILENAME); $ext = pathinfo($basename, PATHINFO_EXTENSION); if (strtolower($ext) === 'jpeg') { $ext = 'jpg'; } if (!$this->replaceOldFile) { // don't overwrite previous files that were uploaded while (is_file(LOCAL_ROOT . $this->uploadDirectory . $filename . '.' . $ext)) { $filename .= rand(10, 99); } } $path = $this->uploadDirectory . $filename . '.' . $ext; $curlResult = Ajde_Http_Curl::get($this->pointer, $path, ['Authorization: Bearer ' . $oauthToken]); // $curlResult = Ajde_Http_Curl::get($this->pointer, $path); if (!$curlResult) { return 'error'; } $this->name = $filename; $this->pointer = $filename . '.' . $ext; $this->thumbnail = $this->pointer; return true; } return false; }
/** * {@inheritdoc} */ public function update() { $url = 'https://raw.githubusercontent.com/Fyrd/caniuse/master/fulldata-json/data-2.0.json'; $this->browsers = @json_decode(Ajde_Http_Curl::get($url)); }
private function web2pdf($url, $filename = null) { $web2pdfRoot = config('misc.pdf.web2PdfApi'); $api = $web2pdfRoot . '?url=' . urlencode($url) . '&filename=' . urlencode($filename); return Ajde_Http_Curl::get($api); }
/** * {@inheritdoc} */ public function update() { $url = 'http://fresh-browsers.com/export/browsers.serialized'; $this->browsers = unserialize(Ajde_Http_Curl::get($url)); }