dimanche 26 octobre 2014

Mobile Detect DLE Module

Mobile Detect DLE Module

The new release Dle 10.3 appeared quite interesting innovation, namely the automatic detection of devices from which to browse the site. And depending on the device can be displayed or hide certain content. For this we introduce new tags [smartphone] text [/ smartphone] and [not-smartphone] text [/ not-smartphone], [tablet] text [/ tablet] and [not-tablet] text [/ not-tablet], and as well [desktop] text [/ desktop] and [not-desktop] text [/ not-desktop]. Let us try to apply this innovation to version 10.2.


Details for tags:
[smartphone] text [/ smartphone], which displays the text enclosed in them, if the site is viewed using a smartphone, and the tags [not-smartphone] text [/ not-smartphone], which displays the text enclosed in them, if the site visitors are not visible from the smartphone. These tags are global and can be used in all template files. Thus, you can flexibly adjust the content output of your site, depending on the visitor of the device, for example, control the output devices for advertising and more.

[tablet] text [/ tablet], which displays the text enclosed in them, if the site is viewed using the tablet, as well as tag [not-tablet] text [/ not-tablet], which displays the text enclosed in them, if the site visitors are not visible using the tablet. These tags are global and can be used in all template files. Thus, you can flexibly adjust the content output of your site, depending on the visitor of the device, for example, control the output devices for advertising and more.

[desktop] text [/ desktop], which displays the text enclosed in them, if the site is viewed using a desktop browser (desktop computers, laptops), and tags [not-desktop] text [/ not-desktop], which displays the text enclosed in them, if the site visitor is not visible using a desktop browser. These tags are global and can be used in all template files. Thus, you can flexibly adjust the content output of your site, depending on the visitor of the device, for example, control the output devices for advertising and more.

Version DLE: 10.2
Source: dle-faq.ru
Author modifications: vitnet

Download Module DLE Mobile detect

Installation
1. Download the following archive file mobile.detect.php and unpack it in a folder /engine/classes/.
2. Open the index.php file and find:
require_once ENGINE_DIR . '/init.php';
Add below:
require_once ENGINE_DIR . '/classes/mobile.detect.php';
$detect = new Mobile_Detect;
Find:
if (stripos ( $tpl->copy_template, "{custom" ) !== false) {
$tpl->copy_template = preg_replace_callback ( "#\\{custom(.+?)\\}#i", "custom_print", $tpl->copy_template );
}
Add below:
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. Open File engine/classes/templates.class.php and find:
if (strpos ( $this->template, "[aviable=" ) !== false) {
$this->template = preg_replace_callback ( "#\[(aviable)=(.+?)\](.*?)\[/aviable\]#is", array( &$this, 'check_module'), $this->template );
}
Add above:
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 );
}
Find:
if (strpos ( $template, "[aviable=" ) !== false) {
$template = preg_replace_callback ( "#\[(aviable)=(.+?)\](.*?)\[/aviable\]#is", array( &$this, 'check_module'), $template );
}
Add above:
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 );
}
Find:
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;
}
Add below:
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 "";
}
Done!

Aucun commentaire:

Enregistrer un commentaire