Skip to content

Commit

Permalink
Issue #13 - Ignoring content for non-HTML files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thee Roperto committed Dec 13, 2016
1 parent 8f86af9 commit 66561f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions classes/robot/crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,17 +737,18 @@ public function scrape($url) {
curl_close($s);
return $result;
}
// See http://stackoverflow.com/questions/9351694/setting-php-default-encoding-to-utf-8 for more.
unset($charset);
$contenttype = curl_getinfo($s, CURLINFO_CONTENT_TYPE);
$ishtml = (strpos($contenttype, 'text/html') === 0); // Related to Issue #13.

$headersize = curl_getinfo($s, CURLINFO_HEADER_SIZE);
$headers = substr($raw, 0, $headersize);
$header = strtok($headers, "\n");
$result->httpmsg = explode(" ", $header, 3)[2];
$result->contents = substr($raw, $headersize);
$result->contents = $ishtml ? substr($raw, $headersize) : '';
$data = $result->contents;

// See http://stackoverflow.com/questions/9351694/setting-php-default-encoding-to-utf-8 for more.
unset($charset);
$contenttype = curl_getinfo($s, CURLINFO_CONTENT_TYPE);

/* 1: HTTP Content-Type: header */
preg_match( '@([\w/+]+)(;\s*charset=(\S+))?@i', $contenttype, $matches );
if ( isset( $matches[3] ) ) {
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2016081601; // The current plugin version (Date: YYYYMMDDXX)
$plugin->release = 2016081601; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2016121300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->release = 2016121300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2013110500; // Requires this Moodle version.
$plugin->component = 'tool_crawler'; // To check on upgrade, that module sits in correct place.
$plugin->maturity = MATURITY_STABLE;
Expand Down

0 comments on commit 66561f9

Please sign in to comment.