Система управления «Сайт PRO»
Версия 20240107

Класс Page

Объект $Page: Cms\Root\Page наследует Cms\Site\Base

Объект «Страница»

Исходный код
class Page extends \Cms\Site\Base { … }

Свойства

$id

$Page->id

ID страницы

Исходный код
    var $id;

$type

$Page->type

Тип страницы

Исходный код
    var $type;

$parent

$Page->parent

Родитель страницы

Исходный код
    var $parent;

$title

$Page->title

Заголовок страницы

Исходный код
    var $title;

$order

$Page->order

Порядковый номер

Исходный код
    var $order;

$brief

$Page->brief

Анонс страницы

Исходный код
    var $brief;

$image

$Page->image

Изображение

Исходный код
    var $image;

$date

$Page->date

Дата

Исходный код
    var $date;

$list

$Page->list

Тип дочерних страниц: все дочерние страницы должны иметь этот тип

Исходный код
    var $list;

$lang

$Page->lang

Язык страницы

Исходный код
    var $lang;

$table

$Page->table

Таблица, в которой хранится страница

Исходный код
    var $table;

$html

$Page->html

HTML-код

Исходный код
    var $html;

$_open_html

$Page->_open_html

Загружен ли HTML-код

Исходный код
    var $_open_html;

$info

$Page->info

Дополнительная информация в виде массива «ключ-значение», значение может быть строкой или списком

Исходный код
    var $info;

$_open_info

$Page->_open_info

Загружена ли дополнительная информация

Исходный код
    var $_open_info;

$tags

$Page->tags

Тэги

Исходный код
    var $tags;

$change_id

$Page->change_id

Изменение ID страницы

Исходный код
    var $change_id;

$url

$Page->url

URL страницы

Исходный код
    var $url;

Методы

route()

$Page->route($Request);

Обработка HTTP-запроса

Параметры:

ИмяОписание
$Request

Cms\Root\Main\Request

Возвращает: true – запрос обработан; null – запрос не обработан

Исходный код
    function route($Request) {
        if (preg_match('~[?&]page=1$~', $_SERVER['REQUEST_URI'], $m)) {
            $href = substr($_SERVER['REQUEST_URI'], 0, -strlen($m[0]));
            $Request->redirect($href, 301);
            $Request->sendHeader();
            return true;
        }
    }

getPanel()

$Page->getPanel();

Список элементов в панели администрирования

Возвращает: array Панель

Исходный код
    function getPanel() {
        $Main = $this->Main();
        if (!strlen($this->id)) return array();
        if ($this->id === $Main->entry_point || $this->type === 'login') {
            $Item = $Main->load('-');
            return $Item->getPanel();
        }
        $panel = array(
            '-' => array(
                'href' => '?a=page&p=&parent=' . urlencode($this->id),
                'title' => 'Создать страницу',
                'image' => 'add',
                'can' => 'add|edit',
            ),
            'page' => array(
                'href' => '?a=page&p=' . urlencode($this->id),
                'title' => 'Редактировать страницу',
                'image' => 'edit',
                'can' => 'page|edit',
            ),
            'sort' => array(
                'href' => '?a=sort&p=' . urlencode($this->id),
                'title' => 'Сортировка подразделов',
                'image' => 'sort',
                'can' => 'sort|edit',
            ),
            'delete' => array(
                'href' => '?a=delete&p=' . urlencode($this->id),
                'title' => 'Удалить страницу',
                'image' => 'delete',
                'can' => 'delete',
            ),
        );
        if (!$this->hasChildren()) unset($panel['sort']);
        if (!strlen($this->parent)) unset($panel['move']);
        if ($this->isMain()) unset($panel['delete']);
        if (($list = $this->list) || ($list = $Main->Modules->modules[$this->type]['list'])) {
            $panel['-']['href'] = '?a=page&type=' . $list . '&p=&parent=' . urlencode($this->id);
            if ($title = $Main->Modules->modules[$list]['create']) $panel['-']['title'] = $title;
        }
        return $panel;
    }

getFull()

$Page->getFull($full=null);

Получение полного текста для поисковой индексации

Параметры:

ИмяОписание
$full

Полный текст

Возвращает: string

Исходный код
    function getFull($full = null) {
        if (isset($full)) {
            $r = $full;
        } elseif ($this->id === 'admin' || substr($this->id, 0, 7) === '/admin/') {
            return;
        } else {
            $this->openHtml();
            $r = htmlspecialchars($this->title) . "\n" . htmlspecialchars($this->brief) . "\n" . $this->html;
        }
        $r = preg_replace('~<((/(p|div|ul|ol|li|table|tr))|(br))[^>]*>~', "\n", $r);
        $r = preg_replace('~<[^>]+>~', ' ', $r);
        $r = strip_tags(html_entity_decode($r, ENT_QUOTES | ENT_HTML5, 'UTF-8'));
        $r = preg_replace('~&#?\\w+;~', ' ', $r);
        $r = preg_replace('~^\\s+~m', '', $r);
        $r = preg_replace('~\\s+$~m', '', $r);
        $r = preg_replace("~\n\n+~s", "\n", $r);
        $r = preg_replace('~[ \t]+~s', ' ', $r);
        return $r;
    }

openAll()

$Page->openAll();

Загрузка всех данных о странице

Возвращает: null

Исходный код
    function openAll() {
        $this->openHtml();
        $this->openInfo();
        $this->openMenu();
        $this->openTags();
    }

saveAll()

$Page->saveAll($transaction=true);

Сохранение всех данных о странице

Возвращает: true|null

Исходный код
    function saveAll($transaction = true) {
        $Data = $this->Data();
        if ($transaction) if (!$Data->beginTransaction()) return false;
        $r = $this->save()
         && $this->saveHtml()
         && $this->saveFull()
         && $this->saveInfo()
         && $this->saveMenu()
         && $this->saveTags()
         && $this->savePath()
        ;
        if ($r) {
            $this->changeAll();
            if ($transaction) $Data->commit();
        } else {
            if ($transaction) $Data->rollback();
        }
        return $r;
    }

get()

$Page->get($key, $default=null);

Получение значения

Параметры:

ИмяОписание
$key

string ключ значения

$default

any значение по умолчанию

Возвращает: any

Исходный код
    function get($key, $default = null) {
        if (substr($key, 0, 5) === 'info-') return $this->getInfo(substr($key, 5), $default);
        return isset($this->$key) ? $this->$key : $default;
    }

set()

$Page->set($key, $value);

Установка значения

Параметры:

ИмяОписание
$key

string ключ значения

$value

any значение

Исходный код
    function set($key, $value) {
        if (substr($key, 0, 5) === 'info-') return $this->setInfo(substr($key, 5), $value);
        $this->$key = $value;
    }

getInfo()

$Page->getInfo($key, $default=null);

Получение дополнительного значения

Параметры:

ИмяОписание
$key

string ключ дополнительного значения

$default

any значение по умолчанию

Возвращает: any

Исходный код
    function getInfo($key, $default = null) {
        if (!$this->_open_info) $this->openInfo();
        return isset($this->info[$key]) ? $this->info[$key] : $default;
    }

setInfo()

$Page->setInfo($key, $value);

Установка дополнительного значения

Параметры:

ИмяОписание
$key

string ключ значения

$value

any значение

Исходный код
    function setInfo($key, $value) {
        if (!$this->_open_info) $this->openInfo();
        $this->info[$key] = $value;
    }

getInfoP()

$Page->getInfoP($key);

Получение дополнительного значения у ближайшего из родителей

Параметры:

ИмяОписание
$key

string ключ значения

Возвращает: any

Исходный код
    function getInfoP($key) {
        $path = $this->_path;
        $Main = $this->Main();
        if (!isset($path)) $path = $this->_path = array_reverse($this->getPath(), true);
        foreach ($path as $id => $title) if (strlen($id)) if ($Item = $Main->load($id)) {
            if (strlen($value = $Item->getInfo($key))) return $value;
        }
    }

getInfoR()

$Page->getInfoR($key);

Получение дополнительного значения у объекта или ближайшего из родителей

Параметры:

ИмяОписание
$key

string ключ значения

Возвращает: any

Исходный код
    function getInfoR($key) {
        $value = $this->getInfo($key);
        if (strval($value) !== '') return $value;
        return $this->getInfoP($key);
    }

changeAll()

$Page->changeAll();

Вызов функции Cms::Root::Page::change() для каждого из изменённых через форму значений

Исходный код
    function changeAll() {
        foreach ($this as $key => $old) {
            if (substr($key, 0, 5) === '_old_') {
                $key = substr($key, 5);
                $new = $this->get($key);
                if ($old != $new) {
                    $this->change($key, $old, $new);
                }
            }
        }
    }

change()

$Page->change($key, $old, $new);

Значение изменено через форму

Параметры:

ИмяОписание
$key

string ключ значения

$old

any старое значение

$new

any новое значение

Исходный код
    function change($key, $old, $new) {
        return;
    }

display()

$Page->display();

Отображение страницы

Смотрите описание Cms::Root::Main::Display::page()

Исходный код
    function display() {
        return $this->Main()->Display->page($this);
    }

displayDetail()

$Page->displayDetail();

Детальное отображение страницы

Смотрите описание Cms::Root::Main::Display::detail()

Исходный код
    function displayDetail() {
        return $this->Main()->Display->detail($this);
    }

displaySimple()

$Page->displaySimple();

Отображение страницы в списке

Смотрите описание Cms::Root::Main::Display::simple()

Исходный код
    function displaySimple() {
        return $this->Main()->Display->simple($this);
    }

displaySearch()

$Page->displaySearch();

Отображение страницы в результатах поиска

Смотрите описание Cms::Root::Main::Display::search()

Исходный код
    function displaySearch() {
        return $this->Main()->Display->search($this);
    }

displayPanel()

$Page->displayPanel($panel=null);

Отображение панели

Параметры:

ИмяОписание
$panel

Массив с описанием панели

Смотрите описание Cms::Root::Main::Display::pagePanel()

Исходный код
    function displayPanel($panel = null) {
        if (isset($panel)) return $this->Main()->Display->panel($panel);
        else return $this->Main()->Display->pagePanel($this);
    }

displayError()

$Page->displayError();

Отображение всех ошибок

Смотрите описание Cms::Root::Main::Display::error()

Исходный код
    function displayError() {
        return $this->Main()->Display->error($this->getError());
    }

displayMenu()

$Page->displayMenu();

Отображение меню страниц

Смотрите описание Cms::Root::Main::Display::pageMenu()

Исходный код
    function displayMenu() {
        return $this->Main()->Display->pageMenu($this);
    }

displayHtml()

$Page->displayHtml();

Отображение контента страницы

Смотрите описание Cms::Root::Main::Display::pageHtml()

Исходный код
    function displayHtml() {
        return $this->Main()->Display->pageHtml($this);
    }

displayCode()

$Page->displayCode();

Подключение кода

Смотрите описание Cms::Root::Main::Display::pageCode()

Исходный код
    function displayCode() {
        return $this->Main()->Display->pageCode($this);
    }

displayBlock()

$Page->displayBlock($block=null, $a=null);

Отображение блока объектов

Параметры:

ИмяОписание
$block

Блок объектов

$a

Массив с дополнительными параметрами

Смотрите описание Cms::Root::Main::Display::block()

Исходный код
    function displayBlock($block = null, $a = null) {
        return $this->Main()->Display->block($this, isset($block) ? $block : $this->list, $a);
    }

displayTags()

$Page->displayTags();

Отображение тэгов

Смотрите описание Cms::Root::Main::Display::pageTags()

Исходный код
    function displayTags() {
        return $this->Main()->Display->pageTags($this);
    }

displayImage()

$Page->displayImage($transform=null, $width=0, $height=0, $default=null, $alt=null);

Отображение изображения

Параметры:

ИмяОписание
$transform

string; null трансформация

$width

int ширина

$height

int высота

$default

string; null по умолчанию

$alt

string; null альтернативный текст

Возвращает: string

Смотрите описание Cms::Root::Main::Display::image()

Исходный код
    function displayImage($transform = null, $width = 0, $height = 0, $default = null, $alt = null) {
        return $this->Main()->Display->image(array(
            'src' => $this->image,
            'default' => $default,
            'transform' => $transform,
            'width' => $width,
            'height' => $height,
            'alt' => isset($alt) ? $alt : $this->title,
        ));
    }

displayPicture()

$Page->displayPicture(array $transform);

Отображение адаптивного изображения

Параметры:

ИмяОписание
$transform

array изображение и трансформация

Смотрите описание Cms::Root::Main::Display::picture()

Исходный код
    function displayPicture(array $transform) {
        if (!isset($transform['src'])) $transform['src'] = $this->image;
        if (!isset($transform['alt'])) $transform['alt'] = $this->title;
        return $this->Main()->Display->picture($transform);
    }

displayDate()

$Page->displayDate($format='j M Y');

Отображение даты

Параметры:

ИмяОписание
$format

string Формат

Смотрите описание Cms::Root::Main::Display::date()

Исходный код
    function displayDate($format = 'j M Y') {
        return $this->Main()->formatDate($format, $this->date);
    }

displayTitle()

$Page->displayTitle();

Отображение заголовка страницы

Смотрите описание Cms::Root::Main::Display::pageTitle()

Исходный код
    function displayTitle() {
        return $this->Main()->Display->pageTitle($this);
    }

displayH1()

$Page->displayH1();

Отображение заголовка H1.

Исходный код
    function displayH1() {
        return $this->Main()->Display->pageH1($this);
    }

displayBrief()

$Page->displayBrief($brief=null);

Отображение многострочного текста без использования HTML.

Параметры:

ИмяОписание
$brief

string; null Текст

Возвращает: string

Смотрите описание Cms::Root::Main::Display::brief()

Исходный код
    function displayBrief($brief = null) {
        if (!func_num_args()) $brief = $this->brief;
        return $this->Main()->Display->brief($brief);
    }

open()

$Page->open();

Загрузка всех данных о странице

Возвращает: null

Исходный код
    function open() {
        return $this->openAll();
    }

getTitle()

$Page->getTitle($id=null);

Заголовок страницы

Возвращает: string

Исходный код
    function getTitle($id = null) {
        return $this->title;
    }

href()

$Page->href();

Ссылка на страницу

Смотрите описание Cms::Root::Main::Request::href()

Исходный код
    function href() {
        if (isset($this->url) && strlen($this->url)) return $this->url;
        return $this->Main()->Request->href($this->id);
    }

getHref()

$Page->getHref();

Ссылка на страницу

Смотрите описание Cms::Root::Main::Request::href()

Исходный код
    function getHref() {
        return $this->Main()->Request->href($this->id);
    }

getPath()

$Page->getPath();

Получение пути к странице

Смотрите описание Cms::Root::Main::Storage::getPath()

Исходный код
    function getPath() {
        return $this->Main()->Storage->getPath($this);
    }

getDefaultId()

$Page->getDefaultId();

ID страницы по умолчанию

Смотрите описание Cms::Root::Main::getDefaultId()

Исходный код
    function getDefaultId() {
        return $this->Main()->getDefaultId($this);
    }

getMenu()

$Page->getMenu();

Меню страницы

Смотрите описание Cms::Root::Main::Storage::getPageMenu()

Исходный код
    function getMenu() {
        return $this->Main()->Storage->getPageMenu($this->id);
    }

getTags()

$Page->getTags();

Получение тэгов

Возвращает: array

Исходный код
    function getTags() {
        $this->openTags();
        $tags = array();
        foreach (explode(', ', $this->tags) as $tag) if (strlen($tag = trim($tag))) $tags[$tag] = $tag;
        return $tags;
    }

can()

$Page->can($access);

Проверка прав доступа к странице

Параметры:

ИмяОписание
$access

Необходимый уровень доступа

Смотрите описание Cms::Root::Main::can()

Исходный код
    function can($access) {
        return $this->Main()->can($access, $this);
    }

openHtml()

$Page->openHtml();

Загрузка HTML.

Смотрите описание Cms::Root::Main::Storage::openHtml()

Исходный код
    function openHtml() {
        return $this->Main()->Storage->openHtml($this);
    }

openMenu()

$Page->openMenu();

Загрузка данных о меню

Смотрите описание Cms::Root::Main::Storage::openMenu()

Исходный код
    function openMenu() {
        return $this->Main()->Storage->openMenu($this);
    }

openInfo()

$Page->openInfo();

Загрузка дополнительных данных

Смотрите описание Cms::Root::Main::Storage::openInfo()

Исходный код
    function openInfo() {
        return $this->Main()->Storage->openInfo($this);
    }

openTags()

$Page->openTags();

Загрузка данных о тэгах

Смотрите описание Cms::Root::Main::Storage::openTags()

Исходный код
    function openTags() {
        return $this->Main()->Storage->openTags($this);
    }

save()

$Page->save();

Сохранение страницы

Смотрите описание Cms::Root::Main::Storage::save()

Исходный код
    function save() {
        return $this->Main()->Storage->savePage($this);
    }

saveHtml()

$Page->saveHtml();

Сохранение HTML.

Смотрите описание Cms::Root::Main::Storage::saveHtml()

Исходный код
    function saveHtml() {
        return $this->Main()->Storage->saveHtml($this);
    }

saveFull()

$Page->saveFull();

Сохранение полного текста для поиска

Смотрите описание Cms::Root::Main::Storage::saveFull()

Исходный код
    function saveFull() {
        return $this->Main()->Storage->saveFull($this);
    }

saveInfo()

$Page->saveInfo();

Сохранение дополнительной информации

Смотрите описание Cms::Root::Main::Storage::saveInfo()

Исходный код
    function saveInfo() {
        return $this->Main()->Storage->saveInfo($this);
    }

saveMenu()

$Page->saveMenu();

 Сохранение меню

Смотрите описание Cms::Root::Main::Storage::saveMenu()

Исходный код
    function saveMenu() {
        return $this->Main()->Storage->saveMenu($this);
    }

saveTags()

$Page->saveTags();

Сохранение тэгов

Смотрите описание Cms::Root::Main::Storage::saveTags()

Исходный код
    function saveTags() {
        return $this->Main()->Storage->saveTags($this);
    }

savePath()

$Page->savePath();

Сохранение пути к странице

Смотрите описание Cms::Root::Main::Storage::savePath()

Исходный код
    function savePath() {
        return $this->Main()->Storage->savePath($this);
    }

delete()

$Page->delete();

Удаление страницы

Смотрите описание Cms::Root::Main::Storage::delete()

Исходный код
    function delete() {
        return $this->Main()->Storage->delete($this);
    }

displayDefaultForm()

$Page->displayDefaultForm($form=null);

Произвольная форма

Параметры:

ИмяОписание
$form

string; null форма

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displayDefaultForm($form = null) {
        if (!isset($form)) return;
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $this;
        $document = $Form->load($form, $Page);
        if ($Form->store($document)) {
            if ($Page->saveAll()) {
                $this->App()->get('file')->updateFileListItem($Page);
                return $Page->href();
            }
        }
        return $document;
    }

displayPageForm()

$Page->displayPageForm($form='page');

Форма редактирования

Параметры:

ИмяОписание
$form

string форма

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displayPageForm($form = 'page') {
        $root = $this->root();
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $this;
        if ($form === 'page' && $Page->type !== 'page') {
            if (file_exists($root . '/cms/form/' . $Page->type . '.xml')) {
                $form = $Page->type;
            } elseif (file_exists($root . '/cms/html/form.' . $Page->type . '.php')) {
                $form = $Page->type;
            }
        }
        if (!strlen($Page->id) && $_GET['copy']) {
            if ($Copy = $Main->load($_GET['copy'])) {
                $Copy->open();
                foreach ($Copy as $k => $v) if ($k !== 'id') $Page->$k = $v;
            }
        }
        $id = $Page->id; $Page->change_id = $Page->id ? $Page->href() : '';
        $type = $Page->type = $Page->type . ($Page->list ? ':' . $Page->list : '');
        $document = $Form->load($form, $Page);
        if ((strlen($Page->id) || $Page->isMain()) && isset($document->fields['default_id'])) {
            $Field = $document->fields['default_id'];
            if (is_object($Field) && $Field->node && $Field->node->field) {
                unset($Field->node->field);
            }
            unset($document->fields['default_id']);
        }
        if ((!strlen($Page->id) || $Page->isMain()) && isset($document->fields['change_id'])) {
            $Field = $document->fields['change_id'];
            if (is_object($Field) && $Field->node && $Field->node->field) {
                unset($Field->node->field);
            }
            unset($document->fields['change_id']);
        }
        if ($Form->store($document)) {
            if (strpos($Page->type, ':') !== false) {
                list($Page->type, $Page->list) = explode(':', $Page->type);
            } elseif ((!$Page->type || $Page->type === 'page') && $type !== 'page' && isset($document->fields['type']->options) && !isset($document->fields['type']->options[$type])) {
                if (strpos($type, ':') !== false) {
                    list($Page->type, $Page->list) = explode(':', $type);
                } else {
                    $Page->type = $type;
                    $Page->list = '';
                }
            } else {
                $Page->list = '';
            }
            if ($Page->saveAll()) {
                $this->App()->get('file')->updateFileListItem($Page);
                if (isset($document->fields['change_id']))
                if (strlen($change_id = $Page->change_id)) if (strlen($change_id = $Main->Request()->getId($change_id))) if ($change_id != $id) {
                    $Main->changeId($id, $change_id);
                    return $Main->href($change_id);
                }
                return $Page->href();
            }
        }
        return $document;
    }

displayHtmlForm()

$Page->displayHtmlForm($form='html');

Форма редактирования HTML.

Параметры:

ИмяОписание
$form

string форма

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displayHtmlForm($form = 'html') {
        $document = $this->displayDefaultForm($form);
        return $document;
    }

displayMenuForm()

$Page->displayMenuForm($form='menu');

Форма редактирования меню

Параметры:

ИмяОписание
$form

string форма

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displayMenuForm($form = 'menu') {
        $Form = $this->Form();
        return $Form->displayMenuForm($this, $form);
    }

displaySeoForm()

$Page->displaySeoForm($form='seo');

Форма редактирования SEO.

Параметры:

ИмяОписание
$form

string форма

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displaySeoForm($form = 'seo') {
        $document = $this->displayDefaultForm($form);
        return $document;
    }

displayConfForm()

$Page->displayConfForm($form='conf');

Форма редактирования настроек

Параметры:

ИмяОписание
$form

string форма

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displayConfForm($form = 'conf') {
        return $this->Form()->displayConfForm($this, $form);
    }

displayDeleteForm()

$Page->displayDeleteForm($form='delete');

Форма удаления

Параметры:

ИмяОписание
$form

string форма

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displayDeleteForm($form = 'delete') {
        if (!isset($form)) return;
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $this;
        $document = $Form->load($form, $Page);
        if ($Form->store($document)) {
            if ($Page->delete()) {
                if ($Page->hasChildren()) {
                    if (is_string($_POST['confirm']) && $_POST['confirm'] !== '' && $_POST['confirm'] !== 'Y') {
                        foreach (explode('|', $_POST['confirm']) as $id) {
                            if ($Item = $Main->load($id)) {
                                $Item->delete();
                            }
                        }
                    }
                }
                return $Main->href($Page->parent);
            }
        }
        return $document;
    }

displaySortForm()

$Page->displaySortForm($form='sort', $a=null);

Форма сортировки

Параметры:

ИмяОписание
$form

string форма

$a

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displaySortForm($form = 'sort', $a = null) {
        if (!isset($form)) return;
        $Conf = $this->Conf();
        $Data = $this->Data();
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $this;
        if (!isset($a)) {
            $a = array();
            if (is_string($_GET['parent'])) $a['parent'] = $_GET['parent'];
        }
        $document = $Form->loadDocumentXML(''
         . '<form>'
         . '<group>'
         . '<field name="order" type="sort" />'
         . '</group>'
         . '<field name="submit" />'
         . '</form>'
        );
        if ($field = $document->fields['order']) {
            $field->list = $Main->Storage->loadSortList($Page, $a);
        }
        if ($_POST && is_array($_POST['order'])) {
            $list = array();
            if (is_array($field->list)) foreach ($field->list as $item) {
                $list[$item['table']][$item['id']] = false;
            }
            foreach ($_POST['order'] as $table => $sort) if (is_array($sort)) {
                foreach ($sort as $order => $id) {
                    if (isset($list[$table][$id])) $list[$table][$id] = $order;
                }
            }
            foreach ($list as $table => $sort) {
                if (is_array($sort)) {
                    foreach ($sort as $id => $order) if ($order === false) unset($sort[$id]);
                }
                if (is_array($sort) && count($sort)) $list[$table] = $sort;
                else unset($list[$table]);
            }
            if ($Main->Storage->saveSortList($Page, $list)) {
                return $Page->href();
            }
        }
        return $document;
    }

displayPagesForm()

$Page->displayPagesForm($form='page');

Форма редактирования дочерних страниц

Параметры:

ИмяОписание
$form

string форма

Возвращает: array|string|null

Исходный код
    function displayPagesForm($form = 'page') {
        $Data = $this->Data();
        $Main = $this->Main();
        $Form = $this->Form();
        $r = array();
        $data = array();
        $Page = $this;
        $type = $Page->list ? $Page->list : $Main->Modules->modules[$Page->type]['list'];
        if (!$type) $type = 'page';
        $table = $Main->Modules->modules[$type]['table'];
        if (!$table) $table = 'item';
        $query = "SELECT * FROM `$table` WHERE `parent`=" . $Data->quote($Page->id) . " ORDER BY `order`";
        if ($form === 'page' && $type !== 'page' && file_exists($Main->getTemplate('form', $type))) $form = $type;
        $document = $Form->load($form, $data);
        $document->fields['id'] = $Form->loadField(array( 'type' => 'hidden', 'name' => 'id' ));
        if ($_POST) {
            if (is_array($_POST['id'])) foreach ($_POST['id'] as $position => $id) if ($Item = $Main->load($id, $type)) {
                $Item->open();
                if ($form == "delete") {
                    if ($_POST['confirm'][$position]) {
                        $Item->delete();
                    }
                } else {
                    foreach ($document->fields as $name => $field) if ($name !== 'submit') {
                        $Item->set($name, $_POST[$name][$position]);
                    }
                    if ($Item->saveAll()) {
                        $this->App()->get('file')->updateFileListItem($Item);
                    }
                }
            }
            return $Page->href();
        }
        $position = 0;
        if ($result = $Data->query($query)) while ($row = $Data->fetch($result)) {
            $position ++;
            $Item = $Main->load($row);
            $Item->open();
            $title = trim($Main->Modules->modules[$type]['title'] . (strlen($Item->title) ? ' &laquo;' . htmlspecialchars($Item->title) . '&raquo;' : ' №' . $position));
            $r[] = "<h3>$title</h3>";
            if ($Item->image) {
                $r[] = $Main->displayImage($Item->image, 'rf100x100', 100, 100);
            }
            foreach ($document->fields as $name => $field) if ($name !== 'submit') {
                $field->name = "{$name}[{$position}]";
                $field->value = $Item->get($name);
                $r[] = $field->display();
            }
            $r[] = '<hr>';
        }
        if ($document->fields['submit']) $r[] = $document->fields['submit'];
        return $r;
    }

displayDeletesForm()

$Page->displayDeletesForm($form='delete');

Форма удаления дочерних страниц

Параметры:

ИмяОписание
$form

string форма

Возвращает: array|string|null

Исходный код
    function displayDeletesForm($form = 'delete') {
        return $this->displayPagesForm($form);
    }

displayMoveForm()

$Page->displayMoveForm($form='move');

Форма перемещения

Параметры:

ИмяОписание
$form

string форма

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displayMoveForm($form = 'move') {
        if (!isset($form)) return;
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $this;
        $document = $Form->load($form, $Page);
        if ($Form->store($document)) {
            $Page->order = 0;
            if ($Page->saveAll()) {
                return $Page->href();
            }
        }
        return $document;
    }

displayBlockForm()

$Page->displayBlockForm();

Форма редактирования блока

Возвращает: Cms\Root\Form\Document |string|null

Исходный код
    function displayBlockForm() {
        $App = $this->App();
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $this;
        $Block = $App->get('block');
        if (!$blockItem = $Block->getBlockItem($Page, $_GET)) $blockItem = $Block->createBlockItem($Page, $_GET);
        if ($blockItem) {
            if (!$form = $App->getAbsolutePath($Block->getBlockEditForm($Page, $blockItem))) return;
            if (!is_array($blockItem['data'])) $blockItem['data'] = array();
            $blockItem['data']['block-active'] = isset($blockItem['active']) ? ($blockItem['active'] ? 'Y' : '') : 'Y';
            $data = new \Cms\Site\Form\Wrapper($blockItem['data']);
            $data->Page = $Page;
            if ($document = $Form->loadDocumentXml($form, $data)) {
                if ($blockItem['block'] === 'html' && $blockItem['n'] == 1) $blockItem['data']['html'] = $Page->html;
                foreach ($document->fields as $name => $field) {
                    if ($field->json) if (is_array($value = $blockItem['data'][$field->name])) $blockItem['data'][$field->name] = json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
                    $field->request();
                }
            }
            if ($Form->store($document)) {
                foreach ($document->fields as $name => $field) {
                    if ($field->type === 'files') {
                        if (is_array($field->value)) {
                            $files = array();
                            foreach ($field->value as $value) {
                                if (is_string($value)) {
                                    if ($value[0] === '{' && $value[strlen($value) - 1] === '}') {
                                        $files[] = json_decode($value, true);
                                    }
                                }
                            }
                            $blockItem['data'][$field->name] = $files;
                        }
                    } elseif ($field->json) {
                        if (is_string($field->value) && strlen($field->value)) {
                            $blockItem['data'][$field->name] = json_decode($field->value, true);
                        }
                    }
                }
                if ($field = $document->fields['menu']) {
                    if ($field->type === 'sort') {
                        $sortList = array();
                        if (is_array($field->list)) foreach ($field->list as $item) $sortList[$item['id']] = $item;
                        $menu = array();
                        if (is_array($blockItem['data']['menu'])) foreach ($blockItem['data']['menu'] as $id) if ($sortItem = $sortList[$id]) {
                            $sortItem['menu'] = $_POST['menu-menu'][$id] ? 'Y' : '';
                            if (!$sortItem['id'] && !$sortItem['menu']) continue;
                            $menu[] = $sortItem;
                        }
                        $blockItem['data']['menu'] = $menu;
                    }
                    if ($field->type === 'menu') {
                        $menu = $blockItem['data']['menu'];
                        if (is_string($menu) && $menu[0] === '[') $menu = json_decode($menu, true);
                        elseif (!is_array($menu)) $menu = array();
                        if ($menu) $blockItem['data']['menu'] = $menu;
                        else unset($blockItem['data']['menu']);
                    }
                }
                if (isset($blockItem['data']['block-active'])) {
                    $blockItem['active'] = $blockItem['data']['block-active'] ? 'Y' : '';
                    unset($blockItem['data']['block-active']);
                }
                if ($Block->saveBlockItem($Page, $blockItem)) {
                    global $_RESULT; if (!is_array($_RESULT)) $_RESULT = array();
                    if ($blockItem = $Block->getBlockItem($Page, $_GET)) $_RESULT['block'] = $blockItem;
                    return $Page->href();
                }
            }
            return $document;
        }
    }

qId()

$Page->qId();

Получение экранированного ID для SQL.

Возвращает: string

Исходный код
    function qId() {
        return $this->Data()->quote($this->id);
    }

isMain()

$Page->isMain();

Является ли страница Главной

Возвращает: boolean

Исходный код
    function isMain() {
        return $this->id === '-' || (isset($this->lang) && $this->id === $this->lang) || $this->id === $this->Main()->lang;
    }

hasChildren()

$Page->hasChildren();

Есть ли дочерние страницы

Возвращает: boolean

Исходный код
    function hasChildren() {
        return $this->Main()->Storage->hasChildren($this);
    }

table()

$Page->table();

Таблица для сохранения

Возвращает: string

Исходный код
    function table() {
        if (isset($this->table) && $this->table) {
            return $this->table;
        }
        if ($this->type) {
            $Modules = $this->Main()->Modules;
            if ($Type = $Modules->getModule($this->type)) {
                return $Type->getTable();
            }
        }
        return 'item';
    }

getList()

$Page->getList();

Тип дочерних элементов

Возвращает: string|null

Исходный код
    function getList() {
        if (isset($this->list) && $this->list) return $this->list;
        if ($this->type) {
            $Modules = $this->Main()->Modules;
            if ($Type = $Modules->getModule($this->type)) {
                return $Type->list;
            }
        }
    }