Изменен механизм расширения ссылок. Избавление от глобальных переменных
This commit is contained in:
parent
524b27936a
commit
40fad0e75b
11 changed files with 77 additions and 61 deletions
|
|
@ -5,12 +5,12 @@ use ctiso\Shortcut,
|
||||||
Exception,
|
Exception,
|
||||||
ctiso\Path,
|
ctiso\Path,
|
||||||
ctiso\Url,
|
ctiso\Url,
|
||||||
ctiso\View\View,
|
|
||||||
ctiso\Model\Factory,
|
ctiso\Model\Factory,
|
||||||
ctiso\HttpRequest,
|
ctiso\HttpRequest,
|
||||||
ctiso\Functions,
|
ctiso\Functions,
|
||||||
ctiso\Settings,
|
ctiso\Settings,
|
||||||
ctiso\View\Composite,
|
ctiso\View\Composite,
|
||||||
|
ctiso\Filter\ActionAccess,
|
||||||
ctiso\View\View,
|
ctiso\View\View,
|
||||||
ctiso\Controller\State;
|
ctiso\Controller\State;
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ class Action
|
||||||
|
|
||||||
private $factory = null; // Ссылка на обьект создания модели
|
private $factory = null; // Ссылка на обьект создания модели
|
||||||
private $helpers = array(); // Помошники для действий
|
private $helpers = array(); // Помошники для действий
|
||||||
public $param = array(); // Параметры для ссылки
|
public $part = null; // Параметры для ссылки
|
||||||
|
|
||||||
public /*.Settings.*/$settings; // Ссылка на настройки
|
public /*.Settings.*/$settings; // Ссылка на настройки
|
||||||
public $user; // Обьект пользователя
|
public $user; // Обьект пользователя
|
||||||
|
|
@ -55,6 +55,7 @@ class Action
|
||||||
public $childViews = array();
|
public $childViews = array();
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
|
$this->part = new Url();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
|
|
@ -198,6 +199,10 @@ class Action
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addUrlPart($key, $value) {
|
||||||
|
$this->part->addQueryParam($key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Генерация ссылки c учетом прав пользователя на ссылки
|
* Генерация ссылки c учетом прав пользователя на ссылки
|
||||||
* @param string $name Действие
|
* @param string $name Действие
|
||||||
|
|
@ -208,16 +213,20 @@ class Action
|
||||||
public function nUrl($name, array $param = array())
|
public function nUrl($name, array $param = array())
|
||||||
{
|
{
|
||||||
/*.ActionAccess.*/$access = $this->access;
|
/*.ActionAccess.*/$access = $this->access;
|
||||||
|
$url = new Url();
|
||||||
|
|
||||||
if ($access == null || $access->checkAction($name)) {
|
if ($access == null || $access->checkAction($name)) {
|
||||||
$param = array_merge(array(
|
$param = array_merge(array(
|
||||||
'module' => strtr($this->modulePrefix . strtolower(get_class($this)), array('module_' => '')),
|
'module' => strtr($this->modulePrefix . strtolower(get_class($this)), array('module_' => '')),
|
||||||
"action" => $name
|
"action" => $name
|
||||||
|
|
||||||
), $param);
|
), $param);
|
||||||
|
|
||||||
return new Url($param);
|
$url->setParent($this->part);
|
||||||
|
$url->setQuery($param);
|
||||||
}
|
}
|
||||||
return new Url();
|
|
||||||
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -318,7 +327,7 @@ class Action
|
||||||
*/
|
*/
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
if ($this->view instanceof View_View) {
|
if ($this->view instanceof View) {
|
||||||
$this->view->assignValues($this->ctrlValues);
|
$this->view->assignValues($this->ctrlValues);
|
||||||
|
|
||||||
/*.Composite.*/$node = null;
|
/*.Composite.*/$node = null;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use ctiso\HttpRequest,
|
||||||
ctiso\File,
|
ctiso\File,
|
||||||
ctiso\Form\Form,
|
ctiso\Form\Form,
|
||||||
ctiso\Form\OptionFactory,
|
ctiso\Form\OptionFactory,
|
||||||
|
ctiso\View\Composite,
|
||||||
ctiso\Database,
|
ctiso\Database,
|
||||||
ctiso\Database\PDOStatement,
|
ctiso\Database\PDOStatement,
|
||||||
ctiso\Collection,
|
ctiso\Collection,
|
||||||
|
|
@ -38,7 +39,7 @@ class FakeTemplate {
|
||||||
}
|
}
|
||||||
|
|
||||||
function execute() {
|
function execute() {
|
||||||
return $this->_data;
|
return json_encode($this->_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,6 +65,7 @@ class Component
|
||||||
|
|
||||||
public $module;
|
public $module;
|
||||||
public $item_module;
|
public $item_module;
|
||||||
|
public $site;
|
||||||
|
|
||||||
function before() {
|
function before() {
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +97,6 @@ class Component
|
||||||
return new FakeTemplate($name);
|
return new FakeTemplate($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
/*.Settings.*/$registry = $this->registry;
|
/*.Settings.*/$registry = $this->registry;
|
||||||
$template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template'));
|
$template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template'));
|
||||||
|
|
||||||
|
|
@ -195,7 +196,7 @@ class Component
|
||||||
/**
|
/**
|
||||||
* Генерация интерфейса для выбора галлереи фотографии
|
* Генерация интерфейса для выбора галлереи фотографии
|
||||||
*/
|
*/
|
||||||
public function setParameters(/*.Composite.*/$view)
|
public function setParameters(/*.Composite.*/ $view)
|
||||||
{
|
{
|
||||||
$form = new Form();
|
$form = new Form();
|
||||||
$options = new OptionFactory($this->db, $this->registry);
|
$options = new OptionFactory($this->db, $this->registry);
|
||||||
|
|
@ -208,7 +209,7 @@ class Component
|
||||||
$view->component_title = $settings['title'];
|
$view->component_title = $settings['title'];
|
||||||
}
|
}
|
||||||
|
|
||||||
static function loadComponent($expression, Database $db, /*.Settings.*/ $registry)
|
static function loadComponent($expression, /*.Site.*/ $site)
|
||||||
{
|
{
|
||||||
|
|
||||||
$expression = htmlspecialchars_decode($expression);
|
$expression = htmlspecialchars_decode($expression);
|
||||||
|
|
@ -232,22 +233,16 @@ class Component
|
||||||
|
|
||||||
if (file_exists($path)) {
|
if (file_exists($path)) {
|
||||||
require_once ($path);
|
require_once ($path);
|
||||||
|
|
||||||
$component = new $className();
|
$component = new $className();
|
||||||
$component->db = $db;
|
|
||||||
$component->registry = $registry;
|
|
||||||
|
|
||||||
$component->viewPath = array(BASE_PATH . '/components/' . $name . '/');
|
$component->viewPath = array(BASE_PATH . '/components/' . $name . '/');
|
||||||
$component->webPath = array(SITE_WWW_PATH . '/components/' . $name);
|
$component->webPath = array(SITE_WWW_PATH . '/components/' . $name);
|
||||||
|
|
||||||
$component->COMPONENTS_WEB = SITE_WWW_PATH . '/components/';
|
$component->COMPONENTS_WEB = SITE_WWW_PATH . '/components/';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$path = Path::join (COMPONENTS, $name, $name . '.php');
|
$path = Path::join (COMPONENTS, $name, $name . '.php');
|
||||||
require_once ($path);
|
require_once ($path);
|
||||||
$component = new $className();
|
$component = new $className();
|
||||||
$component->db = $db;
|
|
||||||
$component->registry = $registry;
|
|
||||||
|
|
||||||
$component->viewPath = array(COMPONENTS . '/' . $name . '/', BASE_PATH . '/components/' . $name . '/');
|
$component->viewPath = array(COMPONENTS . '/' . $name . '/', BASE_PATH . '/components/' . $name . '/');
|
||||||
if (defined('COMPONENTS_WEB')) {
|
if (defined('COMPONENTS_WEB')) {
|
||||||
|
|
@ -255,6 +250,12 @@ class Component
|
||||||
$component->COMPONENTS_WEB = COMPONENTS_WEB;
|
$component->COMPONENTS_WEB = COMPONENTS_WEB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$db = $site->db;
|
||||||
|
|
||||||
|
$component->db = $db;
|
||||||
|
$component->registry = $site->registry;
|
||||||
|
$component->site = $site;
|
||||||
|
|
||||||
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");
|
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");
|
||||||
$stmt->setString(1, $expression);
|
$stmt->setString(1, $expression);
|
||||||
|
|
@ -282,18 +283,13 @@ class Component
|
||||||
|
|
||||||
$params = new Collection();
|
$params = new Collection();
|
||||||
$params->import($arguments);
|
$params->import($arguments);
|
||||||
|
|
||||||
$component->parameter = $params;
|
$component->parameter = $params;
|
||||||
$component->template = $params->get('template', false);
|
$component->template = $params->get('template', false);
|
||||||
|
|
||||||
$editor = $component->getEditUrl();
|
$editor = $component->getEditUrl();
|
||||||
if ($editor) {
|
if ($editor) {
|
||||||
if (class_exists("Controller_Site")) { //Если мы в CMS2
|
$site->componentsConfig[] = $editor;
|
||||||
$instance = Site::getInstance();
|
|
||||||
$instance->componentsConfig[] = $editor;
|
|
||||||
} else {
|
|
||||||
global $componentsConfig;
|
|
||||||
$componentsConfig[] = $editor;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $component;
|
return $component;
|
||||||
|
|
@ -338,12 +334,8 @@ class Component
|
||||||
return '?' . http_build_query($arr);
|
return '?' . http_build_query($arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated В CMS2 перенесено в контроллер сайта!
|
|
||||||
*/
|
|
||||||
|
|
||||||
function addRequireJsPath($name, $path, $shim = null) {
|
function addRequireJsPath($name, $path, $shim = null) {
|
||||||
Site::addRequireJsPath($name, $path, $shim);
|
$this->site->addRequireJsPath($name, $path, $shim);
|
||||||
}
|
}
|
||||||
|
|
||||||
function actionIndex(/*.ComponentRequest.*/ $request) {
|
function actionIndex(/*.ComponentRequest.*/ $request) {
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class Front extends Action
|
||||||
return $module->access->execute($request);
|
return $module->access->execute($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$system = $this->settings['system'];
|
/*.Settings.*/$system = $this->settings['system'];
|
||||||
|
|
||||||
$moulesPath = Path::join($this->settings['base'], $system->readKey(['path', 'modules']));
|
$moulesPath = Path::join($this->settings['base'], $system->readKey(['path', 'modules']));
|
||||||
$logPath = Path::join($this->settings['site'], $system->readKey(['path', 'access.log']));
|
$logPath = Path::join($this->settings['site'], $system->readKey(['path', 'access.log']));
|
||||||
|
|
|
||||||
|
|
@ -181,8 +181,8 @@ class Database extends PDO
|
||||||
return $result['nextval'];
|
return $result['nextval'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare($query) {
|
function prepare($query, $options = NULL) {
|
||||||
/*.PDOStatement.*/$result = $this->prepare($query);
|
/*.PDOStatement.*/$result = parent::prepare($query);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace ctiso\Filter;
|
namespace ctiso\Filter;
|
||||||
use ctiso\HttpRequest;
|
use ctiso\HttpRequest;
|
||||||
|
|
||||||
|
/* Переделать формат Логов на список json */
|
||||||
class ActionLogger
|
class ActionLogger
|
||||||
{
|
{
|
||||||
public $before = array();
|
public $before = array();
|
||||||
|
|
@ -14,13 +15,19 @@ class ActionLogger
|
||||||
function __construct(/*.Filter.*/$processor, $logPath, $user) {
|
function __construct(/*.Filter.*/$processor, $logPath, $user) {
|
||||||
$this->processor = $processor;
|
$this->processor = $processor;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->file = fopen($logPath, "a");
|
$file = fopen($logPath, "a");
|
||||||
|
if (is_resource($file)) {
|
||||||
|
$this->file = $file;
|
||||||
|
} else {
|
||||||
|
throw new \Exception('Ошибка открытия файла ' . $logPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function execute(HttpRequest $request) {
|
function execute(HttpRequest $request) {
|
||||||
$action = $request->getAction();
|
$action = $request->getAction();
|
||||||
if(in_array($action, $this->before)) {
|
if(in_array($action, $this->before)) {
|
||||||
fwrite($this->file, "time: " . date("r", time()) . " query: ". json_encode(array_merge($_POST, $_GET)) . " by: " . $this->user->name . "\n");
|
$message = ["time" => date("r", time()), "query" => array_merge($_POST, $_GET), "user" => $this->user->name];
|
||||||
|
fwrite($this->file, json_encode($message) . "\n");
|
||||||
}
|
}
|
||||||
return $this->processor->execute($request);
|
return $this->processor->execute($request);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ class Login extends Filter
|
||||||
/* ---------------------
|
/* ---------------------
|
||||||
* Проверка на попадание реквеста в белый список
|
* Проверка на попадание реквеста в белый список
|
||||||
*/
|
*/
|
||||||
public function requestIsWhite(Collection $request, $whiteRequestList){
|
public function requestIsWhite(HttpRequest $request, $whiteRequestList){
|
||||||
$module = $request->get('module');
|
$module = $request->get('module');
|
||||||
$action = $request->get('action');
|
$action = $request->get('action');
|
||||||
foreach ($whiteRequestList as $whiteRequest) {
|
foreach ($whiteRequestList as $whiteRequest) {
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,6 @@ use Exception,
|
||||||
ctiso\Collection,
|
ctiso\Collection,
|
||||||
ctiso\Session;
|
ctiso\Session;
|
||||||
|
|
||||||
class WrongRequestException extends Exception
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// HTTPRequest = ArrayAccess
|
// HTTPRequest = ArrayAccess
|
||||||
class HttpRequest extends Collection implements ArrayAccess
|
class HttpRequest extends Collection implements ArrayAccess
|
||||||
{
|
{
|
||||||
|
|
@ -132,4 +128,8 @@ class HttpRequest extends Collection implements ArrayAccess
|
||||||
|
|
||||||
public function offsetGet($key) {
|
public function offsetGet($key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function getProtocol() {
|
||||||
|
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@ use PHPTAL_Php_TalesInternal,
|
||||||
class Tales_DateTime implements PHPTAL_Tales
|
class Tales_DateTime implements PHPTAL_Tales
|
||||||
{
|
{
|
||||||
static public function date($expression, $nothrow = false) {
|
static public function date($expression, $nothrow = false) {
|
||||||
return "ctiso\\Tales::phptal_date(".PHPTAL_Php_TalesInternal::path ($expression).")";
|
return "ctiso\\Tales::phptal_date(".PHPTAL_Php_TalesInternal::path($expression).")";
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function time($expression, $nothrow = false) {
|
static public function time($expression, $nothrow = false) {
|
||||||
return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path ($expression).")";
|
return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path($expression).")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,8 +32,7 @@ class Tales_Component implements PHPTAL_Tales
|
||||||
}
|
}
|
||||||
|
|
||||||
class Tales {
|
class Tales {
|
||||||
static $db;
|
static $site;
|
||||||
static $registry;
|
|
||||||
|
|
||||||
static function phptal_date ($e) {
|
static function phptal_date ($e) {
|
||||||
return date("d.m.Y", $e);
|
return date("d.m.Y", $e);
|
||||||
|
|
@ -50,11 +49,7 @@ class Tales {
|
||||||
$begin = floatval(microtime(true));
|
$begin = floatval(microtime(true));
|
||||||
/*.Component.*/$component = null;
|
/*.Component.*/$component = null;
|
||||||
|
|
||||||
if (class_exists("ctiso\\Controller\\Site")) { //Если мы в CMS2
|
$component = self::$site->loadComponent($expression);
|
||||||
$component = Site::loadComponent($expression);
|
|
||||||
} else {
|
|
||||||
$component = Component::loadComponent($expression, self::$db, self::$registry);
|
|
||||||
}
|
|
||||||
$req = new HttpRequest();
|
$req = new HttpRequest();
|
||||||
$result = $component->execute($req);
|
$result = $component->execute($req);
|
||||||
|
|
||||||
|
|
@ -63,9 +58,8 @@ class Tales {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static function register($db, $registry) {
|
static function register($site) {
|
||||||
self::$db = $db;
|
self::$site = $site;
|
||||||
self::$registry = $registry;
|
|
||||||
|
|
||||||
/* Регистрация нового префикса для подключения компонента */
|
/* Регистрация нового префикса для подключения компонента */
|
||||||
$tales = PHPTAL_TalesRegistry::getInstance();
|
$tales = PHPTAL_TalesRegistry::getInstance();
|
||||||
|
|
|
||||||
18
src/Url.php
18
src/Url.php
|
|
@ -3,13 +3,25 @@
|
||||||
namespace ctiso;
|
namespace ctiso;
|
||||||
|
|
||||||
class Url {
|
class Url {
|
||||||
public $parts;
|
public $parts = [];
|
||||||
|
public $parent;
|
||||||
|
|
||||||
function __construct($parts = []) {
|
function __construct() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function setParent($parent) {
|
||||||
|
$this->parent = $parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setQuery($parts) {
|
||||||
$this->parts = $parts;
|
$this->parts = $parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addQueryParam($key, $value) {
|
||||||
|
$this->parts[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
function toString() {
|
function toString() {
|
||||||
return '?' . http_build_query($this->parts);
|
return '?' . http_build_query(array_merge($this->parts, $this->parent->parts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -10,9 +10,11 @@ class Page extends View
|
||||||
{
|
{
|
||||||
private $counter;
|
private $counter;
|
||||||
public $text;
|
public $text;
|
||||||
|
public $site;
|
||||||
|
|
||||||
function __construct($data)
|
function __construct($data, $site)
|
||||||
{
|
{
|
||||||
|
$this->site = $site;
|
||||||
// Вставка компонентов на странице
|
// Вставка компонентов на странице
|
||||||
$pattern = '/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u';
|
$pattern = '/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u';
|
||||||
$matches = array();
|
$matches = array();
|
||||||
|
|
@ -53,15 +55,8 @@ class Page extends View
|
||||||
|
|
||||||
function replaceContent($match, $offset)
|
function replaceContent($match, $offset)
|
||||||
{
|
{
|
||||||
//$result = phptal_component($match, $offset);
|
|
||||||
/*.Component.*/$component = null;
|
/*.Component.*/$component = null;
|
||||||
|
$component = $this->site->loadComponent($match);
|
||||||
if (class_exists("App\\Controller\\Site")) { //Если мы в CMS2
|
|
||||||
$component = Site::loadComponent($match);
|
|
||||||
} else {
|
|
||||||
global $db, $registry; //
|
|
||||||
$component = Component::loadComponent($match, $db, $registry);
|
|
||||||
}
|
|
||||||
|
|
||||||
$req = new HttpRequest();
|
$req = new HttpRequest();
|
||||||
unset($req['active_page']);
|
unset($req['active_page']);
|
||||||
|
|
|
||||||
7
src/WrongRequestException.php
Normal file
7
src/WrongRequestException.php
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ctiso;
|
||||||
|
|
||||||
|
class WrongRequestException extends Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue