commit as anonymous
[phorkie.git] / www / index.php
1 <?php
2 namespace Phorkie;
3 /**
4  * Show paste creation form
5  *
6  * Elements:
7  * - description
8  * - file name (default: default.php)
9  * - content
10  *
11  * Creates and redirects to display page
12  */
13 require_once 'www-header.php';
14
15 if (isset($_POST['file'])) {
16     //save
17     $repoDir = $GLOBALS['phorkie']['cfg']['repos'];
18     $n = count(glob($repoDir . '/*', GLOB_ONLYDIR));
19     $dir = $repoDir . '/' . $n . '/'; 
20     mkdir($dir, 0777);//FIXME
21     $vc = new \VersionControl_Git($dir);
22     $vc->initRepository();
23     file_put_contents($dir . '.git/description', $_POST['description']);
24
25     foreach ($_POST['file'] as $num => $arFile) {
26         if ($arFile['name'] != '') {
27             $fname = $arFile['name'];
28         } else {
29             $fname = 'phork' . $num . '.' . $arFile['type'];
30         }
31         $fpath = $dir . $fname;
32         file_put_contents($fpath, $arFile['content']);
33         //fixme: let the class do that when it is able to
34         $command = $vc->getCommand('add')
35             ->addArgument($fname)
36             ->execute();
37     }
38     $command = $vc->getCommand('commit')
39         ->setOption('message', 'initial paste')
40         ->setOption('author', 'Anonymous <anonymous@phorkie>')
41         ->execute();
42     //redirect to phork
43     redirect($n);
44 }
45
46 $phork = array(
47     '1' => array(
48         'filename' => '',
49         'content' => '',
50         'type' => ''
51     )
52 );
53 render('index', array('file' => $phork, 'description' => ''));
54 ?>