Created
November 29, 2012 15:34
-
-
Save themusicman/4169835 to your computer and use it in GitHub Desktop.
Simple Little Date Range Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* ExpressionEngine - by EllisLab | |
* | |
* @package ExpressionEngine | |
* @author ExpressionEngine Dev Team | |
* @copyright Copyright (c) 2003 - 2011, EllisLab, Inc. | |
* @license http://expressionengine.com/user_guide/license.html | |
* @link http://expressionengine.com | |
* @since Version 2.0 | |
* @filesource | |
*/ | |
// ------------------------------------------------------------------------ | |
/** | |
* Rangee Plugin | |
* | |
* @package ExpressionEngine | |
* @subpackage Addons | |
* @category Plugin | |
* @author Thomas Brewer | |
* @link | |
*/ | |
$plugin_info = array( | |
'pi_name' => 'Rangee', | |
'pi_version' => '1.0', | |
'pi_author' => 'Thomas Brewer', | |
'pi_author_url' => 'http://21purple.com', | |
'pi_description'=> 'Ranges', | |
'pi_usage' => Rangee::usage() | |
); | |
class Rangee { | |
public $return_data; | |
public function __construct() | |
{ | |
$this->EE =& get_instance(); | |
} | |
/** | |
* Template Usage: | |
* | |
* {exp:rangee:date_range start_date="{entry_date}" end_date="{expiration_date}"} | |
* | |
* Params: | |
* start_date="{entry_date}" | |
* end_date="{expiration_date}" | |
* month_format="%b" (default: %b) | |
* day_format="%e" (default: %e) | |
* year_format="%Y" (default: %Y) | |
* | |
**/ | |
public function date_range() | |
{ | |
$start_date = (int) $this->EE->TMPL->fetch_param('start_date', 0); | |
$end_date = (int) $this->EE->TMPL->fetch_param('end_date', 0); | |
$month_format = $this->EE->TMPL->fetch_param('month_format', '%b'); | |
$day_format = $this->EE->TMPL->fetch_param('day_format', '%e'); | |
$year_format = $this->EE->TMPL->fetch_param('year_format', '%Y'); | |
if ($end_date) | |
{ | |
$date_range = strftime("{$month_format} {$day_format}", $start_date); | |
if (strftime("{$year_format}", $start_date) != strftime("{$year_format}", $end_date)) | |
{ | |
$date_range .= strftime(", {$year_format}", $start_date); | |
} | |
if (strftime("{$day_format}", $start_date) != strftime("{$day_format}", $end_date)) | |
{ | |
$date_range .= " - "; | |
if (strftime("{$month_format}", $start_date) != strftime("{$month_format}", $end_date)) | |
{ | |
$date_range .= strftime("{$month_format}", $end_date) . " "; | |
} | |
$date_range .= strftime("{$day_format}", $end_date); | |
if (strftime("{$year_format}", $start_date) != strftime("{$year_format}", $end_date)) | |
{ | |
$date_range .= strftime(", {$year_format}", $end_date); | |
} | |
else | |
{ | |
$date_range .= strftime(", {$year_format}", $start_date); | |
} | |
} | |
else | |
{ | |
$date_range .= strftime(", {$year_format}", $start_date); | |
} | |
} | |
else | |
{ | |
$date_range = $date_range = strftime("{$month_format} {$day_format}, {$year_format}", $start_date); | |
} | |
return trim($date_range); | |
} | |
// ---------------------------------------------------------------- | |
/** | |
* Plugin Usage | |
*/ | |
public static function usage() | |
{ | |
ob_start(); | |
?> | |
Since you did not provide instructions on the form, make sure to put plugin documentation here. | |
<?php | |
$buffer = ob_get_contents(); | |
ob_end_clean(); | |
return $buffer; | |
} | |
} | |
/* End of file pi.rangee.php */ | |
/* Location: /system/expressionengine/third_party/rangee/pi.rangee.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment