From 6d0777840e50ce98f3d96629b4e92bbdccd3001c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sun, 25 Mar 2012 21:08:29 +0200 Subject: [PATCH] first code that allows you to create pastes and view them --- .gitignore | 2 ++ README.rst | 37 +++++++++++++++++++++++++++ data/config.default.php | 6 +++++ data/templates/base.htm | 17 +++++++++++++ data/templates/display.htm | 16 ++++++++++++ data/templates/index.htm | 25 ++++++++++++++++++ www/.htaccess | 5 ++++ www/display.php | 42 ++++++++++++++++++++++++++++++ www/index.php | 52 ++++++++++++++++++++++++++++++++++++++ www/www-header.php | 36 ++++++++++++++++++++++++++ 10 files changed, 238 insertions(+) create mode 100644 .gitignore create mode 100644 data/templates/base.htm create mode 100644 data/templates/display.htm create mode 100644 data/templates/index.htm create mode 100644 www/display.php create mode 100644 www/www-header.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f82ddfd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +README.html +repos diff --git a/README.rst b/README.rst index e69de29..ea8a940 100644 --- a/README.rst +++ b/README.rst @@ -0,0 +1,37 @@ +************************************ +Phorkie - PHP and Git based pastebin +************************************ + +URLs +==== + +``/`` + Index page. Shows form for new paste +``/[0-9]+`` + Display page for paste +``/[0-9]/edit`` + Edit the paste +``/[0-9]+/raw/(.+)`` + Display raw file contents +``/[0-9]/delete`` + Delete the paste +``/search(/.+)?`` + Search for term +``/list(/[0-9])?`` + List all pastes + + +Internal directory layout +========================= +:: + + repos/ + 1/ - git repository for paste #1 + .git/ + description - Description for the repository + 2/ - git repository for paste #2 + + +Search +====== +Use ``ack-grep`` diff --git a/data/config.default.php b/data/config.default.php index e69de29..ec68622 100644 --- a/data/config.default.php +++ b/data/config.default.php @@ -0,0 +1,6 @@ + __DIR__ . '/../repos/', + 'tpl' => __DIR__ . '/templates/', +); +?> \ No newline at end of file diff --git a/data/templates/base.htm b/data/templates/base.htm new file mode 100644 index 0000000..f406f00 --- /dev/null +++ b/data/templates/base.htm @@ -0,0 +1,17 @@ + + + + + {% block title %}{% endblock %} - Phorkie + + + +
{% block content %}{% endblock %}
+ + \ No newline at end of file diff --git a/data/templates/display.htm b/data/templates/display.htm new file mode 100644 index 0000000..1f33b61 --- /dev/null +++ b/data/templates/display.htm @@ -0,0 +1,16 @@ +{% extends "base.htm" %} +{% block title %}{{description}}{% endblock %} + +{% block content %} +

{{description}}

+

edit

+{% for file in files %} +
+

{{file.filename}}

+

+ raw +

+
{{file.content}}
+
+{% endfor %} +{% endblock %} diff --git a/data/templates/index.htm b/data/templates/index.htm new file mode 100644 index 0000000..eea509b --- /dev/null +++ b/data/templates/index.htm @@ -0,0 +1,25 @@ + +
+

+ + +

+

+ + +

+

+ + +

+

+ +

+

+ +

+
\ No newline at end of file diff --git a/www/.htaccess b/www/.htaccess index e69de29..f41e1bf 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -0,0 +1,5 @@ +RewriteEngine On +RewriteBase / +#RewriteCond %{REQUEST_FILENAME} -f + +RewriteRule ^([0-9]+)$ /display.php?id=$1 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 @@ + file_get_contents($repoDir . '/.git/description'), + 'files' => $tplFiles, + 'links' => array( + 'edit' => '/' . $id . '/edit' + ) + ) +); +?> diff --git a/www/index.php b/www/index.php index e69de29..5276bf2 100644 --- a/www/index.php +++ b/www/index.php @@ -0,0 +1,52 @@ +initRepository(); + file_put_contents($dir . '.git/description', $_POST['description']); + + foreach ($_POST['file'] as $num => $arFile) { + if ($arFile['name'] != '') { + $fname = $arFile['name']; + } else { + $fname = 'phork' . $num . '.' . $arFile['type']; + } + $fpath = $dir . $fname; + file_put_contents($fpath, $arFile['content']); + //fixme: let the class do that when it is able to + $command = $vc->getCommand('add') + ->addArgument($fname) + ->execute(); + } + $command = $vc->getCommand('commit') + ->setOption('message', 'initial paste') + ->execute(); + //redirect to phork + redirect($n); +} + +$phork = array( + '1' => array( + 'filename' => '', + 'content' => '', + 'type' => '' + ) +); +render('index', array('file' => $phork, 'description' => '')); +?> \ No newline at end of file diff --git a/www/www-header.php b/www/www-header.php new file mode 100644 index 0000000..28607da --- /dev/null +++ b/www/www-header.php @@ -0,0 +1,36 @@ + '/path/to/compilation_cache', + 'debug' => true + ) +); + +function render($tplname, $vars) +{ + $template = $GLOBALS['twig']->loadTemplate($tplname . '.htm'); + echo $template->render($vars); +} +function redirect($target) +{ + header('Location: /' . $target); + exit(); +} +function errout($statusCode, $message) +{ + header('HTTP/1.0 ' . $statusCode); + echo $message; + exit(); +} +function get_type_from_file($file) +{ + return substr($file, strrpos($file, '.') + 1); +} +?> \ No newline at end of file -- 2.30.2