<commit_before><?php
/**
 * Utility class of static methods for sfJqueryValdiationPlugin
 *
 * Some methods are based on code by <NAME> in sfCombine
 *
 * @package     sfJqueryValidationPlugin
 * @subpackage  sfJqueryValidationUtility
 * @author      <NAME> <<EMAIL>>
 */
class sfJqueryValidationUtility
{
  /**
   * Send GZip headers if possible
   *
   * @author  <NAME>
   * @return  void
   */
  static public function setGzip()
  {
    // gzip compression
    if (
      sfConfig::get('app_sfJqueryValidationPlugin_gzip', true)
      &&
      !self::_checkGzipFail()
    )
    {
      ob_start("ob_gzhandler");
    }
  }

  /**
   * Send cache headers if possible.
   *
   * @author  <NAME>
   * @param   sfResponse $response
   * @return  void
   */
  static public function setCacheHeaders($response)
  {

    $max_age = sfConfig::get(
      'app_sfJqueryValidationPlugin_client_cache_max_age', false
    );

    if ($max_age !== false)
    {
      $lifetime = $max_age * 86400; // 24*60*60
      $response->addCacheControlHttpHeader('max-age', $lifetime);
      $response->setHttpHeader('Pragma', null, false);
      $response->setHttpHeader('Expires', null, false);
    }
  }

  /**
   * Check whether we can send gzip
   * 
   * @author  <NAME>
   * @return  bool
   */
  static protected function _checkGzipFail()
  {
    $userAgent = $_SERVER['HTTP_USER_AGENT'];

    if (strpos($userAgent, 'Mozilla/4.0 (compatible; MSIE ') !== 0 
    || strpos($userAgent, 'Opera') !== false) {
      return false;
    }
    
    $version = floatval(substr($userAgent, 30));

    return $version < 6
      || ($version == 6 && strpos($userAgent, 'SV1') === false);
  }

  static public function minify($javascript)
  {
    if (
      sfConfig::get('app_sfJqueryValidationPlugin_minify')
      &&
      sfConfig::get('app_sfJqueryValidationPlugin_minify_method')
      &&
      is_callable(sfConfig::get('app_sfJqueryValidationPlugin_minify_method'))
    )
    {
      $javascript = call_user_func(
        sfConfig::get('app_sfJqueryValidationPlugin_minify_method'),
        $javascript,
        sfConfig::get(
          'app_sfJqueryValidationPlugin_minify_method_options',
          array()
        )
      );
    }

    return $javascript;
  }
}
<commit_msg>updated cache methods<commit_after><?php
/**
 * Utility class of static methods for sfJqueryValdiationPlugin
 *
 * Some methods are based on code by <NAME> in sfCombine
 *
 * @package     sfJqueryValidationPlugin
 * @subpackage  sfJqueryValidationUtility
 * @author      <NAME> <<EMAIL>>
 */
class sfJqueryValidationUtility
{
  /**
   * Send GZip headers if possible
   *
   * @author  <NAME>
   * @return  void
   */
  static public function setGzip()
  {
    // gzip compression
    if (
      sfConfig::get('app_sfJqueryValidationPlugin_gzip', true)
      &&
      !self::_checkGzipFail()
    )
    {
      ob_start("ob_gzhandler");
    }
  }

  /**
   * Send cache headers if possible.
   *
   * @author  <NAME>
   * @param   sfResponse $response
   * @return  void
   */
  static public function setCacheHeaders($response)
  {

    $max_age = sfConfig::get(
      'app_sfJqueryValidationPlugin_client_cache_max_age', false
    );

    if ($max_age !== false)
    {
      $lifetime = $max_age * 86400; // 24*60*60
      $response->addCacheControlHttpHeader('max-age', $lifetime);
      $response->setHttpHeader(
        'Pragma',
        sfConfig::get('app_sfJqueryValidationPlugin_pragma_header', 'public')
      );
      $response->setHttpHeader(
        'Expires', $response->getDate(time() + $lifetime)
      );
    }
  }

  /**
   * Check whether we can send gzip
   * 
   * @author  <NAME>
   * @return  bool
   */
  static protected function _checkGzipFail()
  {
    $userAgent = $_SERVER['HTTP_USER_AGENT'];

    if (strpos($userAgent, 'Mozilla/4.0 (compatible; MSIE ') !== 0 
    || strpos($userAgent, 'Opera') !== false) {
      return false;
    }
    
    $version = floatval(substr($userAgent, 30));

    return $version < 6
      || ($version == 6 && strpos($userAgent, 'SV1') === false);
  }

  static public function minify($javascript)
  {
    if (
      sfConfig::get('app_sfJqueryValidationPlugin_minify')
      &&
      sfConfig::get('app_sfJqueryValidationPlugin_minify_method')
      &&
      is_callable(sfConfig::get('app_sfJqueryValidationPlugin_minify_method'))
    )
    {
      $javascript = call_user_func(
        sfConfig::get('app_sfJqueryValidationPlugin_minify_method'),
        $javascript,
        sfConfig::get(
          'app_sfJqueryValidationPlugin_minify_method_options',
          array()
        )
      );
    }

    return $javascript;
  }
}

{'fraction_non_alphanumeric': 0.1299204129920413, 'fraction_numerical': 0.008173800817380082, 'mean_word_length': 2.777416734362307, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 24, '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': '4031777', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1507, 'n_words': 278}