aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-03-30 21:15:31 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-03-30 21:15:31 +0200
commitcdaa5e28290fe0e9e73ca3a0557ee021a7ab404b (patch)
tree5cb6ba6f05bb5cafd8735775ddfeda78923f4940
parent8fadde4a3b26523b15ff019cafc1b49f9143293f (diff)
downloadphorkie-cdaa5e28290fe0e9e73ca3a0557ee021a7ab404b.tar.gz
phorkie-cdaa5e28290fe0e9e73ca3a0557ee021a7ab404b.zip
paste deletion is possible now
-rw-r--r--data/templates/delete.htm30
-rw-r--r--data/templates/display.htm8
-rw-r--r--src/Phorkie/Repository.php17
-rw-r--r--src/Phorkie/Tools.php26
-rw-r--r--www/.htaccess2
-rw-r--r--www/delete.php23
-rw-r--r--www/index.php2
7 files changed, 106 insertions, 2 deletions
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 %}
+<h1>Delete paste #{{repo.id}}?</h1>
+<div class="well" style="margin-top: 5ex;">
+ <p>
+ Do you really want to delete the folloing paste #{{repo.id}}?
+ </p>
+ <p>
+ <strong>{{repo.getDescription}}</strong>
+ </p>
+
+ <div class="row-fluid" style="margin-top: 5ex;">
+ <div class="span6">
+ <a class="btn" href="{{repo.getLink('display')}}">Cancel</a>
+ </div>
+ <div class="span6" style="text-align: right">
+ <form method="post" action="{{repo.getLink('delete-confirm')}}" style="margin: 0px">
+ <button class="btn btn-danger" type="submit">
+ <i class="icon-trash icon-white"></i>
+ Permanently delete
+ </button>
+ </form>
+ </div>
+ </div>
+</div>
+{% 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 @@
</div>
</div>
{% endfor %}
+
+<div class="row-fluid" style="margin-top: 5ex">
+ <div class="span12" style="text-align: right;">
+ <a class="btn btn-warning" href="{{repo.getLink('delete')}}">
+ <i class="icon-trash icon-white"></i> Delete
+ </a>
+ </div>
+</div>
{% 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 @@
+<?php
+namespace Phorkie;
+
+
+class Tools
+{
+ public static function recursiveDelete($path)
+ {
+ if (!is_dir($path) || is_link($path)) {
+ return unlink($path);
+ }
+ foreach (scandir($path) as $file) {
+ if ($file == '.' || $file == '..') {
+ continue;
+ }
+ $filepath = $path . DIRECTORY_SEPARATOR . $file;
+ if (!static::recursiveDelete($filepath)) {
+ return false;
+ };
+ }
+ return rmdir($path);
+ }
+
+}
+
+?> \ 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 @@
+<?php
+namespace Phorkie;
+/**
+ * Delete paste or ask for deletion
+ */
+require_once 'www-header.php';
+
+$repo = new Repository();
+$repo->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
+?>