listing all pastes works
[phorkie.git] / www / list.php
diff --git a/www/list.php b/www/list.php
new file mode 100644 (file)
index 0000000..a212322
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Fork a repository
+ */
+namespace Phorkie;
+require_once 'www-header.php';
+$rs = new Repositories();
+
+$page = 0;
+if (isset($_GET['page'])) {
+    if (!is_numeric($_GET['page'])) {
+        throw new Exception_Input('List page is not numeric');
+    }
+    $page = (int)$_GET['page'];
+}
+
+$perPage = 10;
+$repos = $rs->getList($page, $perPage);
+
+$links = array('prev' => null, 'next' => null);
+if ($page > 0) {
+    $links['prev'] = '/list/' . ($page - 1);
+    if ($page - 1 == 0) {
+        $links['prev'] = '/list';
+    }
+}
+if (count($repos) && count($repos) == $perPage) {
+    $links['next'] = '/list/' . ($page + 1);
+}
+
+render(
+    'list',
+    array(
+        'repos' => $repos,
+        'links' => $links,
+    )
+);
+?>