cacheFolder = str_replace('/', DS, $this->cacheFolder); if ($this->cacheFolder=='web' || empty($this->cacheFolder)) $this->cacheFolder = 'web'.DS; if (substr($this->cacheFolder, -1, 1)!=DS) $this->cacheFolder = $this->cacheFolder.DS; } function httpPost($url, $vars = null, $headers = null, $cookie_file = null, $timeout = null) { $vars = $this->__toUrlData($vars); $ch = curl_init(); if (! $ch) { return false; } curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Don't check certifications that closley if not required, fixed some issues for me before if ($this->ssl_strict==false) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); } curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); if (empty($timeout)) $timeout = $this->connection_timeout; curl_setopt($ch,CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); // follow redirects recursively if (!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); if (!empty($cookie_file)) { curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); } $response = curl_exec($ch); curl_close($ch); return $response; } function httpGet($url, $vars = null, $headers = null, $cookie_file = null, $timeout = null) { if (!empty($vars)) $url = $url.'?'.$this->__toUrlData($vars); $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Don't check certifications that closley if not required, fixed some issues for me before if ($this->ssl_strict==false) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); } curl_setopt($ch, CURLOPT_URL, $url); if (empty($timeout)) $timeout = $this->connection_timeout; curl_setopt($ch,CURLOPT_TIMEOUT, $timeout); if (!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); if (!empty($cookie_file)) { curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); } curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper('get')); curl_setopt($ch, CURLOPT_VERBOSE, 1); ########### debug curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); // follow redirects recursively $ret = curl_exec($ch); curl_close($ch); return $ret; } function cleanUpCacheFolder($expires = '+2 hours', $pattern = '.*') { uses('Folder'); $path = TMP.'cache'.DS.$this->cacheFolder; $folder =& new Folder($path); $cachedFiles = $folder->find(); if (!is_numeric($expires)) { $expires = strtotime($expires); } $errors = array(); foreach ($cachedFiles as $cacheFile) { if (preg_match('/'.$pattern.'/iUs', $cacheFile)) { $age = time() - @filemtime($path.$cacheFile); $maxAge = $expires - time(); if ($age >= $maxAge) { // Well R.I.P. dear cache file ; ) if (!@unlink($path.$cacheFile)) { $errors[] = $cacheFile; } } } } if (empty($errors)) return true; else return $errors; } function __toUrlData($arrayData) { $postData = array(); foreach ($arrayData as $key => $val) { array_push($postData, $key.'='.urlencode($val)); } return join('&', $postData); } /** * Creates a unique cache file path by combining all parameters given to a unique MD5 hash * * @param string $ext The extension for the cache file * @return string Returns a unique file path */ function __createCacheHash($ext = '.txt') { $args = func_get_args(); array_shift($args); $hashSource = null; foreach ($args as $arg) { $hashSource = $hashSource . serialize($arg); } return md5($hashSource).$ext; } } ?>