mad1231999

Untitled

Jan 20th, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.40 KB | None | 0 0
  1. // Check if we need to go back
  2.                     if(!isset($_GET['id'])) {
  3.                         header("Location: /blog.php");
  4.                     }
  5.  
  6.                     function _nl2br($str) {
  7.                         return str_replace("__NEW_LINE__", "<br />", $str);
  8.                     }
  9.  
  10.                     class BlogComment {
  11.                         var $author;
  12.                         var $authorRole;
  13.                         var $authorImagePath;
  14.                         var $body;
  15.                         var $date;
  16.                         var $id;
  17.  
  18.                         function BlogComment() {
  19.                             $this->author = 'Unknown';
  20.                             $this->body = 'Unknown';
  21.                             $this->date = 'Unknown';
  22.                             $this->authorRole = "member";
  23.                             $this->authorImagePath = "/gfx/default_user_icon.png";
  24.                             $this->id = 0;
  25.                         }
  26.  
  27.                         function read($data) {
  28.                             $this->author = $data['author'];
  29.                             $this->date = strip_tags($data['date']);;
  30.                             $this->body = strip_tags($data['body'], "<image><img><div><a><p><ul><li><b><i><u><br><span>");
  31.                             $this->body = stripslashes(_nl2br($this->body));
  32.                             $this->id = strip_tags($data['id']);
  33.  
  34.                             $result = mysql_query("SELECT * FROM users WHERE username='" . mysql_real_escape_string($this->author) . "'");
  35.                             $field = mysql_fetch_assoc($result);
  36.  
  37.                             $this->authorRole = strip_tags($field['role']);
  38.                             $this->authorImagePath = strip_tags($field['prof_pic_path']);
  39.                         }
  40.  
  41.                         function getHTML() {
  42.                             $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";
  43.                        
  44.                             return $str;
  45.                         }
  46.                     }
  47.  
  48.                     class BlogPost {
  49.                         var $author;
  50.                         var $authorRole;
  51.                         var $title;
  52.                         var $body;
  53.                         var $date;
  54.                         var $comments;
  55.                         var $id;
  56.  
  57.                         function BlogPost() {
  58.                             $this->author = 'Unknown';
  59.                             $this->body = 'Unknown';
  60.                             $this->title = 'Unknown';
  61.                             $this->date = 'Unknown';
  62.                             $this->authorRole = "member";
  63.                             $this->comments = array('NO_COMMENTS');
  64.                             $this->id = 0;
  65.                         }
  66.  
  67.                         function read($data) {
  68.                             $this->author = strip_tags($data['author']);
  69.                             $this->body = strip_tags($data['body'], "<image><img><div><a><p><ul><li><b><i><u><br><span>");
  70.                             $this->body = stripslashes(_nl2br($this->body));
  71.                             $this->title = strip_tags($data['title']);
  72.                             $this->comments = unserialize(strip_tags($data['comments']));
  73.                             $this->id = strip_tags($data['id']);
  74.                             $this->date = strip_tags($data['date']);
  75.  
  76.                             $result = mysql_query("SELECT * FROM users WHERE username='" . mysql_real_escape_string($this->author) . "'");
  77.                             $field = mysql_fetch_assoc($result);
  78.  
  79.                             $this->authorRole = strip_tags($field['role']);
  80.                         }
  81.  
  82.                         function getCommentHTML() {
  83.                             $str = "<!-- Comments -->\n";
  84.                            
  85.                             $stack = array();
  86.  
  87.                             foreach($this->comments as $c) {
  88.                                 if($c == 'NO_COMMENTS') {
  89.                                     // echo 'Found "NO_COMMENTS"';
  90.                                     break;
  91.                                 }
  92.  
  93.                                 // echo "COMMENT_ID: " . $c . "<br />";
  94.  
  95.                                 $result = mysql_query("SELECT * FROM blog_comments WHERE id='" . $c . "'");
  96.  
  97.  
  98.                                 while($field = mysql_fetch_assoc($result)) {
  99.                                     // echo "Found a post!\n";
  100.                                     array_push($stack, $field);
  101.                                 }
  102.                             }
  103.  
  104.                             $np = array();
  105.  
  106.                             for($i = 0; $i < count($stack); $i++) {
  107.                                 $bp = new BlogComment;
  108.                                 $bp->read($stack[$i]);
  109.  
  110.                                 echo "<!-- COMMENT #" . $i . "\n" . $bp->getHTML() . "\n-->";
  111.  
  112.                                 $str = $str . "\n" . $bp->getHTML();
  113.                             }
  114.  
  115.                             return $str;
  116.                         }
  117.  
  118.                         function getHTML() {
  119.                             $top = '';
  120.                        
  121.                             if($i == 1) {
  122.                                 $top = 'style="position: relative; top: -20px;"';
  123.                             }
  124.  
  125.                             $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();
  126.  
  127.                             return $str;
  128.                         }
  129.                     }
  130.  
  131.                     function convert($str, $ky = ''){
  132.                         if($ky == '')
  133.                             return $str;
  134.  
  135.                         $ky = str_replace(chr(32), '', $ky);
  136.  
  137.                         if(strlen($ky) < 8)
  138.                             exit('key error');
  139.  
  140.                         $kl = strlen($ky) < 32 ? strlen($ky) : 32;
  141.                         $k = array();
  142.  
  143.                         for($i = 0; $i < $kl; $i++) {
  144.                             $k[$i] = ord($ky{$i}) & 0x1F;
  145.                         }
  146.  
  147.                         $j=0;
  148.  
  149.                         for($i = 0; $i < strlen($str); $i++) {
  150.                             $e = ord($str{$i});
  151.                             $str{$i} = $e & 0xE0 ? chr($e ^ $k[$j]) : chr($e);
  152.                             $j++;
  153.                             $j = $j == $kl ? 0 : $j;
  154.                         }
  155.                        
  156.                         return $str;
  157.                     }
  158.  
  159.                     function getBlogPosts($result) {
  160.                         $stack = array();
  161.  
  162.                         while($field = mysql_fetch_assoc($result)) {
  163.                             // echo "Found a post!\n";
  164.                             array_push($stack, $field);
  165.                         }
  166.  
  167.                         return $stack;
  168.                     }
  169.  
  170.                     function createBlogPosts($posts) {
  171.                         $np = array();
  172.  
  173.                         for($i = count($posts) - 1; $i >= 0; $i--) {
  174.                             $bp = new BlogPost;
  175.                             $bp->read($posts[$i]);
  176.                             array_push($np, $bp);
  177.                         }
  178.  
  179.                         return $np;
  180.                     }
  181.  
  182.                     function writeBlogPosts($posts) {
  183.                         $i = 1;
  184.  
  185.                         foreach($posts as $post) {
  186.                             echo $post->getHTML() . "\n\n";
  187.                             $i++;
  188.                         }
  189.                     }
  190.  
  191.                     $postID = $_GET['id'];
  192.  
  193.                     $conn = mysql_connect(wuthost, wutusername, wutpassword));
  194.                     mysql_select_db(wutdbname);
  195.                     $result = mysql_query("SELECT * FROM blog WHERE id='" . mysql_real_escape_string($postID) . "'");
  196.  
  197.                     $posts = getBlogPosts($result);
  198.                     $np = createBlogPosts($posts);
  199.                     writeBlogPosts($np);
  200.  
  201.                     mysql_close($conn);
  202.                 ?>
  203.  
  204.                 <?php
  205.                     if($_SESSION['loggedin']) {
  206.                     echo '
  207.                     <div class="article_title_bottom_border" style="margin-bottom: 15px"></div>
  208.                     <div id="new_comment_container">
  209.                         <form method="post">
  210.                             <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;" >
  211. Enter your comment here.
  212.                             </textarea>
  213.                             <br />
  214.                             <input type="submit" name="new_comment_button" value="  Submit  " style="margin-left: 615px;" id="new_comment_button" class="new_comment" />
  215.                         </form>
  216.                     </div> <!-- #new_comment_container -->';
  217.                     } else {
  218.                         echo '
  219.                     <div class="article_title_bottom_border" style="margin-bottom: 15px"></div>
  220.                     <div id="new_comment_container">
  221.                         <label class="not_logged_in">You need to be logged in to post a comment</label>
  222.                         </form>
  223.                     </div> <!-- #new_comment_container -->';
  224.                     }
Advertisement
Add Comment
Please, Sign In to add comment