psf
image.php
1 <?php
2 
3 // Part of php simple framework (psf)
4 
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 
15 // Copyright (c) Petr Bena <petr@bena.rocks> 2015 - 2018
16 
17 if (!defined("PSF_ENTRY_POINT"))
18  die("Not a valid psf entry point");
19 
20 require_once (dirname(__FILE__) . "/../../functions.php");
21 require_once (dirname(__FILE__) . "/element.php");
22 
23 class Image extends HtmlElement
24 {
25  public $Format = NULL;
26  public $Height = NULL;
27  public $Width = NULL;
28  public $URL = NULL;
29  public $AlternateText = "";
30  public $Title = NULL;
31 
32  public function __construct($image, $alt = "", $w = NULL, $h = NULL, $_parent = NULL)
33  {
34  parent::__construct($_parent = NULL);
35  $this->URL = $image;
36  $this->AlternateText = $alt;
37  $this->Height = $h;
38  $this->Width = $w;
39  }
40 
41  public function GetFormat()
42  {
43  $f = " alt=\"" . $this->AlternateText . "\"";
44  if ($this->Width !== NULL)
45  $f .= " width=\"" . $this->Width . "\"";
46  if ($this->Height !== NULL)
47  $f .= " height=\"" . $this->Height . "\"";
48  if ($this->Style !== NULL)
49  $f .= " style=\"" . $this->Style->ToCss() . "\"";
50  if ($this->Format !== NULL)
51  {
52  $f .= " $this->Format";
53  }
54  return $f;
55  }
56 
57  public function ToHtml()
58  {
59  $html = "<img src=\"" . $this->URL . "\"" . $this->GetFormat();
60  if ($this->Title !== NULL)
61  $html .= " title=\"" . $this->Title . "\"";
62  if ($this->ClassName !== NULL)
63  $html .= " class=\"" . $this->ClassName . "\"";
64  $html .= ">";
65  if ($this->Style !== NULL)
66  {
67  $style = $this->Style->ToCss();
68  if (strlen($style) > 0)
69  $html .= " style=\"" . $style . "\"";
70  }
71  return $html;
72  }
73 }
Definition: image.php:23