diff --git a/.gitignore b/.gitignore index 492fe9e..fe5fff8 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ public/photos/big/*.jpg public/photos/big/*.jpeg public/photos/big/*.png public/photos/big/*.gif + +logs/*.log \ No newline at end of file diff --git a/ground/app.php b/ground/app.php index 8bbddf3..5787c6b 100644 --- a/ground/app.php +++ b/ground/app.php @@ -33,6 +33,7 @@ class App private static $DB = null; public static $user = null; public static $request = array(); + public static $defaultTitle = 'Лучшие выходные – это выходные в путешествии! – wikipoints.ru'; /** * Разбивает урл на контроллер, метод и выбирает параметры. @@ -205,4 +206,17 @@ class App ); } + public static function log($logName, $value) + { + $fileName = App::getBasedir() . + '../logs/' . + $logName . '.log'; + + return file_put_contents( + $fileName, date('d-m-Y H:i:s') . " - " . + print_r($value, true) . + "\n-------------------\n", FILE_APPEND + ); + } + } diff --git a/ground/classes/Helper.php b/ground/classes/Helper.php index 404d866..833039d 100644 --- a/ground/classes/Helper.php +++ b/ground/classes/Helper.php @@ -8,9 +8,15 @@ class Helper return (bool) $var; } - public static function replaceLinks($string, $linkTemplate = '/page/point/id/') + /** + * TYPES: 'clear','html','js' + * @param type $string + * @param type $replaceType + * @return type + */ + public static function replaceLinks($string, $replaceType = 'clear') { - preg_match_all("(\[#(\d+)[>\|](.*?)\])", $string, $links); + preg_match_all("((\[#(\d+)[>\|](.*?)\])|(\[#(\d+)\]))", $string, $links); $links = isset($links[0]) ? $links[0] : FALSE; if ($links) { foreach ($links as $link) { @@ -19,13 +25,26 @@ class Helper $idAndLink = explode($delimiter, $idAndLink); $linkId = $idAndLink[0]; - $linkName = isset($idAndLink[1]) ? $idAndLink[1] : ''; + $linkName = isset($idAndLink[1]) ? $idAndLink[1] : ''; if ($linkId) { $linkPoint = Point::model()->getByPK($linkId); - if ($linkPoint->id) { - $linkPoint->name = str_replace('"', 'ʺ', $linkPoint->name); - $string = str_replace($link, '' . $linkName . '', $string); + if ($linkPoint && $linkPoint->id) { + $linkTitle = str_replace('"', 'ʺ', $linkPoint->name); + + switch ($replaceType) { + case 'html': + $linkName = $linkName ? $linkName : ''; + $string = str_replace($link, '' . $linkName . '', $string); + break; + case 'js': + $linkName = $linkName ? $linkName : ''; + $string = str_replace($link, '' . $linkName . '', $string); + break; + default: + $string = str_replace($link, $linkName, $string); + break; + } } } } @@ -34,13 +53,69 @@ class Helper return $string; } + public static function replaceImgs($string, $replaceType = 'clear') + { + preg_match_all("(\[img[\|]#(\d+)\])", $string, $images); + $images = isset($images[0]) ? $images[0] : FALSE; + if ($images) { + foreach ($images as $img) { + $imgAndId = mb_substr($img, 2, -1); + $imgAndId = explode('#', $imgAndId); + + $imgId = (int)$imgAndId[1]; + + $imgObj = ArticlePhotos::model()->getByPK($imgId); + + if ($imgObj->name) { + switch ($replaceType) { + case 'html': + $imgObj->caption = $linkTitle = str_replace('"', 'ʺ', $imgObj->caption); + $imgTag = '
'; + $string = str_replace($img, $imgTag, $string); + break; + default: + $imgTag = ''; + $string = str_replace($img, $imgTag, $string); + break; + } + } else { + switch ($replaceType) { + case 'html': + $imgTag = '
'; + $string = str_replace($img, $imgTag, $string); + break; + default: + $imgTag = ''; + $string = str_replace($img, $imgTag, $string); + break; + } + } + } + } + + return $string; + } + + public static function getFirstImg($string) + { + preg_match_all("(\[img[\|]#(\d+)\])", $string, $images); + $images = isset($images[0]) ? $images[0] : FALSE; + $img = isset($images[0]) ? $images[0] : FALSE; + if ($img) { + $imgId = (int) mb_substr($img, 6, -1); + $imgObj = ArticlePhotos::model()->getByPK($imgId); + return $imgObj->name ? (int)$imgObj->id : 0; + } + return 0; + } + public static function buildOG($point) { $og = array(); $og['title'] = str_replace('"', 'ʺ', $point->name) . ' [wikipoints.ru]'; $point->description = str_replace('"', 'ʺ', $point->description); - $og['description'] = mb_substr($point->description, 0, 97, 'UTF-8') . '...'; - $og['site_name'] = 'WikiPoints: Лучшие выходные - это выходные в путешествии!'; + $og['description'] = mb_substr($point->description, 0, 99, 'UTF-8') . '…'; + $og['site_name'] = App::$defaultTitle; $og['type'] = 'website'; $og['url'] = 'http://wikipoints.ru/?point=' . $point->id; $og['image'] = $point->getImg('middle'); @@ -48,4 +123,18 @@ class Helper return $og; } + public static function buildArticleOG($article) + { + $og = array(); + $og['title'] = str_replace('"', 'ʺ', $article->title) . ' [wikipoints.ru]'; + $article->text = Markdown::getClear(str_replace('"', 'ʺ', $article->text)); + $og['description'] = mb_substr($article->text, 0, 99, 'UTF-8') . '…'; + $og['site_name'] = App::$defaultTitle; + $og['type'] = 'website'; + $og['url'] = 'http://wikipoints.ru/page/article/id/' . $article->id; + $og['image'] = $article->getImg('middle'); + + return $og; + } + } diff --git a/ground/classes/Image.php b/ground/classes/Image.php index 6a29456..cd61dd4 100644 --- a/ground/classes/Image.php +++ b/ground/classes/Image.php @@ -29,15 +29,17 @@ class Image * Создаёт все требуемые размеры изображения и раскладывает их по папкам. * @param type $imgName */ - public static function createAllSizes($imgName) + public static function createAllSizes($imgName, $noWatermark = false, $folder = '') { $sizes = App::getConfig('images'); $pathInfo = pathinfo($_SERVER['SCRIPT_FILENAME']); - $uploaddir = $pathInfo['dirname'] . '/photos/'; + $uploaddir = $pathInfo['dirname'] . '/photos/' . $folder; $watermarkDir = App::getBasedir() . 'watermarks/'; foreach ($sizes as $dir => $size) { $watermark = isset($size[3]) ? $watermarkDir . $size[3] : ''; + $watermark = $noWatermark ? '' : $watermark; + self::imgResize( $uploaddir . $imgName, // Source - original image $uploaddir . $dir . '/' . $imgName, // Destination diff --git a/ground/classes/Markdown.php b/ground/classes/Markdown.php new file mode 100644 index 0000000..251067e --- /dev/null +++ b/ground/classes/Markdown.php @@ -0,0 +1,136 @@ + 0; $index--) { + + $pr = '/(^#{' . $index . '} .{1,})/m'; + + preg_match_all($pr, $string, $headers); + + if (isset($headers[0][0])) { + foreach ($headers[0] as $header) { + $hI = $index+1; + $string = str_replace($header, "" . mb_substr($header, $index + 1, NULL, 'UTF-8') . "", $string); + } + } + } + + return $string; + } + + static private function replaceBold($string) + { + $pr = '(\*{2}(.+?)\*{2})'; + $rep = '$1'; + return preg_replace($pr, $rep, $string); + } + + static private function replaceItalic($string) + { + $pr = '(\*{1}(.+?)\*{1})'; + $rep = '$1'; + return preg_replace($pr, $rep, $string); + } + + static private function replaceUnderline($string) + { + $pr = '(\_{1}(.+?)\_{1})'; + $rep = '$1'; + return preg_replace($pr, $rep, $string); + } + + static private function replaceUrls($string) + { + $pr = '((https{0,1}:\/\/[\da-z\.-]+\.[a-z]{2,6})([\/\w\?=&#%+,-]|(\.[^\s]))*\/?)'; + $rep = '$1'; + return preg_replace($pr, $rep, $string); + } + + static private function replaceChars($string) + { + $pr = '((^|\s)-{2}($|\s))'; + $rep = '$1–$2'; + $string = preg_replace($pr, $rep, $string); + + $pr = '((^|\s)\((c|с)\)($|\s))'; + $rep = '$1©$3'; + $string = preg_replace($pr, $rep, $string); + + $string = str_replace( + array("\r", '"', '«', '»'), + array('', 'ʺ', 'ʺ', 'ʺ'), + $string); + + return $string; + } + + static function getClear($string) + { + // Headers + for ($index = 3; $index > 0; $index--) { + + $pr = '/(^#{' . $index . '} .{1,})/m'; + + preg_match_all($pr, $string, $headers); + + if (isset($headers[0][0])) { + foreach ($headers[0] as $header) { + $hI = $index+1; + $string = str_replace($header, '', $string); + } + } + } + + // Bold & Italic + $pr = '(\*{1,3}(.+?)\*{1,3})'; + $rep = '$1'; + $string = preg_replace($pr, $rep, $string); + + // Uderline + $pr = '(\_{1}(.+?)\_{1})'; + $rep = '$1'; + $string = preg_replace($pr, $rep, $string); + + // Images + $pr = '(\[img[\|]#(\d+)\])'; + $rep = ' '; + $string = preg_replace($pr, $rep, $string); + + // \n & \r + $string = str_replace(array("\n","\r",' -- '), array(' ', ' ',' – '), $string); + + // URL + $pr = '((https{0,1}:\/\/[\da-z\.-]+\.[a-z]{2,6})[\/\w\?=&#%+\.,-]*\/?)'; + $rep = ''; + $string = preg_replace($pr, $rep, $string); + + // Points + $pr = '((\[#(\d+)[>\|](.*?)\])|(\[#(\d+)\]))'; + $rep = ' '; + $string = preg_replace($pr, $rep, $string); + + // multi-space + $pr = '(\s{2,})'; + $rep = ' '; + $string = preg_replace($pr, $rep, $string); + + return trim($string); + } + +} diff --git a/ground/classes/Model.php b/ground/classes/Model.php index d2850fa..c1f8645 100644 --- a/ground/classes/Model.php +++ b/ground/classes/Model.php @@ -154,7 +154,15 @@ abstract class Model $calledClass = get_called_class(); while ($res && $row = $res->fetch(PDO::FETCH_ASSOC)) { - $ready[$row[$this->_primaryKey_]] = isset($params['asArray']) && $params['asArray'] ? $row : new $calledClass($row); + if (isset($params['noKeys'])) { + $ready[] = isset($params['asArray']) && $params['asArray'] ? $row : new $calledClass($row); + } else { + if (isset($params['asArrayOf'])) { + $ready[] = isset($params['asArray']) && $params['asArray'] ? $row : new $calledClass($row); + } else { + $ready[$row[$this->_primaryKey_]] = isset($params['asArray']) && $params['asArray'] ? $row : new $calledClass($row); + } + } } return (isset($params['limit']) && $params['limit'] == 1) ? array_shift($ready) : $ready; diff --git a/ground/config_template.php b/ground/config_template.php index e54ae8e..dba4557 100644 --- a/ground/config_template.php +++ b/ground/config_template.php @@ -1,7 +1,7 @@ 'Интересные выходные вместе с wikipoints.ru', + 'title' => 'Лучшие выходные – это выходные в путешествии! – wikipoints.ru', 'DB' => array( 'host' => 'localhost', 'user' => 'root', diff --git a/ground/controllers/ArticlesController.php b/ground/controllers/ArticlesController.php new file mode 100644 index 0000000..31b8a7f --- /dev/null +++ b/ground/controllers/ArticlesController.php @@ -0,0 +1,121 @@ +isAdmin) { + App::error404(); + } + // ------------------------------------------ + + App::setConfig('title', App::$defaultTitle); + + self::render('articles/index.php', array( + 'user' => App::$user, + 'articles' => Article::model()->getAll(), + 'randomPoint' => Point::model()->getRandom(), + )); + } + + static function actionEdit() + { + if (!App::$user || !App::$user->isAdmin) { + App::error404(); + } + + $articleId = (int) App::getParam('id'); + + self::$layout = 'layoutPage.php'; + self::addScript('/js/jquery-2.1.0.min.js'); + self::addScript('/js/jquery-ui-1.10.4.custom.min.js'); + self::addScript('/js/bootstrap.min.js'); + self::addScript('/js/app.js?ver=' . App::getConfig('version')); + self::addScript('http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.js'); + self::addStyle('/css/style.css?ver=' . App::getConfig('version')); + self::addStyle('/css/pageStyle.css?ver=' . App::getConfig('version')); + self::addStyle('/css/bootstrap.min.css'); + self::addStyle('/css/bootstrap-theme.min.css'); + self::addStyle('http://cdnjs.cloudflare.com/ajax/libs/fotorama/4.6.3/fotorama.css'); + + $article = Article::model()->getByPK($articleId); + + if (!$article) { + App::error404(); + } + + App::setConfig('title', 'Редактирование статьи – ' . $article->title . ' – wikipoints.ru'); + + self::render('articles/edit.php', array( + 'article' => $article, + 'randomPoint' => Point::model()->getRandom(), + )); + } + + static function actionSave() + { + if (!App::$user || !App::$user->isAdmin) { + App::error404(); + } + + if (!(isset($_POST['id']) && isset($_POST['title']) && isset($_POST['text']))) { + App::error404(); + } + + $id = (int) $_POST['id']; + $title = strip_tags($_POST['title']); + $text = str_replace(array('<','>'), array('<','>'), $_POST['text']); + + $html = strip_tags($_POST['text']); + $html = str_replace(array('<','>',"'"), array('<','>','′'), $html); + $html = Markdown::processing($html); + $html = nl2br($html); + + $allowComments = (int) isset($_POST['allowComments']); + + $article = $id ? Article::model()->getByPK($id) : new Article(); + + if (!$article) { + App::error404(); + } + + if ($id == 0) { + $article->author = App::$user->id; + } + + $article->title = $title; + $article->text = $text; + $article->html = $html; + $article->photoId = Helper::getFirstImg($text); + $article->allowComments = $allowComments; + $article->save(); + + App::redirect('/articles'); + } + + static function actionMarkdown() + { + if (isset($_POST['text']) ){ + $html = strip_tags($_POST['text']); + $html = str_replace(array('<','>',"'"), array('<','>','′'), $html); + $html = Markdown::processing($html); + $html = nl2br($html); + $html = Helper::replaceLinks($html, 'html'); + $html = Helper::replaceImgs($html, 'html'); + + print $html; + } + + die; + } +} diff --git a/ground/controllers/ImagesController.php b/ground/controllers/ImagesController.php index 860ea85..28671d9 100644 --- a/ground/controllers/ImagesController.php +++ b/ground/controllers/ImagesController.php @@ -45,4 +45,38 @@ class ImagesController extends Controller // print $photo; } + static function actionLoadPhoto() + { + if (isset($_FILES) && !empty($_FILES) && App::$user) { + $userId = App::$user->id; + $uploaddir = App::getBasedir() . '../public/photos/articles/'; + $fileName = (string)$_FILES['photo']['name']; + $temp = pathinfo($fileName); + $extension = strtolower($temp['extension']); + + if (array_search($extension, array('jpg','jpeg','png')) === FALSE || getimagesize($_FILES['photo']['tmp_name']) === false) { + print 'error'; + die; + } + + $photo = $userId . strtolower('_' . substr(md5($fileName . time()), 0, 5) . '.' . $extension); + if (move_uploaded_file($_FILES['photo']['tmp_name'], $uploaddir . $photo)) { + ArticlePhotos::model()->add(array( + 'name' => $photo, + 'owner' => $userId, + 'caption' => isset($_POST['caption'])?$_POST['caption']:'', + 'uploaded' => time(), + )); + + Image::createAllSizes($photo, true, 'articles/'); + + die($photo); + } + } else { + App::error404(); + } + + die; + } + } diff --git a/ground/controllers/IndexController.php b/ground/controllers/IndexController.php index a5e3208..0c28402 100644 --- a/ground/controllers/IndexController.php +++ b/ground/controllers/IndexController.php @@ -56,12 +56,9 @@ class IndexController extends Controller $favorites = Favorite::model()->getAllMy(); } + App::setConfig('title', App::$defaultTitle); + self::addVar('isAdmin', (int) (App::$user && App::$user->isAdmin == 1)); - - $res = App::DB()->query("SELECT COUNT(`id`) pointsCount FROM `points` where `moderate` = 1")->fetch(PDO::FETCH_ASSOC); - App::setConfig('title', $res['pointsCount'] . ' или даже больше поводов не сидеть дома'); - self::addVar('pointsCount', $res['pointsCount']); - self::addVar('pointLat', 0); self::addVar('pointLng', 0); @@ -85,12 +82,12 @@ class IndexController extends Controller 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'] = 'Загляните сюда: http://vk.com/wikipoints Случайная точка на карте - лучший способ узнать что-то новое!'; - $og['site_name'] = 'WikiPoints - ' . $res['pointsCount'] . ' или даже больше поводов не сидеть дома'; + $og['title'] = 'Случайная точка на карте wikipoints.ru'; + $og['description'] = 'Случайная точка на карте – это лучший способ узнать что-то новое! – wikipoints.ru'; + $og['site_name'] = App::$defaultTitle; $og['type'] = 'article'; $og['url'] = 'http://wikipoints.ru/?point=random'; - $og['image'] = 'http://wikipoints.ru/img/compas.jpg'; + $og['image'] = 'http://wikipoints.ru/img/logo.png'; } self::render('indexTemplate.php', array( @@ -148,6 +145,12 @@ class IndexController extends Controller { $xml = new SimpleXMLElement(''); + $url = $xml->addChild('url'); + $url->addChild('loc', 'http://wikipoints.ru/'); + $url->addChild('lastmod', date("Y-m-d")); + $url->addChild('changefreq', "daily"); + $url->addChild('priority', "0.9"); + $articles = Article::model()->getAll(array('order' => 'ID DESC', 'asArray' => true)); foreach ($articles as $article) { $url = $xml->addChild('url'); @@ -161,7 +164,7 @@ class IndexController extends Controller foreach ($points as $point) { $url = $xml->addChild('url'); $url->addChild('loc', 'http://wikipoints.ru/page/point/id/' . $point['id']); - $url->addChild('lastmod', date("Y-m-d", $point['date'])); + $url->addChild('lastmod', date("Y-m-d", $point['dateEdit'])); $url->addChild('changefreq', "weekly"); $url->addChild('priority', "0.8"); } diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 1238e2e..be130f9 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -29,13 +29,14 @@ class JsonController extends Controller $result = array(); foreach ($points as $point) { - $id = $point->id; - $result[$id]['id'] = $point->id; - $result[$id]['name'] = $point->name; - $result[$id]['lat'] = $point->lat; - $result[$id]['lng'] = $point->lng; - $result[$id]['categoryId'] = $point->categoryId; - $result[$id]['moderate'] = $point->moderate ? 'show' : 'hide'; + $tempPoint['id'] = $point->id; + $tempPoint['name'] = $point->name; + $tempPoint['lat'] = $point->lat; + $tempPoint['lng'] = $point->lng; + $tempPoint['categoryId'] = $point->categoryId; + $tempPoint['moderate'] = $point->moderate ? 'show' : 'hide'; + + $result[] = $tempPoint; } self::renderPartial('json.php', array( @@ -53,7 +54,7 @@ class JsonController extends Controller $point = Point::model()->getByPK($id); $point->descriptionHtml = nl2br($point->description); - $point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml, '/?point='); + $point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml, 'js'); $point->name = htmlspecialchars($point->name); $point->moderate = $point->moderate ? 'show' : 'hide'; $imgs = $point->photos; @@ -93,7 +94,7 @@ class JsonController extends Controller */ static function actionCategories() { - $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true)); + $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true, 'noKeys' => true)); self::renderPartial('json.php', array( 'data' => $categories, @@ -185,6 +186,14 @@ class JsonController extends Controller App::redirect('/?point=' . $id); } + if (isset($_POST['name'])) { + $_POST['name'] = strip_tags($_POST['name']); + } + + if (isset($_POST['description'])) { + $_POST['description'] = strip_tags($_POST['description']); + } + if (!( isset($_POST['name']) && $_POST['name'] && strlen($_POST['name']) > 1 )) $errors[1] = 'Неверное название точки'; if (!( isset($_POST['img']) && (int) $_POST['img'])) @@ -254,6 +263,10 @@ class JsonController extends Controller static function actionSaveRoute() { + if (!(isset($_POST['name']) && $_POST['name'] && isset($_POST['points']) && $_POST['points'])) { + App::error404('Неправильное значение!'); + } + $request = array( 'author' => App::$user->id, 'date' => time(), @@ -300,10 +313,13 @@ class JsonController extends Controller $res = @file_get_contents('http://geocode-maps.yandex.ru/1.x/?format=json&geocode=' . urlencode($address)); $res = json_decode($res, true); - if (isset($res['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos'])) + if (isset($res['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos'])) { $point = explode(' ', $res['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos']); - else + } else if (isset($res['response']['GeoObjectCollection']['metaDataProperty']['GeocoderResponseMetaData']['Point']['pos'])) { + $point = explode(' ', $res['response']['GeoObjectCollection']['metaDataProperty']['GeocoderResponseMetaData']['Point']['pos']); + } else { $point = array(0, 0); + } $coords = array(); $coords['lat'] = $point[1]; @@ -336,6 +352,7 @@ class JsonController extends Controller $results = array(); if ($search) { + App::log('searchQueries', $search); // ====== POINTS ============ $points = Point::model()->searchByString($search); if (!empty($points)) { @@ -344,14 +361,14 @@ class JsonController extends Controller } } - if (count($results) < 10) { + if (count($results) < 10 && strlen($search) > 5) { // ====== YANDEX ============ $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'http://geocode-maps.yandex.ru/1.x/?geocode=' . urlencode($search)); + curl_setopt($ch, CURLOPT_URL, 'https://geocode-maps.yandex.ru/1.x/?geocode=' . urlencode($search)); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $out = null; - $out = curl_exec($ch); // выполняем запрос curl - обращаемся к сервера php.su + $out = curl_exec($ch); if (!empty($out)) { $obj = simplexml_load_string($out); @@ -366,6 +383,39 @@ class JsonController extends Controller $lng = $coords[0]; $results[] = array('value' => $name, 'data' => "/?lat=$lat&lng=$lng&zoom=13"); } + } else if (isset($obj->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->Point)) { + $coords = explode(' ', (string) $obj->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->Point->pos); + $lat = $coords[1]; + $lng = $coords[0]; + $name = "Координаты N°" . $lat . ' E°' . $lng; + $results[] = array('value' => $name, 'data' => "/?lat=$lat&lng=$lng&zoom=13"); + } + } + } + curl_close($ch); + } + + if (count($results) < 10 && strlen($search) > 5) { + // ====== GOOGLE ============ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, 'https://maps.googleapis.com/maps/api/geocode/json?language=ru&key=AIzaSyDuWmguxO35oV9WGc6D8xUPvQBaUS4kt78&address=' . urlencode($search)); + curl_setopt($ch, CURLOPT_TIMEOUT, 3); + curl_setopt($ch, CURLOPT_REFERER, "http://wikipoints.ru"); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + $out = null; + $out = curl_exec($ch); + + if (!empty($out)) { + $obj = json_decode($out); + if ((string) $obj->status == 'OK') { + $count = count($obj->results); + if ($count > 0) { + for ($index = 0; $index < $count && $index < 5 && count($results) < 25; $index++) { + $name = (string) $obj->results[$index]->formatted_address; + $lat = (string) $obj->results[$index]->geometry->location->lat; + $lng = (string) $obj->results[$index]->geometry->location->lng; + $results[] = array('value' => $name, 'data' => "/?lat=$lat&lng=$lng&zoom=13"); + } } } } @@ -390,7 +440,7 @@ class JsonController extends Controller } self::renderPartial('modals/article.php', array( 'title' => $article->title, - 'text' => $article->text, + 'text' => $article->html, )); } } @@ -404,7 +454,25 @@ class JsonController extends Controller } self::renderPartial('modals/pointAgreement.php', array( 'title' => $article->title, - 'text' => $article->text, + 'text' => $article->html, + )); + } + + static function actionGetmyartphotos() + { + if (!App::$user) { + App::error404(); + } + + self::renderPartial('json.php', array( + 'data' => ArticlePhotos::model()->getAll( + array( + 'where' => '`owner` = ' . (int) App::$user->id, + 'order' => '`id` DESC', + 'asArray' => true, + 'noKeys' => true + ) + ) )); } diff --git a/ground/controllers/PageController.php b/ground/controllers/PageController.php index 7f558c5..4189fba 100644 --- a/ground/controllers/PageController.php +++ b/ground/controllers/PageController.php @@ -63,8 +63,7 @@ class PageController extends Controller $result[$id]['categoryIcon'] = $categories[$point->categoryId]->icon; } - $res = App::DB()->query("SELECT COUNT(`id`) pointsCount FROM `points`")->fetch(PDO::FETCH_ASSOC); - App::setConfig('title', $res['pointsCount'] . ' или даже больше поводов не сидеть дома'); + App::setConfig('title', App::$defaultTitle); self::render('pointsTemplate.php', array( 'categories' => $categories, @@ -115,7 +114,7 @@ class PageController extends Controller $point->descriptionHtml = nl2br($point->description); $point->name = htmlspecialchars($point->name); - App::setConfig('title', $point->name . ' - wikipoints.ru'); + App::setConfig('title', $point->name . ' – wikipoints.ru'); self::addVar('pointLat', $point->lat); self::addVar('pointLng', $point->lng); self::addVar('pointId', $point->id); @@ -124,7 +123,7 @@ class PageController extends Controller $point->categoryIcon = $categories[$point->categoryId]['icon']; $point->categoryName = $categories[$point->categoryId]['name']; - $point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml); + $point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml, 'html'); // preg_match_all("/.*?(([.?!](?:\s|$))|$)/s", $point->descriptionHtml, $items); preg_match_all("/.*?((([^.?!\s]{3,}?)[.?!](?:\s|$))|$)/s", $point->descriptionHtml, $items); $point->inFavorites = Favorite::model()->checkIsMy($pointId); @@ -192,12 +191,14 @@ class PageController extends Controller App::error404(); } - App::setConfig('title', $article->title . ' - wikipoints.ru'); + App::setConfig('title', $article->title . ' – wikipoints.ru'); + $article->html = Helper::replaceLinks($article->html, 'html'); + $article->html = Helper::replaceImgs($article->html, 'html'); self::render('article.php', array( 'article' => $article, 'randomPoint' => Point::model()->getRandom(), -// 'og' => Helper::buildOG($point), + 'og' => Helper::buildArticleOG($article), // 'user' => App::$user, )); } else { @@ -205,6 +206,19 @@ class PageController extends Controller } } + static function actionMyprofile() + { + $userId = App::$user ? App::$user->id : 0; + + die($userId); + } + +// static function actionProfile() +// { +// $userId = (int) App::getParam('user'); +// +// } + static function actionVkpoint() { $pointId = (int) App::getParam('id'); @@ -220,7 +234,7 @@ class PageController extends Controller $categories = Category::model()->getAll(array('order' => 'ord ASC', 'asArray' => true)); - $point->descriptionHtml = Helper::replaceLinks($point->descriptionHtml); + $point->description = Helper::replaceLinks($point->description); self::renderPartial('vkPoint.php', array( 'point' => $point, diff --git a/ground/models/Article.php b/ground/models/Article.php index 4724cbf..9dde028 100644 --- a/ground/models/Article.php +++ b/ground/models/Article.php @@ -15,4 +15,20 @@ class Article extends Model return new self(); } + public function getImg($size = 'small') + { + $imgId = (int)$this->photoId; + if ($imgId) { + + $img = ArticlePhotos::model()->getByPK($imgId); + + if ($img) { + return '/photos/articles/' . $size . '/' . $img->name; + } + + } + + return '/img/logo.png'; + } + } diff --git a/ground/models/ArticlePhotos.php b/ground/models/ArticlePhotos.php new file mode 100644 index 0000000..e70f7f0 --- /dev/null +++ b/ground/models/ArticlePhotos.php @@ -0,0 +1,18 @@ +_tableName_ = 'articlePhotos'; + parent::__construct($fromArray); + $this->setRelation('authorUser', 'owner', 'User', 'id', self::TO_ONE); + } + + static function model() + { + return new self(); + } + +} diff --git a/ground/models/Photo.php b/ground/models/Photo.php index 26d04fc..3446570 100644 --- a/ground/models/Photo.php +++ b/ground/models/Photo.php @@ -16,4 +16,13 @@ class Photo extends Model return new self(); } + /** + * Возвращает ссылку на исходное изображение (если она есть) + * @return type + */ + function getOriginalLink() + { + $link = $this->link; + return $link ? $link->url : ''; + } } diff --git a/ground/views/article.php b/ground/views/article.php index 66b1b0e..e166354 100644 --- a/ground/views/article.php +++ b/ground/views/article.php @@ -8,9 +8,7 @@
- text; - ?> + html; ?>
diff --git a/ground/views/articles/edit.php b/ground/views/articles/edit.php new file mode 100644 index 0000000..6cf3e52 --- /dev/null +++ b/ground/views/articles/edit.php @@ -0,0 +1,142 @@ + +
+ +
+
+
+

Редактирование статьи

+
+ Вернуться: к списку статей / на карту. +
+
+
+ + +
+ + +
+ +
+ + + + + +
+ + + + +
+
+ + *текст* **текст** ***текст*** http://ссылка.ру # заголвок1 ## заголовк2 ### заголовк3 [#512|ссылка на точку 512] +
+ +
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+ +
+
+ +
+
+
+
+ +
+
+ diff --git a/ground/views/articles/index.php b/ground/views/articles/index.php new file mode 100644 index 0000000..0cb2b58 --- /dev/null +++ b/ground/views/articles/index.php @@ -0,0 +1,19 @@ +
+ +
+ +
diff --git a/ground/views/indexTemplate.php b/ground/views/indexTemplate.php index 69b9e8d..6195364 100644 --- a/ground/views/indexTemplate.php +++ b/ground/views/indexTemplate.php @@ -36,6 +36,9 @@ if (App::$user) { Как пользоваться
Легенда
Список точек
+ isAdmin): ?> + Статьи
+
Случайная точка @@ -45,7 +48,7 @@ if (App::$user) {

Карты

map Quest
-
Генштаб от маршруты.ру
+
Генштаб от маршруты.ру
Google maps
Яндекс.Карты
Open Street Map
@@ -111,6 +114,7 @@ if (App::$user) {
$categories), true) : '' ?> + $categories), true) ?> @@ -121,21 +125,3 @@ if (App::$user) { var categoryArray = ''; - diff --git a/ground/views/layout.php b/ground/views/layout.php index e64d533..d60c943 100644 --- a/ground/views/layout.php +++ b/ground/views/layout.php @@ -4,58 +4,61 @@ prefix="og: http://ogp.me/ns#" xmlns:fb="http://ogp.me/ns/fb#" xmlns:og="http://ogp.me/ns#"> - - <?= App::getConfig('title') ?> + + <?= App::getConfig('title') ?> - - - - - - - - - - - + + + + + + + + + + + + - - - - - - -
- -
- - - - + + + + + + +
+ +
- + + + - - - - - + - - - - - - \ No newline at end of file + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ground/views/layoutPage.php b/ground/views/layoutPage.php index 98c095a..531dc21 100644 --- a/ground/views/layoutPage.php +++ b/ground/views/layoutPage.php @@ -4,72 +4,74 @@ prefix="og: http://ogp.me/ns#" xmlns:fb="http://ogp.me/ns/fb#" xmlns:og="http://ogp.me/ns#"> - - <?= App::getConfig('title') ?> + + <?= App::getConfig('title') ?> - - - - - + + + + + - - - - - + + + + + - - - + + + - - - - - - - - + + + + + + + + - + - - - - - - -
- -
- - - - - - \ No newline at end of file + height = width / 4 * 3; + $('.pagePoinsNearCards').width(width); + $('.pagePoinsNearCardsImg').width(width); + $('.pagePoinsNearCards').height(height); + $('.pagePoinsNearCardsImg').height(height); + } + + setSizeForAdditional(); + + $(window).resize(function () { + setSizeForAdditional(); + }); + + \ No newline at end of file diff --git a/ground/views/layoutPrint.php b/ground/views/layoutPrint.php index 1e59113..2ab78d4 100644 --- a/ground/views/layoutPrint.php +++ b/ground/views/layoutPrint.php @@ -1,32 +1,27 @@ - - <?= App::getConfig('title') ?> - - - - - - - - - - - - - - - - - + + <?= App::getConfig('title') ?> + + + + + - - - + + + + + + + + + +

WikiPoints.ru


diff --git a/ground/views/modals/addPoint.php b/ground/views/modals/addPoint.php index f5e2020..6aeb6e4 100644 --- a/ground/views/modals/addPoint.php +++ b/ground/views/modals/addPoint.php @@ -74,71 +74,3 @@ - diff --git a/ground/views/point.php b/ground/views/point.php index 6158161..a9cfaaa 100644 --- a/ground/views/point.php +++ b/ground/views/point.php @@ -45,7 +45,7 @@ $index = 0; - + diff --git a/ground/views/vkPoint.php b/ground/views/vkPoint.php index 3e10837..6b0988e 100644 --- a/ground/views/vkPoint.php +++ b/ground/views/vkPoint.php @@ -9,4 +9,4 @@ foreach ($photos as $photo) {
Продолжить чтение и посмотреть на карте: http://wikipoints.ru/page/point/id/id ?>

-#wikipoints #выходные #путешествия #туризм # # # # +#wikipoints # # # # # # # # # # # # # # # # #выходные #путешествия #путешествие #туризм #weekend #travels #journey #tourism diff --git a/logs/.gitKeep b/logs/.gitKeep new file mode 100644 index 0000000..e69de29 diff --git a/public/css/style.css b/public/css/style.css index 1a62d40..4407528 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -93,6 +93,8 @@ div#box {background-image: url('/img/back.png'); background-repeat: no-repeat; b .pagePoinsNearCards {display: inline-block; overflow: hidden; padding: 0 2px 4px 2px;width: 186px; height: 139px;} .pagePoinsNearCardsImg {width: 186px; height: 139px;} +#photobank img {margin: 2px; border: solid 1px white;} +img.imageInArticle {border: solid 3px white;} /* -------------------------------------------*/ /* ------------- ADAPTIVE --------------------*/ diff --git a/public/favicon.ico b/public/favicon.ico index 5d0cd5e..a13252a 100644 Binary files a/public/favicon.ico and b/public/favicon.ico differ diff --git a/public/img/touch-icon-ipad-retina.png b/public/img/touch-icon-ipad-retina.png index 43caae4..91514cf 100644 Binary files a/public/img/touch-icon-ipad-retina.png and b/public/img/touch-icon-ipad-retina.png differ diff --git a/public/img/touch-icon-ipad.png b/public/img/touch-icon-ipad.png index 442bf9b..d38dbf7 100644 Binary files a/public/img/touch-icon-ipad.png and b/public/img/touch-icon-ipad.png differ diff --git a/public/img/touch-icon-iphone-retina.png b/public/img/touch-icon-iphone-retina.png index 238476b..854ba25 100644 Binary files a/public/img/touch-icon-iphone-retina.png and b/public/img/touch-icon-iphone-retina.png differ diff --git a/public/img/touch-icon-iphone.png b/public/img/touch-icon-iphone.png index a506317..afdb7de 100644 Binary files a/public/img/touch-icon-iphone.png and b/public/img/touch-icon-iphone.png differ diff --git a/public/js/app.js b/public/js/app.js index 245e661..3ef6fd8 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -146,7 +146,7 @@ window.addEventListener('popstate', function(e) setStatus(statusMovingInHistory); if (e.state.hasOwnProperty('pointId')) { - points[e.state.pointId].openPopup(); + showInfo(e.state.pointId, false, true); } else if (e.state.hasOwnProperty('zoom')) { diff --git a/public/js/map.js b/public/js/map.js index 6faf704..bfccb70 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -63,7 +63,7 @@ ymaps.ready(function () { */ function init(lat, lng) { myMap = L.map('map', {zoomControl: false}).setView([lat, lng], defaultZoom); - markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 45}); + markers = new L.MarkerClusterGroup({showCoverageOnHover: false, maxClusterRadius: 30}); layers['quest'] = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', maxZoom: 18}); layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery ©', maxZoom: 18}); @@ -111,7 +111,7 @@ function init(lat, lng) { myMap.on('moveend', function (e) { if (!myMap._popup && $('#boxRoute').css('display') == 'none' && status != statusMovingInHistory) { - document.title = pointsCount + ' или даже больше поводов не сидеть дома'; + document.title = 'Лучшие выходные – это выходные в путешествии! – wikipoints.ru'; history.pushState({lat: myMap.getCenter().lat, lng: myMap.getCenter().lng, zoom: myMap.getZoom()}, document.title, "/?lat=" + myMap.getCenter().lat + "&lng=" + myMap.getCenter().lng + "&zoom=" + myMap.getZoom()); } @@ -189,9 +189,9 @@ function initPoints(useBounds) bounds: bounds }, success: function (data) { - for (var k in data) { - if (typeof points[k] == 'undefined') { - markers.addLayer(constructPoint(data[k])); + for(var i=0; iOpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox', maxZoom: 18}); @@ -89,12 +89,12 @@ function initPoints() $.ajax({ url: "/json/points/", success: function (data) { - for (var k in data) { - if (k == pointId) { - constructPoint(data[k]); - points[k].addTo(myMap); + for(var i=0; i + + + + + + + + + image/svg+xml + + + + + + + + + + + + +