first work on remote forking
authorChristian Weiske <cweiske@cweiske.de>
Tue, 18 Sep 2012 19:31:49 +0000 (21:31 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 18 Sep 2012 19:31:49 +0000 (21:31 +0200)
data/templates/fork-remote.htm [new file with mode: 0644]
data/templates/new-fork-remote.htm [new file with mode: 0644]
data/templates/new.htm
src/phorkie/ForkRemote.php [new file with mode: 0644]
www/.htaccess
www/fork-remote.php [new file with mode: 0644]

diff --git a/data/templates/fork-remote.htm b/data/templates/fork-remote.htm
new file mode 100644 (file)
index 0000000..f599ec6
--- /dev/null
@@ -0,0 +1,6 @@
+{% extends "base.htm" %}
+{% block title %}Fork remote paste{% endblock %}
+
+{% block content %}
+ {% include 'new-fork-remote.htm' %}
+{% endblock %}
diff --git a/data/templates/new-fork-remote.htm b/data/templates/new-fork-remote.htm
new file mode 100644 (file)
index 0000000..02a94e2
--- /dev/null
@@ -0,0 +1,12 @@
+<form method="post" action="/fork-remote" enctype="multipart/form-data" class="well form-inline">
+ <p>
+  <strong>Copy a paste from a remote server:</strong>
+  Just paste the website or git clone URL.
+ </p>
+
+ <button type="submit" class="btn btn-primary" style="float: right">
+  <i class="icon-share icon-white"></i>Fork remote paste
+ </button>
+ <label for="remote-url">Remote paste URL</label>
+ <input type="text" name="remote_url" id="remote-url" value="{{remote_url}}" class="input-xlarge"/>
+</form>
index 5b75bba..f846fe5 100644 (file)
@@ -20,6 +20,9 @@
  </div>
 
 </form>
+
+{% include 'new-fork-remote.htm' %}
+
 <script type="application/javascript">
 $(document).ready(function() {
     initEdit();
@@ -37,4 +40,4 @@ $(document).ready(function() {
  {% endfor %}
  </ul>
  {% endif %}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/src/phorkie/ForkRemote.php b/src/phorkie/ForkRemote.php
new file mode 100644 (file)
index 0000000..f3639b2
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+namespace phorkie;
+
+class ForkRemote
+{
+    protected $url;
+
+    public function __construct($url)
+    {
+        $this->url = $url;
+    }
+
+    public function parse()
+    {
+        $scheme = parse_url($this->url, PHP_URL_SCHEME);
+        switch ($scheme) {
+        case 'git':
+            //clearly a git url
+            $this->gitUrl = $this->url;
+            return true;
+
+        case 'ssh':
+            //FIXME: maybe loosen this when we know how to skip the 
+            //"do you trust this server" question of ssh
+            $this->error = 'ssh:// URLs are not supported';
+            return false;
+
+        case 'http':
+        case 'https':
+            return $this->extractUrlsFromHtml($this->url);
+        }
+
+        $this->error = 'Unknown URLs scheme: ' . $scheme;
+        return false;
+    }
+
+    protected function extractUrlsFromHtml($url)
+    {
+    }
+}
+
+?>
index c379b23..efb03a9 100644 (file)
@@ -13,6 +13,7 @@ RewriteRule ^([0-9]+)/rev/(.+)$ /revision.php?id=$1&rev=$2
 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 ^new$ /new.php
 
 RewriteRule ^list$ /list.php
diff --git a/www/fork-remote.php b/www/fork-remote.php
new file mode 100644 (file)
index 0000000..dd58165
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+namespace phorkie;
+/**
+ * Fork a remote repository.
+ * Displays a URL selection form when multiple git urls have been found
+ */
+require_once 'www-header.php';
+
+if (isset($_POST['remote_url'])) {
+    $fr = new ForkRemote($_POST['remote_url']);
+    $fr->parse();
+    if ($fr->hasUniqueGitUrl()) {
+        //FIXME: fork
+    }
+    //FIXME: display error or selection list
+}
+
+render(
+    'fork-remote',
+    array(
+        'remote_url' => isset($_POST['remote_url']) ? $_POST['remote_url'] : ''
+    )
+);
+?>