<commit_before><?php

namespace kato\components;

use Yii;
use backend\models\Setting;
use backend\models\Block;
use yii\helpers\HtmlPurifier;
use yii\web\BadRequestHttpException;
use yii\helpers\Json;
use yii\web\UploadedFile;
use kato\helpers\KatoBase;
use yii\helpers\Html;
use kartik\markdown\Markdown;

/**
 * Usage
 * -----
 *
 * In your configuration file, add the setting component.
 *
 * ```php
 * 'components' => [
 *	...
 *	'kato' => 'kato\components\Kato',
 *	...
 * ]
 * ```
 */

class Kato extends \yii\base\Component 
{

    /**
     * Get settings for Kato
     * Usage:
     *
     * ```php
     * $setting = Yii::$app->kato->setting('site_name');
     * ```
     * @param $key
     * @return bool
     */
    public static function setting($key)
    {
        $model = Setting::find()
            ->where(['define' => $key])
            ->one();

        if (!is_null($model)) {
            return $model->value;
        }

        return false;
    }

    /**
     * returns page slug if set
     * @return string
     */
    public function pageSlug()
    {
        if (isset($_GET['slug'])) {
            return HtmlPurifier::process($_GET['slug']);
        }
        return false;
    }

    /**
     * Returns HTML content of block
     * Usage: \Yii::$app->kato->block('block_slug');
     * @param null $slug
     * @return bool
     * @throws \yii\web\BadRequestHttpException
     */
    public function block($slug = null)
    {
        if (is_null($slug)) {
            throw new BadRequestHttpException('Block slug not specified.');
        }

        $model = Block::find()
            ->where(['title' => $slug])
            ->one();

        if (is_null($model)) {
            return false;
        }

        //TODO check parent
        if (!is_null($model->parent)) {
            //var_dump($model->parent);exit;
        }

        return $model->render();
    }



    /**
     * Renders blocks and out as html
     * Usage: \Yii::$app->kato->renderBlock($this->content);
     * @param null $content
     * @return string
     */
    public function renderBlock($content = null)
    {
        if (!is_array($content)) {
            $content = Json::decode($content);
        }

        $blocks = '';<commit_msg>fix render block<commit_after><?php

namespace kato\components;

use Yii;
use backend\models\Setting;
use backend\models\Block;
use yii\helpers\HtmlPurifier;
use yii\web\BadRequestHttpException;
use yii\helpers\Json;
use yii\web\UploadedFile;
use kato\helpers\KatoBase;
use yii\helpers\Html;
use kartik\markdown\Markdown;

/**
 * Usage
 * -----
 *
 * In your configuration file, add the setting component.
 *
 * ```php
 * 'components' => [
 *	...
 *	'kato' => 'kato\components\Kato',
 *	...
 * ]
 * ```
 */

class Kato extends \yii\base\Component 
{

    /**
     * Get settings for Kato
     * Usage:
     *
     * ```php
     * $setting = Yii::$app->kato->setting('site_name');
     * ```
     * @param $key
     * @return bool
     */
    public static function setting($key)
    {
        $model = Setting::find()
            ->where(['define' => $key])
            ->one();

        if (!is_null($model)) {
            return $model->value;
        }

        return false;
    }

    /**
     * returns page slug if set
     * @return string
     */
    public function pageSlug()
    {
        if (isset($_GET['slug'])) {
            return HtmlPurifier::process($_GET['slug']);
        }
        return false;
    }

    /**
     * Returns HTML content of block
     * Usage: \Yii::$app->kato->block('block_slug');
     * @param null $slug
     * @return bool
     * @throws \yii\web\BadRequestHttpException
     */
    public function block($slug = null)
    {
        if (is_null($slug)) {
            throw new BadRequestHttpException('Block slug not specified.');
        }

        $model = Block::find()
            ->where(['title' => $slug])
            ->one();

        if (is_null($model)) {
            return false;
        }

        //TODO check parent
        if (!is_null($model->parent)) {
            //var_dump($model->parent);exit;
        }

        return $model->render();
    }



    /**
     * Renders blocks and out as html
     * Usage: \Yii::$app->kato->renderBlock($this->content);
     * @param null $content
     * @return string
     */
    public function renderBlock($content = null)
    {
        if (!is_array($content)) {
            if (empty($content) || $content == '') {
                return false;
            }
            $content = Json::decode($content);
        }

        $blocks = '';
{'fraction_non_alphanumeric': 0.16056644880174292, 'fraction_numerical': 0.0, 'mean_word_length': 1.8604361370716511, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '69238', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1438, 'n_words': 303}