| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  *  ____  _     _                       _ _ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * |  _ \| |__ | |_ ___ _ __ ___   __ _(_) | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | |_) | '_ \| __/ _ \ '_ ` _ \ / _` | | | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * |  __/| | | | ||  __/ | | | | | (_| | | | | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * |_|   |_| |_|\__\___|_| |_| |_|\__,_|_|_| | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * This file is part of Kristuff\Phtemail. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * (c) Kristuff <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @version    0.2.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @copyright  2017-2020 Kristuff | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | namespace Kristuff\Phtemail\HtmlElements; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Kristuff\Phtemail\Core\HtmlElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * Class image | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * Represents an image tag (<img>) in html content. Image will take full container width  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * in mobile, and respect given width otherwise.   | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | class Image extends HtmlElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @access private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var string  $imageSrc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     private $imageSrc = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @access private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @var string  $imageTitle | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     private $imageTitle = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @access private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * @var string  $imageAlt | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     private $imageAlt = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @access private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @var int     $imageWidth | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     private $imageWidth = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @access private | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @var null|int     $imageMaxHeight | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     private $imageMaxHeight = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * Constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @param string    $src       The image source | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @param int       $width     The image width | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @param string    $title     The image title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @param string    $alt       The image alt | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |     public function __construct(string $src, int $width, string $title = '', string $alt = '') | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         $this->imageSrc   = $src; | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |         $this->imageWidth = $width; | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         $this->imageTitle = $title; | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |         $this->imageAlt   = $alt; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     /**  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * Sets the image max height  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @param int       $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @return void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      */    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     public function setMaxHeight(int $value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $this->imageMaxHeight = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     /**  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * Gets the HTML  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @access public | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @param string    $indent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      *  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     public function getHtml(string $indent) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         return $this->getBuilder()->getHtmlComment('IMAGE', $indent) . $indent  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                              . '<img class="flexibleImage"' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                              . ' src="'. $this->imageSrc . '"'  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                              . ' width="'. strval($this->imageWidth) . '"'  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                              . ' alt="'. $this->imageAlt . '"'  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                              . ' title="'. $this->imageTitle . '"'  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                              . ' style="max-width:'. strval($this->imageWidth) .'px;width:100%;display:block;' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                              . (empty($this->imageMaxHeight) ? '' : 'max-height:'. strval($this->imageMaxHeight) .'px;') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                              . '"/>'; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 111 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 112 |  |  | } |