trending copied from lists

This commit is contained in:
Claude 2012-10-10 11:21:44 +02:00
parent ff28a0e7e0
commit 23c239d045
4 changed files with 64 additions and 1 deletions

View File

@ -52,6 +52,8 @@ $route['view/:any'] = 'main/view';
$route['lists'] = 'main/lists';
$route['lists/rss'] = 'main/lists/rss';
$route['lists/:num'] = 'main/lists/$1';
$route['trends'] = 'main/trends';
$route['trends/:any'] = 'main/trends/$1';
$route['spamadmin/:num'] = 'spamadmin/index';
$route['spamadmin/blacklist/unblock/(:any)'] = 'spamadmin/unblock_ip';
$route['spamadmin/blacklist/(:num)'] = 'spamadmin/blacklist';

View File

@ -10,6 +10,7 @@
* - embed()
* - download()
* - lists()
* - trends()
* - view()
* - cron()
* - about()
@ -470,6 +471,22 @@ class Main extends CI_Controller
}
}
function trends()
{
$this->_valid_authentication();
if ($this->config->item('private_only'))
{
show_404();
}
else
{
$this->load->model('pastes');
$data = $this->pastes->getTrends();
$this->load->view('list', $data);
}
}
function view()
{
$this->_valid_authentication();

View File

@ -333,6 +333,49 @@ class Pastes extends CI_Model
return $data;
}
function getTrends($root = 'lists/', $seg = 2)
{
$this->load->library('pagination');
$this->load->library('process');
$amount = $this->config->item('per_page');
$page = ($this->uri->segment(2) ? $this->uri->segment(2) : 0);
$this->db->select('id, title, name, created, pid, lang, raw');
$this->db->where('private', 0);
$this->db->order_by('created', 'desc');
$query = $this->db->get('pastes', $amount, $page);
if ($query->num_rows() > 0)
{
$n = 0;
foreach ($query->result_array() as $row)
{
$data['pastes'][$n]['id'] = $row['id'];
$data['pastes'][$n]['title'] = $row['title'];
$data['pastes'][$n]['name'] = $row['name'];
$data['pastes'][$n]['created'] = $row['created'];
$data['pastes'][$n]['lang'] = $row['lang'];
$data['pastes'][$n]['pid'] = $row['pid'];
if ($this->uri->segment(2) == 'rss')
{
$data['pastes'][$n]['paste'] = $this->process->syntax(htmlspecialchars_decode($row['raw']) , $row['lang']);
}
$data['pastes'][$n]['raw'] = $row['raw'];
$n++;
}
}
$config['base_url'] = site_url($root);
$config['total_rows'] = $this->countPastes();
$config['per_page'] = $amount;
$config['num_links'] = 9;
$config['full_tag_open'] = '<div class="pages">';
$config['full_tag_close'] = '</div>';
$config['uri_segment'] = $seg;
$this->pagination->initialize($config);
$data['pages'] = $this->pagination->create_links();
return $data;
}
function getSpamLists($root = 'spamadmin/', $seg = 2, $ip_address = false)
{
$this->load->library('pagination');

View File

@ -50,6 +50,7 @@ $this->carabiner->display('css');
<li><a <?php if($l == ""){ echo 'class="active"'; }?> href="<?php echo base_url()?>" title="Create A New Paste">Create</a></li>
<?php if(! $this->config->item('private_only')){ ?>
<li><a <?php if($l == "lists" || $l == "view" and $this->uri->segment(2) != "options"){ echo 'class="active"'; }?> href="<?php echo site_url('lists'); ?>" title="Recent Pastes">Recent</a></li>
<li><a <?php if($l == "trends" || $l == "view" and $this->uri->segment(2) != "options"){ echo 'class="active"'; }?> href="<?php echo site_url('trends'); ?>" title="Trending Pastes">Trending</a></li>
<?php } ?>
<li><a <?php if($l == "api"){ echo 'class="active"'; }?> href="<?php echo site_url('api'); ?>" title="API">API</a></li>
<li><a <?php if($l == "about"){ echo 'class="active"'; }?> href="<?php echo site_url('about'); ?>" title="About">About</a></li>