1
0
Fork 0
NCA-Screens/application/controllers/view.php

70 lines
1.7 KiB
PHP
Raw Normal View History

2011-11-05 14:55:02 -04:00
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class View extends CI_Controller {
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() {
}
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();
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);
$display_views = $upload->views;
2011-11-05 14:55:02 -04:00
$this->load->model('viewer');
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;
$this->data['height'] = $upload->height;
$this->data['width'] = $upload->width;
$this->data['size'] = $upload->size;
2011-11-05 14:55:02 -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);
redirect($id);
2011-11-06 01:02:32 -04:00
}
public function latest() {
$this->load->model('fileupload');
$total_uploads = $this->fileupload->count_uploads();
redirect($total_uploads);
}
2011-11-05 14:55:02 -04:00
}