if ($scheme == 'https' && isset($arUrl['host'])
&& $arUrl['host'] == 'gist.github.com'
) {
- //https://gist.github.com/maddy2101/5764473
+ //https://gist.github.com/cweiske/2400389
+ // clone URL: https://gist.github.com/2400389.git
$parts = explode('/', ltrim($arUrl['path'], '/'));
if (count($parts == 2)) {
//we only want the number, not the user name
} else {
$path = ltrim($arUrl['path'], '/');
}
- //FIXME: title
- $this->arGitUrls[][] = 'git://gist.github.com/'
- . $path . '.git';
+ $title = $this->getHtmlTitle($url);
+ if ($title === null) {
+ $this->arGitUrls[][] = 'https://gist.github.com/'
+ . $path . '.git';
+ } else {
+ $this->arGitUrls[$title][] = 'https://gist.github.com/'
+ . $path . '.git';
+ }
return true;
}
|| $scheme == 'http' || $scheme == 'https';
}
+ /**
+ * Extract the title from a HTML URL
+ *
+ * @param string $url URL to a HTML page
+ *
+ * @return string|null NULL on error, title otherwise
+ */
+ public function getHtmlTitle($url)
+ {
+ libxml_use_internal_errors(true);
+ $doc = \DOMDocument::loadHTMLFile($url);
+ if ($doc === false) {
+ return null;
+ }
+ $sx = simplexml_import_dom($doc);
+ $title = (string) $sx->head->title;
+ if ($title == '') {
+ return null;
+ }
+ return $title;
+ }
}
?>