From ab24be9f1d2de80ff3288ed3d7a8063a88db4156 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 22 May 2007 12:55:12 +0000 Subject: Enhanced preprocess parameter to also allow passing of arguments --- url.class | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'url.class') diff --git a/url.class b/url.class index 280d3e6..4f1118b 100644 --- a/url.class +++ b/url.class @@ -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)) { -- cgit v1.2.3