This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuk3accordion.php
108 lines (98 loc) · 4.88 KB
/
uk3accordion.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
<?php defined('_JEXEC') or die;
/**
* @package Joomla.Plugin
* @subpackage Content.uk3accordion
* @copyright Copyright (C) Aleksey A. Morozov. All rights reserved.
* @license GNU General Public License version 3 or later; see http://www.gnu.org/licenses/gpl-3.0.txt
*/
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Filter\OutputFilter;
class PlgContentUk3accordion extends CMSPlugin
{
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
if ($context == 'com_finder.indexer' || !preg_match('/{accordion\s(.*)}/s', $article->text)) {
return false;
}
$vars = [
'accordion_class', 'title_class', 'content_class',
'active', 'multiple', 'collapsible', 'animation', 'duration', 'transition',
];
foreach ($vars as $var) {
$$var = $this->params->get($var);
}
$layout = Path::clean(PluginHelper::getLayoutPath('content', 'uk3accordion'));
$layout = pathinfo($layout, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . pathinfo($layout, PATHINFO_FILENAME);
$accordion_class = trim($accordion_class) ? ' ' . trim($accordion_class) : '';
$title_class = trim($title_class) ? ' ' . trim($title_class) : '';
$content_class = trim($content_class) ? ' ' . trim($content_class) : '';
$accordion_params = [];
if ((int)$active > 0) $accordion_params[] = 'active:' . $active;
if ($multiple) $accordion_params[] = 'multiple:true';
if (!$collapsible && !$multiple) $accordion_params[] = 'collapsible:false';
if (!$animation) {
$accordion_params[] = 'animation:false';
} else {
if ($duration > 0 && (int)$duration != 200) $accordion_params[] = 'duration:' . $duration;
if ($transition != 'ease') $accordion_params[] = 'transition:' . $transition;
}
$accordion_params = $accordion_params ? '="' . implode(';', $accordion_params) . '"' : '';
$accordion = [];
$matches = [];
if (preg_match_all('/{accordion\s(.*)}{accordion\s(.*)}|{accordion\s(.*)}|{\/accordion}/', $article->text, $matches, PREG_PATTERN_ORDER) > 0) {
$article->text = preg_replace('|<[^>]+>{accordion\s(.*)}</[^>]+>|U', '{accordion \\1}', $article->text);
$article->text = preg_replace('|<(.*)>{accordion\s(.*)}|U', '{accordion \\2}<\\1>', $article->text);
$article->text = preg_replace('|{accordion\s(.*)}</(.*)>|U', '</\\2>{accordion \\1}', $article->text);
$article->text = preg_replace('|<[^>]+>{/accordion}</[^>]+>|U', '{/accordion}', $article->text);
$article->text = preg_replace('|<(.*)>{/accordion}|U', '{/accordion}<\\1>', $article->text);
$article->text = preg_replace('|{/accordion}</(.*)>|U', '</\\1>{/accordion}', $article->text);
$step = 1;
foreach ($matches[0] as $match) {
if ($step == 1 && $match != '{/accordion}') {
$accordion[] = 1;
$step = 2;
} elseif ($match == '{/accordion}') {
$accordion[] = 3;
$step = 1;
} elseif (preg_match('/{accordion\s(.*)}{accordion\s(.*)}/', $match)) {
$accordion[] = 2;
$accordion[] = 1;
$step = 2;
} else {
$accordion[] = 2;
}
}
}
if ($matches) {
Factory::getDocument()->addScript('/plugins/content/uk3accordion/assets/plgukaccordion.js');
$accordionCount = 0;
foreach ($matches[0] as $match) {
if ($accordion[$accordionCount] < 3) {
$title = preg_replace('|{accordion\s(.*)}|U', '\\1', $match);
$title = strip_tags($title);
$id = 'slide-' . OutputFilter::stringURLSafe($title);
$match = '|' . str_replace(['/', '?'], ['\/', '\?'], preg_quote($match)) . '|U';
ob_start();
include $layout . ($accordion[$accordionCount] < 2 ? '_start.php' : '_li_end.php');
include $layout . '_li_start.php';
$accordion_content = ob_get_clean();
} elseif ($accordion[$accordionCount] == 3) {
$match = '|{/accordion}|U';
ob_start();
include $layout . '_li_end.php';
include $layout . '_end.php';
$accordion_content = ob_get_clean();
}
$atext = $article->text;
$atext = preg_replace($match, $accordion_content, $atext, 1);
if ($atext) {
$article->text = $atext;
}
$accordionCount++;
}
}
}
}