I am trying to incorporate a date selection widget (like the one in the manager) but I am not sure I get how to turn the date from xx/xx/xx to a time stamp? Does the cal widget (js) do this or is this done with server side (php) code?
The Date type will present a text field and two Javascript date pickers, one to select a date and one to remove the date. The calendar widget from manager/media/calendar is used. The date is presented in the format day-month-year hour:minutes:seconds; for example 27-09-2008 23:04:47.
http://www.sottwell.com/tv-input-types.html
Viewing the NewsEditor snippet:
$pub_dateformat = $row['pub_date'];
if (empty($pub_dateformat)) {
$modx->setPlaceHolder('pub_date', '');
} else {
$modx->setPlaceHolder('pub_date', strftime($dateformat, $pub_dateformat));
}
$unpub_dateformat = $row['unpub_date'];
if(empty($unpub_dateformat)) {
$modx->setPlaceHolder('unpub_date', '');
} else {
$modx->setPlaceHolder('unpub_date', strftime($dateformat, $unpub_dateformat));
}
Published Date:<br /><input name="pub_date" type="text" class="form" value="[+pub_date+]" size="35" readonly="readonly" />
<a onClick="nwpub_cal1.popup();" onMouseover="window.status=\'Select date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img align="absmiddle" src="manager/media/style/MODxLight/images/icons/cal.gif" width="16" height="16" border="0" alt="Select date" /></a>
<a onClick="document.NewsEditor.pub_date.value=\'\'; return true;" onMouseover="window.status=\'Remove date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img align="absmiddle" src="manager/media/style/MODxLight/images/icons/cal_nodate.gif" width="16" height="16" border="0" alt="Remove date"></a><br />
Unpublished Date:<br /><input name="unpub_date" type="text" class="form" value="[+unpub_date+]" size="35" readonly="readonly" />
<a onClick="nwpub_cal2.popup();" onMouseover="window.status=\'Select date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img align="absmiddle" src="manager/media/style/MODxLight/images/icons/cal.gif" width="16" height="16" border="0" alt="Select date" /></a>
<a onClick="document.NewsEditor.unpub_date.value=\'\'; return true;" onMouseover="window.status=\'Remove date\'; return true;" onMouseout="window.status=\'\'; return true;" style="cursor:pointer; cursor:hand"><img align="absmiddle" src="manager/media/style/MODxLight/images/icons/cal_nodate.gif" width="16" height="16" border="0" alt="Remove date"></a><br />
Summary:<br /><textarea name="introtext" cols="45" class="form" rows="5">[+introtext+]</textarea><br />
<!-- Content:<br /><textarea name="content" cols="45" class="form" rows="8">[+content+]</textarea><br /> //-->
Content:<br />[*blogContent*]<br />
<input name="send" type="submit" value="Submit" />
</form>
<script language="JavaScript" src="manager/media/script/datefunctions.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
var elm_txt = {}; // dummy
var pub = document.forms["NewsEditor"].elements["pub_date"];
var nwpub_cal1 = new calendar1(pub,elm_txt);
nwpub_cal1.path="[(base_url)]manager/media/";
nwpub_cal1.year_scroll = true;
nwpub_cal1.time_comp = true;
var unpub = document.forms["NewsEditor"].elements["unpub_date"];
var nwpub_cal2 = new calendar1(unpub,elm_txt);
nwpub_cal2.path="[(base_url)]manager/media/";
nwpub_cal2.year_scroll = true;
nwpub_cal2.time_comp = true;
/* ]]> */
</script>';
}
This code was written to format the date the same way whether it was taken from the standard createdon field or from a special variable I created.
<?php
/*
Created by Brandon Booth: [email protected]
Last updated: December 14, 2008
Parameters:
&dateField: select standard document date field or custom tv date field by name. Defaults to createdon date.
&dateFormat: set format for date in with standard PHP date formatting. Defaults to %A, %D.
*/
//Begin code, the rest should take care of itself.
$dateField = isset($dateField) ? $dateField : 'createdon';
$dateFormat = isset($dateFormat) ? $dateFormat : '%A, %D';
if ($date = $modx->documentObject[$dateField] ) {
if(is_array($date)){
$dateOutput = $date[1];
if(empty($dateOutput)) return ''; //bail out if no value
$dateOutput = mktime($dateOutput);
return strftime($dateFormat, $dateOutput);
} else {
return strftime($dateFormat, $date);
}
}
return '';
?>
http://spreadsheets.google.com/pub?key=pHJSI5ye5FxqRfh1nEPCnJA&gid=0