Author Topic: Multi-word keywords  (Read 12831 times)

0 Members and 1 Guest are viewing this topic.

Offline SunnyUK

  • Newbie
  • *
  • Posts: 35
    • View Profile
Multi-word keywords
« on: May 31, 2008, 12:43:33 AM »
First of all, I am not a php programmer. In fact today was the first time I ever tried to write a single php statement. So beware that what follows might be utter rubish! ;)

Having said that, I wanted to be able to handle keywords which consists of several individual words. Out-of-the-box 4images would treat the keyword <Summer evening> as two separate words. In English where a lot of phrases are made up of individual words without a dash or anything in between, this feels awkward.

I have spent hours scanning the forum, and it seems that others have asked for this without it being resolved.

My solution builds upon Rembrandt's IPTC V.1.7.6 Suchfelder erweiterung mod: http://www.4homepages.de/forum/index.php?topic=21141.0
Do not attempt this mini-mod-attempt without first having applied Rembrand's mod.

Here goes

a) The idea is to convert spaces to underscores when keywords come into the system and convert underscores back to spaces when keywords are displayed (the keywords table strip underscores away, so a keyword <Summer_Evening> will be stored there as <SummerEvening> which is pretty perfect as it prevents hits if people search for <Summer>).
b) keywords can come into the system from IPTC tags (which corresponds to the tags displayed by e.g. Vista or Photoshop) - see edit 2) below
c) keywords can be entered directly on the "edit image" form in the APC. I don't know how to intercept that... if anyone has an idea, please shout!
d) keywords are shown on the detail screen as clickable hyperlinks - see edit 1) below

1) Edit includes\functions.php.

Find

Code: [Select]
  if (!empty($image_row['image_keywords'])) {
    $split_keywords = explode(" ", $image_row['image_keywords']);
    $keywords = "";
    foreach ($split_keywords as $key => $val) {
        $keywords .= (($keywords != "" ) ? ", " : "")."<a href=\"".$site_sess->url(ROOT_PATH."search.php?search_keywords=".urlencode($val))."\">".format_text($val, 2)."</a>";
    }

Replace by

Code: [Select]
  if (!empty($image_row['image_keywords'])) {
    $split_keywords = explode(" ", $image_row['image_keywords']);
    $keywords = "";
    foreach ($split_keywords as $key => $val) {
        $oldval = $val;
        if ($val != "") {
        $val = str_replace('_', ' ', $val);
}
        $keywords .= (($keywords != "" ) ? ", " : "")."<a href=\"".$site_sess->url(ROOT_PATH."search.php?search_keywords=".urlencode($oldval))."\">".format_text($val, 2)."</a>";
    }

2) Edit \admin\checkimages.php

Find

Code: [Select]
  $iptc_keywords_default = 0; //auto insert keyword from IPTC (0 or 1)

Replace with
Code: [Select]
  $iptc_keywords_default = 1; //auto insert keyword from IPTC (0 or 1)

Find

Code: [Select]
                $caption = ($iptc_description && isset($iptc['2#120'][0])) ? $iptc['2#120'][0] : "";
                $keywords = "";
                if ($iptc_keywords && isset($iptc['2#025']))
                {
                  foreach ($iptc['2#025'] as $val)
                  {
                    $keywords .= (($keywords != "" ) ? " " : "").$val;
                  }

Replace with

Code: [Select]
                $caption = ($iptc_description && isset($iptc['2#120'][0])) ? $iptc['2#120'][0] : "";
                $keywords = "";
                if ($iptc_keywords && isset($iptc['2#025']))
                {
                  foreach ($iptc['2#025'] as $val)
                  {
                    $val = str_replace(' ', '_', $val);
                    $keywords .= (($keywords != "" ) ? " " : "").$val;
                  }

3) This works if you get your pictures into the database by
a) FTP'ing the images to your site
b) running a "check images" from the APC

4) This also works if you type in keywords with underscores in place. So say you wanted to type in the tag <Summer Evening>, you would type it in as <Summer_Evening>. I have not been able figure out how to get checkimage.php to automatically replace <Summer Evening> with <Summer_Evening> for you, so unless someone can point me in the right direction (?), I can't help here. As I aim to have my images tagged before upload, it's not a huge problem for me, but it would be nice to find a solution.

As I started by saying, this is my first attempt at modifying 4images or anything else in php. It is entirely possible that this "mod" will break something or that there are side effects which I haven't considered. So use it at your own peril. Having said that, if you do use it, please let me know if it also works acceptable for you or if you run into problems.

Offline kervol

  • Pre-Newbie
  • Posts: 1
    • View Profile
Re: Multi-word keywords
« Reply #1 on: October 03, 2008, 11:57:44 PM »
 :P

Actually, if you want to make it a little easier..

Go to phpmyadmin located in your cpanel, search for your 4images database and go to images and select the images you want to add the keywords to and add keywords as follows "kate&nbsp;beckinsale beckinsale beckinsale&nbsp;kate" and it will look like this when saved "kate beckinsale, beckinsale, beckinsale kate"

You will accomplich 2 things...

1. Add the multi keywords you want to add without the comma issue
2. You will be able to edit and add multiple keywords and descriptions without the save and search wait through the control panel of 4images

Kervol
http://ibizpanelhosting.com

Offline Anita

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: Multi-word keywords
« Reply #2 on: October 16, 2008, 09:08:05 PM »
Is it that easy? I just got done reading your log on:

B) keywords can come into the system form a IPTC tags.

I would like for the images I add to the gallery using, Check New Images,  with 4 images control panel to add the keywords I have already placed using lightroom or photoshop. If I add the code you suggested, will the keywords from my IPTC tags be added to the keyword area in the 4image gallery, and will these keywords work in the 4 image search box with out going into the control panel  and adding to each image.

Anita

Offline SunnyUK

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Multi-word keywords
« Reply #3 on: October 16, 2008, 09:12:56 PM »
Yes, it really is that easy.

Don't forget to also implement http://www.4homepages.de/forum/index.php?topic=21141.0, though

Offline Anita

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: Multi-word keywords
« Reply #4 on: October 16, 2008, 09:21:45 PM »
What do you mean by this:
Don't forget to also implement http://www.4homepages.de/forum/index.php?topic=21141.0, though
Anita

Offline SunnyUK

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Multi-word keywords
« Reply #5 on: October 16, 2008, 11:10:07 PM »
I mean that the code I have written above only deals with the multi-word keywords.

The real clever stuff, the stuff that makes sure that keywords entered into the IPTC tags (via Photoshop or Lightroom or other programs) are stored in 4images keywords is explained in the link http://www.4homepages.de/forum/index.php?topic=21141.0 .

Offline Anita

  • Pre-Newbie
  • Posts: 3
    • View Profile
Re: Multi-word keywords
« Reply #6 on: October 20, 2008, 11:19:24 PM »
I went into the sheckimages.php file to make the code updates you have suggested in the Forum, but I could not find the exact code to make the changes. I to am not a PHP programer and this will be my first attempt changing the code. Do you have any other suggestions.

Just to be clear, I have attached a image explaining my needs.
Like to have the IPTC info load automatically for each image with out clicking on the IPTC buttons to the left.


Thank Anita

Offline SunnyUK

  • Newbie
  • *
  • Posts: 35
    • View Profile
Re: Multi-word keywords
« Reply #7 on: October 21, 2008, 09:50:59 AM »
Anita,

if you open the file admin\checkimages.php and look at lines 50-60. They look something like this.....:

Code: [Select]
{
  $annotate_default = (isset($config['annotation_use'])) ? $config['annotation_use'] : 0; //add annotation to the images (require "Annotation MOD" by SLL)
  $big_default = 1; //save original image (0 or 1)
  $iptc_date_default = 1; //auto insert date from IPTC (0 or 1)  UPDATED TO 1 TRP
  $iptc_keywords_default = 1; //auto insert keyword from IPTC (0 or 1) UPDATED TO 1 TRP
  $iptc_description_default = 1; //auto insert captions from IPTC (0 or 1) UPDATED TO 1 TRP
  $iptc_name_default = 1; //auto insert name from IPTC (0 or 1) UPDATED TO 1 TRP
  $detailed_default = 0; //detailed view (0 or 1)
  $auto_resize_default = 1; //resize images (0 or 1)
  $auto_thumbs_default = 1; //create thumbs (0 or 1)
  $subcats_default = 0; //include subcategories (0 or 1)
}

This is where you set the default behaviour of the checkimages routine. The ones that says "updated to 1 trp" are the ones I have flicked from 0 to 1 in order to get the behaviour you're looking for.

Hope this helps.

Offline whosthis.ee

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: Multi-word keywords
« Reply #8 on: July 10, 2009, 05:27:27 PM »
HI

Im using 1.7.6

i can'f find this line on checkimages.php

Quote
$iptc_keywords_default = 0; //auto insert keyword from IPTC (0 or 1)