Conditions | 14 |
Paths | 72 |
Total Lines | 153 |
Code Lines | 117 |
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 |
||
129 | function show() |
||
130 | { |
||
131 | global $msgHandler, $xoopsModule, $pathIcon16; |
||
132 | $pick = Request::getInt('pick', 0, 'GET'); |
||
133 | $start = Request::getInt('start', 0, 'GET'); |
||
134 | $sel_status = Request::getInt('sel_status', 0, 'GET'); |
||
135 | $sel_order = Request::getInt('sel_order', 0, 'GET'); |
||
136 | $limit = 10; |
||
137 | $status_option0 = ''; |
||
138 | $status_option1 = ''; |
||
139 | $status_option2 = ''; |
||
140 | $order_option_asc = ''; |
||
141 | $order_option_desc = ''; |
||
142 | |||
143 | switch ($sel_status) { |
||
144 | case 0: |
||
145 | $status_option0 = 'selected'; |
||
146 | $title = AM_XFGUESTBOOK_ALLMSG; |
||
147 | $criteria = new \Criteria('msg_id', 0, '>'); |
||
148 | $criteria->setSort('post_time'); |
||
149 | break; |
||
150 | case 1: |
||
151 | $status_option1 = 'selected'; |
||
152 | $title = AM_XFGUESTBOOK_PUBMSG; |
||
153 | $criteria = new \Criteria('moderate', '0'); |
||
154 | $criteria->setSort('post_time'); |
||
155 | break; |
||
156 | case 2: |
||
157 | $status_option2 = 'selected'; |
||
158 | $title = AM_XFGUESTBOOK_WAITMSG; |
||
159 | $criteria = new \Criteria('moderate', '1'); |
||
160 | $criteria->setSort('post_time'); |
||
161 | break; |
||
162 | } |
||
163 | |||
164 | switch ($sel_order) { |
||
165 | case 1: |
||
166 | $order_option_asc = 'selected'; |
||
167 | $criteria->setOrder('ASC'); |
||
168 | break; |
||
169 | case 0: |
||
170 | $order_option_desc = 'selected'; |
||
171 | $criteria->setOrder('DESC'); |
||
172 | break; |
||
173 | } |
||
174 | |||
175 | $totalcount = $msgHandler->countMsg($criteria); |
||
176 | $criteria->setOrder('DESC'); |
||
177 | $criteria->setLimit($limit); |
||
178 | $criteria->setStart($start); |
||
179 | $msg = $msgHandler->getObjects($criteria); |
||
180 | |||
181 | $badips = Xfguestbook\Utility::get_badips(); |
||
182 | |||
183 | /* -- Code to show selected terms -- */ |
||
184 | echo "<form name='pick' id='pick' action='" . $_SERVER['SCRIPT_NAME'] . '\' method=\'GET\' style=\'margin: 0;\'>'; |
||
185 | |||
186 | echo " |
||
187 | <table width='100%' cellspacing='1' cellpadding='2' border='0' style='border-left: 1px solid #c0c0c0; border-top: 1px solid #c0c0c0; border-right: 1px solid #c0c0c0;'> |
||
188 | <tr> |
||
189 | <td><span style='font-weight: bold; font-size: 12px; font-variant: small-caps;'>" . $title . ' : ' . $totalcount . "</span></td> |
||
190 | <td align='right'> |
||
191 | " . AM_XFGUESTBOOK_DISPLAY . " : |
||
192 | <select name='sel_status' onchange='submit()'> |
||
193 | <option value = '0' $status_option0>" . AM_XFGUESTBOOK_ALLMSG . " </option> |
||
194 | <option value = '1' $status_option1>" . AM_XFGUESTBOOK_PUBMSG . " </option> |
||
195 | <option value = '2' $status_option2>" . AM_XFGUESTBOOK_WAITMSG . ' </option> |
||
196 | </select> |
||
197 | ' . AM_XFGUESTBOOK_SELECT_SORT . " |
||
198 | <select name='sel_order' onchange='submit()'> |
||
199 | <option value = '1' $order_option_asc>" . AM_XFGUESTBOOK_SORT_ASC . "</option> |
||
200 | <option value = '0' $order_option_desc>" . AM_XFGUESTBOOK_SORT_DESC . '</option> |
||
201 | </select> |
||
202 | </td> |
||
203 | </tr> |
||
204 | </table> |
||
205 | </form>'; |
||
206 | /* -- end code to show selected terms -- */ |
||
207 | |||
208 | echo "<table border='1' width='100%' cellpadding ='2' cellspacing='1'>"; |
||
209 | echo "<tr class='bg3'>"; |
||
210 | echo "<td align='center'></td>"; |
||
211 | echo "<td align='center'><b><input type='hidden' name='op' value='delete'></td>"; |
||
212 | echo "<td align='center'><b>" . AM_XFGUESTBOOK_NAME . '</td>'; |
||
213 | echo "<td align='center'><b>" . AM_XFGUESTBOOK_TITLE . '</td>'; |
||
214 | echo "<td align='center'><b>" . AM_XFGUESTBOOK_MESSAGE . '</td>'; |
||
215 | echo "<td align='center'><b>" . AM_XFGUESTBOOK_DATE . '</td>'; |
||
216 | echo "<td align='center'><b>" . AM_XFGUESTBOOK_ACTION . '</td>'; |
||
217 | echo '</tr>'; |
||
218 | |||
219 | if ('0' != $totalcount) { |
||
220 | echo "<form name='msglist' id='list' action='" . $_SERVER['SCRIPT_NAME'] . '\' method=\'POST\' style=\'margin: 0;\'>'; |
||
221 | |||
222 | /** @var \XoopsModules\Xfguestbook\Message $onemsg */ |
||
223 | foreach ($msg as $onemsg) { |
||
224 | $all_msg = []; |
||
225 | $all_msg['post_time'] = formatTimestamp($onemsg->getVar('post_time')); |
||
226 | $all_msg['msg_id'] = $onemsg->getVar('msg_id'); |
||
227 | $all_msg['user'] = ($onemsg->getVar('user_id') > 0) ? \XoopsUser::getUnameFromId($onemsg->getVar('user_id')) : $onemsg->getVar('uname'); |
||
228 | $all_msg['action'] = "<a href='main.php?op=edit&msg_id=" . $onemsg->getVar('msg_id') . '\'><img src=\'' . $pathIcon16 . "/edit.png'></a>"; |
||
229 | $img_status = "<img src='" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/assets/images/'; |
||
230 | if ($onemsg->getVar('moderate')) { |
||
231 | $img_status .= "ic15_question.gif'>"; |
||
232 | } else { |
||
233 | $img_status .= "ic15_ok.gif'>"; |
||
234 | } |
||
235 | $all_msg['title'] = "<a href='../index.php?op=show_one&msg_id=" . $onemsg->getVar('msg_id') . '\'>' . $onemsg->getVar('title') . '</a>'; |
||
236 | $all_msg['message'] = $onemsg->getVar('message'); |
||
237 | |||
238 | if ($onemsg->getVar('photo')) { |
||
239 | $all_msg['message'] = '<img src="' . XOOPS_UPLOAD_URL . '/' . $xoopsModule->getVar('dirname') . '/' . $onemsg->getVar('photo') . '" align = "left" hspace ="10">' . $onemsg->getVar('message'); |
||
240 | } else { |
||
241 | $all_msg['message'] = $onemsg->getVar('message'); |
||
242 | } |
||
243 | |||
244 | echo '<tr>'; |
||
245 | echo "<td align='center' class='even'><input type='checkbox' name='msg_id[]' id='msg_id[]' value='" . $all_msg['msg_id'] . '\'></td>'; |
||
246 | echo "<td align='center' class = 'head'><b>" . $img_status . '</b></td>'; |
||
247 | echo "<td align='center' class = 'even'>" . $all_msg['user'] . '</td>'; |
||
248 | echo "<td align='left' class = 'odd'>" . $all_msg['title'] . '</td>'; |
||
249 | echo "<td align='left' class = 'even'>" . $all_msg['message'] . '</td>'; |
||
250 | echo "<td class='odd'>" . $all_msg['post_time'] . '<br>'; |
||
251 | if (in_array($onemsg->getVar('poster_ip'), $badips)) { |
||
252 | echo "<span style='color: #FF0000; '><b>" . $onemsg->getVar('poster_ip') . '</b></span></td>'; |
||
253 | } else { |
||
254 | echo $onemsg->getVar('poster_ip') . '</td>'; |
||
255 | } |
||
256 | echo "<td align='center' class='even'>" . $all_msg['action'] . '</td>'; |
||
257 | echo '</tr>'; |
||
258 | unset($all_msg); |
||
259 | } |
||
260 | echo "<tr class='foot'><td><select name='op'>"; |
||
261 | if (1 != $sel_status) { |
||
262 | echo "<option value='approve'>" . AM_XFGUESTBOOK_PUB . '</option>'; |
||
263 | } |
||
264 | echo "<option value='delete'>" . _DELETE . '</option>'; |
||
265 | echo "<option value='banish'>" . AM_XFGUESTBOOK_BAN . '</option>'; |
||
266 | echo '</select> </td>'; |
||
267 | echo "<td colspan='6'>" . $GLOBALS['xoopsSecurity']->getTokenHTML() . "<input type='submit' value='" . _GO . '\'>'; |
||
268 | echo '</td></tr>'; |
||
269 | echo '</form>'; |
||
270 | } else { |
||
271 | echo "<tr ><td align='center' colspan ='10' class = 'head'><b>" . AM_XFGUESTBOOK_NOMSG . '</b></td></tr>'; |
||
272 | } |
||
273 | echo '</table><br>'; |
||
274 | if ($totalcount > $limit) { |
||
275 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
276 | $pagenav = new \XoopsPageNav($totalcount, $limit, $start, 'start', 'sel_status=' . $sel_status . '&sel_order=' . $sel_order); |
||
277 | echo "<div class='center;' class = 'head'>" . $pagenav->renderNav() . '</div><br>'; |
||
278 | } else { |
||
279 | echo ''; |
||
280 | } |
||
281 | echo '<br>'; |
||
282 | } |
||
372 |