Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include("resources/functions/main_functions.php");
- /*
- BEGIN MAIN PROGRAM
- BEGIN MAIN PROGRAM
- BEGIN MAIN PROGRAM
- */
- putenv("TZ=Australia/Sydney"); //set local time. At a later point in time, I may make an installation process for this webservice.
- //------ DETERMINE THE USER
- $user = $_SERVER['REMOTE_ADDR'];
- //open the users file
- $fh[1] = fopen("users/admin.txt", 'r');
- $admin = fgets($fh[1], 4096);
- fclose($fh[1]);
- $enc_user = md5(sha1($user));
- //Determine who the user is
- if($enc_user == $admin){
- create_user($enc_user); //even though they are the admin, this process is still useful
- //determine what the admin wants to do
- if($_POST['action']){
- $action = $_POST['action'];
- if($action == "post"){
- //if the admin wants to create a new entry
- action_post();
- }
- if($action == "comment"){
- comment_entry();
- }
- }
- if($_GET['action']){
- $action = $_GET['action'];
- //if the user wants to delete their comment
- if($action == "delete"){
- $entry = $_GET['entry'];
- $comment = $_GET['comment'];
- if(file_exists("resources/entries/comments/$entry/$comment.txt")){
- unlink("resources/entries/comments/$entry/$comment.txt");
- }
- header("Location: http://vrysrs.me/index.php?entry=$entry");
- }
- if($action == "recycle"){
- //Basically move the latter mentioned entry to the recycle bin, where it can later be removed permanently
- $entry = $_GET['entry'];
- if(file_exists("resources/entries/$entry.txt")){
- rename("resources/entries/$entry.txt", "resources/entries/recycle/$entry.txt");
- }
- header("Location: http://vrysrs.me");
- //That's basically it, the rest will be handled else-where
- //That works, now to write the bit which allows the entry to be restored
- }
- if($action == "restore"){
- $entry = $_GET['entry'];
- if(file_exists("resources/entries/recycle/$entry.txt")){
- rename("resources/entries/recycle/$entry.txt", "resources/entries/$entry.txt");
- }
- header("Location: http://vrysrs.me/index.php?entry=$entry");
- //Again this is very simple because that's all it needs to be
- //Actually deleting is a larger process as it needs to be completed thoroughly
- }
- if($action == "deleteentry"){
- $entry = $_GET['entry'];
- if(file_exists("resources/entries/recycle/$entry.txt")){
- //Proceed to delete entry
- /*Btw, if you're wandering, not much checking has to go on here.
- The user has already been signed on as being the admin.*/
- if(($fh[18] = fopen("resources/entries/recycle/$entry.txt", 'r')) !== false){
- //move to the third line in the file where the image name is stored
- for($i = 0; $i < 3; $i++){
- //for loop because Marin would want me to
- $image = trim(fgets($fh[18]));
- }
- if($image !== "none"){
- unlink("resources/entries/images/$image");
- //No confirmation here because 'whatcha gunna do?'
- }
- }
- fclose($fh[18]);
- unlink("resources/entries/recycle/$entry.txt");
- if(file_exists("resources/entries/comments/$entry/count.txt")){
- //begin deleting comments
- $fh[19] = fopen("resources/entries/comments/$entry/count.txt", 'r');
- $count = trim(fgets($fh[19]));
- fclose($fh[19]);
- unlink("resources/entries/comments/$entry/count.txt");
- for($i = 1; $i <= $count; $i++){
- if(file_exists("resources/entries/comments/$entry/$i.txt")){
- unlink("resources/entries/comments/$entry/$i.txt");
- }
- //it's nice to be able to write code which wont generate any E_level warnings
- }
- }
- if(file_exists("resources/entries/comments/$entry/history.txt")){
- unlink("resources/entries/comments/$entry/history.txt");
- }
- rmdir("resources/entries/comments/$entry/");
- }
- header('location: http://vrysrs.me');
- }
- if($action == "displayimage"){
- display_image();
- }
- }
- if($_GET['entry'] && $action != "deleteentry" && $action != "displayimage"){
- $entry = $_GET['entry'];
- display_entry($entry, 1, 0);
- }elseif($action != "displayimage"){
- display_content(1);
- }
- }else{
- //if not admin, aka they are a user
- //Determine if the user exists in our database
- create_user();
- //welcome, you are now a user of the the system.
- //Load a record of the users comments... even if they just joined the system, it's easier that way
- //array structure: $user_comments[<entry>][<comment number>]
- $fh[15] = fopen("users/$enc_user.txt", 'r');
- while(!feof($fh[15])){
- $line = explode("_", trim(fgets($fh[15])));
- $user_comments[$line[0]][$line[1]] = 1;
- }
- if($_POST['action']){
- $action = $_POST['action'];
- if($action == "comment"){
- comment_entry();
- }
- }
- if($_GET['action']){
- $action = $_GET['action'];
- //if the user wants to delete their comment
- if($action == "delete"){
- //Determine what the user wants to delete
- $entry = $_GET['entry'];
- $comment = $_GET['comment'];
- //Determine who the user is and what they have permission to delete
- $fh[17] = fopen("users/$enc_user.txt", 'r');
- while(!feof($fh[17])){
- $line = explode("_", trim(fgets($fh[17])));
- $user_comments[$line[0]][$line[1]] = 1;
- }
- fclose($fh[17]);
- if($user_comments[$entry][$comment] == 1){
- //if the user has permission to delete the file, delete it.
- if(file_exists("resources/entries/comments/$entry/$comment.txt")){
- unlink("resources/entries/comments/$entry/$comment.txt");
- }
- }
- }
- if($action == "displayimage"){
- display_image();
- }
- }
- if($action != "displayimage"){
- if($_GET['entry']){
- //Display the main content
- $entry = $_GET['entry'];
- display_entry($entry, 0, $user_comments[$entry]);
- }else{
- //By default, display the homepage.
- display_content(0);
- }
- }
- //echo "Your IP is: $user <br> $enc_user";
- }
- $date = date('Y');
- echo <<<END
- <br>
- <span class="footer">© James Clarke $date
- <br>
- <br>
- </span>
- </div>
- </body>
- </html>
- END;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment