Browse Source

blacklist some known URLs that don't accept webmention

main
Aaron Parecki 8 years ago
parent
commit
2676034041
2 changed files with 33 additions and 19 deletions
  1. +32
    -18
      controllers/Controller.php
  2. +1
    -1
      views/index.php

+ 32
- 18
controllers/Controller.php View File

@ -22,7 +22,7 @@ class Controller {
}
}
private function _get_role(Request $request) {
private function _get_role(Request $request, Response $response) {
// Default to load their first site, but let the query string override it
$role = ORM::for_table('roles')->join('sites', 'roles.site_id = sites.id')
->where('user_id', session('user_id'))->order_by_asc('sites.created_at')->find_one();
@ -199,11 +199,11 @@ class Controller {
$source = $this->http->get($sourceURL);
$parsed = \Mf2\parse($source['body'], $sourceURL);
$links = $client->findOutgoingLinks($parsed);
$links = array_values($client->findOutgoingLinks($parsed));
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode([
'links' => array_values($links)
'links' => $links
]));
return $response;
}
@ -215,25 +215,39 @@ class Controller {
$targetURL = $request->get('target');
// Cache the discovered result
$cacheKey = 'telegraph:discover_endpoint:'.$targetURL;
if($request->get('ignore_cache') == 'true' || (!$status = redis()->get($cacheKey))) {
$client = new IndieWeb\MentionClient();
$endpoint = $client->discoverWebmentionEndpoint($targetURL);
if($endpoint) {
$status = 'webmention';
} else {
$endpoint = $client->discoverPingbackEndpoint($targetURL);
// Reject links that are known to not accept webmentions
$host = str_replace('www.','',parse_url($targetURL, PHP_URL_HOST));
$unsupported = [
'twitter.com',
'instagram.com',
'facebook.com',
];
if(!$host || in_array($host, $unsupported) || preg_match('/.+\.amazonaws\.com/', $host)) {
$status = 'none';
$cached = -1;
} else {
// Cache the discovered result
$cacheKey = 'telegraph:discover_endpoint:'.$targetURL;
if($request->get('ignore_cache') == 'true' || (!$status = redis()->get($cacheKey))) {
$client = new IndieWeb\MentionClient();
$endpoint = $client->discoverWebmentionEndpoint($targetURL);
if($endpoint) {
$status = 'pingback';
$status = 'webmention';
} else {
$status = 'none';
$endpoint = $client->discoverPingbackEndpoint($targetURL);
if($endpoint) {
$status = 'pingback';
} else {
$status = 'none';
}
}
$cached = false;
redis()->setex($cacheKey, 600, $status);
} else {
$cached = true;
}
$cached = false;
redis()->setex($cacheKey, 600, $status);
} else {
$cached = true;
}
$response->headers->set('Content-Type', 'application/json');

+ 1
- 1
views/index.php View File

@ -207,7 +207,7 @@ $menu = [
<div class="ui vertical stripe segment">
<div class="ui text container">
<h3 class="ui header">We send webmentions for you</h3>
<p>Instead of doing the hard work of sending webmentions yourself, we have a simple API that will handle endpoint discovery, gracefully handle failures and retries, and will let you know whether a webmention was successfully sent. All you have to do is tell us the page you want to send the webmention to and we'll take it from there.</p>
<p>Instead of messing with the details of sending webmentions yourself, we have a simple API that will handle endpoint discovery, gracefully handle failures and retries, and will let you know whether a webmention was successfully sent. All you have to do is tell us the page you want to send the webmention to and we'll take it from there.</p>
<a class="ui large button" href="/api">Read More</a>
<!--
<h4 class="ui horizontal header divider">

Loading…
Cancel
Save