ClarkeRubber

Index.php

Dec 24th, 2011
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.82 KB | None | 0 0
  1. <?php
  2. include("resources/functions/main_functions.php");
  3. /*
  4. BEGIN MAIN PROGRAM
  5. BEGIN MAIN PROGRAM
  6. BEGIN MAIN PROGRAM
  7. */
  8. putenv("TZ=Australia/Sydney"); //set local time. At a later point in time, I may make an installation process for this webservice.
  9. //------ DETERMINE THE USER
  10. $user = $_SERVER['REMOTE_ADDR'];
  11. //open the users file
  12. $fh[1] = fopen("users/admin.txt", 'r');
  13. $admin = fgets($fh[1], 4096);
  14. fclose($fh[1]);
  15. $enc_user = md5(sha1($user));
  16. //Determine who the user is
  17. if($enc_user == $admin){
  18.     create_user($enc_user); //even though they are the admin, this process is still useful
  19.     //determine what the admin wants to do
  20.     if($_POST['action']){
  21.         $action = $_POST['action'];
  22.         if($action == "post"){
  23.             //if the admin wants to create a new entry
  24.             action_post();
  25.         }
  26.         if($action == "comment"){
  27.             comment_entry();
  28.         }
  29.     }
  30.     if($_GET['action']){
  31.         $action = $_GET['action'];
  32.         //if the user wants to delete their comment
  33.         if($action == "delete"){
  34.             $entry = $_GET['entry'];
  35.             $comment = $_GET['comment'];
  36.             if(file_exists("resources/entries/comments/$entry/$comment.txt")){
  37.                 unlink("resources/entries/comments/$entry/$comment.txt");
  38.             }
  39.             header("Location: http://vrysrs.me/index.php?entry=$entry");
  40.         }
  41.         if($action == "recycle"){
  42.             //Basically move the latter mentioned entry to the recycle bin, where it can later be removed permanently
  43.             $entry = $_GET['entry'];
  44.             if(file_exists("resources/entries/$entry.txt")){
  45.                 rename("resources/entries/$entry.txt", "resources/entries/recycle/$entry.txt");
  46.             }
  47.             header("Location: http://vrysrs.me");
  48.             //That's basically it, the rest will be handled else-where
  49.             //That works, now to write the bit which allows the entry to be restored
  50.         }
  51.         if($action == "restore"){
  52.             $entry = $_GET['entry'];
  53.             if(file_exists("resources/entries/recycle/$entry.txt")){
  54.                 rename("resources/entries/recycle/$entry.txt", "resources/entries/$entry.txt");
  55.             }
  56.             header("Location: http://vrysrs.me/index.php?entry=$entry");
  57.             //Again this is very simple because that's all it needs to be
  58.             //Actually deleting is a larger process as it needs to be completed thoroughly
  59.         }
  60.         if($action == "deleteentry"){
  61.             $entry = $_GET['entry'];
  62.             if(file_exists("resources/entries/recycle/$entry.txt")){
  63.                 //Proceed to delete entry
  64.                 /*Btw, if you're wandering, not much checking has to go on here.
  65.                 The user has already been signed on as being the admin.*/
  66.                 if(($fh[18] = fopen("resources/entries/recycle/$entry.txt", 'r')) !== false){
  67.                     //move to the third line in the file where the image name is stored
  68.                     for($i = 0; $i < 3; $i++){
  69.                         //for loop because Marin would want me to
  70.                         $image = trim(fgets($fh[18]));
  71.                     }
  72.                     if($image !== "none"){
  73.                         unlink("resources/entries/images/$image");
  74.                         //No confirmation here because 'whatcha gunna do?'
  75.                     }
  76.                 }
  77.                 fclose($fh[18]);
  78.                 unlink("resources/entries/recycle/$entry.txt");
  79.                 if(file_exists("resources/entries/comments/$entry/count.txt")){
  80.                     //begin deleting comments
  81.                     $fh[19] = fopen("resources/entries/comments/$entry/count.txt", 'r');
  82.                     $count = trim(fgets($fh[19]));
  83.                     fclose($fh[19]);
  84.                     unlink("resources/entries/comments/$entry/count.txt");
  85.                     for($i = 1; $i <= $count; $i++){
  86.                         if(file_exists("resources/entries/comments/$entry/$i.txt")){
  87.                             unlink("resources/entries/comments/$entry/$i.txt");
  88.                         }
  89.                         //it's nice to be able to write code which wont generate any E_level warnings
  90.                     }
  91.                 }
  92.                 if(file_exists("resources/entries/comments/$entry/history.txt")){
  93.                     unlink("resources/entries/comments/$entry/history.txt");
  94.                 }
  95.                 rmdir("resources/entries/comments/$entry/");
  96.             }
  97.             header('location: http://vrysrs.me');
  98.         }
  99.         if($action == "displayimage"){
  100.             display_image();
  101.         }
  102.     }
  103.     if($_GET['entry'] && $action != "deleteentry" && $action != "displayimage"){
  104.         $entry = $_GET['entry'];
  105.         display_entry($entry, 1, 0);
  106.     }elseif($action != "displayimage"){
  107.         display_content(1);
  108.     }
  109. }else{
  110.     //if not admin, aka they are a user
  111.     //Determine if the user exists in our database
  112.     create_user();
  113.     //welcome, you are now a user of the the system.
  114.     //Load a record of the users comments... even if they just joined the system, it's easier that way
  115.     //array structure: $user_comments[<entry>][<comment number>]
  116.     $fh[15] = fopen("users/$enc_user.txt", 'r');
  117.     while(!feof($fh[15])){
  118.         $line = explode("_", trim(fgets($fh[15])));
  119.         $user_comments[$line[0]][$line[1]] = 1;
  120.     }
  121.     if($_POST['action']){
  122.         $action = $_POST['action'];
  123.         if($action == "comment"){
  124.             comment_entry();
  125.         }
  126.     }
  127.     if($_GET['action']){
  128.         $action = $_GET['action'];
  129.         //if the user wants to delete their comment
  130.         if($action == "delete"){
  131.             //Determine what the user wants to delete
  132.             $entry = $_GET['entry'];
  133.             $comment = $_GET['comment'];
  134.             //Determine who the user is and what they have permission to delete
  135.             $fh[17] = fopen("users/$enc_user.txt", 'r');
  136.             while(!feof($fh[17])){
  137.                 $line = explode("_", trim(fgets($fh[17])));
  138.                 $user_comments[$line[0]][$line[1]] = 1;
  139.             }
  140.             fclose($fh[17]);
  141.             if($user_comments[$entry][$comment] == 1){
  142.                 //if the user has permission to delete the file, delete it.
  143.                 if(file_exists("resources/entries/comments/$entry/$comment.txt")){
  144.                     unlink("resources/entries/comments/$entry/$comment.txt");
  145.                 }
  146.             }
  147.         }
  148.         if($action == "displayimage"){
  149.             display_image();
  150.         }
  151.     }
  152.     if($action != "displayimage"){
  153.         if($_GET['entry']){
  154.             //Display the main content
  155.             $entry = $_GET['entry'];
  156.             display_entry($entry, 0, $user_comments[$entry]);
  157.         }else{
  158.             //By default, display the homepage.
  159.             display_content(0);
  160.         }
  161.     }
  162.     //echo "Your IP is: $user <br> $enc_user";
  163. }
  164. $date = date('Y');
  165. echo <<<END
  166. <br>
  167. <span class="footer">&copy; James Clarke $date
  168. <br>
  169. <br>
  170. </span>
  171. </div>
  172. </body>
  173. </html>
  174. END;
  175. ?>
Advertisement
Add Comment
Please, Sign In to add comment