<commit_before><?php
class Cache
 {
  #const CLEAR_INCLUDE_PAGE = true;
  public $doCaching = true;
  public $autoClear = true;
  public $cacheId = false;
  private $_cacheDir;
  private $_settings;

  public function __construct($cacheDir, $settings)
   {
    $this->_cacheDir = $cacheDir;
    $this->_settings = $settings;
   }

  public function createCacheContent($content, $content_type, $charset)
   {
    $cacheContent = '<?php
header(\'Last-Modified: ' . gmdate("D, d M Y H:i:s",time()) . ' GMT\');
header(\'Cache-Control: public\');
if(isset($_SERVER[\'HTTP_IF_MODIFIED_SINCE\']) && '.time().' <= strtotime($_SERVER[\'HTTP_IF_MODIFIED_SINCE\']))
{
header(\'HTTP/1.1 304 Not Modified\');
exit;
}
else
{
';
    if(function_exists('xgzencode')) $cacheContent .= 'if(isset($_SERVER[\'HTTP_ACCEPT_ENCODING\']) && strpos($_SERVER[\'HTTP_ACCEPT_ENCODING\'], \'gzip\')!==false)
{
header(\'Content-Encoding: gzip\');
header(\'Content-Type: '.$content_type.'; charset='.$charset.'\'); ?'.'>'.gzencode($content, 9).'<?php
}
else
{
header(\'Content-Type: '.$content_type.'; charset='.$charset.'\'); ?'.'>'.$content.'<?php
}';
    else $cacheContent .= 'header(\'Content-Type: '.$content_type.'; charset='.$charset.'\'); ?'.'>'.$content.'<?php
';
$cacheContent .= '}
?>';
    return $cacheContent;
   }

  public function createChacheFile($content)
   {
    if($this->cacheId && $this->doCaching)
     {
      #$cacheFile = $this->_cacheDir . str_replace('/','%',$this->cacheId).'.cache';
      $cacheFile = $this->_cacheDir . rawurlencode(strtolower($this->cacheId)).'.cache';
      if(!file_exists($cacheFile))
       {
        $content = str_replace('<?xml','<?php echo \'<?xml\'; ?>', $content);
        $fp = @fopen($cacheFile, 'w');
        @flock($fp, 2);
        @fwrite($fp, $content);
        @flock($fp, 3);
        @fclose($fp);
       }
     }

   if(!file_exists($this->_cacheDir.'settings.php'))
    {
     $this->_createCacheSettingsFile();
    }
   }

  private function _createCacheSettingsFile()
   {
    $content  = "<?php\n";
    $content .= '$settings[\'session_prefix\'] = \''.$this->_settings['session_prefix'].'\';'."\n";
    $content .= '$settings[\'index_page\'] = \''.$this->_settings['index_page'].'\';'."\n";
    #$content .= '$settings[\'caching\'] = '.$this->_settings['caching'].';'."\n";
    $content .= '?'.'>';
    $fp = @fopen($this->_cacheDir.'settings.php', 'w');
    @flock($fp, 2);
    @fwrite($fp, $content);
    @flock($fp, 3);
    @fclose($fp);
   }

  public function clear($page=false)
   {
    if(!$page)
     {
      // delete all cache files (settings.php and *.cache):
      foreach(glob($this->_cacheDir.'{settings.php,*.cache}', GLOB_BRACE) as $cacheFile)
       {
        @unlink($cacheFile);
       }
     }
    else
     {<commit_msg>Fix PHP warning: invalid argument for foreach, when cache dir is empty and argument is bool:false<commit_after><?php
class Cache
 {
  #const CLEAR_INCLUDE_PAGE = true;
  public $doCaching = true;
  public $autoClear = true;
  public $cacheId = false;
  private $_cacheDir;
  private $_settings;

  public function __construct($cacheDir, $settings)
   {
    $this->_cacheDir = $cacheDir;
    $this->_settings = $settings;
   }

  public function createCacheContent($content, $content_type, $charset)
   {
    $cacheContent = '<?php
header(\'Last-Modified: ' . gmdate("D, d M Y H:i:s",time()) . ' GMT\');
header(\'Cache-Control: public\');
if(isset($_SERVER[\'HTTP_IF_MODIFIED_SINCE\']) && '.time().' <= strtotime($_SERVER[\'HTTP_IF_MODIFIED_SINCE\']))
{
header(\'HTTP/1.1 304 Not Modified\');
exit;
}
else
{
';
    if(function_exists('xgzencode')) $cacheContent .= 'if(isset($_SERVER[\'HTTP_ACCEPT_ENCODING\']) && strpos($_SERVER[\'HTTP_ACCEPT_ENCODING\'], \'gzip\')!==false)
{
header(\'Content-Encoding: gzip\');
header(\'Content-Type: '.$content_type.'; charset='.$charset.'\'); ?'.'>'.gzencode($content, 9).'<?php
}
else
{
header(\'Content-Type: '.$content_type.'; charset='.$charset.'\'); ?'.'>'.$content.'<?php
}';
    else $cacheContent .= 'header(\'Content-Type: '.$content_type.'; charset='.$charset.'\'); ?'.'>'.$content.'<?php
';
$cacheContent .= '}
?>';
    return $cacheContent;
   }

  public function createChacheFile($content)
   {
    if($this->cacheId && $this->doCaching)
     {
      #$cacheFile = $this->_cacheDir . str_replace('/','%',$this->cacheId).'.cache';
      $cacheFile = $this->_cacheDir . rawurlencode(strtolower($this->cacheId)).'.cache';
      if(!file_exists($cacheFile))
       {
        $content = str_replace('<?xml','<?php echo \'<?xml\'; ?>', $content);
        $fp = @fopen($cacheFile, 'w');
        @flock($fp, 2);
        @fwrite($fp, $content);
        @flock($fp, 3);
        @fclose($fp);
       }
     }

   if(!file_exists($this->_cacheDir.'settings.php'))
    {
     $this->_createCacheSettingsFile();
    }
   }

  private function _createCacheSettingsFile()
   {
    $content  = "<?php\n";
    $content .= '$settings[\'session_prefix\'] = \''.$this->_settings['session_prefix'].'\';'."\n";
    $content .= '$settings[\'index_page\'] = \''.$this->_settings['index_page'].'\';'."\n";
    #$content .= '$settings[\'caching\'] = '.$this->_settings['caching'].';'."\n";
    $content .= '?'.'>';
    $fp = @fopen($this->_cacheDir.'settings.php', 'w');
    @flock($fp, 2);
    @fwrite($fp, $content);
    @flock($fp, 3);
    @fclose($fp);
   }

  public function clear($page=false)
   {
    if(!$page)
     {
      // delete all cache files (settings.php and *.cache):
         $cacheFiles = glob($this->_cacheDir . '{settings.php,*.cache}', GLOB_BRACE);
         if ($cacheFiles) {
             foreach ($cacheFiles as $cacheFile) {
                 @unlink($cacheFile);
             }
      }
     }
    else
     {
{'fraction_non_alphanumeric': 0.2318941504178273, 'fraction_numerical': 0.003481894150417827, 'mean_word_length': 3.3555724033358607, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3851540', 'n_tokens_mistral': 2057, 'n_tokens_neox': 1994, 'n_words': 319}