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