Formatting
rodzic
811ad7828f
commit
ad781e6fab
28
index.php
28
index.php
|
@ -110,7 +110,7 @@
|
||||||
// Routing:
|
// Routing:
|
||||||
// The .htaccess changes /whatever to /?path=whatever
|
// The .htaccess changes /whatever to /?path=whatever
|
||||||
// This runs the function of the path requested.
|
// This runs the function of the path requested.
|
||||||
switch ($path) {
|
switch ( $path ) {
|
||||||
case ".well-known/webfinger":
|
case ".well-known/webfinger":
|
||||||
webfinger(); // Mandatory. Static.
|
webfinger(); // Mandatory. Static.
|
||||||
case rawurldecode( $username ):
|
case rawurldecode( $username ):
|
||||||
|
@ -181,7 +181,7 @@
|
||||||
"followers" => "https://{$server}/followers",
|
"followers" => "https://{$server}/followers",
|
||||||
"inbox" => "https://{$server}/inbox",
|
"inbox" => "https://{$server}/inbox",
|
||||||
"outbox" => "https://{$server}/outbox",
|
"outbox" => "https://{$server}/outbox",
|
||||||
"preferredUsername" => rawurldecode($username),
|
"preferredUsername" => rawurldecode( $username ),
|
||||||
"name" => "{$realName}",
|
"name" => "{$realName}",
|
||||||
"summary" => "{$summary}",
|
"summary" => "{$summary}",
|
||||||
"url" => "https://{$server}/{$username}",
|
"url" => "https://{$server}/{$username}",
|
||||||
|
@ -577,8 +577,8 @@ HTML;
|
||||||
if ( isset( $message["published"] ) ) {
|
if ( isset( $message["published"] ) ) {
|
||||||
$published = $message["published"];
|
$published = $message["published"];
|
||||||
} else {
|
} else {
|
||||||
$segments = explode("/", explode("-", $inbox_file ?? "")[0]);
|
$segments = explode( "/", explode( "-", $message_file ?? "" )[0]);
|
||||||
$published_hexstamp = end($segments);
|
$published_hexstamp = end( $segments );
|
||||||
$published_time = hexdec( $published_hexstamp );
|
$published_time = hexdec( $published_hexstamp );
|
||||||
$published = date( "c", $published_time );
|
$published = date( "c", $published_time );
|
||||||
|
|
||||||
|
@ -1038,7 +1038,7 @@ HTML;
|
||||||
file_put_contents( $directories["logs"] . "/{$timestamp}.Error.txt", curl_error( $ch ) );
|
file_put_contents( $directories["logs"] . "/{$timestamp}.Error.txt", curl_error( $ch ) );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
curl_close($ch);
|
curl_close( $ch );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1089,7 +1089,7 @@ HTML;
|
||||||
$ch = curl_init( $inbox );
|
$ch = curl_init( $inbox );
|
||||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($message) );
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $message ) );
|
||||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
|
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
|
||||||
curl_setopt( $ch, CURLOPT_USERAGENT, "activitypub-single-php-file/0.0" );
|
curl_setopt( $ch, CURLOPT_USERAGENT, "activitypub-single-php-file/0.0" );
|
||||||
|
|
||||||
|
@ -1128,7 +1128,7 @@ HTML;
|
||||||
$hashtags = [];
|
$hashtags = [];
|
||||||
$hashtag_pattern = '/(?:^|\s)\#(\w+)/'; // Beginning of string, or whitespace, followed by #
|
$hashtag_pattern = '/(?:^|\s)\#(\w+)/'; // Beginning of string, or whitespace, followed by #
|
||||||
preg_match_all( $hashtag_pattern, $content, $hashtag_matches );
|
preg_match_all( $hashtag_pattern, $content, $hashtag_matches );
|
||||||
foreach ($hashtag_matches[1] as $match) {
|
foreach ( $hashtag_matches[1] as $match ) {
|
||||||
$hashtags[] = $match;
|
$hashtags[] = $match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1256,7 +1256,7 @@ HTML;
|
||||||
$totalItems = count( $posts );
|
$totalItems = count( $posts );
|
||||||
// Create an ordered list
|
// Create an ordered list
|
||||||
$orderedItems = [];
|
$orderedItems = [];
|
||||||
foreach ($posts as $post) {
|
foreach ( $posts as $post ) {
|
||||||
$orderedItems[] = array(
|
$orderedItems[] = array(
|
||||||
"type" => "Create",
|
"type" => "Create",
|
||||||
"actor" => "https://{$server}/{$username}",
|
"actor" => "https://{$server}/{$username}",
|
||||||
|
@ -1387,8 +1387,8 @@ HTML;
|
||||||
$currentDatetime = new DateTime();
|
$currentDatetime = new DateTime();
|
||||||
|
|
||||||
// Calculate the time difference in seconds
|
// Calculate the time difference in seconds
|
||||||
$timeDifference = abs($currentDatetime->getTimestamp() - $headerDatetime->getTimestamp());
|
$timeDifference = abs( $currentDatetime->getTimestamp() - $headerDatetime->getTimestamp() );
|
||||||
if ($timeDifference > 30) {
|
if ( $timeDifference > 30 ) {
|
||||||
// Write a log detailing the error
|
// Write a log detailing the error
|
||||||
$timestamp = ( new DateTime() )->format( DATE_RFC3339_EXTENDED );
|
$timestamp = ( new DateTime() )->format( DATE_RFC3339_EXTENDED );
|
||||||
// Filename for the log
|
// Filename for the log
|
||||||
|
@ -1448,14 +1448,14 @@ HTML;
|
||||||
// Converts 'a=b,c=d e f' into ["a"=>"b", "c"=>"d e f"]
|
// Converts 'a=b,c=d e f' into ["a"=>"b", "c"=>"d e f"]
|
||||||
// word="text"
|
// word="text"
|
||||||
preg_match_all('/(\w+)="([^"]+)"/', $signatureHeader, $matches);
|
preg_match_all('/(\w+)="([^"]+)"/', $signatureHeader, $matches);
|
||||||
foreach ($matches[1] as $index => $key) {
|
foreach ( $matches[1] as $index => $key ) {
|
||||||
$signatureParts[$key] = $matches[2][$index];
|
$signatureParts[$key] = $matches[2][$index];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manually reconstruct the header string
|
// Manually reconstruct the header string
|
||||||
$signatureHeaders = explode(" ", $signatureParts["headers"] );
|
$signatureHeaders = explode(" ", $signatureParts["headers"] );
|
||||||
$signatureString = "";
|
$signatureString = "";
|
||||||
foreach ($signatureHeaders as $signatureHeader) {
|
foreach ( $signatureHeaders as $signatureHeader ) {
|
||||||
if ( "(request-target)" == $signatureHeader ) {
|
if ( "(request-target)" == $signatureHeader ) {
|
||||||
$method = strtolower( $_SERVER["REQUEST_METHOD"] );
|
$method = strtolower( $_SERVER["REQUEST_METHOD"] );
|
||||||
$target = $_SERVER["REQUEST_URI"];
|
$target = $_SERVER["REQUEST_URI"];
|
||||||
|
@ -1496,9 +1496,9 @@ HTML;
|
||||||
);
|
);
|
||||||
|
|
||||||
// Convert to boolean
|
// Convert to boolean
|
||||||
if ($verified === 1) {
|
if ( $verified === 1 ) {
|
||||||
$verified = true;
|
$verified = true;
|
||||||
} elseif ($verified === 0) {
|
} elseif ( $verified === 0 ) {
|
||||||
$verified = false;
|
$verified = false;
|
||||||
} else {
|
} else {
|
||||||
$verified = null;
|
$verified = null;
|
||||||
|
|
Ładowanie…
Reference in New Issue