Searchdb modification for Coppermine Photo Gallery, versions 1.3.5 and 1.4.1 beta.This modification will enable you to display the most popular and last search strings on your website. It comes with an easy installer, a simple example page and a fully functional search replacement page for version 1.3.5 of the CPG. It stores the data is two tables in your existing CPG MySQL database.
Working example (integrated into my layout):
www.steverobbins.co.uk/gallery/search.phpWorking example (default search.php with mod):
www.steverobbins.co.uk/gallery/defaultsearch.phpDownload the latest files at:
www.steverobbins.co.uk/photos/coppermine(also attached to this post)
See the searchdb_example file at:
www.steverobbins.co.uk/gallery/searchdb_example.phpTo install:- Unzip the files to your coppermine directory
- Apply a quick modification to thumbnails.php or replace with the supplied versions, use the correct file by removing the version number at the end. thumbnails.php.1.3.5 will also work on v1.3.2
- Choose how many records you would like to keep in your last search database by editing searchdb.php and changing the value of $max_lastsearch_rows. By default it will keep 50 records (that means you can display up to 50 last searches)
- Backup your current database and gallery for maximum safety
- Run the install script searchdb_install.php and click on create database tables
- Search for a few items in your gallery
- Load the example page searchdb_example.php to see if it all works
- Optionally replace the search.php page for a ready made solution (sorry, no 1.4.1 version at the minute)
- Optionally integrate it into your website / gallery by dissecting searchdb_example.php and copying the code.
Removing:- To remove the mod, revert to original files and run searchdb_install.php and choose drop tables – it will only remove tables created by this mod
- To reset the searchdb database (start afresh) run searchdb_install and drop tables and then choose create tables.
thumbnails.php mod for version 1.3.x (or use the supplied file thumbnails.php.1.3.5 and rename to thumbnails.php)
Just below the ‘main code’ comments, approx line 46, find and replace:
if (isset($HTTP_GET_VARS['sort'])) $USER['sort'] = $HTTP_GET_VARS['sort'];
if (isset($HTTP_GET_VARS['cat'])) $cat = (int)$HTTP_GET_VARS['cat'];
if (isset($HTTP_GET_VARS['uid'])) $USER['uid'] = (int)$HTTP_GET_VARS['uid'];
if (isset($HTTP_GET_VARS['search'])) {
$USER['search'] = $HTTP_GET_VARS['search'];
if (isset($HTTP_GET_VARS['type']) && $HTTP_GET_VARS['type'] == 'full') {
$USER['search'] = '###' . $USER['search'];
}
}
with:
if (isset($HTTP_GET_VARS['sort'])) $USER['sort'] = $HTTP_GET_VARS['sort'];
if (isset($HTTP_GET_VARS['cat'])) $cat = (int)$HTTP_GET_VARS['cat'];
if (isset($HTTP_GET_VARS['uid'])) $USER['uid'] = (int)$HTTP_GET_VARS['uid'];
if (isset($HTTP_GET_VARS['search'])) {
$USER['search'] = $HTTP_GET_VARS['search'];
// searchdb mod start
include('searchdb.php');
if ($USER['search'] != "") { searchdb_search ($USER['search'], $_SERVER["REMOTE_ADDR"]); }
// searchdb mod end
if (isset($HTTP_GET_VARS['type']) && $HTTP_GET_VARS['type'] == 'full') {
$USER['search'] = '###' . $USER['search'];
}
}
thumbnails.php mod for version 1.4.1(or use the supplied file thumbnails.php.1.4.1 and rename to thumbnails.php)
In thumbnails.php file find ‘main code’ comments, approx line 76, and below find the statement:
if (isset($_GET['search'])) {
$USER['search']['search'] = $_GET['search'];
}
and enter the following code just below:
// searchdb mod start
include('searchdb.php');
if ($USER['search']['search'] != "") { searchdb_search ($USER['search']['search'], $_SERVER["REMOTE_ADDR"]); }
// searchdb mod end
Notes:- The search mod uses CSS code embedded into the example pages to display the mod working correctly. Add these definitions to your own theme / website and modify to suit your own requirements. Don’t forget to remove it from the supplied pages.
- The search on version 1.4.1 does not obey the checkboxes and logical search operators.
- The IP address of the searcher is stored in the database, but not displayable using the function supplied. You can use something like phpmyadmin to examine the tables if you would like to extract this information.
Files:searchdb.php – contains all the code to make it work. You only need this file.
searchdb_install.php – allows you to create and drop the tables in the database. I suggest you delete this file from your active gallery after the installation is complete.
searchdb_example.php – displays a page of the capabilities of the function, along with simple example code.
Functions:searchdb_search ($searchterm, $ipaddress)This function adds records to the database. It is called from thumbnails.php when a search is initiated.
searchdb_showpopular ($rowstoshow, $show_positions, $show_totals, $show_timedate)This function extracts the records from the database and displays a number of rows based on the parameter $rowstoshow that you pass. By setting the following parameters to true or false you can enable the display of the data.
Example:
searchdb_showpopular (10, true, true, false) would display something like:
1 steve (7 times)
2 ballooning (6 times)
3 best (4 times)
4 friends (4 times)
5 disney (3 times)
6 disneyland (2 times)
7 uk coventry (2 times)
8 kenilworth (2 times)
9 caernafon (2 times)
10 forest (1 time)
searchdb_showlast ($rowstoshow, $show_positions, $show_timedate)This functions extracts the last search terms used in the database. $rowstoshow tell it how many records to select, and the following options enable display of the data. Remember during install there is an option to set the parameter $max_lastsearch_rows which by default is 50. If you call this function to display 100 rows and have the $max_lastsearch_rows set to 50, you will only get 50 rows of data.
Example:
searchdb_showlast(10, true, false) would display something like:
3415 disney
3414 disneyland
3413 steve
3412 ballooning
3411 best
3410 france aix
3409 caernafon
3408 disney
3407 rtusa alamo
3406 disneyland
The number at the start is the search number, recording the total searches of the CPG database.
searchdb_gettotalsearches()This function returns the total searches of the CPG database, as stored in the last search table.
Example:
$total = searchdb_gettotalsearches();
echo “Total searches: $total”;
Would give you:
Total searches: 1234
Please post improvements, examples, suggestions, questions here for all to benefit. Also, if you make use of this mod, please let me know so I can see how it looks.
Hope you find it useful,
Regards
Steve.