Passed
Push — master ( 6b35fa...ccb079 )
by Paul
10:24 queued 05:13
created
plugin/Controllers/MainController.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -10,86 +10,86 @@
 block discarded – undo
10 10
 
11 11
 class MainController extends Controller
12 12
 {
13
-    /**
14
-     * @return void
15
-     * @action init
16
-     */
17
-    public function registerPostType()
18
-    {
19
-        if (!glsr()->hasPermission()) {
20
-            return;
21
-        }
22
-        $command = new RegisterPostType([
23
-            'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE],
24
-            'capability_type' => Application::POST_TYPE,
25
-            'columns' => [
26
-                'title' => '',
27
-                'category' => '',
28
-                'assigned_to' => __('Assigned To', 'site-reviews'),
29
-                'reviewer' => __('Author', 'site-reviews'),
30
-                'email' => __('Email', 'site-reviews'),
31
-                'ip_address' => __('IP Address', 'site-reviews'),
32
-                'response' => __('Response', 'site-reviews'),
33
-                'review_type' => __('Type', 'site-reviews'),
34
-                'rating' => __('Rating', 'site-reviews'),
35
-                'pinned' => __('Pinned', 'site-reviews'),
36
-                'date' => '',
37
-            ],
38
-            'menu_icon' => 'dashicons-star-half',
39
-            'menu_name' => glsr()->name,
40
-            'map_meta_cap' => true,
41
-            'plural' => __('Reviews', 'site-reviews'),
42
-            'post_type' => Application::POST_TYPE,
43
-            'rest_controller_class' => RestReviewController::class,
44
-            'show_in_rest' => true,
45
-            'single' => __('Review', 'site-reviews'),
46
-        ]);
47
-        $this->execute($command);
48
-    }
13
+	/**
14
+	 * @return void
15
+	 * @action init
16
+	 */
17
+	public function registerPostType()
18
+	{
19
+		if (!glsr()->hasPermission()) {
20
+			return;
21
+		}
22
+		$command = new RegisterPostType([
23
+			'capabilities' => ['create_posts' => 'create_'.Application::POST_TYPE],
24
+			'capability_type' => Application::POST_TYPE,
25
+			'columns' => [
26
+				'title' => '',
27
+				'category' => '',
28
+				'assigned_to' => __('Assigned To', 'site-reviews'),
29
+				'reviewer' => __('Author', 'site-reviews'),
30
+				'email' => __('Email', 'site-reviews'),
31
+				'ip_address' => __('IP Address', 'site-reviews'),
32
+				'response' => __('Response', 'site-reviews'),
33
+				'review_type' => __('Type', 'site-reviews'),
34
+				'rating' => __('Rating', 'site-reviews'),
35
+				'pinned' => __('Pinned', 'site-reviews'),
36
+				'date' => '',
37
+			],
38
+			'menu_icon' => 'dashicons-star-half',
39
+			'menu_name' => glsr()->name,
40
+			'map_meta_cap' => true,
41
+			'plural' => __('Reviews', 'site-reviews'),
42
+			'post_type' => Application::POST_TYPE,
43
+			'rest_controller_class' => RestReviewController::class,
44
+			'show_in_rest' => true,
45
+			'single' => __('Review', 'site-reviews'),
46
+		]);
47
+		$this->execute($command);
48
+	}
49 49
 
50
-    /**
51
-     * @return void
52
-     * @action init
53
-     */
54
-    public function registerShortcodes()
55
-    {
56
-        $command = new RegisterShortcodes([
57
-            'site_reviews',
58
-            'site_reviews_form',
59
-            'site_reviews_summary',
60
-        ]);
61
-        $this->execute($command);
62
-    }
50
+	/**
51
+	 * @return void
52
+	 * @action init
53
+	 */
54
+	public function registerShortcodes()
55
+	{
56
+		$command = new RegisterShortcodes([
57
+			'site_reviews',
58
+			'site_reviews_form',
59
+			'site_reviews_summary',
60
+		]);
61
+		$this->execute($command);
62
+	}
63 63
 
64
-    /**
65
-     * @return void
66
-     * @action init
67
-     */
68
-    public function registerTaxonomy()
69
-    {
70
-        $command = new RegisterTaxonomy([
71
-            'hierarchical' => true,
72
-            'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'],
73
-            'public' => false,
74
-            'rest_controller_class' => RestCategoryController::class,
75
-            'show_admin_column' => true,
76
-            'show_in_rest' => true,
77
-            'show_ui' => true,
78
-        ]);
79
-        $this->execute($command);
80
-    }
64
+	/**
65
+	 * @return void
66
+	 * @action init
67
+	 */
68
+	public function registerTaxonomy()
69
+	{
70
+		$command = new RegisterTaxonomy([
71
+			'hierarchical' => true,
72
+			'meta_box_cb' => [glsr(EditorController::class), 'renderTaxonomyMetabox'],
73
+			'public' => false,
74
+			'rest_controller_class' => RestCategoryController::class,
75
+			'show_admin_column' => true,
76
+			'show_in_rest' => true,
77
+			'show_ui' => true,
78
+		]);
79
+		$this->execute($command);
80
+	}
81 81
 
82
-    /**
83
-     * @return void
84
-     * @action widgets_init
85
-     */
86
-    public function registerWidgets()
87
-    {
88
-        $command = new RegisterWidgets([
89
-            'site-reviews',
90
-            'site-reviews-form',
91
-            'site-reviews-summary',
92
-        ]);
93
-        $this->execute($command);
94
-    }
82
+	/**
83
+	 * @return void
84
+	 * @action widgets_init
85
+	 */
86
+	public function registerWidgets()
87
+	{
88
+		$command = new RegisterWidgets([
89
+			'site-reviews',
90
+			'site-reviews-form',
91
+			'site-reviews-summary',
92
+		]);
93
+		$this->execute($command);
94
+	}
95 95
 }
Please login to merge, or discard this patch.
views/pages/addons/index.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,16 +6,16 @@
 block discarded – undo
6 6
     <p><?= __('Add-ons extend the functionality of Site Reviews.', 'site-reviews'); ?></p>
7 7
     <div class="glsr-addons wp-clearfix">
8 8
     <?php
9
-        $template->render('partials/addons/addon', [
10
-            'beta' => true,
11
-            'context' => [
12
-                'description' => __('This add-on allows your site visitors to submit images with their reviews. Apply now to test the unreleased beta version.', 'site-reviews'),
13
-                'link' => 'https://niftyplugins.com/plugins/images/',
14
-                'slug' => 'images',
15
-                'title' => 'Images',
16
-            ],
17
-            'plugin' => 'site-reviews-images/site-reviews-images.php',
18
-        ]);
19
-    ?>
9
+		$template->render('partials/addons/addon', [
10
+			'beta' => true,
11
+			'context' => [
12
+				'description' => __('This add-on allows your site visitors to submit images with their reviews. Apply now to test the unreleased beta version.', 'site-reviews'),
13
+				'link' => 'https://niftyplugins.com/plugins/images/',
14
+				'slug' => 'images',
15
+				'title' => 'Images',
16
+			],
17
+			'plugin' => 'site-reviews-images/site-reviews-images.php',
18
+		]);
19
+	?>
20 20
     </div>
21 21
 </div>
Please login to merge, or discard this patch.
plugin/Modules/System.php 1 patch
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -13,378 +13,378 @@
 block discarded – undo
13 13
 
14 14
 class System
15 15
 {
16
-    const PAD = 40;
16
+	const PAD = 40;
17 17
 
18
-    /**
19
-     * @return string
20
-     */
21
-    public function __toString()
22
-    {
23
-        return $this->get();
24
-    }
18
+	/**
19
+	 * @return string
20
+	 */
21
+	public function __toString()
22
+	{
23
+		return $this->get();
24
+	}
25 25
 
26
-    /**
27
-     * @return string
28
-     */
29
-    public function get()
30
-    {
31
-        $details = [
32
-            'plugin' => 'Plugin Details',
33
-            'addon' => 'Addon Details',
34
-            'browser' => 'Browser Details',
35
-            'server' => 'Server Details',
36
-            'php' => 'PHP Configuration',
37
-            'wordpress' => 'WordPress Configuration',
38
-            'mu-plugin' => 'Must-Use Plugins',
39
-            'multisite-plugin' => 'Network Active Plugins',
40
-            'active-plugin' => 'Active Plugins',
41
-            'inactive-plugin' => 'Inactive Plugins',
42
-            'setting' => 'Plugin Settings',
43
-            'reviews' => 'Review Counts',
44
-        ];
45
-        $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
-            $methodName = Helper::buildMethodName('get-'.$key.'-details');
47
-            if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
48
-                return $carry.$this->implode(
49
-                    strtoupper($details[$key]),
50
-                    apply_filters('site-reviews/system/'.$key, $systemDetails)
51
-                );
52
-            }
53
-            return $carry;
54
-        });
55
-        return trim($systemInfo);
56
-    }
26
+	/**
27
+	 * @return string
28
+	 */
29
+	public function get()
30
+	{
31
+		$details = [
32
+			'plugin' => 'Plugin Details',
33
+			'addon' => 'Addon Details',
34
+			'browser' => 'Browser Details',
35
+			'server' => 'Server Details',
36
+			'php' => 'PHP Configuration',
37
+			'wordpress' => 'WordPress Configuration',
38
+			'mu-plugin' => 'Must-Use Plugins',
39
+			'multisite-plugin' => 'Network Active Plugins',
40
+			'active-plugin' => 'Active Plugins',
41
+			'inactive-plugin' => 'Inactive Plugins',
42
+			'setting' => 'Plugin Settings',
43
+			'reviews' => 'Review Counts',
44
+		];
45
+		$systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
+			$methodName = Helper::buildMethodName('get-'.$key.'-details');
47
+			if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
48
+				return $carry.$this->implode(
49
+					strtoupper($details[$key]),
50
+					apply_filters('site-reviews/system/'.$key, $systemDetails)
51
+				);
52
+			}
53
+			return $carry;
54
+		});
55
+		return trim($systemInfo);
56
+	}
57 57
 
58
-    /**
59
-     * @return array
60
-     */
61
-    public function getActivePluginDetails()
62
-    {
63
-        $plugins = get_plugins();
64
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
-        $inactive = array_diff_key($plugins, array_flip($activePlugins));
66
-        return $this->normalizePluginList(array_diff_key($plugins, $inactive));
67
-    }
58
+	/**
59
+	 * @return array
60
+	 */
61
+	public function getActivePluginDetails()
62
+	{
63
+		$plugins = get_plugins();
64
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
+		$inactive = array_diff_key($plugins, array_flip($activePlugins));
66
+		return $this->normalizePluginList(array_diff_key($plugins, $inactive));
67
+	}
68 68
 
69
-    /**
70
-     * @return array
71
-     */
72
-    public function getAddonDetails()
73
-    {
74
-        $details = apply_filters('site-reviews/addon/system-info', []);
75
-        ksort($details);
76
-        return $details;
77
-    }
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function getAddonDetails()
73
+	{
74
+		$details = apply_filters('site-reviews/addon/system-info', []);
75
+		ksort($details);
76
+		return $details;
77
+	}
78 78
 
79
-    /**
80
-     * @return array
81
-     */
82
-    public function getBrowserDetails()
83
-    {
84
-        $browser = new Browser();
85
-        $name = esc_attr($browser->getName());
86
-        $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
-        $version = esc_attr($browser->getVersion());
88
-        return [
89
-            'Browser Name' => sprintf('%s %s', $name, $version),
90
-            'Browser UA' => $userAgent,
91
-        ];
92
-    }
79
+	/**
80
+	 * @return array
81
+	 */
82
+	public function getBrowserDetails()
83
+	{
84
+		$browser = new Browser();
85
+		$name = esc_attr($browser->getName());
86
+		$userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
+		$version = esc_attr($browser->getVersion());
88
+		return [
89
+			'Browser Name' => sprintf('%s %s', $name, $version),
90
+			'Browser UA' => $userAgent,
91
+		];
92
+	}
93 93
 
94
-    /**
95
-     * @return array
96
-     */
97
-    public function getInactivePluginDetails()
98
-    {
99
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
-        $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
101
-        $multisitePlugins = $this->getMultisitePluginDetails();
102
-        return empty($multisitePlugins)
103
-            ? $inactivePlugins
104
-            : array_diff($inactivePlugins, $multisitePlugins);
105
-    }
94
+	/**
95
+	 * @return array
96
+	 */
97
+	public function getInactivePluginDetails()
98
+	{
99
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
+		$inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
101
+		$multisitePlugins = $this->getMultisitePluginDetails();
102
+		return empty($multisitePlugins)
103
+			? $inactivePlugins
104
+			: array_diff($inactivePlugins, $multisitePlugins);
105
+	}
106 106
 
107
-    /**
108
-     * @return array
109
-     */
110
-    public function getMuPluginDetails()
111
-    {
112
-        if (empty($plugins = get_mu_plugins())) {
113
-            return [];
114
-        }
115
-        return $this->normalizePluginList($plugins);
116
-    }
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function getMuPluginDetails()
111
+	{
112
+		if (empty($plugins = get_mu_plugins())) {
113
+			return [];
114
+		}
115
+		return $this->normalizePluginList($plugins);
116
+	}
117 117
 
118
-    /**
119
-     * @return array
120
-     */
121
-    public function getMultisitePluginDetails()
122
-    {
123
-        $activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
-        if (!is_multisite() || empty($activePlugins)) {
125
-            return [];
126
-        }
127
-        return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
128
-    }
118
+	/**
119
+	 * @return array
120
+	 */
121
+	public function getMultisitePluginDetails()
122
+	{
123
+		$activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
+		if (!is_multisite() || empty($activePlugins)) {
125
+			return [];
126
+		}
127
+		return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
128
+	}
129 129
 
130
-    /**
131
-     * @return array
132
-     */
133
-    public function getPhpDetails()
134
-    {
135
-        $displayErrors = $this->getINI('display_errors', null)
136
-            ? 'On ('.$this->getINI('display_errors').')'
137
-            : 'N/A';
138
-        $intlSupport = extension_loaded('intl')
139
-            ? phpversion('intl')
140
-            : 'false';
141
-        return [
142
-            'cURL' => var_export(function_exists('curl_init'), true),
143
-            'Default Charset' => $this->getINI('default_charset'),
144
-            'Display Errors' => $displayErrors,
145
-            'fsockopen' => var_export(function_exists('fsockopen'), true),
146
-            'Intl' => $intlSupport,
147
-            'IPv6' => var_export(defined('AF_INET6'), true),
148
-            'Max Execution Time' => $this->getINI('max_execution_time'),
149
-            'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
-            'Max Input Vars' => $this->getINI('max_input_vars'),
151
-            'Memory Limit' => $this->getINI('memory_limit'),
152
-            'Post Max Size' => $this->getINI('post_max_size'),
153
-            'Sendmail Path' => $this->getINI('sendmail_path'),
154
-            'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
-            'Session Name' => esc_html($this->getINI('session.name')),
156
-            'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
-            'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
-            'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
-            'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
160
-        ];
161
-    }
130
+	/**
131
+	 * @return array
132
+	 */
133
+	public function getPhpDetails()
134
+	{
135
+		$displayErrors = $this->getINI('display_errors', null)
136
+			? 'On ('.$this->getINI('display_errors').')'
137
+			: 'N/A';
138
+		$intlSupport = extension_loaded('intl')
139
+			? phpversion('intl')
140
+			: 'false';
141
+		return [
142
+			'cURL' => var_export(function_exists('curl_init'), true),
143
+			'Default Charset' => $this->getINI('default_charset'),
144
+			'Display Errors' => $displayErrors,
145
+			'fsockopen' => var_export(function_exists('fsockopen'), true),
146
+			'Intl' => $intlSupport,
147
+			'IPv6' => var_export(defined('AF_INET6'), true),
148
+			'Max Execution Time' => $this->getINI('max_execution_time'),
149
+			'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
+			'Max Input Vars' => $this->getINI('max_input_vars'),
151
+			'Memory Limit' => $this->getINI('memory_limit'),
152
+			'Post Max Size' => $this->getINI('post_max_size'),
153
+			'Sendmail Path' => $this->getINI('sendmail_path'),
154
+			'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
+			'Session Name' => esc_html($this->getINI('session.name')),
156
+			'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
+			'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
+			'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
+			'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
160
+		];
161
+	}
162 162
 
163
-    /**
164
-     * @return array
165
-     */
166
-    public function getReviewsDetails()
167
-    {
168
-        $counts = glsr(CountsManager::class)->getCounts();
169
-        $counts = Arr::flattenArray($counts);
170
-        array_walk($counts, function (&$ratings) use ($counts) {
171
-            if (is_array($ratings)) {
172
-                $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
173
-                return;
174
-            }
175
-            glsr_log()
176
-                ->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
-                ->debug($ratings)
178
-                ->debug($counts);
179
-        });
180
-        ksort($counts);
181
-        return $counts;
182
-    }
163
+	/**
164
+	 * @return array
165
+	 */
166
+	public function getReviewsDetails()
167
+	{
168
+		$counts = glsr(CountsManager::class)->getCounts();
169
+		$counts = Arr::flattenArray($counts);
170
+		array_walk($counts, function (&$ratings) use ($counts) {
171
+			if (is_array($ratings)) {
172
+				$ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
173
+				return;
174
+			}
175
+			glsr_log()
176
+				->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
+				->debug($ratings)
178
+				->debug($counts);
179
+		});
180
+		ksort($counts);
181
+		return $counts;
182
+	}
183 183
 
184
-    /**
185
-     * @return array
186
-     */
187
-    public function getServerDetails()
188
-    {
189
-        global $wpdb;
190
-        return [
191
-            'Host Name' => $this->getHostName(),
192
-            'MySQL Version' => $wpdb->db_version(),
193
-            'PHP Version' => PHP_VERSION,
194
-            'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
195
-        ];
196
-    }
184
+	/**
185
+	 * @return array
186
+	 */
187
+	public function getServerDetails()
188
+	{
189
+		global $wpdb;
190
+		return [
191
+			'Host Name' => $this->getHostName(),
192
+			'MySQL Version' => $wpdb->db_version(),
193
+			'PHP Version' => PHP_VERSION,
194
+			'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
195
+		];
196
+	}
197 197
 
198
-    /**
199
-     * @return array
200
-     */
201
-    public function getSettingDetails()
202
-    {
203
-        $settings = glsr(OptionManager::class)->get('settings', []);
204
-        $settings = Arr::flattenArray($settings, true);
205
-        $settings = $this->purgeSensitiveData($settings);
206
-        ksort($settings);
207
-        $details = [];
208
-        foreach ($settings as $key => $value) {
209
-            if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
210
-                continue;
211
-            }
212
-            $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
213
-            $details[$key] = $value;
214
-        }
215
-        return $details;
216
-    }
198
+	/**
199
+	 * @return array
200
+	 */
201
+	public function getSettingDetails()
202
+	{
203
+		$settings = glsr(OptionManager::class)->get('settings', []);
204
+		$settings = Arr::flattenArray($settings, true);
205
+		$settings = $this->purgeSensitiveData($settings);
206
+		ksort($settings);
207
+		$details = [];
208
+		foreach ($settings as $key => $value) {
209
+			if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
210
+				continue;
211
+			}
212
+			$value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8');
213
+			$details[$key] = $value;
214
+		}
215
+		return $details;
216
+	}
217 217
 
218
-    /**
219
-     * @return array
220
-     */
221
-    public function getPluginDetails()
222
-    {
223
-        return [
224
-            'Console level' => glsr(Console::class)->humanLevel(),
225
-            'Console size' => glsr(Console::class)->humanSize('0'),
226
-            'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
-            'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
228
-            'Version (current)' => glsr()->version,
229
-            'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
230
-        ];
231
-    }
218
+	/**
219
+	 * @return array
220
+	 */
221
+	public function getPluginDetails()
222
+	{
223
+		return [
224
+			'Console level' => glsr(Console::class)->humanLevel(),
225
+			'Console size' => glsr(Console::class)->humanSize('0'),
226
+			'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
+			'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
228
+			'Version (current)' => glsr()->version,
229
+			'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
230
+		];
231
+	}
232 232
 
233
-    /**
234
-     * @return array
235
-     */
236
-    public function getWordpressDetails()
237
-    {
238
-        global $wpdb;
239
-        $theme = wp_get_theme();
240
-        return [
241
-            'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
-            'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
243
-            'Home URL' => home_url(),
244
-            'Language' => get_locale(),
245
-            'Memory Limit' => WP_MEMORY_LIMIT,
246
-            'Multisite' => var_export(is_multisite(), true),
247
-            'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
-            'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
-            'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
-            'Post Stati' => implode(', ', get_post_stati()),
251
-            'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
-            'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
253
-            'Site URL' => site_url(),
254
-            'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
-            'Version' => get_bloginfo('version'),
256
-            'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
-            'WP Max Upload Size' => size_format(wp_max_upload_size()),
258
-            'WP Memory Limit' => WP_MEMORY_LIMIT,
259
-        ];
260
-    }
233
+	/**
234
+	 * @return array
235
+	 */
236
+	public function getWordpressDetails()
237
+	{
238
+		global $wpdb;
239
+		$theme = wp_get_theme();
240
+		return [
241
+			'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
+			'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
243
+			'Home URL' => home_url(),
244
+			'Language' => get_locale(),
245
+			'Memory Limit' => WP_MEMORY_LIMIT,
246
+			'Multisite' => var_export(is_multisite(), true),
247
+			'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
+			'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
+			'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
+			'Post Stati' => implode(', ', get_post_stati()),
251
+			'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
+			'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
253
+			'Site URL' => site_url(),
254
+			'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
+			'Version' => get_bloginfo('version'),
256
+			'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
+			'WP Max Upload Size' => size_format(wp_max_upload_size()),
258
+			'WP Memory Limit' => WP_MEMORY_LIMIT,
259
+		];
260
+	}
261 261
 
262
-    /**
263
-     * @return string
264
-     */
265
-    protected function detectWebhostProvider()
266
-    {
267
-        $checks = [
268
-            '.accountservergroup.com' => 'Site5',
269
-            '.gridserver.com' => 'MediaTemple Grid',
270
-            '.inmotionhosting.com' => 'InMotion Hosting',
271
-            '.ovh.net' => 'OVH',
272
-            '.pair.com' => 'pair Networks',
273
-            '.stabletransit.com' => 'Rackspace Cloud',
274
-            '.stratoserver.net' => 'STRATO',
275
-            '.sysfix.eu' => 'SysFix.eu Power Hosting',
276
-            'bluehost.com' => 'Bluehost',
277
-            'DH_USER' => 'DreamHost',
278
-            'Flywheel' => 'Flywheel',
279
-            'ipagemysql.com' => 'iPage',
280
-            'ipowermysql.com' => 'IPower',
281
-            'localhost:/tmp/mysql5.sock' => 'ICDSoft',
282
-            'mysqlv5' => 'NetworkSolutions',
283
-            'PAGELYBIN' => 'Pagely',
284
-            'secureserver.net' => 'GoDaddy',
285
-            'WPE_APIKEY' => 'WP Engine',
286
-        ];
287
-        foreach ($checks as $key => $value) {
288
-            if (!$this->isWebhostCheckValid($key)) {
289
-                continue;
290
-            }
291
-            return $value;
292
-        }
293
-        return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
294
-    }
262
+	/**
263
+	 * @return string
264
+	 */
265
+	protected function detectWebhostProvider()
266
+	{
267
+		$checks = [
268
+			'.accountservergroup.com' => 'Site5',
269
+			'.gridserver.com' => 'MediaTemple Grid',
270
+			'.inmotionhosting.com' => 'InMotion Hosting',
271
+			'.ovh.net' => 'OVH',
272
+			'.pair.com' => 'pair Networks',
273
+			'.stabletransit.com' => 'Rackspace Cloud',
274
+			'.stratoserver.net' => 'STRATO',
275
+			'.sysfix.eu' => 'SysFix.eu Power Hosting',
276
+			'bluehost.com' => 'Bluehost',
277
+			'DH_USER' => 'DreamHost',
278
+			'Flywheel' => 'Flywheel',
279
+			'ipagemysql.com' => 'iPage',
280
+			'ipowermysql.com' => 'IPower',
281
+			'localhost:/tmp/mysql5.sock' => 'ICDSoft',
282
+			'mysqlv5' => 'NetworkSolutions',
283
+			'PAGELYBIN' => 'Pagely',
284
+			'secureserver.net' => 'GoDaddy',
285
+			'WPE_APIKEY' => 'WP Engine',
286
+		];
287
+		foreach ($checks as $key => $value) {
288
+			if (!$this->isWebhostCheckValid($key)) {
289
+				continue;
290
+			}
291
+			return $value;
292
+		}
293
+		return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
294
+	}
295 295
 
296
-    /**
297
-     * @return string
298
-     */
299
-    protected function getHostName()
300
-    {
301
-        return sprintf('%s (%s)',
302
-            $this->detectWebhostProvider(),
303
-            Helper::getIpAddress()
304
-        );
305
-    }
296
+	/**
297
+	 * @return string
298
+	 */
299
+	protected function getHostName()
300
+	{
301
+		return sprintf('%s (%s)',
302
+			$this->detectWebhostProvider(),
303
+			Helper::getIpAddress()
304
+		);
305
+	}
306 306
 
307
-    protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
308
-    {
309
-        return function_exists('ini_get')
310
-            ? ini_get($name)
311
-            : $disabledValue;
312
-    }
307
+	protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
308
+	{
309
+		return function_exists('ini_get')
310
+			? ini_get($name)
311
+			: $disabledValue;
312
+	}
313 313
 
314
-    /**
315
-     * @return array
316
-     */
317
-    protected function getWordpressPlugins()
318
-    {
319
-        $plugins = get_plugins();
320
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
-        $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
-        $active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
323
-        return $active + $inactive;
324
-    }
314
+	/**
315
+	 * @return array
316
+	 */
317
+	protected function getWordpressPlugins()
318
+	{
319
+		$plugins = get_plugins();
320
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
+		$inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
+		$active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
323
+		return $active + $inactive;
324
+	}
325 325
 
326
-    /**
327
-     * @param string $title
328
-     * @return string
329
-     */
330
-    protected function implode($title, array $details)
331
-    {
332
-        $strings = ['['.$title.']'];
333
-        $padding = max(array_map('strlen', array_keys($details)));
334
-        $padding = max([$padding, static::PAD]);
335
-        foreach ($details as $key => $value) {
336
-            $strings[] = is_string($key)
337
-                ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
338
-                : ' - '.$value;
339
-        }
340
-        return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
341
-    }
326
+	/**
327
+	 * @param string $title
328
+	 * @return string
329
+	 */
330
+	protected function implode($title, array $details)
331
+	{
332
+		$strings = ['['.$title.']'];
333
+		$padding = max(array_map('strlen', array_keys($details)));
334
+		$padding = max([$padding, static::PAD]);
335
+		foreach ($details as $key => $value) {
336
+			$strings[] = is_string($key)
337
+				? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
338
+				: ' - '.$value;
339
+		}
340
+		return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
341
+	}
342 342
 
343
-    /**
344
-     * @param string $key
345
-     * @return bool
346
-     */
347
-    protected function isWebhostCheckValid($key)
348
-    {
349
-        return defined($key)
350
-            || filter_input(INPUT_SERVER, $key)
351
-            || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
-            || Str::contains(DB_HOST, $key)
353
-            || Str::contains(php_uname(), $key);
354
-    }
343
+	/**
344
+	 * @param string $key
345
+	 * @return bool
346
+	 */
347
+	protected function isWebhostCheckValid($key)
348
+	{
349
+		return defined($key)
350
+			|| filter_input(INPUT_SERVER, $key)
351
+			|| Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
+			|| Str::contains(DB_HOST, $key)
353
+			|| Str::contains(php_uname(), $key);
354
+	}
355 355
 
356
-    /**
357
-     * @return array
358
-     */
359
-    protected function normalizePluginList(array $plugins)
360
-    {
361
-        $plugins = array_map(function ($plugin) {
362
-            return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
-        }, $plugins);
364
-        natcasesort($plugins);
365
-        return array_flip($plugins);
366
-    }
356
+	/**
357
+	 * @return array
358
+	 */
359
+	protected function normalizePluginList(array $plugins)
360
+	{
361
+		$plugins = array_map(function ($plugin) {
362
+			return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
+		}, $plugins);
364
+		natcasesort($plugins);
365
+		return array_flip($plugins);
366
+	}
367 367
 
368
-    /**
369
-     * @return array
370
-     */
371
-    protected function purgeSensitiveData(array $settings)
372
-    {
373
-        $keys = [
374
-            'general.trustalyze_serial',
375
-            'licenses.',
376
-            'submissions.recaptcha.key',
377
-            'submissions.recaptcha.secret',
378
-        ];
379
-        array_walk($settings, function (&$value, $setting) use ($keys) {
380
-            foreach ($keys as $key) {
381
-                if (!Str::startsWith($key, $setting) || empty($value)) {
382
-                    continue;
383
-                }
384
-                $value = str_repeat('•', 13);
385
-                return;
386
-            }
387
-        });
388
-        return $settings;
389
-    }
368
+	/**
369
+	 * @return array
370
+	 */
371
+	protected function purgeSensitiveData(array $settings)
372
+	{
373
+		$keys = [
374
+			'general.trustalyze_serial',
375
+			'licenses.',
376
+			'submissions.recaptcha.key',
377
+			'submissions.recaptcha.secret',
378
+		];
379
+		array_walk($settings, function (&$value, $setting) use ($keys) {
380
+			foreach ($keys as $key) {
381
+				if (!Str::startsWith($key, $setting) || empty($value)) {
382
+					continue;
383
+				}
384
+				$value = str_repeat('•', 13);
385
+				return;
386
+			}
387
+		});
388
+		return $settings;
389
+	}
390 390
 }
Please login to merge, or discard this patch.
plugin/Shortcodes/Shortcode.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -12,238 +12,238 @@
 block discarded – undo
12 12
 
13 13
 abstract class Shortcode implements ShortcodeContract
14 14
 {
15
-    /**
16
-     * @var string
17
-     */
18
-    protected $partialName;
19
-
20
-    /**
21
-     * @var string
22
-     */
23
-    protected $shortcodeName;
24
-
25
-    public function __construct()
26
-    {
27
-        $this->partialName = $this->getShortcodePartialName();
28
-        $this->shortcodeName = $this->getShortcodeName();
29
-    }
30
-
31
-    /**
32
-     * @param string|array $atts
33
-     * @param string $type
34
-     * @return string
35
-     */
36
-    public function build($atts, array $args = [], $type = 'shortcode')
37
-    {
38
-        $args = $this->normalizeArgs($args, $type);
39
-        $atts = $this->normalizeAtts($atts, $type);
40
-        $partial = glsr(Partial::class)->build($this->partialName, $atts);
41
-        $title = !empty($atts['title'])
42
-            ? $args['before_title'].$atts['title'].$args['after_title']
43
-            : '';
44
-        $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']);
45
-        return $args['before_widget'].$title.$partial.$debug.$args['after_widget'];
46
-    }
47
-
48
-    /**
49
-     * @param string|array $atts
50
-     * @return string
51
-     */
52
-    public function buildShortcode($atts = [])
53
-    {
54
-        return $this->build($atts);
55
-    }
56
-
57
-    /**
58
-     * @return array
59
-     */
60
-    public function getDefaults($atts)
61
-    {
62
-        return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
63
-    }
64
-
65
-    /**
66
-     * @return array
67
-     */
68
-    public function getHideOptions()
69
-    {
70
-        $options = $this->hideOptions();
71
-        return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
72
-    }
73
-
74
-    /**
75
-     * @return string
76
-     */
77
-    public function getShortcodeClassName($replace = '', $search = 'Shortcode')
78
-    {
79
-        return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
80
-    }
81
-
82
-    /**
83
-     * @return string
84
-     */
85
-    public function getShortcodeDefaultsClassName()
86
-    {
87
-        return Helper::buildClassName(
88
-            $this->getShortcodeClassName('Defaults'),
89
-            'Defaults'
90
-        );
91
-    }
92
-
93
-    /**
94
-     * @return string
95
-     */
96
-    public function getShortcodeName()
97
-    {
98
-        return Str::snakeCase($this->getShortcodeClassName());
99
-    }
100
-
101
-    /**
102
-     * @return string
103
-     */
104
-    public function getShortcodePartialName()
105
-    {
106
-        return Str::dashCase($this->getShortcodeClassName());
107
-    }
108
-
109
-    /**
110
-     * @param array|string $args
111
-     * @param string $type
112
-     * @return array
113
-     */
114
-    public function normalizeArgs($args, $type = 'shortcode')
115
-    {
116
-        $args = wp_parse_args($args, [
117
-            'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">',
118
-            'after_widget' => '</div>',
119
-            'before_title' => '<h3 class="glsr-'.$type.'-title">',
120
-            'after_title' => '</h3>',
121
-        ]);
122
-        return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
123
-    }
124
-
125
-    /**
126
-     * @param array|string $atts
127
-     * @param string $type
128
-     * @return array
129
-     */
130
-    public function normalizeAtts($atts, $type = 'shortcode')
131
-    {
132
-        $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
133
-        $atts = $this->getDefaults($atts);
134
-        array_walk($atts, function (&$value, $key) {
135
-            $methodName = Helper::buildMethodName($key, 'normalize');
136
-            if (!method_exists($this, $methodName)) {
137
-                return;
138
-            }
139
-            $value = $this->$methodName($value);
140
-        });
141
-        $this->setId($atts);
142
-        return $atts;
143
-    }
144
-
145
-    /**
146
-     * @return array
147
-     */
148
-    abstract protected function hideOptions();
149
-
150
-    /**
151
-     * @param string $postId
152
-     * @return int|string
153
-     */
154
-    protected function normalizeAssignedTo($postId)
155
-    {
156
-        if ('parent_id' == $postId) {
157
-            $postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
158
-        } elseif ('post_id' == $postId) {
159
-            $postId = intval(get_the_ID());
160
-        }
161
-        return $postId;
162
-    }
163
-
164
-    /**
165
-     * @param string $postId
166
-     * @return int|string
167
-     */
168
-    protected function normalizeAssignTo($postId)
169
-    {
170
-        return $this->normalizeAssignedTo($postId);
171
-    }
172
-
173
-    /**
174
-     * @param string|array $hide
175
-     * @return array
176
-     */
177
-    protected function normalizeHide($hide)
178
-    {
179
-        if (is_string($hide)) {
180
-            $hide = explode(',', $hide);
181
-        }
182
-        $hideKeys = array_keys($this->getHideOptions());
183
-        return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
184
-            return in_array($value, $hideKeys);
185
-        });
186
-    }
187
-
188
-    /**
189
-     * @param string $id
190
-     * @return string
191
-     */
192
-    protected function normalizeId($id)
193
-    {
194
-        return sanitize_title($id);
195
-    }
196
-
197
-    /**
198
-     * @param string $labels
199
-     * @return array
200
-     */
201
-    protected function normalizeLabels($labels)
202
-    {
203
-        $defaults = [
204
-            __('Excellent', 'site-reviews'),
205
-            __('Very good', 'site-reviews'),
206
-            __('Average', 'site-reviews'),
207
-            __('Poor', 'site-reviews'),
208
-            __('Terrible', 'site-reviews'),
209
-        ];
210
-        $maxRating = (int) glsr()->constant('MAX_RATING', Rating::class);
211
-        $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
212
-        $labels = array_map('trim', explode(',', $labels));
213
-        foreach ($defaults as $i => $label) {
214
-            if (empty($labels[$i])) {
215
-                continue;
216
-            }
217
-            $defaults[$i] = $labels[$i];
218
-        }
219
-        return array_combine(range($maxRating, 1), $defaults);
220
-    }
221
-
222
-    /**
223
-     * @param string $schema
224
-     * @return bool
225
-     */
226
-    protected function normalizeSchema($schema)
227
-    {
228
-        return wp_validate_boolean($schema);
229
-    }
230
-
231
-    /**
232
-     * @param string $text
233
-     * @return string
234
-     */
235
-    protected function normalizeText($text)
236
-    {
237
-        return trim($text);
238
-    }
239
-
240
-    /**
241
-     * @return void
242
-     */
243
-    protected function setId(array &$atts)
244
-    {
245
-        if (empty($atts['id'])) {
246
-            $atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
247
-        }
248
-    }
15
+	/**
16
+	 * @var string
17
+	 */
18
+	protected $partialName;
19
+
20
+	/**
21
+	 * @var string
22
+	 */
23
+	protected $shortcodeName;
24
+
25
+	public function __construct()
26
+	{
27
+		$this->partialName = $this->getShortcodePartialName();
28
+		$this->shortcodeName = $this->getShortcodeName();
29
+	}
30
+
31
+	/**
32
+	 * @param string|array $atts
33
+	 * @param string $type
34
+	 * @return string
35
+	 */
36
+	public function build($atts, array $args = [], $type = 'shortcode')
37
+	{
38
+		$args = $this->normalizeArgs($args, $type);
39
+		$atts = $this->normalizeAtts($atts, $type);
40
+		$partial = glsr(Partial::class)->build($this->partialName, $atts);
41
+		$title = !empty($atts['title'])
42
+			? $args['before_title'].$atts['title'].$args['after_title']
43
+			: '';
44
+		$debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']);
45
+		return $args['before_widget'].$title.$partial.$debug.$args['after_widget'];
46
+	}
47
+
48
+	/**
49
+	 * @param string|array $atts
50
+	 * @return string
51
+	 */
52
+	public function buildShortcode($atts = [])
53
+	{
54
+		return $this->build($atts);
55
+	}
56
+
57
+	/**
58
+	 * @return array
59
+	 */
60
+	public function getDefaults($atts)
61
+	{
62
+		return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts));
63
+	}
64
+
65
+	/**
66
+	 * @return array
67
+	 */
68
+	public function getHideOptions()
69
+	{
70
+		$options = $this->hideOptions();
71
+		return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName);
72
+	}
73
+
74
+	/**
75
+	 * @return string
76
+	 */
77
+	public function getShortcodeClassName($replace = '', $search = 'Shortcode')
78
+	{
79
+		return str_replace($search, $replace, (new ReflectionClass($this))->getShortName());
80
+	}
81
+
82
+	/**
83
+	 * @return string
84
+	 */
85
+	public function getShortcodeDefaultsClassName()
86
+	{
87
+		return Helper::buildClassName(
88
+			$this->getShortcodeClassName('Defaults'),
89
+			'Defaults'
90
+		);
91
+	}
92
+
93
+	/**
94
+	 * @return string
95
+	 */
96
+	public function getShortcodeName()
97
+	{
98
+		return Str::snakeCase($this->getShortcodeClassName());
99
+	}
100
+
101
+	/**
102
+	 * @return string
103
+	 */
104
+	public function getShortcodePartialName()
105
+	{
106
+		return Str::dashCase($this->getShortcodeClassName());
107
+	}
108
+
109
+	/**
110
+	 * @param array|string $args
111
+	 * @param string $type
112
+	 * @return array
113
+	 */
114
+	public function normalizeArgs($args, $type = 'shortcode')
115
+	{
116
+		$args = wp_parse_args($args, [
117
+			'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">',
118
+			'after_widget' => '</div>',
119
+			'before_title' => '<h3 class="glsr-'.$type.'-title">',
120
+			'after_title' => '</h3>',
121
+		]);
122
+		return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName);
123
+	}
124
+
125
+	/**
126
+	 * @param array|string $atts
127
+	 * @param string $type
128
+	 * @return array
129
+	 */
130
+	public function normalizeAtts($atts, $type = 'shortcode')
131
+	{
132
+		$atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName);
133
+		$atts = $this->getDefaults($atts);
134
+		array_walk($atts, function (&$value, $key) {
135
+			$methodName = Helper::buildMethodName($key, 'normalize');
136
+			if (!method_exists($this, $methodName)) {
137
+				return;
138
+			}
139
+			$value = $this->$methodName($value);
140
+		});
141
+		$this->setId($atts);
142
+		return $atts;
143
+	}
144
+
145
+	/**
146
+	 * @return array
147
+	 */
148
+	abstract protected function hideOptions();
149
+
150
+	/**
151
+	 * @param string $postId
152
+	 * @return int|string
153
+	 */
154
+	protected function normalizeAssignedTo($postId)
155
+	{
156
+		if ('parent_id' == $postId) {
157
+			$postId = intval(wp_get_post_parent_id(intval(get_the_ID())));
158
+		} elseif ('post_id' == $postId) {
159
+			$postId = intval(get_the_ID());
160
+		}
161
+		return $postId;
162
+	}
163
+
164
+	/**
165
+	 * @param string $postId
166
+	 * @return int|string
167
+	 */
168
+	protected function normalizeAssignTo($postId)
169
+	{
170
+		return $this->normalizeAssignedTo($postId);
171
+	}
172
+
173
+	/**
174
+	 * @param string|array $hide
175
+	 * @return array
176
+	 */
177
+	protected function normalizeHide($hide)
178
+	{
179
+		if (is_string($hide)) {
180
+			$hide = explode(',', $hide);
181
+		}
182
+		$hideKeys = array_keys($this->getHideOptions());
183
+		return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) {
184
+			return in_array($value, $hideKeys);
185
+		});
186
+	}
187
+
188
+	/**
189
+	 * @param string $id
190
+	 * @return string
191
+	 */
192
+	protected function normalizeId($id)
193
+	{
194
+		return sanitize_title($id);
195
+	}
196
+
197
+	/**
198
+	 * @param string $labels
199
+	 * @return array
200
+	 */
201
+	protected function normalizeLabels($labels)
202
+	{
203
+		$defaults = [
204
+			__('Excellent', 'site-reviews'),
205
+			__('Very good', 'site-reviews'),
206
+			__('Average', 'site-reviews'),
207
+			__('Poor', 'site-reviews'),
208
+			__('Terrible', 'site-reviews'),
209
+		];
210
+		$maxRating = (int) glsr()->constant('MAX_RATING', Rating::class);
211
+		$defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, '');
212
+		$labels = array_map('trim', explode(',', $labels));
213
+		foreach ($defaults as $i => $label) {
214
+			if (empty($labels[$i])) {
215
+				continue;
216
+			}
217
+			$defaults[$i] = $labels[$i];
218
+		}
219
+		return array_combine(range($maxRating, 1), $defaults);
220
+	}
221
+
222
+	/**
223
+	 * @param string $schema
224
+	 * @return bool
225
+	 */
226
+	protected function normalizeSchema($schema)
227
+	{
228
+		return wp_validate_boolean($schema);
229
+	}
230
+
231
+	/**
232
+	 * @param string $text
233
+	 * @return string
234
+	 */
235
+	protected function normalizeText($text)
236
+	{
237
+		return trim($text);
238
+	}
239
+
240
+	/**
241
+	 * @return void
242
+	 */
243
+	protected function setId(array &$atts)
244
+	{
245
+		if (empty($atts['id'])) {
246
+			$atts['id'] = Application::PREFIX.substr(md5(serialize($atts)), 0, 8);
247
+		}
248
+	}
249 249
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviewsSummary.php 1 patch
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -10,197 +10,197 @@
 block discarded – undo
10 10
 
11 11
 class SiteReviewsSummary
12 12
 {
13
-    /**
14
-     * @var array
15
-     */
16
-    protected $args;
17
-
18
-    /**
19
-     * @var float
20
-     */
21
-    protected $averageRating;
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    protected $ratingCounts;
27
-
28
-    /**
29
-     * @return void|string
30
-     */
31
-    public function build(array $args = [])
32
-    {
33
-        $this->args = $args;
34
-        $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
35
-        if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
36
-            return;
37
-        }
38
-        $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
39
-        $this->generateSchema();
40
-        return glsr(Template::class)->build('templates/reviews-summary', [
41
-            'context' => [
42
-                'assigned_to' => $this->args['assigned_to'],
43
-                'category' => $this->args['category'],
44
-                'class' => $this->getClass(),
45
-                'id' => $this->args['id'],
46
-                'percentages' => $this->buildPercentage(),
47
-                'rating' => $this->buildRating(),
48
-                'stars' => $this->buildStars(),
49
-                'text' => $this->buildText(),
50
-            ],
51
-        ]);
52
-    }
53
-
54
-    /**
55
-     * @return void|string
56
-     */
57
-    protected function buildPercentage()
58
-    {
59
-        if ($this->isHidden('bars')) {
60
-            return;
61
-        }
62
-        $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
63
-        $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
64
-            $label = $this->buildPercentageLabel($this->args['labels'][$level]);
65
-            $background = $this->buildPercentageBackground($percentages[$level]);
66
-            $count = apply_filters('site-reviews/summary/counts',
67
-                $percentages[$level],
68
-                $this->ratingCounts[$level]
69
-            );
70
-            $percent = $this->buildPercentageCount($count);
71
-            $value = $label.$background.$percent;
72
-            $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
73
-                'percent' => wp_strip_all_tags($count, true),
74
-                'rating' => $level,
75
-            ]);
76
-            return $carry.glsr(Builder::class)->div($value, [
77
-                'class' => 'glsr-bar',
78
-            ]);
79
-        });
80
-        return $this->wrap('percentage', $bars);
81
-    }
82
-
83
-    /**
84
-     * @param string $percent
85
-     * @return string
86
-     */
87
-    protected function buildPercentageBackground($percent)
88
-    {
89
-        $backgroundPercent = glsr(Builder::class)->span([
90
-            'class' => 'glsr-bar-background-percent',
91
-            'style' => 'width:'.$percent,
92
-        ]);
93
-        return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
94
-    }
95
-
96
-    /**
97
-     * @param string $count
98
-     * @return string
99
-     */
100
-    protected function buildPercentageCount($count)
101
-    {
102
-        return '<span class="glsr-bar-percent">'.$count.'</span>';
103
-    }
104
-
105
-    /**
106
-     * @param string $label
107
-     * @return string
108
-     */
109
-    protected function buildPercentageLabel($label)
110
-    {
111
-        return '<span class="glsr-bar-label">'.$label.'</span>';
112
-    }
113
-
114
-    /**
115
-     * @return void|string
116
-     */
117
-    protected function buildRating()
118
-    {
119
-        if ($this->isHidden('rating')) {
120
-            return;
121
-        }
122
-        return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
123
-    }
124
-
125
-    /**
126
-     * @return void|string
127
-     */
128
-    protected function buildStars()
129
-    {
130
-        if ($this->isHidden('stars')) {
131
-            return;
132
-        }
133
-        $stars = glsr_star_rating($this->averageRating);
134
-        return $this->wrap('stars', $stars);
135
-    }
136
-
137
-    /**
138
-     * @return void|string
139
-     */
140
-    protected function buildText()
141
-    {
142
-        if ($this->isHidden('summary')) {
143
-            return;
144
-        }
145
-        $count = intval(array_sum($this->ratingCounts));
146
-        if (empty($this->args['text'])) {
147
-            // @todo document this change
148
-            $this->args['text'] = _nx(
149
-                '{rating} out of {max} stars (based on {num} review)',
150
-                '{rating} out of {max} stars (based on {num} reviews)',
151
-                $count,
152
-                'Do not translate {rating}, {max}, and {num}, they are template tags.',
153
-                'site-reviews'
154
-            );
155
-        }
156
-        $summary = str_replace(
157
-            ['{rating}', '{max}', '{num}'],
158
-            [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
159
-            $this->args['text']
160
-        );
161
-        return $this->wrap('text', '<span>'.$summary.'</span>');
162
-    }
163
-
164
-    /**
165
-     * @return void
166
-     */
167
-    protected function generateSchema()
168
-    {
169
-        if (!wp_validate_boolean($this->args['schema'])) {
170
-            return;
171
-        }
172
-        glsr(Schema::class)->store(
173
-            glsr(Schema::class)->buildSummary($this->args)
174
-        );
175
-    }
176
-
177
-    /**
178
-     * @return string
179
-     */
180
-    protected function getClass()
181
-    {
182
-        return trim('glsr-summary glsr-default '.$this->args['class']);
183
-    }
184
-
185
-    /**
186
-     * @param string $key
187
-     * @return bool
188
-     */
189
-    protected function isHidden($key)
190
-    {
191
-        return in_array($key, $this->args['hide']);
192
-    }
193
-
194
-    /**
195
-     * @param string $key
196
-     * @param string $value
197
-     * @return string
198
-     */
199
-    protected function wrap($key, $value)
200
-    {
201
-        $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
202
-        return glsr(Builder::class)->div($value, [
203
-            'class' => 'glsr-summary-'.$key,
204
-        ]);
205
-    }
13
+	/**
14
+	 * @var array
15
+	 */
16
+	protected $args;
17
+
18
+	/**
19
+	 * @var float
20
+	 */
21
+	protected $averageRating;
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	protected $ratingCounts;
27
+
28
+	/**
29
+	 * @return void|string
30
+	 */
31
+	public function build(array $args = [])
32
+	{
33
+		$this->args = $args;
34
+		$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args);
35
+		if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) {
36
+			return;
37
+		}
38
+		$this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts);
39
+		$this->generateSchema();
40
+		return glsr(Template::class)->build('templates/reviews-summary', [
41
+			'context' => [
42
+				'assigned_to' => $this->args['assigned_to'],
43
+				'category' => $this->args['category'],
44
+				'class' => $this->getClass(),
45
+				'id' => $this->args['id'],
46
+				'percentages' => $this->buildPercentage(),
47
+				'rating' => $this->buildRating(),
48
+				'stars' => $this->buildStars(),
49
+				'text' => $this->buildText(),
50
+			],
51
+		]);
52
+	}
53
+
54
+	/**
55
+	 * @return void|string
56
+	 */
57
+	protected function buildPercentage()
58
+	{
59
+		if ($this->isHidden('bars')) {
60
+			return;
61
+		}
62
+		$percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts));
63
+		$bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) {
64
+			$label = $this->buildPercentageLabel($this->args['labels'][$level]);
65
+			$background = $this->buildPercentageBackground($percentages[$level]);
66
+			$count = apply_filters('site-reviews/summary/counts',
67
+				$percentages[$level],
68
+				$this->ratingCounts[$level]
69
+			);
70
+			$percent = $this->buildPercentageCount($count);
71
+			$value = $label.$background.$percent;
72
+			$value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [
73
+				'percent' => wp_strip_all_tags($count, true),
74
+				'rating' => $level,
75
+			]);
76
+			return $carry.glsr(Builder::class)->div($value, [
77
+				'class' => 'glsr-bar',
78
+			]);
79
+		});
80
+		return $this->wrap('percentage', $bars);
81
+	}
82
+
83
+	/**
84
+	 * @param string $percent
85
+	 * @return string
86
+	 */
87
+	protected function buildPercentageBackground($percent)
88
+	{
89
+		$backgroundPercent = glsr(Builder::class)->span([
90
+			'class' => 'glsr-bar-background-percent',
91
+			'style' => 'width:'.$percent,
92
+		]);
93
+		return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>';
94
+	}
95
+
96
+	/**
97
+	 * @param string $count
98
+	 * @return string
99
+	 */
100
+	protected function buildPercentageCount($count)
101
+	{
102
+		return '<span class="glsr-bar-percent">'.$count.'</span>';
103
+	}
104
+
105
+	/**
106
+	 * @param string $label
107
+	 * @return string
108
+	 */
109
+	protected function buildPercentageLabel($label)
110
+	{
111
+		return '<span class="glsr-bar-label">'.$label.'</span>';
112
+	}
113
+
114
+	/**
115
+	 * @return void|string
116
+	 */
117
+	protected function buildRating()
118
+	{
119
+		if ($this->isHidden('rating')) {
120
+			return;
121
+		}
122
+		return $this->wrap('rating', '<span>'.$this->averageRating.'</span>');
123
+	}
124
+
125
+	/**
126
+	 * @return void|string
127
+	 */
128
+	protected function buildStars()
129
+	{
130
+		if ($this->isHidden('stars')) {
131
+			return;
132
+		}
133
+		$stars = glsr_star_rating($this->averageRating);
134
+		return $this->wrap('stars', $stars);
135
+	}
136
+
137
+	/**
138
+	 * @return void|string
139
+	 */
140
+	protected function buildText()
141
+	{
142
+		if ($this->isHidden('summary')) {
143
+			return;
144
+		}
145
+		$count = intval(array_sum($this->ratingCounts));
146
+		if (empty($this->args['text'])) {
147
+			// @todo document this change
148
+			$this->args['text'] = _nx(
149
+				'{rating} out of {max} stars (based on {num} review)',
150
+				'{rating} out of {max} stars (based on {num} reviews)',
151
+				$count,
152
+				'Do not translate {rating}, {max}, and {num}, they are template tags.',
153
+				'site-reviews'
154
+			);
155
+		}
156
+		$summary = str_replace(
157
+			['{rating}', '{max}', '{num}'],
158
+			[$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count],
159
+			$this->args['text']
160
+		);
161
+		return $this->wrap('text', '<span>'.$summary.'</span>');
162
+	}
163
+
164
+	/**
165
+	 * @return void
166
+	 */
167
+	protected function generateSchema()
168
+	{
169
+		if (!wp_validate_boolean($this->args['schema'])) {
170
+			return;
171
+		}
172
+		glsr(Schema::class)->store(
173
+			glsr(Schema::class)->buildSummary($this->args)
174
+		);
175
+	}
176
+
177
+	/**
178
+	 * @return string
179
+	 */
180
+	protected function getClass()
181
+	{
182
+		return trim('glsr-summary glsr-default '.$this->args['class']);
183
+	}
184
+
185
+	/**
186
+	 * @param string $key
187
+	 * @return bool
188
+	 */
189
+	protected function isHidden($key)
190
+	{
191
+		return in_array($key, $this->args['hide']);
192
+	}
193
+
194
+	/**
195
+	 * @param string $key
196
+	 * @param string $value
197
+	 * @return string
198
+	 */
199
+	protected function wrap($key, $value)
200
+	{
201
+		$value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args);
202
+		return glsr(Builder::class)->div($value, [
203
+			'class' => 'glsr-summary-'.$key,
204
+		]);
205
+	}
206 206
 }
Please login to merge, or discard this patch.
plugin/Helpers/Arr.php 1 patch
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -4,215 +4,215 @@
 block discarded – undo
4 4
 
5 5
 class Arr
6 6
 {
7
-    /**
8
-     * @return bool
9
-     */
10
-    public static function compareArrays(array $arr1, array $arr2)
11
-    {
12
-        sort($arr1);
13
-        sort($arr2);
14
-        return $arr1 == $arr2;
15
-    }
16
-
17
-    /**
18
-     * @param mixed $array
19
-     * @return array
20
-     */
21
-    public static function consolidateArray($array)
22
-    {
23
-        return is_array($array) || is_object($array)
24
-            ? (array) $array
25
-            : [];
26
-    }
27
-
28
-    /**
29
-     * @return array
30
-     */
31
-    public static function convertDotNotationArray(array $array)
32
-    {
33
-        $results = [];
34
-        foreach ($array as $path => $value) {
35
-            $results = static::set($results, $path, $value);
36
-        }
37
-        return $results;
38
-    }
39
-
40
-    /**
41
-     * @param string $string
42
-     * @param mixed $callback
43
-     * @return array
44
-     */
45
-    public static function convertStringToArray($string, $callback = null)
46
-    {
47
-        $array = array_map('trim', explode(',', $string));
48
-        return $callback
49
-            ? array_filter($array, $callback)
50
-            : array_filter($array);
51
-    }
52
-
53
-    /**
54
-     * @param bool $flattenValue
55
-     * @param string $prefix
56
-     * @return array
57
-     */
58
-    public static function flattenArray(array $array, $flattenValue = false, $prefix = '')
59
-    {
60
-        $result = [];
61
-        foreach ($array as $key => $value) {
62
-            $newKey = ltrim($prefix.'.'.$key, '.');
63
-            if (static::isIndexedFlatArray($value)) {
64
-                if ($flattenValue) {
65
-                    $value = '['.implode(', ', $value).']';
66
-                }
67
-            } elseif (is_array($value)) {
68
-                $result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey));
69
-                continue;
70
-            }
71
-            $result[$newKey] = $value;
72
-        }
73
-        return $result;
74
-    }
75
-
76
-    /**
77
-     * Get a value from an array of values using a dot-notation path as reference.
78
-     * @param mixed $data
79
-     * @param string $path
80
-     * @param mixed $fallback
81
-     * @return mixed
82
-     */
83
-    public static function get($data, $path = '', $fallback = '')
84
-    {
85
-        $data = static::consolidateArray($data);
86
-        $keys = explode('.', $path);
87
-        foreach ($keys as $key) {
88
-            if (!isset($data[$key])) {
89
-                return $fallback;
90
-            }
91
-            $data = $data[$key];
92
-        }
93
-        return $data;
94
-    }
95
-
96
-    /**
97
-     * @param string $key
98
-     * @return array
99
-     */
100
-    public static function insertAfter($key, array $array, array $insert)
101
-    {
102
-        return static::insertInArray($array, $insert, $key, 'after');
103
-    }
104
-
105
-    /**
106
-     * @param string $key
107
-     * @return array
108
-     */
109
-    public static function insertBefore($key, array $array, array $insert)
110
-    {
111
-        return static::insertInArray($array, $insert, $key, 'before');
112
-    }
113
-
114
-    /**
115
-     * @param string $key
116
-     * @param string $position
117
-     * @return array
118
-     */
119
-    public static function insertInArray(array $array, array $insert, $key, $position = 'before')
120
-    {
121
-        $keyPosition = intval(array_search($key, array_keys($array)));
122
-        if ('after' == $position) {
123
-            ++$keyPosition;
124
-        }
125
-        if (false !== $keyPosition) {
126
-            $result = array_slice($array, 0, $keyPosition);
127
-            $result = array_merge($result, $insert);
128
-            return array_merge($result, array_slice($array, $keyPosition));
129
-        }
130
-        return array_merge($array, $insert);
131
-    }
132
-
133
-    /**
134
-     * @param mixed $array
135
-     * @return bool
136
-     */
137
-    public static function isIndexedFlatArray($array)
138
-    {
139
-        if (!is_array($array) || array_filter($array, 'is_array')) {
140
-            return false;
141
-        }
142
-        return wp_is_numeric_array($array);
143
-    }
144
-
145
-    /**
146
-     * @param bool $prefixed
147
-     * @return array
148
-     */
149
-    public static function prefixArrayKeys(array $values, $prefixed = true)
150
-    {
151
-        $trim = '_';
152
-        $prefix = $prefixed
153
-            ? $trim
154
-            : '';
155
-        $prefixed = [];
156
-        foreach ($values as $key => $value) {
157
-            $key = trim($key);
158
-            if (0 === strpos($key, $trim)) {
159
-                $key = substr($key, strlen($trim));
160
-            }
161
-            $prefixed[$prefix.$key] = $value;
162
-        }
163
-        return $prefixed;
164
-    }
165
-
166
-    /**
167
-     * @return array
168
-     */
169
-    public static function removeEmptyArrayValues(array $array)
170
-    {
171
-        $result = [];
172
-        foreach ($array as $key => $value) {
173
-            if (!$value) {
174
-                continue;
175
-            }
176
-            $result[$key] = is_array($value)
177
-                ? static::removeEmptyArrayValues($value)
178
-                : $value;
179
-        }
180
-        return $result;
181
-    }
182
-
183
-
184
-    /**
185
-     * Set a value to an array of values using a dot-notation path as reference.
186
-     * @param string $path
187
-     * @param mixed $value
188
-     * @return array
189
-     */
190
-    public static function set(array $data, $path, $value)
191
-    {
192
-        $token = strtok($path, '.');
193
-        $ref = &$data;
194
-        while (false !== $token) {
195
-            $ref = static::consolidateArray($ref);
196
-            $ref = &$ref[$token];
197
-            $token = strtok('.');
198
-        }
199
-        $ref = $value;
200
-        return $data;
201
-    }
202
-
203
-    /**
204
-     * @return array
205
-     */
206
-    public static function unique(array $values)
207
-    {
208
-        return array_filter(array_unique($values));
209
-    }
210
-
211
-    /**
212
-     * @return array
213
-     */
214
-    public static function unprefixArrayKeys(array $values)
215
-    {
216
-        return static::prefixArrayKeys($values, false);
217
-    }
7
+	/**
8
+	 * @return bool
9
+	 */
10
+	public static function compareArrays(array $arr1, array $arr2)
11
+	{
12
+		sort($arr1);
13
+		sort($arr2);
14
+		return $arr1 == $arr2;
15
+	}
16
+
17
+	/**
18
+	 * @param mixed $array
19
+	 * @return array
20
+	 */
21
+	public static function consolidateArray($array)
22
+	{
23
+		return is_array($array) || is_object($array)
24
+			? (array) $array
25
+			: [];
26
+	}
27
+
28
+	/**
29
+	 * @return array
30
+	 */
31
+	public static function convertDotNotationArray(array $array)
32
+	{
33
+		$results = [];
34
+		foreach ($array as $path => $value) {
35
+			$results = static::set($results, $path, $value);
36
+		}
37
+		return $results;
38
+	}
39
+
40
+	/**
41
+	 * @param string $string
42
+	 * @param mixed $callback
43
+	 * @return array
44
+	 */
45
+	public static function convertStringToArray($string, $callback = null)
46
+	{
47
+		$array = array_map('trim', explode(',', $string));
48
+		return $callback
49
+			? array_filter($array, $callback)
50
+			: array_filter($array);
51
+	}
52
+
53
+	/**
54
+	 * @param bool $flattenValue
55
+	 * @param string $prefix
56
+	 * @return array
57
+	 */
58
+	public static function flattenArray(array $array, $flattenValue = false, $prefix = '')
59
+	{
60
+		$result = [];
61
+		foreach ($array as $key => $value) {
62
+			$newKey = ltrim($prefix.'.'.$key, '.');
63
+			if (static::isIndexedFlatArray($value)) {
64
+				if ($flattenValue) {
65
+					$value = '['.implode(', ', $value).']';
66
+				}
67
+			} elseif (is_array($value)) {
68
+				$result = array_merge($result, static::flattenArray($value, $flattenValue, $newKey));
69
+				continue;
70
+			}
71
+			$result[$newKey] = $value;
72
+		}
73
+		return $result;
74
+	}
75
+
76
+	/**
77
+	 * Get a value from an array of values using a dot-notation path as reference.
78
+	 * @param mixed $data
79
+	 * @param string $path
80
+	 * @param mixed $fallback
81
+	 * @return mixed
82
+	 */
83
+	public static function get($data, $path = '', $fallback = '')
84
+	{
85
+		$data = static::consolidateArray($data);
86
+		$keys = explode('.', $path);
87
+		foreach ($keys as $key) {
88
+			if (!isset($data[$key])) {
89
+				return $fallback;
90
+			}
91
+			$data = $data[$key];
92
+		}
93
+		return $data;
94
+	}
95
+
96
+	/**
97
+	 * @param string $key
98
+	 * @return array
99
+	 */
100
+	public static function insertAfter($key, array $array, array $insert)
101
+	{
102
+		return static::insertInArray($array, $insert, $key, 'after');
103
+	}
104
+
105
+	/**
106
+	 * @param string $key
107
+	 * @return array
108
+	 */
109
+	public static function insertBefore($key, array $array, array $insert)
110
+	{
111
+		return static::insertInArray($array, $insert, $key, 'before');
112
+	}
113
+
114
+	/**
115
+	 * @param string $key
116
+	 * @param string $position
117
+	 * @return array
118
+	 */
119
+	public static function insertInArray(array $array, array $insert, $key, $position = 'before')
120
+	{
121
+		$keyPosition = intval(array_search($key, array_keys($array)));
122
+		if ('after' == $position) {
123
+			++$keyPosition;
124
+		}
125
+		if (false !== $keyPosition) {
126
+			$result = array_slice($array, 0, $keyPosition);
127
+			$result = array_merge($result, $insert);
128
+			return array_merge($result, array_slice($array, $keyPosition));
129
+		}
130
+		return array_merge($array, $insert);
131
+	}
132
+
133
+	/**
134
+	 * @param mixed $array
135
+	 * @return bool
136
+	 */
137
+	public static function isIndexedFlatArray($array)
138
+	{
139
+		if (!is_array($array) || array_filter($array, 'is_array')) {
140
+			return false;
141
+		}
142
+		return wp_is_numeric_array($array);
143
+	}
144
+
145
+	/**
146
+	 * @param bool $prefixed
147
+	 * @return array
148
+	 */
149
+	public static function prefixArrayKeys(array $values, $prefixed = true)
150
+	{
151
+		$trim = '_';
152
+		$prefix = $prefixed
153
+			? $trim
154
+			: '';
155
+		$prefixed = [];
156
+		foreach ($values as $key => $value) {
157
+			$key = trim($key);
158
+			if (0 === strpos($key, $trim)) {
159
+				$key = substr($key, strlen($trim));
160
+			}
161
+			$prefixed[$prefix.$key] = $value;
162
+		}
163
+		return $prefixed;
164
+	}
165
+
166
+	/**
167
+	 * @return array
168
+	 */
169
+	public static function removeEmptyArrayValues(array $array)
170
+	{
171
+		$result = [];
172
+		foreach ($array as $key => $value) {
173
+			if (!$value) {
174
+				continue;
175
+			}
176
+			$result[$key] = is_array($value)
177
+				? static::removeEmptyArrayValues($value)
178
+				: $value;
179
+		}
180
+		return $result;
181
+	}
182
+
183
+
184
+	/**
185
+	 * Set a value to an array of values using a dot-notation path as reference.
186
+	 * @param string $path
187
+	 * @param mixed $value
188
+	 * @return array
189
+	 */
190
+	public static function set(array $data, $path, $value)
191
+	{
192
+		$token = strtok($path, '.');
193
+		$ref = &$data;
194
+		while (false !== $token) {
195
+			$ref = static::consolidateArray($ref);
196
+			$ref = &$ref[$token];
197
+			$token = strtok('.');
198
+		}
199
+		$ref = $value;
200
+		return $data;
201
+	}
202
+
203
+	/**
204
+	 * @return array
205
+	 */
206
+	public static function unique(array $values)
207
+	{
208
+		return array_filter(array_unique($values));
209
+	}
210
+
211
+	/**
212
+	 * @return array
213
+	 */
214
+	public static function unprefixArrayKeys(array $values)
215
+	{
216
+		return static::prefixArrayKeys($values, false);
217
+	}
218 218
 }
Please login to merge, or discard this patch.