Файл: adultscript-2.0.3-pro/files/modules/photo/photo.php
Строк: 99
<?php
defined('_VALID') or die('Restricted Access!');
class VModule_photo
{
protected $db;
protected $cache;
protected $tpl;
public function __construct()
{
$this->db = VF::factory('database');
$this->cache = VF::factory('cache');
$this->tpl = VF::factory('template');
}
public function render()
{
if (!VModule::enabled('photo')) {
VModule::load('404', TRUE);
}
$component = VUri::request(1);
$components = array('tag' => 1, 'rss' => 1, 'search' => 1, 'upload' => 1, 'edit' => 1, 'add' => 1);
$orders = array('recent' => 1, 'popular' => 1, 'rated' => 1, 'discussed' => 1, 'favorited' => 1);
if ($component == '') {
$component = (VCfg::get('photo.browse_type') == 'albums') ? 'albums' : 'photos';
} elseif (!isset($components[$component])) {
if (is_numeric($component)) {
if (VUri::request(2) != '') {
if (VUri::request(3) != '' && VUri::request(3) == 'slideshow') {
$component = 'slideshow';
} else {
$component = 'album';
}
} else {
$component = 'photo';
}
} else {
if (isset($orders[$component])) {
$component = (VCfg::get('photo.browse_type') == 'albums') ? 'albums' : 'photos';
} else {
$component = 'category';
}
}
}
$component_class = 'VComponent_photo_'.$component;
try {
require MODULES_DIR.'/photo/components/'.$component.'.php';
$obj = new $component_class();
$obj->render();
} catch (Exception $e) {
throw new VException($e);
}
}
protected function get_photo_categories()
{
if (!$categories = $this->cache->get('photo_categories', 86400)) {
$this->db->query('SELECT cat_id, name, slug, description, total_albums FROM #__photo_categories ORDER BY name ASC');
if ($this->db->affected_rows()) {
$categories = $this->db->fetch_rows();
$this->cache->store('photo_categories', $categories, 86400);
}
}
return ($categories) ? $categories : array();
}
protected function get_query($slug=FALSE, $start=0)
{
$options = array(
'slug' => '',
'order' => 'recent',
'timeline' => NULL,
'page' => 1
);
$orders = array('recent' => 1, 'popular' => 1, 'rated' => 1, 'discussed' => 1, 'favorited' => 1);
$timelines = array('today' => 1, 'yesterday' => 1, 'week' => 1, 'month' => 1, 'year' => 1);
$query = VUri::query();
if ($start !== 0) {
$query = array_slice($query, $start);
}
if ($slug !== FALSE) {
if (isset($query['0']) && $query['0'] != '') {
if (!isset($orders[$query['0']])) {
$options['slug'] = $query['0'];
array_shift($query);
}
}
}
$arg = (isset($query['0']) && $query['0'] != '') ? $query['0'] : NULL;
if (isset($arg)) {
if (isset($orders[$arg])) {
$options['order'] = $arg;
$type = $orders[$arg];
array_shift($query);
} else {
VModule::load('404', TRUE);
}
}
$arg = (isset($query['0']) && $query['0'] != '') ? $query['0'] : NULL;
if (isset($arg)) {
if ($type === 2) {
$options['page'] = (int) $arg;
} else {
if (is_numeric($arg)) {
$options['page'] = (int) $arg;
} else {
if (isset($timelines[$arg])) {
$options['timeline'] = $arg;
array_shift($query);
} else {
VModule::load('404', TRUE);
}
}
}
}
if (isset($query['0']) && is_numeric($query['0'])) {
$options['page'] = (int) $query['0'];
}
if ($options['page'] === 0) {
VModule::load('404', TRUE);
}
return $options;
}
}
function build_url($order='', $timeline='', $slug='', $page=1, $pagination=false)
{
$url = RELATIVE_URL.'/photo/';
if ($slug != '') {
$url .= $slug.'/';
}
if ($order != '') {
$url .= $order.'/';
}
if ($timeline) {
if ($timeline != 'all' or $page >1) {
$url .= $timeline.'/';
}
}
if ($page === true) {
$url .= '#PAGE#/';
} elseif ($page !== 1) {
$url .= $page.'/';
}
return $url;
}
function build_rss_url($order='', $timeline='', $slug='')
{
$url = RELATIVE_URL.'/photo/rss/';
if ($slug != '') {
$url .= $slug.'/';
}
if ($order != '') {
$url .= $order.'/';
}
if ($timeline != '') {
$url .= $timeline.'/';
}
return $url;
}