@@ -16,33 +16,33 @@ discard block |
||
16 | 16 | } |
17 | 17 | |
18 | 18 | protected function get_dataset_uri() { |
19 | - return trailingslashit( Wordlift_Configuration_Service::get_instance()->get_dataset_uri() ); |
|
19 | + return trailingslashit(Wordlift_Configuration_Service::get_instance()->get_dataset_uri()); |
|
20 | 20 | } |
21 | 21 | |
22 | - protected function is_absolute( $uri ) { |
|
23 | - return 1 === preg_match( '@^https?://@', $uri ); |
|
22 | + protected function is_absolute($uri) { |
|
23 | + return 1 === preg_match('@^https?://@', $uri); |
|
24 | 24 | } |
25 | 25 | |
26 | - protected function is_internal( $uri ) { |
|
26 | + protected function is_internal($uri) { |
|
27 | 27 | $dataset_uri = $this->get_dataset_uri(); |
28 | 28 | |
29 | - return ! empty( $dataset_uri ) && 0 === strpos( $uri, $dataset_uri ); |
|
29 | + return ! empty($dataset_uri) && 0 === strpos($uri, $dataset_uri); |
|
30 | 30 | } |
31 | 31 | |
32 | - protected function make_absolute( $uri ) { |
|
33 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
32 | + protected function make_absolute($uri) { |
|
33 | + Assertions::not_empty($this->get_dataset_uri(), '`dataset_uri` cannot be empty.'); |
|
34 | 34 | |
35 | - if ( 1 !== preg_match( '@^https?://@', $uri ) ) { |
|
36 | - return $this->get_dataset_uri() . $uri; |
|
35 | + if (1 !== preg_match('@^https?://@', $uri)) { |
|
36 | + return $this->get_dataset_uri().$uri; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | return $uri; |
40 | 40 | } |
41 | 41 | |
42 | - protected function make_relative( $uri ) { |
|
42 | + protected function make_relative($uri) { |
|
43 | 43 | $dataset_uri = $this->get_dataset_uri(); |
44 | - if ( 0 === strpos( $uri, $dataset_uri ) ) { |
|
45 | - return substr( $uri, strlen( $dataset_uri ) ); |
|
44 | + if (0 === strpos($uri, $dataset_uri)) { |
|
45 | + return substr($uri, strlen($dataset_uri)); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | return $uri; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return string|null |
55 | 55 | */ |
56 | - public function get_about_jsonld( $content_id ) { |
|
56 | + public function get_about_jsonld($content_id) { |
|
57 | 57 | global $wpdb; |
58 | 58 | |
59 | 59 | return $wpdb->get_var( |
@@ -74,18 +74,18 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @throws Exception If the 'match_name' column does not exist in the database table. |
76 | 76 | */ |
77 | - public function set_about_jsonld( $content_id, $value ) { |
|
77 | + public function set_about_jsonld($content_id, $value) { |
|
78 | 78 | global $wpdb; |
79 | 79 | |
80 | 80 | // Cleanup value. |
81 | - $value = ( is_string( $value ) && strlen( $value ) > 2 ) ? $value : null; |
|
81 | + $value = (is_string($value) && strlen($value) > 2) ? $value : null; |
|
82 | 82 | $match_name = "NULL"; |
83 | 83 | |
84 | - if ( $value ) { |
|
84 | + if ($value) { |
|
85 | 85 | // Check if the 'match_name' column exists in the database table |
86 | - $columns = $wpdb->get_col_info( 'name', 0 ); |
|
87 | - if ( in_array( 'match_name', $columns ) ) { |
|
88 | - $match_name = $this->get_match_name( $value ); |
|
86 | + $columns = $wpdb->get_col_info('name', 0); |
|
87 | + if (in_array('match_name', $columns)) { |
|
88 | + $match_name = $this->get_match_name($value); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | // should revise how this works really. |
94 | 94 | // |
95 | 95 | // This is currently needed because rel_uri is required in the table. |
96 | - switch ( $content_id->get_type() ) { |
|
96 | + switch ($content_id->get_type()) { |
|
97 | 97 | case Object_Type_Enum::POST: |
98 | - Wordpress_Dataset_Content_Service_Hooks::insert_post( $content_id->get_id() ); |
|
98 | + Wordpress_Dataset_Content_Service_Hooks::insert_post($content_id->get_id()); |
|
99 | 99 | break; |
100 | 100 | case Object_Type_Enum::TERM: |
101 | - Wordpress_Dataset_Content_Service_Hooks::created_term( $content_id->get_id() ); |
|
101 | + Wordpress_Dataset_Content_Service_Hooks::created_term($content_id->get_id()); |
|
102 | 102 | break; |
103 | 103 | case Object_Type_Enum::USER: |
104 | - Wordpress_Dataset_Content_Service_Hooks::user_register( $content_id->get_id() ); |
|
104 | + Wordpress_Dataset_Content_Service_Hooks::user_register($content_id->get_id()); |
|
105 | 105 | break; |
106 | 106 | } |
107 | 107 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * as `null` if we directly pass it to the prepare function(). So its necessary |
112 | 112 | * to make the query conditional based on the $value |
113 | 113 | */ |
114 | - if ( null === $value ) { |
|
114 | + if (null === $value) { |
|
115 | 115 | return $wpdb->query( |
116 | 116 | $wpdb->prepare( |
117 | 117 | "UPDATE {$wpdb->prefix}wl_entities |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @return mixed|null |
144 | 144 | */ |
145 | - public function get_match_name( $jsonld ) { |
|
146 | - $data = json_decode( $jsonld, true ); |
|
147 | - if ( ! $data || ! array_key_exists( 'name', $data ) ) { |
|
145 | + public function get_match_name($jsonld) { |
|
146 | + $data = json_decode($jsonld, true); |
|
147 | + if ( ! $data || ! array_key_exists('name', $data)) { |
|
148 | 148 | return "NULL"; |
149 | 149 | } |
150 | 150 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return mixed |
21 | 21 | */ |
22 | - public static function is_column_exists( $column_name ) { |
|
22 | + public static function is_column_exists($column_name) { |
|
23 | 23 | global $wpdb; |
24 | 24 | |
25 | 25 | return $wpdb->get_results( |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | global $wpdb; |
40 | 40 | |
41 | 41 | // Check if 'match_name' column exists |
42 | - if ( self::is_column_exists( 'match_name' ) ) { |
|
42 | + if (self::is_column_exists('match_name')) { |
|
43 | 43 | return; |
44 | 44 | } |
45 | 45 | |
@@ -56,17 +56,17 @@ discard block |
||
56 | 56 | ); |
57 | 57 | |
58 | 58 | // Update 'match_name' for each row |
59 | - foreach ( $results as $row ) { |
|
60 | - $match_name = $this->get_match_name( $row['about_jsonld'] ); |
|
59 | + foreach ($results as $row) { |
|
60 | + $match_name = $this->get_match_name($row['about_jsonld']); |
|
61 | 61 | |
62 | - if ( is_null( $match_name ) ) { |
|
62 | + if (is_null($match_name)) { |
|
63 | 63 | continue; |
64 | 64 | } |
65 | 65 | |
66 | 66 | $wpdb->update( |
67 | 67 | "{$wpdb->prefix}wl_relation_instances", |
68 | - array( 'match_name' => $match_name ), |
|
69 | - array( 'id' => $row['id'] ) |
|
68 | + array('match_name' => $match_name), |
|
69 | + array('id' => $row['id']) |
|
70 | 70 | ); |
71 | 71 | } |
72 | 72 | |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return mixed|null |
82 | 82 | */ |
83 | - public function get_match_name( $jsonld ) { |
|
84 | - $data = json_decode( $jsonld, true ); |
|
85 | - if ( ! $data || ! array_key_exists( 'name', $data ) ) { |
|
83 | + public function get_match_name($jsonld) { |
|
84 | + $data = json_decode($jsonld, true); |
|
85 | + if ( ! $data || ! array_key_exists('name', $data)) { |
|
86 | 86 | return null; |
87 | 87 | } |
88 | 88 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param WP_REST_Request $request |
40 | 40 | * @param Cursor $cursor |
41 | 41 | */ |
42 | - public function __construct( $request, $cursor, $cursor_sort, $limit ) { |
|
42 | + public function __construct($request, $cursor, $cursor_sort, $limit) { |
|
43 | 43 | global $wpdb; |
44 | 44 | |
45 | 45 | $this->request = $request; |
@@ -80,41 +80,41 @@ discard block |
||
80 | 80 | |
81 | 81 | // The `sql` is prepared in each delegated function in this class. |
82 | 82 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
83 | - $items = $wpdb->get_results( $this->sql ); |
|
83 | + $items = $wpdb->get_results($this->sql); |
|
84 | 84 | |
85 | 85 | // Mapping elements to add match_name |
86 | - $items = array_map( array( $this, 'map_item' ), $items ); |
|
86 | + $items = array_map(array($this, 'map_item'), $items); |
|
87 | 87 | |
88 | - $sort = ( $this->sort === 'ASC' ? SORT_ASC : SORT_DESC ); |
|
88 | + $sort = ($this->sort === 'ASC' ? SORT_ASC : SORT_DESC); |
|
89 | 89 | |
90 | 90 | // Sorting functions for specific fields |
91 | 91 | $sort_functions = array( |
92 | - 'match_name' => function ( $a, $b ) use ( $sort ) { |
|
93 | - return $sort === SORT_ASC ? strcmp( $a->match_name, $b->match_name ) : strcmp( $b->match_name, $a->match_name ); |
|
92 | + 'match_name' => function($a, $b) use ($sort) { |
|
93 | + return $sort === SORT_ASC ? strcmp($a->match_name, $b->match_name) : strcmp($b->match_name, $a->match_name); |
|
94 | 94 | }, |
95 | 95 | // Add more specific sorting functions for other fields here |
96 | 96 | ); |
97 | 97 | |
98 | 98 | // Check if a specific sorting function exists for the sortby field, otherwise use the default sorting |
99 | - if ( array_key_exists( $this->sortby, $sort_functions ) ) { |
|
100 | - usort( $items, $sort_functions[ $this->sortby ] ); |
|
99 | + if (array_key_exists($this->sortby, $sort_functions)) { |
|
100 | + usort($items, $sort_functions[$this->sortby]); |
|
101 | 101 | } else { |
102 | 102 | // Use the original sorting method for other keys |
103 | - array_multisort( array_column( $items, $this->cursor_sort->get_sort_property() ), $sort, $items ); |
|
103 | + array_multisort(array_column($items, $this->cursor_sort->get_sort_property()), $sort, $items); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | return $items; |
107 | 107 | } |
108 | 108 | |
109 | - public function map_item( $item ) { |
|
110 | - $item->match_name = $this->get_match_name( $item->match_jsonld ); |
|
109 | + public function map_item($item) { |
|
110 | + $item->match_name = $this->get_match_name($item->match_jsonld); |
|
111 | 111 | |
112 | 112 | return $item; |
113 | 113 | } |
114 | 114 | |
115 | - private function get_match_name( $jsonld ) { |
|
116 | - $data = json_decode( $jsonld, true ); |
|
117 | - if ( ! $data || ! array_key_exists( 'name', $data ) ) { |
|
115 | + private function get_match_name($jsonld) { |
|
116 | + $data = json_decode($jsonld, true); |
|
117 | + if ( ! $data || ! array_key_exists('name', $data)) { |
|
118 | 118 | return null; |
119 | 119 | } |
120 | 120 | |
@@ -122,26 +122,26 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | private function post_types() { |
125 | - $post_types = $this->request->has_param( 'post_types' ) |
|
126 | - ? (array) $this->request->get_param( 'post_types' ) |
|
127 | - : array( 'post', 'page' ); |
|
128 | - $value = array_map( 'esc_sql', $post_types ); |
|
129 | - $this->sql .= " AND p.post_type IN ( '" . implode( "', '", $value ) . "' )"; |
|
125 | + $post_types = $this->request->has_param('post_types') |
|
126 | + ? (array) $this->request->get_param('post_types') |
|
127 | + : array('post', 'page'); |
|
128 | + $value = array_map('esc_sql', $post_types); |
|
129 | + $this->sql .= " AND p.post_type IN ( '".implode("', '", $value)."' )"; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | private function limit() { |
133 | - $value = is_numeric( $this->limit ) ? $this->limit : 10; |
|
134 | - $this->sql .= ' LIMIT ' . esc_sql( $value ); |
|
133 | + $value = is_numeric($this->limit) ? $this->limit : 10; |
|
134 | + $this->sql .= ' LIMIT '.esc_sql($value); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | private function has_match() { |
138 | - if ( ! $this->request->has_param( 'has_match' ) ) { |
|
138 | + if ( ! $this->request->has_param('has_match')) { |
|
139 | 139 | return; |
140 | 140 | } |
141 | 141 | |
142 | - $value = (bool) $this->request->get_param( 'has_match' ); |
|
142 | + $value = (bool) $this->request->get_param('has_match'); |
|
143 | 143 | |
144 | - if ( $value ) { |
|
144 | + if ($value) { |
|
145 | 145 | $this->sql .= ' AND e.about_jsonld IS NOT NULL'; |
146 | 146 | } else { |
147 | 147 | $this->sql .= ' AND e.about_jsonld IS NULL'; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | } |
150 | 150 | |
151 | 151 | private function sort() { |
152 | - switch ( $this->direction . '$' . $this->sort ) { |
|
152 | + switch ($this->direction.'$'.$this->sort) { |
|
153 | 153 | case 'ASCENDING$ASC': |
154 | 154 | case 'DESCENDING$DESC': |
155 | 155 | $sort = 'ASC'; |
@@ -160,15 +160,15 @@ discard block |
||
160 | 160 | break; |
161 | 161 | } |
162 | 162 | |
163 | - $this->sql .= ' ORDER BY t.' . $this->sortby . ' ' . $sort; |
|
163 | + $this->sql .= ' ORDER BY t.'.$this->sortby.' '.$sort; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | private function cursor() { |
167 | - if ( ! isset( $this->position ) ) { |
|
167 | + if ( ! isset($this->position)) { |
|
168 | 168 | return; |
169 | 169 | } |
170 | 170 | |
171 | - switch ( $this->direction . '$' . $this->sort ) { |
|
171 | + switch ($this->direction.'$'.$this->sort) { |
|
172 | 172 | case 'ASCENDING$ASC': |
173 | 173 | case 'DESCENDING$DESC': |
174 | 174 | $condition = '>'; |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | break; |
180 | 180 | } |
181 | 181 | |
182 | - $condition .= ( $this->element === 'INCLUDED' ? '=' : '' ); |
|
182 | + $condition .= ($this->element === 'INCLUDED' ? '=' : ''); |
|
183 | 183 | global $wpdb; |
184 | 184 | // We control the vars in this method. |
185 | 185 | // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
186 | - $this->sql .= $wpdb->prepare( ' AND t.' . esc_sql( $this->sortby ) . ' ' . $condition . ' %s', $this->position ); |
|
186 | + $this->sql .= $wpdb->prepare(' AND t.'.esc_sql($this->sortby).' '.$condition.' %s', $this->position); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | private function set_sort() { |
@@ -193,30 +193,30 @@ discard block |
||
193 | 193 | 'match_name' => 'match_name', |
194 | 194 | ); |
195 | 195 | |
196 | - $value = $this->request->has_param( 'sort' ) |
|
197 | - ? $this->request->get_param( 'sort' ) |
|
196 | + $value = $this->request->has_param('sort') |
|
197 | + ? $this->request->get_param('sort') |
|
198 | 198 | : '+term_name'; |
199 | 199 | |
200 | - $sortby = substr( $value, 1 ); |
|
201 | - $this->sortby = isset( $sortby_to_col[ $sortby ] ) ? $sortby_to_col[ $sortby ] : $sortby; |
|
202 | - $this->sort = substr( $value, 0, 1 ) === '+' ? 'ASC' : 'DESC'; |
|
200 | + $sortby = substr($value, 1); |
|
201 | + $this->sortby = isset($sortby_to_col[$sortby]) ? $sortby_to_col[$sortby] : $sortby; |
|
202 | + $this->sort = substr($value, 0, 1) === '+' ? 'ASC' : 'DESC'; |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | private function term_contains() { |
206 | - if ( ! $this->request->has_param( 'term_contains' ) ) { |
|
206 | + if ( ! $this->request->has_param('term_contains')) { |
|
207 | 207 | return; |
208 | 208 | } |
209 | 209 | |
210 | 210 | global $wpdb; |
211 | - $value = $this->request->get_param( 'term_contains' ); |
|
212 | - $this->sql .= $wpdb->prepare( ' and t.name LIKE %s', '%' . esc_sql( $value ) . '%' ); |
|
211 | + $value = $this->request->get_param('term_contains'); |
|
212 | + $this->sql .= $wpdb->prepare(' and t.name LIKE %s', '%'.esc_sql($value).'%'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | private function taxonomies() { |
216 | - $taxonomies = $this->request->has_param( 'taxonomies' ) |
|
217 | - ? (array) $this->request->get_param( 'taxonomies' ) |
|
218 | - : array( 'post_tag', 'category' ); |
|
219 | - $value = array_map( 'esc_sql', $taxonomies ); |
|
220 | - $this->sql .= " AND tt.taxonomy IN ( '" . implode( "', '", $value ) . "' )"; |
|
216 | + $taxonomies = $this->request->has_param('taxonomies') |
|
217 | + ? (array) $this->request->get_param('taxonomies') |
|
218 | + : array('post_tag', 'category'); |
|
219 | + $value = array_map('esc_sql', $taxonomies); |
|
220 | + $this->sql .= " AND tt.taxonomy IN ( '".implode("', '", $value)."' )"; |
|
221 | 221 | } |
222 | 222 | } |