1 | <?php |
||
17 | class custom extends block |
||
18 | { |
||
19 | /** @var \phpbb\cache\driver\driver_interface */ |
||
20 | protected $cache; |
||
21 | |||
22 | /** @var \phpbb\db\driver\driver_interface */ |
||
23 | protected $db; |
||
24 | |||
25 | /** @var \phpbb\request\request_interface */ |
||
26 | protected $request; |
||
27 | |||
28 | /** @var string */ |
||
29 | protected $cblocks_table; |
||
30 | |||
31 | /** |
||
32 | * Constructor |
||
33 | * |
||
34 | * @param \phpbb\cache\driver\driver_interface $cache Cache driver interface |
||
35 | * @param \phpbb\db\driver\driver_interface $db Database object |
||
36 | * @param \phpbb\request\request_interface $request Request object |
||
37 | * @param string $cblocks_table Name of custom blocks database table |
||
38 | */ |
||
39 | 42 | public function __construct(\phpbb\cache\driver\driver_interface $cache, \phpbb\db\driver\driver_interface $db, \phpbb\request\request_interface $request, $cblocks_table) |
|
40 | { |
||
41 | 42 | $this->cache = $cache; |
|
42 | 42 | $this->db = $db; |
|
43 | 42 | $this->request = $request; |
|
44 | 42 | $this->cblocks_table = $cblocks_table; |
|
45 | 42 | } |
|
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | 4 | public function display(array $bdata, $edit_mode = false) |
|
51 | { |
||
52 | 4 | $cblock = $this->get_block_data($bdata['bid']); |
|
53 | 4 | $content = $this->get_content_for_display($cblock); |
|
54 | |||
55 | 4 | $this->show_editor($cblock, $content, $edit_mode); |
|
56 | |||
57 | return array( |
||
58 | 4 | 'title' => 'BLOCK_TITLE', |
|
59 | 4 | 'content' => $content, |
|
60 | 4 | ); |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param int $block_id |
||
65 | * @return array |
||
66 | */ |
||
67 | 3 | public function edit($block_id) |
|
85 | |||
86 | /** |
||
87 | * @param int $from_bid |
||
88 | * @param int $to_bid |
||
89 | * @see \blitze\sitemaker\services\blocks\action\copy_route::copy_custom_block |
||
90 | */ |
||
91 | 1 | public function copy($from_bid, $to_bid) |
|
103 | |||
104 | /** |
||
105 | * @param int $bid |
||
106 | * @return array |
||
107 | */ |
||
108 | 4 | private function get_block_data($bid) |
|
114 | |||
115 | /** |
||
116 | * @param array $data |
||
117 | * @return string |
||
118 | */ |
||
119 | 7 | private function get_content_for_display(array $data) |
|
120 | { |
||
121 | 7 | $content = generate_text_for_display($data['block_content'], $data['bbcode_uid'], $data['bbcode_bitfield'], $data['bbcode_options'], true); |
|
122 | 7 | return htmlspecialchars_decode($content, ENT_COMPAT); |
|
123 | } |
||
124 | |||
125 | /** |
||
126 | * @param array $sql_data |
||
127 | * @param bool $block_exists |
||
128 | */ |
||
129 | 4 | private function save(array $sql_data, $block_exists) |
|
130 | { |
||
131 | 4 | if (!$block_exists) |
|
132 | 4 | { |
|
133 | 2 | $sql = 'INSERT INTO ' . $this->cblocks_table . ' ' . $this->db->sql_build_array('INSERT', $sql_data); |
|
134 | 2 | } |
|
135 | else |
||
136 | { |
||
137 | 2 | $sql = 'UPDATE ' . $this->cblocks_table . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_data) . ' WHERE block_id = ' . (int) $sql_data['block_id']; |
|
138 | } |
||
139 | 4 | $this->db->sql_query($sql); |
|
140 | 4 | $this->cache->destroy('pt_cblocks'); |
|
141 | 4 | } |
|
142 | |||
143 | /** |
||
144 | * @param array $cblock |
||
145 | * @param string $content |
||
146 | * @param bool $edit_mode |
||
147 | * @return string |
||
148 | */ |
||
149 | 4 | private function show_editor(array $cblock, &$content, $edit_mode) |
|
157 | |||
158 | /** |
||
159 | * @return array |
||
160 | */ |
||
161 | 8 | private function get_custom_blocks() |
|
181 | |||
182 | /** |
||
183 | * @param int $bid |
||
184 | * @return array |
||
185 | */ |
||
186 | 5 | private function get_default_fields($bid) |
|
196 | } |
||
197 |