From 054180f69a1629e95312f610f59aefc6141dbab8 Mon Sep 17 00:00:00 2001 From: Team BlueRidge Date: Thu, 1 Oct 2015 11:28:05 -0400 Subject: [PATCH] Properly fix 'trending' and 'recent' API bugs Prior fixes either didn't fix these API points or broke the normal lists. This fix adds check to make sure we're in the right place and then does a specifc sql query for the API. We should be good now. --- htdocs/application/models/Pastes.php | 15 ++++++++++++--- htdocs/index.php | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/htdocs/application/models/Pastes.php b/htdocs/application/models/Pastes.php index 46c88d8..f941606 100644 --- a/htdocs/application/models/Pastes.php +++ b/htdocs/application/models/Pastes.php @@ -678,13 +678,12 @@ class Pastes extends CI_Model $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') + 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"; } @@ -711,6 +710,11 @@ class Pastes extends CI_Model { $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"; @@ -807,6 +811,11 @@ class Pastes extends CI_Model { $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"; diff --git a/htdocs/index.php b/htdocs/index.php index d27278b..85f0567 100755 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -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'] : 'production'); /* *---------------------------------------------------------------