| Conditions | 63 |
| Paths | 6912 |
| Total Lines | 390 |
| Code Lines | 147 |
| 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 |
||
| 19 | function template_view_package() |
||
| 20 | { |
||
| 21 | global $context, $settings, $txt, $scripturl; |
||
| 22 | |||
| 23 | echo ' |
||
| 24 | <div id="admincenter"> |
||
| 25 | <h2 class="category_header">', $txt[($context['uninstalling'] ? 'un' : '') . 'install_mod'], '</h2> |
||
| 26 | <div class="information">'; |
||
| 27 | |||
| 28 | if ($context['is_installed']) |
||
| 29 | { |
||
| 30 | echo ' |
||
| 31 | <strong>', $txt['package_installed_warning1'], '</strong><br /> |
||
| 32 | <br /> |
||
| 33 | ', $txt['package_installed_warning2'], '<br /> |
||
| 34 | <br />'; |
||
| 35 | } |
||
| 36 | |||
| 37 | echo $txt['package_installed_warning3'], ' |
||
| 38 | </div>'; |
||
| 39 | |||
| 40 | // Do errors exist in the install? If so light them up like a Christmas tree. |
||
| 41 | if ($context['has_failure']) |
||
| 42 | { |
||
| 43 | echo ' |
||
| 44 | <div class="errorbox"> |
||
| 45 | ', sprintf($txt['package_will_fail_title'], $txt['package_' . ($context['uninstalling'] ? 'uninstall' : 'install')]), '<br /> |
||
| 46 | ', sprintf($txt['package_will_fail_warning'], $txt['package_' . ($context['uninstalling'] ? 'uninstall' : 'install')]), |
||
| 47 | empty($context['failure_details']) ? '' : '<br /><br /><strong>' . $context['failure_details'] . '</strong>', ' |
||
| 48 | </div>'; |
||
| 49 | } |
||
| 50 | |||
| 51 | // Display the package readme if one exists |
||
| 52 | if (isset($context['package_readme'])) |
||
| 53 | { |
||
| 54 | echo ' |
||
| 55 | <h2 class="category_header">', $txt['package_' . ($context['uninstalling'] ? 'un' : '') . 'install_readme'], '</h2> |
||
| 56 | <div class="content"> |
||
| 57 | ', $context['package_readme'], ' |
||
| 58 | <span class="floatright">', $txt['package_available_readme_language'], ' |
||
| 59 | <select name="readme_language" id="readme_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = elk_prepareScriptUrl(elk_scripturl + \'', '?action=admin;area=packages;sa=', $context['uninstalling'] ? 'uninstall' : 'install', ';package=', $context['filename'], ';readme=\' + this.options[this.selectedIndex].value + \';license=\' + get_selected(\'license_language\'));">'; |
||
| 60 | |||
| 61 | foreach ($context['readmes'] as $a => $b) |
||
| 62 | { |
||
| 63 | echo ' |
||
| 64 | <option value="', $b, '"', $a === 'selected' ? ' selected="selected"' : '', '>', $b === 'default' ? $txt['package_readme_default'] : ucfirst($b), '</option>'; |
||
| 65 | } |
||
| 66 | |||
| 67 | echo ' |
||
| 68 | </select> |
||
| 69 | </span> |
||
| 70 | </div> |
||
| 71 | <br />'; |
||
| 72 | } |
||
| 73 | |||
| 74 | // Did they specify a license to display? |
||
| 75 | if (isset($context['package_license'])) |
||
| 76 | { |
||
| 77 | echo ' |
||
| 78 | <h2 class="category_header">', $txt['package_install_license'], '</h2> |
||
| 79 | <div class="content"> |
||
| 80 | ', $context['package_license'], ' |
||
| 81 | <span class="floatright">', $txt['package_available_license_language'], ' |
||
| 82 | <select name="license_language" id="license_language" onchange="if (this.options[this.selectedIndex].value) window.location.href = elk_prepareScriptUrl(elk_scripturl + \'', '?action=admin;area=packages;sa=install', ';package=', $context['filename'], ';license=\' + this.options[this.selectedIndex].value + \';readme=\' + get_selected(\'readme_language\'));">'; |
||
| 83 | |||
| 84 | foreach ($context['licenses'] as $a => $b) |
||
| 85 | { |
||
| 86 | echo ' |
||
| 87 | <option value="', $b, '"', $a === 'selected' ? ' selected="selected"' : '', '>', $b === 'default' ? $txt['package_license_default'] : ucfirst($b), '</option>'; |
||
| 88 | } |
||
| 89 | |||
| 90 | echo ' |
||
| 91 | </select> |
||
| 92 | </span> |
||
| 93 | </div> |
||
| 94 | <br />'; |
||
| 95 | } |
||
| 96 | |||
| 97 | if (!empty($context['post_url'])) |
||
| 98 | { |
||
| 99 | echo ' |
||
| 100 | <form action="', $context['post_url'], '" onsubmit="submitonce(this);" method="post" accept-charset="UTF-8">'; |
||
| 101 | } |
||
| 102 | |||
| 103 | echo ' |
||
| 104 | <h2 class="category_header"> |
||
| 105 | ', $context['uninstalling'] ? $txt['package_uninstall_actions'] : $txt['package_install_actions'], ' "', $context['package_name'], '" |
||
| 106 | </h2>'; |
||
| 107 | |||
| 108 | // Are there data changes to be removed? |
||
| 109 | if ($context['uninstalling'] && !empty($context['database_changes'])) |
||
| 110 | { |
||
| 111 | echo ' |
||
| 112 | <div class="content"> |
||
| 113 | <label for="do_db_changes"><input type="checkbox" name="do_db_changes" id="do_db_changes" />', $txt['package_db_uninstall'], '</label> [<a href="#" onclick="return swap_database_changes();">', $txt['package_db_uninstall_details'], '</a>] |
||
| 114 | <div id="db_changes_div"> |
||
| 115 | ', $txt['package_db_uninstall_actions'], ': |
||
| 116 | <ul>'; |
||
| 117 | |||
| 118 | foreach ($context['database_changes'] as $change) |
||
| 119 | { |
||
| 120 | echo ' |
||
| 121 | <li>', $change, '</li>'; |
||
| 122 | } |
||
| 123 | |||
| 124 | echo ' |
||
| 125 | </ul> |
||
| 126 | </div> |
||
| 127 | </div>'; |
||
| 128 | } |
||
| 129 | |||
| 130 | echo ' |
||
| 131 | <div class="information">'; |
||
| 132 | |||
| 133 | if (empty($context['actions']) && empty($context['database_changes'])) |
||
| 134 | { |
||
| 135 | echo ' |
||
| 136 | <br /> |
||
| 137 | <div class="errorbox"> |
||
| 138 | ', $txt['corrupt_compatible'], ' |
||
| 139 | </div> |
||
| 140 | </div>'; |
||
| 141 | } |
||
| 142 | else |
||
| 143 | { |
||
| 144 | echo ' |
||
| 145 | ', $txt['perform_actions'], ' |
||
| 146 | </div> |
||
| 147 | <table class="table_grid"> |
||
| 148 | <thead> |
||
| 149 | <tr class="table_head"> |
||
| 150 | <th scope="col" style="width: 20px;"></th> |
||
| 151 | <th scope="col" style="width: 30px;"></th> |
||
| 152 | <th scope="col" class="lefttext">', $txt['package_install_type'], '</th> |
||
| 153 | <th scope="col" class="lefttext grid50">', $txt['package_install_action'], '</th> |
||
| 154 | <th scope="col" class="lefttext grid20">', $txt['package_install_desc'], '</th> |
||
| 155 | </tr> |
||
| 156 | </thead> |
||
| 157 | <tbody>'; |
||
| 158 | |||
| 159 | $i = 1; |
||
| 160 | $action_num = 1; |
||
| 161 | $js_operations = array(); |
||
| 162 | foreach ($context['actions'] as $packageaction) |
||
| 163 | { |
||
| 164 | // Did we pass or fail? Need to know for later on. |
||
| 165 | $js_operations[$action_num] = $packageaction['failed'] ?? 0; |
||
| 166 | |||
| 167 | echo ' |
||
| 168 | <tr> |
||
| 169 | <td>', isset($packageaction['operations']) ? '<img id="operation_img_' . $action_num . '" src="' . $settings['images_url'] . '/selected_open.png" alt="*" class="hide" />' : '', '</td> |
||
| 170 | <td>', $i++, '.</td> |
||
| 171 | <td>', $packageaction['type'], '</td> |
||
| 172 | <td>', $packageaction['action'], '</td> |
||
| 173 | <td>', $packageaction['description'], '</td> |
||
| 174 | </tr>'; |
||
| 175 | |||
| 176 | // Is there water on the knee? Operation! |
||
| 177 | if (isset($packageaction['operations'])) |
||
| 178 | { |
||
| 179 | echo ' |
||
| 180 | <tr id="operation_', $action_num, '"> |
||
| 181 | <td colspan="5" class="standard_row"> |
||
| 182 | <table class="table_grid">'; |
||
| 183 | |||
| 184 | // Show the operations. |
||
| 185 | $operation_num = 1; |
||
| 186 | foreach ($packageaction['operations'] as $operation) |
||
| 187 | { |
||
| 188 | // Determine the position text. |
||
| 189 | $operation_text = $operation['position'] == 'replace' ? 'operation_replace' : ($operation['position'] == 'before' ? 'operation_after' : 'operation_before'); |
||
| 190 | |||
| 191 | echo ' |
||
| 192 | <tr> |
||
| 193 | <td class="hide"></td> |
||
| 194 | <td class="grid4 smalltext"> |
||
| 195 | <a href="' . $scripturl . '?action=admin;area=packages;sa=showoperations;operation_key=', $operation['operation_key'], ';package=', $context['filename'], ';filename=', $operation['filename'], (empty($context['uninstalling']) ? '' : ';reverse'), '" onclick="return reqWin(this.href, 680, 400, false);"> |
||
| 196 | <i class="icon i-view"></i> |
||
| 197 | </a> |
||
| 198 | </td> |
||
| 199 | <td class="grid4 smalltext">', $operation_num, '.</td> |
||
| 200 | <td class="smalltext">', $txt[$operation_text], '</td> |
||
| 201 | <td class="smalltext grid50">', $operation['action'], '</td> |
||
| 202 | <td class="smalltext grid20">', $operation['description'], empty($operation['ignore_failure']) ? '' : ' (' . $txt['operation_ignore'] . ')', '</td> |
||
| 203 | </tr>'; |
||
| 204 | |||
| 205 | $operation_num++; |
||
| 206 | } |
||
| 207 | |||
| 208 | echo ' |
||
| 209 | </table> |
||
| 210 | </td> |
||
| 211 | </tr>'; |
||
| 212 | |||
| 213 | // Increase it. |
||
| 214 | $action_num++; |
||
| 215 | } |
||
| 216 | } |
||
| 217 | |||
| 218 | echo ' |
||
| 219 | </tbody> |
||
| 220 | </table> |
||
| 221 | '; |
||
| 222 | |||
| 223 | // What if we have custom themes we can install into? List them too! |
||
| 224 | if (!empty($context['theme_actions'])) |
||
| 225 | { |
||
| 226 | echo ' |
||
| 227 | <br /> |
||
| 228 | <h2 class="category_header"> |
||
| 229 | ', $context['uninstalling'] ? $txt['package_other_themes_uninstall'] : $txt['package_other_themes'], ' |
||
| 230 | </h2> |
||
| 231 | <div id="custom_changes"> |
||
| 232 | <div class="information"> |
||
| 233 | ', $txt['package_other_themes_desc'], ' |
||
| 234 | </div> |
||
| 235 | <table class="table_grid">'; |
||
| 236 | |||
| 237 | // Loop through each theme and display it's name, and then it's details. |
||
| 238 | foreach ($context['theme_actions'] as $id => $theme) |
||
| 239 | { |
||
| 240 | // Pass? |
||
| 241 | $js_operations[$action_num] = !empty($theme['has_failure']); |
||
| 242 | |||
| 243 | echo ' |
||
| 244 | <tr class="secondary_header"> |
||
| 245 | <td></td> |
||
| 246 | <td class="centertext">'; |
||
| 247 | |||
| 248 | if (!empty($context['themes_locked'])) |
||
| 249 | { |
||
| 250 | echo ' |
||
| 251 | <input type="hidden" name="custom_theme[]" value="', $id, '" />'; |
||
| 252 | } |
||
| 253 | |||
| 254 | echo ' |
||
| 255 | <input type="checkbox" name="custom_theme[]" id="custom_theme_', $id, '" value="', $id, '" onclick="', (empty($theme['has_failure']) ? '' : 'if (this.form.custom_theme_' . $id . ".checked && !confirm('" . $txt['package_theme_failure_warning'] . "')) return false;"), "invertAll(this, this.form, 'dummy_theme_", $id, '\', true);" ', empty($context['themes_locked']) ? '' : 'disabled="disabled" checked="checked"', '/> |
||
| 256 | </td> |
||
| 257 | <td colspan="3"> |
||
| 258 | ', $theme['name'], ' |
||
| 259 | </td> |
||
| 260 | </tr>'; |
||
| 261 | |||
| 262 | foreach ($theme['actions'] as $action) |
||
| 263 | { |
||
| 264 | echo ' |
||
| 265 | <tr> |
||
| 266 | <td>', isset($packageaction['operations']) ? '<img id="operation_img_' . $action_num . '" src="' . $settings['images_url'] . '/selected_open.png" alt="*" class="hide" />' : '', '</td> |
||
| 267 | <td class="centertext" style="width: 30px;"> |
||
| 268 | <input type="checkbox" name="theme_changes[]" value="', empty($action['value']) ? '' : $action['value'], '" id="dummy_theme_', $id, '" ', (empty($action['not_mod']) ? 'disabled="disabled"' : ''), ' ', empty($context['themes_locked']) ? '' : 'checked="checked"', '/> |
||
| 269 | </td> |
||
| 270 | <td>', $action['type'], '</td> |
||
| 271 | <td class="grid50">', $action['action'], '</td> |
||
| 272 | <td class="grid20"><strong>', $action['description'], '</strong></td> |
||
| 273 | </tr>'; |
||
| 274 | |||
| 275 | // Is there water on the knee? Operation! |
||
| 276 | if (isset($action['operations'])) |
||
| 277 | { |
||
| 278 | echo ' |
||
| 279 | <tr id="operation_', $action_num, '"> |
||
| 280 | <td colspan="5" class="standard_row"> |
||
| 281 | <table class="table_grid">'; |
||
| 282 | |||
| 283 | $operation_num = 1; |
||
| 284 | foreach ($action['operations'] as $operation) |
||
| 285 | { |
||
| 286 | // Determine the position text. |
||
| 287 | $operation_text = $operation['position'] === 'replace' ? 'operation_replace' : ($operation['position'] === 'before' ? 'operation_after' : 'operation_before'); |
||
| 288 | |||
| 289 | echo ' |
||
| 290 | <tr> |
||
| 291 | <td class="hide"></td> |
||
| 292 | <td class="grid4 smalltext"> |
||
| 293 | <a href="' . $scripturl . '?action=admin;area=packages;sa=showoperations;operation_key=', $operation['operation_key'], ';package=', $context['filename'], ';filename=', $operation['filename'], (empty($context['uninstalling']) ? '' : ';reverse'), '" onclick="return reqWin(this.href, 600, 400, false);"> |
||
| 294 | <i class="icon i-view"></i> |
||
| 295 | </a> |
||
| 296 | </td> |
||
| 297 | <td class="grid4 smalltext">', $operation_num, '.</td> |
||
| 298 | <td class="smalltext">', $txt[$operation_text], '</td> |
||
| 299 | <td class="smalltext grid50">', $operation['action'], '</td> |
||
| 300 | <td class="smalltext grid20">', $operation['description'], empty($operation['ignore_failure']) ? '' : ' (' . $txt['operation_ignore'] . ')', '</td> |
||
| 301 | </tr>'; |
||
| 302 | $operation_num++; |
||
| 303 | } |
||
| 304 | |||
| 305 | echo ' |
||
| 306 | </table> |
||
| 307 | </td> |
||
| 308 | </tr>'; |
||
| 309 | |||
| 310 | // Increase it. |
||
| 311 | $action_num++; |
||
| 312 | } |
||
| 313 | } |
||
| 314 | } |
||
| 315 | |||
| 316 | echo ' |
||
| 317 | </table> |
||
| 318 | </div>'; |
||
| 319 | } |
||
| 320 | } |
||
| 321 | |||
| 322 | // Are we effectively ready to install? |
||
| 323 | if (!$context['ftp_needed'] && (!empty($context['actions']) || !empty($context['database_changes']))) |
||
| 324 | { |
||
| 325 | echo ' |
||
| 326 | <div class="submitbutton"> |
||
| 327 | <input type="submit" value="', $context['uninstalling'] ? $txt['package_uninstall_now'] : $txt['package_install_now'], '" onclick="return ', empty($context['has_failure']) ? 'submitThisOnce(this)' : "(submitThisOnce(this) && confirm('" . ($context['uninstalling'] ? $txt['package_will_fail_popup_uninstall'] : $txt['package_will_fail_popup']) . "'))", ';" /> |
||
| 328 | </div>'; |
||
| 329 | } |
||
| 330 | // If we need ftp information then demand it! |
||
| 331 | elseif ($context['ftp_needed']) |
||
| 332 | { |
||
| 333 | echo ' |
||
| 334 | <h2 class="category_header hdicon i-warning">', $txt['package_ftp_necessary'], '</h2> |
||
| 335 | |||
| 336 | <div> |
||
| 337 | ', template_control_chmod(), ' |
||
|
|
|||
| 338 | </div>'; |
||
| 339 | } |
||
| 340 | |||
| 341 | if (!empty($context['post_url'])) |
||
| 342 | { |
||
| 343 | echo ' |
||
| 344 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />', (isset($context['form_sequence_number']) && !$context['ftp_needed']) ? ' |
||
| 345 | <input type="hidden" name="seqnum" value="' . $context['form_sequence_number'] . '" />' : '', ' |
||
| 346 | </form>'; |
||
| 347 | } |
||
| 348 | |||
| 349 | echo ' |
||
| 350 | </div>'; |
||
| 351 | |||
| 352 | // Toggle options. |
||
| 353 | echo ' |
||
| 354 | <script> |
||
| 355 | var aOperationElements = [];'; |
||
| 356 | |||
| 357 | // Operations. |
||
| 358 | foreach ($js_operations as $key => $operation) |
||
| 359 | { |
||
| 360 | echo ' |
||
| 361 | aOperationElements[', $key, '] = new elk_Toggle({ |
||
| 362 | bToggleEnabled: true, |
||
| 363 | bCurrentlyCollapsed: ', $operation ? 'false' : 'true', ', |
||
| 364 | aSwappableContainers: [ |
||
| 365 | \'operation_', $key, '\' |
||
| 366 | ], |
||
| 367 | aSwapImages: [ |
||
| 368 | { |
||
| 369 | sId: \'operation_img_', $key, '\', |
||
| 370 | srcExpanded: elk_images_url + \'/selected_open.png\', |
||
| 371 | altExpanded: ', JavaScriptEscape($txt['hide']), ', |
||
| 372 | srcCollapsed: elk_images_url + \'/selected.png\', |
||
| 373 | altCollapsed: ', JavaScriptEscape($txt['show']), ', |
||
| 374 | } |
||
| 375 | ] |
||
| 376 | });'; |
||
| 377 | } |
||
| 378 | |||
| 379 | echo ' |
||
| 380 | </script>'; |
||
| 381 | |||
| 382 | // Get the currently selected item from a select list |
||
| 383 | echo ' |
||
| 384 | <script> |
||
| 385 | function get_selected(id) |
||
| 386 | { |
||
| 387 | var aSelected = document.getElementById(id); |
||
| 388 | for (var i = 0; i < aSelected.options.length; i++) |
||
| 389 | { |
||
| 390 | if (aSelected.options[i].selected == true) |
||
| 391 | return aSelected.options[i].value; |
||
| 392 | } |
||
| 393 | return aSelected.options[0]; |
||
| 394 | } |
||
| 395 | </script>'; |
||
| 396 | |||
| 397 | // And a bit more for database changes. |
||
| 398 | if (!$context['uninstalling']) |
||
| 399 | { |
||
| 400 | return; |
||
| 401 | } |
||
| 402 | |||
| 403 | if (empty($context['database_changes'])) |
||
| 404 | { |
||
| 405 | return; |
||
| 406 | } |
||
| 407 | |||
| 408 | echo ' |
||
| 409 | <script> |
||
| 810 |