aboutsummaryrefslogtreecommitdiff
path: root/www/display.php
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-03-25 21:08:29 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-03-25 21:08:29 +0200
commit6d0777840e50ce98f3d96629b4e92bbdccd3001c (patch)
tree161a753bf54b4fec0c4357b16dc68ff838e20383 /www/display.php
parent568bf6f9a487a3dc33ce52e45cd31cfbea2cb79e (diff)
downloadphorkie-6d0777840e50ce98f3d96629b4e92bbdccd3001c.tar.gz
phorkie-6d0777840e50ce98f3d96629b4e92bbdccd3001c.zip
first code that allows you to create pastes and view them
Diffstat (limited to 'www/display.php')
-rw-r--r--www/display.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/www/display.php b/www/display.php
new file mode 100644
index 0000000..5bd06bb
--- /dev/null
+++ b/www/display.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Display paste contents
+ *
+ */
+require_once 'www-header.php';
+
+if (!isset($_GET['id'])) {
+ errout(400, 'Paste ID missing');
+}
+if (!is_numeric($_GET['id'])) {
+ errout(400, 'Paste ID not numeric');
+}
+$id = (int)$_GET['id'];
+$repoDir = $GLOBALS['phorkie']['cfg']['repos'] . '/' . $id;
+if (!is_dir($repoDir)) {
+ errout(404, 'Paste not found');
+}
+
+$files = glob($repoDir . '/*');
+$tplFiles = array();
+foreach ($files as $file) {
+ $tplFile = array();
+ $tplFile['filename'] = basename($file);
+ $tplFile['type'] = get_type_from_file($file);
+ //FIXME: highlight
+ $tplFile['content'] = file_get_contents($file);
+ $tplFile['raw'] = '/' . $id . '/raw/' . $tplFile['filename'];
+ $tplFiles[] = $tplFile;
+}
+
+render(
+ 'display',
+ array(
+ 'description' => file_get_contents($repoDir . '/.git/description'),
+ 'files' => $tplFiles,
+ 'links' => array(
+ 'edit' => '/' . $id . '/edit'
+ )
+ )
+);
+?>