Browse Source

refactor XKCD parsing

pull/38/head
Aaron Parecki 7 years ago
parent
commit
f19b8fd7dd
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 3 additions and 19 deletions
  1. +0
    -18
      controllers/Parse.php
  2. +3
    -1
      lib/XRay/Parser.php

+ 0
- 18
controllers/Parse.php View File

@ -117,24 +117,6 @@ class Parse {
// Check for known services
$host = parse_url($result['url'], PHP_URL_HOST);
if(in_array($host, ['www.instagram.com','instagram.com'])) {
list($data, $parsed) = Formats\Instagram::parse($result['body'], $result['url'], $this->http);
if($request->get('include_original'))
$data['original'] = $parsed;
$data['url'] = $result['url'];
$data['code'] = $result['code'];
return $this->respond($response, 200, $data);
}
if($host == 'xkcd.com' && parse_url($url, PHP_URL_PATH) != '/') {
$data = Formats\XKCD::parse($result['body'], $url);
$data['url'] = $result['url'];
$data['code'] = $result['code'];
return $this->respond($response, 200, $data);
}
// attempt to parse the page as HTML // attempt to parse the page as HTML
$doc = new DOMDocument(); $doc = new DOMDocument();

+ 3
- 1
lib/XRay/Parser.php View File

@ -26,7 +26,9 @@ class Parser {
return Formats\GitHub::parse($body, $url); return Formats\GitHub::parse($body, $url);
} }
if(Formats\XKCD::matches($url)) {
return Formats\XKCD::parse($body, $url);
}
return [ return [
'data' => [ 'data' => [

Loading…
Cancel
Save