Passed
Push — master ( d46765...078281 )
by Paul
05:16
created
views/partials/notices/welcome.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,3 +1,3 @@
 block discarded – undo
1 1
 <div class="notice notice-info is-dismissible glsr-notice" data-dismiss="welcome">
2
-    <p><?= $text; ?> &mdash; <a class="button button-small" href="<?= admin_url('edit.php?post_type='.glsr()->post_type.'&page=welcome'); ?>">See what's new</a></p> 
2
+    <p><?= $text; ?> &mdash; <a class="button button-small" href="<?= admin_url( 'edit.php?post_type='.glsr()->post_type.'&page=welcome' ); ?>">See what's new</a></p> 
3 3
 </div>
Please login to merge, or discard this patch.
plugin/Controllers/NoticeController.php 2 patches
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -8,102 +8,102 @@
 block discarded – undo
8 8
 
9 9
 class NoticeController extends Controller
10 10
 {
11
-    const USER_META_KEY = '_glsr_notices';
11
+	const USER_META_KEY = '_glsr_notices';
12 12
 
13
-    /**
14
-     * @return void
15
-     * @action admin_notices
16
-     */
17
-    public function filterAdminNotices()
18
-    {
19
-        $screen = glsr_current_screen();
20
-        $this->renderWelcomeNotice($screen->post_type);
21
-        $this->renderRebusifyNotice($screen->post_type);
22
-        $this->renderAddonsNotice($screen->id);
23
-    }
13
+	/**
14
+	 * @return void
15
+	 * @action admin_notices
16
+	 */
17
+	public function filterAdminNotices()
18
+	{
19
+		$screen = glsr_current_screen();
20
+		$this->renderWelcomeNotice($screen->post_type);
21
+		$this->renderRebusifyNotice($screen->post_type);
22
+		$this->renderAddonsNotice($screen->id);
23
+	}
24 24
 
25
-    /**
26
-     * @return void
27
-     */
28
-    public function routerDismissNotice(array $request)
29
-    {
30
-        if ($key = Arr::get($request, 'notice')) {
31
-            $this->dismissNotice($key);
32
-        }
33
-    }
25
+	/**
26
+	 * @return void
27
+	 */
28
+	public function routerDismissNotice(array $request)
29
+	{
30
+		if ($key = Arr::get($request, 'notice')) {
31
+			$this->dismissNotice($key);
32
+		}
33
+	}
34 34
 
35
-    /**
36
-     * @param string $key
37
-     * @return void
38
-     */
39
-    protected function dismissNotice($key)
40
-    {
41
-        $this->setUserMeta($key, glsr()->version('major'));
42
-    }
35
+	/**
36
+	 * @param string $key
37
+	 * @return void
38
+	 */
39
+	protected function dismissNotice($key)
40
+	{
41
+		$this->setUserMeta($key, glsr()->version('major'));
42
+	}
43 43
 
44
-    /**
45
-     * @param string $key
46
-     * @param mixed $fallback
47
-     * @return mixed
48
-     */
49
-    protected function getUserMeta($key, $fallback)
50
-    {
51
-        $meta = get_user_meta(get_current_user_id(), static::USER_META_KEY, true);
52
-        return Arr::get($meta, $key, $fallback);
53
-    }
44
+	/**
45
+	 * @param string $key
46
+	 * @param mixed $fallback
47
+	 * @return mixed
48
+	 */
49
+	protected function getUserMeta($key, $fallback)
50
+	{
51
+		$meta = get_user_meta(get_current_user_id(), static::USER_META_KEY, true);
52
+		return Arr::get($meta, $key, $fallback);
53
+	}
54 54
 
55
-    /**
56
-     * @param string $screenId
57
-     * @return void
58
-     */
59
-    protected function renderAddonsNotice($screenId)
60
-    {
61
-        if (Application::POST_TYPE.'_page_addons' == $screenId) {
62
-            echo glsr()->render('partials/notices/addons');
63
-        }
64
-    }
55
+	/**
56
+	 * @param string $screenId
57
+	 * @return void
58
+	 */
59
+	protected function renderAddonsNotice($screenId)
60
+	{
61
+		if (Application::POST_TYPE.'_page_addons' == $screenId) {
62
+			echo glsr()->render('partials/notices/addons');
63
+		}
64
+	}
65 65
 
66
-    /**
67
-     * @param string $screenPostType
68
-     * @return void
69
-     */
70
-    protected function renderRebusifyNotice($screenPostType)
71
-    {
72
-        if (Application::POST_TYPE == $screenPostType
73
-            && version_compare(glsr()->version('major'), $this->getUserMeta('rebusify', 0), '>')
74
-            && !glsr(OptionManager::class)->getBool('settings.general.rebusify')) {
75
-            echo glsr()->render('partials/notices/rebusify');
76
-        }
77
-    }
66
+	/**
67
+	 * @param string $screenPostType
68
+	 * @return void
69
+	 */
70
+	protected function renderRebusifyNotice($screenPostType)
71
+	{
72
+		if (Application::POST_TYPE == $screenPostType
73
+			&& version_compare(glsr()->version('major'), $this->getUserMeta('rebusify', 0), '>')
74
+			&& !glsr(OptionManager::class)->getBool('settings.general.rebusify')) {
75
+			echo glsr()->render('partials/notices/rebusify');
76
+		}
77
+	}
78 78
 
79
-    /**
80
-     * @param string $screenPostType
81
-     * @return void
82
-     */
83
-    protected function renderWelcomeNotice($screenPostType)
84
-    {
85
-        if (Application::POST_TYPE == $screenPostType
86
-            && version_compare(glsr()->version('major'), $this->getUserMeta('welcome', 0), '>')) {
87
-            $welcomeText = '0.0.0' == glsr(OptionManager::class)->get('version_upgraded_from')
88
-                ? __('Thanks for installing Site Reviews %s, we hope you love it!', 'site-reviews')
89
-                : __('Thanks for updating to Site Reviews %s, we hope you love the changes!', 'site-reviews');
90
-            echo glsr()->render('partials/notices/welcome', [
91
-                'text' => sprintf($welcomeText, glsr()->version),
92
-            ]);
93
-        }
94
-    }
79
+	/**
80
+	 * @param string $screenPostType
81
+	 * @return void
82
+	 */
83
+	protected function renderWelcomeNotice($screenPostType)
84
+	{
85
+		if (Application::POST_TYPE == $screenPostType
86
+			&& version_compare(glsr()->version('major'), $this->getUserMeta('welcome', 0), '>')) {
87
+			$welcomeText = '0.0.0' == glsr(OptionManager::class)->get('version_upgraded_from')
88
+				? __('Thanks for installing Site Reviews %s, we hope you love it!', 'site-reviews')
89
+				: __('Thanks for updating to Site Reviews %s, we hope you love the changes!', 'site-reviews');
90
+			echo glsr()->render('partials/notices/welcome', [
91
+				'text' => sprintf($welcomeText, glsr()->version),
92
+			]);
93
+		}
94
+	}
95 95
 
96
-    /**
97
-     * @param string $key
98
-     * @param mixed $fallback
99
-     * @return mixed
100
-     */
101
-    protected function setUserMeta($key, $value)
102
-    {
103
-        $userId = get_current_user_id();
104
-        $meta = (array) get_user_meta($userId, static::USER_META_KEY, true);
105
-        $meta = array_filter(wp_parse_args($meta, []));
106
-        $meta[$key] = $value;
107
-        update_user_meta($userId, static::USER_META_KEY, $meta);
108
-    }
96
+	/**
97
+	 * @param string $key
98
+	 * @param mixed $fallback
99
+	 * @return mixed
100
+	 */
101
+	protected function setUserMeta($key, $value)
102
+	{
103
+		$userId = get_current_user_id();
104
+		$meta = (array) get_user_meta($userId, static::USER_META_KEY, true);
105
+		$meta = array_filter(wp_parse_args($meta, []));
106
+		$meta[$key] = $value;
107
+		update_user_meta($userId, static::USER_META_KEY, $meta);
108
+	}
109 109
 }
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -17,18 +17,18 @@  discard block
 block discarded – undo
17 17
     public function filterAdminNotices()
18 18
     {
19 19
         $screen = glsr_current_screen();
20
-        $this->renderWelcomeNotice($screen->post_type);
21
-        $this->renderRebusifyNotice($screen->post_type);
22
-        $this->renderAddonsNotice($screen->id);
20
+        $this->renderWelcomeNotice( $screen->post_type );
21
+        $this->renderRebusifyNotice( $screen->post_type );
22
+        $this->renderAddonsNotice( $screen->id );
23 23
     }
24 24
 
25 25
     /**
26 26
      * @return void
27 27
      */
28
-    public function routerDismissNotice(array $request)
28
+    public function routerDismissNotice( array $request )
29 29
     {
30
-        if ($key = Arr::get($request, 'notice')) {
31
-            $this->dismissNotice($key);
30
+        if( $key = Arr::get( $request, 'notice' ) ) {
31
+            $this->dismissNotice( $key );
32 32
         }
33 33
     }
34 34
 
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
      * @param string $key
37 37
      * @return void
38 38
      */
39
-    protected function dismissNotice($key)
39
+    protected function dismissNotice( $key )
40 40
     {
41
-        $this->setUserMeta($key, glsr()->version('major'));
41
+        $this->setUserMeta( $key, glsr()->version( 'major' ) );
42 42
     }
43 43
 
44 44
     /**
@@ -46,20 +46,20 @@  discard block
 block discarded – undo
46 46
      * @param mixed $fallback
47 47
      * @return mixed
48 48
      */
49
-    protected function getUserMeta($key, $fallback)
49
+    protected function getUserMeta( $key, $fallback )
50 50
     {
51
-        $meta = get_user_meta(get_current_user_id(), static::USER_META_KEY, true);
52
-        return Arr::get($meta, $key, $fallback);
51
+        $meta = get_user_meta( get_current_user_id(), static::USER_META_KEY, true );
52
+        return Arr::get( $meta, $key, $fallback );
53 53
     }
54 54
 
55 55
     /**
56 56
      * @param string $screenId
57 57
      * @return void
58 58
      */
59
-    protected function renderAddonsNotice($screenId)
59
+    protected function renderAddonsNotice( $screenId )
60 60
     {
61
-        if (Application::POST_TYPE.'_page_addons' == $screenId) {
62
-            echo glsr()->render('partials/notices/addons');
61
+        if( Application::POST_TYPE.'_page_addons' == $screenId ) {
62
+            echo glsr()->render( 'partials/notices/addons' );
63 63
         }
64 64
     }
65 65
 
@@ -67,12 +67,12 @@  discard block
 block discarded – undo
67 67
      * @param string $screenPostType
68 68
      * @return void
69 69
      */
70
-    protected function renderRebusifyNotice($screenPostType)
70
+    protected function renderRebusifyNotice( $screenPostType )
71 71
     {
72
-        if (Application::POST_TYPE == $screenPostType
73
-            && version_compare(glsr()->version('major'), $this->getUserMeta('rebusify', 0), '>')
74
-            && !glsr(OptionManager::class)->getBool('settings.general.rebusify')) {
75
-            echo glsr()->render('partials/notices/rebusify');
72
+        if( Application::POST_TYPE == $screenPostType
73
+            && version_compare( glsr()->version( 'major' ), $this->getUserMeta( 'rebusify', 0 ), '>' )
74
+            && !glsr( OptionManager::class )->getBool( 'settings.general.rebusify' ) ) {
75
+            echo glsr()->render( 'partials/notices/rebusify' );
76 76
         }
77 77
     }
78 78
 
@@ -80,16 +80,16 @@  discard block
 block discarded – undo
80 80
      * @param string $screenPostType
81 81
      * @return void
82 82
      */
83
-    protected function renderWelcomeNotice($screenPostType)
83
+    protected function renderWelcomeNotice( $screenPostType )
84 84
     {
85
-        if (Application::POST_TYPE == $screenPostType
86
-            && version_compare(glsr()->version('major'), $this->getUserMeta('welcome', 0), '>')) {
87
-            $welcomeText = '0.0.0' == glsr(OptionManager::class)->get('version_upgraded_from')
88
-                ? __('Thanks for installing Site Reviews %s, we hope you love it!', 'site-reviews')
89
-                : __('Thanks for updating to Site Reviews %s, we hope you love the changes!', 'site-reviews');
90
-            echo glsr()->render('partials/notices/welcome', [
91
-                'text' => sprintf($welcomeText, glsr()->version),
92
-            ]);
85
+        if( Application::POST_TYPE == $screenPostType
86
+            && version_compare( glsr()->version( 'major' ), $this->getUserMeta( 'welcome', 0 ), '>' ) ) {
87
+            $welcomeText = '0.0.0' == glsr( OptionManager::class )->get( 'version_upgraded_from' )
88
+                ? __( 'Thanks for installing Site Reviews %s, we hope you love it!', 'site-reviews' )
89
+                : __( 'Thanks for updating to Site Reviews %s, we hope you love the changes!', 'site-reviews' );
90
+            echo glsr()->render( 'partials/notices/welcome', [
91
+                'text' => sprintf( $welcomeText, glsr()->version ),
92
+            ] );
93 93
         }
94 94
     }
95 95
 
@@ -98,12 +98,12 @@  discard block
 block discarded – undo
98 98
      * @param mixed $fallback
99 99
      * @return mixed
100 100
      */
101
-    protected function setUserMeta($key, $value)
101
+    protected function setUserMeta( $key, $value )
102 102
     {
103 103
         $userId = get_current_user_id();
104
-        $meta = (array) get_user_meta($userId, static::USER_META_KEY, true);
105
-        $meta = array_filter(wp_parse_args($meta, []));
104
+        $meta = (array)get_user_meta( $userId, static::USER_META_KEY, true );
105
+        $meta = array_filter( wp_parse_args( $meta, [] ) );
106 106
         $meta[$key] = $value;
107
-        update_user_meta($userId, static::USER_META_KEY, $meta);
107
+        update_user_meta( $userId, static::USER_META_KEY, $meta );
108 108
     }
109 109
 }
Please login to merge, or discard this patch.
plugin/Modules/Translation.php 2 patches
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -10,272 +10,272 @@
 block discarded – undo
10 10
 
11 11
 class Translation
12 12
 {
13
-    const SEARCH_THRESHOLD = 3;
13
+	const SEARCH_THRESHOLD = 3;
14 14
 
15
-    /**
16
-     * @var array
17
-     */
18
-    protected $entries;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	protected $entries;
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    protected $results;
20
+	/**
21
+	 * @var array
22
+	 */
23
+	protected $results;
24 24
 
25
-    /**
26
-     * Returns all saved custom translations with translation context.
27
-     * @return array
28
-     */
29
-    public function all()
30
-    {
31
-        $translations = $this->translations();
32
-        $entries = $this->filter($translations, $this->entries())->results();
33
-        array_walk($translations, function (&$entry) use ($entries) {
34
-            $entry['desc'] = array_key_exists($entry['id'], $entries)
35
-                ? $this->getEntryString($entries[$entry['id']], 'msgctxt')
36
-                : '';
37
-        });
38
-        return $translations;
39
-    }
25
+	/**
26
+	 * Returns all saved custom translations with translation context.
27
+	 * @return array
28
+	 */
29
+	public function all()
30
+	{
31
+		$translations = $this->translations();
32
+		$entries = $this->filter($translations, $this->entries())->results();
33
+		array_walk($translations, function (&$entry) use ($entries) {
34
+			$entry['desc'] = array_key_exists($entry['id'], $entries)
35
+				? $this->getEntryString($entries[$entry['id']], 'msgctxt')
36
+				: '';
37
+		});
38
+		return $translations;
39
+	}
40 40
 
41
-    /**
42
-     * @return array
43
-     */
44
-    public function entries()
45
-    {
46
-        if (!isset($this->entries)) {
47
-            $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot');
48
-            $entries = $this->extractEntriesFromPotFile($potFile);
49
-            $entries = apply_filters('site-reviews/translation/entries', $entries);
50
-            $this->entries = $entries;
51
-        }
52
-        return $this->entries;
53
-    }
41
+	/**
42
+	 * @return array
43
+	 */
44
+	public function entries()
45
+	{
46
+		if (!isset($this->entries)) {
47
+			$potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot');
48
+			$entries = $this->extractEntriesFromPotFile($potFile);
49
+			$entries = apply_filters('site-reviews/translation/entries', $entries);
50
+			$this->entries = $entries;
51
+		}
52
+		return $this->entries;
53
+	}
54 54
 
55
-    /**
56
-     * @param array|null $entriesToExclude
57
-     * @param array|null $entries
58
-     * @return static
59
-     */
60
-    public function exclude($entriesToExclude = null, $entries = null)
61
-    {
62
-        return $this->filter($entriesToExclude, $entries, false);
63
-    }
55
+	/**
56
+	 * @param array|null $entriesToExclude
57
+	 * @param array|null $entries
58
+	 * @return static
59
+	 */
60
+	public function exclude($entriesToExclude = null, $entries = null)
61
+	{
62
+		return $this->filter($entriesToExclude, $entries, false);
63
+	}
64 64
 
65
-    /**
66
-     * @param string $potFile
67
-     * @return array
68
-     */
69
-    public function extractEntriesFromPotFile($potFile, array $entries = [])
70
-    {
71
-        try {
72
-            $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries());
73
-            foreach ($potEntries as $key => $entry) {
74
-                $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
75
-            }
76
-        } catch (Exception $e) {
77
-            glsr_log()->error($e->getMessage());
78
-        }
79
-        return $entries;
80
-    }
65
+	/**
66
+	 * @param string $potFile
67
+	 * @return array
68
+	 */
69
+	public function extractEntriesFromPotFile($potFile, array $entries = [])
70
+	{
71
+		try {
72
+			$potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries());
73
+			foreach ($potEntries as $key => $entry) {
74
+				$entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
75
+			}
76
+		} catch (Exception $e) {
77
+			glsr_log()->error($e->getMessage());
78
+		}
79
+		return $entries;
80
+	}
81 81
 
82
-    /**
83
-     * @param array|null $filterWith
84
-     * @param array|null $entries
85
-     * @param bool $intersect
86
-     * @return static
87
-     */
88
-    public function filter($filterWith = null, $entries = null, $intersect = true)
89
-    {
90
-        if (!is_array($entries)) {
91
-            $entries = $this->results;
92
-        }
93
-        if (!is_array($filterWith)) {
94
-            $filterWith = $this->translations();
95
-        }
96
-        $keys = array_flip(glsr_array_column($filterWith, 'id'));
97
-        $this->results = $intersect
98
-            ? array_intersect_key($entries, $keys)
99
-            : array_diff_key($entries, $keys);
100
-        return $this;
101
-    }
82
+	/**
83
+	 * @param array|null $filterWith
84
+	 * @param array|null $entries
85
+	 * @param bool $intersect
86
+	 * @return static
87
+	 */
88
+	public function filter($filterWith = null, $entries = null, $intersect = true)
89
+	{
90
+		if (!is_array($entries)) {
91
+			$entries = $this->results;
92
+		}
93
+		if (!is_array($filterWith)) {
94
+			$filterWith = $this->translations();
95
+		}
96
+		$keys = array_flip(glsr_array_column($filterWith, 'id'));
97
+		$this->results = $intersect
98
+			? array_intersect_key($entries, $keys)
99
+			: array_diff_key($entries, $keys);
100
+		return $this;
101
+	}
102 102
 
103
-    /**
104
-     * @param string $template
105
-     * @return string
106
-     */
107
-    public function render($template, array $entry)
108
-    {
109
-        $data = array_combine(
110
-            array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)),
111
-            $entry
112
-        );
113
-        $data['data.class'] = $data['data.error'] = '';
114
-        if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) {
115
-            $data['data.class'] = 'is-invalid';
116
-            $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews');
117
-        }
118
-        return glsr(Template::class)->build('partials/translations/'.$template, [
119
-            'context' => array_map('esc_html', $data),
120
-        ]);
121
-    }
103
+	/**
104
+	 * @param string $template
105
+	 * @return string
106
+	 */
107
+	public function render($template, array $entry)
108
+	{
109
+		$data = array_combine(
110
+			array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)),
111
+			$entry
112
+		);
113
+		$data['data.class'] = $data['data.error'] = '';
114
+		if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) {
115
+			$data['data.class'] = 'is-invalid';
116
+			$data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews');
117
+		}
118
+		return glsr(Template::class)->build('partials/translations/'.$template, [
119
+			'context' => array_map('esc_html', $data),
120
+		]);
121
+	}
122 122
 
123
-    /**
124
-     * Returns a rendered string of all saved custom translations with translation context.
125
-     * @return string
126
-     */
127
-    public function renderAll()
128
-    {
129
-        $rendered = '';
130
-        foreach ($this->all() as $index => $entry) {
131
-            $entry['index'] = $index;
132
-            $entry['prefix'] = OptionManager::databaseKey();
133
-            $rendered.= $this->render($entry['type'], $entry);
134
-        }
135
-        return $rendered;
136
-    }
123
+	/**
124
+	 * Returns a rendered string of all saved custom translations with translation context.
125
+	 * @return string
126
+	 */
127
+	public function renderAll()
128
+	{
129
+		$rendered = '';
130
+		foreach ($this->all() as $index => $entry) {
131
+			$entry['index'] = $index;
132
+			$entry['prefix'] = OptionManager::databaseKey();
133
+			$rendered.= $this->render($entry['type'], $entry);
134
+		}
135
+		return $rendered;
136
+	}
137 137
 
138
-    /**
139
-     * @param bool $resetAfterRender
140
-     * @return string
141
-     */
142
-    public function renderResults($resetAfterRender = true)
143
-    {
144
-        $rendered = '';
145
-        foreach ($this->results as $id => $entry) {
146
-            $data = [
147
-                'desc' => $this->getEntryString($entry, 'msgctxt'),
148
-                'id' => $id,
149
-                'p1' => $this->getEntryString($entry, 'msgid_plural'),
150
-                's1' => $this->getEntryString($entry, 'msgid'),
151
-            ];
152
-            $text = !empty($data['p1'])
153
-                ? sprintf('%s | %s', $data['s1'], $data['p1'])
154
-                : $data['s1'];
155
-            $rendered.= $this->render('result', [
156
-                'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
157
-                'text' => wp_strip_all_tags($text),
158
-            ]);
159
-        }
160
-        if ($resetAfterRender) {
161
-            $this->reset();
162
-        }
163
-        return $rendered;
164
-    }
138
+	/**
139
+	 * @param bool $resetAfterRender
140
+	 * @return string
141
+	 */
142
+	public function renderResults($resetAfterRender = true)
143
+	{
144
+		$rendered = '';
145
+		foreach ($this->results as $id => $entry) {
146
+			$data = [
147
+				'desc' => $this->getEntryString($entry, 'msgctxt'),
148
+				'id' => $id,
149
+				'p1' => $this->getEntryString($entry, 'msgid_plural'),
150
+				's1' => $this->getEntryString($entry, 'msgid'),
151
+			];
152
+			$text = !empty($data['p1'])
153
+				? sprintf('%s | %s', $data['s1'], $data['p1'])
154
+				: $data['s1'];
155
+			$rendered.= $this->render('result', [
156
+				'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
157
+				'text' => wp_strip_all_tags($text),
158
+			]);
159
+		}
160
+		if ($resetAfterRender) {
161
+			$this->reset();
162
+		}
163
+		return $rendered;
164
+	}
165 165
 
166
-    /**
167
-     * @return void
168
-     */
169
-    public function reset()
170
-    {
171
-        $this->results = [];
172
-    }
166
+	/**
167
+	 * @return void
168
+	 */
169
+	public function reset()
170
+	{
171
+		$this->results = [];
172
+	}
173 173
 
174
-    /**
175
-     * @return array
176
-     */
177
-    public function results()
178
-    {
179
-        $results = $this->results;
180
-        $this->reset();
181
-        return $results;
182
-    }
174
+	/**
175
+	 * @return array
176
+	 */
177
+	public function results()
178
+	{
179
+		$results = $this->results;
180
+		$this->reset();
181
+		return $results;
182
+	}
183 183
 
184
-    /**
185
-     * @param string $needle
186
-     * @return static
187
-     */
188
-    public function search($needle = '')
189
-    {
190
-        $this->reset();
191
-        $needle = trim(strtolower($needle));
192
-        foreach ($this->entries() as $key => $entry) {
193
-            $single = strtolower($this->getEntryString($entry, 'msgid'));
194
-            $plural = strtolower($this->getEntryString($entry, 'msgid_plural'));
195
-            if (strlen($needle) < static::SEARCH_THRESHOLD) {
196
-                if (in_array($needle, [$single, $plural])) {
197
-                    $this->results[$key] = $entry;
198
-                }
199
-            } elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) {
200
-                $this->results[$key] = $entry;
201
-            }
202
-        }
203
-        return $this;
204
-    }
184
+	/**
185
+	 * @param string $needle
186
+	 * @return static
187
+	 */
188
+	public function search($needle = '')
189
+	{
190
+		$this->reset();
191
+		$needle = trim(strtolower($needle));
192
+		foreach ($this->entries() as $key => $entry) {
193
+			$single = strtolower($this->getEntryString($entry, 'msgid'));
194
+			$plural = strtolower($this->getEntryString($entry, 'msgid_plural'));
195
+			if (strlen($needle) < static::SEARCH_THRESHOLD) {
196
+				if (in_array($needle, [$single, $plural])) {
197
+					$this->results[$key] = $entry;
198
+				}
199
+			} elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) {
200
+				$this->results[$key] = $entry;
201
+			}
202
+		}
203
+		return $this;
204
+	}
205 205
 
206
-    /**
207
-     * Store the translations to avoid unnecessary loops.
208
-     * @return array
209
-     */
210
-    public function translations()
211
-    {
212
-        static $translations;
213
-        if (empty($translations)) {
214
-            $settings = glsr(OptionManager::class)->get('settings');
215
-            $translations = isset($settings['strings'])
216
-                ? $this->normalizeSettings((array) $settings['strings'])
217
-                : [];
218
-        }
219
-        return $translations;
220
-    }
206
+	/**
207
+	 * Store the translations to avoid unnecessary loops.
208
+	 * @return array
209
+	 */
210
+	public function translations()
211
+	{
212
+		static $translations;
213
+		if (empty($translations)) {
214
+			$settings = glsr(OptionManager::class)->get('settings');
215
+			$translations = isset($settings['strings'])
216
+				? $this->normalizeSettings((array) $settings['strings'])
217
+				: [];
218
+		}
219
+		return $translations;
220
+	}
221 221
 
222
-    /**
223
-     * @param string $key
224
-     * @return string
225
-     */
226
-    protected function getEntryString(array $entry, $key)
227
-    {
228
-        return isset($entry[$key])
229
-            ? implode('', (array) $entry[$key])
230
-            : '';
231
-    }
222
+	/**
223
+	 * @param string $key
224
+	 * @return string
225
+	 */
226
+	protected function getEntryString(array $entry, $key)
227
+	{
228
+		return isset($entry[$key])
229
+			? implode('', (array) $entry[$key])
230
+			: '';
231
+	}
232 232
 
233
-    /**
234
-     * @return array
235
-     */
236
-    protected function normalize(array $entries)
237
-    {
238
-        $keys = [
239
-            'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
240
-        ];
241
-        array_walk($entries, function (&$entry) use ($keys) {
242
-            foreach ($keys as $key) {
243
-                try {
244
-                    $entry = $this->normalizeEntryString($entry, $key);
245
-                } catch (\TypeError $error) {
246
-                    glsr_log()->once('error', 'Translation/normalize', $error);
247
-                    glsr_log()->once('debug', 'Translation/normalize', $entry);
248
-                }
249
-            }
250
-        });
251
-        return $entries;
252
-    }
233
+	/**
234
+	 * @return array
235
+	 */
236
+	protected function normalize(array $entries)
237
+	{
238
+		$keys = [
239
+			'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
240
+		];
241
+		array_walk($entries, function (&$entry) use ($keys) {
242
+			foreach ($keys as $key) {
243
+				try {
244
+					$entry = $this->normalizeEntryString($entry, $key);
245
+				} catch (\TypeError $error) {
246
+					glsr_log()->once('error', 'Translation/normalize', $error);
247
+					glsr_log()->once('debug', 'Translation/normalize', $entry);
248
+				}
249
+			}
250
+		});
251
+		return $entries;
252
+	}
253 253
 
254
-    /**
255
-     * @param string $key
256
-     * @return array
257
-     */
258
-    protected function normalizeEntryString(array $entry, $key)
259
-    {
260
-        if (isset($entry[$key])) {
261
-            $entry[$key] = $this->getEntryString($entry, $key);
262
-        }
263
-        return $entry;
264
-    }
254
+	/**
255
+	 * @param string $key
256
+	 * @return array
257
+	 */
258
+	protected function normalizeEntryString(array $entry, $key)
259
+	{
260
+		if (isset($entry[$key])) {
261
+			$entry[$key] = $this->getEntryString($entry, $key);
262
+		}
263
+		return $entry;
264
+	}
265 265
 
266
-    /**
267
-     * @return array
268
-     */
269
-    protected function normalizeSettings(array $strings)
270
-    {
271
-        $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
272
-        $strings = array_filter($strings, 'is_array');
273
-        foreach ($strings as &$string) {
274
-            $string['type'] = isset($string['p1']) ? 'plural' : 'single';
275
-            $string = wp_parse_args($string, $defaultString);
276
-        }
277
-        return array_filter($strings, function ($string) {
278
-            return !empty($string['id']);
279
-        });
280
-    }
266
+	/**
267
+	 * @return array
268
+	 */
269
+	protected function normalizeSettings(array $strings)
270
+	{
271
+		$defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
272
+		$strings = array_filter($strings, 'is_array');
273
+		foreach ($strings as &$string) {
274
+			$string['type'] = isset($string['p1']) ? 'plural' : 'single';
275
+			$string = wp_parse_args($string, $defaultString);
276
+		}
277
+		return array_filter($strings, function ($string) {
278
+			return !empty($string['id']);
279
+		});
280
+	}
281 281
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
     public function all()
30 30
     {
31 31
         $translations = $this->translations();
32
-        $entries = $this->filter($translations, $this->entries())->results();
33
-        array_walk($translations, function (&$entry) use ($entries) {
34
-            $entry['desc'] = array_key_exists($entry['id'], $entries)
35
-                ? $this->getEntryString($entries[$entry['id']], 'msgctxt')
32
+        $entries = $this->filter( $translations, $this->entries() )->results();
33
+        array_walk( $translations, function( &$entry ) use ($entries) {
34
+            $entry['desc'] = array_key_exists( $entry['id'], $entries )
35
+                ? $this->getEntryString( $entries[$entry['id']], 'msgctxt' )
36 36
                 : '';
37 37
         });
38 38
         return $translations;
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function entries()
45 45
     {
46
-        if (!isset($this->entries)) {
47
-            $potFile = glsr()->path(glsr()->languages.'/'.Application::ID.'.pot');
48
-            $entries = $this->extractEntriesFromPotFile($potFile);
49
-            $entries = apply_filters('site-reviews/translation/entries', $entries);
46
+        if( !isset($this->entries) ) {
47
+            $potFile = glsr()->path( glsr()->languages.'/'.Application::ID.'.pot' );
48
+            $entries = $this->extractEntriesFromPotFile( $potFile );
49
+            $entries = apply_filters( 'site-reviews/translation/entries', $entries );
50 50
             $this->entries = $entries;
51 51
         }
52 52
         return $this->entries;
@@ -57,24 +57,24 @@  discard block
 block discarded – undo
57 57
      * @param array|null $entries
58 58
      * @return static
59 59
      */
60
-    public function exclude($entriesToExclude = null, $entries = null)
60
+    public function exclude( $entriesToExclude = null, $entries = null )
61 61
     {
62
-        return $this->filter($entriesToExclude, $entries, false);
62
+        return $this->filter( $entriesToExclude, $entries, false );
63 63
     }
64 64
 
65 65
     /**
66 66
      * @param string $potFile
67 67
      * @return array
68 68
      */
69
-    public function extractEntriesFromPotFile($potFile, array $entries = [])
69
+    public function extractEntriesFromPotFile( $potFile, array $entries = [] )
70 70
     {
71 71
         try {
72
-            $potEntries = $this->normalize(Parser::parseFile($potFile)->getEntries());
73
-            foreach ($potEntries as $key => $entry) {
74
-                $entries[html_entity_decode($key, ENT_COMPAT, 'UTF-8')] = $entry;
72
+            $potEntries = $this->normalize( Parser::parseFile( $potFile )->getEntries() );
73
+            foreach( $potEntries as $key => $entry ) {
74
+                $entries[html_entity_decode( $key, ENT_COMPAT, 'UTF-8' )] = $entry;
75 75
             }
76
-        } catch (Exception $e) {
77
-            glsr_log()->error($e->getMessage());
76
+        } catch( Exception $e ) {
77
+            glsr_log()->error( $e->getMessage() );
78 78
         }
79 79
         return $entries;
80 80
     }
@@ -85,18 +85,18 @@  discard block
 block discarded – undo
85 85
      * @param bool $intersect
86 86
      * @return static
87 87
      */
88
-    public function filter($filterWith = null, $entries = null, $intersect = true)
88
+    public function filter( $filterWith = null, $entries = null, $intersect = true )
89 89
     {
90
-        if (!is_array($entries)) {
90
+        if( !is_array( $entries ) ) {
91 91
             $entries = $this->results;
92 92
         }
93
-        if (!is_array($filterWith)) {
93
+        if( !is_array( $filterWith ) ) {
94 94
             $filterWith = $this->translations();
95 95
         }
96
-        $keys = array_flip(glsr_array_column($filterWith, 'id'));
96
+        $keys = array_flip( glsr_array_column( $filterWith, 'id' ) );
97 97
         $this->results = $intersect
98
-            ? array_intersect_key($entries, $keys)
99
-            : array_diff_key($entries, $keys);
98
+            ? array_intersect_key( $entries, $keys )
99
+            : array_diff_key( $entries, $keys );
100 100
         return $this;
101 101
     }
102 102
 
@@ -104,20 +104,20 @@  discard block
 block discarded – undo
104 104
      * @param string $template
105 105
      * @return string
106 106
      */
107
-    public function render($template, array $entry)
107
+    public function render( $template, array $entry )
108 108
     {
109 109
         $data = array_combine(
110
-            array_map(function ($key) { return 'data.'.$key; }, array_keys($entry)),
110
+            array_map( function( $key ) { return 'data.'.$key; }, array_keys( $entry ) ),
111 111
             $entry
112 112
         );
113 113
         $data['data.class'] = $data['data.error'] = '';
114
-        if (false === array_search($entry['s1'], glsr_array_column($this->entries(), 'msgid'))) {
114
+        if( false === array_search( $entry['s1'], glsr_array_column( $this->entries(), 'msgid' ) ) ) {
115 115
             $data['data.class'] = 'is-invalid';
116
-            $data['data.error'] = __('This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews');
116
+            $data['data.error'] = __( 'This custom translation is no longer valid as the original text has been changed or removed.', 'site-reviews' );
117 117
         }
118
-        return glsr(Template::class)->build('partials/translations/'.$template, [
119
-            'context' => array_map('esc_html', $data),
120
-        ]);
118
+        return glsr( Template::class )->build( 'partials/translations/'.$template, [
119
+            'context' => array_map( 'esc_html', $data ),
120
+        ] );
121 121
     }
122 122
 
123 123
     /**
@@ -127,10 +127,10 @@  discard block
 block discarded – undo
127 127
     public function renderAll()
128 128
     {
129 129
         $rendered = '';
130
-        foreach ($this->all() as $index => $entry) {
130
+        foreach( $this->all() as $index => $entry ) {
131 131
             $entry['index'] = $index;
132 132
             $entry['prefix'] = OptionManager::databaseKey();
133
-            $rendered.= $this->render($entry['type'], $entry);
133
+            $rendered .= $this->render( $entry['type'], $entry );
134 134
         }
135 135
         return $rendered;
136 136
     }
@@ -139,25 +139,25 @@  discard block
 block discarded – undo
139 139
      * @param bool $resetAfterRender
140 140
      * @return string
141 141
      */
142
-    public function renderResults($resetAfterRender = true)
142
+    public function renderResults( $resetAfterRender = true )
143 143
     {
144 144
         $rendered = '';
145
-        foreach ($this->results as $id => $entry) {
145
+        foreach( $this->results as $id => $entry ) {
146 146
             $data = [
147
-                'desc' => $this->getEntryString($entry, 'msgctxt'),
147
+                'desc' => $this->getEntryString( $entry, 'msgctxt' ),
148 148
                 'id' => $id,
149
-                'p1' => $this->getEntryString($entry, 'msgid_plural'),
150
-                's1' => $this->getEntryString($entry, 'msgid'),
149
+                'p1' => $this->getEntryString( $entry, 'msgid_plural' ),
150
+                's1' => $this->getEntryString( $entry, 'msgid' ),
151 151
             ];
152 152
             $text = !empty($data['p1'])
153
-                ? sprintf('%s | %s', $data['s1'], $data['p1'])
153
+                ? sprintf( '%s | %s', $data['s1'], $data['p1'] )
154 154
                 : $data['s1'];
155
-            $rendered.= $this->render('result', [
156
-                'entry' => json_encode($data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
157
-                'text' => wp_strip_all_tags($text),
158
-            ]);
155
+            $rendered .= $this->render( 'result', [
156
+                'entry' => json_encode( $data, JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ),
157
+                'text' => wp_strip_all_tags( $text ),
158
+            ] );
159 159
         }
160
-        if ($resetAfterRender) {
160
+        if( $resetAfterRender ) {
161 161
             $this->reset();
162 162
         }
163 163
         return $rendered;
@@ -185,18 +185,18 @@  discard block
 block discarded – undo
185 185
      * @param string $needle
186 186
      * @return static
187 187
      */
188
-    public function search($needle = '')
188
+    public function search( $needle = '' )
189 189
     {
190 190
         $this->reset();
191
-        $needle = trim(strtolower($needle));
192
-        foreach ($this->entries() as $key => $entry) {
193
-            $single = strtolower($this->getEntryString($entry, 'msgid'));
194
-            $plural = strtolower($this->getEntryString($entry, 'msgid_plural'));
195
-            if (strlen($needle) < static::SEARCH_THRESHOLD) {
196
-                if (in_array($needle, [$single, $plural])) {
191
+        $needle = trim( strtolower( $needle ) );
192
+        foreach( $this->entries() as $key => $entry ) {
193
+            $single = strtolower( $this->getEntryString( $entry, 'msgid' ) );
194
+            $plural = strtolower( $this->getEntryString( $entry, 'msgid_plural' ) );
195
+            if( strlen( $needle ) < static::SEARCH_THRESHOLD ) {
196
+                if( in_array( $needle, [$single, $plural] ) ) {
197 197
                     $this->results[$key] = $entry;
198 198
                 }
199
-            } elseif (false !== strpos(sprintf('%s %s', $single, $plural), $needle)) {
199
+            } elseif( false !== strpos( sprintf( '%s %s', $single, $plural ), $needle ) ) {
200 200
                 $this->results[$key] = $entry;
201 201
             }
202 202
         }
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
     public function translations()
211 211
     {
212 212
         static $translations;
213
-        if (empty($translations)) {
214
-            $settings = glsr(OptionManager::class)->get('settings');
213
+        if( empty($translations) ) {
214
+            $settings = glsr( OptionManager::class )->get( 'settings' );
215 215
             $translations = isset($settings['strings'])
216
-                ? $this->normalizeSettings((array) $settings['strings'])
216
+                ? $this->normalizeSettings( (array)$settings['strings'] )
217 217
                 : [];
218 218
         }
219 219
         return $translations;
@@ -223,28 +223,28 @@  discard block
 block discarded – undo
223 223
      * @param string $key
224 224
      * @return string
225 225
      */
226
-    protected function getEntryString(array $entry, $key)
226
+    protected function getEntryString( array $entry, $key )
227 227
     {
228 228
         return isset($entry[$key])
229
-            ? implode('', (array) $entry[$key])
229
+            ? implode( '', (array)$entry[$key] )
230 230
             : '';
231 231
     }
232 232
 
233 233
     /**
234 234
      * @return array
235 235
      */
236
-    protected function normalize(array $entries)
236
+    protected function normalize( array $entries )
237 237
     {
238 238
         $keys = [
239 239
             'msgctxt', 'msgid', 'msgid_plural', 'msgstr', 'msgstr[0]', 'msgstr[1]',
240 240
         ];
241
-        array_walk($entries, function (&$entry) use ($keys) {
242
-            foreach ($keys as $key) {
241
+        array_walk( $entries, function( &$entry ) use ($keys) {
242
+            foreach( $keys as $key ) {
243 243
                 try {
244
-                    $entry = $this->normalizeEntryString($entry, $key);
245
-                } catch (\TypeError $error) {
246
-                    glsr_log()->once('error', 'Translation/normalize', $error);
247
-                    glsr_log()->once('debug', 'Translation/normalize', $entry);
244
+                    $entry = $this->normalizeEntryString( $entry, $key );
245
+                } catch( \TypeError $error ) {
246
+                    glsr_log()->once( 'error', 'Translation/normalize', $error );
247
+                    glsr_log()->once( 'debug', 'Translation/normalize', $entry );
248 248
                 }
249 249
             }
250 250
         });
@@ -255,10 +255,10 @@  discard block
 block discarded – undo
255 255
      * @param string $key
256 256
      * @return array
257 257
      */
258
-    protected function normalizeEntryString(array $entry, $key)
258
+    protected function normalizeEntryString( array $entry, $key )
259 259
     {
260
-        if (isset($entry[$key])) {
261
-            $entry[$key] = $this->getEntryString($entry, $key);
260
+        if( isset($entry[$key]) ) {
261
+            $entry[$key] = $this->getEntryString( $entry, $key );
262 262
         }
263 263
         return $entry;
264 264
     }
@@ -266,15 +266,15 @@  discard block
 block discarded – undo
266 266
     /**
267 267
      * @return array
268 268
      */
269
-    protected function normalizeSettings(array $strings)
269
+    protected function normalizeSettings( array $strings )
270 270
     {
271
-        $defaultString = array_fill_keys(['id', 's1', 's2', 'p1', 'p2'], '');
272
-        $strings = array_filter($strings, 'is_array');
273
-        foreach ($strings as &$string) {
271
+        $defaultString = array_fill_keys( ['id', 's1', 's2', 'p1', 'p2'], '' );
272
+        $strings = array_filter( $strings, 'is_array' );
273
+        foreach( $strings as &$string ) {
274 274
             $string['type'] = isset($string['p1']) ? 'plural' : 'single';
275
-            $string = wp_parse_args($string, $defaultString);
275
+            $string = wp_parse_args( $string, $defaultString );
276 276
         }
277
-        return array_filter($strings, function ($string) {
277
+        return array_filter( $strings, function( $string ) {
278 278
             return !empty($string['id']);
279 279
         });
280 280
     }
Please login to merge, or discard this patch.
plugin/Modules/Html/Partials/SiteReviews.php 2 patches
Indentation   +353 added lines, -353 removed lines patch added patch discarded remove patch
@@ -21,382 +21,382 @@
 block discarded – undo
21 21
 
22 22
 class SiteReviews
23 23
 {
24
-    /**
25
-     * @var array
26
-     */
27
-    public $args;
24
+	/**
25
+	 * @var array
26
+	 */
27
+	public $args;
28 28
 
29
-    /**
30
-     * @var Review
31
-     */
32
-    public $current;
29
+	/**
30
+	 * @var Review
31
+	 */
32
+	public $current;
33 33
 
34
-    /**
35
-     * @var array
36
-     */
37
-    public $options;
34
+	/**
35
+	 * @var array
36
+	 */
37
+	public $options;
38 38
 
39
-    /**
40
-     * @var Reviews
41
-     */
42
-    protected $reviews;
39
+	/**
40
+	 * @var Reviews
41
+	 */
42
+	protected $reviews;
43 43
 
44
-    /**
45
-     * @param Reviews|null $reviews
46
-     * @return ReviewsHtml
47
-     */
48
-    public function build(array $args = [], $reviews = null)
49
-    {
50
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
-        $this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
52
-        $this->reviews = $reviews instanceof Reviews
53
-            ? $reviews
54
-            : glsr(ReviewManager::class)->get($this->args);
55
-        $this->generateSchema();
56
-        return $this->buildReviews();
57
-    }
44
+	/**
45
+	 * @param Reviews|null $reviews
46
+	 * @return ReviewsHtml
47
+	 */
48
+	public function build(array $args = [], $reviews = null)
49
+	{
50
+		$this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
+		$this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
52
+		$this->reviews = $reviews instanceof Reviews
53
+			? $reviews
54
+			: glsr(ReviewManager::class)->get($this->args);
55
+		$this->generateSchema();
56
+		return $this->buildReviews();
57
+	}
58 58
 
59
-    /**
60
-     * @return ReviewHtml
61
-     */
62
-    public function buildReview(Review $review)
63
-    {
64
-        $review = apply_filters('site-reviews/review/build/before', $review);
65
-        $this->current = $review;
66
-        $renderedFields = [];
67
-        foreach ($review as $key => $value) {
68
-            $method = Helper::buildMethodName($key, 'buildOption');
69
-            $field = method_exists($this, $method)
70
-                ? $this->$method($key, $value)
71
-                : false;
72
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
-            if (false === $field) {
74
-                continue;
75
-            }
76
-            $renderedFields[$key] = $field;
77
-        }
78
-        $this->wrap($renderedFields, $review);
79
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
-        $this->current = null;
81
-        return new ReviewHtml($review, (array) $renderedFields);
82
-    }
59
+	/**
60
+	 * @return ReviewHtml
61
+	 */
62
+	public function buildReview(Review $review)
63
+	{
64
+		$review = apply_filters('site-reviews/review/build/before', $review);
65
+		$this->current = $review;
66
+		$renderedFields = [];
67
+		foreach ($review as $key => $value) {
68
+			$method = Helper::buildMethodName($key, 'buildOption');
69
+			$field = method_exists($this, $method)
70
+				? $this->$method($key, $value)
71
+				: false;
72
+			$field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
+			if (false === $field) {
74
+				continue;
75
+			}
76
+			$renderedFields[$key] = $field;
77
+		}
78
+		$this->wrap($renderedFields, $review);
79
+		$renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
80
+		$this->current = null;
81
+		return new ReviewHtml($review, (array) $renderedFields);
82
+	}
83 83
 
84
-    /**
85
-     * @return ReviewsHtml
86
-     */
87
-    public function buildReviews()
88
-    {
89
-        $renderedReviews = [];
90
-        foreach ($this->reviews as $index => $review) {
91
-            $renderedReviews[] = $this->buildReview($review);
92
-        }
93
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
-    }
84
+	/**
85
+	 * @return ReviewsHtml
86
+	 */
87
+	public function buildReviews()
88
+	{
89
+		$renderedReviews = [];
90
+		foreach ($this->reviews as $index => $review) {
91
+			$renderedReviews[] = $this->buildReview($review);
92
+		}
93
+		return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
94
+	}
95 95
 
96
-    /**
97
-     * @return void
98
-     */
99
-    public function generateSchema()
100
-    {
101
-        if (!wp_validate_boolean($this->args['schema'])) {
102
-            return;
103
-        }
104
-        glsr(Schema::class)->store(
105
-            glsr(Schema::class)->build($this->args)
106
-        );
107
-    }
96
+	/**
97
+	 * @return void
98
+	 */
99
+	public function generateSchema()
100
+	{
101
+		if (!wp_validate_boolean($this->args['schema'])) {
102
+			return;
103
+		}
104
+		glsr(Schema::class)->store(
105
+			glsr(Schema::class)->build($this->args)
106
+		);
107
+	}
108 108
 
109
-    /**
110
-     * @param string $text
111
-     * @return string
112
-     */
113
-    public function getExcerpt($text)
114
-    {
115
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
-        $split = extension_loaded('intl')
117
-            ? $this->getExcerptIntlSplit($text, $limit)
118
-            : $this->getExcerptSplit($text, $limit);
119
-        $hiddenText = substr($text, $split);
120
-        if (!empty($hiddenText)) {
121
-            $showMore = glsr(Builder::class)->span($hiddenText, [
122
-                'class' => 'glsr-hidden glsr-hidden-text',
123
-                'data-show-less' => __('Show less', 'site-reviews'),
124
-                'data-show-more' => __('Show more', 'site-reviews'),
125
-            ]);
126
-            $text = ltrim(substr($text, 0, $split)).$showMore;
127
-        }
128
-        return $text;
129
-    }
109
+	/**
110
+	 * @param string $text
111
+	 * @return string
112
+	 */
113
+	public function getExcerpt($text)
114
+	{
115
+		$limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
+		$split = extension_loaded('intl')
117
+			? $this->getExcerptIntlSplit($text, $limit)
118
+			: $this->getExcerptSplit($text, $limit);
119
+		$hiddenText = substr($text, $split);
120
+		if (!empty($hiddenText)) {
121
+			$showMore = glsr(Builder::class)->span($hiddenText, [
122
+				'class' => 'glsr-hidden glsr-hidden-text',
123
+				'data-show-less' => __('Show less', 'site-reviews'),
124
+				'data-show-more' => __('Show more', 'site-reviews'),
125
+			]);
126
+			$text = ltrim(substr($text, 0, $split)).$showMore;
127
+		}
128
+		return $text;
129
+	}
130 130
 
131
-    /**
132
-     * @param string $key
133
-     * @param string $path
134
-     * @return bool
135
-     */
136
-    public function isHidden($key, $path = '')
137
-    {
138
-        $isOptionEnabled = !empty($path)
139
-            ? $this->isOptionEnabled($path)
140
-            : true;
141
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
-    }
131
+	/**
132
+	 * @param string $key
133
+	 * @param string $path
134
+	 * @return bool
135
+	 */
136
+	public function isHidden($key, $path = '')
137
+	{
138
+		$isOptionEnabled = !empty($path)
139
+			? $this->isOptionEnabled($path)
140
+			: true;
141
+		return in_array($key, $this->args['hide']) || !$isOptionEnabled;
142
+	}
143 143
 
144
-    /**
145
-     * @param string $key
146
-     * @param string $value
147
-     * @return bool
148
-     */
149
-    public function isHiddenOrEmpty($key, $value)
150
-    {
151
-        return $this->isHidden($key) || empty($value);
152
-    }
144
+	/**
145
+	 * @param string $key
146
+	 * @param string $value
147
+	 * @return bool
148
+	 */
149
+	public function isHiddenOrEmpty($key, $value)
150
+	{
151
+		return $this->isHidden($key) || empty($value);
152
+	}
153 153
 
154
-    /**
155
-     * @param string $text
156
-     * @return string
157
-     */
158
-    public function normalizeText($text)
159
-    {
160
-        $text = wp_kses($text, wp_kses_allowed_html());
161
-        $text = convert_smilies(strip_shortcodes($text));
162
-        $text = str_replace(']]>', ']]&gt;', $text);
163
-        $text = preg_replace('/(\R){2,}/', '$1', $text);
164
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
-            $text = $this->getExcerpt($text);
166
-        }
167
-        return wptexturize(nl2br($text));
168
-    }
154
+	/**
155
+	 * @param string $text
156
+	 * @return string
157
+	 */
158
+	public function normalizeText($text)
159
+	{
160
+		$text = wp_kses($text, wp_kses_allowed_html());
161
+		$text = convert_smilies(strip_shortcodes($text));
162
+		$text = str_replace(']]>', ']]&gt;', $text);
163
+		$text = preg_replace('/(\R){2,}/', '$1', $text);
164
+		if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
+			$text = $this->getExcerpt($text);
166
+		}
167
+		return wptexturize(nl2br($text));
168
+	}
169 169
 
170
-    /**
171
-     * @param string $key
172
-     * @param string $value
173
-     * @return void|string
174
-     */
175
-    protected function buildOptionAssignedTo($key, $value)
176
-    {
177
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
-            return;
179
-        }
180
-        $post = glsr(Polylang::class)->getPost($value);
181
-        if (!($post instanceof WP_Post)) {
182
-            return;
183
-        }
184
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
-            'href' => get_the_permalink($post->ID),
186
-        ]);
187
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
188
-        return '<span>'.$assignedTo.'</span>';
189
-    }
170
+	/**
171
+	 * @param string $key
172
+	 * @param string $value
173
+	 * @return void|string
174
+	 */
175
+	protected function buildOptionAssignedTo($key, $value)
176
+	{
177
+		if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
178
+			return;
179
+		}
180
+		$post = glsr(Polylang::class)->getPost($value);
181
+		if (!($post instanceof WP_Post)) {
182
+			return;
183
+		}
184
+		$permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
+			'href' => get_the_permalink($post->ID),
186
+		]);
187
+		$assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
188
+		return '<span>'.$assignedTo.'</span>';
189
+	}
190 190
 
191
-    /**
192
-     * @param string $key
193
-     * @param string $value
194
-     * @return void|string
195
-     */
196
-    protected function buildOptionAuthor($key, $value)
197
-    {
198
-        if (!$this->isHidden($key)) {
199
-            $name = Str::convertName(
200
-                $value,
201
-                glsr_get_option('reviews.name.format'),
202
-                glsr_get_option('reviews.name.initial')
203
-            );
204
-            return '<span>'.$name.'</span>';
205
-        }
206
-    }
191
+	/**
192
+	 * @param string $key
193
+	 * @param string $value
194
+	 * @return void|string
195
+	 */
196
+	protected function buildOptionAuthor($key, $value)
197
+	{
198
+		if (!$this->isHidden($key)) {
199
+			$name = Str::convertName(
200
+				$value,
201
+				glsr_get_option('reviews.name.format'),
202
+				glsr_get_option('reviews.name.initial')
203
+			);
204
+			return '<span>'.$name.'</span>';
205
+		}
206
+	}
207 207
 
208
-    /**
209
-     * @param string $key
210
-     * @param string $value
211
-     * @return void|string
212
-     */
213
-    protected function buildOptionAvatar($key, $value)
214
-    {
215
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
-            return;
217
-        }
218
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
219
-        return glsr(Builder::class)->img([
220
-            'height' => $size,
221
-            'src' => $this->generateAvatar($value),
222
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
-            'width' => $size,
224
-        ]);
225
-    }
208
+	/**
209
+	 * @param string $key
210
+	 * @param string $value
211
+	 * @return void|string
212
+	 */
213
+	protected function buildOptionAvatar($key, $value)
214
+	{
215
+		if ($this->isHidden($key, 'settings.reviews.avatars')) {
216
+			return;
217
+		}
218
+		$size = $this->getOption('settings.reviews.avatars_size', 40);
219
+		return glsr(Builder::class)->img([
220
+			'height' => $size,
221
+			'src' => $this->generateAvatar($value),
222
+			'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
223
+			'width' => $size,
224
+		]);
225
+	}
226 226
 
227
-    /**
228
-     * @param string $key
229
-     * @param string $value
230
-     * @return void|string
231
-     */
232
-    protected function buildOptionContent($key, $value)
233
-    {
234
-        $text = $this->normalizeText($value);
235
-        if (!$this->isHiddenOrEmpty($key, $text)) {
236
-            return '<p>'.$text.'</p>';
237
-        }
238
-    }
227
+	/**
228
+	 * @param string $key
229
+	 * @param string $value
230
+	 * @return void|string
231
+	 */
232
+	protected function buildOptionContent($key, $value)
233
+	{
234
+		$text = $this->normalizeText($value);
235
+		if (!$this->isHiddenOrEmpty($key, $text)) {
236
+			return '<p>'.$text.'</p>';
237
+		}
238
+	}
239 239
 
240
-    /**
241
-     * @param string $key
242
-     * @param string $value
243
-     * @return void|string
244
-     */
245
-    protected function buildOptionDate($key, $value)
246
-    {
247
-        if ($this->isHidden($key)) {
248
-            return;
249
-        }
250
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
-        if ('relative' == $dateFormat) {
252
-            $date = glsr(Date::class)->relative($value);
253
-        } else {
254
-            $format = 'custom' == $dateFormat
255
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
-                : glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
-            $date = date_i18n($format, strtotime($value));
258
-        }
259
-        return '<span>'.$date.'</span>';
260
-    }
240
+	/**
241
+	 * @param string $key
242
+	 * @param string $value
243
+	 * @return void|string
244
+	 */
245
+	protected function buildOptionDate($key, $value)
246
+	{
247
+		if ($this->isHidden($key)) {
248
+			return;
249
+		}
250
+		$dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
+		if ('relative' == $dateFormat) {
252
+			$date = glsr(Date::class)->relative($value);
253
+		} else {
254
+			$format = 'custom' == $dateFormat
255
+				? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
+				: glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
+			$date = date_i18n($format, strtotime($value));
258
+		}
259
+		return '<span>'.$date.'</span>';
260
+	}
261 261
 
262
-    /**
263
-     * @param string $key
264
-     * @param string $value
265
-     * @return void|string
266
-     */
267
-    protected function buildOptionRating($key, $value)
268
-    {
269
-        if (!$this->isHiddenOrEmpty($key, $value)) {
270
-            return glsr_star_rating($value);
271
-        }
272
-    }
262
+	/**
263
+	 * @param string $key
264
+	 * @param string $value
265
+	 * @return void|string
266
+	 */
267
+	protected function buildOptionRating($key, $value)
268
+	{
269
+		if (!$this->isHiddenOrEmpty($key, $value)) {
270
+			return glsr_star_rating($value);
271
+		}
272
+	}
273 273
 
274
-    /**
275
-     * @param string $key
276
-     * @param string $value
277
-     * @return void|string
278
-     */
279
-    protected function buildOptionResponse($key, $value)
280
-    {
281
-        if ($this->isHiddenOrEmpty($key, $value)) {
282
-            return;
283
-        }
284
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
-        $text = $this->normalizeText($value);
286
-        $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
289
-        return $response.$background;
290
-    }
274
+	/**
275
+	 * @param string $key
276
+	 * @param string $value
277
+	 * @return void|string
278
+	 */
279
+	protected function buildOptionResponse($key, $value)
280
+	{
281
+		if ($this->isHiddenOrEmpty($key, $value)) {
282
+			return;
283
+		}
284
+		$title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
+		$text = $this->normalizeText($value);
286
+		$text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
+		$response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
+		$background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
289
+		return $response.$background;
290
+	}
291 291
 
292
-    /**
293
-     * @param string $key
294
-     * @param string $value
295
-     * @return void|string
296
-     */
297
-    protected function buildOptionTitle($key, $value)
298
-    {
299
-        if ($this->isHidden($key)) {
300
-            return;
301
-        }
302
-        if (empty($value)) {
303
-            $value = __('No Title', 'site-reviews');
304
-        }
305
-        return '<h3>'.$value.'</h3>';
306
-    }
292
+	/**
293
+	 * @param string $key
294
+	 * @param string $value
295
+	 * @return void|string
296
+	 */
297
+	protected function buildOptionTitle($key, $value)
298
+	{
299
+		if ($this->isHidden($key)) {
300
+			return;
301
+		}
302
+		if (empty($value)) {
303
+			$value = __('No Title', 'site-reviews');
304
+		}
305
+		return '<h3>'.$value.'</h3>';
306
+	}
307 307
 
308
-    /**
309
-     * @param string $avatarUrl
310
-     * @return string
311
-     */
312
-    protected function generateAvatar($avatarUrl)
313
-    {
314
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
-            return $avatarUrl;
316
-        }
317
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
318
-        if (empty($authorIdOrEmail)) {
319
-            $authorIdOrEmail = $this->current->email;
320
-        }
321
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
322
-            return $newAvatar;
323
-        }
324
-        return $avatarUrl;
325
-    }
308
+	/**
309
+	 * @param string $avatarUrl
310
+	 * @return string
311
+	 */
312
+	protected function generateAvatar($avatarUrl)
313
+	{
314
+		if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
315
+			return $avatarUrl;
316
+		}
317
+		$authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
318
+		if (empty($authorIdOrEmail)) {
319
+			$authorIdOrEmail = $this->current->email;
320
+		}
321
+		if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
322
+			return $newAvatar;
323
+		}
324
+		return $avatarUrl;
325
+	}
326 326
 
327
-    /**
328
-     * @param string $text
329
-     * @param int $limit
330
-     * @return int
331
-     */
332
-    protected function getExcerptIntlSplit($text, $limit)
333
-    {
334
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
335
-        $words->setText($text);
336
-        $count = 0;
337
-        foreach ($words as $offset) {
338
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
339
-                continue;
340
-            }
341
-            ++$count;
342
-            if ($count != $limit) {
343
-                continue;
344
-            }
345
-            return $offset;
346
-        }
347
-        return strlen($text);
348
-    }
327
+	/**
328
+	 * @param string $text
329
+	 * @param int $limit
330
+	 * @return int
331
+	 */
332
+	protected function getExcerptIntlSplit($text, $limit)
333
+	{
334
+		$words = IntlRuleBasedBreakIterator::createWordInstance('');
335
+		$words->setText($text);
336
+		$count = 0;
337
+		foreach ($words as $offset) {
338
+			if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
339
+				continue;
340
+			}
341
+			++$count;
342
+			if ($count != $limit) {
343
+				continue;
344
+			}
345
+			return $offset;
346
+		}
347
+		return strlen($text);
348
+	}
349 349
 
350
-    /**
351
-     * @param string $text
352
-     * @param int $limit
353
-     * @return int
354
-     */
355
-    protected function getExcerptSplit($text, $limit)
356
-    {
357
-        if (str_word_count($text, 0) > $limit) {
358
-            $words = array_keys(str_word_count($text, 2));
359
-            return $words[$limit];
360
-        }
361
-        return strlen($text);
362
-    }
350
+	/**
351
+	 * @param string $text
352
+	 * @param int $limit
353
+	 * @return int
354
+	 */
355
+	protected function getExcerptSplit($text, $limit)
356
+	{
357
+		if (str_word_count($text, 0) > $limit) {
358
+			$words = array_keys(str_word_count($text, 2));
359
+			return $words[$limit];
360
+		}
361
+		return strlen($text);
362
+	}
363 363
 
364
-    /**
365
-     * @param string $path
366
-     * @param mixed $fallback
367
-     * @return mixed
368
-     */
369
-    protected function getOption($path, $fallback = '')
370
-    {
371
-        if (array_key_exists($path, $this->options)) {
372
-            return $this->options[$path];
373
-        }
374
-        return $fallback;
375
-    }
364
+	/**
365
+	 * @param string $path
366
+	 * @param mixed $fallback
367
+	 * @return mixed
368
+	 */
369
+	protected function getOption($path, $fallback = '')
370
+	{
371
+		if (array_key_exists($path, $this->options)) {
372
+			return $this->options[$path];
373
+		}
374
+		return $fallback;
375
+	}
376 376
 
377
-    /**
378
-     * @param string $path
379
-     * @return bool
380
-     */
381
-    protected function isOptionEnabled($path)
382
-    {
383
-        return 'yes' == $this->getOption($path);
384
-    }
377
+	/**
378
+	 * @param string $path
379
+	 * @return bool
380
+	 */
381
+	protected function isOptionEnabled($path)
382
+	{
383
+		return 'yes' == $this->getOption($path);
384
+	}
385 385
 
386
-    /**
387
-     * @return void
388
-     */
389
-    protected function wrap(array &$renderedFields, Review $review)
390
-    {
391
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
392
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
393
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
394
-            if (empty($value)) {
395
-                return;
396
-            }
397
-            $value = glsr(Builder::class)->div($value, [
398
-                'class' => 'glsr-review-'.$key,
399
-            ]);
400
-        });
401
-    }
386
+	/**
387
+	 * @return void
388
+	 */
389
+	protected function wrap(array &$renderedFields, Review $review)
390
+	{
391
+		$renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
392
+		array_walk($renderedFields, function (&$value, $key) use ($review) {
393
+			$value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
394
+			if (empty($value)) {
395
+				return;
396
+			}
397
+			$value = glsr(Builder::class)->div($value, [
398
+				'class' => 'glsr-review-'.$key,
399
+			]);
400
+		});
401
+	}
402 402
 }
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
      * @param Reviews|null $reviews
46 46
      * @return ReviewsHtml
47 47
      */
48
-    public function build(array $args = [], $reviews = null)
48
+    public function build( array $args = [], $reviews = null )
49 49
     {
50
-        $this->args = glsr(SiteReviewsDefaults::class)->merge($args);
51
-        $this->options = Arr::flattenArray(glsr(OptionManager::class)->all());
50
+        $this->args = glsr( SiteReviewsDefaults::class )->merge( $args );
51
+        $this->options = Arr::flattenArray( glsr( OptionManager::class )->all() );
52 52
         $this->reviews = $reviews instanceof Reviews
53 53
             ? $reviews
54
-            : glsr(ReviewManager::class)->get($this->args);
54
+            : glsr( ReviewManager::class )->get( $this->args );
55 55
         $this->generateSchema();
56 56
         return $this->buildReviews();
57 57
     }
@@ -59,26 +59,26 @@  discard block
 block discarded – undo
59 59
     /**
60 60
      * @return ReviewHtml
61 61
      */
62
-    public function buildReview(Review $review)
62
+    public function buildReview( Review $review )
63 63
     {
64
-        $review = apply_filters('site-reviews/review/build/before', $review);
64
+        $review = apply_filters( 'site-reviews/review/build/before', $review );
65 65
         $this->current = $review;
66 66
         $renderedFields = [];
67
-        foreach ($review as $key => $value) {
68
-            $method = Helper::buildMethodName($key, 'buildOption');
69
-            $field = method_exists($this, $method)
70
-                ? $this->$method($key, $value)
67
+        foreach( $review as $key => $value ) {
68
+            $method = Helper::buildMethodName( $key, 'buildOption' );
69
+            $field = method_exists( $this, $method )
70
+                ? $this->$method( $key, $value )
71 71
                 : false;
72
-            $field = apply_filters('site-reviews/review/build/'.$key, $field, $value, $review, $this);
73
-            if (false === $field) {
72
+            $field = apply_filters( 'site-reviews/review/build/'.$key, $field, $value, $review, $this );
73
+            if( false === $field ) {
74 74
                 continue;
75 75
             }
76 76
             $renderedFields[$key] = $field;
77 77
         }
78
-        $this->wrap($renderedFields, $review);
79
-        $renderedFields = apply_filters('site-reviews/review/build/after', $renderedFields, $review, $this);
78
+        $this->wrap( $renderedFields, $review );
79
+        $renderedFields = apply_filters( 'site-reviews/review/build/after', $renderedFields, $review, $this );
80 80
         $this->current = null;
81
-        return new ReviewHtml($review, (array) $renderedFields);
81
+        return new ReviewHtml( $review, (array)$renderedFields );
82 82
     }
83 83
 
84 84
     /**
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
     public function buildReviews()
88 88
     {
89 89
         $renderedReviews = [];
90
-        foreach ($this->reviews as $index => $review) {
91
-            $renderedReviews[] = $this->buildReview($review);
90
+        foreach( $this->reviews as $index => $review ) {
91
+            $renderedReviews[] = $this->buildReview( $review );
92 92
         }
93
-        return new ReviewsHtml($renderedReviews, $this->reviews->max_num_pages, $this->args);
93
+        return new ReviewsHtml( $renderedReviews, $this->reviews->max_num_pages, $this->args );
94 94
     }
95 95
 
96 96
     /**
@@ -98,11 +98,11 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function generateSchema()
100 100
     {
101
-        if (!wp_validate_boolean($this->args['schema'])) {
101
+        if( !wp_validate_boolean( $this->args['schema'] ) ) {
102 102
             return;
103 103
         }
104
-        glsr(Schema::class)->store(
105
-            glsr(Schema::class)->build($this->args)
104
+        glsr( Schema::class )->store(
105
+            glsr( Schema::class )->build( $this->args )
106 106
         );
107 107
     }
108 108
 
@@ -110,20 +110,20 @@  discard block
 block discarded – undo
110 110
      * @param string $text
111 111
      * @return string
112 112
      */
113
-    public function getExcerpt($text)
113
+    public function getExcerpt( $text )
114 114
     {
115
-        $limit = intval($this->getOption('settings.reviews.excerpts_length', 55));
116
-        $split = extension_loaded('intl')
117
-            ? $this->getExcerptIntlSplit($text, $limit)
118
-            : $this->getExcerptSplit($text, $limit);
119
-        $hiddenText = substr($text, $split);
120
-        if (!empty($hiddenText)) {
121
-            $showMore = glsr(Builder::class)->span($hiddenText, [
115
+        $limit = intval( $this->getOption( 'settings.reviews.excerpts_length', 55 ) );
116
+        $split = extension_loaded( 'intl' )
117
+            ? $this->getExcerptIntlSplit( $text, $limit )
118
+            : $this->getExcerptSplit( $text, $limit );
119
+        $hiddenText = substr( $text, $split );
120
+        if( !empty($hiddenText) ) {
121
+            $showMore = glsr( Builder::class )->span( $hiddenText, [
122 122
                 'class' => 'glsr-hidden glsr-hidden-text',
123
-                'data-show-less' => __('Show less', 'site-reviews'),
124
-                'data-show-more' => __('Show more', 'site-reviews'),
125
-            ]);
126
-            $text = ltrim(substr($text, 0, $split)).$showMore;
123
+                'data-show-less' => __( 'Show less', 'site-reviews' ),
124
+                'data-show-more' => __( 'Show more', 'site-reviews' ),
125
+            ] );
126
+            $text = ltrim( substr( $text, 0, $split ) ).$showMore;
127 127
         }
128 128
         return $text;
129 129
     }
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
      * @param string $path
134 134
      * @return bool
135 135
      */
136
-    public function isHidden($key, $path = '')
136
+    public function isHidden( $key, $path = '' )
137 137
     {
138 138
         $isOptionEnabled = !empty($path)
139
-            ? $this->isOptionEnabled($path)
139
+            ? $this->isOptionEnabled( $path )
140 140
             : true;
141
-        return in_array($key, $this->args['hide']) || !$isOptionEnabled;
141
+        return in_array( $key, $this->args['hide'] ) || !$isOptionEnabled;
142 142
     }
143 143
 
144 144
     /**
@@ -146,25 +146,25 @@  discard block
 block discarded – undo
146 146
      * @param string $value
147 147
      * @return bool
148 148
      */
149
-    public function isHiddenOrEmpty($key, $value)
149
+    public function isHiddenOrEmpty( $key, $value )
150 150
     {
151
-        return $this->isHidden($key) || empty($value);
151
+        return $this->isHidden( $key ) || empty($value);
152 152
     }
153 153
 
154 154
     /**
155 155
      * @param string $text
156 156
      * @return string
157 157
      */
158
-    public function normalizeText($text)
158
+    public function normalizeText( $text )
159 159
     {
160
-        $text = wp_kses($text, wp_kses_allowed_html());
161
-        $text = convert_smilies(strip_shortcodes($text));
162
-        $text = str_replace(']]>', ']]&gt;', $text);
163
-        $text = preg_replace('/(\R){2,}/', '$1', $text);
164
-        if ($this->isOptionEnabled('settings.reviews.excerpts')) {
165
-            $text = $this->getExcerpt($text);
160
+        $text = wp_kses( $text, wp_kses_allowed_html() );
161
+        $text = convert_smilies( strip_shortcodes( $text ) );
162
+        $text = str_replace( ']]>', ']]&gt;', $text );
163
+        $text = preg_replace( '/(\R){2,}/', '$1', $text );
164
+        if( $this->isOptionEnabled( 'settings.reviews.excerpts' ) ) {
165
+            $text = $this->getExcerpt( $text );
166 166
         }
167
-        return wptexturize(nl2br($text));
167
+        return wptexturize( nl2br( $text ) );
168 168
     }
169 169
 
170 170
     /**
@@ -172,19 +172,19 @@  discard block
 block discarded – undo
172 172
      * @param string $value
173 173
      * @return void|string
174 174
      */
175
-    protected function buildOptionAssignedTo($key, $value)
175
+    protected function buildOptionAssignedTo( $key, $value )
176 176
     {
177
-        if ($this->isHidden($key, 'settings.reviews.assigned_links')) {
177
+        if( $this->isHidden( $key, 'settings.reviews.assigned_links' ) ) {
178 178
             return;
179 179
         }
180
-        $post = glsr(Polylang::class)->getPost($value);
181
-        if (!($post instanceof WP_Post)) {
180
+        $post = glsr( Polylang::class )->getPost( $value );
181
+        if( !($post instanceof WP_Post) ) {
182 182
             return;
183 183
         }
184
-        $permalink = glsr(Builder::class)->a(get_the_title($post->ID), [
185
-            'href' => get_the_permalink($post->ID),
186
-        ]);
187
-        $assignedTo = sprintf(__('Review of %s', 'site-reviews'), $permalink);
184
+        $permalink = glsr( Builder::class )->a( get_the_title( $post->ID ), [
185
+            'href' => get_the_permalink( $post->ID ),
186
+        ] );
187
+        $assignedTo = sprintf( __( 'Review of %s', 'site-reviews' ), $permalink );
188 188
         return '<span>'.$assignedTo.'</span>';
189 189
     }
190 190
 
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
      * @param string $value
194 194
      * @return void|string
195 195
      */
196
-    protected function buildOptionAuthor($key, $value)
196
+    protected function buildOptionAuthor( $key, $value )
197 197
     {
198
-        if (!$this->isHidden($key)) {
198
+        if( !$this->isHidden( $key ) ) {
199 199
             $name = Str::convertName(
200 200
                 $value,
201
-                glsr_get_option('reviews.name.format'),
202
-                glsr_get_option('reviews.name.initial')
201
+                glsr_get_option( 'reviews.name.format' ),
202
+                glsr_get_option( 'reviews.name.initial' )
203 203
             );
204 204
             return '<span>'.$name.'</span>';
205 205
         }
@@ -210,18 +210,18 @@  discard block
 block discarded – undo
210 210
      * @param string $value
211 211
      * @return void|string
212 212
      */
213
-    protected function buildOptionAvatar($key, $value)
213
+    protected function buildOptionAvatar( $key, $value )
214 214
     {
215
-        if ($this->isHidden($key, 'settings.reviews.avatars')) {
215
+        if( $this->isHidden( $key, 'settings.reviews.avatars' ) ) {
216 216
             return;
217 217
         }
218
-        $size = $this->getOption('settings.reviews.avatars_size', 40);
219
-        return glsr(Builder::class)->img([
218
+        $size = $this->getOption( 'settings.reviews.avatars_size', 40 );
219
+        return glsr( Builder::class )->img( [
220 220
             'height' => $size,
221
-            'src' => $this->generateAvatar($value),
222
-            'style' => sprintf('width:%1$spx; height:%1$spx;', $size),
221
+            'src' => $this->generateAvatar( $value ),
222
+            'style' => sprintf( 'width:%1$spx; height:%1$spx;', $size ),
223 223
             'width' => $size,
224
-        ]);
224
+        ] );
225 225
     }
226 226
 
227 227
     /**
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
      * @param string $value
230 230
      * @return void|string
231 231
      */
232
-    protected function buildOptionContent($key, $value)
232
+    protected function buildOptionContent( $key, $value )
233 233
     {
234
-        $text = $this->normalizeText($value);
235
-        if (!$this->isHiddenOrEmpty($key, $text)) {
234
+        $text = $this->normalizeText( $value );
235
+        if( !$this->isHiddenOrEmpty( $key, $text ) ) {
236 236
             return '<p>'.$text.'</p>';
237 237
         }
238 238
     }
@@ -242,19 +242,19 @@  discard block
 block discarded – undo
242 242
      * @param string $value
243 243
      * @return void|string
244 244
      */
245
-    protected function buildOptionDate($key, $value)
245
+    protected function buildOptionDate( $key, $value )
246 246
     {
247
-        if ($this->isHidden($key)) {
247
+        if( $this->isHidden( $key ) ) {
248 248
             return;
249 249
         }
250
-        $dateFormat = $this->getOption('settings.reviews.date.format', 'default');
251
-        if ('relative' == $dateFormat) {
252
-            $date = glsr(Date::class)->relative($value);
250
+        $dateFormat = $this->getOption( 'settings.reviews.date.format', 'default' );
251
+        if( 'relative' == $dateFormat ) {
252
+            $date = glsr( Date::class )->relative( $value );
253 253
         } else {
254 254
             $format = 'custom' == $dateFormat
255
-                ? $this->getOption('settings.reviews.date.custom', 'M j, Y')
256
-                : glsr(OptionManager::class)->getWP('date_format', 'F j, Y');
257
-            $date = date_i18n($format, strtotime($value));
255
+                ? $this->getOption( 'settings.reviews.date.custom', 'M j, Y' )
256
+                : glsr( OptionManager::class )->getWP( 'date_format', 'F j, Y' );
257
+            $date = date_i18n( $format, strtotime( $value ) );
258 258
         }
259 259
         return '<span>'.$date.'</span>';
260 260
     }
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
      * @param string $value
265 265
      * @return void|string
266 266
      */
267
-    protected function buildOptionRating($key, $value)
267
+    protected function buildOptionRating( $key, $value )
268 268
     {
269
-        if (!$this->isHiddenOrEmpty($key, $value)) {
270
-            return glsr_star_rating($value);
269
+        if( !$this->isHiddenOrEmpty( $key, $value ) ) {
270
+            return glsr_star_rating( $value );
271 271
         }
272 272
     }
273 273
 
@@ -276,16 +276,16 @@  discard block
 block discarded – undo
276 276
      * @param string $value
277 277
      * @return void|string
278 278
      */
279
-    protected function buildOptionResponse($key, $value)
279
+    protected function buildOptionResponse( $key, $value )
280 280
     {
281
-        if ($this->isHiddenOrEmpty($key, $value)) {
281
+        if( $this->isHiddenOrEmpty( $key, $value ) ) {
282 282
             return;
283 283
         }
284
-        $title = sprintf(__('Response from %s', 'site-reviews'), get_bloginfo('name'));
285
-        $text = $this->normalizeText($value);
284
+        $title = sprintf( __( 'Response from %s', 'site-reviews' ), get_bloginfo( 'name' ) );
285
+        $text = $this->normalizeText( $value );
286 286
         $text = '<p><strong>'.$title.'</strong></p><p>'.$text.'</p>';
287
-        $response = glsr(Builder::class)->div($text, ['class' => 'glsr-review-response-inner']);
288
-        $background = glsr(Builder::class)->div(['class' => 'glsr-review-response-background']);
287
+        $response = glsr( Builder::class )->div( $text, ['class' => 'glsr-review-response-inner'] );
288
+        $background = glsr( Builder::class )->div( ['class' => 'glsr-review-response-background'] );
289 289
         return $response.$background;
290 290
     }
291 291
 
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
      * @param string $value
295 295
      * @return void|string
296 296
      */
297
-    protected function buildOptionTitle($key, $value)
297
+    protected function buildOptionTitle( $key, $value )
298 298
     {
299
-        if ($this->isHidden($key)) {
299
+        if( $this->isHidden( $key ) ) {
300 300
             return;
301 301
         }
302
-        if (empty($value)) {
303
-            $value = __('No Title', 'site-reviews');
302
+        if( empty($value) ) {
303
+            $value = __( 'No Title', 'site-reviews' );
304 304
         }
305 305
         return '<h3>'.$value.'</h3>';
306 306
     }
@@ -309,16 +309,16 @@  discard block
 block discarded – undo
309 309
      * @param string $avatarUrl
310 310
      * @return string
311 311
      */
312
-    protected function generateAvatar($avatarUrl)
312
+    protected function generateAvatar( $avatarUrl )
313 313
     {
314
-        if (!$this->isOptionEnabled('settings.reviews.avatars_regenerate') || 'local' != $this->current->review_type) {
314
+        if( !$this->isOptionEnabled( 'settings.reviews.avatars_regenerate' ) || 'local' != $this->current->review_type ) {
315 315
             return $avatarUrl;
316 316
         }
317
-        $authorIdOrEmail = get_the_author_meta('ID', $this->current->user_id);
318
-        if (empty($authorIdOrEmail)) {
317
+        $authorIdOrEmail = get_the_author_meta( 'ID', $this->current->user_id );
318
+        if( empty($authorIdOrEmail) ) {
319 319
             $authorIdOrEmail = $this->current->email;
320 320
         }
321
-        if ($newAvatar = get_avatar_url($authorIdOrEmail)) {
321
+        if( $newAvatar = get_avatar_url( $authorIdOrEmail ) ) {
322 322
             return $newAvatar;
323 323
         }
324 324
         return $avatarUrl;
@@ -329,22 +329,22 @@  discard block
 block discarded – undo
329 329
      * @param int $limit
330 330
      * @return int
331 331
      */
332
-    protected function getExcerptIntlSplit($text, $limit)
332
+    protected function getExcerptIntlSplit( $text, $limit )
333 333
     {
334
-        $words = IntlRuleBasedBreakIterator::createWordInstance('');
335
-        $words->setText($text);
334
+        $words = IntlRuleBasedBreakIterator::createWordInstance( '' );
335
+        $words->setText( $text );
336 336
         $count = 0;
337
-        foreach ($words as $offset) {
338
-            if (IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus()) {
337
+        foreach( $words as $offset ) {
338
+            if( IntlRuleBasedBreakIterator::WORD_NONE === $words->getRuleStatus() ) {
339 339
                 continue;
340 340
             }
341 341
             ++$count;
342
-            if ($count != $limit) {
342
+            if( $count != $limit ) {
343 343
                 continue;
344 344
             }
345 345
             return $offset;
346 346
         }
347
-        return strlen($text);
347
+        return strlen( $text );
348 348
     }
349 349
 
350 350
     /**
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
      * @param int $limit
353 353
      * @return int
354 354
      */
355
-    protected function getExcerptSplit($text, $limit)
355
+    protected function getExcerptSplit( $text, $limit )
356 356
     {
357
-        if (str_word_count($text, 0) > $limit) {
358
-            $words = array_keys(str_word_count($text, 2));
357
+        if( str_word_count( $text, 0 ) > $limit ) {
358
+            $words = array_keys( str_word_count( $text, 2 ) );
359 359
             return $words[$limit];
360 360
         }
361
-        return strlen($text);
361
+        return strlen( $text );
362 362
     }
363 363
 
364 364
     /**
@@ -366,9 +366,9 @@  discard block
 block discarded – undo
366 366
      * @param mixed $fallback
367 367
      * @return mixed
368 368
      */
369
-    protected function getOption($path, $fallback = '')
369
+    protected function getOption( $path, $fallback = '' )
370 370
     {
371
-        if (array_key_exists($path, $this->options)) {
371
+        if( array_key_exists( $path, $this->options ) ) {
372 372
             return $this->options[$path];
373 373
         }
374 374
         return $fallback;
@@ -378,25 +378,25 @@  discard block
 block discarded – undo
378 378
      * @param string $path
379 379
      * @return bool
380 380
      */
381
-    protected function isOptionEnabled($path)
381
+    protected function isOptionEnabled( $path )
382 382
     {
383
-        return 'yes' == $this->getOption($path);
383
+        return 'yes' == $this->getOption( $path );
384 384
     }
385 385
 
386 386
     /**
387 387
      * @return void
388 388
      */
389
-    protected function wrap(array &$renderedFields, Review $review)
389
+    protected function wrap( array &$renderedFields, Review $review )
390 390
     {
391
-        $renderedFields = apply_filters('site-reviews/review/wrap', $renderedFields, $review, $this);
392
-        array_walk($renderedFields, function (&$value, $key) use ($review) {
393
-            $value = apply_filters('site-reviews/review/wrap/'.$key, $value, $review);
394
-            if (empty($value)) {
391
+        $renderedFields = apply_filters( 'site-reviews/review/wrap', $renderedFields, $review, $this );
392
+        array_walk( $renderedFields, function( &$value, $key ) use ($review) {
393
+            $value = apply_filters( 'site-reviews/review/wrap/'.$key, $value, $review );
394
+            if( empty($value) ) {
395 395
                 return;
396 396
             }
397
-            $value = glsr(Builder::class)->div($value, [
397
+            $value = glsr( Builder::class )->div( $value, [
398 398
                 'class' => 'glsr-review-'.$key,
399
-            ]);
399
+            ] );
400 400
         });
401 401
     }
402 402
 }
Please login to merge, or discard this patch.
plugin/Modules/Translator.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -6,155 +6,155 @@
 block discarded – undo
6 6
 
7 7
 class Translator
8 8
 {
9
-    /**
10
-     * @param string $translation
11
-     * @param string $text
12
-     * @param string $domain
13
-     * @return string
14
-     * @filter gettext
15
-     */
16
-    public function filterGettext($translation, $text, $domain)
17
-    {
18
-        return $this->translate($translation, $domain, [
19
-            'single' => $text,
20
-        ]);
21
-    }
9
+	/**
10
+	 * @param string $translation
11
+	 * @param string $text
12
+	 * @param string $domain
13
+	 * @return string
14
+	 * @filter gettext
15
+	 */
16
+	public function filterGettext($translation, $text, $domain)
17
+	{
18
+		return $this->translate($translation, $domain, [
19
+			'single' => $text,
20
+		]);
21
+	}
22 22
 
23
-    /**
24
-     * @param string $translation
25
-     * @param string $text
26
-     * @param string $context
27
-     * @param string $domain
28
-     * @return string
29
-     * @filter gettext_with_context
30
-     */
31
-    public function filterGettextWithContext($translation, $text, $context, $domain)
32
-    {
33
-        return $this->translate($translation, $domain, [
34
-            'context' => $context,
35
-            'single' => $text,
36
-        ]);
37
-    }
23
+	/**
24
+	 * @param string $translation
25
+	 * @param string $text
26
+	 * @param string $context
27
+	 * @param string $domain
28
+	 * @return string
29
+	 * @filter gettext_with_context
30
+	 */
31
+	public function filterGettextWithContext($translation, $text, $context, $domain)
32
+	{
33
+		return $this->translate($translation, $domain, [
34
+			'context' => $context,
35
+			'single' => $text,
36
+		]);
37
+	}
38 38
 
39
-    /**
40
-     * @param string $translation
41
-     * @param string $single
42
-     * @param string $plural
43
-     * @param int $number
44
-     * @param string $domain
45
-     * @return string
46
-     * @filter ngettext
47
-     */
48
-    public function filterNgettext($translation, $single, $plural, $number, $domain)
49
-    {
50
-        return $this->translate($translation, $domain, [
51
-            'number' => $number,
52
-            'plural' => $plural,
53
-            'single' => $single,
54
-        ]);
55
-    }
39
+	/**
40
+	 * @param string $translation
41
+	 * @param string $single
42
+	 * @param string $plural
43
+	 * @param int $number
44
+	 * @param string $domain
45
+	 * @return string
46
+	 * @filter ngettext
47
+	 */
48
+	public function filterNgettext($translation, $single, $plural, $number, $domain)
49
+	{
50
+		return $this->translate($translation, $domain, [
51
+			'number' => $number,
52
+			'plural' => $plural,
53
+			'single' => $single,
54
+		]);
55
+	}
56 56
 
57
-    /**
58
-     * @param string $translation
59
-     * @param string $single
60
-     * @param string $plural
61
-     * @param int $number
62
-     * @param string $context
63
-     * @param string $domain
64
-     * @return string
65
-     * @filter ngettext_with_context
66
-     */
67
-    public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain)
68
-    {
69
-        return $this->translate($translation, $domain, [
70
-            'context' => $context,
71
-            'number' => $number,
72
-            'plural' => $plural,
73
-            'single' => $single,
74
-        ]);
75
-    }
57
+	/**
58
+	 * @param string $translation
59
+	 * @param string $single
60
+	 * @param string $plural
61
+	 * @param int $number
62
+	 * @param string $context
63
+	 * @param string $domain
64
+	 * @return string
65
+	 * @filter ngettext_with_context
66
+	 */
67
+	public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain)
68
+	{
69
+		return $this->translate($translation, $domain, [
70
+			'context' => $context,
71
+			'number' => $number,
72
+			'plural' => $plural,
73
+			'single' => $single,
74
+		]);
75
+	}
76 76
 
77
-    /**
78
-     * @param string $original
79
-     * @param string $domain
80
-     * @return string
81
-     */
82
-    public function translate($original, $domain, array $args)
83
-    {
84
-        $domains = apply_filters('site-reviews/translator/domains', [Application::ID]);
85
-        if (!in_array($domain, $domains)) {
86
-            return $original;
87
-        }
88
-        $args = $this->normalizeTranslationArgs($args);
89
-        $strings = $this->getTranslationStrings($args['single'], $args['plural']);
90
-        if (empty($strings)) {
91
-            return $original;
92
-        }
93
-        $string = current($strings);
94
-        return 'plural' == $string['type']
95
-            ? $this->translatePlural($domain, $string, $args)
96
-            : $this->translateSingle($domain, $string, $args);
97
-    }
77
+	/**
78
+	 * @param string $original
79
+	 * @param string $domain
80
+	 * @return string
81
+	 */
82
+	public function translate($original, $domain, array $args)
83
+	{
84
+		$domains = apply_filters('site-reviews/translator/domains', [Application::ID]);
85
+		if (!in_array($domain, $domains)) {
86
+			return $original;
87
+		}
88
+		$args = $this->normalizeTranslationArgs($args);
89
+		$strings = $this->getTranslationStrings($args['single'], $args['plural']);
90
+		if (empty($strings)) {
91
+			return $original;
92
+		}
93
+		$string = current($strings);
94
+		return 'plural' == $string['type']
95
+			? $this->translatePlural($domain, $string, $args)
96
+			: $this->translateSingle($domain, $string, $args);
97
+	}
98 98
 
99
-    /**
100
-     * @param string $single
101
-     * @param string $plural
102
-     * @return array
103
-     */
104
-    protected function getTranslationStrings($single, $plural)
105
-    {
106
-        return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) {
107
-            return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8')
108
-                && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8');
109
-        });
110
-    }
99
+	/**
100
+	 * @param string $single
101
+	 * @param string $plural
102
+	 * @return array
103
+	 */
104
+	protected function getTranslationStrings($single, $plural)
105
+	{
106
+		return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) {
107
+			return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8')
108
+				&& $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8');
109
+		});
110
+	}
111 111
 
112
-    /**
113
-     * @return array
114
-     */
115
-    protected function normalizeTranslationArgs(array $args)
116
-    {
117
-        $defaults = [
118
-            'context' => '',
119
-            'number' => 1,
120
-            'plural' => '',
121
-            'single' => '',
122
-        ];
123
-        return shortcode_atts($defaults, $args);
124
-    }
112
+	/**
113
+	 * @return array
114
+	 */
115
+	protected function normalizeTranslationArgs(array $args)
116
+	{
117
+		$defaults = [
118
+			'context' => '',
119
+			'number' => 1,
120
+			'plural' => '',
121
+			'single' => '',
122
+		];
123
+		return shortcode_atts($defaults, $args);
124
+	}
125 125
 
126
-    /**
127
-     * @param string $domain
128
-     * @return string
129
-     */
130
-    protected function translatePlural($domain, array $string, array $args)
131
-    {
132
-        if (!empty($string['s2'])) {
133
-            $args['single'] = $string['s2'];
134
-        }
135
-        if (!empty($string['p2'])) {
136
-            $args['plural'] = $string['p2'];
137
-        }
138
-        return get_translations_for_domain($domain)->translate_plural(
139
-            $args['single'],
140
-            $args['plural'],
141
-            $args['number'],
142
-            $args['context']
143
-        );
144
-    }
126
+	/**
127
+	 * @param string $domain
128
+	 * @return string
129
+	 */
130
+	protected function translatePlural($domain, array $string, array $args)
131
+	{
132
+		if (!empty($string['s2'])) {
133
+			$args['single'] = $string['s2'];
134
+		}
135
+		if (!empty($string['p2'])) {
136
+			$args['plural'] = $string['p2'];
137
+		}
138
+		return get_translations_for_domain($domain)->translate_plural(
139
+			$args['single'],
140
+			$args['plural'],
141
+			$args['number'],
142
+			$args['context']
143
+		);
144
+	}
145 145
 
146
-    /**
147
-     * @param string $domain
148
-     * @return string
149
-     */
150
-    protected function translateSingle($domain, array $string, array $args)
151
-    {
152
-        if (!empty($string['s2'])) {
153
-            $args['single'] = $string['s2'];
154
-        }
155
-        return get_translations_for_domain($domain)->translate(
156
-            $args['single'],
157
-            $args['context']
158
-        );
159
-    }
146
+	/**
147
+	 * @param string $domain
148
+	 * @return string
149
+	 */
150
+	protected function translateSingle($domain, array $string, array $args)
151
+	{
152
+		if (!empty($string['s2'])) {
153
+			$args['single'] = $string['s2'];
154
+		}
155
+		return get_translations_for_domain($domain)->translate(
156
+			$args['single'],
157
+			$args['context']
158
+		);
159
+	}
160 160
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -13,11 +13,11 @@  discard block
 block discarded – undo
13 13
      * @return string
14 14
      * @filter gettext
15 15
      */
16
-    public function filterGettext($translation, $text, $domain)
16
+    public function filterGettext( $translation, $text, $domain )
17 17
     {
18
-        return $this->translate($translation, $domain, [
18
+        return $this->translate( $translation, $domain, [
19 19
             'single' => $text,
20
-        ]);
20
+        ] );
21 21
     }
22 22
 
23 23
     /**
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
      * @return string
29 29
      * @filter gettext_with_context
30 30
      */
31
-    public function filterGettextWithContext($translation, $text, $context, $domain)
31
+    public function filterGettextWithContext( $translation, $text, $context, $domain )
32 32
     {
33
-        return $this->translate($translation, $domain, [
33
+        return $this->translate( $translation, $domain, [
34 34
             'context' => $context,
35 35
             'single' => $text,
36
-        ]);
36
+        ] );
37 37
     }
38 38
 
39 39
     /**
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
      * @return string
46 46
      * @filter ngettext
47 47
      */
48
-    public function filterNgettext($translation, $single, $plural, $number, $domain)
48
+    public function filterNgettext( $translation, $single, $plural, $number, $domain )
49 49
     {
50
-        return $this->translate($translation, $domain, [
50
+        return $this->translate( $translation, $domain, [
51 51
             'number' => $number,
52 52
             'plural' => $plural,
53 53
             'single' => $single,
54
-        ]);
54
+        ] );
55 55
     }
56 56
 
57 57
     /**
@@ -64,14 +64,14 @@  discard block
 block discarded – undo
64 64
      * @return string
65 65
      * @filter ngettext_with_context
66 66
      */
67
-    public function filterNgettextWithContext($translation, $single, $plural, $number, $context, $domain)
67
+    public function filterNgettextWithContext( $translation, $single, $plural, $number, $context, $domain )
68 68
     {
69
-        return $this->translate($translation, $domain, [
69
+        return $this->translate( $translation, $domain, [
70 70
             'context' => $context,
71 71
             'number' => $number,
72 72
             'plural' => $plural,
73 73
             'single' => $single,
74
-        ]);
74
+        ] );
75 75
     }
76 76
 
77 77
     /**
@@ -79,21 +79,21 @@  discard block
 block discarded – undo
79 79
      * @param string $domain
80 80
      * @return string
81 81
      */
82
-    public function translate($original, $domain, array $args)
82
+    public function translate( $original, $domain, array $args )
83 83
     {
84
-        $domains = apply_filters('site-reviews/translator/domains', [Application::ID]);
85
-        if (!in_array($domain, $domains)) {
84
+        $domains = apply_filters( 'site-reviews/translator/domains', [Application::ID] );
85
+        if( !in_array( $domain, $domains ) ) {
86 86
             return $original;
87 87
         }
88
-        $args = $this->normalizeTranslationArgs($args);
89
-        $strings = $this->getTranslationStrings($args['single'], $args['plural']);
90
-        if (empty($strings)) {
88
+        $args = $this->normalizeTranslationArgs( $args );
89
+        $strings = $this->getTranslationStrings( $args['single'], $args['plural'] );
90
+        if( empty($strings) ) {
91 91
             return $original;
92 92
         }
93
-        $string = current($strings);
93
+        $string = current( $strings );
94 94
         return 'plural' == $string['type']
95
-            ? $this->translatePlural($domain, $string, $args)
96
-            : $this->translateSingle($domain, $string, $args);
95
+            ? $this->translatePlural( $domain, $string, $args )
96
+            : $this->translateSingle( $domain, $string, $args );
97 97
     }
98 98
 
99 99
     /**
@@ -101,18 +101,18 @@  discard block
 block discarded – undo
101 101
      * @param string $plural
102 102
      * @return array
103 103
      */
104
-    protected function getTranslationStrings($single, $plural)
104
+    protected function getTranslationStrings( $single, $plural )
105 105
     {
106
-        return array_filter(glsr(Translation::class)->translations(), function ($string) use ($single, $plural) {
107
-            return $string['s1'] == html_entity_decode($single, ENT_COMPAT, 'UTF-8')
108
-                && $string['p1'] == html_entity_decode($plural, ENT_COMPAT, 'UTF-8');
106
+        return array_filter( glsr( Translation::class )->translations(), function( $string ) use ($single, $plural) {
107
+            return $string['s1'] == html_entity_decode( $single, ENT_COMPAT, 'UTF-8' )
108
+                && $string['p1'] == html_entity_decode( $plural, ENT_COMPAT, 'UTF-8' );
109 109
         });
110 110
     }
111 111
 
112 112
     /**
113 113
      * @return array
114 114
      */
115
-    protected function normalizeTranslationArgs(array $args)
115
+    protected function normalizeTranslationArgs( array $args )
116 116
     {
117 117
         $defaults = [
118 118
             'context' => '',
@@ -120,22 +120,22 @@  discard block
 block discarded – undo
120 120
             'plural' => '',
121 121
             'single' => '',
122 122
         ];
123
-        return shortcode_atts($defaults, $args);
123
+        return shortcode_atts( $defaults, $args );
124 124
     }
125 125
 
126 126
     /**
127 127
      * @param string $domain
128 128
      * @return string
129 129
      */
130
-    protected function translatePlural($domain, array $string, array $args)
130
+    protected function translatePlural( $domain, array $string, array $args )
131 131
     {
132
-        if (!empty($string['s2'])) {
132
+        if( !empty($string['s2']) ) {
133 133
             $args['single'] = $string['s2'];
134 134
         }
135
-        if (!empty($string['p2'])) {
135
+        if( !empty($string['p2']) ) {
136 136
             $args['plural'] = $string['p2'];
137 137
         }
138
-        return get_translations_for_domain($domain)->translate_plural(
138
+        return get_translations_for_domain( $domain )->translate_plural(
139 139
             $args['single'],
140 140
             $args['plural'],
141 141
             $args['number'],
@@ -147,12 +147,12 @@  discard block
 block discarded – undo
147 147
      * @param string $domain
148 148
      * @return string
149 149
      */
150
-    protected function translateSingle($domain, array $string, array $args)
150
+    protected function translateSingle( $domain, array $string, array $args )
151 151
     {
152
-        if (!empty($string['s2'])) {
152
+        if( !empty($string['s2']) ) {
153 153
             $args['single'] = $string['s2'];
154 154
         }
155
-        return get_translations_for_domain($domain)->translate(
155
+        return get_translations_for_domain( $domain )->translate(
156 156
             $args['single'],
157 157
             $args['context']
158 158
         );
Please login to merge, or discard this patch.
plugin/Controllers/EditorController/Labels.php 2 patches
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -7,106 +7,106 @@
 block discarded – undo
7 7
 
8 8
 class Labels
9 9
 {
10
-    /**
11
-     * @return void
12
-     */
13
-    public function customizePostStatusLabels()
14
-    {
15
-        global $wp_scripts;
16
-        $strings = [
17
-            'savePending' => __('Save as Unapproved', 'site-reviews'),
18
-            'published' => __('Approved', 'site-reviews'),
19
-        ];
20
-        if (isset($wp_scripts->registered['post']->extra['data'])) {
21
-            $l10n = &$wp_scripts->registered['post']->extra['data'];
22
-            foreach ($strings as $search => $replace) {
23
-                $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n);
24
-            }
25
-        }
26
-    }
10
+	/**
11
+	 * @return void
12
+	 */
13
+	public function customizePostStatusLabels()
14
+	{
15
+		global $wp_scripts;
16
+		$strings = [
17
+			'savePending' => __('Save as Unapproved', 'site-reviews'),
18
+			'published' => __('Approved', 'site-reviews'),
19
+		];
20
+		if (isset($wp_scripts->registered['post']->extra['data'])) {
21
+			$l10n = &$wp_scripts->registered['post']->extra['data'];
22
+			foreach ($strings as $search => $replace) {
23
+				$l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n);
24
+			}
25
+		}
26
+	}
27 27
 
28
-    /**
29
-     * @param string $translation
30
-     * @param string $test
31
-     * @return string
32
-     */
33
-    public function filterPostStatusLabels($translation, $text)
34
-    {
35
-        $replacements = $this->getStatusLabels();
36
-        return array_key_exists($text, $replacements)
37
-            ? $replacements[$text]
38
-            : $translation;
39
-    }
28
+	/**
29
+	 * @param string $translation
30
+	 * @param string $test
31
+	 * @return string
32
+	 */
33
+	public function filterPostStatusLabels($translation, $text)
34
+	{
35
+		$replacements = $this->getStatusLabels();
36
+		return array_key_exists($text, $replacements)
37
+			? $replacements[$text]
38
+			: $translation;
39
+	}
40 40
 
41
-    /**
42
-     * @return array
43
-     */
44
-    public function filterUpdateMessages(array $messages)
45
-    {
46
-        $post = get_post();
47
-        if (!($post instanceof WP_Post)) {
48
-            return;
49
-        }
50
-        $strings = $this->getReviewLabels();
51
-        $restored = filter_input(INPUT_GET, 'revision');
52
-        if ($revisionTitle = wp_post_revision_title(intval($restored), false)) {
53
-            $restored = sprintf($strings['restored'], $revisionTitle);
54
-        }
55
-        $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date));
56
-        $messages[Application::POST_TYPE] = [
57
-             1 => $strings['updated'],
58
-             4 => $strings['updated'],
59
-             5 => $restored,
60
-             6 => $strings['published'],
61
-             7 => $strings['saved'],
62
-             8 => $strings['submitted'],
63
-             9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'),
64
-            10 => $strings['draft_updated'],
65
-            50 => $strings['approved'],
66
-            51 => $strings['unapproved'],
67
-            52 => $strings['reverted'],
68
-        ];
69
-        return $messages;
70
-    }
41
+	/**
42
+	 * @return array
43
+	 */
44
+	public function filterUpdateMessages(array $messages)
45
+	{
46
+		$post = get_post();
47
+		if (!($post instanceof WP_Post)) {
48
+			return;
49
+		}
50
+		$strings = $this->getReviewLabels();
51
+		$restored = filter_input(INPUT_GET, 'revision');
52
+		if ($revisionTitle = wp_post_revision_title(intval($restored), false)) {
53
+			$restored = sprintf($strings['restored'], $revisionTitle);
54
+		}
55
+		$scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date));
56
+		$messages[Application::POST_TYPE] = [
57
+			 1 => $strings['updated'],
58
+			 4 => $strings['updated'],
59
+			 5 => $restored,
60
+			 6 => $strings['published'],
61
+			 7 => $strings['saved'],
62
+			 8 => $strings['submitted'],
63
+			 9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'),
64
+			10 => $strings['draft_updated'],
65
+			50 => $strings['approved'],
66
+			51 => $strings['unapproved'],
67
+			52 => $strings['reverted'],
68
+		];
69
+		return $messages;
70
+	}
71 71
 
72
-    /**
73
-     * @return array
74
-     */
75
-    protected function getReviewLabels()
76
-    {
77
-        return [
78
-            'approved' => __('Review has been approved and published.', 'site-reviews'),
79
-            'draft_updated' => __('Review draft updated.', 'site-reviews'),
80
-            'preview' => __('Preview review', 'site-reviews'),
81
-            'published' => __('Review approved and published.', 'site-reviews'),
82
-            'restored' => __('Review restored to revision from %s.', 'site-reviews'),
83
-            'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'),
84
-            'saved' => __('Review saved.', 'site-reviews'),
85
-            'scheduled' => __('Review scheduled for: %s.', 'site-reviews'),
86
-            'submitted' => __('Review submitted.', 'site-reviews'),
87
-            'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'),
88
-            'updated' => __('Review updated.', 'site-reviews'),
89
-            'view' => __('View review', 'site-reviews'),
90
-        ];
91
-    }
72
+	/**
73
+	 * @return array
74
+	 */
75
+	protected function getReviewLabels()
76
+	{
77
+		return [
78
+			'approved' => __('Review has been approved and published.', 'site-reviews'),
79
+			'draft_updated' => __('Review draft updated.', 'site-reviews'),
80
+			'preview' => __('Preview review', 'site-reviews'),
81
+			'published' => __('Review approved and published.', 'site-reviews'),
82
+			'restored' => __('Review restored to revision from %s.', 'site-reviews'),
83
+			'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'),
84
+			'saved' => __('Review saved.', 'site-reviews'),
85
+			'scheduled' => __('Review scheduled for: %s.', 'site-reviews'),
86
+			'submitted' => __('Review submitted.', 'site-reviews'),
87
+			'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'),
88
+			'updated' => __('Review updated.', 'site-reviews'),
89
+			'view' => __('View review', 'site-reviews'),
90
+		];
91
+	}
92 92
 
93
-    /**
94
-     * Store the labels to avoid unnecessary loops.
95
-     * @return array
96
-     */
97
-    protected function getStatusLabels()
98
-    {
99
-        static $labels;
100
-        if (empty($labels)) {
101
-            $labels = [
102
-                'Pending' => __('Unapproved', 'site-reviews'),
103
-                'Pending Review' => __('Unapproved', 'site-reviews'),
104
-                'Privately Published' => __('Privately Approved', 'site-reviews'),
105
-                'Publish' => __('Approve', 'site-reviews'),
106
-                'Published' => __('Approved', 'site-reviews'),
107
-                'Save as Pending' => __('Save as Unapproved', 'site-reviews'),
108
-            ];
109
-        }
110
-        return $labels;
111
-    }
93
+	/**
94
+	 * Store the labels to avoid unnecessary loops.
95
+	 * @return array
96
+	 */
97
+	protected function getStatusLabels()
98
+	{
99
+		static $labels;
100
+		if (empty($labels)) {
101
+			$labels = [
102
+				'Pending' => __('Unapproved', 'site-reviews'),
103
+				'Pending Review' => __('Unapproved', 'site-reviews'),
104
+				'Privately Published' => __('Privately Approved', 'site-reviews'),
105
+				'Publish' => __('Approve', 'site-reviews'),
106
+				'Published' => __('Approved', 'site-reviews'),
107
+				'Save as Pending' => __('Save as Unapproved', 'site-reviews'),
108
+			];
109
+		}
110
+		return $labels;
111
+	}
112 112
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -14,13 +14,13 @@  discard block
 block discarded – undo
14 14
     {
15 15
         global $wp_scripts;
16 16
         $strings = [
17
-            'savePending' => __('Save as Unapproved', 'site-reviews'),
18
-            'published' => __('Approved', 'site-reviews'),
17
+            'savePending' => __( 'Save as Unapproved', 'site-reviews' ),
18
+            'published' => __( 'Approved', 'site-reviews' ),
19 19
         ];
20
-        if (isset($wp_scripts->registered['post']->extra['data'])) {
20
+        if( isset($wp_scripts->registered['post']->extra['data']) ) {
21 21
             $l10n = &$wp_scripts->registered['post']->extra['data'];
22
-            foreach ($strings as $search => $replace) {
23
-                $l10n = preg_replace('/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n);
22
+            foreach( $strings as $search => $replace ) {
23
+                $l10n = preg_replace( '/("'.$search.'":")([^"]+)/', '$1'.$replace, $l10n );
24 24
             }
25 25
         }
26 26
     }
@@ -30,10 +30,10 @@  discard block
 block discarded – undo
30 30
      * @param string $test
31 31
      * @return string
32 32
      */
33
-    public function filterPostStatusLabels($translation, $text)
33
+    public function filterPostStatusLabels( $translation, $text )
34 34
     {
35 35
         $replacements = $this->getStatusLabels();
36
-        return array_key_exists($text, $replacements)
36
+        return array_key_exists( $text, $replacements )
37 37
             ? $replacements[$text]
38 38
             : $translation;
39 39
     }
@@ -41,18 +41,18 @@  discard block
 block discarded – undo
41 41
     /**
42 42
      * @return array
43 43
      */
44
-    public function filterUpdateMessages(array $messages)
44
+    public function filterUpdateMessages( array $messages )
45 45
     {
46 46
         $post = get_post();
47
-        if (!($post instanceof WP_Post)) {
47
+        if( !($post instanceof WP_Post) ) {
48 48
             return;
49 49
         }
50 50
         $strings = $this->getReviewLabels();
51
-        $restored = filter_input(INPUT_GET, 'revision');
52
-        if ($revisionTitle = wp_post_revision_title(intval($restored), false)) {
53
-            $restored = sprintf($strings['restored'], $revisionTitle);
51
+        $restored = filter_input( INPUT_GET, 'revision' );
52
+        if( $revisionTitle = wp_post_revision_title( intval( $restored ), false ) ) {
53
+            $restored = sprintf( $strings['restored'], $revisionTitle );
54 54
         }
55
-        $scheduled_date = date_i18n('M j, Y @ H:i', strtotime($post->post_date));
55
+        $scheduled_date = date_i18n( 'M j, Y @ H:i', strtotime( $post->post_date ) );
56 56
         $messages[Application::POST_TYPE] = [
57 57
              1 => $strings['updated'],
58 58
              4 => $strings['updated'],
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
              6 => $strings['published'],
61 61
              7 => $strings['saved'],
62 62
              8 => $strings['submitted'],
63
-             9 => sprintf($strings['scheduled'], '<strong>'.$scheduled_date.'</strong>'),
63
+             9 => sprintf( $strings['scheduled'], '<strong>'.$scheduled_date.'</strong>' ),
64 64
             10 => $strings['draft_updated'],
65 65
             50 => $strings['approved'],
66 66
             51 => $strings['unapproved'],
@@ -75,18 +75,18 @@  discard block
 block discarded – undo
75 75
     protected function getReviewLabels()
76 76
     {
77 77
         return [
78
-            'approved' => __('Review has been approved and published.', 'site-reviews'),
79
-            'draft_updated' => __('Review draft updated.', 'site-reviews'),
80
-            'preview' => __('Preview review', 'site-reviews'),
81
-            'published' => __('Review approved and published.', 'site-reviews'),
82
-            'restored' => __('Review restored to revision from %s.', 'site-reviews'),
83
-            'reverted' => __('Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews'),
84
-            'saved' => __('Review saved.', 'site-reviews'),
85
-            'scheduled' => __('Review scheduled for: %s.', 'site-reviews'),
86
-            'submitted' => __('Review submitted.', 'site-reviews'),
87
-            'unapproved' => __('Review has been unapproved and is now pending.', 'site-reviews'),
88
-            'updated' => __('Review updated.', 'site-reviews'),
89
-            'view' => __('View review', 'site-reviews'),
78
+            'approved' => __( 'Review has been approved and published.', 'site-reviews' ),
79
+            'draft_updated' => __( 'Review draft updated.', 'site-reviews' ),
80
+            'preview' => __( 'Preview review', 'site-reviews' ),
81
+            'published' => __( 'Review approved and published.', 'site-reviews' ),
82
+            'restored' => __( 'Review restored to revision from %s.', 'site-reviews' ),
83
+            'reverted' => __( 'Review has been reverted to its original submission state (title, content, and submission date).', 'site-reviews' ),
84
+            'saved' => __( 'Review saved.', 'site-reviews' ),
85
+            'scheduled' => __( 'Review scheduled for: %s.', 'site-reviews' ),
86
+            'submitted' => __( 'Review submitted.', 'site-reviews' ),
87
+            'unapproved' => __( 'Review has been unapproved and is now pending.', 'site-reviews' ),
88
+            'updated' => __( 'Review updated.', 'site-reviews' ),
89
+            'view' => __( 'View review', 'site-reviews' ),
90 90
         ];
91 91
     }
92 92
 
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
     protected function getStatusLabels()
98 98
     {
99 99
         static $labels;
100
-        if (empty($labels)) {
100
+        if( empty($labels) ) {
101 101
             $labels = [
102
-                'Pending' => __('Unapproved', 'site-reviews'),
103
-                'Pending Review' => __('Unapproved', 'site-reviews'),
104
-                'Privately Published' => __('Privately Approved', 'site-reviews'),
105
-                'Publish' => __('Approve', 'site-reviews'),
106
-                'Published' => __('Approved', 'site-reviews'),
107
-                'Save as Pending' => __('Save as Unapproved', 'site-reviews'),
102
+                'Pending' => __( 'Unapproved', 'site-reviews' ),
103
+                'Pending Review' => __( 'Unapproved', 'site-reviews' ),
104
+                'Privately Published' => __( 'Privately Approved', 'site-reviews' ),
105
+                'Publish' => __( 'Approve', 'site-reviews' ),
106
+                'Published' => __( 'Approved', 'site-reviews' ),
107
+                'Save as Pending' => __( 'Save as Unapproved', 'site-reviews' ),
108 108
             ];
109 109
         }
110 110
         return $labels;
Please login to merge, or discard this patch.
plugin/Controllers/EditorController.php 2 patches
Indentation   +421 added lines, -421 removed lines patch added patch discarded remove patch
@@ -19,453 +19,453 @@
 block discarded – undo
19 19
 
20 20
 class EditorController extends Controller
21 21
 {
22
-    /**
23
-     * @return void
24
-     * @action admin_enqueue_scripts
25
-     */
26
-    public function customizePostStatusLabels()
27
-    {
28
-        if ($this->canModifyTranslation()) {
29
-            glsr(Labels::class)->customizePostStatusLabels();
30
-        }
31
-    }
22
+	/**
23
+	 * @return void
24
+	 * @action admin_enqueue_scripts
25
+	 */
26
+	public function customizePostStatusLabels()
27
+	{
28
+		if ($this->canModifyTranslation()) {
29
+			glsr(Labels::class)->customizePostStatusLabels();
30
+		}
31
+	}
32 32
 
33
-    /**
34
-     * @param array $settings
35
-     * @return array
36
-     * @filter wp_editor_settings
37
-     */
38
-    public function filterEditorSettings($settings)
39
-    {
40
-        return glsr(Customization::class)->filterEditorSettings(
41
-            Arr::consolidateArray($settings)
42
-        );
43
-    }
33
+	/**
34
+	 * @param array $settings
35
+	 * @return array
36
+	 * @filter wp_editor_settings
37
+	 */
38
+	public function filterEditorSettings($settings)
39
+	{
40
+		return glsr(Customization::class)->filterEditorSettings(
41
+			Arr::consolidateArray($settings)
42
+		);
43
+	}
44 44
 
45
-    /**
46
-     * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script.
47
-     * @param string $html
48
-     * @return string
49
-     * @filter the_editor
50
-     */
51
-    public function filterEditorTextarea($html)
52
-    {
53
-        return glsr(Customization::class)->filterEditorTextarea($html);
54
-    }
45
+	/**
46
+	 * Modify the WP_Editor html to allow autosizing without breaking the `editor-expand` script.
47
+	 * @param string $html
48
+	 * @return string
49
+	 * @filter the_editor
50
+	 */
51
+	public function filterEditorTextarea($html)
52
+	{
53
+		return glsr(Customization::class)->filterEditorTextarea($html);
54
+	}
55 55
 
56
-    /**
57
-     * @param bool $protected
58
-     * @param string $metaKey
59
-     * @param string $metaType
60
-     * @return bool
61
-     * @filter is_protected_meta
62
-     */
63
-    public function filterIsProtectedMeta($protected, $metaKey, $metaType)
64
-    {
65
-        if ('post' == $metaType && Application::POST_TYPE == get_post_type()) {
66
-            $values = glsr(CreateReviewDefaults::class)->unguarded();
67
-            $values = Arr::prefixArrayKeys($values);
68
-            if (array_key_exists($metaKey, $values)) {
69
-                $protected = false;
70
-            }
71
-        }
72
-        return $protected;
73
-    }
56
+	/**
57
+	 * @param bool $protected
58
+	 * @param string $metaKey
59
+	 * @param string $metaType
60
+	 * @return bool
61
+	 * @filter is_protected_meta
62
+	 */
63
+	public function filterIsProtectedMeta($protected, $metaKey, $metaType)
64
+	{
65
+		if ('post' == $metaType && Application::POST_TYPE == get_post_type()) {
66
+			$values = glsr(CreateReviewDefaults::class)->unguarded();
67
+			$values = Arr::prefixArrayKeys($values);
68
+			if (array_key_exists($metaKey, $values)) {
69
+				$protected = false;
70
+			}
71
+		}
72
+		return $protected;
73
+	}
74 74
 
75
-    /**
76
-     * @param string $translation
77
-     * @param string $test
78
-     * @param string $domain
79
-     * @return string
80
-     * @filter gettext
81
-     */
82
-    public function filterPostStatusLabels($translation, $text, $domain)
83
-    {
84
-        return $this->canModifyTranslation($domain)
85
-            ? glsr(Labels::class)->filterPostStatusLabels($translation, $text)
86
-            : $translation;
87
-    }
75
+	/**
76
+	 * @param string $translation
77
+	 * @param string $test
78
+	 * @param string $domain
79
+	 * @return string
80
+	 * @filter gettext
81
+	 */
82
+	public function filterPostStatusLabels($translation, $text, $domain)
83
+	{
84
+		return $this->canModifyTranslation($domain)
85
+			? glsr(Labels::class)->filterPostStatusLabels($translation, $text)
86
+			: $translation;
87
+	}
88 88
 
89
-    /**
90
-     * @param string $translation
91
-     * @param string $test
92
-     * @param string $domain
93
-     * @return string
94
-     * @filter gettext_with_context
95
-     */
96
-    public function filterPostStatusLabelsWithContext($translation, $text, $context, $domain)
97
-    {
98
-        return $this->canModifyTranslation($domain)
99
-            ? glsr(Labels::class)->filterPostStatusLabels($translation, $text)
100
-            : $translation;
101
-    }
89
+	/**
90
+	 * @param string $translation
91
+	 * @param string $test
92
+	 * @param string $domain
93
+	 * @return string
94
+	 * @filter gettext_with_context
95
+	 */
96
+	public function filterPostStatusLabelsWithContext($translation, $text, $context, $domain)
97
+	{
98
+		return $this->canModifyTranslation($domain)
99
+			? glsr(Labels::class)->filterPostStatusLabels($translation, $text)
100
+			: $translation;
101
+	}
102 102
 
103
-    /**
104
-     * @param array $messages
105
-     * @return array
106
-     * @filter post_updated_messages
107
-     */
108
-    public function filterUpdateMessages($messages)
109
-    {
110
-        return glsr(Labels::class)->filterUpdateMessages(
111
-            Arr::consolidateArray($messages)
112
-        );
113
-    }
103
+	/**
104
+	 * @param array $messages
105
+	 * @return array
106
+	 * @filter post_updated_messages
107
+	 */
108
+	public function filterUpdateMessages($messages)
109
+	{
110
+		return glsr(Labels::class)->filterUpdateMessages(
111
+			Arr::consolidateArray($messages)
112
+		);
113
+	}
114 114
 
115
-    /**
116
-     * @return void
117
-     * @action add_meta_boxes_{Application::POST_TYPE}
118
-     */
119
-    public function registerMetaBoxes($post)
120
-    {
121
-        add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side');
122
-        add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side');
123
-        if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) {
124
-            return;
125
-        }
126
-        add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal');
127
-    }
115
+	/**
116
+	 * @return void
117
+	 * @action add_meta_boxes_{Application::POST_TYPE}
118
+	 */
119
+	public function registerMetaBoxes($post)
120
+	{
121
+		add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side');
122
+		add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side');
123
+		if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) {
124
+			return;
125
+		}
126
+		add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal');
127
+	}
128 128
 
129
-    /**
130
-     * @return void
131
-     * @action admin_print_scripts
132
-     */
133
-    public function removeAutosave()
134
-    {
135
-        glsr(Customization::class)->removeAutosave();
136
-    }
129
+	/**
130
+	 * @return void
131
+	 * @action admin_print_scripts
132
+	 */
133
+	public function removeAutosave()
134
+	{
135
+		glsr(Customization::class)->removeAutosave();
136
+	}
137 137
 
138
-    /**
139
-     * @return void
140
-     * @action admin_menu
141
-     */
142
-    public function removeMetaBoxes()
143
-    {
144
-        glsr(Customization::class)->removeMetaBoxes();
145
-    }
138
+	/**
139
+	 * @return void
140
+	 * @action admin_menu
141
+	 */
142
+	public function removeMetaBoxes()
143
+	{
144
+		glsr(Customization::class)->removeMetaBoxes();
145
+	}
146 146
 
147
-    /**
148
-     * @return void
149
-     */
150
-    public function removePostTypeSupport()
151
-    {
152
-        glsr(Customization::class)->removePostTypeSupport();
153
-    }
147
+	/**
148
+	 * @return void
149
+	 */
150
+	public function removePostTypeSupport()
151
+	{
152
+		glsr(Customization::class)->removePostTypeSupport();
153
+	}
154 154
 
155
-    /**
156
-     * @param WP_Post $post
157
-     * @return void
158
-     * @callback add_meta_box
159
-     */
160
-    public function renderAssignedToMetabox($post)
161
-    {
162
-        if (!$this->isReviewPostType($post)) {
163
-            return;
164
-        }
165
-        $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to');
166
-        wp_nonce_field('assigned_to', '_nonce-assigned-to', false);
167
-        glsr()->render('partials/editor/metabox-assigned-to', [
168
-            'id' => $assignedTo,
169
-            'template' => $this->buildAssignedToTemplate($assignedTo, $post),
170
-        ]);
171
-    }
155
+	/**
156
+	 * @param WP_Post $post
157
+	 * @return void
158
+	 * @callback add_meta_box
159
+	 */
160
+	public function renderAssignedToMetabox($post)
161
+	{
162
+		if (!$this->isReviewPostType($post)) {
163
+			return;
164
+		}
165
+		$assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to');
166
+		wp_nonce_field('assigned_to', '_nonce-assigned-to', false);
167
+		glsr()->render('partials/editor/metabox-assigned-to', [
168
+			'id' => $assignedTo,
169
+			'template' => $this->buildAssignedToTemplate($assignedTo, $post),
170
+		]);
171
+	}
172 172
 
173
-    /**
174
-     * @param WP_Post $post
175
-     * @return void
176
-     * @callback add_meta_box
177
-     */
178
-    public function renderDetailsMetaBox($post)
179
-    {
180
-        if (!$this->isReviewPostType($post)) {
181
-            return;
182
-        }
183
-        $review = glsr_get_review($post);
184
-        glsr()->render('partials/editor/metabox-details', [
185
-            'button' => $this->buildDetailsMetaBoxRevertButton($review, $post),
186
-            'metabox' => $this->normalizeDetailsMetaBox($review),
187
-        ]);
188
-    }
173
+	/**
174
+	 * @param WP_Post $post
175
+	 * @return void
176
+	 * @callback add_meta_box
177
+	 */
178
+	public function renderDetailsMetaBox($post)
179
+	{
180
+		if (!$this->isReviewPostType($post)) {
181
+			return;
182
+		}
183
+		$review = glsr_get_review($post);
184
+		glsr()->render('partials/editor/metabox-details', [
185
+			'button' => $this->buildDetailsMetaBoxRevertButton($review, $post),
186
+			'metabox' => $this->normalizeDetailsMetaBox($review),
187
+		]);
188
+	}
189 189
 
190
-    /**
191
-     * @return void
192
-     * @action post_submitbox_misc_actions
193
-     */
194
-    public function renderPinnedInPublishMetaBox()
195
-    {
196
-        if (!$this->isReviewPostType(get_post())) {
197
-            return;
198
-        }
199
-        glsr(Template::class)->render('partials/editor/pinned', [
200
-            'context' => [
201
-                'no' => __('No', 'site-reviews'),
202
-                'yes' => __('Yes', 'site-reviews'),
203
-            ],
204
-            'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')),
205
-        ]);
206
-    }
190
+	/**
191
+	 * @return void
192
+	 * @action post_submitbox_misc_actions
193
+	 */
194
+	public function renderPinnedInPublishMetaBox()
195
+	{
196
+		if (!$this->isReviewPostType(get_post())) {
197
+			return;
198
+		}
199
+		glsr(Template::class)->render('partials/editor/pinned', [
200
+			'context' => [
201
+				'no' => __('No', 'site-reviews'),
202
+				'yes' => __('Yes', 'site-reviews'),
203
+			],
204
+			'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')),
205
+		]);
206
+	}
207 207
 
208
-    /**
209
-     * @param WP_Post $post
210
-     * @return void
211
-     * @callback add_meta_box
212
-     */
213
-    public function renderResponseMetaBox($post)
214
-    {
215
-        if (!$this->isReviewPostType($post)) {
216
-            return;
217
-        }
218
-        wp_nonce_field('response', '_nonce-response', false);
219
-        glsr()->render('partials/editor/metabox-response', [
220
-            'response' => glsr(Database::class)->get($post->ID, 'response'),
221
-        ]);
222
-    }
208
+	/**
209
+	 * @param WP_Post $post
210
+	 * @return void
211
+	 * @callback add_meta_box
212
+	 */
213
+	public function renderResponseMetaBox($post)
214
+	{
215
+		if (!$this->isReviewPostType($post)) {
216
+			return;
217
+		}
218
+		wp_nonce_field('response', '_nonce-response', false);
219
+		glsr()->render('partials/editor/metabox-response', [
220
+			'response' => glsr(Database::class)->get($post->ID, 'response'),
221
+		]);
222
+	}
223 223
 
224
-    /**
225
-     * @param WP_Post $post
226
-     * @return void
227
-     * @action edit_form_after_title
228
-     */
229
-    public function renderReviewEditor($post)
230
-    {
231
-        if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
232
-            return;
233
-        }
234
-        glsr()->render('partials/editor/review', [
235
-            'post' => $post,
236
-            'response' => glsr(Database::class)->get($post->ID, 'response'),
237
-        ]);
238
-    }
224
+	/**
225
+	 * @param WP_Post $post
226
+	 * @return void
227
+	 * @action edit_form_after_title
228
+	 */
229
+	public function renderReviewEditor($post)
230
+	{
231
+		if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
232
+			return;
233
+		}
234
+		glsr()->render('partials/editor/review', [
235
+			'post' => $post,
236
+			'response' => glsr(Database::class)->get($post->ID, 'response'),
237
+		]);
238
+	}
239 239
 
240
-    /**
241
-     * @return void
242
-     * @action admin_head
243
-     */
244
-    public function renderReviewFields()
245
-    {
246
-        $screen = glsr_current_screen();
247
-        if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) {
248
-            return;
249
-        }
250
-        add_action('edit_form_after_title', [$this, 'renderReviewEditor']);
251
-        add_action('edit_form_top', [$this, 'renderReviewNotice']);
252
-    }
240
+	/**
241
+	 * @return void
242
+	 * @action admin_head
243
+	 */
244
+	public function renderReviewFields()
245
+	{
246
+		$screen = glsr_current_screen();
247
+		if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) {
248
+			return;
249
+		}
250
+		add_action('edit_form_after_title', [$this, 'renderReviewEditor']);
251
+		add_action('edit_form_top', [$this, 'renderReviewNotice']);
252
+	}
253 253
 
254
-    /**
255
-     * @param WP_Post $post
256
-     * @return void
257
-     * @action edit_form_top
258
-     */
259
-    public function renderReviewNotice($post)
260
-    {
261
-        if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
262
-            return;
263
-        }
264
-        glsr(Notice::class)->addWarning(sprintf(
265
-            __('%s reviews are read-only.', 'site-reviews'),
266
-            glsr(Columns::class)->buildColumnReviewType($post->ID)
267
-        ));
268
-        glsr(Template::class)->render('partials/editor/notice', [
269
-            'context' => [
270
-                'notices' => glsr(Notice::class)->get(),
271
-            ],
272
-        ]);
273
-    }
254
+	/**
255
+	 * @param WP_Post $post
256
+	 * @return void
257
+	 * @action edit_form_top
258
+	 */
259
+	public function renderReviewNotice($post)
260
+	{
261
+		if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
262
+			return;
263
+		}
264
+		glsr(Notice::class)->addWarning(sprintf(
265
+			__('%s reviews are read-only.', 'site-reviews'),
266
+			glsr(Columns::class)->buildColumnReviewType($post->ID)
267
+		));
268
+		glsr(Template::class)->render('partials/editor/notice', [
269
+			'context' => [
270
+				'notices' => glsr(Notice::class)->get(),
271
+			],
272
+		]);
273
+	}
274 274
 
275
-    /**
276
-     * @param WP_Post $post
277
-     * @return void
278
-     * @see glsr_categories_meta_box()
279
-     * @callback register_taxonomy
280
-     */
281
-    public function renderTaxonomyMetabox($post)
282
-    {
283
-        if (!$this->isReviewPostType($post)) {
284
-            return;
285
-        }
286
-        glsr()->render('partials/editor/metabox-categories', [
287
-            'post' => $post,
288
-            'tax_name' => Application::TAXONOMY,
289
-            'taxonomy' => get_taxonomy(Application::TAXONOMY),
290
-        ]);
291
-    }
275
+	/**
276
+	 * @param WP_Post $post
277
+	 * @return void
278
+	 * @see glsr_categories_meta_box()
279
+	 * @callback register_taxonomy
280
+	 */
281
+	public function renderTaxonomyMetabox($post)
282
+	{
283
+		if (!$this->isReviewPostType($post)) {
284
+			return;
285
+		}
286
+		glsr()->render('partials/editor/metabox-categories', [
287
+			'post' => $post,
288
+			'tax_name' => Application::TAXONOMY,
289
+			'taxonomy' => get_taxonomy(Application::TAXONOMY),
290
+		]);
291
+	}
292 292
 
293
-    /**
294
-     * @return void
295
-     * @see $this->filterUpdateMessages()
296
-     * @action admin_action_revert
297
-     */
298
-    public function revertReview()
299
-    {
300
-        if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
301
-            return;
302
-        }
303
-        check_admin_referer('revert-review_'.($postId = $this->getPostId()));
304
-        glsr(ReviewManager::class)->revert($postId);
305
-        $this->redirect($postId, 52);
306
-    }
293
+	/**
294
+	 * @return void
295
+	 * @see $this->filterUpdateMessages()
296
+	 * @action admin_action_revert
297
+	 */
298
+	public function revertReview()
299
+	{
300
+		if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
301
+			return;
302
+		}
303
+		check_admin_referer('revert-review_'.($postId = $this->getPostId()));
304
+		glsr(ReviewManager::class)->revert($postId);
305
+		$this->redirect($postId, 52);
306
+	}
307 307
 
308
-    /**
309
-     * @param int $postId
310
-     * @param \WP_Post $post
311
-     * @param bool $isUpdate
312
-     * @return void
313
-     * @action save_post_.Application::POST_TYPE
314
-     */
315
-    public function saveMetaboxes($postId, $post, $isUpdating)
316
-    {
317
-        glsr(Metaboxes::class)->saveAssignedToMetabox($postId);
318
-        glsr(Metaboxes::class)->saveResponseMetabox($postId);
319
-        if ($isUpdating) {
320
-            do_action('site-reviews/review/saved', glsr_get_review($postId));
321
-        }
322
-    }
308
+	/**
309
+	 * @param int $postId
310
+	 * @param \WP_Post $post
311
+	 * @param bool $isUpdate
312
+	 * @return void
313
+	 * @action save_post_.Application::POST_TYPE
314
+	 */
315
+	public function saveMetaboxes($postId, $post, $isUpdating)
316
+	{
317
+		glsr(Metaboxes::class)->saveAssignedToMetabox($postId);
318
+		glsr(Metaboxes::class)->saveResponseMetabox($postId);
319
+		if ($isUpdating) {
320
+			do_action('site-reviews/review/saved', glsr_get_review($postId));
321
+		}
322
+	}
323 323
 
324
-    /**
325
-     * @param string $assignedTo
326
-     * @return string
327
-     */
328
-    protected function buildAssignedToTemplate($assignedTo, WP_Post $post)
329
-    {
330
-        $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo);
331
-        if (!($assignedPost instanceof WP_Post)) {
332
-            return;
333
-        }
334
-        return glsr(Template::class)->build('partials/editor/assigned-post', [
335
-            'context' => [
336
-                'data.url' => (string) get_permalink($assignedPost),
337
-                'data.title' => get_the_title($assignedPost),
338
-            ],
339
-        ]);
340
-    }
324
+	/**
325
+	 * @param string $assignedTo
326
+	 * @return string
327
+	 */
328
+	protected function buildAssignedToTemplate($assignedTo, WP_Post $post)
329
+	{
330
+		$assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo);
331
+		if (!($assignedPost instanceof WP_Post)) {
332
+			return;
333
+		}
334
+		return glsr(Template::class)->build('partials/editor/assigned-post', [
335
+			'context' => [
336
+				'data.url' => (string) get_permalink($assignedPost),
337
+				'data.title' => get_the_title($assignedPost),
338
+			],
339
+		]);
340
+	}
341 341
 
342
-    /**
343
-     * @return string
344
-     */
345
-    protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post)
346
-    {
347
-        $isModified = !Arr::compareArrays(
348
-            [$review->title, $review->content, $review->date],
349
-            [
350
-                glsr(Database::class)->get($post->ID, 'title'),
351
-                glsr(Database::class)->get($post->ID, 'content'),
352
-                glsr(Database::class)->get($post->ID, 'date'),
353
-            ]
354
-        );
355
-        if ($isModified) {
356
-            $revertUrl = wp_nonce_url(
357
-                admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID),
358
-                'revert-review_'.$post->ID
359
-            );
360
-            return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [
361
-                'class' => 'button button-large',
362
-                'href' => $revertUrl,
363
-                'id' => 'revert',
364
-            ]);
365
-        }
366
-        return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [
367
-            'class' => 'button-large',
368
-            'disabled' => true,
369
-            'id' => 'revert',
370
-        ]);
371
-    }
342
+	/**
343
+	 * @return string
344
+	 */
345
+	protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post)
346
+	{
347
+		$isModified = !Arr::compareArrays(
348
+			[$review->title, $review->content, $review->date],
349
+			[
350
+				glsr(Database::class)->get($post->ID, 'title'),
351
+				glsr(Database::class)->get($post->ID, 'content'),
352
+				glsr(Database::class)->get($post->ID, 'date'),
353
+			]
354
+		);
355
+		if ($isModified) {
356
+			$revertUrl = wp_nonce_url(
357
+				admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID),
358
+				'revert-review_'.$post->ID
359
+			);
360
+			return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [
361
+				'class' => 'button button-large',
362
+				'href' => $revertUrl,
363
+				'id' => 'revert',
364
+			]);
365
+		}
366
+		return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [
367
+			'class' => 'button-large',
368
+			'disabled' => true,
369
+			'id' => 'revert',
370
+		]);
371
+	}
372 372
 
373
-    /**
374
-     * @param string $domain
375
-     * @return bool
376
-     */
377
-    protected function canModifyTranslation($domain = 'default')
378
-    {
379
-        if ('default' != $domain || empty(glsr_current_screen()->base)) {
380
-            return false;
381
-        }
382
-        return Application::POST_TYPE == glsr_current_screen()->post_type
383
-            && in_array(glsr_current_screen()->base, ['edit', 'post']);
384
-    }
373
+	/**
374
+	 * @param string $domain
375
+	 * @return bool
376
+	 */
377
+	protected function canModifyTranslation($domain = 'default')
378
+	{
379
+		if ('default' != $domain || empty(glsr_current_screen()->base)) {
380
+			return false;
381
+		}
382
+		return Application::POST_TYPE == glsr_current_screen()->post_type
383
+			&& in_array(glsr_current_screen()->base, ['edit', 'post']);
384
+	}
385 385
 
386
-    /**
387
-     * @param object $review
388
-     * @return string|void
389
-     */
390
-    protected function getReviewType($review)
391
-    {
392
-        if (count(glsr()->reviewTypes) < 2) {
393
-            return;
394
-        }
395
-        $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes)
396
-            ? glsr()->reviewTypes[$review->review_type]
397
-            : __('Unknown', 'site-reviews');
398
-        if (!empty($review->url)) {
399
-            $reviewType = glsr(Builder::class)->a($reviewType, [
400
-                'href' => $review->url,
401
-                'target' => '_blank',
402
-            ]);
403
-        }
404
-        return $reviewType;
405
-    }
386
+	/**
387
+	 * @param object $review
388
+	 * @return string|void
389
+	 */
390
+	protected function getReviewType($review)
391
+	{
392
+		if (count(glsr()->reviewTypes) < 2) {
393
+			return;
394
+		}
395
+		$reviewType = array_key_exists($review->review_type, glsr()->reviewTypes)
396
+			? glsr()->reviewTypes[$review->review_type]
397
+			: __('Unknown', 'site-reviews');
398
+		if (!empty($review->url)) {
399
+			$reviewType = glsr(Builder::class)->a($reviewType, [
400
+				'href' => $review->url,
401
+				'target' => '_blank',
402
+			]);
403
+		}
404
+		return $reviewType;
405
+	}
406 406
 
407
-    /**
408
-     * @return bool
409
-     */
410
-    protected function isReviewEditable($post)
411
-    {
412
-        return $this->isReviewPostType($post)
413
-            && post_type_supports(Application::POST_TYPE, 'title')
414
-            && 'local' == glsr(Database::class)->get($post->ID, 'review_type');
415
-    }
407
+	/**
408
+	 * @return bool
409
+	 */
410
+	protected function isReviewEditable($post)
411
+	{
412
+		return $this->isReviewPostType($post)
413
+			&& post_type_supports(Application::POST_TYPE, 'title')
414
+			&& 'local' == glsr(Database::class)->get($post->ID, 'review_type');
415
+	}
416 416
 
417
-    /**
418
-     * @param mixed $post
419
-     * @return bool
420
-     */
421
-    protected function isReviewPostType($post)
422
-    {
423
-        return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type;
424
-    }
417
+	/**
418
+	 * @param mixed $post
419
+	 * @return bool
420
+	 */
421
+	protected function isReviewPostType($post)
422
+	{
423
+		return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type;
424
+	}
425 425
 
426
-    /**
427
-     * @return array
428
-     */
429
-    protected function normalizeDetailsMetaBox(Review $review)
430
-    {
431
-        $user = empty($review->user_id)
432
-            ? __('Unregistered user', 'site-reviews')
433
-            : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [
434
-                'href' => get_author_posts_url($review->user_id),
435
-            ]);
436
-        $email = empty($review->email)
437
-            ? '&mdash;'
438
-            : glsr(Builder::class)->a($review->email, [
439
-                'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title),
440
-            ]);
441
-        $metabox = [
442
-            __('Rating', 'site-reviews') => glsr_star_rating($review->rating),
443
-            __('Type', 'site-reviews') => $this->getReviewType($review),
444
-            __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'),
445
-            __('Name', 'site-reviews') => $review->author,
446
-            __('Email', 'site-reviews') => $email,
447
-            __('User', 'site-reviews') => $user,
448
-            __('IP Address', 'site-reviews') => $review->ip_address,
449
-            __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar),
450
-        ];
451
-        return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review));
452
-    }
426
+	/**
427
+	 * @return array
428
+	 */
429
+	protected function normalizeDetailsMetaBox(Review $review)
430
+	{
431
+		$user = empty($review->user_id)
432
+			? __('Unregistered user', 'site-reviews')
433
+			: glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [
434
+				'href' => get_author_posts_url($review->user_id),
435
+			]);
436
+		$email = empty($review->email)
437
+			? '&mdash;'
438
+			: glsr(Builder::class)->a($review->email, [
439
+				'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title),
440
+			]);
441
+		$metabox = [
442
+			__('Rating', 'site-reviews') => glsr_star_rating($review->rating),
443
+			__('Type', 'site-reviews') => $this->getReviewType($review),
444
+			__('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'),
445
+			__('Name', 'site-reviews') => $review->author,
446
+			__('Email', 'site-reviews') => $email,
447
+			__('User', 'site-reviews') => $user,
448
+			__('IP Address', 'site-reviews') => $review->ip_address,
449
+			__('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar),
450
+		];
451
+		return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review));
452
+	}
453 453
 
454
-    /**
455
-     * @param int $postId
456
-     * @param int $messageIndex
457
-     * @return void
458
-     */
459
-    protected function redirect($postId, $messageIndex)
460
-    {
461
-        $referer = wp_get_referer();
462
-        $hasReferer = !$referer
463
-            || false !== strpos($referer, 'post.php')
464
-            || false !== strpos($referer, 'post-new.php');
465
-        $redirectUri = $hasReferer
466
-            ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer)
467
-            : get_edit_post_link($postId);
468
-        wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri));
469
-        exit;
470
-    }
454
+	/**
455
+	 * @param int $postId
456
+	 * @param int $messageIndex
457
+	 * @return void
458
+	 */
459
+	protected function redirect($postId, $messageIndex)
460
+	{
461
+		$referer = wp_get_referer();
462
+		$hasReferer = !$referer
463
+			|| false !== strpos($referer, 'post.php')
464
+			|| false !== strpos($referer, 'post-new.php');
465
+		$redirectUri = $hasReferer
466
+			? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer)
467
+			: get_edit_post_link($postId);
468
+		wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri));
469
+		exit;
470
+	}
471 471
 }
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -25,8 +25,8 @@  discard block
 block discarded – undo
25 25
      */
26 26
     public function customizePostStatusLabels()
27 27
     {
28
-        if ($this->canModifyTranslation()) {
29
-            glsr(Labels::class)->customizePostStatusLabels();
28
+        if( $this->canModifyTranslation() ) {
29
+            glsr( Labels::class )->customizePostStatusLabels();
30 30
         }
31 31
     }
32 32
 
@@ -35,10 +35,10 @@  discard block
 block discarded – undo
35 35
      * @return array
36 36
      * @filter wp_editor_settings
37 37
      */
38
-    public function filterEditorSettings($settings)
38
+    public function filterEditorSettings( $settings )
39 39
     {
40
-        return glsr(Customization::class)->filterEditorSettings(
41
-            Arr::consolidateArray($settings)
40
+        return glsr( Customization::class )->filterEditorSettings(
41
+            Arr::consolidateArray( $settings )
42 42
         );
43 43
     }
44 44
 
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
      * @return string
49 49
      * @filter the_editor
50 50
      */
51
-    public function filterEditorTextarea($html)
51
+    public function filterEditorTextarea( $html )
52 52
     {
53
-        return glsr(Customization::class)->filterEditorTextarea($html);
53
+        return glsr( Customization::class )->filterEditorTextarea( $html );
54 54
     }
55 55
 
56 56
     /**
@@ -60,12 +60,12 @@  discard block
 block discarded – undo
60 60
      * @return bool
61 61
      * @filter is_protected_meta
62 62
      */
63
-    public function filterIsProtectedMeta($protected, $metaKey, $metaType)
63
+    public function filterIsProtectedMeta( $protected, $metaKey, $metaType )
64 64
     {
65
-        if ('post' == $metaType && Application::POST_TYPE == get_post_type()) {
66
-            $values = glsr(CreateReviewDefaults::class)->unguarded();
67
-            $values = Arr::prefixArrayKeys($values);
68
-            if (array_key_exists($metaKey, $values)) {
65
+        if( 'post' == $metaType && Application::POST_TYPE == get_post_type() ) {
66
+            $values = glsr( CreateReviewDefaults::class )->unguarded();
67
+            $values = Arr::prefixArrayKeys( $values );
68
+            if( array_key_exists( $metaKey, $values ) ) {
69 69
                 $protected = false;
70 70
             }
71 71
         }
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
      * @return string
80 80
      * @filter gettext
81 81
      */
82
-    public function filterPostStatusLabels($translation, $text, $domain)
82
+    public function filterPostStatusLabels( $translation, $text, $domain )
83 83
     {
84
-        return $this->canModifyTranslation($domain)
85
-            ? glsr(Labels::class)->filterPostStatusLabels($translation, $text)
84
+        return $this->canModifyTranslation( $domain )
85
+            ? glsr( Labels::class )->filterPostStatusLabels( $translation, $text )
86 86
             : $translation;
87 87
     }
88 88
 
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
      * @return string
94 94
      * @filter gettext_with_context
95 95
      */
96
-    public function filterPostStatusLabelsWithContext($translation, $text, $context, $domain)
96
+    public function filterPostStatusLabelsWithContext( $translation, $text, $context, $domain )
97 97
     {
98
-        return $this->canModifyTranslation($domain)
99
-            ? glsr(Labels::class)->filterPostStatusLabels($translation, $text)
98
+        return $this->canModifyTranslation( $domain )
99
+            ? glsr( Labels::class )->filterPostStatusLabels( $translation, $text )
100 100
             : $translation;
101 101
     }
102 102
 
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
      * @return array
106 106
      * @filter post_updated_messages
107 107
      */
108
-    public function filterUpdateMessages($messages)
108
+    public function filterUpdateMessages( $messages )
109 109
     {
110
-        return glsr(Labels::class)->filterUpdateMessages(
111
-            Arr::consolidateArray($messages)
110
+        return glsr( Labels::class )->filterUpdateMessages(
111
+            Arr::consolidateArray( $messages )
112 112
         );
113 113
     }
114 114
 
@@ -116,14 +116,14 @@  discard block
 block discarded – undo
116 116
      * @return void
117 117
      * @action add_meta_boxes_{Application::POST_TYPE}
118 118
      */
119
-    public function registerMetaBoxes($post)
119
+    public function registerMetaBoxes( $post )
120 120
     {
121
-        add_meta_box(Application::ID.'_assigned_to', __('Assigned To', 'site-reviews'), [$this, 'renderAssignedToMetabox'], null, 'side');
122
-        add_meta_box(Application::ID.'_review', __('Details', 'site-reviews'), [$this, 'renderDetailsMetaBox'], null, 'side');
123
-        if ('local' != glsr(Database::class)->get($post->ID, 'review_type')) {
121
+        add_meta_box( Application::ID.'_assigned_to', __( 'Assigned To', 'site-reviews' ), [$this, 'renderAssignedToMetabox'], null, 'side' );
122
+        add_meta_box( Application::ID.'_review', __( 'Details', 'site-reviews' ), [$this, 'renderDetailsMetaBox'], null, 'side' );
123
+        if( 'local' != glsr( Database::class )->get( $post->ID, 'review_type' ) ) {
124 124
             return;
125 125
         }
126
-        add_meta_box(Application::ID.'_response', __('Respond Publicly', 'site-reviews'), [$this, 'renderResponseMetaBox'], null, 'normal');
126
+        add_meta_box( Application::ID.'_response', __( 'Respond Publicly', 'site-reviews' ), [$this, 'renderResponseMetaBox'], null, 'normal' );
127 127
     }
128 128
 
129 129
     /**
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      */
133 133
     public function removeAutosave()
134 134
     {
135
-        glsr(Customization::class)->removeAutosave();
135
+        glsr( Customization::class )->removeAutosave();
136 136
     }
137 137
 
138 138
     /**
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function removeMetaBoxes()
143 143
     {
144
-        glsr(Customization::class)->removeMetaBoxes();
144
+        glsr( Customization::class )->removeMetaBoxes();
145 145
     }
146 146
 
147 147
     /**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      */
150 150
     public function removePostTypeSupport()
151 151
     {
152
-        glsr(Customization::class)->removePostTypeSupport();
152
+        glsr( Customization::class )->removePostTypeSupport();
153 153
     }
154 154
 
155 155
     /**
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
      * @return void
158 158
      * @callback add_meta_box
159 159
      */
160
-    public function renderAssignedToMetabox($post)
160
+    public function renderAssignedToMetabox( $post )
161 161
     {
162
-        if (!$this->isReviewPostType($post)) {
162
+        if( !$this->isReviewPostType( $post ) ) {
163 163
             return;
164 164
         }
165
-        $assignedTo = (string) glsr(Database::class)->get($post->ID, 'assigned_to');
166
-        wp_nonce_field('assigned_to', '_nonce-assigned-to', false);
167
-        glsr()->render('partials/editor/metabox-assigned-to', [
165
+        $assignedTo = (string)glsr( Database::class )->get( $post->ID, 'assigned_to' );
166
+        wp_nonce_field( 'assigned_to', '_nonce-assigned-to', false );
167
+        glsr()->render( 'partials/editor/metabox-assigned-to', [
168 168
             'id' => $assignedTo,
169
-            'template' => $this->buildAssignedToTemplate($assignedTo, $post),
170
-        ]);
169
+            'template' => $this->buildAssignedToTemplate( $assignedTo, $post ),
170
+        ] );
171 171
     }
172 172
 
173 173
     /**
@@ -175,16 +175,16 @@  discard block
 block discarded – undo
175 175
      * @return void
176 176
      * @callback add_meta_box
177 177
      */
178
-    public function renderDetailsMetaBox($post)
178
+    public function renderDetailsMetaBox( $post )
179 179
     {
180
-        if (!$this->isReviewPostType($post)) {
180
+        if( !$this->isReviewPostType( $post ) ) {
181 181
             return;
182 182
         }
183
-        $review = glsr_get_review($post);
184
-        glsr()->render('partials/editor/metabox-details', [
185
-            'button' => $this->buildDetailsMetaBoxRevertButton($review, $post),
186
-            'metabox' => $this->normalizeDetailsMetaBox($review),
187
-        ]);
183
+        $review = glsr_get_review( $post );
184
+        glsr()->render( 'partials/editor/metabox-details', [
185
+            'button' => $this->buildDetailsMetaBoxRevertButton( $review, $post ),
186
+            'metabox' => $this->normalizeDetailsMetaBox( $review ),
187
+        ] );
188 188
     }
189 189
 
190 190
     /**
@@ -193,16 +193,16 @@  discard block
 block discarded – undo
193 193
      */
194 194
     public function renderPinnedInPublishMetaBox()
195 195
     {
196
-        if (!$this->isReviewPostType(get_post())) {
196
+        if( !$this->isReviewPostType( get_post() ) ) {
197 197
             return;
198 198
         }
199
-        glsr(Template::class)->render('partials/editor/pinned', [
199
+        glsr( Template::class )->render( 'partials/editor/pinned', [
200 200
             'context' => [
201
-                'no' => __('No', 'site-reviews'),
202
-                'yes' => __('Yes', 'site-reviews'),
201
+                'no' => __( 'No', 'site-reviews' ),
202
+                'yes' => __( 'Yes', 'site-reviews' ),
203 203
             ],
204
-            'pinned' => wp_validate_boolean(glsr(Database::class)->get(get_the_ID(), 'pinned')),
205
-        ]);
204
+            'pinned' => wp_validate_boolean( glsr( Database::class )->get( get_the_ID(), 'pinned' ) ),
205
+        ] );
206 206
     }
207 207
 
208 208
     /**
@@ -210,15 +210,15 @@  discard block
 block discarded – undo
210 210
      * @return void
211 211
      * @callback add_meta_box
212 212
      */
213
-    public function renderResponseMetaBox($post)
213
+    public function renderResponseMetaBox( $post )
214 214
     {
215
-        if (!$this->isReviewPostType($post)) {
215
+        if( !$this->isReviewPostType( $post ) ) {
216 216
             return;
217 217
         }
218
-        wp_nonce_field('response', '_nonce-response', false);
219
-        glsr()->render('partials/editor/metabox-response', [
220
-            'response' => glsr(Database::class)->get($post->ID, 'response'),
221
-        ]);
218
+        wp_nonce_field( 'response', '_nonce-response', false );
219
+        glsr()->render( 'partials/editor/metabox-response', [
220
+            'response' => glsr( Database::class )->get( $post->ID, 'response' ),
221
+        ] );
222 222
     }
223 223
 
224 224
     /**
@@ -226,15 +226,15 @@  discard block
 block discarded – undo
226 226
      * @return void
227 227
      * @action edit_form_after_title
228 228
      */
229
-    public function renderReviewEditor($post)
229
+    public function renderReviewEditor( $post )
230 230
     {
231
-        if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
231
+        if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) ) {
232 232
             return;
233 233
         }
234
-        glsr()->render('partials/editor/review', [
234
+        glsr()->render( 'partials/editor/review', [
235 235
             'post' => $post,
236
-            'response' => glsr(Database::class)->get($post->ID, 'response'),
237
-        ]);
236
+            'response' => glsr( Database::class )->get( $post->ID, 'response' ),
237
+        ] );
238 238
     }
239 239
 
240 240
     /**
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
     public function renderReviewFields()
245 245
     {
246 246
         $screen = glsr_current_screen();
247
-        if ('post' != $screen->base || Application::POST_TYPE != $screen->post_type) {
247
+        if( 'post' != $screen->base || Application::POST_TYPE != $screen->post_type ) {
248 248
             return;
249 249
         }
250
-        add_action('edit_form_after_title', [$this, 'renderReviewEditor']);
251
-        add_action('edit_form_top', [$this, 'renderReviewNotice']);
250
+        add_action( 'edit_form_after_title', [$this, 'renderReviewEditor'] );
251
+        add_action( 'edit_form_top', [$this, 'renderReviewNotice'] );
252 252
     }
253 253
 
254 254
     /**
@@ -256,20 +256,20 @@  discard block
 block discarded – undo
256 256
      * @return void
257 257
      * @action edit_form_top
258 258
      */
259
-    public function renderReviewNotice($post)
259
+    public function renderReviewNotice( $post )
260 260
     {
261
-        if (!$this->isReviewPostType($post) || $this->isReviewEditable($post)) {
261
+        if( !$this->isReviewPostType( $post ) || $this->isReviewEditable( $post ) ) {
262 262
             return;
263 263
         }
264
-        glsr(Notice::class)->addWarning(sprintf(
265
-            __('%s reviews are read-only.', 'site-reviews'),
266
-            glsr(Columns::class)->buildColumnReviewType($post->ID)
267
-        ));
268
-        glsr(Template::class)->render('partials/editor/notice', [
264
+        glsr( Notice::class )->addWarning( sprintf(
265
+            __( '%s reviews are read-only.', 'site-reviews' ),
266
+            glsr( Columns::class )->buildColumnReviewType( $post->ID )
267
+        ) );
268
+        glsr( Template::class )->render( 'partials/editor/notice', [
269 269
             'context' => [
270
-                'notices' => glsr(Notice::class)->get(),
270
+                'notices' => glsr( Notice::class )->get(),
271 271
             ],
272
-        ]);
272
+        ] );
273 273
     }
274 274
 
275 275
     /**
@@ -278,16 +278,16 @@  discard block
 block discarded – undo
278 278
      * @see glsr_categories_meta_box()
279 279
      * @callback register_taxonomy
280 280
      */
281
-    public function renderTaxonomyMetabox($post)
281
+    public function renderTaxonomyMetabox( $post )
282 282
     {
283
-        if (!$this->isReviewPostType($post)) {
283
+        if( !$this->isReviewPostType( $post ) ) {
284 284
             return;
285 285
         }
286
-        glsr()->render('partials/editor/metabox-categories', [
286
+        glsr()->render( 'partials/editor/metabox-categories', [
287 287
             'post' => $post,
288 288
             'tax_name' => Application::TAXONOMY,
289
-            'taxonomy' => get_taxonomy(Application::TAXONOMY),
290
-        ]);
289
+            'taxonomy' => get_taxonomy( Application::TAXONOMY ),
290
+        ] );
291 291
     }
292 292
 
293 293
     /**
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
      */
298 298
     public function revertReview()
299 299
     {
300
-        if (Application::ID != filter_input(INPUT_GET, 'plugin')) {
300
+        if( Application::ID != filter_input( INPUT_GET, 'plugin' ) ) {
301 301
             return;
302 302
         }
303
-        check_admin_referer('revert-review_'.($postId = $this->getPostId()));
304
-        glsr(ReviewManager::class)->revert($postId);
305
-        $this->redirect($postId, 52);
303
+        check_admin_referer( 'revert-review_'.($postId = $this->getPostId()) );
304
+        glsr( ReviewManager::class )->revert( $postId );
305
+        $this->redirect( $postId, 52 );
306 306
     }
307 307
 
308 308
     /**
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
      * @return void
313 313
      * @action save_post_.Application::POST_TYPE
314 314
      */
315
-    public function saveMetaboxes($postId, $post, $isUpdating)
315
+    public function saveMetaboxes( $postId, $post, $isUpdating )
316 316
     {
317
-        glsr(Metaboxes::class)->saveAssignedToMetabox($postId);
318
-        glsr(Metaboxes::class)->saveResponseMetabox($postId);
319
-        if ($isUpdating) {
320
-            do_action('site-reviews/review/saved', glsr_get_review($postId));
317
+        glsr( Metaboxes::class )->saveAssignedToMetabox( $postId );
318
+        glsr( Metaboxes::class )->saveResponseMetabox( $postId );
319
+        if( $isUpdating ) {
320
+            do_action( 'site-reviews/review/saved', glsr_get_review( $postId ) );
321 321
         }
322 322
     }
323 323
 
@@ -325,81 +325,81 @@  discard block
 block discarded – undo
325 325
      * @param string $assignedTo
326 326
      * @return string
327 327
      */
328
-    protected function buildAssignedToTemplate($assignedTo, WP_Post $post)
328
+    protected function buildAssignedToTemplate( $assignedTo, WP_Post $post )
329 329
     {
330
-        $assignedPost = glsr(Database::class)->getAssignedToPost($post->ID, $assignedTo);
331
-        if (!($assignedPost instanceof WP_Post)) {
330
+        $assignedPost = glsr( Database::class )->getAssignedToPost( $post->ID, $assignedTo );
331
+        if( !($assignedPost instanceof WP_Post) ) {
332 332
             return;
333 333
         }
334
-        return glsr(Template::class)->build('partials/editor/assigned-post', [
334
+        return glsr( Template::class )->build( 'partials/editor/assigned-post', [
335 335
             'context' => [
336
-                'data.url' => (string) get_permalink($assignedPost),
337
-                'data.title' => get_the_title($assignedPost),
336
+                'data.url' => (string)get_permalink( $assignedPost ),
337
+                'data.title' => get_the_title( $assignedPost ),
338 338
             ],
339
-        ]);
339
+        ] );
340 340
     }
341 341
 
342 342
     /**
343 343
      * @return string
344 344
      */
345
-    protected function buildDetailsMetaBoxRevertButton(Review $review, WP_Post $post)
345
+    protected function buildDetailsMetaBoxRevertButton( Review $review, WP_Post $post )
346 346
     {
347 347
         $isModified = !Arr::compareArrays(
348 348
             [$review->title, $review->content, $review->date],
349 349
             [
350
-                glsr(Database::class)->get($post->ID, 'title'),
351
-                glsr(Database::class)->get($post->ID, 'content'),
352
-                glsr(Database::class)->get($post->ID, 'date'),
350
+                glsr( Database::class )->get( $post->ID, 'title' ),
351
+                glsr( Database::class )->get( $post->ID, 'content' ),
352
+                glsr( Database::class )->get( $post->ID, 'date' ),
353 353
             ]
354 354
         );
355
-        if ($isModified) {
355
+        if( $isModified ) {
356 356
             $revertUrl = wp_nonce_url(
357
-                admin_url('post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID),
357
+                admin_url( 'post.php?post='.$post->ID.'&action=revert&plugin='.Application::ID ),
358 358
                 'revert-review_'.$post->ID
359 359
             );
360
-            return glsr(Builder::class)->a(__('Revert Changes', 'site-reviews'), [
360
+            return glsr( Builder::class )->a( __( 'Revert Changes', 'site-reviews' ), [
361 361
                 'class' => 'button button-large',
362 362
                 'href' => $revertUrl,
363 363
                 'id' => 'revert',
364
-            ]);
364
+            ] );
365 365
         }
366
-        return glsr(Builder::class)->button(__('Nothing to Revert', 'site-reviews'), [
366
+        return glsr( Builder::class )->button( __( 'Nothing to Revert', 'site-reviews' ), [
367 367
             'class' => 'button-large',
368 368
             'disabled' => true,
369 369
             'id' => 'revert',
370
-        ]);
370
+        ] );
371 371
     }
372 372
 
373 373
     /**
374 374
      * @param string $domain
375 375
      * @return bool
376 376
      */
377
-    protected function canModifyTranslation($domain = 'default')
377
+    protected function canModifyTranslation( $domain = 'default' )
378 378
     {
379
-        if ('default' != $domain || empty(glsr_current_screen()->base)) {
379
+        if( 'default' != $domain || empty(glsr_current_screen()->base) ) {
380 380
             return false;
381 381
         }
382 382
         return Application::POST_TYPE == glsr_current_screen()->post_type
383
-            && in_array(glsr_current_screen()->base, ['edit', 'post']);
383
+            && in_array( glsr_current_screen()->base, ['edit', 'post'] );
384 384
     }
385 385
 
386 386
     /**
387 387
      * @param object $review
388 388
      * @return string|void
389 389
      */
390
-    protected function getReviewType($review)
390
+    protected function getReviewType( $review )
391 391
     {
392
-        if (count(glsr()->reviewTypes) < 2) {
392
+        if( count( glsr()->reviewTypes ) < 2 ) {
393 393
             return;
394 394
         }
395
-        $reviewType = array_key_exists($review->review_type, glsr()->reviewTypes)
395
+        $reviewType = array_key_exists( $review->review_type, glsr()->reviewTypes )
396 396
             ? glsr()->reviewTypes[$review->review_type]
397
-            : __('Unknown', 'site-reviews');
398
-        if (!empty($review->url)) {
399
-            $reviewType = glsr(Builder::class)->a($reviewType, [
397
+            : __( 'Unknown', 'site-reviews' );
398
+        if( !empty($review->url) ) {
399
+            $reviewType = glsr( Builder::class )->a( $reviewType, [
400 400
                 'href' => $review->url,
401 401
                 'target' => '_blank',
402
-            ]);
402
+            ] );
403 403
         }
404 404
         return $reviewType;
405 405
     }
@@ -407,18 +407,18 @@  discard block
 block discarded – undo
407 407
     /**
408 408
      * @return bool
409 409
      */
410
-    protected function isReviewEditable($post)
410
+    protected function isReviewEditable( $post )
411 411
     {
412
-        return $this->isReviewPostType($post)
413
-            && post_type_supports(Application::POST_TYPE, 'title')
414
-            && 'local' == glsr(Database::class)->get($post->ID, 'review_type');
412
+        return $this->isReviewPostType( $post )
413
+            && post_type_supports( Application::POST_TYPE, 'title' )
414
+            && 'local' == glsr( Database::class )->get( $post->ID, 'review_type' );
415 415
     }
416 416
 
417 417
     /**
418 418
      * @param mixed $post
419 419
      * @return bool
420 420
      */
421
-    protected function isReviewPostType($post)
421
+    protected function isReviewPostType( $post )
422 422
     {
423 423
         return $post instanceof WP_Post && Application::POST_TYPE == $post->post_type;
424 424
     }
@@ -426,29 +426,29 @@  discard block
 block discarded – undo
426 426
     /**
427 427
      * @return array
428 428
      */
429
-    protected function normalizeDetailsMetaBox(Review $review)
429
+    protected function normalizeDetailsMetaBox( Review $review )
430 430
     {
431 431
         $user = empty($review->user_id)
432
-            ? __('Unregistered user', 'site-reviews')
433
-            : glsr(Builder::class)->a(get_the_author_meta('display_name', $review->user_id), [
434
-                'href' => get_author_posts_url($review->user_id),
435
-            ]);
432
+            ? __( 'Unregistered user', 'site-reviews' )
433
+            : glsr( Builder::class )->a( get_the_author_meta( 'display_name', $review->user_id ), [
434
+                'href' => get_author_posts_url( $review->user_id ),
435
+            ] );
436 436
         $email = empty($review->email)
437 437
             ? '&mdash;'
438
-            : glsr(Builder::class)->a($review->email, [
439
-                'href' => 'mailto:'.$review->email.'?subject='.esc_attr(__('RE:', 'site-reviews').' '.$review->title),
440
-            ]);
438
+            : glsr( Builder::class )->a( $review->email, [
439
+                'href' => 'mailto:'.$review->email.'?subject='.esc_attr( __( 'RE:', 'site-reviews' ).' '.$review->title ),
440
+            ] );
441 441
         $metabox = [
442
-            __('Rating', 'site-reviews') => glsr_star_rating($review->rating),
443
-            __('Type', 'site-reviews') => $this->getReviewType($review),
444
-            __('Date', 'site-reviews') => get_date_from_gmt($review->date, 'F j, Y'),
445
-            __('Name', 'site-reviews') => $review->author,
446
-            __('Email', 'site-reviews') => $email,
447
-            __('User', 'site-reviews') => $user,
448
-            __('IP Address', 'site-reviews') => $review->ip_address,
449
-            __('Avatar', 'site-reviews') => sprintf('<img src="%s" width="96">', $review->avatar),
442
+            __( 'Rating', 'site-reviews' ) => glsr_star_rating( $review->rating ),
443
+            __( 'Type', 'site-reviews' ) => $this->getReviewType( $review ),
444
+            __( 'Date', 'site-reviews' ) => get_date_from_gmt( $review->date, 'F j, Y' ),
445
+            __( 'Name', 'site-reviews' ) => $review->author,
446
+            __( 'Email', 'site-reviews' ) => $email,
447
+            __( 'User', 'site-reviews' ) => $user,
448
+            __( 'IP Address', 'site-reviews' ) => $review->ip_address,
449
+            __( 'Avatar', 'site-reviews' ) => sprintf( '<img src="%s" width="96">', $review->avatar ),
450 450
         ];
451
-        return array_filter(apply_filters('site-reviews/metabox/details', $metabox, $review));
451
+        return array_filter( apply_filters( 'site-reviews/metabox/details', $metabox, $review ) );
452 452
     }
453 453
 
454 454
     /**
@@ -456,16 +456,16 @@  discard block
 block discarded – undo
456 456
      * @param int $messageIndex
457 457
      * @return void
458 458
      */
459
-    protected function redirect($postId, $messageIndex)
459
+    protected function redirect( $postId, $messageIndex )
460 460
     {
461 461
         $referer = wp_get_referer();
462 462
         $hasReferer = !$referer
463
-            || false !== strpos($referer, 'post.php')
464
-            || false !== strpos($referer, 'post-new.php');
463
+            || false !== strpos( $referer, 'post.php' )
464
+            || false !== strpos( $referer, 'post-new.php' );
465 465
         $redirectUri = $hasReferer
466
-            ? remove_query_arg(['deleted', 'ids', 'trashed', 'untrashed'], $referer)
467
-            : get_edit_post_link($postId);
468
-        wp_safe_redirect(add_query_arg(['message' => $messageIndex], $redirectUri));
466
+            ? remove_query_arg( ['deleted', 'ids', 'trashed', 'untrashed'], $referer )
467
+            : get_edit_post_link( $postId );
468
+        wp_safe_redirect( add_query_arg( ['message' => $messageIndex], $redirectUri ) );
469 469
         exit;
470 470
     }
471 471
 }
Please login to merge, or discard this patch.