/**
  * Get parameters for createAsset
  * 
  * @param mixed input
  * @return array
  * @access public
  * @since 7/20/05
  */
 function getSingleAssetInfo($input)
 {
     $assetInfo = array();
     $headerData = get_jpeg_header_data($input);
     $photoshopIRB = get_Photoshop_IRB($headerData);
     $this->_photoshopIPTC = get_Photoshop_IPTC($photoshopIRB);
     // 		printpre($this->_photoshopIPTC);
     $assetInfo['description'] = "";
     $assetInfo['displayName'] = basename($input);
     if (is_array($this->_photoshopIPTC)) {
         foreach ($this->_photoshopIPTC as $array) {
             switch ($array['RecName']) {
                 case 'Caption/Abstract':
                 case 'description':
                     $assetInfo['description'] = $array['RecData'];
                     break;
                 case "Object Name (Title)":
                 case "title":
                     if (strlen(trim($array['RecData']))) {
                         $assetInfo['displayName'] = trim($array['RecData']);
                     }
             }
         }
     }
     // 		printpre($assetInfo);
     // 		exit;
     $mime = Services::getService("MIME");
     $mimeType = $mime->getMimeTypeForFileName(basename($input));
     $generalType = substr($mimeType, 0, strpos($mimeType, '/'));
     if ($generalType == "application" || !$generalType) {
         $assetInfo['type'] = new HarmoniType("Asset Types", "edu.middlebury", "Generic Asset");
     } else {
         $assetInfo['type'] = new HarmoniType("Asset Types", "edu.middlebury", ucfirst($generalType));
     }
     return $assetInfo;
 }
Example #2
0
function get_photoshop_file_info($Exif_array, $XMP_array, $IRB_array)
{
    // Create a blank array to receive the output
    $outputarray = array("title" => "", "author" => "", "authorsposition" => "", "caption" => "", "captionwriter" => "", "jobname" => "", "copyrightstatus" => "", "copyrightnotice" => "", "ownerurl" => "", "keywords" => array(), "category" => "", "supplementalcategories" => array(), "date" => "", "city" => "", "state" => "", "country" => "", "credit" => "", "source" => "", "headline" => "", "instructions" => "", "transmissionreference" => "", "urgency" => "");
    /***************************************/
    // XMP Processing
    // Retrieve the dublin core section from the XMP header
    // Extract the Dublin Core section from the XMP
    $dublincore_block = find_XMP_block($XMP_array, "dc");
    // Check that the Dublin Core section exists
    if ($dublincore_block != FALSE) {
        // Dublin Core Description Field contains caption
        // Extract Description
        $Item = find_XMP_item($dublincore_block, "dc:description");
        // Check if Description Tag existed
        if ($Item != FALSE) {
            // Ensure that the Description value exists and save it.
            if (array_key_exists('children', $Item) && $Item['children'][0]['tag'] == "rdf:Alt" && array_key_exists('value', $Item['children'][0]['children'][0])) {
                $outputarray = add_to_field($outputarray, 'caption', HTML_UTF8_Escape($Item['children'][0]['children'][0]['value']), "\n");
            }
        }
        /***************************************/
        // Dublin Core Creator Field contains author
        // Extract Description
        $Item = find_XMP_item($dublincore_block, "dc:creator");
        // Check if Creator Tag existed
        if ($Item != FALSE) {
            // Ensure that the Creator value exists and save it.
            if (array_key_exists('children', $Item) && $Item['children'][0]['tag'] == "rdf:Seq" && array_key_exists('value', $Item['children'][0]['children'][0])) {
                $outputarray = add_to_field($outputarray, 'author', HTML_UTF8_Escape($Item['children'][0]['children'][0]['value']), "\n");
            }
        }
        /***************************************/
        // Dublin Core Title Field contains title
        // Extract Title
        $Item = find_XMP_item($dublincore_block, "dc:title");
        // Check if Title Tag existed
        if ($Item != FALSE) {
            // Ensure that the Title value exists and save it.
            if (array_key_exists('children', $Item) && $Item['children'][0]['tag'] == "rdf:Alt" && array_key_exists('value', $Item['children'][0]['children'][0])) {
                $outputarray = add_to_field($outputarray, 'title', HTML_UTF8_Escape($Item['children'][0]['children'][0]['value']), ",");
            }
        }
        /***************************************/
        // Dublin Core Rights Field contains copyrightnotice
        // Extract Rights
        $Item = find_XMP_item($dublincore_block, "dc:rights");
        // Check if Rights Tag existed
        if ($Item != FALSE) {
            // Ensure that the Rights value exists and save it.
            if (array_key_exists('children', $Item) && $Item['children'][0]['tag'] == "rdf:Alt" && array_key_exists('value', $Item['children'][0]['children'][0])) {
                $outputarray = add_to_field($outputarray, 'copyrightnotice', HTML_UTF8_Escape($Item['children'][0]['children'][0]['value']), ",");
            }
        }
        /***************************************/
        // Dublin Core Subject Field contains keywords
        // Extract Subject
        $Item = find_XMP_item($dublincore_block, "dc:subject");
        // Check if Subject Tag existed
        if ($Item != FALSE) {
            // Ensure that the Subject values exist
            if (array_key_exists('children', $Item) && $Item['children'][0]['tag'] == "rdf:Bag") {
                // Cycle through each Subject value and save them
                foreach ($Item['children'][0]['children'] as $keywords) {
                    if (!in_array(HTML_UTF8_Escape($keywords['value']), $outputarray['keywords'])) {
                        if (array_key_exists('value', $keywords)) {
                            $outputarray['keywords'][] = HTML_UTF8_Escape($keywords['value']);
                        }
                    }
                }
            }
        }
    }
    /***************************************/
    // Find the Photoshop Information within the XMP block
    $photoshop_block = find_XMP_block($XMP_array, "photoshop");
    // Check that the Photoshop Information exists
    if ($photoshop_block != FALSE) {
        // The Photoshop CaptionWriter tag contains captionwriter - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:CaptionWriter");
        // Check that the CaptionWriter Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'captionwriter', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop Headline tag contains headline - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:Headline");
        // Check that the Headline Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'headline', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop Instructions tag contains instructions - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:Instructions");
        // Check that the Instructions Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'instructions', HTML_UTF8_Escape($Item['value']), "\n");
        }
        /***************************************/
        // The Photoshop AuthorsPosition tag contains authorsposition - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:AuthorsPosition");
        // Check that the AuthorsPosition Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'authorsposition', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop Credit tag contains credit - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:Credit");
        // Check that the Credit Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'credit', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop Source tag contains source - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:Source");
        // Check that the Credit Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'source', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop City tag contains city - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:City");
        // Check that the City Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'city', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop State tag contains state - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:State");
        // Check that the State Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'state', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop Country tag contains country - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:Country");
        // Check that the Country Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'country', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop TransmissionReference tag contains transmissionreference - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:TransmissionReference");
        // Check that the TransmissionReference Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'transmissionreference', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop Category tag contains category - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:Category");
        // Check that the TransmissionReference Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'category', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop DateCreated tag contains date - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:DateCreated");
        // Check that the DateCreated Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'date', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop Urgency tag contains urgency - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:Urgency");
        // Check that the Urgency Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'urgency', HTML_UTF8_Escape($Item['value']), ",");
        }
        /***************************************/
        // The Photoshop SupplementalCategories tag contains supplementalcategories - Find it
        $Item = find_XMP_item($photoshop_block, "photoshop:SupplementalCategories");
        // Check that the SupplementalCategories Field exists
        if ($Item != FALSE) {
            // Check that the values exist
            if (array_key_exists('children', $Item) && $Item['children'][0]['tag'] == "rdf:Bag") {
                // Cycle through the values and save them
                foreach ($Item['children'][0]['children'] as $sup_category) {
                    if (array_key_exists('value', $sup_category) && !in_array(HTML_UTF8_Escape($sup_category['value']), $outputarray['supplementalcategories'])) {
                        if (array_key_exists('value', $sup_category)) {
                            $outputarray['supplementalcategories'][] = HTML_UTF8_Escape($sup_category['value']);
                        }
                    }
                }
            }
        }
    }
    /***************************************/
    // Find the Job Reference Information within the XMP block
    $job_block = find_XMP_block($XMP_array, "xapBJ");
    // Check that the Job Reference Information exists
    if ($job_block != FALSE) {
        // The JobRef Field contains jobname - Find it
        $Item = find_XMP_item($job_block, "xapBJ:JobRef");
        // Check that the JobRef Field exists
        if ($Item != FALSE) {
            // Check that the value exists and save it
            if (array_key_exists('children', $Item) && $Item['children'][0]['tag'] == "rdf:Bag" && array_key_exists('children', $Item['children'][0]) && $Item['children'][0]['children'][0]['tag'] == "rdf:li" && array_key_exists('children', $Item['children'][0]['children'][0]) && $Item['children'][0]['children'][0]['children'][0]['tag'] == "stJob:name" && array_key_exists('value', $Item['children'][0]['children'][0]['children'][0])) {
                $outputarray = add_to_field($outputarray, 'jobname', HTML_UTF8_Escape($Item['children'][0]['children'][0]['children'][0]['value']), ",");
            }
        }
    }
    /***************************************/
    // Find the Rights Information within the XMP block
    $rights_block = find_XMP_block($XMP_array, "xapRights");
    // Check that the Rights Information exists
    if ($rights_block != FALSE) {
        // The WebStatement Field contains ownerurl - Find it
        $Item = find_XMP_item($rights_block, "xapRights:WebStatement");
        // Check that the WebStatement Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            $outputarray = add_to_field($outputarray, 'ownerurl', HTML_UTF8_Escape($Item['value']), "\n");
        }
        /***************************************/
        // The Marked Field contains copyrightstatus - Find it
        $Item = find_XMP_item($rights_block, "xapRights:Marked");
        // Check that the Marked Field exists and save the value
        if ($Item != FALSE && array_key_exists('value', $Item)) {
            if ($Item['value'] == "True") {
                $outputarray = add_to_field($outputarray, 'copyrightstatus', "Copyrighted Work", ",");
            } else {
                $outputarray = add_to_field($outputarray, 'copyrightstatus', "Public Domain", ",");
            }
        }
    }
    /***************************************/
    // Photoshop IRB Processing
    // Check that the Photoshop IRB exists
    if ($IRB_array != FALSE) {
        // Create a translation table to convert carriage returns to linefeeds
        $irbtrans = array("\r" => "\n");
        // The Photoshop IRB Copyright flag (0x040A) contains copyrightstatus - find it
        $IRB_copyright_flag = find_Photoshop_IRB_Resource($IRB_array, 0x40a);
        // Check if the Copyright flag Field exists, and save the value
        if ($IRB_copyright_flag != FALSE) {
            // Check the value of the copyright flag
            if (hexdec(bin2hex($IRB_copyright_flag['ResData'])) == 1) {
                // Save the value
                $outputarray = add_to_field($outputarray, 'copyrightstatus', "Copyrighted Work", ",");
            } else {
                // Do nothing - copyrightstatus will be set to unmarked if still blank at end
            }
        }
        /***************************************/
        // The Photoshop IRB URL (0x040B) contains ownerurl - find it
        $IRB_url = find_Photoshop_IRB_Resource($IRB_array, 0x40b);
        // Check if the URL Field exists and save the value
        if ($IRB_url != FALSE) {
            $outputarray = add_to_field($outputarray, 'ownerurl', strtr($IRB_url['ResData'], $irbtrans), "\n");
        }
        /***************************************/
        // Extract any IPTC block from the Photoshop IRB information
        $IPTC_array = get_Photoshop_IPTC($IRB_array);
        // Check if the IPTC block exits
        if ($IPTC_array != FALSE && count($IPTC_array) != 0) {
            // The IPTC Caption/Abstract Field contains caption - find it
            $record = find_IPTC_Resource($IPTC_array, "2:120");
            // Check if the Caption/Abstract Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'caption', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Caption Writer/Editor Field contains captionwriter - find it
            $record = find_IPTC_Resource($IPTC_array, "2:122");
            // Check if the Caption Writer/Editor Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'captionwriter', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Headline Field contains headline - find it
            $record = find_IPTC_Resource($IPTC_array, "2:105");
            // Check if the Headline Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'headline', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Special Instructions Field contains instructions - find it
            $record = find_IPTC_Resource($IPTC_array, "2:40");
            // Check if the Special Instructions Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'instructions', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC By-Line Field contains author - find it
            $record = find_IPTC_Resource($IPTC_array, "2:80");
            // Check if the By-Line Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'author', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC By-Line Title Field contains authorsposition - find it
            $record = find_IPTC_Resource($IPTC_array, "2:85");
            // Check if the By-Line Title Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'authorsposition', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Credit Field contains credit - find it
            $record = find_IPTC_Resource($IPTC_array, "2:110");
            // Check if the Credit Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'credit', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Source Field contains source - find it
            $record = find_IPTC_Resource($IPTC_array, "2:115");
            // Check if the Source Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'source', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Object Name Field contains title - find it
            $record = find_IPTC_Resource($IPTC_array, "2:05");
            // Check if the Object Name Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'title', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Date Created Field contains date - find it
            $record = find_IPTC_Resource($IPTC_array, "2:55");
            // Check if the Date Created Field exists and save the value
            if ($record != FALSE) {
                $date_array = unpack("a4Year/a2Month/A2Day", $record['RecData']);
                $tmpdate = $date_array['Year'] . "-" . $date_array['Month'] . "-" . $date_array['Day'];
                $outputarray = add_to_field($outputarray, 'date', strtr($tmpdate, $irbtrans), ",");
            }
            /***************************************/
            // The IPTC City Field contains city - find it
            $record = find_IPTC_Resource($IPTC_array, "2:90");
            // Check if the City Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'city', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Province/State Field contains state - find it
            $record = find_IPTC_Resource($IPTC_array, "2:95");
            // Check if the Province/State Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'state', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Country/Primary Location Name Field contains country - find it
            $record = find_IPTC_Resource($IPTC_array, "2:101");
            // Check if the Country/Primary Location Name Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'country', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Original Transmission Reference Field contains transmissionreference - find it
            $record = find_IPTC_Resource($IPTC_array, "2:103");
            // Check if the Original Transmission Reference Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'transmissionreference', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // The IPTC Category Field contains category - find it
            $record = find_IPTC_Resource($IPTC_array, "2:15");
            // Check if the Category Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'category', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // Cycle through the IPTC records looking for Supplemental Category records
            foreach ($IPTC_array as $record) {
                // Check if a Supplemental Category record has been found
                if ($record['IPTC_Type'] == "2:20") {
                    // A Supplemental Category record has been found, save it's value if the value doesn't already exist
                    if (!in_array($record['RecData'], $outputarray['supplementalcategories'])) {
                        $outputarray['supplementalcategories'][] = strtr($record['RecData'], array("\n" => "", "\r" => "
"));
                    }
                }
            }
            /***************************************/
            // The IPTC Urgency Field contains urgency - find it
            $record = find_IPTC_Resource($IPTC_array, "2:10");
            // Check if the Urgency Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'urgency', strtr($record['RecData'], $irbtrans), "\n");
            }
            /***************************************/
            // Cycle through the IPTC records looking for Keywords records
            foreach ($IPTC_array as $record) {
                // Check if a Keywords record has been found
                if ($record['IPTC_Type'] == "2:25") {
                    // A Keywords record has been found, save it's value if the value doesn't already exist
                    if (!in_array($record['RecData'], $outputarray['keywords'])) {
                        $outputarray['keywords'][] = strtr($record['RecData'], array("\n" => "", "\r" => "
"));
                    }
                }
            }
            /***************************************/
            // The IPTC Copyright Notice Field contains copyrightnotice - find it
            $record = find_IPTC_Resource($IPTC_array, "2:116");
            // Check if the Copyright Field exists and save the value
            if ($record != FALSE) {
                $outputarray = add_to_field($outputarray, 'copyrightnotice', strtr($record['RecData'], $irbtrans), "\n");
            }
        }
    }
    /***************************************/
    // EXIF Processing
    // Retreive Information from the EXIF data if it exists
    if ($Exif_array != FALSE || count($Exif_array) == 0) {
        // Check the Image Description Tag - it can contain the caption
        if (array_key_exists(270, $Exif_array[0])) {
            $outputarray = add_to_field($outputarray, 'caption', $Exif_array[0][270]['Data'][0], "\n");
        }
        /***************************************/
        // Check the Copyright Information Tag - it contains the copyrightnotice
        if (array_key_exists(33432, $Exif_array[0])) {
            $outputarray = add_to_field($outputarray, 'copyrightnotice', HTML_UTF8_UnEscape($Exif_array[0][33432]['Data'][0]), "\n");
        }
        /***************************************/
        // Check the Artist Name Tag - it contains the author
        if (array_key_exists(315, $Exif_array[0])) {
            $outputarray = add_to_field($outputarray, 'author', HTML_UTF8_UnEscape($Exif_array[0][315]['Data'][0]), "\n");
        }
    }
    /***************************/
    // FINISHED RETRIEVING INFORMATION
    // Perform final processing
    // Check if any urgency information was found
    if ($outputarray["urgency"] == "") {
        // No urgency information was found - set it to default (None)
        $outputarray["urgency"] = "none";
    }
    // Check if any copyrightstatus information was found
    if ($outputarray["copyrightstatus"] == "") {
        // No copyrightstatus information was found - set it to default (Unmarked)
        $outputarray["copyrightstatus"] = "unmarked";
    }
    // Return the resulting Photoshop File Info Array
    return $outputarray;
}