<commit_before><?php

class REST_API {
    const API_NAMESPACE = "kiku/v1";
    const CACHE_PREFIX = "kiku_cache_";

    // public function __construct() {}

    public function pre_dispatch($result, $server, $request) {
        // cache-control ヘッダーをセット
        $headers['Cache-Control'] = 'public, max-age=' . HOUR_IN_SECONDS;
        $server->send_headers($headers);
    }

    public function disable_api_endpoint($endpoints) {
        unset($endpoints['/wp/v2/users']);
        unset($endpoints['/wp/v2/users/(?P<id>[\d]+)']);
        unset($endpoints['/wp/v2/comments']);
        unset($endpoints['/wp/v2/comments/(?P<id>[\d]+)']);
        unset($endpoints['/wp/v2/settings']);

        return $endpoints;
    }

    // To decimate API information.
    public function disable_api_data($response, $post, $request) {
        unset($response->data['date_gmt']);
        unset($response->data['modified_gmt']);
        unset($response->data['guid']);
        unset($response->data['type']);
        unset($response->data['author']);
        unset($response->data['slug']);
        unset($response->data['status']);
        unset($response->data['featured_media']);
        unset($response->data['comment_status']);
        unset($response->data['ping_status']);
        unset($response->data['sticky']);
        unset($response->data['template']);
        unset($response->data['format']);

        return $response;
    }

    public function rest_api_init() {
        $this->original_api();
        $this->rewrite_api();
    }

    public function original_api() {
        register_rest_route(self::API_NAMESPACE, '/post/(?P<id>\d+)', [
            'methods' => WP_REST_Server::READABLE,
            'callback' => function($data) {
                $request_url = $_SERVER['REQUEST_URI'];

                // transient で一時的にキャッシュしたデータをロード
                $key = self::CACHE_PREFIX . md5($request_url);
                $result = get_transient($key);

                if ($result === false) {
                    global $Entry, $post;

                    $post_id = $data['id'];
                    $array = [];

                    // related posts
                    $related = $Entry->get_similar_posts(RELATED_POST_NUM, $post_id);
                    // pager
                    $pager = $Entry->pager($post_id);

                    // set
                    $array = [
                        'related' => $related,
                        'pager' => $pager,
                    ];

                    set_transient($key, $array, HOUR_IN_SECONDS);
                    return $array;
                }

                return $result;
            },
        ]);

        register_rest_route(self::API_NAMESPACE, '/navigation', [
            'methods'  => WP_REST_Server::READABLE,
            'callback' => function($data) {
                $request_url = $_SERVER['REQUEST_URI'];

                // transient で一時的にキャッシュしたデータをロード
                $key = self::CACHE_PREFIX . md5($request_url);
                $result = get_transient($key);

                if ($result === false) {
                    $array = [
                        'site' => [
                            'name' => BLOG_NAME,
                            'url' => BLOG_URL,
                            'copyright' => "© " . Kiku\Util::get_copyright_year(),
                        ],
                        // 'header' => [],
                        'footer' => [
                            'menu' => $this->get_menus(),
                        ],
                '       widget' => $this->get_widget(),
                    ];

                    set_transient($key, $array, HOUR_IN_SECONDS);
                    return $array;
                }

                return $result;
            }
        ]);
    }

    public function get_widget() {
        $widget = null;

        if (is_active_sidebar('sidebar-primary')) {
            ob_start();
            dynamic_sidebar('sidebar-primary');
            $widget = ob_get_contents();
            ob_end_clean();
        }

        return $widget;
    }
<commit_msg>fix: typo<commit_after><?php

class REST_API {
    const API_NAMESPACE = "kiku/v1";
    const CACHE_PREFIX = "kiku_cache_";

    // public function __construct() {}

    public function pre_dispatch($result, $server, $request) {
        // cache-control ヘッダーをセット
        $headers['Cache-Control'] = 'public, max-age=' . HOUR_IN_SECONDS;
        $server->send_headers($headers);
    }

    public function disable_api_endpoint($endpoints) {
        unset($endpoints['/wp/v2/users']);
        unset($endpoints['/wp/v2/users/(?P<id>[\d]+)']);
        unset($endpoints['/wp/v2/comments']);
        unset($endpoints['/wp/v2/comments/(?P<id>[\d]+)']);
        unset($endpoints['/wp/v2/settings']);

        return $endpoints;
    }

    // To decimate API information.
    public function disable_api_data($response, $post, $request) {
        unset($response->data['date_gmt']);
        unset($response->data['modified_gmt']);
        unset($response->data['guid']);
        unset($response->data['type']);
        unset($response->data['author']);
        unset($response->data['slug']);
        unset($response->data['status']);
        unset($response->data['featured_media']);
        unset($response->data['comment_status']);
        unset($response->data['ping_status']);
        unset($response->data['sticky']);
        unset($response->data['template']);
        unset($response->data['format']);

        return $response;
    }

    public function rest_api_init() {
        $this->original_api();
        $this->rewrite_api();
    }

    public function original_api() {
        register_rest_route(self::API_NAMESPACE, '/post/(?P<id>\d+)', [
            'methods' => WP_REST_Server::READABLE,
            'callback' => function($data) {
                $request_url = $_SERVER['REQUEST_URI'];

                // transient で一時的にキャッシュしたデータをロード
                $key = self::CACHE_PREFIX . md5($request_url);
                $result = get_transient($key);

                if ($result === false) {
                    global $Entry, $post;

                    $post_id = $data['id'];
                    $array = [];

                    // related posts
                    $related = $Entry->get_similar_posts(RELATED_POST_NUM, $post_id);
                    // pager
                    $pager = $Entry->pager($post_id);

                    // set
                    $array = [
                        'related' => $related,
                        'pager' => $pager,
                    ];

                    set_transient($key, $array, HOUR_IN_SECONDS);
                    return $array;
                }

                return $result;
            },
        ]);

        register_rest_route(self::API_NAMESPACE, '/navigation', [
            'methods'  => WP_REST_Server::READABLE,
            'callback' => function($data) {
                $request_url = $_SERVER['REQUEST_URI'];

                // transient で一時的にキャッシュしたデータをロード
                $key = self::CACHE_PREFIX . md5($request_url);
                $result = get_transient($key);

                if ($result === false) {
                    $array = [
                        'site' => [
                            'name' => BLOG_NAME,
                            'url' => BLOG_URL,
                            'copyright' => "© " . Kiku\Util::get_copyright_year(),
                        ],
                        // 'header' => [],
                        'footer' => [
                            'menu' => $this->get_menus(),
                        ],
                        'widget' => $this->get_widget(),
                    ];

                    set_transient($key, $array, HOUR_IN_SECONDS);
                    return $array;
                }

                return $result;
            }
        ]);
    }

    public function get_widget() {
        $widget = null;

        if (is_active_sidebar('sidebar-primary')) {
            ob_start();
            dynamic_sidebar('sidebar-primary');
            $widget = ob_get_contents();
            ob_end_clean();
        }

        return $widget;
    }

{'fraction_non_alphanumeric': 0.15096868526867308, 'fraction_numerical': 0.0019495552577068356, 'mean_word_length': 1.4955913651565826, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1518576', 'n_tokens_mistral': 2363, 'n_tokens_neox': 2272, 'n_words': 331}