Advanced search  

News:

cpg1.5.30 maintenance release - upgrade recommended
The Coppermine development team is releasing an update for Coppermine in order to fix several minor issues. All fixes are not security critical, so if your gallery is running fine with cpg1.5.28 you don't need to upgrade. If you are running an older version than cpg1.5.28, you must update to this latest version as soon as possible because of the security impact!
[more]

Pages: [1]   Go Down

Author Topic: Mod to display most popular and last search strings for 1.3.x and 1.4.1 beta  (Read 17555 times)

0 Members and 1 Guest are viewing this topic.

steverobbins

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 35
  • photographer
    • Steve Robbins' Personal Website

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.php

Working example (default search.php with mod):
www.steverobbins.co.uk/gallery/defaultsearch.php

Download 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.php


To 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:

Code: [Select]
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:

Code: [Select]
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:

Code: [Select]
if (isset($_GET['search'])) {
    $USER['search']['search'] = $_GET['search'];
}

and enter the following code just below:

Code: [Select]
// 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.
« Last Edit: September 29, 2005, 08:38:22 AM by GauGau »
Logged

LilAngel

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 39

Wow, I love this script. I have been waiting patiently for something like this! I have installed it on this gallery, and I might add it to my other gallery as well. Thanks!!  ;D

Edit: Also installed on this gallery. I have nothing to add to this, it works great! Haven't spotted any bugs.
« Last Edit: October 01, 2005, 03:46:20 PM by LilAngel »
Logged

antisa33

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 181
    • Free french kids coloring

Thank you very very much for this mod thank you !!!!!!!! :)
Is it possible to store the number of results found ?
For example when they search a word, i would know when the result is 0 to ameliore my search function.
Thank you !!!
Isa
Logged

steverobbins

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 35
  • photographer
    • Steve Robbins' Personal Website

Hi there,

It would be possible to add this function to store the quantity of files found based on the search terms used.  You could see how the code in thumbnails.php makes use of the search terms and get the amount of sql table rows returned and then add this information to the searchdb table.  I'm busy at the moment, but will look into it in the next few weeks.

Any other ideas from anyone?

Regards
Steve.

antisa33

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 181
    • Free french kids coloring

Thanks for your reply.
Do you stock in your code the number of results ?
Because i know how to do a insert into in sql, but i dont know how to get the number of results.
Thanks.
Logged

antisa33

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 181
    • Free french kids coloring

I have an other suggestion, could we add the album link in search results with the thumbs ?
Logged

antisa33

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 181
    • Free french kids coloring

 ???
Logged

steverobbins

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 35
  • photographer
    • Steve Robbins' Personal Website

Here is an update to add the option to display the number of results returned for the search string.

It's basically a cut and paste of the search code that Coppermine uses, which is then used to generate a number to display after the search result.  See an example at www.steverobbins.co.uk/gallery/search.php

To install, just overwrite the exisiting files from the post above, this zip file contains only two updated files, searchdb.php and searchdb_example.php.

Important: you will have to edit the file searchdb.php at the top to enter the table name of your pictures database, not very sophisitcated I know, but more simple to code, my one is set to:

Code: [Select]
// YOUR picture table name
define('PICTURE_TABLE','cpg132_pictures');

If you are not sure of yours, you could use phpmyadmin to find out, or open the file includes/config.inc.php and fnd:

Code: [Select]
// MySQL TABLE NAMES PREFIX
$CONFIG['TABLE_PREFIX'] =                'cpg132_';

Then just add 'pictures' to the end of it.

A note of caution, using this mod to display the results will put extra strain on your SQL server, make sure you are ok about this before installing.

So the two display functions have changed, all you need to do is add an additional parameter to the end of the function call:

Previously:

Code: [Select]
searchdb_showpopular ($rowstoshow, $show_positions, $show_totals, $show_timedate);
searchdb_showlast ($rowstoshow, $show_positions, $show_timedate);

Now:

Code: [Select]
searchdb_showpopular ($rowstoshow, $show_positions, $show_totals, $show_timedate, $show_results);
searchdb_showlast ($rowstoshow, $show_positions, $show_timedate, $show_results);

Passing true on the last $show_results will enable the feature to show the search results.

There you go, not extensively tested, but works ok for me on two seperate web-hosts, any problems just post a reply and we'll figure it out as we go.  If you are new to this mod, follow the instructions in the first post and then apply these files after you have it working.

Regards
Steve.

antisa33

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 181
    • Free french kids coloring

Good work thank you very much !

It is ok for me  ;)

A last suggestion, i would like to have albums names links in results, not just the thumbnails, do you think it will be possible ?
Thanks!
Isa
Logged

claude258

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 150
    • Album photos Brière

Do you know if this mod is working with version 1.4.3 of Coppermine ?
Logged

steverobbins

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 35
  • photographer
    • Steve Robbins' Personal Website

Hi there,

I have seen websites running this on version 1.4.3.  I don't have an example search page for you, but you can modify the 1.4.1 example if you wish, or you can add the code to your own custom page.

Regards
Steve.

wipqozn1

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 60

I see a blank page when call searchdb_install.php. I've replaced the thumbnails.php file before. Was I suppose to do something else?
Logged

dke

  • Guest

I realize this topic might be dead but i though id ask a question..

I've gotten this to work with the current coppermine release 1.4.14 but i cannot figure out how to make it look good.

Im using the Album search plugin and would like to implement the results into the search box. This is how far i've gotten:

[Edit GauGau] Replaced hotlinked image with attachment [/Edit]

could anyone elaborate on how to make the box lines appear around the text and also move the text results to the middle of the search box?

here is how the code for search.php is looking right now:

Code: [Select]
<?php
/**************************************************
  Coppermine Plugin - Search Album
  *************************************************
  Copyright (c) 2005 Paul Van Rompay
  *************************************************
  Portions taken from Coppermine core code:
  Copyright (c) 2003-2005 Coppermine Dev Team
  v1.1 originally written by Gregory DEMAR
  *************************************************
  This program is free software; 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.
***************************************************/

define('SEARCH_PHP'true);

require(
'include/init.inc.php');
include(
'searchdb.php');

if (!
USER_ID && $CONFIG['allow_unlogged_access'] == 0) {
    
$redirect $redirect "login.php";
    
header("Location: $redirect");
    exit();
}

pageheader($lang_search_php['title']);
echo <<< EOT

<form method="post" action="thumbnails.php" name="searchcpg">
EOT;

starttable('60%'$lang_search_php['title']);

$ip GALLERY_ADMIN_MODE '
        <tr>
                <td>
                        <input type="checkbox" name="pic_raw_ip" class="checkbox" id="pic_raw_ip" /><label for="pic_raw_ip" class="clickable_option">'
.$lang_search_php['ip_address'].'</label>
                </td>
        </tr>' 
:
        
'<tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
        </tr>'
;

$customs '';

$result cpg_db_query("SELECT * FROM {$CONFIG['TABLE_CONFIG']} WHERE name LIKE 'user_field%_name' AND value <> '' ORDER BY name ASC");

while (
$row mysql_fetch_assoc($result)){
        
$name str_replace(array('_field''_name'), ''$row['name']);
        
$customs .= <<< EOT
                <tr>
                        <td><input type="checkbox" name="
$name" id="$name" class="checkbox" /><label for="$name" class="clickable_option">{$row['value']}</label></td>
                </tr>
EOT;
}
echo <<< EOT
        <tr>
            <td class="tableb" align="center" >
                <input type="text" style="width: 80%" name="search" maxlength="255" value="" class="textinput" />
                <input type="submit" value="
{$lang_search_php['submit_search']}" class="button" />
                <input type="hidden" name="album" value="search" />
<input type="hidden" name="plugin_search_album" value="true" />
            </td>
        </tr>
                <tr>
                        <td class="tableb">
                                <table align="center" width="60%">
                                        <tr>
                                                <td>
{$lang_search_php['fields']}:</td>
                                                <td align="center">
{$lang_search_php['age']}:</td>
                                        </tr>
                                        <tr>
                                                <td><input type="checkbox" name="title" id="title" class="checkbox" checked="checked" /><label for="title" class="clickable_option">
{$lang_adv_opts['title']}</label></td>
                                                <td align="right">
{$lang_search_php['newer_than']} <input type="text" name="newer_than" size="3" maxlength="4" class="textinput" /> {$lang_search_php['days']}</td>
                                        </tr>
                                        <tr>
                                                <td><input type="checkbox" name="filename" id="filename" class="checkbox" checked="checked" /><label for="filename" class="clickable_option">
{$lang_adv_opts['filename']}</label></td>
                                             <td align="right">
{$lang_search_php['older_than']} <input type="text" name="older_than" size="3" maxlength="4" class="textinput" /> {$lang_search_php['days']}</td>
                                        </tr>
                                       <tr>
                                                <td><input type="checkbox" name="album_title" id="album_title" class="checkbox" checked="checked" /><label for="album_title" class="clickable_option">Album Title</label></td>
                                                <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                                <td><input type="checkbox" name="album_description" id="album_description" class="checkbox" checked="checked" /><label for="album_description" class="clickable_option">Album Description</label></td>
                                                <td>&nbsp;</td>
                                        </tr>
                                </table>
                        </td>
                </tr>
EOT;
searchdb_showlast(5truetrue);
endtable();
echo 
'</form>';

if (
$CONFIG['clickable_keyword_search'] != 0) {
    include(
'include/keyword.inc.php');
}

echo <<< EOT
      <script language="javascript" type="text/javascript">
      <!--
      document.searchcpg.search.focus();
      -->
      </script>
EOT;

pagefooter();
ob_end_flush();
?>

also when clicking a link that is created by this mod, the album search is disabled, i understand its probably far to much to ask, but if you know a simple to solution to make the links include the albums it finds on the search string it would be awesome!

Thanks for this wonderful plugin modification.
« Last Edit: November 25, 2007, 03:15:20 PM by GauGau »
Logged

radium35

  • Coppermine newbie
  • Offline Offline
  • Posts: 14

how would i be able to output this data in 7 columns and 10 rows
Logged
Pages: [1]   Go Up
 

Page created in 0.123 seconds with 19 queries.