-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplateswitcher.php
More file actions
executable file
·61 lines (53 loc) · 1.67 KB
/
Copy pathtemplateswitcher.php
File metadata and controls
executable file
·61 lines (53 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
defined('_JEXEC') or die('Restricted access');
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
class plgSystemTemplateSwitcher extends JPlugin
{
protected $autoloadLanguage = true;
public function onAfterInitialise()
{
$app = JFactory::getApplication();
$session = JFactory::getSession();
// Confirm we are on the front end
if($app instanceof JApplicationSite)
{
require_once(JPATH_SITE . '/plugins/system/templateswitcher/mdetect/Mobile_Detect.php');
$browser = new Mobile_Detect();
$jinput = $app->input;
$jget = $jinput->get;
$jget_fullsite = $jget->get('fullsite', '', 'string');
$full_site = $session->get('fullsite');
// Some sites may have a "full site" link somewhere on the page
if(isset($jget_fullsite) && !empty($jget_fullsite))
{
$session->set('fullsite', true);
$full_site = true;
}
/**
* @todo Add option to enable/disable tablets as "mobile"
* @todo Investigate other uses for changing to secondary template (i.e. use in-development template for certain IPs)
*/
if(($browser->isMobile() && !$browser->isTablet()) && $full_site !== true)
{
$template = $this->params->get('template');
$db = JFactory::getDbo();
$sql = $db->getQuery(true);
$sql
->select('params')
->from($db->quoteName('#__template_styles'))
->where('template = ' . $db->quote($template));
$db->setQuery($sql, 0, 1);
try
{
$params = $db->loadResult();
}
catch(RuntimeException $e)
{
$params = null;
}
$app->setTemplate($template, $params);
}
}
return true;
}
}