preparation for file editing
authorChristian Weiske <cweiske@cweiske.de>
Wed, 28 Mar 2012 14:59:54 +0000 (16:59 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 28 Mar 2012 14:59:54 +0000 (16:59 +0200)
data/templates/edit-file.htm [new file with mode: 0644]
data/templates/edit.htm [new file with mode: 0644]
data/templates/index.htm
src/Phorkie/File.php
www/.htaccess
www/edit.php [new file with mode: 0644]
www/index.php

diff --git a/data/templates/edit-file.htm b/data/templates/edit-file.htm
new file mode 100644 (file)
index 0000000..66647f0
--- /dev/null
@@ -0,0 +1,19 @@
+ <div class="well">
+  <div class="row-fluid">
+   <div class="span6">
+    <label for="filename_1">Filename</label>
+    <input type="text" name="files[{{fileid}}][name]" id="filename_{{fileid}}" value="{{ file.getFilename }}"/>
+   </div>
+   <div class="span6" style="text-align: right">
+    <label for="type_{{fileid}}">Type</label>
+    <!-- fixme: preselect -->
+    <select name="files[{{fileid}}][type]" id="type_{{fileid}}">
+     <option value="css">CSS</option>
+     <option value="php">PHP</option>
+     <option value="xml">XML</option>
+    </select>
+   </div>
+  </div>
+  <textarea name="files[{{fileid}}][content]" id="content_1" cols="80" rows="10" class="content">{{ file.getContent }}</textarea>
+ </div>
+
diff --git a/data/templates/edit.htm b/data/templates/edit.htm
new file mode 100644 (file)
index 0000000..56e08ef
--- /dev/null
@@ -0,0 +1,23 @@
+{% extends "base.htm" %}
+{% block title %}Edit paste{% endblock %}
+
+{% block content %}
+<form method="post" action="/">
+ <div class="control-group well pastedata">
+   <label for="description">Description</label>
+   <input type="text" name="description" id="description" value="{{repo.getDescription}}"/>
+ </div>
+
+ {% for fileid, file in repo.getFiles %}
+  {% include 'edit-file.htm' with {'file': file, 'fileid': fileid} %}
+ {% endfor %}
+
+ <div class="well" style="text-align: right">
+  <button class="btn btn-primary" type="submit">
+   <i class="icon-check icon-white"></i>
+   Save
+  </button>
+ </div>
+
+</form>
+{% endblock %}
index c239d56..05989df 100644 (file)
@@ -8,23 +8,7 @@
    <input type="text" name="description" id="description" value="{{description}}"/>
  </div>
 
- <div class="well">
-  <div class="row-fluid">
-   <div class="span6">
-    <label for="filename_1">Filename</label>
-    <input type="text" name="file[1][name]" id="filename_1" value="{{ file[1]['name'] }}"/>
-   </div>
-   <div class="span6" style="text-align: right">
-    <label for="type_1">Type</label>
-    <select name="file[1][type]" id="type_1">
-     <option value="css">CSS</option>
-     <option value="php">PHP</option>
-     <option value="xml">XML</option>
-    </select>
-   </div>
-  </div>
-  <textarea name="file[1][content]" id="content_1" cols="80" rows="10" class="content">{{ file[1]['content'] }}</textarea>
- </div>
+ {% include 'edit-file.htm' with {'file': file[1], 'fileid': 1} %}
 
  <div class="well" style="text-align: right">
   <button class="btn btn-primary" type="submit">
index bf2eb60..6cdc833 100644 (file)
@@ -42,7 +42,7 @@ class File
         'html' => 'xml',
     );
 
-    public function __construct($path, Repository $repo)
+    public function __construct($path, Repository $repo = null)
     {
         $this->path = $path;
         $this->repo = $repo;
index d053ca7..c5353dd 100644 (file)
@@ -3,7 +3,9 @@ RewriteBase /
 #RewriteCond %{REQUEST_FILENAME} -f
 
 RewriteRule ^([0-9]+)$ /display.php?id=$1
-RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2
+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
+
 RewriteRule ^list$ /list.php
 RewriteRule ^list/([0-9])+$ /list.php?page=$1
diff --git a/www/edit.php b/www/edit.php
new file mode 100644 (file)
index 0000000..d86df41
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+namespace Phorkie;
+/**
+ * Edit paste contents
+ */
+require_once 'www-header.php';
+
+$repo = new Repository();
+$repo->loadFromRequest();
+
+render(
+    'edit',
+    array(
+        'repo' => $repo,
+    )
+);
+?>
index 044ac35..f821c84 100644 (file)
@@ -12,7 +12,7 @@ namespace Phorkie;
  */
 require_once 'www-header.php';
 
-if (isset($_POST['file'])) {
+if (isset($_POST['files'])) {
     //save
     $rs = new Repositories();
     $repo = $rs->createNew();
@@ -23,7 +23,7 @@ if (isset($_POST['file'])) {
     }
     file_put_contents($repo->repoDir . '.git/description', $_POST['description']);
 
-    foreach ($_POST['file'] as $num => $arFile) {
+    foreach ($_POST['files'] as $num => $arFile) {
         if ($arFile['name'] != '') {
             $fname = $arFile['name'];
         } else {
@@ -45,11 +45,7 @@ if (isset($_POST['file'])) {
 }
 
 $phork = array(
-    '1' => array(
-        'filename' => '',
-        'content' => '',
-        'type' => ''
-    )
+    '1' => new File(null, null)
 );
-render('index', array('file' => $phork, 'description' => ''));
+render('index', array('files' => $phork, 'description' => ''));
 ?>
\ No newline at end of file