@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class httpCache { |
|
| 15 | +class httpCache |
|
| 16 | +{ |
|
| 16 | 17 | const DEFAULT_TYPE = "text/html"; |
| 17 | 18 | const DEFAULT_EXPIRE = 604800; // in seconds |
| 18 | 19 | |
@@ -25,15 +26,20 @@ discard block |
||
| 25 | 26 | * @param integer $expire |
| 26 | 27 | * @param array $headers */ |
| 27 | 28 | |
| 28 | - static function file($file, $type=null, $expire=null, array $headers=null) { |
|
| 29 | + static function file($file, $type=null, $expire=null, array $headers=null) |
|
| 30 | + { |
|
| 29 | 31 | $mtime = @filemtime($file); |
| 30 | - if ($mtime !== false) self::checkMTime($mtime); |
|
| 32 | + if ($mtime !== false) { |
|
| 33 | + self::checkMTime($mtime); |
|
| 34 | + } |
|
| 31 | 35 | |
| 32 | 36 | if ($type === null) { |
| 33 | 37 | $magic = ((substr($type, 0, 1) == "/") || preg_match('/^[a-z]\:/i', $type)) |
| 34 | 38 | ? $type : null; |
| 35 | 39 | $type = file::getMimeType($file, $magic); |
| 36 | - if (!$type) $type = null; |
|
| 40 | + if (!$type) { |
|
| 41 | + $type = null; |
|
| 42 | + } |
|
| 37 | 43 | } |
| 38 | 44 | |
| 39 | 45 | self::content(@file_get_contents($file), $mtime, $type, $expire, $headers, false); |
@@ -47,10 +53,17 @@ discard block |
||
| 47 | 53 | * @param array $headers |
| 48 | 54 | * @param bool $checkMTime */ |
| 49 | 55 | |
| 50 | - static function content($content, $mtime, $type=null, $expire=null, array $headers=null, $checkMTime=true) { |
|
| 51 | - if ($checkMTime) self::checkMTime($mtime); |
|
| 52 | - if ($type === null) $type = self::DEFAULT_TYPE; |
|
| 53 | - if ($expire === null) $expire = self::DEFAULT_EXPIRE; |
|
| 56 | + static function content($content, $mtime, $type=null, $expire=null, array $headers=null, $checkMTime=true) |
|
| 57 | + { |
|
| 58 | + if ($checkMTime) { |
|
| 59 | + self::checkMTime($mtime); |
|
| 60 | + } |
|
| 61 | + if ($type === null) { |
|
| 62 | + $type = self::DEFAULT_TYPE; |
|
| 63 | + } |
|
| 64 | + if ($expire === null) { |
|
| 65 | + $expire = self::DEFAULT_EXPIRE; |
|
| 66 | + } |
|
| 54 | 67 | $size = strlen($content); |
| 55 | 68 | $expires = gmdate("D, d M Y H:i:s", time() + $expire) . " GMT"; |
| 56 | 69 | header("Content-Type: $type"); |
@@ -58,7 +71,9 @@ discard block |
||
| 58 | 71 | header("Cache-Control: max-age=$expire"); |
| 59 | 72 | header("Pragma: !invalid"); |
| 60 | 73 | header("Content-Length: $size"); |
| 61 | - if ($headers !== null) foreach ($headers as $header) header($header); |
|
| 74 | + if ($headers !== null) { |
|
| 75 | + foreach ($headers as $header) header($header); |
|
| 76 | + } |
|
| 62 | 77 | echo $content; |
| 63 | 78 | } |
| 64 | 79 | |
@@ -68,7 +83,8 @@ discard block |
||
| 68 | 83 | * the PHP to be configured as Apache module. |
| 69 | 84 | * @param integer $mtime */ |
| 70 | 85 | |
| 71 | - static function checkMTime($mtime, $sendHeaders=null) { |
|
| 86 | + static function checkMTime($mtime, $sendHeaders=null) |
|
| 87 | + { |
|
| 72 | 88 | header("Last-Modified: " . gmdate("D, d M Y H:i:s", $mtime) . " GMT"); |
| 73 | 89 | |
| 74 | 90 | $headers = function_exists("getallheaders") |
@@ -82,11 +98,12 @@ discard block |
||
| 82 | 98 | $client_mtime = @strtotime($client_mtime[0]); |
| 83 | 99 | if ($client_mtime >= $mtime) { |
| 84 | 100 | header('HTTP/1.1 304 Not Modified'); |
| 85 | - if (is_array($sendHeaders) && count($sendHeaders)) |
|
| 86 | - foreach ($sendHeaders as $header) |
|
| 101 | + if (is_array($sendHeaders) && count($sendHeaders)) { |
|
| 102 | + foreach ($sendHeaders as $header) |
|
| 87 | 103 | header($header); |
| 88 | - elseif ($sendHeaders !== null) |
|
| 89 | - header($sendHeaders); |
|
| 104 | + } elseif ($sendHeaders !== null) { |
|
| 105 | + header($sendHeaders); |
|
| 106 | + } |
|
| 90 | 107 | |
| 91 | 108 | |
| 92 | 109 | die; |
@@ -12,14 +12,20 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class image_gd extends image { |
|
| 15 | +class image_gd extends image |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | |
| 18 | 19 | // ABSTRACT PUBLIC METHODS |
| 19 | 20 | |
| 20 | - public function resize($width, $height) { |
|
| 21 | - if (!$width) $width = 1; |
|
| 22 | - if (!$height) $height = 1; |
|
| 21 | + public function resize($width, $height) |
|
| 22 | + { |
|
| 23 | + if (!$width) { |
|
| 24 | + $width = 1; |
|
| 25 | + } |
|
| 26 | + if (!$height) { |
|
| 27 | + $height = 1; |
|
| 28 | + } |
|
| 23 | 29 | return ( |
| 24 | 30 | (false !== ($img = new image_gd(array($width, $height)))) && |
| 25 | 31 | $img->imageCopyResampled($this) && |
@@ -29,9 +35,11 @@ discard block |
||
| 29 | 35 | ); |
| 30 | 36 | } |
| 31 | 37 | |
| 32 | - public function resizeFit($width, $height, $background=false) { |
|
| 33 | - if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height))) |
|
| 34 | - return true; |
|
| 38 | + public function resizeFit($width, $height, $background=false) |
|
| 39 | + { |
|
| 40 | + if ((!$width && !$height) || (($width == $this->width) && ($height == $this->height))) { |
|
| 41 | + return true; |
|
| 42 | + } |
|
| 35 | 43 | if (!$width || (($height / $width) < ($this->height / $this->width))) { |
| 36 | 44 | $h = $height; |
| 37 | 45 | $w = round(($this->width * $h) / $this->height); |
@@ -42,13 +50,16 @@ discard block |
||
| 42 | 50 | $w = $width; |
| 43 | 51 | $h = $height; |
| 44 | 52 | } |
| 45 | - if (!$w) $w = 1; |
|
| 46 | - if (!$h) $h = 1; |
|
| 47 | - |
|
| 48 | - if ($background === false) |
|
| 49 | - return $this->resize($w, $h); |
|
| 53 | + if (!$w) { |
|
| 54 | + $w = 1; |
|
| 55 | + } |
|
| 56 | + if (!$h) { |
|
| 57 | + $h = 1; |
|
| 58 | + } |
|
| 50 | 59 | |
| 51 | - else { |
|
| 60 | + if ($background === false) { |
|
| 61 | + return $this->resize($w, $h); |
|
| 62 | + } else { |
|
| 52 | 63 | $img = new image_gd(array($width, $height)); |
| 53 | 64 | $x = round(($width - $w) / 2); |
| 54 | 65 | $y = round(($height - $h) / 2); |
@@ -56,8 +67,9 @@ discard block |
||
| 56 | 67 | if ((false === $this->resize($w, $h)) || |
| 57 | 68 | (false === $img->imageFilledRectangle(0, 0, $width, $height, $background)) || |
| 58 | 69 | (false === $img->imageCopyResampled($this->image, $x, $y, 0, 0, $w, $h)) |
| 59 | - ) |
|
| 60 | - return false; |
|
| 70 | + ) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 61 | 73 | |
| 62 | 74 | $this->image = $img->image; |
| 63 | 75 | $this->width = $width; |
@@ -67,41 +79,52 @@ discard block |
||
| 67 | 79 | } |
| 68 | 80 | } |
| 69 | 81 | |
| 70 | - public function resizeCrop($width, $height, $offset=false) { |
|
| 82 | + public function resizeCrop($width, $height, $offset=false) |
|
| 83 | + { |
|
| 71 | 84 | |
| 72 | 85 | if (($this->width / $this->height) > ($width / $height)) { |
| 73 | 86 | $h = $height; |
| 74 | 87 | $w = ($this->width * $h) / $this->height; |
| 75 | 88 | $y = 0; |
| 76 | 89 | if ($offset !== false) { |
| 77 | - if ($offset > 0) |
|
| 78 | - $offset = -$offset; |
|
| 79 | - if (($w + $offset) <= $width) |
|
| 80 | - $offset = $width - $w; |
|
| 90 | + if ($offset > 0) { |
|
| 91 | + $offset = -$offset; |
|
| 92 | + } |
|
| 93 | + if (($w + $offset) <= $width) { |
|
| 94 | + $offset = $width - $w; |
|
| 95 | + } |
|
| 81 | 96 | $x = $offset; |
| 82 | - } else |
|
| 83 | - $x = ($width - $w) / 2; |
|
| 97 | + } else { |
|
| 98 | + $x = ($width - $w) / 2; |
|
| 99 | + } |
|
| 84 | 100 | |
| 85 | 101 | } else { |
| 86 | 102 | $w = $width; |
| 87 | 103 | $h = ($this->height * $w) / $this->width; |
| 88 | 104 | $x = 0; |
| 89 | 105 | if ($offset !== false) { |
| 90 | - if ($offset > 0) |
|
| 91 | - $offset = -$offset; |
|
| 92 | - if (($h + $offset) <= $height) |
|
| 93 | - $offset = $height - $h; |
|
| 106 | + if ($offset > 0) { |
|
| 107 | + $offset = -$offset; |
|
| 108 | + } |
|
| 109 | + if (($h + $offset) <= $height) { |
|
| 110 | + $offset = $height - $h; |
|
| 111 | + } |
|
| 94 | 112 | $y = $offset; |
| 95 | - } else |
|
| 96 | - $y = ($height - $h) / 2; |
|
| 113 | + } else { |
|
| 114 | + $y = ($height - $h) / 2; |
|
| 115 | + } |
|
| 97 | 116 | } |
| 98 | 117 | |
| 99 | 118 | $x = round($x); |
| 100 | 119 | $y = round($y); |
| 101 | 120 | $w = round($w); |
| 102 | 121 | $h = round($h); |
| 103 | - if (!$w) $w = 1; |
|
| 104 | - if (!$h) $h = 1; |
|
| 122 | + if (!$w) { |
|
| 123 | + $w = 1; |
|
| 124 | + } |
|
| 125 | + if (!$h) { |
|
| 126 | + $h = 1; |
|
| 127 | + } |
|
| 105 | 128 | |
| 106 | 129 | $return = ( |
| 107 | 130 | (false !== ($img = new image_gd(array($width, $height))))) && |
@@ -117,50 +140,59 @@ discard block |
||
| 117 | 140 | return $return; |
| 118 | 141 | } |
| 119 | 142 | |
| 120 | - public function rotate($angle, $background="#000000") { |
|
| 143 | + public function rotate($angle, $background="#000000") |
|
| 144 | + { |
|
| 121 | 145 | $angle = -$angle; |
| 122 | 146 | $img = @imagerotate($this->image, $angle, $this->gdColor($background)); |
| 123 | - if ($img === false) |
|
| 124 | - return false; |
|
| 147 | + if ($img === false) { |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 125 | 150 | $this->width = imagesx($img); |
| 126 | 151 | $this->height = imagesy($img); |
| 127 | 152 | $this->image = $img; |
| 128 | 153 | return true; |
| 129 | 154 | } |
| 130 | 155 | |
| 131 | - public function flipHorizontal() { |
|
| 156 | + public function flipHorizontal() |
|
| 157 | + { |
|
| 132 | 158 | $img = imagecreatetruecolor($this->width, $this->height); |
| 133 | 159 | imagealphablending($img, false); |
| 134 | 160 | imagesavealpha($img, true); |
| 135 | - if (imagecopyresampled($img, $this->image, 0, 0, ($this->width - 1), 0, $this->width, $this->height, -$this->width, $this->height)) |
|
| 136 | - $this->image = $img; |
|
| 137 | - else |
|
| 138 | - return false; |
|
| 161 | + if (imagecopyresampled($img, $this->image, 0, 0, ($this->width - 1), 0, $this->width, $this->height, -$this->width, $this->height)) { |
|
| 162 | + $this->image = $img; |
|
| 163 | + } else { |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 139 | 166 | return true; |
| 140 | 167 | } |
| 141 | 168 | |
| 142 | - public function flipVertical() { |
|
| 169 | + public function flipVertical() |
|
| 170 | + { |
|
| 143 | 171 | $img = imagecreatetruecolor($this->width, $this->height); |
| 144 | 172 | imagealphablending($img, false); |
| 145 | 173 | imagesavealpha($img, true); |
| 146 | - if (imagecopyresampled($img, $this->image, 0, 0, 0, ($this->height - 1), $this->width, $this->height, $this->width, -$this->height)) |
|
| 147 | - $this->image = $img; |
|
| 148 | - else |
|
| 149 | - return false; |
|
| 174 | + if (imagecopyresampled($img, $this->image, 0, 0, 0, ($this->height - 1), $this->width, $this->height, $this->width, -$this->height)) { |
|
| 175 | + $this->image = $img; |
|
| 176 | + } else { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 150 | 179 | return true; |
| 151 | 180 | } |
| 152 | 181 | |
| 153 | - public function watermark($file, $left=false, $top=false) { |
|
| 182 | + public function watermark($file, $left=false, $top=false) |
|
| 183 | + { |
|
| 154 | 184 | $info = getimagesize($file); |
| 155 | 185 | list($w, $h, $t) = $info; |
| 156 | - if (!in_array($t, array(IMAGETYPE_PNG, IMAGETYPE_GIF))) |
|
| 157 | - return false; |
|
| 186 | + if (!in_array($t, array(IMAGETYPE_PNG, IMAGETYPE_GIF))) { |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 158 | 189 | $imagecreate = ($t == IMAGETYPE_PNG) ? "imagecreatefrompng" : "imagecreatefromgif"; |
| 159 | 190 | |
| 160 | 191 | if (!@imagealphablending($this->image, true) || |
| 161 | 192 | (false === ($wm = @$imagecreate($file))) |
| 162 | - ) |
|
| 163 | - return false; |
|
| 193 | + ) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 164 | 196 | |
| 165 | 197 | $w = imagesx($wm); |
| 166 | 198 | $h = imagesy($wm); |
@@ -176,28 +208,33 @@ discard block |
||
| 176 | 208 | if ((($x + $w) > $this->width) || |
| 177 | 209 | (($y + $h) > $this->height) || |
| 178 | 210 | ($x < 0) || ($y < 0) |
| 179 | - ) |
|
| 180 | - return false; |
|
| 211 | + ) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 181 | 214 | |
| 182 | - if (($wm === false) || !@imagecopy($this->image, $wm, $x, $y, 0, 0, $w, $h)) |
|
| 183 | - return false; |
|
| 215 | + if (($wm === false) || !@imagecopy($this->image, $wm, $x, $y, 0, 0, $w, $h)) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 184 | 218 | |
| 185 | 219 | @imagealphablending($this->image, false); |
| 186 | 220 | @imagesavealpha($this->image, true); |
| 187 | 221 | return true; |
| 188 | 222 | } |
| 189 | 223 | |
| 190 | - public function output($type='jpeg', array $options=array()) { |
|
| 224 | + public function output($type='jpeg', array $options=array()) |
|
| 225 | + { |
|
| 191 | 226 | $method = "output_$type"; |
| 192 | - if (!method_exists($this, $method)) |
|
| 193 | - return false; |
|
| 227 | + if (!method_exists($this, $method)) { |
|
| 228 | + return false; |
|
| 229 | + } |
|
| 194 | 230 | return $this->$method($options); |
| 195 | 231 | } |
| 196 | 232 | |
| 197 | 233 | |
| 198 | 234 | // ABSTRACT PROTECTED METHODS |
| 199 | 235 | |
| 200 | - protected function getBlankImage($width, $height) { |
|
| 236 | + protected function getBlankImage($width, $height) |
|
| 237 | + { |
|
| 201 | 238 | $img = @imagecreatetruecolor($width, $height); |
| 202 | 239 | // imagealphablending($img, false); |
| 203 | 240 | // imagesavealpha($img, true); |
@@ -207,7 +244,8 @@ discard block |
||
| 207 | 244 | return $img; |
| 208 | 245 | } |
| 209 | 246 | |
| 210 | - protected function getImage($image, &$width, &$height) { |
|
| 247 | + protected function getImage($image, &$width, &$height) |
|
| 248 | + { |
|
| 211 | 249 | |
| 212 | 250 | if (is_resource($image) && (get_resource_type($image) == "gd")) { |
| 213 | 251 | $width = @imagesx($image); |
@@ -227,22 +265,26 @@ discard block |
||
| 227 | 265 | |
| 228 | 266 | return $image; |
| 229 | 267 | |
| 230 | - } else |
|
| 231 | - return false; |
|
| 268 | + } else { |
|
| 269 | + return false; |
|
| 270 | + } |
|
| 232 | 271 | } |
| 233 | 272 | |
| 234 | 273 | |
| 235 | 274 | // PSEUDO-ABSTRACT STATIC METHODS |
| 236 | 275 | |
| 237 | - static function available() { |
|
| 276 | + static function available() |
|
| 277 | + { |
|
| 238 | 278 | return function_exists("imagecreatefromjpeg"); |
| 239 | 279 | } |
| 240 | 280 | |
| 241 | - static function checkImage($file) { |
|
| 281 | + static function checkImage($file) |
|
| 282 | + { |
|
| 242 | 283 | if (!is_string($file) || |
| 243 | 284 | ((false === (list($width, $height, $t) = @getimagesize($file)))) |
| 244 | - ) |
|
| 245 | - return false; |
|
| 285 | + ) { |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 246 | 288 | |
| 247 | 289 | $img = |
| 248 | 290 | ($t == IMAGETYPE_GIF) ? @imagecreatefromgif($file) : ( |
@@ -258,34 +300,41 @@ discard block |
||
| 258 | 300 | |
| 259 | 301 | // OWN METHODS |
| 260 | 302 | |
| 261 | - protected function output_png(array $options=array()) { |
|
| 303 | + protected function output_png(array $options=array()) |
|
| 304 | + { |
|
| 262 | 305 | $file = isset($options['file']) ? $options['file'] : null; |
| 263 | 306 | $quality = isset($options['quality']) ? $options['quality'] : null; |
| 264 | 307 | $filters = isset($options['filters']) ? $options['filters'] : null; |
| 265 | - if (($file === null) && !headers_sent()) |
|
| 266 | - header("Content-Type: image/png"); |
|
| 308 | + if (($file === null) && !headers_sent()) { |
|
| 309 | + header("Content-Type: image/png"); |
|
| 310 | + } |
|
| 267 | 311 | @imagesavealpha($this->image, true); |
| 268 | 312 | return imagepng($this->image, $file, $quality, $filters); |
| 269 | 313 | } |
| 270 | 314 | |
| 271 | - protected function output_jpeg(array $options=array()) { |
|
| 315 | + protected function output_jpeg(array $options=array()) |
|
| 316 | + { |
|
| 272 | 317 | $file = isset($options['file']) ? $options['file'] : null; |
| 273 | 318 | $quality = isset($options['quality']) |
| 274 | 319 | ? $options['quality'] |
| 275 | 320 | : self::DEFAULT_JPEG_QUALITY; |
| 276 | - if (($file === null) && !headers_sent()) |
|
| 277 | - header("Content-Type: image/jpeg"); |
|
| 321 | + if (($file === null) && !headers_sent()) { |
|
| 322 | + header("Content-Type: image/jpeg"); |
|
| 323 | + } |
|
| 278 | 324 | return imagejpeg($this->image, $file, $quality); |
| 279 | 325 | } |
| 280 | 326 | |
| 281 | - protected function output_gif(array $options=array()) { |
|
| 327 | + protected function output_gif(array $options=array()) |
|
| 328 | + { |
|
| 282 | 329 | $file = isset($options['file']) ? $options['file'] : null; |
| 283 | - if (isset($options['file']) && !headers_sent()) |
|
| 284 | - header("Content-Type: image/gif"); |
|
| 330 | + if (isset($options['file']) && !headers_sent()) { |
|
| 331 | + header("Content-Type: image/gif"); |
|
| 332 | + } |
|
| 285 | 333 | return imagegif($this->image, $file); |
| 286 | 334 | } |
| 287 | 335 | |
| 288 | - protected function gdColor() { |
|
| 336 | + protected function gdColor() |
|
| 337 | + { |
|
| 289 | 338 | $args = func_get_args(); |
| 290 | 339 | |
| 291 | 340 | $exprRGB = '/^rgb\(\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\,\s*(\d{1,3})\s*\)$/i'; |
@@ -293,8 +342,9 @@ discard block |
||
| 293 | 342 | $exprHex2 = '/^\#?([0-9a-f])([0-9a-f])([0-9a-f])$/i'; |
| 294 | 343 | $exprByte = '/^([01]?\d?\d|2[0-4]\d|25[0-5])$/'; |
| 295 | 344 | |
| 296 | - if (!isset($args[0])) |
|
| 297 | - return false; |
|
| 345 | + if (!isset($args[0])) { |
|
| 346 | + return false; |
|
| 347 | + } |
|
| 298 | 348 | |
| 299 | 349 | if (count($args[0]) == 3) { |
| 300 | 350 | list($r, $g, $b) = $args[0]; |
@@ -321,15 +371,19 @@ discard block |
||
| 321 | 371 | ) { |
| 322 | 372 | list($r, $g, $b) = $args; |
| 323 | 373 | |
| 324 | - } else |
|
| 325 | - return false; |
|
| 374 | + } else { |
|
| 375 | + return false; |
|
| 376 | + } |
|
| 326 | 377 | |
| 327 | 378 | return imagecolorallocate($this->image, $r, $g, $b); |
| 328 | 379 | } |
| 329 | 380 | |
| 330 | - protected function imageFilledRectangle($x1, $y1, $x2, $y2, $color) { |
|
| 381 | + protected function imageFilledRectangle($x1, $y1, $x2, $y2, $color) |
|
| 382 | + { |
|
| 331 | 383 | $color = $this->gdColor($color); |
| 332 | - if ($color === false) return false; |
|
| 384 | + if ($color === false) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 333 | 387 | return imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color); |
| 334 | 388 | } |
| 335 | 389 | |
@@ -338,15 +392,24 @@ discard block |
||
| 338 | 392 | ) { |
| 339 | 393 | $imageDetails = $this->buildImage($src); |
| 340 | 394 | |
| 341 | - if ($imageDetails === false) |
|
| 342 | - return false; |
|
| 395 | + if ($imageDetails === false) { |
|
| 396 | + return false; |
|
| 397 | + } |
|
| 343 | 398 | |
| 344 | 399 | list($src, $srcWidth, $srcHeight) = $imageDetails; |
| 345 | 400 | |
| 346 | - if (is_null($dstW)) $dstW = $this->width - $dstW; |
|
| 347 | - if (is_null($dstH)) $dstH = $this->height - $dstY; |
|
| 348 | - if (is_null($srcW)) $srcW = $srcWidth - $srcX; |
|
| 349 | - if (is_null($srcH)) $srcH = $srcHeight - $srcY; |
|
| 401 | + if (is_null($dstW)) { |
|
| 402 | + $dstW = $this->width - $dstW; |
|
| 403 | + } |
|
| 404 | + if (is_null($dstH)) { |
|
| 405 | + $dstH = $this->height - $dstY; |
|
| 406 | + } |
|
| 407 | + if (is_null($srcW)) { |
|
| 408 | + $srcW = $srcWidth - $srcX; |
|
| 409 | + } |
|
| 410 | + if (is_null($srcH)) { |
|
| 411 | + $srcH = $srcHeight - $srcY; |
|
| 412 | + } |
|
| 350 | 413 | return imageCopyResampled($this->image, $src, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH); |
| 351 | 414 | } |
| 352 | 415 | } |
@@ -12,13 +12,15 @@ discard block |
||
| 12 | 12 | * @link http://kcfinder.sunhater.com |
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | -class text { |
|
| 15 | +class text |
|
| 16 | +{ |
|
| 16 | 17 | |
| 17 | 18 | /** Replace repeated white spaces to single space |
| 18 | 19 | * @param string $string |
| 19 | 20 | * @return string */ |
| 20 | 21 | |
| 21 | - static function clearWhitespaces($string) { |
|
| 22 | + static function clearWhitespaces($string) |
|
| 23 | + { |
|
| 22 | 24 | return trim(preg_replace('/\s+/s', " ", $string)); |
| 23 | 25 | } |
| 24 | 26 | |
@@ -26,7 +28,8 @@ discard block |
||
| 26 | 28 | * @param string $string |
| 27 | 29 | * @return string */ |
| 28 | 30 | |
| 29 | - static function htmlValue($string) { |
|
| 31 | + static function htmlValue($string) |
|
| 32 | + { |
|
| 30 | 33 | return |
| 31 | 34 | str_replace('"', """, |
| 32 | 35 | str_replace("'", ''', |
@@ -39,7 +42,8 @@ discard block |
||
| 39 | 42 | * @param string $string |
| 40 | 43 | * @return string */ |
| 41 | 44 | |
| 42 | - static function jsValue($string) { |
|
| 45 | + static function jsValue($string) |
|
| 46 | + { |
|
| 43 | 47 | return |
| 44 | 48 | preg_replace('/\r?\n/', "\\n", |
| 45 | 49 | str_replace('"', "\\\"", |
@@ -52,10 +56,12 @@ discard block |
||
| 52 | 56 | * @param string $string |
| 53 | 57 | * @param bool $cdata */ |
| 54 | 58 | |
| 55 | - static function xmlData($string, $cdata=false) { |
|
| 59 | + static function xmlData($string, $cdata=false) |
|
| 60 | + { |
|
| 56 | 61 | $string = str_replace("]]>", "]]]]><![CDATA[>", $string); |
| 57 | - if (!$cdata) |
|
| 58 | - $string = "<![CDATA[$string]]>"; |
|
| 62 | + if (!$cdata) { |
|
| 63 | + $string = "<![CDATA[$string]]>"; |
|
| 64 | + } |
|
| 59 | 65 | return $string; |
| 60 | 66 | } |
| 61 | 67 | |
@@ -63,7 +69,8 @@ discard block |
||
| 63 | 69 | * @param string $code |
| 64 | 70 | * @return string */ |
| 65 | 71 | |
| 66 | - static function compressCSS($code) { |
|
| 72 | + static function compressCSS($code) |
|
| 73 | + { |
|
| 67 | 74 | $code = self::clearWhitespaces($code); |
| 68 | 75 | $code = preg_replace('/ ?\{ ?/', "{", $code); |
| 69 | 76 | $code = preg_replace('/ ?\} ?/', "}", $code); |
@@ -13,20 +13,23 @@ discard block |
||
| 13 | 13 | * @link http://kcfinder.sunhater.com |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | -class zipFolder { |
|
| 16 | +class zipFolder |
|
| 17 | +{ |
|
| 17 | 18 | protected $zip; |
| 18 | 19 | protected $root; |
| 19 | 20 | protected $ignored; |
| 20 | 21 | |
| 21 | - function __construct($file, $folder, $ignored=null) { |
|
| 22 | + function __construct($file, $folder, $ignored=null) |
|
| 23 | + { |
|
| 22 | 24 | $this->zip = new ZipArchive(); |
| 23 | 25 | |
| 24 | 26 | $this->ignored = is_array($ignored) |
| 25 | 27 | ? $ignored |
| 26 | 28 | : ($ignored ? array($ignored) : array()); |
| 27 | 29 | |
| 28 | - if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) |
|
| 29 | - throw new Exception("cannot open <$file>\n"); |
|
| 30 | + if ($this->zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) { |
|
| 31 | + throw new Exception("cannot open <$file>\n"); |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | 34 | $folder = rtrim($folder, '/'); |
| 32 | 35 | |
@@ -39,19 +42,22 @@ discard block |
||
| 39 | 42 | $this->zip->close(); |
| 40 | 43 | } |
| 41 | 44 | |
| 42 | - function zip($folder, $parent=null) { |
|
| 45 | + function zip($folder, $parent=null) |
|
| 46 | + { |
|
| 43 | 47 | $full_path = "{$this->root}$parent$folder"; |
| 44 | 48 | $zip_path = "$parent$folder"; |
| 45 | 49 | $this->zip->addEmptyDir($zip_path); |
| 46 | 50 | $dir = new DirectoryIterator($full_path); |
| 47 | - foreach ($dir as $file) |
|
| 48 | - if (!$file->isDot()) { |
|
| 51 | + foreach ($dir as $file) { |
|
| 52 | + if (!$file->isDot()) { |
|
| 49 | 53 | $filename = $file->getFilename(); |
| 54 | + } |
|
| 50 | 55 | if (!in_array($filename, $this->ignored)) { |
| 51 | - if ($file->isDir()) |
|
| 52 | - $this->zip($filename, "$zip_path/"); |
|
| 53 | - else |
|
| 54 | - $this->zip->addFile("$full_path/$filename", "$zip_path/$filename"); |
|
| 56 | + if ($file->isDir()) { |
|
| 57 | + $this->zip($filename, "$zip_path/"); |
|
| 58 | + } else { |
|
| 59 | + $this->zip->addFile("$full_path/$filename", "$zip_path/$filename"); |
|
| 60 | + } |
|
| 55 | 61 | } |
| 56 | 62 | } |
| 57 | 63 | } |
@@ -14,14 +14,19 @@ |
||
| 14 | 14 | |
| 15 | 15 | require "core/autoload.php"; // Init MODX |
| 16 | 16 | |
| 17 | -function returnNoPermissionsMessage($role) { |
|
| 17 | +function returnNoPermissionsMessage($role) |
|
| 18 | +{ |
|
| 18 | 19 | global $_lang; |
| 19 | 20 | echo sprintf($_lang['files_management_no_permission'], $role); |
| 20 | 21 | exit; |
| 21 | 22 | } |
| 22 | 23 | |
| 23 | -if( $_GET['type'] == 'images' && !$modx->hasPermission('file_manager') && !$modx->hasPermission('assets_images')) returnNoPermissionsMessage('assets_images'); |
|
| 24 | -if( $_GET['type'] == 'files' && !$modx->hasPermission('file_manager') && !$modx->hasPermission('assets_files')) returnNoPermissionsMessage('assets_files'); |
|
| 24 | +if( $_GET['type'] == 'images' && !$modx->hasPermission('file_manager') && !$modx->hasPermission('assets_images')) { |
|
| 25 | + returnNoPermissionsMessage('assets_images'); |
|
| 26 | +} |
|
| 27 | +if( $_GET['type'] == 'files' && !$modx->hasPermission('file_manager') && !$modx->hasPermission('assets_files')) { |
|
| 28 | + returnNoPermissionsMessage('assets_files'); |
|
| 29 | +} |
|
| 25 | 30 | |
| 26 | 31 | $browser = new browser($modx); |
| 27 | 32 | $browser->action(); |
@@ -3,9 +3,11 @@ |
||
| 3 | 3 | |
| 4 | 4 | $modx->addSnippet('hasPermission','return $modx->hasPermission($key);');
|
| 5 | 5 | |
| 6 | -if($modx->hasPermission('new_template') || $modx->hasPermission('edit_template') || $modx->hasPermission('new_snippet') || $modx->hasPermission('edit_snippet') || $modx->hasPermission('new_plugin') || $modx->hasPermission('edit_plugin') || $modx->hasPermission('manage_metatags'))
|
|
| 7 | - $hasAnyPermission = 1; |
|
| 8 | -else $hasAnyPermission = 0; |
|
| 6 | +if($modx->hasPermission('new_template') || $modx->hasPermission('edit_template') || $modx->hasPermission('new_snippet') || $modx->hasPermission('edit_snippet') || $modx->hasPermission('new_plugin') || $modx->hasPermission('edit_plugin') || $modx->hasPermission('manage_metatags')) { |
|
| 7 | + $hasAnyPermission = 1; |
|
| 8 | +} else { |
|
| 9 | + $hasAnyPermission = 0; |
|
| 10 | +} |
|
| 9 | 11 | $modx->addSnippet('hasAnyPermission','global $hasAnyPermission; return $hasAnyPermission;');
|
| 10 | 12 | $modx->addSnippet('getLoginUserName','return $modx->getLoginUserName();');
|
| 11 | 13 | $code = 'global $_lang;return $_SESSION["nrtotalmessages"] ? sprintf($_lang["welcome_messages"], $_SESSION["nrtotalmessages"], \'<span style="color:red;">\' . $_SESSION["nrnewmessages"] . "</span>") : $_lang["messages_no_messages"];'; |
@@ -7,11 +7,11 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | $modx->db->connect(); |
| 9 | 9 | |
| 10 | -if (empty ($modx->config)) {
|
|
| 10 | +if (empty ($modx->config)) { |
|
| 11 | 11 | $modx->getSettings(); |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | -if (!isset($_SESSION['mgrValidated']) || !isset($_SERVER['HTTP_X_REQUESTED_WITH']) || (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') || ($_SERVER['REQUEST_METHOD'] != 'POST')) {
|
|
| 14 | +if (!isset($_SESSION['mgrValidated']) || !isset($_SERVER['HTTP_X_REQUESTED_WITH']) || (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') || ($_SERVER['REQUEST_METHOD'] != 'POST')) { |
|
| 15 | 15 | $modx->sendErrorPage(); |
| 16 | 16 | } |
| 17 | 17 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | $_lang = array(); |
| 22 | 22 | include_once MODX_MANAGER_PATH . '/includes/lang/english.inc.php'; |
| 23 | -if ($modx->config['manager_language'] != 'english') {
|
|
| 23 | +if ($modx->config['manager_language'] != 'english') { |
|
| 24 | 24 | include_once MODX_MANAGER_PATH . '/includes/lang/' . $modx->config['manager_language'] . '.inc.php'; |
| 25 | 25 | } |
| 26 | 26 | include_once MODX_MANAGER_PATH . '/media/style/' . $modx->config['manager_theme'] . '/style.php'; |
@@ -33,12 +33,12 @@ discard block |
||
| 33 | 33 | // set limit sql query |
| 34 | 34 | $limit = !empty($modx->config['number_of_results']) ? (int) $modx->config['number_of_results'] : 100; |
| 35 | 35 | |
| 36 | -if (isset($action)) {
|
|
| 37 | - switch ($action) {
|
|
| 36 | +if (isset($action)) { |
|
| 37 | + switch ($action) { |
|
| 38 | 38 | |
| 39 | 39 | case '1': {
|
| 40 | 40 | |
| 41 | - switch ($frame) {
|
|
| 41 | + switch ($frame) { |
|
| 42 | 42 | case 'nodes': |
| 43 | 43 | include_once MODX_MANAGER_PATH . '/frames/nodes.php'; |
| 44 | 44 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $elements = isset($_REQUEST['elements']) && is_scalar($_REQUEST['elements']) ? htmlentities($_REQUEST['elements']) : ''; |
| 54 | 54 | |
| 55 | - if ($elements) {
|
|
| 55 | + if ($elements) { |
|
| 56 | 56 | $output = ''; |
| 57 | 57 | $items = ''; |
| 58 | 58 | $sql = ''; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $sqlLike = $filter ? 'WHERE t1.name LIKE "' . $modx->db->escape($filter) . '%"' : ''; |
| 62 | 62 | $sqlLimit = $sqlLike ? '' : 'LIMIT ' . $limit; |
| 63 | 63 | |
| 64 | - switch ($elements) {
|
|
| 64 | + switch ($elements) { |
|
| 65 | 65 | case 'element_templates': |
| 66 | 66 | $a = 16; |
| 67 | 67 | $sqlLike = $filter ? 'WHERE t1.templatename LIKE "' . $modx->db->escape($filter) . '%"' : ''; |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | ORDER BY t1.templatename ASC |
| 72 | 72 | ' . $sqlLimit); |
| 73 | 73 | |
| 74 | - if ($modx->hasPermission('new_template')) {
|
|
| 74 | + if ($modx->hasPermission('new_template')) { |
|
| 75 | 75 | $output .= '<li><a id="a_19" href="index.php?a=19" target="main"><i class="fa fa-plus"></i>' . $_lang['new_template'] . '</a></li>'; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | ORDER BY t1.name ASC |
| 88 | 88 | ' . $sqlLimit); |
| 89 | 89 | |
| 90 | - if ($modx->hasPermission('edit_template') && $modx->hasPermission('edit_snippet') && $modx->hasPermission('edit_chunk') && $modx->hasPermission('edit_plugin')) {
|
|
| 90 | + if ($modx->hasPermission('edit_template') && $modx->hasPermission('edit_snippet') && $modx->hasPermission('edit_chunk') && $modx->hasPermission('edit_plugin')) { |
|
| 91 | 91 | $output .= '<li><a id="a_300" href="index.php?a=300" target="main"><i class="fa fa-plus"></i>' . $_lang['new_tmplvars'] . '</a></li>'; |
| 92 | 92 | } |
| 93 | 93 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | ORDER BY t1.name ASC |
| 102 | 102 | ' . $sqlLimit); |
| 103 | 103 | |
| 104 | - if ($modx->hasPermission('new_chunk')) {
|
|
| 104 | + if ($modx->hasPermission('new_chunk')) { |
|
| 105 | 105 | $output .= '<li><a id="a_77" href="index.php?a=77" target="main"><i class="fa fa-plus"></i>' . $_lang['new_htmlsnippet'] . '</a></li>'; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | ORDER BY t1.name ASC |
| 116 | 116 | ' . $sqlLimit); |
| 117 | 117 | |
| 118 | - if ($modx->hasPermission('new_snippet')) {
|
|
| 118 | + if ($modx->hasPermission('new_snippet')) { |
|
| 119 | 119 | $output .= '<li><a id="a_23" href="index.php?a=23" target="main"><i class="fa fa-plus"></i>' . $_lang['new_snippet'] . '</a></li>'; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -129,19 +129,19 @@ discard block |
||
| 129 | 129 | ORDER BY t1.name ASC |
| 130 | 130 | ' . $sqlLimit); |
| 131 | 131 | |
| 132 | - if ($modx->hasPermission('new_plugin')) {
|
|
| 132 | + if ($modx->hasPermission('new_plugin')) { |
|
| 133 | 133 | $output .= '<li><a id="a_101" href="index.php?a=101" target="main"><i class="fa fa-plus"></i>' . $_lang['new_plugin'] . '</a></li>'; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | break; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - if ($count = $modx->db->getRecordCount($sql)) {
|
|
| 140 | - if ($count == $limit) {
|
|
| 139 | + if ($count = $modx->db->getRecordCount($sql)) { |
|
| 140 | + if ($count == $limit) { |
|
| 141 | 141 | $output .= '<li class="item-input"><input type="text" name="filter" class="dropdown-item form-control form-control-sm" autocomplete="off" /></li>'; |
| 142 | 142 | } |
| 143 | - while ($row = $modx->db->getRow($sql)) {
|
|
| 144 | - if (($row['disabled'] || $row['locked']) && $role != 1) {
|
|
| 143 | + while ($row = $modx->db->getRow($sql)) { |
|
| 144 | + if (($row['disabled'] || $row['locked']) && $role != 1) { |
|
| 145 | 145 | continue; |
| 146 | 146 | } |
| 147 | 147 | |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - if (isset($_REQUEST['filter'])) {
|
|
| 152 | + if (isset($_REQUEST['filter'])) { |
|
| 153 | 153 | $output = $items; |
| 154 | - } else {
|
|
| 154 | + } else { |
|
| 155 | 155 | $output .= $items; |
| 156 | 156 | } |
| 157 | 157 | |
@@ -176,22 +176,22 @@ discard block |
||
| 176 | 176 | ORDER BY t1.username ASC |
| 177 | 177 | ' . $sqlLimit); |
| 178 | 178 | |
| 179 | - if ($modx->hasPermission('new_user')) {
|
|
| 179 | + if ($modx->hasPermission('new_user')) { |
|
| 180 | 180 | $output .= '<li><a id="a_11" href="index.php?a=11" target="main"><i class="fa fa-plus"></i>' . $_lang['new_user'] . '</a></li>'; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ($count = $modx->db->getRecordCount($sql)) {
|
|
| 184 | - if ($count == $limit) {
|
|
| 183 | + if ($count = $modx->db->getRecordCount($sql)) { |
|
| 184 | + if ($count == $limit) { |
|
| 185 | 185 | $output .= '<li class="item-input"><input type="text" name="filter" class="dropdown-item form-control form-control-sm" autocomplete="off" /></li>'; |
| 186 | 186 | } |
| 187 | - while ($row = $modx->db->getRow($sql)) {
|
|
| 187 | + while ($row = $modx->db->getRow($sql)) { |
|
| 188 | 188 | $items .= '<li class="item ' . ($row['blocked'] ? 'disabled' : '') . '"><a id="a_' . $a . '__id_' . $row['id'] . '" href="index.php?a=' . $a . '&id=' . $row['id'] . '" target="main">' . $row['name'] . ' <small>(' . $row['id'] . ')</small></a></li>';
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if (isset($_REQUEST['filter'])) {
|
|
| 192 | + if (isset($_REQUEST['filter'])) { |
|
| 193 | 193 | $output = $items; |
| 194 | - } else {
|
|
| 194 | + } else { |
|
| 195 | 195 | $output .= $items; |
| 196 | 196 | } |
| 197 | 197 | |
@@ -215,22 +215,22 @@ discard block |
||
| 215 | 215 | ORDER BY t1.username ASC |
| 216 | 216 | ' . $sqlLimit); |
| 217 | 217 | |
| 218 | - if ($modx->hasPermission('new_web_user')) {
|
|
| 218 | + if ($modx->hasPermission('new_web_user')) { |
|
| 219 | 219 | $output .= '<li><a id="a_87" href="index.php?a=87" target="main"><i class="fa fa-plus"></i>' . $_lang['new_web_user'] . '</a></li>'; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - if ($count = $modx->db->getRecordCount($sql)) {
|
|
| 223 | - if ($count == $limit) {
|
|
| 222 | + if ($count = $modx->db->getRecordCount($sql)) { |
|
| 223 | + if ($count == $limit) { |
|
| 224 | 224 | $output .= '<li class="item-input"><input type="text" name="filter" class="dropdown-item form-control form-control-sm" autocomplete="off" /></li>'; |
| 225 | 225 | } |
| 226 | - while ($row = $modx->db->getRow($sql)) {
|
|
| 226 | + while ($row = $modx->db->getRow($sql)) { |
|
| 227 | 227 | $items .= '<li class="item ' . ($row['blocked'] ? 'disabled' : '') . '"><a id="a_' . $a . '__id_' . $row['id'] . '" href="index.php?a=' . $a . '&id=' . $row['id'] . '" target="main">' . $row['name'] . ' <small>(' . $row['id'] . ')</small></a></li>';
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if (isset($_REQUEST['filter'])) {
|
|
| 231 | + if (isset($_REQUEST['filter'])) { |
|
| 232 | 232 | $output = $items; |
| 233 | - } else {
|
|
| 233 | + } else { |
|
| 234 | 234 | $output .= $items; |
| 235 | 235 | } |
| 236 | 236 | |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | $type = isset($_REQUEST['type']) && is_scalar($_REQUEST['type']) ? $modx->db->escape($_REQUEST['type']) : false; |
| 245 | 245 | $contextmenu = ''; |
| 246 | 246 | |
| 247 | - if ($role && $name && $type) {
|
|
| 248 | - switch ($type) {
|
|
| 247 | + if ($role && $name && $type) { |
|
| 248 | + switch ($type) { |
|
| 249 | 249 | case 'Snippet': |
| 250 | 250 | case 'SnippetNoCache': {
|
| 251 | 251 | |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | WHERE name="' . $name . '" |
| 255 | 255 | LIMIT 1'); |
| 256 | 256 | |
| 257 | - if ($modx->db->getRecordCount($sql)) {
|
|
| 257 | + if ($modx->db->getRecordCount($sql)) { |
|
| 258 | 258 | $row = $modx->db->getRow($sql); |
| 259 | 259 | $contextmenu = array( |
| 260 | 260 | 'header' => array( |
@@ -265,13 +265,13 @@ discard block |
||
| 265 | 265 | 'url' => "index.php?a=22&id=" . $row['id'] |
| 266 | 266 | ) |
| 267 | 267 | ); |
| 268 | - if (!empty($row['description'])) {
|
|
| 268 | + if (!empty($row['description'])) { |
|
| 269 | 269 | $contextmenu['seperator'] = ''; |
| 270 | 270 | $contextmenu['description'] = array( |
| 271 | 271 | 'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description'] |
| 272 | 272 | ); |
| 273 | 273 | } |
| 274 | - } else {
|
|
| 274 | + } else { |
|
| 275 | 275 | $contextmenu = array( |
| 276 | 276 | 'header' => array( |
| 277 | 277 | 'innerHTML' => '<i class="fa fa-code"></i> ' . $name |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | WHERE name="' . $name . '" |
| 293 | 293 | LIMIT 1'); |
| 294 | 294 | |
| 295 | - if ($modx->db->getRecordCount($sql)) {
|
|
| 295 | + if ($modx->db->getRecordCount($sql)) { |
|
| 296 | 296 | $row = $modx->db->getRow($sql); |
| 297 | 297 | $contextmenu = array( |
| 298 | 298 | 'header' => array( |
@@ -303,13 +303,13 @@ discard block |
||
| 303 | 303 | 'url' => "index.php?a=78&id=" . $row['id'] |
| 304 | 304 | ) |
| 305 | 305 | ); |
| 306 | - if (!empty($row['description'])) {
|
|
| 306 | + if (!empty($row['description'])) { |
|
| 307 | 307 | $contextmenu['seperator'] = ''; |
| 308 | 308 | $contextmenu['description'] = array( |
| 309 | 309 | 'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description'] |
| 310 | 310 | ); |
| 311 | 311 | } |
| 312 | - } else {
|
|
| 312 | + } else { |
|
| 313 | 313 | $contextmenu = array( |
| 314 | 314 | 'header' => array( |
| 315 | 315 | 'innerHTML' => '<i class="fa fa-th-large"></i> ' . $name |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | WHERE name="' . $name . '" |
| 330 | 330 | LIMIT 1'); |
| 331 | 331 | |
| 332 | - if ($modx->db->getRecordCount($sql)) {
|
|
| 332 | + if ($modx->db->getRecordCount($sql)) { |
|
| 333 | 333 | $row = $modx->db->getRow($sql); |
| 334 | 334 | $contextmenu = array( |
| 335 | 335 | 'header' => array( |
@@ -340,20 +340,20 @@ discard block |
||
| 340 | 340 | 'url' => "index.php?a=78&id=" . $row['id'] |
| 341 | 341 | ) |
| 342 | 342 | ); |
| 343 | - if (!empty($row['description'])) {
|
|
| 343 | + if (!empty($row['description'])) { |
|
| 344 | 344 | $contextmenu['seperator'] = ''; |
| 345 | 345 | $contextmenu['description'] = array( |
| 346 | 346 | 'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description'] |
| 347 | 347 | ); |
| 348 | 348 | } |
| 349 | - } else {
|
|
| 349 | + } else { |
|
| 350 | 350 | |
| 351 | 351 | $sql = $modx->db->query('SELECT *
|
| 352 | 352 | FROM ' . $modx->getFullTableName('site_snippets') . '
|
| 353 | 353 | WHERE name="' . $name . '" |
| 354 | 354 | LIMIT 1'); |
| 355 | 355 | |
| 356 | - if ($modx->db->getRecordCount($sql)) {
|
|
| 356 | + if ($modx->db->getRecordCount($sql)) { |
|
| 357 | 357 | $row = $modx->db->getRow($sql); |
| 358 | 358 | $contextmenu = array( |
| 359 | 359 | 'header' => array( |
@@ -364,13 +364,13 @@ discard block |
||
| 364 | 364 | 'url' => "index.php?a=22&id=" . $row['id'] |
| 365 | 365 | ) |
| 366 | 366 | ); |
| 367 | - if (!empty($row['description'])) {
|
|
| 367 | + if (!empty($row['description'])) { |
|
| 368 | 368 | $contextmenu['seperator'] = ''; |
| 369 | 369 | $contextmenu['description'] = array( |
| 370 | 370 | 'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description'] |
| 371 | 371 | ); |
| 372 | 372 | } |
| 373 | - } else {
|
|
| 373 | + } else { |
|
| 374 | 374 | $contextmenu = array( |
| 375 | 375 | 'header' => array( |
| 376 | 376 | 'innerHTML' => '<i class="fa fa-code"></i> ' . $name |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | 'alias_visible' |
| 433 | 433 | ); |
| 434 | 434 | |
| 435 | - if (in_array($name, $default_field)) {
|
|
| 435 | + if (in_array($name, $default_field)) { |
|
| 436 | 436 | return; |
| 437 | 437 | } |
| 438 | 438 | |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | WHERE name="' . $name . '" |
| 442 | 442 | LIMIT 1'); |
| 443 | 443 | |
| 444 | - if ($modx->db->getRecordCount($sql)) {
|
|
| 444 | + if ($modx->db->getRecordCount($sql)) { |
|
| 445 | 445 | $row = $modx->db->getRow($sql); |
| 446 | 446 | $contextmenu = array( |
| 447 | 447 | 'header' => array( |
@@ -452,13 +452,13 @@ discard block |
||
| 452 | 452 | 'url' => "index.php?a=301&id=" . $row['id'] |
| 453 | 453 | ) |
| 454 | 454 | ); |
| 455 | - if (!empty($row['description'])) {
|
|
| 455 | + if (!empty($row['description'])) { |
|
| 456 | 456 | $contextmenu['seperator'] = ''; |
| 457 | 457 | $contextmenu['description'] = array( |
| 458 | 458 | 'innerHTML' => '<i class="fa fa-info"></i> ' . $row['description'] |
| 459 | 459 | ); |
| 460 | 460 | } |
| 461 | - } else {
|
|
| 461 | + } else { |
|
| 462 | 462 | $contextmenu = array( |
| 463 | 463 | 'header' => array( |
| 464 | 464 | 'innerHTML' => '<i class="fa fa-list-alt"></i> ' . $name |
@@ -483,13 +483,13 @@ discard block |
||
| 483 | 483 | case 'movedocument' : {
|
| 484 | 484 | $json = array(); |
| 485 | 485 | |
| 486 | - if ($modx->hasPermission('new_document') && $modx->hasPermission('edit_document') && $modx->hasPermission('save_document')) {
|
|
| 486 | + if ($modx->hasPermission('new_document') && $modx->hasPermission('edit_document') && $modx->hasPermission('save_document')) { |
|
| 487 | 487 | $id = !empty($_REQUEST['id']) ? (int)$_REQUEST['id'] : ''; |
| 488 | 488 | $parent = isset($_REQUEST['parent']) ? (int)$_REQUEST['parent'] : 0; |
| 489 | 489 | $menuindex = isset($_REQUEST['menuindex']) && is_scalar($_REQUEST['menuindex']) ? $_REQUEST['menuindex'] : 0; |
| 490 | 490 | |
| 491 | 491 | // set parent |
| 492 | - if ($id && $parent >= 0) {
|
|
| 492 | + if ($id && $parent >= 0) { |
|
| 493 | 493 | |
| 494 | 494 | // find older parent |
| 495 | 495 | $parentOld = $modx->db->getValue($modx->db->select('parent', $modx->getFullTableName('site_content'), 'id=' . $id));
|
@@ -500,31 +500,31 @@ discard block |
||
| 500 | 500 | 'new_parent' => $parent, |
| 501 | 501 | ]); |
| 502 | 502 | |
| 503 | - if (is_array($eventOut) && count($eventOut) > 0) {
|
|
| 503 | + if (is_array($eventOut) && count($eventOut) > 0) { |
|
| 504 | 504 | $eventParent = array_pop($eventOut); |
| 505 | 505 | |
| 506 | - if ($eventParent == $parentOld) {
|
|
| 506 | + if ($eventParent == $parentOld) { |
|
| 507 | 507 | $json['errors'] = $_lang['error_movedocument2']; |
| 508 | - } else {
|
|
| 508 | + } else { |
|
| 509 | 509 | $parent = $eventParent; |
| 510 | 510 | } |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - if (empty($json['errors'])) {
|
|
| 513 | + if (empty($json['errors'])) { |
|
| 514 | 514 | // check privileges user for move docs |
| 515 | - if (!empty($modx->config['tree_show_protected']) && $role != 1) {
|
|
| 515 | + if (!empty($modx->config['tree_show_protected']) && $role != 1) { |
|
| 516 | 516 | $sql = $modx->db->select('*', $modx->getFullTableName('document_groups'), 'document IN(' . $id . ',' . $parent . ',' . $parentOld . ')');
|
| 517 | - if ($modx->db->getRecordCount($sql)) {
|
|
| 517 | + if ($modx->db->getRecordCount($sql)) { |
|
| 518 | 518 | $document_groups = array(); |
| 519 | - while ($row = $modx->db->getRow($sql)) {
|
|
| 519 | + while ($row = $modx->db->getRow($sql)) { |
|
| 520 | 520 | $document_groups[$row['document']]['groups'][] = $row['document_group']; |
| 521 | 521 | } |
| 522 | - foreach ($document_groups as $key => $value) {
|
|
| 523 | - if (($key == $parent || $key == $parentOld || $key == $id) && !in_array($role, $value['groups'])) {
|
|
| 522 | + foreach ($document_groups as $key => $value) { |
|
| 523 | + if (($key == $parent || $key == $parentOld || $key == $id) && !in_array($role, $value['groups'])) { |
|
| 524 | 524 | $json['errors'] = $_lang["error_no_privileges"]; |
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | - if ($json['errors']) {
|
|
| 527 | + if ($json['errors']) { |
|
| 528 | 528 | header('content-type: application/json');
|
| 529 | 529 | echo json_encode($json, JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE); |
| 530 | 530 | break; |
@@ -532,9 +532,9 @@ discard block |
||
| 532 | 532 | } |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - if ($parent == 0 && $parent != $parentOld && !$modx->config['udperms_allowroot'] && $role != 1) {
|
|
| 535 | + if ($parent == 0 && $parent != $parentOld && !$modx->config['udperms_allowroot'] && $role != 1) { |
|
| 536 | 536 | $json['errors'] = $_lang["error_no_privileges"]; |
| 537 | - } else {
|
|
| 537 | + } else { |
|
| 538 | 538 | // set new parent |
| 539 | 539 | $modx->db->update(array( |
| 540 | 540 | 'parent' => $parent |
@@ -544,13 +544,13 @@ discard block |
||
| 544 | 544 | 'isfolder' => 1 |
| 545 | 545 | ), $modx->getFullTableName('site_content'), 'id=' . $parent);
|
| 546 | 546 | |
| 547 | - if ($parent != $parentOld) {
|
|
| 547 | + if ($parent != $parentOld) { |
|
| 548 | 548 | // check children docs and set parent isfolder |
| 549 | - if ($modx->db->getRecordCount($modx->db->select('id', $modx->getFullTableName('site_content'), 'parent=' . $parentOld))) {
|
|
| 549 | + if ($modx->db->getRecordCount($modx->db->select('id', $modx->getFullTableName('site_content'), 'parent=' . $parentOld))) { |
|
| 550 | 550 | $modx->db->update(array( |
| 551 | 551 | 'isfolder' => 1 |
| 552 | 552 | ), $modx->getFullTableName('site_content'), 'id=' . $parentOld);
|
| 553 | - } else {
|
|
| 553 | + } else { |
|
| 554 | 554 | $modx->db->update(array( |
| 555 | 555 | 'isfolder' => 0 |
| 556 | 556 | ), $modx->getFullTableName('site_content'), 'id=' . $parentOld);
|
@@ -558,16 +558,16 @@ discard block |
||
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | // set menuindex |
| 561 | - if (!empty($menuindex)) {
|
|
| 561 | + if (!empty($menuindex)) { |
|
| 562 | 562 | $menuindex = explode(',', $menuindex);
|
| 563 | - foreach ($menuindex as $key => $value) {
|
|
| 563 | + foreach ($menuindex as $key => $value) { |
|
| 564 | 564 | $modx->db->query('UPDATE ' . $modx->getFullTableName('site_content') . ' SET menuindex=' . $key . ' WHERE id=' . $value);
|
| 565 | 565 | } |
| 566 | - } else {
|
|
| 566 | + } else { |
|
| 567 | 567 | // TODO: max(*) menuindex |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - if (!$json['errors']) {
|
|
| 570 | + if (!$json['errors']) { |
|
| 571 | 571 | $json['success'] = $_lang["actioncomplete"]; |
| 572 | 572 | |
| 573 | 573 | $modx->invokeEvent('onAfterMoveDocument', [
|
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | } |
| 582 | - } else {
|
|
| 582 | + } else { |
|
| 583 | 583 | $json['errors'] = $_lang["error_no_privileges"]; |
| 584 | 584 | } |
| 585 | 585 | |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | |
| 596 | 596 | $output = !!$modx->elementIsLocked($type, $id, true); |
| 597 | 597 | |
| 598 | - if (!$output) {
|
|
| 598 | + if (!$output) { |
|
| 599 | 599 | $docgrp = (isset($_SESSION['mgrDocgroups']) && is_array($_SESSION['mgrDocgroups'])) ? implode(',', $_SESSION['mgrDocgroups']) : '';
|
| 600 | 600 | $docgrp_cond = $docgrp ? ' OR dg.document_group IN (' . $docgrp . ')' : '';
|
| 601 | 601 | $sql = ' |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | LEFT JOIN ' . $modx->getFullTableName('document_groups') . ' dg ON dg.document=sc.id
|
| 605 | 605 | WHERE sc.id=' . $id . ' GROUP BY sc.id'; |
| 606 | 606 | $sql = $modx->db->query($sql); |
| 607 | - if ($modx->db->getRecordCount($sql)) {
|
|
| 607 | + if ($modx->db->getRecordCount($sql)) { |
|
| 608 | 608 | $row = $modx->db->getRow($sql); |
| 609 | 609 | $output = !!$row['locked']; |
| 610 | 610 | } |
@@ -22,7 +22,8 @@ discard block |
||
| 22 | 22 | NOTE: http://www.w3.org/TR/NOTE-datetime |
| 23 | 23 | \*======================================================================*/ |
| 24 | 24 | |
| 25 | -function parse_w3cdtf ( $date_str ) { |
|
| 25 | +function parse_w3cdtf ( $date_str ) |
|
| 26 | +{ |
|
| 26 | 27 | |
| 27 | 28 | # regex to match wc3dtf |
| 28 | 29 | $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
@@ -37,8 +38,7 @@ discard block |
||
| 37 | 38 | $offset = 0; |
| 38 | 39 | if ( $match[10] == 'Z' ) { |
| 39 | 40 | # zulu time, aka GMT |
| 40 | - } |
|
| 41 | - else { |
|
| 41 | + } else { |
|
| 42 | 42 | list( $tz_mod, $tz_hour, $tz_min ) = |
| 43 | 43 | array( $match[8], $match[9], $match[10]); |
| 44 | 44 | |
@@ -58,8 +58,7 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | $epoch = $epoch + $offset; |
| 60 | 60 | return $epoch; |
| 61 | - } |
|
| 62 | - else { |
|
| 61 | + } else { |
|
| 63 | 62 | return -1; |
| 64 | 63 | } |
| 65 | 64 | } |
@@ -121,14 +121,18 @@ discard block |
||
| 121 | 121 | { |
| 122 | 122 | |
| 123 | 123 | $URI_PARTS = parse_url($URI); |
| 124 | - if (!empty($URI_PARTS["user"])) |
|
| 125 | - $this->user = $URI_PARTS["user"]; |
|
| 126 | - if (!empty($URI_PARTS["pass"])) |
|
| 127 | - $this->pass = $URI_PARTS["pass"]; |
|
| 128 | - if (empty($URI_PARTS["query"])) |
|
| 129 | - $URI_PARTS["query"] = ''; |
|
| 130 | - if (empty($URI_PARTS["path"])) |
|
| 131 | - $URI_PARTS["path"] = ''; |
|
| 124 | + if (!empty($URI_PARTS["user"])) { |
|
| 125 | + $this->user = $URI_PARTS["user"]; |
|
| 126 | + } |
|
| 127 | + if (!empty($URI_PARTS["pass"])) { |
|
| 128 | + $this->pass = $URI_PARTS["pass"]; |
|
| 129 | + } |
|
| 130 | + if (empty($URI_PARTS["query"])) { |
|
| 131 | + $URI_PARTS["query"] = ''; |
|
| 132 | + } |
|
| 133 | + if (empty($URI_PARTS["path"])) { |
|
| 134 | + $URI_PARTS["path"] = ''; |
|
| 135 | + } |
|
| 132 | 136 | |
| 133 | 137 | $fp = null; |
| 134 | 138 | |
@@ -142,8 +146,9 @@ discard block |
||
| 142 | 146 | case "http": |
| 143 | 147 | $this->scheme = strtolower($URI_PARTS["scheme"]); |
| 144 | 148 | $this->host = $URI_PARTS["host"]; |
| 145 | - if (!empty($URI_PARTS["port"])) |
|
| 146 | - $this->port = $URI_PARTS["port"]; |
|
| 149 | + if (!empty($URI_PARTS["port"])) { |
|
| 150 | + $this->port = $URI_PARTS["port"]; |
|
| 151 | + } |
|
| 147 | 152 | if ($this->_connect($fp)) { |
| 148 | 153 | if ($this->_isproxy) { |
| 149 | 154 | // using proxy, send entire URI |
@@ -177,8 +182,9 @@ discard block |
||
| 177 | 182 | if ($this->_framedepth < $this->maxframes) { |
| 178 | 183 | $this->fetch($frameurl); |
| 179 | 184 | $this->_framedepth++; |
| 180 | - } else |
|
| 181 | - break; |
|
| 185 | + } else { |
|
| 186 | + break; |
|
| 187 | + } |
|
| 182 | 188 | } |
| 183 | 189 | } |
| 184 | 190 | } else { |
@@ -213,14 +219,18 @@ discard block |
||
| 213 | 219 | $postdata = $this->_prepare_post_body($formvars, $formfiles); |
| 214 | 220 | |
| 215 | 221 | $URI_PARTS = parse_url($URI); |
| 216 | - if (!empty($URI_PARTS["user"])) |
|
| 217 | - $this->user = $URI_PARTS["user"]; |
|
| 218 | - if (!empty($URI_PARTS["pass"])) |
|
| 219 | - $this->pass = $URI_PARTS["pass"]; |
|
| 220 | - if (empty($URI_PARTS["query"])) |
|
| 221 | - $URI_PARTS["query"] = ''; |
|
| 222 | - if (empty($URI_PARTS["path"])) |
|
| 223 | - $URI_PARTS["path"] = ''; |
|
| 222 | + if (!empty($URI_PARTS["user"])) { |
|
| 223 | + $this->user = $URI_PARTS["user"]; |
|
| 224 | + } |
|
| 225 | + if (!empty($URI_PARTS["pass"])) { |
|
| 226 | + $this->pass = $URI_PARTS["pass"]; |
|
| 227 | + } |
|
| 228 | + if (empty($URI_PARTS["query"])) { |
|
| 229 | + $URI_PARTS["query"] = ''; |
|
| 230 | + } |
|
| 231 | + if (empty($URI_PARTS["path"])) { |
|
| 232 | + $URI_PARTS["path"] = ''; |
|
| 233 | + } |
|
| 224 | 234 | |
| 225 | 235 | switch (strtolower($URI_PARTS["scheme"])) { |
| 226 | 236 | case "https": |
@@ -232,8 +242,9 @@ discard block |
||
| 232 | 242 | case "http": |
| 233 | 243 | $this->scheme = strtolower($URI_PARTS["scheme"]); |
| 234 | 244 | $this->host = $URI_PARTS["host"]; |
| 235 | - if (!empty($URI_PARTS["port"])) |
|
| 236 | - $this->port = $URI_PARTS["port"]; |
|
| 245 | + if (!empty($URI_PARTS["port"])) { |
|
| 246 | + $this->port = $URI_PARTS["port"]; |
|
| 247 | + } |
|
| 237 | 248 | if ($this->_connect($fp)) { |
| 238 | 249 | if ($this->_isproxy) { |
| 239 | 250 | // using proxy, send entire URI |
@@ -249,18 +260,22 @@ discard block |
||
| 249 | 260 | if ($this->_redirectaddr) { |
| 250 | 261 | /* url was redirected, check if we've hit the max depth */ |
| 251 | 262 | if ($this->maxredirs > $this->_redirectdepth) { |
| 252 | - if (!preg_match("|^" . $URI_PARTS["scheme"] . "://|", $this->_redirectaddr)) |
|
| 253 | - $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"] . "://" . $URI_PARTS["host"]); |
|
| 263 | + if (!preg_match("|^" . $URI_PARTS["scheme"] . "://|", $this->_redirectaddr)) { |
|
| 264 | + $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr, $URI_PARTS["scheme"] . "://" . $URI_PARTS["host"]); |
|
| 265 | + } |
|
| 254 | 266 | |
| 255 | 267 | // only follow redirect if it's on this site, or offsiteok is true |
| 256 | 268 | if (preg_match("|^https?://" . preg_quote($this->host) . "|i", $this->_redirectaddr) || $this->offsiteok) { |
| 257 | 269 | /* follow the redirect */ |
| 258 | 270 | $this->_redirectdepth++; |
| 259 | 271 | $this->lastredirectaddr = $this->_redirectaddr; |
| 260 | - if (strpos($this->_redirectaddr, "?") > 0) |
|
| 261 | - $this->fetch($this->_redirectaddr); // the redirect has changed the request method from post to get |
|
| 262 | - else |
|
| 263 | - $this->submit($this->_redirectaddr, $formvars, $formfiles); |
|
| 272 | + if (strpos($this->_redirectaddr, "?") > 0) { |
|
| 273 | + $this->fetch($this->_redirectaddr); |
|
| 274 | + } |
|
| 275 | + // the redirect has changed the request method from post to get |
|
| 276 | + else { |
|
| 277 | + $this->submit($this->_redirectaddr, $formvars, $formfiles); |
|
| 278 | + } |
|
| 264 | 279 | } |
| 265 | 280 | } |
| 266 | 281 | } |
@@ -273,8 +288,9 @@ discard block |
||
| 273 | 288 | if ($this->_framedepth < $this->maxframes) { |
| 274 | 289 | $this->fetch($frameurl); |
| 275 | 290 | $this->_framedepth++; |
| 276 | - } else |
|
| 277 | - break; |
|
| 291 | + } else { |
|
| 292 | + break; |
|
| 293 | + } |
|
| 278 | 294 | } |
| 279 | 295 | } |
| 280 | 296 | |
@@ -302,19 +318,24 @@ discard block |
||
| 302 | 318 | function fetchlinks($URI) |
| 303 | 319 | { |
| 304 | 320 | if ($this->fetch($URI) !== false) { |
| 305 | - if ($this->lastredirectaddr) |
|
| 306 | - $URI = $this->lastredirectaddr; |
|
| 321 | + if ($this->lastredirectaddr) { |
|
| 322 | + $URI = $this->lastredirectaddr; |
|
| 323 | + } |
|
| 307 | 324 | if (is_array($this->results)) { |
| 308 | - for ($x = 0; $x < count($this->results); $x++) |
|
| 309 | - $this->results[$x] = $this->_striplinks($this->results[$x]); |
|
| 310 | - } else |
|
| 311 | - $this->results = $this->_striplinks($this->results); |
|
| 325 | + for ($x = 0; $x < count($this->results); $x++) { |
|
| 326 | + $this->results[$x] = $this->_striplinks($this->results[$x]); |
|
| 327 | + } |
|
| 328 | + } else { |
|
| 329 | + $this->results = $this->_striplinks($this->results); |
|
| 330 | + } |
|
| 312 | 331 | |
| 313 | - if ($this->expandlinks) |
|
| 314 | - $this->results = $this->_expandlinks($this->results, $URI); |
|
| 332 | + if ($this->expandlinks) { |
|
| 333 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 334 | + } |
|
| 315 | 335 | return $this; |
| 316 | - } else |
|
| 317 | - return false; |
|
| 336 | + } else { |
|
| 337 | + return false; |
|
| 338 | + } |
|
| 318 | 339 | } |
| 319 | 340 | |
| 320 | 341 | /*======================================================================*\ |
@@ -330,14 +351,17 @@ discard block |
||
| 330 | 351 | if ($this->fetch($URI) !== false) { |
| 331 | 352 | |
| 332 | 353 | if (is_array($this->results)) { |
| 333 | - for ($x = 0; $x < count($this->results); $x++) |
|
| 334 | - $this->results[$x] = $this->_stripform($this->results[$x]); |
|
| 335 | - } else |
|
| 336 | - $this->results = $this->_stripform($this->results); |
|
| 354 | + for ($x = 0; $x < count($this->results); $x++) { |
|
| 355 | + $this->results[$x] = $this->_stripform($this->results[$x]); |
|
| 356 | + } |
|
| 357 | + } else { |
|
| 358 | + $this->results = $this->_stripform($this->results); |
|
| 359 | + } |
|
| 337 | 360 | |
| 338 | 361 | return $this; |
| 339 | - } else |
|
| 340 | - return false; |
|
| 362 | + } else { |
|
| 363 | + return false; |
|
| 364 | + } |
|
| 341 | 365 | } |
| 342 | 366 | |
| 343 | 367 | |
@@ -352,13 +376,16 @@ discard block |
||
| 352 | 376 | { |
| 353 | 377 | if ($this->fetch($URI) !== false) { |
| 354 | 378 | if (is_array($this->results)) { |
| 355 | - for ($x = 0; $x < count($this->results); $x++) |
|
| 356 | - $this->results[$x] = $this->_striptext($this->results[$x]); |
|
| 357 | - } else |
|
| 358 | - $this->results = $this->_striptext($this->results); |
|
| 379 | + for ($x = 0; $x < count($this->results); $x++) { |
|
| 380 | + $this->results[$x] = $this->_striptext($this->results[$x]); |
|
| 381 | + } |
|
| 382 | + } else { |
|
| 383 | + $this->results = $this->_striptext($this->results); |
|
| 384 | + } |
|
| 359 | 385 | return $this; |
| 360 | - } else |
|
| 361 | - return false; |
|
| 386 | + } else { |
|
| 387 | + return false; |
|
| 388 | + } |
|
| 362 | 389 | } |
| 363 | 390 | |
| 364 | 391 | /*======================================================================*\ |
@@ -371,22 +398,26 @@ discard block |
||
| 371 | 398 | function submitlinks($URI, $formvars = "", $formfiles = "") |
| 372 | 399 | { |
| 373 | 400 | if ($this->submit($URI, $formvars, $formfiles) !== false) { |
| 374 | - if ($this->lastredirectaddr) |
|
| 375 | - $URI = $this->lastredirectaddr; |
|
| 401 | + if ($this->lastredirectaddr) { |
|
| 402 | + $URI = $this->lastredirectaddr; |
|
| 403 | + } |
|
| 376 | 404 | if (is_array($this->results)) { |
| 377 | 405 | for ($x = 0; $x < count($this->results); $x++) { |
| 378 | 406 | $this->results[$x] = $this->_striplinks($this->results[$x]); |
| 379 | - if ($this->expandlinks) |
|
| 380 | - $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 407 | + if ($this->expandlinks) { |
|
| 408 | + $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 409 | + } |
|
| 381 | 410 | } |
| 382 | 411 | } else { |
| 383 | 412 | $this->results = $this->_striplinks($this->results); |
| 384 | - if ($this->expandlinks) |
|
| 385 | - $this->results = $this->_expandlinks($this->results, $URI); |
|
| 413 | + if ($this->expandlinks) { |
|
| 414 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 415 | + } |
|
| 386 | 416 | } |
| 387 | 417 | return $this; |
| 388 | - } else |
|
| 389 | - return false; |
|
| 418 | + } else { |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 390 | 421 | } |
| 391 | 422 | |
| 392 | 423 | /*======================================================================*\ |
@@ -399,22 +430,26 @@ discard block |
||
| 399 | 430 | function submittext($URI, $formvars = "", $formfiles = "") |
| 400 | 431 | { |
| 401 | 432 | if ($this->submit($URI, $formvars, $formfiles) !== false) { |
| 402 | - if ($this->lastredirectaddr) |
|
| 403 | - $URI = $this->lastredirectaddr; |
|
| 433 | + if ($this->lastredirectaddr) { |
|
| 434 | + $URI = $this->lastredirectaddr; |
|
| 435 | + } |
|
| 404 | 436 | if (is_array($this->results)) { |
| 405 | 437 | for ($x = 0; $x < count($this->results); $x++) { |
| 406 | 438 | $this->results[$x] = $this->_striptext($this->results[$x]); |
| 407 | - if ($this->expandlinks) |
|
| 408 | - $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 439 | + if ($this->expandlinks) { |
|
| 440 | + $this->results[$x] = $this->_expandlinks($this->results[$x], $URI); |
|
| 441 | + } |
|
| 409 | 442 | } |
| 410 | 443 | } else { |
| 411 | 444 | $this->results = $this->_striptext($this->results); |
| 412 | - if ($this->expandlinks) |
|
| 413 | - $this->results = $this->_expandlinks($this->results, $URI); |
|
| 445 | + if ($this->expandlinks) { |
|
| 446 | + $this->results = $this->_expandlinks($this->results, $URI); |
|
| 447 | + } |
|
| 414 | 448 | } |
| 415 | 449 | return $this; |
| 416 | - } else |
|
| 417 | - return false; |
|
| 450 | + } else { |
|
| 451 | + return false; |
|
| 452 | + } |
|
| 418 | 453 | } |
| 419 | 454 | |
| 420 | 455 | |
@@ -468,13 +503,15 @@ discard block |
||
| 468 | 503 | // catenate the non-empty matches from the conditional subpattern |
| 469 | 504 | |
| 470 | 505 | while (list($key, $val) = each($links[2])) { |
| 471 | - if (!empty($val)) |
|
| 472 | - $match[] = $val; |
|
| 506 | + if (!empty($val)) { |
|
| 507 | + $match[] = $val; |
|
| 508 | + } |
|
| 473 | 509 | } |
| 474 | 510 | |
| 475 | 511 | while (list($key, $val) = each($links[3])) { |
| 476 | - if (!empty($val)) |
|
| 477 | - $match[] = $val; |
|
| 512 | + if (!empty($val)) { |
|
| 513 | + $match[] = $val; |
|
| 514 | + } |
|
| 478 | 515 | } |
| 479 | 516 | |
| 480 | 517 | // return the links |
@@ -619,23 +656,28 @@ discard block |
||
| 619 | 656 | function _httprequest($url, $fp, $URI, $http_method, $content_type = "", $body = "") |
| 620 | 657 | { |
| 621 | 658 | $cookie_headers = ''; |
| 622 | - if ($this->passcookies && $this->_redirectaddr) |
|
| 623 | - $this->setcookies(); |
|
| 659 | + if ($this->passcookies && $this->_redirectaddr) { |
|
| 660 | + $this->setcookies(); |
|
| 661 | + } |
|
| 624 | 662 | |
| 625 | 663 | $URI_PARTS = parse_url($URI); |
| 626 | - if (empty($url)) |
|
| 627 | - $url = "/"; |
|
| 664 | + if (empty($url)) { |
|
| 665 | + $url = "/"; |
|
| 666 | + } |
|
| 628 | 667 | $headers = $http_method . " " . $url . " " . $this->_httpversion . "\r\n"; |
| 629 | 668 | if (!empty($this->host) && !isset($this->rawheaders['Host'])) { |
| 630 | 669 | $headers .= "Host: " . $this->host; |
| 631 | - if (!empty($this->port) && $this->port != '80') |
|
| 632 | - $headers .= ":" . $this->port; |
|
| 670 | + if (!empty($this->port) && $this->port != '80') { |
|
| 671 | + $headers .= ":" . $this->port; |
|
| 672 | + } |
|
| 633 | 673 | $headers .= "\r\n"; |
| 634 | 674 | } |
| 635 | - if (!empty($this->agent)) |
|
| 636 | - $headers .= "User-Agent: " . $this->agent . "\r\n"; |
|
| 637 | - if (!empty($this->accept)) |
|
| 638 | - $headers .= "Accept: " . $this->accept . "\r\n"; |
|
| 675 | + if (!empty($this->agent)) { |
|
| 676 | + $headers .= "User-Agent: " . $this->agent . "\r\n"; |
|
| 677 | + } |
|
| 678 | + if (!empty($this->accept)) { |
|
| 679 | + $headers .= "Accept: " . $this->accept . "\r\n"; |
|
| 680 | + } |
|
| 639 | 681 | if ($this->use_gzip) { |
| 640 | 682 | // make sure PHP was built with --with-zlib |
| 641 | 683 | // and we can handle gzipp'ed data |
@@ -648,11 +690,13 @@ discard block |
||
| 648 | 690 | E_USER_NOTICE); |
| 649 | 691 | } |
| 650 | 692 | } |
| 651 | - if (!empty($this->referer)) |
|
| 652 | - $headers .= "Referer: " . $this->referer . "\r\n"; |
|
| 693 | + if (!empty($this->referer)) { |
|
| 694 | + $headers .= "Referer: " . $this->referer . "\r\n"; |
|
| 695 | + } |
|
| 653 | 696 | if (!empty($this->cookies)) { |
| 654 | - if (!is_array($this->cookies)) |
|
| 655 | - $this->cookies = (array)$this->cookies; |
|
| 697 | + if (!is_array($this->cookies)) { |
|
| 698 | + $this->cookies = (array)$this->cookies; |
|
| 699 | + } |
|
| 656 | 700 | |
| 657 | 701 | reset($this->cookies); |
| 658 | 702 | if (count($this->cookies) > 0) { |
@@ -664,32 +708,39 @@ discard block |
||
| 664 | 708 | } |
| 665 | 709 | } |
| 666 | 710 | if (!empty($this->rawheaders)) { |
| 667 | - if (!is_array($this->rawheaders)) |
|
| 668 | - $this->rawheaders = (array)$this->rawheaders; |
|
| 669 | - while (list($headerKey, $headerVal) = each($this->rawheaders)) |
|
| 670 | - $headers .= $headerKey . ": " . $headerVal . "\r\n"; |
|
| 711 | + if (!is_array($this->rawheaders)) { |
|
| 712 | + $this->rawheaders = (array)$this->rawheaders; |
|
| 713 | + } |
|
| 714 | + while (list($headerKey, $headerVal) = each($this->rawheaders)) { |
|
| 715 | + $headers .= $headerKey . ": " . $headerVal . "\r\n"; |
|
| 716 | + } |
|
| 671 | 717 | } |
| 672 | 718 | if (!empty($content_type)) { |
| 673 | 719 | $headers .= "Content-type: $content_type"; |
| 674 | - if ($content_type == "multipart/form-data") |
|
| 675 | - $headers .= "; boundary=" . $this->_mime_boundary; |
|
| 720 | + if ($content_type == "multipart/form-data") { |
|
| 721 | + $headers .= "; boundary=" . $this->_mime_boundary; |
|
| 722 | + } |
|
| 676 | 723 | $headers .= "\r\n"; |
| 677 | 724 | } |
| 678 | - if (!empty($body)) |
|
| 679 | - $headers .= "Content-length: " . strlen($body) . "\r\n"; |
|
| 680 | - if (!empty($this->user) || !empty($this->pass)) |
|
| 681 | - $headers .= "Authorization: Basic " . base64_encode($this->user . ":" . $this->pass) . "\r\n"; |
|
| 725 | + if (!empty($body)) { |
|
| 726 | + $headers .= "Content-length: " . strlen($body) . "\r\n"; |
|
| 727 | + } |
|
| 728 | + if (!empty($this->user) || !empty($this->pass)) { |
|
| 729 | + $headers .= "Authorization: Basic " . base64_encode($this->user . ":" . $this->pass) . "\r\n"; |
|
| 730 | + } |
|
| 682 | 731 | |
| 683 | 732 | //add proxy auth headers |
| 684 | - if (!empty($this->proxy_user)) |
|
| 685 | - $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass) . "\r\n"; |
|
| 733 | + if (!empty($this->proxy_user)) { |
|
| 734 | + $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass) . "\r\n"; |
|
| 735 | + } |
|
| 686 | 736 | |
| 687 | 737 | |
| 688 | 738 | $headers .= "\r\n"; |
| 689 | 739 | |
| 690 | 740 | // set the read timeout if needed |
| 691 | - if ($this->read_timeout > 0) |
|
| 692 | - socket_set_timeout($fp, $this->read_timeout); |
|
| 741 | + if ($this->read_timeout > 0) { |
|
| 742 | + socket_set_timeout($fp, $this->read_timeout); |
|
| 743 | + } |
|
| 693 | 744 | $this->timed_out = false; |
| 694 | 745 | |
| 695 | 746 | fwrite($fp, $headers . $body, strlen($headers . $body)); |
@@ -706,8 +757,9 @@ discard block |
||
| 706 | 757 | return false; |
| 707 | 758 | } |
| 708 | 759 | |
| 709 | - if ($currentHeader == "\r\n") |
|
| 710 | - break; |
|
| 760 | + if ($currentHeader == "\r\n") { |
|
| 761 | + break; |
|
| 762 | + } |
|
| 711 | 763 | |
| 712 | 764 | // if a header begins with Location: or URI:, set the redirect |
| 713 | 765 | if (preg_match("/^(Location:|URI:)/i", $currentHeader)) { |
@@ -718,12 +770,14 @@ discard block |
||
| 718 | 770 | // no host in the path, so prepend |
| 719 | 771 | $this->_redirectaddr = $URI_PARTS["scheme"] . "://" . $this->host . ":" . $this->port; |
| 720 | 772 | // eliminate double slash |
| 721 | - if (!preg_match("|^/|", $matches[2])) |
|
| 722 | - $this->_redirectaddr .= "/" . $matches[2]; |
|
| 723 | - else |
|
| 724 | - $this->_redirectaddr .= $matches[2]; |
|
| 725 | - } else |
|
| 726 | - $this->_redirectaddr = $matches[2]; |
|
| 773 | + if (!preg_match("|^/|", $matches[2])) { |
|
| 774 | + $this->_redirectaddr .= "/" . $matches[2]; |
|
| 775 | + } else { |
|
| 776 | + $this->_redirectaddr .= $matches[2]; |
|
| 777 | + } |
|
| 778 | + } else { |
|
| 779 | + $this->_redirectaddr = $matches[2]; |
|
| 780 | + } |
|
| 727 | 781 | } |
| 728 | 782 | |
| 729 | 783 | if (preg_match("|^HTTP/|", $currentHeader)) { |
@@ -770,14 +824,17 @@ discard block |
||
| 770 | 824 | // have we hit our frame depth and is there frame src to fetch? |
| 771 | 825 | if (($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i", $results, $match)) { |
| 772 | 826 | $this->results[] = $results; |
| 773 | - for ($x = 0; $x < count($match[1]); $x++) |
|
| 774 | - $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"] . "://" . $this->host); |
|
| 827 | + for ($x = 0; $x < count($match[1]); $x++) { |
|
| 828 | + $this->_frameurls[] = $this->_expandlinks($match[1][$x], $URI_PARTS["scheme"] . "://" . $this->host); |
|
| 829 | + } |
|
| 775 | 830 | } // have we already fetched framed content? |
| 776 | - elseif (is_array($this->results)) |
|
| 777 | - $this->results[] = $results; |
|
| 831 | + elseif (is_array($this->results)) { |
|
| 832 | + $this->results[] = $results; |
|
| 833 | + } |
|
| 778 | 834 | // no framed content |
| 779 | - else |
|
| 780 | - $this->results = $results; |
|
| 835 | + else { |
|
| 836 | + $this->results = $results; |
|
| 837 | + } |
|
| 781 | 838 | |
| 782 | 839 | return $this; |
| 783 | 840 | } |
@@ -790,8 +847,9 @@ discard block |
||
| 790 | 847 | function setcookies() |
| 791 | 848 | { |
| 792 | 849 | for ($x = 0; $x < count($this->headers); $x++) { |
| 793 | - if (preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x], $match)) |
|
| 794 | - $this->cookies[$match[1]] = urldecode($match[2]); |
|
| 850 | + if (preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x], $match)) { |
|
| 851 | + $this->cookies[$match[1]] = urldecode($match[2]); |
|
| 852 | + } |
|
| 795 | 853 | } |
| 796 | 854 | return $this; |
| 797 | 855 | } |
@@ -852,10 +910,12 @@ discard block |
||
| 852 | 910 | 'disable_compression' => true, |
| 853 | 911 | ); |
| 854 | 912 | |
| 855 | - if (isset($this->cafile)) |
|
| 856 | - $context_opts['ssl']['cafile'] = $this->cafile; |
|
| 857 | - if (isset($this->capath)) |
|
| 858 | - $context_opts['ssl']['capath'] = $this->capath; |
|
| 913 | + if (isset($this->cafile)) { |
|
| 914 | + $context_opts['ssl']['cafile'] = $this->cafile; |
|
| 915 | + } |
|
| 916 | + if (isset($this->capath)) { |
|
| 917 | + $context_opts['ssl']['capath'] = $this->capath; |
|
| 918 | + } |
|
| 859 | 919 | } |
| 860 | 920 | |
| 861 | 921 | $host = 'ssl://' . $host; |
@@ -864,8 +924,9 @@ discard block |
||
| 864 | 924 | $context = stream_context_create($context_opts); |
| 865 | 925 | |
| 866 | 926 | if (version_compare(PHP_VERSION, '5.0.0', '>')) { |
| 867 | - if($this->scheme == 'http') |
|
| 868 | - $host = "tcp://" . $host; |
|
| 927 | + if($this->scheme == 'http') { |
|
| 928 | + $host = "tcp://" . $host; |
|
| 929 | + } |
|
| 869 | 930 | $fp = stream_socket_client( |
| 870 | 931 | "$host:$port", |
| 871 | 932 | $errno, |
@@ -929,8 +990,9 @@ discard block |
||
| 929 | 990 | settype($formfiles, "array"); |
| 930 | 991 | $postdata = ''; |
| 931 | 992 | |
| 932 | - if (count($formvars) == 0 && count($formfiles) == 0) |
|
| 933 | - return; |
|
| 993 | + if (count($formvars) == 0 && count($formfiles) == 0) { |
|
| 994 | + return; |
|
| 995 | + } |
|
| 934 | 996 | |
| 935 | 997 | switch ($this->_submit_type) { |
| 936 | 998 | case "application/x-www-form-urlencoded": |
@@ -940,8 +1002,9 @@ discard block |
||
| 940 | 1002 | while (list($cur_key, $cur_val) = each($val)) { |
| 941 | 1003 | $postdata .= urlencode($key) . "[]=" . urlencode($cur_val) . "&"; |
| 942 | 1004 | } |
| 943 | - } else |
|
| 944 | - $postdata .= urlencode($key) . "=" . urlencode($val) . "&"; |
|
| 1005 | + } else { |
|
| 1006 | + $postdata .= urlencode($key) . "=" . urlencode($val) . "&"; |
|
| 1007 | + } |
|
| 945 | 1008 | } |
| 946 | 1009 | break; |
| 947 | 1010 | |
@@ -967,7 +1030,9 @@ discard block |
||
| 967 | 1030 | while (list($field_name, $file_names) = each($formfiles)) { |
| 968 | 1031 | settype($file_names, "array"); |
| 969 | 1032 | while (list(, $file_name) = each($file_names)) { |
| 970 | - if (!is_readable($file_name)) continue; |
|
| 1033 | + if (!is_readable($file_name)) { |
|
| 1034 | + continue; |
|
| 1035 | + } |
|
| 971 | 1036 | |
| 972 | 1037 | $fp = fopen($file_name, "r"); |
| 973 | 1038 | $file_content = fread($fp, filesize($file_name)); |