<?php
/*
* Force Date from Parent
* Written By Jay Gilmore - 14 November 2008
*
* Forces Pub Date to be Now() if it is empty.
*
* Configuration:
* check the OnBeforeDocFormSave event
*
* Version 1.0
*
*/
global $content;
$e = &$modx->Event;
switch($e->name) {
case 'OnBeforeDocFormSave':
if ($content['pub_date'] =='') {
$content['pub_date'] = now();
}
break;
default:
return;
break;
}
?>
$_REQUEST['pub_date']
I’m trying to get the following plugin to work to force modx to write a pub_date when one is not selected.
Can anyone please help with this?
/*
* CorrectDates
* When a document is published or set to be published,
* always populate publishedon and pub_date variables correctly
*
* Configuration:
* check the OnDocFormSave and OnDocPublished events
*
* Version 0.1, October 2007
*
* Version 0.1.1, November 2007
* Does nothing if page is start page (which can't have publish dates)
*
*/
function normaliseDates($docid) {
global $modx;
$dates = $modx->getPageInfo($docid, 0, 'publishedon,pub_date');
$pub_date = $dates['pub_date'];
$publishedon = $dates['publishedon'];
$dbtable = $modx->getFullTableName('site_content');
if($publishedon && !$pub_date) {
// set pub_date to the same as publishedon
$modx->db->update('pub_date=' . $publishedon, $dbtable, 'id=' . $docid);
} elseif ($pub_date && !$publishedon) {
// set publishedon to now
$modx->db->update('publishedon=' . time(), $dbtable, 'id=' . $docid);
}
}
$e = &$modx->Event;
switch($e->name) {
case 'OnDocFormSave':
if ($id != $modx->config['site_start']) normaliseDates($id);
break;
case 'OnDocPublished':
if ($id != $modx->config['site_start']) normaliseDates($docid);
break;
}
What is publishedon used for, and how is it different than pub_date, or why both?
If I recall correctly ... if you just publish something, then publishedon will be set (and not pub_date). If you set something to be published in the future, then pub_date will be set but not publishedon. At least I think that’s right.Oh, I wish i knew about this (I feel stupid since it is just a matter of looking at the table). If there is a publishedon date recorded then a pub_date is not really needed for many of the things I have been using the pub_date for, like sorting by pub_date would be much more efficient if it was sorted by publishedon. OK, now I need to go back and fix some ditto calls


...
case 'OnDocPublished':
if ($id != $modx->config['site_start']) normaliseDates($docid);
break;
}