X-Git-Url: https://git.cweiske.de/phorkie.git/blobdiff_plain/f92de25cd3760271ea81fcdc5809b64f5f8f2247..1ee5f44ac9a3125f16318ca1d24a7f7e8010a169:/src/phorkie/ForkRemote.php diff --git a/src/phorkie/ForkRemote.php b/src/phorkie/ForkRemote.php index 8784e8e..31b4839 100644 --- a/src/phorkie/ForkRemote.php +++ b/src/phorkie/ForkRemote.php @@ -72,6 +72,8 @@ class ForkRemote 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) { @@ -85,6 +87,8 @@ class ForkRemote } else if ($str != '') { //title $title = $str; + } else if ($pageTitle != '') { + $title = $pageTitle; } else { $title = 'Unnamed repository #' . ++$anonymous; } @@ -107,7 +111,7 @@ class ForkRemote * Iterate through all git urls and return one if there is only * one supported one. * - * @return mixed Boolean false or string + * @return mixed Boolean false or array with keys "url" and "title" */ public function getUniqueGitUrl() { @@ -115,7 +119,7 @@ class ForkRemote foreach ($this->arGitUrls as $title => $arUrls) { foreach ($arUrls as $url) { $nFound++; - $uniqueUrl = $url; + $uniqueUrl = array('url' => $url, 'title' => $title); } } @@ -152,6 +156,23 @@ class ForkRemote 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; + } } ?>