├── .github └── workflows │ └── test.yml ├── .gitignore ├── License.md ├── README.md ├── composer.json ├── phpspec.yml ├── spec └── ConverterSpec.php └── src ├── Converter.php ├── TagConverter ├── AMPAudio.php ├── AMPDailymotion.php ├── AMPFacebook.php ├── AMPGfycat.php ├── AMPGist.php ├── AMPIframe.php ├── AMPImg.php ├── AMPImgLightbox.php ├── AMPImgZoom.php ├── AMPImgur.php ├── AMPInstagram.php ├── AMPPinterest.php ├── AMPPlaybuzz.php ├── AMPTwitter.php ├── AMPVideo.php ├── AMPVimeo.php ├── AMPVk.php └── AMPYoutube.php ├── TagConverterInterface.php └── Util └── ImageSize.php /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | tests: 7 | runs-on: ubuntu-20.04 8 | 9 | strategy: 10 | matrix: 11 | php: ['7.3', '7.4', '8.0', '8.1', '8.2'] 12 | 13 | name: PHP ${{ matrix.php }} 14 | 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: shivammathur/setup-php@v2 18 | with: 19 | php-version: ${{ matrix.php }} 20 | extensions: ctype, dom, libxml, mbstring 21 | tools: composer:v2 22 | coverage: none 23 | - run: composer install --prefer-source --no-interaction 24 | - run: vendor/bin/phpspec run -v --format=progress -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2019 András Magyar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AMP ⚡ converter library 2 | 3 | [](https://github.com/magyarandras/amp-converter/actions) 4 | 5 | A library to convert HTML articles, blog posts or similar content to [AMP (Accelerated Mobile Pages)](https://amp.dev). 6 | 7 | **Note**: This library is not intended to convert entire HTML documents if you want to convert an entire page you should use a more advanced library, for example: [Lullabot/amp-library](https://github.com/Lullabot/amp-library/) 8 | 9 | ## Installation: 10 | 11 | ``` 12 | composer require magyarandras/amp-converter 13 | ``` 14 | 15 | ## Currently supported elments: 16 | * [x] amp-img 17 | * [x] amp-img in amp-pan-zoom 18 | * [x] amp-img with lightbox 19 | * [x] amp-video 20 | * [x] amp-audio 21 | * [x] amp-iframe(A placeholder is automatically added to the iframes, so you can [embed iframes even above the fold](https://www.youtube.com/watch?v=TqfYmlkHVCs).) 22 | * [x] amp-youtube 23 | * [x] amp-facebook 24 | * [x] amp-instagram 25 | * [x] amp-twitter 26 | * [x] amp-pinterest 27 | * [x] amp-playbuzz 28 | * [x] amp-gist(Github gist embed) 29 | * [x] amp-vimeo 30 | * [ ] amp-soundcloud(You can use amp-iframe instead) 31 | * [x] amp-vk 32 | * [x] amp-imgur 33 | * [x] amp-dailymotion 34 | * [x] amp-gfycat 35 | 36 | ## Usage: 37 | 38 | Simple example: 39 | 40 | **Make sure your HTML code doesn't contain tags or attributes invalid in HTML5 otherwise, the generated AMP will be invalid too.** 41 | 42 | ```php 43 | loadDefaultConverters(); 59 | 60 | //HTML to convert 61 | $html = ' 62 |
This is a sample HTML code generated by TinyMCE.
63 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
65 | 66 |67 |
68 |70 | '; 71 | 72 | //Convert html to amp html 73 | $amphtml = $converter->convert($html); 74 | 75 | //Get the necessary amp components 76 | $amp_scripts = $converter->getScripts(); 77 | 78 | print_r($amphtml); 79 | echo PHP_EOL; 80 | print_r($amp_scripts); 81 | 82 | ``` 83 | The output: 84 | ```html 85 |Check out the latest post on the AMP Blog to learn how @AdobeExpCloud has been working to seamless integrate AMP support into its applications ⚡
69 | — AMP Project (@AMPhtml) April 10, 2020
Learn more here 👉 https://t.co/hX3QmJ707x
This is a sample HTML code generated by TinyMCE.
86 |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
88 |90 |
This is a sample HTML code generated by TinyMCE.
148 |text
text
hh
Hello!hh
Loading...
187 | How to Share With Just Friends 188 |191 |How to share with just friends.
189 | Posted by Facebook on Friday, December 5, 2014 190 |
can't see? no problem
')
244 | ->shouldReturn('') 268 | ->shouldReturn('Not just web pages need better UX. Here's how we bring @AMPhtml to other parts of the internet: https://t.co/hSqH3nKsr7
— Paul Bakaus (@pbakaus) May 15, 2018
') 280 | ->shouldReturn('
') 292 | ->shouldReturn('
') 304 | ->shouldReturn('
from Silicon Valley GIFs via Gfycat
') 356 | ->shouldReturn('from Silicon Valley GIFs via Gfycat
'); 357 | 358 | $this->getScripts()->shouldReturn([ 359 | '' 360 | ]); 361 | } 362 | } 363 | -------------------------------------------------------------------------------- /src/Converter.php: -------------------------------------------------------------------------------- 1 | '*', 35 | 'width' => 'hr|table|td|th|col|colgroup|pre', 36 | 'height' => 'hr|table|td|th|col|colgroup|pre', 37 | 'valign' => 'col|colgroup|tbody|td|tfoot|th|thead|tr', 38 | 'type' => 'li|ol|ul', 39 | 'size' => 'hr', 40 | 'rules' => 'table', 41 | 'nowrap' => 'td|th', 42 | 'noshade' => 'hr', 43 | 'frame' =>'table', 44 | 'compact' => 'dl|ol|ul', 45 | 'clear' => 'br', 46 | 'charoff' => 'col|colgroup|tbody|td|tfoot|th|thead|tr', 47 | 'char' => 'col|colgroup|tbody|td|tfoot|th|thead|tr', 48 | 'cellspacing' => 'table', 49 | 'cellpadding' => 'table', 50 | 'border' => '*', 51 | 'bgcolor' => 'table|tr|td|th', 52 | 'align' => '*', 53 | 'scope' => 'td', 54 | 'axis' => 'td', 55 | 'abbr' => 'td', 56 | 'charset' => 'a', 57 | 'coords' => 'a', 58 | 'shape' => 'a', 59 | 'onkeydown' => '*', 60 | 'onkeyup' => '*', 61 | 'onkeypress' => '*', 62 | 'onclick' => '*', 63 | 'ondblclick' => '*', 64 | 'onmousedown' => '*', 65 | 'onmousemove' => '*', 66 | 'onmouseout' => '*', 67 | 'onmouseover' => '*', 68 | 'onmouseup' => '*', 69 | 'onmousewheel' => '*', 70 | 'onwheel' => '*', 71 | 'ondrag' => '*', 72 | 'ondragend' => '*', 73 | 'ondragenter' => '*', 74 | 'ondragleave' => '*', 75 | 'ondragover' => '*', 76 | 'ondragstart' => '*', 77 | 'ondrop' => '*', 78 | 'onscroll' => '*', 79 | 'ontoggle' => '*', 80 | 'oncopy' => '*', 81 | 'onpaste' => '*', 82 | 'oncut' => '*' 83 | ]; 84 | 85 | private $converters = [ 86 | 87 | ]; 88 | 89 | private $scripts = [ 90 | 91 | ]; 92 | 93 | private $base_url = ''; 94 | 95 | private $image_timeout = 10; 96 | 97 | public function __construct($arg = '') 98 | { 99 | if (is_array($arg)) { 100 | 101 | if (array_key_exists('image_base_url', $arg)) { 102 | $this->base_url = $arg['image_base_url']; 103 | } 104 | 105 | if (array_key_exists('image_timeout', $arg)) { 106 | $this->image_timeout = $arg['image_timeout']; 107 | } 108 | 109 | } else { 110 | $this->base_url = $arg; 111 | } 112 | } 113 | 114 | public function loadDefaultConverters() 115 | { 116 | $built_in_converters = [ 117 | new \magyarandras\AMPConverter\TagConverter\AMPImg($this->base_url, $this->image_timeout), 118 | new \magyarandras\AMPConverter\TagConverter\AMPYoutube, 119 | new \magyarandras\AMPConverter\TagConverter\AMPVideo, 120 | new \magyarandras\AMPConverter\TagConverter\AMPAudio, 121 | new \magyarandras\AMPConverter\TagConverter\AMPVimeo, 122 | new \magyarandras\AMPConverter\TagConverter\AMPFacebook, 123 | new \magyarandras\AMPConverter\TagConverter\AMPPinterest, 124 | new \magyarandras\AMPConverter\TagConverter\AMPPlaybuzz, 125 | new \magyarandras\AMPConverter\TagConverter\AMPImgur, 126 | new \magyarandras\AMPConverter\TagConverter\AMPDailymotion, 127 | new \magyarandras\AMPConverter\TagConverter\AMPGfycat, 128 | new \magyarandras\AMPConverter\TagConverter\AMPGist, 129 | new \magyarandras\AMPConverter\TagConverter\AMPTwitter, 130 | new \magyarandras\AMPConverter\TagConverter\AMPInstagram, 131 | new \magyarandras\AMPConverter\TagConverter\AMPVk, 132 | //AMPIframe must be the last 133 | new \magyarandras\AMPConverter\TagConverter\AMPIframe 134 | ]; 135 | 136 | 137 | foreach ($built_in_converters as $converter) { 138 | $this->converters[] = $converter; 139 | } 140 | } 141 | 142 | public function convert($html) 143 | { 144 | $html5 = new HTML5([ 145 | 'disable_html_ns' => true 146 | ]); 147 | $this->doc = $html5->loadHTML($html); 148 | 149 | $this->removeIncorrectDimensionAttributes(); 150 | 151 | foreach ($this->converters as $converter) { 152 | $result = $converter->convert($this->doc); 153 | $this->doc = $result; 154 | 155 | $this->scripts = array_unique(array_merge($this->scripts, $converter->getNecessaryScripts())); 156 | } 157 | 158 | $this->removeProhibitedTags(); 159 | $this->removeProhibitedAttributes(); 160 | 161 | $amphtml = $html5->saveHTML($this->doc); 162 | 163 | $to_replace = [ 164 | '', '', '', '', '', '', '' 165 | ]; 166 | 167 | $amphtml = str_replace($to_replace, '', $amphtml); 168 | 169 | $amphtml = trim($amphtml, "\n\r\0\x0B"); 170 | 171 | 172 | return $amphtml; 173 | } 174 | 175 | public function addConverter(TagConverterInterface $converter) 176 | { 177 | //array_unshift($this->converters, $converter); 178 | $this->converters[] = $converter; 179 | } 180 | 181 | 182 | //Remove prohibited tags 183 | private function removeProhibitedTags() 184 | { 185 | $query = '//' . implode('|//', $this->prohibited_tags); 186 | 187 | $xpath = new \DOMXPath($this->doc); 188 | 189 | $entries = $xpath->query($query); 190 | 191 | foreach ($entries as $entry) { 192 | if ($entry->parentNode !== null) { 193 | $entry->parentNode->removeChild($entry); 194 | } 195 | } 196 | } 197 | 198 | //Remove width and height attributes if they provided in percent 199 | private function removeIncorrectDimensionAttributes() 200 | { 201 | $xpath = new \DOMXPath($this->doc); 202 | 203 | $entries = $xpath->query('//*[contains(@width, "%") or contains(@height, "%") or @width="auto" or @height="auto"]'); 204 | 205 | foreach ($entries as $entry) { 206 | if ($entry->hasAttribute('width')) { 207 | $entry->removeAttribute('width'); 208 | } 209 | 210 | if ($entry->hasAttribute('height')) { 211 | $entry->removeAttribute('height'); 212 | } 213 | } 214 | } 215 | 216 | //Remove prohibited attributes 217 | private function removeProhibitedAttributes() 218 | { 219 | $xpath = new \DOMXPath($this->doc); 220 | 221 | foreach ($this->prohibited_attributes as $attribute=>$tags) { 222 | $entries = $xpath->query('//' . $tags . '[@'.$attribute.']'); 223 | 224 | foreach ($entries as $entry) { 225 | $entry->removeAttribute($attribute); 226 | } 227 | } 228 | 229 | //Remove anchors with href="javascript:*" 230 | $invalid_a_tags = $xpath->query('//a[starts-with(@href, "javascript:")]'); 231 | 232 | foreach ($invalid_a_tags as $tag) { 233 | $tag->parentNode->removeChild($tag); 234 | } 235 | } 236 | 237 | 238 | public function getScripts() 239 | { 240 | return $this->scripts; 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /src/TagConverter/AMPAudio.php: -------------------------------------------------------------------------------- 1 | '; 11 | 12 | public function convert(\DOMDocument $doc) 13 | { 14 | $query = '//audio'; 15 | 16 | $xpath = new \DOMXPath($doc); 17 | 18 | $entries = $xpath->query($query); 19 | 20 | if ($entries->length > 0) { 21 | $this->necessary_scripts[] = $this->extension_script; 22 | } 23 | 24 | $allowed_attributes = ['src', 'autoplay', 'controls', 'loop', 'crossorigin']; 25 | 26 | foreach ($entries as $tag) { 27 | $audio = $doc->createElement('amp-audio'); 28 | 29 | 30 | foreach ($allowed_attributes as $attribute) { 31 | if ($tag->hasAttribute($attribute)) { 32 | $audio->setAttribute($attribute, $tag->getAttribute($attribute)); 33 | } 34 | } 35 | 36 | if ($tag->hasChildNodes()) { 37 | foreach ($tag->childNodes as $node) { 38 | $audio->appendChild($node->cloneNode(true)); 39 | } 40 | } 41 | 42 | 43 | $tag->parentNode->replaceChild($audio, $tag); 44 | } 45 | 46 | return $doc; 47 | } 48 | 49 | public function getNecessaryScripts() 50 | { 51 | return $this->necessary_scripts; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/TagConverter/AMPDailymotion.php: -------------------------------------------------------------------------------- 1 | '; 11 | 12 | public function convert(\DOMDocument $doc) 13 | { 14 | $query = '//iframe[php:functionString(\'preg_match\', \'/dailymotion.com\/embed\/video\/([0-9a-zA-Z]+)/i\', @src) > 0]'; 15 | 16 | $xpath = new \DOMXPath($doc); 17 | 18 | $xpath->registerNamespace("php", "http://php.net/xpath"); 19 | $xpath->registerPhpFunctions('preg_match'); 20 | 21 | $entries = $xpath->query($query); 22 | 23 | if ($entries->length > 0) { 24 | $this->necessary_scripts[] = $this->extension_script; 25 | } 26 | 27 | foreach ($entries as $tag) { 28 | preg_match('/dailymotion.com\/embed\/video\/([0-9a-zA-Z]+)/i', $tag->getAttribute('src'), $id_match); 29 | $video_id = $id_match[1]; 30 | 31 | $dailymotion = $doc->createElement('amp-dailymotion'); 32 | 33 | $dailymotion->setAttribute('data-videoid', $video_id); 34 | $dailymotion->setAttribute('width', '480'); 35 | $dailymotion->setAttribute('height', '270'); 36 | $dailymotion->setAttribute('layout', 'responsive'); 37 | 38 | $tag->parentNode->replaceChild($dailymotion, $tag); 39 | } 40 | 41 | return $doc; 42 | } 43 | 44 | public function getNecessaryScripts() 45 | { 46 | return $this->necessary_scripts; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/TagConverter/AMPFacebook.php: -------------------------------------------------------------------------------- 1 | '; 11 | 12 | public function convert(\DOMDocument $doc) 13 | { 14 | $converted_doc = $this->convertScriptEmbeds($doc); 15 | $converted_doc = $this->convertIframeEmbeds($doc); 16 | 17 | return $converted_doc; 18 | } 19 | 20 | private function convertIframeEmbeds(\DOMDocument $doc) 21 | { 22 | $query = '//iframe[php:functionString(\'preg_match\', \'/\/plugins\/(video|post).php\?href=([^&]*)/i\', @src) > 0]'; 23 | 24 | $xpath = new \DOMXPath($doc); 25 | 26 | $xpath->registerNamespace("php", "http://php.net/xpath"); 27 | $xpath->registerPhpFunctions('preg_match'); 28 | 29 | $entries = $xpath->query($query); 30 | 31 | if ($entries->length > 0 && !$this->necessary_scripts) { 32 | $this->necessary_scripts[] = $this->extension_script; 33 | } 34 | 35 | foreach ($entries as $tag) { 36 | preg_match('/\/plugins\/(video|post).php\?href=([^&]*)/i', $tag->getAttribute('src'), $id_match); 37 | 38 | $type = $id_match[1]; 39 | $post_url = urldecode($id_match[2]); 40 | 41 | $fb_embed = $doc->createElement('amp-facebook'); 42 | 43 | if ($type == 'video') { 44 | $embed_type = 'video'; 45 | } else { 46 | $embed_type = 'post'; 47 | } 48 | 49 | $fb_embed->setAttribute('width', '552'); 50 | $fb_embed->setAttribute('height', '310'); 51 | $fb_embed->setAttribute('layout', 'responsive'); 52 | 53 | $fb_embed->setAttribute('data-href', $post_url); 54 | $fb_embed->setAttribute('data-embed-as', $embed_type); 55 | 56 | $tag->parentNode->replaceChild($fb_embed, $tag); 57 | } 58 | 59 | return $doc; 60 | } 61 | 62 | private function convertScriptEmbeds(\DOMDocument $doc) 63 | { 64 | $query = '//div[(@class="fb-post" or @class="fb-video" or @class="fb-comment-embed") and @data-href]'; 65 | 66 | $xpath = new \DOMXPath($doc); 67 | 68 | $entries = $xpath->query($query); 69 | 70 | if ($entries->length > 0 && !$this->necessary_scripts) { 71 | $this->necessary_scripts[] = $this->extension_script; 72 | } 73 | 74 | foreach ($entries as $tag) { 75 | if ($tag->hasAttribute('data-href')) { 76 | $fb_embed = $doc->createElement('amp-facebook'); 77 | 78 | if ($tag->getAttribute('class') == 'fb-video') { 79 | $embed_type = 'video'; 80 | } elseif ($tag->getAttribute('class') == 'fb-comment-embed') { 81 | $embed_type = 'comment'; 82 | } else { 83 | $embed_type = 'post'; 84 | } 85 | 86 | $fb_embed->setAttribute('width', '552'); 87 | $fb_embed->setAttribute('height', '310'); 88 | $fb_embed->setAttribute('layout', 'responsive'); 89 | 90 | $fb_embed->setAttribute('data-href', $tag->getAttribute('data-href')); 91 | $fb_embed->setAttribute('data-embed-as', $embed_type); 92 | 93 | $tag->parentNode->replaceChild($fb_embed, $tag); 94 | } else { 95 | $tag->parentNode->removeChild($tag); 96 | } 97 | } 98 | 99 | return $doc; 100 | } 101 | 102 | public function getNecessaryScripts() 103 | { 104 | return $this->necessary_scripts; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/TagConverter/AMPGfycat.php: -------------------------------------------------------------------------------- 1 | '; 11 | 12 | public function convert(\DOMDocument $doc) 13 | { 14 | $query = '//iframe[php:functionString(\'preg_match\', \'/gfycat.com\/ifr\/([0-9a-zA-Z]+)/i\', @src) > 0]'; 15 | 16 | $xpath = new \DOMXPath($doc); 17 | 18 | $xpath->registerNamespace("php", "http://php.net/xpath"); 19 | $xpath->registerPhpFunctions('preg_match'); 20 | 21 | $entries = $xpath->query($query); 22 | 23 | if ($entries->length > 0) { 24 | $this->necessary_scripts[] = $this->extension_script; 25 | } 26 | 27 | foreach ($entries as $tag) { 28 | preg_match('/gfycat.com\/ifr\/([0-9a-zA-Z]+)/i', $tag->getAttribute('src'), $id_match); 29 | $gfy_id = $id_match[1]; 30 | 31 | $gfycat = $doc->createElement('amp-gfycat'); 32 | 33 | $gfycat->setAttribute('data-gfyid', $gfy_id); 34 | $gfycat->setAttribute('width', '640'); 35 | $gfycat->setAttribute('height', '360'); 36 | $gfycat->setAttribute('layout', 'responsive'); 37 | 38 | $tag->parentNode->replaceChild($gfycat, $tag); 39 | } 40 | 41 | return $doc; 42 | } 43 | 44 | public function getNecessaryScripts() 45 | { 46 | return $this->necessary_scripts; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/TagConverter/AMPGist.php: -------------------------------------------------------------------------------- 1 | '; 12 | 13 | public function convert(\DOMDocument $doc) 14 | { 15 | 16 | // /https?\:\/\/gist.github.com\/.*\/([0-9a-z]+)\.js/i 17 | $query = '//script[php:functionString(\'preg_match\', \'/https?\:\/\/gist.github.com\/.*\/([0-9a-z]+)\.js/i\', @src) > 0]'; 18 | 19 | $xpath = new \DOMXPath($doc); 20 | 21 | $xpath->registerNamespace("php", "http://php.net/xpath"); 22 | $xpath->registerPhpFunctions('preg_match'); 23 | 24 | $entries = $xpath->query($query); 25 | 26 | if ($entries->length > 0) { 27 | $this->necessary_scripts[] = $this->extension_script; 28 | } 29 | 30 | foreach ($entries as $tag) { 31 | preg_match('/https?\:\/\/gist.github.com\/.*\/([0-9a-z]+)\.js/i', $tag->getAttribute('src'), $id_match); 32 | $gist_id = $id_match[1]; 33 | 34 | $gist = $doc->createElement('amp-gist'); 35 | 36 | $gist->setAttribute('data-gistid', $gist_id); 37 | $gist->setAttribute('layout', 'fixed-height'); 38 | $gist->setAttribute('height', '250'); 39 | 40 | $tag->parentNode->replaceChild($gist, $tag); 41 | } 42 | 43 | return $doc; 44 | } 45 | 46 | public function getNecessaryScripts() 47 | { 48 | return $this->necessary_scripts; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/TagConverter/AMPIframe.php: -------------------------------------------------------------------------------- 1 | '; 11 | 12 | public function convert(\DOMDocument $doc) 13 | { 14 | $query = '//iframe'; 15 | 16 | $xpath = new \DOMXPath($doc); 17 | 18 | $entries = $xpath->query($query); 19 | 20 | if ($entries->length > 0) { 21 | $this->necessary_scripts[] = $this->extension_script; 22 | } 23 | 24 | foreach ($entries as $tag) { 25 | if ($tag->hasAttribute('width') && $tag->hasAttribute('height')) { 26 | $width = $tag->getAttribute('width'); 27 | $height = $tag->getAttribute('height'); 28 | } else { 29 | $width = '600'; 30 | $height = '450'; 31 | } 32 | 33 | if ($tag->getAttribute('sandbox')) { 34 | $sandbox = $tag->getAttribute('sandbox'); 35 | } else { 36 | $sandbox = 'allow-scripts allow-same-origin allow-popups'; 37 | } 38 | 39 | $src = $tag->getAttribute('src'); 40 | 41 | $ampiframe = $doc->createElement('amp-iframe'); 42 | 43 | $ampiframe->setAttribute('src', $src); 44 | $ampiframe->setAttribute('sandbox', $sandbox); 45 | $ampiframe->setAttribute('width', $width); 46 | $ampiframe->setAttribute('height', $height); 47 | 48 | if ($tag->hasAttribute('allowfullscreen')) { 49 | $ampiframe->setAttribute('allowfullscreen', ''); 50 | } 51 | 52 | $ampiframe->setAttribute('layout', 'responsive'); 53 | 54 | //Add a placeholder to the amp-iframe element so it can be embedded even above the fold. 55 | $placeholder = $doc->createElement('p'); 56 | $placeholder->setAttribute('placeholder', ''); 57 | $placeholder_text = $doc->createTextNode('Loading...'); 58 | $placeholder->appendChild($placeholder_text); 59 | $ampiframe->appendChild($placeholder); 60 | 61 | $tag->parentNode->replaceChild($ampiframe, $tag); 62 | } 63 | 64 | return $doc; 65 | } 66 | 67 | public function getNecessaryScripts() 68 | { 69 | return $this->necessary_scripts; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/TagConverter/AMPImg.php: -------------------------------------------------------------------------------- 1 | base_url = $base_url; 22 | $this->timeout = $timeout; 23 | } 24 | 25 | public function convert(\DOMDocument $doc) 26 | { 27 | 28 | $query = '//img'; 29 | 30 | $xpath = new \DOMXPath($doc); 31 | 32 | $entries = $xpath->query($query); 33 | 34 | $allowed_attributes = ['src', 'width', 'height', 'alt', 'srcset', 'sizes']; 35 | 36 | foreach ($entries as $tag) { 37 | if ($tag->hasAttribute('src')) { 38 | $img = $doc->createElement('amp-img'); 39 | 40 | if (!$tag->hasAttribute('width') || !$tag->hasAttribute('height')) { 41 | $imageSize = ImageSize::getImageSize( 42 | $this->base_url, 43 | $tag->getAttribute('src'), 44 | $this->timeout 45 | ); 46 | 47 | if ($imageSize) { 48 | $img->setAttribute('width', $imageSize['width']); 49 | $img->setAttribute('height', $imageSize['height']); 50 | } else { 51 | $tag->parentNode->removeChild($tag); 52 | continue; 53 | } 54 | } 55 | 56 | foreach ($allowed_attributes as $attribute) { 57 | if ($tag->hasAttribute($attribute)) { 58 | $img->setAttribute($attribute, $tag->getAttribute($attribute)); 59 | } 60 | } 61 | 62 | $img->setAttribute('layout', 'responsive'); 63 | 64 | $tag->parentNode->replaceChild($img, $tag); 65 | } else { 66 | $tag->parentNode->removeChild($tag); 67 | } 68 | } 69 | 70 | return $doc; 71 | } 72 | 73 | public function getNecessaryScripts() 74 | { 75 | return $this->necessary_scripts; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/TagConverter/AMPImgLightbox.php: -------------------------------------------------------------------------------- 1 | '; 14 | 15 | 16 | //Base URL of the images 17 | private $base_url; 18 | 19 | //Time limit for acquiring image dimensions in seconds 20 | private $timeout; 21 | 22 | public function __construct($base_url = '', $timeout = 10) 23 | { 24 | $this->base_url = $base_url; 25 | $this->timeout = $timeout; 26 | } 27 | 28 | public function convert(\DOMDocument $doc) 29 | { 30 | $query = '//img'; 31 | 32 | $xpath = new \DOMXPath($doc); 33 | 34 | $entries = $xpath->query($query); 35 | 36 | if ($entries->length > 0) { 37 | $this->necessary_scripts[] = $this->extension_script; 38 | } 39 | 40 | $allowed_attributes = ['src', 'width', 'height', 'alt', 'srcset', 'sizes']; 41 | 42 | foreach ($entries as $tag) { 43 | if ($tag->hasAttribute('src')) { 44 | $img = $doc->createElement('amp-img'); 45 | 46 | if (!$tag->hasAttribute('width') || !$tag->hasAttribute('height')) { 47 | $imageSize = ImageSize::getImageSize( 48 | $this->base_url, 49 | $tag->getAttribute('src'), 50 | $this->timeout 51 | ); 52 | 53 | if ($imageSize) { 54 | $img->setAttribute('width', $imageSize['width']); 55 | $img->setAttribute('height', $imageSize['height']); 56 | } else { 57 | $tag->parentNode->removeChild($tag); 58 | continue; 59 | } 60 | } 61 | 62 | foreach ($allowed_attributes as $attribute) { 63 | if ($tag->hasAttribute($attribute)) { 64 | $img->setAttribute($attribute, $tag->getAttribute($attribute)); 65 | } 66 | } 67 | 68 | $img->setAttribute('layout', 'responsive'); 69 | $img->setAttribute('lightbox', ''); 70 | 71 | $tag->parentNode->replaceChild($img, $tag); 72 | } else { 73 | $tag->parentNode->removeChild($tag); 74 | } 75 | } 76 | 77 | return $doc; 78 | } 79 | 80 | public function getNecessaryScripts() 81 | { 82 | return $this->necessary_scripts; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/TagConverter/AMPImgZoom.php: -------------------------------------------------------------------------------- 1 | '; 12 | 13 | //Base URL of the images 14 | private $base_url; 15 | 16 | //Time limit for acquiring image dimensions in seconds 17 | private $timeout; 18 | 19 | public function __construct($base_url = '', $timeout = 10) 20 | { 21 | $this->base_url = $base_url; 22 | $this->timeout = $timeout; 23 | } 24 | 25 | public function convert(\DOMDocument $doc) 26 | { 27 | $query = '//img'; 28 | 29 | $xpath = new \DOMXPath($doc); 30 | 31 | $entries = $xpath->query($query); 32 | 33 | $allowed_attributes = ['src', 'alt', 'srcset', 'sizes']; 34 | 35 | foreach ($entries as $tag) { 36 | if ($tag->hasAttribute('src')) { 37 | if (!$tag->hasAttribute('width') || !$tag->hasAttribute('height')) { 38 | 39 | $imageSize = ImageSize::getImageSize( 40 | $this->base_url, 41 | $tag->getAttribute('src'), 42 | $this->timeout 43 | ); 44 | 45 | if ($imageSize) { 46 | $width = $imageSize['width']; 47 | $height = $imageSize['height']; 48 | } else { 49 | $tag->parentNode->removeChild($tag); 50 | continue; 51 | } 52 | } else { 53 | $width = $tag->getAttribute('width'); 54 | $height = $tag->getAttribute('height'); 55 | } 56 | 57 | if (!$this->necessary_scripts) { 58 | $this->necessary_scripts[] = $this->extension_script; 59 | } 60 | 61 | $img = $doc->createElement('amp-img'); 62 | 63 | $panzoom = $doc->createElement('amp-pan-zoom'); 64 | 65 | foreach ($allowed_attributes as $attribute) { 66 | if ($tag->hasAttribute($attribute)) { 67 | $img->setAttribute($attribute, $tag->getAttribute($attribute)); 68 | } 69 | } 70 | 71 | $img->setAttribute('layout', 'fill'); 72 | 73 | $panzoom->setAttribute('width', $width); 74 | $panzoom->setAttribute('height', $height); 75 | $panzoom->setAttribute('layout', 'responsive'); 76 | 77 | $panzoom->appendChild($img); 78 | 79 | $tag->parentNode->replaceChild($panzoom, $tag); 80 | } else { 81 | $tag->parentNode->removeChild($tag); 82 | } 83 | } 84 | 85 | return $doc; 86 | } 87 | 88 | public function getNecessaryScripts() 89 | { 90 | return $this->necessary_scripts; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/TagConverter/AMPImgur.php: -------------------------------------------------------------------------------- 1 | '; 11 | 12 | public function convert(\DOMDocument $doc) 13 | { 14 | //can't see? no problem
15 | $query = '//blockquote[@class="imgur-embed-pub" and @data-id]';
16 |
17 | $xpath = new \DOMXPath($doc);
18 |
19 | $entries = $xpath->query($query);
20 |
21 | if ($entries->length > 0) {
22 | $this->necessary_scripts[] = $this->extension_script;
23 | }
24 |
25 | foreach ($entries as $tag) {
26 | if ($tag->hasAttribute('data-id')) {
27 | $imgur = $doc->createElement('amp-imgur');
28 |
29 | $imgur->setAttribute('data-imgur-id', $tag->getAttribute('data-id'));
30 |
31 | $imgur->setAttribute('width', '540');
32 | $imgur->setAttribute('height', '670');
33 | $imgur->setAttribute('layout', 'responsive');
34 |
35 |
36 | $tag->parentNode->replaceChild($imgur, $tag);
37 | } else {
38 | $tag->parentNode->removeChild($tag);
39 | }
40 | }
41 |
42 | return $doc;
43 | }
44 |
45 | public function getNecessaryScripts()
46 | {
47 | return $this->necessary_scripts;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/TagConverter/AMPInstagram.php:
--------------------------------------------------------------------------------
1 | ';
12 |
13 | public function convert(\DOMDocument $doc)
14 | {
15 |
16 | // /instagram.com\/(p|tv|reel)\/([0-9a-zA-Z_\-]+)/i
17 | $query = '//blockquote[@class="instagram-media" and php:functionString(\'preg_match\', \'/instagram.com\/(p|tv|reel)\/([0-9a-zA-Z_\-]+)/i\', @data-instgrm-permalink) > 0]';
18 |
19 | $xpath = new \DOMXPath($doc);
20 |
21 | $xpath->registerNamespace("php", "http://php.net/xpath");
22 | $xpath->registerPhpFunctions('preg_match');
23 |
24 | $entries = $xpath->query($query);
25 |
26 | if ($entries->length > 0) {
27 | $this->necessary_scripts[] = $this->extension_script;
28 | }
29 |
30 | foreach ($entries as $tag) {
31 | preg_match('/instagram.com\/(p|tv|reel)\/([0-9a-zA-Z_\-]+)/i', $tag->getAttribute('data-instgrm-permalink'), $id_match);
32 | $post_id = $id_match[2];
33 |
34 | $ampinstagram = $doc->createElement('amp-instagram');
35 |
36 | $ampinstagram->setAttribute('data-shortcode', $post_id);
37 | $ampinstagram->setAttribute('data-captioned', '');
38 | $ampinstagram->setAttribute('width', '400');
39 | $ampinstagram->setAttribute('height', '400');
40 | $ampinstagram->setAttribute('layout', 'responsive');
41 |
42 | $tag->parentNode->replaceChild($ampinstagram, $tag);
43 | }
44 |
45 | return $doc;
46 | }
47 |
48 | public function getNecessaryScripts()
49 | {
50 | return $this->necessary_scripts;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/TagConverter/AMPPinterest.php:
--------------------------------------------------------------------------------
1 | ';
11 |
12 | public function convert(\DOMDocument $doc)
13 | {
14 | $query = '//a[@data-pin-do="embedPin" and @href]';
15 |
16 | $xpath = new \DOMXPath($doc);
17 |
18 | $entries = $xpath->query($query);
19 |
20 | if ($entries->length > 0) {
21 | $this->necessary_scripts[] = $this->extension_script;
22 | }
23 |
24 | foreach ($entries as $tag) {
25 | if ($tag->hasAttribute('href')) {
26 | $pin_embed = $doc->createElement('amp-pinterest');
27 |
28 | $pin_embed->setAttribute('width', '552');
29 | $pin_embed->setAttribute('height', '310');
30 | $pin_embed->setAttribute('layout', 'responsive');
31 |
32 | $pin_embed->setAttribute('data-url', $tag->getAttribute('href'));
33 | $pin_embed->setAttribute('data-do', 'embedPin');
34 |
35 | $tag->parentNode->replaceChild($pin_embed, $tag);
36 | } else {
37 | $tag->parentNode->removeChild($tag);
38 | }
39 | }
40 |
41 | return $doc;
42 | }
43 |
44 | public function getNecessaryScripts()
45 | {
46 | return $this->necessary_scripts;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/TagConverter/AMPPlaybuzz.php:
--------------------------------------------------------------------------------
1 | ';
11 |
12 | public function convert(\DOMDocument $doc)
13 | {
14 | $query = '//div[@class="playbuzz" and @data-id]';
15 |
16 | $xpath = new \DOMXPath($doc);
17 |
18 | $entries = $xpath->query($query);
19 |
20 | if ($entries->length > 0) {
21 | $this->necessary_scripts[] = $this->extension_script;
22 | }
23 |
24 | foreach ($entries as $tag) {
25 | if ($tag->hasAttribute('data-id')) {
26 | $playbuzz = $doc->createElement('amp-playbuzz');
27 |
28 | $playbuzz->setAttribute('height', '700');
29 |
30 | $playbuzz->setAttribute('data-item', $tag->getAttribute('data-id'));
31 | $playbuzz->setAttribute('data-share-buttons', 'true');
32 |
33 | $tag->parentNode->replaceChild($playbuzz, $tag);
34 | } else {
35 | $tag->parentNode->removeChild($tag);
36 | }
37 | }
38 |
39 | return $doc;
40 | }
41 |
42 | public function getNecessaryScripts()
43 | {
44 | return $this->necessary_scripts;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/TagConverter/AMPTwitter.php:
--------------------------------------------------------------------------------
1 | ';
12 |
13 | public function convert(\DOMDocument $doc)
14 | {
15 |
16 | // /https?\:\/\/twitter.com\/.*\/status\/([0-9a-z]+)/i
17 | $query = '//blockquote[@class="twitter-tweet"]/a[php:functionString(\'preg_match\', \'/https?\:\/\/twitter.com\/.*\/status\/([0-9a-z]+)/i\', @href) > 0]';
18 |
19 | $xpath = new \DOMXPath($doc);
20 |
21 | $xpath->registerNamespace("php", "http://php.net/xpath");
22 | $xpath->registerPhpFunctions('preg_match');
23 |
24 | $entries = $xpath->query($query);
25 |
26 | if ($entries->length > 0) {
27 | $this->necessary_scripts[] = $this->extension_script;
28 | }
29 |
30 | foreach ($entries as $tag) {
31 | preg_match('/https?\:\/\/twitter.com\/.*\/status\/([0-9a-z]+)/i', $tag->getAttribute('href'), $id_match);
32 | $post_id = $id_match[1];
33 |
34 | $amptwitter = $doc->createElement('amp-twitter');
35 |
36 |
37 | $amptwitter->setAttribute('width', '375');
38 | $amptwitter->setAttribute('height', '472');
39 | $amptwitter->setAttribute('layout', 'responsive');
40 | $amptwitter->setAttribute('data-tweetid', $post_id);
41 |
42 | $tag->parentNode->parentNode->replaceChild($amptwitter, $tag->parentNode);
43 | }
44 |
45 | return $doc;
46 | }
47 |
48 | public function getNecessaryScripts()
49 | {
50 | return $this->necessary_scripts;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/TagConverter/AMPVideo.php:
--------------------------------------------------------------------------------
1 | ';
11 |
12 | public function convert(\DOMDocument $doc)
13 | {
14 | $query = '//video';
15 |
16 | $xpath = new \DOMXPath($doc);
17 |
18 | $entries = $xpath->query($query);
19 |
20 | if ($entries->length > 0) {
21 | $this->necessary_scripts[] = $this->extension_script;
22 | }
23 |
24 | $allowed_attributes = ['src', 'poster', 'autoplay', 'controls', 'loop', 'crossorigin'];
25 |
26 | foreach ($entries as $tag) {
27 | if ($tag->hasAttribute('width') && $tag->hasAttribute('height')) {
28 | $width = $tag->getAttribute('width');
29 | $height = $tag->getAttribute('height');
30 |
31 |
32 | $video = $doc->createElement('amp-video');
33 |
34 | $video->setAttribute('width', $width);
35 | $video->setAttribute('height', $height);
36 | $video->setAttribute('layout', 'responsive');
37 |
38 |
39 | foreach ($allowed_attributes as $attribute) {
40 | if ($tag->hasAttribute($attribute)) {
41 | $video->setAttribute($attribute, $tag->getAttribute($attribute));
42 | }
43 | }
44 |
45 | if ($tag->hasChildNodes()) {
46 | foreach ($tag->childNodes as $node) {
47 | $video->appendChild($node->cloneNode(true));
48 | }
49 | }
50 |
51 |
52 | $tag->parentNode->replaceChild($video, $tag);
53 | } else {
54 | $tag->parentNode->removeChild($tag);
55 | }
56 | }
57 |
58 | return $doc;
59 | }
60 |
61 | public function getNecessaryScripts()
62 | {
63 | return $this->necessary_scripts;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/TagConverter/AMPVimeo.php:
--------------------------------------------------------------------------------
1 | ';
11 |
12 | public function convert(\DOMDocument $doc)
13 | {
14 | $query = '//iframe[php:functionString(\'preg_match\', \'/https?:\/\/player.vimeo.com\/video\/([0-9]+)/i\', @src) > 0]';
15 |
16 | $xpath = new \DOMXPath($doc);
17 |
18 | $xpath->registerNamespace("php", "http://php.net/xpath");
19 | $xpath->registerPhpFunctions('preg_match');
20 |
21 | $entries = $xpath->query($query);
22 |
23 | if ($entries->length > 0) {
24 | $this->necessary_scripts[] = $this->extension_script;
25 | }
26 |
27 | foreach ($entries as $tag) {
28 | preg_match('/https?:\/\/player.vimeo.com\/video\/([0-9]+)/i', $tag->getAttribute('src'), $id_match);
29 | $video_id = $id_match[1];
30 |
31 | $vimeo = $doc->createElement('amp-vimeo');
32 |
33 | $vimeo->setAttribute('data-videoid', $video_id);
34 | $vimeo->setAttribute('width', '500');
35 | $vimeo->setAttribute('height', '281');
36 | $vimeo->setAttribute('layout', 'responsive');
37 |
38 | $tag->parentNode->replaceChild($vimeo, $tag);
39 | }
40 |
41 | return $doc;
42 | }
43 |
44 | public function getNecessaryScripts()
45 | {
46 | return $this->necessary_scripts;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/TagConverter/AMPVk.php:
--------------------------------------------------------------------------------
1 | ';
16 |
17 | public function convert(\DOMDocument $doc)
18 | {
19 | $query = '//script[contains(., "VK.Widgets.Post")]';
20 | $expression = '/VK.Widgets.Post[\n\r\s]*\([\n\r\s]*["|\'](.*)["|\'][\n\r\s]*,[\n\r\s]*([0-9]+)[\n\r\s]*,[\n\r\s]*([0-9]+)[\n\r\s]*,[\n\r\s]*["|\']([0-9a-zA-Z]+)["|\']/';
21 |
22 |
23 | $xpath = new \DOMXPath($doc);
24 |
25 | $xpath->registerNamespace("php", "http://php.net/xpath");
26 | $xpath->registerPhpFunctions('preg_match');
27 |
28 | $entries = $xpath->query($query);
29 |
30 | foreach ($entries as $tag) {
31 | if (preg_match($expression, $tag->nodeValue, $data)) {
32 | $tag_id = $data[1];
33 | $owner_id = $data[2];
34 | $post_id = $data[3];
35 | $hash = $data[4];
36 |
37 | $embed_container = $xpath->query('div[@id="'.$tag_id.'"]');
38 |
39 | if ($embed_container->length > 0) {
40 | $vk_container = $embed_container[0];
41 |
42 | $ampvk = $doc->createElement('amp-vk');
43 | $ampvk->setAttribute('data-embedtype', 'post');
44 | $ampvk->setAttribute('data-owner-id', $owner_id);
45 | $ampvk->setAttribute('data-post-id', $post_id);
46 | $ampvk->setAttribute('data-hash', $hash);
47 | $ampvk->setAttribute('width', '500');
48 | $ampvk->setAttribute('height', '300');
49 | $ampvk->setAttribute('layout', 'responsive');
50 |
51 | $vk_container->parentNode->replaceChild($ampvk, $vk_container);
52 |
53 | if (!$this->necessary_scripts) {
54 | $this->necessary_scripts[] = $this->extension_script;
55 | }
56 | }
57 | }
58 | }
59 |
60 | return $doc;
61 | }
62 |
63 | public function getNecessaryScripts()
64 | {
65 | return $this->necessary_scripts;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/TagConverter/AMPYoutube.php:
--------------------------------------------------------------------------------
1 | ';
11 |
12 | public function convert(\DOMDocument $doc)
13 | {
14 | $query = '//iframe[php:functionString(\'preg_match\', \'/youtube\.com\/(?:v|embed)\/([a-zA-z0-9_-]+)/i\', @src) > 0]';
15 |
16 | $xpath = new \DOMXPath($doc);
17 |
18 | $xpath->registerNamespace("php", "http://php.net/xpath");
19 | $xpath->registerPhpFunctions('preg_match');
20 |
21 | $entries = $xpath->query($query);
22 |
23 | if ($entries->length > 0) {
24 | $this->necessary_scripts[] = $this->extension_script;
25 | }
26 |
27 | foreach ($entries as $tag) {
28 | preg_match('/youtube\.com\/(?:v|embed)\/([a-zA-z0-9_-]+)/i', $tag->getAttribute('src'), $id_match);
29 | $video_id = $id_match[1];
30 |
31 | $youtube_video = $doc->createElement('amp-youtube');
32 |
33 | $youtube_video->setAttribute('data-videoid', $video_id);
34 | $youtube_video->setAttribute('width', '480');
35 | $youtube_video->setAttribute('height', '270');
36 | $youtube_video->setAttribute('layout', 'responsive');
37 |
38 | $tag->parentNode->replaceChild($youtube_video, $tag);
39 | }
40 |
41 | return $doc;
42 | }
43 |
44 | public function getNecessaryScripts()
45 | {
46 | return $this->necessary_scripts;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/TagConverterInterface.php:
--------------------------------------------------------------------------------
1 | setTimeout($timeout);
10 |
11 | if (preg_match('/https?:\/\//i', $url)) {
12 | $img_url = $url;
13 | } else {
14 | if (substr($base_url, -1) == '/') {
15 | $base_url = substr($base_url, 0, -1);
16 | }
17 |
18 | if (substr($url, 0, 1) == '/') {
19 | $url = substr($url, 1);
20 | }
21 |
22 | $img_url = $base_url . '/' . $url;
23 | }
24 |
25 | $imageSize = $fasterImageSize->batch([
26 | $img_url
27 | ]);
28 |
29 | if ($imageSize[$img_url]['size'] == 'failed') {
30 | return null;
31 | }
32 |
33 | list($width, $height) = $imageSize[$img_url]['size'];
34 | return [
35 | 'width' => $width,
36 | 'height' => $height,
37 | 'type' => $imageSize[$img_url]['type']
38 | ];
39 |
40 | }
41 | }
42 |
--------------------------------------------------------------------------------