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'] ?: '';
27 if ($scheme == 'https' && isset($arUrl['host'])
28 && $arUrl['host'] == 'gist.github.com'
31 $this->url = 'git://gist.github.com/'. ltrim($arUrl['path'], '/') . '.git';
37 $this->arGitUrls = array(array($this->url));
41 //FIXME: maybe loosen this when we know how to skip the
42 //"do you trust this server" question of ssh
43 $this->error = 'ssh:// URLs are not supported';
48 return $this->extractUrlsFromHtml($this->url);
51 $this->error = 'Unknown URLs scheme: ' . $scheme;
55 protected function extractUrlsFromHtml($url)
57 //HTML is not necessarily well-formed, and Gitorious has many problems
59 //$sx = simplexml_load_file($url);
60 libxml_use_internal_errors(true);
61 $sx = simplexml_import_dom(\DomDocument::loadHtmlFile($url));
62 $elems = $sx->xpath('//*[@rel="vcs-git"]');
64 $count = $anonymous = 0;
65 foreach ($elems as $elem) {
66 if (!isset($elem['href'])) {
70 if (isset($elem['title'])) {
71 //<link href=".." rel="vcs-git" title="title" />
72 $title = (string)$elem['title'];
73 } else if ($str != '') {
74 //<a href=".." rel="vcs-git">title</a>
77 $title = 'Unnamed repository #' . ++$anonymous;
79 $url = (string)$elem['href'];
80 if ($this->isSupported($url)) {
82 $this->arGitUrls[$title][] = $url;
90 * Iterate through all git urls and return one if there is only
93 * @return mixed Boolean false or string
95 public function getUniqueGitUrl()
98 foreach ($this->arGitUrls as $title => $arUrls) {
99 foreach ($arUrls as $url) {
111 public function getGitUrls()
113 return $this->arGitUrls;
116 public function isSupported($url)
118 return parse_url($url, PHP_URL_SCHEME) == 'git';