| Conditions | 55 |
| Paths | > 20000 |
| Total Lines | 280 |
| Code Lines | 137 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 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 |
||
| 97 | function template_block_edit() |
||
| 98 | { |
||
| 99 | global $context, $settings, $options, $scripturl, $txt, $helptxt; |
||
| 100 | |||
| 101 | // Want to take a look before you save? |
||
| 102 | if (!empty($context['SPortal']['preview'])) |
||
| 103 | { |
||
| 104 | if (!empty($context['SPortal']['error'])) |
||
| 105 | echo ' |
||
| 106 | <div class="errorbox">' , $context['SPortal']['error'], '</div>'; |
||
| 107 | |||
| 108 | echo ' |
||
| 109 | <div class="sp_auto_align" style="width: ', $context['widths'][$context['SPortal']['block']['column']], ';">'; |
||
| 110 | |||
| 111 | template_block($context['SPortal']['block']); |
||
| 112 | |||
| 113 | echo ' |
||
| 114 | </div>'; |
||
| 115 | } |
||
| 116 | |||
| 117 | echo ' |
||
| 118 | <div id="sp_edit_block"> |
||
| 119 | <form id="admin_form_wrapper" name="sp_edit_block_form" id="sp_edit_block_form" action="', $scripturl, '?action=admin;area=portalblocks;sa=edit" method="post" accept-charset="UTF-8" onsubmit="submitonce(this);"> |
||
| 120 | <h3 class="category_header"> |
||
| 121 | <a class="hdicon cat_img_helptopics help" href="', $scripturl, '?action=quickhelp;help=sp-blocks', $context['SPortal']['is_new'] ? 'Add' : 'Edit', '" onclick="return reqOverlayDiv(this.href);" title="', $txt['help'], '"></a> |
||
| 122 | ', $context['SPortal']['is_new'] ? $txt['sp-blocksAdd'] : $txt['sp-blocksEdit'], ' |
||
| 123 | </h3> |
||
| 124 | <div class="sp_content_padding"> |
||
| 125 | <h3 class="secondary_header">',$context['SPortal']['block']['type_text'], '</h3> |
||
| 126 | <dl class="sp_form content"> |
||
| 127 | <dt> |
||
| 128 | <label for="block_name">', $txt['sp-adminColumnName'], ':</label> |
||
| 129 | </dt> |
||
| 130 | <dd> |
||
| 131 | <input type="text" name="block_name" id="block_name" value="', $context['SPortal']['block']['label'], '" size="30" class="input_text" /> |
||
| 132 | </dd> |
||
| 133 | <dt> |
||
| 134 | <label for="block_permissions">', $txt['sp_admin_blocks_col_permissions'], ':</label> |
||
| 135 | </dt> |
||
| 136 | <dd> |
||
| 137 | <select name="permissions" id="block_permissions">'; |
||
| 138 | |||
| 139 | foreach ($context['SPortal']['block']['permission_profiles'] as $profile) |
||
| 140 | echo ' |
||
| 141 | <option value="', $profile['id'], '"', $profile['id'] == $context['SPortal']['block']['permissions'] ? ' selected="selected"' : '', '>', $profile['label'], '</option>'; |
||
| 142 | |||
| 143 | echo ' |
||
| 144 | </select> |
||
| 145 | </dd> |
||
| 146 | <dt> |
||
| 147 | <label for="block_styles">', $txt['sp_admin_blocks_col_styles'], ':</label> |
||
| 148 | </dt> |
||
| 149 | <dd> |
||
| 150 | <select name="styles" id="block_styles">'; |
||
| 151 | |||
| 152 | foreach ($context['SPortal']['block']['style_profiles'] as $profile) |
||
| 153 | echo ' |
||
| 154 | <option value="', $profile['id'], '"', $profile['id'] == $context['SPortal']['block']['styles'] ? ' selected="selected"' : '', '>', $profile['label'], '</option>'; |
||
| 155 | |||
| 156 | echo ' |
||
| 157 | </select> |
||
| 158 | </dd> |
||
| 159 | <dt> |
||
| 160 | <label for="block_visibility">', $txt['sp_admin_blocks_col_visibility'], ':</label> |
||
| 161 | </dt> |
||
| 162 | <dd> |
||
| 163 | <select name="visibility" id="block_visibility">'; |
||
| 164 | |||
| 165 | foreach ($context['SPortal']['block']['visibility_profiles'] as $profile) |
||
| 166 | echo ' |
||
| 167 | <option value="', $profile['id'], '"', $profile['id'] == $context['SPortal']['block']['visibility'] ? ' selected="selected"' : '', '>', $profile['label'], '</option>'; |
||
| 168 | |||
| 169 | echo ' |
||
| 170 | </select> |
||
| 171 | </dd> |
||
| 172 | </dl> |
||
| 173 | <h3 class="secondary_header">', $txt['sp-adminBlockSettingsName'], '</h3> |
||
| 174 | <dl class="sp_form content">'; |
||
| 175 | |||
| 176 | // Display any options that are available for this block |
||
| 177 | foreach ($context['SPortal']['block']['options'] as $name => $type) |
||
| 178 | { |
||
| 179 | if (empty($context['SPortal']['block']['parameters'][$name])) |
||
| 180 | $context['SPortal']['block']['parameters'][$name] = ''; |
||
| 181 | |||
| 182 | echo ' |
||
| 183 | <dt>'; |
||
| 184 | |||
| 185 | // Look for the help text using legacyNaming |
||
| 186 | $helpvar = lcfirst(ucwords(str_replace('_', ' ', $context['SPortal']['block']['type']))); |
||
| 187 | $helpvar = str_replace(' ', '', $helpvar); |
||
| 188 | $helpvar = 'sp_param_sp_' . $helpvar . '_' . $name; |
||
| 189 | |||
| 190 | if (!empty($helptxt[$helpvar])) |
||
| 191 | echo ' |
||
| 192 | <a class="help" href="', $scripturl, '?action=quickhelp;help=', $helpvar, '" onclick="return reqOverlayDiv(this.href);"> |
||
| 193 | <img class="icon" src="', $settings['images_url'], '/helptopics.png" alt="', $txt['help'], '" /> |
||
| 194 | </a>'; |
||
| 195 | |||
| 196 | if ($type === 'space') |
||
| 197 | echo ''; |
||
| 198 | else |
||
| 199 | echo ' |
||
| 200 | <label for="', $type === 'bbc' ? 'bbc_content' : $name, '">', $txt['sp_param_' . $context['SPortal']['block']['type'] . '_' . $name], ':</label>'; |
||
| 201 | |||
| 202 | echo ' |
||
| 203 | </dt> |
||
| 204 | <dd>'; |
||
| 205 | |||
| 206 | if ($type === 'bbc') |
||
| 207 | { |
||
| 208 | echo ' |
||
| 209 | </dd> |
||
| 210 | </dl> |
||
| 211 | <div id="sp_rich_editor"> |
||
| 212 | <div id="sp_rich_bbc"></div> |
||
| 213 | <div id="sp_rich_smileys"></div> |
||
| 214 | ', template_control_richedit($context['SPortal']['bbc'], 'sp_rich_smileys', 'sp_rich_bbc'), ' |
||
| 215 | <input type="hidden" name="bbc_name" value="', $name, '" /> |
||
| 216 | <input type="hidden" name="bbc_parameter" value="', $context['SPortal']['bbc'], '" /> |
||
| 217 | </div> |
||
| 218 | <dl class="sp_form">'; |
||
| 219 | } |
||
| 220 | elseif ($type === 'boards' || $type === 'board_select') |
||
| 221 | { |
||
| 222 | echo ' |
||
| 223 | <input type="hidden" name="parameters[', $name, ']" value="" />'; |
||
| 224 | |||
| 225 | if ($type === 'boards') |
||
| 226 | echo ' |
||
| 227 | <select name="parameters[', $name, '][]" id="', $name, '" size="7" multiple="multiple">'; |
||
| 228 | else |
||
| 229 | echo ' |
||
| 230 | <select name="parameters[', $name, '][]" id="', $name, '">'; |
||
| 231 | |||
| 232 | foreach ($context['SPortal']['block']['board_options'][$name] as $option) |
||
| 233 | echo ' |
||
| 234 | <option value="', $option['value'], '"', ($option['selected'] ? ' selected="selected"' : ''), ' >', $option['text'], '</option>'; |
||
| 235 | |||
| 236 | echo ' |
||
| 237 | </select>'; |
||
| 238 | } |
||
| 239 | elseif ($type === 'int') |
||
| 240 | echo ' |
||
| 241 | <input type="text" name="parameters[', $name, ']" id="', $name, '" value="', $context['SPortal']['block']['parameters'][$name],'" size="7" class="input_text" />'; |
||
| 242 | elseif ($type === 'text') |
||
| 243 | echo ' |
||
| 244 | <input type="text" name="parameters[', $name, ']" id="', $name, '" value="', $context['SPortal']['block']['parameters'][$name],'" size="25" class="input_text" />'; |
||
| 245 | elseif ($type === 'check') |
||
| 246 | echo ' |
||
| 247 | <input type="checkbox" name="parameters[', $name, ']" id="', $name, '"', !empty($context['SPortal']['block']['parameters'][$name]) ? ' checked="checked"' : '', ' class="input_check" />'; |
||
| 248 | elseif ($type === 'select') |
||
| 249 | { |
||
| 250 | $options = explode('|', $txt['sp_param_' . $context['SPortal']['block']['type'] . '_' . $name . '_options']); |
||
| 251 | |||
| 252 | echo ' |
||
| 253 | <select name="parameters[', $name, ']" id="', $name, '">'; |
||
| 254 | |||
| 255 | foreach ($options as $key => $option) |
||
| 256 | echo ' |
||
| 257 | <option value="', $key, '"', $context['SPortal']['block']['parameters'][$name] == $key ? ' selected="selected"' : '', '>', $option, '</option>'; |
||
| 258 | |||
| 259 | echo ' |
||
| 260 | </select>'; |
||
| 261 | } |
||
| 262 | elseif (is_array($type)) |
||
| 263 | { |
||
| 264 | echo ' |
||
| 265 | <select name="parameters[', $name, ']" id="', $name, '">'; |
||
| 266 | |||
| 267 | foreach ($type as $key => $option) |
||
| 268 | echo ' |
||
| 269 | <option value="', $key, '"', $context['SPortal']['block']['parameters'][$name] == $key ? ' selected="selected"' : '', '>', $option, '</option>'; |
||
| 270 | |||
| 271 | echo ' |
||
| 272 | </select>'; |
||
| 273 | } |
||
| 274 | elseif ($type === 'textarea') |
||
| 275 | { |
||
| 276 | echo ' |
||
| 277 | </dd> |
||
| 278 | </dl> |
||
| 279 | <div id="sp_text_editor"> |
||
| 280 | <textarea name="parameters[', $name, ']" id="', $name, '" cols="45" rows="10">', $context['SPortal']['block']['parameters'][$name], '</textarea> |
||
| 281 | <input type="button" class="button_submit" value="-" onclick="document.getElementById(\'', $name, '\').rows -= 10" /> |
||
| 282 | <input type="button" class="button_submit" value="+" onclick="document.getElementById(\'', $name, '\').rows += 10" /> |
||
| 283 | </div> |
||
| 284 | <dl class="sp_form">'; |
||
| 285 | } |
||
| 286 | elseif ($type === 'space') |
||
| 287 | { |
||
| 288 | echo ' |
||
| 289 | </dd> |
||
| 290 | </dl> |
||
| 291 | <hr> |
||
| 292 | <dl class="sp_form">'; |
||
| 293 | } |
||
| 294 | |||
| 295 | if ($type != 'bbc' && $type != 'textarea') |
||
| 296 | echo ' |
||
| 297 | </dd>'; |
||
| 298 | } |
||
| 299 | |||
| 300 | if (empty($context['SPortal']['block']['column'])) |
||
| 301 | { |
||
| 302 | echo ' |
||
| 303 | <dt> |
||
| 304 | <label for="block_column">', $txt['sp-blocksColumn'], ':</label> |
||
| 305 | </dt> |
||
| 306 | <dd> |
||
| 307 | <select id="block_column" name="block_column">'; |
||
| 308 | |||
| 309 | $block_sides = array(5 => 'Header', 1 => 'Left', 2 => 'Top', 3 => 'Bottom', 4 => 'Right', 6 => 'Footer'); |
||
| 310 | foreach ($block_sides as $id => $side) |
||
| 311 | echo ' |
||
| 312 | <option value="', $id, '">', $txt['sp-position' . $side], '</option>'; |
||
| 313 | |||
| 314 | echo ' |
||
| 315 | </select> |
||
| 316 | </dd>'; |
||
| 317 | } |
||
| 318 | |||
| 319 | if (count($context['SPortal']['block']['list_blocks']) > 1) |
||
| 320 | { |
||
| 321 | echo ' |
||
| 322 | <dt> |
||
| 323 | ', $txt['sp-blocksRow'], ': |
||
| 324 | </dt> |
||
| 325 | <dd> |
||
| 326 | <select id="order" name="placement"', !$context['SPortal']['is_new'] ? ' onchange="this.form.block_row.disabled = this.options[this.selectedIndex].value == \'\';"' : '', '> |
||
| 327 | ', !$context['SPortal']['is_new'] ? '<option value="nochange">' . $txt['sp-placementUnchanged'] . '</option>' : '', ' |
||
| 328 | <option value="before"', (!empty($context['SPortal']['block']['placement']) && $context['SPortal']['block']['placement'] === 'before' ? ' selected="selected"' : ''), '>', $txt['sp-placementBefore'], '...</option> |
||
| 329 | <option value="after"', (!empty($context['SPortal']['block']['placement']) && $context['SPortal']['block']['placement'] === 'after' ? ' selected="selected"' : ''), '>', $txt['sp-placementAfter'], '...</option> |
||
| 330 | </select> |
||
| 331 | <select id="block_row" name="block_row"', !$context['SPortal']['is_new'] ? ' disabled="disabled"' : '', '>'; |
||
| 332 | |||
| 333 | foreach ($context['SPortal']['block']['list_blocks'] as $block) |
||
| 334 | { |
||
| 335 | if ($block['id'] != $context['SPortal']['block']['id']) |
||
| 336 | echo ' |
||
| 337 | <option value="', $block['row'], '"', (!empty($context['SPortal']['block']['row']) && $context['SPortal']['block']['row'] == $block['row'] ? ' selected="selected"' : ''), '>', $block['label'], '</option>'; } |
||
| 338 | |||
| 339 | echo ' |
||
| 340 | </select> |
||
| 341 | </dd>'; |
||
| 342 | } |
||
| 343 | |||
| 344 | if ($context['SPortal']['block']['type'] !== 'sp_boardNews') |
||
| 345 | { |
||
| 346 | echo ' |
||
| 347 | <dt> |
||
| 348 | <label for="block_force">', $txt['sp-blocksForce'], ':</label> |
||
| 349 | </dt> |
||
| 350 | <dd> |
||
| 351 | <input type="checkbox" name="block_force" id="block_force" value="1"', $context['SPortal']['block']['force_view'] ? ' checked="checked"' : '', ' class="input_check" /> |
||
| 352 | </dd>'; |
||
| 353 | } |
||
| 354 | |||
| 355 | echo ' |
||
| 356 | <dt> |
||
| 357 | <label for="block_active">', $txt['sp-blocksActive'], ':</label> |
||
| 358 | </dt> |
||
| 359 | <dd> |
||
| 360 | <input type="checkbox" name="block_active" id="block_active" value="1"', $context['SPortal']['block']['state'] ? ' checked="checked"' : '', ' class="input_check" /> |
||
| 361 | </dd> |
||
| 362 | </dl> |
||
| 363 | <div class="submitbutton"> |
||
| 364 | <input type="submit" name="preview_block" value="', $txt['sp-blocksPreview'], '" class="button_submit" /> |
||
| 365 | <input type="submit" name="add_block" value="', !$context['SPortal']['is_new'] ? $txt['sp-blocksEdit'] : $txt['sp-blocksAdd'], '" class="button_submit" /> |
||
| 366 | </div> |
||
| 367 | </div>'; |
||
| 368 | |||
| 369 | if (!empty($context['SPortal']['block']['column'])) |
||
| 370 | echo ' |
||
| 371 | <input type="hidden" name="block_column" value="', $context['SPortal']['block']['column'], '" />'; |
||
| 372 | |||
| 373 | echo ' |
||
| 374 | <input type="hidden" name="block_type" value="', $context['SPortal']['block']['type'], '" /> |
||
| 375 | <input type="hidden" name="block_id" value="', $context['SPortal']['block']['id'], '" /> |
||
| 376 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" /> |
||
| 377 | </form> |
||
| 424 |