Giter Club home page Giter Club logo

is4444's Introduction

IS4444 PHP Project

Dave Calnan | 114330306

Site Features

The site is a mockup of a forum where users can create posts and view posts and leave comments.

Users

Users can signup and then login. Places to view users include:

  • Users list - all signed up users, can only be accessed by logged-in users
  • Single user - each user has a page showing a count of their posts, comments and previews of all their posts
  • Post preview - each post preview anywhere on the site shows the user and links to their page
  • Single post - each post shows the user and links to their page

Posts

Anyone can view posts. Logged-in users can view posts. Places to view posts include:

Comments

Anyone can leave a comment. However, if there is a logged in user, their name and email address will be autofilled and the comment will be associated with their unique id. Places to view comments include:

  • Single post - comments can be viewed under each individual post

Site Architecture

Folder Structure

root
│   README.md
│
└───public - All files which are to be accessible by users.
│   │   index.php - Main entrypoint for the site.
│   │
│   └───css - All CSS files.
│   │   │   bulma.css - Bulma CSS framework for layout and basic styling.
│   │   │   main.css - Main CSS stylesheet
│   │
│   └───forms - Scripts for receiving input from forms.
│   │   │   comment.php - Handles post requests for creating comments.
│   │   │   login.php - Handles post requests for authenticating users.
│   │   │   post.php - Handles post requests for creating posts.
│   │   │   signup.php - Handles post requests for creating users.
│   │
│   └───img - Images.
│   │   │   cinema.jpg
│   │
│   └───js - Javascript scripts for adding dynamism.
│       │   main.js - Main javascript script, handles dismissing notifications and toggling nav menu on smaller screens.
│   
└───src - Backend code for the project.
    │   helpers.php - Helpful functions used repeatedly throughout the site.
    │   router.php - Serves the correct response based on the requested path. Also handles authenticated routes.
    │   views.php - Serves the required frontend code.
    │
    └───database - Code relating to interacting with the database.
    │   │   connection.php - Creates the database connection.
    │   │   getters.php - Functions for accessing records from the database.
    │   │   setters.php - Functions for creating records in the database.
    │   │
    └───views - Frontend code creating HTML pages viewed by users.
    │   │   footer.php - Site footer and closing tags.
    │   │   header.php - Opening tags and site header.
    │   │   homepage.php - Site homepage.
    │   │   login.php - Page for logging in.
    │   │   signup.php - Page for signing up.
    │   │   
    │   └───errors - Views for error pages.
    │   │   │   403.php - Error page where access permission is denied.
    │   │   │   404.php - Error page where resource is not found.
    │   │   │   500.php - Error page when there is an itnernal server error.
    │   │
    │   └───posts - Views for interacting with posts.
    │   │   │   create.php - Page for creating a new post.
    │   │   │   index.php - Page listing all posts.
    │   │   │   recent.php - Page listing all posts in recent order.
    │   │   │   single.php - Page showing a single post.
    │   │   │   user.php - Page showing the authenticated user's posts.
    │   │
    │   └───users - Views for interacting with users.
    │       │   index.php - Page showing all registered users.
    │       │   single.php - Page showing a single user, the count of their posts and comments, and showing all of their posts.

Database Structure

Comments Table

  • id: integer, unsigned, auto-increments. A unique identifier for each comment.
  • post_id: integer, unsigned. The unique id of the post on which the comment is made, matching the post's id in the posts table.
  • user_id: integer, unsigned, nullable. If the commenter was logged in, the unique id of that user, matching the user's id in the users table.
  • name: varchar. The name of the commenter, auto-filled if logged in or provided manually.
  • email: varchar. The email of the commenter, auto-filled if logged in or provided manually.
  • body: text. The body of the comment.
  • created_at: datetime. A timestamp of when the comment was made, set using the MySQL NOW() command.

Posts Table

  • id: integer, unsigned, auto-increments. A unique identifier for each post.
  • user_id: integer, unsigned. The unique id of the authenticated user who created the post, matching the user's id in the users table.
  • title: varchar. The title of the post provided.
  • body: text. The body of the post provided.
  • created_at: datetime. A timestamp of when the comment was made, set using the MySQL NOW() command.

Users Table

  • id: integer, unsigned, auto-increments. A unique identifier for each user.
  • name: varchar. The name of the user provided upon signing up.
  • email: varchar. The email of the user provided upon signing up.
  • password: varchar. The password of the user provided upon signing up.

How the site works

For almost all requests, users interact with the public/index.php file.

The src/router.php looks at the path being accessed and if it finds a matching route, it serves the correct response or else responds with a 404 error page.

Most routes respond with a view as handled by the src/views.php file. If a file exists with the name of the requested view, the file will be required. If not, a '404 view not found' message will be shown.

Views can access database records via the src/database/getters.php functions to get the data they need to display.

Submitted forms for either creating posts / comments / users or logging in are accessed directly and sit in the public/forms directory. These make use of the src/database/setters.php functions.

Posts can be created by authenticated users and are associated with the user who creates them via foreign key.

Anyone can leave a comment but if they are logged in, they do not have to provide their name and email address as those are autofilled and the comment will be associated with the user via a foreign key. Every comment is associated with the post it was left on via a foreign key.

is4444's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.