--- modules/taxonomy_image.module.orig 2004-05-31 20:09:10.065748665 -0400 +++ modules/taxonomy_image.module 2004-05-31 20:42:05.959680018 -0400 @@ -0,0 +1,291 @@ +, May 2004. +*/ + +/** + * Call this function from your theme or other php code to display the + * image associated with the given term id. An html tag will be returned + * if an image is found. The format of the link can be modified with the + * tags parameter. + * + * @param int $tid the term id. + * @param string $tags optional tags to add into the link + * + * @return string An html link. + */ +function taxonomy_image_display($tid, $tags = NULL) { + global $user; + + if (user_access('access taxonomy images') && + !$user->taxonomy_image_disable_images) { + // do lookup, return full display path + if ($image = db_fetch_object(db_query('SELECT path FROM {term_image} WHERE tid = %d', $tid))) { + $image->url = file_create_url($image->path); + } + else if (variable_get('taxonomy_image_recursive', 0)) { + // walk up the taxonomy hierarchy and look for an image + while ($parent = db_fetch_object(db_query('SELECT t.tid FROM {term_hierarchy} h, {term_data} t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name', $tid))) { + $tid = $parent->tid; + if ($image = db_fetch_object(db_query('SELECT path FROM {term_image} WHERE tid = %d', $tid))) { + // we found a parent with a configured image, use it + $image->url = file_create_url($image->path); + break; + } + } + } + if ($image->url) { + list($image->width, $image->height) = getimagesize($image->path); + // handle image resizing + switch (variable_get('taxonomy_image_resize', 0)) { + case 3: // exact + if ($width = variable_get('taxonomy_image_width', 0)) + $image->width = $width; + if ($height = variable_get('taxonomy_image_height', 0)) + $image->height = $height; + break; + case 2: // not less than + if (($width = variable_get('taxonomy_image_width', 0)) && + ($width > $image->width)) { + $width_scale = $image->width / $width; + } + if (($height = variable_get('taxonomy_image_height', 0)) && + ($height > $image->height)) { + $height_scale = $image->height / $height; + } + if ($height_scale || $width_scale) { + if ($width_scale && $height_scale) + $scale = min($width_scale, $height_scale); + else + $scale = $width_scale ? $width_scale : $height_scale; + $image->height = $image->height / $scale; + $image->width = $image->width / $scale; + } + break; + case 1: // not greater than + if (($width = variable_get('taxonomy_image_width', 0)) && + ($width < $image->width)) { + $width_scale = $image->width / $width; + } + if (($height = variable_get('taxonomy_image_height', 0)) && + ($height < $image->height)) { + $height_scale = $image->height / $height; + } + if ($height_scale || $width_scale) { + $scale = max($width_scale, $height_scale); + $image->height = $image->height / $scale; + $image->width = $image->width / $scale; + } + break; + } + return ""; + } + } + return ''; +} + +// standard Drupal functions +function taxonomy_image_perm() { + return array ('access taxonomy images', 'administer taxonomy images', 'can disable taxonomy images'); +} + +function taxonomy_image_help($section = '') { + switch ($section) { + case 'admin/system/modules/taxonomy_image': + case 'admin/system/modules#description': + $output = t('Upload and associate images with taxonomy terms.'); + break; + case 'admin/help#taxonomy_image': + $output .= t(' +
The taxonomy_image module allows site administrators to associate images with taxonomy terms. Once defined, this association allows Drupal themes to display images with site content. For example, the taxonomy_image module might be used to display a penguin with content about Linux, and a cheeseburger with content about junk food.
+The module allows both a one-to-one term-to-image relationship, and a many-to-one terms-to-image relationship.
+The taxonomy_image module requires that the taxonomy module also be enabled.
+With the taxonomy_image module enabled, images can be uploaded and associated with taxonomy terms at \'administer >> taxonomy >> images\'. On that page you will find tables containing all your vocabularies and terms. Next to each term is a link titled \'upload image\' which you can click to upload an image for that term. After clicking that link, you will be brought to another page with a small \'Add images\' form. Using the \'browse\' button you can select your image then click \'Save\'. +
Continue this process to upload appropriate images for your taxonomy terms. Note that by default images will be displayed at the size they were uploaded. Alternatively, you can go to \'administer >> configuration >> modules >> taxonomy_image\' to force the display height and/or width of all taxonomy images.
+For your users to be able to view the images you have uploaded, you will need to give them the necessary permissions. Only users with the \'access taxonomy images\' permission will see images. If you wish to give your users the ability to disable the images, also give them the \'can disable taxonomy images\' permission.
+A third permission, \'administer taxonomy images\', controls which users are allowed to configure taxonomy images.
+Taxonomy is a very powerful tool. One of its features is providing the ability to create hierarchical vocabularies, with which you can build a tree of terms. It is possible that an entire tree of terms, or even just a branch of terms, are all about a similar subject and should all be associated with the same image. By going to \'administer >> configuration >> modules >> taxonomy_image\', you can enable \'Recursive image disaply\'. With this option enabled, you only need to configure an image for the parent term, and all children will automatically inheret the same image (unless they are manually configured to display an alternative image).
+To actually display images from your theme, you will have to modify the theme to make a call to taxonomy_image_display(). When calling this function, you will need to pass in the taxonomy term for which an image should be displayed. For example, from your theme\'s \'_node\' function you might do the following: +
+ foreach (taxonomy_node_get_terms($node->nid) as $term) { + if ($image = taxonomy_image_display($term->tid)) { + $output .= "$image"; + } ++'); + break; + } + return $output; +} + +function taxonomy_image_link($type) { + if ($type == 'system' && user_access('administer taxonomy images')) { + menu('admin/taxonomy/image', t('images'), 'taxonomy_image_admin', 4); + menu('admin/taxonomy/image/add', t('Upload image'), 'taxonomy_image_admin', 4, MENU_HIDE); + return; + } + + return $links ? $links : array(); +} + +function taxonomy_image_user($type, $edit, $user) { + switch ($type) { + case 'edit_form': + if (user_access('can disable taxonomy images')) { + $form = form_checkbox(t('Disable images'), 'taxonomy_image_disable_images', 1, $user->taxonomy_image_disable_images, t('Check this box to disable the display of content images.')); + return array(t('Content images') => $form); + } + break; + } +} + +function taxonomy_image_settings() { + $group = form_radios(t('Resize action'), 'taxonomy_image_resize', variable_get('taxonomy_image_resize', 0), array(3 => 'Exact', 2 => 'Not less than', 1 => 'Not greater than', 0 => 'None'), t('This option allows you to control the size of images displayed by this module. If set to \'none\', images will not be resized, displayed exactly as they are uploaded. If set to \'not greater than\', images larger than the specified size will be scaled down. If set to \'not less than\', images smaller than the specified size will be scaled up. If set to \'exact\', images will be resized to exactly the specified dimension(s).')); + $group .= form_textfield(t('Image height'), 'taxonomy_image_height', variable_get('taxonomy_image_height', ''), 5, 6, t('Specify a height in pixels. If left blank or set to 0 this field is ignored.')); + $group .= form_textfield(t('Image width'), 'taxonomy_image_width', variable_get('taxonomy_image_width', ''), 5, 6, t('Specify a width in pixels. If left blank or set to 0 this field is ignored.')); + $output = form_group(t('Image size'), $group); + $group = form_radios(t('Recursive image display'), 'taxonomy_image_recursive', variable_get('taxonomy_image_recursive', 0), array(1 => 'Enabled', 0 => 'Disabled'), t('When enabled, taxonomy_image_display() will recursively search for an image to display, starting with the passed in term, then trying the term\'s parents. This functionality is only useful if you have defined hierarchical taxonomies, and multiple terms within a tree will share the same image. If this doesn\'t mean anything to you, leave this option disabled.')); + $output .= form_group(t('Advanced'), $group); + return $output; +} + +// taxonomy_image specific functions +function taxonomy_image_admin() { + $op = $_POST['op']; + $edit = $_POST['edit']; + + if (empty($op)) { + $op = arg(2); + } + + switch ($op) { + case 'image': + if (arg(3) == 'add') { + $output = taxonomy_image_form(object2array(taxonomy_image_get_term(arg(4)))); + break; + } + $output = taxonomy_image_overview(); + break; + case t('Save'): + $output = taxonomy_image_save($edit); + $output = taxonomy_image_overview(); + break; + case t('Delete'): + $output = taxonomy_image_delete($edit); + $output = taxonomy_image_overview(); + break; + default: + $output = taxonomy_image_overview(); + } + + print theme('page', $output); +} + +function taxonomy_image_overview() { + $output = '