? LICENSE.txt ? nodeimageblock.install ? nodeimageblock.tpl.php Index: README.txt =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/nodeimageblock/README.txt,v retrieving revision 1.1 diff -u -p -r1.1 README.txt --- README.txt 9 Feb 2006 15:19:11 -0000 1.1 +++ README.txt 8 Nov 2009 20:40:43 -0000 @@ -1,40 +1,82 @@ -Module: Node Image Block -Author: Mike Carter +$Id$ +Node Image Block 2 +================== -Description -=========== -Displays all images that are attached to any node using the upload.module. +Node Image Block 2 is a Drupal module that provides a block that displays all +images attached to a node. Requirements -============ +------------ -* Drupal 4.5+ installation -* upload.module to attach images to nodes +To install Node Image Block 2 you need: + + * Drupal 6.x + * Upload module Installation -============ -* Copy the 'nodeimageblock' module directory in to your Drupal -modules directory as usual. +------------ + +Install Node Image Block 2 as follows: + +1. Enable and configure the Upload module, following the instructions for that + module . + +2. Download the latest stable version of Node Image Block 2 from its project + page . + +3. Unpack the downloaded file into sites/all/modules or the modules directory + of your site. + +4. Go to Administer » Site building » Modules, and enable the module. + + +Configuration, usage and theming +-------------------------------- + +For information about configuration, usage and theming of Node Image Block 2, +please see the online help provided by the module. Go to Administer » Help, and +click on the "Node Image Block 2" link. + + +Author +------ + +Node Image Block 2 is developed by Thomas Barregren +. The author can be contacted for paid +customizations of this module as well as Drupal consulting, installation, +development, and customizations. + +The development of Node Image Block 2 has been sponsored by + + * SSPA , and + * Webbredaktören . -Usage -===== -When editing a node, attach an image to it using the upload.module functionality. +Credits +------- -Untick the 'list' option to prevent the image(s) from being listed to -the public at the end of the node. +This module is a complete rewrite of the original Node Image Block developed by +Mike Carter . -In the Blocks configuration page (?q=admin/block) enable the 'Node Image' block -and assign it to a region on the page. +License +------- +Node Image Block 2. Copyright © 2007–2008 Thomas Barregren. +Node Image Block 2 is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2 of the License, or (at your option) any +later version. -Security -======== -To restrict who can see your 'contact card' nodes I suggest using the Simple_Access module. -Available from http://drupal.org/project/simple_access +Node Image Block 2 is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 51 Franklin +Street, Fifth Floor, Boston, MA 02110-1301, USA. Index: nodeimageblock.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/nodeimageblock/nodeimageblock.info,v retrieving revision 1.1 diff -u -p -r1.1 nodeimageblock.info --- nodeimageblock.info 2 Jan 2008 11:47:24 -0000 1.1 +++ nodeimageblock.info 8 Nov 2009 20:40:43 -0000 @@ -1,5 +1,13 @@ -; $Id: nodeimageblock.info,v 1.1 2008/01/02 11:47:24 tbarregren Exp $ -name = "Node Image Block" -description = "Provides a block to displays all images attached to a node." +; $Id: nodeimageblock.info,v 1.1.2.3 2008/01/03 19:51:57 tbarregren Exp $ +name = "Node Image Block 2" +description = "Provides a block that displays all images attached to a node." package = "Image" -dependencies = upload +dependencies[] = upload + +; Information added by drupal.org packaging script on 2008-01-03 +version = "6.x-2.1" +project = "nodeimageblock" +datestamp = "1199390708" + + +core = 6.x \ No newline at end of file Index: nodeimageblock.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/nodeimageblock/nodeimageblock.module,v retrieving revision 1.6 diff -u -p -r1.6 nodeimageblock.module --- nodeimageblock.module 2 Jan 2008 11:47:24 -0000 1.6 +++ nodeimageblock.module 8 Nov 2009 20:40:44 -0000 @@ -1,75 +1,494 @@ + * Node Image Block 2 is developed by Thomas Barregren. It is a complete + * rewrite of the original Node Image Block developed by Mike Carter. + * + * Author: + * Thomas Barregren + */ + + +/****************************************************************************** + * THEMEABLE FUNCTIONS + ******************************************************************************/ + +/** + * Themeable function for the container of the images to be viewed. + * + * @param images + * An array of image objects. An image object has following attributes: + * - src: + * The path to the image to be shown. If an imagecache preset has been + * chosen in the block settings, this path will reflect that preset. + * Otherwise it is the same as the path to uploaded image. + * - path: + * The path to the originally uploaded image. + * - desc: + * An description of the image as given in the node's file attachement + * fieldset. + */ +function theme_nodeimageblock($images) { + + global $theme_engine; + + // If the current theme engine is PHPTemplate and the current theme has a + // Node Image Block 2 template file, process the provided template file, and + // return the resulting output. Otherwise, return the default theming. + if ($theme_engine == 'phptemplate' && file_exists(path_to_theme() .'/nodeimageblock.tpl.php')) { + //$out = _phptemplate_callback('nodeimageblock', array('images' => $images)); + $out = theme_render_template(path_to_theme() . '/nodeimageblock.tpl.php', array('images' => $images)); + } + else { + + $out[] = '
'; + foreach ($images as $img) { + $out[] = '
'; + $out[] = ' '. $img->desc .''; + $out[] = '

'. $img->desc .'

'; + $out[] = '
'; + } + $out[] = '
'; + $out = implode("\n", $out); + } + + return $out; + +} + + +/****************************************************************************** + * CONSTANTS + ******************************************************************************/ + +/** + * Bitwise flag for viewing images that are checked in the node's file + * attachement fieldset to be listed. + */ +define('NODEIMAGEBLOCK_INCLUDE_LISTED', 0x01); + +/** + * Bitwise flag for viewing images that are not checked in the node's file + * attachement fieldset to be listed. */ +define('NODEIMAGEBLOCK_INCLUDE_NOT_LISTED', 0x02); +/****************************************************************************** + * HOOKS + ******************************************************************************/ + /** * Implementation of hook_block(). - * - * Displays all images that are attached to the current node */ -function nodeimageblock_block($op = 'list', $delta = 0) { - if ($op == 'list') { - $block[0]['info'] = 'Node Image'; - } - elseif($op == 'view') { - if(arg(0) == 'node') { - $nid = arg(1); - if ($node = node_load(array('nid' => $nid))) { - - // Get all images associated with this node - $imagesrc = _nodeimageblock_get_node_images($node); - - if(count($imagesrc) > 0) { - $output = ''; - foreach($imagesrc as $img) { - $output .= theme('nodeimageblock_block_item', $node, $img); - } - - $block['subject'] = ''; - $block['content'] = theme('nodeimageblock_block', $output); - } - } - } +function nodeimageblock_block($op, $delta = 0, $edit = array()) { + $function = 'nodeimageblock_block_'. $op; + if (function_exists($function)) { + return $function($delta, $edit); } +} +/** + * Implementation of hook_help(). + */ +function nodeimageblock_help($path, $arg) { + switch ($path) { + case 'admin/help#nodeimageblock': + return _nodeimageblock_help(); + } +} + +/** + * Implementation of hook_theme(). + */ +function nodeimageblock_theme() { + return array( + 'nodeimageblock' => array( + 'arguments' => array('images' => NULL) + ) + ); +} + +/****************************************************************************** + * IMPLEMENTATION OF THE BLOCK API + ******************************************************************************/ + +/** + * Implements the 'list' operator of te hook_block(). + */ +function nodeimageblock_block_list() { + $block[0]['info'] = 'Node Image Block 2'; return $block; } -function theme_nodeimageblock_block($items) { - $output = '
'; - $output .= $items; - $output .= '
'; - return $output; -} - -function theme_nodeimageblock_block_item($node, $imagesrc) { - $output = ' -
- -
'; - - return $output; -} - -function _nodeimageblock_get_node_images($node) { - $filepath = ''; - - // -- if upload.module is enabled - if($files = module_invoke('upload', 'load', $node)) { - $image_mime = array("image/gif", "image/png", "image/jpeg", "image/pjpeg"); - $images = array(); - - foreach($files as $key => $file){ - - // --- Is the file an image? - if(in_array($file->filemime, $image_mime)) { - $images[] = file_create_url($file->filepath); - } - } - } - return $images; -} \ No newline at end of file +/** + * Implements the 'configure' operator of te hook_block(). + */ +function nodeimageblock_block_configure($delta) { + + // Ask for which images to include. + $options = array( + NODEIMAGEBLOCK_INCLUDE_LISTED | NODEIMAGEBLOCK_INCLUDE_NOT_LISTED => 'All attached images', + NODEIMAGEBLOCK_INCLUDE_LISTED => 'Only attached images that are listed', + NODEIMAGEBLOCK_INCLUDE_NOT_LISTED => 'Only attached images that are not listed', + ); + $form[nodeimageblock_images_to_include] = array( + '#type' => 'select', + '#title' => 'Images to show', + '#description' => 'Select which attached images to show.', + '#options' => $options, + '#default_value' => nodeimageblock_variable_images_to_include(), + ); + + // Ask for imagecache preset to use (if any). + if (module_exists('imagecache')) { + $options = _imagecache_get_presets(); + $options[0] = t(''); + ksort($options); + $form[nodeimageblock_imagecahce_preset] = array( + '#type' => 'select', + '#title' => 'Imagecache preset', + '#description' => 'Select the Imagecache preset to use for the images in the Node Image Block 2.', + '#options' => $options, + '#default_value' => nodeimageblock_variable_imagecahce_preset(), + ); + } + + return $form; + +} + +/** + * Implements the 'save' operator of te hook_block(). + */ +function nodeimageblock_block_save($delta, $edit) { + nodeimageblock_variable_images_to_include($edit['nodeimageblock_images_to_include']); + nodeimageblock_variable_imagecahce_preset($edit['nodeimageblock_imagecahce_preset']); +} + +/** + * Implements the 'view' operator of te hook_block(). + */ +function nodeimageblock_block_view($delta) { + + // Abort if the page viewed isn't a node. + if (arg(0) != 'node' || !is_numeric($nid = arg(1))) return; + + // Load the images. Abort if there are no images. + if (!($images = _nodeimageblock_images($nid))) return; + + // Get the base path for the original file path and the source path. + $path_base = base_path(); + $src_base = _nodeimageblock_source_base(); + + // Build the image objects that will be passed into the themable function. + foreach ($images as $image) { + $item = new stdClass(); + $item->path = "$path_base$image->filepath"; + $item->desc = $image->description; + $item->src = "$src_base$image->filepath"; + $items[] = $item; + } + + // Theme and return the block. + $block['subject'] = ''; + + $block['content'] = theme('nodeimageblock', $items); + + return $block; + +} + +/** + * Returns an array of file object representing image files attached to the + * node id $nid. + */ +function _nodeimageblock_images($nid) { + if (($files = module_invoke('upload', 'load', node_load($nid)))) { + return array_filter($files, '_nodeimageblock_images_filter'); + } +} + +/** + * Returns true if $file is an image which should be viewed. + */ +function _nodeimageblock_images_filter($file) { + static $image_mime = array("image/gif", "image/png", "image/jpeg", "image/pjpeg"); + $flags = nodeimageblock_variable_images_to_include(); + return in_array($file->filemime, $image_mime) && ($flags & NODEIMAGEBLOCK_INCLUDE_LISTED && $file->list || $flags & NODEIMAGEBLOCK_INCLUDE_NOT_LISTED && !$file->list); +} + +/** + * Returns the base path of the images. + */ +function _nodeimageblock_source_base() { + $base_path = base_path(); + $preset = nodeimageblock_variable_imagecahce_preset(); + if ($preset && module_exists('imagecache')) { + $preset = _imagecache_preset_load($preset); + $base_path .= file_directory_path() ."/imagecache/$preset/"; + } + return $base_path; +} + + +/****************************************************************************** + * PERSISTED VARIABLES + *****************************************************************************/ + +/** + * The persisted variable 'images_to_include' contains the flags indicating + * which images to be included. + */ +function nodeimageblock_variable_images_to_include($include = null) { + return _nodeimageblock_variable('nodeimageblock_images_to_include', $include, NODEIMAGEBLOCK_INCLUDE_LISTED | NODEIMAGEBLOCK_INCLUDE_NOT_LISTED); +} + +/** + * The persisted variable 'preset' containing the selected imagecache preset. + */ +function nodeimageblock_variable_imagecahce_preset($preset = null) { + return _nodeimageblock_variable('nodeimageblock_imagecahce_preset', $preset, 0); +} + +/** + * Sets and gets the named persisted variable. + */ +function _nodeimageblock_variable($name, $value = null, $default = null) { + if (isset($value)) { + variable_set($name, $value); + } + return variable_get($name, $default); +} + + +/****************************************************************************** + * HELP + *****************************************************************************/ + +/** + * Returns full help text. + */ +function _nodeimageblock_help() { + $help = << --> + +

+ Node Image Block 2 is a Drupal module that provides a block that displays all images attached to a node. +

+

+ Requirements +

+

+ To install Node Image Block 2 you need: +

+ +

+ Installation +

+

+ Install Node Image Block 2 as follows: +

+
    +
  1. +

    + Enable and configure the Upload module, following the instructions for that module. +

    +
  2. +
  3. +

    + Download the latest stable version of Node Image Block 2 from its project page. +

    +
  4. +
  5. +

    + Unpack the downloaded file into sites/all/modules or the modules directory of your site. +

    +
  6. +
  7. +

    + Go to Administer » Site building » Modules and enable the module. +

    +
  8. +
+

+ Configuration +

+

+ Node Image Block 2 is configured as described below: +

+
    +
  1. +

    + Go to Administer » Site building » Blocks and enable Node Image Block 2. +

    +
  2. +
  3. +

    + Click on the configure link of Node Image Block 2, and locate the Block specific settings. +

    +
  4. +
  5. +

    + Enter the title of the block in the text field called Block title. Leave empty (or write <none>) for no title. +

    +
  6. +
  7. +

    + In the drop down menu called Images to show, choose whether to display all images or only those images that are checked or those not checked to be included in the Upload module's list of attached files. +

    +
  8. +
  9. +

    + Make sure the remaning block settings are as desired, and press the Save block button. +

    +
  10. +
+

+ If the Imagecache module is installed, there is a third settings available in the Block specific settings. It is configured as follows: +

+
    +
  1. +

    + If not already existing, go to Administer » Site configuration » Image cache and add at least one preset that can be used to generate and cache resized and/or cropped versions of the images to be displayed. Return to the configuration page of Node Image Block 2. +

    +

    + In the drop down menu called Imagecache preset, choose the preset to use on the images displayed by Node Image Block 2. +

    +
  2. +
+

+ Usage +

+

+ It is trivial to use Node Image Block 2. Just upload one or more images to the node. For each image to be displeyd, enter a description and make sure that the List checkbox is set according to the Node Image Block 2 settings. +

+

+ Theming +

+

+ The default theming of Node Image Block 2 follows: +

+
+  <div id="nodeimageblock">
+    <div>
+      <img src="\$src" alt="\$desc" title="\$desc" />
+      <p>\$desc</p>
+    </div>
+  </div>
+
+

+ where the inner <div>-block is repeared for each image to be displayed. \$src is the path to the image to be displayed and \$desc is the description of the image. +

+

+ Template file +

+

+ The easiest way to change this theming, is to copy nodeimageblock.tpl.php from the folder with the Node Image Block 2 module, e.g. site/all/modules/nodeimageblock, to the folder containing the theme's page.tpl.php and edit is as needed. This works for all themes based on the built-in PHPTemplate theme engine. +

+

+ Themable function +

+

+ For advanced themers, and themes not based on the PHPTemplate theme engine, it is possible to override the themable function theme_nodeimageblock(\$images), where \$images is an array of of image objects. Each image object has following attributes: +

+
+
\$src
+
+

+ The path to the image to be shown. If an imagecache preset has been chosen in the block settings, this path will reflect that preset. Otherwise it is the same as the path to uploaded image. +

+
+
\$path
+
+

+ The path to the originally uploaded image. +

+
+
\$desc
+
+

+ A description of the image as given in the node's file attachement fieldset. +

+
+ +
+

+ The default implementation returns the default theming described in the previous subsection. +

+

+ Author +

+

+ Node Image Block 2 is developed by Thomas Barregren. The author can be contacted for paid customizations of this module as well as Drupal consulting, installation, development, and customizations. +

+

+ The development of Node Image Block 2 has been sponsored by +

+ +

+ Credits +

+

+ This module is a complete rewrite of the original Node Image Block developed by Mike Carter. +

+

+ License +

+

+ Node Image Block 2 !version. Copyright © 2007–!year Thomas Barregren. +

+

+ Node Image Block 2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. +

+

+ Node Image Block 2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +

+

+ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +

+EOT; + + $version = str_replace(array('$Re'.'vision:', ' $'), array('', ''), '$Revision: 2.x $'); + $year = substr('$Date: 2008/01/03 00:00:00 $', 7, 4); + return t($help, array('!version' => $version, '!year' => $year)); + +}