Skip to content

Commit 31c94cc

Browse files
committed
boostrap 4 added in public
1 parent 3a7acbe commit 31c94cc

28 files changed

+263
-9180
lines changed

admin/comments.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<td scope="col"><?php echo $comment_author ?></td>
8585
<td scope="col"><?php echo substr($comment_content,0,50) ?></td>
8686
<td scope="col"><?php echo $comment_email ?></td>
87-
<td scope="col"><a href="<?php echo getRootURI() ?>/post.php?p_id=<?php echo $comment_post_id ?>"><?php echo $comment_post_title ?></a></td>
87+
<td scope="col"><a href="<?php echo ROOT ?>/post.php?p_id=<?php echo $comment_post_id ?>"><?php echo $comment_post_title ?></a></td>
8888
<td scope="col"><?php echo $comment_status ?></td>
8989
<td scope="col"><?php echo $comment_date ?></td>
9090
</tr>

admin/css/bootstrap.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

admin/css/bootstrap.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

admin/includes/function.php

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?php include "db.php" ?>
22
<?php
33

4-
function getRootURI(){
5-
return "http://localhost/php-newcms";
6-
}
7-
84
function is_loggedin(){
95
return (isset($_SESSION['user_id'])) ? true : false;
106
}
@@ -110,7 +106,7 @@ function clone_category($cat_id){
110106

111107
function fetch_all_posts(){
112108
global $connection;
113-
$query = "SELECT * FROM posts";
109+
$query = "SELECT * FROM posts ORDER BY post_date DESC";
114110
$res = mysqli_query($connection, $query);
115111

116112
if(!$res){
@@ -125,7 +121,7 @@ function fetch_all_posts(){
125121
function fetch_published_posts(){
126122
global $connection;
127123
$query = "SELECT * FROM posts ";
128-
$query .= "WHERE post_status = 'published'";
124+
$query .= "WHERE post_status = 'published' ORDER BY post_date DESC";
129125
$res = mysqli_query($connection, $query);
130126

131127
if(!$res){
@@ -158,15 +154,16 @@ function add_post($post_fields){
158154
$post_cat_id = $post_fields['post_cat_id'];
159155
$post_title = $post_fields['post_title'];
160156
$post_author_id = $post_fields['post_author_id'];
161-
$post_date = date('d-m-y');
162157
$post_image = $post_fields['post_image'];
158+
//$post_date = date('M dS, Y \a\t g:i A');
159+
$post_date = date('Y-m-d H:i:s');
163160
$post_content = $post_fields['post_content'];
164161
$post_tags = $post_fields['post_tags'];
165162
$post_comment_count = 0;
166163
$post_status = $post_fields['post_status'];
167164

168165
$query = "INSERT INTO posts(post_cat_id, post_title, post_author_id, post_date, post_image, post_content, post_tags, post_comment_count, post_status) ";
169-
$query .= "VALUES($post_cat_id, '$post_title', $post_author_id, $post_date, '$post_image', '$post_content', '$post_tags', $post_comment_count, '$post_status')";
166+
$query .= "VALUES($post_cat_id, '$post_title', $post_author_id, '$post_date', '$post_image', '$post_content', '$post_tags', $post_comment_count, '$post_status')";
170167
$res = mysqli_query($connection,$query);
171168

172169
if(!$res){
@@ -191,7 +188,8 @@ function edit_post($post_id, $post_fields){
191188

192189
$post_cat_id = $post_fields['post_cat_id'];
193190
$post_title = $post_fields['post_title'];
194-
$post_date = date('dd-mm-yyyy');
191+
//$post_date = date('M dS, Y \a\t g:i A');
192+
$post_date = date('Y-m-d H:i:s');
195193
$post_image = $post_fields['post_image'];
196194
$post_content = $post_fields['post_content'];
197195
$post_tags = $post_fields['post_tags'];
@@ -200,7 +198,7 @@ function edit_post($post_id, $post_fields){
200198
$query = "UPDATE posts SET ";
201199
$query .= "post_cat_id = $post_cat_id, ";
202200
$query .= "post_title = '$post_title', ";
203-
$query .= "post_date = $post_date, ";
201+
$query .= "post_date = '$post_date', ";
204202
$query .= "post_content = '$post_content', ";
205203
$query .= "post_image = '$post_image', ";
206204
$query .= "post_tags = '$post_tags', ";
@@ -238,7 +236,7 @@ function clone_post($post_id){
238236
function fetch_category_posts($cat_id){
239237
global $connection;
240238
$query = "SELECT * FROM posts ";
241-
$query .= "WHERE post_cat_id = $cat_id";
239+
$query .= "WHERE post_cat_id = $cat_id ORDER BY post_date DESC";
242240
$res = mysqli_query($connection, $query);
243241

244242
if(!$res){
@@ -254,7 +252,7 @@ function fetch_category_posts($cat_id){
254252
function fetch_author_posts($u_id){
255253
global $connection;
256254
$query = "SELECT * FROM posts ";
257-
$query .= "WHERE post_author_id = $u_id";
255+
$query .= "WHERE post_author_id = $u_id ORDER BY post_date DESC";
258256
$res = mysqli_query($connection, $query);
259257

260258
if(!$res){
@@ -272,7 +270,7 @@ function search_post($search){
272270

273271
global $connection;
274272
$query = "SELECT * FROM posts WHERE post_tags LIKE '%$search%' ";
275-
$query .= "OR post_title LIKE '%$search%' ";
273+
$query .= "OR post_title LIKE '%$search%' ORDER BY post_date DESC";
276274
$res = mysqli_query($connection, $query);
277275

278276
if(!$res){
@@ -578,12 +576,13 @@ function count_rows($tablename, $condition = '', $value = ''){
578576

579577
function fetch_rows($tablename, $condition = '', $value = ''){
580578
global $connection;
581-
579+
$idq = substr($tablename,0,-1) . '_id';
582580
$query = "SELECT * FROM $tablename";
583581
if(!empty($condition) && !empty($value)){
584582
$query .= " WHERE $condition = ";
585583
$query .= (is_string($value)) ? "'$value'" : "$value";;
586584
}
585+
//$query .= " ORDER BY $idq DESC";
587586

588587
$res = mysqli_query($connection,$query);
589588
if(!$res){
@@ -634,4 +633,11 @@ function is_my_post($post_id){
634633
}
635634
}
636635
return false;
636+
}
637+
638+
function date_to_string($date){
639+
$d = new DateTime($date);
640+
$r = $d->format('M dS, Y \a\t g:i A');
641+
642+
return ($r) ? $r : false;
637643
}

admin/includes/navigation.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
</li>
109109
<li class="divider"></li>
110110
<li>
111-
<a href="<?php echo getRootURI(); ?>/admin/includes/logout.php"><i class="fa fa-fw fa-power-off"></i> Log Out</a>
111+
<a href="<?php echo ROOT; ?>/admin/includes/logout.php"><i class="fa fa-fw fa-power-off"></i> Log Out</a>
112112
</li>
113113
</ul>
114114
</li>

admin/post.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<div class="alert <?php echo $notifyClass?>">
7373
<?php echo $notify?>
7474
<a href="posts.php" class="btn btn-primary">See all posts</a>
75-
<a href="<?php echo getRootURI() ?>/post.php?p_id=<?php echo $post_id?>" class="btn btn-primary" target="_blank">view Post</a>
75+
<a href="<?php echo ROOT ?>/post.php?p_id=<?php echo $post_id?>" class="btn btn-primary" target="_blank">view Post</a>
7676
</div>
7777
<?php endif; ?>
7878
<form method="post" enctype="multipart/form-data">

admin/posts.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@
109109
<?php echo $post_id ?>
110110
</td>
111111
<td scope="col">
112-
<a href="<?php echo getRootURI() ?>/author.php?u_id=<?php echo $post_author_id ?>"><?php echo $post_author ?></a>
112+
<a href="<?php echo ROOT ?>/author.php?u_id=<?php echo $post_author_id ?>"><?php echo $post_author ?></a>
113113
</td>
114-
<td scope="col"><a href="<?php echo getRootURI() ?>/post.php?p_id=<?php echo $post_id ?>">
114+
<td scope="col"><a href="<?php echo ROOT ?>/post.php?p_id=<?php echo $post_id ?>">
115115
<?php echo $post_title ?></a></td>
116116
<td scope="col">
117117
<?php echo $post_cat_title ?>

author_posts.php

+24-23
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
<div class="container">
1515

1616
<div class="row">
17-
17+
1818
<!-- Blog Entries Column -->
1919
<div class="col-md-8">
20-
<h1 class="page-header">Author <small>- <?php echo $post_author; ?></small></h1>
21-
<?php $rows = fetch_author_posts($u_id); ?>
20+
<h1 class="page-header">Author <small>-
21+
<?php echo $post_author; ?></small></h1>
22+
<hr>
23+
<?php $rows = fetch_author_posts($u_id); ?>
2224
<?php if(empty($rows)): ?>
23-
<h3 class="alert alert-info" role="alert">No Post found!</h3>
24-
<?php endif; ?>
25+
<h3 class="alert alert-info" role="alert">No Post found!</h3>
26+
<?php endif; ?>
2527
<?php foreach($rows as $row): ?>
2628
<?php
2729

@@ -35,23 +37,22 @@
3537
$post_image = $row['post_image'];
3638
$post_tags = $row['post_tags'];
3739
$post_comment_count = $row['post_comment_count'];
38-
$post_date = $row['post_date'];
40+
$post_date = date_to_string($row['post_date']);
3941
$post_content = $row['post_content'];
4042

4143
?>
42-
<!-- First Blog Post -->
43-
<h2>
44-
<a href="post.php?p_id=<?php echo $post_id ?>"><?php echo $post_title ?></a>
45-
</h2>
46-
<p class="lead">
47-
by <a href="author_posts.php?u_id=<?php echo $post_author_id ?>"><?php echo $post_author ?></a>
48-
</p>
49-
<p><span class="glyphicon glyphicon-time"></span> Posted on <?php echo $post_date ?></p>
50-
<hr>
51-
<a href="post.php?p_id=<?php echo $post_id ?>"><img class="img-responsive" src="imgs/<?php echo $post_image ?>" alt=""></a>
52-
<hr>
53-
<p><?php echo substr($post_content, 0, 100) ?>...</p>
54-
<hr>
44+
<!-- First Blog Post -->
45+
<h2 class="display-5"><a class="text-info" href="post.php?p_id=<?php echo $post_id ?>"><?php echo $post_title ?></a></h2>
46+
<div class="post-info clearfix">
47+
<p class="float-left align-middle"><strong>By </strong><a href="author_posts.php?u_id=<?php echo $post_author_id ?>">
48+
<?php echo $post_author ?></a></p>
49+
<p class="align-middle float-right"><i class="far fa-clock"></i> <strong>Posted on</strong>
50+
<?php echo $post_date ?>
51+
</p>
52+
</div>
53+
<a href="post.php?p_id=<?php echo $post_id ?>"><img class="img-fluid" src="imgs/<?php echo $post_image ?>" alt="postimage"></a>
54+
<!--p><?php echo substr($post_content, 0, 100) ?></p-->
55+
<hr>
5556
<?php endforeach; ?>
5657
</div>
5758

@@ -64,7 +65,7 @@
6465
<hr>
6566

6667
<!-- Footer -->
67-
<?php include "includes/footer.php" ?>
68-
<?php else: ?>
69-
<?php header('Location: index.php'); ?>
70-
<?php endif; ?>
68+
<?php include "includes/footer.php" ?>
69+
<?php else: ?>
70+
<?php header('Location: index.php'); ?>
71+
<?php endif; ?>

category.php

+33-35
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,54 @@
11
<?php include "includes/header.php" ?>
22
<?php include "includes/navigation.php" ?>
33

4-
<?php if(isset($_GET['cat_id'])): ?>
4+
<?php if (isset($_GET['cat_id'])) : ?>
55
<?php
66

7-
$cat_id = $_GET['cat_id'];
8-
$row = fetch_category($cat_id);
9-
$cat_title = $row['cat_title'];
7+
$cat_id = $_GET['cat_id'];
8+
$row = fetch_category($cat_id);
9+
$cat_title = $row['cat_title'];
1010

1111
?>
1212

1313
<!-- Page Content -->
1414
<div class="container">
15-
1615
<div class="row">
1716
<!-- Blog Entries Column -->
1817
<div class="col-md-8">
19-
<h1 class="page-header">Category <small>- <?php echo $cat_title; ?></small></h1>
20-
<?php $rows = fetch_category_posts($cat_id); ?>
21-
<?php if(empty($rows)): ?>
22-
<h3 class="alert alert-info" role="alert">No Post found!</h3>
23-
<?php endif; ?>
24-
<?php foreach($rows as $row): ?>
18+
<h1 class="page-header">Category <small>-
19+
<?php echo $cat_title; ?></small></h1>
20+
<hr>
21+
<?php $rows = fetch_category_posts($cat_id); ?>
22+
<?php if (empty($rows)) : ?>
23+
<h3 class="alert alert-info" role="alert">No Post found!</h3>
24+
<?php endif; ?>
25+
<?php foreach ($rows as $row) : ?>
2526
<?php
26-
2727
$post_id = $row['post_id'];
2828
$post_cat_id = $row['post_cat_id'];
2929
$post_author_id = $row['post_author_id'];
3030
$post_author_row = fetch_user($post_author_id);
31-
$post_author = $post_author_row['user_firstname']." ".$post_author_row['user_lastname'];
32-
$post_title = $row['post_title'];
33-
31+
$post_author = $post_author_row['user_firstname'] . " " . $post_author_row['user_lastname'];
32+
$post_title = $row['post_title'];
33+
3434
$post_image = $row['post_image'];
3535
$post_tags = $row['post_tags'];
3636
$post_comment_count = $row['post_comment_count'];
37-
$post_date = $row['post_date'];
37+
$post_date = date_to_string($row['post_date']);
3838
$post_content = $row['post_content'];
39-
40-
?>
41-
<!-- First Blog Post -->
42-
<h2>
43-
<a href="post.php?p_id=<?php echo $post_id ?>"><?php echo $post_title ?></a>
44-
</h2>
45-
<p class="lead">
46-
by <a href="author_posts.php?u_id=<?php echo $post_author_id ?>"><?php echo $post_author ?></a>
47-
</p>
48-
<p><span class="glyphicon glyphicon-time"></span> Posted on <?php echo $post_date ?></p>
49-
<hr>
50-
<a href="post.php?p_id=<?php echo $post_id ?>"><img class="img-responsive" src="imgs/<?php echo $post_image ?>" alt=""></a>
51-
<hr>
52-
<p><?php echo substr($post_content, 0, 100) ?>...</p>
53-
<hr>
39+
?>
40+
<!-- First Blog Post -->
41+
<h2 class="display-5"><a class="text-info" href="post.php?p_id=<?php echo $post_id ?>"><?php echo $post_title ?></a></h2>
42+
<div class="post-info clearfix">
43+
<p class="float-left align-middle"><strong>By </strong><a href="author_posts.php?u_id=<?php echo $post_author_id ?>">
44+
<?php echo $post_author ?></a></p>
45+
<p class="align-middle float-right"><i class="far fa-clock"></i> <strong>Posted on</strong>
46+
<?php echo $post_date ?>
47+
</p>
48+
</div>
49+
<a href="post.php?p_id=<?php echo $post_id ?>"><img class="img-fluid" src="imgs/<?php echo $post_image ?>" alt="postimage"></a>
50+
<!--p><?php echo substr($post_content, 0, 100) ?></p-->
51+
<hr>
5452
<?php endforeach; ?>
5553
</div>
5654

@@ -63,7 +61,7 @@
6361
<hr>
6462

6563
<!-- Footer -->
66-
<?php include "includes/footer.php" ?>
67-
<?php else: ?>
68-
<?php header('Location: index.php'); ?>
69-
<?php endif; ?>
64+
<?php include "includes/footer.php" ?>
65+
<?php else : ?>
66+
<?php header('Location: index.php'); ?>
67+
<?php endif; ?>

config.php

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
define('SITE_TITLE', 'php-newCMS');
4+
define('ROOT', 'http://localhost/php-newcms');

0 commit comments

Comments
 (0)