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