Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function action_post(){
- //update the entry count file
- $fh[4] = fopen("resources/count/entry.txt", 'r');
- $entry_count = intval(fgets($fh[4]));
- fclose($fh[4]);
- unlink("resources/count/entry.txt");
- $fh[4] = fopen("resources/count/entry.txt", 'x');
- fwrite($fh[4], 1+intval($entry_count));
- fclose($fh[4]);
- //create new entry
- $title = $_POST['title'];
- $date = date('l, j/n/Y g:ia');
- $extension = end(explode('.', $_FILES['uploadedimage']['name']));
- $file_location = "resources/entries/images/$entry_count.$extension";
- if(move_uploaded_file($_FILES['uploadedimage']['tmp_name'], $file_location)){
- //echo "succesful";
- $image = $entry_count.".".$extension;
- }else{
- //echo "unsuccesful";
- //echo $_FILES['uploadedimage']['error'];
- $image = "none";
- }
- $body = $_POST['body'];
- $fh[5] = fopen("resources/entries/$entry_count.txt", 'w');
- fwrite($fh[5], "$title\n$date\n$image\n$body");
- fclose($fh[5]);
- mkdir("resources/entries/comments/$entry_count", 0777);
- $fh[11] = fopen("resources/entries/comments/$entry_count/history.txt", 'x');
- fclose($fh[11]);
- $fh[7] = fopen("resources/entries/comments/$entry_count/count.txt", 'x');
- fwrite($fh[7], "0");
- fclose($fh[7]);
- }
- function create_user($enc_user){
- if(!file_exists("users/$enc_user.txt")){
- //create new user file
- //This file is where a record of the users posts are kept
- //this is so they can later be deleted.
- $fh[14] = fopen("users/$enc_user.txt", 'x');
- fclose($fh[14]);
- }
- }
- function display_image(){
- if($_GET['target'] && $_GET['type']){
- $image = "resources/entries/images/".$_GET['target'].".".$_GET['type'];
- if(file_exists($image)){
- //this is basically a page in itself, so all of the includes must be done.
- page_start();
- if($_GET['source']){
- $source = $_GET['source'];
- echo <<<END
- <div onclick="location.href='index.php?entry=$source';" class="container_comments_banner">Back</div>
- <div class="container_no_background">
- <img class="full_image" src="$image">
- </div>
- END;
- }else{
- echo <<<END
- <div class="container_no_background">
- <img class="full_image" src="$image">
- </div>
- END;
- }
- }else{
- page_start();
- echo <<<END
- <div class="container_home_entry">
- <span class="entry_title">FILE DOES NOT EXIST</span>
- </div>
- END;
- }
- }
- }
- function comment_entry(){
- $target = htmlspecialchars(trim($_POST['target']));
- $body = trim(str_replace("\n", "<br>", htmlspecialchars(substr($_POST['body'], 0, 750))));
- $body_md5 = md5($body);
- //make sure that the post does not already exist in this thread.
- $fh[12] = fopen("resources/entries/comments/$target/history.txt", 'r');
- $j = 0;
- while(!feof($fh[12])){
- $history[$j] = trim(fgets($fh[12]));
- $j++;
- }
- fclose($fh[12]);
- if(!in_array($body_md5, $history)){
- $title = nl2br(htmlspecialchars(substr($_POST['title'], 0, 20)));
- $author = nl2br(htmlspecialchars(substr($_POST['author'], 0, 20)));
- $date = date('l, j/n/Y g:ia');
- if(file_exists("resources/entries/comments/$target/count.txt")){
- $fh[8] = fopen("resources/entries/comments/$target/count.txt", 'r');
- $count = 1+intval(trim(fgets($fh[8])));
- fclose($fh[8]);
- unlink("resources/entries/comments/$target/count.txt");
- $fh[9] = fopen("resources/entries/comments/$target/count.txt", 'x');
- fwrite($fh[9], $count);
- fclose($fh[9]);
- $fh[10] = fopen("resources/entries/comments/$target/$count.txt", 'w');
- $string = "$title\n$author\n$date\n$body";
- fwrite($fh[10], $string);
- fclose($fh[10]);
- //write the comment to the history file
- $fh[13] = fopen("resources/entries/comments/$target/history.txt",'a');
- fwrite($fh[13], $body_md5."\n");
- //Update the users 'user' file
- $fh[16] = fopen("users/$enc_user.txt", 'a');
- $string = $target . "_" . $count . "\n";
- fwrite($fh[16], $string);
- fclose($fh[16]);
- }else{
- $comment_fail = 1;
- }
- }else{
- $comment_fail = 1;
- }
- header("Location: http://vrysrs.me/index.php?entry=$target");
- }
- function page_start(){
- /* This will replace the
- include("resources/layouts/header.html");
- include("resources/layouts/main_container.html");
- include("resources/layouts/banner.html");
- sequence
- */
- echo <<<END
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <LINK href="resources/styles/entries.css" rel="stylesheet" type="text/css">
- <link rel="shortcut icon" href="/resources/images/favicon.ico">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>RAWR</title>
- </head>
- <body link="#A40000">
- <div class="container_main">
- <div class="container_banner">
- <a href="http://vrysrs.me">
- <img class="banner_image" src="resources/images/banner.png" border=0>
- </a>
- </div>
- END;
- }
- function display_content($admin){
- //open the current count
- //This will begin to display content to the user.
- $fh[2] = fopen("resources/count/entry.txt",'r');
- $entry_count = intval(fgets($fh[2]));
- fclose($fh[2]);
- page_start();
- if($admin){
- //include("resources/layouts/create_entry.html");
- //Also include the ability to see items in the recycle bin
- /*I'm considering writing this script in the create_entry.php file
- as it would make it easier to display the information
- although this would destroy the centralised paradigm of my website.
- ...Screw it, the create_entry.php will be incorporated into this main .php file
- */
- echo <<<END
- <div class="container_comments_banner">
- Admin Control Panel
- </div>
- <div class="container_admin_controls">
- <div class="container_create_content">
- <span class="entry_title">Create Entry</span><br>
- <form enctype="multipart/form-data" method="post" action="index.php">
- <input name="action" type="hidden" value="post">
- Title:
- <input type="text" name="title" id="title" />
- </br>
- Body (HTML scripting enabled):
- </br>
- <textarea name="body" id="body" cols="45" rows="5"></textarea>
- </br>
- File:
- <input type="hidden" name="MAX_FILE_SIZE" value="300000000000" />
- <input name="uploadedimage" type="file" />
- </br>
- <input type="submit" name="button" id="button" value="Submit" />
- </form>
- </br>
- </div>
- END;
- //Div is not closed yet
- //open the recycle bin directory
- $dir = "resources/entries/recycle/";
- if(is_dir($dir)){
- if($dh = opendir($dir)){
- $c = 0;
- while(($file[$c] = readdir($dh)) !== false){
- $c++;
- //that's a funny looking piece of code, this was taken mainly from php.net, but altered for my needs.
- }
- closedir($dh);
- }
- }
- if(isset($file)){
- echo <<<END
- <div class="container_recycle_bin">
- <span class="entry_title">Recycle Bin</span>
- END;
- $flag = true;
- foreach($file as $key => $value){
- //I could do this as a for loop, but foreach is easier
- //I need to think about how this is going to be formatted visually.
- if(file_exists("resources/entries/recycle/$value")){
- $fh[$key] = fopen("resources/entries/recycle/$value", 'r');
- //Get the entries name, and image
- $title = trim(fgets($fh[$key]));
- $date = trim(fgets($fh[$key]));
- $image = trim(fgets($fh[$key]));
- $entry = explode(".", $value);
- $entry = $entry[0];
- if($image != "none" && $image != ""){
- $flag = false;
- echo <<<END
- <div class="container_recycleBinOptions">
- <img class="small_image" src="resources/entries/images/$image">
- <span class="small_title">$title</span>
- <span class="small_date">$date</span>
- <div class="container_restore_entry"><a href="index.php?entry=$entry&action=restore">restore</a></div>
- <div class="container_delete_entry"><a href="index.php?entry=$entry&action=deleteentry">delete permanently</a></div>
- </div>
- END;
- }elseif($image != ""){
- $flag = false;
- echo <<<END
- <div class="container_recycleBinOptions">
- <span class="small_title">$title</span>
- <span class="small_date">$date</span>
- <div class="container_restore_entry"><a href="index.php?entry=$entry&action=restore">restore</a></div>
- <div class="container_delete_entry"><a href="index.php?entry=$entry&action=deleteentry">delete permanently</a></div>
- </div>
- END;
- }
- fclose($fh[$key]);
- }
- }
- if($flag){
- echo "<div class=\"container_bin_is_empty\">Recycle Bin Is Empty</div>";
- }
- }
- echo <<<END
- </div>
- </div>
- <div class="container_comments_banner">
- Entries
- </div>
- END;
- }
- //display entries
- //display 10 items per page
- if($_GET['page']){
- $page = $_GET['page'];
- }else{
- $page = 1;
- }
- for($i = $entry_count-(($page-1)*10); $i >= 0 && $i > $entry_count-$page*10; $i--){
- if(file_exists("resources/entries/$i.txt")){
- $fh[3] = fopen("resources/entries/$i.txt", 'r');
- echo "<div onclick=\"location.href='index.php?entry=$i';\" class=\"container_home_entry\">";
- $title = trim(fgets($fh[3]));
- $date = trim(fgets($fh[3]));
- $image = trim(fgets($fh[3]));
- echo <<<END
- <span class="entry_title">$title</span>
- <span class="entry_date">$date</span>
- <p class="entry_body">
- END;
- $file = "resources/entries/images/$image";
- if($image != "none" && file_exists($file)){
- echo "<img src=\"$file\" border=0 class=\"entry_image\">\n";
- }
- while(!feof($fh[3])){
- echo trim(nl2br(fgets($fh[3])))."\n";
- }
- echo <<<END
- <a href="index.php?entry=$i">more...</a>
- </p></div>
- END;
- fclose($fh[3]);
- }
- }
- echo "<br>\n";
- if($page > 1){
- $out = $page-1;
- echo "<a href=\"index.php?page=$out\"><img src=\"resources/images/newer.png\" border=0></a>";
- }
- if($entry_count-$page*10 > 0){
- $out = $page+1;
- echo "<a href=\"index.php?page=$out\"><img src=\"resources/images/older.png\" border=0></a>";
- }
- }
- function display_entry($entry, $admin, $user_comments){
- //must remember, if admin is true, they have the ability to delete this post.
- page_start();
- if(file_exists("resources/entries/$entry.txt")){
- //Display the entry
- $fh[3] = fopen("resources/entries/$entry.txt", 'r');
- echo "<div class=\"container_home_entry\">";
- $title = trim(fgets($fh[3]));
- $date = trim(fgets($fh[3]));
- $image = trim(fgets($fh[3]));
- if($admin){
- echo "<div class=\"container_delete_comment\"><a href=\"index.php?entry=$entry&action=recycle\">delete</a></div>\n";
- }
- echo <<<END
- <span class="entry_title">$title</span>
- <span class="entry_date">$date</span>
- <p class="entry_body">
- END;
- $file = "resources/entries/images/$image";
- if($image != "none" && file_exists($file)){
- $explode = explode(".", $image);
- $name = $explode[0];
- $type = $explode[1];
- echo "<a href=\"index.php?action=displayimage&target=$name&type=$type&source=$entry\" target=\"_new\"><img src=\"$file\" border=0 class=\"entry_image\"></a>\n";
- }
- while(!feof($fh[3])){
- echo trim(nl2br(fgets($fh[3])))."\n";
- }
- echo "</p></div>";
- fclose($fh[3]);
- //display the comments
- //comments are contained in "resources/entries/comments/$entry/#.txt"
- //Comments count is contained in "resources/entries/comments/$entry/count.txt"
- $fh[5] = fopen("resources/entries/comments/$entry/count.txt", 'r'); //The amount of comments
- $count = intval(trim(fgets($fh[5])));
- echo "<div class=\"container_comments_banner\">Comments</div>";
- for($i = $count; $i >= 0; $i--){
- $flag = 0;
- $char_count = 0;
- if(file_exists("resources/entries/comments/$entry/$i.txt")){
- $fh[6] = fopen("resources/entries/comments/$entry/$i.txt", 'r');
- //file layout: title \n author \n date \n content
- //Content has a character limit of 50, 50, none, 750 - respectively
- $title = substr(trim(fgets($fh[6])), 0, 50);
- $author = substr(trim(fgets($fh[6])), 0, 50);
- $date = trim(fgets($fh[6]));
- echo <<<END
- <div class="container_comment">
- END;
- if(isset($user_comments[$i]) || $admin == 1){
- //That means that this is the users comment!! :D
- //Display the ability to delete this post
- echo "<div class=\"container_delete_comment\"><a href=\"index.php?entry=$entry&action=delete&comment=$i\">delete</a></div>\n";
- }
- echo "<span class=\"entry_title\">$title - $author</span>\n";
- echo "<span class=\"entry_date\">$date</span><br>\n";
- while(!feof($fh[6]) && $char_count <= 750){
- if($flag == 0){
- echo "<p class=\"entry_body\">";
- }
- $new_line = trim(fgets($fh[6]));
- $char_count += strlen($new_line);
- $print_len = 750-$char_count;
- if((750-$char_count)== 0){
- $print_len = 0;
- }
- echo substr($new_line, 0, $print_len);
- $flag = 1;
- }
- echo "</p></div>\n";
- fclose($fh[6]);
- }
- }
- $entry = $_GET['entry'];
- echo <<<END
- <div class="container_create_comment">
- <form method="post" action="index.php?entry=$entry">
- <span class="entry_title">Write Comment</span>
- <br>
- <input name="action" type="hidden" value="comment">
- <input name="target" type="hidden" value="$entry">
- Title:
- <input type="text" name="title" id="title" />
- Author:
- <input type="text" name="author" id="author" value="Anonymous"/>
- <br>
- Body (750 character limit):
- <br>
- <textarea name="body" id="body" cols="95" rows="6"></textarea>
- <br>
- <input type="submit" name="button" id="button" value="Submit" />
- </form>
- <br>
- </div>
- END;
- }else{
- echo <<<END
- <div class="container_home_entry">
- <span class="entry_title">ENTRY DOES NOT EXIST</span>
- </div>
- END;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment