-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathuniversalbuttons.php
More file actions
executable file
·157 lines (104 loc) · 3.55 KB
/
Copy pathuniversalbuttons.php
File metadata and controls
executable file
·157 lines (104 loc) · 3.55 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
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
<?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;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Access\Access;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Uri\Uri;
class plgButtonUniversalButtons extends CMSPlugin
{
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 = Access::getGroupsByUser(Factory::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 = '';
}
$url = $root . $value->url ;
if ($value->Componentonly==true ) {
if( strpos( $url , '?' ) !== false) {
$url .= '&tmpl=component' ;
} else {
$url .= '?tmpl=component' ;
}
}
$button = new CMSObject();
$button->modal = true;
$button->class = 'btn';
$button->set('link', $url);
$button->options = "{handler: 'iframe', size: {x: ".$value->popupwidth.", y: ".$value->popupheight."}}";
$button->set('name', 'button'. $i );
$button->set('text', $value->Buttonlabel);
$button->set('icon', $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."');
if (txt".$iVariable." !== null) {
str = str.replace(/%".$iVariable."/g,txt".$iVariable.");
}
";
$iVariable++;
}
$js .= " if (str.includes('%') == false) { Joomla.editors.instances[editor].replaceSelection(str);} }";
$css = "";
$doc = Factory::getDocument();
$doc->addScriptDeclaration($js);
$doc->addStyleDeclaration($css);
$button = new CMSObject();
$button->set('modal', false);
$button->set('onclick', 'buttonClick'.$i.'(\''.$name.'\');return false;');
$button->set('name', 'button'. $i );
$button->set('text', $value->Buttonlabel);
$button->set('icon', $value->Buttonicon);
$button->set('link', '#');
$buttons[$i]= $button ;
break;
case "2":
break;
} // end case
$i++;
}// end autorised
} // end foreach
return $buttons;
} // end ondisplay
}
?>