',
$beforeRow = '

', $afterRow = '

',
$before = '

WordPress Coppermine Search Integration

I’ve modified the default search so that it will also search through the photo gallery. I achieved this by inspecting the Coppermine code for searching and then extending this plugin from Idahocline.


This is the function that I added. My main goal was just to get something working right away, so I pretty much just copied most of the CPGAlbum function instead of trying to make something more modular.
[code lang="php"]
function CPGSearch( $to_find, $aid = -1,
$nCols = 4, $nSize = 1,
$beforeCol = '

', $afterCol = '
', $after = '

' ) {
global $CONFIG,$cpgdb;
if( !$CONFIG ) {
echo 'psnGallery2 Upgrade / Install required';
return( -1 );
}

$count = ( $count < 1 ) ? $CONFIG[ 'MAXPICT' ] : $count;
$where = ( $aid != -1 ) ? ' AND aid=' . $aid : '';
switch( $nSize ) {
case 3:
$cSize = 'fullsize';
$maxsize = -1;
break;
case 2:
$cSize = 'normal';
$maxsize = $CONFIG[ 'picture_width' ];
break;
default:
$cSize = 'thumb';
$maxsize = $CONFIG[ 'thumb_width' ];
break;
}
$result = $cpgdb->query( "
SELECT COUNT( * ) AS nbrows
FROM {$CONFIG[ 'TABLE_PICTURES' ]}
JOIN {$CONFIG[ 'TABLE_ALBUMS' ]} ON
{$CONFIG[ 'TABLE_PICTURES' ]}.aid=
{$CONFIG[ 'TABLE_ALBUMS' ]}.aid
WHERE MATCH( filename, {$CONFIG[ 'TABLE_PICTURES' ]}.title,
caption, keywords )
AGAINST( '$to_find' IN BOOLEAN MODE )
AND approved='YES'
AND visibility=0
$where;
" );
$rows = $cpgdb->get_results();
echo $before;
if( !$rows ) {
echo $beforeRow . $beforeCol . 'No Images Found' . $afterCol .
$afterRow;
return( 0 );
}
$pic_count = $rows[ 0 ]->nbrows;
// if we have more than 1000 pictures, we limit the number of
// pictures returned by the SELECT statement as ORDER BY RAND() is
// time consuming
$result = $cpgdb->query( "
SELECT *
FROM {$CONFIG['TABLE_PICTURES']}
WHERE MATCH( filename, title, caption, keywords )
AGAINST( '$to_find' IN BOOLEAN MODE )
AND approved='YES'
$where;
" );
$rows = $cpgdb->get_results();
foreach( $rows as $picture ) {
$image_size = psnImgSize( $picture->pwidth, $picture->pheight,
$maxsize, $cSize );
$pic_title = $picture->pid . ' / ' .
$lang_display_thumbnails[ 'filename' ] .
$picture ->filename . ' / ' .
$lang_display_thumbnails[ 'dimensions' ] .
$picture->pwidth . 'x' . $picture->pheight;
$thumb_list[ $i ][ 'pos' ] = $key < 0 ? $key : $i - 1;
$thumb_list[ $i ][ 'image' ] =
psnGenHTMLTag( $picture, $cSize, $image_size, $pic_title );

// beginning of row?
if( $col < 1 )
echo "\n\t$beforeRow\n";
echo "\n\t\t$beforeCol" . psnGenModuleURL( '', $picture->pid )
. $thumb_list[ $i ][ 'image' ] . '' . $afterCol;
$col++;
// end of row ?
if( $col >= $nCols ) {
echo "\n\t$afterRow
\n";
$col = 0;
}
}
// row closed yet?
if( $col > 0 )
echo "\n\t$afterRow\n";
echo $after;
}
[/code]

So far, it is configured to not return any photos that an unregistered user would not have access to. Integrating the user system would be quite difficult.

June 28th, 2005 | Category: Blog

Leave a Reply

You must be logged in to post a comment.

Photostream

Recent Posts