From 0bf9d11cf26314c7a3285a934c2faf3db50ec9ce Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Wed, 24 Oct 2012 23:15:40 +0200 Subject: [PATCH] make getLink optionally return full urls --- src/phorkie/Repository.php | 41 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/phorkie/Repository.php b/src/phorkie/Repository.php index ba3079a..d82789d 100644 --- a/src/phorkie/Repository.php +++ b/src/phorkie/Repository.php @@ -259,35 +259,42 @@ class Repository /** * Get a link to the repository * - * @param string $type Link type. Supported are: - * - "edit" - * - "delete" - * - "delete-confirm" - * - "display" - * - "fork" - * - "revision" - * @param string $option Additional link option, e.g. revision number + * @param string $type Link type. Supported are: + * - "edit" + * - "delete" + * - "delete-confirm" + * - "display" + * - "fork" + * - "revision" + * @param string $option Additional link option, e.g. revision number + * @param boolean $full Return full URL or normal relative * * @return string */ - public function getLink($type, $option = null) + public function getLink($type, $option = null, $full = false) { if ($type == 'edit') { - return '/' . $this->id . '/edit'; + $link = '/' . $this->id . '/edit'; } else if ($type == 'display') { - return '/' . $this->id; + $link = '/' . $this->id; } else if ($type == 'fork') { - return '/' . $this->id . '/fork'; + $link = '/' . $this->id . '/fork'; } else if ($type == 'doap') { - return '/' . $this->id . '/doap'; + $link = '/' . $this->id . '/doap'; } else if ($type == 'delete') { - return '/' . $this->id . '/delete'; + $link = '/' . $this->id . '/delete'; } else if ($type == 'delete-confirm') { - return '/' . $this->id . '/delete/confirm'; + $link = '/' . $this->id . '/delete/confirm'; } else if ($type == 'revision') { - return '/' . $this->id . '/rev/' . $option; + $link = '/' . $this->id . '/rev/' . $option; + } else { + throw new Exception('Unknown link type'); + } + + if ($full) { + $link = Tools::fullUrl($link); } - throw new Exception('Unknown link type'); + return $link; } public function getCloneURL($public = true) -- 2.30.2