Conditions | 12 |
Paths | 224 |
Total Lines | 171 |
Code Lines | 139 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
42 | function form_user($add_or_edit, $user = '') |
||
43 | { |
||
44 | global $xoopsConfig, $xoopsUser; |
||
45 | $uid = Request::getInt('uid', 0); |
||
46 | |||
47 | //RMV-NOTIFY |
||
48 | include_once XOOPS_ROOT_PATH . '/language/' . $xoopsConfig['language'] . '/notification.php'; |
||
49 | include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
||
50 | |||
51 | if ($add_or_edit === true) { |
||
52 | /** @var XoopsConfigHandler $config_handler */ |
||
53 | $config_handler = xoops_getHandler('config'); |
||
54 | $xoopsConfigUser = $config_handler->getConfigsByCat(XOOPS_CONF_USER); |
||
55 | //Add user |
||
56 | $uid_value = ''; |
||
57 | $uname_value = ''; |
||
58 | $name_value = ''; |
||
59 | $email_value = ''; |
||
60 | $email_cbox_value = 0; |
||
61 | $url_value = ''; |
||
62 | $timezone_value = $xoopsConfig['default_TZ']; |
||
63 | $icq_value = ''; |
||
64 | $aim_value = ''; |
||
65 | $yim_value = ''; |
||
66 | $msnm_value = ''; |
||
67 | $location_value = ''; |
||
68 | $occ_value = ''; |
||
69 | $interest_value = ''; |
||
70 | $sig_value = ''; |
||
71 | $sig_cbox_value = 0; |
||
72 | $umode_value = $xoopsConfig['com_mode']; |
||
73 | $uorder_value = $xoopsConfig['com_order']; |
||
74 | // RMV-NOTIFY |
||
75 | $notify_method_value = (isset($xoopsConfigUser['default_notification']) ? $xoopsConfigUser['default_notification'] : XOOPS_NOTIFICATION_METHOD_PM); |
||
76 | $notify_mode_value = XOOPS_NOTIFICATION_MODE_SENDALWAYS; |
||
77 | $bio_value = ''; |
||
78 | $rank_value = 0; |
||
79 | $mailok_value = 0; |
||
80 | $form_title = _AM_SYSTEM_USERS_ADDUSER; |
||
81 | $form_isedit = false; |
||
82 | $groups = array(XOOPS_GROUP_USERS); |
||
83 | } else { |
||
84 | //Edit user |
||
85 | /** @var XoopsMemberHandler $member_handler */ |
||
86 | $member_handler = xoops_getHandler('member'); |
||
87 | $user = $member_handler->getUser($uid); |
||
88 | if (is_object($user)) { |
||
89 | $uid_value = $uid; |
||
90 | $uname_value = $user->getVar('uname', 'E'); |
||
91 | $name_value = $user->getVar('name', 'E'); |
||
92 | $email_value = $user->getVar('email', 'E'); |
||
93 | $email_cbox_value = $user->getVar('user_viewemail') ? 1 : 0; |
||
94 | $url_value = $user->getVar('url', 'E'); |
||
95 | $temp = $user->getVar('theme'); |
||
96 | $timezone_value = $user->getVar('timezone_offset'); |
||
97 | $icq_value = $user->getVar('user_icq', 'E'); |
||
98 | $aim_value = $user->getVar('user_aim', 'E'); |
||
99 | $yim_value = $user->getVar('user_yim', 'E'); |
||
100 | $msnm_value = $user->getVar('user_msnm', 'E'); |
||
101 | $location_value = $user->getVar('user_from', 'E'); |
||
102 | $occ_value = $user->getVar('user_occ', 'E'); |
||
103 | $interest_value = $user->getVar('user_intrest', 'E'); |
||
104 | $sig_value = $user->getVar('user_sig', 'E'); |
||
105 | $sig_cbox_value = ($user->getVar('attachsig') == 1) ? 1 : 0; |
||
106 | $umode_value = $user->getVar('umode'); |
||
107 | $uorder_value = $user->getVar('uorder'); |
||
108 | // RMV-NOTIFY |
||
109 | $notify_method_value = $user->getVar('notify_method'); |
||
110 | $notify_mode_value = $user->getVar('notify_mode'); |
||
111 | $bio_value = $user->getVar('bio', 'E'); |
||
112 | $rank_value = $user->rank(false); |
||
113 | $mailok_value = $user->getVar('user_mailok', 'E'); |
||
114 | $form_title = _AM_SYSTEM_USERS_UPDATEUSER . ': ' . $user->getVar('uname'); |
||
115 | $form_isedit = true; |
||
116 | $groups = array_values($user->getGroups()); |
||
117 | } |
||
118 | } |
||
119 | |||
120 | //Affichage du formulaire |
||
121 | $form = new XoopsThemeForm($form_title, 'form_user', 'admin.php', 'post', true); |
||
122 | |||
123 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_NICKNAME, 'username', 25, 25, $uname_value), true); |
||
124 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_NAME, 'name', 30, 60, $name_value)); |
||
125 | $email_tray = new XoopsFormElementTray(_AM_SYSTEM_USERS_EMAIL, '<br>'); |
||
126 | $email_text = new XoopsFormText('', 'email', 30, 60, $email_value); |
||
127 | $email_tray->addElement($email_text, true); |
||
128 | $email_cbox = new XoopsFormCheckBox('', 'user_viewemail', $email_cbox_value); |
||
129 | $email_cbox->addOption(1, _AM_SYSTEM_USERS_AOUTVTEAD); |
||
130 | $email_tray->addElement($email_cbox); |
||
131 | $form->addElement($email_tray, true); |
||
132 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_URL, 'url', 30, 100, $url_value)); |
||
133 | $form->addElement(new XoopsFormSelectTimezone(_AM_SYSTEM_USERS_TIMEZONE, 'timezone_offset', $timezone_value)); |
||
134 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_ICQ, 'user_icq', 15, 15, $icq_value)); |
||
135 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_AIM, 'user_aim', 18, 18, $aim_value)); |
||
136 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_YIM, 'user_yim', 25, 25, $yim_value)); |
||
137 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_MSNM, 'user_msnm', 30, 100, $msnm_value)); |
||
138 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_LOCATION, 'user_from', 30, 100, $location_value)); |
||
139 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_OCCUPATION, 'user_occ', 30, 100, $occ_value)); |
||
140 | $form->addElement(new XoopsFormText(_AM_SYSTEM_USERS_INTEREST, 'user_intrest', 30, 150, $interest_value)); |
||
141 | $sig_tray = new XoopsFormElementTray(_AM_SYSTEM_USERS_SIGNATURE, '<br>'); |
||
142 | $sig_tarea = new XoopsFormTextArea('', 'user_sig', $sig_value); |
||
143 | $sig_tray->addElement($sig_tarea); |
||
144 | $sig_cbox = new XoopsFormCheckBox('', 'attachsig', $sig_cbox_value); |
||
145 | $sig_cbox->addOption(1, _AM_SYSTEM_USERS_SHOWSIG); |
||
146 | $sig_tray->addElement($sig_cbox); |
||
147 | $form->addElement($sig_tray); |
||
148 | $umode_select = new XoopsFormSelect(_AM_SYSTEM_USERS_CDISPLAYMODE, 'umode', $umode_value); |
||
149 | $umode_select->addOptionArray(array('nest' => _NESTED, 'flat' => _FLAT, 'thread' => _THREADED)); |
||
150 | $form->addElement($umode_select); |
||
151 | $uorder_select = new XoopsFormSelect(_AM_SYSTEM_USERS_CSORTORDER, 'uorder', $uorder_value); |
||
152 | $uorder_select->addOptionArray(array('0' => _OLDESTFIRST, '1' => _NEWESTFIRST)); |
||
153 | $form->addElement($uorder_select); |
||
154 | // RMV-NOTIFY |
||
155 | $notify_method_select = new XoopsFormSelect(_NOT_NOTIFYMETHOD, 'notify_method', $notify_method_value); |
||
156 | $notify_method_select->addOptionArray(array( |
||
157 | XOOPS_NOTIFICATION_METHOD_DISABLE => _NOT_METHOD_DISABLE, |
||
158 | XOOPS_NOTIFICATION_METHOD_PM => _NOT_METHOD_PM, |
||
159 | XOOPS_NOTIFICATION_METHOD_EMAIL => _NOT_METHOD_EMAIL)); |
||
160 | $form->addElement($notify_method_select); |
||
161 | $notify_mode_select = new XoopsFormSelect(_NOT_NOTIFYMODE, 'notify_mode', $notify_mode_value); |
||
162 | $notify_mode_select->addOptionArray(array( |
||
163 | XOOPS_NOTIFICATION_MODE_SENDALWAYS => _NOT_MODE_SENDALWAYS, |
||
164 | XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE => _NOT_MODE_SENDONCE, |
||
165 | XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT => _NOT_MODE_SENDONCEPERLOGIN)); |
||
166 | $form->addElement($notify_mode_select); |
||
167 | $form->addElement(new XoopsFormTextArea(_AM_SYSTEM_USERS_EXTRAINFO, 'bio', $bio_value)); |
||
168 | $rank_select = new XoopsFormSelect(_AM_SYSTEM_USERS_RANK, 'rank', $rank_value); |
||
169 | $ranklist = XoopsLists::getUserRankList(); |
||
170 | if (count($ranklist) > 0) { |
||
171 | $rank_select->addOption(0, '--------------'); |
||
172 | $rank_select->addOptionArray($ranklist); |
||
173 | } else { |
||
174 | $rank_select->addOption(0, _AM_SYSTEM_USERS_NSRID); |
||
175 | } |
||
176 | $form->addElement($rank_select); |
||
177 | // adding a new user requires password fields |
||
178 | if (!$form_isedit) { |
||
179 | $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_PASSWORD, 'password', 10, 32), true); |
||
180 | $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_RETYPEPD, 'pass2', 10, 32), true); |
||
181 | } else { |
||
182 | $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_PASSWORD, 'password', 10, 32)); |
||
183 | $form->addElement(new XoopsFormPassword(_AM_SYSTEM_USERS_RETYPEPD, 'pass2', 10, 32)); |
||
184 | } |
||
185 | $form->addElement(new XoopsFormRadioYN(_AM_SYSTEM_USERS_ACCEPT_EMAIL, 'user_mailok', $mailok_value)); |
||
186 | |||
187 | //Groups administration addition XOOPS 2.0.9: Mith |
||
188 | /** @var XoopsGroupPermHandler $gperm_handler */ |
||
189 | $gperm_handler = xoops_getHandler('groupperm'); |
||
190 | //If user has admin rights on groups |
||
191 | if ($gperm_handler->checkRight('system_admin', XOOPS_SYSTEM_GROUP, $xoopsUser->getGroups(), 1)) { |
||
192 | //add group selection |
||
193 | $group_select[] = new XoopsFormSelectGroup(_AM_SYSTEM_USERS_GROUPS, 'groups', false, $groups, 5, true); |
||
194 | } else { |
||
195 | //add each user groups |
||
196 | foreach ($groups as $key => $group) { |
||
197 | $group_select[] = new XoopsFormHidden('groups[' . $key . ']', $group); |
||
198 | } |
||
199 | } |
||
200 | foreach ($group_select as $group) { |
||
201 | $form->addElement($group); |
||
202 | unset($group); |
||
203 | } |
||
204 | |||
205 | $form->addElement(new XoopsFormHidden('fct', 'users')); |
||
206 | $form->addElement(new XoopsFormHidden('op', 'users_save')); |
||
207 | $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit')); |
||
208 | |||
209 | if (!empty($uid_value)) { |
||
210 | $form->addElement(new XoopsFormHidden('uid', $uid_value)); |
||
211 | } |
||
212 | $form->display(); |
||
213 | } |
||
283 |