x Sorry, these patches are not available anymore due to data migration. Please run a fresh inspection.
Passed
Push — master ( af979f...1dfed5 )
by Paul
08:16 queued 04:12
created
plugin/Filters.php 1 patch
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -15,72 +15,72 @@
 block discarded – undo
15 15
 
16 16
 class Filters implements HooksContract
17 17
 {
18
-    protected $admin;
19
-    protected $app;
20
-    protected $basename;
21
-    protected $blocks;
22
-    protected $editor;
23
-    protected $listtable;
24
-    protected $public;
25
-    protected $rebusify;
26
-    protected $translator;
27
-    protected $welcome;
18
+	protected $admin;
19
+	protected $app;
20
+	protected $basename;
21
+	protected $blocks;
22
+	protected $editor;
23
+	protected $listtable;
24
+	protected $public;
25
+	protected $rebusify;
26
+	protected $translator;
27
+	protected $welcome;
28 28
 
29
-    public function __construct(Application $app)
30
-    {
31
-        $this->app = $app;
32
-        $this->admin = $app->make(AdminController::class);
33
-        $this->basename = plugin_basename($app->file);
34
-        $this->blocks = $app->make(BlocksController::class);
35
-        $this->editor = $app->make(EditorController::class);
36
-        $this->listtable = $app->make(ListTableController::class);
37
-        $this->public = $app->make(PublicController::class);
38
-        $this->rebusify = $app->make(RebusifyController::class);
39
-        $this->translator = $app->make(TranslationController::class);
40
-        $this->welcome = $app->make(WelcomeController::class);
41
-    }
29
+	public function __construct(Application $app)
30
+	{
31
+		$this->app = $app;
32
+		$this->admin = $app->make(AdminController::class);
33
+		$this->basename = plugin_basename($app->file);
34
+		$this->blocks = $app->make(BlocksController::class);
35
+		$this->editor = $app->make(EditorController::class);
36
+		$this->listtable = $app->make(ListTableController::class);
37
+		$this->public = $app->make(PublicController::class);
38
+		$this->rebusify = $app->make(RebusifyController::class);
39
+		$this->translator = $app->make(TranslationController::class);
40
+		$this->welcome = $app->make(WelcomeController::class);
41
+	}
42 42
 
43
-    /**
44
-     * @return void
45
-     */
46
-    public function run()
47
-    {
48
-        add_filter('map_meta_cap',                                              [$this->admin, 'filterCreateCapability'], 10, 2);
49
-        add_filter('mce_external_plugins',                                      [$this->admin, 'filterTinymcePlugins'], 15);
50
-        add_filter('plugin_action_links_'.$this->basename,                      [$this->admin, 'filterActionLinks']);
51
-        add_filter('dashboard_glance_items',                                    [$this->admin, 'filterDashboardGlanceItems']);
52
-        add_filter('block_categories',                                          [$this->blocks, 'filterBlockCategories']);
53
-        add_filter('classic_editor_enabled_editors_for_post_type',              [$this->blocks, 'filterEnabledEditors'], 10, 2);
54
-        add_filter('use_block_editor_for_post_type',                            [$this->blocks, 'filterUseBlockEditor'], 10, 2);
55
-        add_filter('wp_editor_settings',                                        [$this->editor, 'filterEditorSettings']);
56
-        add_filter('the_editor',                                                [$this->editor, 'filterEditorTextarea']);
57
-        add_filter('is_protected_meta',                                         [$this->editor, 'filterIsProtectedMeta'], 10, 3);
58
-        add_filter('post_updated_messages',                                     [$this->editor, 'filterUpdateMessages']);
59
-        add_filter('manage_'.Application::POST_TYPE.'_posts_columns',           [$this->listtable, 'filterColumnsForPostType']);
60
-        add_filter('post_date_column_status',                                   [$this->listtable, 'filterDateColumnStatus'], 10, 2);
61
-        add_filter('default_hidden_columns',                                    [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2);
62
-        add_filter('post_row_actions',                                          [$this->listtable, 'filterRowActions'], 10, 2);
63
-        add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns',   [$this->listtable, 'filterSortableColumns']);
64
-        add_filter('script_loader_tag',                                         [$this->public, 'filterEnqueuedScripts'], 10, 2);
65
-        add_filter('site-reviews/config/forms/submission-form',                 [$this->public, 'filterFieldOrder'], 11);
66
-        add_filter('site-reviews/render/view',                                  [$this->public, 'filterRenderView']);
67
-        add_filter('site-reviews/settings/callback',                            [$this->rebusify, 'filterSettingsCallback']);
68
-        add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3);
69
-        add_filter('bulk_post_updated_messages',                                [$this->translator, 'filterBulkUpdateMessages'], 10, 2);
70
-        add_filter('gettext',                                                   [$this->translator, 'filterGettext'], 9, 3);
71
-        add_filter('site-reviews/gettext/site-reviews',                         [$this->translator, 'filterGettextSiteReviews'], 10, 2);
72
-        add_filter('gettext_with_context',                                      [$this->translator, 'filterGettextWithContext'], 9, 4);
73
-        add_filter('site-reviews/gettext_with_context/site-reviews',            [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3);
74
-        add_filter('ngettext',                                                  [$this->translator, 'filterNgettext'], 9, 5);
75
-        add_filter('site-reviews/ngettext/site-reviews',                        [$this->translator, 'filterNgettextSiteReviews'], 10, 4);
76
-        add_filter('ngettext_with_context',                                     [$this->translator, 'filterNgettextWithContext'], 9, 6);
77
-        add_filter('site-reviews/ngettext_with_context/site-reviews',           [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5);
78
-        add_filter('display_post_states',                                       [$this->translator, 'filterPostStates'], 10, 2);
79
-        add_filter('site-reviews/gettext/default',                              [$this->translator, 'filterPostStatusLabels'], 10, 2);
80
-        add_filter('site-reviews/gettext_with_context/default',                 [$this->translator, 'filterPostStatusLabels'], 10, 2);
81
-        add_filter('site-reviews/ngettext/default',                             [$this->translator, 'filterPostStatusText'], 10, 4);
82
-        add_filter('plugin_action_links_'.$this->basename,                      [$this->welcome, 'filterActionLinks'], 9);
83
-        add_filter('admin_title',                                               [$this->welcome, 'filterAdminTitle']);
84
-        add_filter('admin_footer_text',                                         [$this->welcome, 'filterFooterText']);
85
-    }
43
+	/**
44
+	 * @return void
45
+	 */
46
+	public function run()
47
+	{
48
+		add_filter('map_meta_cap',                                              [$this->admin, 'filterCreateCapability'], 10, 2);
49
+		add_filter('mce_external_plugins',                                      [$this->admin, 'filterTinymcePlugins'], 15);
50
+		add_filter('plugin_action_links_'.$this->basename,                      [$this->admin, 'filterActionLinks']);
51
+		add_filter('dashboard_glance_items',                                    [$this->admin, 'filterDashboardGlanceItems']);
52
+		add_filter('block_categories',                                          [$this->blocks, 'filterBlockCategories']);
53
+		add_filter('classic_editor_enabled_editors_for_post_type',              [$this->blocks, 'filterEnabledEditors'], 10, 2);
54
+		add_filter('use_block_editor_for_post_type',                            [$this->blocks, 'filterUseBlockEditor'], 10, 2);
55
+		add_filter('wp_editor_settings',                                        [$this->editor, 'filterEditorSettings']);
56
+		add_filter('the_editor',                                                [$this->editor, 'filterEditorTextarea']);
57
+		add_filter('is_protected_meta',                                         [$this->editor, 'filterIsProtectedMeta'], 10, 3);
58
+		add_filter('post_updated_messages',                                     [$this->editor, 'filterUpdateMessages']);
59
+		add_filter('manage_'.Application::POST_TYPE.'_posts_columns',           [$this->listtable, 'filterColumnsForPostType']);
60
+		add_filter('post_date_column_status',                                   [$this->listtable, 'filterDateColumnStatus'], 10, 2);
61
+		add_filter('default_hidden_columns',                                    [$this->listtable, 'filterDefaultHiddenColumns'], 10, 2);
62
+		add_filter('post_row_actions',                                          [$this->listtable, 'filterRowActions'], 10, 2);
63
+		add_filter('manage_edit-'.Application::POST_TYPE.'_sortable_columns',   [$this->listtable, 'filterSortableColumns']);
64
+		add_filter('script_loader_tag',                                         [$this->public, 'filterEnqueuedScripts'], 10, 2);
65
+		add_filter('site-reviews/config/forms/submission-form',                 [$this->public, 'filterFieldOrder'], 11);
66
+		add_filter('site-reviews/render/view',                                  [$this->public, 'filterRenderView']);
67
+		add_filter('site-reviews/settings/callback',                            [$this->rebusify, 'filterSettingsCallback']);
68
+		add_filter('site-reviews/interpolate/partials/form/table-row-multiple', [$this->rebusify, 'filterSettingsTableRow'], 10, 3);
69
+		add_filter('bulk_post_updated_messages',                                [$this->translator, 'filterBulkUpdateMessages'], 10, 2);
70
+		add_filter('gettext',                                                   [$this->translator, 'filterGettext'], 9, 3);
71
+		add_filter('site-reviews/gettext/site-reviews',                         [$this->translator, 'filterGettextSiteReviews'], 10, 2);
72
+		add_filter('gettext_with_context',                                      [$this->translator, 'filterGettextWithContext'], 9, 4);
73
+		add_filter('site-reviews/gettext_with_context/site-reviews',            [$this->translator, 'filterGettextWithContextSiteReviews'], 10, 3);
74
+		add_filter('ngettext',                                                  [$this->translator, 'filterNgettext'], 9, 5);
75
+		add_filter('site-reviews/ngettext/site-reviews',                        [$this->translator, 'filterNgettextSiteReviews'], 10, 4);
76
+		add_filter('ngettext_with_context',                                     [$this->translator, 'filterNgettextWithContext'], 9, 6);
77
+		add_filter('site-reviews/ngettext_with_context/site-reviews',           [$this->translator, 'filterNgettextWithContextSiteReviews'], 10, 5);
78
+		add_filter('display_post_states',                                       [$this->translator, 'filterPostStates'], 10, 2);
79
+		add_filter('site-reviews/gettext/default',                              [$this->translator, 'filterPostStatusLabels'], 10, 2);
80
+		add_filter('site-reviews/gettext_with_context/default',                 [$this->translator, 'filterPostStatusLabels'], 10, 2);
81
+		add_filter('site-reviews/ngettext/default',                             [$this->translator, 'filterPostStatusText'], 10, 4);
82
+		add_filter('plugin_action_links_'.$this->basename,                      [$this->welcome, 'filterActionLinks'], 9);
83
+		add_filter('admin_title',                                               [$this->welcome, 'filterAdminTitle']);
84
+		add_filter('admin_footer_text',                                         [$this->welcome, 'filterFooterText']);
85
+	}
86 86
 }
Please login to merge, or discard this patch.
plugin/Controllers/PublicController.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -13,81 +13,81 @@
 block discarded – undo
13 13
 
14 14
 class PublicController extends Controller
15 15
 {
16
-    /**
17
-     * @return void
18
-     * @action wp_enqueue_scripts
19
-     */
20
-    public function enqueueAssets()
21
-    {
22
-        (new EnqueuePublicAssets())->handle();
23
-    }
16
+	/**
17
+	 * @return void
18
+	 * @action wp_enqueue_scripts
19
+	 */
20
+	public function enqueueAssets()
21
+	{
22
+		(new EnqueuePublicAssets())->handle();
23
+	}
24 24
 
25
-    /**
26
-     * @param string $tag
27
-     * @param string $handle
28
-     * @return string
29
-     * @filter script_loader_tag
30
-     */
31
-    public function filterEnqueuedScripts($tag, $handle)
32
-    {
33
-        $scripts = [Application::ID.'/google-recaptcha'];
34
-        if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) {
35
-            $tag = str_replace(' src=', ' async src=', $tag);
36
-        }
37
-        if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) {
38
-            $tag = str_replace(' src=', ' defer src=', $tag);
39
-        }
40
-        return $tag;
41
-    }
25
+	/**
26
+	 * @param string $tag
27
+	 * @param string $handle
28
+	 * @return string
29
+	 * @filter script_loader_tag
30
+	 */
31
+	public function filterEnqueuedScripts($tag, $handle)
32
+	{
33
+		$scripts = [Application::ID.'/google-recaptcha'];
34
+		if (in_array($handle, apply_filters('site-reviews/async-scripts', $scripts))) {
35
+			$tag = str_replace(' src=', ' async src=', $tag);
36
+		}
37
+		if (in_array($handle, apply_filters('site-reviews/defer-scripts', $scripts))) {
38
+			$tag = str_replace(' src=', ' defer src=', $tag);
39
+		}
40
+		return $tag;
41
+	}
42 42
 
43
-    /**
44
-     * @return array
45
-     * @filter site-reviews/config/forms/submission-form
46
-     */
47
-    public function filterFieldOrder(array $config)
48
-    {
49
-        $order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config));
50
-        return array_intersect_key(array_merge(array_flip($order), $config), $config);
51
-    }
43
+	/**
44
+	 * @return array
45
+	 * @filter site-reviews/config/forms/submission-form
46
+	 */
47
+	public function filterFieldOrder(array $config)
48
+	{
49
+		$order = (array) apply_filters('site-reviews/submission-form/order', array_keys($config));
50
+		return array_intersect_key(array_merge(array_flip($order), $config), $config);
51
+	}
52 52
 
53
-    /**
54
-     * @param string $view
55
-     * @return string
56
-     * @filter site-reviews/render/view
57
-     */
58
-    public function filterRenderView($view)
59
-    {
60
-        return glsr(Style::class)->filterView($view);
61
-    }
53
+	/**
54
+	 * @param string $view
55
+	 * @return string
56
+	 * @filter site-reviews/render/view
57
+	 */
58
+	public function filterRenderView($view)
59
+	{
60
+		return glsr(Style::class)->filterView($view);
61
+	}
62 62
 
63
-    /**
64
-     * @return void
65
-     * @action site-reviews/builder
66
-     */
67
-    public function modifyBuilder(Builder $instance)
68
-    {
69
-        call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]);
70
-    }
63
+	/**
64
+	 * @return void
65
+	 * @action site-reviews/builder
66
+	 */
67
+	public function modifyBuilder(Builder $instance)
68
+	{
69
+		call_user_func_array([glsr(Style::class), 'modifyField'], [$instance]);
70
+	}
71 71
 
72
-    /**
73
-     * @return void
74
-     * @action wp_footer
75
-     */
76
-    public function renderSchema()
77
-    {
78
-        glsr(Schema::class)->render();
79
-    }
72
+	/**
73
+	 * @return void
74
+	 * @action wp_footer
75
+	 */
76
+	public function renderSchema()
77
+	{
78
+		glsr(Schema::class)->render();
79
+	}
80 80
 
81
-    /**
82
-     * @return CreateReview
83
-     */
84
-    public function routerSubmitReview(array $request)
85
-    {
86
-        $validated = glsr(ValidateReview::class)->validate($request);
87
-        $command = new CreateReview($validated->request);
88
-        if (empty($validated->error) && !$validated->recaptchaIsUnset) {
89
-            $this->execute($command);
90
-        }
91
-        return $command;
92
-    }
81
+	/**
82
+	 * @return CreateReview
83
+	 */
84
+	public function routerSubmitReview(array $request)
85
+	{
86
+		$validated = glsr(ValidateReview::class)->validate($request);
87
+		$command = new CreateReview($validated->request);
88
+		if (empty($validated->error) && !$validated->recaptchaIsUnset) {
89
+			$this->execute($command);
90
+		}
91
+		return $command;
92
+	}
93 93
 }
Please login to merge, or discard this patch.
plugin/Database/Cache.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -6,63 +6,63 @@
 block discarded – undo
6 6
 
7 7
 class Cache
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    public function getCloudflareIps()
13
-    {
14
-        if (false === ($ipAddresses = get_transient(Application::ID.'_cloudflare_ips'))) {
15
-            $ipAddresses = array_fill_keys(['v4', 'v6'], []);
16
-            foreach (array_keys($ipAddresses) as $version) {
17
-                $url = 'https://www.cloudflare.com/ips-'.$version;
18
-                $response = wp_remote_get($url, ['sslverify' => false]);
19
-                if (is_wp_error($response)) {
20
-                    glsr_log()->error($response->get_error_message());
21
-                    continue;
22
-                }
23
-                if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) {
24
-                    glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']');
25
-                    continue;
26
-                }
27
-                $ipAddresses[$version] = array_filter(
28
-                    (array) preg_split('/\R/', wp_remote_retrieve_body($response))
29
-                );
30
-            }
31
-            set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS);
32
-        }
33
-        return $ipAddresses;
34
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	public function getCloudflareIps()
13
+	{
14
+		if (false === ($ipAddresses = get_transient(Application::ID.'_cloudflare_ips'))) {
15
+			$ipAddresses = array_fill_keys(['v4', 'v6'], []);
16
+			foreach (array_keys($ipAddresses) as $version) {
17
+				$url = 'https://www.cloudflare.com/ips-'.$version;
18
+				$response = wp_remote_get($url, ['sslverify' => false]);
19
+				if (is_wp_error($response)) {
20
+					glsr_log()->error($response->get_error_message());
21
+					continue;
22
+				}
23
+				if ('200' != ($statusCode = wp_remote_retrieve_response_code($response))) {
24
+					glsr_log()->error('Unable to connect to '.$url.' ['.$statusCode.']');
25
+					continue;
26
+				}
27
+				$ipAddresses[$version] = array_filter(
28
+					(array) preg_split('/\R/', wp_remote_retrieve_body($response))
29
+				);
30
+			}
31
+			set_transient(Application::ID.'_cloudflare_ips', $ipAddresses, WEEK_IN_SECONDS);
32
+		}
33
+		return $ipAddresses;
34
+	}
35 35
 
36
-    /**
37
-     * @param string $metaKey
38
-     * @return array
39
-     */
40
-    public function getReviewCountsFor($metaKey)
41
-    {
42
-        $counts = wp_cache_get(Application::ID, $metaKey.'_count');
43
-        if (false === $counts) {
44
-            $counts = [];
45
-            $results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey);
46
-            foreach ($results as $result) {
47
-                $counts[$result->name] = $result->num_posts;
48
-            }
49
-            wp_cache_set(Application::ID, $counts, $metaKey.'_count');
50
-        }
51
-        return $counts;
52
-    }
36
+	/**
37
+	 * @param string $metaKey
38
+	 * @return array
39
+	 */
40
+	public function getReviewCountsFor($metaKey)
41
+	{
42
+		$counts = wp_cache_get(Application::ID, $metaKey.'_count');
43
+		if (false === $counts) {
44
+			$counts = [];
45
+			$results = glsr(SqlQueries::class)->getReviewCountsFor($metaKey);
46
+			foreach ($results as $result) {
47
+				$counts[$result->name] = $result->num_posts;
48
+			}
49
+			wp_cache_set(Application::ID, $counts, $metaKey.'_count');
50
+		}
51
+		return $counts;
52
+	}
53 53
 
54
-    /**
55
-     * @return string
56
-     */
57
-    public function getRemotePostTest()
58
-    {
59
-        if (false === ($test = get_transient(Application::ID.'_remote_post_test'))) {
60
-            $response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/');
61
-            $test = !is_wp_error($response) && in_array($response['response']['code'], range(200, 299))
62
-                ? 'Works'
63
-                : 'Does not work';
64
-            set_transient(Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS);
65
-        }
66
-        return $test;
67
-    }
54
+	/**
55
+	 * @return string
56
+	 */
57
+	public function getRemotePostTest()
58
+	{
59
+		if (false === ($test = get_transient(Application::ID.'_remote_post_test'))) {
60
+			$response = wp_remote_post('https://api.wordpress.org/stats/php/1.0/');
61
+			$test = !is_wp_error($response) && in_array($response['response']['code'], range(200, 299))
62
+				? 'Works'
63
+				: 'Does not work';
64
+			set_transient(Application::ID.'_remote_post_test', $test, WEEK_IN_SECONDS);
65
+		}
66
+		return $test;
67
+	}
68 68
 }
Please login to merge, or discard this patch.
plugin/Controllers/RebusifyController.php 1 patch
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -12,231 +12,231 @@
 block discarded – undo
12 12
 
13 13
 class RebusifyController extends Controller
14 14
 {
15
-    protected $apiKey = 'settings.general.rebusify_serial';
16
-    protected $emailKey = 'settings.general.rebusify_email';
17
-    protected $enabledKey = 'settings.general.rebusify';
18
-    protected $rebusifyKey = '_glsr_rebusify';
19
-
20
-    /**
21
-     * @return array
22
-     * @filter site-reviews/settings/callback
23
-     */
24
-    public function filterSettingsCallback(array $settings)
25
-    {
26
-        if ('yes' !== Arr::get($settings, $this->enabledKey)) {
27
-            return $settings;
28
-        }
29
-        $isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings);
30
-        $isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings);
31
-        $isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false);
32
-        if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) {
33
-            $settings = $this->sanitizeRebusifySettings($settings);
34
-        }
35
-        return $settings;
36
-    }
37
-
38
-    /**
39
-     * @param string $template
40
-     * @return array
41
-     * @filter site-reviews/interpolate/partials/form/table-row-multiple
42
-     */
43
-    public function filterSettingsTableRow(array $context, $template, array $data)
44
-    {
45
-        if ($this->enabledKey !== Arr::get($data, 'field.path')) {
46
-            return $context;
47
-        }
48
-        $rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey);
49
-        if ('P' === $rebusifyProductType) {
50
-            return $context;
51
-        }
52
-        if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) {
53
-            $button = $this->buildUpgradeButton();
54
-        } else {
55
-            $button = $this->buildCreateButton();
56
-        }
57
-        $context['field'].= $button;
58
-        return $context;
59
-    }
60
-
61
-    /**
62
-     * Triggered when a review is created.
63
-     * @return void
64
-     * @action site-reviews/review/created
65
-     */
66
-    public function onCreated(Review $review)
67
-    {
68
-        if (!$this->canPostReview($review)) {
69
-            return;
70
-        }
71
-        $rebusify = glsr(Rebusify::class)->sendReview($review);
72
-        if ($rebusify->success) {
73
-            glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
74
-        }
75
-    }
76
-
77
-    /**
78
-     * Triggered when a review is reverted to its original title/content/date_timestamp.
79
-     * @return void
80
-     * @action site-reviews/review/reverted
81
-     */
82
-    public function onReverted(Review $review)
83
-    {
84
-        if (!$this->canPostReview($review)) {
85
-            return;
86
-        }
87
-        $rebusify = glsr(Rebusify::class)->sendReview($review);
88
-        if ($rebusify->success) {
89
-            glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
90
-        }
91
-    }
92
-
93
-    /**
94
-     * Triggered when an existing review is updated.
95
-     * @return void
96
-     * @action site-reviews/review/saved
97
-     */
98
-    public function onSaved(Review $review)
99
-    {
100
-        if (!$this->canPostReview($review)) {
101
-            return;
102
-        }
103
-        $rebusify = glsr(Rebusify::class)->sendReview($review);
104
-        if ($rebusify->success) {
105
-            glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
106
-        }
107
-    }
108
-
109
-    /**
110
-     * Triggered when a review's response is added or updated.
111
-     * @param int $metaId
112
-     * @param int $postId
113
-     * @param string $metaKey
114
-     * @return void
115
-     * @action updated_postmeta
116
-     */
117
-    public function onUpdatedMeta($metaId, $postId, $metaKey)
118
-    {
119
-        $review = glsr_get_review($postId);
120
-        if (!$this->canPostResponse($review) || '_response' !== $metaKey) {
121
-            return;
122
-        }
123
-        $rebusify = glsr(Rebusify::class)->sendReviewResponse($review);
124
-        if ($rebusify->success) {
125
-            glsr(Database::class)->set($review->ID, 'rebusify_response', true);
126
-        }
127
-    }
128
-
129
-    /**
130
-     * @return string
131
-     */
132
-    protected function buildCreateButton()
133
-    {
134
-        return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [
135
-            'class' => 'button',
136
-            'href' => Rebusify::WEB_URL,
137
-            'target' => '_blank',
138
-        ]);
139
-    }
140
-
141
-    /**
142
-     * @return string
143
-     */
144
-    protected function buildUpgradeButton()
145
-    {
146
-        $build = glsr(Builder::class);
147
-        $notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews'));
148
-        $button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [
149
-            'class' => 'button',
150
-            'href' => Rebusify::WEB_URL,
151
-            'target' => '_blank',
152
-        ]);
153
-        return $build->div($notice.$button, [
154
-            'class' => 'glsr-notice-inline notice inline notice-info',
155
-        ]);
156
-    }
157
-
158
-    /**
159
-     * @return bool
160
-     */
161
-    protected function canPostResponse(Review $review)
162
-    {
163
-        $requiredValues = [
164
-            glsr(Database::class)->get($review->ID, 'rebusify'),
165
-            $review->response,
166
-            $review->review_id,
167
-        ];
168
-        return $this->canProceed($review, 'rebusify_response')
169
-            && 'publish' === $review->status
170
-            && 3 === count(array_filter($requiredValues));
171
-    }
172
-
173
-    /**
174
-     * @return bool
175
-     */
176
-    protected function canPostReview(Review $review)
177
-    {
178
-        $requiredValues = [
179
-            $review->author,
180
-            $review->content,
181
-            $review->rating,
182
-            $review->review_id,
183
-            $review->title,
184
-        ];
185
-        return $this->canProceed($review)
186
-            && 'publish' === $review->status
187
-            && 5 === count(array_filter($requiredValues));
188
-    }
189
-
190
-    /**
191
-     * @param string $metaKey
192
-     * @return bool
193
-     */
194
-    protected function canProceed(Review $review, $metaKey = 'rebusify')
195
-    {
196
-        return glsr(OptionManager::class)->getBool($this->enabledKey)
197
-            && $this->isReviewPostId($review->ID)
198
-            && !$this->hasMetaKey($review, $metaKey);
199
-    }
200
-
201
-    /**
202
-     * @param string $metaKey
203
-     * @return bool
204
-     */
205
-    protected function hasMetaKey(Review $review, $metaKey = 'rebusify')
206
-    {
207
-        return '' !== glsr(Database::class)->get($review->ID, $metaKey);
208
-    }
209
-
210
-    /**
211
-     * @param string $key
212
-     * @return bool
213
-     */
214
-    protected function isEmptyOrModified($key, array $settings)
215
-    {
216
-        $oldValue = glsr_get_option($key);
217
-        $newValue = Arr::get($settings, $key);
218
-        return empty($newValue) || $newValue !== $oldValue;
219
-    }
220
-
221
-    /**
222
-     * @return array
223
-     */
224
-    protected function sanitizeRebusifySettings(array $settings)
225
-    {
226
-        $rebusify = glsr(Rebusify::class)->activateKey(
227
-            Arr::get($settings, $this->apiKey),
228
-            Arr::get($settings, $this->emailKey)
229
-        );
230
-        if ($rebusify->success) {
231
-            update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype'));
232
-        } else {
233
-            delete_option($this->rebusifyKey);
234
-            $settings = Arr::set($settings, $this->enabledKey, 'no');
235
-            glsr(Notice::class)->addError(sprintf(
236
-                __('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'),
237
-                '('.$rebusify->message.')'
238
-            ));
239
-        }
240
-        return $settings;
241
-    }
15
+	protected $apiKey = 'settings.general.rebusify_serial';
16
+	protected $emailKey = 'settings.general.rebusify_email';
17
+	protected $enabledKey = 'settings.general.rebusify';
18
+	protected $rebusifyKey = '_glsr_rebusify';
19
+
20
+	/**
21
+	 * @return array
22
+	 * @filter site-reviews/settings/callback
23
+	 */
24
+	public function filterSettingsCallback(array $settings)
25
+	{
26
+		if ('yes' !== Arr::get($settings, $this->enabledKey)) {
27
+			return $settings;
28
+		}
29
+		$isApiKeyModified = $this->isEmptyOrModified($this->apiKey, $settings);
30
+		$isEmailModified = $this->isEmptyOrModified($this->emailKey, $settings);
31
+		$isAccountVerified = glsr(OptionManager::class)->getWP($this->rebusifyKey, false);
32
+		if (!$isAccountVerified || $isApiKeyModified || $isEmailModified) {
33
+			$settings = $this->sanitizeRebusifySettings($settings);
34
+		}
35
+		return $settings;
36
+	}
37
+
38
+	/**
39
+	 * @param string $template
40
+	 * @return array
41
+	 * @filter site-reviews/interpolate/partials/form/table-row-multiple
42
+	 */
43
+	public function filterSettingsTableRow(array $context, $template, array $data)
44
+	{
45
+		if ($this->enabledKey !== Arr::get($data, 'field.path')) {
46
+			return $context;
47
+		}
48
+		$rebusifyProductType = glsr(OptionManager::class)->getWP($this->rebusifyKey);
49
+		if ('P' === $rebusifyProductType) {
50
+			return $context;
51
+		}
52
+		if ('F' === $rebusifyProductType && 'yes' === glsr_get_option('general.rebusify')) {
53
+			$button = $this->buildUpgradeButton();
54
+		} else {
55
+			$button = $this->buildCreateButton();
56
+		}
57
+		$context['field'].= $button;
58
+		return $context;
59
+	}
60
+
61
+	/**
62
+	 * Triggered when a review is created.
63
+	 * @return void
64
+	 * @action site-reviews/review/created
65
+	 */
66
+	public function onCreated(Review $review)
67
+	{
68
+		if (!$this->canPostReview($review)) {
69
+			return;
70
+		}
71
+		$rebusify = glsr(Rebusify::class)->sendReview($review);
72
+		if ($rebusify->success) {
73
+			glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
74
+		}
75
+	}
76
+
77
+	/**
78
+	 * Triggered when a review is reverted to its original title/content/date_timestamp.
79
+	 * @return void
80
+	 * @action site-reviews/review/reverted
81
+	 */
82
+	public function onReverted(Review $review)
83
+	{
84
+		if (!$this->canPostReview($review)) {
85
+			return;
86
+		}
87
+		$rebusify = glsr(Rebusify::class)->sendReview($review);
88
+		if ($rebusify->success) {
89
+			glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
90
+		}
91
+	}
92
+
93
+	/**
94
+	 * Triggered when an existing review is updated.
95
+	 * @return void
96
+	 * @action site-reviews/review/saved
97
+	 */
98
+	public function onSaved(Review $review)
99
+	{
100
+		if (!$this->canPostReview($review)) {
101
+			return;
102
+		}
103
+		$rebusify = glsr(Rebusify::class)->sendReview($review);
104
+		if ($rebusify->success) {
105
+			glsr(Database::class)->set($review->ID, 'rebusify', $rebusify->review_id);
106
+		}
107
+	}
108
+
109
+	/**
110
+	 * Triggered when a review's response is added or updated.
111
+	 * @param int $metaId
112
+	 * @param int $postId
113
+	 * @param string $metaKey
114
+	 * @return void
115
+	 * @action updated_postmeta
116
+	 */
117
+	public function onUpdatedMeta($metaId, $postId, $metaKey)
118
+	{
119
+		$review = glsr_get_review($postId);
120
+		if (!$this->canPostResponse($review) || '_response' !== $metaKey) {
121
+			return;
122
+		}
123
+		$rebusify = glsr(Rebusify::class)->sendReviewResponse($review);
124
+		if ($rebusify->success) {
125
+			glsr(Database::class)->set($review->ID, 'rebusify_response', true);
126
+		}
127
+	}
128
+
129
+	/**
130
+	 * @return string
131
+	 */
132
+	protected function buildCreateButton()
133
+	{
134
+		return glsr(Builder::class)->a(__('Create Your Rebusify Account', 'site-reviews'), [
135
+			'class' => 'button',
136
+			'href' => Rebusify::WEB_URL,
137
+			'target' => '_blank',
138
+		]);
139
+	}
140
+
141
+	/**
142
+	 * @return string
143
+	 */
144
+	protected function buildUpgradeButton()
145
+	{
146
+		$build = glsr(Builder::class);
147
+		$notice = $build->p(__('Free Rebusify accounts are limited to 500 blockchain transactions per year.', 'site-reviews'));
148
+		$button = $build->a(__('Upgrade Your Rebusify Plan', 'site-reviews'), [
149
+			'class' => 'button',
150
+			'href' => Rebusify::WEB_URL,
151
+			'target' => '_blank',
152
+		]);
153
+		return $build->div($notice.$button, [
154
+			'class' => 'glsr-notice-inline notice inline notice-info',
155
+		]);
156
+	}
157
+
158
+	/**
159
+	 * @return bool
160
+	 */
161
+	protected function canPostResponse(Review $review)
162
+	{
163
+		$requiredValues = [
164
+			glsr(Database::class)->get($review->ID, 'rebusify'),
165
+			$review->response,
166
+			$review->review_id,
167
+		];
168
+		return $this->canProceed($review, 'rebusify_response')
169
+			&& 'publish' === $review->status
170
+			&& 3 === count(array_filter($requiredValues));
171
+	}
172
+
173
+	/**
174
+	 * @return bool
175
+	 */
176
+	protected function canPostReview(Review $review)
177
+	{
178
+		$requiredValues = [
179
+			$review->author,
180
+			$review->content,
181
+			$review->rating,
182
+			$review->review_id,
183
+			$review->title,
184
+		];
185
+		return $this->canProceed($review)
186
+			&& 'publish' === $review->status
187
+			&& 5 === count(array_filter($requiredValues));
188
+	}
189
+
190
+	/**
191
+	 * @param string $metaKey
192
+	 * @return bool
193
+	 */
194
+	protected function canProceed(Review $review, $metaKey = 'rebusify')
195
+	{
196
+		return glsr(OptionManager::class)->getBool($this->enabledKey)
197
+			&& $this->isReviewPostId($review->ID)
198
+			&& !$this->hasMetaKey($review, $metaKey);
199
+	}
200
+
201
+	/**
202
+	 * @param string $metaKey
203
+	 * @return bool
204
+	 */
205
+	protected function hasMetaKey(Review $review, $metaKey = 'rebusify')
206
+	{
207
+		return '' !== glsr(Database::class)->get($review->ID, $metaKey);
208
+	}
209
+
210
+	/**
211
+	 * @param string $key
212
+	 * @return bool
213
+	 */
214
+	protected function isEmptyOrModified($key, array $settings)
215
+	{
216
+		$oldValue = glsr_get_option($key);
217
+		$newValue = Arr::get($settings, $key);
218
+		return empty($newValue) || $newValue !== $oldValue;
219
+	}
220
+
221
+	/**
222
+	 * @return array
223
+	 */
224
+	protected function sanitizeRebusifySettings(array $settings)
225
+	{
226
+		$rebusify = glsr(Rebusify::class)->activateKey(
227
+			Arr::get($settings, $this->apiKey),
228
+			Arr::get($settings, $this->emailKey)
229
+		);
230
+		if ($rebusify->success) {
231
+			update_option($this->rebusifyKey, Arr::get($rebusify->response, 'producttype'));
232
+		} else {
233
+			delete_option($this->rebusifyKey);
234
+			$settings = Arr::set($settings, $this->enabledKey, 'no');
235
+			glsr(Notice::class)->addError(sprintf(
236
+				__('Your Rebusify account details could not be verified, please try again. %s', 'site-reviews'),
237
+				'('.$rebusify->message.')'
238
+			));
239
+		}
240
+		return $settings;
241
+	}
242 242
 }
Please login to merge, or discard this patch.
plugin/Defaults/CreateReviewDefaults.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -6,41 +6,41 @@
 block discarded – undo
6 6
 
7 7
 class CreateReviewDefaults extends Defaults
8 8
 {
9
-    /**
10
-     * @var array
11
-     */
12
-    protected $guarded = [
13
-        'assigned_to',
14
-        'content',
15
-        'date',
16
-        'pinned',
17
-        'response',
18
-        'review_id',
19
-        'review_type',
20
-        'title',
21
-    ];
9
+	/**
10
+	 * @var array
11
+	 */
12
+	protected $guarded = [
13
+		'assigned_to',
14
+		'content',
15
+		'date',
16
+		'pinned',
17
+		'response',
18
+		'review_id',
19
+		'review_type',
20
+		'title',
21
+	];
22 22
 
23
-    /**
24
-     * @return array
25
-     */
26
-    protected function defaults()
27
-    {
28
-        return [
29
-            'assigned_to' => '',
30
-            'author' => '',
31
-            'avatar' => '',
32
-            'content' => '',
33
-            'custom' => '',
34
-            'date' => '',
35
-            'email' => '',
36
-            'ip_address' => '',
37
-            'pinned' => false,
38
-            'rating' => '',
39
-            'response' => '',
40
-            'review_id' => md5(time().mt_rand()),
41
-            'review_type' => 'local',
42
-            'title' => '',
43
-            'url' => '',
44
-        ];
45
-    }
23
+	/**
24
+	 * @return array
25
+	 */
26
+	protected function defaults()
27
+	{
28
+		return [
29
+			'assigned_to' => '',
30
+			'author' => '',
31
+			'avatar' => '',
32
+			'content' => '',
33
+			'custom' => '',
34
+			'date' => '',
35
+			'email' => '',
36
+			'ip_address' => '',
37
+			'pinned' => false,
38
+			'rating' => '',
39
+			'response' => '',
40
+			'review_id' => md5(time().mt_rand()),
41
+			'review_type' => 'local',
42
+			'title' => '',
43
+			'url' => '',
44
+		];
45
+	}
46 46
 }
Please login to merge, or discard this patch.
plugin/Defaults/ValidateReviewDefaults.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -6,22 +6,22 @@
 block discarded – undo
6 6
 
7 7
 class ValidateReviewDefaults extends Defaults
8 8
 {
9
-    /**
10
-     * @return array
11
-     */
12
-    protected function defaults()
13
-    {
14
-        return [
15
-            'assign_to' => '',
16
-            'category' => '',
17
-            'content' => '',
18
-            'email' => '',
19
-            'form_id' => '',
20
-            'ip_address' => '',
21
-            'name' => '',
22
-            'rating' => '0',
23
-            'terms' => '',
24
-            'title' => '',
25
-        ];
26
-    }
9
+	/**
10
+	 * @return array
11
+	 */
12
+	protected function defaults()
13
+	{
14
+		return [
15
+			'assign_to' => '',
16
+			'category' => '',
17
+			'content' => '',
18
+			'email' => '',
19
+			'form_id' => '',
20
+			'ip_address' => '',
21
+			'name' => '',
22
+			'rating' => '0',
23
+			'terms' => '',
24
+			'title' => '',
25
+		];
26
+	}
27 27
 }
Please login to merge, or discard this patch.
plugin/Modules/Console.php 1 patch
Indentation   +433 added lines, -433 removed lines patch added patch discarded remove patch
@@ -10,437 +10,437 @@
 block discarded – undo
10 10
 
11 11
 class Console
12 12
 {
13
-    const DEBUG = 0;      // Detailed debug information
14
-    const INFO = 1;       // Interesting events
15
-    const NOTICE = 2;     // Normal but significant events
16
-    const WARNING = 4;    // Exceptional occurrences that are not errors
17
-    const ERROR = 8;      // Runtime errors that do not require immediate action
18
-    const CRITICAL = 16;  // Critical conditions
19
-    const ALERT = 32;     // Action must be taken immediately
20
-    const EMERGENCY = 64; // System is unusable
21
-
22
-    protected $file;
23
-    protected $log;
24
-    protected $logOnceKey = 'glsr_log_once';
25
-
26
-    public function __construct()
27
-    {
28
-        $this->file = glsr()->path('console.log');
29
-        $this->log = file_exists($this->file)
30
-            ? file_get_contents($this->file)
31
-            : '';
32
-        $this->reset();
33
-    }
34
-
35
-    /**
36
-     * @return string
37
-     */
38
-    public function __toString()
39
-    {
40
-        return $this->get();
41
-    }
42
-
43
-    /**
44
-     * Action must be taken immediately
45
-     * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
46
-     * @param mixed $message
47
-     * @param array $context
48
-     * @return static
49
-     */
50
-    public function alert($message, array $context = [])
51
-    {
52
-        return $this->log(static::ALERT, $message, $context);
53
-    }
54
-
55
-    /**
56
-     * @return void
57
-     */
58
-    public function clear()
59
-    {
60
-        $this->log = '';
61
-        file_put_contents($this->file, $this->log);
62
-    }
63
-
64
-    /**
65
-     * Critical conditions
66
-     * Example: Application component unavailable, unexpected exception.
67
-     * @param mixed $message
68
-     * @param array $context
69
-     * @return static
70
-     */
71
-    public function critical($message, array $context = [])
72
-    {
73
-        return $this->log(static::CRITICAL, $message, $context);
74
-    }
75
-
76
-    /**
77
-     * Detailed debug information.
78
-     * @param mixed $message
79
-     * @param array $context
80
-     * @return static
81
-     */
82
-    public function debug($message, array $context = [])
83
-    {
84
-        return $this->log(static::DEBUG, $message, $context);
85
-    }
86
-
87
-    /**
88
-     * System is unusable.
89
-     * @param mixed $message
90
-     * @param array $context
91
-     * @return static
92
-     */
93
-    public function emergency($message, array $context = [])
94
-    {
95
-        return $this->log(static::EMERGENCY, $message, $context);
96
-    }
97
-
98
-    /**
99
-     * Runtime errors that do not require immediate action but should typically be logged and monitored.
100
-     * @param mixed $message
101
-     * @param array $context
102
-     * @return static
103
-     */
104
-    public function error($message, array $context = [])
105
-    {
106
-        return $this->log(static::ERROR, $message, $context);
107
-    }
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function get()
113
-    {
114
-        return empty($this->log)
115
-            ? __('Console is empty', 'site-reviews')
116
-            : $this->log;
117
-    }
118
-
119
-    /**
120
-     * @return int
121
-     */
122
-    public function getLevel()
123
-    {
124
-        return intval(apply_filters('site-reviews/console/level', static::INFO));
125
-    }
126
-
127
-    /**
128
-     * @return array
129
-     */
130
-    public function getLevels()
131
-    {
132
-        $constants = (new ReflectionClass(__CLASS__))->getConstants();
133
-        return array_map('strtolower', array_flip($constants));
134
-    }
135
-
136
-    /**
137
-     * @return string
138
-     */
139
-    public function humanLevel()
140
-    {
141
-        $level = $this->getLevel();
142
-        return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level);
143
-    }
144
-
145
-    /**
146
-     * @param string|null $valueIfEmpty
147
-     * @return string
148
-     */
149
-    public function humanSize($valueIfEmpty = null)
150
-    {
151
-        $bytes = $this->size();
152
-        if (empty($bytes) && is_string($valueIfEmpty)) {
153
-            return $valueIfEmpty;
154
-        }
155
-        $exponent = floor(log(max($bytes, 1), 1024));
156
-        return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent];
157
-    }
158
-
159
-    /**
160
-     * Interesting events
161
-     * Example: User logs in, SQL logs.
162
-     * @param mixed $message
163
-     * @param array $context
164
-     * @return static
165
-     */
166
-    public function info($message, array $context = [])
167
-    {
168
-        return $this->log(static::INFO, $message, $context);
169
-    }
170
-
171
-    /**
172
-     * @param int $level
173
-     * @param mixed $message
174
-     * @param array $context
175
-     * @param string $backtraceLine
176
-     * @return static
177
-     */
178
-    public function log($level, $message, $context = [], $backtraceLine = '')
179
-    {
180
-        if (empty($backtraceLine)) {
181
-            $backtraceLine = $this->getBacktraceLine();
182
-        }
183
-        if ($this->canLogEntry($level, $backtraceLine)) {
184
-            $levelName = Arr::get($this->getLevels(), $level);
185
-            $context = Arr::consolidateArray($context);
186
-            $backtraceLine = $this->normalizeBacktraceLine($backtraceLine);
187
-            $message = $this->interpolate($message, $context);
188
-            $entry = $this->buildLogEntry($levelName, $message, $backtraceLine);
189
-            file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX);
190
-            apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed
191
-            $this->reset();
192
-        }
193
-        return $this;
194
-    }
195
-
196
-    /**
197
-     * @return void
198
-     */
199
-    public function logOnce()
200
-    {
201
-        $once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
202
-        $levels = $this->getLevels();
203
-        foreach ($once as $entry) {
204
-            $levelName = Arr::get($entry, 'level');
205
-            if (!in_array($levelName, $levels)) {
206
-                continue;
207
-            }
208
-            $level = Arr::get(array_flip($levels), $levelName);
209
-            $message = Arr::get($entry, 'message');
210
-            $backtraceLine = Arr::get($entry, 'backtrace');
211
-            $this->log($level, $message, [], $backtraceLine);
212
-        }
213
-        glsr()->{$this->logOnceKey} = [];
214
-    }
215
-
216
-    /**
217
-     * Normal but significant events.
218
-     * @param mixed $message
219
-     * @param array $context
220
-     * @return static
221
-     */
222
-    public function notice($message, array $context = [])
223
-    {
224
-        return $this->log(static::NOTICE, $message, $context);
225
-    }
226
-
227
-    /**
228
-     * @param string $levelName
229
-     * @param string $handle
230
-     * @param mixed $data
231
-     * @return void
232
-     */
233
-    public function once($levelName, $handle, $data)
234
-    {
235
-        $once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
236
-        $filtered = array_filter($once, function ($entry) use ($levelName, $handle) {
237
-            return Arr::get($entry, 'level') == $levelName
238
-                && Arr::get($entry, 'handle') == $handle;
239
-        });
240
-        if (!empty($filtered)) {
241
-            return;
242
-        }
243
-        $once[] = [
244
-            'backtrace' => $this->getBacktraceLineFromData($data),
245
-            'handle' => $handle,
246
-            'level' => $levelName,
247
-            'message' => '[RECURRING] '.$this->getMessageFromData($data),
248
-        ];
249
-        glsr()->{$this->logOnceKey} = $once;
250
-    }
251
-
252
-    /**
253
-     * @return int
254
-     */
255
-    public function size()
256
-    {
257
-        return file_exists($this->file)
258
-            ? filesize($this->file)
259
-            : 0;
260
-    }
261
-
262
-    /**
263
-     * Exceptional occurrences that are not errors
264
-     * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
265
-     * @param mixed $message
266
-     * @param array $context
267
-     * @return static
268
-     */
269
-    public function warning($message, array $context = [])
270
-    {
271
-        return $this->log(static::WARNING, $message, $context);
272
-    }
273
-
274
-    /**
275
-     * @param array $backtrace
276
-     * @param int $index
277
-     * @return string
278
-     */
279
-    protected function buildBacktraceLine($backtrace, $index)
280
-    {
281
-        return sprintf('%s:%s',
282
-            Arr::get($backtrace, $index.'.file'), // realpath
283
-            Arr::get($backtrace, $index.'.line')
284
-        );
285
-    }
286
-
287
-    /**
288
-     * @param string $levelName
289
-     * @param mixed $message
290
-     * @param string $backtraceLine
291
-     * @return string
292
-     */
293
-    protected function buildLogEntry($levelName, $message, $backtraceLine = '')
294
-    {
295
-        return sprintf('[%s] %s [%s] %s',
296
-            current_time('mysql'),
297
-            strtoupper($levelName),
298
-            $backtraceLine,
299
-            $message
300
-        );
301
-    }
302
-
303
-    /**
304
-     * @param int $level
305
-     * @return bool
306
-     */
307
-    protected function canLogEntry($level, $backtraceLine)
308
-    {
309
-        $levelExists = array_key_exists($level, $this->getLevels());
310
-        if (!Str::contains($backtraceLine, glsr()->path())) {
311
-            return $levelExists; // ignore level restriction if triggered outside of the plugin
312
-        }
313
-        return $levelExists && $level >= $this->getLevel();
314
-    }
315
-
316
-    /**
317
-     * @return void|string
318
-     */
319
-    protected function getBacktraceLine()
320
-    {
321
-        $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
322
-        $search = array_search('glsr_log', glsr_array_column($backtrace, 'function'));
323
-        if (false !== $search) {
324
-            return $this->buildBacktraceLine($backtrace, (int) $search);
325
-        }
326
-        $search = array_search('log', glsr_array_column($backtrace, 'function'));
327
-        if (false !== $search) {
328
-            $index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function')
329
-                ? $search + 4
330
-                : $search + 1;
331
-            return $this->buildBacktraceLine($backtrace, $index);
332
-        }
333
-        return 'Unknown';
334
-    }
335
-
336
-    /**
337
-     * @param mixed $data
338
-     * @return string
339
-     */
340
-    protected function getBacktraceLineFromData($data)
341
-    {
342
-        $backtrace = $data instanceof Throwable
343
-            ? $data->getTrace()
344
-            : debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
345
-        return $this->buildBacktraceLine($backtrace, 0);
346
-    }
347
-
348
-    /**
349
-     * @param mixed $data
350
-     * @return string
351
-     */
352
-    protected function getMessageFromData($data)
353
-    {
354
-        return $data instanceof Throwable
355
-            ? $this->normalizeThrowableMessage($data->getMessage())
356
-            : print_r($data, 1);
357
-    }
358
-
359
-    /**
360
-     * Interpolates context values into the message placeholders.
361
-     * @param mixed $message
362
-     * @param array $context
363
-     * @return string
364
-     */
365
-    protected function interpolate($message, $context = [])
366
-    {
367
-        if ($this->isObjectOrArray($message) || !is_array($context)) {
368
-            return print_r($message, true);
369
-        }
370
-        $replace = [];
371
-        foreach ($context as $key => $value) {
372
-            $replace['{'.$key.'}'] = $this->normalizeValue($value);
373
-        }
374
-        return strtr($message, $replace);
375
-    }
376
-
377
-    /**
378
-     * @param mixed $value
379
-     * @return bool
380
-     */
381
-    protected function isObjectOrArray($value)
382
-    {
383
-        return is_object($value) || is_array($value);
384
-    }
385
-
386
-    /**
387
-     * @param string $backtraceLine
388
-     * @return string
389
-     */
390
-    protected function normalizeBacktraceLine($backtraceLine)
391
-    {
392
-        $search = [
393
-            glsr()->path('plugin/'),
394
-            glsr()->path('plugin/', false),
395
-            trailingslashit(glsr()->path()),
396
-            trailingslashit(glsr()->path('', false)),
397
-            WP_CONTENT_DIR,
398
-            ABSPATH,
399
-        ];
400
-        return str_replace(array_unique($search), '', $backtraceLine);
401
-    }
402
-
403
-    /**
404
-     * @param string $message
405
-     * @return string
406
-     */
407
-    protected function normalizeThrowableMessage($message)
408
-    {
409
-        $calledIn = strpos($message, ', called in');
410
-        return false !== $calledIn
411
-            ? substr($message, 0, $calledIn)
412
-            : $message;
413
-    }
414
-
415
-    /**
416
-     * @param mixed $value
417
-     * @return string
418
-     */
419
-    protected function normalizeValue($value)
420
-    {
421
-        if ($value instanceof DateTime) {
422
-            $value = $value->format('Y-m-d H:i:s');
423
-        } elseif ($this->isObjectOrArray($value)) {
424
-            $value = json_encode($value);
425
-        }
426
-        return (string) $value;
427
-    }
428
-
429
-    /**
430
-     * @return void
431
-     */
432
-    protected function reset()
433
-    {
434
-        if ($this->size() <= pow(1024, 2) / 8) {
435
-            return;
436
-        }
437
-        $this->clear();
438
-        file_put_contents(
439
-            $this->file,
440
-            $this->buildLogEntry(
441
-                static::NOTICE,
442
-                __('Console was automatically cleared (128 KB maximum size)', 'site-reviews')
443
-            )
444
-        );
445
-    }
13
+	const DEBUG = 0;      // Detailed debug information
14
+	const INFO = 1;       // Interesting events
15
+	const NOTICE = 2;     // Normal but significant events
16
+	const WARNING = 4;    // Exceptional occurrences that are not errors
17
+	const ERROR = 8;      // Runtime errors that do not require immediate action
18
+	const CRITICAL = 16;  // Critical conditions
19
+	const ALERT = 32;     // Action must be taken immediately
20
+	const EMERGENCY = 64; // System is unusable
21
+
22
+	protected $file;
23
+	protected $log;
24
+	protected $logOnceKey = 'glsr_log_once';
25
+
26
+	public function __construct()
27
+	{
28
+		$this->file = glsr()->path('console.log');
29
+		$this->log = file_exists($this->file)
30
+			? file_get_contents($this->file)
31
+			: '';
32
+		$this->reset();
33
+	}
34
+
35
+	/**
36
+	 * @return string
37
+	 */
38
+	public function __toString()
39
+	{
40
+		return $this->get();
41
+	}
42
+
43
+	/**
44
+	 * Action must be taken immediately
45
+	 * Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
46
+	 * @param mixed $message
47
+	 * @param array $context
48
+	 * @return static
49
+	 */
50
+	public function alert($message, array $context = [])
51
+	{
52
+		return $this->log(static::ALERT, $message, $context);
53
+	}
54
+
55
+	/**
56
+	 * @return void
57
+	 */
58
+	public function clear()
59
+	{
60
+		$this->log = '';
61
+		file_put_contents($this->file, $this->log);
62
+	}
63
+
64
+	/**
65
+	 * Critical conditions
66
+	 * Example: Application component unavailable, unexpected exception.
67
+	 * @param mixed $message
68
+	 * @param array $context
69
+	 * @return static
70
+	 */
71
+	public function critical($message, array $context = [])
72
+	{
73
+		return $this->log(static::CRITICAL, $message, $context);
74
+	}
75
+
76
+	/**
77
+	 * Detailed debug information.
78
+	 * @param mixed $message
79
+	 * @param array $context
80
+	 * @return static
81
+	 */
82
+	public function debug($message, array $context = [])
83
+	{
84
+		return $this->log(static::DEBUG, $message, $context);
85
+	}
86
+
87
+	/**
88
+	 * System is unusable.
89
+	 * @param mixed $message
90
+	 * @param array $context
91
+	 * @return static
92
+	 */
93
+	public function emergency($message, array $context = [])
94
+	{
95
+		return $this->log(static::EMERGENCY, $message, $context);
96
+	}
97
+
98
+	/**
99
+	 * Runtime errors that do not require immediate action but should typically be logged and monitored.
100
+	 * @param mixed $message
101
+	 * @param array $context
102
+	 * @return static
103
+	 */
104
+	public function error($message, array $context = [])
105
+	{
106
+		return $this->log(static::ERROR, $message, $context);
107
+	}
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function get()
113
+	{
114
+		return empty($this->log)
115
+			? __('Console is empty', 'site-reviews')
116
+			: $this->log;
117
+	}
118
+
119
+	/**
120
+	 * @return int
121
+	 */
122
+	public function getLevel()
123
+	{
124
+		return intval(apply_filters('site-reviews/console/level', static::INFO));
125
+	}
126
+
127
+	/**
128
+	 * @return array
129
+	 */
130
+	public function getLevels()
131
+	{
132
+		$constants = (new ReflectionClass(__CLASS__))->getConstants();
133
+		return array_map('strtolower', array_flip($constants));
134
+	}
135
+
136
+	/**
137
+	 * @return string
138
+	 */
139
+	public function humanLevel()
140
+	{
141
+		$level = $this->getLevel();
142
+		return sprintf('%s (%d)', strtoupper(Arr::get($this->getLevels(), $level, 'unknown')), $level);
143
+	}
144
+
145
+	/**
146
+	 * @param string|null $valueIfEmpty
147
+	 * @return string
148
+	 */
149
+	public function humanSize($valueIfEmpty = null)
150
+	{
151
+		$bytes = $this->size();
152
+		if (empty($bytes) && is_string($valueIfEmpty)) {
153
+			return $valueIfEmpty;
154
+		}
155
+		$exponent = floor(log(max($bytes, 1), 1024));
156
+		return round($bytes / pow(1024, $exponent), 2).' '.['bytes', 'KB', 'MB', 'GB'][$exponent];
157
+	}
158
+
159
+	/**
160
+	 * Interesting events
161
+	 * Example: User logs in, SQL logs.
162
+	 * @param mixed $message
163
+	 * @param array $context
164
+	 * @return static
165
+	 */
166
+	public function info($message, array $context = [])
167
+	{
168
+		return $this->log(static::INFO, $message, $context);
169
+	}
170
+
171
+	/**
172
+	 * @param int $level
173
+	 * @param mixed $message
174
+	 * @param array $context
175
+	 * @param string $backtraceLine
176
+	 * @return static
177
+	 */
178
+	public function log($level, $message, $context = [], $backtraceLine = '')
179
+	{
180
+		if (empty($backtraceLine)) {
181
+			$backtraceLine = $this->getBacktraceLine();
182
+		}
183
+		if ($this->canLogEntry($level, $backtraceLine)) {
184
+			$levelName = Arr::get($this->getLevels(), $level);
185
+			$context = Arr::consolidateArray($context);
186
+			$backtraceLine = $this->normalizeBacktraceLine($backtraceLine);
187
+			$message = $this->interpolate($message, $context);
188
+			$entry = $this->buildLogEntry($levelName, $message, $backtraceLine);
189
+			file_put_contents($this->file, $entry.PHP_EOL, FILE_APPEND | LOCK_EX);
190
+			apply_filters('console', $message, $levelName, $backtraceLine); // Show in Blackbar plugin if installed
191
+			$this->reset();
192
+		}
193
+		return $this;
194
+	}
195
+
196
+	/**
197
+	 * @return void
198
+	 */
199
+	public function logOnce()
200
+	{
201
+		$once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
202
+		$levels = $this->getLevels();
203
+		foreach ($once as $entry) {
204
+			$levelName = Arr::get($entry, 'level');
205
+			if (!in_array($levelName, $levels)) {
206
+				continue;
207
+			}
208
+			$level = Arr::get(array_flip($levels), $levelName);
209
+			$message = Arr::get($entry, 'message');
210
+			$backtraceLine = Arr::get($entry, 'backtrace');
211
+			$this->log($level, $message, [], $backtraceLine);
212
+		}
213
+		glsr()->{$this->logOnceKey} = [];
214
+	}
215
+
216
+	/**
217
+	 * Normal but significant events.
218
+	 * @param mixed $message
219
+	 * @param array $context
220
+	 * @return static
221
+	 */
222
+	public function notice($message, array $context = [])
223
+	{
224
+		return $this->log(static::NOTICE, $message, $context);
225
+	}
226
+
227
+	/**
228
+	 * @param string $levelName
229
+	 * @param string $handle
230
+	 * @param mixed $data
231
+	 * @return void
232
+	 */
233
+	public function once($levelName, $handle, $data)
234
+	{
235
+		$once = Arr::consolidateArray(glsr()->{$this->logOnceKey});
236
+		$filtered = array_filter($once, function ($entry) use ($levelName, $handle) {
237
+			return Arr::get($entry, 'level') == $levelName
238
+				&& Arr::get($entry, 'handle') == $handle;
239
+		});
240
+		if (!empty($filtered)) {
241
+			return;
242
+		}
243
+		$once[] = [
244
+			'backtrace' => $this->getBacktraceLineFromData($data),
245
+			'handle' => $handle,
246
+			'level' => $levelName,
247
+			'message' => '[RECURRING] '.$this->getMessageFromData($data),
248
+		];
249
+		glsr()->{$this->logOnceKey} = $once;
250
+	}
251
+
252
+	/**
253
+	 * @return int
254
+	 */
255
+	public function size()
256
+	{
257
+		return file_exists($this->file)
258
+			? filesize($this->file)
259
+			: 0;
260
+	}
261
+
262
+	/**
263
+	 * Exceptional occurrences that are not errors
264
+	 * Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
265
+	 * @param mixed $message
266
+	 * @param array $context
267
+	 * @return static
268
+	 */
269
+	public function warning($message, array $context = [])
270
+	{
271
+		return $this->log(static::WARNING, $message, $context);
272
+	}
273
+
274
+	/**
275
+	 * @param array $backtrace
276
+	 * @param int $index
277
+	 * @return string
278
+	 */
279
+	protected function buildBacktraceLine($backtrace, $index)
280
+	{
281
+		return sprintf('%s:%s',
282
+			Arr::get($backtrace, $index.'.file'), // realpath
283
+			Arr::get($backtrace, $index.'.line')
284
+		);
285
+	}
286
+
287
+	/**
288
+	 * @param string $levelName
289
+	 * @param mixed $message
290
+	 * @param string $backtraceLine
291
+	 * @return string
292
+	 */
293
+	protected function buildLogEntry($levelName, $message, $backtraceLine = '')
294
+	{
295
+		return sprintf('[%s] %s [%s] %s',
296
+			current_time('mysql'),
297
+			strtoupper($levelName),
298
+			$backtraceLine,
299
+			$message
300
+		);
301
+	}
302
+
303
+	/**
304
+	 * @param int $level
305
+	 * @return bool
306
+	 */
307
+	protected function canLogEntry($level, $backtraceLine)
308
+	{
309
+		$levelExists = array_key_exists($level, $this->getLevels());
310
+		if (!Str::contains($backtraceLine, glsr()->path())) {
311
+			return $levelExists; // ignore level restriction if triggered outside of the plugin
312
+		}
313
+		return $levelExists && $level >= $this->getLevel();
314
+	}
315
+
316
+	/**
317
+	 * @return void|string
318
+	 */
319
+	protected function getBacktraceLine()
320
+	{
321
+		$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
322
+		$search = array_search('glsr_log', glsr_array_column($backtrace, 'function'));
323
+		if (false !== $search) {
324
+			return $this->buildBacktraceLine($backtrace, (int) $search);
325
+		}
326
+		$search = array_search('log', glsr_array_column($backtrace, 'function'));
327
+		if (false !== $search) {
328
+			$index = '{closure}' == Arr::get($backtrace, ($search + 2).'.function')
329
+				? $search + 4
330
+				: $search + 1;
331
+			return $this->buildBacktraceLine($backtrace, $index);
332
+		}
333
+		return 'Unknown';
334
+	}
335
+
336
+	/**
337
+	 * @param mixed $data
338
+	 * @return string
339
+	 */
340
+	protected function getBacktraceLineFromData($data)
341
+	{
342
+		$backtrace = $data instanceof Throwable
343
+			? $data->getTrace()
344
+			: debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
345
+		return $this->buildBacktraceLine($backtrace, 0);
346
+	}
347
+
348
+	/**
349
+	 * @param mixed $data
350
+	 * @return string
351
+	 */
352
+	protected function getMessageFromData($data)
353
+	{
354
+		return $data instanceof Throwable
355
+			? $this->normalizeThrowableMessage($data->getMessage())
356
+			: print_r($data, 1);
357
+	}
358
+
359
+	/**
360
+	 * Interpolates context values into the message placeholders.
361
+	 * @param mixed $message
362
+	 * @param array $context
363
+	 * @return string
364
+	 */
365
+	protected function interpolate($message, $context = [])
366
+	{
367
+		if ($this->isObjectOrArray($message) || !is_array($context)) {
368
+			return print_r($message, true);
369
+		}
370
+		$replace = [];
371
+		foreach ($context as $key => $value) {
372
+			$replace['{'.$key.'}'] = $this->normalizeValue($value);
373
+		}
374
+		return strtr($message, $replace);
375
+	}
376
+
377
+	/**
378
+	 * @param mixed $value
379
+	 * @return bool
380
+	 */
381
+	protected function isObjectOrArray($value)
382
+	{
383
+		return is_object($value) || is_array($value);
384
+	}
385
+
386
+	/**
387
+	 * @param string $backtraceLine
388
+	 * @return string
389
+	 */
390
+	protected function normalizeBacktraceLine($backtraceLine)
391
+	{
392
+		$search = [
393
+			glsr()->path('plugin/'),
394
+			glsr()->path('plugin/', false),
395
+			trailingslashit(glsr()->path()),
396
+			trailingslashit(glsr()->path('', false)),
397
+			WP_CONTENT_DIR,
398
+			ABSPATH,
399
+		];
400
+		return str_replace(array_unique($search), '', $backtraceLine);
401
+	}
402
+
403
+	/**
404
+	 * @param string $message
405
+	 * @return string
406
+	 */
407
+	protected function normalizeThrowableMessage($message)
408
+	{
409
+		$calledIn = strpos($message, ', called in');
410
+		return false !== $calledIn
411
+			? substr($message, 0, $calledIn)
412
+			: $message;
413
+	}
414
+
415
+	/**
416
+	 * @param mixed $value
417
+	 * @return string
418
+	 */
419
+	protected function normalizeValue($value)
420
+	{
421
+		if ($value instanceof DateTime) {
422
+			$value = $value->format('Y-m-d H:i:s');
423
+		} elseif ($this->isObjectOrArray($value)) {
424
+			$value = json_encode($value);
425
+		}
426
+		return (string) $value;
427
+	}
428
+
429
+	/**
430
+	 * @return void
431
+	 */
432
+	protected function reset()
433
+	{
434
+		if ($this->size() <= pow(1024, 2) / 8) {
435
+			return;
436
+		}
437
+		$this->clear();
438
+		file_put_contents(
439
+			$this->file,
440
+			$this->buildLogEntry(
441
+				static::NOTICE,
442
+				__('Console was automatically cleared (128 KB maximum size)', 'site-reviews')
443
+			)
444
+		);
445
+	}
446 446
 }
Please login to merge, or discard this patch.
deprecated.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -3,134 +3,134 @@
 block discarded – undo
3 3
 defined('WPINC') || die;
4 4
 
5 5
 if (apply_filters('site-reviews/support/deprecated/v4', true)) {
6
-    // Unprotected review meta has been deprecated
7
-    add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
8
-        $metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
9
-        if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
10
-            return $data;
11
-        }
12
-        glsr()->deprecated[] = sprintf(
13
-            'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
14
-            $metaKey
15
-        );
16
-        return get_post_meta($postId, '_'.$metaKey, $single);
17
-    }, 10, 4);
6
+	// Unprotected review meta has been deprecated
7
+	add_filter('get_post_metadata', function ($data, $postId, $metaKey, $single) {
8
+		$metaKeys = array_keys(glsr('Defaults\CreateReviewDefaults')->defaults());
9
+		if (!in_array($metaKey, $metaKeys) || glsr()->post_type != get_post_type($postId)) {
10
+			return $data;
11
+		}
12
+		glsr()->deprecated[] = sprintf(
13
+			'The "%1$s" meta_key has been deprecated for Reviews. Please use the protected "_%1$s" meta_key instead.',
14
+			$metaKey
15
+		);
16
+		return get_post_meta($postId, '_'.$metaKey, $single);
17
+	}, 10, 4);
18 18
 
19
-    // Modules/Html/Template.php
20
-    add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
21
-        $search = '{{ navigation }}';
22
-        if (false !== strpos($template, $search)) {
23
-            $context['navigation'] = $context['pagination'];
24
-            glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
25
-        }
26
-        return $context;
27
-    }, 10, 2);
19
+	// Modules/Html/Template.php
20
+	add_filter('site-reviews/interpolate/reviews', function ($context, $template) {
21
+		$search = '{{ navigation }}';
22
+		if (false !== strpos($template, $search)) {
23
+			$context['navigation'] = $context['pagination'];
24
+			glsr()->deprecated[] = 'The {{ navigation }} template key in "YOUR_THEME/site-reviews/reviews.php" has been deprecated. Please use the {{ pagination }} template key instead.';
25
+		}
26
+		return $context;
27
+	}, 10, 2);
28 28
 
29
-    // Database/ReviewManager.php
30
-    add_action('site-reviews/review/created', function ($review) {
31
-        if (has_action('site-reviews/local/review/create')) {
32
-            glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
33
-            do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
34
-        }
35
-    }, 9);
29
+	// Database/ReviewManager.php
30
+	add_action('site-reviews/review/created', function ($review) {
31
+		if (has_action('site-reviews/local/review/create')) {
32
+			glsr()->deprecated[] = 'The "site-reviews/local/review/create" hook has been deprecated. Please use the "site-reviews/review/created" hook instead.';
33
+			do_action('site-reviews/local/review/create', (array) get_post($review->ID), (array) $review, $review->ID);
34
+		}
35
+	}, 9);
36 36
 
37
-    // Handlers/CreateReview.php
38
-    add_action('site-reviews/review/submitted', function ($review) {
39
-        if (has_action('site-reviews/local/review/submitted')) {
40
-            glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
41
-            do_action('site-reviews/local/review/submitted', null, $review);
42
-        }
43
-        if (has_filter('site-reviews/local/review/submitted/message')) {
44
-            glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
45
-        }
46
-    }, 9);
37
+	// Handlers/CreateReview.php
38
+	add_action('site-reviews/review/submitted', function ($review) {
39
+		if (has_action('site-reviews/local/review/submitted')) {
40
+			glsr()->deprecated[] = 'The "site-reviews/local/review/submitted" hook has been deprecated. Please use the "site-reviews/review/submitted" hook instead.';
41
+			do_action('site-reviews/local/review/submitted', null, $review);
42
+		}
43
+		if (has_filter('site-reviews/local/review/submitted/message')) {
44
+			glsr()->deprecated[] = 'The "site-reviews/local/review/submitted/message" hook has been deprecated.';
45
+		}
46
+	}, 9);
47 47
 
48
-    // Database/ReviewManager.php
49
-    add_filter('site-reviews/create/review-values', function ($values, $command) {
50
-        if (has_filter('site-reviews/local/review')) {
51
-            glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
52
-            return apply_filters('site-reviews/local/review', $values, $command);
53
-        }
54
-        return $values;
55
-    }, 9, 2);
48
+	// Database/ReviewManager.php
49
+	add_filter('site-reviews/create/review-values', function ($values, $command) {
50
+		if (has_filter('site-reviews/local/review')) {
51
+			glsr()->deprecated[] = 'The "site-reviews/local/review" hook has been deprecated. Please use the "site-reviews/create/review-values" hook instead.';
52
+			return apply_filters('site-reviews/local/review', $values, $command);
53
+		}
54
+		return $values;
55
+	}, 9, 2);
56 56
 
57
-    // Handlers/EnqueuePublicAssets.php
58
-    add_filter('site-reviews/enqueue/public/localize', function ($variables) {
59
-        if (has_filter('site-reviews/enqueue/localize')) {
60
-            glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
61
-            return apply_filters('site-reviews/enqueue/localize', $variables);
62
-        }
63
-        return $variables;
64
-    }, 9);
57
+	// Handlers/EnqueuePublicAssets.php
58
+	add_filter('site-reviews/enqueue/public/localize', function ($variables) {
59
+		if (has_filter('site-reviews/enqueue/localize')) {
60
+			glsr()->deprecated[] = 'The "site-reviews/enqueue/localize" hook has been deprecated. Please use the "site-reviews/enqueue/public/localize" hook instead.';
61
+			return apply_filters('site-reviews/enqueue/localize', $variables);
62
+		}
63
+		return $variables;
64
+	}, 9);
65 65
 
66
-    // Modules/Rating.php
67
-    add_filter('site-reviews/rating/average', function ($average) {
68
-        if (has_filter('site-reviews/average/rating')) {
69
-            glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
70
-        }
71
-        return $average;
72
-    }, 9);
66
+	// Modules/Rating.php
67
+	add_filter('site-reviews/rating/average', function ($average) {
68
+		if (has_filter('site-reviews/average/rating')) {
69
+			glsr()->deprecated[] = 'The "site-reviews/average/rating" hook has been deprecated. Please use the "site-reviews/rating/average" hook instead.';
70
+		}
71
+		return $average;
72
+	}, 9);
73 73
 
74
-    // Modules/Rating.php
75
-    add_filter('site-reviews/rating/ranking', function ($ranking) {
76
-        if (has_filter('site-reviews/bayesian/ranking')) {
77
-            glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
78
-        }
79
-        return $ranking;
80
-    }, 9);
74
+	// Modules/Rating.php
75
+	add_filter('site-reviews/rating/ranking', function ($ranking) {
76
+		if (has_filter('site-reviews/bayesian/ranking')) {
77
+			glsr()->deprecated[] = 'The "site-reviews/bayesian/ranking" hook has been deprecated. Please use the "site-reviews/rating/ranking" hook instead.';
78
+		}
79
+		return $ranking;
80
+	}, 9);
81 81
 
82
-    // Modules/Html/Partials/SiteReviews.php
83
-    add_filter('site-reviews/review/build/after', function ($renderedFields) {
84
-        if (has_filter('site-reviews/reviews/review/text')) {
85
-            glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
86
-        }
87
-        if (has_filter('site-reviews/reviews/review/title')) {
88
-            glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
89
-        }
90
-        return $renderedFields;
91
-    }, 9);
82
+	// Modules/Html/Partials/SiteReviews.php
83
+	add_filter('site-reviews/review/build/after', function ($renderedFields) {
84
+		if (has_filter('site-reviews/reviews/review/text')) {
85
+			glsr()->deprecated[] = 'The "site-reviews/reviews/review/text" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
86
+		}
87
+		if (has_filter('site-reviews/reviews/review/title')) {
88
+			glsr()->deprecated[] = 'The "site-reviews/reviews/review/title" hook has been deprecated. Please use the "site-reviews/review/build/after" hook instead.';
89
+		}
90
+		return $renderedFields;
91
+	}, 9);
92 92
 
93
-    // Modules/Html/Partials/SiteReviews.php
94
-    add_filter('site-reviews/review/build/before', function ($review) {
95
-        if (has_filter('site-reviews/rendered/review')) {
96
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
97
-        }
98
-        if (has_filter('site-reviews/rendered/review/meta/order')) {
99
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
100
-        }
101
-        if (has_filter('site-reviews/rendered/review/order')) {
102
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
103
-        }
104
-        if (has_filter('site-reviews/rendered/review-form/login-register')) {
105
-            glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
106
-        }
107
-        if (has_filter('site-reviews/reviews/navigation_links')) {
108
-            glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
109
-        }
110
-        return $review;
111
-    }, 9);
93
+	// Modules/Html/Partials/SiteReviews.php
94
+	add_filter('site-reviews/review/build/before', function ($review) {
95
+		if (has_filter('site-reviews/rendered/review')) {
96
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review" hook has been deprecated. Please either use a custom "review.php" template (refer to the documentation), or use the "site-reviews/review/build/after" hook instead.';
97
+		}
98
+		if (has_filter('site-reviews/rendered/review/meta/order')) {
99
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review/meta/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
100
+		}
101
+		if (has_filter('site-reviews/rendered/review/order')) {
102
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review/order" hook has been deprecated. Please use a custom "review.php" template instead (refer to the documentation).';
103
+		}
104
+		if (has_filter('site-reviews/rendered/review-form/login-register')) {
105
+			glsr()->deprecated[] = 'The "site-reviews/rendered/review-form/login-register" hook has been deprecated. Please use a custom "login-register.php" template instead (refer to the documentation).';
106
+		}
107
+		if (has_filter('site-reviews/reviews/navigation_links')) {
108
+			glsr()->deprecated[] = 'The "site-reviews/reviews/navigation_links" hook has been deprecated. Please use a custom "pagination.php" template instead (refer to the documentation).';
109
+		}
110
+		return $review;
111
+	}, 9);
112 112
 
113
-    add_filter('site-reviews/validate/custom', function ($result, $request) {
114
-        if (has_filter('site-reviews/validate/review/submission')) {
115
-            glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.');
116
-            return apply_filters('site-reviews/validate/review/submission', $result, $request);
117
-        }
118
-        return $result;
119
-    }, 9, 2);
113
+	add_filter('site-reviews/validate/custom', function ($result, $request) {
114
+		if (has_filter('site-reviews/validate/review/submission')) {
115
+			glsr_log()->warning('The "site-reviews/validate/review/submission" hook has been deprecated. Please use the "site-reviews/validate/custom" hook instead.');
116
+			return apply_filters('site-reviews/validate/review/submission', $result, $request);
117
+		}
118
+		return $result;
119
+	}, 9, 2);
120 120
 
121
-    add_filter('site-reviews/views/file', function ($file, $view, $data) {
122
-        if (has_filter('site-reviews/addon/views/file')) {
123
-            glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
124
-            $file = apply_filters('site-reviews/addon/views/file', $file, $view, $data);
125
-        }
126
-        return $file;
127
-    }, 9, 3);
121
+	add_filter('site-reviews/views/file', function ($file, $view, $data) {
122
+		if (has_filter('site-reviews/addon/views/file')) {
123
+			glsr()->deprecated[] = 'The "site-reviews/addon/views/file" hook has been deprecated. Please use the "site-reviews/views/file" hook instead.';
124
+			$file = apply_filters('site-reviews/addon/views/file', $file, $view, $data);
125
+		}
126
+		return $file;
127
+	}, 9, 3);
128 128
 }
129 129
 
130 130
 add_action('wp_footer', function () {
131
-    $notices = array_keys(array_flip(glsr()->deprecated));
132
-    natsort($notices);
133
-    foreach ($notices as $notice) {
134
-        glsr_log()->warning($notice);
135
-    }
131
+	$notices = array_keys(array_flip(glsr()->deprecated));
132
+	natsort($notices);
133
+	foreach ($notices as $notice) {
134
+		glsr_log()->warning($notice);
135
+	}
136 136
 });
Please login to merge, or discard this patch.
plugin/Handlers/EnqueuePublicAssets.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -9,148 +9,148 @@
 block discarded – undo
9 9
 
10 10
 class EnqueuePublicAssets
11 11
 {
12
-    /**
13
-     * @return void
14
-     */
15
-    public function handle()
16
-    {
17
-        $this->enqueueAssets();
18
-        $this->enqueuePolyfillService();
19
-        $this->enqueueRecaptchaScript();
20
-        $this->inlineScript();
21
-        $this->inlineStyles();
22
-    }
12
+	/**
13
+	 * @return void
14
+	 */
15
+	public function handle()
16
+	{
17
+		$this->enqueueAssets();
18
+		$this->enqueuePolyfillService();
19
+		$this->enqueueRecaptchaScript();
20
+		$this->inlineScript();
21
+		$this->inlineStyles();
22
+	}
23 23
 
24
-    /**
25
-     * @return void
26
-     */
27
-    public function enqueueAssets()
28
-    {
29
-        if (apply_filters('site-reviews/assets/css', true)) {
30
-            wp_enqueue_style(
31
-                Application::ID,
32
-                $this->getStylesheet(),
33
-                [],
34
-                glsr()->version
35
-            );
36
-        }
37
-        if (apply_filters('site-reviews/assets/js', true)) {
38
-            $dependencies = apply_filters('site-reviews/assets/polyfill', true)
39
-                ? [Application::ID.'/polyfill']
40
-                : [];
41
-            $dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
42
-            wp_enqueue_script(
43
-                Application::ID,
44
-                glsr()->url('assets/scripts/'.Application::ID.'.js'),
45
-                $dependencies,
46
-                glsr()->version,
47
-                true
48
-            );
49
-        }
50
-    }
24
+	/**
25
+	 * @return void
26
+	 */
27
+	public function enqueueAssets()
28
+	{
29
+		if (apply_filters('site-reviews/assets/css', true)) {
30
+			wp_enqueue_style(
31
+				Application::ID,
32
+				$this->getStylesheet(),
33
+				[],
34
+				glsr()->version
35
+			);
36
+		}
37
+		if (apply_filters('site-reviews/assets/js', true)) {
38
+			$dependencies = apply_filters('site-reviews/assets/polyfill', true)
39
+				? [Application::ID.'/polyfill']
40
+				: [];
41
+			$dependencies = apply_filters('site-reviews/enqueue/public/dependencies', $dependencies);
42
+			wp_enqueue_script(
43
+				Application::ID,
44
+				glsr()->url('assets/scripts/'.Application::ID.'.js'),
45
+				$dependencies,
46
+				glsr()->version,
47
+				true
48
+			);
49
+		}
50
+	}
51 51
 
52
-    /**
53
-     * @return void
54
-     */
55
-    public function enqueuePolyfillService()
56
-    {
57
-        if (!apply_filters('site-reviews/assets/polyfill', true)) {
58
-            return;
59
-        }
60
-        wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
61
-            'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62
-            'flags' => 'gated',
63
-        ], 'https://polyfill.io/v3/polyfill.min.js'));
64
-    }
52
+	/**
53
+	 * @return void
54
+	 */
55
+	public function enqueuePolyfillService()
56
+	{
57
+		if (!apply_filters('site-reviews/assets/polyfill', true)) {
58
+			return;
59
+		}
60
+		wp_enqueue_script(Application::ID.'/polyfill', add_query_arg([
61
+			'features' => 'Array.prototype.findIndex,CustomEvent,Element.prototype.closest,Element.prototype.dataset,Event,XMLHttpRequest,MutationObserver',
62
+			'flags' => 'gated',
63
+		], 'https://polyfill.io/v3/polyfill.min.js'));
64
+	}
65 65
 
66
-    /**
67
-     * @return void
68
-     */
69
-    public function enqueueRecaptchaScript()
70
-    {
71
-        // wpforms-recaptcha
72
-        // google-recaptcha
73
-        // nf-google-recaptcha
74
-        if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
75
-            return;
76
-        }
77
-        $language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
-        wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
79
-            'hl' => $language,
80
-            'render' => 'explicit',
81
-        ], 'https://www.google.com/recaptcha/api.js'));
82
-    }
66
+	/**
67
+	 * @return void
68
+	 */
69
+	public function enqueueRecaptchaScript()
70
+	{
71
+		// wpforms-recaptcha
72
+		// google-recaptcha
73
+		// nf-google-recaptcha
74
+		if (!glsr(OptionManager::class)->isRecaptchaEnabled()) {
75
+			return;
76
+		}
77
+		$language = apply_filters('site-reviews/recaptcha/language', get_locale());
78
+		wp_enqueue_script(Application::ID.'/google-recaptcha', add_query_arg([
79
+			'hl' => $language,
80
+			'render' => 'explicit',
81
+		], 'https://www.google.com/recaptcha/api.js'));
82
+	}
83 83
 
84
-    /**
85
-     * @return void
86
-     */
87
-    public function inlineScript()
88
-    {
89
-        $variables = [
90
-            'action' => Application::PREFIX.'action',
91
-            'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
-            'ajaxurl' => admin_url('admin-ajax.php'),
93
-            'nameprefix' => Application::ID,
94
-            'validationconfig' => glsr(Style::class)->validation,
95
-            'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
96
-        ];
97
-        $variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
98
-        wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
99
-    }
84
+	/**
85
+	 * @return void
86
+	 */
87
+	public function inlineScript()
88
+	{
89
+		$variables = [
90
+			'action' => Application::PREFIX.'action',
91
+			'ajaxpagination' => $this->getFixedSelectorsForPagination(),
92
+			'ajaxurl' => admin_url('admin-ajax.php'),
93
+			'nameprefix' => Application::ID,
94
+			'validationconfig' => glsr(Style::class)->validation,
95
+			'validationstrings' => glsr(ValidationStringsDefaults::class)->defaults(),
96
+		];
97
+		$variables = apply_filters('site-reviews/enqueue/public/localize', $variables);
98
+		wp_add_inline_script(Application::ID, $this->buildInlineScript($variables), 'before');
99
+	}
100 100
 
101
-    /**
102
-     * @return void
103
-     */
104
-    public function inlineStyles()
105
-    {
106
-        $inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
107
-        if (!apply_filters('site-reviews/assets/css', true)) {
108
-            return;
109
-        }
110
-        if (!file_exists($inlineStylesheetPath)) {
111
-            glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
112
-            return;
113
-        }
114
-        $inlineStylesheetValues = glsr()->config('inline-styles');
115
-        $stylesheet = str_replace(
116
-            array_keys($inlineStylesheetValues),
117
-            array_values($inlineStylesheetValues),
118
-            file_get_contents($inlineStylesheetPath)
119
-        );
120
-        wp_add_inline_style(Application::ID, $stylesheet);
121
-    }
101
+	/**
102
+	 * @return void
103
+	 */
104
+	public function inlineStyles()
105
+	{
106
+		$inlineStylesheetPath = glsr()->path('assets/styles/inline-styles.css');
107
+		if (!apply_filters('site-reviews/assets/css', true)) {
108
+			return;
109
+		}
110
+		if (!file_exists($inlineStylesheetPath)) {
111
+			glsr_log()->error('Inline stylesheet is missing: '.$inlineStylesheetPath);
112
+			return;
113
+		}
114
+		$inlineStylesheetValues = glsr()->config('inline-styles');
115
+		$stylesheet = str_replace(
116
+			array_keys($inlineStylesheetValues),
117
+			array_values($inlineStylesheetValues),
118
+			file_get_contents($inlineStylesheetPath)
119
+		);
120
+		wp_add_inline_style(Application::ID, $stylesheet);
121
+	}
122 122
 
123
-    /**
124
-     * @return string
125
-     */
126
-    protected function buildInlineScript(array $variables)
127
-    {
128
-        $script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
129
-        foreach ($variables as $key => $value) {
130
-            $script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
131
-        }
132
-        $pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
133
-        $optimizedScript = preg_replace($pattern, '$1$2', $script);
134
-        return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
135
-    }
123
+	/**
124
+	 * @return string
125
+	 */
126
+	protected function buildInlineScript(array $variables)
127
+	{
128
+		$script = 'window.hasOwnProperty("GLSR")||(window.GLSR={});';
129
+		foreach ($variables as $key => $value) {
130
+			$script.= sprintf('GLSR.%s=%s;', $key, json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
131
+		}
132
+		$pattern = '/\"([^ \-\"]+)\"(:[{\[\"])/'; // removes unnecessary quotes surrounding object keys
133
+		$optimizedScript = preg_replace($pattern, '$1$2', $script);
134
+		return apply_filters('site-reviews/enqueue/public/inline-script', $optimizedScript, $script, $variables);
135
+	}
136 136
 
137
-    /**
138
-     * @return array
139
-     */
140
-    protected function getFixedSelectorsForPagination()
141
-    {
142
-        $selectors = ['#wpadminbar', '.site-navigation-fixed'];
143
-        return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
144
-    }
137
+	/**
138
+	 * @return array
139
+	 */
140
+	protected function getFixedSelectorsForPagination()
141
+	{
142
+		$selectors = ['#wpadminbar', '.site-navigation-fixed'];
143
+		return apply_filters('site-reviews/enqueue/public/localize/ajax-pagination', $selectors);
144
+	}
145 145
 
146
-    /**
147
-     * @return string
148
-     */
149
-    protected function getStylesheet()
150
-    {
151
-        $currentStyle = glsr(Style::class)->style;
152
-        return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
153
-            ? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
154
-            : glsr()->url('assets/styles/'.Application::ID.'.css');
155
-    }
146
+	/**
147
+	 * @return string
148
+	 */
149
+	protected function getStylesheet()
150
+	{
151
+		$currentStyle = glsr(Style::class)->style;
152
+		return file_exists(glsr()->path('assets/styles/custom/'.$currentStyle.'.css'))
153
+			? glsr()->url('assets/styles/custom/'.$currentStyle.'.css')
154
+			: glsr()->url('assets/styles/'.Application::ID.'.css');
155
+	}
156 156
 }
Please login to merge, or discard this patch.