--- /dev/null
+{% 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 %}
</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 %}
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')) {
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');
}
}
--- /dev/null
+<?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
#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
--- /dev/null
+<?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)
+);
+?>
'1' => new File(null, null)
);
render('index', array('files' => $phork, 'description' => ''));
-?>
\ No newline at end of file
+?>