You are here

function xbbcode_highlighter_import in Extensible BBCode 5

1 string reference to 'xbbcode_highlighter_import'
xbbcode_highlighter_menu in xbbcode_highlighter/xbbcode_highlighter.module

File

xbbcode_highlighter/xbbcode_highlighter.module, line 188

Code

function xbbcode_highlighter_import() {

  /* install missing classes */
  $xmlpath = file_directory_path() . "/highlighter";
  $path = drupal_get_path('module', 'xbbcode_highlighter');
  $files = file_scan_directory($path . '/classes', '^.+\\.php$', array(), false, '', 'name');
  $xmlfiles = file_scan_directory($xmlpath, '^.+\\.xml$', array(), false, '', 'name');
  $dest = drupal_get_path('module', 'xbbcode_highlighter') . '/classes';
  require_once 'Text/Highlighter/Generator.php';
  foreach ($xmlfiles as $name => $file) {
    if (!$files[$name]) {
      $generator =& new Text_Highlighter_Generator("{$xmlpath}/{$name}.xml");
      $generator
        ->generate();
      $generator
        ->saveCode("{$dest}/{$name}.php");
      $files[$name] = $file;
      drupal_set_message(t("Drupal detected an XML file for %lang and regenerated the missing class from it.", array(
        '%lang' => $name,
      )), 'status');
    }
  }
  foreach ($files as $name => $file) {
    if (!db_result(db_query("SELECT id FROM {xbbcode_highlighter} WHERE id='%s'", $name))) {
      drupal_set_message(t("Language class %lang was detected and automatically added.", array(
        '%lang' => $name,
      )), 'status');
      db_query("INSERT INTO {xbbcode_highlighter} (id) VALUES('%s');", $name);
    }
  }
  $form['help'] = array(
    '#type' => 'item',
    '#value' => t("You can import a new syntax highlighting scheme here. Due to the way Drupal handles uploads, only XML files can be imported. If only the generated class is available, you must add it to the directory 'classes/' manually."),
  );
  $form['#tree'] = true;
  $form['#attributes'] = array(
    'enctype' => "multipart/form-data",
  );
  $form['xml'] = array(
    '#type' => 'fieldset',
    '#collapsible' => true,
    '#title' => t("Import XML File"),
  );
  $form['xml']['upload'] = array(
    '#type' => 'file',
    '#title' => t("Upload"),
    '#description' => t("You can upload an XML file here."),
  );
  $form['xml']['scan'] = array(
    '#type' => 'textfield',
    '#title' => t("Scan directory"),
    '#description' => t("You may choose to import a whole directory full of XML files."),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t("Import"),
  );
  return $form;
}