Browse Source

Merge development into production.

pull/24/head
Teknikode 4 years ago
parent
commit
3354a7f691
8 changed files with 569 additions and 409 deletions
  1. 75
    75
      blog/add_post.php
  2. 39
    39
      blog/delete_post.php
  3. 83
    83
      blog/edit_post.php
  4. 57
    38
      blog/get_post.php
  5. 49
    0
      blog/publish_post.php
  6. 160
    130
      blog/view_post.php
  7. 50
    40
      home/main.php
  8. 56
    4
      templates/default/js/blog.js

blog/publish_blog.php → blog/add_post.php View File

@@ -1,75 +1,75 @@
<?php
require_once('../includes/config.php');
$userID = 0;
$authorID = 0;
$title = "";
$post = "";
//check to see that the form has been submitted
if(isset($_POST))
{
//retrieve the $_POST variables
$userID = rawurldecode($_POST['userID']);
$title = rawurldecode($_POST['title']);
$post = rawurldecode($_POST['post']);
//initialize variables for form validation
$success = true;
if($success && !$logged_in)
{
$error = "You must be logged in to make a blog post.";
$success = false;
}
if($success && empty($title))
{
$error = "You need to submit a title with your post.";
$success = false;
}
if($success && strlen($title) > 140)
{
$error = "The maximum length for your title is 140 characters.";
$success = false;
}
if($success && empty($post))
{
$error = "You need to submit an actual post.";
$success = false;
}
if($success && (($userID == 0 && !$user->admin) || ($userID != 0 && $user->id != $userID)))
{
$error = "You are not allowed to post to this blog.";
$success = false;
}
if($success)
{
$data = array(
"user_id" => $userID,
"author_id" => $user->id,
"title" => $title,
"tags" => "",
"post" => $post,
"date_posted" => date("Y-m-d H:i:s",time())
);
$post_id = $db->insert($data, 'blog');
unset($_POST);
echo "true";
}
else
{
unset($_POST);
echo $error;
}
}
else
{
echo "$_POST is not set.";
}
?>
<?php
require_once('../includes/config.php');
$userID = 0;
$authorID = 0;
$title = "";
$post = "";
//check to see that the form has been submitted
if(isset($_POST))
{
//retrieve the $_POST variables
$userID = rawurldecode($_POST['userID']);
$title = rawurldecode($_POST['title']);
$post = rawurldecode($_POST['post']);
//initialize variables for form validation
$success = true;
if($success && !$logged_in)
{
$error = "You must be logged in to make a blog post.";
$success = false;
}
if($success && empty($title))
{
$error = "You need to submit a title with your post.";
$success = false;
}
if($success && strlen($title) > 140)
{
$error = "The maximum length for your title is 140 characters.";
$success = false;
}
if($success && empty($post))
{
$error = "You need to submit an actual post.";
$success = false;
}
if($success && (($userID == 0 && !$user->admin) || ($userID != 0 && $user->id != $userID)))
{
$error = "You are not allowed to post to this blog.";
$success = false;
}
if($success)
{
$data = array(
"user_id" => $userID,
"author_id" => $user->id,
"title" => $title,
"tags" => "",
"post" => $post,
"date_posted" => date("Y-m-d H:i:s",time())
);
$post_id = $db->insert($data, 'blog');
unset($_POST);
echo "true";
}
else
{
unset($_POST);
echo $error;
}
}
else
{
echo "$_POST is not set.";
}
?>

blog/delete_blog.php → blog/delete_post.php View File

@@ -1,39 +1,39 @@
<?php
require_once('../includes/config.php');
//check to see that the form has been submitted
$id = 0;
if(isset($_POST) && $logged_in)
{
$id = rawurldecode($_POST['id']);
$post = $db->select('blog', "id=? LIMIT 1", array($id));
if ($post)
{
$success = true;
$userID = $post['user_id'];
if($success && (($userID == 0 && !$user->admin) || ($userID != 0 && ($user->id != $userID && !$user->admin))))
{
$error = "You are not allowed to delete this post.";
$success = false;
}
if ($success)
{
$db->delete('blog', 'id=?', array($id));
echo "true";
}
else
{
echo $error;
}
}
else
{
echo "That blog post does not exist.";
}
}
else
{
echo "You need to be logged in to delete this post.";
}
?>
<?php
require_once('../includes/config.php');
//check to see that the form has been submitted
$id = 0;
if(isset($_POST) && $logged_in)
{
$id = rawurldecode($_POST['id']);
$post = $db->select('blog', "id=? LIMIT 1", array($id));
if ($post)
{
$success = true;
$userID = $post['user_id'];
if($success && (($userID == 0 && !$user->admin) || ($userID != 0 && ($user->id != $userID && !$user->admin))))
{
$error = "You are not allowed to delete this post.";
$success = false;
}
if ($success)
{
$db->delete('blog', 'id=?', array($id));
echo "true";
}
else
{
echo $error;
}
}
else
{
echo "That blog post does not exist.";
}
}
else
{
echo "You need to be logged in to delete this post.";
}
?>

blog/edit_blog.php → blog/edit_post.php View File

@@ -1,83 +1,83 @@
<?php
require_once('../includes/config.php');
$userID = 0;
$postID = 0;
$authorID = 0;
$title = "";
$post = "";
//check to see that the form has been submitted
if(isset($_POST))
{
//retrieve the $_POST variables
$userID = rawurldecode($_POST['userID']);
$postID = rawurldecode($_POST['postID']);
$title = rawurldecode($_POST['title']);
$post = rawurldecode($_POST['post']);
$post_select = $db->select('blog', "id=? LIMIT 1", array($postID));
if ($post_select)
{
//initialize variables for form validation
$success = true;
if($success && !$logged_in)
{
$error = "You must be logged in to edit this blog post.";
$success = false;
}
if($success && empty($title))
{
$error = "You need to submit a title with your post.";
$success = false;
}
if($success && strlen($title) > 140)
{
$error = "The maximum length for your title is 140 characters.";
$success = false;
}
if($success && empty($post))
{
$error = "You need to submit an actual post.";
$success = false;
}
if ($success && !$user->admin && $post_select['author_id'] != $user->id)
{
$error = "You are not allowed to edit this post.";
$success = false;
}
if($success)
{
$data = array(
"title" => $title,
"tags" => "",
"post" => $post
);
$post_id = $db->update($data, 'blog', 'id=?', array($postID));
unset($_POST);
echo "true";
}
else
{
unset($_POST);
echo $error;
}
}
else
{
echo "That blog post does not exist.";
}
}
else
{
echo "$_POST is not set.";
}
?>
<?php
require_once('../includes/config.php');
$userID = 0;
$postID = 0;
$authorID = 0;
$title = "";
$post = "";
//check to see that the form has been submitted
if(isset($_POST))
{
//retrieve the $_POST variables
$userID = rawurldecode($_POST['userID']);
$postID = rawurldecode($_POST['postID']);
$title = rawurldecode($_POST['title']);
$post = rawurldecode($_POST['post']);
$post_select = $db->select('blog', "id=? LIMIT 1", array($postID));
if ($post_select)
{
//initialize variables for form validation
$success = true;
if($success && !$logged_in)
{
$error = "You must be logged in to edit this blog post.";
$success = false;
}
if($success && empty($title))
{
$error = "You need to submit a title with your post.";
$success = false;
}
if($success && strlen($title) > 140)
{
$error = "The maximum length for your title is 140 characters.";
$success = false;
}
if($success && empty($post))
{
$error = "You need to submit an actual post.";
$success = false;
}
if ($success && !$user->admin && $post_select['author_id'] != $user->id)
{
$error = "You are not allowed to edit this post.";
$success = false;
}
if($success)
{
$data = array(
"title" => $title,
"tags" => "",
"post" => $post
);
$post_id = $db->update($data, 'blog', 'id=?', array($postID));
unset($_POST);
echo "true";
}
else
{
unset($_POST);
echo $error;
}
}
else
{
echo "That blog post does not exist.";
}
}
else
{
echo "$_POST is not set.";
}
?>

+ 57
- 38
blog/get_post.php View File

@@ -34,52 +34,71 @@ if(isset($_POST))
$author_id = $post['author_id'];
$author = $userTools->get($author_id);
$date = $post['date_posted'];
$published = $post['published'];
$title = $post['title'];
$tags = $post['tags'];
$post = $post['post'];
$reply_msg = "";
$replies = $db->select('comments', "reply_id=? AND service=?", array($post_id, 'blog'), 'count(*) cnt');
$reply_count = $replies['cnt'];
if ($reply_count > 0)
if ($published || $own_blog)
{
$reply_msg = " | <a href='".get_page_url("blog", $CONF)."/".$author->username."/".$post_id."#replies'>Replies:".$reply_count."</a>";
}
?>
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#title_<?php echo $post_id; ?>").html(new_post);
// Post Conversion
var old_post = $("#post_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#post_<?php echo $post_id; ?>").html(new_post);
</script>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="blog-post">
<h2 class="blog-post-title text-center"><a href="<?php echo get_page_url("blog", $CONF); ?>/<?php echo $author->username; ?>/<?php echo $post_id; ?>" id="title_<?php echo $post_id; ?>"><?php echo $title; ?></a></h2>
<p class="blog-post-meta text-center text-muted">
Posted on <?php echo date("F d, Y",strtotime($date)); ?> by <a href="<?php echo get_page_url("home", $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a><?php echo $reply_msg; ?>
<?php
if ($own_blog)
{
?>
<br />
<button type="button" class="btn btn-info edit_post" id="<?php echo $post_id; ?>" data-toggle="modal" data-target="#editPost">Edit</button>
<button type="button" class="btn btn-danger delete_post" id="<?php echo $post_id; ?>">Delete</button>
<?php
}
?>
</p>
<p id="post_<?php echo $post_id; ?>"><?php echo $post; ?></p>

$replies = $db->select('comments', "reply_id=? AND service=?", array($post_id, 'blog'), 'count(*) cnt');
$reply_count = $replies['cnt'];
if ($reply_count > 0)
{
$reply_msg = " | <a href='".get_page_url("blog", $CONF)."/".$author->username."/".$post_id."#replies'>Replies:".$reply_count."</a>";
}
?>
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#title_<?php echo $post_id; ?>").html(new_post);
// Post Conversion
var old_post = $("#post_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#post_<?php echo $post_id; ?>").html(new_post);
</script>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<div class="blog-post">
<h2 class="blog-post-title text-center"><a href="<?php echo get_page_url("blog", $CONF); ?>/<?php echo $author->username; ?>/<?php echo $post_id; ?>" id="title_<?php echo $post_id; ?>"><?php echo $title; ?></a></h2>
<p class="blog-post-meta text-center text-muted">
Posted on <?php echo date("F d, Y",strtotime($date)); ?> by <a href="<?php echo get_page_url("home", $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a><?php echo $reply_msg; ?>
<?php
if ($own_blog)
{
?>
<br />
<button type="button" class="btn btn-info edit_post" id="<?php echo $post_id; ?>" data-toggle="modal" data-target="#editPost">Edit</button>
<?php
if ($published)
{
?>
<button type="button" class="btn btn-warning unpublish_post" id="<?php echo $post_id; ?>">Unpublish</button>
<?php
}
else
{
?>
<button type="button" class="btn btn-success publish_post" id="<?php echo $post_id; ?>">Publish</button>
<?php
}
?>
<button type="button" class="btn btn-danger delete_post" id="<?php echo $post_id; ?>">Delete</button>
<?php
}
?>
</p>
<p id="post_<?php echo $post_id; ?>"><?php echo $post; ?></p>
</div>
</div>
</div>
</div>
<?php
<?php
}
}
}
}
?>
?>

+ 49
- 0
blog/publish_post.php View File

@@ -0,0 +1,49 @@
<?php
require_once('../includes/config.php');

//check to see that the form has been submitted
$id = 0;
if(isset($_POST) && $logged_in)
{
$id = rawurldecode($_POST['id']);
$post = $db->select('blog', "id=? LIMIT 1", array($id));
if ($post)
{
$success = true;
$publish = $post['publish'];
if ($success && !$user->admin && $post_select['author_id'] != $user->id)
{
$error = "You are not allowed to publish this post.";
if (!$publish)
{
$error = "You are not allowed to unpublish this post.";
}
$success = false;
}

if ($success)
{
$data = array(
"publish" => $publish,
"date_published" => date("Y-m-d H:i:s",time())
);

$post_id = $db->update($data, 'blog', 'id=?', array($id));
unset($_POST);
echo "true";
}
else
{
echo $error;
}
}
else
{
echo "That blog post does not exist.";
}
}
else
{
echo "You need to be logged in to delete this post.";
}
?>

+ 160
- 130
blog/view_post.php View File

@@ -23,6 +23,7 @@ if (isset($_GET['post']))
$author_id = $post['author_id'];
$author = $userTools->get($author_id);
$date = $post['date_posted'];
$published = $post['published'];
$title = $post['title'];
$tags = $post['tags'];
$post = $post['post'];
@@ -31,160 +32,189 @@ if (isset($_GET['post']))
{
$own_blog = true;
}

if ($published || $own_blog)
{
set_page_title($title);
?>
<div class="container">
<?php
if ($own_blog)
{
set_page_title($title);
?>
<div class="modal fade" id="editPost" tabindex="-1" role="dialog" aria-labelledby="editPostLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form" action="##" method="post" id="editPostForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cancel</span></button>
<h4 class="modal-title" id="editPostLabel">Edit Your Post</h4>
</div>
<div class="modal-body">
<input name="edit_blog_userid" id="edit_blog_userid" type="hidden" value="<?php echo $author_id; ?>" />
<input name="edit_blog_postid" id="edit_blog_postid" type="hidden" />
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_blog_title"><h4>Title</h4></label>
<input class="form-control" name="edit_blog_title" id="edit_blog_title" placeholder="generic click bait" title="enter a title for your post." type="text" />
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_blog_post"><h4>Article</h4></label>
<textarea class="form-control" name="edit_blog_post" id="edit_blog_post" placeholder="I ate a burger today." title="enter any information you want to share with the world." data-provide="markdown" rows="10"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="edit_submit">Save</button>
</div>
</form>
</div>
</div>
</div>
<?php
}
?>
<div class="blog-main" id="<?php echo $post_id; ?>">
<div class="row">
<div class="col-sm-10 col-sm-offset-1 blog-main">
<div class="blog-post">
<ol class="breadcrumb">
<li><a href="<?php echo get_page_url('blog', $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a></li>
<li class="active"><a href="#"><?php echo $title; ?></a></li>
</ol>
<h2 class="blog-post-title text-center"><a href="<?php echo get_page_url("blog", $CONF); ?>/<?php echo $author->username; ?>/<?php echo $post_id; ?>" id="title_<?php echo $post_id; ?>"><?php echo $title; ?></a></h2>
<p class="blog-post-meta text-center text-muted">
Posted on <?php echo date("F d, Y",strtotime($date)); ?> by <a href="<?php echo get_page_url("home", $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a>
<?php
if ($own_blog)
{
?>
<br />
<button type="button" class="btn btn-info edit_post" id="<?php echo $post_id; ?>" data-toggle="modal" data-target="#editPost">Edit</button>
<button type="button" class="btn btn-danger delete_post" id="<?php echo $post_id; ?>">Delete</button>
<?php
}
?>
</p>
<p id="post_<?php echo $post_id; ?>"><?php echo $post; ?></p>
</div>
</div>
</div>
</div>
<?php
if ($logged_in)
{
?>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newComment">Add Comment</button>
</div>
</div>
<br />
<div class="modal fade" id="newComment" tabindex="-1" role="dialog" aria-labelledby="newCommentLabel" aria-hidden="true">
<div class="container">
<?php
if ($own_blog)
{
?>
<div class="modal fade" id="editPost" tabindex="-1" role="dialog" aria-labelledby="editPostLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form" action="##" method="post" id="publishComment">
<form class="form" action="##" method="post" id="editPostForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cancel</span></button>
<h4 class="modal-title" id="newCommentLabel">Add a New Comment</h4>
<h4 class="modal-title" id="editPostLabel">Edit Your Post</h4>
</div>
<div class="modal-body">
<input name="post_id" id="post_id" type="hidden" value="<?php echo $post_id; ?>" />
<input name="edit_blog_userid" id="edit_blog_userid" type="hidden" value="<?php echo $author_id; ?>" />
<input name="edit_blog_postid" id="edit_blog_postid" type="hidden" />
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_blog_title"><h4>Title</h4></label>
<input class="form-control" name="edit_blog_title" id="edit_blog_title" placeholder="generic click bait" title="enter a title for your post." type="text" />
</div>
</div>
<div class="row">
<div class="form-group col-sm-12">
<label for="comment_post"><h4>Comment</h4></label>
<textarea class="form-control wmd-input" name="comment_post" id="comment_post" placeholder="Nice post!" title="enter what you think about the post." data-provide="markdown" rows="10"></textarea>
<label for="edit_blog_post"><h4>Article</h4></label>
<textarea class="form-control" name="edit_blog_post" id="edit_blog_post" placeholder="I ate a burger today." title="enter any information you want to share with the world." data-provide="markdown" rows="10"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="comment_submit">Publish</button>
<button type="button" class="btn btn-primary" id="edit_submit">Save</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" id="editComment" tabindex="-1" role="dialog" aria-labelledby="editCommentLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form" action="##" method="post" id="editCommentForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cancel</span></button>
<h4 class="modal-title" id="editCommentLabel">Edit Your Comment</h4>
</div>
<div class="modal-body">
<input name="edit_comment_postid" id="edit_comment_postid" type="hidden" />
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_comment_post"><h4>Comment</h4></label>
<textarea class="form-control" name="edit_comment_post" id="edit_comment_post" placeholder="What an interesting article!" title="enter what you thought about the article." data-provide="markdown" rows="10"></textarea>
<?php
}
?>
<div class="blog-main" id="<?php echo $post_id; ?>">
<div class="row">
<div class="col-sm-10 col-sm-offset-1 blog-main">
<div class="blog-post">
<ol class="breadcrumb">
<li><a href="<?php echo get_page_url('blog', $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a></li>
<li class="active"><a href="#"><?php echo $title; ?></a></li>
</ol>
<h2 class="blog-post-title text-center"><a href="<?php echo get_page_url("blog", $CONF); ?>/<?php echo $author->username; ?>/<?php echo $post_id; ?>" id="title_<?php echo $post_id; ?>"><?php echo $title; ?></a></h2>
<p class="blog-post-meta text-center text-muted">
Posted on <?php echo date("F d, Y",strtotime($date)); ?> by <a href="<?php echo get_page_url("home", $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a>
<?php
if ($own_blog)
{
?>
<br />
<button type="button" class="btn btn-info edit_post" id="<?php echo $post_id; ?>" data-toggle="modal" data-target="#editPost">Edit</button>
<?php
if ($published)
{
?>
<button type="button" class="btn btn-warning unpublish_post" id="<?php echo $post_id; ?>">Unpublish</button>
<?php
}
else
{
?>
<button type="button" class="btn btn-success publish_post" id="<?php echo $post_id; ?>">Publish</button>
<?php
}
?>
<button type="button" class="btn btn-danger delete_post" id="<?php echo $post_id; ?>">Delete</button>
<?php
}
?>
</p>
<p id="post_<?php echo $post_id; ?>"><?php echo $post; ?></p>
</div>
</div>
</div>
</div>
<?php
if ($logged_in)
{
?>
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newComment">Add Comment</button>
</div>
</div>
<br />
<div class="modal fade" id="newComment" tabindex="-1" role="dialog" aria-labelledby="newCommentLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form" action="##" method="post" id="publishComment">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cancel</span></button>
<h4 class="modal-title" id="newCommentLabel">Add a New Comment</h4>
</div>
<div class="modal-body">
<input name="post_id" id="post_id" type="hidden" value="<?php echo $post_id; ?>" />
<div class="row">
<div class="form-group col-sm-12">
<label for="comment_post"><h4>Comment</h4></label>
<textarea class="form-control wmd-input" name="comment_post" id="comment_post" placeholder="Nice post!" title="enter what you think about the post." data-provide="markdown" rows="10"></textarea>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="edit_comment_submit">Save</button>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="comment_submit">Publish</button>
</div>
</form>
</div>
</div>
</div>

<div class="modal fade" id="editComment" tabindex="-1" role="dialog" aria-labelledby="editCommentLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form class="form" action="##" method="post" id="editCommentForm">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Cancel</span></button>
<h4 class="modal-title" id="editCommentLabel">Edit Your Comment</h4>
</div>
<div class="modal-body">
<input name="edit_comment_postid" id="edit_comment_postid" type="hidden" />
<div class="row">
<div class="form-group col-sm-12">
<label for="edit_comment_post"><h4>Comment</h4></label>
<textarea class="form-control" name="edit_comment_post" id="edit_comment_post" placeholder="What an interesting article!" title="enter what you thought about the article." data-provide="markdown" rows="10"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="edit_comment_submit">Save</button>
</div>
</form>
</div>
</div>
</div>
<?php
}
?>
<a name="replies"></a>
<div class="post-comments" id="<?php echo $post_id; ?>"></div>
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#title_<?php echo $post_id; ?>").html(new_post);
// Post Conversion
var old_post = $("#post_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#post_<?php echo $post_id; ?>").html(new_post);

var posts = <?php echo $comments_per_load; ?>;
var start_post = 0;
var view_post_id = <?php echo $post_num; ?>;
loadMoreComments(start_post, posts);
start_post = start_post + posts;
</script>
<?php
}
else
{
set_page_title("Invalid Post");
?>
<div class="row">
<div class="col-sm-12 text-center">
<h2>That post does not exist</h2>
</div>
<?php
}
?>
<a name="replies"></a>
<div class="post-comments" id="<?php echo $post_id; ?>"></div>
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#title_<?php echo $post_id; ?>").html(new_post);
// Post Conversion
var old_post = $("#post_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#post_<?php echo $post_id; ?>").html(new_post);
var posts = <?php echo $comments_per_load; ?>;
var start_post = 0;
var view_post_id = <?php echo $post_num; ?>;
loadMoreComments(start_post, posts);
start_post = start_post + posts;
</script>
<?php
</div>
<?php
}
}
else
{
@@ -225,4 +255,4 @@ else
<?php
}
include('../templates/'.$CONF['template'].'/footer.php');
?>
?>

+ 50
- 40
home/main.php View File

@@ -141,30 +141,35 @@
$author_id = $post['author_id'];
$author = $userTools->get($author_id);
$date = $post['date_posted'];
$published = $post['published'];
$title = $post['title'];
$tags = $post['tags'];
$post = $post['post'];
?>
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#title_<?php echo $post_id; ?>").html(new_post);
</script>
<li class="list-group-item">
<div class="row">
<div class="col-sm-12">
<div class="blog-post-sm">
<h2 class="blog-post-title-sm text-left"><a href="<?php echo get_page_url("blog", $CONF); ?>/<?php echo $author->username; ?>/<?php echo $post_id; ?>" id="title_<?php echo $post_id; ?>"><?php echo $title; ?></a></h2>
<p class="blog-post-meta-sm text-left text-muted">
Posted on <?php echo date("F d, Y",strtotime($date)); ?> by <a href="<?php echo get_page_url("home", $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a>
</p>

if ($published)
{
?>
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#title_<?php echo $post_id; ?>").html(new_post);
</script>
<li class="list-group-item">
<div class="row">
<div class="col-sm-12">
<div class="blog-post-sm">
<h2 class="blog-post-title-sm text-left"><a href="<?php echo get_page_url("blog", $CONF); ?>/<?php echo $author->username; ?>/<?php echo $post_id; ?>" id="title_<?php echo $post_id; ?>"><?php echo $title; ?></a></h2>
<p class="blog-post-meta-sm text-left text-muted">
Posted on <?php echo date("F d, Y",strtotime($date)); ?> by <a href="<?php echo get_page_url("home", $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a>
</p>
</div>
</div>
</div>
</div>
</div>
</li>
<?php
</li>
<?php
}
}
?>
</ul>
@@ -251,30 +256,35 @@
$author_id = $post['author_id'];
$author = $userTools->get($author_id);
$date = $post['date_posted'];
$published = $post['published'];
$title = $post['title'];
$tags = $post['tags'];
$post = $post['post'];
?>
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#title_<?php echo $post_id; ?>").html(new_post);
</script>
<li class="list-group-item">
<div class="row">
<div class="col-sm-12">
<div class="blog-post-sm">
<h2 class="blog-post-title-sm text-left"><a href="<?php echo get_page_url("blog", $CONF); ?>/<?php echo $author->username; ?>/<?php echo $post_id; ?>" id="title_<?php echo $post_id; ?>"><?php echo $title; ?></a></h2>
<p class="blog-post-meta-sm text-left text-muted">
Posted on <?php echo date("F d, Y",strtotime($date)); ?> by <a href="<?php echo get_page_url("home", $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a>
</p>

if ($published)
{
?>
<script>
var converter = new Markdown.getSanitizingConverter();
// Title Conversion
var old_post = $("#title_<?php echo $post_id; ?>").text();
var new_post = converter.makeHtml(old_post);
$("#title_<?php echo $post_id; ?>").html(new_post);
</script>
<li class="list-group-item">
<div class="row">
<div class="col-sm-12">
<div class="blog-post-sm">
<h2 class="blog-post-title-sm text-left"><a href="<?php echo get_page_url("blog", $CONF); ?>/<?php echo $author->username; ?>/<?php echo $post_id; ?>" id="title_<?php echo $post_id; ?>"><?php echo $title; ?></a></h2>
<p class="blog-post-meta-sm text-left text-muted">
Posted on <?php echo date("F d, Y",strtotime($date)); ?> by <a href="<?php echo get_page_url("home", $CONF); ?>/<?php echo $author->username; ?>"><?php echo $author->username; ?></a>
</p>
</div>
</div>
</div>
</div>
</div>
</li>
<?php
</li>
<?php
}
}
?>
</ul>

+ 56
- 4
templates/default/js/blog.js View File

@@ -6,7 +6,7 @@ $(document).ready(function() {
post=encodeURIComponent($("#blog_post").val());
$.ajax({
type: "POST",
url: "../../../publish_blog.php",
url: "../../../add_post.php",
data: "userID="+userID+"&title="+title+"&post="+post,
success: function(html)
{
@@ -62,7 +62,7 @@ $(document).ready(function() {
post=encodeURIComponent($("#edit_blog_post").val());
$.ajax({
type: "POST",
url: "../../../edit_blog.php",
url: "../../../edit_post.php",
data: "userID="+userID+"&postID="+postID+"&title="+title+"&post="+post,
success: function(html)
{
@@ -182,6 +182,8 @@ function loadMorePosts(start, count)
{
$(".blog-main").append(html);
linkPostDelete('.delete_post');
linkPostPublish('.post_publish');
linkPostUnpublish('.post_unpublish');
$(window).bind('scroll', bindScrollPosts);
}
}
@@ -227,6 +229,56 @@ function bindScrollComments()
}
}
function linkPostUnpublish(selector)
{
$(selector).click(function() {
var object = $(this);
post_id=encodeURIComponent(object.attr("id"));
$.ajax({
type: "POST",
url: "../../../publish_post.php",
data: "publish=FALSE&id="+post_id,
success: function(html)
{
if(html=='true')
{
window.location.reload();
}
else
{
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+html+'</div>');
}
}
});
});
}

function linkPostPublish(selector)
{
$(selector).click(function() {
var object = $(this);
post_id=encodeURIComponent(object.attr("id"));
$.ajax({
type: "POST",
url: "../../../publish_post.php",
data: "publish=TRUE&id="+post_id,
success: function(html)
{
if(html=='true')
{
window.location.reload();
}
else
{
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+html+'</div>');
}
}
});
});
}

function linkPostDelete(selector)
{
$(selector).click(function() {
@@ -237,7 +289,7 @@ function linkPostDelete(selector)
{
$.ajax({
type: "POST",
url: "../../../delete_blog.php",
url: "../../../delete_post.php",
data: "id="+post_id,
success: function(html)
{
@@ -285,4 +337,4 @@ function linkCommentDelete(selector)
}
});
});
}
}

Loading…
Cancel
Save