<commit_before><?php

class EIApps {
  private function println($s) {
    printf("%s\n",$s);
  }

  private static function expand_app_ids($app_id) {
    if ( gettype( $app_id ) == "array" ) {
      $app_ids = $app_id;
    } else if ( $app_id == "_ei_all" ) {
      $app_ids = EIConfig::get_appIds();
    } else {
      $app_ids =  array( $app_id );
    }

    return $app_ids;
  }


  static function get_app_info( $app_id ) {
      $app_ids = EIApps::expand_app_ids($app_id);
      $out = '<apps>';
    foreach ($app_ids as $id ) {
      if(EIConfig::get_appVisible( $id )== "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_appInfoXML( $id )->asXML();
	$out .= '</app>';
      }
    }
     $out .= '</apps>';

    return $out;
  }

  static function get_app_help( $app_id ) {
      $app_ids = EIApps::expand_app_ids($app_id);
      $out = '<apps>';
    foreach ($app_ids as $id ) {
      if(EIConfig::get_appVisible( $id )== "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_apphelpXML( $id )->asXML();
	$out .= '</app>';
      }
    }
     $out .= '</apps>';

    return $out;
  }

  static function get_app_parameters( $app_id ) {
    $app_ids = EIApps::expand_app_ids($app_id);
    $out = ' <apps> ';
    foreach ($app_ids as $id ) {
      if(EIConfig::get_appVisible( $id )== "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_appParametersXML( $id )->asXML();
	$out .= EIConfig::get_appProfilesXML( $id )->asXML();
	$out .= '</app>';
      }
    }
    $out .= ' </apps> '; 

    return $out;
  }

  static function get_app_profiles( $app_id ) {
    $app_ids = EIApps::expand_app_ids($app_id);
    $out = ' <apps> ';
    foreach ($app_ids as $id ) {
      if(EIConfig::get_appVisible( $id )== "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_appProfilesXML( $id )->asXML();
	$out .= '</app>';
      }
    }
    $out .= ' </apps> '; 

    return $out;
  }

  static function get_app_details( $app_id ) {
    $app_ids = EIApps::expand_app_ids($app_id);
    $out = '<apps>';
    foreach ( $app_ids as $id ) {
      if(EIConfig::get_appVisible( $id ) == "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_appInfoXML( $id )->asXML();
	$out .= EIConfig::get_appHelpXML( $id )->asXML();
	$out .= EIConfig::get_appParametersXML( $id )->asXML();
	$out .= EIConfig::get_appProfilesXML( $id )->asXML();
	$out .= '</app>';
      }
    }
    $out .= '</apps>'; 

    return $out;
  }


  static function execute( $app_id, $parameters ) {
    $execInfo = EIConfig::get_appExecXML($app_id);
    $output = "";
    $output = EIApps::execute_cmdline($app_id, $parameters);
    return $output;
  }

  private static function token($length) {
    $characters = '<KEY>IJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789';
    return substr(str_shuffle($characters), 0, $length);
  }

  static function execute_cmdline( $app_id, $parameters ) {
    $execInfo = EIConfig::get_appExecXML($app_id);
    $sandboxProps = EIConfig::get_sandboxProps();
    $pAuxy = (EIConfig::get_appParametersARRAY($app_id));
    $paramsArr = $pAuxy["parameters"];

    // prefix to be attached to each parameter anme
    $param_prefix = "-";
    if( $paramsArr["@attr"] && array_key_exists("prefix",$paramsArr["@attr"])) 
	$param_prefix = $paramsArr["@attr"]["prefix"];

    // boolean to check compatible parameters or not
    $param_check = false;
    if( $paramsArr["@attr"] && array_key_exists("check",$paramsArr["@attr"]))
	$param_check = $paramsArr["@attr"]["check"];

    // the parameters template
    if ( $execInfo->cmdlineapp ) {
      $cmdline =  (string) $execInfo->cmdlineapp;
    } else {
      throw new Exception("Could not find environment cmdlineapp for '" 
			  . $app_id . "'");
    }
    // session ID
    //
    $sessiondir_str = sys_get_temp_dir()."/easyinterface_sessions/";
    $sessionid_str = EIApps::getSessionData();

    if (!file_exists($sessiondir_str)) {
      mkdir($sessiondir_str, 0755);
    }

    $sessiondir_str  .= $sessionid_str;
    mkdir($sessiondir_str,0755);
    // client ID
    //
    $clientid_str = "";
    if ( array_key_exists( '_ei_clientid', $parameters ) ) {    
      $clientid_str = $parameters['_ei_clientid'];
      unset( $parameters['_ei_clientid'] );
    }

    // outformat 
    //
    $outformat_str = "txt";
    if ( array_key_exists( '_ei_outformat', $parameters ) ) {    
      $outformat_str = $parameters['_ei_outformat'];
      unset( $parameters['_ei_outformat'] );
    }
    // files
    //   
    $files_str = "";
    $root_str = "";
    $stream_str = "";
    $execid_str = EIApps::token(5);

    // the temporal directory has the form
    //
    //    easyinterface_VWXYZ/_ei_files 
    //
    // where VWXYZ are some random characters generated by php. In
    // unix based systems, this directory is typically placed in
    // /tmp. In Windows it is placed in temp. 
    // 
    // **IMPORTANT** The use of _ei_files is essential, so clients
    // can reconstruct file names easily (i.e., whatever comes after
    // _ei_files is the name passed by the client)
    
    $aux = sys_get_temp_dir()."/easyinterface_".$execid_str; 
    $dir = str_replace("\\", "/", $aux);
    unset($aux);
    mkdir($dir, 0755);
    $filespath_str = $dir . "/_ei_files";
    mkdir($filespath_str, 0755);
    $dir_str = $dir . "/_ei_stream";
    mkdir($dir_str, 0755);
    $dir_str = $dir . "/_ei_tmp";
    mkdir($dir_str, 0755);
    $dir_str = $dir . "/_ei_download";
    mkdir($dir_str, 0755);
    $root_str = $dir;
    echo $filespath_str;
    if ( array_key_exists( '_ei_files', $parameters ) ) {    
      EIApps::build_directories($files_str,$filespath_str,$parameters);
      unset( $parameters['_ei_files'] );
    }


    // outline
    //
    $outline_str = "";
    if ( array_key_exists('_ei_outline',$parameters) ) {<commit_msg>minor error solved<commit_after><?php

class EIApps {
  private function println($s) {
    printf("%s\n",$s);
  }

  private static function expand_app_ids($app_id) {
    if ( gettype( $app_id ) == "array" ) {
      $app_ids = $app_id;
    } else if ( $app_id == "_ei_all" ) {
      $app_ids = EIConfig::get_appIds();
    } else {
      $app_ids =  array( $app_id );
    }

    return $app_ids;
  }


  static function get_app_info( $app_id ) {
      $app_ids = EIApps::expand_app_ids($app_id);
      $out = '<apps>';
    foreach ($app_ids as $id ) {
      if(EIConfig::get_appVisible( $id )== "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_appInfoXML( $id )->asXML();
	$out .= '</app>';
      }
    }
     $out .= '</apps>';

    return $out;
  }

  static function get_app_help( $app_id ) {
      $app_ids = EIApps::expand_app_ids($app_id);
      $out = '<apps>';
    foreach ($app_ids as $id ) {
      if(EIConfig::get_appVisible( $id )== "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_apphelpXML( $id )->asXML();
	$out .= '</app>';
      }
    }
     $out .= '</apps>';

    return $out;
  }

  static function get_app_parameters( $app_id ) {
    $app_ids = EIApps::expand_app_ids($app_id);
    $out = ' <apps> ';
    foreach ($app_ids as $id ) {
      if(EIConfig::get_appVisible( $id )== "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_appParametersXML( $id )->asXML();
	$out .= EIConfig::get_appProfilesXML( $id )->asXML();
	$out .= '</app>';
      }
    }
    $out .= ' </apps> '; 

    return $out;
  }

  static function get_app_profiles( $app_id ) {
    $app_ids = EIApps::expand_app_ids($app_id);
    $out = ' <apps> ';
    foreach ($app_ids as $id ) {
      if(EIConfig::get_appVisible( $id )== "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_appProfilesXML( $id )->asXML();
	$out .= '</app>';
      }
    }
    $out .= ' </apps> '; 

    return $out;
  }

  static function get_app_details( $app_id ) {
    $app_ids = EIApps::expand_app_ids($app_id);
    $out = '<apps>';
    foreach ( $app_ids as $id ) {
      if(EIConfig::get_appVisible( $id ) == "true"){
	$out .= '<app id=\'' . $id . '\'>';
	$out .= EIConfig::get_appInfoXML( $id )->asXML();
	$out .= EIConfig::get_appHelpXML( $id )->asXML();
	$out .= EIConfig::get_appParametersXML( $id )->asXML();
	$out .= EIConfig::get_appProfilesXML( $id )->asXML();
	$out .= '</app>';
      }
    }
    $out .= '</apps>'; 

    return $out;
  }


  static function execute( $app_id, $parameters ) {
    $execInfo = EIConfig::get_appExecXML($app_id);
    $output = "";
    $output = EIApps::execute_cmdline($app_id, $parameters);
    return $output;
  }

  private static function token($length) {
    $characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789';
    return substr(str_shuffle($characters), 0, $length);
  }

  static function execute_cmdline( $app_id, $parameters ) {
    $execInfo = EIConfig::get_appExecXML($app_id);
    $sandboxProps = EIConfig::get_sandboxProps();
    $pAuxy = (EIConfig::get_appParametersARRAY($app_id));
    $paramsArr = $pAuxy["parameters"];

    // prefix to be attached to each parameter anme
    $param_prefix = "-";
    if( $paramsArr["@attr"] && array_key_exists("prefix",$paramsArr["@attr"])) 
	$param_prefix = $paramsArr["@attr"]["prefix"];

    // boolean to check compatible parameters or not
    $param_check = false;
    if( $paramsArr["@attr"] && array_key_exists("check",$paramsArr["@attr"]))
	$param_check = $paramsArr["@attr"]["check"];

    // the parameters template
    if ( $execInfo->cmdlineapp ) {
      $cmdline =  (string) $execInfo->cmdlineapp;
    } else {
      throw new Exception("Could not find environment cmdlineapp for '" 
			  . $app_id . "'");
    }
    // session ID
    //
    $sessiondir_str = sys_get_temp_dir()."/easyinterface_sessions/";
    $sessionid_str = EIApps::getSessionData();

    if (!file_exists($sessiondir_str)) {
      mkdir($sessiondir_str, 0755);
    }

    $sessiondir_str  .= $sessionid_str;
    mkdir($sessiondir_str,0755);
    // client ID
    //
    $clientid_str = "";
    if ( array_key_exists( '_ei_clientid', $parameters ) ) {    
      $clientid_str = $parameters['_ei_clientid'];
      unset( $parameters['_ei_clientid'] );
    }

    // outformat 
    //
    $outformat_str = "txt";
    if ( array_key_exists( '_ei_outformat', $parameters ) ) {    
      $outformat_str = $parameters['_ei_outformat'];
      unset( $parameters['_ei_outformat'] );
    }
    // files
    //   
    $files_str = "";
    $root_str = "";
    $stream_str = "";
    $execid_str = EIApps::token(5);

    // the temporal directory has the form
    //
    //    easyinterface_VWXYZ/_ei_files 
    //
    // where VWXYZ are some random characters generated by php. In
    // unix based systems, this directory is typically placed in
    // /tmp. In Windows it is placed in temp. 
    // 
    // **IMPORTANT** The use of _ei_files is essential, so clients
    // can reconstruct file names easily (i.e., whatever comes after
    // _ei_files is the name passed by the client)
    
    $aux = sys_get_temp_dir()."/easyinterface_".$execid_str; 
    $dir = str_replace("\\", "/", $aux);
    unset($aux);
    mkdir($dir, 0755);
    $filespath_str = $dir . "/_ei_files";
    mkdir($filespath_str, 0755);
    $dir_str = $dir . "/_ei_stream";
    mkdir($dir_str, 0755);
    $dir_str = $dir . "/_ei_tmp";
    mkdir($dir_str, 0755);
    $dir_str = $dir . "/_ei_download";
    mkdir($dir_str, 0755);
    $root_str = $dir;

    if ( array_key_exists( '_ei_files', $parameters ) ) {    
      EIApps::build_directories($files_str,$filespath_str,$parameters);
      unset( $parameters['_ei_files'] );
    }


    // outline
    //
    $outline_str = "";
    if ( array_key_exists('_ei_outline',$parameters) ) {
{'fraction_non_alphanumeric': 0.18590730289037113, 'fraction_numerical': 0.006670087224217547, 'mean_word_length': 2.8983333333333334, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 66, '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': '6154776', 'n_tokens_mistral': 4458, 'n_tokens_neox': 4302, 'n_words': 832}