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

107 lines
3.3 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
2016-08-18 20:39:31 +00:00
$logged_user = CHV\Login::getUser();
2018-04-17 21:25:26 +00:00
2018-08-16 18:51:52 +00:00
if(!$handler::getCond('explore_enabled') && !$logged_user['is_admin']) {
2016-08-18 20:39:31 +00:00
return $handler->issue404();
}
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
$doing = $handler->request[0];
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
if(!$doing && CHV\getSetting('homepage_style') == 'route_explore' && strpos(G\get_current_url(), G\get_base_url(G\get_route_name())) !== FALSE) {
$redir = G\str_replace_first(G\get_base_url(G\get_route_name()), G\get_base_url(), G\get_current_url());
G\redirect($redir);
}
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
$explore_semantics = $handler::getVar('explore_semantics');
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
if(isset($doing) && !array_key_exists($doing, $explore_semantics)) {
return $handler->issue404();
2016-08-18 20:39:31 +00:00
}
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
if($handler->isRequestLevel(3)) return $handler->issue404(); // Allow only 3 levels
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
$basename = CHV\getSetting('homepage_style') == 'route_explore' && $handler->getCond('mapped_route') ? NULL : G\get_route_name();
if($doing) {
$basename .= ($basename ? '/' : NULL) . $doing;
2016-08-18 20:39:31 +00:00
}
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
$listing = isset($doing) ? $explore_semantics[$doing] : ['label' => _s('Explore'), 'icon' => 'icon-images2'];
$listing['list'] = is_null($doing) ? G\get_route_name() : $doing;
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
$listingParams = [
'listing' => $listing['list'],
'basename' => $basename,
2018-08-16 18:51:52 +00:00
'params_hidden' => [
'hide_empty' => 1,
'hide_banned' => 1,
'album_min_image_count' => CHV\getSetting('explore_albums_min_image_count'),
],
2017-11-09 19:02:18 +00:00
];
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
if($doing == 'animated') {
$listingParams['params_hidden']['is_animated'] = 1;
}
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
$tabs = CHV\Listing::getTabs($listingParams, TRUE);
2018-04-17 21:25:26 +00:00
$currentKey = $tabs['currentKey'];
2017-11-09 19:02:18 +00:00
$type = $tabs['tabs'][$currentKey]['type'];
$tabs = $tabs['tabs'];
parse_str($tabs[$currentKey]['params'], $tabs_params);
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
$list_params = CHV\Listing::getParams(); // Use CHV magic params
2017-11-09 19:02:18 +00:00
$list_params['sort'] = explode('_', $tabs_params['sort']); // Hack this stuff
// List
2016-08-18 20:39:31 +00:00
$list = new CHV\Listing;
2017-11-09 19:02:18 +00:00
$list->setType($type);
2016-08-18 20:39:31 +00:00
$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 | likes
$list->setSortOrder($list_params['sort'][1]); // asc | desc
$list->setRequester(CHV\Login::getUser());
2017-11-09 19:02:18 +00:00
$list->setParamsHidden($listingParams['params_hidden']);
2016-08-18 20:39:31 +00:00
$list->exec();
2018-04-17 21:25:26 +00:00
2017-11-09 19:02:18 +00:00
$handler::setVar('listing', $listing);
2018-04-17 21:25:26 +00:00
if(CHV\getSetting('homepage_style') == 'route_explore') {
$handler::setVar('doctitle', CHV\Settings::get('website_doctitle'));
$handler::setVar('pre_doctitle', CHV\Settings::get('website_name'));
} else {
$handler::setVar('pre_doctitle', _s('Explore'));
}
2016-08-18 20:39:31 +00:00
$handler::setVar('category', NULL);
$handler::setVar('tabs', $tabs);
$handler::setVar('list', $list);
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
if($logged_user['is_admin']) {
2017-11-09 19:02:18 +00:00
$handler::setVar('user_items_editor', FALSE);
2016-08-18 20:39:31 +00:00
}
2018-04-17 21:25:26 +00:00
2016-08-18 20:39:31 +00:00
} catch(Exception $e) {
G\exception_to_error($e);
}
2018-04-17 21:25:26 +00:00
};