Григорий

Григорий

Был в сети 30 декабря 2025, 09:50
Заказы не принимаю
Страное дело. Журнал ошибок пишет:
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 3
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 4
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 5
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 6
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 7
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 8
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 9
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 10
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 11
[2019-02-02 20:52:36] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 12
[2019-02-02 20:52:38] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): Unexpected end tag : p in Entity, line: 30
[2019-02-02 20:52:39] (ERROR @ *******/core/cache/includes/elements/modplugin/27.include.cache.php : 14) PHP warning: DOMDocument::loadHTML(): Unexpected end tag : p in Entity, line: 30
Файл 27.include.cache.php

<?php
	
//  modx.pro/development/16940
	
switch ($modx->event->name) {
  
    //Работа с контентом
    
   case 'OnLoadWebDocument':
        $content = $modx->resource->content;
        $content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'); //исправляем ошибки кодировки
        
        $dom = new DOMDocument;
        $dom->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
        $imgs = $dom->getElementsByTagName('img'); //ищем все изображения
        
        foreach ($imgs as $img) {
          //убираем атрибуты width и height, добавляем класс
          $img->removeAttribute('width');
          $img->removeAttribute('height');
         
          // $img->setAttribute('className', 'img-responsive');
          // kalina *** 
          $class = $img->getAttribute( 'class' );
          $img->setAttribute('class', $class . ' img-fluid' );
        }
        
        //компилируем html и устанавливаем
       $html = $dom->saveHTML();
        $modx->resource->set('content', $html);
        
        break;
Что это может быть?
Вопрос.
foreach ($imgs as $img) {
//убираем атрибуты width и height, добавляем класс
$img->removeAttribute('width');
$img->removeAttribute('height');
$img->setAttribute('class', 'img-thumbnail');
}
Код
$img->setAttribute('class', 'img-thumbnail');
заменяет любой уже присвоенный class.
По логике, правильнее добавлять class, а не зарезать существующие…