Created
January 13, 2012 15:53
-
-
Save objectivehtml/1607083 to your computer and use it in GitHub Desktop.
A simpe date comparison utility
This file contains hidden or 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'); | |
/** | |
* Simple Date Formatting Plugin | |
* | |
* @package ExpressionEngine | |
* @category Plugin | |
* @author Justin Kimbrell | |
* @copyright Copyright (c) 2012, Justin Kimbrell | |
* @link http://objectivehtml.com/ | |
*/ | |
$plugin_info = array( | |
'pi_name' => 'Date Format', | |
'pi_version' => '1.0', | |
'pi_author' => 'Justin Kimbrell', | |
'pi_author_url' => 'http://objectivehtml.com/', | |
'pi_description' => 'Allows custom date formatted and specialized conditionals', | |
'pi_usage' => Date_format::usage() | |
); | |
class Date_format { | |
public $return_data = ""; | |
public function __construct() | |
{ | |
$this->EE =& get_instance(); | |
} | |
public function future_entries() | |
{ | |
$date = strtotime($this->param('date')); | |
$time = $this->param('time') ? strtotime($this->param('time')) : $this->EE->localize->now; | |
if($date >= $time) | |
{ | |
return $this->EE->TMPL->tagdata; | |
} | |
return NULL; | |
} | |
private function param($param, $default = FALSE, $boolean = FALSE, $required = FALSE) | |
{ | |
$name = $param; | |
$param = $this->EE->TMPL->fetch_param($param); | |
if($required && !$param) show_error('You must define a "'.$name.'" parameter in the '.__CLASS__.' tag.'); | |
if($param === FALSE && $default !== FALSE) | |
{ | |
$param = $default; | |
} | |
else | |
{ | |
if($boolean) | |
{ | |
$param = strtolower($param); | |
$param = ($param == 'true' || $param == 'yes') ? TRUE : FALSE; | |
} | |
} | |
return $param; | |
} | |
// -------------------------------------------------------------------- | |
/** | |
* Usage | |
* | |
* This function describes how the plugin is used. | |
* | |
* @access public | |
* @return string | |
*/ | |
public static function usage() | |
{ | |
ob_start(); ?> | |
{exp:date_format:future_entries date="01/01/2013"} | |
If the date is in the future, the tagdata is returned. | |
{/exp:date_format:future_entries} | |
{exp:date_format:future_entries date="01/01/2013" time="01/01/2011"} | |
You can even set a custom time for your starting comparison. | |
{/exp:date_format:future_entries} | |
<?php | |
$buffer = ob_get_contents(); | |
ob_end_clean(); | |
return $buffer; | |
} | |
// END | |
} | |
/* End of file pi.memberlist.php */ | |
/* Location: ./system/expressionengine/third_party/memberlist/pi.memberlist.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment