sql_query($sql)){
message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
}
if ( $db->sql_numrows($result) ){
$cat_info = $db->sql_fetchrow($result);
$cat_title = ' / '. $cat_info['cat_title'];
}
}
else if ( !empty($filter['keyword']) ){
$cat_title = ' / Search Results';
}
//---------------------------------
$template->assign_vars(array(
'S_SEARCH_ACTION' => $base_url,
'SCATID_VALUE' => $filter['cat_id'],
'SKEYWORD_VALUE' => stripslashes($filter['keyword']),
'CAT_TITLE' => $cat_title,
));
}
//List all articles
function list_articles(){
global $template, $db, $base_url, $site_option, $template_body_page, $start, $filter, $image_path;
$start = isset($_GET['start']) ? intval($_GET['start']) : 0;
$cid = isset($_GET['cid']) ? intval($_GET['cid']) : 0;
$date_format = $site_option['date_time_format'];
$timezone = $site_option['timezone']*3600;
$itemperpage = 6;
$cat_title = "";
// Filter -----------------------------------------------
$where_sql = 'WHERE enabled=1';
if ( $filter['cat_id'] ){
$where_sql .= ' AND cat_id='. $filter['cat_id'];
}
if ( !empty($filter['keyword']) ){
$keyword = str_replace('*', '%', $filter['keyword']);
$where_sql .= " AND (title LIKE '%". $keyword ."%' OR preview LIKE '%". $keyword ."%' OR content LIKE '%". $keyword ."%' OR author LIKE '%". $keyword ."%')";
}
// ------------------------------------------------------
//Get articles
$sql = 'SELECT * FROM article '. $where_sql .' ORDER BY posted_date DESC LIMIT '.$start.','.$itemperpage;
if ( !$result = $db->sql_query($sql) ){
message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
}
$article_count = $db->sql_numrows($result);
$article_data = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
//Generate Pagination
$sql = 'SELECT count(article_id) AS total FROM article '. $where_sql;
if (!$result = $db->sql_query($sql)) {
message_die("Couldn't run the sql query!!!", __LINE__, __FILE__, $sql);
}
$total = $db->sql_fetchrow($result);
$the_url = $cid ? "cid=$cid" : $filter['url_append'];
$pagination = g3_pagination($base_url . "?". $the_url, $total['total'], $itemperpage, $start, 'start', 'Page: ////')." ";
for ($i=0; $i<$article_count; $i++){
$template->assign_block_vars("articlerow", array(
'TITLE' => $article_data[$i]['title'],
'PREVIEW' => restore_htmltags(nl2br($article_data[$i]['preview'])),
'PIC_THUMB' => !empty($article_data[$i]['pic_thumb']) ? '' : '',
'POSTED_DATE' => gmdate($date_format, $article_data[$i]['posted_date']),
'U_VIEW' => $base_url . '?' . $filter['url_append'] .'id='.$article_data[$i]['article_id'],
));
}
$template->assign_vars(array(
'PAGINATION' => $pagination,
));
$template->set_filenames(array('body' => $template_body_page));
$template->pparse('body');
}
//View article detail
function view_article() {
global $db, $template, $base_url, $template_view_page, $id, $site_option, $image_path;
$date_format = $site_option['date_time_format'];
$timezone = $site_option['timezone']*3600;
//Get content of article
$sql = 'SELECT * FROM article WHERE enabled=1 AND article_id='.$id;
if (!$result = $db->sql_query($sql)){
message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
}
if ( !$db->sql_numrows($result) ){
list_articles();
}
$article_info = $db->sql_fetchrow($result);
$template->assign_vars(array(
'TITLE' => $article_info['title'],
'PIC_THUMB' => !empty($article_info['pic_thumb']) ? '' : '',
'CONTENT' => restore_htmltags(nl2br($article_info['content'])),
'AUTHOR' => $article_info['author'],
'POSTED_DATE' => gmdate($date_format, $article_info['posted_date'] + $timezone),
));
//Update hits
$sql = 'UPDATE article SET hits=hits+1 WHERE article_id='.$id;
if ( !$result = $db->sql_query($sql) ){
message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
}
//Get next articles
get_next_articles($article_info['posted_date']);
$template->set_filenames(array('body' => $template_view_page));
$template->pparse('body');
}
//Get other articles
function get_next_articles($posted_date){
global $db, $template, $base_url, $filter, $site_option;
$date_format = $site_option['date_format'];
$timezone = $site_option['timezone']*3600;
// Filter -----------------------------------------------
$where_sql = 'WHERE enabled=1 AND posted_date<'. $posted_date;
if ( $filter['cat_id'] ){
$where_sql .= ' AND cat_id='. $filter['cat_id'];
}
if ( !empty($filter['keyword']) ){
$keyword = str_replace('*', '%', $filter['keyword']);
$where_sql .= " AND (title LIKE '%". $keyword ."%' OR preview LIKE '%". $keyword ."%' OR content LIKE '%". $keyword ."%' OR author LIKE '%". $keyword ."%')";
}
// ------------------------------------------------------
//Get news
$sql = 'SELECT article_id, title, posted_date FROM article '. $where_sql .' ORDER BY posted_date DESC LIMIT 0,10';
if ( !$result = $db->sql_query($sql) ){
message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
}
$article_count = $db->sql_numrows($result);
$article_data = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
if ( $article_count ){
$template->assign_block_vars("nextarticle", array());
for ($i=0; $i<$article_count; $i++){
$template->assign_block_vars("nextarticle.articlerow", array(
'TITLE' => $article_data[$i]['title'],
'POSTED_DATE' => gmdate($date_format, $article_data[$i]['posted_date'] + $timezone),
'U_VIEW' => $base_url . '?' . $filter['url_append'] .'id='. $article_data[$i]['article_id'],
));
}
}
}
?>