From ac6d834e2b4f02d656e38fe300b5c6404d1f75e6 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 17 May 2012 21:36:32 +0200 Subject: improve is_cli_client() and use everywhere Signed-off-by: Florian Pritz --- application/helpers/filebin_helper.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'application/helpers') diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index 4c1423725..d9a490bd6 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -170,16 +170,25 @@ function mb_str_pad($ps_input, $pn_pad_length, $ps_pad_string = " ", $pn_pad_typ return $ret; } -function is_cli_client() +function is_cli_client($override = null) { - // official client uses "fb-client/$version" as useragent - $clients = array("fb-client", "libcurl", "pyfb"); - foreach ($clients as $client) { - if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], $client) !== false) { - return true; + static $is_cli = null; + + if ($override !== null) { + $is_cli = $override; + } + + if ($is_cli === null) { + $is_cli = false; + // official client uses "fb-client/$version" as useragent + $clients = array("fb-client", "libcurl", "pyfb"); + foreach ($clients as $client) { + if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], $client) !== false) { + $is_cli = true; + } } } - return false; + return $is_cli; } function random_alphanum($min_length, $max_length = null) -- cgit v1.2.3-24-g4f1b