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: IPTC problems when values are arrays  (Read 7434 times)

0 Members and 1 Guest are viewing this topic.

kaptainkory

  • Tester
  • Coppermine regular visitor
  • *
  • Offline Offline
  • Posts: 51
IPTC problems when values are arrays
« on: July 28, 2005, 07:42:57 am »

IPTC Keywords and Subcategories don't work.  The problem seems to be in iptc.inc.php at line 49:

Code: [Select]
$IPTC_data[$key] = htmlentities(strip_tags(trim($data,"\x7f..\xff\x0..\x1f")),ENT_QUOTES); //sanitize data against sql/html injection; trim any nongraphical non-ASCII character:

This code is not "array friendly".  It  needs to be taken into account that $data could be an array rather than a string value.  I'll leave it up to the coders to solve.

I'd also like to suggest that IPTC Headline replace the current IPTC Title information when displaying IPTC data for an image.  I've used several different freeware programs that allows editing of metadata and not a one of them has anything about IPTC Title.  (As a request on the side, what about turning the EXIF Manager into the EXIF/IPTC Manager?)

Thanks.
« Last Edit: August 09, 2005, 03:56:59 am by donnoman »
Logged

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
Re: IPTC problems when values are arrays
« Reply #1 on: July 29, 2005, 07:01:13 am »

Can you upload as small sample image where IPTC data is an array I will look into it - I can code it without having a sample but that would be being blind.

Also - you can fix the IPTC Title by editing the Lang file
Logged
SANIsoft PHP applications for E Biz

kaptainkory

  • Tester
  • Coppermine regular visitor
  • *
  • Offline Offline
  • Posts: 51
Re: IPTC problems when values are arrays
« Reply #2 on: July 29, 2005, 04:58:24 pm »

Right now, I'm running Coppermine on my local machine as "localhost".  Set some IPTC keywords or subcategories to any JPEG and you should be able to replicate the problem.  If you don't get to it, I can have something online to show in 3 or 4 days.

Thanks.
Logged

donnoman

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1615
  • From donovanbray.com
    • Donovan Bray
Re: IPTC problems when values are arrays
« Reply #3 on: July 30, 2005, 05:34:09 am »

*any* jpeg.. If that were true we would have run accross this before.

If you could just upload a couple of the offending jpegs to this forum we can use those to test with.

@tarique I do have some sample exif/iptc images on my gallery

http://donovanbray.com/index.php?cat=3

but I haven't seen any of them trip up the iptc/exif thats currently in Coppermine.
Logged

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
Re: IPTC problems when values are arrays
« Reply #4 on: July 30, 2005, 01:09:24 pm »

@donnoman IPTC and EXIF are not interchangeable
Logged
SANIsoft PHP applications for E Biz

donnoman

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1615
  • From donovanbray.com
    • Donovan Bray
Re: IPTC problems when values are arrays
« Reply #5 on: July 30, 2005, 04:44:37 pm »

@tarique I didn't suggest they were, I just have a gallery of images that have IPTC and some with EXIF information.

However I do think in a future version we should probably treat them identically. For example we cache the exif info, but don't cache the iptc info. It would make sense to me that we support both in similar fashions.

By caching the info we would be able to search by IPTC fields, but that really is off topic for this post.

Bottom line is we need some images that exhibit this behavior, I have a gallery of various images with exif and some with iptc, but I haven't seen this behavior.
Logged

kaptainkory

  • Tester
  • Coppermine regular visitor
  • *
  • Offline Offline
  • Posts: 51
Re: IPTC problems when values are arrays
« Reply #6 on: August 02, 2005, 01:51:23 am »

Okay, the first attachment shows the errors I'm getting when I set IPTC Keywords and Subcategories.  The second attachment shows that IPTC Keywords and IPTC Subcategories is blank.  The third attachment is the actual picture that is throwing the errors (though I'm getting the same behavior with any other picture I set to show IPTC Keywords or Subcategories).

Quote
Also - you can fix the IPTC Title by editing the Lang file

Not quite as easy as that since the information is extracted in diplayimage.php at line 154:

Code: [Select]
        if (isset($iptc['Title'])) $info[$lang_picinfo['iptcTitle']] = trim($iptc['Title']);
Quote
By caching the info we would be able to search by IPTC fields, but that really is off topic for this post.

I totally agree!  It seems like there is some room for improvement in this area.  For example, why aren't IPTC Keywords plugged in as CPG Keywords when pictures are added?  And why can't the EXIF Manager simply be the METADATA Manager or something like that and take care of EXIF, ITPC, JPEG COMMENT, FILE DATA, etc. altogether?  Okay, I'll stop now.  I know it's off-topic.

Thanks.
Logged

donnoman

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1615
  • From donovanbray.com
    • Donovan Bray
Re: IPTC problems when values are arrays
« Reply #7 on: August 02, 2005, 03:15:57 am »

Quote
For example, why aren't IPTC Keywords plugged in as CPG Keywords when pictures are added?

If you have 1.4 installed and IPTC turned on IT SHOULD be automatically adding the IPTC keywords to coppermines keywords.
Logged

kaptainkory

  • Tester
  • Coppermine regular visitor
  • *
  • Offline Offline
  • Posts: 51
Re: IPTC problems when values are arrays
« Reply #8 on: August 02, 2005, 03:27:59 am »

I'm running CVS devel from this morning.  Have you tested that pic?
Logged

kaptainkory

  • Tester
  • Coppermine regular visitor
  • *
  • Offline Offline
  • Posts: 51
Re: IPTC problems when values are arrays
« Reply #9 on: August 07, 2005, 09:42:38 pm »

I looked into this issue again and suggest the following:

In iptc.inc.php, FIND (line 48):

Code: [Select]
                foreach ($IPTC_data as $key=>$data) {
                   $IPTC_data[$key] = htmlentities(strip_tags(trim($data,"\x7f..\xff\x0..\x1f")),ENT_QUOTES); //sanitize data against sql/html injection; trim any nongraphical non-ASCII character:
                }

REPLACE WITH:

Code: [Select]
                foreach ($IPTC_data as $key=>$data) {
                    if (is_array($data)) {
                        for ($i=0;$i<count($data);$i++) {
                            $IPTC_data[$key] = htmlentities(strip_tags(trim($data,"\x7f..\xff\x0..\x1f")),ENT_QUOTES); //sanitize data against sql/html injection; trim any nongraphical non-ASCII character:
                        }
                    else {
                        $IPTC_data[$key] = htmlentities(strip_tags(trim($data,"\x7f..\xff\x0..\x1f")),ENT_QUOTES); //sanitize data against sql/html injection; trim any nongraphical non-ASCII character:
                    }
                }
                $IPTC_data=filter_content($IPTC_data);   //run the data against the bad word list
            }

Thanks.
Logged

donnoman

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1615
  • From donovanbray.com
    • Donovan Bray
Re: IPTC problems when values are arrays
« Reply #10 on: August 08, 2005, 12:09:34 am »

I implemented it as a recursive function

Code: [Select]
function strip_IPTC($data) {
    if (is_array($data)) {
        foreach ($data as $key=>$item) {
             $data[$key]=strip_IPTC($item);
        }
    } else {
         $data=htmlentities(strip_tags(trim($data,"\x7f..\xff\x0..\x1f")),ENT_QUOTES); //sanitize data against sql/html injection; trim any nongraphical non-ASCII character:
    }
    return $data;
}

I did test your snake picture with this, and it worked like a charm. Thanks for your help in locating and suggesting a fix for the problem.
Logged

sublime

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: IPTC problems when values are arrays
« Reply #11 on: August 08, 2005, 04:26:59 am »

I'm having the same problem, I think.  I cannot get my IPTC keywords to show up in CPG.  I tried your fix above and get this error when trying to view any photos now:

Code: [Select]
Parse error: parse error, unexpected T_ELSE in /home/ramoswa/public_html/waramos/include/iptc.inc.php on line 53
Here's the code I am using:


 
Code: [Select]
             foreach ($IPTC_data as $key=>$data) {
                    if (is_array($data)) {
                        for ($i=0;$i<count($data);$i++) {
                            $IPTC_data[$key] = htmlentities(strip_tags(trim($data,"\x7f..\xff\x0..\x1f")),ENT_QUOTES); //sanitize data against sql/html injection; trim any nongraphical non-ASCII character:
                        }
                    else {
                        $IPTC_data[$key] = htmlentities(strip_tags(trim($data,"\x7f..\xff\x0..\x1f")),ENT_QUOTES); //sanitize data against sql/html injection; trim any nongraphical non-ASCII character:
                    }
                }
                $IPTC_data=filter_content($IPTC_data);   //run the data against the bad word list
            }
return $IPTC_data;
}


Any help would be much appreciated! Thanks! =)
Logged

donnoman

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 1615
  • From donovanbray.com
    • Donovan Bray
Re: IPTC problems when values are arrays
« Reply #12 on: August 08, 2005, 07:10:41 am »

the code snippit you are referring to won't work as posted. I've already posted and comitted a fix that uses a recursive function to do what that one was intending to do.

Just update your cvs install of coppermine and you should get it.

Note: Sometimes it can take 24 hours after a dev has made a commit before it actually shows up as available in anonymous cvs.

try this snippit

Code: [Select]
function strip_IPTC($data) {
    if (is_array($data)) {
        foreach ($data as $key=>$item) {
             $data[$key]=strip_IPTC($item);
        }
    } else {
         $data=htmlentities(strip_tags(trim($data,"\x7f..\xff\x0..\x1f")),ENT_QUOTES); //sanitize data against sql/html injection; trim any nongraphical non-ASCII character:
    }
    return $data;
}

function get_IPTC($filename) {
        $IPTC_data=array();
        $size = GetImageSize ($filename, $info);
        if (isset($info["APP13"])) {
            $iptc = iptcparse($info["APP13"]);
            if (is_array($iptc)) {
                $IPTC_data=array(        "Title"                        =>         $iptc["2#005"][0],        # Max 65 octets, non-repeatable, alphanumeric
                                        "Urgency"                =>         $iptc["2#010"][0],        # Max 1 octet, non-repeatable, numeric, 1 - High, 8 - Low
                                        "Category"                =>         $iptc["2#015"][0],        # Max 3 octets, non-repeatable, alpha
                                        "SubCategories"                =>         $iptc["2#020"],                # Max 32 octets, repeatable, alphanumeric
                                        "Keywords"                =>         $iptc["2#025"],                # Max 64 octets, repeatable, alphanumeric
                                        "Instructions"                =>         $iptc["2#040"][0],        # Max 256 octets, non-repeatable, alphanumeric
                                        "CreationDate"                =>         $iptc["2#055"][0],        # Max 8 octets, non-repeatable, numeric, YYYYMMDD
                                        "CreationTime"                =>         $iptc["2#060"][0],        # Max 11 octets, non-repeatable, numeric+-, HHMMSS(+|-)HHMM
                                        "ProgramUsed"                =>         $iptc["2#065"][0],        # Max 32 octets, non-repeatable, alphanumeric
                                        "Author"                =>         $iptc["2#080"][0],        #!Max 32 octets, repeatable, alphanumeric
                                        "Position"                =>         $iptc["2#085"][0],        #!Max 32 octets, repeatable, alphanumeric
                                        "City"                        =>         $iptc["2#090"][0],        # Max 32 octets, non-repeatable, alphanumeric
                                        "State"                        =>         $iptc["2#095"][0],        # Max 32 octets, non-repeatable, alphanumeric
                                        "Country"                =>         $iptc["2#101"][0],        # Max 64 octets, non-repeatable, alphanumeric
                                        "TransmissionReference"        =>         $iptc["2#103"][0],        # Max 32 octets, non-repeatable, alphanumeric
                                        "Headline"                =>         $iptc["2#105"][0],        # Max 256 octets, non-repeatable, alphanumeric
                                        "Credit"                =>         $iptc["2#110"][0],        # Max 32 octets, non-repeatable, alphanumeric
                                        "Source"                =>         $iptc["2#115"][0],        # Max 32 octets, non-repeatable, alphanumeric
                                        "Copyright"                =>         $iptc["2#116"][0],        # Max 128 octets, non-repeatable, alphanumeric
                                        "Caption"                =>         $iptc["2#120"][0],        # Max 2000 octets, non-repeatable, alphanumeric
                                        "CaptionWriter"                =>         $iptc["2#122"][0],       # Max 32 octets, non-repeatable, alphanumeric
                );
                $IPTC_data=strip_IPTC($IPTC_data); //sanitize data against sql/html injection; trim any nongraphical non-ASCII character:
                $IPTC_data=filter_content($IPTC_data);   //run the data against the bad word list
            }
        }
return $IPTC_data;
}
Logged

sublime

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: IPTC problems when values are arrays
« Reply #13 on: August 08, 2005, 12:47:19 pm »

donnoman,

Thanks! That did the trick!    :)

One other quick question:  Will the IPTC keywords in my photos be searchable? Right now, I can see the IPTC keywords but the searching doesn't seem to pick them up. 

~Sub
Logged

sublime

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: IPTC problems when values are arrays
« Reply #14 on: August 08, 2005, 01:22:38 pm »

Sorry...Just found this topic and inserted the small bit of code and now I'm able to search my IPTC keywords after uploading photos to my gallery:
http://forum.coppermine-gallery.net/index.php?topic=692.0

Although I wonder if there is a a way for me to fix / import my IPTC fields to the photos that are already in my gallery?

Thanks again! I really appreciate the time and help!

~Sub

Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: IPTC problems when values are arrays
« Reply #15 on: August 08, 2005, 09:02:31 pm »

*clearing throat, shaking naughty finger*
This thread deals with other issues, it's not a support thread. Please help us fix all bugs in cpg1.4.x as quickly as possible to have a stable release soon by not posting support requests or hijacking threads. This thread is about the suggested modifications of IPTC array, not about searching for IPTC keywords.

Joachim
Logged

sublime

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: IPTC problems when values are arrays
« Reply #16 on: August 08, 2005, 09:09:43 pm »

Gotcha! I apologize. Thanks again for the help!  :)

~Sub
Logged
Pages: [1]   Go Up
 

Page created in 0.023 seconds with 19 queries.