From 69e4391bfb53ce2d7a3a42f69e37bbf136d3ee09 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 6 Jul 2015 23:10:18 +0200 Subject: [PATCH] Add "add file" button to display page --- data/templates/display-foot.htm | 9 ++++++++- data/templates/edit.htm | 6 +++++- src/phorkie/Repository/Post.php | 11 +++++++++++ www/edit.php | 18 ++++++++++++++++-- 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/data/templates/display-foot.htm b/data/templates/display-foot.htm index 3a53adf..6324509 100644 --- a/data/templates/display-foot.htm +++ b/data/templates/display-foot.htm @@ -1,5 +1,12 @@
-
+
+ +
Delete paste diff --git a/data/templates/edit.htm b/data/templates/edit.htm index 870ef23..912a073 100644 --- a/data/templates/edit.htm +++ b/data/templates/edit.htm @@ -7,7 +7,7 @@ {% block content %}
-
+
@@ -21,6 +21,10 @@ {% endif %} {% endfor %} + {% if singlefile == "newfile" %} + {% include 'edit-file.htm' with {'file': null, 'fileid': 'newfile', 'newfile': true} %} + {% endif %} + {% include 'edit-add.htm' %}
diff --git a/src/phorkie/Repository/Post.php b/src/phorkie/Repository/Post.php index a61f2a2..511a83c 100644 --- a/src/phorkie/Repository/Post.php +++ b/src/phorkie/Repository/Post.php @@ -5,6 +5,16 @@ class Repository_Post { public $repo; + /** + * When a new file is created during processing, its name + * is stored here for later use. + * + * @var string + */ + public $newfileName; + + + public function __construct(Repository $repo = null) { $this->repo = $repo; @@ -76,6 +86,7 @@ class Repository_Post //automatically append file extension if none is there $name .= '.' . $arFile['type']; } + $this->newfileName = $name; } else if (!$this->repo->hasFile($orignalName)) { //unknown file //FIXME: Show error message diff --git a/www/edit.php b/www/edit.php index 33b22c2..e7e6fbc 100644 --- a/www/edit.php +++ b/www/edit.php @@ -11,18 +11,31 @@ $repo->loadFromRequest(); $file = null; if (isset($_GET['file'])) { - $file = $repo->getFileByName($_GET['file']); + if ($_GET['file'] == 'newfile') { + $file = 'newfile'; + } else { + $file = $repo->getFileByName($_GET['file']); + } } $repopo = new Repository_Post($repo); if ($repopo->process($_POST, $_SESSION)) { $anchor = ''; - if ($file !== null) { + if ($file instanceof File) { $anchor = '#' . $file->getAnchorName(); + } else if ($file === 'newfile' && $repopo->newfileName) { + $anchor = '#' . $repo->getFileByName($repopo->newfileName)->getAnchorName(); } redirect($repo->getLink('display', null, true) . $anchor); } +$actionFile = null; +if ($file instanceof File) { + $actionFile = $file->getFilename(); +} else if ($file === 'newfile') { + $actionFile = 'newfile'; +} + render( 'edit', array( @@ -30,6 +43,7 @@ render( 'singlefile' => $file, 'dh' => new \Date_HumanDiff(), 'htmlhelper' => new HtmlHelper(), + 'formaction' => $repo->getLink('edit', $actionFile) ) ); ?> -- 2.30.2