1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-13 18:14:26 +02:00

Major clean-up and enhancement of datepicker() and related functions

This commit is contained in:
CaMer0n
2012-05-26 12:21:39 +00:00
parent 1c7db4632a
commit d8a6c15c02
14 changed files with 1915 additions and 133 deletions

View File

@@ -1077,26 +1077,37 @@ class admin_newspost
$ix = new news; $ix = new news;
$_POST['news_start'] = vartrue(e107::getDate()->convert($_POST['news_start'],'inputdatetime'), 0);
echo "date=".$_POST['news_start'];
if($_POST['news_start']) if($_POST['news_start'])
{ {
$tmp = explode("/", $_POST['news_start']); // $_POST['news_start'] = e107::getDate()->convert($_POST['news_start']);
$_POST['news_start'] = mktime(0, 0, 0, $tmp[1], $tmp[0], $tmp[2]);
} }
else else
{ {
$_POST['news_start'] = 0; // $_POST['news_start'] = 0;
} }
if($_POST['news_end']) if($_POST['news_end'])
{ {
$tmp = explode("/", $_POST['news_end']); $_POST['news_end'] = e107::getDate()->convert($_POST['news_end'],'inputdatetime');
$_POST['news_end'] = mktime(0, 0, 0, $tmp[1], $tmp[0], $tmp[2]);
} }
else else
{ {
$_POST['news_end'] = 0; $_POST['news_end'] = 0;
} }
if($_POST['news_datestamp'])
{
$_POST['news_datestamp'] = e107::getDate()->convert($_POST['news_datestamp'],'inputdatetime');
}
else
{
$_POST['news_datestamp'] = time();
}
/*
$matches = array(); $matches = array();
if(preg_match('#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#', $_POST['news_datestamp'], $matches)) if(preg_match('#(.*?)/(.*?)/(.*?) (.*?):(.*?):(.*?)$#', $_POST['news_datestamp'], $matches))
{ {
@@ -1111,6 +1122,8 @@ class admin_newspost
{ {
$_POST['news_datestamp'] = time(); $_POST['news_datestamp'] = time();
} }
*/
if ($id && $sub_action != "sn" && $sub_action != "upload") if ($id && $sub_action != "sn" && $sub_action != "upload")
{ {
@@ -2088,7 +2101,7 @@ class admin_newspost
<div class='field-spacer'>".NWSLAN_21.":</div> <div class='field-spacer'>".NWSLAN_21.":</div>
<div class='field-spacer'> <div class='field-spacer'>
"; ";
/*
$_startdate = ($_POST['news_start'] > 0) ? date("d/m/Y", $_POST['news_start']) : ""; $_startdate = ($_POST['news_start'] > 0) ? date("d/m/Y", $_POST['news_start']) : "";
$cal_options['showsTime'] = false; $cal_options['showsTime'] = false;
@@ -2101,9 +2114,14 @@ class admin_newspost
$cal_attrib['value'] = $_startdate; $cal_attrib['value'] = $_startdate;
$cal_attrib['tabindex'] = $frm->getNext(); $cal_attrib['tabindex'] = $frm->getNext();
$text .= $this->_cal->make_input_field($cal_options, $cal_attrib); $text .= $this->_cal->make_input_field($cal_options, $cal_attrib);
*/
$text .= $frm->datepicker("news_start",$_POST['news_start'],"type=datetime");
$text .= " - "; $text .= " - ";
/*
$_enddate = ($_POST['news_end'] > 0) ? date("d/m/Y", $_POST['news_end']) : ""; $_enddate = ($_POST['news_end'] > 0) ? date("d/m/Y", $_POST['news_end']) : "";
unset($cal_options); unset($cal_options);
@@ -2118,6 +2136,8 @@ class admin_newspost
$cal_attrib['value'] = $_enddate; $cal_attrib['value'] = $_enddate;
$cal_attrib['tabindex'] = $frm->getNext(); $cal_attrib['tabindex'] = $frm->getNext();
$text .= $this->_cal->make_input_field($cal_options, $cal_attrib); $text .= $this->_cal->make_input_field($cal_options, $cal_attrib);
*/
$text .= $frm->datepicker("news_end",$_POST['news_end'],"type=datetime");
$text .= " $text .= "
</div> </div>
@@ -2131,7 +2151,7 @@ class admin_newspost
<td class='control'> <td class='control'>
<div class='field-spacer'> <div class='field-spacer'>
"; ";
/*
$_update_datestamp = ($_POST['news_datestamp'] > 0 && !strpos($_POST['news_datestamp'],"/")) ? date("d/m/Y H:i:s", $_POST['news_datestamp']) : trim($_POST['news_datestamp']); $_update_datestamp = ($_POST['news_datestamp'] > 0 && !strpos($_POST['news_datestamp'],"/")) ? date("d/m/Y H:i:s", $_POST['news_datestamp']) : trim($_POST['news_datestamp']);
unset($cal_options); unset($cal_options);
unset($cal_attrib); unset($cal_attrib);
@@ -2144,6 +2164,8 @@ class admin_newspost
$cal_attrib['name'] = "news_datestamp"; $cal_attrib['name'] = "news_datestamp";
$cal_attrib['value'] = $_update_datestamp; $cal_attrib['value'] = $_update_datestamp;
$text .= $this->_cal->make_input_field($cal_options, $cal_attrib); $text .= $this->_cal->make_input_field($cal_options, $cal_attrib);
*/
$text .= $frm->datepicker("news_datestamp",$_POST['news_datestamp'],"type=datetime");
$text .= " $text .= "
</div> </div>

View File

@@ -421,6 +421,7 @@ $ga = new convert();
$date1 = $ga->convert_date(time(), "short"); $date1 = $ga->convert_date(time(), "short");
$date2 = $ga->convert_date(time(), "long"); $date2 = $ga->convert_date(time(), "long");
$date3 = $ga->convert_date(time(), "forum"); $date3 = $ga->convert_date(time(), "forum");
$date4 = e107::getDate()->convert(time(),"input");
$text .= " $text .= "
<fieldset class='e-hideme' id='core-prefs-date'> <fieldset class='e-hideme' id='core-prefs-date'>
@@ -452,6 +453,51 @@ $text .= "
<div class='field-help'>".PRFLAN_83.": {$date3}</div> <div class='field-help'>".PRFLAN_83.": {$date3}</div>
<div class='field-help'>".PRFLAN_25." <a href='http://www.php.net/manual/en/function.strftime.php' rel='external'>".PRFLAN_93."</a></div> <div class='field-help'>".PRFLAN_25." <a href='http://www.php.net/manual/en/function.strftime.php' rel='external'>".PRFLAN_93."</a></div>
</td> </td>
</tr>";
$inputdate = array( // TODO add more formats
"%A, %d %b, %Y" => strftime("%A, %d %b, %Y"),
"%a, %d %b, %Y" => strftime("%a, %d %b, %Y"),
"%Y-%m-%d" => strftime("%Y-%m-%d"),
"%d-%m-%Y" => strftime("%d-%m-%Y"),
"%m/%d/%Y" => strftime("%m/%d/%Y")
);
$inputtime = array();
$inputtime["%I:%M %p"] = strftime("%I:%M %p",mktime(14,3,11));
if(e107::getDate()->supported('P'))
{
$inputtime["%I:%M %P"] = strftime("%I:%M %P",mktime(14,3,11));
}
if(e107::getDate()->supported('l'))
{
$inputtime["%l:%M %p"] = strftime("%l:%M %p",mktime(14,3,11));
$inputtime["%l:%M %P"] = strftime("%l:%M %P",mktime(14,3,11));
}
$inputtime["%H:%M"] = strftime("%H:%M",mktime(14,3,11));
$inputtime["%H:%M:%S"] = strftime("%H:%M:%S",mktime(14,3,11));
$text .= "
<tr>
<td class='label'>Date/Time Input-Field format: </td>
<td class='control'>
".$frm->selectbox('inputdate',$inputdate, e107::getPref('inputdate'));
$text .= $frm->selectbox('inputtime',$inputtime, e107::getPref('inputtime'));
$text .= "
</td>
</tr> </tr>
<tr> <tr>
<td class='label'>".PRFLAN_26."</td> <td class='label'>".PRFLAN_26."</td>

View File

@@ -101,6 +101,8 @@
<core name="logcode">0</core> <core name="logcode">0</core>
<core name="loginname_maxlength">30</core> <core name="loginname_maxlength">30</core>
<core name="longdate">%A %d %B %Y - %H:%M:%S</core> <core name="longdate">%A %d %B %Y - %H:%M:%S</core>
<core name="inputdate">%A, %d %b, %Y</core>
<core name="inputtime">%I:%M %p</core>
<core name="mail_pause">3</core> <core name="mail_pause">3</core>
<core name="mail_bounce">none</core> <core name="mail_bounce">none</core>
<core name="mail_pausetime">4</core> <core name="mail_pausetime">4</core>

View File

@@ -10,7 +10,56 @@ $(document).ready(function()
// Date // Date
$(function() { $(function() {
$( ".e-date" ).datepicker();
$("input.e-date").each(function() {
$(this).datepicker({
dateFormat: $(this).attr("data-date-format"),
ampm: $(this).attr("data-date-ampm")
});
});
$("input.e-datetime").each(function() {
$(this).datetimepicker({
dateFormat: $(this).attr("data-date-format"),
timeFormat: $(this).attr("data-time-format"),
ampm: $(this).attr("data-date-ampm")
});
});
// Inline versions
$("span.e-date").each(function() {
var id = $(this).attr("id");
var newid = id.replace("inline-", "");
$(this).datepicker({
dateFormat: $(this).attr("data-date-format"),
ampm: $(this).attr("data-date-ampm"),
defaultDate: $("#"+newid).val(),
onSelect: function(dateText, inst) {
$("#"+newid).val(dateText);
}
});
});
$("span.e-datetime").each(function() {
var id = $(this).attr("id");
var newid = id.replace("inline-", "");
$(this).datetimepicker({
dateFormat: $(this).attr("data-date-format"),
ampm: $(this).attr("data-date-ampm"),
defaultDate: $("#"+newid).val(),
onSelect: function(dateText, inst) {
$("#"+newid).val(dateText);
}
});
});
}); });
// Tabs // Tabs

File diff suppressed because it is too large Load Diff

View File

@@ -2840,7 +2840,13 @@ class e_admin_controller_ui extends e_admin_controller
case 'datestamp': case 'datestamp':
if(!is_numeric($value)) if(!is_numeric($value))
{ {
$value = trim($value) ? e107::getDateConvert()->toTime($value, 'input') : 0; if(vartrue($attributes['writeParms']))
{
parse_str($attributes['writeParms'],$opt);
}
$format = $opt['type'] ? ('input'.$opt['type']) : 'inputdate';
$value = trim($value) ? e107::getDate()->toTime($value, $format) : 0;
} }
break; break;

View File

@@ -18,6 +18,12 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE."/lan_date.php");
class convert class convert
{ {
function __construct()
{
}
/** /**
* Convert datestamp to human readable date. * Convert datestamp to human readable date.
* System time offset is considered. * System time offset is considered.
@@ -43,8 +49,19 @@ class convert
$mask = e107::getPref('shortdate'); $mask = e107::getPref('shortdate');
break; break;
case 'input': //New - use inputdate as mask; FIXME - add inputdate to Date site prefs case 'input':
$mask = e107::getPref('inputdate', '%d/%m/%Y %H:%M:%S'); case 'inputdate':
$mask = e107::getPref('inputdate', '%d/%m/%Y %H:%M');
// $mask .= " ".e107::getPref('inputtime', '%H:%M');
break;
case 'inputdatetime':
$mask = e107::getPref('inputdate', '%d/%m/%Y %H:%M');
$mask .= " ".e107::getPref('inputtime', '%H:%M');
break;
case 'inputtime':
$mask .= e107::getPref('inputtime', '%H:%M');
break; break;
case 'forum': // DEPRECATED - temporary here from BC reasons only case 'forum': // DEPRECATED - temporary here from BC reasons only
@@ -63,6 +80,18 @@ class convert
/**
* Converts between unix timestamp and human-readable date-time OR vice-versa. (auto-detected)
* @param string $string unix timestamp OR human-readable date-time.
* @param string $mask (optional) long | short | input
*/
function convert($string=null, $mask = 'inputdate')
{
if($string == null) return false;
return is_integer($string) ? $this->convert_date($string, $mask) : $this->toTime($string, $mask);
}
/** /**
* Convert date string back to integer (unix timestamp) * Convert date string back to integer (unix timestamp)
@@ -84,13 +113,26 @@ class convert
$mask = e107::getPref('shortdate'); $mask = e107::getPref('shortdate');
break; break;
case 'input': //New - use inputdate as mask; FIXME - add inputdate to Date site prefs case 'input':
$mask = e107::getPref('inputdate', '%d/%m/%Y %H:%M:%S'); case 'inputdate':
$mask = e107::getPref('inputdate', '%Y/%m/%d');
break;
case 'inputdatetime':
$mask = e107::getPref('inputdate', '%Y/%m/%d');
$mask .= " ".e107::getPref('inputtime', '%H:%M');
break;
case 'inputtime':
$mask = e107::getPref('inputtime', '%H:%M');
break; break;
} }
// see php compat handler // also in php compat handler for plugins that might use it.
$tdata = strptime($date_string, $mask); $tdata = $this->strptime($date_string, $mask);
print_a($tdata);
if(empty($tdata)) if(empty($tdata))
{ {
return null; return null;
@@ -99,19 +141,16 @@ class convert
$tdata['tm_hour'], $tdata['tm_hour'],
$tdata['tm_min'], $tdata['tm_min'],
$tdata['tm_sec'], $tdata['tm_sec'],
$tdata['tm_mon'] + 1, $tdata['tm_mon'],
$tdata['tm_mday'], $tdata['tm_mday'],
$tdata['tm_year'] + 1900 ($tdata['tm_year'] + 1900)
); );
// var_dump($tdata, $date_string, $this->convert_date($unxTimestamp, $mask), $unxTimestamp); // var_dump($tdata, $date_string, $this->convert_date($unxTimestamp, $mask), $unxTimestamp);
return $unxTimestamp; return $unxTimestamp;
} }
// -----------------------
/** /**
* Tolerant date/time input routine - doesn't force use of specific delimiters, and can sometimes allow no delimiters at all * Tolerant date/time input routine - doesn't force use of specific delimiters, and can sometimes allow no delimiters at all
@@ -347,5 +386,243 @@ class convert
} }
return ($mode ? $outputArray : implode(", ", $outputArray)); return ($mode ? $outputArray : implode(", ", $outputArray));
} }
/**
* This work of Lionel SAURON (http://sauron.lionel.free.fr:80) is licensed under the
* Creative Commons Attribution-Noncommercial-Share Alike 2.0 France License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.0/fr/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
* http://snipplr.com/view/4964/emulate-php-5-for-backwards-compatibility/
*
* Parse a date generated with strftime().
*
* @author Lionel SAURON and reworked by e107 Inc. for month names.
* @version 1.0
* @public
*
* @param string $str date string to parse (e.g. returned from strftime()).
* @param string $sFormat strftime format used to create the date
* @return array Returns an array with the <code>$str</code> parsed, or <code>false</code> on error.
*/
public function strptime($str, $format)
{
static $expand = array('%D'=>'%m/%d/%y', '%T'=>'%H:%M:%S', );
$ampm = (preg_match("/%l|%I|%p|%P/",$format)) ? 'true' : 'false';
static $map_r = array(
'%S' =>'tm_sec',
'%M' =>'tm_min',
'%H' =>'tm_hour',
'%I' =>'tm_hour',
'%d' =>'tm_mday',
'%m' =>'tm_mon',
'%Y' =>'tm_year',
'%y' =>'tm_year',
'%W' =>'tm_wday',
'%D' =>'tm_yday',
'%B' =>'tm_fmon', // full month-name
'%b' =>'tm_amon', // abrev. month-name
'%p' =>'tm_AMPM', // AM/PM
'%P' =>'tm_ampm', // am/pm
'%u' =>'unparsed',
);
$fullmonth = array();
$abrevmonth = array();
for ($i = 1; $i <= 12; $i++)
{
$k = strftime('%B',mktime(0,0,0,$i));
$fullmonth[$k] = $i;
$j = strftime('%b',mktime(0,0,0,$i));
$abrevmonth[$j] = $i;
}
#-- transform $format into extraction regex
$format = str_replace(array_keys($expand), array_values($expand), $format);
$preg = preg_replace('/(%\w)/', '(\w+)', preg_quote($format));
#-- record the positions of all STRFCMD-placeholders
preg_match_all('/(%\w)/', $format, $positions);
$positions = $positions[1];
#-- get individual values
if (preg_match("#$preg#", $str, $extracted))
{
#-- get values
foreach ($positions as $pos => $strfc)
{
$v = $extracted[$pos + 1];
#-- add
if (isset($map_r[$strfc]))
{
$n = $map_r[$strfc];
$vals[$n] = ($v > 0) ? (int) $v : $v;
}
else
{
$vals['unparsed'] .= $v.' ';
}
}
#-- fixup some entries
//$vals["tm_wday"] = $names[ substr($vals["tm_wday"], 0, 3) ];
if ($vals['tm_year'] >= 1900)
{
$vals['tm_year'] -= 1900;
}
elseif ($vals['tm_year'] > 0)
{
$vals['tm_year'] += 100;
}
if ($vals['tm_mon'])
{
$vals['tm_mon'] -= 1;
}
else
{
if(isset($fullmonth[$vals['tm_fmon']]))
{
$vals['tm_mon'] = $fullmonth[$vals['tm_fmon']];
}
elseif(isset($abrevmonth[$vals['tm_amon']]))
{
$vals['tm_mon'] = $abrevmonth[$vals['tm_amon']];
}
}
if($ampm && ($vals['tm_AMPM'] == 'PM' || $vals['tm_ampm'] == 'pm'))
{
$vals['tm_hour'] = $vals['tm_hour'] + 12;
}
//$vals['tm_sec'] -= 1; always increasing tm_sec + 1 ??????
#-- calculate wday/yday
$unxTimestamp = mktime($vals['tm_hour'], $vals['tm_min'], $vals['tm_sec'], ($vals['tm_mon'] + 1), $vals['tm_mday'], ($vals['tm_year'] + 1900));
$vals['tm_wday'] = (int) strftime('%w', $unxTimestamp); // Days since Sunday (0-6)
$vals['tm_yday'] = (strftime('%j', $unxTimestamp) - 1); // Days since January 1 (0-365)
//var_dump($vals, $str, strftime($format, $unxTimestamp), $unxTimestamp);
}
return isset($vals) ? $vals : false;
}
function supported($mode = FALSE)
{
$strftimeFormats = array(
'A' => 'A full textual representation of the day',
'B' => 'Full month name, based on the locale',
'C' => 'Two digit representation of the century (year divided by 100, truncated to an integer)',
'D' => 'Same as "%m/%d/%y"',
'E' => '',
'F' => 'Same as "%Y-%m-%d"',
'G' => 'The full four-digit version of %g',
'H' => 'Two digit representation of the hour in 24-hour format',
'I' => 'Two digit representation of the hour in 12-hour format',
'J' => '',
'K' => '',
'L' => '',
'M' => 'Two digit representation of the minute',
'N' => '',
'O' => '',
'P' => 'lower-case "am" or "pm" based on the given time',
'Q' => '',
'R' => 'Same as "%H:%M"',
'S' => 'Two digit representation of the second',
'T' => 'Same as "%H:%M:%S"',
'U' => 'Week number of the given year, starting with the first Sunday as the first week',
'V' => 'ISO-8601:1988 week number of the given year, starting with the first week of the year with at least 4 weekdays, with Monday being the start of the week',
'W' => 'A numeric representation of the week of the year, starting with the first Monday as the first week',
'X' => 'Preferred time representation based on locale, without the date',
'Y' => 'Four digit representation for the year',
'Z' => 'The time zone offset/abbreviation option NOT given by %z (depends on operating system)',
'a' => 'An abbreviated textual representation of the day',
'b' => 'Abbreviated month name, based on the locale',
'c' => 'Preferred date and time stamp based on local',
'd' => 'Two-digit day of the month (with leading zeros)',
'e' => 'Day of the month, with a space preceding single digits',
'f' => '',
'g' => 'Two digit representation of the year going by ISO-8601:1988 standards (see %V)',
'h' => 'Abbreviated month name, based on the locale (an alias of %b)',
'i' => '',
'j' => 'Day of the year, 3 digits with leading zeros',
'k' => '',
'l' => 'Hour in 12-hour format, with a space preceeding single digits',
'm' => 'Two digit representation of the month',
'n' => 'A newline character ("\n")',
'o' => '',
'p' => 'UPPER-CASE "AM" or "PM" based on the given time',
'q' => '',
'r' => 'Same as "%I:%M:%S %p"',
's' => 'Unix Epoch Time timestamp',
't' => 'A Tab character ("\t")',
'u' => 'ISO-8601 numeric representation of the day of the week',
'v' => '',
'w' => 'Numeric representation of the day of the week',
'x' => 'Preferred date representation based on locale, without the time',
'y' => 'Two digit representation of the year',
'z' => 'Either the time zone offset from UTC or the abbreviation (depends on operating system)',
'%' => 'A literal percentage character ("%")',
);
// Results.
$strftimeValues = array();
// Evaluate the formats whilst suppressing any errors.
foreach($strftimeFormats as $format => $description)
{
if (False !== ($value = @strftime("%{$format}")))
{
$strftimeValues[$format] = $value;
}
}
// Find the longest value.
$maxValueLength = 2 + max(array_map('strlen', $strftimeValues));
$ret = array(
'enabled' => array(),
'disabled' => array()
);
// Report known formats.
foreach($strftimeValues as $format => $value)
{
$ret['enabled'][] = $format;
echo ($mode =='list') ? "Known format : '{$format}' = ". str_pad("'{$value}'", $maxValueLength). " ( {$strftimeFormats[$format]} )<br />" : "";
}
// Report unknown formats.
foreach(array_diff_key($strftimeFormats, $strftimeValues) as $format => $description)
{
$ret['disabled'][] = $format;
echo ($mode =='list') ? "Unknown format : '{$format}' ". str_pad(' ', $maxValueLength). ($description ? " ( {$description} )" : ''). "<br />" : "";
}
return in_array($mode,$ret['enabled']);
}
} }
?> ?>

View File

@@ -1146,6 +1146,16 @@ class e107
return self::getSingleton('convert', true); return self::getSingleton('convert', true);
} }
/**
* Retrieve date handler singleton object - preferred method.
*
* @return convert
*/
public static function getDate()
{
return self::getSingleton('convert', true);
}
/** /**
* Retrieve notify handler singleton object * Retrieve notify handler singleton object
* *

View File

@@ -312,24 +312,153 @@ class e_form
/** /**
* Date field with popup calendar // NEW in 0.8/2.0 * Date field with popup calendar // NEW in 0.8/2.0
* $options allowed keys:
* - time: show time, default is true
* - others: ???, default is false
* - weeks: show weeks, default is false
* - size: input field size attribute, default 25
* *
* @param string $name the name of the field * @param string $name the name of the field
* @param integer $datestamp UNIX timestamp - default value of the field * @param integer $datestamp UNIX timestamp - default value of the field
* @param array $options calendar options * @param array or str
* @example $frm->datepicker('my_field',time(),'type=date');
* @example $frm->datepicker('my_field',time(),'type=datetime&inline=1');
*
* @url http://trentrichardson.com/examples/timepicker/
*/ */
function datepicker($name, $datestamp = false, $options = array()) function datepicker($name, $datestamp = false, $options = null)
{ {
if(vartrue($options) && !is_array($options))
{
parse_str($options,$options);
}
$dateFormat = ($options['dateformat']) ? trim($options['dateformat']) :e107::getPref('inputdate', '%Y-%m-%d');
$timeFormat = ($options['timeformat']) ? trim($options['timeformat']) :e107::getPref('inputtime', '%H:%M:%S');
$type = ($options['type']) ? trim($options['type']) : "date";
$ampm = (preg_match("/%l|%I|%p|%P/",$timeFormat)) ? 'true' : 'false';
$convert = array(
'%d' => 'dd',
'%m' => 'mm',
'%y' => 'y',
'%Y' => 'yy',
'%a' => 'D', // An abbreviated textual representation of the day
'%A' => 'DD', // A full textual representation of the day
'%B' => 'MM', // Full month name, based on the locale
'%b' => 'M', // Abbreviated month name, based on the locale
'%h' => 'M', // Abbreviated month name, based on the locale (an alias of %b)
'%l' => 'h', // 12 hour format - no leading zero
'%I' => 'hh', // 12 hour format - leading zero
'%H' => 'hh', // 24 hour format - leading zero
'%M' => 'mm',
'%S' => 'ss',
'%p' => 'TT', // %p UPPER-CASE 'AM' or 'PM' based on the given time
'%P' => 'tt', // %P lower-case 'am' or 'pm' based on the given time
'%T' => 'hh:mm:ss',
'%r' => "hh:mmm:ss TT" // 12 hour format
);
$s = array_keys($convert);
$r = array_values($convert);
$dformat = str_replace($s,$r,$dateFormat);
$tformat = str_replace($s,$r,$timeFormat);
$id = $this->name2id($name);
$classes = array(
'date' => 'e-date',
// 'time' => 'e-time',
'datetime' => 'e-datetime'
);
$def = array(
'date' => $dateFormat,
// 'time' => $timeFormat,
'datetime' => $dateFormat." ".$timeFormat
);
$defdisp = (isset($def[$type])) ? $def[$type] : $def['date'];
if ($datestamp)
{
$value = is_numeric($datestamp) ? e107::getDate()->convert_date($datestamp, $defdisp) : $datestamp; //date("d/m/Y H:i:s", $datestamp);
}
$text = "";
$class = (isset($classes[$type])) ? $classes[$type] : "e-date";
if(vartrue($options['inline']))
{
return "<span class='{$class}' id='inline-{$id}' data-date-format='{$dformat}' data-time-format='{$tformat}' data-date-ampm='{$ampm}' ></span>
<input type='text' size='40' name='{$name}' id='{$id}' value='{$value}' data-date-format='{$dformat}' data-time-format='{$tformat}' data-date-ampm='{$ampm}' />
";
}
else
{
return "<input class='{$class}' type='date' size='40' name='{$name}' id='{$id}' value='{$value}' data-date-format='{$dformat}' data-time-format='{$tformat}' data-date-ampm='{$ampm}' />";
}
// Keep this info here:
/*
* $options allowed keys:
*
* d - day of month (no leading zero)
dd - day of month (two digit)
o - day of the year (no leading zeros)
oo - day of the year (three digit)
D - day name short
DD - day name long
m - month of year (no leading zero)
mm - month of year (two digit)
M - month name short
MM - month name long
y - year (two digit)
yy - year (four digit)
@ - Unix timestamp (ms since 01/01/1970)
! - Windows ticks (100ns since 01/01/0001)
'...' - literal text
'' - single quote
anything else - literal text
ATOM - 'yy-mm-dd' (Same as RFC 3339/ISO 8601)
COOKIE - 'D, dd M yy'
ISO_8601 - 'yy-mm-dd'
RFC_822 - 'D, d M y' (See RFC 822)
RFC_850 - 'DD, dd-M-y' (See RFC 850)
RFC_1036 - 'D, d M y' (See RFC 1036)
RFC_1123 - 'D, d M yy' (See RFC 1123)
RFC_2822 - 'D, d M yy' (See RFC 2822)
RSS - 'D, d M y' (Same as RFC 822)
TICKS - '!'
TIMESTAMP - '@'
W3C - 'yy-mm-dd' (Same as ISO 8601)
*
* h Hour with no leading 0
* hh Hour with leading 0
* m Minute with no leading 0
* mm Minute with leading 0
* s Second with no leading 0
* ss Second with leading 0
* l Milliseconds always with leading 0
* t a or p for AM/PM
* T A or P for AM/PM
* tt am or pm for AM/PM
* TT AM or PM for AM/PM
*/
// DHTML Calendar is deprecated in 2.0. // DHTML Calendar is deprecated in 2.0.
/*
$cal = new DHTML_Calendar(true); $cal = new DHTML_Calendar(true);
$cal_options['showsTime'] = varset($options['time'], true); $cal_options['showsTime'] = varset($options['time'], true);
$cal_options['showOthers'] = varset($options['others'], false); $cal_options['showOthers'] = varset($options['others'], false);
@@ -346,6 +475,8 @@ class e_form
} }
return $cal->make_input_field($cal_options, $cal_attrib); return $cal->make_input_field($cal_options, $cal_attrib);
*/
} }
/** /**
@@ -1548,7 +1679,7 @@ class e_form
break; break;
case 'datestamp': case 'datestamp':
$value = $value ? e107::getDateConvert()->convert_date($value, vartrue($parms['mask'], 'short')) : ''; $value = $value ? e107::getDate()->convert_date($value, vartrue($parms['mask'], 'short')) : '';
break; break;
case 'userclass': case 'userclass':
@@ -1774,6 +1905,7 @@ class e_form
return $this->iconpicker($key, $value, defset($label, $label), $parms, $ajax); return $this->iconpicker($key, $value, defset($label, $label), $parms, $ajax);
break; break;
case 'datestamp': case 'datestamp':
// If hidden, value is updated regardless. eg. a 'last updated' field. // If hidden, value is updated regardless. eg. a 'last updated' field.
// If not hidden, and there is a value, it is retained. eg. during the update of an existing record. // If not hidden, and there is a value, it is retained. eg. during the update of an existing record.
@@ -1787,7 +1919,7 @@ class e_form
{ {
return $this->hidden($key, $value); return $this->hidden($key, $value);
} }
print_a($parms);
return $this->datepicker($key, $value, $parms); return $this->datepicker($key, $value, $parms);
break; break;

View File

@@ -164,103 +164,13 @@ if (!function_exists('simplexml_load_string'))
*/ */
/*
* This work of Lionel SAURON (http://sauron.lionel.free.fr:80) is licensed under the
* Creative Commons Attribution-Noncommercial-Share Alike 2.0 France License.
*
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.0/fr/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*/
/**
* http://snipplr.com/view/4964/emulate-php-5-for-backwards-compatibility/
*
* Parse a date generated with strftime().
* PHP Compatibility *nix v5.1.0+, all $M
*
* This function is the same as the original one defined by PHP (Linux/Unix only),
* but now you can use it on Windows too.
* Limitation : Only this format can be parsed %S, %M, %H, %d, %m, %Y
*
* @author Lionel SAURON
* @version 1.0
* @public
*
* @param string $str date string to parse (e.g. returned from strftime()).
* @param string $sFormat strftime format used to create the date
* @return array Returns an array with the <code>$str</code> parsed, or <code>false</code> on error.
*/
// strptime - PHP 5 >= 5.1.0
if (!function_exists('strptime')) if (!function_exists('strptime'))
{ {
define('STRPTIME_COMPAT', true); define('STRPTIME_COMPAT', true);
function strptime($str, $format) function strptime($str, $format)
{ {
static $expand = array('%D'=>'%m/%d/%y', '%T'=>'%H:%M:%S', ); return e107::getDate()->strptime($str,$format);
static $map_r = array('%S'=>'tm_sec', '%M'=>'tm_min', '%H'=>'tm_hour', '%d'=>'tm_mday', '%m'=>'tm_mon', '%Y'=>'tm_year', '%y'=>'tm_year', /*'%W'=>'tm_wday', '%D'=>'tm_yday',*/ '%u'=>'unparsed', );
#-- TODO - not so useful, locale is breaking it, so use date() and mktime() to generate the array below
static $names = array('Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12, 'Sun'=>0, 'Mon'=>1, 'Tue'=>2, 'Wed'=>3, 'Thu'=>4, 'Fri'=>5, 'Sat'=>6 );
#-- transform $format into extraction regex
$format = str_replace(array_keys($expand), array_values($expand), $format);
$preg = preg_replace('/(%\w)/', '(\w+)', preg_quote($format));
#-- record the positions of all STRFCMD-placeholders
preg_match_all('/(%\w)/', $format, $positions);
$positions = $positions[1];
#-- get individual values
if (preg_match("#$preg#", $str, $extracted))
{
#-- get values
foreach ($positions as $pos => $strfc)
{
$v = $extracted[$pos + 1];
#-- add
if (isset($map_r[$strfc]))
{
$n = $map_r[$strfc];
$vals[$n] = ($v > 0) ? (int) $v : $v;
}
else
{
$vals['unparsed'] .= $v.' ';
}
}
#-- fixup some entries
//$vals["tm_wday"] = $names[ substr($vals["tm_wday"], 0, 3) ];
if ($vals['tm_year'] >= 1900)
{
$vals['tm_year'] -= 1900;
}
elseif ($vals['tm_year'] > 0)
{
$vals['tm_year'] += 100;
}
if ($vals['tm_mon'])
{
$vals['tm_mon'] -= 1;
}
else
{
$vals['tm_mon'] = $names[substr($vals['tm_mon'], 0, 3)] - 1;
}
//$vals['tm_sec'] -= 1; always increasing tm_sec + 1 ??????
#-- calculate wday/yday
$unxTimestamp = mktime($vals['tm_hour'], $vals['tm_min'], $vals['tm_sec'], ($vals['tm_mon'] + 1), $vals['tm_mday'], ($vals['tm_year'] + 1900));
$vals['tm_wday'] = (int) strftime('%w', $unxTimestamp); // Days since Sunday (0-6)
$vals['tm_yday'] = (strftime('%j', $unxTimestamp) - 1); // Days since January 1 (0-365)
//var_dump($vals, $str, strftime($format, $unxTimestamp), $unxTimestamp);
}
return isset($vals) ? $vals : false;
} }
} }

View File

@@ -256,7 +256,7 @@ class plugin_release_admin_ui extends e_admin_ui
'release_version' => array('title'=> 'Version', 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => ''), 'release_version' => array('title'=> 'Version', 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => ''),
'release_author' => array('title'=> LAN_AUTHOR, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), 'release_author' => array('title'=> LAN_AUTHOR, 'type' => 'text', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'),
'release_authorURL' => array('title'=> LAN_AUTHOR_URL, 'type' => 'url', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'), 'release_authorURL' => array('title'=> LAN_AUTHOR_URL, 'type' => 'url', 'data' => 'str', 'width' => 'auto', 'thclass' => 'left'),
'release_date' => array('title'=> LAN_DATE, 'type' => 'datestamp', 'data' => 'int', 'width' => 'auto', 'thclass' => '', 'readParms' => 'long', 'writeParms' => ''), 'release_date' => array('title'=> LAN_DATE, 'type' => 'datestamp', 'data' => 'int', 'width' => 'auto', 'thclass' => '', 'readParms' => 'long', 'writeParms' => 'type=datetime'),
'release_compatibility' => array('title'=> 'compatib', 'type' => 'text', 'data' => 'str', 'width' => '10%', 'thclass' => 'center' ), 'release_compatibility' => array('title'=> 'compatib', 'type' => 'text', 'data' => 'str', 'width' => '10%', 'thclass' => 'center' ),
'release_url' => array('title'=> 'release_url', 'type' => 'url', 'data' => 'str', 'width' => '20%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'parms' => 'truncate=30', 'validate' => true, 'help' => 'Enter release URL here', 'error' => 'please, ener valid URL'), 'release_url' => array('title'=> 'release_url', 'type' => 'url', 'data' => 'str', 'width' => '20%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'parms' => 'truncate=30', 'validate' => true, 'help' => 'Enter release URL here', 'error' => 'please, ener valid URL'),
'test_list_1' => array('title'=> 'test 1', 'type' => 'boolean', 'data' => 'int', 'width' => '5%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'noedit' => true), 'test_list_1' => array('title'=> 'test 1', 'type' => 'boolean', 'data' => 'int', 'width' => '5%', 'thclass' => 'center', 'batch' => TRUE, 'filter'=>TRUE, 'noedit' => true),

View File

@@ -10,7 +10,8 @@ include_lan(e_THEME."_blank/languages/".e_LANGUAGE.".php");
e107::js('core', 'colorbox/jquery.colorbox-min.js', 'jquery', 2); e107::js('core', 'colorbox/jquery.colorbox-min.js', 'jquery', 2);
e107::css('core', 'colorbox/colorbox.css', 'jquery'); e107::css('core', 'colorbox/colorbox.css', 'jquery');
e107::js('core', 'core/jquery.elastic.source.js', 'jquery', 2); e107::js('core', 'jquery.elastic.js', 'jquery', 2);
e107::js('core', 'jquery-ui-timepicker-addon.js', 'jquery', 2);
e107::js('core', 'plupload/plupload.full.js', 'jquery', 2); e107::js('core', 'plupload/plupload.full.js', 'jquery', 2);
e107::css('core', 'plupload/jquery.plupload.queue/css/jquery.plupload.queue.css', 'jquery'); e107::css('core', 'plupload/jquery.plupload.queue/css/jquery.plupload.queue.css', 'jquery');

View File

@@ -106,7 +106,8 @@ e107::css('inline',"/******** Tabs JS */
e107::js('core', 'colorbox/jquery.colorbox-min.js', 'jquery', 2); e107::js('core', 'colorbox/jquery.colorbox-min.js', 'jquery', 2);
e107::css('core', 'colorbox/colorbox.css', 'jquery'); e107::css('core', 'colorbox/colorbox.css', 'jquery');
e107::js('core', 'core/jquery.elastic.source.js', 'jquery', 2); e107::js('core', 'jquery.elastic.js', 'jquery', 2);
e107::js('core', 'jquery-ui-timepicker-addon.js', 'jquery', 2);
e107::js('core', 'plupload/plupload.full.js', 'jquery', 2); e107::js('core', 'plupload/plupload.full.js', 'jquery', 2);
e107::css('core', 'plupload/jquery.plupload.queue/css/jquery.plupload.queue.css', 'jquery'); e107::css('core', 'plupload/jquery.plupload.queue/css/jquery.plupload.queue.css', 'jquery');