X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/1ee5f44ac9a3125f16318ca1d24a7f7e8010a169..94b076f028c2a12f522887caf02b6289957cf4fe:/src/phorkie/ForkRemote.php
diff --git a/src/phorkie/ForkRemote.php b/src/phorkie/ForkRemote.php
index 31b4839..f8e319a 100644
--- a/src/phorkie/ForkRemote.php
+++ b/src/phorkie/ForkRemote.php
@@ -27,84 +27,12 @@ class ForkRemote
public function parse()
{
- if ($this->url == '') {
- $this->error = 'Empty fork URL';
- return false;
- }
-
- $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;
-
- 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"]');
- $titles = $sx->xpath('/html/head/title');
- $pageTitle = $this->cleanPageTitle((string) reset($titles));
-
- $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 if ($pageTitle != '') {
- $title = $pageTitle;
- } else {
- $title = 'Unnamed repository #' . ++$anonymous;
- }
- $url = (string)$elem['href'];
- if ($this->isSupported($url)) {
- ++$count;
- $this->arGitUrls[$title][] = $url;
- }
- }
-
- if ($count > 0) {
- return true;
- }
+ $hp = new HtmlParser();
+ $ret = $hp->extractGitUrls($this->url);
+ $this->arGitUrls = $hp->getGitUrls();
+ $this->error = $hp->error;
- $this->error = 'No git:// clone URL found';
- return false;
+ return $ret;
}
/**
@@ -149,30 +77,5 @@ class ForkRemote
{
$this->url = $url;
}
-
- public function isSupported($url)
- {
- $scheme = parse_url($url, PHP_URL_SCHEME);
- return $scheme == 'git'
- || $scheme == 'http' || $scheme == 'https';
- }
-
- /**
- * Remove application names from HTML page titles
- *
- * @param string $title HTML page title
- *
- * @return string Cleaned HTML page title
- */
- protected function cleanPageTitle($title)
- {
- $title = trim($title);
- if (substr($title, -9) == '- phorkie') {
- $title = trim(substr($title, 0, -9));
- }
-
- return $title;
- }
}
-
?>