Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

## Summary
n/a

I am glad this is over


23 changes: 23 additions & 0 deletions count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
// Set the current working directory
$directory = getcwd()."/";

// Initialize filecount variable
$story_count = 0;

$files1 = glob( $directory ."story*" );


if( $files1) {
$story_count = count($files1);
$story_count++;
}

$fname1 = "story";
$fname2 = "comment";
$ex = ".txt";
$myfile = fopen($fname1.$story_count.$ex, "w");
$myfile = fopen($fname2.$story_count.$ex, "w");

echo "<br>";
?>
42 changes: 42 additions & 0 deletions create_story.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="story.css">
<title>Submit an article</title>
</head>

<body>
<div class="navbar">
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#logout">logout</a></li>
</ul>
</div>

<h1><center>Submit an article</center></h1>

<div id="poststory">
<?php
$user_data= file("CMPT-241/files/users.txt"); //Get file
for($i = 0; $i < count($user_data); $i++){
$user = explode("|", $user_data[$i]);
$fname = $user[0];
}
?>
<form action="post_story.php" method="post" id="postform">
<input type="hidden" name="user" value="<?php echo $fname;?>">
<input type="hidden" name="date" value="<?php echo date("M d Y");?>">
<label for="title">Title:</label><br>
<input type="text" name="title" form="postform"><br>
Story:<br>
<textarea cols="70" rows="10" name="story" form="postform"></textarea>
<input type="submit">
</form>
</div>

</body>
</html>

17 changes: 17 additions & 0 deletions post_comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=story.php" />
</head>

<?php
$user = $_POST["user"];
$comment = $_POST["comment"];
$date = $_POST["date"];
$to_write = array($user, $comment, $date);
$to_write = implode("\n",$to_write);
file_put_contents("comments.txt", PHP_EOL.$to_write, FILE_APPEND);
echo "Your comment has been posted";
?>

</html>
18 changes: 18 additions & 0 deletions post_story.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=story.php" /> <!-- when integrated return to homepage-->
</head>
<?php
$name = $_POST["user"];
$title = $_POST["title"];
$date = $_POST["date"];
$story = $_POST["story"];
$to_write = array($title, $story, $name, $date);
$to_write = implode("|",$to_write);
file_put_contents("post_story.txt", $to_write);
echo "Your story has been posted";
?>

</html>

76 changes: 76 additions & 0 deletions story.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html>
<head>
<?php
$story_data = file("post_story.txt"); //Get file
for($i = 0; $i < count($story_data); $i++){
$user = explode("|", $story_data[$i]);
$title = $user[0];
$story = $user[1];
$author = $user[2];
$date = $user[3];
}
?>

<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="story.css">
<title><?=$title?></title>
</head>

<body>
<div class="navbar">
<ul>
<li><a href="#home">Home</a></li>
<li><a href="create_story.php">Create an article</a></li> <!-- This was included for testing -->
<li><a href="#logout">logout</a></li>
</ul>
</div>

<h1><center><?=$title?></center></h1>

<h2>Author: <?=$author?></h2>

<h3>Date Posted: <?=$date?></h3>

<div class="story">
<p>
<?php
echo $story;
?>
</p>
</div>

Leave a comment:
<div id="postcomments">
<?php
$user_data= file("CMPT-241/files/users.txt"); //Get file
for($i = 0; $i < count($user_data); $i++){
$user = explode("|", $user_data[$i]);
$fname = $user[0];
}
?>
<form action="post_comment.php" method="post" id="postform">
<input type="hidden" name="user" value="<?php echo $fname;?>">
<input type="hidden" name="date" value="<?php echo date("M d Y");?>">
<textarea cols="40" rows="8" name="comment" form="postform"></textarea>
<input type="submit">
</form>
</div>
Comments
<div class="showcomments">

<?php
$file = fopen("comments.txt","r"); //printing all comments for current story
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>

</div>

</body>
</html>