|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* @package sitemaker |
|
5
|
|
|
* @copyright (c) 2013 Daniel A. (blitze) |
|
6
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace blitze\content\services\form\field; |
|
11
|
|
|
|
|
12
|
|
|
class image extends base |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var \blitze\sitemaker\services\util */ |
|
15
|
|
|
protected $util; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Constructor |
|
19
|
|
|
* |
|
20
|
|
|
* @param \phpbb\language\language $language Language object |
|
21
|
|
|
* @param \phpbb\request\request_interface $request Request object |
|
22
|
|
|
* @param \blitze\sitemaker\services\template $ptemplate Sitemaker template object |
|
23
|
|
|
* @param \blitze\sitemaker\services\util $util Sitemaker utility object |
|
24
|
|
|
*/ |
|
25
|
8 |
|
public function __construct(\phpbb\language\language $language, \phpbb\request\request_interface $request, \blitze\sitemaker\services\template $ptemplate, \blitze\sitemaker\services\util $util) |
|
26
|
|
|
{ |
|
27
|
8 |
|
parent::__construct($language, $request, $ptemplate); |
|
28
|
|
|
|
|
29
|
8 |
|
$this->util = $util; |
|
30
|
8 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @inheritdoc |
|
34
|
|
|
*/ |
|
35
|
3 |
|
public function get_field_value($name, $value) |
|
36
|
|
|
{ |
|
37
|
3 |
|
$value = $this->request->variable($name, $value); |
|
38
|
3 |
|
$value = $this->get_image_src($value); |
|
39
|
|
|
|
|
40
|
3 |
|
return ($value) ? '[img]' . $value . '[/img]' : ''; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @inheritdoc |
|
45
|
|
|
*/ |
|
46
|
3 |
|
public function show_form_field($name, array &$data) |
|
47
|
|
|
{ |
|
48
|
3 |
|
$bbcode_value = $this->get_field_value($name, $data['field_value']); |
|
49
|
|
|
|
|
50
|
3 |
|
$field = $this->get_name(); |
|
51
|
3 |
|
$data['field_name'] = $name; |
|
52
|
3 |
|
$data['field_value'] = $this->get_image_src($bbcode_value); |
|
53
|
|
|
|
|
54
|
3 |
|
$this->util->add_assets(array( |
|
55
|
|
|
'js' => array( |
|
56
|
3 |
|
'@blitze_content/assets/form/fields.min.js', |
|
57
|
3 |
|
), |
|
58
|
3 |
|
)); |
|
59
|
|
|
|
|
60
|
3 |
|
$this->ptemplate->assign_vars($data); |
|
61
|
3 |
|
$field = $this->ptemplate->render_view('blitze/content', "fields/image.html", $field . '_field'); |
|
62
|
|
|
|
|
63
|
3 |
|
$data['field_value'] = $bbcode_value; |
|
64
|
|
|
|
|
65
|
3 |
|
return $field; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @inheritdoc |
|
70
|
|
|
*/ |
|
71
|
2 |
|
public function display_field(array $data, $mode = '') |
|
72
|
|
|
{ |
|
73
|
2 |
|
$image = ''; |
|
74
|
2 |
|
if ($data['field_value']) |
|
75
|
2 |
|
{ |
|
76
|
1 |
|
$image = '<figure class="img-ui">' . $data['field_value'] . '</figure>'; |
|
77
|
1 |
|
if ($mode !== 'block') |
|
78
|
1 |
|
{ |
|
79
|
1 |
|
$image = '<div class="' . join(' ', array_filter($data['field_props'])) . '">' . $image . '</div>'; |
|
80
|
1 |
|
} |
|
81
|
1 |
|
} |
|
82
|
2 |
|
return $image; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @inheritdoc |
|
87
|
|
|
*/ |
|
88
|
6 |
|
public function get_default_props() |
|
89
|
|
|
{ |
|
90
|
|
|
return array( |
|
91
|
6 |
|
'size' => '', |
|
92
|
6 |
|
'align' => '', |
|
93
|
6 |
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @inheritdoc |
|
98
|
|
|
*/ |
|
99
|
5 |
|
public function get_name() |
|
100
|
|
|
{ |
|
101
|
5 |
|
return 'image'; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param string $bbcode_string |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
3 |
|
private function get_image_src($bbcode_string) |
|
109
|
|
|
{ |
|
110
|
3 |
|
return str_replace(array('[img]', '[/img]'), '', $bbcode_string); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|