summaryrefslogtreecommitdiffstats
path: root/application/helpers
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-04-09 11:22:03 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-04-09 20:48:14 +0200
commitcb8b733a6c2333ff90d3af0fc37e8c21c73d9e7a (patch)
treedf73e68d134ba5100e454d2da41b6276dc4eb5c8 /application/helpers
parent2f149783585b88033f425a2ef4a0fdb06c8fb9f9 (diff)
Move is_cli_client() and random_id() to helper
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/helpers')
-rw-r--r--application/helpers/filebin_helper.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php
index 41960a3d6..3dcd03794 100644
--- a/application/helpers/filebin_helper.php
+++ b/application/helpers/filebin_helper.php
@@ -170,4 +170,31 @@ function mb_str_pad($ps_input, $pn_pad_length, $ps_pad_string = " ", $pn_pad_typ
return $ret;
}
+function is_cli_client()
+{
+ // 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;
+ }
+ }
+ return false;
+}
+
+function random_id($min_length, $max_length)
+{
+ $random = '';
+ $char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ $char_list .= "abcdefghijklmnopqrstuvwxyz";
+ $char_list .= "1234567890";
+ $length = rand()%($max_length-$min_length) + $min_length;
+
+ for($i = 0; $i < $max_length; $i++) {
+ if (strlen($random) == $length) break;
+ $random .= substr($char_list,(rand()%(strlen($char_list))), 1);
+ }
+ return $random;
+}
+
# vim: set noet: