/[drupal]/contributions/modules/docapi/docapi.module
ViewVC logotype

Diff of /contributions/modules/docapi/docapi.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2.2.4 by bradfordcp, Sun Jul 6 06:35:59 2008 UTC revision 1.2.2.5 by bradfordcp, Tue Jul 8 04:26:39 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2    // $Id: docapi.module,v 1.2.2.3 2008/07/03 04:29:41 bradfordcp Exp $    // $Id: docapi.module,v 1.2.2.4 2008/07/06 06:35:59 bradfordcp Exp $
3    
4    /**    /**
5     * @file     * @file
# Line 20  Line 20 
20        'access arguments' => array('administer site configuration'),        'access arguments' => array('administer site configuration'),
21      );      );
22    
23      $items['doc/add'] = array(      $items['node/add/doc'] = array(
24        'title' => t('Import Document to Library'),        'title' => t('Import Document into Library'),
25        'description' => t('Upload files into the document library.'),        'description' => t('Upload and parse files into the document library.'),
26        'page callback' => 'drupal_get_form',        'page callback' => 'drupal_get_form',
27        'page arguments' => array('docapi_doc_add_form'),        'page arguments' => array('docapi_doc_add_form'),
28        'access arguments' => array('Import Documents to Library'),        'access arguments' => array('import documents to library'),
29      );      );
30    
31        // The item to load a document from the library
32        /*$items['node/add/lib'] = array(
33          'title' => t('Load Library Item'),
34          'description' => t('Load an item from the library into s specified node type.'),
35          'access arguments' => array('create node from document'),
36        );*/
37    
38      return $items;      return $items;
39    }    }
40    
# Line 36  Line 43 
43     */     */
44    function docapi_perm() {    function docapi_perm() {
45      return array(      return array(
46        'Import Documents to Library',        'import documents to library',
47        'Create Node from Document',        'create node from document',
       'Administer DocAPI Plugin Settings'  
48      );      );
49    }    }
50    
# Line 53  Line 59 
59    }    }
60    
61    /**    /**
    * Implementation of hook_con().  
    */  
   function docapi_cron() {  
     docapi_find_plugins();  
   }  
   
   /**  
62     * Probe other modules for docapi hooks     * Probe other modules for docapi hooks
63       * @TODO: Remove, this is being replaced with code in docapi_add_plugin()
64     */     */
65    function docapi_find_plugins() {    function docapi_find_plugins() {
66      $result = db_query("SELECT s.name FROM {system} s WHERE s.type = 'module' AND NOT (s.name IN (SELECT dp.module FROM {docapi_plugins} dp))");      $result = db_query("SELECT s.name FROM {system} s WHERE s.type = 'module' AND NOT (s.name IN (SELECT dp.module FROM {docapi_plugins} dp))");
# Line 72  Line 72 
72    
73          foreach ($info['mimetypes'] as $mimetype) {          foreach ($info['mimetypes'] as $mimetype) {
74            // MyISAM does this automatically, but we cannot use it since we are within the schema API            // MyISAM does this automatically, but we cannot use it since we are within the schema API
75            // Instead we pull out the largest value or 0 if the value is null, this isn't a public facing            // Instead we pull out the largest value or 0 if the value is null
           // page so there are not that many issues when doing it this way.  
76            $weight = db_result(db_query("SELECT dpm.weight FROM {docapi_plugin_mimetypes} dpm WHERE mimetype = '%s'", $mimetype));            $weight = db_result(db_query("SELECT dpm.weight FROM {docapi_plugin_mimetypes} dpm WHERE mimetype = '%s'", $mimetype));
77    
78            if ($weight == null)            if ($weight == null)
# Line 88  Line 87 
87    }    }
88    
89    /**    /**
90       * Add the specified parser to the docapi
91       */
92      function docapi_add_plugin($plugin) {
93        // This plugin provide support to the image/jpeg mimetype
94        $info = module_invoke($plugin, 'docapi_info');
95        db_query("INSERT INTO {docapi_plugins} (name, module) VALUES ('%s', '%s')", $info['name'], $plugin);
96        $plugin_id = db_last_insert_id('docapi_info', 'plugin_id');
97    
98        foreach ($info['mimetypes'] as $mimetype) {
99          // Pull out the largest value or 0 if the value is null
100          $weight = db_result(db_query("SELECT dpm.weight FROM {docapi_plugin_mimetypes} dpm WHERE mimetype = '%s'", $mimetype));
101    
102          if ($weight == null)
103            $weight = 0;
104          else
105            $weight++;
106    
107          db_query("INSERT INTO {docapi_plugin_mimetypes} (plugin_id, mimetype, weight) VALUES (%d, '%s', %d)", $plugin_id, $mimetype, $weight);
108        }
109      }
110    
111      /**
112       * Remove the specified parser from docapi
113       */
114      function docapi_remove_plugin($plugin) {
115        // Remove the mimetypes and cascade the weight column
116        $result = db_query("SELECT dpm.mimetype, dpm.weight FROM {docapi_plugin_mimetypes} dpm
117                            INNER JOIN {docapi_plugins} dp ON dpm.plugin_id = dp.plugin_id
118                            WHERE dp.module = '%s'", $plugin);
119    
120        while ($row = db_fetch_array($result)) {
121          db_query("DELETE FROM {docapi_plugin_mimetypes} WHERE mimetype = '%s' AND weight = %d", $row['mimetype'], $row['weight']);
122          db_query("UPDATE {docapi_plugin_mimetypes} SET weight = weight - 1 WHERE mimetype = '%s' AND weight > %d", $row['mimetype'], $row['weight']);
123        }
124    
125        db_query("DELETE FROM {docapi_plugins} WHERE module = '%s'", $plugin);
126      }
127    
128      /**
129     * Retrieve the list of available parsers     * Retrieve the list of available parsers
130     *     *
131     * @param $auto     * @param $auto
# Line 136  Line 174 
174        '#type' => 'textfield',        '#type' => 'textfield',
175        '#title' => t('DocAPI file save path'),        '#title' => t('DocAPI file save path'),
176        '#description' => t('The path the location where the imported files will be placed.'),        '#description' => t('The path the location where the imported files will be placed.'),
177        '#default_value' => variable_get('docapi_file_path', 'sites/files/docapi_library'),        '#default_value' => variable_get('docapi_file_path', 'sites/default/files/docapi_library'),
178      );      );
179    
180      $form['docapi_plugin_settings'] = array(      $form['docapi_plugin_settings'] = array(
# Line 298  Line 336 
336      // Begin file processing once it has cleared all of the validation      // Begin file processing once it has cleared all of the validation
337    
338      // Move the file to the its location within the 'docapi_file_path'      // Move the file to the its location within the 'docapi_file_path'
339      if (!move_uploaded_file($form_state['values']['docapi_file_path'], variable_get('docapi_file_path', 'sites/files/docapi_library') .'/'. $form_state['values']['docapi_file_name'])) {      if (!move_uploaded_file($form_state['values']['docapi_file_path'], variable_get('docapi_file_path', 'sites/defaultfiles/docapi_library') .'/'. $form_state['values']['docapi_file_name'])) {
340        form_set_error('docapi_file', t('Could not move file into the upload directory.'));        form_set_error('docapi_file', t('Could not move file into the upload directory.'));
341      }      }
342      else {      else {

Legend:
Removed from v.1.2.2.4  
changed lines
  Added in v.1.2.2.5

  ViewVC Help
Powered by ViewVC 1.1.6