You are here

function search_files_install_auto_helper_app_configuration in Search Files 7.2

Same name and namespace in other branches
  1. 6.2 search_files.module \search_files_install_auto_helper_app_configuration()

Detects helper applications and adds to database.

1 call to search_files_install_auto_helper_app_configuration()
search_files_helper_autodetect_submit in ./search_files.module
Submit callback for search_files_helper_autodetect().

File

./search_files.module, line 123
Organizes and provides helper functions for extracting text from files.

Code

function search_files_install_auto_helper_app_configuration() {

  // safe_mode will inhibit shell_exec()
  if (search_files_issafemode()) {
    drupal_set_message(t('Since PHP is running in safe mode we cannot detect all possible helpers and most will have to be added manually.'));

    // load sample helper apps into database
    search_files_helper_db_add(t("Portable Document Format"), "pdf", "/usr/bin/env pdftotext %file% -");
    search_files_helper_db_add(t("Text"), "txt", "/usr/bin/env cat %file%");
  }
  else {
    if (php_uname('s') == 'Darwin') {

      // we are running on a mac so make sure the default install location are
      // in the path
      $path = 'export PATH=/opt/local/bin:/opt/local/sbin:$PATH;';
    }
    else {
      $path = '';
    }

    // test for pdftotext
    $location = trim(shell_exec('which pdftotext'));
    $location = preg_replace("/^no .*\$/", "", $location);
    if ($location) {
      search_files_helper_db_add(t("Portable Document Format"), "pdf", $location . " %file% -");
      drupal_set_message(t('Helper app pdftotext has been detected and configured'));
    }
    else {
      $location = trim(shell_exec($path . 'which pstotext'));
      $location = preg_replace("/^no .*\$/", "", $location);
      if ($location) {
        search_files_helper_db_add(t("PDF"), "pdf", $location . " %file%");
        drupal_set_message(t('Helper app pstotext has been detected and configured'));
      }
    }

    // test for cat
    $location = trim(shell_exec($path . 'which cat'));
    $location = preg_replace("/^no .*\$/", "", $location);
    if ($location) {
      search_files_helper_db_add(t("Text files"), "txt", $location . " %file%");
      drupal_set_message(t('Helper app cat has been detected and configured'));
    }

    // test for catdoc
    $location = trim(shell_exec($path . 'which catdoc'));
    $location = preg_replace("/^no .*\$/", "", $location);
    if ($location) {
      search_files_helper_db_add(t("Word documents"), "doc", $location . " %file%");
      drupal_set_message(t('Helper app catdoc has been detected and configured'));
    }

    // test for docx2txt
    $location = trim(shell_exec($path . 'which docx2txt.pl'));
    $location = preg_replace("/^no .*\$/", "", $location);
    $perl_location = trim(shell_exec($path . 'which perl'));
    $perl_location = preg_replace("/^no .*\$/", "", $perl_location);
    if ($location && $perl_location) {
      search_files_helper_db_add("Word 2007 files", "docx", $perl_location . ' ' . $location . " %file% -");
      drupal_set_message(t('Helper app docx2txt has been detected and configured'));
    }

    // test for xls2csv
    $location = trim(shell_exec($path . 'which xls2csv'));
    $location = preg_replace("/^no .*\$/", "", $location);
    if ($location) {
      search_files_helper_db_add(t("Excel files"), "xls", $location . " %file%");
      drupal_set_message(t('Helper app xls2csv has been detected and configured'));
    }

    // test for catppt
    $location = trim(shell_exec($path . 'which catppt'));
    $location = preg_replace("/^no .*\$/", "", $location);
    if ($location) {
      search_files_helper_db_add(t("Power Point Presentations"), "ppt", $location . " %file%");
      drupal_set_message(t('Helper app catppt has been detected and configured'));
    }

    // test for unrtf
    $location = trim(shell_exec($path . 'which unrtf'));
    $location = preg_replace("/^no .*\$/", "", $location);
    if ($location) {
      search_files_helper_db_add(t("Rich Text Format files"), "rtf", $location . " %file%");
      drupal_set_message(t('Helper app unrtf has been detected and configured'));
    }
  }
}