-
Notifications
You must be signed in to change notification settings - Fork 0
/
wbty_accordion.php
105 lines (94 loc) · 3.29 KB
/
wbty_accordion.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
<?php
/**
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access.
defined('_JEXEC') or die;
/**
* Email cloack plugin class.
*
* @package Joomla.Plugin
* @subpackage Content.wbty_accordion
*/
class plgContentWbty_accordion extends JPlugin
{
var $script_added = false;
/**
* Plugin that cloaks all emails in content from spambots via Javascript.
*
* @param string The context of the content being passed to the plugin.
* @param mixed An object with a "text" property or the string to be cloaked.
* @param array Additional parameters. See {@see plgEmailCloak()}.
* @param int Optional page number. Unused. Defaults to zero.
* @return boolean True on success.
*/
public function onContentPrepare($context, &$row, &$params, $page = 0)
{
// Don't run this plugin when the content is being indexed
if ($context == 'com_finder.indexer') {
return true;
}
if (is_object($row)) {
return $this->_scan($row->text);
}
return $this->_scan($row);
}
protected function _scan(&$text)
{
for ($i=0; $i<8; $i++) {
$text = preg_replace_callback('/({wbty_accordion})(.*)({\/wbty_accordion})/siU',
array(get_class($this),'_buildAccordion'),
$text);
}
return true;
}
protected function _buildAccordion($matches) {
$header_tag = $this->params->get('header_tag');
if (!$this->script_added) {
$document =& JFactory::getDocument();
$jversion = new JVersion();
$above3 = version_compare($jversion->getShortVersion(), '3.0', 'ge');
if ($above3) {
JHTML::_('jquery.framework');
} else {
//JHTML::script('plg_content_wbty_accordion/jquery-1.8.3.js', false, true);
}
$document->addStyleSheet(JURI::root(true) . '/media/plg_content_wbty_accordion/css/no-theme/jquery-ui-1.9.2.custom.css');
$document->addScriptDeclaration("
window.addEvent('load', function() {
loadAccordion();
});
function loadAccordion() {
if(!window.jQuery)
{
var script = document.createElement('script');
script.type = \"text/javascript\";
script.src = \"".JURI::root(true) . '/media/plg_content_wbty_accordion/js/jquery-1.8.3.js'."\";
document.getElementsByTagName('head')[0].appendChild(script);
setTimeout(function() {loadAccordion();}, 1500);
} else {
jQuery.getScript(\"".JURI::root(true) . '/media/plg_content_wbty_accordion/js/jquery-ui-1.9.2.custom.min.js'."\")
.done(function(script, textStatus) {
jQuery('.wbty_accordion').accordion({
header: '".$header_tag."',
heightStyle: 'content'". ( $this->params->get('collapsed') ? ", active: false, collapsible: true" : "" ) ."
});
});
}
}
");
$this->script_added = true;
}
$return = $matches[2];
$append = '';
if (strpos($return, '{/wbty_accordion}')!== FALSE) {
$split = explode('{/wbty_accordion}', $return);
$return = $split[0];
unset($split[0]);
$append = implode('{/wbty_accordion}', $split).'{/wbty_accordion}';
}
$return = '<div class="wbty_accordion"><div>'.str_replace(array('<'.$header_tag.'>','</'.$header_tag.'>'), array('</div><'.$header_tag.'>','</'.$header_tag.'><div>'), $return).'</div></div>'.$append;
return $return;
}
}