chevereto-free/app/routes/route.category.php

79 lines
2.1 KiB
PHP
Raw Normal View History

2016-08-18 20:39:31 +00:00
<?php
/* --------------------------------------------------------------------
Chevereto
http://chevereto.com/
@author Rodolfo Berrios A. <http://rodolfoberrios.com/>
<inbox@rodolfoberrios.com>
Copyright (C) Rodolfo Berrios A. All rights reserved.
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
BY USING THIS SOFTWARE YOU DECLARE TO ACCEPT THE CHEVERETO EULA
http://chevereto.com/license
--------------------------------------------------------------------- */
$route = function($handler) {
try {
2018-04-17 21:25:26 +00:00
2018-08-16 18:51:52 +00:00
if(!$handler::getCond('explore_enabled')) {
2016-08-18 20:39:31 +00:00
return $handler->issue404();
}
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
$category = NULL;
$categories = $handler::getVar('categories');
$category_url_key = $handler->request[0];
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
if(!$category_url_key) {
G\redirect('explore');
}
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
if($category_url_key) {
foreach($categories as $k => $v) {
// Set category info
if($v['url_key'] == $category_url_key) {
$category = $v;
break;
}
}
if(!$category) {
return $handler->issue404();
}
$handler::setVar('pre_doctitle', $category['name']);
}
// Tabs
2017-11-09 19:02:18 +00:00
$tabs = CHV\Listing::getTabs([
'listing' => 'images',
'basename' => G\get_route_name() . '/' . $category['url_key'],
'params_hidden' => ['category_id' => $category['id'], 'hide_banned' => 1],
]);
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
// List
$list_params = CHV\Listing::getParams(); // Use CHV magic params
$list = new CHV\Listing;
$list->setType('images');
$list->setOffset($list_params['offset']);
$list->setLimit($list_params['limit']); // how many results?
$list->setItemsPerPage($list_params['items_per_page']); // must
$list->setSortType($list_params['sort'][0]); // date | size | views
$list->setSortOrder($list_params['sort'][1]); // asc | desc
$list->setCategory($category['id']);
$list->setRequester(CHV\Login::getUser());
$list->exec();
2017-11-09 19:02:18 +00:00
$meta_description = $category['description'] ?: NULL;
2018-08-16 18:51:52 +00:00
2016-08-18 20:39:31 +00:00
$handler::setVar('meta_description', htmlspecialchars($meta_description));
$handler::setVar('category', $category);
$handler::setVar('tabs', $tabs);
$handler::setVar('list', $list);
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
$handler->template = 'explore';
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
} catch(Exception $e) {
G\exception_to_error($e);
}
};