mambax7 /
adslight
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /* |
||
| 3 | ------------------------------------------------------------------------- |
||
| 4 | ADSLIGHT 2 : Module for Xoops |
||
| 5 | |||
| 6 | Redesigned and ameliorate By Luc Bizet user at www.frxoops.org |
||
| 7 | Started with the Classifieds module and made MANY changes |
||
| 8 | Website : http://www.luc-bizet.fr |
||
| 9 | Contact : [email protected] |
||
| 10 | ------------------------------------------------------------------------- |
||
| 11 | Original credits below Version History |
||
| 12 | ########################################################################## |
||
| 13 | # Classified Module for Xoops # |
||
| 14 | # By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com # |
||
| 15 | # Started with the MyAds module and made MANY changes # |
||
| 16 | ########################################################################## |
||
| 17 | Original Author: Pascal Le Boustouller |
||
| 18 | Author Website : [email protected] |
||
| 19 | Licence Type : GPL |
||
| 20 | ------------------------------------------------------------------------- |
||
| 21 | */ |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Class GD |
||
| 25 | */ |
||
| 26 | class GD |
||
| 27 | { |
||
| 28 | public $image; |
||
| 29 | public $width; |
||
| 30 | public $height; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param $location |
||
| 34 | */ |
||
| 35 | public function __construct($location) |
||
| 36 | { |
||
| 37 | $imageinfo = @getimagesize($location) || exit('Unknown picture'); |
||
| 38 | |||
| 39 | $this->width = $imageinfo['0']; |
||
| 40 | $this->height = $imageinfo['1']; |
||
| 41 | |||
| 42 | switch ($imageinfo['2']) { |
||
| 43 | case '1': |
||
| 44 | $this->image = imagecreatefromgif($location); |
||
| 45 | break; |
||
| 46 | |||
| 47 | case '2': |
||
| 48 | $this->image = imagecreatefromjpeg($location); |
||
| 49 | break; |
||
| 50 | |||
| 51 | case '3': |
||
| 52 | $this->image = imagecreatefrompng($location); |
||
| 53 | break; |
||
| 54 | |||
| 55 | default: |
||
| 56 | exit('Unknown file format'); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param $sizex |
||
| 62 | * @param $sizey |
||
| 63 | */ |
||
| 64 | public function resize($sizex, $sizey) |
||
| 65 | { |
||
| 66 | $org = round($this->width / $this->height, 2); |
||
| 67 | $new = round($sizex / $sizey, 2); |
||
| 68 | |||
| 69 | if ($new > $org) { |
||
| 70 | $sizex = round($this->width / ($this->height / $sizey), 0); |
||
| 71 | // $sizey = $sizey; |
||
|
0 ignored issues
–
show
|
|||
| 72 | } else { |
||
| 73 | // $sizex = $sizex; |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
43% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 74 | $sizey = round($this->height / ($this->width / $sizex), 0); |
||
| 75 | } |
||
| 76 | |||
| 77 | $resized = imagecreatetruecolor($sizex, $sizey); |
||
| 78 | imagecopyresampled($resized, $this->image, 0, 0, 0, 0, $sizex, $sizey, $this->width, $this->height); |
||
| 79 | |||
| 80 | $this->image = $resized; |
||
| 81 | $this->width = $sizex; |
||
| 82 | $this->height = $sizey; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param $color |
||
| 87 | * |
||
| 88 | * @return array |
||
| 89 | */ |
||
| 90 | public function make_color($color) |
||
| 91 | { |
||
| 92 | $rgb = array(); |
||
| 93 | |||
| 94 | if (is_array($color) && count($color) == '3') { |
||
| 95 | $rgb['r'] = $color['0']; |
||
| 96 | $rgb['g'] = $color['1']; |
||
| 97 | $rgb['b'] = $color['2']; |
||
| 98 | } elseif (preg_match('/^#?([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i', $color, $results)) { |
||
| 99 | $rgb['r'] = hexdec($results['1']); |
||
| 100 | $rgb['g'] = hexdec($results['2']); |
||
| 101 | $rgb['b'] = hexdec($results['3']); |
||
| 102 | } else { |
||
| 103 | exit('Unknown color'); |
||
| 104 | } |
||
| 105 | |||
| 106 | foreach (array('r', 'g', 'b') as $value) { |
||
| 107 | if (!array_key_exists($value, $rgb) || $rgb[$value] < 0 || $rgb[$value] > 255 |
||
| 108 | || !is_numeric($rgb[$value]) |
||
| 109 | ) { |
||
| 110 | exit('Wrong color'); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | return $rgb; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @param $width |
||
| 119 | * @param $color |
||
| 120 | */ |
||
| 121 | public function add_border($width, $color) |
||
| 122 | { |
||
| 123 | $rgb = $this->make_color($color); |
||
| 124 | $allocate = imagecolorallocate($this->image, $rgb['r'], $rgb['g'], $rgb['b']); |
||
| 125 | |||
| 126 | if ($width < 1) { |
||
| 127 | exit('Wrong frame width'); |
||
| 128 | } |
||
| 129 | |||
| 130 | $sizex = $this->width + (2 * $width); |
||
| 131 | $sizey = $this->height + (2 * $width); |
||
| 132 | $new_image = imagecreatetruecolor($sizex, $sizey); |
||
| 133 | |||
| 134 | imagefill($new_image, 0, 0, $allocate); |
||
| 135 | imagecopyresampled($new_image, $this->image, $width, $width, 0, 0, $this->width, $this->height, $this->width, $this->height); |
||
| 136 | |||
| 137 | $this->image = $new_image; |
||
| 138 | $this->width = $sizex; |
||
| 139 | $this->height = $sizey; |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param $text |
||
| 144 | * @param $font |
||
| 145 | * @param $color |
||
| 146 | * @param $x |
||
| 147 | * @param $y |
||
| 148 | */ |
||
| 149 | public function add_text($text, $font, $color, $x, $y) |
||
| 150 | { |
||
| 151 | if ($font < 1 || $font > 5) { |
||
| 152 | exit('Wrong font'); |
||
| 153 | } |
||
| 154 | |||
| 155 | $rgb = $this->make_color($color); |
||
| 156 | $allocate = imagecolorallocate($this->image, $rgb['r'], $rgb['g'], $rgb['b']); |
||
| 157 | $text_width = imagefontwidth($font) * strlen($text); |
||
| 158 | $text_height = imagefontheight($font); |
||
| 159 | |||
| 160 | //Dokoncaj |
||
| 161 | } |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @param $text |
||
| 165 | * @param $size |
||
| 166 | * @param $color |
||
| 167 | * @param $x |
||
| 168 | * @param $y |
||
| 169 | * @param string $font |
||
| 170 | */ |
||
| 171 | public function add_ttf_text($text, $size, $color, $x, $y, $font = './tahoma.ttf') |
||
| 172 | { |
||
| 173 | if (!is_file($font)) { |
||
| 174 | exit('Unknown font'); |
||
| 175 | } |
||
| 176 | |||
| 177 | $rgb = $this->make_color($color); |
||
| 178 | $allocate = imagecolorallocate($this->image, $rgb['r'], $rgb['g'], $rgb['b']); |
||
| 179 | imagettftext($this->image, $size, 0, $x, $y, $allocate, $font, $text); |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @param $location |
||
| 184 | * @param string $quality |
||
| 185 | */ |
||
| 186 | public function save($location, $quality = '80') |
||
| 187 | { |
||
| 188 | imagejpeg($this->image, $location, $quality); |
||
| 189 | imagedestroy($this->image); |
||
| 190 | } |
||
| 191 | } |
||
| 192 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.