├── .DS_Store
├── LICENSE
├── README.md
├── config
└── config.php
├── core
└── init.php
├── create.php
├── helpers
├── .DS_Store
├── db_helper.php
├── format_helper.php
└── system_helper.php
├── images
└── avatars
│ ├── amritms.jpg
│ ├── dprabin.jpg
│ ├── gravatar.jpg
│ └── rkbhushal.jpg
├── index.php
├── libraries
├── .DS_Store
├── Database.php
├── Template.php
├── Topic.php
├── User.php
└── Validator.php
├── login.php
├── logout.php
├── register.php
├── talkingspace.sql
├── templates
├── create.php
├── css
│ ├── bootstrap.css
│ └── custom.css
├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ └── glyphicons-halflings-regular.woff
├── frontpage.php
├── img
│ └── gravatar.jpg
├── includes
│ ├── footer.php
│ └── header.php
├── js
│ ├── bootstrap.js
│ ├── bootstrap.min.js
│ ├── ckeditor
│ │ ├── CHANGES.md
│ │ ├── LICENSE.md
│ │ ├── README.md
│ │ ├── adapters
│ │ │ └── jquery.js
│ │ ├── build-config.js
│ │ ├── ckeditor.js
│ │ ├── config.js
│ │ ├── contents.css
│ │ ├── lang
│ │ │ ├── af.js
│ │ │ ├── ar.js
│ │ │ ├── bg.js
│ │ │ ├── bn.js
│ │ │ ├── bs.js
│ │ │ ├── ca.js
│ │ │ ├── cs.js
│ │ │ ├── cy.js
│ │ │ ├── da.js
│ │ │ ├── de.js
│ │ │ ├── el.js
│ │ │ ├── en-au.js
│ │ │ ├── en-ca.js
│ │ │ ├── en-gb.js
│ │ │ ├── en.js
│ │ │ ├── eo.js
│ │ │ ├── es.js
│ │ │ ├── et.js
│ │ │ ├── eu.js
│ │ │ ├── fa.js
│ │ │ ├── fi.js
│ │ │ ├── fo.js
│ │ │ ├── fr-ca.js
│ │ │ ├── fr.js
│ │ │ ├── gl.js
│ │ │ ├── gu.js
│ │ │ ├── he.js
│ │ │ ├── hi.js
│ │ │ ├── hr.js
│ │ │ ├── hu.js
│ │ │ ├── id.js
│ │ │ ├── is.js
│ │ │ ├── it.js
│ │ │ ├── ja.js
│ │ │ ├── ka.js
│ │ │ ├── km.js
│ │ │ ├── ko.js
│ │ │ ├── ku.js
│ │ │ ├── lt.js
│ │ │ ├── lv.js
│ │ │ ├── mk.js
│ │ │ ├── mn.js
│ │ │ ├── ms.js
│ │ │ ├── nb.js
│ │ │ ├── nl.js
│ │ │ ├── no.js
│ │ │ ├── pl.js
│ │ │ ├── pt-br.js
│ │ │ ├── pt.js
│ │ │ ├── ro.js
│ │ │ ├── ru.js
│ │ │ ├── si.js
│ │ │ ├── sk.js
│ │ │ ├── sl.js
│ │ │ ├── sq.js
│ │ │ ├── sr-latn.js
│ │ │ ├── sr.js
│ │ │ ├── sv.js
│ │ │ ├── th.js
│ │ │ ├── tr.js
│ │ │ ├── tt.js
│ │ │ ├── ug.js
│ │ │ ├── uk.js
│ │ │ ├── vi.js
│ │ │ ├── zh-cn.js
│ │ │ └── zh.js
│ │ ├── plugins
│ │ │ ├── about
│ │ │ │ └── dialogs
│ │ │ │ │ ├── about.js
│ │ │ │ │ ├── hidpi
│ │ │ │ │ └── logo_ckeditor.png
│ │ │ │ │ └── logo_ckeditor.png
│ │ │ ├── clipboard
│ │ │ │ └── dialogs
│ │ │ │ │ └── paste.js
│ │ │ ├── dialog
│ │ │ │ └── dialogDefinition.js
│ │ │ ├── icons.png
│ │ │ ├── icons_hidpi.png
│ │ │ └── link
│ │ │ │ ├── dialogs
│ │ │ │ ├── anchor.js
│ │ │ │ └── link.js
│ │ │ │ └── images
│ │ │ │ ├── anchor.png
│ │ │ │ └── hidpi
│ │ │ │ └── anchor.png
│ │ ├── samples
│ │ │ ├── ajax.html
│ │ │ ├── api.html
│ │ │ ├── appendto.html
│ │ │ ├── assets
│ │ │ │ ├── inlineall
│ │ │ │ │ └── logo.png
│ │ │ │ ├── outputxhtml
│ │ │ │ │ └── outputxhtml.css
│ │ │ │ ├── posteddata.php
│ │ │ │ ├── sample.jpg
│ │ │ │ └── uilanguages
│ │ │ │ │ └── languages.js
│ │ │ ├── datafiltering.html
│ │ │ ├── divreplace.html
│ │ │ ├── index.html
│ │ │ ├── inlineall.html
│ │ │ ├── inlinebycode.html
│ │ │ ├── inlinetextarea.html
│ │ │ ├── jquery.html
│ │ │ ├── plugins
│ │ │ │ ├── dialog
│ │ │ │ │ ├── assets
│ │ │ │ │ │ └── my_dialog.js
│ │ │ │ │ └── dialog.html
│ │ │ │ ├── enterkey
│ │ │ │ │ └── enterkey.html
│ │ │ │ ├── toolbar
│ │ │ │ │ └── toolbar.html
│ │ │ │ └── wysiwygarea
│ │ │ │ │ └── fullpage.html
│ │ │ ├── readonly.html
│ │ │ ├── replacebyclass.html
│ │ │ ├── replacebycode.html
│ │ │ ├── sample.css
│ │ │ ├── sample.js
│ │ │ ├── sample_posteddata.php
│ │ │ ├── tabindex.html
│ │ │ ├── uicolor.html
│ │ │ ├── uilanguages.html
│ │ │ └── xhtmlstyle.html
│ │ ├── skins
│ │ │ └── moono
│ │ │ │ ├── dialog.css
│ │ │ │ ├── dialog_ie.css
│ │ │ │ ├── dialog_ie7.css
│ │ │ │ ├── dialog_ie8.css
│ │ │ │ ├── dialog_iequirks.css
│ │ │ │ ├── editor.css
│ │ │ │ ├── editor_gecko.css
│ │ │ │ ├── editor_ie.css
│ │ │ │ ├── editor_ie7.css
│ │ │ │ ├── editor_ie8.css
│ │ │ │ ├── editor_iequirks.css
│ │ │ │ ├── icons.png
│ │ │ │ ├── icons_hidpi.png
│ │ │ │ ├── images
│ │ │ │ ├── arrow.png
│ │ │ │ ├── close.png
│ │ │ │ ├── hidpi
│ │ │ │ │ ├── close.png
│ │ │ │ │ ├── lock-open.png
│ │ │ │ │ ├── lock.png
│ │ │ │ │ └── refresh.png
│ │ │ │ ├── lock-open.png
│ │ │ │ ├── lock.png
│ │ │ │ └── refresh.png
│ │ │ │ └── readme.md
│ │ └── styles.js
│ └── npm.js
├── register.php
├── topic.php
└── topics.php
├── topic.php
└── topics.php
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/.DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Simple PHP Forum Application
2 |
3 | This is a simple PHP Forum Application created with core PHP. It uses simple Model-View-Controller (MVC) like pattern. This PHP forum Application uses Object Oriented programming to create a forum. It uses PHP Data Object (PDO) to connect to database It supports
4 |
5 | - Creation of forum topic
6 | - Reply message to forum
7 | - User registration
8 |
9 | The controller are the files at root folder of the application. They are
10 |
11 | - index.php: The main controller
12 | - create.php: Controller to create a new forum topic
13 | - register.php: Controller to register a user
14 | - topic.php: Controller to display a forum topic and manage reply to it
15 | - topics.php: Controller to display multiple forum topics
16 |
17 | Models are contained in libraries folder. Classes are defined for each model containing data and methods
18 |
19 | - Database.php: Class used to connect to database
20 | - Template.php: Calss to define and manage template or view
21 | - Topic.php: Class to define the forum topic
22 | - User.php: Class to define the user
23 | - Validator.php: Class to validate different input forms
24 |
25 | The views are inside templates folder. Templates folder contains stylesheets, bootstrap javascripts and CKeditor files.
26 |
27 | The core folder contains initializer code and the config folder contains configuration variables and constants. init.php reads config.php, connects to database and includes other required codes. This file is included in every controller.
28 |
29 | The helpers folder contain helper functions that are needed by the code anywhere else. They are extensively used inside views. User avatar is stored in images/avatars and default avatar is stored in templates/img/.
30 |
31 | To install this applicaion, create a db from talkingspace.sql file. then copy all other files to your htdocs folder and run.
32 |
--------------------------------------------------------------------------------
/config/config.php:
--------------------------------------------------------------------------------
1 |
2 | isRequired($field_array)){
22 | //Create Topic
23 | if($topic->create($data)){
24 | redirect('index.php', 'Your topic has been posted', 'success');
25 | } else {
26 | redirect('topic.php?id='.$topic_id, 'Something went wrong whti your post.', 'error');
27 | }
28 | } else {
29 | redirect('create.php', 'Please fill in all required fields', 'error');
30 | }
31 |
32 | }
33 |
34 | //Get Template and Assign Vars
35 | $template = new Template('templates/create.php');
36 |
37 | //Assign Vars
38 |
39 | //Display template
40 | echo $template;
41 |
42 | ?>
--------------------------------------------------------------------------------
/helpers/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/helpers/.DS_Store
--------------------------------------------------------------------------------
/helpers/db_helper.php:
--------------------------------------------------------------------------------
1 | query('select * from replies where topic_id = :topic_id');
12 | $db->bind(':topic_id',$topic_id);
13 | //Assign rows
14 | $rows = $db->resultset();
15 | //Get Count
16 | return $db->rowCount();
17 | }
18 |
19 | //Get all categories in DB
20 | function getCategories(){
21 | $db=new Database;
22 | $db->query('select * from categories');
23 | //Run query and assign it to results variable
24 | $results = $db->resultset();
25 | //return result
26 | return $results;
27 | }
28 |
29 | //User Post Count
30 | function userPostCount($user_id){
31 | $db = new Database;
32 | $db->query('select * from topics where user_id = :user_id');
33 | $db->bind(':user_id',$user_id);
34 | $rows = $db->resultset();
35 | $topic_count = $db->rowCount();
36 |
37 | $db->query('select * from replies where user_id = :user_id');
38 | $db->bind(':user_id',$user_id);
39 | $rows = $db->resultset();
40 | $reply_count = $db->rowCount();
41 |
42 | return $topic_count + $reply_count;
43 | }
44 |
45 | //Count post by category
46 | function postCountByCategory($category_id){
47 | $db = new Database;
48 | $db->query('select * from topics where category_id = :category_id');
49 | $db->bind(':category_id',$category_id);
50 | $result = $db->resultset();
51 | $category_count = $db->rowCount();
52 | return $category_count;
53 | }
54 |
55 | //Count total number of posts
56 | function totalPostCount(){
57 | $db = new Database;
58 | $db->query('select * from topics where 1');
59 | $result = $db->resultset();
60 | $count = $db->rowCount();
61 | return $count;
62 | }
63 |
64 | ?>
--------------------------------------------------------------------------------
/helpers/format_helper.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/helpers/system_helper.php:
--------------------------------------------------------------------------------
1 | '.$message.'';
37 | } else {
38 | echo '
'.$message.'
';
39 | }
40 | //Unset Message
41 | unset($_SESSION['message']);
42 | unset($_SESSION['message_type']);
43 | } else {
44 | echo '';
45 | }
46 | }
47 | }
48 |
49 | //Check whether user is logged in
50 | function isLoggedIn(){
51 | if(isset($_SESSION['is_logged_in'])){
52 | return true;
53 | } else {
54 | return false;
55 | }
56 | }
57 |
58 | //Get Logged in user information
59 | function getUser(){
60 | $userArray=array();
61 | $userArray['user_id'] = $_SESSION['user_id'];
62 | $userArray['username'] = $_SESSION['username'];
63 | $userArray['name'] = $_SESSION['name'];
64 | return $userArray;
65 | }
66 |
67 | ?>
--------------------------------------------------------------------------------
/images/avatars/amritms.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/images/avatars/amritms.jpg
--------------------------------------------------------------------------------
/images/avatars/dprabin.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/images/avatars/dprabin.jpg
--------------------------------------------------------------------------------
/images/avatars/gravatar.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/images/avatars/gravatar.jpg
--------------------------------------------------------------------------------
/images/avatars/rkbhushal.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/images/avatars/rkbhushal.jpg
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 |
2 | topics = $topic->getAllTopics();
13 | $template->totalTopics = $topic->getTotalTopics();
14 | $template->totalCategories = $topic->getTotalCategories();
15 | $template->totalUsers = $user->getTotalUsers();
16 |
17 | //Display template
18 | echo $template;
19 |
20 | ?>
--------------------------------------------------------------------------------
/libraries/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/libraries/.DS_Store
--------------------------------------------------------------------------------
/libraries/Database.php:
--------------------------------------------------------------------------------
1 | host . ';dbname=' . $this->dbname;
16 | // Set options
17 | $options = array(
18 | PDO::ATTR_PERSISTENT => true,
19 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
20 | );
21 | //Create a new PDO instance
22 | try {
23 | $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
24 | }catch (PDOException $e) { //catch any error of type PDOException
25 | $this->error = $e->getMessage();
26 | }
27 | }
28 |
29 |
30 | public function query($query){
31 | $this->stmt = $this->dbh->prepare($query);
32 | }
33 |
34 |
35 | public function bind($param, $value, $type = null){
36 | if (is_null($type)) {
37 | switch (true) {
38 | case is_int($value):
39 | $type = PDO::PARAM_INT;
40 | break;
41 | case is_bool($value):
42 | $type = PDO::PARAM_BOOL;
43 | break;
44 | case is_null($value):
45 | $type = PDO::PARAM_NULL;
46 | break;
47 | default:
48 | $type = PDO::PARAM_STR;
49 | }
50 | }
51 | $this->stmt->bindValue($param, $value, $type);
52 | }
53 |
54 |
55 | public function execute(){
56 | return $this->stmt->execute();
57 | }
58 |
59 | public function resultset(){
60 | $this->execute();
61 | return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
62 | }
63 |
64 | public function single(){
65 | $this->execute();
66 | return $this->stmt->fetch(PDO::FETCH_ASSOC);
67 | }
68 |
69 | public function rowCount(){
70 | return $this->stmt->rowCount();
71 | }
72 |
73 | public function lastInsertId(){
74 | return $this->dbh->lastInsertId();
75 | }
76 |
77 | public function beginTransaction(){
78 | return $this->dbh->beginTransaction();
79 | }
80 |
81 | public function endTransaction(){
82 | return $this->dbh->commit();
83 | }
84 |
85 | public function cancelTransaction(){
86 | return $this->dbh->rollBack();
87 | }
88 |
89 | public function debugDumpParams(){
90 | return $this->stmt->debugDumpParams();
91 | }
92 | }
93 |
94 |
95 | ?>
96 |
--------------------------------------------------------------------------------
/libraries/Template.php:
--------------------------------------------------------------------------------
1 | template = $template;
15 | }
16 |
17 | //Get template variables
18 | public function __get($key){
19 | return $this->vars[$key];
20 | }
21 |
22 | //Set template variables
23 | public function __set($key, $value){
24 | $this->vars[$key] = $value;
25 | }
26 |
27 | //Convert Object to String
28 | public function __toString(){
29 | extract($this->vars);
30 | chdir(dirname($this->template));
31 | ob_start();
32 |
33 | include basename($this->template);
34 | return ob_get_clean();
35 | }
36 | }
--------------------------------------------------------------------------------
/libraries/Topic.php:
--------------------------------------------------------------------------------
1 | db = new Database;
9 | }
10 |
11 | //Get All Topics
12 | public function getAllTopics(){
13 | $this->db->query("select topics.*, users.username, users.avatar, categories.name from topics inner join users on topics.user_id = users.id inner join categories on topics.category_id = categories.id order by create_date desc");
14 |
15 | //Assign Result Set
16 | $results = $this->db->resultset();
17 | return $results;
18 | }
19 |
20 | //Get Total Number of Topics
21 | public function getTotalTopics(){
22 | $this->db->query('select * from topics');
23 | $rows = $this->db->resultset();
24 | return $this->db->rowCount();
25 | }
26 |
27 | //Get Total Number of Categories
28 | public function getTotalCategories(){
29 | $this->db->query('select * from categories');
30 | $rows = $this->db->resultset();
31 | return $this->db->rowCount();
32 | }
33 |
34 | //Get by Category
35 | public function getByCategory($category_id){
36 | $this->db->query('select topics.*, categories.*, users.username from topics
37 | inner join categories on topics.category_id=categories.id
38 | inner join users on topics.user_id=users.id
39 | where topics.category_id = :category_id');
40 | $this->db->bind(':category_id',$category_id);
41 | $results = $this->db->resultset();
42 | return $results;
43 | }
44 |
45 | //Get Category details
46 | public function getCategory($category_id){
47 | $this->db->query('select * from categories where id = :category_id');
48 | $this->db->bind(':category_id',$category_id);
49 |
50 | //Assign result
51 | $result = $this->db->single();
52 | return $result;
53 | }
54 |
55 | //Get Topic by user ID
56 | public function getByUser($user_id){
57 | $this->db->query("select topics.*, categories.*, users.username,users.avatar from topics
58 | inner join categories on topics.category_id=categories.id
59 | inner join users on topics.user_id=users.id
60 | where topics.user_id = :user_id");
61 | $this->db->bind(':user_id',$user_id);
62 | $results=$this->db->resultset();
63 | return $results;
64 | }
65 |
66 |
67 | //Get Topic By ID
68 | public function getTopic($id){
69 | $this->db->query('select topics.*, users.username, users.name, users.avatar from topics
70 | inner join users on topics.user_id=users.id
71 | where topics.id = :id');
72 | $this->db->bind(':id',$id);
73 |
74 | $row = $this->db->single();
75 | return $row;
76 | }
77 |
78 | //Get replies for the topic
79 | public function getReplies($topic_id){
80 | $this->db->query('select replies.*,users.* from replies
81 | inner join users on replies.user_id=users.id
82 | where replies.topic_id = :topic_id
83 | order by create_date asc');
84 | $this->db->bind(':topic_id',$topic_id);
85 | $rows = $this->db->resultset();
86 | return $rows;
87 | }
88 |
89 | //get total replies
90 | public function getTotalReplies($topic_id){
91 | $this->db->query('select * from replies where topic_id = '.$topic_id);
92 | $rows = $this->db->resultset();
93 | return $this->db->rowCount();
94 | }
95 |
96 | //Create a new topic
97 | public function create($data) {
98 | $this->db->query("insert into topics (category_id,user_id,title,body,last_activity)
99 | values (:category_id,:user_id,:title,:body,:last_activity)");
100 |
101 | $this->db->bind(':category_id',$data['category_id']);
102 | $this->db->bind(':user_id',$data['user_id']);
103 | $this->db->bind(':title',$data['title']);
104 | $this->db->bind(':body',$data['body']);
105 | $this->db->bind(':last_activity',date("Y-m-d H:i:s"));
106 |
107 | if($this->db->execute()){
108 | return true;
109 | } else {
110 | return false;
111 | }
112 | }
113 |
114 | //Reply to a post
115 | public function reply($data){
116 | $this->db->query("insert into replies (topic_id,user_id,body)
117 | values (:topic_id,:user_id,:body)");
118 |
119 | $this->db->bind(':topic_id',$data['topic_id']);
120 | $this->db->bind(':user_id',$data['user_id']);
121 | $this->db->bind(':body',$data['body']);
122 |
123 | if($this->db->execute()){
124 | return true;
125 | } else {
126 | return false;
127 | }
128 | }
129 | }
--------------------------------------------------------------------------------
/libraries/User.php:
--------------------------------------------------------------------------------
1 | db = new Database;
10 | }
11 |
12 | //Register User
13 | public function register($data){
14 | //Query
15 | $this->db->query('insert into users (name, email, avatar, username, password, about, last_activity) values (:name, :email, :avatar, :username, :password, :about, :last_activity)');
16 | //Bind Values
17 | $this->db->bind(':name',$data['name']);
18 | $this->db->bind(':email',$data['email']);
19 | $this->db->bind(':avatar',$data['avatar']);
20 | $this->db->bind(':username',$data['username']);
21 | $this->db->bind(':password',$data['password']);
22 | $this->db->bind(':about',$data['about']);
23 | $this->db->bind(':last_activity',$data['last_activity']);
24 | //Execute
25 | if($this->db->execute()){
26 | return true;
27 | } else {
28 | return false;
29 | }
30 | }
31 |
32 | //Upload User Avatar
33 | public function uploadAvatar(){
34 | $allowedExts = array("gif","jpg","jpeg","png");
35 | $temp = explode(".",$_FILES['avatar']['name']);
36 | $extension = end($temp);
37 |
38 | if((($_FILES['avatar']['type'] == 'image/gif')
39 | || ($_FILES['avatar']['type'] == 'image/jpeg')
40 | || ($_FILES['avatar']['type'] == 'image/jpg')
41 | || ($_FILES['avatar']['type'] == 'image/pjpg')
42 | || ($_FILES['avatar']['type'] == 'image/x-png')
43 | || ($_FILES['avatar']['type'] == 'image/png'))
44 | && ($_FILES['avatar']['size'] < 500000)
45 | && in_array($extension,$allowedExts)) {
46 | if ($_FILES['avatar']['error'] > 0){
47 | redirect('register.php', $_FILES['avatar']['error'],'error');
48 | } else {
49 | if (file_exists("images/avatars/" . $_FILES['avatar']['name'])){
50 | redirect('register.php', 'File already exists','error');
51 | } else {
52 | move_uploaded_file($_FILES['avatar']['tmp_name'], "images/avatars/".$_FILES['avatar']['name']);
53 | return true;
54 | }
55 | }
56 | } else {
57 | redirect('register.php', 'Invalid File Type!','error');
58 | }
59 |
60 | }
61 |
62 | //User login
63 | public function login($username,$password){
64 | $this->db->query('select * from users where username = :username and password = :password');
65 | //Bind values
66 | $this->db->bind('username', $username);
67 | $this->db->bind('password', $password);
68 | $result = $this->db->single();
69 | //check result
70 | if($this->db->rowCount()>0){
71 | $this->setUserData($result);
72 | return true;
73 | } else {
74 | return false;
75 | }
76 | }
77 |
78 | //Set User data
79 | private function setUserData($result){
80 | $_SESSION['is_logged_in']=true;
81 | $_SESSION['user_id']=$result['id'];
82 | $_SESSION['username']=$result['username'];
83 | $_SESSION['name']=$result['name'];
84 | }
85 |
86 | //User Logout
87 | public function logout(){
88 | unset($_SESSION['is_logged_in']);
89 | unset($_SESSION['user_id']);
90 | unset($_SESSION['username']);
91 | unset($_SESSION['name']);
92 | return true;
93 | }
94 |
95 | //Get total number of users
96 | public function getTotalUsers(){
97 | $this->db->query('select * from users');
98 | $result = $this->db->resultset();
99 | return $this->db->rowCount();
100 | }
101 | }
102 | ?>
--------------------------------------------------------------------------------
/libraries/Validator.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/login.php:
--------------------------------------------------------------------------------
1 |
2 | login($username, $password)){
12 | redirect('index.php','You have been logged in.', 'success');
13 | } else {
14 | redirect('index.php','Invalid login', 'error');
15 | }
16 | } else {
17 | redirect('index.php');
18 | }
19 |
20 | ?>
--------------------------------------------------------------------------------
/logout.php:
--------------------------------------------------------------------------------
1 |
2 | logout()){
8 | redirect('index.php','You have been logged out.', 'success');
9 | } else {
10 | redirect('index.php','Something went wrong.', 'error');
11 | }
12 | } else {
13 | redirect('index.php');
14 | }
15 |
16 | ?>
--------------------------------------------------------------------------------
/register.php:
--------------------------------------------------------------------------------
1 |
2 | isRequired($field_array)){
24 | if($validate->isValidEmail($data['email'])){
25 | if($validate->passwordsMatch($data['password'],$data['password2'])){
26 | //Upload Avatar image
27 | if ($user->uploadAvatar()){
28 | $data['avatar'] = $_FILES["avatar"]["name"];
29 | } else {
30 | $data['avatar'] = 'noimage.png';
31 | }
32 |
33 | //Register User
34 | if($user->register($data)){
35 | redirect('index.php', 'You are registered and can now log in','success');
36 | } else {
37 | redirect('register.php', 'Something went wrong with registration','error');
38 | }
39 | } else {
40 | redirect('register.php',"Your Passwords do not match.",'error');
41 | }
42 | } else {
43 | redirect('register.php',"Use a valid email address.",'error');
44 | }
45 | } else {
46 | redirect('register.php',"Please fill in All required fields",'error');
47 | }
48 |
49 |
50 | }
51 |
52 | //Get Template and Assign Vars
53 | $template = new Template('templates/register.php');
54 |
55 | //Assign Vars
56 |
57 | //Display template
58 | echo $template;
59 |
60 | ?>
--------------------------------------------------------------------------------
/templates/create.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
24 |
25 |
--------------------------------------------------------------------------------
/templates/css/custom.css:
--------------------------------------------------------------------------------
1 | body{
2 | padding-top:60px;
3 | background: #f4f4f4;
4 | font-size: 15px;
5 | }
6 |
7 | a{
8 | color:#5c5b69;
9 | }
10 | ul{
11 | padding: 0;
12 | margin:0;
13 | list-style: none;
14 | }
15 | hr{
16 | margin:10px 0 15px 0;
17 | }
18 | h3{
19 | margin-bottom: 5px;
20 | }
21 |
22 | /* Navbar Customization */
23 | .navbar{
24 | height: 40px !important;
25 | background: #5c5b69;
26 | border: 0;
27 | margin-bottom: 30px;
28 | }
29 | .navbar-inverse .navbar-nav > li > a, .navbar-inverse .navbar-brand{
30 | color:#fff !important;
31 | }
32 | .navbar a:hover, .navbar li.active a{
33 | background: none !important;
34 | }
35 | .navbar-brand{
36 | padding: 10px 0 0 0;
37 | color:#fff;
38 | }
39 | .navbar-nav > li > a {
40 | padding:10px 10px 0 10px;
41 | }
42 |
43 | .block{
44 | background: #fff;
45 | border-radius: 5px;
46 | padding: 15px 20px;
47 | margin-bottom:20px;
48 | }
49 |
50 | .main-col{
51 | overflow: auto;
52 | }
53 | .main-col h1{
54 | font-size:22px;
55 | margin: 5px 0 0 0;
56 | padding: 0;
57 | }
58 | .main-col h4{
59 | font-size:16px;
60 | margin: 5px 0 0 0;
61 | padding: 0;
62 | color: #aaa;
63 | }
64 |
65 | .sidebar .block h3{
66 | margin: 0 0 10px 0;
67 | padding-bottom: 10px;
68 | border-bottom: #eee solid 1px;
69 | }
70 |
71 |
72 | .topic{
73 | border-bottom: #eee solid 1px;
74 | margin-bottom: 10px;
75 | padding:10px;
76 | }
77 | .topic-content{
78 | width:100%;
79 | }
80 | img.avatar{
81 | width: 100%;
82 | }
83 |
84 |
85 | a.list-group-item.active, a.list-group-item.active:hover, a.list-group-item.active:focus{
86 | background: #5c5b69;
87 | border-radius: 0;
88 | }
89 | .list-group-item{
90 | border:0;
91 | }
92 |
93 |
94 | #main-topic{
95 | background: #f4f4f4;
96 | padding: 10px;
97 | }
98 |
99 |
100 | .user-info{
101 | border: #ddd solid 1px;
102 | padding:5px;
103 | overflow: hidden;
104 | font-size: 13px;
105 | }
106 | .user-info img{
107 | display: block;
108 | margin-bottom: 5px;
109 | }
110 | .user-info ul{
111 | list-style: none;
112 | margin: 10px 0 0 5px;
113 | }
114 | .user-info li{
115 | line-height: 1.6em;
116 | }
117 |
118 |
119 | .btn-primary{
120 | background:#5c5b69;
121 | }
--------------------------------------------------------------------------------
/templates/fonts/glyphicons-halflings-regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/templates/fonts/glyphicons-halflings-regular.eot
--------------------------------------------------------------------------------
/templates/fonts/glyphicons-halflings-regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/templates/fonts/glyphicons-halflings-regular.ttf
--------------------------------------------------------------------------------
/templates/fonts/glyphicons-halflings-regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/templates/fonts/glyphicons-halflings-regular.woff
--------------------------------------------------------------------------------
/templates/frontpage.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 |

9 |
10 |
11 |
12 |
13 |
14 |
>>
15 |
>>
16 | Posted on:
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | No Topics to Display.
27 |
28 |
29 |
30 | Forum Statistics
31 |
32 | - Total Number of Users:
33 | - Total Number of Topics:
34 | - Total Number of Categories:
35 |
36 |
37 |
--------------------------------------------------------------------------------
/templates/img/gravatar.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dprabin/simple-php-forum-application/0ab7d4d519e943160b4db6584a4e22ab3829948f/templates/img/gravatar.jpg
--------------------------------------------------------------------------------
/templates/includes/footer.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
49 |
50 |
51 |
52 |
53 |