first code that allows you to create pastes and view them
[phorkie.git] / www / display.php
1 <?php
2 /**
3  * Display paste contents
4  *
5  */
6 require_once 'www-header.php';
7
8 if (!isset($_GET['id'])) {
9     errout(400, 'Paste ID missing');
10 }
11 if (!is_numeric($_GET['id'])) {
12     errout(400, 'Paste ID not numeric');
13 }
14 $id = (int)$_GET['id'];
15 $repoDir = $GLOBALS['phorkie']['cfg']['repos'] . '/' . $id;
16 if (!is_dir($repoDir)) {
17     errout(404, 'Paste not found');
18 }
19
20 $files = glob($repoDir . '/*');
21 $tplFiles = array();
22 foreach ($files as $file) {
23     $tplFile = array();
24     $tplFile['filename'] = basename($file);
25     $tplFile['type'] = get_type_from_file($file);
26     //FIXME: highlight
27     $tplFile['content'] = file_get_contents($file);
28     $tplFile['raw'] = '/' . $id . '/raw/' . $tplFile['filename'];
29     $tplFiles[] = $tplFile;
30 }
31
32 render(
33     'display',
34     array(
35         'description' => file_get_contents($repoDir . '/.git/description'),
36         'files' => $tplFiles,
37         'links' => array(
38             'edit' => '/' . $id . '/edit'
39         )
40     )
41 );
42 ?>