Advertisement
Guest User

events_countdown.php

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