summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-05-17 17:20:06 -0700
committerJesse Morgan <jesse@jesterpm.net ; true>2011-05-17 17:20:06 -0700
commit251349acaf0f8fed47aad1610b5b627a7e684f27 (patch)
tree933268c87ea64e432cf511a0f77133380490976f
parentc7ede0038e98b386cbd1ef333d89faa2568b1cb1 (diff)
Added category buttons and categories page
-rw-r--r--design/database.sql13
-rw-r--r--htdocs/categories.php71
-rw-r--r--htdocs/css/main.css29
-rw-r--r--htdocs/images/bigbutton.pngbin0 -> 2854 bytes
-rw-r--r--htdocs/images/calendar.pngbin0 -> 5583 bytes
-rw-r--r--htdocs/images/house.pngbin0 -> 5417 bytes
-rw-r--r--htdocs/images/jobs.pngbin0 -> 5221 bytes
-rw-r--r--htdocs/images/smallbutton.pngbin0 -> 2863 bytes
-rw-r--r--htdocs/images/tag.pngbin0 -> 6265 bytes
-rw-r--r--htdocs/src/Category.inc.php86
-rw-r--r--htdocs/src/PostIterator.inc.php4
-rw-r--r--htdocs/src/header.inc.php27
12 files changed, 221 insertions, 9 deletions
diff --git a/design/database.sql b/design/database.sql
index 22daf7f..08bcc54 100644
--- a/design/database.sql
+++ b/design/database.sql
@@ -24,6 +24,7 @@ USE p4scommunity;
CREATE TABLE category (
id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
+ shortname VARCHAR(30) NOT NULL,
name VARCHAR(30) NOT NULL,
PRIMARY KEY(id)
@@ -79,12 +80,12 @@ CREATE TABLE pages (
);
-- The following creates some sample data
-INSERT INTO category (name) VALUES
- ('Jobs'),
- ('Housing'),
- ('Events'),
- ('For Sale'),
- ('Needs');
+INSERT INTO category (name, shortname) VALUES
+ ('Jobs', 'jobs'),
+ ('Housing', 'housing'),
+ ('Events', 'events'),
+ ('For Sale','forsale'),
+ ('Needs', 'needs');
INSERT INTO source (name) VALUES ('Foursquare Church');
diff --git a/htdocs/categories.php b/htdocs/categories.php
new file mode 100644
index 0000000..5725125
--- /dev/null
+++ b/htdocs/categories.php
@@ -0,0 +1,71 @@
+<?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";
+
+// Do we have a path info?
+if (isset($_SERVER['PATH_INFO'])) {
+ // Get the category
+ $category = addslashes(substr($_SERVER['PATH_INFO'], 1));
+
+ $category = Category::getByShortname($category);
+ if ($category) {
+ displayEvents($category);
+
+ } else {
+ // Bad category. List them all.
+ listCategories();
+ }
+
+} else {
+ // No category. List them all.
+ listCategories();
+}
+
+
+function listCategories() {
+ echo "<h2>Categories</h2>";
+
+ $cats = Category::getCategories();
+ foreach ($cats as $short => $name) {
+ $url = $GLOBALS['CONFIG']['urlroot'] . "/categories/$short";
+ echo "<p><a href=\"$url\">$name</a></p>";
+ }
+}
+
+function displayEvents($category) {
+ echo "<h2>". $category->getName() ."</h2>";
+
+ // Get all recent, approved posts.
+ $posts = new PostIterator();
+ $posts->filterCategory($category->getId());
+ $posts->filterStage('approved');
+ $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/css/main.css b/htdocs/css/main.css
index 6f5349c..523eb8c 100644
--- a/htdocs/css/main.css
+++ b/htdocs/css/main.css
@@ -2,6 +2,8 @@ body {
background: #E8E8E8;
margin: 7px 0 0 0;
padding: 0;
+
+ font-family: Helvetica;
}
#nav, #buttonblock, #content, #footer {
@@ -10,6 +12,29 @@ body {
text-transform: uppercase;
}
+#nav ul li {
+ display: inline;
+ list-style: none;
+}
+
+.bigbutton {
+ background: url('../images/bigbutton.png') repeat-x center top;
+ color: white;
+ padding: 0.3em 1em 0.3em 1em;
+ text-decoration: none;
+ border-radius: 5px;
+}
+
+.smallbutton {
+ background: url('../images/smallbutton.png') repeat-x center top;
+ color: white;
+ padding: 0.3em 1em 0.3em 1em;
+ text-decoration: none;
+ border-radius: 5px;
+ font-size: 75%;
+}
+
+
#header {
background: url('../images/headerbg.jpg') repeat-x center top;
text-align: center;
@@ -23,6 +48,10 @@ body {
text-align: center;
}
+#buttonblock div {
+ display: inline-block;
+}
+
#content {
padding: 35px 0 35px 0;
}
diff --git a/htdocs/images/bigbutton.png b/htdocs/images/bigbutton.png
new file mode 100644
index 0000000..8e4bc21
--- /dev/null
+++ b/htdocs/images/bigbutton.png
Binary files differ
diff --git a/htdocs/images/calendar.png b/htdocs/images/calendar.png
new file mode 100644
index 0000000..0a8355c
--- /dev/null
+++ b/htdocs/images/calendar.png
Binary files differ
diff --git a/htdocs/images/house.png b/htdocs/images/house.png
new file mode 100644
index 0000000..969ef88
--- /dev/null
+++ b/htdocs/images/house.png
Binary files differ
diff --git a/htdocs/images/jobs.png b/htdocs/images/jobs.png
new file mode 100644
index 0000000..561b508
--- /dev/null
+++ b/htdocs/images/jobs.png
Binary files differ
diff --git a/htdocs/images/smallbutton.png b/htdocs/images/smallbutton.png
new file mode 100644
index 0000000..c95831b
--- /dev/null
+++ b/htdocs/images/smallbutton.png
Binary files differ
diff --git a/htdocs/images/tag.png b/htdocs/images/tag.png
new file mode 100644
index 0000000..fe4ef2b
--- /dev/null
+++ b/htdocs/images/tag.png
Binary files differ
diff --git a/htdocs/src/Category.inc.php b/htdocs/src/Category.inc.php
new file mode 100644
index 0000000..edc0303
--- /dev/null
+++ b/htdocs/src/Category.inc.php
@@ -0,0 +1,86 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "base.inc.php";
+
+class Category {
+ private $info;
+
+
+ public function __construct($info=null) {
+ $this->info = $info;
+ }
+
+ public static function getCategories() {
+ $db = getDatabase();
+
+ $query = "SELECT * FROM category ORDER BY name";
+
+ $rows = $db->fetchAssocRows($query);
+
+ $result = array();
+ foreach ($rows as $row) {
+ $result[$row['shortname']] = $row['name'];
+ }
+
+ return $result;
+ }
+
+ public static function getById($id) {
+ $where = "id='$id'";
+
+ return Category::getCategory($where);
+ }
+
+ public static function getByShortname($shortname) {
+ $where = "shortname='$shortname'";
+
+ return Category::getCategory($where);
+ }
+
+ private static function getCategory($where) {
+ $query = "SELECT * FROM category WHERE $where";
+
+ $db = getDatabase();
+
+ $row = $db->fetchAssocRow($query);
+
+ if ($row) {
+ $category = new Category();
+ $category->info = $row;
+
+ return $category;
+
+ } else {
+ return false;
+ }
+ }
+
+ public function save() {
+ $db = getDatabase();
+
+ // TODO: Implement Save
+ }
+
+ public function getId() {
+ return $this->info['id'];
+ }
+
+ public function getName() {
+ return htmlspecialchars($this->info['name']);
+ }
+
+ public function getShortname() {
+ return htmlspecialchars($this->info['shortname']);
+ }
+}
+
+?>
+
diff --git a/htdocs/src/PostIterator.inc.php b/htdocs/src/PostIterator.inc.php
index 52eb750..cced79b 100644
--- a/htdocs/src/PostIterator.inc.php
+++ b/htdocs/src/PostIterator.inc.php
@@ -33,6 +33,10 @@ class PostIterator implements Iterator {
$this->where[] = "source_id='$source'";
}
+ public function filterCategory($category_id) {
+ $this->where[] = "category_id='$category_id'";
+ }
+
public function orderBy($order) {
$this->order = $order;
}
diff --git a/htdocs/src/header.inc.php b/htdocs/src/header.inc.php
index f2966e4..856ba32 100644
--- a/htdocs/src/header.inc.php
+++ b/htdocs/src/header.inc.php
@@ -18,14 +18,35 @@
<div id="nav">
<ul>
- <li><a href="" class="button">Create Post</a></li>
- <li><a href="" class="button">Safety Tips</a></li>
- <li><a href="" class="button">Contact Us</a></li>
+ <li><a href="" class="bigbutton">Create Post</a></li>
+ <li><a href="" class="bigbutton">Safety Tips</a></li>
+ <li><a href="" class="bigbutton">Contact Us</a></li>
</ul>
</div>
<div id="buttonblock">
<p>What are you looking for?</p>
+ <div>
+ <a href="<?= $CONFIG['urlroot'] ?>/categories/forsale"><img src="<?= $CONFIG['urlroot'] ?>/images/tag.png" alt="For Sale" /></a>
+ <br />
+ <a href="<?= $CONFIG['urlroot'] ?>/categories/forsale" class="smallbutton">For Sale</a>
+ </div>
+ <div>
+ <a href="<?= $CONFIG['urlroot'] ?>/categories/events"><img src="<?= $CONFIG['urlroot'] ?>/images/calendar.png" alt="Events" /></a>
+ <br />
+ <a href="<?= $CONFIG['urlroot'] ?>/categories/events" class="smallbutton">Events</a>
+ </div>
+ <div>
+ <a href="<?= $CONFIG['urlroot'] ?>/categories/housing"><img src="<?= $CONFIG['urlroot'] ?>/images/house.png" alt="Housing" /></a>
+ <br />
+ <a href="<?= $CONFIG['urlroot'] ?>/categories/housing" class="smallbutton">Housing</a>
+ </div>
+ <div>
+ <a href="<?= $CONFIG['urlroot'] ?>/categories/jobs"><img src="<?= $CONFIG['urlroot'] ?>/images/jobs.png" alt="Jobs" /></a>
+ <br />
+ <a href="<?= $CONFIG['urlroot'] ?>/categories/jobs" class="smallbutton">Jobs</a>
+ </div>
+
</div>
<div id="content">