From 4d3b1690a86631b4b1abc74dfa4c4e5bde8faf10 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 27 Mar 2012 07:50:58 +0200 Subject: [PATCH] listing all pastes works --- README.rst | 1 - data/templates/list.htm | 25 ++++++++++++++++++++++++ src/Phorkie/Repositories.php | 23 ++++++++++++++++++++++ src/Phorkie/Repository.php | 14 +++++++++++++ www/.htaccess | 2 ++ www/list.php | 38 ++++++++++++++++++++++++++++++++++++ 6 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 data/templates/list.htm create mode 100644 www/list.php diff --git a/README.rst b/README.rst index b1c2522..1a77182 100644 --- a/README.rst +++ b/README.rst @@ -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 %} + + +{% 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 @@ +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, + ) +); +?> -- 2.30.2