Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Yay! You can delete posts now!

  • Loading branch information...
commit c87b27af6271d28d1b59957d8a06894351a3ba5c 1 parent e4f6ad5
@damianb authored
View
82 app/src/codebite/homebooru/Controller/PostDeleteController.php
@@ -0,0 +1,82 @@
+<?php
+namespace codebite\homebooru\Controller;
+use \codebite\homebooru\Internal\SubmitFailException;
+use \codebite\homebooru\Model\BooruPostModel;
+use \codebite\homebooru\Model\BooruTagModel;
+use \R;
+
+if(!defined('SHOT_ROOT')) exit;
+
+class PostDeleteController
+ extends BaseController
+{
+ protected $cacheable = false;
+
+ public function before()
+ {
+ $this->app->form->setFormSeed($this->app->session->getSessionSeed());
+ }
+
+ public function runController()
+ {
+ $success = $submit = false;
+ $id = $this->getInput('GET::id', 0);
+
+ $bean = R::findOne('post', 'status = ? AND id = ?', array(BooruPostModel::ENTRY_ACCEPT, $id));
+
+ if(empty($bean->id))
+ {
+ return $this->respond('error.twig.html', 404, array(
+ 'error' => array(
+ 'message' => 'Not found',
+ 'code' => 404,
+ ),
+ ));
+ }
+
+ if($this->wasInputSet('POST::submit'))
+ {
+ $submit = true;
+ R::begin();
+ try {
+ $form_key = $this->getInput('POST::formkey', '');
+ $form_time = $this->getInput('POST::formtime', 0);
+
+ if(!$this->app->form->checkFormKey($form_key, $form_time, 'deletepost'))
+ {
+ throw new SubmitFailException('Invalid form key submitted');
+ }
+
+ R::trash($bean);
+ R::commit();
+
+ $success = true;
+ }
+ catch(SubmitFailException $e)
+ {
+ R::rollback();
+ $success = false;
+ }
+ catch(\Exception $e)
+ {
+ R::rollback();
+ $success = false;
+ }
+ }
+
+ return $this->respond('deletepost.twig.html', 200, array(
+ 'page' => array(
+ 'delete' => true,
+ ),
+ 'post' => $bean,
+
+ 'form' => array(
+ 'submit' => $submit,
+ 'success' => $success,
+ 'error' => ($submit && !$success) ? $e->getMessage() : false,
+ 'time' => $this->app->form->getFormTime(),
+ 'key' => $this->app->form->buildFormKey('deletepost')
+ ),
+ ));
+ }
+}
View
51 app/views/deletepost.twig.html
@@ -0,0 +1,51 @@
+{% extends "layout.twig.html" %}
+{% block content %}
+ {% if form.submit and not form.success -%}
+ <div class="alert alert-error">
+ <a class="close" data-dismiss="alert">&#215;</a>
+ <h4 class="alert-heading">Error</h4>
+ {{ form.error }}
+ </div>
+ {%- endif %}
+
+ {% if form.submit and form.success %}
+ <div class="alert alert-success">
+ <h4 class="alert-heading">Form submitted successfully</h4>
+ The entry was successfully deleted.
+ </div>
+ {% endif %}
+
+ {% if (form.submit and not form.success) or not form.submit %}
+ <h2>delete image</h2>
+ <div class="deletepost">
+ <div class="pull-left">
+ <ul class="thumbnails">
+ <li class="img span3">
+ <a href="{{ url.archive_id(post.id) }}" class="thumbnail" style="width:{{ post.thumb_width + 2 }}px; height:{{ post.thumb_height + 2 }}px">
+ <img src="{{ site.thumburl ~ post.thumb_file }}" alt="" title="{% for tag in post.getTags() %}{{ tag.title }} {% endfor %}" style="height: {{ post.thumb_height }}px; width: {{ post.thumb_width }}px">
+ </a>
+ </li>
+ </ul>
+ </div>
+
+ <div class="pull-right span9">
+ <form class="form-horizontal" id="deletepost" action="{{ url.delete(post.id) }}" method="post">
+ <div class="well">
+ <fieldset>
+ <h3>Warning</h3>
+ <div>You are about to permanently delete this post and all associated data.</div><hr><br>
+
+ <input type="hidden" name="id" value="{{ post.id }}">
+ <input type="hidden" name="formkey" value="{{ form.key }}">
+ <input type="hidden" name="formtime" value="{{ form.time }}">
+ <input type="hidden" name="submit" value="1">
+ <button type="submit" class="btn btn-danger">Delete post</button>
+ </fieldset>
+ </div>
+ </form>
+ </div>
+ <div class="clear"></div>
+ </div>
+ {% endif %}
+
+{% endblock %}
View
2  app/views/editpost.twig.html
@@ -19,7 +19,7 @@ <h4 class="alert-heading">Form submitted successfully</h4>
<ul class="thumbnails">
<li class="img span3">
<a href="{{ url.archive_id(post.id) }}" class="thumbnail" style="width:{{ post.thumb_width + 2 }}px; height:{{ post.thumb_height + 2 }}px">
- <img src="{{ site.thumburl ~ post.thumb_file }}" alt="{{ post.getTags()|join(' ') }}" title="{{ post.getTags()|join(' ') }}" style="height: {{ post.thumb_height }}px; width: {{ post.thumb_width }}px">
+ <img src="{{ site.thumburl ~ post.thumb_file }}" alt="" title="{% for tag in post.getTags() %}{{ tag.title }} {% endfor %}" style="height: {{ post.thumb_height }}px; width: {{ post.thumb_width }}px">
</a>
</li>
</ul>
View
2  app/views/viewposts.twig.html
@@ -8,7 +8,7 @@
<div class="pull-left span2 posts-adjust-left">
<ul class="side-tags">
{% for tag in post_tags %}
- {% if tag.getEncounters()|length > 1 %}
+ {% if tag.getEncounters()|length > 2 %}
<li>{% if page.search %}<a href="#">+</a> <a href="#">-</a> {% endif %}<a class="tag-text tag-text-{{ tag.getType() }}" href="{{ url.search_tag(tag.title|url_encode) }}" title="{{ tag.getDescription() }}">{{ tag.title|replace({'_':' '}) }}</a> <span class="tag-count">{{ tag.tag_count }}</span></li>
{% endif %}
{% endfor %}
View
2  config/controllers.json
@@ -11,7 +11,7 @@
"site.controller.search":"codebite\\homebooru\\Controller\\PostSearchController",
"site.controller.edit":"codebite\\homebooru\\Controller\\PostEditController",
"site.controller.single":"codebite\\homebooru\\Controller\\PostViewController",
- #"site.controller.delete":"codebite\\homebooru\\Controller\\PostDeleteController",
+ "site.controller.delete":"codebite\\homebooru\\Controller\\PostDeleteController",
#"site.controller.pool":"codebite\\homebooru\\Controller\\PoolArchiveController",
#"site.controller.pool.create":"codebite\\homebooru\\Controller\\PoolCreateController",
Please sign in to comment.
Something went wrong with that request. Please try again.