summaryrefslogtreecommitdiff
path: root/url.class
diff options
context:
space:
mode:
authorChristian Schneider2007-05-22 12:55:12 +0000
committerChristian Schneider2007-05-22 12:55:12 +0000
commitab24be9f1d2de80ff3288ed3d7a8063a88db4156 (patch)
tree8560e72ebfac8ec81276d7d0d924eeed7d10396f /url.class
parente21ff4047b8c1e19acba0cf1a2531f3716038064 (diff)
downloaditools-ab24be9f1d2de80ff3288ed3d7a8063a88db4156.tar.gz
itools-ab24be9f1d2de80ff3288ed3d7a8063a88db4156.tar.bz2
itools-ab24be9f1d2de80ff3288ed3d7a8063a88db4156.zip
Enhanced preprocess parameter to also allow passing of arguments
Diffstat (limited to 'url.class')
-rw-r--r--url.class24
1 files changed, 14 insertions, 10 deletions
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))
{