9 * Array with keys (URL title) and values (arrays of urls)
10 * Only supported URLs are included.
18 public function __construct($url)
23 public function parse()
25 $arUrl = parse_url($this->url);
26 $scheme = $arUrl['scheme'] ?: '';
28 if ($scheme == 'https' && isset($arUrl['host'])
29 && $arUrl['host'] == 'gist.github.com'
31 $this->arGitUrls[][] = 'git://gist.github.com/'
32 . ltrim($arUrl['path'], '/') . '.git';
39 $this->arGitUrls = array(array($this->url));
43 //FIXME: maybe loosen this when we know how to skip the
44 //"do you trust this server" question of ssh
45 $this->error = 'ssh:// URLs are not supported';
50 return $this->extractUrlsFromHtml($this->url);
53 $this->error = 'Unknown URLs scheme: ' . $scheme;
57 protected function extractUrlsFromHtml($url)
59 //HTML is not necessarily well-formed, and Gitorious has many problems
61 //$sx = simplexml_load_file($url);
62 libxml_use_internal_errors(true);
63 $sx = simplexml_import_dom(\DomDocument::loadHtmlFile($url));
64 $elems = $sx->xpath('//*[@rel="vcs-git"]');
66 $count = $anonymous = 0;
67 foreach ($elems as $elem) {
68 if (!isset($elem['href'])) {
72 if (isset($elem['title'])) {
73 //<link href=".." rel="vcs-git" title="title" />
74 $title = (string)$elem['title'];
75 } else if ($str != '') {
76 //<a href=".." rel="vcs-git">title</a>
79 $title = 'Unnamed repository #' . ++$anonymous;
81 $url = (string)$elem['href'];
82 if ($this->isSupported($url)) {
84 $this->arGitUrls[$title][] = $url;
92 * Iterate through all git urls and return one if there is only
95 * @return mixed Boolean false or string
97 public function getUniqueGitUrl()
100 foreach ($this->arGitUrls as $title => $arUrls) {
101 foreach ($arUrls as $url) {
113 public function getGitUrls()
115 return $this->arGitUrls;
119 * Get the URL from which the git URL was derived, often
124 public function getUrl()
129 public function setUrl($url)
134 public function isSupported($url)
136 return parse_url($url, PHP_URL_SCHEME) == 'git';