| Conditions | 14 |
| Paths | 37 |
| Total Lines | 152 |
| 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_download_language() |
||
| 20 | { |
||
| 21 | global $context, $settings, $txt, $scripturl; |
||
| 22 | |||
| 23 | // Actually finished? |
||
| 24 | if (!empty($context['install_complete'])) |
||
| 25 | { |
||
| 26 | echo ' |
||
| 27 | <div id="admincenter"> |
||
| 28 | <h2 class="category_header">', $txt['languages_download_complete'], '</h2> |
||
| 29 | <div class="content"> |
||
| 30 | ', $context['install_complete'], ' |
||
| 31 | </div> |
||
| 32 | </div>'; |
||
| 33 | return; |
||
| 34 | } |
||
| 35 | |||
| 36 | // An error? |
||
| 37 | if (!empty($context['error_message'])) |
||
| 38 | echo ' |
||
| 39 | <div class="errorbox"> |
||
| 40 | ', $context['error_message'], ' |
||
| 41 | </div>'; |
||
| 42 | |||
| 43 | // Provide something of an introduction... |
||
| 44 | echo ' |
||
| 45 | <div id="admincenter"> |
||
| 46 | <form action="', $scripturl, '?action=admin;area=languages;sa=downloadlang;did=', $context['download_id'], ';', $context['session_var'], '=', $context['session_id'], '" method="post" accept-charset="UTF-8"> |
||
| 47 | <h2 class="category_header">', $txt['languages_download'], '</h2> |
||
| 48 | <div class="content"> |
||
| 49 | <p> |
||
| 50 | ', $txt['languages_download_note'], ' |
||
| 51 | </p> |
||
| 52 | <div class="smalltext"> |
||
| 53 | ', $txt['languages_download_info'], ' |
||
| 54 | </div> |
||
| 55 | </div>'; |
||
| 56 | |||
| 57 | // Show the main files. |
||
| 58 | template_show_list('lang_main_files_list'); |
||
| 59 | |||
| 60 | // Now, all the images and the likes, hidden via javascript 'cause there are so fecking many. |
||
| 61 | echo ' |
||
| 62 | <br /> |
||
| 63 | <h2 class="category_header">', $txt['languages_download_theme_files'], '</h2> |
||
| 64 | <table class="table_grid"> |
||
| 65 | <thead> |
||
| 66 | <tr class="table_head"> |
||
| 67 | <th scope="col"> |
||
| 68 | ', $txt['languages_download_filename'], ' |
||
| 69 | </th> |
||
| 70 | <th scope="col" style="width: 100px;"> |
||
| 71 | ', $txt['languages_download_writable'], ' |
||
| 72 | </th> |
||
| 73 | <th scope="col" style="width: 100px;"> |
||
| 74 | ', $txt['languages_download_exists'], ' |
||
| 75 | </th> |
||
| 76 | <th scope="col" style="width: 4%;"> |
||
| 77 | ', $txt['languages_download_copy'], ' |
||
| 78 | </th> |
||
| 79 | </tr> |
||
| 80 | </thead> |
||
| 81 | <tbody>'; |
||
| 82 | |||
| 83 | foreach ($context['files']['images'] as $theme => $group) |
||
| 84 | { |
||
| 85 | $count = 0; |
||
| 86 | echo ' |
||
| 87 | <tr class="secondary_header"> |
||
| 88 | <td colspan="4"> |
||
| 89 | <img class="sort" src="', $settings['images_url'], '/sort_down.png" id="toggle_image_', $theme, '" alt="*" /> ', isset($context['theme_names'][$theme]) ? $context['theme_names'][$theme] : $theme, ' |
||
| 90 | </td> |
||
| 91 | </tr>'; |
||
| 92 | |||
| 93 | foreach ($group as $file) |
||
| 94 | { |
||
| 95 | echo ' |
||
| 96 | <tr id="', $theme, '-', ($count++), '"> |
||
| 97 | <td> |
||
| 98 | <strong>', $file['name'], '</strong><br /> |
||
| 99 | <span class="smalltext">', $txt['languages_download_dest'], ': ', $file['destination'], '</span> |
||
| 100 | </td> |
||
| 101 | <td> |
||
| 102 | <span style="color: ', ($file['writable'] ? 'green' : 'red'), ';">', ($file['writable'] ? $txt['yes'] : $txt['no']), '</span> |
||
| 103 | </td> |
||
| 104 | <td> |
||
| 105 | ', $file['exists'] ? ($file['exists'] == 'same' ? $txt['languages_download_exists_same'] : $txt['languages_download_exists_different']) : $txt['no'], ' |
||
| 106 | </td> |
||
| 107 | <td class="centertext"> |
||
| 108 | <input type="checkbox" name="copy_file[]" value="', $file['generaldest'], '"', ($file['default_copy'] ? ' checked="checked"' : ''), ' /> |
||
| 109 | </td> |
||
| 110 | </tr>'; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | echo ' |
||
| 115 | </tbody> |
||
| 116 | </table>'; |
||
| 117 | |||
| 118 | // Do we want some FTP baby? |
||
| 119 | // If the files are not writable, we might! |
||
| 120 | if (!empty($context['still_not_writable'])) |
||
| 121 | { |
||
| 122 | template_ftp_required(); |
||
| 123 | } |
||
| 124 | |||
| 125 | // Install? |
||
| 126 | echo ' |
||
| 127 | <div class="submitbutton"> |
||
| 128 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" /> |
||
| 129 | <input type="hidden" name="', $context['admin-dlang_token_var'], '" value="', $context['admin-dlang_token'], '" /> |
||
| 130 | <input type="submit" name="do_install" value="', $txt['add_language_elk_install'], '" /> |
||
| 131 | </div> |
||
| 132 | </form> |
||
| 133 | </div>'; |
||
| 134 | |||
| 135 | // The javascript for expand and collapse of sections. |
||
| 136 | echo ' |
||
| 137 | <script>'; |
||
| 138 | |||
| 139 | // Each theme gets its own handler. |
||
| 140 | foreach ($context['files']['images'] as $theme => $group) |
||
| 141 | { |
||
| 142 | $count = 0; |
||
| 143 | echo ' |
||
| 144 | var oTogglePanel_', $theme, ' = new elk_Toggle({ |
||
| 145 | bToggleEnabled: true, |
||
| 146 | bCurrentlyCollapsed: true, |
||
| 147 | aSwappableContainers: ['; |
||
| 148 | |||
| 149 | foreach ($group as $file) |
||
| 150 | echo ' |
||
| 151 | ', JavaScriptEscape($theme . '-' . ($count++)), ','; |
||
| 152 | |||
| 153 | echo ' |
||
| 154 | null |
||
| 155 | ], |
||
| 156 | aSwapImages: [ |
||
| 157 | { |
||
| 158 | sId: \'toggle_image_', $theme, '\', |
||
| 159 | srcExpanded: elk_images_url + \'/selected_open.png\', |
||
| 160 | altExpanded: \'*\', |
||
| 161 | srcCollapsed: elk_images_url + \'/selected.png\', |
||
| 162 | altCollapsed: \'*\' |
||
| 163 | } |
||
| 164 | ] |
||
| 165 | });'; |
||
| 166 | } |
||
| 167 | |||
| 168 | echo ' |
||
| 169 | </script>'; |
||
| 170 | } |
||
| 171 | |||
| 360 |