Summary:
CGBlog articleid=-1 does not work
Detailed Description:
On my website I want to show the latest add CGBlog article via:
{CGBlog action='detail'}
{CGBlog action='detail' articleid="-1"}
This does not work.
By digging into your code base I found a typo inside
/modules/CGBlog/lib/class.cgblog_article.php -> public static function
&get_latest
$query = 'SELECT mn.* FROM '.cms_db_prefix().'mdoule_cgblog mn WHERE';
should read
$query = 'SELECT mn.* FROM '.cms_db_prefix().'module_cgblog mn WHERE'
Besides $canviewdraft can either be TRUE|FALSE so the query should be executed
with or without placeholders.
if (!$canviewdraft) {
$row = $db->GetRow($query, $qparms);
} else {
$row = $db->GetRow($query);
}
Your version:
public static function &get_latest($canviewdraft = FALSE,$get_fields =
'PUBLIC',$get_categories = TRUE)
{
$db = cmsms()->GetDb();
$now = $db->DbTimeStamp(time());
$query = 'SELECT mn.* FROM '.cms_db_prefix().'mdoule_cgblog mn WHERE';
$qparms = array();
if( !$canviewdraft )
{
$query .= ' status = ? AND ';
$qparms[] = 'published';
}
$query .= " (".$db->IfNull('start_time',$db->DBTimeStamp(1))." < $now) AND
";
$query .= "((".$db->IfNull('end_time',$db->DBTimeStamp(1))." =
".$db->DBTimeStamp(1).") OR (end_time > $now)) ";
$query .= 'ORDER BY end_time,start_time DESC LIMIT 1';
$row = $db->GetRow($query);
$res = null;
if( !is_array($row) ) {
// todo: throw an exception?
return $res;
}
return self::get_from_row($row);
}
My version:
public static function &get_latest($canviewdraft = FALSE,$get_fields =
'PUBLIC',$get_categories = TRUE)
{
$db = cmsms()->GetDb();
$now = $db->DbTimeStamp(time());
$query = 'SELECT mn.* FROM '.cms_db_prefix().'module_cgblog mn WHERE';
$qparms = array();
if( !$canviewdraft )
{
$query .= ' status = ? AND ';
$qparms[] = 'published';
}
$query .= " (".$db->IfNull('start_time',$db->DBTimeStamp(1))." < $now) AND
";
$query .= "((".$db->IfNull('end_time',$db->DBTimeStamp(1))." =
".$db->DBTimeStamp(1).") OR (end_time > $now)) ";
$query .= 'ORDER BY end_time,start_time DESC LIMIT 1';
if (!$canviewdraft) {
$row = $db->GetRow($query, $qparms);
} else {
$row = $db->GetRow($query);
}
$res = null;
if( !is_array($row) ) {
// todo: throw an exception?
return $res;
}
return self::get_from_row($row);
}