| Conditions | 15 |
| Paths | 104 |
| Total Lines | 56 |
| Code Lines | 39 |
| 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 |
||
| 39 | function newbbAttachmentImage($source) |
||
| 40 | { |
||
| 41 | $img_path = $GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments']); |
||
| 42 | $img_url = XOOPS_URL . '/' . $GLOBALS['xoopsModuleConfig']['dir_attachments']; |
||
| 43 | $thumb_path = $img_path . '/thumbs'; |
||
| 44 | $thumb_url = $img_url . '/thumbs'; |
||
| 45 | |||
| 46 | $thumb = $thumb_path . '/' . $source; |
||
| 47 | $image = $img_path . '/' . $source; |
||
| 48 | $thumb_url = $thumb_url . '/' . $source; |
||
|
|
|||
| 49 | $image_url = $img_url . '/' . $source; |
||
| 50 | |||
| 51 | $imginfo = @getimagesize($image); |
||
| 52 | $img_info = (count($imginfo) > 0) ? $imginfo[0] . 'X' . $imginfo[1] . ' px' : ''; |
||
| 53 | |||
| 54 | if ($GLOBALS['xoopsModuleConfig']['max_image_width'] > 0 |
||
| 55 | && $GLOBALS['xoopsModuleConfig']['max_image_height'] > 0) { |
||
| 56 | if ($imginfo[0] > $GLOBALS['xoopsModuleConfig']['max_image_width'] |
||
| 57 | || $imginfo[1] > $GLOBALS['xoopsModuleConfig']['max_image_height']) { |
||
| 58 | //if (!file_exists($thumb_path.'/'.$source) && $imginfo[0] > $GLOBALS['xoopsModuleConfig']['max_img_width']) { |
||
| 59 | if (!file_exists($thumb_path . '/' . $source)) { |
||
| 60 | newbbCreateThumbnail($source, $GLOBALS['xoopsModuleConfig']['max_image_width']); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | if ($imginfo[0] > $GLOBALS['xoopsModuleConfig']['max_image_width'] |
||
| 65 | || $imginfo[1] > $GLOBALS['xoopsModuleConfig']['max_image_height']) { |
||
| 66 | $pseudo_width = $GLOBALS['xoopsModuleConfig']['max_image_width']; |
||
| 67 | $pseudo_height = $GLOBALS['xoopsModuleConfig']['max_image_width'] * ($imginfo[1] / $imginfo[0]); |
||
| 68 | $pseudo_size = "width='" . $pseudo_width . "px' height='" . $pseudo_height . "px'"; |
||
| 69 | } |
||
| 70 | // irmtfan to fix Undefined variable: pseudo_height |
||
| 71 | if (!empty($pseudo_height) && $GLOBALS['xoopsModuleConfig']['max_image_height'] > 0 |
||
| 72 | && $pseudo_height > $GLOBALS['xoopsModuleConfig']['max_image_height']) { |
||
| 73 | $pseudo_height = $GLOBALS['xoopsModuleConfig']['max_image_height']; |
||
| 74 | $pseudo_width = $GLOBALS['xoopsModuleConfig']['max_image_height'] * ($imginfo[0] / $imginfo[1]); |
||
| 75 | $pseudo_size = "width='" . $pseudo_width . "px' height='" . $pseudo_height . "px'"; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | if (file_exists($thumb)) { |
||
| 80 | $attachmentImage = '<a href="' . $image_url . '" title="' . $source . ' ' . $img_info . '" target="_blank">'; |
||
| 81 | // $attachmentImage .= '<img src="' . $thumb_url . '" alt="' . $source . ' ' . $img_info . '" >'; |
||
| 82 | $attachmentImage .= '<img src="' . $image_url . '" ' . $pseudo_size . ' alt="' . $source . ' ' . $img_info . '" >'; |
||
| 83 | $attachmentImage .= '</a>'; |
||
| 84 | } elseif (!empty($pseudo_size)) { |
||
| 85 | $attachmentImage = '<a href="' . $image_url . '" title="' . $source . ' ' . $img_info . '" target="_blank">'; |
||
| 86 | $attachmentImage .= '<img src="' . $image_url . '" ' . $pseudo_size . ' alt="' . $source . ' ' . $img_info . '" >'; |
||
| 87 | $attachmentImage .= '</a>'; |
||
| 88 | } elseif (file_exists($image)) { |
||
| 89 | $attachmentImage = '<img src="' . $image_url . '" alt="' . $source . ' ' . $img_info . '" >'; |
||
| 90 | } else { |
||
| 91 | $attachmentImage = ''; |
||
| 92 | } |
||
| 93 | |||
| 94 | return $attachmentImage; |
||
| 95 | } |
||
| 222 |