Merge pull request #288 from kageurufu/master

Fix #235, db_prefix causes Recent and Trending to break
This commit is contained in:
Claude 2015-08-12 16:08:42 +02:00
commit d917452cbd
4 changed files with 28 additions and 17 deletions

View File

@ -32,3 +32,4 @@
* kiang https://github.com/kiang (Chinese-Traditional translation) * kiang https://github.com/kiang (Chinese-Traditional translation)
* Abbas A. Elmas https://github.com/abbaselmas (Intense testing and making valuable suggestions) * Abbas A. Elmas https://github.com/abbaselmas (Intense testing and making valuable suggestions)
* Sebastian Korotkiewicz http://git.itunix.eu/git/cleanwhite.git/ (CleanWhite theme) * Sebastian Korotkiewicz http://git.itunix.eu/git/cleanwhite.git/ (CleanWhite theme)
* Franklyn Tackitt https://github.com/kageurufu (Fixed bug with db_prefix config value)

View File

@ -60,6 +60,14 @@ In the folder doc/, you will find:
Changelog Changelog
--------- ---------
### Version 0.9.1:
* Fixed bug with db_prefix config value
#### Upgrade instructions
Copy your htdocs/application/stikked.php config file away. Upload the new version. Copy it back.
### Version 0.9.0: ### Version 0.9.0:
* New translations: Japanese, Chinese-Simplified, Chinese-Traditional, Russian * New translations: Japanese, Chinese-Simplified, Chinese-Traditional, Russian

View File

@ -24,7 +24,7 @@ $config['base_url'] = '';
| So that we can track your version. | So that we can track your version.
| |
*/ */
$config['stikked_version'] = '0.9.0'; $config['stikked_version'] = '0.9.1';
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -456,13 +456,14 @@ class Pastes extends CI_Model
$amount = $this->config->item('per_page'); $amount = $this->config->item('per_page');
$page = ($this->uri->segment($seg) ? $this->uri->segment($seg) : 0); $page = ($this->uri->segment($seg) ? $this->uri->segment($seg) : 0);
$search = $this->input->get('search'); $search = $this->input->get('search');
$TABLE = $this->config->item('db_prefix') . "pastes";
if ($search) if ($search)
{ {
$search = '%' . $search . '%'; $search = '%' . $search . '%';
// count total results // count total results
$sql = "SELECT id FROM pastes WHERE private = 0 AND (title LIKE ? OR raw LIKE ?)"; $sql = "SELECT id FROM ${this->config->item("db_prefix")}pastes WHERE private = 0 AND (title LIKE ? OR raw LIKE ?)";
$query = $this->db->query($sql, array( $query = $this->db->query($sql, array(
$search, $search,
$search, $search,
@ -473,16 +474,16 @@ class Pastes extends CI_Model
if ($this->db->dbdriver == "postgre") if ($this->db->dbdriver == "postgre")
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw FROM pastes WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY created DESC LIMIT $amount OFFSET $page"; $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 else
if ($root == 'api/recent') if ($root == 'api/recent')
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw FROM pastes WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY created DESC LIMIT 0,15"; $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 else
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw FROM pastes WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY created DESC LIMIT $page,$amount"; $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( $query = $this->db->query($sql, array(
$search, $search,
@ -493,7 +494,7 @@ class Pastes extends CI_Model
{ {
// count total results // count total results
$sql = "SELECT id FROM pastes WHERE private = 0"; $sql = "SELECT id FROM $TABLE WHERE private = 0";
$query = $this->db->query($sql); $query = $this->db->query($sql);
$total_rows = $query->num_rows(); $total_rows = $query->num_rows();
@ -501,11 +502,11 @@ class Pastes extends CI_Model
if ($this->db->dbdriver == "postgre") if ($this->db->dbdriver == "postgre")
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw FROM pastes WHERE private = 0 ORDER BY created DESC LIMIT $amount OFFSET $page"; $sql = "SELECT id, title, name, created, pid, lang, raw FROM $TABLE WHERE private = 0 ORDER BY created DESC LIMIT $amount OFFSET $page";
} }
else else
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw FROM pastes WHERE private = 0 ORDER BY created DESC LIMIT $page,$amount"; $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); $query = $this->db->query($sql);
} }
@ -551,13 +552,14 @@ class Pastes extends CI_Model
$amount = $this->config->item('per_page'); $amount = $this->config->item('per_page');
$page = ($this->uri->segment(2) ? $this->uri->segment(2) : 0); $page = ($this->uri->segment(2) ? $this->uri->segment(2) : 0);
$search = $this->input->get('search'); $search = $this->input->get('search');
$TABLE = $this->config->item('db_prefix') . "pastes";
if ($search) if ($search)
{ {
$search = '%' . $search . '%'; $search = '%' . $search . '%';
// count total results // count total results
$sql = "SELECT id FROM pastes WHERE private = 0 AND (title LIKE ? OR raw LIKE ?)"; $sql = "SELECT id FROM $TABLE WHERE private = 0 AND (title LIKE ? OR raw LIKE ?)";
$query = $this->db->query($sql, array( $query = $this->db->query($sql, array(
$search, $search,
$search, $search,
@ -568,16 +570,16 @@ class Pastes extends CI_Model
if ($this->db->dbdriver == "postgre") if ($this->db->dbdriver == "postgre")
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM pastes WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY hits DESC, created DESC LIMIT $amount OFFSET $page"; $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 else
if ($root == "api/trending") if ($root == "api/trending")
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM pastes WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY hits DESC, created DESC LIMIT 0,15"; $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 else
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM pastes WHERE private = 0 AND (title LIKE ? OR raw LIKE ?) ORDER BY hits DESC, created DESC LIMIT $page,$amount"; $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( $query = $this->db->query($sql, array(
$search, $search,
@ -588,7 +590,7 @@ class Pastes extends CI_Model
{ {
// count total results // count total results
$sql = "SELECT id FROM pastes WHERE private = 0"; $sql = "SELECT id FROM $TABLE WHERE private = 0";
$query = $this->db->query($sql); $query = $this->db->query($sql);
$total_rows = $query->num_rows(); $total_rows = $query->num_rows();
@ -596,11 +598,11 @@ class Pastes extends CI_Model
if ($this->db->dbdriver == "postgre") if ($this->db->dbdriver == "postgre")
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM pastes WHERE private = 0 ORDER BY hits DESC, created DESC LIMIT $amount OFFSET $page"; $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 else
{ {
$sql = "SELECT id, title, name, created, pid, lang, raw, hits FROM pastes WHERE private = 0 ORDER BY hits DESC, created DESC LIMIT $page,$amount"; $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); $query = $this->db->query($sql);
} }