/
browse-posts.php
92 lines (77 loc) · 2.77 KB
/
browse-posts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
require_once('includes/travel-setup.inc.php');
function outputPostRows($dbAdapter) {
$gateTravelPost = new TravelPostTableGateway($dbAdapter);
$gateTravelImage = new TravelImageTableGateway($dbAdapter);
$gateTravelUserDetails = new TravelUserDetailsTableGateway($dbAdapter);
$gateTravelPostImage = new TravelPostImagesTableGateway($dbAdapter);
$result = $gateTravelPost->findAll();
foreach ($result as $row)
{
$postId = $row->PostID;
$userId = $row->UID;
$imageId = $gateTravelPostImage->findById($postId)->ImageID;
$thumb = $gateTravelImage->findById($imageId)->Path;
$title = $row->Title;
$firstName = $gateTravelUserDetails->findById($userId)->FirstName;
$lastName = $gateTravelUserDetails->findById($userId)->LastName;
$userName = utf8_encode($firstName . $lastName);
$excerpt = (substr($row->Message,0,200)."...");
$date = substr($row->PostTime,0,10);
echo utf8_encode('<div class="row">
<div class="col-md-2">
<a href="single-image.php?id='.$imageId.'" class="">
<img src="travel-images/square-medium/'.$thumb.'" alt="'.$title.'" class="img-thumbnail"/>
</a>
</div>
<div class="col-md-10">
<h2>'.$title.'</h2>
<div class="details">
Posted by <a href="single-user.php?id='. $userId. '" class="">'. $userName. '</a>
<span class="pull-right">'. $date.'</span>
</div>
<p class="excerpt">'.
$excerpt.
'</p>
<p><a href="single-post.php?id='. $postId. '" class="btn btn-primary btn-sm">Read more</a></p>
</div>
</div>
<hr/>');
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Share your Travels Assignment 1</title>
<?php include 'includes/travel-head.inc.php'; ?>
</head>
<body>
<?php include 'includes/travel-header.inc.php'; ?>
<div class="container">
<div class="row">
<div class="col-md-3">
<?php include 'includes/travel-left-rail.inc.php'; ?>
</div>
<div class="col-md-9"> <!-- start main content column -->
<ol class="breadcrumb">
<li><a href="index.php">Home</a></li>
<li><a href="browse.php">Browse</a></li>
<li class="active">Posts</li>
</ol>
<div class="jumbotron" id="postJumbo">
<h1>Posts</h1>
<p>Read other travellers' posts ... or create your own.</p>
<p><a href ="#" class="btn btn-primary btn-lg">Learn more »</a></p>
</div>
<div class="postlist">
<?php outputPostRows($dbAdapter); ?>
</div>
</div>
</div>
</div>
<?php include 'includes/travel-footer.inc.php'; ?>
<?php include 'includes/javascript.php'; ?>
<?php $dbAdapter->closeConnection(); ?>
</body>
</html>