PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/events-manager/widgets/em-events.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net
PHP | 190 lines | 164 code | 11 blank | 15 comment | 18 complexity | ebce7d536da7ec72c9b978109837c33c MD5 | raw file
  1. <?php
  2. /**
  3. * @author marcus
  4. * Standard events list widget
  5. */
  6. class EM_Widget extends WP_Widget {
  7. var $defaults;
  8. /** constructor */
  9. function EM_Widget() {
  10. $this->defaults = array(
  11. 'title' => __('Events','dbem'),
  12. 'scope' => 'future',
  13. 'order' => 'ASC',
  14. 'limit' => 5,
  15. 'category' => 0,
  16. 'format' => '#_EVENTLINK<ul><li>#j #M #y</li><li>#_LOCATIONTOWN</li></ul>',
  17. 'nolistwrap' => false,
  18. 'orderby' => 'event_start_date,event_start_time,event_name',
  19. 'all_events' => 0,
  20. 'all_events_text' => __('all events', 'dbem'),
  21. 'no_events_text' => __('No events', 'dbem')
  22. );
  23. $this->em_orderby_options = apply_filters('em_settings_events_default_orderby_ddm', array(
  24. 'event_start_date,event_start_time,event_name' => __('start date, start time, event name','dbem'),
  25. 'event_name,event_start_date,event_start_time' => __('name, start date, start time','dbem'),
  26. 'event_name,event_end_date,event_end_time' => __('name, end date, end time','dbem'),
  27. 'event_end_date,event_end_time,event_name' => __('end date, end time, event name','dbem'),
  28. ));
  29. $widget_ops = array('description' => __( "Display a list of events on Events Manager.", 'dbem') );
  30. parent::WP_Widget(false, $name = 'Events', $widget_ops);
  31. }
  32. /** @see WP_Widget::widget */
  33. function widget($args, $instance) {
  34. $instance = array_merge($this->defaults, $instance);
  35. $instance = $this->fix_scope($instance); // depcreciate
  36. echo $args['before_widget'];
  37. if( !empty($instance['title']) ){
  38. echo $args['before_title'];
  39. echo $instance['title'];
  40. echo $args['after_title'];
  41. }
  42. $instance['owner'] = false;
  43. //orderby fix for previous versions with old orderby values
  44. if( !array_key_exists($instance['orderby'], $this->em_orderby_options) ){
  45. //replace old values
  46. $old_vals = array(
  47. 'name' => 'event_name',
  48. 'end_date' => 'event_end_date',
  49. 'start_date' => 'event_start_date',
  50. 'end_time' => 'event_end_time',
  51. 'start_time' => 'event_start_time'
  52. );
  53. foreach($old_vals as $old_val => $new_val){
  54. $instance['orderby'] = str_replace($old_val, $new_val, $instance['orderby']);
  55. }
  56. }
  57. $events = EM_Events::get(apply_filters('em_widget_events_get_args',$instance));
  58. echo "<ul>";
  59. $li_wrap = !preg_match('/^<li>/i', trim($instance['format']));
  60. if ( count($events) > 0 ){
  61. foreach($events as $event){
  62. if( $li_wrap ){
  63. echo '<li>'. $event->output($instance['format']) .'</li>';
  64. }else{
  65. echo $event->output($instance['format']);
  66. }
  67. }
  68. }else{
  69. echo '<li>'.$instance['no_events_text'].'</li>';
  70. }
  71. if ( !empty($instance['all_events']) ){
  72. $events_link = (!empty($instance['all_events_text'])) ? em_get_link($instance['all_events_text']) : em_get_link(__('all events','dbem'));
  73. echo '<li class="all-events-link">'.$events_link.'</li>';
  74. }
  75. echo "</ul>";
  76. echo $args['after_widget'];
  77. }
  78. /** @see WP_Widget::update */
  79. function update($new_instance, $old_instance) {
  80. foreach($this->defaults as $key => $value){
  81. if( !isset($new_instance[$key]) ){
  82. $new_instance[$key] = $value;
  83. }
  84. }
  85. return $new_instance;
  86. }
  87. /** @see WP_Widget::form */
  88. function form($instance) {
  89. $instance = array_merge($this->defaults, $instance);
  90. $instance = $this->fix_scope($instance); // depcreciate
  91. ?>
  92. <p>
  93. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'dbem'); ?>: </label>
  94. <input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" />
  95. </p>
  96. <p>
  97. <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e('Number of events','dbem'); ?>: </label>
  98. <input type="text" id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" size="3" value="<?php echo esc_attr($instance['limit']); ?>" />
  99. </p>
  100. <p>
  101. <label for="<?php echo $this->get_field_id('scope'); ?>"><?php _e('Scope','dbem'); ?>: </label><br/>
  102. <select id="<?php echo $this->get_field_id('scope'); ?>" name="<?php echo $this->get_field_name('scope'); ?>" >
  103. <?php foreach( em_get_scopes() as $key => $value) : ?>
  104. <option value='<?php echo $key ?>' <?php echo ($key == $instance['scope']) ? "selected='selected'" : ''; ?>>
  105. <?php echo $value; ?>
  106. </option>
  107. <?php endforeach; ?>
  108. </select>
  109. </p>
  110. <p>
  111. <label for="<?php echo $this->get_field_id('order'); ?>"><?php _e('Order By','dbem'); ?>: </label>
  112. <select id="<?php echo $this->get_field_id('orderby'); ?>" name="<?php echo $this->get_field_name('orderby'); ?>">
  113. <?php
  114. echo $this->em_orderby_options;
  115. ?>
  116. <?php foreach($this->em_orderby_options as $key => $value) : ?>
  117. <option value='<?php echo $key ?>' <?php echo ( !empty($instance['orderby']) && $key == $instance['orderby']) ? "selected='selected'" : ''; ?>>
  118. <?php echo $value; ?>
  119. </option>
  120. <?php endforeach; ?>
  121. </select>
  122. </p>
  123. <p>
  124. <label for="<?php echo $this->get_field_id('order'); ?>"><?php _e('Order','dbem'); ?>: </label>
  125. <select id="<?php echo $this->get_field_id('order'); ?>" name="<?php echo $this->get_field_name('order'); ?>">
  126. <?php
  127. $order_options = apply_filters('em_widget_order_ddm', array(
  128. 'ASC' => __('Ascending','dbem'),
  129. 'DESC' => __('Descending','dbem')
  130. ));
  131. ?>
  132. <?php foreach( $order_options as $key => $value) : ?>
  133. <option value='<?php echo $key ?>' <?php echo ($key == $instance['order']) ? "selected='selected'" : ''; ?>>
  134. <?php echo $value; ?>
  135. </option>
  136. <?php endforeach; ?>
  137. </select>
  138. </p>
  139. <p>
  140. <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e('Category IDs','dbem'); ?>: </label>
  141. <input type="text" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" size="3" value="<?php echo esc_attr($instance['category']); ?>" /><br />
  142. <em><?php _e('1,2,3 or 2 (0 = all)','dbem'); ?> </em>
  143. </p>
  144. <p>
  145. <label for="<?php echo $this->get_field_id('format'); ?>"><?php _e('List item format','dbem'); ?>: </label>
  146. <textarea rows="5" cols="24" id="<?php echo $this->get_field_id('format'); ?>" name="<?php echo $this->get_field_name('format'); ?>"><?php echo $instance['format']; ?></textarea>
  147. </p>
  148. <p>
  149. <label for="<?php echo $this->get_field_id('all_events'); ?>"><?php _e('Show all events link at bottom?','dbem'); ?>: </label>
  150. <input type="checkbox" id="<?php echo $this->get_field_id('all_events'); ?>" name="<?php echo $this->get_field_name('all_events'); ?>" <?php echo (!empty($instance['all_events']) && $instance['all_events']) ? 'checked':''; ?> >
  151. </p>
  152. <p>
  153. <label for="<?php echo $this->get_field_id('all_events'); ?>"><?php _e('All events link text?','dbem'); ?>: </label>
  154. <input type="text" id="<?php echo $this->get_field_id('all_events_text'); ?>" name="<?php echo $this->get_field_name('all_events_text'); ?>" value="<?php echo (!empty($instance['all_events_text'])) ? $instance['all_events_text']:__('all events','dbem'); ?>" >
  155. </p>
  156. <p>
  157. <label for="<?php echo $this->get_field_id('no_events_text'); ?>"><?php _e('No events text','dbem'); ?>: </label>
  158. <input type="text" id="<?php echo $this->get_field_id('no_events_text'); ?>" name="<?php echo $this->get_field_name('no_events_text'); ?>" value="<?php echo (!empty($instance['no_events_text'])) ? $instance['no_events_text']:__('No events', 'dbem'); ?>" >
  159. </p>
  160. <?php
  161. }
  162. /**
  163. * Backwards compatability for an old setting which is now just another scope.
  164. * @param unknown_type $instance
  165. * @return string
  166. */
  167. function fix_scope($instance){
  168. if( !empty($instance['time_limit']) && is_numeric($instance['time_limit']) && $instance['time_limit'] > 1 ){
  169. $instance['scope'] = $instance['time_limit'].'-months';
  170. }elseif( !empty($instance['time_limit']) && $instance['time_limit'] == 1){
  171. $instance['scope'] = 'month';
  172. }elseif( !empty($instance['time_limit']) && $instance['time_limit'] == 'no-limit'){
  173. $instance['scope'] = 'all';
  174. }
  175. return $instance;
  176. }
  177. }
  178. add_action('widgets_init', create_function('', 'return register_widget("EM_Widget");'));
  179. ?>