diff options
| author | Christian Schneider | 2011-12-09 16:45:14 +0000 | 
|---|---|---|
| committer | Christian Schneider | 2011-12-09 16:45:14 +0000 | 
| commit | ced5bfa06c5003ca03d17838c59e7bc4290c2d4d (patch) | |
| tree | 14d258f79254ea13fd980df76cc24e9231d97523 | |
| parent | a05213b1c5ae586fa9a0c2f898f46e128364aec9 (diff) | |
| download | itools-ced5bfa06c5003ca03d17838c59e7bc4290c2d4d.tar.gz itools-ced5bfa06c5003ca03d17838c59e7bc4290c2d4d.tar.bz2 itools-ced5bfa06c5003ca03d17838c59e7bc4290c2d4d.zip | |
Added parameter $p["returnheaders"] => true to return array($path, $headers) for url instead of only $path
| -rw-r--r-- | it_url.class | 14 | 
1 files changed, 12 insertions, 2 deletions
| diff --git a/it_url.class b/it_url.class index da6f033..cf7f45a 100644 --- a/it_url.class +++ b/it_url.class @@ -459,6 +459,7 @@ function get_cache_filename($p)   * @param $p['preprocess']  callback function (or array for methods) to change received file or array('function' => ..., 'in' => $src, 'out' => $dst, ...) with callback function plus args   * @param $p['safety']      value 0 means dont generate alert, value 1 means generate alerts on timeouts and failures   * @param $p['keepfailed']  keep old versions of files if download fails (sending alerts conservatively) + * @param $p['returnheaders'] Return array($path, $headers) instead of simply $path   * @param $p['it_error']    parameters for it::error()   */  function get_cache($p = array()) @@ -485,8 +486,13 @@ function get_cache($p = array())  				touch($path);  			EDC('getcache', "new", $filemtime, $p['url'], $path); -			if ($result = it_url::get($p + array('filemtime' => EDC('nocache') ? null : $filemtime)))	# => true means not modified (no new data fetched) +			$url = new it_url; +			if ($result = $url->get($p + array('filemtime' => EDC('nocache') ? null : $filemtime)))	# => true means not modified (no new data fetched) +			{  				$newfile = it_url::_atomicwrite($path, $result); +				if ($p['returnheaders']) +					file_put_contents("$path.headers", '<?php return ' . var_export($url->headers, true) . ";\n"); +			}  			else if ($p['keepfailed'])  				$result = $fileexists;  			else @@ -513,6 +519,10 @@ function get_cache($p = array())  		$result = true;	# Up to date  	} +	# Read headers before $path is modified for preprocessing +	if ($p['returnheaders']) +		$headers = @include("$path.headers"); +  	if ($result && $p['preprocess'])  	{  		$srcpath = $path; @@ -565,7 +575,7 @@ function get_cache($p = array())  	}  	EDC('getcache', $result, $path); -	return $result ? $path : false; +	return $result ? ($p['returnheaders'] ? array($path, $headers) : $path) : false;  }  /** |