Browse Source

fix media crawling

main
ghost 2 years ago
parent
commit
7c5ba050b2
  1. 115
      crontab/crawler.php
  2. 2
      library/filter.php

115
crontab/crawler.php

@ -250,11 +250,23 @@ try {
continue; continue;
} }
// Skip page processing on MIME type not allowed in settings // Validate MIME
$hostPageIsDom = false;
$hostPageBanned = true; $hostPageBanned = true;
foreach ((array) explode(',', CRAWL_PAGE_MIME) as $mime) { foreach ((array) explode(',', CRAWL_PAGE_MIME) as $mime) {
if (false !== strpos($contentType, trim($mime))) { $mime = trim(strtolower($mime));
// Check for DOM
if (false !== strpos('text/html', $mime)) {
$hostPageIsDom = true;
$hostPageBanned = false;
break;
}
// Ban page on MIME type not allowed in settings
if (false !== strpos(strtolower($contentType), $mime)) {
$hostPageBanned = false; $hostPageBanned = false;
break; break;
@ -276,58 +288,69 @@ try {
continue; continue;
} }
// Grab page content // Define variables
$dom = new DomDocument(); $title = null;
$description = null;
$keywords = null;
$robots = null;
$yggoManifest = null;
@$dom->loadHTML($content); // Is DOM
if ($hostPageIsDom) {
// Skip index page links without titles // Parse content
$title = @$dom->getElementsByTagName('title'); $dom = new DomDocument();
if ($title->length == 0) { @$dom->loadHTML($content);
$hostPagesBanned += $db->updateHostPageTimeBanned($queueHostPage->hostPageId, time()); // Skip index page links without titles
$title = @$dom->getElementsByTagName('title');
continue; if ($title->length == 0) {
}
// Get optional page meta data $hostPagesBanned += $db->updateHostPageTimeBanned($queueHostPage->hostPageId, time());
$metaDescription = '';
$metaKeywords = '';
$metaRobots = '';
$metaYggoManifest = '';
foreach (@$dom->getElementsByTagName('meta') as $meta) { continue;
if (@$meta->getAttribute('name') == 'description') { } else {
$metaDescription = @$meta->getAttribute('content');
}
if (@$meta->getAttribute('name') == 'keywords') { $title = $title->item(0)->nodeValue;
$metaKeywords = @$meta->getAttribute('content');
} }
if (@$meta->getAttribute('name') == 'robots') { // Get optional page meta data
$metaRobots = @$meta->getAttribute('content'); foreach (@$dom->getElementsByTagName('meta') as $meta) {
}
if (@$meta->getAttribute('name') == 'yggo:manifest') { if (@$meta->getAttribute('name') == 'description') {
$metaYggoManifest = Filter::url(@$meta->getAttribute('content')); $description = @$meta->getAttribute('content');
} }
}
// Append page with meta robots:noindex value to the robotsPostfix disallow list if (@$meta->getAttribute('name') == 'keywords') {
if (false !== stripos($metaRobots, 'noindex')) { $keywords = @$meta->getAttribute('content');
}
$hostPagesBanned += $db->updateHostPageTimeBanned($queueHostPage->hostPageId, time()); if (@$meta->getAttribute('name') == 'robots') {
continue; $robots = @$meta->getAttribute('content');
}
// Skip page links following by robots:nofollow attribute detected // Append page with meta robots:noindex value to the robotsPostfix disallow list
if (false !== stripos($metaRobots, 'nofollow')) { if (false !== stripos($robots, 'noindex')) {
continue; $hostPagesBanned += $db->updateHostPageTimeBanned($queueHostPage->hostPageId, time());
continue;
}
// Skip page links following by robots:nofollow attribute detected
if (false !== stripos($robots, 'nofollow')) {
continue;
}
}
if (@$meta->getAttribute('name') == 'yggo:manifest') {
$yggoManifest = Filter::url(@$meta->getAttribute('content'));
}
}
} }
// Update queued page // Update queued page
@ -337,20 +360,20 @@ try {
// Add queued page description if not exists // Add queued page description if not exists
$db->addHostPageDescription($queueHostPage->hostPageId, $db->addHostPageDescription($queueHostPage->hostPageId,
Filter::pageTitle($title->item(0)->nodeValue), $title ? Filter::pageTitle($title) : null,
Filter::pageDescription($metaDescription), $description ? Filter::pageDescription($description) : null,
Filter::pageKeywords($metaKeywords), $keywords ? Filter::pageKeywords($keywords) : null,
$queueHostPage->crawlMetaOnly ? null : base64_encode($content), $content ? ($queueHostPage->crawlMetaOnly ? null : base64_encode($content)) : null,
time()); time());
// Update manifest registry // Update manifest registry
if (CRAWL_MANIFEST && !empty($metaYggoManifest) && filter_var($metaYggoManifest, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $metaYggoManifest)) { if (CRAWL_MANIFEST && !empty($yggoManifest) && filter_var($yggoManifest, FILTER_VALIDATE_URL) && preg_match(CRAWL_URL_REGEXP, $yggoManifest)) {
$metaYggoManifestCRC32 = crc32($metaYggoManifest); $yggoManifestCRC32 = crc32($yggoManifest);
if (!$db->getManifest($metaYggoManifestCRC32)) { if (!$db->getManifest($yggoManifestCRC32)) {
$db->addManifest($metaYggoManifestCRC32, $db->addManifest($yggoManifestCRC32,
$metaYggoManifest, $yggoManifest,
(string) CRAWL_MANIFEST_DEFAULT_STATUS, (string) CRAWL_MANIFEST_DEFAULT_STATUS,
time()); time());

2
library/filter.php

@ -18,7 +18,7 @@ class Filter {
$mime = (string) $mime; $mime = (string) $mime;
return trim($mime); return trim(strtolower($mime));
} }
static public function pageTitle(mixed $title) { static public function pageTitle(mixed $title) {

Loading…
Cancel
Save