<commit_before><?php
/////////////// Upload SLIDE-PPT CLASS ////////////////
//***********************************************
//************************************************
//**************   CREATED BY  *******************
//************ <NAME>,<EMAIL> **************
///////////////////////////////////////////////////
define('CLOUD_TOKEN','<PASSWORD>');
define('CLOUD_BASE','http://ppthtml2.cloudapp.net/');
define('ORG_APP_DELIM','_');
define('SLIDE_SLAG','preview/slide/');
define('PATH_LOG','C:/Windows/Temp/');
define('FILE_LOG','log_php.txt');
define("PATH_UPLOAD", "upload/");
define("PATH_SLIDERS", "preview/slide/");   //"output_html/sliders_html/"
define("PATH_PPTS", "preview/ppt/");

error_reporting(E_ALL);

class Upload {
  var $state="\n";
  var $fieldname;
  var $type;
  var $upload_dir;
  var $filename;
  var $slider_main_file;
  var $uploaded_file_name;
  var $type_sf_file;//--html,zip,ppt
  var $cloud_toke='???';
  var $action='';
  var $org_id;
  var $app_id;
  var $slide_id;
  var $ppt_session_id;//--sessionId from active SF all
  var $rewrite_ppt;//--what to do with slides: 1- rewrite 0 -add
  var $schema_url;        //--SF soap schema url
  var $send_url;        //--SF soap endpoint post send url
  var $deny_content;    //--deny index.php content
  function __construct($n_fieldname, $n_type, $n_upload_dir) {
    $this->fieldname = $n_fieldname;
    $this->type = $n_type;
    $this->type_arr = array('application/ppt', 'application/pptx', 'application/vnd.ms-powerpoint');
    $this->upload_dir = $n_upload_dir;
    $this->deny_content='<?php  ?><img src="/ctmobile.logo.png" />';
  }
  function show_files() {
    $myDirectory = opendir($this->upload_dir);

    while ($entryName = readdir($myDirectory)) {
      $dirArray[] = $entryName;
    }
    closedir($myDirectory);
    $indexCount = count($dirArray);
    print ("<a href='".CLOUD_BASE."'>Home</a>");
    print ('<h1>Uploaded files list</h1>');
    Print ("$indexCount-2 files<br>\n");

    sort($dirArray);

    print ("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
    print ("<TR><TH>Filename</TH><th>FileExt</th><th>Filesize</th></TR>\n");
    // loop through the array of files and print them all
    for ($index = 0; $index < $indexCount; $index++) {
     $cur_ext= pathinfo(getcwd()."/".$this->upload_dir.$dirArray[$index], PATHINFO_EXTENSION);
     if ( (!isset($_GET['all'])) && ($cur_ext=='zip')) { continue;}
     if ( (!isset($_GET['all'])) && ($cur_ext=='html')){ continue;}
     if ( (!isset($_GET['all'])) && ($cur_ext=='done')){ continue;}
     if ( (!isset($_GET['all'])) && ($cur_ext=='config')){ continue;}

       if (substr("$dirArray[$index]", 0, 1) != ".") { // don't list hidden files

        print ("<TR><TD><a href=\"$this->upload_dir$dirArray[$index]\">$dirArray[$index]</a></td>");
        print ("<td>");

        print ($cur_ext);

        print ("</td>");
        print ("<td>");
        print ((filesize(getcwd()."/".$this->upload_dir.$dirArray[$index])/1000)." kb");
        //print (getcwd()."/".$this->upload_dir.$dirArray[$index]);
        print ("</td>");
        print ("</TR>\n");

      }
    }
    print ("</TABLE>\n");
  }
function unzipFile($name, $dir_file_unzip) {
        $zip = new ZipArchive;
        $res = $zip->open($name);
        if ($res === TRUE) {
          $zip->extractTo($dir_file_unzip);
          $zip->close();
          $this->state .= 'data-unzip-done;';
        }
        else {
          $this->state .= "error-unzip-dir; dir_file_unzip=".$dir_file_unzip;
          error_log(__FUNCTION__.' '.$this->state);
        }
}
function deletePartFiles() {
  try {
    array_map('unlink', glob(PATH_UPLOAD."pt_*_".$this->org_id.ORG_APP_DELIM.$this->app_id.ORG_APP_DELIM."*"));
  } catch (Exception $e) {
      $this->state .= "error-delete-part-files";
      error_log(__FUNCTION__.' '.$this->state);
  }
}
function deleteSlides() {
  if ((isset($_POST['cloud_token']) == false) or ($_POST['cloud_token'] != CLOUD_TOKEN)) {
      echo "error";
      return ;
  }
  if (isset($_POST['slide_token'])) {
      require_once "sftk.php";
      $az_store= new AzureStore();
      if ($az_store->findByToken($_POST['slide_token']) == true) {
          $org_id=$_POST['org_id'];
          $app_id=$_POST['app_id'];
          $dir_to_delete=getcwd().'/preview/ppt/'.$org_id.'/'.$app_id.'/sliders/';
          if (preg_match('/all/i',$_POST['slide_id'])) {

             array_map('unlink', glob($dir_to_delete."*.jpg"));
           } else {
                $slide_del_arr=explod(',',$_POST['slide_id']);
                foreach ($slide_del_arr as $slide_n) {
                   $file_name=$dir_to_delete.'slide_'.$slide_n.'.jpg';
                   unlink($file_name);
                   error_log('DELETED file '.$file_name);
                }
           }
      }
  }
}
function deleteFiles($tp_file) {
   try {
      if ($tp_file=='ppt'){
        $old_dir=getcwd().'/preview/'.$tp_file.'/'.$this->org_id.'/'.$this->app_id;
      }
      if ($tp_file=='slide'){
        $old_dir=getcwd().'/preview/'.$tp_file.'/'.$this->org_id.'/'.$this->app_id.'/'.$this->slide_id;
      }
      $deleted_dir=$old_dir.'-deleted';
      rename($old_dir,$deleted_dir);
   } catch (Exception $e) {<commit_msg>delete slides<commit_after><?php
/////////////// Upload SLIDE-PPT CLASS ////////////////
//***********************************************
//************************************************
//**************   CREATED BY  *******************
//************ <NAME>,Kharkov,<EMAIL> **************
///////////////////////////////////////////////////
define('CLOUD_TOKEN','<PASSWORD>');
define('CLOUD_BASE','http://ppthtml2.cloudapp.net/');
define('ORG_APP_DELIM','_');
define('SLIDE_SLAG','preview/slide/');
define('PATH_LOG','C:/Windows/Temp/');
define('FILE_LOG','log_php.txt');
define("PATH_UPLOAD", "upload/");
define("PATH_SLIDERS", "preview/slide/");   //"output_html/sliders_html/"
define("PATH_PPTS", "preview/ppt/");

error_reporting(E_ALL);

class Upload {
  var $state="\n";
  var $fieldname;
  var $type;
  var $upload_dir;
  var $filename;
  var $slider_main_file;
  var $uploaded_file_name;
  var $type_sf_file;//--html,zip,ppt
  var $cloud_toke='???';
  var $action='';
  var $org_id;
  var $app_id;
  var $slide_id;
  var $ppt_session_id;//--sessionId from active SF all
  var $rewrite_ppt;//--what to do with slides: 1- rewrite 0 -add
  var $schema_url;        //--SF soap schema url
  var $send_url;        //--SF soap endpoint post send url
  var $deny_content;    //--deny index.php content
  function __construct($n_fieldname, $n_type, $n_upload_dir) {
    $this->fieldname = $n_fieldname;
    $this->type = $n_type;
    $this->type_arr = array('application/ppt', 'application/pptx', 'application/vnd.ms-powerpoint');
    $this->upload_dir = $n_upload_dir;
    $this->deny_content='<?php  ?><img src="/ctmobile.logo.png" />';
  }
  function show_files() {
    $myDirectory = opendir($this->upload_dir);

    while ($entryName = readdir($myDirectory)) {
      $dirArray[] = $entryName;
    }
    closedir($myDirectory);
    $indexCount = count($dirArray);
    print ("<a href='".CLOUD_BASE."'>Home</a>");
    print ('<h1>Uploaded files list</h1>');
    Print ("$indexCount-2 files<br>\n");

    sort($dirArray);

    print ("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
    print ("<TR><TH>Filename</TH><th>FileExt</th><th>Filesize</th></TR>\n");
    // loop through the array of files and print them all
    for ($index = 0; $index < $indexCount; $index++) {
     $cur_ext= pathinfo(getcwd()."/".$this->upload_dir.$dirArray[$index], PATHINFO_EXTENSION);
     if ( (!isset($_GET['all'])) && ($cur_ext=='zip')) { continue;}
     if ( (!isset($_GET['all'])) && ($cur_ext=='html')){ continue;}
     if ( (!isset($_GET['all'])) && ($cur_ext=='done')){ continue;}
     if ( (!isset($_GET['all'])) && ($cur_ext=='config')){ continue;}

       if (substr("$dirArray[$index]", 0, 1) != ".") { // don't list hidden files

        print ("<TR><TD><a href=\"$this->upload_dir$dirArray[$index]\">$dirArray[$index]</a></td>");
        print ("<td>");

        print ($cur_ext);

        print ("</td>");
        print ("<td>");
        print ((filesize(getcwd()."/".$this->upload_dir.$dirArray[$index])/1000)." kb");
        //print (getcwd()."/".$this->upload_dir.$dirArray[$index]);
        print ("</td>");
        print ("</TR>\n");

      }
    }
    print ("</TABLE>\n");
  }
function unzipFile($name, $dir_file_unzip) {
        $zip = new ZipArchive;
        $res = $zip->open($name);
        if ($res === TRUE) {
          $zip->extractTo($dir_file_unzip);
          $zip->close();
          $this->state .= 'data-unzip-done;';
        }
        else {
          $this->state .= "error-unzip-dir; dir_file_unzip=".$dir_file_unzip;
          error_log(__FUNCTION__.' '.$this->state);
        }
}
function deletePartFiles() {
  try {
    array_map('unlink', glob(PATH_UPLOAD."pt_*_".$this->org_id.ORG_APP_DELIM.$this->app_id.ORG_APP_DELIM."*"));
  } catch (Exception $e) {
      $this->state .= "error-delete-part-files";
      error_log(__FUNCTION__.' '.$this->state);
  }
}
function deleteSlides() {
  if (($_POST['cloud_token'] != CLOUD_TOKEN)) {
      echo "error";
      return ;
  }
  if (isset($_POST['slide_token'])) {
      require_once "sftk.php";
      $az_store= new AzureStore();
      if ($az_store->findByToken($_POST['slide_token']) == true) {
          $org_id   =$_POST['org_id'];
          $app_id   =$_POST['app_id'];
          $slide_id =$_POST['slide_id'];
          $dir_to_delete=getcwd().'/preview/ppt/'.$org_id.'/'.$app_id.'/sliders/';
          if (preg_match('/all/i',$_POST['slide_id'])) {

             array_map('unlink', glob($dir_to_delete."*.jpg"));
             echo "done";return ;
           } else {
                error_log('TRY DELETED  '.$slide_id);
                $slide_del_arr=explode('_',$slide_id);
                foreach ($slide_del_arr as $slide_n) {
                   $file_name=$dir_to_delete.'slide_'.$slide_n.'.jpg';
                   unlink($file_name);
                   error_log('DELETED file '.$file_name);
                }
                echo "done";return ;
           }
      } else {
             error_log('ERROR INVALID azure slide token '.$_POST['slide_token']);
      }
  } else {
      error_log('ERROR DELETED - no slide_token '.$slide_token);
  }
}
function deleteFiles($tp_file) {
   try {
      if ($tp_file=='ppt'){
        $old_dir=getcwd().'/preview/'.$tp_file.'/'.$this->org_id.'/'.$this->app_id;
      }
      if ($tp_file=='slide'){
        $old_dir=getcwd().'/preview/'.$tp_file.'/'.$this->org_id.'/'.$this->app_id.'/'.$this->slide_id;
      }
      $deleted_dir=$old_dir.'-deleted';
      rename($old_dir,$deleted_dir);
   } catch (Exception $e) {
{'fraction_non_alphanumeric': 0.2485682615924626, 'fraction_numerical': 0.002955847034915943, 'mean_word_length': 2.9002161383285303, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 115, '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': '5348915', 'n_tokens_mistral': 3808, 'n_tokens_neox': 3749, 'n_words': 588}