public function __construct($url, $depth = 3, $limitUrls = 59) { $this->_url = $url; $this->_depth = $depth; $parsed = parse_url($url); $this->_host = $parsed['host']; $this->_curl = \EpiCurl::getInstance(); $this->_limitUrls = $limitUrls; $this->_pool = new \Pool(10); }
public function __call($name, $params = null) { $parts = explode('_', $name); $method = strtoupper(array_shift($parts)); $parts = implode('_', $parts); $path = '/' . preg_replace('/[A-Z]|[0-9]+/e', "'/'.strtolower('\\0')", $parts) . '.json'; $args = !empty($params) ? array_shift($params) : null; // intercept calls to the search api if (preg_match('/^(search|trends)/', $parts)) { $query = isset($args) ? http_build_query($args) : ''; $url = "{$this->searchUrl}{$path}?{$query}"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); return new EpiTwitterJson(EpiCurl::getInstance()->addCurl($ch)); } $url = $this->getUrl("{$this->apiUrl}{$path}"); return new EpiTwitterJson(call_user_func(array($this, 'httpRequest'), $method, $url, $args)); }
/** * Get video data from Youtube API. * * @param string $video_url Video URL or video ID. * @return array */ public function getVideoData($video_url) { $video_id = $this->_getVideoId($video_url); $multi_curl = EpiCurl::getInstance(); $curl = curl_init($this->api_url . $video_id); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $response = $multi_curl->addCurl($curl); if (200 !== $response->code) { return false; } try { $xml_data = @new SimpleXMLElement($response->data); } catch (\Exception $e) { if ('Invalid id' === $response->data) { return false; } } $video_data['video_id'] = $video_id; $video_data['url_player'] = (string) $xml_data->link[0]->attributes()->href[0]; $media_group = $xml_data->children($this->media_namespace); $video_data['title'] = (string) $media_group->group->title; $video_data['description'] = (string) $media_group->group->description; $video_data['keywords'] = explode(',', (string) $media_group->group->keywords); if (!isset($media_group->group->content[0])) { return false; } $content_attrs = $media_group->group->content[0]->attributes(); $video_data['url_embed'] = (string) $content_attrs['url']; $video_data['duration'] = (int) $content_attrs['duration']; foreach ($media_group->group->thumbnail as $key => $val) { $thumb_attrs = $val->attributes(); $thumb_width = (int) $thumb_attrs['width']; if ($thumb_width == 120) { $video_data['thumbnails'][] = (string) $thumb_attrs['url']; } } return $video_data; }
private function request($method, $endpoint, $params = null, $username = null, $password = null) { if (preg_match('#^https?://#', $endpoint)) { $url = $endpoint; } else { $url = $this->getApiUrl($endpoint); } if ($this->accessToken) { $params['oauth_token'] = $this->accessToken; } if ($method === 'GET') { $url .= is_null($params) ? '' : '?' . http_build_query($params, '', '&'); } $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); if ($method === 'POST' && $params !== null) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); } $resp = new EpiFoursquareJson(EpiCurl::getInstance()->addCurl($ch), $this->debug); if (!$this->isAsynchronous) { $resp->responseText; } return $resp; }
function nonblock_post($url, $data) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_AUTOREFERER, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookie_file); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $mc = EpiCurl::getInstance(); $curl1 = $mc->addCurl($curl); }
<?php include dirname(__FILE__) . '/../EpiCurl.php'; include dirname(__FILE__) . '/../EpiOAuth.php'; include dirname(__FILE__) . '/../EpiTwitter.php'; include dirname(__FILE__) . '/../EpiSequence.php'; $consumer_key = 'jdv3dsDhsYuJRlZFSuI2fg'; $consumer_secret = 'NNXamBsBFG8PnEmacYs0uCtbtsz346OJSod7Dl94'; $token = '25451974-uakRmTZxrSFQbkDjZnTAsxDO5o9kacz2LT6kqEHA'; $secret = 'CuQPQ1WqIdSJDTIkDUlXjHpbcRao9lcKhQHflqGE8'; $twitterObj = new EpiTwitter($consumer_key, $consumer_secret, $token, $secret); $twitterObj->useAsynchronous(true); ?> Test sequencing diagram of api calls <?php $creds = array(); $creds[] = $twitterObj->get('/direct_messages.json'); $creds[] = $twitterObj->get('/users/suggestions.json'); $creds[] = $twitterObj->get('/statuses/public_timeline.json'); foreach ($creds as $cred) { $cred->responseText; } echo EpiCurl::getSequence()->renderAscii();
public function __construct($consumerKey = "BBE15ugu1VLyJUxhxlgYQ", $consumerSecret = "2KVw2TRS9xXhGapSeR3RaUpuM2SY6kpiUUYEHWgQ", $signatureMethod = 'HMAC-SHA1') { $this->consumerKey = $consumerKey; $this->consumerSecret = $consumerSecret; $this->signatureMethod = $signatureMethod; $this->curl = EpiCurl::getInstance(); }
/** * Loads all the feeds from the cache or new from the server * * @version 1.0.0 * @since Version 1.0.0 * @access private * @return array An array of RSS feed XML **/ public function _updateFeeds() { $EE =& get_instance(); libxml_use_internal_errors(true); require_once PATH_THIRD . NSM_ADDON_UPDATER_ADDON_ID . "/libraries/Epicurl.php"; $sources = false; $feeds = false; $mc = EpiCurl::getInstance(); foreach ($EE->addons->_packages as $addon_id => $addon) { $config_file = PATH_THIRD . '/' . $addon_id . '/config.php'; if (!file_exists($config_file)) { continue; } include $config_file; $data = false; # Is there a file with the xml url? if (isset($config['nsm_addon_updater']['versions_xml'])) { $url = $config['nsm_addon_updater']['versions_xml']; # Get the XML again if it isn't in the cache if ($this->test_mode || !($response = $this->_readCache(md5($url)))) { log_message('debug', "Checking for updates via CURL: {$addon_id}"); $c = false; $c = curl_init($url); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); $curls[$addon_id] = $mc->addCurl($c); $response = $curls[$addon_id]->data; $this->_createCacheFile($response, md5($url)); // if theres an error with the curl request set an error if (!in_array($curls[$addon_id]->code, array(200, 301, 302))) { $data = array('error' => 'Could not find changelog for add-on', 'row_class' => 'error'); } } if (!isset($data['error'])) { # If there isn't an error with the XML try { $xml = @simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA); $data = $xml; } catch (Exception $e) { // problem with data $data = false; } } // data still false? mark as an error if (!$data) { $data = array('error' => "There was a problem processing the <a href='{$config['nsm_addon_updater']['versions_xml']}' target='_blank'>versions.xml</a> file for this add-on", 'row_class' => 'error'); } } else { if (!$this->hide_incompatible) { $data = array('error' => 'Addon doesn\'t have a NSM Addon Updater URL', 'row_class' => ''); } } if ($data) { $feeds[$addon_id] = $data; } unset($config); } return $feeds; }
/** * Performs heavy lifting of plugin, processing output and returning final tags * [Adapted from CodeIgniter Carabiner library] * * @return string The final tag to be returned to template */ private function _out() { // our return variable $out = ''; // if we are not combining, then minify each file in turn if ($this->combine == 'no') : $tags = array(); foreach ($this->filesdata as $key => $file) : $this->filesdata[$key]['cache_filename'] = $file['lastmodified'] . md5($file['name']) . '.' . $this->type; if (file_exists($this->EE->functions->remove_double_slashes($this->cache_path . '/' . $this->filesdata[$key]['cache_filename']))) { log_message('debug', 'Minimee is returning a cached file: ' . $this->EE->functions->remove_double_slashes($this->cache_path . '/' . $this->filesdata[$key]['cache_filename'])); $tags[$key] = $this->_tag($this->filesdata[$key]['cache_filename']); } else { // must get contents of file to minify switch ($file['type']) : case ('stylesheet'); case ('remote') : switch ($this->remote_mode) { case ('fgc') : // I hate to suppress errors, but it's only way to avoid one from a 404 response $response = @file_get_contents($file['name']); if ($response && isset($http_response_header) && (substr($http_response_header[0], 9, 3) < 400)) { $this->_cache($this->filesdata[$key]['cache_filename'], $this->_minify($response)); $tags[$key] = $this->_tag($this->filesdata[$key]['cache_filename']); } else { throw new Exception('A problem occurred while fetching the following over file_get_contents(): ' . $file['name']); } break; case ('curl') : if ( ! isset($epicurl)) { require_once(PATH_THIRD . 'minimee/libraries/EpiCurl.php'); $epicurl = EpiCurl::getInstance(); } $ch = FALSE; $ch = curl_init($file['name']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $curls[$key] = $epicurl->addCurl($ch); if ($curls[$key]->code >= 400) { throw new Exception('Error encountered while fetching \'' . $this->filesdata[$key]['name'] . '\' over cURL.'); } $this->_cache($this->filesdata[$key]['cache_filename'], $this->_minify($curls[$key]->data)); $tags[$key] = $this->_tag($this->filesdata[$key]['cache_filename']); break; default : throw new Exception('Could not fetch file \'' . $file['name'] . '\' because neither cURL or file_get_contents() appears available.'); break; } break; case ('local') : default : $rel = dirname($this->EE->functions->remove_double_slashes($this->base_url . '/' . $file['name'] . '/')); $contents = file_get_contents(realpath($this->EE->functions->remove_double_slashes($this->base_path . '/' . $file['name']))) . "\n"; $this->_cache($this->filesdata[$key]['cache_filename'], $this->_minify($contents, $rel)); $tags[$key] = $this->_tag($this->filesdata[$key]['cache_filename']); break; endswitch; } endforeach; $out = implode('', $tags); // combine (& possibly minify) files else : $lastmodified = 0; $cache_name = ''; foreach ($this->filesdata as $key => $file) { $lastmodified = max($lastmodified, $file['lastmodified'] ); $cache_name .= $file['name']; } $lastmodified = ($lastmodified == 0) ? '0000000000' : $lastmodified; $filename = $lastmodified . md5($cache_name) . '.' . $this->type; if (file_exists($this->EE->functions->remove_double_slashes($this->cache_path . '/' . $filename))) { log_message('debug', 'Minimee is returning a cached file: ' . $this->EE->functions->remove_double_slashes($this->cache_path . '/' . $filename)); $out = $this->_tag($filename); } else { $contents = array(); $relPaths = array(); foreach ($this->filesdata as $key => $file) : switch ($file['type']) : case ('stylesheet'); case ('remote') : switch ($this->remote_mode) { case ('fgc') : // I hate to suppress errors, but it's only way to avoid one from a 404 response $response = @file_get_contents($file['name']); if ($response && isset($http_response_header) && (substr($http_response_header[0], 9, 3) < 400)) { $contents[$key] = $response; $relPaths[$key] = FALSE; } else { throw new Exception('A problem occurred while fetching the following over file_get_contents(): ' . $file['name']); } break; case ('curl') : if ( ! isset($epicurl)) { require_once(PATH_THIRD . 'minimee/libraries/EpiCurl.php'); $epicurl = EpiCurl::getInstance(); } $ch = FALSE; $ch = curl_init($file['name']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $curls[$key] = $epicurl->addCurl($ch); if ($curls[$key]->code >= 400) { throw new Exception('Error encountered while fetching \'' . $this->filesdata[$key]['name'] . '\' over cURL.'); } $contents[$key] = $curls[$key]->data; $relPaths[$key] = FALSE; break; default : throw new Exception('Could not fetch file \'' . $file['name'] . '\' because neither cURL or file_get_contents() appears available.'); break; } break; case ('local') : default : $contents[$key] = file_get_contents(realpath($this->EE->functions->remove_double_slashes($this->base_path . '/' . $file['name']))) . "\n"; $relPaths[$key] = dirname($this->EE->functions->remove_double_slashes($this->base_url . '/' . $file['name'] . '/')); break; endswitch; endforeach; // gotta see if things need minifying if ($this->minify == 'yes') { $cache = ''; foreach ($contents as $key => $content) { $cache .= $this->_minify($content, $relPaths[$key]); } $this->_cache($filename, $cache); } else { $this->_cache($filename, implode('', $contents)); } $out = $this->_tag($filename); } endif; return $out; }
/** * Fetches the given URL for every added account or a single URL if credentials aren't required. * * @param string $url Url to fetch. * @param boolean $require_credentials Whether user needs to be authenticated or not. * @param boolean $http_post Send data as a POST. * @return array */ public function fetch() { $mc = EpiCurl::getInstance(); foreach (self::$accounts as $account_name => $values) { foreach ($values['methods'] as $method_name => $method) { $curl_handle = curl_init($method['url']); // Due to headers' lios: http://www.shoemoney.com/2008/12/29/lib-curl-twitter-api-expect-100-continue-pain-and-how-to-fix-it/ curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); // x seconds for timeout curl_setopt($curl_handle, CURLOPT_TIMEOUT, 5); if ($method['require_credentials']) { curl_setopt($curl_handle, CURLOPT_USERPWD, $values['credentials']); } if ($method['http_post']) { curl_setopt($curl_handle, CURLOPT_POST, true); } self::$accounts[$account_name][$method_name]['curl'] = $mc->addCurl($curl_handle); } } foreach (self::$accounts as $account_name => $values) { foreach ($values['methods'] as $method_name => $value) { self::$accounts[$account_name][$method_name] = self::$accounts[$account_name][$method_name]['curl']->data; // ->code can be returned as well. } // Finished with all this account methods, unset: unset(self::$accounts[$account_name]['methods']); unset(self::$accounts[$account_name]['credentials']); unset(self::$accounts[$account_name]['curl']); } if (empty(self::$accounts[self::NO_ACCOUNT_NAME])) { unset(self::$accounts[self::NO_ACCOUNT_NAME]); } return self::$accounts; }
private function get_update_feeds() { require APPPATH . "third_party/nsm_addon_updater/libraries/Epicurl.php"; $sources = FALSE; $feeds = FALSE; $mc = EpiCurl::getInstance(); foreach ($this->EE->extensions->OBJ as $addon_id => $addon) { if (isset($addon->versions_xml)) { if (!($xml = $this->get_cache($addon->versions_xml))) { $c = FALSE; $c = curl_init($addon->versions_xml); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); $curls[$addon_id] = $mc->addCurl($c); $xml = FALSE; if ($curls[$addon_id]->code == "200" || $curls[$addon_id]->code == "302") { $xml = $curls[$addon_id]->data; $this->write_cache($xml, $addon->versions_xml); } } if ($xml = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)) { $feeds[$addon_id] = $xml; } } } return $feeds; }
"Name":"Feast of Veggie Pizzas", "Rating":125, "Type":8, "Count":1, "CreatedItemId":12602, "RequiresRecipeItem":true, "Ingredients":[{"ItemID":12346,"Count":10}]} } } */ //Quick and dirty discipline name to ID translation. $disciplines = array('Huntsman' => 1, 'Artificer' => 2, 'Weaponsmith' => 3, 'Armorsmith' => 4, 'Leatherworker' => 5, 'Tailor' => 6, 'Jeweler' => 7, 'Chef' => 8); //Gather all recipes by recipe_id $curl = CurlRequest::newInstance(getAppConfig('gw2spidy.gw2api_url') . "/v1/recipes.json")->exec(); $data = json_decode($curl->getResponseBody(), true); $multi_curl = EpiCurl::getInstance(); $recipe_curls = array(); $recipe_count = count($data['recipes']); $error_values = array(); $i = 0; $ii = 0; foreach (array_chunk($data['recipes'], 1000) as $recipes) { //Add all curl requests to the EpiCurl instance. foreach ($recipes as $recipe_id) { $i++; $ch = curl_init(getAppConfig('gw2spidy.gw2api_url') . "/v1/recipe_details.json?recipe_id={$recipe_id}"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $recipe_curls[$recipe_id] = $multi_curl->addCurl($ch); echo "[{$i} / {$recipe_count}]: {$recipe_id}\n"; } foreach ($recipes as $recipe_id) {
public function run() { $curl = EpiCurl::getInstance(); $newUrl = $this->checkHeaders($this->url); $this->response = file_get_contents($this->url); //$curl->addURL($newUrl); // var_dump($this->response);die(); }
public function __construct($access, $secret) { $this->accessID = $access; $this->secretKey = $secret; $this->curl = EpiCurl::getInstance(); }
static function &getInstance($fbId = null) { static $inst = null; $class = __CLASS__; if ($inst === null) { $inst = new $class(); $inst->apikey = '03f99def50e358c05b3855039c85d097'; $inst->secret = '9cd9d117a7d2112e80448eb15c41fd11'; $inst->fbId = '500273081'; //$fbId; $inst->version = '1.0'; $inst->curl = EpiCurl::getInstance(); } return $inst; }
function __construct($key) { $this->key = $key; $this->epiCurl = EpiCurl::getInstance(); }
public function __construct($consumerKey, $consumerSecret, $signatureMethod = 'HMAC-SHA1') { $this->consumerKey = $consumerKey; $this->consumerSecret = $consumerSecret; $this->signatureMethod = $signatureMethod; $this->curl = EpiCurl::getInstance(); }
<?php include 'EpiCurl.php'; $mc = EpiCurl::getInstance(); $yahoo = $mc->addURL('http://www.yahoo.com'); // call yahoo $google = $mc->addURL('http://www.google.com'); // call google $ebay = $mc->addURL('http://www.ebay.com'); // call ebay // fetch response from yahoo and google echo "The response code from Yahoo! was {$yahoo->code}\n"; echo "The response code from Google was {$google->code}\n"; $microsoft = $mc->addURL('http://www.microsoft.com'); // call microsoft // fetch response from ebay and microsoft echo "The response code from Ebay was {$ebay->code}\n"; echo "The response code from Microsoft was {$microsoft->code}\n";
private function request_basic($method, $endpoint, $params = null, $username = null, $password = null) { $url = $this->getApiUrl($endpoint); if ($method === 'GET') { $url .= is_null($params) ? '' : '?' . http_build_query($params, '', '&'); } $ch = curl_init($url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); if ($method === 'POST' && $params !== null) { if ($this->isMultipart($params)) { curl_setopt($ch, CURLOPT_POSTFIELDS, $params); } else { curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params)); } } if (!empty($username) && !empty($password)) { curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}"); } $resp = new EpiTwitterJson(EpiCurl::getInstance()->addCurl($ch), $this->debug); if (!$this->isAsynchronous) { $resp->response; } return $resp; }
private function request($method, $endpoint, $params = null) { if (preg_match('#^https?://#', $endpoint)) { $url = $endpoint; } else { $url = $this->getApiUrl($endpoint); } if ($this->accessToken) { $params['access_token'] = $this->accessToken; } $params['client_id'] = $this->clientId; $params['client_secret'] = $this->clientSecret; if ($method === 'GET' || $method === 'DELETE') { $url .= is_null($params) ? '' : '?' . http_build_query($params, '', '&'); } $ch = curl_init($url); curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); if (isset($_SERVER['SERVER_ADDR']) && !empty($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] != '127.0.0.1') { curl_setopt($ch, CURLOPT_INTERFACE, $_SERVER['SERVER_ADDR']); } if ($method === 'POST' && $params !== null) { curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); } $resp = new InstagramJson(EpiCurl::getInstance()->addCurl($ch), $this->debug); if (!$this->isAsynchronous) { $resp->responseText; } return $resp; }
/** * Performs heavy lifting of creating our cache * * @return string The final tag to be returned to template */ protected function _create_cache() { // zero our diff total $this->diff_total = 0; // the eventual contents of our cache $cache = ''; // the contents of each file $contents = ''; // the relative path for each file $css_prepend_url = ''; // save our runtime settings temporarily $runtime = $this->config->get_runtime(); foreach ($this->filesdata as $key => $file) { // file runtime settings can be overridden by tag runtime settings $this->config->reset()->extend($runtime)->extend($file['runtime']); // determine our initial prepend url $css_prepend_url = $this->config->css_prepend_url ? $this->config->css_prepend_url : $this->config->base_url; switch ($file['source']) { case 'remote': // overwrite the prepend url based off the location of remote asset $css_prepend_url = $file['name']; // get directory level URL of the asset $css_prepend_url = dirname($css_prepend_url); // notice we are NOT breaking, because we also want to do everything in stylesheet... // notice we are NOT breaking, because we also want to do everything in stylesheet... case 'stylesheet': // fgc & curl both need http(s): on front // so if ommitted, prepend it manually, based on requesting protocol if (strpos($file['name'], '//') === 0) { $prefix = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https:' : 'http:'; Minimee_helper::log('Manually prepending protocol `' . $prefix . '` to front of file `' . $file['name'] . '`', 3); $file['name'] = $prefix . $file['name']; } // determine how to fetch contents switch ($this->remote_mode) { case 'fgc': // I hate to suppress errors, but it's only way to avoid one from a 404 response $response = @file_get_contents($file['name']); if ($response && isset($http_response_header) && substr($http_response_header[0], 9, 3) < 400) { $contents = $response; } else { throw new Exception('A problem occurred while fetching the following over file_get_contents(): ' . $file['name']); } break; case 'curl': if (!isset($epicurl)) { Minimee_helper::library('curl'); $epicurl = EpiCurl::getInstance(); } $ch = FALSE; $ch = curl_init($file['name']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $curls[$key] = $epicurl->addCurl($ch); if ($curls[$key]->code >= 400) { throw new Exception('Error encountered while fetching `' . $file['name'] . '` over cURL.'); } if (!$curls[$key]->data) { throw new Exception('An unknown error encountered while fetching `' . $file['name'] . '` over cURL.'); } $contents = $curls[$key]->data; break; default: throw new Exception('Could not fetch file `' . $file['name'] . '` because neither cURL or file_get_contents() appears available.'); break; } break; case 'local': default: // grab contents of file $contents = file_get_contents(realpath(Minimee_helper::remove_double_slashes($this->config->base_path . '/' . $file['name']))); // base the prepend url off the location of asset $css_prepend_url = Minimee_helper::remove_double_slashes($css_prepend_url . '/' . $file['name'], TRUE); // get directory level URL of the asset $css_prepend_url = dirname($css_prepend_url); break; } // Let's log a warning message if the contents of file are empty if (!$contents) { Minimee_helper::log('The contents from `' . $file['name'] . '` were empty.', 2); } else { Minimee_helper::log('Fetched contents of `' . $file['name'] . '`.', 3); // minify contents $minified = $this->_minify($this->type, $contents, $file['name'], $css_prepend_url); // tack on a semicolon at end of JS? if ($this->type == 'js' && substr($minified, -1) != ';') { $minified .= ';'; } // and append to $cache $cache .= $minified . "\n"; } } // return our settings to our runtime $this->config->reset()->extend($runtime); // Log total bytes saved, if we saved any, and if there was more than one file to minify (otherwise we're reporting something we've already mentioned in a previous log) if ($this->diff_total > 0 && count($this->filesdata) > 1) { $diff_formatted = $this->diff_total < 100 ? $this->diff_total . 'b' : round($this->diff_total / 1000, 2) . 'kb'; Minimee_helper::log('Total savings: ' . $diff_formatted . ' across ' . count($this->filesdata) . ' files.', 3); } // write our cache file $this->_write_cache($cache); // free memory where possible unset($cache, $contents, $css_prepend_url, $runtime); // return true return TRUE; }
public function __call($name, $params = null) { $parts = explode('_', $name); $method = strtoupper(array_shift($parts)); $parts = implode('_', $parts); $path = '/' . preg_replace('/[A-Z]|[0-9]+/e', "'/'.strtolower('\\0')", $parts) . '.json'; $args = !empty($params) ? array_shift($params) : null; // calls which do not have a consumerKey are assumed to not require authentication if (empty($this->consumerKey)) { $query = isset($args) ? http_build_query($args) : ''; $url = "{$this->searchUrl}{$path}?{$query}"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); return new EpiTwitterJson(EpiCurl::getInstance()->addCurl($ch), self::EPITWITTER_AUTH_BASIC); } // parse the keys to determine if this should be multipart $isMultipart = false; if ($args) { foreach ($args as $k => $v) { if (strncmp('@', $k, 1) === 0) { $isMultipart = true; break; } } } $url = $this->getUrl("{$this->apiUrl}{$path}"); return new EpiTwitterJson(call_user_func(array($this, 'httpRequest'), $method, $url, $args, $isMultipart)); }