From d06f9e8ea6cefcfae1ad28bb203a7e4e562820a8 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 2 May 2014 17:42:34 +0200 Subject: basic web+fork handling --- README.rst | 6 +++++ data/templates/display-head.htm | 12 +++++++++- data/templates/help.htm | 49 +++++++++++++++++++++++++++++++++++++++++ src/phorkie/HtmlHelper.php | 5 +++++ src/phorkie/Repository.php | 2 ++ www/.htaccess | 1 + www/fork-remote.php | 10 ++++++--- www/help.php | 15 +++++++++++++ 8 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 data/templates/help.htm create mode 100644 www/help.php diff --git a/README.rst b/README.rst index 7df1579..1270c30 100644 --- a/README.rst +++ b/README.rst @@ -288,6 +288,10 @@ URLs Search for term, with optional page ``/list(/[0-9])?`` List all pastes, with optional page +``/fork-remote`` + Fork a remote URL +``/help`` + Show help page ``/new`` Shows form for new paste ``/login`` @@ -329,6 +333,8 @@ If you use nginx, place the following lines into your ``server`` block: rewrite ^/([0-9]+)/rev-raw/(.+)$ /raw.php?id=$1&rev=$2&file=$3; rewrite ^/([0-9]+)/tool/([^/]+)/(.+)$ /tool.php?id=$1&tool=$2&file=$3; + rewrite ^/fork-remote$ /fork-remote.php; + rewrite ^/help$ /help.php; rewrite ^/new$ /new.php; rewrite ^/feed/new$ /feed-new.php; rewrite ^/feed/updated$ /feed-updated.php; diff --git a/data/templates/display-head.htm b/data/templates/display-head.htm index 78c32a5..ba699bf 100644 --- a/data/templates/display-head.htm +++ b/data/templates/display-head.htm @@ -5,7 +5,17 @@
- +
diff --git a/data/templates/help.htm b/data/templates/help.htm new file mode 100644 index 0000000..555a738 --- /dev/null +++ b/data/templates/help.htm @@ -0,0 +1,49 @@ +{% extends "base.htm" %} +{% block title %}phorkie help{% endblock %} + +{% block content %} +

Help on phorkie

+ +

Remote forking

+ + +
+
+

+ Phorkie allows cloning/forking of pastes on other servers + - other phorkie instances, github gists or simply any remote + git repository. +

+

+ You can go to fork-remote and enter the + URL of the paste on the other server. +

+

+ It's way easier to simply click a "fork" button that automatically + takes you to this phorkie's remote paste page, prefilled with + the correct git URL. +

+

+ To make this work, click the register button on the right. + It will register a "protocol handler" for "web+fork:"-URLs, + making phorkie chime in whenever a web+fork URL is clicked. +

+
+ +
+{% endblock %} diff --git a/src/phorkie/HtmlHelper.php b/src/phorkie/HtmlHelper.php index 945c7ea..efde714 100644 --- a/src/phorkie/HtmlHelper.php +++ b/src/phorkie/HtmlHelper.php @@ -39,6 +39,11 @@ class HtmlHelper } return $html; } + + public function fullUrl($path = '') + { + return Tools::fullUrl($path); + } } ?> diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php index 2683ad0..9de2e1a 100644 --- a/src/phorkie/Repository.php +++ b/src/phorkie/Repository.php @@ -331,6 +331,8 @@ class Repository $link = $this->id . '/delete'; } else if ($type == 'delete-confirm') { $link = $this->id . '/delete/confirm'; + } else if ($type == 'remotefork') { + return 'web+fork:' . $this->getLink('display', null, true); } else if ($type == 'revision') { $link = $this->id . '/rev/' . $option; } else if ($type == 'linkback') { diff --git a/www/.htaccess b/www/.htaccess index 94a6979..bf8c582 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -18,6 +18,7 @@ RewriteRule ^([0-9]+)/rev-raw/(.+)/(.+)$ raw.php?id=$1&rev=$2&file=$3 RewriteRule ^([0-9]+)/tool/([^/]+)/(.+)$ tool.php?id=$1&tool=$2&file=$3 RewriteRule ^fork-remote$ fork-remote.php +RewriteRule ^help$ help.php RewriteRule ^new$ new.php RewriteRule ^feed/new$ feed-new.php diff --git a/www/fork-remote.php b/www/fork-remote.php index 4f1b682..f41f981 100644 --- a/www/fork-remote.php +++ b/www/fork-remote.php @@ -8,8 +8,12 @@ require_once 'www-header.php'; $error = null; $urls = null; -if (isset($_POST['remote_url'])) { - $fr = new ForkRemote($_POST['remote_url']); +if (isset($_REQUEST['remote_url'])) { + if (substr($_REQUEST['remote_url'], 0, 9) == 'web+fork:') { + $_REQUEST['remote_url'] = substr($_REQUEST['remote_url'], 9); + } + + $fr = new ForkRemote($_REQUEST['remote_url']); if (false === $fr->parse()) { //no url found $error = $fr->error; @@ -45,7 +49,7 @@ if (is_array($urls)) { render( 'fork-remote', array( - 'remote_url' => isset($_POST['remote_url']) ? $_POST['remote_url'] : '', + 'remote_url' => isset($_REQUEST['remote_url']) ? $_REQUEST['remote_url'] : '', 'error' => $error, 'urls' => $urls, 'urlselsize' => $selsize, diff --git a/www/help.php b/www/help.php new file mode 100644 index 0000000..fe56c22 --- /dev/null +++ b/www/help.php @@ -0,0 +1,15 @@ + new HtmlHelper(), + ) +); +?> -- cgit v1.2.3