Passed
Push — master ( 04b043...334ee0 )
by Paul
04:11
created
config/styles/divi.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 return [
4
-    'fields' => [
5
-        'input' => 'input',
6
-        'input_checkbox' => 'input',
7
-        'input_radio' => 'input',
8
-        'label' => 'et_pb_contact_form_label',
9
-        'select' => 'et_pb_contact_select input',
10
-        'textarea' => 'et_pb_contact_message input',
11
-    ],
12
-    'validation' => [
13
-        'field_error_class' => 'et_contact_error',
14
-        'input_error_class' => 'et_contact_error',
15
-    ],
4
+	'fields' => [
5
+		'input' => 'input',
6
+		'input_checkbox' => 'input',
7
+		'input_radio' => 'input',
8
+		'label' => 'et_pb_contact_form_label',
9
+		'select' => 'et_pb_contact_select input',
10
+		'textarea' => 'et_pb_contact_message input',
11
+	],
12
+	'validation' => [
13
+		'field_error_class' => 'et_contact_error',
14
+		'input_error_class' => 'et_contact_error',
15
+	],
16 16
 ];
Please login to merge, or discard this patch.
plugin/Controllers/SettingsController.php 1 patch
Indentation   +152 added lines, -152 removed lines patch added patch discarded remove patch
@@ -12,163 +12,163 @@
 block discarded – undo
12 12
 
13 13
 class SettingsController extends Controller
14 14
 {
15
-    /**
16
-     * @param mixed $input
17
-     * @return array
18
-     * @callback register_setting
19
-     */
20
-    public function callbackRegisterSettings($input)
21
-    {
22
-        $settings = Arr::consolidateArray($input);
23
-        if (1 === count($settings) && array_key_exists('settings', $settings)) {
24
-            $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input);
25
-            $options = $this->sanitizeGeneral($input, $options);
26
-            $options = $this->sanitizeLicenses($input, $options);
27
-            $options = $this->sanitizeSubmissions($input, $options);
28
-            $options = $this->sanitizeTranslations($input, $options);
29
-            $options = apply_filters('site-reviews/settings/callback', $options, $settings);
30
-            if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') {
31
-                glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews'));
32
-            }
33
-            return $options;
34
-        }
35
-        return $input;
36
-    }
15
+	/**
16
+	 * @param mixed $input
17
+	 * @return array
18
+	 * @callback register_setting
19
+	 */
20
+	public function callbackRegisterSettings($input)
21
+	{
22
+		$settings = Arr::consolidateArray($input);
23
+		if (1 === count($settings) && array_key_exists('settings', $settings)) {
24
+			$options = array_replace_recursive(glsr(OptionManager::class)->all(), $input);
25
+			$options = $this->sanitizeGeneral($input, $options);
26
+			$options = $this->sanitizeLicenses($input, $options);
27
+			$options = $this->sanitizeSubmissions($input, $options);
28
+			$options = $this->sanitizeTranslations($input, $options);
29
+			$options = apply_filters('site-reviews/settings/callback', $options, $settings);
30
+			if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') {
31
+				glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews'));
32
+			}
33
+			return $options;
34
+		}
35
+		return $input;
36
+	}
37 37
 
38
-    /**
39
-     * @return void
40
-     * @action admin_init
41
-     */
42
-    public function registerSettings()
43
-    {
44
-        register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
45
-            'sanitize_callback' => [$this, 'callbackRegisterSettings'],
46
-        ]);
47
-    }
38
+	/**
39
+	 * @return void
40
+	 * @action admin_init
41
+	 */
42
+	public function registerSettings()
43
+	{
44
+		register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [
45
+			'sanitize_callback' => [$this, 'callbackRegisterSettings'],
46
+		]);
47
+	}
48 48
 
49
-    /**
50
-     * @return array
51
-     */
52
-    protected function sanitizeGeneral(array $input, array $options)
53
-    {
54
-        $key = 'settings.general';
55
-        $inputForm = Arr::get($input, $key);
56
-        if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) {
57
-            $options = Arr::set($options, $key.'.multilingual', '');
58
-        }
59
-        if ('' == trim(Arr::get($inputForm, 'notification_message'))) {
60
-            $defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message');
61
-            $options = Arr::set($options, $key.'.notification_message', $defaultValue);
62
-        }
63
-        $defaultValue = Arr::get($inputForm, 'notifications', []);
64
-        $options = Arr::set($options, $key.'.notifications', $defaultValue);
65
-        return $options;
66
-    }
49
+	/**
50
+	 * @return array
51
+	 */
52
+	protected function sanitizeGeneral(array $input, array $options)
53
+	{
54
+		$key = 'settings.general';
55
+		$inputForm = Arr::get($input, $key);
56
+		if (!$this->hasMultilingualIntegration(Arr::get($inputForm, 'multilingual'))) {
57
+			$options = Arr::set($options, $key.'.multilingual', '');
58
+		}
59
+		if ('' == trim(Arr::get($inputForm, 'notification_message'))) {
60
+			$defaultValue = Arr::get(glsr()->defaults, $key.'.notification_message');
61
+			$options = Arr::set($options, $key.'.notification_message', $defaultValue);
62
+		}
63
+		$defaultValue = Arr::get($inputForm, 'notifications', []);
64
+		$options = Arr::set($options, $key.'.notifications', $defaultValue);
65
+		return $options;
66
+	}
67 67
 
68
-    /**
69
-     * @return array
70
-     */
71
-    protected function sanitizeLicenses(array $input, array $options)
72
-    {
73
-        $key = 'settings.licenses';
74
-        $licenses = Arr::consolidateArray(Arr::get($input, $key));
75
-        foreach ($licenses as $slug => &$license) {
76
-            if (empty($license)) {
77
-                continue;
78
-            }
79
-            $license = $this->verifyLicense($license, $slug);
80
-        }
81
-        $options = Arr::set($options, $key, $licenses);
82
-        return $options;
83
-    }
68
+	/**
69
+	 * @return array
70
+	 */
71
+	protected function sanitizeLicenses(array $input, array $options)
72
+	{
73
+		$key = 'settings.licenses';
74
+		$licenses = Arr::consolidateArray(Arr::get($input, $key));
75
+		foreach ($licenses as $slug => &$license) {
76
+			if (empty($license)) {
77
+				continue;
78
+			}
79
+			$license = $this->verifyLicense($license, $slug);
80
+		}
81
+		$options = Arr::set($options, $key, $licenses);
82
+		return $options;
83
+	}
84 84
 
85
-    /**
86
-     * @return array
87
-     */
88
-    protected function sanitizeSubmissions(array $input, array $options)
89
-    {
90
-        $key = 'settings.submissions';
91
-        $inputForm = Arr::get($input, $key);
92
-        $defaultValue = isset($inputForm['required'])
93
-            ? $inputForm['required']
94
-            : [];
95
-        $options = Arr::set($options, $key.'.required', $defaultValue);
96
-        return $options;
97
-    }
85
+	/**
86
+	 * @return array
87
+	 */
88
+	protected function sanitizeSubmissions(array $input, array $options)
89
+	{
90
+		$key = 'settings.submissions';
91
+		$inputForm = Arr::get($input, $key);
92
+		$defaultValue = isset($inputForm['required'])
93
+			? $inputForm['required']
94
+			: [];
95
+		$options = Arr::set($options, $key.'.required', $defaultValue);
96
+		return $options;
97
+	}
98 98
 
99
-    /**
100
-     * @return array
101
-     */
102
-    protected function sanitizeTranslations(array $input, array $options)
103
-    {
104
-        $key = 'settings.strings';
105
-        $inputForm = Arr::consolidateArray(Arr::get($input, $key));
106
-        if (!empty($inputForm)) {
107
-            $options = Arr::set($options, $key, array_values(array_filter($inputForm)));
108
-            $allowedTags = [
109
-                'a' => ['class' => [], 'href' => [], 'target' => []],
110
-                'span' => ['class' => []],
111
-            ];
112
-            array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
113
-                if (isset($string['s2'])) {
114
-                    $string['s2'] = wp_kses($string['s2'], $allowedTags);
115
-                }
116
-                if (isset($string['p2'])) {
117
-                    $string['p2'] = wp_kses($string['p2'], $allowedTags);
118
-                }
119
-            });
120
-        }
121
-        return $options;
122
-    }
99
+	/**
100
+	 * @return array
101
+	 */
102
+	protected function sanitizeTranslations(array $input, array $options)
103
+	{
104
+		$key = 'settings.strings';
105
+		$inputForm = Arr::consolidateArray(Arr::get($input, $key));
106
+		if (!empty($inputForm)) {
107
+			$options = Arr::set($options, $key, array_values(array_filter($inputForm)));
108
+			$allowedTags = [
109
+				'a' => ['class' => [], 'href' => [], 'target' => []],
110
+				'span' => ['class' => []],
111
+			];
112
+			array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) {
113
+				if (isset($string['s2'])) {
114
+					$string['s2'] = wp_kses($string['s2'], $allowedTags);
115
+				}
116
+				if (isset($string['p2'])) {
117
+					$string['p2'] = wp_kses($string['p2'], $allowedTags);
118
+				}
119
+			});
120
+		}
121
+		return $options;
122
+	}
123 123
 
124
-    /**
125
-     * @param string $integrationSlug
126
-     * @return bool
127
-     */
128
-    protected function hasMultilingualIntegration($integrationSlug)
129
-    {
130
-        $integration = glsr(Multilingual::class)->getIntegration($integrationSlug);
131
-        if (!$integration) {
132
-            return false;
133
-        }
134
-        if (!$integration->isActive()) {
135
-            glsr(Notice::class)->addError(sprintf(
136
-                __('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
137
-                $integration->pluginName
138
-            ));
139
-            return false;
140
-        } elseif (!$integration->isSupported()) {
141
-            glsr(Notice::class)->addError(sprintf(
142
-                __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'),
143
-                $integration->pluginName,
144
-                $integration->supportedVersion
145
-            ));
146
-            return false;
147
-        }
148
-        return true;
149
-    }
124
+	/**
125
+	 * @param string $integrationSlug
126
+	 * @return bool
127
+	 */
128
+	protected function hasMultilingualIntegration($integrationSlug)
129
+	{
130
+		$integration = glsr(Multilingual::class)->getIntegration($integrationSlug);
131
+		if (!$integration) {
132
+			return false;
133
+		}
134
+		if (!$integration->isActive()) {
135
+			glsr(Notice::class)->addError(sprintf(
136
+				__('Please install/activate the %s plugin to enable integration.', 'site-reviews'),
137
+				$integration->pluginName
138
+			));
139
+			return false;
140
+		} elseif (!$integration->isSupported()) {
141
+			glsr(Notice::class)->addError(sprintf(
142
+				__('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'),
143
+				$integration->pluginName,
144
+				$integration->supportedVersion
145
+			));
146
+			return false;
147
+		}
148
+		return true;
149
+	}
150 150
 
151
-    /**
152
-     * @param string $license
153
-     * @param string $slug
154
-     * @return string
155
-     */
156
-    protected function verifyLicense($license, $slug)
157
-    {
158
-        try {
159
-            $addon = glsr($slug);
160
-            $updater = new Updater($addon->update_url, $addon->file, [
161
-                'license' => $license,
162
-                'testedTo' => $addon->testedTo,
163
-            ]);
164
-            if (!$updater->isLicenseValid()) {
165
-                throw new Exception('Invalid license: '.$license.' ('.$addon->id.')');
166
-            }
167
-        } catch (Exception $e) {
168
-            $license = '';
169
-            glsr_log()->debug($e->getMessage());
170
-            glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews'));
171
-        }
172
-        return $license;
173
-    }
151
+	/**
152
+	 * @param string $license
153
+	 * @param string $slug
154
+	 * @return string
155
+	 */
156
+	protected function verifyLicense($license, $slug)
157
+	{
158
+		try {
159
+			$addon = glsr($slug);
160
+			$updater = new Updater($addon->update_url, $addon->file, [
161
+				'license' => $license,
162
+				'testedTo' => $addon->testedTo,
163
+			]);
164
+			if (!$updater->isLicenseValid()) {
165
+				throw new Exception('Invalid license: '.$license.' ('.$addon->id.')');
166
+			}
167
+		} catch (Exception $e) {
168
+			$license = '';
169
+			glsr_log()->debug($e->getMessage());
170
+			glsr(Notice::class)->addError(__('A license you entered was invalid.', 'site-reviews'));
171
+		}
172
+		return $license;
173
+	}
174 174
 }
Please login to merge, or discard this patch.
plugin/Modules/Email.php 1 patch
Indentation   +201 added lines, -201 removed lines patch added patch discarded remove patch
@@ -9,205 +9,205 @@
 block discarded – undo
9 9
 
10 10
 class Email
11 11
 {
12
-    /**
13
-     * @var array
14
-     */
15
-    public $attachments;
16
-
17
-    /**
18
-     * @var array
19
-     */
20
-    public $email;
21
-
22
-    /**
23
-     * @var array
24
-     */
25
-    public $headers;
26
-
27
-    /**
28
-     * @var string
29
-     */
30
-    public $message;
31
-
32
-    /**
33
-     * @var string
34
-     */
35
-    public $subject;
36
-
37
-    /**
38
-     * @var string|array
39
-     */
40
-    public $to;
41
-
42
-    /**
43
-     * @return Email
44
-     */
45
-    public function compose(array $email)
46
-    {
47
-        $this->normalize($email);
48
-        $this->attachments = $this->email['attachments'];
49
-        $this->headers = $this->buildHeaders();
50
-        $this->message = $this->buildHtmlMessage();
51
-        $this->subject = $this->email['subject'];
52
-        $this->to = $this->email['to'];
53
-        add_action('phpmailer_init', [$this, 'buildPlainTextMessage']);
54
-        return $this;
55
-    }
56
-
57
-    /**
58
-     * @param string $format
59
-     * @return string|null
60
-     */
61
-    public function read($format = '')
62
-    {
63
-        if ('plaintext' == $format) {
64
-            $message = $this->stripHtmlTags($this->message);
65
-            return apply_filters('site-reviews/email/message', $message, 'text', $this);
66
-        }
67
-        return $this->message;
68
-    }
69
-
70
-    /**
71
-     * @return void|bool
72
-     */
73
-    public function send()
74
-    {
75
-        if (!$this->message || !$this->subject || !$this->to) {
76
-            return;
77
-        }
78
-        add_action('wp_mail_failed', [$this, 'logMailError']);
79
-        $sent = wp_mail(
80
-            $this->to,
81
-            $this->subject,
82
-            $this->message,
83
-            $this->headers,
84
-            $this->attachments
85
-        );
86
-        remove_action('wp_mail_failed', [$this, 'logMailError']);
87
-        $this->reset();
88
-        return $sent;
89
-    }
90
-
91
-    /**
92
-     * @return void
93
-     * @action phpmailer_init
94
-     */
95
-    public function buildPlainTextMessage(PHPMailer $phpmailer)
96
-    {
97
-        if (empty($this->email)) {
98
-            return;
99
-        }
100
-        if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) {
101
-            return;
102
-        }
103
-        $message = $this->stripHtmlTags($phpmailer->Body);
104
-        $phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this);
105
-    }
106
-
107
-    /**
108
-     * @return array
109
-     */
110
-    protected function buildHeaders()
111
-    {
112
-        $allowed = [
113
-            'bcc', 'cc', 'from', 'reply-to',
114
-        ];
115
-        $headers = array_intersect_key($this->email, array_flip($allowed));
116
-        $headers = array_filter($headers);
117
-        foreach ($headers as $key => $value) {
118
-            unset($headers[$key]);
119
-            $headers[] = $key.': '.$value;
120
-        }
121
-        $headers[] = 'Content-Type: text/html';
122
-        return apply_filters('site-reviews/email/headers', $headers, $this);
123
-    }
124
-
125
-    /**
126
-     * @return string
127
-     */
128
-    protected function buildHtmlMessage()
129
-    {
130
-        $template = trim(glsr(OptionManager::class)->get('settings.general.notification_message'));
131
-        if (!empty($template)) {
132
-            $message = glsr(Template::class)->interpolate(
133
-                $template, 
134
-                ['context' => $this->email['template-tags']], 
135
-                $this->email['template']
136
-            );
137
-        } elseif ($this->email['template']) {
138
-            $message = glsr(Template::class)->build('templates/'.$this->email['template'], [
139
-                'context' => $this->email['template-tags'],
140
-            ]);
141
-        }
142
-        if (!isset($message)) {
143
-            $message = $this->email['message'];
144
-        }
145
-        $message = $this->email['before'].$message.$this->email['after'];
146
-        $message = strip_shortcodes($message);
147
-        $message = wptexturize($message);
148
-        $message = wpautop($message);
149
-        $message = str_replace('&lt;&gt; ', '', $message);
150
-        $message = str_replace(']]>', ']]&gt;', $message);
151
-        $message = glsr(Template::class)->build('partials/email/index', [
152
-            'context' => ['message' => $message],
153
-        ]);
154
-        return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this);
155
-    }
156
-
157
-    /**
158
-     * @param \WP_Error $error
159
-     * @return void
160
-     */
161
-    protected function logMailError($error)
162
-    {
163
-        glsr_log()->error('Email was not sent (wp_mail failed)')
164
-            ->debug($this)
165
-            ->debug($error);
166
-    }
167
-
168
-    /**
169
-     * @return void
170
-     */
171
-    protected function normalize(array $email = [])
172
-    {
173
-        $email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email);
174
-        if (empty($email['reply-to'])) {
175
-            $email['reply-to'] = $email['from'];
176
-        }
177
-        $this->email = apply_filters('site-reviews/email/compose', $email, $this);
178
-    }
179
-
180
-    /**
181
-     * @return void
182
-     */
183
-    protected function reset()
184
-    {
185
-        $this->attachments = [];
186
-        $this->email = [];
187
-        $this->headers = [];
188
-        $this->message = null;
189
-        $this->subject = null;
190
-        $this->to = null;
191
-    }
192
-
193
-    /**
194
-     * @return string
195
-     */
196
-    protected function stripHtmlTags($string)
197
-    {
198
-        // remove invisible elements
199
-        $string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string);
200
-        // replace certain elements with a line-break
201
-        $string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string);
202
-        // replace other elements with a space
203
-        $string = preg_replace('@</(td|th)@iu', ' $0', $string);
204
-        // add a placeholder for plain-text bullets to list elements
205
-        $string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string);
206
-        // strip all remaining HTML tags
207
-        $string = wp_strip_all_tags($string);
208
-        $string = wp_specialchars_decode($string, ENT_QUOTES);
209
-        $string = preg_replace('/\v(?:[\v\h]+){2,}/u', "\r\n\r\n", $string);
210
-        $string = str_replace('-o-^-o-', ' - ', $string);
211
-        return html_entity_decode($string, ENT_QUOTES, 'UTF-8');
212
-    }
12
+	/**
13
+	 * @var array
14
+	 */
15
+	public $attachments;
16
+
17
+	/**
18
+	 * @var array
19
+	 */
20
+	public $email;
21
+
22
+	/**
23
+	 * @var array
24
+	 */
25
+	public $headers;
26
+
27
+	/**
28
+	 * @var string
29
+	 */
30
+	public $message;
31
+
32
+	/**
33
+	 * @var string
34
+	 */
35
+	public $subject;
36
+
37
+	/**
38
+	 * @var string|array
39
+	 */
40
+	public $to;
41
+
42
+	/**
43
+	 * @return Email
44
+	 */
45
+	public function compose(array $email)
46
+	{
47
+		$this->normalize($email);
48
+		$this->attachments = $this->email['attachments'];
49
+		$this->headers = $this->buildHeaders();
50
+		$this->message = $this->buildHtmlMessage();
51
+		$this->subject = $this->email['subject'];
52
+		$this->to = $this->email['to'];
53
+		add_action('phpmailer_init', [$this, 'buildPlainTextMessage']);
54
+		return $this;
55
+	}
56
+
57
+	/**
58
+	 * @param string $format
59
+	 * @return string|null
60
+	 */
61
+	public function read($format = '')
62
+	{
63
+		if ('plaintext' == $format) {
64
+			$message = $this->stripHtmlTags($this->message);
65
+			return apply_filters('site-reviews/email/message', $message, 'text', $this);
66
+		}
67
+		return $this->message;
68
+	}
69
+
70
+	/**
71
+	 * @return void|bool
72
+	 */
73
+	public function send()
74
+	{
75
+		if (!$this->message || !$this->subject || !$this->to) {
76
+			return;
77
+		}
78
+		add_action('wp_mail_failed', [$this, 'logMailError']);
79
+		$sent = wp_mail(
80
+			$this->to,
81
+			$this->subject,
82
+			$this->message,
83
+			$this->headers,
84
+			$this->attachments
85
+		);
86
+		remove_action('wp_mail_failed', [$this, 'logMailError']);
87
+		$this->reset();
88
+		return $sent;
89
+	}
90
+
91
+	/**
92
+	 * @return void
93
+	 * @action phpmailer_init
94
+	 */
95
+	public function buildPlainTextMessage(PHPMailer $phpmailer)
96
+	{
97
+		if (empty($this->email)) {
98
+			return;
99
+		}
100
+		if ('text/plain' === $phpmailer->ContentType || !empty($phpmailer->AltBody)) {
101
+			return;
102
+		}
103
+		$message = $this->stripHtmlTags($phpmailer->Body);
104
+		$phpmailer->AltBody = apply_filters('site-reviews/email/message', $message, 'text', $this);
105
+	}
106
+
107
+	/**
108
+	 * @return array
109
+	 */
110
+	protected function buildHeaders()
111
+	{
112
+		$allowed = [
113
+			'bcc', 'cc', 'from', 'reply-to',
114
+		];
115
+		$headers = array_intersect_key($this->email, array_flip($allowed));
116
+		$headers = array_filter($headers);
117
+		foreach ($headers as $key => $value) {
118
+			unset($headers[$key]);
119
+			$headers[] = $key.': '.$value;
120
+		}
121
+		$headers[] = 'Content-Type: text/html';
122
+		return apply_filters('site-reviews/email/headers', $headers, $this);
123
+	}
124
+
125
+	/**
126
+	 * @return string
127
+	 */
128
+	protected function buildHtmlMessage()
129
+	{
130
+		$template = trim(glsr(OptionManager::class)->get('settings.general.notification_message'));
131
+		if (!empty($template)) {
132
+			$message = glsr(Template::class)->interpolate(
133
+				$template, 
134
+				['context' => $this->email['template-tags']], 
135
+				$this->email['template']
136
+			);
137
+		} elseif ($this->email['template']) {
138
+			$message = glsr(Template::class)->build('templates/'.$this->email['template'], [
139
+				'context' => $this->email['template-tags'],
140
+			]);
141
+		}
142
+		if (!isset($message)) {
143
+			$message = $this->email['message'];
144
+		}
145
+		$message = $this->email['before'].$message.$this->email['after'];
146
+		$message = strip_shortcodes($message);
147
+		$message = wptexturize($message);
148
+		$message = wpautop($message);
149
+		$message = str_replace('&lt;&gt; ', '', $message);
150
+		$message = str_replace(']]>', ']]&gt;', $message);
151
+		$message = glsr(Template::class)->build('partials/email/index', [
152
+			'context' => ['message' => $message],
153
+		]);
154
+		return apply_filters('site-reviews/email/message', stripslashes($message), 'html', $this);
155
+	}
156
+
157
+	/**
158
+	 * @param \WP_Error $error
159
+	 * @return void
160
+	 */
161
+	protected function logMailError($error)
162
+	{
163
+		glsr_log()->error('Email was not sent (wp_mail failed)')
164
+			->debug($this)
165
+			->debug($error);
166
+	}
167
+
168
+	/**
169
+	 * @return void
170
+	 */
171
+	protected function normalize(array $email = [])
172
+	{
173
+		$email = shortcode_atts(glsr(EmailDefaults::class)->defaults(), $email);
174
+		if (empty($email['reply-to'])) {
175
+			$email['reply-to'] = $email['from'];
176
+		}
177
+		$this->email = apply_filters('site-reviews/email/compose', $email, $this);
178
+	}
179
+
180
+	/**
181
+	 * @return void
182
+	 */
183
+	protected function reset()
184
+	{
185
+		$this->attachments = [];
186
+		$this->email = [];
187
+		$this->headers = [];
188
+		$this->message = null;
189
+		$this->subject = null;
190
+		$this->to = null;
191
+	}
192
+
193
+	/**
194
+	 * @return string
195
+	 */
196
+	protected function stripHtmlTags($string)
197
+	{
198
+		// remove invisible elements
199
+		$string = preg_replace('@<(embed|head|noembed|noscript|object|script|style)[^>]*?>.*?</\\1>@siu', '', $string);
200
+		// replace certain elements with a line-break
201
+		$string = preg_replace('@</(div|h[1-9]|p|pre|tr)@iu', "\r\n\$0", $string);
202
+		// replace other elements with a space
203
+		$string = preg_replace('@</(td|th)@iu', ' $0', $string);
204
+		// add a placeholder for plain-text bullets to list elements
205
+		$string = preg_replace('@<(li)[^>]*?>@siu', '$0-o-^-o-', $string);
206
+		// strip all remaining HTML tags
207
+		$string = wp_strip_all_tags($string);
208
+		$string = wp_specialchars_decode($string, ENT_QUOTES);
209
+		$string = preg_replace('/\v(?:[\v\h]+){2,}/u', "\r\n\r\n", $string);
210
+		$string = str_replace('-o-^-o-', ' - ', $string);
211
+		return html_entity_decode($string, ENT_QUOTES, 'UTF-8');
212
+	}
213 213
 }
Please login to merge, or discard this patch.
plugin/Modules/System.php 1 patch
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -13,378 +13,378 @@
 block discarded – undo
13 13
 
14 14
 class System
15 15
 {
16
-    const PAD = 40;
16
+	const PAD = 40;
17 17
 
18
-    /**
19
-     * @return string
20
-     */
21
-    public function __toString()
22
-    {
23
-        return $this->get();
24
-    }
18
+	/**
19
+	 * @return string
20
+	 */
21
+	public function __toString()
22
+	{
23
+		return $this->get();
24
+	}
25 25
 
26
-    /**
27
-     * @return string
28
-     */
29
-    public function get()
30
-    {
31
-        $details = [
32
-            'plugin' => 'Plugin Details',
33
-            'addon' => 'Addon Details',
34
-            'browser' => 'Browser Details',
35
-            'server' => 'Server Details',
36
-            'php' => 'PHP Configuration',
37
-            'wordpress' => 'WordPress Configuration',
38
-            'mu-plugin' => 'Must-Use Plugins',
39
-            'multisite-plugin' => 'Network Active Plugins',
40
-            'active-plugin' => 'Active Plugins',
41
-            'inactive-plugin' => 'Inactive Plugins',
42
-            'setting' => 'Plugin Settings',
43
-            'reviews' => 'Review Counts',
44
-        ];
45
-        $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
-            $methodName = Helper::buildMethodName('get-'.$key.'-details');
47
-            if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
48
-                return $carry.$this->implode(
49
-                    strtoupper($details[$key]),
50
-                    apply_filters('site-reviews/system/'.$key, $systemDetails)
51
-                );
52
-            }
53
-            return $carry;
54
-        });
55
-        return trim($systemInfo);
56
-    }
26
+	/**
27
+	 * @return string
28
+	 */
29
+	public function get()
30
+	{
31
+		$details = [
32
+			'plugin' => 'Plugin Details',
33
+			'addon' => 'Addon Details',
34
+			'browser' => 'Browser Details',
35
+			'server' => 'Server Details',
36
+			'php' => 'PHP Configuration',
37
+			'wordpress' => 'WordPress Configuration',
38
+			'mu-plugin' => 'Must-Use Plugins',
39
+			'multisite-plugin' => 'Network Active Plugins',
40
+			'active-plugin' => 'Active Plugins',
41
+			'inactive-plugin' => 'Inactive Plugins',
42
+			'setting' => 'Plugin Settings',
43
+			'reviews' => 'Review Counts',
44
+		];
45
+		$systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) {
46
+			$methodName = Helper::buildMethodName('get-'.$key.'-details');
47
+			if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) {
48
+				return $carry.$this->implode(
49
+					strtoupper($details[$key]),
50
+					apply_filters('site-reviews/system/'.$key, $systemDetails)
51
+				);
52
+			}
53
+			return $carry;
54
+		});
55
+		return trim($systemInfo);
56
+	}
57 57
 
58
-    /**
59
-     * @return array
60
-     */
61
-    public function getActivePluginDetails()
62
-    {
63
-        $plugins = get_plugins();
64
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
-        $inactive = array_diff_key($plugins, array_flip($activePlugins));
66
-        return $this->normalizePluginList(array_diff_key($plugins, $inactive));
67
-    }
58
+	/**
59
+	 * @return array
60
+	 */
61
+	public function getActivePluginDetails()
62
+	{
63
+		$plugins = get_plugins();
64
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
65
+		$inactive = array_diff_key($plugins, array_flip($activePlugins));
66
+		return $this->normalizePluginList(array_diff_key($plugins, $inactive));
67
+	}
68 68
 
69
-    /**
70
-     * @return array
71
-     */
72
-    public function getAddonDetails()
73
-    {
74
-        $details = apply_filters('site-reviews/addon/system-info', []);
75
-        ksort($details);
76
-        return $details;
77
-    }
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function getAddonDetails()
73
+	{
74
+		$details = apply_filters('site-reviews/addon/system-info', []);
75
+		ksort($details);
76
+		return $details;
77
+	}
78 78
 
79
-    /**
80
-     * @return array
81
-     */
82
-    public function getBrowserDetails()
83
-    {
84
-        $browser = new Browser();
85
-        $name = esc_attr($browser->getName());
86
-        $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
-        $version = esc_attr($browser->getVersion());
88
-        return [
89
-            'Browser Name' => sprintf('%s %s', $name, $version),
90
-            'Browser UA' => $userAgent,
91
-        ];
92
-    }
79
+	/**
80
+	 * @return array
81
+	 */
82
+	public function getBrowserDetails()
83
+	{
84
+		$browser = new Browser();
85
+		$name = esc_attr($browser->getName());
86
+		$userAgent = esc_attr($browser->getUserAgent()->getUserAgentString());
87
+		$version = esc_attr($browser->getVersion());
88
+		return [
89
+			'Browser Name' => sprintf('%s %s', $name, $version),
90
+			'Browser UA' => $userAgent,
91
+		];
92
+	}
93 93
 
94
-    /**
95
-     * @return array
96
-     */
97
-    public function getInactivePluginDetails()
98
-    {
99
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
-        $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
101
-        $multisitePlugins = $this->getMultisitePluginDetails();
102
-        return empty($multisitePlugins)
103
-            ? $inactivePlugins
104
-            : array_diff($inactivePlugins, $multisitePlugins);
105
-    }
94
+	/**
95
+	 * @return array
96
+	 */
97
+	public function getInactivePluginDetails()
98
+	{
99
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
100
+		$inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins)));
101
+		$multisitePlugins = $this->getMultisitePluginDetails();
102
+		return empty($multisitePlugins)
103
+			? $inactivePlugins
104
+			: array_diff($inactivePlugins, $multisitePlugins);
105
+	}
106 106
 
107
-    /**
108
-     * @return array
109
-     */
110
-    public function getMuPluginDetails()
111
-    {
112
-        if (empty($plugins = get_mu_plugins())) {
113
-            return [];
114
-        }
115
-        return $this->normalizePluginList($plugins);
116
-    }
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function getMuPluginDetails()
111
+	{
112
+		if (empty($plugins = get_mu_plugins())) {
113
+			return [];
114
+		}
115
+		return $this->normalizePluginList($plugins);
116
+	}
117 117
 
118
-    /**
119
-     * @return array
120
-     */
121
-    public function getMultisitePluginDetails()
122
-    {
123
-        $activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
-        if (!is_multisite() || empty($activePlugins)) {
125
-            return [];
126
-        }
127
-        return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
128
-    }
118
+	/**
119
+	 * @return array
120
+	 */
121
+	public function getMultisitePluginDetails()
122
+	{
123
+		$activePlugins = (array) get_site_option('active_sitewide_plugins', []);
124
+		if (!is_multisite() || empty($activePlugins)) {
125
+			return [];
126
+		}
127
+		return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins));
128
+	}
129 129
 
130
-    /**
131
-     * @return array
132
-     */
133
-    public function getPhpDetails()
134
-    {
135
-        $displayErrors = $this->getINI('display_errors', null)
136
-            ? 'On ('.$this->getINI('display_errors').')'
137
-            : 'N/A';
138
-        $intlSupport = extension_loaded('intl')
139
-            ? phpversion('intl')
140
-            : 'false';
141
-        return [
142
-            'cURL' => var_export(function_exists('curl_init'), true),
143
-            'Default Charset' => $this->getINI('default_charset'),
144
-            'Display Errors' => $displayErrors,
145
-            'fsockopen' => var_export(function_exists('fsockopen'), true),
146
-            'Intl' => $intlSupport,
147
-            'IPv6' => var_export(defined('AF_INET6'), true),
148
-            'Max Execution Time' => $this->getINI('max_execution_time'),
149
-            'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
-            'Max Input Vars' => $this->getINI('max_input_vars'),
151
-            'Memory Limit' => $this->getINI('memory_limit'),
152
-            'Post Max Size' => $this->getINI('post_max_size'),
153
-            'Sendmail Path' => $this->getINI('sendmail_path'),
154
-            'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
-            'Session Name' => esc_html($this->getINI('session.name')),
156
-            'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
-            'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
-            'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
-            'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
160
-        ];
161
-    }
130
+	/**
131
+	 * @return array
132
+	 */
133
+	public function getPhpDetails()
134
+	{
135
+		$displayErrors = $this->getINI('display_errors', null)
136
+			? 'On ('.$this->getINI('display_errors').')'
137
+			: 'N/A';
138
+		$intlSupport = extension_loaded('intl')
139
+			? phpversion('intl')
140
+			: 'false';
141
+		return [
142
+			'cURL' => var_export(function_exists('curl_init'), true),
143
+			'Default Charset' => $this->getINI('default_charset'),
144
+			'Display Errors' => $displayErrors,
145
+			'fsockopen' => var_export(function_exists('fsockopen'), true),
146
+			'Intl' => $intlSupport,
147
+			'IPv6' => var_export(defined('AF_INET6'), true),
148
+			'Max Execution Time' => $this->getINI('max_execution_time'),
149
+			'Max Input Nesting Level' => $this->getINI('max_input_nesting_level'),
150
+			'Max Input Vars' => $this->getINI('max_input_vars'),
151
+			'Memory Limit' => $this->getINI('memory_limit'),
152
+			'Post Max Size' => $this->getINI('post_max_size'),
153
+			'Sendmail Path' => $this->getINI('sendmail_path'),
154
+			'Session Cookie Path' => esc_html($this->getINI('session.cookie_path')),
155
+			'Session Name' => esc_html($this->getINI('session.name')),
156
+			'Session Save Path' => esc_html($this->getINI('session.save_path')),
157
+			'Session Use Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_cookies', false)), true),
158
+			'Session Use Only Cookies' => var_export(wp_validate_boolean($this->getINI('session.use_only_cookies', false)), true),
159
+			'Upload Max Filesize' => $this->getINI('upload_max_filesize'),
160
+		];
161
+	}
162 162
 
163
-    /**
164
-     * @return array
165
-     */
166
-    public function getReviewsDetails()
167
-    {
168
-        $counts = glsr(CountsManager::class)->getCounts();
169
-        $counts = Arr::flattenArray($counts);
170
-        array_walk($counts, function (&$ratings) use ($counts) {
171
-            if (is_array($ratings)) {
172
-                $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
173
-                return;
174
-            }
175
-            glsr_log()
176
-                ->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
-                ->debug($ratings)
178
-                ->debug($counts);
179
-        });
180
-        ksort($counts);
181
-        return $counts;
182
-    }
163
+	/**
164
+	 * @return array
165
+	 */
166
+	public function getReviewsDetails()
167
+	{
168
+		$counts = glsr(CountsManager::class)->getCounts();
169
+		$counts = Arr::flattenArray($counts);
170
+		array_walk($counts, function (&$ratings) use ($counts) {
171
+			if (is_array($ratings)) {
172
+				$ratings = array_sum($ratings).' ('.implode(', ', $ratings).')';
173
+				return;
174
+			}
175
+			glsr_log()
176
+				->error('$ratings is not an array, possibly due to incorrectly imported reviews.')
177
+				->debug($ratings)
178
+				->debug($counts);
179
+		});
180
+		ksort($counts);
181
+		return $counts;
182
+	}
183 183
 
184
-    /**
185
-     * @return array
186
-     */
187
-    public function getServerDetails()
188
-    {
189
-        global $wpdb;
190
-        return [
191
-            'Host Name' => $this->getHostName(),
192
-            'MySQL Version' => $wpdb->db_version(),
193
-            'PHP Version' => PHP_VERSION,
194
-            'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
195
-        ];
196
-    }
184
+	/**
185
+	 * @return array
186
+	 */
187
+	public function getServerDetails()
188
+	{
189
+		global $wpdb;
190
+		return [
191
+			'Host Name' => $this->getHostName(),
192
+			'MySQL Version' => $wpdb->db_version(),
193
+			'PHP Version' => PHP_VERSION,
194
+			'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'),
195
+		];
196
+	}
197 197
 
198
-    /**
199
-     * @return array
200
-     */
201
-    public function getSettingDetails()
202
-    {
203
-        $settings = glsr(OptionManager::class)->get('settings', []);
204
-        $settings = Arr::flattenArray($settings, true);
205
-        $settings = $this->purgeSensitiveData($settings);
206
-        ksort($settings);
207
-        $details = [];
208
-        foreach ($settings as $key => $value) {
209
-            if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
210
-                continue;
211
-            }
212
-            $value = htmlspecialchars(trim(preg_replace('/\s\s+/u', '\\n', $value)), ENT_QUOTES, 'UTF-8');
213
-            $details[$key] = $value;
214
-        }
215
-        return $details;
216
-    }
198
+	/**
199
+	 * @return array
200
+	 */
201
+	public function getSettingDetails()
202
+	{
203
+		$settings = glsr(OptionManager::class)->get('settings', []);
204
+		$settings = Arr::flattenArray($settings, true);
205
+		$settings = $this->purgeSensitiveData($settings);
206
+		ksort($settings);
207
+		$details = [];
208
+		foreach ($settings as $key => $value) {
209
+			if (Str::startsWith('strings', $key) && Str::endsWith('id', $key)) {
210
+				continue;
211
+			}
212
+			$value = htmlspecialchars(trim(preg_replace('/\s\s+/u', '\\n', $value)), ENT_QUOTES, 'UTF-8');
213
+			$details[$key] = $value;
214
+		}
215
+		return $details;
216
+	}
217 217
 
218
-    /**
219
-     * @return array
220
-     */
221
-    public function getPluginDetails()
222
-    {
223
-        return [
224
-            'Console level' => glsr(Console::class)->humanLevel(),
225
-            'Console size' => glsr(Console::class)->humanSize('0'),
226
-            'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
-            'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
228
-            'Version (current)' => glsr()->version,
229
-            'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
230
-        ];
231
-    }
218
+	/**
219
+	 * @return array
220
+	 */
221
+	public function getPluginDetails()
222
+	{
223
+		return [
224
+			'Console level' => glsr(Console::class)->humanLevel(),
225
+			'Console size' => glsr(Console::class)->humanSize('0'),
226
+			'Last Migration Run' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_migration_run'), 'unknown'),
227
+			'Last Rating Count' => glsr(Date::class)->localized(glsr(OptionManager::class)->get('last_review_count'), 'unknown'),
228
+			'Version (current)' => glsr()->version,
229
+			'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'),
230
+		];
231
+	}
232 232
 
233
-    /**
234
-     * @return array
235
-     */
236
-    public function getWordpressDetails()
237
-    {
238
-        global $wpdb;
239
-        $theme = wp_get_theme();
240
-        return [
241
-            'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
-            'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
243
-            'Home URL' => home_url(),
244
-            'Language' => get_locale(),
245
-            'Memory Limit' => WP_MEMORY_LIMIT,
246
-            'Multisite' => var_export(is_multisite(), true),
247
-            'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
-            'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
-            'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
-            'Post Stati' => implode(', ', get_post_stati()),
251
-            'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
-            'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
253
-            'Site URL' => site_url(),
254
-            'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
-            'Version' => get_bloginfo('version'),
256
-            'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
-            'WP Max Upload Size' => size_format(wp_max_upload_size()),
258
-            'WP Memory Limit' => WP_MEMORY_LIMIT,
259
-        ];
260
-    }
233
+	/**
234
+	 * @return array
235
+	 */
236
+	public function getWordpressDetails()
237
+	{
238
+		global $wpdb;
239
+		$theme = wp_get_theme();
240
+		return [
241
+			'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version),
242
+			'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1),
243
+			'Home URL' => home_url(),
244
+			'Language' => get_locale(),
245
+			'Memory Limit' => WP_MEMORY_LIMIT,
246
+			'Multisite' => var_export(is_multisite(), true),
247
+			'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'),
248
+			'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'),
249
+			'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'),
250
+			'Post Stati' => implode(', ', get_post_stati()),
251
+			'Remote Post' => glsr(Cache::class)->getRemotePostTest(),
252
+			'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'),
253
+			'Site URL' => site_url(),
254
+			'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', $this->getINI('date.timezone').' (PHP)'),
255
+			'Version' => get_bloginfo('version'),
256
+			'WP Debug' => var_export(defined('WP_DEBUG'), true),
257
+			'WP Max Upload Size' => size_format(wp_max_upload_size()),
258
+			'WP Memory Limit' => WP_MEMORY_LIMIT,
259
+		];
260
+	}
261 261
 
262
-    /**
263
-     * @return string
264
-     */
265
-    protected function detectWebhostProvider()
266
-    {
267
-        $checks = [
268
-            '.accountservergroup.com' => 'Site5',
269
-            '.gridserver.com' => 'MediaTemple Grid',
270
-            '.inmotionhosting.com' => 'InMotion Hosting',
271
-            '.ovh.net' => 'OVH',
272
-            '.pair.com' => 'pair Networks',
273
-            '.stabletransit.com' => 'Rackspace Cloud',
274
-            '.stratoserver.net' => 'STRATO',
275
-            '.sysfix.eu' => 'SysFix.eu Power Hosting',
276
-            'bluehost.com' => 'Bluehost',
277
-            'DH_USER' => 'DreamHost',
278
-            'Flywheel' => 'Flywheel',
279
-            'ipagemysql.com' => 'iPage',
280
-            'ipowermysql.com' => 'IPower',
281
-            'localhost:/tmp/mysql5.sock' => 'ICDSoft',
282
-            'mysqlv5' => 'NetworkSolutions',
283
-            'PAGELYBIN' => 'Pagely',
284
-            'secureserver.net' => 'GoDaddy',
285
-            'WPE_APIKEY' => 'WP Engine',
286
-        ];
287
-        foreach ($checks as $key => $value) {
288
-            if (!$this->isWebhostCheckValid($key)) {
289
-                continue;
290
-            }
291
-            return $value;
292
-        }
293
-        return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
294
-    }
262
+	/**
263
+	 * @return string
264
+	 */
265
+	protected function detectWebhostProvider()
266
+	{
267
+		$checks = [
268
+			'.accountservergroup.com' => 'Site5',
269
+			'.gridserver.com' => 'MediaTemple Grid',
270
+			'.inmotionhosting.com' => 'InMotion Hosting',
271
+			'.ovh.net' => 'OVH',
272
+			'.pair.com' => 'pair Networks',
273
+			'.stabletransit.com' => 'Rackspace Cloud',
274
+			'.stratoserver.net' => 'STRATO',
275
+			'.sysfix.eu' => 'SysFix.eu Power Hosting',
276
+			'bluehost.com' => 'Bluehost',
277
+			'DH_USER' => 'DreamHost',
278
+			'Flywheel' => 'Flywheel',
279
+			'ipagemysql.com' => 'iPage',
280
+			'ipowermysql.com' => 'IPower',
281
+			'localhost:/tmp/mysql5.sock' => 'ICDSoft',
282
+			'mysqlv5' => 'NetworkSolutions',
283
+			'PAGELYBIN' => 'Pagely',
284
+			'secureserver.net' => 'GoDaddy',
285
+			'WPE_APIKEY' => 'WP Engine',
286
+		];
287
+		foreach ($checks as $key => $value) {
288
+			if (!$this->isWebhostCheckValid($key)) {
289
+				continue;
290
+			}
291
+			return $value;
292
+		}
293
+		return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')]));
294
+	}
295 295
 
296
-    /**
297
-     * @return string
298
-     */
299
-    protected function getHostName()
300
-    {
301
-        return sprintf('%s (%s)',
302
-            $this->detectWebhostProvider(),
303
-            Helper::getIpAddress()
304
-        );
305
-    }
296
+	/**
297
+	 * @return string
298
+	 */
299
+	protected function getHostName()
300
+	{
301
+		return sprintf('%s (%s)',
302
+			$this->detectWebhostProvider(),
303
+			Helper::getIpAddress()
304
+		);
305
+	}
306 306
 
307
-    protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
308
-    {
309
-        return function_exists('ini_get')
310
-            ? ini_get($name)
311
-            : $disabledValue;
312
-    }
307
+	protected function getINI($name, $disabledValue = 'ini_get() is disabled.')
308
+	{
309
+		return function_exists('ini_get')
310
+			? ini_get($name)
311
+			: $disabledValue;
312
+	}
313 313
 
314
-    /**
315
-     * @return array
316
-     */
317
-    protected function getWordpressPlugins()
318
-    {
319
-        $plugins = get_plugins();
320
-        $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
-        $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
-        $active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
323
-        return $active + $inactive;
324
-    }
314
+	/**
315
+	 * @return array
316
+	 */
317
+	protected function getWordpressPlugins()
318
+	{
319
+		$plugins = get_plugins();
320
+		$activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array');
321
+		$inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins)));
322
+		$active = $this->normalizePluginList(array_diff_key($plugins, $inactive));
323
+		return $active + $inactive;
324
+	}
325 325
 
326
-    /**
327
-     * @param string $title
328
-     * @return string
329
-     */
330
-    protected function implode($title, array $details)
331
-    {
332
-        $strings = ['['.$title.']'];
333
-        $padding = max(array_map('strlen', array_keys($details)));
334
-        $padding = max([$padding, static::PAD]);
335
-        foreach ($details as $key => $value) {
336
-            $strings[] = is_string($key)
337
-                ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
338
-                : ' - '.$value;
339
-        }
340
-        return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
341
-    }
326
+	/**
327
+	 * @param string $title
328
+	 * @return string
329
+	 */
330
+	protected function implode($title, array $details)
331
+	{
332
+		$strings = ['['.$title.']'];
333
+		$padding = max(array_map('strlen', array_keys($details)));
334
+		$padding = max([$padding, static::PAD]);
335
+		foreach ($details as $key => $value) {
336
+			$strings[] = is_string($key)
337
+				? sprintf('%s : %s', str_pad($key, $padding, '.'), $value)
338
+				: ' - '.$value;
339
+		}
340
+		return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL;
341
+	}
342 342
 
343
-    /**
344
-     * @param string $key
345
-     * @return bool
346
-     */
347
-    protected function isWebhostCheckValid($key)
348
-    {
349
-        return defined($key)
350
-            || filter_input(INPUT_SERVER, $key)
351
-            || Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
-            || Str::contains(DB_HOST, $key)
353
-            || Str::contains(php_uname(), $key);
354
-    }
343
+	/**
344
+	 * @param string $key
345
+	 * @return bool
346
+	 */
347
+	protected function isWebhostCheckValid($key)
348
+	{
349
+		return defined($key)
350
+			|| filter_input(INPUT_SERVER, $key)
351
+			|| Str::contains(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key)
352
+			|| Str::contains(DB_HOST, $key)
353
+			|| Str::contains(php_uname(), $key);
354
+	}
355 355
 
356
-    /**
357
-     * @return array
358
-     */
359
-    protected function normalizePluginList(array $plugins)
360
-    {
361
-        $plugins = array_map(function ($plugin) {
362
-            return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
-        }, $plugins);
364
-        natcasesort($plugins);
365
-        return array_flip($plugins);
366
-    }
356
+	/**
357
+	 * @return array
358
+	 */
359
+	protected function normalizePluginList(array $plugins)
360
+	{
361
+		$plugins = array_map(function ($plugin) {
362
+			return sprintf('%s v%s', Arr::get($plugin, 'Name'), Arr::get($plugin, 'Version'));
363
+		}, $plugins);
364
+		natcasesort($plugins);
365
+		return array_flip($plugins);
366
+	}
367 367
 
368
-    /**
369
-     * @return array
370
-     */
371
-    protected function purgeSensitiveData(array $settings)
372
-    {
373
-        $keys = [
374
-            'general.trustalyze_serial',
375
-            'licenses.',
376
-            'submissions.recaptcha.key',
377
-            'submissions.recaptcha.secret',
378
-        ];
379
-        array_walk($settings, function (&$value, $setting) use ($keys) {
380
-            foreach ($keys as $key) {
381
-                if (!Str::startsWith($key, $setting) || empty($value)) {
382
-                    continue;
383
-                }
384
-                $value = str_repeat('•', 13);
385
-                return;
386
-            }
387
-        });
388
-        return $settings;
389
-    }
368
+	/**
369
+	 * @return array
370
+	 */
371
+	protected function purgeSensitiveData(array $settings)
372
+	{
373
+		$keys = [
374
+			'general.trustalyze_serial',
375
+			'licenses.',
376
+			'submissions.recaptcha.key',
377
+			'submissions.recaptcha.secret',
378
+		];
379
+		array_walk($settings, function (&$value, $setting) use ($keys) {
380
+			foreach ($keys as $key) {
381
+				if (!Str::startsWith($key, $setting) || empty($value)) {
382
+					continue;
383
+				}
384
+				$value = str_repeat('•', 13);
385
+				return;
386
+			}
387
+		});
388
+		return $settings;
389
+	}
390 390
 }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviews.php 1 patch
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -21,384 +21,384 @@
 block discarded – undo
21 21
 
22 22
 class SiteReviews
23 23
 {
24
-    /**
25
-     * @var array
26
-     */
27
-    public $args;
24
+	/**
25
+	 * @var array
26
+	 */
27
+	public $args;
28 28
 
29
-    /**
30
-     * @var Review
31
-     */
32
-    public $current;
29
+	/**
30
+	 * @var Review
31
+	 */
32
+	public $current;
33 33
 
34
-    /**
35
-     * @var array
36
-     */
37
-    public $options;
34
+	/**
35
+	 * @var array
36
+	 */
37
+	public $options;
38 38
 
39
-    /**
40
-     * @var Reviews
41
-     */
42
-    protected $reviews;
39
+	/**
40
+	 * @var Reviews
41
+	 */
42
+	protected $reviews;
43 43
 
44
-    /**
45
-     * @param Reviews|null $reviews
46
-     * @return ReviewsHtml
47
-     */
48
-    public function build(array $args = [], $reviews = null)
49
-    {
50
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
-        $this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
52
-        $this->reviews = $reviews instanceof Reviews
53
-            ? $reviews
54
-            : glsr(ReviewManager::class)->get($this->args);
55
-        $this->generateSchema();
56
-        return $this->buildReviews();
57
-    }
44
+	/**
45
+	 * @param Reviews|null $reviews
46
+	 * @return ReviewsHtml
47
+	 */
48
+	public function build(array $args = [], $reviews = null)
49
+	{
50
+		$this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
+		$this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
52
+		$this->reviews = $reviews instanceof Reviews
53
+			? $reviews
54
+			: glsr(ReviewManager::class)->get($this->args);
55
+		$this->generateSchema();
56
+		return $this->buildReviews();
57
+	}
58 58
 
59
-    /**
60
-     * @return ReviewHtml
61
-     */
62
-    public function buildReview(Review $review)
63
-    {
64
-        $review = apply_filters('site-reviews/review/build/before', $review);
65
-        $this->current = $review;
66
-        $renderedFields = [];
67
-        foreach ($review as $key => $value) {
68
-            $method = Helper::buildMethodName($key, 'buildOption');
69
-            $field = method_exists($this, $method)
70
-                ? $this->$method($key, $value)
71
-                : false;
72
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
-            if (false === $field) {
74
-                continue;
75
-            }
76
-            $renderedFields[$key] = $field;
77
-        }
78
-        $this->wrap($renderedFields, $review);
79
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
-        $this->current = null;
81
-        return new ReviewHtml($review, (array) $renderedFields);
82
-    }
59
+	/**
60
+	 * @return ReviewHtml
61
+	 */
62
+	public function buildReview(Review $review)
63
+	{
64
+		$review = apply_filters('site-reviews/review/build/before', $review);
65
+		$this->current = $review;
66
+		$renderedFields = [];
67
+		foreach ($review as $key => $value) {
68
+			$method = Helper::buildMethodName($key, 'buildOption');
69
+			$field = method_exists($this, $method)
70
+				? $this->$method($key, $value)
71
+				: false;
72
+			$field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
+			if (false === $field) {
74
+				continue;
75
+			}
76
+			$renderedFields[$key] = $field;
77
+		}
78
+		$this->wrap($renderedFields, $review);
79
+		$renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
+		$this->current = null;
81
+		return new ReviewHtml($review, (array) $renderedFields);
82
+	}
83 83
 
84
-    /**
85
-     * @return ReviewsHtml
86
-     */
87
-    public function buildReviews()
88
-    {
89
-        $renderedReviews = [];
90
-        foreach ($this->reviews as $index => $review) {
91
-            $renderedReviews[] = $this->buildReview($review);
92
-        }
93
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
-    }
84
+	/**
85
+	 * @return ReviewsHtml
86
+	 */
87
+	public function buildReviews()
88
+	{
89
+		$renderedReviews = [];
90
+		foreach ($this->reviews as $index => $review) {
91
+			$renderedReviews[] = $this->buildReview($review);
92
+		}
93
+		return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
+	}
95 95
 
96
-    /**
97
-     * @return void
98
-     */
99
-    public function generateSchema()
100
-    {
101
-        if (!wp_validate_boolean($this->args['schema'])) {
102
-            return;
103
-        }
104
-        glsr(Schema::class)->store(
105
-            glsr(Schema::class)->build($this->args)
106
-        );
107
-    }
96
+	/**
97
+	 * @return void
98
+	 */
99
+	public function generateSchema()
100
+	{
101
+		if (!wp_validate_boolean($this->args['schema'])) {
102
+			return;
103
+		}
104
+		glsr(Schema::class)->store(
105
+			glsr(Schema::class)->build($this->args)
106
+		);
107
+	}
108 108
 
109
-    /**
110
-     * @param string $text
111
-     * @return string
112
-     */
113
-    public function getExcerpt($text)
114
-    {
115
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
-        $split = extension_loaded('intl')
117
-            ? $this->getExcerptIntlSplit($text, $limit)
118
-            : $this->getExcerptSplit($text, $limit);
119
-        $hiddenText = substr($text, $split);
120
-        if (!empty($hiddenText)) {
121
-            $showMore = glsr(Builder::class)->span($hiddenText, [
122
-                'class' => 'glsr-hidden glsr-hidden-text',
123
-                'data-show-less' => __('Show less', 'site-reviews'),
124
-                'data-show-more' => __('Show more', 'site-reviews'),
125
-            ]);
126
-            $text = ltrim(substr($text, 0, $split)).$showMore;
127
-        }
128
-        return $text;
129
-    }
109
+	/**
110
+	 * @param string $text
111
+	 * @return string
112
+	 */
113
+	public function getExcerpt($text)
114
+	{
115
+		$limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
+		$split = extension_loaded('intl')
117
+			? $this->getExcerptIntlSplit($text, $limit)
118
+			: $this->getExcerptSplit($text, $limit);
119
+		$hiddenText = substr($text, $split);
120
+		if (!empty($hiddenText)) {
121
+			$showMore = glsr(Builder::class)->span($hiddenText, [
122
+				'class' => 'glsr-hidden glsr-hidden-text',
123
+				'data-show-less' => __('Show less', 'site-reviews'),
124
+				'data-show-more' => __('Show more', 'site-reviews'),
125
+			]);
126
+			$text = ltrim(substr($text, 0, $split)).$showMore;
127
+		}
128
+		return $text;
129
+	}
130 130
 
131
-    /**
132
-     * @param string $key
133
-     * @param string $path
134
-     * @return bool
135
-     */
136
-    public function isHidden($key, $path = '')
137
-    {
138
-        $isOptionEnabled = !empty($path)
139
-            ? $this->isOptionEnabled($path)
140
-            : true;
141
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
-    }
131
+	/**
132
+	 * @param string $key
133
+	 * @param string $path
134
+	 * @return bool
135
+	 */
136
+	public function isHidden($key, $path = '')
137
+	{
138
+		$isOptionEnabled = !empty($path)
139
+			? $this->isOptionEnabled($path)
140
+			: true;
141
+		return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
+	}
143 143
 
144
-    /**
145
-     * @param string $key
146
-     * @param string $value
147
-     * @return bool
148
-     */
149
-    public function isHiddenOrEmpty($key, $value)
150
-    {
151
-        return $this->isHidden($key) || empty($value);
152
-    }
144
+	/**
145
+	 * @param string $key
146
+	 * @param string $value
147
+	 * @return bool
148
+	 */
149
+	public function isHiddenOrEmpty($key, $value)
150
+	{
151
+		return $this->isHidden($key) || empty($value);
152
+	}
153 153
 
154
-    /**
155
-     * @param string $text
156
-     * @return string
157
-     */
158
-    public function normalizeText($text)
159
-    {
160
-        $text = wp_kses($text, wp_kses_allowed_html());
161
-        $text = convert_smilies(strip_shortcodes($text));
162
-        $text = str_replace(']]>', ']]&gt;', $text);
163
-        $text = preg_replace('/(\R){2,}/u', '$1', $text);
164
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
-            $text = $this->getExcerpt($text);
166
-        }
167
-        return wptexturize(nl2br($text));
168
-    }
154
+	/**
155
+	 * @param string $text
156
+	 * @return string
157
+	 */
158
+	public function normalizeText($text)
159
+	{
160
+		$text = wp_kses($text, wp_kses_allowed_html());
161
+		$text = convert_smilies(strip_shortcodes($text));
162
+		$text = str_replace(']]>', ']]&gt;', $text);
163
+		$text = preg_replace('/(\R){2,}/u', '$1', $text);
164
+		if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
+			$text = $this->getExcerpt($text);
166
+		}
167
+		return wptexturize(nl2br($text));
168
+	}
169 169
 
170
-    /**
171
-     * @param string $key
172
-     * @param string $value
173
-     * @return void|string
174
-     */
175
-    protected function buildOptionAssignedTo($key, $value)
176
-    {
177
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
-            return;
179
-        }
180
-        $post = get_post(glsr(Multilingual::class)->getPostId($value));
181
-        if (empty($post->ID)) {
182
-            return;
183
-        }
184
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
-            'href' => get_the_permalink($post->ID),
186
-        ]);
187
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
188
-        return '<span>'.$assignedTo.'</span>';
189
-    }
170
+	/**
171
+	 * @param string $key
172
+	 * @param string $value
173
+	 * @return void|string
174
+	 */
175
+	protected function buildOptionAssignedTo($key, $value)
176
+	{
177
+		if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
+			return;
179
+		}
180
+		$post = get_post(glsr(Multilingual::class)->getPostId($value));
181
+		if (empty($post->ID)) {
182
+			return;
183
+		}
184
+		$permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
+			'href' => get_the_permalink($post->ID),
186
+		]);
187
+		$assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
188
+		return '<span>'.$assignedTo.'</span>';
189
+	}
190 190
 
191
-    /**
192
-     * @param string $key
193
-     * @param string $value
194
-     * @return void|string
195
-     */
196
-    protected function buildOptionAuthor($key, $value)
197
-    {
198
-        if (!$this->isHidden($key)) {
199
-            $name = Str::convertName(
200
-                $value,
201
-                glsr_get_option('reviews.name.format'),
202
-                glsr_get_option('reviews.name.initial')
203
-            );
204
-            return '<span>'.$name.'</span>';
205
-        }
206
-    }
191
+	/**
192
+	 * @param string $key
193
+	 * @param string $value
194
+	 * @return void|string
195
+	 */
196
+	protected function buildOptionAuthor($key, $value)
197
+	{
198
+		if (!$this->isHidden($key)) {
199
+			$name = Str::convertName(
200
+				$value,
201
+				glsr_get_option('reviews.name.format'),
202
+				glsr_get_option('reviews.name.initial')
203
+			);
204
+			return '<span>'.$name.'</span>';
205
+		}
206
+	}
207 207
 
208
-    /**
209
-     * @param string $key
210
-     * @param string $value
211
-     * @return void|string
212
-     */
213
-    protected function buildOptionAvatar($key, $value)
214
-    {
215
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
-            return;
217
-        }
218
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
219
-        return glsr(Builder::class)->img([
220
-            'height' => $size,
221
-            'src' => $this->generateAvatar($value),
222
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
-            'width' => $size,
224
-        ]);
225
-    }
208
+	/**
209
+	 * @param string $key
210
+	 * @param string $value
211
+	 * @return void|string
212
+	 */
213
+	protected function buildOptionAvatar($key, $value)
214
+	{
215
+		if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
+			return;
217
+		}
218
+		$size = $this->getOption('settings.reviews.avatars_size', 40);
219
+		return glsr(Builder::class)->img([
220
+			'height' => $size,
221
+			'src' => $this->generateAvatar($value),
222
+			'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
+			'width' => $size,
224
+		]);
225
+	}
226 226
 
227
-    /**
228
-     * @param string $key
229
-     * @param string $value
230
-     * @return void|string
231
-     */
232
-    protected function buildOptionContent($key, $value)
233
-    {
234
-        $text = $this->normalizeText($value);
235
-        if (!$this->isHiddenOrEmpty($key, $text)) {
236
-            return '<p>'.$text.'</p>';
237
-        }
238
-    }
227
+	/**
228
+	 * @param string $key
229
+	 * @param string $value
230
+	 * @return void|string
231
+	 */
232
+	protected function buildOptionContent($key, $value)
233
+	{
234
+		$text = $this->normalizeText($value);
235
+		if (!$this->isHiddenOrEmpty($key, $text)) {
236
+			return '<p>'.$text.'</p>';
237
+		}
238
+	}
239 239
 
240
-    /**
241
-     * @param string $key
242
-     * @param string $value
243
-     * @return void|string
244
-     */
245
-    protected function buildOptionDate($key, $value)
246
-    {
247
-        if ($this->isHidden($key)) {
248
-            return;
249
-        }
250
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
-        if ('relative' == $dateFormat) {
252
-            $date = glsr(Date::class)->relative($value);
253
-        } else {
254
-            $format = 'custom' == $dateFormat
255
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
-                : glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
-            $date = date_i18n($format, strtotime($value));
258
-        }
259
-        return '<span>'.$date.'</span>';
260
-    }
240
+	/**
241
+	 * @param string $key
242
+	 * @param string $value
243
+	 * @return void|string
244
+	 */
245
+	protected function buildOptionDate($key, $value)
246
+	{
247
+		if ($this->isHidden($key)) {
248
+			return;
249
+		}
250
+		$dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
+		if ('relative' == $dateFormat) {
252
+			$date = glsr(Date::class)->relative($value);
253
+		} else {
254
+			$format = 'custom' == $dateFormat
255
+				? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
+				: glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
+			$date = date_i18n($format, strtotime($value));
258
+		}
259
+		return '<span>'.$date.'</span>';
260
+	}
261 261
 
262
-    /**
263
-     * @param string $key
264
-     * @param string $value
265
-     * @return void|string
266
-     */
267
-    protected function buildOptionRating($key, $value)
268
-    {
269
-        if (!$this->isHiddenOrEmpty($key, $value)) {
270
-            return glsr_star_rating($value);
271
-        }
272
-    }
262
+	/**
263
+	 * @param string $key
264
+	 * @param string $value
265
+	 * @return void|string
266
+	 */
267
+	protected function buildOptionRating($key, $value)
268
+	{
269
+		if (!$this->isHiddenOrEmpty($key, $value)) {
270
+			return glsr_star_rating($value);
271
+		}
272
+	}
273 273
 
274
-    /**
275
-     * @param string $key
276
-     * @param string $value
277
-     * @return void|string
278
-     */
279
-    protected function buildOptionResponse($key, $value)
280
-    {
281
-        if ($this->isHiddenOrEmpty($key, $value)) {
282
-            return;
283
-        }
284
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
-        $text = $this->normalizeText($value);
286
-        $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
289
-        return $response.$background;
290
-    }
274
+	/**
275
+	 * @param string $key
276
+	 * @param string $value
277
+	 * @return void|string
278
+	 */
279
+	protected function buildOptionResponse($key, $value)
280
+	{
281
+		if ($this->isHiddenOrEmpty($key, $value)) {
282
+			return;
283
+		}
284
+		$title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
+		$text = $this->normalizeText($value);
286
+		$text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
+		$response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
+		$background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
289
+		return $response.$background;
290
+	}
291 291
 
292
-    /**
293
-     * @param string $key
294
-     * @param string $value
295
-     * @return void|string
296
-     */
297
-    protected function buildOptionTitle($key, $value)
298
-    {
299
-        if ($this->isHidden($key)) {
300
-            return;
301
-        }
302
-        if (empty($value)) {
303
-            $value = __('No Title', 'site-reviews');
304
-        }
305
-        return '<h3>'.$value.'</h3>';
306
-    }
292
+	/**
293
+	 * @param string $key
294
+	 * @param string $value
295
+	 * @return void|string
296
+	 */
297
+	protected function buildOptionTitle($key, $value)
298
+	{
299
+		if ($this->isHidden($key)) {
300
+			return;
301
+		}
302
+		if (empty($value)) {
303
+			$value = __('No Title', 'site-reviews');
304
+		}
305
+		return '<h3>'.$value.'</h3>';
306
+	}
307 307
 
308
-    /**
309
-     * @param string $avatarUrl
310
-     * @return string
311
-     */
312
-    protected function generateAvatar($avatarUrl)
313
-    {
314
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
-            return $avatarUrl;
316
-        }
317
-        if ($this->current->user_id) {
318
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
319
-        }
320
-        if (empty($authorIdOrEmail)) {
321
-            $authorIdOrEmail = $this->current->email;
322
-        }
323
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
324
-            return $newAvatar;
325
-        }
326
-        return $avatarUrl;
327
-    }
308
+	/**
309
+	 * @param string $avatarUrl
310
+	 * @return string
311
+	 */
312
+	protected function generateAvatar($avatarUrl)
313
+	{
314
+		if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
+			return $avatarUrl;
316
+		}
317
+		if ($this->current->user_id) {
318
+		$authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
319
+		}
320
+		if (empty($authorIdOrEmail)) {
321
+			$authorIdOrEmail = $this->current->email;
322
+		}
323
+		if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
324
+			return $newAvatar;
325
+		}
326
+		return $avatarUrl;
327
+	}
328 328
 
329
-    /**
330
-     * @param string $text
331
-     * @param int $limit
332
-     * @return int
333
-     */
334
-    protected function getExcerptIntlSplit($text, $limit)
335
-    {
336
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
337
-        $words->setText($text);
338
-        $count = 0;
339
-        foreach ($words as $offset) {
340
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
341
-                continue;
342
-            }
343
-            ++$count;
344
-            if ($count != $limit) {
345
-                continue;
346
-            }
347
-            return $offset;
348
-        }
349
-        return strlen($text);
350
-    }
329
+	/**
330
+	 * @param string $text
331
+	 * @param int $limit
332
+	 * @return int
333
+	 */
334
+	protected function getExcerptIntlSplit($text, $limit)
335
+	{
336
+		$words = IntlRuleBasedBreakIterator::createWordInstance('');
337
+		$words->setText($text);
338
+		$count = 0;
339
+		foreach ($words as $offset) {
340
+			if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
341
+				continue;
342
+			}
343
+			++$count;
344
+			if ($count != $limit) {
345
+				continue;
346
+			}
347
+			return $offset;
348
+		}
349
+		return strlen($text);
350
+	}
351 351
 
352
-    /**
353
-     * @param string $text
354
-     * @param int $limit
355
-     * @return int
356
-     */
357
-    protected function getExcerptSplit($text, $limit)
358
-    {
359
-        if (str_word_count($text, 0) > $limit) {
360
-            $words = array_keys(str_word_count($text, 2));
361
-            return $words[$limit];
362
-        }
363
-        return strlen($text);
364
-    }
352
+	/**
353
+	 * @param string $text
354
+	 * @param int $limit
355
+	 * @return int
356
+	 */
357
+	protected function getExcerptSplit($text, $limit)
358
+	{
359
+		if (str_word_count($text, 0) > $limit) {
360
+			$words = array_keys(str_word_count($text, 2));
361
+			return $words[$limit];
362
+		}
363
+		return strlen($text);
364
+	}
365 365
 
366
-    /**
367
-     * @param string $path
368
-     * @param mixed $fallback
369
-     * @return mixed
370
-     */
371
-    protected function getOption($path, $fallback = '')
372
-    {
373
-        if (array_key_exists($path, $this->options)) {
374
-            return $this->options[$path];
375
-        }
376
-        return $fallback;
377
-    }
366
+	/**
367
+	 * @param string $path
368
+	 * @param mixed $fallback
369
+	 * @return mixed
370
+	 */
371
+	protected function getOption($path, $fallback = '')
372
+	{
373
+		if (array_key_exists($path, $this->options)) {
374
+			return $this->options[$path];
375
+		}
376
+		return $fallback;
377
+	}
378 378
 
379
-    /**
380
-     * @param string $path
381
-     * @return bool
382
-     */
383
-    protected function isOptionEnabled($path)
384
-    {
385
-        return 'yes' == $this->getOption($path);
386
-    }
379
+	/**
380
+	 * @param string $path
381
+	 * @return bool
382
+	 */
383
+	protected function isOptionEnabled($path)
384
+	{
385
+		return 'yes' == $this->getOption($path);
386
+	}
387 387
 
388
-    /**
389
-     * @return void
390
-     */
391
-    protected function wrap(array &$renderedFields, Review $review)
392
-    {
393
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
394
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
395
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
396
-            if (empty($value)) {
397
-                return;
398
-            }
399
-            $value = glsr(Builder::class)->div($value, [
400
-                'class' => 'glsr-review-'.$key,
401
-            ]);
402
-        });
403
-    }
388
+	/**
389
+	 * @return void
390
+	 */
391
+	protected function wrap(array &$renderedFields, Review $review)
392
+	{
393
+		$renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
394
+		array_walk($renderedFields, function (&$value, $key) use ($review) {
395
+			$value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
396
+			if (empty($value)) {
397
+				return;
398
+			}
399
+			$value = glsr(Builder::class)->div($value, [
400
+				'class' => 'glsr-review-'.$key,
401
+			]);
402
+		});
403
+	}
404 404
 }
Please login to merge, or discard this patch.
plugin/Controllers/EditorController/Labels.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -7,106 +7,106 @@
 block discarded – undo
7 7
 
8 8
 class Labels
9 9
 {
10
-    /**
11
-     * @param string $translation
12
-     * @param string $test
13
-     * @return string
14
-     */
15
-    public function filterPostStatusLabels($translation, $text)
16
-    {
17
-        $replacements = $this->getStatusLabels();
18
-        return array_key_exists($text, $replacements)
19
-            ? $replacements[$text]
20
-            : $translation;
21
-    }
10
+	/**
11
+	 * @param string $translation
12
+	 * @param string $test
13
+	 * @return string
14
+	 */
15
+	public function filterPostStatusLabels($translation, $text)
16
+	{
17
+		$replacements = $this->getStatusLabels();
18
+		return array_key_exists($text, $replacements)
19
+			? $replacements[$text]
20
+			: $translation;
21
+	}
22 22
 
23
-    /**
24
-     * @return array
25
-     */
26
-    public function filterUpdateMessages(array $messages)
27
-    {
28
-        $post = get_post();
29
-        if (!($post instanceof WP_Post)) {
30
-            return;
31
-        }
32
-        $strings = $this->getReviewLabels();
33
-        $restored = filter_input(INPUT_GET, 'revision');
34
-        if ($revisionTitle = wp_post_revision_title(intval($restored), false)) {
35
-            $restored = sprintf($strings['restored'], $revisionTitle);
36
-        }
37
-        $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date));
38
-        $messages[Application::POST_TYPE] = [
39
-             1 => $strings['updated'],
40
-             4 => $strings['updated'],
41
-             5 => $restored,
42
-             6 => $strings['published'],
43
-             7 => $strings['saved'],
44
-             8 => $strings['submitted'],
45
-             9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'),
46
-            10 => $strings['draft_updated'],
47
-            50 => $strings['approved'],
48
-            51 => $strings['unapproved'],
49
-            52 => $strings['reverted'],
50
-        ];
51
-        return $messages;
52
-    }
23
+	/**
24
+	 * @return array
25
+	 */
26
+	public function filterUpdateMessages(array $messages)
27
+	{
28
+		$post = get_post();
29
+		if (!($post instanceof WP_Post)) {
30
+			return;
31
+		}
32
+		$strings = $this->getReviewLabels();
33
+		$restored = filter_input(INPUT_GET, 'revision');
34
+		if ($revisionTitle = wp_post_revision_title(intval($restored), false)) {
35
+			$restored = sprintf($strings['restored'], $revisionTitle);
36
+		}
37
+		$scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date));
38
+		$messages[Application::POST_TYPE] = [
39
+			 1 => $strings['updated'],
40
+			 4 => $strings['updated'],
41
+			 5 => $restored,
42
+			 6 => $strings['published'],
43
+			 7 => $strings['saved'],
44
+			 8 => $strings['submitted'],
45
+			 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'),
46
+			10 => $strings['draft_updated'],
47
+			50 => $strings['approved'],
48
+			51 => $strings['unapproved'],
49
+			52 => $strings['reverted'],
50
+		];
51
+		return $messages;
52
+	}
53 53
 
54
-    /**
55
-     * @return void
56
-     */
57
-    public function translatePostStatusLabels()
58
-    {
59
-        global $wp_scripts;
60
-        $strings = [
61
-            'savePending' => __('Save as Unapproved', 'site-reviews'),
62
-            'published' => __('Approved', 'site-reviews'),
63
-        ];
64
-        if (isset($wp_scripts->registered['post']->extra['data'])) {
65
-            $l10n = &$wp_scripts->registered['post']->extra['data'];
66
-            foreach ($strings as $search => $replace) {
67
-                $l10n = preg_replace('/("'.$search.'":")([^"]+)/u', '$1'.$replace, $l10n);
68
-            }
69
-        }
70
-    }
54
+	/**
55
+	 * @return void
56
+	 */
57
+	public function translatePostStatusLabels()
58
+	{
59
+		global $wp_scripts;
60
+		$strings = [
61
+			'savePending' => __('Save as Unapproved', 'site-reviews'),
62
+			'published' => __('Approved', 'site-reviews'),
63
+		];
64
+		if (isset($wp_scripts->registered['post']->extra['data'])) {
65
+			$l10n = &$wp_scripts->registered['post']->extra['data'];
66
+			foreach ($strings as $search => $replace) {
67
+				$l10n = preg_replace('/("'.$search.'":")([^"]+)/u', '$1'.$replace, $l10n);
68
+			}
69
+		}
70
+	}
71 71
 
72
-    /**
73
-     * @return array
74
-     */
75
-    protected function getReviewLabels()
76
-    {
77
-        return [
78
-            'approved' => __('Review has been approved and published.', 'site-reviews'),
79
-            'draft_updated' => __('Review draft updated.', 'site-reviews'),
80
-            'preview' => __('Preview review', 'site-reviews'),
81
-            'published' => __('Review approved and published.', 'site-reviews'),
82
-            'restored' => __('Review restored to revision from %s.', 'site-reviews'),
83
-            'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'),
84
-            'saved' => __('Review saved.', 'site-reviews'),
85
-            'scheduled' => __('Review scheduled for: %s.', 'site-reviews'),
86
-            'submitted' => __('Review submitted.', 'site-reviews'),
87
-            'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'),
88
-            'updated' => __('Review updated.', 'site-reviews'),
89
-            'view' => __('View review', 'site-reviews'),
90
-        ];
91
-    }
72
+	/**
73
+	 * @return array
74
+	 */
75
+	protected function getReviewLabels()
76
+	{
77
+		return [
78
+			'approved' => __('Review has been approved and published.', 'site-reviews'),
79
+			'draft_updated' => __('Review draft updated.', 'site-reviews'),
80
+			'preview' => __('Preview review', 'site-reviews'),
81
+			'published' => __('Review approved and published.', 'site-reviews'),
82
+			'restored' => __('Review restored to revision from %s.', 'site-reviews'),
83
+			'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'),
84
+			'saved' => __('Review saved.', 'site-reviews'),
85
+			'scheduled' => __('Review scheduled for: %s.', 'site-reviews'),
86
+			'submitted' => __('Review submitted.', 'site-reviews'),
87
+			'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'),
88
+			'updated' => __('Review updated.', 'site-reviews'),
89
+			'view' => __('View review', 'site-reviews'),
90
+		];
91
+	}
92 92
 
93
-    /**
94
-     * Store the labels to avoid unnecessary loops.
95
-     * @return array
96
-     */
97
-    protected function getStatusLabels()
98
-    {
99
-        static $labels;
100
-        if (empty($labels)) {
101
-            $labels = [
102
-                'Pending' => __('Unapproved', 'site-reviews'),
103
-                'Pending Review' => __('Unapproved', 'site-reviews'),
104
-                'Privately Published' => __('Privately Approved', 'site-reviews'),
105
-                'Publish' => __('Approve', 'site-reviews'),
106
-                'Published' => __('Approved', 'site-reviews'),
107
-                'Save as Pending' => __('Save as Unapproved', 'site-reviews'),
108
-            ];
109
-        }
110
-        return $labels;
111
-    }
93
+	/**
94
+	 * Store the labels to avoid unnecessary loops.
95
+	 * @return array
96
+	 */
97
+	protected function getStatusLabels()
98
+	{
99
+		static $labels;
100
+		if (empty($labels)) {
101
+			$labels = [
102
+				'Pending' => __('Unapproved', 'site-reviews'),
103
+				'Pending Review' => __('Unapproved', 'site-reviews'),
104
+				'Privately Published' => __('Privately Approved', 'site-reviews'),
105
+				'Publish' => __('Approve', 'site-reviews'),
106
+				'Published' => __('Approved', 'site-reviews'),
107
+				'Save as Pending' => __('Save as Unapproved', 'site-reviews'),
108
+			];
109
+		}
110
+		return $labels;
111
+	}
112 112
 }
Please login to merge, or discard this patch.
plugin/Blocks/SiteReviewsFormBlock.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -7,115 +7,115 @@
 block discarded – undo
7 7
 
8 8
 class SiteReviewsFormBlock extends BlockGenerator
9 9
 {
10
-    /**
11
-     * @return array
12
-     */
13
-    public function attributes()
14
-    {
15
-        return [
16
-            'assign_to' => [
17
-                'default' => '',
18
-                'type' => 'string',
19
-            ],
20
-            'category' => [
21
-                'default' => '',
22
-                'type' => 'string',
23
-            ],
24
-            'className' => [
25
-                'default' => '',
26
-                'type' => 'string',
27
-            ],
28
-            'hide' => [
29
-                'default' => '',
30
-                'type' => 'string',
31
-            ],
32
-            'id' => [
33
-                'default' => '',
34
-                'type' => 'string',
35
-            ],
36
-        ];
37
-    }
10
+	/**
11
+	 * @return array
12
+	 */
13
+	public function attributes()
14
+	{
15
+		return [
16
+			'assign_to' => [
17
+				'default' => '',
18
+				'type' => 'string',
19
+			],
20
+			'category' => [
21
+				'default' => '',
22
+				'type' => 'string',
23
+			],
24
+			'className' => [
25
+				'default' => '',
26
+				'type' => 'string',
27
+			],
28
+			'hide' => [
29
+				'default' => '',
30
+				'type' => 'string',
31
+			],
32
+			'id' => [
33
+				'default' => '',
34
+				'type' => 'string',
35
+			],
36
+		];
37
+	}
38 38
 
39
-    /**
40
-     * @return string
41
-     */
42
-    public function render(array $attributes)
43
-    {
44
-        $attributes['class'] = $attributes['className'];
45
-        $shortcode = glsr(Shortcode::class);
46
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
47
-            $this->filterFormFields();
48
-            $this->filterRatingField();
49
-            $this->filterShortcodeClass();
50
-            $this->filterSubmitButton();
51
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
52
-                $this->filterInterpolation();
53
-            }
54
-        }
55
-        return $shortcode->buildShortcode($attributes);
56
-    }
39
+	/**
40
+	 * @return string
41
+	 */
42
+	public function render(array $attributes)
43
+	{
44
+		$attributes['class'] = $attributes['className'];
45
+		$shortcode = glsr(Shortcode::class);
46
+		if ('edit' == filter_input(INPUT_GET, 'context')) {
47
+			$this->filterFormFields();
48
+			$this->filterRatingField();
49
+			$this->filterShortcodeClass();
50
+			$this->filterSubmitButton();
51
+			if (!$this->hasVisibleFields($shortcode, $attributes)) {
52
+				$this->filterInterpolation();
53
+			}
54
+		}
55
+		return $shortcode->buildShortcode($attributes);
56
+	}
57 57
 
58
-    /**
59
-     * @return void
60
-     */
61
-    protected function filterFormFields()
62
-    {
63
-        add_filter('site-reviews/config/forms/submission-form', function (array $config) {
64
-            array_walk($config, function (&$field) {
65
-                $field['disabled'] = true;
66
-                $field['tabindex'] = '-1';
67
-            });
68
-            return $config;
69
-        });
70
-    }
58
+	/**
59
+	 * @return void
60
+	 */
61
+	protected function filterFormFields()
62
+	{
63
+		add_filter('site-reviews/config/forms/submission-form', function (array $config) {
64
+			array_walk($config, function (&$field) {
65
+				$field['disabled'] = true;
66
+				$field['tabindex'] = '-1';
67
+			});
68
+			return $config;
69
+		});
70
+	}
71 71
 
72
-    /**
73
-     * @return void
74
-     */
75
-    protected function filterInterpolation()
76
-    {
77
-        add_filter('site-reviews/interpolate/reviews-form', function ($context) {
78
-            $context['class'] = 'glsr-default glsr-block-disabled';
79
-            $context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews');
80
-            $context['response'] = '';
81
-            $context['submit_button'] = '';
82
-            return $context;
83
-        });
84
-    }
72
+	/**
73
+	 * @return void
74
+	 */
75
+	protected function filterInterpolation()
76
+	{
77
+		add_filter('site-reviews/interpolate/reviews-form', function ($context) {
78
+			$context['class'] = 'glsr-default glsr-block-disabled';
79
+			$context['fields'] = __('You have hidden all of the fields for this block.', 'site-reviews');
80
+			$context['response'] = '';
81
+			$context['submit_button'] = '';
82
+			return $context;
83
+		});
84
+	}
85 85
 
86
-    /**
87
-     * @return void
88
-     */
89
-    protected function filterRatingField()
90
-    {
91
-        add_filter('site-reviews/rendered/field', function ($html, $type, $args) {
92
-            if ('rating' == $args['path']) {
93
-                $stars = '<span class="glsr-stars">';
94
-                $stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class));
95
-                $stars.= '</span>';
96
-                $html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/u', '$1'.$stars.'$4', $html);
97
-            }
98
-            return $html;
99
-        }, 10, 3);
100
-    }
86
+	/**
87
+	 * @return void
88
+	 */
89
+	protected function filterRatingField()
90
+	{
91
+		add_filter('site-reviews/rendered/field', function ($html, $type, $args) {
92
+			if ('rating' == $args['path']) {
93
+				$stars = '<span class="glsr-stars">';
94
+				$stars.= str_repeat('<span class="glsr-star glsr-star-empty" aria-hidden="true"></span>', (int) glsr()->constant('MAX_RATING', Rating::class));
95
+				$stars.= '</span>';
96
+				$html = preg_replace('/(.*)(<select.*)(<\/select>)(.*)/u', '$1'.$stars.'$4', $html);
97
+			}
98
+			return $html;
99
+		}, 10, 3);
100
+	}
101 101
 
102
-    /**
103
-     * @return void
104
-     */
105
-    protected function filterShortcodeClass()
106
-    {
107
-        add_filter('site-reviews/style', function () {
108
-            return 'default';
109
-        });
110
-    }
102
+	/**
103
+	 * @return void
104
+	 */
105
+	protected function filterShortcodeClass()
106
+	{
107
+		add_filter('site-reviews/style', function () {
108
+			return 'default';
109
+		});
110
+	}
111 111
 
112
-    /**
113
-     * @return void
114
-     */
115
-    protected function filterSubmitButton()
116
-    {
117
-        add_filter('site-reviews/rendered/template/form/submit-button', function ($template) {
118
-            return str_replace('type="submit"', 'tabindex="-1"', $template);
119
-        });
120
-    }
112
+	/**
113
+	 * @return void
114
+	 */
115
+	protected function filterSubmitButton()
116
+	{
117
+		add_filter('site-reviews/rendered/template/form/submit-button', function ($template) {
118
+			return str_replace('type="submit"', 'tabindex="-1"', $template);
119
+		});
120
+	}
121 121
 }
Please login to merge, or discard this patch.
plugin/Blocks/SiteReviewsBlock.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -6,124 +6,124 @@
 block discarded – undo
6 6
 
7 7
 class SiteReviewsBlock extends BlockGenerator
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function attributes()
13
-    {
14
-        return [
15
-            'assigned_to' => [
16
-                'default' => '',
17
-                'type' => 'string',
18
-            ],
19
-            'category' => [
20
-                'default' => '',
21
-                'type' => 'string',
22
-            ],
23
-            'className' => [
24
-                'default' => '',
25
-                'type' => 'string',
26
-            ],
27
-            'display' => [
28
-                'default' => 5,
29
-                'type' => 'number',
30
-            ],
31
-            'hide' => [
32
-                'default' => '',
33
-                'type' => 'string',
34
-            ],
35
-            'id' => [
36
-                'default' => '',
37
-                'type' => 'string',
38
-            ],
39
-            'pagination' => [
40
-                'default' => '',
41
-                'type' => 'string',
42
-            ],
43
-            'post_id' => [
44
-                'default' => '',
45
-                'type' => 'string',
46
-            ],
47
-            'rating' => [
48
-                'default' => 0,
49
-                'type' => 'number',
50
-            ],
51
-            'schema' => [
52
-                'default' => false,
53
-                'type' => 'boolean',
54
-            ],
55
-            'type' => [
56
-                'default' => 'local',
57
-                'type' => 'string',
58
-            ],
59
-        ];
60
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function attributes()
13
+	{
14
+		return [
15
+			'assigned_to' => [
16
+				'default' => '',
17
+				'type' => 'string',
18
+			],
19
+			'category' => [
20
+				'default' => '',
21
+				'type' => 'string',
22
+			],
23
+			'className' => [
24
+				'default' => '',
25
+				'type' => 'string',
26
+			],
27
+			'display' => [
28
+				'default' => 5,
29
+				'type' => 'number',
30
+			],
31
+			'hide' => [
32
+				'default' => '',
33
+				'type' => 'string',
34
+			],
35
+			'id' => [
36
+				'default' => '',
37
+				'type' => 'string',
38
+			],
39
+			'pagination' => [
40
+				'default' => '',
41
+				'type' => 'string',
42
+			],
43
+			'post_id' => [
44
+				'default' => '',
45
+				'type' => 'string',
46
+			],
47
+			'rating' => [
48
+				'default' => 0,
49
+				'type' => 'number',
50
+			],
51
+			'schema' => [
52
+				'default' => false,
53
+				'type' => 'boolean',
54
+			],
55
+			'type' => [
56
+				'default' => 'local',
57
+				'type' => 'string',
58
+			],
59
+		];
60
+	}
61 61
 
62
-    /**
63
-     * @return string
64
-     */
65
-    public function render(array $attributes)
66
-    {
67
-        $attributes['class'] = $attributes['className'];
68
-        $shortcode = glsr(Shortcode::class);
69
-        if ('edit' == filter_input(INPUT_GET, 'context')) {
70
-            $attributes = $this->normalize($attributes);
71
-            $this->filterReviewLinks();
72
-            $this->filterShortcodeClass();
73
-            $this->filterShowMoreLinks('content');
74
-            $this->filterShowMoreLinks('response');
75
-            if (!$this->hasVisibleFields($shortcode, $attributes)) {
76
-                $this->filterInterpolation();
77
-            }
78
-        }
79
-        return $shortcode->buildShortcode($attributes);
80
-    }
62
+	/**
63
+	 * @return string
64
+	 */
65
+	public function render(array $attributes)
66
+	{
67
+		$attributes['class'] = $attributes['className'];
68
+		$shortcode = glsr(Shortcode::class);
69
+		if ('edit' == filter_input(INPUT_GET, 'context')) {
70
+			$attributes = $this->normalize($attributes);
71
+			$this->filterReviewLinks();
72
+			$this->filterShortcodeClass();
73
+			$this->filterShowMoreLinks('content');
74
+			$this->filterShowMoreLinks('response');
75
+			if (!$this->hasVisibleFields($shortcode, $attributes)) {
76
+				$this->filterInterpolation();
77
+			}
78
+		}
79
+		return $shortcode->buildShortcode($attributes);
80
+	}
81 81
 
82
-    /**
83
-     * @return void
84
-     */
85
-    protected function filterInterpolation()
86
-    {
87
-        add_filter('site-reviews/interpolate/reviews', function ($context) {
88
-            $context['class'] = 'glsr-default glsr-block-disabled';
89
-            $context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews');
90
-            return $context;
91
-        });
92
-    }
82
+	/**
83
+	 * @return void
84
+	 */
85
+	protected function filterInterpolation()
86
+	{
87
+		add_filter('site-reviews/interpolate/reviews', function ($context) {
88
+			$context['class'] = 'glsr-default glsr-block-disabled';
89
+			$context['reviews'] = __('You have hidden all of the fields for this block.', 'site-reviews');
90
+			return $context;
91
+		});
92
+	}
93 93
 
94
-    /**
95
-     * @return void
96
-     */
97
-    protected function filterReviewLinks()
98
-    {
99
-        add_filter('site-reviews/rendered/template/reviews', function ($template) {
100
-            return str_replace('<a', '<a tabindex="-1"', $template);
101
-        });
102
-    }
94
+	/**
95
+	 * @return void
96
+	 */
97
+	protected function filterReviewLinks()
98
+	{
99
+		add_filter('site-reviews/rendered/template/reviews', function ($template) {
100
+			return str_replace('<a', '<a tabindex="-1"', $template);
101
+		});
102
+	}
103 103
 
104
-    /**
105
-     * @return void
106
-     */
107
-    protected function filterShortcodeClass()
108
-    {
109
-        add_filter('site-reviews/style', function () {
110
-            return 'default';
111
-        });
112
-    }
104
+	/**
105
+	 * @return void
106
+	 */
107
+	protected function filterShortcodeClass()
108
+	{
109
+		add_filter('site-reviews/style', function () {
110
+			return 'default';
111
+		});
112
+	}
113 113
 
114
-    /**
115
-     * @param string $field
116
-     * @return void
117
-     */
118
-    protected function filterShowMoreLinks($field)
119
-    {
120
-        add_filter('site-reviews/review/wrap/'.$field, function ($value) {
121
-            $value = preg_replace(
122
-                '/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/us',
123
-                '$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5',
124
-                $value
125
-            );
126
-            return $value;
127
-        });
128
-    }
114
+	/**
115
+	 * @param string $field
116
+	 * @return void
117
+	 */
118
+	protected function filterShowMoreLinks($field)
119
+	{
120
+		add_filter('site-reviews/review/wrap/'.$field, function ($value) {
121
+			$value = preg_replace(
122
+				'/(.*)(<span class="glsr-hidden)(.*)(<\/span>)(.*)/us',
123
+				'$1... <a href="#" class="glsr-read-more" tabindex="-1">'.__('Show more', 'site-reviews').'</a>$5',
124
+				$value
125
+			);
126
+			return $value;
127
+		});
128
+	}
129 129
 }
Please login to merge, or discard this patch.
plugin/Controllers/TrustalyzeController.php 1 patch
Indentation   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -12,210 +12,210 @@
 block discarded – undo
12 12
 
13 13
 class TrustalyzeController extends Controller
14 14
 {
15
-    protected $apiKey = 'settings.general.trustalyze_serial';
16
-    protected $emailKey = 'settings.general.trustalyze_email';
17
-    protected $enabledKey = 'settings.general.trustalyze';
18
-    protected $trustalyzeKey = '_glsr_trustalyze';
19
-
20
-    /**
21
-     * @return array
22
-     * @filter site-reviews/settings/callback
23
-     */
24
-    public function filterSettingsCallback(array $settings)
25
-    {
26
-        if ('yes' !== Arr::get($settings, $this->enabledKey)) {
27
-            return $settings;
28
-        }
29
-        $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings);
30
-        $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings);
31
-        $isAccountVerified = glsr(OptionManager::class)->getWP($this->trustalyzeKey, false);
32
-        if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) {
33
-            $settings = $this->sanitizeTrustalyzeSettings($settings);
34
-        }
35
-        return $settings;
36
-    }
37
-
38
-    /**
39
-     * @param string $template
40
-     * @return array
41
-     * @filter site-reviews/interpolate/partials/form/table-row-multiple
42
-     */
43
-    public function filterSettingsTableRow(array $context, $template, array $data)
44
-    {
45
-        if ($this->enabledKey !== Arr::get($data, 'field.path')) {
46
-            return $context;
47
-        }
48
-        $isAccountValidated = !empty(glsr(OptionManager::class)->getWP($this->trustalyzeKey));
49
-        $isIntegrationEnabled = glsr(OptionManager::class)->getBool('settings.general.trustalyze');
50
-        if ($isAccountValidated && $isIntegrationEnabled) {
51
-            return $context;
52
-        }
53
-        $context['field'].= $this->buildCreateButton();
54
-        return $context;
55
-    }
56
-
57
-    /**
58
-     * Triggered when a review is created.
59
-     * @return void
60
-     * @action site-reviews/review/created
61
-     */
62
-    public function onCreated(Review $review)
63
-    {
64
-        if (!$this->canPostReview($review)) {
65
-            return;
66
-        }
67
-        $trustalyze = glsr(Trustalyze::class)->sendReview($review);
68
-        if ($trustalyze->success) {
69
-            glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id);
70
-        }
71
-    }
72
-
73
-    /**
74
-     * Triggered when a review is reverted to its original title/content/date_timestamp.
75
-     * @return void
76
-     * @action site-reviews/review/reverted
77
-     */
78
-    public function onReverted(Review $review)
79
-    {
80
-        if (!$this->canPostReview($review)) {
81
-            return;
82
-        }
83
-        $trustalyze = glsr(Trustalyze::class)->sendReview($review);
84
-        if ($trustalyze->success) {
85
-            glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id);
86
-        }
87
-    }
88
-
89
-    /**
90
-     * Triggered when an existing review is updated.
91
-     * @return void
92
-     * @action site-reviews/review/saved
93
-     */
94
-    public function onSaved(Review $review)
95
-    {
96
-        if (!$this->canPostReview($review)) {
97
-            return;
98
-        }
99
-        $trustalyze = glsr(Trustalyze::class)->sendReview($review);
100
-        if ($trustalyze->success) {
101
-            glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id);
102
-        }
103
-    }
104
-
105
-    /**
106
-     * Triggered when a review's response is added or updated.
107
-     * @param int $metaId
108
-     * @param int $postId
109
-     * @param string $metaKey
110
-     * @return void
111
-     * @action updated_postmeta
112
-     */
113
-    public function onUpdatedMeta($metaId, $postId, $metaKey)
114
-    {
115
-        $review = glsr_get_review($postId);
116
-        if (!$this->canPostResponse($review) || '_response' !== $metaKey) {
117
-            return;
118
-        }
119
-        $trustalyze = glsr(Trustalyze::class)->sendReviewResponse($review);
120
-        if ($trustalyze->success) {
121
-            glsr(Database::class)->set($review->ID, 'trustalyze_response', true);
122
-        }
123
-    }
124
-
125
-    /**
126
-     * @return string
127
-     */
128
-    protected function buildCreateButton()
129
-    {
130
-        return glsr(Builder::class)->a(__('Create Your Trustalyze Account', 'site-reviews'), [
131
-            'class' => 'button',
132
-            'href' => Trustalyze::WEB_URL,
133
-            'target' => '_blank',
134
-        ]);
135
-    }
136
-
137
-    /**
138
-     * @return bool
139
-     */
140
-    protected function canPostResponse(Review $review)
141
-    {
142
-        $requiredValues = [
143
-            glsr(Database::class)->get($review->ID, 'trustalyze'),
144
-            $review->response,
145
-            $review->review_id,
146
-        ];
147
-        return $this->canProceed($review, 'trustalyze_response')
148
-            && 'publish' === $review->status
149
-            && 3 === count(array_filter($requiredValues));
150
-    }
151
-
152
-    /**
153
-     * @return bool
154
-     */
155
-    protected function canPostReview(Review $review)
156
-    {
157
-        $requiredValues = [
158
-            $review->author,
159
-            $review->content,
160
-            $review->rating,
161
-            $review->review_id,
162
-            $review->title,
163
-        ];
164
-        return $this->canProceed($review)
165
-            && 'publish' === $review->status
166
-            && 5 === count(array_filter($requiredValues));
167
-    }
168
-
169
-    /**
170
-     * @param string $metaKey
171
-     * @return bool
172
-     */
173
-    protected function canProceed(Review $review, $metaKey = 'trustalyze')
174
-    {
175
-        return glsr(OptionManager::class)->getBool($this->enabledKey)
176
-            && $this->isReviewPostId($review->ID)
177
-            && !$this->hasMetaKey($review, $metaKey);
178
-    }
179
-
180
-    /**
181
-     * @param string $metaKey
182
-     * @return bool
183
-     */
184
-    protected function hasMetaKey(Review $review, $metaKey = 'trustalyze')
185
-    {
186
-        return '' !== glsr(Database::class)->get($review->ID, $metaKey);
187
-    }
188
-
189
-    /**
190
-     * @param string $key
191
-     * @return bool
192
-     */
193
-    protected function isEmptyOrModified($key, array $settings)
194
-    {
195
-        $oldValue = glsr_get_option($key);
196
-        $newValue = Arr::get($settings, $key);
197
-        return empty($newValue) || $newValue !== $oldValue;
198
-    }
199
-
200
-    /**
201
-     * @return array
202
-     */
203
-    protected function sanitizeTrustalyzeSettings(array $settings)
204
-    {
205
-        $trustalyze = glsr(Trustalyze::class)->activateKey(
206
-            Arr::get($settings, $this->apiKey),
207
-            Arr::get($settings, $this->emailKey)
208
-        );
209
-        if ($trustalyze->success) {
210
-            update_option($this->trustalyzeKey, Arr::get($trustalyze->response, 'producttype'));
211
-        } else {
212
-            delete_option($this->trustalyzeKey);
213
-            $settings = Arr::set($settings, $this->enabledKey, 'no');
214
-            glsr(Notice::class)->addError(sprintf(
215
-                __('Your Trustalyze account details could not be verified, please try again. %s', 'site-reviews'),
216
-                '('.$trustalyze->message.')'
217
-            ));
218
-        }
219
-        return $settings;
220
-    }
15
+	protected $apiKey = 'settings.general.trustalyze_serial';
16
+	protected $emailKey = 'settings.general.trustalyze_email';
17
+	protected $enabledKey = 'settings.general.trustalyze';
18
+	protected $trustalyzeKey = '_glsr_trustalyze';
19
+
20
+	/**
21
+	 * @return array
22
+	 * @filter site-reviews/settings/callback
23
+	 */
24
+	public function filterSettingsCallback(array $settings)
25
+	{
26
+		if ('yes' !== Arr::get($settings, $this->enabledKey)) {
27
+			return $settings;
28
+		}
29
+		$isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings);
30
+		$isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings);
31
+		$isAccountVerified = glsr(OptionManager::class)->getWP($this->trustalyzeKey, false);
32
+		if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) {
33
+			$settings = $this->sanitizeTrustalyzeSettings($settings);
34
+		}
35
+		return $settings;
36
+	}
37
+
38
+	/**
39
+	 * @param string $template
40
+	 * @return array
41
+	 * @filter site-reviews/interpolate/partials/form/table-row-multiple
42
+	 */
43
+	public function filterSettingsTableRow(array $context, $template, array $data)
44
+	{
45
+		if ($this->enabledKey !== Arr::get($data, 'field.path')) {
46
+			return $context;
47
+		}
48
+		$isAccountValidated = !empty(glsr(OptionManager::class)->getWP($this->trustalyzeKey));
49
+		$isIntegrationEnabled = glsr(OptionManager::class)->getBool('settings.general.trustalyze');
50
+		if ($isAccountValidated && $isIntegrationEnabled) {
51
+			return $context;
52
+		}
53
+		$context['field'].= $this->buildCreateButton();
54
+		return $context;
55
+	}
56
+
57
+	/**
58
+	 * Triggered when a review is created.
59
+	 * @return void
60
+	 * @action site-reviews/review/created
61
+	 */
62
+	public function onCreated(Review $review)
63
+	{
64
+		if (!$this->canPostReview($review)) {
65
+			return;
66
+		}
67
+		$trustalyze = glsr(Trustalyze::class)->sendReview($review);
68
+		if ($trustalyze->success) {
69
+			glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id);
70
+		}
71
+	}
72
+
73
+	/**
74
+	 * Triggered when a review is reverted to its original title/content/date_timestamp.
75
+	 * @return void
76
+	 * @action site-reviews/review/reverted
77
+	 */
78
+	public function onReverted(Review $review)
79
+	{
80
+		if (!$this->canPostReview($review)) {
81
+			return;
82
+		}
83
+		$trustalyze = glsr(Trustalyze::class)->sendReview($review);
84
+		if ($trustalyze->success) {
85
+			glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id);
86
+		}
87
+	}
88
+
89
+	/**
90
+	 * Triggered when an existing review is updated.
91
+	 * @return void
92
+	 * @action site-reviews/review/saved
93
+	 */
94
+	public function onSaved(Review $review)
95
+	{
96
+		if (!$this->canPostReview($review)) {
97
+			return;
98
+		}
99
+		$trustalyze = glsr(Trustalyze::class)->sendReview($review);
100
+		if ($trustalyze->success) {
101
+			glsr(Database::class)->set($review->ID, 'trustalyze', $trustalyze->review_id);
102
+		}
103
+	}
104
+
105
+	/**
106
+	 * Triggered when a review's response is added or updated.
107
+	 * @param int $metaId
108
+	 * @param int $postId
109
+	 * @param string $metaKey
110
+	 * @return void
111
+	 * @action updated_postmeta
112
+	 */
113
+	public function onUpdatedMeta($metaId, $postId, $metaKey)
114
+	{
115
+		$review = glsr_get_review($postId);
116
+		if (!$this->canPostResponse($review) || '_response' !== $metaKey) {
117
+			return;
118
+		}
119
+		$trustalyze = glsr(Trustalyze::class)->sendReviewResponse($review);
120
+		if ($trustalyze->success) {
121
+			glsr(Database::class)->set($review->ID, 'trustalyze_response', true);
122
+		}
123
+	}
124
+
125
+	/**
126
+	 * @return string
127
+	 */
128
+	protected function buildCreateButton()
129
+	{
130
+		return glsr(Builder::class)->a(__('Create Your Trustalyze Account', 'site-reviews'), [
131
+			'class' => 'button',
132
+			'href' => Trustalyze::WEB_URL,
133
+			'target' => '_blank',
134
+		]);
135
+	}
136
+
137
+	/**
138
+	 * @return bool
139
+	 */
140
+	protected function canPostResponse(Review $review)
141
+	{
142
+		$requiredValues = [
143
+			glsr(Database::class)->get($review->ID, 'trustalyze'),
144
+			$review->response,
145
+			$review->review_id,
146
+		];
147
+		return $this->canProceed($review, 'trustalyze_response')
148
+			&& 'publish' === $review->status
149
+			&& 3 === count(array_filter($requiredValues));
150
+	}
151
+
152
+	/**
153
+	 * @return bool
154
+	 */
155
+	protected function canPostReview(Review $review)
156
+	{
157
+		$requiredValues = [
158
+			$review->author,
159
+			$review->content,
160
+			$review->rating,
161
+			$review->review_id,
162
+			$review->title,
163
+		];
164
+		return $this->canProceed($review)
165
+			&& 'publish' === $review->status
166
+			&& 5 === count(array_filter($requiredValues));
167
+	}
168
+
169
+	/**
170
+	 * @param string $metaKey
171
+	 * @return bool
172
+	 */
173
+	protected function canProceed(Review $review, $metaKey = 'trustalyze')
174
+	{
175
+		return glsr(OptionManager::class)->getBool($this->enabledKey)
176
+			&& $this->isReviewPostId($review->ID)
177
+			&& !$this->hasMetaKey($review, $metaKey);
178
+	}
179
+
180
+	/**
181
+	 * @param string $metaKey
182
+	 * @return bool
183
+	 */
184
+	protected function hasMetaKey(Review $review, $metaKey = 'trustalyze')
185
+	{
186
+		return '' !== glsr(Database::class)->get($review->ID, $metaKey);
187
+	}
188
+
189
+	/**
190
+	 * @param string $key
191
+	 * @return bool
192
+	 */
193
+	protected function isEmptyOrModified($key, array $settings)
194
+	{
195
+		$oldValue = glsr_get_option($key);
196
+		$newValue = Arr::get($settings, $key);
197
+		return empty($newValue) || $newValue !== $oldValue;
198
+	}
199
+
200
+	/**
201
+	 * @return array
202
+	 */
203
+	protected function sanitizeTrustalyzeSettings(array $settings)
204
+	{
205
+		$trustalyze = glsr(Trustalyze::class)->activateKey(
206
+			Arr::get($settings, $this->apiKey),
207
+			Arr::get($settings, $this->emailKey)
208
+		);
209
+		if ($trustalyze->success) {
210
+			update_option($this->trustalyzeKey, Arr::get($trustalyze->response, 'producttype'));
211
+		} else {
212
+			delete_option($this->trustalyzeKey);
213
+			$settings = Arr::set($settings, $this->enabledKey, 'no');
214
+			glsr(Notice::class)->addError(sprintf(
215
+				__('Your Trustalyze account details could not be verified, please try again. %s', 'site-reviews'),
216
+				'('.$trustalyze->message.')'
217
+			));
218
+		}
219
+		return $settings;
220
+	}
221 221
 }
Please login to merge, or discard this patch.