simplifying

This commit is contained in:
Claude 2012-11-24 11:20:23 +01:00
parent 50c7ab7e80
commit 2033d4fe74
3 changed files with 21 additions and 24 deletions

View File

@ -56,12 +56,8 @@ $route['trends'] = 'main/trends';
$route['trends/:any'] = 'main/trends/$1'; $route['trends/:any'] = 'main/trends/$1';
$route['spamadmin/:num'] = 'spamadmin/index'; $route['spamadmin/:num'] = 'spamadmin/index';
$route['spamadmin/blacklist/unblock/(:any)'] = 'spamadmin/unblock_ip'; $route['spamadmin/blacklist/unblock/(:any)'] = 'spamadmin/unblock_ip';
$route['spamadmin/blacklist/(:num)'] = 'spamadmin/blacklist';
$route['spamadmin/blacklist'] = 'spamadmin/blacklist';
$route['spamadmin/:any'] = 'spamadmin/spam_detail'; $route['spamadmin/:any'] = 'spamadmin/spam_detail';
$route['about'] = 'main/about'; $route['about'] = 'main/about';
$route['api/paste/:any'] = 'api/paste';
$route['api/random'] = 'api/random_paste';
$route['iphone/:num'] = 'iphone'; $route['iphone/:num'] = 'iphone';
$route['iphone/view/:any'] = 'iphone/view'; $route['iphone/view/:any'] = 'iphone/view';

View File

@ -5,6 +5,8 @@
* - __construct() * - __construct()
* - index() * - index()
* - create() * - create()
* - paste()
* - random()
* Classes list: * Classes list:
* - Api extends Main * - Api extends Main
*/ */
@ -54,13 +56,13 @@ class Api extends Main
$this->load->view('view/api', $data); $this->load->view('view/api', $data);
} }
} }
function paste() function paste()
{ {
$this->load->model('pastes'); $this->load->model('pastes');
$check = $this->pastes->checkPaste(3); $check = $this->pastes->checkPaste(3);
if ($check) if ($check)
{ {
$data = $this->pastes->getPaste(3); $data = $this->pastes->getPaste(3);
} }
@ -72,13 +74,13 @@ class Api extends Main
} }
echo stripslashes(json_encode($data)); echo stripslashes(json_encode($data));
} }
function random_paste() function random()
{ {
$this->load->model('pastes'); $this->load->model('pastes');
$data = $this->pastes->random_paste(); $data = $this->pastes->random_paste();
if (!$data) if (!$data)
{ {
$data = array( $data = array(
'message' => 'Please try again', 'message' => 'Please try again',

View File

@ -15,6 +15,7 @@
* - getTrends() * - getTrends()
* - getSpamLists() * - getSpamLists()
* - cron() * - cron()
* - random_paste()
* Classes list: * Classes list:
* - Pastes extends CI_Model * - Pastes extends CI_Model
*/ */
@ -488,18 +489,17 @@ class Pastes extends CI_Model
} }
return; return;
} }
function random_paste() function random_paste()
{ {
$this->load->library('process'); $this->load->library('process');
$paste_id = rand(1, $this->countPastes()); $paste_id = rand(1, $this->countPastes());
$this->db->where('id', $paste_id); $this->db->where('id', $paste_id);
$query = $this->db->get('pastes'); $query = $this->db->get('pastes');
if ($query->num_rows() > 0) if ($query->num_rows() > 0)
{ {
foreach ($query->result_array() as $row) foreach ($query->result_array() as $row)
{ {
$data['title'] = $row['title']; $data['title'] = $row['title'];
$data['pid'] = $row['pid']; $data['pid'] = $row['pid'];
@ -515,16 +515,16 @@ class Pastes extends CI_Model
$data['snipurl'] = $row['snipurl']; $data['snipurl'] = $row['snipurl'];
$inreply = $row['replyto']; $inreply = $row['replyto'];
} }
if ($inreply) if ($inreply)
{ {
$this->db->select('name, title'); $this->db->select('name, title');
$this->db->where('pid', $inreply); $this->db->where('pid', $inreply);
$query = $this->db->get('pastes'); $query = $this->db->get('pastes');
if ($query->num_rows() > 0) if ($query->num_rows() > 0)
{ {
foreach ($query->result_array() as $row) foreach ($query->result_array() as $row)
{ {
$data['inreply']['title'] = $row['title']; $data['inreply']['title'] = $row['title'];
$data['inreply']['name'] = $row['name']; $data['inreply']['name'] = $row['name'];
@ -538,7 +538,6 @@ class Pastes extends CI_Model
} }
return $data; return $data;
} }
return false; return false;
} }
} }