indieweb/rel-me

用于发现、消费和验证 rel-me 微格式的函数

v0.1.1 2022-10-08 21:02 UTC

This package is auto-updated.

Last update: 2024-09-09 01:07:45 UTC


README

一套PHP函数,用于发现、消费和验证rel-me微格式。这主要用于实现RelMeAuth

Build Status

用法

使用 Composer 安装: ./composer.phar require indieweb/rel-me:dev-master

解析和测试一个个人资料URL

<?php

// Register the composer autoloader (assumed in future code samples.)
require 'vendor/autoload.php';

// This is a profile URL a user has given you, or you have parsed from a page somewhere.
$givenProfileUrl = 'http://waterpigs.co.uk';

list($resolvedProfileUrl, $isSecure, $redirectChain) = IndieWeb\relMeDocumentUrl($givenProfileUrl);

if ($isSecure) {
	// $resolvedProfileUrl is the final resolved profile URL derived from the given one.
} else {
	echo 'Your profile URL redirected insecurely (changed protocols)';
	// Here you might use the $redirectChain (list of URLs) to present a more useful error message.
}

在一个页面上找到所有的 rel=me 链接

// This should be derived and checked using relMeDocumentUrl().
$resolvedProfileUrl = 'http://waterpigs.co.uk';

$relMeLinks = IndieWeb\relMeLinks($resolvedProfileUrl);

测试一个回链 rel=me URL 是否可以安全地被认为是链接

// A rel=me link from a silo profile page.
$inboundRelMeUrl = 'https://#/qhZqdUcTbQ';
// The derived profile document URL to test for matches of.
$meUrl = 'http://waterpigs.co.uk';

list($matches, $secure, $redirectChain) = IndieWeb\backlinkingRelMeUrlMatches($inboundRelMeUrl, $meUrl);

if ($matches) {
	if ($secure) {
		echo "{$inboundRelMeUrl} is a secure, valid link to {$meUrl}";
	} else {
		echo "{$inboundRelMeUrl} isn’t a secure link to {$meUrl} because it redirects insecurely (changes protocols)";
		// Here you might use the $redirectChain (list of URLs) to present a more useful error message.
	}
} else {
	echo "None of that silo backlink’s redirect chain match {$meUrl}";
}

实用函数

  • string $url = IndieWeb\unparseUrl(array $parsedUrl) 将核心 parse_url() 的输出转换为URL
  • string $url = IndieWeb\normaliseUrl($url) 通过解析和再次解析来规范化URL
  • list(string $body, array $headers, array $info) = IndieWeb\httpGet($url) 对URL执行基本的HTTP GET操作
  • string $nextUrl | null = IndieWeb\followOneRedirect($url) 获取一个URL,如果它是重定向,则返回重定向URL,否则返回 null
  • bool $match = IndieWeb\urlsMatchOtherThanScheme($url1, $url2) 比较两个URL并返回它们是否相同,忽略方案的不同

测试

使用 ./vendor/bin/phpunit 运行测试套件

还有一个实验性的HTML+microformats测试套件,可以使用 ./tests/html-test-runner.php 运行

版本历史

0.1.1 2022-10-08

  • 更新依赖,包括php-mf2 v0.5.0
  • 更新CI到Github Actions

0.1.0 2014-01-04

  • 从indiewebify.me中提取,转换成composer包