<?php
/**
* mobiCMS (https://mobicms.org/)
* This file is part of mobiCMS Content Management System.
*
* @license https://opensource.org/licenses/GPL-3.0 GPL-3.0 (see the LICENSE.md file)
* @link http://mobicms.org mobiCMS Project
* @copyright Copyright (C) mobiCMS Community
*/
defined('MOBICMS') or die('Error: restricted access');
$id = isset($_REQUEST['id']) ? abs(intval($_REQUEST['id'])) : 0;
$act = isset($_GET['act']) ? trim($_GET['act']) : '';
$mod = isset($_GET['mod']) ? trim($_GET['mod']) : '';
$al = isset($_REQUEST['al']) ? abs(intval($_REQUEST['al'])) : null;
$img = isset($_REQUEST['img']) ? abs(intval($_REQUEST['img'])) : null;
/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();
/** @var Mobicms\Asset\Manager $asset */
$asset = $container->get(Mobicms\Asset\Manager::class);
/** @var Mobicms\Api\UserInterface $systemUser */
$systemUser = $container->get(Mobicms\Api\UserInterface::class);
/** @var Zend\I18n\Translator\Translator $translator */
$translator = $container->get(Zend\I18n\Translator\Translator::class);
$translator->addTranslationFilePattern('gettext', __DIR__ . '/locale', '/%s/default.mo');
/** @var Mobicms\Api\ToolsInterface $tools */
$tools = $container->get(Mobicms\Api\ToolsInterface::class);
$pageTitle = _t('Album');
$max_album = 20;
$max_photo = 400;
// Закрываем от неавторизованных юзеров
if (!$systemUser->isValid()) {
require ROOT_PATH . 'system/head.php';
echo $tools->displayError(_t('For registered users only'));
require ROOT_PATH . 'system/end.php';
exit;
}
// Получаем данные пользователя
$user = $tools->getUser(isset($_REQUEST['user']) ? abs(intval($_REQUEST['user'])) : 0);
if (!$user) {
require ROOT_PATH . 'system/head.php';
echo $tools->displayError(_t('User does not exists'));
require ROOT_PATH . '../system/end.php';
exit;
}
/**
* Функция голосований за фотографии
*
* @param array $arg
* @return bool|string
*/
function vote_photo(array $arg)
{
/** @var Psr\Container\ContainerInterface $container */
$container = App::getContainer();
/** @var PDO $db */
$db = $container->get(PDO::class);
/** @var Mobicms\Api\UserInterface $systemUser */
$systemUser = $container->get(Mobicms\Api\UserInterface::class);
$rating = $arg['vote_plus'] - $arg['vote_minus'];
if ($rating > 0) {
$color = 'C0FFC0';
} elseif ($rating < 0) {
$color = 'F196A8';
} else {
$color = 'CCC';
}
$out = '<div class="gray">' . _t('Rating') . ': <span style="color:#000;background-color:#' . $color . '">  <big><b>' . $rating . '</b></big>  </span> ' .
'(' . _t('Against') . ': ' . $arg['vote_minus'] . ', ' . _t('For') . ': ' . $arg['vote_plus'] . ')';
if ($systemUser->id != $arg['user_id'] && empty($systemUser->ban) && $systemUser->postforum > 10 && $systemUser->total_on_site > 1200) {
// Проверяем, имеет ли юзер право голоса
$req = $db->query("SELECT * FROM `cms_album_votes` WHERE `user_id` = '" . $systemUser->id . "' AND `file_id` = '" . $arg['id'] . "' LIMIT 1");
if (!$req->rowCount()) {
$out .= '<br>' . _t('Vote') . ': <a href="?act=vote&mod=minus&img=' . $arg['id'] . '"><< -1</a> | <a href="?act=vote&mod=plus&img=' . $arg['id'] . '">+1 >></a>';
}
}
$out .= '</div>';
return $out;
}
// Переключаем режимы работы
$array = [
'comments',
'delete',
'edit',
'image_delete',
'image_download',
'image_edit',
'image_move',
'image_upload',
'list',
'new_comm',
'show',
'sort',
'top',
'users',
'vote',
];
if (in_array($act, $array) && is_file(__DIR__ . '/includes/' . $act . '.php')) {
require __DIR__ . '/includes/' . $act . '.php';
} else {
/** @var PDO $db */
$db = $container->get(PDO::class);
/** @var Mobicms\Api\ConfigInterface $config */
$config = $container->get(Mobicms\Api\ConfigInterface::class);
require ROOT_PATH . 'system/head.php';
$albumcount = $db->query("SELECT COUNT(DISTINCT `user_id`) FROM `cms_album_files`")->fetchColumn();
$total_mans = $db->query("SELECT COUNT(DISTINCT `user_id`)
FROM `cms_album_files`
LEFT JOIN `users` ON `cms_album_files`.`user_id` = `users`.`id`
WHERE `users`.`sex` = 'm'
")->fetchColumn();
$total_womans = $db->query("SELECT COUNT(DISTINCT `user_id`)
FROM `cms_album_files`
LEFT JOIN `users` ON `cms_album_files`.`user_id` = `users`.`id`
WHERE `users`.`sex` = 'zh'
")->fetchColumn();
$newcount = $db->query("SELECT COUNT(*) FROM `cms_album_files` WHERE `time` > '" . (time() - 259200) . "' AND `access` = 4")->fetchColumn();
echo '<div class="phdr"><b>' . _t('Photo Albums') . '</b></div>' .
'<div class="gmenu"><p>' .
$asset->img('users.png')->class('icon') . '<a href="?act=top">' . _t('New Photos') . '</a> (' . $newcount . ')<br>' .
$asset->img('talk.gif')->class('icon') . '<a href="?act=top&mod=last_comm">' . _t('New Comments') . '</a>' .
'</p></div>' .
'<div class="menu">' .
'<p><h3>' . $asset->img('users.png')->class('left') . ' ' . _t('Albums') . '</h3><ul>' .
'<li><a href="?act=users&mod=boys">' . _t('Guys') . '</a> (' . $total_mans . ')</li>' .
'<li><a href="?act=users&mod=girls">' . _t('Girls') . '</a> (' . $total_womans . ')</li>';
if ($systemUser->isValid()) {
echo '<li><a href="?act=list">' . _t('My Album') . '</a></li>';
}
echo '</ul></p>' .
'<p><h3>' . $asset->img('rate.gif')->class('icon') . _t('Rating') . '</h3><ul>' .
'<li><a href="?act=top&mod=votes">' . _t('Top Votes') . '</a></li>' .
'<li><a href="?act=top&mod=downloads">' . _t('Top Downloads') . '</a></li>' .
'<li><a href="?act=top&mod=views">' . _t('Top Views') . '</a></li>' .
'<li><a href="?act=top&mod=comments">' . _t('Top Comments') . '</a></li>' .
'<li><a href="?act=top&mod=trash">' . _t('Top Worst') . '</a></li>' .
'</ul></p>' .
'</div>' .
'<div class="phdr"><a href="index.php">' . _t('Users') . '</a></div>';
}
require ROOT_PATH . 'system/end.php';