<commit_before><?php
require_once dirname(__FILE__).'/accesscheck.php';

$GLOBALS["plugins"] = array();
$GLOBALS['editorplugin'] = false;
if (!defined("PLUGIN_ROOTDIR")) {
  define("PLUGIN_ROOTDIR","notdefined");
}

$pluginRootDirs = array();
if (defined('PLUGIN_ROOTDIRS')) {
  $pluginRootDirs = explode(';',PLUGIN_ROOTDIRS);
}
$pluginRootDirs[] = PLUGIN_ROOTDIR;
$pluginRootDirs = array_unique($pluginRootDirs);

include_once dirname(__FILE__). "/defaultplugin.php";
$pluginFiles = array();

foreach ($pluginRootDirs as $pluginRootDir) {
  ## try to expand to subdir of the admin dir
  if (!is_dir($pluginRootDir) && !empty($pluginRootDir)) {
    $pluginRootDir = dirname(__FILE__).'/'.$pluginRootDir;
  }
  
#  print '<h3>'.$pluginRootDir.'</h3>';
  if (is_dir($pluginRootDir)) {
    $dh = opendir($pluginRootDir);
    while (false!==($file = readdir($dh))) {
      if ($file != "." && $file != ".." && !preg_match("/~$/",$file)) {
#        print $pluginRootDir.' '.$file.'<br/>';
        if (is_file($pluginRootDir."/".$file) && preg_match("/\.php$/",$file)) {
#          print "ADD $file<br/>";
          array_push($pluginFiles,$pluginRootDir."/".$file);
        } elseif (is_dir($pluginRootDir.'/'.$file.'/plugins')) {
#         print 'SUBROOT'.$pluginRootDir.' '.$file.'<br/>';
          $subRoot = $pluginRootDir.'/'.$file.'/plugins';
          $subDir = opendir($subRoot);
          while (false!==($subFile = readdir($subDir))) {
            if (is_file($subRoot.'/'.$subFile) && preg_match("/\.php$/",$subFile) ) {
#              print "ADD $subFile<br/>";
              array_push($pluginFiles,$subRoot.'/'.$subFile);
            } else {
#              print "NOT A FILE: $subRoot.'/'.$subFile<br/>";
            }
          }
        } else {
#          print 'NOT A DIR: '.$pluginRootDir.'/'.$file.'/plugins<br/>';
        }
      }
    }
    closedir($dh);
  }
}

$auto_enable_plugins = array();
if (isset($GLOBALS['plugins_autoenable'])) {
  $auto_enable_plugins = $GLOBALS['plugins_autoenable'];
}

#var_dump($pluginFiles);exit;
$disabled_plugins = unserialize(getConfig('plugins_disabled'));
if (is_array($disabled_plugins)) {
  foreach ($disabled_plugins as $pl => $plstate) {
    if (!empty($plstate) && !in_array($pl,$auto_enable_plugins)) {
      $GLOBALS['plugins_disabled'][] = $pl;
    }
  }
}

#var_dump($GLOBALS['plugins_disabled']);exit;
foreach ($pluginFiles as $file) {
  list($className,$ext) = explode(".",basename($file));
  if (preg_match("/[\w]+/",$className)) {# && !in_array($className,$GLOBALS['plugins_disabled'])) {
    if (!class_exists($className)) {
      include_once $file;
      if (class_exists($className)) {
        $pluginInstance = new $className();
      #  print "Instance $className<br/>";
        ## bit of a duplication of plugins, but $GLOBALS['plugins'] should only contain active ones
        ## using "allplugins" allow listing them, and switch on/off in the plugins page
        $GLOBALS["allplugins"][$className] = $pluginInstance;
        if (!in_array($className,$GLOBALS['plugins_disabled'])) {
          $GLOBALS["plugins"][$className] = $pluginInstance;
          ## remember the first plugin that says it can provide the editor
          ## the "editor" method is not defined in the default plugin, so it'll have to be made explicitly.
          if (!$GLOBALS['editorplugin'] && $pluginInstance->editorProvider && method_exists($pluginInstance,'editor')) {
            $GLOBALS['editorplugin'] = $className;
          }
     #     print $className.' '.md5('plugin-'.$className.'-initialised').'<br/>';
          $plugin_initialised = getConfig(md5('plugin-'.$className.'-initialised'));
          if (!empty($plugin_initialised)) {
            $GLOBALS["plugins"][$className]->enabled = true;
          } elseif (in_array($className,$auto_enable_plugins)) {
            $GLOBALS["plugins"][$className]->initialise();
            $GLOBALS["plugins"][$className]->enabled = true;
          } else {
            $GLOBALS["plugins"][$className]->enabled = false;
            $disabled_plugins[$className] = 1;
            saveConfig('plugins_disabled',serialize($disabled_plugins),0);
          }
          
          if (!empty($GLOBALS["plugins"][$className]->DBstruct)) {
            foreach ($GLOBALS["plugins"][$className]->DBstruct as $tablename => $tablecolumns) {
              $GLOBALS['tables'][$className.'_'.$tablename] =  $GLOBALS['table_prefix'] . $className.'_'.$tablename;<commit_msg>remember the original location of the plugin instance<commit_after><?php
require_once dirname(__FILE__).'/accesscheck.php';

$GLOBALS["plugins"] = array();
$GLOBALS['editorplugin'] = false;
if (!defined("PLUGIN_ROOTDIR")) {
  define("PLUGIN_ROOTDIR","notdefined");
}

$pluginRootDirs = array();
if (defined('PLUGIN_ROOTDIRS')) {
  $pluginRootDirs = explode(';',PLUGIN_ROOTDIRS);
}
$pluginRootDirs[] = PLUGIN_ROOTDIR;
$pluginRootDirs = array_unique($pluginRootDirs);

include_once dirname(__FILE__). "/defaultplugin.php";
$pluginFiles = array();

foreach ($pluginRootDirs as $pluginRootDir) {
  ## try to expand to subdir of the admin dir
  if (!is_dir($pluginRootDir) && !empty($pluginRootDir)) {
    $pluginRootDir = dirname(__FILE__).'/'.$pluginRootDir;
  }
  
#  print '<h3>'.$pluginRootDir.'</h3>';
  if (is_dir($pluginRootDir)) {
    $dh = opendir($pluginRootDir);
    while (false!==($file = readdir($dh))) {
      if ($file != "." && $file != ".." && !preg_match("/~$/",$file)) {
#        print $pluginRootDir.' '.$file.'<br/>';
        if (is_file($pluginRootDir."/".$file) && preg_match("/\.php$/",$file)) {
#          print "ADD $file<br/>";
          array_push($pluginFiles,$pluginRootDir."/".$file);
        } elseif (is_dir($pluginRootDir.'/'.$file.'/plugins')) {
#         print 'SUBROOT'.$pluginRootDir.' '.$file.'<br/>';
          $subRoot = $pluginRootDir.'/'.$file.'/plugins';
          $subDir = opendir($subRoot);
          while (false!==($subFile = readdir($subDir))) {
            if (is_file($subRoot.'/'.$subFile) && preg_match("/\.php$/",$subFile) ) {
#              print "ADD $subFile<br/>";
              array_push($pluginFiles,$subRoot.'/'.$subFile);
            } else {
#              print "NOT A FILE: $subRoot.'/'.$subFile<br/>";
            }
          }
        } else {
#          print 'NOT A DIR: '.$pluginRootDir.'/'.$file.'/plugins<br/>';
        }
      }
    }
    closedir($dh);
  }
}

$auto_enable_plugins = array();
if (isset($GLOBALS['plugins_autoenable'])) {
  $auto_enable_plugins = $GLOBALS['plugins_autoenable'];
}

#var_dump($pluginFiles);exit;
$disabled_plugins = unserialize(getConfig('plugins_disabled'));
if (is_array($disabled_plugins)) {
  foreach ($disabled_plugins as $pl => $plstate) {
    if (!empty($plstate) && !in_array($pl,$auto_enable_plugins)) {
      $GLOBALS['plugins_disabled'][] = $pl;
    }
  }
}

#var_dump($GLOBALS['plugins_disabled']);exit;
foreach ($pluginFiles as $file) {
  list($className,$ext) = explode(".",basename($file));
  if (preg_match("/[\w]+/",$className)) {# && !in_array($className,$GLOBALS['plugins_disabled'])) {
    if (!class_exists($className)) {
      include_once $file;
      if (class_exists($className)) {
        $pluginInstance = new $className();
        $pluginInstance->origin = $file;
      #  print "Instance $className<br/>";
        ## bit of a duplication of plugins, but $GLOBALS['plugins'] should only contain active ones
        ## using "allplugins" allow listing them, and switch on/off in the plugins page
        $GLOBALS["allplugins"][$className] = $pluginInstance;
        if (!in_array($className,$GLOBALS['plugins_disabled'])) {
          $GLOBALS["plugins"][$className] = $pluginInstance;
          ## remember the first plugin that says it can provide the editor
          ## the "editor" method is not defined in the default plugin, so it'll have to be made explicitly.
          if (!$GLOBALS['editorplugin'] && $pluginInstance->editorProvider && method_exists($pluginInstance,'editor')) {
            $GLOBALS['editorplugin'] = $className;
          }
     #     print $className.' '.md5('plugin-'.$className.'-initialised').'<br/>';
          $plugin_initialised = getConfig(md5('plugin-'.$className.'-initialised'));
          if (!empty($plugin_initialised)) {
            $GLOBALS["plugins"][$className]->enabled = true;
          } elseif (in_array($className,$auto_enable_plugins)) {
            $GLOBALS["plugins"][$className]->initialise();
            $GLOBALS["plugins"][$className]->enabled = true;
          } else {
            $GLOBALS["plugins"][$className]->enabled = false;
            $disabled_plugins[$className] = 1;
            saveConfig('plugins_disabled',serialize($disabled_plugins),0);
          }
          
          if (!empty($GLOBALS["plugins"][$className]->DBstruct)) {
            foreach ($GLOBALS["plugins"][$className]->DBstruct as $tablename => $tablecolumns) {
              $GLOBALS['tables'][$className.'_'.$tablename] =  $GLOBALS['table_prefix'] . $className.'_'.$tablename;
{'fraction_non_alphanumeric': 0.19127926328636413, 'fraction_numerical': 0.0013314101852879175, 'mean_word_length': 3.375728155339806, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 42, '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': '2217199', 'n_tokens_mistral': 2768, 'n_tokens_neox': 2795, 'n_words': 480}