How to set joomla finish publishing date never as default

If you are using joomla to run a website, you may have a strange problem about the “finish publishing” time/date when you try to post a new article, the joomla “finish publishing” date may be automatically set to 1970 or be automatically set to a date as same as the publishing date, sometimes even earlier than publishing date, thus as soon as you post it, it has been expired.

joomla-finish-publishing-date

I also came across this problem this morning, it seems that this problem mostly came after upgrade, now I’ve solved the problem by folling this tutorial, if you are confused by this problem, you can have a try. The tutorial was originally post here: http://forum.joomla.org/viewtopic.php?t=256452

{loadposition content_adsense2}

Lets take a look into the code administratorcomponentscom_contentcontroller.php.

Line 384 says:

Code:
if ($id)
{
$row->checkout($user->get(’id’));
if (trim($row->images)) {
$row->images = explode(”n”, $row->images);
} else {
$row->images = array ();
}

$query = ‘SELECT name’ .
‘ FROM #__users’.
‘ WHERE id = ‘. (int) $row->created_by;
$db->setQuery($query);
$row->creator = $db->loadResult();

// test to reduce unneeded query
if ($row->created_by == $row->modified_by) {
$row->modifier = $row->creator;
} else {
$query = ‘SELECT name’ .
‘ FROM #__users’ .
‘ WHERE id = ‘. (int) $row->modified_by;
$db->setQuery($query);
$row->modifier = $db->loadResult();
}

$query = ‘SELECT COUNT(content_id)’ .
‘ FROM #__content_frontpage’ .
‘ WHERE content_id = ‘. (int) $row->id;
$db->setQuery($query);
$row->frontpage = $db->loadResult();
if (!$row->frontpage) {
$row->frontpage = 0;
}
}
else
{
if (!$sectionid && JRequest::getInt(’filter_sectionid’)) {
$sectionid =JRequest::getInt(’filter_sectionid’);
}

if (JRequest::getInt(’catid’))
{
$row->catid = JRequest::getInt(’catid’);
$category = & JTable::getInstance(’category’);
$category->load($row->catid);
$sectionid = $category->section;
} else {
$row->catid = NULL;
}
jimport(’joomla.utilities.date’);
$createdate = new JDate();
$row->sectionid = $sectionid;
$row->version = 0;
$row->state = 1;
$row->ordering = 0;
$row->images = array ();
$row->publish_up = $createdate->toUnix();
$row->publish_down = JText::_(’Never’);
$row->creator = ”;
$row->created = $createdate->toUnix();
$row->modified = $nullDate;
$row->modifier = ”;
$row->frontpage = 0;

}

As you can see if the article does not exist, $row->publish_down is set to Never.

Line 559 says:

Code:
if (JHTML::_(’date’, $row->publish_down, ‘%Y’) <= 1969 || $row->publish_down == $db->getNullDate()) {
$form->set(’publish_down’, JText::_(’Never’));
} else {
$form->set(’publish_down’, JHTML::_(’date’, $row->publish_down, ‘%Y-%m-%d %H:%M:%S’));
}

The field is set to Never, if the date is below 1970 or the date is 0000-00-00 00:00:00, which means it never expires.

At this time $row->publish_down is “Never” if the article does not exist. The first line seems to work on most systems even if there are no compatible types, but maybe not everywhere.

This could be a reason for this problem. I think the following addition should fix this problem.

Code:
if (JHTML::_(’date’, $row->publish_down, ‘%Y’) <= 1969 || $row->publish_down == $nullDate /* method call not necessary */ || strcmp($row->publish_down, JText::_(’Never’)) == 0) {
$form->set(’publish_down’, JText::_(’Never’));
} else {
$form->set(’publish_down’, JHTML::_(’date’, $row->publish_down, ‘%Y-%m-%d %H:%M:%S’));
}

A better way would be to place this if statement directly at the first place.

Filed Under: Joomla Templates

Tags:

About the Author: An expert in making money online, a freelance English-Chinese translator with 8 years experiences.

RSSComments (0)

Trackback URL

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.

Please copy the string R2P9Ol to the field below:


six − = 4