@@ -85,8 +85,11 @@ discard block |
||
| 85 | 85 | * @return bool true on image, false on anything else |
| 86 | 86 | */ |
| 87 | 87 | public static function isImage($link) { |
| 88 | - if (preg_match('%\.(gif|jpe?g|png|bmp)$%i',$link)) return true; |
|
| 89 | - else return false; |
|
| 88 | + if (preg_match('%\.(gif|jpe?g|png|bmp)$%i',$link)) { |
|
| 89 | + return true; |
|
| 90 | + } else { |
|
| 91 | + return false; |
|
| 92 | + } |
|
| 90 | 93 | } |
| 91 | 94 | |
| 92 | 95 | /** |
@@ -143,8 +146,11 @@ discard block |
||
| 143 | 146 | * @return bool true on mailto:, false on everything else |
| 144 | 147 | */ |
| 145 | 148 | public static function isMailto($link) { |
| 146 | - if (stripos($link,'mailto:')===FALSE) return false; |
|
| 147 | - else return true; |
|
| 149 | + if (stripos($link,'mailto:')===FALSE) { |
|
| 150 | + return false; |
|
| 151 | + } else { |
|
| 152 | + return true; |
|
| 153 | + } |
|
| 148 | 154 | } |
| 149 | 155 | |
| 150 | 156 | /* Depreciated (I think) |
@@ -210,9 +216,15 @@ discard block |
||
| 210 | 216 | |
| 211 | 217 | // Copy base authority. |
| 212 | 218 | $r['host'] = $b['host']; |
| 213 | - if ( isset( $b['port'] ) ) $r['port'] = $b['port']; |
|
| 214 | - if ( isset( $b['user'] ) ) $r['user'] = $b['user']; |
|
| 215 | - if ( isset( $b['pass'] ) ) $r['pass'] = $b['pass']; |
|
| 219 | + if ( isset( $b['port'] ) ) { |
|
| 220 | + $r['port'] = $b['port']; |
|
| 221 | + } |
|
| 222 | + if ( isset( $b['user'] ) ) { |
|
| 223 | + $r['user'] = $b['user']; |
|
| 224 | + } |
|
| 225 | + if ( isset( $b['pass'] ) ) { |
|
| 226 | + $r['pass'] = $b['pass']; |
|
| 227 | + } |
|
| 216 | 228 | |
| 217 | 229 | // If relative URL has no path, use base path |
| 218 | 230 | if ( empty( $r['path'] ) ) |
@@ -232,7 +244,9 @@ discard block |
||
| 232 | 244 | if ( $r['path'][0] != '/' ) |
| 233 | 245 | { |
| 234 | 246 | $base = mb_strrchr( $b['path'], '/', TRUE, 'UTF-8' ); |
| 235 | - if ( $base === FALSE ) $base = ''; |
|
| 247 | + if ( $base === FALSE ) { |
|
| 248 | + $base = ''; |
|
| 249 | + } |
|
| 236 | 250 | $r['path'] = $base . '/' . $r['path']; |
| 237 | 251 | } |
| 238 | 252 | $r['path'] = self::urlRemoveDotSegments( $r['path'] ); |
@@ -323,41 +337,70 @@ discard block |
||
| 323 | 337 | return FALSE; |
| 324 | 338 | } |
| 325 | 339 | |
| 326 | - if ( !empty($m[2]) ) $parts['scheme'] = strtolower($m[2]); |
|
| 340 | + if ( !empty($m[2]) ) { |
|
| 341 | + $parts['scheme'] = strtolower($m[2]); |
|
| 342 | + } |
|
| 327 | 343 | |
| 328 | 344 | if ( !empty($m[7]) ) { |
| 329 | - if ( isset( $m[9] ) ) $parts['user'] = $m[9]; |
|
| 330 | - else $parts['user'] = ''; |
|
| 345 | + if ( isset( $m[9] ) ) { |
|
| 346 | + $parts['user'] = $m[9]; |
|
| 347 | + } else { |
|
| 348 | + $parts['user'] = ''; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + if ( !empty($m[10]) ) { |
|
| 352 | + $parts['pass'] = $m[11]; |
|
| 331 | 353 | } |
| 332 | - if ( !empty($m[10]) ) $parts['pass'] = $m[11]; |
|
| 333 | 354 | |
| 334 | - if ( !empty($m[13]) ) $h=$parts['host'] = $m[13]; |
|
| 335 | - else if ( !empty($m[14]) ) $parts['host'] = $m[14]; |
|
| 336 | - else if ( !empty($m[16]) ) $parts['host'] = $m[16]; |
|
| 337 | - else if ( !empty( $m[5] ) ) $parts['host'] = ''; |
|
| 338 | - if ( !empty($m[17]) ) $parts['port'] = $m[18]; |
|
| 355 | + if ( !empty($m[13]) ) { |
|
| 356 | + $h=$parts['host'] = $m[13]; |
|
| 357 | + } else if ( !empty($m[14]) ) { |
|
| 358 | + $parts['host'] = $m[14]; |
|
| 359 | + } else if ( !empty($m[16]) ) { |
|
| 360 | + $parts['host'] = $m[16]; |
|
| 361 | + } else if ( !empty( $m[5] ) ) { |
|
| 362 | + $parts['host'] = ''; |
|
| 363 | + } |
|
| 364 | + if ( !empty($m[17]) ) { |
|
| 365 | + $parts['port'] = $m[18]; |
|
| 366 | + } |
|
| 339 | 367 | |
| 340 | - if ( !empty($m[19]) ) $parts['path'] = $m[19]; |
|
| 341 | - else if ( !empty($m[21]) ) $parts['path'] = $m[21]; |
|
| 342 | - else if ( !empty($m[25]) ) $parts['path'] = $m[25]; |
|
| 368 | + if ( !empty($m[19]) ) { |
|
| 369 | + $parts['path'] = $m[19]; |
|
| 370 | + } else if ( !empty($m[21]) ) { |
|
| 371 | + $parts['path'] = $m[21]; |
|
| 372 | + } else if ( !empty($m[25]) ) { |
|
| 373 | + $parts['path'] = $m[25]; |
|
| 374 | + } |
|
| 343 | 375 | |
| 344 | - if ( !empty($m[27]) ) $parts['query'] = $m[28]; |
|
| 345 | - if ( !empty($m[29]) ) $parts['fragment']= $m[30]; |
|
| 376 | + if ( !empty($m[27]) ) { |
|
| 377 | + $parts['query'] = $m[28]; |
|
| 378 | + } |
|
| 379 | + if ( !empty($m[29]) ) { |
|
| 380 | + $parts['fragment']= $m[30]; |
|
| 381 | + } |
|
| 346 | 382 | |
| 347 | - if ( !$decode ) |
|
| 348 | - return $parts; |
|
| 349 | - if ( !empty($parts['user']) ) |
|
| 350 | - $parts['user'] = rawurldecode( $parts['user'] ); |
|
| 351 | - if ( !empty($parts['pass']) ) |
|
| 352 | - $parts['pass'] = rawurldecode( $parts['pass'] ); |
|
| 353 | - if ( !empty($parts['path']) ) |
|
| 354 | - $parts['path'] = rawurldecode( $parts['path'] ); |
|
| 355 | - if ( isset($h) ) |
|
| 356 | - $parts['host'] = rawurldecode( $parts['host'] ); |
|
| 357 | - if ( !empty($parts['query']) ) |
|
| 358 | - $parts['query'] = rawurldecode( $parts['query'] ); |
|
| 359 | - if ( !empty($parts['fragment']) ) |
|
| 360 | - $parts['fragment'] = rawurldecode( $parts['fragment'] ); |
|
| 383 | + if ( !$decode ) { |
|
| 384 | + return $parts; |
|
| 385 | + } |
|
| 386 | + if ( !empty($parts['user']) ) { |
|
| 387 | + $parts['user'] = rawurldecode( $parts['user'] ); |
|
| 388 | + } |
|
| 389 | + if ( !empty($parts['pass']) ) { |
|
| 390 | + $parts['pass'] = rawurldecode( $parts['pass'] ); |
|
| 391 | + } |
|
| 392 | + if ( !empty($parts['path']) ) { |
|
| 393 | + $parts['path'] = rawurldecode( $parts['path'] ); |
|
| 394 | + } |
|
| 395 | + if ( isset($h) ) { |
|
| 396 | + $parts['host'] = rawurldecode( $parts['host'] ); |
|
| 397 | + } |
|
| 398 | + if ( !empty($parts['query']) ) { |
|
| 399 | + $parts['query'] = rawurldecode( $parts['query'] ); |
|
| 400 | + } |
|
| 401 | + if ( !empty($parts['fragment']) ) { |
|
| 402 | + $parts['fragment'] = rawurldecode( $parts['fragment'] ); |
|
| 403 | + } |
|
| 361 | 404 | return $parts; |
| 362 | 405 | } |
| 363 | 406 | |
@@ -397,33 +440,44 @@ discard block |
||
| 397 | 440 | } |
| 398 | 441 | |
| 399 | 442 | $url = ''; |
| 400 | - if ( !empty( $parts['scheme'] ) ) |
|
| 401 | - $url .= $parts['scheme'] . ':'; |
|
| 443 | + if ( !empty( $parts['scheme'] ) ) { |
|
| 444 | + $url .= $parts['scheme'] . ':'; |
|
| 445 | + } |
|
| 402 | 446 | if ( isset( $parts['host'] ) ) |
| 403 | 447 | { |
| 404 | 448 | $url .= '//'; |
| 405 | 449 | if ( isset( $parts['user'] ) ) |
| 406 | 450 | { |
| 407 | 451 | $url .= $parts['user']; |
| 408 | - if ( isset( $parts['pass'] ) ) |
|
| 409 | - $url .= ':' . $parts['pass']; |
|
| 452 | + if ( isset( $parts['pass'] ) ) { |
|
| 453 | + $url .= ':' . $parts['pass']; |
|
| 454 | + } |
|
| 410 | 455 | $url .= '@'; |
| 411 | 456 | } |
| 412 | - if ( preg_match( '!^[\da-f]*:[\da-f.:]+$!ui', $parts['host'] ) ) |
|
| 413 | - $url .= '[' . $parts['host'] . ']'; // IPv6 |
|
| 414 | - else |
|
| 415 | - $url .= $parts['host']; // IPv4 or name |
|
| 416 | - if ( isset( $parts['port'] ) ) |
|
| 417 | - $url .= ':' . $parts['port']; |
|
| 418 | - if ( !empty( $parts['path'] ) && $parts['path'][0] != '/' ) |
|
| 419 | - $url .= '/'; |
|
| 420 | - } |
|
| 421 | - if ( !empty( $parts['path'] ) ) |
|
| 422 | - $url .= $parts['path']; |
|
| 423 | - if ( isset( $parts['query'] ) ) |
|
| 424 | - $url .= '?' . $parts['query']; |
|
| 425 | - if ( isset( $parts['fragment'] ) ) |
|
| 426 | - $url .= '#' . $parts['fragment']; |
|
| 457 | + if ( preg_match( '!^[\da-f]*:[\da-f.:]+$!ui', $parts['host'] ) ) { |
|
| 458 | + $url .= '[' . $parts['host'] . ']'; |
|
| 459 | + } |
|
| 460 | + // IPv6 |
|
| 461 | + else { |
|
| 462 | + $url .= $parts['host']; |
|
| 463 | + } |
|
| 464 | + // IPv4 or name |
|
| 465 | + if ( isset( $parts['port'] ) ) { |
|
| 466 | + $url .= ':' . $parts['port']; |
|
| 467 | + } |
|
| 468 | + if ( !empty( $parts['path'] ) && $parts['path'][0] != '/' ) { |
|
| 469 | + $url .= '/'; |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + if ( !empty( $parts['path'] ) ) { |
|
| 473 | + $url .= $parts['path']; |
|
| 474 | + } |
|
| 475 | + if ( isset( $parts['query'] ) ) { |
|
| 476 | + $url .= '?' . $parts['query']; |
|
| 477 | + } |
|
| 478 | + if ( isset( $parts['fragment'] ) ) { |
|
| 479 | + $url .= '#' . $parts['fragment']; |
|
| 480 | + } |
|
| 427 | 481 | return $url; |
| 428 | 482 | } |
| 429 | 483 | |