Compare commits

...

16 Commits
0.1.16 ... main

2 changed files with 147 additions and 142 deletions

View File

@ -1,7 +1,8 @@
# gnuboard5-activitypub # gnuboard5-activitypub
ActivityPub implementation for GNUBOARD 5 GNUBOARD5-ActivityPub: ActivityPub (Fediverse) implementation for GNUBOARD5
https://sir.kr/g5_plugin/10381 * https://sir.kr/g5_plugin/10381
* https://codeberg.org/fediverse/delightful-activitypub-development
## 사용 전 설정 ## 사용 전 설정
* `apstreams` 게시판 추가 * `apstreams` 게시판 추가
@ -15,12 +16,12 @@ https://sir.kr/g5_plugin/10381
- [x] Followers - [x] Followers
- [x] Following - [x] Following
- [x] Liked - [x] Liked
- [ ] Shares (개선 진행 중) - [ ] ~~Shares~~ (Altered to inbound/outbound)
- [x] Geolocation (IP2Location, Naver Cloud) - [x] Geolocation
- [x] File attachment - [x] File attachment
- [ ] File attachment - Automatically download a file to the local server - [ ] File attachment - Automatically download a remote file to the local server
- [x] Digest/Signature - [x] Digest/Signature - Outbound
- [ ] Digest/Signature - Verification - [ ] ~~Digest/Signature - Inbound~~ (No required)
- [x] w3id.org (e.g. the `publicKey` field of an actor) - [x] w3id.org (e.g. the `publicKey` field of an actor)
- [ ] OAuth 2.0 - [ ] OAuth 2.0
- [ ] Message Queue Compatible (e.g. Redis, RebbitMQ, Kafka) - [ ] Message Queue Compatible (e.g. Redis, RebbitMQ, Kafka)
@ -29,9 +30,10 @@ https://sir.kr/g5_plugin/10381
- [x] 아바타 (gravatar.com) - [x] 아바타 (gravatar.com)
- [x] 날씨 (openweathermap.org) - [x] 날씨 (openweathermap.org)
- [x] 환율 (koreaexim.go.kr) - [x] 환율 (koreaexim.go.kr)
- [x] 국내 Geolocation (Naver Cloud)
- [x] 국외 Geolocation (IP2Location)
## 전문(메시지) 예시
## 전문 예시
```json ```json
{ {
@ -121,6 +123,9 @@ https://sir.kr/g5_plugin/10381
* https://github.com/autogestion/pubgate-telegram * https://github.com/autogestion/pubgate-telegram
* https://docs.joinmastodon.org/spec/security/ * https://docs.joinmastodon.org/spec/security/
* https://chat.openai.com/share/4fda7974-cc0b-439a-b0f2-dc828f8acfef * https://chat.openai.com/share/4fda7974-cc0b-439a-b0f2-dc828f8acfef
* https://codeberg.org/mro/activitypub/src/commit/4b1319d5363f4a836f23c784ef780b81bc674013/like.sh#L101
* https://socialhub.activitypub.rocks/t/problems-posting-to-mastodon-inbox/801/10
## 문의 ## 문의
* abuse@catswords.net * abuse@catswords.net
* ActivityPub [@gnh1201@catswords.social](https://catswords.social/@gnh1201)

View File

@ -1,11 +1,12 @@
<?php <?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가 if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// ActivityPub implementation for GNUBOARD 5 // Description: ActivityPub implementation for GNUBOARD 5
// Go Namhyeon <abuse@catswords.net> // Author: Go Namhyeon (Catswords Research) <abuse@catswords.net>
// MIT License // ActivityPub: @gnh1201@catswords.social
// 2023-08-06 (version 0.1.16) // License: MIT
// Date: 2023-08-08
// Version: 0.1.18
// References: // References:
// * https://www.w3.org/TR/activitypub/ // * https://www.w3.org/TR/activitypub/
// * https://www.w3.org/TR/activitystreams-core/ // * https://www.w3.org/TR/activitystreams-core/
@ -17,9 +18,12 @@ if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
// * https://github.com/broidHQ/integrations/tree/master/broid-schemas#readme // * https://github.com/broidHQ/integrations/tree/master/broid-schemas#readme
// * https://github.com/autogestion/pubgate-telegram // * https://github.com/autogestion/pubgate-telegram
// * https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/ // * https://blog.joinmastodon.org/2018/06/how-to-implement-a-basic-activitypub-server/
// * https://chat.openai.com/share/4fda7974-cc0b-439a-b0f2-dc828f8acfef
// * https://codeberg.org/mro/activitypub/src/commit/4b1319d5363f4a836f23c784ef780b81bc674013/like.sh#L101
// * https://socialhub.activitypub.rocks/t/problems-posting-to-mastodon-inbox/801/10
define("ACTIVITYPUB_INSTANCE_ID", md5_file(G5_DATA_PATH . "/dbconfig.php")); define("ACTIVITYPUB_INSTANCE_ID", md5_file(G5_DATA_PATH . "/dbconfig.php"));
define("ACTIVITYPUB_INSTANCE_VERSION", "0.1.14-dev"); define("ACTIVITYPUB_INSTANCE_VERSION", "0.1.18");
define("ACTIVITYPUB_DEFAULT_SCHEME", "https"); // 외부 통신용 스킴 (SSL 사용이 기본) define("ACTIVITYPUB_DEFAULT_SCHEME", "https"); // 외부 통신용 스킴 (SSL 사용이 기본)
define("ACTIVITYPUB_INSECURE_SCHEME", "http"); // 그누보드5 ActivityPub 통신용 스킴 (SSL 사용을 하지 않을 수도 있음을 고려) define("ACTIVITYPUB_INSECURE_SCHEME", "http"); // 그누보드5 ActivityPub 통신용 스킴 (SSL 사용을 하지 않을 수도 있음을 고려)
define("ACTIVITYPUB_HOST", (empty(G5_DOMAIN) ? $_SERVER['HTTP_HOST'] : G5_DOMAIN)); define("ACTIVITYPUB_HOST", (empty(G5_DOMAIN) ? $_SERVER['HTTP_HOST'] : G5_DOMAIN));
@ -348,7 +352,7 @@ function activitypub_build_http_headers($headers) {
function activitypub_build_datetime($s='now') { function activitypub_build_datetime($s='now') {
// e.g. 18 Dec 2019 10:08:46 GMT // e.g. 18 Dec 2019 10:08:46 GMT
$format = "d M Y H:i:s e"; $format = "D, d M Y H:i:s e";
$dt = ($s == "now" ? new DateTime('now', new DateTimeZone("GMT")) : DateTime::createFromFormat($format, $s)); $dt = ($s == "now" ? new DateTime('now', new DateTimeZone("GMT")) : DateTime::createFromFormat($format, $s));
return $dt->format($format); return $dt->format($format);
} }
@ -360,7 +364,7 @@ function activitypub_build_digest($body) {
return $digest; return $digest;
} }
function activitypub_build_signature($url, $date, $digest, $mb, $method="POST") { function activitypub_build_signature($url, $date, $digest, $mb, $method="post") {
// get a certificate // get a certificate
list($private_key, $public_key) = activitypub_get_stored_keypair($mb); list($private_key, $public_key) = activitypub_get_stored_keypair($mb);
@ -372,13 +376,24 @@ function activitypub_build_signature($url, $date, $digest, $mb, $method="POST")
$keyId = $activitypub_user_id . "#main-key"; $keyId = $activitypub_user_id . "#main-key";
// build a target data to get signature // build a target data to get signature
/*
$signature = $method . ' ' . $path . "\n" . $signature = $method . ' ' . $path . "\n" .
'HOST: ' . $host . "\n" . 'HOST: ' . $host . "\n" .
'Date: ' . $date . "\n" . 'Date: ' . $date . "\n" .
'Digest: ' . $digest; 'Digest: ' . $digest;
*/
// Ref: https://codeberg.org/mro/activitypub/src/commit/4b1319d5363f4a836f23c784ef780b81bc674013/like.sh#L101
$signature = sprintf(
"%s: %s\n%s: %s\n%s: %s\n%s: %s",
"(request-target)",
"{$method} {$path}",
"host", $host,
"date", $date,
"digest", $digest
);
// create a signature // create a signature
openssl_sign($signature, $signature, $privateKey, OPENSSL_ALGO_SHA256); openssl_sign($signature, $signature, $private_key, OPENSSL_ALGO_SHA256);
$signature = base64_encode($signature); $signature = base64_encode($signature);
// create a signature header // create a signature header
@ -389,7 +404,7 @@ function activitypub_http_get($url, $access_token = '') {
// build the header // build the header
$headers = array( $headers = array(
"Date" => activitypub_build_datetime('now'), "Date" => activitypub_build_datetime('now'),
"Accept" => "application/ld+json; profile=\"" . NAMESPACE_ACTIVITYSTREAMS . "\"" "Accept" => "application/activity+json; profile=\"" . NAMESPACE_ACTIVITYSTREAMS . "\""
); );
// set access token // set access token
@ -430,20 +445,20 @@ function activitypub_get_attachments($bo_table, $wr_id) {
return $attachments; return $attachments;
} }
function activitypub_http_post($url, $raw_data, $mb, $access_token = '') { function activitypub_http_post($url, $rawdata, $mb, $access_token = '') {
// get digest // get digest
$date = activitypub_build_datetime('now'); $date = activitypub_build_datetime('now');
$digest = activitypub_build_digest($raw_data); $digest = activitypub_build_digest($rawdata);
// build the headers // build the headers
$headers = array( $headers = array(
"Date" => $date, "Date" => $date,
"Digest" => $digest, "Digest" => $digest,
"Content-Type" => "application/ld+json; profile=\"" . NAMESPACE_ACTIVITYSTREAMS . "\"", "Content-Type" => "application/activity+json; profile=\"" . NAMESPACE_ACTIVITYSTREAMS . "\"",
); );
// build the signature // build the signature
$signature = activitypub_build_signature($url, $date, $digest, $mb, "POST"); $signature = activitypub_build_signature($url, $date, $digest, $mb);
$headers["Signature"] = $signature; $headers["Signature"] = $signature;
// set access token // set access token
@ -459,12 +474,18 @@ function activitypub_http_post($url, $raw_data, $mb, $access_token = '') {
CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true, CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $raw_data, CURLOPT_POSTFIELDS => $rawdata,
CURLOPT_POST => true CURLOPT_POST => true
)); ));
$response = curl_exec($ch); $response = curl_exec($ch);
$errno = curl_errno($ch);
curl_close($ch); curl_close($ch);
// 전송 오류가 있었을 시 쪽지로 알림
if ($errno) {
activitypub_add_memo(ACTIVITYPUB_G5_USERNAME, $mb['mb_id'], "[경고] 메시지 전송 중 오류가 발생함. 오류 번호: " . $errno);
}
return activitypub_json_decode($response, true); return activitypub_json_decode($response, true);
} }
@ -560,6 +581,9 @@ function koreaexim_get_exchange_data() {
} }
function activitypub_publish_content($content, $object_id, $mb, $_added_object = array(), $_added_to = array()) { function activitypub_publish_content($content, $object_id, $mb, $_added_object = array(), $_added_to = array()) {
// 액티비티 관리용 계정의 글 전송 차단
if ($mb['mb_id'] == ACTIVITYPUB_G5_USERNAME) return;
// 위치정보를 사용하는 경우 모듈 로드 // 위치정보를 사용하는 경우 모듈 로드
$location_ctx = array(); $location_ctx = array();
if (ACTIVITYPUB_ENABLED_GEOLOCATION) { if (ACTIVITYPUB_ENABLED_GEOLOCATION) {
@ -647,7 +671,10 @@ function activitypub_publish_content($content, $object_id, $mb, $_added_object =
$terms = activitypub_parse_content($content); $terms = activitypub_parse_content($content);
// 수신자/내용 생성 // 수신자/내용 생성
$to = array_merge(array(NAMESPACE_ACTIVITYSTREAMS_PUBLIC), $_added_to); $to = array_merge(activitypub_cast_to_array(NAMESPACE_ACTIVITYSTREAMS_PUBLIC), $_added_to);
$cc = array(); // 참조자
$tag = array(); // 태그
$endpoints = array();
$content = ""; $content = "";
foreach($terms as $term_ctx) { foreach($terms as $term_ctx) {
switch ($term_ctx['type']) { switch ($term_ctx['type']) {
@ -677,14 +704,24 @@ function activitypub_publish_content($content, $object_id, $mb, $_added_object =
$counter--; // 시도 횟수 차감 $counter--; // 시도 횟수 차감
} }
// WebFinger 정보 수신을 못한 경우 아무 작업도 하지 않음 // WebFinger 정보 수신을 못한 경우, 쪽지로 알리고 아무 작업도 하지 않음
if ($counter < 0) break; if (empty($webfigner_ctx['subject'])) {
activitypub_add_memo(ACTIVITYPUB_G5_USERNAME, $mb['mb_id'], "[발송실패] 수신자를 찾을 수 없음: @" . $account);
break;
}
// 받은 요청으로 처리 // 받은 요청으로 처리
$webfigner_links = $webfigner_ctx['links']; $webfigner_links = $webfigner_ctx['links'];
foreach($webfigner_links as $link) { foreach($webfigner_links as $link) {
if ($link['rel'] == "self" && $link['type'] == "application/activity+json") { if ($link['rel'] == "self" && $link['type'] == "application/activity+json") {
array_push($to, $link['href']); // 수신자에 반영 // 태그 목록에 추가
array_push($tag, array(
"type" => "Mention",
"href" => $link['href'],
"name" => '@' . $account
));
array_push($cc, $link['href']); // 참조자 목록에 추가
array_push($endpoints, $link['href']); // 글을 전송할 엔드포인트(URL)에 반영
} }
} }
} }
@ -698,48 +735,57 @@ function activitypub_publish_content($content, $object_id, $mb, $_added_object =
// 위치정보가 활성화되어 있으면 // 위치정보가 활성화되어 있으면
if (ACTIVITYPUB_ENABLED_GEOLOCATION) { if (ACTIVITYPUB_ENABLED_GEOLOCATION) {
$object = array_merge($_added_object, array( $_added_object = array_merge($_added_object, array(
"location" => $location_ctx "location" => $location_ctx
)); ));
} }
// 태그 추가
$_added_object = array_merge($_added_object, array(
"tag" => $tag
));
// 전문 생성 // 전문 생성
$object = activitypub_build_note($content, $object_id, $mb, $_added_object); $object = activitypub_build_note($content, $object_id, $mb, $_added_object);
// 외부로 보낼 전문 생성 // 외부로 보낼 전문 생성
$data = array( $data = array(
"@context" => NAMESPACE_ACTIVITYSTREAMS, "@context" => activitypub_cast_to_array(NAMESPACE_ACTIVITYSTREAMS),
"type" => "Create", "type" => "Create",
"id" => G5_BBS_URL . "/board.php?bo_table=" . ACTIVITYPUB_G5_BOARDNAME . "#Draft", "id" => G5_BBS_URL . "/board.php?bo_table=" . ACTIVITYPUB_G5_BOARDNAME . "#Draft",
"to" => $to, "to" => $to,
"cc" => $cc,
"actor" => $object['attributedTo'], "actor" => $object['attributedTo'],
"object" => $object "object" => $object
); );
// 초안(Draft) 작성 // 초안(Draft) 작성
$activity_wr_id = activitypub_update_activity("outbox", $data, $mb, "draft"); $activity_id = activitypub_update_activity("outbox", $data, $mb, "draft");
$data['id'] = G5_BBS_URL . "/board.php?bo_table=" . ACTIVITYPUB_G5_BOARDNAME . "&wr_id=" . $activity_wr_id; $data['object']['id'] = G5_BBS_URL . "/board.php?bo_table=" . ACTIVITYPUB_G5_BOARDNAME . "&wr_id=" . $activity_id;
$data['id'] = activitypub_get_url("activity", array("id" => $activity_id));
// 현재 시간 반영
$now_utc_tz = str_replace('+00:00', 'Z', gmdate('c'));
$data['published'] = $now_utc_tz;
$data['updated'] = $now_utc_tz;
// 보낼 전문을 인코딩 // 보낼 전문을 인코딩
$rawdata = activitypub_json_encode($data); $rawdata = activitypub_json_encode($data);
// 수신자 작업 // 수신자 엔드포인트(URL) 작업
foreach($to as $_to) { foreach($endpoints as $endpoint) {
// 공개 네임스페이스인 경우 건너뛰기
if ($_to == NAMESPACE_ACTIVITYSTREAMS_PUBLIC) continue;
// 수신자 정보 조회 // 수신자 정보 조회
$remote_user_ctx = activitypub_http_get($_to); $remote_account_ctx = activitypub_http_get($endpoint);
// inbox 주소 찾기 // inbox 주소 찾기
$remote_inbox_url = $remote_user_ctx['inbox']; $remote_inbox_url = $remote_account_ctx['inbox'];
if (empty($remote_inbox_url)) { if (empty($remote_inbox_url)) {
$remote_inbox_url = $remote_user_ctx['endpoints']['sharedInbox']; $remote_inbox_url = $remote_account_ctx['endpoints']['sharedInbox'];
} }
// inbox 주소가 없으면 건너뛰기 // inbox 주소가 없으면 건너뛰기
if (empty($remote_inbox_url)) { if (empty($remote_inbox_url)) {
activitypub_add_memo(ACTIVITYPUB_G5_USERNAME, $mb['mb_id'], "Could not find the inbox of " . $_to); activitypub_add_memo(ACTIVITYPUB_G5_USERNAME, $mb['mb_id'], "이 사용자 또는 서버는 메시지를 수신할 수 없는 상태임: " . $_to);
continue; continue;
} }
@ -754,7 +800,7 @@ function activitypub_publish_content($content, $object_id, $mb, $_added_object =
} }
// inbox로 데이터 전송 // inbox로 데이터 전송
$response = activitypub_http_post($remote_inbox_url, $rawdata, $mb, $access_token); activitypub_http_post($remote_inbox_url, $rawdata, $mb, $access_token);
} }
// 발행됨(Published)으로 상태 업데이트 // 발행됨(Published)으로 상태 업데이트
@ -769,12 +815,13 @@ function activitypub_parse_content($content) {
$pos = -1; $pos = -1;
$get_next_position = function ($pos) use ($content) { $get_next_position = function ($pos) use ($content) {
try { try {
return min(array_filter(array( $positions = array_filter(array(
strpos($content, '@', $pos + 1), strpos($content, '@', $pos + 1),
strpos($content, '#', $pos + 1), strpos($content, '#', $pos + 1),
strpos($content, 'http://', $pos + 1), strpos($content, 'http://', $pos + 1),
strpos($content, 'https://', $pos + 1) strpos($content, 'https://', $pos + 1)
), "is_numeric")); ), "is_numeric");
return (count($positions) > 0 ? min($positions) : false);
} catch (ValueError $e) { } catch (ValueError $e) {
return false; return false;
} }
@ -904,8 +951,8 @@ function activitypub_update_activity($inbox = "inbox", $data, $mb = array("mb_id
if ($status == "published") { if ($status == "published") {
// 저장 전 데이터 처리 // 저장 전 데이터 처리
$now_utc_tz = str_replace('+00:00', 'Z', gmdate('c')); $now_utc_tz = str_replace('+00:00', 'Z', gmdate('c'));
$data['published'] = $now_utc_tz; $data['published'] = empty($data['published']) ? $now_utc_tz : $data['published'];
$data['updated'] = $now_utc_tz; $data['updated'] = empty($data['updated']) ? $now_utc_tz : $data['updated'];
// 요청 전문은 파일로 저장 // 요청 전문은 파일로 저장
$raw_context = activitypub_json_encode($data); $raw_context = activitypub_json_encode($data);
@ -947,43 +994,30 @@ function activitypub_update_activity($inbox = "inbox", $data, $mb = array("mb_id
return $wr_id; return $wr_id;
} }
function activitypub_get_objects($mb, $inbox = "inbox") { function activitypub_get_activity_by_id($activity_id) {
global $g5; global $g5;
$items = array(); // 액티비티 전문
$activity_ctx = array();
// 정보 불러오기 // 해당 액티비티 찾고 없으면 빈 정보 반환
$sql = ""; $write_table = $g5['write_prefix'] . ACTIVITYPUB_G5_BOARDNAME;
if(!$mb['mb_id']) { $wr = get_write($write_table, $activity_id);
$sql = "select wr_id from " . ACTIVITYPUB_G5_TABLENAME . " if (empty($wr['wr_id'])) return $activity_ctx;
where ca_name = '$inbox'
and DATE(wr_datetime) BETWEEN CURDATE() - INTERVAL " . ACTIVITYPUB_G5_OUTDATED_DAYS . " DAY AND CURDATE() // 액티비티 조회
"; $sql = "select * from {$g5['board_file_table']}
} else { where bo_table = '" . ACTIVITYPUB_G5_BOARDNAME . "' and wr_id = '{$wr['wr_id']}' and bf_content = 'application/activity+json'";
$sql = "select wr_id from " . ACTIVITYPUB_G5_TABLENAME . "
where ca_name = '$inbox'
and FIND_IN_SET('$mb_id', wr_7) > 0
and DATE(wr_datetime) BETWEEN CURDATE() - INTERVAL " . ACTIVITYPUB_G5_OUTDATED_DAYS . " DAY AND CURDATE()
";
}
$result = sql_query($sql); $result = sql_query($sql);
// 정보 조회 후 처리
while ($row = sql_fetch_array($result)) { while ($row = sql_fetch_array($result)) {
$sql2 = "select * from {$g5['board_file_table']} $filename = $row['bf_file'];
where bo_table = '" . ACTIVITYPUB_G5_BOARDNAME . "' and wr_id = '{$row['wr_id']}' and bf_content = 'application/activity+json'";
$result2 = sql_query($sql2);
while ($row2 = sql_fetch_array($result2)) {
$filename = $row2['bf_file'];
$filepath = G5_DATA_PATH . "/file/" . ACTIVITYPUB_G5_BOARDNAME . "/" . $filename; $filepath = G5_DATA_PATH . "/file/" . ACTIVITYPUB_G5_BOARDNAME . "/" . $filename;
if (file_exists($filepath)) { if (file_exists($filepath)) {
array_push($items, activitypub_json_decode(file_get_contents($filepath))['object']); $activity_ctx = activitypub_json_decode(@file_get_contents($filepath))['object'];
}
} }
} }
// 전문 만들기 return $activity_ctx;
return activitypub_build_collection($items);
} }
// Object type: Note // Object type: Note
@ -1133,6 +1167,17 @@ class _GNUBOARD_ActivityPub {
return activitypub_json_encode($context); return activitypub_json_encode($context);
} }
public static function activity() {
// HTTP 요청 유형에 따라 작업
switch ($_SERVER['REQUEST_METHOD']) {
case "POST":
return activitypub_json_encode(array("message" => "Disallowed method"));
case "GET":
return activitypub_get_activity_by_id($_GET['id']);
}
}
public static function inbox() { public static function inbox() {
// HTTP 요청 유형에 따라 작업 // HTTP 요청 유형에 따라 작업
switch ($_SERVER['REQUEST_METHOD']) { switch ($_SERVER['REQUEST_METHOD']) {
@ -1376,8 +1421,7 @@ class _GNUBOARD_ActivityPub {
return activitypub_json_encode(array("message" => "Success")); return activitypub_json_encode(array("message" => "Success"));
case "GET": case "GET":
$mb = get_member($_GET['mb_id']); return activitypub_json_encode(array("message" => "Disallowed method"));
return activitypub_json_encode(activitypub_get_objects($mb, "inbox"));
default: default:
return activitypub_json_encode(array("message" => "Not supported method")); return activitypub_json_encode(array("message" => "Not supported method"));
@ -1419,56 +1463,6 @@ class _GNUBOARD_ActivityPub {
$items = array(); // 항목을 담을 배열 $items = array(); // 항목을 담을 배열
/* // TODO: Remove (Security Reason)
// 게시판인 경우
if (array_key_exists("bo_table", $_GET)) {
$bo = get_board_db($_GET['bo_table'], true);
if (!empty($bo['bo_table'])) {
switch($bo['bo_table']) {
case ACTIVITYPUB_G5_BOARDNAME:
return self::inbox(); // 액티비티를 저장하는 테이블인 경우 inbox와 동일하게 취급
default:
// 조회할 페이지 수 불러오기
$page = intval($_GET['page']);
if ($page < 1) {
$page = 1;
}
// 페이지 당 표시할 게시물 수 불러오기
$page_rows = 0;
if (!empty($bo['bo_mobile_page_rows'])) {
$page_rows = intval($bo['bo_mobile_page_rows']);
} else if (!empty($bo['bo_page_rows'])) {
$page_rows = intval($bo['bo_page_rows']);
}
// 페이지 당 표시할 게시물 수가 1보다 작으면 기본값(15)로 설정
if ($pages_rows < 1) {
$page_rows = 15;
}
// SQL 작성
$write_table = $g5['write_prefix'] . $bo['bo_table'];
$offset = ($page - 1) * $page_rows;
$sql = "select wr_id, mb_id, wr_content, wr_datetime from {$write_table} where FIND_IN_SET('secret', wr_option) = 0 order by wr_datetime desc limit {$offset}, {$page_rows} ";
// SQL 실행
$result = sql_query($sql);
while ($row = sql_fetch_array($result)) {
$object_id = G5_BBS_URL . "/board.php?bo_table={$bo['bo_table']}&wr_id={$row['wr_id']}";
$mb = get_member($row['mb_id']);
$content = $row['wr_content'];
array_push($items, activitypub_build_note($content, $object_id, $mb));
}
}
}
}
*/
// 최근 활동에서 추출 // 최근 활동에서 추출
$sql = "select * from " . $g5['board_new_table']; $sql = "select * from " . $g5['board_new_table'];
$result = sql_query($sql); $result = sql_query($sql);
@ -1493,15 +1487,15 @@ class _GNUBOARD_ActivityPub {
switch ($grant_type) { switch ($grant_type) {
case "authorization_code": case "authorization_code":
return activitypub_json_encode(array("message" => "Sorry. This grant type does not supported yet")); return activitypub_json_encode(array("message" => "Not implemented"));
break; break;
case "password": case "password":
return activitypub_json_encode(array("message" => "Sorry. This grant type does not supported yet")); return activitypub_json_encode(array("message" => "Not implemented"));
break; break;
case "client_credentials": case "client_credentials":
return activitypub_json_encode(array("message" => "Sorry. This grant type does not supported yet")); return activitypub_json_encode(array("message" => "Not implemented"));
break; break;
} }
} }
@ -1518,13 +1512,13 @@ function _activitypub_memo_form_update_after($member_list, $str_nick_list, $redi
// 'apstreams' 계정이 있는지 확인 // 'apstreams' 계정이 있는지 확인
if (!in_array(ACTIVITYPUB_G5_USERNAME, $member_list['id'])) return; if (!in_array(ACTIVITYPUB_G5_USERNAME, $member_list['id'])) return;
// 현재 로그인되어 있으면, 로그인된 계정의 정보를 따름 // 글을 생성한 회원 정보
$mb = (isset($member['mb_id']) ? $member : get_member(ACTIVITYPUB_G5_USERNAME)); $mb = (isset($member['mb_id']) ? $member : get_member(ACTIVITYPUB_G5_USERNAME));
// 글 전송하기 // 글 전송하기
if (!empty($mb['mb_id'])) { if (!empty($mb['mb_id'])) {
// 글 전송하기 // 글 전송하기
$data = activitypub_publish_content( activitypub_publish_content(
$me_memo, $me_memo,
activitypub_get_url("user", array("mb_id" => $mb['mb_id'])), activitypub_get_url("user", array("mb_id" => $mb['mb_id'])),
$mb $mb
@ -1535,12 +1529,12 @@ function _activitypub_memo_form_update_after($member_list, $str_nick_list, $redi
function _activitypub_write_update_after($board, $wr_id, $w, $qstr, $redirect_url) { function _activitypub_write_update_after($board, $wr_id, $w, $qstr, $redirect_url) {
global $g5, $member; global $g5, $member;
// 본문 가져오기 // 본문 가져오기 (본문이 없는 경우 중단)
$sql = "select wr_id, wr_content from {$g5['write_prefix']}{$board['bo_table']} where wr_id = '{$wr_id}'"; $sql = "select wr_id, wr_content from {$g5['write_prefix']}{$board['bo_table']} where wr_id = '{$wr_id}'";
$row = sql_fetch($sql); $row = sql_fetch($sql);
if (empty($row['wr_id'])) return; if (empty($row['wr_id'])) return;
// 현재 로그인되어 있으면, 로그인된 계정의 정보를 따름 // 글을 생성한 회원 정보
$mb = (isset($member['mb_id']) ? $member : get_member(ACTIVITYPUB_G5_USERNAME)); $mb = (isset($member['mb_id']) ? $member : get_member(ACTIVITYPUB_G5_USERNAME));
// 추가할 오브젝트 속성 // 추가할 오브젝트 속성
@ -1554,7 +1548,7 @@ function _activitypub_write_update_after($board, $wr_id, $w, $qstr, $redirect_ur
// 글 전송하기 // 글 전송하기
if (!empty($mb['mb_id'])) { if (!empty($mb['mb_id'])) {
$data = activitypub_publish_content( activitypub_publish_content(
$row['wr_content'], $row['wr_content'],
G5_BBS_URL . "/board.php?bo_table={$board['bo_table']}&wr_id={$row['wr_id']}", G5_BBS_URL . "/board.php?bo_table={$board['bo_table']}&wr_id={$row['wr_id']}",
$mb, $mb,
@ -1566,12 +1560,12 @@ function _activitypub_write_update_after($board, $wr_id, $w, $qstr, $redirect_ur
function _activitypub_comment_update_after($board, $wr_id, $w, $qstr, $redirect_url, $comment_id, $reply_array) { function _activitypub_comment_update_after($board, $wr_id, $w, $qstr, $redirect_url, $comment_id, $reply_array) {
global $g5, $member; global $g5, $member;
// 본문(댓글) 가져오기 // 본문(댓글) 가져오기 (본문이 없는 경우 중단)
$sql = "select wr_id, wr_content from {$g5['write_prefix']}{$board['bo_table']} where wr_id = '{$wr_id}'"; $sql = "select wr_id, wr_content from {$g5['write_prefix']}{$board['bo_table']} where wr_id = '{$wr_id}'";
$row = sql_fetch($sql); $row = sql_fetch($sql);
if (empty($row['wr_id'])) return; if (empty($row['wr_id'])) return;
// 현재 로그인되어 있으면, 로그인된 계정의 정보를 따름 // 글을 생성한 회원 정보
$mb = (isset($member['mb_id']) ? $member : get_member(ACTIVITYPUB_G5_USERNAME)); $mb = (isset($member['mb_id']) ? $member : get_member(ACTIVITYPUB_G5_USERNAME));
// 추가할 오브젝트 속성 // 추가할 오브젝트 속성
@ -1587,7 +1581,7 @@ function _activitypub_comment_update_after($board, $wr_id, $w, $qstr, $redirect_
// 글 전송하기 // 글 전송하기
if (!empty($mb['mb_id'])) { if (!empty($mb['mb_id'])) {
$data = activitypub_publish_content( activitypub_publish_content(
$row['wr_content'], $row['wr_content'],
G5_BBS_URL . "/board.php?bo_table={$board['bo_table']}&wr_id={$row['wr_parent']}&c_id=" . $comment_id, G5_BBS_URL . "/board.php?bo_table={$board['bo_table']}&wr_id={$row['wr_parent']}&c_id=" . $comment_id,
$mb, $mb,
@ -1633,6 +1627,12 @@ switch ($route) {
_GNUBOARD_ActivityPub::close(); _GNUBOARD_ActivityPub::close();
break; break;
case "activitypub.activity":
_GNUBOARD_ActivityPub::open();
echo _GNUBOARD_ActivityPub::activity();
_GNUBOARD_ActivityPub::close();
break;
case "activitypub.inbox": case "activitypub.inbox":
_GNUBOARD_ActivityPub::open(); _GNUBOARD_ActivityPub::open();
echo _GNUBOARD_ActivityPub::inbox(); echo _GNUBOARD_ActivityPub::inbox();
@ -1669,7 +1669,7 @@ switch ($route) {
_GNUBOARD_ActivityPub::close(); _GNUBOARD_ActivityPub::close();
break; break;
case "oauth2.authorize": // TODO case "oauth2.authorize": // Not implemented
_GNUBOARD_ActivityPub::open(); _GNUBOARD_ActivityPub::open();
echo _GNUBOARD_ActivityPub::authorize(); echo _GNUBOARD_ActivityPub::authorize();
_GNUBOARD_ActivityPub::close(); _GNUBOARD_ActivityPub::close();