Skip to content

Instantly share code, notes, and snippets.

@jamsesso
Created July 9, 2011 20:24
Show Gist options
  • Save jamsesso/1073932 to your computer and use it in GitHub Desktop.
Save jamsesso/1073932 to your computer and use it in GitHub Desktop.
<?php
require '../engine.php';
system::import('blog');
if(http::get('article'))
{
$article = blog::get_article(http::get('article'));
$article or page_not_found();
system::import('comments');
if(http::post_request() and http::submitted('comment'))
{
signed_in or page_not_found();
if(strlen(trim(http::post('comment'))) < 1)
redirect(link_to('blog', null, array('article' => $article['blogID'])), 'Please enter a longer comment.', 0);
comments::post('blog', http::get('article'), http::post('comment'));
blog::update_comments(http::get('article'));
if($user['userID'] != $article['userID'])
{
$article_link = link_to('blog', $article['title'], array('article' => $article['blogID']));
$comment = http::post('comment');
$message = <<<DOC
{$user['name']} commented on your blog article, {$article_link}
"{$comment}"
DOC;
inbox::send($article['user'], $message);
}
redirect(link_to('blog', null, array('article' => $article['blogID'])), 'Your comment has been posted!', 1);
}
else
{
templates::load('header', array(
'title' => $article['title']
));
templates::load('blog.view', array(
'article' => $article,
'comments' => comments::load_for('blog', http::get('article'))
));
templates::load('footer');
}
}
else
{
templates::load('header', array(
'title' => 'Blog'
));
templates::load('blog.main');
templates::load('footer');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment