Mobile detect for DLE 10.2 » Techno-Co — Всё для вебмастера, для создание сайтов с нуля. {title}
В новом релизе Dle 10.3 появилось довольно интересное новшество, а именно автоматическое определение устройств, с которого просматривается сайт. И в зависимости от устройства, может выводиться или скрываться определенный контент. Для этого введены новые теги [smartphone] текст [/smartphone] и [not-smartphone] текст [/not-smartphone], [tablet] текст [/tablet] и [not-tablet] текст [/not-tablet], а так же [desktop] текст [/desktop] и [not-desktop] текст [/not-desktop]. Попытаемся применить это новшество к версии 10.2.
Подробная информация по тегам [smartphone] текст [/smartphone], которые выводят текст, заключенный в них, если сайт просматривается при помощи смартфона, а также теги [not-smartphone] текст [/not-smartphone], которые выводят текст, заключенный в них, если сайт просматривается посетителем не со смартфона. Данные теги являются глобальными и могут использоваться во всех файлах шаблона. Тем самым вы можете гибко настраивать вывод контента своего сайта, в зависимости от используемого посетителем устройства, например, управлять выводом рекламы для устройств и многое другое.[tablet] текст [/tablet], которые выводят текст, заключенный в них, если сайт просматривается при помощи планшета, а также теги [not-tablet] текст [/not-tablet], которые выводят текст, заключенный в них, если сайт просматривается посетителем не с использованием планшета. Данные теги являются глобальными и могут использоваться во всех файлах шаблона. Тем самым вы можете гибко настраивать вывод контента своего сайта, в зависимости от используемого посетителем устройства, например, управлять выводом рекламы для устройств и многое другое.
[desktop] текст [/desktop], которые выводят текст, заключенный в них, если сайт просматривается при помощи десктопного браузера (настольные компьютеры, ноутбуки), а также теги [not-desktop] текст [/not-desktop], которые выводят текст, заключенный в них, если сайт просматривается посетителем не с использованием десктопного браузера. Данные теги являются глобальными и могут использоваться во всех файлах шаблона. Тем самым вы можете гибко настраивать вывод контента своего сайта, в зависимости от используемого посетителем устройства, например, управлять выводом рекламы для устройств и многое другое.
Установка:
1. Скачать ниже архив с файлом mobile.detect.php и распаковать его в папку /engine/classes/.
2. Открыть файл index.php и найти:
require_once ENGINE_DIR . '/init.php';
Добавить ниже:
require_once ENGINE_DIR . '/classes/mobile.detect.php';
$detect = new Mobile_Detect;
Далее найти:
if (stripos ( $tpl->copy_template, "{custom" ) !== false) {
$tpl->copy_template = preg_replace_callback ( "#\{custom(.+?)\}#i", "custom_print", $tpl->copy_template );
}
Добавить ниже:
if (stripos ( $tpl->copy_template, "[smartphone" ) !== false) {
$tpl->copy_template = preg_replace_callback ( "#\[(smartphone)\](.*?)\[/smartphone\]#is", "check_smartphone", $tpl->copy_template );
}
if (stripos ( $tpl->copy_template, "[not-smartphone" ) !== false) {
$tpl->copy_template = preg_replace_callback ( "#\[(not-smartphone)\](.*?)\[/not-smartphone\]#is", "check_smartphone", $tpl->copy_template );
}
if (stripos ( $tpl->copy_template, "[tablet" ) !== false) {
$tpl->copy_template = preg_replace_callback ( "#\[(tablet)\](.*?)\[/tablet\]#is", "check_tablet", $tpl->copy_template );
}
if (stripos ( $tpl->copy_template, "[not-tablet" ) !== false) {
$tpl->copy_template = preg_replace_callback ( "#\[(not-tablet)\](.*?)\[/not-tablet\]#is", "check_tablet", $tpl->copy_template );
}
if (stripos ( $tpl->copy_template, "[desktop" ) !== false) {
$tpl->copy_template = preg_replace_callback ( "#\[(desktop)\](.*?)\[/desktop\]#is", "check_desktop", $tpl->copy_template );
}
if (stripos ( $tpl->copy_template, "[not-desktop" ) !== false) {
$tpl->copy_template = preg_replace_callback ( "#\[(not-desktop)\](.*?)\[/not-desktop\]#is", "check_desktop", $tpl->copy_template );
}
3. Открыть файл engine/classes/templates.class.php и найти:
if (strpos ( $this->template, "[aviable=" ) !== false) {
$this->template = preg_replace_callback ( "#\[(aviable)=(.+?)\](.*?)\[/aviable\]#is", array( &$this, 'check_module'), $this->template );
}
Добавить выше:
if (strpos ( $this->template, "[smartphone" ) !== false) {
$this->template = preg_replace_callback ( "#\[(smartphone)\](.*?)\[/smartphone\]#is", array( &$this, 'check_smartphone'), $this->template );
}
if (strpos ( $this->template, "[not-smartphone" ) !== false) {
$this->template = preg_replace_callback ( "#\[(not-smartphone)\](.*?)\[/not-smartphone\]#is", array( &$this, 'check_smartphone'), $this->template );
}
if (strpos ( $this->template, "[tablet" ) !== false) {
$this->template = preg_replace_callback ( "#\[(tablet)\](.*?)\[/tablet\]#is", array( &$this, 'check_tablet'), $this->template );
}
if (strpos ( $this->template, "[not-tablet" ) !== false) {
$this->template = preg_replace_callback ( "#\[(not-tablet)\](.*?)\[/not-tablet\]#is", array( &$this, 'check_tablet'), $this->template );
}
if (strpos ( $this->template, "[desktop" ) !== false) {
$this->template = preg_replace_callback ( "#\[(desktop)\](.*?)\[/desktop\]#is", array( &$this, 'check_desktop'), $this->template );
}
if (strpos ( $this->template, "[not-desktop" ) !== false) {
$this->template = preg_replace_callback ( "#\[(not-desktop)\](.*?)\[/not-desktop\]#is", array( &$this, 'check_desktop'), $this->template );
}
Далее найти:
if (strpos ( $template, "[aviable=" ) !== false) {
$template = preg_replace_callback ( "#\[(aviable)=(.+?)\](.*?)\[/aviable\]#is", array( &$this, 'check_module'), $template );
}
Добавить выше:
if (strpos ( $template, "[smartphone" ) !== false) {
$template = preg_replace_callback ( "#\[(smartphone)\](.*?)\[/smartphone\]#is", array( &$this, 'check_smartphone'), $template );
}
if (strpos ( $template, "[not-smartphone" ) !== false) {
$template = preg_replace_callback ( "#\[(not-smartphone)\](.*?)\[/not-smartphone\]#is", array( &$this, 'check_smartphone'), $template );
}
if (strpos ( $template, "[tablet" ) !== false) {
$template = preg_replace_callback ( "#\[(tablet)\](.*?)\[/tablet\]#is", array( &$this, 'check_tablet'), $template );
}
if (strpos ( $template, "[not-tablet" ) !== false) {
$template = preg_replace_callback ( "#\[(not-tablet)\](.*?)\[/not-tablet\]#is", array( &$this, 'check_tablet'), $template );
}
if (strpos ( $template, "[desktop" ) !== false) {
$template = preg_replace_callback ( "#\[(desktop)\](.*?)\[/desktop\]#is", array( &$this, 'check_desktop'), $template );
}
if (strpos ( $template, "[not-desktop" ) !== false) {
$template = preg_replace_callback ( "#\[(not-desktop)\](.*?)\[/not-desktop\]#is", array( &$this, 'check_desktop'), $template );
}
Далее найти:
function clear_url_dir($var) {
if ( is_array($var) ) return "";
$var = str_ireplace( ".php", "", $var );
$var = str_ireplace( ".php", ".ppp", $var );
$var = trim( strip_tags( $var ) );
$var = str_replace( "\", "/", $var );
$var = preg_replace( "/[^a-z0-9/_-]+/mi", "", $var );
$var = preg_replace( '#[/]+#i', '/', $var );
return $var;
}
Добавить ниже:
function check_smartphone( $matches = array() ) {
global $detect;
$action = $matches[1];
$block = $matches[2];
if( $action == "smartphone" ) {
if( $detect->isMobile() && !$detect->isTablet() ) {
return $block;
}
} elseif( $action == "not-smartphone" ) {
if( !$detect->isMobile() || $detect->isTablet() ) {
return $block;
}
} else return "";
}
function check_tablet( $matches = array() ) {
global $detect;
$action = $matches[1];
$block = $matches[2];
if( $action == "tablet" ) {
if( $detect->isTablet() ) {
return $block;
}
} elseif( $action == "not-tablet" ) {
if( !$detect->isTablet() ) {
return $block;
}
} else return "";
}
function check_desktop( $matches = array() ) {
global $detect;
$action = $matches[1];
$block = $matches[2];
if( $action == "desktop" ) {
if( !$detect->isMobile() && !$detect->isTablet() ) {
return $block;
}
} elseif( $action == "not-desktop" ) {
if( $detect->isMobile() ) {
return $block;
}
} else return "";
}
Готово!
Версия DLE: 10.2
Автор модификации: vitnet
Комментарии 0