Completed
Pull Request — develop (#1272)
by
unknown
03:03
created
src/includes/class-wordlift-property-factory.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -11,56 +11,56 @@
 block discarded – undo
11 11
  */
12 12
 class Wordlift_Property_Factory {
13 13
 
14
-	/**
15
-	 * The default {@link Wordlift_Property_Service}.
16
-	 *
17
-	 * @since 3.7.0
18
-	 * @access private
19
-	 * @var \Wordlift_Property_Service $default_property_service The default {@link Wordlift_Property_Service}.
20
-	 */
21
-	private $default_property_service;
14
+    /**
15
+     * The default {@link Wordlift_Property_Service}.
16
+     *
17
+     * @since 3.7.0
18
+     * @access private
19
+     * @var \Wordlift_Property_Service $default_property_service The default {@link Wordlift_Property_Service}.
20
+     */
21
+    private $default_property_service;
22 22
 
23
-	private $property_services = array();
23
+    private $property_services = array();
24 24
 
25
-	/**
26
-	 * Wordlift_Property_Factory constructor.
27
-	 *
28
-	 * @since 3.7.0
29
-	 *
30
-	 * @param \Wordlift_Property_Service $default_property_service
31
-	 */
32
-	public function __construct( $default_property_service ) {
25
+    /**
26
+     * Wordlift_Property_Factory constructor.
27
+     *
28
+     * @since 3.7.0
29
+     *
30
+     * @param \Wordlift_Property_Service $default_property_service
31
+     */
32
+    public function __construct( $default_property_service ) {
33 33
 
34
-		$this->default_property_service = $default_property_service;
34
+        $this->default_property_service = $default_property_service;
35 35
 
36
-	}
36
+    }
37 37
 
38
-	/**
39
-	 * Set the {@link Wordlift_Property_Service} which handles that meta key.
40
-	 *
41
-	 * @since 3.7.0
42
-	 *
43
-	 * @param string $meta_key WordPress' meta key.
44
-	 * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance.
45
-	 */
46
-	public function register( $meta_key, $property_service ) {
38
+    /**
39
+     * Set the {@link Wordlift_Property_Service} which handles that meta key.
40
+     *
41
+     * @since 3.7.0
42
+     *
43
+     * @param string $meta_key WordPress' meta key.
44
+     * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance.
45
+     */
46
+    public function register( $meta_key, $property_service ) {
47 47
 
48
-		$this->property_services[ $meta_key ] = $property_service;
48
+        $this->property_services[ $meta_key ] = $property_service;
49 49
 
50
-	}
50
+    }
51 51
 
52
-	/**
53
-	 * Get the {@link Wordlift_Property_Service} which handles the specified meta key.
54
-	 *
55
-	 * @since 3.7.0
56
-	 *
57
-	 * @param $meta_key
58
-	 *
59
-	 * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key.
60
-	 */
61
-	public function get( $meta_key ) {
52
+    /**
53
+     * Get the {@link Wordlift_Property_Service} which handles the specified meta key.
54
+     *
55
+     * @since 3.7.0
56
+     *
57
+     * @param $meta_key
58
+     *
59
+     * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key.
60
+     */
61
+    public function get( $meta_key ) {
62 62
 
63
-		return $this->property_services[ $meta_key ] ?: $this->default_property_service;
64
-	}
63
+        return $this->property_services[ $meta_key ] ?: $this->default_property_service;
64
+    }
65 65
 
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param \Wordlift_Property_Service $default_property_service
31 31
 	 */
32
-	public function __construct( $default_property_service ) {
32
+	public function __construct($default_property_service) {
33 33
 
34 34
 		$this->default_property_service = $default_property_service;
35 35
 
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 	 * @param string $meta_key WordPress' meta key.
44 44
 	 * @param \Wordlift_Property_Service $property_service A {@link Wordlift_Property_Service} instance.
45 45
 	 */
46
-	public function register( $meta_key, $property_service ) {
46
+	public function register($meta_key, $property_service) {
47 47
 
48
-		$this->property_services[ $meta_key ] = $property_service;
48
+		$this->property_services[$meta_key] = $property_service;
49 49
 
50 50
 	}
51 51
 
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
 	 *
59 59
 	 * @return \Wordlift_Property_Service The {@link Wordlift_Property_Service} which handles the specified meta key.
60 60
 	 */
61
-	public function get( $meta_key ) {
61
+	public function get($meta_key) {
62 62
 
63
-		return $this->property_services[ $meta_key ] ?: $this->default_property_service;
63
+		return $this->property_services[$meta_key] ?: $this->default_property_service;
64 64
 	}
65 65
 
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
src/includes/class-wordlift-languages.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  * @since   3.9.0
11 11
  */
12 12
 
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
 	public static function get_languages() {
83 83
 
84 84
 		// Lazily load the languages.
85
-		if ( null === self::$languages ) {
85
+		if (null === self::$languages) {
86 86
 
87 87
 			// Get the language names from WP's own (multisite) function.
88
-			foreach ( self::$codes as $key ) {
89
-				self::$languages[ $key ] = self::format_code_lang( $key );
88
+			foreach (self::$codes as $key) {
89
+				self::$languages[$key] = self::format_code_lang($key);
90 90
 			}
91 91
 
92 92
 			// Sort by language name.
93
-			asort( self::$languages );
93
+			asort(self::$languages);
94 94
 		}
95 95
 
96 96
 		return self::$languages;
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 	 * @return string The language corresponding to $code if it exists. If it does not exist,
107 107
 	 *                then the first two letters of $code is returned.
108 108
 	 */
109
-	private static function format_code_lang( $code = '' ) {
110
-		$code       = strtolower( substr( $code, 0, 2 ) );
109
+	private static function format_code_lang($code = '') {
110
+		$code       = strtolower(substr($code, 0, 2));
111 111
 		$lang_codes = array(
112 112
 			'aa' => 'Afar',
113 113
 			'ab' => 'Abkhazian',
@@ -304,9 +304,9 @@  discard block
 block discarded – undo
304 304
 		 * @param array $lang_codes Key/value pair of language codes where key is the short version.
305 305
 		 * @param string $code A two-letter designation of the language.
306 306
 		 */
307
-		$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
307
+		$lang_codes = apply_filters('lang_codes', $lang_codes, $code);
308 308
 
309
-		return strtr( $code, $lang_codes );
309
+		return strtr($code, $lang_codes);
310 310
 	}
311 311
 
312 312
 }
Please login to merge, or discard this patch.
Indentation   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 if ( ! defined( 'ABSPATH' ) ) {
14
-	exit;
14
+    exit;
15 15
 }
16 16
 
17 17
 /**
@@ -21,295 +21,295 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Languages {
23 23
 
24
-	/**
25
-	 * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the
26
-	 * `get_languages` function.
27
-	 *
28
-	 * @since 3.9.0
29
-	 * @var array|null An array of language codes => language names pairs or NULL if not initialized yet.
30
-	 */
31
-	private static $languages = null;
24
+    /**
25
+     * An array that will contain language codes => language names pairs. It gets lazily loaded the first time by the
26
+     * `get_languages` function.
27
+     *
28
+     * @since 3.9.0
29
+     * @var array|null An array of language codes => language names pairs or NULL if not initialized yet.
30
+     */
31
+    private static $languages = null;
32 32
 
33
-	/**
34
-	 * The list of supported language codes.
35
-	 *
36
-	 * @since 3.9.0
37
-	 *
38
-	 * @var array An array of language codes.
39
-	 */
40
-	private static $codes = array(
41
-		'ar',
42
-		'be',
43
-		'bg',
44
-		'ca',
45
-		'cs',
46
-		'da',
47
-		'de',
48
-		'el',
49
-		'en',
50
-		'es',
51
-		'et',
52
-		'fi',
53
-		'fr',
54
-		'he',
55
-		'hr',
56
-		'hu',
57
-		'id',
58
-		'is',
59
-		'it',
60
-		'lt',
61
-		'lv',
62
-		'nl',
63
-		'no',
64
-		'pl',
65
-		'pt',
66
-		'ro',
67
-		'ru',
68
-		'sk',
69
-		'sl',
70
-		'sq',
71
-		'sr',
72
-		'sv',
73
-		'tr',
74
-		'uk',
75
-		'zh-cn',
76
-	);
33
+    /**
34
+     * The list of supported language codes.
35
+     *
36
+     * @since 3.9.0
37
+     *
38
+     * @var array An array of language codes.
39
+     */
40
+    private static $codes = array(
41
+        'ar',
42
+        'be',
43
+        'bg',
44
+        'ca',
45
+        'cs',
46
+        'da',
47
+        'de',
48
+        'el',
49
+        'en',
50
+        'es',
51
+        'et',
52
+        'fi',
53
+        'fr',
54
+        'he',
55
+        'hr',
56
+        'hu',
57
+        'id',
58
+        'is',
59
+        'it',
60
+        'lt',
61
+        'lv',
62
+        'nl',
63
+        'no',
64
+        'pl',
65
+        'pt',
66
+        'ro',
67
+        'ru',
68
+        'sk',
69
+        'sl',
70
+        'sq',
71
+        'sr',
72
+        'sv',
73
+        'tr',
74
+        'uk',
75
+        'zh-cn',
76
+    );
77 77
 
78
-	/**
79
-	 * Get the list of WordLift's supported languages in an array with language code => language name pairs.
80
-	 *
81
-	 * @since 3.9.0
82
-	 *
83
-	 * @return array An array with language code => language name pairs.
84
-	 */
85
-	public static function get_languages() {
78
+    /**
79
+     * Get the list of WordLift's supported languages in an array with language code => language name pairs.
80
+     *
81
+     * @since 3.9.0
82
+     *
83
+     * @return array An array with language code => language name pairs.
84
+     */
85
+    public static function get_languages() {
86 86
 
87
-		// Lazily load the languages.
88
-		if ( null === self::$languages ) {
87
+        // Lazily load the languages.
88
+        if ( null === self::$languages ) {
89 89
 
90
-			// Get the language names from WP's own (multisite) function.
91
-			foreach ( self::$codes as $key ) {
92
-				self::$languages[ $key ] = self::format_code_lang( $key );
93
-			}
90
+            // Get the language names from WP's own (multisite) function.
91
+            foreach ( self::$codes as $key ) {
92
+                self::$languages[ $key ] = self::format_code_lang( $key );
93
+            }
94 94
 
95
-			// Sort by language name.
96
-			asort( self::$languages );
97
-		}
95
+            // Sort by language name.
96
+            asort( self::$languages );
97
+        }
98 98
 
99
-		return self::$languages;
100
-	}
99
+        return self::$languages;
100
+    }
101 101
 
102
-	/**
103
-	 * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`.
104
-	 *
105
-	 * @since 3.9.3
106
-	 *
107
-	 * @param string $code Optional. The two-letter language code. Default empty.
108
-	 *
109
-	 * @return string The language corresponding to $code if it exists. If it does not exist,
110
-	 *                then the first two letters of $code is returned.
111
-	 */
112
-	private static function format_code_lang( $code = '' ) {
113
-		$code       = strtolower( substr( $code, 0, 2 ) );
114
-		$lang_codes = array(
115
-			'aa' => 'Afar',
116
-			'ab' => 'Abkhazian',
117
-			'af' => 'Afrikaans',
118
-			'ak' => 'Akan',
119
-			'sq' => 'Albanian',
120
-			'am' => 'Amharic',
121
-			'ar' => 'Arabic',
122
-			'an' => 'Aragonese',
123
-			'hy' => 'Armenian',
124
-			'as' => 'Assamese',
125
-			'av' => 'Avaric',
126
-			'ae' => 'Avestan',
127
-			'ay' => 'Aymara',
128
-			'az' => 'Azerbaijani',
129
-			'ba' => 'Bashkir',
130
-			'bm' => 'Bambara',
131
-			'eu' => 'Basque',
132
-			'be' => 'Belarusian',
133
-			'bn' => 'Bengali',
134
-			'bh' => 'Bihari',
135
-			'bi' => 'Bislama',
136
-			'bs' => 'Bosnian',
137
-			'br' => 'Breton',
138
-			'bg' => 'Bulgarian',
139
-			'my' => 'Burmese',
140
-			'ca' => 'Catalan; Valencian',
141
-			'ch' => 'Chamorro',
142
-			'ce' => 'Chechen',
143
-			'zh' => 'Chinese',
144
-			'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic',
145
-			'cv' => 'Chuvash',
146
-			'kw' => 'Cornish',
147
-			'co' => 'Corsican',
148
-			'cr' => 'Cree',
149
-			'cs' => 'Czech',
150
-			'da' => 'Danish',
151
-			'dv' => 'Divehi; Dhivehi; Maldivian',
152
-			'nl' => 'Dutch; Flemish',
153
-			'dz' => 'Dzongkha',
154
-			'en' => 'English',
155
-			'eo' => 'Esperanto',
156
-			'et' => 'Estonian',
157
-			'ee' => 'Ewe',
158
-			'fo' => 'Faroese',
159
-			'fj' => 'Fijjian',
160
-			'fi' => 'Finnish',
161
-			'fr' => 'French',
162
-			'fy' => 'Western Frisian',
163
-			'ff' => 'Fulah',
164
-			'ka' => 'Georgian',
165
-			'de' => 'German',
166
-			'gd' => 'Gaelic; Scottish Gaelic',
167
-			'ga' => 'Irish',
168
-			'gl' => 'Galician',
169
-			'gv' => 'Manx',
170
-			'el' => 'Greek, Modern',
171
-			'gn' => 'Guarani',
172
-			'gu' => 'Gujarati',
173
-			'ht' => 'Haitian; Haitian Creole',
174
-			'ha' => 'Hausa',
175
-			'he' => 'Hebrew',
176
-			'hz' => 'Herero',
177
-			'hi' => 'Hindi',
178
-			'ho' => 'Hiri Motu',
179
-			'hu' => 'Hungarian',
180
-			'ig' => 'Igbo',
181
-			'is' => 'Icelandic',
182
-			'io' => 'Ido',
183
-			'ii' => 'Sichuan Yi',
184
-			'iu' => 'Inuktitut',
185
-			'ie' => 'Interlingue',
186
-			'ia' => 'Interlingua (International Auxiliary Language Association)',
187
-			'id' => 'Indonesian',
188
-			'ik' => 'Inupiaq',
189
-			'it' => 'Italian',
190
-			'jv' => 'Javanese',
191
-			'ja' => 'Japanese',
192
-			'kl' => 'Kalaallisut; Greenlandic',
193
-			'kn' => 'Kannada',
194
-			'ks' => 'Kashmiri',
195
-			'kr' => 'Kanuri',
196
-			'kk' => 'Kazakh',
197
-			'km' => 'Central Khmer',
198
-			'ki' => 'Kikuyu; Gikuyu',
199
-			'rw' => 'Kinyarwanda',
200
-			'ky' => 'Kirghiz; Kyrgyz',
201
-			'kv' => 'Komi',
202
-			'kg' => 'Kongo',
203
-			'ko' => 'Korean',
204
-			'kj' => 'Kuanyama; Kwanyama',
205
-			'ku' => 'Kurdish',
206
-			'lo' => 'Lao',
207
-			'la' => 'Latin',
208
-			'lv' => 'Latvian',
209
-			'li' => 'Limburgan; Limburger; Limburgish',
210
-			'ln' => 'Lingala',
211
-			'lt' => 'Lithuanian',
212
-			'lb' => 'Luxembourgish; Letzeburgesch',
213
-			'lu' => 'Luba-Katanga',
214
-			'lg' => 'Ganda',
215
-			'mk' => 'Macedonian',
216
-			'mh' => 'Marshallese',
217
-			'ml' => 'Malayalam',
218
-			'mi' => 'Maori',
219
-			'mr' => 'Marathi',
220
-			'ms' => 'Malay',
221
-			'mg' => 'Malagasy',
222
-			'mt' => 'Maltese',
223
-			'mo' => 'Moldavian',
224
-			'mn' => 'Mongolian',
225
-			'na' => 'Nauru',
226
-			'nv' => 'Navajo; Navaho',
227
-			'nr' => 'Ndebele, South; South Ndebele',
228
-			'nd' => 'Ndebele, North; North Ndebele',
229
-			'ng' => 'Ndonga',
230
-			'ne' => 'Nepali',
231
-			'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian',
232
-			'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
233
-			'no' => 'Norwegian',
234
-			'ny' => 'Chichewa; Chewa; Nyanja',
235
-			'oc' => 'Occitan, Provençal',
236
-			'oj' => 'Ojibwa',
237
-			'or' => 'Oriya',
238
-			'om' => 'Oromo',
239
-			'os' => 'Ossetian; Ossetic',
240
-			'pa' => 'Panjabi; Punjabi',
241
-			'fa' => 'Persian',
242
-			'pi' => 'Pali',
243
-			'pl' => 'Polish',
244
-			'pt' => 'Portuguese',
245
-			'ps' => 'Pushto',
246
-			'qu' => 'Quechua',
247
-			'rm' => 'Romansh',
248
-			'ro' => 'Romanian',
249
-			'rn' => 'Rundi',
250
-			'ru' => 'Russian',
251
-			'sg' => 'Sango',
252
-			'sa' => 'Sanskrit',
253
-			'sr' => 'Serbian',
254
-			'hr' => 'Croatian',
255
-			'si' => 'Sinhala; Sinhalese',
256
-			'sk' => 'Slovak',
257
-			'sl' => 'Slovenian',
258
-			'se' => 'Northern Sami',
259
-			'sm' => 'Samoan',
260
-			'sn' => 'Shona',
261
-			'sd' => 'Sindhi',
262
-			'so' => 'Somali',
263
-			'st' => 'Sotho, Southern',
264
-			'es' => 'Spanish; Castilian',
265
-			'sc' => 'Sardinian',
266
-			'ss' => 'Swati',
267
-			'su' => 'Sundanese',
268
-			'sw' => 'Swahili',
269
-			'sv' => 'Swedish',
270
-			'ty' => 'Tahitian',
271
-			'ta' => 'Tamil',
272
-			'tt' => 'Tatar',
273
-			'te' => 'Telugu',
274
-			'tg' => 'Tajik',
275
-			'tl' => 'Tagalog',
276
-			'th' => 'Thai',
277
-			'bo' => 'Tibetan',
278
-			'ti' => 'Tigrinya',
279
-			'to' => 'Tonga (Tonga Islands)',
280
-			'tn' => 'Tswana',
281
-			'ts' => 'Tsonga',
282
-			'tk' => 'Turkmen',
283
-			'tr' => 'Turkish',
284
-			'tw' => 'Twi',
285
-			'ug' => 'Uighur; Uyghur',
286
-			'uk' => 'Ukrainian',
287
-			'ur' => 'Urdu',
288
-			'uz' => 'Uzbek',
289
-			've' => 'Venda',
290
-			'vi' => 'Vietnamese',
291
-			'vo' => 'Volapük',
292
-			'cy' => 'Welsh',
293
-			'wa' => 'Walloon',
294
-			'wo' => 'Wolof',
295
-			'xh' => 'Xhosa',
296
-			'yi' => 'Yiddish',
297
-			'yo' => 'Yoruba',
298
-			'za' => 'Zhuang; Chuang',
299
-			'zu' => 'Zulu'
300
-		);
102
+    /**
103
+     * Returns the language for a language code. This function is a clone of WP's function provided in `ms.php`.
104
+     *
105
+     * @since 3.9.3
106
+     *
107
+     * @param string $code Optional. The two-letter language code. Default empty.
108
+     *
109
+     * @return string The language corresponding to $code if it exists. If it does not exist,
110
+     *                then the first two letters of $code is returned.
111
+     */
112
+    private static function format_code_lang( $code = '' ) {
113
+        $code       = strtolower( substr( $code, 0, 2 ) );
114
+        $lang_codes = array(
115
+            'aa' => 'Afar',
116
+            'ab' => 'Abkhazian',
117
+            'af' => 'Afrikaans',
118
+            'ak' => 'Akan',
119
+            'sq' => 'Albanian',
120
+            'am' => 'Amharic',
121
+            'ar' => 'Arabic',
122
+            'an' => 'Aragonese',
123
+            'hy' => 'Armenian',
124
+            'as' => 'Assamese',
125
+            'av' => 'Avaric',
126
+            'ae' => 'Avestan',
127
+            'ay' => 'Aymara',
128
+            'az' => 'Azerbaijani',
129
+            'ba' => 'Bashkir',
130
+            'bm' => 'Bambara',
131
+            'eu' => 'Basque',
132
+            'be' => 'Belarusian',
133
+            'bn' => 'Bengali',
134
+            'bh' => 'Bihari',
135
+            'bi' => 'Bislama',
136
+            'bs' => 'Bosnian',
137
+            'br' => 'Breton',
138
+            'bg' => 'Bulgarian',
139
+            'my' => 'Burmese',
140
+            'ca' => 'Catalan; Valencian',
141
+            'ch' => 'Chamorro',
142
+            'ce' => 'Chechen',
143
+            'zh' => 'Chinese',
144
+            'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic',
145
+            'cv' => 'Chuvash',
146
+            'kw' => 'Cornish',
147
+            'co' => 'Corsican',
148
+            'cr' => 'Cree',
149
+            'cs' => 'Czech',
150
+            'da' => 'Danish',
151
+            'dv' => 'Divehi; Dhivehi; Maldivian',
152
+            'nl' => 'Dutch; Flemish',
153
+            'dz' => 'Dzongkha',
154
+            'en' => 'English',
155
+            'eo' => 'Esperanto',
156
+            'et' => 'Estonian',
157
+            'ee' => 'Ewe',
158
+            'fo' => 'Faroese',
159
+            'fj' => 'Fijjian',
160
+            'fi' => 'Finnish',
161
+            'fr' => 'French',
162
+            'fy' => 'Western Frisian',
163
+            'ff' => 'Fulah',
164
+            'ka' => 'Georgian',
165
+            'de' => 'German',
166
+            'gd' => 'Gaelic; Scottish Gaelic',
167
+            'ga' => 'Irish',
168
+            'gl' => 'Galician',
169
+            'gv' => 'Manx',
170
+            'el' => 'Greek, Modern',
171
+            'gn' => 'Guarani',
172
+            'gu' => 'Gujarati',
173
+            'ht' => 'Haitian; Haitian Creole',
174
+            'ha' => 'Hausa',
175
+            'he' => 'Hebrew',
176
+            'hz' => 'Herero',
177
+            'hi' => 'Hindi',
178
+            'ho' => 'Hiri Motu',
179
+            'hu' => 'Hungarian',
180
+            'ig' => 'Igbo',
181
+            'is' => 'Icelandic',
182
+            'io' => 'Ido',
183
+            'ii' => 'Sichuan Yi',
184
+            'iu' => 'Inuktitut',
185
+            'ie' => 'Interlingue',
186
+            'ia' => 'Interlingua (International Auxiliary Language Association)',
187
+            'id' => 'Indonesian',
188
+            'ik' => 'Inupiaq',
189
+            'it' => 'Italian',
190
+            'jv' => 'Javanese',
191
+            'ja' => 'Japanese',
192
+            'kl' => 'Kalaallisut; Greenlandic',
193
+            'kn' => 'Kannada',
194
+            'ks' => 'Kashmiri',
195
+            'kr' => 'Kanuri',
196
+            'kk' => 'Kazakh',
197
+            'km' => 'Central Khmer',
198
+            'ki' => 'Kikuyu; Gikuyu',
199
+            'rw' => 'Kinyarwanda',
200
+            'ky' => 'Kirghiz; Kyrgyz',
201
+            'kv' => 'Komi',
202
+            'kg' => 'Kongo',
203
+            'ko' => 'Korean',
204
+            'kj' => 'Kuanyama; Kwanyama',
205
+            'ku' => 'Kurdish',
206
+            'lo' => 'Lao',
207
+            'la' => 'Latin',
208
+            'lv' => 'Latvian',
209
+            'li' => 'Limburgan; Limburger; Limburgish',
210
+            'ln' => 'Lingala',
211
+            'lt' => 'Lithuanian',
212
+            'lb' => 'Luxembourgish; Letzeburgesch',
213
+            'lu' => 'Luba-Katanga',
214
+            'lg' => 'Ganda',
215
+            'mk' => 'Macedonian',
216
+            'mh' => 'Marshallese',
217
+            'ml' => 'Malayalam',
218
+            'mi' => 'Maori',
219
+            'mr' => 'Marathi',
220
+            'ms' => 'Malay',
221
+            'mg' => 'Malagasy',
222
+            'mt' => 'Maltese',
223
+            'mo' => 'Moldavian',
224
+            'mn' => 'Mongolian',
225
+            'na' => 'Nauru',
226
+            'nv' => 'Navajo; Navaho',
227
+            'nr' => 'Ndebele, South; South Ndebele',
228
+            'nd' => 'Ndebele, North; North Ndebele',
229
+            'ng' => 'Ndonga',
230
+            'ne' => 'Nepali',
231
+            'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian',
232
+            'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
233
+            'no' => 'Norwegian',
234
+            'ny' => 'Chichewa; Chewa; Nyanja',
235
+            'oc' => 'Occitan, Provençal',
236
+            'oj' => 'Ojibwa',
237
+            'or' => 'Oriya',
238
+            'om' => 'Oromo',
239
+            'os' => 'Ossetian; Ossetic',
240
+            'pa' => 'Panjabi; Punjabi',
241
+            'fa' => 'Persian',
242
+            'pi' => 'Pali',
243
+            'pl' => 'Polish',
244
+            'pt' => 'Portuguese',
245
+            'ps' => 'Pushto',
246
+            'qu' => 'Quechua',
247
+            'rm' => 'Romansh',
248
+            'ro' => 'Romanian',
249
+            'rn' => 'Rundi',
250
+            'ru' => 'Russian',
251
+            'sg' => 'Sango',
252
+            'sa' => 'Sanskrit',
253
+            'sr' => 'Serbian',
254
+            'hr' => 'Croatian',
255
+            'si' => 'Sinhala; Sinhalese',
256
+            'sk' => 'Slovak',
257
+            'sl' => 'Slovenian',
258
+            'se' => 'Northern Sami',
259
+            'sm' => 'Samoan',
260
+            'sn' => 'Shona',
261
+            'sd' => 'Sindhi',
262
+            'so' => 'Somali',
263
+            'st' => 'Sotho, Southern',
264
+            'es' => 'Spanish; Castilian',
265
+            'sc' => 'Sardinian',
266
+            'ss' => 'Swati',
267
+            'su' => 'Sundanese',
268
+            'sw' => 'Swahili',
269
+            'sv' => 'Swedish',
270
+            'ty' => 'Tahitian',
271
+            'ta' => 'Tamil',
272
+            'tt' => 'Tatar',
273
+            'te' => 'Telugu',
274
+            'tg' => 'Tajik',
275
+            'tl' => 'Tagalog',
276
+            'th' => 'Thai',
277
+            'bo' => 'Tibetan',
278
+            'ti' => 'Tigrinya',
279
+            'to' => 'Tonga (Tonga Islands)',
280
+            'tn' => 'Tswana',
281
+            'ts' => 'Tsonga',
282
+            'tk' => 'Turkmen',
283
+            'tr' => 'Turkish',
284
+            'tw' => 'Twi',
285
+            'ug' => 'Uighur; Uyghur',
286
+            'uk' => 'Ukrainian',
287
+            'ur' => 'Urdu',
288
+            'uz' => 'Uzbek',
289
+            've' => 'Venda',
290
+            'vi' => 'Vietnamese',
291
+            'vo' => 'Volapük',
292
+            'cy' => 'Welsh',
293
+            'wa' => 'Walloon',
294
+            'wo' => 'Wolof',
295
+            'xh' => 'Xhosa',
296
+            'yi' => 'Yiddish',
297
+            'yo' => 'Yoruba',
298
+            'za' => 'Zhuang; Chuang',
299
+            'zu' => 'Zulu'
300
+        );
301 301
 
302
-		/**
303
-		 * Filters the language codes.
304
-		 *
305
-		 * @since MU
306
-		 *
307
-		 * @param array $lang_codes Key/value pair of language codes where key is the short version.
308
-		 * @param string $code A two-letter designation of the language.
309
-		 */
310
-		$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
302
+        /**
303
+         * Filters the language codes.
304
+         *
305
+         * @since MU
306
+         *
307
+         * @param array $lang_codes Key/value pair of language codes where key is the short version.
308
+         * @param string $code A two-letter designation of the language.
309
+         */
310
+        $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
311 311
 
312
-		return strtr( $code, $lang_codes );
313
-	}
312
+        return strtr( $code, $lang_codes );
313
+    }
314 314
 
315 315
 }
Please login to merge, or discard this patch.
src/includes/class-wordlift-rating-service.php 3 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -173,7 +173,6 @@  discard block
 block discarded – undo
173 173
 	 * @since 3.3.0
174 174
 	 *
175 175
 	 * @param int $post_id      The entity post id.
176
-	 * @param     $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj.
177 176
 	 *
178 177
 	 * @return array An array representing the rating obj.
179 178
 	 */
@@ -332,7 +331,7 @@  discard block
 block discarded – undo
332 331
 	 *
333 332
 	 * @param int $score The rating score for a given entity.
334 333
 	 *
335
-	 * @return string The input HTML code.
334
+	 * @return double The input HTML code.
336 335
 	 */
337 336
 	public function convert_raw_score_to_percentage( $score ) {
338 337
 
Please login to merge, or discard this patch.
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -14,374 +14,374 @@
 block discarded – undo
14 14
  */
15 15
 class Wordlift_Rating_Service {
16 16
 
17
-	/**
18
-	 * Entity rating max.
19
-	 *
20
-	 * @since 3.3.0
21
-	 */
22
-	const RATING_MAX = 7;
23
-
24
-	/**
25
-	 * Entity rating score meta key.
26
-	 *
27
-	 * @since 3.3.0
28
-	 */
29
-	const RATING_RAW_SCORE_META_KEY = '_wl_entity_rating_raw_score';
30
-
31
-	/**
32
-	 * Entity rating warnings meta key.
33
-	 *
34
-	 * @since 3.3.0
35
-	 */
36
-	const RATING_WARNINGS_META_KEY = '_wl_entity_rating_warnings';
37
-
38
-	/**
39
-	 * Entity warning has related post identifier.
40
-	 *
41
-	 * @since 3.3.0
42
-	 */
43
-	const RATING_WARNING_HAS_RELATED_POSTS = 'There are no related posts for the current entity.';
44
-
45
-	/**
46
-	 * Entity warning has content post identifier.
47
-	 *
48
-	 * @since 3.3.0
49
-	 */
50
-	const RATING_WARNING_HAS_CONTENT_POST = 'This entity has not description.';
51
-
52
-	/**
53
-	 * Entity warning has related entities identifier.
54
-	 *
55
-	 * @since 3.3.0
56
-	 */
57
-	const RATING_WARNING_HAS_RELATED_ENTITIES = 'There are no related entities for the current entity.';
58
-
59
-	/**
60
-	 * Entity warning is published identifier.
61
-	 *
62
-	 * @since 3.3.0
63
-	 */
64
-	const RATING_WARNING_IS_PUBLISHED = 'This entity is not published. It will not appear within analysis results.';
65
-
66
-	/**
67
-	 * Entity warning has thumbnail identifier.
68
-	 *
69
-	 * @since 3.3.0
70
-	 */
71
-	const RATING_WARNING_HAS_THUMBNAIL = 'This entity has no featured image yet.';
72
-
73
-	/**
74
-	 * Entity warning has same as identifier.
75
-	 *
76
-	 * @since 3.3.0
77
-	 */
78
-	const RATING_WARNING_HAS_SAME_AS = 'There are no sameAs configured for this entity.';
79
-
80
-	/**
81
-	 * Entity warning has completed metadata identifier.
82
-	 *
83
-	 * @since 3.3.0
84
-	 */
85
-	const RATING_WARNING_HAS_COMPLETED_METADATA = 'Schema.org metadata for this entity are not completed.';
86
-
87
-	/**
88
-	 * A {@link Wordlift_Entity_Service} instance.
89
-	 *
90
-	 * @since  3.10.0
91
-	 * @access private
92
-	 * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
93
-	 */
94
-	private $entity_service;
95
-
96
-	/**
97
-	 *  A {@link Wordlift_Entity_Type_Service} instance.
98
-	 *
99
-	 * @since  3.10.0
100
-	 * @access private
101
-	 * @var Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
102
-	 */
103
-	private $entity_type_service;
104
-
105
-	/**
106
-	 * The Notice service.
107
-	 *
108
-	 * @since  3.3.0
109
-	 * @access private
110
-	 * @var \Wordlift_Notice_Service $notice_service The Notice service.
111
-	 */
112
-	private $notice_service;
113
-
114
-	/**
115
-	 * A {@link Wordlift_Log_Service} instance.
116
-	 *
117
-	 * @since  3.10.0
118
-	 * @access private
119
-	 * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
120
-	 */
121
-	private $log;
122
-
123
-	/**
124
-	 * Create a {@link Wordlift_Rating_Service} instance.
125
-	 *
126
-	 * @since 3.10.0
127
-	 *
128
-	 * @param \Wordlift_Entity_Service      $entity_service      A {@link Wordlift_Entity_Service} instance.
129
-	 * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
130
-	 * @param \Wordlift_Notice_Service      $notice_service      A {@link Wordlift_Notice_Service} instance.
131
-	 */
132
-	public function __construct( $entity_service, $entity_type_service, $notice_service ) {
133
-
134
-		$this->entity_service      = $entity_service;
135
-		$this->entity_type_service = $entity_type_service;
136
-		$this->notice_service      = $notice_service;
137
-
138
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rating_Service' );
139
-
140
-	}
141
-
142
-	/**
143
-	 * Set rating for a given entity.
144
-	 *
145
-	 * @since 3.3.0
146
-	 *
147
-	 * @param int $post_id The entity post id.
148
-	 *
149
-	 * @return array An array representing the rating obj.
150
-	 */
151
-	public function set_rating_for( $post_id ) {
152
-
153
-		if ( ! $this->entity_service->is_entity( $post_id ) ) {
154
-			return;
155
-		}
156
-
157
-		// Calculate rating for the given post.
158
-		$rating = $this->calculate_rating_for( $post_id );
159
-
160
-		// Store the rating on db as post meta. Please notice that RATING_RAW_SCORE_META_KEY
161
-		// is saved on a different meta to allow score sorting. Both meta are managed as unique.
162
-		//
163
-		// See https://codex.wordpress.org/Function_Reference/update_post_meta
164
-		update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score'] );
165
-		update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings'] );
166
-
167
-		$this->log->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'] ) );
168
-
169
-		// Finally returns the rating
170
-		return $rating;
171
-	}
172
-
173
-
174
-	/**
175
-	 * Get or calculate rating for a given entity
176
-	 *
177
-	 * @since 3.3.0
178
-	 *
179
-	 * @param int $post_id      The entity post id.
180
-	 * @param     $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj.
181
-	 *
182
-	 * @return array An array representing the rating obj.
183
-	 */
184
-	public function get_rating_for( $post_id, $force_reload = false ) {
185
-
186
-		// If forced reload is required or rating is missing.
187
-		if ( $force_reload ) {
188
-			$this->log->trace( "Force rating reload [ post_id :: $post_id ]" );
189
-
190
-			return $this->set_rating_for( $post_id );
191
-		}
192
-
193
-		$current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true );
194
-
195
-		if ( ! is_numeric( $current_raw_score ) ) {
196
-			$this->log->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" );
197
-
198
-			return $this->set_rating_for( $post_id );
199
-		}
200
-
201
-		$current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true );
202
-
203
-		// Finally return score and warnings
204
-		return array(
205
-			'raw_score'           => $current_raw_score,
206
-			'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ),
207
-			'percentage_score'    => $this->convert_raw_score_to_percentage( $current_raw_score ),
208
-			'warnings'            => $current_warnings,
209
-		);
210
-
211
-	}
212
-
213
-	/**
214
-	 * Calculate rating for a given entity.
215
-	 *
216
-	 * Rating depends from following criteria:
217
-	 *
218
-	 * 1. Is the current entity related to at least 1 post?
219
-	 * 2. Is the current entity content post not empty?
220
-	 * 3. Is the current entity related to at least 1 entity?
221
-	 * 4. Is the entity published?
222
-	 * 5. There is a a thumbnail associated to the entity?
223
-	 * 6. Has the entity a sameas defined?
224
-	 * 7. Are all schema.org required metadata compiled?
225
-	 *
226
-	 * Each positive check means +1 in terms of rating score.
227
-	 *
228
-	 * @since 3.3.0
229
-	 *
230
-	 * @param int $post_id The entity post id.
231
-	 *
232
-	 * @return array An array representing the rating obj.
233
-	 */
234
-	private function calculate_rating_for( $post_id ) {
235
-
236
-		// If it's not an entity, return.
237
-		if ( ! $this->entity_service->is_entity( $post_id ) ) {
238
-			return array();
239
-		}
240
-		// Retrieve the post object.
241
-		$post = get_post( $post_id );
242
-
243
-		// Rating value.
244
-		$score = 0;
245
-
246
-		// Store warning messages.
247
-		$warnings = array();
248
-
249
-		// Is the current entity related to at least 1 post?
250
-		( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ?
251
-			$score ++ :
252
-			array_push( $warnings, __( 'There are no related posts for the current entity.', 'wordlift' ) );
253
-
254
-		// Is the post content not empty?
255
-		( ! empty( $post->post_content ) ) ?
256
-			$score ++ :
257
-			array_push( $warnings, __( 'This entity has not description.', 'wordlift' ) );
258
-
259
-		// Is the current entity related to at least 1 entity?
260
-		// Was the current entity already disambiguated?
261
-		( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ?
262
-			$score ++ :
263
-			array_push( $warnings, __( 'There are no related entities for the current entity.', 'wordlift' ) );
264
-
265
-		// Is the entity published?
266
-		( 'publish' === get_post_status( $post->ID ) ) ?
267
-			$score ++ :
268
-			array_push( $warnings, __( 'This entity is not published. It will not appear within analysis results.', 'wordlift' ) );
269
-
270
-		// Has a thumbnail?
271
-		( has_post_thumbnail( $post->ID ) ) ?
272
-			$score ++ :
273
-			array_push( $warnings, __( 'This entity has no featured image yet.', 'wordlift' ) );
274
-
275
-		// Get all post meta keys for the current post
276
-		global $wpdb;
277
-
278
-		$query = $wpdb->prepare(
279
-			"SELECT DISTINCT (meta_key) FROM $wpdb->postmeta  WHERE post_id = %d", $post->ID
280
-		);
281
-
282
-		// Check intersection between available meta keys and expected ones
283
-		// arrays to detect missing values.
284
-		$available_meta_keys = $wpdb->get_col( $query );
285
-
286
-		// If each expected key is contained in available keys array ...
287
-		( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ?
288
-			$score ++ :
289
-			array_push( $warnings, __( 'There are no sameAs configured for this entity.', 'wordlift' ) );
290
-
291
-		$schema = $this->entity_type_service->get( $post_id );
292
-
293
-		$expected_meta_keys = ( null === $schema['custom_fields'] ) ?
294
-			array() :
295
-			array_keys( $schema['custom_fields'] );
296
-
297
-		$intersection = array_intersect( $expected_meta_keys, $available_meta_keys );
298
-		// If each expected key is contained in available keys array ...
299
-		( count( $intersection ) === count( $expected_meta_keys ) ) ?
300
-			$score ++ :
301
-			array_push( $warnings, __( 'Schema.org metadata for this entity are not completed.', 'wordlift' ) );
302
-
303
-		// Finally return score and warnings
304
-		return array(
305
-			'raw_score'           => $score,
306
-			'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ),
307
-			'percentage_score'    => $this->convert_raw_score_to_percentage( $score ),
308
-			'warnings'            => $warnings,
309
-		);
310
-
311
-	}
312
-
313
-	/**
314
-	 * Get as rating as input and convert in a traffic-light rating
315
-	 *
316
-	 * @since 3.3.0
317
-	 *
318
-	 * @param int $score The rating score for a given entity.
319
-	 *
320
-	 * @return string The input HTML code.
321
-	 */
322
-	private function convert_raw_score_to_traffic_light( $score ) {
323
-		// RATING_MAX : $score = 3 : x
324
-		// See http://php.net/manual/en/function.round.php
325
-		$rating = round( ( $score * 3 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
326
-
327
-		// If rating is 0, return 1, otherwise return rating
328
-		return ( 0 == $rating ) ? 1 : $rating;
329
-
330
-	}
331
-
332
-	/**
333
-	 * Get as rating as input and convert in a traffic-light rating
334
-	 *
335
-	 * @since 3.3.0
336
-	 *
337
-	 * @param int $score The rating score for a given entity.
338
-	 *
339
-	 * @return string The input HTML code.
340
-	 */
341
-	public function convert_raw_score_to_percentage( $score ) {
342
-
343
-		// RATING_MAX : $score = 100 : x
344
-		return round( ( $score * 100 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
345
-	}
346
-
347
-
348
-	/**
349
-	 * Add admin notices for the current entity depending on the current rating.
350
-	 *
351
-	 * @since 3.3.0
352
-	 */
353
-	public function in_admin_header() {
354
-
355
-		// Return safely if get_current_screen() is not defined (yet)
356
-		if ( false === function_exists( 'get_current_screen' ) ) {
357
-			return;
358
-		}
359
-
360
-		$screen = get_current_screen();
361
-		// If there is any valid screen nothing to do
362
-		if ( null === $screen ) {
363
-			return;
364
-		}
365
-
366
-		// If you're not in the entity post edit page, return.
367
-		if ( Wordlift_Entity_Service::TYPE_NAME !== $screen->id ) {
368
-			return;
369
-		}
370
-		// Retrieve the current global post
371
-		global $post;
372
-		// If it's not an entity, return.
373
-		if ( ! $this->entity_service->is_entity( $post->ID ) ) {
374
-			return;
375
-		}
376
-		// Retrieve an updated rating for the current entity
377
-		$rating = $this->get_rating_for( $post->ID, true );
378
-
379
-		// If there is at least 1 warning
380
-		if ( isset( $rating['warnings'] ) && 0 < count( $rating['warnings'] ) ) {
381
-			// TODO - Pass Wordlift_Notice_Service trough the service constructor
382
-			$this->notice_service->add_suggestion( $rating['warnings'] );
383
-		}
384
-
385
-	}
17
+    /**
18
+     * Entity rating max.
19
+     *
20
+     * @since 3.3.0
21
+     */
22
+    const RATING_MAX = 7;
23
+
24
+    /**
25
+     * Entity rating score meta key.
26
+     *
27
+     * @since 3.3.0
28
+     */
29
+    const RATING_RAW_SCORE_META_KEY = '_wl_entity_rating_raw_score';
30
+
31
+    /**
32
+     * Entity rating warnings meta key.
33
+     *
34
+     * @since 3.3.0
35
+     */
36
+    const RATING_WARNINGS_META_KEY = '_wl_entity_rating_warnings';
37
+
38
+    /**
39
+     * Entity warning has related post identifier.
40
+     *
41
+     * @since 3.3.0
42
+     */
43
+    const RATING_WARNING_HAS_RELATED_POSTS = 'There are no related posts for the current entity.';
44
+
45
+    /**
46
+     * Entity warning has content post identifier.
47
+     *
48
+     * @since 3.3.0
49
+     */
50
+    const RATING_WARNING_HAS_CONTENT_POST = 'This entity has not description.';
51
+
52
+    /**
53
+     * Entity warning has related entities identifier.
54
+     *
55
+     * @since 3.3.0
56
+     */
57
+    const RATING_WARNING_HAS_RELATED_ENTITIES = 'There are no related entities for the current entity.';
58
+
59
+    /**
60
+     * Entity warning is published identifier.
61
+     *
62
+     * @since 3.3.0
63
+     */
64
+    const RATING_WARNING_IS_PUBLISHED = 'This entity is not published. It will not appear within analysis results.';
65
+
66
+    /**
67
+     * Entity warning has thumbnail identifier.
68
+     *
69
+     * @since 3.3.0
70
+     */
71
+    const RATING_WARNING_HAS_THUMBNAIL = 'This entity has no featured image yet.';
72
+
73
+    /**
74
+     * Entity warning has same as identifier.
75
+     *
76
+     * @since 3.3.0
77
+     */
78
+    const RATING_WARNING_HAS_SAME_AS = 'There are no sameAs configured for this entity.';
79
+
80
+    /**
81
+     * Entity warning has completed metadata identifier.
82
+     *
83
+     * @since 3.3.0
84
+     */
85
+    const RATING_WARNING_HAS_COMPLETED_METADATA = 'Schema.org metadata for this entity are not completed.';
86
+
87
+    /**
88
+     * A {@link Wordlift_Entity_Service} instance.
89
+     *
90
+     * @since  3.10.0
91
+     * @access private
92
+     * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance.
93
+     */
94
+    private $entity_service;
95
+
96
+    /**
97
+     *  A {@link Wordlift_Entity_Type_Service} instance.
98
+     *
99
+     * @since  3.10.0
100
+     * @access private
101
+     * @var Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
102
+     */
103
+    private $entity_type_service;
104
+
105
+    /**
106
+     * The Notice service.
107
+     *
108
+     * @since  3.3.0
109
+     * @access private
110
+     * @var \Wordlift_Notice_Service $notice_service The Notice service.
111
+     */
112
+    private $notice_service;
113
+
114
+    /**
115
+     * A {@link Wordlift_Log_Service} instance.
116
+     *
117
+     * @since  3.10.0
118
+     * @access private
119
+     * @var Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
120
+     */
121
+    private $log;
122
+
123
+    /**
124
+     * Create a {@link Wordlift_Rating_Service} instance.
125
+     *
126
+     * @since 3.10.0
127
+     *
128
+     * @param \Wordlift_Entity_Service      $entity_service      A {@link Wordlift_Entity_Service} instance.
129
+     * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
130
+     * @param \Wordlift_Notice_Service      $notice_service      A {@link Wordlift_Notice_Service} instance.
131
+     */
132
+    public function __construct( $entity_service, $entity_type_service, $notice_service ) {
133
+
134
+        $this->entity_service      = $entity_service;
135
+        $this->entity_type_service = $entity_type_service;
136
+        $this->notice_service      = $notice_service;
137
+
138
+        $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rating_Service' );
139
+
140
+    }
141
+
142
+    /**
143
+     * Set rating for a given entity.
144
+     *
145
+     * @since 3.3.0
146
+     *
147
+     * @param int $post_id The entity post id.
148
+     *
149
+     * @return array An array representing the rating obj.
150
+     */
151
+    public function set_rating_for( $post_id ) {
152
+
153
+        if ( ! $this->entity_service->is_entity( $post_id ) ) {
154
+            return;
155
+        }
156
+
157
+        // Calculate rating for the given post.
158
+        $rating = $this->calculate_rating_for( $post_id );
159
+
160
+        // Store the rating on db as post meta. Please notice that RATING_RAW_SCORE_META_KEY
161
+        // is saved on a different meta to allow score sorting. Both meta are managed as unique.
162
+        //
163
+        // See https://codex.wordpress.org/Function_Reference/update_post_meta
164
+        update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score'] );
165
+        update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings'] );
166
+
167
+        $this->log->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'] ) );
168
+
169
+        // Finally returns the rating
170
+        return $rating;
171
+    }
172
+
173
+
174
+    /**
175
+     * Get or calculate rating for a given entity
176
+     *
177
+     * @since 3.3.0
178
+     *
179
+     * @param int $post_id      The entity post id.
180
+     * @param     $force_reload $warnings_needed If true, detailed warnings collection is provided with the rating obj.
181
+     *
182
+     * @return array An array representing the rating obj.
183
+     */
184
+    public function get_rating_for( $post_id, $force_reload = false ) {
185
+
186
+        // If forced reload is required or rating is missing.
187
+        if ( $force_reload ) {
188
+            $this->log->trace( "Force rating reload [ post_id :: $post_id ]" );
189
+
190
+            return $this->set_rating_for( $post_id );
191
+        }
192
+
193
+        $current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true );
194
+
195
+        if ( ! is_numeric( $current_raw_score ) ) {
196
+            $this->log->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" );
197
+
198
+            return $this->set_rating_for( $post_id );
199
+        }
200
+
201
+        $current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true );
202
+
203
+        // Finally return score and warnings
204
+        return array(
205
+            'raw_score'           => $current_raw_score,
206
+            'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ),
207
+            'percentage_score'    => $this->convert_raw_score_to_percentage( $current_raw_score ),
208
+            'warnings'            => $current_warnings,
209
+        );
210
+
211
+    }
212
+
213
+    /**
214
+     * Calculate rating for a given entity.
215
+     *
216
+     * Rating depends from following criteria:
217
+     *
218
+     * 1. Is the current entity related to at least 1 post?
219
+     * 2. Is the current entity content post not empty?
220
+     * 3. Is the current entity related to at least 1 entity?
221
+     * 4. Is the entity published?
222
+     * 5. There is a a thumbnail associated to the entity?
223
+     * 6. Has the entity a sameas defined?
224
+     * 7. Are all schema.org required metadata compiled?
225
+     *
226
+     * Each positive check means +1 in terms of rating score.
227
+     *
228
+     * @since 3.3.0
229
+     *
230
+     * @param int $post_id The entity post id.
231
+     *
232
+     * @return array An array representing the rating obj.
233
+     */
234
+    private function calculate_rating_for( $post_id ) {
235
+
236
+        // If it's not an entity, return.
237
+        if ( ! $this->entity_service->is_entity( $post_id ) ) {
238
+            return array();
239
+        }
240
+        // Retrieve the post object.
241
+        $post = get_post( $post_id );
242
+
243
+        // Rating value.
244
+        $score = 0;
245
+
246
+        // Store warning messages.
247
+        $warnings = array();
248
+
249
+        // Is the current entity related to at least 1 post?
250
+        ( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ?
251
+            $score ++ :
252
+            array_push( $warnings, __( 'There are no related posts for the current entity.', 'wordlift' ) );
253
+
254
+        // Is the post content not empty?
255
+        ( ! empty( $post->post_content ) ) ?
256
+            $score ++ :
257
+            array_push( $warnings, __( 'This entity has not description.', 'wordlift' ) );
258
+
259
+        // Is the current entity related to at least 1 entity?
260
+        // Was the current entity already disambiguated?
261
+        ( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ?
262
+            $score ++ :
263
+            array_push( $warnings, __( 'There are no related entities for the current entity.', 'wordlift' ) );
264
+
265
+        // Is the entity published?
266
+        ( 'publish' === get_post_status( $post->ID ) ) ?
267
+            $score ++ :
268
+            array_push( $warnings, __( 'This entity is not published. It will not appear within analysis results.', 'wordlift' ) );
269
+
270
+        // Has a thumbnail?
271
+        ( has_post_thumbnail( $post->ID ) ) ?
272
+            $score ++ :
273
+            array_push( $warnings, __( 'This entity has no featured image yet.', 'wordlift' ) );
274
+
275
+        // Get all post meta keys for the current post
276
+        global $wpdb;
277
+
278
+        $query = $wpdb->prepare(
279
+            "SELECT DISTINCT (meta_key) FROM $wpdb->postmeta  WHERE post_id = %d", $post->ID
280
+        );
281
+
282
+        // Check intersection between available meta keys and expected ones
283
+        // arrays to detect missing values.
284
+        $available_meta_keys = $wpdb->get_col( $query );
285
+
286
+        // If each expected key is contained in available keys array ...
287
+        ( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ?
288
+            $score ++ :
289
+            array_push( $warnings, __( 'There are no sameAs configured for this entity.', 'wordlift' ) );
290
+
291
+        $schema = $this->entity_type_service->get( $post_id );
292
+
293
+        $expected_meta_keys = ( null === $schema['custom_fields'] ) ?
294
+            array() :
295
+            array_keys( $schema['custom_fields'] );
296
+
297
+        $intersection = array_intersect( $expected_meta_keys, $available_meta_keys );
298
+        // If each expected key is contained in available keys array ...
299
+        ( count( $intersection ) === count( $expected_meta_keys ) ) ?
300
+            $score ++ :
301
+            array_push( $warnings, __( 'Schema.org metadata for this entity are not completed.', 'wordlift' ) );
302
+
303
+        // Finally return score and warnings
304
+        return array(
305
+            'raw_score'           => $score,
306
+            'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ),
307
+            'percentage_score'    => $this->convert_raw_score_to_percentage( $score ),
308
+            'warnings'            => $warnings,
309
+        );
310
+
311
+    }
312
+
313
+    /**
314
+     * Get as rating as input and convert in a traffic-light rating
315
+     *
316
+     * @since 3.3.0
317
+     *
318
+     * @param int $score The rating score for a given entity.
319
+     *
320
+     * @return string The input HTML code.
321
+     */
322
+    private function convert_raw_score_to_traffic_light( $score ) {
323
+        // RATING_MAX : $score = 3 : x
324
+        // See http://php.net/manual/en/function.round.php
325
+        $rating = round( ( $score * 3 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
326
+
327
+        // If rating is 0, return 1, otherwise return rating
328
+        return ( 0 == $rating ) ? 1 : $rating;
329
+
330
+    }
331
+
332
+    /**
333
+     * Get as rating as input and convert in a traffic-light rating
334
+     *
335
+     * @since 3.3.0
336
+     *
337
+     * @param int $score The rating score for a given entity.
338
+     *
339
+     * @return string The input HTML code.
340
+     */
341
+    public function convert_raw_score_to_percentage( $score ) {
342
+
343
+        // RATING_MAX : $score = 100 : x
344
+        return round( ( $score * 100 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
345
+    }
346
+
347
+
348
+    /**
349
+     * Add admin notices for the current entity depending on the current rating.
350
+     *
351
+     * @since 3.3.0
352
+     */
353
+    public function in_admin_header() {
354
+
355
+        // Return safely if get_current_screen() is not defined (yet)
356
+        if ( false === function_exists( 'get_current_screen' ) ) {
357
+            return;
358
+        }
359
+
360
+        $screen = get_current_screen();
361
+        // If there is any valid screen nothing to do
362
+        if ( null === $screen ) {
363
+            return;
364
+        }
365
+
366
+        // If you're not in the entity post edit page, return.
367
+        if ( Wordlift_Entity_Service::TYPE_NAME !== $screen->id ) {
368
+            return;
369
+        }
370
+        // Retrieve the current global post
371
+        global $post;
372
+        // If it's not an entity, return.
373
+        if ( ! $this->entity_service->is_entity( $post->ID ) ) {
374
+            return;
375
+        }
376
+        // Retrieve an updated rating for the current entity
377
+        $rating = $this->get_rating_for( $post->ID, true );
378
+
379
+        // If there is at least 1 warning
380
+        if ( isset( $rating['warnings'] ) && 0 < count( $rating['warnings'] ) ) {
381
+            // TODO - Pass Wordlift_Notice_Service trough the service constructor
382
+            $this->notice_service->add_suggestion( $rating['warnings'] );
383
+        }
384
+
385
+    }
386 386
 
387 387
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -63 removed lines patch added patch discarded remove patch
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
 	 * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance.
130 130
 	 * @param \Wordlift_Notice_Service      $notice_service      A {@link Wordlift_Notice_Service} instance.
131 131
 	 */
132
-	public function __construct( $entity_service, $entity_type_service, $notice_service ) {
132
+	public function __construct($entity_service, $entity_type_service, $notice_service) {
133 133
 
134 134
 		$this->entity_service      = $entity_service;
135 135
 		$this->entity_type_service = $entity_type_service;
136 136
 		$this->notice_service      = $notice_service;
137 137
 
138
-		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Rating_Service' );
138
+		$this->log = Wordlift_Log_Service::get_logger('Wordlift_Rating_Service');
139 139
 
140 140
 	}
141 141
 
@@ -148,23 +148,23 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @return array An array representing the rating obj.
150 150
 	 */
151
-	public function set_rating_for( $post_id ) {
151
+	public function set_rating_for($post_id) {
152 152
 
153
-		if ( ! $this->entity_service->is_entity( $post_id ) ) {
153
+		if ( ! $this->entity_service->is_entity($post_id)) {
154 154
 			return;
155 155
 		}
156 156
 
157 157
 		// Calculate rating for the given post.
158
-		$rating = $this->calculate_rating_for( $post_id );
158
+		$rating = $this->calculate_rating_for($post_id);
159 159
 
160 160
 		// Store the rating on db as post meta. Please notice that RATING_RAW_SCORE_META_KEY
161 161
 		// is saved on a different meta to allow score sorting. Both meta are managed as unique.
162 162
 		//
163 163
 		// See https://codex.wordpress.org/Function_Reference/update_post_meta
164
-		update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score'] );
165
-		update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings'] );
164
+		update_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score']);
165
+		update_post_meta($post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings']);
166 166
 
167
-		$this->log->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'] ) );
167
+		$this->log->trace(sprintf("Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score']));
168 168
 
169 169
 		// Finally returns the rating
170 170
 		return $rating;
@@ -181,30 +181,30 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @return array An array representing the rating obj.
183 183
 	 */
184
-	public function get_rating_for( $post_id, $force_reload = false ) {
184
+	public function get_rating_for($post_id, $force_reload = false) {
185 185
 
186 186
 		// If forced reload is required or rating is missing.
187
-		if ( $force_reload ) {
188
-			$this->log->trace( "Force rating reload [ post_id :: $post_id ]" );
187
+		if ($force_reload) {
188
+			$this->log->trace("Force rating reload [ post_id :: $post_id ]");
189 189
 
190
-			return $this->set_rating_for( $post_id );
190
+			return $this->set_rating_for($post_id);
191 191
 		}
192 192
 
193
-		$current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true );
193
+		$current_raw_score = get_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, true);
194 194
 
195
-		if ( ! is_numeric( $current_raw_score ) ) {
196
-			$this->log->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" );
195
+		if ( ! is_numeric($current_raw_score)) {
196
+			$this->log->trace("Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]");
197 197
 
198
-			return $this->set_rating_for( $post_id );
198
+			return $this->set_rating_for($post_id);
199 199
 		}
200 200
 
201
-		$current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true );
201
+		$current_warnings = get_post_meta($post_id, self::RATING_WARNINGS_META_KEY, true);
202 202
 
203 203
 		// Finally return score and warnings
204 204
 		return array(
205 205
 			'raw_score'           => $current_raw_score,
206
-			'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ),
207
-			'percentage_score'    => $this->convert_raw_score_to_percentage( $current_raw_score ),
206
+			'traffic_light_score' => $this->convert_raw_score_to_traffic_light($current_raw_score),
207
+			'percentage_score'    => $this->convert_raw_score_to_percentage($current_raw_score),
208 208
 			'warnings'            => $current_warnings,
209 209
 		);
210 210
 
@@ -231,14 +231,14 @@  discard block
 block discarded – undo
231 231
 	 *
232 232
 	 * @return array An array representing the rating obj.
233 233
 	 */
234
-	private function calculate_rating_for( $post_id ) {
234
+	private function calculate_rating_for($post_id) {
235 235
 
236 236
 		// If it's not an entity, return.
237
-		if ( ! $this->entity_service->is_entity( $post_id ) ) {
237
+		if ( ! $this->entity_service->is_entity($post_id)) {
238 238
 			return array();
239 239
 		}
240 240
 		// Retrieve the post object.
241
-		$post = get_post( $post_id );
241
+		$post = get_post($post_id);
242 242
 
243 243
 		// Rating value.
244 244
 		$score = 0;
@@ -247,30 +247,25 @@  discard block
 block discarded – undo
247 247
 		$warnings = array();
248 248
 
249 249
 		// Is the current entity related to at least 1 post?
250
-		( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ?
251
-			$score ++ :
252
-			array_push( $warnings, __( 'There are no related posts for the current entity.', 'wordlift' ) );
250
+		(0 < count(wl_core_get_related_post_ids($post->ID))) ?
251
+			$score++ : array_push($warnings, __('There are no related posts for the current entity.', 'wordlift'));
253 252
 
254 253
 		// Is the post content not empty?
255
-		( ! empty( $post->post_content ) ) ?
256
-			$score ++ :
257
-			array_push( $warnings, __( 'This entity has not description.', 'wordlift' ) );
254
+		( ! empty($post->post_content)) ?
255
+			$score++ : array_push($warnings, __('This entity has not description.', 'wordlift'));
258 256
 
259 257
 		// Is the current entity related to at least 1 entity?
260 258
 		// Was the current entity already disambiguated?
261
-		( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ?
262
-			$score ++ :
263
-			array_push( $warnings, __( 'There are no related entities for the current entity.', 'wordlift' ) );
259
+		(0 < count(wl_core_get_related_entity_ids($post->ID))) ?
260
+			$score++ : array_push($warnings, __('There are no related entities for the current entity.', 'wordlift'));
264 261
 
265 262
 		// Is the entity published?
266
-		( 'publish' === get_post_status( $post->ID ) ) ?
267
-			$score ++ :
268
-			array_push( $warnings, __( 'This entity is not published. It will not appear within analysis results.', 'wordlift' ) );
263
+		('publish' === get_post_status($post->ID)) ?
264
+			$score++ : array_push($warnings, __('This entity is not published. It will not appear within analysis results.', 'wordlift'));
269 265
 
270 266
 		// Has a thumbnail?
271
-		( has_post_thumbnail( $post->ID ) ) ?
272
-			$score ++ :
273
-			array_push( $warnings, __( 'This entity has no featured image yet.', 'wordlift' ) );
267
+		(has_post_thumbnail($post->ID)) ?
268
+			$score++ : array_push($warnings, __('This entity has no featured image yet.', 'wordlift'));
274 269
 
275 270
 		// Get all post meta keys for the current post
276 271
 		global $wpdb;
@@ -281,30 +276,27 @@  discard block
 block discarded – undo
281 276
 
282 277
 		// Check intersection between available meta keys and expected ones
283 278
 		// arrays to detect missing values.
284
-		$available_meta_keys = $wpdb->get_col( $query );
279
+		$available_meta_keys = $wpdb->get_col($query);
285 280
 
286 281
 		// If each expected key is contained in available keys array ...
287
-		( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ?
288
-			$score ++ :
289
-			array_push( $warnings, __( 'There are no sameAs configured for this entity.', 'wordlift' ) );
282
+		(in_array(Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys)) ?
283
+			$score++ : array_push($warnings, __('There are no sameAs configured for this entity.', 'wordlift'));
290 284
 
291
-		$schema = $this->entity_type_service->get( $post_id );
285
+		$schema = $this->entity_type_service->get($post_id);
292 286
 
293
-		$expected_meta_keys = ( null === $schema['custom_fields'] ) ?
294
-			array() :
295
-			array_keys( $schema['custom_fields'] );
287
+		$expected_meta_keys = (null === $schema['custom_fields']) ?
288
+			array() : array_keys($schema['custom_fields']);
296 289
 
297
-		$intersection = array_intersect( $expected_meta_keys, $available_meta_keys );
290
+		$intersection = array_intersect($expected_meta_keys, $available_meta_keys);
298 291
 		// If each expected key is contained in available keys array ...
299
-		( count( $intersection ) === count( $expected_meta_keys ) ) ?
300
-			$score ++ :
301
-			array_push( $warnings, __( 'Schema.org metadata for this entity are not completed.', 'wordlift' ) );
292
+		(count($intersection) === count($expected_meta_keys)) ?
293
+			$score++ : array_push($warnings, __('Schema.org metadata for this entity are not completed.', 'wordlift'));
302 294
 
303 295
 		// Finally return score and warnings
304 296
 		return array(
305 297
 			'raw_score'           => $score,
306
-			'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ),
307
-			'percentage_score'    => $this->convert_raw_score_to_percentage( $score ),
298
+			'traffic_light_score' => $this->convert_raw_score_to_traffic_light($score),
299
+			'percentage_score'    => $this->convert_raw_score_to_percentage($score),
308 300
 			'warnings'            => $warnings,
309 301
 		);
310 302
 
@@ -319,13 +311,13 @@  discard block
 block discarded – undo
319 311
 	 *
320 312
 	 * @return string The input HTML code.
321 313
 	 */
322
-	private function convert_raw_score_to_traffic_light( $score ) {
314
+	private function convert_raw_score_to_traffic_light($score) {
323 315
 		// RATING_MAX : $score = 3 : x
324 316
 		// See http://php.net/manual/en/function.round.php
325
-		$rating = round( ( $score * 3 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
317
+		$rating = round(($score * 3) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP);
326 318
 
327 319
 		// If rating is 0, return 1, otherwise return rating
328
-		return ( 0 == $rating ) ? 1 : $rating;
320
+		return (0 == $rating) ? 1 : $rating;
329 321
 
330 322
 	}
331 323
 
@@ -338,10 +330,10 @@  discard block
 block discarded – undo
338 330
 	 *
339 331
 	 * @return string The input HTML code.
340 332
 	 */
341
-	public function convert_raw_score_to_percentage( $score ) {
333
+	public function convert_raw_score_to_percentage($score) {
342 334
 
343 335
 		// RATING_MAX : $score = 100 : x
344
-		return round( ( $score * 100 ) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP );
336
+		return round(($score * 100) / self::RATING_MAX, 0, PHP_ROUND_HALF_UP);
345 337
 	}
346 338
 
347 339
 
@@ -353,33 +345,33 @@  discard block
 block discarded – undo
353 345
 	public function in_admin_header() {
354 346
 
355 347
 		// Return safely if get_current_screen() is not defined (yet)
356
-		if ( false === function_exists( 'get_current_screen' ) ) {
348
+		if (false === function_exists('get_current_screen')) {
357 349
 			return;
358 350
 		}
359 351
 
360 352
 		$screen = get_current_screen();
361 353
 		// If there is any valid screen nothing to do
362
-		if ( null === $screen ) {
354
+		if (null === $screen) {
363 355
 			return;
364 356
 		}
365 357
 
366 358
 		// If you're not in the entity post edit page, return.
367
-		if ( Wordlift_Entity_Service::TYPE_NAME !== $screen->id ) {
359
+		if (Wordlift_Entity_Service::TYPE_NAME !== $screen->id) {
368 360
 			return;
369 361
 		}
370 362
 		// Retrieve the current global post
371 363
 		global $post;
372 364
 		// If it's not an entity, return.
373
-		if ( ! $this->entity_service->is_entity( $post->ID ) ) {
365
+		if ( ! $this->entity_service->is_entity($post->ID)) {
374 366
 			return;
375 367
 		}
376 368
 		// Retrieve an updated rating for the current entity
377
-		$rating = $this->get_rating_for( $post->ID, true );
369
+		$rating = $this->get_rating_for($post->ID, true);
378 370
 
379 371
 		// If there is at least 1 warning
380
-		if ( isset( $rating['warnings'] ) && 0 < count( $rating['warnings'] ) ) {
372
+		if (isset($rating['warnings']) && 0 < count($rating['warnings'])) {
381 373
 			// TODO - Pass Wordlift_Notice_Service trough the service constructor
382
-			$this->notice_service->add_suggestion( $rating['warnings'] );
374
+			$this->notice_service->add_suggestion($rating['warnings']);
383 375
 		}
384 376
 
385 377
 	}
Please login to merge, or discard this patch.
src/public/class-wordlift-seo-service.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -21,66 +21,66 @@
 block discarded – undo
21 21
  */
22 22
 class Wordlift_Seo_Service {
23 23
 
24
-	/**
25
-	 * @inheritdoc
26
-	 */
27
-	function __construct() {
24
+    /**
25
+     * @inheritdoc
26
+     */
27
+    function __construct() {
28 28
 
29
-		// If we are not on the admin, run the get_term filter for entity type terms.
30
-		add_filter( 'get_wl_entity_type', array(
31
-			$this,
32
-			'get_wl_entity_type',
33
-		), 10, 2 );
29
+        // If we are not on the admin, run the get_term filter for entity type terms.
30
+        add_filter( 'get_wl_entity_type', array(
31
+            $this,
32
+            'get_wl_entity_type',
33
+        ), 10, 2 );
34 34
 
35
-	}
35
+    }
36 36
 
37
-	/**
38
-	 * Filter the entity term object, and when not in admin context replace title
39
-	 * and description with whatever was set in the entity settings page.
40
-	 *
41
-	 * @since    3.11
42
-	 *
43
-	 * @param WP_Term $term     The term to filters.
44
-	 * @param string  $taxonomy The taxonomy name.
45
-	 *
46
-	 * @return WP_Term The {@link WP_Term} with fields changed.
47
-	 */
48
-	function get_wl_entity_type( $term, $taxonomy ) {
37
+    /**
38
+     * Filter the entity term object, and when not in admin context replace title
39
+     * and description with whatever was set in the entity settings page.
40
+     *
41
+     * @since    3.11
42
+     *
43
+     * @param WP_Term $term     The term to filters.
44
+     * @param string  $taxonomy The taxonomy name.
45
+     *
46
+     * @return WP_Term The {@link WP_Term} with fields changed.
47
+     */
48
+    function get_wl_entity_type( $term, $taxonomy ) {
49 49
 
50
-		// Do nothing when in admin.
51
-		if ( is_admin() ) {
52
-			return $term;
53
-		}
50
+        // Do nothing when in admin.
51
+        if ( is_admin() ) {
52
+            return $term;
53
+        }
54 54
 
55
-		// Get the terms' settings.
56
-		$entity_settings = get_option( 'wl_entity_type_settings', array() );
55
+        // Get the terms' settings.
56
+        $entity_settings = get_option( 'wl_entity_type_settings', array() );
57 57
 
58
-		// If we have no settings for the specified term, then return the original
59
-		// term.
60
-		if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
58
+        // If we have no settings for the specified term, then return the original
59
+        // term.
60
+        if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
61 61
 
62
-			return $term;
63
-		}
62
+            return $term;
63
+        }
64 64
 
65
-		// Get the settings for the specified term.
66
-		$settings = $entity_settings[ $term->term_id ];
65
+        // Get the settings for the specified term.
66
+        $settings = $entity_settings[ $term->term_id ];
67 67
 
68
-		// Update the name.
69
-		if ( ! empty( $settings['title'] ) ) {
68
+        // Update the name.
69
+        if ( ! empty( $settings['title'] ) ) {
70 70
 
71
-			$term->name = $settings['title'];
71
+            $term->name = $settings['title'];
72 72
 
73
-		}
73
+        }
74 74
 
75
-		// Update the description.
76
-		if ( ! empty( $settings['description'] ) ) {
75
+        // Update the description.
76
+        if ( ! empty( $settings['description'] ) ) {
77 77
 
78
-			$term->description = $settings['description'];
78
+            $term->description = $settings['description'];
79 79
 
80
-		}
80
+        }
81 81
 
82
-		// Return the updated term.
83
-		return $term;
84
-	}
82
+        // Return the updated term.
83
+        return $term;
84
+    }
85 85
 
86 86
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@  discard block
 block discarded – undo
27 27
 	function __construct() {
28 28
 
29 29
 		// If we are not on the admin, run the get_term filter for entity type terms.
30
-		add_filter( 'get_wl_entity_type', array(
30
+		add_filter('get_wl_entity_type', array(
31 31
 			$this,
32 32
 			'get_wl_entity_type',
33
-		), 10, 2 );
33
+		), 10, 2);
34 34
 
35 35
 	}
36 36
 
@@ -45,35 +45,35 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @return WP_Term The {@link WP_Term} with fields changed.
47 47
 	 */
48
-	function get_wl_entity_type( $term, $taxonomy ) {
48
+	function get_wl_entity_type($term, $taxonomy) {
49 49
 
50 50
 		// Do nothing when in admin.
51
-		if ( is_admin() ) {
51
+		if (is_admin()) {
52 52
 			return $term;
53 53
 		}
54 54
 
55 55
 		// Get the terms' settings.
56
-		$entity_settings = get_option( 'wl_entity_type_settings', array() );
56
+		$entity_settings = get_option('wl_entity_type_settings', array());
57 57
 
58 58
 		// If we have no settings for the specified term, then return the original
59 59
 		// term.
60
-		if ( ! isset( $entity_settings[ $term->term_id ] ) ) {
60
+		if ( ! isset($entity_settings[$term->term_id])) {
61 61
 
62 62
 			return $term;
63 63
 		}
64 64
 
65 65
 		// Get the settings for the specified term.
66
-		$settings = $entity_settings[ $term->term_id ];
66
+		$settings = $entity_settings[$term->term_id];
67 67
 
68 68
 		// Update the name.
69
-		if ( ! empty( $settings['title'] ) ) {
69
+		if ( ! empty($settings['title'])) {
70 70
 
71 71
 			$term->name = $settings['title'];
72 72
 
73 73
 		}
74 74
 
75 75
 		// Update the description.
76
-		if ( ! empty( $settings['description'] ) ) {
76
+		if ( ! empty($settings['description'])) {
77 77
 
78 78
 			$term->description = $settings['description'];
79 79
 
Please login to merge, or discard this patch.
src/public/class-wordlift-widget.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,26 +16,26 @@
 block discarded – undo
16 16
  */
17 17
 abstract class Wordlift_Widget extends WP_Widget {
18 18
 
19
-	/**
20
-	 * @inheritdoc
21
-	 */
22
-	public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) {
23
-		parent::__construct( $id_base, $name, $widget_options, $control_options );
19
+    /**
20
+     * @inheritdoc
21
+     */
22
+    public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) {
23
+        parent::__construct( $id_base, $name, $widget_options, $control_options );
24 24
 
25
-		// Initialize the Related Entities Cloud Widget.
26
-		add_action( 'widgets_init', array( $this, 'widget_init' ) );
25
+        // Initialize the Related Entities Cloud Widget.
26
+        add_action( 'widgets_init', array( $this, 'widget_init' ) );
27 27
 
28
-	}
28
+    }
29 29
 
30
-	/**
31
-	 * Register the related entities cloud widget
32
-	 *
33
-	 * @since 3.11.0
34
-	 */
35
-	public function widget_init() {
30
+    /**
31
+     * Register the related entities cloud widget
32
+     *
33
+     * @since 3.11.0
34
+     */
35
+    public function widget_init() {
36 36
 
37
-		register_widget( get_class( $this ) );
37
+        register_widget( get_class( $this ) );
38 38
 
39
-	}
39
+    }
40 40
 
41 41
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
 	/**
20 20
 	 * @inheritdoc
21 21
 	 */
22
-	public function __construct( $id_base, $name, array $widget_options = array(), array $control_options = array() ) {
23
-		parent::__construct( $id_base, $name, $widget_options, $control_options );
22
+	public function __construct($id_base, $name, array $widget_options = array(), array $control_options = array()) {
23
+		parent::__construct($id_base, $name, $widget_options, $control_options);
24 24
 
25 25
 		// Initialize the Related Entities Cloud Widget.
26
-		add_action( 'widgets_init', array( $this, 'widget_init' ) );
26
+		add_action('widgets_init', array($this, 'widget_init'));
27 27
 
28 28
 	}
29 29
 
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 */
35 35
 	public function widget_init() {
36 36
 
37
-		register_widget( get_class( $this ) );
37
+		register_widget(get_class($this));
38 38
 
39 39
 	}
40 40
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-publisher-ajax-adapter.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -16,55 +16,55 @@
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Publisher_Ajax_Adapter {
18 18
 
19
-	/**
20
-	 * The {@link Wordlift_Publisher_Service} instance.
21
-	 *
22
-	 * @since  3.11.0
23
-	 * @access private
24
-	 * @var Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
25
-	 */
26
-	private $publisher_service;
19
+    /**
20
+     * The {@link Wordlift_Publisher_Service} instance.
21
+     *
22
+     * @since  3.11.0
23
+     * @access private
24
+     * @var Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
25
+     */
26
+    private $publisher_service;
27 27
 
28
-	/**
29
-	 * Create a {@link Wordlift_Publisher_Ajax_Adapter} instance.
30
-	 *
31
-	 * @since 3.11.0
32
-	 *
33
-	 * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
34
-	 */
35
-	function __construct( $publisher_service ) {
28
+    /**
29
+     * Create a {@link Wordlift_Publisher_Ajax_Adapter} instance.
30
+     *
31
+     * @since 3.11.0
32
+     *
33
+     * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
34
+     */
35
+    function __construct( $publisher_service ) {
36 36
 
37
-		$this->publisher_service = $publisher_service;
37
+        $this->publisher_service = $publisher_service;
38 38
 
39
-	}
39
+    }
40 40
 
41
-	/**
42
-	 * The publisher AJAX action. This function is hook to the `wl_publisher`
43
-	 * action.
44
-	 *
45
-	 * @since 3.11.0
46
-	 */
47
-	public function publisher() {
41
+    /**
42
+     * The publisher AJAX action. This function is hook to the `wl_publisher`
43
+     * action.
44
+     *
45
+     * @since 3.11.0
46
+     */
47
+    public function publisher() {
48 48
 
49
-		// Ensure we don't have garbage before us.
50
-		ob_clean();
49
+        // Ensure we don't have garbage before us.
50
+        ob_clean();
51 51
 
52
-		// Check if the current user can `manage_options`.
53
-		if ( ! current_user_can( 'manage_options' ) ) {
54
-			wp_send_json_error( 'Access denied.' );
55
-		}
52
+        // Check if the current user can `manage_options`.
53
+        if ( ! current_user_can( 'manage_options' ) ) {
54
+            wp_send_json_error( 'Access denied.' );
55
+        }
56 56
 
57
-		// No actual search parameter was passed, bail out.
58
-		if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) {
59
-			wp_send_json_error( 'The q parameter is required.' );
60
-		}
57
+        // No actual search parameter was passed, bail out.
58
+        if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) {
59
+            wp_send_json_error( 'The q parameter is required.' );
60
+        }
61 61
 
62
-		// Get the response.
63
-		$response = $this->publisher_service->query( $_POST['q'] );
62
+        // Get the response.
63
+        $response = $this->publisher_service->query( $_POST['q'] );
64 64
 
65
-		// Finally output the response.
66
-		wp_send_json_success( $response );
65
+        // Finally output the response.
66
+        wp_send_json_success( $response );
67 67
 
68
-	}
68
+    }
69 69
 
70 70
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 *
33 33
 	 * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance.
34 34
 	 */
35
-	function __construct( $publisher_service ) {
35
+	function __construct($publisher_service) {
36 36
 
37 37
 		$this->publisher_service = $publisher_service;
38 38
 
@@ -50,20 +50,20 @@  discard block
 block discarded – undo
50 50
 		ob_clean();
51 51
 
52 52
 		// Check if the current user can `manage_options`.
53
-		if ( ! current_user_can( 'manage_options' ) ) {
54
-			wp_send_json_error( 'Access denied.' );
53
+		if ( ! current_user_can('manage_options')) {
54
+			wp_send_json_error('Access denied.');
55 55
 		}
56 56
 
57 57
 		// No actual search parameter was passed, bail out.
58
-		if ( ! isset( $_POST['q'] ) || empty( $_POST['q'] ) ) {
59
-			wp_send_json_error( 'The q parameter is required.' );
58
+		if ( ! isset($_POST['q']) || empty($_POST['q'])) {
59
+			wp_send_json_error('The q parameter is required.');
60 60
 		}
61 61
 
62 62
 		// Get the response.
63
-		$response = $this->publisher_service->query( $_POST['q'] );
63
+		$response = $this->publisher_service->query($_POST['q']);
64 64
 
65 65
 		// Finally output the response.
66
-		wp_send_json_success( $response );
66
+		wp_send_json_success($response);
67 67
 
68 68
 	}
69 69
 
Please login to merge, or discard this patch.
src/includes/class-wordlift-category-taxonomy-service.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -18,74 +18,74 @@
 block discarded – undo
18 18
  */
19 19
 class Wordlift_Category_Taxonomy_Service {
20 20
 
21
-	/**
22
-	 * The {@link Wordlift_Entity_Post_Type_Service} instance.
23
-	 *
24
-	 * @since  3.11.0
25
-	 * @access private
26
-	 * @var \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
27
-	 */
28
-	private $entity_post_type_service;
21
+    /**
22
+     * The {@link Wordlift_Entity_Post_Type_Service} instance.
23
+     *
24
+     * @since  3.11.0
25
+     * @access private
26
+     * @var \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
27
+     */
28
+    private $entity_post_type_service;
29 29
 
30
-	/**
31
-	 * Create a {@link Wordlift_Category_Taxonomy_Service} instance.
32
-	 *
33
-	 * @since 3.11.0
34
-	 *
35
-	 * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
36
-	 */
37
-	function __construct( $entity_post_type_service ) {
30
+    /**
31
+     * Create a {@link Wordlift_Category_Taxonomy_Service} instance.
32
+     *
33
+     * @since 3.11.0
34
+     *
35
+     * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
36
+     */
37
+    function __construct( $entity_post_type_service ) {
38 38
 
39
-		$this->entity_post_type_service = $entity_post_type_service;
39
+        $this->entity_post_type_service = $entity_post_type_service;
40 40
 
41
-	}
41
+    }
42 42
 
43
-	/**
44
-	 * Set the entity post types as one to be included in archive pages.
45
-	 *
46
-	 * In order to have entities show up in standard WP categories (Posts categories)
47
-	 * we configure the `entity` post type, but we also need to alter the main
48
-	 * WP query (which by default queries posts only) to include the `entities`.
49
-	 *
50
-	 * @since 3.11.0
51
-	 *
52
-	 * @param WP_Query $query WP's {@link WP_Query} instance.
53
-	 */
54
-	public function pre_get_posts( $query ) {
43
+    /**
44
+     * Set the entity post types as one to be included in archive pages.
45
+     *
46
+     * In order to have entities show up in standard WP categories (Posts categories)
47
+     * we configure the `entity` post type, but we also need to alter the main
48
+     * WP query (which by default queries posts only) to include the `entities`.
49
+     *
50
+     * @since 3.11.0
51
+     *
52
+     * @param WP_Query $query WP's {@link WP_Query} instance.
53
+     */
54
+    public function pre_get_posts( $query ) {
55 55
 
56
-		// Only for the main query, avoid problems with widgets and what not.
57
-		if ( ! $query->is_main_query() ) {
58
-			return;
59
-		}
56
+        // Only for the main query, avoid problems with widgets and what not.
57
+        if ( ! $query->is_main_query() ) {
58
+            return;
59
+        }
60 60
 
61
-		// We don't want to alter the query if we're in the admin UI, if this is
62
-		// not a category query, or if the `suppress_filters` is set.
63
-		//
64
-		// Note that it is unlikely for `suppress_filter` to be set on the front
65
-		// end, but let's be safe if it is set the calling code assumes no
66
-		// modifications of queries.
67
-		//
68
-		// is_admin is needed, otherwise category based post filters will show
69
-		// both types and at the current release (4.7) it causes PHP errors.
70
-		if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) {
71
-			return;
72
-		}
61
+        // We don't want to alter the query if we're in the admin UI, if this is
62
+        // not a category query, or if the `suppress_filters` is set.
63
+        //
64
+        // Note that it is unlikely for `suppress_filter` to be set on the front
65
+        // end, but let's be safe if it is set the calling code assumes no
66
+        // modifications of queries.
67
+        //
68
+        // is_admin is needed, otherwise category based post filters will show
69
+        // both types and at the current release (4.7) it causes PHP errors.
70
+        if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) {
71
+            return;
72
+        }
73 73
 
74
-		// Check the current post types, maybe the category archive pages
75
-		// are already associated with other post types.
76
-		//
77
-		// If `post_type` isn't set, WP assumes `post` by default.
78
-		$post_types = (array) ( $query->get( 'post_type' ) ?: 'post' );
74
+        // Check the current post types, maybe the category archive pages
75
+        // are already associated with other post types.
76
+        //
77
+        // If `post_type` isn't set, WP assumes `post` by default.
78
+        $post_types = (array) ( $query->get( 'post_type' ) ?: 'post' );
79 79
 
80
-		// Add the entities post type only if the post post type is used in the query
81
-		// since we only want `entities` to appear alongside posts.
82
-		if ( in_array( 'post', $post_types ) ) {
83
-			$post_types[] = $this->entity_post_type_service->get_post_type();
84
-		}
80
+        // Add the entities post type only if the post post type is used in the query
81
+        // since we only want `entities` to appear alongside posts.
82
+        if ( in_array( 'post', $post_types ) ) {
83
+            $post_types[] = $this->entity_post_type_service->get_post_type();
84
+        }
85 85
 
86
-		// Update the query post types.
87
-		$query->set( 'post_type', $post_types );
86
+        // Update the query post types.
87
+        $query->set( 'post_type', $post_types );
88 88
 
89
-	}
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param \Wordlift_Entity_Post_Type_Service $entity_post_type_service The {@link Wordlift_Entity_Post_Type_Service} instance.
36 36
 	 */
37
-	function __construct( $entity_post_type_service ) {
37
+	function __construct($entity_post_type_service) {
38 38
 
39 39
 		$this->entity_post_type_service = $entity_post_type_service;
40 40
 
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 *
52 52
 	 * @param WP_Query $query WP's {@link WP_Query} instance.
53 53
 	 */
54
-	public function pre_get_posts( $query ) {
54
+	public function pre_get_posts($query) {
55 55
 
56 56
 		// Only for the main query, avoid problems with widgets and what not.
57
-		if ( ! $query->is_main_query() ) {
57
+		if ( ! $query->is_main_query()) {
58 58
 			return;
59 59
 		}
60 60
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 		//
68 68
 		// is_admin is needed, otherwise category based post filters will show
69 69
 		// both types and at the current release (4.7) it causes PHP errors.
70
-		if ( is_admin() || ! is_category() || ! empty( $query->query_vars['suppress_filters'] ) ) {
70
+		if (is_admin() || ! is_category() || ! empty($query->query_vars['suppress_filters'])) {
71 71
 			return;
72 72
 		}
73 73
 
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
 		// are already associated with other post types.
76 76
 		//
77 77
 		// If `post_type` isn't set, WP assumes `post` by default.
78
-		$post_types = (array) ( $query->get( 'post_type' ) ?: 'post' );
78
+		$post_types = (array) ($query->get('post_type') ?: 'post');
79 79
 
80 80
 		// Add the entities post type only if the post post type is used in the query
81 81
 		// since we only want `entities` to appear alongside posts.
82
-		if ( in_array( 'post', $post_types ) ) {
82
+		if (in_array('post', $post_types)) {
83 83
 			$post_types[] = $this->entity_post_type_service->get_post_type();
84 84
 		}
85 85
 
86 86
 		// Update the query post types.
87
-		$query->set( 'post_type', $post_types );
87
+		$query->set('post_type', $post_types);
88 88
 
89 89
 	}
90 90
 
Please login to merge, or discard this patch.
src/admin/partials/wordlift-admin-entity-type-settings.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 if ( ! defined( 'ABSPATH' ) ) {
15
-	exit;
15
+    exit;
16 16
 }
17 17
 
18 18
 $term = get_term( $term_id, 'wl_entity_type' );
19 19
 
20 20
 $term_settings = ! is_null( $settings ) ? $settings : array(
21
-	'title'       => '',
22
-	'description' => '',
21
+    'title'       => '',
22
+    'description' => '',
23 23
 );
24 24
 
25 25
 ?>
@@ -37,32 +37,32 @@  discard block
 block discarded – undo
37 37
 			<tr class="form-field form-required term-name-wrap">
38 38
 				<th scope="row">
39 39
 					<label><?php
40
-						esc_html_e( 'Name', 'wordlift' ); ?></label>
40
+                        esc_html_e( 'Name', 'wordlift' ); ?></label>
41 41
 				</th>
42 42
 				<td><?php
43
-					echo esc_html( $term->name ) ?></td>
43
+                    echo esc_html( $term->name ) ?></td>
44 44
 			</tr>
45 45
 			<tr class="form-field form-required term-name-wrap">
46 46
 				<th scope="row">
47 47
 					<label for="title"><?php
48
-						esc_html_e( 'Title', 'wordlift' ); ?></label>
48
+                        esc_html_e( 'Title', 'wordlift' ); ?></label>
49 49
 				</th>
50 50
 				<td><input name="title" id="title" type="text"
51 51
 				           value="<?php echo esc_attr( $term_settings['title'] ) ?>"
52 52
 				           size="40" />
53 53
 					<p class="description"><?php
54
-						esc_html_e( 'The HTML title to be used in the entity type archive page.', 'wordlift' ); ?></p>
54
+                        esc_html_e( 'The HTML title to be used in the entity type archive page.', 'wordlift' ); ?></p>
55 55
 				</td>
56 56
 			</tr>
57 57
 			<tr class="form-field term-description-wrap">
58 58
 				<th scope="row"><label for="description"><?php
59
-						esc_html_e( 'Description', 'wordlift' ); ?></label>
59
+                        esc_html_e( 'Description', 'wordlift' ); ?></label>
60 60
 				</th>
61 61
 				<td><textarea name="description" id="description" rows="5"
62 62
 				              cols="50" class="large-text"><?php
63
-						echo esc_html( $term_settings['description'] ) ?></textarea>
63
+                        echo esc_html( $term_settings['description'] ) ?></textarea>
64 64
 					<p class="description"><?php
65
-						esc_html_e( 'The description to be used in the entity type archive page.', 'wordlift' ); ?></p>
65
+                        esc_html_e( 'The description to be used in the entity type archive page.', 'wordlift' ); ?></p>
66 66
 				</td>
67 67
 			</tr>
68 68
 		</table>
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -11,61 +11,61 @@
 block discarded – undo
11 11
  *
12 12
  */
13 13
 
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
18
-$term = get_term( $term_id, 'wl_entity_type' );
18
+$term = get_term($term_id, 'wl_entity_type');
19 19
 
20
-$term_settings = ! is_null( $settings ) ? $settings : array(
20
+$term_settings = ! is_null($settings) ? $settings : array(
21 21
 	'title'       => '',
22 22
 	'description' => '',
23 23
 );
24 24
 
25 25
 ?>
26 26
 <div class="wrap">
27
-	<h1><?php esc_html_e( 'Edit Entity Type', 'wordlift' ) ?></h1>
27
+	<h1><?php esc_html_e('Edit Entity Type', 'wordlift') ?></h1>
28 28
 
29 29
 	<form name="edittag" id="edittag" method="post"
30
-	      action="<?php echo admin_url( 'admin.php?page=wl_entity_type_settings' ) ?>"
30
+	      action="<?php echo admin_url('admin.php?page=wl_entity_type_settings') ?>"
31 31
 	      class="validate">
32 32
 		<input type="hidden" name="tag_ID"
33
-		       value="<?php echo esc_attr( $term_id ) ?>" />
33
+		       value="<?php echo esc_attr($term_id) ?>" />
34 34
 		<input type="hidden" name="action" value="wl_edit_entity_type_term" />
35
-		<?php wp_nonce_field( 'update-entity_type_term_' . $term_id ); ?>
35
+		<?php wp_nonce_field('update-entity_type_term_'.$term_id); ?>
36 36
 		<table class="form-table">
37 37
 			<tr class="form-field form-required term-name-wrap">
38 38
 				<th scope="row">
39 39
 					<label><?php
40
-						esc_html_e( 'Name', 'wordlift' ); ?></label>
40
+						esc_html_e('Name', 'wordlift'); ?></label>
41 41
 				</th>
42 42
 				<td><?php
43
-					echo esc_html( $term->name ) ?></td>
43
+					echo esc_html($term->name) ?></td>
44 44
 			</tr>
45 45
 			<tr class="form-field form-required term-name-wrap">
46 46
 				<th scope="row">
47 47
 					<label for="title"><?php
48
-						esc_html_e( 'Title', 'wordlift' ); ?></label>
48
+						esc_html_e('Title', 'wordlift'); ?></label>
49 49
 				</th>
50 50
 				<td><input name="title" id="title" type="text"
51
-				           value="<?php echo esc_attr( $term_settings['title'] ) ?>"
51
+				           value="<?php echo esc_attr($term_settings['title']) ?>"
52 52
 				           size="40" />
53 53
 					<p class="description"><?php
54
-						esc_html_e( 'The HTML title to be used in the entity type archive page.', 'wordlift' ); ?></p>
54
+						esc_html_e('The HTML title to be used in the entity type archive page.', 'wordlift'); ?></p>
55 55
 				</td>
56 56
 			</tr>
57 57
 			<tr class="form-field term-description-wrap">
58 58
 				<th scope="row"><label for="description"><?php
59
-						esc_html_e( 'Description', 'wordlift' ); ?></label>
59
+						esc_html_e('Description', 'wordlift'); ?></label>
60 60
 				</th>
61 61
 				<td><textarea name="description" id="description" rows="5"
62 62
 				              cols="50" class="large-text"><?php
63
-						echo esc_html( $term_settings['description'] ) ?></textarea>
63
+						echo esc_html($term_settings['description']) ?></textarea>
64 64
 					<p class="description"><?php
65
-						esc_html_e( 'The description to be used in the entity type archive page.', 'wordlift' ); ?></p>
65
+						esc_html_e('The description to be used in the entity type archive page.', 'wordlift'); ?></p>
66 66
 				</td>
67 67
 			</tr>
68 68
 		</table>
69
-		<?php submit_button( __( 'Update' ) ); ?>
69
+		<?php submit_button(__('Update')); ?>
70 70
 	</form>
71 71
 </div>
Please login to merge, or discard this patch.
src/public/class-wordlift-related-entities-cloud-widget.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -16,33 +16,33 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class Wordlift_Related_Entities_Cloud_Widget extends Wordlift_Widget {
18 18
 
19
-	/**
20
-	 * Create an {@link Wordlift_Related_Entities_Cloud_Widget} instance.
21
-	 *
22
-	 * @since 3.11.0
23
-	 */
24
-	public function __construct() {
25
-		parent::__construct(
26
-			'wl_related_entities_cloud',
27
-			__( 'WordLift Entities Cloud', 'wordlift' ),
28
-			array(
29
-				'classname'   => 'wl_related_entities_cloud',
30
-				'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ),
31
-			)
32
-		);
33
-
34
-	}
35
-
36
-	/**
37
-	 * @inheritdoc
38
-	 */
39
-	public function form( $instance ) {
40
-		$title_id          = $this->get_field_id( 'title' );
41
-		$instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
42
-		?>
19
+    /**
20
+     * Create an {@link Wordlift_Related_Entities_Cloud_Widget} instance.
21
+     *
22
+     * @since 3.11.0
23
+     */
24
+    public function __construct() {
25
+        parent::__construct(
26
+            'wl_related_entities_cloud',
27
+            __( 'WordLift Entities Cloud', 'wordlift' ),
28
+            array(
29
+                'classname'   => 'wl_related_entities_cloud',
30
+                'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ),
31
+            )
32
+        );
33
+
34
+    }
35
+
36
+    /**
37
+     * @inheritdoc
38
+     */
39
+    public function form( $instance ) {
40
+        $title_id          = $this->get_field_id( 'title' );
41
+        $instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
42
+        ?>
43 43
 
44 44
 		<p><label for="<?php echo esc_attr( $title_id ); ?>"><?php
45
-				esc_html_e( 'Title:' ); ?></label>
45
+                esc_html_e( 'Title:' ); ?></label>
46 46
 			<input type="text" class="widefat"
47 47
 			       id="<?php echo esc_attr( $title_id ); ?>"
48 48
 			       name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
@@ -51,46 +51,46 @@  discard block
 block discarded – undo
51 51
 
52 52
 		<?php
53 53
 
54
-		return 'wl_related_entities_cloud_form';
55
-	}
54
+        return 'wl_related_entities_cloud_form';
55
+    }
56 56
 
57
-	/**
58
-	 * @inheritdoc
59
-	 */
60
-	public function update( $new_instance, $old_instance ) {
57
+    /**
58
+     * @inheritdoc
59
+     */
60
+    public function update( $new_instance, $old_instance ) {
61 61
 
62
-		return array( 'title' => sanitize_text_field( $new_instance['title'] ) );
63
-	}
62
+        return array( 'title' => sanitize_text_field( $new_instance['title'] ) );
63
+    }
64 64
 
65
-	/**
66
-	 * @inheritdoc
67
-	 */
68
-	public function widget( $args, $instance ) {
65
+    /**
66
+     * @inheritdoc
67
+     */
68
+    public function widget( $args, $instance ) {
69 69
 
70
-		/*
70
+        /*
71 71
 		 * Use the shortcode to calculate the HTML required to show the cloud
72 72
 		 * if there is no such html do not render the widget at all.
73 73
 		 */
74
-		$cloud_html = do_shortcode( '[wl_cloud]' );
75
-		if ( empty( $cloud_html ) ) {
76
-			return false;
77
-		}
74
+        $cloud_html = do_shortcode( '[wl_cloud]' );
75
+        if ( empty( $cloud_html ) ) {
76
+            return false;
77
+        }
78 78
 
79
-		// The widget title.
80
-		$title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title'];
79
+        // The widget title.
80
+        $title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title'];
81 81
 
82
-		// Standard filter all widgets should apply
83
-		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
82
+        // Standard filter all widgets should apply
83
+        $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
84 84
 
85
-		echo $args['before_widget'];
85
+        echo $args['before_widget'];
86 86
 
87
-		if ( $title ) {
88
-			echo $args['before_title'] . $title . $args['after_title'];
89
-		}
87
+        if ( $title ) {
88
+            echo $args['before_title'] . $title . $args['after_title'];
89
+        }
90 90
 
91
-		echo $cloud_html;
92
-		echo $args['after_widget'];
91
+        echo $cloud_html;
92
+        echo $args['after_widget'];
93 93
 
94
-	}
94
+    }
95 95
 
96 96
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
 	public function __construct() {
25 25
 		parent::__construct(
26 26
 			'wl_related_entities_cloud',
27
-			__( 'WordLift Entities Cloud', 'wordlift' ),
27
+			__('WordLift Entities Cloud', 'wordlift'),
28 28
 			array(
29 29
 				'classname'   => 'wl_related_entities_cloud',
30
-				'description' => __( 'Display entities related to the current post/entity in a tag cloud.', 'wordlift' ),
30
+				'description' => __('Display entities related to the current post/entity in a tag cloud.', 'wordlift'),
31 31
 			)
32 32
 		);
33 33
 
@@ -36,17 +36,17 @@  discard block
 block discarded – undo
36 36
 	/**
37 37
 	 * @inheritdoc
38 38
 	 */
39
-	public function form( $instance ) {
40
-		$title_id          = $this->get_field_id( 'title' );
41
-		$instance['title'] = ! empty( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
39
+	public function form($instance) {
40
+		$title_id          = $this->get_field_id('title');
41
+		$instance['title'] = ! empty($instance['title']) ? esc_attr($instance['title']) : '';
42 42
 		?>
43 43
 
44
-		<p><label for="<?php echo esc_attr( $title_id ); ?>"><?php
45
-				esc_html_e( 'Title:' ); ?></label>
44
+		<p><label for="<?php echo esc_attr($title_id); ?>"><?php
45
+				esc_html_e('Title:'); ?></label>
46 46
 			<input type="text" class="widefat"
47
-			       id="<?php echo esc_attr( $title_id ); ?>"
48
-			       name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>"
49
-			       value="<?php echo esc_attr( $instance['title'] ); ?>" />
47
+			       id="<?php echo esc_attr($title_id); ?>"
48
+			       name="<?php echo esc_attr($this->get_field_name('title')); ?>"
49
+			       value="<?php echo esc_attr($instance['title']); ?>" />
50 50
 		</p>
51 51
 
52 52
 		<?php
@@ -57,35 +57,35 @@  discard block
 block discarded – undo
57 57
 	/**
58 58
 	 * @inheritdoc
59 59
 	 */
60
-	public function update( $new_instance, $old_instance ) {
60
+	public function update($new_instance, $old_instance) {
61 61
 
62
-		return array( 'title' => sanitize_text_field( $new_instance['title'] ) );
62
+		return array('title' => sanitize_text_field($new_instance['title']));
63 63
 	}
64 64
 
65 65
 	/**
66 66
 	 * @inheritdoc
67 67
 	 */
68
-	public function widget( $args, $instance ) {
68
+	public function widget($args, $instance) {
69 69
 
70 70
 		/*
71 71
 		 * Use the shortcode to calculate the HTML required to show the cloud
72 72
 		 * if there is no such html do not render the widget at all.
73 73
 		 */
74
-		$cloud_html = do_shortcode( '[wl_cloud]' );
75
-		if ( empty( $cloud_html ) ) {
74
+		$cloud_html = do_shortcode('[wl_cloud]');
75
+		if (empty($cloud_html)) {
76 76
 			return false;
77 77
 		}
78 78
 
79 79
 		// The widget title.
80
-		$title = empty( $instance['title'] ) ? __( 'Related Entities', 'wordlift' ) : $instance['title'];
80
+		$title = empty($instance['title']) ? __('Related Entities', 'wordlift') : $instance['title'];
81 81
 
82 82
 		// Standard filter all widgets should apply
83
-		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
83
+		$title = apply_filters('widget_title', $title, $instance, $this->id_base);
84 84
 
85 85
 		echo $args['before_widget'];
86 86
 
87
-		if ( $title ) {
88
-			echo $args['before_title'] . $title . $args['after_title'];
87
+		if ($title) {
88
+			echo $args['before_title'].$title.$args['after_title'];
89 89
 		}
90 90
 
91 91
 		echo $cloud_html;
Please login to merge, or discard this patch.