zdoom-styles/art_mobile/contrib/detect_mobile-old_version.xml
Rachael Alexanderson 5d9fa0f654 - add art_mobile
2018-06-02 11:12:00 -05:00

159 lines
6.3 KiB
XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="modx.prosilver.en.xsl"?>
<!--NOTICE: Please open this file in your web browser. If presented with a security warning, you may safely tell it to allow the blocked content.-->
<!--For security purposes, please check: http://www.phpbb.com/mods/ for the latest version of this MOD.\nAlthough MODs are checked before being allowed in the MODs Database there is no guarantee that there are no security problems within the MOD.\nNo support will be given for MODs not found within the MODs Database which can be found at http://www.phpbb.com/mods/-->
<mod xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phpbb.com/mods/xml/modx-1.2.5.xsd">
<header>
<meta name="generator" content="MODX file generated with PP MODX Creator by tumba25 (online version)"/>
<license><![CDATA[http://opensource.org/licenses/gpl-license.php GNU General Public License v2]]></license>
<title lang="en"><![CDATA[Mobile/SEO automatic switch]]></title>
<description lang="en"><![CDATA[Automatically switches style to "Artodia: Mobile" for mobile devices.
This mod has been replaced by newer version, see detect_mobile.xml. Do not install both new and old versions on same forum!]]></description>
<author-group>
<author>
<username><![CDATA[Arty]]></username>
</author>
</author-group>
<mod-version>2.0</mod-version>
<installation>
<level>easy</level>
<time>60</time>
<target-version>3.0.11</target-version>
</installation>
</header>
<action-group>
<open src="includes/functions.php">
<edit>
<find><![CDATA[ // The following assigns all _common_ variables that may be used at any point in a template.
]]></find>
<action type="before-add"><![CDATA[ // MOD start: Mobile/SEO style
if(defined('MOBILE_DEVICE'))
{
$full_style = defined('MOBILE_DEVICE_OFF');
if($full_style)
{
$s_search_hidden_fields['nomobile'] = 1;
$mobile_text = isset($user->lang['MOBILE_ON']) ? $user->lang['MOBILE_ON'] : 'Mobile Version';
$mobile_link = str_replace('nomobile=1&amp;', '', append_sid("{$phpbb_root_path}index.$phpEx", 'nomobile=0'));
}
else
{
$mobile_text = isset($user->lang['MOBILE_OFF']) ? $user->lang['MOBILE_OFF'] : 'Full Version';
$mobile_link = append_sid("{$phpbb_root_path}index.$phpEx", 'nomobile=1');
}
$mobile_html = '<a href="' . $mobile_link . '">' . $mobile_text . '</a>';
$user->lang['TRANSLATION_INFO'] = (isset($user->lang['TRANSLATION_INFO']) ? $user->lang['TRANSLATION_INFO'] . ' ' : '') . $mobile_html;
$template->assign_var('MOBILE_LINK', $mobile_html);
}
// MOD end: Mobile/SEO style
]]></action>
</edit>
</open>
<open src="includes/session.php">
<edit>
<find><![CDATA[ $result = $db->sql_query($sql, 3600);
$this->theme = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
// User has wrong style
]]></find>
<action type="before-add"><![CDATA[ // MOD start: Mobile/SEO style
if($this->check_mobile($sql, $style))
{
// MOD end: Mobile/SEO style
]]></action>
</edit>
<edit>
<find><![CDATA[ if (!$this->theme)
{
trigger_error('Could not get style data', E_USER_ERROR);
}
]]></find>
<action type="before-add"><![CDATA[ // MOD start: Mobile/SEO style
}
if(defined('MOBILE_DEVICE_OFF'))
{
global $SID, $_EXTRA_URL;
$SID .= '&amp;nomobile=1';
$_EXTRA_URL[] = 'nomobile=1';
}
// MOD end: Mobile/SEO style
]]></action>
</edit>
<edit>
<find><![CDATA[ /**
* More advanced language substitution
]]></find>
<action type="before-add"><![CDATA[ // MOD start: Mobile/SEO style
/**
* Check for mobile/seo, get style
*/
function check_mobile($sql, $style)
{
$browser = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
if (empty($this->data['is_bot']) && strpos($browser, 'Mobile') === false && strpos($browser, 'Symbian') === false && strpos($browser, 'Opera M') === false && strpos($browser, 'Android') === false && stripos($browser, 'HTC_') === false && strpos($browser, 'Fennec/') === false && stripos($browser, 'Blackberry') === false && strpos($browser, 'Windows Phone') === false && strpos($browser, 'WP7') === false && strpos($browser, 'WP8') === false)
{
return true;
}
define('MOBILE_DEVICE', true);
if(!empty($_REQUEST['nomobile']))
{
define('MOBILE_DEVICE_OFF', true);
return true;
}
global $db;
// Important: change number 0 below to ID of Artodia:Mobile style.
// If it is set to 0, script will automatically find style, but it will use extra time and resources.
$mobile_style_id = 0;
if($mobile_style_id)
{
$sql2 = str_replace('s.style_id = ' . $style, 's.style_id = ' . $mobile_style_id, $sql);
$result = $db->sql_query($sql2, 3600);
$this->theme = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if($this->theme !== false)
{
define('MOBILE_STYLE', true);
return false;
}
}
// try to find style
global $phpbb_root_path;
$files = scandir($phpbb_root_path . 'styles');
$base = $phpbb_root_path . 'styles/';
for($i=0; $i<count($files); $i++)
{
if($files[$i] != '.' && $files[$i] != '..' && is_dir($base . $files[$i]) && @file_exists($base . $files[$i] . '/style.cfg'))
{
// found directory with style
$data = file_get_contents($base . $files[$i] . '/style.cfg');
if(strpos($data, 'mobile = 1') !== false && ($pos = strpos($data, 'name = ')) !== false)
{
$list = explode("\n", substr($data, $pos + 7), 2);
$name = trim($list[0]);
// found style
$sql2 = str_replace('s.style_id = ' . $style, 's.style_name = \'' . $db->sql_escape($name) . '\'', $sql);
$result = $db->sql_query($sql2, 3600);
$this->theme = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if($this->theme !== false)
{
define('MOBILE_STYLE', true);
return false;
}
}
}
}
return true;
}
// MOD end: Mobile/SEO style
]]></action>
</edit>
</open>
<diy-instructions lang="en"><![CDATA[After installing this mobile style and this modification, open includes/session.php, find $mobile_style_id and change its value from 0 to ID of this mobile style. If you do not change it, script will search for mobile style every time a mobile device is used to check forum page, so it is better to change it to reduce server load.]]></diy-instructions>
</action-group>
</mod>