Fix phpcs

This commit is contained in:
Laurent Destailleur
2023-12-04 10:22:29 +01:00
parent 697c8d14b7
commit b282251fbc
3 changed files with 70 additions and 60 deletions

View File

@@ -55,7 +55,9 @@ function followLink($url, $depth = 0)
$metaData = getDocMetaData($doc);
foreach ($links as $i) {
$link = $i->getAttribute('href');
if (ignoreLink($link)) continue;
if (ignoreLink($link)) {
continue;
}
$link = convertLink($url, $link);
if (!in_array($link, $crawledLinks)) {
$crawledLinks[] = $link;
@@ -63,9 +65,10 @@ function followLink($url, $depth = 0)
insertIntoDatabase($link, $pageTitle, $metaData, $depth);
}
}
foreach ($crawling as $crawlURL)
foreach ($crawling as $crawlURL) {
followLink($crawlURL, $depth + 1);
}
}
/**
* @param string $site Site
@@ -74,14 +77,16 @@ function followLink($url, $depth = 0)
*/
function convertLink($site, $path)
{
if (substr_compare($path, "//", 0, 2)==0)
if (substr_compare($path, "//", 0, 2) == 0) {
return parse_url($site)['scheme'].$path;
elseif (substr_compare($path, "http://", 0, 7)==0
} elseif (substr_compare($path, "http://", 0, 7) == 0
or substr_compare($path, "https://", 0, 8) == 0
or substr_compare($path, "www.", 0, 4) == 0
)
) {
return $path;
else return $site.'/'.$path;
} else {
return $site.'/'.$path;
}
}
/**
@@ -117,8 +122,9 @@ function insertIntoDatabase($link, $title, &$metaData, $depth)
function getDocTitle(&$doc, $url)
{
$titleNodes = $doc->getElementsByTagName('title');
if (count($titleNodes)==0 or !isset($titleNodes[0]->nodeValue))
if (count($titleNodes) == 0 or !isset($titleNodes[0]->nodeValue)) {
return $url;
}
$title = str_replace('', '\n', $titleNodes[0]->nodeValue);
return (strlen($title) < 1) ? $url : $title;
}
@@ -131,11 +137,15 @@ function getDocMetaData(&$doc)
{
$metaData = array();
$metaNodes = $doc->getElementsByTagName('meta');
foreach ($metaNodes as $node)
foreach ($metaNodes as $node) {
$metaData[$node->getAttribute("name")] = $node->getAttribute("content");
if (!isset($metaData['description']))
}
if (!isset($metaData['description'])) {
$metaData['description'] = 'No Description Available';
if (!isset($metaData['keywords'])) $metaData['keywords']='';
}
if (!isset($metaData['keywords'])) {
$metaData['keywords'] = '';
}
return array(
'keywords' => str_replace('', '\n', $metaData['keywords']),
'description' => str_replace('', '\n', $metaData['description'])