Slideshowpro with cck imagefield.

hakkisak - November 26, 2007 - 02:47
Project:SlideShowPro
Version:5.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

as has been previously written about in here, when using this module with an imagefield there is no /imagename.jpg added to the file path,

It says on this modules page that it is possible to override a theme function but there is no documentation or any help anywhere on how to do this? Any ideas?

#1

hakkisak - November 29, 2007 - 01:46
Component:Documentation» Code

I am happy to pay for someone to help me rewrite the function to be able to use imagefield images with SSP,
I have managed to hack it so that it loads the first image but can't get the others from a multiple value field,

Any ideas? I have the money in paypal for anyone that can help me.

#2

alex_b - November 29, 2007 - 14:13

hey, until when do you need this? I am really tied up in work here, but I could help over the weekend.

#3

hakkisak - November 30, 2007 - 00:37

Hey that would be great, it is really on an ASAP basis, at the moment admin is by using drupal, and an external slideshowpro director setup, would be great if it could use imagefields because i believe it would be an amazing step between linking drupal and flash that much easier.

if you could contact me on hakkisak@gmail.com when you are available that would be much appreciated

#4

alex_b - December 3, 2007 - 15:34

Hey,

check out the latest version of slideshowpro, it has a themable theme_slideshowpro_xml_image() function - which makes it a lot easier to integrate w/ cck.

Here is how you override the slideshowpro function so that you can use ssp image field with cck:

<?php
/**
* Format an image.
*/
function theme_slideshowpro_xml_image(&$node, $size = 'preview') {   
 
$output = '<img src="%src" title="%title" caption="%caption" link="%link" target="_blank" tn="%thumb" />'."\n";
 
$variables = array(
   
// REPLACED: '%src' => slideshowpro_get_image_path() . basename($node->images[$size]),
    // NEW. (the name "field_picture" depends on the actual name of your cck field)
  
'%src' => base_path() . $node->field_picture[0]['filepath'],
   
'%title' => check_plain($node->title),
   
'%caption' => variable_get('slideshowpro_title_as_caption', 0) ?
     
check_plain($node->title) : check_plain(truncate_utf8($node->body, 100, TRUE, TRUE)),
   
'%link' => url('node/'.$node->nid, NULL, NULL, TRUE),
   
//'%thumb' => str_replace('images/','http://icad.devseed.org/sites/default/files/images/',str_replace('en/', '',url($node->images['thumbnail'], NULL, NULL, FALSE))));
   
'%thumb' => str_replace('en/', file_directory_path().'/',url($node->images['thumbnail'], NULL, NULL, TRUE)));
   
//'%thumb' => url($node->images['thumbnail'], NULL, NULL, TRUE));
    //'%thumb' => 'http://icad.devseed.org/sites/default/files/images/DSC_0134_0.thumbnail.JPG');
 
return strtr($output, $variables);
}
?>

The package scripts might not have run yet, so the development snapshot might not contain this latest patch. You can grab the latest version always from the repository. Here is the diff of the latest patch: http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/slideshowpr...

Let me know if I could help you,

Alex

#5

hakkisak - December 3, 2007 - 22:38

you are a champion! i'll update this now,

#6

hakkisak - December 3, 2007 - 23:37

updated with the new code, but it can still only load the first image from the field,

<?php
$node
->field_imagename[0]['filepath'],
?>

the [0] means it will only load the first image.
i really need it to load from a multiple values cck imagefield all of the images, can this be done so that the xml feed is written out as one item per [0] imagefield value?

#7

hakkisak - December 3, 2007 - 23:36

--

#8

alex_b - December 4, 2007 - 14:39

Hey hakkisak,

Override theme_slideshowpro_feed().

This is the part that you need to modify:

<?php
 
foreach ($nodes as $n) {
   
$node = node_load($n->nid);
   
$tids = array();
    if (
$n->tid) {
     
$tids = array($n->tid);
     
$album_terms[$n->tid] = taxonomy_get_term($n->tid);
    }
   
// If no image gallery tid was passed in, get tids from node.
   
else {
      foreach (
$node->taxonomy as $term) {
        if (
$term->vid == $gallery_vid) {
         
$album_terms[$term->tid] = $term;
         
$tids[] = $term->tid;
        }
      }
    }
   
// Stick images with no album in an album called "In no album"
   
if (!count($tids)) {
     
$tids = array(0);
     
$album->name = t('In no album');
     
$album_terms[0] = $album;
    }
   
$image = theme('slideshowpro_xml_image', $node, $size);
   
// An image can be in more than one album.
   
foreach ($tids as $tid) {
     
$albums[$tid][] = $image;
    }
  }
?>

For each node cycle through each image on the node and pass in the results into theme('slideshowpro_xml_image', ...) - you see that theme_slideshowpro_xml_image() takes a node as parameter - this won't make sense in your scenario. But as you are already overriding this function you can define the parameters freely. You will want to define the function similar to this:

<?php
phptemplate_slideshowpro_xml_image
($nid, $title, $body, $imagepath)
?>

Let me know if this helps.

Alex

#9

hakkisak - December 5, 2007 - 06:26

hmm, that really doesn't help me much at all.

#10

alex_b - December 5, 2007 - 14:58

Ok. Forget about #8. I just did it and it is actually much easier:

<?php
/**
* Format an image.
*/
function phptemplate_slideshowpro_xml_image(&$node, $size = 'preview') { 
 
$format_str = '<img src="%src" title="%title" caption="%caption" link="%link" target="_blank" tn="%thumb" />'."\n";

 
// Instead of just showing the first picture in the image field variable, we cycle through all of them.
  // As before, $node->field_picture depends on the name of your image field.
 
foreach ($node->field_picture as $picture) {
   
   
// If you use imagecache - "default" and "thumbnail" are your presets from admin/settings/imagecache
   
$default = file_create_url("imagecache/default/" . $picture['filepath']);
   
$thumbnail = file_create_url("imagecache/thumbnail/" . $picture['filepath']);
   
/* If you don't use imagecache - not recommendable
    $default = file_create_url($picture['filepath']);
    $thumbnail = $default;
    */
   
$variables = array(
     
'%src' => $default,
     
'%title' => check_plain($node->title),
     
'%caption' => variable_get('slideshowpro_title_as_caption', 0) ?
       
check_plain($node->title) : check_plain(truncate_utf8($node->body, 100, TRUE, TRUE)),
     
'%link' => url('node/'. $node->nid, NULL, NULL, TRUE),
     
'%thumb' => $thumbnail,
      );
   
$output .= strtr($format_str, $variables) ."\n";
  }
  return
$output;
}
?>

#11

vanderlip - December 9, 2007 - 13:13

Sorry, relatively new to Drupal and with limited coding skills.

I am using imagefield with imagecache. I have a node type called image with a single image for each node. I am not using the image module.

I would like to use views and the Drupal Slideshowpro module to build slide shows of images based on the filters in the view. I don't have galleries set up.

I have followed the install instructions, watched the video, and tried to follow the thread above, but I just don't have the knowledge to get it working? I can get the viewer showing up in the node, but can't get my view to create XML of nodes based on filters in the view. Any guidance would be appreciated.

Thanks in advance.

#12

hakkisak - December 17, 2007 - 23:06

thanks Alex_b,

I have been hacking around inside the module a bit and have something working alright,
maybe for future releases it would be great if you could choose the field in the views setup and have it replace the $field_picture variable as well as be able to choose the imagecache preset without having to override inside the code.

This would make it possible to make several feeds with different imagecache sizes, aswell as load flashvideo data, say for instance have a view setup as a list view with say $field_flashvideo and $field_picture, and filter by any normal views filter,

I have managed to use different imagecache sizes for different feeds so far by duplicating the module, and overriding following the last post.

#13

jimi089 - December 31, 2007 - 21:12

This didn't seem to do it for me. I changed the file paths for imagecache but nothing is getting passed through properly to my XML.

#14

jimi089 - December 31, 2007 - 22:47

Well, I got the XML to parse correctly tweaking Alex's code (thanks!)

However, the XML is not being passed to the SWF file correctly. In my Log entries I can see that it's looking for images.xml at the root of the site even though my embed code is telling it to look elsewhere.

My embed code is:

[ssp|path=frontpageimages|width=450|height=350|params=navAppearance:Hidden]

But it isn't looking at root/frontpageimages/images.xml

It's looking at root/images.xml

Any ideas?

#15

alex_b - January 2, 2008 - 14:31

@jimi089 - i moved the topic to: http://drupal.org/node/205610

Alex

#16

avolve - May 16, 2008 - 12:17

i have had my first attempt to set up this module (i used SSP on a site some time ago—with manual modification of the XML file).

I have successfully generated an XML feed from my CCK imagefields and placed the slideshow in a a node (working).

I have noted an issue, not yet certain of the source. In Safari 3.1 (OS X 10.0.0.14) the Slideshow works fine as would be expected, in Firefox (2.0.0.14) the following text is given above the ssp.swf in the node, irrespective of theme*:

codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="500" height="500" id="ssp-player-1" align="middle">

Firefox does not all seem to like the swf file either. Scrolling the page causes the background color/nav/etc of the ssp.swf file to disappear.

Has anyone noted/resolved this issue (the code)? I have not posted a new issue as am unsure if it is related to the override??

*I have tried this with pushbutton and Garland.

#17

SocialNicheGuru - May 29, 2008 - 23:38

I was told SlideShowPro is a great solution, but after reading the last entry I am hesitant.

Chris

#18

avolve - May 31, 2008 - 08:27

Don't let the minor issue i currently have with this module dissuade you. It will be easy to resolve once the actual bug is found.

[i started an issue for it and hope to have it resolved soon — http://drupal.org/node/261373]

#19

spunky_chrispi - June 4, 2008 - 17:26

avolve - You might want to check the order of your filters. I fixed this problem by moving the SSP filter after the Line break converter.

#20

avolve - June 8, 2008 - 08:54

Thanks spunky_chrispi—changing the order of the input filters has fixed the code issue in FF.

It has not had any impact on the issue with the background color/nav/etc of the ssp.swf file disappearing. Anyone else note this or could it just be my local install/FF/Flash??

#21

light-blue - July 9, 2008 - 00:40

REGARDING COMMENT #10 ABOVE...

Just a usage clarification for SSP with CCK. You should

1) Change NO code in the slideshowpro module
2) Copy and paste AlexB's snippet above (comment #10) somewhere like template.php in your template (e.g. Garland)
3) Change foreach ($node->field_picture as $picture) to
foreach ($node->field_the_name_of_your_image_field_which_you_verify_in_your_cck_node_type_under_manage_fields_then_name as $picture)
4) Change imagecache/default/ to
imagecache/your_big_picture_preset_name (see http://example.com/admin/build/imagecache)
5) Change imagecache/thumbnail to
imagecache/your_thumbnail_preset_name (see http://example.com/admin/build/imagecache)

Also, below is an example (improvements welcome!) of using SlideShowPro (ssp) and its Views XML integration to dynamically read Ubercart's list of products (from a CCK field I'm using called, creatively enough, field_image_cache). This approach is cool because as you add / delete products, SlideShowPro will showcase and link to them with watermarks and or any other documented ssp parameters you care to throw at it. If you only want to show most recent products, you can change your Views filter. I'm using this for the homepage of an e-commerce website.

EXAMPLE: THIS SNIPPET WENT INTO MY TEMPLATE.PHP

<?php
/**
* Format an image.
*/
function phptemplate_slideshowpro_xml_image(&$node, $size = 'preview') {
 
$format_str = '<img src="%src" title="%title" caption="%caption" link="%link" target="_blank" tn="%thumb" />'."\n";

 
// Instead of just showing the first picture in the image field variable, we cycle through all of them.
  // As before, $node->field_picture depends on the name of your image field.
 
if ($node->field_image_cache)
  foreach (
$node->field_image_cache as $picture) {
  
   
// If you use imagecache - "default" and "thumbnail" are your presets from admin/settings/imagecache
   
$default = file_create_url("imagecache/scale-250-pixels/" . $picture['filepath']);
   
$thumbnail = file_create_url("imagecache/scale-crop-100-pixels/" . $picture['filepath']);
   
/* If you don't use imagecache - not recommendable
    $default = file_create_url($picture['filepath']);
    $thumbnail = $default;
    */
   
$variables = array(
     
'%src' => $default,
     
'%title' => check_plain($node->title),
     
'%caption' => variable_get('slideshowpro_title_as_caption', 0) ?
       
check_plain($node->title) : check_plain(truncate_utf8($node->body, 100, TRUE, TRUE)),
     
'%link' => url('node/'. $node->nid, NULL, NULL, TRUE),
     
'%thumb' => $thumbnail,
      );
   
$output .= strtr($format_str, $variables) ."\n";
  }
  return
$output;
}
?>

EXAMPLE: THE SNIPPET BELOW EMBEDS ADOBE FLASH'S AC_RUNACTIVECONTENT.JS AND THE SSP VIEWS XML FEED OF CCK IMAGE FIELD / IMAGECACHE. IN MY CASE, I PUT THIS IN A PANELS2 PANE WITH THE PHP INPUT FILTER TURNED ON

<?php
//drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE);
drupal_add_js('files/AC_RunActiveContent.js');
$player="/files/ssp_default.swf";
$playerName="/files/ssp_default";
$width=480; //550 default
$height=330; //400 default
$xml='http://example.com/ssp_view%26parameters=';
?>



<script language="javascript">
if (AC_FL_RunContent == 0) {
alert("This page requires AC_RunActiveContent.js.");
} else {
AC_FL_RunContent(
'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
'width', '<?php print ($width); ?>',
'height', '<?php print ($height); ?>',
'src', '<?php print ($player); ?>',
'quality', 'high',
'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
'align', 'middle',
'play', 'true',
'loop', 'true',
'scale', 'showall',
'wmode', 'window',
'devicefont', 'false',
'id', '<?php print ($player); ?>',
'bgcolor', '#ffffff',
'name', '<?php print ($player); ?>',
'menu', 'true',
'allowFullScreen', 'true',
'allowScriptAccess','sameDomain',
'movie', '<?php print ($playerName); ?>',
'salign', '',
'FlashVars','xmlfilepath=<?php print ($xml); ?>'
); //end AC code
}
</script>
<noscript>
<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="test0836" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="FlashVars" value="xmlfilepath=<?php print ($xml); ?>" />
<param name="allowFullScreen" value="true" />
<param name="movie" value="<?php print ($player); ?>" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> <embed src="<?php print ($player); ?>" FlashVars="xmlfilepath=<?php print ($xml); ?>" quality="high" bgcolor="#ffffff" width="<?php print ($width); ?>" height="<?php print ($height); ?>" name="player" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</noscript>

#22

iaminawe - August 19, 2008 - 14:23

sounds great light blue, I am going to give this a try...

Do you have a sample link for the e-commerce frontend you used slideshowpro with?

#23

Sean B Fuller - April 8, 2009 - 03:14

Great post. I'm using this for d6 and wanted to drop a quick warning for others. The issues I ran into are:

1. The call to url() now takes an array of attributes instead of a list of params. You'll get a white screen. The new version of the module handles this correctly. People who are using the above code might run into it, however. Pull the theme function from slideshowpro.theme.inc in the 6.x dev and start from that.

2. I ran into some issues with the filepath not working as I think it did in d5. I was able to get around this with a call to: imagecache_create_path('thumbnail', $picture['filepath']);

Hope that helps someone out there. Thanks for the great module!

#24

iaminawe - September 13, 2009 - 10:48

Thanks for clarifying this change for Drupal 6...

Here is the adapted code that worked for me

/**
* Format an image.
*/
function themename_slideshowpro_xml_image(&$node, $size = 'preview', $title_caption = 0) {
$output = ''."\n";

foreach ($node->field_image_field_main as $picture) {
$default = file_create_url("imagecache/homeslideshow/" . $picture['filepath']);
$thumbnail = file_create_url("imagecache/thumbnail/" . $picture['filepath']);

$variables = array(
'%src' => $default,
'%title' => check_plain($node->title),
'%caption' => $title_caption ? trim(check_plain($node->title)) : trim(check_plain(truncate_utf8($node->body, 100, TRUE, TRUE))),
'%link' => url('node/'. $node->nid, array('absolute' => TRUE)),
'%thumb' => $thumbnail
);
}
return strtr($output, $variables);
}

/**
* Theme output.
*/
function themename_slideshowpro_embed($output, $id) {
return ''. $output .'';
}

 
 

Drupal is a registered trademark of Dries Buytaert.