From 9ad57b3d8d1000f17962bb0ba00a8958b2f141db Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Wed, 1 Jun 2011 12:15:26 -0700 Subject: Added scripts, email addresses, other minor modifications --- htdocs/deletepost.php | 57 +++++++++++++++++++++++++++++++++++++++ htdocs/postings.php | 2 ++ htdocs/src/Post.inc.php | 34 ++++++++++++++++++----- htdocs/src/PostIterator.inc.php | 10 +++++++ htdocs/src/base.inc.php | 5 ++++ htdocs/src/config.inc.php.example | 1 + 6 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 htdocs/deletepost.php (limited to 'htdocs') diff --git a/htdocs/deletepost.php b/htdocs/deletepost.php new file mode 100644 index 0000000..7ebec19 --- /dev/null +++ b/htdocs/deletepost.php @@ -0,0 +1,57 @@ + + * + */ + +require_once "src/base.inc.php"; + +require_once "src/header.inc.php"; + +// Make sure we have all the needed information +if (!isset($_GET['id']) or !is_numeric($_GET['id']) + or !isset($_GET['secret'])) { + errorNotFound(); +} + +// Get the post. +$post = Post::getById($_GET['id']); + +// Got a post with the right secretid? +if (!$post and $post->getSecretId() == $_GET['secret']) { + errorNotFound(); +} + +if (isset($_GET['confirmed'])) { + // Delete post + $post->delete(); + + echo "

Your post has been removed.

"; + + echo "

Return to homepage.

"; + +} else { + // Are you sure... + echo "

Are you sure you want to remove your posting titled " + . $post->getName() ."?

"; + echo "

Yes, delete it "; + echo "No, do not delete

"; +} + +require_once "src/footer.inc.php"; + +function errorNotFound() { + // TODO: Better 404 error + echo "404"; + exit; +} + +?> + diff --git a/htdocs/postings.php b/htdocs/postings.php index 7550e18..ee178cb 100644 --- a/htdocs/postings.php +++ b/htdocs/postings.php @@ -51,6 +51,8 @@ if (isset($_GET['moderate'])) { echo "

". $post->getName() ."

"; echo "

Date: ". date('r', $post->getTimestamp()) ."

"; +echo "

Email: getPublicEmail() ."\">" + . $post->getPublicEmail() ."

"; echo "

". str_replace("\n", '
', $post->getDescription()) diff --git a/htdocs/src/Post.inc.php b/htdocs/src/Post.inc.php index c05cb7e..4a109d2 100644 --- a/htdocs/src/Post.inc.php +++ b/htdocs/src/Post.inc.php @@ -88,7 +88,7 @@ class Post { } else { // Creating... set special fields. $info['stage'] = 'verification'; - $info['secretid'] = uniqid(); + $info['secretid'] = uniqid('', true); $info['created'] = date('Y-m-d H:i:s'); try { @@ -108,6 +108,16 @@ class Post { } } + public function delete() { + $db = getDatabase(); + + // Delete Images + $db->delete('image', 'post_id=' . $this->getId()); + + // Delete Post + $db->delete('post', 'id=' . $this->getId()); + } + public function getId() { return $this->info['id']; } @@ -167,6 +177,10 @@ class Post { return $this->info['email']; } + public function getPublicEmail() { + return 'posting-' . $this->getId() .'@'. $GLOBALS['CONFIG']['emaildomain']; + } + public function setEmail($value) { $this->info['email'] = $value; } @@ -254,7 +268,7 @@ class Post { $email->setSubject($GLOBALS['CONFIG']['sitetitle'] . " Email Validation"); - $url = $GLOBALS['CONFIG']['urlroot'] . '/validate.php?id=' . $this->getSecretId(); + $url = buildUrl('validate.php?id=' . $this->getSecretId()); $email->appendMessage("Please click on the link below to verify your email address.\n\n"); $email->appendMessage($url); @@ -265,14 +279,22 @@ class Post { public function sendAcceptance() { $email = new Email($this->getEmail()); - $email->setSubject($GLOBALS['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"); - $url = $GLOBALS['CONFIG']['urlroot'] . '/postings/' - . $this->getId() .'.html'; - $email->appendMessage("You can view your post at $url."); + // View URL + $url = buildUrl('postings/' . $this->getId() . '.html'); + $email->appendMessage("You can view your post at $url.\n\n"); + + // Delete URL + $url = buildUrl('deletepost.php?id=' . $this->getId() + . '&secret=' . $this->getSecretId()); + $email->appendMessage("Your posting will expire in " . + $GLOBALS['CONFIG']['expiretime'] + . " days. If you would like to remove it sooner, go to $url.\n"); $email->send(); } diff --git a/htdocs/src/PostIterator.inc.php b/htdocs/src/PostIterator.inc.php index 43c1a05..a269853 100644 --- a/htdocs/src/PostIterator.inc.php +++ b/htdocs/src/PostIterator.inc.php @@ -37,6 +37,16 @@ class PostIterator implements Iterator { $this->where[] = "category_id='$category_id'"; } + public function filterCreated($after, $before = false) { + $sqlafter = date('Y-m-d H:i:s', $after); + $this->where[] = "created > '$sqlafter'"; + + if ($before !== false) { + $sqlbefore = date('Y-m-d H:i:s', $before); + $this->where[] = "created < '$sqlbefore'"; + } + } + public function orderBy($order) { $this->order = $order; } diff --git a/htdocs/src/base.inc.php b/htdocs/src/base.inc.php index d7a9354..7d48ca7 100644 --- a/htdocs/src/base.inc.php +++ b/htdocs/src/base.inc.php @@ -41,5 +41,10 @@ function __autoload($class) { require_once "$class.inc.php"; } +function buildUrl($tail='') { + return 'http://' . $GLOBALS['CONFIG']['domain'] + . $GLOBALS['CONFIG']['urlroot'] . "/$tail"; +} + ?> diff --git a/htdocs/src/config.inc.php.example b/htdocs/src/config.inc.php.example index d0d912c..0a4a8d4 100644 --- a/htdocs/src/config.inc.php.example +++ b/htdocs/src/config.inc.php.example @@ -20,6 +20,7 @@ $CONFIG = array( 'email_from' => 'community@myfoursquarechurch.com', 'emaildomain' => 'listandshare.com', + 'domain' => 'localhost', 'urlroot' => '/~jesse/p4s/community/htdocs', 'root' => '/Users/jesse/Development/P4Square/community/htdocs', 'uploads' => '/Users/jesse/Development/P4Square/community/uploads', -- cgit v1.2.3