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

Contents of /contributions/modules/nodeimageblock/nodeimageblock.module

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


Revision 1.6 - (show annotations) (download) (as text)
Wed Jan 2 11:47:24 2008 UTC (22 months, 3 weeks ago) by tbarregren
Branch: MAIN
CVS Tags: DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5
Changes since 1.5: +1 -1 lines
File MIME type: text/x-php
#147348 by TBarregren. Upgrading to 5.x.
1 <?php
2 /* Drupal Module: Node Image Block
3 * Displays all images attached to any node using the upload.module
4 *
5 * @author: Mike Carter <mike@ixis.co.uk>
6 */
7
8
9 /**
10 * Implementation of hook_block().
11 *
12 * Displays all images that are attached to the current node
13 */
14 function nodeimageblock_block($op = 'list', $delta = 0) {
15 if ($op == 'list') {
16 $block[0]['info'] = 'Node Image';
17 }
18 elseif($op == 'view') {
19 if(arg(0) == 'node') {
20 $nid = arg(1);
21 if ($node = node_load(array('nid' => $nid))) {
22
23 // Get all images associated with this node
24 $imagesrc = _nodeimageblock_get_node_images($node);
25
26 if(count($imagesrc) > 0) {
27 $output = '';
28 foreach($imagesrc as $img) {
29 $output .= theme('nodeimageblock_block_item', $node, $img);
30 }
31
32 $block['subject'] = '';
33 $block['content'] = theme('nodeimageblock_block', $output);
34 }
35 }
36 }
37 }
38
39 return $block;
40 }
41
42 function theme_nodeimageblock_block($items) {
43 $output = '<div id="nodeimageblock">';
44 $output .= $items;
45 $output .= '</div>';
46 return $output;
47 }
48
49 function theme_nodeimageblock_block_item($node, $imagesrc) {
50 $output = '
51 <div class="nodeimage">
52 <img src="' . $imagesrc . '" alt="" />
53 </div>';
54
55 return $output;
56 }
57
58 function _nodeimageblock_get_node_images($node) {
59 $filepath = '';
60
61 // -- if upload.module is enabled
62 if($files = module_invoke('upload', 'load', $node)) {
63 $image_mime = array("image/gif", "image/png", "image/jpeg", "image/pjpeg");
64 $images = array();
65
66 foreach($files as $key => $file){
67
68 // --- Is the file an image?
69 if(in_array($file->filemime, $image_mime)) {
70 $images[] = file_create_url($file->filepath);
71 }
72 }
73 }
74 return $images;
75 }

  ViewVC Help
Powered by ViewVC 1.1.2