Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Check if we need to go back
- if(!isset($_GET['id'])) {
- header("Location: /blog.php");
- }
- function _nl2br($str) {
- return str_replace("__NEW_LINE__", "<br />", $str);
- }
- class BlogComment {
- var $author;
- var $authorRole;
- var $authorImagePath;
- var $body;
- var $date;
- var $id;
- function BlogComment() {
- $this->author = 'Unknown';
- $this->body = 'Unknown';
- $this->date = 'Unknown';
- $this->authorRole = "member";
- $this->authorImagePath = "/gfx/default_user_icon.png";
- $this->id = 0;
- }
- function read($data) {
- $this->author = $data['author'];
- $this->date = strip_tags($data['date']);;
- $this->body = strip_tags($data['body'], "<image><img><div><a><p><ul><li><b><i><u><br><span>");
- $this->body = stripslashes(_nl2br($this->body));
- $this->id = strip_tags($data['id']);
- $result = mysql_query("SELECT * FROM users WHERE username='" . mysql_real_escape_string($this->author) . "'");
- $field = mysql_fetch_assoc($result);
- $this->authorRole = strip_tags($field['role']);
- $this->authorImagePath = strip_tags($field['prof_pic_path']);
- }
- function getHTML() {
- $str = "<div class=\"article_title_bottom_border\"></div>\n<div class=\"comment\" id=\"" . $this->id . "\" style=\"margin-left: 20px;\">\n<image class=\"comment_author_image\" src=\"" . $this->authorImagePath . "\" alt=\"Profile Picture\" style=\"border-radius: 4px; -moz-border-radius: 4px; box-shadow: 4px 4px 6px #222222;\" width=\"64px\" height=\"64px\" />\n<a class=\"article_author_viewprofile\" href=\"/viewprofile.php?usr=" . $this->author . "\">\n<label class=\"username_label_" . $this->authorRole . "\" style=\"margin-bottom: 14px; margin-left: 10px; position: relative; top: -50px;\">" . $this->author . "</label></a>\n<br />\n<div style=\"margin-left: 94px; position: relative; top: -50px;\">\n<label class=\"article_body_comment\">" . $this->body . "</label>\n</div>\n</div>" . "\n\n";
- return $str;
- }
- }
- class BlogPost {
- var $author;
- var $authorRole;
- var $title;
- var $body;
- var $date;
- var $comments;
- var $id;
- function BlogPost() {
- $this->author = 'Unknown';
- $this->body = 'Unknown';
- $this->title = 'Unknown';
- $this->date = 'Unknown';
- $this->authorRole = "member";
- $this->comments = array('NO_COMMENTS');
- $this->id = 0;
- }
- function read($data) {
- $this->author = strip_tags($data['author']);
- $this->body = strip_tags($data['body'], "<image><img><div><a><p><ul><li><b><i><u><br><span>");
- $this->body = stripslashes(_nl2br($this->body));
- $this->title = strip_tags($data['title']);
- $this->comments = unserialize(strip_tags($data['comments']));
- $this->id = strip_tags($data['id']);
- $this->date = strip_tags($data['date']);
- $result = mysql_query("SELECT * FROM users WHERE username='" . mysql_real_escape_string($this->author) . "'");
- $field = mysql_fetch_assoc($result);
- $this->authorRole = strip_tags($field['role']);
- }
- function getCommentHTML() {
- $str = "<!-- Comments -->\n";
- $stack = array();
- foreach($this->comments as $c) {
- if($c == 'NO_COMMENTS') {
- // echo 'Found "NO_COMMENTS"';
- break;
- }
- // echo "COMMENT_ID: " . $c . "<br />";
- $result = mysql_query("SELECT * FROM blog_comments WHERE id='" . $c . "'");
- while($field = mysql_fetch_assoc($result)) {
- // echo "Found a post!\n";
- array_push($stack, $field);
- }
- }
- $np = array();
- for($i = 0; $i < count($stack); $i++) {
- $bp = new BlogComment;
- $bp->read($stack[$i]);
- echo "<!-- COMMENT #" . $i . "\n" . $bp->getHTML() . "\n-->";
- $str = $str . "\n" . $bp->getHTML();
- }
- return $str;
- }
- function getHTML() {
- $top = '';
- if($i == 1) {
- $top = 'style="position: relative; top: -20px;"';
- }
- $str = "<div class=\"article\" id=\"" . $this->id . "\">\n<a class=\"viewarticle_a\" href=\"/viewblogpost.php?id=" . $this->id . "\"><label class=\"article_title\">" . $this->title . "</label></a>\n<label class=\"article_date\"" . $top . ">" . $this->date . "</label>\n<div class=\"article_title_bottom_border\"></div>\n<div class=\"article_body\">" . $this->body . "</div><br><label class=\"article_author\">- <a class=\"article_author_viewprofile\" href=\"/viewprofile.php?usr=" . $this->author . "\"><label class=\"username_label_" . $this->authorRole . "\">" . $this->author . "</label></a></label><br />" . $this->getCommentHTML();
- return $str;
- }
- }
- function convert($str, $ky = ''){
- if($ky == '')
- return $str;
- $ky = str_replace(chr(32), '', $ky);
- if(strlen($ky) < 8)
- exit('key error');
- $kl = strlen($ky) < 32 ? strlen($ky) : 32;
- $k = array();
- for($i = 0; $i < $kl; $i++) {
- $k[$i] = ord($ky{$i}) & 0x1F;
- }
- $j=0;
- for($i = 0; $i < strlen($str); $i++) {
- $e = ord($str{$i});
- $str{$i} = $e & 0xE0 ? chr($e ^ $k[$j]) : chr($e);
- $j++;
- $j = $j == $kl ? 0 : $j;
- }
- return $str;
- }
- function getBlogPosts($result) {
- $stack = array();
- while($field = mysql_fetch_assoc($result)) {
- // echo "Found a post!\n";
- array_push($stack, $field);
- }
- return $stack;
- }
- function createBlogPosts($posts) {
- $np = array();
- for($i = count($posts) - 1; $i >= 0; $i--) {
- $bp = new BlogPost;
- $bp->read($posts[$i]);
- array_push($np, $bp);
- }
- return $np;
- }
- function writeBlogPosts($posts) {
- $i = 1;
- foreach($posts as $post) {
- echo $post->getHTML() . "\n\n";
- $i++;
- }
- }
- $postID = $_GET['id'];
- $conn = mysql_connect(wuthost, wutusername, wutpassword));
- mysql_select_db(wutdbname);
- $result = mysql_query("SELECT * FROM blog WHERE id='" . mysql_real_escape_string($postID) . "'");
- $posts = getBlogPosts($result);
- $np = createBlogPosts($posts);
- writeBlogPosts($np);
- mysql_close($conn);
- ?>
- <?php
- if($_SESSION['loggedin']) {
- echo '
- <div class="article_title_bottom_border" style="margin-bottom: 15px"></div>
- <div id="new_comment_container">
- <form method="post">
- <textarea id="new_comment_field" name="new_comment_field" cols="80" rows="5" style="margin-left: 20px; padding: 4px; border-radius: 5px; -moz-border-radius: 5px; box-shadow: 2px 2px 4px black;" >
- Enter your comment here.
- </textarea>
- <br />
- <input type="submit" name="new_comment_button" value=" Submit " style="margin-left: 615px;" id="new_comment_button" class="new_comment" />
- </form>
- </div> <!-- #new_comment_container -->';
- } else {
- echo '
- <div class="article_title_bottom_border" style="margin-bottom: 15px"></div>
- <div id="new_comment_container">
- <label class="not_logged_in">You need to be logged in to post a comment</label>
- </form>
- </div> <!-- #new_comment_container -->';
- }
Advertisement
Add Comment
Please, Sign In to add comment