<?php

/*
 * @name        JMY CMS
 * @link        https://jmy.su/
 * @copyright   Copyright (C) 2012-2025 JMY LTD
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      Komarov Ivan
 * @edited      Orlov Alexsey
 */

if (!defined('ACCESS')) {
    header('Location: /');
    exit;
}
global $user, $db, $config, $core, $url, $cache, $lang;
if (file_exists(ROOT . 'usr/other/other.vars.php')) include(ROOT . 'usr/other/other.vars.php');

$full_lnk = $config['url'] . (!empty($url[0]) ? '/' . $url[0] : '') . (!empty($url[1]) ? '/' . $url[1] : '') . (!empty($url[2]) ? '/' . $url[2] : '') . (!empty($url[3]) ? '/' . $url[3] : '');
$cat_keyword = (isset($this->keywords) ? ', ' . $this->keywords : false);
$desc = ($this->description ?? $config['description']);
$title_now = html_entity_decode((!empty($this->title) && !empty($_REQUEST['url']) ? $this->title . $config['name'] : $config['name'] . $config['divider'] . $config['slogan']), ENT_QUOTES);
$bookmarks = $core->sum_data('bookmarks', 'uid = ' . $core->auth->user_id);
$comments = $core->sum_data('comments', 'uid = ' . $core->auth->user_id);
$on_news = isset($core->auth->user_info['nick']) ? $core->sum_data('news', 'author = "' . $core->auth->user_info['nick'] . '" AND active=1') : null;
$off_news = isset($core->auth->user_info['nick']) ? $core->sum_data('news', 'author = "' . $core->auth->user_info['nick'] . '" AND active=3') : null;
$mod_news = isset($core->auth->user_info['nick']) ? $core->sum_data('news', 'author = "' . $core->auth->user_info['nick'] . '" AND active=2') : null;
list($friends) = isset($core->auth->user_info['nick']) ? $db->fetchRow($db->query("SELECT COUNT(*) FROM `" . USER_DB . "`.`" . USER_PREFIX . "_users` as u LEFT JOIN `" . USER_DB . "`.`" . USER_PREFIX . "_user_friends` as f on (u.id = f.who_invite OR u.id = f.whom_invite) WHERE (f.who_invite = '" . $core->auth->user_info['id'] . "' OR f.whom_invite = '" . $core->auth->user_info['id'] . "') AND u.id != '" . $core->auth->user_info['id'] . "' AND f.confirmed = '1'")) : null;
list($onfriends) = isset($core->auth->user_info['nick']) ? $db->fetchRow($db->query("SELECT COUNT(*) FROM `" . USER_DB . "`.`" . USER_PREFIX . "_online` as u LEFT JOIN `" . USER_DB . "`.`" . USER_PREFIX . "_user_friends` as f on (u.uid = f.who_invite OR u.uid = f.whom_invite) WHERE (f.who_invite = '" . $core->auth->user_info['id'] . "' OR f.whom_invite = '" . $core->auth->user_info['id'] . "') AND u.uid != '" . $core->auth->user_info['id'] . "' AND f.confirmed = '1'")) : null;
list($inbox) = $db->fetchRow($db->query("SELECT COUNT(*) FROM `" . DB_PREFIX . "_pm` as pm LEFT JOIN `" . USER_DB . "`.`" . USER_PREFIX . "_users` as u on (pm.fromid = u.id) WHERE pm.toid = '" . $core->auth->user_id . "'	AND pm.status !='2' AND pm.status !='3' AND pm.status !='4' ORDER BY time DESC"));
list($sentbox) = $db->fetchRow($db->query("SELECT COUNT(*) FROM `" . DB_PREFIX . "_pm` as pm LEFT JOIN `" . USER_DB . "`.`" . USER_PREFIX . "_users` as u on (pm.toid = u.id) WHERE pm.fromid = '" . $core->auth->user_id . "' AND pm.status !='2' AND pm.status !='3' AND pm.status !='4' ORDER BY time DESC"));
list($draftcopy) = $db->fetchRow($db->query("SELECT COUNT(*) FROM `" . DB_PREFIX . "_pm` as pm LEFT JOIN `" . USER_DB . "`.`" . USER_PREFIX . "_users` as u on (pm.toid = u.id) WHERE pm.fromid = '" . $core->auth->user_id . "' AND pm.status='2' ORDER BY time DESC"));
list($basket) = $db->fetchRow($db->query("SELECT COUNT(*) FROM `" . DB_PREFIX . "_pm` as pm LEFT JOIN `" . USER_DB . "`.`" . USER_PREFIX . "_users` as u on (pm.toid = u.id) WHERE pm.fromid = '" . $core->auth->user_id . "' AND pm.status='3' ORDER BY time DESC"));
////////////////////////////////////BANNERS//////////////////////////
include(ROOT . 'usr/modules/banners/outbanners.php');
////////////////////////////////////////////////////////////////////////
////////////////////////////////////TAGCODE//////////////////////////
include(ROOT . 'usr/modules/tagcode/index.php');
////////////////////////////////////////////////////////////////////////
////////////////////////////////////includ_chart//////////////////////////
require_once(ROOT . 'usr/modules/includ_chart/index.php');
////////////////////////////////////////////////////////////////////////
$this->setVar('FULL_AJAX:start', '<div id="fullAjax">');
$this->setVar('FULL_AJAX:end', '</div>');
$this->setVar('GENERATE', mb_substr(microtime(1) - TIMER, 0, 5));
$this->setVar('GZIP', $config['gzip'] ? 'GZIP Включён' : 'GZIP Выключён');
$this->setVar('SITE_NAME', $config['name']);
$this->setVar('SITE_SLOGAN', $config['slogan']);
$this->setVar('TIME_ZONE', mb_substr($db->timeQueries, 0, 5));
$this->setVar('MOD_NAME', $url[0]);
$this->setVar('THEME', '/usr/tpl/' . $this->tplDir);
$this->setVar('URL', $config['url']);
$this->setVar('FULL_LNK', $full_lnk);
$this->setVar('LICENSE', 'Powered by <a target="_blank" href="https://jmy.su/">JMY CMS</a>');
$this->setVar('D_YEAR', date("Y"));
$this->setVar('D_MOTH', date("M"));
$this->setVar('D_DAY', date("d"));
$this->setVar('ADMINLOG', $core->auth->isAdmin ? ' <a href="' . ADMIN . '">[Панель управления]</a>' : '');
$this->setVar('USER_AVATAR', avatar($core->auth->user_id));
$this->setVar('USER_NAME', $core->auth->user_info['nick'] ?? '');
$this->setVar('QUERIES', $db->numQueries);
$this->setVar('NEW_PM', $core->auth->newPmsNumb ?? $inbox);
$this->setVar('NUM_INBOX', $inbox);
$this->setVar('NUM_SENTBOX', $sentbox);
$this->setVar('NUM_DRAFTCOPY', $draftcopy);
$this->setVar('NUM_BASKET', $basket);
$this->setVar('NUM_BOOKMARKS', $bookmarks);
$this->setVar('NUM_COMMENTS', $comments);
$this->setVar('NUM_NEWS_ON', $on_news);
$this->setVar('NUM_NEWS_OFF', $off_news);
$this->setVar('NUM_NEWS_MOD', $mod_news);
$this->setVar('NUM_FRIENDS', $friends);
$this->setVar('NUM_ONFRIENDS', $onfriends);
$this->setVar('TITLE_NOW', $title_now);
$this->setVar('VERSION', VERSION_ID);
//ссылки модулей
$this->setVar('METOD', !$core->ban ? (($user['auth_metod'] == 'email') ? $lang['email'] : $lang['login']) : '');
$this->setVar('URL_LOGIN', 'profile');
$this->setVar('URL_ADD', '/news/addPost');
$this->setVar('URL_ADMIN', ADMIN);
$this->setVar('URL_REG', 'profile/register');
$this->setVar('URL_FORGOT', 'profile/forgot_pass');
$this->setVar('URL_LOGOUT', 'profile/logout');
$this->setVar('URL_PDA', 'index.php?phone_change');
$this->setVar('URL_PROFIL', 'profile');
$this->setVar('URL_PM', 'pm');
$this->setVar('URL_BLOG', 'blog');
$this->setVar('URL_FORUM', 'board');
$this->setVar('URL_NEWS', 'news');
$this->setVar('URL_GUEST', 'guestbook');
$this->setVar('URL_GALLERY', 'gallery');
$this->setVar('URL_SITEMAP', 'sitemap');
$this->setVar('URL_FEEDBACK', 'feedback');
$this->setVar('URL_FAQ', 'help');
$this->setVar('URL_BOOKMARKS', 'news/bookmarks');
$this->setVar('URL_FLIST', ($friends > 0) ? 'profile/friends_list' : '');
$this->setVar('URL_ONFLIST', ($onfriends > 0) ? 'profile/online_friends_list' : '');
$this->setVar('URL_UNEWS', 'news/user_news');
$this->setVar('URL_COMMENTS', 'news/user_comments');
$this->setVar('URL_TAGS', 'news/tags');
$this->setVar('SEARCH', 'search');
//auth
$this->setVar('AUTH_LIST', !$core->ban ? social_list() : '');
$this->setVar('AUTH_VK', $config['url'] . '/auth.php?url=vk');
$this->setVar('AUTH_OK', $config['url'] . '/auth.php?url=odnoklassniki');
$this->setVar('AUTH_FB', $config['url'] . '/auth.php?url=facebook');
$this->setVar('AUTH_GP', $config['url'] . '/auth.php?url=google');
$this->setVar('AUTH_YA', $config['url'] . '/auth.php?url=yandex');
$this->setVar('AUTH_MM', $config['url'] . '/auth.php?url=mailru');
//share
$this->setVar('SHARE_VK', 'https://vk.com/share.php?url=' . $full_lnk . '&title=' . $title_now);
$this->setVar('SHARE_FB', 'https://www.facebook.com/share.php?u=' . $full_lnk);
$this->setVar('SHARE_TW', 'https://twitter.com/intent/tweet?status=' . $full_lnk);
$this->setVar('SHARE_YT', 'https://www.googleapis.com/youtube/v3/playlistItems?part=' . $full_lnk);
$this->setVar('SHARE_SK', 'https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=13&ct=1525987970&rver=7.0.6730.0&wp=MBI_SSL&wreply=https%3A%2F%2Flw.skype.com%2Flogin%2Foauth%2Fproxy%3Fclient_id%3D578134%26redirect_uri%3Dhttps%253A%252F%252Fweb.skype.com%252Fshare%253Furl%253Dhttp%' . $full_lnk . '%2526utm_source%253Dshare2%26site_name%3Dlw.skype.com&lc=1033&id=293290&mkt=ru&psi=skype&lw=1&cobrandid=90010&client_flight=hsu%2CReservedFlight33%2CReservedFlight67');
$this->setVar('SHARE_GP', 'https://plus.google.com/share?url=' . $full_lnk);
$this->setVar('SHARE_LJ', 'https://www.livejournal.com/update.bml?mode=full&subject=test&event=' . $full_lnk);
$this->setVar('SHARE_BZ', 'https://www.google.com/buzz/post?message=' . $title_now . '&url=' . $full_lnk . '&hl=ru');
$this->setVar('SHARE_TB', 'https://www.tumblr.com/share/link?url=' . $full_lnk . '&amp;title=' . $title_now);
$this->setVar('SHARE_LI', 'https://www.linkedin.com/shareArticle?mini=true&amp;url=' . $full_lnk);
$this->setVar('SHARE_PP', 'https://plus.google.com/share?url=' . $full_lnk);
$this->setVar('SHARE_SB', 'https://plus.google.com/share?url=' . $full_lnk);
$this->setVar('SHARE_YA', 'https://plus.google.com/share?url=' . $full_lnk);
$this->setVar('SHARE_MM', 'https://connect.mail.ru/share?url=' . $full_lnk . '&title=' . $title_now . '&description=&imageurl=');
$this->setVar('SHARE_PR', 'javascript:window.print();');
$this->setVar('SHARE_MA', 'mailto:?Subject=' . $title_now . '&amp;Body=Share%20from%20' . $config['name'] . '%20' . $full_lnk);
$this->setVar('SHARE_PT', 'javascript:void((function()%7Bvar%20e=document.createElement(\'script\');e.setAttribute(\'type\',\'text/javascript\');e.setAttribute(\'charset\',\'UTF-8\');e.setAttribute(\'src\',\'http://assets.pinterest.com/js/pinmarklet.js?r=\'+Math.random()*99999999);document.body.appendChild(e)%7D)());');