Hello
I would like to share a slider that I integrated in my site.
You can see the result at
http://pierre.basmoreau.free.frIt is based on a Javascript code available free to
http://www.dynamicdrive.com/dynamicindex14/leftrightslide.htm that I adapted to integrate it in coppermine. This site (dynamicdrive) is a true gold mine for the developers !
The script chooses pictures random from the database (15 by default) and to make them move (scrolling) of right to left.
Each picture of the slider has a direct link to the album. 15 new pics are shown with each loading of page.
I had tested the MOD "Image Scroller based one Filmstrip", but I wanted a slider less important in occupation of screen and with a random choice.
Here thus complete script called "slider.php" that you will place at the root of your site:
<?php
/****************************************************************************
slider.php
this script choose random pics (15 by default) from your coppermine album.
Each picture of the slider has a direct link to the album. 15 new pics are shown with each loading of page.
It is based on a Javascript code available free to http://www.dynamicdrive.com/dynamicindex14/leftrightslide.htm
that I adapted to integrate it in coppermine.
*****************************************************************************/
// Initialisation
define('IN_COPPERMINE', true);
//For all tests only,uncomment the line "required..." and run the script by http://your-site/slider.php
//require('include/init.inc.php');
//Comment this line to integration in coppermine album
?>
<script type="text/javascript">
/**********************************************************************************************
* Initial javascript code is cutting to 2 parts :
* first part : initialisation
***********************************************************************************************
* Conveyor belt slideshow script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
**********************************************************************************************/
//Specify the slider's width (in pixels)
var sliderwidth="1000px"
//Specify the slider's height (by default, height of pic)
var sliderheight="75px"
//Specify the slider's slide speed (larger is faster 1-10)
var slidespeed=1
//configure background color: no color is transparent and show the background color of your theme
slidebgcolor=""
//Specify the slider's images
var leftrightslide=new Array()
var finalslide=''
</script>
<?php
/******************************************************************************
PHP Code :
*******************************************************************************/
// maximum pics to show
$limit=15;
// request of your database
$query = "SELECT * FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' ORDER BY RAND() LIMIT $limit";
// result of request
$result = cpg_db_query($query);
// For reading result
$rowset = array();
// Index of tab
$i=0;
// max height : will be 75px or 100px
$max_height=0;
// For each pic.....building javascript in php
echo "<script type=\"text/javascript\">"."\n";
while($row = mysql_fetch_array($result)){
// reading pid of pic
$key=$row['pid'];
// reading height of pic
$image_size = compute_img_size($row['pwidth'], $row['pheight'], $CONFIG['thumb_width']);
// Calcul de la hauteur maxi de la zone déroulante (par défaut = 75px)
if ($image_size['height'] > $max_height) {
$max_height = $image_size['height'];
}
// path of pic
$file="albums/".$row['filepath']."thumb_".$row['filename'];
// link of pic
$lien="<a href=\"displayimage.php?album=random&cat=0&pos=-$key\"><img src=\"".$file."\" border=0></a>";
// building javascript code
echo "leftrightslide[".$i."]='".$lien."'"."\n";
$i=$i+1;
}
//Max height of pics fixed
echo "sliderheight=\"".$max_height."px\""."\n";
echo "</script>"."\n";
// free memory
mysql_free_result($result);
/******************************************************************************
END PHP code
*******************************************************************************/
?>
<script type="text/javascript">
// *****************************************************************
// Part 2 : end of initial javascript code
// *****************************************************************
//Specify gap between each image (use HTML):
var imagegap=" "
//Specify pixels gap between each slideshow rotation (use integer):
var slideshowgap=5
////NO NEED TO EDIT BELOW THIS LINE////////////
var copyspeed=slidespeed
leftrightslide='<nobr>'+leftrightslide.join(imagegap)+'</nobr>'
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">'+leftrightslide+'</span>')
var actualwidth=''
var cross_slide, ns_slide
window.onload=fillup
function fillup(){
if (iedom){
cross_slide=document.getElementById? document.getElementById("test2") : document.all.test2
cross_slide2=document.getElementById? document.getElementById("test3") : document.all.test3
cross_slide.innerHTML=cross_slide2.innerHTML=leftrightslide
actualwidth=document.all? cross_slide.offsetWidth : document.getElementById("temp").offsetWidth
cross_slide2.style.left=actualwidth+slideshowgap+"px"
}
else if (document.layers){
ns_slide=document.ns_slidemenu.document.ns_slidemenu2
ns_slide2=document.ns_slidemenu.document.ns_slidemenu3
ns_slide.document.write(leftrightslide)
ns_slide.document.close()
actualwidth=ns_slide.document.width
ns_slide2.left=actualwidth+slideshowgap
ns_slide2.document.write(leftrightslide)
ns_slide2.document.close()
}
lefttime=setInterval("slideleft()",30)
}
function slideleft(){
if (iedom){
if (parseInt(cross_slide.style.left)>(actualwidth*(-1)+8))
cross_slide.style.left=parseInt(cross_slide.style.left)-copyspeed+"px"
else
cross_slide.style.left=parseInt(cross_slide2.style.left)+actualwidth+slideshowgap+"px"
if (parseInt(cross_slide2.style.left)>(actualwidth*(-1)+8))
cross_slide2.style.left=parseInt(cross_slide2.style.left)-copyspeed+"px"
else
cross_slide2.style.left=parseInt(cross_slide.style.left)+actualwidth+slideshowgap+"px"
}
else if (document.layers){
if (ns_slide.left>(actualwidth*(-1)+8))
ns_slide.left-=copyspeed
else
ns_slide.left=ns_slide2.left+actualwidth+slideshowgap
if (ns_slide2.left>(actualwidth*(-1)+8))
ns_slide2.left-=copyspeed
else
ns_slide2.left=ns_slide.left+actualwidth+slideshowgap
}
}
if (iedom||document.layers){
with (document){
// Adapt property align (left or right or center) Not in initial code
document.write('<table border="0" cellspacing="0" cellpadding="0" align="center"><td>')
if (iedom){
write('<div style="position:relative;width:'+sliderwidth+';height:'+sliderheight+';overflow:hidden">')
write('<div style="position:absolute;width:'+sliderwidth+';height:'+sliderheight+';background-color:'+slidebgcolor+'" onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed">')
write('<div id="test2" style="position:absolute;left:0px;top:0px"></div>')
write('<div id="test3" style="position:absolute;left:-1000px;top:0px"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+sliderwidth+' height='+sliderheight+' name="ns_slidemenu" bgColor='+slidebgcolor+'>')
write('<layer name="ns_slidemenu2" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"></layer>')
write('<layer name="ns_slidemenu3" left=0 top=0 onMouseover="copyspeed=0" onMouseout="copyspeed=slidespeed"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}
</script>
They are 2 ways for using it :
1) Integration in script 'anycontent.php':It is the simplest way.
Here the final code of script 'anycontent.php' :
if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
starttable("100%", "Welcome");
include "slider.php";
?>
<tr><td class="tableb" >
</td></tr>
<?php
endtable();
?>
The option must be activated to show the contents of 'anycontent.php' with admin configuration -> Album list view -> content of the main page : i.e :
anycontent/minicms/updatehistory/breadcrumb/catlist/alblist/onlinestats2) Integration in theme.php of your themeIt is the solution which I chose.
I currently use the theme "Rainy Day" and Slider is in the heading of page.
But it is necessary to modify 2 scripts in the folder of the theme:
Here the code which I inserted right before the tag ?> (the original code is in script themes.inc.php, line 1181 and others...)
function pageheader($section, $meta = '')
{
global $CONFIG, $THEME_DIR;
global $template_header, $lang_charset, $lang_text_dir;
$custom_header = cpg_get_custom_include($CONFIG['custom_header_path']);
// Define the slider
$bandeau=cpg_get_custom_include("slider.php");
$charset = ($CONFIG['charset'] == 'language file') ? $lang_charset : $CONFIG['charset'];
header('P3P: CP="CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE"');
header("Content-Type: text/html; charset=$charset");
user_save_profile();
$template_vars = array('{LANG_DIR}' => $lang_text_dir,
'{TITLE}' => $CONFIG['gallery_name'] . ' - ' . strip_tags(bb_decode($section)),
'{CHARSET}' => $charset,
'{META}' => $meta,
'{GAL_NAME}' => $CONFIG['gallery_name'],
// Add slider to global variables
'{BANDEAU}' => $bandeau,
'{GAL_DESCRIPTION}' => $CONFIG['gallery_description'],
'{SYS_MENU}' => theme_main_menu('sys_menu'),
'{SUB_MENU}' => theme_main_menu('sub_menu'),
'{ADMIN_MENU}' => theme_admin_mode_menu(),
'{CUSTOM_HEADER}' => $custom_header,
);
echo template_eval($template_header, $template_vars);
}
The 2 lines specific are annotated.
I use 2 variable named $bandeau and {¦BANDEAU¦}.
But the slider will not appear yet.
It is necessary to add the variable {¦BANDEAU¦} in the template.html of your theme.
Place the variable {BANDEAU}at position desired to show the slider.
Several tests were necessary to find the good place.
Good slider to all

PS ! french original article is posted at
http://forum.coppermine-gallery.net/index.php?topic=41073.0