Changeset 7011 for sites/trunk/wp15.wordpress.net/public_html/content/plugins/wp15-meetup-events/wp15-meetup-events.php
- Timestamp:
- 04/03/2018 08:46:45 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wp15.wordpress.net/public_html/content/plugins/wp15-meetup-events/wp15-meetup-events.php
r7009 r7011 177 177 } 178 178 179 wp_enqueue_style( 180 'wp15-meetup-events', 181 plugins_url( 'wp15-meetup-events.css', __FILE__ ), 182 array(), 183 filemtime( __DIR__ . '/wp15-meetup-events.css' ) 184 ); 185 179 186 wp_register_script( 180 187 'google-maps', … … 201 208 ); 202 209 203 wp_ enqueue_style(210 wp_localize_script( 204 211 'wp15-meetup-events', 205 plugins_url( 'wp15-meetup-events.css', __FILE__ ), 206 array(), 207 filemtime( __DIR__ . '/wp15-meetup-events.css' ) 208 ); 209 } 210 211 /** 212 * Render the WP15 events shortcode. 213 */ 214 function render_events_shortcode() { 215 $events = get_option( 'wp15_events' ); 216 217 // This needs to be done on the fly, in order to use the date format for the visitor's locale. 218 foreach ( $events as & $event ) { 219 $event['time'] = get_local_formatted_date( $event['time'], $event['timezone'] ); 220 } 221 unset( $event ); // Destroy the reference to restore expected behavior; see https://stackoverflow.com/a/4969286/450127. 222 223 usort( $events, __NAMESPACE__ . '\sort_events' ); 224 225 $map_options = array( 212 'wp15MeetupEventsData', 213 array( 214 'map_options' => get_map_options(), 215 'events' => get_formatted_events(), 216 ) 217 ); 218 } 219 220 221 /** 222 * Get the configuration for the Google Map of events. 223 * 224 * @return array 225 */ 226 function get_map_options() { 227 return array( 226 228 'mapContainer' => 'wp15-events-map', 227 'mapMarkers' => $events,228 229 'markerIconBaseURL' => plugins_url( '/images/', __FILE__ ), 229 230 'markerIcon' => 'map-marker.svg', … … 235 236 'clusterIconHeight' => 52, 236 237 ); 238 } 239 240 /** 241 * Format the WP15 events for presentation. 242 * 243 * @return array 244 */ 245 function get_formatted_events() { 246 $events = get_option( 'wp15_events' ); 247 248 // This needs to be done on the fly, in order to use the date format for the visitor's locale. 249 foreach ( $events as & $event ) { 250 $event['time'] = get_local_formatted_date( $event['time'], $event['timezone'] ); 251 } 252 unset( $event ); // Destroy the reference to restore expected behavior; see https://stackoverflow.com/a/4969286/450127. 253 254 usort( $events, __NAMESPACE__ . '\sort_events' ); 255 256 return $events; 257 } 258 259 /** 260 * Sort events by their timestamp. 261 * 262 * @param array $a 263 * @param array $b 264 * 265 * @return int 266 */ 267 function sort_events( $a, $b ) { 268 if ( $a['time'] === $b['time'] ) { 269 return 0; 270 } 271 272 return $a['time'] > $b['time']; 273 } 274 275 /** 276 * Render the WP15 events shortcode. 277 */ 278 function render_events_shortcode() { 279 $events = get_formatted_events(); 237 280 238 281 ob_start(); … … 240 283 require_once( __DIR__ . '/views/events-list.php' ); 241 284 return ob_get_clean(); 242 }243 244 /**245 * Sort events by their timestamp.246 *247 * @param array $a248 * @param array $b249 *250 * @return int251 */252 function sort_events( $a, $b ) {253 if ( $a['time'] === $b['time'] ) {254 return 0;255 }256 257 return $a['time'] > $b['time'];258 285 } 259 286
Note: See TracChangeset
for help on using the changeset viewer.