> For the complete documentation index, see [llms.txt](https://linkis-organization.gitbook.io/v2boar-zero-theme/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://linkis-organization.gitbook.io/v2boar-zero-theme/shi-yong-jiao-cheng/za-qi-za-ba.md).

# 杂七杂八

### 1. 知识库仅为有效订阅显示

修改以下文件：`app/Http/Controllers/V1/User/KnowledgeController.php`

<mark style="color:red;">代码使用xboard代码为原型修改，其他版本请手动增加函数和调用。</mark>

```php
<?php

namespace App\Http\Controllers\V1\User;

use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;
use App\Models\Knowledge;
use App\Models\User;
use App\Services\UserService;
use App\Utils\Helper;
use Illuminate\Http\Request;

class KnowledgeController extends Controller
{
    public function fetch(Request $request)
    {
        if ($request->input('id')) {
            $knowledge = Knowledge::where('id', $request->input('id'))
                ->where('show', 1)
                ->first()
                ->toArray();
            if (!$knowledge) return $this->fail([500, __('Article does not exist')]);
            $user = User::find($request->user['id']);
            $userService = new UserService();
            if (!$userService->isAvailable($user)) {
                $this->formatAccessData($knowledge['body']);
            }
            
            // 调用增加的函数
            $this->formatAccessDataWithPlan($knowledge['body'], $user->plan_id);
            
            $subscribeUrl = Helper::getSubscribeUrl("/api/v1/client/subscribe?token={$user['token']}");
            $knowledge['body'] = str_replace('{{siteName}}', admin_setting('app_name', 'XBoard'), $knowledge['body']);
            $knowledge['body'] = str_replace('{{subscribeUrl}}', $subscribeUrl, $knowledge['body']);
            $knowledge['body'] = str_replace('{{urlEncodeSubscribeUrl}}', urlencode($subscribeUrl), $knowledge['body']);
            $knowledge['body'] = str_replace(
                '{{safeBase64SubscribeUrl}}',
                str_replace(
                    array('+', '/', '='),
                    array('-', '_', ''),
                    base64_encode($subscribeUrl)
                ),
                $knowledge['body']
            );
            return $this->success($knowledge);
        }
        $builder = Knowledge::select(['id', 'category', 'title', 'updated_at'])
            ->where('language', $request->input('language'))
            ->where('show', 1)
            ->orderBy('sort', 'ASC');
        $keyword = $request->input('keyword');
        if ($keyword) {
            $builder = $builder->where(function ($query) use ($keyword) {
                $query->where('title', 'LIKE', "%{$keyword}%")
                    ->orWhere('body', 'LIKE', "%{$keyword}%");
            });
        }

        $knowledges = $builder->get()
            ->groupBy('category');
        return $this->success($knowledges);
    }
    
    private function formatAccessData(&$body)
    {
        $pattern = '/<!--access start-->(.*?)<!--access end-->/s';
        $replacement = '<div class="v2board-no-access">' . __('You must have a valid subscription to view content in this area') . '</div>';
        $body = preg_replace($pattern, $replacement, $body);
    }
    
    // 增加函数
    private function formatAccessDataWithPlan(&$body, $plan_id)
    {
        $pattern = '/<!--access start plan_id=([\d,]+) -->(.*?)<!--access end-->/s';
        $callback = function ($matches) use ($plan_id) {
            $allowed_plan_ids = array_map('intval', explode(',', $matches[1]));
    
            if (!in_array((int)$plan_id, $allowed_plan_ids, true)) {
                return '<div class="v2board-no-access">' . __('You must have a valid subscription to view content in this area') . '</div>';
            }
            return $matches[0];
        };
        $body = preg_replace_callback($pattern, $callback, $body);
    }

}

```

修改后可支持:

```
<!--access start plan_id=1,2,3 -->
订阅ID为1,2,3 则展示内容...
<!--access end-->
```

### 2.Nginx 配置禁止缓存 config.json

```
location = /config.json {
    add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate";
    add_header Pragma "no-cache";
    add_header Expires 0;
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://linkis-organization.gitbook.io/v2boar-zero-theme/shi-yong-jiao-cheng/za-qi-za-ba.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
