-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·40 lines (32 loc) · 1.25 KB
/
Copy pathindex.php
File metadata and controls
executable file
·40 lines (32 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require __DIR__ . '/../vendor/autoload.php';
require_once('mercury.php');
require_once('related.php');
// $url = $argv[1];
$url = $_GET['url'];
$mercuryParser = new \Mercury\Parser;
$mercuryParser->apiKey = 'API_KEY';
$mercuryParser->url = $url;
$parserData = $mercuryParser->parse();
$htmlString = '';
function getHtmlString($url){
exec("../phantomjs --load-images=false ./getSource.js ".$url, $output);
return implode(" ", $output);
}
if(strlen(strip_tags($parserData['content'])) < 20){
$parsers = \Jkphl\Micrometa\Parser\Microformats2::PARSE | // Microformats = 1
\Jkphl\Micrometa\Parser\Microdata::PARSE | // Microdata = 2
\Jkphl\Micrometa\Parser\JsonLD::PARSE; // JSON-LD = 4
$htmlString = getHtmlString($url);
$micrometaData = \Jkphl\Micrometa::instance($url, $htmlString, $parsers);
$mercuryParser->url = $micrometaData->rels()['amphtml'][0];
$parserData = $mercuryParser->parse();
}
if($htmlString == '') $htmlString = getHtmlString($url);
$relatedParser = new \GM\Related;
$relatedParser->url=$url;
$relatedParser->htmlString=$htmlString;
$relatedContent = $relatedParser->parse();
$parserData['relatedGM'] = $relatedContent;
header('Content-type: application/json');
echo json_encode($parserData);