Completed
Pull Request — master (#52)
by Jakub
33:08 queued 31:18
created

admin_controller::action_disable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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 \phpbb\files\upload */
47
	protected $files_upload;
48
49
	/** @var string root_path */
50
	protected $root_path;
51
52
	/** @var string php_ext */
53
	protected $php_ext;
54
55
	/** @var string ext_path */
56
	protected $ext_path;
57
58
	/** @var string Custom form action */
59
	protected $u_action;
60
61
	/** @var array Form validation errors */
62
	protected $errors = array();
63
64
	/**
65
	* Constructor
66
	*
67
	* @param \phpbb\template\template		$template			Template object
68
	* @param \phpbb\user					$user				User object
69
	* @param \phpbb\request\request			$request			Request object
70
	* @param \phpbb\ads\ad\manager			$manager			Advertisement manager object
71
	* @param \phpbb\ads\location\manager	$location_manager	Template location manager object
72
	* @param \phpbb\log\log					$log				The phpBB log system
73
	* @param \phpbb\config\db_text			$config_text		Config text object
74
	* @param \phpbb\config\config			$config				Config object
75
	* @param \phpbb\files\upload			$files_upload		Files upload object
76
	* @param string                      	$root_path			phpBB root path
77
	* @param string							$php_ext			PHP extension
78
	* @param string							$ext_path			Path to this extension
79
	*/
80
	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, \phpbb\files\upload $files_upload, $root_path, $php_ext, $ext_path)
81
	{
82
		$this->template = $template;
83
		$this->user = $user;
84
		$this->request = $request;
85
		$this->manager = $manager;
86
		$this->location_manager = $location_manager;
87
		$this->log = $log;
88
		$this->config_text = $config_text;
89
		$this->config = $config;
90
		$this->files_upload = $files_upload;
91
		$this->root_path = $root_path;
92
		$this->php_ext = $php_ext;
93
		$this->ext_path = $ext_path;
94
	}
95
96
	/**
97
	 * Process user request for manage mode
98
	 *
99
	 * @return void
100
	 */
101
	public function mode_manage()
102
	{
103
		$this->setup();
104
105
		if (!function_exists('user_get_id_name'))
106
		{
107
			include($this->root_path . 'includes/functions_user.' . $this->php_ext);
108
		}
109
110
		// Trigger specific action
111
		$action = $this->request->variable('action', '');
112
		if (in_array($action, array('add', 'edit', 'enable', 'disable', 'delete')))
113
		{
114
			$this->{'action_' . $action}();
115
		}
116
117
		// Otherwise default to this
118
		$this->list_ads();
119
	}
120
121
	/**
122
	 * Process user request for settings mode
123
	 *
124
	 * @return void
125
	 */
126
	public function mode_settings()
127
	{
128
		$this->setup();
129
130
		add_form_key('phpbb/ads/settings');
131
		if ($this->request->is_set_post('submit'))
132
		{
133
			// Validate form key
134
			if (!check_form_key('phpbb/ads/settings'))
135
			{
136
				$this->errors[] = $this->user->lang('FORM_INVALID');
137
			}
138
139
			if (empty($this->errors))
140
			{
141
				$this->config->set('phpbb_ads_adblocker_message', $this->request->variable('adblocker_message', 0));
142
				$this->config->set('phpbb_ads_enable_views', $this->request->variable('enable_views', 0));
143
				$this->config->set('phpbb_ads_enable_clicks', $this->request->variable('enable_clicks', 0));
144
				$this->config_text->set('phpbb_ads_hide_groups', json_encode($this->request->variable('hide_groups', array(0))));
145
146
				$this->success('ACP_AD_SETTINGS_SAVED');
147
			}
148
149
			$this->template->assign_vars(array(
150
				'S_ERROR'   => (bool) count($this->errors),
151
				'ERROR_MSG' => count($this->errors) ? implode('<br />', $this->errors) : '',
152
			));
153
		}
154
155
		$hide_groups = json_decode($this->config_text->get('phpbb_ads_hide_groups'), true);
156
		$groups = $this->manager->load_groups();
157
		foreach ($groups as $group)
158
		{
159
			$group_name = ($group['group_type'] == GROUP_SPECIAL) ? $this->user->lang('G_' . $group['group_name']) : $group['group_name'];
160
161
			$this->template->assign_block_vars('groups', array(
162
				'ID'         => $group['group_id'],
163
				'NAME'       => $group_name,
164
				'S_SELECTED' => in_array($group['group_id'], $hide_groups),
165
			));
166
		}
167
168
		$this->template->assign_vars(array(
169
			'U_ACTION'          => $this->u_action,
170
			'ADBLOCKER_MESSAGE' => $this->config['phpbb_ads_adblocker_message'],
171
			'ENABLE_VIEWS'      => $this->config['phpbb_ads_enable_views'],
172
			'ENABLE_CLICKS'     => $this->config['phpbb_ads_enable_clicks'],
173
		));
174
	}
175
176
	/**
177
	 * Set page url
178
	 *
179
	 * @param string $u_action Custom form action
180
	 * @return void
181
	 */
182
	public function set_page_url($u_action)
183
	{
184
		$this->u_action = $u_action;
185
	}
186
187
	/**
188
	 * Get ACP page title for Ads module
189
	 *
190
	 * @return string    Language string for Ads ACP module
191
	 */
192
	public function get_page_title()
193
	{
194
		return $this->user->lang('ACP_PHPBB_ADS_TITLE');
195
	}
196
197
	/**
198
	 * Add an advertisement
199
	 *
200
	 * @return void
201
	 */
202
	public function action_add()
203
	{
204
		$preview = $this->request->is_set_post('preview');
205
		$submit = $this->request->is_set_post('submit');
206
		$upload_banner = $this->request->is_set_post('upload_banner');
207
208
		add_form_key('phpbb/ads/add');
209
		if ($preview || $submit || $upload_banner)
210
		{
211
			$data = $this->get_form_data('phpbb/ads/add');
212
213 View Code Duplication
			if ($preview)
214
			{
215
				$this->ad_preview($data['ad_code']);
216
			}
217
			else if ($upload_banner)
218
			{
219
				$data['ad_code'] = $this->process_banner_upload($data['ad_code']);
220
			}
221
			else if (empty($this->errors))
222
			{
223
				$ad_id = $this->manager->insert_ad($data);
224
				$this->manager->insert_ad_locations($ad_id, $data['ad_locations']);
225
226
				$this->log('ADD', $data['ad_name']);
227
228
				$this->success('ACP_AD_ADD_SUCCESS');
229
			}
230
231
			$this->assign_locations($data);
232
			$this->assign_form_data($data);
233
		}
234
		else
235
		{
236
			$this->assign_locations();
237
		}
238
239
		// Set output vars for display in the template
240
		$this->template->assign_vars(array(
241
			'S_ADD_AD'           => true,
242
			'U_BACK'             => $this->u_action,
243
			'U_ACTION'           => "{$this->u_action}&amp;action=add",
244
			'PICKER_DATE_FORMAT' => self::DATE_FORMAT,
245
			'U_FIND_USERNAME'    => $this->get_find_username_link(),
246
		));
247
	}
248
249
	/**
250
	 * Edit an advertisement
251
	 *
252
	 * @return void
253
	 */
254
	public function action_edit()
255
	{
256
		$ad_id = $this->request->variable('id', 0);
257
		$preview = $this->request->is_set_post('preview');
258
		$submit = $this->request->is_set_post('submit');
259
		$upload_banner = $this->request->is_set_post('upload_banner');
260
261
		add_form_key('phpbb/ads/edit/' . $ad_id);
262
		if ($preview || $submit || $upload_banner)
263
		{
264
			$data = $this->get_form_data('phpbb/ads/edit/' . $ad_id);
265
266
			if ($preview)
267
			{
268
				$this->ad_preview($data['ad_code']);
269
			}
270 View Code Duplication
			else if ($upload_banner)
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
271
			{
272
				$data['ad_code'] = $this->process_banner_upload($data['ad_code']);
273
			}
274
			else if (empty($this->errors))
275
			{
276
				$success = $this->manager->update_ad($ad_id, $data);
277
278
				if ($success)
279
				{
280
					// Only insert new ad locations to DB when ad exists
281
					$this->manager->delete_ad_locations($ad_id);
282
					$this->manager->insert_ad_locations($ad_id, $data['ad_locations']);
283
284
					$this->log('EDIT', $data['ad_name']);
285
286
					$this->success('ACP_AD_EDIT_SUCCESS');
287
				}
288
289
				$this->error('ACP_AD_DOES_NOT_EXIST');
290
			}
291
		}
292
		else
293
		{
294
			$data = $this->manager->get_ad($ad_id);
295
			if (empty($data))
296
			{
297
				$this->error('ACP_AD_DOES_NOT_EXIST');
298
			}
299
300
			// Load ad template locations
301
			$data['ad_locations'] = $this->manager->get_ad_locations($ad_id);
302
		}
303
304
		// Set output vars for display in the template
305
		$this->template->assign_vars(array(
306
			'S_EDIT_AD'          => true,
307
			'EDIT_ID'            => $ad_id,
308
			'U_BACK'             => $this->u_action,
309
			'U_ACTION'           => "{$this->u_action}&amp;action=edit&amp;id=" . $ad_id,
310
			'PICKER_DATE_FORMAT' => self::DATE_FORMAT,
311
			'U_FIND_USERNAME'    => $this->get_find_username_link(),
312
		));
313
		$this->assign_locations($data);
314
		$this->assign_form_data($data);
315
	}
316
317
	/**
318
	 * Enable an advertisement
319
	 *
320
	 * @return void
321
	 */
322
	public function action_enable()
323
	{
324
		$this->ad_enable(true);
325
	}
326
327
	/**
328
	 * Disable an advertisement
329
	 *
330
	 * @return void
331
	 */
332
	public function action_disable()
333
	{
334
		$this->ad_enable(false);
335
	}
336
337
	/**
338
	 * Delete an advertisement
339
	 *
340
	 * @return void
341
	 */
342
	public function action_delete()
343
	{
344
		$ad_id = $this->request->variable('id', 0);
345
		if ($ad_id)
346
		{
347
			if (confirm_box(true))
348
			{
349
				// Get ad data so that we can log ad name
350
				$ad_data = $this->manager->get_ad($ad_id);
351
352
				// Delete ad and it's template locations
353
				$this->manager->delete_ad_locations($ad_id);
354
				$success = $this->manager->delete_ad($ad_id);
355
356
				// Only notify user on error or if not ajax
357
				if (!$success)
358
				{
359
					$this->error('ACP_AD_DELETE_ERRORED');
360
				}
361
				else
362
				{
363
					$this->log('DELETE', $ad_data['ad_name']);
364
365
					if (!$this->request->is_ajax())
366
					{
367
						$this->success('ACP_AD_DELETE_SUCCESS');
368
					}
369
				}
370
			}
371
			else
372
			{
373
				confirm_box(false, $this->user->lang('CONFIRM_OPERATION'), build_hidden_fields(array(
374
					'id'     => $ad_id,
375
					'i'      => $this->request->variable('i', ''),
376
					'mode'   => $this->request->variable('mode', ''),
377
					'action' => 'delete'
378
				)));
379
			}
380
		}
381
	}
382
383
	/**
384
	 * Display the ads
385
	 *
386
	 * @return void
387
	 */
388
	public function list_ads()
389
	{
390
		foreach ($this->manager->get_all_ads() as $row)
391
		{
392
			$ad_enabled = (int) $row['ad_enabled'];
393
			$ad_end_date = (int) $row['ad_end_date'];
394
			$ad_expired = $ad_end_date > 0 && $ad_end_date < time();
395
			if ($ad_expired && $ad_enabled)
396
			{
397
				$ad_enabled = 0;
398
				$this->manager->update_ad($row['ad_id'], array('ad_enabled' => 0));
399
			}
400
401
			$this->template->assign_block_vars('ads', array(
402
				'NAME'               => $row['ad_name'],
403
				'END_DATE'           => $ad_end_date ? $this->user->format_date($ad_end_date, self::DATE_FORMAT) : '',
404
				'VIEWS'              => $row['ad_views'],
405
				'CLICKS'             => $row['ad_clicks'],
406
				'VIEWS_LIMIT'        => $row['ad_views_limit'],
407
				'CLICKS_LIMIT'       => $row['ad_clicks_limit'],
408
				'S_END_DATE_EXPIRED' => $ad_expired,
409
				'S_ENABLED'          => $ad_enabled,
410
				'U_ENABLE'           => $this->u_action . '&amp;action=' . ($ad_enabled ? 'disable' : 'enable') . '&amp;id=' . $row['ad_id'],
411
				'U_EDIT'             => $this->u_action . '&amp;action=edit&amp;id=' . $row['ad_id'],
412
				'U_DELETE'           => $this->u_action . '&amp;action=delete&amp;id=' . $row['ad_id'],
413
			));
414
		}
415
416
		// Set output vars for display in the template
417
		$this->template->assign_vars(array(
418
			'U_ACTION_ADD'     => $this->u_action . '&amp;action=add',
419
			'S_VIEWS_ENABLED'  => $this->config['phpbb_ads_enable_views'],
420
			'S_CLICKS_ENABLED' => $this->config['phpbb_ads_enable_clicks'],
421
		));
422
	}
423
424
	/**
425
	 * Perform general tasks
426
	 *
427
	 * @return void
428
	 */
429
	protected function setup()
430
	{
431
		$this->user->add_lang('posting'); // Used by process_banner_upload() file errors
432
		$this->user->add_lang_ext('phpbb/ads', 'acp');
433
434
		$this->template->assign_var('S_PHPBB_ADS', true);
435
	}
436
437
	/**
438
	 * Enable/disable an advertisement
439
	 *
440
	 * @param    bool $enable Enable or disable the advertisement?
441
	 * @return void
442
	 */
443
	protected function ad_enable($enable)
444
	{
445
		$ad_id = $this->request->variable('id', 0);
446
447
		$success = $this->manager->update_ad($ad_id, array(
448
			'ad_enabled' => (int) $enable,
449
		));
450
451
		// If AJAX was used, show user a result message
452
		if ($this->request->is_ajax())
453
		{
454
			$json_response = new \phpbb\json_response;
455
			$json_response->send(array(
456
				'text'  => $this->user->lang($enable ? 'ENABLED' : 'DISABLED'),
457
				'title' => $this->user->lang('AD_ENABLE_TITLE', (int) $enable),
458
			));
459
		}
460
461
		// Otherwise, show traditional infobox
462
		if ($success)
463
		{
464
			$this->success($enable ? 'ACP_AD_ENABLE_SUCCESS' : 'ACP_AD_DISABLE_SUCCESS');
465
		}
466
		else
467
		{
468
			$this->error($enable ? 'ACP_AD_ENABLE_ERRORED' : 'ACP_AD_DISABLE_ERRORED');
469
		}
470
	}
471
472
	/**
473
	 * Upload image and return updated ad code or <img> of new banner when using ajax.
474
	 *
475
	 * @param	 string	 $ad_code	 Current ad code
476
	 * @return	 mixed	 JsonResponse when request is ajax or updated ad code otherwise.
477
	 */
478
	protected function process_banner_upload($ad_code)
479
	{
480
		// Set file restrictions
481
		$this->files_upload->reset_vars();
482
		$this->files_upload->set_allowed_extensions(array('gif', 'jpg', 'jpeg', 'png'));
483
484
		// Upload file
485
		$file = $this->files_upload->handle_upload('files.types.form', 'banner');
486
		$file->clean_filename('unique_ext');
487
		$file->move_file('images/phpbb_ads');
488
489
		// Problem with uploading
490
		if (sizeof($file->error))
491
		{
492
			$file->remove();
493
			if ($this->request->is_ajax())
494
			{
495
				$json_response = new \phpbb\json_response;
496
				$json_response->send(array(
497
					'success'	=> false,
498
					'title'		=> $this->user->lang('INFORMATION'),
499
					'text'		=> implode(',', $file->error),
500
				));
501
			}
502
			else
503
			{
504
				$this->errors[] = implode(',', $file->error);
505
			}
506
		}
507
		else
508
		{
509
			$banner_html = '<img src="' . generate_board_url() . '/images/phpbb_ads/' . $file->get('realname') . '" />';
510
511
			if ($this->request->is_ajax())
512
			{
513
				$json_response = new \phpbb\json_response;
514
				$json_response->send(array(
515
					'success'	=> true,
516
					'text'		=> $banner_html,
517
				));
518
			}
519
520
			return $ad_code . "\n\n" . $banner_html;
521
		}
522
523
		return $ad_code;
524
	}
525
526
	/**
527
	* Get admin form data.
528
	*
529
	* @param	string	$form_name	The form name.
530
	* @return	array	Form data
531
	*/
532
	protected function get_form_data($form_name)
533
	{
534
		$data = array(
535
			'ad_name'         => $this->request->variable('ad_name', '', true),
536
			'ad_note'         => $this->request->variable('ad_note', '', true),
537
			'ad_code'         => $this->request->variable('ad_code', '', true),
538
			'ad_enabled'      => $this->request->variable('ad_enabled', 0),
539
			'ad_locations'    => $this->request->variable('ad_locations', array('')),
540
			'ad_end_date'     => $this->request->variable('ad_end_date', ''),
541
			'ad_priority'     => $this->request->variable('ad_priority', self::DEFAULT_PRIORITY),
542
			'ad_views_limit'  => $this->request->variable('ad_views_limit', 0),
543
			'ad_clicks_limit' => $this->request->variable('ad_clicks_limit', 0),
544
			'ad_owner'        => $this->request->variable('ad_owner', '', true),
545
		);
546
547
		// Validate form key
548
		if (!check_form_key($form_name))
549
		{
550
			$this->errors[] = $this->user->lang('FORM_INVALID');
551
		}
552
553
		// Validate ad name
554
		if ($data['ad_name'] === '')
555
		{
556
			$this->errors[] = $this->user->lang('AD_NAME_REQUIRED');
557
		}
558
		if (truncate_string($data['ad_name'], self::MAX_NAME_LENGTH) !== $data['ad_name'])
559
		{
560
			$this->errors[] = $this->user->lang('AD_NAME_TOO_LONG', self::MAX_NAME_LENGTH);
561
		}
562
563
		// Validate ad end date
564
		if (preg_match('#^\d{4}\-\d{2}\-\d{2}$#', $data['ad_end_date']))
565
		{
566
			$data['ad_end_date'] = (int) $this->user->get_timestamp_from_format(self::DATE_FORMAT, $data['ad_end_date']);
567
568
			if ($data['ad_end_date'] < time())
569
			{
570
				$this->errors[] = $this->user->lang('AD_END_DATE_INVALID');
571
			}
572
		}
573
		else if ($data['ad_end_date'] !== '')
574
		{
575
			$this->errors[] = $this->user->lang('AD_END_DATE_INVALID');
576
		}
577
		else
578
		{
579
			$data['ad_end_date'] = 0;
580
		}
581
582
		// Validate ad priority
583
		if ($data['ad_priority'] < 1 || $data['ad_priority'] > 10)
584
		{
585
			$this->errors[] = $this->user->lang('AD_PRIORITY_INVALID');
586
		}
587
588
		// Validate ad views limit
589
		if ($data['ad_views_limit'] < 0)
590
		{
591
			$this->errors[] = $this->user->lang('AD_VIEWS_LIMIT_INVALID');
592
		}
593
594
		// Validate ad clicks limit
595
		if ($data['ad_clicks_limit'] < 0)
596
		{
597
			$this->errors[] = $this->user->lang('AD_CLICKS_LIMIT_INVALID');
598
		}
599
600
		// Validate ad owner. Username in $data['ad_owner'] will be replaced with user_id.
601
		if (!empty($data['ad_owner']))
602
		{
603
			// Function returns false if everything is OK.
604
			if (user_get_id_name($ad_owner_id, $data['ad_owner']))
605
			{
606
				$this->errors[] = $this->user->lang('AD_OWNER_INVALID');
607
			}
608
			else
609
			{
610
				$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...
611
			}
612
		}
613
		else
614
		{
615
			$data['ad_owner'] = 0;
616
		}
617
618
		return $data;
619
	}
620
621
	/**
622
	 * Assign form data to the template.
623
	 *
624
	 * @param    array $data The form data.
625
	 * @return void
626
	 */
627
	protected function assign_form_data($data)
628
	{
629
		$this->template->assign_vars(array(
630
			'S_ERROR'   => (bool) count($this->errors),
631
			'ERROR_MSG' => count($this->errors) ? implode('<br />', $this->errors) : '',
632
633
			'AD_NAME'         => $data['ad_name'],
634
			'AD_NOTE'         => $data['ad_note'],
635
			'AD_CODE'         => $data['ad_code'],
636
			'AD_ENABLED'      => $data['ad_enabled'],
637
			'AD_END_DATE'     => $this->prepare_end_date($data['ad_end_date']),
638
			'AD_PRIORITY'     => $data['ad_priority'],
639
			'AD_VIEWS_LIMIT'  => $data['ad_views_limit'],
640
			'AD_CLICKS_LIMIT' => $data['ad_clicks_limit'],
641
			'AD_OWNER'        => $this->prepare_ad_owner($data['ad_owner']),
642
		));
643
	}
644
645
	/**
646
	 * Prepare end date for display
647
	 *
648
	 * @param    mixed $end_date End date.
649
	 * @return    string    End date prepared for display.
650
	 */
651
	protected function prepare_end_date($end_date)
652
	{
653
		if (empty($end_date))
654
		{
655
			return '';
656
		}
657
658
		if (is_numeric($end_date))
659
		{
660
			return $this->user->format_date($end_date, self::DATE_FORMAT);
661
		}
662
663
		return (string) $end_date;
664
	}
665
666
	/**
667
	 * Prepare ad owner for display. Method takes user_id
668
	 * of the ad owner and returns his/her username.
669
	 *
670
	 * @param	int		$ad_owner	User ID
671
	 * @return	string	Username belonging to $ad_owner.
672
	 */
673
	protected function prepare_ad_owner($ad_owner)
674
	{
675
		// Returns false when no errors occur trying to find the user
676
		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...
677
		{
678
			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...
679
			{
680
				return $ad_owner[0];
681
			}
682
			return $ad_owner_name[(int) $ad_owner[0]];
683
		}
684
		return '';
685
	}
686
	/**
687
	 * Assign template locations data to the template.
688
	 *
689
	 * @param    mixed $data The form data or nothing.
690
	 * @return    void
691
	 */
692
	protected function assign_locations($data = false)
693
	{
694
		foreach ($this->location_manager->get_all_locations() as $location_id => $location_data)
695
		{
696
			$this->template->assign_block_vars('ad_locations', array(
697
				'LOCATION_ID'   => $location_id,
698
				'LOCATION_DESC' => $location_data['desc'],
699
				'LOCATION_NAME' => $location_data['name'],
700
				'S_SELECTED'    => $data ? in_array($location_id, $data['ad_locations']) : false,
701
			));
702
		}
703
	}
704
705
	/**
706
	 * Prepare advertisement preview
707
	 *
708
	 * @param    string $code Ad code to preview
709
	 * @return    void
710
	 */
711
	protected function ad_preview($code)
712
	{
713
		$this->template->assign_var('PREVIEW', htmlspecialchars_decode($code));
714
	}
715
716
	/**
717
	 * Print success message.
718
	 *
719
	 * It takes arguments in the form of a language key, followed by language substitution values.
720
	 */
721
	protected function success()
722
	{
723
		trigger_error(call_user_func_array(array($this->user, 'lang'), func_get_args()) . adm_back_link($this->u_action));
724
	}
725
726
	/**
727
	 * Print error message.
728
	 *
729
	 * It takes arguments in the form of a language key, followed by language substitution values.
730
	 */
731
	protected function error()
732
	{
733
		trigger_error(call_user_func_array(array($this->user, 'lang'), func_get_args()) . adm_back_link($this->u_action), E_USER_WARNING);
734
	}
735
736
	/**
737
	 * Log action
738
	 *
739
	 * @param    string $action  Performed action in uppercase
740
	 * @param    string $ad_name Advertisement name
741
	 * @return    void
742
	 */
743
	protected function log($action, $ad_name)
744
	{
745
		$this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_PHPBB_ADS_' . $action . '_LOG', time(), array($ad_name));
746
	}
747
748
	protected function get_find_username_link()
749
	{
750
		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');
751
	}
752
}
753