187 lines
6.0 KiB
PHP
187 lines
6.0 KiB
PHP
<?php
|
|
/*************************************************************
|
|
# 076 License
|
|
|
|
Copyright (c) テクニカル諏訪子
|
|
|
|
Permission is hereby granted to any person obtaining a copy of the software
|
|
Little Beast (the "Software") to use, modify, merge, copy, publish, distribute,
|
|
sublicense, and/or sell copies of the Software, subject to the following conditions:
|
|
|
|
1. **Origin Attribution**:
|
|
- You must not misrepresent the origin of the Software; you must not claim
|
|
you created the original Software.
|
|
- If the Software is used in a product, you must either:
|
|
a. Provide clear attribution in the product's documentation, user interface,
|
|
or other visible areas, **OR**
|
|
b. Pay the original developers a fee they specify in writing.
|
|
2. **Usage Restriction**:
|
|
- The Software, or any derivative works, dependencies, or libraries
|
|
incorporating it, must not be used for censorship or to suppress freedom of
|
|
speech, expression, or creativity. Prohibited uses include, but are not
|
|
limited to:
|
|
- Censorship of so-called "hate speech", visuals, non-mainstream opinions,
|
|
ideas, or objective reality.
|
|
- Tools or systems designed to restrict access to information or
|
|
artistic works.
|
|
3. **Notice Preservation**:
|
|
- This license and the above copyright notice must remain intact in all copies
|
|
of the source code.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
|
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
namespace Site\Controller;
|
|
|
|
use Site\Controller\BlogPost;
|
|
use Site\Controller\Mods;
|
|
use Std\Lib\Activitypub;
|
|
|
|
class Fediverse extends BlogPost {
|
|
use Mods;
|
|
|
|
/**
|
|
* @param array $params パラメータ配列
|
|
* @return void
|
|
*/
|
|
public function apfinger(array $params): void {
|
|
try {
|
|
header('Content-Type: application/jrd+json');
|
|
$ap = new Activitypub();
|
|
echo $ap->getWebfinger();
|
|
exit;
|
|
} catch (\Exception $e) {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'フェディバースの作成に失敗: '.$e->getMessage();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array $params パラメータ配列
|
|
* @return void
|
|
*/
|
|
public function apactor(array $params): void {
|
|
try {
|
|
header('Content-Type: application/activity+json');
|
|
$ap = new Activitypub();
|
|
echo $ap->getActor();
|
|
exit;
|
|
} catch (\Exception $e) {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'フェディバースの作成に失敗: '.$e->getMessage();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array $params パラメータ配列
|
|
* @return void
|
|
*/
|
|
public function apinbox(array $params): void {
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header('HTTP/1.1 405 Method Not Allowed');
|
|
header('Allow: POST');
|
|
exit;
|
|
}
|
|
|
|
$input = file_get_contents('php://input');
|
|
$activity = json_decode($input, true);
|
|
if (!$activity || !isset($activity['type'])) {
|
|
header('HTTP/1.1 400 Bad Request');
|
|
header('Content-Type: application/activity+json');
|
|
echo json_encode(['error' => '不正なアクティビティ']);
|
|
exit;
|
|
}
|
|
|
|
logger(\LogType::ActivityPub, "受付に入れた:".json_encode($activity));
|
|
|
|
try {
|
|
header('Content-Type: application/activity+json');
|
|
$ap = new Activitypub();
|
|
$ap->postInbox($activity);
|
|
exit;
|
|
} catch (\Exception $e) {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'フェディバースの作成に失敗: '.$e->getMessage();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array $params パラメータ配列
|
|
* @return void
|
|
*/
|
|
public function apactivity(array $params): void {
|
|
$uuid = '';
|
|
if (isset($params['uuid'])) $uuid = $params['uuid'];
|
|
|
|
try {
|
|
header('Content-Type: application/activity+json');
|
|
$posts = $this->getPosts('/blog/', null);
|
|
$ap = new Activitypub($posts);
|
|
echo $ap->getActivity($uuid);
|
|
exit;
|
|
} catch (\Exception $e) {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'フェディバースの作成に失敗: '.$e->getMessage();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array $params パラメータ配列
|
|
* @return void
|
|
*/
|
|
public function apoutbox(array $params): void {
|
|
try {
|
|
header('Content-Type: application/activity+json');
|
|
$posts = $this->getPosts('/blog/', null);
|
|
$ap = new Activitypub($posts);
|
|
echo $ap->getOutbox();
|
|
exit;
|
|
} catch (\Exception $e) {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'フェディバースの作成に失敗: '.$e->getMessage();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array $params パラメータ配列
|
|
* @return void
|
|
*/
|
|
public function apfollowers(array $params): void {
|
|
try {
|
|
header('Content-Type: application/activity+json');
|
|
$ap = new Activitypub();
|
|
echo $ap->getFollowers();
|
|
exit;
|
|
} catch (\Exception $e) {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'フェディバースの作成に失敗: '.$e->getMessage();
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param array $params パラメータ配列
|
|
* @return void
|
|
*/
|
|
public function apfollowing(array $params): void {
|
|
try {
|
|
header('Content-Type: application/activity+json');
|
|
$ap = new Activitypub();
|
|
echo $ap->getFollowing();
|
|
exit;
|
|
} catch (\Exception $e) {
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
echo 'フェディバースの作成に失敗: '.$e->getMessage();
|
|
exit;
|
|
}
|
|
}
|
|
} |