mad1231999

Untitled

Jan 22nd, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.90 KB | None | 0 0
  1. <?php
  2.                     // Check if we need to go back
  3.                     if(!isset($_GET['id'])) {
  4.                         header("Location: /blog.php");
  5.                     }
  6.  
  7.                     function _nl2br($str) {
  8.                         return str_replace("__NEW_LINE__", "<br />", $str);
  9.                     }
  10.  
  11.                     class BlogComment {
  12.                         var $author;
  13.                         var $authorRole;
  14.                         var $authorImagePath;
  15.                         var $body;
  16.                         var $date;
  17.                         var $id;
  18.  
  19.                         function BlogComment() {
  20.                             $this->author = 'Unknown';
  21.                             $this->body = 'Unknown';
  22.                             $this->date = 'Unknown';
  23.                             $this->authorRole = "member";
  24.                             $this->authorImagePath = "/gfx/default_user_icon.png";
  25.                             $this->id = 0;
  26.                         }
  27.  
  28.                         function read($data) {
  29.                             $this->author = $data['author'];
  30.                             $this->date = strip_tags($data['date']);;
  31.                             $this->body = strip_tags($data['body'], "<image><img><div><a><p><ul><li><b><i><u><br><span>");
  32.                             $this->body = stripslashes(_nl2br($this->body));
  33.                             $this->id = strip_tags($data['id']);
  34.  
  35.                             $result = mysql_query("SELECT * FROM users WHERE username='" . mysql_real_escape_string($this->author) . "'");
  36.                             $field = mysql_fetch_assoc($result);
  37.  
  38.                             $this->authorRole = strip_tags($field['role']);
  39.                             $this->authorImagePath = strip_tags($field['prof_pic_path']);
  40.                         }
  41.  
  42.                         function getHTML() {
  43.                             $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";
  44.                        
  45.                             return $str;
  46.                         }
  47.                     }
  48.  
  49.                     class BlogPost {
  50.                         var $author;
  51.                         var $authorRole;
  52.                         var $title;
  53.                         var $body;
  54.                         var $date;
  55.                         var $comments;
  56.                         var $id;
  57.  
  58.                         function BlogPost() {
  59.                             $this->author = 'Unknown';
  60.                             $this->body = 'Unknown';
  61.                             $this->title = 'Unknown';
  62.                             $this->date = 'Unknown';
  63.                             $this->authorRole = "member";
  64.                             $this->comments = array('NO_COMMENTS');
  65.                             $this->id = 0;
  66.                         }
  67.  
  68.                         function read($data) {
  69.                             $this->author = strip_tags($data['author']);
  70.                             $this->body = strip_tags($data['body'], "<image><img><div><a><p><ul><li><b><i><u><br><span>");
  71.                             $this->body = stripslashes(_nl2br($this->body));
  72.                             $this->title = strip_tags($data['title']);
  73.                             $this->comments = unserialize(strip_tags($data['comments']));
  74.                             $this->id = strip_tags($data['id']);
  75.                             $this->date = strip_tags($data['date']);
  76.  
  77.                             $result = mysql_query("SELECT * FROM users WHERE username='" . mysql_real_escape_string($this->author) . "'");
  78.                             $field = mysql_fetch_assoc($result);
  79.  
  80.                             $this->authorRole = strip_tags($field['role']);
  81.                         }
  82.  
  83.                         function getCommentHTML() {
  84.                             $str = "<!-- Comments -->\n";
  85.                            
  86.                             $stack = array();
  87.  
  88.                             foreach($this->comments as $c) {
  89.                                 if($c == 'NO_COMMENTS') {
  90.                                     // echo 'Found "NO_COMMENTS"';
  91.                                     break;
  92.                                 }
  93.  
  94.                                 // echo "COMMENT_ID: " . $c . "<br />";
  95.  
  96.                                 $result = mysql_query("SELECT * FROM blog_comments WHERE id='" . $c . "'");
  97.  
  98.  
  99.                                 while($field = mysql_fetch_assoc($result)) {
  100.                                     // echo "Found a post!\n";
  101.                                     array_push($stack, $field);
  102.                                 }
  103.                             }
  104.  
  105.                             $np = array();
  106.  
  107.                             for($i = 0; $i < count($stack); $i++) {
  108.                                 $bp = new BlogComment;
  109.                                 $bp->read($stack[$i]);
  110.  
  111.                                 echo "<!-- COMMENT #" . $i . "\n" . $bp->getHTML() . "\n-->";
  112.  
  113.                                 $str = $str . "\n" . $bp->getHTML();
  114.                             }
  115.  
  116.                             return $str;
  117.                         }
  118.  
  119.                         function getHTML($i) {
  120.                             $top = '';
  121.                             $i = 2;
  122.                        
  123.                             if($i == 1) {
  124.                                 $top = 'style="position: relative; top: -20px;"';
  125.                             }
  126.  
  127.                             $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();
  128.  
  129.                             return $str;
  130.                         }
  131.                     }
  132.  
  133.                     function convert($str, $ky = ''){
  134.                         if($ky == '')
  135.                             return $str;
  136.  
  137.                         $ky = str_replace(chr(32), '', $ky);
  138.  
  139.                         if(strlen($ky) < 8)
  140.                             exit('key error');
  141.  
  142.                         $kl = strlen($ky) < 32 ? strlen($ky) : 32;
  143.                         $k = array();
  144.  
  145.                         for($i = 0; $i < $kl; $i++) {
  146.                             $k[$i] = ord($ky{$i}) & 0x1F;
  147.                         }
  148.  
  149.                         $j=0;
  150.  
  151.                         for($i = 0; $i < strlen($str); $i++) {
  152.                             $e = ord($str{$i});
  153.                             $str{$i} = $e & 0xE0 ? chr($e ^ $k[$j]) : chr($e);
  154.                             $j++;
  155.                             $j = $j == $kl ? 0 : $j;
  156.                         }
  157.                        
  158.                         return $str;
  159.                     }
  160.  
  161.                     function getBlogPosts($result) {
  162.                         $stack = array();
  163.  
  164.                         while($field = mysql_fetch_assoc($result)) {
  165.                             // echo "Found a post!\n";
  166.                             array_push($stack, $field);
  167.                         }
  168.  
  169.                         return $stack;
  170.                     }
  171.  
  172.                     function createBlogPosts($posts) {
  173.                         $np = array();
  174.  
  175.                         for($i = count($posts) - 1; $i >= 0; $i--) {
  176.                             $bp = new BlogPost;
  177.                             $bp->read($posts[$i]);
  178.                             array_push($np, $bp);
  179.                         }
  180.  
  181.                         return $np;
  182.                     }
  183.  
  184.                     function writeBlogPosts($posts) {
  185.                         $i = 1;
  186.  
  187.                         foreach($posts as $post) {
  188.                             echo $post->getHTML($i) . "\n\n";
  189.                             $i++;
  190.                         }
  191.                     }
  192.  
  193.                     $postID = $_GET['id'];
  194.  
  195.                     $conn = mysql_connect($mysql_host, $mysql_user, convert($mysql_pass, "abcdefghijklmnopqrstuvwxyz123456789"));
  196.                     mysql_select_db("a6341707_main");
  197.                     $result = mysql_query("SELECT * FROM blog WHERE id='" . mysql_real_escape_string($postID) . "'");
  198.  
  199.                     $posts = getBlogPosts($result);
  200.                     $np = createBlogPosts($posts);
  201.                     writeBlogPosts($np);
  202.  
  203.                     mysql_close($conn);
  204.                 ?>
  205.  
  206.                 <?php
  207.                     if(getSession("loggedin")) {
  208.                     echo '
  209.                     <div class="article_title_bottom_border" style="margin-bottom: 15px"></div>
  210.                     <div id="new_comment_container">
  211.                         <form method="post">
  212.                             <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;" >
  213. Enter your comment here.
  214.                             </textarea>
  215.                             <br />
  216.                             <input type="submit" name="new_comment_button" value="  Submit  " style="margin-left: 615px;" id="new_comment_button" class="new_comment" />
  217.                         </form>
  218.                     </div> <!-- #new_comment_container -->';
  219.                     } else {
  220.                         echo '
  221.                     <div class="article_title_bottom_border" style="margin-bottom: 15px"></div>
  222.                     <div id="new_comment_container">
  223.                         <label class="not_logged_in">You need to be logged in to post a comment</label>
  224.                         </form>
  225.                     </div> <!-- #new_comment_container -->';
  226.                     }
  227.                 ?>
  228.  
  229.                 <?php
  230.                     require_once("tools/nbbc.php");
  231.                    
  232.                     /*
  233.                     function convert($str, $ky = ''){
  234.                         if($ky == '')
  235.                             return $str;
  236.  
  237.                         $ky = str_replace(chr(32), '', $ky);
  238.  
  239.                         if(strlen($ky) < 8)
  240.                             exit('key error');
  241.  
  242.                         $kl = strlen($ky) < 32 ? strlen($ky) : 32;
  243.                         $k = array();
  244.  
  245.                         for($i = 0; $i < $kl; $i++) {
  246.                             $k[$i] = ord($ky{$i}) & 0x1F;
  247.                         }
  248.  
  249.                         $j=0;
  250.  
  251.                         for($i = 0; $i < strlen($str); $i++) {
  252.                             $e = ord($str{$i});
  253.                             $str{$i} = $e & 0xE0 ? chr($e ^ $k[$j]) : chr($e);
  254.                             $j++;
  255.                             $j = $j == $kl ? 0 : $j;
  256.                         }
  257.                        
  258.                         return $str;
  259.                     }
  260.                     */
  261.  
  262.                     if(isset($_POST['new_comment_button']) && getSession("loggedin") && isset($_POST['new_comment_field'])) {
  263.                         $bbcode = new BBCode;
  264.  
  265.                         $body = $bbcode->Parse($_POST['new_comment_field']);
  266.  
  267.                         $conn = mysql_connect("mysql14.000webhost.com", "a6341707_madsc", convert("Lfheuvt9;9mx}", "abcdefghijklmnopqrstuvwxyz123456789"));
  268.                         mysql_select_db("a6341707_main");
  269.  
  270.                         $today = date("d/m - Y");
  271.                         $result = mysql_query("INSERT INTO blog_comments VALUES('','" . mysql_real_escape_string($body) . "','" . $today . "','" . $_SESSION['currentuser'] . "')");
  272.  
  273.                         $result = mysql_query("SELECT * FROM blog_comments");
  274.  
  275.                         $ids = array();
  276.  
  277.                         while($field = mysql_fetch_assoc($result)) {
  278.                             array_push($ids, $field['id']);
  279.                         }
  280.  
  281.                         $id = max($ids);
  282.  
  283.                         $result = mysql_query("SELECT * FROM blog WHERE id='" . mysql_real_escape_string($_GET['id']) . "'");
  284.  
  285.                         $field = mysql_fetch_assoc($result);
  286.                         $comments = unserialize($field['comments']);
  287.  
  288.                         if($comments[0] == "NO_COMMENTS") {
  289.                             for($i = 0; $i < count($comments); $i++) {
  290.                                 unset($comments[$i]);
  291.                             }
  292.  
  293.                             $comments[0] = $id;
  294.                         } else {
  295.                             array_push($comments, $id);
  296.                         }
  297.  
  298.                         $result = mysql_query("UPDATE blog SET comments='" . serialize($comments) . "' WHERE id='" . mysql_real_escape_string($_GET['id']) . "'");
  299.  
  300.                         mysql_close($conn);
  301.  
  302.                         // get the full url of current page
  303.                         $page = $_SERVER['PHP_SELF'];
  304.                         // find position of the last '/'
  305.                         $file_name_begin_pos = strripos($page, "/");
  306.                         // get substring from position to end
  307.                         $file_name = substr($page, ++$fileNamePos);
  308.  
  309.                         header("Location: /viewblogpost.php?id=" . $_GET['id']);
  310.                     }
  311.                 ?>
Advertisement
Add Comment
Please, Sign In to add comment