<commit_before><?php

namespace o;

class HitCounter {

    static public $skipThisPage = false;

    static private $BOT_REGEX = '/bot\b|crawl|spider|slurp|baidu|\bbing|duckduckgo|yandex|teoma|aolbuild/i';

    static public function add() {

        if (!Tht::getConfig('hitCounter')) {
            return;
        }

        if (self::skip()) {
            return;
        }

        Tht::module('Perf')->u_start('tht.hitCounter');

        self::countDate();
        self::countPage();
        self::countReferrer();

        Tht::module('Perf')->u_stop();
    }

    static private function skip() {

        if (self::$skipThisPage) {
            return true;
        }

        // bots
        $ua = Tht::module('Request')->u_user_agent();
        if (preg_match(self::$BOT_REGEX, $ua['full'])) {
            return true;
        }
        // only count routes
        $path = Tht::module('Request')->u_url()->u_path();
        if (strpos($path, '.') !== false) {
            return true;
        }

        return false;
    }

    static private function logPath($dir, $file) {
        return realpath(DATA_ROOT . '/counter/' . $dir) . '/' . $file . '.txt';
    }

    static private function logDir($dir) {
        return realpath(DATA_ROOT . '/counter/' . $dir);
    }

    // Date counter - 1 byte per hit
    static private function countDate() {
        $date = strftime('%Y%m%d');
        $dateLogPath = self::logPath('date', $date);
        file_put_contents($dateLogPath, '+', FILE_APPEND|LOCK_EX);
    }

    // Page counter - 1 byte per hit
    static private function countPage() {

        $page = Tht::module('Request')->u_url()->u_path();<commit_msg>extra check for counter dir<commit_after><?php

namespace o;

class HitCounter {

    static public $skipThisPage = false;

    static private $BOT_REGEX = '/bot\b|crawl|spider|slurp|baidu|\bbing|duckduckgo|yandex|teoma|aolbuild/i';

    static public function add() {

        if (!Tht::getConfig('hitCounter')) {
            return;
        }

        if (self::skip()) {
            return;
        }

        Tht::module('Perf')->u_start('tht.hitCounter');

        self::countDate();
        self::countPage();
        self::countReferrer();

        Tht::module('Perf')->u_stop();
    }

    static private function skip() {

        if (self::$skipThisPage) {
            return true;
        }

        // bots
        $ua = Tht::module('Request')->u_user_agent();
        if (preg_match(self::$BOT_REGEX, $ua['full'])) {
            return true;
        }
        // only count routes
        $path = Tht::module('Request')->u_url()->u_path();
        if (strpos($path, '.') !== false) {
            return true;
        }

        return false;
    }

    static private function logPath($dir, $file) {
        return self::logDir($dir) . '/' . $file . '.txt';
    }

    static private function logDir($dir) {
        $root = DATA_ROOT . '/counter/' . $dir;
        $path = realpath($root);
        if ($path == '') {
            Tht::error("Unable to find counter directory: `$root`");
        }
        return $path;
    }

    // Date counter - 1 byte per hit
    static private function countDate() {
        $date = strftime('%Y%m%d');
        $dateLogPath = self::logPath('date', $date);
        file_put_contents($dateLogPath, '+', FILE_APPEND|LOCK_EX);
    }

    // Page counter - 1 byte per hit
    static private function countPage() {

        $page = Tht::module('Request')->u_url()->u_path();
{'fraction_non_alphanumeric': 0.16389684813753583, 'fraction_numerical': 0.001146131805157593, 'mean_word_length': 2.1086375779162956, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '3293792', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1081, 'n_words': 221}