summaryrefslogtreecommitdiff
path: root/htdocs/src
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-06-02 17:20:54 -0700
committerJesse Morgan <jesse@jesterpm.net ; true>2011-06-02 17:20:54 -0700
commit0720091ca73b9714aab2b38c3682c15a0cbd4533 (patch)
tree0d77e48eb52d3f39123659550976c5999effddff /htdocs/src
parent1800a1e9022a9f4316e0d57a650faed9da0e8df4 (diff)
Added pages
Diffstat (limited to 'htdocs/src')
-rw-r--r--htdocs/src/Page.inc.php132
-rw-r--r--htdocs/src/PageIterator.inc.php79
-rw-r--r--htdocs/src/header.inc.php4
3 files changed, 213 insertions, 2 deletions
diff --git a/htdocs/src/Page.inc.php b/htdocs/src/Page.inc.php
new file mode 100644
index 0000000..edb0583
--- /dev/null
+++ b/htdocs/src/Page.inc.php
@@ -0,0 +1,132 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "base.inc.php";
+
+class Page {
+ private $info;
+ private $indatabase;
+
+ public function __construct($info=null) {
+ $this->info = is_null($info) ? array() : $info;
+
+ if ($info !== null and isset($info['id'])) {
+ $this->indatabase = true;
+
+ } else {
+ $this->indatabase = false;
+ }
+ }
+
+ public static function getById($id) {
+ $where = "id='$id'";
+
+ return Page::getPage($where);
+ }
+
+ public static function getByUrl($url) {
+ $where = "url='$url'";
+
+ return Page::getPage($where);
+ }
+
+ private static function getPage($where) {
+ $query = "SELECT * FROM page WHERE $where";
+
+ $db = getDatabase();
+
+ $row = $db->fetchAssocRow($query);
+
+ if ($row) {
+ $page = new Page();
+ $page->info = $row;
+ $page->indatabase = true;
+
+ return $page;
+
+ } else {
+ return false;
+ }
+ }
+
+ public function save() {
+ $db = getDatabase();
+
+ // Cleanup Info
+ foreach ($this->info as $key=>$value)
+ $info[$key] = addslashes($value);
+
+ // Save or create?
+ if ($this->indatabase) {
+ try {
+ $db->update('page', $info, "WHERE `id`='"
+ . $this->getId() ."'");
+ return true;
+
+ } catch (Cif_Database_Exception $e) {
+ return false;
+ }
+
+ } else {
+ // Creating...
+ try {
+ $ret = $db->insert('page', $info);
+
+ if ($ret) {
+ $this->info['id'] = $ret;
+ $this->indatabase = true;
+ }
+
+ return true;
+
+ } catch (Cif_Database_Exception $e) {
+ return false;
+ }
+ }
+ }
+
+ public function delete() {
+ $db = getDatabase();
+
+ $db->delete('page', 'id=' . $this->getId());
+
+ $this->indatabase = false;
+ }
+
+ public function getId() {
+ return $this->info['id'];
+ }
+
+ public function getTitle() {
+ return $this->info['title'];
+ }
+
+ public function setTitle($value) {
+ $this->info['title'] = $value;
+ }
+
+ public function getURL() {
+ return $this->info['url'];
+ }
+
+ public function setURL($value) {
+ $this->info['url'] = $value;
+ }
+
+ public function getContent() {
+ return $this->info['content'];
+ }
+
+ public function setContent($value) {
+ $this->info['content'] = $value;
+ }
+}
+
+?>
diff --git a/htdocs/src/PageIterator.inc.php b/htdocs/src/PageIterator.inc.php
new file mode 100644
index 0000000..080c4db
--- /dev/null
+++ b/htdocs/src/PageIterator.inc.php
@@ -0,0 +1,79 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "base.inc.php";
+
+class PageIterator 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 = "title asc";
+ $this->limit = 0;
+ }
+
+ public function orderBy($order) {
+ $this->order = $order;
+ }
+
+ public function limit($limit) {
+ $this->limit = $limit;
+ }
+
+ public function rewind() {
+ $this->position = 0;
+ }
+
+ public function current() {
+ return new Page($this->rows[$this->position]);
+ }
+
+ public function key() {
+ return $this->rows[$this->position]['id'];
+ }
+
+ public function next() {
+ ++$this->position;
+ }
+
+ public function valid() {
+ return isset($this->rows[$this->position]);
+ }
+
+ public function query() {
+ $query = "SELECT * FROM page";
+
+ 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);
+ $this->position = 0;
+ }
+}
+
+?>
+
+
diff --git a/htdocs/src/header.inc.php b/htdocs/src/header.inc.php
index 3d7f4b0..db5906d 100644
--- a/htdocs/src/header.inc.php
+++ b/htdocs/src/header.inc.php
@@ -23,8 +23,8 @@
<ul>
<li><a href="<?= $CONFIG['urlroot'] ?>/new-post" class="bigbutton">
Create Post</a></li>
- <li><a href="" class="bigbutton">Safety Tips</a></li>
- <li><a href="" class="bigbutton">Contact Us</a></li>
+ <li><a href="<?= buildUrl('page/safety.html') ?>" class="bigbutton">Safety Tips</a></li>
+ <li><a href="<?= buildUrl('page/contact.html') ?>" class="bigbutton">Contact Us</a></li>
</ul>
</div>