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