Update activitiypub.extend.php
This commit is contained in:
parent
50e11ad01c
commit
f8a8f51b21
|
@ -116,6 +116,16 @@ function activitypub_add_memo($mb_id, $recv_mb_id, $me_memo) {
|
||||||
return ($me_id == sql_insert_id());
|
return ($me_id == sql_insert_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function activitypub_set_liked($good, $bo_table, $wr_id) {
|
||||||
|
global $g5;
|
||||||
|
|
||||||
|
// 추천(찬성), 비추천(반대) 카운트 증가
|
||||||
|
sql_query(" update {$g5['write_prefix']}{$bo_table} set wr_{$good} = wr_{$good} + 1 where wr_id = '{$wr_id}' ");
|
||||||
|
|
||||||
|
// 내역 생성
|
||||||
|
sql_query(" insert {$g5['board_good_table']} set bo_table = '{$bo_table}', wr_id = '{$wr_id}', mb_id = '" . ACTIVITYPUB_G5_USERNAME . "', bg_flag = '{$good}', bg_datetime = '" . G5_TIME_YMDHIS . "' ");
|
||||||
|
}
|
||||||
|
|
||||||
class _GNUBOARD_ActivityPub {
|
class _GNUBOARD_ActivityPub {
|
||||||
public static function open() {
|
public static function open() {
|
||||||
header("Content-Type: application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"");
|
header("Content-Type: application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"");
|
||||||
|
@ -166,6 +176,8 @@ class _GNUBOARD_ActivityPub {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function inbox() {
|
public static function inbox() {
|
||||||
|
global $g5;
|
||||||
|
|
||||||
// 개인에게 보낸 메시지는 쪽지에 저장
|
// 개인에게 보낸 메시지는 쪽지에 저장
|
||||||
// 공개(Public) 설정한 메시지는 ACTIVITYPUB_G5_TABLENAME에 저장
|
// 공개(Public) 설정한 메시지는 ACTIVITYPUB_G5_TABLENAME에 저장
|
||||||
// 게시물이 특정된 경우 댓글로 저장 (그누 전용)
|
// 게시물이 특정된 경우 댓글로 저장 (그누 전용)
|
||||||
|
@ -180,8 +192,7 @@ class _GNUBOARD_ActivityPub {
|
||||||
return activitypub_json_encode(array("message" => "This is not an ActivityStreams request"));
|
return activitypub_json_encode(array("message" => "This is not an ActivityStreams request"));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($data['type']) {
|
if (!empty($data['type'])) {
|
||||||
case "Create":
|
|
||||||
// 멤버정보 처리
|
// 멤버정보 처리
|
||||||
$mb_id = activitypub_parse_url($data['actor'])['query']['mb_id'];
|
$mb_id = activitypub_parse_url($data['actor'])['query']['mb_id'];
|
||||||
if (empty($mb_id)) {
|
if (empty($mb_id)) {
|
||||||
|
@ -195,6 +206,9 @@ class _GNUBOARD_ActivityPub {
|
||||||
// 원글 정보 확인
|
// 원글 정보 확인
|
||||||
$object = $data['object'];
|
$object = $data['object'];
|
||||||
|
|
||||||
|
// 타입 별 해야될 일 지정
|
||||||
|
switch ($data['type']) {
|
||||||
|
case "Create":
|
||||||
// 내용 처리
|
// 내용 처리
|
||||||
if (empty($object['content'])) {
|
if (empty($object['content'])) {
|
||||||
return activitypub_json_encode(array("message" => "Content is empty"));
|
return activitypub_json_encode(array("message" => "Content is empty"));
|
||||||
|
@ -251,25 +265,87 @@ class _GNUBOARD_ActivityPub {
|
||||||
sql_query($sql);
|
sql_query($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 원글이 삭제된 경우 오류를 기록
|
// 원글이 삭제된 경우
|
||||||
else {
|
else {
|
||||||
activitypub_add_memo(
|
return activitypub_json_encode(array("message" => "Could not find the original message"));
|
||||||
ACTIVITYPUB_G5_USERNAME,
|
|
||||||
ACTIVITYPUB_G5_USERNAME,
|
|
||||||
(
|
|
||||||
"[ERROR: Could not find the original message]\r\n\r\n" .
|
|
||||||
"From: " . $data['actor'] . "\r\n" .
|
|
||||||
"To: " . implode(", ", $to) . "\r\n" .
|
|
||||||
$content .
|
|
||||||
"\r\n\r\n" .
|
|
||||||
G5_TIME_YMDHIS
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Like":
|
||||||
|
// '좋아요'는 원글 표시가 문자열로 되어 있음
|
||||||
|
if (is_string($object)) {
|
||||||
|
$query = activitypub_parse_url($object);
|
||||||
|
|
||||||
|
// 원글을 특정한 경우
|
||||||
|
if (!empty($query['bo_table']) && !empty($query['wr_id'])) {
|
||||||
|
$wr_id = $query['wr_id'];
|
||||||
|
$write_table = G5_TABLE_PREFIX . $query['bo_table'];
|
||||||
|
$wr = get_write($write_table, $wr_id);
|
||||||
|
|
||||||
|
// 원글이 존재하는 경우
|
||||||
|
if (!empty($wr['wr_id'])) {
|
||||||
|
activitypub_set_liked("good", $query['bo_table'], $wr['wr_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 원글이 삭제된 경우
|
||||||
|
else {
|
||||||
|
return activitypub_json_encode(array("message" => "Could not find the original message"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 받을사람 처리
|
// 특정하지 않은 경우
|
||||||
|
else {
|
||||||
|
return activitypub_json_encode(array("message" => "Please specify the original message"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 문자열이 아닌 경우
|
||||||
|
else {
|
||||||
|
return activitypub_json_encode(array("message" => "'Object' must be set type to 'String' to request 'Like' type"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Dislike":
|
||||||
|
// '싫어요'는 원글 표시가 문자열로 되어 있음
|
||||||
|
if (is_string($object)) {
|
||||||
|
$query = activitypub_parse_url($object);
|
||||||
|
|
||||||
|
// 원글을 특정한 경우
|
||||||
|
if (!empty($query['bo_table']) && !empty($query['wr_id'])) {
|
||||||
|
$wr_id = $query['wr_id'];
|
||||||
|
$write_table = G5_TABLE_PREFIX . $query['bo_table'];
|
||||||
|
$wr = get_write($write_table, $wr_id);
|
||||||
|
|
||||||
|
// 원글이 존재하는 경우
|
||||||
|
if (!empty($wr['wr_id'])) {
|
||||||
|
activitypub_set_liked("nogood", $query['bo_table'], $wr['wr_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 원글이 삭제된 경우
|
||||||
|
else {
|
||||||
|
return activitypub_json_encode(array("message" => "Could not find the original message"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 특정하지 않은 경우
|
||||||
|
else {
|
||||||
|
return activitypub_json_encode(array("message" => "Please specify the original message"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 문자열이 아닌 경우
|
||||||
|
else {
|
||||||
|
return activitypub_json_encode(array("message" => "'Object' must be set type to 'String' to request 'Like' type"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return activitypub_json_encode(array("message" => "This is not implemented type"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 받을사람(수신자) 처리
|
||||||
foreach($to as $_to) {
|
foreach($to as $_to) {
|
||||||
$query = activitypub_parse_url($_to)['query'];
|
$query = activitypub_parse_url($_to)['query'];
|
||||||
|
|
||||||
|
@ -282,8 +358,10 @@ class _GNUBOARD_ActivityPub {
|
||||||
$wr_reply = '';
|
$wr_reply = '';
|
||||||
$ca_name = 'ActivityStreams';
|
$ca_name = 'ActivityStreams';
|
||||||
$wr_subject = mb_substr($content, 0, 45);
|
$wr_subject = mb_substr($content, 0, 45);
|
||||||
|
$wr_seo_title = mb_substr($content, 0, 45);
|
||||||
$wr_content = $content;
|
$wr_content = $content;
|
||||||
$wr_link1 = $data['actor'];
|
$wr_link1 = $data['actor'];
|
||||||
|
$wr_link2 = '';
|
||||||
$wr_homepage = $data['actor'];
|
$wr_homepage = $data['actor'];
|
||||||
|
|
||||||
$sql = "
|
$sql = "
|
||||||
|
@ -297,7 +375,7 @@ class _GNUBOARD_ActivityPub {
|
||||||
wr_content = '$wr_content',
|
wr_content = '$wr_content',
|
||||||
wr_seo_title = '$wr_seo_title',
|
wr_seo_title = '$wr_seo_title',
|
||||||
wr_link1 = '$wr_link1',
|
wr_link1 = '$wr_link1',
|
||||||
wr_link2 = '',
|
wr_link2 = '$wr_link2',
|
||||||
wr_link1_hit = 0,
|
wr_link1_hit = 0,
|
||||||
wr_link2_hit = 0,
|
wr_link2_hit = 0,
|
||||||
wr_hit = 0,
|
wr_hit = 0,
|
||||||
|
@ -350,10 +428,6 @@ class _GNUBOARD_ActivityPub {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return activitypub_json_encode(array("message" => "This is not implemented type"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,19 +436,25 @@ class _GNUBOARD_ActivityPub {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function followers() {
|
public static function followers() {
|
||||||
$mb = get_member($_GET['mb_id']);
|
$params = array(
|
||||||
|
"mb_id" => $_GET['mb_id']
|
||||||
|
);
|
||||||
|
|
||||||
|
$mb = get_member($params['mb_id']);
|
||||||
return activitypub_json_encode(array("followers" => activitypub_get_followers($mb)));
|
return activitypub_json_encode(array("followers" => activitypub_get_followers($mb)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function following() {
|
public static function following() {
|
||||||
|
$params = array(
|
||||||
|
"mb_id" => $_GET['mb_id']
|
||||||
|
);
|
||||||
|
|
||||||
$mb = get_member($_GET['mb_id']);
|
$mb = get_member($_GET['mb_id']);
|
||||||
return activitypub_json_encode(array("following" => activitypub_get_following($mb)));
|
return activitypub_json_encode(array("following" => activitypub_get_following($mb)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function liked() {
|
public static function liked() {
|
||||||
return array(
|
return self::inbox();
|
||||||
"message" => "Not implemented"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function close() {
|
public static function close() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user