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: need keywords with embedded spaces  (Read 5649 times)

0 Members and 1 Guest are viewing this topic.

wprowe

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • Music, Travel, Outdoor, Nature and Wildlife Photography
need keywords with embedded spaces
« on: September 25, 2006, 10:41:00 pm »

CPG does not properly handle keywords with embedded spaces. Suppose I have a keyword "Sugar Maple" to identify a kind of tree. CPG turns that into "Sugar" and "Maple" - two keywords instead of one. The problem manifests itself in the keyword search feature in the detailed image info form. Instead of "Suger Maple" showing up as a single search link, "sugar" and "maple" are displayed as separate search links - each link searching only for the individual word "sugar" or "maple" respectively.

Other examples where spaces will be embedded in keywords are band names (Van Halen, Def Leppard, Goo Goo Dolls, The Who, Grateful Dead), names and titles (Wolfgang Amadeus Mozart, Prime Minister, Vice President), landmarks (Grand Canyon, Eiffel Tower, Big Ben, Machu Picchu), country/ state names and continents (South Korea, North Dakota, South America, East Timor), etc. As you can see, this is a serious problem for stock photographers like me. We need a reliable search engine where our clients can search our image gallery and accurately find things.

The keywords are properly stored in the original image files and correctly extracted into the initial iptc array in includes/iptc.inc.php. Later calls to implode in include/picmgmt.inc.php and upload.php before storing in the pictures table use a space as the glue string to flatten out the keywords array into a varchar string. This is where the problem gets introduced. From there on, it is impossible to determine which spaces were originally embedded in keywords and which were used as glue strings. I suggest using a semi-colon as the glue string. Many programs use it as a delimiter when entering multiple keywords. I'm sure code will have to be changed in numerous places to correct this problem and support using the semi-colon delimiter (and creating proper search links in the detailed image info form).

UPDATE:
I figured out a pattern for preg_replace() in displayimage.php to properly parse using a semi-colon delimiter for keywords. The pattern should be /([^;]+)/, which matches one or more of anything but a semi-colon. This allows commas to be embedded in keywords just in case someone wanted to use it - for example "Washington, DC", "Dr. Neil Clark Warren, Ph.D" or "Dale Earnhardt, Jr" are valid keywords with commas in them.
« Last Edit: November 05, 2006, 10:54:32 am by GauGau »
Logged
Walter Rowe
Music, Travel, Outdoor, Nature and Wildlife Photography

DMR

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: need keywords with embedded spaces
« Reply #1 on: November 03, 2006, 10:03:00 pm »

Thanks for the start!

To finish it up for the whole system you need to change the following. 

In displayimage.php
Code: [Select]
Change:
        $info[$lang_picinfo['Keywords']] = '<span class="alblink">' . preg_replace("/(\S+)/", "<a href=\"thumbnails.php?album=search&amp;search=\\1\">\\1</a>" , $CURRENT_PIC_DATA['keywords']) . '</span>';
To:
        $info[$lang_picinfo['Keywords']] = '<span class="alblink">' . preg_replace("/([^;]+)/", "<a href=\"thumbnails.php?album=search&amp;search=\\1\">\\1</a>" , $CURRENT_PIC_DATA['keywords']) . '</span>';


Change:
        if (!empty($iptc['Keywords'])) $info[$lang_picinfo['iptcKeywords']] = implode(' ',$iptc['Keywords']);

To:
        if (!empty($iptc['Keywords'])) $info[$lang_picinfo['iptcKeywords']] = implode(';',$iptc['Keywords']);


In keywordmgr.php
Code: [Select]
Change:
       $query = "SELECT `pid`,`keywords` FROM {$CONFIG['TABLE_PICTURES']} WHERE CONCAT(' ',`keywords`,' ') LIKE '% {$keywordEdit} %'";


To:
       $query = "SELECT `pid`,`keywords` FROM {$CONFIG['TABLE_PICTURES']} WHERE CONCAT(' ',`keywords`,' ') LIKE '%" . $keywordEdit . "%'";


Change:
   while (list($keywords) = mysql_fetch_row($result)) {
       $array = explode(' ',$keywords);

To:
   while (list($keywords) = mysql_fetch_row($result)) {
       $array = explode(' ',$keywords);


In keyword_select.php
Code: [Select]
Change:

               window.opener.document.getElementById(\'keywords\').value += \' \' + str;

To:
            if (window.opener.document.getElementById(\'keywords\').value.length != 0) {
              // DMR if it's not blank add the ; and the value
                window.opener.document.getElementById(\'keywords\').value += \';\' + str;
            } else {
              // Just add the value
                window.opener.document.getElementById(\'keywords\').value = str;
            }


in keyword_create_dict.php
Code: [Select]
Change:
    $keyArr   = explode(" ",$keywords);

To:
    $keyArr   = explode(";",$keywords);

in upload.php
Code: [Select]
Change:
    array($lang_upload_php['keywords'], 'keywords', 0, 255, 1,(isset($iptc['Keywords'])) ? implode(' ',$iptc['Keywords']): ''),
To:
    array($lang_upload_php['keywords'], 'keywords', 0, 255, 1,(isset($iptc['Keywords'])) ? implode(';',$iptc['Keywords']): ''),

in keyword.inc.php
Code: [Select]
Change:
      $array = explode(" ",$keywords);

To:
      $array = explode(";",$keywords);

in picmgmt.inc.php
Code: [Select]
Change:
               $keywords = (isset($iptc['Keywords'])) ? implode(' ',$iptc['Keywords']) : $keywords;

To:
               $keywords = (isset($iptc['Keywords'])) ? implode(';',$iptc['Keywords']) : $keywords;


Then finally update the language file you are using so the users know what to do now.

Code: [Select]
Change:
  'keywords' => 'Keywords (separate with spaces)<br /><a href="#" onClick="return MM_openBrWindow(\'keyword_select.php\',\'selectKey\',\'width=250, height=400, scrollbars=yes,toolbar=no,status=yes,resizable=yes\')">Insert from list</a>', //cpg1.4 //DMR Changed to semicolon

To:
  'keywords' => 'Keywords (separate with semi-colons)<br /><a href="#" onClick="return MM_openBrWindow(\'keyword_select.php\',\'selectKey\',\'width=250, height=400, scrollbars=yes,toolbar=no,status=yes,resizable=yes\')">Insert from list</a>', //cpg1.4 //Changed to semicolon

I think that covers everything :)

Hope this helps someone. 

Since it's fairly straight forward (just spread out) I though about adding a global to define the keyword seperator but since I don't plan on changing it again I didn't.  But it might be nice it it was added then set in the install script.

I noticed a missing change to a SQL statement in keywordmgr.php and have added it above.
« Last Edit: November 03, 2006, 10:18:16 pm by DMR »
Logged

ronny

  • Coppermine novice
  • *
  • Country: 00
  • Offline Offline
  • Posts: 49
Re: need keywords with embedded spaces
« Reply #2 on: September 28, 2007, 01:33:57 am »

Sorry for this old thread, but this changes does not work!

ex. the keywords:

tuning;car-wash;lowrider show;crash

the keywords "tuning" and "crash" are ok and working
the keyword "car-wash" doesn´t work cause the "-" (btw. with or without this mod above)
the keyword "lowrider show" works as separat keywords "lowrider" and "show" cause the space

what can i do?  ???
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: need keywords with embedded spaces
« Reply #3 on: October 01, 2007, 07:22:08 am »

Logged
Pages: [1]   Go Up
 

Page created in 0.018 seconds with 20 queries.