From 40a22a46868a1c29b003b0e03c5fa8c7d234579b Mon Sep 17 00:00:00 2001 From: Franklyn Tackitt Date: Mon, 10 Aug 2015 10:55:27 -0700 Subject: [PATCH] Fix #235, db_prefix causes Recent and Trending to break --- AUTHORS.md | 1 + README.md | 8 +++++++ htdocs/application/config/config.php | 2 +- htdocs/application/models/pastes.php | 34 +++++++++++++++------------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index c5999e9..241672f 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -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) diff --git a/README.md b/README.md index 7aecad9..fa62bd9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/htdocs/application/config/config.php b/htdocs/application/config/config.php index 92208d6..e070c74 100644 --- a/htdocs/application/config/config.php +++ b/htdocs/application/config/config.php @@ -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'; /* |-------------------------------------------------------------------------- diff --git a/htdocs/application/models/pastes.php b/htdocs/application/models/pastes.php index 53c5992..8f4762d 100644 --- a/htdocs/application/models/pastes.php +++ b/htdocs/application/models/pastes.php @@ -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); }