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 $scheme = parse_url($this->url, PHP_URL_SCHEME);
29 $this->arGitUrls = array(array($this->url));
33 //FIXME: maybe loosen this when we know how to skip the
34 //"do you trust this server" question of ssh
35 $this->error = 'ssh:// URLs are not supported';
40 return $this->extractUrlsFromHtml($this->url);
43 $this->error = 'Unknown URLs scheme: ' . $scheme;
47 protected function extractUrlsFromHtml($url)
49 //HTML is not necessarily well-formed, and Gitorious has many problems
51 //$sx = simplexml_load_file($url);
52 libxml_use_internal_errors(true);
53 $sx = simplexml_import_dom(\DomDocument::loadHtmlFile($url));
54 $elems = $sx->xpath('//*[@rel="vcs-git"]');
56 $count = $anonymous = 0;
57 foreach ($elems as $elem) {
58 if (!isset($elem['href'])) {
62 if (isset($elem['title'])) {
63 //<link href=".." rel="vcs-git" title="title" />
64 $title = (string)$elem['title'];
65 } else if ($str != '') {
66 //<a href=".." rel="vcs-git">title</a>
69 $title = 'Unnamed repository #' . ++$anonymous;
71 $url = (string)$elem['href'];
72 if ($this->isSupported($url)) {
74 $this->arGitUrls[$title][] = $url;
82 * Iterate through all git urls and return one if there is only
85 * @return mixed Boolean false or string
87 public function getUniqueGitUrl()
90 foreach ($this->arGitUrls as $title => $arUrls) {
91 foreach ($arUrls as $url) {
103 public function getGitUrls()
105 return $this->arGitUrls;
108 public function isSupported($url)
110 return parse_url($url, PHP_URL_SCHEME) == 'git';