Completed
Pull Request — master (#48)
by Jakub
09:29
created

admin_controller::prepare_ad_owner()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
ccs 7
cts 8
cp 0.875
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3.0175
1
<?php
2
/**
3
 *
4
 * Advertisement management. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2017 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ads\controller;
12
13
/**
14
* Admin controller
15
*/
16
class admin_controller
17
{
18
	const MAX_NAME_LENGTH = 255;
19
	const DATE_FORMAT = 'Y-m-d';
20
	const DEFAULT_PRIORITY = 5;
21
22
	/** @var \phpbb\template\template */
23
	protected $template;
24
25
	/** @var \phpbb\user */
26
	protected $user;
27
28
	/** @var \phpbb\request\request */
29
	protected $request;
30
31
	/** @var \phpbb\ads\ad\manager */
32
	protected $manager;
33
34
	/** @var \phpbb\ads\location\manager */
35
	protected $location_manager;
36
37
	/** @var \phpbb\log\log */
38
	protected $log;
39
40
	/** @var \phpbb\config\db_text */
41
	protected $config_text;
42
43
	/** @var \phpbb\config\config */
44
	protected $config;
45
46
	/** @var string root_path */
47
	protected $root_path;
48
49
	/** @var string php_ext */
50
	protected $php_ext;
51
52
	/** @var string ext_path */
53
	protected $ext_path;
54
55
	/** @var string Custom form action */
56
	protected $u_action;
57
58
	/** @var array Form validation errors */
59
	protected $errors = array();
60
61
	/**
62
	 * Constructor
63
	 *
64
	 * @param \phpbb\template\template    $template         Template object
65
	 * @param \phpbb\user                 $user             User object
66
	 * @param \phpbb\request\request      $request          Request object
67
	 * @param \phpbb\ads\ad\manager       $manager          Advertisement manager object
68
	 * @param \phpbb\ads\location\manager $location_manager Template location manager object
69
	 * @param \phpbb\log\log              $log              The phpBB log system
70
	 * @param \phpbb\config\db_text       $config_text      Config text object
71
	 * @param \phpbb\config\config        $config           Config object
72
	 * @param string                      $root_path        phpBB root path
73
	 * @param string                      $php_ext          PHP extension
74
	 * @param string                      $ext_path         Path to this extension
75
	 */
76 44
	public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\request\request $request, \phpbb\ads\ad\manager $manager, \phpbb\ads\location\manager $location_manager, \phpbb\log\log $log, \phpbb\config\db_text $config_text, \phpbb\config\config $config, $root_path, $php_ext, $ext_path)
77
	{
78 44
		$this->template = $template;
79 44
		$this->user = $user;
80 44
		$this->request = $request;
81 44
		$this->manager = $manager;
82 44
		$this->location_manager = $location_manager;
83 44
		$this->log = $log;
84 44
		$this->config_text = $config_text;
85 44
		$this->config = $config;
86 44
		$this->root_path = $root_path;
87 44
		$this->php_ext = $php_ext;
88 44
		$this->ext_path = $ext_path;
89 44
	}
90
91
	/**
92
	 * Process user request for manage mode
93
	 *
94
	 * @return void
95
	 */
96 6
	public function mode_manage()
97
	{
98 6
		$this->setup();
99
100 6
		if (!function_exists('user_get_id_name'))
101 6
		{
102
			include($this->root_path . 'includes/functions_user.' . $this->php_ext);
103
		}
104
105
		// Trigger specific action
106 6
		$action = $this->request->variable('action', '');
107 6
		if (in_array($action, array('add', 'edit', 'enable', 'disable', 'delete')))
108 6
		{
109 5
			$this->{'action_' . $action}();
110 5
		}
111
112
		// Otherwise default to this
113 6
		$this->list_ads();
114 6
	}
115
116
	/**
117
	 * Process user request for settings mode
118
	 *
119
	 * @return void
120
	 */
121 3
	public function mode_settings()
122
	{
123 3
		$this->setup();
124
125 3
		add_form_key('phpbb/ads/settings');
126 3
		if ($this->request->is_set_post('submit'))
127 3
		{
128
			// Validate form key
129 2
			if (!check_form_key('phpbb/ads/settings'))
130 2
			{
131 1
				$this->errors[] = $this->user->lang('FORM_INVALID');
132 1
			}
133
134 2
			if (empty($this->errors))
135 2
			{
136 1
				$this->config->set('phpbb_ads_adblocker_message', $this->request->variable('adblocker_message', 0));
137 1
				$this->config->set('phpbb_ads_enable_views', $this->request->variable('enable_views', 0));
138 1
				$this->config->set('phpbb_ads_enable_clicks', $this->request->variable('enable_clicks', 0));
139 1
				$this->config_text->set('phpbb_ads_hide_groups', json_encode($this->request->variable('hide_groups', array(0))));
140
141 1
				$this->success('ACP_AD_SETTINGS_SAVED');
142
			}
143
144 1
			$this->template->assign_vars(array(
145 1
				'S_ERROR'   => (bool) count($this->errors),
146 1
				'ERROR_MSG' => count($this->errors) ? implode('<br />', $this->errors) : '',
147 1
			));
148 1
		}
149
150 2
		$hide_groups = json_decode($this->config_text->get('phpbb_ads_hide_groups'), true);
151 2
		$groups = $this->manager->load_groups();
152 2
		foreach ($groups as $group)
153
		{
154 2
			$group_name = ($group['group_type'] == GROUP_SPECIAL) ? $this->user->lang('G_' . $group['group_name']) : $group['group_name'];
155
156 2
			$this->template->assign_block_vars('groups', array(
157 2
				'ID'         => $group['group_id'],
158 2
				'NAME'       => $group_name,
159 2
				'S_SELECTED' => in_array($group['group_id'], $hide_groups),
160 2
			));
161 2
		}
162
163 2
		$this->template->assign_vars(array(
164 2
			'U_ACTION'          => $this->u_action,
165 2
			'ADBLOCKER_MESSAGE' => $this->config['phpbb_ads_adblocker_message'],
166 2
			'ENABLE_VIEWS'      => $this->config['phpbb_ads_enable_views'],
167 2
			'ENABLE_CLICKS'     => $this->config['phpbb_ads_enable_clicks'],
168 2
		));
169 2
	}
170
171
	/**
172
	 * Set page url
173
	 *
174
	 * @param string $u_action Custom form action
175
	 * @return void
176
	 */
177 38
	public function set_page_url($u_action)
178
	{
179 38
		$this->u_action = $u_action;
180 38
	}
181
182
	/**
183
	 * Get ACP page title for Ads module
184
	 *
185
	 * @return string    Language string for Ads ACP module
186
	 */
187 1
	public function get_page_title()
188
	{
189 1
		return $this->user->lang('ACP_PHPBB_ADS_TITLE');
190
	}
191
192
	/**
193
	 * Add an advertisement
194
	 *
195
	 * @return void
196
	 */
197 12
	public function action_add()
198
	{
199 12
		$preview = $this->request->is_set_post('preview');
200 12
		$submit = $this->request->is_set_post('submit');
201
202 12
		add_form_key('phpbb/ads/add');
203 12
		if ($preview || $submit)
204 12
		{
205 11
			$data = $this->get_form_data('phpbb/ads/add');
206
207 View Code Duplication
			if ($preview)
208 11
			{
209 1
				$this->ad_preview($data['ad_code']);
210 1
			}
211
			else if (empty($this->errors))
212 10
			{
213 1
				$ad_id = $this->manager->insert_ad($data);
214 1
				$this->manager->insert_ad_locations($ad_id, $data['ad_locations']);
215
216 1
				$this->log('ADD', $data['ad_name']);
217
218 1
				$this->success('ACP_AD_ADD_SUCCESS');
219
			}
220
221 10
			$this->assign_locations($data);
222 10
			$this->assign_form_data($data);
223 10
		}
224
		else
225
		{
226 1
			$this->assign_locations();
227
		}
228
229
		// Set output vars for display in the template
230 11
		$this->template->assign_vars(array(
231 11
			'S_ADD_AD'           => true,
232 11
			'U_BACK'             => $this->u_action,
233 11
			'U_ACTION'           => "{$this->u_action}&amp;action=add",
234 11
			'PICKER_DATE_FORMAT' => self::DATE_FORMAT,
235 11
			'U_FIND_USERNAME'    => $this->get_find_username_link(),
236 11
		));
237 11
	}
238
239
	/**
240
	 * Edit an advertisement
241
	 *
242
	 * @return void
243
	 */
244 14
	public function action_edit()
245
	{
246 14
		$ad_id = $this->request->variable('id', 0);
247 14
		$preview = $this->request->is_set_post('preview');
248 14
		$submit = $this->request->is_set_post('submit');
249
250 14
		add_form_key('phpbb/ads/edit/' . $ad_id);
251 14
		if ($preview || $submit)
252 14
		{
253 12
			$data = $this->get_form_data('phpbb/ads/edit/' . $ad_id);
254
255
			if ($preview)
256 12
			{
257 1
				$this->ad_preview($data['ad_code']);
258 1
			}
259 View Code Duplication
			else if (empty($this->errors))
260 11
			{
261 2
				$success = $this->manager->update_ad($ad_id, $data);
262
263
				if ($success)
264 2
				{
265
					// Only insert new ad locations to DB when ad exists
266 1
					$this->manager->delete_ad_locations($ad_id);
267 1
					$this->manager->insert_ad_locations($ad_id, $data['ad_locations']);
268
269 1
					$this->log('EDIT', $data['ad_name']);
270
271 1
					$this->success('ACP_AD_EDIT_SUCCESS');
272
				}
273
274 1
				$this->error('ACP_AD_DOES_NOT_EXIST');
275
			}
276 10
		}
277
		else
278
		{
279 2
			$data = $this->manager->get_ad($ad_id);
280 2
			if (empty($data))
281 2
			{
282 1
				$this->error('ACP_AD_DOES_NOT_EXIST');
283
			}
284
285
			// Load ad template locations
286 1
			$data['ad_locations'] = $this->manager->get_ad_locations($ad_id);
287
		}
288
289
		// Set output vars for display in the template
290 11
		$this->template->assign_vars(array(
291 11
			'S_EDIT_AD'          => true,
292 11
			'EDIT_ID'            => $ad_id,
293 11
			'U_BACK'             => $this->u_action,
294 11
			'U_ACTION'           => "{$this->u_action}&amp;action=edit&amp;id=" . $ad_id,
295 11
			'PICKER_DATE_FORMAT' => self::DATE_FORMAT,
296 11
			'U_FIND_USERNAME'    => $this->get_find_username_link(),
297 11
		));
298 11
		$this->assign_locations($data);
299 11
		$this->assign_form_data($data);
300 11
	}
301
302
	/**
303
	 * Enable an advertisement
304
	 *
305
	 * @return void
306
	 */
307 3
	public function action_enable()
308
	{
309 3
		$this->ad_enable(true);
310 1
	}
311
312
	/**
313
	 * Disable an advertisement
314
	 *
315
	 * @return void
316
	 */
317 3
	public function action_disable()
318
	{
319 3
		$this->ad_enable(false);
320 1
	}
321
322
	/**
323
	 * Delete an advertisement
324
	 *
325
	 * @return void
326
	 */
327 3
	public function action_delete()
328
	{
329 3
		$ad_id = $this->request->variable('id', 0);
330
		if ($ad_id)
331 3
		{
332 3
			if (confirm_box(true))
333 3
			{
334
				// Get ad data so that we can log ad name
335 2
				$ad_data = $this->manager->get_ad($ad_id);
336
337
				// Delete ad and it's template locations
338 2
				$this->manager->delete_ad_locations($ad_id);
339 2
				$success = $this->manager->delete_ad($ad_id);
340
341
				// Only notify user on error or if not ajax
342 2
				if (!$success)
343 2
				{
344 1
					$this->error('ACP_AD_DELETE_ERRORED');
345
				}
346
				else
347
				{
348 1
					$this->log('DELETE', $ad_data['ad_name']);
349
350 1
					if (!$this->request->is_ajax())
351 1
					{
352 1
						$this->success('ACP_AD_DELETE_SUCCESS');
353
					}
354
				}
355
			}
356
			else
357
			{
358 1
				confirm_box(false, $this->user->lang('CONFIRM_OPERATION'), build_hidden_fields(array(
359 1
					'id'     => $ad_id,
360 1
					'i'      => $this->request->variable('i', ''),
361 1
					'mode'   => $this->request->variable('mode', ''),
362
					'action' => 'delete'
363 1
				)));
364
			}
365 1
		}
366 1
	}
367
368
	/**
369
	 * Display the ads
370
	 *
371
	 * @return void
372
	 */
373 1
	public function list_ads()
374
	{
375 1
		foreach ($this->manager->get_all_ads() as $row)
376
		{
377 1
			$ad_enabled = (int) $row['ad_enabled'];
378 1
			$ad_end_date = (int) $row['ad_end_date'];
379 1
			$ad_expired = $ad_end_date > 0 && $ad_end_date < time();
380 1
			if ($ad_expired && $ad_enabled)
381 1
			{
382 1
				$ad_enabled = 0;
383 1
				$this->manager->update_ad($row['ad_id'], array('ad_enabled' => 0));
384 1
			}
385
386 1
			$this->template->assign_block_vars('ads', array(
387 1
				'NAME'               => $row['ad_name'],
388 1
				'END_DATE'           => $ad_end_date ? $this->user->format_date($ad_end_date, self::DATE_FORMAT) : '',
389 1
				'VIEWS'              => $row['ad_views'],
390 1
				'CLICKS'             => $row['ad_clicks'],
391 1
				'VIEWS_LIMIT'        => $row['ad_views_limit'],
392 1
				'CLICKS_LIMIT'       => $row['ad_clicks_limit'],
393 1
				'S_END_DATE_EXPIRED' => $ad_expired,
394 1
				'S_ENABLED'          => $ad_enabled,
395 1
				'U_ENABLE'           => $this->u_action . '&amp;action=' . ($ad_enabled ? 'disable' : 'enable') . '&amp;id=' . $row['ad_id'],
396 1
				'U_EDIT'             => $this->u_action . '&amp;action=edit&amp;id=' . $row['ad_id'],
397 1
				'U_DELETE'           => $this->u_action . '&amp;action=delete&amp;id=' . $row['ad_id'],
398 1
			));
399 1
		}
400
401
		// Set output vars for display in the template
402 1
		$this->template->assign_vars(array(
403 1
			'U_ACTION_ADD'     => $this->u_action . '&amp;action=add',
404 1
			'S_VIEWS_ENABLED'  => $this->config['phpbb_ads_enable_views'],
405 1
			'S_CLICKS_ENABLED' => $this->config['phpbb_ads_enable_clicks'],
406 1
		));
407 1
	}
408
409
	/**
410
	 * Perform general tasks
411
	 *
412
	 * @return void
413
	 */
414 9
	protected function setup()
415
	{
416 9
		$this->user->add_lang_ext('phpbb/ads', 'acp');
417
418 9
		$this->template->assign_var('S_PHPBB_ADS', true);
419 9
	}
420
421
	/**
422
	 * Enable/disable an advertisement
423
	 *
424
	 * @param    bool $enable Enable or disable the advertisement?
425
	 * @return void
426
	 */
427 4
	protected function ad_enable($enable)
428
	{
429 4
		$ad_id = $this->request->variable('id', 0);
430
431 4
		$success = $this->manager->update_ad($ad_id, array(
432 4
			'ad_enabled' => (int) $enable,
433 4
		));
434
435
		// If AJAX was used, show user a result message
436 4
		if ($this->request->is_ajax())
437 4
		{
438
			$json_response = new \phpbb\json_response;
439
			$json_response->send(array(
440
				'text'  => $this->user->lang($enable ? 'ENABLED' : 'DISABLED'),
441
				'title' => $this->user->lang('AD_ENABLE_TITLE', (int) $enable),
442
			));
443
		}
444
445
		// Otherwise, show traditional infobox
446
		if ($success)
447 4
		{
448 2
			$this->success($enable ? 'ACP_AD_ENABLE_SUCCESS' : 'ACP_AD_DISABLE_SUCCESS');
449
		}
450
		else
451
		{
452 2
			$this->error($enable ? 'ACP_AD_ENABLE_ERRORED' : 'ACP_AD_DISABLE_ERRORED');
453
		}
454
	}
455
456
	/**
457
	 * Get admin form data.
458
	 *
459
	 * @param    string $form_name The form name.
460
	 * @return    array    Form data
461
	 */
462 23
	protected function get_form_data($form_name)
463
	{
464
		$data = array(
465 23
			'ad_name'         => $this->request->variable('ad_name', '', true),
466 23
			'ad_note'         => $this->request->variable('ad_note', '', true),
467 23
			'ad_code'         => $this->request->variable('ad_code', '', true),
468 23
			'ad_enabled'      => $this->request->variable('ad_enabled', 0),
469 23
			'ad_locations'    => $this->request->variable('ad_locations', array('')),
470 23
			'ad_end_date'     => $this->request->variable('ad_end_date', ''),
471 23
			'ad_priority'     => $this->request->variable('ad_priority', self::DEFAULT_PRIORITY),
472 23
			'ad_views_limit'  => $this->request->variable('ad_views_limit', 0),
473 23
			'ad_clicks_limit' => $this->request->variable('ad_clicks_limit', 0),
474 23
			'ad_owner'        => $this->request->variable('ad_owner', '', true),
475 23
		);
476
477
		// Validate form key
478 23
		if (!check_form_key($form_name))
479 23
		{
480 2
			$this->errors[] = $this->user->lang('FORM_INVALID');
481 2
		}
482
483
		// Validate ad name
484 23
		if ($data['ad_name'] === '')
485 23
		{
486 2
			$this->errors[] = $this->user->lang('AD_NAME_REQUIRED');
487 2
		}
488 23
		if (truncate_string($data['ad_name'], self::MAX_NAME_LENGTH) !== $data['ad_name'])
489 23
		{
490 2
			$this->errors[] = $this->user->lang('AD_NAME_TOO_LONG', self::MAX_NAME_LENGTH);
491 2
		}
492
493
		// Validate ad end date
494 23
		if (preg_match('#^\d{4}\-\d{2}\-\d{2}$#', $data['ad_end_date']))
495 23
		{
496 4
			$data['ad_end_date'] = (int) $this->user->get_timestamp_from_format(self::DATE_FORMAT, $data['ad_end_date']);
497
498 4
			if ($data['ad_end_date'] < time())
499 4
			{
500 2
				$this->errors[] = $this->user->lang('AD_END_DATE_INVALID');
501 2
			}
502 4
		}
503 19
		else if ($data['ad_end_date'] !== '')
504 19
		{
505 2
			$this->errors[] = $this->user->lang('AD_END_DATE_INVALID');
506 2
		}
507
		else
508
		{
509 17
			$data['ad_end_date'] = 0;
510
		}
511
512
		// Validate ad priority
513 23
		if ($data['ad_priority'] < 1 || $data['ad_priority'] > 10)
514 23
		{
515 6
			$this->errors[] = $this->user->lang('AD_PRIORITY_INVALID');
516 6
		}
517
518
		// Validate ad views limit
519 23
		if ($data['ad_views_limit'] < 0)
520 23
		{
521 2
			$this->errors[] = $this->user->lang('AD_VIEWS_LIMIT_INVALID');
522 2
		}
523
524
		// Validate ad clicks limit
525 23
		if ($data['ad_clicks_limit'] < 0)
526 23
		{
527 2
			$this->errors[] = $this->user->lang('AD_CLICKS_LIMIT_INVALID');
528 2
		}
529
530
		// Validate ad owner. Username in $data['ad_owner'] will be replaced with user_id.
531 23
		if (!empty($data['ad_owner']))
532 23
		{
533
			// Function returns false if everything is OK.
534 2
			if (user_get_id_name($ad_owner_id, $data['ad_owner']))
535 2
			{
536
				$this->errors[] = $this->user->lang('AD_OWNER_INVALID');
537
			}
538
			else
539
			{
540 2
				$data['ad_owner'] = $ad_owner_id[0];
0 ignored issues
show
Bug introduced by
The variable $ad_owner_id does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
541
			}
542 2
		}
543
		else
544
		{
545 21
			$data['ad_owner'] = 0;
546
		}
547
548 23
		return $data;
549
	}
550
551
	/**
552
	 * Assign form data to the template.
553
	 *
554
	 * @param    array $data The form data.
555
	 * @return void
556
	 */
557 21
	protected function assign_form_data($data)
558
	{
559 21
		$this->template->assign_vars(array(
560 21
			'S_ERROR'   => (bool) count($this->errors),
561 21
			'ERROR_MSG' => count($this->errors) ? implode('<br />', $this->errors) : '',
562
563 21
			'AD_NAME'         => $data['ad_name'],
564 21
			'AD_NOTE'         => $data['ad_note'],
565 21
			'AD_CODE'         => $data['ad_code'],
566 21
			'AD_ENABLED'      => $data['ad_enabled'],
567 21
			'AD_END_DATE'     => $this->prepare_end_date($data['ad_end_date']),
568 21
			'AD_PRIORITY'     => $data['ad_priority'],
569 21
			'AD_VIEWS_LIMIT'  => $data['ad_views_limit'],
570 21
			'AD_CLICKS_LIMIT' => $data['ad_clicks_limit'],
571 21
			'AD_OWNER'        => $this->prepare_ad_owner($data['ad_owner']),
572 21
		));
573 21
	}
574
575
	/**
576
	 * Prepare end date for display
577
	 *
578
	 * @param    mixed $end_date End date.
579
	 * @return    string    End date prepared for display.
580
	 */
581 21
	protected function prepare_end_date($end_date)
582
	{
583 21
		if (empty($end_date))
584 21
		{
585 16
			return '';
586
		}
587
588 5
		if (is_numeric($end_date))
589 5
		{
590 3
			return $this->user->format_date($end_date, self::DATE_FORMAT);
591
		}
592
593 2
		return (string) $end_date;
594
	}
595
596
	/**
597
	 * Prepare ad owner for display. Method takes user_id
598
	 * of the ad owner and returns his/her username.
599
	 *
600
	 * @param	int		$ad_owner	User ID
601
	 * @return	string	Username belonging to $ad_owner.
602
	 */
603 21
	protected function prepare_ad_owner($ad_owner)
604
	{
605
		// Returns false when no errors occur trying to find the user
606 21
		if (false === user_get_id_name($ad_owner, $ad_owner_name))
0 ignored issues
show
Bug introduced by
The variable $ad_owner_name does not exist. Did you mean $ad_owner?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
607 21
		{
608 1
			if (empty($ad_owner_name))
0 ignored issues
show
Bug introduced by
The variable $ad_owner_name does not exist. Did you mean $ad_owner?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
609 1
			{
610
				return $ad_owner[0];
611
			}
612 1
			return $ad_owner_name[(int) $ad_owner[0]];
613
		}
614 20
		return '';
615
	}
616
	/**
617
	 * Assign template locations data to the template.
618
	 *
619
	 * @param    mixed $data The form data or nothing.
620
	 * @return    void
621
	 */
622 22
	protected function assign_locations($data = false)
623
	{
624 22
		foreach ($this->location_manager->get_all_locations() as $location_id => $location_data)
625
		{
626 22
			$this->template->assign_block_vars('ad_locations', array(
627 22
				'LOCATION_ID'   => $location_id,
628 22
				'LOCATION_DESC' => $location_data['desc'],
629 22
				'LOCATION_NAME' => $location_data['name'],
630 22
				'S_SELECTED'    => $data ? in_array($location_id, $data['ad_locations']) : false,
631 22
			));
632 22
		}
633 22
	}
634
635
	/**
636
	 * Prepare advertisement preview
637
	 *
638
	 * @param    string $code Ad code to preview
639
	 * @return    void
640
	 */
641 2
	protected function ad_preview($code)
642
	{
643 2
		$this->template->assign_var('PREVIEW', htmlspecialchars_decode($code));
644 2
	}
645
646
	/**
647
	 * Print success message.
648
	 *
649
	 * It takes arguments in the form of a language key, followed by language substitution values.
650
	 */
651 6
	protected function success()
652
	{
653 6
		trigger_error(call_user_func_array(array($this->user, 'lang'), func_get_args()) . adm_back_link($this->u_action));
654
	}
655
656
	/**
657
	 * Print error message.
658
	 *
659
	 * It takes arguments in the form of a language key, followed by language substitution values.
660
	 */
661 5
	protected function error()
662
	{
663 5
		trigger_error(call_user_func_array(array($this->user, 'lang'), func_get_args()) . adm_back_link($this->u_action), E_USER_WARNING);
664
	}
665
666
	/**
667
	 * Log action
668
	 *
669
	 * @param    string $action  Performed action in uppercase
670
	 * @param    string $ad_name Advertisement name
671
	 * @return    void
672
	 */
673 3
	protected function log($action, $ad_name)
674
	{
675 3
		$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_PHPBB_ADS_' . $action . '_LOG', time(), array($ad_name));
676 3
	}
677
678 22
	protected function get_find_username_link()
679
	{
680 22
		return append_sid("{$this->root_path}memberlist.{$this->php_ext}", 'mode=searchuser&amp;form=acp_admanagement_add&amp;field=ad_owner&amp;select_single=true');
681
	}
682
}
683