PluginProbe
404 Solution / 4.2.0
404 Solution v4.2.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / View_Suggestions.php

View_Suggestions.php in 404 Solution 4.2.0, at includes/View_Suggestions.php

99 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 if (!defined('ABSPATH')) {
5 exit;
6 }
7
8 class ABJ_404_Solution_View_Suggestions {
9
10 /** @var self|null */
11 private static $instance = null;
12
13 /** @var ABJ_404_Solution_Functions */
14 private $f;
15
16 /**
17 * Constructor with dependency injection.
18 *
19 * @param ABJ_404_Solution_Functions|null $functions String utilities
20 */
21 public function __construct($functions = null) {
22 $this->f = $functions !== null ? $functions : abj_service('functions');
23 }
24
25 /** @return self */
26 public static function getInstance() {
27 if (self::$instance == null) {
28 self::$instance = new ABJ_404_Solution_View_Suggestions();
29 }
30
31 return self::$instance;
32 }
33
34 /**
35 * @param array<string, mixed> $options
36 * @return string
37 */
38 function getAdminOptionsPage404Suggestions($options) {
39 $options = array_merge(array(
40 'suggest_cats' => '0',
41 'suggest_tags' => '0',
42 'update_suggest_url' => '0',
43 'suggest_max' => '5',
44 'suggest_title' => '',
45 'suggest_before' => '',
46 'suggest_after' => '',
47 'suggest_entrybefore' => '',
48 'suggest_entryafter' => '',
49 'suggest_noresults' => '',
50 ), $options);
51
52 // Suggested Alternatives Options
53 $selectedSuggestCats = "";
54 if ($options['suggest_cats'] == '1') {
55 $selectedSuggestCats = " checked";
56 }
57 $selectedSuggestTags = "";
58 if ($options['suggest_tags'] == '1') {
59 $selectedSuggestTags = " checked";
60 }
61 $selectedSuggestURL = "";
62 if ($options['update_suggest_url'] == '1') {
63 $selectedSuggestURL = " checked";
64 }
65 $selectedSuggestMinscoreEnabled = "";
66 if (isset($options['suggest_minscore_enabled']) && $options['suggest_minscore_enabled'] == '1') {
67 $selectedSuggestMinscoreEnabled = " checked";
68 }
69
70
71 // read the html content.
72 $html = ABJ_404_Solution_Functions::readFileContents(__DIR__ . "/html/viewSuggestions.html");
73 // do special replacements
74 $html = $this->f->str_replace('{SELECTED_SUGGEST_CATS}', $selectedSuggestCats, $html);
75 $html = $this->f->str_replace('{SELECTED_SUGGEST_TAGS}', $selectedSuggestTags, $html);
76 $html = $this->f->str_replace('{SELECTED_SUGGEST_MINSCORE_ENABLED}', $selectedSuggestMinscoreEnabled, $html);
77 $html = $this->f->str_replace('{SELECTED_SUGGEST_URL}', $selectedSuggestURL, $html);
78 $sugMax = $options['suggest_max'];
79 $sugTitle = $options['suggest_title'];
80 $sugBefore = $options['suggest_before'];
81 $sugAfter = $options['suggest_after'];
82 $sugEntryBefore = $options['suggest_entrybefore'];
83 $sugEntryAfter = $options['suggest_entryafter'];
84 $sugNoResults = $options['suggest_noresults'];
85 $html = $this->f->str_replace('{SUGGEST_MAX_SUGGESTIONS}', esc_attr(is_scalar($sugMax) ? (string)$sugMax : ''), $html);
86 $html = $this->f->str_replace('{SUGGEST_USER_TITLE}', esc_attr(is_scalar($sugTitle) ? (string)$sugTitle : ''), $html);
87 $html = $this->f->str_replace('{SUGGEST_USER_BEFORE}', esc_attr(is_scalar($sugBefore) ? (string)$sugBefore : ''), $html);
88 $html = $this->f->str_replace('{SUGGEST_USER_AFTER}', esc_attr(is_scalar($sugAfter) ? (string)$sugAfter : ''), $html);
89 $html = $this->f->str_replace('{SUGGEST_USER_ENTRY_BEFORE}', esc_attr(is_scalar($sugEntryBefore) ? (string)$sugEntryBefore : ''), $html);
90 $html = $this->f->str_replace('{SUGGEST_USER_ENTRY_AFTER}', esc_attr(is_scalar($sugEntryAfter) ? (string)$sugEntryAfter : ''), $html);
91 $html = $this->f->str_replace('{SUGGEST_USER_NO_RESULTS}', esc_attr(is_scalar($sugNoResults) ? (string)$sugNoResults : ''), $html);
92 // constants and translations.
93 $html = $this->f->doNormalReplacements($html);
94
95 return $html;
96 }
97
98 }
99