AUTOFORMAT
This commit is contained in:
parent
c70d82c57d
commit
29fba9e036
|
|
@ -23,6 +23,7 @@ function __autoload($className)
|
|||
|
||||
class App
|
||||
{
|
||||
|
||||
private static $url = array();
|
||||
private static $controller = 'IndexController';
|
||||
private static $action = 'actionIndex';
|
||||
|
|
@ -44,10 +45,8 @@ class App
|
|||
self::$action = isset(self::$url[2]) && self::$url[2] ? 'action' . ucfirst(self::$url[2]) : self::$action;
|
||||
|
||||
// Разбираем параметры из урла
|
||||
if ((count(self::$url) > 3) && (self::$url[3]))
|
||||
{
|
||||
for ($index = 3; $index < count(self::$url); $index = $index + 2)
|
||||
{
|
||||
if ((count(self::$url) > 3) && (self::$url[3])) {
|
||||
for ($index = 3; $index < count(self::$url); $index = $index + 2) {
|
||||
$paramName = self::$url[$index];
|
||||
$paramValue = isset(self::$url[$index + 1]) && self::$url[$index + 1] ? self::$url[$index + 1] : NULL;
|
||||
self::$urlParams[$paramName] = $paramValue;
|
||||
|
|
@ -73,8 +72,7 @@ class App
|
|||
|
||||
self::fillRequest();
|
||||
|
||||
if (method_exists($controller, $action))
|
||||
{
|
||||
if (method_exists($controller, $action)) {
|
||||
$controller::$action();
|
||||
// if (method_exists($controller, '__construct')) {
|
||||
// $class = new $controller();
|
||||
|
|
@ -82,23 +80,18 @@ class App
|
|||
// } else {
|
||||
// $controller::$action();
|
||||
// }
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
self::error404();
|
||||
}
|
||||
}
|
||||
|
||||
public static function DB()
|
||||
{
|
||||
if (self::$DB === NULL && self::getConfig('DB'))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (self::$DB === NULL && self::getConfig('DB')) {
|
||||
try {
|
||||
$confDB = self::getConfig('DB');
|
||||
self::$DB = new PDO('mysql:host=' . $confDB['host'] . ';dbname=' . $confDB['dbname'] . ';charset=utf8;', $confDB['user'], $confDB['password']);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
|
@ -116,12 +109,10 @@ class App
|
|||
// Пытаемся восстановить пользователя из сессии
|
||||
public static function userInit()
|
||||
{
|
||||
if (isset($_SESSION['user_id']) && isset($_SESSION['user_key']) && $_SESSION['user_id'] && $_SESSION['user_key'] )
|
||||
{
|
||||
if (isset($_SESSION['user_id']) && isset($_SESSION['user_key']) && $_SESSION['user_id'] && $_SESSION['user_key']) {
|
||||
$user = User::model()->getByPK((int) $_SESSION['user_id']);
|
||||
|
||||
if ( $user && md5($user->uid) == $_SESSION['user_key'] )
|
||||
{
|
||||
if ($user && md5($user->uid) == $_SESSION['user_key']) {
|
||||
App::$user = $user;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,19 +9,16 @@ abstract class Controller
|
|||
static private $og = array();
|
||||
static private $vars = array();
|
||||
|
||||
|
||||
static function addStyle($name)
|
||||
{
|
||||
if (array_search($name, self::$styles) === FALSE )
|
||||
{
|
||||
if (array_search($name, self::$styles) === FALSE) {
|
||||
self::$styles[] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
static function addScript($name)
|
||||
{
|
||||
if (array_search($name, self::$scripts) === FALSE )
|
||||
{
|
||||
if (array_search($name, self::$scripts) === FALSE) {
|
||||
self::$scripts[] = $name;
|
||||
}
|
||||
}
|
||||
|
|
@ -43,21 +40,18 @@ abstract class Controller
|
|||
if (!file_exists(App::getBasedir() . 'views/' . $template))
|
||||
return 'Template not found';
|
||||
|
||||
if ($return)
|
||||
{
|
||||
if ($return) {
|
||||
$oldContentFormBuffer_temp = ob_get_clean();
|
||||
ob_start();
|
||||
}
|
||||
|
||||
if ( $data && is_array($data) )
|
||||
{
|
||||
if ($data && is_array($data)) {
|
||||
extract($data);
|
||||
}
|
||||
|
||||
include App::getBasedir() . 'views/' . $template;
|
||||
|
||||
if ($return)
|
||||
{
|
||||
if ($return) {
|
||||
$newContentFormBuffer_temp = ob_get_clean();
|
||||
ob_start();
|
||||
echo $oldContentFormBuffer_temp;
|
||||
|
|
@ -86,11 +80,9 @@ abstract class Controller
|
|||
'data' => $data,
|
||||
), true);
|
||||
|
||||
if ($return)
|
||||
{
|
||||
if ($return) {
|
||||
return $result;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
echo $result;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Coord
|
||||
{
|
||||
|
||||
static function dergeeToMinute($input)
|
||||
{
|
||||
$input = abs($input);
|
||||
|
|
@ -11,4 +12,5 @@ class Coord
|
|||
|
||||
return $degree . '°' . substr($minute, 0, 6) . '\'';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Helper
|
||||
{
|
||||
|
||||
public static function boolval($var)
|
||||
{
|
||||
return (bool) $var;
|
||||
|
|
@ -11,21 +12,17 @@ class Helper
|
|||
{
|
||||
preg_match_all("(\[#(\d+)>?(.*?)\])", $string, $links);
|
||||
$links = isset($links[0]) ? $links[0] : FALSE;
|
||||
if ($links)
|
||||
{
|
||||
foreach ($links as $link)
|
||||
{
|
||||
if ($links) {
|
||||
foreach ($links as $link) {
|
||||
$idAndLink = mb_substr($link, 2, -1);
|
||||
$idAndLink = explode('>', $idAndLink);
|
||||
|
||||
$linkId = $idAndLink[0];
|
||||
$linkName = isset($idAndLink[1]) ? $idAndLink[1] : '<span class="glyphicon glyphicon-link"></span>';
|
||||
|
||||
if ($linkId)
|
||||
{
|
||||
if ($linkId) {
|
||||
$linkPoint = Point::model()->getByPK($linkId);
|
||||
if ($linkPoint->id)
|
||||
{
|
||||
if ($linkPoint->id) {
|
||||
$linkPoint->name = str_replace('"', 'ʺ', $linkPoint->name);
|
||||
$string = str_replace($link, '<a href="' . $linkTemplate . $linkId . '" title="' . $linkPoint->name . '">' . $linkName . '</a>', $string);
|
||||
}
|
||||
|
|
@ -49,4 +46,5 @@ class Helper
|
|||
|
||||
return $og;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,10 @@ class Image
|
|||
*/
|
||||
public static function toBase64($path)
|
||||
{
|
||||
if ($path)
|
||||
{
|
||||
if ($path) {
|
||||
$type = pathinfo($path, PATHINFO_EXTENSION);
|
||||
|
||||
if (!$type)
|
||||
{
|
||||
if (!$type) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -38,8 +36,7 @@ class Image
|
|||
$uploaddir = $pathInfo['dirname'] . '/photos/';
|
||||
$watermarkDir = App::getBasedir() . 'watermarks/';
|
||||
|
||||
foreach ($sizes as $dir => $size)
|
||||
{
|
||||
foreach ($sizes as $dir => $size) {
|
||||
$watermark = isset($size[3]) ? $watermarkDir . $size[3] : '';
|
||||
self::imgResize(
|
||||
$uploaddir . $imgName, // Source - original image
|
||||
|
|
@ -57,10 +54,7 @@ class Image
|
|||
public static function createCustomSize($imgFullName, $x, $y)
|
||||
{
|
||||
self::imgResize(
|
||||
$imgFullName,
|
||||
null,
|
||||
$x,
|
||||
$y
|
||||
$imgFullName, null, $x, $y
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -108,8 +102,7 @@ class Image
|
|||
imagefill($idest, 0, 0, 0xFFFFFF);
|
||||
imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]);
|
||||
|
||||
if ($watermark)
|
||||
{
|
||||
if ($watermark) {
|
||||
$stamp = imagecreatefrompng($watermark);
|
||||
|
||||
$marge_right = 10;
|
||||
|
|
|
|||
|
|
@ -52,8 +52,7 @@ abstract class Model
|
|||
{
|
||||
$this->_primaryKey_ = $this->getPk();
|
||||
|
||||
if ($fromArray)
|
||||
{
|
||||
if ($fromArray) {
|
||||
$this->setValues($fromArray);
|
||||
}
|
||||
}
|
||||
|
|
@ -67,26 +66,21 @@ abstract class Model
|
|||
{
|
||||
$this->_vals_[$name] = $value;
|
||||
|
||||
if ($name == $this->_primaryKey_)
|
||||
{
|
||||
if ($name == $this->_primaryKey_) {
|
||||
$this->_id_ = $value;
|
||||
}
|
||||
}
|
||||
|
||||
function __get($name)
|
||||
{
|
||||
if (isset($this->_vals_[$name]))
|
||||
{
|
||||
if (isset($this->_vals_[$name])) {
|
||||
return $this->_vals_[$name];
|
||||
} else
|
||||
{
|
||||
if (isset($this->_relations_[$name]))
|
||||
{
|
||||
} else {
|
||||
if (isset($this->_relations_[$name])) {
|
||||
extract($this->_relations_[$name]);
|
||||
$model = new $targetModel;
|
||||
|
||||
switch ($relationType)
|
||||
{
|
||||
switch ($relationType) {
|
||||
case self::TO_ONE:
|
||||
return $model::model()->getOne($targetField, $this->$localField);
|
||||
break;
|
||||
|
|
@ -159,8 +153,7 @@ abstract class Model
|
|||
$ready = array();
|
||||
|
||||
$calledClass = get_called_class();
|
||||
while ($res && $row = $res->fetch(PDO::FETCH_ASSOC))
|
||||
{
|
||||
while ($res && $row = $res->fetch(PDO::FETCH_ASSOC)) {
|
||||
$ready[$row[$this->_primaryKey_]] = isset($params['asArray']) && $params['asArray'] ? $row : new $calledClass($row);
|
||||
}
|
||||
|
||||
|
|
@ -202,32 +195,27 @@ abstract class Model
|
|||
unset($values[$this->_primaryKey_]);
|
||||
|
||||
$q = array();
|
||||
foreach ($values as $val)
|
||||
{
|
||||
foreach ($values as $val) {
|
||||
$q[] = '?';
|
||||
}
|
||||
|
||||
var_dump('INSERT INTO `' . $this->_tableName_ . '` (`' . implode('`, `', array_keys($values)) . '`) VALUES (' . implode(', ', array_values($q)) . ') ');die;
|
||||
var_dump('INSERT INTO `' . $this->_tableName_ . '` (`' . implode('`, `', array_keys($values)) . '`) VALUES (' . implode(', ', array_values($q)) . ') ');
|
||||
die;
|
||||
$res = App::DB()->prepare_query('INSERT INTO `' . $this->_tableName_ . '` (`' . implode('`, `', array_keys($values)) . '`) VALUES (' . implode(', ', array_values($q)) . ') ', self::arrayWithTypes($values));
|
||||
|
||||
if ($res)
|
||||
{
|
||||
if ($res) {
|
||||
throw new Exception('MySQL error #' . $res->errno . ' - ' . $res->error);
|
||||
}
|
||||
|
||||
return $this->getByPK(App::DB()->insert_id);
|
||||
}
|
||||
|
||||
|
||||
function add($values)
|
||||
{
|
||||
$request = App::DB()->prepare('INSERT INTO ' . $this->_tableName_ . ' (' . implode(',', array_keys($values)) . ') values (:' . implode(', :', array_keys($values)) . ')');
|
||||
if ( $request->execute((array) $values) )
|
||||
{
|
||||
if ($request->execute((array) $values)) {
|
||||
return $this->getByPK(App::DB()->lastInsertId());
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -238,8 +226,7 @@ abstract class Model
|
|||
*/
|
||||
function setValues($values)
|
||||
{
|
||||
if (isset($values[$this->_primaryKey_]))
|
||||
{
|
||||
if (isset($values[$this->_primaryKey_])) {
|
||||
$this->_id_ = $values[$this->_primaryKey_];
|
||||
}
|
||||
|
||||
|
|
@ -252,14 +239,10 @@ abstract class Model
|
|||
*/
|
||||
function save2()
|
||||
{
|
||||
if (!$this->_id_ || !$this->_vals_)
|
||||
{
|
||||
if ($this->_vals_)
|
||||
{
|
||||
if (!$this->_id_ || !$this->_vals_) {
|
||||
if ($this->_vals_) {
|
||||
return $this->add($this->_vals_);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
@ -276,14 +259,10 @@ abstract class Model
|
|||
|
||||
function save()
|
||||
{
|
||||
if (!$this->_id_ || !$this->_vals_)
|
||||
{
|
||||
if ($this->_vals_)
|
||||
{
|
||||
if (!$this->_id_ || !$this->_vals_) {
|
||||
if ($this->_vals_) {
|
||||
return $this->add($this->_vals_);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,18 +44,15 @@ class IndexController extends Controller
|
|||
$category = Category::model()->getAll(array('order' => 'ord ASC'));
|
||||
|
||||
$routes = array();
|
||||
if (App::$user && App::$user->id)
|
||||
{
|
||||
if (App::$user && App::$user->id) {
|
||||
$routes = Route::model()->getByAuthor(App::$user->id);
|
||||
self::addVar('user', App::$user->id);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
self::addVar('user', '0');
|
||||
}
|
||||
|
||||
$favorites = array();
|
||||
if (App::$user && App::$user->id)
|
||||
{
|
||||
if (App::$user && App::$user->id) {
|
||||
$favorites = Favorite::model()->getAllMy();
|
||||
}
|
||||
|
||||
|
|
@ -74,8 +71,7 @@ class IndexController extends Controller
|
|||
}
|
||||
|
||||
$og = array();
|
||||
if (isset($_GET['point']) && $_GET['point'] && is_numeric($_GET['point']))
|
||||
{
|
||||
if (isset($_GET['point']) && $_GET['point'] && is_numeric($_GET['point'])) {
|
||||
$id = (int) $_GET['point'];
|
||||
|
||||
$point = Point::model()->getByPK($id);
|
||||
|
|
@ -88,8 +84,7 @@ 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')
|
||||
{
|
||||
} 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'] . ' или даже больше поводов не сидеть дома';
|
||||
|
|
@ -130,8 +125,7 @@ class IndexController extends Controller
|
|||
|
||||
$user = User::model()->getByUID($uLoginUser['identity']);
|
||||
|
||||
if (!$user->id)
|
||||
{
|
||||
if (!$user->id) {
|
||||
$user = $user->add(array(
|
||||
'uid' => $uLoginUser['identity'],
|
||||
'nick' => $uLoginUser['nickname'],
|
||||
|
|
@ -141,8 +135,7 @@ class IndexController extends Controller
|
|||
'photo' => $uLoginUser['photo_big'],
|
||||
));
|
||||
|
||||
if (!$user)
|
||||
{
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -156,8 +149,7 @@ class IndexController extends Controller
|
|||
$xml = new SimpleXMLElement('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"/>');
|
||||
|
||||
$articles = Article::model()->getAll(array('order' => 'ID DESC', 'asArray' => true));
|
||||
foreach ($articles as $article)
|
||||
{
|
||||
foreach ($articles as $article) {
|
||||
$url = $xml->addChild('url');
|
||||
$url->addChild('loc', 'http://wikipoints.ru/page/article/id/' . $article['id']);
|
||||
$url->addChild('lastmod', date("Y-m-d", strtotime('- 5 days')));
|
||||
|
|
@ -166,8 +158,7 @@ class IndexController extends Controller
|
|||
}
|
||||
|
||||
$points = Point::model()->getAll(array('order' => 'ID DESC', 'asArray' => true));
|
||||
foreach ($points as $point)
|
||||
{
|
||||
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']));
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ class JsonController extends Controller
|
|||
|
||||
$result = array();
|
||||
|
||||
foreach ($points as $point)
|
||||
{
|
||||
foreach ($points as $point) {
|
||||
$id = $point->id;
|
||||
$result[$id]['id'] = $point->id;
|
||||
$result[$id]['name'] = $point->name;
|
||||
|
|
@ -50,8 +49,7 @@ class JsonController extends Controller
|
|||
static function actionPoint()
|
||||
{
|
||||
$id = (int) App::getParam('id');
|
||||
if ($id)
|
||||
{
|
||||
if ($id) {
|
||||
$point = Point::model()->getByPK($id);
|
||||
|
||||
$point->descriptionHtml = nl2br($point->description);
|
||||
|
|
@ -61,19 +59,16 @@ class JsonController extends Controller
|
|||
$imgs = $point->photos;
|
||||
$photosCount = 1;
|
||||
|
||||
if ($point->img == '' && !empty($imgs))
|
||||
{
|
||||
if ($point->img == '' && !empty($imgs)) {
|
||||
$img = array_shift($imgs);
|
||||
$point->img = $img->name;
|
||||
}
|
||||
|
||||
$imgs = $point->photos;
|
||||
if (!empty($imgs))
|
||||
{
|
||||
if (!empty($imgs)) {
|
||||
$tmp = array();
|
||||
$photosCount = count($imgs);
|
||||
foreach ($imgs as $img)
|
||||
{
|
||||
foreach ($imgs as $img) {
|
||||
$tmp[] = $img->name;
|
||||
}
|
||||
$point->images = $tmp;
|
||||
|
|
@ -88,8 +83,7 @@ class JsonController extends Controller
|
|||
$point->iLike = Like::model()->checkIsMy($id);
|
||||
|
||||
self::renderPartial('json.php', $point->getValues());
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
App::error404();
|
||||
}
|
||||
}
|
||||
|
|
@ -113,61 +107,49 @@ class JsonController extends Controller
|
|||
{
|
||||
$errors = array();
|
||||
|
||||
if (!App::$user)
|
||||
{
|
||||
if (!App::$user) {
|
||||
$errors[8] = 'Вы не авторизованы! Пожалуйста, войдите.';
|
||||
}
|
||||
|
||||
if (isset($_POST['id']) && $_POST['id'] && App::$user->isAdmin == 0)
|
||||
{
|
||||
if (isset($_POST['id']) && $_POST['id'] && App::$user->isAdmin == 0) {
|
||||
$point = new Point();
|
||||
$id = (int) $_POST['id'];
|
||||
$point = $point->getByPK($id);
|
||||
|
||||
if ($point->author != App::$user->id || $point->moderate == 1)
|
||||
{
|
||||
if ($point->author != App::$user->id || $point->moderate == 1) {
|
||||
$errors[9] = 'Редактирование точек достурно только администратору или автору!';
|
||||
}
|
||||
}
|
||||
|
||||
$photos = $images = array();
|
||||
if (empty($errors) && !App::$request['ajax'] && isset($_POST['id']) && (int) $_POST['id'])
|
||||
{
|
||||
if (empty($errors) && !App::$request['ajax'] && isset($_POST['id']) && (int) $_POST['id']) {
|
||||
$id = (int) $_POST['id'];
|
||||
$pathInfo = pathinfo($_SERVER['SCRIPT_FILENAME']);
|
||||
$uploaddir = $pathInfo['dirname'] . '/photos/';
|
||||
|
||||
if (isset($_FILES) && !empty($_FILES))
|
||||
{
|
||||
foreach ($_FILES['photos']['name'] as $key => $fileName)
|
||||
{
|
||||
if (isset($_FILES) && !empty($_FILES)) {
|
||||
foreach ($_FILES['photos']['name'] as $key => $fileName) {
|
||||
$temp = pathinfo($_FILES['photos']['name'][$key]);
|
||||
$extension = strtolower($temp['extension']) ? strtolower($temp['extension']) : 'jpg';
|
||||
$photo = $id . strtolower('_' . substr(md5($fileName . time()), 0, 5) . '.' . $extension);
|
||||
if (move_uploaded_file($_FILES['photos']['tmp_name'][$key], $uploaddir . $photo))
|
||||
{
|
||||
if (move_uploaded_file($_FILES['photos']['tmp_name'][$key], $uploaddir . $photo)) {
|
||||
$photos[] = $photo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['imgs']) && !empty($_POST['imgs']))
|
||||
{
|
||||
foreach ($_POST['imgs'] as $key => $img)
|
||||
{
|
||||
if (mb_strpos($img, '://') !== false)
|
||||
{
|
||||
if (isset($_POST['imgs']) && !empty($_POST['imgs'])) {
|
||||
foreach ($_POST['imgs'] as $key => $img) {
|
||||
if (mb_strpos($img, '://') !== false) {
|
||||
$temp = pathinfo($img);
|
||||
$extension = strtolower($temp['extension']) ? strtolower($temp['extension']) : 'jpg';
|
||||
$photo = $id . strtolower('_' . substr(md5($img . time()), 0, 5) . '.' . $extension);
|
||||
|
||||
if (file_put_contents($uploaddir . $photo, file_get_contents($img)))
|
||||
{
|
||||
if (file_put_contents($uploaddir . $photo, file_get_contents($img))) {
|
||||
PhotoLinks::addLink($photo, $img);
|
||||
$images[] = $photo;
|
||||
}
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
$images[] = $img;
|
||||
}
|
||||
}
|
||||
|
|
@ -175,18 +157,15 @@ class JsonController extends Controller
|
|||
|
||||
$resPhotos = array();
|
||||
$ordering = $_POST['ordering'];
|
||||
foreach ($ordering as $order)
|
||||
{
|
||||
foreach ($ordering as $order) {
|
||||
$resPhotos[] = $order == 'FILE' ? array_shift($photos) : array_shift($images);
|
||||
}
|
||||
|
||||
if (!empty($resPhotos))
|
||||
{
|
||||
if (!empty($resPhotos)) {
|
||||
App::DB()->query('DELETE FROM `poi`.`photos` WHERE `pointId` = ' . $id . ';');
|
||||
|
||||
$P = new Photo();
|
||||
foreach ($resPhotos as $key => $photo)
|
||||
{
|
||||
foreach ($resPhotos as $key => $photo) {
|
||||
$P->add(array(
|
||||
'pointId' => $id,
|
||||
'name' => $photo,
|
||||
|
|
@ -221,21 +200,18 @@ class JsonController extends Controller
|
|||
if (!( isset($_POST['lng']) && $_POST['lng'] ))
|
||||
$errors[7] = 'Ошибочное значение долготы';
|
||||
|
||||
if (!empty($errors))
|
||||
{
|
||||
if (!empty($errors)) {
|
||||
header("HTTP/1.0 400 Bad Request");
|
||||
header('Content-Type: application/json');
|
||||
print json_encode($errors);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (App::$request['ajax'])
|
||||
{
|
||||
if (App::$request['ajax']) {
|
||||
$point = new Point();
|
||||
unset($_POST['img']);
|
||||
|
||||
if (isset($_POST['id']) && $_POST['id'])
|
||||
{
|
||||
if (isset($_POST['id']) && $_POST['id']) {
|
||||
// Редактирование существующей точки
|
||||
$id = (int) $_POST['id'];
|
||||
$_POST['dateEdit'] = time();
|
||||
|
|
@ -243,22 +219,19 @@ class JsonController extends Controller
|
|||
$point = $point->getByPK($id);
|
||||
$point->setValues($_POST);
|
||||
$point->save();
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
$_POST['author'] = App::$user->id;
|
||||
$_POST['date'] = time();
|
||||
$_POST['dateEdit'] = time();
|
||||
$_POST['moderate'] = (App::$user && App::$user->isAdmin == 1) ? $_POST['moderate'] : 0;
|
||||
$point->add($_POST);
|
||||
|
||||
if (!$point->id)
|
||||
{
|
||||
if (!$point->id) {
|
||||
header("HTTP/1.0 500 Internal Server Error");
|
||||
die('Error 500 - Internal Server Error');
|
||||
}
|
||||
|
||||
if (!App::getConfig('disableSMS'))
|
||||
{
|
||||
if (!App::getConfig('disableSMS')) {
|
||||
$ch = curl_init("http://sms.ru/sms/send");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
|
|
@ -296,12 +269,10 @@ class JsonController extends Controller
|
|||
static function actionRoute()
|
||||
{
|
||||
$id = (int) App::getParam('id');
|
||||
if ($id)
|
||||
{
|
||||
if ($id) {
|
||||
$route = Route::model()->getByPK($id);
|
||||
self::renderPartial('json.php', $route->points);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
App::error404();
|
||||
}
|
||||
}
|
||||
|
|
@ -309,18 +280,15 @@ class JsonController extends Controller
|
|||
static function actionDeleteRoute()
|
||||
{
|
||||
$id = (int) App::getParam('id');
|
||||
if ($id && App::$user)
|
||||
{
|
||||
if ($id && App::$user) {
|
||||
$route = Route::model()->getByPK($id);
|
||||
|
||||
if ($route->author == App::$user->id)
|
||||
{
|
||||
if ($route->author == App::$user->id) {
|
||||
$route->delete($id);
|
||||
}
|
||||
|
||||
self::renderPartial('json.php', true);
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
App::error404();
|
||||
}
|
||||
}
|
||||
|
|
@ -347,8 +315,7 @@ class JsonController extends Controller
|
|||
static function actionAddRemoveFavorites()
|
||||
{
|
||||
$id = (int) App::getParam('id');
|
||||
if (!$id || !App::$user)
|
||||
{
|
||||
if (!$id || !App::$user) {
|
||||
App::error404();
|
||||
}
|
||||
self::renderPartial('json.php', Helper::boolval(Favorite::addRemove($id)));
|
||||
|
|
@ -357,8 +324,7 @@ class JsonController extends Controller
|
|||
static function actionAddRemoveLike()
|
||||
{
|
||||
$id = (int) App::getParam('id');
|
||||
if (!$id || !App::$user)
|
||||
{
|
||||
if (!$id || !App::$user) {
|
||||
App::error404();
|
||||
}
|
||||
self::renderPartial('json.php', Helper::boolval(Like::addRemove($id)));
|
||||
|
|
@ -369,20 +335,16 @@ class JsonController extends Controller
|
|||
$search = isset($_GET['query']) ? $_GET['query'] : '';
|
||||
|
||||
$results = array();
|
||||
if ($search)
|
||||
{
|
||||
if ($search) {
|
||||
// ====== POINTS ============
|
||||
$points = Point::model()->searchByString($search);
|
||||
if (!empty($points))
|
||||
{
|
||||
foreach ($points as $point)
|
||||
{
|
||||
if (!empty($points)) {
|
||||
foreach ($points as $point) {
|
||||
$results[] = array('value' => $point->name, 'data' => '/?point=' . $point->id);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($results) < 10)
|
||||
{
|
||||
if (count($results) < 10) {
|
||||
// ====== YANDEX ============
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, 'http://geocode-maps.yandex.ru/1.x/?geocode=' . urlencode($search));
|
||||
|
|
@ -391,17 +353,13 @@ class JsonController extends Controller
|
|||
$out = null;
|
||||
$out = curl_exec($ch); // выполняем запрос curl - обращаемся к сервера php.su
|
||||
|
||||
if (!empty($out))
|
||||
{
|
||||
if (!empty($out)) {
|
||||
$obj = simplexml_load_string($out);
|
||||
|
||||
if (isset($obj->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found))
|
||||
{
|
||||
if (isset($obj->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found)) {
|
||||
$count = (int) $obj->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found;
|
||||
if ($count > 0)
|
||||
{
|
||||
for ($index = 0; $index < $count && $index < 5 && count($results) < 25; $index++)
|
||||
{
|
||||
if ($count > 0) {
|
||||
for ($index = 0; $index < $count && $index < 5 && count($results) < 25; $index++) {
|
||||
$name = (string) $obj->GeoObjectCollection->featureMember[$index]->GeoObject->name;
|
||||
$coords = explode(' ', (string) $obj->GeoObjectCollection->featureMember[$index]->GeoObject->Point->pos);
|
||||
$lat = $coords[1];
|
||||
|
|
@ -424,15 +382,13 @@ class JsonController extends Controller
|
|||
static function actionArticle()
|
||||
{
|
||||
$id = (int) App::getParam('id');
|
||||
if ($id)
|
||||
{
|
||||
if ($id) {
|
||||
$article = Article::model()->getByPK($id);
|
||||
|
||||
if (!$article) {
|
||||
die;
|
||||
}
|
||||
self::renderPartial('modals/article.php',
|
||||
array(
|
||||
self::renderPartial('modals/article.php', array(
|
||||
'title' => $article->title,
|
||||
'text' => $article->text,
|
||||
));
|
||||
|
|
@ -446,8 +402,7 @@ class JsonController extends Controller
|
|||
if (!$article) {
|
||||
die;
|
||||
}
|
||||
self::renderPartial('modals/pointAgreement.php',
|
||||
array(
|
||||
self::renderPartial('modals/pointAgreement.php', array(
|
||||
'title' => $article->title,
|
||||
'text' => $article->text,
|
||||
));
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Article extends Model
|
||||
{
|
||||
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
$this->_tableName_ = 'articles';
|
||||
|
|
@ -15,4 +16,3 @@ class Article extends Model
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Category extends Model
|
||||
{
|
||||
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
$this->_tableName_ = 'categories';
|
||||
|
|
@ -13,5 +14,5 @@ class Category extends Model
|
|||
{
|
||||
return new self();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,9 @@ class Favorite extends Model
|
|||
|
||||
$res = self::model()->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId, 'limit' => 1));
|
||||
|
||||
if ($res)
|
||||
{
|
||||
if ($res) {
|
||||
return Helper::boolval(Favorite::model()->delete($res->id));
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
return Favorite::model()->add(array('userId' => App::$user->id, 'pointId' => $pointId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,9 @@ class Like extends Model
|
|||
|
||||
$res = self::model()->getAll(array('where' => '`userId` = ' . (int) App::$user->id . ' AND `pointId` = ' . (int) $pointId, 'limit' => 1));
|
||||
|
||||
if ($res)
|
||||
{
|
||||
if ($res) {
|
||||
return Helper::boolval(Like::model()->delete($res->id));
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
return Like::model()->add(array('userId' => App::$user->id, 'pointId' => $pointId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Photo extends Model
|
||||
{
|
||||
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
$this->_tableName_ = 'photos';
|
||||
|
|
@ -14,5 +15,5 @@ class Photo extends Model
|
|||
{
|
||||
return new self();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class PhotoLinks extends Model
|
||||
{
|
||||
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
$this->_tableName_ = 'photoLinks';
|
||||
|
|
@ -31,5 +32,5 @@ class PhotoLinks extends Model
|
|||
|
||||
return $photolink->host ? $photolink->host : $photolink->url;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Point extends Model
|
||||
{
|
||||
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
$this->_tableName_ = 'points';
|
||||
|
|
@ -19,8 +20,7 @@ class Point extends Model
|
|||
public function getImg($size = 'small')
|
||||
{
|
||||
$img = $this->img;
|
||||
if ($img == '')
|
||||
{
|
||||
if ($img == '') {
|
||||
$photos = $this->photos;
|
||||
$img = array_shift($photos);
|
||||
|
||||
|
|
@ -72,8 +72,7 @@ class Point extends Model
|
|||
|
||||
$ready = array();
|
||||
$calledClass = get_called_class();
|
||||
while ($res && $row = $res->fetch(PDO::FETCH_ASSOC))
|
||||
{
|
||||
while ($res && $row = $res->fetch(PDO::FETCH_ASSOC)) {
|
||||
$ready[] = new $calledClass($row);
|
||||
}
|
||||
|
||||
|
|
@ -108,4 +107,3 @@ class Point extends Model
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class Route extends Model
|
||||
{
|
||||
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
$this->_tableName_ = 'routes';
|
||||
|
|
@ -17,5 +18,5 @@ class Route extends Model
|
|||
{
|
||||
return $this->getAll(array('where' => '`author` = ' . $authorId));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
class User extends Model
|
||||
{
|
||||
|
||||
function __construct($fromArray = array())
|
||||
{
|
||||
$this->_tableName_ = 'users';
|
||||
|
|
@ -17,15 +18,12 @@ class User extends Model
|
|||
function getByUID($uid)
|
||||
{
|
||||
$res = App::DB()->query('SELECT `id` FROM `' . $this->_tableName_ . '` WHERE `uid` = "' . $uid . '"');
|
||||
if ($res)
|
||||
{
|
||||
if ($res) {
|
||||
$res = $res->fetch(PDO::FETCH_ASSOC);
|
||||
$user = $this->getByPK((int) $res['id']);
|
||||
|
||||
return $user;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -34,5 +32,5 @@ class User extends Model
|
|||
{
|
||||
return Point::model()->getCountByUser($this->id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
<?php if (App::getConfig('ganalytics')): ?>
|
||||
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
(function (i, s, o, g, r, a, m) {
|
||||
i['GoogleAnalyticsObject'] = r;
|
||||
i[r] = i[r] || function () {
|
||||
(i[r].q = i[r].q || []).push(arguments)
|
||||
}, i[r].l = 1 * new Date();
|
||||
a = s.createElement(o),
|
||||
m = s.getElementsByTagName(o)[0];
|
||||
a.async = 1;
|
||||
a.src = g;
|
||||
m.parentNode.insertBefore(a, m)
|
||||
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
|
||||
|
||||
ga('create', 'UA-56791930-1', 'auto');
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@
|
|||
width = $('.col-md-12').width() / 3 - 4;
|
||||
|
||||
height = width / 4 * 3;
|
||||
|
||||
$('.pagePoinsNearCards').width(width);
|
||||
$('.pagePoinsNearCardsImg').width(width);
|
||||
$('.pagePoinsNearCards').height(height);
|
||||
|
|
|
|||
|
|
@ -91,7 +91,9 @@
|
|||
function removeInput(el)
|
||||
{
|
||||
container = $(el).parent().parent();
|
||||
container.hide(300, function(){container.remove()});
|
||||
container.hide(300, function () {
|
||||
container.remove()
|
||||
});
|
||||
}
|
||||
|
||||
function switchType(el)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
foreach ($points as $point)
|
||||
{
|
||||
foreach ($points as $point) {
|
||||
?>
|
||||
|
||||
<h2><?= $point->name ?></h2>
|
||||
|
|
|
|||
Loading…
Reference in New Issue