Conditions | 13 |
Paths | 648 |
Total Lines | 133 |
Code Lines | 89 |
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 declare(strict_types=1); |
||
146 | function manageFiles() |
||
147 | { |
||
148 | global $aSortBy, $aOrderBy, $aLimitBy, $order, $limit, $start, $sort; |
||
149 | $xhelpUploadDir = XHELP_UPLOAD_PATH; |
||
150 | $dir_status = xhelp_admin_getPathStatus($xhelpUploadDir, true); |
||
151 | $helper = Xhelp\Helper::getInstance(); |
||
152 | |||
153 | if (-1 == $dir_status) { |
||
154 | $can_upload = xhelp_admin_mkdir($xhelpUploadDir); |
||
155 | } |
||
156 | |||
157 | /** @var \XoopsModules\Xhelp\FileHandler $fileHandler */ |
||
158 | $fileHandler = $helper->getHandler('File'); |
||
159 | |||
160 | if (Request::hasVar('deleteFiles', 'POST')) { // Delete all selected files |
||
161 | $aFiles = $_POST['files']; |
||
162 | $criteria = new \Criteria('id', '(' . implode(',', $aFiles) . ')', 'IN'); |
||
163 | |||
164 | if ($fileHandler->deleteAll($criteria)) { |
||
165 | $helper->redirect('admin/file.php?op=manageFiles'); |
||
166 | } |
||
167 | $helper->redirect('admin/file.php?op=manageFiles', 3, _XHELP_MESSAGE_DELETE_FILE_ERR); |
||
168 | } |
||
169 | xoops_cp_header(); |
||
170 | //echo $oAdminButton->renderButtons('manFiles'); |
||
171 | $adminObject = Admin::getInstance(); |
||
172 | $adminObject->displayNavigation('file.php?op=manageFiles'); |
||
173 | |||
174 | echo '<script type="text/javascript" src="' . XOOPS_URL . '/modules/xhelp/include/functions.js"></script>'; |
||
175 | echo "<form method='post' action='" . XHELP_ADMIN_URL . "/file.php?op=manageFiles'>"; |
||
176 | |||
177 | echo "<table width='100%' cellspacing='1' class='outer'> |
||
178 | <tr><th colspan='2'><label>" . _AM_XHELP_TEXT_TOTAL_USED_SPACE . '</label></th></tr>'; |
||
179 | |||
180 | echo "<tr><td class='head' width='20%'>" . _AM_XHELP_TEXT_ALL_ATTACH . "</td> |
||
181 | <td class='even'>" . xhelpDirsize($xhelpUploadDir) . ' |
||
182 | </td> |
||
183 | </tr>'; |
||
184 | |||
185 | $resolvedSize = xhelpDirsize($xhelpUploadDir, true); |
||
186 | echo "<tr><td class='head'>" . _AM_XHELP_TEXT_RESOLVED_ATTACH . "</td> |
||
187 | <td class='even'>"; |
||
188 | if ($resolvedSize > 0) { |
||
189 | echo $resolvedSize . ' <b>(' . _AM_XHELP_TEXT_DELETE_RESOLVED . " |
||
190 | <a href='" . XHELP_ADMIN_URL . "/file.php?op=deleteResolved'><img src='" . XHELP_IMAGE_URL . "/button_delete.png' title='" . _AM_XHELP_TEXT_DELETE . "' name='deleteFile'></a>)</b>"; |
||
191 | } else { |
||
192 | echo $resolvedSize; |
||
193 | } |
||
194 | echo '</td> |
||
195 | </tr>'; |
||
196 | echo '</table></form>'; |
||
197 | |||
198 | $criteria = new \Criteria('', ''); |
||
199 | $criteria->setOrder($order); |
||
200 | $criteria->setSort($sort); |
||
201 | $criteria->setLimit($limit); |
||
202 | $criteria->setStart($start); |
||
203 | $files = $fileHandler->getObjects($criteria); |
||
204 | $total = $fileHandler->getCount($criteria); |
||
205 | |||
206 | $nav = new \XoopsPageNav($total, $limit, $start, 'start', "op=manageFiles&limit=$limit"); |
||
207 | |||
208 | echo "<form action='" . XHELP_ADMIN_URL . "/file.php?op=manageFiles' style='margin:0; padding:0;' method='post'>"; |
||
209 | echo $GLOBALS['xoopsSecurity']->getTokenHTML(); |
||
210 | echo "<table width='100%' cellspacing='1' class='outer'>"; |
||
211 | echo "<tr><td align='right'>" . _AM_XHELP_TEXT_SORT_BY . " |
||
212 | <select name='sort'>"; |
||
213 | foreach ($aSortBy as $value => $text) { |
||
214 | ($sort == $value) ? $selected = 'selected' : $selected = ''; |
||
215 | echo "<option value='$value' $selected>$text</option>"; |
||
216 | } |
||
217 | echo '</select> |
||
218 | |
||
219 | ' . _AM_XHELP_TEXT_ORDER_BY . " |
||
220 | <select name='order'>"; |
||
221 | foreach ($aOrderBy as $value => $text) { |
||
222 | ($order == $value) ? $selected = 'selected' : $selected = ''; |
||
223 | echo "<option value='$value' $selected>$text</option>"; |
||
224 | } |
||
225 | echo '</select> |
||
226 | |
||
227 | ' . _AM_XHELP_TEXT_NUMBER_PER_PAGE . " |
||
228 | <select name='limit'>"; |
||
229 | foreach ($aLimitBy as $value => $text) { |
||
230 | ($limit == $value) ? $selected = 'selected' : $selected = ''; |
||
231 | echo "<option value='$value' $selected>$text</option>"; |
||
232 | } |
||
233 | echo "</select> |
||
234 | <input type='submit' name='file_sort' id='file_sort' value='" . _AM_XHELP_BUTTON_SUBMIT . "'> |
||
235 | </td> |
||
236 | </tr>"; |
||
237 | echo '</table></form>'; |
||
238 | |||
239 | echo "<form method='post' action='" . XHELP_ADMIN_URL . "/file.php?op=manageFiles'>"; |
||
240 | echo "<table width='100%' cellspacing='1' class='outer'> |
||
241 | <tr><th colspan='6'><label>" . _AM_XHELP_TEXT_MANAGE_FILES . '</label></th></tr>'; |
||
242 | if (0 != $total) { |
||
243 | echo "<tr class='head'> |
||
244 | <td>" . _AM_XHELP_TEXT_ID . '</td> |
||
245 | <td>' . _AM_XHELP_TEXT_TICKETID . '</td> |
||
246 | <td>' . _AM_XHELP_TEXT_FILENAME . '</td> |
||
247 | <td>' . _AM_XHELP_TEXT_SIZE . '</td> |
||
248 | <td>' . _AM_XHELP_TEXT_MIMETYPE . '</td> |
||
249 | <td>' . _AM_XHELP_TEXT_ACTIONS . '</td> |
||
250 | </tr>'; |
||
251 | |||
252 | foreach ($files as $file) { |
||
253 | $filepath = XHELP_BASE_URL . '/viewFile.php?id=' . $file->getVar('id'); |
||
254 | $ticketpath = XHELP_BASE_URL . '/ticket.php?id=' . $file->getVar('ticketid'); |
||
255 | $filesize = filesize($xhelpUploadDir . '/' . $file->getVar('filename')); |
||
256 | |||
257 | echo "<tr class='even'> |
||
258 | <td><input type='checkbox' name='files[]' value='" . $file->getVar('id') . "'> " . $file->getVar('id') . "</td> |
||
259 | <td><a href='" . $ticketpath . "' target='_BLANK'>" . $file->getVar('ticketid') . "</a></td> |
||
260 | <td><a href='" . $filepath . "'>" . $file->getVar('filename') . '</a></td> |
||
261 | <td>' . Xhelp\Utility::prettyBytes($filesize) . '</td> |
||
262 | <td>' . $file->getVar('mimetype') . "</td> |
||
263 | <td> |
||
264 | <a href='" . XHELP_ADMIN_URL . '/file.php?op=deleteFile&fileid=' . $file->getVar('id') . "'><img src='" . XOOPS_URL . "/modules/xhelp/assets/images/button_delete.png' title='" . _AM_XHELP_TEXT_DELETE . "' name='deleteFile'></a> |
||
265 | </td> |
||
266 | </tr>"; |
||
267 | } |
||
268 | echo "<tr class='foot'><td colspan='6'> |
||
269 | <input type='checkbox' name='checkAllFiles' value='0' onclick='selectAll(this.form,\"files[]\",this.checked);'> |
||
270 | <input type='submit' name='deleteFiles' id='deleteFiles' value='" . _AM_XHELP_BUTTON_DELETE . "'></td></tr>"; |
||
271 | echo '</table></form>'; |
||
272 | echo "<div id='status_nav'>" . $nav->renderNav() . '</div>'; |
||
273 | } else { |
||
274 | echo "<tr class='even'<td colspan='6'>" . _AM_XHELP_TEXT_NO_FILES . '</td></tr>'; |
||
275 | echo '</table></form>'; |
||
276 | } |
||
277 | |||
278 | require_once __DIR__ . '/admin_footer.php'; |
||
279 | } |
||
280 |