<commit_before><?php

$dcon = defined('connection') ? (connection ? true : false) : false;

// Static vs singleton class http://moisadoru.wordpress.com/2010/03/02/static-call-versus-singleton-call-in-php/
class datemod {
    //public function __construct($mysqli) {} // MySQLi in class http://www.weblimner.com/tutorial/using-mysqli-in-a-seperate-class/
    // HTTP header cache
    public static function cache() {
        global $dcon, $mysqli, $url;

        $update = $fmod = date('Y-m-d H:i:s', filemtime($_SERVER['SCRIPT_FILENAME']));

        if ($dcon) {
            $stmt = isset($url) ? $mysqli->prepare("SELECT GREATEST(updated, created) AS date FROM `" . table . "` WHERE url = ? LIMIT 1")
                                : $mysqli->prepare("SELECT MAX(GREATEST(updated, created)) AS date FROM `" . table . "`");
            if (isset($url)) {
                $stmt->bind_param('s', $url);
            }
            $stmt->execute();
            $stmt->bind_result($date);

            while ($stmt->fetch()) {
                $update = max($fmod, $date);
            }

            $stmt->free_result();
            $stmt->close();
        }

        $update = date('D, d M Y H:i:s T', strtotime($update));

        if ((isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $update) {
            http_response_code(304);
            ob_end_clean(); // Empty the response body
            exit;
        }

        header('Last-Modified: '. $update);
    }

    // Recent file update
    public static function date() {
        global $dcon, $mysqli, $url;

        $directory = new RecursiveDirectoryIterator('.');
        $iterator  = new RecursiveIteratorIterator($directory);
        $regex     = new RegexIterator($iterator, '/.+\.(appcache|css|js|php|txt|xml)/');
        $modfile   = array();

        foreach($regex as $key) {
            $modfile[] = $key->getMTime();
        }

        $update = date('Y-m-d H:i:s',  max($modfile));

        if ($dcon) {
            // Recent database update
            if ($stmt = $mysqli->prepare("SELECT MAX(GREATEST(updated, created)) AS date FROM `" . table . "`")) {
                $stmt->execute();
                $stmt->bind_result($date);

                while ($stmt->fetch()) {
                    $update = max($update, $date);
                }

                $stmt->free_result();
                $stmt->close();
            }
        }

        //$update = date('Y/m/d', strtotime($update));
        return $update;
    }
}
datemod::cache();<commit_msg>HTTP cache related to update date<commit_after><?php
//
// Static vs singleton class http://moisadoru.wordpress.com/2010/03/02/static-call-versus-singleton-call-in-php/
//

$dbcon = defined('connection') ? connection : false;

class cache {
    private static $dbcon;

    // HTTP header cache
    private static function http($date) {
        // $date = strtotime($date);
        // if (!$date) return false;
        $date = date('D, d M Y H:i:s T', strtotime($date));

        if ((isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $date) {
            http_response_code(304);
            ob_end_clean(); // Empty the response body
            exit;
        }

        header('Last-Modified: '. $date);
    }

    // Identified URL cache
    public static function url() {
        self::http(self::$dbcon ? max(date::url(), date::file('php')) : date::file('php'));
    }

    // The opened file
    public static function me() {
        self::http(date::me());
    }

    // The opened file vs latest database update
    public static function medb() {
        self::http(self::$dbcon ? max(date::db(), date::me()) : date::me());
    }

    // Latest update
    public static function all() {
        self::http(self::$dbcon ? max(date::db(), date::file('appcache|css|js|php|txt|xml')) : date::file('appcache|css|js|php|txt|xml'));
    }
}

class date {
    private static $mysqli;

    //public function __construct($mysqli) {} // MySQLi in class http://www.weblimner.com/tutorial/using-mysqli-in-a-seperate-class/
    public static function url() {
        global $url;

        $stmt = self::$mysqli->prepare('SELECT GREATEST(updated, created) AS date FROM `' . table . '` WHERE url=? LIMIT 1');

        $stmt->bind_param('s', $url);
        $stmt->execute();
        $stmt->bind_result($date);
        $stmt->fetch();
        $stmt->free_result();
        $stmt->close();

        return $date;
    }

    // Latest database update
    public static function db() {
        $stmt = self::$mysqli->prepare('SELECT MAX(GREATEST(updated, created)) AS date FROM `' . table . '`');

        $stmt->execute();
        $stmt->bind_result($date);
        $stmt->fetch();
        $stmt->free_result();
        $stmt->close();

        return $date;
    }

    // The file
    public static function me() {
        return date('Y-m-d H:i:s', filemtime($_SERVER['SCRIPT_FILENAME']));
    }

    // Recent file update filtered by type
    public static function file($type) {
        $directory = new RecursiveDirectoryIterator('.');
        $iterator  = new RecursiveIteratorIterator($directory);
        $regex     = new RegexIterator($iterator, '/.+\.(' . $type . ')/');
        $date      = [];

        foreach($regex as $key) $date[] = $key->getMTime();

        return date('Y-m-d H:i:s', max($date));
    }

    // Latest update
    public static function all() {
        return max(self::db(), self::file('appcache|css|js|php|txt|xml'));
    }
}
{'fraction_non_alphanumeric': 0.17395167022032693, 'fraction_numerical': 0.0042643923240938165, 'mean_word_length': 2.2481246393537218, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1600839', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1724, 'n_words': 363}