<commit_before><?php
/*****************************************************************************
 * This file regroups functions for handling non-http images when running
 * camptocamp on https. The goal is to prevent mixed content warnings.
 ****************************************************************************/

if (!defined('PUN_ROOT'))
    exit('The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.');

@include PUN_ROOT.'config.php';

if (!defined('PUN'))
    exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run <a href="install.php">install.php</a> to install PunBB first.');

//
// Check if a url is available on https
//
function is_secure_url($url)
{
  return (substr($url, 0, 8) === 'https://' || substr($url, 0, 2) === '//');
}

//
// Check if we are running on https
//
function https_enabled()
{
  return (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ||
         !empty($_SERVER["HTTPS"]);
}

//
// Check if camo enabled
//
function camo_enabled()
{
  global $use_camo;

  return (bool) $use_camo;
}

//
// Hexencode data
//
function hexencode($data)
{
  $ascii = unpack("C*", $data);
  $retval = '';
  foreach ($ascii as $v) {
    $retval .= sprintf("%02x", $v);
  }
  return $retval;
}

//
// Generate camo url
//
function camo_url($url)
{
  global $camo_url, $camo_key;

  $hash = hash_hmac('sha1', $url, $camo_key);
  return $camo_url . $hash . '/' . hexencode($url);<commit_msg>use php bin2hex<commit_after><?php
/*****************************************************************************
 * This file regroups functions for handling non-http images when running
 * camptocamp on https. The goal is to prevent mixed content warnings.
 ****************************************************************************/

if (!defined('PUN_ROOT'))
    exit('The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.');

@include PUN_ROOT.'config.php';

if (!defined('PUN'))
    exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run <a href="install.php">install.php</a> to install PunBB first.');

//
// Check if a url is available on https
//
function is_secure_url($url)
{
  return (substr($url, 0, 8) === 'https://' || substr($url, 0, 2) === '//');
}

//
// Check if we are running on https
//
function https_enabled()
{
  return (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ||
         !empty($_SERVER["HTTPS"]);
}

//
// Check if camo enabled
//
function camo_enabled()
{
  global $use_camo;

  return (bool) $use_camo;
}

//
// Generate camo url
//
function camo_url($url)
{
  global $camo_url, $camo_key;

  $hash = hash_hmac('sha1', $url, $camo_key);
  return $camo_url . $hash . '/' . bin2hex($url);
{'fraction_non_alphanumeric': 0.2628430682617875, 'fraction_numerical': 0.0049261083743842365, 'mean_word_length': 4.255083179297597, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '6617458', 'n_tokens_mistral': 918, 'n_tokens_neox': 886, 'n_words': 254}