I made 2 simple scripts.
- a gallery-script
- a banner-rotation-script
Nothing special, but working well and easy.
Samples of both scripts are here: http://surfclub-bernau.de
The Gallery-Script
Put the code in a php-file, for example 'gallery.php'.
You can call the script from a content-part with:
[PHP]include("your_path/gallery.php");[/PHP]
If you have installed my PHP-SCRIPTS-MOD, you can add a new Script from the backend, copy the code and call it like {SCRIPT:gallery.php}
Here you can find the PHP-SCRIPTS-MOD.
Put the images in a folder, thumbnails are generated by the script.
Edit the parameters in the 'gallery.php'.
Code: Select all
<?php
// a simple gallery-script for phpwcms
// gdlib 2 is required for generating thumbnails
// save the script somewhere in a php-file, for example 'gallery.php'
// include it with the right path in a content-part (for example) like: [PHP]include("stuff/scripts/gallery.php");[/PHP] //
// put your images in a folder, thumbnails will be generated by the script
// if you call your gallery with '&generatethumbs' at the end of your path, all thumbnails will be generated new
// if you call your gallery with '&deletethumbs' at the end of your path, all thumbnails will be deleted
// Andi Platen, 02.06.2006, www.wireframe.de|www.gleitschirm-taxi.de|www.mountain-panorama.com
// ------- edit the parameters to your needs -------------------------- //
$dirName = 'stuff/upload/gallery'; // path to your gallery images
$border_style = 'border:solid 2px #666666'; // style of image borders
$galPageClass = 'gal_page_select'; // class for page-select
$pageSelector = ' | ';
$backLink = 'back'; // title of the back-link
$thumbWidth = 120; // thumbnail width
$thumbHeight = 60; // thumbnail height
$imageSpaceH = 10; // horizontal space between images
$imageSpaceV = 10; // vertical space between images
$maxColumns = 5; // number of columns
$maxRows = 3; // number of rows pro page
$thumb_quality = 90; // thumbnail quality
// ------- end edit --------------------------------------------------- //
$form_action = explode('&', $_SERVER['QUERY_STRING']);
$form_action = $form_action[0];
$form_action = str_replace('&', '&', $form_action);
$form_action = 'index.php?' . $form_action;
$pageSel = $_REQUEST['pageSel'];
if(!$pageSel)
{
$pageSel = 1;
}
if(isset($_REQUEST['big']))
{
$show_big = $dirName . '/' . $_REQUEST['big'] . '.jpg';
$big_size = getimagesize($show_big);
$pages = $_REQUEST['pages'];
if($pages > 1)
{
$i = 1;
while($i < $pages + 1)
{
if($i == $pageSel)
{
echo '<a class="' . $galPageClass . '" href="' . $form_action . '&pageSel=' . $i . '"><b>' . $i . '</b></a>';
}
else
{
echo '<a class="' . $galPageClass . '" href="' . $form_action . '&pageSel=' . $i . '">' . $i . '</a>';
}
if($i < $pages)
{
echo $pageSelector;
}
$i++;
}
echo '<br /><br />';
}
echo '<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="' . $border_style . '"><a href="' . $form_action . '&pageSel=' . $pageSel . '"><img src="' . $show_big . '" ' . $big_size[3] . ' border="0" alt="' . $_REQUEST['big'] . '" /></a></td>
</tr>
<tr>
<td>[ <a href="' . $form_action . '&pageSel=' . $pageSel . '">' . $backLink . '</a> ]</td>
</tr>
</table>';
}
else
{
$thumbs = array();
$bigs = array();
$dirList = opendir($dirName);
while($file_big = readdir($dirList))
{
if($file_big != '.' && $file_big != '..' && substr($file_big, 0, 5) != 'thumb')
{
$big_size = getimagesize($dirName . '/' . $file_big);
$file_thumb = $file_big;
$file_thumb = 'thumb_' . $file_big;
if(!file_exists($dirName . '/' . $file_thumb) || isset($_REQUEST['generatethumbs']))
{
$gd_image = imagecreatefromjpeg($dirName . '/' . $file_big);
$new_picture = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($new_picture, $gd_image, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $big_size[0], $big_size[1]);
imagejpeg($new_picture, $dirName . '/' . $file_thumb, $thumb_quality);
}
array_push($bigs, $dirName . '/' . $file_big);
array_push($thumbs, $dirName . '/' . $file_thumb);
}
if(isset($_REQUEST['deletethumbs']) && substr($file_big, 0, 5) == 'thumb')
{
unlink($dirName . '/' . $file_big);
}
}
closedir($dirList);
natsort($thumbs);
$bigs = array_values($thumbs);
// start pages //
$pages = ceil(count($thumbs) / ($maxRows * $maxColumns));
if($pages > 1)
{
$i = 1;
while($i < $pages + 1)
{
if($i == $pageSel)
{
echo '<a class="' . $galPageClass . '" href="' . $form_action . '&pageSel=' . $i . '"><b>' . $i . '</b></a>';
}
else
{
echo '<a class="' . $galPageClass . '" href="' . $form_action . '&pageSel=' . $i . '">' . $i . '</a>';
}
if($i < $pages)
{
echo $pageSelector;
}
$i++;
}
echo '<br /><br />';
}
$aktPageStart = (($pageSel - 1) * $maxColumns) * $maxRows;
$aktPageStop = $aktPageStart + $maxRows * $maxColumns;
if($aktPageStop > count($thumbs))
{
$aktPageStop = count($thumbs);
}
// stop pages //
echo '<table border="0" cellspacing="0" cellpadding="0">';
$i = $aktPageStart;
while($i < $aktPageStop)
{
echo '<tr>';
$k = 1;
while($k <= $maxColumns)
{
if($i + $k < 10)
{
$imageSel = '00' . ($i + $k);
}
else if ($i + $k < 100)
{
$imageSel = '0' . ($i + $k);
}
$bild[$k] = $thumbs[$i + $k - 1];
$bild_name = str_replace($dirName . '/' . 'thumb_','',$bild[$k]);
$bild_name = str_replace('.jpg','',$bild_name);
$link[$k] = $form_action . '&pages=' . $pages . '&pageSel=' . $pageSel . '&big=' . $bild_name;
$insertImage = '<td style="' . $border_style . '"><a href="' . $link[$k] . '"><img src="' . $bild[$k] . '" width="' . $thumbWidth . '" height="' . $thumbHeight . '" border="0" alt="' . $bild_name . '" /></a></td>';
if(!$thumbs[$i + $k - 1])
{
$insertImage = '<td> </td>';
}
echo $insertImage;
if($k < $maxColumns)
{
echo '<td style="width:' . $imageSpaceH . 'px"> </td>';
}
$k++;
}
echo '</tr>';
if($i < count($thumbs) - $maxColumns)
{
echo '<tr>
<td colspan="' . ($maxColumns * 2 - 1) . '" style="height:' . $imageSpaceV . 'px; line-height:0px;"> </td>
</tr>';
}
$i += $maxColumns;
}
echo '</table>';
}
?>
The Banner-Script
New: I made a banner-mod - you can find it here:
http://www.phpwcms.de/forum/viewtopic.php?t=11466
But of course, you can use this script
Put the code in a php-file, for example 'banner.php'.
You can call the script from your template or from a content-part with:
[PHP]include("your_path/banner.php");[/PHP]
Some Features:
banner-rotation, click-counter, impression-counter, max. clicks, active/inactive...
Read the instructions and set the parameters.
The Banner-Statistic of the 'surfclub-site' can be seen with this link:
http://www.surfclub-bernau.de/surfclubc ... annerstats
Code: Select all
<?php
// a simple banner-rotation-script for phpwcms
// save the script somewhere in a php-file, for example 'banner.php'
// include it in your template or in a content-part (for example) like: [PHP]include("stuff/scripts/banner.php");[/PHP] //
// put your banner-images in a folder
// $banner_file: path (with name) to your banner-script
// $banner_path: path to the banner-images
// $banner_alt: alt-tag of the banner-images
// $banner_empty: will be shown, all banners inactive or reached the click-limit
// $banner_count: if 1, your 'banner.php' file must be writeable, because the count of impressions and clicks will be written in this file
// $banner_stats: if you call your bannerscript directly with $banner_stats like '?bannerstats', a banner-statistic will be shown
// image: name of the banner-image
// link: url for the click
// active: 0 or 1, when all banners inactive, $banner_empty will be shown
// bought_clicks: number of maximal clicks, if 0 there is no limit
// clicks: number of clicks
// impressions: number of impressions
// Andi Platen, 03.06.2006, www.wireframe.de|www.gleitschirm-taxi.de|www.mountain-panorama.com
// ------- edit the parameters to your needs -------------------------- //
$banner_file = 'stuff/scripts/banner.php';
$banner_path = 'stuff/images/banner/';
$banner_alt = 'click to open';
$banner_empty = '[ Like to see your Banner here...? ]';
$banner_stats = 'bannerstats';
$banner_count = 0;
// banner 1 //
$banner[1]['image'] = 'wireframe.jpg';
$banner[1]['link'] = 'http://www.wireframe.de';
$banner[1]['active'] = 1;
$banner[1]['bought_clicks'] = 0;
$banner[1]['clicks'] = 0;
$banner[1]['impressions'] = 0;
// banner 1 //
// banner 2 //
$banner[2]['image'] = 'gleitschirm_taxi.jpg';
$banner[2]['link'] = 'http://www.gleitschirm-taxi.de';
$banner[2]['active'] = 1;
$banner[2]['bought_clicks'] = 0;
$banner[2]['clicks'] = 0;
$banner[2]['impressions'] = 0;
// banner 2 //
// ------- end edit --------------------------------------------------- //
$banner_tmp = $banner;
if(isset($_REQUEST[$banner_stats]))
{
foreach($banner as $key => $value)
{
foreach($banner[$key] as $a => $b)
{
echo '<b>' . $a . ': <span style=color:#FF0000;>' . $banner[$key][$a] . '</span></b><br>';
}
echo '<br>';
}
exit;
}
if(isset($_REQUEST['banner']))
{
$banner_number = $_REQUEST['banner'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: '. $banner[$banner_number]['link']);
countplus('clicks', $banner_file, $banner_count, $banner_number);
exit;
}
if($banner_count == 1)
{
foreach($banner_tmp as $key => $value)
{
if($banner_tmp[$key]['active'] == 0 || ($banner_tmp[$key]['bought_clicks'] != 0 && $banner_tmp[$key]['clicks'] >= $banner_tmp[$key]['bought_clicks']))
{
unset($banner_tmp[$key]);
}
}
}
else
{
foreach($banner_tmp as $key => $value)
{
if($banner_tmp[$key]['active'] == 0)
{
unset($banner_tmp[$key]);
}
}
}
if($banner_tmp)
{
$banner_number = array_rand($banner_tmp);
}
if($banner_number)
{
$banner_img = $banner_path . $banner_tmp[$banner_number]['image'];
$banner_data = getimagesize($banner_img);
echo '<a href="' . $_SERVER['REQUEST_URI'] . '&banner=' . $banner_number . '" target="_blank"><img src="' . $banner_img . '" ' . $banner_data[3] . ' border="0" alt="' . $banner_alt . '"></a>';
countplus('impressions', $banner_file, $banner_count, $banner_number);
}
else
{
echo $banner_empty;
}
// function: count impressions and clicks //
function countplus($countvalue, $banner_file, $banner_count, $banner_number)
{
if($banner_count == 1)
{
$inhalt = file($banner_file);
foreach($inhalt as $key => $value)
{
$count_tmp = explode(' = ', $inhalt[$key]);
if($count_tmp[0] == '$banner[' . $banner_number . '][\'' . $countvalue . '\']')
{
$count_tmp[1] = str_replace(';', '', $count_tmp[1]);
$count_tmp[1] = $count_tmp[1] + 1;
$inhalt[$key] = $count_tmp[0] . ' = ' . $count_tmp[1] . ";\n";
}
$schreiben .= $inhalt[$key];
}
$file = fopen($banner_file, 'w+');
fwrite($file, $schreiben);
fclose($file);
}
}
// function: count impressions and clicks //
?>