monospaced font, more height for content
[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['files'])) {
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     $repo->setDescription($_POST['description']);
25
26     foreach ($_POST['files'] as $num => $arFile) {
27         if ($arFile['name'] != '') {
28             //FIXME: fix file name from ..
29             $fname = $arFile['name'];
30         } else {
31             $fname = 'phork' . $num . '.' . $arFile['type'];
32         }
33         $fpath = $repo->repoDir . $fname;
34         file_put_contents($fpath, $arFile['content']);
35         //fixme: let the class do that when it is able to
36         $command = $vc->getCommand('add')
37             ->addArgument($fname)
38             ->execute();
39     }
40     $command = $vc->getCommand('commit')
41         ->setOption('message', 'initial paste')
42         ->setOption('author', 'Anonymous <anonymous@phorkie>')
43         ->execute();
44     //redirect to phork
45     redirect($repo->getLink('display'));
46 }
47
48 $phork = array(
49     '1' => new File(null, null)
50 );
51 render('index', array('files' => $phork, 'description' => ''));
52 ?>