Passed
Push — master ( ccb079...7906b4 )
by Paul
04:39
created
plugin/Modules/Migrations/Migrate_3_0_0.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -7,160 +7,160 @@
 block discarded – undo
7 7
 
8 8
 class Migrate_3_0_0
9 9
 {
10
-    const MAPPED_SETTINGS = [
11
-        'settings.general.notification' => 'settings.general.notifications', // array
12
-        'settings.general.notification_email' => 'settings.general.notification_email',
13
-        'settings.general.notification_message' => 'settings.general.notification_message',
14
-        'settings.general.require.approval' => 'settings.general.require.approval',
15
-        'settings.general.require.login' => 'settings.general.require.login',
16
-        'settings.general.require.login_register' => 'settings.general.require.login_register',
17
-        'settings.general.webhook_url' => 'settings.general.notification_slack',
18
-        'settings.reviews-form.akismet' => 'settings.submissions.akismet',
19
-        'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action',
20
-        'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries',
21
-        'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration',
22
-        'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key',
23
-        'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position',
24
-        'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret',
25
-        'settings.reviews-form.required' => 'settings.submissions.required', // array
26
-        'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links',
27
-        'settings.reviews.avatars.enabled' => 'settings.reviews.avatars',
28
-        'settings.reviews.date.custom' => 'settings.reviews.date.custom',
29
-        'settings.reviews.date.format' => 'settings.reviews.date.format',
30
-        'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts',
31
-        'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length',
32
-        'settings.reviews.schema.address' => 'settings.schema.address',
33
-        'settings.reviews.schema.description.custom' => 'settings.schema.description.custom',
34
-        'settings.reviews.schema.description.default' => 'settings.schema.description.default',
35
-        'settings.reviews.schema.highprice' => 'settings.schema.highprice',
36
-        'settings.reviews.schema.image.custom' => 'settings.schema.image.custom',
37
-        'settings.reviews.schema.image.default' => 'settings.schema.image.default',
38
-        'settings.reviews.schema.lowprice' => 'settings.schema.lowprice',
39
-        'settings.reviews.schema.name.custom' => 'settings.schema.name.custom',
40
-        'settings.reviews.schema.name.default' => 'settings.schema.name.default',
41
-        'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency',
42
-        'settings.reviews.schema.pricerange' => 'settings.schema.pricerange',
43
-        'settings.reviews.schema.telephone' => 'settings.schema.telephone',
44
-        'settings.reviews.schema.type.custom' => 'settings.schema.type.custom',
45
-        'settings.reviews.schema.type.default' => 'settings.schema.type.default',
46
-        'settings.reviews.schema.url.custom' => 'settings.schema.url.custom',
47
-        'settings.reviews.schema.url.default' => 'settings.schema.url.default',
48
-        'version' => 'version_upgraded_from',
49
-    ];
10
+	const MAPPED_SETTINGS = [
11
+		'settings.general.notification' => 'settings.general.notifications', // array
12
+		'settings.general.notification_email' => 'settings.general.notification_email',
13
+		'settings.general.notification_message' => 'settings.general.notification_message',
14
+		'settings.general.require.approval' => 'settings.general.require.approval',
15
+		'settings.general.require.login' => 'settings.general.require.login',
16
+		'settings.general.require.login_register' => 'settings.general.require.login_register',
17
+		'settings.general.webhook_url' => 'settings.general.notification_slack',
18
+		'settings.reviews-form.akismet' => 'settings.submissions.akismet',
19
+		'settings.reviews-form.blacklist.action' => 'settings.submissions.blacklist.action',
20
+		'settings.reviews-form.blacklist.entries' => 'settings.submissions.blacklist.entries',
21
+		'settings.reviews-form.recaptcha.integration' => 'settings.submissions.recaptcha.integration',
22
+		'settings.reviews-form.recaptcha.key' => 'settings.submissions.recaptcha.key',
23
+		'settings.reviews-form.recaptcha.position' => 'settings.submissions.recaptcha.position',
24
+		'settings.reviews-form.recaptcha.secret' => 'settings.submissions.recaptcha.secret',
25
+		'settings.reviews-form.required' => 'settings.submissions.required', // array
26
+		'settings.reviews.assigned_links.enabled' => 'settings.reviews.assigned_links',
27
+		'settings.reviews.avatars.enabled' => 'settings.reviews.avatars',
28
+		'settings.reviews.date.custom' => 'settings.reviews.date.custom',
29
+		'settings.reviews.date.format' => 'settings.reviews.date.format',
30
+		'settings.reviews.excerpt.enabled' => 'settings.reviews.excerpts',
31
+		'settings.reviews.excerpt.length' => 'settings.reviews.excerpts_length',
32
+		'settings.reviews.schema.address' => 'settings.schema.address',
33
+		'settings.reviews.schema.description.custom' => 'settings.schema.description.custom',
34
+		'settings.reviews.schema.description.default' => 'settings.schema.description.default',
35
+		'settings.reviews.schema.highprice' => 'settings.schema.highprice',
36
+		'settings.reviews.schema.image.custom' => 'settings.schema.image.custom',
37
+		'settings.reviews.schema.image.default' => 'settings.schema.image.default',
38
+		'settings.reviews.schema.lowprice' => 'settings.schema.lowprice',
39
+		'settings.reviews.schema.name.custom' => 'settings.schema.name.custom',
40
+		'settings.reviews.schema.name.default' => 'settings.schema.name.default',
41
+		'settings.reviews.schema.pricecurrency' => 'settings.schema.pricecurrency',
42
+		'settings.reviews.schema.pricerange' => 'settings.schema.pricerange',
43
+		'settings.reviews.schema.telephone' => 'settings.schema.telephone',
44
+		'settings.reviews.schema.type.custom' => 'settings.schema.type.custom',
45
+		'settings.reviews.schema.type.default' => 'settings.schema.type.default',
46
+		'settings.reviews.schema.url.custom' => 'settings.schema.url.custom',
47
+		'settings.reviews.schema.url.default' => 'settings.schema.url.default',
48
+		'version' => 'version_upgraded_from',
49
+	];
50 50
 
51
-    /**
52
-     * @var array
53
-     */
54
-    protected $newSettings;
51
+	/**
52
+	 * @var array
53
+	 */
54
+	protected $newSettings;
55 55
 
56
-    /**
57
-     * @var array
58
-     */
59
-    protected $oldSettings;
56
+	/**
57
+	 * @var array
58
+	 */
59
+	protected $oldSettings;
60 60
 
61
-    /**
62
-     * @return void
63
-     */
64
-    public function migrateSettings()
65
-    {
66
-        $this->newSettings = $this->getNewSettings();
67
-        $this->oldSettings = $this->getOldSettings();
68
-        if (empty($this->oldSettings) || empty($this->newSettings)) {
69
-            return;
70
-        }
71
-        foreach (static::MAPPED_SETTINGS as $old => $new) {
72
-            if (empty($this->oldSettings[$old])) {
73
-                continue;
74
-            }
75
-            $this->newSettings[$new] = $this->oldSettings[$old];
76
-        }
77
-        $this->migrateNotificationSettings();
78
-        $this->migrateRecaptchaSettings();
79
-        $this->migrateRequiredSettings();
80
-        $oldSettings = Arr::convertFromDotNotation($this->oldSettings);
81
-        $newSettings = Arr::convertFromDotNotation($this->newSettings);
82
-        if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) {
83
-            $newSettings['settings']['strings'] = $oldSettings['settings']['strings'];
84
-        }
85
-        update_option(OptionManager::databaseKey(3), $newSettings);
86
-    }
61
+	/**
62
+	 * @return void
63
+	 */
64
+	public function migrateSettings()
65
+	{
66
+		$this->newSettings = $this->getNewSettings();
67
+		$this->oldSettings = $this->getOldSettings();
68
+		if (empty($this->oldSettings) || empty($this->newSettings)) {
69
+			return;
70
+		}
71
+		foreach (static::MAPPED_SETTINGS as $old => $new) {
72
+			if (empty($this->oldSettings[$old])) {
73
+				continue;
74
+			}
75
+			$this->newSettings[$new] = $this->oldSettings[$old];
76
+		}
77
+		$this->migrateNotificationSettings();
78
+		$this->migrateRecaptchaSettings();
79
+		$this->migrateRequiredSettings();
80
+		$oldSettings = Arr::convertFromDotNotation($this->oldSettings);
81
+		$newSettings = Arr::convertFromDotNotation($this->newSettings);
82
+		if (isset($oldSettings['settings']['strings']) && is_array($oldSettings['settings']['strings'])) {
83
+			$newSettings['settings']['strings'] = $oldSettings['settings']['strings'];
84
+		}
85
+		update_option(OptionManager::databaseKey(3), $newSettings);
86
+	}
87 87
 
88
-    /**
89
-     * @return void
90
-     */
91
-    public function run()
92
-    {
93
-        $this->migrateSettings();
94
-    }
88
+	/**
89
+	 * @return void
90
+	 */
91
+	public function run()
92
+	{
93
+		$this->migrateSettings();
94
+	}
95 95
 
96
-    /**
97
-     * @return array
98
-     */
99
-    protected function getNewSettings()
100
-    {
101
-        return  Arr::flatten(Arr::consolidate(OptionManager::databaseKey(3)));
102
-    }
96
+	/**
97
+	 * @return array
98
+	 */
99
+	protected function getNewSettings()
100
+	{
101
+		return  Arr::flatten(Arr::consolidate(OptionManager::databaseKey(3)));
102
+	}
103 103
 
104
-    /**
105
-     * @return array
106
-     */
107
-    protected function getOldSettings()
108
-    {
109
-        $defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), '');
110
-        $settings = Arr::consolidate(get_option(OptionManager::databaseKey(2)));
111
-        $settings = Arr::flatten($settings);
112
-        return !empty($settings)
113
-            ? wp_parse_args($settings, $defaults)
114
-            : [];
115
-    }
104
+	/**
105
+	 * @return array
106
+	 */
107
+	protected function getOldSettings()
108
+	{
109
+		$defaults = array_fill_keys(array_keys(static::MAPPED_SETTINGS), '');
110
+		$settings = Arr::consolidate(get_option(OptionManager::databaseKey(2)));
111
+		$settings = Arr::flatten($settings);
112
+		return !empty($settings)
113
+			? wp_parse_args($settings, $defaults)
114
+			: [];
115
+	}
116 116
 
117
-    /**
118
-     * @return void
119
-     */
120
-    protected function migrateNotificationSettings()
121
-    {
122
-        $notifications = [
123
-            'custom' => 'custom',
124
-            'default' => 'admin',
125
-            'webhook' => 'slack',
126
-        ];
127
-        $this->newSettings['settings.general.notifications'] = [];
128
-        foreach ($notifications as $old => $new) {
129
-            if ($this->oldSettings['settings.general.notification'] != $old) {
130
-                continue;
131
-            }
132
-            $this->newSettings['settings.general.notifications'][] = $new;
133
-        }
134
-    }
117
+	/**
118
+	 * @return void
119
+	 */
120
+	protected function migrateNotificationSettings()
121
+	{
122
+		$notifications = [
123
+			'custom' => 'custom',
124
+			'default' => 'admin',
125
+			'webhook' => 'slack',
126
+		];
127
+		$this->newSettings['settings.general.notifications'] = [];
128
+		foreach ($notifications as $old => $new) {
129
+			if ($this->oldSettings['settings.general.notification'] != $old) {
130
+				continue;
131
+			}
132
+			$this->newSettings['settings.general.notifications'][] = $new;
133
+		}
134
+	}
135 135
 
136
-    /**
137
-     * @return void
138
-     */
139
-    protected function migrateRecaptchaSettings()
140
-    {
141
-        $recaptcha = [
142
-            'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'],
143
-            'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'],
144
-            'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'],
145
-        ];
146
-        if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) {
147
-            $this->newSettings['settings.submissions.recaptcha.integration'] = 'all';
148
-        }
149
-        if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) {
150
-            $recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha);
151
-        }
152
-        $this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey'];
153
-        $this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey'];
154
-        $this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition'];
155
-    }
136
+	/**
137
+	 * @return void
138
+	 */
139
+	protected function migrateRecaptchaSettings()
140
+	{
141
+		$recaptcha = [
142
+			'BadgePosition' => $this->oldSettings['settings.reviews-form.recaptcha.position'],
143
+			'SecretKey' => $this->oldSettings['settings.reviews-form.recaptcha.secret'],
144
+			'SiteKey' => $this->oldSettings['settings.reviews-form.recaptcha.key'],
145
+		];
146
+		if (in_array($this->oldSettings['settings.reviews-form.recaptcha.integration'], ['custom', 'invisible-recaptcha'])) {
147
+			$this->newSettings['settings.submissions.recaptcha.integration'] = 'all';
148
+		}
149
+		if ('invisible-recaptcha' == $this->oldSettings['settings.reviews-form.recaptcha.integration']) {
150
+			$recaptcha = wp_parse_args((array) get_site_option('ic-settings', [], false), $recaptcha);
151
+		}
152
+		$this->newSettings['settings.submissions.recaptcha.key'] = $recaptcha['SiteKey'];
153
+		$this->newSettings['settings.submissions.recaptcha.secret'] = $recaptcha['SecretKey'];
154
+		$this->newSettings['settings.submissions.recaptcha.position'] = $recaptcha['BadgePosition'];
155
+	}
156 156
 
157
-    /**
158
-     * @return void
159
-     */
160
-    protected function migrateRequiredSettings()
161
-    {
162
-        $this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']);
163
-        $this->newSettings['settings.submissions.required'][] = 'rating';
164
-        $this->newSettings['settings.submissions.required'][] = 'terms';
165
-    }
157
+	/**
158
+	 * @return void
159
+	 */
160
+	protected function migrateRequiredSettings()
161
+	{
162
+		$this->newSettings['settings.submissions.required'] = array_filter((array) $this->oldSettings['settings.reviews-form.required']);
163
+		$this->newSettings['settings.submissions.required'][] = 'rating';
164
+		$this->newSettings['settings.submissions.required'][] = 'terms';
165
+	}
166 166
 }
Please login to merge, or discard this patch.
plugin/Modules/Migrations/Migrate_4_6_0.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -8,84 +8,84 @@
 block discarded – undo
8 8
 
9 9
 class Migrate_4_6_0
10 10
 {
11
-    /**
12
-     * @return void
13
-     */
14
-    public function migrateSidebarWidgets()
15
-    {
16
-        $sidebars = get_option('sidebars_widgets');
17
-        if ($this->widgetsExist($sidebars)) {
18
-            $sidebars = $this->updateWidgetNames($sidebars);
19
-            update_option('sidebars_widgets', $sidebars);
20
-        }
21
-    }
11
+	/**
12
+	 * @return void
13
+	 */
14
+	public function migrateSidebarWidgets()
15
+	{
16
+		$sidebars = get_option('sidebars_widgets');
17
+		if ($this->widgetsExist($sidebars)) {
18
+			$sidebars = $this->updateWidgetNames($sidebars);
19
+			update_option('sidebars_widgets', $sidebars);
20
+		}
21
+	}
22 22
 
23
-    /**
24
-     * @return void
25
-     */
26
-    public function migrateThemeModWidgets()
27
-    {
28
-        $themes = $this->queryThemeMods();
29
-        foreach ($themes as $theme) {
30
-            $themeMod = get_option($theme);
31
-            $sidebars = Arr::get($themeMod, 'sidebars_widgets.data');
32
-            if ($this->widgetsExist($sidebars)) {
33
-                $themeMod['sidebars_widgets']['data'] = $this->updateWidgetNames($sidebars);
34
-                update_option($theme, $themeMod);
35
-            }
36
-        }
37
-    }
23
+	/**
24
+	 * @return void
25
+	 */
26
+	public function migrateThemeModWidgets()
27
+	{
28
+		$themes = $this->queryThemeMods();
29
+		foreach ($themes as $theme) {
30
+			$themeMod = get_option($theme);
31
+			$sidebars = Arr::get($themeMod, 'sidebars_widgets.data');
32
+			if ($this->widgetsExist($sidebars)) {
33
+				$themeMod['sidebars_widgets']['data'] = $this->updateWidgetNames($sidebars);
34
+				update_option($theme, $themeMod);
35
+			}
36
+		}
37
+	}
38 38
 
39
-    /**
40
-     * @return void
41
-     */
42
-    public function run()
43
-    {
44
-        $this->migrateSidebarWidgets();
45
-        $this->migrateThemeModWidgets();
46
-    }
39
+	/**
40
+	 * @return void
41
+	 */
42
+	public function run()
43
+	{
44
+		$this->migrateSidebarWidgets();
45
+		$this->migrateThemeModWidgets();
46
+	}
47 47
 
48
-    /**
49
-     * @return array
50
-     */
51
-    protected function queryThemeMods()
52
-    {
53
-        global $wpdb;
54
-        return $wpdb->get_col("
48
+	/**
49
+	 * @return array
50
+	 */
51
+	protected function queryThemeMods()
52
+	{
53
+		global $wpdb;
54
+		return $wpdb->get_col("
55 55
             SELECT option_name 
56 56
             FROM {$wpdb->options} 
57 57
             WHERE option_name LIKE '%theme_mods_%'
58 58
         ");
59
-    }
59
+	}
60 60
 
61
-    /**
62
-     * @param array $sidebars
63
-     * @return array
64
-     */
65
-    protected function updateWidgetNames(array $sidebars)
66
-    {
67
-        array_walk($sidebars, function(&$widgets) {
68
-            array_walk($widgets, function(&$widget) {
69
-                if (Str::startsWith(Application::ID.'_', $widget)) {
70
-                    $widget = Str::replaceFirst(Application::ID.'_', Application::PREFIX, $widget);
71
-                }
72
-            });
73
-        });
74
-        return $sidebars;
75
-    }
61
+	/**
62
+	 * @param array $sidebars
63
+	 * @return array
64
+	 */
65
+	protected function updateWidgetNames(array $sidebars)
66
+	{
67
+		array_walk($sidebars, function(&$widgets) {
68
+			array_walk($widgets, function(&$widget) {
69
+				if (Str::startsWith(Application::ID.'_', $widget)) {
70
+					$widget = Str::replaceFirst(Application::ID.'_', Application::PREFIX, $widget);
71
+				}
72
+			});
73
+		});
74
+		return $sidebars;
75
+	}
76 76
 
77
-    /**
78
-     * @param array $sidebars
79
-     * @return bool
80
-     */
81
-    protected function widgetsExist($sidebars)
82
-    {
83
-        $widgets = call_user_func_array('array_merge', array_filter(Arr::consolidate($sidebars), 'is_array'));
84
-        foreach ($widgets as $widget) {
85
-            if (Str::startsWith(Application::ID.'_', $widget)) {
86
-                return true;
87
-            }
88
-        }
89
-        return false;
90
-    }
77
+	/**
78
+	 * @param array $sidebars
79
+	 * @return bool
80
+	 */
81
+	protected function widgetsExist($sidebars)
82
+	{
83
+		$widgets = call_user_func_array('array_merge', array_filter(Arr::consolidate($sidebars), 'is_array'));
84
+		foreach ($widgets as $widget) {
85
+			if (Str::startsWith(Application::ID.'_', $widget)) {
86
+				return true;
87
+			}
88
+		}
89
+		return false;
90
+	}
91 91
 }
Please login to merge, or discard this patch.
plugin/Modules/Style.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -12,144 +12,144 @@
 block discarded – undo
12 12
 
13 13
 class Style
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    public $fields;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	public $fields;
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    public $style;
20
+	/**
21
+	 * @var string
22
+	 */
23
+	public $style;
24 24
 
25
-    /**
26
-     * @var array
27
-     */
28
-    public $pagination;
25
+	/**
26
+	 * @var array
27
+	 */
28
+	public $pagination;
29 29
 
30
-    /**
31
-     * @var array
32
-     */
33
-    public $validation;
30
+	/**
31
+	 * @var array
32
+	 */
33
+	public $validation;
34 34
 
35
-    public function __construct()
36
-    {
37
-        $this->style = glsr(OptionManager::class)->get('settings.general.style', 'default');
38
-        $this->setConfig();
39
-    }
35
+	public function __construct()
36
+	{
37
+		$this->style = glsr(OptionManager::class)->get('settings.general.style', 'default');
38
+		$this->setConfig();
39
+	}
40 40
 
41
-    /**
42
-     * @param string $view
43
-     * @return string
44
-     */
45
-    public function filterView($view)
46
-    {
47
-        $styledViews = apply_filters('site-reviews/style/views', [
48
-            'templates/form/field',
49
-            'templates/form/response',
50
-            'templates/form/submit-button',
51
-            'templates/reviews-form',
52
-        ]);
53
-        if (!preg_match('('.implode('|', $styledViews).')', $view)) {
54
-            return $view;
55
-        }
56
-        $views = $this->generatePossibleViews($view);
57
-        foreach ($views as $possibleView) {
58
-            if (!file_exists(glsr()->file($possibleView))) {
59
-                continue;
60
-            }
61
-            return Str::removePrefix('views/', $possibleView);
62
-        }
63
-        return $view;
64
-    }
41
+	/**
42
+	 * @param string $view
43
+	 * @return string
44
+	 */
45
+	public function filterView($view)
46
+	{
47
+		$styledViews = apply_filters('site-reviews/style/views', [
48
+			'templates/form/field',
49
+			'templates/form/response',
50
+			'templates/form/submit-button',
51
+			'templates/reviews-form',
52
+		]);
53
+		if (!preg_match('('.implode('|', $styledViews).')', $view)) {
54
+			return $view;
55
+		}
56
+		$views = $this->generatePossibleViews($view);
57
+		foreach ($views as $possibleView) {
58
+			if (!file_exists(glsr()->file($possibleView))) {
59
+				continue;
60
+			}
61
+			return Str::removePrefix('views/', $possibleView);
62
+		}
63
+		return $view;
64
+	}
65 65
 
66
-    /**
67
-     * @return string
68
-     */
69
-    public function get()
70
-    {
71
-        return apply_filters('site-reviews/style', $this->style);
72
-    }
66
+	/**
67
+	 * @return string
68
+	 */
69
+	public function get()
70
+	{
71
+		return apply_filters('site-reviews/style', $this->style);
72
+	}
73 73
 
74
-    /**
75
-     * @return array
76
-     */
77
-    public function setConfig()
78
-    {
79
-        $config = shortcode_atts(
80
-            array_fill_keys(['fields', 'pagination', 'validation'], []),
81
-            glsr()->config('styles/'.$this->style)
82
-        );
83
-        $this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']);
84
-        $this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']);
85
-        $this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']);
86
-    }
74
+	/**
75
+	 * @return array
76
+	 */
77
+	public function setConfig()
78
+	{
79
+		$config = shortcode_atts(
80
+			array_fill_keys(['fields', 'pagination', 'validation'], []),
81
+			glsr()->config('styles/'.$this->style)
82
+		);
83
+		$this->fields = glsr(StyleFieldsDefaults::class)->restrict($config['fields']);
84
+		$this->pagination = glsr(PaginationDefaults::class)->restrict($config['pagination']);
85
+		$this->validation = glsr(StyleValidationDefaults::class)->restrict($config['validation']);
86
+	}
87 87
 
88
-    /**
89
-     * @return void
90
-     */
91
-    public function modifyField(Builder $instance)
92
-    {
93
-        if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) {
94
-            return;
95
-        }
96
-        call_user_func_array([$this, 'customize'], [$instance]);
97
-    }
88
+	/**
89
+	 * @return void
90
+	 */
91
+	public function modifyField(Builder $instance)
92
+	{
93
+		if (!$this->isPublicInstance($instance) || empty(array_filter($this->fields))) {
94
+			return;
95
+		}
96
+		call_user_func_array([$this, 'customize'], [$instance]);
97
+	}
98 98
 
99
-    /**
100
-     * @return array
101
-     */
102
-    public function paginationArgs(array $args)
103
-    {
104
-        return wp_parse_args($args, $this->pagination);
105
-    }
99
+	/**
100
+	 * @return array
101
+	 */
102
+	public function paginationArgs(array $args)
103
+	{
104
+		return wp_parse_args($args, $this->pagination);
105
+	}
106 106
 
107
-    /**
108
-     * @return void
109
-     */
110
-    protected function customize(Builder $instance)
111
-    {
112
-        if (!array_key_exists($instance->tag, $this->fields)) {
113
-            return;
114
-        }
115
-        $args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], ''));
116
-        $key = $instance->tag.'_'.$args['type'];
117
-        $classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag));
118
-        $instance->args['class'] = trim($args['class'].' '.$classes);
119
-        do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]);
120
-    }
107
+	/**
108
+	 * @return void
109
+	 */
110
+	protected function customize(Builder $instance)
111
+	{
112
+		if (!array_key_exists($instance->tag, $this->fields)) {
113
+			return;
114
+		}
115
+		$args = wp_parse_args($instance->args, array_fill_keys(['class', 'type'], ''));
116
+		$key = $instance->tag.'_'.$args['type'];
117
+		$classes = Arr::get($this->fields, $key, Arr::get($this->fields, $instance->tag));
118
+		$instance->args['class'] = trim($args['class'].' '.$classes);
119
+		do_action_ref_array('site-reviews/customize/'.$this->style, [$instance]);
120
+	}
121 121
 
122
-    /**
123
-     * @param string $view
124
-     * @return array
125
-     */
126
-    protected function generatePossibleViews($view)
127
-    {
128
-        $basename = basename($view);
129
-        $basepath = rtrim($view, $basename);
130
-        $customPath = 'views/partials/styles/'.$this->style.'/';
131
-        $parts = explode('_', $basename);
132
-        $views = [
133
-            $customPath.$basename,
134
-            $customPath.$parts[0],
135
-            $view,
136
-            $basepath.$parts[0],
137
-        ];
138
-        return array_filter($views);
139
-    }
122
+	/**
123
+	 * @param string $view
124
+	 * @return array
125
+	 */
126
+	protected function generatePossibleViews($view)
127
+	{
128
+		$basename = basename($view);
129
+		$basepath = rtrim($view, $basename);
130
+		$customPath = 'views/partials/styles/'.$this->style.'/';
131
+		$parts = explode('_', $basename);
132
+		$views = [
133
+			$customPath.$basename,
134
+			$customPath.$parts[0],
135
+			$view,
136
+			$basepath.$parts[0],
137
+		];
138
+		return array_filter($views);
139
+	}
140 140
 
141
-    /**
142
-     * @return bool
143
-     */
144
-    protected function isPublicInstance(Builder $instance)
145
-    {
146
-        $args = wp_parse_args($instance->args, [
147
-            'is_public' => false,
148
-            'is_raw' => false,
149
-        ]);
150
-        if (is_admin() || !$args['is_public'] || $args['is_raw']) {
151
-            return false;
152
-        }
153
-        return true;
154
-    }
141
+	/**
142
+	 * @return bool
143
+	 */
144
+	protected function isPublicInstance(Builder $instance)
145
+	{
146
+		$args = wp_parse_args($instance->args, [
147
+			'is_public' => false,
148
+			'is_raw' => false,
149
+		]);
150
+		if (is_admin() || !$args['is_public'] || $args['is_raw']) {
151
+			return false;
152
+		}
153
+		return true;
154
+	}
155 155
 }
Please login to merge, or discard this patch.
plugin/Modules/Migrate.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -10,135 +10,135 @@
 block discarded – undo
10 10
 
11 11
 class Migrate
12 12
 {
13
-    /**
14
-     * @var string
15
-     */
16
-    public $currentVersion;
13
+	/**
14
+	 * @var string
15
+	 */
16
+	public $currentVersion;
17 17
 
18
-    /**
19
-     * @var string
20
-     */
21
-    public $transientKey;
18
+	/**
19
+	 * @var string
20
+	 */
21
+	public $transientKey;
22 22
 
23
-    public function __construct()
24
-    {
25
-        $this->currentVersion = $this->getCurrentVersion();
26
-        $this->transientKey = Application::PREFIX.'migrations';
27
-    }
23
+	public function __construct()
24
+	{
25
+		$this->currentVersion = $this->getCurrentVersion();
26
+		$this->transientKey = Application::PREFIX.'migrations';
27
+	}
28 28
 
29
-    /**
30
-     * @return bool
31
-     */
32
-    public function isMigrationNeeded()
33
-    {
34
-        $transient = get_transient($this->transientKey);
35
-        if (false === $transient || !isset($transient[glsr()->version])) {
36
-            $transient = [
37
-                glsr()->version => !empty($this->getNewMigrationFiles()),
38
-            ];
39
-            set_transient($this->transientKey, $transient);
40
-        }
41
-        return Helper::castToBool($transient[glsr()->version]);
42
-    }
29
+	/**
30
+	 * @return bool
31
+	 */
32
+	public function isMigrationNeeded()
33
+	{
34
+		$transient = get_transient($this->transientKey);
35
+		if (false === $transient || !isset($transient[glsr()->version])) {
36
+			$transient = [
37
+				glsr()->version => !empty($this->getNewMigrationFiles()),
38
+			];
39
+			set_transient($this->transientKey, $transient);
40
+		}
41
+		return Helper::castToBool($transient[glsr()->version]);
42
+	}
43 43
 
44
-    /**
45
-     * @return bool
46
-     */
47
-    public function run()
48
-    {
49
-        return $this->runMigrations($this->getNewMigrationFiles());
50
-    }
44
+	/**
45
+	 * @return bool
46
+	 */
47
+	public function run()
48
+	{
49
+		return $this->runMigrations($this->getNewMigrationFiles());
50
+	}
51 51
 
52
-    /**
53
-     * @return bool
54
-     */
55
-    public function runAll()
56
-    {
57
-        return $this->runMigrations($this->getMigrationFiles());
58
-    }
52
+	/**
53
+	 * @return bool
54
+	 */
55
+	public function runAll()
56
+	{
57
+		return $this->runMigrations($this->getMigrationFiles());
58
+	}
59 59
 
60
-    /**
61
-     * @return string
62
-     */
63
-    protected function getCurrentVersion()
64
-    {
65
-        $fallback = '0.0.0';
66
-        $majorVersions = [4, 3, 2, 1];
67
-        foreach ($majorVersions as $majorVersion) {
68
-            $settings = get_option(OptionManager::databaseKey($majorVersion));
69
-            $version = Arr::get($settings, 'version', $fallback);
70
-            if (Helper::isGreaterThan($version, $fallback)) {
71
-                return $version;
72
-            }
73
-        }
74
-        return $fallback;
75
-    }
60
+	/**
61
+	 * @return string
62
+	 */
63
+	protected function getCurrentVersion()
64
+	{
65
+		$fallback = '0.0.0';
66
+		$majorVersions = [4, 3, 2, 1];
67
+		foreach ($majorVersions as $majorVersion) {
68
+			$settings = get_option(OptionManager::databaseKey($majorVersion));
69
+			$version = Arr::get($settings, 'version', $fallback);
70
+			if (Helper::isGreaterThan($version, $fallback)) {
71
+				return $version;
72
+			}
73
+		}
74
+		return $fallback;
75
+	}
76 76
 
77
-    /**
78
-     * @return array
79
-     */
80
-    protected function getMigrationFiles()
81
-    {
82
-        $files = [];
83
-        $dir = glsr()->path('plugin/Modules/Migrations');
84
-        if (is_dir($dir)) {
85
-            $iterator = new DirectoryIterator($dir);
86
-            foreach ($iterator as $fileinfo) {
87
-                if ($fileinfo->isFile()) {
88
-                    $files[] = $fileinfo->getFilename();
89
-                }
90
-            }
91
-            natsort($files);
92
-        }
93
-        return $files;
94
-    }
77
+	/**
78
+	 * @return array
79
+	 */
80
+	protected function getMigrationFiles()
81
+	{
82
+		$files = [];
83
+		$dir = glsr()->path('plugin/Modules/Migrations');
84
+		if (is_dir($dir)) {
85
+			$iterator = new DirectoryIterator($dir);
86
+			foreach ($iterator as $fileinfo) {
87
+				if ($fileinfo->isFile()) {
88
+					$files[] = $fileinfo->getFilename();
89
+				}
90
+			}
91
+			natsort($files);
92
+		}
93
+		return $files;
94
+	}
95 95
 
96
-    /**
97
-     * @return array
98
-     */
99
-    protected function getNewMigrationFiles()
100
-    {
101
-        $files = $this->getMigrationFiles();
102
-        foreach ($files as $index => $file) {
103
-            $className = str_replace('.php', '', $file);
104
-            $migrationVersion = str_replace(['Migrate_', '_'], ['', '.'], $className);
105
-            $suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions
106
-            if (Helper::isGreaterThanOrEqual($this->currentVersion, $migrationVersion.$suffix)) {
107
-                unset($files[$index]);
108
-            }
109
-        }
110
-        return $files;
111
-    }
96
+	/**
97
+	 * @return array
98
+	 */
99
+	protected function getNewMigrationFiles()
100
+	{
101
+		$files = $this->getMigrationFiles();
102
+		foreach ($files as $index => $file) {
103
+			$className = str_replace('.php', '', $file);
104
+			$migrationVersion = str_replace(['Migrate_', '_'], ['', '.'], $className);
105
+			$suffix = preg_replace('/[\d.]+(.+)?/', '${1}', glsr()->version); // allow alpha/beta versions
106
+			if (Helper::isGreaterThanOrEqual($this->currentVersion, $migrationVersion.$suffix)) {
107
+				unset($files[$index]);
108
+			}
109
+		}
110
+		return $files;
111
+	}
112 112
 
113
-    /**
114
-     * @return bool
115
-     */
116
-    protected function runMigrations(array $files)
117
-    {
118
-        if (empty($files)) {
119
-            return false;
120
-        }
121
-        array_walk($files, function ($file) {
122
-            $className = str_replace('.php', '', $file);
123
-            glsr('Modules\\Migrations\\'.$className)->run();
124
-            $versionMigrated = str_replace(['Migrate_', '_'], ['v','.'], $className);
125
-            glsr_log()->debug('migration completed for '.$versionMigrated);
126
-        });
127
-        if ($this->currentVersion !== glsr()->version) {
128
-            $this->updateVersionFrom($this->currentVersion);
129
-        }
130
-        glsr(OptionManager::class)->set('last_migration_run', current_time('timestamp'));
131
-        delete_transient($this->transientKey);
132
-        return true;
133
-    }
113
+	/**
114
+	 * @return bool
115
+	 */
116
+	protected function runMigrations(array $files)
117
+	{
118
+		if (empty($files)) {
119
+			return false;
120
+		}
121
+		array_walk($files, function ($file) {
122
+			$className = str_replace('.php', '', $file);
123
+			glsr('Modules\\Migrations\\'.$className)->run();
124
+			$versionMigrated = str_replace(['Migrate_', '_'], ['v','.'], $className);
125
+			glsr_log()->debug('migration completed for '.$versionMigrated);
126
+		});
127
+		if ($this->currentVersion !== glsr()->version) {
128
+			$this->updateVersionFrom($this->currentVersion);
129
+		}
130
+		glsr(OptionManager::class)->set('last_migration_run', current_time('timestamp'));
131
+		delete_transient($this->transientKey);
132
+		return true;
133
+	}
134 134
 
135
-    /**
136
-     * @param string $previousVersion
137
-     * @return void
138
-     */
139
-    protected function updateVersionFrom($previousVersion)
140
-    {
141
-        glsr(OptionManager::class)->set('version', glsr()->version);
142
-        glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion);
143
-    }
135
+	/**
136
+	 * @param string $previousVersion
137
+	 * @return void
138
+	 */
139
+	protected function updateVersionFrom($previousVersion)
140
+	{
141
+		glsr(OptionManager::class)->set('version', glsr()->version);
142
+		glsr(OptionManager::class)->set('version_upgraded_from', $previousVersion);
143
+	}
144 144
 }
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::consolidate($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::consolidate(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::consolidate(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::consolidate($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::consolidate(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::consolidate(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.
plugin/Application.php 1 patch
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -18,357 +18,357 @@
 block discarded – undo
18 18
  */
19 19
 final class Application extends Container
20 20
 {
21
-    const CAPABILITY = 'edit_others_posts';
22
-    const CRON_EVENT = 'site-reviews/schedule/session/purge';
23
-    const ID = 'site-reviews';
24
-    const PAGED_QUERY_VAR = 'reviews-page';
25
-    const POST_TYPE = 'site-review';
26
-    const PREFIX = 'glsr_';
27
-    const TAXONOMY = 'site-review-category';
21
+	const CAPABILITY = 'edit_others_posts';
22
+	const CRON_EVENT = 'site-reviews/schedule/session/purge';
23
+	const ID = 'site-reviews';
24
+	const PAGED_QUERY_VAR = 'reviews-page';
25
+	const POST_TYPE = 'site-review';
26
+	const PREFIX = 'glsr_';
27
+	const TAXONOMY = 'site-review-category';
28 28
 
29
-    public $addons = [];
30
-    public $defaults;
31
-    public $deprecated = [];
32
-    public $file;
33
-    public $languages;
34
-    public $mceShortcodes = []; //defined elsewhere
35
-    public $name;
36
-    public $postTypeColumns = []; // defined elsewhere
37
-    public $reviewTypes;
38
-    public $schemas = []; //defined elsewhere
39
-    public $version;
29
+	public $addons = [];
30
+	public $defaults;
31
+	public $deprecated = [];
32
+	public $file;
33
+	public $languages;
34
+	public $mceShortcodes = []; //defined elsewhere
35
+	public $name;
36
+	public $postTypeColumns = []; // defined elsewhere
37
+	public $reviewTypes;
38
+	public $schemas = []; //defined elsewhere
39
+	public $version;
40 40
 
41
-    public function __construct()
42
-    {
43
-        static::$instance = $this;
44
-        $this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName());
45
-        $plugin = get_file_data($this->file, [
46
-            'languages' => 'Domain Path',
47
-            'name' => 'Plugin Name',
48
-            'version' => 'Version',
49
-        ], 'plugin');
50
-        array_walk($plugin, function ($value, $key) {
51
-            $this->$key = $value;
52
-        });
53
-    }
41
+	public function __construct()
42
+	{
43
+		static::$instance = $this;
44
+		$this->file = str_replace('plugin/Application', static::ID, (new ReflectionClass($this))->getFileName());
45
+		$plugin = get_file_data($this->file, [
46
+			'languages' => 'Domain Path',
47
+			'name' => 'Plugin Name',
48
+			'version' => 'Version',
49
+		], 'plugin');
50
+		array_walk($plugin, function ($value, $key) {
51
+			$this->$key = $value;
52
+		});
53
+	}
54 54
 
55
-    /**
56
-     * @return void
57
-     */
58
-    public function activate()
59
-    {
60
-        $this->scheduleCronJob();
61
-        add_option(static::ID.'activated', true);
62
-    }
55
+	/**
56
+	 * @return void
57
+	 */
58
+	public function activate()
59
+	{
60
+		$this->scheduleCronJob();
61
+		add_option(static::ID.'activated', true);
62
+	}
63 63
 
64
-    /**
65
-     * @param string $view
66
-     * @return string
67
-     */
68
-    public function build($view, array $data = [])
69
-    {
70
-        ob_start();
71
-        $this->render($view, $data);
72
-        return ob_get_clean();
73
-    }
64
+	/**
65
+	 * @param string $view
66
+	 * @return string
67
+	 */
68
+	public function build($view, array $data = [])
69
+	{
70
+		ob_start();
71
+		$this->render($view, $data);
72
+		return ob_get_clean();
73
+	}
74 74
 
75
-    /**
76
-     * @param string $capability
77
-     * @return bool
78
-     */
79
-    public function can($capability)
80
-    {
81
-        return $this->make(Role::class)->can($capability);
82
-    }
75
+	/**
76
+	 * @param string $capability
77
+	 * @return bool
78
+	 */
79
+	public function can($capability)
80
+	{
81
+		return $this->make(Role::class)->can($capability);
82
+	}
83 83
 
84
-    /**
85
-     * @return void
86
-     */
87
-    public function catchFatalError()
88
-    {
89
-        $error = error_get_last();
90
-        if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) {
91
-            return;
92
-        }
93
-        glsr_log()->error($error['message']);
94
-    }
84
+	/**
85
+	 * @return void
86
+	 */
87
+	public function catchFatalError()
88
+	{
89
+		$error = error_get_last();
90
+		if (E_ERROR !== $error['type'] || !Str::contains($error['message'], $this->path())) {
91
+			return;
92
+		}
93
+		glsr_log()->error($error['message']);
94
+	}
95 95
 
96
-    /**
97
-     * @param string $name
98
-     * @return array
99
-     */
100
-    public function config($name)
101
-    {
102
-        $path = apply_filters('site-reviews/config', 'config/'.$name.'.php');
103
-        $configFile = $this->path($path);
104
-        $config = file_exists($configFile)
105
-            ? include $configFile
106
-            : [];
107
-        return apply_filters('site-reviews/config/'.$name, $config);
108
-    }
96
+	/**
97
+	 * @param string $name
98
+	 * @return array
99
+	 */
100
+	public function config($name)
101
+	{
102
+		$path = apply_filters('site-reviews/config', 'config/'.$name.'.php');
103
+		$configFile = $this->path($path);
104
+		$config = file_exists($configFile)
105
+			? include $configFile
106
+			: [];
107
+		return apply_filters('site-reviews/config/'.$name, $config);
108
+	}
109 109
 
110
-    /**
111
-     * @param string $property
112
-     * @return string
113
-     */
114
-    public function constant($property, $className = 'static')
115
-    {
116
-        $constant = $className.'::'.$property;
117
-        return defined($constant)
118
-            ? apply_filters('site-reviews/const/'.$property, constant($constant))
119
-            : '';
120
-    }
110
+	/**
111
+	 * @param string $property
112
+	 * @return string
113
+	 */
114
+	public function constant($property, $className = 'static')
115
+	{
116
+		$constant = $className.'::'.$property;
117
+		return defined($constant)
118
+			? apply_filters('site-reviews/const/'.$property, constant($constant))
119
+			: '';
120
+	}
121 121
 
122
-    /**
123
-     * @return void
124
-     */
125
-    public function deactivate()
126
-    {
127
-        $this->unscheduleCronJob();
128
-    }
122
+	/**
123
+	 * @return void
124
+	 */
125
+	public function deactivate()
126
+	{
127
+		$this->unscheduleCronJob();
128
+	}
129 129
 
130
-    /**
131
-     * @param string $view
132
-     * @return void|string
133
-     */
134
-    public function file($view)
135
-    {
136
-        $view.= '.php';
137
-        $filePaths = [];
138
-        if (Str::startsWith('templates/', $view)) {
139
-            $filePaths[] = $this->themePath(Str::removePrefix('templates/', $view));
140
-        }
141
-        $filePaths[] = $this->path($view);
142
-        $filePaths[] = $this->path('views/'.$view);
143
-        foreach ($filePaths as $file) {
144
-            if (!file_exists($file)) {
145
-                continue;
146
-            }
147
-            return $file;
148
-        }
149
-    }
130
+	/**
131
+	 * @param string $view
132
+	 * @return void|string
133
+	 */
134
+	public function file($view)
135
+	{
136
+		$view.= '.php';
137
+		$filePaths = [];
138
+		if (Str::startsWith('templates/', $view)) {
139
+			$filePaths[] = $this->themePath(Str::removePrefix('templates/', $view));
140
+		}
141
+		$filePaths[] = $this->path($view);
142
+		$filePaths[] = $this->path('views/'.$view);
143
+		foreach ($filePaths as $file) {
144
+			if (!file_exists($file)) {
145
+				continue;
146
+			}
147
+			return $file;
148
+		}
149
+	}
150 150
 
151
-    /**
152
-     * @return array
153
-     */
154
-    public function getDefaults()
155
-    {
156
-        if (empty($this->defaults)) {
157
-            $this->defaults = $this->make(DefaultsManager::class)->get();
158
-        }
159
-        return apply_filters('site-reviews/get/defaults', $this->defaults);
160
-    }
151
+	/**
152
+	 * @return array
153
+	 */
154
+	public function getDefaults()
155
+	{
156
+		if (empty($this->defaults)) {
157
+			$this->defaults = $this->make(DefaultsManager::class)->get();
158
+		}
159
+		return apply_filters('site-reviews/get/defaults', $this->defaults);
160
+	}
161 161
 
162
-    /**
163
-     * @param string $page
164
-     * @param string $tab
165
-     * @return string
166
-     */
167
-    public function getPermission($page = '', $tab = 'index')
168
-    {
169
-        $fallback = 'edit_posts';
170
-        $permissions = [
171
-            'addons' => 'install_plugins',
172
-            'documentation' => [
173
-                'faq' => 'edit_others_posts',
174
-                'functions' => 'manage_options',
175
-                'hooks' => 'edit_others_posts',
176
-                'index' => 'edit_posts',
177
-                'support' => 'edit_others_posts',
178
-            ],
179
-            'settings' => 'manage_options',
180
-            'tools' => [
181
-                'console' => 'edit_others_posts',
182
-                'general' => 'edit_others_posts',
183
-                'index' => 'edit_others_posts',
184
-                'sync' => 'manage_options',
185
-                'system-info' => 'edit_others_posts',
186
-            ]
187
-        ];
188
-        $permission = Arr::get($permissions, $page, $fallback);
189
-        if (is_array($permission)) {
190
-            $permission = Arr::get($permission, $tab, $fallback);
191
-        }
192
-        return empty($permission) || !is_string($permission)
193
-            ? $fallback
194
-            : $permission;
195
-    }
162
+	/**
163
+	 * @param string $page
164
+	 * @param string $tab
165
+	 * @return string
166
+	 */
167
+	public function getPermission($page = '', $tab = 'index')
168
+	{
169
+		$fallback = 'edit_posts';
170
+		$permissions = [
171
+			'addons' => 'install_plugins',
172
+			'documentation' => [
173
+				'faq' => 'edit_others_posts',
174
+				'functions' => 'manage_options',
175
+				'hooks' => 'edit_others_posts',
176
+				'index' => 'edit_posts',
177
+				'support' => 'edit_others_posts',
178
+			],
179
+			'settings' => 'manage_options',
180
+			'tools' => [
181
+				'console' => 'edit_others_posts',
182
+				'general' => 'edit_others_posts',
183
+				'index' => 'edit_others_posts',
184
+				'sync' => 'manage_options',
185
+				'system-info' => 'edit_others_posts',
186
+			]
187
+		];
188
+		$permission = Arr::get($permissions, $page, $fallback);
189
+		if (is_array($permission)) {
190
+			$permission = Arr::get($permission, $tab, $fallback);
191
+		}
192
+		return empty($permission) || !is_string($permission)
193
+			? $fallback
194
+			: $permission;
195
+	}
196 196
 
197
-    /**
198
-     * @param string $page
199
-     * @param string $tab
200
-     * @return bool
201
-     */
202
-    public function hasPermission($page = '', $tab = 'index')
203
-    {
204
-        $isAdmin = $this->isAdmin();
205
-        return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab)));
206
-    }
197
+	/**
198
+	 * @param string $page
199
+	 * @param string $tab
200
+	 * @return bool
201
+	 */
202
+	public function hasPermission($page = '', $tab = 'index')
203
+	{
204
+		$isAdmin = $this->isAdmin();
205
+		return !$isAdmin || ($isAdmin && $this->can($this->getPermission($page, $tab)));
206
+	}
207 207
 
208
-    /**
209
-     * @return void
210
-     */
211
-    public function init()
212
-    {
213
-        $this->make(Actions::class)->run();
214
-        $this->make(Filters::class)->run();
215
-    }
208
+	/**
209
+	 * @return void
210
+	 */
211
+	public function init()
212
+	{
213
+		$this->make(Actions::class)->run();
214
+		$this->make(Filters::class)->run();
215
+	}
216 216
 
217
-    /**
218
-     * @return bool
219
-     */
220
-    public function isAdmin()
221
-    {
222
-        return is_admin() && !wp_doing_ajax();
223
-    }
217
+	/**
218
+	 * @return bool
219
+	 */
220
+	public function isAdmin()
221
+	{
222
+		return is_admin() && !wp_doing_ajax();
223
+	}
224 224
 
225
-    /**
226
-     * @param string $file
227
-     * @return string
228
-     */
229
-    public function path($file = '', $realpath = true)
230
-    {
231
-        $path = plugin_dir_path($this->file);
232
-        if (!$realpath) {
233
-            $path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file));
234
-        }
235
-        $path = trailingslashit($path).ltrim(trim($file), '/');
236
-        return apply_filters('site-reviews/path', $path, $file);
237
-    }
225
+	/**
226
+	 * @param string $file
227
+	 * @return string
228
+	 */
229
+	public function path($file = '', $realpath = true)
230
+	{
231
+		$path = plugin_dir_path($this->file);
232
+		if (!$realpath) {
233
+			$path = trailingslashit(WP_PLUGIN_DIR).basename(dirname($this->file));
234
+		}
235
+		$path = trailingslashit($path).ltrim(trim($file), '/');
236
+		return apply_filters('site-reviews/path', $path, $file);
237
+	}
238 238
 
239
-    /**
240
-     * @param object $addon
241
-     * @return void
242
-     */
243
-    public function register($addon)
244
-    {
245
-        try {
246
-            $reflection = new \ReflectionClass($addon);
247
-            if ($id = $reflection->getConstant('ID')) {
248
-                $this->addons[] = $id;
249
-                $this->bind($id, $addon);
250
-                $addon->init();
251
-            }
252
-        } catch(\ReflectionException $e) {
253
-            glsr_log()->error('Attempted to register an invalid addon.');
254
-        }
255
-    }
239
+	/**
240
+	 * @param object $addon
241
+	 * @return void
242
+	 */
243
+	public function register($addon)
244
+	{
245
+		try {
246
+			$reflection = new \ReflectionClass($addon);
247
+			if ($id = $reflection->getConstant('ID')) {
248
+				$this->addons[] = $id;
249
+				$this->bind($id, $addon);
250
+				$addon->init();
251
+			}
252
+		} catch(\ReflectionException $e) {
253
+			glsr_log()->error('Attempted to register an invalid addon.');
254
+		}
255
+	}
256 256
 
257
-    /**
258
-     * @return void
259
-     */
260
-    public function registerAddons()
261
-    {
262
-        do_action('site-reviews/addon/register', $this);
263
-    }
257
+	/**
258
+	 * @return void
259
+	 */
260
+	public function registerAddons()
261
+	{
262
+		do_action('site-reviews/addon/register', $this);
263
+	}
264 264
 
265
-    /**
266
-     * @return void
267
-     */
268
-    public function registerLanguages()
269
-    {
270
-        load_plugin_textdomain(static::ID, false,
271
-            trailingslashit(plugin_basename($this->path()).'/'.$this->languages)
272
-        );
273
-    }
265
+	/**
266
+	 * @return void
267
+	 */
268
+	public function registerLanguages()
269
+	{
270
+		load_plugin_textdomain(static::ID, false,
271
+			trailingslashit(plugin_basename($this->path()).'/'.$this->languages)
272
+		);
273
+	}
274 274
 
275
-    /**
276
-     * @return void
277
-     */
278
-    public function registerReviewTypes()
279
-    {
280
-        $types = apply_filters('site-reviews/addon/types', []);
281
-        $this->reviewTypes = wp_parse_args($types, [
282
-            'local' => __('Local', 'site-reviews'),
283
-        ]);
284
-    }
275
+	/**
276
+	 * @return void
277
+	 */
278
+	public function registerReviewTypes()
279
+	{
280
+		$types = apply_filters('site-reviews/addon/types', []);
281
+		$this->reviewTypes = wp_parse_args($types, [
282
+			'local' => __('Local', 'site-reviews'),
283
+		]);
284
+	}
285 285
 
286
-    /**
287
-     * @param string $view
288
-     * @return void
289
-     */
290
-    public function render($view, array $data = [])
291
-    {
292
-        $view = apply_filters('site-reviews/render/view', $view, $data);
293
-        $file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data);
294
-        if (!file_exists($file)) {
295
-            glsr_log()->error(sprintf('File not found: (%s) %s', $view, $file));
296
-            return;
297
-        }
298
-        $data = apply_filters('site-reviews/views/data', $data, $view);
299
-        extract($data);
300
-        include $file;
301
-    }
286
+	/**
287
+	 * @param string $view
288
+	 * @return void
289
+	 */
290
+	public function render($view, array $data = [])
291
+	{
292
+		$view = apply_filters('site-reviews/render/view', $view, $data);
293
+		$file = apply_filters('site-reviews/views/file', $this->file($view), $view, $data);
294
+		if (!file_exists($file)) {
295
+			glsr_log()->error(sprintf('File not found: (%s) %s', $view, $file));
296
+			return;
297
+		}
298
+		$data = apply_filters('site-reviews/views/data', $data, $view);
299
+		extract($data);
300
+		include $file;
301
+	}
302 302
 
303
-    /**
304
-     * @return void
305
-     */
306
-    public function scheduleCronJob()
307
-    {
308
-        if (false === wp_next_scheduled(static::CRON_EVENT)) {
309
-            wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT);
310
-        }
311
-    }
303
+	/**
304
+	 * @return void
305
+	 */
306
+	public function scheduleCronJob()
307
+	{
308
+		if (false === wp_next_scheduled(static::CRON_EVENT)) {
309
+			wp_schedule_event(time(), 'twicedaily', static::CRON_EVENT);
310
+		}
311
+	}
312 312
 
313
-    /**
314
-     * @return void
315
-     */
316
-    public function setDefaults()
317
-    {
318
-        if (get_option(static::ID.'activated')) {
319
-            $this->make(DefaultsManager::class)->set();
320
-            delete_option(static::ID.'activated');
321
-        }
322
-    }
313
+	/**
314
+	 * @return void
315
+	 */
316
+	public function setDefaults()
317
+	{
318
+		if (get_option(static::ID.'activated')) {
319
+			$this->make(DefaultsManager::class)->set();
320
+			delete_option(static::ID.'activated');
321
+		}
322
+	}
323 323
 
324
-    /**
325
-     * @param string $file
326
-     * @return string
327
-     */
328
-    public function themePath($file = '')
329
-    {
330
-        return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/');
331
-    }
324
+	/**
325
+	 * @param string $file
326
+	 * @return string
327
+	 */
328
+	public function themePath($file = '')
329
+	{
330
+		return get_stylesheet_directory().'/'.static::ID.'/'.ltrim(trim($file), '/');
331
+	}
332 332
 
333
-    /**
334
-     * @return void
335
-     */
336
-    public function unscheduleCronJob()
337
-    {
338
-        wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT);
339
-    }
333
+	/**
334
+	 * @return void
335
+	 */
336
+	public function unscheduleCronJob()
337
+	{
338
+		wp_unschedule_event(intval(wp_next_scheduled(static::CRON_EVENT)), static::CRON_EVENT);
339
+	}
340 340
 
341
-    /**
342
-     * @param string $path
343
-     * @return string
344
-     */
345
-    public function url($path = '')
346
-    {
347
-        $url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/'));
348
-        return apply_filters('site-reviews/url', $url, $path);
349
-    }
341
+	/**
342
+	 * @param string $path
343
+	 * @return string
344
+	 */
345
+	public function url($path = '')
346
+	{
347
+		$url = esc_url(plugin_dir_url($this->file).ltrim(trim($path), '/'));
348
+		return apply_filters('site-reviews/url', $url, $path);
349
+	}
350 350
 
351
-    /**
352
-     * @param string $versionLevel
353
-     * @return string
354
-     */
355
-    public function version($versionLevel = '')
356
-    {
357
-        $pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i';
358
-        preg_match($pattern, $this->version, $matches);
359
-        switch ($versionLevel) {
360
-            case 'major':
361
-                $version = Arr::get($matches, 1);
362
-                break;
363
-            case 'minor':
364
-                $version = Arr::get($matches, 1).Arr::get($matches, 2);
365
-                break;
366
-            case 'patch':
367
-                $version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3);
368
-                break;
369
-        }
370
-        return empty($version)
371
-            ? $this->version
372
-            : $version;
373
-    }
351
+	/**
352
+	 * @param string $versionLevel
353
+	 * @return string
354
+	 */
355
+	public function version($versionLevel = '')
356
+	{
357
+		$pattern = '/^v?(\d{1,5})(\.\d++)?(\.\d++)?(.+)?$/i';
358
+		preg_match($pattern, $this->version, $matches);
359
+		switch ($versionLevel) {
360
+			case 'major':
361
+				$version = Arr::get($matches, 1);
362
+				break;
363
+			case 'minor':
364
+				$version = Arr::get($matches, 1).Arr::get($matches, 2);
365
+				break;
366
+			case 'patch':
367
+				$version = Arr::get($matches, 1).Arr::get($matches, 2).Arr::get($matches, 3);
368
+				break;
369
+		}
370
+		return empty($version)
371
+			? $this->version
372
+			: $version;
373
+	}
374 374
 }
Please login to merge, or discard this patch.
plugin/Handlers/RegisterWidgets.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@
 block discarded – undo
8 8
 
9 9
 class RegisterWidgets
10 10
 {
11
-    /**
12
-     * @return void
13
-     */
14
-    public function handle(Command $command)
15
-    {
16
-        foreach ($command->widgets as $baseId => $args) {
17
-            $widgetClass = Helper::buildClassName($baseId.'-widget', 'Widgets');
18
-            if (!class_exists($widgetClass)) {
19
-                glsr_log()->error(sprintf('Widget class missing (%s)', $widgetClass));
20
-                continue;
21
-            }
22
-            register_widget(new $widgetClass(Application::PREFIX.$baseId, $args['name'], $args));
23
-        }
24
-    }
11
+	/**
12
+	 * @return void
13
+	 */
14
+	public function handle(Command $command)
15
+	{
16
+		foreach ($command->widgets as $baseId => $args) {
17
+			$widgetClass = Helper::buildClassName($baseId.'-widget', 'Widgets');
18
+			if (!class_exists($widgetClass)) {
19
+				glsr_log()->error(sprintf('Widget class missing (%s)', $widgetClass));
20
+				continue;
21
+			}
22
+			register_widget(new $widgetClass(Application::PREFIX.$baseId, $args['name'], $args));
23
+		}
24
+	}
25 25
 }
Please login to merge, or discard this patch.
plugin/Handlers/EnqueueAdminAssets.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -10,158 +10,158 @@
 block discarded – undo
10 10
 
11 11
 class EnqueueAdminAssets
12 12
 {
13
-    /**
14
-     * @var array
15
-     */
16
-    protected $pointers;
13
+	/**
14
+	 * @var array
15
+	 */
16
+	protected $pointers;
17 17
 
18
-    /**
19
-     * @return void
20
-     */
21
-    public function handle(Command $command)
22
-    {
23
-        $this->generatePointers($command->pointers);
24
-        $this->enqueueAssets();
25
-        $this->localizeAssets();
26
-    }
18
+	/**
19
+	 * @return void
20
+	 */
21
+	public function handle(Command $command)
22
+	{
23
+		$this->generatePointers($command->pointers);
24
+		$this->enqueueAssets();
25
+		$this->localizeAssets();
26
+	}
27 27
 
28
-    /**
29
-     * @return void
30
-     */
31
-    public function enqueueAssets()
32
-    {
33
-        if (!$this->isCurrentScreen()) {
34
-            return;
35
-        }
36
-        wp_enqueue_style(
37
-            Application::ID.'/admin',
38
-            glsr()->url('assets/styles/'.Application::ID.'-admin.css'),
39
-            [],
40
-            glsr()->version
41
-        );
42
-        wp_enqueue_script(
43
-            Application::ID.'/admin',
44
-            glsr()->url('assets/scripts/'.Application::ID.'-admin.js'),
45
-            $this->getDependencies(),
46
-            glsr()->version,
47
-            true
48
-        );
49
-        if (!empty($this->pointers)) {
50
-            wp_enqueue_style('wp-pointer');
51
-            wp_enqueue_script('wp-pointer');
52
-        }
53
-    }
28
+	/**
29
+	 * @return void
30
+	 */
31
+	public function enqueueAssets()
32
+	{
33
+		if (!$this->isCurrentScreen()) {
34
+			return;
35
+		}
36
+		wp_enqueue_style(
37
+			Application::ID.'/admin',
38
+			glsr()->url('assets/styles/'.Application::ID.'-admin.css'),
39
+			[],
40
+			glsr()->version
41
+		);
42
+		wp_enqueue_script(
43
+			Application::ID.'/admin',
44
+			glsr()->url('assets/scripts/'.Application::ID.'-admin.js'),
45
+			$this->getDependencies(),
46
+			glsr()->version,
47
+			true
48
+		);
49
+		if (!empty($this->pointers)) {
50
+			wp_enqueue_style('wp-pointer');
51
+			wp_enqueue_script('wp-pointer');
52
+		}
53
+	}
54 54
 
55
-    /**
56
-     * @return void
57
-     */
58
-    public function localizeAssets()
59
-    {
60
-        $variables = [
61
-            'action' => Application::PREFIX.'action',
62
-            'addons' => [],
63
-            'ajaxurl' => admin_url('admin-ajax.php'),
64
-            'hideoptions' => [
65
-                'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(),
66
-                'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(),
67
-                'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(),
68
-            ],
69
-            'nameprefix' => Application::ID,
70
-            'nonce' => [
71
-                'change-status' => wp_create_nonce('change-status'),
72
-                'clear-console' => wp_create_nonce('clear-console'),
73
-                'count-reviews' => wp_create_nonce('count-reviews'),
74
-                'fetch-console' => wp_create_nonce('fetch-console'),
75
-                'mce-shortcode' => wp_create_nonce('mce-shortcode'),
76
-                'sync-reviews' => wp_create_nonce('sync-reviews'),
77
-                'toggle-pinned' => wp_create_nonce('toggle-pinned'),
78
-            ],
79
-            'pointers' => $this->pointers,
80
-            'shortcodes' => [],
81
-            'tinymce' => [
82
-                'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'),
83
-            ],
84
-        ];
85
-        if (user_can_richedit()) {
86
-            $variables['shortcodes'] = $this->localizeShortcodes();
87
-        }
88
-        $variables = apply_filters('site-reviews/enqueue/admin/localize', $variables);
89
-        wp_localize_script(Application::ID.'/admin', 'GLSR', $variables);
90
-    }
55
+	/**
56
+	 * @return void
57
+	 */
58
+	public function localizeAssets()
59
+	{
60
+		$variables = [
61
+			'action' => Application::PREFIX.'action',
62
+			'addons' => [],
63
+			'ajaxurl' => admin_url('admin-ajax.php'),
64
+			'hideoptions' => [
65
+				'site_reviews' => glsr(SiteReviewsShortcode::class)->getHideOptions(),
66
+				'site_reviews_form' => glsr(SiteReviewsFormShortcode::class)->getHideOptions(),
67
+				'site_reviews_summary' => glsr(SiteReviewsSummaryShortcode::class)->getHideOptions(),
68
+			],
69
+			'nameprefix' => Application::ID,
70
+			'nonce' => [
71
+				'change-status' => wp_create_nonce('change-status'),
72
+				'clear-console' => wp_create_nonce('clear-console'),
73
+				'count-reviews' => wp_create_nonce('count-reviews'),
74
+				'fetch-console' => wp_create_nonce('fetch-console'),
75
+				'mce-shortcode' => wp_create_nonce('mce-shortcode'),
76
+				'sync-reviews' => wp_create_nonce('sync-reviews'),
77
+				'toggle-pinned' => wp_create_nonce('toggle-pinned'),
78
+			],
79
+			'pointers' => $this->pointers,
80
+			'shortcodes' => [],
81
+			'tinymce' => [
82
+				'glsr_shortcode' => glsr()->url('assets/scripts/mce-plugin.js'),
83
+			],
84
+		];
85
+		if (user_can_richedit()) {
86
+			$variables['shortcodes'] = $this->localizeShortcodes();
87
+		}
88
+		$variables = apply_filters('site-reviews/enqueue/admin/localize', $variables);
89
+		wp_localize_script(Application::ID.'/admin', 'GLSR', $variables);
90
+	}
91 91
 
92
-    /**
93
-     * @return array
94
-     */
95
-    protected function getDependencies()
96
-    {
97
-        $dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []);
98
-        $dependencies = array_merge($dependencies, [
99
-            'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util',
100
-        ]);
101
-        return $dependencies;
102
-    }
92
+	/**
93
+	 * @return array
94
+	 */
95
+	protected function getDependencies()
96
+	{
97
+		$dependencies = apply_filters('site-reviews/enqueue/admin/dependencies', []);
98
+		$dependencies = array_merge($dependencies, [
99
+			'jquery', 'jquery-ui-sortable', 'underscore', 'wp-util',
100
+		]);
101
+		return $dependencies;
102
+	}
103 103
 
104
-    /**
105
-     * @return array
106
-     */
107
-    protected function generatePointer(array $pointer)
108
-    {
109
-        return [
110
-            'id' => $pointer['id'],
111
-            'options' => [
112
-                'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>',
113
-                'position' => $pointer['position'],
114
-            ],
115
-            'screen' => $pointer['screen'],
116
-            'target' => $pointer['target'],
117
-        ];
118
-    }
104
+	/**
105
+	 * @return array
106
+	 */
107
+	protected function generatePointer(array $pointer)
108
+	{
109
+		return [
110
+			'id' => $pointer['id'],
111
+			'options' => [
112
+				'content' => '<h3>'.$pointer['title'].'</h3><p>'.$pointer['content'].'</p>',
113
+				'position' => $pointer['position'],
114
+			],
115
+			'screen' => $pointer['screen'],
116
+			'target' => $pointer['target'],
117
+		];
118
+	}
119 119
 
120
-    /**
121
-     * @return void
122
-     */
123
-    protected function generatePointers(array $pointers)
124
-    {
125
-        $dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true);
126
-        $dismissedPointers = explode(',', (string) $dismissedPointers);
127
-        $generatedPointers = [];
128
-        foreach ($pointers as $pointer) {
129
-            if ($pointer['screen'] != glsr_current_screen()->id) {
130
-                continue;
131
-            }
132
-            if (in_array($pointer['id'], $dismissedPointers)) {
133
-                continue;
134
-            }
135
-            $generatedPointers[] = $this->generatePointer($pointer);
136
-        }
137
-        $this->pointers = $generatedPointers;
138
-    }
120
+	/**
121
+	 * @return void
122
+	 */
123
+	protected function generatePointers(array $pointers)
124
+	{
125
+		$dismissedPointers = get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true);
126
+		$dismissedPointers = explode(',', (string) $dismissedPointers);
127
+		$generatedPointers = [];
128
+		foreach ($pointers as $pointer) {
129
+			if ($pointer['screen'] != glsr_current_screen()->id) {
130
+				continue;
131
+			}
132
+			if (in_array($pointer['id'], $dismissedPointers)) {
133
+				continue;
134
+			}
135
+			$generatedPointers[] = $this->generatePointer($pointer);
136
+		}
137
+		$this->pointers = $generatedPointers;
138
+	}
139 139
 
140
-    /**
141
-     * @return bool
142
-     */
143
-    protected function isCurrentScreen()
144
-    {
145
-        $screen = glsr_current_screen();
146
-        return Application::POST_TYPE == $screen->post_type
147
-            || 'dashboard' == $screen->id
148
-            || 'plugins_page_'.Application::ID == $screen->id
149
-            || 'post' == $screen->base
150
-            || 'widgets' == $screen->id;
151
-    }
140
+	/**
141
+	 * @return bool
142
+	 */
143
+	protected function isCurrentScreen()
144
+	{
145
+		$screen = glsr_current_screen();
146
+		return Application::POST_TYPE == $screen->post_type
147
+			|| 'dashboard' == $screen->id
148
+			|| 'plugins_page_'.Application::ID == $screen->id
149
+			|| 'post' == $screen->base
150
+			|| 'widgets' == $screen->id;
151
+	}
152 152
 
153
-    /**
154
-     * @return array
155
-     */
156
-    protected function localizeShortcodes()
157
-    {
158
-        $variables = [];
159
-        foreach (glsr()->mceShortcodes as $tag => $args) {
160
-            if (empty($args['required'])) {
161
-                continue;
162
-            }
163
-            $variables[$tag] = $args['required'];
164
-        }
165
-        return $variables;
166
-    }
153
+	/**
154
+	 * @return array
155
+	 */
156
+	protected function localizeShortcodes()
157
+	{
158
+		$variables = [];
159
+		foreach (glsr()->mceShortcodes as $tag => $args) {
160
+			if (empty($args['required'])) {
161
+				continue;
162
+			}
163
+			$variables[$tag] = $args['required'];
164
+		}
165
+		return $variables;
166
+	}
167 167
 }
Please login to merge, or discard this patch.
plugin/Handlers/RegisterShortcodes.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -7,18 +7,18 @@
 block discarded – undo
7 7
 
8 8
 class RegisterShortcodes
9 9
 {
10
-    /**
11
-     * @return void
12
-     */
13
-    public function handle(Command $command)
14
-    {
15
-        foreach ($command->shortcodes as $shortcode) {
16
-            $shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes');
17
-            if (!class_exists($shortcodeClass)) {
18
-                glsr_log()->error(sprintf('Shortcode class missing (%s)', $shortcodeClass));
19
-                continue;
20
-            }
21
-            add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']);
22
-        }
23
-    }
10
+	/**
11
+	 * @return void
12
+	 */
13
+	public function handle(Command $command)
14
+	{
15
+		foreach ($command->shortcodes as $shortcode) {
16
+			$shortcodeClass = Helper::buildClassName($shortcode.'-shortcode', 'Shortcodes');
17
+			if (!class_exists($shortcodeClass)) {
18
+				glsr_log()->error(sprintf('Shortcode class missing (%s)', $shortcodeClass));
19
+				continue;
20
+			}
21
+			add_shortcode($shortcode, [glsr($shortcodeClass), 'buildShortcode']);
22
+		}
23
+	}
24 24
 }
Please login to merge, or discard this patch.