<commit_before><?php
if (file_exists( dirname(__FILE__) . '/rg2-config.php')) {
  require_once( dirname(__FILE__) . '/rg2-config.php' );
} else {
  echo "Routegadget 2: Configuration file " . dirname(__FILE__) . "/rg2-config.php not found.";
  return;
}

// override allows testing of a local configuration such as c:/xampp/htdocs/rg2
if (file_exists( dirname(__FILE__) . '/rg2-override-config.php')) {
  $override = true;
  require_once ( dirname(__FILE__) . '/rg2-override-config.php');
} else {
  $override = false;
}

if (defined('OVERRIDE_UI_THEME')) {
  $ui_theme = OVERRIDE_UI_THEME;
} else {
  $ui_theme = UI_THEME;
}

if (defined('HEADER_COLOUR')) {
  $header_colour = HEADER_COLOUR;
} else {
  $header_colour = '#002bd9';
}
if (defined('HEADER_TEXT_COLOUR')) {
  $header_text_colour = HEADER_TEXT_COLOUR;
} else {
  $header_text_colour = '#ffffff';
}

if (defined('OVERRIDE_BASE_DIRECTORY')) {
  $json_url = OVERRIDE_BASE_DIRECTORY . "/rg2/rg2api.php";
  if (defined('OVERRIDE_SOURCE_DIRECTORY')) {
    $source_url = OVERRIDE_SOURCE_DIRECTORY . "/rg2";
  } else {
    $source_url = OVERRIDE_BASE_DIRECTORY . "/rg2";
  }
} else {
  $json_url = RG_BASE_DIRECTORY . "/rg2/rg2api.php";
  if (defined('OVERRIDE_SOURCE_DIRECTORY')) {
    $source_url = OVERRIDE_SOURCE_DIRECTORY . "/rg2";
  } else {
    $source_url = RG_BASE_DIRECTORY . "/rg2";
  }
}

if (defined('OVERRIDE_KARTAT_DIRECTORY')) {
  $maps_url = OVERRIDE_KARTAT_DIRECTORY;
} else {
  $maps_url = RG_BASE_DIRECTORY . "/kartat/";
}

// include manager function as parameter for now until we decide the best way forward
if (isset($_GET['manage'])) {
  $manager = TRUE;
  if (defined('OVERRIDE_KARTAT_DIRECTORY')) {
    $manager_url = OVERRIDE_KARTAT_DIRECTORY;
  } else {
    $manager_url = "../kartat/";
  }
  // simple cookie generator! Don't need unique, just need something vaguely random
  $keksi = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"), 0, 20);
  file_put_contents($manager_url."keksi.txt", $keksi.PHP_EOL); 
} else {
  $manager=  FALSE;
}

// include debug function as parameter for now until we decide the best way forward
if (isset($_GET['debug']) || $override) {
  $debug = TRUE;
} else {
  $debug = FALSE;
}

// include language file if requested
if (isset($_GET['lang'])) {
  $lang = $_GET['lang'];
} else {
  if ((defined('START_LANGUAGE'))) {
    $lang = START_LANGUAGE;
  } else {
    $lang = "";
  }
}
$langdir = dirname(__FILE__) . '/lang/';
if (file_exists($langdir.$lang.'.txt')) {
  $dictionary = 'dictionary: {'.PHP_EOL;
  $dictionary .= file_get_contents($langdir.$lang.'.txt').PHP_EOL;
  $dictionary .= '}'.PHP_EOL; 
} else {
  $dictionary = "dictionary: {}".PHP_EOL;
}

// create list of available languages
$languages = "languages: {".PHP_EOL;
foreach(glob($langdir.'??.txt') as $file) {
  // xx is a dummy file to hold the master list of terms
  if ($file != $langdir.'xx.txt') {
    $lines = explode(PHP_EOL, file_get_contents($file));
    $code = "";
    $name = "";
    foreach ($lines as $line) {
      $line = trim($line);
      if (strpos($line, 'code') !== FALSE) {
        $codepos = strpos($line, "'") + 1;
        $code = substr($line, $codepos, 2);
        if ($name !== "") {
          break;
        }
      }
      if (strpos($line, 'language') !== FALSE) {
        $namepos = strpos($line, "'");
        $name = substr($line, $namepos);
        if ($code !== "") {
          break;
        }
      }
    }
    
    if (($code != "") && ($name != "")) {
      $languages .= $code.': '.$name.PHP_EOL;<commit_msg>Avoid explode on PHP_EOL<commit_after><?php
if (file_exists( dirname(__FILE__) . '/rg2-config.php')) {
  require_once( dirname(__FILE__) . '/rg2-config.php' );
} else {
  echo "Routegadget 2: Configuration file " . dirname(__FILE__) . "/rg2-config.php not found.";
  return;
}

// override allows testing of a local configuration such as c:/xampp/htdocs/rg2
if (file_exists( dirname(__FILE__) . '/rg2-override-config.php')) {
  $override = true;
  require_once ( dirname(__FILE__) . '/rg2-override-config.php');
} else {
  $override = false;
}

if (defined('OVERRIDE_UI_THEME')) {
  $ui_theme = OVERRIDE_UI_THEME;
} else {
  $ui_theme = UI_THEME;
}

if (defined('HEADER_COLOUR')) {
  $header_colour = HEADER_COLOUR;
} else {
  $header_colour = '#002bd9';
}
if (defined('HEADER_TEXT_COLOUR')) {
  $header_text_colour = HEADER_TEXT_COLOUR;
} else {
  $header_text_colour = '#ffffff';
}

if (defined('OVERRIDE_BASE_DIRECTORY')) {
  $json_url = OVERRIDE_BASE_DIRECTORY . "/rg2/rg2api.php";
  if (defined('OVERRIDE_SOURCE_DIRECTORY')) {
    $source_url = OVERRIDE_SOURCE_DIRECTORY . "/rg2";
  } else {
    $source_url = OVERRIDE_BASE_DIRECTORY . "/rg2";
  }
} else {
  $json_url = RG_BASE_DIRECTORY . "/rg2/rg2api.php";
  if (defined('OVERRIDE_SOURCE_DIRECTORY')) {
    $source_url = OVERRIDE_SOURCE_DIRECTORY . "/rg2";
  } else {
    $source_url = RG_BASE_DIRECTORY . "/rg2";
  }
}

if (defined('OVERRIDE_KARTAT_DIRECTORY')) {
  $maps_url = OVERRIDE_KARTAT_DIRECTORY;
} else {
  $maps_url = RG_BASE_DIRECTORY . "/kartat/";
}

// include manager function as parameter for now until we decide the best way forward
if (isset($_GET['manage'])) {
  $manager = TRUE;
  if (defined('OVERRIDE_KARTAT_DIRECTORY')) {
    $manager_url = OVERRIDE_KARTAT_DIRECTORY;
  } else {
    $manager_url = "../kartat/";
  }
  // simple cookie generator! Don't need unique, just need something vaguely random
  $keksi = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"), 0, 20);
  file_put_contents($manager_url."keksi.txt", $keksi.PHP_EOL); 
} else {
  $manager=  FALSE;
}

// include debug function as parameter for now until we decide the best way forward
if (isset($_GET['debug']) || $override) {
  $debug = TRUE;
} else {
  $debug = FALSE;
}

// include language file if requested
if (isset($_GET['lang'])) {
  $lang = $_GET['lang'];
} else {
  if ((defined('START_LANGUAGE'))) {
    $lang = START_LANGUAGE;
  } else {
    $lang = "";
  }
}
$langdir = dirname(__FILE__) . '/lang/';
if (file_exists($langdir.$lang.'.txt')) {
  $dictionary = 'dictionary: {'.PHP_EOL;
  $dictionary .= file_get_contents($langdir.$lang.'.txt').PHP_EOL;
  $dictionary .= '}'.PHP_EOL; 
} else {
  $dictionary = "dictionary: {}".PHP_EOL;
}

// create list of available languages
$languages = "languages: {".PHP_EOL;
foreach(glob($langdir.'??.txt') as $file) {
  // xx is a dummy file to hold the master list of terms
  if ($file != $langdir.'xx.txt') {
    $lines = file($file);
    $code = "";
    $name = "";
    foreach ($lines as $line) {
      $line = trim($line);
      if (strpos($line, 'code') !== FALSE) {
        $codepos = strpos($line, "'") + 1;
        $code = substr($line, $codepos, 2);
        if ($name !== "") {
          break;
        }
      }
      if (strpos($line, 'language') !== FALSE) {
        $namepos = strpos($line, "'");
        $name = substr($line, $namepos);
        if ($code !== "") {
          break;
        }
      }
    }
    
    if (($code != "") && ($name != "")) {
      $languages .= $code.': '.$name.PHP_EOL;
{'fraction_non_alphanumeric': 0.17520405291303123, 'fraction_numerical': 0.009569377990430622, 'mean_word_length': 3.500949968334389, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5149333', 'n_tokens_mistral': 2701, 'n_tokens_neox': 2587, 'n_words': 531}