@@ -8,66 +8,66 @@ |
||
8 | 8 | |
9 | 9 | class Migrate_4_5_0 |
10 | 10 | { |
11 | - /** |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function migrateOptions() |
|
15 | - { |
|
16 | - $isAccountVerified = glsr(OptionManager::class)->getWP('_glsr_rebusify', false); |
|
17 | - update_option('_glsr_trustalyze', $isAccountVerified); |
|
18 | - delete_option('_glsr_rebusify'); |
|
19 | - } |
|
11 | + /** |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function migrateOptions() |
|
15 | + { |
|
16 | + $isAccountVerified = glsr(OptionManager::class)->getWP('_glsr_rebusify', false); |
|
17 | + update_option('_glsr_trustalyze', $isAccountVerified); |
|
18 | + delete_option('_glsr_rebusify'); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - public function migrateSettings() |
|
25 | - { |
|
26 | - if ($settings = get_option(OptionManager::databaseKey(4))) { |
|
27 | - $settings = Arr::set($settings, 'settings.general.trustalyze', |
|
28 | - Arr::get($settings, 'settings.general.rebusify') |
|
29 | - ); |
|
30 | - $settings = Arr::set($settings, 'settings.general.trustalyze_email', |
|
31 | - Arr::get($settings, 'settings.general.rebusify_email') |
|
32 | - ); |
|
33 | - $settings = Arr::set($settings, 'settings.general.trustalyze_serial', |
|
34 | - Arr::get($settings, 'settings.general.rebusify_serial') |
|
35 | - ); |
|
36 | - unset($settings['settings']['general']['rebusify']); |
|
37 | - unset($settings['settings']['general']['rebusify_email']); |
|
38 | - unset($settings['settings']['general']['rebusify_serial']); |
|
39 | - update_option(OptionManager::databaseKey(4), $settings); |
|
40 | - } |
|
41 | - } |
|
21 | + /** |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + public function migrateSettings() |
|
25 | + { |
|
26 | + if ($settings = get_option(OptionManager::databaseKey(4))) { |
|
27 | + $settings = Arr::set($settings, 'settings.general.trustalyze', |
|
28 | + Arr::get($settings, 'settings.general.rebusify') |
|
29 | + ); |
|
30 | + $settings = Arr::set($settings, 'settings.general.trustalyze_email', |
|
31 | + Arr::get($settings, 'settings.general.rebusify_email') |
|
32 | + ); |
|
33 | + $settings = Arr::set($settings, 'settings.general.trustalyze_serial', |
|
34 | + Arr::get($settings, 'settings.general.rebusify_serial') |
|
35 | + ); |
|
36 | + unset($settings['settings']['general']['rebusify']); |
|
37 | + unset($settings['settings']['general']['rebusify_email']); |
|
38 | + unset($settings['settings']['general']['rebusify_serial']); |
|
39 | + update_option(OptionManager::databaseKey(4), $settings); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function migrateUserMeta() |
|
47 | - { |
|
48 | - $metaKey = NoticeController::USER_META_KEY; |
|
49 | - $userIds = get_users([ |
|
50 | - 'fields' => 'ID', |
|
51 | - 'meta_compare' => 'EXISTS', |
|
52 | - 'meta_key' => $metaKey, |
|
53 | - ]); |
|
54 | - foreach ($userIds as $userId) { |
|
55 | - $meta = (array) get_user_meta($userId, $metaKey, true); |
|
56 | - if (array_key_exists('rebusify', $meta)) { |
|
57 | - $meta['trustalyze'] = $meta['rebusify']; |
|
58 | - unset($meta['rebusify']); |
|
59 | - update_user_meta($userId, $metaKey, $meta); |
|
60 | - } |
|
61 | - } |
|
62 | - } |
|
43 | + /** |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function migrateUserMeta() |
|
47 | + { |
|
48 | + $metaKey = NoticeController::USER_META_KEY; |
|
49 | + $userIds = get_users([ |
|
50 | + 'fields' => 'ID', |
|
51 | + 'meta_compare' => 'EXISTS', |
|
52 | + 'meta_key' => $metaKey, |
|
53 | + ]); |
|
54 | + foreach ($userIds as $userId) { |
|
55 | + $meta = (array) get_user_meta($userId, $metaKey, true); |
|
56 | + if (array_key_exists('rebusify', $meta)) { |
|
57 | + $meta['trustalyze'] = $meta['rebusify']; |
|
58 | + unset($meta['rebusify']); |
|
59 | + update_user_meta($userId, $metaKey, $meta); |
|
60 | + } |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return void |
|
66 | - */ |
|
67 | - public function run() |
|
68 | - { |
|
69 | - $this->migrateOptions(); |
|
70 | - $this->migrateSettings(); |
|
71 | - $this->migrateUserMeta(); |
|
72 | - } |
|
64 | + /** |
|
65 | + * @return void |
|
66 | + */ |
|
67 | + public function run() |
|
68 | + { |
|
69 | + $this->migrateOptions(); |
|
70 | + $this->migrateSettings(); |
|
71 | + $this->migrateUserMeta(); |
|
72 | + } |
|
73 | 73 | } |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | */ |
14 | 14 | public function migrateOptions() |
15 | 15 | { |
16 | - $isAccountVerified = glsr(OptionManager::class)->getWP('_glsr_rebusify', false); |
|
17 | - update_option('_glsr_trustalyze', $isAccountVerified); |
|
18 | - delete_option('_glsr_rebusify'); |
|
16 | + $isAccountVerified = glsr( OptionManager::class )->getWP( '_glsr_rebusify', false ); |
|
17 | + update_option( '_glsr_trustalyze', $isAccountVerified ); |
|
18 | + delete_option( '_glsr_rebusify' ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,20 +23,20 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function migrateSettings() |
25 | 25 | { |
26 | - if ($settings = get_option(OptionManager::databaseKey(4))) { |
|
27 | - $settings = Arr::set($settings, 'settings.general.trustalyze', |
|
28 | - Arr::get($settings, 'settings.general.rebusify') |
|
26 | + if( $settings = get_option( OptionManager::databaseKey( 4 ) ) ) { |
|
27 | + $settings = Arr::set( $settings, 'settings.general.trustalyze', |
|
28 | + Arr::get( $settings, 'settings.general.rebusify' ) |
|
29 | 29 | ); |
30 | - $settings = Arr::set($settings, 'settings.general.trustalyze_email', |
|
31 | - Arr::get($settings, 'settings.general.rebusify_email') |
|
30 | + $settings = Arr::set( $settings, 'settings.general.trustalyze_email', |
|
31 | + Arr::get( $settings, 'settings.general.rebusify_email' ) |
|
32 | 32 | ); |
33 | - $settings = Arr::set($settings, 'settings.general.trustalyze_serial', |
|
34 | - Arr::get($settings, 'settings.general.rebusify_serial') |
|
33 | + $settings = Arr::set( $settings, 'settings.general.trustalyze_serial', |
|
34 | + Arr::get( $settings, 'settings.general.rebusify_serial' ) |
|
35 | 35 | ); |
36 | 36 | unset($settings['settings']['general']['rebusify']); |
37 | 37 | unset($settings['settings']['general']['rebusify_email']); |
38 | 38 | unset($settings['settings']['general']['rebusify_serial']); |
39 | - update_option(OptionManager::databaseKey(4), $settings); |
|
39 | + update_option( OptionManager::databaseKey( 4 ), $settings ); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
@@ -46,17 +46,17 @@ discard block |
||
46 | 46 | public function migrateUserMeta() |
47 | 47 | { |
48 | 48 | $metaKey = NoticeController::USER_META_KEY; |
49 | - $userIds = get_users([ |
|
49 | + $userIds = get_users( [ |
|
50 | 50 | 'fields' => 'ID', |
51 | 51 | 'meta_compare' => 'EXISTS', |
52 | 52 | 'meta_key' => $metaKey, |
53 | - ]); |
|
54 | - foreach ($userIds as $userId) { |
|
55 | - $meta = (array) get_user_meta($userId, $metaKey, true); |
|
56 | - if (array_key_exists('rebusify', $meta)) { |
|
53 | + ] ); |
|
54 | + foreach( $userIds as $userId ) { |
|
55 | + $meta = (array)get_user_meta( $userId, $metaKey, true ); |
|
56 | + if( array_key_exists( 'rebusify', $meta ) ) { |
|
57 | 57 | $meta['trustalyze'] = $meta['rebusify']; |
58 | 58 | unset($meta['rebusify']); |
59 | - update_user_meta($userId, $metaKey, $meta); |
|
59 | + update_user_meta( $userId, $metaKey, $meta ); |
|
60 | 60 | } |
61 | 61 | } |
62 | 62 | } |
@@ -1,10 +1,10 @@ discard block |
||
1 | -<?php defined('WPINC') || die; ?> |
|
1 | +<?php defined( 'WPINC' ) || die; ?> |
|
2 | 2 | |
3 | 3 | <div id="support-01" class="glsr-card postbox"> |
4 | 4 | <div class="glsr-card-header"> |
5 | 5 | <h3>Basic Troubleshooting Steps</h3> |
6 | 6 | <button type="button" class="handlediv" aria-expanded="true"> |
7 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
7 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
8 | 8 | <span class="toggle-indicator" aria-hidden="true"></span> |
9 | 9 | </button> |
10 | 10 | </div> |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | <div class="glsr-card-header"> |
33 | 33 | <h3>Common Problems and Solutions</h3> |
34 | 34 | <button type="button" class="handlediv" aria-expanded="true"> |
35 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
35 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
36 | 36 | <span class="toggle-indicator" aria-hidden="true"></span> |
37 | 37 | </button> |
38 | 38 | </div> |
@@ -41,12 +41,12 @@ discard block |
||
41 | 41 | <li> |
42 | 42 | <p class="glsr-heading">Email notifications are not working</p> |
43 | 43 | <p>Site Reviews uses the standard WordPress mail functions to send email. However, this does not guarantee that emails will send successfully as it still depends on your WordPress settings and server configuration being correct.</p> |
44 | - <p>To make sure that emails are correctly sent, please verify that the email you have saved in the "Email Address" setting of the <code><a href="<?= admin_url('options-general.php'); ?>">WordPress General Settings</a></code> page uses the same domain as that of your website. For example, if your website is <code>https://reviews.com</code> then the "Email Address" setting should end with, <code>@reviews.com</code>. If the email address you have saved in the WordPress General Settings does not share the same domain as your website, you will likely experience issues sending email from your WordPress site.</p> |
|
44 | + <p>To make sure that emails are correctly sent, please verify that the email you have saved in the "Email Address" setting of the <code><a href="<?= admin_url( 'options-general.php' ); ?>">WordPress General Settings</a></code> page uses the same domain as that of your website. For example, if your website is <code>https://reviews.com</code> then the "Email Address" setting should end with, <code>@reviews.com</code>. If the email address you have saved in the WordPress General Settings does not share the same domain as your website, you will likely experience issues sending email from your WordPress site.</p> |
|
45 | 45 | <p>If your email notifications are not sending, I recommend that you install the <a href="https://wordpress.org/plugins/check-email/">Check Email</a> plugin to verify that your website is able to correctly send email. See also, <a href="https://www.butlerblog.com/2013/12/12/easy-smtp-email-wordpress-wp_mail/">Easy SMTP email settings for WordPress</a>.</p> |
46 | 46 | </li> |
47 | 47 | <li> |
48 | 48 | <p class="glsr-heading">I only want my reviews to show on the page they were published or assigned to but they are showing on every page.</p> |
49 | - <p>All reviews are unassigned by default. If you want to assign reviews to specific pages, you will need to use the “assign_to” and “assigned_to” shortcode options. Please see the <code><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-shortcodes'); ?>">Shortcodes</a></code> documentation page for more information.</p> |
|
49 | + <p>All reviews are unassigned by default. If you want to assign reviews to specific pages, you will need to use the “assign_to” and “assigned_to” shortcode options. Please see the <code><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-shortcodes' ); ?>">Shortcodes</a></code> documentation page for more information.</p> |
|
50 | 50 | </li> |
51 | 51 | <li> |
52 | 52 | <p class="glsr-heading">My submission form is not assigning reviews to the page even though I have set the option to do so.</p> |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | <div class="glsr-card-header"> |
69 | 69 | <h3>Contact Support</h3> |
70 | 70 | <button type="button" class="handlediv" aria-expanded="true"> |
71 | - <span class="screen-reader-text"><?= __('Toggle documentation panel', 'site-reviews'); ?></span> |
|
71 | + <span class="screen-reader-text"><?= __( 'Toggle documentation panel', 'site-reviews' ); ?></span> |
|
72 | 72 | <span class="toggle-indicator" aria-hidden="true"></span> |
73 | 73 | </button> |
74 | 74 | </div> |
@@ -77,32 +77,32 @@ discard block |
||
77 | 77 | <p>However, you may also contact us directly (expect a slower response time) after confirming the following:</p> |
78 | 78 | <p class="glsr-card-field"> |
79 | 79 | <input type="checkbox" id="step-1" class="glsr-support-step"> |
80 | - <label for="step-1">I have read the <code><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-support'); ?>" data-expand="#support-02">Common Problems and Solutions</a></code> and it does not answer my question.</label> |
|
80 | + <label for="step-1">I have read the <code><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-support' ); ?>" data-expand="#support-02">Common Problems and Solutions</a></code> and it does not answer my question.</label> |
|
81 | 81 | </p> |
82 | 82 | <p class="glsr-card-field"> |
83 | 83 | <input type="checkbox" id="step-2" class="glsr-support-step"> |
84 | - <label for="step-2">I have read the <code><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-faq'); ?>">FAQ</a></code> page and it does not answer my question.</label> |
|
84 | + <label for="step-2">I have read the <code><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-faq' ); ?>">FAQ</a></code> page and it does not answer my question.</label> |
|
85 | 85 | </p> |
86 | 86 | <p class="glsr-card-field"> |
87 | 87 | <input type="checkbox" id="step-3" class="glsr-support-step"> |
88 | - <label for="step-3">I have read the <code><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-shortcodes'); ?>">Shortcodes</a></code> page and it does not answer my question.</label> |
|
88 | + <label for="step-3">I have read the <code><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-shortcodes' ); ?>">Shortcodes</a></code> page and it does not answer my question.</label> |
|
89 | 89 | </p> |
90 | - <?php if (glsr()->hasPermission('documentation', 'hooks')) : ?> |
|
90 | + <?php if( glsr()->hasPermission( 'documentation', 'hooks' ) ) : ?> |
|
91 | 91 | <p class="glsr-card-field"> |
92 | 92 | <input type="checkbox" id="step-4" class="glsr-support-step"> |
93 | - <label for="step-4">I have read the <code><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-hooks'); ?>">Hooks</a></code> page and it does not answer my question.</label> |
|
93 | + <label for="step-4">I have read the <code><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-hooks' ); ?>">Hooks</a></code> page and it does not answer my question.</label> |
|
94 | 94 | </p> |
95 | 95 | <?php endif; ?> |
96 | 96 | <p class="glsr-card-field"> |
97 | 97 | <input type="checkbox" id="step-5" class="glsr-support-step"> |
98 | - <label for="step-5">I have completed the <code><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-support'); ?>" data-expand="#support-01">Basic Troubleshooting Steps</a></code> provided above.</label> |
|
98 | + <label for="step-5">I have completed the <code><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=documentation#tab-support' ); ?>" data-expand="#support-01">Basic Troubleshooting Steps</a></code> provided above.</label> |
|
99 | 99 | </p> |
100 | 100 | <div class="glsr-card-result hidden"> |
101 | 101 | <p><strong>Please send an email to <a href="mailto:[email protected]?subject=Support%20request">[email protected]</a> and include the following details:</strong></p> |
102 | 102 | <ul> |
103 | 103 | <li>A detailed description of the problem you are having and steps to reproduce it.</li> |
104 | - <li>Download and attach the <code><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=tools#tab-console'); ?>">Tools → Console</a></code> log file to the email.</li> |
|
105 | - <li>Download and attach the <code><a href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=tools#tab-system-info'); ?>">Tools → System Info</a></code> report to the email.</li> |
|
104 | + <li>Download and attach the <code><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=tools#tab-console' ); ?>">Tools → Console</a></code> log file to the email.</li> |
|
105 | + <li>Download and attach the <code><a href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=tools#tab-system-info' ); ?>">Tools → System Info</a></code> report to the email.</li> |
|
106 | 106 | <li>Include screenshots if they will help explain the problem.</li> |
107 | 107 | </ul> |
108 | 108 | <p><span class="required">Please be aware that if your email does not include the System Info report and the Console log (as requested above), it will most likely be ignored. Thank you for understanding.</span></p> |
@@ -11,6 +11,6 @@ |
||
11 | 11 | */ |
12 | 12 | class Upgrader |
13 | 13 | { |
14 | - public function run() |
|
15 | - {} |
|
14 | + public function run() |
|
15 | + {} |
|
16 | 16 | } |
@@ -12,5 +12,6 @@ |
||
12 | 12 | class Upgrader |
13 | 13 | { |
14 | 14 | public function run() |
15 | - {} |
|
15 | + { |
|
16 | +} |
|
16 | 17 | } |
@@ -8,47 +8,47 @@ discard block |
||
8 | 8 | |
9 | 9 | class SqlQueries |
10 | 10 | { |
11 | - protected $db; |
|
12 | - protected $postType; |
|
11 | + protected $db; |
|
12 | + protected $postType; |
|
13 | 13 | |
14 | - public function __construct() |
|
15 | - { |
|
16 | - global $wpdb; |
|
17 | - $this->db = $wpdb; |
|
18 | - $this->postType = Application::POST_TYPE; |
|
19 | - } |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + global $wpdb; |
|
17 | + $this->db = $wpdb; |
|
18 | + $this->postType = Application::POST_TYPE; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @return bool |
|
23 | - */ |
|
24 | - public function deletePostCountMetaKeys() |
|
25 | - { |
|
26 | - $this->db->query(" |
|
21 | + /** |
|
22 | + * @return bool |
|
23 | + */ |
|
24 | + public function deletePostCountMetaKeys() |
|
25 | + { |
|
26 | + $this->db->query(" |
|
27 | 27 | DELETE |
28 | 28 | FROM {$this->db->postmeta} |
29 | 29 | WHERE meta_key LIKE '_glsr_%' |
30 | 30 | "); |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function deleteTermCountMetaKeys() |
|
37 | - { |
|
38 | - $this->db->query(" |
|
33 | + /** |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function deleteTermCountMetaKeys() |
|
37 | + { |
|
38 | + $this->db->query(" |
|
39 | 39 | DELETE |
40 | 40 | FROM {$this->db->termmeta} |
41 | 41 | WHERE meta_key LIKE '_glsr_%' |
42 | 42 | "); |
43 | - } |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $metaReviewId |
|
47 | - * @return int |
|
48 | - */ |
|
49 | - public function getPostIdFromReviewId($metaReviewId) |
|
50 | - { |
|
51 | - $postId = $this->db->get_var(" |
|
45 | + /** |
|
46 | + * @param string $metaReviewId |
|
47 | + * @return int |
|
48 | + */ |
|
49 | + public function getPostIdFromReviewId($metaReviewId) |
|
50 | + { |
|
51 | + $postId = $this->db->get_var(" |
|
52 | 52 | SELECT p.ID |
53 | 53 | FROM {$this->db->posts} AS p |
54 | 54 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | AND m.meta_key = '_review_id' |
57 | 57 | AND m.meta_value = '{$metaReviewId}' |
58 | 58 | "); |
59 | - return intval($postId); |
|
60 | - } |
|
59 | + return intval($postId); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param int $lastPostId |
|
64 | - * @param int $limit |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
68 | - { |
|
69 | - return (array) $this->db->get_results(" |
|
62 | + /** |
|
63 | + * @param int $lastPostId |
|
64 | + * @param int $limit |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
68 | + { |
|
69 | + return (array) $this->db->get_results(" |
|
70 | 70 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
71 | 71 | FROM {$this->db->posts} AS p |
72 | 72 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -81,17 +81,17 @@ discard block |
||
81 | 81 | ORDER By p.ID ASC |
82 | 82 | LIMIT {$limit} |
83 | 83 | "); |
84 | - } |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @todo remove this? |
|
88 | - * @param string $metaKey |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - public function getReviewCountsFor($metaKey) |
|
92 | - { |
|
93 | - $metaKey = Str::prefix('_', $metaKey); |
|
94 | - return (array) $this->db->get_results(" |
|
86 | + /** |
|
87 | + * @todo remove this? |
|
88 | + * @param string $metaKey |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + public function getReviewCountsFor($metaKey) |
|
92 | + { |
|
93 | + $metaKey = Str::prefix('_', $metaKey); |
|
94 | + return (array) $this->db->get_results(" |
|
95 | 95 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
96 | 96 | FROM {$this->db->posts} AS p |
97 | 97 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -99,16 +99,16 @@ discard block |
||
99 | 99 | AND m.meta_key = '{$metaKey}' |
100 | 100 | GROUP BY name |
101 | 101 | "); |
102 | - } |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * @todo remove this? |
|
106 | - * @param string $reviewType |
|
107 | - * @return array |
|
108 | - */ |
|
109 | - public function getReviewIdsByType($reviewType) |
|
110 | - { |
|
111 | - $results = $this->db->get_col(" |
|
104 | + /** |
|
105 | + * @todo remove this? |
|
106 | + * @param string $reviewType |
|
107 | + * @return array |
|
108 | + */ |
|
109 | + public function getReviewIdsByType($reviewType) |
|
110 | + { |
|
111 | + $results = $this->db->get_col(" |
|
112 | 112 | SELECT DISTINCT m1.meta_value AS review_id |
113 | 113 | FROM {$this->db->posts} AS p |
114 | 114 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -118,20 +118,20 @@ discard block |
||
118 | 118 | AND m2.meta_key = '_review_type' |
119 | 119 | AND m2.meta_value = '{$reviewType}' |
120 | 120 | "); |
121 | - return array_keys(array_flip($results)); |
|
122 | - } |
|
121 | + return array_keys(array_flip($results)); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @param int $greaterThanId |
|
126 | - * @param int $limit |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
130 | - { |
|
131 | - sort($postIds); |
|
132 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
133 | - $postIds = implode(',', $postIds); |
|
134 | - return (array) $this->db->get_results(" |
|
124 | + /** |
|
125 | + * @param int $greaterThanId |
|
126 | + * @param int $limit |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
130 | + { |
|
131 | + sort($postIds); |
|
132 | + $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
133 | + $postIds = implode(',', $postIds); |
|
134 | + return (array) $this->db->get_results(" |
|
135 | 135 | SELECT p.ID, m.meta_value AS rating |
136 | 136 | FROM {$this->db->posts} AS p |
137 | 137 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -144,20 +144,20 @@ discard block |
||
144 | 144 | ORDER By p.ID ASC |
145 | 145 | LIMIT {$limit} |
146 | 146 | "); |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * @param string $key |
|
151 | - * @param string $status |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public function getReviewsMeta($key, $status = 'publish') |
|
155 | - { |
|
156 | - $postStatusQuery = 'all' != $status && !empty($status) |
|
157 | - ? "AND p.post_status = '{$status}'" |
|
158 | - : ''; |
|
159 | - $key = Str::prefix('_', $key); |
|
160 | - $values = $this->db->get_col(" |
|
149 | + /** |
|
150 | + * @param string $key |
|
151 | + * @param string $status |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public function getReviewsMeta($key, $status = 'publish') |
|
155 | + { |
|
156 | + $postStatusQuery = 'all' != $status && !empty($status) |
|
157 | + ? "AND p.post_status = '{$status}'" |
|
158 | + : ''; |
|
159 | + $key = Str::prefix('_', $key); |
|
160 | + $values = $this->db->get_col(" |
|
161 | 161 | SELECT DISTINCT m.meta_value |
162 | 162 | FROM {$this->db->postmeta} m |
163 | 163 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -168,42 +168,42 @@ discard block |
||
168 | 168 | GROUP BY p.ID -- remove duplicate meta_value entries |
169 | 169 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
170 | 170 | "); |
171 | - sort($values); |
|
172 | - return $values; |
|
173 | - } |
|
171 | + sort($values); |
|
172 | + return $values; |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * @param string $and |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - protected function getAndForCounts(array $args, $and = '') |
|
180 | - { |
|
181 | - $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', []))); |
|
182 | - $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', []))); |
|
183 | - if (!empty($args['type'])) { |
|
184 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
185 | - } |
|
186 | - if ($postIds) { |
|
187 | - $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
188 | - } |
|
189 | - if ($termIds) { |
|
190 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
191 | - } |
|
192 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
193 | - } |
|
175 | + /** |
|
176 | + * @param string $and |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + protected function getAndForCounts(array $args, $and = '') |
|
180 | + { |
|
181 | + $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', []))); |
|
182 | + $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', []))); |
|
183 | + if (!empty($args['type'])) { |
|
184 | + $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
185 | + } |
|
186 | + if ($postIds) { |
|
187 | + $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
188 | + } |
|
189 | + if ($termIds) { |
|
190 | + $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
191 | + } |
|
192 | + return apply_filters('site-reviews/query/and-for-counts', $and); |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
196 | - * @param string $innerJoin |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
200 | - { |
|
201 | - if (!empty(Arr::get($args, 'post_ids'))) { |
|
202 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
203 | - } |
|
204 | - if (!empty(Arr::get($args, 'term_ids'))) { |
|
205 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
206 | - } |
|
207 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
208 | - } |
|
195 | + /** |
|
196 | + * @param string $innerJoin |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
200 | + { |
|
201 | + if (!empty(Arr::get($args, 'post_ids'))) { |
|
202 | + $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
203 | + } |
|
204 | + if (!empty(Arr::get($args, 'term_ids'))) { |
|
205 | + $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
206 | + } |
|
207 | + return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
208 | + } |
|
209 | 209 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function deletePostCountMetaKeys() |
25 | 25 | { |
26 | - $this->db->query(" |
|
26 | + $this->db->query( " |
|
27 | 27 | DELETE |
28 | 28 | FROM {$this->db->postmeta} |
29 | 29 | WHERE meta_key LIKE '_glsr_%' |
30 | - "); |
|
30 | + " ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -35,28 +35,28 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function deleteTermCountMetaKeys() |
37 | 37 | { |
38 | - $this->db->query(" |
|
38 | + $this->db->query( " |
|
39 | 39 | DELETE |
40 | 40 | FROM {$this->db->termmeta} |
41 | 41 | WHERE meta_key LIKE '_glsr_%' |
42 | - "); |
|
42 | + " ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @param string $metaReviewId |
47 | 47 | * @return int |
48 | 48 | */ |
49 | - public function getPostIdFromReviewId($metaReviewId) |
|
49 | + public function getPostIdFromReviewId( $metaReviewId ) |
|
50 | 50 | { |
51 | - $postId = $this->db->get_var(" |
|
51 | + $postId = $this->db->get_var( " |
|
52 | 52 | SELECT p.ID |
53 | 53 | FROM {$this->db->posts} AS p |
54 | 54 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
55 | 55 | WHERE p.post_type = '{$this->postType}' |
56 | 56 | AND m.meta_key = '_review_id' |
57 | 57 | AND m.meta_value = '{$metaReviewId}' |
58 | - "); |
|
59 | - return intval($postId); |
|
58 | + " ); |
|
59 | + return intval( $postId ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -64,23 +64,23 @@ discard block |
||
64 | 64 | * @param int $limit |
65 | 65 | * @return array |
66 | 66 | */ |
67 | - public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500) |
|
67 | + public function getReviewCounts( array $args, $lastPostId = 0, $limit = 500 ) |
|
68 | 68 | { |
69 | - return (array) $this->db->get_results(" |
|
69 | + return (array)$this->db->get_results( " |
|
70 | 70 | SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type |
71 | 71 | FROM {$this->db->posts} AS p |
72 | 72 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
73 | 73 | INNER JOIN {$this->db->postmeta} AS m2 ON p.ID = m2.post_id |
74 | - {$this->getInnerJoinForCounts($args)} |
|
74 | + {$this->getInnerJoinForCounts( $args )} |
|
75 | 75 | WHERE p.ID > {$lastPostId} |
76 | 76 | AND p.post_status = 'publish' |
77 | 77 | AND p.post_type = '{$this->postType}' |
78 | 78 | AND m1.meta_key = '_rating' |
79 | 79 | AND m2.meta_key = '_review_type' |
80 | - {$this->getAndForCounts($args)} |
|
80 | + {$this->getAndForCounts( $args )} |
|
81 | 81 | ORDER By p.ID ASC |
82 | 82 | LIMIT {$limit} |
83 | - "); |
|
83 | + " ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | * @param string $metaKey |
89 | 89 | * @return array |
90 | 90 | */ |
91 | - public function getReviewCountsFor($metaKey) |
|
91 | + public function getReviewCountsFor( $metaKey ) |
|
92 | 92 | { |
93 | - $metaKey = Str::prefix('_', $metaKey); |
|
94 | - return (array) $this->db->get_results(" |
|
93 | + $metaKey = Str::prefix( '_', $metaKey ); |
|
94 | + return (array)$this->db->get_results( " |
|
95 | 95 | SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts |
96 | 96 | FROM {$this->db->posts} AS p |
97 | 97 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
98 | 98 | WHERE p.post_type = '{$this->postType}' |
99 | 99 | AND m.meta_key = '{$metaKey}' |
100 | 100 | GROUP BY name |
101 | - "); |
|
101 | + " ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param string $reviewType |
107 | 107 | * @return array |
108 | 108 | */ |
109 | - public function getReviewIdsByType($reviewType) |
|
109 | + public function getReviewIdsByType( $reviewType ) |
|
110 | 110 | { |
111 | - $results = $this->db->get_col(" |
|
111 | + $results = $this->db->get_col( " |
|
112 | 112 | SELECT DISTINCT m1.meta_value AS review_id |
113 | 113 | FROM {$this->db->posts} AS p |
114 | 114 | INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | AND m1.meta_key = '_review_id' |
118 | 118 | AND m2.meta_key = '_review_type' |
119 | 119 | AND m2.meta_value = '{$reviewType}' |
120 | - "); |
|
121 | - return array_keys(array_flip($results)); |
|
120 | + " ); |
|
121 | + return array_keys( array_flip( $results ) ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | * @param int $limit |
127 | 127 | * @return array |
128 | 128 | */ |
129 | - public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100) |
|
129 | + public function getReviewRatingsFromIds( array $postIds, $greaterThanId = 0, $limit = 100 ) |
|
130 | 130 | { |
131 | - sort($postIds); |
|
132 | - $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit); |
|
133 | - $postIds = implode(',', $postIds); |
|
134 | - return (array) $this->db->get_results(" |
|
131 | + sort( $postIds ); |
|
132 | + $postIds = array_slice( $postIds, intval( array_search( $greaterThanId, $postIds ) ), $limit ); |
|
133 | + $postIds = implode( ',', $postIds ); |
|
134 | + return (array)$this->db->get_results( " |
|
135 | 135 | SELECT p.ID, m.meta_value AS rating |
136 | 136 | FROM {$this->db->posts} AS p |
137 | 137 | INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | GROUP BY p.ID |
144 | 144 | ORDER By p.ID ASC |
145 | 145 | LIMIT {$limit} |
146 | - "); |
|
146 | + " ); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | * @param string $status |
152 | 152 | * @return array |
153 | 153 | */ |
154 | - public function getReviewsMeta($key, $status = 'publish') |
|
154 | + public function getReviewsMeta( $key, $status = 'publish' ) |
|
155 | 155 | { |
156 | 156 | $postStatusQuery = 'all' != $status && !empty($status) |
157 | 157 | ? "AND p.post_status = '{$status}'" |
158 | 158 | : ''; |
159 | - $key = Str::prefix('_', $key); |
|
160 | - $values = $this->db->get_col(" |
|
159 | + $key = Str::prefix( '_', $key ); |
|
160 | + $values = $this->db->get_col( " |
|
161 | 161 | SELECT DISTINCT m.meta_value |
162 | 162 | FROM {$this->db->postmeta} m |
163 | 163 | LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | $postStatusQuery |
168 | 168 | GROUP BY p.ID -- remove duplicate meta_value entries |
169 | 169 | ORDER BY m.meta_id ASC -- sort by oldest meta_value |
170 | - "); |
|
171 | - sort($values); |
|
170 | + " ); |
|
171 | + sort( $values ); |
|
172 | 172 | return $values; |
173 | 173 | } |
174 | 174 | |
@@ -176,34 +176,34 @@ discard block |
||
176 | 176 | * @param string $and |
177 | 177 | * @return string |
178 | 178 | */ |
179 | - protected function getAndForCounts(array $args, $and = '') |
|
179 | + protected function getAndForCounts( array $args, $and = '' ) |
|
180 | 180 | { |
181 | - $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', []))); |
|
182 | - $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', []))); |
|
183 | - if (!empty($args['type'])) { |
|
184 | - $and.= "AND m2.meta_value = '{$args['type']}' "; |
|
181 | + $postIds = implode( ',', array_filter( Arr::get( $args, 'post_ids', [] ) ) ); |
|
182 | + $termIds = implode( ',', array_filter( Arr::get( $args, 'term_ids', [] ) ) ); |
|
183 | + if( !empty($args['type']) ) { |
|
184 | + $and .= "AND m2.meta_value = '{$args['type']}' "; |
|
185 | 185 | } |
186 | - if ($postIds) { |
|
187 | - $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
186 | + if( $postIds ) { |
|
187 | + $and .= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) "; |
|
188 | 188 | } |
189 | - if ($termIds) { |
|
190 | - $and.= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
189 | + if( $termIds ) { |
|
190 | + $and .= "AND tr.term_taxonomy_id IN ({$termIds}) "; |
|
191 | 191 | } |
192 | - return apply_filters('site-reviews/query/and-for-counts', $and); |
|
192 | + return apply_filters( 'site-reviews/query/and-for-counts', $and ); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | 196 | * @param string $innerJoin |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - protected function getInnerJoinForCounts(array $args, $innerJoin = '') |
|
199 | + protected function getInnerJoinForCounts( array $args, $innerJoin = '' ) |
|
200 | 200 | { |
201 | - if (!empty(Arr::get($args, 'post_ids'))) { |
|
202 | - $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
201 | + if( !empty(Arr::get( $args, 'post_ids' )) ) { |
|
202 | + $innerJoin .= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id "; |
|
203 | 203 | } |
204 | - if (!empty(Arr::get($args, 'term_ids'))) { |
|
205 | - $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
204 | + if( !empty(Arr::get( $args, 'term_ids' )) ) { |
|
205 | + $innerJoin .= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id "; |
|
206 | 206 | } |
207 | - return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin); |
|
207 | + return apply_filters( 'site-reviews/query/inner-join-for-counts', $innerJoin ); |
|
208 | 208 | } |
209 | 209 | } |
@@ -9,93 +9,93 @@ |
||
9 | 9 | |
10 | 10 | class TermCountsManager |
11 | 11 | { |
12 | - /** |
|
13 | - * @var CountsManager |
|
14 | - */ |
|
15 | - protected $manager; |
|
12 | + /** |
|
13 | + * @var CountsManager |
|
14 | + */ |
|
15 | + protected $manager; |
|
16 | 16 | |
17 | - public function __construct() |
|
18 | - { |
|
19 | - $this->manager = glsr(CountsManager::class); |
|
20 | - } |
|
17 | + public function __construct() |
|
18 | + { |
|
19 | + $this->manager = glsr(CountsManager::class); |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * @param int $termTaxonomyId |
|
24 | - * @return array |
|
25 | - */ |
|
26 | - public function build($termTaxonomyId) |
|
27 | - { |
|
28 | - return $this->manager->buildCounts([ |
|
29 | - 'term_ids' => [$termTaxonomyId], |
|
30 | - ]); |
|
31 | - } |
|
22 | + /** |
|
23 | + * @param int $termTaxonomyId |
|
24 | + * @return array |
|
25 | + */ |
|
26 | + public function build($termTaxonomyId) |
|
27 | + { |
|
28 | + return $this->manager->buildCounts([ |
|
29 | + 'term_ids' => [$termTaxonomyId], |
|
30 | + ]); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public function decrease(Review $review) |
|
37 | - { |
|
38 | - foreach ($review->term_ids as $termId) { |
|
39 | - if (empty($counts = $this->get($termId))) { |
|
40 | - continue; |
|
41 | - } |
|
42 | - $this->update($termId, |
|
43 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
44 | - ); |
|
45 | - } |
|
46 | - } |
|
33 | + /** |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public function decrease(Review $review) |
|
37 | + { |
|
38 | + foreach ($review->term_ids as $termId) { |
|
39 | + if (empty($counts = $this->get($termId))) { |
|
40 | + continue; |
|
41 | + } |
|
42 | + $this->update($termId, |
|
43 | + $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
44 | + ); |
|
45 | + } |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param int $termId |
|
50 | - * @return array |
|
51 | - */ |
|
52 | - public function get($termId) |
|
53 | - { |
|
54 | - return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true)); |
|
55 | - } |
|
48 | + /** |
|
49 | + * @param int $termId |
|
50 | + * @return array |
|
51 | + */ |
|
52 | + public function get($termId) |
|
53 | + { |
|
54 | + return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true)); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function increase(Review $review) |
|
61 | - { |
|
62 | - $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
63 | - foreach ($terms as $term) { |
|
64 | - $counts = $this->get($term['term_id']); |
|
65 | - $counts = empty($counts) |
|
66 | - ? $this->build($term['term_taxonomy_id']) |
|
67 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
68 | - $this->update($term['term_id'], $counts); |
|
69 | - } |
|
70 | - } |
|
57 | + /** |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function increase(Review $review) |
|
61 | + { |
|
62 | + $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
63 | + foreach ($terms as $term) { |
|
64 | + $counts = $this->get($term['term_id']); |
|
65 | + $counts = empty($counts) |
|
66 | + ? $this->build($term['term_taxonomy_id']) |
|
67 | + : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
68 | + $this->update($term['term_id'], $counts); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @param int $termId |
|
74 | - * @return void |
|
75 | - */ |
|
76 | - public function update($termId, array $reviewCounts) |
|
77 | - { |
|
78 | - $term = get_term($termId, Application::TAXONOMY); |
|
79 | - if (!isset($term->term_id)) { |
|
80 | - return; |
|
81 | - } |
|
82 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
83 | - update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts); |
|
84 | - update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
85 | - update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
86 | - } |
|
72 | + /** |
|
73 | + * @param int $termId |
|
74 | + * @return void |
|
75 | + */ |
|
76 | + public function update($termId, array $reviewCounts) |
|
77 | + { |
|
78 | + $term = get_term($termId, Application::TAXONOMY); |
|
79 | + if (!isset($term->term_id)) { |
|
80 | + return; |
|
81 | + } |
|
82 | + $ratingCounts = $this->manager->flatten($reviewCounts); |
|
83 | + update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts); |
|
84 | + update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
85 | + update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - public function updateAll() |
|
92 | - { |
|
93 | - glsr(SqlQueries::class)->deleteTermCountMetaKeys(); |
|
94 | - $terms = glsr(Database::class)->getTerms([ |
|
95 | - 'fields' => 'all', |
|
96 | - ]); |
|
97 | - foreach ($terms as $term) { |
|
98 | - $this->update($term->term_id, $this->build($term->term_taxonomy_id)); |
|
99 | - } |
|
100 | - } |
|
88 | + /** |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + public function updateAll() |
|
92 | + { |
|
93 | + glsr(SqlQueries::class)->deleteTermCountMetaKeys(); |
|
94 | + $terms = glsr(Database::class)->getTerms([ |
|
95 | + 'fields' => 'all', |
|
96 | + ]); |
|
97 | + foreach ($terms as $term) { |
|
98 | + $this->update($term->term_id, $this->build($term->term_taxonomy_id)); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | } |
@@ -16,31 +16,31 @@ discard block |
||
16 | 16 | |
17 | 17 | public function __construct() |
18 | 18 | { |
19 | - $this->manager = glsr(CountsManager::class); |
|
19 | + $this->manager = glsr( CountsManager::class ); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @param int $termTaxonomyId |
24 | 24 | * @return array |
25 | 25 | */ |
26 | - public function build($termTaxonomyId) |
|
26 | + public function build( $termTaxonomyId ) |
|
27 | 27 | { |
28 | - return $this->manager->buildCounts([ |
|
28 | + return $this->manager->buildCounts( [ |
|
29 | 29 | 'term_ids' => [$termTaxonomyId], |
30 | - ]); |
|
30 | + ] ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @return void |
35 | 35 | */ |
36 | - public function decrease(Review $review) |
|
36 | + public function decrease( Review $review ) |
|
37 | 37 | { |
38 | - foreach ($review->term_ids as $termId) { |
|
39 | - if (empty($counts = $this->get($termId))) { |
|
38 | + foreach( $review->term_ids as $termId ) { |
|
39 | + if( empty($counts = $this->get( $termId )) ) { |
|
40 | 40 | continue; |
41 | 41 | } |
42 | - $this->update($termId, |
|
43 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
42 | + $this->update( $termId, |
|
43 | + $this->manager->decreaseRating( $counts, $review->review_type, $review->rating ) |
|
44 | 44 | ); |
45 | 45 | } |
46 | 46 | } |
@@ -49,23 +49,23 @@ discard block |
||
49 | 49 | * @param int $termId |
50 | 50 | * @return array |
51 | 51 | */ |
52 | - public function get($termId) |
|
52 | + public function get( $termId ) |
|
53 | 53 | { |
54 | - return array_filter((array) get_term_meta($termId, CountsManager::META_COUNT, true)); |
|
54 | + return array_filter( (array)get_term_meta( $termId, CountsManager::META_COUNT, true ) ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * @return void |
59 | 59 | */ |
60 | - public function increase(Review $review) |
|
60 | + public function increase( Review $review ) |
|
61 | 61 | { |
62 | - $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids)); |
|
63 | - foreach ($terms as $term) { |
|
64 | - $counts = $this->get($term['term_id']); |
|
62 | + $terms = glsr( ReviewManager::class )->normalizeTerms( implode( ',', $review->term_ids ) ); |
|
63 | + foreach( $terms as $term ) { |
|
64 | + $counts = $this->get( $term['term_id'] ); |
|
65 | 65 | $counts = empty($counts) |
66 | - ? $this->build($term['term_taxonomy_id']) |
|
67 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
68 | - $this->update($term['term_id'], $counts); |
|
66 | + ? $this->build( $term['term_taxonomy_id'] ) |
|
67 | + : $this->manager->increaseRating( $counts, $review->review_type, $review->rating ); |
|
68 | + $this->update( $term['term_id'], $counts ); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
@@ -73,16 +73,16 @@ discard block |
||
73 | 73 | * @param int $termId |
74 | 74 | * @return void |
75 | 75 | */ |
76 | - public function update($termId, array $reviewCounts) |
|
76 | + public function update( $termId, array $reviewCounts ) |
|
77 | 77 | { |
78 | - $term = get_term($termId, Application::TAXONOMY); |
|
79 | - if (!isset($term->term_id)) { |
|
78 | + $term = get_term( $termId, Application::TAXONOMY ); |
|
79 | + if( !isset($term->term_id) ) { |
|
80 | 80 | return; |
81 | 81 | } |
82 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
83 | - update_term_meta($termId, CountsManager::META_COUNT, $reviewCounts); |
|
84 | - update_term_meta($termId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
85 | - update_term_meta($termId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
82 | + $ratingCounts = $this->manager->flatten( $reviewCounts ); |
|
83 | + update_term_meta( $termId, CountsManager::META_COUNT, $reviewCounts ); |
|
84 | + update_term_meta( $termId, CountsManager::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
85 | + update_term_meta( $termId, CountsManager::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function updateAll() |
92 | 92 | { |
93 | - glsr(SqlQueries::class)->deleteTermCountMetaKeys(); |
|
94 | - $terms = glsr(Database::class)->getTerms([ |
|
93 | + glsr( SqlQueries::class )->deleteTermCountMetaKeys(); |
|
94 | + $terms = glsr( Database::class )->getTerms( [ |
|
95 | 95 | 'fields' => 'all', |
96 | - ]); |
|
97 | - foreach ($terms as $term) { |
|
98 | - $this->update($term->term_id, $this->build($term->term_taxonomy_id)); |
|
96 | + ] ); |
|
97 | + foreach( $terms as $term ) { |
|
98 | + $this->update( $term->term_id, $this->build( $term->term_taxonomy_id ) ); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
@@ -7,85 +7,85 @@ |
||
7 | 7 | |
8 | 8 | class PostCountsManager |
9 | 9 | { |
10 | - /** |
|
11 | - * @var CountsManager |
|
12 | - */ |
|
13 | - protected $manager; |
|
10 | + /** |
|
11 | + * @var CountsManager |
|
12 | + */ |
|
13 | + protected $manager; |
|
14 | 14 | |
15 | - public function __construct() |
|
16 | - { |
|
17 | - $this->manager = glsr(CountsManager::class); |
|
18 | - } |
|
15 | + public function __construct() |
|
16 | + { |
|
17 | + $this->manager = glsr(CountsManager::class); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param int $postId |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function build($postId) |
|
25 | - { |
|
26 | - return $this->manager->buildCounts([ |
|
27 | - 'post_ids' => [$postId], |
|
28 | - ]); |
|
29 | - } |
|
20 | + /** |
|
21 | + * @param int $postId |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function build($postId) |
|
25 | + { |
|
26 | + return $this->manager->buildCounts([ |
|
27 | + 'post_ids' => [$postId], |
|
28 | + ]); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function decrease(Review $review) |
|
35 | - { |
|
36 | - if (empty($counts = $this->get($review->assigned_to))) { |
|
37 | - return; |
|
38 | - } |
|
39 | - $this->update($review->assigned_to, |
|
40 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
41 | - ); |
|
42 | - } |
|
31 | + /** |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function decrease(Review $review) |
|
35 | + { |
|
36 | + if (empty($counts = $this->get($review->assigned_to))) { |
|
37 | + return; |
|
38 | + } |
|
39 | + $this->update($review->assigned_to, |
|
40 | + $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
41 | + ); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int $postId |
|
46 | - * @return array |
|
47 | - */ |
|
48 | - public function get($postId) |
|
49 | - { |
|
50 | - return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true)); |
|
51 | - } |
|
44 | + /** |
|
45 | + * @param int $postId |
|
46 | + * @return array |
|
47 | + */ |
|
48 | + public function get($postId) |
|
49 | + { |
|
50 | + return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true)); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function increase(Review $review) |
|
57 | - { |
|
58 | - if (!(get_post($review->assigned_to) instanceof \WP_Post)) { |
|
59 | - return; |
|
60 | - } |
|
61 | - $counts = $this->get($review->assigned_to); |
|
62 | - $counts = empty($counts) |
|
63 | - ? $this->build($review->assigned_to) |
|
64 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
65 | - $this->update($review->assigned_to, $counts); |
|
66 | - } |
|
53 | + /** |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function increase(Review $review) |
|
57 | + { |
|
58 | + if (!(get_post($review->assigned_to) instanceof \WP_Post)) { |
|
59 | + return; |
|
60 | + } |
|
61 | + $counts = $this->get($review->assigned_to); |
|
62 | + $counts = empty($counts) |
|
63 | + ? $this->build($review->assigned_to) |
|
64 | + : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
65 | + $this->update($review->assigned_to, $counts); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param int $postId |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function update($postId, array $reviewCounts) |
|
73 | - { |
|
74 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
75 | - update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts); |
|
76 | - update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
77 | - update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
78 | - } |
|
68 | + /** |
|
69 | + * @param int $postId |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function update($postId, array $reviewCounts) |
|
73 | + { |
|
74 | + $ratingCounts = $this->manager->flatten($reviewCounts); |
|
75 | + update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts); |
|
76 | + update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
77 | + update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function updateAll() |
|
84 | - { |
|
85 | - glsr(SqlQueries::class)->deletePostCountMetaKeys(); |
|
86 | - $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
87 | - foreach ($postIds as $postId) { |
|
88 | - $this->update($postId, $this->build($postId)); |
|
89 | - } |
|
90 | - } |
|
80 | + /** |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function updateAll() |
|
84 | + { |
|
85 | + glsr(SqlQueries::class)->deletePostCountMetaKeys(); |
|
86 | + $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
87 | + foreach ($postIds as $postId) { |
|
88 | + $this->update($postId, $this->build($postId)); |
|
89 | + } |
|
90 | + } |
|
91 | 91 | } |
@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | |
15 | 15 | public function __construct() |
16 | 16 | { |
17 | - $this->manager = glsr(CountsManager::class); |
|
17 | + $this->manager = glsr( CountsManager::class ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param int $postId |
22 | 22 | * @return array |
23 | 23 | */ |
24 | - public function build($postId) |
|
24 | + public function build( $postId ) |
|
25 | 25 | { |
26 | - return $this->manager->buildCounts([ |
|
26 | + return $this->manager->buildCounts( [ |
|
27 | 27 | 'post_ids' => [$postId], |
28 | - ]); |
|
28 | + ] ); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @return void |
33 | 33 | */ |
34 | - public function decrease(Review $review) |
|
34 | + public function decrease( Review $review ) |
|
35 | 35 | { |
36 | - if (empty($counts = $this->get($review->assigned_to))) { |
|
36 | + if( empty($counts = $this->get( $review->assigned_to )) ) { |
|
37 | 37 | return; |
38 | 38 | } |
39 | - $this->update($review->assigned_to, |
|
40 | - $this->manager->decreaseRating($counts, $review->review_type, $review->rating) |
|
39 | + $this->update( $review->assigned_to, |
|
40 | + $this->manager->decreaseRating( $counts, $review->review_type, $review->rating ) |
|
41 | 41 | ); |
42 | 42 | } |
43 | 43 | |
@@ -45,36 +45,36 @@ discard block |
||
45 | 45 | * @param int $postId |
46 | 46 | * @return array |
47 | 47 | */ |
48 | - public function get($postId) |
|
48 | + public function get( $postId ) |
|
49 | 49 | { |
50 | - return array_filter((array) get_post_meta($postId, CountsManager::META_COUNT, true)); |
|
50 | + return array_filter( (array)get_post_meta( $postId, CountsManager::META_COUNT, true ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @return void |
55 | 55 | */ |
56 | - public function increase(Review $review) |
|
56 | + public function increase( Review $review ) |
|
57 | 57 | { |
58 | - if (!(get_post($review->assigned_to) instanceof \WP_Post)) { |
|
58 | + if( !(get_post( $review->assigned_to ) instanceof \WP_Post) ) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | - $counts = $this->get($review->assigned_to); |
|
61 | + $counts = $this->get( $review->assigned_to ); |
|
62 | 62 | $counts = empty($counts) |
63 | - ? $this->build($review->assigned_to) |
|
64 | - : $this->manager->increaseRating($counts, $review->review_type, $review->rating); |
|
65 | - $this->update($review->assigned_to, $counts); |
|
63 | + ? $this->build( $review->assigned_to ) |
|
64 | + : $this->manager->increaseRating( $counts, $review->review_type, $review->rating ); |
|
65 | + $this->update( $review->assigned_to, $counts ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
69 | 69 | * @param int $postId |
70 | 70 | * @return void |
71 | 71 | */ |
72 | - public function update($postId, array $reviewCounts) |
|
72 | + public function update( $postId, array $reviewCounts ) |
|
73 | 73 | { |
74 | - $ratingCounts = $this->manager->flatten($reviewCounts); |
|
75 | - update_post_meta($postId, CountsManager::META_COUNT, $reviewCounts); |
|
76 | - update_post_meta($postId, CountsManager::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts)); |
|
77 | - update_post_meta($postId, CountsManager::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts)); |
|
74 | + $ratingCounts = $this->manager->flatten( $reviewCounts ); |
|
75 | + update_post_meta( $postId, CountsManager::META_COUNT, $reviewCounts ); |
|
76 | + update_post_meta( $postId, CountsManager::META_AVERAGE, glsr( Rating::class )->getAverage( $ratingCounts ) ); |
|
77 | + update_post_meta( $postId, CountsManager::META_RANKING, glsr( Rating::class )->getRanking( $ratingCounts ) ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function updateAll() |
84 | 84 | { |
85 | - glsr(SqlQueries::class)->deletePostCountMetaKeys(); |
|
86 | - $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to'); |
|
87 | - foreach ($postIds as $postId) { |
|
88 | - $this->update($postId, $this->build($postId)); |
|
85 | + glsr( SqlQueries::class )->deletePostCountMetaKeys(); |
|
86 | + $postIds = glsr( SqlQueries::class )->getReviewsMeta( 'assigned_to' ); |
|
87 | + foreach( $postIds as $postId ) { |
|
88 | + $this->update( $postId, $this->build( $postId ) ); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -4,15 +4,15 @@ |
||
4 | 4 | |
5 | 5 | class SiteReviewsFormShortcode extends Shortcode |
6 | 6 | { |
7 | - protected function hideOptions() |
|
8 | - { |
|
9 | - return [ |
|
10 | - 'rating' => __('Hide the rating field', 'site-reviews'), |
|
11 | - 'title' => __('Hide the title field', 'site-reviews'), |
|
12 | - 'content' => __('Hide the review field', 'site-reviews'), |
|
13 | - 'name' => __('Hide the name field', 'site-reviews'), |
|
14 | - 'email' => __('Hide the email field', 'site-reviews'), |
|
15 | - 'terms' => __('Hide the terms field', 'site-reviews'), |
|
16 | - ]; |
|
17 | - } |
|
7 | + protected function hideOptions() |
|
8 | + { |
|
9 | + return [ |
|
10 | + 'rating' => __('Hide the rating field', 'site-reviews'), |
|
11 | + 'title' => __('Hide the title field', 'site-reviews'), |
|
12 | + 'content' => __('Hide the review field', 'site-reviews'), |
|
13 | + 'name' => __('Hide the name field', 'site-reviews'), |
|
14 | + 'email' => __('Hide the email field', 'site-reviews'), |
|
15 | + 'terms' => __('Hide the terms field', 'site-reviews'), |
|
16 | + ]; |
|
17 | + } |
|
18 | 18 | } |
@@ -7,12 +7,12 @@ |
||
7 | 7 | protected function hideOptions() |
8 | 8 | { |
9 | 9 | return [ |
10 | - 'rating' => __('Hide the rating field', 'site-reviews'), |
|
11 | - 'title' => __('Hide the title field', 'site-reviews'), |
|
12 | - 'content' => __('Hide the review field', 'site-reviews'), |
|
13 | - 'name' => __('Hide the name field', 'site-reviews'), |
|
14 | - 'email' => __('Hide the email field', 'site-reviews'), |
|
15 | - 'terms' => __('Hide the terms field', 'site-reviews'), |
|
10 | + 'rating' => __( 'Hide the rating field', 'site-reviews' ), |
|
11 | + 'title' => __( 'Hide the title field', 'site-reviews' ), |
|
12 | + 'content' => __( 'Hide the review field', 'site-reviews' ), |
|
13 | + 'name' => __( 'Hide the name field', 'site-reviews' ), |
|
14 | + 'email' => __( 'Hide the email field', 'site-reviews' ), |
|
15 | + 'terms' => __( 'Hide the terms field', 'site-reviews' ), |
|
16 | 16 | ]; |
17 | 17 | } |
18 | 18 | } |
@@ -10,197 +10,197 @@ |
||
10 | 10 | |
11 | 11 | class SiteReviewsSummary |
12 | 12 | { |
13 | - /** |
|
14 | - * @var array |
|
15 | - */ |
|
16 | - protected $args; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var float |
|
20 | - */ |
|
21 | - protected $averageRating; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected $ratingCounts; |
|
27 | - |
|
28 | - /** |
|
29 | - * @return void|string |
|
30 | - */ |
|
31 | - public function build(array $args = []) |
|
32 | - { |
|
33 | - $this->args = $args; |
|
34 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args); |
|
35 | - if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) { |
|
36 | - return; |
|
37 | - } |
|
38 | - $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts); |
|
39 | - $this->generateSchema(); |
|
40 | - return glsr(Template::class)->build('templates/reviews-summary', [ |
|
41 | - 'context' => [ |
|
42 | - 'assigned_to' => $this->args['assigned_to'], |
|
43 | - 'category' => $this->args['category'], |
|
44 | - 'class' => $this->getClass(), |
|
45 | - 'id' => $this->args['id'], |
|
46 | - 'percentages' => $this->buildPercentage(), |
|
47 | - 'rating' => $this->buildRating(), |
|
48 | - 'stars' => $this->buildStars(), |
|
49 | - 'text' => $this->buildText(), |
|
50 | - ], |
|
51 | - ]); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @return void|string |
|
56 | - */ |
|
57 | - protected function buildPercentage() |
|
58 | - { |
|
59 | - if ($this->isHidden('bars')) { |
|
60 | - return; |
|
61 | - } |
|
62 | - $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts)); |
|
63 | - $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) { |
|
64 | - $label = $this->buildPercentageLabel($this->args['labels'][$level]); |
|
65 | - $background = $this->buildPercentageBackground($percentages[$level]); |
|
66 | - $count = apply_filters('site-reviews/summary/counts', |
|
67 | - $percentages[$level], |
|
68 | - $this->ratingCounts[$level] |
|
69 | - ); |
|
70 | - $percent = $this->buildPercentageCount($count); |
|
71 | - $value = $label.$background.$percent; |
|
72 | - $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [ |
|
73 | - 'percent' => wp_strip_all_tags($count, true), |
|
74 | - 'rating' => $level, |
|
75 | - ]); |
|
76 | - return $carry.glsr(Builder::class)->div($value, [ |
|
77 | - 'class' => 'glsr-bar', |
|
78 | - ]); |
|
79 | - }); |
|
80 | - return $this->wrap('percentage', $bars); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @param string $percent |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - protected function buildPercentageBackground($percent) |
|
88 | - { |
|
89 | - $backgroundPercent = glsr(Builder::class)->span([ |
|
90 | - 'class' => 'glsr-bar-background-percent', |
|
91 | - 'style' => 'width:'.$percent, |
|
92 | - ]); |
|
93 | - return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param string $count |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - protected function buildPercentageCount($count) |
|
101 | - { |
|
102 | - return '<span class="glsr-bar-percent">'.$count.'</span>'; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $label |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - protected function buildPercentageLabel($label) |
|
110 | - { |
|
111 | - return '<span class="glsr-bar-label">'.$label.'</span>'; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @return void|string |
|
116 | - */ |
|
117 | - protected function buildRating() |
|
118 | - { |
|
119 | - if ($this->isHidden('rating')) { |
|
120 | - return; |
|
121 | - } |
|
122 | - return $this->wrap('rating', '<span>'.$this->averageRating.'</span>'); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return void|string |
|
127 | - */ |
|
128 | - protected function buildStars() |
|
129 | - { |
|
130 | - if ($this->isHidden('stars')) { |
|
131 | - return; |
|
132 | - } |
|
133 | - $stars = glsr_star_rating($this->averageRating); |
|
134 | - return $this->wrap('stars', $stars); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return void|string |
|
139 | - */ |
|
140 | - protected function buildText() |
|
141 | - { |
|
142 | - if ($this->isHidden('summary')) { |
|
143 | - return; |
|
144 | - } |
|
145 | - $count = intval(array_sum($this->ratingCounts)); |
|
146 | - if (empty($this->args['text'])) { |
|
147 | - // @todo document this change |
|
148 | - $this->args['text'] = _nx( |
|
149 | - '{rating} out of {max} stars (based on {num} review)', |
|
150 | - '{rating} out of {max} stars (based on {num} reviews)', |
|
151 | - $count, |
|
152 | - 'Do not translate {rating}, {max}, and {num}, they are template tags.', |
|
153 | - 'site-reviews' |
|
154 | - ); |
|
155 | - } |
|
156 | - $summary = str_replace( |
|
157 | - ['{rating}', '{max}', '{num}'], |
|
158 | - [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count], |
|
159 | - $this->args['text'] |
|
160 | - ); |
|
161 | - return $this->wrap('text', '<span>'.$summary.'</span>'); |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - protected function generateSchema() |
|
168 | - { |
|
169 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
170 | - return; |
|
171 | - } |
|
172 | - glsr(Schema::class)->store( |
|
173 | - glsr(Schema::class)->buildSummary($this->args) |
|
174 | - ); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - protected function getClass() |
|
181 | - { |
|
182 | - return trim('glsr-summary glsr-default '.$this->args['class']); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $key |
|
187 | - * @return bool |
|
188 | - */ |
|
189 | - protected function isHidden($key) |
|
190 | - { |
|
191 | - return in_array($key, $this->args['hide']); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @param string $key |
|
196 | - * @param string $value |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - protected function wrap($key, $value) |
|
200 | - { |
|
201 | - $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args); |
|
202 | - return glsr(Builder::class)->div($value, [ |
|
203 | - 'class' => 'glsr-summary-'.$key, |
|
204 | - ]); |
|
205 | - } |
|
13 | + /** |
|
14 | + * @var array |
|
15 | + */ |
|
16 | + protected $args; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var float |
|
20 | + */ |
|
21 | + protected $averageRating; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected $ratingCounts; |
|
27 | + |
|
28 | + /** |
|
29 | + * @return void|string |
|
30 | + */ |
|
31 | + public function build(array $args = []) |
|
32 | + { |
|
33 | + $this->args = $args; |
|
34 | + $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args); |
|
35 | + if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) { |
|
36 | + return; |
|
37 | + } |
|
38 | + $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts); |
|
39 | + $this->generateSchema(); |
|
40 | + return glsr(Template::class)->build('templates/reviews-summary', [ |
|
41 | + 'context' => [ |
|
42 | + 'assigned_to' => $this->args['assigned_to'], |
|
43 | + 'category' => $this->args['category'], |
|
44 | + 'class' => $this->getClass(), |
|
45 | + 'id' => $this->args['id'], |
|
46 | + 'percentages' => $this->buildPercentage(), |
|
47 | + 'rating' => $this->buildRating(), |
|
48 | + 'stars' => $this->buildStars(), |
|
49 | + 'text' => $this->buildText(), |
|
50 | + ], |
|
51 | + ]); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @return void|string |
|
56 | + */ |
|
57 | + protected function buildPercentage() |
|
58 | + { |
|
59 | + if ($this->isHidden('bars')) { |
|
60 | + return; |
|
61 | + } |
|
62 | + $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts)); |
|
63 | + $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) { |
|
64 | + $label = $this->buildPercentageLabel($this->args['labels'][$level]); |
|
65 | + $background = $this->buildPercentageBackground($percentages[$level]); |
|
66 | + $count = apply_filters('site-reviews/summary/counts', |
|
67 | + $percentages[$level], |
|
68 | + $this->ratingCounts[$level] |
|
69 | + ); |
|
70 | + $percent = $this->buildPercentageCount($count); |
|
71 | + $value = $label.$background.$percent; |
|
72 | + $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [ |
|
73 | + 'percent' => wp_strip_all_tags($count, true), |
|
74 | + 'rating' => $level, |
|
75 | + ]); |
|
76 | + return $carry.glsr(Builder::class)->div($value, [ |
|
77 | + 'class' => 'glsr-bar', |
|
78 | + ]); |
|
79 | + }); |
|
80 | + return $this->wrap('percentage', $bars); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @param string $percent |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + protected function buildPercentageBackground($percent) |
|
88 | + { |
|
89 | + $backgroundPercent = glsr(Builder::class)->span([ |
|
90 | + 'class' => 'glsr-bar-background-percent', |
|
91 | + 'style' => 'width:'.$percent, |
|
92 | + ]); |
|
93 | + return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param string $count |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + protected function buildPercentageCount($count) |
|
101 | + { |
|
102 | + return '<span class="glsr-bar-percent">'.$count.'</span>'; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $label |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + protected function buildPercentageLabel($label) |
|
110 | + { |
|
111 | + return '<span class="glsr-bar-label">'.$label.'</span>'; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @return void|string |
|
116 | + */ |
|
117 | + protected function buildRating() |
|
118 | + { |
|
119 | + if ($this->isHidden('rating')) { |
|
120 | + return; |
|
121 | + } |
|
122 | + return $this->wrap('rating', '<span>'.$this->averageRating.'</span>'); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return void|string |
|
127 | + */ |
|
128 | + protected function buildStars() |
|
129 | + { |
|
130 | + if ($this->isHidden('stars')) { |
|
131 | + return; |
|
132 | + } |
|
133 | + $stars = glsr_star_rating($this->averageRating); |
|
134 | + return $this->wrap('stars', $stars); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return void|string |
|
139 | + */ |
|
140 | + protected function buildText() |
|
141 | + { |
|
142 | + if ($this->isHidden('summary')) { |
|
143 | + return; |
|
144 | + } |
|
145 | + $count = intval(array_sum($this->ratingCounts)); |
|
146 | + if (empty($this->args['text'])) { |
|
147 | + // @todo document this change |
|
148 | + $this->args['text'] = _nx( |
|
149 | + '{rating} out of {max} stars (based on {num} review)', |
|
150 | + '{rating} out of {max} stars (based on {num} reviews)', |
|
151 | + $count, |
|
152 | + 'Do not translate {rating}, {max}, and {num}, they are template tags.', |
|
153 | + 'site-reviews' |
|
154 | + ); |
|
155 | + } |
|
156 | + $summary = str_replace( |
|
157 | + ['{rating}', '{max}', '{num}'], |
|
158 | + [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count], |
|
159 | + $this->args['text'] |
|
160 | + ); |
|
161 | + return $this->wrap('text', '<span>'.$summary.'</span>'); |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + protected function generateSchema() |
|
168 | + { |
|
169 | + if (!wp_validate_boolean($this->args['schema'])) { |
|
170 | + return; |
|
171 | + } |
|
172 | + glsr(Schema::class)->store( |
|
173 | + glsr(Schema::class)->buildSummary($this->args) |
|
174 | + ); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + protected function getClass() |
|
181 | + { |
|
182 | + return trim('glsr-summary glsr-default '.$this->args['class']); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $key |
|
187 | + * @return bool |
|
188 | + */ |
|
189 | + protected function isHidden($key) |
|
190 | + { |
|
191 | + return in_array($key, $this->args['hide']); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @param string $key |
|
196 | + * @param string $value |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + protected function wrap($key, $value) |
|
200 | + { |
|
201 | + $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args); |
|
202 | + return glsr(Builder::class)->div($value, [ |
|
203 | + 'class' => 'glsr-summary-'.$key, |
|
204 | + ]); |
|
205 | + } |
|
206 | 206 | } |
@@ -28,16 +28,16 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * @return void|string |
30 | 30 | */ |
31 | - public function build(array $args = []) |
|
31 | + public function build( array $args = [] ) |
|
32 | 32 | { |
33 | 33 | $this->args = $args; |
34 | - $this->ratingCounts = glsr(ReviewManager::class)->getRatingCounts($args); |
|
35 | - if (!array_sum($this->ratingCounts) && $this->isHidden('if_empty')) { |
|
34 | + $this->ratingCounts = glsr( ReviewManager::class )->getRatingCounts( $args ); |
|
35 | + if( !array_sum( $this->ratingCounts ) && $this->isHidden( 'if_empty' ) ) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | - $this->averageRating = glsr(Rating::class)->getAverage($this->ratingCounts); |
|
38 | + $this->averageRating = glsr( Rating::class )->getAverage( $this->ratingCounts ); |
|
39 | 39 | $this->generateSchema(); |
40 | - return glsr(Template::class)->build('templates/reviews-summary', [ |
|
40 | + return glsr( Template::class )->build( 'templates/reviews-summary', [ |
|
41 | 41 | 'context' => [ |
42 | 42 | 'assigned_to' => $this->args['assigned_to'], |
43 | 43 | 'category' => $this->args['category'], |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | 'stars' => $this->buildStars(), |
49 | 49 | 'text' => $this->buildText(), |
50 | 50 | ], |
51 | - ]); |
|
51 | + ] ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -56,40 +56,40 @@ discard block |
||
56 | 56 | */ |
57 | 57 | protected function buildPercentage() |
58 | 58 | { |
59 | - if ($this->isHidden('bars')) { |
|
59 | + if( $this->isHidden( 'bars' ) ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | - $percentages = preg_filter('/$/', '%', glsr(Rating::class)->getPercentages($this->ratingCounts)); |
|
63 | - $bars = array_reduce(range(glsr()->constant('MAX_RATING', Rating::class), 1), function ($carry, $level) use ($percentages) { |
|
64 | - $label = $this->buildPercentageLabel($this->args['labels'][$level]); |
|
65 | - $background = $this->buildPercentageBackground($percentages[$level]); |
|
66 | - $count = apply_filters('site-reviews/summary/counts', |
|
62 | + $percentages = preg_filter( '/$/', '%', glsr( Rating::class )->getPercentages( $this->ratingCounts ) ); |
|
63 | + $bars = array_reduce( range( glsr()->constant( 'MAX_RATING', Rating::class ), 1 ), function( $carry, $level ) use ($percentages) { |
|
64 | + $label = $this->buildPercentageLabel( $this->args['labels'][$level] ); |
|
65 | + $background = $this->buildPercentageBackground( $percentages[$level] ); |
|
66 | + $count = apply_filters( 'site-reviews/summary/counts', |
|
67 | 67 | $percentages[$level], |
68 | 68 | $this->ratingCounts[$level] |
69 | 69 | ); |
70 | - $percent = $this->buildPercentageCount($count); |
|
70 | + $percent = $this->buildPercentageCount( $count ); |
|
71 | 71 | $value = $label.$background.$percent; |
72 | - $value = apply_filters('site-reviews/summary/wrap/bar', $value, $this->args, [ |
|
73 | - 'percent' => wp_strip_all_tags($count, true), |
|
72 | + $value = apply_filters( 'site-reviews/summary/wrap/bar', $value, $this->args, [ |
|
73 | + 'percent' => wp_strip_all_tags( $count, true ), |
|
74 | 74 | 'rating' => $level, |
75 | - ]); |
|
76 | - return $carry.glsr(Builder::class)->div($value, [ |
|
75 | + ] ); |
|
76 | + return $carry.glsr( Builder::class )->div( $value, [ |
|
77 | 77 | 'class' => 'glsr-bar', |
78 | - ]); |
|
78 | + ] ); |
|
79 | 79 | }); |
80 | - return $this->wrap('percentage', $bars); |
|
80 | + return $this->wrap( 'percentage', $bars ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
84 | 84 | * @param string $percent |
85 | 85 | * @return string |
86 | 86 | */ |
87 | - protected function buildPercentageBackground($percent) |
|
87 | + protected function buildPercentageBackground( $percent ) |
|
88 | 88 | { |
89 | - $backgroundPercent = glsr(Builder::class)->span([ |
|
89 | + $backgroundPercent = glsr( Builder::class )->span( [ |
|
90 | 90 | 'class' => 'glsr-bar-background-percent', |
91 | 91 | 'style' => 'width:'.$percent, |
92 | - ]); |
|
92 | + ] ); |
|
93 | 93 | return '<span class="glsr-bar-background">'.$backgroundPercent.'</span>'; |
94 | 94 | } |
95 | 95 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param string $count |
98 | 98 | * @return string |
99 | 99 | */ |
100 | - protected function buildPercentageCount($count) |
|
100 | + protected function buildPercentageCount( $count ) |
|
101 | 101 | { |
102 | 102 | return '<span class="glsr-bar-percent">'.$count.'</span>'; |
103 | 103 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * @param string $label |
107 | 107 | * @return string |
108 | 108 | */ |
109 | - protected function buildPercentageLabel($label) |
|
109 | + protected function buildPercentageLabel( $label ) |
|
110 | 110 | { |
111 | 111 | return '<span class="glsr-bar-label">'.$label.'</span>'; |
112 | 112 | } |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | */ |
117 | 117 | protected function buildRating() |
118 | 118 | { |
119 | - if ($this->isHidden('rating')) { |
|
119 | + if( $this->isHidden( 'rating' ) ) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | - return $this->wrap('rating', '<span>'.$this->averageRating.'</span>'); |
|
122 | + return $this->wrap( 'rating', '<span>'.$this->averageRating.'</span>' ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function buildStars() |
129 | 129 | { |
130 | - if ($this->isHidden('stars')) { |
|
130 | + if( $this->isHidden( 'stars' ) ) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | - $stars = glsr_star_rating($this->averageRating); |
|
134 | - return $this->wrap('stars', $stars); |
|
133 | + $stars = glsr_star_rating( $this->averageRating ); |
|
134 | + return $this->wrap( 'stars', $stars ); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,11 +139,11 @@ discard block |
||
139 | 139 | */ |
140 | 140 | protected function buildText() |
141 | 141 | { |
142 | - if ($this->isHidden('summary')) { |
|
142 | + if( $this->isHidden( 'summary' ) ) { |
|
143 | 143 | return; |
144 | 144 | } |
145 | - $count = intval(array_sum($this->ratingCounts)); |
|
146 | - if (empty($this->args['text'])) { |
|
145 | + $count = intval( array_sum( $this->ratingCounts ) ); |
|
146 | + if( empty($this->args['text']) ) { |
|
147 | 147 | // @todo document this change |
148 | 148 | $this->args['text'] = _nx( |
149 | 149 | '{rating} out of {max} stars (based on {num} review)', |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | } |
156 | 156 | $summary = str_replace( |
157 | 157 | ['{rating}', '{max}', '{num}'], |
158 | - [$this->averageRating, glsr()->constant('MAX_RATING', Rating::class), $count], |
|
158 | + [$this->averageRating, glsr()->constant( 'MAX_RATING', Rating::class ), $count], |
|
159 | 159 | $this->args['text'] |
160 | 160 | ); |
161 | - return $this->wrap('text', '<span>'.$summary.'</span>'); |
|
161 | + return $this->wrap( 'text', '<span>'.$summary.'</span>' ); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | */ |
167 | 167 | protected function generateSchema() |
168 | 168 | { |
169 | - if (!wp_validate_boolean($this->args['schema'])) { |
|
169 | + if( !wp_validate_boolean( $this->args['schema'] ) ) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | - glsr(Schema::class)->store( |
|
173 | - glsr(Schema::class)->buildSummary($this->args) |
|
172 | + glsr( Schema::class )->store( |
|
173 | + glsr( Schema::class )->buildSummary( $this->args ) |
|
174 | 174 | ); |
175 | 175 | } |
176 | 176 | |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | */ |
180 | 180 | protected function getClass() |
181 | 181 | { |
182 | - return trim('glsr-summary glsr-default '.$this->args['class']); |
|
182 | + return trim( 'glsr-summary glsr-default '.$this->args['class'] ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
186 | 186 | * @param string $key |
187 | 187 | * @return bool |
188 | 188 | */ |
189 | - protected function isHidden($key) |
|
189 | + protected function isHidden( $key ) |
|
190 | 190 | { |
191 | - return in_array($key, $this->args['hide']); |
|
191 | + return in_array( $key, $this->args['hide'] ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -196,11 +196,11 @@ discard block |
||
196 | 196 | * @param string $value |
197 | 197 | * @return string |
198 | 198 | */ |
199 | - protected function wrap($key, $value) |
|
199 | + protected function wrap( $key, $value ) |
|
200 | 200 | { |
201 | - $value = apply_filters('site-reviews/summary/wrap/'.$key, $value, $this->args); |
|
202 | - return glsr(Builder::class)->div($value, [ |
|
201 | + $value = apply_filters( 'site-reviews/summary/wrap/'.$key, $value, $this->args ); |
|
202 | + return glsr( Builder::class )->div( $value, [ |
|
203 | 203 | 'class' => 'glsr-summary-'.$key, |
204 | - ]); |
|
204 | + ] ); |
|
205 | 205 | } |
206 | 206 | } |
@@ -7,86 +7,86 @@ |
||
7 | 7 | |
8 | 8 | class Template |
9 | 9 | { |
10 | - /** |
|
11 | - * @param string $templatePath |
|
12 | - * @return void|string |
|
13 | - */ |
|
14 | - public function build($templatePath, array $data = []) |
|
15 | - { |
|
16 | - $data = $this->normalize($data); |
|
17 | - $path = Str::removePrefix('templates/', $templatePath); |
|
18 | - $template = glsr()->build($templatePath, $data); |
|
19 | - $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
20 | - $template = $this->interpolate($template, $data, $path); |
|
21 | - $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
22 | - $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
23 | - return $template; |
|
24 | - } |
|
10 | + /** |
|
11 | + * @param string $templatePath |
|
12 | + * @return void|string |
|
13 | + */ |
|
14 | + public function build($templatePath, array $data = []) |
|
15 | + { |
|
16 | + $data = $this->normalize($data); |
|
17 | + $path = Str::removePrefix('templates/', $templatePath); |
|
18 | + $template = glsr()->build($templatePath, $data); |
|
19 | + $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
20 | + $template = $this->interpolate($template, $data, $path); |
|
21 | + $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
22 | + $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
23 | + return $template; |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Interpolate context values into template placeholders. |
|
28 | - * @param string $template |
|
29 | - * @param string $templatePath |
|
30 | - * @return string |
|
31 | - */ |
|
32 | - public function interpolate($template, array $data = [], $templatePath) |
|
33 | - { |
|
34 | - $context = $this->normalizeContext(Arr::get($data, 'context', [])); |
|
35 | - $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
36 | - return $this->interpolateContext($template, $context); |
|
37 | - } |
|
26 | + /** |
|
27 | + * Interpolate context values into template placeholders. |
|
28 | + * @param string $template |
|
29 | + * @param string $templatePath |
|
30 | + * @return string |
|
31 | + */ |
|
32 | + public function interpolate($template, array $data = [], $templatePath) |
|
33 | + { |
|
34 | + $context = $this->normalizeContext(Arr::get($data, 'context', [])); |
|
35 | + $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
36 | + return $this->interpolateContext($template, $context); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Interpolate context values into template placeholders. |
|
41 | - * @param string $text |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - public function interpolateContext($text, array $context = []) |
|
45 | - { |
|
46 | - foreach ($context as $key => $value) { |
|
47 | - $text = strtr( |
|
48 | - $text, |
|
49 | - array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
50 | - ); |
|
51 | - } |
|
52 | - return trim($text); |
|
53 | - } |
|
39 | + /** |
|
40 | + * Interpolate context values into template placeholders. |
|
41 | + * @param string $text |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + public function interpolateContext($text, array $context = []) |
|
45 | + { |
|
46 | + foreach ($context as $key => $value) { |
|
47 | + $text = strtr( |
|
48 | + $text, |
|
49 | + array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
50 | + ); |
|
51 | + } |
|
52 | + return trim($text); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param string $templatePath |
|
57 | - * @return void|string |
|
58 | - */ |
|
59 | - public function render($templatePath, array $data = []) |
|
60 | - { |
|
61 | - echo $this->build($templatePath, $data); |
|
62 | - } |
|
55 | + /** |
|
56 | + * @param string $templatePath |
|
57 | + * @return void|string |
|
58 | + */ |
|
59 | + public function render($templatePath, array $data = []) |
|
60 | + { |
|
61 | + echo $this->build($templatePath, $data); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - protected function normalize(array $data) |
|
68 | - { |
|
69 | - $arrayKeys = ['context', 'globals']; |
|
70 | - $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
71 | - foreach ($arrayKeys as $key) { |
|
72 | - if (is_array($data[$key])) { |
|
73 | - continue; |
|
74 | - } |
|
75 | - $data[$key] = []; |
|
76 | - } |
|
77 | - return $data; |
|
78 | - } |
|
64 | + /** |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + protected function normalize(array $data) |
|
68 | + { |
|
69 | + $arrayKeys = ['context', 'globals']; |
|
70 | + $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
71 | + foreach ($arrayKeys as $key) { |
|
72 | + if (is_array($data[$key])) { |
|
73 | + continue; |
|
74 | + } |
|
75 | + $data[$key] = []; |
|
76 | + } |
|
77 | + return $data; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - protected function normalizeContext(array $context) |
|
84 | - { |
|
85 | - $context = array_filter($context, function ($value) { |
|
86 | - return !is_array($value) && !is_object($value); |
|
87 | - }); |
|
88 | - return array_map(function ($value) { |
|
89 | - return (string) $value; |
|
90 | - }, $context); |
|
91 | - } |
|
80 | + /** |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + protected function normalizeContext(array $context) |
|
84 | + { |
|
85 | + $context = array_filter($context, function ($value) { |
|
86 | + return !is_array($value) && !is_object($value); |
|
87 | + }); |
|
88 | + return array_map(function ($value) { |
|
89 | + return (string) $value; |
|
90 | + }, $context); |
|
91 | + } |
|
92 | 92 | } |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | * @param string $templatePath |
12 | 12 | * @return void|string |
13 | 13 | */ |
14 | - public function build($templatePath, array $data = []) |
|
14 | + public function build( $templatePath, array $data = [] ) |
|
15 | 15 | { |
16 | - $data = $this->normalize($data); |
|
17 | - $path = Str::removePrefix('templates/', $templatePath); |
|
18 | - $template = glsr()->build($templatePath, $data); |
|
19 | - $template = apply_filters('site-reviews/build/template/'.$path, $template, $data); |
|
20 | - $template = $this->interpolate($template, $data, $path); |
|
21 | - $template = apply_filters('site-reviews/rendered/template', $template, $templatePath, $data); |
|
22 | - $template = apply_filters('site-reviews/rendered/template/'.$path, $template, $data); |
|
16 | + $data = $this->normalize( $data ); |
|
17 | + $path = Str::removePrefix( 'templates/', $templatePath ); |
|
18 | + $template = glsr()->build( $templatePath, $data ); |
|
19 | + $template = apply_filters( 'site-reviews/build/template/'.$path, $template, $data ); |
|
20 | + $template = $this->interpolate( $template, $data, $path ); |
|
21 | + $template = apply_filters( 'site-reviews/rendered/template', $template, $templatePath, $data ); |
|
22 | + $template = apply_filters( 'site-reviews/rendered/template/'.$path, $template, $data ); |
|
23 | 23 | return $template; |
24 | 24 | } |
25 | 25 | |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | * @param string $templatePath |
30 | 30 | * @return string |
31 | 31 | */ |
32 | - public function interpolate($template, array $data = [], $templatePath) |
|
32 | + public function interpolate( $template, array $data = [], $templatePath ) |
|
33 | 33 | { |
34 | - $context = $this->normalizeContext(Arr::get($data, 'context', [])); |
|
35 | - $context = apply_filters('site-reviews/interpolate/'.$templatePath, $context, $template, $data); |
|
36 | - return $this->interpolateContext($template, $context); |
|
34 | + $context = $this->normalizeContext( Arr::get( $data, 'context', [] ) ); |
|
35 | + $context = apply_filters( 'site-reviews/interpolate/'.$templatePath, $context, $template, $data ); |
|
36 | + return $this->interpolateContext( $template, $context ); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -41,35 +41,35 @@ discard block |
||
41 | 41 | * @param string $text |
42 | 42 | * @return string |
43 | 43 | */ |
44 | - public function interpolateContext($text, array $context = []) |
|
44 | + public function interpolateContext( $text, array $context = [] ) |
|
45 | 45 | { |
46 | - foreach ($context as $key => $value) { |
|
46 | + foreach( $context as $key => $value ) { |
|
47 | 47 | $text = strtr( |
48 | 48 | $text, |
49 | - array_fill_keys(['{'.$key.'}', '{{ '.$key.' }}'], $value) |
|
49 | + array_fill_keys( ['{'.$key.'}', '{{ '.$key.' }}'], $value ) |
|
50 | 50 | ); |
51 | 51 | } |
52 | - return trim($text); |
|
52 | + return trim( $text ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @param string $templatePath |
57 | 57 | * @return void|string |
58 | 58 | */ |
59 | - public function render($templatePath, array $data = []) |
|
59 | + public function render( $templatePath, array $data = [] ) |
|
60 | 60 | { |
61 | - echo $this->build($templatePath, $data); |
|
61 | + echo $this->build( $templatePath, $data ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
65 | 65 | * @return array |
66 | 66 | */ |
67 | - protected function normalize(array $data) |
|
67 | + protected function normalize( array $data ) |
|
68 | 68 | { |
69 | 69 | $arrayKeys = ['context', 'globals']; |
70 | - $data = wp_parse_args($data, array_fill_keys($arrayKeys, [])); |
|
71 | - foreach ($arrayKeys as $key) { |
|
72 | - if (is_array($data[$key])) { |
|
70 | + $data = wp_parse_args( $data, array_fill_keys( $arrayKeys, [] ) ); |
|
71 | + foreach( $arrayKeys as $key ) { |
|
72 | + if( is_array( $data[$key] ) ) { |
|
73 | 73 | continue; |
74 | 74 | } |
75 | 75 | $data[$key] = []; |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | /** |
81 | 81 | * @return array |
82 | 82 | */ |
83 | - protected function normalizeContext(array $context) |
|
83 | + protected function normalizeContext( array $context ) |
|
84 | 84 | { |
85 | - $context = array_filter($context, function ($value) { |
|
86 | - return !is_array($value) && !is_object($value); |
|
85 | + $context = array_filter( $context, function( $value ) { |
|
86 | + return !is_array( $value ) && !is_object( $value ); |
|
87 | 87 | }); |
88 | - return array_map(function ($value) { |
|
89 | - return (string) $value; |
|
90 | - }, $context); |
|
88 | + return array_map( function( $value ) { |
|
89 | + return (string)$value; |
|
90 | + }, $context ); |
|
91 | 91 | } |
92 | 92 | } |