|
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\event; |
|
11
|
|
|
|
|
12
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
13
|
|
|
|
|
14
|
|
|
class posting implements EventSubscriberInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var \blitze\content\services\form\builder */ |
|
17
|
|
|
protected $builder; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string */ |
|
20
|
|
|
protected $content_type = ''; |
|
21
|
|
|
|
|
22
|
|
|
/** @var bool */ |
|
23
|
|
|
protected $build_content = false; |
|
24
|
|
|
|
|
25
|
|
|
/** @var int */ |
|
26
|
|
|
protected $content_post_id = 0; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Constructor |
|
30
|
|
|
* |
|
31
|
|
|
* @param \blitze\content\services\form\builder $builder Form builder object |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(\blitze\content\services\form\builder $builder) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->builder = $builder; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return array |
|
40
|
|
|
*/ |
|
41
|
|
|
static public function getSubscribedEvents() |
|
|
|
|
|
|
42
|
|
|
{ |
|
43
|
|
|
return array( |
|
44
|
|
|
'core.modify_posting_auth' => 'init_builder', |
|
45
|
|
|
'core.posting_modify_message_text' => 'build_message', |
|
46
|
|
|
'core.posting_modify_submission_errors' => 'show_errors', |
|
47
|
|
|
'core.posting_modify_submit_post_before' => 'modify_post_data', |
|
48
|
|
|
'core.submit_post_modify_sql_data' => 'modify_sql_data', |
|
49
|
|
|
'core.posting_modify_submit_post_after' => array('save_fields', 'set_redirect_url'), |
|
50
|
|
|
'core.topic_review_modify_post_list' => 'set_content_post_id', |
|
51
|
|
|
'core.topic_review_modify_row' => 'modify_topic_review', |
|
52
|
|
|
'core.posting_modify_template_vars' => 'build_form', |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param \phpbb\event\data $event |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function init_builder(\phpbb\event\data $event) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->content_type = $this->builder->init($event['forum_id'], $event['topic_id'], $event['mode'], $event['save']); |
|
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
$topic_first_post_id = $event['post_data']['topic_first_post_id']; |
|
65
|
|
|
if (!$topic_first_post_id || $topic_first_post_id == $event['post_id']) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->build_content = ($this->content_type && $event['mode'] !== 'reply') ? true : false; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param \phpbb\event\data $event |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
|
|
public function build_message(\phpbb\event\data $event) |
|
76
|
|
|
{ |
|
77
|
|
|
if ($this->build_content) |
|
78
|
|
|
{ |
|
79
|
|
|
$message_parser = $event['message_parser']; |
|
80
|
|
|
$message_parser->message = $this->builder->generate_message(); |
|
81
|
|
|
$event['message_parser'] = $message_parser; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param \phpbb\event\data $event |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
public function show_errors(\phpbb\event\data $event) |
|
90
|
|
|
{ |
|
91
|
|
|
if ($this->build_content) |
|
92
|
|
|
{ |
|
93
|
|
|
$event['error'] = $this->builder->get_errors(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param \phpbb\event\data $event |
|
99
|
|
|
* @return void |
|
100
|
|
|
*/ |
|
101
|
|
|
public function modify_post_data(\phpbb\event\data $event) |
|
102
|
|
|
{ |
|
103
|
|
|
if ($this->build_content) |
|
104
|
|
|
{ |
|
105
|
|
|
$data = $event['data']; |
|
106
|
|
|
$this->builder->force_visibility($data); |
|
107
|
|
|
$event['data'] = $data; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param \phpbb\event\data $event |
|
113
|
|
|
* @return void |
|
114
|
|
|
*/ |
|
115
|
|
|
public function modify_sql_data(\phpbb\event\data $event) |
|
116
|
|
|
{ |
|
117
|
|
|
if ($this->build_content) |
|
118
|
|
|
{ |
|
119
|
|
|
$sql_data = $event['sql_data']; |
|
120
|
|
|
$this->builder->modify_posting_data($sql_data[TOPICS_TABLE]['sql']); |
|
121
|
|
|
$event['sql_data'] = $sql_data; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param \phpbb\event\data $event |
|
127
|
|
|
* @return void |
|
128
|
|
|
*/ |
|
129
|
|
|
public function set_content_post_id(\phpbb\event\data $event) |
|
130
|
|
|
{ |
|
131
|
|
|
if ($this->content_type) |
|
132
|
|
|
{ |
|
133
|
|
|
$this->content_post_id = array_pop($event['post_list']); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param \phpbb\event\data $event |
|
139
|
|
|
* @return void |
|
140
|
|
|
*/ |
|
141
|
|
|
public function modify_topic_review(\phpbb\event\data $event) |
|
142
|
|
|
{ |
|
143
|
|
|
if ($this->content_type && $event['row']['post_id'] === $this->content_post_id) |
|
144
|
|
|
{ |
|
145
|
|
|
$post_row = $event['post_row']; |
|
146
|
|
|
$post_row['MESSAGE'] = $this->builder->get_content_view($this->content_type, $post_row, 'summary'); |
|
147
|
|
|
$event['post_row'] = $post_row; |
|
148
|
|
|
unset($post_row); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @param \phpbb\event\data $event |
|
154
|
|
|
* @return void |
|
155
|
|
|
*/ |
|
156
|
|
|
public function set_redirect_url(\phpbb\event\data $event) |
|
157
|
|
|
{ |
|
158
|
|
|
if ($this->content_type) |
|
159
|
|
|
{ |
|
160
|
|
|
if ($this->build_content) |
|
161
|
|
|
{ |
|
162
|
|
|
$event['redirect_url'] = $this->builder->get_cp_url(); |
|
163
|
|
|
} |
|
164
|
|
|
else |
|
165
|
|
|
{ |
|
166
|
|
|
$topic_url = $this->builder->get_post_url($this->content_type, $event['post_data']); |
|
167
|
|
|
|
|
168
|
|
|
$post_id = $event['post_id']; |
|
169
|
|
|
if ($post_id != $event['post_data']['topic_first_post_id']) |
|
170
|
|
|
{ |
|
171
|
|
|
$topic_url .= "?p=$post_id#p$post_id"; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
$event['redirect_url'] = $topic_url; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @param \phpbb\event\data $event |
|
181
|
|
|
* @return void |
|
182
|
|
|
*/ |
|
183
|
|
|
public function save_fields(\phpbb\event\data $event) |
|
184
|
|
|
{ |
|
185
|
|
|
if ($this->build_content && in_array($event['mode'], array('post', 'edit', 'save'))) |
|
186
|
|
|
{ |
|
187
|
|
|
$this->builder->save_db_fields($event['topic_id']); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @param \phpbb\event\data $event |
|
193
|
|
|
* @return void |
|
194
|
|
|
*/ |
|
195
|
|
|
public function build_form(\phpbb\event\data $event) |
|
196
|
|
|
{ |
|
197
|
|
|
if ($this->build_content) |
|
198
|
|
|
{ |
|
199
|
|
|
$post_data = $event['post_data']; |
|
200
|
|
|
$page_data = $event['page_data']; |
|
201
|
|
|
|
|
202
|
|
|
$post_data['TOPIC_URL'] = './'; |
|
203
|
|
|
$page_data['SITEMAKER_FORM'] = $this->builder->generate_form($event['topic_id'], $post_data, $page_data); |
|
204
|
|
|
|
|
205
|
|
|
if ($event['preview']) |
|
206
|
|
|
{ |
|
207
|
|
|
$page_data['PREVIEW_MESSAGE'] = $this->builder->generate_preview($this->content_type, $post_data); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
$event['page_data'] = $page_data; |
|
211
|
|
|
unset($post_data, $page_data); |
|
212
|
|
|
} |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
|