Merge branch 'master' of http://gitlab.edu.yar.ru/composer/PHP_Library into dev
This commit is contained in:
commit
f33afc2861
18 changed files with 240 additions and 48 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ class Mail
|
|||
$this->_to = $name;
|
||||
}
|
||||
|
||||
function replyTo($name) // recipient
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка получателей копии
|
||||
*/
|
||||
|
|
|
|||
90
src/MailAlt.php
Normal file
90
src/MailAlt.php
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
class MailAlt
|
||||
{
|
||||
public $mailer;
|
||||
|
||||
function __construct() {
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
32
src/Model/Factory.php
Normal file
32
src/Model/Factory.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
class Model_Factory
|
||||
{
|
||||
static $shortcut = "model";
|
||||
public $db;
|
||||
public $_registry;
|
||||
public $_shortcut;
|
||||
|
||||
public function __construct (/*.Database.*/ $db, Settings $_registry = null)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
/**
|
||||
* Проверка формата электронной почты
|
||||
*/
|
||||
class Validator_Rule_Code extends Rule_Abstract
|
||||
class Validator_Rule_Code extends Validator_Rule_Abstract
|
||||
{
|
||||
public function getErrorMsg()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
57
src/View/Pages.php
Normal file
57
src/View/Pages.php
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
/**
|
||||
* @package system.widgets
|
||||
*/
|
||||
|
||||
class View_Pages
|
||||
{
|
||||
static $range = 5;
|
||||
static function getPages($page, $onpage, $count, $prefix = '?')
|
||||
{
|
||||
$n = ceil($count / $onpage);
|
||||
if ($page > $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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue