mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 07:15:13 +00:00
60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
|
<?php
|
||
|
namespace Code\Lib;
|
||
|
|
||
|
use IndieWeb;
|
||
|
|
||
|
class Relme
|
||
|
{
|
||
|
protected $channel = null;
|
||
|
|
||
|
public function setChannel($channel)
|
||
|
{
|
||
|
$this->channel = $channel;
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
public function getChannel()
|
||
|
{
|
||
|
return $this->channel;
|
||
|
}
|
||
|
|
||
|
public function getLinksFrom($url)
|
||
|
{
|
||
|
$output = '';
|
||
|
$results = IndieWeb\relMeDocumentUrl($url);
|
||
|
$canon = $results[0];
|
||
|
$results = Url::get($canon);
|
||
|
if ($results['success']) {
|
||
|
$headers = '<pre>' . htmlspecialchars(print_r($results['header'], true)) . '</pre>';
|
||
|
$output .= $headers;
|
||
|
$links = IndieWeb\relMeLinks($results['body'], $canon);
|
||
|
}
|
||
|
$output .= print_r($links, true);
|
||
|
return $output;
|
||
|
}
|
||
|
|
||
|
|
||
|
public function checkLinks(array $links, $url = null)
|
||
|
{
|
||
|
if ($url) {
|
||
|
$checkUrl = IndieWeb\relMeDocumentUrl($url);
|
||
|
$url = $checkUrl[0];
|
||
|
}
|
||
|
else {
|
||
|
$url = z_root() . '/channel/' . $this->channel['channel_address'];
|
||
|
}
|
||
|
|
||
|
if (!$links || !$url) {
|
||
|
return false;
|
||
|
}
|
||
|
foreach($links as $link) {
|
||
|
list($matches, $secure, $redirectChain) = IndieWeb\backlinkingRelMeUrlMatches($link, $url);
|
||
|
if ($matches && $secure) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|