Passed
Push — master ( 925e6d...054ae2 )
by Paul
08:03 queued 03:39
created
plugin/Commands/RegisterPostType.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -9,77 +9,77 @@
 block discarded – undo
9 9
 
10 10
 class RegisterPostType
11 11
 {
12
-    public $args;
13
-    public $columns;
14
-    public $plural;
15
-    public $postType;
16
-    public $single;
12
+	public $args;
13
+	public $columns;
14
+	public $plural;
15
+	public $postType;
16
+	public $single;
17 17
 
18
-    public function __construct($input)
19
-    {
20
-        $args = glsr(PostTypeDefaults::class)->merge($input);
21
-        $this->normalize($args);
22
-        $this->normalizeColumns();
23
-        $this->normalizeLabels();
24
-    }
18
+	public function __construct($input)
19
+	{
20
+		$args = glsr(PostTypeDefaults::class)->merge($input);
21
+		$this->normalize($args);
22
+		$this->normalizeColumns();
23
+		$this->normalizeLabels();
24
+	}
25 25
 
26
-    /**
27
-     * @return void
28
-     */
29
-    protected function normalize(array $args)
30
-    {
31
-        foreach ($args as $key => $value) {
32
-            $property = Helper::buildPropertyName($key);
33
-            if (!property_exists($this, $property)) {
34
-                continue;
35
-            }
36
-            $this->$property = $value;
37
-            unset($args[$key]);
38
-        }
39
-        $this->args = wp_parse_args($args, [
40
-            'menu_name' => $this->plural,
41
-        ]);
42
-    }
26
+	/**
27
+	 * @return void
28
+	 */
29
+	protected function normalize(array $args)
30
+	{
31
+		foreach ($args as $key => $value) {
32
+			$property = Helper::buildPropertyName($key);
33
+			if (!property_exists($this, $property)) {
34
+				continue;
35
+			}
36
+			$this->$property = $value;
37
+			unset($args[$key]);
38
+		}
39
+		$this->args = wp_parse_args($args, [
40
+			'menu_name' => $this->plural,
41
+		]);
42
+	}
43 43
 
44
-    /**
45
-     * @return void
46
-     */
47
-    protected function normalizeLabels()
48
-    {
49
-        $this->args['labels'] = wp_parse_args($this->args['labels'], [
50
-            'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural),
51
-            'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural),
52
-            'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single),
53
-            'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single),
54
-            'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single),
55
-            'menu_name' => $this->args['menu_name'],
56
-            'name' => $this->plural,
57
-            'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single),
58
-            'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural),
59
-            'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural),
60
-            'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural),
61
-            'singular_name' => $this->single,
62
-            'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single),
63
-            'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single),
64
-        ]);
65
-        unset($this->args['menu_name']);
66
-    }
44
+	/**
45
+	 * @return void
46
+	 */
47
+	protected function normalizeLabels()
48
+	{
49
+		$this->args['labels'] = wp_parse_args($this->args['labels'], [
50
+			'add_new_item' => sprintf(_x('Add New %s', 'Add New Post', 'site-reviews'), $this->plural),
51
+			'all_items' => sprintf(_x('All %s', 'All Posts', 'site-reviews'), $this->plural),
52
+			'archives' => sprintf(_x('%s Archives', 'Post Archives', 'site-reviews'), $this->single),
53
+			'edit_item' => sprintf(_x('Edit %s', 'Edit Post', 'site-reviews'), $this->single),
54
+			'insert_into_item' => sprintf(_x('Insert into %s', 'Insert into Post', 'site-reviews'), $this->single),
55
+			'menu_name' => $this->args['menu_name'],
56
+			'name' => $this->plural,
57
+			'new_item' => sprintf(_x('New %s', 'New Post', 'site-reviews'), $this->single),
58
+			'not_found' => sprintf(_x('No %s found', 'No Posts found', 'site-reviews'), $this->plural),
59
+			'not_found_in_trash' => sprintf(_x('No %s found in Trash', 'No Posts found in Trash', 'site-reviews'), $this->plural),
60
+			'search_items' => sprintf(_x('Search %s', 'Search Posts', 'site-reviews'), $this->plural),
61
+			'singular_name' => $this->single,
62
+			'uploaded_to_this_item' => sprintf(_x('Uploaded to this %s', 'Uploaded to this Post', 'site-reviews'), $this->single),
63
+			'view_item' => sprintf(_x('View %s', 'View Post', 'site-reviews'), $this->single),
64
+		]);
65
+		unset($this->args['menu_name']);
66
+	}
67 67
 
68
-    /**
69
-     * @return void
70
-     */
71
-    protected function normalizeColumns()
72
-    {
73
-        $this->columns = ['cb' => ''] + $this->columns;
74
-        if (array_key_exists('category', $this->columns)) {
75
-            $keys = array_keys($this->columns);
76
-            $keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY;
77
-            $this->columns = array_combine($keys, $this->columns);
78
-        }
79
-        if (array_key_exists('pinned', $this->columns)) {
80
-            $this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>',
81
-                ['class' => 'pinned-icon']
82
-            );
83
-        }
84
-    }
68
+	/**
69
+	 * @return void
70
+	 */
71
+	protected function normalizeColumns()
72
+	{
73
+		$this->columns = ['cb' => ''] + $this->columns;
74
+		if (array_key_exists('category', $this->columns)) {
75
+			$keys = array_keys($this->columns);
76
+			$keys[array_search('category', $keys)] = 'taxonomy-'.Application::TAXONOMY;
77
+			$this->columns = array_combine($keys, $this->columns);
78
+		}
79
+		if (array_key_exists('pinned', $this->columns)) {
80
+			$this->columns['pinned'] = glsr(Builder::class)->span('<span>'.$this->columns['pinned'].'</span>',
81
+				['class' => 'pinned-icon']
82
+			);
83
+		}
84
+	}
85 85
 }
Please login to merge, or discard this patch.
plugin/Commands/CreateReview.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -6,140 +6,140 @@
 block discarded – undo
6 6
 
7 7
 class CreateReview
8 8
 {
9
-    public $ajax_request;
10
-    public $assigned_to;
11
-    public $author;
12
-    public $avatar;
13
-    public $blacklisted;
14
-    public $category;
15
-    public $content;
16
-    public $custom;
17
-    public $date;
18
-    public $email;
19
-    public $form_id;
20
-    public $ip_address;
21
-    public $post_id;
22
-    public $rating;
23
-    public $referer;
24
-    public $request;
25
-    public $response;
26
-    public $terms;
27
-    public $title;
28
-    public $url;
9
+	public $ajax_request;
10
+	public $assigned_to;
11
+	public $author;
12
+	public $avatar;
13
+	public $blacklisted;
14
+	public $category;
15
+	public $content;
16
+	public $custom;
17
+	public $date;
18
+	public $email;
19
+	public $form_id;
20
+	public $ip_address;
21
+	public $post_id;
22
+	public $rating;
23
+	public $referer;
24
+	public $request;
25
+	public $response;
26
+	public $terms;
27
+	public $title;
28
+	public $url;
29 29
 
30
-    public function __construct($input)
31
-    {
32
-        $this->request = $input;
33
-        $this->ajax_request = isset($input['_ajax_request']);
34
-        $this->assigned_to = $this->getNumeric('assign_to');
35
-        $this->author = sanitize_text_field($this->getUser('name'));
36
-        $this->avatar = $this->getAvatar();
37
-        $this->blacklisted = isset($input['blacklisted']);
38
-        $this->category = $this->getCategory();
39
-        $this->content = sanitize_textarea_field($this->get('content'));
40
-        $this->custom = $this->getCustom();
41
-        $this->date = $this->getDate('date');
42
-        $this->email = sanitize_email($this->getUser('email'));
43
-        $this->form_id = sanitize_key($this->get('form_id'));
44
-        $this->ip_address = $this->get('ip_address');
45
-        $this->post_id = intval($this->get('_post_id'));
46
-        $this->rating = intval($this->get('rating'));
47
-        $this->referer = $this->get('_referer');
48
-        $this->response = sanitize_textarea_field($this->get('response'));
49
-        $this->terms = !empty($input['terms']);
50
-        $this->title = sanitize_text_field($this->get('title'));
51
-        $this->url = esc_url_raw($this->get('url'));
52
-    }
30
+	public function __construct($input)
31
+	{
32
+		$this->request = $input;
33
+		$this->ajax_request = isset($input['_ajax_request']);
34
+		$this->assigned_to = $this->getNumeric('assign_to');
35
+		$this->author = sanitize_text_field($this->getUser('name'));
36
+		$this->avatar = $this->getAvatar();
37
+		$this->blacklisted = isset($input['blacklisted']);
38
+		$this->category = $this->getCategory();
39
+		$this->content = sanitize_textarea_field($this->get('content'));
40
+		$this->custom = $this->getCustom();
41
+		$this->date = $this->getDate('date');
42
+		$this->email = sanitize_email($this->getUser('email'));
43
+		$this->form_id = sanitize_key($this->get('form_id'));
44
+		$this->ip_address = $this->get('ip_address');
45
+		$this->post_id = intval($this->get('_post_id'));
46
+		$this->rating = intval($this->get('rating'));
47
+		$this->referer = $this->get('_referer');
48
+		$this->response = sanitize_textarea_field($this->get('response'));
49
+		$this->terms = !empty($input['terms']);
50
+		$this->title = sanitize_text_field($this->get('title'));
51
+		$this->url = esc_url_raw($this->get('url'));
52
+	}
53 53
 
54
-    /**
55
-     * @param string $key
56
-     * @return string
57
-     */
58
-    protected function get($key)
59
-    {
60
-        return (string) Arr::get($this->request, $key);
61
-    }
54
+	/**
55
+	 * @param string $key
56
+	 * @return string
57
+	 */
58
+	protected function get($key)
59
+	{
60
+		return (string) Arr::get($this->request, $key);
61
+	}
62 62
 
63
-    /**
64
-     * @return string
65
-     */
66
-    protected function getAvatar()
67
-    {
68
-        $avatar = $this->get('avatar');
69
-        return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)
70
-            ? (string) get_avatar_url($this->get('email'))
71
-            : $avatar;
72
-    }
63
+	/**
64
+	 * @return string
65
+	 */
66
+	protected function getAvatar()
67
+	{
68
+		$avatar = $this->get('avatar');
69
+		return !filter_var($avatar, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)
70
+			? (string) get_avatar_url($this->get('email'))
71
+			: $avatar;
72
+	}
73 73
 
74
-    /**
75
-     * @return string
76
-     */
77
-    protected function getCategory()
78
-    {
79
-        $categories = Arr::convertStringToArray($this->get('category'));
80
-        return sanitize_key(Arr::get($categories, 0));
81
-    }
74
+	/**
75
+	 * @return string
76
+	 */
77
+	protected function getCategory()
78
+	{
79
+		$categories = Arr::convertStringToArray($this->get('category'));
80
+		return sanitize_key(Arr::get($categories, 0));
81
+	}
82 82
 
83
-    /**
84
-     * @return array
85
-     */
86
-    protected function getCustom()
87
-    {
88
-        $unset = [
89
-            '_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token',
90
-            '_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id',
91
-            'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url',
92
-        ];
93
-        $unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset);
94
-        $custom = $this->request;
95
-        foreach ($unset as $value) {
96
-            unset($custom[$value]);
97
-        }
98
-        return $custom;
99
-    }
83
+	/**
84
+	 * @return array
85
+	 */
86
+	protected function getCustom()
87
+	{
88
+		$unset = [
89
+			'_action', '_ajax_request', '_counter', '_nonce', '_post_id', '_recaptcha-token',
90
+			'_referer', 'assign_to', 'category', 'content', 'date', 'email', 'excluded', 'form_id',
91
+			'gotcha', 'ip_address', 'name', 'rating', 'response', 'terms', 'title', 'url',
92
+		];
93
+		$unset = apply_filters('site-reviews/create/unset-keys-from-custom', $unset);
94
+		$custom = $this->request;
95
+		foreach ($unset as $value) {
96
+			unset($custom[$value]);
97
+		}
98
+		return $custom;
99
+	}
100 100
 
101
-    /**
102
-     * @param string $key
103
-     * @return string
104
-     */
105
-    protected function getDate($key)
106
-    {
107
-        $date = strtotime($this->get($key));
108
-        if (false === $date) {
109
-            $date = time();
110
-        }
111
-        return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date));
112
-    }
101
+	/**
102
+	 * @param string $key
103
+	 * @return string
104
+	 */
105
+	protected function getDate($key)
106
+	{
107
+		$date = strtotime($this->get($key));
108
+		if (false === $date) {
109
+			$date = time();
110
+		}
111
+		return get_date_from_gmt(gmdate('Y-m-d H:i:s', $date));
112
+	}
113 113
 
114
-    /**
115
-     * @param string $key
116
-     * @return string
117
-     */
118
-    protected function getUser($key)
119
-    {
120
-        $value = $this->get($key);
121
-        if (empty($value)) {
122
-            $user = wp_get_current_user();
123
-            $userValues = [
124
-                'email' => 'user_email',
125
-                'name' => 'display_name',
126
-            ];
127
-            if ($user->exists() && array_key_exists($key, $userValues)) {
128
-                return $user->{$userValues[$key]};
129
-            }
130
-        }
131
-        return $value;
132
-    }
114
+	/**
115
+	 * @param string $key
116
+	 * @return string
117
+	 */
118
+	protected function getUser($key)
119
+	{
120
+		$value = $this->get($key);
121
+		if (empty($value)) {
122
+			$user = wp_get_current_user();
123
+			$userValues = [
124
+				'email' => 'user_email',
125
+				'name' => 'display_name',
126
+			];
127
+			if ($user->exists() && array_key_exists($key, $userValues)) {
128
+				return $user->{$userValues[$key]};
129
+			}
130
+		}
131
+		return $value;
132
+	}
133 133
 
134
-    /**
135
-     * @param string $key
136
-     * @return string
137
-     */
138
-    protected function getNumeric($key)
139
-    {
140
-        $value = $this->get($key);
141
-        return is_numeric($value)
142
-            ? $value
143
-            : '';
144
-    }
134
+	/**
135
+	 * @param string $key
136
+	 * @return string
137
+	 */
138
+	protected function getNumeric($key)
139
+	{
140
+		$value = $this->get($key);
141
+		return is_numeric($value)
142
+			? $value
143
+			: '';
144
+	}
145 145
 }
Please login to merge, or discard this patch.
plugin/Router.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -7,162 +7,162 @@
 block discarded – undo
7 7
 
8 8
 class Router
9 9
 {
10
-    /**
11
-     * @var array
12
-     */
13
-    protected $unguardedActions = [];
10
+	/**
11
+	 * @var array
12
+	 */
13
+	protected $unguardedActions = [];
14 14
 
15
-    public function __construct()
16
-    {
17
-        $this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [
18
-            'dismiss-notice',
19
-            'fetch-paged-reviews',
20
-        ]);
21
-    }
15
+	public function __construct()
16
+	{
17
+		$this->unguardedActions = apply_filters('site-reviews/router/unguarded-actions', [
18
+			'dismiss-notice',
19
+			'fetch-paged-reviews',
20
+		]);
21
+	}
22 22
 
23
-    /**
24
-     * @return void
25
-     */
26
-    public function routeAdminPostRequest()
27
-    {
28
-        $request = $this->getRequest();
29
-        if (!$this->isValidPostRequest($request)) {
30
-            return;
31
-        }
32
-        check_admin_referer($request['_action']);
33
-        $this->routeRequest('admin', $request['_action'], $request);
34
-    }
23
+	/**
24
+	 * @return void
25
+	 */
26
+	public function routeAdminPostRequest()
27
+	{
28
+		$request = $this->getRequest();
29
+		if (!$this->isValidPostRequest($request)) {
30
+			return;
31
+		}
32
+		check_admin_referer($request['_action']);
33
+		$this->routeRequest('admin', $request['_action'], $request);
34
+	}
35 35
 
36
-    /**
37
-     * @return void
38
-     */
39
-    public function routeAjaxRequest()
40
-    {
41
-        $request = $this->getRequest();
42
-        $this->checkAjaxRequest($request);
43
-        $this->checkAjaxNonce($request);
44
-        $this->routeRequest('ajax', $request['_action'], $request);
45
-        wp_die();
46
-    }
36
+	/**
37
+	 * @return void
38
+	 */
39
+	public function routeAjaxRequest()
40
+	{
41
+		$request = $this->getRequest();
42
+		$this->checkAjaxRequest($request);
43
+		$this->checkAjaxNonce($request);
44
+		$this->routeRequest('ajax', $request['_action'], $request);
45
+		wp_die();
46
+	}
47 47
 
48
-    /**
49
-     * @return void
50
-     */
51
-    public function routePublicPostRequest()
52
-    {
53
-        if (is_admin()) {
54
-            return;
55
-        }
56
-        $request = $this->getRequest();
57
-        if (!$this->isValidPostRequest($request)) {
58
-            return;
59
-        }
60
-        if (!$this->isValidPublicNonce($request)) {
61
-            return;
62
-        }
63
-        $this->routeRequest('public', $request['_action'], $request);
64
-    }
48
+	/**
49
+	 * @return void
50
+	 */
51
+	public function routePublicPostRequest()
52
+	{
53
+		if (is_admin()) {
54
+			return;
55
+		}
56
+		$request = $this->getRequest();
57
+		if (!$this->isValidPostRequest($request)) {
58
+			return;
59
+		}
60
+		if (!$this->isValidPublicNonce($request)) {
61
+			return;
62
+		}
63
+		$this->routeRequest('public', $request['_action'], $request);
64
+	}
65 65
 
66
-    /**
67
-     * @return void
68
-     */
69
-    protected function checkAjaxNonce(array $request)
70
-    {
71
-        if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) {
72
-            return;
73
-        }
74
-        if (!isset($request['_nonce'])) {
75
-            $this->sendAjaxError('request is missing a nonce', $request);
76
-        }
77
-        if (!wp_verify_nonce($request['_nonce'], $request['_action'])) {
78
-            $this->sendAjaxError('request failed the nonce check', $request, 403);
79
-        }
80
-    }
66
+	/**
67
+	 * @return void
68
+	 */
69
+	protected function checkAjaxNonce(array $request)
70
+	{
71
+		if (!is_user_logged_in() || in_array(Arr::get($request, '_action'), $this->unguardedActions)) {
72
+			return;
73
+		}
74
+		if (!isset($request['_nonce'])) {
75
+			$this->sendAjaxError('request is missing a nonce', $request);
76
+		}
77
+		if (!wp_verify_nonce($request['_nonce'], $request['_action'])) {
78
+			$this->sendAjaxError('request failed the nonce check', $request, 403);
79
+		}
80
+	}
81 81
 
82
-    /**
83
-     * @return void
84
-     */
85
-    protected function checkAjaxRequest(array $request)
86
-    {
87
-        if (!isset($request['_action'])) {
88
-            $this->sendAjaxError('request must include an action', $request);
89
-        }
90
-        if (empty($request['_ajax_request'])) {
91
-            $this->sendAjaxError('request is invalid', $request);
92
-        }
93
-    }
82
+	/**
83
+	 * @return void
84
+	 */
85
+	protected function checkAjaxRequest(array $request)
86
+	{
87
+		if (!isset($request['_action'])) {
88
+			$this->sendAjaxError('request must include an action', $request);
89
+		}
90
+		if (empty($request['_ajax_request'])) {
91
+			$this->sendAjaxError('request is invalid', $request);
92
+		}
93
+	}
94 94
 
95
-    /**
96
-     * All ajax requests in the plugin are triggered by a single action hook: glsr_action,
97
-     * while each ajax route is determined by $_POST[request][_action].
98
-     * @return array
99
-     */
100
-    protected function getRequest()
101
-    {
102
-        $request = Helper::filterInputArray(Application::ID);
103
-        if (Helper::filterInput('action') == Application::PREFIX.'action') {
104
-            $request['_ajax_request'] = true;
105
-        }
106
-        if ('submit-review' == Helper::filterInput('_action', $request)) {
107
-            $request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response');
108
-        }
109
-        return $request;
110
-    }
95
+	/**
96
+	 * All ajax requests in the plugin are triggered by a single action hook: glsr_action,
97
+	 * while each ajax route is determined by $_POST[request][_action].
98
+	 * @return array
99
+	 */
100
+	protected function getRequest()
101
+	{
102
+		$request = Helper::filterInputArray(Application::ID);
103
+		if (Helper::filterInput('action') == Application::PREFIX.'action') {
104
+			$request['_ajax_request'] = true;
105
+		}
106
+		if ('submit-review' == Helper::filterInput('_action', $request)) {
107
+			$request['_recaptcha-token'] = Helper::filterInput('g-recaptcha-response');
108
+		}
109
+		return $request;
110
+	}
111 111
 
112
-    /**
113
-     * @return bool
114
-     */
115
-    protected function isValidPostRequest(array $request = [])
116
-    {
117
-        return !empty($request['_action']) && empty($request['_ajax_request']);
118
-    }
112
+	/**
113
+	 * @return bool
114
+	 */
115
+	protected function isValidPostRequest(array $request = [])
116
+	{
117
+		return !empty($request['_action']) && empty($request['_ajax_request']);
118
+	}
119 119
 
120
-    /**
121
-     * @return bool
122
-     */
123
-    protected function isValidPublicNonce(array $request)
124
-    {
125
-        if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) {
126
-            glsr_log()->error('nonce check failed for public request')->debug($request);
127
-            return false;
128
-        }
129
-        return true;
130
-    }
120
+	/**
121
+	 * @return bool
122
+	 */
123
+	protected function isValidPublicNonce(array $request)
124
+	{
125
+		if (is_user_logged_in() && !wp_verify_nonce($request['_nonce'], $request['_action'])) {
126
+			glsr_log()->error('nonce check failed for public request')->debug($request);
127
+			return false;
128
+		}
129
+		return true;
130
+	}
131 131
 
132
-    /**
133
-     * @param string $type
134
-     * @param string $action
135
-     * @return void
136
-     */
137
-    protected function routeRequest($type, $action, array $request = [])
138
-    {
139
-        $actionHook = 'site-reviews/route/'.$type.'/request';
140
-        $controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers'));
141
-        $method = Helper::buildMethodName($action, 'router');
142
-        $request = apply_filters('site-reviews/route/request', $request, $action, $type);
143
-        do_action($actionHook, $action, $request);
144
-        if (is_callable([$controller, $method])) {
145
-            call_user_func([$controller, $method], $request);
146
-            return;
147
-        }
148
-        if (0 === did_action($actionHook)) {
149
-            glsr_log('Unknown '.$type.' router request: '.$action);
150
-        }
151
-    }
132
+	/**
133
+	 * @param string $type
134
+	 * @param string $action
135
+	 * @return void
136
+	 */
137
+	protected function routeRequest($type, $action, array $request = [])
138
+	{
139
+		$actionHook = 'site-reviews/route/'.$type.'/request';
140
+		$controller = glsr(Helper::buildClassName($type.'-controller', 'Controllers'));
141
+		$method = Helper::buildMethodName($action, 'router');
142
+		$request = apply_filters('site-reviews/route/request', $request, $action, $type);
143
+		do_action($actionHook, $action, $request);
144
+		if (is_callable([$controller, $method])) {
145
+			call_user_func([$controller, $method], $request);
146
+			return;
147
+		}
148
+		if (0 === did_action($actionHook)) {
149
+			glsr_log('Unknown '.$type.' router request: '.$action);
150
+		}
151
+	}
152 152
 
153
-    /**
154
-     * @param string $error
155
-     * @param int $statusCode
156
-     * @return void
157
-     */
158
-    protected function sendAjaxError($error, array $request, $statusCode = 400)
159
-    {
160
-        glsr_log()->error($error)->debug($request);
161
-        glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>');
162
-        wp_send_json_error([
163
-            'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'),
164
-            'notices' => glsr(Notice::class)->get(),
165
-            'error' => $error,
166
-        ]);
167
-    }
153
+	/**
154
+	 * @param string $error
155
+	 * @param int $statusCode
156
+	 * @return void
157
+	 */
158
+	protected function sendAjaxError($error, array $request, $statusCode = 400)
159
+	{
160
+		glsr_log()->error($error)->debug($request);
161
+		glsr(Notice::class)->addError(__('There was an error (try reloading the page).', 'site-reviews').' <code>'.$error.'</code>');
162
+		wp_send_json_error([
163
+			'message' => __('The form could not be submitted. Please notify the site administrator.', 'site-reviews'),
164
+			'notices' => glsr(Notice::class)->get(),
165
+			'error' => $error,
166
+		]);
167
+	}
168 168
 }
Please login to merge, or discard this patch.
plugin/Database/CountsManager.php 1 patch
Indentation   +354 added lines, -354 removed lines patch added patch discarded remove patch
@@ -12,385 +12,385 @@
 block discarded – undo
12 12
 
13 13
 class CountsManager
14 14
 {
15
-    const LIMIT = 500;
16
-    const META_AVERAGE = '_glsr_average';
17
-    const META_COUNT = '_glsr_count';
18
-    const META_RANKING = '_glsr_ranking';
15
+	const LIMIT = 500;
16
+	const META_AVERAGE = '_glsr_average';
17
+	const META_COUNT = '_glsr_count';
18
+	const META_RANKING = '_glsr_ranking';
19 19
 
20
-    /**
21
-     * @return array
22
-     * @todo verify the additional type checks are needed
23
-     */
24
-    public function buildCounts(array $args = [])
25
-    {
26
-        $counts = [];
27
-        $query = $this->queryReviews($args);
28
-        while ($query) {
29
-            $types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
-            $types = array_unique(array_merge(['local'], $types));
31
-            foreach ($types as $type) {
32
-                $type = $this->normalizeType($type);
33
-                if (isset($counts[$type])) {
34
-                    continue;
35
-            }
36
-                $counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
-            }
38
-            foreach ($query->reviews as $review) {
39
-                $type = $this->normalizeType($review->type);
40
-                ++$counts[$type][$review->rating];
41
-            }
42
-            $query = $query->has_more
43
-                ? $this->queryReviews($args, end($query->reviews)->ID)
44
-                : false;
45
-        }
46
-        return $counts;
47
-    }
20
+	/**
21
+	 * @return array
22
+	 * @todo verify the additional type checks are needed
23
+	 */
24
+	public function buildCounts(array $args = [])
25
+	{
26
+		$counts = [];
27
+		$query = $this->queryReviews($args);
28
+		while ($query) {
29
+			$types = array_keys(array_flip(glsr_array_column($query->reviews, 'type')));
30
+			$types = array_unique(array_merge(['local'], $types));
31
+			foreach ($types as $type) {
32
+				$type = $this->normalizeType($type);
33
+				if (isset($counts[$type])) {
34
+					continue;
35
+			}
36
+				$counts[$type] = array_fill_keys(range(0, glsr()->constant('MAX_RATING', Rating::class)), 0);
37
+			}
38
+			foreach ($query->reviews as $review) {
39
+				$type = $this->normalizeType($review->type);
40
+				++$counts[$type][$review->rating];
41
+			}
42
+			$query = $query->has_more
43
+				? $this->queryReviews($args, end($query->reviews)->ID)
44
+				: false;
45
+		}
46
+		return $counts;
47
+	}
48 48
 
49
-    /**
50
-     * @param int $postId
51
-     * @return array
52
-     */
53
-    public function buildPostCounts($postId)
54
-    {
55
-        return $this->buildCounts(['post_ids' => [$postId]]);
56
-    }
49
+	/**
50
+	 * @param int $postId
51
+	 * @return array
52
+	 */
53
+	public function buildPostCounts($postId)
54
+	{
55
+		return $this->buildCounts(['post_ids' => [$postId]]);
56
+	}
57 57
 
58
-    /**
59
-     * @param int $termTaxonomyId
60
-     * @return array
61
-     */
62
-    public function buildTermCounts($termTaxonomyId)
63
-    {
64
-        return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
65
-    }
58
+	/**
59
+	 * @param int $termTaxonomyId
60
+	 * @return array
61
+	 */
62
+	public function buildTermCounts($termTaxonomyId)
63
+	{
64
+		return $this->buildCounts(['term_ids' => [$termTaxonomyId]]);
65
+	}
66 66
 
67
-    /**
68
-     * @return void
69
-     */
70
-    public function countAll()
71
-    {
72
-        $terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
-        foreach ($terms as $term) {
74
-            $this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
75
-        }
76
-        $postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
-        foreach ($postIds as $postId) {
78
-            $this->setPostCounts($postId, $this->buildPostCounts($postId));
79
-        }
80
-        $this->setCounts($this->buildCounts());
81
-    }
67
+	/**
68
+	 * @return void
69
+	 */
70
+	public function countAll()
71
+	{
72
+		$terms = glsr(Database::class)->getTerms(['fields' => 'all']);
73
+		foreach ($terms as $term) {
74
+			$this->setTermCounts($term->term_id, $this->buildTermCounts($term->term_taxonomy_id));
75
+		}
76
+		$postIds = glsr(SqlQueries::class)->getReviewsMeta('assigned_to');
77
+		foreach ($postIds as $postId) {
78
+			$this->setPostCounts($postId, $this->buildPostCounts($postId));
79
+		}
80
+		$this->setCounts($this->buildCounts());
81
+	}
82 82
 
83
-    /**
84
-     * @return void
85
-     */
86
-    public function decrease(Review $review)
87
-    {
88
-        $this->decreaseCounts($review);
89
-        $this->decreasePostCounts($review);
90
-        $this->decreaseTermCounts($review);
91
-    }
83
+	/**
84
+	 * @return void
85
+	 */
86
+	public function decrease(Review $review)
87
+	{
88
+		$this->decreaseCounts($review);
89
+		$this->decreasePostCounts($review);
90
+		$this->decreaseTermCounts($review);
91
+	}
92 92
 
93
-    /**
94
-     * @return void
95
-     */
96
-    public function decreaseCounts(Review $review)
97
-    {
98
-        $this->setCounts($this->decreaseRating(
99
-            $this->getCounts(),
100
-            $review->review_type,
101
-            $review->rating
102
-        ));
103
-    }
93
+	/**
94
+	 * @return void
95
+	 */
96
+	public function decreaseCounts(Review $review)
97
+	{
98
+		$this->setCounts($this->decreaseRating(
99
+			$this->getCounts(),
100
+			$review->review_type,
101
+			$review->rating
102
+		));
103
+	}
104 104
 
105
-    /**
106
-     * @return void
107
-     */
108
-    public function decreasePostCounts(Review $review)
109
-    {
110
-        if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
-            return;
112
-        }
113
-        $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
-        $this->setPostCounts($review->assigned_to, $counts);
115
-    }
105
+	/**
106
+	 * @return void
107
+	 */
108
+	public function decreasePostCounts(Review $review)
109
+	{
110
+		if (empty($counts = $this->getPostCounts($review->assigned_to))) {
111
+			return;
112
+		}
113
+		$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
114
+		$this->setPostCounts($review->assigned_to, $counts);
115
+	}
116 116
 
117
-    /**
118
-     * @return void
119
-     */
120
-    public function decreaseTermCounts(Review $review)
121
-    {
122
-        foreach ($review->term_ids as $termId) {
123
-            if (empty($counts = $this->getTermCounts($termId))) {
124
-                continue;
125
-            }
126
-            $counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
-            $this->setTermCounts($termId, $counts);
128
-        }
129
-    }
117
+	/**
118
+	 * @return void
119
+	 */
120
+	public function decreaseTermCounts(Review $review)
121
+	{
122
+		foreach ($review->term_ids as $termId) {
123
+			if (empty($counts = $this->getTermCounts($termId))) {
124
+				continue;
125
+			}
126
+			$counts = $this->decreaseRating($counts, $review->review_type, $review->rating);
127
+			$this->setTermCounts($termId, $counts);
128
+		}
129
+	}
130 130
 
131
-    /**
132
-     * @return array
133
-     */
134
-    public function flatten(array $reviewCounts, array $args = [])
135
-    {
136
-        $counts = [];
137
-        array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
-            $counts[$index] = $num + intval(Arr::get($counts, $index, 0));
139
-        });
140
-        $args = wp_parse_args($args, [
141
-            'max' => glsr()->constant('MAX_RATING', Rating::class),
142
-            'min' => glsr()->constant('MIN_RATING', Rating::class),
143
-        ]);
144
-        foreach ($counts as $index => &$num) {
145
-            if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
146
-                continue;
147
-            }
148
-            $num = 0;
149
-        }
150
-        return $counts;
151
-    }
131
+	/**
132
+	 * @return array
133
+	 */
134
+	public function flatten(array $reviewCounts, array $args = [])
135
+	{
136
+		$counts = [];
137
+		array_walk_recursive($reviewCounts, function ($num, $index) use (&$counts) {
138
+			$counts[$index] = $num + intval(Arr::get($counts, $index, 0));
139
+		});
140
+		$args = wp_parse_args($args, [
141
+			'max' => glsr()->constant('MAX_RATING', Rating::class),
142
+			'min' => glsr()->constant('MIN_RATING', Rating::class),
143
+		]);
144
+		foreach ($counts as $index => &$num) {
145
+			if ($index >= intval($args['min']) && $index <= intval($args['max'])) {
146
+				continue;
147
+			}
148
+			$num = 0;
149
+		}
150
+		return $counts;
151
+	}
152 152
 
153
-    /**
154
-     * @return array
155
-     */
156
-    public function get(array $args = [])
157
-    {
158
-        $args = $this->normalizeArgs($args);
159
-        $counts = [];
160
-        if ($this->isMixedCount($args)) {
161
-            $counts = [$this->buildCounts($args)]; // force query the database
162
-        } else {
163
-            foreach ($args['post_ids'] as $postId) {
164
-                $counts[] = $this->getPostCounts($postId);
165
-        }
166
-            foreach ($args['term_ids'] as $termId) {
167
-                $counts[] = $this->getTermCounts($termId);
168
-            }
169
-            if (empty($counts)) {
170
-                $counts[] = $this->getCounts();
171
-            }
172
-        }
173
-        return in_array($args['type'], ['', 'all'])
174
-            ? $this->normalize([$this->flatten($counts)])
175
-            : $this->normalize(glsr_array_column($counts, $args['type']));
176
-    }
153
+	/**
154
+	 * @return array
155
+	 */
156
+	public function get(array $args = [])
157
+	{
158
+		$args = $this->normalizeArgs($args);
159
+		$counts = [];
160
+		if ($this->isMixedCount($args)) {
161
+			$counts = [$this->buildCounts($args)]; // force query the database
162
+		} else {
163
+			foreach ($args['post_ids'] as $postId) {
164
+				$counts[] = $this->getPostCounts($postId);
165
+		}
166
+			foreach ($args['term_ids'] as $termId) {
167
+				$counts[] = $this->getTermCounts($termId);
168
+			}
169
+			if (empty($counts)) {
170
+				$counts[] = $this->getCounts();
171
+			}
172
+		}
173
+		return in_array($args['type'], ['', 'all'])
174
+			? $this->normalize([$this->flatten($counts)])
175
+			: $this->normalize(glsr_array_column($counts, $args['type']));
176
+	}
177 177
 
178
-    /**
179
-     * @return array
180
-     */
181
-    public function getCounts()
182
-    {
183
-        $counts = glsr(OptionManager::class)->get('counts', []);
184
-        if (!is_array($counts)) {
185
-            glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts);
186
-            return [];
187
-        }
188
-        return $counts;
189
-    }
178
+	/**
179
+	 * @return array
180
+	 */
181
+	public function getCounts()
182
+	{
183
+		$counts = glsr(OptionManager::class)->get('counts', []);
184
+		if (!is_array($counts)) {
185
+			glsr_log()->error('Review counts is not an array; possibly due to incorrectly imported reviews.')->debug($counts);
186
+			return [];
187
+		}
188
+		return $counts;
189
+	}
190 190
 
191
-    /**
192
-     * @param int $postId
193
-     * @return array
194
-     */
195
-    public function getPostCounts($postId)
196
-    {
197
-        return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
198
-    }
191
+	/**
192
+	 * @param int $postId
193
+	 * @return array
194
+	 */
195
+	public function getPostCounts($postId)
196
+	{
197
+		return array_filter((array) get_post_meta($postId, static::META_COUNT, true));
198
+	}
199 199
 
200
-    /**
201
-     * @param int $termId
202
-     * @return array
203
-     */
204
-    public function getTermCounts($termId)
205
-    {
206
-        return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
207
-    }
200
+	/**
201
+	 * @param int $termId
202
+	 * @return array
203
+	 */
204
+	public function getTermCounts($termId)
205
+	{
206
+		return array_filter((array) get_term_meta($termId, static::META_COUNT, true));
207
+	}
208 208
 
209
-    /**
210
-     * @return void
211
-     */
212
-    public function increase(Review $review)
213
-    {
214
-        $this->increaseCounts($review);
215
-        $this->increasePostCounts($review);
216
-        $this->increaseTermCounts($review);
217
-    }
209
+	/**
210
+	 * @return void
211
+	 */
212
+	public function increase(Review $review)
213
+	{
214
+		$this->increaseCounts($review);
215
+		$this->increasePostCounts($review);
216
+		$this->increaseTermCounts($review);
217
+	}
218 218
 
219
-    /**
220
-     * @return void
221
-     */
222
-    public function increaseCounts(Review $review)
223
-    {
224
-        if (empty($counts = $this->getCounts())) {
225
-            $counts = $this->buildCounts();
226
-        }
227
-        $this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
228
-    }
219
+	/**
220
+	 * @return void
221
+	 */
222
+	public function increaseCounts(Review $review)
223
+	{
224
+		if (empty($counts = $this->getCounts())) {
225
+			$counts = $this->buildCounts();
226
+		}
227
+		$this->setCounts($this->increaseRating($counts, $review->review_type, $review->rating));
228
+	}
229 229
 
230
-    /**
231
-     * @return void
232
-     */
233
-    public function increasePostCounts(Review $review)
234
-    {
235
-        if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
-            return;
237
-        }
238
-        $counts = $this->getPostCounts($review->assigned_to);
239
-        $counts = empty($counts)
240
-            ? $this->buildPostCounts($review->assigned_to)
241
-            : $this->increaseRating($counts, $review->review_type, $review->rating);
242
-        $this->setPostCounts($review->assigned_to, $counts);
243
-    }
230
+	/**
231
+	 * @return void
232
+	 */
233
+	public function increasePostCounts(Review $review)
234
+	{
235
+		if (!(get_post($review->assigned_to) instanceof WP_Post)) {
236
+			return;
237
+		}
238
+		$counts = $this->getPostCounts($review->assigned_to);
239
+		$counts = empty($counts)
240
+			? $this->buildPostCounts($review->assigned_to)
241
+			: $this->increaseRating($counts, $review->review_type, $review->rating);
242
+		$this->setPostCounts($review->assigned_to, $counts);
243
+	}
244 244
 
245
-    /**
246
-     * @return void
247
-     */
248
-    public function increaseTermCounts(Review $review)
249
-    {
250
-        $terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
-        foreach ($terms as $term) {
252
-            $counts = $this->getTermCounts($term['term_id']);
253
-            $counts = empty($counts)
254
-                ? $this->buildTermCounts($term['term_taxonomy_id'])
255
-                : $this->increaseRating($counts, $review->review_type, $review->rating);
256
-            $this->setTermCounts($term['term_id'], $counts);
257
-        }
258
-    }
245
+	/**
246
+	 * @return void
247
+	 */
248
+	public function increaseTermCounts(Review $review)
249
+	{
250
+		$terms = glsr(ReviewManager::class)->normalizeTerms(implode(',', $review->term_ids));
251
+		foreach ($terms as $term) {
252
+			$counts = $this->getTermCounts($term['term_id']);
253
+			$counts = empty($counts)
254
+				? $this->buildTermCounts($term['term_taxonomy_id'])
255
+				: $this->increaseRating($counts, $review->review_type, $review->rating);
256
+			$this->setTermCounts($term['term_id'], $counts);
257
+		}
258
+	}
259 259
 
260
-    /**
261
-     * @return void
262
-     */
263
-    public function setCounts(array $reviewCounts)
264
-    {
265
-        glsr(OptionManager::class)->set('counts', $reviewCounts);
266
-    }
260
+	/**
261
+	 * @return void
262
+	 */
263
+	public function setCounts(array $reviewCounts)
264
+	{
265
+		glsr(OptionManager::class)->set('counts', $reviewCounts);
266
+	}
267 267
 
268
-    /**
269
-     * @param int $postId
270
-     * @return void
271
-     */
272
-    public function setPostCounts($postId, array $reviewCounts)
273
-    {
274
-        $ratingCounts = $this->flatten($reviewCounts);
275
-        update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
-        update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
-        update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
278
-    }
268
+	/**
269
+	 * @param int $postId
270
+	 * @return void
271
+	 */
272
+	public function setPostCounts($postId, array $reviewCounts)
273
+	{
274
+		$ratingCounts = $this->flatten($reviewCounts);
275
+		update_post_meta($postId, static::META_COUNT, $reviewCounts);
276
+		update_post_meta($postId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
277
+		update_post_meta($postId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
278
+	}
279 279
 
280
-    /**
281
-     * @param int $termId
282
-     * @return void
283
-     */
284
-    public function setTermCounts($termId, array $reviewCounts)
285
-    {
286
-        $term = get_term($termId, Application::TAXONOMY);
287
-        if (!isset($term->term_id)) {
288
-            return;
289
-        }
290
-        $ratingCounts = $this->flatten($reviewCounts);
291
-        update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
-        update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
-        update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
294
-    }
280
+	/**
281
+	 * @param int $termId
282
+	 * @return void
283
+	 */
284
+	public function setTermCounts($termId, array $reviewCounts)
285
+	{
286
+		$term = get_term($termId, Application::TAXONOMY);
287
+		if (!isset($term->term_id)) {
288
+			return;
289
+		}
290
+		$ratingCounts = $this->flatten($reviewCounts);
291
+		update_term_meta($termId, static::META_COUNT, $reviewCounts);
292
+		update_term_meta($termId, static::META_AVERAGE, glsr(Rating::class)->getAverage($ratingCounts));
293
+		update_term_meta($termId, static::META_RANKING, glsr(Rating::class)->getRanking($ratingCounts));
294
+	}
295 295
 
296
-    /**
297
-     * @param string $type
298
-     * @param int $rating
299
-     * @return array
300
-     */
301
-    protected function decreaseRating(array $reviewCounts, $type, $rating)
302
-    {
303
-        if (isset($reviewCounts[$type][$rating])) {
304
-            $reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
305
-        }
306
-        return $reviewCounts;
307
-    }
296
+	/**
297
+	 * @param string $type
298
+	 * @param int $rating
299
+	 * @return array
300
+	 */
301
+	protected function decreaseRating(array $reviewCounts, $type, $rating)
302
+	{
303
+		if (isset($reviewCounts[$type][$rating])) {
304
+			$reviewCounts[$type][$rating] = max(0, $reviewCounts[$type][$rating] - 1);
305
+		}
306
+		return $reviewCounts;
307
+	}
308 308
 
309
-    /**
310
-     * @param string $type
311
-     * @param int $rating
312
-     * @return array
313
-     */
314
-    protected function increaseRating(array $reviewCounts, $type, $rating)
315
-    {
316
-        if (!array_key_exists($type, glsr()->reviewTypes)) {
317
-            return $reviewCounts;
318
-        }
319
-        if (!array_key_exists($type, $reviewCounts)) {
320
-            $reviewCounts[$type] = [];
321
-        }
322
-        $reviewCounts = $this->normalize($reviewCounts);
323
-        $reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
324
-        return $reviewCounts;
325
-    }
309
+	/**
310
+	 * @param string $type
311
+	 * @param int $rating
312
+	 * @return array
313
+	 */
314
+	protected function increaseRating(array $reviewCounts, $type, $rating)
315
+	{
316
+		if (!array_key_exists($type, glsr()->reviewTypes)) {
317
+			return $reviewCounts;
318
+		}
319
+		if (!array_key_exists($type, $reviewCounts)) {
320
+			$reviewCounts[$type] = [];
321
+		}
322
+		$reviewCounts = $this->normalize($reviewCounts);
323
+		$reviewCounts[$type][$rating] = intval($reviewCounts[$type][$rating]) + 1;
324
+		return $reviewCounts;
325
+	}
326 326
 
327
-    /**
328
-     * @return bool
329
-     */
330
-    protected function isMixedCount(array $args)
331
-    {
332
-        return !empty($args['post_ids']) && !empty($args['term_ids']);
333
-    }
327
+	/**
328
+	 * @return bool
329
+	 */
330
+	protected function isMixedCount(array $args)
331
+	{
332
+		return !empty($args['post_ids']) && !empty($args['term_ids']);
333
+	}
334 334
 
335
-    /**
336
-     * @return array
337
-     */
338
-    protected function normalize(array $reviewCounts)
339
-    {
340
-        if (empty($reviewCounts)) {
341
-            $reviewCounts = [[]];
342
-        }
343
-        foreach ($reviewCounts as &$counts) {
344
-            foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
-                if (isset($counts[$index])) {
346
-                    continue;
347
-                }
348
-                $counts[$index] = 0;
349
-            }
350
-            ksort($counts);
351
-        }
352
-        return $reviewCounts;
353
-    }
335
+	/**
336
+	 * @return array
337
+	 */
338
+	protected function normalize(array $reviewCounts)
339
+	{
340
+		if (empty($reviewCounts)) {
341
+			$reviewCounts = [[]];
342
+		}
343
+		foreach ($reviewCounts as &$counts) {
344
+			foreach (range(0, glsr()->constant('MAX_RATING', Rating::class)) as $index) {
345
+				if (isset($counts[$index])) {
346
+					continue;
347
+				}
348
+				$counts[$index] = 0;
349
+			}
350
+			ksort($counts);
351
+		}
352
+		return $reviewCounts;
353
+	}
354 354
 
355
-    /**
356
-     * @return array
357
-     */
358
-    protected function normalizeArgs(array $args)
359
-    {
360
-        $args = wp_parse_args(array_filter($args), [
361
-            'post_ids' => [],
362
-            'term_ids' => [],
363
-            'type' => 'local',
364
-        ]);
365
-        $args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']);
366
-        $args['type'] = $this->normalizeType($args['type']);
367
-        return $args;
368
-    }
355
+	/**
356
+	 * @return array
357
+	 */
358
+	protected function normalizeArgs(array $args)
359
+	{
360
+		$args = wp_parse_args(array_filter($args), [
361
+			'post_ids' => [],
362
+			'term_ids' => [],
363
+			'type' => 'local',
364
+		]);
365
+		$args['post_ids'] = glsr(Polylang::class)->getPostIds($args['post_ids']);
366
+		$args['type'] = $this->normalizeType($args['type']);
367
+		return $args;
368
+	}
369 369
 
370
-    /**
371
-     * @param string $type
372
-     * @return string
373
-     */
374
-    protected function normalizeType($type)
375
-    {
376
-        return empty($type) || !is_string($type)
377
-            ? 'local'
378
-            : $type;
379
-    }
370
+	/**
371
+	 * @param string $type
372
+	 * @return string
373
+	 */
374
+	protected function normalizeType($type)
375
+	{
376
+		return empty($type) || !is_string($type)
377
+			? 'local'
378
+			: $type;
379
+	}
380 380
 
381
-    /**
382
-     * @param int $lastPostId
383
-     * @return object
384
-     */
385
-    protected function queryReviews(array $args = [], $lastPostId = 0)
386
-    {
387
-        $reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
-        $hasMore = is_array($reviews)
389
-            ? count($reviews) == static::LIMIT
390
-            : false;
391
-        return (object) [
392
-            'has_more' => $hasMore,
393
-            'reviews' => $reviews,
394
-        ];
395
-    }
381
+	/**
382
+	 * @param int $lastPostId
383
+	 * @return object
384
+	 */
385
+	protected function queryReviews(array $args = [], $lastPostId = 0)
386
+	{
387
+		$reviews = glsr(SqlQueries::class)->getReviewCounts($args, $lastPostId, static::LIMIT);
388
+		$hasMore = is_array($reviews)
389
+			? count($reviews) == static::LIMIT
390
+			: false;
391
+		return (object) [
392
+			'has_more' => $hasMore,
393
+			'reviews' => $reviews,
394
+		];
395
+	}
396 396
 }
Please login to merge, or discard this patch.
plugin/Database/SqlQueries.php 1 patch
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -8,23 +8,23 @@  discard block
 block discarded – undo
8 8
 
9 9
 class SqlQueries
10 10
 {
11
-    protected $db;
12
-    protected $postType;
11
+	protected $db;
12
+	protected $postType;
13 13
 
14
-    public function __construct()
15
-    {
16
-        global $wpdb;
17
-        $this->db = $wpdb;
18
-        $this->postType = Application::POST_TYPE;
19
-    }
14
+	public function __construct()
15
+	{
16
+		global $wpdb;
17
+		$this->db = $wpdb;
18
+		$this->postType = Application::POST_TYPE;
19
+	}
20 20
 
21
-    /**
22
-     * @param string $metaReviewId
23
-     * @return int
24
-     */
25
-    public function getPostIdFromReviewId($metaReviewId)
26
-    {
27
-        $postId = $this->db->get_var("
21
+	/**
22
+	 * @param string $metaReviewId
23
+	 * @return int
24
+	 */
25
+	public function getPostIdFromReviewId($metaReviewId)
26
+	{
27
+		$postId = $this->db->get_var("
28 28
             SELECT p.ID
29 29
             FROM {$this->db->posts} AS p
30 30
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
             AND m.meta_key = '_review_id'
33 33
             AND m.meta_value = '{$metaReviewId}'
34 34
         ");
35
-        return intval($postId);
36
-    }
35
+		return intval($postId);
36
+	}
37 37
 
38
-    /**
39
-     * @param int $lastPostId
40
-     * @param int $limit
41
-     * @return array
42
-     */
43
-    public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
44
-    {
45
-        return (array) $this->db->get_results("
38
+	/**
39
+	 * @param int $lastPostId
40
+	 * @param int $limit
41
+	 * @return array
42
+	 */
43
+	public function getReviewCounts(array $args, $lastPostId = 0, $limit = 500)
44
+	{
45
+		return (array) $this->db->get_results("
46 46
             SELECT DISTINCT p.ID, m1.meta_value AS rating, m2.meta_value AS type
47 47
             FROM {$this->db->posts} AS p
48 48
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -57,17 +57,17 @@  discard block
 block discarded – undo
57 57
             ORDER By p.ID ASC
58 58
             LIMIT {$limit}
59 59
         ");
60
-    }
60
+	}
61 61
 
62
-    /**
63
-     * @todo remove this?
64
-     * @param string $metaKey
65
-     * @return array
66
-     */
67
-    public function getReviewCountsFor($metaKey)
68
-    {
69
-        $metaKey = Str::prefix('_', $metaKey);
70
-        return (array) $this->db->get_results("
62
+	/**
63
+	 * @todo remove this?
64
+	 * @param string $metaKey
65
+	 * @return array
66
+	 */
67
+	public function getReviewCountsFor($metaKey)
68
+	{
69
+		$metaKey = Str::prefix('_', $metaKey);
70
+		return (array) $this->db->get_results("
71 71
             SELECT DISTINCT m.meta_value AS name, COUNT(*) num_posts
72 72
             FROM {$this->db->posts} AS p
73 73
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
             AND m.meta_key = '{$metaKey}'
76 76
             GROUP BY name
77 77
         ");
78
-    }
78
+	}
79 79
 
80
-    /**
81
-     * @todo remove this?
82
-     * @param string $reviewType
83
-     * @return array
84
-     */
85
-    public function getReviewIdsByType($reviewType)
86
-    {
87
-        $results = $this->db->get_col("
80
+	/**
81
+	 * @todo remove this?
82
+	 * @param string $reviewType
83
+	 * @return array
84
+	 */
85
+	public function getReviewIdsByType($reviewType)
86
+	{
87
+		$results = $this->db->get_col("
88 88
             SELECT DISTINCT m1.meta_value AS review_id
89 89
             FROM {$this->db->posts} AS p
90 90
             INNER JOIN {$this->db->postmeta} AS m1 ON p.ID = m1.post_id
@@ -94,20 +94,20 @@  discard block
 block discarded – undo
94 94
             AND m2.meta_key = '_review_type'
95 95
             AND m2.meta_value = '{$reviewType}'
96 96
         ");
97
-        return array_keys(array_flip($results));
98
-    }
97
+		return array_keys(array_flip($results));
98
+	}
99 99
 
100
-    /**
101
-     * @param int $greaterThanId
102
-     * @param int $limit
103
-     * @return array
104
-     */
105
-    public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
106
-    {
107
-        sort($postIds);
108
-        $postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
109
-        $postIds = implode(',', $postIds);
110
-        return (array) $this->db->get_results("
100
+	/**
101
+	 * @param int $greaterThanId
102
+	 * @param int $limit
103
+	 * @return array
104
+	 */
105
+	public function getReviewRatingsFromIds(array $postIds, $greaterThanId = 0, $limit = 100)
106
+	{
107
+		sort($postIds);
108
+		$postIds = array_slice($postIds, intval(array_search($greaterThanId, $postIds)), $limit);
109
+		$postIds = implode(',', $postIds);
110
+		return (array) $this->db->get_results("
111 111
             SELECT p.ID, m.meta_value AS rating
112 112
             FROM {$this->db->posts} AS p
113 113
             INNER JOIN {$this->db->postmeta} AS m ON p.ID = m.post_id
@@ -120,17 +120,17 @@  discard block
 block discarded – undo
120 120
             ORDER By p.ID ASC
121 121
             LIMIT {$limit}
122 122
         ");
123
-    }
123
+	}
124 124
 
125
-    /**
126
-     * @param string $key
127
-     * @param string $status
128
-     * @return array
129
-     */
130
-    public function getReviewsMeta($key, $status = 'publish')
131
-    {
132
-        $key = Str::prefix('_', $key);
133
-        $values = $this->db->get_col("
125
+	/**
126
+	 * @param string $key
127
+	 * @param string $status
128
+	 * @return array
129
+	 */
130
+	public function getReviewsMeta($key, $status = 'publish')
131
+	{
132
+		$key = Str::prefix('_', $key);
133
+		$values = $this->db->get_col("
134 134
             SELECT DISTINCT m.meta_value
135 135
             FROM {$this->db->postmeta} m
136 136
             LEFT JOIN {$this->db->posts} p ON p.ID = m.post_id
@@ -141,42 +141,42 @@  discard block
 block discarded – undo
141 141
             GROUP BY p.ID -- remove duplicate meta_value entries
142 142
             ORDER BY m.meta_id ASC -- sort by oldest meta_value
143 143
         ");
144
-        sort($values);
145
-        return $values;
146
-    }
144
+		sort($values);
145
+		return $values;
146
+	}
147 147
 
148
-    /**
149
-     * @param string $and
150
-     * @return string
151
-     */
152
-    protected function getAndForCounts(array $args, $and = '')
153
-    {
154
-        $postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
155
-        $termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
156
-        if (!empty($args['type'])) {
157
-            $and.= "AND m2.meta_value = '{$args['type']}' ";
158
-        }
159
-        if ($postIds) {
160
-            $and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
161
-        }
162
-        if ($termIds) {
163
-            $and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
164
-        }
165
-        return apply_filters('site-reviews/query/and-for-counts', $and);
166
-    }
148
+	/**
149
+	 * @param string $and
150
+	 * @return string
151
+	 */
152
+	protected function getAndForCounts(array $args, $and = '')
153
+	{
154
+		$postIds = implode(',', array_filter(Arr::get($args, 'post_ids', [])));
155
+		$termIds = implode(',', array_filter(Arr::get($args, 'term_ids', [])));
156
+		if (!empty($args['type'])) {
157
+			$and.= "AND m2.meta_value = '{$args['type']}' ";
158
+		}
159
+		if ($postIds) {
160
+			$and.= "AND m3.meta_key = '_assigned_to' AND m3.meta_value IN ({$postIds}) ";
161
+		}
162
+		if ($termIds) {
163
+			$and.= "AND tr.term_taxonomy_id IN ({$termIds}) ";
164
+		}
165
+		return apply_filters('site-reviews/query/and-for-counts', $and);
166
+	}
167 167
 
168
-    /**
169
-     * @param string $innerJoin
170
-     * @return string
171
-     */
172
-    protected function getInnerJoinForCounts(array $args, $innerJoin = '')
173
-    {
174
-        if (!empty(Arr::get($args, 'post_ids'))) {
175
-            $innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
176
-        }
177
-        if (!empty(Arr::get($args, 'term_ids'))) {
178
-            $innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
179
-        }
180
-        return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
181
-    }
168
+	/**
169
+	 * @param string $innerJoin
170
+	 * @return string
171
+	 */
172
+	protected function getInnerJoinForCounts(array $args, $innerJoin = '')
173
+	{
174
+		if (!empty(Arr::get($args, 'post_ids'))) {
175
+			$innerJoin.= "INNER JOIN {$this->db->postmeta} AS m3 ON p.ID = m3.post_id ";
176
+		}
177
+		if (!empty(Arr::get($args, 'term_ids'))) {
178
+			$innerJoin.= "INNER JOIN {$this->db->term_relationships} AS tr ON p.ID = tr.object_id ";
179
+		}
180
+		return apply_filters('site-reviews/query/inner-join-for-counts', $innerJoin);
181
+	}
182 182
 }
Please login to merge, or discard this patch.
plugin/Controllers/TaxonomyController.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -8,97 +8,97 @@
 block discarded – undo
8 8
 
9 9
 class TaxonomyController
10 10
 {
11
-    /**
12
-     * @return void
13
-     * @action Application::TAXONOMY._add_form_fields
14
-     * @action Application::TAXONOMY._edit_form
15
-     */
16
-    public function disableParents()
17
-    {
18
-        global $wp_taxonomies;
19
-        $wp_taxonomies[Application::TAXONOMY]->hierarchical = false;
20
-    }
11
+	/**
12
+	 * @return void
13
+	 * @action Application::TAXONOMY._add_form_fields
14
+	 * @action Application::TAXONOMY._edit_form
15
+	 */
16
+	public function disableParents()
17
+	{
18
+		global $wp_taxonomies;
19
+		$wp_taxonomies[Application::TAXONOMY]->hierarchical = false;
20
+	}
21 21
 
22
-    /**
23
-     * @return void
24
-     * @action Application::TAXONOMY._term_edit_form_top
25
-     * @action Application::TAXONOMY._term_new_form_tag
26
-     */
27
-    public function enableParents()
28
-    {
29
-        global $wp_taxonomies;
30
-        $wp_taxonomies[Application::TAXONOMY]->hierarchical = true;
31
-    }
22
+	/**
23
+	 * @return void
24
+	 * @action Application::TAXONOMY._term_edit_form_top
25
+	 * @action Application::TAXONOMY._term_new_form_tag
26
+	 */
27
+	public function enableParents()
28
+	{
29
+		global $wp_taxonomies;
30
+		$wp_taxonomies[Application::TAXONOMY]->hierarchical = true;
31
+	}
32 32
 
33
-    /**
34
-     * @return void
35
-     * @action restrict_manage_posts
36
-     */
37
-    public function renderTaxonomyFilter()
38
-    {
39
-        if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) {
40
-            return;
41
-        }
42
-        echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [
43
-            'class' => 'screen-reader-text',
44
-            'for' => Application::TAXONOMY,
45
-        ]);
46
-        wp_dropdown_categories([
47
-            'depth' => 3,
48
-            'hide_empty' => true,
49
-            'hide_if_empty' => true,
50
-            'hierarchical' => true,
51
-            'name' => Application::TAXONOMY,
52
-            'orderby' => 'name',
53
-            'selected' => $this->getSelected(),
54
-            'show_count' => false,
55
-            'show_option_all' => $this->getShowOptionAll(),
56
-            'taxonomy' => Application::TAXONOMY,
57
-            'value_field' => 'slug',
58
-        ]);
59
-    }
33
+	/**
34
+	 * @return void
35
+	 * @action restrict_manage_posts
36
+	 */
37
+	public function renderTaxonomyFilter()
38
+	{
39
+		if (!is_object_in_taxonomy(glsr_current_screen()->post_type, Application::TAXONOMY)) {
40
+			return;
41
+		}
42
+		echo glsr(Builder::class)->label(__('Filter by category', 'site-reviews'), [
43
+			'class' => 'screen-reader-text',
44
+			'for' => Application::TAXONOMY,
45
+		]);
46
+		wp_dropdown_categories([
47
+			'depth' => 3,
48
+			'hide_empty' => true,
49
+			'hide_if_empty' => true,
50
+			'hierarchical' => true,
51
+			'name' => Application::TAXONOMY,
52
+			'orderby' => 'name',
53
+			'selected' => $this->getSelected(),
54
+			'show_count' => false,
55
+			'show_option_all' => $this->getShowOptionAll(),
56
+			'taxonomy' => Application::TAXONOMY,
57
+			'value_field' => 'slug',
58
+		]);
59
+	}
60 60
 
61
-    /**
62
-     * @param int $postId
63
-     * @param array $terms
64
-     * @param array $newTTIds
65
-     * @param string $taxonomy
66
-     * @param bool $append
67
-     * @param array $oldTTIds
68
-     * @return void
69
-     * @action set_object_terms
70
-     */
71
-    public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
72
-    {
73
-        if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) {
74
-            return;
75
-        }
76
-        $diff = array_diff($newTTIds, $oldTTIds);
77
-        if (empty($newTerm = array_shift($diff))) {
78
-            $newTerm = array_shift($newTTIds);
79
-        }
80
-        if ($newTerm) {
81
-            wp_set_object_terms($postId, intval($newTerm), $taxonomy);
82
-        }
83
-    }
61
+	/**
62
+	 * @param int $postId
63
+	 * @param array $terms
64
+	 * @param array $newTTIds
65
+	 * @param string $taxonomy
66
+	 * @param bool $append
67
+	 * @param array $oldTTIds
68
+	 * @return void
69
+	 * @action set_object_terms
70
+	 */
71
+	public function restrictTermSelection($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
72
+	{
73
+		if (Application::TAXONOMY != $taxonomy || count($newTTIds) <= 1) {
74
+			return;
75
+		}
76
+		$diff = array_diff($newTTIds, $oldTTIds);
77
+		if (empty($newTerm = array_shift($diff))) {
78
+			$newTerm = array_shift($newTTIds);
79
+		}
80
+		if ($newTerm) {
81
+			wp_set_object_terms($postId, intval($newTerm), $taxonomy);
82
+		}
83
+	}
84 84
 
85
-    /**
86
-     * @return string
87
-     */
88
-    protected function getSelected()
89
-    {
90
-        global $wp_query;
91
-        return Arr::get($wp_query->query, Application::TAXONOMY);
92
-    }
85
+	/**
86
+	 * @return string
87
+	 */
88
+	protected function getSelected()
89
+	{
90
+		global $wp_query;
91
+		return Arr::get($wp_query->query, Application::TAXONOMY);
92
+	}
93 93
 
94
-    /**
95
-     * @return string
96
-     */
97
-    protected function getShowOptionAll()
98
-    {
99
-        $taxonomy = get_taxonomy(Application::TAXONOMY);
100
-        return $taxonomy
101
-            ? ucfirst(strtolower($taxonomy->labels->all_items))
102
-            : '';
103
-    }
94
+	/**
95
+	 * @return string
96
+	 */
97
+	protected function getShowOptionAll()
98
+	{
99
+		$taxonomy = get_taxonomy(Application::TAXONOMY);
100
+		return $taxonomy
101
+			? ucfirst(strtolower($taxonomy->labels->all_items))
102
+			: '';
103
+	}
104 104
 }
Please login to merge, or discard this patch.
plugin/Controllers/ReviewController.php 1 patch
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -13,139 +13,139 @@
 block discarded – undo
13 13
 
14 14
 class ReviewController extends Controller
15 15
 {
16
-    /**
17
-     * @param int $postId
18
-     * @param array $terms
19
-     * @param array $newTTIds
20
-     * @param string $taxonomy
21
-     * @param bool $append
22
-     * @param array $oldTTIds
23
-     * @return void
24
-     * @action set_object_terms
25
-     */
26
-    public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
27
-    {
28
-        sort($newTTIds);
29
-        sort($oldTTIds);
30
-        if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) {
31
-            return;
32
-        }
33
-        $review = glsr_get_review($postId);
34
-        $ignoredIds = array_intersect($oldTTIds, $newTTIds);
35
-        $decreasedIds = array_diff($oldTTIds, $ignoredIds);
36
-        $increasedIds = array_diff($newTTIds, $ignoredIds);
37
-        if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) {
38
-            glsr(CountsManager::class)->decreaseTermCounts($review);
39
-        }
40
-        if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) {
41
-            glsr(CountsManager::class)->increaseTermCounts($review);
42
-        }
43
-    }
16
+	/**
17
+	 * @param int $postId
18
+	 * @param array $terms
19
+	 * @param array $newTTIds
20
+	 * @param string $taxonomy
21
+	 * @param bool $append
22
+	 * @param array $oldTTIds
23
+	 * @return void
24
+	 * @action set_object_terms
25
+	 */
26
+	public function onAfterChangeCategory($postId, $terms, $newTTIds, $taxonomy, $append, $oldTTIds)
27
+	{
28
+		sort($newTTIds);
29
+		sort($oldTTIds);
30
+		if ($newTTIds === $oldTTIds || !$this->isReviewPostId($postId)) {
31
+			return;
32
+		}
33
+		$review = glsr_get_review($postId);
34
+		$ignoredIds = array_intersect($oldTTIds, $newTTIds);
35
+		$decreasedIds = array_diff($oldTTIds, $ignoredIds);
36
+		$increasedIds = array_diff($newTTIds, $ignoredIds);
37
+		if ($review->term_ids = glsr(Database::class)->getTermIds($decreasedIds, 'term_taxonomy_id')) {
38
+			glsr(CountsManager::class)->decreaseTermCounts($review);
39
+		}
40
+		if ($review->term_ids = glsr(Database::class)->getTermIds($increasedIds, 'term_taxonomy_id')) {
41
+			glsr(CountsManager::class)->increaseTermCounts($review);
42
+		}
43
+	}
44 44
 
45
-    /**
46
-     * @param string $oldStatus
47
-     * @param string $newStatus
48
-     * @param WP_Post $post
49
-     * @return void
50
-     * @action transition_post_status
51
-     */
52
-    public function onAfterChangeStatus($newStatus, $oldStatus, $post)
53
-    {
54
-        if (Application::POST_TYPE != Arr::get($post, 'post_type') || in_array($oldStatus, ['new', $newStatus])) {
55
-            return;
56
-        }
57
-        $review = glsr_get_review($post);
58
-        if ('publish' == $post->post_status) {
59
-            glsr(CountsManager::class)->increase($review);
60
-        } else {
61
-            glsr(CountsManager::class)->decrease($review);
62
-        }
63
-    }
45
+	/**
46
+	 * @param string $oldStatus
47
+	 * @param string $newStatus
48
+	 * @param WP_Post $post
49
+	 * @return void
50
+	 * @action transition_post_status
51
+	 */
52
+	public function onAfterChangeStatus($newStatus, $oldStatus, $post)
53
+	{
54
+		if (Application::POST_TYPE != Arr::get($post, 'post_type') || in_array($oldStatus, ['new', $newStatus])) {
55
+			return;
56
+		}
57
+		$review = glsr_get_review($post);
58
+		if ('publish' == $post->post_status) {
59
+			glsr(CountsManager::class)->increase($review);
60
+		} else {
61
+			glsr(CountsManager::class)->decrease($review);
62
+		}
63
+	}
64 64
 
65
-    /**
66
-     * @return void
67
-     * @action site-reviews/review/created
68
-     */
69
-    public function onAfterCreate(Review $review)
70
-    {
71
-        if ('publish' !== $review->status) {
72
-            return;
73
-        }
74
-        glsr(CountsManager::class)->increaseCounts($review);
75
-        glsr(CountsManager::class)->increasePostCounts($review);
76
-    }
65
+	/**
66
+	 * @return void
67
+	 * @action site-reviews/review/created
68
+	 */
69
+	public function onAfterCreate(Review $review)
70
+	{
71
+		if ('publish' !== $review->status) {
72
+			return;
73
+		}
74
+		glsr(CountsManager::class)->increaseCounts($review);
75
+		glsr(CountsManager::class)->increasePostCounts($review);
76
+	}
77 77
 
78
-    /**
79
-     * @param int $postId
80
-     * @return void
81
-     * @action before_delete_post
82
-     */
83
-    public function onBeforeDelete($postId)
84
-    {
85
-        if (!$this->isReviewPostId($postId)) {
86
-            return;
87
-        }
88
-        $review = glsr_get_review($postId);
89
-        if ('trash' !== $review->status) { // do not run for trashed posts
90
-            glsr(CountsManager::class)->decrease($review);
91
-        }
92
-    }
78
+	/**
79
+	 * @param int $postId
80
+	 * @return void
81
+	 * @action before_delete_post
82
+	 */
83
+	public function onBeforeDelete($postId)
84
+	{
85
+		if (!$this->isReviewPostId($postId)) {
86
+			return;
87
+		}
88
+		$review = glsr_get_review($postId);
89
+		if ('trash' !== $review->status) { // do not run for trashed posts
90
+			glsr(CountsManager::class)->decrease($review);
91
+		}
92
+	}
93 93
 
94
-    /**
95
-     * @param int $metaId
96
-     * @param int $postId
97
-     * @param string $metaKey
98
-     * @param mixed $metaValue
99
-     * @return void
100
-     * @action update_postmeta
101
-     */
102
-    public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue)
103
-    {
104
-        if (!$this->isReviewPostId($postId)) {
105
-            return;
106
-        }
107
-        $metaKey = Str::removePrefix('_', $metaKey);
108
-        if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) {
109
-            return;
110
-        }
111
-        $review = glsr_get_review($postId);
112
-        if ($review->$metaKey == $metaValue) {
113
-            return;
114
-        }
115
-        $method = Helper::buildMethodName($metaKey, 'onBeforeChange');
116
-        call_user_func([$this, $method], $review, $metaValue);
117
-    }
94
+	/**
95
+	 * @param int $metaId
96
+	 * @param int $postId
97
+	 * @param string $metaKey
98
+	 * @param mixed $metaValue
99
+	 * @return void
100
+	 * @action update_postmeta
101
+	 */
102
+	public function onBeforeUpdate($metaId, $postId, $metaKey, $metaValue)
103
+	{
104
+		if (!$this->isReviewPostId($postId)) {
105
+			return;
106
+		}
107
+		$metaKey = Str::removePrefix('_', $metaKey);
108
+		if (!in_array($metaKey, ['assigned_to', 'rating', 'review_type'])) {
109
+			return;
110
+		}
111
+		$review = glsr_get_review($postId);
112
+		if ($review->$metaKey == $metaValue) {
113
+			return;
114
+		}
115
+		$method = Helper::buildMethodName($metaKey, 'onBeforeChange');
116
+		call_user_func([$this, $method], $review, $metaValue);
117
+	}
118 118
 
119
-    /**
120
-     * @param string|int $assignedTo
121
-     * @return void
122
-     */
123
-    public function onBeforeChangeAssignedTo(Review $review, $assignedTo)
124
-    {
125
-        glsr(CountsManager::class)->decreasePostCounts($review);
126
-        $review->assigned_to = $assignedTo;
127
-        glsr(CountsManager::class)->increasePostCounts($review);
128
-    }
119
+	/**
120
+	 * @param string|int $assignedTo
121
+	 * @return void
122
+	 */
123
+	public function onBeforeChangeAssignedTo(Review $review, $assignedTo)
124
+	{
125
+		glsr(CountsManager::class)->decreasePostCounts($review);
126
+		$review->assigned_to = $assignedTo;
127
+		glsr(CountsManager::class)->increasePostCounts($review);
128
+	}
129 129
 
130
-    /**
131
-     * @param string|int $rating
132
-     * @return void
133
-     */
134
-    public function onBeforeChangeRating(Review $review, $rating)
135
-    {
136
-        glsr(CountsManager::class)->decrease($review);
137
-        $review->rating = $rating;
138
-        glsr(CountsManager::class)->increase($review);
139
-    }
130
+	/**
131
+	 * @param string|int $rating
132
+	 * @return void
133
+	 */
134
+	public function onBeforeChangeRating(Review $review, $rating)
135
+	{
136
+		glsr(CountsManager::class)->decrease($review);
137
+		$review->rating = $rating;
138
+		glsr(CountsManager::class)->increase($review);
139
+	}
140 140
 
141
-    /**
142
-     * @param string $reviewType
143
-     * @return void
144
-     */
145
-    public function onBeforeChangeReviewType(Review $review, $reviewType)
146
-    {
147
-        glsr(CountsManager::class)->decrease($review);
148
-        $review->review_type = $reviewType;
149
-        glsr(CountsManager::class)->increase($review);
150
-    }
141
+	/**
142
+	 * @param string $reviewType
143
+	 * @return void
144
+	 */
145
+	public function onBeforeChangeReviewType(Review $review, $reviewType)
146
+	{
147
+		glsr(CountsManager::class)->decrease($review);
148
+		$review->review_type = $reviewType;
149
+		glsr(CountsManager::class)->increase($review);
150
+	}
151 151
 }
Please login to merge, or discard this patch.
plugin/Controllers/AdminController.php 1 patch
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -16,222 +16,222 @@
 block discarded – undo
16 16
 
17 17
 class AdminController extends Controller
18 18
 {
19
-    /**
20
-     * @return void
21
-     * @action admin_enqueue_scripts
22
-     */
23
-    public function enqueueAssets()
24
-    {
25
-        $command = new EnqueueAdminAssets([
26
-            'pointers' => [[
27
-                'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'),
28
-                'id' => 'glsr-pointer-pinned',
29
-                'position' => [
30
-                    'edge' => 'right',
31
-                    'align' => 'middle',
32
-                ],
33
-                'screen' => Application::POST_TYPE,
34
-                'target' => '#misc-pub-pinned',
35
-                'title' => __('Pin Your Reviews', 'site-reviews'),
36
-            ]],
37
-        ]);
38
-        $this->execute($command);
39
-    }
40
-
41
-    /**
42
-     * @return array
43
-     * @filter plugin_action_links_site-reviews/site-reviews.php
44
-     */
45
-    public function filterActionLinks(array $links)
46
-    {
47
-        $links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [
48
-            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'),
49
-        ]);
50
-        $links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [
51
-            'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'),
52
-        ]);
53
-        return $links;
54
-    }
55
-
56
-    /**
57
-     * @param array $capabilities
58
-     * @param string $capability
59
-     * @return array
60
-     * @filter map_meta_cap
61
-     */
62
-    public function filterCreateCapability($capabilities, $capability)
63
-    {
64
-        if ($capability == 'create_'.Application::POST_TYPE) {
65
-            $capabilities[] = 'do_not_allow';
66
-        }
67
-        return $capabilities;
68
-    }
69
-
70
-    /**
71
-     * @param array $items
72
-     * @return array
73
-     * @filter dashboard_glance_items
74
-     */
75
-    public function filterDashboardGlanceItems($items)
76
-    {
77
-        $postCount = wp_count_posts(Application::POST_TYPE);
78
-        if (empty($postCount->publish)) {
79
-            return $items;
80
-        }
81
-        $text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews');
82
-        $text = sprintf($text, number_format_i18n($postCount->publish));
83
-        $items = Arr::consolidateArray($items);
84
-        $items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts)
85
-            ? glsr(Builder::class)->a($text, [
86
-                'class' => 'glsr-review-count',
87
-                'href' => 'edit.php?post_type='.Application::POST_TYPE,
88
-            ])
89
-            : glsr(Builder::class)->span($text, [
90
-                'class' => 'glsr-review-count',
91
-            ]);
92
-        return $items;
93
-    }
94
-
95
-    /**
96
-     * @param array $plugins
97
-     * @return array
98
-     * @filter mce_external_plugins
99
-     */
100
-    public function filterTinymcePlugins($plugins)
101
-    {
102
-        if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
103
-            $plugins = Arr::consolidateArray($plugins);
104
-            $plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js');
105
-        }
106
-        return $plugins;
107
-    }
108
-
109
-    /**
110
-     * @return void
111
-     * @action admin_init
112
-     */
113
-    public function registerTinymcePopups()
114
-    {
115
-        $command = new RegisterTinymcePopups([
116
-            'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'),
117
-            'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'),
118
-            'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'),
119
-        ]);
120
-        $this->execute($command);
121
-    }
122
-
123
-    /**
124
-     * @param string $editorId
125
-     * @return void|null
126
-     * @action media_buttons
127
-     */
128
-    public function renderTinymceButton($editorId)
129
-    {
130
-        $allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId);
131
-        if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) {
132
-            return;
133
-        }
134
-        $shortcodes = [];
135
-        foreach (glsr()->mceShortcodes as $shortcode => $values) {
136
-            $shortcodes[$shortcode] = $values;
137
-        }
138
-        if (empty($shortcodes)) {
139
-            return;
140
-        }
141
-        glsr()->render('partials/editor/tinymce', [
142
-            'shortcodes' => $shortcodes,
143
-        ]);
144
-    }
145
-
146
-    /**
147
-     * @return void
148
-     */
149
-    public function routerClearConsole()
150
-    {
151
-        glsr(Console::class)->clear();
152
-        glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews'));
153
-    }
154
-
155
-    /**
156
-     * @return void
157
-     */
158
-    public function routerFetchConsole()
159
-    {
160
-        glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews'));
161
-    }
162
-
163
-    /**
164
-     * @param bool $showNotice
165
-     * @return void
166
-     */
167
-    public function routerCountReviews($showNotice = true)
168
-    {
169
-        glsr(CountsManager::class)->countAll();
170
-        glsr(OptionManager::class)->set('last_review_count', current_time('timestamp'));
171
-        if ($showNotice) {
172
-            glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews'));
173
-        }
174
-    }
175
-
176
-    /**
177
-     * @return void
178
-     */
179
-    public function routerDownloadConsole()
180
-    {
181
-        $this->download(Application::ID.'-console.txt', glsr(Console::class)->get());
182
-    }
183
-
184
-    /**
185
-     * @return void
186
-     */
187
-    public function routerDownloadSystemInfo()
188
-    {
189
-        $this->download(Application::ID.'-system-info.txt', glsr(System::class)->get());
190
-    }
191
-
192
-    /**
193
-     * @return void
194
-     */
195
-    public function routerExportSettings()
196
-    {
197
-        $this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json());
198
-    }
199
-
200
-    /**
201
-     * @return void
202
-     */
203
-    public function routerImportSettings()
204
-    {
205
-        $file = $_FILES['import-file'];
206
-        if (UPLOAD_ERR_OK !== $file['error']) {
207
-            return glsr(Notice::class)->addError($this->getUploadError($file['error']));
208
-        }
209
-        if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) {
210
-            return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews'));
211
-        }
212
-        $settings = json_decode(file_get_contents($file['tmp_name']), true);
213
-        if (empty($settings)) {
214
-            return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews'));
215
-        }
216
-        glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings));
217
-        glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews'));
218
-    }
219
-
220
-    /**
221
-     * @param int $errorCode
222
-     * @return string
223
-     */
224
-    protected function getUploadError($errorCode)
225
-    {
226
-        $errors = [
227
-            UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'),
228
-            UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'),
229
-            UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'),
230
-            UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'),
231
-            UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'),
232
-            UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'),
233
-            UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'),
234
-        ];
235
-        return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews'));
236
-    }
19
+	/**
20
+	 * @return void
21
+	 * @action admin_enqueue_scripts
22
+	 */
23
+	public function enqueueAssets()
24
+	{
25
+		$command = new EnqueueAdminAssets([
26
+			'pointers' => [[
27
+				'content' => __('You can pin exceptional reviews so that they are always shown first.', 'site-reviews'),
28
+				'id' => 'glsr-pointer-pinned',
29
+				'position' => [
30
+					'edge' => 'right',
31
+					'align' => 'middle',
32
+				],
33
+				'screen' => Application::POST_TYPE,
34
+				'target' => '#misc-pub-pinned',
35
+				'title' => __('Pin Your Reviews', 'site-reviews'),
36
+			]],
37
+		]);
38
+		$this->execute($command);
39
+	}
40
+
41
+	/**
42
+	 * @return array
43
+	 * @filter plugin_action_links_site-reviews/site-reviews.php
44
+	 */
45
+	public function filterActionLinks(array $links)
46
+	{
47
+		$links['documentation'] = glsr(Builder::class)->a(__('Help', 'site-reviews'), [
48
+			'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=documentation'),
49
+		]);
50
+		$links['settings'] = glsr(Builder::class)->a(__('Settings', 'site-reviews'), [
51
+			'href' => admin_url('edit.php?post_type='.Application::POST_TYPE.'&page=settings'),
52
+		]);
53
+		return $links;
54
+	}
55
+
56
+	/**
57
+	 * @param array $capabilities
58
+	 * @param string $capability
59
+	 * @return array
60
+	 * @filter map_meta_cap
61
+	 */
62
+	public function filterCreateCapability($capabilities, $capability)
63
+	{
64
+		if ($capability == 'create_'.Application::POST_TYPE) {
65
+			$capabilities[] = 'do_not_allow';
66
+		}
67
+		return $capabilities;
68
+	}
69
+
70
+	/**
71
+	 * @param array $items
72
+	 * @return array
73
+	 * @filter dashboard_glance_items
74
+	 */
75
+	public function filterDashboardGlanceItems($items)
76
+	{
77
+		$postCount = wp_count_posts(Application::POST_TYPE);
78
+		if (empty($postCount->publish)) {
79
+			return $items;
80
+		}
81
+		$text = _n('%s Review', '%s Reviews', $postCount->publish, 'site-reviews');
82
+		$text = sprintf($text, number_format_i18n($postCount->publish));
83
+		$items = Arr::consolidateArray($items);
84
+		$items[] = current_user_can(get_post_type_object(Application::POST_TYPE)->cap->edit_posts)
85
+			? glsr(Builder::class)->a($text, [
86
+				'class' => 'glsr-review-count',
87
+				'href' => 'edit.php?post_type='.Application::POST_TYPE,
88
+			])
89
+			: glsr(Builder::class)->span($text, [
90
+				'class' => 'glsr-review-count',
91
+			]);
92
+		return $items;
93
+	}
94
+
95
+	/**
96
+	 * @param array $plugins
97
+	 * @return array
98
+	 * @filter mce_external_plugins
99
+	 */
100
+	public function filterTinymcePlugins($plugins)
101
+	{
102
+		if (current_user_can('edit_posts') || current_user_can('edit_pages')) {
103
+			$plugins = Arr::consolidateArray($plugins);
104
+			$plugins['glsr_shortcode'] = glsr()->url('assets/scripts/mce-plugin.js');
105
+		}
106
+		return $plugins;
107
+	}
108
+
109
+	/**
110
+	 * @return void
111
+	 * @action admin_init
112
+	 */
113
+	public function registerTinymcePopups()
114
+	{
115
+		$command = new RegisterTinymcePopups([
116
+			'site_reviews' => esc_html__('Recent Reviews', 'site-reviews'),
117
+			'site_reviews_form' => esc_html__('Submit a Review', 'site-reviews'),
118
+			'site_reviews_summary' => esc_html__('Summary of Reviews', 'site-reviews'),
119
+		]);
120
+		$this->execute($command);
121
+	}
122
+
123
+	/**
124
+	 * @param string $editorId
125
+	 * @return void|null
126
+	 * @action media_buttons
127
+	 */
128
+	public function renderTinymceButton($editorId)
129
+	{
130
+		$allowedEditors = apply_filters('site-reviews/tinymce/editor-ids', ['content'], $editorId);
131
+		if ('post' != glsr_current_screen()->base || !in_array($editorId, $allowedEditors)) {
132
+			return;
133
+		}
134
+		$shortcodes = [];
135
+		foreach (glsr()->mceShortcodes as $shortcode => $values) {
136
+			$shortcodes[$shortcode] = $values;
137
+		}
138
+		if (empty($shortcodes)) {
139
+			return;
140
+		}
141
+		glsr()->render('partials/editor/tinymce', [
142
+			'shortcodes' => $shortcodes,
143
+		]);
144
+	}
145
+
146
+	/**
147
+	 * @return void
148
+	 */
149
+	public function routerClearConsole()
150
+	{
151
+		glsr(Console::class)->clear();
152
+		glsr(Notice::class)->addSuccess(__('Console cleared.', 'site-reviews'));
153
+	}
154
+
155
+	/**
156
+	 * @return void
157
+	 */
158
+	public function routerFetchConsole()
159
+	{
160
+		glsr(Notice::class)->addSuccess(__('Console reloaded.', 'site-reviews'));
161
+	}
162
+
163
+	/**
164
+	 * @param bool $showNotice
165
+	 * @return void
166
+	 */
167
+	public function routerCountReviews($showNotice = true)
168
+	{
169
+		glsr(CountsManager::class)->countAll();
170
+		glsr(OptionManager::class)->set('last_review_count', current_time('timestamp'));
171
+		if ($showNotice) {
172
+			glsr(Notice::class)->clear()->addSuccess(__('Recalculated rating counts.', 'site-reviews'));
173
+		}
174
+	}
175
+
176
+	/**
177
+	 * @return void
178
+	 */
179
+	public function routerDownloadConsole()
180
+	{
181
+		$this->download(Application::ID.'-console.txt', glsr(Console::class)->get());
182
+	}
183
+
184
+	/**
185
+	 * @return void
186
+	 */
187
+	public function routerDownloadSystemInfo()
188
+	{
189
+		$this->download(Application::ID.'-system-info.txt', glsr(System::class)->get());
190
+	}
191
+
192
+	/**
193
+	 * @return void
194
+	 */
195
+	public function routerExportSettings()
196
+	{
197
+		$this->download(Application::ID.'-settings.json', glsr(OptionManager::class)->json());
198
+	}
199
+
200
+	/**
201
+	 * @return void
202
+	 */
203
+	public function routerImportSettings()
204
+	{
205
+		$file = $_FILES['import-file'];
206
+		if (UPLOAD_ERR_OK !== $file['error']) {
207
+			return glsr(Notice::class)->addError($this->getUploadError($file['error']));
208
+		}
209
+		if ('application/json' !== $file['type'] || !Str::endsWith('.json', $file['name'])) {
210
+			return glsr(Notice::class)->addError(__('Please use a valid Site Reviews settings file.', 'site-reviews'));
211
+		}
212
+		$settings = json_decode(file_get_contents($file['tmp_name']), true);
213
+		if (empty($settings)) {
214
+			return glsr(Notice::class)->addWarning(__('There were no settings found to import.', 'site-reviews'));
215
+		}
216
+		glsr(OptionManager::class)->set(glsr(OptionManager::class)->normalize($settings));
217
+		glsr(Notice::class)->addSuccess(__('Settings imported.', 'site-reviews'));
218
+	}
219
+
220
+	/**
221
+	 * @param int $errorCode
222
+	 * @return string
223
+	 */
224
+	protected function getUploadError($errorCode)
225
+	{
226
+		$errors = [
227
+			UPLOAD_ERR_INI_SIZE => __('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'site-reviews'),
228
+			UPLOAD_ERR_FORM_SIZE => __('The uploaded file is too big.', 'site-reviews'),
229
+			UPLOAD_ERR_PARTIAL => __('The uploaded file was only partially uploaded.', 'site-reviews'),
230
+			UPLOAD_ERR_NO_FILE => __('No file was uploaded.', 'site-reviews'),
231
+			UPLOAD_ERR_NO_TMP_DIR => __('Missing a temporary folder.', 'site-reviews'),
232
+			UPLOAD_ERR_CANT_WRITE => __('Failed to write file to disk.', 'site-reviews'),
233
+			UPLOAD_ERR_EXTENSION => __('A PHP extension stopped the file upload.', 'site-reviews'),
234
+		];
235
+		return Arr::get($errors, $errorCode, __('Unknown upload error.', 'site-reviews'));
236
+	}
237 237
 }
Please login to merge, or discard this patch.
plugin/Modules/ReviewLimits.php 1 patch
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -8,103 +8,103 @@
 block discarded – undo
8 8
 
9 9
 class ReviewLimits
10 10
 {
11
-    protected $request;
11
+	protected $request;
12 12
 
13
-    /**
14
-     * @return array
15
-     * @filter site-reviews/get/reviews/query
16
-     */
17
-    public function filterReviewsQuery(array $parameters, array $args)
18
-    {
19
-        if ($authorId = get_current_user_id()) {
20
-            $parameters['author'] = $authorId;
21
-        }
22
-        $parameters['post_status'] = ['pending', 'publish'];
23
-        return apply_filters('site-reviews/reviews-limits/query', $parameters, $args);
24
-    }
13
+	/**
14
+	 * @return array
15
+	 * @filter site-reviews/get/reviews/query
16
+	 */
17
+	public function filterReviewsQuery(array $parameters, array $args)
18
+	{
19
+		if ($authorId = get_current_user_id()) {
20
+			$parameters['author'] = $authorId;
21
+		}
22
+		$parameters['post_status'] = ['pending', 'publish'];
23
+		return apply_filters('site-reviews/reviews-limits/query', $parameters, $args);
24
+	}
25 25
 
26
-    /**
27
-     * @return bool
28
-     */
29
-    public function hasReachedLimit(array $request = [])
30
-    {
31
-        $this->request = $request;
32
-        $method = Helper::buildMethodName(
33
-            glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy'
34
-        );
35
-        return method_exists($this, $method)
36
-            ? !call_user_func([$this, $method])
37
-            : false;
38
-    }
26
+	/**
27
+	 * @return bool
28
+	 */
29
+	public function hasReachedLimit(array $request = [])
30
+	{
31
+		$this->request = $request;
32
+		$method = Helper::buildMethodName(
33
+			glsr(OptionManager::class)->get('settings.submissions.limit'), 'validateBy'
34
+		);
35
+		return method_exists($this, $method)
36
+			? !call_user_func([$this, $method])
37
+			: false;
38
+	}
39 39
 
40
-    /**
41
-     * @param string $value
42
-     * @param string $whitelist
43
-     * @return bool
44
-     */
45
-    public function isWhitelisted($value, $whitelist)
46
-    {
47
-        if (empty($whitelist)) {
48
-            return false;
49
-        }
50
-        return in_array($value, array_filter(explode("\n", $whitelist), 'trim'));
51
-    }
40
+	/**
41
+	 * @param string $value
42
+	 * @param string $whitelist
43
+	 * @return bool
44
+	 */
45
+	public function isWhitelisted($value, $whitelist)
46
+	{
47
+		if (empty($whitelist)) {
48
+			return false;
49
+		}
50
+		return in_array($value, array_filter(explode("\n", $whitelist), 'trim'));
51
+	}
52 52
 
53
-    /**
54
-     * @param string $whitelistName
55
-     * @return string
56
-     */
57
-    protected function getWhitelist($whitelistName)
58
-    {
59
-        return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName);
60
-    }
53
+	/**
54
+	 * @param string $whitelistName
55
+	 * @return string
56
+	 */
57
+	protected function getWhitelist($whitelistName)
58
+	{
59
+		return glsr(OptionManager::class)->get('settings.submissions.limit_whitelist.'.$whitelistName);
60
+	}
61 61
 
62
-    /**
63
-     * @return bool
64
-     */
65
-    protected function validate($key, $value, $addMetaQuery = true)
66
-    {
67
-        if ($this->isWhitelisted($value, $this->getWhitelist($key))) {
68
-            return true;
69
-        }
70
-        add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2);
71
-        $args = ['assigned_to' => Arr::get($this->request, 'assign_to')];
72
-        if ($addMetaQuery) {
73
-            $args[$key] = $value;
74
-        }
75
-        $reviews = glsr_get_reviews($args);
76
-        remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5);
77
-        return 0 === count($reviews);
78
-    }
62
+	/**
63
+	 * @return bool
64
+	 */
65
+	protected function validate($key, $value, $addMetaQuery = true)
66
+	{
67
+		if ($this->isWhitelisted($value, $this->getWhitelist($key))) {
68
+			return true;
69
+		}
70
+		add_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5, 2);
71
+		$args = ['assigned_to' => Arr::get($this->request, 'assign_to')];
72
+		if ($addMetaQuery) {
73
+			$args[$key] = $value;
74
+		}
75
+		$reviews = glsr_get_reviews($args);
76
+		remove_filter('site-reviews/get/reviews/query', [$this, 'filterReviewsQuery'], 5);
77
+		return 0 === count($reviews);
78
+	}
79 79
 
80
-    /**
81
-     * @return bool
82
-     */
83
-    protected function validateByEmail()
84
-    {
85
-        glsr_log()->debug('Email is: '.Arr::get($this->request, 'email'));
86
-        return $this->validate('email', Arr::get($this->request, 'email'));
87
-    }
80
+	/**
81
+	 * @return bool
82
+	 */
83
+	protected function validateByEmail()
84
+	{
85
+		glsr_log()->debug('Email is: '.Arr::get($this->request, 'email'));
86
+		return $this->validate('email', Arr::get($this->request, 'email'));
87
+	}
88 88
 
89
-    /**
90
-     * @return bool
91
-     */
92
-    protected function validateByIpAddress()
93
-    {
94
-        glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address'));
95
-        return $this->validate('ip_address', Arr::get($this->request, 'ip_address'));
96
-    }
89
+	/**
90
+	 * @return bool
91
+	 */
92
+	protected function validateByIpAddress()
93
+	{
94
+		glsr_log()->debug('IP Address is: '.Arr::get($this->request, 'ip_address'));
95
+		return $this->validate('ip_address', Arr::get($this->request, 'ip_address'));
96
+	}
97 97
 
98
-    /**
99
-     * @return bool
100
-     */
101
-    protected function validateByUsername()
102
-    {
103
-        $user = wp_get_current_user();
104
-        if (!$user->exists()) {
105
-            return true;
106
-        }
107
-        glsr_log()->debug('Username is: '.$user->user_login);
108
-        return $this->validate('username', $user->user_login, false);
109
-    }
98
+	/**
99
+	 * @return bool
100
+	 */
101
+	protected function validateByUsername()
102
+	{
103
+		$user = wp_get_current_user();
104
+		if (!$user->exists()) {
105
+			return true;
106
+		}
107
+		glsr_log()->debug('Username is: '.$user->user_login);
108
+		return $this->validate('username', $user->user_login, false);
109
+	}
110 110
 }
Please login to merge, or discard this patch.