|
1
|
|
|
<?php namespace XoopsModules\Mymenus\Plugins\MyMenus; |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
15
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License |
|
16
|
|
|
* @package Mymenus |
|
17
|
|
|
* @since 1.0 |
|
18
|
|
|
* @author trabis <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use Xmf\Request; |
|
|
|
|
|
|
22
|
|
|
use XoopsModules\Mymenus; |
|
23
|
|
|
|
|
24
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class PluginItem |
|
28
|
|
|
*/ |
|
29
|
|
|
class PluginItem extends Mymenus\PluginItem |
|
30
|
|
|
{ |
|
31
|
|
|
public static function eventBoot() |
|
32
|
|
|
{ |
|
33
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
34
|
|
|
/** @var \XoopsMemberHandler $memberHandler */ |
|
35
|
|
|
$memberHandler = xoops_getHandler('member'); |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
$user = ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser'] : null; |
|
|
|
|
|
|
38
|
|
|
if (!$user) { |
|
39
|
|
|
$user = $memberHandler->createUser(); |
|
40
|
|
|
$user->setVar('uid', 0); |
|
41
|
|
|
$user->setVar('uname', $GLOBALS['xoopsConfig']['anonymous']); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$ownerid = Request::getInt('uid', null, 'GET'); |
|
45
|
|
|
$owner = $memberHandler->getUser($ownerid); |
|
46
|
|
|
//if uid > 0 but user does not exists |
|
47
|
|
|
if (!($owner instanceof \XoopsUser)) { |
|
48
|
|
|
//create new user |
|
49
|
|
|
$owner = $memberHandler->createUser(); |
|
50
|
|
|
} |
|
51
|
|
|
if ($owner->isNew()) { |
|
52
|
|
|
$owner->setVar('uid', 0); |
|
53
|
|
|
$owner->setVar('uname', $GLOBALS['xoopsConfig']['anonymous']); |
|
54
|
|
|
} |
|
55
|
|
|
$registry->setEntry('user', $user->getValues()); |
|
56
|
|
|
$registry->setEntry('owner', $owner->getValues()); |
|
57
|
|
|
$registry->setEntry('user_groups', ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS]); |
|
|
|
|
|
|
58
|
|
|
$registry->setEntry('user_uid', ($GLOBALS['xoopsUser'] instanceof \XoopsUser) ? $GLOBALS['xoopsUser']->getVar('uid') : 0); |
|
59
|
|
|
$registry->setEntry('get_uid', Request::getInt('uid', 0, 'GET')); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function eventLinkDecoration() |
|
63
|
|
|
{ |
|
64
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
65
|
|
|
$linkArray = $registry->getEntry('link_array'); |
|
|
|
|
|
|
66
|
|
|
$linkArray['link'] = self::doDecoration($linkArray['link']); |
|
67
|
|
|
//if (!eregi('mailto:', $linkArray['link']) && !eregi('://', $linkArray['link'])) { |
|
68
|
|
|
if (!preg_match('/mailto:/i', $linkArray['link']) && !preg_match('#://#i', $linkArray['link'])) { |
|
69
|
|
|
$linkArray['link'] = XOOPS_URL . '/' . $linkArray['link']; //Do not do this in other decorators |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
$registry->setEntry('link_array', $linkArray); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public static function eventImageDecoration() |
|
75
|
|
|
{ |
|
76
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
77
|
|
|
$linkArray = $registry->getEntry('link_array'); |
|
|
|
|
|
|
78
|
|
|
if ($linkArray['image'] && !filter_var($linkArray['image'], FILTER_VALIDATE_URL)) { |
|
79
|
|
|
$linkArray['image'] = XOOPS_URL . '/' . $linkArray['image']; |
|
|
|
|
|
|
80
|
|
|
//Do not do this in other decorators |
|
81
|
|
|
$linkArray['image'] = self::doDecoration($linkArray['image']); |
|
82
|
|
|
$registry->setEntry('link_array', $linkArray); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public static function eventTitleDecoration() |
|
87
|
|
|
{ |
|
88
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
89
|
|
|
$linkArray = $registry->getEntry('link_array'); |
|
|
|
|
|
|
90
|
|
|
$linkArray['title'] = self::doDecoration($linkArray['title']); |
|
91
|
|
|
$registry->setEntry('link_array', $linkArray); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public static function eventAltTitleDecoration() |
|
95
|
|
|
{ |
|
96
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
97
|
|
|
$linkArray = $registry->getEntry('link_array'); |
|
|
|
|
|
|
98
|
|
|
if (!$linkArray['alt_title']) { |
|
99
|
|
|
$linkArray['alt_title'] = $linkArray['title']; |
|
100
|
|
|
} |
|
101
|
|
|
$linkArray['alt_title'] = self::doDecoration($linkArray['alt_title']); |
|
102
|
|
|
$registry->setEntry('link_array', $linkArray); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param $string |
|
107
|
|
|
* |
|
108
|
|
|
* @return mixed |
|
109
|
|
|
*/ |
|
110
|
|
|
protected static function doDecoration($string) |
|
111
|
|
|
{ |
|
112
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
113
|
|
|
//if (!eregi("{(.*\|.*)}", $string, $reg)) { |
|
114
|
|
|
if (!preg_match('/{(.*\|.*)}/i', $string, $reg)) { |
|
115
|
|
|
return $string; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$expression = $reg[0]; |
|
119
|
|
|
list($validator, $value) = array_map('strtolower', explode('|', $reg[1])); |
|
120
|
|
|
|
|
121
|
|
|
//just to prevent any bad admin to get easy passwords |
|
122
|
|
|
if ('pass' === $value) { |
|
123
|
|
|
return $string; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if ('user' === $validator) { |
|
127
|
|
|
$user = $registry->getEntry('user'); |
|
|
|
|
|
|
128
|
|
|
$value = isset($user[$value]) ? $user[$value] : static::getExtraValue('user', $value); |
|
129
|
|
|
$string = str_replace($expression, $value, $string); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
if ('uri' === $validator) { |
|
133
|
|
|
$value = Request::getString($value, 0, 'GET'); |
|
134
|
|
|
$string = str_replace($expression, $value, $string); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
if ('owner' === $validator) { |
|
138
|
|
|
$owner = $registry->getEntry('owner'); |
|
|
|
|
|
|
139
|
|
|
$value = isset($owner[$value]) ? $owner[$value] : static::getExtraValue('owner', $value); |
|
140
|
|
|
$string = str_replace($expression, $value, $string); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
return $string; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public static function eventFormLinkDescription() |
|
147
|
|
|
{ |
|
148
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
149
|
|
|
$description = $registry->getEntry('form_link_description'); |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public static function eventHasAccess() |
|
153
|
|
|
{ |
|
154
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
155
|
|
|
$menu = $registry->getEntry('menu'); |
|
|
|
|
|
|
156
|
|
|
$groups = $registry->getEntry('user_groups'); |
|
|
|
|
|
|
157
|
|
|
if (0 == $menu['visible'] || !array_intersect($menu['groups'], $groups)) { |
|
158
|
|
|
$registry->setEntry('has_access', 'no'); |
|
159
|
|
|
|
|
160
|
|
|
return; |
|
161
|
|
|
} |
|
162
|
|
|
$hooks = array_intersect($menu['hooks'], get_class_methods(__CLASS__)); |
|
163
|
|
|
|
|
164
|
|
|
foreach ($hooks as $method) { |
|
165
|
|
|
if (!self::$method()) { |
|
166
|
|
|
$registry->setEntry('has_access', 'no'); |
|
167
|
|
|
|
|
168
|
|
|
return; |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public static function eventAccessFilter() |
|
174
|
|
|
{ |
|
175
|
|
|
static::loadLanguage('mymenus'); |
|
176
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
177
|
|
|
$accessFilter = $registry->getEntry('accessFilter'); |
|
|
|
|
|
|
178
|
|
|
$accessFilter['is_owner']['name'] = _PL_MYMENUS_MYMENUS_ISOWNER; |
|
179
|
|
|
$accessFilter['is_owner']['method'] = 'isOwner'; |
|
180
|
|
|
$accessFilter['is_not_owner']['name'] = _PL_MYMENUS_MYMENUS_ISNOTOWNER; |
|
181
|
|
|
$accessFilter['is_not_owner']['method'] = 'isNotOwner'; |
|
182
|
|
|
$registry->setEntry('accessFilter', $accessFilter); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @return bool |
|
187
|
|
|
*/ |
|
188
|
|
|
public function isOwner() |
|
189
|
|
|
{ |
|
190
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
191
|
|
|
|
|
192
|
|
|
return (0 != $registry->getEntry('user_uid') |
|
|
|
|
|
|
193
|
|
|
&& $registry->getEntry('user_uid') == $registry->getEntry('get_uid')); |
|
|
|
|
|
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @return bool |
|
198
|
|
|
*/ |
|
199
|
|
|
public function isNotOwner() |
|
200
|
|
|
{ |
|
201
|
|
|
return !$this->isOwner(); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @param string $type |
|
206
|
|
|
* @param $value |
|
207
|
|
|
* |
|
208
|
|
|
* @return int |
|
209
|
|
|
*/ |
|
210
|
|
|
public static function getExtraValue($type = 'user', $value) |
|
211
|
|
|
{ |
|
212
|
|
|
$registry = Mymenus\Registry::getInstance(); |
|
213
|
|
|
$ret = 0; |
|
214
|
|
|
$values = ['pm_new', 'pm_readed', 'pm_total']; |
|
215
|
|
|
if (!in_array($value, $values)) { |
|
216
|
|
|
return $ret; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
$entry = $registry->getEntry($type); |
|
|
|
|
|
|
220
|
|
|
if (!$entry) { |
|
|
|
|
|
|
221
|
|
|
return $ret; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
$pmHandler = xoops_getHandler('privmessage'); |
|
|
|
|
|
|
225
|
|
|
|
|
226
|
|
|
if ('pm_new' === $value) { |
|
227
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('read_msg', 0)); |
|
|
|
|
|
|
228
|
|
|
$criteria->add(new \Criteria('to_userid', $entry['uid'])); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
if ('pm_readed' === $value) { |
|
232
|
|
|
$criteria = new \CriteriaCompo(new \Criteria('read_msg', 1)); |
|
233
|
|
|
$criteria->add(new \Criteria('to_userid', $entry['uid'])); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
if ('pm_total' === $value) { |
|
237
|
|
|
$criteria = new \Criteria('to_userid', $entry['uid']); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
$entry[$value] = $pmHandler->getCount($criteria); |
|
241
|
|
|
|
|
242
|
|
|
$registry->setEntry($type, $entry); |
|
243
|
|
|
|
|
244
|
|
|
unset($criteria); |
|
245
|
|
|
|
|
246
|
|
|
return $entry[$value]; |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths