<?
// Copyright (C) Bloggie Lite Written by : Sean
// http://www.mywebland.com , http://mybloggie.mywebland.com
// You are requested to retain this copyright notice in order to use
// this software.
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
if ( !defined('IN_BLOGGIE') )
{
die("You are not allowed to access this page directly !");
}
include_once($bloggie_root_path.'includes/classes.php');
if (isset($mode)) {
switch ($mode) {
case "category":
if ( $sef_method != "xsef" ) {
$category = sanitize_url_subject($path_parts[1]);
if (count($path_parts) == 3 ) $page = htmlspecialchars($path_parts[2]); else unset($page);
if (count($path_parts) == 4 && numerical_check($path_parts[3])) $pno = intval($path_parts[3]); else unset($pno);
$sql= "SELECT ".CAT_TBL.".cat_desc FROM ".CAT_TBL." WHERE ".CAT_TBL.".cat_perma='".$category."'" ;
$result = $db->sql_query($sql);
if( !($result = $db->sql_query($sql)) )
{
$sql_error = $db->sql_error();
die($sql_error['message']);;
}
if ( $db->sql_numrows($result)== 0 )
{
$template->set_filenames(array(
'simpleheader' => 'simpleheader.tpl',
'simplefooter' => 'simplefooter.tpl',
));
$template->pparse('simpleheader'); echo "dasda";
error( $lang['Error'], $lang['Invalid'] ) ;
}
} elseif ( isset($_GET['mode'])) {
if (isset($_GET['cat_id'])) $cat_id = intval($_GET['cat_id']);
$criteria = POST_TBL.".cat_id='".$cat_id."' " ;
$sql = "SELECT ".POST_TBL.".subject, ".CAT_TBL.".cat_desc FROM ".POST_TBL." , ".CAT_TBL." WHERE ".$criteria;
$result = $db->sql_query($sql);
if ( $db->sql_numrows($result)== 0 ) {
$template->set_filenames(array(
'simpleheader' => 'simpleheader.tpl',
'simplefooter' => 'simplefooter.tpl',
));
$template->pparse('simpleheader');
error( $lang['Error'], $lang['Invalid'] ) ;
}
}
$row = $db->sql_fetchrow($result) ;
$title = $pref_data['blog_name']." » ". $lang['Category']." - ".$row['cat_desc'];
break;
case "archives":
if ( $sef_method != "xsef" ) {
$yyyy = ( numerical_check($path_parts[1]) && isset($path_parts[1])) ? intval($path_parts[1]) : "";
$mm = ( numerical_check($path_parts[2]) && isset($path_parts[2])) ? intval($path_parts[2]) : "";
if (count($path_parts) == 4 ) $page = htmlspecialchars($path_parts[3]); else unset($page);
if (count($path_parts) == 5 && numerical_check($path_parts[4])) $pno = intval($path_parts[4]); else unset($pno);
} elseif ( $sef_method == "xsef" && isset($_GET['mode'])) {
if (isset($_GET['mth'])) $mm = intval($_GET['mth']);
if (isset($_GET['yr'])) $yyyy = intval($_GET['yr']);
}
break;
case "page":
$pno = intval(htmlspecialchars($path_parts[1]));
break;
}
}
if ( !isset($pno) || empty($pno)) $pno = 0;
if ($mode == "archives")
{
$criteria = " DATE_FORMAT(FROM_UNIXTIME(".POST_TBL.".timestamp) , '%Y') = '".$yyyy."' AND
DATE_FORMAT(FROM_UNIXTIME(".POST_TBL.".timestamp) , '%c') = '".$mm."'";
} elseif ($mode == "category")
{
if ($sef_method == "xsef" ) $criteria = CAT_TBL.".cat_id='".$cat_id."'";
else $criteria = CAT_TBL.".cat_perma='".$category."'";
}
$sql = "SELECT COUNT(".POST_TBL.".post_id) AS num_posts
FROM ".POST_TBL.", ".CAT_TBL."
WHERE ".POST_TBL.".cat_id=".CAT_TBL.".cat_id AND ".$criteria;
if ( !($result = $db->sql_query($sql)) )
{ $sql_error = $db->sql_error(); echo $sql_error['message'] ; }
$numrow = ( $row = $db->sql_fetchrow($result) ) ? intval($row['num_posts']) : 0;
$row = $db->sql_fetchrow($result); $db->sql_freeresult($result);
if($mode == "category") {
$pagination = ($sef_method == "xsef" ) ? pagination( "XSEF",$site_url."/index.php"."?mode=category&cat_id=$cat_id", $numrow , $pref_data['blog_limit'], $pno):
pagination( "SEF",$site_url."/index.php/category/".$category, $numrow , $pref_data['blog_limit'], $pno);
} elseif ($mode == "archives") {
$pagination = ($sef_method == "xsef" ) ? pagination( "XSEF",$site_url."/index.php"."?mode=archives&mth=$mm&yr=$yyyy", $numrow , $pref_data['blog_limit'], $pno):
pagination( "SEF",$site_url."/index.php/archives/$yyyy/$mm", $numrow , $pref_data['blog_limit'], $pno);
}
$sql = "SELECT ".CAT_TBL.".cat_desc, ".CAT_TBL.".cat_perma, ".POST_TBL.".cat_id, ".POST_TBL.".perm_subj, ".CAT_TBL.".cat_id,
".POST_TBL.".post_id, ".POST_TBL.".subject,".POST_TBL.".message, ".USER_TBL.".user, ".POST_TBL.".timestamp, ".POST_TBL.".comments_count,
".USER_TBL.".id, ".POST_TBL.".user_id
FROM ".POST_TBL.", ".USER_TBL.", ".CAT_TBL."
WHERE ".POST_TBL.".user_id=".USER_TBL.".id AND ".CAT_TBL.".cat_id=".POST_TBL.".cat_id AND ".POST_TBL.".timestamp<='".$current_timestamp."' AND ".$criteria."
Order by ".POST_TBL.".timestamp DESC, ".POST_TBL.".post_id DESC LIMIT $pno, ".$pref_data['blog_limit'] ;
if( !($result = $db->sql_query($sql)) )
{
$sql_error = $db->sql_error();
echo $sql_error['message'];
}
$result = $db->sql_query($sql) ;
while ($row = $db->sql_fetchrow($result)) {
$message=$row['message'];
$time = date("h:i a", $row['timestamp']) ;
$dt = date("d", $row['timestamp']) ;
$shortmth = date("M", $row['timestamp']) ;
$yr = date("Y", $row['timestamp']) ;
$date = $dt." ".$lang["$shortmth"]." ".$yr;
$time_YYYYMMDD = time_YYYYMMDD($row['timestamp']);
$link = new link_modifier;
$link->assign_vars(array(
'READ' => "read",
'CAT' => "category",
'YYYY' => $time_YYYYMMDD['YYYY'],
'MM' => $time_YYYYMMDD['MM'],
'DD' => $time_YYYYMMDD['DD'],
'TITLE' => $row['perm_subj'],
'CAT_DESC' => $row['cat_perma'],
'POST_ID' => $row['post_id'],
'CAT_ID' => $row['cat_id'],
));
$modified_link = $link->parse($link_format);
$modified_cat_link = $link->parse($cat_format);
$sef_url = $site_url."/".$modified_link;
$cat_sef= $site_url."/".$modified_cat_link;
$message = nl2br($message);
$message=viewsmile($message);
$message=viewlink($message);
$message=autolink($message);
$message=viewbbcode($message);
$template->assign_block_vars('blogparse', array(
'USER_NAME' => $row['user'],
'SUBJECT' => $row['subject'],
'MESSAGE' => $message,
'TIME' => $time ,
'DATE' => $date ,
'L_COMMENTS' => $lang['Comments'],
'PERMALINK' => $sef_url ,
'L_CATEGORY' => $lang['Category'],
'U_CATEGORY' => $cat_sef,
'CATEGORY' => $row['cat_desc'],
'U_COMMENTS' => $sef_url."#comments",
'L_POSTED_BY' => $lang['By'],
'L_TIME' => $lang['Time'],
'COMMENTS_COUNT' => $row['comments_count'],
)
);
}
$template->assign_vars(array(
'PAGE' => $pagination,
));
$template->pparse('blog_body');
?>