summaryrefslogtreecommitdiffstats
path: root/application
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
parent2f149783585b88033f425a2ef4a0fdb06c8fb9f9 (diff)
Move is_cli_client() and random_id() to helper
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r--application/controllers/file.php2
-rw-r--r--application/controllers/user.php2
-rw-r--r--application/helpers/filebin_helper.php27
-rw-r--r--application/models/file_mod.php30
-rw-r--r--application/models/muser.php3
5 files changed, 32 insertions, 32 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php
index e693a8667..e5e984b21 100644
--- a/application/controllers/file.php
+++ b/application/controllers/file.php
@@ -36,7 +36,7 @@ class File extends CI_Controller {
$this->var->latest_client = trim(file_get_contents(FCPATH.'data/client/latest'));
}
- $this->var->cli_client = $this->file_mod->is_cli_client();
+ $this->var->cli_client = is_cli_client();
if ($this->var->cli_client) {
$this->var->view_dir = "file_plaintext";
diff --git a/application/controllers/user.php b/application/controllers/user.php
index 2a73a1ef5..722996d93 100644
--- a/application/controllers/user.php
+++ b/application/controllers/user.php
@@ -13,7 +13,7 @@ class User extends CI_Controller {
$this->load->model("muser");
$this->data["title"] = "FileBin";
- $this->load->helper('form');
+ $this->load->helper(array('form', 'filebin'));
$this->var->view_dir = "user/";
$this->data['username'] = $this->muser->get_username();
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:
diff --git a/application/models/file_mod.php b/application/models/file_mod.php
index f804ede9b..1f1fa5f49 100644
--- a/application/models/file_mod.php
+++ b/application/models/file_mod.php
@@ -23,7 +23,7 @@ class File_mod extends CI_Model {
// TODO: make threadsafe
function new_id()
{
- $id = $this->random_id(3,6);
+ $id = random_id(3,6);
if ($this->id_exists($id) || $id == 'file' || $id == 'user') {
return $this->new_id();
@@ -175,18 +175,6 @@ class File_mod extends CI_Model {
return true;
}
- 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;
- }
-
// download a given ID
// TODO: make smaller
function download()
@@ -367,22 +355,6 @@ class File_mod extends CI_Model {
return true;
}
- // Generate a random ID
- private 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;
- }
-
// Allow certain types to be highlight without doing it automatically
function can_highlight($type)
{
diff --git a/application/models/muser.php b/application/models/muser.php
index 0fc99ab85..f3176d06d 100644
--- a/application/models/muser.php
+++ b/application/models/muser.php
@@ -5,6 +5,7 @@ class Muser extends CI_Model {
{
parent::__construct();
$this->load->library("session");
+ $this->load->helper("filebin");
}
function logged_in()
@@ -56,7 +57,7 @@ class Muser extends CI_Model {
if ($this->logged_in()) {
return true;
} else {
- if ($this->file_mod->is_cli_client()) {
+ if (is_cli_client()) {
echo "FileBin requires you to have an account, please go to the homepage for more information.\n";
exit();
} else {