@@ -40,87 +29,73 @@ if (!defined('BASEPATH')) exit('No direct script access allowed');
class Auth extends CI_Controller
{
-
- function __construct()
- {
- parent::__construct();
- $this->load->helper('form');
- $this->load->library('Form_validation');
- $this->load->library('auth_ldap');
- $this->load->helper('url');
- $this->load->library('table');
- }
-
- function index()
- {
- $this->session->keep_flashdata('tried_to');
- $this->login();
- }
-
- function login($errorMsg = NULL)
- {
- $this->session->keep_flashdata('tried_to');
-
- if (!$this->auth_ldap->is_authenticated())
- {
- // Set up rules for form validation
- $rules = $this->form_validation;
- $rules->set_rules('username', 'Username', 'required|callback_alpha_dash_dot');
- $rules->set_rules('password', 'Password', 'required');
+ public function __construct()
+ {
+ parent::__construct();
+ $this->load->helper('form');
+ $this->load->library('Form_validation');
+ $this->load->library('auth_ldap');
+ $this->load->helper('url');
+ $this->load->library('table');
+ }
- // Do the login...
-
- if ($rules->run() && $this->auth_ldap->login($rules->set_value('username') , $rules->set_value('password')))
- {
+ public function index()
+ {
+ $this->session->keep_flashdata('tried_to');
+ $this->login();
+ }
- // Login WIN!
-
- if ($this->session->flashdata('tried_to'))
- {
- redirect($this->session->flashdata('tried_to'));
- }
- else
- {
- redirect('/');
- }
- }
- else
- {
+ public function login($errorMsg = null)
+ {
+ $this->session->keep_flashdata('tried_to');
- // Login FAIL
- $this->session->set_flashdata('login_error', 'Incorrect username or password.');
- $this->load->view('auth/login_form');
- }
- }
- else
- {
+ if (!$this->auth_ldap->is_authenticated()) {
- // Already logged in...
- redirect('/');
- }
- }
-
- function logout()
- {
-
- if ($this->session->userdata('logged_in'))
- {
- $data['name'] = $this->session->userdata('cn');
- $data['username'] = $this->session->userdata('username');
- $data['logged_in'] = TRUE;
- $this->auth_ldap->logout();
- }
- else
- {
- $data['logged_in'] = FALSE;
- }
- redirect('/');
- }
- public
- function alpha_dash_dot($str)
- {
- return (!preg_match("/^([-a-z0-9_\-\.])+$/i", $str)) ? FALSE : TRUE;
- }
+ // Set up rules for form validation
+ $rules = $this->form_validation;
+ $rules->set_rules('username', 'Username', 'required|callback_alpha_dash_dot');
+ $rules->set_rules('password', 'Password', 'required');
+
+ // Do the login...
+
+ if ($rules->run() && $this->auth_ldap->login($rules->set_value('username'), $rules->set_value('password'))) {
+
+ // Login WIN!
+
+ if ($this->session->flashdata('tried_to')) {
+ redirect($this->session->flashdata('tried_to'));
+ } else {
+ redirect('/');
+ }
+ } else {
+
+ // Login FAIL
+ $this->session->set_flashdata('login_error', 'Incorrect username or password.');
+ $this->load->view('auth/login_form');
+ }
+ } else {
+
+ // Already logged in...
+ redirect('/');
+ }
+ }
+
+ public function logout()
+ {
+
+ if ($this->session->userdata('logged_in')) {
+ $data['name'] = $this->session->userdata('cn');
+ $data['username'] = $this->session->userdata('username');
+ $data['logged_in'] = true;
+ $this->auth_ldap->logout();
+ } else {
+ $data['logged_in'] = false;
+ }
+ redirect('/');
+ }
+ public function alpha_dash_dot($str)
+ {
+ return (!preg_match("/^([-a-z0-9_\-\.])+$/i", $str)) ? false : true;
+ }
}
-?>
diff --git a/htdocs/application/controllers/Backup.php b/htdocs/application/controllers/Backup.php
index 0f42026..64d0b3c 100644
--- a/htdocs/application/controllers/Backup.php
+++ b/htdocs/application/controllers/Backup.php
@@ -1,43 +1,36 @@
-config->item('backup_user');
- $pass = $this->config->item('backup_pass');
-
- if ($user == '' || $pass == '' || !isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pass)
- {
- header('WWW-Authenticate: Basic realm="Backup"');
- header('HTTP/1.0 401 Unauthorized');
- exit;
- }
- }
-
- function index()
- {
+ public function __construct()
+ {
+ parent::__construct();
- // Load the DB utility class
- $this->load->dbutil();
+ //protection
+ $user = $this->config->item('backup_user');
+ $pass = $this->config->item('backup_pass');
- // Backup your entire database and assign it to a variable
- $backup = & $this->dbutil->backup();
+ if ($user == '' || $pass == '' || !isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != $user || $_SERVER['PHP_AUTH_PW'] != $pass) {
+ header('WWW-Authenticate: Basic realm="Backup"');
+ header('HTTP/1.0 401 Unauthorized');
+ exit;
+ }
+ }
- // Load the download helper and send the file to your desktop
- $this->load->helper('download');
- force_download('stikked.gz', $backup);
- }
+ public function index()
+ {
+
+ // Load the DB utility class
+ $this->load->dbutil();
+
+ // Backup your entire database and assign it to a variable
+ $backup = &$this->dbutil->backup();
+
+ // Load the download helper and send the file to your desktop
+ $this->load->helper('download');
+ force_download('stikked.gz', $backup);
+ }
}
diff --git a/htdocs/application/controllers/Iphone.php b/htdocs/application/controllers/Iphone.php
index 52d0227..22ee22f 100644
--- a/htdocs/application/controllers/Iphone.php
+++ b/htdocs/application/controllers/Iphone.php
@@ -1,34 +1,27 @@
-load->model('languages');
- }
-
- function index()
- {
- $this->load->model('pastes');
- $data = $this->pastes->getLists('iphone/');
- $this->load->view('iphone/recent', $data);
- }
-
- function view()
- {
- $this->load->model('pastes');
- $data = $this->pastes->getPaste(3);
- $this->load->view('iphone/view', $data);
- }
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->load->model('languages');
+ }
+
+ public function index()
+ {
+ $this->load->model('pastes');
+ $data = $this->pastes->getLists('iphone/');
+ $this->load->view('iphone/recent', $data);
+ }
+
+ public function view()
+ {
+ $this->load->model('pastes');
+ $data = $this->pastes->getPaste(3);
+ $this->load->view('iphone/view', $data);
+ }
}
diff --git a/htdocs/application/controllers/Main.php b/htdocs/application/controllers/Main.php
index 05de769..c2ce255 100644
--- a/htdocs/application/controllers/Main.php
+++ b/htdocs/application/controllers/Main.php
@@ -1,1037 +1,883 @@
-output->enable_profiler(false);
- $this->load->model('languages');
- $this->load->library('curl');
-
- if (config_item('require_auth'))
- {
- $this->load->library('auth_ldap');
- }
- //recaptcha
- $this->recaptcha_publickey = config_item('recaptcha_publickey');
- $this->recaptcha_privatekey = config_item('recaptcha_privatekey');
- $this->use_recaptcha = false;
-
- if ($this->recaptcha_publickey != '' && $this->recaptcha_privatekey != '')
- {
- $this->load->helper('recaptcha');
- $this->use_recaptcha = true;
- }
-
- if (!$this->db->table_exists('sessions'))
- {
- $this->load->dbforge();
-
- if ($this->db->table_exists('ci_sessions'))
- {
- $this->dbforge->drop_table('ci_sessions');
- }
- $fields = array(
- 'id' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 128,
- 'default' => 0,
- ) ,
- 'ip_address' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 45,
- 'default' => 0,
- ) ,
- 'timestamp' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- 'unsigned' => TRUE,
- 'default' => 0,
- ) ,
- 'data' => array(
- 'type' => ($this->db->dbdriver == "postgre") ? 'TEXT' : 'BLOB',
- ) ,
- );
- $this->dbforge->add_field($fields);
- $this->dbforge->add_key('id', true);
- $this->dbforge->add_key('timestamp');
- $this->dbforge->create_table('sessions', true);
- }
+ public function __construct()
+ {
+ parent::__construct();
+ $this->output->enable_profiler(false);
+ $this->load->model('languages');
+ $this->load->library('curl');
- // load this after db has been initialized
- $this->load->library('session');
-
- if (!$this->db->table_exists('pastes'))
- {
- $this->load->dbforge();
- $fields = array(
- 'id' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- 'auto_increment' => TRUE,
- ) ,
- 'pid' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 8,
- ) ,
- 'title' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 50,
- ) ,
- 'name' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 32,
- ) ,
- 'lang' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 32,
- ) ,
- 'private' => array(
- 'type' => 'TINYINT',
- 'constraint' => 1,
- ) ,
- 'raw' => array(
- 'type' => ($this->db->dbdriver == "postgre") ? 'TEXT' : 'LONGTEXT',
- ) ,
- 'created' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- ) ,
- 'expire' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- 'default' => 0,
- ) ,
- 'toexpire' => array(
- 'type' => 'TINYINT',
- 'constraint' => 1,
- 'unsigned' => TRUE,
- 'default' => 0,
- ) ,
- 'snipurl' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 64,
- 'default' => 0,
- ) ,
- 'replyto' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 8,
- ) ,
- 'ip_address' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 45,
- 'null' => TRUE,
- ) ,
- 'hits' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- 'default' => 0,
- ) ,
- 'hits_updated' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- 'default' => 0,
- ) ,
- );
- $this->dbforge->add_field($fields);
- $this->dbforge->add_key('id', true);
- $this->dbforge->add_key('pid');
- $this->dbforge->add_key('private');
- $this->dbforge->add_key('replyto');
- $this->dbforge->add_key('created');
- $this->dbforge->add_key('ip_address');
- $this->dbforge->add_key('hits');
- $this->dbforge->add_key('hits_updated');
- $this->dbforge->create_table('pastes', true);
- }
-
- if (!$this->db->table_exists('blocked_ips'))
- {
- $this->load->dbforge();
- $fields = array(
- 'ip_address' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 45,
- 'default' => 0,
- ) ,
- 'blocked_at' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- ) ,
- 'spam_attempts' => array(
- 'type' => 'INT',
- 'constraint' => 6,
- 'default' => 0,
- ) ,
- );
- $this->dbforge->add_field($fields);
- $this->dbforge->add_key('ip_address', true);
- $this->dbforge->create_table('blocked_ips', true);
- }
-
- if (!$this->db->table_exists('trending'))
- {
- $this->load->dbforge();
- $fields = array(
- 'paste_id' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 8,
- ) ,
- 'ip_address' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 45,
- 'default' => 0,
- ) ,
- 'created' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- ) ,
- );
- $this->dbforge->add_field($fields);
- $this->dbforge->add_key('paste_id', true);
- $this->dbforge->add_key('ip_address', true);
- $this->dbforge->add_key('created');
- $this->dbforge->create_table('trending', true);
- }
-
- if (!$this->db->field_exists('ip_address', 'pastes'))
- {
- $this->load->dbforge();
- $fields = array(
- 'ip_address' => array(
- 'type' => 'VARCHAR',
- 'constraint' => 45,
- 'null' => TRUE,
- ) ,
- );
- $this->dbforge->add_column('pastes', $fields);
- }
-
- if (!$this->db->field_exists('hits', 'pastes'))
- {
- $this->load->dbforge();
- $fields = array(
- 'hits' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- 'default' => 0,
- ) ,
- 'hits_updated' => array(
- 'type' => 'INT',
- 'constraint' => 10,
- 'default' => 0,
- ) ,
- );
- $this->dbforge->add_key('hits');
- $this->dbforge->add_key('hits_updated');
- $this->dbforge->add_column('pastes', $fields);
- }
+ if (config_item('require_auth')) {
+ $this->load->library('auth_ldap');
+ }
- //ipv6 migration
- $fields = $this->db->field_data('trending');
-
- if (stristr(config_item('db_driver') , 'sqlite') === false && $fields[1]->max_length < 45)
- {
- $db_prefix = config_item('db_prefix');
-
- if ($this->db->dbdriver == "postgre")
- {
- $this->db->query("ALTER TABLE " . $db_prefix . "trending ALTER COLUMN ip_address TYPE VARCHAR(45), ALTER COLUMN ip_address SET NOT NULL, ALTER COLUMN ip_address SET DEFAULT '0'");
- $this->db->query("ALTER TABLE " . $db_prefix . "pastes ALTER COLUMN ip_address TYPE VARCHAR(45), ALTER COLUMN ip_address SET NOT NULL, ALTER COLUMN ip_address SET DEFAULT '0'");
- $this->db->query("ALTER TABLE " . $db_prefix . "blocked_ips ALTER COLUMN ip_address TYPE VARCHAR(45), ALTER COLUMN ip_address SET NOT NULL, ALTER COLUMN ip_address SET DEFAULT '0'");
- $this->db->query("ALTER TABLE " . $db_prefix . "sessions ALTER COLUMN ip_address TYPE VARCHAR(45), ALTER COLUMN ip_address SET NOT NULL, ALTER COLUMN ip_address SET DEFAULT '0'");
- }
- else
- {
- $this->db->query("ALTER TABLE " . $db_prefix . "trending CHANGE COLUMN ip_address ip_address VARCHAR(45) NOT NULL DEFAULT '0'");
- $this->db->query("ALTER TABLE " . $db_prefix . "pastes CHANGE COLUMN ip_address ip_address VARCHAR(45) NOT NULL DEFAULT '0'");
- $this->db->query("ALTER TABLE " . $db_prefix . "blocked_ips CHANGE COLUMN ip_address ip_address VARCHAR(45) NOT NULL DEFAULT '0'");
- $this->db->query("ALTER TABLE " . $db_prefix . "sessions CHANGE COLUMN ip_address ip_address VARCHAR(45) NOT NULL DEFAULT '0'");
- }
- }
+ //recaptcha
+ $this->recaptcha_publickey = config_item('recaptcha_publickey');
+ $this->recaptcha_privatekey = config_item('recaptcha_privatekey');
+ $this->use_recaptcha = false;
- //expand title to 50
- $fields = $this->db->field_data('pastes');
- foreach ($fields as $field)
- {
-
- if ($field->name == 'title')
- {
-
- if (stristr(config_item('db_driver') , 'sqlite') === false && $field->max_length < 50)
- {
- $db_prefix = config_item('db_prefix');
-
- if ($this->db->dbdriver == "postgre")
- {
- $this->db->query("ALTER TABLE " . $db_prefix . "pastes ALTER COLUMN title TYPE VARCHAR(50), ALTER COLUMN title SET NOT NULL");
- }
- else
- {
- $this->db->query("ALTER TABLE " . $db_prefix . "pastes CHANGE COLUMN title title VARCHAR(50) NOT NULL");
- }
- }
- }
- }
+ if ($this->recaptcha_publickey != '' && $this->recaptcha_privatekey != '') {
+ $this->load->helper('recaptcha');
+ $this->use_recaptcha = true;
+ }
- //upgrade to CI 3.1.2
- $fields = $this->db->field_data('sessions');
- foreach ($fields as $field)
- {
-
- if ($field->name == 'id')
- {
-
- if (stristr(config_item('db_driver') , 'sqlite') === false)
- {
-
- if ($field->max_length < 128)
- {
- $db_prefix = config_item('db_prefix');
-
- if ($this->db->dbdriver == "postgre")
- {
- $this->db->query("ALTER TABLE " . $db_prefix . "sessions ALTER COLUMN id SET DATA TYPE varchar(128)");
- }
- else
- {
- $this->db->query("ALTER TABLE " . $db_prefix . "sessions CHANGE id id VARCHAR(128) NOT NULL");
- }
- }
- }
- }
- }
- }
-
- function _form_prep($lang = false, $title = '', $paste = '', $reply = false)
- {
- $this->load->model('languages');
- $this->load->helper('form');
- $data['languages'] = $this->languages->get_languages();
-
- if (config_item('js_editor') == 'codemirror')
- {
+ if (!$this->db->table_exists('sessions')) {
+ $this->load->dbforge();
- //codemirror languages
- $this->load->config('codemirror_languages');
- $codemirror_languages = config_item('codemirror_languages');
- $data['codemirror_languages'] = $codemirror_languages;
+ if ($this->db->table_exists('ci_sessions')) {
+ $this->dbforge->drop_table('ci_sessions');
+ }
+ $fields = array(
+ 'id' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 128,
+ 'default' => 0,
+ ),
+ 'ip_address' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'default' => 0,
+ ),
+ 'timestamp' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ 'unsigned' => true,
+ 'default' => 0,
+ ),
+ 'data' => array(
+ 'type' => ($this->db->dbdriver == "postgre") ? 'TEXT' : 'BLOB',
+ ),
+ );
+ $this->dbforge->add_field($fields);
+ $this->dbforge->add_key('id', true);
+ $this->dbforge->add_key('timestamp');
+ $this->dbforge->create_table('sessions', true);
+ }
- //codemirror modes
- $cmm = array();
- foreach ($codemirror_languages as $geshi_name => $l)
- {
-
- if (gettype($l) == 'array')
- {
- $cmm[$geshi_name] = $l['mode'];
- }
- }
- $data['codemirror_modes'] = $cmm;
- }
-
- if (config_item('js_editor') == 'ace')
- {
+ // load this after db has been initialized
+ $this->load->library('session');
- //ace languages
- $this->load->config('ace_languages');
- $ace_languages = config_item('ace_languages');
- $data['ace_languages'] = $ace_languages;
+ if (!$this->db->table_exists('pastes')) {
+ $this->load->dbforge();
+ $fields = array(
+ 'id' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ 'auto_increment' => true,
+ ),
+ 'pid' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 8,
+ ),
+ 'title' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 50,
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 32,
+ ),
+ 'lang' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 32,
+ ),
+ 'private' => array(
+ 'type' => 'TINYINT',
+ 'constraint' => 1,
+ ),
+ 'raw' => array(
+ 'type' => ($this->db->dbdriver == "postgre") ? 'TEXT' : 'LONGTEXT',
+ ),
+ 'created' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ ),
+ 'expire' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ 'default' => 0,
+ ),
+ 'toexpire' => array(
+ 'type' => 'TINYINT',
+ 'constraint' => 1,
+ 'unsigned' => true,
+ 'default' => 0,
+ ),
+ 'snipurl' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 64,
+ 'default' => 0,
+ ),
+ 'replyto' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 8,
+ ),
+ 'ip_address' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => true,
+ ),
+ 'hits' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ 'default' => 0,
+ ),
+ 'hits_updated' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ 'default' => 0,
+ ),
+ );
+ $this->dbforge->add_field($fields);
+ $this->dbforge->add_key('id', true);
+ $this->dbforge->add_key('pid');
+ $this->dbforge->add_key('private');
+ $this->dbforge->add_key('replyto');
+ $this->dbforge->add_key('created');
+ $this->dbforge->add_key('ip_address');
+ $this->dbforge->add_key('hits');
+ $this->dbforge->add_key('hits_updated');
+ $this->dbforge->create_table('pastes', true);
+ }
- //ace modes
- $acem = array();
- foreach ($ace_languages as $geshi_name => $l)
- {
- $acem[$geshi_name] = $l;
- }
- $data['ace_modes'] = $acem;
- }
+ if (!$this->db->table_exists('blocked_ips')) {
+ $this->load->dbforge();
+ $fields = array(
+ 'ip_address' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'default' => 0,
+ ),
+ 'blocked_at' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ ),
+ 'spam_attempts' => array(
+ 'type' => 'INT',
+ 'constraint' => 6,
+ 'default' => 0,
+ ),
+ );
+ $this->dbforge->add_field($fields);
+ $this->dbforge->add_key('ip_address', true);
+ $this->dbforge->create_table('blocked_ips', true);
+ }
- //recaptcha
- $data['use_recaptcha'] = $this->use_recaptcha;
- $data['recaptcha_publickey'] = $this->recaptcha_publickey;
-
- if (!$this->input->post('submit'))
- {
-
- if (!$this->session->userdata('expire'))
- {
- $default_expiration = config_item('default_expiration');
- $this->session->set_userdata('expire', $default_expiration);
- }
-
- if (!$this->session->userdata('snipurl'))
- {
- $shorturl_selected = config_item('shorturl_selected');
- $this->session->set_userdata('snipurl', $shorturl_selected);
- }
-
- if ($this->session->flashdata('settings_changed'))
- {
- $data['status_message'] = 'Settings successfully changed';
- }
- $data['name_set'] = $this->session->userdata('name');
- $data['expire_set'] = $this->session->userdata('expire');
- $data['private_set'] = $this->session->userdata('private');
- $data['snipurl_set'] = $this->session->userdata('snipurl');
- $data['paste_set'] = $paste;
- $data['title_set'] = $title;
- $data['reply'] = $reply;
-
- if (!$lang)
- {
- $lang = config_item('default_language');
- }
- $data['lang_set'] = $lang;
- }
- else
- {
- $data['name_set'] = $this->input->post('name');
- $data['expire_set'] = $this->input->post('expire');
- $data['private_set'] = $this->input->post('private');
- $data['snipurl_set'] = $this->input->post('snipurl');
- $data['paste_set'] = htmlspecialchars($this->input->post('code'));
- $data['title_set'] = $this->input->post('title');
- $data['reply'] = $this->input->post('reply');
- $data['lang_set'] = $this->input->post('lang');
- }
- return $data;
- }
-
- function index()
- {
- $this->_valid_authentication();
- $this->load->helper('json');
-
- if (!$this->input->post('submit'))
- {
- $data = $this->_form_prep();
- $this->content_expiration(config_item('content_expiration'));
- $this->load->view('home', $data);
- }
- else
- {
- $this->load->model('pastes');
- $this->load->library('form_validation');
+ if (!$this->db->table_exists('trending')) {
+ $this->load->dbforge();
+ $fields = array(
+ 'paste_id' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 8,
+ ),
+ 'ip_address' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'default' => 0,
+ ),
+ 'created' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ ),
+ );
+ $this->dbforge->add_field($fields);
+ $this->dbforge->add_key('paste_id', true);
+ $this->dbforge->add_key('ip_address', true);
+ $this->dbforge->add_key('created');
+ $this->dbforge->create_table('trending', true);
+ }
- //rules
- $rules = array(
- array(
- 'field' => 'code',
- 'label' => 'Main Paste',
- 'rules' => 'required',
- ) ,
- array(
- 'field' => 'lang',
- 'label' => 'Language',
- 'rules' => 'min_length[1]|required|callback__valid_lang',
- ) ,
- array(
- 'field' => 'captcha',
- 'label' => 'Captcha',
- 'rules' => 'callback__valid_captcha',
- ) ,
- array(
- 'field' => 'valid_ip',
- 'label' => 'Valid IP',
- 'rules' => 'callback__valid_ip',
- ) ,
- array(
- 'field' => 'blockwords_check',
- 'label' => 'No blocked words',
- 'rules' => 'callback__blockwords_check',
- ) ,
- array(
- 'field' => 'email',
- 'label' => 'Field must remain empty',
- 'rules' => 'callback__autofill_check',
- ) ,
- );
+ if (!$this->db->field_exists('ip_address', 'pastes')) {
+ $this->load->dbforge();
+ $fields = array(
+ 'ip_address' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 45,
+ 'null' => true,
+ ),
+ );
+ $this->dbforge->add_column('pastes', $fields);
+ }
- //form validation
- $this->form_validation->set_rules($rules);
- $this->form_validation->set_message('min_length', lang('empty'));
- $this->form_validation->set_error_delimiters('');
-
- if ($this->form_validation->run() == FALSE)
- {
- $data = $this->_form_prep();
- $this->load->view('home', $data);
- }
- else
- {
-
- if (config_item('private_only'))
- {
- $_POST['private'] = 1;
- }
-
- if (config_item('disable_shorturl'))
- {
- $_POST['snipurl'] = 0;
- }
-
- if ($this->input->post('reply') == false)
- {
- $user_data = array(
- 'name' => $this->input->post('name') ,
- 'lang' => $this->input->post('lang') ,
- 'expire' => $this->input->post('expire') ,
- 'snipurl' => $this->input->post('snipurl') ,
- 'private' => $this->input->post('private') ,
- );
- $this->session->set_userdata($user_data);
- }
- redirect($this->pastes->createPaste());
- }
- }
- }
-
- function post_encrypted()
- {
- $this->_valid_authentication();
-
- if ($this->_valid_captcha($this->input->post('captcha')))
- {
- $this->load->model('pastes');
- $_POST['private'] = 1;
- $_POST['snipurl'] = 0;
- $ret_url = $this->pastes->createPaste();
- echo $ret_url;
- }
- else
- {
- echo 'E_CAPTCHA';
- }
- }
-
- function raw()
- {
- $this->_valid_authentication();
- $this->load->model('pastes');
- $check = $this->pastes->checkPaste(3);
-
- if ($check)
- {
- $data = $this->pastes->getPaste(3);
-
- if (isset($_GET['preview']))
- {
- $this->load->helper('text');
- $data['raw'] = character_limiter($data['raw'], 500);
- }
- $this->content_expiration(config_item('content_expiration'));
- $this->load->view('view/raw', $data);
- }
- else
- {
- show_404();
- }
- }
-
- function rss()
- {
- $this->_valid_authentication();
- $this->load->model('pastes');
- $check = $this->pastes->checkPaste(3);
-
- if ($check)
- {
- $this->load->helper('text');
- $paste = $this->pastes->getPaste(3);
- $data = $this->pastes->getReplies(3);
- $data['page_title'] = $paste['title'] . ' - ' . config_item('site_name');
- $data['feed_url'] = site_url('view/rss/' . $this->uri->segment(3));
- $this->load->view('view/rss', $data);
- }
- else
- {
- show_404();
- }
- }
-
- function embed()
- {
- $this->_valid_authentication();
- $this->load->model('pastes');
- $check = $this->pastes->checkPaste(3);
-
- if ($check)
- {
- $data = $this->pastes->getPaste(3, true, $this->uri->segment(4) == 'diff');
- $this->content_expiration(config_item('content_expiration'));
- $this->load->view('view/embed', $data);
- }
- else
- {
- show_404();
- }
- }
-
- function qr()
- {
- $this->load->model('pastes');
- $check = $this->pastes->checkPaste(3);
-
- if ($check)
- {
- $data = $this->pastes->getPaste(3);
- $this->content_expiration('+1 year');
- $this->load->view('view/qr', $data);
- }
- }
-
- function download()
- {
- $this->_valid_authentication();
- $this->load->model('pastes');
- $check = $this->pastes->checkPaste(3);
-
- if ($check)
- {
- $data = $this->pastes->getPaste(3);
- $this->load->view('view/download', $data);
- }
- else
- {
- show_404();
- }
- }
-
- function lists()
- {
- $this->_valid_authentication();
-
- if (config_item('private_only'))
- {
- show_404();
- }
- else
- {
- $this->load->model('pastes');
-
- if ($this->uri->segment(2) == 'rss')
- {
- $this->load->helper('text');
- $data = $this->pastes->getLists('lists/', 3);
- $data['page_title'] = config_item('site_name');
- $data['feed_url'] = site_url('lists/rss');
- $data['replies'] = $data['pastes'];
- unset($data['pastes']);
- $this->load->view('view/rss', $data);
- }
- else
- {
- $data = $this->pastes->getLists('lists/', 2);
- $this->load->view('list', $data);
- }
- }
- }
-
- function trends()
- {
- $this->_valid_authentication();
-
- if (config_item('private_only'))
- {
- show_404();
- }
- else
- {
- $this->load->model('pastes');
- $data = $this->pastes->getTrends();
- $this->load->view('trends', $data);
- }
- }
-
- function view()
- {
- $this->_valid_authentication();
- $this->load->helper('json');
- $this->load->model('pastes');
- $check = $this->pastes->checkPaste(2);
-
- if ($check)
- {
-
- if ($this->session->userdata('view_raw'))
- {
- redirect('view/raw/' . $this->uri->segment(2));
- }
- $data = $this->pastes->getPaste(2, true, $this->uri->segment(3) == 'diff');
- $data['reply_form'] = $this->_form_prep($data['lang_code'], 'Re: ' . $data['title'], $data['raw'], $data['pid']);
-
- if ($data['private'] == 1)
- {
- $data['reply_form']['use_recaptcha'] = $this->use_recaptcha;
- }
- $this->content_expiration(config_item('content_expiration'));
- $this->load->view('view/view', $data);
- }
- else
- {
- show_404();
- }
- }
-
- function cron()
- {
- $this->load->model('pastes');
- $key = $this->uri->segment(2);
-
- if ($key != config_item('cron_key'))
- {
- show_404();
- }
- else
- {
- $this->pastes->cron();
- return 0;
- }
- }
-
- function about()
- {
- $this->load->view('about');
- }
-
- function captcha()
- {
- $this->load->helper('captcha');
+ if (!$this->db->field_exists('hits', 'pastes')) {
+ $this->load->dbforge();
+ $fields = array(
+ 'hits' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ 'default' => 0,
+ ),
+ 'hits_updated' => array(
+ 'type' => 'INT',
+ 'constraint' => 10,
+ 'default' => 0,
+ ),
+ );
+ $this->dbforge->add_key('hits');
+ $this->dbforge->add_key('hits_updated');
+ $this->dbforge->add_column('pastes', $fields);
+ }
- //get "word"
- $pool = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ@';
- $str = '';
- for ($i = 0;$i < 8;$i++)
- {
- $str.= substr($pool, mt_rand(0, strlen($pool) - 1) , 1);
- }
- $word = $str;
+ //ipv6 migration
+ $fields = $this->db->field_data('trending');
- //save
- $this->session->set_userdata(array(
- 'captcha' => $word
- ));
+ if (stristr(config_item('db_driver'), 'sqlite') === false && $fields[1]->max_length < 45) {
+ $db_prefix = config_item('db_prefix');
- //view
- $this->load->view('view/captcha', array(
- 'word' => $word
- ));
- }
-
- function _valid_lang($lang)
- {
- $this->load->model('languages');
- $this->form_validation->set_message('_valid_lang', lang('valid_lang'));
- return $this->languages->valid_language($lang);
- }
-
- function _valid_captcha($text)
- {
-
- if (config_item('enable_captcha') && $this->session->userdata('is_human') === null)
- {
-
- if (isset($this->form_validation))
- {
- $this->form_validation->set_message('_valid_captcha', lang('captcha'));
- }
-
- if ($this->use_recaptcha)
- {
-
- if ($this->_valid_recaptcha())
- {
- $this->session->set_userdata('is_human', true);
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
-
- if (strtolower($text) == strtolower($this->session->userdata('captcha')))
- {
- $this->session->set_userdata('is_human', true);
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- else
- {
- return true;
- }
- }
-
- function _valid_recaptcha()
- {
-
- if ($this->recaptcha_privatekey == null || $this->recaptcha_privatekey == '')
- {
- die("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create");
- }
-
- if ($this->input->post('g-recaptcha-response'))
- {
- $pk = $this->recaptcha_privatekey;
- $ra = $_SERVER['REMOTE_ADDR'];
- $rf = trim($this->input->post('g-recaptcha-response'));
- $url = "https://www.google.com/recaptcha/api/siteverify?secret=" . $pk . "&response;=" . $rf . "&remoteip;=" . $ra;
- $response = $this->curl->simple_get($url);
- $status = json_decode($response, true);
- $recaptcha_response = new stdClass();
-
- if ($status['success'])
- {
- $recaptcha_response->is_valid = true;
- }
- else
- {
- $recaptcha_response->is_valid = false;
- }
- return $recaptcha_response;
- }
- else
- {
- return false;
- }
- }
-
- function _valid_ip()
- {
+ if ($this->db->dbdriver == "postgre") {
+ $this->db->query("ALTER TABLE " . $db_prefix . "trending ALTER COLUMN ip_address TYPE VARCHAR(45), ALTER COLUMN ip_address SET NOT NULL, ALTER COLUMN ip_address SET DEFAULT '0'");
+ $this->db->query("ALTER TABLE " . $db_prefix . "pastes ALTER COLUMN ip_address TYPE VARCHAR(45), ALTER COLUMN ip_address SET NOT NULL, ALTER COLUMN ip_address SET DEFAULT '0'");
+ $this->db->query("ALTER TABLE " . $db_prefix . "blocked_ips ALTER COLUMN ip_address TYPE VARCHAR(45), ALTER COLUMN ip_address SET NOT NULL, ALTER COLUMN ip_address SET DEFAULT '0'");
+ $this->db->query("ALTER TABLE " . $db_prefix . "sessions ALTER COLUMN ip_address TYPE VARCHAR(45), ALTER COLUMN ip_address SET NOT NULL, ALTER COLUMN ip_address SET DEFAULT '0'");
+ } else {
+ $this->db->query("ALTER TABLE " . $db_prefix . "trending CHANGE COLUMN ip_address ip_address VARCHAR(45) NOT NULL DEFAULT '0'");
+ $this->db->query("ALTER TABLE " . $db_prefix . "pastes CHANGE COLUMN ip_address ip_address VARCHAR(45) NOT NULL DEFAULT '0'");
+ $this->db->query("ALTER TABLE " . $db_prefix . "blocked_ips CHANGE COLUMN ip_address ip_address VARCHAR(45) NOT NULL DEFAULT '0'");
+ $this->db->query("ALTER TABLE " . $db_prefix . "sessions CHANGE COLUMN ip_address ip_address VARCHAR(45) NOT NULL DEFAULT '0'");
+ }
+ }
- //get ip
- $ip_address = $this->input->ip_address();
-
- if (stristr($ip_address, ':'))
- {
- return $this->_valid_ipv6($ip_address);
- }
- else
- {
- return $this->_valid_ipv4($ip_address);
- }
- }
-
- function _valid_ipv4($ip_address)
- {
+ //expand title to 50
+ $fields = $this->db->field_data('pastes');
+ foreach ($fields as $field) {
- //get ip range
- $ip = explode('.', $ip_address);
- $ip_firstpart = $ip[0] . '.' . $ip[1] . '.';
+ if ($field->name == 'title') {
- //setup message
- $this->form_validation->set_message('_valid_ip', lang('not_allowed'));
+ if (stristr(config_item('db_driver'), 'sqlite') === false && $field->max_length < 50) {
+ $db_prefix = config_item('db_prefix');
- //lookup
- $this->db->select('ip_address, spam_attempts');
- $this->db->like('ip_address', $ip_firstpart, 'after');
- $query = $this->db->get('blocked_ips');
+ if ($this->db->dbdriver == "postgre") {
+ $this->db->query("ALTER TABLE " . $db_prefix . "pastes ALTER COLUMN title TYPE VARCHAR(50), ALTER COLUMN title SET NOT NULL");
+ } else {
+ $this->db->query("ALTER TABLE " . $db_prefix . "pastes CHANGE COLUMN title title VARCHAR(50) NOT NULL");
+ }
+ }
+ }
+ }
- //check
-
- if ($query->num_rows() > 0)
- {
+ //upgrade to CI 3.1.2
+ $fields = $this->db->field_data('sessions');
+ foreach ($fields as $field) {
- //update spamcount
- $blocked_ips = $query->result_array();
- $spam_attempts = $blocked_ips[0]['spam_attempts'];
- $this->db->where('ip_address', $ip_address);
- $this->db->update('blocked_ips', array(
- 'spam_attempts' => $spam_attempts + 1,
- ));
+ if ($field->name == 'id') {
- //return for the validation
- return false;
- }
- else
- {
- return true;
- }
- }
-
- function _valid_ipv6($ip_address)
- {
+ if (stristr(config_item('db_driver'), 'sqlite') === false) {
- //setup message
- $this->form_validation->set_message('_valid_ip', lang('not_allowed'));
+ if ($field->max_length < 128) {
+ $db_prefix = config_item('db_prefix');
- //lookup
- $this->db->select('ip_address, spam_attempts');
- $this->db->where('ip_address', $ip_address);
- $query = $this->db->get('blocked_ips');
+ if ($this->db->dbdriver == "postgre") {
+ $this->db->query("ALTER TABLE " . $db_prefix . "sessions ALTER COLUMN id SET DATA TYPE varchar(128)");
+ } else {
+ $this->db->query("ALTER TABLE " . $db_prefix . "sessions CHANGE id id VARCHAR(128) NOT NULL");
+ }
+ }
+ }
+ }
+ }
+ }
- //check
-
- if ($query->num_rows() > 0)
- {
+ public function _form_prep($lang = false, $title = '', $paste = '', $reply = false)
+ {
+ $this->load->model('languages');
+ $this->load->helper('form');
+ $data['languages'] = $this->languages->get_languages();
- //update spamcount
- $blocked_ips = $query->result_array();
- $spam_attempts = $blocked_ips[0]['spam_attempts'];
- $this->db->where('ip_address', $ip_address);
- $this->db->update('blocked_ips', array(
- 'spam_attempts' => $spam_attempts + 1,
- ));
+ if (config_item('js_editor') == 'codemirror') {
- //return for the validation
- return false;
- }
- else
- {
- return true;
- }
- }
-
- function _blockwords_check()
- {
+ //codemirror languages
+ $this->load->config('codemirror_languages');
+ $codemirror_languages = config_item('codemirror_languages');
+ $data['codemirror_languages'] = $codemirror_languages;
- //setup message
- $this->form_validation->set_message('_blockwords_check', lang('blocked_words'));
+ //codemirror modes
+ $cmm = array();
+ foreach ($codemirror_languages as $geshi_name => $l) {
- //check
- $blocked_words = config_item('blocked_words');
- $post = $this->input->post();
-
- if (!$blocked_words)
- {
- return true;
- }
+ if (gettype($l) == 'array') {
+ $cmm[$geshi_name] = $l['mode'];
+ }
+ }
+ $data['codemirror_modes'] = $cmm;
+ }
- //we have blocked words
- foreach (explode(',', $blocked_words) as $word)
- {
- $word = trim($word);
-
- if (stristr($post['code'], $word) || stristr($post['title'], $word))
- {
- return false;
- }
- }
- return true;
- }
-
- function _autofill_check()
- {
+ if (config_item('js_editor') == 'ace') {
- //setup message
- $this->form_validation->set_message('_autofill_check', lang('robot'));
+ //ace languages
+ $this->load->config('ace_languages');
+ $ace_languages = config_item('ace_languages');
+ $data['ace_languages'] = $ace_languages;
- //check
- return (!$this->input->post('email') && !$this->input->post('url'));
- }
-
- function _valid_authentication()
- {
-
- if (config_item('require_auth'))
- {
-
- if (!$this->auth_ldap->is_authenticated())
- {
- $this->session->set_flashdata('tried_to', "/" . $this->uri->uri_string());
- redirect('/auth');
- }
- }
- }
-
- function get_cm_js()
- {
- $lang = $this->uri->segment(3);
- $this->load->config('codemirror_languages');
- $cml = config_item('codemirror_languages');
+ //ace modes
+ $acem = array();
+ foreach ($ace_languages as $geshi_name => $l) {
+ $acem[$geshi_name] = $l;
+ }
+ $data['ace_modes'] = $acem;
+ }
- //file path
- $file_path = 'themes/' . config_item('theme') . '/js/';
-
- if (!file_exists($file_path))
- {
- $file_path = 'themes/default/js/';
- }
-
- if (isset($cml[$lang]) && gettype($cml[$lang]) == 'array')
- {
- header('Content-Type: application/x-javascript; charset=utf-8');
- header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 60 * 60 * 24 * 30));
- foreach ($cml[$lang]['js'] as $js)
- {
- echo file_get_contents($file_path . $js[0]);
- }
- }
- exit;
- }
-
- function error_404()
- {
- show_404();
- }
-
- function robots_txt()
- {
-
- if (config_item('disallow_search_engines'))
- {
- header('Content-Type: text/plain; charset=utf-8');
- $this->load->view('robots_txt');
- }
- else
- {
- echo '';
- }
- }
+ //recaptcha
+ $data['use_recaptcha'] = $this->use_recaptcha;
+ $data['recaptcha_publickey'] = $this->recaptcha_publickey;
- function content_expiration($cache_time)
- {
- if(!$cache_time)
- {
- $cache_time = '-1 week';
- }
- $cache_expiration = strtotime($cache_time);
- $this->output->set_header('Pragma: ', true);
- $this->output->set_header('Cache-Control: ', true);
- $this->output->set_header('Expires: ' . gmdate('D, d M Y H:i:s', $cache_expiration) . ' GMT', true);
- }
+ if (!$this->input->post('submit')) {
+
+ if (!$this->session->userdata('expire')) {
+ $default_expiration = config_item('default_expiration');
+ $this->session->set_userdata('expire', $default_expiration);
+ }
+
+ if (!$this->session->userdata('snipurl')) {
+ $shorturl_selected = config_item('shorturl_selected');
+ $this->session->set_userdata('snipurl', $shorturl_selected);
+ }
+
+ if ($this->session->flashdata('settings_changed')) {
+ $data['status_message'] = 'Settings successfully changed';
+ }
+ $data['name_set'] = $this->session->userdata('name');
+ $data['expire_set'] = $this->session->userdata('expire');
+ $data['private_set'] = $this->session->userdata('private');
+ $data['snipurl_set'] = $this->session->userdata('snipurl');
+ $data['paste_set'] = $paste;
+ $data['title_set'] = $title;
+ $data['reply'] = $reply;
+
+ if (!$lang) {
+ $lang = config_item('default_language');
+ }
+ $data['lang_set'] = $lang;
+ } else {
+ $data['name_set'] = $this->input->post('name');
+ $data['expire_set'] = $this->input->post('expire');
+ $data['private_set'] = $this->input->post('private');
+ $data['snipurl_set'] = $this->input->post('snipurl');
+ $data['paste_set'] = htmlspecialchars($this->input->post('code'));
+ $data['title_set'] = $this->input->post('title');
+ $data['reply'] = $this->input->post('reply');
+ $data['lang_set'] = $this->input->post('lang');
+ }
+ return $data;
+ }
+
+ public function index()
+ {
+ $this->_valid_authentication();
+ $this->load->helper('json');
+
+ if (!$this->input->post('submit')) {
+ $data = $this->_form_prep();
+ $this->content_expiration(config_item('content_expiration'));
+ $this->load->view('home', $data);
+ } else {
+ $this->load->model('pastes');
+ $this->load->library('form_validation');
+
+ //rules
+ $rules = array(
+ array(
+ 'field' => 'code',
+ 'label' => 'Main Paste',
+ 'rules' => 'required',
+ ),
+ array(
+ 'field' => 'lang',
+ 'label' => 'Language',
+ 'rules' => 'min_length[1]|required|callback__valid_lang',
+ ),
+ array(
+ 'field' => 'captcha',
+ 'label' => 'Captcha',
+ 'rules' => 'callback__valid_captcha',
+ ),
+ array(
+ 'field' => 'valid_ip',
+ 'label' => 'Valid IP',
+ 'rules' => 'callback__valid_ip',
+ ),
+ array(
+ 'field' => 'blockwords_check',
+ 'label' => 'No blocked words',
+ 'rules' => 'callback__blockwords_check',
+ ),
+ array(
+ 'field' => 'email',
+ 'label' => 'Field must remain empty',
+ 'rules' => 'callback__autofill_check',
+ ),
+ );
+
+ //form validation
+ $this->form_validation->set_rules($rules);
+ $this->form_validation->set_message('min_length', lang('empty'));
+ $this->form_validation->set_error_delimiters('');
+
+ if ($this->form_validation->run() == false) {
+ $data = $this->_form_prep();
+ $this->load->view('home', $data);
+ } else {
+
+ if (config_item('private_only')) {
+ $_POST['private'] = 1;
+ }
+
+ if (config_item('disable_shorturl')) {
+ $_POST['snipurl'] = 0;
+ }
+
+ if ($this->input->post('reply') == false) {
+ $user_data = array(
+ 'name' => $this->input->post('name'),
+ 'lang' => $this->input->post('lang'),
+ 'expire' => $this->input->post('expire'),
+ 'snipurl' => $this->input->post('snipurl'),
+ 'private' => $this->input->post('private'),
+ );
+ $this->session->set_userdata($user_data);
+ }
+ redirect($this->pastes->createPaste());
+ }
+ }
+ }
+
+ public function post_encrypted()
+ {
+ $this->_valid_authentication();
+
+ if ($this->_valid_captcha($this->input->post('captcha'))) {
+ $this->load->model('pastes');
+ $_POST['private'] = 1;
+ $_POST['snipurl'] = 0;
+ $ret_url = $this->pastes->createPaste();
+ echo $ret_url;
+ } else {
+ echo 'E_CAPTCHA';
+ }
+ }
+
+ public function raw()
+ {
+ $this->_valid_authentication();
+ $this->load->model('pastes');
+ $check = $this->pastes->checkPaste(3);
+
+ if ($check) {
+ $data = $this->pastes->getPaste(3);
+
+ if (isset($_GET['preview'])) {
+ $this->load->helper('text');
+ $data['raw'] = character_limiter($data['raw'], 500);
+ }
+ $this->content_expiration(config_item('content_expiration'));
+ $this->load->view('view/raw', $data);
+ } else {
+ show_404();
+ }
+ }
+
+ public function rss()
+ {
+ $this->_valid_authentication();
+ $this->load->model('pastes');
+ $check = $this->pastes->checkPaste(3);
+
+ if ($check) {
+ $this->load->helper('text');
+ $paste = $this->pastes->getPaste(3);
+ $data = $this->pastes->getReplies(3);
+ $data['page_title'] = $paste['title'] . ' - ' . config_item('site_name');
+ $data['feed_url'] = site_url('view/rss/' . $this->uri->segment(3));
+ $this->load->view('view/rss', $data);
+ } else {
+ show_404();
+ }
+ }
+
+ public function embed()
+ {
+ $this->_valid_authentication();
+ $this->load->model('pastes');
+ $check = $this->pastes->checkPaste(3);
+
+ if ($check) {
+ $data = $this->pastes->getPaste(3, true, $this->uri->segment(4) == 'diff');
+ $this->content_expiration(config_item('content_expiration'));
+ $this->load->view('view/embed', $data);
+ } else {
+ show_404();
+ }
+ }
+
+ public function qr()
+ {
+ $this->load->model('pastes');
+ $check = $this->pastes->checkPaste(3);
+
+ if ($check) {
+ $data = $this->pastes->getPaste(3);
+ $this->content_expiration('+1 year');
+ $this->load->view('view/qr', $data);
+ }
+ }
+
+ public function download()
+ {
+ $this->_valid_authentication();
+ $this->load->model('pastes');
+ $check = $this->pastes->checkPaste(3);
+
+ if ($check) {
+ $data = $this->pastes->getPaste(3);
+ $this->load->view('view/download', $data);
+ } else {
+ show_404();
+ }
+ }
+
+ public function lists()
+ {
+ $this->_valid_authentication();
+
+ if (config_item('private_only')) {
+ show_404();
+ } else {
+ $this->load->model('pastes');
+
+ if ($this->uri->segment(2) == 'rss') {
+ $this->load->helper('text');
+ $data = $this->pastes->getLists('lists/', 3);
+ $data['page_title'] = config_item('site_name');
+ $data['feed_url'] = site_url('lists/rss');
+ $data['replies'] = $data['pastes'];
+ unset($data['pastes']);
+ $this->load->view('view/rss', $data);
+ } else {
+ $data = $this->pastes->getLists('lists/', 2);
+ $this->load->view('list', $data);
+ }
+ }
+ }
+
+ public function trends()
+ {
+ $this->_valid_authentication();
+
+ if (config_item('private_only')) {
+ show_404();
+ } else {
+ $this->load->model('pastes');
+ $data = $this->pastes->getTrends();
+ $this->load->view('trends', $data);
+ }
+ }
+
+ public function view()
+ {
+ $this->_valid_authentication();
+ $this->load->helper('json');
+ $this->load->model('pastes');
+ $check = $this->pastes->checkPaste(2);
+
+ if ($check) {
+
+ if ($this->session->userdata('view_raw')) {
+ redirect('view/raw/' . $this->uri->segment(2));
+ }
+ $data = $this->pastes->getPaste(2, true, $this->uri->segment(3) == 'diff');
+ $data['reply_form'] = $this->_form_prep($data['lang_code'], 'Re: ' . $data['title'], $data['raw'], $data['pid']);
+
+ if ($data['private'] == 1) {
+ $data['reply_form']['use_recaptcha'] = $this->use_recaptcha;
+ }
+ $this->content_expiration(config_item('content_expiration'));
+ $this->load->view('view/view', $data);
+ } else {
+ show_404();
+ }
+ }
+
+ public function cron()
+ {
+ $this->load->model('pastes');
+ $key = $this->uri->segment(2);
+
+ if ($key != config_item('cron_key')) {
+ show_404();
+ } else {
+ $this->pastes->cron();
+ return 0;
+ }
+ }
+
+ public function about()
+ {
+ $this->load->view('about');
+ }
+
+ public function captcha()
+ {
+ $this->load->helper('captcha');
+
+ //get "word"
+ $pool = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ@';
+ $str = '';
+ for ($i = 0; $i < 8; $i++) {
+ $str .= substr($pool, mt_rand(0, strlen($pool) - 1), 1);
+ }
+ $word = $str;
+
+ //save
+ $this->session->set_userdata(array(
+ 'captcha' => $word,
+ ));
+
+ //view
+ $this->load->view('view/captcha', array(
+ 'word' => $word,
+ ));
+ }
+
+ public function _valid_lang($lang)
+ {
+ $this->load->model('languages');
+ $this->form_validation->set_message('_valid_lang', lang('valid_lang'));
+ return $this->languages->valid_language($lang);
+ }
+
+ public function _valid_captcha($text)
+ {
+
+ if (config_item('enable_captcha') && $this->session->userdata('is_human') === null) {
+
+ if (isset($this->form_validation)) {
+ $this->form_validation->set_message('_valid_captcha', lang('captcha'));
+ }
+
+ if ($this->use_recaptcha) {
+
+ if ($this->_valid_recaptcha()) {
+ $this->session->set_userdata('is_human', true);
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+
+ if (strtolower($text) == strtolower($this->session->userdata('captcha'))) {
+ $this->session->set_userdata('is_human', true);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ } else {
+ return true;
+ }
+ }
+
+ public function _valid_recaptcha()
+ {
+
+ if ($this->recaptcha_privatekey == null || $this->recaptcha_privatekey == '') {
+ die("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create");
+ }
+
+ if ($this->input->post('g-recaptcha-response')) {
+ $pk = $this->recaptcha_privatekey;
+ $ra = $_SERVER['REMOTE_ADDR'];
+ $rf = trim($this->input->post('g-recaptcha-response'));
+ $url = "https://www.google.com/recaptcha/api/siteverify?secret=" . $pk . "&response;=" . $rf . "&remoteip;=" . $ra;
+ $response = $this->curl->simple_get($url);
+ $status = json_decode($response, true);
+ $recaptcha_response = new stdClass();
+
+ if ($status['success']) {
+ $recaptcha_response->is_valid = true;
+ } else {
+ $recaptcha_response->is_valid = false;
+ }
+ return $recaptcha_response;
+ } else {
+ return false;
+ }
+ }
+
+ public function _valid_ip()
+ {
+
+ //get ip
+ $ip_address = $this->input->ip_address();
+
+ if (stristr($ip_address, ':')) {
+ return $this->_valid_ipv6($ip_address);
+ } else {
+ return $this->_valid_ipv4($ip_address);
+ }
+ }
+
+ public function _valid_ipv4($ip_address)
+ {
+
+ //get ip range
+ $ip = explode('.', $ip_address);
+ $ip_firstpart = $ip[0] . '.' . $ip[1] . '.';
+
+ //setup message
+ $this->form_validation->set_message('_valid_ip', lang('not_allowed'));
+
+ //lookup
+ $this->db->select('ip_address, spam_attempts');
+ $this->db->like('ip_address', $ip_firstpart, 'after');
+ $query = $this->db->get('blocked_ips');
+
+ //check
+
+ if ($query->num_rows() > 0) {
+
+ //update spamcount
+ $blocked_ips = $query->result_array();
+ $spam_attempts = $blocked_ips[0]['spam_attempts'];
+ $this->db->where('ip_address', $ip_address);
+ $this->db->update('blocked_ips', array(
+ 'spam_attempts' => $spam_attempts + 1,
+ ));
+
+ //return for the validation
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public function _valid_ipv6($ip_address)
+ {
+
+ //setup message
+ $this->form_validation->set_message('_valid_ip', lang('not_allowed'));
+
+ //lookup
+ $this->db->select('ip_address, spam_attempts');
+ $this->db->where('ip_address', $ip_address);
+ $query = $this->db->get('blocked_ips');
+
+ //check
+
+ if ($query->num_rows() > 0) {
+
+ //update spamcount
+ $blocked_ips = $query->result_array();
+ $spam_attempts = $blocked_ips[0]['spam_attempts'];
+ $this->db->where('ip_address', $ip_address);
+ $this->db->update('blocked_ips', array(
+ 'spam_attempts' => $spam_attempts + 1,
+ ));
+
+ //return for the validation
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ public function _blockwords_check()
+ {
+
+ //setup message
+ $this->form_validation->set_message('_blockwords_check', lang('blocked_words'));
+
+ //check
+ $blocked_words = config_item('blocked_words');
+ $post = $this->input->post();
+
+ if (!$blocked_words) {
+ return true;
+ }
+
+ //we have blocked words
+ foreach (explode(',', $blocked_words) as $word) {
+ $word = trim($word);
+
+ if (stristr($post['code'], $word) || stristr($post['title'], $word)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public function _autofill_check()
+ {
+
+ //setup message
+ $this->form_validation->set_message('_autofill_check', lang('robot'));
+
+ //check
+ return (!$this->input->post('email') && !$this->input->post('url'));
+ }
+
+ public function _valid_authentication()
+ {
+
+ if (config_item('require_auth')) {
+
+ if (!$this->auth_ldap->is_authenticated()) {
+ $this->session->set_flashdata('tried_to', "/" . $this->uri->uri_string());
+ redirect('/auth');
+ }
+ }
+ }
+
+ public function get_cm_js()
+ {
+ $lang = $this->uri->segment(3);
+ $this->load->config('codemirror_languages');
+ $cml = config_item('codemirror_languages');
+
+ //file path
+ $file_path = 'themes/' . config_item('theme') . '/js/';
+
+ if (!file_exists($file_path)) {
+ $file_path = 'themes/default/js/';
+ }
+
+ if (isset($cml[$lang]) && gettype($cml[$lang]) == 'array') {
+ header('Content-Type: application/x-javascript; charset=utf-8');
+ header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 60 * 60 * 24 * 30));
+ foreach ($cml[$lang]['js'] as $js) {
+ echo file_get_contents($file_path . $js[0]);
+ }
+ }
+ exit;
+ }
+
+ public function error_404()
+ {
+ show_404();
+ }
+
+ public function robots_txt()
+ {
+
+ if (config_item('disallow_search_engines')) {
+ header('Content-Type: text/plain; charset=utf-8');
+ $this->load->view('robots_txt');
+ } else {
+ echo '';
+ }
+ }
+
+ public function content_expiration($cache_time)
+ {
+ if (!$cache_time) {
+ $cache_time = '-1 week';
+ }
+ $cache_expiration = strtotime($cache_time);
+ $this->output->set_header('Pragma: ', true);
+ $this->output->set_header('Cache-Control: ', true);
+ $this->output->set_header('Expires: ' . gmdate('D, d M Y H:i:s', $cache_expiration) . ' GMT', true);
+ }
}
diff --git a/htdocs/application/controllers/Spamadmin.php b/htdocs/application/controllers/Spamadmin.php
index 8bd9682..0f03645 100644
--- a/htdocs/application/controllers/Spamadmin.php
+++ b/htdocs/application/controllers/Spamadmin.php
@@ -1,159 +1,139 @@
-config->item('spamadmin_user');
- $pass = $this->config->item('spamadmin_pass');
+ public function __construct()
+ {
+ parent::__construct();
- // FastCGI doesn't provide PHP_AUTH_USER and PHP_AUTH_PW, apparently?
- if (empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW'])) {
- if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
- list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
- }
- }
+ //protection
+ $user = $this->config->item('spamadmin_user');
+ $pass = $this->config->item('spamadmin_pass');
- // If they're not set, set them to blank. The null coalesce operator would be handy here, but
- // that's PHP 7.0 and higher...
- if (empty($_SERVER['PHP_AUTH_USER']))
- {
- $_SERVER['PHP_AUTH_USER'] = "";
- }
- if (empty($_SERVER['PHP_AUTH_PW']))
- {
- $_SERVER['PHP_AUTH_PW'] = "";
- }
-
- if ($user === '' || $pass === '' || $_SERVER['PHP_AUTH_USER'] !== $user || $_SERVER['PHP_AUTH_PW'] !== $pass)
- {
- header('WWW-Authenticate: Basic realm="Spamadmin"');
- header('HTTP/1.0 401 Unauthorized');
- exit;
- }
- }
-
- function index()
- {
- $this->load->model('pastes');
- $pastes_to_delete = $this->input->post('pastes_to_delete');
-
- if ($pastes_to_delete)
- {
- foreach (explode(' ', $pastes_to_delete) as $pid)
- {
- $this->db->where('pid', $pid);
- $this->db->delete('pastes');
- }
- redirect(site_url('spamadmin/' . $this->uri->segment(2)));
- }
+ // FastCGI doesn't provide PHP_AUTH_USER and PHP_AUTH_PW, apparently?
+ if (empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW'])) {
+ if (!empty($_SERVER['HTTP_AUTHORIZATION'])) {
+ list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
+ }
+ }
- //render view
- $data = $this->pastes->getSpamLists();
- $this->load->view('list_ips', $data);
- }
-
- function spam_detail()
- {
- $this->load->model('pastes');
- $ip_address = $this->uri->segment(2);
-
- if ($this->input->post('confirm_remove') && $ip_address != '')
- {
- $this->db->where('ip_address', $ip_address);
- $this->db->delete('pastes');
- $paste_count = $this->db->affected_rows();
-
- if ($this->input->post('block_ip'))
- {
- $query = $this->db->get_where('blocked_ips', array(
- 'ip_address' => $ip_address
- ));
-
- if ($query->num_rows() == 0)
- {
- $this->db->insert('blocked_ips', array(
- 'ip_address' => $ip_address,
- 'blocked_at' => time() ,
- 'spam_attempts' => $paste_count,
- ));
- }
- }
- }
+ // If they're not set, set them to blank. The null coalesce operator would be handy here, but
+ // that's PHP 7.0 and higher...
+ if (empty($_SERVER['PHP_AUTH_USER'])) {
+ $_SERVER['PHP_AUTH_USER'] = "";
+ }
+ if (empty($_SERVER['PHP_AUTH_PW'])) {
+ $_SERVER['PHP_AUTH_PW'] = "";
+ }
- //fill data
- $data = $this->pastes->getSpamLists('spamadmin/' . $ip_address, $seg = 3, $ip_address);
- $data['ip_address'] = $ip_address;
- $ip = explode('.', $ip_address);
-
- if (count($ip) > 1)
- {
- $ip_firstpart = $ip[0] . '.' . $ip[1] . '.';
- $data['ip_range'] = $ip_firstpart . '*.*';
- }
- else
- {
+ if ($user === '' || $pass === '' || $_SERVER['PHP_AUTH_USER'] !== $user || $_SERVER['PHP_AUTH_PW'] !== $pass) {
+ header('WWW-Authenticate: Basic realm="Spamadmin"');
+ header('HTTP/1.0 401 Unauthorized');
+ exit;
+ }
+ }
- // ipv6
- $ip = explode(':', $ip_address);
- $ip_firstpart = $ip[0] . ':' . $ip[1] . ':' . $ip[2] . ':' . $ip[3] . ':' . $ip[4] . ':' . $ip[5] . ':' . $ip[6];
- $data['ip_range'] = $ip_firstpart . ':*';
- }
+ public function index()
+ {
+ $this->load->model('pastes');
+ $pastes_to_delete = $this->input->post('pastes_to_delete');
- //view
- $this->load->view('spam_detail', $data);
- }
-
- function blacklist()
- {
+ if ($pastes_to_delete) {
+ foreach (explode(' ', $pastes_to_delete) as $pid) {
+ $this->db->where('pid', $pid);
+ $this->db->delete('pastes');
+ }
+ redirect(site_url('spamadmin/' . $this->uri->segment(2)));
+ }
- //pagination
- $amount = $this->config->item('per_page');
- $page = ($this->uri->segment(3) ? $this->uri->segment(3) : 0);
+ //render view
+ $data = $this->pastes->getSpamLists();
+ $this->load->view('list_ips', $data);
+ }
- //get
- $this->db->select('ip_address, blocked_at, spam_attempts');
- $this->db->order_by('blocked_at desc, ip_address asc');
- $query = $this->db->get('blocked_ips', $amount, $page);
- $data['blocked_ips'] = $query->result_array();
+ public function spam_detail()
+ {
+ $this->load->model('pastes');
+ $ip_address = $this->uri->segment(2);
- //pagination
- $config['base_url'] = site_url('spamadmin/blacklist');
- $query = $this->db->get('blocked_ips');
- $config['total_rows'] = $query->num_rows();
- $config['per_page'] = $amount;
- $config['num_links'] = 9;
- $config['full_tag_open'] = '';
- $config['full_tag_close'] = '
';
- $config['uri_segment'] = 3;
- $this->load->library('pagination');
- $this->pagination->initialize($config);
- $data['pages'] = $this->pagination->create_links();
+ if ($this->input->post('confirm_remove') && $ip_address != '') {
+ $this->db->where('ip_address', $ip_address);
+ $this->db->delete('pastes');
+ $paste_count = $this->db->affected_rows();
- //view
- $this->load->view('list_blocked_ips', $data);
- }
-
- function unblock_ip()
- {
- $ip_address = $this->uri->segment(4);
- $this->db->where('ip_address', $ip_address);
- $this->db->delete('blocked_ips');
- redirect('spamadmin/blacklist');
- }
+ if ($this->input->post('block_ip')) {
+ $query = $this->db->get_where('blocked_ips', array(
+ 'ip_address' => $ip_address,
+ ));
+
+ if ($query->num_rows() == 0) {
+ $this->db->insert('blocked_ips', array(
+ 'ip_address' => $ip_address,
+ 'blocked_at' => time(),
+ 'spam_attempts' => $paste_count,
+ ));
+ }
+ }
+ }
+
+ //fill data
+ $data = $this->pastes->getSpamLists('spamadmin/' . $ip_address, $seg = 3, $ip_address);
+ $data['ip_address'] = $ip_address;
+ $ip = explode('.', $ip_address);
+
+ if (count($ip) > 1) {
+ $ip_firstpart = $ip[0] . '.' . $ip[1] . '.';
+ $data['ip_range'] = $ip_firstpart . '*.*';
+ } else {
+
+ // ipv6
+ $ip = explode(':', $ip_address);
+ $ip_firstpart = $ip[0] . ':' . $ip[1] . ':' . $ip[2] . ':' . $ip[3] . ':' . $ip[4] . ':' . $ip[5] . ':' . $ip[6];
+ $data['ip_range'] = $ip_firstpart . ':*';
+ }
+
+ //view
+ $this->load->view('spam_detail', $data);
+ }
+
+ public function blacklist()
+ {
+
+ //pagination
+ $amount = $this->config->item('per_page');
+ $page = ($this->uri->segment(3) ? $this->uri->segment(3) : 0);
+
+ //get
+ $this->db->select('ip_address, blocked_at, spam_attempts');
+ $this->db->order_by('blocked_at desc, ip_address asc');
+ $query = $this->db->get('blocked_ips', $amount, $page);
+ $data['blocked_ips'] = $query->result_array();
+
+ //pagination
+ $config['base_url'] = site_url('spamadmin/blacklist');
+ $query = $this->db->get('blocked_ips');
+ $config['total_rows'] = $query->num_rows();
+ $config['per_page'] = $amount;
+ $config['num_links'] = 9;
+ $config['full_tag_open'] = '';
+ $config['full_tag_close'] = '
';
+ $config['uri_segment'] = 3;
+ $this->load->library('pagination');
+ $this->pagination->initialize($config);
+ $data['pages'] = $this->pagination->create_links();
+
+ //view
+ $this->load->view('list_blocked_ips', $data);
+ }
+
+ public function unblock_ip()
+ {
+ $ip_address = $this->uri->segment(4);
+ $this->db->where('ip_address', $ip_address);
+ $this->db->delete('blocked_ips');
+ redirect('spamadmin/blacklist');
+ }
}
diff --git a/htdocs/application/controllers/Theme_assets.php b/htdocs/application/controllers/Theme_assets.php
index a6d084f..8bb87cc 100644
--- a/htdocs/application/controllers/Theme_assets.php
+++ b/htdocs/application/controllers/Theme_assets.php
@@ -1,227 +1,191 @@
-theme = config_item('theme');
- }
-
- function css()
- {
- $css_file = $this->uri->segment(4);
- $css_file = basename($css_file); // Fix LFI Vulnerability
-
- if ($css_file == 'fonts')
- {
- $font_file = $this->uri->segment(5);
- $font_file = basename($font_file);
+ public function __construct()
+ {
+ parent::__construct();
+ $this->theme = config_item('theme');
+ }
- //file path
- $file_path = 'themes/' . $this->theme . '/css/fonts/' . $font_file;
-
- if (!file_exists($file_path))
- {
- return false;
- }
- $path_parts = pathinfo(dirname(dirname(dirname(__FILE__))) . '/' . $file_path);
-
- if ($path_parts['extension'] == "woff")
- {
- header('Content-type: application/font-woff');
- }
-
- if ($path_parts['extension'] == "eot")
- {
- header('Content-type: application/vnd.ms-fontobject');
- }
-
- if ($path_parts['extension'] == "ttf" || $path_parts['extension'] == "ttc")
- {
- header('Content-type: application/x-font-ttf');
- }
-
- if ($path_parts['extension'] == "otf")
- {
- header('Content-type: font/opentype');
- }
-
- if ($path_parts['extension'] == "svg")
- {
- header('Content-type: image/svg+xml');
- }
-
- if ($path_parts['extension'] == "svgz")
- {
- header("Content-Encoding: gzip");
- header('Content-type: image/svg+xml');
- }
+ public function css()
+ {
+ $css_file = $this->uri->segment(4);
+ $css_file = basename($css_file); // Fix LFI Vulnerability
- //send
- $this->_expires_header(1);
- readfile($file_path);
- }
- else
- {
+ if ($css_file == 'fonts') {
+ $font_file = $this->uri->segment(5);
+ $font_file = basename($font_file);
- //file path
- $file_path = 'themes/' . $this->theme . '/css/' . $css_file;
+ //file path
+ $file_path = 'themes/' . $this->theme . '/css/fonts/' . $font_file;
- //fallback to default css if view in theme not found
-
- if (!file_exists($file_path))
- {
- $file_path = 'themes/default/css/' . $css_file;
- }
+ if (!file_exists($file_path)) {
+ return false;
+ }
+ $path_parts = pathinfo(dirname(dirname(dirname(__FILE__))) . '/' . $file_path);
- // Double checking file
-
- if (!file_exists($file_path))
- {
- return false;
- }
+ if ($path_parts['extension'] == "woff") {
+ header('Content-type: application/font-woff');
+ }
- //send
- header('Content-type: text/css');
- $this->_expires_header(1);
- readfile($file_path);
- }
- }
-
- function fonts()
- {
- $font_file = $this->uri->segment(4);
+ if ($path_parts['extension'] == "eot") {
+ header('Content-type: application/vnd.ms-fontobject');
+ }
- //file path
- $file_path = 'themes/' . $this->theme . '/fonts/' . $font_file;
+ if ($path_parts['extension'] == "ttf" || $path_parts['extension'] == "ttc") {
+ header('Content-type: application/x-font-ttf');
+ }
- //no fallback to default, since default has no such fonts
- //since no fallbcack, there is no doucle checking for file
+ if ($path_parts['extension'] == "otf") {
+ header('Content-type: font/opentype');
+ }
-
- if (!file_exists($file_path))
- {
- return false;
- }
+ if ($path_parts['extension'] == "svg") {
+ header('Content-type: image/svg+xml');
+ }
- //send
- $path_parts = pathinfo(dirname(dirname(dirname(__FILE__))) . '/' . $file_path);
-
- if ($path_parts['extension'] == "woff")
- {
- header('Content-type: application/font-woff');
- }
-
- if ($path_parts['extension'] == "eot")
- {
- header('Content-type: application/vnd.ms-fontobject');
- }
-
- if ($path_parts['extension'] == "ttf" || $path_parts['extension'] == "ttc")
- {
- header('Content-type: application/x-font-ttf');
- }
-
- if ($path_parts['extension'] == "otf")
- {
- header('Content-type: font/opentype');
- }
-
- if ($path_parts['extension'] == "svg")
- {
- header('Content-type: image/svg+xml');
- }
-
- if ($path_parts['extension'] == "svgz")
- {
- header("Content-Encoding: gzip");
- header('Content-type: image/svg+xml');
- }
- $this->_expires_header(1);
- readfile($file_path);
- }
-
- function images()
- {
- $image_file = $this->uri->segment(4);
- $image_file = basename($image_file);
+ if ($path_parts['extension'] == "svgz") {
+ header("Content-Encoding: gzip");
+ header('Content-type: image/svg+xml');
+ }
- //file path
- $file_path = 'themes/' . $this->theme . '/images/' . $image_file;
+ //send
+ $this->_expires_header(1);
+ readfile($file_path);
+ } else {
- //fallback to default css if view in theme not found
-
- if (!file_exists($file_path))
- {
- $file_path = 'themes/default/images/' . $image_file;
- }
+ //file path
+ $file_path = 'themes/' . $this->theme . '/css/' . $css_file;
- // double checking file
-
- if (!file_exists($file_path))
- {
- return false;
- }
+ //fallback to default css if view in theme not found
- //send
- $size = getimagesize($file_path);
- header('Content-type: ' . $size['mime']);
- $this->_expires_header(30);
- readfile($file_path);
- }
-
- function js()
- {
+ if (!file_exists($file_path)) {
+ $file_path = 'themes/default/css/' . $css_file;
+ }
- //get js
- $segments = $this->uri->segment_array();
- array_shift($segments);
- array_shift($segments);
- array_shift($segments);
- $js_file = implode('/', $segments);
- $js_file = str_replace('../', '', $js_file);
+ // Double checking file
- //file path
- $file_path = 'themes/' . $this->theme . '/js/' . $js_file;
+ if (!file_exists($file_path)) {
+ return false;
+ }
- //fallback to default js if js in theme not found
-
- if (!file_exists($file_path))
- {
- $file_path = 'themes/default/js/' . $js_file;
- }
+ //send
+ header('Content-type: text/css');
+ $this->_expires_header(1);
+ readfile($file_path);
+ }
+ }
- // return empty string if not found, to not mess up existing JS
-
- if (!file_exists($file_path))
- {
- header('HTTP/1.1 404 Not Found');
- return '';
- }
+ public function fonts()
+ {
+ $font_file = $this->uri->segment(4);
- //send
- header('Content-Type: application/x-javascript; charset=utf-8');
- $this->_expires_header(30);
- readfile($file_path);
- }
- private
- function _expires_header($days)
- {
- header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 60 * 60 * 24 * $days));
- }
+ //file path
+ $file_path = 'themes/' . $this->theme . '/fonts/' . $font_file;
+
+ //no fallback to default, since default has no such fonts
+ //since no fallbcack, there is no doucle checking for file
+
+ if (!file_exists($file_path)) {
+ return false;
+ }
+
+ //send
+ $path_parts = pathinfo(dirname(dirname(dirname(__FILE__))) . '/' . $file_path);
+
+ if ($path_parts['extension'] == "woff") {
+ header('Content-type: application/font-woff');
+ }
+
+ if ($path_parts['extension'] == "eot") {
+ header('Content-type: application/vnd.ms-fontobject');
+ }
+
+ if ($path_parts['extension'] == "ttf" || $path_parts['extension'] == "ttc") {
+ header('Content-type: application/x-font-ttf');
+ }
+
+ if ($path_parts['extension'] == "otf") {
+ header('Content-type: font/opentype');
+ }
+
+ if ($path_parts['extension'] == "svg") {
+ header('Content-type: image/svg+xml');
+ }
+
+ if ($path_parts['extension'] == "svgz") {
+ header("Content-Encoding: gzip");
+ header('Content-type: image/svg+xml');
+ }
+ $this->_expires_header(1);
+ readfile($file_path);
+ }
+
+ public function images()
+ {
+ $image_file = $this->uri->segment(4);
+ $image_file = basename($image_file);
+
+ //file path
+ $file_path = 'themes/' . $this->theme . '/images/' . $image_file;
+
+ //fallback to default css if view in theme not found
+
+ if (!file_exists($file_path)) {
+ $file_path = 'themes/default/images/' . $image_file;
+ }
+
+ // double checking file
+
+ if (!file_exists($file_path)) {
+ return false;
+ }
+
+ //send
+ $size = getimagesize($file_path);
+ header('Content-type: ' . $size['mime']);
+ $this->_expires_header(30);
+ readfile($file_path);
+ }
+
+ public function js()
+ {
+
+ //get js
+ $segments = $this->uri->segment_array();
+ array_shift($segments);
+ array_shift($segments);
+ array_shift($segments);
+ $js_file = implode('/', $segments);
+ $js_file = str_replace('../', '', $js_file);
+
+ //file path
+ $file_path = 'themes/' . $this->theme . '/js/' . $js_file;
+
+ //fallback to default js if js in theme not found
+
+ if (!file_exists($file_path)) {
+ $file_path = 'themes/default/js/' . $js_file;
+ }
+
+ // return empty string if not found, to not mess up existing JS
+
+ if (!file_exists($file_path)) {
+ header('HTTP/1.1 404 Not Found');
+ return '';
+ }
+
+ //send
+ header('Content-Type: application/x-javascript; charset=utf-8');
+ $this->_expires_header(30);
+ readfile($file_path);
+ }
+ private function _expires_header($days)
+ {
+ header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 60 * 60 * 24 * $days));
+ }
}
diff --git a/htdocs/application/controllers/Unittest.php b/htdocs/application/controllers/Unittest.php
index 3a12be0..937ab92 100644
--- a/htdocs/application/controllers/Unittest.php
+++ b/htdocs/application/controllers/Unittest.php
@@ -1,57 +1,50 @@
-load->library('unit_test');
- $this->load->model('pastes');
+ public function __construct()
+ {
+ parent::__construct();
- //self test
- $test = 1 + 1;
- $expected_result = 2;
- $test_name = 'Self test: Adds one plus one';
- $this->unit->run($test, $expected_result, $test_name);
+ //protection
- //manipulation: create paste
- $_POST['code'] = 'pastes->createPaste();
+ if ($_SERVER['HTTP_HOST'] != 'stikked') {
+ exit;
+ }
+ }
- //paste created, has pid
- $test = $pid;
- $expected_result = 'is_string';
- $test_name = 'Create paste, has pid';
- $this->unit->run($test, $expected_result, $test_name);
- $pid = str_replace('view/', '', $pid);
+ public function index()
+ {
+ $this->load->library('unit_test');
+ $this->load->model('pastes');
- //manipulation: delete paste
- $this->pastes->delete_paste($pid);
+ //self test
+ $test = 1 + 1;
+ $expected_result = 2;
+ $test_name = 'Self test: Adds one plus one';
+ $this->unit->run($test, $expected_result, $test_name);
- //report
- echo $this->unit->report();
- }
+ //manipulation: create paste
+ $_POST['code'] = 'pastes->createPaste();
+
+ //paste created, has pid
+ $test = $pid;
+ $expected_result = 'is_string';
+ $test_name = 'Create paste, has pid';
+ $this->unit->run($test, $expected_result, $test_name);
+ $pid = str_replace('view/', '', $pid);
+
+ //manipulation: delete paste
+ $this->pastes->delete_paste($pid);
+
+ //report
+ echo $this->unit->report();
+ }
}
diff --git a/htdocs/application/core/MY_Loader.php b/htdocs/application/core/MY_Loader.php
index 1b1f1da..64d67b6 100644
--- a/htdocs/application/core/MY_Loader.php
+++ b/htdocs/application/core/MY_Loader.php
@@ -1,209 +1,178 @@
-_ci_load(array(
- '_ci_view' => $view_path,
- '_ci_vars' => $this->_ci_prepare_view_vars($vars) ,
- '_ci_return' => $return
- ));
- }
+ //view path
+ $view_path = 'themes/' . $theme . '/views/' . $view . '.php';
- // --------------------------------------------------------------------
-
- /**
- * Internal CI Data Loader
- *
- * Used to load views and files.
- *
- * Variables are prefixed with _ci_ to avoid symbol collision with
- * variables made available to view files.
- *
- * @used-by CI_Loader::view()
- * @used-by CI_Loader::file()
- * @param array $_ci_data Data to load
- * @return object
- */
- protected
- function _ci_load($_ci_data)
- {
+ //fallback to default view if view in theme not found
- // Set the default data variables
- foreach (array(
- '_ci_view',
- '_ci_vars',
- '_ci_path',
- '_ci_return'
- ) as $_ci_val)
- {
- $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : FALSE;
- }
- $file_exists = FALSE;
+ if (!file_exists($view_path)) {
+ $view_path = 'themes/default/views/' . $view . '.php';
+ }
- // Set the path to the requested file
-
- if (is_string($_ci_path) && $_ci_path !== '')
- {
- $_ci_x = explode('/', $_ci_path);
- $_ci_file = end($_ci_x);
- }
- else
- {
- $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
- $_ci_file = ($_ci_ext === '') ? $_ci_view . '.php' : $_ci_view;
- foreach ($this->_ci_view_paths as $_ci_view_file => $cascade)
- {
+ //return
+ return $this->_ci_load(array(
+ '_ci_view' => $view_path,
+ '_ci_vars' => $this->_ci_prepare_view_vars($vars),
+ '_ci_return' => $return,
+ ));
+ }
- /* *** modification for stikked themes ***
- *
- * we are by default in the htdocs/application/views folder, which is bad.
- * for security reasons, themes folder should be outside the application dir.
- * but file_exists() doesn't work with ../../ in filenames :-(
- * so, applying the full FrontControllerPATH here, making ../../ superfluous.
- *
- */
-
- if (file_exists(FCPATH . $_ci_file))
- {
- $_ci_path = FCPATH . $_ci_file;
- $file_exists = TRUE;
- break;
- }
-
- if (!$cascade)
- {
- break;
- }
- }
- }
-
- if (!$file_exists && !file_exists($_ci_path))
- {
- show_error('Unable to load the requested file: ' . $_ci_file);
- }
+ // --------------------------------------------------------------------
- // This allows anything loaded using $this->load (views, files, etc.)
- // to become accessible from within the Controller and Model functions.
+ /**
+ * Internal CI Data Loader
+ *
+ * Used to load views and files.
+ *
+ * Variables are prefixed with _ci_ to avoid symbol collision with
+ * variables made available to view files.
+ *
+ * @used-by CI_Loader::view()
+ * @used-by CI_Loader::file()
+ * @param array $_ci_data Data to load
+ * @return object
+ */
+ protected function _ci_load($_ci_data)
+ {
- $_ci_CI = & get_instance();
- foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
- {
-
- if (!isset($this->$_ci_key))
- {
- $this->$_ci_key = & $_ci_CI->$_ci_key;
- }
- }
+ // Set the default data variables
+ foreach (array(
+ '_ci_view',
+ '_ci_vars',
+ '_ci_path',
+ '_ci_return',
+ ) as $_ci_val) {
+ $$_ci_val = isset($_ci_data[$_ci_val]) ? $_ci_data[$_ci_val] : false;
+ }
+ $file_exists = false;
- /*
- * Extract and cache variables
- *
- * You can either set variables using the dedicated $this->load->vars()
- * function or via the second parameter of this function. We'll merge
- * the two types and cache them so that views that are embedded within
- * other views can have access to these variables.
- */
-
- if (is_array($_ci_vars))
- {
- $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
- }
- extract($this->_ci_cached_vars);
+ // Set the path to the requested file
- /*
- * Buffer the output
- *
- * We buffer the output for two reasons:
- * 1. Speed. You get a significant speed boost.
- * 2. So that the final rendered template can be post-processed by
- * the output class. Why do we need post processing? For one thing,
- * in order to show the elapsed page load time. Unless we can
- * intercept the content right before it's sent to the browser and
- * then stop the timer it won't be accurate.
- */
- ob_start();
+ if (is_string($_ci_path) && $_ci_path !== '') {
+ $_ci_x = explode('/', $_ci_path);
+ $_ci_file = end($_ci_x);
+ } else {
+ $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION);
+ $_ci_file = ($_ci_ext === '') ? $_ci_view . '.php' : $_ci_view;
+ foreach ($this->_ci_view_paths as $_ci_view_file => $cascade) {
- // If the PHP installation does not support short tags we'll
- // do a little string replacement, changing the short tags
+ /* *** modification for stikked themes ***
+ *
+ * we are by default in the htdocs/application/views folder, which is bad.
+ * for security reasons, themes folder should be outside the application dir.
+ * but file_exists() doesn't work with ../../ in filenames :-(
+ * so, applying the full FrontControllerPATH here, making ../../ superfluous.
+ *
+ */
- // to standard PHP echo statements.
+ if (file_exists(FCPATH . $_ci_file)) {
+ $_ci_path = FCPATH . $_ci_file;
+ $file_exists = true;
+ break;
+ }
-
- if (!is_php('5.4') && !ini_get('short_open_tag') && config_item('rewrite_short_tags') === TRUE)
- {
- echo eval('?>' . preg_replace('/;*\s*\?>/', '; ?>', str_replace('=', 'load (views, files, etc.)
+ // to become accessible from within the Controller and Model functions.
- /*
- * Flush the buffer... or buff the flusher?
- *
- * In order to permit views to be nested within
- * other views, we need to flush the content back out whenever
- * we are beyond the first level of output buffering so that
- * it can be seen and included properly by the first included
- * template and any subsequent ones. Oy!
- */
-
- if (ob_get_level() > $this->_ci_ob_level + 1)
- {
- ob_end_flush();
- }
- else
- {
- $_ci_CI->output->append_output(ob_get_contents());
- @ob_end_clean();
- }
- return $this;
- }
+ $_ci_CI = &get_instance();
+ foreach (get_object_vars($_ci_CI) as $_ci_key => $_ci_var) {
+
+ if (!isset($this->$_ci_key)) {
+ $this->$_ci_key = &$_ci_CI->$_ci_key;
+ }
+ }
+
+ /*
+ * Extract and cache variables
+ *
+ * You can either set variables using the dedicated $this->load->vars()
+ * function or via the second parameter of this function. We'll merge
+ * the two types and cache them so that views that are embedded within
+ * other views can have access to these variables.
+ */
+
+ if (is_array($_ci_vars)) {
+ $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars);
+ }
+ extract($this->_ci_cached_vars);
+
+ /*
+ * Buffer the output
+ *
+ * We buffer the output for two reasons:
+ * 1. Speed. You get a significant speed boost.
+ * 2. So that the final rendered template can be post-processed by
+ * the output class. Why do we need post processing? For one thing,
+ * in order to show the elapsed page load time. Unless we can
+ * intercept the content right before it's sent to the browser and
+ * then stop the timer it won't be accurate.
+ */
+ ob_start();
+
+ // If the PHP installation does not support short tags we'll
+ // do a little string replacement, changing the short tags
+
+ // to standard PHP echo statements.
+
+ if (!is_php('5.4') && !ini_get('short_open_tag') && config_item('rewrite_short_tags') === true) {
+ echo eval('?>' . preg_replace('/;*\s*\?>/', '; ?>', str_replace('=', ' $this->_ci_ob_level + 1) {
+ ob_end_flush();
+ } else {
+ $_ci_CI->output->append_output(ob_get_contents());
+ @ob_end_clean();
+ }
+ return $this;
+ }
}
diff --git a/htdocs/application/helpers/captcha_helper.php b/htdocs/application/helpers/captcha_helper.php
index 770b6a5..9bcb132 100644
--- a/htdocs/application/helpers/captcha_helper.php
+++ b/htdocs/application/helpers/captcha_helper.php
@@ -1,25 +1,18 @@
- '',
- 'img_path' => '',
- 'img_url' => '',
- 'img_width' => '150',
- 'img_height' => '30',
- 'font_path' => '',
- 'expiration' => 7200
- );
- foreach ($defaults as $key => $val)
- {
-
- if (!is_array($data))
- {
-
- if (!isset($$key) OR $$key == '')
- {
- $$key = $val;
- }
- }
- else
- {
- $$key = (!isset($data[$key])) ? $val : $data[$key];
- }
- }
-
- if ($img_path == '' OR $img_url == '')
- {
- return FALSE;
- }
-
- if (!@is_dir($img_path))
- {
- return FALSE;
- }
-
- if (!is_writable($img_path))
- {
- return FALSE;
- }
-
- if (!extension_loaded('gd'))
- {
- return FALSE;
- }
+if (!function_exists('create_captcha')) {
- // -----------------------------------
- // Remove old images
+ function create_captcha($data = '', $img_path = '', $img_url = '', $font_path = '')
+ {
+ $defaults = array(
+ 'word' => '',
+ 'img_path' => '',
+ 'img_url' => '',
+ 'img_width' => '150',
+ 'img_height' => '30',
+ 'font_path' => '',
+ 'expiration' => 7200,
+ );
+ foreach ($defaults as $key => $val) {
- // -----------------------------------
+ if (!is_array($data)) {
- list($usec, $sec) = explode(" ", microtime());
- $now = ((float)$usec + (float)$sec);
- $current_dir = @opendir($img_path);
- while ($filename = @readdir($current_dir))
- {
-
- if ($filename != "." and $filename != ".." and $filename != "index.html")
- {
- $name = str_replace(".jpg", "", $filename);
-
- if (($name + $expiration) < $now)
- {
- @unlink($img_path . $filename);
- }
- }
- }
- @closedir($current_dir);
+ if (!isset($$key) or $$key == '') {
+ $$key = $val;
+ }
+ } else {
+ $$key = (!isset($data[$key])) ? $val : $data[$key];
+ }
+ }
- // -----------------------------------
- // Do we have a "word" yet?
+ if ($img_path == '' or $img_url == '') {
+ return false;
+ }
- // -----------------------------------
+ if (!@is_dir($img_path)) {
+ return false;
+ }
-
- if ($word == '')
- {
- $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $str = '';
- for ($i = 0;$i < 8;$i++)
- {
- $str.= substr($pool, mt_rand(0, strlen($pool) - 1) , 1);
- }
- $word = $str;
- }
+ if (!is_writable($img_path)) {
+ return false;
+ }
- // -----------------------------------
- // Determine angle and position
+ if (!extension_loaded('gd')) {
+ return false;
+ }
- // -----------------------------------
+ // -----------------------------------
+ // Remove old images
- $length = strlen($word);
- $angle = ($length >= 6) ? rand(-($length - 6) , ($length - 6)) : 0;
- $x_axis = rand(6, (360 / $length) - 16);
- $y_axis = ($angle >= 0) ? rand($img_height, $img_width) : rand(6, $img_height);
+ // -----------------------------------
- // -----------------------------------
- // Create image
+ list($usec, $sec) = explode(" ", microtime());
+ $now = ((float) $usec + (float) $sec);
+ $current_dir = @opendir($img_path);
+ while ($filename = @readdir($current_dir)) {
- // -----------------------------------
+ if ($filename != "." and $filename != ".." and $filename != "index.html") {
+ $name = str_replace(".jpg", "", $filename);
- // PHP.net recommends imagecreatetruecolor(), but it isn't always available
+ if (($name + $expiration) < $now) {
+ @unlink($img_path . $filename);
+ }
+ }
+ }
+ @closedir($current_dir);
-
- if (function_exists('imagecreatetruecolor'))
- {
- $im = imagecreatetruecolor($img_width, $img_height);
- }
- else
- {
- $im = imagecreate($img_width, $img_height);
- }
+ // -----------------------------------
+ // Do we have a "word" yet?
- // -----------------------------------
- // Assign colors
+ // -----------------------------------
- // -----------------------------------
+ if ($word == '') {
+ $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $str = '';
+ for ($i = 0; $i < 8; $i++) {
+ $str .= substr($pool, mt_rand(0, strlen($pool) - 1), 1);
+ }
+ $word = $str;
+ }
- $bg_color = imagecolorallocate($im, 255, 255, 255);
- $border_color = imagecolorallocate($im, 153, 102, 102);
- $text_color = imagecolorallocate($im, 204, 153, 153);
- $grid_color = imagecolorallocate($im, 255, 182, 182);
- $shadow_color = imagecolorallocate($im, 255, 240, 240);
+ // -----------------------------------
+ // Determine angle and position
- // -----------------------------------
- // Create the rectangle
+ // -----------------------------------
- // -----------------------------------
+ $length = strlen($word);
+ $angle = ($length >= 6) ? rand(-($length - 6), ($length - 6)) : 0;
+ $x_axis = rand(6, (360 / $length) - 16);
+ $y_axis = ($angle >= 0) ? rand($img_height, $img_width) : rand(6, $img_height);
- ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color);
+ // -----------------------------------
+ // Create image
- // -----------------------------------
- // Create the spiral pattern
+ // -----------------------------------
- // -----------------------------------
+ // PHP.net recommends imagecreatetruecolor(), but it isn't always available
- $theta = 1;
- $thetac = 7;
- $radius = 16;
- $circles = 20;
- $points = 32;
- for ($i = 0;$i < ($circles * $points) - 1;$i++)
- {
- $theta = $theta + $thetac;
- $rad = $radius * ($i / $points);
- $x = ($rad * cos($theta)) + $x_axis;
- $y = ($rad * sin($theta)) + $y_axis;
- $theta = $theta + $thetac;
- $rad1 = $radius * (($i + 1) / $points);
- $x1 = ($rad1 * cos($theta)) + $x_axis;
- $y1 = ($rad1 * sin($theta)) + $y_axis;
- imageline($im, $x, $y, $x1, $y1, $grid_color);
- $theta = $theta - $thetac;
- }
+ if (function_exists('imagecreatetruecolor')) {
+ $im = imagecreatetruecolor($img_width, $img_height);
+ } else {
+ $im = imagecreate($img_width, $img_height);
+ }
- // -----------------------------------
- // Write the text
+ // -----------------------------------
+ // Assign colors
- // -----------------------------------
+ // -----------------------------------
- $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE;
-
- if ($use_font == FALSE)
- {
- $font_size = 5;
- $x = rand(0, $img_width / ($length / 3));
- $y = 0;
- }
- else
- {
- $font_size = 16;
- $x = rand(0, $img_width / ($length / 1.5));
- $y = $font_size + 2;
- }
- for ($i = 0;$i < strlen($word);$i++)
- {
-
- if ($use_font == FALSE)
- {
- $y = rand(0, $img_height / 2);
- imagestring($im, $font_size, $x, $y, substr($word, $i, 1) , $text_color);
- $x+= ($font_size * 2);
- }
- else
- {
- $y = rand($img_height / 2, $img_height - 3);
- imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1));
- $x+= $font_size;
- }
- }
+ $bg_color = imagecolorallocate($im, 255, 255, 255);
+ $border_color = imagecolorallocate($im, 153, 102, 102);
+ $text_color = imagecolorallocate($im, 204, 153, 153);
+ $grid_color = imagecolorallocate($im, 255, 182, 182);
+ $shadow_color = imagecolorallocate($im, 255, 240, 240);
- // -----------------------------------
- // Create the border
+ // -----------------------------------
+ // Create the rectangle
- // -----------------------------------
+ // -----------------------------------
- imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $border_color);
+ ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color);
- // -----------------------------------
- // Generate the image
+ // -----------------------------------
+ // Create the spiral pattern
- // -----------------------------------
+ // -----------------------------------
- $img_name = $now . '.jpg';
- ImageJPEG($im, $img_path . $img_name);
- $img = "
";
- ImageDestroy($im);
- return array(
- 'word' => $word,
- 'time' => $now,
- 'image' => $img
- );
- }
+ $theta = 1;
+ $thetac = 7;
+ $radius = 16;
+ $circles = 20;
+ $points = 32;
+ for ($i = 0; $i < ($circles * $points) - 1; $i++) {
+ $theta = $theta + $thetac;
+ $rad = $radius * ($i / $points);
+ $x = ($rad * cos($theta)) + $x_axis;
+ $y = ($rad * sin($theta)) + $y_axis;
+ $theta = $theta + $thetac;
+ $rad1 = $radius * (($i + 1) / $points);
+ $x1 = ($rad1 * cos($theta)) + $x_axis;
+ $y1 = ($rad1 * sin($theta)) + $y_axis;
+ imageline($im, $x, $y, $x1, $y1, $grid_color);
+ $theta = $theta - $thetac;
+ }
+
+ // -----------------------------------
+ // Write the text
+
+ // -----------------------------------
+
+ $use_font = ($font_path != '' and file_exists($font_path) and function_exists('imagettftext')) ? true : false;
+
+ if ($use_font == false) {
+ $font_size = 5;
+ $x = rand(0, $img_width / ($length / 3));
+ $y = 0;
+ } else {
+ $font_size = 16;
+ $x = rand(0, $img_width / ($length / 1.5));
+ $y = $font_size + 2;
+ }
+ for ($i = 0; $i < strlen($word); $i++) {
+
+ if ($use_font == false) {
+ $y = rand(0, $img_height / 2);
+ imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color);
+ $x += ($font_size * 2);
+ } else {
+ $y = rand($img_height / 2, $img_height - 3);
+ imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1));
+ $x += $font_size;
+ }
+ }
+
+ // -----------------------------------
+ // Create the border
+
+ // -----------------------------------
+
+ imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $border_color);
+
+ // -----------------------------------
+ // Generate the image
+
+ // -----------------------------------
+
+ $img_name = $now . '.jpg';
+ ImageJPEG($im, $img_path . $img_name);
+ $img = "
";
+ ImageDestroy($im);
+ return array(
+ 'word' => $word,
+ 'time' => $now,
+ 'image' => $img,
+ );
+ }
}
/**
* Display CAPTCHA
*
- * @access public
- * @return string
+ * @access public
+ * @return string
*/
-if (!function_exists('display_captcha'))
-{
-
- function display_captcha($word = '')
- {
- $data = '';
- list($usec, $sec) = explode(" ", microtime());
- $now = ((float)$usec + (float)$sec);
- $defaults = array(
- 'word' => $word,
- 'img_path' => '',
- 'img_url' => '',
- 'img_width' => '180',
- 'img_height' => '40',
- 'font_path' => '',
- 'expiration' => 7200
- );
- foreach ($defaults as $key => $val)
- {
-
- if (!is_array($data))
- {
-
- if (!isset($$key) OR $$key == '')
- {
- $$key = $val;
- }
- }
- else
- {
- $$key = (!isset($data[$key])) ? $val : $data[$key];
- }
- }
-
- if (!extension_loaded('gd'))
- {
- return FALSE;
- }
+if (!function_exists('display_captcha')) {
- // -----------------------------------
- // Do we have a "word" yet?
+ function display_captcha($word = '')
+ {
+ $data = '';
+ list($usec, $sec) = explode(" ", microtime());
+ $now = ((float) $usec + (float) $sec);
+ $defaults = array(
+ 'word' => $word,
+ 'img_path' => '',
+ 'img_url' => '',
+ 'img_width' => '180',
+ 'img_height' => '40',
+ 'font_path' => '',
+ 'expiration' => 7200,
+ );
+ foreach ($defaults as $key => $val) {
- // -----------------------------------
+ if (!is_array($data)) {
-
- if ($word == '')
- {
- $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $str = '';
- for ($i = 0;$i < 4;$i++)
- {
- $str.= substr($pool, mt_rand(0, strlen($pool) - 1) , 1);
- }
- $word = $str;
- }
+ if (!isset($$key) or $$key == '') {
+ $$key = $val;
+ }
+ } else {
+ $$key = (!isset($data[$key])) ? $val : $data[$key];
+ }
+ }
- // -----------------------------------
- // Determine angle and position
+ if (!extension_loaded('gd')) {
+ return false;
+ }
- // -----------------------------------
+ // -----------------------------------
+ // Do we have a "word" yet?
- $length = strlen($word);
- $angle = ($length >= 6) ? mt_rand(-($length - 6) , ($length - 6)) : 0;
- $angle = 10;
- $x_axis = mt_rand(6, (360 / $length) - 16);
- $y_axis = ($angle >= 0) ? mt_rand($img_height, $img_width) : mt_rand(6, $img_height);
+ // -----------------------------------
- // -----------------------------------
- // Create image
+ if ($word == '') {
+ $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $str = '';
+ for ($i = 0; $i < 4; $i++) {
+ $str .= substr($pool, mt_rand(0, strlen($pool) - 1), 1);
+ }
+ $word = $str;
+ }
- // -----------------------------------
+ // -----------------------------------
+ // Determine angle and position
- // PHP.net recommends imagecreatetruecolor(), but it isn't always available
+ // -----------------------------------
-
- if (function_exists('imagecreatetruecolor'))
- {
- $im = imagecreatetruecolor($img_width, $img_height);
- }
- else
- {
- $im = imagecreate($img_width, $img_height);
- }
+ $length = strlen($word);
+ $angle = ($length >= 6) ? mt_rand(-($length - 6), ($length - 6)) : 0;
+ $angle = 10;
+ $x_axis = mt_rand(6, (360 / $length) - 16);
+ $y_axis = ($angle >= 0) ? mt_rand($img_height, $img_width) : mt_rand(6, $img_height);
- // -----------------------------------
- // Assign colors
+ // -----------------------------------
+ // Create image
- // -----------------------------------
+ // -----------------------------------
-
- function b()
- {
- return mt_rand(240, 255);
- }
- $bg_color = imagecolorallocate($im, b() , b() , b());
- $border_color = imagecolorallocate($im, 153, 102, 102);
- $text_color = imagecolorallocate($im, 204, 153, 153);
- $grid_color = imagecolorallocate($im, 255, 182, 182);
- $shadow_color = imagecolorallocate($im, 255, 240, 240);
+ // PHP.net recommends imagecreatetruecolor(), but it isn't always available
- // -----------------------------------
- // Create the rectangle
+ if (function_exists('imagecreatetruecolor')) {
+ $im = imagecreatetruecolor($img_width, $img_height);
+ } else {
+ $im = imagecreate($img_width, $img_height);
+ }
- // -----------------------------------
+ // -----------------------------------
+ // Assign colors
- ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color);
+ // -----------------------------------
- // -----------------------------------
- // Create the spiral pattern
+ function b()
+ {
+ return mt_rand(240, 255);
+ }
+ $bg_color = imagecolorallocate($im, b(), b(), b());
+ $border_color = imagecolorallocate($im, 153, 102, 102);
+ $text_color = imagecolorallocate($im, 204, 153, 153);
+ $grid_color = imagecolorallocate($im, 255, 182, 182);
+ $shadow_color = imagecolorallocate($im, 255, 240, 240);
- // -----------------------------------
+ // -----------------------------------
+ // Create the rectangle
- $theta = 1;
- $thetac = 7;
- $radius = 16;
- $circles = 20;
- $points = 32;
- for ($i = 0;$i < ($circles * $points) - 1;$i++)
- {
- $theta = $theta + $thetac;
- $rad = $radius * ($i / $points);
- $x = ($rad * cos($theta)) + $x_axis;
- $y = ($rad * sin($theta)) + $y_axis;
- $theta = $theta + $thetac;
- $rad1 = $radius * (($i + 1) / $points);
- $x1 = ($rad1 * cos($theta)) + $x_axis;
- $y1 = ($rad1 * sin($theta)) + $y_axis;
- imageline($im, $x, $y, $x1, $y1, $grid_color);
- $theta = $theta - $thetac;
- }
+ // -----------------------------------
- // -----------------------------------
- // Write the text
+ ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color);
- // -----------------------------------
+ // -----------------------------------
+ // Create the spiral pattern
- //get random font
+ // -----------------------------------
- $fn = explode(',', '4,5,6,8,16,17,19,24,26');
- $f = mt_rand(0, count($fn) - 1);
- $font_path = './static/fonts/font' . $fn[$f] . '.ttf';
- $use_font = ($font_path != '' AND file_exists($font_path) AND function_exists('imagettftext')) ? TRUE : FALSE;
-
- if ($use_font == FALSE)
- {
- $font_size = 5;
- $x = mt_rand(0, $img_width / ($length / 3));
- $y = 0;
- }
- else
- {
- $font_size = 16;
- $x = mt_rand(0, $img_width / ($length / 1.5));
- $y = $font_size + 2;
- }
- for ($i = 0;$i < strlen($word);$i++)
- {
-
- if ($use_font == FALSE)
- {
- $y = mt_rand(0, $img_height / 2);
- imagestring($im, $font_size, $x, $y, substr($word, $i, 1) , $text_color);
- $x+= ($font_size * 2);
- }
- else
- {
- $y = mt_rand($img_height / 2, $img_height - 3);
- imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1));
- $x+= $font_size;
- }
- }
+ $theta = 1;
+ $thetac = 7;
+ $radius = 16;
+ $circles = 20;
+ $points = 32;
+ for ($i = 0; $i < ($circles * $points) - 1; $i++) {
+ $theta = $theta + $thetac;
+ $rad = $radius * ($i / $points);
+ $x = ($rad * cos($theta)) + $x_axis;
+ $y = ($rad * sin($theta)) + $y_axis;
+ $theta = $theta + $thetac;
+ $rad1 = $radius * (($i + 1) / $points);
+ $x1 = ($rad1 * cos($theta)) + $x_axis;
+ $y1 = ($rad1 * sin($theta)) + $y_axis;
+ imageline($im, $x, $y, $x1, $y1, $grid_color);
+ $theta = $theta - $thetac;
+ }
- // -----------------------------------
- // Create the border
+ // -----------------------------------
+ // Write the text
- // -----------------------------------
+ // -----------------------------------
- imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $border_color);
+ //get random font
- // -----------------------------------
- // Generate the image
+ $fn = explode(',', '4,5,6,8,16,17,19,24,26');
+ $f = mt_rand(0, count($fn) - 1);
+ $font_path = './static/fonts/font' . $fn[$f] . '.ttf';
+ $use_font = ($font_path != '' and file_exists($font_path) and function_exists('imagettftext')) ? true : false;
- // -----------------------------------
+ if ($use_font == false) {
+ $font_size = 5;
+ $x = mt_rand(0, $img_width / ($length / 3));
+ $y = 0;
+ } else {
+ $font_size = 16;
+ $x = mt_rand(0, $img_width / ($length / 1.5));
+ $y = $font_size + 2;
+ }
+ for ($i = 0; $i < strlen($word); $i++) {
- $img_name = $now . '.jpg';
- echo ImageJPEG($im);
- ImageDestroy($im);
- }
+ if ($use_font == false) {
+ $y = mt_rand(0, $img_height / 2);
+ imagestring($im, $font_size, $x, $y, substr($word, $i, 1), $text_color);
+ $x += ($font_size * 2);
+ } else {
+ $y = mt_rand($img_height / 2, $img_height - 3);
+ imagettftext($im, $font_size, $angle, $x, $y, $text_color, $font_path, substr($word, $i, 1));
+ $x += $font_size;
+ }
+ }
+
+ // -----------------------------------
+ // Create the border
+
+ // -----------------------------------
+
+ imagerectangle($im, 0, 0, $img_width - 1, $img_height - 1, $border_color);
+
+ // -----------------------------------
+ // Generate the image
+
+ // -----------------------------------
+
+ $img_name = $now . '.jpg';
+ echo ImageJPEG($im);
+ ImageDestroy($im);
+ }
}
// ------------------------------------------------------------------------
/* End of file captcha_helper.php */
-
/* Location: ./system/heleprs/captcha_helper.php */
diff --git a/htdocs/application/helpers/json_helper.php b/htdocs/application/helpers/json_helper.php
index 8fe3c02..7adfe03 100644
--- a/htdocs/application/helpers/json_helper.php
+++ b/htdocs/application/helpers/json_helper.php
@@ -1,58 +1,46 @@
- $value)
- {
- $output_indexed[] = json_encode($value);
- $output_associative[] = json_encode($key) . ':' . json_encode($value);
-
- if ($output_index_count !== NULL && $output_index_count++ !== $key)
- {
- $output_index_count = NULL;
- }
- }
-
- if ($output_index_count !== NULL)
- {
- return '[' . implode(',', $output_indexed) . ']';
- }
- else
- {
- return '{' . implode(',', $output_associative) . '}';
- }
- default:
- return ''; // Not supported
-
-
- }
- }
+ $value) {
+ $output_indexed[] = json_encode($value);
+ $output_associative[] = json_encode($key) . ':' . json_encode($value);
+
+ if ($output_index_count !== null && $output_index_count++ !== $key) {
+ $output_index_count = null;
+ }
+ }
+
+ if ($output_index_count !== null) {
+ return '[' . implode(',', $output_indexed) . ']';
+ } else {
+ return '{' . implode(',', $output_associative) . '}';
+ }
+ default:
+ return ''; // Not supported
+
+ }
+ }
}
diff --git a/htdocs/application/helpers/language_helper.php b/htdocs/application/helpers/language_helper.php
index 1439520..14c0220 100644
--- a/htdocs/application/helpers/language_helper.php
+++ b/htdocs/application/helpers/language_helper.php
@@ -1,24 +1,18 @@
-lang->line($index);
-
- if ($id != '')
- {
- $line = '";
- }
- return ($line != '' ? $line : '[' . $index . ']');
- }
+if (!function_exists('lang')) {
+
+ function lang($index, $id = '')
+ {
+ $CI = &get_instance();
+ $line = $CI->lang->line($index);
+
+ if ($id != '') {
+ $line = '";
+ }
+ return ($line != '' ? $line : '[' . $index . ']');
+ }
}
/**
* Random expire msg
*
* Displays a random expire message
*
- * @access public
- * @return string
+ * @access public
+ * @return string
*/
-if (!function_exists('random_expire_msg'))
-{
-
- function random_expire_msg()
- {
- $CI = & get_instance();
- $expires = $CI->config->item('expires');
- return $expires[rand(0, sizeof($expires) - 1) ];
- }
+if (!function_exists('random_expire_msg')) {
+
+ function random_expire_msg()
+ {
+ $CI = &get_instance();
+ $expires = $CI->config->item('expires');
+ return $expires[rand(0, sizeof($expires) - 1)];
+ }
}
// ------------------------------------------------------------------------
/* End of file language_helper.php */
-
/* Location: ./system/helpers/language_helper.php */
diff --git a/htdocs/application/helpers/recaptcha_helper.php b/htdocs/application/helpers/recaptcha_helper.php
index 7067ab7..3bf9c3e 100644
--- a/htdocs/application/helpers/recaptcha_helper.php
+++ b/htdocs/application/helpers/recaptcha_helper.php
@@ -44,18 +44,18 @@ define("RECAPTCHA_VERIFY_SERVER", "www.google.com");
* @param $data - array of string elements to be encoded
* @return string - encoded request
*/
-function _recaptcha_qsencode ($data) {
- $req = "";
- foreach ( $data as $key => $value )
- $req .= $key . '=' . urlencode( stripslashes($value) ) . '&';
+function _recaptcha_qsencode($data)
+{
+ $req = "";
+ foreach ($data as $key => $value) {
+ $req .= $key . '=' . urlencode(stripslashes($value)) . '&';
+ }
- // Cut the last '&'
- $req=substr($req,0,strlen($req)-1);
- return $req;
+ // Cut the last '&'
+ $req = substr($req, 0, strlen($req) - 1);
+ return $req;
}
-
-
/**
* Submits an HTTP POST to a reCAPTCHA server
* @param string $host
@@ -64,35 +64,36 @@ function _recaptcha_qsencode ($data) {
* @param int port
* @return array response
*/
-function _recaptcha_http_post($host, $path, $data, $port = 80) {
+function _recaptcha_http_post($host, $path, $data, $port = 80)
+{
- $req = _recaptcha_qsencode ($data);
+ $req = _recaptcha_qsencode($data);
- $http_request = "POST $path HTTP/1.0\r\n";
- $http_request .= "Host: $host\r\n";
- $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
- $http_request .= "Content-Length: " . strlen($req) . "\r\n";
- $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
- $http_request .= "\r\n";
- $http_request .= $req;
+ $http_request = "POST $path HTTP/1.0\r\n";
+ $http_request .= "Host: $host\r\n";
+ $http_request .= "Content-Type: application/x-www-form-urlencoded;\r\n";
+ $http_request .= "Content-Length: " . strlen($req) . "\r\n";
+ $http_request .= "User-Agent: reCAPTCHA/PHP\r\n";
+ $http_request .= "\r\n";
+ $http_request .= $req;
- $response = '';
- if( false == ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
- die ('Could not open socket');
- }
+ $response = '';
+ if (false == ($fs = @fsockopen($host, $port, $errno, $errstr, 10))) {
+ die('Could not open socket');
+ }
- fwrite($fs, $http_request);
+ fwrite($fs, $http_request);
- while ( !feof($fs) )
- $response .= fgets($fs, 1160); // One TCP-IP packet
- fclose($fs);
- $response = explode("\r\n\r\n", $response, 2);
+ while (!feof($fs)) {
+ $response .= fgets($fs, 1160);
+ }
+ // One TCP-IP packet
+ fclose($fs);
+ $response = explode("\r\n\r\n", $response, 2);
- return $response;
+ return $response;
}
-
-
/**
* Gets the challenge HTML (javascript and non-javascript version).
* This is called from the browser, and the resulting reCAPTCHA HTML widget
@@ -103,96 +104,89 @@ function _recaptcha_http_post($host, $path, $data, $port = 80) {
* @return string - The HTML to be embedded in the user's form.
*/
-function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
+function recaptcha_get_html($pubkey, $error = null, $use_ssl = false)
{
- if ($pubkey == null || $pubkey == '') {
- die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create");
- }
-
- if ($use_ssl) {
- $server = RECAPTCHA_API_SECURE_SERVER;
- } else {
- $server = RECAPTCHA_API_SERVER;
- }
+ if ($pubkey == null || $pubkey == '') {
+ die("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create");
+ }
- $errorpart = "";
- if ($error) {
- $errorpart = "&error=" . $error;
- }
- return '
+ if ($use_ssl) {
+ $server = RECAPTCHA_API_SECURE_SERVER;
+ } else {
+ $server = RECAPTCHA_API_SERVER;
+ }
+
+ $errorpart = "";
+ if ($error) {
+ $errorpart = "&error=" . $error;
+ }
+ return '
';
+ /*return '
- /*return '
-
- ';*/
+';*/
}
-
-
-
/**
* A ReCaptchaResponse is returned from recaptcha_check_answer()
*/
-class ReCaptchaResponse {
- var $is_valid;
- var $error;
+class ReCaptchaResponse
+{
+ public $is_valid;
+ public $error;
}
-
/**
- * Calls an HTTP POST function to verify if the user's guess was correct
- * @param string $privkey
- * @param string $remoteip
- * @param string $challenge
- * @param string $response
- * @param array $extra_params an array of extra variables to post to the server
- * @return ReCaptchaResponse
- */
-function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
+ * Calls an HTTP POST function to verify if the user's guess was correct
+ * @param string $privkey
+ * @param string $remoteip
+ * @param string $challenge
+ * @param string $response
+ * @param array $extra_params an array of extra variables to post to the server
+ * @return ReCaptchaResponse
+ */
+function recaptcha_check_answer($privkey, $remoteip, $challenge, $response, $extra_params = array())
{
- if ($privkey == null || $privkey == '') {
- die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create");
- }
+ if ($privkey == null || $privkey == '') {
+ die("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create");
+ }
- if ($remoteip == null || $remoteip == '') {
- die ("For security reasons, you must pass the remote ip to reCAPTCHA");
- }
+ if ($remoteip == null || $remoteip == '') {
+ die("For security reasons, you must pass the remote ip to reCAPTCHA");
+ }
-
-
- //discard spam submissions
- if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
- $recaptcha_response = new ReCaptchaResponse();
- $recaptcha_response->is_valid = false;
- $recaptcha_response->error = 'incorrect-captcha-sol';
- return $recaptcha_response;
- }
-
- $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
- array (
- 'privatekey' => $privkey,
- 'remoteip' => $remoteip,
- 'challenge' => $challenge,
- 'response' => $response
- ) + $extra_params
- );
-
- $answers = explode ("\n", $response [1]);
+ //discard spam submissions
+ if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
$recaptcha_response = new ReCaptchaResponse();
-
- if (trim ($answers [0]) == 'true') {
- $recaptcha_response->is_valid = true;
- }
- else {
- $recaptcha_response->is_valid = false;
- $recaptcha_response->error = $answers [1];
- }
+ $recaptcha_response->is_valid = false;
+ $recaptcha_response->error = 'incorrect-captcha-sol';
return $recaptcha_response;
+ }
+
+ $response = _recaptcha_http_post(RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
+ array(
+ 'privatekey' => $privkey,
+ 'remoteip' => $remoteip,
+ 'challenge' => $challenge,
+ 'response' => $response,
+ ) + $extra_params
+ );
+
+ $answers = explode("\n", $response[1]);
+ $recaptcha_response = new ReCaptchaResponse();
+
+ if (trim($answers[0]) == 'true') {
+ $recaptcha_response->is_valid = true;
+ } else {
+ $recaptcha_response->is_valid = false;
+ $recaptcha_response->error = $answers[1];
+ }
+ return $recaptcha_response;
}
@@ -203,45 +197,48 @@ function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $ex
* @param string $domain The domain where the page is hosted
* @param string $appname The name of your application
*/
-function recaptcha_get_signup_url ($domain = null, $appname = null) {
- return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
+function recaptcha_get_signup_url($domain = null, $appname = null)
+{
+ return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode(array('domains' => $domain, 'app' => $appname));
}
-function _recaptcha_aes_pad($val) {
- $block_size = 16;
- $numpad = $block_size - (strlen ($val) % $block_size);
- return str_pad($val, strlen ($val) + $numpad, chr($numpad));
+function _recaptcha_aes_pad($val)
+{
+ $block_size = 16;
+ $numpad = $block_size - (strlen($val) % $block_size);
+ return str_pad($val, strlen($val) + $numpad, chr($numpad));
}
/* Mailhide related code */
-function _recaptcha_aes_encrypt($val,$ky) {
- if (! function_exists ("mcrypt_encrypt")) {
- die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
- }
- $mode=MCRYPT_MODE_CBC;
- $enc=MCRYPT_RIJNDAEL_128;
- $val=_recaptcha_aes_pad($val);
- return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
+function _recaptcha_aes_encrypt($val, $ky)
+{
+ if (!function_exists("mcrypt_encrypt")) {
+ die("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
+ }
+ $mode = MCRYPT_MODE_CBC;
+ $enc = MCRYPT_RIJNDAEL_128;
+ $val = _recaptcha_aes_pad($val);
+ return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
}
-
-function _recaptcha_mailhide_urlbase64 ($x) {
- return strtr(base64_encode ($x), '+/', '-_');
+function _recaptcha_mailhide_urlbase64($x)
+{
+ return strtr(base64_encode($x), '+/', '-_');
}
/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
-function recaptcha_mailhide_url($pubkey, $privkey, $email) {
- if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
- die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
- "you can do so at http://www.google.com/recaptcha/mailhide/apikey");
- }
-
+function recaptcha_mailhide_url($pubkey, $privkey, $email)
+{
+ if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
+ die("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
+ "you can do so at http://www.google.com/recaptcha/mailhide/apikey");
+ }
- $ky = pack('H*', $privkey);
- $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
-
- return "https://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
+ $ky = pack('H*', $privkey);
+ $cryptmail = _recaptcha_aes_encrypt($email, $ky);
+
+ return "https://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64($cryptmail);
}
/**
@@ -249,17 +246,18 @@ function recaptcha_mailhide_url($pubkey, $privkey, $email) {
* eg, given johndoe@example,com return ["john", "example.com"].
* the email is then displayed as john...@example.com
*/
-function _recaptcha_mailhide_email_parts ($email) {
- $arr = preg_split("/@/", $email );
+function _recaptcha_mailhide_email_parts($email)
+{
+ $arr = preg_split("/@/", $email);
- if (strlen ($arr[0]) <= 4) {
- $arr[0] = substr ($arr[0], 0, 1);
- } else if (strlen ($arr[0]) <= 6) {
- $arr[0] = substr ($arr[0], 0, 3);
- } else {
- $arr[0] = substr ($arr[0], 0, 4);
- }
- return $arr;
+ if (strlen($arr[0]) <= 4) {
+ $arr[0] = substr($arr[0], 0, 1);
+ } else if (strlen($arr[0]) <= 6) {
+ $arr[0] = substr($arr[0], 0, 3);
+ } else {
+ $arr[0] = substr($arr[0], 0, 4);
+ }
+ return $arr;
}
/**
@@ -268,14 +266,12 @@ function _recaptcha_mailhide_email_parts ($email) {
*
* http://www.google.com/recaptcha/mailhide/apikey
*/
-function recaptcha_mailhide_html($pubkey, $privkey, $email) {
- $emailparts = _recaptcha_mailhide_email_parts ($email);
- $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
-
- return htmlentities($emailparts[0]) . "...@" . htmlentities ($emailparts [1]);
+function recaptcha_mailhide_html($pubkey, $privkey, $email)
+{
+ $emailparts = _recaptcha_mailhide_email_parts($email);
+ $url = recaptcha_mailhide_url($pubkey, $privkey, $email);
+
+ return htmlentities($emailparts[0]) . "...@" . htmlentities($emailparts[1]);
}
-
-
-?>
diff --git a/htdocs/application/models/Languages.php b/htdocs/application/models/Languages.php
index dfc7fb9..2ceaff9 100644
--- a/htdocs/application/models/Languages.php
+++ b/htdocs/application/models/Languages.php
@@ -1,62 +1,49 @@
-load->config('geshi_languages');
- $this->geshi_languages = $this->config->item('geshi_languages');
- $this->favorite_languages = $this->config->item('favorite_languages');
-
- if ($this->favorite_languages === NULL)
- {
- $this->load->config('config');
- $this->favorite_languages = $this->config->item('favorite_languages');
- }
- }
-
- function valid_language($lang)
- {
- return array_key_exists($lang, $this->geshi_languages);
- }
-
- function get_languages()
- {
- $data = array();
-
- if (is_array($this->favorite_languages))
- {
- foreach ($this->favorite_languages as $key)
- {
- $data[$key] = $this->geshi_languages[$key];
- }
- $data["0"] = "-----------------";
- }
- foreach ($this->geshi_languages as $key => $value)
- {
-
- if (!in_array($key, $data))
- {
- $data[$key] = $value;
- }
- }
- return $data;
- }
-
- function code_to_description($code)
- {
- return $this->geshi_languages[$code];
- }
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->load->config('geshi_languages');
+ $this->geshi_languages = $this->config->item('geshi_languages');
+ $this->favorite_languages = $this->config->item('favorite_languages');
+
+ if ($this->favorite_languages === null) {
+ $this->load->config('config');
+ $this->favorite_languages = $this->config->item('favorite_languages');
+ }
+ }
+
+ public function valid_language($lang)
+ {
+ return array_key_exists($lang, $this->geshi_languages);
+ }
+
+ public function get_languages()
+ {
+ $data = array();
+
+ if (is_array($this->favorite_languages)) {
+ foreach ($this->favorite_languages as $key) {
+ $data[$key] = $this->geshi_languages[$key];
+ }
+ $data["0"] = "-----------------";
+ }
+ foreach ($this->geshi_languages as $key => $value) {
+
+ if (!in_array($key, $data)) {
+ $data[$key] = $value;
+ }
+ }
+ return $data;
+ }
+
+ public function code_to_description($code)
+ {
+ return $this->geshi_languages[$code];
+ }
}
diff --git a/htdocs/application/models/Pastes.php b/htdocs/application/models/Pastes.php
index 9f0612d..bdffd1d 100644
--- a/htdocs/application/models/Pastes.php
+++ b/htdocs/application/models/Pastes.php
@@ -1,1084 +1,904 @@
-db->where('private', 0);
-
- if ($ip_address)
- {
- $this->db->where('ip_address', $ip_address);
- }
- $query = $this->db->get('pastes');
- return $query->num_rows();
- }
-
- function countReplies($pid)
- {
- $this->db->where('replyto', $pid);
- $query = $this->db->get('pastes');
- return $query->num_rows();
- }
-
- function createPaste()
- {
- $data['created'] = time();
- //this is SO evil… saving the «raw» data with htmlspecialchars :-( (but I have to leave this, because of backwards-compatibility)
- $data['raw'] = htmlspecialchars($this->_strip_bad_multibyte_chars($this->input->post('code')));
- $data['lang'] = htmlspecialchars($this->input->post('lang'));
- $data['replyto'] = ($this->input->post('reply') === null ? '0' : $this->input->post('reply'));
-
- if ($this->input->post('name'))
- {
- $data['name'] = htmlspecialchars($this->input->post('name'));
- }
- else
- {
- $data['name'] = $this->config->item('unknown_poster');
-
- if ($data['name'] == 'random')
- {
- $nouns = $this->config->item('nouns');
- $adjectives = $this->config->item('adjectives');
- $data['name'] = $adjectives[array_rand($adjectives) ] . " " . $nouns[array_rand($nouns) ];
- }
- }
-
- if ($this->input->post('title'))
- {
- $data['title'] = htmlspecialchars($this->input->post('title'));
- }
- else
- {
- $data['title'] = $this->config->item('unknown_title');
- }
- $data['private'] = ($this->input->post('private') === null ? '0' : $this->input->post('private'));
- do
- {
- $data['pid'] = substr(md5(md5(mt_rand(0, 1000000) . time())) , rand(0, 24) , 8);
- $this->db->select('id');
- $this->db->where('pid', $data['pid']);
- $query = $this->db->get('pastes');
-
- if ($query->num_rows > 0 or $data['pid'] == 'download')
- {
- $n = 0;
- break;
- }
- else
- {
- $n = 1;
- break;
- }
- }
- while ($n == 0);
- $burn = false;
-
- if ($this->input->post('expire') == '0')
- {
- $data['expire'] = 0;
- }
- else
- if ($this->input->post('expire') == 'burn')
- {
- $burn = true;
- $data['toexpire'] = 1;
- $data['expire'] = 0;
- $data['private'] = 1;
- }
- else
- {
- $format = 'Y-m-d H:i:s';
- $data['toexpire'] = 1;
- $data['expire'] = time() + (60 * $this->input->post('expire'));
- }
-
- if ($this->input->post('snipurl') == false)
- {
- $data['snipurl'] = false;
- }
- else
- {
- $url = $this->_get_url($data['pid']);
- $shorturl = $this->_shorten_url($url);
- $data['snipurl'] = $shorturl;
- }
- $data['ip_address'] = $this->input->ip_address();
- $this->db->insert('pastes', $data);
-
- if ($burn)
- {
- $CItemp =& get_instance();
- echo 'Warning!';
- echo 'Copy this URL:
';
- echo '' . site_url('view/'.$data['pid']) . "\n";
- if ($data['snipurl'] !== false)
- {
- echo '
Shorturl: ' . $shorturl . '">' . $shorturl . '
';
- }
- echo "It will become invalid on visit (will be deleted after first read)
\n";
- echo 'Return to ' . $CItemp->config->item('site_name') . '';
- exit;
- }
- else
- {
- return 'view/' . $data['pid'];
- }
- }
- private
- function _get_url($pid)
- {
- $override_url = $this->config->item('displayurl_override');
- return ($override_url ? str_replace('$id', $pid, $override_url) : site_url('view/' . $pid));
- }
- /**
- * Simple cURL connect // Used by _shorten_url
- * @param array $opt_array
- * @return mixed or boolean false on failure
- */
- private
- function curl_connect($opt_array)
- {
- $ch = curl_init();
- curl_setopt_array($ch, $opt_array);
- $resp = curl_exec($ch);
- curl_close($ch);
- return (empty($resp) ? false : $resp);
- }
- private
- function _shorten_url($url)
- {
+ public function __construct()
+ {
+ parent::__construct();
+ }
- // Check if url shortening should be used
- $url_shortening_api = $this->config->item('url_shortening_use');
- $API_DB = array(
- "googl",
- "goo.gl",
- "bitly",
- "bit.ly",
- "yourls",
- "gwgd",
- "polr",
- "random"
- );
-
- if ($url_shortening_api !== false)
- {
-
- if (in_array($url_shortening_api, $API_DB, true))
- {
-
- if ($url_shortening_api === "random")
- {
- $url_shortening_consider = $this->config->item('random_url_engines');
-
- if (!is_array($url_shortening_consider))
- {
-
- if ($url_shortening_consider = @explode(",", preg_replace("/[^a-zA-Z0-9.]+/", "", $url_shortening_consider)))
- {
-
- if (count($url_shortening_consider) > 1)
- {
- foreach ($url_shortening_consider as $key => $api)
- {
-
- if (($key = array_search($api, $API_DB)) === false)
- {
- unset($API_DB[$key]);
- }
- }
- }
- }
- }
- else
- {
-
- if (count($url_shortening_consider) > 1)
- {
- foreach ($url_shortening_consider as $key => $api)
- {
-
- if (($key = array_search($api, $API_DB)) === false)
- {
- unset($API_DB[$key]);
- }
- }
- }
- }
+ public function countPastes($ip_address = false)
+ {
+ $this->db->where('private', 0);
- // We will use random API in this case
- $url_shortening_api = false; //Prepare for use in while loop
+ if ($ip_address) {
+ $this->db->where('ip_address', $ip_address);
+ }
+ $query = $this->db->get('pastes');
+ return $query->num_rows();
+ }
- // Run through while loop as long as an API which satisfy requirement's isn't found.
+ public function countReplies($pid)
+ {
+ $this->db->where('replyto', $pid);
+ $query = $this->db->get('pastes');
+ return $query->num_rows();
+ }
- // As satisfied API is considerer any API which is filled and not empty
+ public function createPaste()
+ {
+ $data['created'] = time();
- while ($url_shortening_api === false && $url_shortening_api !== "random")
- {
- $RAND_API = $API_DB[mt_rand(0, count($API_DB) - 1) ];
- switch ($RAND_API)
- {
- case "yourls":
- $var_yourls_url = $this->config->item('yourls_url');
- $var_yourls_signature = $this->config->item('yourls_signature');
-
- if (!empty($var_yourls_url) && !empty($v_yourls_signature))
- {
- $url_shortening_api = "yourls";
- }
- break;
- case "gwgd":
- case "gw.gd":
- $var_gwgd_url = $this->config->item('gwgd_url');
-
- if (!empty($var_gwgd_url))
- {
- $url_shortening_api = "gwgd";
- }
- break;
- case "googl":
- case "google":
- case "goo.gl":
- $var_googl_url_api = $this->config->item('googl_url_api');
-
- if (!empty($var_googl_url_api))
- {
- $url_shortening_api = "googl";
- }
- break;
- case "bitly":
- case "bit.ly":
- $var_bitly_url_api = $this->config->item('bitly_url_api');
-
- if (!empty($var_bitly_url_api))
- {
- $url_shortening_api = "bitly";
- }
- break;
- case "polr":
- $var_polr_url = $this->config->item('polr_url');
- $var_polr_api = $this->config->item('polr_api');
- if ((!empty($var_polr_url)) && (!empty($var_polr_api)))
- {
- $url_shortening_api = "polr";
- }
- break;
- default:
- $url_shortening_api = false;
- break;
- }
- }
- }
+ //this is SO evil… saving the «raw» data with htmlspecialchars :-( (but I have to leave this, because of backwards-compatibility)
+ $data['raw'] = htmlspecialchars($this->_strip_bad_multibyte_chars($this->input->post('code')));
+ $data['lang'] = htmlspecialchars($this->input->post('lang'));
+ $data['replyto'] = ($this->input->post('reply') === null ? '0' : $this->input->post('reply'));
- // switch: Check which engine should be used
- switch ($url_shortening_api)
- {
- case "yourls":
- $config_yourls_url = $this->config->item('yourls_url');
- $config_yourls_signature = $this->config->item('yourls_signature');
- $timestamp = time();
+ if ($this->input->post('name')) {
+ $data['name'] = htmlspecialchars($this->input->post('name'));
+ } else {
+ $data['name'] = $this->config->item('unknown_poster');
- // grab title to avoid 404s in yourls
-
- if ($this->input->post('title'))
- {
- $yourl_title = htmlspecialchars($this->input->post('title'));
- }
- else
- {
- $yourl_title = $this->config->item('unknown_title');
- }
- $prep_data = array(
- CURLOPT_URL => $config_yourls_url . 'yourls-api.php',
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => array(
- 'url' => $url,
- 'format' => 'simple',
- 'action' => 'shorturl',
- 'title' => $yourl_title,
- 'signature' => md5($timestamp . $config_yourls_signature) ,
- 'timestamp' => $timestamp
- )
- );
- $fetchResp = $this->curl_connect($prep_data);
- $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
- break;
- case "gwgd":
- case "gw.gd":
+ if ($data['name'] == 'random') {
+ $nouns = $this->config->item('nouns');
+ $adjectives = $this->config->item('adjectives');
+ $data['name'] = $adjectives[array_rand($adjectives)] . " " . $nouns[array_rand($nouns)];
+ }
+ }
- //use gwgd
- $url = urlencode($url);
- $config_gwgd_url = $this->config->item('gwgd_url');
- $gwgd_url = ($config_gwgd_url ? $config_gwgd_url : 'http://gw.gd/');
+ if ($this->input->post('title')) {
+ $data['title'] = htmlspecialchars($this->input->post('title'));
+ } else {
+ $data['title'] = $this->config->item('unknown_title');
+ }
+ $data['private'] = ($this->input->post('private') === null ? '0' : $this->input->post('private'));
- // Prepare CURL options array
- $prep_data = array(
- CURLOPT_URL => $gwgd_url . 'api.php?long=' . $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => 'identity'
- );
- $fetchResp = $this->curl_connect($prep_data);
- $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
- break;
- case "googl":
- case "google":
- case "goo.gl":
+ do {
+ $data['pid'] = substr(md5(md5(mt_rand(0, 1000000) . time())), rand(0, 24), 8);
+ $this->db->select('id');
+ $this->db->where('pid', $data['pid']);
+ $query = $this->db->get('pastes');
- // Prepare CURL options array
- $prep_data = array(
- CURLOPT_URL => 'https://www.googleapis.com/urlshortener/v1/url?key=' . $this->config->item('googl_url_api') ,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_HEADER => false,
- CURLOPT_HTTPHEADER => array(
- 'Content-type:application/json'
- ) ,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => json_encode(array(
- 'longUrl' => $url
- ))
- );
- $shorturl = @json_decode($this->curl_connect($prep_data));
- $shorturl = ((isset($shorturl->id)) ? $shorturl->id : false);
- break;
- case "bitly":
- case "bit.ly":
- $config_bitly_api = $this->config->item('bitly_url_api');
- $url = urlencode($url);
+ if ($query->num_rows > 0 or $data['pid'] == 'download') {
+ $n = 0;
+ break;
+ } else {
+ $n = 1;
+ break;
+ }
+ } while ($n == 0);
- // Prepare CURL options array
- $prep_data = array(
- CURLOPT_URL => "https://api-ssl.bitly.com/v3/shorten?access_token={$config_bitly_api}&longUrl={$url}&format=txt",
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYPEER => false
- );
- $fetchResp = $this->curl_connect($prep_data);
- $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
- break;
- case "polr":
- $config_polr_url = $this->config->item('polr_url');
- $config_polr_api = $this->config->item('polr_api');
- $url = urlencode($url);
+ $burn = false;
+ if ($this->input->post('expire') == '0') {
+ $data['expire'] = 0;
+ } else if ($this->input->post('expire') == 'burn') {
+ $burn = true;
+ $data['toexpire'] = 1;
+ $data['expire'] = 0;
+ $data['private'] = 1;
+ } else {
+ $format = 'Y-m-d H:i:s';
+ $data['toexpire'] = 1;
+ $data['expire'] = time() + (60 * $this->input->post('expire'));
+ }
- // Prepare CURL options array
- $prep_data = array(
- CURLOPT_URL => "{$config_polr_url}/api/v2/action/shorten?key={$config_polr_api}&url={$url}&is_secret=false",
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYPEER => false
- );
- $fetchResp = $this->curl_connect($prep_data);
- $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
+ if ($this->input->post('snipurl') == false) {
+ $data['snipurl'] = false;
+ } else {
+ $url = $this->_get_url($data['pid']);
+ $shorturl = $this->_shorten_url($url);
+ $data['snipurl'] = $shorturl;
+ }
+ $data['ip_address'] = $this->input->ip_address();
+ $this->db->insert('pastes', $data);
+
+ if ($burn) {
+ $CItemp = &get_instance();
+ echo 'Warning!';
+ echo 'Copy this URL:
';
+ echo '' . site_url('view/' . $data['pid']) . "\n";
+ if ($data['snipurl'] !== false) {
+ echo '
Shorturl: ' . $shorturl . '">' . $shorturl . '
';
+ }
+ echo "It will become invalid on visit (will be deleted after first read)
\n";
+ echo 'Return to ' . $CItemp->config->item('site_name') . '';
+ exit;
+ } else {
+ return 'view/' . $data['pid'];
+ }
+ }
+
+ private function _get_url($pid)
+ {
+ $override_url = $this->config->item('displayurl_override');
+ return ($override_url ? str_replace('$id', $pid, $override_url) : site_url('view/' . $pid));
+ }
+
+ /**
+ * Simple cURL connect // Used by _shorten_url
+ * @param array $opt_array
+ * @return mixed or boolean false on failure
+ */
+ private function curl_connect($opt_array)
+ {
+ $ch = curl_init();
+ curl_setopt_array($ch, $opt_array);
+ $resp = curl_exec($ch);
+ curl_close($ch);
+ return (empty($resp) ? false : $resp);
+ }
+
+ private function _shorten_url($url)
+ {
+
+ // Check if url shortening should be used
+ $url_shortening_api = $this->config->item('url_shortening_use');
+ $API_DB = array(
+ "googl",
+ "goo.gl",
+ "bitly",
+ "bit.ly",
+ "yourls",
+ "gwgd",
+ "polr",
+ "random",
+ );
+
+ if ($url_shortening_api !== false) {
+
+ if (in_array($url_shortening_api, $API_DB, true)) {
+
+ if ($url_shortening_api === "random") {
+ $url_shortening_consider = $this->config->item('random_url_engines');
+
+ if (!is_array($url_shortening_consider)) {
+
+ if ($url_shortening_consider = @explode(",", preg_replace("/[^a-zA-Z0-9.]+/", "", $url_shortening_consider))) {
+
+ if (count($url_shortening_consider) > 1) {
+ foreach ($url_shortening_consider as $key => $api) {
+
+ if (($key = array_search($api, $API_DB)) === false) {
+ unset($API_DB[$key]);
+ }
+ }
+ }
+ }
+ } else {
+
+ if (count($url_shortening_consider) > 1) {
+ foreach ($url_shortening_consider as $key => $api) {
+
+ if (($key = array_search($api, $API_DB)) === false) {
+ unset($API_DB[$key]);
+ }
+ }
+ }
+ }
+
+ // We will use random API in this case
+ $url_shortening_api = false; //Prepare for use in while loop
+ // Run through while loop as long as an API which satisfy requirement's isn't found.
+ // As satisfied API is considerer any API which is filled and not empty
+ while ($url_shortening_api === false && $url_shortening_api !== "random") {
+ $RAND_API = $API_DB[mt_rand(0, count($API_DB) - 1)];
+ switch ($RAND_API) {
+ case "yourls":
+ $var_yourls_url = $this->config->item('yourls_url');
+ $var_yourls_signature = $this->config->item('yourls_signature');
+
+ if (!empty($var_yourls_url) && !empty($v_yourls_signature)) {
+ $url_shortening_api = "yourls";
+ }
break;
- default:
- $shorturl = false;
- break;
- }
- }
- else
- {
- $shorturl = false;
- }
- }
- else
- {
+ case "gwgd":
+ case "gw.gd":
+ $var_gwgd_url = $this->config->item('gwgd_url');
- // Backward compatibility - Falling back to legacy mode
- $config_yourls_url = $this->config->item('yourls_url');
-
- if ($config_yourls_url)
- {
+ if (!empty($var_gwgd_url)) {
+ $url_shortening_api = "gwgd";
+ }
+ break;
+ case "googl":
+ case "google":
+ case "goo.gl":
+ $var_googl_url_api = $this->config->item('googl_url_api');
- //use yourls
- $config_yourls_signature = $this->config->item('yourls_signature');
- $timestamp = time();
+ if (!empty($var_googl_url_api)) {
+ $url_shortening_api = "googl";
+ }
+ break;
+ case "bitly":
+ case "bit.ly":
+ $var_bitly_url_api = $this->config->item('bitly_url_api');
- // grab title to avoid 404s in yourls
-
- if ($this->input->post('title'))
- {
- $yourl_title = htmlspecialchars($this->input->post('title'));
- }
- else
- {
- $yourl_title = $this->config->item('unknown_title');
- }
- $prep_data = array(
- CURLOPT_URL => $config_yourls_url . 'yourls-api.php',
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => array(
- 'url' => $url,
- 'format' => 'simple',
- 'action' => 'shorturl',
- 'title' => $yourl_title,
- 'signature' => md5($timestamp . $config_yourls_signature) ,
- 'timestamp' => $timestamp
- )
- );
- $fetchResp = $this->curl_connect($prep_data);
- $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
- }
- else
- {
+ if (!empty($var_bitly_url_api)) {
+ $url_shortening_api = "bitly";
+ }
+ break;
+ case "polr":
+ $var_polr_url = $this->config->item('polr_url');
+ $var_polr_api = $this->config->item('polr_api');
+ if ((!empty($var_polr_url)) && (!empty($var_polr_api))) {
+ $url_shortening_api = "polr";
+ }
+ break;
+ default:
+ $url_shortening_api = false;
+ break;
+ }
+ }
+ }
- //use gdgw
- $url = urlencode($url);
- $config_gwgd_url = $this->config->item('gwgd_url');
- $gwgd_url = ($config_gwgd_url ? $config_gwgd_url : 'http://gw.gd/');
+ // switch: Check which engine should be used
+ switch ($url_shortening_api) {
+ case "yourls":
+ $config_yourls_url = $this->config->item('yourls_url');
+ $config_yourls_signature = $this->config->item('yourls_signature');
+ $timestamp = time();
- // Prepare CURL options array
- $prep_data = array(
- CURLOPT_URL => $gwgd_url . 'api.php?long=' . $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => 'identity'
- );
- $fetchResp = $this->curl_connect($prep_data);
- $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
- }
- }
- return $shorturl;
- }
-
- function checkPaste($seg = 2)
- {
-
- if ($this->uri->segment($seg) == "")
- {
- return false;
- }
- else
- {
- $this->db->where('pid', $this->uri->segment($seg));
- $query = $this->db->get('pastes');
-
- if ($query->num_rows() > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
-
- function getPaste($seg = 2, $replies = false, $diff = false)
- {
-
- if ($this->uri->segment($seg) == '')
- {
- redirect('');
- }
- else
- {
- $pid = $this->uri->segment($seg);
- $data['script'] = 'jquery.js';
- }
- $this->load->library('process');
- $this->db->where('pid', $pid);
- $query = $this->db->get('pastes');
- foreach ($query->result_array() as $row)
- {
- $data['title'] = $row['title'];
- $data['pid'] = $row['pid'];
- $data['name'] = $row['name'];
- $data['lang_code'] = $row['lang'];
- $data['lang'] = $this->languages->code_to_description($row['lang']);
- $data['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']) , $row['lang']);
- $data['created'] = $row['created'];
- $data['private'] = $row['private'];
- $data['expire'] = $row['expire'];
- $data['toexpire'] = $row['toexpire'];
- $data['url'] = $this->_get_url($row['pid']);
- $data['raw'] = $row['raw'];
- $data['hits'] = $row['hits'];
- $data['hits_updated'] = $row['hits_updated'];
- $data['snipurl'] = $row['snipurl'];
- $inreply = $row['replyto'];
- }
-
- if ($inreply)
- {
- $this->db->select('name, title');
- $this->db->where('pid', $inreply);
- $query = $this->db->get('pastes');
-
- if ($query->num_rows() > 0)
- {
- foreach ($query->result_array() as $row)
- {
- $data['inreply']['title'] = $row['title'];
- $data['inreply']['name'] = $row['name'];
- $data['inreply']['url'] = site_url('view/' . $inreply);
- }
- }
- else
- {
- $data['inreply'] = false;
- }
-
- if ($diff)
- {
- $this->db->select('raw');
- $this->db->where('pid', $inreply);
- $query = $this->db->get('pastes');
-
- if ($query->num_rows() > 0)
- {
- foreach ($query->result_array() as $row)
- {
+ // grab title to avoid 404s in yourls
+ if ($this->input->post('title')) {
+ $yourl_title = htmlspecialchars($this->input->post('title'));
+ } else {
+ $yourl_title = $this->config->item('unknown_title');
+ }
+ $prep_data = array(
+ CURLOPT_URL => $config_yourls_url . 'yourls-api.php',
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS => array(
+ 'url' => $url,
+ 'format' => 'simple',
+ 'action' => 'shorturl',
+ 'title' => $yourl_title,
+ 'signature' => md5($timestamp . $config_yourls_signature),
+ 'timestamp' => $timestamp,
+ ),
+ );
+ $fetchResp = $this->curl_connect($prep_data);
+ $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
+ break;
+ case "gwgd":
+ case "gw.gd":
- //diff
- //yes, I'm aware, two times htmlspecialchars_decode(). Needs to be, since it's saved that way in the DB from the original stikked author ages ago ;)
+ //use gwgd
+ $url = urlencode($url);
+ $config_gwgd_url = $this->config->item('gwgd_url');
+ $gwgd_url = ($config_gwgd_url ? $config_gwgd_url : 'http://gw.gd/');
- include_once (APPPATH . '/libraries/finediff.php');
- $from_text = htmlspecialchars_decode(utf8_decode($row['raw']));
- $to_text = htmlspecialchars_decode(utf8_decode($data['raw']));
- $opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, FineDiff::$wordGranularity);
- $to_text = FineDiff::renderToTextFromOpcodes($from_text, $opcodes);
- $data['paste'] = htmlspecialchars_decode($this->_format_diff(nl2br(FineDiff::renderDiffToHTMLFromOpcodes($from_text, $opcodes))));
- }
- }
- else
- {
- $data['inreply'] = false;
- }
- }
- }
-
- if ($replies)
- {
- $amount = $this->config->item('per_page');
- $page = ($this->uri->segment(3) ? $this->uri->segment(3) : 0);
- $this->db->select('title, name, created, pid, lang');
- $this->db->where('replyto', $data['pid']);
- $this->db->order_by('id', 'desc');
- $this->db->limit($amount);
- $query = $this->db->get('pastes', $amount, $page);
-
- if ($query->num_rows() > 0)
- {
- $n = 0;
- foreach ($query->result_array() as $row)
- {
- $data['replies'][$n]['title'] = $row['title'];
- $data['replies'][$n]['name'] = $row['name'];
- $data['replies'][$n]['lang'] = $row['lang'];
- $data['replies'][$n]['created'] = $row['created'];
- $data['replies'][$n]['pid'] = $row['pid'];
- $n++;
- }
- $config['base_url'] = site_url('view/' . $data['pid']);
- $config['total_rows'] = $this->countReplies($data['pid']);
- $config['per_page'] = $amount;
- $config['num_links'] = 9;
- $config['full_tag_open'] = '';
- $config['full_tag_close'] = '
';
- $config['uri_segment'] = 3;
- $this->load->library('pagination');
- $this->pagination->initialize($config);
- $data['pages'] = $this->pagination->create_links();
- }
- else
- {
- $replies = false;
- }
- }
+ // Prepare CURL options array
+ $prep_data = array(
+ CURLOPT_URL => $target . $gwgd_url . 'api.php?long=' . $url,
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_ENCODING => 'identity',
+ );
+ $fetchResp = $this->curl_connect($prep_data);
+ $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
+ break;
+ case "googl":
+ case "google":
+ case "goo.gl":
- /*
- * Hits
- * First check if record already exists. If it does, do not insert.
- * INSERT IGNORE INTO does not work for postgres.
- */
- $this->db->select('count(paste_id) as count');
- $this->db->where('paste_id', $pid);
- $this->db->where('ip_address', $this->input->ip_address());
- $query = $this->db->get('trending');
- $hits_count = $query->result_array();
- $hits_count = $hits_count[0]['count'];
-
- if ($hits_count == 0)
- {
- $this->db->insert('trending', array(
- 'paste_id' => $pid,
- 'ip_address' => $this->input->ip_address() ,
- 'created' => time() ,
- ));
- }
+ // Prepare CURL options array
+ $prep_data = array(
+ CURLOPT_URL => 'https://www.googleapis.com/urlshortener/v1/url?key=' . $this->config->item('googl_url_api'),
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_SSL_VERIFYPEER => false,
+ CURLOPT_HEADER => false,
+ CURLOPT_HTTPHEADER => array(
+ 'Content-type:application/json',
+ ),
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS => json_encode(array(
+ 'longUrl' => $url,
+ )),
+ );
+ $shorturl = @json_decode($this->curl_connect($prep_data));
+ $shorturl = ((isset($shorturl->id)) ? $shorturl->id : false);
+ break;
+ case "bitly":
+ case "bit.ly":
+ $config_bitly_api = $this->config->item('bitly_url_api');
+ $url = urlencode($url);
- //update hits counter every minute
-
- if (time() > (60 + $data['hits_updated']))
- {
- $this->calculate_hits($pid, $data['hits']);
- }
+ // Prepare CURL options array
+ $prep_data = array(
+ CURLOPT_URL => "https://api-ssl.bitly.com/v3/shorten?access_token={$config_bitly_api}&longUrl={$url}&format=txt",
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_SSL_VERIFYPEER => false,
+ );
+ $fetchResp = $this->curl_connect($prep_data);
+ $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
+ break;
+ case "polr":
+ $config_polr_url = $this->config->item('polr_url');
+ $config_polr_api = $this->config->item('polr_api');
+ $url = urlencode($url);
- //burn if necessary
-
- if ($data['expire'] == 0 and $data['toexpire'] == 1)
- {
- $this->delete_paste($data['pid']);
- }
- return $data;
- }
-
- function calculate_hits($pid, $current_hits)
- {
- $this->db->select('count(paste_id) as count');
- $this->db->where('paste_id', $pid);
- $query = $this->db->get('trending');
- $hits_count = $query->result_array();
- $hits_count = $hits_count[0]['count'];
-
- if ($hits_count != $current_hits)
- {
+ // Prepare CURL options array
+ $prep_data = array(
+ CURLOPT_URL => "{$config_polr_url}/api/v2/action/shorten?key={$config_polr_api}&url={$url}&is_secret=false",
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_SSL_VERIFYPEER => false,
+ );
+ $fetchResp = $this->curl_connect($prep_data);
+ $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
+ break;
+ default:
+ $shorturl = false;
+ break;
+ }
+ } else {
+ $shorturl = false;
+ }
+ } else {
- //update
- $this->db->where('pid', $pid);
- $this->db->update('pastes', array(
- 'hits' => $hits_count,
- 'hits_updated' => time() ,
- ));
- }
- }
-
- function getReplies($seg = 3)
- {
- $amount = $this->config->item('per_page');
-
- if ($this->uri->segment($seg) == '')
- {
- redirect('');
- }
- else
- {
- $pid = $this->uri->segment($seg);
- }
- $this->db->select('title, name, created, pid, raw, lang');
- $this->db->where('replyto', $pid);
- $this->db->order_by('id', 'desc');
- $this->db->limit($amount);
- $query = $this->db->get('pastes', $amount);
-
- if ($query->num_rows() > 0)
- {
- $n = 0;
- foreach ($query->result_array() as $row)
- {
- $data['replies'][$n]['title'] = $row['title'];
- $data['replies'][$n]['name'] = $row['name'];
- $data['replies'][$n]['lang'] = $row['lang'];
- $data['replies'][$n]['created'] = $row['created'];
- $data['replies'][$n]['pid'] = $row['pid'];
-
- if ($this->uri->segment(2) == 'rss')
- {
- $data['replies'][$n]['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']) , $row['lang']);
- $data['replies'][$n]['raw'] = $row['raw'];
- }
- $n++;
- }
- }
- return $data;
- }
-
- function getLists($root = 'lists/', $seg = 2)
- {
- $this->load->library('pagination');
- $this->load->library('process');
- $amount = $this->config->item('per_page');
- $page = ($this->uri->segment($seg) ? $this->uri->segment($seg) : 0);
- $search = $this->input->get('search');
- $TABLE = $this->config->item('db_prefix') . "pastes";
-
- if ($search)
- {
- $search = '%' . $search . '%';
+ // Backward compatibility - Falling back to legacy mode
+ $config_yourls_url = $this->config->item('yourls_url');
- // count total results
- $sql = "SELECT id FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?)";
- $query = $this->db->query($sql, array(
- $search,
- $search,
- ));
- $total_rows = $query->num_rows();
+ if ($config_yourls_url) {
- // query
-
- if ($this->db->dbdriver == "postgre")
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY created DESC LIMIT $amount OFFSET $page";
- }
- else
- if ($root == 'api/recent')
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY created DESC LIMIT 0,15";
- }
- else
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY created DESC LIMIT $page,$amount";
- }
- $query = $this->db->query($sql, array(
- $search,
- $search,
- ));
- }
- else
- {
+ //use yourls
+ $config_yourls_signature = $this->config->item('yourls_signature');
+ $timestamp = time();
- // count total results
- $sql = "SELECT id FROM $TABLE WHERE private = 0";
- $query = $this->db->query($sql);
- $total_rows = $query->num_rows();
+ // grab title to avoid 404s in yourls
+ if ($this->input->post('title')) {
+ $yourl_title = htmlspecialchars($this->input->post('title'));
+ } else {
+ $yourl_title = $this->config->item('unknown_title');
+ }
+ $prep_data = array(
+ CURLOPT_URL => $config_yourls_url . 'yourls-api.php',
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS => array(
+ 'url' => $url,
+ 'format' => 'simple',
+ 'action' => 'shorturl',
+ 'title' => $yourl_title,
+ 'signature' => md5($timestamp . $config_yourls_signature),
+ 'timestamp' => $timestamp,
+ ),
+ );
+ $fetchResp = $this->curl_connect($prep_data);
+ $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
+ } else {
- // query
-
- if ($this->db->dbdriver == "postgre")
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 ORDER BY created DESC LIMIT $amount OFFSET $page";
- }
- else
- if ($root == 'api/recent')
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 ORDER BY created DESC LIMIT 0,15";
- }
- else
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 ORDER BY created DESC LIMIT $page,$amount";
- }
- $query = $this->db->query($sql);
- }
-
- if ($query->num_rows() > 0)
- {
- $n = 0;
- foreach ($query->result_array() as $row)
- {
- $data['pastes'][$n]['id'] = $row['id'];
- $data['pastes'][$n]['title'] = $row['title'];
- $data['pastes'][$n]['name'] = $row['name'];
- $data['pastes'][$n]['created'] = $row['created'];
- $data['pastes'][$n]['lang'] = $this->languages->code_to_description($row['lang']);
- $data['pastes'][$n]['pid'] = $row['pid'];
-
- if ($this->uri->segment(2) == 'rss')
- {
- $data['pastes'][$n]['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']) , $row['lang']);
- }
- $data['pastes'][$n]['raw'] = $row['raw'];
- $n++;
- }
- }
- $config['base_url'] = site_url($root);
- $config['total_rows'] = $total_rows;
- $config['per_page'] = $amount;
- $config['num_links'] = 9;
- $config['full_tag_open'] = '';
- $config['full_tag_close'] = '
';
- $config['uri_segment'] = $seg;
- $searchparams = ($this->input->get('search') ? '?search=' . $this->input->get('search') : '');
- $config['first_url'] = '0' . $searchparams;
- $config['suffix'] = $searchparams;
- $this->pagination->initialize($config);
- $data['pages'] = $this->pagination->create_links();
- return $data;
- }
-
- function getTrends($root = 'trends/', $seg = 2)
- {
- $this->load->library('pagination');
- $amount = $this->config->item('per_page');
- $page = ($this->uri->segment(2) ? $this->uri->segment(2) : 0);
- $search = $this->input->get('search');
- $TABLE = $this->config->item('db_prefix') . "pastes";
-
- if ($search)
- {
- $search = '%' . $search . '%';
+ //use gdgw
+ $url = urlencode($url);
+ $config_gwgd_url = $this->config->item('gwgd_url');
+ $gwgd_url = ($config_gwgd_url ? $config_gwgd_url : 'http://gw.gd/');
- // count total results
- $sql = "SELECT id FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?)";
- $query = $this->db->query($sql, array(
- $search,
- $search,
- ));
- $total_rows = $query->num_rows();
+ // Prepare CURL options array
+ $prep_data = array(
+ CURLOPT_URL => $target . $gwgd_url . 'api.php?long=' . $url,
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_ENCODING => 'identity',
+ );
+ $fetchResp = $this->curl_connect($prep_data);
+ $shorturl = ((strlen($fetchResp) > 4) ? $fetchResp : false);
+ }
+ }
+ return $shorturl;
+ }
- // query
-
- if ($this->db->dbdriver == "postgre")
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY hits DESC, created DESC LIMIT $amount OFFSET $page";
- }
- else
- if ($root == "api/trending")
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY hits DESC, created DESC LIMIT 0,15";
- }
- else
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY hits DESC, created DESC LIMIT $page,$amount";
- }
- $query = $this->db->query($sql, array(
- $search,
- $search,
- ));
- }
- else
- {
+ public function checkPaste($seg = 2)
+ {
- // count total results
- $sql = "SELECT id FROM $TABLE WHERE private = 0";
- $query = $this->db->query($sql);
- $total_rows = $query->num_rows();
+ if ($this->uri->segment($seg) == "") {
+ return false;
+ } else {
+ $this->db->where('pid', $this->uri->segment($seg));
+ $query = $this->db->get('pastes');
- // query
-
- if ($this->db->dbdriver == "postgre")
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 ORDER BY hits DESC, created DESC LIMIT $amount OFFSET $page";
- }
- else
- if ($root == "api/trending")
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 ORDER BY hits DESC, created DESC LIMIT 0,15";
- }
- else
- {
- $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 ORDER BY hits DESC, created DESC LIMIT $page,$amount";
- }
- $query = $this->db->query($sql);
- }
-
- if ($query->num_rows() > 0)
- {
- $n = 0;
- foreach ($query->result_array() as $row)
- {
- $data['pastes'][$n]['id'] = $row['id'];
- $data['pastes'][$n]['title'] = $row['title'];
- $data['pastes'][$n]['name'] = $row['name'];
- $data['pastes'][$n]['created'] = $row['created'];
- $data['pastes'][$n]['lang'] = $this->languages->code_to_description($row['lang']);
- $data['pastes'][$n]['pid'] = $row['pid'];
- $data['pastes'][$n]['raw'] = $row['raw'];
- $data['pastes'][$n]['hits'] = $row['hits'];
- $n++;
- }
- }
- $config['base_url'] = site_url($root);
- $config['total_rows'] = $total_rows;
- $config['per_page'] = $amount;
- $config['num_links'] = 9;
- $config['full_tag_open'] = '';
- $config['full_tag_close'] = '
';
- $config['uri_segment'] = $seg;
- $searchparams = ($this->input->get('search') ? '?search=' . $this->input->get('search') : '');
- $config['first_url'] = '0' . $searchparams;
- $config['suffix'] = $searchparams;
- $this->pagination->initialize($config);
- $data['pages'] = $this->pagination->create_links();
- return $data;
- }
-
- function getSpamLists($root = 'spamadmin/', $seg = 2, $ip_address = false)
- {
- $this->load->library('pagination');
- $this->load->library('process');
- $amount = $this->config->item('per_page');
- $page = ($this->uri->segment($seg) ? $this->uri->segment($seg) : 0);
- $this->db->select('id, title, name, created, pid, lang, ip_address');
- $this->db->where('private', 0);
-
- if ($ip_address)
- {
- $this->db->where('ip_address', $ip_address);
- }
- $this->db->order_by('created', 'desc');
- $query = $this->db->get('pastes', $amount, $page);
-
- if ($query->num_rows() > 0)
- {
- $n = 0;
- foreach ($query->result_array() as $row)
- {
- $data['pastes'][$n]['id'] = $row['id'];
- $data['pastes'][$n]['title'] = $row['title'];
- $data['pastes'][$n]['name'] = $row['name'];
- $data['pastes'][$n]['created'] = $row['created'];
- $data['pastes'][$n]['lang'] = $row['lang'];
- $data['pastes'][$n]['pid'] = $row['pid'];
- $data['pastes'][$n]['ip_address'] = $row['ip_address'];
- $n++;
- }
- }
+ if ($query->num_rows() > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
- //pagination
- $config['base_url'] = site_url($root);
- $config['total_rows'] = $this->countPastes($ip_address);
- $config['per_page'] = $amount;
- $config['num_links'] = 9;
- $config['full_tag_open'] = '';
- $config['full_tag_close'] = '
';
- $config['uri_segment'] = $seg;
- $this->pagination->initialize($config);
- $data['pages'] = $this->pagination->create_links();
+ public function getPaste($seg = 2, $replies = false, $diff = false)
+ {
- //total spam attempts
- $this->db->select('SUM(spam_attempts) as sum');
- $query = $this->db->get('blocked_ips');
- $q = $query->result_array();
- $data['total_spam_attempts'] = ($q[0]['sum'] != '' ? $q[0]['sum'] : 0);
+ if ($this->uri->segment($seg) == '') {
+ redirect('');
+ } else {
+ $pid = $this->uri->segment($seg);
+ $data['script'] = 'jquery.js';
+ }
+ $this->load->library('process');
+ $this->db->where('pid', $pid);
+ $query = $this->db->get('pastes');
+ foreach ($query->result_array() as $row) {
+ $data['title'] = $row['title'];
+ $data['pid'] = $row['pid'];
+ $data['name'] = $row['name'];
+ $data['lang_code'] = $row['lang'];
+ $data['lang'] = $this->languages->code_to_description($row['lang']);
+ $data['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']), $row['lang']);
+ $data['created'] = $row['created'];
+ $data['private'] = $row['private'];
+ $data['expire'] = $row['expire'];
+ $data['toexpire'] = $row['toexpire'];
+ $data['url'] = $this->_get_url($row['pid']);
+ $data['raw'] = $row['raw'];
+ $data['hits'] = $row['hits'];
+ $data['hits_updated'] = $row['hits_updated'];
+ $data['snipurl'] = $row['snipurl'];
+ $inreply = $row['replyto'];
+ }
- //return
- return $data;
- }
-
- function cron()
- {
- $now = now();
- $this->db->select('pid,expire');
- $this->db->where('toexpire', '1');
- $query = $this->db->get('pastes');
- foreach ($query->result_array() as $row)
- {
- $stamp = $row['expire'];
-
- if ($now > $stamp AND $stamp != 0)
- {
- $this->delete_paste($row['pid']);
- }
- }
- return;
- }
-
- function delete_paste($pid)
- {
- $this->db->where('pid', $pid);
- $this->db->delete('pastes');
+ if ($inreply) {
+ $this->db->select('name, title');
+ $this->db->where('pid', $inreply);
+ $query = $this->db->get('pastes');
- // delete from trending
- $this->db->where('paste_id', $pid);
- $this->db->delete('trending');
- return;
- }
-
- function random_paste()
- {
- $this->load->library('process');
- $this->db->order_by('id', 'RANDOM');
- $this->db->limit(1);
- $this->db->where('private', '0');
- $query = $this->db->get('pastes');
-
- if ($query->num_rows() > 0)
- {
- foreach ($query->result_array() as $row)
- {
- $data['title'] = $row['title'];
- $data['pid'] = $row['pid'];
- $data['name'] = $row['name'];
- $data['lang_code'] = $row['lang'];
- $data['lang'] = $this->languages->code_to_description($row['lang']);
- $data['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']) , $row['lang']);
- $data['created'] = $row['created'];
- $data['url'] = $this->_get_url($row['pid']);
- $data['raw'] = $row['raw'];
- $data['hits'] = $row['hits'];
- $data['hits_updated'] = $row['hits_updated'];
- $data['snipurl'] = $row['snipurl'];
- $inreply = $row['replyto'];
- }
-
- if ($inreply)
- {
- $this->db->select('name, title');
- $this->db->where('pid', $inreply);
- $query = $this->db->get('pastes');
-
- if ($query->num_rows() > 0)
- {
- foreach ($query->result_array() as $row)
- {
- $data['inreply']['title'] = $row['title'];
- $data['inreply']['name'] = $row['name'];
- $data['inreply']['url'] = site_url('view/' . $inreply);
- }
- }
- else
- {
- $data['inreply'] = false;
- }
- }
- return $data;
- }
- return false;
- }
- private
- function _format_diff($text)
- {
- $text = str_replace("\t", ' ', $text);
- $text = str_replace("
", '
', $text);
- $text = str_replace(" ", ' ', $text);
- $text = '' . $text . '
';
- return $text;
- }
- private
- function _strip_bad_multibyte_chars($str)
- {
- $result = '';
- $length = strlen($str);
- for ($i = 0;$i < $length;$i++)
- {
+ if ($query->num_rows() > 0) {
+ foreach ($query->result_array() as $row) {
+ $data['inreply']['title'] = $row['title'];
+ $data['inreply']['name'] = $row['name'];
+ $data['inreply']['url'] = site_url('view/' . $inreply);
+ }
+ } else {
+ $data['inreply'] = false;
+ }
- // Replace four-byte characters (11110www 10zzzzzz 10yyyyyy 10xxxxxx)
- $ord = ord($str[$i]);
-
- if ($ord >= 240 && $ord <= 244)
- {
- $result.= '?';
- $i+= 3;
- }
- else
- {
- $result.= $str[$i];
- }
- }
- return $result;
- }
+ if ($diff) {
+ $this->db->select('raw');
+ $this->db->where('pid', $inreply);
+ $query = $this->db->get('pastes');
+
+ if ($query->num_rows() > 0) {
+ foreach ($query->result_array() as $row) {
+
+ //diff
+ //yes, I'm aware, two times htmlspecialchars_decode(). Needs to be, since it's saved that way in the DB from the original stikked author ages ago ;)
+ include_once APPPATH . '/libraries/finediff.php';
+ $from_text = htmlspecialchars_decode(utf8_decode($row['raw']));
+ $to_text = htmlspecialchars_decode(utf8_decode($data['raw']));
+ $opcodes = FineDiff::getDiffOpcodes($from_text, $to_text, FineDiff::$wordGranularity);
+ $to_text = FineDiff::renderToTextFromOpcodes($from_text, $opcodes);
+ $data['paste'] = htmlspecialchars_decode($this->_format_diff(nl2br(FineDiff::renderDiffToHTMLFromOpcodes($from_text, $opcodes))));
+ }
+ } else {
+ $data['inreply'] = false;
+ }
+ }
+ }
+
+ if ($replies) {
+ $amount = $this->config->item('per_page');
+ $page = ($this->uri->segment(3) ? $this->uri->segment(3) : 0);
+ $this->db->select('title, name, created, pid, lang');
+ $this->db->where('replyto', $data['pid']);
+ $this->db->order_by('id', 'desc');
+ $this->db->limit($amount);
+ $query = $this->db->get('pastes', $amount, $page);
+
+ if ($query->num_rows() > 0) {
+ $n = 0;
+ foreach ($query->result_array() as $row) {
+ $data['replies'][$n]['title'] = $row['title'];
+ $data['replies'][$n]['name'] = $row['name'];
+ $data['replies'][$n]['lang'] = $row['lang'];
+ $data['replies'][$n]['created'] = $row['created'];
+ $data['replies'][$n]['pid'] = $row['pid'];
+ $n++;
+ }
+ $config['base_url'] = site_url('view/' . $data['pid']);
+ $config['total_rows'] = $this->countReplies($data['pid']);
+ $config['per_page'] = $amount;
+ $config['num_links'] = 9;
+ $config['full_tag_open'] = '';
+ $config['full_tag_close'] = '
';
+ $config['uri_segment'] = 3;
+ $this->load->library('pagination');
+ $this->pagination->initialize($config);
+ $data['pages'] = $this->pagination->create_links();
+ } else {
+ $replies = false;
+ }
+ }
+
+ /*
+ * Hits
+ * First check if record already exists. If it does, do not insert.
+ * INSERT IGNORE INTO does not work for postgres.
+ */
+ $this->db->select('count(paste_id) as count');
+ $this->db->where('paste_id', $pid);
+ $this->db->where('ip_address', $this->input->ip_address());
+ $query = $this->db->get('trending');
+ $hits_count = $query->result_array();
+ $hits_count = $hits_count[0]['count'];
+
+ if ($hits_count == 0) {
+ $this->db->insert('trending', array(
+ 'paste_id' => $pid,
+ 'ip_address' => $this->input->ip_address(),
+ 'created' => time(),
+ ));
+ }
+
+ //update hits counter every minute
+ if (time() > (60 + $data['hits_updated'])) {
+ $this->calculate_hits($pid, $data['hits']);
+ }
+
+ //burn if necessary
+ if ($data['expire'] == 0 and $data['toexpire'] == 1) {
+ $this->delete_paste($data['pid']);
+ }
+ return $data;
+ }
+
+ public function calculate_hits($pid, $current_hits)
+ {
+ $this->db->select('count(paste_id) as count');
+ $this->db->where('paste_id', $pid);
+ $query = $this->db->get('trending');
+ $hits_count = $query->result_array();
+ $hits_count = $hits_count[0]['count'];
+
+ if ($hits_count != $current_hits) {
+
+ //update
+ $this->db->where('pid', $pid);
+ $this->db->update('pastes', array(
+ 'hits' => $hits_count,
+ 'hits_updated' => time(),
+ ));
+ }
+ }
+
+ public function getReplies($seg = 3)
+ {
+ $amount = $this->config->item('per_page');
+
+ if ($this->uri->segment($seg) == '') {
+ redirect('');
+ } else {
+ $pid = $this->uri->segment($seg);
+ }
+ $this->db->select('title, name, created, pid, raw, lang');
+ $this->db->where('replyto', $pid);
+ $this->db->order_by('id', 'desc');
+ $this->db->limit($amount);
+ $query = $this->db->get('pastes', $amount);
+
+ if ($query->num_rows() > 0) {
+ $n = 0;
+ foreach ($query->result_array() as $row) {
+ $data['replies'][$n]['title'] = $row['title'];
+ $data['replies'][$n]['name'] = $row['name'];
+ $data['replies'][$n]['lang'] = $row['lang'];
+ $data['replies'][$n]['created'] = $row['created'];
+ $data['replies'][$n]['pid'] = $row['pid'];
+
+ if ($this->uri->segment(2) == 'rss') {
+ $data['replies'][$n]['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']), $row['lang']);
+ $data['replies'][$n]['raw'] = $row['raw'];
+ }
+ $n++;
+ }
+ }
+ return $data;
+ }
+
+ public function getLists($root = 'lists/', $seg = 2)
+ {
+ $this->load->library('pagination');
+ $this->load->library('process');
+ $amount = $this->config->item('per_page');
+ $page = ($this->uri->segment($seg) ? $this->uri->segment($seg) : 0);
+ $search = $this->input->get('search');
+ $TABLE = $this->config->item('db_prefix') . "pastes";
+
+ if ($search) {
+ $search = '%' . $search . '%';
+
+ // count total results
+ $sql = "SELECT id FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?)";
+ $query = $this->db->query($sql, array(
+ $search,
+ $search,
+ ));
+ $total_rows = $query->num_rows();
+
+ // query
+ if ($this->db->dbdriver == "postgre") {
+ $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY created DESC LIMIT $amount OFFSET $page";
+ } else if ($root == 'api/recent') {
+ $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY created DESC LIMIT 0,15";
+ } else {
+ $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY created DESC LIMIT $page,$amount";
+ }
+ $query = $this->db->query($sql, array(
+ $search,
+ $search,
+ ));
+ } else {
+
+ // count total results
+ $sql = "SELECT id FROM $TABLE WHERE private = 0";
+ $query = $this->db->query($sql);
+ $total_rows = $query->num_rows();
+
+ // query
+ if ($this->db->dbdriver == "postgre") {
+ $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 ORDER BY created DESC LIMIT $amount OFFSET $page";
+ } else if ($root == 'api/recent') {
+ $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 ORDER BY created DESC LIMIT 0,15";
+ } else {
+ $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 ORDER BY created DESC LIMIT $page,$amount";
+ }
+ $query = $this->db->query($sql);
+ }
+
+ if ($query->num_rows() > 0) {
+ $n = 0;
+ foreach ($query->result_array() as $row) {
+ $data['pastes'][$n]['id'] = $row['id'];
+ $data['pastes'][$n]['title'] = $row['title'];
+ $data['pastes'][$n]['name'] = $row['name'];
+ $data['pastes'][$n]['created'] = $row['created'];
+ $data['pastes'][$n]['lang'] = $this->languages->code_to_description($row['lang']);
+ $data['pastes'][$n]['pid'] = $row['pid'];
+
+ if ($this->uri->segment(2) == 'rss') {
+ $data['pastes'][$n]['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']), $row['lang']);
+ }
+ $data['pastes'][$n]['raw'] = $row['raw'];
+ $n++;
+ }
+ }
+ $config['base_url'] = site_url($root);
+ $config['total_rows'] = $total_rows;
+ $config['per_page'] = $amount;
+ $config['num_links'] = 9;
+ $config['full_tag_open'] = '';
+ $config['full_tag_close'] = '
';
+ $config['uri_segment'] = $seg;
+ $searchparams = ($this->input->get('search') ? '?search=' . $this->input->get('search') : '');
+ $config['first_url'] = '0' . $searchparams;
+ $config['suffix'] = $searchparams;
+ $this->pagination->initialize($config);
+ $data['pages'] = $this->pagination->create_links();
+ return $data;
+ }
+
+ public function getTrends($root = 'trends/', $seg = 2)
+ {
+ $this->load->library('pagination');
+ $amount = $this->config->item('per_page');
+ $page = ($this->uri->segment(2) ? $this->uri->segment(2) : 0);
+ $search = $this->input->get('search');
+ $TABLE = $this->config->item('db_prefix') . "pastes";
+
+ if ($search) {
+ $search = '%' . $search . '%';
+
+ // count total results
+ $sql = "SELECT id FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?)";
+ $query = $this->db->query($sql, array(
+ $search,
+ $search,
+ ));
+ $total_rows = $query->num_rows();
+
+ // query
+ if ($this->db->dbdriver == "postgre") {
+ $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY hits DESC, created DESC LIMIT $amount OFFSET $page";
+ } else if ($root == "api/trending") {
+ $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY hits DESC, created DESC LIMIT 0,15";
+ } else {
+ $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY hits DESC, created DESC LIMIT $page,$amount";
+ }
+ $query = $this->db->query($sql, array(
+ $search,
+ $search,
+ ));
+ } else {
+
+ // count total results
+ $sql = "SELECT id FROM $TABLE WHERE private = 0";
+ $query = $this->db->query($sql);
+ $total_rows = $query->num_rows();
+
+ // query
+ if ($this->db->dbdriver == "postgre") {
+ $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 ORDER BY hits DESC, created DESC LIMIT $amount OFFSET $page";
+ } else if ($root == "api/trending") {
+ $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 ORDER BY hits DESC, created DESC LIMIT 0,15";
+ } else {
+ $sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM $TABLE WHERE private = 0 ORDER BY hits DESC, created DESC LIMIT $page,$amount";
+ }
+ $query = $this->db->query($sql);
+ }
+
+ if ($query->num_rows() > 0) {
+ $n = 0;
+ foreach ($query->result_array() as $row) {
+ $data['pastes'][$n]['id'] = $row['id'];
+ $data['pastes'][$n]['title'] = $row['title'];
+ $data['pastes'][$n]['name'] = $row['name'];
+ $data['pastes'][$n]['created'] = $row['created'];
+ $data['pastes'][$n]['lang'] = $this->languages->code_to_description($row['lang']);
+ $data['pastes'][$n]['pid'] = $row['pid'];
+ $data['pastes'][$n]['raw'] = $row['raw'];
+ $data['pastes'][$n]['hits'] = $row['hits'];
+ $n++;
+ }
+ }
+ $config['base_url'] = site_url($root);
+ $config['total_rows'] = $total_rows;
+ $config['per_page'] = $amount;
+ $config['num_links'] = 9;
+ $config['full_tag_open'] = '';
+ $config['full_tag_close'] = '
';
+ $config['uri_segment'] = $seg;
+ $searchparams = ($this->input->get('search') ? '?search=' . $this->input->get('search') : '');
+ $config['first_url'] = '0' . $searchparams;
+ $config['suffix'] = $searchparams;
+ $this->pagination->initialize($config);
+ $data['pages'] = $this->pagination->create_links();
+ return $data;
+ }
+
+ public function getSpamLists($root = 'spamadmin/', $seg = 2, $ip_address = false)
+ {
+ $this->load->library('pagination');
+ $this->load->library('process');
+ $amount = $this->config->item('per_page');
+ $page = ($this->uri->segment($seg) ? $this->uri->segment($seg) : 0);
+ $this->db->select('id, title, name, created, pid, lang, ip_address');
+ $this->db->where('private', 0);
+
+ if ($ip_address) {
+ $this->db->where('ip_address', $ip_address);
+ }
+ $this->db->order_by('created', 'desc');
+ $query = $this->db->get('pastes', $amount, $page);
+
+ if ($query->num_rows() > 0) {
+ $n = 0;
+ foreach ($query->result_array() as $row) {
+ $data['pastes'][$n]['id'] = $row['id'];
+ $data['pastes'][$n]['title'] = $row['title'];
+ $data['pastes'][$n]['name'] = $row['name'];
+ $data['pastes'][$n]['created'] = $row['created'];
+ $data['pastes'][$n]['lang'] = $row['lang'];
+ $data['pastes'][$n]['pid'] = $row['pid'];
+ $data['pastes'][$n]['ip_address'] = $row['ip_address'];
+ $n++;
+ }
+ }
+
+ //pagination
+ $config['base_url'] = site_url($root);
+ $config['total_rows'] = $this->countPastes($ip_address);
+ $config['per_page'] = $amount;
+ $config['num_links'] = 9;
+ $config['full_tag_open'] = '';
+ $config['full_tag_close'] = '
';
+ $config['uri_segment'] = $seg;
+ $this->pagination->initialize($config);
+ $data['pages'] = $this->pagination->create_links();
+
+ //total spam attempts
+ $this->db->select('SUM(spam_attempts) as sum');
+ $query = $this->db->get('blocked_ips');
+ $q = $query->result_array();
+ $data['total_spam_attempts'] = ($q[0]['sum'] != '' ? $q[0]['sum'] : 0);
+
+ //return
+ return $data;
+ }
+
+ public function cron()
+ {
+ $now = now();
+ $this->db->select('pid,expire');
+ $this->db->where('toexpire', '1');
+ $query = $this->db->get('pastes');
+ foreach ($query->result_array() as $row) {
+ $stamp = $row['expire'];
+
+ if ($now > $stamp and $stamp != 0) {
+ $this->delete_paste($row['pid']);
+ }
+ }
+ return;
+ }
+
+ public function delete_paste($pid)
+ {
+ $this->db->where('pid', $pid);
+ $this->db->delete('pastes');
+
+ // delete from trending
+ $this->db->where('paste_id', $pid);
+ $this->db->delete('trending');
+ return;
+ }
+
+ public function random_paste()
+ {
+ $this->load->library('process');
+ $this->db->order_by('id', 'RANDOM');
+ $this->db->limit(1);
+ $this->db->where('private', '0');
+ $query = $this->db->get('pastes');
+
+ if ($query->num_rows() > 0) {
+ foreach ($query->result_array() as $row) {
+ $data['title'] = $row['title'];
+ $data['pid'] = $row['pid'];
+ $data['name'] = $row['name'];
+ $data['lang_code'] = $row['lang'];
+ $data['lang'] = $this->languages->code_to_description($row['lang']);
+ $data['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']), $row['lang']);
+ $data['created'] = $row['created'];
+ $data['url'] = $this->_get_url($row['pid']);
+ $data['raw'] = $row['raw'];
+ $data['hits'] = $row['hits'];
+ $data['hits_updated'] = $row['hits_updated'];
+ $data['snipurl'] = $row['snipurl'];
+ $inreply = $row['replyto'];
+ }
+
+ if ($inreply) {
+ $this->db->select('name, title');
+ $this->db->where('pid', $inreply);
+ $query = $this->db->get('pastes');
+
+ if ($query->num_rows() > 0) {
+ foreach ($query->result_array() as $row) {
+ $data['inreply']['title'] = $row['title'];
+ $data['inreply']['name'] = $row['name'];
+ $data['inreply']['url'] = site_url('view/' . $inreply);
+ }
+ } else {
+ $data['inreply'] = false;
+ }
+ }
+ return $data;
+ }
+ return false;
+ }
+
+ private function _format_diff($text)
+ {
+ $text = str_replace("\t", ' ', $text);
+ $text = str_replace("
", '
', $text);
+ $text = str_replace(" ", ' ', $text);
+ $text = '' . $text . '
';
+ return $text;
+ }
+
+ private function _strip_bad_multibyte_chars($str)
+ {
+ $result = '';
+ $length = strlen($str);
+ for ($i = 0; $i < $length; $i++) {
+
+ // Replace four-byte characters (11110www 10zzzzzz 10yyyyyy 10xxxxxx)
+ $ord = ord($str[$i]);
+
+ if ($ord >= 240 && $ord <= 244) {
+ $result .= '?';
+ $i += 3;
+ } else {
+ $result .= $str[$i];
+ }
+ }
+ return $result;
+ }
}
diff --git a/htdocs/index.php b/htdocs/index.php
index 3e75f0a..924d557 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -26,13 +26,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
- * @package CodeIgniter
- * @author EllisLab Dev Team
- * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
- * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
- * @license http://opensource.org/licenses/MIT MIT License
- * @link https://codeigniter.com
- * @since Version 1.0.0
+ * @package CodeIgniter
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
+ * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
+ * @license http://opensource.org/licenses/MIT MIT License
+ * @link https://codeigniter.com
+ * @since Version 1.0.0
* @filesource
*/
@@ -53,7 +53,7 @@
*
* NOTE: If you change these, also change the error_reporting() code below
*/
- define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
+define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
/*
*---------------------------------------------------------------
@@ -63,30 +63,26 @@
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.
*/
-switch (ENVIRONMENT)
-{
- case 'development':
- error_reporting(-1);
- ini_set('display_errors', 1);
- break;
+switch (ENVIRONMENT) {
+ case 'development':
+ error_reporting(-1);
+ ini_set('display_errors', 1);
+ break;
- case 'testing':
- case 'production':
- ini_set('display_errors', 0);
- if (version_compare(PHP_VERSION, '5.3', '>='))
- {
- error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
- }
- else
- {
- error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
- }
- break;
+ case 'testing':
+ case 'production':
+ ini_set('display_errors', 0);
+ if (version_compare(PHP_VERSION, '5.3', '>=')) {
+ error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
+ } else {
+ error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
+ }
+ break;
- default:
- header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
- echo 'The application environment is not set correctly.';
- exit(1); // EXIT_ERROR
+ default:
+ header('HTTP/1.1 503 Service Unavailable.', true, 503);
+ echo 'The application environment is not set correctly.';
+ exit(1); // EXIT_ERROR
}
/*
@@ -97,7 +93,7 @@ switch (ENVIRONMENT)
* This variable must contain the name of your "system" directory.
* Set the path if it is not in the same directory as this file.
*/
- $system_path = 'system';
+$system_path = 'system';
/*
*---------------------------------------------------------------
@@ -114,7 +110,7 @@ switch (ENVIRONMENT)
*
* NO TRAILING SLASH!
*/
- $application_folder = 'application';
+$application_folder = 'application';
/*
*---------------------------------------------------------------
@@ -129,8 +125,7 @@ switch (ENVIRONMENT)
*
* NO TRAILING SLASH!
*/
- $view_folder = 'themes/default/views';
-
+$view_folder = 'themes/default/views';
/*
* --------------------------------------------------------------------
@@ -151,16 +146,15 @@ switch (ENVIRONMENT)
*
* Un-comment the $routing array below to use this feature
*/
- // The directory name, relative to the "controllers" directory. Leave blank
- // if your controller is not in a sub-directory within the "controllers" one
- // $routing['directory'] = '';
+// The directory name, relative to the "controllers" directory. Leave blank
+// if your controller is not in a sub-directory within the "controllers" one
+// $routing['directory'] = '';
- // The controller class file name. Example: mycontroller
- // $routing['controller'] = '';
-
- // The controller function you wish to be called.
- // $routing['function'] = '';
+// The controller class file name. Example: mycontroller
+// $routing['controller'] = '';
+// The controller function you wish to be called.
+// $routing['function'] = '';
/*
* -------------------------------------------------------------------
@@ -176,9 +170,7 @@ switch (ENVIRONMENT)
*
* Un-comment the $assign_to_config array below to use this feature
*/
- // $assign_to_config['name_of_config_item'] = 'value of config item';
-
-
+// $assign_to_config['name_of_config_item'] = 'value of config item';
// --------------------------------------------------------------------
// END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE
@@ -190,120 +182,97 @@ switch (ENVIRONMENT)
* ---------------------------------------------------------------
*/
- // Set the current directory correctly for CLI requests
- if (defined('STDIN'))
- {
- chdir(dirname(__FILE__));
- }
+// Set the current directory correctly for CLI requests
+if (defined('STDIN')) {
+ chdir(dirname(__FILE__));
+}
- if (($_temp = realpath($system_path)) !== FALSE)
- {
- $system_path = $_temp.DIRECTORY_SEPARATOR;
- }
- else
- {
- // Ensure there's a trailing slash
- $system_path = strtr(
- rtrim($system_path, '/\\'),
- '/\\',
- DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
- ).DIRECTORY_SEPARATOR;
- }
+if (($_temp = realpath($system_path)) !== false) {
+ $system_path = $_temp . DIRECTORY_SEPARATOR;
+} else {
+ // Ensure there's a trailing slash
+ $system_path = strtr(
+ rtrim($system_path, '/\\'),
+ '/\\',
+ DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
+ ) . DIRECTORY_SEPARATOR;
+}
- // Is the system path correct?
- if ( ! is_dir($system_path))
- {
- header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
- echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME);
- exit(3); // EXIT_CONFIG
- }
+// Is the system path correct?
+if (!is_dir($system_path)) {
+ header('HTTP/1.1 503 Service Unavailable.', true, 503);
+ echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: ' . pathinfo(__FILE__, PATHINFO_BASENAME);
+ exit(3); // EXIT_CONFIG
+}
/*
* -------------------------------------------------------------------
* Now that we know the path, set the main path constants
* -------------------------------------------------------------------
*/
- // The name of THIS file
- define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
+// The name of THIS file
+define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
- // Path to the system directory
- define('BASEPATH', $system_path);
+// Path to the system directory
+define('BASEPATH', $system_path);
- // Path to the front controller (this file) directory
- define('FCPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
+// Path to the front controller (this file) directory
+define('FCPATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
- // Name of the "system" directory
- define('SYSDIR', basename(BASEPATH));
+// Name of the "system" directory
+define('SYSDIR', basename(BASEPATH));
- // The path to the "application" directory
- if (is_dir($application_folder))
- {
- if (($_temp = realpath($application_folder)) !== FALSE)
- {
- $application_folder = $_temp;
- }
- else
- {
- $application_folder = strtr(
- rtrim($application_folder, '/\\'),
- '/\\',
- DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
- );
- }
- }
- elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR))
- {
- $application_folder = BASEPATH.strtr(
- trim($application_folder, '/\\'),
- '/\\',
- DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
- );
- }
- else
- {
- header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
- echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
- exit(3); // EXIT_CONFIG
- }
+// The path to the "application" directory
+if (is_dir($application_folder)) {
+ if (($_temp = realpath($application_folder)) !== false) {
+ $application_folder = $_temp;
+ } else {
+ $application_folder = strtr(
+ rtrim($application_folder, '/\\'),
+ '/\\',
+ DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
+ );
+ }
+} elseif (is_dir(BASEPATH . $application_folder . DIRECTORY_SEPARATOR)) {
+ $application_folder = BASEPATH . strtr(
+ trim($application_folder, '/\\'),
+ '/\\',
+ DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
+ );
+} else {
+ header('HTTP/1.1 503 Service Unavailable.', true, 503);
+ echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF;
+ exit(3); // EXIT_CONFIG
+}
- define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);
+define('APPPATH', $application_folder . DIRECTORY_SEPARATOR);
- // The path to the "views" directory
- if ( ! isset($view_folder[0]) && is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR))
- {
- $view_folder = APPPATH.'views';
- }
- elseif (is_dir($view_folder))
- {
- if (($_temp = realpath($view_folder)) !== FALSE)
- {
- $view_folder = $_temp;
- }
- else
- {
- $view_folder = strtr(
- rtrim($view_folder, '/\\'),
- '/\\',
- DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
- );
- }
- }
- elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR))
- {
- $view_folder = APPPATH.strtr(
- trim($view_folder, '/\\'),
- '/\\',
- DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
- );
- }
- else
- {
- header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
- echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
- exit(3); // EXIT_CONFIG
- }
+// The path to the "views" directory
+if (!isset($view_folder[0]) && is_dir(APPPATH . 'views' . DIRECTORY_SEPARATOR)) {
+ $view_folder = APPPATH . 'views';
+} elseif (is_dir($view_folder)) {
+ if (($_temp = realpath($view_folder)) !== false) {
+ $view_folder = $_temp;
+ } else {
+ $view_folder = strtr(
+ rtrim($view_folder, '/\\'),
+ '/\\',
+ DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
+ );
+ }
+} elseif (is_dir(APPPATH . $view_folder . DIRECTORY_SEPARATOR)) {
+ $view_folder = APPPATH . strtr(
+ trim($view_folder, '/\\'),
+ '/\\',
+ DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR
+ );
+} else {
+ header('HTTP/1.1 503 Service Unavailable.', true, 503);
+ echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: ' . SELF;
+ exit(3); // EXIT_CONFIG
+}
- define('VIEWPATH', $view_folder.DIRECTORY_SEPARATOR);
+define('VIEWPATH', $view_folder . DIRECTORY_SEPARATOR);
/*
* --------------------------------------------------------------------
@@ -312,4 +281,4 @@ switch (ENVIRONMENT)
*
* And away we go...
*/
-require_once BASEPATH.'core/CodeIgniter.php';
+require_once BASEPATH . 'core/CodeIgniter.php';