rendered paste body<?php
/*
Make the blog class
*/
class blog
{
/*
My main pagination function
*/
function pagination( $page, $number )
{
$query = mysql_query("SELECT id FROM `blog`");
$num = mysql_num_rows( $query );
if( $num < 1 )
{
return false;
}
else
{
$pages = $num / $number;
$pages = ceil($pages);
if( $pages == 1 )
{
return false;
}
elseif( $pages > 1 )
{
$pagep = $page + 1;
$pagem = $page - 1;
$responce = '<div class="page-num">';
if( $page > 1 ) $responce .= '<small><a href="http://www.henrylegge.co.uk/blog/page/'.$pagem.'/" title="Previous Page"><</a></small> ';
$responce .= $page.'<small>/'.$pages.'</small>';
if( $page < $pages ) $responce .= ' <small><a href="http://www.henrylegge.co.uk/blog/page/'.$pagep.'/" title="Next Page">></a></small>';
$responce .= '</div>';
return $responce;
}
}
}
/*
My category pagination function
*/
function category_pagination( $cat, $page, $number )
{
$query = mysql_query("SELECT id FROM `blog` WHERE `category` = '".$cat."'");
$num = mysql_num_rows( $query );
if( $num < 1 )
{
return false;
}
else
{
$pages = $num / $number;
$pages = ceil($pages);
if( $pages == 1 )
{
return false;
}
elseif( $pages > 1 )
{
$pagep = $page + 1;
$pagem = $page - 1;
$responce = '<div class="page-num">';
if( $page > 1 ) $responce .= '<small><a href="http://www.henrylegge.co.uk/blog/page/'.$pagem.'/" title="Previous Page"><</a></small> ';
$responce .= $page.'<small>/'.$pages.'</small>';
if( $page < $pages ) $responce .= ' <small><a href="http://www.henrylegge.co.uk/blog/page/'.$pagep.'/" title="Next Page">></a></small>';
$responce .= '</div>';
return $responce;
}
}
}
/*
Get the posts for the blog page
*/
function get_main_posts( $page, $number )
{
$from = ($page - 1) * $number;
$to = $number;
$query = mysql_query("SELECT * FROM `blog` ORDER BY `id` DESC LIMIT ".$from.", ".$to) or die( mysql_error() );
if( mysql_num_rows( $query ) < 1 )
{
return false;
}
else
{
$post = array();
$q = NULL;
while( $q = mysql_fetch_array( $query ) )
{
$tags = ( isset( $q['tags'] ) ) ? clean( $q['tags'] ) : NULL;
$content = bbcode($q['content']);
$tags = explode( ",", $tags );
$total_tags = count( $tags );
$i = 1;
foreach( $tags as $tag )
{
if( $i == 1 ) $tags = '';
$tags .= '<a href="http://www.henrylegge.co.uk/tags/'.$tag.'/" title="'.$tag.' Tag">'.$tag.'</a>';
if( $i < $total_tags ) $tags .= ', ';
$i++;
}
$query = mysql_query("SELECT * FROM `comments` WHERE `bid` = '".$q['id']."'") or die( mysql_error() );
$num = mysql_num_rows( $query );
$id = num_clean( $q['id'] );
$day = ( isset( $q['day'] ) ) ? num_clean( $q['day'] ) : NULL;
$month = ( isset( $q['month'] ) ) ? clean( $q['month'] ) : NULL;
$title = ( isset( $q['title'] ) ) ? clean( $q['title'] ) : NULL;
$time = ( isset( $q['time'] ) ) ? clean( $q['time'] ) : NULL;
$category = ( isset( $q['category'] ) ) ? clean( $q['category'] ) : NULL;
$array = array(
'id' => $id,
'day' => $day,
'month' => $month,
'title' => $title,
'time' => $time,
'category' => $category,
'content' => $content,
'tags' => $tags,
'comments' => $num
);
$post[] = $array;
}
return $post;
}
}
/*
Get the posts for the home page
*/
function get_home_posts()
{
$query = mysql_query("SELECT * FROM `blog` ORDER BY `id` DESC LIMIT 5;") or die( mysql_error() );
if( mysql_num_rows( $query ) < 1 )
{
return false;
}
else
{
$post = array();
$q = NULL;
while( $q = mysql_fetch_array( $query ) )
{
$tags = ( isset( $q['tags'] ) ) ? clean( $q['tags'] ) : NULL;
$content = bbcode($q['content']);
$tags = explode( ",", $tags );
$total_tags = count( $tags );
$i = 1;
foreach( $tags as $tag )
{
if( $i == 1 ) $tags = '';
$tags .= '<a href="http://www.henrylegge.co.uk/tags/'.$tag.'/" title="'.$tag.' Tag">'.$tag.'</a>';
if( $i < $total_tags ) $tags .= ', ';
$i++;
}
$query = mysql_query("SELECT * FROM `comments` WHERE `bid` = '".$q['id']."'") or die( mysql_error() );
$num = mysql_num_rows( $query );
$id = num_clean( $q['id'] );
$day = ( isset( $q['day'] ) ) ? num_clean( $q['day'] ) : NULL;
$month = ( isset( $q['month'] ) ) ? clean( $q['month'] ) : NULL;
$title = ( isset( $q['title'] ) ) ? clean( $q['title'] ) : NULL;
$time = ( isset( $q['time'] ) ) ? clean( $q['time'] ) : NULL;
$category = ( isset( $q['category'] ) ) ? clean( $q['category'] ) : NULL;
$array = array(
'id' => $id,
'day' => $day,
'month' => $month,
'title' => $title,
'time' => $time,
'category' => $category,
'content' => $content,
'tags' => $tags,
'comments' => $num
);
$post[] = $array;
}
return $post;
}
}
/*
Get category posts
*/
function get_cat_posts( $cat, $page, $number )
{
$from = ($page - 1) * $number;
$to = $number;
$query = mysql_query("SELECT * FROM `blog` WHERE `category` = '".$cat."' ORDER BY `id` DESC LIMIT ".$from.", ".$to.";");
if( mysql_num_rows( $query ) < 1 )
{
return false;
}
else
{
$post = array();
$q = NULL;
while( $q = mysql_fetch_array( $query ) )
{
$tags = ( isset( $q['tags'] ) ) ? clean( $q['tags'] ) : NULL;
$content = bbcode($q['content']);
$tags = explode( ",", $tags );
$total_tags = count( $tags );
$i = 1;
foreach( $tags as $tag )
{
if( $i == 1 ) $tags = '';
$tags .= '<a href="http://www.henrylegge.co.uk/tags/'.$tag.'/" title="'.$tag.' Tag">'.$tag.'</a>';
if( $i < $total_tags ) $tags .= ', ';
$i++;
}
$query = mysql_query("SELECT * FROM `comments` WHERE `bid` = '".$q['id']."'");
$num = mysql_num_rows( $query );
$id = num_clean( $q['id'] );
$day = ( isset( $q['day'] ) ) ? num_clean( $q['day'] ) : NULL;
$month = ( isset( $q['month'] ) ) ? clean( $q['month'] ) : NULL;
$title = ( isset( $q['title'] ) ) ? clean( $q['title'] ) : NULL;
$time = ( isset( $q['time'] ) ) ? clean( $q['time'] ) : NULL;
$category = ( isset( $q['category'] ) ) ? clean( $q['category'] ) : NULL;
$array = array(
'id' => $id,
'day' => $day,
'month' => $month,
'title' => $title,
'time' => $time,
'category' => $category,
'content' => $content,
'tags' => $tags,
'comments' => $num
);
$post[] = $array;
}
return $post;
}
}
/*
Get single post
*/
function get_post( $id )
{
$id = clean( $id );
$query = mysql_query("SELECT * FROM `blog` WHERE `id` = '".$id."' ");
if( mysql_num_rows( $query ) < 1 )
{
return false;
}
else
{
$q = NULL;
$q = mysql_fetch_array( $query );
$tags = ( isset( $q['tags'] ) ) ? clean( $q['tags'] ) : NULL;
$content = bbcode($q['content']);
$tags = explode( ",", $tags );
$i = 1;
foreach( $tags as $tag )
{
if( $i == 1 ) $tags = '';
$tags .= '<a href="http://www.henrylegge.co.uk/tags/'.$tag.'/" title="'.$tag.' Tag">'.$tag.'</a>';
if( $i < $total_tags ) $tags .= ', ';
$i++;
}
for( $i = 0; $i == 0; $i++ )
{
$query = mysql_query("SELECT * FROM `comments` WHERE `bid` = '".$q['id']."'");
$num = mysql_num_rows( $query );
$id = num_clean( $q['id'] );
$day = ( isset( $q['day'] ) ) ? num_clean( $q['day'] ) : NULL;
$month = ( isset( $q['month'] ) ) ? clean( $q['month'] ) : NULL;
$title = ( isset( $q['title'] ) ) ? clean( $q['title'] ) : NULL;
$time = ( isset( $q['time'] ) ) ? clean( $q['time'] ) : NULL;
$category = ( isset( $q['category'] ) ) ? clean( $q['category'] ) : NULL;
$array = array(
'id' => $id,
'day' => $day,
'month' => $month,
'title' => $title,
'time' => $time,
'category' => $category,
'content' => $content,
'tags' => $tags,
'comments' => $num
);
}
return $post;
}
}
/*
Get Comments
*/
function get_comments( $id )
{
$id = clean( $id );
$query = mysql_query("SELECT * FROM `comments` WHERE `bid` = '".$id."' ORDER BY `id` DESC");
if( mysql_num_rows( $query ) < 1 )
{
return false;
}
else
{
$comment = array();
$q = NULL;
while( $q = mysql_fetch_array( $query ) )
{
$content = bbcode($q['content']);
$array = array(
'author' => $q['author'],
'time' => $q['time'],
'content' => $content
);
$comment[] = $array;
}
return $comment;
}
}
/*
Post comments
*/
function post_comment( $bid, $name, $email, $comment, $captcha, $session, $site )
{
if( empty( $bid ) )
{
return 'error';
}
elseif( empty( $name ) | empty( $email ) | empty( $comment ) | empty( $captcha ) | empty( $session ) )
{
return ' fields';
}
elseif( !email_check( $email ) )
{
return 'email';
}
elseif( strlen( $comment ) < 10 )
{
return 'comment';
}
elseif( $captcha !== $session )
{
return 'captcha';
}
else
{
$bid = num_clean( $bid );
$name = mysql_clean( $name );
$email = clean( $email );
$comment = mysql_clean( $comment );
$site = ( isset( $site ) ) ? mysql_clean( $site ) : NULL;
$ip = get_real_ip();
$time = date('F jS, Y');
mysql_query("INSERT INTO `comments` (`bid`, `author`, `email`, `content`, `ip`, `time`, `site` ) VALUES ('".$bid."', '".$name."', '".$email."', '".$comment."', '".$ip."', '".$time."', '".$site."')");
return 'sucess';
}
}
}
?>