-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
80 lines (74 loc) · 2.11 KB
/
index.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
<?php
session_start();
$m = new Mongo();
$collection = $m->blogsite->posts;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mangoblog</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<?php include "header.php"; include "sidebar.php"; ?>
<div id="mainContent">
<?php
if(is_numeric($_GET['id'])){
$skipby=$_GET['id'];
}else if($_GET['id']<0){
$skipby=1;
}else{
$skipby=1;
}
$skip=9*($skipby-1);
if($skip>$collection->count()){
$skipby=1;
$skip=0;
}
//$cursor = $collection->find()->skip($skip);
//$cursor->sort(array('_id' => -1));
$cursor = $collection->find()->sort(array('_id' => -1));
if($skipby-1>0 AND $skipby!=NULL){
$cursor->skip($skip);
}
$cursor->limit(9);
$stack=array();
while( $cursor->hasNext() ) {
$post=$cursor->getNext();
if($post['title']!=NULL){
echo "<p class=\"post\">";
echo "<a href=\"post.php?id=".$post["_id"]."\">".$post["title"]." by ".$post["author"].", ". $post["date"]."</a> <br />";
$content = $post["content"];
if(strlen($content)>100){
$temp=strpos($content, " ", 95);
$description=substr($content, 0, $temp);
if(($description[strlen($content)-1]==",")
or
($description[strlen($content)-1]=="."))
{
$description=substr($content, 0, $temp-1)."..";
}else{
$description=substr($content, 0, $temp)."..";
}
}
echo "$description <br />";
$comments=$post["comments"];
if($comments!=NULL){
$comments=count($comments);
echo "$comments comments <br /></p>";
}else
echo "0 comments <br /></p>";
}
}
?>
<div id="prev"><?php if(9*($skipby)<=$collection->count()){ echo "<a href=\"?id=".($skipby+1)."\">Previous Entries</a>";} ?></div>
<div id="next"><?php if(($skipby-1)>0){ echo "<a href=\"?id=".($skipby-1)."\">Newer Entries</a>";} ?></div>
<br />
<div style="clear:both;"></div>
</div>
<?php include "footer.php"; ?>
</div>
</body>
</html>