forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Searching => Topic started by: FlemishDreams on March 24, 2006, 06:36:47 pm

Title: Keywords and Stock Photography
Post by: FlemishDreams on March 24, 2006, 06:36:47 pm
The keywording system in CPG1.44 finally works, and it works great! Stock photographers that are used to submit to stock agencies like Dreamstime, Istock, Bigstoc, Shuttershock most of the time have a heavily IPTC-keyworded portfolio. Each agency uses other rules for kwd separation, like spaces, commas, semicolons. Kwd separation by a comma and a space works for all, so that's how we keyword. Importing a portfolio in CPG is simple now, with the clickable keywords.

But the kwd separation in CPG is only on white spaces, which means that commas for instance are added to the keyword. Moreover, stock photogs use *loads* of keywords, very often over the 256-character boundary. That means that in CPG, the last kwd is truncated somewhere in the middle.
There is another issue, in the kwd management of CPG. When a kwd contains upper case characters, they have to be changed first into lower case to be deleted, since they are saved as lower-case in the database. This code also removes the duplicate keywords.

Since I don't have any intention to re-keywd my entire portfolio just for my personal CPG gallery, I wrote a hack that solves these problems. It just involves one file, and it seems to work OK with me.

The file is iptc.inc.php in the include/ subdirectory of the main CPG distribution.
File ID:
Code: [Select]
Coppermine version: 1.4.4
  $Source: /cvsroot/coppermine/stable/include/iptc.inc.php,v $
  $Revision: 1.10 $
  $Author: gaugau $
  $Date: 2006/02/24 13:32:44 $

Go to the {} block where the $IPTC_data array is built. Go under that block, at line 59 where you can find this:
Code: [Select]
$IPTC_data=strip_IPTC($IPTC_data);Insert the following code in front of that line:

Code: [Select]
// my additions - begin
if (isset($IPTC_data["Keywords"])) {
$tmp_arr = $IPTC_data["Keywords"];
//$tmp_str = str_replace('-','_',strtolower($tmp_arr[0])); // lowercase, replace hyphens by underscores
//$tmp_str = str_replace('-','',strtolower($tmp_arr[0])); // lowercase, remove hyphens
$tmp_str = strtolower($tmp_arr[0]); // lowercase
$tmp_res_array = array();
$tok = strtok($tmp_str, ",;.: \n\t");
while ($tok !== false) {
array_push($tmp_res_array,$tok);
$tok = strtok(",;.: \n\t");
}
$tmp_res_array = array_unique($tmp_res_array); // remove duplicates
$tmp_str = '';
$topad = TRUE;
foreach($tmp_res_array as $word) {
if (((strlen($tmp_str) + strlen($word)) >= 256) && $topad) { // avoid split words at the 256 boundary to be added to the keywords
$tmp_str = str_pad($tmp_str,256," ");
$topad = FALSE;
}
$tmp_str .= $word." ";
}
$tmp_arr[0] = trim($tmp_str);
$IPTC_data["Keywords"] = $tmp_arr;
}
// my additions - end



If you want to preserve the upper cases, just replace this line:
Code: [Select]
$tmp_str = strtolower($tmp_arr[0]);by this one:
Code: [Select]
$tmp_str = $tmp_arr[0];
I also have been playing with the 256-chars boundary (with is a bit tight for stock photogs) but no success yet. It's not that this module doesn't *read* them, it's just the 256 bounday set on array elements.

Of course, if you apply this hack, make sure you backup your original version first. And yes, I *know* that loads of keywords make your app slower. You can always delete synonym and plural kwds afterwards in the  kwd manager.

There was a small bug in the code of the original post as to the 256-char boundary. I put the right version in here on March 30, 2006.

Note April 2, 2006 concerning hyphens. Stock sites are not consistent how to treat hyphens and quotes. As to CPG, I noted that a keyword with a hyphen (e.g. palm-tree) goes in the database, but when you click on it, you get "no files". As a workaround, I added the option to remove hyphens alltogether. You can choose out of 3 behaviors now: (1) just lowercase (2) lowercase and hyphens converted to underscore (doesn't work for clicking), (3) lowercase and hyphens removed (works for clicking). Comment out the behavior you don't want in this part of the code:

Code: [Select]
//$tmp_str = str_replace('-','_',strtolower($tmp_arr[0])); // lowercase, replace hyphens by underscores
//$tmp_str = str_replace('-','',strtolower($tmp_arr[0])); // lowercase, remove hyphens
$tmp_str = strtolower($tmp_arr[0]); // lowercase