8fc24052f54f6dc0c98bacb260583ff7c92fb8cf
[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     $rs = new Repositories();
18     $repo = $rs->createNew();
19     $vc = $repo->getVc();
20     $vc->initRepository();
21     file_put_contents($repo->repoDir . '.git/description', $_POST['description']);
22
23     foreach ($_POST['file'] as $num => $arFile) {
24         if ($arFile['name'] != '') {
25             $fname = $arFile['name'];
26         } else {
27             $fname = 'phork' . $num . '.' . $arFile['type'];
28         }
29         $fpath = $repo->repoDir . $fname;
30         file_put_contents($fpath, $arFile['content']);
31         //fixme: let the class do that when it is able to
32         $command = $vc->getCommand('add')
33             ->addArgument($fname)
34             ->execute();
35     }
36     $command = $vc->getCommand('commit')
37         ->setOption('message', 'initial paste')
38         ->setOption('author', 'Anonymous <anonymous@phorkie>')
39         ->execute();
40     //redirect to phork
41     redirect($repo->getLink('display'));
42 }
43
44 $phork = array(
45     '1' => array(
46         'filename' => '',
47         'content' => '',
48         'type' => ''
49     )
50 );
51 render('index', array('file' => $phork, 'description' => ''));
52 ?>