-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjlnodoubles.php
247 lines (211 loc) · 7.48 KB
/
jlnodoubles.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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/**
* @package plg_jlnodubles
* @author Arkadiy (a.sedelnikov@gmail.com), Vadim Kunicin (vadim@joomline.ru), Sher ZA (irina@hekima.ru).
* @version 2.5.1
* @copyright (C) 2014-2019 by JoomLine (http://www.joomline.net)
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
*
*/
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
jimport('joomla.error.error');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
require_once JPATH_ROOT . '/plugins/system/jlnodoubles/helpers/helper.php';
class plgSystemJlnodoubles extends JPlugin
{
public static $noRedirect = null;
public static $isPro = true;
public static $sef;
function __construct(&$subject, $config = array())
{
parent::__construct($subject, $config);
self::$noRedirect = $this->stopWords();
self::$sef = JFactory::getConfig()->get('sef', 0);
}
public function onAfterRoute()
{
if(!self::$sef) return true;
$app = JFactory::getApplication();
if ($app->getName() != 'site' || self::$noRedirect)
{
return true;
}
$option = $app->input->getCmd('option', '');
$Itemid = $app->input->getInt('Itemid', 0);
$view = $app->input->getCmd('view', '');
$id = $app->input->getString('id', 0);
$task = $app->input->getCmd('task', '');
$layout = $app->input->getCmd('layout', '');
$lang = $app->input->getCmd('lang', '');
$tmpl = $app->input->getCmd('tmpl', '');
$allGet = array(
'Itemid' => $Itemid,
'option' => $option,
'view' => $view,
'id' => $id,
'task' => $task,
'layout' => $layout,
'lang' => $lang,
'tmpl' => $tmpl
);
$u = JUri::getInstance();
$currentLink = $u->toString(array('path'));
$defValue = array(
array(
'var_name' => array( 'task', 'format', 'no_html', 'tmpl' ),
'var_value' => array( 'save, edit, add, delete, apply', 'nohtml', '1', 'component' )
),
'com_content' => array( 'checkbox' => 'on', 'var_name' => array(''), 'var_value' => array('') )
);
$componentsvars = $this->params->get('componentsvars', $defValue);
if (is_object($componentsvars))
{
$tmp = array();
foreach ($componentsvars as $k => $val)
{
$tmp[$k] = (array)$val;
}
$componentsvars = $tmp;
unset($tmp);
}
$helpers = JFolder::files(JPATH_ROOT.'/plugins/system/jlnodoubles/helpers');
if (!isset($componentsvars[$option]["checkbox"]))
{
self::$noRedirect = true;
return true;
}
if (isset($componentsvars[$option]))
{
for ($i = 0; $i < sizeof($componentsvars[$option]["var_name"]); $i++)
{
$var_name = $componentsvars[$option]["var_name"][$i];
if (trim($componentsvars[$option]["var_value"][$i]))
{
$var_values = array_map('trim', explode(',', $componentsvars[$option]["var_value"][$i]));
foreach ($var_values as $vvalue)
{
if (isset($allGet[trim($var_name)])
&& $allGet[trim($var_name)] == trim($vvalue)
) {
self::$noRedirect = true;
return true;
}
}
}
else if (isset($allGet[$var_name]))
{
self::$noRedirect = true;
return true;
}
}
}
$helperPath = JPATH_ROOT.'/plugins/system/jlnodoubles/helpers/'.$option.'.php';
$return = true;
if(is_file($helperPath) && ($option == 'com_content' || $option == 'com_tags' || self::$isPro))
{
require_once $helperPath;
$class = 'JLNodoubles_' . $option . '_helper';
if(class_exists($class))
{
$this->params->set('isPro', self::$isPro);
$helper = new $class($this->params);
if(method_exists($helper, 'go'))
{
$return = $helper->go($allGet);
}
}
}
if ($option && $return == false)
{
$allGetArr = array();
foreach ($allGet as $ag_name => $ag_value) {
if ($ag_name && $ag_value) $allGetArr[] = $ag_name . '=' . $ag_value;
}
if (!$Itemid)
{
$app = JFactory::getApplication();
$menus = $app->getMenu();
//$menus = &JApplication::getMenu('site', array());
$component_menu = $menus->getItems('component', $option);
$Itemid = $component_menu[0]->id;
if ($Itemid) $allGetArr[] = 'Itemid=' . $Itemid;
}
$redirectLink = JRoute::_('index.php?' . implode('&', $allGetArr));
if ($redirectLink != urldecode($currentLink)) {
JLNodoublesHelper::getInstance($this->params)->shRedirect($redirectLink);
}
}
return true;
}
public function onAfterRender()
{
if (JFactory::getApplication()->getName() != 'site' || self::$noRedirect || !self::$sef)
{
return true;
}
$homealias = $this->params->get('homealias', 'home');
$buffer = JResponse::getBody();
$regex = '#component/content/article/#m';
$buffer = preg_replace($regex, $homealias . '/', $buffer);
JResponse::setBody($buffer);
return true;
}
public function onAfterInitialise()
{
if(!self::$sef) return true;
$application = JFactory::getApplication();
if($application->getName() != 'site'){
return;
}
$router = $application->getRouter();
if ($router->getMode() == JROUTER_MODE_SEF) {
$router->attachBuildRule(array(&$this, 'build'));
//$router->attachParseRule(array(&$this, 'parse'));
}
}
public function build(&$router, &$uri)
{
// Get the route
$route = $uri->getPath();
// Get the query data
$query = $uri->getQuery(true);
if ($query['option'] == 'com_content')
{
$toUnset = array('showall', 'start', 'limitstart');
foreach ($toUnset as $tu)
{
if (isset($query[$tu]) && !$query[$tu]) unset($query[$tu]);
}
} else return;
//Set query again in the URI
$uri->setQuery($query);
$uri->setPath($route);
}
private function stopWords()
{
$stopWords = $this->params->get('stop_words','');
if(empty($stopWords))
{
return false;
}
$stopWords = explode("\n", $stopWords);
if(count($stopWords)){
$u = JUri::getInstance();
$uri = $u->toString(array('path', 'query'));
foreach($stopWords as $stopWord)
{
$stopWord = trim($stopWord);
if(empty($stopWord))
{
continue;
}
if(strpos($uri, $stopWord) !== false){
return true;
}
}
}
return false;
}
}