Ticket #470: patch_470_meta.diff
File patch_470_meta.diff, 3.3 KB (added by , 10 years ago) |
---|
-
official-wordpress-events.php
26 26 * Constructor 27 27 */ 28 28 public function __construct() { 29 add_action( 'wp_ajax_nopriv_infinite_scroll' , array( $this, 'infinite_scroll_func' ) ); 29 30 add_shortcode( 'official_wordpress_events', array( $this, 'render_events' ) ); 30 31 } 31 32 … … 35 36 public function render_events() { 36 37 $events = $this->get_all_events(); 37 38 38 if ( $events ) {39 if ( $events ) 39 40 require_once( __DIR__ . '/template-events.php' ); 40 }41 41 } 42 42 43 43 /** … … 51 51 52 52 return $events; 53 53 } 54 /** 55 * Infinite Scroll functionality added 56 */ 57 public function infinite_scroll_func() { 58 $off = $_POST[ 'off' ]; 59 $off = $off + 1; 60 if ( $tempEvents = $this->get_meetup_events( $off ) ) { 61 usort( $tempEvents, array( $this, 'sort_events' ) ); 62 foreach ( $tempEvents as $event ) : ?> 54 63 64 <li> 65 <a href="<?php echo esc_attr( esc_url( $event->url ) ) ?>"><?php echo esc_html( $event->title ) ?></a> 66 <br />' 67 <?php echo esc_html( date( "l, F jS | g:i a", (int) $event->start_timestamp ) ) ?> 68 <br /> 69 <?php echo esc_html( $event->location ) ?> 70 </li> 71 72 <?php endforeach; 73 } 74 75 wp_die(); 76 } 77 55 78 /** 56 79 * Sort events based on start timestamp 57 80 * … … 104 127 105 128 /** 106 129 * Get WordPress meetups from the Meetup.com API 107 * 130 * @param $offset 108 131 * @return array 109 132 */ 110 protected function get_meetup_events( ) {133 protected function get_meetup_events( $offset = 0 ) { 111 134 $events = array(); 112 113 135 if ( ! defined( 'MEETUP_API_KEY' ) || ! MEETUP_API_KEY || ! $groups = $this->get_meetup_group_ids() ) { 114 136 return $events; 115 137 } 116 138 117 139 $response = $this->remote_get( sprintf( 118 '%s2/events?group_id=%s&time=0,1m&page=%d& key=%s',140 '%s2/events?group_id=%s&time=0,1m&page=%d&offset=%d&key=%s', 119 141 self::MEETUP_API_BASE_URL, 120 142 implode( ',', $groups ), 121 143 self::POSTS_PER_PAGE, 144 $offset, 122 145 MEETUP_API_KEY 123 146 ) ); 124 147 … … 229 252 } 230 253 231 254 if ( $error ) { 232 $error = preg_replace( '/&key=[a-z0-9]+/i', '&key=[redacted]', $error );233 255 trigger_error( sprintf( '%s error for %s: %s', __METHOD__, parse_url( site_url(), PHP_URL_HOST ), sanitize_text_field( $error ) ), E_USER_WARNING ); 234 256 235 257 if ( $to = apply_filters( 'owe_error_email_addresses', array() ) ) { -
template-events.php
1 <script> 2 var flag = 0; 3 var offset = 0; 4 var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; 5 function async_infinite_load() { 6 jQuery.post ( 7 ajaxurl, 8 { 9 'action': 'infinite_scroll', 10 'off' : offset, 11 }, 12 function( response ) { 13 jQuery("#ofe_events ul").append(response); 14 flag = 0; 15 offset = offset + 1; 16 } 17 ); 18 19 } 20 21 jQuery(window).scroll( function() { 22 23 if( jQuery(window).scrollTop() + jQuery(window).height() > ( jQuery('#ofe_events').height() + jQuery('#ofe_events').offset().top -10 ) && !flag ) { 24 flag = flag + 1; 25 async_infinite_load(); 26 } 27 } ); 28 29 </script> 1 30 <div id="ofe_events"> 2 31 <ul> 3 32 <?php foreach ( $events as $event ) : ?>