diff --git a/src/Connection/HttpRequest.php b/src/Connection/HttpRequest.php index 28d0515..87a2561 100644 --- a/src/Connection/HttpRequest.php +++ b/src/Connection/HttpRequest.php @@ -81,7 +81,7 @@ class Connection_HttpRequest $port = ($this->proxy_port) ? $this->proxy_port : $this->port; $errno = 0; $errstr = ''; - $socket = fsockopen($host, $port, $errno, $errstr, 30); + $socket = @fsockopen($host, $port, $errno, $errstr, 30); if (is_resource($socket)) { $header = $this->getHeader(); fwrite($socket, $header); diff --git a/src/Controller/Action.php b/src/Controller/Action.php index 6e314e2..9d5753f 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -62,6 +62,7 @@ class Controller_Action public function loadConfig($name) { $filename = Shortcut::getUrl('config', $name); + $settings = []; if (file_exists($filename)) { include($filename); } else { @@ -210,7 +211,8 @@ class Controller_Action public function nUrl($name, array $param = array()) { /*.Filter_ActionAccess.*/$access = $this->access; - if ($access != null || $access->checkAction($name)) { + + if ($access == null || $access->checkAction($name)) { return lcurry(array($this, 'postUrl'), $name, $param); } return null; @@ -372,4 +374,9 @@ class Controller_Action { $this->_getActionPath()->getPath($this, ($action) ? $action : $request->getAction()); } + + function redirect($action) { + header('location: ' . $this->fUrl($action)); + exit(); + } } diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 0c95af2..1f53e91 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -66,7 +66,13 @@ class Controller_Component function execute(HttpRequest $request, $has_id = true) { $crequest = new ComponentRequest($this->component_id, $request); - $action = 'action' . ucfirst($request->get('action', 'index')); + + $_action = $request->get('action', 'index'); + if (is_array($_action)) { + $action = 'action' . ucfirst(Arr::get($_action, $this->component_id, 'index')); + } else { + $action = 'action' . ucfirst($_action); + } $this->before(); if (method_exists($this, $action)) { @@ -106,7 +112,9 @@ class Controller_Component $tpl->set('common', Path::join(WWW_PATH, '../', 'common')); $tpl->set('script', Path::join(WWW_PATH, 'js')); $tpl->set('media', Path::join(TEMPLATE_WEB, $template)); - $tpl->set('site_template', SITE_WWW_PATH . '/templates' . $registry->readKey(array('system', 'template'))); + if ($registry) { + $tpl->set('site_template', SITE_WWW_PATH . '/templates' . $registry->readKey(array('system', 'template'))); + } $tpl->set('base', SITE_WWW_PATH); $tpl->set('component_base', $this->webPath[$selected]); @@ -125,14 +133,6 @@ class Controller_Component return Path::join($this->webPath[0], 'templates', 'modern'); } - /** - * @param $name Имя модели - */ - private function getModelPath($name) - { - return Path::join (CMS_PATH, "model", $name . ".php"); - } - /** * Создает модель * @param string $name @@ -140,9 +140,8 @@ class Controller_Component */ public function getModel($name) { - require_once ($this->getModelPath ($name)); - $modelName = $name . "Mapper"; - $model = new $modelName (); + $modelName = "Mapper_" . $name; + $model = new $modelName(); $model->db = $this->db; return $model; } @@ -188,7 +187,7 @@ class Controller_Component $view->component_title = $settings['title']; } - static function loadComponent($expression, Database $db, Settings $registry) + static function loadComponent($expression, Database $db, /*.Settings.*/ $registry) { $expression = htmlspecialchars_decode($expression); @@ -322,11 +321,7 @@ class Controller_Component */ function addRequireJsPath($name, $path, $shim = null) { - global $requireJsConfig; - $requireJsConfig['paths'][$name] = $path; - if ($shim) { - $requireJsConfig['shim'][$name] = $shim; - } + Controller_Site::addRequireJsPath($name, $path, $shim); } function actionIndex(/*.ComponentRequest.*/ $request) { diff --git a/src/Controller/Installer.php b/src/Controller/Installer.php index dcc4562..d20a93d 100644 --- a/src/Controller/Installer.php +++ b/src/Controller/Installer.php @@ -48,7 +48,7 @@ class Controller_Installer foreach ($sql as $version => $install) { if (version_compare($version, $version_new, "<=") && version_compare($version, $version_old, ">")) { $file = Path::join(call_user_func($this->installPath, $name), "sql", $install); - $json_installer->install($file,null); + $json_installer->install($file, null); $result[] = $version; } } @@ -64,11 +64,13 @@ class Controller_Installer $this->_registry->removeKey($name); $this->_registry->write(); } + // Устанавливает обновления если есть function doUpdates($name, $force = false) // Установка модуля { $result = array(); $setup = $this->getSetupFile($name); + if (file_exists($setup) && ($this->isChanged($name) || $force)) { $registry = $this->_registry; $settings = new Settings($setup); @@ -91,21 +93,22 @@ class Controller_Installer $result[]=$res; } } - } - // Обновление версии меню - $registry->removeKey($name); - $registry->writeKey(array($name), $settings->get('settings')); - $registry->writeKey(array($name), + // Обновление версии меню + $registry->removeKey($name); + $registry->writeKey(array($name), $settings->get('settings')); + $registry->writeKey(array($name), array('version' => $version_new, 'time' => filemtime($setup))); + } + $registry->write(); } return $result; } - function install($dbinit_path,$dbfill_path=null){ + function install($dbinit_path, $dbfill_path = null) { $json_installer = new Database_JsonInstall($this->db_manager); - $json_installer->install($dbinit_path,$dbfill_path); + $json_installer->install($dbinit_path, $dbfill_path); } } diff --git a/src/Database.php b/src/Database.php index 0d8813e..2ddc1f4 100644 --- a/src/Database.php +++ b/src/Database.php @@ -29,7 +29,7 @@ class Database extends PDO { if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') { - $port = (isset($dsn['port'])) ? "port={$dsn['port']};" : ""; + $port = (isset($dsn['port'])) ? "port={$dsn['port']};" : ""; /*.Database.*/$connection = new static("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']); if ($dsn['phptype'] == 'pgsql') { $connection->query('SET client_encoding="UTF-8"'); diff --git a/src/Database/JsonInstall.php b/src/Database/JsonInstall.php index ee62cf3..54a7d6f 100644 --- a/src/Database/JsonInstall.php +++ b/src/Database/JsonInstall.php @@ -14,11 +14,11 @@ class Database_JsonInstall { if (is_string($dbinit_file)) { $initActions = json_decode($dbinit_file, true); if (!$initActions) { - echo "Invalid dbinit.json ".$dbinit_file; + echo "Invalid ".$dbinit_path; return 0; } } else { - echo "No dbinit.json"; + echo "No ".$dbinit_path; return 0; } diff --git a/src/Excel/Document.php b/src/Excel/Document.php index e46ff31..365dba3 100644 --- a/src/Excel/Document.php +++ b/src/Excel/Document.php @@ -76,7 +76,9 @@ class Excel_Document { function save($filename) { $doc = new XMLWriter(); - $doc->openURI($filename); + if (!$doc->openURI($filename)) { + throw new Exception("unknown file " . $filename); + } $doc->setIndent(false); $doc->startDocument('1.0','utf-8'); $doc->startElement('Workbook'); diff --git a/src/Filter/Authorization.php b/src/Filter/Authorization.php index 17db6a6..5afd556 100644 --- a/src/Filter/Authorization.php +++ b/src/Filter/Authorization.php @@ -4,14 +4,14 @@ class Filter_Authorization { const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#'; const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign'; - static function isLogged() { + static function isLogged($group = 'access') { +// echo session_status(); if (session_status() == PHP_SESSION_NONE) { session_start(); } $hash = self::getBrowserSign(); // Если $hash не совпадает $_SESSION['hash'] то удаляем сессию - if (isset($_SESSION ['access']) && isset($_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME])) { - + if (isset($_SESSION[$group]) && isset($_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME])) { if ($hash == $_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME]) { // UserAccess::getUserById($_SESSION ['access']); // Поиск по идентификатору return true; @@ -22,14 +22,14 @@ class Filter_Authorization { return false; } - static function enter($id) + static function enter($id, $group = 'access') { // $db->executeQuery("UPDATE visitor SET sid = '' WHERE id_visitor = " . $result->getInt('id_user')); - session_register("access"); - session_register("time"); +// session_register("access"); +// session_register("time"); // $_SESSION ["group"] = $result->getInt('access'); - $_SESSION ["access"] = $id; // id_user + $_SESSION [$group] = $id; // id_user $_SESSION [self::SESSION_BROWSER_SIGN_KEYNAME] = self::getBrowserSign(); $_SESSION ["time"] = time(); } diff --git a/src/Form/Form.php b/src/Form/Form.php index 585f06a..f79c9f3 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -217,9 +217,9 @@ class OptionFactory { } else if (isset($input['options.db'])) { list($table, $keyvalue) = explode(":", $input['options.db']); list($key, $value) = explode(",", $keyvalue); - try{ + try { $query_result = $this->db->executeQuery("SELECT * FROM $table"); - }catch(Exception $ex){ + } catch(Exception $ex) { $query_result = []; } $field->options = $this->optionsDB($key, $value, $query_result); @@ -288,7 +288,7 @@ class Form_Form extends View_View { 'color' => 'TColor', 'textarea' => 'TTextArea', - 'text' => 'TTextArea', + 'text' => 'TTextArea', 'multiselect' => 'TSelectMany', // 'selectmany' => 'TSelectMany', 'select1' => 'TSelectOne', @@ -302,6 +302,7 @@ class Form_Form extends View_View { 'hidden' => 'THidden', 'radio' => 'TSelectOne', 'filebrowser' => 'TComponentBrowserInput', + 'documents' => 'TComponentBrowserInput', ); } diff --git a/src/Mail.php b/src/Mail.php index f27a0a8..1f4eda4 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -40,6 +40,10 @@ class Mail $this->_to = $name; } + function replyTo($name) // recipient + { + } + /** * Установка получателей копии */ diff --git a/src/MailAlt.php b/src/MailAlt.php new file mode 100644 index 0000000..f8761f6 --- /dev/null +++ b/src/MailAlt.php @@ -0,0 +1,90 @@ +mailer = new PHPMailer(); + $this->mailer->CharSet = 'UTF-8'; + } + + /** + * Установка отправителя + */ + function from($name) + { + $this->mailer->setFrom($name); + } + + /** + * Установка получателя + */ + function to($name) // recipient + { + $this->mailer->addAddress($name); + } + + function replyTo($name) // recipient + { + $this->mailer->AddReplyTo($name); + } + + /** + * Установка получателей копии + */ + function copy($name) // recipient cc + { + $this->addCC($name); + } + + function notify($notify) + { + $this->_notify = $notify; + } + + /** + * Тема письма + */ + function subject($subject) + { + $this->mailer->Subject = $subject; + } + + /** + * Текст письма + */ + function setContent($text) + { + $this->mailer->Body = $text; + } + + function setType($text) + { + $this->mailer->isHTML($text == 'text/html'); + } + + /** + * Кодировка текста в письме + */ + function setEncoding($encoding) + { + $this->encoding = $encoding; + } + + /** + * Добавление вложения из файла + */ + function addAttachment($filename, $name = false) + { + $this->mailer->addAttachment($filename, $name); + } + + /** + * Отправка почты + */ + function send() + { + return $this->mailer->send(); + } +} diff --git a/src/Model/Factory.php b/src/Model/Factory.php new file mode 100644 index 0000000..30ceb8c --- /dev/null +++ b/src/Model/Factory.php @@ -0,0 +1,32 @@ +db = $db; + $this->_registry = $_registry; + } + + /** + * Создает модель + * @param string $name + * @return model + */ + public function getModel ($name) + { + $modelName = "Mapper_" . $name; + $model = new $modelName(); + $model->db = $this->db; + $model->factory = $this; + $model->_registry = $this->_registry; + $model->setUp(); + // + return $model; + } +} diff --git a/src/security.php b/src/Security.php similarity index 100% rename from src/security.php rename to src/Security.php diff --git a/src/Validator/Rule/Code.php b/src/Validator/Rule/Code.php index 54514e2..2bcfbf8 100644 --- a/src/Validator/Rule/Code.php +++ b/src/Validator/Rule/Code.php @@ -3,7 +3,7 @@ /** * Проверка формата электронной почты */ -class Validator_Rule_Code extends Rule_Abstract +class Validator_Rule_Code extends Validator_Rule_Abstract { public function getErrorMsg() { diff --git a/src/Validator/Rule/Count.php b/src/Validator/Rule/Count.php index f8c1800..2afd612 100644 --- a/src/Validator/Rule/Count.php +++ b/src/Validator/Rule/Count.php @@ -3,7 +3,7 @@ /** * Проверка формата даты */ -class Validator_Rule_Count extends Rule_Abstract +class Validator_Rule_Count extends Validator_Rule_Abstract { public $size = 1; public $max = false; diff --git a/src/Validator/Rule/IsFile.php b/src/Validator/Rule/IsFile.php index c19cf12..64d5f97 100644 --- a/src/Validator/Rule/IsFile.php +++ b/src/Validator/Rule/IsFile.php @@ -3,7 +3,7 @@ /** * Проверка формата времени */ -class Validator_Rule_IsFile extends Rule_Abstract +class Validator_Rule_IsFile extends Validator_Rule_Abstract { private $type = array(); private $maxsize = 1024; diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index fe3ea2e..c429efe 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -44,6 +44,7 @@ class Validator_Validator // Список правил if (! isset($value['validate'])) continue; $rules = explode("|", $value['validate']); + foreach ($rules as $rule) { // Список параметров правила $rule_param = explode(",", $rule); @@ -61,14 +62,14 @@ class Validator_Validator $ruleObj->$p_name = $p_value; } $this->addRule($ruleObj); - } else { + } else if (!empty($rule)) { throw new Exception('Unknown validation rule "' . $rule . "'"); } } } } - public function addRule(/*.any.*/&$rule) { + public function addRule(/*.any.*/$rule) { if (is_array($rule)) { $this->chain = array_merge($this->chain, $rule); } else { diff --git a/src/View/Pages.php b/src/View/Pages.php new file mode 100644 index 0000000..736a861 --- /dev/null +++ b/src/View/Pages.php @@ -0,0 +1,57 @@ + $n) $page = $n; + if ($page < 1) $page = 1; + $url = 'page='; + $result = array(); + for ($i = max($page - self::$range, 1); $i <= min($n, $page + self::$range); $i++) { + $result [] = array('page' => $i, 'href' => ($i != $page) ? self::href($prefix, $url . $i) : false); + } + return array( + 'all' => ($n > 1), + 'list' => $result, + 'first' => self::href($prefix, $url . 1), + 'last' => self::href($prefix, $url . $n), + 'next' => ($page == $n)? false : self::href($prefix, $url . ($page + 1)) , + 'prev' => ($page == 1)? false : self::href($prefix, $url . ($page - 1))); + } + + /** + * @deprecated + * @param $page int номер страницы + * @param $onpage int количество элем на странице + * @return string + */ + static function getLimit(/*.number.*/$page, /*.number.*/$onpage) { + if ($page <= 0) { $page = 1; } + return "LIMIT $onpage OFFSET " . ($page - 1) * $onpage; + } + + /** + * @param $page int номер страницы + * @param $onpage int количество элем на странице + * @return array + */ + static function _getLimit($page, $onpage) { + if ($page <= 0) { $page = 1; } + return array( + 'count' => $onpage, + 'start' => ($page - 1) * $onpage, + ); + } + + static function href($prefix, $x) { + return $prefix . $x; + } + +} +