Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Bug: Keywords appear multiple times on the search page.  (Read 20687 times)

0 Members and 1 Guest are viewing this topic.

Absoblogginlutely

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
    • http://absoblogginlutely.net/gallery
Bug: Keywords appear multiple times on the search page.
« on: November 24, 2005, 02:32:03 pm »

I have tagged some of my photos with keywords but when i go to my search page (http://www.absoblogginlutely.net/gallery/search.php) all the keywords appear multiple times, so I  have Brian listed 20+ times. I'm guessing there should be some form of unique within the search statement?
« Last Edit: November 29, 2005, 04:02:27 am by DJMaze »
Logged

Absoblogginlutely

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
    • http://absoblogginlutely.net/gallery
Re: Bug: Keywords appear multiple times on the search page.
« Reply #1 on: November 24, 2005, 06:18:01 pm »

Using one of the other search pages I now have http://absoblogginlutely.net/gallery/search2.php which not only has 1 entry per word but also sizes the words ala flickr tags depending on the number of times it has been used. The code is messy and hacked but works.
Logged

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: Bug: Keywords appear multiple times on the search page.
« Reply #2 on: November 24, 2005, 06:21:01 pm »

That's pretty cool. Would you mind sharing the code for search2?
Logged

artistsinhawaii

  • VIP
  • Coppermine addict
  • ***
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 856
    • evj art and photography
Re: Bug: Keywords appear multiple times on the search page.
« Reply #3 on: November 25, 2005, 12:44:27 am »

I have tagged some of my photos with keywords but when i go to my search page (http://www.absoblogginlutely.net/gallery/search.php) all the keywords appear multiple times, so I  have Brian listed 20+ times. I'm guessing there should be some form of unique within the search statement?

Strange, this isn't happening on my setup at all. But then, I haven't uploaded all the updated files from the newly released, stable version into my setup yet.


Dennis
Logged
Learn and live ... In January of 2011, after a botched stent attempt, the doctors told me I needed a multiple bypass surgery or I could die.  I told them I needed new doctors.

Nibbler

  • Guest
Re: Bug: Keywords appear multiple times on the search page.
« Reply #4 on: November 25, 2005, 12:51:30 am »

include/keywords.inc.php

change

Code: [Select]
if (!in_array(strtolower($word),$keywords_array)) $keywords_array[] = $word;
to

Code: [Select]
if (!in_array($word = strtolower($word),$keywords_array)) $keywords_array[] = $word;
Logged

Absoblogginlutely

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
    • http://absoblogginlutely.net/gallery
Re: Bug: Keywords appear multiple times on the search page.
« Reply #5 on: November 25, 2005, 02:02:57 am »

the code i've used is as follows - note I'm not a php coder *at all* so there are probably some awful code things in there. I didn't care too much about the speed (I do a count of each keyword within the loop so there are a lot of database lookups) but as I don't have many keywords *I* don't really care but if someone else wants to improve that would be great.

Code: [Select]
<?php
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.2.0                                            //
// ------------------------------------------------------------------------- //
// Copyright (C) 2002,2003 Gregory DEMAR <gdemar@wanadoo.fr>                 //
// http://www.chezgreg.net/coppermine/                                       //
// ------------------------------------------------------------------------- //
// Updated by the Coppermine Dev Team                                        //
// (http://coppermine.sf.net/team/)                                          //
// see /docs/credits.html for details                                        //
// ------------------------------------------------------------------------- //
// 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('IN_COPPERMINE'true);
define('SEARCH_PHP'true);

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

pageheader($lang_search_php[0]);

starttable(500$lang_search_php[0]);
echo <<< EOT
        <tr><td>Please enter a keyword:</td></tr>
        <tr>
                <form method="get" action="thumbnails.php">
               <input type="hidden" name="album" value="search">
               <input type="hidden" name="type" value="full">
        <td class="tableb" align="center" height="60">
                <input type="input" style="width: 90%" name="search" maxlength="255" value="" class="textinput">
                </td>
        </tr>
        <tr>
                <td colspan="8" align="center" class="tablef">
                        <input type="submit" value="
{$lang_search_php[0]}" class="button">
                </td>
                </form>
        </tr>

EOT;
endtable();

echo 
"<br><br>" ;

// Select all keywords
starttable("80%""All keywords in the database"1);

$result mysql_query("select keywords from {$CONFIG['TABLE_PICTURES']}");

if (!
mysql_num_rows($result)) cpg_die(ERROR$lang_errors['non_exist_ap']);

// Find unique keywords
$keywords_array = array();

while (list(
$keywords) = mysql_fetch_row($result)) {
        
$array explode(" ",$keywords);

        foreach(
$array as $word)
        {
        if (!
in_array($word,$keywords_array)) $keywords_array[] = $word;
       }
}

sort($keywords_array);
$count count($keywords_array);

// Result to table
echo "<tr><td>" ;
for (
$i 0$i $count$i++) {
//get count of each word.
$keywordcountmysql_query("SELECT *  FROM {$CONFIG['TABLE_PICTURES']} where keywords like '%$keywords_array[$i]%'");
        
        
//First divide the number of times a keyword appears by 4, then round down to the nearest whole number. Add 10 to this number to get the pixel size and create a style for this magic number.
        //I couldn't work out how to do a select count * in sql and return data that works hence the my_sql_num_rows instead


        
echo "<a href=\"thumbnails.php?album=search&search=$keywords_array[$i]\" style=\"font-size: " .  floor(10+(mysql_num_rows($keywordcount)/4)) . "px;\">$keywords_array[$i]</a></font> ";
}
echo 
"</td></tr>" ;
endtable();

echo 
pagefooter();
ob_end_flush();

?>

Logged

Nibbler

  • Guest
Re: Bug: Keywords appear multiple times on the search page.
« Reply #6 on: November 25, 2005, 01:17:26 pm »

Please post mods on the mods board and bugs on the bugs board, it gets confusing otherwise. Can someone confirm my fix ?
Logged

Absoblogginlutely

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
    • http://absoblogginlutely.net/gallery
Re: Bug: Keywords appear multiple times on the search page.
« Reply #7 on: November 25, 2005, 08:14:56 pm »

Please post mods on the mods board and bugs on the bugs board, it gets confusing otherwise. Can someone confirm my fix ?
I can confirm this works fine. If someone wants to move my other code to the other forum then feel free.
Logged

flogghe

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 44
    • MaritimeDigital Archive
Re: Bug: Keywords appear multiple times on the search page.
« Reply #8 on: November 28, 2005, 11:23:12 pm »

Thanks Nibbler, it does indeed work!!!  :)

Frederic
Logged
Kind regards,

Frederic Logghe
Webmaster MaritimeDigital Archive
http://www.ibiblio.org/maritime

DJMaze

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 831
    • Dragonfly CMS
Re: Bug: Keywords appear multiple times on the search page.
« Reply #9 on: November 29, 2005, 04:04:59 am »

I've opened the bug again since there are still issues.
strtolower() only works on ANSI characters, not utf8. Use utf_strtolower() instead.

Secondly it seems to be a bug related to PHP 4.4.1, could some confirm this so we can write a report at http://bugs.php.net
Logged
There are 2 kinds of users in this world: satisfied and complainers.
Why do we never hear something from the satisfied users?
http://coppermine-gallery.net/forum/index.php?topic=24315.0

Nibbler

  • Guest
Re: Bug: Keywords appear multiple times on the search page.
« Reply #10 on: November 29, 2005, 10:23:55 am »

What's the bug ?
Logged

artistsinhawaii

  • VIP
  • Coppermine addict
  • ***
  • Country: us
  • Offline Offline
  • Gender: Male
  • Posts: 856
    • evj art and photography
Re: Bug: Keywords appear multiple times on the search page.
« Reply #11 on: November 29, 2005, 10:27:25 am »

I've opened the bug again since there are still issues.
strtolower() only works on ANSI characters, not utf8. Use utf_strtolower() instead.

Secondly it seems to be a bug related to PHP 4.4.1, could some confirm this so we can write a report at http://bugs.php.net


Woah, are you saying that we should replace all such instance in all 10 affected files?

Dennis.
Logged
Learn and live ... In January of 2011, after a botched stent attempt, the doctors told me I needed a multiple bypass surgery or I could die.  I told them I needed new doctors.

DJMaze

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 831
    • Dragonfly CMS
Re: Bug: Keywords appear multiple times on the search page.
« Reply #12 on: November 29, 2005, 05:49:32 pm »

Code: [Select]
if (!in_array(strtolower($word),$keywords_array)) $keywords_array[] = $word;to
Code: [Select]
if (!in_array($word = strtolower($word),$keywords_array)) $keywords_array[] = $word;

The above code stores the keywords in lowercase format inside $keywords_array.
This is because in_array() can only handle ANSI upper/lower casing
So Nibbler's solution makes shure $word is lowercase in any way BUT... since 1.4.x is UTF8 based strtolower() fails since it can't handle multibyte strings. Therefore the new utf_strtolower() function (and some others) are added to handle them even if the PHP functionality mb_* isn't available.

All keywords and keyword searching must be done in lowercase, especialy when you move on to MySQL 5.x since query searching on 'fôo' doesn't find 'fÔo'.
MySQL 4.0.x is no problem since that only understands ANSI and is thereby case-insensitive. Anything else (including Postgre, Oracle, etc.) is case-sensitive.

That's why i re-opened the topic, the issue is wider then that small fix especialy now that there's MySQL 5 support
Logged
There are 2 kinds of users in this world: satisfied and complainers.
Why do we never hear something from the satisfied users?
http://coppermine-gallery.net/forum/index.php?topic=24315.0
Pages: [1]   Go Up
 

Page created in 0.035 seconds with 20 queries.