diff options
author | Florian Pritz <bluewind@xinu.at> | 2012-05-17 21:36:32 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2012-05-17 21:40:00 +0200 |
commit | ac6d834e2b4f02d656e38fe300b5c6404d1f75e6 (patch) | |
tree | 8ce13504d568098e3b37501c69c562ed3fb0d074 | |
parent | 59b763e9896d6f6196a894c6d57d58ef9ddd6bc6 (diff) |
improve is_cli_client() and use everywhere
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/controllers/file.php | 15 | ||||
-rw-r--r-- | application/helpers/filebin_helper.php | 23 | ||||
-rw-r--r-- | application/models/file_mod.php | 2 |
3 files changed, 23 insertions, 17 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php index 1ac3a79c9..b8306b5bc 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -31,16 +31,13 @@ class File extends CI_Controller { $this->load->model('file_mod'); $this->load->model('muser'); - $this->var->cli_client = false; - $this->file_mod->var->cli_client =& $this->var->cli_client; $this->var->latest_client = false; if (file_exists(FCPATH.'data/client/latest')) { $this->var->latest_client = trim(file_get_contents(FCPATH.'data/client/latest')); } - $this->var->cli_client = is_cli_client(); - if ($this->var->cli_client) { + if (is_cli_client()) { $this->var->view_dir = "file_plaintext"; } else { $this->var->view_dir = "file"; @@ -85,11 +82,11 @@ class File extends CI_Controller { $this->data['client_link_deb'] = base_url().'data/client/deb/'; $this->data['client_link_slackware'] = base_url().'data/client/slackware/'; - if (!$this->var->cli_client) { + if (is_cli_client()) { $this->load->view($this->var->view_dir.'/header', $this->data); } $this->load->view($this->var->view_dir.'/client', $this->data); - if (!$this->var->cli_client) { + if (is_cli_client()) { $this->load->view($this->var->view_dir.'/footer', $this->data); } } @@ -106,7 +103,7 @@ class File extends CI_Controller { $this->load->view($this->var->view_dir.'/header', $this->data); $this->load->view($this->var->view_dir.'/upload_form', $this->data); - if ($this->var->cli_client) { + if (is_cli_client()) { $this->client(); } $this->load->view($this->var->view_dir.'/footer', $this->data); @@ -155,7 +152,7 @@ class File extends CI_Controller { foreach($query as $key => $item) { $query[$key]["date"] = date("r", $item["date"]); $query[$key]["filesize"] = format_bytes($item["filesize"]); - if ($this->var->cli_client) { + if (is_cli_client()) { // Keep track of longest string to pad plaintext output correctly foreach($fields as $length_key => $value) { $len = mb_strlen($query[$key][$length_key]); @@ -226,7 +223,7 @@ class File extends CI_Controller { { $this->muser->require_access(); - if (!$this->var->cli_client) { + if (is_cli_client()) { echo "Not a listed cli client, please use the history to delete uploads.\n"; return; } 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) diff --git a/application/models/file_mod.php b/application/models/file_mod.php index 9157f8eca..f203f8ef9 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -134,7 +134,7 @@ class File_mod extends CI_Model { } } - if ($this->var->cli_client) { + if (is_cli_client()) { $redirect = false; } if ($redirect) { |