Fix #235, db_prefix causes Recent and Trending to break

This commit is contained in:
Franklyn Tackitt 2015-08-10 10:55:27 -07:00
parent eca80707d8
commit 40a22a4686
4 changed files with 28 additions and 17 deletions

View File

@ -32,3 +32,4 @@
* kiang https://github.com/kiang (Chinese-Traditional translation)
* Abbas A. Elmas https://github.com/abbaselmas (Intense testing and making valuable suggestions)
* 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
---------
### 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:
* New translations: Japanese, Chinese-Simplified, Chinese-Traditional, Russian

View File

@ -24,7 +24,7 @@ $config['base_url'] = '';
| 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');
$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 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(
$search,
$search,
@ -473,16 +474,16 @@ class Pastes extends CI_Model
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
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
{
$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(
$search,
@ -493,7 +494,7 @@ class Pastes extends CI_Model
{
// count total results
$sql = "SELECT id FROM pastes WHERE private = 0";
$sql = "SELECT id FROM $TABLE WHERE private = 0";
$query = $this->db->query($sql);
$total_rows = $query->num_rows();
@ -501,11 +502,11 @@ class Pastes extends CI_Model
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
{
$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);
}
@ -551,13 +552,14 @@ class Pastes extends CI_Model
$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 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(
$search,
$search,
@ -568,16 +570,16 @@ class Pastes extends CI_Model
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
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
{
$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(
$search,
@ -588,7 +590,7 @@ class Pastes extends CI_Model
{
// count total results
$sql = "SELECT id FROM pastes WHERE private = 0";
$sql = "SELECT id FROM $TABLE WHERE private = 0";
$query = $this->db->query($sql);
$total_rows = $query->num_rows();
@ -596,11 +598,11 @@ class Pastes extends CI_Model
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
{
$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);
}