diff --git a/classes/Action.class.php b/classes/Action.class.php index 115aabb..9990012 100644 --- a/classes/Action.class.php +++ b/classes/Action.class.php @@ -3,7 +3,7 @@ * Рутовый класс для любого действия. * Описывает основной функционал для работы с классами действий. * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Action @@ -106,4 +106,4 @@ abstract class Action } } } -?> \ No newline at end of file +?> diff --git a/classes/Cache.class.php b/classes/Cache.class.php index 1754e7f..428c569 100644 --- a/classes/Cache.class.php +++ b/classes/Cache.class.php @@ -3,7 +3,7 @@ * Класс кеша. * Отвечает за кеширование результатов выполнения действий. * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Cache @@ -126,4 +126,4 @@ final class Cache } } -?> \ No newline at end of file +?> diff --git a/classes/DBConnector.class.php b/classes/DBConnector.class.php index e6d4e5e..e1ba951 100644 --- a/classes/DBConnector.class.php +++ b/classes/DBConnector.class.php @@ -3,7 +3,7 @@ * Класс базы данных. * Возвращает идентификатор соединения * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage DB @@ -131,7 +131,7 @@ class DBConnector return mysqli_num_rows($result); } - static public function affectedRows($handler) + static public function affectedRows($handler, $result) { return mysqli_affected_rows($handler); } @@ -156,4 +156,4 @@ class DBConnector return mysqli_rollback($handler); } } -?> \ No newline at end of file +?> diff --git a/classes/Decorator.class.php b/classes/Decorator.class.php index 82122d8..4a21d34 100644 --- a/classes/Decorator.class.php +++ b/classes/Decorator.class.php @@ -2,7 +2,7 @@ /** * Родительский класс для всех декораторов. Содержит основной функционал. * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Decorator @@ -59,4 +59,4 @@ abstract class Decorator */ abstract function exec(); } -?> \ No newline at end of file +?> diff --git a/classes/DynamicPageException.class.php b/classes/DynamicPageException.class.php index d4ae9f4..35ec89a 100644 --- a/classes/DynamicPageException.class.php +++ b/classes/DynamicPageException.class.php @@ -3,7 +3,7 @@ /** * Эксепшен для выводя результата работы класса * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Core @@ -13,4 +13,4 @@ */ class DynamicPageException extends Exception {} -?> \ No newline at end of file +?> diff --git a/classes/Env.class.php b/classes/Env.class.php index 38ff0d7..3ad1552 100644 --- a/classes/Env.class.php +++ b/classes/Env.class.php @@ -2,7 +2,7 @@ /** * Класс для работы с переменными окружения. * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Core @@ -87,21 +87,5 @@ final class Env $res = isset($_FILES[$name]) ? $_FILES[$name] : $default; return $param ? $res[$param] : $res; } - - /** - * Получить цену ставки - * - * @param integer $dis - некое число от кооторого считается скидка - */ - static public function getBidCost($dis = 0) - { - $settings_model = new SettingsModel(); - $cost = $settings_model->get('bid_base_price'); - if ($dis > 0 && $dis <= 100) { - return $cost - intval($dis); - } - - return $cost; - } } -?> \ No newline at end of file +?> diff --git a/classes/Format.class.php b/classes/Format.class.php index 842a008..17b2bd5 100644 --- a/classes/Format.class.php +++ b/classes/Format.class.php @@ -2,7 +2,7 @@ /** * Format * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Core @@ -19,9 +19,11 @@ class Format { /* Date & time */ - static protected $time_format = 'H:i:s'; - static protected $date_format = 'd.m.Y'; - static protected $date_time_format = 'H:i d.m.Y'; + static protected $time_format = 'H:i:s'; + static protected $date_format = 'd.m.Y'; + static protected $today_format = 'd.m.Y'; //disabled by default + static protected $date_time_format = 'H:i d.m.Y'; + static protected $today_time_format = 'H:i d.m.Y'; //disabled by default static protected $timezone_offset = 0; /* money */ @@ -71,8 +73,8 @@ class Format $minutes = floor(($timestamp / 60) - ($hours * 60)); $seconds = $timestamp - ($hours * 3600) - ($minutes * 60); - return ($hours < 10 ? ('0' . $hours) : $hours) - . ':' . ($minutes < 10 ? ('0' . $minutes) : $minutes) + return ($hours < 10 ? ('0' . $hours) : $hours) + . ':' . ($minutes < 10 ? ('0' . $minutes) : $minutes) . ':' . ($seconds < 10 ? ('0' . $seconds) : $seconds); } @@ -85,15 +87,18 @@ class Format */ static public function int2date($timestamp = 0, $hours = true) { - $date = date(($hours) ? self::$date_time_format : self::$date_format , $timestamp); - return $date; + if (date('Ymd') == date('Ymd', $timestamp)) { + return date(($hours) ? self::$today_time_format : self::$today_format , $timestamp); + } + + return date(($hours) ? self::$date_time_format : self::$date_format , $timestamp); } static public function int2rusDate($timestamp = 0, $hours = false) { - $month = array('января', 'февраля', 'марта', - 'апреля', 'мая', 'июня', - 'июля', 'августа', 'сентября', + $month = array('января', 'февраля', 'марта', + 'апреля', 'мая', 'июня', + 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); $date = ($hours) ? date('H:i d', $timestamp) . ' ' . $month[date('m', $timestamp) - 1] . ' ' .date('Y', $timestamp) : date('d', $timestamp) . ' ' . $month[date('m', $timestamp) - 1] . ' ' .date('Y', $timestamp); return $date; @@ -110,6 +115,30 @@ class Format } /** + * Установка форматов даты + * + */ + static public function setDateFormat($date_time_format, $date_format = false) + { + self::$date_time_format = $date_time_format; + if ($date_format) { + self::$date_format = $date_format; + } + } + + /** + * Установка форматов даты для текущего дня + * + */ + static public function setTodayFormat($today_time_format, $today_format = false) + { + self::$today_time_format = $today_time_format; + if ($today_format) { + self::$today_format = $today_format; + } + } + + /** * Преобразует время в секунды. * * @param string $time @@ -168,4 +197,4 @@ class Format * Оффсет с учетом летнего/зимнего времени */ Format::setTimezoneOffset(date('Z') - ((date('I') ? 60*60 : 0 ))); -?> \ No newline at end of file +?> diff --git a/classes/Load.class.php b/classes/Load.class.php index 8fd2779..eb11f16 100644 --- a/classes/Load.class.php +++ b/classes/Load.class.php @@ -2,7 +2,7 @@ /** * * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Load @@ -42,4 +42,4 @@ class Load return self::$router ? self::$router : self::$router = new Router; } } -?> \ No newline at end of file +?> diff --git a/classes/MJException.class.php b/classes/MJException.class.php index 586abdc..bc6aa91 100644 --- a/classes/MJException.class.php +++ b/classes/MJException.class.php @@ -2,7 +2,7 @@ /** * Обработчик эксепшенов * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Core @@ -63,4 +63,4 @@ class MJException extends Exception return $return . ''; } } -?> \ No newline at end of file +?> diff --git a/classes/Mailer.class.php b/classes/Mailer.class.php index da0f508..6632010 100644 --- a/classes/Mailer.class.php +++ b/classes/Mailer.class.php @@ -2,7 +2,7 @@ /** * Класс для отправки мыла * -* @copyright +* @copyright netmonsters.ru * @link * @package Nakon * @subpackage face @@ -77,4 +77,4 @@ class Mailer return mail($email, $encoded_subject, $content, $this->headers); } } -?> \ No newline at end of file +?> diff --git a/classes/Model.class.php b/classes/Model.class.php index 9e3ea93..ff8ffd5 100644 --- a/classes/Model.class.php +++ b/classes/Model.class.php @@ -2,7 +2,7 @@ /** * Класс модели данных * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage DB @@ -61,9 +61,9 @@ abstract class Model return new ModelSelectResult($res); case 'insert': case 'replac': - return new ModelInsertResult($this->handler); + return new ModelInsertResult($this->handler, $res); //$res for postgreSQL default: - return new ModelChangeResult($this->handler); + return new ModelChangeResult($this->handler, $res); //$res for postgreSQL } } @@ -224,9 +224,9 @@ class ModelChangeResult extends ModelResult { public $affected; - function __construct($resource) + function __construct($resource, $result) { - $this->affected = DBConnector::affectedRows($resource); + $this->affected = DBConnector::affectedRows($resource, $result); } function count() @@ -239,9 +239,9 @@ class ModelInsertResult extends ModelChangeResult { public $id; - function __construct($resource) + function __construct($resource, $result) { - parent::__construct($resource); + parent::__construct($resource, $result); $this->id = DBConnector::getId($resource); } @@ -250,4 +250,4 @@ class ModelInsertResult extends ModelChangeResult return $this->id; } } -?> \ No newline at end of file +?> diff --git a/classes/PageController.class.php b/classes/PageController.class.php index 3784bac..c7eb1a2 100644 --- a/classes/PageController.class.php +++ b/classes/PageController.class.php @@ -2,7 +2,7 @@ /** * * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage PageController @@ -43,4 +43,4 @@ final class PageController } } } -?> \ No newline at end of file +?> diff --git a/classes/Pager.class.php b/classes/Pager.class.php index 0ea6bdb..eeaac8a 100644 --- a/classes/Pager.class.php +++ b/classes/Pager.class.php @@ -2,7 +2,7 @@ /** * PagerAction * - * @copyright + * @copyright netmonsters.ru * @link * @package Nakon * @subpackage face @@ -65,4 +65,4 @@ class Pager extends Action $this->templater->assign('count', $this->count); } } -?> \ No newline at end of file +?> diff --git a/classes/Router.class.php b/classes/Router.class.php index d866511..dbab7af 100644 --- a/classes/Router.class.php +++ b/classes/Router.class.php @@ -2,7 +2,7 @@ /** * Класс для работы с роутерами * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Core @@ -128,4 +128,4 @@ final class Route return true; } } -?> \ No newline at end of file +?> diff --git a/classes/StaticPageException.class.php b/classes/StaticPageException.class.php index da6359e..4729a84 100644 --- a/classes/StaticPageException.class.php +++ b/classes/StaticPageException.class.php @@ -3,7 +3,7 @@ /** * Эксепшен для вывода статических шаблонов * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Core @@ -15,4 +15,4 @@ class StaticPageException extends Exception { } -?> \ No newline at end of file +?> diff --git a/classes/Sublimer.class.php b/classes/Sublimer.class.php index 2e0723b..6bd13c4 100644 --- a/classes/Sublimer.class.php +++ b/classes/Sublimer.class.php @@ -3,7 +3,7 @@ * Простейший шаблонизатор. * Зато быстрый. * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Decorator @@ -132,4 +132,4 @@ final class Sublimer } -?> \ No newline at end of file +?> diff --git a/classes/User.class.php b/classes/User.class.php index 687204d..43519ae 100644 --- a/classes/User.class.php +++ b/classes/User.class.php @@ -2,7 +2,7 @@ /** * Класс для работы с пользователями * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage Decorator @@ -12,11 +12,11 @@ */ class User { - static private $user = false; + static private $user = false; - static function login($login, $password) - { - if (empty($login) || empty($password)) { + static function login($login, $password) + { + if (empty($login) || empty($password)) { return false; } @@ -25,7 +25,7 @@ class User } self::setInfo(self::getByLogin($login)); - if (!self::getInfo() || self::$user->isBanned()) { + if (!self::getInfo()) { return false; } @@ -34,22 +34,19 @@ class User } self::setSession(); - $model = new UserDataModel(); - $model->loginUpdate($login); - return true; - } + return true; + } - static function logout() - { + static function logout() + { Env::setCookie(session_name(), '', 0); Env::setCookie('login', '', 0); Env::setCookie('login_hash', '', 0); - Env::setCookie('login_ipbhash', '', 0); if (session_id()) { session_destroy(); } - } + } static function process() { @@ -61,106 +58,62 @@ class User } } - static function setSession() - { + static function setSession() + { $hash = self::getHash(); - Env::setCookie('login', self::$user->login, TIME_NOW + LOGIN_COOKIE_TTL); + Env::setCookie('login', self::$user->login, TIME_NOW + LOGIN_COOKIE_TTL); Env::setCookie('login_hash', $hash, TIME_NOW + LOGIN_COOKIE_TTL); - Env::setCookie('login_ipbhash', self::getIPBHash($hash), TIME_NOW + LOGIN_COOKIE_TTL); @session_start(); $_SESSION['user'] = self::$user; - } + } - static function remember() - { + static function remember() + { self::setInfo(self::getByLogin(Env::getCookie('login'))); - if (!self::getInfo()) { - self::logout(); - } - - if (Env::getCookie('login_hash') == self::getHash()) { - self::setSession(); - } else { - self::logout(); - } - } - - static function getHash() - { - return md5(self::$user->id.'hckrz'.self::$user->login.'mst'.self::$user->pass.'dai'); - } - - /** - * Создает хеш для проверки хеша в в IPB - * - */ - static public function getIPBHash($hash) + if (!self::getInfo()) { + self::logout(); + } + + if (Env::getCookie('login_hash') == self::getHash()) { + self::setSession(); + } else { + self::logout(); + } + } + + static function getHash() { - return md5($hash . strtolower(self::$user->login) . 'brainfuck'); + return md5(self::$user->id.'hckrz'.self::$user->login.'mst'.self::$user->pass.'dai'); } - static function getInfo() - { - return Env::Session('user', self::$user); - } + static function getInfo() + { + return Env::Session('user', self::$user); + } static function setInfo($data) { self::$user = $data; } - static function isGuest() - { - return ! (bool) Env::Session('user'); - } + static function isGuest() + { + return ! (bool) Env::Session('user'); + } - static function getByLogin($login) - { + static function getByLogin($login) + { $model = new UserDataModel(); return $model->getByLogin($login); - } + } static function getById($id) { $model = new UserDataModel(); return $model->getById($id); } - - - /** - * отправляет письмо для активации - * - * @param string $mail - * @param string $login - * - */ - static function sendActivateMail($mail, $login) - { - $settings = Env::getParam('site_settings'); - $model = new UserActivateModel(); - $link = 'http://' . $settings['host_name'] . '/activate/?key=' . $model->generateKey($login, $mail); - - $text = new SettingsTextModel(); - $message = $text->getText('mail_activate'); - - $replaces = array( - 'link' => $link, - 'host' => $settings['site_url'], - 'email' => $mail, - ); - - if (!$message) { - return false; - } - - foreach ($replaces as $key => $val) { - $message->text = str_replace('%' . $key . '%', $val, $message->text); - } - $mailer = new Mailer(); - return $mailer->sendMessage($mail, 'Подтверждение E-mail ' . $settings['host_name'], $message->text); - } } -?> \ No newline at end of file +?> diff --git a/classes/pg_DBConnector.class.php b/classes/pg_DBConnector.class.php index 50170c5..6ebc2ff 100644 --- a/classes/pg_DBConnector.class.php +++ b/classes/pg_DBConnector.class.php @@ -3,7 +3,7 @@ * Класс базы данных. * Возвращает идентификатор соединения * - * @copyright + * @copyright netmonsters.ru * @link * @package Majestic * @subpackage DB @@ -38,8 +38,8 @@ class DBConnector return self::$handlers[$handler_name]; } - if (!$handler = pg_connect("host='".$db_settings['host']."' dbname='".$db_settings['database']."' user='".$db_settings['user'].'" password="'.$db_settings['password']."'")) { - throw new MJException('Can\'t connect to DB '.pg_last_error($handler), 2); + if (!$handler = pg_connect("host='".$db_settings['host']."' dbname='".$db_settings['database']."' user='".$db_settings['user']."' password='".$db_settings['password']."'")) { + throw new MJException('Can\'t connect to DB '.pg_last_error(), 2); } return self::$handlers[$handler_name] = $handler; @@ -82,14 +82,14 @@ class DBConnector return pg_num_rows($result); } - static public function affectedRows($handler) + static public function affectedRows($handler, $result) { - return pg_affected_rows($handler); + return pg_affected_rows($result); } static public function getId($handler) { - return pg_last_oid($handler); + return -1; //DISABLED FORM postgreSQL } static public function autocommit($handler, $switch) @@ -107,4 +107,4 @@ class DBConnector throw new MJException('Rollback disabled for postgreSQL Connector' ,1); } } -?> \ No newline at end of file +?> diff --git a/init/init.inc.php b/init/init.inc.php index 010bf59..8bfa784 100644 --- a/init/init.inc.php +++ b/init/init.inc.php @@ -2,7 +2,7 @@ /** * Файл роутеров * - * @copyright + * @copyright netmonsters.ru * @link * @package Nakon * @subpackage Config @@ -25,4 +25,4 @@ require(CONFIG_PATH.'/routers.inc.php'); define('E_404', 404); define('E_403', 403); -?> \ No newline at end of file +?> diff --git a/init/sys.inc.php b/init/sys.inc.php index c979baf..48e1619 100644 --- a/init/sys.inc.php +++ b/init/sys.inc.php @@ -4,7 +4,7 @@ * Если вы не меняли стандартное расположение файлов, * то ничего тут править не надо. * - * @copyright + * @copyright netmonsters.ru * @link * @package Nakon * @subpackage System @@ -97,4 +97,4 @@ function __autoload($name) require(LIB_PATH.'/'.$name.'.lib.php'); } } -?> \ No newline at end of file +?>