├── .gitignore
├── README.md
├── sql
└── mvc_db.sql
└── src
├── .htaccess
├── config
└── config.php
├── controller
├── About.php
├── Auth.php
├── Category.php
├── Contact.php
├── Dashboard.php
├── Home.php
└── Navbar.php
├── index.php
├── info.php
├── lib
├── Application.php
├── Controller.php
├── Database.php
├── Debug.php
├── File.php
├── Helper.php
├── Message.php
├── Model.php
├── Session.php
└── View.php
├── model
├── About_Model.php
├── Auth_Model.php
├── Category_Model.php
├── Contact_Model.php
├── Dashboard_Model.php
├── Home_Model.php
└── Navbar_Model.php
├── partial
├── debug.php
├── footer.php
├── footer_end.php
├── footer_essentials.php
├── header.php
├── message.php
├── navbar.php
└── sidebar.php
├── public
├── css
│ ├── main.css
│ ├── main.css.map
│ ├── main.scss
│ └── styles.css
├── img
│ ├── default.jpg
│ └── header-bg.jpg
├── js
│ ├── pagination.js
│ ├── scripts.js
│ └── validation.js
└── lib
│ ├── bootstrap
│ ├── bootstrap.css
│ └── bootstrap.min.js
│ ├── jquery
│ ├── jquery-3.1.1.min.js
│ └── jquery.min.js
│ ├── popper
│ └── popper.min.js
│ └── tinymce
│ ├── skins
│ └── lightgray
│ │ ├── content.inline.min.css
│ │ ├── content.min.css
│ │ ├── content.mobile.min.css
│ │ ├── fonts
│ │ ├── tinymce-mobile.woff
│ │ ├── tinymce-small.eot
│ │ ├── tinymce-small.svg
│ │ ├── tinymce-small.ttf
│ │ ├── tinymce-small.woff
│ │ ├── tinymce.eot
│ │ ├── tinymce.svg
│ │ ├── tinymce.ttf
│ │ └── tinymce.woff
│ │ ├── img
│ │ ├── anchor.gif
│ │ ├── loader.gif
│ │ ├── object.gif
│ │ └── trans.gif
│ │ ├── skin.min.css
│ │ └── skin.mobile.min.css
│ ├── themes
│ ├── inlite
│ │ └── theme.min.js
│ ├── mobile
│ │ └── theme.min.js
│ └── modern
│ │ └── theme.min.js
│ └── tinymce-4.8.1.min.js
├── uploads
└── images
│ └── 2018
│ └── 09
│ ├── 14
│ ├── 1536913237-9845-thumb.jpg
│ ├── 1536913237-9845.jpg
│ ├── 1536913290-2706-thumb.jpg
│ ├── 1536913290-2706.jpg
│ ├── 1536913366-496-thumb.jpg
│ ├── 1536913366-496.jpg
│ ├── 1536913444-6969-thumb.jpg
│ ├── 1536913444-6969.jpg
│ ├── 1536913542-2102-thumb.jpg
│ ├── 1536913542-2102.jpg
│ ├── 1536913621-853-thumb.jpg
│ ├── 1536913621-853.jpg
│ ├── 1536913750-4448-thumb.jpg
│ ├── 1536913750-4448.jpg
│ ├── 1536913812-1393-thumb.jpg
│ ├── 1536913812-1393.jpg
│ ├── 1536913867-9338-thumb.jpg
│ ├── 1536913867-9338.jpg
│ ├── 1536913916-1177-thumb.jpg
│ ├── 1536913916-1177.jpg
│ ├── 1536913959-433-thumb.jpg
│ ├── 1536913959-433.jpg
│ ├── 1536914158-4046-thumb.jpg
│ ├── 1536914158-4046.jpg
│ ├── 1536914198-2443-thumb.jpg
│ ├── 1536914198-2443.jpg
│ ├── 1536914235-9919-thumb.jpg
│ ├── 1536914235-9919.jpg
│ ├── 1536914287-4434-thumb.jpg
│ ├── 1536914287-4434.jpg
│ ├── 1536914350-9139-thumb.jpg
│ ├── 1536914350-9139.jpg
│ ├── 1536914403-733-thumb.jpg
│ ├── 1536914403-733.jpg
│ ├── 1536914458-6646-thumb.jpg
│ ├── 1536914458-6646.jpg
│ ├── 1536914627-6200-thumb.jpg
│ ├── 1536914627-6200.jpg
│ ├── 1536914686-1449-thumb.jpg
│ ├── 1536914686-1449.jpg
│ ├── 1536914771-9762-thumb.jpg
│ ├── 1536914771-9762.jpg
│ ├── 1536916312-385-thumb.jpg
│ ├── 1536916312-385.jpg
│ ├── 1536916346-337-thumb.jpg
│ └── 1536916346-337.jpg
│ └── 18
│ ├── 1537266729-4155-thumb.jpg
│ └── 1537266729-4155.jpg
└── view
├── about
└── index.php
├── auth
├── login.php
└── register.php
├── category
├── show.php
└── showAll.php
├── contact
└── index.php
├── dashboard
├── add.php
├── allUserPosts.php
├── allUsers.php
├── category.php
├── edit.php
├── editProfile.php
└── view.php
└── home
└── index.php
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Ignore .idea folder
3 |
4 | .idea/
5 | /docs
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PHP CMS – Blog
2 |
3 | > This project is a university task 👨🎓
4 |
5 | ## Task
6 | Create a CMS with own Fronted and Backend using PHP & MYSQL. The Website should have multiple pages and some private pages that can be only accessed when logged in. The logged in user should be able to do all CRUD functionalities with the posts. Make sure the data are persistent and stored in the database.
7 |
8 | ## Blog Features
9 |
10 | * Image upload Drag & Drop
11 | * Categories
12 | * Comments
13 | * CRUD Functionality
14 | * Form Validation
15 | * Pagination
16 | * Register/Login
17 | * Responsive Design
18 | * Search
19 | * Text Limit for Blogpost Preview
20 | * Text Styling with TinyMCE
21 | * User Ban-System
22 | * User Management (Admin, Editor...)
23 | * User Profile Editing (Read & Update) with individual User Images
24 |
--------------------------------------------------------------------------------
/src/.htaccess:
--------------------------------------------------------------------------------
1 | RewriteEngine On
2 |
3 | RewriteCond %{REQUEST_FILENAME} !-d
4 | RewriteCond %{REQUEST_FILENAME} !-f
5 | RewriteCond %{REQUEST_FILENAME} !-l
6 |
7 | # Comment
8 | RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
9 |
--------------------------------------------------------------------------------
/src/config/config.php:
--------------------------------------------------------------------------------
1 | view->render('about/index');
9 | }
10 |
11 | }
--------------------------------------------------------------------------------
/src/controller/Auth.php:
--------------------------------------------------------------------------------
1 | model->getUserFromEmail($user['email']);
12 |
13 | // Save all emails
14 | $error = array();
15 |
16 | //Validate Email
17 | if (!filter_var($user['email'], FILTER_VALIDATE_EMAIL)) {
18 | $error['email_err'] = 'Not a valid mail';
19 | }
20 |
21 | // Check if Mail already exists
22 | if ($userEntry) {
23 | $error['email_err'] = 'E-Mail already exists';
24 | }
25 |
26 | // Validate Name
27 | if(empty($user['firstname'])){
28 | $error['name_err'] = 'Please enter first name';
29 | }
30 |
31 | // Validate Name
32 | if(empty($user['lastname'])){
33 | $error['lastname_err'] = 'Please enter last name';
34 | }
35 |
36 | // Validate Password
37 | if(empty($user['password'])){
38 | $error['password_err'] = 'Please enter password';
39 | } elseif(strlen($user['password']) < 6){
40 | $error['password_err'] = 'Password must be at least 6 characters';
41 | }
42 |
43 | // Validate Confirm Password
44 | if(empty($user['confirm_password'])){
45 | $error['confirm_password_err'] = 'Please confirm password';
46 | } else {
47 | if($user['password'] != $user['confirm_password']){
48 | $error['confirm_password_err'] = 'Passwords do not match';
49 | }
50 | }
51 |
52 | // Check for error - if no error register
53 | if($error) {
54 | $this->view->error = $error;
55 | $this->view->formData = $user;
56 |
57 | $this->view->render('auth/register');
58 | } else {
59 | Message::add('You are registered and can now log in');
60 | $this->model->registerUser($user);
61 |
62 | // Change location (goto login)
63 | header('Location: ' . URL . 'auth/login');
64 | }
65 |
66 | }
67 |
68 | public function doLogin() {
69 | //Get credentials from POST
70 | $user = $_POST;
71 |
72 | // Init data
73 | $user['email'] = trim($user['email']);
74 | $user['password'] = trim($user['password']);
75 |
76 | // Empty check
77 | if(empty($user['email']) || empty($user['password'])) {
78 | $this->view->email_err = 'Filling out the form would be a good start';
79 | return $this->login();
80 | }
81 |
82 | // Adds +1 to the login attempts if login is false
83 | $this->model->recordLoginAttempt($user['email']);
84 |
85 | // Get User Entry, Check if exists & Verify Password
86 | $userEntry = $this->model->loginUser($user);
87 |
88 | // Checking user entry + attempted logins
89 | if($userEntry && $userEntry['login_attempts'] < MAXIMUM_LOGINS) {
90 | Session::set('user', $userEntry);
91 | Session::set('user_image', $userEntry['image']);
92 |
93 | // Resets login attempts to 0 if login successfull
94 | $resetAttempts = $this->model->resetLoginAttempts($user['email']);
95 | header('Location: ' . URL . 'home');
96 | return;
97 | }
98 |
99 | // Gets the attempted logins from the Database
100 | $checkLoginAttempts = $this->model->checkLoginAttempts($user['email']);
101 |
102 | // Check if login Attempts exceeded max logins.
103 | if($checkLoginAttempts >= MAXIMUM_LOGINS) {
104 | $this->view->email_err = 'Contact Admin. You\'re blocked.';
105 | return $this->login();
106 | }
107 |
108 | $this->view->email_err = 'Username or Password wrong.';
109 | $this->login();
110 | }
111 |
112 | public function logout() {
113 | // Remove userEntry from Session
114 | Session::remove('user');
115 | session_destroy();
116 |
117 | // Change location (goto home)
118 | header('Location: ' . URL . 'home');
119 | }
120 |
121 | # *****************
122 | # Render functions
123 | # *****************
124 |
125 | public function login() {
126 | $this->view->render('auth/login');
127 | }
128 |
129 | public function register() {
130 | //Render register view
131 | $this->view->render('auth/register');
132 | }
133 |
134 | public function index() {
135 | $this->view->render('auth/register');
136 | }
137 |
138 | }
--------------------------------------------------------------------------------
/src/controller/Category.php:
--------------------------------------------------------------------------------
1 | model->getPostsByCategoryId($id, $search);
15 | $this->view->posts = $result;
16 |
17 | $this->view->render('category/showAll');
18 | }
19 |
20 |
21 | # **********************
22 | # Comment functionality
23 | # **********************
24 |
25 | public function insertComment() {
26 | $comment = $_POST;
27 | # Split URL to get Id parameter
28 | $getId = explode("/", $_GET['url']);
29 | $postId = $getId[2];
30 | # User input into comment field
31 | $user_comment = $comment['user_comment'];
32 |
33 | $this->model->userComment($user_comment, $postId);
34 |
35 | # Redirect to same page after comment has been submitted
36 | header("Location: " . URL . "category/show/$postId");
37 | }
38 |
39 | # ************************
40 | # Show Post Functionality
41 | # ************************
42 |
43 | public function show($id) {
44 | # Get all Data needed for post
45 | $data = $this->model->getPostById($id);
46 | $comments = $this->model->getAllCommentsById($id);
47 |
48 | # Passing it into the view
49 | $this->view->data = $data;
50 | $this->view->comments = $comments;
51 |
52 | $this->view->render('category/show');
53 | }
54 |
55 | # ************************
56 | # Standard Index Render
57 | # ************************
58 |
59 | public function index() {
60 | $this->view->render('category/digitalminimalism');
61 | }
62 |
63 | }
--------------------------------------------------------------------------------
/src/controller/Contact.php:
--------------------------------------------------------------------------------
1 | view->render('contact/index');
6 | }
7 | }
--------------------------------------------------------------------------------
/src/controller/Dashboard.php:
--------------------------------------------------------------------------------
1 | model->addPost($category_id, $userId, $post_header, $post_content, $uploadedFile);
18 |
19 | Message::add('Perfect! New post has been added to your blog');
20 |
21 | header('Location: ' . URL . 'dashboard/add');
22 | }
23 |
24 | # Rendering the add Page - Only accessible if Admin status
25 | public function add() {
26 | if(Session::get('user')['permission'] == "Admin") {
27 | $data = $this->model->getCategories();
28 | $this->view->data = $data;
29 | $this->view->render('dashboard/add');
30 | } else {
31 | header('Location: ' . URL . 'dashboard');
32 | }
33 | }
34 |
35 | # ****************
36 | # User Management
37 | # ****************
38 |
39 | public function allUsers() {
40 | $allPermissions = $this->model->getAllPermissions();
41 | $allUsers = $this->model->getAllUsers();
42 | $this->view->allUsers = $allUsers;
43 | $this->view->allPermissions = $allPermissions;
44 | $this->view->render('dashboard/allUsers');
45 | }
46 |
47 | public function unbanUser() {
48 | $userEmail = explode("/", $_GET["url"]);
49 | $this->model->unbanUser($userEmail[2]);
50 | header("Location: " . URL . "dashboard/allUsers");
51 | }
52 |
53 | public function banUser() {
54 | $userEmail = explode("/", $_GET["url"]);
55 | $this->model->banUser($userEmail[2]);
56 | header("Location: " . URL . "dashboard/allUsers");
57 | }
58 |
59 | public function updatePermission() {
60 | $permission = $_POST['permission_id'];
61 | $userEmail = explode("/", $_GET["url"]);
62 | $this->model->updatePermission($permission ,$userEmail[2]);
63 | header("Location: " . URL . "dashboard/allUsers");
64 | }
65 |
66 | # **********************
67 | # Category functionality
68 | # ***********************
69 |
70 | public function category() {
71 | if(!(Session::get('user'))) {
72 | header("Location: " . URL . "home");
73 | } else {
74 | $this->view->render('dashboard/category');
75 |
76 | }
77 | }
78 |
79 | public function addCategory() {
80 | $getCategory = $_POST['category'];
81 | $this->model->insertCategory($getCategory);
82 | header("Location: " . URL . "dashboard/category");
83 | }
84 |
85 | # ******************
86 | # Edit User Profile
87 | # ******************
88 |
89 | public function editProfile() {
90 | if(!(Session::get('user'))) {
91 | Header("Location: " . URL . "home");
92 | } else {
93 | $userEmail = Session::get('user')['email'];
94 | $userImgThumb = Session::get('user')['thumb'];
95 |
96 | $userData = $this->model->getUserFromEmail($userEmail);
97 | $this->view->userData = $userData;
98 | $this->view->userImg = $userImgThumb;
99 | $this->view->render('dashboard/editProfile');
100 | }
101 | }
102 |
103 | public function doUpdateUser() {
104 | $post = $_POST;
105 | $post_firstname = $_POST['firstname'];
106 | $user = Session::get('user');
107 | $user_id = $user['id'];
108 | $post_lastname = $_POST['lastname'];
109 | $post_email = $_POST['email'];
110 | $post_password = $_POST['password'];
111 | $file_id = $_POST['file_id'];
112 | $new_foto = $_FILES['new_foto'];
113 | $userEmail = $user['email'];
114 | $userData = $this->model->getUserFromEmail($userEmail);
115 | $this->view->userData = $userData;
116 |
117 | if (!$new_foto['error']) {
118 |
119 | $uploadedFile = File::uploadImg($new_foto);
120 |
121 | if(!empty($user['image'])) {
122 | File::delete($user['thumb']);
123 | File::delete($user['image']);
124 | }
125 |
126 | if($user['file_id'] === NULL) {
127 | $this->model->uploadUserImage($user_id, $uploadedFile);
128 | } else {
129 | $this->model->updateFile($file_id, $uploadedFile);
130 | }
131 | }
132 |
133 | $this->view->post = $post;
134 | $this->model->editProfile($user_id, $post_firstname, $post_lastname, $post_email, $post_password);
135 | $updatedUser = $this->model->getUserById($user['id']);
136 | // Debug::add($updatedUser);
137 | Session::set("user", $updatedUser);
138 | // $this->view->render('dashboard/editProfile');
139 | header('Location: ' . URL . 'dashboard/editProfile');
140 | }
141 |
142 | # *************************************
143 | # CRUD Functionality for View Posts
144 | # *************************************
145 |
146 | public function view() {
147 | if(!(Session::get('user'))) {
148 | Header("Location: " . URL . "home");
149 | } else {
150 | $posts = $this->model->getPosts();
151 | $this->view->posts = $posts;
152 | $this->view->render('dashboard/view');
153 | }
154 | }
155 |
156 | public function edit($id) {
157 | if(!(Session::get('user'))) {
158 | Header("Location: " . URL . "home");
159 | } else {
160 | $posts = $this->model->getPostById($id);
161 | $this->view->posts = $posts;
162 | $this->view->render('dashboard/edit');
163 | }
164 | }
165 |
166 | public function doEdit($id) {
167 | $post = $_POST;
168 | $posts = $this->model->getPostById($id);
169 | $post['id'] = $id;
170 | $post['header'] = trim($post['header']);
171 | $post['content'] = trim($post['content']);
172 | $file_id = $_POST['file_id'];
173 | $new_foto = $_FILES['new_foto'];
174 |
175 | if(empty($post['header']) || empty($post['content'])) {
176 | $this->view->post_err = 'Please fill out the complete form';
177 | return $this->edit();
178 | }
179 |
180 | if (!$new_foto['error']) {
181 | $uploadedFile = File::uploadImg($new_foto);
182 |
183 | File::delete($posts[0]->thumb);
184 | File::delete($posts[0]->image);
185 |
186 | $this->model->updateFile($file_id, $uploadedFile);
187 | }
188 |
189 | $this->view->post = $post;
190 | $this->model->updatePost($post);
191 | Message::add('Post updated');
192 |
193 | header('Location: ' . URL . 'home');
194 | }
195 |
196 | public function delete($id) {
197 | $post = $this->model->getPostById($id);
198 | $file_id = $post[0]->file_id;
199 |
200 | $this->model->deleteFile($file_id);
201 | $this->model->deletePost($id);
202 | File::delete($post[0]->image);
203 | File::delete($post[0]->thumb);
204 |
205 | Message::add('Post deleted', 'danger');
206 | header('Location: ' . URL . 'home');
207 | }
208 |
209 | public function allUserPosts() {
210 | $allPosts = $this->model->getPostsByEmail();
211 | $this->view->allPosts = $allPosts;
212 | $this->view->render('dashboard/allUserPosts');
213 | }
214 |
215 | public function index() {
216 | if(!(Session::get('user'))) {
217 | Header("Location: " . URL . "home");
218 | } else {
219 | $this->view();
220 | }
221 | }
222 | }
--------------------------------------------------------------------------------
/src/controller/Home.php:
--------------------------------------------------------------------------------
1 | model->getPosts();
10 |
11 | $this->view->post = $data;
12 | $this->view->render('home/index');
13 | }
14 |
15 | }
--------------------------------------------------------------------------------
/src/controller/Navbar.php:
--------------------------------------------------------------------------------
1 | model->getAllCategories();
6 | $newCategories = array();
7 |
8 | foreach($categories as $category) {
9 | $newCategories[$category['id']] = $category['category_name'];
10 | }
11 |
12 | Session::set('categories', $newCategories);
13 | Session::set('activeCategory', 'null');
14 | }
15 |
16 | public function index () {
17 | // Nothing to do here
18 | }
19 | }
--------------------------------------------------------------------------------
/src/index.php:
--------------------------------------------------------------------------------
1 | loadModel();
25 | $navbarController->initCategories();
26 |
27 | //------------------------------------------------------
28 | // Autoload controller
29 |
30 | $file = 'controller/' . $url[0] . '.php';
31 | if (file_exists($file)) {
32 | require $file;
33 | } else {
34 | echo "(404) No \"$url[0]\" controller found
";
35 | }
36 |
37 | $controller = new $url[0];
38 |
39 |
40 |
41 | //------------------------------------------------------
42 | // Load a Model (if exists)
43 | $controller->loadModel();
44 |
45 | //------------------------------------------------------
46 | // Calling Controller-Methods
47 | if (isset($url[2])) {
48 | if (method_exists($controller, $url[1])) {
49 | $controller->{$url[1]}($url[2]);
50 | } else {
51 | echo "Echo calling method with param $url[1]($url[2])";
52 | }
53 | } else {
54 | if (isset($url[1])) {
55 | if (method_exists($controller, $url[1])) {
56 | $controller->{$url[1]}();
57 | } else {
58 | echo "Error calling method $url[1]()
";
59 | }
60 | }
61 | }
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 | //---------------------------------------------------------
74 | // Rendering
75 | $controller->index();
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | }
84 |
85 | }
--------------------------------------------------------------------------------
/src/lib/Controller.php:
--------------------------------------------------------------------------------
1 | view = new View();
11 |
12 | Session::set('controller_name', get_class($this));
13 | }
14 |
15 | public function loadModel() {
16 |
17 | $model_name = get_class($this) . '_Model';
18 | $model_file = 'model/' . $model_name . '.php';
19 |
20 | // Load a Model-File only if it exists
21 | if (file_exists($model_file)) {
22 | require $model_file;
23 | $this->model = new $model_name;
24 | }
25 |
26 | }
27 |
28 | //TODO make function index abstract
29 | //abstract function index();
30 |
31 | }
--------------------------------------------------------------------------------
/src/lib/Database.php:
--------------------------------------------------------------------------------
1 | getMessage();
18 | }
19 |
20 | }
21 |
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/src/lib/Debug.php:
--------------------------------------------------------------------------------
1 | $img_ratio){
75 | $thumb_height = $height;
76 | $thumb_width = (int) $height * $img_ratio;
77 | } else {
78 | $thumb_height = (int) $width / $img_ratio;
79 | $thumb_width = $width;
80 | }
81 |
82 | $gd_thumb = imagecreatetruecolor($thumb_width, $thumb_height);
83 |
84 | imagecopyresampled($gd_thumb, $gd_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $img_width, $img_height);
85 | imagejpeg($gd_thumb, $thumb_path, 90);
86 |
87 | imagedestroy($gd_img);
88 | imagedestroy($gd_thumb);
89 |
90 | return true;
91 | }
92 |
93 | /**
94 | * Get type of an image
95 | * @access private
96 | * @param string $tempImgFile
97 | * @return string
98 | * @since 1.0.0
99 | * @author nbe
100 | */
101 | private static function getImgType($tempImgFile){
102 | list( , , $tempImgFile) = getimagesize($tempImgFile);
103 | switch($tempImgFile){
104 | case IMAGETYPE_GIF:
105 | return '.gif';
106 | case IMAGETYPE_ICO:
107 | return '.ico';
108 | case IMAGETYPE_JPEG:
109 | return '.jpg';
110 | case IMAGETYPE_PNG:
111 | return '.png';
112 | default:
113 | return false;
114 | }
115 | }
116 |
117 | /**
118 | * Move Uploaded File
119 | * @access public
120 | * @param string $file
121 | * @param string $destination
122 | * @return bool
123 | * @since 1.0.0
124 | * @author nbe
125 | */
126 | public static function moveUploadedFile($file, $destination){
127 | return (boolean) move_uploaded_file($file, $destination);
128 | }
129 |
130 | /**
131 | * Delete file
132 | * @access public
133 | * @param string $file
134 | * @return bool
135 | * @since 1.0.0
136 | * @author nbe
137 | */
138 | public static function delete($file) {
139 | return (boolean) unlink($file);
140 | }
141 |
142 | /**
143 | * Upload Img
144 | * @access public
145 | * @param array $fileArray
146 | * @param string $path
147 | * @param array $thumb
148 | * @return mixed
149 | * @since 1.0.0
150 | * @author nbe
151 | */
152 | public static function uploadImg($fileArray, $path = '', array $thumb = array(IMAGE_THUMB_WIDTH, IMAGE_THUMB_HEIGHT)) {
153 |
154 | $temp_img_id = $fileArray['name'];
155 | $temp_img_file = $fileArray['tmp_name'];
156 | $temp_img_type = '.'.explode('.', $temp_img_id)[1];
157 | $temp_img_size = $fileArray['size'];
158 |
159 | $img_name = time().'-'.rand(100,9999);
160 | $img_type = self::getImgType($temp_img_file);
161 |
162 | if (!$img_type && !$temp_img_type)
163 | $img_type = IMAGE_DEFAULT_EXT;
164 | else
165 | $img_type = $temp_img_type;
166 |
167 | $inner_path = implode('/', explode('/', $path)).'/';
168 | $coded_path = self::createDateCodedPath();
169 | $img_dir = IMAGE_UPLOADS_PATH."{$inner_path}{$coded_path}";
170 |
171 | $img_path = "{$img_dir}{$img_name}{$img_type}";
172 | $thumb_path = "{$img_dir}{$img_name}".IMAGE_THUMB_EXT."{$img_type}";
173 |
174 | // TODO: ForLoop if more then one thumb-size
175 | if (!empty($thumb)) {
176 | $thumb_height = $thumb[1];
177 | $thumb_width = $thumb[0];
178 | }
179 |
180 | if (!self::createFolder($img_dir))
181 | $error['upload'] = _('Missing User-Rights');
182 | if (!self::moveUploadedFile($temp_img_file, $img_path))
183 | $error['upload'] = _('Error while uploading file');
184 | if (empty($thumb) && !self::createImgThumbnail($img_path, $thumb_path, $thumb_width, $thumb_height) || !empty($thumb) && !self::createImgThumbnail($img_path, $thumb_path, $thumb_width, $thumb_height))
185 | $error['upload'] = _('Error while generating Thumbnails');
186 |
187 | if (!isset($error))
188 | return array('name' => $temp_img_id, 'image' => $img_path, 'thumb' => $thumb_path, 'size' => $temp_img_size);
189 | else {
190 | return false;
191 | }
192 |
193 |
194 | }
195 |
196 |
197 | }
--------------------------------------------------------------------------------
/src/lib/Helper.php:
--------------------------------------------------------------------------------
1 | ";
7 | var_dump($data);
8 | echo "";
9 | }
10 |
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/src/lib/Message.php:
--------------------------------------------------------------------------------
1 | $text, 'class' => $class, 'time' => $now, 'duration' => $duration));
11 |
12 | Session::set('allMessages', $allMessages);
13 | }
14 |
15 | public static function getAll() {
16 | return (Session::get('allMessages')) ? Session::get('allMessages') : array();
17 | }
18 |
19 | public static function remove($index) {
20 | $allMessages = self::getAll();
21 |
22 | unset($allMessages[$index]);
23 |
24 | Session::set('allMessages', $allMessages);
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/src/lib/Model.php:
--------------------------------------------------------------------------------
1 | db = new Database();
10 |
11 | }
12 |
13 | }
--------------------------------------------------------------------------------
/src/lib/Session.php:
--------------------------------------------------------------------------------
1 | rendered) {
12 |
13 | //Prevent double rendering
14 | $this->rendered = true;
15 |
16 | require 'partial/header.php';
17 |
18 | require 'partial/navbar.php';
19 |
20 | require 'partial/message.php';
21 |
22 | require 'view/' . $name . '.php';
23 |
24 | if(Session::get('controller_name') !== 'Dashboard') {
25 | require 'partial/footer.php';
26 | }
27 |
28 | // Check DEBUG_MODE (config)
29 | if (DEBUG_MODE) {
30 | //Draw Debug-View
31 | require 'partial/debug.php';
32 | }
33 |
34 | require 'partial/footer_essentials.php';
35 |
36 | }
37 |
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/src/model/About_Model.php:
--------------------------------------------------------------------------------
1 | db->prepare($sql);
15 |
16 | $obj->execute(array(
17 | 'firstname' => $user['firstname'],
18 | 'lastname' => $user['lastname'],
19 | 'email' => $user['email'],
20 | 'password' => $user['password']
21 | ));
22 | }
23 |
24 | public function loginUser($user) {
25 |
26 | //Get userEntry from DB
27 | $userEntry = $this->getUserFromEmail($user['email']);
28 |
29 | //Check if user exists (and early return if not)
30 | if (!$userEntry) return false;
31 |
32 | //Get password and hash
33 | $password = $user['password'];
34 | $hash = $userEntry['password'];
35 |
36 | //Remove hashed password from $userEntry
37 | unset($userEntry['password']);
38 |
39 | //Add users fullname to $userEntry
40 | $userEntry['fullname'] = $userEntry['firstname'] . ' ' . $userEntry['lastname'];
41 |
42 | //Verify password
43 | if (password_verify($password, $hash)) return $userEntry;
44 |
45 | //Otherwise return false
46 | return false;
47 | }
48 |
49 | public function getUserFromEmail($email) {
50 | $sql = 'SELECT user.*, user_permission.permission, file.thumb, file.image FROM user
51 | LEFT JOIN user_permission ON permission_id = user_permission.id
52 | LEFT JOIN file ON file_id = file.id WHERE email = :email LIMIT 1';
53 |
54 | $obj = $this->db->prepare($sql);
55 |
56 | $obj->execute(array(
57 | 'email' => $email
58 | ));
59 |
60 | $result = $obj->fetch(PDO::FETCH_ASSOC);
61 |
62 | return $result;
63 | }
64 |
65 | public function recordLoginAttempt($email) {
66 | # +1 login attempts on every false password input
67 | $sql = 'UPDATE user SET login_attempts = login_attempts + 1 WHERE email = :email ';
68 | $obj = $this->db->prepare($sql);
69 |
70 | $result = $obj->execute(array(
71 | 'email' => $email
72 | ));
73 |
74 | return $result;
75 | }
76 |
77 | public function resetLoginAttempts($email) {
78 | # if login correct reset attempts to 0
79 | $sql = 'UPDATE user SET login_attempts = 0 WHERE email = :email';
80 | $obj = $this->db->prepare($sql);
81 |
82 | $result = $obj->execute(array(
83 | 'email' => $email
84 | ));
85 |
86 | return $result;
87 | }
88 |
89 | public function checkLoginAttempts($email) {
90 | # Check login attempts and see if exceeded the amount of false logins
91 | $sql = 'SELECT login_attempts FROM user WHERE email = :email';
92 |
93 | $obj = $this->db->prepare($sql);
94 |
95 | $obj->execute(array(
96 | 'email' => $email
97 | ));
98 |
99 | if($obj->rowCount() > 0) {
100 | $result = $obj->fetch(PDO::FETCH_ASSOC);
101 | return $result['login_attempts'];
102 | }
103 |
104 | return false;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/model/Category_Model.php:
--------------------------------------------------------------------------------
1 | db->prepare($sql);
15 |
16 | $obj->execute();
17 |
18 | if ($obj->rowCount() > 0) {
19 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
20 | return $data;
21 | }
22 |
23 | return false;
24 | }
25 |
26 | // public function searchFunction($post_id = null, $search = null) {
27 | // $sql1 = 'SELECT user.firstname, user.lastname, file.image, file.thumb, category.category_name, posts.*
28 | // FROM user
29 | // JOIN posts
30 | // ON user.id = posts.user_id
31 | // JOIN file
32 | // ON file.id = posts.file_id
33 | // JOIN category
34 | // ON category.id = posts.category_id';
35 |
36 | // $sql2 = ' WHERE post.id = :id ';
37 |
38 | // // Always needed!
39 | // $sql3 = 'GROUP BY posts.id;';
40 |
41 | // // Concat $sql1 and $sql3
42 | // $sql = $sql1 . $sql3;
43 |
44 | // $excute_array = array();
45 |
46 | // if ($post_id) {
47 | // $sql = $sql1 . $sql2 . $sql3;
48 |
49 | // $excute_array = array(
50 | // ':id' => $post_id
51 | // );
52 | // }
53 |
54 | // if ($search) {
55 | // $sql = $sql1 . " WHERE posts.header LIKE :search " . $sql3;
56 | // $excute_array = array(
57 | // ':search' => '%'.$search.'%'
58 | // );
59 | // }
60 |
61 | // $obj = $this->db->prepare($sql);
62 |
63 | // $result = $obj->execute($excute_array);
64 |
65 | // Debug::add($result, '$result');
66 |
67 | // if ($result) {
68 | // $data = $obj->fetchAll(PDO::FETCH_OBJ);
69 | // return $data;
70 | // }
71 |
72 | // return false;
73 | // }
74 |
75 | public function getPostById($id) {
76 | $sql = 'SELECT user.firstname, user.lastname, file.image, file.thumb, category.category_name, posts.*
77 | FROM user
78 | JOIN posts
79 | ON user.id = posts.user_id
80 | JOIN file
81 | ON file.id = posts.file_id
82 | JOIN category
83 | ON category.id = posts.category_id WHERE posts.id = :id';
84 |
85 | $obj = $this->db->prepare($sql);
86 |
87 | $obj->execute(array(
88 | ":id" => $id
89 | ));
90 |
91 | if($obj->rowCount() > 0) {
92 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
93 | return $data;
94 | }
95 |
96 | return false;
97 | }
98 |
99 | public function getPostsByCategoryId($id, $search) {
100 | $sql = 'SELECT user.firstname, user.lastname, file.image, file.thumb, category.category_name, posts.*
101 | FROM user
102 | JOIN posts
103 | ON user.id = posts.user_id
104 | JOIN file
105 | ON file.id = posts.file_id
106 | JOIN category
107 | ON category.id = posts.category_id
108 | WHERE category.id = :id AND posts.header LIKE :search';
109 |
110 | $obj = $this->db->prepare($sql);
111 |
112 | $result = $obj->execute(array(
113 | ":id" => $id,
114 | ':search' => '%'.$search.'%'
115 | ));
116 |
117 | if ($result) {
118 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
119 | return $data;
120 | }
121 |
122 | return false;
123 | }
124 |
125 | // public function getPostsByCategory($category) {
126 | // $sql = 'SELECT user.firstname, user.lastname, file.image, file.thumb, category.category_name, posts.*
127 | // FROM user
128 | // JOIN posts
129 | // ON user.id = posts.user_id
130 | // JOIN file
131 | // ON file.id = posts.file_id
132 | // JOIN category
133 | // ON category.id = posts.category_id
134 | // WHERE category.category_name = :category';
135 |
136 | // $obj = $this->db->prepare($sql);
137 |
138 | // $obj->execute(array(
139 | // ":category" => $category
140 | // ));
141 |
142 | // if ($obj->rowCount() > 0) {
143 | // $data = $obj->fetchAll(PDO::FETCH_OBJ);
144 | // return $data;
145 | // }
146 |
147 | // return false;
148 | // }
149 |
150 | # **********************
151 | # Comment feature SQL
152 | # **********************
153 |
154 | public function getAllCommentsById($id) {
155 | $sql = 'SELECT
156 | USER.firstname,
157 | USER.lastname,
158 | comments.*
159 | FROM
160 | comments
161 | LEFT JOIN USER ON USER.id = comments.user_id
162 | WHERE post_id = :post_id';
163 |
164 | $obj = $this->db->prepare($sql);
165 |
166 | $obj->execute(array(
167 | ":post_id" => $id
168 | ));
169 |
170 | if ($obj->rowCount() > 0) {
171 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
172 | return $data;
173 | }
174 |
175 | return false;
176 | }
177 |
178 | public function userComment($user_comment, $postId) {
179 | $sql = 'INSERT INTO comments(comment_content, user_id, post_id) VALUES (:comment_content, :user_id, :post_id)';
180 | $obj = $this->db->prepare($sql);
181 | $obj->execute(array(
182 | ":comment_content" => $user_comment,
183 | ':user_id' => Session::get('user')['id'],
184 | ":post_id" => $postId
185 | ));
186 | }
187 |
188 | }
--------------------------------------------------------------------------------
/src/model/Contact_Model.php:
--------------------------------------------------------------------------------
1 | db->prepare($sql);
9 |
10 | $result1 = $obj->execute(array(
11 | ':name' => $uploadedFile['name'],
12 | ':image' => $uploadedFile['image'],
13 | ':thumb' => $uploadedFile['thumb'],
14 | ':size' => $uploadedFile['size'],
15 | ));
16 |
17 | // Remember the id of the new file entry
18 | $file_id = $this->db->lastInsertId();
19 |
20 |
21 | // 2. Step: insert Post ----------------------------------------------------------------------------------------------
22 |
23 | $sql = 'INSERT INTO posts(header, content, user_id, file_id, category_id) VALUES (:header, :content, :user_id, :file_id, :category_id)';
24 |
25 | $obj = $this->db->prepare($sql);
26 |
27 | $result2 = $obj->execute(array(
28 | ":header" => $post_header,
29 | ":content" => $post_content,
30 | ":user_id" => $userId,
31 | ":file_id" => $file_id,
32 | ":category_id" => $category_id,
33 | ));
34 |
35 | return $result1 && $result2;
36 | }
37 |
38 | public function uploadUserImage($userId, $uploadedFile) {
39 | // 1. Step: insert File ----------------------------------------------------------------------------------------------
40 | $sql = 'INSERT INTO file (name, image, thumb, size) VALUES (:name, :image, :thumb, :size)';
41 |
42 | $obj = $this->db->prepare($sql);
43 |
44 | $result1 = $obj->execute(array(
45 | ':name' => $uploadedFile['name'],
46 | ':image' => $uploadedFile['image'],
47 | ':thumb' => $uploadedFile['thumb'],
48 | ':size' => $uploadedFile['size'],
49 | ));
50 |
51 | // Remember the id of the new file entry
52 | $file_id = $this->db->lastInsertId();
53 |
54 | // 2. Step: insert Post ----------------------------------------------------------------------------------------------
55 |
56 | $sql = "UPDATE user SET file_id = :file_id WHERE id = :id";
57 |
58 | $obj = $this->db->prepare($sql);
59 |
60 | $result2 = $obj->execute(array(
61 | ":id" => $userId,
62 | ":file_id" => $file_id,
63 | ));
64 |
65 | return $result1 && $result2;
66 | }
67 |
68 | public function updateFile($file_id, $file) {
69 | $sql = 'UPDATE file SET name=:name, image=:image, thumb=:thumb, size=:size WHERE id=:file_id';
70 |
71 | $obj = $this->db->prepare($sql);
72 |
73 | $result = $obj->execute(array(
74 | ':file_id' => $file_id,
75 | ':name' => $file['name'],
76 | ':image' => $file['image'],
77 | ':thumb' => $file['thumb'],
78 | ':size' => $file['size'],
79 | ));
80 |
81 | // Return result
82 | return $result;
83 | }
84 |
85 | // public function updateUser($user) {
86 | // $password = $user['password'];
87 | // $hashPassword = password_hash($password, PASSWORD_DEFAULT);
88 | // $user['password'] = $hashPassword;
89 |
90 | // $sql = "UPDATE user SET firstname = :firstname, lastname = :lastname, email = :email, password = :password WHERE id = :id";
91 | // $obj = $this->db->prepare($sql);
92 |
93 | // $obj->execute(array(
94 | // ":firstname" => $user['firstname'],
95 | // ":lastname" => $user['lastname'],
96 | // ":email" => $user['email'],
97 | // ":email" => $user['email'],
98 | // ":password" => $user['password'],
99 | // ":id" => Session::get('user')['id']
100 | // ));
101 |
102 | // }
103 |
104 |
105 | public function editProfile($user_id, $post_firstname, $post_lastname, $post_email, $post_password) {
106 |
107 | $sql = "UPDATE user SET firstname = :firstname, lastname = :lastname, email = :email WHERE id = :id";
108 |
109 | $executeArray = array(
110 | ":firstname" => $post_firstname,
111 | ":lastname" => $post_lastname,
112 | ":email" => $post_email,
113 | ":id" => $user_id
114 | );
115 |
116 | if(!empty($post_password)) {
117 | $sql = "UPDATE user SET firstname = :firstname, lastname = :lastname, email = :email, password = :password WHERE id = :id";
118 | $password = $post_password;
119 | $hashPassword = password_hash($password, PASSWORD_DEFAULT);
120 | $post_password = $hashPassword;
121 |
122 | $executeArray[':password'] = $post_password;
123 | }
124 |
125 | $obj = $this->db->prepare($sql);
126 |
127 | $result1 = $obj->execute($executeArray);
128 |
129 | return $result1;
130 | }
131 |
132 | public function getPosts() {
133 | $sql = 'SELECT user.firstname, user.lastname, file.image, file.thumb, category.category_name, posts.*
134 | FROM user
135 | JOIN posts
136 | ON user.id = posts.user_id
137 | JOIN file
138 | ON file.id = posts.file_id
139 | JOIN category
140 | ON category.id = posts.category_id ORDER BY timestamp DESC';
141 |
142 | $obj = $this->db->prepare($sql);
143 |
144 | $obj->execute();
145 |
146 | if ($obj->rowCount() > 0) {
147 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
148 | return $data;
149 | }
150 |
151 | return false;
152 | }
153 |
154 | public function getPostById($id) {
155 | $sql = "SELECT user.firstname, user.lastname, file.image, file.thumb, category.category_name, posts.*
156 | FROM user
157 | JOIN posts
158 | ON user.id = posts.user_id
159 | JOIN file
160 | ON file.id = posts.file_id
161 | JOIN category
162 | ON category.id = posts.category_id WHERE posts.id = :id";
163 |
164 | $obj = $this->db->prepare($sql);
165 |
166 | $obj->execute(array(
167 | ":id" => $id
168 | ));
169 |
170 | if($obj->rowCount() > 0) {
171 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
172 | return $data;
173 | }
174 |
175 | return false;
176 | }
177 |
178 | public function getFileById($id) {
179 | $sql = "SELECT * FROM file WHERE id = :id";
180 | $obj = $this->db->prepare($sql);
181 |
182 | $obj->execute(array(
183 | ":id" => $id
184 | ));
185 |
186 | if($obj->rowCount() > 0) {
187 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
188 | return $data;
189 | }
190 |
191 | return false;
192 | }
193 |
194 | public function getPostsByEmail() {
195 | $sql = 'SELECT user.firstname, user.lastname, file.image, file.thumb, category.category_name, posts.*
196 | FROM user
197 | JOIN posts
198 | ON user.id = posts.user_id
199 | JOIN file
200 | ON file.id = posts.file_id
201 | JOIN category
202 | ON category.id = posts.category_id
203 | WHERE user.email = :email';
204 |
205 | $obj = $this->db->prepare($sql);
206 |
207 | $obj->execute(array(
208 | ":email" => Session::get('user')['email']
209 | ));
210 |
211 | if ($obj->rowCount() > 0) {
212 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
213 | return $data;
214 | }
215 |
216 | return false;
217 | }
218 |
219 | public function getUserById($id) {
220 | $sql = 'SELECT u.id, u.firstname, u.lastname, u.email, u.login_attempts, u.permission_id, u.file_id, file.image, file.thumb, p.permission
221 | FROM user as u
222 | LEFT JOIN file ON file.id = u.file_id
223 | LEFT JOIN user_permission AS p ON u.permission_id = p.id
224 | WHERE u.id = :id';
225 |
226 | $obj = $this->db->prepare($sql);
227 |
228 | $obj->execute(array(
229 | ":id" => $id
230 | ));
231 |
232 | if ($obj->rowCount() > 0) {
233 | $data = $obj->fetch(PDO::FETCH_ASSOC);
234 | return $data;
235 | }
236 |
237 | return false;
238 | }
239 |
240 | public function getUserFromEmail($email) {
241 | $sql = 'SELECT user.*, user_permission.permission FROM user LEFT JOIN user_permission ON permission_id = user_permission.id WHERE email = :email LIMIT 1';
242 | $obj = $this->db->prepare($sql);
243 |
244 | $obj->execute(array(
245 | 'email' => $email
246 | ));
247 |
248 | $result = $obj->fetch(PDO::FETCH_ASSOC);
249 |
250 | return $result;
251 | }
252 |
253 | public function updatePost($data) {
254 | $sql = "UPDATE posts SET header = :header, content = :content WHERE id = :id";
255 |
256 | $obj = $this->db->prepare($sql);
257 |
258 | $obj->execute(array(
259 | ":id" => $data["id"],
260 | ":header" => $data["header"],
261 | ":content" => $data["content"]
262 | ));
263 | }
264 |
265 | public function getCategories() {
266 | $sql = "SELECT * FROM category WHERE 1";
267 | $obj = $this->db->prepare($sql);
268 |
269 | $obj->execute();
270 |
271 | if($obj->rowCount() > 0) {
272 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
273 | return $data;
274 | }
275 |
276 | return false;
277 | }
278 |
279 | public function insertCategory($categoryName) {
280 | $sql = "INSERT INTO category(category_name) VALUES (:category_name)";
281 | $obj = $this->db->prepare($sql);
282 |
283 | $obj->execute(array(
284 | ":category_name" => $categoryName
285 | ));
286 |
287 | if($obj->rowCount() > 0) {
288 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
289 | return $data;
290 | }
291 |
292 | return false;
293 | }
294 |
295 | public function getAllUsers() {
296 | $sql = 'SELECT user.*, user_permission.permission FROM user LEFT JOIN user_permission ON permission_id = user_permission.id ORDER BY user.email ASC';
297 | $obj = $this->db->prepare($sql);
298 |
299 | $obj->execute();
300 |
301 | $result = $obj->fetchAll(PDO::FETCH_OBJ);
302 |
303 | return $result;
304 | }
305 |
306 | public function updatePermission($permission, $userEmail) {
307 | $sql = "UPDATE `user` SET permission_id = :permission WHERE email = :email";
308 |
309 | $obj = $this->db->prepare($sql);
310 |
311 | $obj->execute(array(
312 | ":permission" => $permission,
313 | ":email" => $userEmail
314 | ));
315 | }
316 |
317 | public function getAllPermissions() {
318 | $sql = "SELECT * FROM user_permission";
319 | $obj = $this->db->prepare($sql);
320 | $obj->execute();
321 |
322 | $result = $obj->fetchAll(PDO::FETCH_OBJ);
323 |
324 | return $result;
325 | }
326 |
327 | # ********************
328 | # Ban/Unban Functions
329 | # ********************
330 |
331 | public function unbanUser($userEmail) {
332 | $sql = 'UPDATE user SET login_attempts = 0 WHERE email = :email';
333 | $obj = $this->db->prepare($sql);
334 |
335 | $result = $obj->execute(array(
336 | ":email" => $userEmail
337 | ));
338 |
339 | return $result;
340 | }
341 |
342 | public function banUser($userEmail) {
343 | $sql = 'UPDATE user SET login_attempts = 3 WHERE email = :email';
344 | $obj = $this->db->prepare($sql);
345 |
346 | $result = $obj->execute(array(
347 | ":email" => $userEmail
348 | ));
349 |
350 | return $result;
351 | }
352 |
353 | # *****************
354 | # Delete Functions
355 | # *****************
356 |
357 | public function deleteFile($file_id) {
358 |
359 | $sql = 'DELETE FROM file WHERE id = :file_id';
360 |
361 | $obj = $this->db->prepare($sql);
362 |
363 | $result = $obj->execute(array(
364 | ':file_id' => $file_id
365 | ));
366 |
367 | return $result;
368 | }
369 |
370 | public function deletePost($id) {
371 |
372 | $sql = 'DELETE FROM posts WHERE id = :id LIMIT 1;';
373 |
374 | $obj = $this->db->prepare($sql);
375 |
376 | $result = $obj->execute(array(
377 | ':id' => $id
378 | ));
379 |
380 | return $result;
381 | }
382 |
383 | }
--------------------------------------------------------------------------------
/src/model/Home_Model.php:
--------------------------------------------------------------------------------
1 | db->prepare($sql);
17 |
18 | $obj->execute();
19 |
20 | if ($obj->rowCount() > 0) {
21 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
22 | return $data;
23 | }
24 |
25 | return false;
26 | }
27 |
28 | public function getPostsTotal() {
29 | $sql = 'SELECT * FROM posts';
30 |
31 | $obj = $this->db->prepare($sql);
32 |
33 | $obj->execute();
34 |
35 | $data = $obj->rowCount();
36 | return $data;
37 |
38 |
39 | return false;
40 | }
41 |
42 | public function paginationCount($limit, $offset) {
43 | $sql = 'SELECT * FROM posts LIMIT = :limit OFFSET = :offset';
44 |
45 | $obj = $this->db->prepare($sql);
46 |
47 | $obj->execute(array(
48 | ":limit" => $limit,
49 | ":offset" => $offset
50 | ));
51 |
52 | // Do we have any results?
53 | if ($obj->rowCount() > 0) {
54 | // Define how we want to fetch the results
55 | $data = $obj->fetchAll(PDO::FETCH_OBJ);
56 | Debug::add($data);
57 | $iterator = new IteratorIterator($data);
58 |
59 | // Display the results
60 | foreach ($iterator as $row) {
61 | echo '
', $row['name'], '
'; 62 | } 63 | } 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/model/Navbar_Model.php: -------------------------------------------------------------------------------- 1 | db->prepare($sql); 7 | $result = $obj->execute(); 8 | 9 | if($result) { 10 | $data = $obj->fetchAll(PDO::FETCH_ASSOC); 11 | return $data; 12 | } 13 | 14 | return false; 15 | } 16 | } -------------------------------------------------------------------------------- /src/partial/debug.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |