helick /
imgix
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Helick\Imgix; |
||||
| 4 | |||||
| 5 | use Imgix\UrlBuilder; |
||||
| 6 | |||||
| 7 | /** |
||||
| 8 | * Get the imgix domain. |
||||
| 9 | * |
||||
| 10 | * @return string |
||||
| 11 | */ |
||||
| 12 | function domain(): string |
||||
| 13 | { |
||||
| 14 | return defined('IMGIX_DOMAIN') |
||||
| 15 | ? IMGIX_DOMAIN |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 16 | : ''; |
||||
| 17 | } |
||||
| 18 | |||||
| 19 | /** |
||||
| 20 | * Get the imgix url. |
||||
| 21 | * |
||||
| 22 | * @param string $imageUrl |
||||
| 23 | * @param array $args |
||||
| 24 | * @param bool $useHttps |
||||
| 25 | * @param string $signKey |
||||
| 26 | * |
||||
| 27 | * @return string |
||||
| 28 | */ |
||||
| 29 | function url(string $imageUrl, array $args = [], bool $useHttps = true, string $signKey = ''): string |
||||
| 30 | { |
||||
| 31 | $requiresProcessing = strpos($imageUrl, wp_upload_dir()['baseurl']) === 0; |
||||
|
0 ignored issues
–
show
The function
wp_upload_dir was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 32 | |||||
| 33 | /** |
||||
| 34 | * Control whether the given image url is processable. |
||||
| 35 | * |
||||
| 36 | * @param bool $isProcessable |
||||
| 37 | * @param string $imageUrl |
||||
| 38 | * @param array $args |
||||
| 39 | */ |
||||
| 40 | $isProcessable = apply_filters('helick_imgix_image_url_processable', true, $imageUrl, $args); |
||||
|
0 ignored issues
–
show
The function
apply_filters was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 41 | $isProcessable = (bool)$isProcessable; |
||||
| 42 | |||||
| 43 | if (!$requiresProcessing || !$isProcessable) { |
||||
| 44 | return $imageUrl; |
||||
| 45 | } |
||||
| 46 | |||||
| 47 | $imageUrlPath = parse_url($imageUrl, PHP_URL_PATH); |
||||
| 48 | |||||
| 49 | $imageFile = basename($imageUrlPath); |
||||
| 50 | $imageFile = urlencode($imageFile); |
||||
| 51 | |||||
| 52 | $imageUrlPath = str_replace($imageUrl, $imageFile, $imageUrlPath); |
||||
| 53 | |||||
| 54 | /** |
||||
| 55 | * Control the imgix image url path. |
||||
| 56 | * |
||||
| 57 | * @param string $imageUrlPath |
||||
| 58 | * @param array $args |
||||
| 59 | */ |
||||
| 60 | $imageUrlPath = apply_filters('helick_imgix_image_url_path', $imageUrlPath, $args); |
||||
| 61 | |||||
| 62 | /** |
||||
| 63 | * Control the imgix arguments. |
||||
| 64 | * |
||||
| 65 | * @param array $args |
||||
| 66 | * @param string $imageUrlPath |
||||
| 67 | */ |
||||
| 68 | $args = apply_filters('helick_imgix_args', $args, $imageUrlPath); |
||||
| 69 | |||||
| 70 | $urlBuilder = new UrlBuilder(domain(), $useHttps, $signKey); |
||||
| 71 | $imgixUrl = $urlBuilder->createURL($imageUrlPath, $args); |
||||
| 72 | |||||
| 73 | /** |
||||
| 74 | * Control the imgix url. |
||||
| 75 | * |
||||
| 76 | * @param string $imgixUrl |
||||
| 77 | * @param string $imageUrl |
||||
| 78 | * @param array $args |
||||
| 79 | */ |
||||
| 80 | $imgixUrl = apply_filters('helick_imgix_url', $imgixUrl, $imageUrl, $args); |
||||
| 81 | |||||
| 82 | return $imgixUrl; |
||||
| 83 | } |
||||
| 84 |