<commit_before><?php

namespace Yard;

class Base
{
    use \Yard\Lib\ArrayTools;
    
    public $offline = false;
    public $host = '';
    public $dir = [
        'base' => '',
        'cache' => '',
        'redux' => ''
    ];
    public $url = [
        'base' => '',
        'page' => '',
        'cache' => ''
    ];
    public $pages = [];
    public $pageNamespace = 'Pages\\';

    function __construct($settings = [])
    {
        $settings['dir'] = $this->validateDir(@$settings['dir']);
        $this->validateUrl(@$settings['url']);
        $this->validatePages(@$settings['pages']);

        foreach ($settings['url'] as $k => $url) {
            if (strpos($url, 'http') !== 0) {
                $settings['url'][$k] = substr($url, 0, 3) . str_replace("//", "/", substr($url, 3));
            } else {
                $settings['url'][$k] = substr($url, 0, 7) . str_replace("//", "/", substr($url, 7));
            }
        }
        
        if (isset($settings['offline'])) {
            $this->offline = $settings['offline'];
        }
        
        $this->host = $settings['host'];
        $this->name = @$settings['name'];
        $this->dir = $settings['dir'];
        $this->url = $settings['url'];
        $this->pages = $settings['pages'];

        $d = DIRECTORY_SEPARATOR;
        
        # load sample yard pages
        $vurl = strtr($this->url['page'], [
            '[page]' => 'vendor...vendor'
        ]);
        
        if (strpos($vurl, '?') === false) {
            $vurl = $vurl . "?_v_dr=";
        } else {
            $vurl = $vurl . "&_v_dr=";
        }
        
        $this->pages['yard'] = [
            'dir' => dirname(__FILE__) . $d . 'Sample',
            'url' => $vurl . "/plansys/yard/src/Sample"
        ];
        
        # load crud if exists
        if (class_exists('\Plansys\Crud\Init')) {
            $base = \Plansys\Crud\Init::getBase($this->host);
            $this->pages['crud'] = $base['pages'][''];
        }

        # load crud if exists
        if (class_exists('\Plansys\Db\Init')) {
            $base = \Plansys\Db\Init::getBase($this->host);
            $this->pages['db'] = $base['pages'][''];
        }
    }
    
    public function isPage($tag)
    {
        $tag = str_replace(".", DIRECTORY_SEPARATOR, $tag);
        $tags = explode(":", $tag);
        $shortcut = '';
        if (count($tags) > 1) {
            $shortcut = array_shift($tags);
            $tag = implode(":", $tags);
        }

        if (is_file($this->pages[$shortcut]['dir'] . DIRECTORY_SEPARATOR . $tag . '.php')) {
            return true;<commit_msg>Fixing base without default module<commit_after><?php

namespace Yard;

class Base
{
    use \Yard\Lib\ArrayTools;
    
    public $offline = false;
    public $host = '';
    public $dir = [
        'base' => '',
        'cache' => '',
        'redux' => ''
    ];
    public $url = [
        'base' => '',
        'page' => '',
        'cache' => ''
    ];
    public $pages = [];
    public $pageNamespace = 'Pages\\';

    function __construct($settings = [])
    {
        $settings['dir'] = $this->validateDir(@$settings['dir']);
        $this->validateUrl(@$settings['url']);
        $this->validatePages(@$settings['pages']);

        foreach ($settings['url'] as $k => $url) {
            if (strpos($url, 'http') !== 0) {
                $settings['url'][$k] = substr($url, 0, 3) . str_replace("//", "/", substr($url, 3));
            } else {
                $settings['url'][$k] = substr($url, 0, 7) . str_replace("//", "/", substr($url, 7));
            }
        }
        
        if (isset($settings['offline'])) {
            $this->offline = $settings['offline'];
        }
        
        $this->host = $settings['host'];
        $this->name = @$settings['name'];
        $this->dir = $settings['dir'];
        $this->url = $settings['url'];
        $this->pages = $settings['pages'];

        $d = DIRECTORY_SEPARATOR;
        
        # load sample yard pages
        $vurl = strtr($this->url['page'], [
            '[page]' => 'vendor...vendor'
        ]);
        
        if (strpos($vurl, '?') === false) {
            $vurl = $vurl . "?_v_dr=";
        } else {
            $vurl = $vurl . "&_v_dr=";
        }
        
        $this->pages['yard'] = [
            'dir' => dirname(__FILE__) . $d . 'Sample',
            'url' => $vurl . "/plansys/yard/src/Sample"
        ];
        
        # load crud if exists
        if (class_exists('\Plansys\Crud\Init')) {
            $base = \Plansys\Crud\Init::getBase($this->host);
            $this->pages['crud'] = $base['pages'][''];
        }

        # load crud if exists
        if (class_exists('\Plansys\Db\Init')) {
            $base = \Plansys\Db\Init::getBase($this->host);
            $this->pages['db'] = $base['pages'][''];
        }
    }
    
    public function isPage($tag)
    {
        $tag = str_replace(".", DIRECTORY_SEPARATOR, $tag);
        $tags = explode(":", $tag);
        $shortcut = '';
        if (count($tags) > 1) {
            $shortcut = array_shift($tags);
            $tag = implode(":", $tags);
        }

        if (is_file(@$this->pages[$shortcut]['dir'] . DIRECTORY_SEPARATOR . $tag . '.php')) {
            return true;
{'fraction_non_alphanumeric': 0.21161904761904762, 'fraction_numerical': 0.0030476190476190477, 'mean_word_length': 1.7136950904392765, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 57, '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': '6364003', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1673, 'n_words': 293}