aboutsummaryrefslogtreecommitdiff
path: root/lib/evaluation/classes/HTML.class.php
blob: 50b01eb69e6b982b8d64f86b0653fdbfd170c2fe (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/**
 * HTML-class for the Stud.IP-project.
 * Based on scripts from "http://tut.php-q.net/".
 *
 * @author  Alexander Willner <mail@AlexanderWillner.de>
 *
 * @copyright   2004 Stud.IP-Project
 * @access      public
 * @package     evaluation
 * @modulegroup evaluation_modules
 *
 */

// +--------------------------------------------------------------------------+
// This file is part of Stud.IP
// Copyright (C) 2001-2004 Stud.IP
// +--------------------------------------------------------------------------+
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or any later version.
// +--------------------------------------------------------------------------+
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// +--------------------------------------------------------------------------+
require_once 'HTMLempty.class.php';

class HTML extends HTMLempty
{
    /**
     * Holds the content.
     *
     * @access   private
     * @var      object $_content
     */
    var $_content;

    /**
     */
    var $has_textarea = false;

    public function addHTMLContent($_content)
    {
        if (is_object($_content)) {
            $classname = mb_strtolower(get_class($_content));
            $valid_classes = ['htmlempty', 'html', 'htm', 'htmpty', 'studip\button', 'studip\linkbutton', 'messagebox'];
            if (in_array($classname, $valid_classes)) {
                $this->_content[] = $_content;
            } else {
                trigger_error('Ungültiges Objekt: "' . $classname . '"', E_USER_ERROR);
            }
        } elseif (is_scalar($_content)) {
            $this->_content[] = (string)$_content;
        } else {
            echo "Fehler in HTML.class.php: Es fehlt ein addHTMLContent-Element für ein Element des Typs \"&lt;" . $this->getName() . "&gt;\"<br>";
        }
    }

    public function addContent($_content)
    {
        if (is_object($_content)) {
            $this->addHTMLContent($_content);
        } elseif (is_scalar($_content)) {
            $this->addHTMLContent(htmlReady(((string)$_content)));
        } else {
            $this->addHTMLContent("");
        }
    }

    /**
     *
     */
    public function getContent()
    {
        return $this->_content;
    }

    /**
     * avoid indentation of <textarea>...
     */
    public function setTextareaCheck()
    {
        $this->has_textarea = true;
    }

    /**
     *
     */
    public function printContent($indent = 0)
    {
        echo $this->createContent($indent);
    }

    /**
     *
     */
    public function createContent($indent = 0)
    {
        $output = "";

        $str_indent = str_repeat(' ', $indent);

        $_content = $this->getContent();
        $output .= ($str_indent . "<" . $this->getName());

        $attribute = $this->getAttr();
        foreach ($attribute as $name => $value) {
            $output .= (' ' . $name . '="' . $value . '"');
        }

        $output .= $this->_string;
        $output .= (">\n");
        if (!is_array($_content)) {
            $attributes = "";
            foreach ($attribute as $name => $value) {
                $attributes .= ($name . '=&gt;"' . $value . '"; ');
            }
            print "Fehler in HTML.class.php: Es fehlt ein Content-Element für ein Element des Typs \"&lt;" . $this->getName() . "&gt;\" (Attribute: $attributes).";

            return;
        }

        foreach ($_content as $content) {
            if (is_object($content)) {
                // der aktuelle Content ist ein Object
                // also ein HTML-Element. Also geben
                // wir es aus
                $classname = mb_strtolower(get_class($content));
                $valid_classes = ['studip\button', 'studip\linkbutton', 'messagebox'];
                if (in_array($classname, $valid_classes)) {
                    $output .= $content;
                } else {
                    $output .= $content->createContent($indent + 4);
                }
                // Rekursion lässt grüßen ...
            } else {
                // Content ist ein String. Jeden Zeile
                // geben wir getrennt aus
                $zeilen = explode("\n", $content);
                $echo = "";

                if ($this->has_textarea) {

                    // look for textarea in content
                    $text_area = false;
                    foreach ($zeilen as $zeile) {

                        if (mb_strstr($zeile, "<textarea"))
                            $text_area = true;

                        if ($text_area)
                            $echo .= $zeile . "\n";
                        else
                            $echo .= $str_indent . "    " . $zeile . "\n";

                        if (mb_strstr($zeile, "</textarea"))
                            $text_area = false;
                    }
                } else {
                    // standard
                    foreach ($zeilen as $zeile) {
                        $echo .= $str_indent . "    " . $zeile . "\n";
                    }
                }
                $output .= $echo;
            }
        }
        $output .= ($str_indent . "</" . $this->getName() . ">\n");

        return $output;
    }
}

include_once("LazyHTML.class.php");