Helper.php
2.44 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* @package Better Preview
* @version 6.1.0
*
* @author Peter van Westen <info@regularlabs.com>
* @link http://www.regularlabs.com
* @copyright Copyright © 2018 Regular Labs All Rights Reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
namespace RegularLabs\Plugin\System\BetterPreview;
defined('_JEXEC') or die;
use JFactory;
use JText;
use RegularLabs\Library\Document as RL_Document;
/**
* Plugin that replaces stuff
*/
class Helper
{
var $isadmin = false;
var $ispreview = false;
var $class = null;
public function __construct()
{
$this->isadmin = RL_Document::isAdmin();
$this->ispreview = JFactory::getApplication()->input->get('bp_preview');
}
public function onAfterRoute()
{
if (JFactory::getApplication()->input->get('bp_generatesefs'))
{
require_once 'GenerateSefs.php';
return false;
}
// only in admin and not on preview pages
if ( ! ($this->isadmin || $this->ispreview))
{
return false;
}
if (JFactory::getApplication()->input->get('bp_purgesefs'))
{
Sefs::purge();
return false;
}
if (JFactory::getApplication()->input->get('bp_preloader'))
{
PreLoader::_();
return false;
}
$params = Params::get();
if ($this->isadmin && ! $params->display_title_link && ! $params->display_status_link)
{
return false;
}
if ( ! $class = $this->getClass())
{
return false;
}
switch (true)
{
case ($this->ispreview):
// Check for request forgeries.
$class->checkSession() or jexit(JText::_('JINVALID_TOKEN'));
$class->purgeCache();
$class->setLanguage();
$class->states();
break;
case ($this->isadmin) :
Document::loadScriptsAndCSS();
break;
}
}
public function onContentPrepare($context, &$article)
{
if ( ! $this->ispreview)
{
return;
}
if ( ! $class = $this->getClass())
{
return;
}
$class->render($article, $context);
}
public function onAfterRender()
{
if ( ! $class = $this->getClass())
{
return;
}
switch (true)
{
case ($this->ispreview):
$class->restoreStates();
$class->addMessages();
break;
case ($this->isadmin) :
$class->convertLinks();
break;
}
}
public function getClass()
{
if ( ! is_null($this->class))
{
return $this->class;
}
$type = $this->ispreview ? 'Preview' : 'Link';
$this->class = Component::getClass($type);
return $this->class;
}
}