|
@ -47,6 +47,22 @@ class Controller { |
|
|
return $response; |
|
|
return $response; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static function _icon_for_status($status) { |
|
|
|
|
|
switch($status) { |
|
|
|
|
|
case 'success': |
|
|
|
|
|
case 'accepted': |
|
|
|
|
|
return 'green checkmark'; |
|
|
|
|
|
case 'not_supported': |
|
|
|
|
|
return 'yellow x'; |
|
|
|
|
|
case 'error': |
|
|
|
|
|
return 'red x'; |
|
|
|
|
|
case 'pending': |
|
|
|
|
|
return 'orange wait'; |
|
|
|
|
|
default: |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public function dashboard(Request $request, Response $response) { |
|
|
public function dashboard(Request $request, Response $response) { |
|
|
if(!$this->_is_logged_in($request, $response)) { |
|
|
if(!$this->_is_logged_in($request, $response)) { |
|
|
return $response; |
|
|
return $response; |
|
@ -67,23 +83,11 @@ class Controller { |
|
|
foreach($query as $m) { |
|
|
foreach($query as $m) { |
|
|
$statuses = ORM::for_table('webmention_status')->where('webmention_id', $m->id)->order_by_desc('created_at')->find_many(); |
|
|
$statuses = ORM::for_table('webmention_status')->where('webmention_id', $m->id)->order_by_desc('created_at')->find_many(); |
|
|
if(count($statuses) == 0) { |
|
|
if(count($statuses) == 0) { |
|
|
$icon = 'wait'; |
|
|
|
|
|
$status = 'pending'; |
|
|
$status = 'pending'; |
|
|
} else { |
|
|
} else { |
|
|
$status = $statuses[0]->status; |
|
|
$status = $statuses[0]->status; |
|
|
switch($status) { |
|
|
|
|
|
case 'success': |
|
|
|
|
|
case 'accepted': |
|
|
|
|
|
$icon = 'checkmark'; |
|
|
|
|
|
break; |
|
|
|
|
|
case 'not_supported': |
|
|
|
|
|
case 'error': |
|
|
|
|
|
$icon = 'warning'; |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
$icon = ''; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
$icon = self::_icon_for_status($status); |
|
|
|
|
|
|
|
|
$webmentions[] = [ |
|
|
$webmentions[] = [ |
|
|
'webmention' => $m, |
|
|
'webmention' => $m, |
|
@ -98,6 +102,7 @@ class Controller { |
|
|
'user' => $this->_user(), |
|
|
'user' => $this->_user(), |
|
|
'accounts' => $this->_accounts(), |
|
|
'accounts' => $this->_accounts(), |
|
|
'site' => $site, |
|
|
'site' => $site, |
|
|
|
|
|
'role' => $role, |
|
|
'webmentions' => $webmentions |
|
|
'webmentions' => $webmentions |
|
|
])); |
|
|
])); |
|
|
return $response; |
|
|
return $response; |
|
@ -120,13 +125,22 @@ class Controller { |
|
|
|
|
|
|
|
|
$statuses = ORM::for_table('webmention_status')->where('webmention_id', $webmention->id)->order_by_desc('created_at')->find_many(); |
|
|
$statuses = ORM::for_table('webmention_status')->where('webmention_id', $webmention->id)->order_by_desc('created_at')->find_many(); |
|
|
|
|
|
|
|
|
|
|
|
if(count($statuses) == 0) { |
|
|
|
|
|
$status = 'pending'; |
|
|
|
|
|
} else { |
|
|
|
|
|
$status = $statuses[0]->status; |
|
|
|
|
|
} |
|
|
|
|
|
$icon = self::_icon_for_status($status); |
|
|
|
|
|
|
|
|
$response->setContent(view('webmention-details', [ |
|
|
$response->setContent(view('webmention-details', [ |
|
|
'title' => 'Webmention Details', |
|
|
'title' => 'Webmention Details', |
|
|
'user' => $this->_user(), |
|
|
'user' => $this->_user(), |
|
|
'accounts' => $this->_accounts(), |
|
|
'accounts' => $this->_accounts(), |
|
|
'site' => $site, |
|
|
'site' => $site, |
|
|
'webmention' => $webmention, |
|
|
'webmention' => $webmention, |
|
|
'statuses' => $statuses |
|
|
|
|
|
|
|
|
'statuses' => $statuses, |
|
|
|
|
|
'icon' => $icon, |
|
|
|
|
|
'status' => $status |
|
|
])); |
|
|
])); |
|
|
return $response; |
|
|
return $response; |
|
|
} |
|
|
} |
|
@ -173,6 +187,42 @@ class Controller { |
|
|
return $response; |
|
|
return $response; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function discover_endpoint(Request $request, Response $response) { |
|
|
|
|
|
if(!$this->_is_logged_in($request, $response)) { |
|
|
|
|
|
return $response; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$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); |
|
|
|
|
|
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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private function _user() { |
|
|
private function _user() { |
|
|
return ORM::for_table('users')->where_id_is(session('user_id'))->find_one(); |
|
|
return ORM::for_table('users')->where_id_is(session('user_id'))->find_one(); |
|
|
} |
|
|
} |
|
|