-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclass.blog.php
executable file
·176 lines (135 loc) · 4.87 KB
/
class.blog.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
class paginate
{
private $db;
function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
// $this->db = $conn;
}
public function dataview($query)
{
//
// $farmer_name = new FARMER();
// $stmt = $farmer_name->runQuery("SELECT * FROM tbl_farmers WHERE email=:email_id");
// $stmt->execute(array(":email_id"=>$_SESSION['farmerSession']));
// $name = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt = $this->conn->prepare($query);
$stmt->execute();
if($stmt->rowCount()>0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<!-- if (isset($_POST['btn-more'])) {
$btn = trim($_POST['btn-more']);
header("Location: blog.php?more");
} -->
<div class="col-md-12 col-xs-12 col-sm-12 row-eq-height card __card" id="mauni">
<div class="col-md-3 col-sm-3">
<?php if ( $row['photo']==''){
echo "";
}else {?>
<img src="consultants/message_images/<?php echo $row['photo']; ?>" style="padding: 10px 0px;" class="item_image img-responsive" />
<?php }
?>
</div>
<div class="col-md-9 col-sm-9 ">
<a href="blog_view.php?page=<?php echo $row['ID']; ?>"><h4 class="itemed h4"><b><?php echo $row['title']; ?></b></h4></a>
<span class="text"><?php
$position = 150;
$message = $row['description'];
$post = substr($message,0,$position);
echo $post;
echo "...";
?>
<a href="blog_view.php?page=<?php echo $row['ID']; ?>"><button class="btn small btn-secondary btn-sm __item-cta" type="submit" name="btn-more" value="<?php echo $row['ID']; ?>">Read More...</button></a>
</span>
<span class="phoned"><b> <?php echo $row['email']; ?> </b> </span>
<a href="tel:+254-<?php echo $row['phone']; ?>"> <span class="priced btn btn-default btn-xs"> <?php echo $row['phone']; ?></span></a>
<span class="itemed h5 " style="font-style: italic;"><?php
date_default_timezone_set('Africa/Nairobi');
$timed = $row['timer'];
$timestamp = strtotime($timed);
$strTime = array("second", "minute", "hour", "day", "month", "year");
$length = array("60","60","24","30","12","10");
$currentTime = time();
if($currentTime >= $timestamp) {
$diff = time()- $timestamp;
for($i = 0; $diff >= $length[$i] && $i < count($length)-1; $i++) {
$diff = $diff / $length[$i];
}
$diff = round($diff);
echo $diff . " " . $strTime[$i] . "(s) ago ";
} ?></span>
<!-- <span>Favourite </span><i class="glyphicon glyphicon-star"></i>
<span>Comment </span><i class="glyphicon glyphicon-comment"></i><br> -->
</div><br>
</div>
<?php
}
}
else
{
?>
<div class="__nothing">
<i class="fa fa-meh-o"></i>
<p class="__nothing-text">No articles just yet</p>
</div>
<?php
}
}
public function paging($query,$records_per_page)
{
$starting_position=0;
if(isset($_GET["page_no"]))
{
$starting_position=($_GET["page_no"]-1)*$records_per_page;
}
$query2=$query." limit $starting_position,$records_per_page";
return $query2;
}
public function paginglink($query,$records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->conn->prepare($query);
$stmt->execute();
$total_no_of_records = $stmt->rowCount();
if($total_no_of_records > 0)
{
?><tr><td colspan="3"><?php
$total_no_of_pages=ceil($total_no_of_records/$records_per_page);
$current_page=1;
if(isset($_GET["page_no"]))
{
$current_page=$_GET["page_no"];
}
if($current_page!=1)
{
$previous =$current_page-1;
echo "<li><a href='".$self."?page_no=1'>First</a> </li>";
echo "<li><a href='".$self."?page_no=".$previous."'>Previous</a> </li>";
}
for($i=1;$i<=$total_no_of_pages;$i++)
{
if($i==$current_page)
{
echo "<li class='active'><a href='".$self."?page_no=".$i."'>".$i."</a></li>";
}
else
{
echo "<li><a href='".$self."?page_no=".$i."'>".$i."</a> </li>";
}
}
if($current_page!=$total_no_of_pages)
{
$next=$current_page+1;
echo "<li><a href='".$self."?page_no=".$next."'>Next</a> </li>";
echo "<li><a href='".$self."?page_no=".$total_no_of_pages."'>Last</a> </li>";
}
?></td></tr><?php
}
}
}