/** * Fetch a new feed. */ private function fetch() { if (!$this->url) { return false; } $this->posted = array(); $this->skipped = array(); $this->duplicate = array(); $this->lastReturned = 0; $this->time = ''; $this->cachedTime = ''; global $idfeedversion; $http = new http_request($this->getFullURL()); $http->set_useragent("EDK IDFeedfetcher " . $idfeedversion); $http->set_timeout(300); //accept gzip encoding $http->set_header('Accept-Encoding: gzip'); if (strpos($http->get_header(), 'Content-Encoding: gzip') !== false) { $this->xml = gzdecode($http->get_content()); } else { $this->xml = $http->get_content(); } if ($http->get_http_code() != 200) { trigger_error("HTTP error " . $http->get_http_code() . " while fetching feed from " . $this->url . $options . ".", E_USER_WARNING); return false; } if ($this->xml) { return true; } else { return false; } }
/** * Fetch an image from the image server. * * Returns the image resource or false on failure. * @param integer $id * @param integer $size * @return resource|boolean The image resource or false on failure. */ private static function fetchImage($id, $size = 64) { $url = 'http://' . IMG_SERVER . "/" . "InventoryType" . "/" . $id . "_" . $size . ".png"; if (function_exists('curl_init')) { // in case of a dead eve server we only want to wait 2 seconds @ini_set('default_socket_timeout', 2); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); $file = curl_exec($ch); //list($header, $file) = explode("\n\n", $file, 2); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } else { // in case of a dead eve server we only want to wait 2 seconds @ini_set('default_socket_timeout', 2); // try alternative access via fsockopen // happens if allow_url_fopen wrapper is false $http = new http_request($url); $file = $http->get_content(); $http_code = $http->get_http_code(); } return @imagecreatefromstring($file); }
private function loaddata($id) { $url = API_SERVER . "/eve/CharacterInfo.xml.aspx?characterID=" . urlencode($id); $http = new http_request($url); $http->set_useragent("PHPApi"); return $http->get_content(); }
function loaddata($keystring, $typestring) { $configvalue = $this->API_characterID_ . '_Standings'; $UseCaching = config::get('API_UseCache'); $url = API_SERVER . "/" . $typestring . "/Standings.xml.aspx" . $keystring; $path = "/" . $typestring . "/Standings.xml.aspx"; if (is_file(KB_CACHEDIR . '/api/' . $configvalue . '.xml')) { $cacheexists = true; } else { $cacheexists = false; } if (strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0 || $UseCaching == 1 || !$cacheexists) { $http = new http_request($url); $http->set_useragent("PHPApi"); foreach ($keystring as $key => $val) { $http->set_postform($key, $val); } $contents = $http->get_content(); $start = strpos($contents, "?>"); if ($start !== FALSE) { $contents = substr($contents, $start + strlen("\r\n\r\n")); } if ($UseCaching == 0) { $file = fopen(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 'w+'); fwrite($file, $contents); fclose($file); @chmod(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 0666); } } else { // re-use cached XML if ($fp = @fopen(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 'r')) { $contents = fread($fp, filesize(KB_CACHEDIR . '/api/' . $configvalue . '.xml')); fclose($fp); } else { return "<i>error loading cached file " . $configvalue . ".xml</i><br><br>"; } } return $contents; }
function loaddata($keystring) { $configvalue = $this->CharName_ . '_CharacterSheet'; $CachedTime = ApiCache::get($configvalue); $UseCaching = config::get('API_UseCache'); $url = API_SERVER . "/char/CharacterSheet.xml.aspx" . $keystring; $path = '/char/CharacterSheet.xml.aspx'; // API Caching system, If we're still under cachetime reuse the last XML, if not download the new one. Helps with Bug hunting and just better all round. if ($CachedTime == "") { $CachedTime = "2005-01-01 00:00:00"; // fake date to ensure that it runs first time. } if (is_file(KB_CACHEDIR . '/api/' . $configvalue . '.xml')) { $cacheexists = true; } else { $cacheexists = false; } // if API_UseCache = 1 (off) then don't use cache if (strtotime(gmdate("M d Y H:i:s")) - strtotime($CachedTime) > 0 || $UseCaching == 1 || !$cacheexists) { $http = new http_request($url); $http->set_useragent("PHPApi"); foreach ($keystring as $key => $val) { $http->set_postform($key, $val); } $contents = $http->get_content(); $start = strpos($contents, "?>"); if ($start !== FALSE) { $contents = substr($contents, $start + strlen("\r\n\r\n")); } // Save the file if we're caching (0 = true in Thunks world) if ($UseCaching == 0) { $file = fopen(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 'w+'); fwrite($file, $contents); fclose($file); @chmod(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 0666); } } else { // re-use cached XML if ($fp = @fopen(KB_CACHEDIR . '/api/' . $configvalue . '.xml', 'r')) { $contents = fread($fp, filesize(KB_CACHEDIR . '/api/' . $configvalue . '.xml')); fclose($fp); } else { return "<i>error loading cached file " . $configvalue . ".xml</i><br><br>"; } } return $contents; }
public static function xajax_req() { // if the xajax call gets aborted, ignore that @ignore_user_abort(true); @set_time_limit(0); $state = config::get('ajcron_running'); if (!is_array($state)) { $state = array(); config::set('ajcron_running', $state); } // check for blocking if (config::get('ajcron_blocking')) { // if there is already something running, give up if (count($state) >= 1) { return; } } // load up our crontasks $jobs = ajcron::parseJobs(); // if there are no jobs just quit if (!count($jobs)) { return; } // see which one should be started now $sorttable = array(); foreach ($jobs as $job) { $sorttable[$job['id']] = $job['nextrun']; } asort($sorttable); foreach ($sorttable as $id => $nextrun) { // this bypasses already running jobs if (isset($state[$id])) { continue; } break; } if (!$id) { // no id found we could run as all are running return; } // set current id to running $state[$id] = 'running'; $currentJob = null; config::set('ajcron_running', $state); foreach ($jobs as $job) { if ($job['id'] == $id) { $currentJob = $job; } } // run the job (finally) $http = new http_request($currentJob['url']); $http->set_timeout(120); $data = $http->get_content(); // job done, clean up // we need to refresh our variable to prevent overwriting of // other running jobs $db = DBFactory::getDBQuery(true); $db->execute('select * from kb3_config where cfg_site=\'' . KB_SITE . '\' and cfg_key=\'ajcron_running\''); $row = $db->getRow(); $state = unserialize($row['cfg_value']); unset($state[$id]); config::set('ajcron_running', $state); // calculate when next to insert ajax ajcron::getNextRuntime(); // testfun! $objResponse = new xajaxResponse(); #$objResponse->Assign("header", "innerHTML", nl2br(var_export($sorttable[key($sorttable)], true))); #sleep(15); return $objResponse; }
$trouble['Graphics'][] = array('passed' => false, 'text' => $html); } // connectivity $sections['Connectivity'] = 'Connectivity'; $url = 'http://www.evekb.org/'; if (ini_get('allow_url_fopen')) { if (count(file($url))) { $html = ' allow_url_fopen is available.<br />'; $trouble['Connectivity'][] = array('passed' => true, 'text' => $html); } else { $html = ' I could not get the file, this might be a firewall related issue or the eve-dev server is not available.<br />'; $trouble['Connectivity'][] = array('passed' => false, 'text' => $html); } } $http = new http_request($url); if ($http->get_content()) { $html = ' Socket Connect is available.'; $trouble['Connectivity'][] = array('passed' => true, 'text' => $html); } else { $html = ' I could not get the file, this might be a firewall related issue or the eve-dev server is not available.<br />'; $trouble['Connectivity'][] = array('passed' => false, 'text' => $html); } if (extension_loaded('openssl')) { $html = ' OpenSSL module is installed.<br />'; $trouble['Connectivity'][] = array('passed' => true, 'text' => $html); } else { $html = ' OpenSSL module is not installed<br />'; $trouble['Connectivity'][] = array('passed' => false, 'text' => $html); } if (array_search('https', stream_get_wrappers())) { $html = ' HTTPS wrapper is installed.';
} else { $stoppage = true; $smarty->assign('conf_conditional', true); $smarty->assign('conf_image', $fail_img); } // connectivity $url = 'http://www.evekb.org/'; $smarty->assign('conn_url', $url); $smarty->assign('conn_fopen_exists', ini_get('allow_url_fopen')); $smarty->assign('conn_image', $pass_img); if (ini_get('allow_url_fopen')) { $smarty->assign('conn_fopen_success', count(file($url))); } else { include '../common/includes/class.httprequest.php'; $http = new http_request($url); $smarty->assign('conn_http_success', $http->get_content()); if (!$http->get_content()) { $smarty->assign('conn_image', $amb_img); } } $smarty->assign('conn_curl_exists', function_exists('curl_init')); if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $content = curl_exec($ch); curl_close($ch); if ($content) { $smarty->assign('conn_curl_success', true); } }
function fetchImage($id, $type = 'Character', $size = 128, $ext = "jpg") { include_once 'kbconfig.php'; require_once 'common/includes/globals.php'; require_once "common/includes/class.cachehandler.php"; $url = 'http://' . IMG_SERVER . "/" . $type . "/" . $id . "_" . $size . "." . $ext; if (function_exists('curl_init')) { // in case of a dead eve server we only want to wait 2 seconds @ini_set('default_socket_timeout', 2); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); // CURLOPT_FOLLOWLOCATION doesn't work if safe mode or open_basedir is set // For pilots we should try from oldportraits.eveonline.com if the main server doesn't have them. //if($type != 'Character') curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //curl_setopt($ch, CURLOPT_HEADER, true); $file = curl_exec($ch); //list($header, $file) = explode("\n\n", $file, 2); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code != 200) { if ($type == 'Character') { $url = "http://oldportraits.eveonline.com/Character/" . $id . "_" . $size . "." . $ext; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $file = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($http_code != 200) { $file = file_get_contents("img/1_{$size}.jpg"); } } else { if ($type == 'Alliance') { $file = file_get_contents("img/alliances/default.png"); } else { if ($type == 'Corporation') { $file = file_get_contents("img/corps/default.png"); } else { show404(); } } } } curl_close($ch); } else { require_once 'common/includes/class.httprequest.php'; // in case of a dead eve server we only want to wait 2 seconds @ini_set('default_socket_timeout', 2); // try alternative access via fsockopen // happens if allow_url_fopen wrapper is false $http = new http_request($url); $file = $http->get_content(); $http_code = $http->get_http_code(); if ($http_code != 200) { if ($type == 'Character') { $url = "http://oldportraits.eveonline.com/Character/" . $id . "_" . $size . "." . $ext; $http = new http_request($url); $file = $http->get_content(); $http_code = $http->get_http_code(); if ($http_code != 200) { $file = file_get_contents("img/1_{$size}.jpg"); } } else { if ($type == 'Alliance') { $file = file_get_contents("img/alliances/default.png"); } else { if ($type == 'Corporation') { $file = file_get_contents("img/corps/default.png"); } else { show404(); } } } } } if ($img = @imagecreatefromstring($file)) { CacheHandler::put($id . '_' . $size . '.' . $ext, $file, 'img'); } return $img; }