summaryrefslogtreecommitdiff
path: root/htdocs
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-05-12 17:37:31 -0700
committerJesse Morgan <jesse@jesterpm.net ; true>2011-05-12 17:37:31 -0700
commitc7ede0038e98b386cbd1ef333d89faa2568b1cb1 (patch)
treedd8d5e83ae20a3b2389bd4721b0c45285c83475f /htdocs
parentdd24e2c973a7979894971bdc38d904d2aecc7d5d (diff)
Now we have some basic functionality
Diffstat (limited to 'htdocs')
-rw-r--r--htdocs/index.php23
-rw-r--r--htdocs/postings.php51
-rw-r--r--htdocs/src/Post.inc.php32
-rw-r--r--htdocs/src/PostIterator.inc.php20
4 files changed, 121 insertions, 5 deletions
diff --git a/htdocs/index.php b/htdocs/index.php
index 4777b05..a5f5456 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -8,11 +8,30 @@
*
*/
-require_once "src/config.inc.php";
+require_once "src/base.inc.php";
require_once "src/header.inc.php";
-echo "Content";
+echo "<h2>Recent Posts</h2>";
+
+// Get all recent, approved posts.
+$posts = new PostIterator();
+$posts->filterStage('approved');
+$posts->limit(5);
+$posts->query();
+
+if ($posts->valid()) {
+ foreach ($posts as $id => $post) {
+ printf("<div class=\"post\"><p><a href=\"postings/%s.html\">%s</a></p>"
+ . "<div class=\"desc\"><span class=\"location\">%s</span>"
+ . " <span class=\"age\">%s</span></div></div>",
+
+ $id, $post->getName(), $post->getLocation(), $post->getAge());
+ }
+
+} else {
+ echo "<p>No recent posts.</p>";
+}
require_once "src/footer.inc.php";
diff --git a/htdocs/postings.php b/htdocs/postings.php
new file mode 100644
index 0000000..c6f53d5
--- /dev/null
+++ b/htdocs/postings.php
@@ -0,0 +1,51 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "src/base.inc.php";
+
+require_once "src/header.inc.php";
+
+
+// Make sure we had a path info
+if (!isset($_SERVER['PATH_INFO'])) {
+ errorNotFound();
+}
+
+// Clean up the id in the path info.
+$id = substr($_SERVER['PATH_INFO'], 1, strpos($_SERVER['PATH_INFO'], '.') - 1);
+
+if (!is_numeric($id)) {
+ errorNotFound();
+}
+
+// Get the post.
+$post = Post::getById($id);
+
+if (!$post) {
+ errorNotFound();
+}
+
+// Display the post.
+
+echo "<h2>". $post->getName() ."</h2>";
+
+echo "<p>". $post->getDescription() ."</p>";
+
+
+
+require_once "src/footer.inc.php";
+
+function errorNotFound() {
+ // TODO: Better 404 error
+ echo "404";
+ exit;
+}
+
+?>
diff --git a/htdocs/src/Post.inc.php b/htdocs/src/Post.inc.php
index a4d34f7..22d2fce 100644
--- a/htdocs/src/Post.inc.php
+++ b/htdocs/src/Post.inc.php
@@ -31,7 +31,7 @@ class Post {
}
private static function getPost($where) {
- $query = "SELECT * FROM post WHERE $where";
+ $query = "SELECT *, UNIX_TIMESTAMP(created) AS createdts FROM post WHERE $where";
$db = getDatabase();
@@ -59,7 +59,11 @@ class Post {
}
public function getName() {
- return $this->info['name'];
+ return htmlspecialchars($this->info['name']);
+ }
+
+ public function getDescription() {
+ return htmlspecialchars($this->info['description']);
}
public function getStage() {
@@ -77,6 +81,30 @@ class Post {
public function getCreated() {
return $this->info['created'];
}
+
+ public function getAge() {
+ $diff = time() - $this->info['createdts'];
+
+ if ($diff < 60) {
+ return floor($diff) ." seconds ago";
+
+ } else if ($diff < 3600) {
+ return floor($diff / 60) ." minutes ago";
+
+ } else if ($diff < 86400) {
+ return floor($diff / 3600) ." hours ago";
+
+ } else if ($diff < 604800) {
+ return floor($diff / 86400) ." days ago";
+
+ } else {
+ return floor($diff / 604800) . " weeks ago";
+ }
+ }
+
+ public function getLocation() {
+ return $this->info['location'];
+ }
}
?>
diff --git a/htdocs/src/PostIterator.inc.php b/htdocs/src/PostIterator.inc.php
index 6106f23..52eb750 100644
--- a/htdocs/src/PostIterator.inc.php
+++ b/htdocs/src/PostIterator.inc.php
@@ -14,11 +14,15 @@ class PostIterator implements Iterator {
private $where;
private $rows;
private $position;
+ private $order;
+ private $limit;
public function __construct() {
$this->where = array();
$this->rows = array();
$this->position = 0;
+ $this->order = "created desc";
+ $this->limit = 0;
}
public function filterStage($stage) {
@@ -29,6 +33,14 @@ class PostIterator implements Iterator {
$this->where[] = "source_id='$source'";
}
+ public function orderBy($order) {
+ $this->order = $order;
+ }
+
+ public function limit($limit) {
+ $this->limit = limit;
+ }
+
public function rewind() {
$this->position = 0;
}
@@ -50,13 +62,19 @@ class PostIterator implements Iterator {
}
public function query() {
- $query = "SELECT * FROM post";
+ $query = "SELECT *, UNIX_TIMESTAMP(created) AS createdts FROM post";
if (count($this->where) > 0) {
$where = join(' AND ', $this->where);
$query .= " WHERE $where";
}
+ $query .= " ORDER BY ". $this->order;
+
+ if ($this->limit != 0) {
+ $query .= " LIMIT ". $this->limit;
+ }
+
$db = getDatabase();
$this->rows = $db->fetchAssocRows($query);