Skip to content

Commit

Permalink
Маски для строкового поля, возможность указывать CSS класс тегу body,
Browse files Browse the repository at this point in the history
из типографа убраны теги object, param, embed, в виджете элементы шаблона
теперь можно указывать другие логотипы, в окне отладки теперь есть сортировка
по времени выполнения и поиск,
плюс исправление мелочей.
  • Loading branch information
fuzegit committed Sep 14, 2021
1 parent 491fcab commit e911bf4
Show file tree
Hide file tree
Showing 30 changed files with 497 additions and 178 deletions.
8 changes: 8 additions & 0 deletions credits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,11 @@ Third-party plugins, libraries and resources included in InstantCMS:
Free Bootstrap Admin Template
by Łukasz Holeczek, woothu, xidedix
https://coreui.io/

Inputmask
by Robin Herbots
https://github.com/RobinHerbots/Inputmask

List.js
by Jonny Strömberg @javve
https://listjs.com/
1 change: 1 addition & 0 deletions install/languages/en/sql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,7 @@ CREATE TABLE `{#}widgets_pages` (
`url_mask_not` text COMMENT 'Negative mask',
`groups` text COMMENT 'Access groups',
`countries` text COMMENT 'Access countries',
`body_css` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `controller` (`controller`),
KEY `name` (`name`)
Expand Down
1 change: 1 addition & 0 deletions install/languages/ru/sql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,7 @@ CREATE TABLE `{#}widgets_pages` (
`url_mask_not` text COMMENT 'Отрицательная маска',
`groups` text COMMENT 'Группы доступа',
`countries` text COMMENT 'Страны доступа',
`body_css` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `controller` (`controller`),
KEY `name` (`name`)
Expand Down
7 changes: 7 additions & 0 deletions system/controllers/admin/forms/form_widgets_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public function init() {
return array(
'title' => array(
'type' => 'fieldset',
'title' => LANG_CP_BASIC,
'childs' => array(
new fieldString('title', array(
'title' => LANG_TITLE,
Expand All @@ -16,6 +17,12 @@ public function init() {
array('max_length', 64)
)
)),
new fieldString('body_css', array(
'title' => LANG_CP_WIDGET_PAGE_BODY_CSS,
'rules' => array(
array('max_length', 100)
)
))
)
),
'urls' => array(
Expand Down
22 changes: 11 additions & 11 deletions system/controllers/bootstrap4/hooks/admin_col_scheme_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ public function run($data){
'' => LANG_NO,
'col' => LANG_AUTO,
'col-1' => 'col-1 (8.33%)',
'col-2' => 'col-1 (16.67%)',
'col-3' => 'col-1 (25%)',
'col-4' => 'col-1 (33.33%)',
'col-5' => 'col-1 (41.67%)',
'col-6' => 'col-1 (50%)',
'col-7' => 'col-1 (58.33%)',
'col-8' => 'col-1 (66.67%)',
'col-9' => 'col-1 (75%)',
'col-10' => 'col-1 (83.33%)',
'col-11' => 'col-1 (91.67%)',
'col-12' => 'col-1 (100%)',
'col-2' => 'col-2 (16.67%)',
'col-3' => 'col-3 (25%)',
'col-4' => 'col-4 (33.33%)',
'col-5' => 'col-5 (41.67%)',
'col-6' => 'col-6 (50%)',
'col-7' => 'col-7 (58.33%)',
'col-8' => 'col-8 (66.67%)',
'col-9' => 'col-9 (75%)',
'col-10' => 'col-10 (83.33%)',
'col-11' => 'col-11 (91.67%)',
'col-12' => 'col-12 (100%)',
'col-auto' => LANG_CP_WIDGETS_COL_AUTO
),
'visible_depend' => array('type' => array('hide' => array('custom')))
Expand Down
12 changes: 5 additions & 7 deletions system/controllers/typograph/hooks/html_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ private function getJevix() {
'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'pre', 'code', 'blockquote', 'picture',
'video', 'source', 'audio', 'youtube', 'facebook', 'figure', 'figcaption',
'object', 'param', 'embed', 'iframe', 'spoiler', 'cite', 'footer'
'iframe', 'spoiler', 'cite', 'footer', 'address'
]);

// Устанавливаем коротие теги. (не имеющие закрывающего тега)
$jevix->cfgSetTagShort([
'br', 'img', 'hr', 'embed', 'input', 'source'
'br', 'img', 'hr', 'input', 'source'
]);

// Устанавливаем преформатированные теги. (в них все будет заменятся на HTML сущности)
Expand All @@ -77,20 +77,18 @@ private function getJevix() {
]);

$jevix->cfgSetTagIsEmpty([
'param', 'embed', 'a', 'iframe', 'div'
'a', 'iframe', 'div'
]);

// Устанавливаем разрешённые параметры тегов. Также можно устанавливать допустимые значения этих параметров.
$jevix->cfgAllowTagParams('address', ['class' => '#text']);
$jevix->cfgAllowTagParams('a', ['href' => '#link', 'name' => '#text', 'target' => '#text', 'class' => '#text']);
$jevix->cfgAllowTagParams('img', ['src', 'style' => '#text', 'alt' => '#text', 'title' => '#text', 'align' => ['right', 'left', 'center'], 'width' => '#int', 'height' => '#int', 'hspace' => '#int', 'vspace' => '#int', 'class' => '#text']);
$jevix->cfgAllowTagParams('span', ['style' => '#text']);
$jevix->cfgAllowTagParams('input', ['tabindex' => '#text', 'type' => '#text', 'id' => '#text']);
$jevix->cfgAllowTagParams('label', ['class' => '#text', 'for' => '#text']);
$jevix->cfgAllowTagParams('footer', ['class' => '#text']);
$jevix->cfgAllowTagParams('object', ['width' => '#int', 'height' => '#int', 'data' => ['#domain' => ['youtube.com', 'rutube.ru', 'vimeo.com', 'vk.com']], 'type' => '#text']);
$jevix->cfgAllowTagParams('param', ['name' => '#text', 'value' => '#text']);
$jevix->cfgAllowTagParams('embed', ['src' => ['#domain' => ['youtube.com', 'rutube.ru', 'vimeo.com', 'vk.com']], 'type' => '#text', 'allowscriptaccess' => '#text', 'allowfullscreen' => '#text', 'width' => '#int', 'height' => '#int', 'flashvars' => '#text', 'wmode' => '#text']);
$jevix->cfgAllowTagParams('iframe', ['width' => '#int', 'height' => '#int', 'style' => '#text', 'frameborder' => '#int', 'allowfullscreen' => '#text', 'src' => ['#domain' => ['youtube.com', 'rutube.ru', 'vimeo.com', 'vk.com', 'my.mail.ru', 'facebook.com', parse_url($this->cms_config->host, PHP_URL_HOST)]]]);
$jevix->cfgAllowTagParams('iframe', ['width' => '#int', 'height' => '#int', 'style' => '#text', 'frameborder' => '#int', 'allowfullscreen' => '#text', 'src' => ['#domain' => ['youtube.com', 'yandex.ru', 'rutube.ru', 'vimeo.com', 'vk.com', 'my.mail.ru', 'facebook.com', parse_url($this->cms_config->host, PHP_URL_HOST)]]]);
$jevix->cfgAllowTagParams('table', ['width' => '#int', 'height' => '#int', 'cellpadding' => '#int', 'cellspacing' => '#int', 'border' => '#int', 'style' => '#text', 'align' => '#text', 'valign' => '#text']);
$jevix->cfgAllowTagParams('td', ['width' => '#int', 'height' => '#int', 'style' => '#text', 'align' => '#text', 'valign' => '#text', 'colspan' => '#int', 'rowspan' => '#int']);
$jevix->cfgAllowTagParams('th', ['width' => '#int', 'height' => '#int', 'style' => '#text', 'align' => '#text', 'valign' => '#text', 'colspan' => '#int', 'rowspan' => '#int']);
Expand Down
67 changes: 43 additions & 24 deletions system/core/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -2091,7 +2091,15 @@ public function applyGridFilter($grid, $filter){
//============================================================================//
//============================================================================//

public function increment($table, $field, $step=1){
/**
* Изменяет числовое поле в таблице на величину $step
*
* @param string $table Имя таблицы
* @param string $field Имя поля
* @param type $step Шаг изменения
* @return boolean
*/
public function increment($table, $field, $step = 1) {

$sign = $step > 0 ? '+' : '-';
$step = abs($step);
Expand All @@ -2100,25 +2108,41 @@ public function increment($table, $field, $step=1){
SET i.{$field} = i.{$field} {$sign} {$step}
";

if ($this->where){ $sql .= 'WHERE '.$this->where; }
if ($this->where) {
$sql .= 'WHERE ' . $this->where;
}

$this->resetFilters();

return $this->db->query($sql, false, true);

return $this->db->query($sql, false, true) ? true : false;
}

public function decrement($table, $field, $step=1){
/**
* Изменяет числовое поле в таблице на величину $step с противоположенным знаком
*
* @param string $table Имя таблицы
* @param string $field Имя поля
* @param type $step Шаг изменения
* @return boolean
*/
public function decrement($table, $field, $step = 1) {
return $this->increment($table, $field, $step * -1);
}

/**
* Удаляет известные данные о контроллере $name в таблицах БД
*
* @param string $name Имя контроллера
* @return boolean
*/
public function deleteController($name) {

if(is_numeric($name)){
$controller = $this->getItemById('controllers', $name);
$name = $controller['name'];
}

$this->filterEqual('controller', $name)->deleteFiltered('{users}_tabs');
$this->filterEqual('listener', $name)->deleteFiltered('events');

cmsCache::getInstance()->clean('events');
Expand All @@ -2139,12 +2163,11 @@ public function deleteController($name) {

public function fieldsAfterStore($item, $fields, $action = 'add') {

foreach($fields as $field){
foreach ($fields as $field) {
$field['handler']->afterStore($item, $this, $action);
}

return $this;

}

/**
Expand Down Expand Up @@ -2197,26 +2220,23 @@ public static function arrayToYaml($input_array, $indent = 2, $word_wrap = 40) {

$array = [];

if(cmsConfig::get('native_yaml')){
if (cmsConfig::get('native_yaml')) {

if(!empty($input_array)){
if (!empty($input_array)) {
$array = $input_array;
}

return yaml_emit($array, YAML_UTF8_ENCODING);
}

if(!empty($input_array)){

if (!empty($input_array)) {
foreach ($input_array as $key => $value) {
$_k = str_replace(array('[',']'), '', $key); // был фатальный баг, если в ключах эти символы
$_k = str_replace(['[', ']'], '', $key); // был фатальный баг, если в ключах эти символы
$array[$_k] = $value;
}

}

return Spyc::YAMLDump($array, $indent, $word_wrap);

}

/**
Expand All @@ -2226,19 +2246,18 @@ public static function arrayToYaml($input_array, $indent = 2, $word_wrap = 40) {
*/
public static function yamlToArray($yaml) {

if(!$yaml){ return array(); }
if (!$yaml) { return []; }

if(is_array($yaml)){ return $yaml; }
if (is_array($yaml)) { return $yaml; }

if($yaml === "---\n- 0\n"){ return array(); }
if($yaml === "---\n- \"0\"\n...\n"){ return array(); }
if ($yaml === "---\n- 0\n") { return []; }
if ($yaml === "---\n- \"0\"\n...\n") { return []; }

if(cmsConfig::get('native_yaml')){
if (cmsConfig::get('native_yaml')) {
return yaml_parse($yaml);
}

return Spyc::YAMLLoadString($yaml);

}

/**
Expand All @@ -2247,7 +2266,7 @@ public static function yamlToArray($yaml) {
* @return string
*/
public static function arrayToString($input_array) {
if(!is_array($input_array)){
if (!is_array($input_array)) {
return null;
}
return json_encode($input_array);
Expand All @@ -2259,8 +2278,8 @@ public static function arrayToString($input_array) {
* @return array
*/
public static function stringToArray($string) {
if(!$string){ return array(); }
return (array)json_decode($string, true);
if (!$string) { return []; }
return (array) json_decode($string, true);
}

/**
Expand All @@ -2272,7 +2291,7 @@ public static function cacheResult($key, $data) {
self::$cached[$key] = $data;
}
public static function getCachedResult($key) {
if(isset(self::$cached[$key])){
if (isset(self::$cached[$key])) {
return self::$cached[$key];
}
return null;
Expand Down
14 changes: 13 additions & 1 deletion system/core/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,7 @@ public function getAvailableTemplatesFiles($path, $pattern='*.*', $template_name

if(in_array($file_name, $excluded)){ continue; }

$file_path = $template_instance->getTemplateFileName($path.'/'.$file_name);
$file_path = $template_instance->getTemplateFileName($path.'/'.$file_name, true);
if(!$file_path){ continue; }

// Ищем название шаблона внутри файла
Expand Down Expand Up @@ -3018,6 +3018,18 @@ public function renderPage(){
$rows = cmsCore::getModel('widgets')->getLayoutRows($this->name);
}

// CSS классы для тега body
$body_classes = [];

$matched_pages = $core->getMatchedPages();
if($matched_pages && $matched_pages != [0, 1]){
foreach ($matched_pages as $matched_page) {
if(!empty($matched_page['body_css'])){
$body_classes[] = $matched_page['body_css'];
}
}
}

ob_start();

include($template_file);
Expand Down
11 changes: 10 additions & 1 deletion system/core/widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ public function __construct($widget){
}

public function getOption($key, $default = false){
return array_key_exists($key, $this->options) ? $this->options[$key] : $default;

$is_array = strpos($key, ':');

if ($is_array === false){
$value = array_key_exists($key, $this->options) ? $this->options[$key] : null;
} else {
$value = array_value_recursive($key, $this->options);
}

return $value !== null ? $value : $default;
}

public function getOptions(){
Expand Down
Loading

0 comments on commit e911bf4

Please sign in to comment.