getAll(array('order' => 'ord ASC')); $categoryArray = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true)); $routes = $favorites = $tracks = array(); if (App::$user && App::$user->id) { self::addVar('user', App::$user->id); $routes = Route::model()->getByAuthor(App::$user->id); $favorites = Favorite::model()->getAllMy(); $tracks = Trips::model()->getAll(array('where' => '`owner` = ?'), array(App::$user->id)); } else { self::addVar('user', '0'); } App::setConfig('title', App::$defaultTitle); self::addVar('isAdmin', (int) (App::$user && App::$user->isAdmin == 1)); self::addVar('pointLat', (isset($_GET['lat'])?floatval($_GET['lat']):0)); self::addVar('pointLng', (isset($_GET['lng'])?floatval($_GET['lng']):0)); if (isset($_COOKIE['userLat']) && isset($_COOKIE['userLng'])) { self::addVar('userLat', $_COOKIE['userLat']); self::addVar('userLng', $_COOKIE['userLng']); } else { self::addVar('userLat', App::$userGeo['lat']); self::addVar('userLng', App::$userGeo['lng']); } $og = array(); if (isset($_GET['point']) && $_GET['point'] && is_numeric($_GET['point'])) { $id = (int) $_GET['point']; $point = Point::model()->getByPK($id); $point->name = htmlspecialchars($point->name); $point->descriptionHtml = htmlspecialchars($point->description); $point->descriptionHtml .= ' Посмотреть на карте: https://wikipoints.ru/?point=' . $id; $point->descriptionHtml .= ' #wikipoints'; $og = Helper::buildOG($point); self::addVar('pointLat', $point->lat); self::addVar('pointLng', $point->lng); } else if (isset($_GET['point']) && $_GET['point'] && strtolower($_GET['point']) == 'random') { $og['title'] = 'Случайная точка на карте wikipoints.ru'; $og['description'] = 'Случайная точка на карте — это лучший способ узнать что-то новое! – wikipoints.ru'; $og['site_name'] = App::$defaultTitle; $og['type'] = 'article'; $og['url'] = 'https://wikipoints.ru/?point=random'; $og['image'] = 'https://wikipoints.ru/img/logo.png'; } self::render('indexTemplate.php', array( 'categories' => $category, 'categoryArray' => $categoryArray, 'user' => App::$user, 'routes' => $routes, 'favorites' => $favorites, 'tracks' => $tracks, 'og' => $og, )); } static function actionLogout() { $referrer = (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'wikipoints.ru') !== FALSE) ? $_SERVER['HTTP_REFERER'] : '/'; App::userLogout(); App::redirect($referrer); } static function actionLogin() { $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; if (!$email || !$password) { $_SESSION['login_error'] = 'Заполните email и пароль.'; App::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'); } $user = User::model()->getByEmail($email); if (!$user || !$user->id || !$user->verifyPassword($password)) { $_SESSION['login_error'] = 'Неверный email или пароль.'; App::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'); } if (!$user->emailConfirmed) { $_SESSION['login_error'] = 'Email не подтверждён. Проверьте почту.'; App::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'); } App::userLogin($user); unset($_SESSION['login_error']); App::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'); } static function actionRegister() { $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $nick = isset($_POST['nick']) ? trim($_POST['nick']) : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; $password2 = isset($_POST['password2']) ? $_POST['password2'] : ''; $error = ''; if (!$email || !$nick || !$password) { $error = 'Заполните все поля.'; } elseif ($password !== $password2) { $error = 'Пароли не совпадают.'; } elseif (strlen($password) < 6) { $error = 'Пароль должен быть не менее 6 символов.'; } elseif (User::model()->getByEmail($email)) { $error = 'Этот email уже зарегистрирован.'; } if ($error) { $_SESSION['register_error'] = $error; App::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/'); } $user = User::model()->add(array( 'uid' => md5($email . time()), 'email' => $email, 'nick' => $nick, 'name' => $nick, 'password' => User::hashPassword($password), 'profile' => '', 'network' => 'email', 'photo' => '', 'emailConfirmed' => 0, 'confirmToken' => bin2hex(random_bytes(32)), )); if (!$user) { $_SESSION['register_error'] = 'Ошибка регистрации. Попробуйте позже.'; App::redirect('/'); } $_SESSION['register_success'] = 'Регистрация прошла успешно! Подтвердите email, перейдя по ссылке в письме.'; App::redirect('/'); } static function actionSitemap() { $xml = new SimpleXMLElement(''); $url = $xml->addChild('url'); $url->addChild('loc', 'https://wikipoints.ru/'); $url->addChild('lastmod', date("Y-m-d")); $url->addChild('changefreq', "daily"); $url->addChild('priority', "0.9"); $articles = Article::model()->getAll(array('where'=>'`author` != 0 AND (`status` = "published" OR `status` = "system") ', 'order' => 'ID DESC', 'asArray' => true)); foreach ($articles as $article) { $url = $xml->addChild('url'); $url->addChild('loc', 'https://wikipoints.ru/article/' . $article['id']); $url->addChild('lastmod', date("Y-m-d", strtotime('- 5 days'))); $url->addChild('changefreq', "weekly"); $url->addChild('priority', "0.8"); } $points = Point::model()->getAll(array('order' => 'ID DESC', 'asArray' => true)); foreach ($points as $point) { $url = $xml->addChild('url'); $url->addChild('loc', 'https://wikipoints.ru/point/' . $point['id']); $url->addChild('lastmod', date("Y-m-d", $point['dateEdit'])); $url->addChild('changefreq', "weekly"); $url->addChild('priority', "0.8"); } Header('Content-type: text/xml'); print($xml->asXML()); } static function actionRoute() { self::$layout = 'layouts/print.php'; self::addStyle('/css/print.css?ver=' . App::getConfig('version')); if (!isset($_GET['route']) || !$_GET['route']) { App::error404('Нет данных для построения маршрута!'); } $route = json_decode($_GET['route']); if (!$route || !is_array($route)) { App::error404(); } $points = array(); foreach ($route as $pointId) { if ((int) $pointId) { $points[] = Point::model()->getByPK($pointId); } } self::render('route.php', array( 'points' => $points, )); } function actionShorturlroute() { if (!isset($_GET['elements']) || empty($_GET['elements'])) { App::error404(); } $elements = (array)$_GET['elements']; $url = '/?route=['; foreach ($elements AS $key => $element) { if ($key != 0) { $url .= ','; } if (isset($element['id'])) { $url .= '"'.$element['id'].'"'; } if (isset($element['latLng'])) { $url .= '"['.$element['latLng']['lat'].','.$element['latLng']['lng'].']"'; } } $url .= ']'; $shortUrl = ShortUrl::model()->getAll(array('where' => '`url` LIKE :url', 'limit' => 1), array('url' => $url)); if (!$shortUrl || $shortUrl->isEmpty()) { $shortUrl = ShortUrl::addNew($url); } print 'https://wikipoints.ru/s/'.x62::encode($shortUrl->id); } }