knowledge: add access area

This commit is contained in:
tokumeikoi 2021-05-13 18:08:09 +09:00
parent 3275b96a0a
commit f1c62e2732
4 changed files with 24 additions and 3 deletions

View File

@ -20,8 +20,14 @@ class KnowledgeController extends Controller
if (!$knowledge) abort(500, __('user.knowledge.fetch.knowledge_not_exist'));
$user = User::find($request->session()->get('id'));
$userService = new UserService();
$appleId = $userService->isAvailable($user) ? config('v2board.apple_id') : __('user.knowledge.fetch.apple_id_must_be_plan');
$appleIdPassword = $userService->isAvailable($user) ? config('v2board.apple_id_password') : __('user.knowledge.fetch.apple_id_must_be_plan');
if ($userService->isAvailable($user)) {
$appleId = config('v2board.apple_id');
$appleIdPassword = config('v2board.apple_id_password');
} else {
$appleId = __('user.knowledge.fetch.apple_id_must_be_plan');
$appleIdPassword = __('user.knowledge.fetch.apple_id_must_be_plan');
$this->formatAccessData($knowledge['body']);
}
$subscribeUrl = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user['token'];
$knowledge['body'] = str_replace('{{siteName}}', config('v2board.app_name', 'V2Board'), $knowledge['body']);
$knowledge['body'] = str_replace('{{appleId}}', $appleId, $knowledge['body']);
@ -51,4 +57,13 @@ class KnowledgeController extends Controller
'data' => $knowledges
]);
}
private function formatAccessData(&$body)
{
function getBetween($input, $start, $end){$substr = substr($input, strlen($start)+strpos($input, $start),(strlen($input) - strpos($input, $end))*(-1));return $substr;}
$accessData = getBetween($body, '<!--access start-->', '<!--access end-->');
if ($accessData) {
$body = str_replace($accessData, '<div class="v2board-no-access">'. __('user.knowledge.formatAccessData.no_access') .'</div>', $body);
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -112,6 +112,9 @@ return [
'fetch' => [
'knowledge_not_exist' => 'Article does not exist',
'apple_id_must_be_plan' => 'No active subscription. Unable to use our provided Apple ID'
],
'formatAccessData' => [
'no_access' => 'You must have a valid subscription to view content in this area'
]
],
'invite' => [

View File

@ -112,6 +112,9 @@ return [
'fetch' => [
'knowledge_not_exist' => '文章不存在',
'apple_id_must_be_plan' => '无有效订阅,无法使用本站提供的 AppleID'
],
'formatAccessData' => [
'no_access' => '你必须拥有有效的订阅才可以查看该区域的内容'
]
],
'invite' => [