<commit_before><?php

ob_start();

class SSImageCache {

  const memory_value = 128;

  /**
   * Stores the image source given for reference
   */
  public $image_src;

  /**
   * If the file is remote or not
   */
  public $is_remote;

  /**
   * Allow the user to set the options for the setup
   */
  public $options;

  /**
   * The location of the cached images directory
   */
  public $cached_image_directory;

  /**
   * The name of the cached file
   */
  public $cached_filename;

  /**
   * Stores the server's version of the GD Library, if enabled
   */
  protected $gd_version;

  /**
   * The memory limit currently established on the server
   */
  protected $memory_limit;

  /**
   * The file mime type
   */
  protected $file_mime_type;

  /**
   * The extension of the file
   */
  protected $file_extension;

  /**
   * The original size of the file
   */
  protected $local_image_src;

  /**
   * The original size of the file
   */
  protected $src_filesize;

  /**
   * The extension of the file
   */
  protected $cached_filesize;

  public function cache( $image )
  {
    if( ! is_string( $image ) )
      $this->error( 'Image source given must be a string.' );

    $this->image_src = $image;
    $this->pre_set_class_vars();

    // If the image hasn't been server up at this point, fetch, compress, cache, and return
    if( $this->cached_file_exists() ) {
      $this->src_filesize = filesize( $this->image_src );
      $this->cached_filesize = filesize( $this->cached_filename );
      if( $this->src_filesize < $this->cached_filesize ) {
        return $this->docroot_to_url( $this->image_src );
      }
      return $this->docroot_to_url();
    }
    if($this->is_remote) {
      $this->download_image();
    }
    if( ! $this->fetch_image() )
      $this->error( 'Could not copy image resource.' );
    $this->src_filesize = filesize( $this->image_src );
    $this->cached_filesize = filesize( $this->cached_filename );
    if( $this->src_filesize < $this->cached_filesize ) {
      return $this->docroot_to_url( $this->image_src );
    }
    return $this->docroot_to_url();
  }

  /**
   * Constructor function
   *
   * @param array $options Options include the keys 'echo' (boolean) and 'cache_time' (integer).  'cache_time' is currently not employed, but in place for future reference.
   * @return object Returns the class object for the user to reference it in the future.
   */
  public function __construct( $options = array() )
  {<commit_msg>se a imagem não passar pelo method fix, é a adicionado o ? + hash da imagem depois do nome do arquivo, para quando outra imagem sobrescrever essa, ela não fica cacheada no browser, pq os nomes dos arquivos são diferentes.<commit_after><?php

ob_start();

class SSImageCache {

  const memory_value = 128;

  /**
   * Stores the image source given for reference
   */
  public $image_src;

  /**
   * If the file is remote or not
   */
  public $is_remote;

  /**
   * Allow the user to set the options for the setup
   */
  public $options;

  /**
   * The location of the cached images directory
   */
  public $cached_image_directory;

  /**
   * The name of the cached file
   */
  public $cached_filename;

  /**
   * Stores the server's version of the GD Library, if enabled
   */
  protected $gd_version;

  /**
   * The memory limit currently established on the server
   */
  protected $memory_limit;

  /**
   * The file mime type
   */
  protected $file_mime_type;

  /**
   * The extension of the file
   */
  protected $file_extension;

  /**
   * The original size of the file
   */
  protected $local_image_src;

  /**
   * The original size of the file
   */
  protected $src_filesize;

  /**
   * The extension of the file
   */
  protected $cached_filesize;

  public function cache( $image )
  {
    if( ! is_string( $image ) )
      $this->error( 'Image source given must be a string.' );

    $this->image_src = $image;
    $this->pre_set_class_vars();

    // If the image hasn't been server up at this point, fetch, compress, cache, and return
    if( $this->cached_file_exists() ) {
      $this->src_filesize = filesize( $this->image_src );
      $this->cached_filesize = filesize( $this->cached_filename );
      if( $this->src_filesize < $this->cached_filesize ) {
        return $this->docroot_to_url( $this->image_src . '?' . sha1_file($this->image_src) );
      }
      return $this->docroot_to_url();
    }
    if($this->is_remote) {
      $this->download_image();
    }
    if( ! $this->fetch_image() )
      $this->error( 'Could not copy image resource.' );
    $this->src_filesize = filesize( $this->image_src );
    $this->cached_filesize = filesize( $this->cached_filename );
    if( $this->src_filesize < $this->cached_filesize ) {
      return $this->docroot_to_url( $this->image_src . '?' . sha1_file($this->image_src) );
    }
    return $this->docroot_to_url();
  }

  /**
   * Constructor function
   *
   * @param array $options Options include the keys 'echo' (boolean) and 'cache_time' (integer).  'cache_time' is currently not employed, but in place for future reference.
   * @return object Returns the class object for the user to reference it in the future.
   */
  public function __construct( $options = array() )
  {
{'fraction_non_alphanumeric': 0.12395277989337396, 'fraction_numerical': 0.0015232292460015233, 'mean_word_length': 2.834306569343066, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2058350', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1654, 'n_words': 500}