Update activitypub.extend.php
This commit is contained in:
parent
f6317997f1
commit
20198c98dd
|
@ -29,14 +29,14 @@ define("ACTIVITYPUB_G5_NEW_DAYS", (empty($config['cf_new_del']) ? 30 : $config['
|
||||||
define("ACTIVITYPUB_ACCESS_TOKEN", "server1.example.org=xxuPtHDkMgYQfcy9; server2.example.org=PC6ujkjQXhL6lUtS;");
|
define("ACTIVITYPUB_ACCESS_TOKEN", "server1.example.org=xxuPtHDkMgYQfcy9; server2.example.org=PC6ujkjQXhL6lUtS;");
|
||||||
define("NAMESPACE_ACTIVITYSTREAMS", "https://www.w3.org/ns/activitystreams");
|
define("NAMESPACE_ACTIVITYSTREAMS", "https://www.w3.org/ns/activitystreams");
|
||||||
define("NAMESPACE_ACTIVITYSTREAMS_PUBLIC", "https://www.w3.org/ns/activitystreams#Public");
|
define("NAMESPACE_ACTIVITYSTREAMS_PUBLIC", "https://www.w3.org/ns/activitystreams#Public");
|
||||||
define("ACTIVITYPUB_ENABLED_GEOLOCATION", false); // 위치정보 활성화 (https://lite.ip2location.com/)
|
define("ACTIVITYPUB_ENABLED_GEOLOCATION", true); // 위치정보 활성화 (https://lite.ip2location.com/)
|
||||||
define("NAVERCLOUD_ENABLED_GEOLOCATION", false); // 국내용 위치정보 활성화 (https://www.ncloud.com/product/applicationService/geoLocation)
|
define("NAVERCLOUD_ENABLED_GEOLOCATION", true); // 국내용 위치정보 활성화 (https://www.ncloud.com/product/applicationService/geoLocation)
|
||||||
define("NAVERCLOUD_API_ACCESS_KEY", ""); // 네이버 클라우드 API 키 설정
|
define("NAVERCLOUD_API_ACCESS_KEY", "KmUjQNeej5q14ZYrhFG9"); // 네이버 클라우드 API 키 설정
|
||||||
define("NAVERCLOUD_API_SECRET_KEY", ""); // 네이버 클라우드 API 키 설정
|
define("NAVERCLOUD_API_SECRET_KEY", "1GpX5QcWUfa2uy7kJFvkRhU9T4tDAzN7COe4vgqD"); // 네이버 클라우드 API 키 설정
|
||||||
define("OPENWEATHERMAP_ENABLED", false); // 날씨정보 활성화
|
define("OPENWEATHERMAP_ENABLED", true); // 날씨정보 활성화
|
||||||
define("OPENWEATHERMAP_API_KEY", ""); // 날씨정보 키 설정 (https://openweathermap.org/api/one-call-3)
|
define("OPENWEATHERMAP_API_KEY", "7506066cfc291e1acfa7119b1ca0bb62"); // 날씨정보 키 설정 (https://openweathermap.org/api/one-call-3)
|
||||||
define("KOREAEXIM_ENABLED", false); // 한국수출입은행 현재환율 API
|
define("KOREAEXIM_ENABLED", true); // 한국수출입은행 현재환율 API
|
||||||
define("KOREAEXIM_API_KEY", ""); // 한국수출입은행 현재환율 API 키
|
define("KOREAEXIM_API_KEY", "Gu4EaPsTjet1u7l6kkQGZs5GGrDZYZBD"); // 한국수출입은행 현재환율 API 키
|
||||||
|
|
||||||
$activitypub_loaded_libraries = array();
|
$activitypub_loaded_libraries = array();
|
||||||
|
|
||||||
|
@ -460,12 +460,12 @@ function activitypub_publish_content($content, $id, $mb, $_added_object = array(
|
||||||
$account_terms = explode('@', $account);
|
$account_terms = explode('@', $account);
|
||||||
$account_ctx = array("username" => $account_terms[0], "host" => $account_terms[1]);
|
$account_ctx = array("username" => $account_terms[0], "host" => $account_terms[1]);
|
||||||
if (!empty($account_ctx['host'])) {
|
if (!empty($account_ctx['host'])) {
|
||||||
// 그누5 전용 WebFinger에 우선적으로 연결
|
// 공통 WebFinger에 연결
|
||||||
$webfigner_ctx = activitypub_http_get("http://" . $account_ctx['host'] . "/?route=webfinger&resource=acct:" . $account);
|
|
||||||
|
|
||||||
// 실패시, 공통 WebFinger에 연결
|
|
||||||
if ($webfigner_ctx['subject'] != ("acct:" . $account)) {
|
|
||||||
$webfigner_ctx = activitypub_http_get("http://" . $account_ctx['host'] . "/.well-known/webfinger?resource=acct:" . $account);
|
$webfigner_ctx = activitypub_http_get("http://" . $account_ctx['host'] . "/.well-known/webfinger?resource=acct:" . $account);
|
||||||
|
|
||||||
|
// 실패시, 그누5 전용 WebFinger에 연결
|
||||||
|
if ($webfigner_ctx['subject'] != ("acct:" . $account)) {
|
||||||
|
$webfigner_ctx = activitypub_http_get("http://" . $account_ctx['host'] . "/?route=webfinger&resource=acct:" . $account);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 한번 더 확인
|
// 한번 더 확인
|
||||||
|
@ -517,6 +517,10 @@ function activitypub_publish_content($content, $id, $mb, $_added_object = array(
|
||||||
"object" => $object
|
"object" => $object
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 초안(Draft) 작성
|
||||||
|
$activity_wr_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;
|
||||||
|
|
||||||
// 보낼 전문을 인코딩
|
// 보낼 전문을 인코딩
|
||||||
$rawdata = activitypub_json_encode($data);
|
$rawdata = activitypub_json_encode($data);
|
||||||
|
|
||||||
|
@ -554,6 +558,9 @@ function activitypub_publish_content($content, $id, $mb, $_added_object = array(
|
||||||
$response = activitypub_http_post($remote_inbox_url, $rawdata, $access_token);
|
$response = activitypub_http_post($remote_inbox_url, $rawdata, $access_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 발행됨(Published)으로 상태 업데이트
|
||||||
|
activitypub_update_activity("outbox", $data, $mb, "published", $activity_wr_id);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,12 +610,14 @@ function activitypub_parse_content($content) {
|
||||||
return $entities;
|
return $entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
function activitypub_add_activity($inbox = "inbox", $data, $mb = array("mb_id" => ACTIVITYPUB_G5_USERNAME), $status = "draft") {
|
function activitypub_update_activity($inbox = "inbox", $data, $mb = array("mb_id" => ACTIVITYPUB_G5_USERNAME), $status = "draft", $wr_id = 0) {
|
||||||
global $g5;
|
global $g5;
|
||||||
|
|
||||||
// 반환할 글 번호
|
// 게시판 테이블이름
|
||||||
$wr_id = 0;
|
$write_table = ACTIVITYPUB_G5_TABLENAME;
|
||||||
|
|
||||||
|
// Activity 초안(Draft)이 없는 경우
|
||||||
|
if (!($wr_id > 0)) {
|
||||||
// 기본 파라미터
|
// 기본 파라미터
|
||||||
$to = $data['to'];
|
$to = $data['to'];
|
||||||
$object = $data['object'];
|
$object = $data['object'];
|
||||||
|
@ -620,7 +629,6 @@ function activitypub_add_activity($inbox = "inbox", $data, $mb = array("mb_id" =
|
||||||
$wr_option = 'secret';
|
$wr_option = 'secret';
|
||||||
|
|
||||||
// 게시글로 등록
|
// 게시글로 등록
|
||||||
$write_table = ACTIVITYPUB_G5_TABLENAME;
|
|
||||||
$wr_num = get_next_num($write_table);
|
$wr_num = get_next_num($write_table);
|
||||||
$wr_reply = '';
|
$wr_reply = '';
|
||||||
$ca_name = $inbox; // Inbox/Outbox
|
$ca_name = $inbox; // Inbox/Outbox
|
||||||
|
@ -691,18 +699,18 @@ function activitypub_add_activity($inbox = "inbox", $data, $mb = array("mb_id" =
|
||||||
";
|
";
|
||||||
sql_query($sql);
|
sql_query($sql);
|
||||||
$wr_id = sql_insert_id();
|
$wr_id = sql_insert_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activity를 발행됨(published)으로 상태를 업데이트하는 경우
|
||||||
|
if ($status == "published") {
|
||||||
// 저장 전 데이터 처리
|
// 저장 전 데이터 처리
|
||||||
$now_utc_tz = str_replace('+00:00', 'Z', gmdate('c'));
|
$now_utc_tz = str_replace('+00:00', 'Z', gmdate('c'));
|
||||||
if ($status == "published") {
|
|
||||||
$data['published'] = $now_utc_tz;
|
$data['published'] = $now_utc_tz;
|
||||||
}
|
|
||||||
$data['updated'] = $now_utc_tz;
|
$data['updated'] = $now_utc_tz;
|
||||||
|
|
||||||
// 요청 전문은 파일로 저장
|
// 요청 전문은 파일로 저장
|
||||||
$raw_context = activitypub_json_encode($data);
|
$raw_context = activitypub_json_encode($data);
|
||||||
$time_ms = floor(microtime(true) * 1000);
|
$filename = md5($raw_context) . ".json";
|
||||||
$filename = md5($raw_context . $time_ms) . ".json";
|
|
||||||
$filepath = G5_DATA_PATH . "/file/" . ACTIVITYPUB_G5_BOARDNAME . "/" . $filename;
|
$filepath = G5_DATA_PATH . "/file/" . ACTIVITYPUB_G5_BOARDNAME . "/" . $filename;
|
||||||
$result = file_put_contents($filepath, $raw_context);
|
$result = file_put_contents($filepath, $raw_context);
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
|
@ -731,6 +739,8 @@ function activitypub_add_activity($inbox = "inbox", $data, $mb = array("mb_id" =
|
||||||
$sql = "update $write_table set wr_file = 1 where wr_id = '{$wr_id}'";
|
$sql = "update $write_table set wr_file = 1 where wr_id = '{$wr_id}'";
|
||||||
sql_query($sql);
|
sql_query($sql);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $wr_id;
|
return $wr_id;
|
||||||
}
|
}
|
||||||
|
@ -937,7 +947,7 @@ class _GNUBOARD_ActivityPub {
|
||||||
$object['content'] = "[NO CONTENT]";
|
$object['content'] = "[NO CONTENT]";
|
||||||
|
|
||||||
// 수신된 내용 등록
|
// 수신된 내용 등록
|
||||||
$activity_wr_id = activitypub_add_activity("inbox", $data, $mb, "published");
|
$activity_wr_id = activitypub_update_activity("inbox", $data, $mb, "published");
|
||||||
|
|
||||||
// 컨텐츠 설정
|
// 컨텐츠 설정
|
||||||
$bo = get_board_db(ACTIVITYPUB_G5_BOARDNAME, true);
|
$bo = get_board_db(ACTIVITYPUB_G5_BOARDNAME, true);
|
||||||
|
@ -1189,7 +1199,6 @@ function _activitypub_memo_form_update_after($member_list, $str_nick_list, $redi
|
||||||
activitypub_get_url("user", array("mb_id" => $member['mb_id'])),
|
activitypub_get_url("user", array("mb_id" => $member['mb_id'])),
|
||||||
$member
|
$member
|
||||||
);
|
);
|
||||||
activitypub_add_activity("outbox", $data, $member, "published");
|
|
||||||
} else {
|
} else {
|
||||||
// 글 전송하기
|
// 글 전송하기
|
||||||
$mb = get_member(ACTIVITYPUB_G5_USERNAME);
|
$mb = get_member(ACTIVITYPUB_G5_USERNAME);
|
||||||
|
@ -1198,7 +1207,6 @@ function _activitypub_memo_form_update_after($member_list, $str_nick_list, $redi
|
||||||
activitypub_get_url("user", array("mb_id" => $mb['mb_id'])),
|
activitypub_get_url("user", array("mb_id" => $mb['mb_id'])),
|
||||||
$mb
|
$mb
|
||||||
);
|
);
|
||||||
activitypub_add_activity("outbox", $data, $mb, "published");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1218,7 +1226,6 @@ function _activitypub_write_update_after($board, $wr_id, $w, $qstr, $redirect_ur
|
||||||
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']}",
|
||||||
$member
|
$member
|
||||||
);
|
);
|
||||||
activitypub_add_activity("outbox", $data, $member, "published");
|
|
||||||
} else {
|
} else {
|
||||||
// 글 전송하기
|
// 글 전송하기
|
||||||
$mb = get_member(ACTIVITYPUB_G5_USERNAME);
|
$mb = get_member(ACTIVITYPUB_G5_USERNAME);
|
||||||
|
@ -1227,7 +1234,6 @@ function _activitypub_write_update_after($board, $wr_id, $w, $qstr, $redirect_ur
|
||||||
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
|
||||||
);
|
);
|
||||||
activitypub_add_activity("outbox", $data, $mb, "published");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1248,7 +1254,6 @@ function _activitypub_comment_update_after($board, $wr_id, $w, $qstr, $redirect_
|
||||||
$member,
|
$member,
|
||||||
array("inReplyTo" => G5_BBS_URL . "/board.php?bo_table={$board['bo_table']}&wr_id={$row['wr_id']}")
|
array("inReplyTo" => G5_BBS_URL . "/board.php?bo_table={$board['bo_table']}&wr_id={$row['wr_id']}")
|
||||||
);
|
);
|
||||||
activitypub_add_activity("outbox", $data, $member);
|
|
||||||
} else {
|
} else {
|
||||||
// 글 전송하기
|
// 글 전송하기
|
||||||
$mb = get_member(ACTIVITYPUB_G5_USERNAME);
|
$mb = get_member(ACTIVITYPUB_G5_USERNAME);
|
||||||
|
@ -1258,7 +1263,6 @@ function _activitypub_comment_update_after($board, $wr_id, $w, $qstr, $redirect_
|
||||||
$mb,
|
$mb,
|
||||||
array("inReplyTo" => G5_BBS_URL . "/board.php?bo_table={$board['bo_table']}&wr_id={$row['wr_id']}")
|
array("inReplyTo" => G5_BBS_URL . "/board.php?bo_table={$board['bo_table']}&wr_id={$row['wr_id']}")
|
||||||
);
|
);
|
||||||
activitypub_add_activity("outbox", $data, $mb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user