Ejemplo n.º 1
0
 public function discover_endpoint(Request $request, Response $response)
 {
     if (!$this->_is_logged_in($request, $response)) {
         return $response;
     }
     $targetURL = $request->get('target');
     if (!Telegraph\Webmention::isProbablySupported($targetURL)) {
         $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 = 'webmention';
             } else {
                 $endpoint = $client->discoverPingbackEndpoint($targetURL);
                 if ($endpoint) {
                     $status = 'pingback';
                 } else {
                     $status = 'none';
                 }
             }
             $cached = false;
             redis()->setex($cacheKey, 600, $status);
         } else {
             $cached = true;
         }
     }
     $response->headers->set('Content-Type', 'application/json');
     $response->setContent(json_encode(['status' => $status, 'cached' => $cached]));
     return $response;
 }