<commit_before><?php
class Utility
{
  private $isMobile, $licenses;

  public function __construct() { }

  public function callApis($apisToCall, $apiObj = null)
  {
    if($apiObj === null)
      $apiObj = getApi();

    $params = array();
    if(!empty($apisToCall))
    {
      foreach($apisToCall as $name => $api)
      {
        $apiParts = explode(' ', $api);
        $apiMethod = strtoupper($apiParts[0]);
        $apiMethod = $apiMethod == 'GET' ? EpiRoute::httpGet : EpiRoute::httpPost;
        $apiUrlParts = parse_url($apiParts[1]);
        $apiParams = array();
        if(isset($apiUrlParts['query']))
          parse_str($apiUrlParts['query'], $apiParams);

        $response = $apiObj->invoke($apiUrlParts['path'], $apiMethod, array("_{$apiMethod}" => $apiParams));
        $params[$name] = $response['result'];

      }
    }
    return $params;
  }

  public function decrypt($string, $secret = null, $salt = null)
  {
    if($secret === null)
      $secret = getConfig()->get('secrets')->secret;

    if($salt === null)
      $salt = $this->getBaseDir();

    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $key = md5(sprintf('%s~%s', $salt, $secret));

    $string = base64_decode($string);
    $decryptedString = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_ECB, $iv));
    return $decryptedString;
  }

  public function diagnosticLine($status, $message)
  {
    $status = (bool)$status;
    $label = $status ? 'success' : 'failure';
    return array('status' => $status, 'label' => $label, 'message' => $message);
  }

  public function encrypt($string, $secret = null, $salt = null)
  {
    if($secret === null)
      $secret = getConfig()->get('secrets')->secret;

    if($salt === null)
      $salt = $this->getBaseDir();

    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $key = md5(sprintf('%s~%s', $salt, $secret));

    $encryptedString = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_ECB, $iv);
    return base64_encode($encryptedString);
  }

  public function getBaseDir()
  {
    return dirname(dirname(dirname(__FILE__)));
  }

  public function getLicenses($selected = null)
  {
    if(!$this->licenses)
    {
      $this->licenses = array(
        '' => array('name' => 'All Rights Reserved', 'description' => ''),
        'CC BY' => array('name' => 'Attribution', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by/3.0'),
        'CC BY-SA' => array('name' => 'Attribution-ShareAlike', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-sa/3.0'),
        'CC BY-ND' => array('name' => 'Attribution-NoDerivs', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-nd/3.0'),
        'CC BY-NC' => array('name' => 'Attribution-NonCommercial', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-nc/3.0' ),
        'CC BY-NC-SA' => array('name' => 'Attribution-NonCommercial-ShareAlike', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-nc-sa/3.0'),
        'CC BY-NC-ND' => array('name' => 'Attribution-NonCommercial-NoDerivs', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-nc-nd/3.0')
      );
    }

    foreach($this->licenses as $key => $value)
      $this->licenses[$key]['selected'] = ($key == $selected);

    if($selected === null)
      $this->licenses['']['selected'] = true;

    return $this->licenses;
  }

  public function dateLong($ts, $write = true)
  {
    if(empty($ts))
      return 'Unknown';
    return $this->returnValue(date('l, F jS, Y \a\t g:ia', $ts), $write);<commit_msg>Adding getHost method to the Utility model. #723<commit_after><?php
class Utility
{
  private $isMobile, $licenses;

  public function __construct() { }

  public function callApis($apisToCall, $apiObj = null)
  {
    if($apiObj === null)
      $apiObj = getApi();

    $params = array();
    if(!empty($apisToCall))
    {
      foreach($apisToCall as $name => $api)
      {
        $apiParts = explode(' ', $api);
        $apiMethod = strtoupper($apiParts[0]);
        $apiMethod = $apiMethod == 'GET' ? EpiRoute::httpGet : EpiRoute::httpPost;
        $apiUrlParts = parse_url($apiParts[1]);
        $apiParams = array();
        if(isset($apiUrlParts['query']))
          parse_str($apiUrlParts['query'], $apiParams);

        $response = $apiObj->invoke($apiUrlParts['path'], $apiMethod, array("_{$apiMethod}" => $apiParams));
        $params[$name] = $response['result'];

      }
    }
    return $params;
  }

  public function decrypt($string, $secret = null, $salt = null)
  {
    if($secret === null)
      $secret = getConfig()->get('secrets')->secret;

    if($salt === null)
      $salt = $this->getBaseDir();

    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $key = md5(sprintf('%s~%s', $salt, $secret));

    $string = base64_decode($string);
    $decryptedString = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_ECB, $iv));
    return $decryptedString;
  }

  public function diagnosticLine($status, $message)
  {
    $status = (bool)$status;
    $label = $status ? 'success' : 'failure';
    return array('status' => $status, 'label' => $label, 'message' => $message);
  }

  public function encrypt($string, $secret = null, $salt = null)
  {
    if($secret === null)
      $secret = getConfig()->get('secrets')->secret;

    if($salt === null)
      $salt = $this->getBaseDir();

    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
    $key = md5(sprintf('%s~%s', $salt, $secret));

    $encryptedString = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_ECB, $iv);
    return base64_encode($encryptedString);
  }

  public function getBaseDir()
  {
    return dirname(dirname(dirname(__FILE__)));
  }

  public function getHost()
  {
    return $_SERVER['HTTP_HOST'];
  }

  public function getLicenses($selected = null)
  {
    if(!$this->licenses)
    {
      $this->licenses = array(
        '' => array('name' => 'All Rights Reserved', 'description' => ''),
        'CC BY' => array('name' => 'Attribution', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by/3.0'),
        'CC BY-SA' => array('name' => 'Attribution-ShareAlike', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-sa/3.0'),
        'CC BY-ND' => array('name' => 'Attribution-NoDerivs', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-nd/3.0'),
        'CC BY-NC' => array('name' => 'Attribution-NonCommercial', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-nc/3.0' ),
        'CC BY-NC-SA' => array('name' => 'Attribution-NonCommercial-ShareAlike', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-nc-sa/3.0'),
        'CC BY-NC-ND' => array('name' => 'Attribution-NonCommercial-NoDerivs', 'description' => '', 'link' => 'http://creativecommons.org/licenses/by-nc-nd/3.0')
      );
    }

    foreach($this->licenses as $key => $value)
      $this->licenses[$key]['selected'] = ($key == $selected);

    if($selected === null)
      $this->licenses['']['selected'] = true;

    return $this->licenses;
  }

  public function dateLong($ts, $write = true)
  {
    if(empty($ts))
      return 'Unknown';
    return $this->returnValue(date('l, F jS, Y \a\t g:ia', $ts), $write);
{'fraction_non_alphanumeric': 0.19914802981895632, 'fraction_numerical': 0.008919062832800853, 'mean_word_length': 3.5894929749541844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 97, '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': '4206613', 'n_tokens_mistral': 2703, 'n_tokens_neox': 2560, 'n_words': 453}