@@ -9,59 +9,59 @@ |
||
9 | 9 | |
10 | 10 | class Upgrade_4_0_0 |
11 | 11 | { |
12 | - public function __construct() |
|
13 | - { |
|
14 | - $this->migrateSettings(); |
|
15 | - $this->protectMetaKeys(); |
|
16 | - $this->deleteSessions(); |
|
17 | - delete_transient(Application::ID.'_cloudflare_ips'); |
|
18 | - } |
|
12 | + public function __construct() |
|
13 | + { |
|
14 | + $this->migrateSettings(); |
|
15 | + $this->protectMetaKeys(); |
|
16 | + $this->deleteSessions(); |
|
17 | + delete_transient(Application::ID.'_cloudflare_ips'); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function deleteSessions() |
|
24 | - { |
|
25 | - global $wpdb; |
|
26 | - $wpdb->query(" |
|
20 | + /** |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function deleteSessions() |
|
24 | + { |
|
25 | + global $wpdb; |
|
26 | + $wpdb->query(" |
|
27 | 27 | DELETE |
28 | 28 | FROM {$wpdb->options} |
29 | 29 | WHERE option_name LIKE '_glsr_session%' |
30 | 30 | "); |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function migrateSettings() |
|
37 | - { |
|
38 | - $settingsKey = glsr(Helper::class)->snakeCase(Application::ID.'-v3'); |
|
39 | - if ($settings = get_option($settingsKey)) { |
|
40 | - $multilingual = 'yes' == glsr(Helper::class)->dataGet($settings, 'settings.general.support.polylang') |
|
41 | - ? 'polylang' |
|
42 | - : ''; |
|
43 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.support.multilingual', $multilingual); |
|
44 | - $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.blacklist.integration', ''); |
|
45 | - unset($settings['settings']['general']['support']['polylang']); |
|
46 | - add_option(OptionManager::databaseKey(), $settings); |
|
47 | - } |
|
48 | - } |
|
33 | + /** |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function migrateSettings() |
|
37 | + { |
|
38 | + $settingsKey = glsr(Helper::class)->snakeCase(Application::ID.'-v3'); |
|
39 | + if ($settings = get_option($settingsKey)) { |
|
40 | + $multilingual = 'yes' == glsr(Helper::class)->dataGet($settings, 'settings.general.support.polylang') |
|
41 | + ? 'polylang' |
|
42 | + : ''; |
|
43 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.general.support.multilingual', $multilingual); |
|
44 | + $settings = glsr(Helper::class)->dataSet($settings, 'settings.submissions.blacklist.integration', ''); |
|
45 | + unset($settings['settings']['general']['support']['polylang']); |
|
46 | + add_option(OptionManager::databaseKey(), $settings); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function protectMetaKeys() |
|
54 | - { |
|
55 | - global $wpdb; |
|
56 | - $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | - $keys = implode("','", $keys); |
|
58 | - $postType = Application::POST_TYPE; |
|
59 | - $wpdb->query(" |
|
50 | + /** |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function protectMetaKeys() |
|
54 | + { |
|
55 | + global $wpdb; |
|
56 | + $keys = array_keys(glsr(CreateReviewDefaults::class)->defaults()); |
|
57 | + $keys = implode("','", $keys); |
|
58 | + $postType = Application::POST_TYPE; |
|
59 | + $wpdb->query(" |
|
60 | 60 | UPDATE {$wpdb->postmeta} pm |
61 | 61 | INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id |
62 | 62 | SET pm.meta_key = CONCAT('_', pm.meta_key) |
63 | 63 | WHERE pm.meta_key IN ('{$keys}') |
64 | 64 | AND p.post_type = '{$postType}' |
65 | 65 | "); |
66 | - } |
|
66 | + } |
|
67 | 67 | } |
@@ -8,114 +8,114 @@ |
||
8 | 8 | |
9 | 9 | class SettingsController extends Controller |
10 | 10 | { |
11 | - /** |
|
12 | - * @param mixed $input |
|
13 | - * @return array |
|
14 | - * @callback register_setting |
|
15 | - */ |
|
16 | - public function callbackRegisterSettings($input) |
|
17 | - { |
|
18 | - if (!is_array($input)) { |
|
19 | - $input = ['settings' => []]; |
|
20 | - } |
|
21 | - if ('settings' == key($input)) { |
|
22 | - $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
23 | - $options = $this->sanitizeGeneral($input, $options); |
|
24 | - $options = $this->sanitizeSubmissions($input, $options); |
|
25 | - $options = $this->sanitizeTranslations($input, $options); |
|
26 | - if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | - glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
28 | - } |
|
29 | - return $options; |
|
30 | - } |
|
31 | - return $input; |
|
32 | - } |
|
11 | + /** |
|
12 | + * @param mixed $input |
|
13 | + * @return array |
|
14 | + * @callback register_setting |
|
15 | + */ |
|
16 | + public function callbackRegisterSettings($input) |
|
17 | + { |
|
18 | + if (!is_array($input)) { |
|
19 | + $input = ['settings' => []]; |
|
20 | + } |
|
21 | + if ('settings' == key($input)) { |
|
22 | + $options = array_replace_recursive(glsr(OptionManager::class)->all(), $input); |
|
23 | + $options = $this->sanitizeGeneral($input, $options); |
|
24 | + $options = $this->sanitizeSubmissions($input, $options); |
|
25 | + $options = $this->sanitizeTranslations($input, $options); |
|
26 | + if (filter_input(INPUT_POST, 'option_page') == Application::ID.'-settings') { |
|
27 | + glsr(Notice::class)->addSuccess(__('Settings updated.', 'site-reviews')); |
|
28 | + } |
|
29 | + return $options; |
|
30 | + } |
|
31 | + return $input; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @return void |
|
36 | - * @action admin_init |
|
37 | - */ |
|
38 | - public function registerSettings() |
|
39 | - { |
|
40 | - register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | - 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
42 | - ]); |
|
43 | - } |
|
34 | + /** |
|
35 | + * @return void |
|
36 | + * @action admin_init |
|
37 | + */ |
|
38 | + public function registerSettings() |
|
39 | + { |
|
40 | + register_setting(Application::ID.'-settings', OptionManager::databaseKey(), [ |
|
41 | + 'sanitize_callback' => [$this, 'callbackRegisterSettings'], |
|
42 | + ]); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - protected function sanitizeGeneral(array $input, array $options) |
|
49 | - { |
|
50 | - $inputForm = $input['settings']['general']; |
|
51 | - if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) { |
|
52 | - $options['settings']['general']['support']['multilingual'] = ''; |
|
53 | - } |
|
54 | - if ('' == trim($inputForm['notification_message'])) { |
|
55 | - $options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message']; |
|
56 | - } |
|
57 | - $options['settings']['general']['notifications'] = glsr_get($inputForm, 'notifications', []); |
|
58 | - return $options; |
|
59 | - } |
|
45 | + /** |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + protected function sanitizeGeneral(array $input, array $options) |
|
49 | + { |
|
50 | + $inputForm = $input['settings']['general']; |
|
51 | + if (!$this->hasMultilingualIntegration($inputForm['support']['multilingual'])) { |
|
52 | + $options['settings']['general']['support']['multilingual'] = ''; |
|
53 | + } |
|
54 | + if ('' == trim($inputForm['notification_message'])) { |
|
55 | + $options['settings']['general']['notification_message'] = glsr()->defaults['settings']['general']['notification_message']; |
|
56 | + } |
|
57 | + $options['settings']['general']['notifications'] = glsr_get($inputForm, 'notifications', []); |
|
58 | + return $options; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return array |
|
63 | - */ |
|
64 | - protected function sanitizeSubmissions(array $input, array $options) |
|
65 | - { |
|
66 | - $inputForm = $input['settings']['submissions']; |
|
67 | - $options['settings']['submissions']['required'] = isset($inputForm['required']) |
|
68 | - ? $inputForm['required'] |
|
69 | - : []; |
|
70 | - return $options; |
|
71 | - } |
|
61 | + /** |
|
62 | + * @return array |
|
63 | + */ |
|
64 | + protected function sanitizeSubmissions(array $input, array $options) |
|
65 | + { |
|
66 | + $inputForm = $input['settings']['submissions']; |
|
67 | + $options['settings']['submissions']['required'] = isset($inputForm['required']) |
|
68 | + ? $inputForm['required'] |
|
69 | + : []; |
|
70 | + return $options; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return array |
|
75 | - */ |
|
76 | - protected function sanitizeTranslations(array $input, array $options) |
|
77 | - { |
|
78 | - if (isset($input['settings']['strings'])) { |
|
79 | - $options['settings']['strings'] = array_values(array_filter($input['settings']['strings'])); |
|
80 | - $allowedTags = [ |
|
81 | - 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
82 | - 'span' => ['class' => []], |
|
83 | - ]; |
|
84 | - array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
85 | - if (isset($string['s2'])) { |
|
86 | - $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
87 | - } |
|
88 | - if (isset($string['p2'])) { |
|
89 | - $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
90 | - } |
|
91 | - }); |
|
92 | - } |
|
93 | - return $options; |
|
94 | - } |
|
73 | + /** |
|
74 | + * @return array |
|
75 | + */ |
|
76 | + protected function sanitizeTranslations(array $input, array $options) |
|
77 | + { |
|
78 | + if (isset($input['settings']['strings'])) { |
|
79 | + $options['settings']['strings'] = array_values(array_filter($input['settings']['strings'])); |
|
80 | + $allowedTags = [ |
|
81 | + 'a' => ['class' => [], 'href' => [], 'target' => []], |
|
82 | + 'span' => ['class' => []], |
|
83 | + ]; |
|
84 | + array_walk($options['settings']['strings'], function (&$string) use ($allowedTags) { |
|
85 | + if (isset($string['s2'])) { |
|
86 | + $string['s2'] = wp_kses($string['s2'], $allowedTags); |
|
87 | + } |
|
88 | + if (isset($string['p2'])) { |
|
89 | + $string['p2'] = wp_kses($string['p2'], $allowedTags); |
|
90 | + } |
|
91 | + }); |
|
92 | + } |
|
93 | + return $options; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - protected function hasMultilingualIntegration($integration) |
|
100 | - { |
|
101 | - if (!in_array($integration, ['polylang', 'wpml'])) { |
|
102 | - return false; |
|
103 | - } |
|
104 | - $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration); |
|
105 | - if (!glsr($integrationClass)->isActive()) { |
|
106 | - glsr(Notice::class)->addError(sprintf( |
|
107 | - __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
108 | - constant($integrationClass.'::PLUGIN_NAME') |
|
109 | - )); |
|
110 | - return false; |
|
111 | - } elseif (!glsr($integrationClass)->isSupported()) { |
|
112 | - glsr(Notice::class)->addError(sprintf( |
|
113 | - __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
114 | - constant($integrationClass.'::PLUGIN_NAME'), |
|
115 | - constant($integrationClass.'::SUPPORTED_VERSION') |
|
116 | - )); |
|
117 | - return false; |
|
118 | - } |
|
119 | - return true; |
|
120 | - } |
|
96 | + /** |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + protected function hasMultilingualIntegration($integration) |
|
100 | + { |
|
101 | + if (!in_array($integration, ['polylang', 'wpml'])) { |
|
102 | + return false; |
|
103 | + } |
|
104 | + $integrationClass = 'GeminiLabs\SiteReviews\Modules\\'.ucfirst($integration); |
|
105 | + if (!glsr($integrationClass)->isActive()) { |
|
106 | + glsr(Notice::class)->addError(sprintf( |
|
107 | + __('Please install/activate the %s plugin to enable integration.', 'site-reviews'), |
|
108 | + constant($integrationClass.'::PLUGIN_NAME') |
|
109 | + )); |
|
110 | + return false; |
|
111 | + } elseif (!glsr($integrationClass)->isSupported()) { |
|
112 | + glsr(Notice::class)->addError(sprintf( |
|
113 | + __('Please update the %s plugin to v%s or greater to enable integration.', 'site-reviews'), |
|
114 | + constant($integrationClass.'::PLUGIN_NAME'), |
|
115 | + constant($integrationClass.'::SUPPORTED_VERSION') |
|
116 | + )); |
|
117 | + return false; |
|
118 | + } |
|
119 | + return true; |
|
120 | + } |
|
121 | 121 | } |
@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | interface MultilingualContract |
6 | 6 | { |
7 | - /** |
|
8 | - * @param int|string $postId |
|
9 | - * @return \WP_Post|void|null |
|
10 | - */ |
|
11 | - public function getPost($postId); |
|
7 | + /** |
|
8 | + * @param int|string $postId |
|
9 | + * @return \WP_Post|void|null |
|
10 | + */ |
|
11 | + public function getPost($postId); |
|
12 | 12 | |
13 | - /** |
|
14 | - * @return array |
|
15 | - */ |
|
16 | - public function getPostIds(array $postIds); |
|
13 | + /** |
|
14 | + * @return array |
|
15 | + */ |
|
16 | + public function getPostIds(array $postIds); |
|
17 | 17 | |
18 | - /** |
|
19 | - * @return bool |
|
20 | - */ |
|
21 | - public function isActive(); |
|
18 | + /** |
|
19 | + * @return bool |
|
20 | + */ |
|
21 | + public function isActive(); |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return bool |
|
25 | - */ |
|
26 | - public function isEnabled(); |
|
23 | + /** |
|
24 | + * @return bool |
|
25 | + */ |
|
26 | + public function isEnabled(); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @return bool |
|
30 | - */ |
|
31 | - public function isSupported(); |
|
28 | + /** |
|
29 | + * @return bool |
|
30 | + */ |
|
31 | + public function isSupported(); |
|
32 | 32 | } |
@@ -7,79 +7,79 @@ |
||
7 | 7 | |
8 | 8 | class Polylang implements Contract |
9 | 9 | { |
10 | - const PLUGIN_NAME = 'Polylang'; |
|
11 | - const SUPPORTED_VERSION = '2.3'; |
|
10 | + const PLUGIN_NAME = 'Polylang'; |
|
11 | + const SUPPORTED_VERSION = '2.3'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function getPost($postId) |
|
17 | - { |
|
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
20 | - return; |
|
21 | - } |
|
22 | - if ($this->isEnabled()) { |
|
23 | - $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | - } |
|
25 | - if (!empty($polylangPostId)) { |
|
26 | - $postId = $polylangPostId; |
|
27 | - } |
|
28 | - return get_post(intval($postId)); |
|
29 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function getPost($postId) |
|
17 | + { |
|
18 | + $postId = trim($postId); |
|
19 | + if (!is_numeric($postId)) { |
|
20 | + return; |
|
21 | + } |
|
22 | + if ($this->isEnabled()) { |
|
23 | + $polylangPostId = pll_get_post($postId, pll_get_post_language(get_the_ID())); |
|
24 | + } |
|
25 | + if (!empty($polylangPostId)) { |
|
26 | + $postId = $polylangPostId; |
|
27 | + } |
|
28 | + return get_post(intval($postId)); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritdoc} |
|
33 | - */ |
|
34 | - public function getPostIds(array $postIds) |
|
35 | - { |
|
36 | - if (!$this->isEnabled()) { |
|
37 | - return $postIds; |
|
38 | - } |
|
39 | - $newPostIds = []; |
|
40 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | - $newPostIds = array_merge( |
|
42 | - $newPostIds, |
|
43 | - array_values(pll_get_post_translations($postId)) |
|
44 | - ); |
|
45 | - } |
|
46 | - return $this->cleanIds($newPostIds); |
|
47 | - } |
|
31 | + /** |
|
32 | + * {@inheritdoc} |
|
33 | + */ |
|
34 | + public function getPostIds(array $postIds) |
|
35 | + { |
|
36 | + if (!$this->isEnabled()) { |
|
37 | + return $postIds; |
|
38 | + } |
|
39 | + $newPostIds = []; |
|
40 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
41 | + $newPostIds = array_merge( |
|
42 | + $newPostIds, |
|
43 | + array_values(pll_get_post_translations($postId)) |
|
44 | + ); |
|
45 | + } |
|
46 | + return $this->cleanIds($newPostIds); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - */ |
|
52 | - public function isActive() |
|
53 | - { |
|
54 | - return function_exists('PLL') |
|
55 | - && function_exists('pll_get_post') |
|
56 | - && function_exists('pll_get_post_language') |
|
57 | - && function_exists('pll_get_post_translations'); |
|
58 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + */ |
|
52 | + public function isActive() |
|
53 | + { |
|
54 | + return function_exists('PLL') |
|
55 | + && function_exists('pll_get_post') |
|
56 | + && function_exists('pll_get_post_language') |
|
57 | + && function_exists('pll_get_post_translations'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - public function isEnabled() |
|
64 | - { |
|
65 | - return $this->isActive() |
|
66 | - && 'polylang' == glsr(OptionManager::class)->get('settings.general.support.multilingual'); |
|
67 | - } |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + public function isEnabled() |
|
64 | + { |
|
65 | + return $this->isActive() |
|
66 | + && 'polylang' == glsr(OptionManager::class)->get('settings.general.support.multilingual'); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * {@inheritdoc} |
|
71 | - */ |
|
72 | - public function isSupported() |
|
73 | - { |
|
74 | - return defined('POLYLANG_VERSION') |
|
75 | - && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
76 | - } |
|
69 | + /** |
|
70 | + * {@inheritdoc} |
|
71 | + */ |
|
72 | + public function isSupported() |
|
73 | + { |
|
74 | + return defined('POLYLANG_VERSION') |
|
75 | + && version_compare(POLYLANG_VERSION, static::SUPPORTED_VERSION, '>='); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - protected function cleanIds(array $postIds) |
|
82 | - { |
|
83 | - return array_filter(array_unique($postIds)); |
|
84 | - } |
|
78 | + /** |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + protected function cleanIds(array $postIds) |
|
82 | + { |
|
83 | + return array_filter(array_unique($postIds)); |
|
84 | + } |
|
85 | 85 | } |
@@ -10,223 +10,223 @@ |
||
10 | 10 | |
11 | 11 | abstract class Shortcode implements ShortcodeContract |
12 | 12 | { |
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $partialName; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $shortcodeName; |
|
22 | - |
|
23 | - /** |
|
24 | - * @param string|array $atts |
|
25 | - * @param string $type |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function build($atts, array $args = [], $type = 'shortcode') |
|
29 | - { |
|
30 | - $this->partialName = $this->getShortcodePartialName(); |
|
31 | - $this->shortcodeName = $this->getShortcodeName(); |
|
32 | - $args = $this->normalizeArgs($args, $type); |
|
33 | - $atts = $this->normalizeAtts($atts, $type); |
|
34 | - $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
35 | - $title = !empty($atts['title']) |
|
36 | - ? $args['before_title'].$atts['title'].$args['after_title'] |
|
37 | - : ''; |
|
38 | - $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
39 | - return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param string|array $atts |
|
44 | - * @return string |
|
45 | - */ |
|
46 | - public function buildShortcode($atts = []) |
|
47 | - { |
|
48 | - return $this->build($atts); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function getDefaults($atts) |
|
55 | - { |
|
56 | - return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function getHideOptions() |
|
63 | - { |
|
64 | - $options = $this->hideOptions(); |
|
65 | - return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
72 | - { |
|
73 | - return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getShortcodeDefaultsClassName() |
|
80 | - { |
|
81 | - return glsr(Helper::class)->buildClassName( |
|
82 | - $this->getShortcodeClassName('Defaults'), |
|
83 | - 'Defaults' |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function getShortcodeName() |
|
91 | - { |
|
92 | - return glsr(Helper::class)->snakeCase($this->getShortcodeClassName()); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function getShortcodePartialName() |
|
99 | - { |
|
100 | - return glsr(Helper::class)->dashCase($this->getShortcodeClassName()); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param array|string $args |
|
105 | - * @param string $type |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - public function normalizeArgs($args, $type = 'shortcode') |
|
109 | - { |
|
110 | - $args = wp_parse_args($args, [ |
|
111 | - 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
|
112 | - 'after_widget' => '</div>', |
|
113 | - 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
|
114 | - 'after_title' => '</h3>', |
|
115 | - ]); |
|
116 | - return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param array|string $atts |
|
121 | - * @param string $type |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - public function normalizeAtts($atts, $type = 'shortcode') |
|
125 | - { |
|
126 | - $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
127 | - $atts = $this->getDefaults($atts); |
|
128 | - array_walk($atts, function (&$value, $key) { |
|
129 | - $methodName = glsr(Helper::class)->buildMethodName($key, 'normalize'); |
|
130 | - if (!method_exists($this, $methodName)) { |
|
131 | - return; |
|
132 | - } |
|
133 | - $value = $this->$methodName($value); |
|
134 | - }); |
|
135 | - return $atts; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @return array |
|
140 | - */ |
|
141 | - abstract protected function hideOptions(); |
|
142 | - |
|
143 | - /** |
|
144 | - * @param string $postId |
|
145 | - * @return int|string |
|
146 | - */ |
|
147 | - protected function normalizeAssignedTo($postId) |
|
148 | - { |
|
149 | - if ('parent_id' == $postId) { |
|
150 | - $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
151 | - } elseif ('post_id' == $postId) { |
|
152 | - $postId = intval(get_the_ID()); |
|
153 | - } |
|
154 | - return $postId; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param string $postId |
|
159 | - * @return int|string |
|
160 | - */ |
|
161 | - protected function normalizeAssignTo($postId) |
|
162 | - { |
|
163 | - return $this->normalizeAssignedTo($postId); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string|array $hide |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - protected function normalizeHide($hide) |
|
171 | - { |
|
172 | - if (is_string($hide)) { |
|
173 | - $hide = explode(',', $hide); |
|
174 | - } |
|
175 | - $hideKeys = array_keys($this->getHideOptions()); |
|
176 | - return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
177 | - return in_array($value, $hideKeys); |
|
178 | - }); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param string $id |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - protected function normalizeId($id) |
|
186 | - { |
|
187 | - return sanitize_title($id); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * @param string $labels |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - protected function normalizeLabels($labels) |
|
195 | - { |
|
196 | - $defaults = [ |
|
197 | - __('Excellent', 'site-reviews'), |
|
198 | - __('Very good', 'site-reviews'), |
|
199 | - __('Average', 'site-reviews'), |
|
200 | - __('Poor', 'site-reviews'), |
|
201 | - __('Terrible', 'site-reviews'), |
|
202 | - ]; |
|
203 | - $maxRating = glsr()->constant('MAX_RATING', Rating::class); |
|
204 | - $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
205 | - $labels = array_map('trim', explode(',', $labels)); |
|
206 | - foreach ($defaults as $i => $label) { |
|
207 | - if (empty($labels[$i])) { |
|
208 | - continue; |
|
209 | - } |
|
210 | - $defaults[$i] = $labels[$i]; |
|
211 | - } |
|
212 | - return array_combine(range($maxRating, 1), $defaults); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @param string $schema |
|
217 | - * @return bool |
|
218 | - */ |
|
219 | - protected function normalizeSchema($schema) |
|
220 | - { |
|
221 | - return wp_validate_boolean($schema); |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param string $text |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - protected function normalizeText($text) |
|
229 | - { |
|
230 | - return trim($text); |
|
231 | - } |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $partialName; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $shortcodeName; |
|
22 | + |
|
23 | + /** |
|
24 | + * @param string|array $atts |
|
25 | + * @param string $type |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function build($atts, array $args = [], $type = 'shortcode') |
|
29 | + { |
|
30 | + $this->partialName = $this->getShortcodePartialName(); |
|
31 | + $this->shortcodeName = $this->getShortcodeName(); |
|
32 | + $args = $this->normalizeArgs($args, $type); |
|
33 | + $atts = $this->normalizeAtts($atts, $type); |
|
34 | + $partial = glsr(Partial::class)->build($this->partialName, $atts); |
|
35 | + $title = !empty($atts['title']) |
|
36 | + ? $args['before_title'].$atts['title'].$args['after_title'] |
|
37 | + : ''; |
|
38 | + $debug = sprintf('<glsr-%1$s hidden data-atts=\'%2$s\'></glsr-%1$s>', $type, $atts['json']); |
|
39 | + return $args['before_widget'].$title.$partial.$debug.$args['after_widget']; |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param string|array $atts |
|
44 | + * @return string |
|
45 | + */ |
|
46 | + public function buildShortcode($atts = []) |
|
47 | + { |
|
48 | + return $this->build($atts); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function getDefaults($atts) |
|
55 | + { |
|
56 | + return glsr($this->getShortcodeDefaultsClassName())->restrict(wp_parse_args($atts)); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function getHideOptions() |
|
63 | + { |
|
64 | + $options = $this->hideOptions(); |
|
65 | + return apply_filters('site-reviews/shortcode/hide-options', $options, $this->shortcodeName); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function getShortcodeClassName($replace = '', $search = 'Shortcode') |
|
72 | + { |
|
73 | + return str_replace($search, $replace, (new ReflectionClass($this))->getShortName()); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getShortcodeDefaultsClassName() |
|
80 | + { |
|
81 | + return glsr(Helper::class)->buildClassName( |
|
82 | + $this->getShortcodeClassName('Defaults'), |
|
83 | + 'Defaults' |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function getShortcodeName() |
|
91 | + { |
|
92 | + return glsr(Helper::class)->snakeCase($this->getShortcodeClassName()); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function getShortcodePartialName() |
|
99 | + { |
|
100 | + return glsr(Helper::class)->dashCase($this->getShortcodeClassName()); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param array|string $args |
|
105 | + * @param string $type |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + public function normalizeArgs($args, $type = 'shortcode') |
|
109 | + { |
|
110 | + $args = wp_parse_args($args, [ |
|
111 | + 'before_widget' => '<div class="glsr-'.$type.' '.$type.'-'.$this->partialName.'">', |
|
112 | + 'after_widget' => '</div>', |
|
113 | + 'before_title' => '<h3 class="glsr-'.$type.'-title">', |
|
114 | + 'after_title' => '</h3>', |
|
115 | + ]); |
|
116 | + return apply_filters('site-reviews/shortcode/args', $args, $type, $this->partialName); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param array|string $atts |
|
121 | + * @param string $type |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + public function normalizeAtts($atts, $type = 'shortcode') |
|
125 | + { |
|
126 | + $atts = apply_filters('site-reviews/shortcode/atts', $atts, $type, $this->partialName); |
|
127 | + $atts = $this->getDefaults($atts); |
|
128 | + array_walk($atts, function (&$value, $key) { |
|
129 | + $methodName = glsr(Helper::class)->buildMethodName($key, 'normalize'); |
|
130 | + if (!method_exists($this, $methodName)) { |
|
131 | + return; |
|
132 | + } |
|
133 | + $value = $this->$methodName($value); |
|
134 | + }); |
|
135 | + return $atts; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @return array |
|
140 | + */ |
|
141 | + abstract protected function hideOptions(); |
|
142 | + |
|
143 | + /** |
|
144 | + * @param string $postId |
|
145 | + * @return int|string |
|
146 | + */ |
|
147 | + protected function normalizeAssignedTo($postId) |
|
148 | + { |
|
149 | + if ('parent_id' == $postId) { |
|
150 | + $postId = intval(wp_get_post_parent_id(intval(get_the_ID()))); |
|
151 | + } elseif ('post_id' == $postId) { |
|
152 | + $postId = intval(get_the_ID()); |
|
153 | + } |
|
154 | + return $postId; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param string $postId |
|
159 | + * @return int|string |
|
160 | + */ |
|
161 | + protected function normalizeAssignTo($postId) |
|
162 | + { |
|
163 | + return $this->normalizeAssignedTo($postId); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string|array $hide |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + protected function normalizeHide($hide) |
|
171 | + { |
|
172 | + if (is_string($hide)) { |
|
173 | + $hide = explode(',', $hide); |
|
174 | + } |
|
175 | + $hideKeys = array_keys($this->getHideOptions()); |
|
176 | + return array_filter(array_map('trim', $hide), function ($value) use ($hideKeys) { |
|
177 | + return in_array($value, $hideKeys); |
|
178 | + }); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param string $id |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + protected function normalizeId($id) |
|
186 | + { |
|
187 | + return sanitize_title($id); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * @param string $labels |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + protected function normalizeLabels($labels) |
|
195 | + { |
|
196 | + $defaults = [ |
|
197 | + __('Excellent', 'site-reviews'), |
|
198 | + __('Very good', 'site-reviews'), |
|
199 | + __('Average', 'site-reviews'), |
|
200 | + __('Poor', 'site-reviews'), |
|
201 | + __('Terrible', 'site-reviews'), |
|
202 | + ]; |
|
203 | + $maxRating = glsr()->constant('MAX_RATING', Rating::class); |
|
204 | + $defaults = array_pad(array_slice($defaults, 0, $maxRating), $maxRating, ''); |
|
205 | + $labels = array_map('trim', explode(',', $labels)); |
|
206 | + foreach ($defaults as $i => $label) { |
|
207 | + if (empty($labels[$i])) { |
|
208 | + continue; |
|
209 | + } |
|
210 | + $defaults[$i] = $labels[$i]; |
|
211 | + } |
|
212 | + return array_combine(range($maxRating, 1), $defaults); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @param string $schema |
|
217 | + * @return bool |
|
218 | + */ |
|
219 | + protected function normalizeSchema($schema) |
|
220 | + { |
|
221 | + return wp_validate_boolean($schema); |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param string $text |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + protected function normalizeText($text) |
|
229 | + { |
|
230 | + return trim($text); |
|
231 | + } |
|
232 | 232 | } |
@@ -19,377 +19,377 @@ |
||
19 | 19 | |
20 | 20 | class SiteReviews |
21 | 21 | { |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $args; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $args; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var Review |
|
29 | - */ |
|
30 | - public $current; |
|
27 | + /** |
|
28 | + * @var Review |
|
29 | + */ |
|
30 | + public $current; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - public $options; |
|
32 | + /** |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + public $options; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var Reviews |
|
39 | - */ |
|
40 | - protected $reviews; |
|
37 | + /** |
|
38 | + * @var Reviews |
|
39 | + */ |
|
40 | + protected $reviews; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param Reviews|null $reviews |
|
44 | - * @return ReviewsHtml |
|
45 | - */ |
|
46 | - public function build(array $args = [], $reviews = null) |
|
47 | - { |
|
48 | - $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
49 | - $this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()); |
|
50 | - $this->reviews = $reviews instanceof Reviews |
|
51 | - ? $reviews |
|
52 | - : glsr(ReviewManager::class)->get($args); |
|
53 | - $this->generateSchema(); |
|
54 | - return $this->buildReviews(); |
|
55 | - } |
|
42 | + /** |
|
43 | + * @param Reviews|null $reviews |
|
44 | + * @return ReviewsHtml |
|
45 | + */ |
|
46 | + public function build(array $args = [], $reviews = null) |
|
47 | + { |
|
48 | + $this->args = glsr(SiteReviewsDefaults::class)->merge($args); |
|
49 | + $this->options = glsr(Helper::class)->flattenArray(glsr(OptionManager::class)->all()); |
|
50 | + $this->reviews = $reviews instanceof Reviews |
|
51 | + ? $reviews |
|
52 | + : glsr(ReviewManager::class)->get($args); |
|
53 | + $this->generateSchema(); |
|
54 | + return $this->buildReviews(); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return ReviewHtml |
|
59 | - */ |
|
60 | - public function buildReview(Review $review) |
|
61 | - { |
|
62 | - $review = apply_filters('site-reviews/review/build/before', $review); |
|
63 | - $this->current = $review; |
|
64 | - $renderedFields = []; |
|
65 | - foreach ($review as $key => $value) { |
|
66 | - $method = glsr(Helper::class)->buildMethodName($key, 'buildOption'); |
|
67 | - $field = method_exists($this, $method) |
|
68 | - ? $this->$method($key, $value) |
|
69 | - : false; |
|
70 | - $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $this, $review); |
|
71 | - if (false === $field) { |
|
72 | - continue; |
|
73 | - } |
|
74 | - $renderedFields[$key] = $field; |
|
75 | - } |
|
76 | - $this->wrap($renderedFields, $review); |
|
77 | - $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this); |
|
78 | - $this->current = null; |
|
79 | - return new ReviewHtml($review, (array) $renderedFields); |
|
80 | - } |
|
57 | + /** |
|
58 | + * @return ReviewHtml |
|
59 | + */ |
|
60 | + public function buildReview(Review $review) |
|
61 | + { |
|
62 | + $review = apply_filters('site-reviews/review/build/before', $review); |
|
63 | + $this->current = $review; |
|
64 | + $renderedFields = []; |
|
65 | + foreach ($review as $key => $value) { |
|
66 | + $method = glsr(Helper::class)->buildMethodName($key, 'buildOption'); |
|
67 | + $field = method_exists($this, $method) |
|
68 | + ? $this->$method($key, $value) |
|
69 | + : false; |
|
70 | + $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $this, $review); |
|
71 | + if (false === $field) { |
|
72 | + continue; |
|
73 | + } |
|
74 | + $renderedFields[$key] = $field; |
|
75 | + } |
|
76 | + $this->wrap($renderedFields, $review); |
|
77 | + $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this); |
|
78 | + $this->current = null; |
|
79 | + return new ReviewHtml($review, (array) $renderedFields); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return ReviewsHtml |
|
84 | - */ |
|
85 | - public function buildReviews() |
|
86 | - { |
|
87 | - $renderedReviews = []; |
|
88 | - foreach ($this->reviews as $index => $review) { |
|
89 | - $renderedReviews[] = $this->buildReview($review); |
|
90 | - } |
|
91 | - return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
92 | - } |
|
82 | + /** |
|
83 | + * @return ReviewsHtml |
|
84 | + */ |
|
85 | + public function buildReviews() |
|
86 | + { |
|
87 | + $renderedReviews = []; |
|
88 | + foreach ($this->reviews as $index => $review) { |
|
89 | + $renderedReviews[] = $this->buildReview($review); |
|
90 | + } |
|
91 | + return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public function generateSchema() |
|
98 | - { |
|
99 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
100 | - return; |
|
101 | - } |
|
102 | - glsr(Schema::class)->store( |
|
103 | - glsr(Schema::class)->build($this->args) |
|
104 | - ); |
|
105 | - } |
|
94 | + /** |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public function generateSchema() |
|
98 | + { |
|
99 | + if (!wp_validate_boolean($this->args['schema'])) { |
|
100 | + return; |
|
101 | + } |
|
102 | + glsr(Schema::class)->store( |
|
103 | + glsr(Schema::class)->build($this->args) |
|
104 | + ); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * @param string $key |
|
109 | - * @param string $path |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isHidden($key, $path = '') |
|
113 | - { |
|
114 | - $isOptionEnabled = !empty($path) |
|
115 | - ? $this->isOptionEnabled($path) |
|
116 | - : true; |
|
117 | - return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
118 | - } |
|
107 | + /** |
|
108 | + * @param string $key |
|
109 | + * @param string $path |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isHidden($key, $path = '') |
|
113 | + { |
|
114 | + $isOptionEnabled = !empty($path) |
|
115 | + ? $this->isOptionEnabled($path) |
|
116 | + : true; |
|
117 | + return in_array($key, $this->args['hide']) || !$isOptionEnabled; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @param string $key |
|
122 | - * @param string $value |
|
123 | - * @return void|string |
|
124 | - */ |
|
125 | - protected function buildOptionAssignedTo($key, $value) |
|
126 | - { |
|
127 | - if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
128 | - return; |
|
129 | - } |
|
130 | - $post = glsr(Polylang::class)->getPost($value); |
|
131 | - if (!($post instanceof WP_Post)) { |
|
132 | - return; |
|
133 | - } |
|
134 | - $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
135 | - 'href' => get_the_permalink($post->ID), |
|
136 | - ]); |
|
137 | - $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
138 | - return '<span>'.$assignedTo.'</span>'; |
|
139 | - } |
|
120 | + /** |
|
121 | + * @param string $key |
|
122 | + * @param string $value |
|
123 | + * @return void|string |
|
124 | + */ |
|
125 | + protected function buildOptionAssignedTo($key, $value) |
|
126 | + { |
|
127 | + if ($this->isHidden($key, 'settings.reviews.assigned_links')) { |
|
128 | + return; |
|
129 | + } |
|
130 | + $post = glsr(Polylang::class)->getPost($value); |
|
131 | + if (!($post instanceof WP_Post)) { |
|
132 | + return; |
|
133 | + } |
|
134 | + $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [ |
|
135 | + 'href' => get_the_permalink($post->ID), |
|
136 | + ]); |
|
137 | + $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink); |
|
138 | + return '<span>'.$assignedTo.'</span>'; |
|
139 | + } |
|
140 | 140 | |
141 | - /** |
|
142 | - * @param string $key |
|
143 | - * @param string $value |
|
144 | - * @return void|string |
|
145 | - */ |
|
146 | - protected function buildOptionAuthor($key, $value) |
|
147 | - { |
|
148 | - if (!$this->isHidden($key)) { |
|
149 | - return '<span>'.$value.'</span>'; |
|
150 | - } |
|
151 | - } |
|
141 | + /** |
|
142 | + * @param string $key |
|
143 | + * @param string $value |
|
144 | + * @return void|string |
|
145 | + */ |
|
146 | + protected function buildOptionAuthor($key, $value) |
|
147 | + { |
|
148 | + if (!$this->isHidden($key)) { |
|
149 | + return '<span>'.$value.'</span>'; |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @param string $key |
|
155 | - * @param string $value |
|
156 | - * @return void|string |
|
157 | - */ |
|
158 | - protected function buildOptionAvatar($key, $value) |
|
159 | - { |
|
160 | - if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
161 | - return; |
|
162 | - } |
|
163 | - $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
164 | - return glsr(Builder::class)->img([ |
|
165 | - 'height' => $size, |
|
166 | - 'src' => $this->generateAvatar($value), |
|
167 | - 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
168 | - 'width' => $size, |
|
169 | - ]); |
|
170 | - } |
|
153 | + /** |
|
154 | + * @param string $key |
|
155 | + * @param string $value |
|
156 | + * @return void|string |
|
157 | + */ |
|
158 | + protected function buildOptionAvatar($key, $value) |
|
159 | + { |
|
160 | + if ($this->isHidden($key, 'settings.reviews.avatars')) { |
|
161 | + return; |
|
162 | + } |
|
163 | + $size = $this->getOption('settings.reviews.avatars_size', 40); |
|
164 | + return glsr(Builder::class)->img([ |
|
165 | + 'height' => $size, |
|
166 | + 'src' => $this->generateAvatar($value), |
|
167 | + 'style' => sprintf('width:%1$spx; height:%1$spx;', $size), |
|
168 | + 'width' => $size, |
|
169 | + ]); |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * @param string $key |
|
174 | - * @param string $value |
|
175 | - * @return void|string |
|
176 | - */ |
|
177 | - protected function buildOptionContent($key, $value) |
|
178 | - { |
|
179 | - $text = $this->normalizeText($value); |
|
180 | - if (!$this->isHiddenOrEmpty($key, $text)) { |
|
181 | - return '<p>'.$text.'</p>'; |
|
182 | - } |
|
183 | - } |
|
172 | + /** |
|
173 | + * @param string $key |
|
174 | + * @param string $value |
|
175 | + * @return void|string |
|
176 | + */ |
|
177 | + protected function buildOptionContent($key, $value) |
|
178 | + { |
|
179 | + $text = $this->normalizeText($value); |
|
180 | + if (!$this->isHiddenOrEmpty($key, $text)) { |
|
181 | + return '<p>'.$text.'</p>'; |
|
182 | + } |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @param string $key |
|
187 | - * @param string $value |
|
188 | - * @return void|string |
|
189 | - */ |
|
190 | - protected function buildOptionDate($key, $value) |
|
191 | - { |
|
192 | - if ($this->isHidden($key)) { |
|
193 | - return; |
|
194 | - } |
|
195 | - $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
196 | - if ('relative' == $dateFormat) { |
|
197 | - $date = glsr(Date::class)->relative($value); |
|
198 | - } else { |
|
199 | - $format = 'custom' == $dateFormat |
|
200 | - ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
201 | - : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
202 | - $date = date_i18n($format, strtotime($value)); |
|
203 | - } |
|
204 | - return '<span>'.$date.'</span>'; |
|
205 | - } |
|
185 | + /** |
|
186 | + * @param string $key |
|
187 | + * @param string $value |
|
188 | + * @return void|string |
|
189 | + */ |
|
190 | + protected function buildOptionDate($key, $value) |
|
191 | + { |
|
192 | + if ($this->isHidden($key)) { |
|
193 | + return; |
|
194 | + } |
|
195 | + $dateFormat = $this->getOption('settings.reviews.date.format', 'default'); |
|
196 | + if ('relative' == $dateFormat) { |
|
197 | + $date = glsr(Date::class)->relative($value); |
|
198 | + } else { |
|
199 | + $format = 'custom' == $dateFormat |
|
200 | + ? $this->getOption('settings.reviews.date.custom', 'M j, Y') |
|
201 | + : glsr(OptionManager::class)->getWP('date_format', 'F j, Y'); |
|
202 | + $date = date_i18n($format, strtotime($value)); |
|
203 | + } |
|
204 | + return '<span>'.$date.'</span>'; |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * @param string $key |
|
209 | - * @param string $value |
|
210 | - * @return void|string |
|
211 | - */ |
|
212 | - protected function buildOptionRating($key, $value) |
|
213 | - { |
|
214 | - if (!$this->isHiddenOrEmpty($key, $value)) { |
|
215 | - return glsr_star_rating($value); |
|
216 | - } |
|
217 | - } |
|
207 | + /** |
|
208 | + * @param string $key |
|
209 | + * @param string $value |
|
210 | + * @return void|string |
|
211 | + */ |
|
212 | + protected function buildOptionRating($key, $value) |
|
213 | + { |
|
214 | + if (!$this->isHiddenOrEmpty($key, $value)) { |
|
215 | + return glsr_star_rating($value); |
|
216 | + } |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * @param string $key |
|
221 | - * @param string $value |
|
222 | - * @return void|string |
|
223 | - */ |
|
224 | - protected function buildOptionResponse($key, $value) |
|
225 | - { |
|
226 | - if ($this->isHiddenOrEmpty($key, $value)) { |
|
227 | - return; |
|
228 | - } |
|
229 | - $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
230 | - $text = $this->normalizeText($value); |
|
231 | - $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
|
232 | - $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
233 | - $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
234 | - return $response.$background; |
|
235 | - } |
|
219 | + /** |
|
220 | + * @param string $key |
|
221 | + * @param string $value |
|
222 | + * @return void|string |
|
223 | + */ |
|
224 | + protected function buildOptionResponse($key, $value) |
|
225 | + { |
|
226 | + if ($this->isHiddenOrEmpty($key, $value)) { |
|
227 | + return; |
|
228 | + } |
|
229 | + $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name')); |
|
230 | + $text = $this->normalizeText($value); |
|
231 | + $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>'; |
|
232 | + $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']); |
|
233 | + $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']); |
|
234 | + return $response.$background; |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * @param string $key |
|
239 | - * @param string $value |
|
240 | - * @return void|string |
|
241 | - */ |
|
242 | - protected function buildOptionTitle($key, $value) |
|
243 | - { |
|
244 | - if ($this->isHidden($key)) { |
|
245 | - return; |
|
246 | - } |
|
247 | - if (empty($value)) { |
|
248 | - $value = __('No Title', 'site-reviews'); |
|
249 | - } |
|
250 | - return '<h3>'.$value.'</h3>'; |
|
251 | - } |
|
237 | + /** |
|
238 | + * @param string $key |
|
239 | + * @param string $value |
|
240 | + * @return void|string |
|
241 | + */ |
|
242 | + protected function buildOptionTitle($key, $value) |
|
243 | + { |
|
244 | + if ($this->isHidden($key)) { |
|
245 | + return; |
|
246 | + } |
|
247 | + if (empty($value)) { |
|
248 | + $value = __('No Title', 'site-reviews'); |
|
249 | + } |
|
250 | + return '<h3>'.$value.'</h3>'; |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * @param string $avatarUrl |
|
255 | - * @return string |
|
256 | - */ |
|
257 | - protected function generateAvatar($avatarUrl) |
|
258 | - { |
|
259 | - if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
260 | - return $avatarUrl; |
|
261 | - } |
|
262 | - $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
263 | - if (empty($authorIdOrEmail)) { |
|
264 | - $authorIdOrEmail = $this->current->email; |
|
265 | - } |
|
266 | - if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
267 | - return $newAvatar; |
|
268 | - } |
|
269 | - return $avatarUrl; |
|
270 | - } |
|
253 | + /** |
|
254 | + * @param string $avatarUrl |
|
255 | + * @return string |
|
256 | + */ |
|
257 | + protected function generateAvatar($avatarUrl) |
|
258 | + { |
|
259 | + if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) { |
|
260 | + return $avatarUrl; |
|
261 | + } |
|
262 | + $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id); |
|
263 | + if (empty($authorIdOrEmail)) { |
|
264 | + $authorIdOrEmail = $this->current->email; |
|
265 | + } |
|
266 | + if ($newAvatar = get_avatar_url($authorIdOrEmail)) { |
|
267 | + return $newAvatar; |
|
268 | + } |
|
269 | + return $avatarUrl; |
|
270 | + } |
|
271 | 271 | |
272 | - /** |
|
273 | - * @param string $text |
|
274 | - * @return string |
|
275 | - */ |
|
276 | - protected function getExcerpt($text) |
|
277 | - { |
|
278 | - $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
279 | - $split = extension_loaded('intl') |
|
280 | - ? $this->getExcerptIntlSplit($text, $limit) |
|
281 | - : $this->getExcerptSplit($text, $limit); |
|
282 | - $hiddenText = substr($text, $split); |
|
283 | - if (!empty($hiddenText)) { |
|
284 | - $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
285 | - 'class' => 'glsr-hidden glsr-hidden-text', |
|
286 | - 'data-show-less' => __('Show less', 'site-reviews'), |
|
287 | - 'data-show-more' => __('Show more', 'site-reviews'), |
|
288 | - ]); |
|
289 | - $text = ltrim(substr($text, 0, $split)).$showMore; |
|
290 | - } |
|
291 | - return $text; |
|
292 | - } |
|
272 | + /** |
|
273 | + * @param string $text |
|
274 | + * @return string |
|
275 | + */ |
|
276 | + protected function getExcerpt($text) |
|
277 | + { |
|
278 | + $limit = intval($this->getOption('settings.reviews.excerpts_length', 55)); |
|
279 | + $split = extension_loaded('intl') |
|
280 | + ? $this->getExcerptIntlSplit($text, $limit) |
|
281 | + : $this->getExcerptSplit($text, $limit); |
|
282 | + $hiddenText = substr($text, $split); |
|
283 | + if (!empty($hiddenText)) { |
|
284 | + $showMore = glsr(Builder::class)->span($hiddenText, [ |
|
285 | + 'class' => 'glsr-hidden glsr-hidden-text', |
|
286 | + 'data-show-less' => __('Show less', 'site-reviews'), |
|
287 | + 'data-show-more' => __('Show more', 'site-reviews'), |
|
288 | + ]); |
|
289 | + $text = ltrim(substr($text, 0, $split)).$showMore; |
|
290 | + } |
|
291 | + return $text; |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * @param string $text |
|
296 | - * @param int $limit |
|
297 | - * @return int |
|
298 | - */ |
|
299 | - protected function getExcerptIntlSplit($text, $limit) |
|
300 | - { |
|
301 | - $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
302 | - $words->setText($text); |
|
303 | - $count = 0; |
|
304 | - foreach ($words as $offset) { |
|
305 | - if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
306 | - continue; |
|
307 | - } |
|
308 | - ++$count; |
|
309 | - if ($count != $limit) { |
|
310 | - continue; |
|
311 | - } |
|
312 | - return $offset; |
|
313 | - } |
|
314 | - return strlen($text); |
|
315 | - } |
|
294 | + /** |
|
295 | + * @param string $text |
|
296 | + * @param int $limit |
|
297 | + * @return int |
|
298 | + */ |
|
299 | + protected function getExcerptIntlSplit($text, $limit) |
|
300 | + { |
|
301 | + $words = IntlRuleBasedBreakIterator::createWordInstance(''); |
|
302 | + $words->setText($text); |
|
303 | + $count = 0; |
|
304 | + foreach ($words as $offset) { |
|
305 | + if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) { |
|
306 | + continue; |
|
307 | + } |
|
308 | + ++$count; |
|
309 | + if ($count != $limit) { |
|
310 | + continue; |
|
311 | + } |
|
312 | + return $offset; |
|
313 | + } |
|
314 | + return strlen($text); |
|
315 | + } |
|
316 | 316 | |
317 | - /** |
|
318 | - * @param string $text |
|
319 | - * @param int $limit |
|
320 | - * @return int |
|
321 | - */ |
|
322 | - protected function getExcerptSplit($text, $limit) |
|
323 | - { |
|
324 | - if (str_word_count($text, 0) > $limit) { |
|
325 | - $words = array_keys(str_word_count($text, 2)); |
|
326 | - return $words[$limit]; |
|
327 | - } |
|
328 | - return strlen($text); |
|
329 | - } |
|
317 | + /** |
|
318 | + * @param string $text |
|
319 | + * @param int $limit |
|
320 | + * @return int |
|
321 | + */ |
|
322 | + protected function getExcerptSplit($text, $limit) |
|
323 | + { |
|
324 | + if (str_word_count($text, 0) > $limit) { |
|
325 | + $words = array_keys(str_word_count($text, 2)); |
|
326 | + return $words[$limit]; |
|
327 | + } |
|
328 | + return strlen($text); |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * @param string $path |
|
333 | - * @param mixed $fallback |
|
334 | - * @return mixed |
|
335 | - */ |
|
336 | - protected function getOption($path, $fallback = '') |
|
337 | - { |
|
338 | - if (array_key_exists($path, $this->options)) { |
|
339 | - return $this->options[$path]; |
|
340 | - } |
|
341 | - return $fallback; |
|
342 | - } |
|
331 | + /** |
|
332 | + * @param string $path |
|
333 | + * @param mixed $fallback |
|
334 | + * @return mixed |
|
335 | + */ |
|
336 | + protected function getOption($path, $fallback = '') |
|
337 | + { |
|
338 | + if (array_key_exists($path, $this->options)) { |
|
339 | + return $this->options[$path]; |
|
340 | + } |
|
341 | + return $fallback; |
|
342 | + } |
|
343 | 343 | |
344 | - /** |
|
345 | - * @param string $key |
|
346 | - * @param string $value |
|
347 | - * @return bool |
|
348 | - */ |
|
349 | - protected function isHiddenOrEmpty($key, $value) |
|
350 | - { |
|
351 | - return $this->isHidden($key) || empty($value); |
|
352 | - } |
|
344 | + /** |
|
345 | + * @param string $key |
|
346 | + * @param string $value |
|
347 | + * @return bool |
|
348 | + */ |
|
349 | + protected function isHiddenOrEmpty($key, $value) |
|
350 | + { |
|
351 | + return $this->isHidden($key) || empty($value); |
|
352 | + } |
|
353 | 353 | |
354 | - /** |
|
355 | - * @param string $path |
|
356 | - * @return bool |
|
357 | - */ |
|
358 | - protected function isOptionEnabled($path) |
|
359 | - { |
|
360 | - return 'yes' == $this->getOption($path); |
|
361 | - } |
|
354 | + /** |
|
355 | + * @param string $path |
|
356 | + * @return bool |
|
357 | + */ |
|
358 | + protected function isOptionEnabled($path) |
|
359 | + { |
|
360 | + return 'yes' == $this->getOption($path); |
|
361 | + } |
|
362 | 362 | |
363 | - /** |
|
364 | - * @param string $text |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - protected function normalizeText($text) |
|
368 | - { |
|
369 | - $text = wp_kses($text, wp_kses_allowed_html()); |
|
370 | - $text = convert_smilies(strip_shortcodes($text)); |
|
371 | - $text = str_replace(']]>', ']]>', $text); |
|
372 | - $text = preg_replace('/(\R){2,}/', '$1', $text); |
|
373 | - if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
374 | - $text = $this->getExcerpt($text); |
|
375 | - } |
|
376 | - return wptexturize(nl2br($text)); |
|
377 | - } |
|
363 | + /** |
|
364 | + * @param string $text |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + protected function normalizeText($text) |
|
368 | + { |
|
369 | + $text = wp_kses($text, wp_kses_allowed_html()); |
|
370 | + $text = convert_smilies(strip_shortcodes($text)); |
|
371 | + $text = str_replace(']]>', ']]>', $text); |
|
372 | + $text = preg_replace('/(\R){2,}/', '$1', $text); |
|
373 | + if ($this->isOptionEnabled('settings.reviews.excerpts')) { |
|
374 | + $text = $this->getExcerpt($text); |
|
375 | + } |
|
376 | + return wptexturize(nl2br($text)); |
|
377 | + } |
|
378 | 378 | |
379 | - /** |
|
380 | - * @return void |
|
381 | - */ |
|
382 | - protected function wrap(array &$renderedFields, Review $review) |
|
383 | - { |
|
384 | - $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this); |
|
385 | - array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
386 | - $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
387 | - if (empty($value)) { |
|
388 | - return; |
|
389 | - } |
|
390 | - $value = glsr(Builder::class)->div($value, [ |
|
391 | - 'class' => 'glsr-review-'.$key, |
|
392 | - ]); |
|
393 | - }); |
|
394 | - } |
|
379 | + /** |
|
380 | + * @return void |
|
381 | + */ |
|
382 | + protected function wrap(array &$renderedFields, Review $review) |
|
383 | + { |
|
384 | + $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this); |
|
385 | + array_walk($renderedFields, function (&$value, $key) use ($review) { |
|
386 | + $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review); |
|
387 | + if (empty($value)) { |
|
388 | + return; |
|
389 | + } |
|
390 | + $value = glsr(Builder::class)->div($value, [ |
|
391 | + 'class' => 'glsr-review-'.$key, |
|
392 | + ]); |
|
393 | + }); |
|
394 | + } |
|
395 | 395 | } |
@@ -10,368 +10,368 @@ |
||
10 | 10 | |
11 | 11 | class System |
12 | 12 | { |
13 | - const PAD = 40; |
|
13 | + const PAD = 40; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function __toString() |
|
19 | - { |
|
20 | - return $this->get(); |
|
21 | - } |
|
15 | + /** |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function __toString() |
|
19 | + { |
|
20 | + return $this->get(); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function get() |
|
27 | - { |
|
28 | - $details = [ |
|
29 | - 'plugin' => 'Plugin Details', |
|
30 | - 'addon' => 'Addon Details', |
|
31 | - 'browser' => 'Browser Details', |
|
32 | - 'server' => 'Server Details', |
|
33 | - 'php' => 'PHP Configuration', |
|
34 | - 'wordpress' => 'WordPress Configuration', |
|
35 | - 'mu-plugin' => 'Must-Use Plugins', |
|
36 | - 'multisite-plugin' => 'Network Active Plugins', |
|
37 | - 'active-plugin' => 'Active Plugins', |
|
38 | - 'inactive-plugin' => 'Inactive Plugins', |
|
39 | - 'setting' => 'Plugin Settings', |
|
40 | - 'reviews' => 'Review Counts', |
|
41 | - ]; |
|
42 | - $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
43 | - $methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details'); |
|
44 | - if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
45 | - return $carry.$this->implode( |
|
46 | - strtoupper($details[$key]), |
|
47 | - apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
48 | - ); |
|
49 | - } |
|
50 | - return $carry; |
|
51 | - }); |
|
52 | - return trim($systemInfo); |
|
53 | - } |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function get() |
|
27 | + { |
|
28 | + $details = [ |
|
29 | + 'plugin' => 'Plugin Details', |
|
30 | + 'addon' => 'Addon Details', |
|
31 | + 'browser' => 'Browser Details', |
|
32 | + 'server' => 'Server Details', |
|
33 | + 'php' => 'PHP Configuration', |
|
34 | + 'wordpress' => 'WordPress Configuration', |
|
35 | + 'mu-plugin' => 'Must-Use Plugins', |
|
36 | + 'multisite-plugin' => 'Network Active Plugins', |
|
37 | + 'active-plugin' => 'Active Plugins', |
|
38 | + 'inactive-plugin' => 'Inactive Plugins', |
|
39 | + 'setting' => 'Plugin Settings', |
|
40 | + 'reviews' => 'Review Counts', |
|
41 | + ]; |
|
42 | + $systemInfo = array_reduce(array_keys($details), function ($carry, $key) use ($details) { |
|
43 | + $methodName = glsr(Helper::class)->buildMethodName('get-'.$key.'-details'); |
|
44 | + if (method_exists($this, $methodName) && $systemDetails = $this->$methodName()) { |
|
45 | + return $carry.$this->implode( |
|
46 | + strtoupper($details[$key]), |
|
47 | + apply_filters('site-reviews/system/'.$key, $systemDetails) |
|
48 | + ); |
|
49 | + } |
|
50 | + return $carry; |
|
51 | + }); |
|
52 | + return trim($systemInfo); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getActivePluginDetails() |
|
59 | - { |
|
60 | - $plugins = get_plugins(); |
|
61 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
62 | - $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
63 | - return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
64 | - } |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getActivePluginDetails() |
|
59 | + { |
|
60 | + $plugins = get_plugins(); |
|
61 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
62 | + $inactive = array_diff_key($plugins, array_flip($activePlugins)); |
|
63 | + return $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function getAddonDetails() |
|
70 | - { |
|
71 | - $details = apply_filters('site-reviews/addon/system-info', []); |
|
72 | - ksort($details); |
|
73 | - return $details; |
|
74 | - } |
|
66 | + /** |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function getAddonDetails() |
|
70 | + { |
|
71 | + $details = apply_filters('site-reviews/addon/system-info', []); |
|
72 | + ksort($details); |
|
73 | + return $details; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - public function getBrowserDetails() |
|
80 | - { |
|
81 | - $browser = new Browser(); |
|
82 | - $name = esc_attr($browser->getName()); |
|
83 | - $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
84 | - $version = esc_attr($browser->getVersion()); |
|
85 | - return [ |
|
86 | - 'Browser Name' => sprintf('%s %s', $name, $version), |
|
87 | - 'Browser UA' => $userAgent, |
|
88 | - ]; |
|
89 | - } |
|
76 | + /** |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + public function getBrowserDetails() |
|
80 | + { |
|
81 | + $browser = new Browser(); |
|
82 | + $name = esc_attr($browser->getName()); |
|
83 | + $userAgent = esc_attr($browser->getUserAgent()->getUserAgentString()); |
|
84 | + $version = esc_attr($browser->getVersion()); |
|
85 | + return [ |
|
86 | + 'Browser Name' => sprintf('%s %s', $name, $version), |
|
87 | + 'Browser UA' => $userAgent, |
|
88 | + ]; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function getInactivePluginDetails() |
|
95 | - { |
|
96 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
97 | - $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
98 | - $multisitePlugins = $this->getMultisitePluginDetails(); |
|
99 | - return empty($multisitePlugins) |
|
100 | - ? $inactivePlugins |
|
101 | - : array_diff($inactivePlugins, $multisitePlugins); |
|
102 | - } |
|
91 | + /** |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function getInactivePluginDetails() |
|
95 | + { |
|
96 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
97 | + $inactivePlugins = $this->normalizePluginList(array_diff_key(get_plugins(), array_flip($activePlugins))); |
|
98 | + $multisitePlugins = $this->getMultisitePluginDetails(); |
|
99 | + return empty($multisitePlugins) |
|
100 | + ? $inactivePlugins |
|
101 | + : array_diff($inactivePlugins, $multisitePlugins); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - public function getMuPluginDetails() |
|
108 | - { |
|
109 | - if (empty($plugins = get_mu_plugins())) { |
|
110 | - return []; |
|
111 | - } |
|
112 | - return $this->normalizePluginList($plugins); |
|
113 | - } |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + public function getMuPluginDetails() |
|
108 | + { |
|
109 | + if (empty($plugins = get_mu_plugins())) { |
|
110 | + return []; |
|
111 | + } |
|
112 | + return $this->normalizePluginList($plugins); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * @return array |
|
117 | - */ |
|
118 | - public function getMultisitePluginDetails() |
|
119 | - { |
|
120 | - $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
121 | - if (!is_multisite() || empty($activePlugins)) { |
|
122 | - return []; |
|
123 | - } |
|
124 | - return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
125 | - } |
|
115 | + /** |
|
116 | + * @return array |
|
117 | + */ |
|
118 | + public function getMultisitePluginDetails() |
|
119 | + { |
|
120 | + $activePlugins = (array) get_site_option('active_sitewide_plugins', []); |
|
121 | + if (!is_multisite() || empty($activePlugins)) { |
|
122 | + return []; |
|
123 | + } |
|
124 | + return $this->normalizePluginList(array_intersect_key(get_plugins(), $activePlugins)); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - public function getPhpDetails() |
|
131 | - { |
|
132 | - $displayErrors = ini_get('display_errors') |
|
133 | - ? 'On ('.ini_get('display_errors').')' |
|
134 | - : 'N/A'; |
|
135 | - $intlSupport = extension_loaded('intl') |
|
136 | - ? phpversion('intl') |
|
137 | - : 'false'; |
|
138 | - return [ |
|
139 | - 'cURL' => var_export(function_exists('curl_init'), true), |
|
140 | - 'Default Charset' => ini_get('default_charset'), |
|
141 | - 'Display Errors' => $displayErrors, |
|
142 | - 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
143 | - 'Intl' => $intlSupport, |
|
144 | - 'IPv6' => var_export(defined('AF_INET6'), true), |
|
145 | - 'Max Execution Time' => ini_get('max_execution_time'), |
|
146 | - 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
147 | - 'Max Input Vars' => ini_get('max_input_vars'), |
|
148 | - 'Memory Limit' => ini_get('memory_limit'), |
|
149 | - 'Post Max Size' => ini_get('post_max_size'), |
|
150 | - 'Sendmail Path' => ini_get('sendmail_path'), |
|
151 | - 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
152 | - 'Session Name' => esc_html(ini_get('session.name')), |
|
153 | - 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
154 | - 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
155 | - 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
156 | - 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
157 | - ]; |
|
158 | - } |
|
127 | + /** |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + public function getPhpDetails() |
|
131 | + { |
|
132 | + $displayErrors = ini_get('display_errors') |
|
133 | + ? 'On ('.ini_get('display_errors').')' |
|
134 | + : 'N/A'; |
|
135 | + $intlSupport = extension_loaded('intl') |
|
136 | + ? phpversion('intl') |
|
137 | + : 'false'; |
|
138 | + return [ |
|
139 | + 'cURL' => var_export(function_exists('curl_init'), true), |
|
140 | + 'Default Charset' => ini_get('default_charset'), |
|
141 | + 'Display Errors' => $displayErrors, |
|
142 | + 'fsockopen' => var_export(function_exists('fsockopen'), true), |
|
143 | + 'Intl' => $intlSupport, |
|
144 | + 'IPv6' => var_export(defined('AF_INET6'), true), |
|
145 | + 'Max Execution Time' => ini_get('max_execution_time'), |
|
146 | + 'Max Input Nesting Level' => ini_get('max_input_nesting_level'), |
|
147 | + 'Max Input Vars' => ini_get('max_input_vars'), |
|
148 | + 'Memory Limit' => ini_get('memory_limit'), |
|
149 | + 'Post Max Size' => ini_get('post_max_size'), |
|
150 | + 'Sendmail Path' => ini_get('sendmail_path'), |
|
151 | + 'Session Cookie Path' => esc_html(ini_get('session.cookie_path')), |
|
152 | + 'Session Name' => esc_html(ini_get('session.name')), |
|
153 | + 'Session Save Path' => esc_html(ini_get('session.save_path')), |
|
154 | + 'Session Use Cookies' => var_export(wp_validate_boolean(ini_get('session.use_cookies')), true), |
|
155 | + 'Session Use Only Cookies' => var_export(wp_validate_boolean(ini_get('session.use_only_cookies')), true), |
|
156 | + 'Upload Max Filesize' => ini_get('upload_max_filesize'), |
|
157 | + ]; |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public function getReviewsDetails() |
|
164 | - { |
|
165 | - $counts = glsr(CountsManager::class)->getCounts(); |
|
166 | - $counts = glsr(Helper::class)->flattenArray($counts); |
|
167 | - array_walk($counts, function (&$ratings) use ($counts) { |
|
168 | - if (!is_array($ratings)) { |
|
169 | - glsr_log() |
|
170 | - ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
171 | - ->debug($ratings) |
|
172 | - ->debug($counts); |
|
173 | - return; |
|
174 | - } |
|
175 | - $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
176 | - }); |
|
177 | - ksort($counts); |
|
178 | - return $counts; |
|
179 | - } |
|
160 | + /** |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public function getReviewsDetails() |
|
164 | + { |
|
165 | + $counts = glsr(CountsManager::class)->getCounts(); |
|
166 | + $counts = glsr(Helper::class)->flattenArray($counts); |
|
167 | + array_walk($counts, function (&$ratings) use ($counts) { |
|
168 | + if (!is_array($ratings)) { |
|
169 | + glsr_log() |
|
170 | + ->error('$ratings is not an array, possibly due to incorrectly imported reviews.') |
|
171 | + ->debug($ratings) |
|
172 | + ->debug($counts); |
|
173 | + return; |
|
174 | + } |
|
175 | + $ratings = array_sum($ratings).' ('.implode(', ', $ratings).')'; |
|
176 | + }); |
|
177 | + ksort($counts); |
|
178 | + return $counts; |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - public function getServerDetails() |
|
185 | - { |
|
186 | - global $wpdb; |
|
187 | - return [ |
|
188 | - 'Host Name' => $this->getHostName(), |
|
189 | - 'MySQL Version' => $wpdb->db_version(), |
|
190 | - 'PHP Version' => PHP_VERSION, |
|
191 | - 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
192 | - ]; |
|
193 | - } |
|
181 | + /** |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + public function getServerDetails() |
|
185 | + { |
|
186 | + global $wpdb; |
|
187 | + return [ |
|
188 | + 'Host Name' => $this->getHostName(), |
|
189 | + 'MySQL Version' => $wpdb->db_version(), |
|
190 | + 'PHP Version' => PHP_VERSION, |
|
191 | + 'Server Software' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE'), |
|
192 | + ]; |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * @return array |
|
197 | - */ |
|
198 | - public function getSettingDetails() |
|
199 | - { |
|
200 | - $helper = glsr(Helper::class); |
|
201 | - $settings = glsr(OptionManager::class)->get('settings', []); |
|
202 | - $settings = $helper->flattenArray($settings, true); |
|
203 | - $settings = $this->purgeSensitiveData($settings); |
|
204 | - ksort($settings); |
|
205 | - $details = []; |
|
206 | - foreach ($settings as $key => $value) { |
|
207 | - if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) { |
|
208 | - continue; |
|
209 | - } |
|
210 | - $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
211 | - $details[$key] = $value; |
|
212 | - } |
|
213 | - return $details; |
|
214 | - } |
|
195 | + /** |
|
196 | + * @return array |
|
197 | + */ |
|
198 | + public function getSettingDetails() |
|
199 | + { |
|
200 | + $helper = glsr(Helper::class); |
|
201 | + $settings = glsr(OptionManager::class)->get('settings', []); |
|
202 | + $settings = $helper->flattenArray($settings, true); |
|
203 | + $settings = $this->purgeSensitiveData($settings); |
|
204 | + ksort($settings); |
|
205 | + $details = []; |
|
206 | + foreach ($settings as $key => $value) { |
|
207 | + if ($helper->startsWith('strings', $key) && $helper->endsWith('id', $key)) { |
|
208 | + continue; |
|
209 | + } |
|
210 | + $value = htmlspecialchars(trim(preg_replace('/\s\s+/', '\\n', $value)), ENT_QUOTES, 'UTF-8'); |
|
211 | + $details[$key] = $value; |
|
212 | + } |
|
213 | + return $details; |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * @return array |
|
218 | - */ |
|
219 | - public function getPluginDetails() |
|
220 | - { |
|
221 | - return [ |
|
222 | - 'Console level' => glsr(Console::class)->humanLevel(), |
|
223 | - 'Console size' => glsr(Console::class)->humanSize('0'), |
|
224 | - 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
225 | - 'Version (current)' => glsr()->version, |
|
226 | - 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
227 | - ]; |
|
228 | - } |
|
216 | + /** |
|
217 | + * @return array |
|
218 | + */ |
|
219 | + public function getPluginDetails() |
|
220 | + { |
|
221 | + return [ |
|
222 | + 'Console level' => glsr(Console::class)->humanLevel(), |
|
223 | + 'Console size' => glsr(Console::class)->humanSize('0'), |
|
224 | + 'Last Rating Count' => date_i18n('Y-m-d H:i', glsr(OptionManager::class)->get('last_review_count')), |
|
225 | + 'Version (current)' => glsr()->version, |
|
226 | + 'Version (previous)' => glsr(OptionManager::class)->get('version_upgraded_from'), |
|
227 | + ]; |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * @return array |
|
232 | - */ |
|
233 | - public function getWordpressDetails() |
|
234 | - { |
|
235 | - global $wpdb; |
|
236 | - $theme = wp_get_theme(); |
|
237 | - return [ |
|
238 | - 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
239 | - 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
240 | - 'Home URL' => home_url(), |
|
241 | - 'Language' => get_locale(), |
|
242 | - 'Memory Limit' => WP_MEMORY_LIMIT, |
|
243 | - 'Multisite' => var_export(is_multisite(), true), |
|
244 | - 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
245 | - 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
246 | - 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
247 | - 'Post Stati' => implode(', ', get_post_stati()), |
|
248 | - 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
249 | - 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
250 | - 'Site URL' => site_url(), |
|
251 | - 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
252 | - 'Version' => get_bloginfo('version'), |
|
253 | - 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
254 | - 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
255 | - 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
256 | - ]; |
|
257 | - } |
|
230 | + /** |
|
231 | + * @return array |
|
232 | + */ |
|
233 | + public function getWordpressDetails() |
|
234 | + { |
|
235 | + global $wpdb; |
|
236 | + $theme = wp_get_theme(); |
|
237 | + return [ |
|
238 | + 'Active Theme' => sprintf('%s v%s', (string) $theme->Name, (string) $theme->Version), |
|
239 | + 'Email Domain' => substr(strrchr(glsr(OptionManager::class)->getWP('admin_email'), '@'), 1), |
|
240 | + 'Home URL' => home_url(), |
|
241 | + 'Language' => get_locale(), |
|
242 | + 'Memory Limit' => WP_MEMORY_LIMIT, |
|
243 | + 'Multisite' => var_export(is_multisite(), true), |
|
244 | + 'Page For Posts ID' => glsr(OptionManager::class)->getWP('page_for_posts'), |
|
245 | + 'Page On Front ID' => glsr(OptionManager::class)->getWP('page_on_front'), |
|
246 | + 'Permalink Structure' => glsr(OptionManager::class)->getWP('permalink_structure', 'default'), |
|
247 | + 'Post Stati' => implode(', ', get_post_stati()), |
|
248 | + 'Remote Post' => glsr(Cache::class)->getRemotePostTest(), |
|
249 | + 'Show On Front' => glsr(OptionManager::class)->getWP('show_on_front'), |
|
250 | + 'Site URL' => site_url(), |
|
251 | + 'Timezone' => glsr(OptionManager::class)->getWP('timezone_string', ini_get('date.timezone').' (PHP)'), |
|
252 | + 'Version' => get_bloginfo('version'), |
|
253 | + 'WP Debug' => var_export(defined('WP_DEBUG'), true), |
|
254 | + 'WP Max Upload Size' => size_format(wp_max_upload_size()), |
|
255 | + 'WP Memory Limit' => WP_MEMORY_LIMIT, |
|
256 | + ]; |
|
257 | + } |
|
258 | 258 | |
259 | - /** |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - protected function detectWebhostProvider() |
|
263 | - { |
|
264 | - $checks = [ |
|
265 | - '.accountservergroup.com' => 'Site5', |
|
266 | - '.gridserver.com' => 'MediaTemple Grid', |
|
267 | - '.inmotionhosting.com' => 'InMotion Hosting', |
|
268 | - '.ovh.net' => 'OVH', |
|
269 | - '.pair.com' => 'pair Networks', |
|
270 | - '.stabletransit.com' => 'Rackspace Cloud', |
|
271 | - '.stratoserver.net' => 'STRATO', |
|
272 | - '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
273 | - 'bluehost.com' => 'Bluehost', |
|
274 | - 'DH_USER' => 'DreamHost', |
|
275 | - 'Flywheel' => 'Flywheel', |
|
276 | - 'ipagemysql.com' => 'iPage', |
|
277 | - 'ipowermysql.com' => 'IPower', |
|
278 | - 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
279 | - 'mysqlv5' => 'NetworkSolutions', |
|
280 | - 'PAGELYBIN' => 'Pagely', |
|
281 | - 'secureserver.net' => 'GoDaddy', |
|
282 | - 'WPE_APIKEY' => 'WP Engine', |
|
283 | - ]; |
|
284 | - foreach ($checks as $key => $value) { |
|
285 | - if (!$this->isWebhostCheckValid($key)) { |
|
286 | - continue; |
|
287 | - } |
|
288 | - return $value; |
|
289 | - } |
|
290 | - return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
291 | - } |
|
259 | + /** |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + protected function detectWebhostProvider() |
|
263 | + { |
|
264 | + $checks = [ |
|
265 | + '.accountservergroup.com' => 'Site5', |
|
266 | + '.gridserver.com' => 'MediaTemple Grid', |
|
267 | + '.inmotionhosting.com' => 'InMotion Hosting', |
|
268 | + '.ovh.net' => 'OVH', |
|
269 | + '.pair.com' => 'pair Networks', |
|
270 | + '.stabletransit.com' => 'Rackspace Cloud', |
|
271 | + '.stratoserver.net' => 'STRATO', |
|
272 | + '.sysfix.eu' => 'SysFix.eu Power Hosting', |
|
273 | + 'bluehost.com' => 'Bluehost', |
|
274 | + 'DH_USER' => 'DreamHost', |
|
275 | + 'Flywheel' => 'Flywheel', |
|
276 | + 'ipagemysql.com' => 'iPage', |
|
277 | + 'ipowermysql.com' => 'IPower', |
|
278 | + 'localhost:/tmp/mysql5.sock' => 'ICDSoft', |
|
279 | + 'mysqlv5' => 'NetworkSolutions', |
|
280 | + 'PAGELYBIN' => 'Pagely', |
|
281 | + 'secureserver.net' => 'GoDaddy', |
|
282 | + 'WPE_APIKEY' => 'WP Engine', |
|
283 | + ]; |
|
284 | + foreach ($checks as $key => $value) { |
|
285 | + if (!$this->isWebhostCheckValid($key)) { |
|
286 | + continue; |
|
287 | + } |
|
288 | + return $value; |
|
289 | + } |
|
290 | + return implode(',', array_filter([DB_HOST, filter_input(INPUT_SERVER, 'SERVER_NAME')])); |
|
291 | + } |
|
292 | 292 | |
293 | - /** |
|
294 | - * @return string |
|
295 | - */ |
|
296 | - protected function getHostName() |
|
297 | - { |
|
298 | - return sprintf('%s (%s)', |
|
299 | - $this->detectWebhostProvider(), |
|
300 | - glsr(Helper::class)->getIpAddress() |
|
301 | - ); |
|
302 | - } |
|
293 | + /** |
|
294 | + * @return string |
|
295 | + */ |
|
296 | + protected function getHostName() |
|
297 | + { |
|
298 | + return sprintf('%s (%s)', |
|
299 | + $this->detectWebhostProvider(), |
|
300 | + glsr(Helper::class)->getIpAddress() |
|
301 | + ); |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * @return array |
|
306 | - */ |
|
307 | - protected function getWordpressPlugins() |
|
308 | - { |
|
309 | - $plugins = get_plugins(); |
|
310 | - $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
311 | - $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
312 | - $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
313 | - return $active + $inactive; |
|
314 | - } |
|
304 | + /** |
|
305 | + * @return array |
|
306 | + */ |
|
307 | + protected function getWordpressPlugins() |
|
308 | + { |
|
309 | + $plugins = get_plugins(); |
|
310 | + $activePlugins = glsr(OptionManager::class)->getWP('active_plugins', [], 'array'); |
|
311 | + $inactive = $this->normalizePluginList(array_diff_key($plugins, array_flip($activePlugins))); |
|
312 | + $active = $this->normalizePluginList(array_diff_key($plugins, $inactive)); |
|
313 | + return $active + $inactive; |
|
314 | + } |
|
315 | 315 | |
316 | - /** |
|
317 | - * @param string $title |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - protected function implode($title, array $details) |
|
321 | - { |
|
322 | - $strings = ['['.$title.']']; |
|
323 | - $padding = max(array_map('strlen', array_keys($details))); |
|
324 | - $padding = max([$padding, static::PAD]); |
|
325 | - foreach ($details as $key => $value) { |
|
326 | - $strings[] = is_string($key) |
|
327 | - ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
328 | - : ' - '.$value; |
|
329 | - } |
|
330 | - return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
331 | - } |
|
316 | + /** |
|
317 | + * @param string $title |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + protected function implode($title, array $details) |
|
321 | + { |
|
322 | + $strings = ['['.$title.']']; |
|
323 | + $padding = max(array_map('strlen', array_keys($details))); |
|
324 | + $padding = max([$padding, static::PAD]); |
|
325 | + foreach ($details as $key => $value) { |
|
326 | + $strings[] = is_string($key) |
|
327 | + ? sprintf('%s : %s', str_pad($key, $padding, '.'), $value) |
|
328 | + : ' - '.$value; |
|
329 | + } |
|
330 | + return implode(PHP_EOL, $strings).PHP_EOL.PHP_EOL; |
|
331 | + } |
|
332 | 332 | |
333 | - /** |
|
334 | - * @param string $key |
|
335 | - * @return bool |
|
336 | - */ |
|
337 | - protected function isWebhostCheckValid($key) |
|
338 | - { |
|
339 | - return defined($key) |
|
340 | - || filter_input(INPUT_SERVER, $key) |
|
341 | - || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
342 | - || false !== strpos(DB_HOST, $key) |
|
343 | - || false !== strpos(php_uname(), $key); |
|
344 | - } |
|
333 | + /** |
|
334 | + * @param string $key |
|
335 | + * @return bool |
|
336 | + */ |
|
337 | + protected function isWebhostCheckValid($key) |
|
338 | + { |
|
339 | + return defined($key) |
|
340 | + || filter_input(INPUT_SERVER, $key) |
|
341 | + || false !== strpos(filter_input(INPUT_SERVER, 'SERVER_NAME'), $key) |
|
342 | + || false !== strpos(DB_HOST, $key) |
|
343 | + || false !== strpos(php_uname(), $key); |
|
344 | + } |
|
345 | 345 | |
346 | - /** |
|
347 | - * @return array |
|
348 | - */ |
|
349 | - protected function normalizePluginList(array $plugins) |
|
350 | - { |
|
351 | - $plugins = array_map(function ($plugin) { |
|
352 | - return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version')); |
|
353 | - }, $plugins); |
|
354 | - natcasesort($plugins); |
|
355 | - return array_flip($plugins); |
|
356 | - } |
|
346 | + /** |
|
347 | + * @return array |
|
348 | + */ |
|
349 | + protected function normalizePluginList(array $plugins) |
|
350 | + { |
|
351 | + $plugins = array_map(function ($plugin) { |
|
352 | + return sprintf('%s v%s', glsr_get($plugin, 'Name'), glsr_get($plugin, 'Version')); |
|
353 | + }, $plugins); |
|
354 | + natcasesort($plugins); |
|
355 | + return array_flip($plugins); |
|
356 | + } |
|
357 | 357 | |
358 | - /** |
|
359 | - * @return array |
|
360 | - */ |
|
361 | - protected function purgeSensitiveData(array $settings) |
|
362 | - { |
|
363 | - $keys = [ |
|
364 | - 'licenses.', 'submissions.recaptcha.key', 'submissions.recaptcha.secret', |
|
365 | - ]; |
|
366 | - array_walk($settings, function (&$value, $setting) use ($keys) { |
|
367 | - foreach ($keys as $key) { |
|
368 | - if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) { |
|
369 | - continue; |
|
370 | - } |
|
371 | - $value = str_repeat('•', 13); |
|
372 | - return; |
|
373 | - } |
|
374 | - }); |
|
375 | - return $settings; |
|
376 | - } |
|
358 | + /** |
|
359 | + * @return array |
|
360 | + */ |
|
361 | + protected function purgeSensitiveData(array $settings) |
|
362 | + { |
|
363 | + $keys = [ |
|
364 | + 'licenses.', 'submissions.recaptcha.key', 'submissions.recaptcha.secret', |
|
365 | + ]; |
|
366 | + array_walk($settings, function (&$value, $setting) use ($keys) { |
|
367 | + foreach ($keys as $key) { |
|
368 | + if (!glsr(Helper::class)->startsWith($key, $setting) || empty($value)) { |
|
369 | + continue; |
|
370 | + } |
|
371 | + $value = str_repeat('•', 13); |
|
372 | + return; |
|
373 | + } |
|
374 | + }); |
|
375 | + return $settings; |
|
376 | + } |
|
377 | 377 | } |
@@ -12,291 +12,291 @@ |
||
12 | 12 | |
13 | 13 | class Schema |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $args; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $args; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $ratingCounts; |
|
20 | + /** |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $ratingCounts; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @return array |
|
27 | - */ |
|
28 | - public function build(array $args = []) |
|
29 | - { |
|
30 | - $this->args = $args; |
|
31 | - $schema = $this->buildSummary($args); |
|
32 | - $reviews = []; |
|
33 | - foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
34 | - // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
|
35 | - // @see https://developers.google.com/search/docs/data-types/review |
|
36 | - if ('local' != $review->review_type) { |
|
37 | - continue; |
|
38 | - } |
|
39 | - $reviews[] = $this->buildReview($review); |
|
40 | - } |
|
41 | - if (!empty($reviews)) { |
|
42 | - array_walk($reviews, function (&$review) { |
|
43 | - unset($review['@context']); |
|
44 | - unset($review['itemReviewed']); |
|
45 | - }); |
|
46 | - $schema['review'] = $reviews; |
|
47 | - } |
|
48 | - return $schema; |
|
49 | - } |
|
25 | + /** |
|
26 | + * @return array |
|
27 | + */ |
|
28 | + public function build(array $args = []) |
|
29 | + { |
|
30 | + $this->args = $args; |
|
31 | + $schema = $this->buildSummary($args); |
|
32 | + $reviews = []; |
|
33 | + foreach (glsr(ReviewManager::class)->get($this->args) as $review) { |
|
34 | + // Only include critic reviews that have been directly produced by your site, not reviews from third-party sites or syndicated reviews. |
|
35 | + // @see https://developers.google.com/search/docs/data-types/review |
|
36 | + if ('local' != $review->review_type) { |
|
37 | + continue; |
|
38 | + } |
|
39 | + $reviews[] = $this->buildReview($review); |
|
40 | + } |
|
41 | + if (!empty($reviews)) { |
|
42 | + array_walk($reviews, function (&$review) { |
|
43 | + unset($review['@context']); |
|
44 | + unset($review['itemReviewed']); |
|
45 | + }); |
|
46 | + $schema['review'] = $reviews; |
|
47 | + } |
|
48 | + return $schema; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param array|null $args |
|
53 | - * @return array |
|
54 | - */ |
|
55 | - public function buildSummary($args = null) |
|
56 | - { |
|
57 | - if (is_array($args)) { |
|
58 | - $this->args = $args; |
|
59 | - } |
|
60 | - $buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
61 | - $count = array_sum($this->getRatingCounts()); |
|
62 | - $schema = method_exists($this, $buildSummary) |
|
63 | - ? $this->$buildSummary() |
|
64 | - : $this->buildSummaryForCustom(); |
|
65 | - if (!empty($count)) { |
|
66 | - $schema->aggregateRating( |
|
67 | - $this->getSchemaType('AggregateRating') |
|
68 | - ->ratingValue($this->getRatingValue()) |
|
69 | - ->reviewCount($count) |
|
70 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
71 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
72 | - ); |
|
73 | - } |
|
74 | - $schema = $schema->toArray(); |
|
75 | - return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
76 | - } |
|
51 | + /** |
|
52 | + * @param array|null $args |
|
53 | + * @return array |
|
54 | + */ |
|
55 | + public function buildSummary($args = null) |
|
56 | + { |
|
57 | + if (is_array($args)) { |
|
58 | + $this->args = $args; |
|
59 | + } |
|
60 | + $buildSummary = glsr(Helper::class)->buildMethodName($this->getSchemaOptionValue('type'), 'buildSummaryFor'); |
|
61 | + $count = array_sum($this->getRatingCounts()); |
|
62 | + $schema = method_exists($this, $buildSummary) |
|
63 | + ? $this->$buildSummary() |
|
64 | + : $this->buildSummaryForCustom(); |
|
65 | + if (!empty($count)) { |
|
66 | + $schema->aggregateRating( |
|
67 | + $this->getSchemaType('AggregateRating') |
|
68 | + ->ratingValue($this->getRatingValue()) |
|
69 | + ->reviewCount($count) |
|
70 | + ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
71 | + ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
72 | + ); |
|
73 | + } |
|
74 | + $schema = $schema->toArray(); |
|
75 | + return apply_filters('site-reviews/schema/'.$schema['@type'], $schema, $args); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public function render() |
|
82 | - { |
|
83 | - if (empty(glsr()->schemas)) { |
|
84 | - return; |
|
85 | - } |
|
86 | - printf('<script type="application/ld+json">%s</script>', json_encode( |
|
87 | - apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
88 | - JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
|
89 | - )); |
|
90 | - } |
|
78 | + /** |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public function render() |
|
82 | + { |
|
83 | + if (empty(glsr()->schemas)) { |
|
84 | + return; |
|
85 | + } |
|
86 | + printf('<script type="application/ld+json">%s</script>', json_encode( |
|
87 | + apply_filters('site-reviews/schema/all', glsr()->schemas), |
|
88 | + JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
|
89 | + )); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function store(array $schema) |
|
96 | - { |
|
97 | - $schemas = glsr()->schemas; |
|
98 | - $schemas[] = $schema; |
|
99 | - glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
100 | - } |
|
92 | + /** |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function store(array $schema) |
|
96 | + { |
|
97 | + $schemas = glsr()->schemas; |
|
98 | + $schemas[] = $schema; |
|
99 | + glsr()->schemas = array_map('unserialize', array_unique(array_map('serialize', $schemas))); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * @param Review $review |
|
104 | - * @return array |
|
105 | - */ |
|
106 | - protected function buildReview($review) |
|
107 | - { |
|
108 | - $schema = $this->getSchemaType('Review') |
|
109 | - ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
110 | - $schema->name($review->title); |
|
111 | - }) |
|
112 | - ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
113 | - $schema->reviewBody($review->content); |
|
114 | - }) |
|
115 | - ->datePublished((new DateTime($review->date))) |
|
116 | - ->author($this->getSchemaType('Person')->name($review->author)) |
|
117 | - ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
118 | - if (!empty($review->rating)) { |
|
119 | - $schema->reviewRating( |
|
120 | - $this->getSchemaType('Rating') |
|
121 | - ->ratingValue($review->rating) |
|
122 | - ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
123 | - ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
124 | - ); |
|
125 | - } |
|
126 | - return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
127 | - } |
|
102 | + /** |
|
103 | + * @param Review $review |
|
104 | + * @return array |
|
105 | + */ |
|
106 | + protected function buildReview($review) |
|
107 | + { |
|
108 | + $schema = $this->getSchemaType('Review') |
|
109 | + ->doIf(!in_array('title', $this->args['hide']), function ($schema) use ($review) { |
|
110 | + $schema->name($review->title); |
|
111 | + }) |
|
112 | + ->doIf(!in_array('excerpt', $this->args['hide']), function ($schema) use ($review) { |
|
113 | + $schema->reviewBody($review->content); |
|
114 | + }) |
|
115 | + ->datePublished((new DateTime($review->date))) |
|
116 | + ->author($this->getSchemaType('Person')->name($review->author)) |
|
117 | + ->itemReviewed($this->getSchemaType()->name($this->getSchemaOptionValue('name'))); |
|
118 | + if (!empty($review->rating)) { |
|
119 | + $schema->reviewRating( |
|
120 | + $this->getSchemaType('Rating') |
|
121 | + ->ratingValue($review->rating) |
|
122 | + ->bestRating(glsr()->constant('MAX_RATING', Rating::class)) |
|
123 | + ->worstRating(glsr()->constant('MIN_RATING', Rating::class)) |
|
124 | + ); |
|
125 | + } |
|
126 | + return apply_filters('site-reviews/schema/review', $schema->toArray(), $review, $this->args); |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @param mixed $schema |
|
131 | - * @return mixed |
|
132 | - */ |
|
133 | - protected function buildSchemaValues($schema, array $values = []) |
|
134 | - { |
|
135 | - foreach ($values as $value) { |
|
136 | - $option = $this->getSchemaOptionValue($value); |
|
137 | - if (empty($option)) { |
|
138 | - continue; |
|
139 | - } |
|
140 | - $schema->$value($option); |
|
141 | - } |
|
142 | - return $schema; |
|
143 | - } |
|
129 | + /** |
|
130 | + * @param mixed $schema |
|
131 | + * @return mixed |
|
132 | + */ |
|
133 | + protected function buildSchemaValues($schema, array $values = []) |
|
134 | + { |
|
135 | + foreach ($values as $value) { |
|
136 | + $option = $this->getSchemaOptionValue($value); |
|
137 | + if (empty($option)) { |
|
138 | + continue; |
|
139 | + } |
|
140 | + $schema->$value($option); |
|
141 | + } |
|
142 | + return $schema; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * @return mixed |
|
147 | - */ |
|
148 | - protected function buildSummaryForCustom() |
|
149 | - { |
|
150 | - return $this->buildSchemaValues($this->getSchemaType(), [ |
|
151 | - 'description', 'image', 'name', 'url', |
|
152 | - ]); |
|
153 | - } |
|
145 | + /** |
|
146 | + * @return mixed |
|
147 | + */ |
|
148 | + protected function buildSummaryForCustom() |
|
149 | + { |
|
150 | + return $this->buildSchemaValues($this->getSchemaType(), [ |
|
151 | + 'description', 'image', 'name', 'url', |
|
152 | + ]); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * @return mixed |
|
157 | - */ |
|
158 | - protected function buildSummaryForLocalBusiness() |
|
159 | - { |
|
160 | - return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
161 | - 'address', 'priceRange', 'telephone', |
|
162 | - ]); |
|
163 | - } |
|
155 | + /** |
|
156 | + * @return mixed |
|
157 | + */ |
|
158 | + protected function buildSummaryForLocalBusiness() |
|
159 | + { |
|
160 | + return $this->buildSchemaValues($this->buildSummaryForCustom(), [ |
|
161 | + 'address', 'priceRange', 'telephone', |
|
162 | + ]); |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * @return mixed |
|
167 | - */ |
|
168 | - protected function buildSummaryForProduct() |
|
169 | - { |
|
170 | - $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
171 | - $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
172 | - 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
|
173 | - ]); |
|
174 | - return $this->buildSummaryForCustom() |
|
175 | - ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
176 | - $schema->offers($offers); |
|
177 | - }) |
|
178 | - ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
179 | - } |
|
165 | + /** |
|
166 | + * @return mixed |
|
167 | + */ |
|
168 | + protected function buildSummaryForProduct() |
|
169 | + { |
|
170 | + $offerType = $this->getSchemaOption('offerType', 'AggregateOffer'); |
|
171 | + $offers = $this->buildSchemaValues($this->getSchemaType($offerType), [ |
|
172 | + 'highPrice', 'lowPrice', 'price', 'priceCurrency', |
|
173 | + ]); |
|
174 | + return $this->buildSummaryForCustom() |
|
175 | + ->doIf(!empty($offers->getProperties()), function ($schema) use ($offers) { |
|
176 | + $schema->offers($offers); |
|
177 | + }) |
|
178 | + ->setProperty('@id', $this->getSchemaOptionValue('url').'#product'); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - protected function getRatingCounts() |
|
185 | - { |
|
186 | - if (!isset($this->ratingCounts)) { |
|
187 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
188 | - } |
|
189 | - return $this->ratingCounts; |
|
190 | - } |
|
181 | + /** |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + protected function getRatingCounts() |
|
185 | + { |
|
186 | + if (!isset($this->ratingCounts)) { |
|
187 | + $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($this->args); |
|
188 | + } |
|
189 | + return $this->ratingCounts; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * @return int|float |
|
194 | - */ |
|
195 | - protected function getRatingValue() |
|
196 | - { |
|
197 | - return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
198 | - } |
|
192 | + /** |
|
193 | + * @return int|float |
|
194 | + */ |
|
195 | + protected function getRatingValue() |
|
196 | + { |
|
197 | + return glsr(Rating::class)->getAverage($this->getRatingCounts()); |
|
198 | + } |
|
199 | 199 | |
200 | - /** |
|
201 | - * @param string $option |
|
202 | - * @param string $fallback |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - protected function getSchemaOption($option, $fallback) |
|
206 | - { |
|
207 | - $option = strtolower($option); |
|
208 | - if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
209 | - return $schemaOption; |
|
210 | - } |
|
211 | - $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
212 | - if (is_array($setting)) { |
|
213 | - return $this->getSchemaOptionDefault($setting, $fallback); |
|
214 | - } |
|
215 | - return !empty($setting) |
|
216 | - ? $setting |
|
217 | - : $fallback; |
|
218 | - } |
|
200 | + /** |
|
201 | + * @param string $option |
|
202 | + * @param string $fallback |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + protected function getSchemaOption($option, $fallback) |
|
206 | + { |
|
207 | + $option = strtolower($option); |
|
208 | + if ($schemaOption = trim((string) get_post_meta(intval(get_the_ID()), 'schema_'.$option, true))) { |
|
209 | + return $schemaOption; |
|
210 | + } |
|
211 | + $setting = glsr(OptionManager::class)->get('settings.schema.'.$option); |
|
212 | + if (is_array($setting)) { |
|
213 | + return $this->getSchemaOptionDefault($setting, $fallback); |
|
214 | + } |
|
215 | + return !empty($setting) |
|
216 | + ? $setting |
|
217 | + : $fallback; |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * @param string $fallback |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - protected function getSchemaOptionDefault(array $setting, $fallback) |
|
225 | - { |
|
226 | - $setting = wp_parse_args($setting, [ |
|
227 | - 'custom' => '', |
|
228 | - 'default' => $fallback, |
|
229 | - ]); |
|
230 | - return 'custom' != $setting['default'] |
|
231 | - ? $setting['default'] |
|
232 | - : $setting['custom']; |
|
233 | - } |
|
220 | + /** |
|
221 | + * @param string $fallback |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + protected function getSchemaOptionDefault(array $setting, $fallback) |
|
225 | + { |
|
226 | + $setting = wp_parse_args($setting, [ |
|
227 | + 'custom' => '', |
|
228 | + 'default' => $fallback, |
|
229 | + ]); |
|
230 | + return 'custom' != $setting['default'] |
|
231 | + ? $setting['default'] |
|
232 | + : $setting['custom']; |
|
233 | + } |
|
234 | 234 | |
235 | - /** |
|
236 | - * @param string $option |
|
237 | - * @param string $fallback |
|
238 | - * @return void|string |
|
239 | - */ |
|
240 | - protected function getSchemaOptionValue($option, $fallback = 'post') |
|
241 | - { |
|
242 | - $value = $this->getSchemaOption($option, $fallback); |
|
243 | - if ($value != $fallback) { |
|
244 | - return $value; |
|
245 | - } |
|
246 | - if (!is_single() && !is_page()) { |
|
247 | - return; |
|
248 | - } |
|
249 | - $method = glsr(Helper::class)->buildMethodName($option, 'getThing'); |
|
250 | - if (method_exists($this, $method)) { |
|
251 | - return $this->$method(); |
|
252 | - } |
|
253 | - } |
|
235 | + /** |
|
236 | + * @param string $option |
|
237 | + * @param string $fallback |
|
238 | + * @return void|string |
|
239 | + */ |
|
240 | + protected function getSchemaOptionValue($option, $fallback = 'post') |
|
241 | + { |
|
242 | + $value = $this->getSchemaOption($option, $fallback); |
|
243 | + if ($value != $fallback) { |
|
244 | + return $value; |
|
245 | + } |
|
246 | + if (!is_single() && !is_page()) { |
|
247 | + return; |
|
248 | + } |
|
249 | + $method = glsr(Helper::class)->buildMethodName($option, 'getThing'); |
|
250 | + if (method_exists($this, $method)) { |
|
251 | + return $this->$method(); |
|
252 | + } |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * @param string|null $type |
|
257 | - * @return mixed |
|
258 | - */ |
|
259 | - protected function getSchemaType($type = null) |
|
260 | - { |
|
261 | - if (!is_string($type)) { |
|
262 | - $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
263 | - } |
|
264 | - $className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema'); |
|
265 | - return class_exists($className) |
|
266 | - ? new $className() |
|
267 | - : new UnknownType($type); |
|
268 | - } |
|
255 | + /** |
|
256 | + * @param string|null $type |
|
257 | + * @return mixed |
|
258 | + */ |
|
259 | + protected function getSchemaType($type = null) |
|
260 | + { |
|
261 | + if (!is_string($type)) { |
|
262 | + $type = $this->getSchemaOption('type', 'LocalBusiness'); |
|
263 | + } |
|
264 | + $className = glsr(Helper::class)->buildClassName($type, 'Modules\Schema'); |
|
265 | + return class_exists($className) |
|
266 | + ? new $className() |
|
267 | + : new UnknownType($type); |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * @return string |
|
272 | - */ |
|
273 | - protected function getThingDescription() |
|
274 | - { |
|
275 | - $description = strip_shortcodes(wp_strip_all_tags(get_the_excerpt())); |
|
276 | - return wp_trim_words($description, apply_filters('excerpt_length', 55)); |
|
277 | - } |
|
270 | + /** |
|
271 | + * @return string |
|
272 | + */ |
|
273 | + protected function getThingDescription() |
|
274 | + { |
|
275 | + $description = strip_shortcodes(wp_strip_all_tags(get_the_excerpt())); |
|
276 | + return wp_trim_words($description, apply_filters('excerpt_length', 55)); |
|
277 | + } |
|
278 | 278 | |
279 | - /** |
|
280 | - * @return string |
|
281 | - */ |
|
282 | - protected function getThingImage() |
|
283 | - { |
|
284 | - return (string) get_the_post_thumbnail_url(null, 'large'); |
|
285 | - } |
|
279 | + /** |
|
280 | + * @return string |
|
281 | + */ |
|
282 | + protected function getThingImage() |
|
283 | + { |
|
284 | + return (string) get_the_post_thumbnail_url(null, 'large'); |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
288 | - * @return string |
|
289 | - */ |
|
290 | - protected function getThingName() |
|
291 | - { |
|
292 | - return get_the_title(); |
|
293 | - } |
|
287 | + /** |
|
288 | + * @return string |
|
289 | + */ |
|
290 | + protected function getThingName() |
|
291 | + { |
|
292 | + return get_the_title(); |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - protected function getThingUrl() |
|
299 | - { |
|
300 | - return (string) get_the_permalink(); |
|
301 | - } |
|
295 | + /** |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + protected function getThingUrl() |
|
299 | + { |
|
300 | + return (string) get_the_permalink(); |
|
301 | + } |
|
302 | 302 | } |
@@ -7,83 +7,83 @@ |
||
7 | 7 | |
8 | 8 | class Wpml implements Contract |
9 | 9 | { |
10 | - const PLUGIN_NAME = 'WPML'; |
|
11 | - const SUPPORTED_VERSION = '3.3.5'; |
|
10 | + const PLUGIN_NAME = 'WPML'; |
|
11 | + const SUPPORTED_VERSION = '3.3.5'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * {@inheritdoc} |
|
15 | - */ |
|
16 | - public function getPost($postId) |
|
17 | - { |
|
18 | - $postId = trim($postId); |
|
19 | - if (!is_numeric($postId)) { |
|
20 | - return; |
|
21 | - } |
|
22 | - if ($this->isEnabled()) { |
|
23 | - $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | - } |
|
25 | - return get_post(intval($postId)); |
|
26 | - } |
|
13 | + /** |
|
14 | + * {@inheritdoc} |
|
15 | + */ |
|
16 | + public function getPost($postId) |
|
17 | + { |
|
18 | + $postId = trim($postId); |
|
19 | + if (!is_numeric($postId)) { |
|
20 | + return; |
|
21 | + } |
|
22 | + if ($this->isEnabled()) { |
|
23 | + $postId = apply_filters('wpml_object_id', $postId, 'any', true); |
|
24 | + } |
|
25 | + return get_post(intval($postId)); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritdoc} |
|
30 | - */ |
|
31 | - public function getPostIds(array $postIds) |
|
32 | - { |
|
33 | - if (!$this->isEnabled()) { |
|
34 | - return $postIds; |
|
35 | - } |
|
36 | - $newPostIds = []; |
|
37 | - foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | - $postType = get_post_type($postId); |
|
39 | - if (!$postType) { |
|
40 | - continue; |
|
41 | - } |
|
42 | - $elementType = 'post_'.$postType; |
|
43 | - $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | - $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | - if (!is_array($translations)) { |
|
46 | - $translations = []; |
|
47 | - } |
|
48 | - $newPostIds = array_merge( |
|
49 | - $newPostIds, |
|
50 | - array_column($translations, 'element_id') |
|
51 | - ); |
|
52 | - } |
|
53 | - return $this->cleanIds($newPostIds); |
|
54 | - } |
|
28 | + /** |
|
29 | + * {@inheritdoc} |
|
30 | + */ |
|
31 | + public function getPostIds(array $postIds) |
|
32 | + { |
|
33 | + if (!$this->isEnabled()) { |
|
34 | + return $postIds; |
|
35 | + } |
|
36 | + $newPostIds = []; |
|
37 | + foreach ($this->cleanIds($postIds) as $postId) { |
|
38 | + $postType = get_post_type($postId); |
|
39 | + if (!$postType) { |
|
40 | + continue; |
|
41 | + } |
|
42 | + $elementType = 'post_'.$postType; |
|
43 | + $trid = apply_filters('wpml_element_trid', null, $postId, $elementType); |
|
44 | + $translations = apply_filters('wpml_get_element_translations', null, $trid, $elementType); |
|
45 | + if (!is_array($translations)) { |
|
46 | + $translations = []; |
|
47 | + } |
|
48 | + $newPostIds = array_merge( |
|
49 | + $newPostIds, |
|
50 | + array_column($translations, 'element_id') |
|
51 | + ); |
|
52 | + } |
|
53 | + return $this->cleanIds($newPostIds); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function isActive() |
|
60 | - { |
|
61 | - return defined('ICL_SITEPRESS_VERSION'); |
|
62 | - } |
|
56 | + /** |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function isActive() |
|
60 | + { |
|
61 | + return defined('ICL_SITEPRESS_VERSION'); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - public function isEnabled() |
|
68 | - { |
|
69 | - return $this->isActive() |
|
70 | - && 'wpml' == glsr(OptionManager::class)->get('settings.general.support.multilingual'); |
|
71 | - } |
|
64 | + /** |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + public function isEnabled() |
|
68 | + { |
|
69 | + return $this->isActive() |
|
70 | + && 'wpml' == glsr(OptionManager::class)->get('settings.general.support.multilingual'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * {@inheritdoc} |
|
75 | - */ |
|
76 | - public function isSupported() |
|
77 | - { |
|
78 | - return $this->isActive() |
|
79 | - && version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>='); |
|
80 | - } |
|
73 | + /** |
|
74 | + * {@inheritdoc} |
|
75 | + */ |
|
76 | + public function isSupported() |
|
77 | + { |
|
78 | + return $this->isActive() |
|
79 | + && version_compare(ICL_SITEPRESS_VERSION, static::SUPPORTED_VERSION, '>='); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - protected function cleanIds(array $postIds) |
|
86 | - { |
|
87 | - return array_filter(array_unique($postIds)); |
|
88 | - } |
|
82 | + /** |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + protected function cleanIds(array $postIds) |
|
86 | + { |
|
87 | + return array_filter(array_unique($postIds)); |
|
88 | + } |
|
89 | 89 | } |