nextendsmartslider3.php
3 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
<?php
jimport('joomla.plugin.plugin');
class plgSystemNextendSmartslider3 extends JPlugin {
public function onInitN2Library() {
N2Base::registerApplication(JPATH_SITE . DIRECTORY_SEPARATOR . "libraries" . DIRECTORY_SEPARATOR . 'nextend2/smartslider/smartslider/N2SmartsliderApplicationInfo.php');
}
public function onNextendBeforeCompileHead() {
$application = JFactory::getApplication();
if ($application->isSite()) {
$request = $application->input->request;
if (method_exists($application, 'frontediting') && $application->get('frontediting', 1) && !JFactory::getUser()->guest && $request->get('option') == 'com_content' && $request->get('view') == 'form' && $request->get('layout') == 'edit') {
return;
}
if (class_exists('JApplicationWeb') && method_exists($application, 'getBody')) {
$body = $application->getBody();
$mode = 'JApplicationWeb';
} else {
$body = JResponse::getBody();
$mode = 'JResponse';
}
// Simple performance check to determine whether bot should process further
if (strpos($body, 'smartslider3[') !== false) {
if (class_exists('EshopHelper', false) && EshopHelper::getConfigValue('rich_snippets') == '1') {
$body = preg_replace_callback('/(<.*?>)?smartslider3\[([0-9]+)\]/', 'plgSystemNextendSmartslider3::cleanEshop', $body);
}
$bodyParts = explode('</head>', $body);
if (isset($bodyParts[0]) && isset($bodyParts[1])) {
$bodyParts[1] = preg_replace_callback('/smartslider3\[([0-9]+)\]/', 'plgSystemNextendSmartslider3::prepare', $bodyParts[1]);
} else {
$bodyParts[0] = preg_replace_callback('/smartslider3\[([0-9]+)\]/', 'plgSystemNextendSmartslider3::prepare', $bodyParts[0]);
}
switch ($mode) {
case 'JResponse':
JResponse::setBody(implode('</head>', $bodyParts));
break;
default:
$application->setBody(implode('</head>', $bodyParts));
}
}
}
}
public static function prepare($matches) {
ob_start();
nextend_smartslider3($matches[1]);
return ob_get_clean();
}
public static function cleanEshop($matches) {
if (strpos($matches[1], 'itemprop') !== false) {
return $matches[1];
}
return $matches[0];
}
}
function nextend_smartslider3($sliderId, $usage = 'Used in PHP') {
jimport("nextend2.nextend.joomla.library");
N2Base::getApplication("smartslider")
->getApplicationType('frontend')
->render(array(
"controller" => 'home',
"action" => 'joomla',
"useRequest" => false
), array(
$sliderId,
$usage
));
}