compatibility
5 months ago
config
5 months ago
css
5 months ago
data
3 years ago
images
3 years ago
js
5 months ago
vendor
4 months ago
views
2 months ago
class-tiny-apache-rewrite.php
2 months ago
class-tiny-bulk-optimization.php
5 months ago
class-tiny-cli.php
5 months ago
class-tiny-compress-client.php
5 months ago
class-tiny-compress-fopen.php
5 months ago
class-tiny-compress.php
5 months ago
class-tiny-conversion.php
2 months ago
class-tiny-diagnostics.php
5 months ago
class-tiny-exception.php
5 months ago
class-tiny-helpers.php
5 months ago
class-tiny-image-size.php
5 months ago
class-tiny-image.php
5 months ago
class-tiny-logger.php
2 months ago
class-tiny-notices.php
2 months ago
class-tiny-php.php
5 months ago
class-tiny-picture.php
4 months ago
class-tiny-plugin.php
2 months ago
class-tiny-settings.php
2 months ago
class-tiny-source-base.php
2 months ago
class-tiny-source-image.php
5 months ago
class-tiny-source-picture.php
5 months ago
class-tiny-wp-base.php
5 months ago
class-tiny-source-image.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * Tiny Compress Images - WordPress plugin. |
| 5 | * Copyright (C) 2015-2018 Tinify B.V. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the Free |
| 9 | * Software Foundation; either version 2 of the License, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., 51 |
| 19 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
| 22 | class Tiny_Source_Image extends Tiny_Source_Base { |
| 23 | |
| 24 | /** |
| 25 | * Generates a formatted image source array if the corresponding local file exists. |
| 26 | * |
| 27 | * Attempts to replace the file extension of the provided image path with the |
| 28 | * specified MIME type, resolves the local path of the resulting file, and returns |
| 29 | * the `srcset` and `type` if the file exists. |
| 30 | * |
| 31 | * @return string a <picture> element contain additional sources |
| 32 | */ |
| 33 | public function create_picture_elements() { |
| 34 | $sources = $this->create_alternative_sources( $this->raw_html ); |
| 35 | if ( empty( $sources ) ) { |
| 36 | return $this->raw_html; |
| 37 | } |
| 38 | $picture_element = array( '<picture>' ); |
| 39 | $picture_element[] = implode( '', $sources ); |
| 40 | $picture_element[] = $this->raw_html; |
| 41 | $picture_element[] = '</picture>'; |
| 42 | |
| 43 | return implode( '', $picture_element ); |
| 44 | } |
| 45 | } |
| 46 |