From cdaa5e28290fe0e9e73ca3a0557ee021a7ab404b Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 30 Mar 2012 21:15:31 +0200 Subject: [PATCH] paste deletion is possible now --- data/templates/delete.htm | 30 ++++++++++++++++++++++++++++++ data/templates/display.htm | 8 ++++++++ src/Phorkie/Repository.php | 17 ++++++++++++++++- src/Phorkie/Tools.php | 26 ++++++++++++++++++++++++++ www/.htaccess | 2 ++ www/delete.php | 23 +++++++++++++++++++++++ www/index.php | 2 +- 7 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 data/templates/delete.htm create mode 100644 src/Phorkie/Tools.php create mode 100644 www/delete.php diff --git a/data/templates/delete.htm b/data/templates/delete.htm new file mode 100644 index 0000000..ff27220 --- /dev/null +++ b/data/templates/delete.htm @@ -0,0 +1,30 @@ +{% extends "base.htm" %} +{% block title %} +Confirm deletion of repository #{{repo.id}} +{% endblock %} + +{% block content %} +

Delete paste #{{repo.id}}?

+
+

+ Do you really want to delete the folloing paste #{{repo.id}}? +

+

+ {{repo.getDescription}} +

+ +
+
+ Cancel +
+
+
+ +
+
+
+
+{% endblock %} diff --git a/data/templates/display.htm b/data/templates/display.htm index ca52775..2ba490e 100644 --- a/data/templates/display.htm +++ b/data/templates/display.htm @@ -34,6 +34,14 @@ {% endfor %} + +
+ +
{% endblock %} {% block sidebar %} diff --git a/src/Phorkie/Repository.php b/src/Phorkie/Repository.php index d9fc234..bcaf3e1 100644 --- a/src/Phorkie/Repository.php +++ b/src/Phorkie/Repository.php @@ -102,6 +102,17 @@ class Repository return true; } + /** + * Permanently deletes the paste repository without any way to get + * it back. + * + * @return boolean True if all went well, false if not + */ + public function delete() + { + return Tools::recursiveDelete($this->repoDir); + } + public function getDescription() { if (!is_readable($this->repoDir . '/.git/description')) { @@ -133,8 +144,12 @@ class Repository return '/' . $this->id; } else if ($type == 'fork') { return '/' . $this->id . '/fork'; + } else if ($type == 'delete') { + return '/' . $this->id . '/delete'; + } else if ($type == 'delete-confirm') { + return '/' . $this->id . '/delete/confirm'; } - throw new Exception('Unknown type'); + throw new Exception('Unknown link type'); } } diff --git a/src/Phorkie/Tools.php b/src/Phorkie/Tools.php new file mode 100644 index 0000000..8e67fe2 --- /dev/null +++ b/src/Phorkie/Tools.php @@ -0,0 +1,26 @@ + \ No newline at end of file diff --git a/www/.htaccess b/www/.htaccess index a058392..32701be 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -3,6 +3,8 @@ RewriteBase / #RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^([0-9]+)$ /display.php?id=$1 +RewriteRule ^([0-9]+)/delete$ /delete.php?id=$1 +RewriteRule ^([0-9]+)/delete/confirm$ /delete.php?id=$1&confirm=1 RewriteRule ^([0-9]+)/edit$ /edit.php?id=$1 RewriteRule ^([0-9]+)/fork$ /fork.php?id=$1 RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2 diff --git a/www/delete.php b/www/delete.php new file mode 100644 index 0000000..9feaf4e --- /dev/null +++ b/www/delete.php @@ -0,0 +1,23 @@ +loadFromRequest(); + +if (isset($_GET['confirm']) && $_GET['confirm'] == 1) { + if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + throw new Exception_Input('Deleting only possible via POST'); + } + $repo->delete(); + redirect('/'); +} + +render( + 'delete', + array('repo' => $repo) +); +?> diff --git a/www/index.php b/www/index.php index d33604d..9a03b77 100644 --- a/www/index.php +++ b/www/index.php @@ -21,4 +21,4 @@ $phork = array( '1' => new File(null, null) ); render('index', array('files' => $phork, 'description' => '')); -?> \ No newline at end of file +?> -- 2.30.2