use repositories class
authorChristian Weiske <cweiske@cweiske.de>
Mon, 26 Mar 2012 21:38:53 +0000 (23:38 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 26 Mar 2012 21:38:53 +0000 (23:38 +0200)
data/templates/display.htm
src/Phorkie/Repositories.php [new file with mode: 0644]
src/Phorkie/Repository.php
www/.htaccess
www/index.php
www/www-header.php

index 43a76fc9f3ef5f940d2ef8cbe42971ce06e911a9..657561717d14192b05c9096204ab88b54074b67a 100644 (file)
@@ -3,7 +3,10 @@
 
 {% block content %}
 <h1>{{repo.getDescription}}</h1>
 
 {% block content %}
 <h1>{{repo.getDescription}}</h1>
-<p><a href="{{repo.getLink('edit')}}">edit</a></p>
+<ul class="links">
+ <li><a href="{{repo.getLink('edit')}}">edit</a></li>
+ <li><a href="{{repo.getLink('fork')}}">fork</a></li>
+</ul>
 {% for file in repo.getFiles %}
 <div>
  <h2>{{file.getFilename}}</h2>
 {% for file in repo.getFiles %}
 <div>
  <h2>{{file.getFilename}}</h2>
diff --git a/src/Phorkie/Repositories.php b/src/Phorkie/Repositories.php
new file mode 100644 (file)
index 0000000..6582ae8
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+namespace Phorkie;
+
+class Repositories
+{
+    public function __construct()
+    {
+        $this->reposDir = $GLOBALS['phorkie']['cfg']['repos'];
+    }
+
+    /**
+     * @return Repository
+     */
+    public function createNew()
+    {
+        $n = basename(end(glob($this->reposDir . '/*', GLOB_ONLYDIR))) + 1;
+        $dir = $this->reposDir . '/' . $n . '/'; 
+        mkdir($dir, 0777);//FIXME
+        $r = new Repository();
+        $r->id = $n;
+        $r->repoDir = $dir;
+        return $r;
+    }
+
+}
+
+?>
index 531ff6872950fd4dafa9715fc0550a9dedbfc3ed..f23db7e17faea3f6d7569b27b1c7d9bd11da0fb1 100644 (file)
@@ -42,6 +42,11 @@ class Repository
         $this->repoDir = $repoDir;
     }
 
         $this->repoDir = $repoDir;
     }
 
+    public function getVc()
+    {
+        return new \VersionControl_Git($this->repoDir);
+    }
+
     /**
      * Loads the list of files in this repository
      *
     /**
      * Loads the list of files in this repository
      *
@@ -84,6 +89,7 @@ class Repository
      * @param string $type Link type. Supported are:
      *                     - "edit"
      *                     - "display"
      * @param string $type Link type. Supported are:
      *                     - "edit"
      *                     - "display"
+     *                     - "fork"
      *
      * @return string
      */
      *
      * @return string
      */
@@ -93,6 +99,8 @@ class Repository
             return '/' . $this->id . '/edit';
         } else if ($type == 'display') {
             return '/' . $this->id;
             return '/' . $this->id . '/edit';
         } else if ($type == 'display') {
             return '/' . $this->id;
+        } else if ($type == 'fork') {
+            return '/' . $this->id . '/fork';
         }
         throw new Exception('Unknown type');
     }
         }
         throw new Exception('Unknown type');
     }
index a57b34df48be7e7ae654a08b5767bc77d6a8682b..bf82bc236851023fee38d3fe3e5a56bbc9a26e36 100644 (file)
@@ -4,3 +4,4 @@ RewriteBase /
 
 RewriteRule ^([0-9]+)$ /display.php?id=$1
 RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2
 
 RewriteRule ^([0-9]+)$ /display.php?id=$1
 RewriteRule ^([0-9]+)/raw/(.+)$ /raw.php?id=$1&file=$2
+RewriteRule ^([0-9]+)/fork$ /fork.php?id=$1
index 5bda39084f0d0a7f2b8f20ca96e8a704714fc88a..8fc24052f54f6dc0c98bacb260583ff7c92fb8cf 100644 (file)
@@ -14,13 +14,11 @@ require_once 'www-header.php';
 
 if (isset($_POST['file'])) {
     //save
 
 if (isset($_POST['file'])) {
     //save
-    $repoDir = $GLOBALS['phorkie']['cfg']['repos'];
-    $n = count(glob($repoDir . '/*', GLOB_ONLYDIR));
-    $dir = $repoDir . '/' . $n . '/'; 
-    mkdir($dir, 0777);//FIXME
-    $vc = new \VersionControl_Git($dir);
+    $rs = new Repositories();
+    $repo = $rs->createNew();
+    $vc = $repo->getVc();
     $vc->initRepository();
     $vc->initRepository();
-    file_put_contents($dir . '.git/description', $_POST['description']);
+    file_put_contents($repo->repoDir . '.git/description', $_POST['description']);
 
     foreach ($_POST['file'] as $num => $arFile) {
         if ($arFile['name'] != '') {
 
     foreach ($_POST['file'] as $num => $arFile) {
         if ($arFile['name'] != '') {
@@ -28,7 +26,7 @@ if (isset($_POST['file'])) {
         } else {
             $fname = 'phork' . $num . '.' . $arFile['type'];
         }
         } else {
             $fname = 'phork' . $num . '.' . $arFile['type'];
         }
-        $fpath = $dir . $fname;
+        $fpath = $repo->repoDir . $fname;
         file_put_contents($fpath, $arFile['content']);
         //fixme: let the class do that when it is able to
         $command = $vc->getCommand('add')
         file_put_contents($fpath, $arFile['content']);
         //fixme: let the class do that when it is able to
         $command = $vc->getCommand('add')
@@ -40,7 +38,7 @@ if (isset($_POST['file'])) {
         ->setOption('author', 'Anonymous <anonymous@phorkie>')
         ->execute();
     //redirect to phork
         ->setOption('author', 'Anonymous <anonymous@phorkie>')
         ->execute();
     //redirect to phork
-    redirect($n);
+    redirect($repo->getLink('display'));
 }
 
 $phork = array(
 }
 
 $phork = array(
index 8b99234a0b091216d5129158a93c8030fcffebb4..520d793520627c73ae116f882e0a6fdf299014dc 100644 (file)
@@ -47,7 +47,7 @@ function render($tplname, $vars)
 }
 function redirect($target)
 {
 }
 function redirect($target)
 {
-    header('Location: /' . $target);
+    header('Location: ' . $target);
     exit();
 }
 ?>
\ No newline at end of file
     exit();
 }
 ?>
\ No newline at end of file