psf
 All Classes Functions Variables
image.php
1 <?php
2 
3 // Part of simple php framework (spf)
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 - 2017
16 
17 require_once (dirname(__FILE__) . "/../../functions.php");
18 require_once (dirname(__FILE__) . "/element.php");
19 
20 class Image extends HtmlElement
21 {
22  public $Format = NULL;
23  public $Height = NULL;
24  public $Width = NULL;
25  public $URL = NULL;
26  public $AlternateText = "";
27  public $Title = NULL;
28 
29  public function __construct($image, $alt = "", $w = NULL, $h = NULL, $_parent = NULL)
30  {
31  parent::__construct($_parent = NULL);
32  $this->URL = $image;
33  $this->AlternateText = $alt;
34  $this->Height = $h;
35  $this->Width = $w;
36  }
37 
38  public function GetFormat()
39  {
40  $f = " alt=\"" . $this->AlternateText . "\"";
41  if ($this->Width !== NULL)
42  $f .= " width=\"" . $this->Width . "\"";
43  if ($this->Height !== NULL)
44  $f .= " height=\"" . $this->Height . "\"";
45  if ($this->Style !== NULL)
46  $f .= " style=\"" . $this->Style->ToCss() . "\"";
47  if ($this->Format !== NULL)
48  {
49  $f .= " $this->Format";
50  }
51  return $f;
52  }
53 
54  public function ToHtml()
55  {
56  $html = "<img src=\"" . $this->URL . "\"" . $this->GetFormat();
57  if ($this->Title !== NULL)
58  $html .= " title=\"" . $this->Title . "\"";
59  if ($this->ClassName !== NULL)
60  $html .= " class=\"" . $this->ClassName . "\"";
61  $html .= ">";
62  if ($this->Style !== NULL)
63  {
64  $style = $this->Style->ToCss();
65  if (strlen($style) > 0)
66  $html .= " style=\"" . $style . "\"";
67  }
68  return $html;
69  }
70 }