diff --git a/ground/app.php b/ground/app.php
index 6aaed35..8bbddf3 100644
--- a/ground/app.php
+++ b/ground/app.php
@@ -2,27 +2,28 @@
function __autoload($className)
{
- $dirs = array('classes','models','controllers');
+ $dirs = array('classes', 'models', 'controllers');
- $loaded = false;
- foreach ($dirs as $dir) {
- $fileName = dirname(__FILE__) . '/../ground/' . $dir. '/' . $className . '.php';
+ $loaded = false;
+ foreach ($dirs as $dir) {
+ $fileName = dirname(__FILE__) . '/../ground/' . $dir . '/' . $className . '.php';
- if (file_exists($fileName)){
- $loaded = (bool) include $fileName;
- }
- }
+ if (file_exists($fileName)) {
+ $loaded = (bool) include $fileName;
+ }
+ }
- if (!$loaded){
- App::error404('Class '.$className.' was not loaded!');
- return false;
- }
+ if (!$loaded) {
+ App::error404('Class ' . $className . ' was not loaded!');
+ return false;
+ }
- return true;
+ return true;
}
class App
{
+
private static $url = array();
private static $controller = 'IndexController';
private static $action = 'actionIndex';
@@ -38,16 +39,14 @@ class App
*/
private static function parseUrl()
{
- $url = explode('?', $_SERVER['REQUEST_URI']);
+ $url = explode('?', $_SERVER['REQUEST_URI']);
self::$url = explode('/', $url[0]);
self::$controller = isset(self::$url[1]) && self::$url[1] ? ucfirst(self::$url[1]) . 'Controller' : self::$controller;
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)
- {
+ self::$DB = new PDO('mysql:host=' . $confDB['host'] . ';dbname=' . $confDB['dbname'] . ';charset=utf8;', $confDB['user'], $confDB['password']);
+ } 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'] )
- {
- $user = User::model()->getByPK((int)$_SESSION['user_id']);
+ 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;
}
}
@@ -142,10 +133,10 @@ class App
}
/**
- * Перенаправление на другой URL
- * @param type $url
- * @param type $httpCode - по умолчанию 307, временный редирект
- */
+ * Перенаправление на другой URL
+ * @param type $url
+ * @param type $httpCode - по умолчанию 307, временный редирект
+ */
public static function redirect($url, $httpCode = 307)
{
header('Location: ' . $url, true, $httpCode);
diff --git a/ground/classes/Controller.php b/ground/classes/Controller.php
index 724a53e..d52313b 100644
--- a/ground/classes/Controller.php
+++ b/ground/classes/Controller.php
@@ -4,95 +4,87 @@ abstract class Controller
{
static $layout = 'layout.php';
- static private $styles = array();
- static private $scripts = array();
+ static private $styles = array();
+ static private $scripts = array();
static private $og = array();
static private $vars = array();
+ static function addStyle($name)
+ {
+ if (array_search($name, self::$styles) === FALSE) {
+ self::$styles[] = $name;
+ }
+ }
- static function addStyle($name)
- {
- if (array_search($name, self::$styles) === FALSE )
- {
- self::$styles[] = $name;
- }
- }
-
- static function addScript($name)
- {
- if (array_search($name, self::$scripts) === FALSE )
- {
- self::$scripts[] = $name;
- }
- }
+ static function addScript($name)
+ {
+ if (array_search($name, self::$scripts) === FALSE) {
+ self::$scripts[] = $name;
+ }
+ }
static function addVar($name, $value)
- {
- self::$vars[$name] = $value;
- }
+ {
+ self::$vars[$name] = $value;
+ }
- /**
- * Рендерит шаблон без лейаута.
- * @param string $template - имя шаблона
- * @param array $data - передаваемые параметры
- * @param bool $return - вернуть результат в виде строки
- * @return string
- */
- static function renderPartial($template, $data, $return = false)
+ /**
+ * Рендерит шаблон без лейаута.
+ * @param string $template - имя шаблона
+ * @param array $data - передаваемые параметры
+ * @param bool $return - вернуть результат в виде строки
+ * @return string
+ */
+ static function renderPartial($template, $data, $return = false)
{
if (!file_exists(App::getBasedir() . 'views/' . $template))
return 'Template not found';
- if ($return)
- {
+ if ($return) {
$oldContentFormBuffer_temp = ob_get_clean();
- ob_start();
- }
+ 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();
+ ob_start();
echo $oldContentFormBuffer_temp;
return $newContentFormBuffer_temp;
}
- return true;
+ return true;
}
- /**
- * Рендерит шаблон и вписывает его в лейаут.
- * @param string $template - имя шаблона
- * @param array $data - передаваемые параметры
- * @param bool $return - вернуть результат в виде строки
- * @return string
- */
+ /**
+ * Рендерит шаблон и вписывает его в лейаут.
+ * @param string $template - имя шаблона
+ * @param array $data - передаваемые параметры
+ * @param bool $return - вернуть результат в виде строки
+ * @return string
+ */
static function render($template, $data, $return = false)
{
$content = self::renderPartial($template, $data, true);
- $result = self::renderPartial(self::$layout, array(
- 'content' => $content,
- 'styles' => self::$styles,
- 'scripts' => self::$scripts,
- 'vars' => self::$vars,
- 'data' => $data,
- ), true);
+ $result = self::renderPartial(self::$layout, array(
+ 'content' => $content,
+ 'styles' => self::$styles,
+ 'scripts' => self::$scripts,
+ 'vars' => self::$vars,
+ 'data' => $data,
+ ), true);
- if ($return)
- {
+ if ($return) {
return $result;
- } else
- {
+ } else {
echo $result;
- return true;
+ return true;
}
}
diff --git a/ground/classes/Coord.php b/ground/classes/Coord.php
index e267470..8cc4ccc 100644
--- a/ground/classes/Coord.php
+++ b/ground/classes/Coord.php
@@ -2,6 +2,7 @@
class Coord
{
+
static function dergeeToMinute($input)
{
$input = abs($input);
@@ -9,6 +10,7 @@ class Coord
$degree = floor($input);
$minute = 60 * ($input - $degree);
- return $degree.'°'.substr($minute,0,6).'\'';
+ return $degree . '°' . substr($minute, 0, 6) . '\'';
}
+
}
diff --git a/ground/classes/Helper.php b/ground/classes/Helper.php
index 279d1d0..e50f33c 100644
--- a/ground/classes/Helper.php
+++ b/ground/classes/Helper.php
@@ -2,6 +2,7 @@
class Helper
{
+
public static function boolval($var)
{
return (bool) $var;
@@ -11,23 +12,19 @@ class Helper
{
preg_match_all("(\[#(\d+)>?(.*?)\])", $string, $links);
$links = isset($links[0]) ? $links[0] : FALSE;
- if ($links)
- {
- foreach ($links as $link)
- {
- $idAndLink = mb_substr($link, 2, -1);
+ if ($links) {
+ foreach ($links as $link) {
+ $idAndLink = mb_substr($link, 2, -1);
$idAndLink = explode('>', $idAndLink);
$linkId = $idAndLink[0];
- $linkName = isset($idAndLink[1])?$idAndLink[1]:'';
+ $linkName = isset($idAndLink[1]) ? $idAndLink[1] : '';
- 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, ''.$linkName.'', $string);
+ $string = str_replace($link, '' . $linkName . '', $string);
}
}
}
@@ -41,7 +38,7 @@ class Helper
$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['description'] = mb_substr($point->description, 0, 97, 'UTF-8') . '...';
$og['site_name'] = 'WikiPoints: Лучшие выходные - это выходные в путешествии!';
$og['type'] = 'website';
$og['url'] = 'http://wikipoints.ru/?point=' . $point->id;
@@ -49,4 +46,5 @@ class Helper
return $og;
}
+
}
diff --git a/ground/classes/Image.php b/ground/classes/Image.php
index d82c6f8..6a29456 100644
--- a/ground/classes/Image.php
+++ b/ground/classes/Image.php
@@ -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;
}
@@ -36,11 +34,10 @@ class Image
$sizes = App::getConfig('images');
$pathInfo = pathinfo($_SERVER['SCRIPT_FILENAME']);
$uploaddir = $pathInfo['dirname'] . '/photos/';
- $watermarkDir = App::getBasedir().'watermarks/';
+ $watermarkDir = App::getBasedir() . 'watermarks/';
- foreach ($sizes as $dir => $size)
- {
- $watermark = isset($size[3])?$watermarkDir.$size[3]:'';
+ foreach ($sizes as $dir => $size) {
+ $watermark = isset($size[3]) ? $watermarkDir . $size[3] : '';
self::imgResize(
$uploaddir . $imgName, // Source - original image
$uploaddir . $dir . '/' . $imgName, // Destination
@@ -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;
diff --git a/ground/classes/Model.php b/ground/classes/Model.php
index c603017..d2850fa 100644
--- a/ground/classes/Model.php
+++ b/ground/classes/Model.php
@@ -6,16 +6,16 @@
class User extends Model
{
- function __construct($fromArray = array())
- {
- $this->_tableName_ = 'Users';
- parent::__construct($fromArray);
- }
+ function __construct($fromArray = array())
+ {
+ $this->_tableName_ = 'Users';
+ parent::__construct($fromArray);
+ }
- static function model()
- {
- return new self();
- }
+ static function model()
+ {
+ return new self();
+ }
}
Просто новый пользователь:
@@ -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;
@@ -151,20 +145,19 @@ abstract class Model
function getAll($params = array())
{
$sql = 'SELECT * FROM `' . $this->_tableName_ . '`';
- $sql .= isset($params['where'])&&$params['where'] ? ' WHERE ' . $params['where'] : '';
- $sql .= isset($params['order'])&&$params['order'] ? ' ORDER BY ' . $params['order'] : '';
- $sql .= isset($params['limit'])&&$params['limit'] ? ' LIMIT ' . $params['limit'] : '';
+ $sql .= isset($params['where']) && $params['where'] ? ' WHERE ' . $params['where'] : '';
+ $sql .= isset($params['order']) && $params['order'] ? ' ORDER BY ' . $params['order'] : '';
+ $sql .= isset($params['limit']) && $params['limit'] ? ' LIMIT ' . $params['limit'] : '';
$res = App::DB()->query($sql);
$ready = array();
$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);
+ while ($res && $row = $res->fetch(PDO::FETCH_ASSOC)) {
+ $ready[$row[$this->_primaryKey_]] = isset($params['asArray']) && $params['asArray'] ? $row : new $calledClass($row);
}
- return (isset($params['limit'])&&$params['limit']==1) ? array_shift($ready) : $ready;
+ return (isset($params['limit']) && $params['limit'] == 1) ? array_shift($ready) : $ready;
}
/**
@@ -178,7 +171,7 @@ abstract class Model
return $this->getAll(array(
'where' => '`' . $whereField . '` = "' . $whereValue . '"',
'limit' => 1
- ));
+ ));
}
/**
@@ -202,34 +195,29 @@ 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) )
- {
- return $this->getByPK(App::DB()->lastInsertId());
- }
- else
- {
- return false;
- }
+ if ($request->execute((array) $values)) {
+ return $this->getByPK(App::DB()->lastInsertId());
+ } 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;
}
}
@@ -275,27 +258,23 @@ 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;
}
}
- $values = $this->_vals_;
- unset($values[$this->_primaryKey_]);
+ $values = $this->_vals_;
+ unset($values[$this->_primaryKey_]);
- $request = App::DB()->prepare('UPDATE ' . $this->_tableName_ . ' SET ' . implode('=?, ', array_keys($values)) . '=? WHERE '.$this->_primaryKey_.'='.$this->_id_);
+ $request = App::DB()->prepare('UPDATE ' . $this->_tableName_ . ' SET ' . implode('=?, ', array_keys($values)) . '=? WHERE ' . $this->_primaryKey_ . '=' . $this->_id_);
$res = $request->execute(array_values($values));
- return $res ? $this : FALSE;
- }
+ return $res ? $this : FALSE;
+ }
/**
* Возвращает значения полей объекта в виде ассоциативного массива.
diff --git a/ground/config_template.php b/ground/config_template.php
index 4a55ba1..e54ae8e 100644
--- a/ground/config_template.php
+++ b/ground/config_template.php
@@ -14,7 +14,7 @@ return array(
'middle' => array(555, 450, 90, 'middle.png'),
'big' => array(1110, 900, 90, 'big.png'),
),
- //'version' => trim(file_get_contents(dirname(__FILE__).'/version')),
+ //'version' => trim(file_get_contents(dirname(__FILE__).'/version')),
'metrika' => true,
'ganalytics' => true,
'disableSMS' => false,
diff --git a/ground/controllers/ImagesController.php b/ground/controllers/ImagesController.php
index 615967c..860ea85 100644
--- a/ground/controllers/ImagesController.php
+++ b/ground/controllers/ImagesController.php
@@ -3,9 +3,9 @@
class ImagesController extends Controller
{
- static function actionGet()
- {
- $pointId = (int) App::getParam('id');
+ static function actionGet()
+ {
+ $pointId = (int) App::getParam('id');
$width = (int) App::getParam('width');
$height = (int) App::getParam('height');
@@ -17,32 +17,32 @@ class ImagesController extends Controller
$height = 200;
}
- if (!$pointId) {
- App::error404();
- }
-
- $point = Point::model()->getByPK($pointId);
-
- if (!$point) {
- App::error404();
- }
-
- $photos = $point->photos;
- $img = array_shift($photos);
-
-
- if ($img) {
- $photo = $photo = App::getBasedir().'../public/'.'photos/'.$img->name;
- } else {
- $photo = $photo = App::getBasedir().'../public/'.'img/noPhoto.png';
- }
-
- if (!file_exists($photo)) {
- $photo = $photo = App::getBasedir().'../public/'.'img/noPhoto.png';
+ if (!$pointId) {
+ App::error404();
}
- Image::createCustomSize($photo, $width, $height);
+ $point = Point::model()->getByPK($pointId);
+
+ if (!$point) {
+ App::error404();
+ }
+
+ $photos = $point->photos;
+ $img = array_shift($photos);
+
+
+ if ($img) {
+ $photo = $photo = App::getBasedir() . '../public/' . 'photos/' . $img->name;
+ } else {
+ $photo = $photo = App::getBasedir() . '../public/' . 'img/noPhoto.png';
+ }
+
+ if (!file_exists($photo)) {
+ $photo = $photo = App::getBasedir() . '../public/' . 'img/noPhoto.png';
+ }
+
+ Image::createCustomSize($photo, $width, $height);
// print $photo;
- }
+ }
}
diff --git a/ground/controllers/IndexController.php b/ground/controllers/IndexController.php
index 11591c7..a5e3208 100644
--- a/ground/controllers/IndexController.php
+++ b/ground/controllers/IndexController.php
@@ -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,14 +135,13 @@ class IndexController extends Controller
'photo' => $uLoginUser['photo_big'],
));
- if (!$user)
- {
+ if (!$user) {
return false;
}
}
App::userLogin($user);
- App::redirect(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'/');
+ App::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/');
}
static function actionSitemap()
@@ -156,8 +149,7 @@ class IndexController extends Controller
$xml = new SimpleXMLElement('