--- /home/shenliang/Desktop/apachesolr_attachments.admin.inc	2010-12-02 16:03:57.000000000 +0800
+++ /var/www/drupal_commons/sites/all/modules/apachesolr_attachments/apachesolr_attachments.admin.inc	2010-12-26 15:34:27.000000000 +0800
@@ -1,5 +1,5 @@
 <?php
-// $Id: apachesolr_attachments.admin.inc,v 1.4.2.8 2010/12/02 08:03:57 wmostrey Exp $
+// $Id: apachesolr_attachments.admin.inc,v 1.4.2.6 2010/06/22 16:02:23 pwolanin Exp $
 
 /**
  * @file
@@ -59,6 +59,30 @@ function apachesolr_attachments_settings
     '#description' =>  t("The name of the tika CLI application jar file, e.g. tika-0.3.jar or tika-app-0.4.jar."),
     '#default_value' => variable_get('apachesolr_attachments_tika_jar', 'tika-0.3.jar'),
   );
+  $form['apachesolr_attachments_poppler'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path to pdftotext file'),
+    '#description' =>  t('Use Poppler pdftotext command to parse pdf file'),
+    '#default_value' => variable_get('apachesolr_attachments_poppler', '/usr/bin/pdftotext'),
+  );
+  $form['apachesolr_attachments_catdoc'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path to catdoc'),
+    '#description' =>  t('Use catdoc command to parse doc file'),
+    '#default_value' => variable_get('apachesolr_attachments_catdoc', '/usr/bin/catdoc'),
+  );
+  $form['apachesolr_attachments_catppt'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path to catppt'),
+    '#description' =>  t('Use catppt command to parse ppt file'),
+    '#default_value' => variable_get('apachesolr_attachments_catppt', '/usr/bin/catppt'),
+  );
+  $form['apachesolr_attachments_xls2csv'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Path to xls2csv'),
+    '#description' =>  t('Use xls2csv command to parse xls file'),
+    '#default_value' => variable_get('apachesolr_attachments_xls2csv', '/usr/bin/xls2csv'),
+  );
   $form['apachesolr_attachments-cron-settings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Cron settings'),
@@ -208,8 +232,7 @@ function apachesolr_attachements_delete_
     return TRUE;
   }
   catch (Exception $e) {
-    // Shortened project name because the watchdog limits type to 16 characters.
-    watchdog('ApacheSolrAttach', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
+    watchdog('Apache Solr Attachments', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
   }
   return FALSE;
 }
@@ -272,13 +295,6 @@ function apachesolr_attachments_add_docu
         $document->promote = $node->promote;
         $document->uid = $node->uid;
         $document->name = $node->name;
-        if (empty($node->language)) {
-          // 'und' is the language-neutral code in Drupal 7.
-          $document->language = 'und';
-        }
-        else {
-          $document->language = $node->language;
-        }
         $document->body = apachesolr_clean_text($file->description) .' '. $text;
 
         $document->ss_filemime = $file->filemime;
@@ -297,8 +313,7 @@ function apachesolr_attachments_add_docu
         $documents[] = $document;
       }
       else {
-        // Shortened project name because the watchdog limits type to 16 characters.
-        watchdog('ApacheSolrAttach', 'Could not extract any indexable text from %filepath', array('%filepath' => $file->filepath), WATCHDOG_WARNING);
+        watchdog('Apache Solr Attachments', 'Could not extract any indexable text from %filepath', array('%filepath' => $file->filepath), WATCHDOG_WARNING);
       }
     }
   }
@@ -416,6 +431,36 @@ function apachesolr_attachments_get_atta
     return $cached['body'];
   }
 
+  switch ($file->filemime){
+    case 'application/pdf':
+      $text = apachesolr_attachments_extract_using_poppler($filepath);
+      $text = trim(apachesolr_clean_text($text));
+      db_query("UPDATE {apachesolr_attachments_files} SET sha1 = '%s', body = '%s' WHERE fid = %d", $sha1, $text, $file->fid);
+      return $text;
+    case 'application/msword':
+      $text = apachesolr_attachments_extract_using_catdoc($filepath);
+      $text = trim(apachesolr_clean_text($text));
+      db_query("UPDATE {apachesolr_attachments_files} SET sha1 = '%s', body = '%s' WHERE fid = %d", $sha1, $text, $file->fid);
+      return $text;
+    case 'application/vnd.ms-powerpoint':
+      $text = apachesolr_attachments_extract_using_catppt($filepath);
+      $text = trim(apachesolr_clean_text($text));
+      db_query("UPDATE {apachesolr_attachments_files} SET sha1 = '%s', body = '%s' WHERE fid = %d", $sha1, $text, $file->fid);
+      return $text;
+    case 'application/vnd.ms-excel':
+      $text = apachesolr_attachments_extract_using_xls2csv($filepath);
+      $text = trim(apachesolr_clean_text($text));
+      db_query("UPDATE {apachesolr_attachments_files} SET sha1 = '%s', body = '%s' WHERE fid = %d", $sha1, $text, $file->fid);
+      return $text;
+  }
+  
+  if (array_pop(explode('.', $file->filename)) == 'epub') {
+    $text = apachesolr_attachments_extract_using_ebooklib($filepath);
+    $text = trim(apachesolr_clean_text($text));
+    db_query("UPDATE {apachesolr_attachments_files} SET sha1 = '%s', body = '%s' WHERE fid = %d", $sha1, $text, $file->fid);
+    return $text;
+  }
+
   if (variable_get('apachesolr_attachment_extract_using', 'tika') == 'tika') {
     $text = apachesolr_attachments_extract_using_tika($filepath);
   }
@@ -426,8 +471,7 @@ function apachesolr_attachments_get_atta
     }
     catch (Exception $e) {
       // Exceptions from Solr may be transient, or indicate a problem with a specific file.
-      // Shortened project name because the watchdog limits type to 16 characters.
-      watchdog('ApacheSolrAttach', "Exception occured sending %filepath to Solr\n!message", array('%filepath' => $file->filepath, '!message' => nl2br(check_plain($e->getMessage()))), WATCHDOG_ERROR);
+      watchdog('Apache Solr Attachments', "Exception occured sending %filepath to Solr\n!message", array('%filepath' => $file->filepath, '!message' => nl2br(check_plain($e->getMessage()))), WATCHDOG_ERROR);
       return '';
     }
   }
@@ -494,3 +538,60 @@ function apachesolr_attachments_extract_
   return array($response->extracted, $response->extracted_metadata);
 }
 
+function apachesolr_attachments_extract_using_ebooklib($filepath) {
+  $ebooklib = variable_get('ebooklib_path', 'sites/all/libraries/eBookLib');
+  if (file_exists($ebooklib .'/ebookData.php') && file_exists($ebooklib .'/ebookRead.php')) {
+    require_once($ebooklib .'/ebookData.php');
+    require_once($ebooklib .'/ebookRead.php');
+    $ebook = new ebookRead($filepath);
+    $spine = $ebook->getSpine();
+    $content ='';
+    foreach ($spine as $index => $id) {
+      $content .= $ebook->getContentById($id);
+    }
+    return $content;
+  } 
+  else {
+    return 'FALSE';
+  }
+}
+
+function apachesolr_attachments_extract_using_poppler($filepath) {
+  if (file_exists(variable_get('apachesolr_attachments_poppler', '/usr/bin/pdftotext'))){
+    $cmd = 'pdftotext "' . $filepath . '" -';
+    return shell_exec($cmd);
+  }
+  else {
+    return FALSE;
+  }
+}
+
+function apachesolr_attachments_extract_using_catdoc($filepath) {
+  if (file_exists(variable_get('apachesolr_attachments_catdoc', '/usr/bin/catdoc'))){
+    $cmd = 'LANG=en_US.UTF-8; catdoc -w "' . $filepath . '"';
+    return shell_exec($cmd);
+  }
+  else {
+    return FALSE;
+  }
+}
+
+function apachesolr_attachments_extract_using_catppt($filepath) {
+  if (file_exists(variable_get('apachesolr_attachments_catppt', '/usr/bin/catppt'))){
+    $cmd = 'LANG=en_US.UTF-8; catppt "' . $filepath . '"';
+    return shell_exec($cmd);
+  }
+  else {
+    return FALSE;
+  }
+}
+
+function apachesolr_attachments_extract_using_xls2csv($filepath) {
+  if (file_exists(variable_get('apachesolr_attachments_xls2csv', '/usr/bin/xls2csv'))){
+    $cmd = 'LANG=en_US.UTF-8; xls2csv "' . $filepath . '"';
+    return shell_exec($cmd);
+  }
+  else {
+    return FALSE;
+  }
+}
