{% 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>
--- /dev/null
+<?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;
+ }
+
+}
+
+?>
$this->repoDir = $repoDir;
}
+ public function getVc()
+ {
+ return new \VersionControl_Git($this->repoDir);
+ }
+
/**
* Loads the list of files in this repository
*
* @param string $type Link type. Supported are:
* - "edit"
* - "display"
+ * - "fork"
*
* @return string
*/
return '/' . $this->id . '/edit';
} else if ($type == 'display') {
return '/' . $this->id;
+ } else if ($type == 'fork') {
+ return '/' . $this->id . '/fork';
}
throw new Exception('Unknown type');
}
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
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();
- 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'] != '') {
} 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')
->setOption('author', 'Anonymous <anonymous@phorkie>')
->execute();
//redirect to phork
- redirect($n);
+ redirect($repo->getLink('display'));
}
$phork = array(
}
function redirect($target)
{
- header('Location: /' . $target);
+ header('Location: ' . $target);
exit();
}
?>
\ No newline at end of file