Skip to content
On this page

Content Handler Plugin Development

API involved

Post List

Endpoint PathDescriptionCommand Word
/api/v2/post/listGet post all listgetPostByAll
/api/v2/post/followGet post list by followgetPostByFollow
/api/v2/post/nearbyGet post list by nearbygetPostByNearby
/api/v2/comment/listGet comment all listgetCommentByAll
/api/v2/comment/followGet comment list by followgetCommentByFollow
/api/v2/comment/nearbyGet comment list by nearbygetCommentByNearby
  • According to the configuration of plugin_usages->data_sources in the plug-in associated usage table, the main program would send the request to the plug-in through command word, after which the plug-in would process the request from the client-end and return the results.

Post Detail

Endpoint PathDescriptionCommand Word
/api/v2/post/detailGet post detailgetPostDetail
/api/v2/comment/detailGet comment detailgetCommentDetail
Endpoint PathDescriptionCommand Word
/api/v2/search/usersSearch UserssearchUsers
/api/v2/search/groupsSearch GroupssearchGroups
/api/v2/search/hashtagsSearch HashtagssearchHashtags
/api/v2/search/postsSearch PostssearchPosts
/api/v2/search/commentsSearch CommentssearchComments

Content Review

Endpoint PathDescriptionCommand Word
/api/v2/editor/{type}/{draftId}

/api/v2/editor/direct-publish
Content PublishreviewNotice

This command word is requested when the content triggers an review.

Request Example
php
$reviewService = ConfigHelper::fresnsConfigByItemKey('content_review_service');

$wordType = match ($type) {
    'post' => 1,
    'comment' => 2,
};

$wordBody = [
    'type' => $wordType,
    'logId' => $draft->id,
];

\FresnsCmdWord::plugin($reviewService)->reviewNotice($wordBody);

Request Process

Parameter NameTypeRequiredDescription
headersObjectrequiredAPI Headers parameter
bodyObjectrequiredThe Body parameter of the corresponding API

Request Example:

php
$wordBody = [
    "headers" => \request()->headers->all(),
    "body" => $dtoRequest->toArray(),
];

\FresnsCmdWord::plugin($unikey)->getPostByFollow($wordBody)

\FresnsCmdWord::plugin($unikey)->getPostDetail($wordBody)

\FresnsCmdWord::plugin($unikey)->searchPosts($wordBody)

Return Example:

After the plug-in processes the request and returns the data, the main program would transmit the returned data to its API interface directly.

  • It is recommended that the plug-in outputs according to the parameter format of the corresponding API, so as to ensure that different client-end could use the plug-in directly.
  • If your client-end is a customized one, the plug-in could also return the output in the format required by the customized client if there are any special requirements.

Additional information

Public Mode: site_mode=public

  • Unlogged in
      1. Do not output private group posts groups->type_mode=2
      1. Judge whether a post has any permission conditions posts->is_allow
      • If there is no permission condition, output the content normally, otherwise the content should be output according to the permission configuration directly (percentage, button text, and plugin)
      • Percentage post_appends->allow_proportion
      • Button Text post_appends->allow_btn_name
      • Plugin post_appends->allow_plugin_unikey
      • Reference App\Fresns\Api\Services\PostService::contentHandle
  • Logged in
      1. Do not output private group posts groups->type_mode=2 unless the user has already followed(user_follows) the group.
      1. Screen posts of blocked accounts user_blocks->block_id
      • block_type=1 Posts by this user
      • block_type=2 Posts under the group
      • block_type=3 Posts related to this hashtag
      • block_type=4 The post
      1. Judge whether a post has any permission conditions posts->is_allow. The logic is the same as above

Private Mode: site_mode=private

  • Unlogged in
      1. Do not output post lists.
  • Logged in
      1. Role permission, whether the role has the right to view roles->permission['content_view']
      1. Whether users->expired_at is within the validity period (permanently effective if left empty)
      • 2.1 site_private_end_after=1 If expired, the content should invisible. In this case, the post lists should not be output.
      • 2.2 site_private_end_after=2 If expired, the content that has not expired is visible. In this case, only the list of posts before the expiration date could be output.
      • 2.3 Within the validity period, all post lists should be output.
    • Other logged-in scenarios with the same logic as the public mode (private groups, blocked accounts, post permission)

Content output and parse logic (including comment content)

  • It is necessary to part and output content of the corresponding format when outputting contents (hashtag, links, mention, and sticker).
    • Reference App\Utilities\ContentUtility::handleAndReplaceAll
  • To output content, the filter words should be replaced.
    • Reference App\Utilities\ContentUtility::replaceBlockWords

Released under the Apache-2.0 License