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

admin_controller::prepare_ad_owner()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 3
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 46
	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 46
		$this->template = $template;
79 46
		$this->user = $user;
80 46
		$this->request = $request;
81 46
		$this->manager = $manager;
82 46
		$this->location_manager = $location_manager;
83 46
		$this->log = $log;
84 46
		$this->config_text = $config_text;
85 46
		$this->config = $config;
86 46
		$this->root_path = $root_path;
87 46
		$this->php_ext = $php_ext;
88 46
		$this->ext_path = $ext_path;
89 46
	}
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 40
	public function set_page_url($u_action)
178
	{
179 40
		$this->u_action = $u_action;
180 40
	}
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 13
	public function action_add()
198
	{
199 13
		$preview = $this->request->is_set_post('preview');
200 13
		$submit = $this->request->is_set_post('submit');
201
202 13
		add_form_key('phpbb/ads/add');
203 13
		if ($preview || $submit)
204 13
		{
205 12
			$data = $this->get_form_data('phpbb/ads/add');
206
207 View Code Duplication
			if ($preview)
208 12
			{
209 1
				$this->ad_preview($data['ad_code']);
210 1
			}
211
			else if (empty($this->errors))
212 11
			{
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 11
			$this->assign_locations($data);
222 11
			$this->assign_form_data($data);
223 11
		}
224
		else
225
		{
226 1
			$this->assign_locations();
227
		}
228
229
		// Set output vars for display in the template
230 12
		$this->template->assign_vars(array(
231 12
			'S_ADD_AD'           => true,
232 12
			'U_BACK'             => $this->u_action,
233 12
			'U_ACTION'           => "{$this->u_action}&amp;action=add",
234 12
			'PICKER_DATE_FORMAT' => self::DATE_FORMAT,
235 12
			'U_FIND_USERNAME'    => $this->get_find_username_link(),
236 12
		));
237 12
	}
238
239
	/**
240
	 * Edit an advertisement
241
	 *
242
	 * @return void
243
	 */
244 15
	public function action_edit()
245
	{
246 15
		$ad_id = $this->request->variable('id', 0);
247 15
		$preview = $this->request->is_set_post('preview');
248 15
		$submit = $this->request->is_set_post('submit');
249
250 15
		add_form_key('phpbb/ads/edit/' . $ad_id);
251 15
		if ($preview || $submit)
252 15
		{
253 13
			$data = $this->get_form_data('phpbb/ads/edit/' . $ad_id);
254
255
			if ($preview)
256 13
			{
257 1
				$this->ad_preview($data['ad_code']);
258 1
			}
259 View Code Duplication
			else if (empty($this->errors))
260 12
			{
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 11
		}
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 12
		$this->template->assign_vars(array(
291 12
			'S_EDIT_AD'          => true,
292 12
			'EDIT_ID'            => $ad_id,
293 12
			'U_BACK'             => $this->u_action,
294 12
			'U_ACTION'           => "{$this->u_action}&amp;action=edit&amp;id=" . $ad_id,
295 12
			'PICKER_DATE_FORMAT' => self::DATE_FORMAT,
296 12
			'U_FIND_USERNAME'    => $this->get_find_username_link(),
297 12
		));
298 12
		$this->assign_locations($data);
299 12
		$this->assign_form_data($data);
300 12
	}
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 25
	protected function get_form_data($form_name)
463
	{
464
		$data = array(
465 25
			'ad_name'         => $this->request->variable('ad_name', '', true),
466 25
			'ad_note'         => $this->request->variable('ad_note', '', true),
467 25
			'ad_code'         => $this->request->variable('ad_code', '', true),
468 25
			'ad_enabled'      => $this->request->variable('ad_enabled', 0),
469 25
			'ad_locations'    => $this->request->variable('ad_locations', array('')),
470 25
			'ad_end_date'     => $this->request->variable('ad_end_date', ''),
471 25
			'ad_priority'     => $this->request->variable('ad_priority', self::DEFAULT_PRIORITY),
472 25
			'ad_views_limit'  => $this->request->variable('ad_views_limit', 0),
473 25
			'ad_clicks_limit' => $this->request->variable('ad_clicks_limit', 0),
474 25
			'ad_owner'        => $this->request->variable('ad_owner', '', true),
475 25
		);
476
477
		// Validate form key
478 25
		if (!check_form_key($form_name))
479 25
		{
480 2
			$this->errors[] = $this->user->lang('FORM_INVALID');
481 2
		}
482
483
		// Validate ad name
484 25
		if ($data['ad_name'] === '')
485 25
		{
486 2
			$this->errors[] = $this->user->lang('AD_NAME_REQUIRED');
487 2
		}
488 25
		if (truncate_string($data['ad_name'], self::MAX_NAME_LENGTH) !== $data['ad_name'])
489 25
		{
490 2
			$this->errors[] = $this->user->lang('AD_NAME_TOO_LONG', self::MAX_NAME_LENGTH);
491 2
		}
492
493
		// Validate ad end date
494 25
		if (preg_match('#^\d{4}\-\d{2}\-\d{2}$#', $data['ad_end_date']))
495 25
		{
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 21
		else if ($data['ad_end_date'] !== '')
504 21
		{
505 2
			$this->errors[] = $this->user->lang('AD_END_DATE_INVALID');
506 2
		}
507
		else
508
		{
509 19
			$data['ad_end_date'] = 0;
510
		}
511
512
		// Validate ad priority
513 25
		if ($data['ad_priority'] < 1 || $data['ad_priority'] > 10)
514 25
		{
515 6
			$this->errors[] = $this->user->lang('AD_PRIORITY_INVALID');
516 6
		}
517
518
		// Validate ad views limit
519 25
		if ($data['ad_views_limit'] < 0)
520 25
		{
521 2
			$this->errors[] = $this->user->lang('AD_VIEWS_LIMIT_INVALID');
522 2
		}
523
524
		// Validate ad clicks limit
525 25
		if ($data['ad_clicks_limit'] < 0)
526 25
		{
527 2
			$this->errors[] = $this->user->lang('AD_CLICKS_LIMIT_INVALID');
528 2
		}
529
530
		// Validate ad owner
531 25
		if (!empty($data['ad_owner']))
532 25
		{
533 4
			user_get_id_name($ad_owner_id, $data['ad_owner']);
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...
534 4
			if (!empty($data['ad_owner']) && (!count($ad_owner_id) || ($data['ad_owner'] = $ad_owner_id[0]) === false))
535 4
			{
536 2
				$this->errors[] = $this->user->lang('AD_OWNER_INVALID');
537 2
			}
538 4
		}
539
		else
540
		{
541 21
			$data['ad_owner'] = 0;
542
		}
543
544 25
		return $data;
545
	}
546
547
	/**
548
	 * Assign form data to the template.
549
	 *
550
	 * @param    array $data The form data.
551
	 * @return void
552
	 */
553 23
	protected function assign_form_data($data)
554
	{
555 23
		$this->template->assign_vars(array(
556 23
			'S_ERROR'   => (bool) count($this->errors),
557 23
			'ERROR_MSG' => count($this->errors) ? implode('<br />', $this->errors) : '',
558
559 23
			'AD_NAME'         => $data['ad_name'],
560 23
			'AD_NOTE'         => $data['ad_note'],
561 23
			'AD_CODE'         => $data['ad_code'],
562 23
			'AD_ENABLED'      => $data['ad_enabled'],
563 23
			'AD_END_DATE'     => $this->prepare_end_date($data['ad_end_date']),
564 23
			'AD_PRIORITY'     => $data['ad_priority'],
565 23
			'AD_VIEWS_LIMIT'  => $data['ad_views_limit'],
566 23
			'AD_CLICKS_LIMIT' => $data['ad_clicks_limit'],
567 23
			'AD_OWNER'        => $this->prepare_ad_owner($data['ad_owner']),
568 23
		));
569 23
	}
570
571
	/**
572
	 * Prepare end date for display
573
	 *
574
	 * @param    mixed $end_date End date.
575
	 * @return    string    End date prepared for display.
576
	 */
577 23
	protected function prepare_end_date($end_date)
578
	{
579 23
		if (empty($end_date))
580 23
		{
581 18
			return '';
582
		}
583
584 5
		if (is_numeric($end_date))
585 5
		{
586 3
			return $this->user->format_date($end_date, self::DATE_FORMAT);
587
		}
588
589 2
		return (string) $end_date;
590
	}
591
592
	/**
593
	 * Prepare ad owner for display
594
	 *
595
	 * @param	mixed	$ad_owner	End date.
596
	 * @return	string	End date prepared for display.
597
	 */
598 23
	protected function prepare_ad_owner($ad_owner)
599
	{
600
		if ($ad_owner)
601 23
		{
602 3
			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...
603 3
			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...
604 3
			{
605 2
				return $ad_owner[0];
606
			}
607 1
			return $ad_owner_name[(int) $ad_owner[0]];
608
		}
609
610 20
		return '';
611
	}
612
	/**
613
	 * Assign template locations data to the template.
614
	 *
615
	 * @param    mixed $data The form data or nothing.
616
	 * @return    void
617
	 */
618 24
	protected function assign_locations($data = false)
619
	{
620 24
		foreach ($this->location_manager->get_all_locations() as $location_id => $location_data)
621
		{
622 24
			$this->template->assign_block_vars('ad_locations', array(
623 24
				'LOCATION_ID'   => $location_id,
624 24
				'LOCATION_DESC' => $location_data['desc'],
625 24
				'LOCATION_NAME' => $location_data['name'],
626 24
				'S_SELECTED'    => $data ? in_array($location_id, $data['ad_locations']) : false,
627 24
			));
628 24
		}
629 24
	}
630
631
	/**
632
	 * Prepare advertisement preview
633
	 *
634
	 * @param    string $code Ad code to preview
635
	 * @return    void
636
	 */
637 2
	protected function ad_preview($code)
638
	{
639 2
		$this->template->assign_var('PREVIEW', htmlspecialchars_decode($code));
640 2
	}
641
642
	/**
643
	 * Print success message.
644
	 *
645
	 * It takes arguments in the form of a language key, followed by language substitution values.
646
	 */
647 6
	protected function success()
648
	{
649 6
		trigger_error(call_user_func_array(array($this->user, 'lang'), func_get_args()) . adm_back_link($this->u_action));
650
	}
651
652
	/**
653
	 * Print error message.
654
	 *
655
	 * It takes arguments in the form of a language key, followed by language substitution values.
656
	 */
657 5
	protected function error()
658
	{
659 5
		trigger_error(call_user_func_array(array($this->user, 'lang'), func_get_args()) . adm_back_link($this->u_action), E_USER_WARNING);
660
	}
661
662
	/**
663
	 * Log action
664
	 *
665
	 * @param    string $action  Performed action in uppercase
666
	 * @param    string $ad_name Advertisement name
667
	 * @return    void
668
	 */
669 3
	protected function log($action, $ad_name)
670
	{
671 3
		$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_PHPBB_ADS_' . $action . '_LOG', time(), array($ad_name));
672 3
	}
673
674 24
	protected function get_find_username_link()
675
	{
676 24
		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');
677
	}
678
}
679