summaryrefslogtreecommitdiff
path: root/htdocs/src
diff options
context:
space:
mode:
Diffstat (limited to 'htdocs/src')
-rw-r--r--htdocs/src/Post.inc.php69
-rw-r--r--htdocs/src/PostIterator.inc.php2
-rw-r--r--htdocs/src/config.inc.php5
3 files changed, 63 insertions, 13 deletions
diff --git a/htdocs/src/Post.inc.php b/htdocs/src/Post.inc.php
index 34230b2..c05cb7e 100644
--- a/htdocs/src/Post.inc.php
+++ b/htdocs/src/Post.inc.php
@@ -13,6 +13,7 @@ require_once "base.inc.php";
class Post {
private $info;
private $indatabase = false;
+ private $images;
public function __construct($info=null) {
@@ -24,6 +25,8 @@ class Post {
} else {
$this->indatabase = false;
}
+
+ $images = null;
}
public static function getById($id) {
@@ -38,6 +41,12 @@ class Post {
return Post::getPost($where);
}
+ public static function getByImage($imgid) {
+ $where = "id=(SELECT post_id FROM image WHERE id='$imgid')";
+
+ return Post::getPost($where);
+ }
+
private static function getPost($where) {
$query = "SELECT *, UNIX_TIMESTAMP(created) AS createdts FROM post WHERE $where";
@@ -150,6 +159,10 @@ class Post {
return $this->info['created'];
}
+ public function getTimestamp() {
+ return $this->info['createdts'];
+ }
+
public function getEmail() {
return $this->info['email'];
}
@@ -186,24 +199,60 @@ class Post {
return $this->info['location'];
}
- public function addImage($file) {
- // TODO: Verify file type
+ public function getImages() {
+ if ($this->images == null) {
+ $this->loadImages();
+ }
- // TODO: Unique name for file.
- $newfile = $GLOBALS['CONFIG']['uploads'];
+ return $this->images;
+ }
- if (move_uploaded_file($file, $newfile)) {
- return true;
+ public function addImage($file) {
+ // Verify file type
+ $info = @getimagesize($file);
- } else {
+ if (!$info) {
return false;
}
+
+ // TODO Verify image dimensions?
+
+ // Get image id
+ $db = getDatabase();
+ try {
+ $id = $db->insert('image', array('post_id' => $this->getId()));
+ $newfile = $GLOBALS['CONFIG']['uploads'] . "/$id";
+
+ if (move_uploaded_file($file, $newfile)) {
+ // Invalidate the image cache
+ $this->images = null;
+
+ return true;
+ }
+
+ } catch (Cif_Database_Exception $e) {
+
+ }
+
+ return false;
+ }
+
+ private function loadImages() {
+ $query = "SELECT id FROM image WHERE post_id='". $this->getId() ."'";
+
+ $db = getDatabase();
+ $imgs = $db->fetchAssocRows($query);
+
+ $this->images = array();
+ foreach ($imgs as $img) {
+ $this->images[] = $img['id'];
+ }
}
public function sendValidation() {
$email = new Email($this->getEmail());
- $email->setSubject($GLOBAL['CONFIG']['sitetitle'] . " Email Validation");
+ $email->setSubject($GLOBALS['CONFIG']['sitetitle'] . " Email Validation");
$url = $GLOBALS['CONFIG']['urlroot'] . '/validate.php?id=' . $this->getSecretId();
@@ -216,7 +265,7 @@ class Post {
public function sendAcceptance() {
$email = new Email($this->getEmail());
- $email->setSubject($GLOBAL['CONFIG']['sitetitle'] . " Posting Approved");
+ $email->setSubject($GLOBALS['CONFIG']['sitetitle'] . " Posting Approved");
$email->appendMessage("Your posting titled ". $this->getName()
." has been approved by our moderation team.\n\n");
@@ -231,7 +280,7 @@ class Post {
public function sendRejection($message='') {
$email = new Email($this->getEmail());
- $email->setSubject($GLOBAL['CONFIG']['sitetitle'] . " Posting Rejected");
+ $email->setSubject($GLOBALS['CONFIG']['sitetitle'] . " Posting Rejected");
$email->appendMessage("Your posting titled ". $this->getName()
." has been rejected by our moderation team.\n\n");
diff --git a/htdocs/src/PostIterator.inc.php b/htdocs/src/PostIterator.inc.php
index cced79b..43c1a05 100644
--- a/htdocs/src/PostIterator.inc.php
+++ b/htdocs/src/PostIterator.inc.php
@@ -42,7 +42,7 @@ class PostIterator implements Iterator {
}
public function limit($limit) {
- $this->limit = limit;
+ $this->limit = $limit;
}
public function rewind() {
diff --git a/htdocs/src/config.inc.php b/htdocs/src/config.inc.php
index 211a798..829c632 100644
--- a/htdocs/src/config.inc.php
+++ b/htdocs/src/config.inc.php
@@ -19,11 +19,12 @@ $CONFIG = array(
'sitetitle' => 'Foursquare Community',
'email_from' => 'community@myfoursquarechurch.com',
- 'urlroot' => 'http://localhost/~jesse/p4s/community/htdocs',
+ 'urlroot' => '/~jesse/p4s/community/htdocs',
'root' => '/home/jesse/Development/p4square/community/htdocs',
+ 'uploads' => '/home/jesse/Development/p4square/community/uploads',
'debug' => true,
- 'production' => false,
+ 'production' => true,
);
set_include_path(get_include_path() . PATH_SEPARATOR . $CONFIG['root'].'/src');