1 | <?php |
||||||
2 | |||||||
3 | declare(strict_types=1); |
||||||
4 | |||||||
5 | /* |
||||||
6 | You may not change or alter any portion of this comment or credits |
||||||
7 | of supporting developers from this source code or any supporting source code |
||||||
8 | which is considered copyrighted (c) material of the original comment or credit authors. |
||||||
9 | |||||||
10 | This program is distributed in the hope that it will be useful, |
||||||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||||
13 | */ |
||||||
14 | |||||||
15 | /** |
||||||
16 | * Extended User Profile |
||||||
17 | * |
||||||
18 | * @copyright XOOPS Project https://xoops.org/ |
||||||
19 | * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
||||||
20 | * @author Jan Pedersen |
||||||
21 | * @author Taiwen Jiang <[email protected]> |
||||||
22 | * @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
||||||
23 | */ |
||||||
24 | |||||||
25 | use Xmf\Request; |
||||||
26 | use XoopsModules\Yogurt; |
||||||
27 | use XoopsModules\Yogurt\IndexController; |
||||||
28 | |||||||
29 | $GLOBALS['xoopsOption']['template_main'] = 'yogurt_editprofile.tpl'; |
||||||
30 | require __DIR__ . '/header.php'; |
||||||
31 | |||||||
32 | /** |
||||||
33 | * Fetching numbers of groups friends videos pictures etc... |
||||||
34 | */ |
||||||
35 | $controller = new IndexController($xoopsDB, $xoopsUser, $xoopsModule); |
||||||
0 ignored issues
–
show
|
|||||||
36 | $nbSections = $controller->getNumbersSections(); |
||||||
37 | |||||||
38 | require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
||||||
39 | |||||||
40 | // If not a user, redirect |
||||||
41 | if (!is_object($GLOBALS['xoopsUser'])) { |
||||||
42 | redirect_header(XOOPS_URL, 3, _US_NOEDITRIGHT); |
||||||
43 | } |
||||||
44 | |||||||
45 | $myts = MyTextSanitizer::getInstance(); |
||||||
46 | $op = Request::getCmd('op', editprofile); |
||||||
0 ignored issues
–
show
|
|||||||
47 | /* @var XoopsConfigHandler $config_handler */ |
||||||
48 | $config_handler = xoops_getHandler('config'); |
||||||
49 | $GLOBALS['xoopsConfigUser'] = $config_handler->getConfigsByCat(XOOPS_CONF_USER); |
||||||
50 | |||||||
51 | if ('save' === $op) { |
||||||
52 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||||
53 | redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/', 3, _US_NOEDITRIGHT . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||||||
54 | exit(); |
||||||
55 | } |
||||||
56 | $uid = $GLOBALS['xoopsUser']->getVar('uid'); |
||||||
57 | $errors = []; |
||||||
58 | $edituser =& $GLOBALS['xoopsUser']; |
||||||
59 | if ($GLOBALS['xoopsUser']->isAdmin()) { |
||||||
60 | $edituser->setVar('uname', trim($_POST['uname'])); |
||||||
61 | $edituser->setVar('email', trim($_POST['email'])); |
||||||
62 | } |
||||||
63 | xoops_load('XoopsUserUtility'); |
||||||
64 | $stop = XoopsUserUtility::validate($edituser); |
||||||
65 | |||||||
66 | if (!empty($stop)) { |
||||||
67 | $op = 'editprofile'; |
||||||
68 | } else { |
||||||
69 | // Dynamic fields |
||||||
70 | $profile_handler = xoops_getModuleHandler('profile'); |
||||||
71 | // Get fields |
||||||
72 | $fields = $profile_handler->loadFields(); |
||||||
0 ignored issues
–
show
The method
loadFields() does not exist on XoopsObjectHandler . It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
73 | // Get ids of fields that can be edited |
||||||
74 | /* @var XoopsGroupPermHandler $grouppermHandler */ |
||||||
75 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||||
76 | $editable_fields = $grouppermHandler->getItemIds('profile_edit', $GLOBALS['xoopsUser']->getGroups(), $GLOBALS['xoopsModule']->getVar('mid')); |
||||||
77 | |||||||
78 | if (!$profile = $profile_handler->get($edituser->getVar('uid'))) { |
||||||
79 | $profile = $profile_handler->create(); |
||||||
80 | $profile->setVar('profile_id', $edituser->getVar('uid')); |
||||||
81 | } |
||||||
82 | |||||||
83 | foreach (array_keys($fields) as $i) { |
||||||
84 | $fieldname = $fields[$i]->getVar('field_name'); |
||||||
85 | if (in_array($fields[$i]->getVar('field_id'), $editable_fields) && isset($_REQUEST[$fieldname])) { |
||||||
86 | $value = $fields[$i]->getValueForSave($_REQUEST[$fieldname]); |
||||||
87 | if (in_array($fieldname, $profile_handler->getUserVars())) { |
||||||
0 ignored issues
–
show
The method
getUserVars() does not exist on XoopsObjectHandler . It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
88 | $edituser->setVar($fieldname, $value); |
||||||
89 | } else { |
||||||
90 | $profile->setVar($fieldname, $value); |
||||||
91 | } |
||||||
92 | } |
||||||
93 | } |
||||||
94 | if (!$memberHandler->insertUser($edituser)) { |
||||||
95 | $stop = $edituser->getHtmlErrors(); |
||||||
96 | $op = 'editprofile'; |
||||||
97 | } else { |
||||||
98 | $profile->setVar('profile_id', $edituser->getVar('uid')); |
||||||
99 | $profile_handler->insert($profile); |
||||||
100 | unset($_SESSION['xoopsUserTheme']); |
||||||
101 | redirect_header(XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/index.php?uid=' . $edituser->getVar('uid'), 2, _US_PROFUPDATED); |
||||||
102 | } |
||||||
103 | } |
||||||
104 | } |
||||||
105 | |||||||
106 | if ('editprofile' === $op) { |
||||||
107 | require_once $GLOBALS['xoops']->path('header.php'); |
||||||
108 | require_once __DIR__ . '/include/forms.php'; |
||||||
109 | $form = yogurt_getUserForm($GLOBALS['xoopsUser']); |
||||||
110 | $form->assign($GLOBALS['xoopsTpl']); |
||||||
111 | if (!empty($stop)) { |
||||||
112 | $GLOBALS['xoopsTpl']->assign('stop', $stop); |
||||||
113 | } |
||||||
114 | |||||||
115 | $xoBreadcrumbs[] = ['title' => _US_EDITPROFILE]; |
||||||
116 | } |
||||||
117 | |||||||
118 | if ('avatarform' === $op) { |
||||||
119 | $GLOBALS['xoopsOption']['template_main'] = 'yogurt_avatar.tpl'; |
||||||
120 | require $GLOBALS['xoops']->path('header.php'); |
||||||
121 | $xoBreadcrumbs[] = ['title' => _US_MYAVATAR]; |
||||||
122 | |||||||
123 | $oldavatar = $GLOBALS['xoopsUser']->getVar('user_avatar'); |
||||||
124 | |||||||
125 | if (!empty($oldavatar) && 'blank.gif' !== $oldavatar) { |
||||||
126 | $GLOBALS['xoopsTpl']->assign('old_avatar', XOOPS_UPLOAD_URL . '/' . $oldavatar); |
||||||
127 | } |
||||||
128 | |||||||
129 | if (1 == $GLOBALS['xoopsConfigUser']['avatar_allow_upload'] && $GLOBALS['xoopsUser']->getVar('posts') >= $GLOBALS['xoopsConfigUser']['avatar_minposts']) { |
||||||
130 | require_once $GLOBALS['xoops']->path('class/xoopsformloader.php'); |
||||||
131 | $form = new XoopsThemeForm(_US_UPLOADMYAVATAR, 'uploadavatar', XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/edituser.php', 'post', true); |
||||||
132 | $form->setExtra('enctype="multipart/form-data"'); |
||||||
133 | $form->addElement(new XoopsFormLabel(_US_MAXPIXEL, $GLOBALS['xoopsConfigUser']['avatar_width'] . ' x ' . $GLOBALS['xoopsConfigUser']['avatar_height'])); |
||||||
134 | $form->addElement(new XoopsFormLabel(_US_MAXIMGSZ, $GLOBALS['xoopsConfigUser']['avatar_maxsize'])); |
||||||
135 | $form->addElement(new XoopsFormFile(_US_SELFILE, 'avatarfile', $GLOBALS['xoopsConfigUser']['avatar_maxsize']), true); |
||||||
136 | $form->addElement(new XoopsFormHidden('op', 'avatarupload')); |
||||||
137 | $form->addElement(new XoopsFormHidden('uid', $GLOBALS['xoopsUser']->getVar('uid'))); |
||||||
138 | $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||||||
139 | $form->assign($GLOBALS['xoopsTpl']); |
||||||
140 | } |
||||||
141 | $avatar_handler = xoops_getHandler('avatar'); |
||||||
142 | $form2 = new XoopsThemeForm(_US_CHOOSEAVT, 'chooseavatar', XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/edituser.php', 'post', true); |
||||||
143 | $avatar_select = new XoopsFormSelect('', 'user_avatar', $GLOBALS['xoopsUser']->getVar('user_avatar')); |
||||||
144 | $avatar_list = $avatar_handler->getList('S', true); |
||||||
0 ignored issues
–
show
The method
getList() does not exist on XoopsObjectHandler . It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsImageHandler or XoopsRankHandler or XoopsCommentHandler or XoopsTplsetHandler or XoopsAvatarHandler or XoopsBlockHandler or XoopsImagesetHandler or XoopsPersistableObjectHandler or XoopsImagecategoryHandler .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
145 | $avatar_selected = $GLOBALS['xoopsUser']->getVar('user_avatar', 'E'); |
||||||
146 | // $avatar_selected = in_array($avatar_selected, array_keys($avatar_list)) ? $avatar_selected : "blank.gif"; |
||||||
147 | $avatar_selected = array_key_exists($avatar_selected, $avatar_list) ? $avatar_selected : 'blank.gif'; |
||||||
148 | $avatar_select->addOptionArray($avatar_list); |
||||||
149 | $avatar_select->setExtra("onchange='showImgSelected(\"avatar\", \"user_avatar\", \"uploads\", \"\", \"" . XOOPS_URL . "\")'"); |
||||||
150 | $avatar_tray = new XoopsFormElementTray(_US_AVATAR, ' '); |
||||||
151 | $avatar_tray->addElement($avatar_select); |
||||||
152 | $avatar_tray->addElement(new XoopsFormLabel('', "<a href=\"javascript:openWithSelfMain('" . XOOPS_URL . "/misc.php?action=showpopups&type=avatars','avatars',600,400);\">" . _LIST . '</a><br>')); |
||||||
153 | $avatar_tray->addElement(new XoopsFormLabel('', "<br><img src='" . XOOPS_UPLOAD_URL . '/' . $avatar_selected . "' name='avatar' id='avatar' alt='' />")); |
||||||
154 | $form2->addElement($avatar_tray); |
||||||
155 | $form2->addElement(new XoopsFormHidden('uid', $GLOBALS['xoopsUser']->getVar('uid'))); |
||||||
156 | $form2->addElement(new XoopsFormHidden('op', 'avatarchoose')); |
||||||
157 | $form2->addElement(new XoopsFormButton('', 'submit2', _SUBMIT, 'submit')); |
||||||
158 | $form2->assign($GLOBALS['xoopsTpl']); |
||||||
159 | } |
||||||
160 | |||||||
161 | if ('avatarupload' === $op) { |
||||||
162 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||||
163 | redirect_header('index.php', 3, _US_NOEDITRIGHT . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
||||||
164 | } |
||||||
165 | $xoops_upload_file = []; |
||||||
166 | $uid = 0; |
||||||
167 | if (!empty($_POST['xoops_upload_file']) && is_array($_POST['xoops_upload_file'])) { |
||||||
168 | $xoops_upload_file = $_POST['xoops_upload_file']; |
||||||
169 | } |
||||||
170 | if (!empty($_POST['uid'])) { |
||||||
171 | $uid = Request::getInt('uid', 0, 'POST'); |
||||||
172 | } |
||||||
173 | |||||||
174 | if (empty($uid) || $GLOBALS['xoopsUser']->getVar('uid') != $uid) { |
||||||
175 | redirect_header('index.php', 3, _US_NOEDITRIGHT); |
||||||
176 | } |
||||||
177 | $allowed_mimetypes = ['image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png']; |
||||||
178 | if (1 == $GLOBALS['xoopsConfigUser']['avatar_allow_upload'] |
||||||
179 | && $GLOBALS['xoopsUser']->getVar('posts') >= $GLOBALS['xoopsConfigUser']['avatar_minposts']) { |
||||||
180 | require_once $GLOBALS['xoops']->path('class/uploader.php'); |
||||||
181 | $uploader = new XoopsMediaUploader( |
||||||
182 | XOOPS_UPLOAD_PATH . '/avatars', |
||||||
183 | $allowed_mimetypes, |
||||||
184 | $GLOBALS['xoopsConfigUser']['avatar_maxsize'], |
||||||
185 | $GLOBALS['xoopsConfigUser']['avatar_width'], |
||||||
186 | $GLOBALS['xoopsConfigUser']['avatar_height'] |
||||||
187 | ); |
||||||
188 | if ($uploader->fetchMedia($_POST['xoops_upload_file'][0])) { |
||||||
189 | $uploader->setPrefix('cavt'); |
||||||
190 | if ($uploader->upload()) { |
||||||
191 | /* @var XoopsAvatarHandler $avtHandler */ |
||||||
192 | $avtHandler = xoops_getHandler('avatar'); |
||||||
193 | $avatar = $avtHandler->create(); |
||||||
194 | $avatar->setVar('avatar_file', 'avatars / ' . $uploader->getSavedFileName()); |
||||||
195 | $avatar->setVar('avatar_name', $GLOBALS['xoopsUser']->getVar('uname')); |
||||||
196 | $avatar->setVar('avatar_mimetype', $uploader->getMediaType()); |
||||||
197 | $avatar->setVar('avatar_display', 1); |
||||||
198 | $avatar->setVar('avatar_type', 'C'); |
||||||
199 | if (!$avtHandler->insert($avatar)) { |
||||||
200 | @unlink($uploader->getSavedDestination()); |
||||||
0 ignored issues
–
show
It seems like you do not handle an error condition for
unlink() . This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||||||
201 | } else { |
||||||
202 | $oldavatar = $GLOBALS['xoopsUser']->getVar('user_avatar'); |
||||||
203 | if (!empty($oldavatar) && false !== stripos($oldavatar, 'cavt')) { |
||||||
204 | $avatars = $avtHandler->getObjects(new Criteria('avatar_file', $oldavatar)); |
||||||
205 | if (!empty($avatars) && 1 == count($avatars) && is_object($avatars[0])) { |
||||||
206 | $avtHandler->delete($avatars[0]); |
||||||
207 | $oldavatar_path = realpath(XOOPS_UPLOAD_PATH . ' / ' . $oldavatar); |
||||||
208 | if (0 === strpos($oldavatar_path, XOOPS_UPLOAD_PATH) && is_file($oldavatar_path)) { |
||||||
209 | unlink($oldavatar_path); |
||||||
210 | } |
||||||
211 | } |
||||||
212 | } |
||||||
213 | $sql = sprintf('UPDATE % s SET user_avatar = % s WHERE uid = % u', $GLOBALS['xoopsDB']->prefix('users'), $GLOBALS['xoopsDB']->quoteString('avatars / ' . $uploader->getSavedFileName()), $GLOBALS['xoopsUser']->getVar('uid')); |
||||||
214 | $GLOBALS['xoopsDB']->query($sql); |
||||||
215 | $avtHandler->addUser($avatar->getVar('avatar_id'), $GLOBALS['xoopsUser']->getVar('uid')); |
||||||
216 | redirect_header('index . php ? t = ' . time() . ' & amp;uid = ' . $GLOBALS['xoopsUser']->getVar('uid'), 3, _US_PROFUPDATED); |
||||||
217 | } |
||||||
218 | } |
||||||
219 | } |
||||||
220 | redirect_header('edituser . php ? op = avatarform', 3, $uploader->getErrors()); |
||||||
221 | } |
||||||
222 | } |
||||||
223 | |||||||
224 | if ('avatarchoose' === $op) { |
||||||
225 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||||||
226 | redirect_header('index . php', 3, _US_NOEDITRIGHT . ' < br > ' . implode(' < br > ', $GLOBALS['xoopsSecurity']->getErrors())); |
||||||
227 | |||||||
228 | } |
||||||
229 | $uid = 0; |
||||||
230 | if (!empty($_POST['uid'])) { |
||||||
231 | $uid = Request::getInt('uid', 0, 'POST'); |
||||||
232 | } |
||||||
233 | if (empty($uid) || $GLOBALS['xoopsUser']->getVar('uid') != $uid) { |
||||||
234 | redirect_header('index . php', 3, _US_NOEDITRIGHT); |
||||||
235 | } |
||||||
236 | $user_avatar = ''; |
||||||
237 | $avtHandler = xoops_getHandler('avatar'); |
||||||
238 | if (!empty($_POST['user_avatar'])) { |
||||||
239 | $user_avatar = Request::getString('user_avatar', '', 'POST'); |
||||||
240 | $criteria_avatar = new CriteriaCompo(new Criteria('avatar_file', $user_avatar)); |
||||||
241 | $criteria_avatar->add(new Criteria('avatar_type', 'S')); |
||||||
242 | $avatars = $avtHandler->getObjects($criteria_avatar); |
||||||
0 ignored issues
–
show
The method
getObjects() does not exist on XoopsObjectHandler . It seems like you code against a sub-type of said class. However, the method does not exist in XoopsRankHandler or XoUserHandler . Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
243 | if (!is_array($avatars) || !count($avatars)) { |
||||||
244 | $user_avatar = 'avatars / blank . gif'; |
||||||
245 | } |
||||||
246 | unset($avatars, $criteria_avatar); |
||||||
247 | } |
||||||
248 | $user_avatarpath = realpath(XOOPS_UPLOAD_PATH . ' / ' . $user_avatar); |
||||||
249 | |||||||
250 | if (0 === mb_strpos($user_avatarpath, realpath(XOOPS_UPLOAD_PATH)) && is_file($user_avatarpath)) { |
||||||
251 | $oldavatar = $GLOBALS['xoopsUser']->getVar('user_avatar'); |
||||||
252 | $GLOBALS['xoopsUser']->setVar('user_avatar', $user_avatar); |
||||||
253 | /* @var XoopsMemberHandler $memberHandler */ |
||||||
254 | $memberHandler = xoops_getHandler('member'); |
||||||
255 | if (!$memberHandler->insertUser($GLOBALS['xoopsUser'])) { |
||||||
256 | require $GLOBALS['xoops']->path('header . php'); |
||||||
257 | echo $GLOBALS['xoopsUser']->getHtmlErrors(); |
||||||
258 | require $GLOBALS['xoops']->path('footer.php'); |
||||||
259 | |||||||
260 | exit(); |
||||||
261 | } |
||||||
262 | // if ($oldavatar && preg_match("/^cavt/", strtolower(substr($oldavatar, 8)))) { |
||||||
263 | |||||||
264 | if ($oldavatar && 0 === mb_stripos(mb_substr($oldavatar, 8), 'cavt')) { |
||||||
265 | $avatars = $avtHandler->getObjects(new Criteria('avatar_file', $oldavatar)); |
||||||
266 | |||||||
267 | if (!empty($avatars) && 1 == count($avatars) && is_object($avatars[0])) { |
||||||
268 | $avtHandler->delete($avatars[0]); |
||||||
269 | $oldavatar_path = realpath(XOOPS_UPLOAD_PATH . ' / ' . $oldavatar); |
||||||
270 | |||||||
271 | if (0 === mb_strpos($oldavatar_path, realpath(XOOPS_UPLOAD_PATH)) && is_file($oldavatar_path)) { |
||||||
272 | unlink($oldavatar_path); |
||||||
273 | } |
||||||
274 | } |
||||||
275 | } |
||||||
276 | |||||||
277 | if ('avatars/blank.gif' !== $user_avatar) { |
||||||
278 | $avatars = $avtHandler->getObjects(new Criteria('avatar_file', $user_avatar)); |
||||||
279 | if (is_object($avatars[0])) { |
||||||
280 | $avtHandler->addUser($avatars[0]->getVar('avatar_id'), $GLOBALS['xoopsUser']->getVar('uid')); |
||||||
0 ignored issues
–
show
The method
addUser() does not exist on XoopsObjectHandler . It seems like you code against a sub-type of XoopsObjectHandler such as XoopsAvatarHandler or XoopsPersistableObjectHandler .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
281 | } |
||||||
282 | } |
||||||
283 | } |
||||||
284 | redirect_header('index . php ? uid = ' . $uid, 0, _US_PROFUPDATED); |
||||||
285 | } |
||||||
286 | |||||||
287 | |||||||
288 | require __DIR__ . ' / footer . php'; |
||||||
289 | require dirname(__DIR__, 2) . ' / footer . php'; |
||||||
290 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.