phpbb-extensions /
ad-management
| 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 | use phpbb\ads\ext; |
||||
| 14 | |||||
| 15 | /** |
||||
| 16 | * Admin controller |
||||
| 17 | */ |
||||
| 18 | class admin_controller |
||||
| 19 | { |
||||
| 20 | /** @var array Form data */ |
||||
| 21 | protected $data = array(); |
||||
| 22 | |||||
| 23 | /** @var \phpbb\template\template */ |
||||
|
0 ignored issues
–
show
|
|||||
| 24 | protected $template; |
||||
| 25 | |||||
| 26 | /** @var \phpbb\language\language */ |
||||
|
0 ignored issues
–
show
The type
phpbb\language\language was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 27 | protected $language; |
||||
| 28 | |||||
| 29 | /** @var \phpbb\request\request */ |
||||
|
0 ignored issues
–
show
The type
phpbb\request\request was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 30 | protected $request; |
||||
| 31 | |||||
| 32 | /** @var \phpbb\ads\ad\manager */ |
||||
| 33 | protected $manager; |
||||
| 34 | |||||
| 35 | /** @var \phpbb\config\db_text */ |
||||
|
0 ignored issues
–
show
The type
phpbb\config\db_text was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 36 | protected $config_text; |
||||
| 37 | |||||
| 38 | /** @var \phpbb\config\config */ |
||||
|
0 ignored issues
–
show
The type
phpbb\config\config was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 39 | protected $config; |
||||
| 40 | |||||
| 41 | /** @var \phpbb\ads\controller\admin_input */ |
||||
| 42 | protected $input; |
||||
| 43 | |||||
| 44 | /** @var \phpbb\ads\controller\helper */ |
||||
| 45 | protected $helper; |
||||
| 46 | |||||
| 47 | /** @var \phpbb\ads\analyser\manager */ |
||||
| 48 | protected $analyser; |
||||
| 49 | |||||
| 50 | /** @var \phpbb\controller\helper */ |
||||
|
0 ignored issues
–
show
The type
phpbb\controller\helper was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 51 | protected $controller_helper; |
||||
| 52 | |||||
| 53 | /** @var string Custom form action */ |
||||
| 54 | protected $u_action; |
||||
| 55 | |||||
| 56 | /** @var \auth_admin Auth admin */ |
||||
|
0 ignored issues
–
show
The type
auth_admin was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 57 | protected $auth_admin; |
||||
| 58 | |||||
| 59 | /** |
||||
| 60 | * Constructor |
||||
| 61 | * |
||||
| 62 | * @param \phpbb\template\template $template Template object |
||||
| 63 | * @param \phpbb\language\language $language Language object |
||||
| 64 | * @param \phpbb\request\request $request Request object |
||||
| 65 | * @param \phpbb\ads\ad\manager $manager Advertisement manager object |
||||
| 66 | * @param \phpbb\config\db_text $config_text Config text object |
||||
| 67 | * @param \phpbb\config\config $config Config object |
||||
| 68 | * @param \phpbb\ads\controller\admin_input $input Admin input object |
||||
| 69 | * @param \phpbb\ads\controller\helper $helper Helper object |
||||
| 70 | * @param \phpbb\ads\analyser\manager $analyser Ad code analyser object |
||||
| 71 | * @param \phpbb\controller\helper $controller_helper Controller helper object |
||||
| 72 | * @param string $root_path phpBB root path |
||||
| 73 | * @param string $php_ext PHP extension |
||||
| 74 | */ |
||||
| 75 | 37 | public function __construct(\phpbb\template\template $template, \phpbb\language\language $language, \phpbb\request\request $request, \phpbb\ads\ad\manager $manager, \phpbb\config\db_text $config_text, \phpbb\config\config $config, \phpbb\ads\controller\admin_input $input, \phpbb\ads\controller\helper $helper, \phpbb\ads\analyser\manager $analyser, \phpbb\controller\helper $controller_helper, $root_path, $php_ext) |
|||
| 76 | { |
||||
| 77 | 37 | $this->template = $template; |
|||
| 78 | 37 | $this->language = $language; |
|||
| 79 | 37 | $this->request = $request; |
|||
| 80 | 37 | $this->manager = $manager; |
|||
| 81 | 37 | $this->config_text = $config_text; |
|||
| 82 | 37 | $this->config = $config; |
|||
| 83 | 37 | $this->input = $input; |
|||
| 84 | 37 | $this->helper = $helper; |
|||
| 85 | 37 | $this->analyser = $analyser; |
|||
| 86 | 37 | $this->controller_helper = $controller_helper; |
|||
| 87 | |||||
| 88 | 37 | $this->language->add_lang('posting'); // Used by banner_upload() file errors |
|||
| 89 | 37 | $this->language->add_lang('acp', 'phpbb/ads'); |
|||
| 90 | |||||
| 91 | 37 | $this->template->assign_var('S_PHPBB_ADS', true); |
|||
| 92 | |||||
| 93 | 37 | if (!class_exists('auth_admin')) |
|||
| 94 | 37 | { |
|||
| 95 | 1 | include($root_path . 'includes/acp/auth.' . $php_ext); |
|||
| 96 | 1 | } |
|||
| 97 | 37 | $this->auth_admin = new \auth_admin(); |
|||
| 98 | 37 | } |
|||
| 99 | |||||
| 100 | /** |
||||
| 101 | * Set page url |
||||
| 102 | * |
||||
| 103 | * @param string $u_action Custom form action |
||||
| 104 | * @return void |
||||
| 105 | */ |
||||
| 106 | 31 | public function set_page_url($u_action) |
|||
| 107 | { |
||||
| 108 | 31 | $this->u_action = $u_action; |
|||
| 109 | 31 | } |
|||
| 110 | |||||
| 111 | /** |
||||
| 112 | * Process user request for settings mode |
||||
| 113 | * |
||||
| 114 | * @return void |
||||
| 115 | */ |
||||
| 116 | 1 | public function mode_settings() |
|||
| 117 | { |
||||
| 118 | 1 | if ($this->request->is_set_post('submit')) |
|||
| 119 | { |
||||
| 120 | // Validate form key |
||||
| 121 | if (check_form_key('phpbb_ads')) |
||||
|
0 ignored issues
–
show
The function
check_form_key was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 122 | { |
||||
| 123 | $this->config->set('phpbb_ads_adblocker_message', $this->request->variable('adblocker_message', 0)); |
||||
| 124 | $this->config->set('phpbb_ads_enable_views', $this->request->variable('enable_views', 0)); |
||||
| 125 | $this->config->set('phpbb_ads_enable_clicks', $this->request->variable('enable_clicks', 0)); |
||||
| 126 | 3 | $this->config->set('phpbb_ads_show_agreement', $this->request->variable('show_agreement', 0)); |
|||
| 127 | |||||
| 128 | 3 | $this->success('ACP_AD_SETTINGS_SAVED'); |
|||
| 129 | 3 | } |
|||
| 130 | |||||
| 131 | 2 | $this->error('FORM_INVALID'); |
|||
| 132 | 2 | } |
|||
| 133 | 1 | ||||
| 134 | 1 | $this->template->assign_vars(array( |
|||
| 135 | 1 | 'U_ACTION' => $this->u_action, |
|||
| 136 | 'AD_BLOCK_MODES' => ext::AD_BLOCK_MODES, |
||||
| 137 | 1 | 'AD_BLOCK_CONFIG' => $this->config['phpbb_ads_adblocker_message'], |
|||
| 138 | 'ENABLE_VIEWS' => $this->config['phpbb_ads_enable_views'], |
||||
| 139 | 'ENABLE_CLICKS' => $this->config['phpbb_ads_enable_clicks'], |
||||
| 140 | 1 | 'SHOW_AGREEMENT' => $this->config['phpbb_ads_show_agreement'], |
|||
| 141 | )); |
||||
| 142 | } |
||||
| 143 | 1 | ||||
| 144 | 1 | /** |
|||
| 145 | 1 | * Process user request for manage mode |
|||
| 146 | 1 | * |
|||
| 147 | 1 | * @return void |
|||
| 148 | 1 | */ |
|||
| 149 | 1 | public function mode_manage() |
|||
| 150 | { |
||||
| 151 | // Trigger specific action |
||||
| 152 | $action = $this->request->variable('action', ''); |
||||
| 153 | if (in_array($action, array('add', 'edit', 'enable', 'disable', 'delete'))) |
||||
| 154 | { |
||||
| 155 | $this->{'action_' . $action}(); |
||||
| 156 | 33 | } |
|||
| 157 | else |
||||
| 158 | { |
||||
| 159 | 33 | // Otherwise default to this |
|||
| 160 | 33 | $this->list_ads(); |
|||
| 161 | 33 | } |
|||
| 162 | 31 | } |
|||
| 163 | 16 | ||||
| 164 | /** |
||||
| 165 | * Add an advertisement |
||||
| 166 | * |
||||
| 167 | 2 | * @return void |
|||
| 168 | */ |
||||
| 169 | 18 | protected function action_add() |
|||
| 170 | { |
||||
| 171 | $action = $this->get_submitted_action(); |
||||
| 172 | if ($action !== false) |
||||
| 173 | { |
||||
| 174 | $this->data = $this->input->get_form_data(); |
||||
| 175 | $this->{$action}(); |
||||
| 176 | 21 | $this->helper->assign_data($this->data, $this->input->get_errors()); |
|||
| 177 | } |
||||
| 178 | 8 | else |
|||
| 179 | 8 | { |
|||
| 180 | 8 | $this->helper->assign_locations(); |
|||
| 181 | 7 | $this->helper->assign_groups(); |
|||
| 182 | 7 | } |
|||
| 183 | 5 | ||||
| 184 | 5 | // Set output vars for display in the template |
|||
| 185 | $this->template->assign_vars(array( |
||||
| 186 | 'S_ADD_AD' => true, |
||||
| 187 | 1 | 'U_BACK' => $this->u_action, |
|||
| 188 | 1 | 'U_ACTION' => "{$this->u_action}&action=add", |
|||
| 189 | 'U_FIND_USERNAME' => $this->helper->get_find_username_link(), |
||||
| 190 | 'U_ENABLE_VISUAL_DEMO' => $this->controller_helper->route('phpbb_ads_visual_demo', array('action' => 'enable')), |
||||
| 191 | 'DATE_MINIMUM' => $this->helper->get_date('tomorrow'), |
||||
| 192 | 6 | )); |
|||
| 193 | 6 | } |
|||
| 194 | 6 | ||||
| 195 | 6 | /** |
|||
| 196 | 6 | * Edit an advertisement |
|||
| 197 | 21 | * |
|||
| 198 | 6 | * @return void |
|||
| 199 | 6 | */ |
|||
| 200 | 6 | protected function action_edit() |
|||
| 201 | { |
||||
| 202 | $ad_id = $this->request->variable('id', 0); |
||||
| 203 | $action = $this->get_submitted_action(); |
||||
| 204 | if ($action !== false) |
||||
| 205 | { |
||||
| 206 | $this->data = $this->input->get_form_data(); |
||||
| 207 | 8 | $this->{$action}(); |
|||
| 208 | } |
||||
| 209 | 8 | else |
|||
| 210 | 8 | { |
|||
| 211 | 8 | $this->data = $this->manager->get_ad($ad_id); |
|||
| 212 | 8 | if (empty($this->data)) |
|||
| 213 | 6 | { |
|||
| 214 | 6 | $this->error('ACP_AD_DOES_NOT_EXIST'); |
|||
| 215 | 3 | } |
|||
| 216 | // Load ad template locations |
||||
| 217 | $this->data['ad_locations'] = $this->manager->get_ad_locations($ad_id); |
||||
| 218 | 2 | } |
|||
| 219 | 2 | ||||
| 220 | 2 | // Set output vars for display in the template |
|||
| 221 | 1 | $this->template->assign_vars(array( |
|||
| 222 | 'S_EDIT_AD' => true, |
||||
| 223 | 'EDIT_ID' => $ad_id, |
||||
| 224 | 1 | 'U_BACK' => $this->u_action, |
|||
| 225 | 'U_ACTION' => "{$this->u_action}&action=edit&id=$ad_id", |
||||
| 226 | 'U_FIND_USERNAME' => $this->helper->get_find_username_link(), |
||||
| 227 | 'U_ENABLE_VISUAL_DEMO' => $this->controller_helper->route('phpbb_ads_visual_demo', array('action' => 'enable')), |
||||
| 228 | 4 | 'DATE_MINIMUM' => $this->helper->get_date('tomorrow'), |
|||
| 229 | 4 | )); |
|||
| 230 | 4 | $this->helper->assign_data($this->data, $this->input->get_errors()); |
|||
| 231 | 4 | } |
|||
| 232 | 4 | ||||
| 233 | 4 | /** |
|||
| 234 | 4 | * Enable an advertisement |
|||
| 235 | 4 | * |
|||
| 236 | 4 | * @return void |
|||
| 237 | 4 | */ |
|||
| 238 | 4 | protected function action_enable() |
|||
| 239 | { |
||||
| 240 | $this->ad_enable(true); |
||||
| 241 | } |
||||
| 242 | |||||
| 243 | /** |
||||
| 244 | * Disable an advertisement |
||||
| 245 | 4 | * |
|||
| 246 | * @return void |
||||
| 247 | 4 | */ |
|||
| 248 | 1 | protected function action_disable() |
|||
| 249 | { |
||||
| 250 | $this->ad_enable(false); |
||||
| 251 | } |
||||
| 252 | |||||
| 253 | /** |
||||
| 254 | * Delete an advertisement |
||||
| 255 | 4 | * |
|||
| 256 | * @return void |
||||
| 257 | 4 | */ |
|||
| 258 | 1 | protected function action_delete() |
|||
| 259 | { |
||||
| 260 | $ad_id = $this->request->variable('id', 0); |
||||
| 261 | if ($ad_id) |
||||
| 262 | { |
||||
| 263 | if (confirm_box(true)) |
||||
|
0 ignored issues
–
show
The function
confirm_box was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 264 | { |
||||
| 265 | 4 | // Get ad data so that we can log ad name |
|||
| 266 | $ad_data = $this->manager->get_ad($ad_id); |
||||
| 267 | 4 | ||||
| 268 | // Delete ad and it's template locations |
||||
| 269 | 4 | $this->manager->delete_ad_locations($ad_id); |
|||
| 270 | 4 | $success = $this->manager->delete_ad($ad_id); |
|||
| 271 | 4 | ||||
| 272 | $this->toggle_permission($ad_data['ad_owner']); |
||||
| 273 | 3 | ||||
| 274 | // Only notify user on error or if not ajax |
||||
| 275 | if (!$success) |
||||
| 276 | 3 | { |
|||
| 277 | 3 | $this->error('ACP_AD_DELETE_ERRORED'); |
|||
| 278 | } |
||||
| 279 | 3 | else |
|||
| 280 | { |
||||
| 281 | $this->helper->log('DELETE', $ad_data['ad_name']); |
||||
| 282 | 3 | ||||
| 283 | 3 | if (!$this->request->is_ajax()) |
|||
| 284 | 1 | { |
|||
| 285 | $this->success('ACP_AD_DELETE_SUCCESS'); |
||||
| 286 | } |
||||
| 287 | } |
||||
| 288 | 2 | } |
|||
| 289 | else |
||||
| 290 | 2 | { |
|||
| 291 | 2 | confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), build_hidden_fields(array( |
|||
|
0 ignored issues
–
show
The function
build_hidden_fields was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 292 | 2 | 'id' => $ad_id, |
|||
| 293 | 'i' => $this->request->variable('i', ''), |
||||
| 294 | 'mode' => $this->request->variable('mode', ''), |
||||
| 295 | 'action' => 'delete', |
||||
| 296 | ))); |
||||
| 297 | |||||
| 298 | 1 | // When you don't confirm deleting ad |
|||
| 299 | 1 | $this->list_ads(); |
|||
| 300 | 1 | } |
|||
| 301 | 1 | } |
|||
| 302 | 1 | } |
|||
| 303 | 1 | ||||
| 304 | /** |
||||
| 305 | * Display the list of all ads |
||||
| 306 | 1 | * |
|||
| 307 | * @return void |
||||
| 308 | 1 | */ |
|||
| 309 | 1 | protected function list_ads() |
|||
| 310 | { |
||||
| 311 | foreach ($this->manager->get_all_ads() as $row) |
||||
| 312 | { |
||||
| 313 | $ad_enabled = (int) $row['ad_enabled']; |
||||
| 314 | $ad_expired = $this->helper->is_expired($row); |
||||
| 315 | |||||
| 316 | 2 | if ($ad_expired && $ad_enabled) |
|||
| 317 | { |
||||
| 318 | 2 | $ad_enabled = 0; |
|||
| 319 | $this->manager->update_ad($row['ad_id'], array('ad_enabled' => 0)); |
||||
| 320 | 1 | } |
|||
| 321 | 1 | ||||
| 322 | $this->template->assign_block_vars($ad_expired ? 'expired' : 'ads', array( |
||||
| 323 | 1 | 'NAME' => $row['ad_name'], |
|||
| 324 | 1 | 'PRIORITY' => $row['ad_priority'], |
|||
| 325 | 1 | 'START_DATE' => $row['ad_start_date'], |
|||
| 326 | 1 | 'END_DATE' => $row['ad_end_date'], |
|||
| 327 | 1 | 'VIEWS' => $row['ad_views'], |
|||
| 328 | 'CLICKS' => $row['ad_clicks'], |
||||
| 329 | 1 | 'VIEWS_LIMIT' => $row['ad_views_limit'], |
|||
| 330 | 1 | 'CLICKS_LIMIT' => $row['ad_clicks_limit'], |
|||
| 331 | 1 | 'S_EXPIRED' => $ad_expired, |
|||
| 332 | 1 | 'S_ENABLED' => $ad_enabled, |
|||
| 333 | 1 | 'U_ENABLE' => $this->u_action . '&action=' . ($ad_enabled ? 'disable' : 'enable') . '&id=' . $row['ad_id'], |
|||
| 334 | 1 | 'U_EDIT' => $this->u_action . '&action=edit&id=' . $row['ad_id'], |
|||
| 335 | 1 | 'U_DELETE' => $this->u_action . '&action=delete&id=' . $row['ad_id'], |
|||
| 336 | 1 | )); |
|||
| 337 | 1 | } |
|||
| 338 | 1 | ||||
| 339 | 1 | // Set output vars for display in the template |
|||
| 340 | 1 | $this->template->assign_vars(array( |
|||
| 341 | 1 | 'U_ACTION_ADD' => $this->u_action . '&action=add', |
|||
| 342 | 1 | 'S_VIEWS_ENABLED' => $this->config['phpbb_ads_enable_views'], |
|||
| 343 | 1 | 'S_CLICKS_ENABLED' => $this->config['phpbb_ads_enable_clicks'], |
|||
| 344 | 2 | )); |
|||
| 345 | } |
||||
| 346 | |||||
| 347 | 2 | /** |
|||
| 348 | 2 | * Get what action user wants to do with the form. |
|||
| 349 | 2 | * Possible options are: |
|||
| 350 | 2 | * - preview ad code |
|||
| 351 | 2 | * - upload banner to display in an ad code |
|||
| 352 | 2 | * - analyse ad code |
|||
| 353 | * - submit form (either add or edit an ad) |
||||
| 354 | * |
||||
| 355 | * @return string|false Action name or false when no action was submitted |
||||
| 356 | */ |
||||
| 357 | protected function get_submitted_action() |
||||
| 358 | { |
||||
| 359 | $actions = array('preview', 'upload_banner', 'analyse_ad_code', 'submit_add', 'submit_edit'); |
||||
| 360 | foreach ($actions as $action) |
||||
| 361 | { |
||||
| 362 | if ($this->request->is_set_post($action)) |
||||
| 363 | { |
||||
| 364 | 16 | return $action; |
|||
| 365 | } |
||||
| 366 | 16 | } |
|||
| 367 | 16 | ||||
| 368 | return false; |
||||
| 369 | 16 | } |
|||
| 370 | 16 | ||||
| 371 | 13 | /** |
|||
| 372 | * Enable/disable an advertisement |
||||
| 373 | 14 | * |
|||
| 374 | * @param bool $enable Enable or disable the advertisement? |
||||
| 375 | 3 | * @return void |
|||
| 376 | */ |
||||
| 377 | protected function ad_enable($enable) |
||||
| 378 | { |
||||
| 379 | $ad_id = $this->request->variable('id', 0); |
||||
| 380 | |||||
| 381 | $success = $this->manager->update_ad($ad_id, array( |
||||
| 382 | 'ad_enabled' => (int) $enable, |
||||
| 383 | )); |
||||
| 384 | 6 | ||||
| 385 | // If AJAX was used, show user a result message |
||||
| 386 | 6 | if ($this->request->is_ajax()) |
|||
| 387 | { |
||||
| 388 | 6 | $json_response = new \phpbb\json_response; |
|||
|
0 ignored issues
–
show
The type
phpbb\json_response was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 389 | 6 | $json_response->send(array( |
|||
| 390 | 6 | 'text' => $this->language->lang($enable ? 'ENABLED' : 'DISABLED'), |
|||
| 391 | 'title' => $this->language->lang('AD_ENABLE_TITLE', (int) $enable), |
||||
| 392 | )); |
||||
| 393 | 6 | } |
|||
| 394 | 6 | ||||
| 395 | 2 | // Otherwise, show traditional infobox |
|||
| 396 | 2 | if ($success) |
|||
| 397 | 2 | { |
|||
| 398 | 2 | $this->success($enable ? 'ACP_AD_ENABLE_SUCCESS' : 'ACP_AD_DISABLE_SUCCESS'); |
|||
| 399 | 2 | } |
|||
| 400 | else |
||||
| 401 | { |
||||
| 402 | $this->error($enable ? 'ACP_AD_ENABLE_ERRORED' : 'ACP_AD_DISABLE_ERRORED'); |
||||
| 403 | } |
||||
| 404 | 4 | } |
|||
| 405 | 2 | ||||
| 406 | /** |
||||
| 407 | * Submit action "preview". |
||||
| 408 | * Prepare advertisement preview. |
||||
| 409 | 2 | * |
|||
| 410 | * @return void |
||||
| 411 | */ |
||||
| 412 | protected function preview() |
||||
| 413 | { |
||||
| 414 | $this->template->assign_var('PREVIEW', htmlspecialchars_decode($this->data['ad_code'], ENT_COMPAT)); |
||||
| 415 | } |
||||
| 416 | |||||
| 417 | /** |
||||
| 418 | * Submit action "upload_banner". |
||||
| 419 | 2 | * Upload banner and append it to the ad code. |
|||
| 420 | * |
||||
| 421 | 2 | * @return void |
|||
| 422 | 2 | */ |
|||
| 423 | protected function upload_banner() |
||||
| 424 | { |
||||
| 425 | $this->data['ad_code'] = $this->input->banner_upload($this->data['ad_code']); |
||||
| 426 | } |
||||
| 427 | |||||
| 428 | /** |
||||
| 429 | * Submit action "analyse_ad_code". |
||||
| 430 | 1 | * Upload banner and append it to the ad code. |
|||
| 431 | * |
||||
| 432 | 1 | * @return void |
|||
| 433 | 1 | */ |
|||
| 434 | protected function analyse_ad_code() |
||||
| 435 | { |
||||
| 436 | $this->analyser->run($this->data['ad_code']); |
||||
| 437 | } |
||||
| 438 | |||||
| 439 | /** |
||||
| 440 | * Submit action "submit_add". |
||||
| 441 | 1 | * Add new ad. |
|||
| 442 | * |
||||
| 443 | 1 | * @return void |
|||
| 444 | 1 | */ |
|||
| 445 | protected function submit_add() |
||||
| 446 | { |
||||
| 447 | if (!$this->input->has_errors()) |
||||
| 448 | { |
||||
| 449 | $ad_id = $this->manager->insert_ad($this->data); |
||||
| 450 | $this->toggle_permission($this->data['ad_owner']); |
||||
| 451 | $this->manager->insert_ad_locations($ad_id, $this->data['ad_locations']); |
||||
| 452 | 4 | ||||
| 453 | $this->helper->log('ADD', $this->data['ad_name']); |
||||
| 454 | 4 | ||||
| 455 | 4 | $this->success('ACP_AD_ADD_SUCCESS'); |
|||
| 456 | 2 | } |
|||
| 457 | 2 | } |
|||
| 458 | 2 | ||||
| 459 | /** |
||||
| 460 | 2 | * Submit action "submit_edit". |
|||
| 461 | * Edit ad. |
||||
| 462 | 2 | * |
|||
| 463 | * @return void |
||||
| 464 | 2 | */ |
|||
| 465 | protected function submit_edit() |
||||
| 466 | { |
||||
| 467 | $ad_id = $this->request->variable('id', 0); |
||||
| 468 | if ($ad_id && !$this->input->has_errors()) |
||||
| 469 | { |
||||
| 470 | $old_data = $this->manager->get_ad($ad_id); |
||||
| 471 | $success = $this->manager->update_ad($ad_id, $this->data); |
||||
| 472 | 5 | if ($success) |
|||
| 473 | { |
||||
| 474 | 5 | // Only update permissions when update was successful |
|||
| 475 | 5 | $this->toggle_permission($old_data['ad_owner']); |
|||
| 476 | 5 | $this->toggle_permission($this->data['ad_owner']); |
|||
| 477 | 3 | ||||
| 478 | 3 | // Only insert new ad locations to DB when ad exists |
|||
| 479 | $this->manager->delete_ad_locations($ad_id); |
||||
| 480 | 3 | $this->manager->insert_ad_locations($ad_id, $this->data['ad_locations']); |
|||
| 481 | |||||
| 482 | 2 | $this->helper->log('EDIT', $this->data['ad_name']); |
|||
| 483 | 2 | ||||
| 484 | $this->success('ACP_AD_EDIT_SUCCESS'); |
||||
| 485 | } |
||||
| 486 | 2 | ||||
| 487 | 2 | $this->error('ACP_AD_DOES_NOT_EXIST'); |
|||
| 488 | } |
||||
| 489 | 2 | } |
|||
| 490 | |||||
| 491 | 2 | /** |
|||
| 492 | * Print success message. |
||||
| 493 | * |
||||
| 494 | 1 | * @param string $msg Message lang key |
|||
| 495 | */ |
||||
| 496 | 2 | protected function success($msg) |
|||
| 497 | { |
||||
| 498 | trigger_error($this->language->lang($msg) . adm_back_link($this->u_action)); |
||||
|
0 ignored issues
–
show
The function
adm_back_link was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 499 | } |
||||
| 500 | |||||
| 501 | /** |
||||
| 502 | * Print error message. |
||||
| 503 | 9 | * |
|||
| 504 | * @param string $msg Message lang key |
||||
| 505 | 9 | */ |
|||
| 506 | protected function error($msg) |
||||
| 507 | { |
||||
| 508 | trigger_error($this->language->lang($msg) . adm_back_link($this->u_action), E_USER_WARNING); |
||||
|
0 ignored issues
–
show
The function
adm_back_link was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 509 | } |
||||
| 510 | |||||
| 511 | /** |
||||
| 512 | * Try to remove or add permission to see UCP module. |
||||
| 513 | 6 | * Permission is only removed when user has no more ads. |
|||
| 514 | * Permission is only added when user has at least one ad. |
||||
| 515 | 6 | * |
|||
| 516 | * @param int $user_id User ID to try to remove permission |
||||
| 517 | * |
||||
| 518 | * @return void |
||||
| 519 | */ |
||||
| 520 | protected function toggle_permission($user_id) |
||||
| 521 | { |
||||
| 522 | if ($user_id) |
||||
| 523 | { |
||||
| 524 | $has_ads = count($this->manager->get_ads_by_owner($user_id)) !== 0; |
||||
| 525 | |||||
| 526 | $this->auth_admin->acl_set('user', 0, $user_id, array('u_phpbb_ads' => (int) $has_ads)); |
||||
| 527 | 7 | } |
|||
| 528 | } |
||||
| 529 | } |
||||
| 530 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths