editing works basically
[phorkie.git] / www / index.php
index 31aef7d0d35257db0c5dd90a4f082a097d49237d..db3fd7bf42b12434de4a4ac1a955445d447c78b1 100644 (file)
@@ -12,23 +12,25 @@ namespace Phorkie;
  */
 require_once 'www-header.php';
 
-if (isset($_POST['file'])) {
+if (isset($_POST['files'])) {
     //save
-    $repoDir = $GLOBALS['phorkie']['cfg']['repos'];
-    $n = count(glob($repoDir . '/*', GLOB_ONLYDIR));
-    $dir = $repoDir . '/' . $n . '/'; 
-    mkdir($dir, 0777);//FIXME
-    $vc = new VersionControl_Git($dir);
+    $rs = new Repositories();
+    $repo = $rs->createNew();
+    $vc = $repo->getVc();
     $vc->initRepository();
-    file_put_contents($dir . '.git/description', $_POST['description']);
+    foreach (glob($repo->repoDir . '/.git/hooks/*') as $hookfile) {
+        unlink($hookfile);
+    }
+    $repo->setDescription($_POST['description']);
 
-    foreach ($_POST['file'] as $num => $arFile) {
+    foreach ($_POST['files'] as $num => $arFile) {
         if ($arFile['name'] != '') {
+            //FIXME: fix file name from ..
             $fname = $arFile['name'];
         } else {
             $fname = 'phork' . $num . '.' . $arFile['type'];
         }
-        $fpath = $dir . $fname;
+        $fpath = $repo->repoDir . $fname;
         file_put_contents($fpath, $arFile['content']);
         //fixme: let the class do that when it is able to
         $command = $vc->getCommand('add')
@@ -37,17 +39,14 @@ if (isset($_POST['file'])) {
     }
     $command = $vc->getCommand('commit')
         ->setOption('message', 'initial paste')
+        ->setOption('author', 'Anonymous <anonymous@phorkie>')
         ->execute();
     //redirect to phork
-    redirect($n);
+    redirect($repo->getLink('display'));
 }
 
 $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