2011-11-05 14:55:02 -04:00
|
|
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class View extends CI_Controller {
|
2011-11-05 16:10:30 -04:00
|
|
|
function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
$this->load->model('viewer');
|
|
|
|
$this->viewer->clean_viewers(5 * 60);
|
|
|
|
}
|
|
|
|
|
2011-11-05 14:55:02 -04:00
|
|
|
public function index() {
|
2011-11-05 15:49:55 -04:00
|
|
|
|
|
|
|
}
|
2011-11-05 16:10:30 -04:00
|
|
|
|
2011-11-05 15:49:55 -04:00
|
|
|
public function specific() {
|
2011-11-05 14:55:02 -04:00
|
|
|
$this->load->model('fileupload');
|
|
|
|
|
|
|
|
$id = $this->uri->segment($this->uri->total_segments());
|
|
|
|
$total_uploads = $this->fileupload->count_uploads();
|
|
|
|
|
2011-11-07 22:16:31 -05:00
|
|
|
if($id == 'latest') {
|
|
|
|
$id = $total_uploads;
|
|
|
|
} elseif($id == 'random') {
|
|
|
|
$id = rand(1,$total_uploads);
|
|
|
|
} elseif($id == false || !is_numeric($id) || $id < 0 || $id > $total_uploads) {
|
|
|
|
exit('bad id' . $id);
|
2011-11-05 14:55:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$upload = $this->fileupload->get_upload($id);
|
|
|
|
|
2011-11-05 15:49:55 -04:00
|
|
|
$display_views = $upload->views;
|
|
|
|
|
2011-11-05 14:55:02 -04:00
|
|
|
$this->load->model('viewer');
|
2011-11-05 15:49:55 -04:00
|
|
|
if($this->viewer->add_viewer($_SERVER['REMOTE_ADDR'], $id)) {
|
|
|
|
$this->fileupload->add_view($id);
|
|
|
|
$display_views++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->data['prev'] = $id - 1;
|
|
|
|
$this->data['next'] = ($id + 1 <= $total_uploads) ? $id + 1 : 0;
|
|
|
|
|
|
|
|
$this->data['image'] = $id . $upload->extension;
|
|
|
|
|
|
|
|
$this->data['original'] = $upload->original_name;
|
|
|
|
$this->data['views'] = $display_views;
|
|
|
|
$this->data['created'] = $upload->created;
|
2011-11-05 14:55:02 -04:00
|
|
|
|
2011-11-05 15:49:55 -04:00
|
|
|
$this->template->load('template', 'view', $this->data);
|
2011-11-05 14:55:02 -04:00
|
|
|
}
|
2011-11-06 01:02:32 -04:00
|
|
|
|
|
|
|
public function random() {
|
|
|
|
$this->load->model('fileupload');
|
|
|
|
$total_uploads = $this->fileupload->count_uploads();
|
|
|
|
|
|
|
|
$id = rand(1,$total_uploads);
|
|
|
|
|
2011-11-08 14:41:16 -05:00
|
|
|
redirect($id);
|
2011-11-06 01:02:32 -04:00
|
|
|
}
|
2011-11-06 01:05:36 -04:00
|
|
|
|
|
|
|
public function latest() {
|
|
|
|
$this->load->model('fileupload');
|
|
|
|
$total_uploads = $this->fileupload->count_uploads();
|
|
|
|
|
2011-11-08 14:41:16 -05:00
|
|
|
redirect($total_uploads);
|
2011-11-06 01:05:36 -04:00
|
|
|
}
|
2011-11-05 14:55:02 -04:00
|
|
|
}
|