1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kaloa\Renderer\Inigo\Handler; |
4
|
|
|
|
5
|
|
|
use Kaloa\Renderer\Inigo\Handler\ProtoHandler; |
6
|
|
|
use Kaloa\Renderer\Inigo\Parser; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* |
10
|
|
|
*/ |
11
|
|
|
final class ImgHandler extends ProtoHandler |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $last_img_align = ''; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
18 |
|
public function __construct() |
23
|
|
|
{ |
24
|
18 |
|
$this->name = 'img'; |
25
|
18 |
|
$this->type = Parser::TAG_OUTLINE; |
26
|
|
|
|
27
|
18 |
|
$this->defaultParam = 'src'; |
28
|
18 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* |
32
|
|
|
* @param string $path |
33
|
|
|
* @param string $alt |
34
|
|
|
* @param string $title |
35
|
|
|
* @param int $align |
36
|
|
|
* @param string $dir |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
3 |
|
private function drawImage( |
40
|
|
|
$path, |
41
|
|
|
$alt = '', |
42
|
|
|
$title = '', |
|
|
|
|
43
|
|
|
$align = Parser::PC_IMG_ALIGN_LEFT, |
44
|
|
|
$dir = '' |
45
|
|
|
) { |
46
|
|
|
// width of framing div's border (one side) |
47
|
3 |
|
$border_width = 1; |
48
|
3 |
|
$padding = 2; |
49
|
3 |
|
$ret = ''; |
50
|
3 |
|
$path = $dir . $path; |
51
|
|
|
|
52
|
|
|
//$title = $this->ParseInline($title); |
53
|
|
|
|
54
|
3 |
|
$width = 150; |
55
|
3 |
|
$attr = 'width="150" height="150"'; |
56
|
|
|
|
57
|
|
|
// Image exists? |
58
|
3 |
|
if (@getimagesize($path) !== false) { |
59
|
3 |
|
list($width, $height, $type, $attr) = getimagesize($path); |
60
|
3 |
|
} |
61
|
|
|
|
62
|
|
|
//$path = $this->m_rel_path . $path; |
63
|
|
|
|
64
|
3 |
|
if ($alt === '') { |
65
|
3 |
|
$alt = $path; |
66
|
3 |
|
} |
67
|
|
|
|
68
|
3 |
|
$style = 'width: ' . ($width + 2 * (1 + $border_width + $padding)) . 'px;'; |
69
|
|
|
//$style2 .= "height: " . ($height + 2 * ($border_width )) . "px;"; |
70
|
|
|
|
71
|
3 |
|
if ($align == Parser::PC_IMG_ALIGN_RIGHT) { |
72
|
|
|
$ret .= '<div class="img">' . "\n" |
73
|
1 |
|
. ' <div class="img_right" style="' . $style . '">' . "\n" |
74
|
1 |
|
. ' <div class="img_border">' . "\n" |
75
|
1 |
|
. ' <img src="' . $this->e($path) . '" alt="Bild: ' . $this->e($alt) . '" title="' |
76
|
1 |
|
. $this->e($alt) . '" ' . $attr . ' />' . "\n" |
77
|
1 |
|
. ' </div>' . "\n" |
78
|
1 |
|
. ' <div class="img_content">'; |
79
|
3 |
|
} elseif ($align == Parser::PC_IMG_ALIGN_CENTER) { |
80
|
|
|
$ret .= '<div class="center">' . "\n" |
81
|
1 |
|
. ' <div class="img">' . "\n" |
82
|
1 |
|
. ' <div class="img_center" style="' . $style . '">' . "\n" |
83
|
1 |
|
. ' <div class="img_border">' . "\n" |
84
|
1 |
|
. ' <img src="' . $this->e($path) . '" alt="Bild: ' . $this->e($alt) . '" title="' |
85
|
1 |
|
. $this->e($alt) . '" ' . $attr . ' />' . "\n" |
86
|
1 |
|
. ' </div>' . "\n" |
87
|
1 |
|
. ' <div class="img_content">'; |
88
|
3 |
|
} elseif ($align == Parser::PC_IMG_ALIGN_LEFT) { |
89
|
|
|
$ret .= '<div class="img">' . "\n" |
90
|
3 |
|
. ' <div class="img_left" style="' . $style . '">' . "\n" |
91
|
3 |
|
. ' <div class="img_border">' . "\n" |
92
|
3 |
|
. ' <img src="' . $this->e($path) . '" alt="Bild: ' . $this->e($alt) . '" title="' |
93
|
3 |
|
. $this->e($alt) . '" ' . $attr . ' />' . "\n" |
94
|
3 |
|
. ' </div>' . "\n" |
95
|
3 |
|
. ' <div class="img_content">'; |
96
|
3 |
|
} |
97
|
|
|
|
98
|
3 |
|
return $ret; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* |
103
|
|
|
* @param array $data |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
3 |
|
public function draw(array $data) |
107
|
|
|
{ |
108
|
3 |
|
$ret = ''; |
109
|
|
|
|
110
|
3 |
|
if ($data['front']) { |
111
|
3 |
|
$src = $this->fillParam($data, 'src', ''); |
112
|
3 |
|
$title = $this->fillParam($data, 'title', ''); |
113
|
3 |
|
$align = $this->fillParam($data, 'align', null); |
114
|
|
|
|
115
|
|
|
//$src = $this->m_image_path . $src; |
116
|
3 |
|
$this->last_img_align = $align; |
117
|
|
|
|
118
|
|
|
switch ($align) { |
119
|
3 |
|
case 'right': |
120
|
1 |
|
$align = Parser::PC_IMG_ALIGN_RIGHT; |
121
|
1 |
|
break; |
122
|
3 |
|
case 'center': |
123
|
1 |
|
$align = Parser::PC_IMG_ALIGN_CENTER; |
124
|
1 |
|
break; |
125
|
3 |
|
default: |
126
|
3 |
|
$align = Parser::PC_IMG_ALIGN_LEFT; |
127
|
3 |
|
break; |
128
|
3 |
|
} |
129
|
|
|
|
130
|
3 |
|
$ret = $this->drawImage($src, $title, '', $align, $data['vars']['image-dir']); |
131
|
3 |
|
} elseif ($this->last_img_align === 'center') { |
132
|
1 |
|
$this->last_img_align = ''; |
133
|
1 |
|
$ret = "</div>\n </div>\n </div>\n</div>\n\n"; |
134
|
1 |
|
} else { |
135
|
3 |
|
$ret = "</div>\n </div>\n</div>\n\n"; |
136
|
|
|
} |
137
|
|
|
|
138
|
3 |
|
return $ret; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.