Passed
Push — feature/rebusify ( 289185...639d49 )
by Paul
04:02
created
activate.php 1 patch
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -8,137 +8,137 @@
 block discarded – undo
8 8
  */
9 9
 class GL_Plugin_Check_v3
10 10
 {
11
-    const MIN_PHP_VERSION = '5.6.0';
12
-    const MIN_WORDPRESS_VERSION = '4.7.0';
11
+	const MIN_PHP_VERSION = '5.6.0';
12
+	const MIN_WORDPRESS_VERSION = '4.7.0';
13 13
 
14
-    /**
15
-     * @var string
16
-     */
17
-    protected $file;
14
+	/**
15
+	 * @var string
16
+	 */
17
+	protected $file;
18 18
 
19
-    /**
20
-     * @var array
21
-     */
22
-    protected $versions;
19
+	/**
20
+	 * @var array
21
+	 */
22
+	protected $versions;
23 23
 
24
-    /**
25
-     * @param string $file
26
-     */
27
-    public function __construct($file, array $versions = array())
28
-    {
29
-        $this->file = realpath($file);
30
-        $this->versions = wp_parse_args($versions, array(
31
-            'php' => static::MIN_PHP_VERSION,
32
-            'wordpress' => static::MIN_WORDPRESS_VERSION,
33
-        ));
34
-    }
24
+	/**
25
+	 * @param string $file
26
+	 */
27
+	public function __construct($file, array $versions = array())
28
+	{
29
+		$this->file = realpath($file);
30
+		$this->versions = wp_parse_args($versions, array(
31
+			'php' => static::MIN_PHP_VERSION,
32
+			'wordpress' => static::MIN_WORDPRESS_VERSION,
33
+		));
34
+	}
35 35
 
36
-    /**
37
-     * @return bool
38
-     */
39
-    public function canProceed()
40
-    {
41
-        if ($this->isValid()) {
42
-            return true;
43
-        }
44
-        add_action('activated_plugin', array($this, 'deactivate'));
45
-        add_action('admin_notices', array($this, 'deactivate'));
46
-        return false;
47
-    }
36
+	/**
37
+	 * @return bool
38
+	 */
39
+	public function canProceed()
40
+	{
41
+		if ($this->isValid()) {
42
+			return true;
43
+		}
44
+		add_action('activated_plugin', array($this, 'deactivate'));
45
+		add_action('admin_notices', array($this, 'deactivate'));
46
+		return false;
47
+	}
48 48
 
49
-    /**
50
-     * @return bool
51
-     */
52
-    public function isPhpValid()
53
-    {
54
-        return !version_compare(PHP_VERSION, $this->versions['php'], '<');
55
-    }
49
+	/**
50
+	 * @return bool
51
+	 */
52
+	public function isPhpValid()
53
+	{
54
+		return !version_compare(PHP_VERSION, $this->versions['php'], '<');
55
+	}
56 56
 
57
-    /**
58
-     * @return bool
59
-     */
60
-    public function isValid()
61
-    {
62
-        return $this->isPhpValid() && $this->isWpValid();
63
-    }
57
+	/**
58
+	 * @return bool
59
+	 */
60
+	public function isValid()
61
+	{
62
+		return $this->isPhpValid() && $this->isWpValid();
63
+	}
64 64
 
65
-    /**
66
-     * @return bool
67
-     */
68
-    public function isWpValid()
69
-    {
70
-        global $wp_version;
71
-        return !version_compare($wp_version, $this->versions['wordpress'], '<');
72
-    }
65
+	/**
66
+	 * @return bool
67
+	 */
68
+	public function isWpValid()
69
+	{
70
+		global $wp_version;
71
+		return !version_compare($wp_version, $this->versions['wordpress'], '<');
72
+	}
73 73
 
74
-    /**
75
-     * @param string $plugin
76
-     * @return void
77
-     */
78
-    public function deactivate($plugin)
79
-    {
80
-        if ($this->isValid()) {
81
-            return;
82
-        }
83
-        $pluginSlug = plugin_basename($this->file);
84
-        if ($plugin == $pluginSlug) {
85
-            $this->redirect(); //exit
86
-        }
87
-        $pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin');
88
-        deactivate_plugins($pluginSlug);
89
-        $this->printNotice($pluginData['name']);
90
-    }
74
+	/**
75
+	 * @param string $plugin
76
+	 * @return void
77
+	 */
78
+	public function deactivate($plugin)
79
+	{
80
+		if ($this->isValid()) {
81
+			return;
82
+		}
83
+		$pluginSlug = plugin_basename($this->file);
84
+		if ($plugin == $pluginSlug) {
85
+			$this->redirect(); //exit
86
+		}
87
+		$pluginData = get_file_data($this->file, array('name' => 'Plugin Name'), 'plugin');
88
+		deactivate_plugins($pluginSlug);
89
+		$this->printNotice($pluginData['name']);
90
+	}
91 91
 
92
-    /**
93
-     * @return array
94
-     */
95
-    protected function getMessages()
96
-    {
97
-        return array(
98
-            __('The %s plugin was deactivated.', 'site-reviews'),
99
-            __('This plugin requires %s or greater in order to work properly.', 'site-reviews'),
100
-            __('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'),
101
-            __('PHP version', 'site-reviews'),
102
-            __('WordPress version', 'site-reviews'),
103
-            __('Update WordPress', 'site-reviews'),
104
-            __('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'),
105
-        );
106
-    }
92
+	/**
93
+	 * @return array
94
+	 */
95
+	protected function getMessages()
96
+	{
97
+		return array(
98
+			__('The %s plugin was deactivated.', 'site-reviews'),
99
+			__('This plugin requires %s or greater in order to work properly.', 'site-reviews'),
100
+			__('Please contact your hosting provider or server administrator to upgrade the version of PHP on your server (your server is running PHP version %s), or try to find an alternative plugin.', 'site-reviews'),
101
+			__('PHP version', 'site-reviews'),
102
+			__('WordPress version', 'site-reviews'),
103
+			__('Update WordPress', 'site-reviews'),
104
+			__('You can use the %s plugin to restore %s to the previous version.', 'site-reviews'),
105
+		);
106
+	}
107 107
 
108
-    /**
109
-     * @param string $pluginName
110
-     * @return void
111
-     */
112
-    protected function printNotice($pluginName)
113
-    {
114
-        $noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>';
115
-        $messages = $this->getMessages();
116
-        $rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName);
117
-        if (!$this->isPhpValid()) {
118
-            printf($noticeTemplate,
119
-                sprintf($messages[0], $pluginName),
120
-                sprintf($messages[1], $messages[3].' '.$this->versions['php']),
121
-                sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage
122
-            );
123
-        } elseif (!$this->isWpValid()) {
124
-            printf($noticeTemplate,
125
-                sprintf($messages[0], $pluginName),
126
-                sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']),
127
-                $rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5])
128
-            );
129
-        }
130
-    }
108
+	/**
109
+	 * @param string $pluginName
110
+	 * @return void
111
+	 */
112
+	protected function printNotice($pluginName)
113
+	{
114
+		$noticeTemplate = '<div id="message" class="notice notice-error error is-dismissible"><p><strong>%s</strong></p><p>%s</p><p>%s</p></div>';
115
+		$messages = $this->getMessages();
116
+		$rollbackMessage = sprintf('<strong>'.$messages[6].'</strong>', '<a href="https://wordpress.org/plugins/wp-rollback/">WP Rollback</a>', $pluginName);
117
+		if (!$this->isPhpValid()) {
118
+			printf($noticeTemplate,
119
+				sprintf($messages[0], $pluginName),
120
+				sprintf($messages[1], $messages[3].' '.$this->versions['php']),
121
+				sprintf($messages[2], PHP_VERSION).'</p><p>'.$rollbackMessage
122
+			);
123
+		} elseif (!$this->isWpValid()) {
124
+			printf($noticeTemplate,
125
+				sprintf($messages[0], $pluginName),
126
+				sprintf($messages[1], $messages[4].' '.$this->versions['wordpress']),
127
+				$rollbackMessage.'</p><p>'.sprintf('<a href="%s">%s</a>', admin_url('update-core.php'), $messages[5])
128
+			);
129
+		}
130
+	}
131 131
 
132
-    /**
133
-     * @return void
134
-     */
135
-    protected function redirect()
136
-    {
137
-        wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s',
138
-            filter_input(INPUT_GET, 'plugin_status'),
139
-            filter_input(INPUT_GET, 'paged'),
140
-            filter_input(INPUT_GET, 's')
141
-        )));
142
-        exit;
143
-    }
132
+	/**
133
+	 * @return void
134
+	 */
135
+	protected function redirect()
136
+	{
137
+		wp_safe_redirect(self_admin_url(sprintf('plugins.php?plugin_status=%s&paged=%s&s=%s',
138
+			filter_input(INPUT_GET, 'plugin_status'),
139
+			filter_input(INPUT_GET, 'paged'),
140
+			filter_input(INPUT_GET, 's')
141
+		)));
142
+		exit;
143
+	}
144 144
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Settings.php 1 patch
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -9,239 +9,239 @@
 block discarded – undo
9 9
 
10 10
 class Settings
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    public $settings;
16
-
17
-    /**
18
-     * @param string $id
19
-     * @return string
20
-     */
21
-    public function buildFields($id)
22
-    {
23
-        $this->settings = glsr(DefaultsManager::class)->settings();
24
-        $method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor');
25
-        $data = !method_exists($this, $method)
26
-            ? $this->getTemplateData($id)
27
-            : $this->$method($id);
28
-        return glsr(Template::class)->build('pages/settings/'.$id, $data);
29
-    }
30
-
31
-    /**
32
-     * @return string
33
-     */
34
-    protected function getFieldDefault(array $field)
35
-    {
36
-        return glsr_get($field, 'default');
37
-    }
38
-
39
-    /**
40
-     * @return string
41
-     */
42
-    protected function getFieldNameForDependsOn($path)
43
-    {
44
-        $fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey());
45
-        return $this->isMultiDependency($path)
46
-            ? $fieldName.'[]'
47
-            : $fieldName;
48
-    }
49
-
50
-    /**
51
-     * @return array
52
-     */
53
-    protected function getSettingFields($path)
54
-    {
55
-        return array_filter($this->settings, function ($key) use ($path) {
56
-            return glsr(Helper::class)->startsWith($path, $key);
57
-        }, ARRAY_FILTER_USE_KEY);
58
-    }
59
-
60
-    /**
61
-     * @return string
62
-     */
63
-    protected function getSettingRows(array $fields)
64
-    {
65
-        $rows = '';
66
-        foreach ($fields as $name => $field) {
67
-            $field = wp_parse_args($field, [
68
-                'is_setting' => true,
69
-                'name' => $name,
70
-            ]);
71
-            $rows.= new Field($this->normalize($field));
72
-        }
73
-        return $rows;
74
-    }
75
-
76
-    /**
77
-     * @param string $id
78
-     * @return array
79
-     */
80
-    protected function getTemplateData($id)
81
-    {
82
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
83
-        return [
84
-            'context' => [
85
-                'rows' => $this->getSettingRows($fields),
86
-            ],
87
-        ];
88
-    }
89
-
90
-    /**
91
-     * @param string $id
92
-     * @return array
93
-     */
94
-    protected function getTemplateDataForAddons($id)
95
-    {
96
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
97
-        $settings = glsr(Helper::class)->convertDotNotationArray($fields);
98
-        $settingKeys = array_keys($settings['settings']['addons']);
99
-        $results = [];
100
-        foreach ($settingKeys as $key) {
101
-            $addonFields = array_filter($fields, function ($path) use ($key) {
102
-                return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path);
103
-            }, ARRAY_FILTER_USE_KEY);
104
-            $results[$key] = $this->getSettingRows($addonFields);
105
-        }
106
-        ksort($results);
107
-        return [
108
-            'settings' => $results,
109
-        ];
110
-    }
111
-
112
-    /**
113
-     * @param string $id
114
-     * @return array
115
-     */
116
-    protected function getTemplateDataForLicenses($id)
117
-    {
118
-        $fields = $this->getSettingFields($this->normalizeSettingPath($id));
119
-        ksort($fields);
120
-        return [
121
-            'context' => [
122
-                'rows' => $this->getSettingRows($fields),
123
-            ],
124
-        ];
125
-    }
126
-
127
-    /**
128
-     * @return array
129
-     */
130
-    protected function getTemplateDataForTranslations()
131
-    {
132
-        $translations = glsr(Translation::class)->renderAll();
133
-        $class = empty($translations)
134
-            ? 'glsr-hidden'
135
-            : '';
136
-        return [
137
-            'context' => [
138
-                'class' => $class,
139
-                'database_key' => OptionManager::databaseKey(),
140
-                'translations' => $translations,
141
-            ],
142
-        ];
143
-    }
144
-
145
-    /**
146
-     * @param string $path
147
-     * @param string|array $expectedValue
148
-     * @return bool
149
-     */
150
-    protected function isFieldHidden($path, $expectedValue)
151
-    {
152
-        $optionValue = glsr(OptionManager::class)->get(
153
-            $path,
154
-            glsr(Helper::class)->dataGet(glsr()->defaults, $path)
155
-        );
156
-        if (is_array($expectedValue)) {
157
-            return is_array($optionValue)
158
-                ? 0 === count(array_intersect($optionValue, $expectedValue))
159
-                : !in_array($optionValue, $expectedValue);
160
-        }
161
-        return $optionValue != $expectedValue;
162
-    }
163
-
164
-    /**
165
-     * @return bool
166
-     */
167
-    protected function isMultiDependency($path)
168
-    {
169
-        if (isset($this->settings[$path])) {
170
-            $field = $this->settings[$path];
171
-            return ('checkbox' == $field['type'] && !empty($field['options']))
172
-                || !empty($field['multiple']);
173
-        }
174
-        return false;
175
-    }
176
-
177
-    /**
178
-     * @return array
179
-     */
180
-    protected function normalize(array $field)
181
-    {
182
-        $field = $this->normalizeDependsOn($field);
183
-        $field = $this->normalizeLabelAndLegend($field);
184
-        $field = $this->normalizeValue($field);
185
-        return $field;
186
-    }
187
-
188
-    /**
189
-     * @return array
190
-     */
191
-    protected function normalizeDependsOn(array $field)
192
-    {
193
-        if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
194
-            $isFieldHidden = false;
195
-            $conditions = [];
196
-            foreach ($field['depends_on'] as $path => $value) {
197
-                $conditions[] = [
198
-                    'name' => $this->getFieldNameForDependsOn($path),
199
-                    'value' => $value,
200
-                ];
201
-                if ($this->isFieldHidden($path, $value)) {
202
-                    $isFieldHidden = true;
203
-                }
204
-            }
205
-            $field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
206
-            $field['is_hidden'] = $isFieldHidden;
207
-        }
208
-        return $field;
209
-    }
210
-
211
-    /**
212
-     * @return array
213
-     */
214
-    protected function normalizeLabelAndLegend(array $field)
215
-    {
216
-        if (!empty($field['label'])) {
217
-            $field['legend'] = $field['label'];
218
-            unset($field['label']);
219
-        } else {
220
-            $field['is_valid'] = false;
221
-            glsr_log()->warning('Setting field is missing a label')->debug($field);
222
-        }
223
-        return $field;
224
-    }
225
-
226
-    /**
227
-     * @return array
228
-     */
229
-    protected function normalizeValue(array $field)
230
-    {
231
-        if (!isset($field['value'])) {
232
-            $field['value'] = glsr(OptionManager::class)->get(
233
-                $field['name'],
234
-                $this->getFieldDefault($field)
235
-            );
236
-        }
237
-        return $field;
238
-    }
239
-
240
-    /**
241
-     * @return string
242
-     */
243
-    protected function normalizeSettingPath($path)
244
-    {
245
-        return glsr(Helper::class)->prefixString(rtrim($path, '.'), 'settings.');
246
-    }
12
+	/**
13
+	 * @var array
14
+	 */
15
+	public $settings;
16
+
17
+	/**
18
+	 * @param string $id
19
+	 * @return string
20
+	 */
21
+	public function buildFields($id)
22
+	{
23
+		$this->settings = glsr(DefaultsManager::class)->settings();
24
+		$method = glsr(Helper::class)->buildMethodName($id, 'getTemplateDataFor');
25
+		$data = !method_exists($this, $method)
26
+			? $this->getTemplateData($id)
27
+			: $this->$method($id);
28
+		return glsr(Template::class)->build('pages/settings/'.$id, $data);
29
+	}
30
+
31
+	/**
32
+	 * @return string
33
+	 */
34
+	protected function getFieldDefault(array $field)
35
+	{
36
+		return glsr_get($field, 'default');
37
+	}
38
+
39
+	/**
40
+	 * @return string
41
+	 */
42
+	protected function getFieldNameForDependsOn($path)
43
+	{
44
+		$fieldName = glsr(Helper::class)->convertPathToName($path, OptionManager::databaseKey());
45
+		return $this->isMultiDependency($path)
46
+			? $fieldName.'[]'
47
+			: $fieldName;
48
+	}
49
+
50
+	/**
51
+	 * @return array
52
+	 */
53
+	protected function getSettingFields($path)
54
+	{
55
+		return array_filter($this->settings, function ($key) use ($path) {
56
+			return glsr(Helper::class)->startsWith($path, $key);
57
+		}, ARRAY_FILTER_USE_KEY);
58
+	}
59
+
60
+	/**
61
+	 * @return string
62
+	 */
63
+	protected function getSettingRows(array $fields)
64
+	{
65
+		$rows = '';
66
+		foreach ($fields as $name => $field) {
67
+			$field = wp_parse_args($field, [
68
+				'is_setting' => true,
69
+				'name' => $name,
70
+			]);
71
+			$rows.= new Field($this->normalize($field));
72
+		}
73
+		return $rows;
74
+	}
75
+
76
+	/**
77
+	 * @param string $id
78
+	 * @return array
79
+	 */
80
+	protected function getTemplateData($id)
81
+	{
82
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
83
+		return [
84
+			'context' => [
85
+				'rows' => $this->getSettingRows($fields),
86
+			],
87
+		];
88
+	}
89
+
90
+	/**
91
+	 * @param string $id
92
+	 * @return array
93
+	 */
94
+	protected function getTemplateDataForAddons($id)
95
+	{
96
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
97
+		$settings = glsr(Helper::class)->convertDotNotationArray($fields);
98
+		$settingKeys = array_keys($settings['settings']['addons']);
99
+		$results = [];
100
+		foreach ($settingKeys as $key) {
101
+			$addonFields = array_filter($fields, function ($path) use ($key) {
102
+				return glsr(Helper::class)->startsWith('settings.addons.'.$key, $path);
103
+			}, ARRAY_FILTER_USE_KEY);
104
+			$results[$key] = $this->getSettingRows($addonFields);
105
+		}
106
+		ksort($results);
107
+		return [
108
+			'settings' => $results,
109
+		];
110
+	}
111
+
112
+	/**
113
+	 * @param string $id
114
+	 * @return array
115
+	 */
116
+	protected function getTemplateDataForLicenses($id)
117
+	{
118
+		$fields = $this->getSettingFields($this->normalizeSettingPath($id));
119
+		ksort($fields);
120
+		return [
121
+			'context' => [
122
+				'rows' => $this->getSettingRows($fields),
123
+			],
124
+		];
125
+	}
126
+
127
+	/**
128
+	 * @return array
129
+	 */
130
+	protected function getTemplateDataForTranslations()
131
+	{
132
+		$translations = glsr(Translation::class)->renderAll();
133
+		$class = empty($translations)
134
+			? 'glsr-hidden'
135
+			: '';
136
+		return [
137
+			'context' => [
138
+				'class' => $class,
139
+				'database_key' => OptionManager::databaseKey(),
140
+				'translations' => $translations,
141
+			],
142
+		];
143
+	}
144
+
145
+	/**
146
+	 * @param string $path
147
+	 * @param string|array $expectedValue
148
+	 * @return bool
149
+	 */
150
+	protected function isFieldHidden($path, $expectedValue)
151
+	{
152
+		$optionValue = glsr(OptionManager::class)->get(
153
+			$path,
154
+			glsr(Helper::class)->dataGet(glsr()->defaults, $path)
155
+		);
156
+		if (is_array($expectedValue)) {
157
+			return is_array($optionValue)
158
+				? 0 === count(array_intersect($optionValue, $expectedValue))
159
+				: !in_array($optionValue, $expectedValue);
160
+		}
161
+		return $optionValue != $expectedValue;
162
+	}
163
+
164
+	/**
165
+	 * @return bool
166
+	 */
167
+	protected function isMultiDependency($path)
168
+	{
169
+		if (isset($this->settings[$path])) {
170
+			$field = $this->settings[$path];
171
+			return ('checkbox' == $field['type'] && !empty($field['options']))
172
+				|| !empty($field['multiple']);
173
+		}
174
+		return false;
175
+	}
176
+
177
+	/**
178
+	 * @return array
179
+	 */
180
+	protected function normalize(array $field)
181
+	{
182
+		$field = $this->normalizeDependsOn($field);
183
+		$field = $this->normalizeLabelAndLegend($field);
184
+		$field = $this->normalizeValue($field);
185
+		return $field;
186
+	}
187
+
188
+	/**
189
+	 * @return array
190
+	 */
191
+	protected function normalizeDependsOn(array $field)
192
+	{
193
+		if (!empty($field['depends_on']) && is_array($field['depends_on'])) {
194
+			$isFieldHidden = false;
195
+			$conditions = [];
196
+			foreach ($field['depends_on'] as $path => $value) {
197
+				$conditions[] = [
198
+					'name' => $this->getFieldNameForDependsOn($path),
199
+					'value' => $value,
200
+				];
201
+				if ($this->isFieldHidden($path, $value)) {
202
+					$isFieldHidden = true;
203
+				}
204
+			}
205
+			$field['data-depends'] = json_encode($conditions, JSON_HEX_APOS | JSON_HEX_QUOT);
206
+			$field['is_hidden'] = $isFieldHidden;
207
+		}
208
+		return $field;
209
+	}
210
+
211
+	/**
212
+	 * @return array
213
+	 */
214
+	protected function normalizeLabelAndLegend(array $field)
215
+	{
216
+		if (!empty($field['label'])) {
217
+			$field['legend'] = $field['label'];
218
+			unset($field['label']);
219
+		} else {
220
+			$field['is_valid'] = false;
221
+			glsr_log()->warning('Setting field is missing a label')->debug($field);
222
+		}
223
+		return $field;
224
+	}
225
+
226
+	/**
227
+	 * @return array
228
+	 */
229
+	protected function normalizeValue(array $field)
230
+	{
231
+		if (!isset($field['value'])) {
232
+			$field['value'] = glsr(OptionManager::class)->get(
233
+				$field['name'],
234
+				$this->getFieldDefault($field)
235
+			);
236
+		}
237
+		return $field;
238
+	}
239
+
240
+	/**
241
+	 * @return string
242
+	 */
243
+	protected function normalizeSettingPath($path)
244
+	{
245
+		return glsr(Helper::class)->prefixString(rtrim($path, '.'), 'settings.');
246
+	}
247 247
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Builder.php 1 patch
Indentation   +342 added lines, -342 removed lines patch added patch discarded remove patch
@@ -18,346 +18,346 @@
 block discarded – undo
18 18
  */
19 19
 class Builder
20 20
 {
21
-    const INPUT_TYPES = [
22
-        'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
23
-        'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
24
-        'url', 'week',
25
-    ];
26
-
27
-    const TAGS_FORM = [
28
-        'input', 'select', 'textarea',
29
-    ];
30
-
31
-    const TAGS_SINGLE = [
32
-        'img',
33
-    ];
34
-
35
-    const TAGS_STRUCTURE = [
36
-        'div', 'form', 'nav', 'ol', 'section', 'ul',
37
-    ];
38
-
39
-    const TAGS_TEXT = [
40
-        'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
41
-        'small', 'span',
42
-    ];
43
-
44
-    /**
45
-     * @var array
46
-     */
47
-    public $args = [];
48
-
49
-    /**
50
-     * @var bool
51
-     */
52
-    public $render = false;
53
-
54
-    /**
55
-     * @var string
56
-     */
57
-    public $tag;
58
-
59
-    /**
60
-     * @param string $method
61
-     * @param array $args
62
-     * @return string|void
63
-     */
64
-    public function __call($method, $args)
65
-    {
66
-        $instance = new static();
67
-        $instance->setTagFromMethod($method);
68
-        call_user_func_array([$instance, 'normalize'], $args += ['', '']);
69
-        $tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
70
-        do_action_ref_array('site-reviews/builder', [$instance]);
71
-        $generatedTag = in_array($instance->tag, $tags)
72
-            ? $instance->buildTag()
73
-            : $instance->buildCustomField();
74
-        $generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
75
-        if (!$this->render) {
76
-            return $generatedTag;
77
-        }
78
-        echo $generatedTag;
79
-    }
80
-
81
-    /**
82
-     * @param string $property
83
-     * @param mixed $value
84
-     * @return void
85
-     */
86
-    public function __set($property, $value)
87
-    {
88
-        $properties = [
89
-            'args' => 'is_array',
90
-            'render' => 'is_bool',
91
-            'tag' => 'is_string',
92
-        ];
93
-        if (!isset($properties[$property])
94
-            || empty(array_filter([$value], $properties[$property]))
95
-        ) {
96
-            return;
97
-        }
98
-        $this->$property = $value;
99
-    }
100
-
101
-    /**
102
-     * @return void|string
103
-     */
104
-    public function getClosingTag()
105
-    {
106
-        if (empty($this->tag)) {
107
-            return;
108
-        }
109
-        return '</'.$this->tag.'>';
110
-    }
111
-
112
-    /**
113
-     * @return void|string
114
-     */
115
-    public function getOpeningTag()
116
-    {
117
-        if (empty($this->tag)) {
118
-            return;
119
-        }
120
-        $attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
121
-        return '<'.trim($this->tag.' '.$attributes).'>';
122
-    }
123
-
124
-    /**
125
-     * @return void|string
126
-     */
127
-    public function getTag()
128
-    {
129
-        if (in_array($this->tag, static::TAGS_SINGLE)) {
130
-            return $this->getOpeningTag();
131
-        }
132
-        if (!in_array($this->tag, static::TAGS_FORM)) {
133
-            return $this->buildDefaultTag();
134
-        }
135
-        return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
136
-    }
137
-
138
-    /**
139
-     * @return string
140
-     */
141
-    public function raw(array $field)
142
-    {
143
-        unset($field['label']);
144
-        return $this->{$field['type']}($field);
145
-    }
146
-
147
-    /**
148
-     * @return string|void
149
-     */
150
-    protected function buildCustomField()
151
-    {
152
-        $className = $this->getCustomFieldClassName();
153
-        if (class_exists($className)) {
154
-            return (new $className($this))->build();
155
-        }
156
-        glsr_log()->error('Field missing: '.$className);
157
-    }
158
-
159
-    /**
160
-     * @return string|void
161
-     */
162
-    protected function buildDefaultTag($text = '')
163
-    {
164
-        if (empty($text)) {
165
-            $text = $this->args['text'];
166
-        }
167
-        return $this->getOpeningTag().$text.$this->getClosingTag();
168
-    }
169
-
170
-    /**
171
-     * @return string|void
172
-     */
173
-    protected function buildFieldDescription()
174
-    {
175
-        if (empty($this->args['description'])) {
176
-            return;
177
-        }
178
-        if ($this->args['is_widget']) {
179
-            return $this->small($this->args['description']);
180
-        }
181
-        return $this->p($this->args['description'], ['class' => 'description']);
182
-    }
183
-
184
-    /**
185
-     * @return string|void
186
-     */
187
-    protected function buildFormInput()
188
-    {
189
-        if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
190
-            if (isset($this->args['multiple'])) {
191
-                $this->args['name'].= '[]';
192
-            }
193
-            return $this->buildFormLabel().$this->getOpeningTag();
194
-        }
195
-        return empty($this->args['options'])
196
-            ? $this->buildFormInputChoice()
197
-            : $this->buildFormInputMultiChoice();
198
-    }
199
-
200
-    /**
201
-     * @return string|void
202
-     */
203
-    protected function buildFormInputChoice()
204
-    {
205
-        if (!empty($this->args['text'])) {
206
-            $this->args['label'] = $this->args['text'];
207
-        }
208
-        if (!$this->args['is_public']) {
209
-            return $this->buildFormLabel([
210
-                'class' => 'glsr-'.$this->args['type'].'-label',
211
-                'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
212
-            ]);
213
-        }
214
-        return $this->getOpeningTag().$this->buildFormLabel([
215
-            'class' => 'glsr-'.$this->args['type'].'-label',
216
-            'text' => $this->args['label'].'<span></span>',
217
-        ]);
218
-    }
219
-
220
-    /**
221
-     * @return string|void
222
-     */
223
-    protected function buildFormInputMultiChoice()
224
-    {
225
-        if ('checkbox' == $this->args['type']) {
226
-            $this->args['name'].= '[]';
227
-        }
228
-        $index = 0;
229
-        $options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
230
-            return $carry.$this->li($this->{$this->args['type']}([
231
-                'checked' => in_array($key, (array) $this->args['value']),
232
-                'id' => $this->args['id'].'-'.$index++,
233
-                'name' => $this->args['name'],
234
-                'text' => $this->args['options'][$key],
235
-                'value' => $key,
236
-            ]));
237
-        });
238
-        return $this->ul($options, [
239
-            'class' => $this->args['class'],
240
-            'id' => $this->args['id'],
241
-        ]);
242
-    }
243
-
244
-    /**
245
-     * @return void|string
246
-     */
247
-    protected function buildFormLabel(array $customArgs = [])
248
-    {
249
-        if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
250
-            return;
251
-        }
252
-        return $this->label(wp_parse_args($customArgs, [
253
-            'for' => $this->args['id'],
254
-            'is_public' => $this->args['is_public'],
255
-            'text' => $this->args['label'],
256
-            'type' => $this->args['type'],
257
-        ]));
258
-    }
259
-
260
-    /**
261
-     * @return string|void
262
-     */
263
-    protected function buildFormSelect()
264
-    {
265
-        return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
266
-    }
267
-
268
-    /**
269
-     * @return string|void
270
-     */
271
-    protected function buildFormSelectOptions()
272
-    {
273
-        return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
274
-            return $carry.$this->option([
275
-                'selected' => $this->args['value'] == $key,
276
-                'text' => $this->args['options'][$key],
277
-                'value' => $key,
278
-            ]);
279
-        });
280
-    }
281
-
282
-    /**
283
-     * @return string|void
284
-     */
285
-    protected function buildFormTextarea()
286
-    {
287
-        return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
288
-    }
289
-
290
-    /**
291
-     * @return string|void
292
-     */
293
-    protected function buildTag()
294
-    {
295
-        $this->mergeArgsWithRequiredDefaults();
296
-        return $this->getTag();
297
-    }
298
-
299
-    /**
300
-     * @return string
301
-     */
302
-    protected function getCustomFieldClassName()
303
-    {
304
-        $classname = glsr(Helper::class)->buildClassName($this->tag, __NAMESPACE__.'\Fields');
305
-        return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
306
-    }
307
-
308
-    /**
309
-     * @return void
310
-     */
311
-    protected function mergeArgsWithRequiredDefaults()
312
-    {
313
-        $className = $this->getCustomFieldClassName();
314
-        if (class_exists($className)) {
315
-            $this->args = $className::merge($this->args);
316
-        }
317
-        $this->args = glsr(BuilderDefaults::class)->merge($this->args);
318
-    }
319
-
320
-    /**
321
-     * @param string|array ...$params
322
-     * @return void
323
-     */
324
-    protected function normalize(...$params)
325
-    {
326
-        if (is_string($params[0]) || is_numeric($params[0])) {
327
-            $this->setNameOrTextAttributeForTag($params[0]);
328
-        }
329
-        if (is_array($params[0])) {
330
-            $this->args += $params[0];
331
-        } elseif (is_array($params[1])) {
332
-            $this->args += $params[1];
333
-        }
334
-        if (!isset($this->args['is_public'])) {
335
-            $this->args['is_public'] = false;
336
-        }
337
-    }
338
-
339
-    /**
340
-     * @param string $value
341
-     * @return void
342
-     */
343
-    protected function setNameOrTextAttributeForTag($value)
344
-    {
345
-        $attribute = in_array($this->tag, static::TAGS_FORM)
346
-            ? 'name'
347
-            : 'text';
348
-        $this->args[$attribute] = $value;
349
-    }
350
-
351
-    /**
352
-     * @param string $method
353
-     * @return void
354
-     */
355
-    protected function setTagFromMethod($method)
356
-    {
357
-        $this->tag = strtolower($method);
358
-        if (in_array($this->tag, static::INPUT_TYPES)) {
359
-            $this->args['type'] = $this->tag;
360
-            $this->tag = 'input';
361
-        }
362
-    }
21
+	const INPUT_TYPES = [
22
+		'checkbox', 'date', 'datetime-local', 'email', 'file', 'hidden', 'image', 'month',
23
+		'number', 'password', 'radio', 'range', 'reset', 'search', 'submit', 'tel', 'text', 'time',
24
+		'url', 'week',
25
+	];
26
+
27
+	const TAGS_FORM = [
28
+		'input', 'select', 'textarea',
29
+	];
30
+
31
+	const TAGS_SINGLE = [
32
+		'img',
33
+	];
34
+
35
+	const TAGS_STRUCTURE = [
36
+		'div', 'form', 'nav', 'ol', 'section', 'ul',
37
+	];
38
+
39
+	const TAGS_TEXT = [
40
+		'a', 'button', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'label', 'li', 'option', 'p', 'pre',
41
+		'small', 'span',
42
+	];
43
+
44
+	/**
45
+	 * @var array
46
+	 */
47
+	public $args = [];
48
+
49
+	/**
50
+	 * @var bool
51
+	 */
52
+	public $render = false;
53
+
54
+	/**
55
+	 * @var string
56
+	 */
57
+	public $tag;
58
+
59
+	/**
60
+	 * @param string $method
61
+	 * @param array $args
62
+	 * @return string|void
63
+	 */
64
+	public function __call($method, $args)
65
+	{
66
+		$instance = new static();
67
+		$instance->setTagFromMethod($method);
68
+		call_user_func_array([$instance, 'normalize'], $args += ['', '']);
69
+		$tags = array_merge(static::TAGS_FORM, static::TAGS_SINGLE, static::TAGS_STRUCTURE, static::TAGS_TEXT);
70
+		do_action_ref_array('site-reviews/builder', [$instance]);
71
+		$generatedTag = in_array($instance->tag, $tags)
72
+			? $instance->buildTag()
73
+			: $instance->buildCustomField();
74
+		$generatedTag = apply_filters('site-reviews/builder/result', $generatedTag, $instance);
75
+		if (!$this->render) {
76
+			return $generatedTag;
77
+		}
78
+		echo $generatedTag;
79
+	}
80
+
81
+	/**
82
+	 * @param string $property
83
+	 * @param mixed $value
84
+	 * @return void
85
+	 */
86
+	public function __set($property, $value)
87
+	{
88
+		$properties = [
89
+			'args' => 'is_array',
90
+			'render' => 'is_bool',
91
+			'tag' => 'is_string',
92
+		];
93
+		if (!isset($properties[$property])
94
+			|| empty(array_filter([$value], $properties[$property]))
95
+		) {
96
+			return;
97
+		}
98
+		$this->$property = $value;
99
+	}
100
+
101
+	/**
102
+	 * @return void|string
103
+	 */
104
+	public function getClosingTag()
105
+	{
106
+		if (empty($this->tag)) {
107
+			return;
108
+		}
109
+		return '</'.$this->tag.'>';
110
+	}
111
+
112
+	/**
113
+	 * @return void|string
114
+	 */
115
+	public function getOpeningTag()
116
+	{
117
+		if (empty($this->tag)) {
118
+			return;
119
+		}
120
+		$attributes = glsr(Attributes::class)->{$this->tag}($this->args)->toString();
121
+		return '<'.trim($this->tag.' '.$attributes).'>';
122
+	}
123
+
124
+	/**
125
+	 * @return void|string
126
+	 */
127
+	public function getTag()
128
+	{
129
+		if (in_array($this->tag, static::TAGS_SINGLE)) {
130
+			return $this->getOpeningTag();
131
+		}
132
+		if (!in_array($this->tag, static::TAGS_FORM)) {
133
+			return $this->buildDefaultTag();
134
+		}
135
+		return call_user_func([$this, 'buildForm'.ucfirst($this->tag)]).$this->buildFieldDescription();
136
+	}
137
+
138
+	/**
139
+	 * @return string
140
+	 */
141
+	public function raw(array $field)
142
+	{
143
+		unset($field['label']);
144
+		return $this->{$field['type']}($field);
145
+	}
146
+
147
+	/**
148
+	 * @return string|void
149
+	 */
150
+	protected function buildCustomField()
151
+	{
152
+		$className = $this->getCustomFieldClassName();
153
+		if (class_exists($className)) {
154
+			return (new $className($this))->build();
155
+		}
156
+		glsr_log()->error('Field missing: '.$className);
157
+	}
158
+
159
+	/**
160
+	 * @return string|void
161
+	 */
162
+	protected function buildDefaultTag($text = '')
163
+	{
164
+		if (empty($text)) {
165
+			$text = $this->args['text'];
166
+		}
167
+		return $this->getOpeningTag().$text.$this->getClosingTag();
168
+	}
169
+
170
+	/**
171
+	 * @return string|void
172
+	 */
173
+	protected function buildFieldDescription()
174
+	{
175
+		if (empty($this->args['description'])) {
176
+			return;
177
+		}
178
+		if ($this->args['is_widget']) {
179
+			return $this->small($this->args['description']);
180
+		}
181
+		return $this->p($this->args['description'], ['class' => 'description']);
182
+	}
183
+
184
+	/**
185
+	 * @return string|void
186
+	 */
187
+	protected function buildFormInput()
188
+	{
189
+		if (!in_array($this->args['type'], ['checkbox', 'radio'])) {
190
+			if (isset($this->args['multiple'])) {
191
+				$this->args['name'].= '[]';
192
+			}
193
+			return $this->buildFormLabel().$this->getOpeningTag();
194
+		}
195
+		return empty($this->args['options'])
196
+			? $this->buildFormInputChoice()
197
+			: $this->buildFormInputMultiChoice();
198
+	}
199
+
200
+	/**
201
+	 * @return string|void
202
+	 */
203
+	protected function buildFormInputChoice()
204
+	{
205
+		if (!empty($this->args['text'])) {
206
+			$this->args['label'] = $this->args['text'];
207
+		}
208
+		if (!$this->args['is_public']) {
209
+			return $this->buildFormLabel([
210
+				'class' => 'glsr-'.$this->args['type'].'-label',
211
+				'text' => $this->getOpeningTag().' '.$this->args['label'].'<span></span>',
212
+			]);
213
+		}
214
+		return $this->getOpeningTag().$this->buildFormLabel([
215
+			'class' => 'glsr-'.$this->args['type'].'-label',
216
+			'text' => $this->args['label'].'<span></span>',
217
+		]);
218
+	}
219
+
220
+	/**
221
+	 * @return string|void
222
+	 */
223
+	protected function buildFormInputMultiChoice()
224
+	{
225
+		if ('checkbox' == $this->args['type']) {
226
+			$this->args['name'].= '[]';
227
+		}
228
+		$index = 0;
229
+		$options = array_reduce(array_keys($this->args['options']), function ($carry, $key) use (&$index) {
230
+			return $carry.$this->li($this->{$this->args['type']}([
231
+				'checked' => in_array($key, (array) $this->args['value']),
232
+				'id' => $this->args['id'].'-'.$index++,
233
+				'name' => $this->args['name'],
234
+				'text' => $this->args['options'][$key],
235
+				'value' => $key,
236
+			]));
237
+		});
238
+		return $this->ul($options, [
239
+			'class' => $this->args['class'],
240
+			'id' => $this->args['id'],
241
+		]);
242
+	}
243
+
244
+	/**
245
+	 * @return void|string
246
+	 */
247
+	protected function buildFormLabel(array $customArgs = [])
248
+	{
249
+		if (empty($this->args['label']) || 'hidden' == $this->args['type']) {
250
+			return;
251
+		}
252
+		return $this->label(wp_parse_args($customArgs, [
253
+			'for' => $this->args['id'],
254
+			'is_public' => $this->args['is_public'],
255
+			'text' => $this->args['label'],
256
+			'type' => $this->args['type'],
257
+		]));
258
+	}
259
+
260
+	/**
261
+	 * @return string|void
262
+	 */
263
+	protected function buildFormSelect()
264
+	{
265
+		return $this->buildFormLabel().$this->buildDefaultTag($this->buildFormSelectOptions());
266
+	}
267
+
268
+	/**
269
+	 * @return string|void
270
+	 */
271
+	protected function buildFormSelectOptions()
272
+	{
273
+		return array_reduce(array_keys($this->args['options']), function ($carry, $key) {
274
+			return $carry.$this->option([
275
+				'selected' => $this->args['value'] == $key,
276
+				'text' => $this->args['options'][$key],
277
+				'value' => $key,
278
+			]);
279
+		});
280
+	}
281
+
282
+	/**
283
+	 * @return string|void
284
+	 */
285
+	protected function buildFormTextarea()
286
+	{
287
+		return $this->buildFormLabel().$this->buildDefaultTag($this->args['value']);
288
+	}
289
+
290
+	/**
291
+	 * @return string|void
292
+	 */
293
+	protected function buildTag()
294
+	{
295
+		$this->mergeArgsWithRequiredDefaults();
296
+		return $this->getTag();
297
+	}
298
+
299
+	/**
300
+	 * @return string
301
+	 */
302
+	protected function getCustomFieldClassName()
303
+	{
304
+		$classname = glsr(Helper::class)->buildClassName($this->tag, __NAMESPACE__.'\Fields');
305
+		return apply_filters('site-reviews/builder/field/'.$this->tag, $classname);
306
+	}
307
+
308
+	/**
309
+	 * @return void
310
+	 */
311
+	protected function mergeArgsWithRequiredDefaults()
312
+	{
313
+		$className = $this->getCustomFieldClassName();
314
+		if (class_exists($className)) {
315
+			$this->args = $className::merge($this->args);
316
+		}
317
+		$this->args = glsr(BuilderDefaults::class)->merge($this->args);
318
+	}
319
+
320
+	/**
321
+	 * @param string|array ...$params
322
+	 * @return void
323
+	 */
324
+	protected function normalize(...$params)
325
+	{
326
+		if (is_string($params[0]) || is_numeric($params[0])) {
327
+			$this->setNameOrTextAttributeForTag($params[0]);
328
+		}
329
+		if (is_array($params[0])) {
330
+			$this->args += $params[0];
331
+		} elseif (is_array($params[1])) {
332
+			$this->args += $params[1];
333
+		}
334
+		if (!isset($this->args['is_public'])) {
335
+			$this->args['is_public'] = false;
336
+		}
337
+	}
338
+
339
+	/**
340
+	 * @param string $value
341
+	 * @return void
342
+	 */
343
+	protected function setNameOrTextAttributeForTag($value)
344
+	{
345
+		$attribute = in_array($this->tag, static::TAGS_FORM)
346
+			? 'name'
347
+			: 'text';
348
+		$this->args[$attribute] = $value;
349
+	}
350
+
351
+	/**
352
+	 * @param string $method
353
+	 * @return void
354
+	 */
355
+	protected function setTagFromMethod($method)
356
+	{
357
+		$this->tag = strtolower($method);
358
+		if (in_array($this->tag, static::INPUT_TYPES)) {
359
+			$this->args['type'] = $this->tag;
360
+			$this->tag = 'input';
361
+		}
362
+	}
363 363
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/ReviewsHtml.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -7,135 +7,135 @@
 block discarded – undo
7 7
 
8 8
 class ReviewsHtml extends ArrayObject
9 9
 {
10
-    /**
11
-     * @var array
12
-     */
13
-    public $args;
10
+	/**
11
+	 * @var array
12
+	 */
13
+	public $args;
14 14
 
15
-    /**
16
-     * @var int
17
-     */
18
-    public $max_num_pages;
15
+	/**
16
+	 * @var int
17
+	 */
18
+	public $max_num_pages;
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    public $pagination;
20
+	/**
21
+	 * @var string
22
+	 */
23
+	public $pagination;
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    public $reviews;
25
+	/**
26
+	 * @var array
27
+	 */
28
+	public $reviews;
29 29
 
30
-    public function __construct(array $reviews, $maxPageCount, array $args)
31
-    {
32
-        $this->args = $args;
33
-        $this->max_num_pages = $maxPageCount;
34
-        $this->reviews = $reviews;
35
-        $this->pagination = $this->buildPagination();
36
-        parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
37
-    }
30
+	public function __construct(array $reviews, $maxPageCount, array $args)
31
+	{
32
+		$this->args = $args;
33
+		$this->max_num_pages = $maxPageCount;
34
+		$this->reviews = $reviews;
35
+		$this->pagination = $this->buildPagination();
36
+		parent::__construct($reviews, ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
37
+	}
38 38
 
39
-    /**
40
-     * @return string
41
-     */
42
-    public function __toString()
43
-    {
44
-        return glsr(Template::class)->build('templates/reviews', [
45
-            'args' => $this->args,
46
-            'context' => [
47
-                'assigned_to' => $this->args['assigned_to'],
48
-                'category' => $this->args['category'],
49
-                'class' => $this->getClass(),
50
-                'id' => $this->args['id'],
51
-                'pagination' => $this->getPagination(),
52
-                'reviews' => $this->getReviews(),
53
-            ],
54
-        ]);
55
-    }
39
+	/**
40
+	 * @return string
41
+	 */
42
+	public function __toString()
43
+	{
44
+		return glsr(Template::class)->build('templates/reviews', [
45
+			'args' => $this->args,
46
+			'context' => [
47
+				'assigned_to' => $this->args['assigned_to'],
48
+				'category' => $this->args['category'],
49
+				'class' => $this->getClass(),
50
+				'id' => $this->args['id'],
51
+				'pagination' => $this->getPagination(),
52
+				'reviews' => $this->getReviews(),
53
+			],
54
+		]);
55
+	}
56 56
 
57
-    /**
58
-     * @return string
59
-     */
60
-    public function getPagination()
61
-    {
62
-        return wp_validate_boolean($this->args['pagination'])
63
-            ? $this->pagination
64
-            : '';
65
-    }
57
+	/**
58
+	 * @return string
59
+	 */
60
+	public function getPagination()
61
+	{
62
+		return wp_validate_boolean($this->args['pagination'])
63
+			? $this->pagination
64
+			: '';
65
+	}
66 66
 
67
-    /**
68
-     * @return string
69
-     */
70
-    public function getReviews()
71
-    {
72
-        $html = empty($this->reviews)
73
-            ? $this->getReviewsFallback()
74
-            : implode(PHP_EOL, $this->reviews);
75
-        $wrapper = '<div class="glsr-reviews">%s</div>';
76
-        $wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper);
77
-        return sprintf($wrapper, $html);
78
-    }
67
+	/**
68
+	 * @return string
69
+	 */
70
+	public function getReviews()
71
+	{
72
+		$html = empty($this->reviews)
73
+			? $this->getReviewsFallback()
74
+			: implode(PHP_EOL, $this->reviews);
75
+		$wrapper = '<div class="glsr-reviews">%s</div>';
76
+		$wrapper = apply_filters('site-reviews/reviews/reviews-wrapper', $wrapper);
77
+		return sprintf($wrapper, $html);
78
+	}
79 79
 
80
-    /**
81
-     * @param mixed $key
82
-     * @return mixed
83
-     */
84
-    public function offsetGet($key)
85
-    {
86
-        if ('navigation' == $key) {
87
-            glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
88
-            return $this->pagination;
89
-        }
90
-        if (property_exists($this, $key)) {
91
-            return $this->{$key};
92
-        }
93
-        return array_key_exists($key, $this->reviews)
94
-            ? $this->reviews[$key]
95
-            : null;
96
-    }
80
+	/**
81
+	 * @param mixed $key
82
+	 * @return mixed
83
+	 */
84
+	public function offsetGet($key)
85
+	{
86
+		if ('navigation' == $key) {
87
+			glsr()->deprecated[] = 'The $reviewsHtml->navigation property has been been deprecated. Please use the $reviewsHtml->pagination property instead.';
88
+			return $this->pagination;
89
+		}
90
+		if (property_exists($this, $key)) {
91
+			return $this->{$key};
92
+		}
93
+		return array_key_exists($key, $this->reviews)
94
+			? $this->reviews[$key]
95
+			: null;
96
+	}
97 97
 
98
-    /**
99
-     * @return string
100
-     */
101
-    protected function buildPagination()
102
-    {
103
-        $html = glsr(Partial::class)->build('pagination', [
104
-            'baseUrl' => glsr_get($this->args, 'pagedUrl'),
105
-            'current' => glsr_get($this->args, 'paged'),
106
-            'total' => $this->max_num_pages,
107
-        ]);
108
-        $html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']);
109
-        $wrapper = '<div class="glsr-pagination">%s</div>';
110
-        $wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper);
111
-        return sprintf($wrapper, $html);
112
-    }
98
+	/**
99
+	 * @return string
100
+	 */
101
+	protected function buildPagination()
102
+	{
103
+		$html = glsr(Partial::class)->build('pagination', [
104
+			'baseUrl' => glsr_get($this->args, 'pagedUrl'),
105
+			'current' => glsr_get($this->args, 'paged'),
106
+			'total' => $this->max_num_pages,
107
+		]);
108
+		$html.= sprintf('<glsr-pagination hidden data-atts=\'%s\'></glsr-pagination>', $this->args['json']);
109
+		$wrapper = '<div class="glsr-pagination">%s</div>';
110
+		$wrapper = apply_filters('site-reviews/reviews/pagination-wrapper', $wrapper);
111
+		return sprintf($wrapper, $html);
112
+	}
113 113
 
114
-    /**
115
-     * @return string
116
-     */
117
-    protected function getClass()
118
-    {
119
-        $defaults = [
120
-            'glsr-default',
121
-        ];
122
-        if ('ajax' == $this->args['pagination']) {
123
-            $defaults[] = 'glsr-ajax-pagination';
124
-        }
125
-        $classes = explode(' ', $this->args['class']);
126
-        $classes = array_unique(array_merge($defaults, array_filter($classes)));
127
-        return implode(' ', $classes);
128
-    }
114
+	/**
115
+	 * @return string
116
+	 */
117
+	protected function getClass()
118
+	{
119
+		$defaults = [
120
+			'glsr-default',
121
+		];
122
+		if ('ajax' == $this->args['pagination']) {
123
+			$defaults[] = 'glsr-ajax-pagination';
124
+		}
125
+		$classes = explode(' ', $this->args['class']);
126
+		$classes = array_unique(array_merge($defaults, array_filter($classes)));
127
+		return implode(' ', $classes);
128
+	}
129 129
 
130
-    /**
131
-     * @return string
132
-     */
133
-    protected function getReviewsFallback()
134
-    {
135
-        if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
136
-            $this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
137
-        }
138
-        $fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
139
-        return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
140
-    }
130
+	/**
131
+	 * @return string
132
+	 */
133
+	protected function getReviewsFallback()
134
+	{
135
+		if (empty($this->args['fallback']) && glsr(OptionManager::class)->getBool('settings.reviews.fallback')) {
136
+			$this->args['fallback'] = __('There are no reviews yet. Be the first one to write one.', 'site-reviews');
137
+		}
138
+		$fallback = '<p class="glsr-no-margins">'.$this->args['fallback'].'</p>';
139
+		return apply_filters('site-reviews/reviews/fallback', $fallback, $this->args);
140
+	}
141 141
 }
Please login to merge, or discard this patch.
plugin/Modules/Notice.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -8,114 +8,114 @@
 block discarded – undo
8 8
 
9 9
 class Notice
10 10
 {
11
-    /**
12
-     * @param string $type
13
-     * @param string|array|WP_Error $message
14
-     * @return void
15
-     */
16
-    public function add($type, $message, array $args = [])
17
-    {
18
-        if (empty(array_filter([$message, $type]))) {
19
-            return;
20
-        }
21
-        $args['message'] = $message;
22
-        $args['type'] = $type;
23
-        add_settings_error(Application::ID, '', json_encode($this->normalize($args)));
24
-    }
11
+	/**
12
+	 * @param string $type
13
+	 * @param string|array|WP_Error $message
14
+	 * @return void
15
+	 */
16
+	public function add($type, $message, array $args = [])
17
+	{
18
+		if (empty(array_filter([$message, $type]))) {
19
+			return;
20
+		}
21
+		$args['message'] = $message;
22
+		$args['type'] = $type;
23
+		add_settings_error(Application::ID, '', json_encode($this->normalize($args)));
24
+	}
25 25
 
26
-    /**
27
-     * @param string|array|WP_Error $message
28
-     * @return void
29
-     */
30
-    public function addError($message, array $args = [])
31
-    {
32
-        $this->add('error', $message, $args);
33
-    }
26
+	/**
27
+	 * @param string|array|WP_Error $message
28
+	 * @return void
29
+	 */
30
+	public function addError($message, array $args = [])
31
+	{
32
+		$this->add('error', $message, $args);
33
+	}
34 34
 
35
-    /**
36
-     * @param string|array|WP_Error $message
37
-     * @return void
38
-     */
39
-    public function addSuccess($message, array $args = [])
40
-    {
41
-        $this->add('success', $message, $args);
42
-    }
35
+	/**
36
+	 * @param string|array|WP_Error $message
37
+	 * @return void
38
+	 */
39
+	public function addSuccess($message, array $args = [])
40
+	{
41
+		$this->add('success', $message, $args);
42
+	}
43 43
 
44
-    /**
45
-     * @param string|array|WP_Error $message
46
-     * @return void
47
-     */
48
-    public function addWarning($message, array $args = [])
49
-    {
50
-        $this->add('warning', $message, $args);
51
-    }
44
+	/**
45
+	 * @param string|array|WP_Error $message
46
+	 * @return void
47
+	 */
48
+	public function addWarning($message, array $args = [])
49
+	{
50
+		$this->add('warning', $message, $args);
51
+	}
52 52
 
53
-    /**
54
-     * @return static
55
-     */
56
-    public function clear()
57
-    {
58
-        global $wp_settings_errors;
59
-        $wp_settings_errors = [];
60
-        delete_transient('settings_errors');
61
-        return $this;
62
-    }
53
+	/**
54
+	 * @return static
55
+	 */
56
+	public function clear()
57
+	{
58
+		global $wp_settings_errors;
59
+		$wp_settings_errors = [];
60
+		delete_transient('settings_errors');
61
+		return $this;
62
+	}
63 63
 
64
-    /**
65
-     * @return string
66
-     */
67
-    public function get()
68
-    {
69
-        $notices = array_map('unserialize',
70
-            array_unique(array_map('serialize', get_settings_errors(Application::ID)))
71
-        );
72
-        if (empty($notices)) {
73
-            return;
74
-        }
75
-        return array_reduce($notices, function ($carry, $notice) {
76
-            return $carry.$this->buildNotice(json_decode($notice['message'], true));
77
-        });
78
-    }
64
+	/**
65
+	 * @return string
66
+	 */
67
+	public function get()
68
+	{
69
+		$notices = array_map('unserialize',
70
+			array_unique(array_map('serialize', get_settings_errors(Application::ID)))
71
+		);
72
+		if (empty($notices)) {
73
+			return;
74
+		}
75
+		return array_reduce($notices, function ($carry, $notice) {
76
+			return $carry.$this->buildNotice(json_decode($notice['message'], true));
77
+		});
78
+	}
79 79
 
80
-    /**
81
-     * @return string
82
-     */
83
-    protected function buildNotice(array $args)
84
-    {
85
-        $messages = array_reduce($args['messages'], function ($carry, $message) {
86
-            return $carry.glsr(Builder::class)->p($message);
87
-        });
88
-        $class = 'notice notice-'.$args['type'];
89
-        if ($args['inline']) {
90
-            $class.= ' inline';
91
-        }
92
-        if ($args['dismissible']) {
93
-            $class.= ' is-dismissible';
94
-        }
95
-        return glsr(Builder::class)->div($messages, [
96
-            'class' => $class,
97
-        ]);
98
-    }
80
+	/**
81
+	 * @return string
82
+	 */
83
+	protected function buildNotice(array $args)
84
+	{
85
+		$messages = array_reduce($args['messages'], function ($carry, $message) {
86
+			return $carry.glsr(Builder::class)->p($message);
87
+		});
88
+		$class = 'notice notice-'.$args['type'];
89
+		if ($args['inline']) {
90
+			$class.= ' inline';
91
+		}
92
+		if ($args['dismissible']) {
93
+			$class.= ' is-dismissible';
94
+		}
95
+		return glsr(Builder::class)->div($messages, [
96
+			'class' => $class,
97
+		]);
98
+	}
99 99
 
100
-    /**
101
-     * @return array
102
-     */
103
-    protected function normalize(array $args)
104
-    {
105
-        $defaults = [
106
-            'dismissible' => true,
107
-            'inline' => true,
108
-            'message' => '',
109
-            'type' => '',
110
-        ];
111
-        $args = shortcode_atts($defaults, $args);
112
-        if (!in_array($args['type'], ['error', 'warning', 'success'])) {
113
-            $args['type'] = 'success';
114
-        }
115
-        $args['messages'] = is_wp_error($args['message'])
116
-            ? (array) $args['message']->get_error_message()
117
-            : (array) $args['message'];
118
-        unset($args['message']);
119
-        return $args;
120
-    }
100
+	/**
101
+	 * @return array
102
+	 */
103
+	protected function normalize(array $args)
104
+	{
105
+		$defaults = [
106
+			'dismissible' => true,
107
+			'inline' => true,
108
+			'message' => '',
109
+			'type' => '',
110
+		];
111
+		$args = shortcode_atts($defaults, $args);
112
+		if (!in_array($args['type'], ['error', 'warning', 'success'])) {
113
+			$args['type'] = 'success';
114
+		}
115
+		$args['messages'] = is_wp_error($args['message'])
116
+			? (array) $args['message']->get_error_message()
117
+			: (array) $args['message'];
118
+		unset($args['message']);
119
+		return $args;
120
+	}
121 121
 }
Please login to merge, or discard this patch.
plugin/Modules/Translation.php 1 patch
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -10,272 +10,272 @@
 block discarded – undo
10 10
 
11 11
 class Translation
12 12
 {
13
-    const SEARCH_THRESHOLD = 3;
13
+	const SEARCH_THRESHOLD = 3;
14 14
 
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $entries;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $entries;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $results;
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $results;
24 24
 
25
-    /**
26
-     * Returns all saved custom translations with translation context.
27
-     * @return array
28
-     */
29
-    public function all()
30
-    {
31
-        $translations = $this->translations();
32
-        $entries = $this->filter($translations, $this->entries())->results();
33
-        array_walk($translations, function (&$entry) use ($entries) {
34
-            $entry['desc'] = array_key_exists($entry['id'], $entries)
35
-                ? $this->getEntryString($entries[$entry['id']], 'msgctxt')
36
-                : '';
37
-        });
38
-        return $translations;
39
-    }
25
+	/**
26
+	 * Returns all saved custom translations with translation context.
27
+	 * @return array
28
+	 */
29
+	public function all()
30
+	{
31
+		$translations = $this->translations();
32
+		$entries = $this->filter($translations, $this->entries())->results();
33
+		array_walk($translations, function (&$entry) use ($entries) {
34
+			$entry['desc'] = array_key_exists($entry['id'], $entries)
35
+				? $this->getEntryString($entries[$entry['id']], 'msgctxt')
36
+				: '';
37
+		});
38
+		return $translations;
39
+	}
40 40
 
41
-    /**
42
-     * @return array
43
-     */
44
-    public function entries()
45
-    {
46
-        if (!isset($this->entries)) {
47
-            $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot');
48
-            $entries = $this->extractEntriesFromPotFile($potFile);
49
-            $entries = apply_filters('site-reviews/translation/entries', $entries);
50
-            $this->entries = $entries;
51
-        }
52
-        return $this->entries;
53
-    }
41
+	/**
42
+	 * @return array
43
+	 */
44
+	public function entries()
45
+	{
46
+		if (!isset($this->entries)) {
47
+			$potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot');
48
+			$entries = $this->extractEntriesFromPotFile($potFile);
49
+			$entries = apply_filters('site-reviews/translation/entries', $entries);
50
+			$this->entries = $entries;
51
+		}
52
+		return $this->entries;
53
+	}
54 54
 
55
-    /**
56
-     * @param array|null $entriesToExclude
57
-     * @param array|null $entries
58
-     * @return static
59
-     */
60
-    public function exclude($entriesToExclude = null, $entries = null)
61
-    {
62
-        return $this->filter($entriesToExclude, $entries, false);
63
-    }
55
+	/**
56
+	 * @param array|null $entriesToExclude
57
+	 * @param array|null $entries
58
+	 * @return static
59
+	 */
60
+	public function exclude($entriesToExclude = null, $entries = null)
61
+	{
62
+		return $this->filter($entriesToExclude, $entries, false);
63
+	}
64 64
 
65
-    /**
66
-     * @param string $potFile
67
-     * @return array
68
-     */
69
-    public function extractEntriesFromPotFile($potFile, array $entries = [])
70
-    {
71
-        try {
72
-            $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries());
73
-            foreach ($potEntries as $key => $entry) {
74
-                $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
75
-            }
76
-        } catch (Exception $e) {
77
-            glsr_log()->error($e->getMessage());
78
-        }
79
-        return $entries;
80
-    }
65
+	/**
66
+	 * @param string $potFile
67
+	 * @return array
68
+	 */
69
+	public function extractEntriesFromPotFile($potFile, array $entries = [])
70
+	{
71
+		try {
72
+			$potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries());
73
+			foreach ($potEntries as $key => $entry) {
74
+				$entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
75
+			}
76
+		} catch (Exception $e) {
77
+			glsr_log()->error($e->getMessage());
78
+		}
79
+		return $entries;
80
+	}
81 81
 
82
-    /**
83
-     * @param array|null $filterWith
84
-     * @param array|null $entries
85
-     * @param bool $intersect
86
-     * @return static
87
-     */
88
-    public function filter($filterWith = null, $entries = null, $intersect = true)
89
-    {
90
-        if (!is_array($entries)) {
91
-            $entries = $this->results;
92
-        }
93
-        if (!is_array($filterWith)) {
94
-            $filterWith = $this->translations();
95
-        }
96
-        $keys = array_flip(glsr_array_column($filterWith, 'id'));
97
-        $this->results = $intersect
98
-            ? array_intersect_key($entries, $keys)
99
-            : array_diff_key($entries, $keys);
100
-        return $this;
101
-    }
82
+	/**
83
+	 * @param array|null $filterWith
84
+	 * @param array|null $entries
85
+	 * @param bool $intersect
86
+	 * @return static
87
+	 */
88
+	public function filter($filterWith = null, $entries = null, $intersect = true)
89
+	{
90
+		if (!is_array($entries)) {
91
+			$entries = $this->results;
92
+		}
93
+		if (!is_array($filterWith)) {
94
+			$filterWith = $this->translations();
95
+		}
96
+		$keys = array_flip(glsr_array_column($filterWith, 'id'));
97
+		$this->results = $intersect
98
+			? array_intersect_key($entries, $keys)
99
+			: array_diff_key($entries, $keys);
100
+		return $this;
101
+	}
102 102
 
103
-    /**
104
-     * @param string $template
105
-     * @return string
106
-     */
107
-    public function render($template, array $entry)
108
-    {
109
-        $data = array_combine(
110
-            array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)),
111
-            $entry
112
-        );
113
-        $data['data.class'] = $data['data.error'] = '';
114
-        if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) {
115
-            $data['data.class'] = 'is-invalid';
116
-            $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews');
117
-        }
118
-        return glsr(Template::class)->build('partials/translations/'.$template, [
119
-            'context' => $data,
120
-        ]);
121
-    }
103
+	/**
104
+	 * @param string $template
105
+	 * @return string
106
+	 */
107
+	public function render($template, array $entry)
108
+	{
109
+		$data = array_combine(
110
+			array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)),
111
+			$entry
112
+		);
113
+		$data['data.class'] = $data['data.error'] = '';
114
+		if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) {
115
+			$data['data.class'] = 'is-invalid';
116
+			$data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews');
117
+		}
118
+		return glsr(Template::class)->build('partials/translations/'.$template, [
119
+			'context' => $data,
120
+		]);
121
+	}
122 122
 
123
-    /**
124
-     * Returns a rendered string of all saved custom translations with translation context.
125
-     * @return string
126
-     */
127
-    public function renderAll()
128
-    {
129
-        $rendered = '';
130
-        foreach ($this->all() as $index => $entry) {
131
-            $entry['index'] = $index;
132
-            $entry['prefix'] = OptionManager::databaseKey();
133
-            $rendered.= $this->render($entry['type'], $entry);
134
-        }
135
-        return $rendered;
136
-    }
123
+	/**
124
+	 * Returns a rendered string of all saved custom translations with translation context.
125
+	 * @return string
126
+	 */
127
+	public function renderAll()
128
+	{
129
+		$rendered = '';
130
+		foreach ($this->all() as $index => $entry) {
131
+			$entry['index'] = $index;
132
+			$entry['prefix'] = OptionManager::databaseKey();
133
+			$rendered.= $this->render($entry['type'], $entry);
134
+		}
135
+		return $rendered;
136
+	}
137 137
 
138
-    /**
139
-     * @param bool $resetAfterRender
140
-     * @return string
141
-     */
142
-    public function renderResults($resetAfterRender = true)
143
-    {
144
-        $rendered = '';
145
-        foreach ($this->results as $id => $entry) {
146
-            $data = [
147
-                'desc' => $this->getEntryString($entry, 'msgctxt'),
148
-                'id' => $id,
149
-                'p1' => $this->getEntryString($entry, 'msgid_plural'),
150
-                's1' => $this->getEntryString($entry, 'msgid'),
151
-            ];
152
-            $text = !empty($data['p1'])
153
-                ? sprintf('%s | %s', $data['s1'], $data['p1'])
154
-                : $data['s1'];
155
-            $rendered.= $this->render('result', [
156
-                'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
157
-                'text' => wp_strip_all_tags($text),
158
-            ]);
159
-        }
160
-        if ($resetAfterRender) {
161
-            $this->reset();
162
-        }
163
-        return $rendered;
164
-    }
138
+	/**
139
+	 * @param bool $resetAfterRender
140
+	 * @return string
141
+	 */
142
+	public function renderResults($resetAfterRender = true)
143
+	{
144
+		$rendered = '';
145
+		foreach ($this->results as $id => $entry) {
146
+			$data = [
147
+				'desc' => $this->getEntryString($entry, 'msgctxt'),
148
+				'id' => $id,
149
+				'p1' => $this->getEntryString($entry, 'msgid_plural'),
150
+				's1' => $this->getEntryString($entry, 'msgid'),
151
+			];
152
+			$text = !empty($data['p1'])
153
+				? sprintf('%s | %s', $data['s1'], $data['p1'])
154
+				: $data['s1'];
155
+			$rendered.= $this->render('result', [
156
+				'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
157
+				'text' => wp_strip_all_tags($text),
158
+			]);
159
+		}
160
+		if ($resetAfterRender) {
161
+			$this->reset();
162
+		}
163
+		return $rendered;
164
+	}
165 165
 
166
-    /**
167
-     * @return void
168
-     */
169
-    public function reset()
170
-    {
171
-        $this->results = [];
172
-    }
166
+	/**
167
+	 * @return void
168
+	 */
169
+	public function reset()
170
+	{
171
+		$this->results = [];
172
+	}
173 173
 
174
-    /**
175
-     * @return array
176
-     */
177
-    public function results()
178
-    {
179
-        $results = $this->results;
180
-        $this->reset();
181
-        return $results;
182
-    }
174
+	/**
175
+	 * @return array
176
+	 */
177
+	public function results()
178
+	{
179
+		$results = $this->results;
180
+		$this->reset();
181
+		return $results;
182
+	}
183 183
 
184
-    /**
185
-     * @param string $needle
186
-     * @return static
187
-     */
188
-    public function search($needle = '')
189
-    {
190
-        $this->reset();
191
-        $needle = trim(strtolower($needle));
192
-        foreach ($this->entries() as $key => $entry) {
193
-            $single = strtolower($this->getEntryString($entry, 'msgid'));
194
-            $plural = strtolower($this->getEntryString($entry, 'msgid_plural'));
195
-            if (strlen($needle) < static::SEARCH_THRESHOLD) {
196
-                if (in_array($needle, [$single, $plural])) {
197
-                    $this->results[$key] = $entry;
198
-                }
199
-            } elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) {
200
-                $this->results[$key] = $entry;
201
-            }
202
-        }
203
-        return $this;
204
-    }
184
+	/**
185
+	 * @param string $needle
186
+	 * @return static
187
+	 */
188
+	public function search($needle = '')
189
+	{
190
+		$this->reset();
191
+		$needle = trim(strtolower($needle));
192
+		foreach ($this->entries() as $key => $entry) {
193
+			$single = strtolower($this->getEntryString($entry, 'msgid'));
194
+			$plural = strtolower($this->getEntryString($entry, 'msgid_plural'));
195
+			if (strlen($needle) < static::SEARCH_THRESHOLD) {
196
+				if (in_array($needle, [$single, $plural])) {
197
+					$this->results[$key] = $entry;
198
+				}
199
+			} elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) {
200
+				$this->results[$key] = $entry;
201
+			}
202
+		}
203
+		return $this;
204
+	}
205 205
 
206
-    /**
207
-     * Store the translations to avoid unnecessary loops.
208
-     * @return array
209
-     */
210
-    public function translations()
211
-    {
212
-        static $translations;
213
-        if (empty($translations)) {
214
-            $settings = glsr(OptionManager::class)->get('settings');
215
-            $translations = isset($settings['strings'])
216
-                ? $this->normalizeSettings((array) $settings['strings'])
217
-                : [];
218
-        }
219
-        return $translations;
220
-    }
206
+	/**
207
+	 * Store the translations to avoid unnecessary loops.
208
+	 * @return array
209
+	 */
210
+	public function translations()
211
+	{
212
+		static $translations;
213
+		if (empty($translations)) {
214
+			$settings = glsr(OptionManager::class)->get('settings');
215
+			$translations = isset($settings['strings'])
216
+				? $this->normalizeSettings((array) $settings['strings'])
217
+				: [];
218
+		}
219
+		return $translations;
220
+	}
221 221
 
222
-    /**
223
-     * @param string $key
224
-     * @return string
225
-     */
226
-    protected function getEntryString(array $entry, $key)
227
-    {
228
-        return isset($entry[$key])
229
-            ? implode('', (array) $entry[$key])
230
-            : '';
231
-    }
222
+	/**
223
+	 * @param string $key
224
+	 * @return string
225
+	 */
226
+	protected function getEntryString(array $entry, $key)
227
+	{
228
+		return isset($entry[$key])
229
+			? implode('', (array) $entry[$key])
230
+			: '';
231
+	}
232 232
 
233
-    /**
234
-     * @return array
235
-     */
236
-    protected function normalize(array $entries)
237
-    {
238
-        $keys = [
239
-            'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
240
-        ];
241
-        array_walk($entries, function (&$entry) use ($keys) {
242
-            foreach ($keys as $key) {
243
-                try {
244
-                    $entry = $this->normalizeEntryString($entry, $key);
245
-                } catch (\TypeError $error) {
246
-                    glsr_log()->once('error', 'Translation/normalize', $error);
247
-                    glsr_log()->once('debug', 'Translation/normalize', $entry);
248
-                }
249
-            }
250
-        });
251
-        return $entries;
252
-    }
233
+	/**
234
+	 * @return array
235
+	 */
236
+	protected function normalize(array $entries)
237
+	{
238
+		$keys = [
239
+			'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
240
+		];
241
+		array_walk($entries, function (&$entry) use ($keys) {
242
+			foreach ($keys as $key) {
243
+				try {
244
+					$entry = $this->normalizeEntryString($entry, $key);
245
+				} catch (\TypeError $error) {
246
+					glsr_log()->once('error', 'Translation/normalize', $error);
247
+					glsr_log()->once('debug', 'Translation/normalize', $entry);
248
+				}
249
+			}
250
+		});
251
+		return $entries;
252
+	}
253 253
 
254
-    /**
255
-     * @param string $key
256
-     * @return array
257
-     */
258
-    protected function normalizeEntryString(array $entry, $key)
259
-    {
260
-        if (isset($entry[$key])) {
261
-            $entry[$key] = $this->getEntryString($entry, $key);
262
-        }
263
-        return $entry;
264
-    }
254
+	/**
255
+	 * @param string $key
256
+	 * @return array
257
+	 */
258
+	protected function normalizeEntryString(array $entry, $key)
259
+	{
260
+		if (isset($entry[$key])) {
261
+			$entry[$key] = $this->getEntryString($entry, $key);
262
+		}
263
+		return $entry;
264
+	}
265 265
 
266
-    /**
267
-     * @return array
268
-     */
269
-    protected function normalizeSettings(array $strings)
270
-    {
271
-        $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
272
-        $strings = array_filter($strings, 'is_array');
273
-        foreach ($strings as &$string) {
274
-            $string['type'] = isset($string['p1']) ? 'plural' : 'single';
275
-            $string = wp_parse_args($string, $defaultString);
276
-        }
277
-        return array_filter($strings, function ($string) {
278
-            return !empty($string['id']);
279
-        });
280
-    }
266
+	/**
267
+	 * @return array
268
+	 */
269
+	protected function normalizeSettings(array $strings)
270
+	{
271
+		$defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
272
+		$strings = array_filter($strings, 'is_array');
273
+		foreach ($strings as &$string) {
274
+			$string['type'] = isset($string['p1']) ? 'plural' : 'single';
275
+			$string = wp_parse_args($string, $defaultString);
276
+		}
277
+		return array_filter($strings, function ($string) {
278
+			return !empty($string['id']);
279
+		});
280
+	}
281 281
 }
Please login to merge, or discard this patch.
plugin/Modules/Schema.php 1 patch
Indentation   +271 added lines, -271 removed lines patch added patch discarded remove patch
@@ -12,295 +12,295 @@
 block discarded – undo
12 12
 
13 13
 class Schema
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $args;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $args;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $ratingCounts;
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $ratingCounts;
24 24
 
25
-    /**
26
-     * @return array
27
-     */
28
-    public function build(array $args = [])
29
-    {
30
-        $this->args = $args;
31
-        $schema = $this->buildSummary($args);
32
-        $reviews = [];
33
-        foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
34
-            // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
35
-            // @see https://developers.google.com/search/docs/data-types/review
36
-            if ('local' != $review->review_type) {
37
-                continue;
38
-            }
39
-            $reviews[] = $this->buildReview($review);
40
-        }
41
-        if (!empty($reviews)) {
42
-            array_walk($reviews, function (&$review) {
43
-                unset($review['@context']);
44
-                unset($review['itemReviewed']);
45
-            });
46
-            $schema['review'] = $reviews;
47
-        }
48
-        return $schema;
49
-    }
25
+	/**
26
+	 * @return array
27
+	 */
28
+	public function build(array $args = [])
29
+	{
30
+		$this->args = $args;
31
+		$schema = $this->buildSummary($args);
32
+		$reviews = [];
33
+		foreach (glsr(ReviewManager::class)->get($this->args) as $review) {
34
+			// Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews.
35
+			// @see https://developers.google.com/search/docs/data-types/review
36
+			if ('local' != $review->review_type) {
37
+				continue;
38
+			}
39
+			$reviews[] = $this->buildReview($review);
40
+		}
41
+		if (!empty($reviews)) {
42
+			array_walk($reviews, function (&$review) {
43
+				unset($review['@context']);
44
+				unset($review['itemReviewed']);
45
+			});
46
+			$schema['review'] = $reviews;
47
+		}
48
+		return $schema;
49
+	}
50 50
 
51
-    /**
52
-     * @param array|null $args
53
-     * @return array
54
-     */
55
-    public function buildSummary($args = null)
56
-    {
57
-        if (is_array($args)) {
58
-            $this->args = $args;
59
-        }
60
-        $buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
61
-        $count = array_sum($this->getRatingCounts());
62
-        $schema = method_exists($this, $buildSummary)
63
-            ? $this->$buildSummary()
64
-            : $this->buildSummaryForCustom();
65
-        if (!empty($count)) {
66
-            $schema->aggregateRating(
67
-                $this->getSchemaType('AggregateRating')
68
-                    ->ratingValue($this->getRatingValue())
69
-                    ->reviewCount($count)
70
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
71
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
72
-            );
73
-        }
74
-        $schema = $schema->toArray();
75
-        return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
76
-    }
51
+	/**
52
+	 * @param array|null $args
53
+	 * @return array
54
+	 */
55
+	public function buildSummary($args = null)
56
+	{
57
+		if (is_array($args)) {
58
+			$this->args = $args;
59
+		}
60
+		$buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor');
61
+		$count = array_sum($this->getRatingCounts());
62
+		$schema = method_exists($this, $buildSummary)
63
+			? $this->$buildSummary()
64
+			: $this->buildSummaryForCustom();
65
+		if (!empty($count)) {
66
+			$schema->aggregateRating(
67
+				$this->getSchemaType('AggregateRating')
68
+					->ratingValue($this->getRatingValue())
69
+					->reviewCount($count)
70
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
71
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
72
+			);
73
+		}
74
+		$schema = $schema->toArray();
75
+		return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args);
76
+	}
77 77
 
78
-    /**
79
-     * @return void
80
-     */
81
-    public function render()
82
-    {
83
-        if (empty(glsr()->schemas)) {
84
-            return;
85
-        }
86
-        printf('<script type="application/ld+json">%s</script>', json_encode(
87
-            apply_filters('site-reviews/schema/all', glsr()->schemas),
88
-            JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
89
-        ));
90
-    }
78
+	/**
79
+	 * @return void
80
+	 */
81
+	public function render()
82
+	{
83
+		if (empty(glsr()->schemas)) {
84
+			return;
85
+		}
86
+		printf('<script type="application/ld+json">%s</script>', json_encode(
87
+			apply_filters('site-reviews/schema/all', glsr()->schemas),
88
+			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
89
+		));
90
+	}
91 91
 
92
-    /**
93
-     * @return void
94
-     */
95
-    public function store(array $schema)
96
-    {
97
-        $schemas = glsr()->schemas;
98
-        $schemas[] = $schema;
99
-        glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
100
-    }
92
+	/**
93
+	 * @return void
94
+	 */
95
+	public function store(array $schema)
96
+	{
97
+		$schemas = glsr()->schemas;
98
+		$schemas[] = $schema;
99
+		glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas)));
100
+	}
101 101
 
102
-    /**
103
-     * @param Review $review
104
-     * @return array
105
-     */
106
-    protected function buildReview($review)
107
-    {
108
-        $schema = $this->getSchemaType('Review')
109
-            ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
110
-                $schema->name($review->title);
111
-            })
112
-            ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
113
-                $schema->reviewBody($review->content);
114
-            })
115
-            ->datePublished((new DateTime($review->date)))
116
-            ->author($this->getSchemaType('Person')->name($review->author))
117
-            ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
118
-        if (!empty($review->rating)) {
119
-            $schema->reviewRating(
120
-                $this->getSchemaType('Rating')
121
-                    ->ratingValue($review->rating)
122
-                    ->bestRating(glsr()->constant('MAX_RATING', Rating::class))
123
-                    ->worstRating(glsr()->constant('MIN_RATING', Rating::class))
124
-            );
125
-        }
126
-        return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
127
-    }
102
+	/**
103
+	 * @param Review $review
104
+	 * @return array
105
+	 */
106
+	protected function buildReview($review)
107
+	{
108
+		$schema = $this->getSchemaType('Review')
109
+			->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) {
110
+				$schema->name($review->title);
111
+			})
112
+			->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) {
113
+				$schema->reviewBody($review->content);
114
+			})
115
+			->datePublished((new DateTime($review->date)))
116
+			->author($this->getSchemaType('Person')->name($review->author))
117
+			->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name')));
118
+		if (!empty($review->rating)) {
119
+			$schema->reviewRating(
120
+				$this->getSchemaType('Rating')
121
+					->ratingValue($review->rating)
122
+					->bestRating(glsr()->constant('MAX_RATING', Rating::class))
123
+					->worstRating(glsr()->constant('MIN_RATING', Rating::class))
124
+			);
125
+		}
126
+		return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args);
127
+	}
128 128
 
129
-    /**
130
-     * @param mixed $schema
131
-     * @return mixed
132
-     */
133
-    protected function buildSchemaValues($schema, array $values = [])
134
-    {
135
-        foreach ($values as $value) {
136
-            $option = $this->getSchemaOptionValue($value);
137
-            if (empty($option)) {
138
-                continue;
139
-            }
140
-            $schema->$value($option);
141
-        }
142
-        return $schema;
143
-    }
129
+	/**
130
+	 * @param mixed $schema
131
+	 * @return mixed
132
+	 */
133
+	protected function buildSchemaValues($schema, array $values = [])
134
+	{
135
+		foreach ($values as $value) {
136
+			$option = $this->getSchemaOptionValue($value);
137
+			if (empty($option)) {
138
+				continue;
139
+			}
140
+			$schema->$value($option);
141
+		}
142
+		return $schema;
143
+	}
144 144
 
145
-    /**
146
-     * @return mixed
147
-     */
148
-    protected function buildSummaryForCustom()
149
-    {
150
-        return $this->buildSchemaValues($this->getSchemaType(), [
151
-            'description', 'image', 'name', 'url',
152
-        ]);
153
-    }
145
+	/**
146
+	 * @return mixed
147
+	 */
148
+	protected function buildSummaryForCustom()
149
+	{
150
+		return $this->buildSchemaValues($this->getSchemaType(), [
151
+			'description', 'image', 'name', 'url',
152
+		]);
153
+	}
154 154
 
155
-    /**
156
-     * @return mixed
157
-     */
158
-    protected function buildSummaryForLocalBusiness()
159
-    {
160
-        return $this->buildSchemaValues($this->buildSummaryForCustom(), [
161
-            'address', 'priceRange', 'telephone',
162
-        ]);
163
-    }
155
+	/**
156
+	 * @return mixed
157
+	 */
158
+	protected function buildSummaryForLocalBusiness()
159
+	{
160
+		return $this->buildSchemaValues($this->buildSummaryForCustom(), [
161
+			'address', 'priceRange', 'telephone',
162
+		]);
163
+	}
164 164
 
165
-    /**
166
-     * @return mixed
167
-     */
168
-    protected function buildSummaryForProduct()
169
-    {
170
-        $offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
171
-        $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
172
-            'highPrice', 'lowPrice', 'price', 'priceCurrency',
173
-        ]);
174
-        return $this->buildSummaryForCustom()
175
-            ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
176
-                $schema->offers($offers);
177
-            })
178
-            ->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
179
-    }
165
+	/**
166
+	 * @return mixed
167
+	 */
168
+	protected function buildSummaryForProduct()
169
+	{
170
+		$offerType = $this->getSchemaOption('offerType', 'AggregateOffer');
171
+		$offers = $this->buildSchemaValues($this->getSchemaType($offerType), [
172
+			'highPrice', 'lowPrice', 'price', 'priceCurrency',
173
+		]);
174
+		return $this->buildSummaryForCustom()
175
+			->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) {
176
+				$schema->offers($offers);
177
+			})
178
+			->setProperty('@id', $this->getSchemaOptionValue('url').'#product');
179
+	}
180 180
 
181
-    /**
182
-     * @return array
183
-     */
184
-    protected function getRatingCounts()
185
-    {
186
-        if (!isset($this->ratingCounts)) {
187
-            $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
188
-        }
189
-        return $this->ratingCounts;
190
-    }
181
+	/**
182
+	 * @return array
183
+	 */
184
+	protected function getRatingCounts()
185
+	{
186
+		if (!isset($this->ratingCounts)) {
187
+			$this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args);
188
+		}
189
+		return $this->ratingCounts;
190
+	}
191 191
 
192
-    /**
193
-     * @return int|float
194
-     */
195
-    protected function getRatingValue()
196
-    {
197
-        return glsr(Rating::class)->getAverage($this->getRatingCounts());
198
-    }
192
+	/**
193
+	 * @return int|float
194
+	 */
195
+	protected function getRatingValue()
196
+	{
197
+		return glsr(Rating::class)->getAverage($this->getRatingCounts());
198
+	}
199 199
 
200
-    /**
201
-     * @param string $option
202
-     * @param string $fallback
203
-     * @return string
204
-     */
205
-    protected function getSchemaOption($option, $fallback)
206
-    {
207
-        $option = strtolower($option);
208
-        if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
209
-            return $schemaOption;
210
-        }
211
-        $setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
212
-        if (is_array($setting)) {
213
-            return $this->getSchemaOptionDefault($setting, $fallback);
214
-        }
215
-        return !empty($setting)
216
-            ? $setting
217
-            : $fallback;
218
-    }
200
+	/**
201
+	 * @param string $option
202
+	 * @param string $fallback
203
+	 * @return string
204
+	 */
205
+	protected function getSchemaOption($option, $fallback)
206
+	{
207
+		$option = strtolower($option);
208
+		if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) {
209
+			return $schemaOption;
210
+		}
211
+		$setting = glsr(OptionManager::class)->get('settings.schema.'.$option);
212
+		if (is_array($setting)) {
213
+			return $this->getSchemaOptionDefault($setting, $fallback);
214
+		}
215
+		return !empty($setting)
216
+			? $setting
217
+			: $fallback;
218
+	}
219 219
 
220
-    /**
221
-     * @param string $fallback
222
-     * @return string
223
-     */
224
-    protected function getSchemaOptionDefault(array $setting, $fallback)
225
-    {
226
-        $setting = wp_parse_args($setting, [
227
-            'custom' => '',
228
-            'default' => $fallback,
229
-        ]);
230
-        return 'custom' != $setting['default']
231
-            ? $setting['default']
232
-            : $setting['custom'];
233
-    }
220
+	/**
221
+	 * @param string $fallback
222
+	 * @return string
223
+	 */
224
+	protected function getSchemaOptionDefault(array $setting, $fallback)
225
+	{
226
+		$setting = wp_parse_args($setting, [
227
+			'custom' => '',
228
+			'default' => $fallback,
229
+		]);
230
+		return 'custom' != $setting['default']
231
+			? $setting['default']
232
+			: $setting['custom'];
233
+	}
234 234
 
235
-    /**
236
-     * @param string $option
237
-     * @param string $fallback
238
-     * @return void|string
239
-     */
240
-    protected function getSchemaOptionValue($option, $fallback = 'post')
241
-    {
242
-        $value = $this->getSchemaOption($option, $fallback);
243
-        if ($value != $fallback) {
244
-            return $value;
245
-        }
246
-        if (!is_single() && !is_page()) {
247
-            return;
248
-        }
249
-        $method = glsr(Helper::class)->buildMethodName($option, 'getThing');
250
-        if (method_exists($this, $method)) {
251
-            return $this->$method();
252
-        }
253
-    }
235
+	/**
236
+	 * @param string $option
237
+	 * @param string $fallback
238
+	 * @return void|string
239
+	 */
240
+	protected function getSchemaOptionValue($option, $fallback = 'post')
241
+	{
242
+		$value = $this->getSchemaOption($option, $fallback);
243
+		if ($value != $fallback) {
244
+			return $value;
245
+		}
246
+		if (!is_single() && !is_page()) {
247
+			return;
248
+		}
249
+		$method = glsr(Helper::class)->buildMethodName($option, 'getThing');
250
+		if (method_exists($this, $method)) {
251
+			return $this->$method();
252
+		}
253
+	}
254 254
 
255
-    /**
256
-     * @param string|null $type
257
-     * @return mixed
258
-     */
259
-    protected function getSchemaType($type = null)
260
-    {
261
-        if (!is_string($type)) {
262
-            $type = $this->getSchemaOption('type', 'LocalBusiness');
263
-        }
264
-        $className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema');
265
-        return class_exists($className)
266
-            ? new $className()
267
-            : new UnknownType($type);
268
-    }
255
+	/**
256
+	 * @param string|null $type
257
+	 * @return mixed
258
+	 */
259
+	protected function getSchemaType($type = null)
260
+	{
261
+		if (!is_string($type)) {
262
+			$type = $this->getSchemaOption('type', 'LocalBusiness');
263
+		}
264
+		$className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema');
265
+		return class_exists($className)
266
+			? new $className()
267
+			: new UnknownType($type);
268
+	}
269 269
 
270
-    /**
271
-     * @return string
272
-     */
273
-    protected function getThingDescription()
274
-    {
275
-        $post = get_post();
276
-        if (!($post instanceof WP_Post)) {
277
-            return '';
278
-        }
279
-        $text = strip_shortcodes(wp_strip_all_tags($post->post_excerpt));
280
-        return wp_trim_words($text, apply_filters('excerpt_length', 55));
281
-    }
270
+	/**
271
+	 * @return string
272
+	 */
273
+	protected function getThingDescription()
274
+	{
275
+		$post = get_post();
276
+		if (!($post instanceof WP_Post)) {
277
+			return '';
278
+		}
279
+		$text = strip_shortcodes(wp_strip_all_tags($post->post_excerpt));
280
+		return wp_trim_words($text, apply_filters('excerpt_length', 55));
281
+	}
282 282
 
283
-    /**
284
-     * @return string
285
-     */
286
-    protected function getThingImage()
287
-    {
288
-        return (string) get_the_post_thumbnail_url(null, 'large');
289
-    }
283
+	/**
284
+	 * @return string
285
+	 */
286
+	protected function getThingImage()
287
+	{
288
+		return (string) get_the_post_thumbnail_url(null, 'large');
289
+	}
290 290
 
291
-    /**
292
-     * @return string
293
-     */
294
-    protected function getThingName()
295
-    {
296
-        return get_the_title();
297
-    }
291
+	/**
292
+	 * @return string
293
+	 */
294
+	protected function getThingName()
295
+	{
296
+		return get_the_title();
297
+	}
298 298
 
299
-    /**
300
-     * @return string
301
-     */
302
-    protected function getThingUrl()
303
-    {
304
-        return (string) get_the_permalink();
305
-    }
299
+	/**
300
+	 * @return string
301
+	 */
302
+	protected function getThingUrl()
303
+	{
304
+		return (string) get_the_permalink();
305
+	}
306 306
 }
Please login to merge, or discard this patch.
plugin/Application.php 1 patch
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -7,283 +7,283 @@
 block discarded – undo
7 7
 
8 8
 final class Application extends Container
9 9
 {
10
-    const CAPABILITY = 'edit_others_posts';
11
-    const CRON_EVENT = 'site-reviews/schedule/session/purge';
12
-    const ID = 'site-reviews';
13
-    const PAGED_QUERY_VAR = 'reviews-page';
14
-    const POST_TYPE = 'site-review';
15
-    const PREFIX = 'glsr_';
16
-    const TAXONOMY = 'site-review-category';
10
+	const CAPABILITY = 'edit_others_posts';
11
+	const CRON_EVENT = 'site-reviews/schedule/session/purge';
12
+	const ID = 'site-reviews';
13
+	const PAGED_QUERY_VAR = 'reviews-page';
14
+	const POST_TYPE = 'site-review';
15
+	const PREFIX = 'glsr_';
16
+	const TAXONOMY = 'site-review-category';
17 17
 
18
-    public $defaults;
19
-    public $deprecated = [];
20
-    public $file;
21
-    public $languages;
22
-    public $mceShortcodes = []; //defined elsewhere
23
-    public $name;
24
-    public $reviewTypes;
25
-    public $schemas = []; //defined elsewhere
26
-    public $version;
18
+	public $defaults;
19
+	public $deprecated = [];
20
+	public $file;
21
+	public $languages;
22
+	public $mceShortcodes = []; //defined elsewhere
23
+	public $name;
24
+	public $reviewTypes;
25
+	public $schemas = []; //defined elsewhere
26
+	public $version;
27 27
 
28
-    public function __construct()
29
-    {
30
-        static::$instance = $this;
31
-        $this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php');
32
-        $plugin = get_file_data($this->file, [
33
-            'languages' => 'Domain Path',
34
-            'name' => 'Plugin Name',
35
-            'version' => 'Version',
36
-        ], 'plugin');
37
-        array_walk($plugin, function ($value, $key) {
38
-            $this->$key = $value;
39
-        });
40
-    }
28
+	public function __construct()
29
+	{
30
+		static::$instance = $this;
31
+		$this->file = realpath(trailingslashit(dirname(__DIR__)).static::ID.'.php');
32
+		$plugin = get_file_data($this->file, [
33
+			'languages' => 'Domain Path',
34
+			'name' => 'Plugin Name',
35
+			'version' => 'Version',
36
+		], 'plugin');
37
+		array_walk($plugin, function ($value, $key) {
38
+			$this->$key = $value;
39
+		});
40
+	}
41 41
 
42
-    /**
43
-     * @return void
44
-     */
45
-    public function activate()
46
-    {
47
-        $this->make(DefaultsManager::class)->set();
48
-        $this->scheduleCronJob();
49
-        $this->upgrade();
50
-    }
42
+	/**
43
+	 * @return void
44
+	 */
45
+	public function activate()
46
+	{
47
+		$this->make(DefaultsManager::class)->set();
48
+		$this->scheduleCronJob();
49
+		$this->upgrade();
50
+	}
51 51
 
52
-    /**
53
-     * @return void
54
-     */
55
-    public function catchFatalError()
56
-    {
57
-        $error = error_get_last();
58
-        if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) {
59
-            return;
60
-        }
61
-        glsr_log()->error($error['message']);
62
-    }
52
+	/**
53
+	 * @return void
54
+	 */
55
+	public function catchFatalError()
56
+	{
57
+		$error = error_get_last();
58
+		if (E_ERROR !== $error['type'] || false === strpos($error['message'], $this->path())) {
59
+			return;
60
+		}
61
+		glsr_log()->error($error['message']);
62
+	}
63 63
 
64
-    /**
65
-     * @param string $name
66
-     * @return array
67
-     */
68
-    public function config($name)
69
-    {
70
-        $configFile = $this->path('config/'.$name.'.php');
71
-        $config = file_exists($configFile)
72
-            ? include $configFile
73
-            : [];
74
-        return apply_filters('site-reviews/config/'.$name, $config);
75
-    }
64
+	/**
65
+	 * @param string $name
66
+	 * @return array
67
+	 */
68
+	public function config($name)
69
+	{
70
+		$configFile = $this->path('config/'.$name.'.php');
71
+		$config = file_exists($configFile)
72
+			? include $configFile
73
+			: [];
74
+		return apply_filters('site-reviews/config/'.$name, $config);
75
+	}
76 76
 
77
-    /**
78
-     * @param string $property
79
-     * @return string
80
-     */
81
-    public function constant($property, $className = 'static')
82
-    {
83
-        $constant = $className.'::'.$property;
84
-        return defined($constant)
85
-            ? apply_filters('site-reviews/const/'.$property, constant($constant))
86
-            : '';
87
-    }
77
+	/**
78
+	 * @param string $property
79
+	 * @return string
80
+	 */
81
+	public function constant($property, $className = 'static')
82
+	{
83
+		$constant = $className.'::'.$property;
84
+		return defined($constant)
85
+			? apply_filters('site-reviews/const/'.$property, constant($constant))
86
+			: '';
87
+	}
88 88
 
89
-    /**
90
-     * @return void
91
-     */
92
-    public function deactivate()
93
-    {
94
-        $this->unscheduleCronJob();
95
-    }
89
+	/**
90
+	 * @return void
91
+	 */
92
+	public function deactivate()
93
+	{
94
+		$this->unscheduleCronJob();
95
+	}
96 96
 
97
-    /**
98
-     * @param string $view
99
-     * @return void|string
100
-     */
101
-    public function file($view)
102
-    {
103
-        $view.= '.php';
104
-        $filePaths = [];
105
-        if (glsr(Helper::class)->startsWith('templates/', $view)) {
106
-            $filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view));
107
-        }
108
-        $filePaths[] = $this->path($view);
109
-        $filePaths[] = $this->path('views/'.$view);
110
-        foreach ($filePaths as $file) {
111
-            if (!file_exists($file)) {
112
-                continue;
113
-            }
114
-            return $file;
115
-        }
116
-    }
97
+	/**
98
+	 * @param string $view
99
+	 * @return void|string
100
+	 */
101
+	public function file($view)
102
+	{
103
+		$view.= '.php';
104
+		$filePaths = [];
105
+		if (glsr(Helper::class)->startsWith('templates/', $view)) {
106
+			$filePaths[] = $this->themePath(glsr(Helper::class)->removePrefix('templates/', $view));
107
+		}
108
+		$filePaths[] = $this->path($view);
109
+		$filePaths[] = $this->path('views/'.$view);
110
+		foreach ($filePaths as $file) {
111
+			if (!file_exists($file)) {
112
+				continue;
113
+			}
114
+			return $file;
115
+		}
116
+	}
117 117
 
118
-    /**
119
-     * @return array
120
-     */
121
-    public function getDefaults()
122
-    {
123
-        if (empty($this->defaults)) {
124
-            $this->defaults = $this->make(DefaultsManager::class)->get();
125
-            $this->upgrade();
126
-        }
127
-        return apply_filters('site-reviews/get/defaults', $this->defaults);
128
-    }
118
+	/**
119
+	 * @return array
120
+	 */
121
+	public function getDefaults()
122
+	{
123
+		if (empty($this->defaults)) {
124
+			$this->defaults = $this->make(DefaultsManager::class)->get();
125
+			$this->upgrade();
126
+		}
127
+		return apply_filters('site-reviews/get/defaults', $this->defaults);
128
+	}
129 129
 
130
-    /**
131
-     * @return bool
132
-     */
133
-    public function getPermission($page = '')
134
-    {
135
-        $permissions = [
136
-            'addons' => 'install_plugins',
137
-            'settings' => 'manage_options',
138
-        ];
139
-        return glsr_get($permissions, $page, $this->constant('CAPABILITY'));
140
-    }
130
+	/**
131
+	 * @return bool
132
+	 */
133
+	public function getPermission($page = '')
134
+	{
135
+		$permissions = [
136
+			'addons' => 'install_plugins',
137
+			'settings' => 'manage_options',
138
+		];
139
+		return glsr_get($permissions, $page, $this->constant('CAPABILITY'));
140
+	}
141 141
 
142
-    /**
143
-     * @return bool
144
-     */
145
-    public function hasPermission($page = '')
146
-    {
147
-        $isAdmin = $this->isAdmin();
148
-        return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page)));
149
-    }
142
+	/**
143
+	 * @return bool
144
+	 */
145
+	public function hasPermission($page = '')
146
+	{
147
+		$isAdmin = $this->isAdmin();
148
+		return !$isAdmin || ($isAdmin && current_user_can($this->getPermission($page)));
149
+	}
150 150
 
151
-    /**
152
-     * @return void
153
-     */
154
-    public function init()
155
-    {
156
-        $this->make(Actions::class)->run();
157
-        $this->make(Filters::class)->run();
158
-    }
151
+	/**
152
+	 * @return void
153
+	 */
154
+	public function init()
155
+	{
156
+		$this->make(Actions::class)->run();
157
+		$this->make(Filters::class)->run();
158
+	}
159 159
 
160
-    /**
161
-     * @return bool
162
-     */
163
-    public function isAdmin()
164
-    {
165
-        return is_admin() && !wp_doing_ajax();
166
-    }
160
+	/**
161
+	 * @return bool
162
+	 */
163
+	public function isAdmin()
164
+	{
165
+		return is_admin() && !wp_doing_ajax();
166
+	}
167 167
 
168
-    /**
169
-     * @param string $file
170
-     * @return string
171
-     */
172
-    public function path($file = '', $realpath = true)
173
-    {
174
-        $path = plugin_dir_path($this->file);
175
-        if (!$realpath) {
176
-            $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file));
177
-        }
178
-        $path = trailingslashit($path).ltrim(trim($file), '/');
179
-        return apply_filters('site-reviews/path', $path, $file);
180
-    }
168
+	/**
169
+	 * @param string $file
170
+	 * @return string
171
+	 */
172
+	public function path($file = '', $realpath = true)
173
+	{
174
+		$path = plugin_dir_path($this->file);
175
+		if (!$realpath) {
176
+			$path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file));
177
+		}
178
+		$path = trailingslashit($path).ltrim(trim($file), '/');
179
+		return apply_filters('site-reviews/path', $path, $file);
180
+	}
181 181
 
182
-    /**
183
-     * @return void
184
-     */
185
-    public function registerAddons()
186
-    {
187
-        do_action('site-reviews/addon/register', $this);
188
-    }
182
+	/**
183
+	 * @return void
184
+	 */
185
+	public function registerAddons()
186
+	{
187
+		do_action('site-reviews/addon/register', $this);
188
+	}
189 189
 
190
-    /**
191
-     * @return void
192
-     */
193
-    public function registerLanguages()
194
-    {
195
-        load_plugin_textdomain(static::ID, false,
196
-            trailingslashit(plugin_basename($this->path()).'/'.$this->languages)
197
-        );
198
-    }
190
+	/**
191
+	 * @return void
192
+	 */
193
+	public function registerLanguages()
194
+	{
195
+		load_plugin_textdomain(static::ID, false,
196
+			trailingslashit(plugin_basename($this->path()).'/'.$this->languages)
197
+		);
198
+	}
199 199
 
200
-    /**
201
-     * @return void
202
-     */
203
-    public function registerReviewTypes()
204
-    {
205
-        $types = apply_filters('site-reviews/addon/types', []);
206
-        $this->reviewTypes = wp_parse_args($types, [
207
-            'local' => __('Local', 'site-reviews'),
208
-        ]);
209
-    }
200
+	/**
201
+	 * @return void
202
+	 */
203
+	public function registerReviewTypes()
204
+	{
205
+		$types = apply_filters('site-reviews/addon/types', []);
206
+		$this->reviewTypes = wp_parse_args($types, [
207
+			'local' => __('Local', 'site-reviews'),
208
+		]);
209
+	}
210 210
 
211
-    /**
212
-     * @param string $view
213
-     * @return void
214
-     */
215
-    public function render($view, array $data = [])
216
-    {
217
-        $view = apply_filters('site-reviews/render/view', $view, $data);
218
-        $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data);
219
-        if (!file_exists($file)) {
220
-            glsr_log()->error('File not found: '.$file);
221
-            return;
222
-        }
223
-        $data = apply_filters('site-reviews/views/data', $data, $view);
224
-        extract($data);
225
-        include $file;
226
-    }
211
+	/**
212
+	 * @param string $view
213
+	 * @return void
214
+	 */
215
+	public function render($view, array $data = [])
216
+	{
217
+		$view = apply_filters('site-reviews/render/view', $view, $data);
218
+		$file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data);
219
+		if (!file_exists($file)) {
220
+			glsr_log()->error('File not found: '.$file);
221
+			return;
222
+		}
223
+		$data = apply_filters('site-reviews/views/data', $data, $view);
224
+		extract($data);
225
+		include $file;
226
+	}
227 227
 
228
-    /**
229
-     * @return void
230
-     */
231
-    public function scheduleCronJob()
232
-    {
233
-        if (wp_next_scheduled(static::CRON_EVENT)) {
234
-            return;
235
-        }
236
-        wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT);
237
-    }
228
+	/**
229
+	 * @return void
230
+	 */
231
+	public function scheduleCronJob()
232
+	{
233
+		if (wp_next_scheduled(static::CRON_EVENT)) {
234
+			return;
235
+		}
236
+		wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT);
237
+	}
238 238
 
239
-    /**
240
-     * @param string $file
241
-     * @return string
242
-     */
243
-    public function themePath($file = '')
244
-    {
245
-        return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/');
246
-    }
239
+	/**
240
+	 * @param string $file
241
+	 * @return string
242
+	 */
243
+	public function themePath($file = '')
244
+	{
245
+		return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/');
246
+	}
247 247
 
248
-    /**
249
-     * @return void
250
-     */
251
-    public function unscheduleCronJob()
252
-    {
253
-        wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT);
254
-    }
248
+	/**
249
+	 * @return void
250
+	 */
251
+	public function unscheduleCronJob()
252
+	{
253
+		wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT);
254
+	}
255 255
 
256
-    /**
257
-     * @return void
258
-     */
259
-    public function upgrade()
260
-    {
261
-        $this->make(Upgrader::class)->run();
262
-    }
256
+	/**
257
+	 * @return void
258
+	 */
259
+	public function upgrade()
260
+	{
261
+		$this->make(Upgrader::class)->run();
262
+	}
263 263
 
264
-    /**
265
-     * @param mixed $upgrader
266
-     * @return void
267
-     * @action upgrader_process_complete
268
-     */
269
-    public function upgraded($upgrader, array $data)
270
-    {
271
-        if (array_key_exists('plugins', $data)
272
-            && in_array(plugin_basename($this->file), $data['plugins'])
273
-            && 'update' === $data['action']
274
-            && 'plugin' === $data['type']
275
-        ) {
276
-            $this->upgrade();
277
-        }
278
-    }
264
+	/**
265
+	 * @param mixed $upgrader
266
+	 * @return void
267
+	 * @action upgrader_process_complete
268
+	 */
269
+	public function upgraded($upgrader, array $data)
270
+	{
271
+		if (array_key_exists('plugins', $data)
272
+			&& in_array(plugin_basename($this->file), $data['plugins'])
273
+			&& 'update' === $data['action']
274
+			&& 'plugin' === $data['type']
275
+		) {
276
+			$this->upgrade();
277
+		}
278
+	}
279 279
 
280
-    /**
281
-     * @param string $path
282
-     * @return string
283
-     */
284
-    public function url($path = '')
285
-    {
286
-        $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/'));
287
-        return apply_filters('site-reviews/url', $url, $path);
288
-    }
280
+	/**
281
+	 * @param string $path
282
+	 * @return string
283
+	 */
284
+	public function url($path = '')
285
+	{
286
+		$url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/'));
287
+		return apply_filters('site-reviews/url', $url, $path);
288
+	}
289 289
 }
Please login to merge, or discard this patch.
plugin/Handlers/EnqueuePublicAssets.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -9,148 +9,148 @@
 block discarded – undo
9 9
 
10 10
 class EnqueuePublicAssets
11 11
 {
12
-    /**
13
-     * @return void
14
-     */
15
-    public function handle()
16
-    {
17
-        $this->enqueueAssets();
18
-        $this->enqueuePolyfillService();
19
-        $this->enqueueRecaptchaScript();
20
-        $this->inlineScript();
21
-        $this->inlineStyles();
22
-    }
12
+	/**
13
+	 * @return void
14
+	 */
15
+	public function handle()
16
+	{
17
+		$this->enqueueAssets();
18
+		$this->enqueuePolyfillService();
19
+		$this->enqueueRecaptchaScript();
20
+		$this->inlineScript();
21
+		$this->inlineStyles();
22
+	}
23 23
 
24
-    /**
25
-     * @return void
26
-     */
27
-    public function enqueueAssets()
28
-    {
29
-        if (apply_filters('site-reviews/assets/css', true)) {
30
-            wp_enqueue_style(
31
-                Application::ID,
32
-                $this->getStylesheet(),
33
-                [],
34
-                glsr()->version
35
-            );
36
-        }
37
-        if (apply_filters('site-reviews/assets/js', true)) {
38
-            $dependencies = apply_filters('site-reviews/assets/polyfill', true)
39
-                ? [Application::ID.'/polyfill']
40
-                : [];
41
-            $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
42
-            wp_enqueue_script(
43
-                Application::ID,
44
-                glsr()->url('assets/scripts/'.Application::ID.'.js'),
45
-                $dependencies,
46
-                glsr()->version,
47
-                true
48
-            );
49
-        }
50
-    }
24
+	/**
25
+	 * @return void
26
+	 */
27
+	public function enqueueAssets()
28
+	{
29
+		if (apply_filters('site-reviews/assets/css', true)) {
30
+			wp_enqueue_style(
31
+				Application::ID,
32
+				$this->getStylesheet(),
33
+				[],
34
+				glsr()->version
35
+			);
36
+		}
37
+		if (apply_filters('site-reviews/assets/js', true)) {
38
+			$dependencies = apply_filters('site-reviews/assets/polyfill', true)
39
+				? [Application::ID.'/polyfill']
40
+				: [];
41
+			$dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
42
+			wp_enqueue_script(
43
+				Application::ID,
44
+				glsr()->url('assets/scripts/'.Application::ID.'.js'),
45
+				$dependencies,
46
+				glsr()->version,
47
+				true
48
+			);
49
+		}
50
+	}
51 51
 
52
-    /**
53
-     * @return void
54
-     */
55
-    public function enqueuePolyfillService()
56
-    {
57
-        if (!apply_filters('site-reviews/assets/polyfill', true)) {
58
-            return;
59
-        }
60
-        wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
61
-            'features' => 'CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62
-            'flags' => 'gated',
63
-        ], 'https://polyfill.io/v3/polyfill.min.js'));
64
-    }
52
+	/**
53
+	 * @return void
54
+	 */
55
+	public function enqueuePolyfillService()
56
+	{
57
+		if (!apply_filters('site-reviews/assets/polyfill', true)) {
58
+			return;
59
+		}
60
+		wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
61
+			'features' => 'CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62
+			'flags' => 'gated',
63
+		], 'https://polyfill.io/v3/polyfill.min.js'));
64
+	}
65 65
 
66
-    /**
67
-     * @return void
68
-     */
69
-    public function enqueueRecaptchaScript()
70
-    {
71
-        // wpforms-recaptcha
72
-        // google-recaptcha
73
-        // nf-google-recaptcha
74
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
75
-            return;
76
-        }
77
-        $language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
-        wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
79
-            'hl' => $language,
80
-            'render' => 'explicit',
81
-        ], 'https://www.google.com/recaptcha/api.js'));
82
-    }
66
+	/**
67
+	 * @return void
68
+	 */
69
+	public function enqueueRecaptchaScript()
70
+	{
71
+		// wpforms-recaptcha
72
+		// google-recaptcha
73
+		// nf-google-recaptcha
74
+		if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
75
+			return;
76
+		}
77
+		$language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
+		wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
79
+			'hl' => $language,
80
+			'render' => 'explicit',
81
+		], 'https://www.google.com/recaptcha/api.js'));
82
+	}
83 83
 
84
-    /**
85
-     * @return void
86
-     */
87
-    public function inlineScript()
88
-    {
89
-        $variables = [
90
-            'action' => Application::PREFIX.'action',
91
-            'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
-            'ajaxurl' => admin_url('admin-ajax.php'),
93
-            'nameprefix' => Application::ID,
94
-            'validationconfig' => glsr(Style::class)->validation,
95
-            'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
96
-        ];
97
-        $variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
98
-        wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
99
-    }
84
+	/**
85
+	 * @return void
86
+	 */
87
+	public function inlineScript()
88
+	{
89
+		$variables = [
90
+			'action' => Application::PREFIX.'action',
91
+			'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
+			'ajaxurl' => admin_url('admin-ajax.php'),
93
+			'nameprefix' => Application::ID,
94
+			'validationconfig' => glsr(Style::class)->validation,
95
+			'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
96
+		];
97
+		$variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
98
+		wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
99
+	}
100 100
 
101
-    /**
102
-     * @return void
103
-     */
104
-    public function inlineStyles()
105
-    {
106
-        $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
107
-        if (!apply_filters('site-reviews/assets/css', true)) {
108
-            return;
109
-        }
110
-        if (!file_exists($inlineStylesheetPath)) {
111
-            glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
112
-            return;
113
-        }
114
-        $inlineStylesheetValues = glsr()->config('inline-styles');
115
-        $stylesheet = str_replace(
116
-            array_keys($inlineStylesheetValues),
117
-            array_values($inlineStylesheetValues),
118
-            file_get_contents($inlineStylesheetPath)
119
-        );
120
-        wp_add_inline_style(Application::ID, $stylesheet);
121
-    }
101
+	/**
102
+	 * @return void
103
+	 */
104
+	public function inlineStyles()
105
+	{
106
+		$inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
107
+		if (!apply_filters('site-reviews/assets/css', true)) {
108
+			return;
109
+		}
110
+		if (!file_exists($inlineStylesheetPath)) {
111
+			glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
112
+			return;
113
+		}
114
+		$inlineStylesheetValues = glsr()->config('inline-styles');
115
+		$stylesheet = str_replace(
116
+			array_keys($inlineStylesheetValues),
117
+			array_values($inlineStylesheetValues),
118
+			file_get_contents($inlineStylesheetPath)
119
+		);
120
+		wp_add_inline_style(Application::ID, $stylesheet);
121
+	}
122 122
 
123
-    /**
124
-     * @return string
125
-     */
126
-    protected function buildInlineScript(array $variables)
127
-    {
128
-        $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
129
-        foreach ($variables as $key => $value) {
130
-            $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
131
-        }
132
-        $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
133
-        $optimizedScript = preg_replace($pattern, '$1$2', $script);
134
-        return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
135
-    }
123
+	/**
124
+	 * @return string
125
+	 */
126
+	protected function buildInlineScript(array $variables)
127
+	{
128
+		$script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
129
+		foreach ($variables as $key => $value) {
130
+			$script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
131
+		}
132
+		$pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
133
+		$optimizedScript = preg_replace($pattern, '$1$2', $script);
134
+		return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
135
+	}
136 136
 
137
-    /**
138
-     * @return array
139
-     */
140
-    protected function getFixedSelectorsForPagination()
141
-    {
142
-        $selectors = ['#wpadminbar', '.site-navigation-fixed'];
143
-        return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
144
-    }
137
+	/**
138
+	 * @return array
139
+	 */
140
+	protected function getFixedSelectorsForPagination()
141
+	{
142
+		$selectors = ['#wpadminbar', '.site-navigation-fixed'];
143
+		return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
144
+	}
145 145
 
146
-    /**
147
-     * @return string
148
-     */
149
-    protected function getStylesheet()
150
-    {
151
-        $currentStyle = glsr(Style::class)->style;
152
-        return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
153
-            ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
154
-            : glsr()->url('assets/styles/'.Application::ID.'.css');
155
-    }
146
+	/**
147
+	 * @return string
148
+	 */
149
+	protected function getStylesheet()
150
+	{
151
+		$currentStyle = glsr(Style::class)->style;
152
+		return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
153
+			? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
154
+			: glsr()->url('assets/styles/'.Application::ID.'.css');
155
+	}
156 156
 }
Please login to merge, or discard this patch.