A quick hack can allow authors of items to preview the item-pages for their draft items. This can be handy to spot HTML/layout errors before actually publishing.
The basic idea is to replace all idraft=0 strings in SQL queries by (idraft=0 or iauthor=id) when the member is logged in.
ITEM.php
Find:
function getitem($itemid, $allowdraft, $allowfuture) {
global $manager;
Replace by:
function getitem($itemid, $allowdraft, $allowfuture) {
global $manager, $member;
In the getitem function, find:
if (!$allowdraft)
$query .= ' and i.idraft=0';
Replace by:
if (!$allowdraft)
{
if (!$member->isLoggedIn())
{
$query .= ' and i.idraft=0';
} else {
// always allow draft items for their authors
$query .= ' and (i.idraft=0 or i.iauthor=' . intval($member->getID()) . ')';
}
}
Find:
function exists($id,$future,$draft) {
global $manager;
Replace by:
function exists($id,$future,$draft) {
global $manager, $member;
In the exists function, find:
if (!$draft)
$r .= ' and idraft=0';
Replace by:
if (!$draft)
{
if (!$member->isLoggedIn())
{
$r .= ' and idraft=0';
} else {
// always allow draft items for their authors
$r .= ' and (idraft=0 or iauthor=' . intval($member->getID()) . ')';
}
}
BLOG.php
Find:
function getSqlBlog($extraQuery, $mode = '')
{
Replace by
function getSqlBlog($extraQuery, $mode = '')
{
global $member;
In the getSqlBlog function, find:
$query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
. ' WHERE i.iblog='.$this->blogid
. ' and i.iauthor=m.mnumber'
. ' and i.icat=c.catid'
. ' and i.idraft=0' // exclude drafts
// don't show future items
. ' and i.itime<=' . mysqldate($this->getCorrectTime());
Replace by:
$query .= ' FROM '.sql_table('item').' as i, '.sql_table('member').' as m, '.sql_table('category').' as c'
. ' WHERE i.iblog='.$this->blogid
. ' and i.iauthor=m.mnumber'
. ' and i.icat=c.catid'
// don't show future items
. ' and i.itime<=' . mysqldate($this->getCorrectTime());
if (!$member->isLoggedIn())
{
$query .= ' and i.idraft=0'; // exclude drafts
} else {
$query .= ' and (i.idraft=0 or i.iauthor=' . intval($member->getID()). ')';
}
Notes
- As author of a draft item, you can now surf to it using
?itemid=draftid. Non-logged in members won't be able to do this. - The draft item will show up with a date of
1970-01-01(it's stored like this in the database to push it to the bottom of the "edit/delete items" list on the admin area)
Posted by karma at 17:50:10. Filed under: Nucleus Hacks

Comments
Add Comment