| Total Complexity | 11 |
| Total Lines | 83 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | final class Content implements Bootable |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Boot the service. |
||
| 11 | * |
||
| 12 | * @return void |
||
| 13 | */ |
||
| 14 | public static function boot(): void |
||
| 15 | { |
||
| 16 | $self = new static; |
||
| 17 | |||
| 18 | add_filter('the_content', [$self, 'parse'], 100); |
||
|
|
|||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Parse a given content. |
||
| 23 | * |
||
| 24 | * @param string $content |
||
| 25 | * |
||
| 26 | * @return string |
||
| 27 | */ |
||
| 28 | public function parse(string $content): string |
||
| 29 | { |
||
| 30 | if (!$images = $this->resolveImages($content)) { |
||
| 31 | return $content; |
||
| 32 | } |
||
| 33 | |||
| 34 | if ($attachmentIds = $this->resolveAttachmentIds($images['img_tags'])) { |
||
| 35 | _prime_post_caches($attachmentIds, false, true); |
||
| 36 | } |
||
| 37 | |||
| 38 | foreach ($images['img_tags'] as $index => $tag) { |
||
| 39 | $transform = 'resize'; |
||
| 40 | |||
| 41 | $attachmentId = null; |
||
| 42 | |||
| 43 | $fullSizeUrl = null; |
||
| 44 | |||
| 45 | $src = $srcOrig = $images['img_urls'][$index]; |
||
| 46 | |||
| 47 | if (!apply_filters('imgix_image_url_processable', true, $src)) |
||
| 48 | continue; |
||
| 49 | } |
||
| 50 | |||
| 51 | return $content; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param string $content |
||
| 56 | * |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | private function resolveImages(string $content): array |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param array $tags |
||
| 76 | * |
||
| 77 | * @return array |
||
| 78 | */ |
||
| 79 | private function resolveAttachmentIds(array $tags): array |
||
| 90 | } |
||
| 91 | } |
||
| 92 |