googlePlusHangout

The Yakadanda Google+ Hangout Events googlePlusHangout class.

Defined (1)

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

/lib/_widgets.php  
  1. class googlePlusHangout extends WP_Widget { 
  2. //Register widget with WordPress. 
  3. public function __construct() { 
  4. parent::__construct( 
  5. 'googleplus_hangout_events', // Base ID 
  6. 'Google+ Hangout', // Name 
  7. array('description' => __('A countdown function to time of the Google+ Hangout', '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_hangout_widget_' . $instance['timezone'] . $token); 
  23. if ( (false === ( $special_query_hangout_widget = get_transient($transient_name) )) && $token && $data['transient'] ) { 
  24. $special_query_hangout_widget = googleplushangoutevent_response(null, null, null, $instance['timezone']); 
  25.  
  26. if ( !empty($special_query_hangout_widget) ) { set_transient($transient_name, $special_query_hangout_widget, 60 * $data['expiration']); } 
  27. if (!$token) { 
  28. delete_transient($transient_name); 
  29. $events = ($data['transient']) ? $special_query_hangout_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.  
  41. $http_status = isset($events['error']['code']) ? $events['error']['code'] : null; 
  42.  
  43. extract( $args ); 
  44. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? null : $instance['title'], $instance, $this->id_base ); 
  45.  
  46. echo $before_widget; 
  47. if ( ! empty( $title ) ) echo $before_title . $title . $after_title; 
  48.  
  49. ?> 
  50. <div id="ghe-hangout-widget"> 
  51. <?php if ($events && !$http_status): 
  52. $is_countdown = ($countdown == 'none') ? false : true; 
  53. ?> 
  54. <?php foreach ( $events as $event ): 
  55. $hangoutlink = isset($event['hangoutLink']) ? $event['hangoutLink'] : false; 
  56.  
  57. $event['visibility'] = isset($event['visibility']) ? $event['visibility'] : 'public'; 
  58. $event['visibility'] = ($visibility == "all") ? 'all' : $event['visibility']; 
  59.  
  60. switch($author) { 
  61. case 'self': 
  62. if ( isset($event["\0*\0modelData"]['creator']['self']) ) 
  63. $creator = $event["\0*\0modelData"]['creator']['self']; 
  64. else 
  65. $creator = ($event["\0*\0modelData"]['creator']['email'] == $data['calendar_id']) ? 1 : 0; 
  66. break; 
  67. case 'other': 
  68. if ( isset($event["\0*\0modelData"]['creator']['self']) ) 
  69. $creator = !$event["\0*\0modelData"]['creator']['self']; 
  70. else 
  71. $creator = ($event["\0*\0modelData"]['creator']['email'] == $data['calendar_id']) ? 0 : 1; 
  72. break; 
  73.  
  74. if ( $hangoutlink && $creator && ($visibility == $event['visibility']) ): 
  75. $timezone = isset($event['timeZoneLocation']) ? $event['timeZoneLocation'] : $event['timeZoneCalendar']; 
  76. $timezone = ($instance['timezone']) ? $instance['timezone'] : $timezone; 
  77.  
  78. $start = (array) $event["\0*\0modelData"]['start']; 
  79. $end = (array) $event["\0*\0modelData"]['end']; 
  80. $start_event = isset($start['dateTime']) ? $start['dateTime'] : $start['date']; 
  81. $end_event = isset($end['dateTime']) ? $end['dateTime'] : $end['date']; 
  82.  
  83. $time = googleplushangoutevent_start_time($start_event, $timezone); 
  84.  
  85. $onair = googleplushangoutevent_onair($start['dateTime'], $end['dateTime']); 
  86. ?> 
  87. <div itemscope itemtype="http://data-vocabulary.org/Event" class="ghe-vessel"> 
  88. <h4 itemprop="summary" class="ghe-title"><?php echo $event['summary']; ?></h4> 
  89. <div class="ghe-time"><?php echo googleplushangoutevent_time($start_event, $end_event, $timezone, 'widget'); ?></div> 
  90. <div itemprop="description" class="ghe-detail"><?php echo nl2br( $event['description'] ); ?></div> 
  91.  
  92. <ul class="ghe-icons"> 
  93. <li><a href="<?php echo $event['htmlLink'] ?>" target="_blank"><?php _e('Event', 'yakadanda-google-hangout-events'); ?></a></li> 
  94. <li><a href="<?php echo $event['htmlLink'] ?>" target="_blank"><?php _e('Hangout', 'yakadanda-google-hangout-events'); ?></a></li> 
  95. <?php if ($onair): ?> 
  96. <li><a href="<?php echo $event['hangoutLink'] ?>" target="_blank"><?php _e('On Air', 'yakadanda-google-hangout-events'); ?></a></li> 
  97. <?php endif; ?> 
  98. </ul> 
  99.  
  100. <?php if ($is_countdown): ?> 
  101. <div id="<?php echo uniqid(); ?>" class="ghe-countdown fix" data-cdate="<?php echo $time; ?>"><?php echo $time; ?></div> 
  102. <?php endif; ?> 
  103.  
  104. <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> 
  105. </div> 
  106.  
  107. <?php if ( ($countdown == 'first') && ($i==0) ) $is_countdown = false; ?> 
  108. <?php $i++; if ( $i == $display ) break; ?> 
  109.  
  110. <?php endif; endforeach; ?> 
  111. <?php endif; ?> 
  112.  
  113. <?php if ($i == 0): ?> 
  114. <div class="ghe-vessel"><p><?php echo googleplushangoutevent_get_widget_message($events, 'hangout'); ?></p></div> 
  115. <?php endif; ?> 
  116. </div> 
  117.  
  118. <?php 
  119.  
  120. echo $after_widget; 
  121.  
  122. // Sanitize widget form values as they are saved. 
  123. public function update($new_instance, $old_instance) { 
  124. $instance = array(); 
  125. $instance['title'] = strip_tags($new_instance['title']); 
  126. $instance['author'] = strip_tags($new_instance['author']); 
  127. $instance['display'] = strip_tags($new_instance['display']); 
  128. $instance['visibility'] = strip_tags($new_instance['visibility']); 
  129. $instance['countdown'] = strip_tags($new_instance['countdown']); 
  130. $instance['timezone'] = strip_tags($new_instance['timezone']); 
  131. return $instance; 
  132.  
  133. // Back-end widget form. 
  134. public function form( $instance ) { 
  135. if ( isset( $instance[ 'title' ] ) ) $title = $instance[ 'title' ]; 
  136. $author = isset( $instance[ 'author' ] ) ? $instance[ 'author' ] : 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('display'); ?>"><?php _e('Display:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  156. <select id="<?php echo $this->get_field_id('display'); ?>" name="<?php echo $this->get_field_name('display'); ?>"> 
  157. <option value="1" <?php echo ($display == 1) ? 'selected="selected"': null; ?>>1 </option> 
  158. <option value="2" <?php echo ($display == 2) ? 'selected="selected"': null; ?>>2 </option> 
  159. <option value="3" <?php echo ($display == 3) ? 'selected="selected"': null; ?>>3 </option> 
  160. <option value="4" <?php echo ($display == 4) ? 'selected="selected"': null; ?>>4 </option> 
  161. <option value="5" <?php echo ($display == 5) ? 'selected="selected"': null; ?>>5 </option> 
  162. </select> 
  163. </p> 
  164. <p> 
  165. <label for="<?php echo $this->get_field_id('visibility'); ?>"><?php _e('Visibility:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  166. <select id="<?php echo $this->get_field_id('visibility'); ?>" name="<?php echo $this->get_field_name('visibility'); ?>"> 
  167. <option value="public" <?php echo ($visibility == "public") ? 'selected="selected"': null; ?>>Public </option> 
  168. <option value="private" <?php echo ($visibility == "private") ? 'selected="selected"': null; ?>>Private </option> 
  169. <option value="all" <?php echo ($visibility == "all") ? 'selected="selected"': null; ?>>All </option> 
  170. </select> 
  171. </p> 
  172. <p> 
  173. <label for="<?php echo $this->get_field_id('countdown'); ?>"><?php _e('Countdown:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  174. <label title="Display countdown clock on first only"> 
  175. <input type="radio" value="first" name="<?php echo $this->get_field_name('countdown'); ?>" <?php echo ( ($countdown == 'first') || empty($countdown) ) ? 'checked="checked"' : null; ?>> 
  176. <span><?php _e('First only', 'yakadanda-google-hangout-events'); ?></span> 
  177. </label> 
  178. <br/> 
  179. <label title="Display countdown clock on all"> 
  180. <input type="radio" value="all" name="<?php echo $this->get_field_name('countdown'); ?>" <?php echo ($countdown == 'all') ? 'checked="checked"' : null; ?>> 
  181. <span><?php _e('All', 'yakadanda-google-hangout-events'); ?></span> 
  182. </label> 
  183. <br/> 
  184. <label title="Display countdown clock on none"> 
  185. <input type="radio" value="none" name="<?php echo $this->get_field_name('countdown'); ?>" <?php echo ($countdown == 'none') ? 'checked="checked"' : null; ?>> 
  186. <span><?php _e('None', 'yakadanda-google-hangout-events'); ?></span> 
  187. </label> 
  188. </p> 
  189. <p> 
  190. <label for="<?php echo $this->get_field_id('timezone'); ?>"><?php _e('Timezone:', 'yakadanda-google-hangout-events'); ?></label><br/> 
  191. <select id="<?php echo $this->get_field_id('timezone'); ?>" name="<?php echo $this->get_field_name('timezone'); ?>" style="width: 100%"> 
  192. <?php googleplushangoutevent_timezone_options($timezone); ?> 
  193. </select> 
  194. </p> 
  195. <?php  
  196.  
  197. }/** end of googlePlusHangoutEvents class */