googlePlusEvent

The Yakadanda Google+ Hangout Events googlePlusEvent class.

Defined (1)

The class is defined in the following location(s).

/lib/_widgets.php  
  1. class googlePlusEvent extends WP_Widget { 
  2. //Register widget with WordPress. 
  3. public function __construct() { 
  4. parent::__construct( 
  5. 'googleplus_events', // Base ID 
  6. 'Google+ Event', // Name 
  7. array('description' => __('A countdown function to time of the Google+ Event', 'yakadanda-google-hangout-events'), ) // Args 
  8. ); 
  9.  
  10. // Front-end display of widget. 
  11. public function widget( $args, $instance ) { 
  12. // Enqueue scripts 
  13. googleplushangoutevent_wp_enqueue_scripts_load(); 
  14.  
  15. $data = googleplushangoutevent_get_settings(); 
  16. $token = get_option('yakadanda_googleplus_hangout_event_access_token'); 
  17.  
  18. $data['transient'] = ($data['transient'] == 'on') ? true : false; 
  19.  
  20. $instance['timezone'] = isset($instance['timezone']) ? $instance['timezone'] : null; 
  21.  
  22. $transient_name = md5('special_query_event_widget_' . $instance['timezone'] . $token); 
  23. if ( (false === ( $special_query_event_widget = get_transient($transient_name) )) && $token && $data['transient'] ) { 
  24. $special_query_event_widget = googleplushangoutevent_response(null, null, null, $instance['timezone']); 
  25.  
  26. if ( !empty($special_query_event_widget) ) { set_transient($transient_name, $special_query_event_widget, 60 * $data['expiration']); } 
  27. if (!$token) { 
  28. delete_transient($transient_name); 
  29. $events = ($data['transient']) ? $special_query_event_widget : googleplushangoutevent_response(null, null, null, $instance['timezone']); 
  30.  
  31. // sorting 
  32. if ($events) { uasort( $events , 'googleplushangoutevent_sort_events_asc' ); } 
  33.  
  34. $i = 0; 
  35. $display = isset( $instance['display'] ) ? $instance['display'] : 1; 
  36. $creator = 1; 
  37. $author = isset($instance['author']) ? $instance['author'] : 'all'; 
  38. $countdown = isset($instance['countdown']) ? $instance['countdown'] : 'first'; 
  39. $visibility = isset($instance['visibility']) ? $instance['visibility'] : 'public'; 
  40. $source = empty($instance['src']) ? 'all' : $instance['src']; 
  41.  
  42. $http_status = isset($events['error']['code']) ? $events['error']['code'] : null; 
  43.  
  44. extract( $args ); 
  45. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? null : $instance['title'], $instance, $this->id_base ); 
  46.  
  47. echo $before_widget; 
  48. if ( ! empty( $title ) ) echo $before_title . $title . $after_title; 
  49.  
  50. ?> 
  51. <div id="ghe-event-widget"> 
  52. <?php if ($events && !$http_status): 
  53. $is_countdown = ($countdown == 'none') ? false : true; 
  54. $src_filter = true; 
  55. ?> 
  56. <?php foreach ( $events as $event ): 
  57. $hangoutlink = isset($event['hangoutLink']) ? $event['hangoutLink'] : false; 
  58.  
  59. $event['visibility'] = isset($event['visibility']) ? $event['visibility'] : 'public'; 
  60. $event['visibility'] = ($visibility == "all") ? 'all' : $event['visibility']; 
  61.  
  62. switch($author) { 
  63. case 'self': 
  64. if ( isset($event["\0*\0modelData"]['creator']['self']) ) 
  65. $creator = $event["\0*\0modelData"]['creator']['self']; 
  66. else 
  67. $creator = ($event["\0*\0modelData"]['creator']['email'] == $data['calendar_id']) ? 1 : 0; 
  68. break; 
  69. case 'other': 
  70. if ( isset($event["\0*\0modelData"]['creator']['self']) ) 
  71. $creator = !$event["\0*\0modelData"]['creator']['self']; 
  72. else 
  73. $creator = ($event["\0*\0modelData"]['creator']['email'] == $data['calendar_id']) ? 0 : 1; 
  74. break; 
  75.  
  76. if ($source != 'all') $src_filter = googleplushangoutevent_src_filter($source, $event['htmlLink']); 
  77.  
  78. if ( !$hangoutlink && $creator && ($visibility == $event['visibility']) && $src_filter ): 
  79. $timezone = isset($event['timeZoneLocation']) ? $event['timeZoneLocation'] : $event['timeZoneCalendar']; 
  80. $timezone = ($instance['timezone']) ? $instance['timezone'] : $timezone; 
  81.  
  82. $start = (array) $event["\0*\0modelData"]['start']; 
  83. $end = (array) $event["\0*\0modelData"]['end']; 
  84. $start_event = isset($start['dateTime']) ? $start['dateTime'] : $start['date']; 
  85. $end_event = isset($end['dateTime']) ? $end['dateTime'] : $end['date']; 
  86.  
  87. $time = googleplushangoutevent_start_time($start_event, $timezone); 
  88. ?> 
  89. <div itemscope itemtype="http://data-vocabulary.org/Event" class="ghe-vessel"> 
  90. <h4 itemprop="summary" class="ghe-title"><?php echo $event['summary']; ?></h4> 
  91. <div class="ghe-time"><?php echo googleplushangoutevent_time($start_event, $end_event, $timezone, 'widget'); ?></div> 
  92. <div itemprop="description" class="ghe-detail"><?php echo isset($event['description']) ? nl2br( $event['description'] ) : null; ?></div> 
  93.  
  94. <ul class="ghe-icons"> 
  95. <li><a href="<?php echo $event['htmlLink'] ?>" target="_blank"><?php _e('Event', 'yakadanda-google-hangout-events'); ?></a></li> 
  96. </ul> 
  97.  
  98. <?php if ($is_countdown): ?> 
  99. <div id="<?php echo uniqid(); ?>" class="ghe-countdown fix" data-cdate="<?php echo $time; ?>"><?php echo $time; ?></div> 
  100. <?php endif; ?> 
  101.  
  102. <div class="ghe-button"><a itemprop="url" href="<?php echo $event['htmlLink'] ?>" target="_blank"><?php _e('View Event on Google+', 'yakadanda-google-hangout-events'); ?></a></div> 
  103. </div> 
  104.  
  105. <?php if ( ($countdown == 'first') && ($i==0) ) $is_countdown = false; ?> 
  106. <?php $i++; if ( $i == $display ) break; ?> 
  107.  
  108. <?php endif; endforeach; ?> 
  109. <?php endif; ?> 
  110.  
  111. <?php if ($i == 0): ?> 
  112. <div class="ghe-vessel"><p><?php echo googleplushangoutevent_get_widget_message($events, 'normal'); ?></p></div> 
  113. <?php endif; ?> 
  114. </div> 
  115.  
  116. <?php 
  117.  
  118. echo $after_widget; 
  119.  
  120. // Sanitize widget form values as they are saved. 
  121. public function update($new_instance, $old_instance) { 
  122. $instance = array(); 
  123. $instance['title'] = strip_tags($new_instance['title']); 
  124. $instance['author'] = strip_tags($new_instance['author']); 
  125. $instance['src'] = strip_tags($new_instance['src']); 
  126. $instance['display'] = strip_tags($new_instance['display']); 
  127. $instance['visibility'] = strip_tags($new_instance['visibility']); 
  128. $instance['countdown'] = strip_tags($new_instance['countdown']); 
  129. $instance['timezone'] = strip_tags($new_instance['timezone']); 
  130. return $instance; 
  131.  
  132. // Back-end widget form. 
  133. public function form( $instance ) { 
  134. if ( isset( $instance[ 'title' ] ) ) $title = $instance[ 'title' ]; 
  135. $author = isset( $instance[ 'author' ] ) ? $instance[ 'author' ] : null; 
  136. $src = isset( $instance[ 'src' ] ) ? $instance[ 'src' ] : null; 
  137. $display = isset( $instance[ 'display' ] ) ? $instance[ 'display' ] : null; 
  138. $visibility = isset( $instance[ 'visibility' ] ) ? $instance[ 'visibility' ] : null; 
  139. $countdown = isset( $instance[ 'countdown' ] ) ? $instance[ 'countdown' ] : null; 
  140. $timezone = isset( $instance[ 'timezone' ] ) ? $instance[ 'timezone' ] : null; 
  141. ?> 
  142. <p> 
  143. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'yakadanda-google-hangout-events'); ?></label> 
  144. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo isset($title) ? esc_attr($title): null; ?>" /> 
  145. </p> 
  146. <p> 
  147. <label for="<?php echo $this->get_field_id('author'); ?>"><?php _e('Author:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  148. <select id="<?php echo $this->get_field_id('author'); ?>" name="<?php echo $this->get_field_name('author'); ?>"> 
  149. <option value="all" <?php echo ($author == 'all') ? 'selected="selected"': null; ?>><?php _e('All', 'yakadanda-google-hangout-events'); ?> </option> 
  150. <option value="self" <?php echo ($author == 'self') ? 'selected="selected"': null; ?>><?php _e('Self', 'yakadanda-google-hangout-events'); ?> </option> 
  151. <option value="other" <?php echo ($author == 'other') ? 'selected="selected"': null; ?>><?php _e('Other', 'yakadanda-google-hangout-events'); ?> </option> 
  152. </select> 
  153. </p> 
  154. <p> 
  155. <label for="<?php echo $this->get_field_id('src'); ?>"><?php _e('Source:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  156. <select id="<?php echo $this->get_field_id('src'); ?>" name="<?php echo $this->get_field_name( 'src' ); ?>"> 
  157. <option value="all" <?php echo ($src == 'all') ? 'selected="selected"': null; ?>><?php _e('All', 'yakadanda-google-hangout-events'); ?> </option> 
  158. <option value="gcal" <?php echo ($src == 'gcal') ? 'selected="selected"': null; ?>><?php _e('Google Calendar', 'yakadanda-google-hangout-events'); ?> </option> 
  159. <option value="gplus" <?php echo ($src == 'gplus') ? 'selected="selected"': null; ?>>Google+ </option> 
  160. </select> 
  161. </p> 
  162. <p> 
  163. <label for="<?php echo $this->get_field_id('display'); ?>"><?php _e('Display:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  164. <select id="<?php echo $this->get_field_id('display'); ?>" name="<?php echo $this->get_field_name('display'); ?>"> 
  165. <option value="1" <?php echo ($display == 1) ? 'selected="selected"': null; ?>>1 </option> 
  166. <option value="2" <?php echo ($display == 2) ? 'selected="selected"': null; ?>>2 </option> 
  167. <option value="3" <?php echo ($display == 3) ? 'selected="selected"': null; ?>>3 </option> 
  168. <option value="4" <?php echo ($display == 4) ? 'selected="selected"': null; ?>>4 </option> 
  169. <option value="5" <?php echo ($display == 5) ? 'selected="selected"': null; ?>>5 </option> 
  170. </select> 
  171. </p> 
  172. <p> 
  173. <label for="<?php echo $this->get_field_id('visibility'); ?>"><?php _e('Visibility:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  174. <select id="<?php echo $this->get_field_id('visibility'); ?>" name="<?php echo $this->get_field_name('visibility'); ?>"> 
  175. <option value="public" <?php echo ($visibility == "public") ? 'selected="selected"': null; ?>>Public </option> 
  176. <option value="private" <?php echo ($visibility == "private") ? 'selected="selected"': null; ?>>Private </option> 
  177. <option value="all" <?php echo ($visibility == "all") ? 'selected="selected"': null; ?>>All </option> 
  178. </select> 
  179. </p> 
  180. <p> 
  181. <label for="<?php echo $this->get_field_id('countdown'); ?>"><?php _e('Countdown:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  182. <label title="Display countdown clock on first only"> 
  183. <input type="radio" value="first" name="<?php echo $this->get_field_name('countdown'); ?>" <?php echo ( ($countdown == 'first') || empty($countdown) ) ? 'checked="checked"' : null; ?>> 
  184. <span><?php _e('First only', 'yakadanda-google-hangout-events'); ?></span> 
  185. </label> 
  186. <br/> 
  187. <label title="Display countdown clock on all"> 
  188. <input type="radio" value="all" name="<?php echo $this->get_field_name('countdown'); ?>" <?php echo ($countdown == 'all') ? 'checked="checked"' : null; ?>> 
  189. <span><?php _e('All', 'yakadanda-google-hangout-events'); ?></span> 
  190. </label> 
  191. <br/> 
  192. <label title="Display countdown clock on none"> 
  193. <input type="radio" value="none" name="<?php echo $this->get_field_name('countdown'); ?>" <?php echo ($countdown == 'none') ? 'checked="checked"' : null; ?>> 
  194. <span><?php _e('None', 'yakadanda-google-hangout-events'); ?></span> 
  195. </label> 
  196. </p> 
  197. <p> 
  198. <label for="<?php echo $this->get_field_id('timezone'); ?>"><?php _e('Timezone:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  199. <select id="<?php echo $this->get_field_id('timezone'); ?>" name="<?php echo $this->get_field_name('timezone'); ?>" style="width: 100%"> 
  200. <?php googleplushangoutevent_timezone_options($timezone); ?> 
  201. </select> 
  202. </p> 
  203. <?php 
  204.  
  205. }/** end of googlePlusHangoutEvents class */