Advertisement
Guest User

Upcoming widget modification

a guest
Dec 28th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.35 KB | None | 0 0
  1. <?php
  2. if (!class_exists('Event_Espresso_Widget')) {
  3.  
  4. class Event_Espresso_Widget extends WP_Widget {
  5.  
  6. function Event_Espresso_Widget() {
  7.  
  8. /* Widget settings. */
  9.  
  10. $widget_options = array('classname' => 'events', 'description' => __('A widget to display your upcoming events.', 'event_espresso'));
  11. /* Widget control settings. */
  12.  
  13. $control_options = array('width' => 300, 'height' => 350, 'id_base' => 'events-widget');
  14. /* Create the widget. */
  15.  
  16. $this->WP_Widget('events-widget', __('Event Espresso Upcoming Events Widget', 'event_espresso'), $widget_options, $control_options);
  17. }
  18.  
  19. function widget($args, $instance) {
  20.  
  21. extract($args);
  22.  
  23. global $wpdb, $org_options;
  24. /* Our variables from the widget settings. */
  25.  
  26. $title = apply_filters('widget_title', $instance['title']);
  27.  
  28. /* Before widget (defined by themes). */
  29. echo $before_widget;
  30.  
  31. /* Display the widget title if one was input (before and after defined by themes). */
  32. if ($title)
  33. echo $before_title . $title . $after_title;
  34.  
  35. if ($instance['category_name'] != '') {
  36. $type = 'category';
  37. }
  38.  
  39. $event_page_id = $org_options['event_page_id'];
  40.  
  41. $show_expired = $instance['show_expired'] == 'false' ? " AND (e.start_date >= '" . date('Y-m-d') . "' OR e.event_status = 'O' OR e.registration_end >= '" . date('Y-m-d') . "') " : '';
  42. $show_secondary = $instance['show_secondary'] == 'false' ? " AND e.event_status != 'S' " : '';
  43. $show_deleted = $instance['show_deleted'] == 'false' ? " AND e.event_status != 'D' " : '';
  44. $show_recurrence = $instance['show_recurrence'] == 'false' ? " AND e.recurrence_id = '0' " : '';
  45. $limit = $instance['limit'] > 0 ? " LIMIT 0," . $instance['limit'] . " " : ' LIMIT 0,5 ';
  46. //$order_by = $order_by != 'NULL'? " ORDER BY ". $order_by ." ASC " : " ORDER BY date(start_date), id ASC ";
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. $order_by = " ORDER BY date(start_date), id ASC ";
  58.  
  59. if (isset($type) && $type == 'category') {
  60. $sql = "SELECT e.*, c.category_name, c.category_name, c.category_desc, ese.start_time FROM " . EVENTS_CATEGORY_TABLE . " c ";
  61. $sql .= " JOIN " . EVENTS_CATEGORY_REL_TABLE . " r ON r.cat_id = c.id ";
  62. $sql .= " JOIN " . EVENTS_DETAIL_TABLE . " e ON e.id = r.event_id ";
  63. $sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id ";
  64. $sql .= " WHERE c.id = '" . $instance['category_name'] . "' ";
  65. $sql .= " AND e.is_active = 'Y' ";
  66. } else {
  67. $sql = "SELECT e.*, ese.start_time FROM " . EVENTS_DETAIL_TABLE . " e ";
  68. $sql .= " LEFT JOIN " . EVENTS_START_END_TABLE . " ese ON ese.event_id = e.id ";
  69. $sql .= " WHERE e.is_active = 'Y' ";
  70. }
  71. $sql .= $show_expired;
  72. $sql .= $show_secondary;
  73. $sql .= $show_deleted;
  74. $sql .= $show_recurrence;
  75. $sql .= " GROUP BY e.id ";
  76. $sql .= $order_by;
  77. $sql .= $limit;
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. /* Events */
  90. //Get number of total events
  91. $wpdb->query("SELECT id FROM ". EVENTS_DETAIL_TABLE ." WHERE event_status != 'D'");
  92. $total_events = $wpdb->num_rows;
  93.  
  94. //Get total events today
  95. $wpdb->query("SELECT id FROM ". EVENTS_DETAIL_TABLE ." WHERE event_status != 'D' AND start_date = '" . $curdate . "' ");
  96. $total_events_today = $wpdb->num_rows;
  97.  
  98. if ($total_events > 0) {
  99.  
  100. $curdate = date("Y-m-d");
  101. /*$pieces = explode('-',$curdate, 3);
  102. $this_year_r = $pieces[0];
  103. $this_month_r = $pieces[1];
  104. //echo $this_year_r;
  105. $days_this_month = date('t', strtotime($curdate));*/
  106.  
  107. $days_in_dasboard = $org_options['events_in_dasboard'] == ''? '30':stripslashes_deep($org_options['events_in_dasboard']);
  108.  
  109. $sql = "SELECT e.id event_id, e.event_name, e.event_identifier, e.reg_limit, e.registration_start, ";
  110. $sql .= " e.start_date, e.is_active, e.recurrence_id, e.registration_startT FROM ". EVENTS_DETAIL_TABLE ." e ";
  111. $sql .= " WHERE event_status != 'D' ";
  112. if ($total_events_today >0){
  113. $sql .= " AND start_date = '" . $curdate ."' ";
  114. global $how_many_events;
  115. $how_many_events = __('todays\' events', 'event_espresso');
  116. }else{
  117. $sql .= " AND ADDDATE('".date ( 'Y-m-d' )."', INTERVAL " . $days_in_dasboard . " DAY) >= start_date AND start_date >= '".date('Y-m-d', strtotime($curdate))."' ";
  118. global $how_many_events;
  119. $how_many_events = __("the next $days_in_dasboard days of events", 'event_espresso');
  120. }
  121. //$sql .= " WHERE event_status != 'D' AND start_date BETWEEN '".date('Y-m-d', strtotime($this_year_r. '-' .$this_month_r . '-01'))."' AND '".date('Y-m-d', strtotime($this_year_r . '-' .$this_month_r. '-' . $days_this_month))."' ";
  122.  
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. $events = $wpdb->get_results($sql);
  133.  
  134. //print_r($events);
  135. //event_espresso_get_event_details($sql);
  136. foreach ($events as $event) {
  137. $event->id = $event->id;
  138. $event->event_name = isset($event->event_name) ? $event->event_name : '';
  139. $event->start_date = isset($event->start_date) ? $event->start_date : '';
  140. $event->category_name = isset($event->category_name) ? $event->category_name : '';
  141. $event->category_desc = isset($event->category_desc) ? $event->category_desc : '';
  142. $event->externalURL = isset($event->externalURL) ? $event->externalURL : '';
  143. $registration_url = $event->externalURL != '' ? $event->externalURL : espresso_reg_url($event->id);
  144.  
  145. $all_meta = array(
  146. 'is_active' => $event->is_active,
  147. 'event_status' => $event->event_status,
  148. 'event_address' => $event->address,
  149. 'event_address2' => $event->address2,
  150. 'registration_startT' => $event->registration_startT,
  151. 'registration_start' => $event->registration_start,
  152. 'registration_endT' => $event->registration_endT,
  153. 'registration_end' => $event->registration_end,
  154. 'start_date' => event_date_display($event->start_date, get_option('date_format')),
  155. 'start_time' => event_date_display($event->start_time, get_option('time_format')),
  156. 'end_date' => event_date_display($event->end_date, get_option('date_format')),
  157. );
  158.  
  159. //Here we can create messages based on the event status
  160.  
  161. $status = event_espresso_get_is_active($event->id, $all_meta);
  162. //Print out the array of event status options
  163. //print_r (event_espresso_get_is_active($event->id));
  164.  
  165. $status_display = ' - ' . $status['display_custom'];
  166. $status_display_ongoing = $status['status'] == 'ONGOING' ? ' - ' . $status['display_custom'] : '';
  167. $status_display_deleted = $status['status'] == 'DELETED' ? ' - ' . $status['display_custom'] : '';
  168. $status_display_secondary = $status['status'] == 'SECONDARY' ? ' - ' . $status['display_custom'] : ''; //Waitlist event
  169. $status_display_reg_closed = $status['status'] == 'REGISTRATION_CLOSED' ? ' - ' . $status['display_custom'] : '';
  170. $status_display_not_open = $status['status'] == 'REGISTRATION_NOT_OPEN' ? ' - ' . $status['display_custom'] : '';
  171. $status_display_open = $status['status'] == 'REGISTRATION_OPEN' ? ' - ' . $status['display_custom'] : '';
  172.  
  173. //You can also display a custom message. For example, this is a custom registration not open message:
  174. $status_display_custom_closed = $status['status'] == 'REGISTRATION_CLOSED' ? ' - <span class="espresso_closed">' . __('Regsitration is closed', 'event_espresso') . '</span>' : '';
  175.  
  176. //End
  177.  
  178. if (!is_user_logged_in() && defined('EVENTS_MEMBER_REL_TABLE') && !empty($member_only) && $member_only == 'Y') {
  179. //Display a message if the user is not logged in.
  180. //_e('Member Only Event. Please ','event_espresso') . event_espresso_user_login_link() . '.';
  181. } else {
  182. //Serve up the event list
  183. //As of version 3.0.17 the event list details have been moved to event_list_display.php
  184. switch ($status['status']) {
  185. case 'NOT_ACTIVE':
  186. //Don't show the event if any of the above are true
  187. break;
  188.  
  189. default:
  190. ?>
  191. <p><a href="<?php echo $registration_url; ?>"><?php echo stripslashes_deep($event->event_name) ?> - <?php echo event_date_display($event->start_date) ?></a>
  192. <?php /* These are custom messages that can be displayed based on the event status. Just comment the one you want to use. */ ?>
  193. <?php //echo $status_display; //Turn this on to display the overall status of the event. ?>
  194. <?php //echo $status_display_ongoing; //Turn this on to display the ongoing message. ?>
  195. <?php //echo $status_display_deleted; //Turn this on to display the deleted message. ?>
  196. <?php //echo $status_display_secondary; //Turn this on to display the waitlist message. ?>
  197. <?php //echo $status_display_reg_closed; //Turn this on to display the secondary message. ?>
  198. <?php //echo $status_display_not_open; //Turn this on to display the secondary message. ?>
  199. <?php //echo $status_display_open; //Turn this on to display the secondary message. ?>
  200. <?php //echo $status_display_custom_closed; //Turn this on to display the secondary message. ?>
  201. </p>
  202. <?php
  203. break;
  204. }
  205. }
  206. }
  207. /* After widget (defined by themes). */
  208. echo $after_widget;
  209. }
  210.  
  211. /* Update the widget settings. */
  212.  
  213. function update($new_instance, $old_instance) {
  214. $instance = $old_instance;
  215.  
  216. /* Strip tags for title and name to remove HTML (important for text inputs). */
  217. $instance['title'] = strip_tags($new_instance['title']);
  218. $instance['category_name'] = $new_instance['category_name'];
  219. $instance['show_expired'] = $new_instance['show_expired'];
  220. $instance['show_secondary'] = $new_instance['show_secondary'];
  221. $instance['show_deleted'] = $new_instance['show_deleted'];
  222. $instance['show_recurrence'] = $new_instance['show_recurrence'];
  223. $instance['limit'] = $new_instance['limit'];
  224.  
  225. return $instance;
  226. }
  227.  
  228. /**
  229. * Displays the widget settings controls on the widget panel.
  230. * Make use of the get_field_id() and get_field_name() function
  231. * when creating your form elements. This handles the confusing stuff.
  232. * */
  233. function form($instance) {
  234.  
  235. /* Set up some default widget settings. */
  236.  
  237. $defaults = array('title' => __('Upcoming Events', 'event_espresso'), 'category_name' => '', 'show_expired' => 'false', 'show_secondary' => 'false', 'show_deleted' => 'false', 'show_recurrence' => 'false');
  238.  
  239. $instance = wp_parse_args((array) $instance, $defaults);
  240.  
  241. $values = array(
  242. array('id' => 'false', 'text' => __('No', 'event_espresso')),
  243. array('id' => 'true', 'text' => __('Yes', 'event_espresso')));
  244. //select_input('allow_multiple', $values, $allow_multiple);
  245. ?>
  246.  
  247. <!-- Widget Title: Text Input -->
  248.  
  249. <p>
  250. <label for="<?php echo $this->get_field_id('title'); ?>">
  251. <?php _e('Title:', 'event_espresso'); ?>
  252. </label>
  253. <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" size="20" type="text" />
  254. </p>
  255. <p> <label for="<?php echo $this->get_field_id('category_name'); ?>">
  256. <?php _e('Event Category:', 'event_espresso'); ?>
  257. </label><br />
  258. <?php echo espresso_db_dropdown('id', 'category_name', EVENTS_CATEGORY_TABLE, 'id', $instance['category_name'], $strMethod = "desc", $this->get_field_name('category_name')) ?></p>
  259. <p>
  260. <label for="<?php echo $this->get_field_id('limit'); ?>">
  261. <?php _e('Limit:', 'event_espresso'); ?>
  262. </label>
  263. <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" value="<?php echo $instance['limit']; ?>" size="3" type="text" />
  264. </p>
  265. <p><strong><?php _e('Optional Settings:', 'event_espresso'); ?></strong></p>
  266. <p><?php _e('Show Expired Events?', 'event_espresso'); ?> <?php echo select_input($this->get_field_name('show_expired'), $values, $instance['show_expired']); ?></p>
  267. <p><?php _e('Show Waitlist Events?', 'event_espresso'); ?> <?php echo select_input($this->get_field_name('show_secondary'), $values, $instance['show_secondary']); ?></p>
  268. <p><?php _e('Show Deleted Events?', 'event_espresso'); ?> <?php echo select_input($this->get_field_name('show_deleted'), $values, $instance['show_deleted']); ?></p>
  269. <p><?php _e('Show Recurring Events?', 'event_espresso'); ?> <?php echo select_input($this->get_field_name('show_recurrence'), $values, $instance['show_recurrence']); ?></p>
  270.  
  271. <?php
  272. }
  273.  
  274. }
  275.  
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement