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

Diff of /contributions/modules/taxonomy_image/taxonomy_image.module

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

revision 1.12.4.13.2.41, Tue Mar 17 14:09:44 2009 UTC revision 1.12.4.13.2.42, Tue Mar 17 14:38:16 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: taxonomy_image.module,v 1.12.4.13.2.40 2009/03/17 13:57:36 nancyw Exp $  // $Id: taxonomy_image.module,v 1.12.4.13.2.41 2009/03/17 14:09:44 nancyw Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 611  function taxonomy_image_taxonomy($op, $t Line 611  function taxonomy_image_taxonomy($op, $t
611    switch ($op) {    switch ($op) {
612      case 'insert':      case 'insert':
613      case 'update':      case 'update':
614          // Check / create category picture directory.
615        $directory = file_create_path(variable_get('taxonomy_image_path', 'category_pictures'));        $directory = file_create_path(variable_get('taxonomy_image_path', 'category_pictures'));
616        file_check_directory($directory, FILE_CREATE_DIRECTORY);        if (!file_check_directory($directory, FILE_CREATE_DIRECTORY)) {
617            drupal_set_message(t('Error creating the category picture directory: "%dir" does not exist, or is not writable.', array('%dir' => $directory)), 'error');
618            return;
619          }
620    
621        // Did they mark it to delete?        // Did they mark it to delete?
622        if ($form_values['taxonomy_image_current_image_delete'] == TRUE) {        if ($form_values['taxonomy_image_current_image_delete'] == TRUE) {
623          taxonomy_image_delete($tid);          taxonomy_image_delete($tid);
# Line 634  function taxonomy_image_taxonomy($op, $t Line 637  function taxonomy_image_taxonomy($op, $t
637            drupal_set_message(t('Copy from @source to @where failed.', array('@source' => $source, '@where' => $where)), 'error');            drupal_set_message(t('Copy from @source to @where failed.', array('@source' => $source, '@where' => $where)), 'error');
638          }          }
639        }        }
640        // Use upload field        // Upload field used?
641        else {        else {
642          $validators = array();          $validators = array();
643          // FILE_EXISTS_REPLACE allows multiple terms to use the same image without having multiple files.          // FILE_EXISTS_REPLACE allows multiple terms to use the same image without having multiple files.
644          $file = file_save_upload('taxonomy_image_upload', $validators, $directory, FILE_EXISTS_REPLACE);          $file = file_save_upload('taxonomy_image_upload', $validators, $directory, FILE_EXISTS_REPLACE);
         // New file to upload?  
         if (!$file) {  
           break; // No, just go on our way.  
         }  
645    
646          if(is_object($file)) {          if (is_object($file)) {
647            // Make sure Cron doesn't delete this file.            // If no errors while uploading, save term-image relation into DB
           file_set_status($file, FILE_STATUS_PERMANENT);  
648            $filepath = variable_get('taxonomy_image_path', 'category_pictures') . '/' . $file->filename;            $filepath = variable_get('taxonomy_image_path', 'category_pictures') . '/' . $file->filename;
649    
650            if (taxonomy_image_add($tid, $file->filename))            if (taxonomy_image_add($tid, $file->filename)) {
651                // Successfully added to DB, make sure Cron doesn't delete this file.
652                file_set_status($file, FILE_STATUS_PERMANENT);
653              drupal_set_message(t('Image uploaded as @name.', array('@name' => $filepath)));              drupal_set_message(t('Image uploaded as @name.', array('@name' => $filepath)));
654              }
655            else            else
656              drupal_set_message(t('Database insert failed. [tid = !tid, path = @path.', array('!tid' => $tid, '@path' => $filepath)), 'error');              drupal_set_message(t('Error while adding image [tid = !tid, path = @path].', array('!tid' => $tid, '@path' => $filepath)), 'error');
         }  
         elseif (!file_check_directory($directory)) {  
           // We know what's wrong, so generate a more useful error message.  
           drupal_set_message(t('The category picture directory "%dir" does not exist, or is not writable.', array('%dir' => $directory)), 'error');  
         }  
         else {  
           drupal_set_message(t('Image upload failed.'), 'error');  
657          }          }
658        }        }
659        break;        break;
# Line 668  function taxonomy_image_taxonomy($op, $t Line 662  function taxonomy_image_taxonomy($op, $t
662        break;        break;
663    }    }
664  }  }
665    
666  /**  /**
667   * Helper function for adding an image to a term   * Helper function for adding an image to a term
668   */   */

Legend:
Removed from v.1.12.4.13.2.41  
changed lines
  Added in v.1.12.4.13.2.42

  ViewVC Help
Powered by ViewVC 1.1.2