forked from bembelimen/Joomla-Intro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro.php
executable file
·83 lines (63 loc) · 2.58 KB
/
intro.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
// no direct access
defined('_JEXEC') or die;
jimport('joomla.event.plugin');
class plgSystemIntro extends JPlugin
{
// OnAfterDispatch event to render the introsite.
public function OnAfterDispatch()
{
// Exlude bots from execution if option is set in the settings
if($this->params->get('nobots'))
{
$agent = $_SERVER['HTTP_USER_AGENT'];
$botslist = array_map('trim', explode(',', $this->params->get('botslist')));
foreach($botslist as $bot)
{
if(preg_match('@'.$bot.'@i', $agent))
{
return;
}
}
}
$app = JFactory::getApplication();
$doc = JFactory::getDocument();
//check for frontend
if(!$app->isSite())
return;
// check for intro into the session
$intro = $app->getUserState('plugin.system.intro');
// a small google hack
// normal visitors start at the frontpage, so they will see the intro content
// google bots (or other search engines) visit sub links => don't show them the intro content
// this is important, or google will list the intro content for every link at the homepage
$active = $app->getMenu()->getActive();
if(empty($intro) && !empty($active->home))
{
// load the component.php for a valid html structure
$file = 'component.php';
// allow to use an own "intro.php" just for the intro text...
if(JFile::exists(JPATH_THEMES.'/'.$app->getTemplate().'/intro.php'))
{
$file = 'intro.php';
}
$params = array('template' => $app->getTemplate(), 'file' => $file, 'directory' => JPATH_THEMES);
$doc->parse($params);
// inject the plugin content
$doc->setBuffer($this->params->get('intro'), array('type' => 'component', 'name' => null));
JResponse::setHeader('Content-Type', $doc->getMimeEncoding().($doc->getCharset() ? '; charset='.$doc->getCharset() : ''));
$caching = ($app->getCfg('caching') >= 2) ? true : false;
// output the whole template
echo $doc->render($caching, $params);
// set intro to session
$app->setUserState('plugin.system.intro', 1);
// stop rendering the site and show the html-output
$app->close();
}
// keep the session alive
if($this->params->get('session'))
{
echo JHTML::_('behavior.keepalive');
}
}
}