Add couloir slideshow dynamic into block or custom template
| Project: | Couloir Slideshow |
| Version: | 6.x-1.6 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
I create a new function dynamic_couloir_slideshow_block from the original code to generate the couloir slideshow for my nodes which uploaded some images belongs to itself with custom image source path.
You may add this function to the end of couloir_slideshow.module file.
function dynamic_couloir_slideshow_block($dynamic_settings = array('couloir_slideshow_disable_caption'=>
false, 'couloir_slideshow_imagepath'=>'1', 'wmax'=>500, 'hmax'=>500,
'number'=>1, 'order'=>'random', 'autoplay'=>1, 'autoplay_dur'=>10000)) {
$block = array();
$settings['wmax'] = isset($dynamic_settings['wmax'])?$dynamic_settings['wmax']:500;
$settings['hmax'] = isset($dynamic_settings['hmax'])?$dynamic_settings['hmax']:500;
$settings['number'] = isset($dynamic_settings['number'])?$dynamic_settings['number']:'1';
$settings['order'] = isset($dynamic_settings['order'])?$dynamic_settings['order']:'random';
$settings['autoplay'] = isset($dynamic_settings['couloir_slideshow_autoplay'])?$dynamic_settings['coul
oir_slideshow_autoplay']:1;
$settings['autoplay_dur'] = isset($dynamic_settings['couloir_slideshow_autoplay_dur'])?$dynamic_settin
gs['couloir_slideshow_autoplay_dur']:'10000';
$settings['couloir_slideshow_imagepath'] = isset($dynamic_settings['couloir_slideshow_imagepath'])?$dy
namic_settings['couloir_slideshow_imagepath']:'';
$settings['couloir_slideshow_disable_caption'] = isset($dynamic_settings['couloir_slideshow_disable_ca
ption'])?$dynamic_settings['couloir_slideshow_disable_caption']:flase;
$settings['show_thumbnails'] = isset($dynamic_settings['show_thumbnails'])?$dynamic_settings['show_thu
mbnails']:'both';
// Set default path
$imagepath= file_directory_path() . '/' . $settings['couloir_slideshow_imagepath'];
$imagearray = getImageArray($imagepath, $settings);
$slideheader = "<script type=\"text/javascript\">\n";
$slideheader .= getHeader($imagearray, $imagepath , $settings) . "\n";
$slideheader .= "</script>\n";
$caption = '';
if(!$settings['couloir_slideshow_disable_caption']){
$caption = '
<div id="CaptionContainer">
<p><span> </span> <span id="Counter"> </span> <span id="Caption"> </s
pan></p>
</div>
';
}
$url = base_path().drupal_get_path('module', 'couloir_slideshow');
$html = '<!-- slideshow ' . $delta . ' -->
<div id="OuterContainer">
<div id="PhotoContainer">
<img id="Photo" src="' . $url . '/img/c.gif" alt="Photo: Couloir" />
<div id="LinkContainer">
<a href="#" id="PrevLink" title="Previous Photo"><span>Previous</spa
n></a>
<a href="#" id="ViewPhoto" rel="lightbox" title="View Photo"><span>V
iew Photo</span></a>
<a href="#" id="NextLink" title="Next Photo"><span>Next</span></a>
</div>
</div>
</div>'
.$caption.
'<script type="text/javascript">
// <![CDATA[
Behaviour.register(myrules);
// ]]>
</script>';
if (count($imagearray) > 0) {
drupal_set_html_head($slideheader);
drupal_add_js(drupal_get_path('module', 'couloir_slideshow') .'/js/behaviour.js');
drupal_add_js(drupal_get_path('module', 'couloir_slideshow') .'/js/jquery.fxqueues-2.0.2.js');
drupal_add_js(drupal_get_path('module', 'couloir_slideshow') .'/js/couloir-slideshow.js');
drupal_add_css(drupal_get_path('module', 'couloir_slideshow') .'/css/couloir.css');
$block['subject'] = 'Slideshow';
$block['content'] = $html;
}
if (count($imagearray) == 1){
$block['content'] = '<a rel="lightbox" href="/' . $imagepath . '/' . $imagearray[0]['nam
e'] . '" alt="Photo: Couloir"><img src="/' . $imagepath . '/' . $imagearray[0]['name'] . '" width="'. $s
ettings['wmax'] . '" height="' . $settings['hmax'] .'"></img></a>';
}
return $block['content'];
}To add the couloir slideshow to your node, you should set the settings before like this. And Change the couloir_slideshow_imagepath setting to yours image path.
<?php
$sldshowsettings = array();
$sldshowsettings['couloir_slideshow_disable_caption'] = true;
$sldshowsettings['couloir_slideshow_imagepath'] = $node->uid . '/' . $node->type . '/' . $node->nid;
$sldshowsettings['number'] = 1;
$sldshowsettings['order'] = 'random';
$sldshowsettings['autoplay'] = 1;
$sldshowsettings['autoplay_dur'] = 10000;
$sldshowsettings['wmax'] = 400;
$sldshowsettings['hmax'] = 300;
$sldshowsettings['show_thumbnails'] = 'no';
print dynamic_couloir_slideshow_block($sldshowsettings);
?>Also I add one more setting named show_thumbnails to let the Thumbnails shows or not. This have 3 value, 'both', 'only', 'no' .
'both' allows original image and the Thumbnails to show. 'no' will block the Thumbnails. And 'only' will allow only Thumbnails to show.
To let the show_thumbnails work, I add this code after
if ($file == "." || $file == ".." || $file == ".DS_Store"
|| is_dir($path ."/".$file) || $ext == "html" || $ext == "htm" |
| $ext == "php") continue;in getImageArray function.
I only test it with images uploaded by ImageField moude , It may not work with Image moudle. You may test it yourself.
Here is the code I have add.
if($settings['show_thumbnails']=='no'){
if(ereg('.thumb',$file)) continue;
}
if($settings['show_thumbnails']=='only'){
if(!ereg('.thumb',$file)) continue;
}I also find that when the image source folder only has one image, the couloir slideshow not work on my site. It may be a bug or not I have to create more code to let it shows the only image right. You may notice them in the dynamic_couloir_slideshow_block function.
These code work with ImageField moude and lightbox2 on my site, it may be not work with other moudles but It should be a start for those who want create custom couloir slideshow on their node with dynamic image source.
that's all.
