basic web+fork handling
authorChristian Weiske <cweiske@cweiske.de>
Fri, 2 May 2014 15:42:34 +0000 (17:42 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 2 May 2014 15:42:34 +0000 (17:42 +0200)
README.rst
data/templates/display-head.htm
data/templates/help.htm [new file with mode: 0644]
src/phorkie/HtmlHelper.php
src/phorkie/Repository.php
www/.htaccess
www/fork-remote.php
www/help.php [new file with mode: 0644]

index 7df1579f382a0b64724b2d064e48e7f125b22fa6..1270c30b5cc520ac7473a6b2da2f2a2d15936d98 100644 (file)
@@ -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;
index 78c32a5324c5d3368e1982768b4341513d32c762..ba699bf6c9429641de1b525cccf74934e7a9736e 100644 (file)
@@ -5,7 +5,17 @@
  </div>
  <div class="span2 pull-right">
   <form method="post" action="{{repo.getLink('fork')}}">
-   <button type="submit" class="btn pull-right"><i class="icon-share"></i> fork</button>
+   <div class="btn-group pull-right">
+    <button type="submit" class="btn"><i class="icon-share"></i> fork</button>
+    <button class="btn dropdown-toggle" data-toggle="dropdown">
+     <span class="caret"></span>
+    </button>
+    <ul class="dropdown-menu">
+     <li><a href="{{repo.getLink('remotefork')}}"><i class="icon-share"></i> Fork to remote system</a></li>
+     <li class="divider"></li>
+     <li><a href="help#remote-forking"><i class="icon-question-sign"></i> Help on remote forking</a></li>
+    </ul>
+   </div>
   </form>
  </div>
 </div>
diff --git a/data/templates/help.htm b/data/templates/help.htm
new file mode 100644 (file)
index 0000000..555a738
--- /dev/null
@@ -0,0 +1,49 @@
+{% extends "base.htm" %}
+{% block title %}phorkie help{% endblock %}
+
+{% block content %}
+<h1>Help on phorkie</h1>
+
+<h2 id="remote-forking">Remote forking</h2>
+<script type="text/javascript">
+function registerHandler() {
+    navigator.registerProtocolHandler(
+        "web+fork",
+        "{{htmlhelper.fullUrl('fork-remote?remote_url=%s')}}",
+        "phorkie@"
+        + "{{htmlhelper.fullUrl()}}"
+            .replace(/https?:\/\//, '')
+            .replace(/\/$/, '')
+    );
+}
+</script>
+
+<div class="row-fluid">
+ <div class="span8">
+  <p>
+   Phorkie allows cloning/forking of pastes on other servers
+   - other phorkie instances, github gists or simply any remote
+   git repository.
+  </p>
+  <p>
+   You can go to <a href="fork-remote">fork-remote</a> and enter the
+   URL of the paste on the other server.
+  </p>
+  <p>
+   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.
+  </p>
+  <p>
+   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 <tt>web+fork</tt> URL is clicked.
+  </p>
+ </div>
+ <div class="span4">
+  <a href="#" onclick="registerHandler(); return false;" class="btn">
+   register web+fork protocol handler
+  </a>
+ </div>
+</div>
+{% endblock %}
index 945c7ea25bd134cfbebb723675908780201bad51..efde7149048d38af172f4a5a003196ea084812ff 100644 (file)
@@ -39,6 +39,11 @@ class HtmlHelper
         }
         return $html;
     }
+
+    public function fullUrl($path = '')
+    {
+        return Tools::fullUrl($path);
+    }
 }
 
 ?>
index 2683ad0964a10a96b56140cc09febd88d4159d03..9de2e1ab8995b8226e0e8845d9d5eb0866019879 100644 (file)
@@ -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') {
index 94a6979ad8a0516544bb1df5e1cc6b4f0cf848f4..bf8c5827de86c114638ab19984a216318e97802a 100644 (file)
@@ -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
index 4f1b6829bfb544d6cb8fa430fc95602066657f62..f41f98134b49b862445e2dac30cdc9e94d605e1f 100644 (file)
@@ -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 (file)
index 0000000..fe56c22
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+namespace phorkie;
+/**
+ * Show help
+ */
+$reqWritePermissions = false;
+require_once 'www-header.php';
+
+render(
+    'help',
+    array(
+        'htmlhelper' => new HtmlHelper(),
+    )
+);
+?>