DLE: показываем/скрываем блоки для мобильных устройств


  1. скачиваем библиоетку по детекту устройств с сайта автора mobiledetect
  2. файл mobile_detect.php копируем в /engine/classes
  3. открываем /engine/classes/templates.class.php и находим код:
    if (strpos ( $this->template, "[not-aviable=" ) !== false) {
    			$this->template = preg_replace ( "#\\[not-aviable=(.+?)\\](.*?)\\[/not-aviable\\]#ies", "\$this->check_module('\\1', '\\2', false)", $this->template );
    		}

    после него добавляем:

    if (strpos ( $this->template, "[if_mobile=" ) !== false) {
    			$this->template = preg_replace ( "#\\[if_mobile=(.+?)\\](.*?)\\[/if_mobile\\]#ies", "\$this->check_mobile('\\1', '\\2')", $this->template );
    		}

    дальше находим еще один

    if (strpos ( $template, "[not-aviable=" ) !== false) {
    			$template = preg_replace ( "#\\[not-aviable=(.+?)\\](.*?)\\[/not-aviable\\]#ies", "\$this->check_module('\\1', '\\2', false)", $template );
    		}

    и после добавляем:

    if (strpos ( $template, "[if_mobile=" ) !== false) {
    			$template = preg_replace ( "#\\[if_mobile=(.+?)\\](.*?)\\[/if_mobile\\]#ies", "\$this->check_mobile('\\1', '\\2')", $template );
    		}

    далее находим функцию

    function check_module($aviable, $block, $action = true) {

    и перед ней вставляем нашу новую:


        function check_mobile($action, $block) {
            
            require_once ENGINE_DIR.'/classes/mobile_detect.php';
            $detect = new Mobile_Detect;
            $block = str_replace('\"', '"', $block);
            if ( $detect->isMobile() && $action=="display" ) { return $block; }
            if ( $detect->isMobile() && $action=="hide" ) { return ""; }
            if ( !$detect->isMobile() && $action=="hide" ) { return $block; }
            
        }
  4. открываем index.php в корне и ищем
    	if ( strpos( $tpl->copy_template, "[not-aviable=" ) !== false ) {
    		$tpl->copy_template = preg_replace( "#\\[not-aviable=(.+?)\\](.*?)\\[/not-aviable\\]#ies","check_module('\\1', '\\2', '{$do}', false)", $tpl->copy_template);
    	}

    после нее добавляем:

    	if (strpos ( $tpl->copy_template, "[if_mobile=" ) !== false) {
    		$tpl->copy_template = preg_replace ( "#\\[if_mobile=(.+?)\\](.*?)\\[/if_mobile\\]#ies", "\$this->check_mobile('\\1', '\\2')", $tpl->copy_template );
    	}
  5. после этого в шаблонах можем использовать код:
    [if_mobile=display] test [/if_mobile] - показывать на мобильных
    [if_mobile=hide] test [/if_mobile] - скрывать для мобильных
ПОЛЕЗНО  DLE: Изменение названий загружаемых картинок и файлов

п.с. тесты проводились на ДЛЕ 7,5