-
Notifications
You must be signed in to change notification settings - Fork 3
/
universalbuttons.php
executable file
·152 lines (95 loc) · 3.33 KB
/
universalbuttons.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
<?php
/**
* @version 1.4
* @package Joomla
* @subpackage System
* @copyright Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.
* @license GNU GPL v2.0
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
class plgButtonUniversalButtons extends JPlugin
{
public function onDisplay($name, &$params)
{
//retrieve Buttons
$buttons = $this->params->get('buttons');
$arr = (array) $buttons;
$buttons = array();
$i=0;
$additional_names = '';
foreach ($arr as $value) {
// check autorisation
$autorised = 'false';
$usergroups = JAccess::getGroupsByUser(JFactory::getUser()->get('id'), $recursive = true);
if (empty($value->usergroups)) { // if not set show button
$autorised = 'true';
}
elseif (array_sum(array_count_values(array_intersect($usergroups, $value->usergroups)))>0) {
// compare user and usergroup values for matches. by summing the matching array ID`s.
$autorised = 'true';
}
if ($autorised == 'true') {
switch ($value->style) {
case "0":
$app = Factory::getApplication();
// ...
$root = '';
if ($app->isClient('administrator')) {
$root = '../'; // Joomla expects a relative path, leave site folder "administrator"
} else {
$root = '';
}
$button = new JObject();
$url = $root . $value->url;
if ($this->params->get('componentonly')==1 ) {
if( strpos( $url , '?' ) !== false) {
$url .= $url . '&tmpl=component' ;
} else {
$url .= $url . '?tmpl=component' ;
}
}
$button->set('link', $url);
$button->set('options', "{handler: 'iframe', size: {x: ".$value->popupwidth.", y: ".$value->popupheight."}}");
$button->set('text', $value->Buttonlabel);
//$button->set('onclick', 'insertText(\''.$value->name .'\')');
$button->set('name', $value->Buttonicon);
$buttons[$i]= $button ;
break;
case "1":
// remove enters
$value->code= str_replace(array("\n", "\r"), ' ', $value->code);
$js = " function buttonClick".$i."(editor) { let str = '". $value->code . "';
";
$subforminputs = $value->variables;
$arr2 = (array) $subforminputs;
$iVariable=1;
foreach ($arr2 as $value2) {
$js .= " txt".$iVariable." = prompt('". $value2->Variablelabel. "','".$value2->variabledefault."');
str = str.replace(/%".$iVariable."/g,txt".$iVariable.");
";
$iVariable++;
}
$js .= " Joomla.editors.instances[editor].replaceSelection(str); }";
$css = "";
$doc = JFactory::getDocument();
$doc->addScriptDeclaration($js);
$doc->addStyleDeclaration($css);
$button = new JObject();
$button->set('modal', false);
$button->set('onclick', 'buttonClick'.$i.'(\''.$name.'\');return false;');
$button->set('text', $value->Buttonlabel);
$button->set('name', $value->Buttonicon);
$button->set('link', '#');
$buttons[$i]= $button ;
break;
case "2":
break;
} // end case
$i++;
}// end autorised
} // end foreach
return $buttons;
} // end ondisplay
}
?>