Welcome to mirror list, hosted at ThFree Co, Russian Federation.

XHtmlElement.php « xhtml « src - github.com/HuasoFoundries/phpPgAdmin6.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dcd600eb89eea24782e4bf4bb05627e0093ede83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php

/**
 * PHPPgAdmin 6.1.3
 */

namespace PHPPgAdmin\XHtml;

/**
 *  XHtmlElement.
 *
 *  Used to generate Xhtml-Code for xhtml elements
 *  that can contain child elements
 */
class XHtmlElement extends XHtmlSimpleElement
{
    public $_text;

    public $_htmlcode = '';

    public $_siblings = [];

    public function __construct($text = null)
    {
        parent::__construct();

        if ($text) {
            $this->set_text($text);
        }
    }

    /**
     * Adds an xhtml child to element.
     *
     * @param XHtmlOption $object
     */
    public function add(XHtmlOption &$object): void
    {
        \array_push($this->_siblings, $object);
    }

    /**
     * The CDATA section of Element.
     *
     * @param string $text Text content of the element
     */
    public function set_text($text): void
    {
        if ($text) {
            $this->_text = \htmlspecialchars($text);
        }
    }

    public function fetch()
    {
        return $this->_html();
    }

    /**
     * @return string
     */
    public function _html()
    {
        $this->_htmlcode = "<{$this->_element}";

        foreach ($this->_attributes as $attribute => $value) {
            if (!empty($value)) {
                $this->_htmlcode .= \sprintf(' %s="%s" ', $attribute, $value);
            }
        }
        $this->_htmlcode .= '>';

        if ($this->_text) {
            $this->_htmlcode .= $this->_text;
        }

        foreach ($this->_siblings as $obj) {
            $this->_htmlcode .= $obj->fetch();
        }

        $this->_htmlcode .= "</{$this->_element}>";

        return $this->_htmlcode;
    }

    // Returns siblings of Element
    public function get_siblings()
    {
        return $this->_siblings;
    }

    /**
     * @return bool
     */
    public function has_siblings()
    {
        return 0 !== \count($this->_siblings);
    }
}