X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/3c0605419d071c567f800148d2343ad6a85c7735..f0b5a3f429928c07b134e37c706555de1cf71b59:/src/phorkie/ForkRemote.php?ds=sidebyside
diff --git a/src/phorkie/ForkRemote.php b/src/phorkie/ForkRemote.php
index 76eec05..f8e319a 100644
--- a/src/phorkie/ForkRemote.php
+++ b/src/phorkie/ForkRemote.php
@@ -3,6 +3,11 @@ namespace phorkie;
class ForkRemote
{
+ /**
+ * Contains error message when parse() failed
+ */
+ public $error;
+
protected $url;
/**
@@ -22,77 +27,19 @@ class ForkRemote
public function parse()
{
- $arUrl = parse_url($this->url);
- $scheme = isset($arUrl['scheme']) ? $arUrl['scheme'] : '';
-
- if ($scheme == 'https' && isset($arUrl['host'])
- && $arUrl['host'] == 'gist.github.com'
- ) {
- $this->arGitUrls[][] = 'git://gist.github.com/'
- . ltrim($arUrl['path'], '/') . '.git';
- return true;
- }
-
- switch ($scheme) {
- case 'git':
- //clearly a git url
- $this->arGitUrls = array(array($this->url));
- return true;
+ $hp = new HtmlParser();
+ $ret = $hp->extractGitUrls($this->url);
+ $this->arGitUrls = $hp->getGitUrls();
+ $this->error = $hp->error;
- case 'ssh':
- //FIXME: maybe loosen this when we know how to skip the
- //"do you trust this server" question of ssh
- $this->error = 'ssh:// URLs are not supported';
- return false;
-
- case 'http':
- case 'https':
- return $this->extractUrlsFromHtml($this->url);
- }
-
- $this->error = 'Unknown URLs scheme: ' . $scheme;
- return false;
- }
-
- protected function extractUrlsFromHtml($url)
- {
- //HTML is not necessarily well-formed, and Gitorious has many problems
- // in this regard
- //$sx = simplexml_load_file($url);
- libxml_use_internal_errors(true);
- $sx = simplexml_import_dom(\DomDocument::loadHtmlFile($url));
- $elems = $sx->xpath('//*[@rel="vcs-git"]');
-
- $count = $anonymous = 0;
- foreach ($elems as $elem) {
- if (!isset($elem['href'])) {
- continue;
- }
- $str = (string)$elem;
- if (isset($elem['title'])) {
- //
- $title = (string)$elem['title'];
- } else if ($str != '') {
- //title
- $title = $str;
- } else {
- $title = 'Unnamed repository #' . ++$anonymous;
- }
- $url = (string)$elem['href'];
- if ($this->isSupported($url)) {
- ++$count;
- $this->arGitUrls[$title][] = $url;
- }
- }
-
- return $count > 0;
+ return $ret;
}
/**
* Iterate through all git urls and return one if there is only
* one supported one.
*
- * @return mixed Boolean false or string
+ * @return mixed Boolean false or array with keys "url" and "title"
*/
public function getUniqueGitUrl()
{
@@ -100,7 +47,7 @@ class ForkRemote
foreach ($this->arGitUrls as $title => $arUrls) {
foreach ($arUrls as $url) {
$nFound++;
- $uniqueUrl = $url;
+ $uniqueUrl = array('url' => $url, 'title' => $title);
}
}
@@ -130,11 +77,5 @@ class ForkRemote
{
$this->url = $url;
}
-
- public function isSupported($url)
- {
- return parse_url($url, PHP_URL_SCHEME) == 'git';
- }
}
-
?>