1 | <?php |
||
27 | class admin_donation_pages_controller extends admin_main |
||
28 | { |
||
29 | protected $phpbb_root_path; |
||
30 | protected $php_ext; |
||
31 | protected $ppde_operator; |
||
32 | protected $lang_local_name; |
||
33 | |||
34 | /** |
||
35 | * Constructor |
||
36 | * |
||
37 | * @param ContainerInterface $container Service container interface |
||
38 | * @param \phpbb\log\log $log The phpBB log system |
||
39 | * @param \skouat\ppde\operators\donation_pages $ppde_operator_donation_pages Operator object |
||
40 | * @param \phpbb\request\request $request Request object |
||
41 | * @param \phpbb\template\template $template Template object |
||
42 | * @param \phpbb\user $user User object |
||
43 | * @param string $phpbb_root_path phpBB root path |
||
44 | * @param string $php_ext phpEx |
||
45 | * |
||
46 | * @access public |
||
47 | */ |
||
48 | public function __construct(ContainerInterface $container, \phpbb\log\log $log, \skouat\ppde\operators\donation_pages $ppde_operator_donation_pages, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, $phpbb_root_path, $php_ext) |
||
64 | |||
65 | /** |
||
66 | * Display the pages |
||
67 | * |
||
68 | * @return null |
||
69 | * @access public |
||
70 | */ |
||
71 | public function display_donation_pages() |
||
109 | |||
110 | /** |
||
111 | * Assign language template vars to a block vars |
||
112 | * $s_select is for build options select menu |
||
113 | * |
||
114 | * @param array $lang |
||
115 | * @param integer $current |
||
116 | * |
||
117 | * @return null |
||
118 | * @access private |
||
119 | */ |
||
120 | private function assign_langs_template_vars($lang, $current = 0) |
||
128 | |||
129 | /** |
||
130 | * Add a donation page |
||
131 | * |
||
132 | * @return null |
||
133 | * @access public |
||
134 | */ |
||
135 | public function add_donation_page() |
||
167 | |||
168 | /** |
||
169 | * Set template var options for language select menus |
||
170 | * |
||
171 | * @param integer $current ID of the language assigned to the donation page |
||
172 | * |
||
173 | * @return null |
||
174 | * @access protected |
||
175 | */ |
||
176 | protected function create_language_options($current) |
||
187 | |||
188 | /** |
||
189 | * Process donation pages data to be added or edited |
||
190 | * |
||
191 | * @param \skouat\ppde\entity\donation_pages $entity The donation pages entity object |
||
192 | * @param array $data The form data to be processed |
||
193 | * |
||
194 | * @return null |
||
195 | * @access private |
||
196 | */ |
||
197 | private function add_edit_donation_page_data(\skouat\ppde\entity\donation_pages $entity, $data) |
||
198 | { |
||
199 | // Get form's POST actions (submit or preview) |
||
200 | $this->submit = $this->request->is_set_post('submit'); |
||
201 | $this->preview = $this->request->is_set_post('preview'); |
||
202 | |||
203 | // Create an array to collect errors that will be output to the user |
||
204 | $errors = array(); |
||
205 | |||
206 | // Load posting language file for the BBCode editor |
||
207 | $this->user->add_lang('posting'); |
||
208 | |||
209 | $message_parse_options = array_merge( |
||
210 | $this->get_message_parse_options($entity, $data, 'bbcode'), |
||
211 | $this->get_message_parse_options($entity, $data, 'magic_url'), |
||
212 | $this->get_message_parse_options($entity, $data, 'smilies') |
||
213 | ); |
||
214 | |||
215 | // Set the message parse options in the entity |
||
216 | foreach ($message_parse_options as $function => $enabled) |
||
217 | { |
||
218 | call_user_func(array($entity, ($enabled ? 'message_enable_' : 'message_disable_') . $function)); |
||
219 | } |
||
220 | |||
221 | unset($message_parse_options); |
||
222 | |||
223 | // Set the donation page's data in the entity |
||
224 | $item_fields = array( |
||
225 | 'lang_id' => $data['page_lang_id'], |
||
226 | 'name' => $data['page_title'], |
||
227 | 'message' => $data['page_content'], |
||
228 | ); |
||
229 | $this->set_entity_data($entity, $item_fields); |
||
230 | |||
231 | // Check some settings before loading and submitting form |
||
232 | $errors = array_merge($errors, |
||
233 | $this->is_invalid_form('add_edit_' . $this->module_name, $this->submit_or_preview($this->submit)), |
||
234 | $this->is_empty_data($entity, 'name', '', $this->submit_or_preview($this->submit)), |
||
235 | $this->is_empty_data($entity, 'lang_id', 0, $this->submit_or_preview($this->submit)) |
||
236 | ); |
||
237 | |||
238 | // Grab predefined template vars |
||
239 | $vars = $entity->get_vars(); |
||
240 | |||
241 | // Assign variables in a template block vars |
||
242 | $this->assign_preview_template_vars($entity, $errors); |
||
243 | $this->assign_predefined_block_vars($vars); |
||
244 | |||
245 | // Submit form data |
||
246 | $this->submit_data($entity, $errors); |
||
247 | |||
248 | // Set output vars for display in the template |
||
249 | $this->s_error_assign_template_vars($errors); |
||
250 | $this->template->assign_vars(array( |
||
251 | 'DONATION_BODY' => $entity->get_message_for_edit(), |
||
252 | 'L_DONATION_PAGES_TITLE' => $this->user->lang[strtoupper($entity->get_name())], |
||
253 | 'L_DONATION_PAGES_TITLE_EXPLAIN' => $this->user->lang[strtoupper($entity->get_name()) . '_EXPLAIN'], |
||
254 | |||
255 | 'S_BBCODE_DISABLE_CHECKED' => !$entity->message_bbcode_enabled(), |
||
256 | 'S_MAGIC_URL_DISABLE_CHECKED' => !$entity->message_magic_url_enabled(), |
||
257 | 'S_SMILIES_DISABLE_CHECKED' => !$entity->message_smilies_enabled(), |
||
258 | |||
259 | 'BBCODE_STATUS' => $this->user->lang('BBCODE_IS_ON', '<a href="' . append_sid("{$this->phpbb_root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), |
||
260 | 'FLASH_STATUS' => $this->user->lang['FLASH_IS_ON'], |
||
261 | 'IMG_STATUS' => $this->user->lang['IMAGES_ARE_ON'], |
||
262 | 'SMILIES_STATUS' => $this->user->lang['SMILIES_ARE_ON'], |
||
263 | 'URL_STATUS' => $this->user->lang['URL_IS_ON'], |
||
264 | |||
265 | 'S_BBCODE_ALLOWED' => true, |
||
266 | 'S_BBCODE_FLASH' => true, |
||
267 | 'S_BBCODE_IMG' => true, |
||
268 | 'S_LINKS_ALLOWED' => true, |
||
269 | 'S_SMILIES_ALLOWED' => true, |
||
270 | 'S_HIDDEN_FIELDS' => '<input type="hidden" name="page_title" value="' . $entity->get_name() . '" />', |
||
271 | )); |
||
272 | |||
273 | // Display custom bbcodes and smilies |
||
274 | $this->include_custom_bbcodes($entity->message_bbcode_enabled()); |
||
275 | $this->include_smileys($entity->message_smilies_enabled()); |
||
276 | } |
||
277 | |||
278 | /** |
||
279 | * @param $bbcode_enabled |
||
280 | * |
||
281 | * @return null |
||
282 | * @access private |
||
283 | */ |
||
284 | private function include_custom_bbcodes($bbcode_enabled) |
||
292 | |||
293 | /** |
||
294 | * @param $smilies_enabled |
||
295 | * |
||
296 | * @return null |
||
297 | * @access private |
||
298 | */ |
||
299 | private function include_smileys($smilies_enabled) |
||
307 | |||
308 | /** |
||
309 | * Includes the file that contains the function, if not loaded. |
||
310 | * |
||
311 | * @param $function_name string Name of the function to test |
||
312 | * @param $function_filepath string Path of the file that containing the function |
||
313 | * |
||
314 | * @return null |
||
315 | * @access private |
||
316 | */ |
||
317 | private function include_function($function_name, $function_filepath) |
||
324 | |||
325 | /** |
||
326 | * Get parse options of the message |
||
327 | * |
||
328 | * @param \skouat\ppde\entity\donation_pages $entity The donation pages entity object |
||
329 | * @param array $data The form data to be processed |
||
330 | * @param string $type |
||
331 | * |
||
332 | * @return array |
||
333 | * @access private |
||
334 | */ |
||
335 | private function get_message_parse_options(\skouat\ppde\entity\donation_pages $entity, $data, $type) |
||
339 | |||
340 | /** |
||
341 | * Assign vars to the template if preview is true. |
||
342 | * |
||
343 | * @param \skouat\ppde\entity\donation_pages $entity The donation pages entity object |
||
344 | * @param $errors |
||
345 | * |
||
346 | * @access private |
||
347 | */ |
||
348 | private function assign_preview_template_vars(\skouat\ppde\entity\donation_pages $entity, $errors) |
||
359 | |||
360 | /** |
||
361 | * Assign Predefined variables to a template block_vars |
||
362 | * |
||
363 | * @param array $vars |
||
364 | * |
||
365 | * @return null |
||
366 | * @access private |
||
367 | */ |
||
368 | private function assign_predefined_block_vars($vars) |
||
379 | |||
380 | /** |
||
381 | * Submit data to the database |
||
382 | * |
||
383 | * @param \skouat\ppde\entity\donation_pages $entity The donation pages entity object |
||
384 | * @param array $errors |
||
385 | * |
||
386 | * @return null |
||
387 | * @access private |
||
388 | */ |
||
389 | private function submit_data(\skouat\ppde\entity\donation_pages $entity, array $errors) |
||
404 | |||
405 | /** |
||
406 | * Get Local lang name |
||
407 | * |
||
408 | * @param array $langs |
||
409 | * |
||
410 | * @return null |
||
411 | * @access private |
||
412 | */ |
||
413 | private function get_lang_local_name($langs) |
||
420 | |||
421 | /** |
||
422 | * Edit a donation page |
||
423 | * |
||
424 | * @param int $page_id Donation page identifier |
||
425 | * |
||
426 | * @return null |
||
427 | * @access public |
||
428 | */ |
||
429 | public function edit_donation_page($page_id) |
||
463 | |||
464 | /** |
||
465 | * Delete a donation page |
||
466 | * |
||
467 | * @param int $page_id The donation page identifier to delete |
||
468 | * |
||
469 | * @return null |
||
470 | * @access public |
||
471 | */ |
||
472 | public function delete_donation_page($page_id) |
||
491 | } |
||
492 |