-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpi.countdown.php
More file actions
91 lines (66 loc) · 2.25 KB
/
Copy pathpi.countdown.php
File metadata and controls
91 lines (66 loc) · 2.25 KB
1
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');$plugin_info = array( 'pi_name' => 'EE2 Countdown', 'pi_version' => '1.0', 'pi_author' => 'Jack McDade', 'pi_author_url' => 'http://lobsterwarmachine.com/', 'pi_description' => "Counts down to a given date. Based off Marlana Shipley's EE Countdown plugin.", 'pi_usage' => Countdown::usage());class Countdown{ var $return_data = ''; function Countdown() { $this->EE =& get_instance(); $day = $this->EE->TMPL->fetch_param('day'); $month = $this->EE->TMPL->fetch_param('month'); $year = $this->EE->TMPL->fetch_param('year'); $hour = $this->EE->TMPL->fetch_param('hour'); // get current unix timestamp $today = time(); //make unix timestamp for given date $countdowndate = mktime(0, 0, $hour, $month, $day, $year); //calculate difference $difference = $countdowndate - $today; $difference = $difference < 0 ? 0 : $difference; $days_left = floor($difference/60/60/24); $hours_left = floor(($difference - $days_left*60*60*24)/60/60); $variables = array(); $variables[] = array( 'days' => $days_left, 'hours' => $hours_left ); $this->return_data = $this->EE->TMPL->parse_variables($this->EE->TMPL->tagdata, $variables); } // ---------------------------------------- // Plugin Usage // ---------------------------------------- function usage() { ob_start(); ?> The EE Countdown plug-in allows you to insert a simple countdown to a specified date into your templates. The required paramaters are the day, month and year (in numberic form) of the date you are counting down to. ==REQUIRED PARAMETERS== day="[1..31]" The day of the month you are counting down to. month="[1..12]" The month number that you are counting down to. Ex: 1 for January, 2 February, etc. year="[2004...]" The year, any above 2004 should work. ==OPTIONAL PARAMETERS== hours="[0...24]" The hour your event begins on, in 24 hour format. 24 is midnight, 12 is noon, etc. ==SINGLE VARIABLES== {days} Days left {hours} Hours left ===POSSIBLE EXAMPLES=== {exp:countdown day="25" month="12" year="2012"} Christmas next year is in {days} days. {/exp:countdown} <?php $buffer = ob_get_contents(); ob_end_clean(); return $buffer; }}