• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dragomano / Optimus / 15002330223

13 May 2025 04:54PM UTC coverage: 94.636% (+0.003%) from 94.633%
15002330223

push

github

dragomano
Refactor code

4 of 4 new or added lines in 2 files covered. (100.0%)

25 existing lines in 3 files now uncovered.

1782 of 1883 relevant lines covered (94.64%)

2.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.18
/src/Sources/Optimus/Handlers/SettingHandler.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * @package Optimus
5
 * @link https://custom.simplemachines.org/mods/index.php?mod=2659
6
 * @author Bugo https://dragomano.ru/mods/optimus
7
 * @copyright 2010-2025 Bugo
8
 * @license https://opensource.org/licenses/artistic-license-2.0 Artistic-2.0
9
 *
10
 * @version 3.0 RC3
11
 */
12

13
namespace Bugo\Optimus\Handlers;
14

15
use Bugo\Compat\Actions\Admin\ACP;
16
use Bugo\Compat\{Config, Db, ErrorHandler};
17
use Bugo\Compat\{IntegrationHook, Lang};
18
use Bugo\Compat\{Theme, User, Utils};
19
use Bugo\Optimus\Services\RobotsGenerator;
20
use Bugo\Optimus\Tasks\Sitemap;
21
use Bugo\Optimus\Utils\Input;
22
use Bugo\Optimus\Utils\Str;
23

24
if (! defined('SMF'))
25
        die('No direct access...');
26

27
final class SettingHandler
28
{
29
        public function __invoke(): void
30
        {
31
                IntegrationHook::add(
1✔
32
                        'integrate_modify_basic_settings', self::class . '::modifyBasicSettings#', false, __FILE__
1✔
33
                );
1✔
34

35
                IntegrationHook::add(
1✔
36
                        'integrate_admin_areas', self::class . '::adminAreas#', false, __FILE__
1✔
37
                );
1✔
38

39
                IntegrationHook::add(
1✔
40
                        'integrate_admin_search', self::class . '::adminSearch#', false, __FILE__
1✔
41
                );
1✔
42
        }
43

44
        /**
45
         * Remove meta_keywords setting and move it to the Optimus settings
46
         *
47
         * Удаляем настройку meta_keywords и помещаем на страницу настроек Optimus
48
         */
49
        public function modifyBasicSettings(array &$config_vars): void
50
        {
51
                foreach ($config_vars as $key => $dump) {
1✔
52
                        if (isset($dump[1]) && $dump[1] === 'meta_keywords') {
1✔
53
                                unset($config_vars[$key]);
1✔
54
                        }
55
                }
56
        }
57

58
        public function adminAreas(array &$admin_areas): void
59
        {
60
                Theme::addInlineCss('
1✔
61
                .main_icons.optimus::before {
62
                        background:url(' . Theme::$current->settings['default_images_url'] . '/optimus.png) no-repeat 0 0 !important;
1✔
63
                }
64
                .large_admin_menu_icon.optimus::before {
65
                        background:url(' . Theme::$current->settings['default_images_url'] . '/optimus_large.png) no-repeat 0 0;
1✔
66
                }
67
                .fa-optimus::before {
68
                        content: "\f717";
69
                }');
1✔
70

71
                if (Input::request('area') === 'optimus') {
1✔
72
                        Theme::loadCSSFile('optimus/optimus.css');
1✔
73
                }
74

75
                $admin_areas['config']['areas']['optimus'] = [
1✔
76
                        'label' => Lang::getTxt('optimus_title', file: 'Optimus/Optimus'),
1✔
77
                        'function' => $this->actions(...),
1✔
78
                        'icon' => 'optimus',
1✔
79
                        'subsections' => [
1✔
80
                                'basic'    => [Lang::getTxt('optimus_basic_title')],
1✔
81
                                'extra'    => [Lang::getTxt('optimus_extra_title')],
1✔
82
                                'favicon'  => [Lang::getTxt('optimus_favicon_title')],
1✔
83
                                'metatags' => [Lang::getTxt('optimus_meta_title')],
1✔
84
                                'redirect' => [Lang::getTxt('optimus_redirect_title')],
1✔
85
                                'counters' => [Lang::getTxt('optimus_counters')],
1✔
86
                                'robots'   => [Lang::getTxt('optimus_robots_title')],
1✔
87
                                'htaccess' => [Lang::getTxt('optimus_htaccess_title')],
1✔
88
                                'sitemap'  => [Lang::getTxt('optimus_sitemap_title')],
1✔
89
                        ]
1✔
90
                ];
1✔
91
        }
92

93
        public function adminSearch(array $language_files, array $include_files, array &$settings_search): void
94
        {
95
                $settings_search[] = [$this->basicTabSettings(...), 'area=optimus;sa=basic'];
1✔
96
                $settings_search[] = [$this->extraTabSettings(...), 'area=optimus;sa=extra'];
1✔
97
                $settings_search[] = [$this->faviconTabSettings(...), 'area=optimus;sa=favicon'];
1✔
98
                $settings_search[] = [$this->sitemapTabSettings(...), 'area=optimus;sa=sitemap'];
1✔
99
        }
100

101
        public function actions(): void
102
        {
103
                User::$me->isAllowedTo('admin_forum');
1✔
104

105
                Utils::$context['page_title'] = OP_NAME;
1✔
106

107
                Theme::loadTemplate('Optimus');
1✔
108

109
                $subActions = [
1✔
110
                        'basic'    => 'basicTabSettings',
1✔
111
                        'extra'    => 'extraTabSettings',
1✔
112
                        'favicon'  => 'faviconTabSettings',
1✔
113
                        'metatags' => 'metatagsTabSettings',
1✔
114
                        'redirect' => 'redirectTabSettings',
1✔
115
                        'counters' => 'counterTabSettings',
1✔
116
                        'robots'   => 'robotsTabSettings',
1✔
117
                        'htaccess' => 'htaccessTabSettings',
1✔
118
                        'sitemap'  => 'sitemapTabSettings',
1✔
119
                ];
1✔
120

121
                Utils::$context[Utils::$context['admin_menu_name']]['tab_data'] = [
1✔
122
                        'title' => Lang::getTxt('optimus_title'),
1✔
123
                        'tabs' => [
1✔
124
                                'basic' => [
1✔
125
                                        'description' => sprintf(
1✔
126
                                                Lang::getTxt('optimus_basic_desc'),
1✔
127
                                                OP_VERSION,
1✔
128
                                                PHP_VERSION,
1✔
129
                                                Utils::$smcFunc['db_title'],
1✔
130
                                                Db::$db->get_version(),
1✔
131
                                        )
1✔
132
                                ],
1✔
133
                                'extra' => [
1✔
134
                                        'description' => Lang::getTxt('optimus_extra_desc')
1✔
135
                                ],
1✔
136
                                'favicon' => [
1✔
137
                                        'description' => Lang::getTxt('optimus_favicon_desc')
1✔
138
                                ],
1✔
139
                                'metatags' => [
1✔
140
                                        'description' => Lang::getTxt('optimus_meta_desc')
1✔
141
                                ],
1✔
142
                                'redirect' => [
1✔
143
                                        'description' => Lang::getTxt('optimus_redirect_desc')
1✔
144
                                ],
1✔
145
                                'counters' => [
1✔
146
                                        'description' => Lang::getTxt('optimus_counters_desc')
1✔
147
                                ],
1✔
148
                                'robots' => [
1✔
149
                                        'description' => Lang::getTxt('optimus_robots_desc')
1✔
150
                                ],
1✔
151
                                'htaccess' => [
1✔
152
                                        'description' => Lang::getTxt('optimus_htaccess_desc')
1✔
153
                                ],
1✔
154
                                'sitemap' => [
1✔
155
                                        'description' => sprintf(Lang::getTxt('optimus_sitemap_desc'), OP_NAME)
1✔
156
                                ]
1✔
157
                        ]
1✔
158
                ];
1✔
159

160
                $this->addBlockWithTips();
1✔
161

162
                $this->callActionFromAreas($subActions);
1✔
163
        }
164

165
        /**
166
         * @return void|array
167
         */
168
        public function basicTabSettings(bool $return_config = false)
169
        {
170
                Utils::$context['page_title'] .= ' - ' . Lang::getTxt('optimus_basic_title');
2✔
171
                Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=optimus;sa=basic;save';
2✔
172

173
                $this->addDefaultSettings(
2✔
174
                        ['optimus_forum_index' => sprintf(Lang::getTxt('forum_index'), Utils::$context['forum_name'])]
2✔
175
                );
2✔
176

177
                $config_vars = [
2✔
178
                        ['title', 'optimus_main_page'],
2✔
179
                        [
2✔
180
                                'text',
2✔
181
                                'optimus_forum_index',
2✔
182
                                80,
2✔
183
                                'value' => Utils::htmlspecialcharsDecode((string) (Config::$modSettings['optimus_forum_index'] ?? ''))
2✔
184
                        ],
2✔
185
                        [
2✔
186
                                'large_text',
2✔
187
                                'optimus_description',
2✔
188
                                'value' => Utils::htmlspecialcharsDecode((string) (Config::$modSettings['optimus_description'] ?? '')),
2✔
189
                                'subtext' => Lang::getTxt('optimus_description_subtext')
2✔
190
                        ],
2✔
191
                        [
2✔
192
                                'large_text',
2✔
193
                                'meta_keywords',
2✔
194
                                'label' => Lang::getTxt('meta_keywords', file: 'Search'),
2✔
195
                                'subtext' => Lang::getTxt('meta_keywords_note', file: 'ManageSettings')
2✔
196
                        ],
2✔
197
                        ['title', 'optimus_all_pages'],
2✔
198
                        ['select', 'optimus_board_extend_title', Lang::getTxt('optimus_board_extend_title_set')],
2✔
199
                        ['select', 'optimus_topic_extend_title', Lang::getTxt('optimus_topic_extend_title_set')],
2✔
200
                        '',
2✔
201
                        ['title', 'optimus_extra_settings'],
2✔
202
                        ['check', 'optimus_errors_for_wrong_actions'],
2✔
203
                        ['check', 'optimus_errors_for_wrong_boards_topics'],
2✔
204
                        ['check', 'optimus_log_search'],
2✔
205
                ];
2✔
206

207
                // You can add your own options
208
                IntegrationHook::call('integrate_optimus_basic_settings', [&$config_vars]);
2✔
209

210
                if ($return_config)
2✔
211
                        return $config_vars;
1✔
212

213
                if (Input::isGet('save')) {
2✔
214
                        User::$me->checkSession();
1✔
215

216
                        if (Input::isPost('optimus_forum_index')) {
1✔
UNCOV
217
                                Input::post(['optimus_forum_index' => Input::filter('optimus_forum_index')]);
×
218
                        }
219

220
                        if (Input::isPost('optimus_description')) {
1✔
UNCOV
221
                                Input::post(['optimus_description' => Input::filter('optimus_description')]);
×
222
                        }
223

224
                        IntegrationHook::call('integrate_save_optimus_basic_settings');
1✔
225

226
                        $save_vars = $config_vars;
1✔
227
                        ACP::saveDBSettings($save_vars);
1✔
228

229
                        Utils::redirectexit('action=admin;area=optimus;sa=basic');
1✔
230
                }
231

232
                ACP::prepareDBSettingContext($config_vars);
2✔
233
        }
234

235
        /**
236
         * @return void|array
237
         */
238
        public function extraTabSettings(bool $return_config = false)
239
        {
240
                Utils::$context['page_title'] .= ' - ' . Lang::getTxt('optimus_extra_title');
1✔
241
                Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=optimus;sa=extra;save';
1✔
242

243
                Lang::setTxt('optimus_extra_info', sprintf(Lang::getTxt('optimus_extra_info'), Config::$scripturl));
1✔
244

245
                $config_vars = [
1✔
246
                        ['title', 'optimus_extra_title'],
1✔
247
                        ['desc', 'optimus_extra_info'],
1✔
248
                        [
1✔
249
                                'check',
1✔
250
                                'optimus_og_image',
1✔
251
                                'help' => 'optimus_og_image_help',
1✔
252
                                'subtext' => sprintf(Lang::getTxt('optimus_og_image_subtext'), implode('', [
1✔
253
                                        Config::$scripturl . '?action=admin;area=theme;sa=list;th=',
1✔
254
                                        Theme::$current->settings['theme_id']  . '#options_og_image',
1✔
255
                                ]))
1✔
256
                        ],
1✔
257
                        [
1✔
258
                                'check',
1✔
259
                                'optimus_allow_change_board_og_image',
1✔
260
                                'subtext' => Lang::getTxt('optimus_allow_change_board_og_image_subtext')
1✔
261
                        ],
1✔
262
                        ['text', 'optimus_fb_appid', 40, 'help' => 'optimus_fb_appid_help'],
1✔
263
                        ['text', 'optimus_tw_cards', 40, 'preinput' => '@', 'help' => 'optimus_tw_cards_help'],
1✔
264
                ];
1✔
265

266
                // You can add your own options
267
                IntegrationHook::call('integrate_optimus_extra_settings', [&$config_vars]);
1✔
268

269
                if ($return_config)
1✔
270
                        return $config_vars;
1✔
271

272
                if (Input::isGet('save')) {
1✔
273
                        User::$me->checkSession();
1✔
274

275
                        if (Input::isPost('optimus_fb_appid')) {
1✔
276
                                Input::post(['optimus_fb_appid' => Input::filter('optimus_fb_appid')]);
×
277
                        }
278

279
                        if (Input::isPost('optimus_tw_cards')) {
1✔
UNCOV
280
                                Input::post([
×
UNCOV
281
                                        'optimus_tw_cards' => str_replace(
×
UNCOV
282
                                                '@', '', Input::filter('optimus_tw_cards'))
×
UNCOV
283
                                ]);
×
284
                        }
285

286
                        IntegrationHook::call('integrate_save_optimus_extra_settings');
1✔
287

288
                        $save_vars = $config_vars;
1✔
289
                        ACP::saveDBSettings($save_vars);
1✔
290

291
                        Utils::redirectexit('action=admin;area=optimus;sa=extra');
1✔
292
                }
293

294
                ACP::prepareDBSettingContext($config_vars);
1✔
295
        }
296

297
        /**
298
         * @return void|array
299
         */
300
        public function faviconTabSettings(bool $return_config = false)
301
        {
302
                Utils::$context['page_title'] .= ' - ' . Lang::getTxt('optimus_favicon_title');
1✔
303
                Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=optimus;sa=favicon;save';
1✔
304

305
                $config_vars = [
1✔
306
                        ['large_text', 'optimus_favicon_text'],
1✔
307
                ];
1✔
308

309
                if ($return_config)
1✔
310
                        return $config_vars;
1✔
311

312
                Utils::$context['sub_template'] = 'favicon';
1✔
313

314
                if (Input::isGet('save')) {
1✔
315
                        User::$me->checkSession();
1✔
316

317
                        $save_vars = $config_vars;
1✔
318
                        ACP::saveDBSettings($save_vars);
1✔
319

320
                        Utils::redirectexit('action=admin;area=optimus;sa=favicon');
1✔
321
                }
322

323
                ACP::prepareDBSettingContext($config_vars);
1✔
324
        }
325

326
        public function metatagsTabSettings(): void
327
        {
328
                Utils::$context['sub_template'] = 'metatags';
1✔
329
                Utils::$context['page_title'] .= ' - ' . Lang::getTxt('optimus_meta_title');
1✔
330
                Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=optimus;sa=metatags;save';
1✔
331

332
                Utils::$context['optimus_metatags_rules'] = empty(Config::$modSettings['optimus_meta'])
1✔
333
                        ? [] : unserialize(Config::$modSettings['optimus_meta']);
1✔
334

335
                $config_vars = [];
1✔
336

337
                if (Input::isGet('save')) {
1✔
338
                        User::$me->checkSession();
1✔
339

340
                        $save_vars = $config_vars;
1✔
341
                        ACP::saveDBSettings($save_vars);
1✔
342

343
                        $meta = [];
1✔
344
                        if (Input::isPost('custom_tag_name') && Input::isPost('custom_tag_value')) {
1✔
345
                                $custom_tag = filter_input_array(INPUT_POST);
×
UNCOV
346
                                $custom_tag['custom_tag_name'] = array_filter($custom_tag['custom_tag_name']);
×
347

UNCOV
348
                                foreach ($custom_tag['custom_tag_name'] as $key => $value) {
×
UNCOV
349
                                        $meta[$value] = $custom_tag['custom_tag_value'][$key];
×
350
                                }
351
                        }
352

353
                        Config::updateModSettings(['optimus_meta' => serialize($meta)]);
1✔
354
                        Utils::redirectexit('action=admin;area=optimus;sa=metatags');
1✔
355
                }
356

357
                ACP::prepareDBSettingContext($config_vars);
1✔
358
        }
359

360
        public function redirectTabSettings(): void
361
        {
362
                Utils::$context['sub_template'] = 'redirect';
1✔
363
                Utils::$context['page_title'] .= ' - ' . Lang::getTxt('optimus_redirect_title');
1✔
364
                Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=optimus;sa=redirect;save';
1✔
365

366
                Utils::$context['optimus_redirect_rules'] = empty(Config::$modSettings['optimus_redirect'])
1✔
367
                        ? [] : unserialize(Config::$modSettings['optimus_redirect']);
1✔
368

369
                $config_vars = [];
1✔
370

371
                if (Input::isGet('save')) {
1✔
372
                        User::$me->checkSession();
1✔
373

374
                        $save_vars = $config_vars;
1✔
375
                        ACP::saveDBSettings($save_vars);
1✔
376

377
                        $redirect = [];
1✔
378
                        if (Input::isPost('custom_redirect_from') && Input::isPost('custom_redirect_to')) {
1✔
379
                                $custom_redirect = filter_input_array(INPUT_POST);
×
UNCOV
380
                                $custom_redirect['custom_redirect_from'] = array_filter($custom_redirect['custom_redirect_from']);
×
381

UNCOV
382
                                foreach ($custom_redirect['custom_redirect_from'] as $to => $from) {
×
UNCOV
383
                                        $redirect[$from] = $custom_redirect['custom_redirect_to'][$to];
×
384
                                }
385
                        }
386

387
                        Config::updateModSettings(['optimus_redirect' => serialize($redirect)]);
1✔
388
                        Utils::redirectexit('action=admin;area=optimus;sa=redirect');
1✔
389
                }
390

391
                ACP::prepareDBSettingContext($config_vars);
1✔
392
        }
393

394
        public function counterTabSettings(): void
395
        {
396
                Utils::$context['sub_template'] = 'counters';
1✔
397
                Utils::$context['page_title'] .= ' - ' . Lang::getTxt('optimus_counters');
1✔
398
                Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=optimus;sa=counters;save';
1✔
399

400
                $this->addDefaultSettings([
1✔
401
                        'optimus_counters_css'    => '.counters {text-align: center}',
1✔
402
                        'optimus_ignored_actions' => 'admin,bookmarks,credits,helpadmin,pm,printpage',
1✔
403
                ]);
1✔
404

405
                $config_vars = [
1✔
406
                        ['large_text', 'optimus_head_code'],
1✔
407
                        ['large_text', 'optimus_stat_code'],
1✔
408
                        ['large_text', 'optimus_count_code'],
1✔
409
                        ['large_text', 'optimus_counters_css'],
1✔
410
                        ['text', 'optimus_ignored_actions'],
1✔
411
                ];
1✔
412

413
                if (Input::isGet('save')) {
1✔
414
                        User::$me->checkSession();
1✔
415

416
                        $save_vars = $config_vars;
1✔
417
                        ACP::saveDBSettings($save_vars);
1✔
418

419
                        Utils::redirectexit('action=admin;area=optimus;sa=counters');
1✔
420
                }
421

422
                ACP::prepareDBSettingContext($config_vars);
1✔
423
        }
424

425
        public function robotsTabSettings(): void
426
        {
427
                Utils::$context['sub_template'] = 'robots';
1✔
428
                Utils::$context['page_title'] .= ' - ' . Lang::getTxt('optimus_robots_title');
1✔
429
                Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=optimus;sa=robots;save';
1✔
430

431
                $config_vars = [];
1✔
432

433
                $path = (Input::server('document_root') ?: Config::$boarddir) . '/robots.txt';
1✔
434

435
                Utils::$context['robots_content'] = Utils::makeWritable($path) ? file_get_contents($path) : '';
1✔
436

437
                (new RobotsGenerator())->generate();
1✔
438

439
                if (Input::isGet('save')) {
1✔
440
                        User::$me->checkSession();
1✔
441

442
                        $save_vars = $config_vars;
1✔
443
                        ACP::saveDBSettings($save_vars);
1✔
444

445
                        file_put_contents($path, Input::filter('optimus_robots'), LOCK_EX);
1✔
446

447
                        Utils::redirectexit('action=admin;area=optimus;sa=robots');
1✔
448
                }
449

450
                ACP::prepareDBSettingContext($config_vars);
1✔
451
        }
452

453
        public function htaccessTabSettings(): void
454
        {
455
                Utils::$context['sub_template'] = 'htaccess';
1✔
456
                Utils::$context['page_title'] .= ' - ' . Lang::getTxt('optimus_htaccess_title');
1✔
457
                Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=optimus;sa=htaccess;save';
1✔
458

459
                $config_vars = [];
1✔
460

461
                $path = (Input::server('document_root') ?: Config::$boarddir) . '/.htaccess';
1✔
462

463
                Utils::$context['htaccess_content'] = Utils::makeWritable($path) ? file_get_contents($path) : '';
1✔
464

465
                if (Input::isGet('save')) {
1✔
466
                        User::$me->checkSession();
1✔
467

468
                        $save_vars = $config_vars;
1✔
469
                        ACP::saveDBSettings($save_vars);
1✔
470

471
                        if (is_file($path)) {
1✔
UNCOV
472
                                copy($path, $path . '.backup');
×
473
                        }
474

475
                        file_put_contents($path, trim(Input::post('optimus_htaccess')), LOCK_EX);
1✔
476

477
                        Utils::redirectexit('action=admin;area=optimus;sa=htaccess');
1✔
478
                }
479

480
                ACP::prepareDBSettingContext($config_vars);
1✔
481
        }
482

483
        /**
484
         * @return void|array
485
         */
486
        public function sitemapTabSettings(bool $return_config = false)
487
        {
488
                Utils::$context['page_title'] .= ' - ' . Lang::getTxt('optimus_sitemap_title');
1✔
489
                Utils::$context['settings_title'] = Lang::getTxt('optimus_sitemap_title');
1✔
490
                Utils::$context['post_url'] = Config::$scripturl . '?action=admin;area=optimus;sa=sitemap;save';
1✔
491

492
                if (! Utils::makeWritable(Config::$boarddir)) {
1✔
493
                        ErrorHandler::fatalLang('optimus_root_is_not_writable');
1✔
494
                }
495

496
                $this->addDefaultSettings([
1✔
497
                        'optimus_sitemap_topics_num_replies' => 5,
1✔
498
                        'optimus_sitemap_items_display'      => 10000,
1✔
499
                        'optimus_start_year'                 => 1994,
1✔
500
                        'optimus_update_frequency'           => 1,
1✔
501
                ]);
1✔
502

503
                $title = Lang::getTxt('admin_maintenance', file: 'ManageMaintenance') . ' - ' . Lang::getTxt('maintain_recount');
1✔
504
                $link = Str::html('a', $title)->class('bbc_link')
1✔
505
                        ->href(sprintf('%s?action=admin;area=maintain;sa=routine', Config::$scripturl));
1✔
506

507
                Utils::$context['settings_insert_above'] = Str::html('div')->class('roundframe')
1✔
508
                        ->setHtml(sprintf(Lang::getTxt('optimus_sitemap_info'), $link));
1✔
509

510
                $config_vars = [
1✔
511
                        ['check', 'optimus_sitemap_enable', 'subtext' => Lang::getTxt('optimus_sitemap_enable_subtext')],
1✔
512
                        ['check', 'optimus_sitemap_link'],
1✔
513
                        ['check', 'optimus_remove_previous_xml_files'],
1✔
514
                        '',
1✔
515
                        ['select', 'optimus_main_page_frequency', Lang::getTxt('optimus_main_page_frequency_set')],
1✔
516
                        ['check', 'optimus_sitemap_boards', 'subtext' => Lang::getTxt('optimus_sitemap_boards_subtext')],
1✔
517
                        [
1✔
518
                                'check',
1✔
519
                                'optimus_sitemap_all_topic_pages',
1✔
520
                                'subtext' => Lang::getTxt('optimus_sitemap_all_topic_pages_subtext')
1✔
521
                        ],
1✔
522
                        ['int', 'optimus_sitemap_topics_num_replies', 'min' => 0],
1✔
523
                        ['check', 'optimus_sitemap_add_found_images'],
1✔
524
                        '',
1✔
525
                        ['int', 'optimus_sitemap_items_display', 'min' => 1, 'max' => 50000],
1✔
526
                        ['int', 'optimus_start_year', 'min' => 1994, 'max' => date('Y')],
1✔
527
                        ['select', 'optimus_update_frequency', Lang::getTxt('optimus_update_frequency_set')],
1✔
528
                ];
1✔
529

530
                // You can add your own options
531
                IntegrationHook::call('integrate_optimus_sitemap_settings', [&$config_vars]);
1✔
532

533
                if ($return_config)
1✔
534
                        return $config_vars;
1✔
535

536
                if (Input::isGet('save')) {
1✔
537
                        User::$me->checkSession();
1✔
538

539
                        // Recreate a sitemap after save settings
540
                        Db::$db->query('', '
1✔
541
                                DELETE FROM {db_prefix}background_tasks
542
                                WHERE task_class = {string:task_class}',
1✔
543
                                [
1✔
544
                                        'task_class' => '\\' . Sitemap::class,
1✔
545
                                ]
1✔
546
                        );
1✔
547

548
                        if (Input::isPost('optimus_sitemap_enable')) {
1✔
549
                                Db::$db->insert('insert',
×
550
                                        '{db_prefix}background_tasks',
×
551
                                        ['task_file' => 'string-255', 'task_class' => 'string-255', 'task_data' => 'string'],
×
552
                                        ['$sourcedir/Optimus/Tasks/Sitemap.php', '\\' . Sitemap::class, ''],
×
UNCOV
553
                                        ['id_task'],
×
UNCOV
554
                                );
×
555
                        }
556

557
                        IntegrationHook::call('integrate_save_optimus_sitemap_settings');
1✔
558

559
                        $save_vars = $config_vars;
1✔
560
                        ACP::saveDBSettings($save_vars);
1✔
561

562
                        Utils::redirectexit('action=admin;area=optimus;sa=sitemap');
1✔
563
                }
564

565
                ACP::prepareDBSettingContext($config_vars);
1✔
566
        }
567

568
        private function addBlockWithTips(): void
569
        {
570
                if (empty(Input::isRequest('area')) || empty(Utils::$context['template_layers']))
1✔
UNCOV
571
                        return;
×
572

573
                if (str_contains(Input::request('area'), 'optimus')) {
1✔
574
                        Theme::loadTemplate('Optimus');
1✔
575

576
                        Utils::$context['template_layers'][] = 'tips';
1✔
577
                }
578
        }
579

580
        private function callActionFromAreas(array $subActions): void
581
        {
582
                Utils::$context['sub_template'] = 'show_settings';
1✔
583

584
                $sa = Input::request('sa', 'basic');
1✔
585
                Input::request(['sa' => isset($subActions[$sa]) ? $sa : key($subActions)]);
1✔
586

587
                $this->{$subActions[Input::request('sa')]}();
1✔
588
        }
589

590
        private function addDefaultSettings($settings): void
591
        {
592
                if (empty($settings))
4✔
UNCOV
593
                        return;
×
594

595
                $vars = array_filter($settings, fn($key) => ! isset(Config::$modSettings[$key]), ARRAY_FILTER_USE_KEY);
4✔
596

597
                Config::updateModSettings($vars);
4✔
598
        }
599
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc