Advertisement
Guest User

events_countdown.php

a guest
Jul 14th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.03 KB | None | 0 0
  1. <?php
  2. /**
  3. * Display Numbers that count from 0 to the number you entered
  4. */
  5.  
  6.  
  7. if( !class_exists( 'TribeEvents' ) )
  8. {
  9. function av_countdown_events_fallback()
  10. {
  11. return "<p>Please install the <a href='https://wordpress.org/plugins/the-events-calendar/'>The Events Calendar</a> or <a href='http://mbsy.co/6cr37'>The Events Calendar Pro</a> Plugin to display the countdown</p>";
  12. }
  13.  
  14. add_shortcode('av_events_countdown', 'av_countdown_events_fallback');
  15. return;
  16. }
  17.  
  18.  
  19. if ( !class_exists( 'avia_sc_events_countdown' ) )
  20. {
  21.  
  22. class avia_sc_events_countdown extends aviaShortcodeTemplate
  23. {
  24. /**
  25. * Create the config array for the shortcode button
  26. */
  27. function shortcode_insert_button()
  28. {
  29. $this->config['name'] = __('Events Countdown', 'avia_framework' );
  30. $this->config['tab'] = __('Plugin Additions', 'avia_framework' );
  31. $this->config['icon'] = AviaBuilder::$path['imagesURL']."sc-countdown.png";
  32. $this->config['order'] = 14;
  33. $this->config['target'] = 'avia-target-insert';
  34. $this->config['shortcode'] = 'av_events_countdown';
  35. $this->config['tooltip'] = __('Display a countdown to the next upcoming event', 'avia_framework' );
  36.  
  37. $this->time_array = array(
  38. __('Second', 'avia_framework' ) =>'1',
  39. __('Minute', 'avia_framework' ) =>'2',
  40. __('Hour', 'avia_framework' ) =>'3',
  41. __('Day', 'avia_framework' ) =>'4',
  42. __('Week', 'avia_framework' ) =>'5',
  43. /*
  44. __('Month', 'avia_framework' ) =>'6',
  45. __('Year', 'avia_framework' ) =>'7'
  46. */
  47. );
  48.  
  49.  
  50. }
  51.  
  52. function fetch_upcoming()
  53. {
  54. $query = array('paged'=> false, 'posts_per_page' => -1, 'eventDisplay' => 'list');
  55. $upcoming = TribeEventsQuery::getEvents( $query, true);
  56.  
  57. return $upcoming;
  58. }
  59.  
  60.  
  61. /**
  62. * Popup Elements
  63. *
  64. * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  65. * opens a modal window that allows to edit the element properties
  66. *
  67. * @return void
  68. */
  69. function popup_elements()
  70. {
  71. $this->elements = array(
  72. array(
  73. "type" => "tab_container", 'nodescription' => true
  74. ),
  75.  
  76. array(
  77. "type" => "tab",
  78. "name" => __("Content" , 'avia_framework'),
  79. 'nodescription' => true
  80. ),
  81.  
  82.  
  83. array(
  84. "name" => __("Smallest time unit", 'avia_framework' ),
  85. "desc" => __("The smallest unit that will be displayed", 'avia_framework' ),
  86. "id" => "min",
  87. "type" => "select",
  88. "std" => "1",
  89. "subtype" => $this->time_array),
  90.  
  91.  
  92. array(
  93. "name" => __("Largest time unit", 'avia_framework' ),
  94. "desc" => __("The largest unit that will be displayed", 'avia_framework' ),
  95. "id" => "max",
  96. "type" => "select",
  97. "std" => "5",
  98. "subtype" => $this->time_array),
  99.  
  100.  
  101.  
  102.  
  103. array(
  104. "name" => __("Text Alignment", 'avia_framework' ),
  105. "desc" => __("Choose here, how to align your text", 'avia_framework' ),
  106. "id" => "align",
  107. "type" => "select",
  108. "std" => "center",
  109. "subtype" => array(
  110. __('Center', 'avia_framework' ) =>'av-align-center',
  111. __('Right', 'avia_framework' ) =>'av-align-right',
  112. __('Left', 'avia_framework' ) =>'av-align-left',
  113. )
  114. ),
  115.  
  116. array( "name" => __("Number Font Size", 'avia_framework' ),
  117. "desc" => __("Size of your numbers in Pixel", 'avia_framework' ),
  118. "id" => "size",
  119. "type" => "select",
  120. "subtype" => AviaHtmlHelper::number_array(20,90,1, array( __("Default Size", 'avia_framework' )=>'')),
  121. "std" => ""),
  122.  
  123. array(
  124. "name" => __("Display Event Title?", 'avia_framework' ),
  125. "desc" => __("Choose here, if you want to display the event title", 'avia_framework' ),
  126. "id" => "title",
  127. "type" => "select",
  128. "std" => "",
  129. "subtype" => array(
  130. __('No Title, timer only', 'avia_framework' ) =>'',
  131. __('Title on top', 'avia_framework' ) =>'top',
  132. __('Title below', 'avia_framework' ) =>'bottom',
  133. )
  134. ),
  135.  
  136.  
  137.  
  138.  
  139. array(
  140. "type" => "close_div",
  141. 'nodescription' => true
  142. ),
  143.  
  144. array(
  145. "type" => "tab",
  146. "name" => __("Colors",'avia_framework' ),
  147. 'nodescription' => true
  148. ),
  149.  
  150. array(
  151. "name" => __("Colors", 'avia_framework' ),
  152. "desc" => __("Choose the colors here", 'avia_framework' ),
  153. "id" => "style",
  154. "type" => "select",
  155. "std" => "center",
  156. "subtype" => array(
  157. __('Default', 'avia_framework' ) =>'av-default-style',
  158. __('Theme colors', 'avia_framework' ) =>'av-colored-style',
  159. __('Transparent Light', 'avia_framework' ) =>'av-trans-light-style',
  160. __('Transparent Dark', 'avia_framework' ) =>'av-trans-dark-style',
  161. )
  162. ),
  163. array(
  164. "type" => "close_div",
  165. 'nodescription' => true
  166. ),
  167.  
  168. array(
  169. "type" => "close_div",
  170. 'nodescription' => true
  171. ),
  172. );
  173.  
  174. }
  175.  
  176. /**
  177. * Frontend Shortcode Handler
  178. *
  179. * @param array $atts array of attributes
  180. * @param string $content text within enclosing form of shortcode element
  181. * @param string $shortcodename the shortcode found, when == callback name
  182. * @return string $output returns the modified html string
  183. */
  184. function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  185. {
  186. $time = time();
  187. $next = $this->fetch_upcoming();
  188.  
  189. $upcomings = array();
  190.  
  191. foreach($next->posts as $post) {
  192. $end = explode(" ", $post->EventEndDate );
  193. $start = explode(" ", $post->EventStartDate );
  194.  
  195. if($time < strtotime($end[0]) && strtotime($start[0]) > $time) {
  196. $upcomings[] = $post;
  197. }
  198. }
  199.  
  200. if(empty( $upcomings[1] ) || empty( $upcomings[1]->EventStartDate )) return;
  201.  
  202. $events_date = explode(" ", $upcomings[1]->EventStartDate );
  203.  
  204. if(isset($events_date[0]))
  205. {
  206. $atts['date'] = date("m/d/Y", strtotime($events_date[0]));
  207. }
  208.  
  209. if(isset($events_date[1]))
  210. {
  211. $events_date = explode(":", $events_date[1] );
  212. $atts['hour'] = $events_date[0];
  213. $atts['minute'] = $events_date[1];
  214. }
  215.  
  216. $atts['link'] = get_permalink( $upcomings[1]->ID );
  217. $title = get_the_title( $upcomings[1]->ID );
  218.  
  219. if(!empty( $atts['title'] ))
  220. {
  221. $atts['title'] = array( $atts['title'] => __("Upcoming",'avia_framework') .": " . $title );
  222. }
  223.  
  224. $timer = new avia_sc_countdown( $this->builder );
  225. $output = $timer->shortcode_handler( $atts , $content, $shortcodename, $meta);
  226.  
  227.  
  228. return $output;
  229. }
  230. }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement