psf
alert.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__) . "/../html/divcontainer.php");
21 
22 class BS_Alert extends DivContainer
23 {
24  public $Text;
25  public $Type;
26  public $EscapeHTML = true;
27  public $IsDismissable = true;
28 
29  public function __construct($_text, $_type = "success", $_parent = NULL)
30  {
31  $this->Text = $_text;
32  $this->Type = $_type;
33  parent::__construct($_parent);
34  }
35 
36  private function getClass()
37  {
38  $class = "alert alert-" . $this->Type;
39  if ($this->IsDismissable)
40  $class .= " alert-dismissable";
41  return $class;
42  }
43 
44  public function ToHtml()
45  {
46  if ($this->EscapeHTML)
47  $this->AppendHtmlLine(htmlspecialchars($this->Text));
48  else
49  $this->AppendHtmlLine($this->Text);
50  if ($this->ClassName === NULL)
51  {
52  $this->ClassName = $this->getClass();
53  } else
54  {
55  $this->ClassName = $this->getClass() . " " . $this->ClassName;
56  }
57  return parent::ToHtml();
58  }
59 }
AppendHtmlLine($html, $indent=-1)
Insert a line of html into body of a page (to bottom of the body). If $indent contains anything else ...
Definition: container.php:45
Represents a simple div container that can contain html elements.
$ClassName
The class of html element, if HTML5, this will be added as <element class="text"> if not NULL...
Definition: element.php:29