all repos — blogroll2email @ 860a172661e87a97a6c06b53458e6ab41c70b517

vendor/mf2/mf2/bin/fetch-mf2 (view raw)

 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
 41
 42
#!/usr/bin/env php
<?php

$files = array(
  __DIR__ . '/../vendor/autoload.php',
  __DIR__ . '/../../../autoload.php',
  __DIR__ . '/../Mf2/Parser.php'
);

foreach ($files as $file) {
	if (file_exists($file)) {
		require $file;
		define('COMPOSER_INSTALL_LOCATION', $file);
		break;
	}
}

if (!defined('COMPOSER_INSTALL_LOCATION')) {
	die('A composer /vendor/autoload.php file could not be found. You need to install composer: https://getcomposer.org/download');
}

$url = $argv[1];

if (empty($url)) {
	die("Please provide a URL to fetch+parse, e.g. bin/fetch-mf2 waterpigs.co.uk/notes");
}

if (!file_exists($url)) {
	if (!preg_match('|https?://|', $url)) {
		$url = 'http://' . $url;
	}
}

$html = file_get_contents($url);

$result = Mf2\parse($html, $url);

if (defined('JSON_PRETTY_PRINT')) {
	echo json_encode($result, JSON_PRETTY_PRINT);
} else {
	echo json_encode($result);
}