proper type dropdown for files now
[phorkie.git] / www / index.php
index 5276bf2c96f6c14f436f34eec566006357317754..898c443a72309ce53097286fc1a74f845855e280 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+namespace Phorkie;
 /**
  * Show paste creation form
  *
  */
 require_once 'www-header.php';
 
-if (isset($_POST['file'])) {
-    //save
-    $repoDir = $GLOBALS['phorkie']['cfg']['repos'];
-    $n = count(glob($repoDir . '/*', GLOB_ONLYDIR));
-    $dir = $repoDir . '/' . $n . '/'; 
-    mkdir($dir, 0777);//FIXME
-    $vc = new VersionControl_Git($dir);
-    $vc->initRepository();
-    file_put_contents($dir . '.git/description', $_POST['description']);
-
-    foreach ($_POST['file'] as $num => $arFile) {
-        if ($arFile['name'] != '') {
-            $fname = $arFile['name'];
-        } else {
-            $fname = 'phork' . $num . '.' . $arFile['type'];
-        }
-        $fpath = $dir . $fname;
-        file_put_contents($fpath, $arFile['content']);
-        //fixme: let the class do that when it is able to
-        $command = $vc->getCommand('add')
-            ->addArgument($fname)
-            ->execute();
-    }
-    $command = $vc->getCommand('commit')
-        ->setOption('message', 'initial paste')
-        ->execute();
-    //redirect to phork
-    redirect($n);
+$repopo = new Repository_Post();
+if ($repopo->process($_POST)) {
+    redirect($repopo->repo->getLink('display'));
 }
 
 $phork = array(
-    '1' => array(
-        'filename' => '',
-        'content' => '',
-        'type' => ''
+    '1' => new File(null, null)
+);
+render(
+    'index',
+    array(
+        'files' => $phork,
+        'description' => '',
+        'htmlhelper' => new HtmlHelper(),
     )
 );
-render('index', array('file' => $phork, 'description' => ''));
-?>
\ No newline at end of file
+?>