<commit_before><?php
/**
 * processes_ImportFile.php
 *
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2008 Colosa Inc.23
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email <EMAIL>.
 *
 */

global $RBAC;
$RBAC->requirePermissions('PM_SETUP_ADVANCE');

try {
  //load the variables
  G::LoadClass('plugin');
  if ( ! isset($_FILES['form']['error']['PLUGIN_FILENAME'] ) || $_FILES['form']['error']['PLUGIN_FILENAME'] == 1 ) {
    throw ( new Exception ("There was an error uploading the file, probably the file size if greater than upload_max_filesize parameter in php.ini, please check this parameter and try again." ) );
  }

  //save the file
  if ($_FILES['form']['error']['PLUGIN_FILENAME'] == 0) {
    $filename = $_FILES['form']['name']['PLUGIN_FILENAME'];
    $path     = PATH_DOCUMENT . 'input' . PATH_SEP ;
    $tempName = $_FILES['form']['tmp_name']['PLUGIN_FILENAME'];
    G::uploadFile($tempName, $path, $filename );
  }
  if ( ! $_FILES['form']['type']['PLUGIN_FILENAME'] == 'application/octet-stream')
    throw ( new Exception ( "the uploaded files are invalid, expected 'application/octect-stream mime type file (".  $_FILES['form']['type']['PLUGIN_FILENAME'] . ")" ));


  G::LoadThirdParty( 'pear/Archive','Tar');
  $tar = new Archive_Tar ( $path. $filename);
  $sFileName  = substr($filename,0,strrpos($filename, '.' ));
  $sClassName = substr($filename,0,strpos($filename, '-' ));

  $aFiles = $tar->listContent();
  $bMainFile = false;
  $bClassFile = false;
  foreach ( $aFiles as $key => $val ) {
    if ( $val['filename'] == $sClassName . '.php' ) $bMainFile = true;
    if ( $val['filename'] == $sClassName . PATH_SEP . 'class.' . $sClassName . '.php' ) $bClassFile = true;
  }

  $oPluginRegistry =& PMPluginRegistry::getSingleton();
  $pluginFile = $sClassName . '.php';

  if ( $bMainFile && $bClassFile ) {
    $sAux = $sClassName . 'Plugin';
    $fVersionOld = 0.0;
    if (file_exists(PATH_PLUGINS . $pluginFile)) {
      if (!class_exists($sAux) && !class_exists($sClassName . 'plugin')) {
        include PATH_PLUGINS . $pluginFile;
      }
      if (!class_exists($sAux)) {
        $sAux = $sClassName . 'plugin';
      }
      $oClass = new $sAux($sClassName);
      $fVersionOld = $oClass->iVersion;
      unset($oClass);
    }
    $res = $tar->extract ( $path );
    $sContent = file_get_contents($path . PATH_SEP . $pluginFile);
    $sContent = str_ireplace($sAux, $sAux . '_', $sContent);
    $sContent = str_ireplace('$oPluginRegistry =& PMPluginRegistry::getSingleton();', '', $sContent);
    $sContent = str_ireplace('$oPluginRegistry->registerPlugin(\'' . $sClassName . '\', __FILE__);', '', $sContent);
    //header('Content-Type: text/plain');var_dump($sClassName, $sContent);die;
    file_put_contents($path . PATH_SEP . $pluginFile, $sContent);
    $sAux = $sAux . '_';
    include $path . PATH_SEP . $pluginFile;
    $oClass = new $sAux($sClassName);
    $fVersionNew = $oClass->iVersion;
    if (!isset($oClass->iPMVersion)) {
      $oClass->iPMVersion = 0;
    }
    if ($oClass->iPMVersion > 0) {
      G::LoadClass("system");
      if (System::getVersion() > 0) {
        if ($oClass->iPMVersion > System::getVersion()) {
          //throw new Exception('This plugin needs version ' . $oClass->iPMVersion . ' or higher of ProcessMaker');
        }
      }
    }
    if (!isset($oClass->aDependences)) {
      $oClass->aDependences = null;<commit_msg>BUG 0000 Fix an issue importing enterpriseplugins 2.0<commit_after><?php
/**
 * processes_ImportFile.php
 *
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2008 Colosa Inc.23
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email <EMAIL>.
 *
 */

global $RBAC;
$RBAC->requirePermissions('PM_SETUP_ADVANCE');

try {
  //load the variables
  G::LoadClass('plugin');
  if ( ! isset($_FILES['form']['error']['PLUGIN_FILENAME'] ) || $_FILES['form']['error']['PLUGIN_FILENAME'] == 1 ) {
    throw ( new Exception ("There was an error uploading the file, probably the file size if greater than upload_max_filesize parameter in php.ini, please check this parameter and try again." ) );
  }

  //save the file
  if ($_FILES['form']['error']['PLUGIN_FILENAME'] == 0) {
    $filename = $_FILES['form']['name']['PLUGIN_FILENAME'];
    $path     = PATH_DOCUMENT . 'input' . PATH_SEP ;
    $tempName = $_FILES['form']['tmp_name']['PLUGIN_FILENAME'];
    G::uploadFile($tempName, $path, $filename );
  }
  if ( ! $_FILES['form']['type']['PLUGIN_FILENAME'] == 'application/octet-stream')
    throw ( new Exception ( "the uploaded files are invalid, expected 'application/octect-stream mime type file (".  $_FILES['form']['type']['PLUGIN_FILENAME'] . ")" ));


  G::LoadThirdParty( 'pear/Archive','Tar');
  $tar = new Archive_Tar ( $path. $filename);
  $sFileName  = substr($filename,0,strrpos($filename, '.' ));
  $sClassName = substr($filename,0,strpos($filename, '-' ));

  $aFiles = $tar->listContent();
  $bMainFile = false;
  $bClassFile = false;
  foreach ( $aFiles as $key => $val ) {
    if ( $val['filename'] == $sClassName . '.php' ) $bMainFile = true;
    if ( $val['filename'] == $sClassName . PATH_SEP . 'class.' . $sClassName . '.php' ) $bClassFile = true;
  }

  $oPluginRegistry =& PMPluginRegistry::getSingleton();
  $pluginFile = $sClassName . '.php';

  if ( $bMainFile && $bClassFile ) {
    $sAux = $sClassName . 'Plugin';
    $fVersionOld = 0.0;
    if (file_exists(PATH_PLUGINS . $pluginFile)) {
      if (!class_exists($sAux) && !class_exists($sClassName . 'plugin')) {
        include PATH_PLUGINS . $pluginFile;
      }
      if (!class_exists($sAux)) {
        $sAux = $sClassName . 'plugin';
      }
      $oClass = new $sAux($sClassName);
      $fVersionOld = $oClass->iVersion;
      unset($oClass);
    }
    $res = $tar->extract ( $path );
    $sContent = file_get_contents($path . PATH_SEP . $pluginFile);
    $sContent = str_ireplace($sAux, $sAux . '_', $sContent);
    $sContent = str_ireplace('PATH_PLUGINS', "'".$path."'", $sContent);
    $sContent = str_ireplace('$oPluginRegistry =& PMPluginRegistry::getSingleton();', '', $sContent);
    $sContent = str_ireplace('$oPluginRegistry->registerPlugin(\'' . $sClassName . '\', __FILE__);', '', $sContent);
    //header('Content-Type: text/plain');var_dump($sClassName, $sContent);die;
    file_put_contents($path . PATH_SEP . $pluginFile, $sContent);
    $sAux = $sAux . '_';
    include $path . PATH_SEP . $pluginFile;
    $oClass = new $sAux($sClassName);
    $fVersionNew = $oClass->iVersion;
    if (!isset($oClass->iPMVersion)) {
      $oClass->iPMVersion = 0;
    }
    if ($oClass->iPMVersion > 0) {
      G::LoadClass("system");
      if (System::getVersion() > 0) {
        if ($oClass->iPMVersion > System::getVersion()) {
          //throw new Exception('This plugin needs version ' . $oClass->iPMVersion . ' or higher of ProcessMaker');
        }
      }
    }
    if (!isset($oClass->aDependences)) {
      $oClass->aDependences = null;
{'fraction_non_alphanumeric': 0.16341114816579325, 'fraction_numerical': 0.007622677465459742, 'mean_word_length': 3.6910614525139667, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6608740', 'n_tokens_mistral': 2826, 'n_tokens_neox': 2697, 'n_words': 698}