IPTC problems when values are arrays IPTC problems when values are arrays
 

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]

Main Menu

IPTC problems when values are arrays

Started by kaptainkory, July 28, 2005, 07:42:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kaptainkory

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

$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.

Tarique Sani

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
SANIsoft PHP applications for E Biz

kaptainkory

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.

donnoman

*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.

Tarique Sani

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

donnoman

@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.

kaptainkory

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).

QuoteAlso - 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:

        if (isset($iptc['Title'])) $info[$lang_picinfo['iptcTitle']] = trim($iptc['Title']);

QuoteBy 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.

donnoman

QuoteFor 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.

kaptainkory

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

kaptainkory

I looked into this issue again and suggest the following:

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

                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:

                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.

donnoman

I implemented it as a recursive function


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.

sublime

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:

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:


             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! =)

donnoman

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


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;
}

sublime

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

sublime

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


Joachim Müller

*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

sublime

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

~Sub