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

Diff of /contributions/modules/img_assist/img_assist.module

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

revision 1.106, Mon Aug 3 21:47:25 2009 UTC revision 1.107, Thu Aug 13 19:32:44 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: img_assist.module,v 1.105 2009/07/23 09:57:56 sun Exp $  // $Id: img_assist.module,v 1.106 2009/08/03 21:47:25 sun Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 48  function img_assist_theme() { Line 48  function img_assist_theme() {
48   * Implementation of hook_menu().   * Implementation of hook_menu().
49   */   */
50  function img_assist_menu() {  function img_assist_menu() {
   $items = array();  
   
51    $items['img_assist/cache/clear'] = array(    $items['img_assist/cache/clear'] = array(
52      'title' => 'Empty cache',      'title' => 'Empty cache',
53      'page callback' => 'img_assist_cache_clear',      'page callback' => 'img_assist_cache_clear',
54      'access arguments' => array('administer site configuration'),      'access arguments' => array('administer site configuration'),
55      'type' => MENU_CALLBACK,      'type' => MENU_CALLBACK,
56        'file' => 'img_assist.admin.inc',
57    );    );
58    $items['img_assist/load'] = array(    $items['img_assist/load'] = array(
59      'title' => 'Image assist',      'title' => 'Image assist',
# Line 108  function img_assist_menu() { Line 107  function img_assist_menu() {
107      'page callback' => 'drupal_get_form',      'page callback' => 'drupal_get_form',
108      'page arguments' => array('img_assist_admin_settings'),      'page arguments' => array('img_assist_admin_settings'),
109      'access arguments' => array('administer site configuration'),      'access arguments' => array('administer site configuration'),
110        'file' => 'img_assist.admin.inc',
111    );    );
112    return $items;    return $items;
113  }  }
# Line 210  function img_assist_block($op = 'list', Line 210  function img_assist_block($op = 'list',
210  }  }
211    
212  /**  /**
  * Implementation of hook_settings().  
  */  
 function img_assist_admin_settings() {  
   require_once drupal_get_path('module', 'img_assist') .'/includes/img_assist.token.inc';  
   
   // Access settings.  
   $form['access'] = array(  
     '#type' => 'fieldset',  
     '#title' => t('Access settings'),  
     '#collapsible' => TRUE,  
     '#collapsed' => TRUE,  
   );  
   $form['access']['img_assist_paths_type'] = array(  
     '#type' => 'radios',  
     '#title' => t('Display Image assist on paths'),  
     '#default_value' => variable_get('img_assist_paths_type', 2),  
     '#options' => array(t('on specific paths'), t('not on specific paths'), t('all paths')),  
   );  
   $form['access']['img_assist_paths'] = array(  
     '#type' => 'textarea',  
     '#title' => t('Paths'),  
     '#default_value' => variable_get('img_assist_paths', "node/*\ncomment/*"),  
     '#cols' => 40,  
     '#rows' => 5,  
     '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>')),  
   );  
   $form['access']['img_assist_textareas_type'] = array(  
     '#type' => 'radios',  
     '#title' => t('Display Image assist on text areas'),  
     '#default_value' => variable_get('img_assist_textareas_type', 2),  
     '#options' => array(t('Show on every textarea except the listed textareas.'), t('Show on only the listed textareas.'), t('Show on all textareas.')),  
   );  
   $form['access']['img_assist_textareas'] = array(  
     '#type' => 'textarea',  
     '#title' => t('Text areas'),  
     '#default_value' => variable_get('img_assist_textareas', "edit-body\nedit-comment"),  
     '#cols' => 40,  
     '#rows' => 5,  
     '#description' => t("Enter one text area form-id per line. Form-id's are used by Drupal to typify them, which allows themers and coders to modify certain form fields, but not all. Find form-id's using this method: view the source of the webpage, then search for the string that's just above the text area and you'll see the form-id nearby. The '*' character is a wildcard. For example, you can specify all CCK fields as %cck-example.", array('%cck-example' => 'edit-field-*')),  
   );  
   $form['access']['img_assist_link'] = array(  
     '#type' => 'select',  
     '#title' => t('Textarea image link'),  
     '#default_value' => variable_get('img_assist_link', 'icon'),  
     '#options' => array('icon' => t('Show icon'), 'text' => t('Show text link'), 'none' => t('Do not show a link')),  
     '#description' => t('Choose what to show under the textareas for which Image assist is enabled.'),  
   );  
   
   // Prepare select options for image browser views.  
   $options = array();  
   views_include('admin');  
   $views = views_get_all_views();  
   $base_tables = views_fetch_base_tables();  
   foreach ($views as $view) {  
     // Exclude malformed views (@see views/admin.inc).  
     if (!empty($view->disabled) || empty($view->display)) {  
       continue;  
     }  
     // Exclude views considered unusable for IA.  
     if (!($view->base_table == 'node' || $view->base_table == 'files')) {  
       continue;  
     }  
     $options[$view->name] = ($view->get_title() == '') ? $view->name : $view->get_title();  
   }  
   $form['access']['img_assist_views'] = array(  
     '#type' => 'select',  
     '#multiple' => TRUE,  
     '#title' => t('Image browser views'),  
     '#default_value' => variable_get('img_assist_views', drupal_map_assoc(array('img_assist_browser'))),  
     '#options' => $options,  
     '#required' => TRUE,  
     '#description' => t('Select the views to use for selecting images.'),  
   );  
   
   if (module_exists('taxonomy')) {  
     $vocs = array(0 => '<'. t('none') .'>');  
     foreach (taxonomy_get_vocabularies() as $vid => $voc) {  
       $vocs[$vid] = $voc->name;  
     }  
     if (count($vocs) > 1) {  
       $form['access']['img_assist_vocabs'] = array(  
         '#type' => 'select',  
         '#multiple' => TRUE,  
         '#title' => t('Select the vocabularies to use for Image assist'),  
         '#default_value' => variable_get('img_assist_vocabs', array()),  
         '#options' => $vocs,  
         '#description' => t('Select the vocabularies you want to be able to filter thumbnails by. This setting changes the behavior of Image assist at startup from loading all image thumbnails to displaying a list of image names until a filter is chosen.'),  
       );  
     }  
   }  
   
   // Image settings.  
   $form['image'] = array(  
     '#type' => 'fieldset',  
     '#title' => t('Image generation settings'),  
     '#collapsible' => TRUE,  
     '#collapsed' => TRUE,  
   );  
   $form['image']['img_assist_max_size'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Maximum inline image size allowed'),  
     '#default_value' => variable_get('img_assist_max_size', '640x640'),  
     '#size' => 9,  
     '#maxlength' => 9,  
     '#description' => t('Enter the number of maximum image dimensions to display with Image assist. This is a way to prevent users from breaking your layouts. This is applied when the filter tag is processed, so it will affect existing images. If an existing image exceeds these dimensions, a smaller derivative of the image will be substituted (or a smaller version will be created if you have allowed Image assist to create its own derivatives).'),  
   );  
   if (function_exists('image_get_sizes')) {  
     $max_size = explode('x', variable_get('img_assist_max_size', '640x640'));  
     $oversize_count = 0;  
     foreach (image_get_sizes() as $key => $size) {  
       $dimensions = $size['width'] .'x'. $size['height'];  
       if ((!empty($size['width']) && $size['width'] <= $max_size[0]) || (!empty($size['height']) && $size['height'] <= $max_size[1])) {  
         $derivatives[$dimensions] = $size['label'];  
       }  
       elseif ($key == IMAGE_THUMBNAIL) {  
         // Thumbnail option is shown even if it is larger than maximum size.  
         $derivatives[$dimensions] = $size['label'];  
       }  
       else {  
         $oversize_count++;  
       }  
       $allsizes[$key] = $size['label'];  
     }  
   
     $form['image']['img_assist_popup_label'] = array(  
       '#type' => 'select',  
       '#title' => t('Popup size'),  
       '#default_value' => variable_get('img_assist_popup_label', IMAGE_PREVIEW),  
       '#options' => $allsizes,  
       '#description' => t('Select the size of the image that is popped up.'),  
     );  
   
     $oversize_alert = ($oversize_count) ? '<br /><strong>'. format_plural($oversize_count, '1 image size is not being shown because it exceeds the the maximum inline image size setting (see above).', '@count image sizes are not being shown because they exceed the the maximum inline image size setting (see above).') .'</strong>' : '';  
     $form['image']['img_assist_default_label'] = array(  
       '#type' => 'select',  
       '#title' => t('Default size for inline images'),  
       '#default_value' => variable_get('img_assist_default_label', '100x100'),  
       '#options' => $derivatives,  
       '#description' => t('Select a derivative to be used by default for inline images.') . $oversize_alert,  
     );  
   }  
   $form['image']['img_assist_create_derivatives'] = array(  
     '#type' => 'checkboxes',  
     '#title' => t('Creation of image derivatives'),  
     '#default_value' => variable_get('img_assist_create_derivatives', array()),  
     '#options' => array(  
       'properties' => t('Create 200x200 images for the image properties window (useful if the thumbnail size is small).'),  
       'custom_advanced' => t('Allow users with %access permission to create custom size inline images.', array('%access' => 'access advanced options')),  
       'custom_all' => t('Allow all users to create custom size inline images.'),  
     ),  
     '#description' => t('These options allow Image assist to generate its custom image sizes (in the same manner as image.module) when a user would prefer a different size from the default image sizes defined in the image.module settings.'),  
   );  
   
   // Other properties.  
   $form['properties'] = array(  
     '#type' => 'fieldset',  
     '#title' => t('Image property dialog settings'),  
     '#collapsible' => TRUE,  
     '#collapsed' => TRUE,  
   );  
   $form['properties']['img_assist_default_link_behavior'] = array(  
     '#type' => 'select',  
     '#title' => t('Default link behavior'),  
     '#default_value' => variable_get('img_assist_default_link_behavior', 'none'),  
     '#options' => array('none' => t('Not a link'), 'node' => t('Link to image page'), 'popup' => t('Open in popup window'), 'url' => t('Go to URL')),  
     '#description' => t('The link behavior can be overridden when inserting images by users with the proper permissions, but these defaults will still be used for everyone else.'),  
   );  
   $form['properties']['img_assist_default_link_url'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Default URL'),  
     '#default_value' => variable_get('img_assist_default_link_url', 'http://'),  
     '#size' => 30,  
     '#maxlength' => 255,  
     '#description' => t('The default URL is used when Go to URL is choosen as the link behavior.'),  
   );  
   $form['properties']['img_assist_default_insert_mode'] = array(  
     '#type' => 'select',  
     '#title' => t('Default insert mode'),  
     '#default_value' => variable_get('img_assist_default_insert_mode', 'none'),  
     '#options' => array('filtertag' => t('Filter Tag'), 'html' => t('HTML Code')),  
     '#description' => t('The insert behavior can be overridden by users with the %permission permission when inserting images.  <strong>Warning:</strong> If images are inserted as HTML, Image Assist is not able to correct a link or image URL afterwards.  Please also note that users will not be able to edit already inserted images when using HTML code and the TinyMCE plugin.', array('%permission' => t('access advanced options'))),  
   );  
   $form['properties']['img_assist_load_title'] = array(  
     '#type' => 'radios',  
     '#title' => t('Preset caption title'),  
     '#default_value' => variable_get('img_assist_load_title', 1),  
     '#options' => array(t('Disabled'), t('Enabled')),  
     '#description' => t('If enabled, the title from the image will be loaded as the bolded caption by default.'),  
   );  
   $token_installed = module_exists('token');  
   $token_instructions = (!$token_installed ? t('Requires the !token module.', array('!token' => l('Token', 'http://drupal.org/project/token'))) : t('See below for a list of available replacement patterns.'));  
   $form['properties']['img_assist_title_pattern'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Caption title pattern'),  
     '#default_value' => variable_get('img_assist_title_pattern', '[title]'),  
     '#size' => 60,  
     '#maxlength' => 255,  
     '#description' => t('The pattern to generate the bolded caption title from.') .' '. $token_instructions,  
     '#disabled' => !$token_installed,  
   );  
   $form['properties']['img_assist_load_description'] = array(  
     '#type' => 'radios',  
     '#title' => t('Preset caption text'),  
     '#default_value' => variable_get('img_assist_load_description', 1),  
     '#options' => array(t('Disabled'), t('Enabled')),  
     '#description' => t('If enabled, the body text from the image will be loaded as the caption by default.'),  
   );  
   $form['properties']['img_assist_description_pattern'] = array(  
     '#type' => 'textfield',  
     '#title' => t('Caption text pattern'),  
     '#default_value' => variable_get('img_assist_description_pattern', '[body]'),  
     '#size' => 60,  
     '#maxlength' => 255,  
     '#description' => t('The pattern to generate the caption text from.') .' '. $token_instructions,  
     '#disabled' => !$token_installed,  
   );  
   if ($token_installed) {  
     $form['properties']['token_help'] = array(  
       '#title' => t('Replacement patterns'),  
       '#type' => 'fieldset',  
       '#collapsible' => TRUE,  
       '#collapsed' => TRUE,  
     );  
     $form['properties']['token_help'][] = array(  
       '#value' => theme('token_help', 'node'),  
     );  
   }  
   if (module_exists('content')) {  
     $options = array();  
     $info = _content_type_info();  
     foreach ($info['content types']['image']['fields'] as $field) {  
       $options[$field['field_name']] = t($field['widget']['label']) .' ('. $field['field_name'] .')';  
     }  
     $form['properties']['img_assist_display_properties'] = array(  
       '#type' => 'checkboxes',  
       '#title' => t('Image properties shown'),  
       '#default_value' => variable_get('img_assist_display_properties', array()),  
       '#options' => $options,  
       '#description' => t('All selected CCK fields from the Image node will be displayed in the Image Assist pop-up window.'),  
     );  
     if (empty($options)) {  
       $form['properties']['img_assist_display_properties']['#description'] .= '<br />'. t('<strong>Note:</strong> The <a href="!content-type">Image content-type</a> does not contain any CCK fields currently.', array('!content-type' => url('admin/content/node-type/image/fields')));  
     }  
   }  
   
   // Image display settings.  
   $form['display'] = array(  
     '#type' => 'fieldset',  
     '#title' => t('Image display settings'),  
     '#collapsible' => TRUE,  
     '#collapsed' => TRUE,  
   );  
   $form['display']['img_assist_page_styling'] = array(  
     '#type' => 'select',  
     '#title' => t('Include img_assist.css on all pages for styling inline images?'),  
     '#default_value' => variable_get('img_assist_page_styling', 'yes'),  
     '#options' => array('yes' => t('yes'), 'no' => t('no')),  
     '#description' => t('Advanced users can customize their theme\'s CSS file so that inclusion of the img_assist.css file will not be necessary. See notes at the bottom of img_assist.css for details.'),  
   );  
   
   return system_settings_form($form);  
 }  
   
 /**  
  * Validate Image Assist settings.  
  */  
 function img_assist_admin_settings_validate($form, &$form_state) {  
   // img_assist_max_size must contain a value for width and height.  
   if (!preg_match('/\d+x\d+/', $form_state['values']['img_assist_max_size'])) {  
     form_set_error('img_assist_max_size', t('Allowed maximum inline image size has to indicate width and height, for example %example.', array('%example' => '200x300')));  
   }  
 }  
   
 /**  
213   * Implementation of hook_filter().   * Implementation of hook_filter().
214   */   */
215  function img_assist_filter($op, $delta = 0, $format = -1, $text = '') {  function img_assist_filter($op, $delta = 0, $format = -1, $text = '') {
# Line 546  function img_assist_nodeapi(&$node, $op, Line 272  function img_assist_nodeapi(&$node, $op,
272  }  }
273    
274  /**  /**
  * Menu callback; clears relevant caches, then redirects to the previous page.  
  *  
  * @see devel_cache_clear()  
  */  
 function img_assist_cache_clear() {  
   // clear core tables  
   $core = array('cache_filter', 'cache_page');  
   foreach ($core as $table) {  
     cache_clear_all('*', $table, TRUE);  
   }  
   drupal_set_message('Cache cleared.');  
   drupal_goto('admin/settings/img_assist');  
 }  
   
 /**  
275   * @defgroup img_assist_pages Image Assist Pages   * @defgroup img_assist_pages Image Assist Pages
276   * @{   * @{
277   * All but img_assist_loader() are in frames.   * All but img_assist_loader() are in frames.
# Line 1933  function img_assist_views_api() { Line 1644  function img_assist_views_api() {
1644   */   */
1645    
1646  /**  /**
  * Load all images into a static array.  
  */  
 function img_assist_load_images($tid = NULL, $uid = NULL) {  
   static $image;  
   
   if ($tid) {  
     foreach ($tid as $key => $term) {  
       if ($term == 0) {  
         unset($tid[$key]);  
       }  
     }  
     $image = NULL;  
   }  
   
   $where = '';  
   if ($uid > 0) {  
     $image = NULL;  
     $where = 'AND n.uid = '. db_escape_string($uid);  
   }  
   
   if (!$image) {  
     $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, i.*, f.* FROM {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {image} i ON n.nid = i.nid AND n.type = 'image' INNER JOIN {files} f ON f.fid = i.fid ". $where ." ORDER BY n.changed DESC"));  
     while ($node = db_fetch_object($result)) {  
       $node->filepath = file_create_path($node->filepath);  
       $dim = getimagesize($node->filepath, $info);  
       $node->width = $dim[0];  
       $node->height = $dim[1];  
       $image[$node->nid][$node->filename] = $node;  
   
       if ($tid) {  
         $tid2 = array();  
         foreach (taxonomy_node_get_terms($node) as $term) {  
           $tid2[] = $term->tid;  
         }  
         if (array_intersect($tid, $tid2) == $tid) {  
           $img[$node->nid][$node->filename] = $node;  
         }  
       }  
     }  
     $image = ($tid) ? $img : $image;  
   
     // Note: If we didn't use "LIKE 'image/%%'" here we could load other files.  
     // Might be interesting to expand on this someday.  
     if ($image) {  
       $result = db_query(db_rewrite_sql("SELECT n.nid, n.title, r.teaser, i.*, f.* FROM {image} i, {node} n INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = n.nid INNER JOIN {files} f ON f.fid = i.fid WHERE i.nid = n.nid AND f.filemime LIKE 'image/%%' AND n.nid NOT IN (". implode(array_keys($image), ', ') .") ". $where ." ORDER BY n.changed DESC"));  
       while ($node = db_fetch_object($result)) {  
         $node->filepath = file_create_path($node->filepath);  
         $dim = getimagesize($node->filepath, $info);  
         $node->width  = $dim[0];  
         $node->height = $dim[1];  
         $image[$node->nid][IMAGE_THUMBNAIL] = $node;  
         $image[$node->nid][IMAGE_ORIGINAL]  = $node;  
   
         if ($tid) {  
           $tid2 = array();  
           foreach (taxonomy_node_get_terms($node) as $term) {  
             $tid2[] = $term->tid;  
           }  
           if (array_intersect($tid, $tid2) == $tid) {  
             $img[$node->nid][IMAGE_THUMBNAIL] = $node;  
             $img[$node->nid][IMAGE_ORIGINAL] = $node;  
           }  
         }  
       }  
       $image = ($tid) ? $img : $image;  
     }  
   }  
   
   return $image;  
 }  
   
 /**  
1647   * Load an image from the database.   * Load an image from the database.
1648   */   */
1649  function img_assist_load_image($id, $derivatives = TRUE) {  function img_assist_load_image($id, $derivatives = TRUE) {

Legend:
Removed from v.1.106  
changed lines
  Added in v.1.107

  ViewVC Help
Powered by ViewVC 1.1.2