diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2012-03-27 07:50:58 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2012-03-27 07:50:58 +0200 |
| commit | 4d3b1690a86631b4b1abc74dfa4c4e5bde8faf10 (patch) | |
| tree | 0da5e9ace9d5b5eb359308dfaa81d7fbf5a147b0 | |
| parent | c12906d4181a185db6de00e4a1dc11897a1d4718 (diff) | |
| download | phorkie-4d3b1690a86631b4b1abc74dfa4c4e5bde8faf10.tar.gz phorkie-4d3b1690a86631b4b1abc74dfa4c4e5bde8faf10.zip | |
listing all pastes works
| -rw-r--r-- | README.rst | 1 | ||||
| -rw-r--r-- | data/templates/list.htm | 25 | ||||
| -rw-r--r-- | src/Phorkie/Repositories.php | 23 | ||||
| -rw-r--r-- | src/Phorkie/Repository.php | 14 | ||||
| -rw-r--r-- | www/.htaccess | 2 | ||||
| -rw-r--r-- | www/list.php | 38 |
6 files changed, 102 insertions, 1 deletions
@@ -48,7 +48,6 @@ Install geshi TODO ==== - edit -- list all - search - OpenID-Login to get username+email as authorship information - sidebar: history diff --git a/data/templates/list.htm b/data/templates/list.htm new file mode 100644 index 0000000..5142a7b --- /dev/null +++ b/data/templates/list.htm @@ -0,0 +1,25 @@ +{% extends "base.htm" %} +{% block title %}List of all pastes{% endblock %} + +{% block content %} +<ul class="list"> +{% for repo in repos %} + <li> + <h2><a href="{{repo.getLink('display')}}">{{repo.id}}</a></h2> + <p>{{repo.getDescription}}</p> + </li> +{% endfor %} +</ul> +<ul class="pager"> + {% if links.prev %} + <li class="prev"> + <a href="{{links.prev}}">prev</a> + </li> + {% endif %} + {% if links.next %} + <li class="next"> + <a href="{{links.next}}">next</a> + </li> + {% endif %} +</ul> +{% endblock %} diff --git a/src/Phorkie/Repositories.php b/src/Phorkie/Repositories.php index 3afe8c5..eeaec34 100644 --- a/src/Phorkie/Repositories.php +++ b/src/Phorkie/Repositories.php @@ -27,6 +27,29 @@ class Repositories return $r; } + /** + * Get a list of repository objects + * + * @param integer $page Page number, beginning with 0 + * @param integer $perPage Number of repositories per page + * + * @return array Array of Repositories + */ + public function getList($page = 0, $perPage = 10) + { + chdir($this->reposDir); + $dirs = glob('*', GLOB_ONLYDIR); + sort($dirs, SORT_NUMERIC); + + $some = array_slice($dirs, $page * $perPage, $perPage); + $repos = array(); + foreach ($some as $oneDir) { + $r = new Repository(); + $r->loadById($oneDir); + $repos[] = $r; + } + return $repos; + } } ?> diff --git a/src/Phorkie/Repository.php b/src/Phorkie/Repository.php index f23db7e..aeccc72 100644 --- a/src/Phorkie/Repository.php +++ b/src/Phorkie/Repository.php @@ -42,6 +42,20 @@ class Repository $this->repoDir = $repoDir; } + public function loadById($id) + { + if (!is_numeric($id)) { + throw new Exception_Input('Paste ID not numeric'); + } + $this->id = (int)$id; + + $repoDir = $GLOBALS['phorkie']['cfg']['repos'] . '/' . $this->id; + if (!is_dir($repoDir)) { + throw new Exception_NotFound('Paste not found'); + } + $this->repoDir = $repoDir; + } + public function getVc() { return new \VersionControl_Git($this->repoDir); diff --git a/www/.htaccess b/www/.htaccess index bf82bc2..d053ca7 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -5,3 +5,5 @@ RewriteBase / 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 +RewriteRule ^list$ /list.php +RewriteRule ^list/([0-9])+$ /list.php?page=$1 diff --git a/www/list.php b/www/list.php new file mode 100644 index 0000000..a212322 --- /dev/null +++ b/www/list.php @@ -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, + ) +); +?> |
