|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
This project is Licenced under The MIT License (MIT) |
|
4
|
|
|
|
|
5
|
|
|
Copyright (c) 2014 Christopher Seufert |
|
6
|
|
|
|
|
7
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8
|
|
|
of this software and associated documentation files (the "Software"), to deal |
|
9
|
|
|
in the Software without restriction, including without limitation the rights |
|
10
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11
|
|
|
copies of the Software, and to permit persons to whom the Software is |
|
12
|
|
|
furnished to do so, subject to the following conditions: |
|
13
|
|
|
|
|
14
|
|
|
The above copyright notice and this permission notice shall be included in |
|
15
|
|
|
all copies or substantial portions of the Software. |
|
16
|
|
|
|
|
17
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
23
|
|
|
THE SOFTWARE. |
|
24
|
|
|
|
|
25
|
|
|
*/ |
|
26
|
|
|
namespace Seufert\Hamle\Tag; |
|
27
|
|
|
|
|
28
|
|
|
use Seufert\Hamle as H; |
|
29
|
|
|
use Seufert\Hamle\Exception\ParseError; |
|
30
|
|
|
|
|
31
|
|
|
class DynHtml extends Html { |
|
32
|
|
|
static $var = 0; |
|
33
|
|
|
protected $varname; |
|
34
|
|
|
protected $baseType; |
|
35
|
|
|
|
|
36
|
|
|
function __construct($tag, $class, $param, $id, $ref) { |
|
37
|
|
|
parent::__construct($tag, $class, $param, $id); |
|
38
|
|
|
$this->source[] = $ref; |
|
39
|
|
|
$this->baseType = $tag; |
|
40
|
|
|
self::$var++; |
|
41
|
|
|
$this->varname = "\$dynhtml" . self::$var; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function render($indent = 0, $doIndent = true) { |
|
45
|
|
|
$data = H\Text::varToCode(array("base" => $this->baseType, "type" => $this->type, "opt" => $this->opt, "source" => $this->source, "content" => $this->content)); |
|
46
|
|
|
$out = "<?php " . $this->varname . "=$data; echo Hamle\\Tag\\DynHtml::toStTag(" . $this->varname . ",\$form)."; |
|
47
|
|
|
$out .= "implode(\"\\n\"," . $this->varname . "['content'])."; |
|
48
|
|
|
$out .= "Hamle\\Tag\\DynHtml::toEnTag(" . $this->varname . ",\$form)?>\n"; |
|
49
|
|
|
return $out; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
function addChild(H\Tag $tag, $mode = "append") { |
|
53
|
|
|
throw new ParseError("Unable to display content within a Dynamic Tag"); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
static function toStTag(&$d, H\Form $form) { |
|
57
|
|
|
foreach ($d["source"] as $source) { |
|
58
|
|
|
$form->getField($source)->getDynamicAtt($d['base'], $d['opt'], $d['type'], $d['content']); |
|
59
|
|
|
} |
|
60
|
|
|
$out = "<" . $d['type'] . " "; |
|
61
|
|
|
foreach ($d['opt'] as $k => $v) { |
|
62
|
|
|
if (is_array($v)) { |
|
63
|
|
|
foreach ($v as $k2 => $v2) |
|
64
|
|
|
if ($v[$k2] instanceof Text) $v[$k2] = eval('return ' . $v[$k2]->toPHP() . ';'); |
|
65
|
|
|
$v = implode(" ", $v); |
|
66
|
|
|
} |
|
67
|
|
|
if ($v instanceOf H\Text) $v = eval('return ' . $v->toPHP() . ';'); |
|
68
|
|
|
$out .= $k . "=\"" . htmlspecialchars($v) . "\" "; |
|
69
|
|
|
} |
|
70
|
|
|
$out .= in_array($d['type'], self::$selfCloseTags) ? "/>" : ">"; |
|
71
|
|
|
return $out; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
static function toEnTag($d, $form) { |
|
75
|
|
|
return in_array($d['type'], self::$selfCloseTags) ? "" : "</" . $d['type'] . ">"; |
|
76
|
|
|
} |
|
77
|
|
|
} |