diff options
author | Christian Schneider | 2007-05-22 12:55:12 +0000 |
---|---|---|
committer | Christian Schneider | 2007-05-22 12:55:12 +0000 |
commit | ab24be9f1d2de80ff3288ed3d7a8063a88db4156 (patch) | |
tree | 8560e72ebfac8ec81276d7d0d924eeed7d10396f | |
parent | e21ff4047b8c1e19acba0cf1a2531f3716038064 (diff) | |
download | itools-ab24be9f1d2de80ff3288ed3d7a8063a88db4156.tar.gz itools-ab24be9f1d2de80ff3288ed3d7a8063a88db4156.tar.bz2 itools-ab24be9f1d2de80ff3288ed3d7a8063a88db4156.zip |
Enhanced preprocess parameter to also allow passing of arguments
-rw-r--r-- | url.class | 24 |
1 files changed, 14 insertions, 10 deletions
@@ -337,15 +337,15 @@ function get_cache_filename($p) /** * Store contents of url in a file and return file name. Provides locking. Call statically. * Requires www writeable var/urlcache in your service dir. Params in assoc array: - * @url url to get - * @timeout timeout in milliseconds, default 10000 - * @maxage maximum age of cache entries in seconds, default 86400 - * @cleanbefore maximum daytime when attempting cleanup, default 7200 - * @preprocess callback function (or array for methods) to change received file - * @safety value 0 means dont generate alert, value 1 means generate alerts on timeouts and failures - * @keepfailed keep old versions of files if download fails (sending alerts conservatively) - * @cachedir directory to store cache files in. NO TRAILING SLASH - * @it_error parameters for it_error + * @p['url'] url to get + * @p['timeout'] timeout in milliseconds, default 10000 + * @p['maxage'] maximum age of cache entries in seconds, default 86400 + * @p['cleanbefore'] maximum daytime when attempting cleanup, default 7200 + * @p['preprocess'] callback function (or array for methods) to change received file or array('function' => ..., 'in' => $src, 'out' => $dst, ...) with callback function plus args + * @p['safety'] value 0 means dont generate alert, value 1 means generate alerts on timeouts and failures + * @p['keepfailed'] keep old versions of files if download fails (sending alerts conservatively) + * @p['cachedir'] directory to store cache files in. NO TRAILING SLASH + * @p['it_error'] parameters for it_error */ function get_cache($p = array()) { @@ -412,7 +412,11 @@ function get_cache($p = array()) fclose($dummy); EDC('getcache', "process", $p['url'], $path); $dstpath = "$path.preprocesstmp"; - call_user_func($p['preprocess'], $srcpath, $dstpath); + + if (is_array($p['preprocess']) && $p['preprocess']['function']) # Needs is_array as it can be a string where dereferencing gives first character! + call_user_func($p['preprocess']['function'], array('in' => $srcpath, 'out' => $dstpath) + $p['preprocess']); + else + call_user_func($p['preprocess'], $srcpath, $dstpath); if (!@filesize($dstpath) || !@rename($dstpath, $path)) { |