Project assignment 4. Due Wednesday, April 28th.

For this part of the project you need to implement the following features:

  1. provide forms for users to post and comment
  2. validate the user data and store it in the database. Validation must be done using regular expressions.
  3. display comment threads using a recursive function

For this assignment use your group database. Your account information will be provided to you by e-mail.

Displaying comment threads

Write a recursive function that allows you to display threads of comments (i.e. comments that reply to other comments). The comments must be displayed with proper indentation, i.e. each next level must be indented relative to the previous one (similar to lab 8). You don't have to restrict the number of comments displayed in a page.

The wp_comments table in your database has a post with threads of comments, feel free to add more testing data. A comment that replies to another comment has that comment's ID as in its comment_parent field. Note that it also the post ID in its comment_post_ID field. If a comment is replying directly to the post, its comment_parent is 0.

User posts

Add a form to let the user post a new post. Make sure the form is accessible from the front page (and possibly from other pages, as a part of the menu bar, if any) to let the user post a new post. The post form should require a user to enter the following data:

  1. their login name (this will go away after we implement sessions and login, but we need it for now).
  2. the post subject (can be empty)
  3. the post contents

When the server recieves the data, it must validate it as follows:

  1. Check that the user name is no more than 10 characters long and consists only of valid characters (letters, digits, and underscores). Note that you need to check this before the next step (why?)
  2. Check that the user name exists in the database. You may want to get the user ID as well since you will need it for the post to be added to the database.
  3. Check that the subject is not too long and has only valid characters (you probably want to allow spaces in addition to the symbols in part 1, what else?)
  4. Check that the post message is not too long and not empty. Check that there is no more than three a tags in the post: posts with a large number of links are often spam.
    Some HTML tags should be disallowed - form tag, for instance. You don't need to make a full-proof checking system, just demonstrate how you would allow some tags but not other ones. Write (in comments) what is allowed in posts and what is not allowed.
    Here is the list of all HTML tags.

If the data did not pass validation on any of the counts, display the form with a meaningful error message to the user. Make sure to redisplay all entries that passed the validation so that they don't need to be retyped (we will see an example in class on how to do this).

After the data has been validated you need to add it to the database. Use your group login name and password to connect to the database.

User comments

The user should be able to comment on a post by clicking the "Comment on this" link of the post (you don't need to implement the ability to comment to a comment!). The link should bring the user to a page with a form. Note that you need to pass the post ID (through a GET method) to the comment form. Since you need to pass it further to the php file that handles the comment form, you may either still use the GET method or include it as a hidden field in the form:


<input type="hidden" name="post_id" value="..."

where the value is the post ID. Then you can access it in the php file that handles the form like this: $_POST["post_id"].

The rest of the comment form is similar to the post form. It requires the user to enter (at least):

  1. their login name
  2. the comment contents

You need to check the validity of both (you may use the same functions as you used for validating post data, in this case store the functions in a separate file and include the file in both files that handle forms).

After you have validated the data, store it in the database. Make sure to increment the comment count in the wp_posts table and set the user display name.
Test your forms carefully to make sure that all the data is stored correctly and that the data is validated so that the incorrect data does not get stored. Also make sure that when the user enters incorrect or incomplete data, the form with wrong fields marked is displayed.

Project groups of one

You only need to implement the abilty to post, not to comment. Also, skip validation for three links.

Additional features

All groups of two are required to implement at least two additional features (of your choice) for the final installment; groups of three are required to implement three features. If you are working alone, you don't need to implement any additional features, but youcan for extra credit or in a (pre-approved!) exchange for some of the mandatory ones.
Here are some suggestions:

  1. Post categories - let the user choose a category (out of a pull-down menu?) for their posts and provide a search option to find all posts in a category.
  2. Allow the user to turn off comments for their own post (set comment_status to "close" and check before inserting a comment; you might also just not provide the comment link for such posts)
  3. Allow deleting a post or a comment. Make sure that the correct user login is provided (i.e. a person is allowed to delete only their own posts or comments). When deleting a post, make sure that all its comments are deleted as well.
  4. Threads of comments (the ability to reply to a comment rather than just a post). This is a "lighter" extra feature since most of the functionality of comments threads is included as a requirement. It should be balanced off by a more complex one, or you might want to add the ability to "collapse" comment threads (show just the titles and the user names, and then display the entire comment if the title is clicked).

This page is a part of CSci 1101 course web site.