<commit_before><?php
    require_once(__DIR__ . '/lib/Spyc.php');

    error_reporting(E_ALL);

    define('TEMPLATE_PATH', realpath(__DIR__ . '/../') . '/');


    function recurseDir($location, $path) {
        $files = array();
        if(is_dir($path)){
            $files = array_merge($files, glob($path . '/*.php'));
            foreach(glob($path . '/*', GLOB_ONLYDIR) as $dir) {
                $files = array_merge($files, recurseDir($location, $dir));
            }
        }
        else {
            $path = TEMPLATE_PATH . trim($location, '/') . '.php';
            if (file_exists($path)) {
                $files[] = $path;
            }
        }
        return $files;
    }

    function getBlock($location, $options=array()) {
        $path = TEMPLATE_PATH . trim($location, '/');

        $files = recurseDir($location, $path);

        if(empty($files)) {
            return '';
        }
        $printContainer = false;
        ob_start();
        foreach($files as $path) {
            $_t = new TemplateHelper(parseComments(file_get_contents($path)), $options);
            $printContainer |= $_t->shouldPrintContainer();
            echo $_t->printTitle();
            include $path;
        }
        $contents .= ob_get_contents();
        ob_end_clean();
        if($printContainer) { 
            $contents = '<div class="u-container">' . $contents . '</div>'; 
        }
        return $contents;
    }

    function getBaseUrl() {
        return dirname($_SERVER['SCRIPT_NAME']) . "/../";
    }

    function getUrl($url = false) {
        return getBaseUrl().($url ?: '');
    }

    function getRequestPath() {
        $base = substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], 'index.php'));
        $url_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        return substr($url_path, strlen($base) - 1);
    }

    function isIndex() {
        return getRequestPath() === '/';
    }

    function imageUrl($src, array $args) {
        if (strlen($src) >= 4 && substr($src, 0, 4) !== 'http') {
            $src = getUrl($src);
        }

        $qs = http_build_query($args);

        return 'http://iweb:developer@isabelaweb1.cms.iwebcloud.co.uk/image/'.base64_encode($src).($qs ? '?'.$qs : '');
    }

    function title($title, $class, $description='') {
	    return array(
            'title'=>$title,
            'class'=>$class,
            'description'=>$description
        );
    }

    function parseComments($source) {
        $tokens = token_get_all( $source );
        $comments = array();
        $comment = array(
            T_COMMENT,
            T_DOC_COMMENT
        );
        foreach( $tokens as $token ) {
            if( !in_array($token[0], $comment) ) {
                continue;
            }
            $matches = array();
            if(preg_match('#(?:/\*+)((?:(?!\*+/).)*)#ms', $token[1], $matches)){
                $comments[] = $matches[1];
            }
            else{
                $comments[] = substr(trim($token[1]), 2);
            }
        }

        $data = array();

        foreach($comments as $comment) {
            $data = array_merge($data, spyc_load($comment));
        }
        return $data;
    }

    class TemplateHelper {
        protected $data = array();
        protected $options = array();

        public function __construct($data = array(), $options=array()) {
            $this->printTitle = isset($options['print_title']) && $options['print_title'];
            $this->printContainer = isset($options['print_container']) && $options['print_container'];
            $this->data = $data;
            $this->options = $options;
        }

        public function __get($key) {
            if(isset($this->data[$key])){
                return $this->data[$key];
            }
            return '';
        }

        public function shouldPrintContainer(){
            return $this->printContainer && $this->Container !== false; 
        }

        public function printTitle() {
            $title = '';
            if(!$this->printTitle) {
                return '';
            }
            if($this->Title) {
                $title = '<p class=cc-heading>' . $this->Title;
                if($this->Class) {
                    $title .= ' <code>' . $this->Class . '</code>';
                }
                $title .= '</p>';
                if($this->Description) {
                    $title .= '<p>' . $this->Description . '</p>';
                }
            }
            return $title;
        }
    }

    $toplevels = array('branding', 'atom', 'molecule', 'organism', 'template');
<commit_msg>Rename branding -> global<commit_after><?php
    require_once(__DIR__ . '/lib/Spyc.php');

    error_reporting(E_ALL);

    define('TEMPLATE_PATH', realpath(__DIR__ . '/../') . '/');


    function recurseDir($location, $path) {
        $files = array();
        if(is_dir($path)){
            $files = array_merge($files, glob($path . '/*.php'));
            foreach(glob($path . '/*', GLOB_ONLYDIR) as $dir) {
                $files = array_merge($files, recurseDir($location, $dir));
            }
        }
        else {
            $path = TEMPLATE_PATH . trim($location, '/') . '.php';
            if (file_exists($path)) {
                $files[] = $path;
            }
        }
        return $files;
    }

    function getBlock($location, $options=array()) {
        $path = TEMPLATE_PATH . trim($location, '/');

        $files = recurseDir($location, $path);

        if(empty($files)) {
            return '';
        }
        $printContainer = false;
        ob_start();
        foreach($files as $path) {
            $_t = new TemplateHelper(parseComments(file_get_contents($path)), $options);
            $printContainer |= $_t->shouldPrintContainer();
            echo $_t->printTitle();
            include $path;
        }
        $contents .= ob_get_contents();
        ob_end_clean();
        if($printContainer) { 
            $contents = '<div class="u-container">' . $contents . '</div>'; 
        }
        return $contents;
    }

    function getBaseUrl() {
        return dirname($_SERVER['SCRIPT_NAME']) . "/../";
    }

    function getUrl($url = false) {
        return getBaseUrl().($url ?: '');
    }

    function getRequestPath() {
        $base = substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], 'index.php'));
        $url_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        return substr($url_path, strlen($base) - 1);
    }

    function isIndex() {
        return getRequestPath() === '/';
    }

    function imageUrl($src, array $args) {
        if (strlen($src) >= 4 && substr($src, 0, 4) !== 'http') {
            $src = getUrl($src);
        }

        $qs = http_build_query($args);

        return 'http://iweb:<EMAIL>.cms.iwebcloud.co.uk/image/'.base64_encode($src).($qs ? '?'.$qs : '');
    }

    function title($title, $class, $description='') {
	    return array(
            'title'=>$title,
            'class'=>$class,
            'description'=>$description
        );
    }

    function parseComments($source) {
        $tokens = token_get_all( $source );
        $comments = array();
        $comment = array(
            T_COMMENT,
            T_DOC_COMMENT
        );
        foreach( $tokens as $token ) {
            if( !in_array($token[0], $comment) ) {
                continue;
            }
            $matches = array();
            if(preg_match('#(?:/\*+)((?:(?!\*+/).)*)#ms', $token[1], $matches)){
                $comments[] = $matches[1];
            }
            else{
                $comments[] = substr(trim($token[1]), 2);
            }
        }

        $data = array();

        foreach($comments as $comment) {
            $data = array_merge($data, spyc_load($comment));
        }
        return $data;
    }

    class TemplateHelper {
        protected $data = array();
        protected $options = array();

        public function __construct($data = array(), $options=array()) {
            $this->printTitle = isset($options['print_title']) && $options['print_title'];
            $this->printContainer = isset($options['print_container']) && $options['print_container'];
            $this->data = $data;
            $this->options = $options;
        }

        public function __get($key) {
            if(isset($this->data[$key])){
                return $this->data[$key];
            }
            return '';
        }

        public function shouldPrintContainer(){
            return $this->printContainer && $this->Container !== false; 
        }

        public function printTitle() {
            $title = '';
            if(!$this->printTitle) {
                return '';
            }
            if($this->Title) {
                $title = '<p class=cc-heading>' . $this->Title;
                if($this->Class) {
                    $title .= ' <code>' . $this->Class . '</code>';
                }
                $title .= '</p>';
                if($this->Description) {
                    $title .= '<p>' . $this->Description . '</p>';
                }
            }
            return $title;
        }
    }

    $toplevels = array('global', 'atom', 'molecule', 'organism', 'template');

{'fraction_non_alphanumeric': 0.17550096961861666, 'fraction_numerical': 0.0026933850463262228, 'mean_word_length': 1.7009019493744544, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '3361957', 'n_tokens_mistral': 2732, 'n_tokens_neox': 2615, 'n_words': 472}