Browse Source

fix media crawling

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

77
crontab/crawler.php

@ -250,11 +250,23 @@ try { @@ -250,11 +250,23 @@ try {
continue;
}
// Skip page processing on MIME type not allowed in settings
// Validate MIME
$hostPageIsDom = false;
$hostPageBanned = true;
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;
break;
@ -276,7 +288,17 @@ try { @@ -276,7 +288,17 @@ try {
continue;
}
// Grab page content
// Define variables
$title = null;
$description = null;
$keywords = null;
$robots = null;
$yggoManifest = null;
// Is DOM
if ($hostPageIsDom) {
// Parse content
$dom = new DomDocument();
@$dom->loadHTML($content);
@ -289,35 +311,29 @@ try { @@ -289,35 +311,29 @@ try {
$hostPagesBanned += $db->updateHostPageTimeBanned($queueHostPage->hostPageId, time());
continue;
} else {
$title = $title->item(0)->nodeValue;
}
// Get optional page meta data
$metaDescription = '';
$metaKeywords = '';
$metaRobots = '';
$metaYggoManifest = '';
foreach (@$dom->getElementsByTagName('meta') as $meta) {
if (@$meta->getAttribute('name') == 'description') {
$metaDescription = @$meta->getAttribute('content');
$description = @$meta->getAttribute('content');
}
if (@$meta->getAttribute('name') == 'keywords') {
$metaKeywords = @$meta->getAttribute('content');
$keywords = @$meta->getAttribute('content');
}
if (@$meta->getAttribute('name') == 'robots') {
$metaRobots = @$meta->getAttribute('content');
}
if (@$meta->getAttribute('name') == 'yggo:manifest') {
$metaYggoManifest = Filter::url(@$meta->getAttribute('content'));
}
}
$robots = @$meta->getAttribute('content');
// Append page with meta robots:noindex value to the robotsPostfix disallow list
if (false !== stripos($metaRobots, 'noindex')) {
if (false !== stripos($robots, 'noindex')) {
$hostPagesBanned += $db->updateHostPageTimeBanned($queueHostPage->hostPageId, time());
@ -325,10 +341,17 @@ try { @@ -325,10 +341,17 @@ try {
}
// Skip page links following by robots:nofollow attribute detected
if (false !== stripos($metaRobots, 'nofollow')) {
if (false !== stripos($robots, 'nofollow')) {
continue;
}
}
if (@$meta->getAttribute('name') == 'yggo:manifest') {
$yggoManifest = Filter::url(@$meta->getAttribute('content'));
}
}
}
// Update queued page
$hostPagesIndexed += $db->updateHostPage($queueHostPage->hostPageId,
@ -337,20 +360,20 @@ try { @@ -337,20 +360,20 @@ try {
// Add queued page description if not exists
$db->addHostPageDescription($queueHostPage->hostPageId,
Filter::pageTitle($title->item(0)->nodeValue),
Filter::pageDescription($metaDescription),
Filter::pageKeywords($metaKeywords),
$queueHostPage->crawlMetaOnly ? null : base64_encode($content),
$title ? Filter::pageTitle($title) : null,
$description ? Filter::pageDescription($description) : null,
$keywords ? Filter::pageKeywords($keywords) : null,
$content ? ($queueHostPage->crawlMetaOnly ? null : base64_encode($content)) : null,
time());
// 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)) {
$db->addManifest($metaYggoManifestCRC32,
$metaYggoManifest,
if (!$db->getManifest($yggoManifestCRC32)) {
$db->addManifest($yggoManifestCRC32,
$yggoManifest,
(string) CRAWL_MANIFEST_DEFAULT_STATUS,
time());

2
library/filter.php

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

Loading…
Cancel
Save