@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | public function column_id(EE_Venue $venue): string |
108 | 108 | { |
109 | 109 | $content = ' |
110 | - <span class="ee-entity-id">' . $venue->ID() . '</span> |
|
111 | - <span class="show-on-mobile-view-only">' . $this->column_name($venue, false) . '</span>'; |
|
110 | + <span class="ee-entity-id">' . $venue->ID().'</span> |
|
111 | + <span class="show-on-mobile-view-only">' . $this->column_name($venue, false).'</span>'; |
|
112 | 112 | return $this->columnContent('id', $content, 'end'); |
113 | 113 | } |
114 | 114 | |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | $actions = $prep_content ? $this->_column_name_action_setup($venue) : []; |
135 | 135 | $content = |
136 | 136 | EE_Registry::instance()->CAP->current_user_can('ee_edit_venue', 'espresso_venues_edit', $venue->ID()) |
137 | - ? '<strong><a class="row-title" href="' . $edit_link . '">' . stripslashes_deep( |
|
137 | + ? '<strong><a class="row-title" href="'.$edit_link.'">'.stripslashes_deep( |
|
138 | 138 | $venue->name() |
139 | - ) . '</a></strong>' : $venue->name(); |
|
140 | - $content .= $venue->status() == 'draft' ? ' - <span class="post-state">' . $statuses['draft'] . '</span>' : ''; |
|
139 | + ).'</a></strong>' : $venue->name(); |
|
140 | + $content .= $venue->status() == 'draft' ? ' - <span class="post-state">'.$statuses['draft'].'</span>' : ''; |
|
141 | 141 | |
142 | 142 | $content .= $prep_content ? $this->row_actions($actions) : ''; |
143 | 143 | return $prep_content ? $this->columnContent('name', $content) : $content; |
@@ -164,10 +164,10 @@ discard block |
||
164 | 164 | 'post' => $venue->ID(), |
165 | 165 | ]; |
166 | 166 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_VENUES_ADMIN_URL); |
167 | - $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__( |
|
167 | + $actions['edit'] = '<a href="'.$edit_link.'" title="'.esc_attr__( |
|
168 | 168 | 'Edit Venue', |
169 | 169 | 'event_espresso' |
170 | - ) . '">' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
170 | + ).'">'.esc_html__('Edit', 'event_espresso').'</a>'; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | |
@@ -188,10 +188,10 @@ discard block |
||
188 | 188 | EE_VENUES_ADMIN_URL |
189 | 189 | ); |
190 | 190 | |
191 | - $actions['restore_from_trash'] = '<a href="' . $restore_venue_link . '" title="' . esc_attr__( |
|
191 | + $actions['restore_from_trash'] = '<a href="'.$restore_venue_link.'" title="'.esc_attr__( |
|
192 | 192 | 'Restore from Trash', |
193 | 193 | 'event_espresso' |
194 | - ) . '">' . esc_html__('Restore from Trash', 'event_espresso') . '</a>'; |
|
194 | + ).'">'.esc_html__('Restore from Trash', 'event_espresso').'</a>'; |
|
195 | 195 | } |
196 | 196 | if ( |
197 | 197 | $venue->count_related('Event') === 0 |
@@ -209,18 +209,18 @@ discard block |
||
209 | 209 | EE_VENUES_ADMIN_URL |
210 | 210 | ); |
211 | 211 | |
212 | - $actions['delete permanently'] = '<a href="' . $delete_venue_link . '" title="' . esc_attr__( |
|
212 | + $actions['delete permanently'] = '<a href="'.$delete_venue_link.'" title="'.esc_attr__( |
|
213 | 213 | 'Delete Permanently', |
214 | 214 | 'event_espresso' |
215 | - ) . '">' . esc_html__('Delete Permanently', 'event_espresso') . '</a>'; |
|
215 | + ).'">'.esc_html__('Delete Permanently', 'event_espresso').'</a>'; |
|
216 | 216 | } |
217 | 217 | break; |
218 | 218 | default: |
219 | 219 | $actions['view'] = ' |
220 | - <a href="' . get_permalink($venue->ID()) . '" |
|
221 | - title="' . esc_attr__('View Venue', 'event_espresso') . '" |
|
220 | + <a href="' . get_permalink($venue->ID()).'" |
|
221 | + title="' . esc_attr__('View Venue', 'event_espresso').'" |
|
222 | 222 | > |
223 | - ' . esc_html__('View', 'event_espresso') . ' |
|
223 | + ' . esc_html__('View', 'event_espresso').' |
|
224 | 224 | </a>'; |
225 | 225 | if ( |
226 | 226 | EE_Registry::instance()->CAP->current_user_can( |
@@ -237,10 +237,10 @@ discard block |
||
237 | 237 | EE_VENUES_ADMIN_URL |
238 | 238 | ); |
239 | 239 | |
240 | - $actions['move to trash'] = '<a href="' . $trash_venue_link . '" title="' . esc_attr__( |
|
240 | + $actions['move to trash'] = '<a href="'.$trash_venue_link.'" title="'.esc_attr__( |
|
241 | 241 | 'Trash Event', |
242 | 242 | 'event_espresso' |
243 | - ) . '">' . esc_html__('Trash', 'event_espresso') . '</a>'; |
|
243 | + ).'">'.esc_html__('Trash', 'event_espresso').'</a>'; |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | return $actions; |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | */ |
276 | 276 | public function column_shortcode(EE_Venue $venue): string |
277 | 277 | { |
278 | - $content = '[ESPRESSO_VENUE id=' . $venue->ID() . ']'; |
|
278 | + $content = '[ESPRESSO_VENUE id='.$venue->ID().']'; |
|
279 | 279 | return $this->columnContent('shortcode', $content); |
280 | 280 | } |
281 | 281 | } |
@@ -13,269 +13,269 @@ |
||
13 | 13 | */ |
14 | 14 | class Venues_Admin_List_Table extends EE_Admin_List_Table |
15 | 15 | { |
16 | - /** |
|
17 | - * @var Venues_Admin_Page $_admin_page |
|
18 | - */ |
|
19 | - protected EE_Admin_Page $_admin_page; |
|
20 | - |
|
21 | - |
|
22 | - protected function _setup_data() |
|
23 | - { |
|
24 | - $this->_data = $this->_admin_page->get_venues($this->_per_page); |
|
25 | - $this->_all_data_count = $this->_admin_page->get_venues($this->_per_page, true); |
|
26 | - } |
|
27 | - |
|
28 | - |
|
29 | - protected function _set_properties() |
|
30 | - { |
|
31 | - $this->_wp_list_args = [ |
|
32 | - 'singular' => esc_html__('Event Venue', 'event_espresso'), |
|
33 | - 'plural' => esc_html__('Event Venues', 'event_espresso'), |
|
34 | - 'ajax' => true, // for now, |
|
35 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
36 | - ]; |
|
37 | - |
|
38 | - $this->_columns = [ |
|
39 | - 'cb' => '<input type="checkbox" />', |
|
40 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
41 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
42 | - 'address' => esc_html__('Address', 'event_espresso'), |
|
43 | - 'city' => esc_html__('City', 'event_espresso'), |
|
44 | - 'capacity' => esc_html__('Capacity', 'event_espresso'), |
|
45 | - // 'shortcode' => esc_html__('Shortcode', 'event_espresso'), |
|
46 | - ]; |
|
47 | - |
|
48 | - $this->_sortable_columns = [ |
|
49 | - 'id' => ['id' => true], |
|
50 | - 'name' => ['name' => false], |
|
51 | - 'city' => ['city' => false], |
|
52 | - 'capacity' => ['capacity' => false], |
|
53 | - ]; |
|
54 | - |
|
55 | - $this->_hidden_columns = []; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - // todo... add _venue_status in here (which we'll define a EE_Admin_CPT_List_Table for common properties) |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - protected function _get_table_filters() |
|
66 | - { |
|
67 | - return []; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @throws EE_Error |
|
73 | - * @throws ReflectionException |
|
74 | - */ |
|
75 | - protected function _add_view_counts() |
|
76 | - { |
|
77 | - $this->_views['all']['count'] = EEM_Venue::instance()->count(); |
|
78 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) { |
|
79 | - $this->_views['trash']['count'] = EEM_Venue::instance()->count_deleted(); |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * @param EE_Venue|null $item |
|
86 | - * @return string |
|
87 | - * @throws EE_Error |
|
88 | - * @throws ReflectionException |
|
89 | - */ |
|
90 | - public function column_cb($item): string |
|
91 | - { |
|
92 | - return $item->count_related('Event') > 0 && $item->get('status') === 'trash' |
|
93 | - ? '<span class="dashicons dashicons-lock"></span>' |
|
94 | - : sprintf( |
|
95 | - '<input type="checkbox" name="venue_id[]" value="%s" />', |
|
96 | - $item->ID() |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @param EE_Venue $venue |
|
103 | - * @return string |
|
104 | - * @throws EE_Error |
|
105 | - * @throws ReflectionException |
|
106 | - */ |
|
107 | - public function column_id(EE_Venue $venue): string |
|
108 | - { |
|
109 | - $content = ' |
|
16 | + /** |
|
17 | + * @var Venues_Admin_Page $_admin_page |
|
18 | + */ |
|
19 | + protected EE_Admin_Page $_admin_page; |
|
20 | + |
|
21 | + |
|
22 | + protected function _setup_data() |
|
23 | + { |
|
24 | + $this->_data = $this->_admin_page->get_venues($this->_per_page); |
|
25 | + $this->_all_data_count = $this->_admin_page->get_venues($this->_per_page, true); |
|
26 | + } |
|
27 | + |
|
28 | + |
|
29 | + protected function _set_properties() |
|
30 | + { |
|
31 | + $this->_wp_list_args = [ |
|
32 | + 'singular' => esc_html__('Event Venue', 'event_espresso'), |
|
33 | + 'plural' => esc_html__('Event Venues', 'event_espresso'), |
|
34 | + 'ajax' => true, // for now, |
|
35 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
36 | + ]; |
|
37 | + |
|
38 | + $this->_columns = [ |
|
39 | + 'cb' => '<input type="checkbox" />', |
|
40 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
41 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
42 | + 'address' => esc_html__('Address', 'event_espresso'), |
|
43 | + 'city' => esc_html__('City', 'event_espresso'), |
|
44 | + 'capacity' => esc_html__('Capacity', 'event_espresso'), |
|
45 | + // 'shortcode' => esc_html__('Shortcode', 'event_espresso'), |
|
46 | + ]; |
|
47 | + |
|
48 | + $this->_sortable_columns = [ |
|
49 | + 'id' => ['id' => true], |
|
50 | + 'name' => ['name' => false], |
|
51 | + 'city' => ['city' => false], |
|
52 | + 'capacity' => ['capacity' => false], |
|
53 | + ]; |
|
54 | + |
|
55 | + $this->_hidden_columns = []; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + // todo... add _venue_status in here (which we'll define a EE_Admin_CPT_List_Table for common properties) |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + protected function _get_table_filters() |
|
66 | + { |
|
67 | + return []; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @throws EE_Error |
|
73 | + * @throws ReflectionException |
|
74 | + */ |
|
75 | + protected function _add_view_counts() |
|
76 | + { |
|
77 | + $this->_views['all']['count'] = EEM_Venue::instance()->count(); |
|
78 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) { |
|
79 | + $this->_views['trash']['count'] = EEM_Venue::instance()->count_deleted(); |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * @param EE_Venue|null $item |
|
86 | + * @return string |
|
87 | + * @throws EE_Error |
|
88 | + * @throws ReflectionException |
|
89 | + */ |
|
90 | + public function column_cb($item): string |
|
91 | + { |
|
92 | + return $item->count_related('Event') > 0 && $item->get('status') === 'trash' |
|
93 | + ? '<span class="dashicons dashicons-lock"></span>' |
|
94 | + : sprintf( |
|
95 | + '<input type="checkbox" name="venue_id[]" value="%s" />', |
|
96 | + $item->ID() |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @param EE_Venue $venue |
|
103 | + * @return string |
|
104 | + * @throws EE_Error |
|
105 | + * @throws ReflectionException |
|
106 | + */ |
|
107 | + public function column_id(EE_Venue $venue): string |
|
108 | + { |
|
109 | + $content = ' |
|
110 | 110 | <span class="ee-entity-id">' . $venue->ID() . '</span> |
111 | 111 | <span class="show-on-mobile-view-only">' . $this->column_name($venue, false) . '</span>'; |
112 | - return $this->columnContent('id', $content, 'end'); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @param EE_Venue $venue |
|
118 | - * @param bool $prep_content |
|
119 | - * @return string |
|
120 | - * @throws EE_Error |
|
121 | - * @throws ReflectionException |
|
122 | - */ |
|
123 | - public function column_name(EE_Venue $venue, bool $prep_content = true): string |
|
124 | - { |
|
125 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
126 | - [ |
|
127 | - 'action' => 'edit', |
|
128 | - 'post' => $venue->ID(), |
|
129 | - ], |
|
130 | - EE_VENUES_ADMIN_URL |
|
131 | - ); |
|
132 | - |
|
133 | - $statuses = EEM_Venue::instance()->get_status_array(); |
|
134 | - $actions = $prep_content ? $this->_column_name_action_setup($venue) : []; |
|
135 | - $content = |
|
136 | - EE_Registry::instance()->CAP->current_user_can('ee_edit_venue', 'espresso_venues_edit', $venue->ID()) |
|
137 | - ? '<strong><a class="row-title" href="' . $edit_link . '">' . stripslashes_deep( |
|
138 | - $venue->name() |
|
139 | - ) . '</a></strong>' : $venue->name(); |
|
140 | - $content .= $venue->status() == 'draft' ? ' - <span class="post-state">' . $statuses['draft'] . '</span>' : ''; |
|
141 | - |
|
142 | - $content .= $prep_content ? $this->row_actions($actions) : ''; |
|
143 | - return $prep_content ? $this->columnContent('name', $content) : $content; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * Used to setup the actions for the Venue name column |
|
149 | - * |
|
150 | - * @param EE_Venue $venue |
|
151 | - * @return array() |
|
152 | - * @throws EE_Error |
|
153 | - * @throws ReflectionException |
|
154 | - * @throws EE_Error |
|
155 | - * @throws ReflectionException |
|
156 | - */ |
|
157 | - protected function _column_name_action_setup(EE_Venue $venue): array |
|
158 | - { |
|
159 | - $actions = []; |
|
160 | - |
|
161 | - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_venue', 'espresso_venues_edit', $venue->ID())) { |
|
162 | - $edit_query_args = [ |
|
163 | - 'action' => 'edit', |
|
164 | - 'post' => $venue->ID(), |
|
165 | - ]; |
|
166 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_VENUES_ADMIN_URL); |
|
167 | - $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__( |
|
168 | - 'Edit Venue', |
|
169 | - 'event_espresso' |
|
170 | - ) . '">' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - switch ($venue->get('status')) { |
|
175 | - case 'trash': |
|
176 | - if ( |
|
177 | - EE_Registry::instance()->CAP->current_user_can( |
|
178 | - 'ee_delete_venue', |
|
179 | - 'espresso_venues_restore_venue', |
|
180 | - $venue->ID() |
|
181 | - ) |
|
182 | - ) { |
|
183 | - $restore_venue_link = EE_Admin_Page::add_query_args_and_nonce( |
|
184 | - [ |
|
185 | - 'action' => 'restore_venue', |
|
186 | - 'VNU_ID' => $venue->ID(), |
|
187 | - ], |
|
188 | - EE_VENUES_ADMIN_URL |
|
189 | - ); |
|
190 | - |
|
191 | - $actions['restore_from_trash'] = '<a href="' . $restore_venue_link . '" title="' . esc_attr__( |
|
192 | - 'Restore from Trash', |
|
193 | - 'event_espresso' |
|
194 | - ) . '">' . esc_html__('Restore from Trash', 'event_espresso') . '</a>'; |
|
195 | - } |
|
196 | - if ( |
|
197 | - $venue->count_related('Event') === 0 |
|
198 | - && EE_Registry::instance()->CAP->current_user_can( |
|
199 | - 'ee_delete_venue', |
|
200 | - 'espresso_venues_delete_venue', |
|
201 | - $venue->ID() |
|
202 | - ) |
|
203 | - ) { |
|
204 | - $delete_venue_link = EE_Admin_Page::add_query_args_and_nonce( |
|
205 | - [ |
|
206 | - 'action' => 'delete_venue', |
|
207 | - 'VNU_ID' => $venue->ID(), |
|
208 | - ], |
|
209 | - EE_VENUES_ADMIN_URL |
|
210 | - ); |
|
211 | - |
|
212 | - $actions['delete permanently'] = '<a href="' . $delete_venue_link . '" title="' . esc_attr__( |
|
213 | - 'Delete Permanently', |
|
214 | - 'event_espresso' |
|
215 | - ) . '">' . esc_html__('Delete Permanently', 'event_espresso') . '</a>'; |
|
216 | - } |
|
217 | - break; |
|
218 | - default: |
|
219 | - $actions['view'] = ' |
|
112 | + return $this->columnContent('id', $content, 'end'); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @param EE_Venue $venue |
|
118 | + * @param bool $prep_content |
|
119 | + * @return string |
|
120 | + * @throws EE_Error |
|
121 | + * @throws ReflectionException |
|
122 | + */ |
|
123 | + public function column_name(EE_Venue $venue, bool $prep_content = true): string |
|
124 | + { |
|
125 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
126 | + [ |
|
127 | + 'action' => 'edit', |
|
128 | + 'post' => $venue->ID(), |
|
129 | + ], |
|
130 | + EE_VENUES_ADMIN_URL |
|
131 | + ); |
|
132 | + |
|
133 | + $statuses = EEM_Venue::instance()->get_status_array(); |
|
134 | + $actions = $prep_content ? $this->_column_name_action_setup($venue) : []; |
|
135 | + $content = |
|
136 | + EE_Registry::instance()->CAP->current_user_can('ee_edit_venue', 'espresso_venues_edit', $venue->ID()) |
|
137 | + ? '<strong><a class="row-title" href="' . $edit_link . '">' . stripslashes_deep( |
|
138 | + $venue->name() |
|
139 | + ) . '</a></strong>' : $venue->name(); |
|
140 | + $content .= $venue->status() == 'draft' ? ' - <span class="post-state">' . $statuses['draft'] . '</span>' : ''; |
|
141 | + |
|
142 | + $content .= $prep_content ? $this->row_actions($actions) : ''; |
|
143 | + return $prep_content ? $this->columnContent('name', $content) : $content; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * Used to setup the actions for the Venue name column |
|
149 | + * |
|
150 | + * @param EE_Venue $venue |
|
151 | + * @return array() |
|
152 | + * @throws EE_Error |
|
153 | + * @throws ReflectionException |
|
154 | + * @throws EE_Error |
|
155 | + * @throws ReflectionException |
|
156 | + */ |
|
157 | + protected function _column_name_action_setup(EE_Venue $venue): array |
|
158 | + { |
|
159 | + $actions = []; |
|
160 | + |
|
161 | + if (EE_Registry::instance()->CAP->current_user_can('ee_edit_venue', 'espresso_venues_edit', $venue->ID())) { |
|
162 | + $edit_query_args = [ |
|
163 | + 'action' => 'edit', |
|
164 | + 'post' => $venue->ID(), |
|
165 | + ]; |
|
166 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EE_VENUES_ADMIN_URL); |
|
167 | + $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__( |
|
168 | + 'Edit Venue', |
|
169 | + 'event_espresso' |
|
170 | + ) . '">' . esc_html__('Edit', 'event_espresso') . '</a>'; |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + switch ($venue->get('status')) { |
|
175 | + case 'trash': |
|
176 | + if ( |
|
177 | + EE_Registry::instance()->CAP->current_user_can( |
|
178 | + 'ee_delete_venue', |
|
179 | + 'espresso_venues_restore_venue', |
|
180 | + $venue->ID() |
|
181 | + ) |
|
182 | + ) { |
|
183 | + $restore_venue_link = EE_Admin_Page::add_query_args_and_nonce( |
|
184 | + [ |
|
185 | + 'action' => 'restore_venue', |
|
186 | + 'VNU_ID' => $venue->ID(), |
|
187 | + ], |
|
188 | + EE_VENUES_ADMIN_URL |
|
189 | + ); |
|
190 | + |
|
191 | + $actions['restore_from_trash'] = '<a href="' . $restore_venue_link . '" title="' . esc_attr__( |
|
192 | + 'Restore from Trash', |
|
193 | + 'event_espresso' |
|
194 | + ) . '">' . esc_html__('Restore from Trash', 'event_espresso') . '</a>'; |
|
195 | + } |
|
196 | + if ( |
|
197 | + $venue->count_related('Event') === 0 |
|
198 | + && EE_Registry::instance()->CAP->current_user_can( |
|
199 | + 'ee_delete_venue', |
|
200 | + 'espresso_venues_delete_venue', |
|
201 | + $venue->ID() |
|
202 | + ) |
|
203 | + ) { |
|
204 | + $delete_venue_link = EE_Admin_Page::add_query_args_and_nonce( |
|
205 | + [ |
|
206 | + 'action' => 'delete_venue', |
|
207 | + 'VNU_ID' => $venue->ID(), |
|
208 | + ], |
|
209 | + EE_VENUES_ADMIN_URL |
|
210 | + ); |
|
211 | + |
|
212 | + $actions['delete permanently'] = '<a href="' . $delete_venue_link . '" title="' . esc_attr__( |
|
213 | + 'Delete Permanently', |
|
214 | + 'event_espresso' |
|
215 | + ) . '">' . esc_html__('Delete Permanently', 'event_espresso') . '</a>'; |
|
216 | + } |
|
217 | + break; |
|
218 | + default: |
|
219 | + $actions['view'] = ' |
|
220 | 220 | <a href="' . get_permalink($venue->ID()) . '" |
221 | 221 | title="' . esc_attr__('View Venue', 'event_espresso') . '" |
222 | 222 | > |
223 | 223 | ' . esc_html__('View', 'event_espresso') . ' |
224 | 224 | </a>'; |
225 | - if ( |
|
226 | - EE_Registry::instance()->CAP->current_user_can( |
|
227 | - 'ee_delete_venue', |
|
228 | - 'espresso_venues_trash_venue', |
|
229 | - $venue->ID() |
|
230 | - ) |
|
231 | - ) { |
|
232 | - $trash_venue_link = EE_Admin_Page::add_query_args_and_nonce( |
|
233 | - [ |
|
234 | - 'action' => 'trash_venue', |
|
235 | - 'VNU_ID' => $venue->ID(), |
|
236 | - ], |
|
237 | - EE_VENUES_ADMIN_URL |
|
238 | - ); |
|
239 | - |
|
240 | - $actions['move to trash'] = '<a href="' . $trash_venue_link . '" title="' . esc_attr__( |
|
241 | - 'Trash Event', |
|
242 | - 'event_espresso' |
|
243 | - ) . '">' . esc_html__('Trash', 'event_espresso') . '</a>'; |
|
244 | - } |
|
245 | - } |
|
246 | - return $actions; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - public function column_address(EE_Venue $venue): string |
|
251 | - { |
|
252 | - return $this->columnContent('address', $venue->address()); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - public function column_city(EE_Venue $venue): string |
|
257 | - { |
|
258 | - return $this->columnContent('city', $venue->city()); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @throws EE_Error |
|
264 | - * @throws ReflectionException |
|
265 | - */ |
|
266 | - public function column_capacity(EE_Venue $venue): string |
|
267 | - { |
|
268 | - return $this->columnContent('capacity', $venue->capacity()); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @throws ReflectionException |
|
274 | - * @throws EE_Error |
|
275 | - */ |
|
276 | - public function column_shortcode(EE_Venue $venue): string |
|
277 | - { |
|
278 | - $content = '[ESPRESSO_VENUE id=' . $venue->ID() . ']'; |
|
279 | - return $this->columnContent('shortcode', $content); |
|
280 | - } |
|
225 | + if ( |
|
226 | + EE_Registry::instance()->CAP->current_user_can( |
|
227 | + 'ee_delete_venue', |
|
228 | + 'espresso_venues_trash_venue', |
|
229 | + $venue->ID() |
|
230 | + ) |
|
231 | + ) { |
|
232 | + $trash_venue_link = EE_Admin_Page::add_query_args_and_nonce( |
|
233 | + [ |
|
234 | + 'action' => 'trash_venue', |
|
235 | + 'VNU_ID' => $venue->ID(), |
|
236 | + ], |
|
237 | + EE_VENUES_ADMIN_URL |
|
238 | + ); |
|
239 | + |
|
240 | + $actions['move to trash'] = '<a href="' . $trash_venue_link . '" title="' . esc_attr__( |
|
241 | + 'Trash Event', |
|
242 | + 'event_espresso' |
|
243 | + ) . '">' . esc_html__('Trash', 'event_espresso') . '</a>'; |
|
244 | + } |
|
245 | + } |
|
246 | + return $actions; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + public function column_address(EE_Venue $venue): string |
|
251 | + { |
|
252 | + return $this->columnContent('address', $venue->address()); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + public function column_city(EE_Venue $venue): string |
|
257 | + { |
|
258 | + return $this->columnContent('city', $venue->city()); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @throws EE_Error |
|
264 | + * @throws ReflectionException |
|
265 | + */ |
|
266 | + public function column_capacity(EE_Venue $venue): string |
|
267 | + { |
|
268 | + return $this->columnContent('capacity', $venue->capacity()); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @throws ReflectionException |
|
274 | + * @throws EE_Error |
|
275 | + */ |
|
276 | + public function column_shortcode(EE_Venue $venue): string |
|
277 | + { |
|
278 | + $content = '[ESPRESSO_VENUE id=' . $venue->ID() . ']'; |
|
279 | + return $this->columnContent('shortcode', $content); |
|
280 | + } |
|
281 | 281 | } |
@@ -22,19 +22,19 @@ |
||
22 | 22 | <td> |
23 | 23 | <p> |
24 | 24 | <?php echo wp_kses( |
25 | - EEH_Form_Fields::select_input( |
|
26 | - 'default_reg_status', |
|
27 | - $reg_status_array, |
|
28 | - $default_reg_status |
|
29 | - ), |
|
30 | - AllowedTags::getWithFormTags() |
|
31 | - ); ?> |
|
25 | + EEH_Form_Fields::select_input( |
|
26 | + 'default_reg_status', |
|
27 | + $reg_status_array, |
|
28 | + $default_reg_status |
|
29 | + ), |
|
30 | + AllowedTags::getWithFormTags() |
|
31 | + ); ?> |
|
32 | 32 | </p> |
33 | 33 | <p class="description"> |
34 | 34 | <?php esc_html_e( |
35 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
36 | - 'event_espresso' |
|
37 | - ); ?> |
|
35 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
36 | + 'event_espresso' |
|
37 | + ); ?> |
|
38 | 38 | </p> |
39 | 39 | </td> |
40 | 40 | </tr> |
@@ -20,24 +20,24 @@ discard block |
||
20 | 20 | </th> |
21 | 21 | <td> |
22 | 22 | <?php echo wp_kses( |
23 | - EEH_Form_Fields::select_input( |
|
24 | - 'use_google_maps', |
|
25 | - $values, |
|
26 | - $map_settings->use_google_maps, |
|
27 | - 'id="ee-display-map-no-shortcodes"' |
|
28 | - ), |
|
29 | - AllowedTags::getWithFormTags() |
|
30 | - ); ?> |
|
23 | + EEH_Form_Fields::select_input( |
|
24 | + 'use_google_maps', |
|
25 | + $values, |
|
26 | + $map_settings->use_google_maps, |
|
27 | + 'id="ee-display-map-no-shortcodes"' |
|
28 | + ), |
|
29 | + AllowedTags::getWithFormTags() |
|
30 | + ); ?> |
|
31 | 31 | <p class="description"> |
32 | 32 | <?php esc_html_e( |
33 | - 'Turn Google maps on or off site wide for Event Espresso.', |
|
34 | - 'event_espresso' |
|
35 | - ); ?> |
|
33 | + 'Turn Google maps on or off site wide for Event Espresso.', |
|
34 | + 'event_espresso' |
|
35 | + ); ?> |
|
36 | 36 | </p> |
37 | 37 | </td> |
38 | 38 | </tr> |
39 | 39 | <?php |
40 | - if (apply_filters('FHEE__google_map__show_api_key_input', true)) { ?> |
|
40 | + if (apply_filters('FHEE__google_map__show_api_key_input', true)) { ?> |
|
41 | 41 | <tr> |
42 | 42 | <th> |
43 | 43 | <label for="ee-google-map-api-key"> |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | /> |
54 | 54 | <p class="description"> |
55 | 55 | <?php printf( |
56 | - esc_html__( |
|
57 | - 'An API key is now required to use the Google Maps API: %1$sclick here to get an API key%2$s', |
|
58 | - 'event_espresso' |
|
59 | - ), |
|
60 | - '<a href="https://console.developers.google.com/flows/enableapi?apiid=maps_backend,geocoding_backend,directions_backend,distance_matrix_backend,elevation_backend,static_maps_backend&keyType=CLIENT_SIDE&reusekey=true" target="_blank" rel="noopener noreferrer">', |
|
61 | - '</a>' |
|
62 | - ); |
|
63 | - ?> |
|
56 | + esc_html__( |
|
57 | + 'An API key is now required to use the Google Maps API: %1$sclick here to get an API key%2$s', |
|
58 | + 'event_espresso' |
|
59 | + ), |
|
60 | + '<a href="https://console.developers.google.com/flows/enableapi?apiid=maps_backend,geocoding_backend,directions_backend,distance_matrix_backend,elevation_backend,static_maps_backend&keyType=CLIENT_SIDE&reusekey=true" target="_blank" rel="noopener noreferrer">', |
|
61 | + '</a>' |
|
62 | + ); |
|
63 | + ?> |
|
64 | 64 | </p> |
65 | 65 | </td> |
66 | 66 | </tr> |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | </th> |
133 | 133 | <td> |
134 | 134 | <?php echo wp_kses( |
135 | - EEH_Form_Fields::select_input( |
|
136 | - 'event_details_display_nav', |
|
137 | - $values, |
|
138 | - $map_settings->event_details_display_nav, |
|
139 | - 'id="event_details_display_nav" ' |
|
140 | - ), |
|
141 | - AllowedTags::getWithFormTags() |
|
142 | - ); ?> |
|
135 | + EEH_Form_Fields::select_input( |
|
136 | + 'event_details_display_nav', |
|
137 | + $values, |
|
138 | + $map_settings->event_details_display_nav, |
|
139 | + 'id="event_details_display_nav" ' |
|
140 | + ), |
|
141 | + AllowedTags::getWithFormTags() |
|
142 | + ); ?> |
|
143 | 143 | </td> |
144 | 144 | </tr> |
145 | 145 | |
@@ -151,14 +151,14 @@ discard block |
||
151 | 151 | </th> |
152 | 152 | <td> |
153 | 153 | <?php echo wp_kses( |
154 | - EEH_Form_Fields::select_input( |
|
155 | - 'event_details_nav_size', |
|
156 | - $values, |
|
157 | - $map_settings->event_details_nav_size, |
|
158 | - 'id="event_details_nav_size"' |
|
159 | - ), |
|
160 | - AllowedTags::getWithFormTags() |
|
161 | - ); ?> |
|
154 | + EEH_Form_Fields::select_input( |
|
155 | + 'event_details_nav_size', |
|
156 | + $values, |
|
157 | + $map_settings->event_details_nav_size, |
|
158 | + 'id="event_details_nav_size"' |
|
159 | + ), |
|
160 | + AllowedTags::getWithFormTags() |
|
161 | + ); ?> |
|
162 | 162 | </td> |
163 | 163 | </tr> |
164 | 164 | |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | <td> |
170 | 170 | <label for="event_details_control_type-default" class="ee-admin-radio-lbl"> |
171 | 171 | <?php $checked = $map_settings->event_details_control_type == 'default' |
172 | - ? 'checked' |
|
173 | - : ''; ?> |
|
172 | + ? 'checked' |
|
173 | + : ''; ?> |
|
174 | 174 | <input id="event_details_control_type-default" |
175 | 175 | type="radio" |
176 | 176 | name="event_details_control_type" |
@@ -182,8 +182,8 @@ discard block |
||
182 | 182 | |
183 | 183 | <label for="event_details_control_type-horizontal" class="ee-admin-radio-lbl"> |
184 | 184 | <?php $checked = $map_settings->event_details_control_type == 'horizontal' |
185 | - ? 'checked' |
|
186 | - : ''; ?> |
|
185 | + ? 'checked' |
|
186 | + : ''; ?> |
|
187 | 187 | <input id="event_details_control_type-horizontal" |
188 | 188 | type="radio" |
189 | 189 | name="event_details_control_type" |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | |
196 | 196 | <label for="event_details_control_type-dropdown" class="ee-admin-radio-lbl"> |
197 | 197 | <?php $checked = $map_settings->event_details_control_type == 'dropdown' |
198 | - ? 'checked' |
|
199 | - : ''; ?> |
|
198 | + ? 'checked' |
|
199 | + : ''; ?> |
|
200 | 200 | <input id="event_details_control_type-dropdown" |
201 | 201 | type="radio" |
202 | 202 | name="event_details_control_type" |
@@ -214,8 +214,8 @@ discard block |
||
214 | 214 | <td> |
215 | 215 | <label for="event_details_map_align-none" class="ee-admin-radio-lbl"> |
216 | 216 | <?php $checked = $map_settings->event_details_map_align == 'none' |
217 | - ? 'checked' |
|
218 | - : ''; ?> |
|
217 | + ? 'checked' |
|
218 | + : ''; ?> |
|
219 | 219 | <input id="event_details_map_align-none" |
220 | 220 | type="radio" |
221 | 221 | name="event_details_map_align" |
@@ -227,8 +227,8 @@ discard block |
||
227 | 227 | |
228 | 228 | <label for="event_details_map_align-left" class="ee-admin-radio-lbl"> |
229 | 229 | <?php $checked = $map_settings->event_details_map_align == 'left' |
230 | - ? 'checked' |
|
231 | - : ''; ?> |
|
230 | + ? 'checked' |
|
231 | + : ''; ?> |
|
232 | 232 | <input id="event_details_map_align-left" |
233 | 233 | type="radio" |
234 | 234 | name="event_details_map_align" |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | |
241 | 241 | <label for="event_details_map_align-center" class="ee-admin-radio-lbl"> |
242 | 242 | <?php $checked = $map_settings->event_details_map_align == 'center' |
243 | - ? 'checked' |
|
244 | - : ''; ?> |
|
243 | + ? 'checked' |
|
244 | + : ''; ?> |
|
245 | 245 | <input id="event_details_map_align-center" |
246 | 246 | type="radio" |
247 | 247 | name="event_details_map_align" |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | |
254 | 254 | <label for="event_details_map_align-right" class="ee-admin-radio-lbl"> |
255 | 255 | <?php $checked = $map_settings->event_details_map_align == 'right' |
256 | - ? 'checked' |
|
257 | - : ''; ?> |
|
256 | + ? 'checked' |
|
257 | + : ''; ?> |
|
258 | 258 | <input id="event_details_map_align-right" |
259 | 259 | type="radio" |
260 | 260 | name="event_details_map_align" |
@@ -330,14 +330,14 @@ discard block |
||
330 | 330 | </th> |
331 | 331 | <td> |
332 | 332 | <?php echo wp_kses( |
333 | - EEH_Form_Fields::select_input( |
|
334 | - 'event_list_display_nav', |
|
335 | - $values, |
|
336 | - $map_settings->event_list_display_nav, |
|
337 | - 'id="event_list_display_nav"' |
|
338 | - ), |
|
339 | - AllowedTags::getWithFormTags() |
|
340 | - ); ?> |
|
333 | + EEH_Form_Fields::select_input( |
|
334 | + 'event_list_display_nav', |
|
335 | + $values, |
|
336 | + $map_settings->event_list_display_nav, |
|
337 | + 'id="event_list_display_nav"' |
|
338 | + ), |
|
339 | + AllowedTags::getWithFormTags() |
|
340 | + ); ?> |
|
341 | 341 | </td> |
342 | 342 | </tr> |
343 | 343 | |
@@ -349,14 +349,14 @@ discard block |
||
349 | 349 | </th> |
350 | 350 | <td> |
351 | 351 | <?php echo wp_kses( |
352 | - EEH_Form_Fields::select_input( |
|
353 | - 'event_list_nav_size', |
|
354 | - $values, |
|
355 | - $map_settings->event_list_nav_size, |
|
356 | - 'id="event_list_nav_size"' |
|
357 | - ), |
|
358 | - AllowedTags::getWithFormTags() |
|
359 | - ); ?> |
|
352 | + EEH_Form_Fields::select_input( |
|
353 | + 'event_list_nav_size', |
|
354 | + $values, |
|
355 | + $map_settings->event_list_nav_size, |
|
356 | + 'id="event_list_nav_size"' |
|
357 | + ), |
|
358 | + AllowedTags::getWithFormTags() |
|
359 | + ); ?> |
|
360 | 360 | </td> |
361 | 361 | </tr> |
362 | 362 | |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | <td> |
368 | 368 | <label for="event_list_control_type-default" class="ee-admin-radio-lbl"> |
369 | 369 | <?php $checked = $map_settings->event_list_control_type == 'default' |
370 | - ? 'checked' |
|
371 | - : ''; ?> |
|
370 | + ? 'checked' |
|
371 | + : ''; ?> |
|
372 | 372 | <input id="event_list_control_type-default" |
373 | 373 | type="radio" |
374 | 374 | name="event_list_control_type" |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | |
381 | 381 | <label for="event_list_control_type-horizontal" class="ee-admin-radio-lbl"> |
382 | 382 | <?php $checked = $map_settings->event_list_control_type == 'horizontal' |
383 | - ? 'checked' |
|
384 | - : ''; ?> |
|
383 | + ? 'checked' |
|
384 | + : ''; ?> |
|
385 | 385 | <input id="event_list_control_type-horizontal" |
386 | 386 | type="radio" |
387 | 387 | name="event_list_control_type" |
@@ -393,9 +393,9 @@ discard block |
||
393 | 393 | |
394 | 394 | <label for="event_list_control_type-dropdown" class="ee-admin-radio-lbl"> |
395 | 395 | <?php $checked = |
396 | - $map_settings->event_list_control_type == 'dropdown' |
|
397 | - ? 'checked' |
|
398 | - : ''; ?> |
|
396 | + $map_settings->event_list_control_type == 'dropdown' |
|
397 | + ? 'checked' |
|
398 | + : ''; ?> |
|
399 | 399 | <input id="event_list_control_type-dropdown" |
400 | 400 | type="radio" |
401 | 401 | name="event_list_control_type" |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | <td> |
416 | 416 | <label for="event_list_map_align-none" class="ee-admin-radio-lbl"> |
417 | 417 | <?php $checked = $map_settings->event_list_map_align == 'none' |
418 | - ? 'checked' |
|
419 | - : ''; ?> |
|
418 | + ? 'checked' |
|
419 | + : ''; ?> |
|
420 | 420 | <input id="event_list_map_align-none" |
421 | 421 | type="radio" |
422 | 422 | name="event_list_map_align" |
@@ -428,8 +428,8 @@ discard block |
||
428 | 428 | |
429 | 429 | <label for="event_list_map_align-left" class="ee-admin-radio-lbl"> |
430 | 430 | <?php $checked = $map_settings->event_list_map_align == 'left' |
431 | - ? 'checked' |
|
432 | - : ''; ?> |
|
431 | + ? 'checked' |
|
432 | + : ''; ?> |
|
433 | 433 | <input id="event_list_map_align-left" |
434 | 434 | type="radio" |
435 | 435 | name="event_list_map_align" |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | |
442 | 442 | <label for="event_list_map_align-center" class="ee-admin-radio-lbl"> |
443 | 443 | <?php $checked = $map_settings->event_list_map_align == 'center' |
444 | - ? 'checked' |
|
445 | - : ''; ?> |
|
444 | + ? 'checked' |
|
445 | + : ''; ?> |
|
446 | 446 | <input id="event_list_map_align-center" |
447 | 447 | type="radio" |
448 | 448 | name="event_list_map_align" |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | |
455 | 455 | <label for="event_list_map_align-right" class="ee-admin-radio-lbl"> |
456 | 456 | <?php $checked = $map_settings->event_list_map_align == 'right' |
457 | - ? 'checked' |
|
458 | - : ''; ?> |
|
457 | + ? 'checked' |
|
458 | + : ''; ?> |
|
459 | 459 | <input id="event_list_map_align-right" |
460 | 460 | type="radio" |
461 | 461 | name="event_list_map_align" |
@@ -54,61 +54,61 @@ discard block |
||
54 | 54 | ), |
55 | 55 | ], |
56 | 56 | ]; |
57 | - $this->_model_relations = [ |
|
57 | + $this->_model_relations = [ |
|
58 | 58 | 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
59 | 59 | ]; |
60 | 60 | foreach ($models_this_can_attach_to as $model_name) { |
61 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
61 | + $this->_model_relations[$model_name] = new EE_Belongs_To_Relation(); |
|
62 | 62 | } |
63 | 63 | $this->_wp_core_model = true; |
64 | 64 | $this->_indexes = [ |
65 | 65 | 'PRIMARY' => new EE_Primary_Key_Index(['object_id', 'term_taxonomy_id']), |
66 | 66 | ]; |
67 | 67 | $path_to_event_model = 'Event'; |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = |
|
69 | 69 | new EE_Restriction_Generator_Event_Related_Public( |
70 | 70 | $path_to_event_model |
71 | 71 | ); |
72 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
72 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
73 | 73 | new EE_Restriction_Generator_Event_Related_Protected( |
74 | 74 | $path_to_event_model |
75 | 75 | ); |
76 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
76 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = |
|
77 | 77 | new EE_Restriction_Generator_Event_Related_Protected( |
78 | 78 | $path_to_event_model |
79 | 79 | ); |
80 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
80 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
81 | 81 | new EE_Restriction_Generator_Event_Related_Protected( |
82 | 82 | $path_to_event_model, |
83 | 83 | EEM_Base::caps_edit |
84 | 84 | ); |
85 | - $path_to_tax_model = 'Term_Taxonomy.'; |
|
85 | + $path_to_tax_model = 'Term_Taxonomy.'; |
|
86 | 86 | // add cap restrictions for editing term relations to the "ee_assign_*" |
87 | 87 | // and for deleting term relations too |
88 | 88 | $cap_contexts_affected = [EEM_Base::caps_edit, EEM_Base::caps_delete]; |
89 | 89 | foreach ($cap_contexts_affected as $cap_context_affected) { |
90 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
90 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] = |
|
91 | 91 | new EE_Default_Where_Conditions( |
92 | 92 | [ |
93 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => [ |
|
93 | + $path_to_tax_model.'taxonomy*ee_assign_event_category' => [ |
|
94 | 94 | '!=', |
95 | 95 | 'espresso_event_categories', |
96 | 96 | ], |
97 | 97 | ] |
98 | 98 | ); |
99 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
99 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] = |
|
100 | 100 | new EE_Default_Where_Conditions( |
101 | 101 | [ |
102 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => [ |
|
102 | + $path_to_tax_model.'taxonomy*ee_assign_venue_category' => [ |
|
103 | 103 | '!=', |
104 | 104 | 'espresso_venue_categories', |
105 | 105 | ], |
106 | 106 | ] |
107 | 107 | ); |
108 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = |
|
108 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = |
|
109 | 109 | new EE_Default_Where_Conditions( |
110 | 110 | [ |
111 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => ['!=', 'espresso_event_type'], |
|
111 | + $path_to_tax_model.'taxonomy*ee_assign_event_type' => ['!=', 'espresso_event_type'], |
|
112 | 112 | ] |
113 | 113 | ); |
114 | 114 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | { |
252 | 252 | if ($model === EEM_Term_Relationship::instance()) { |
253 | 253 | $taxonomies = get_taxonomies(['show_in_rest' => true]); |
254 | - if (! empty($taxonomies)) { |
|
254 | + if ( ! empty($taxonomies)) { |
|
255 | 255 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies]; |
256 | 256 | } |
257 | 257 | } |
@@ -9,236 +9,236 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Term_Relationship extends EEM_Base |
11 | 11 | { |
12 | - protected static ?EEM_Term_Relationship $_instance = null; |
|
12 | + protected static ?EEM_Term_Relationship $_instance = null; |
|
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * EEM_Term_Relationship constructor. |
|
17 | - * |
|
18 | - * @param string|null $timezone |
|
19 | - * @throws EE_Error |
|
20 | - */ |
|
21 | - protected function __construct(?string $timezone = '') |
|
22 | - { |
|
23 | - $this->singular_item = esc_html__('Term Relationship', 'event_espresso'); |
|
24 | - $this->plural_item = esc_html__('Term Relationships', 'event_espresso'); |
|
25 | - $this->_tables = [ |
|
26 | - 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
27 | - ]; |
|
28 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
29 | - $this->_fields = [ |
|
30 | - 'Term_Relationship' => [ |
|
31 | - 'object_id' => new EE_Foreign_Key_Int_Field( |
|
32 | - 'object_id', |
|
33 | - esc_html__('Object(Post) ID', 'event_espresso'), |
|
34 | - false, |
|
35 | - 0, |
|
36 | - $models_this_can_attach_to |
|
37 | - ), |
|
38 | - 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
39 | - 'term_taxonomy_id', |
|
40 | - esc_html__( |
|
41 | - 'Term (in context of a taxonomy) ID', |
|
42 | - 'event_espresso' |
|
43 | - ), |
|
44 | - false, |
|
45 | - 0, |
|
46 | - 'Term_Taxonomy' |
|
47 | - ), |
|
48 | - 'term_order' => new EE_Integer_Field( |
|
49 | - 'term_order', |
|
50 | - esc_html__('Term Order', 'event_espresso'), |
|
51 | - false, |
|
52 | - 0 |
|
53 | - ), |
|
54 | - ], |
|
55 | - ]; |
|
56 | - $this->_model_relations = [ |
|
57 | - 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
58 | - ]; |
|
59 | - foreach ($models_this_can_attach_to as $model_name) { |
|
60 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
61 | - } |
|
62 | - $this->_wp_core_model = true; |
|
63 | - $this->_indexes = [ |
|
64 | - 'PRIMARY' => new EE_Primary_Key_Index(['object_id', 'term_taxonomy_id']), |
|
65 | - ]; |
|
66 | - $path_to_event_model = 'Event'; |
|
67 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
68 | - new EE_Restriction_Generator_Event_Related_Public( |
|
69 | - $path_to_event_model |
|
70 | - ); |
|
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
72 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
73 | - $path_to_event_model |
|
74 | - ); |
|
75 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
76 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
77 | - $path_to_event_model |
|
78 | - ); |
|
79 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
80 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
81 | - $path_to_event_model, |
|
82 | - EEM_Base::caps_edit |
|
83 | - ); |
|
84 | - $path_to_tax_model = 'Term_Taxonomy.'; |
|
85 | - // add cap restrictions for editing term relations to the "ee_assign_*" |
|
86 | - // and for deleting term relations too |
|
87 | - $cap_contexts_affected = [EEM_Base::caps_edit, EEM_Base::caps_delete]; |
|
88 | - foreach ($cap_contexts_affected as $cap_context_affected) { |
|
89 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
90 | - new EE_Default_Where_Conditions( |
|
91 | - [ |
|
92 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => [ |
|
93 | - '!=', |
|
94 | - 'espresso_event_categories', |
|
95 | - ], |
|
96 | - ] |
|
97 | - ); |
|
98 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
99 | - new EE_Default_Where_Conditions( |
|
100 | - [ |
|
101 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => [ |
|
102 | - '!=', |
|
103 | - 'espresso_venue_categories', |
|
104 | - ], |
|
105 | - ] |
|
106 | - ); |
|
107 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = |
|
108 | - new EE_Default_Where_Conditions( |
|
109 | - [ |
|
110 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => ['!=', 'espresso_event_type'], |
|
111 | - ] |
|
112 | - ); |
|
113 | - } |
|
114 | - parent::__construct($timezone); |
|
115 | - add_filter( |
|
116 | - 'FHEE__Read__create_model_query_params', |
|
117 | - ['EEM_Term_Relationship', 'rest_api_query_params'], |
|
118 | - 10, |
|
119 | - 3 |
|
120 | - ); |
|
121 | - } |
|
15 | + /** |
|
16 | + * EEM_Term_Relationship constructor. |
|
17 | + * |
|
18 | + * @param string|null $timezone |
|
19 | + * @throws EE_Error |
|
20 | + */ |
|
21 | + protected function __construct(?string $timezone = '') |
|
22 | + { |
|
23 | + $this->singular_item = esc_html__('Term Relationship', 'event_espresso'); |
|
24 | + $this->plural_item = esc_html__('Term Relationships', 'event_espresso'); |
|
25 | + $this->_tables = [ |
|
26 | + 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
27 | + ]; |
|
28 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
29 | + $this->_fields = [ |
|
30 | + 'Term_Relationship' => [ |
|
31 | + 'object_id' => new EE_Foreign_Key_Int_Field( |
|
32 | + 'object_id', |
|
33 | + esc_html__('Object(Post) ID', 'event_espresso'), |
|
34 | + false, |
|
35 | + 0, |
|
36 | + $models_this_can_attach_to |
|
37 | + ), |
|
38 | + 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
39 | + 'term_taxonomy_id', |
|
40 | + esc_html__( |
|
41 | + 'Term (in context of a taxonomy) ID', |
|
42 | + 'event_espresso' |
|
43 | + ), |
|
44 | + false, |
|
45 | + 0, |
|
46 | + 'Term_Taxonomy' |
|
47 | + ), |
|
48 | + 'term_order' => new EE_Integer_Field( |
|
49 | + 'term_order', |
|
50 | + esc_html__('Term Order', 'event_espresso'), |
|
51 | + false, |
|
52 | + 0 |
|
53 | + ), |
|
54 | + ], |
|
55 | + ]; |
|
56 | + $this->_model_relations = [ |
|
57 | + 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
58 | + ]; |
|
59 | + foreach ($models_this_can_attach_to as $model_name) { |
|
60 | + $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
61 | + } |
|
62 | + $this->_wp_core_model = true; |
|
63 | + $this->_indexes = [ |
|
64 | + 'PRIMARY' => new EE_Primary_Key_Index(['object_id', 'term_taxonomy_id']), |
|
65 | + ]; |
|
66 | + $path_to_event_model = 'Event'; |
|
67 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
68 | + new EE_Restriction_Generator_Event_Related_Public( |
|
69 | + $path_to_event_model |
|
70 | + ); |
|
71 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
72 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
73 | + $path_to_event_model |
|
74 | + ); |
|
75 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
76 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
77 | + $path_to_event_model |
|
78 | + ); |
|
79 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
80 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
81 | + $path_to_event_model, |
|
82 | + EEM_Base::caps_edit |
|
83 | + ); |
|
84 | + $path_to_tax_model = 'Term_Taxonomy.'; |
|
85 | + // add cap restrictions for editing term relations to the "ee_assign_*" |
|
86 | + // and for deleting term relations too |
|
87 | + $cap_contexts_affected = [EEM_Base::caps_edit, EEM_Base::caps_delete]; |
|
88 | + foreach ($cap_contexts_affected as $cap_context_affected) { |
|
89 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
90 | + new EE_Default_Where_Conditions( |
|
91 | + [ |
|
92 | + $path_to_tax_model . 'taxonomy*ee_assign_event_category' => [ |
|
93 | + '!=', |
|
94 | + 'espresso_event_categories', |
|
95 | + ], |
|
96 | + ] |
|
97 | + ); |
|
98 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
99 | + new EE_Default_Where_Conditions( |
|
100 | + [ |
|
101 | + $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => [ |
|
102 | + '!=', |
|
103 | + 'espresso_venue_categories', |
|
104 | + ], |
|
105 | + ] |
|
106 | + ); |
|
107 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = |
|
108 | + new EE_Default_Where_Conditions( |
|
109 | + [ |
|
110 | + $path_to_tax_model . 'taxonomy*ee_assign_event_type' => ['!=', 'espresso_event_type'], |
|
111 | + ] |
|
112 | + ); |
|
113 | + } |
|
114 | + parent::__construct($timezone); |
|
115 | + add_filter( |
|
116 | + 'FHEE__Read__create_model_query_params', |
|
117 | + ['EEM_Term_Relationship', 'rest_api_query_params'], |
|
118 | + 10, |
|
119 | + 3 |
|
120 | + ); |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * Makes sure all term-taxonomy counts are correct |
|
126 | - * |
|
127 | - * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
128 | - * @return int the number of rows affected |
|
129 | - * @throws EE_Error |
|
130 | - * @global wpdb $wpdb |
|
131 | - */ |
|
132 | - public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
133 | - { |
|
134 | - // because this uses a subquery and sometimes assigning to column to be another column's |
|
135 | - // value, we just write the SQL directly. |
|
136 | - global $wpdb; |
|
124 | + /** |
|
125 | + * Makes sure all term-taxonomy counts are correct |
|
126 | + * |
|
127 | + * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
128 | + * @return int the number of rows affected |
|
129 | + * @throws EE_Error |
|
130 | + * @global wpdb $wpdb |
|
131 | + */ |
|
132 | + public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
133 | + { |
|
134 | + // because this uses a subquery and sometimes assigning to column to be another column's |
|
135 | + // value, we just write the SQL directly. |
|
136 | + global $wpdb; |
|
137 | 137 | |
138 | - $query = " |
|
138 | + $query = " |
|
139 | 139 | UPDATE {$wpdb->term_taxonomy} AS tt |
140 | 140 | SET count = ( |
141 | 141 | select count(*) as proper_count from {$wpdb->term_relationships} AS tr |
142 | 142 | WHERE tt.term_taxonomy_id = tr.term_taxonomy_id |
143 | 143 | )"; |
144 | 144 | |
145 | - if ($term_taxonomy_id) { |
|
146 | - $query .= ' WHERE tt.term_taxonomy_id = %d'; |
|
147 | - $query = $wpdb->prepare( |
|
148 | - $query, |
|
149 | - $term_taxonomy_id |
|
150 | - ); |
|
151 | - } |
|
152 | - $rows_affected = $this->_do_wpdb_query( |
|
153 | - 'query', |
|
154 | - [ |
|
155 | - $query, |
|
156 | - ] |
|
157 | - ); |
|
158 | - return $rows_affected; |
|
159 | - } |
|
145 | + if ($term_taxonomy_id) { |
|
146 | + $query .= ' WHERE tt.term_taxonomy_id = %d'; |
|
147 | + $query = $wpdb->prepare( |
|
148 | + $query, |
|
149 | + $term_taxonomy_id |
|
150 | + ); |
|
151 | + } |
|
152 | + $rows_affected = $this->_do_wpdb_query( |
|
153 | + 'query', |
|
154 | + [ |
|
155 | + $query, |
|
156 | + ] |
|
157 | + ); |
|
158 | + return $rows_affected; |
|
159 | + } |
|
160 | 160 | |
161 | 161 | |
162 | - /** |
|
163 | - * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
164 | - * inserting |
|
165 | - * |
|
166 | - * @param array $field_n_values @see EEM_Base::insert |
|
167 | - * @return boolean |
|
168 | - */ |
|
169 | - public function insert($field_n_values) |
|
170 | - { |
|
171 | - $return = parent::insert($field_n_values); |
|
172 | - if (isset($field_n_values['term_taxonomy_id'])) { |
|
173 | - $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
174 | - } |
|
175 | - return $return; |
|
176 | - } |
|
162 | + /** |
|
163 | + * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
164 | + * inserting |
|
165 | + * |
|
166 | + * @param array $field_n_values @see EEM_Base::insert |
|
167 | + * @return boolean |
|
168 | + */ |
|
169 | + public function insert($field_n_values) |
|
170 | + { |
|
171 | + $return = parent::insert($field_n_values); |
|
172 | + if (isset($field_n_values['term_taxonomy_id'])) { |
|
173 | + $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
174 | + } |
|
175 | + return $return; |
|
176 | + } |
|
177 | 177 | |
178 | 178 | |
179 | - /** |
|
180 | - * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | - * all ok |
|
182 | - * |
|
183 | - * @param array $fields_n_values see EEM_Base::update |
|
184 | - * @param array $query_params @see |
|
185 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
186 | - * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
187 | - * in this model's entity map according to $fields_n_values that match |
|
188 | - * $query_params. This obviously has some overhead, so you can disable it |
|
189 | - * by setting this to FALSE, but be aware that model objects being used |
|
190 | - * could get out-of-sync with the database |
|
191 | - * @return int |
|
192 | - */ |
|
193 | - public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
194 | - { |
|
195 | - $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
196 | - if ($count) { |
|
197 | - $this->update_term_taxonomy_counts(); |
|
198 | - } |
|
199 | - return $count; |
|
200 | - } |
|
179 | + /** |
|
180 | + * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | + * all ok |
|
182 | + * |
|
183 | + * @param array $fields_n_values see EEM_Base::update |
|
184 | + * @param array $query_params @see |
|
185 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
186 | + * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
187 | + * in this model's entity map according to $fields_n_values that match |
|
188 | + * $query_params. This obviously has some overhead, so you can disable it |
|
189 | + * by setting this to FALSE, but be aware that model objects being used |
|
190 | + * could get out-of-sync with the database |
|
191 | + * @return int |
|
192 | + */ |
|
193 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
194 | + { |
|
195 | + $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
196 | + if ($count) { |
|
197 | + $this->update_term_taxonomy_counts(); |
|
198 | + } |
|
199 | + return $count; |
|
200 | + } |
|
201 | 201 | |
202 | 202 | |
203 | - /** |
|
204 | - * Overrides parent so that after running this, we also double-check |
|
205 | - * the term taxonomy counts are up-to-date |
|
206 | - * |
|
207 | - * @param array $query_params |
|
208 | - * @param boolean $block_deletes |
|
209 | - * @return int |
|
210 | - * @throws EE_Error |
|
211 | - * @throws ReflectionException |
|
212 | - * @see EEM_Base::delete() |
|
213 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
214 | - */ |
|
215 | - public function delete($query_params, $block_deletes = true) |
|
216 | - { |
|
217 | - $count = parent::delete($query_params, $block_deletes); |
|
218 | - if ($count) { |
|
219 | - $this->update_term_taxonomy_counts(); |
|
220 | - } |
|
221 | - return $count; |
|
222 | - } |
|
203 | + /** |
|
204 | + * Overrides parent so that after running this, we also double-check |
|
205 | + * the term taxonomy counts are up-to-date |
|
206 | + * |
|
207 | + * @param array $query_params |
|
208 | + * @param boolean $block_deletes |
|
209 | + * @return int |
|
210 | + * @throws EE_Error |
|
211 | + * @throws ReflectionException |
|
212 | + * @see EEM_Base::delete() |
|
213 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
214 | + */ |
|
215 | + public function delete($query_params, $block_deletes = true) |
|
216 | + { |
|
217 | + $count = parent::delete($query_params, $block_deletes); |
|
218 | + if ($count) { |
|
219 | + $this->update_term_taxonomy_counts(); |
|
220 | + } |
|
221 | + return $count; |
|
222 | + } |
|
223 | 223 | |
224 | 224 | |
225 | - /** |
|
226 | - * Makes sure that during REST API queries, we only return term relationships |
|
227 | - * for term taxonomies which should be shown in the rest api |
|
228 | - * |
|
229 | - * @param array $model_query_params |
|
230 | - * @param array $querystring_query_params |
|
231 | - * @param EEM_Base $model |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
235 | - { |
|
236 | - if ($model === EEM_Term_Relationship::instance()) { |
|
237 | - $taxonomies = get_taxonomies(['show_in_rest' => true]); |
|
238 | - if (! empty($taxonomies)) { |
|
239 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies]; |
|
240 | - } |
|
241 | - } |
|
242 | - return $model_query_params; |
|
243 | - } |
|
225 | + /** |
|
226 | + * Makes sure that during REST API queries, we only return term relationships |
|
227 | + * for term taxonomies which should be shown in the rest api |
|
228 | + * |
|
229 | + * @param array $model_query_params |
|
230 | + * @param array $querystring_query_params |
|
231 | + * @param EEM_Base $model |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
235 | + { |
|
236 | + if ($model === EEM_Term_Relationship::instance()) { |
|
237 | + $taxonomies = get_taxonomies(['show_in_rest' => true]); |
|
238 | + if (! empty($taxonomies)) { |
|
239 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = ['IN', $taxonomies]; |
|
240 | + } |
|
241 | + } |
|
242 | + return $model_query_params; |
|
243 | + } |
|
244 | 244 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0) |
56 | 56 | { |
57 | 57 | parent::__construct($iLineNo); |
58 | - $this->fSize = (float)$fSize; |
|
58 | + $this->fSize = (float) $fSize; |
|
59 | 59 | $this->sUnit = $sUnit; |
60 | 60 | $this->bIsColorComponent = $bIsColorComponent; |
61 | 61 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
96 | - return new Size((float)$sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); |
|
96 | + return new Size((float) $sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | */ |
102 | 102 | private static function getSizeUnits() |
103 | 103 | { |
104 | - if (!is_array(self::$SIZE_UNITS)) { |
|
104 | + if ( ! is_array(self::$SIZE_UNITS)) { |
|
105 | 105 | self::$SIZE_UNITS = []; |
106 | 106 | foreach (array_merge(self::ABSOLUTE_SIZE_UNITS, self::RELATIVE_SIZE_UNITS, self::NON_SIZE_UNITS) as $val) { |
107 | 107 | $iSize = strlen($val); |
108 | - if (!isset(self::$SIZE_UNITS[$iSize])) { |
|
108 | + if ( ! isset(self::$SIZE_UNITS[$iSize])) { |
|
109 | 109 | self::$SIZE_UNITS[$iSize] = []; |
110 | 110 | } |
111 | 111 | self::$SIZE_UNITS[$iSize][strtolower($val)] = $val; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function setSize($fSize) |
142 | 142 | { |
143 | - $this->fSize = (float)$fSize; |
|
143 | + $this->fSize = (float) $fSize; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | if (in_array($this->sUnit, self::NON_SIZE_UNITS, true)) { |
170 | 170 | return false; |
171 | 171 | } |
172 | - return !$this->isColorComponent(); |
|
172 | + return ! $this->isColorComponent(); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | { |
202 | 202 | $l = localeconv(); |
203 | 203 | $sPoint = preg_quote($l['decimal_point'], '/'); |
204 | - $sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string)$this->fSize) |
|
204 | + $sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string) $this->fSize) |
|
205 | 205 | ? preg_replace("/$sPoint?0+$/", "", sprintf("%f", $this->fSize)) : $this->fSize; |
206 | 206 | return preg_replace(["/$sPoint/", "/^(-?)0\./"], ['.', '$1.'], $sSize) |
207 | 207 | . ($this->sUnit === null ? '' : $this->sUnit); |
@@ -12,219 +12,219 @@ |
||
12 | 12 | */ |
13 | 13 | class Size extends PrimitiveValue |
14 | 14 | { |
15 | - /** |
|
16 | - * vh/vw/vm(ax)/vmin/rem are absolute insofar as they don’t scale to the immediate parent (only the viewport) |
|
17 | - * |
|
18 | - * @var array<int, string> |
|
19 | - * |
|
20 | - * @internal |
|
21 | - */ |
|
22 | - const ABSOLUTE_SIZE_UNITS = [ |
|
23 | - 'px', 'pt', 'pc', |
|
24 | - 'cm', 'mm', 'mozmm', 'in', |
|
25 | - 'vh', 'dvh', 'svh', 'lvh', |
|
26 | - 'vw', 'vmin', 'vmax', 'rem', |
|
27 | - ]; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var array<int, string> |
|
31 | - * |
|
32 | - * @internal |
|
33 | - */ |
|
34 | - const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr']; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var array<int, string> |
|
38 | - * |
|
39 | - * @internal |
|
40 | - */ |
|
41 | - const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz']; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var array<int, array<string, string>>|null |
|
45 | - */ |
|
46 | - private static $SIZE_UNITS = null; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var float |
|
50 | - */ |
|
51 | - private $fSize; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string|null |
|
55 | - */ |
|
56 | - private $sUnit; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var bool |
|
60 | - */ |
|
61 | - private $bIsColorComponent; |
|
62 | - |
|
63 | - /** |
|
64 | - * @param float|int|string $fSize |
|
65 | - * @param string|null $sUnit |
|
66 | - * @param bool $bIsColorComponent |
|
67 | - * @param int $iLineNo |
|
68 | - */ |
|
69 | - public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0) |
|
70 | - { |
|
71 | - parent::__construct($iLineNo); |
|
72 | - $this->fSize = (float)$fSize; |
|
73 | - $this->sUnit = $sUnit; |
|
74 | - $this->bIsColorComponent = $bIsColorComponent; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * @param bool $bIsColorComponent |
|
79 | - * |
|
80 | - * @return Size |
|
81 | - * |
|
82 | - * @throws UnexpectedEOFException |
|
83 | - * @throws UnexpectedTokenException |
|
84 | - */ |
|
85 | - public static function parse(ParserState $oParserState, $bIsColorComponent = false) |
|
86 | - { |
|
87 | - $sSize = ''; |
|
88 | - if ($oParserState->comes('-')) { |
|
89 | - $sSize .= $oParserState->consume('-'); |
|
90 | - } |
|
91 | - while (is_numeric($oParserState->peek()) || $oParserState->comes('.') || $oParserState->comes('e', true)) { |
|
92 | - if ($oParserState->comes('.')) { |
|
93 | - $sSize .= $oParserState->consume('.'); |
|
94 | - } elseif ($oParserState->comes('e', true)) { |
|
95 | - $sLookahead = $oParserState->peek(1, 1); |
|
96 | - if (is_numeric($sLookahead) || $sLookahead === '+' || $sLookahead === '-') { |
|
97 | - $sSize .= $oParserState->consume(2); |
|
98 | - } else { |
|
99 | - break; // Reached the unit part of the number like "em" or "ex" |
|
100 | - } |
|
101 | - } else { |
|
102 | - $sSize .= $oParserState->consume(1); |
|
103 | - } |
|
104 | - } |
|
105 | - |
|
106 | - $sUnit = null; |
|
107 | - $aSizeUnits = self::getSizeUnits(); |
|
108 | - foreach ($aSizeUnits as $iLength => &$aValues) { |
|
109 | - $sKey = strtolower($oParserState->peek($iLength)); |
|
110 | - if (array_key_exists($sKey, $aValues)) { |
|
111 | - if (($sUnit = $aValues[$sKey]) !== null) { |
|
112 | - $oParserState->consume($iLength); |
|
113 | - break; |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
117 | - return new Size((float)$sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return array<int, array<string, string>> |
|
122 | - */ |
|
123 | - private static function getSizeUnits() |
|
124 | - { |
|
125 | - if (!is_array(self::$SIZE_UNITS)) { |
|
126 | - self::$SIZE_UNITS = []; |
|
127 | - foreach (array_merge(self::ABSOLUTE_SIZE_UNITS, self::RELATIVE_SIZE_UNITS, self::NON_SIZE_UNITS) as $val) { |
|
128 | - $iSize = strlen($val); |
|
129 | - if (!isset(self::$SIZE_UNITS[$iSize])) { |
|
130 | - self::$SIZE_UNITS[$iSize] = []; |
|
131 | - } |
|
132 | - self::$SIZE_UNITS[$iSize][strtolower($val)] = $val; |
|
133 | - } |
|
134 | - |
|
135 | - krsort(self::$SIZE_UNITS, SORT_NUMERIC); |
|
136 | - } |
|
137 | - |
|
138 | - return self::$SIZE_UNITS; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @param string $sUnit |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public function setUnit($sUnit) |
|
147 | - { |
|
148 | - $this->sUnit = $sUnit; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @return string|null |
|
153 | - */ |
|
154 | - public function getUnit() |
|
155 | - { |
|
156 | - return $this->sUnit; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @param float|int|string $fSize |
|
161 | - */ |
|
162 | - public function setSize($fSize) |
|
163 | - { |
|
164 | - $this->fSize = (float)$fSize; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @return float |
|
169 | - */ |
|
170 | - public function getSize() |
|
171 | - { |
|
172 | - return $this->fSize; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - public function isColorComponent() |
|
179 | - { |
|
180 | - return $this->bIsColorComponent; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Returns whether the number stored in this Size really represents a size (as in a length of something on screen). |
|
185 | - * |
|
186 | - * @return false if the unit an angle, a duration, a frequency or the number is a component in a Color object. |
|
187 | - */ |
|
188 | - public function isSize() |
|
189 | - { |
|
190 | - if (in_array($this->sUnit, self::NON_SIZE_UNITS, true)) { |
|
191 | - return false; |
|
192 | - } |
|
193 | - return !$this->isColorComponent(); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function isRelative() |
|
200 | - { |
|
201 | - if (in_array($this->sUnit, self::RELATIVE_SIZE_UNITS, true)) { |
|
202 | - return true; |
|
203 | - } |
|
204 | - if ($this->sUnit === null && $this->fSize != 0) { |
|
205 | - return true; |
|
206 | - } |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - /** |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - public function __toString() |
|
214 | - { |
|
215 | - return $this->render(new OutputFormat()); |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - public function render(OutputFormat $oOutputFormat) |
|
222 | - { |
|
223 | - $l = localeconv(); |
|
224 | - $sPoint = preg_quote($l['decimal_point'], '/'); |
|
225 | - $sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string)$this->fSize) |
|
226 | - ? preg_replace("/$sPoint?0+$/", "", sprintf("%f", $this->fSize)) : $this->fSize; |
|
227 | - return preg_replace(["/$sPoint/", "/^(-?)0\./"], ['.', '$1.'], $sSize) |
|
228 | - . ($this->sUnit === null ? '' : $this->sUnit); |
|
229 | - } |
|
15 | + /** |
|
16 | + * vh/vw/vm(ax)/vmin/rem are absolute insofar as they don’t scale to the immediate parent (only the viewport) |
|
17 | + * |
|
18 | + * @var array<int, string> |
|
19 | + * |
|
20 | + * @internal |
|
21 | + */ |
|
22 | + const ABSOLUTE_SIZE_UNITS = [ |
|
23 | + 'px', 'pt', 'pc', |
|
24 | + 'cm', 'mm', 'mozmm', 'in', |
|
25 | + 'vh', 'dvh', 'svh', 'lvh', |
|
26 | + 'vw', 'vmin', 'vmax', 'rem', |
|
27 | + ]; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var array<int, string> |
|
31 | + * |
|
32 | + * @internal |
|
33 | + */ |
|
34 | + const RELATIVE_SIZE_UNITS = ['%', 'em', 'ex', 'ch', 'fr']; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var array<int, string> |
|
38 | + * |
|
39 | + * @internal |
|
40 | + */ |
|
41 | + const NON_SIZE_UNITS = ['deg', 'grad', 'rad', 's', 'ms', 'turn', 'Hz', 'kHz']; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var array<int, array<string, string>>|null |
|
45 | + */ |
|
46 | + private static $SIZE_UNITS = null; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var float |
|
50 | + */ |
|
51 | + private $fSize; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string|null |
|
55 | + */ |
|
56 | + private $sUnit; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var bool |
|
60 | + */ |
|
61 | + private $bIsColorComponent; |
|
62 | + |
|
63 | + /** |
|
64 | + * @param float|int|string $fSize |
|
65 | + * @param string|null $sUnit |
|
66 | + * @param bool $bIsColorComponent |
|
67 | + * @param int $iLineNo |
|
68 | + */ |
|
69 | + public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $iLineNo = 0) |
|
70 | + { |
|
71 | + parent::__construct($iLineNo); |
|
72 | + $this->fSize = (float)$fSize; |
|
73 | + $this->sUnit = $sUnit; |
|
74 | + $this->bIsColorComponent = $bIsColorComponent; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * @param bool $bIsColorComponent |
|
79 | + * |
|
80 | + * @return Size |
|
81 | + * |
|
82 | + * @throws UnexpectedEOFException |
|
83 | + * @throws UnexpectedTokenException |
|
84 | + */ |
|
85 | + public static function parse(ParserState $oParserState, $bIsColorComponent = false) |
|
86 | + { |
|
87 | + $sSize = ''; |
|
88 | + if ($oParserState->comes('-')) { |
|
89 | + $sSize .= $oParserState->consume('-'); |
|
90 | + } |
|
91 | + while (is_numeric($oParserState->peek()) || $oParserState->comes('.') || $oParserState->comes('e', true)) { |
|
92 | + if ($oParserState->comes('.')) { |
|
93 | + $sSize .= $oParserState->consume('.'); |
|
94 | + } elseif ($oParserState->comes('e', true)) { |
|
95 | + $sLookahead = $oParserState->peek(1, 1); |
|
96 | + if (is_numeric($sLookahead) || $sLookahead === '+' || $sLookahead === '-') { |
|
97 | + $sSize .= $oParserState->consume(2); |
|
98 | + } else { |
|
99 | + break; // Reached the unit part of the number like "em" or "ex" |
|
100 | + } |
|
101 | + } else { |
|
102 | + $sSize .= $oParserState->consume(1); |
|
103 | + } |
|
104 | + } |
|
105 | + |
|
106 | + $sUnit = null; |
|
107 | + $aSizeUnits = self::getSizeUnits(); |
|
108 | + foreach ($aSizeUnits as $iLength => &$aValues) { |
|
109 | + $sKey = strtolower($oParserState->peek($iLength)); |
|
110 | + if (array_key_exists($sKey, $aValues)) { |
|
111 | + if (($sUnit = $aValues[$sKey]) !== null) { |
|
112 | + $oParserState->consume($iLength); |
|
113 | + break; |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | + return new Size((float)$sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return array<int, array<string, string>> |
|
122 | + */ |
|
123 | + private static function getSizeUnits() |
|
124 | + { |
|
125 | + if (!is_array(self::$SIZE_UNITS)) { |
|
126 | + self::$SIZE_UNITS = []; |
|
127 | + foreach (array_merge(self::ABSOLUTE_SIZE_UNITS, self::RELATIVE_SIZE_UNITS, self::NON_SIZE_UNITS) as $val) { |
|
128 | + $iSize = strlen($val); |
|
129 | + if (!isset(self::$SIZE_UNITS[$iSize])) { |
|
130 | + self::$SIZE_UNITS[$iSize] = []; |
|
131 | + } |
|
132 | + self::$SIZE_UNITS[$iSize][strtolower($val)] = $val; |
|
133 | + } |
|
134 | + |
|
135 | + krsort(self::$SIZE_UNITS, SORT_NUMERIC); |
|
136 | + } |
|
137 | + |
|
138 | + return self::$SIZE_UNITS; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @param string $sUnit |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public function setUnit($sUnit) |
|
147 | + { |
|
148 | + $this->sUnit = $sUnit; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @return string|null |
|
153 | + */ |
|
154 | + public function getUnit() |
|
155 | + { |
|
156 | + return $this->sUnit; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @param float|int|string $fSize |
|
161 | + */ |
|
162 | + public function setSize($fSize) |
|
163 | + { |
|
164 | + $this->fSize = (float)$fSize; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @return float |
|
169 | + */ |
|
170 | + public function getSize() |
|
171 | + { |
|
172 | + return $this->fSize; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + public function isColorComponent() |
|
179 | + { |
|
180 | + return $this->bIsColorComponent; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Returns whether the number stored in this Size really represents a size (as in a length of something on screen). |
|
185 | + * |
|
186 | + * @return false if the unit an angle, a duration, a frequency or the number is a component in a Color object. |
|
187 | + */ |
|
188 | + public function isSize() |
|
189 | + { |
|
190 | + if (in_array($this->sUnit, self::NON_SIZE_UNITS, true)) { |
|
191 | + return false; |
|
192 | + } |
|
193 | + return !$this->isColorComponent(); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function isRelative() |
|
200 | + { |
|
201 | + if (in_array($this->sUnit, self::RELATIVE_SIZE_UNITS, true)) { |
|
202 | + return true; |
|
203 | + } |
|
204 | + if ($this->sUnit === null && $this->fSize != 0) { |
|
205 | + return true; |
|
206 | + } |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + /** |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public function __toString() |
|
214 | + { |
|
215 | + return $this->render(new OutputFormat()); |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + public function render(OutputFormat $oOutputFormat) |
|
222 | + { |
|
223 | + $l = localeconv(); |
|
224 | + $sPoint = preg_quote($l['decimal_point'], '/'); |
|
225 | + $sSize = preg_match("/[\d\.]+e[+-]?\d+/i", (string)$this->fSize) |
|
226 | + ? preg_replace("/$sPoint?0+$/", "", sprintf("%f", $this->fSize)) : $this->fSize; |
|
227 | + return preg_replace(["/$sPoint/", "/^(-?)0\./"], ['.', '$1.'], $sSize) |
|
228 | + . ($this->sUnit === null ? '' : $this->sUnit); |
|
229 | + } |
|
230 | 230 | } |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | abstract class PrimitiveValue extends Value |
6 | 6 | { |
7 | - /** |
|
8 | - * @param int $iLineNo |
|
9 | - */ |
|
10 | - public function __construct($iLineNo = 0) |
|
11 | - { |
|
12 | - parent::__construct($iLineNo); |
|
13 | - } |
|
7 | + /** |
|
8 | + * @param int $iLineNo |
|
9 | + */ |
|
10 | + public function __construct($iLineNo = 0) |
|
11 | + { |
|
12 | + parent::__construct($iLineNo); |
|
13 | + } |
|
14 | 14 | } |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | $sContent = null; |
49 | 49 | if ($sQuote === null) { |
50 | 50 | // Unquoted strings end in whitespace or with braces, brackets, parentheses |
51 | - while (!preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) { |
|
51 | + while ( ! preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) { |
|
52 | 52 | $sResult .= $oParserState->parseCharacter(false); |
53 | 53 | } |
54 | 54 | } else { |
55 | - while (!$oParserState->comes($sQuote)) { |
|
55 | + while ( ! $oParserState->comes($sQuote)) { |
|
56 | 56 | $sContent = $oParserState->parseCharacter(false); |
57 | 57 | if ($sContent === null) { |
58 | 58 | throw new SourceException( |
@@ -100,6 +100,6 @@ discard block |
||
100 | 100 | { |
101 | 101 | $sString = addslashes($this->sString); |
102 | 102 | $sString = str_replace("\n", '\A', $sString); |
103 | - return $oOutputFormat->getStringQuotingType() . $sString . $oOutputFormat->getStringQuotingType(); |
|
103 | + return $oOutputFormat->getStringQuotingType().$sString.$oOutputFormat->getStringQuotingType(); |
|
104 | 104 | } |
105 | 105 | } |
@@ -15,96 +15,96 @@ |
||
15 | 15 | */ |
16 | 16 | class CSSString extends PrimitiveValue |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - private $sString; |
|
18 | + /** |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + private $sString; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param string $sString |
|
25 | - * @param int $iLineNo |
|
26 | - */ |
|
27 | - public function __construct($sString, $iLineNo = 0) |
|
28 | - { |
|
29 | - $this->sString = $sString; |
|
30 | - parent::__construct($iLineNo); |
|
31 | - } |
|
23 | + /** |
|
24 | + * @param string $sString |
|
25 | + * @param int $iLineNo |
|
26 | + */ |
|
27 | + public function __construct($sString, $iLineNo = 0) |
|
28 | + { |
|
29 | + $this->sString = $sString; |
|
30 | + parent::__construct($iLineNo); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @return CSSString |
|
35 | - * |
|
36 | - * @throws SourceException |
|
37 | - * @throws UnexpectedEOFException |
|
38 | - * @throws UnexpectedTokenException |
|
39 | - */ |
|
40 | - public static function parse(ParserState $oParserState) |
|
41 | - { |
|
42 | - $sBegin = $oParserState->peek(); |
|
43 | - $sQuote = null; |
|
44 | - if ($sBegin === "'") { |
|
45 | - $sQuote = "'"; |
|
46 | - } elseif ($sBegin === '"') { |
|
47 | - $sQuote = '"'; |
|
48 | - } |
|
49 | - if ($sQuote !== null) { |
|
50 | - $oParserState->consume($sQuote); |
|
51 | - } |
|
52 | - $sResult = ""; |
|
53 | - $sContent = null; |
|
54 | - if ($sQuote === null) { |
|
55 | - // Unquoted strings end in whitespace or with braces, brackets, parentheses |
|
56 | - while (!preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) { |
|
57 | - $sResult .= $oParserState->parseCharacter(false); |
|
58 | - } |
|
59 | - } else { |
|
60 | - while (!$oParserState->comes($sQuote)) { |
|
61 | - $sContent = $oParserState->parseCharacter(false); |
|
62 | - if ($sContent === null) { |
|
63 | - throw new SourceException( |
|
64 | - "Non-well-formed quoted string {$oParserState->peek(3)}", |
|
65 | - $oParserState->currentLine() |
|
66 | - ); |
|
67 | - } |
|
68 | - $sResult .= $sContent; |
|
69 | - } |
|
70 | - $oParserState->consume($sQuote); |
|
71 | - } |
|
72 | - return new CSSString($sResult, $oParserState->currentLine()); |
|
73 | - } |
|
33 | + /** |
|
34 | + * @return CSSString |
|
35 | + * |
|
36 | + * @throws SourceException |
|
37 | + * @throws UnexpectedEOFException |
|
38 | + * @throws UnexpectedTokenException |
|
39 | + */ |
|
40 | + public static function parse(ParserState $oParserState) |
|
41 | + { |
|
42 | + $sBegin = $oParserState->peek(); |
|
43 | + $sQuote = null; |
|
44 | + if ($sBegin === "'") { |
|
45 | + $sQuote = "'"; |
|
46 | + } elseif ($sBegin === '"') { |
|
47 | + $sQuote = '"'; |
|
48 | + } |
|
49 | + if ($sQuote !== null) { |
|
50 | + $oParserState->consume($sQuote); |
|
51 | + } |
|
52 | + $sResult = ""; |
|
53 | + $sContent = null; |
|
54 | + if ($sQuote === null) { |
|
55 | + // Unquoted strings end in whitespace or with braces, brackets, parentheses |
|
56 | + while (!preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) { |
|
57 | + $sResult .= $oParserState->parseCharacter(false); |
|
58 | + } |
|
59 | + } else { |
|
60 | + while (!$oParserState->comes($sQuote)) { |
|
61 | + $sContent = $oParserState->parseCharacter(false); |
|
62 | + if ($sContent === null) { |
|
63 | + throw new SourceException( |
|
64 | + "Non-well-formed quoted string {$oParserState->peek(3)}", |
|
65 | + $oParserState->currentLine() |
|
66 | + ); |
|
67 | + } |
|
68 | + $sResult .= $sContent; |
|
69 | + } |
|
70 | + $oParserState->consume($sQuote); |
|
71 | + } |
|
72 | + return new CSSString($sResult, $oParserState->currentLine()); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param string $sString |
|
77 | - * |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - public function setString($sString) |
|
81 | - { |
|
82 | - $this->sString = $sString; |
|
83 | - } |
|
75 | + /** |
|
76 | + * @param string $sString |
|
77 | + * |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + public function setString($sString) |
|
81 | + { |
|
82 | + $this->sString = $sString; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function getString() |
|
89 | - { |
|
90 | - return $this->sString; |
|
91 | - } |
|
85 | + /** |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function getString() |
|
89 | + { |
|
90 | + return $this->sString; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function __toString() |
|
97 | - { |
|
98 | - return $this->render(new OutputFormat()); |
|
99 | - } |
|
93 | + /** |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function __toString() |
|
97 | + { |
|
98 | + return $this->render(new OutputFormat()); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @return string |
|
103 | - */ |
|
104 | - public function render(OutputFormat $oOutputFormat) |
|
105 | - { |
|
106 | - $sString = addslashes($this->sString); |
|
107 | - $sString = str_replace("\n", '\A', $sString); |
|
108 | - return $oOutputFormat->getStringQuotingType() . $sString . $oOutputFormat->getStringQuotingType(); |
|
109 | - } |
|
101 | + /** |
|
102 | + * @return string |
|
103 | + */ |
|
104 | + public function render(OutputFormat $oOutputFormat) |
|
105 | + { |
|
106 | + $sString = addslashes($this->sString); |
|
107 | + $sString = str_replace("\n", '\A', $sString); |
|
108 | + return $oOutputFormat->getStringQuotingType() . $sString . $oOutputFormat->getStringQuotingType(); |
|
109 | + } |
|
110 | 110 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct($aComponents = [], $sSeparator = ',', $iLineNo = 0) |
26 | 26 | { |
27 | 27 | parent::__construct($iLineNo); |
28 | - if (!is_array($aComponents)) { |
|
28 | + if ( ! is_array($aComponents)) { |
|
29 | 29 | $aComponents = [$aComponents]; |
30 | 30 | } |
31 | 31 | $this->aComponents = $aComponents; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | public function render(OutputFormat $oOutputFormat) |
93 | 93 | { |
94 | 94 | return $oOutputFormat->implode( |
95 | - $oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator) . $this->sSeparator |
|
95 | + $oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator).$this->sSeparator |
|
96 | 96 | . $oOutputFormat->spaceAfterListArgumentSeparator($this->sSeparator), |
97 | 97 | $this->aComponents |
98 | 98 | ); |
@@ -12,95 +12,95 @@ |
||
12 | 12 | */ |
13 | 13 | abstract class ValueList extends Value |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> |
|
17 | - */ |
|
18 | - protected $aComponents; |
|
15 | + /** |
|
16 | + * @var array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> |
|
17 | + */ |
|
18 | + protected $aComponents; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $sSeparator; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $sSeparator; |
|
24 | 24 | |
25 | - /** |
|
26 | - * phpcs:ignore Generic.Files.LineLength |
|
27 | - * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>|RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $aComponents |
|
28 | - * @param string $sSeparator |
|
29 | - * @param int $iLineNo |
|
30 | - */ |
|
31 | - public function __construct($aComponents = [], $sSeparator = ',', $iLineNo = 0) |
|
32 | - { |
|
33 | - parent::__construct($iLineNo); |
|
34 | - if (!is_array($aComponents)) { |
|
35 | - $aComponents = [$aComponents]; |
|
36 | - } |
|
37 | - $this->aComponents = $aComponents; |
|
38 | - $this->sSeparator = $sSeparator; |
|
39 | - } |
|
25 | + /** |
|
26 | + * phpcs:ignore Generic.Files.LineLength |
|
27 | + * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string>|RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $aComponents |
|
28 | + * @param string $sSeparator |
|
29 | + * @param int $iLineNo |
|
30 | + */ |
|
31 | + public function __construct($aComponents = [], $sSeparator = ',', $iLineNo = 0) |
|
32 | + { |
|
33 | + parent::__construct($iLineNo); |
|
34 | + if (!is_array($aComponents)) { |
|
35 | + $aComponents = [$aComponents]; |
|
36 | + } |
|
37 | + $this->aComponents = $aComponents; |
|
38 | + $this->sSeparator = $sSeparator; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $mComponent |
|
43 | - * |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public function addListComponent($mComponent) |
|
47 | - { |
|
48 | - $this->aComponents[] = $mComponent; |
|
49 | - } |
|
41 | + /** |
|
42 | + * @param RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string $mComponent |
|
43 | + * |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public function addListComponent($mComponent) |
|
47 | + { |
|
48 | + $this->aComponents[] = $mComponent; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> |
|
53 | - */ |
|
54 | - public function getListComponents() |
|
55 | - { |
|
56 | - return $this->aComponents; |
|
57 | - } |
|
51 | + /** |
|
52 | + * @return array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> |
|
53 | + */ |
|
54 | + public function getListComponents() |
|
55 | + { |
|
56 | + return $this->aComponents; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public function setListComponents(array $aComponents) |
|
65 | - { |
|
66 | - $this->aComponents = $aComponents; |
|
67 | - } |
|
59 | + /** |
|
60 | + * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public function setListComponents(array $aComponents) |
|
65 | + { |
|
66 | + $this->aComponents = $aComponents; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function getListSeparator() |
|
73 | - { |
|
74 | - return $this->sSeparator; |
|
75 | - } |
|
69 | + /** |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function getListSeparator() |
|
73 | + { |
|
74 | + return $this->sSeparator; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @param string $sSeparator |
|
79 | - * |
|
80 | - * @return void |
|
81 | - */ |
|
82 | - public function setListSeparator($sSeparator) |
|
83 | - { |
|
84 | - $this->sSeparator = $sSeparator; |
|
85 | - } |
|
77 | + /** |
|
78 | + * @param string $sSeparator |
|
79 | + * |
|
80 | + * @return void |
|
81 | + */ |
|
82 | + public function setListSeparator($sSeparator) |
|
83 | + { |
|
84 | + $this->sSeparator = $sSeparator; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function __toString() |
|
91 | - { |
|
92 | - return $this->render(new OutputFormat()); |
|
93 | - } |
|
87 | + /** |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function __toString() |
|
91 | + { |
|
92 | + return $this->render(new OutputFormat()); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function render(OutputFormat $oOutputFormat) |
|
99 | - { |
|
100 | - return $oOutputFormat->implode( |
|
101 | - $oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator) . $this->sSeparator |
|
102 | - . $oOutputFormat->spaceAfterListArgumentSeparator($this->sSeparator), |
|
103 | - $this->aComponents |
|
104 | - ); |
|
105 | - } |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function render(OutputFormat $oOutputFormat) |
|
99 | + { |
|
100 | + return $oOutputFormat->implode( |
|
101 | + $oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator) . $this->sSeparator |
|
102 | + . $oOutputFormat->spaceAfterListArgumentSeparator($this->sSeparator), |
|
103 | + $this->aComponents |
|
104 | + ); |
|
105 | + } |
|
106 | 106 | } |
@@ -9,57 +9,57 @@ |
||
9 | 9 | |
10 | 10 | class LineName extends ValueList |
11 | 11 | { |
12 | - /** |
|
13 | - * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents |
|
14 | - * @param int $iLineNo |
|
15 | - */ |
|
16 | - public function __construct(array $aComponents = [], $iLineNo = 0) |
|
17 | - { |
|
18 | - parent::__construct($aComponents, ' ', $iLineNo); |
|
19 | - } |
|
12 | + /** |
|
13 | + * @param array<int, RuleValueList|CSSFunction|CSSString|LineName|Size|URL|string> $aComponents |
|
14 | + * @param int $iLineNo |
|
15 | + */ |
|
16 | + public function __construct(array $aComponents = [], $iLineNo = 0) |
|
17 | + { |
|
18 | + parent::__construct($aComponents, ' ', $iLineNo); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * @return LineName |
|
23 | - * |
|
24 | - * @throws UnexpectedTokenException |
|
25 | - * @throws UnexpectedEOFException |
|
26 | - */ |
|
27 | - public static function parse(ParserState $oParserState) |
|
28 | - { |
|
29 | - $oParserState->consume('['); |
|
30 | - $oParserState->consumeWhiteSpace(); |
|
31 | - $aNames = []; |
|
32 | - do { |
|
33 | - if ($oParserState->getSettings()->bLenientParsing) { |
|
34 | - try { |
|
35 | - $aNames[] = $oParserState->parseIdentifier(); |
|
36 | - } catch (UnexpectedTokenException $e) { |
|
37 | - if (!$oParserState->comes(']')) { |
|
38 | - throw $e; |
|
39 | - } |
|
40 | - } |
|
41 | - } else { |
|
42 | - $aNames[] = $oParserState->parseIdentifier(); |
|
43 | - } |
|
44 | - $oParserState->consumeWhiteSpace(); |
|
45 | - } while (!$oParserState->comes(']')); |
|
46 | - $oParserState->consume(']'); |
|
47 | - return new LineName($aNames, $oParserState->currentLine()); |
|
48 | - } |
|
21 | + /** |
|
22 | + * @return LineName |
|
23 | + * |
|
24 | + * @throws UnexpectedTokenException |
|
25 | + * @throws UnexpectedEOFException |
|
26 | + */ |
|
27 | + public static function parse(ParserState $oParserState) |
|
28 | + { |
|
29 | + $oParserState->consume('['); |
|
30 | + $oParserState->consumeWhiteSpace(); |
|
31 | + $aNames = []; |
|
32 | + do { |
|
33 | + if ($oParserState->getSettings()->bLenientParsing) { |
|
34 | + try { |
|
35 | + $aNames[] = $oParserState->parseIdentifier(); |
|
36 | + } catch (UnexpectedTokenException $e) { |
|
37 | + if (!$oParserState->comes(']')) { |
|
38 | + throw $e; |
|
39 | + } |
|
40 | + } |
|
41 | + } else { |
|
42 | + $aNames[] = $oParserState->parseIdentifier(); |
|
43 | + } |
|
44 | + $oParserState->consumeWhiteSpace(); |
|
45 | + } while (!$oParserState->comes(']')); |
|
46 | + $oParserState->consume(']'); |
|
47 | + return new LineName($aNames, $oParserState->currentLine()); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function __toString() |
|
54 | - { |
|
55 | - return $this->render(new OutputFormat()); |
|
56 | - } |
|
50 | + /** |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function __toString() |
|
54 | + { |
|
55 | + return $this->render(new OutputFormat()); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function render(OutputFormat $oOutputFormat) |
|
62 | - { |
|
63 | - return '[' . parent::render(OutputFormat::createCompact()) . ']'; |
|
64 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function render(OutputFormat $oOutputFormat) |
|
62 | + { |
|
63 | + return '[' . parent::render(OutputFormat::createCompact()) . ']'; |
|
64 | + } |
|
65 | 65 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | try { |
35 | 35 | $aNames[] = $oParserState->parseIdentifier(); |
36 | 36 | } catch (UnexpectedTokenException $e) { |
37 | - if (!$oParserState->comes(']')) { |
|
37 | + if ( ! $oParserState->comes(']')) { |
|
38 | 38 | throw $e; |
39 | 39 | } |
40 | 40 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $aNames[] = $oParserState->parseIdentifier(); |
43 | 43 | } |
44 | 44 | $oParserState->consumeWhiteSpace(); |
45 | - } while (!$oParserState->comes(']')); |
|
45 | + }while ( ! $oParserState->comes(']')); |
|
46 | 46 | $oParserState->consume(']'); |
47 | 47 | return new LineName($aNames, $oParserState->currentLine()); |
48 | 48 | } |
@@ -60,6 +60,6 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function render(OutputFormat $oOutputFormat) |
62 | 62 | { |
63 | - return '[' . parent::render(OutputFormat::createCompact()) . ']'; |
|
63 | + return '['.parent::render(OutputFormat::createCompact()).']'; |
|
64 | 64 | } |
65 | 65 | } |