Coppermine Gallery Bridge Script v1.0

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
Fulvio Romanin
Posts: 394
Joined: Thu 4. Dec 2003, 11:12
Location: Udine, Italy
Contact:

Coppermine Gallery Bridge Script v1.0

Post by Fulvio Romanin »

Sometimes for huge sites i use Coppermine as a picture gallery. Thru the years it has become powerful and flexible.
Still a "not many frills just tons of content", it's the best choice to me when a gallery is not made of 1 level and 1 album.
I always thought it would have been a great thing if we could import the images into wcms.
Into Sunsplash days as i am now, i asked my friend and colleague Anthony Barchiesi to write down a script to display the images into wcms. It's a simple script that takes images from coppermine and shrinks them to the needed size, being able to display a full gallery into the site.

The usage is pretty simple:

{COPPER:gallerynum, imagenum, width, height}

Examples:
{COPPER:770,1,400}
will show image 1 (remember they start from 0 as usual) from gallery 770, large 400px and with his height scaled proportionally

{COPPER:420,ALL,210,100}
would show all images from gallery 420, large 210px and 100px high (in case for some reason you needed images scaled to a certain ratio)

Lightbox is enabled, but you need to have it turned on on the article by checking the button.
You have two classes where you can customize stuff, which are the

coppermineLink to customize the appearance of the link itself
coppermine to customize the appearance of the image

SCRIPT

Code: Select all

<?php
/*************************************************************************************
   Copyright notice
   
   (c) 2009-2010 Anthony Barchiesi (antbar81@gmail.com) // All rights reserved.
 
   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.
  
   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
   A copy is found in the textfile GPL.txt and important notices to the license 
   from the author is found in LICENSE.txt distributed with these scripts.
  
   This script 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.
 
   This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************/


if(strpos($content['all'], '{COPPER')) {
		
	$content['all'] = preg_replace_callback('/\{COPPER(.*?)\}/', 'gallery', $content['all']);	
	
}

function gallery($matches) {
	
	global $content, $aktion;
	
	$data = explode(',', trim($matches[1], ':') );
	
	$data[0] = empty($data[0]) ? '' : trim($data[0]);
	$data[1] = empty($data[1]) && $data[1] != 0 ? '' : trim($data[1]);
	$data[2] = empty($data[2]) ? '0' : trim($data[2]);
	$data[3] = empty($data[3]) ? '0' : trim($data[3]);
	
	
        if ($data[0] == '' || $data[1] == ''){
            // show no error on front page in case of wrong call
	    return '';
            exit;
        }	
	
	$coppermineDir = 'http://www.site.com/coppermine/albums/'; // coppermine path

        // Coppermine configuration file
        
        // MySQL configuration
        $CONFIG['dbserver'] =                         "";        // Your database server
        $CONFIG['dbuser'] =                         "";        // Your mysql username
        $CONFIG['dbpass'] =                         "";                // Your mysql password
        $CONFIG['dbname'] =                         "";        // Your mysql database name
        
        
        // MySQL TABLE NAMES PREFIX
        $CONFIG['TABLE_PREFIX'] =                "";

        
        $connessione = @mysql_connect($CONFIG['dbserver'],$CONFIG['dbuser'],$CONFIG['dbpass']);
        $selDb = @mysql_select_db($CONFIG['dbname'],$connessione);
        if($selDb){
            // prende la foto n¡ $parameter[1] partendo da un ordinamento contrario di ID
	    if($data[1] == 'ALL' || $data[1] == 'all'){
	            $sql = "SELECT * FROM ".$CONFIG['TABLE_PREFIX']."pictures WHERE aid='".$data[0]."' ORDER BY pid";		
	    } else if($data[1] >= 0) {
	            $sql = "SELECT * FROM ".$CONFIG['TABLE_PREFIX']."pictures WHERE aid='".$data[0]."' ORDER BY pid LIMIT ".$data[1].",1";
	    } else {
		return '';
		exit;
	    }
            $result = mysql_query($sql);
	    $text = '';
            while($row = mysql_fetch_array($result)){
		
		// shrink and resize
		list($width, $height) = getimagesize($coppermineDir.$row['filepath'].$row['filename']);
		if($data[2] >0 && $data[3] >0){
			$newW = $data[2];
			$newH = $data[3];
		} else if($data[2] >0 && $data[3] == 0){
			$newW = $data[2];
			$newH = $height*$newW/$width;
		} else if($data[2] == 0 && $data[3] > 0){
			$newH = $data[3];			
			$newW = $width*$newH/$height;
		} else if($data[2] == 0 && $data[3] == 0){
			$newW = $width;
			$newH = $height;			
		}
				
                $text .= '<a class="coppermineLink" href="'.$coppermineDir.$row['filepath'].$row['filename'].'" rel="lightbox[galleria]"><img class="coppermine" src="thumb.php?foto='.$coppermineDir.$row['filepath'].$row['filename'].'&width='.$newW.'&height='.$newH.'" alt="galery" /></a>';
            }
	}
            return $text;
}
?>

INSTALLATION

1) edit those lines configuring those to your setup:

$coppermineDir = 'http://www.site.com/coppermine/albums/'; // coppermine path

// Coppermine configuration file

// MySQL configuration
$CONFIG['dbserver'] = "myserver"; // Your database server
$CONFIG['dbuser'] = "sql_username"; // Your mysql COPPERMINE username
$CONFIG['dbpass'] = "sql_password"; // Your mysql COPPERMINE password
$CONFIG['dbname'] = "sql_dbname"; // Your mysql database name

please double check that these data are the ones from COPPERMINE, not from wcms, especially if you got different dbs
2) Copy the above script into a php file, upload it into template/inc_script/frontend_render directory in your website

that's all, folks! :)
F
Completeness is reached through subtraction, not through addition
User avatar
Oliver Georgi
Site Admin
Posts: 9889
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: Coppermine Gallery Bridge Script v1.0

Post by Oliver Georgi »

I have checked the function and optimized a bit (I guess).
There is no need to set anything other than coppermine db table prefix if you use the same db as for phpwcms.

Be warned - I have not tested it. Maybe Fulvio can do.
coppermine_gallery.zip
(1.73 KiB) Downloaded 226 times

Code: Select all

<?php
/*************************************************************************************
   Copyright notice
   
   (c) 2009-2010 Anthony Barchiesi (antbar81@gmail.com) // All rights reserved.

   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.
 
   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
   A copy is found in the textfile GPL.txt and important notices to the license
   from the author is found in LICENSE.txt distributed with these scripts.
 
   This script 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.

   This copyright notice MUST APPEAR in all copies of the script!
*************************************************************************************/


if(strpos($content['all'], '{COPPER')) {
      
   $content['all'] = preg_replace_callback('/\{COPPER(.*?)\}/', 'coppermine_gallery', $content['all']);   
   
}

function coppermine_gallery($matches) {
   
	global $content, $aktion;
	
	$data = explode(',', trim($matches[1], ':') );
	$data[0] = empty($data[0]) ? '' : trim($data[0]);
	$data[1] = empty($data[1]) && $data[1] != 0 ? '' : trim($data[1]);
	$data[2] = empty($data[2]) ? '0' : trim($data[2]);
	$data[3] = empty($data[3]) ? '0' : trim($data[3]);
	
	
	if ($data[0] == '' || $data[1] == ''){
		// show no error on front page in case of wrong call
		return '';
	}   
	
	$coppermineDir = 'http://www.site.com/coppermine/albums/'; // coppermine path
	
	// Coppermine configuration file
	
	// MySQL configuration
	// Let it empty if you use same db as your phpwcms installation
	$CONFIG['dbserver']		= "";        // Your database server
	$CONFIG['dbuser']		= "";        // Your mysql username
	$CONFIG['dbpass']		= "";                // Your mysql password
	$CONFIG['dbname']		= "";        // Your mysql database name
	
	// Coppermine TABLE NAMES PREFIX
	$CONFIG['TABLE_PREFIX'] = "";
	
	// prende la foto n¡ $parameter[1] partendo da un ordinamento contrario di ID
	if($data[1] == 'ALL' || $data[1] == 'all'){
		$sql = "SELECT * FROM ".$CONFIG['TABLE_PREFIX']."pictures WHERE aid='".aporeplace($data[0])."' ORDER BY pid";      
	} elseif($data[1] >= 0) {
		$data[1] = intval($data[1]);
		$sql = "SELECT * FROM ".$CONFIG['TABLE_PREFIX']."pictures WHERE aid='".aporeplace($data[0])."' ORDER BY pid LIMIT ".$data[1].",1";
	} else {
		return '';
	}
	
	if( ($CONFIG['dbserver'].$CONFIG['dbname']) != ($phpwcms['db_host'].$phpwcms['db_table']) ) {
	
		$connessione = @mysql_connect($CONFIG['dbserver'],$CONFIG['dbuser'],$CONFIG['dbpass']);
		$selDb = @mysql_select_db($CONFIG['dbname'],$connessione);
		if($selDb){
			$result = mysql_query($sql);
			while($row = mysql_fetch_array($result)){
				$data[] = $row;
			}
		}
	} else {
		$data = _dbQuery($sql);
	}
	
	$text = array();
	
	foreach($data as $row) {
	
		// shrink and resize
		$imageinfo = @getimagesize($coppermineDir.$row['filepath'].$row['filename']);
		if($imageinfo) {

			list($width, $height) = $imageinfo;

			if($data[2] >0 && $data[3] >0){
				$newW = $data[2];
				$newH = $data[3];
			} elseif($data[2] >0 && $data[3] == 0){
				$newW = $data[2];
				$newH = $height*$newW/$width;
			} elseif($data[2] == 0 && $data[3] > 0){
				$newH = $data[3];         
				$newW = $width*$newH/$height;
			} elseif($data[2] == 0 && $data[3] == 0){
				$newW = $width;
				$newH = $height;         
			}
		
			$text[] = '<a class="coppermineLink" href="'.$coppermineDir.$row['filepath'].$row['filename'].'" rel="lightbox[galleria]"><img class="coppermine" src="thumb.php?foto='.$coppermineDir.$row['filepath'].$row['filename'].'&width='.$newW.'&height='.$newH.'" alt="galery" /></a>';
		}
	}

	return implode(LF, $text);
}
?>
Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
dani
Posts: 78
Joined: Sat 21. Jan 2006, 19:39
Location: Germany
Contact:

Re: Coppermine Gallery Bridge Script v1.0

Post by dani »

Hi,
I played a little bit with the script at my local web server. Now I have some questions about.

1. How can work the following string from the script?

Code: Select all

$text[] = '<a class="coppermineLink" href="'.$coppermineDir.$row['filepath'].$row['filename'].'" rel="lightbox[galleria]"><img class="coppermine" src="thumb.php?foto='.$coppermineDir.$row['filepath'].$row['filename'].'&width='.$newW.'&height='.$newH.'" alt="galery" /></a>';
At my case, this is the result (generated source code) that not worked for the thumb:

Code: Select all

<a class="coppermineLink" href="http://localhost/version142/coppermine/albums/laender/album31/P1000192.JPG" rel="lightbox[galleria]"><img class="coppermine" src="thumb.php?foto=http://localhost/version142/coppermine/albums/laender/album31/P1000192.JPG&width=150&height=112.5" alt="galery" /></a>
I never saw a "src" string like this before that worked.

I changed it like this:

Code: Select all

$text[] = '<a class="coppermineLink" href="'.$coppermineDir.$row['filepath'].$row['filename'].'" rel="lightbox[galleria]" title="'.$row['title'].'"><img class="coppermine" src="'.$coppermineDir.$row['filepath'].$row['filename'].'" width="'.$newW.'" height="'.$newH.'" alt="galery" /></a>';
Then it worked for me. My question is, done I some thing wrong with the old script?

2. enabling Lightbox
Lightbox is enabled, but you need to have it turned on on the article by checking the button.
How can I turn it on, for example at the CP "pictures <div>"? When I used the coppermine script string only, at the "div" section, the enable button for the lightbox doesn't worked. Only when I selected a picture from the system file archiv. But this is not what I want. Is it possible that the lightbox button works without a picture selection from the system?

Daniel
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Re: Coppermine Gallery Bridge Script v1.0

Post by flip-flop »

Hi,

1. Mhh, a link like

Code: Select all

<a class="remooz-element" rel="remoozboxed" href="img/cmsimage.php/1400x1400/4eec2ee661a1....jpg" title="his is my teacher"><img src="img/cmsimage.php/138x200xx85/4eec2ee661a1b.....jpg" alt="hi is my teacher" title="hi is my teacher" class="xremo" align="right" border="0" height="200" hspace="10" width="138"></a>
is running well.
http://www.artagnon.de/geschichtenerzaehler.phtml

2.

Code: Select all

initializeLightbox();  // start mootools and slimbox
Knut
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
dani
Posts: 78
Joined: Sat 21. Jan 2006, 19:39
Location: Germany
Contact:

Re: Coppermine Gallery Bridge Script v1.0

Post by dani »

Hi Knut,
1. yes, your link is correct, my one looks the same, after changing the script. You used the original coppermine script for rendering this picture link?
What I mean was, How it works when the rendered link looks like this:

Code: Select all

href="thumb.php?foto=http://localhost/version142/coppermine/albums/laender/album31/P1000192.JPG&width=150&height=112.5"
What is doing the "thumb.php?foto=" in front and also the size definition at the end direct in the link?

2. Oh, that's easy :idea: , it works!
One more. Can it be a problem, when the Lightbox get initialized 2 time, for example when there is a regular CP with Lightbox in the same article that initialized it too?

Thanks
Daniel
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Re: Coppermine Gallery Bridge Script v1.0

Post by flip-flop »

1. That isn´t coppermine, I haven´t tested this script. The two picture uses this script WYSIWYG (FCK) image resize

2. An gallery is used on this site isabelleathiel.de -> Tag galleryx

Coppermine:

Code: Select all

albums/laender/album31/P1000192.JPG&width=150&height=112.5"
I think:
albums/laender/album31 = Categories
P1000192.JPG = the picture
in width=150
and height=112.5 ????

I dont know about the dot five statement.

Knut
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
Post Reply