Пример #1
0
 private function _gmagickRead($ps_filepath)
 {
     try {
         $handle = new Gmagick($ps_filepath);
         $this->setResourceLimits($handle);
         $handle->setimageindex(0);
         // force use of first image in multi-page TIFF
         $this->handle = $handle;
         $this->filepath = $ps_filepath;
         $this->metadata = array();
         // handle metadata
         /* EXIF */
         if (function_exists('exif_read_data') && !$this->opo_config->get('dont_use_exif_read_data')) {
             if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
                 $va_metadata['EXIF'] = $va_exif;
             }
         }
         // if the builtin EXIF extraction is not used or failed for some reason, try ExifTool
         if (!isset($va_metadata['EXIF']) || !is_array($va_metadata['EXIF'])) {
             if (caExifToolInstalled()) {
                 $va_metadata['EXIF'] = caExtractMetadataWithExifTool($ps_filepath, true);
             }
         }
         // Rotate incoming image as needed
         if (isset($va_metadata['EXIF']['IFD0']['Orientation'])) {
             $vn_orientation = $va_metadata['EXIF']['IFD0']['Orientation'];
             $vs_tmp_basename = tempnam(caGetTempDirPath(), 'ca_image_tmp');
             $vb_is_rotated = false;
             switch ($vn_orientation) {
                 case 3:
                     $this->handle->rotateimage("#FFFFFF", 180);
                     unset($va_metadata['EXIF']['IFD0']['Orientation']);
                     $vb_is_rotated = true;
                     break;
                 case 6:
                     $this->handle->rotateimage("#FFFFFF", 90);
                     unset($va_metadata['EXIF']['IFD0']['Orientation']);
                     $vb_is_rotated = true;
                     break;
                 case 8:
                     $this->handle->rotateimage("#FFFFFF", -90);
                     unset($va_metadata['EXIF']['IFD0']['Orientation']);
                     $vb_is_rotated = true;
                     break;
             }
             if ($vb_is_rotated) {
                 if ($this->handle->writeimage($vs_tmp_basename)) {
                     $va_tmp = $this->handle->getimagegeometry();
                     $this->properties["faces"] = $this->opa_faces = caDetectFaces($vs_tmp_basename, $va_tmp['width'], $va_tmp['height']);
                 }
                 @unlink($vs_tmp_basename);
             }
         }
         // get XMP
         $o_xmp = new XMPParser();
         if ($o_xmp->parse($ps_filepath)) {
             if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
                 $va_metadata['XMP'] = array();
                 foreach ($va_xmp_metadata as $vs_xmp_tag => $va_xmp_values) {
                     $va_metadata['XMP'][$vs_xmp_tag] = join('; ', $va_xmp_values);
                 }
             }
         }
         // try to get IPTC and DPX with GraphicsMagick, if available
         if (caMediaPluginGraphicsMagickInstalled()) {
             /* IPTC metadata */
             $vs_iptc_file = tempnam(caGetTempDirPath(), 'gmiptc');
             @rename($vs_iptc_file, $vs_iptc_file . '.iptc');
             // GM uses the file extension to figure out what we want
             $vs_iptc_file .= '.iptc';
             exec($this->ops_graphicsmagick_path . " convert " . caEscapeShellArg($ps_filepath) . " " . caEscapeShellArg($vs_iptc_file) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
             $vs_iptc_data = file_get_contents($vs_iptc_file);
             @unlink($vs_iptc_file);
             $va_iptc_raw = iptcparse($vs_iptc_data);
             $va_iptc_tags = array('2#004' => 'Genre', '2#005' => 'DocumentTitle', '2#010' => 'Urgency', '2#015' => 'Category', '2#020' => 'Subcategories', '2#025' => 'Keywords', '2#040' => 'SpecialInstructions', '2#055' => 'CreationDate', '2#060' => 'TimeCreated', '2#080' => 'AuthorByline', '2#085' => 'AuthorTitle', '2#090' => 'City', '2#095' => 'State', '2#100' => 'CountryCode', '2#101' => 'Country', '2#103' => 'OTR', '2#105' => 'Headline', '2#110' => 'Credit', '2#115' => 'PhotoSource', '2#116' => 'Copyright', '2#120' => 'Caption', '2#122' => 'CaptionWriter');
             $va_iptc = array();
             if (is_array($va_iptc_raw)) {
                 foreach ($va_iptc_raw as $vs_iptc_tag => $va_iptc_tag_data) {
                     if (isset($va_iptc_tags[$vs_iptc_tag])) {
                         $va_iptc[$va_iptc_tags[$vs_iptc_tag]] = join('; ', $va_iptc_tag_data);
                     }
                 }
             }
             if (sizeof($va_iptc)) {
                 $va_metadata['IPTC'] = $va_iptc;
             }
             /* DPX metadata */
             exec($this->ops_graphicsmagick_path . " identify -format '%[DPX:*]' " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
             if ($va_output[0]) {
                 $va_metadata['DPX'] = $va_output;
             }
         }
         $this->metadata = $va_metadata;
         return $handle;
     } catch (Exception $e) {
         $this->postError(1610, _t("Could not read image file"), "WLPlugGmagick->read()");
         return false;
         // gmagick couldn't read file, presumably
     }
 }
Пример #2
0
 public function read($filepath, $mimetype = "")
 {
     if ($mimetype == 'image/tilepic') {
         #
         # Read in Tilepic format image
         #
         $this->handle = new TilepicParser($filepath);
         $this->handle->useLibrary(LIBRARY_GD);
         if (!$this->handle->error) {
             $this->filepath = $filepath;
             foreach ($this->handle->properties as $k => $v) {
                 if (isset($this->properties[$k])) {
                     $this->properties[$k] = $v;
                 }
             }
             $this->properties["mimetype"] = "image/tilepic";
             $this->properties["typename"] = "Tilepic";
             return true;
         } else {
             $this->postError(1610, $this->handle->error, "WLPlugGD->read()");
             return false;
         }
     } else {
         $this->handle = "";
         $this->filepath = "";
         $this->metadata = array();
         $va_info = @getimagesize($filepath);
         switch ($va_info[2]) {
             case IMAGETYPE_GIF:
                 $this->handle = imagecreatefromgif($filepath);
                 $vs_mimetype = "image/gif";
                 $vs_typename = "GIF";
                 break;
             case IMAGETYPE_JPEG:
                 if (function_exists('exif_read_data') && !$this->opo_config->get('dont_use_exif_read_data')) {
                     $this->metadata["EXIF"] = $va_exif = caSanitizeArray(@exif_read_data($filepath, 'EXIF', true, false));
                     //
                     // Rotate incoming image as needed
                     //
                     if (is_array($va_exif)) {
                         if (isset($va_exif['IFD0']['Orientation'])) {
                             $vn_orientation = $va_exif['IFD0']['Orientation'];
                             switch ($vn_orientation) {
                                 case 3:
                                     $this->handle = imagecreatefromjpeg($filepath);
                                     $this->handle = $this->rotateImage($this->handle, -180);
                                     break;
                                 case 6:
                                     $this->handle = imagecreatefromjpeg($filepath);
                                     $this->handle = $this->rotateImage($this->handle, -90);
                                     $va_tmp = $va_info;
                                     $va_info[0] = $va_tmp[1];
                                     $va_info[1] = $va_tmp[0];
                                     break;
                                 case 8:
                                     $this->handle = imagecreatefromjpeg($filepath);
                                     $this->handle = $this->rotateImage($this->handle, 90);
                                     $va_tmp = $va_info;
                                     $va_info[0] = $va_tmp[1];
                                     $va_info[1] = $va_tmp[0];
                                     break;
                             }
                         }
                     }
                 }
                 if (!$this->handle) {
                     $this->handle = imagecreatefromjpeg($filepath);
                 }
                 $vs_mimetype = "image/jpeg";
                 $vs_typename = "JPEG";
                 $o_xmp = new XMPParser();
                 if ($o_xmp->parse($filepath)) {
                     if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
                         $va_metadata['XMP'] = $va_xmp_metadata;
                     }
                 }
                 break;
             case IMAGETYPE_PNG:
                 $this->handle = imagecreatefrompng($filepath);
                 $vs_mimetype = "image/png";
                 $vs_typename = "PNG";
                 break;
             default:
                 return false;
                 break;
         }
         if ($this->handle) {
             $this->filepath = $filepath;
             # load image properties
             $this->properties["width"] = $va_info[0];
             $this->properties["height"] = $va_info[1];
             $this->properties["mimetype"] = $vs_mimetype;
             $this->properties["typename"] = $vs_typename;
             $this->properties["filesize"] = @filesize($filepath);
             return true;
         } else {
             # plug-in can't handle format
             return false;
         }
     }
 }
Пример #3
0
/**
 * Removes from supplied array values that begin with binary (non-character) data. 
 * Arrays may be of any depth. 
 *
 * Note that function is of limited use outside of the case it was designed for: to remove binary entries from extracted EXIF metadata arrays.
 *
 * @param array $pa_array The array to sanitize
 * @param array $pa_options
 *        allowStdClass = stdClass object array values are allowed. This is useful for arrays that are about to be passed to json_encode [Default=false]
 *		  removeNonCharacterData = remove non-character data from all array value. This option leaves all character data in-place [Default=false]
 * @return array The sanitized array
 */
function caSanitizeArray($pa_array, $pa_options = null)
{
    if (!is_array($pa_array)) {
        return array();
    }
    $vb_allow_stdclass = caGetOption('allowStdClass', $pa_options, false);
    $vb_remove_noncharacter_data = caGetOption('removeNonCharacterData', $pa_options, false);
    foreach ($pa_array as $vn_k => $vm_v) {
        if (is_array($vm_v)) {
            $pa_array[$vn_k] = caSanitizeArray($vm_v, $pa_options);
        } else {
            if ($vb_allow_stdclass && is_object($vm_v) && get_class($vm_v) == 'stdClass') {
                continue;
            }
            if (!preg_match("!^\\X+\$!", $vm_v) || !mb_detect_encoding($vm_v)) {
                unset($pa_array[$vn_k]);
                continue;
            }
            if ($vb_remove_noncharacter_data) {
                $pa_array[$vn_k] = caSanitizeStringForJsonEncode($pa_array[$vn_k]);
            }
        }
    }
    return $pa_array;
}
 /**
  * Returns values for bundle. Can be used to set initial state of bundle as well as to grab partial value sets for
  * progressive loading of bundles.
  *
  * NOTE: Currently only support ca_object_representations bundle
  *
  */
 public function getBundleFormValues($ps_bundle_name, $ps_placement_code, $pa_bundle_settings, $pa_options = null)
 {
     global $g_ui_locale;
     // Check if user has access to this bundle
     if ($pa_options['request']->user->getBundleAccessLevel($this->tableName(), $ps_bundle_name) == __CA_BUNDLE_ACCESS_NONE__) {
         return;
     }
     // Check if user has access to this type
     if ((bool) $this->getAppConfig()->get('perform_type_access_checking')) {
         $vn_type_access = $pa_options['request']->user->getTypeAccessLevel($this->tableName(), $this->getTypeID());
         if ($vn_type_access == __CA_BUNDLE_ACCESS_NONE__) {
             return;
         }
         if ($vn_type_access == __CA_BUNDLE_ACCESS_READONLY__) {
             $pa_bundle_settings['readonly'] = true;
         }
     }
     // Check if user has access to this source
     if ((bool) $this->getAppConfig()->get('perform_source_access_checking')) {
         $vn_source_access = $pa_options['request']->user->getSourceAccessLevel($this->tableName(), $this->getSourceID());
         if ($vn_source_access == __CA_BUNDLE_ACCESS_NONE__) {
             return;
         }
         if ($vn_source_access == __CA_BUNDLE_ACCESS_READONLY__) {
             $pa_bundle_settings['readonly'] = true;
         }
     }
     if ((bool) $this->getAppConfig()->get('perform_item_level_access_checking') && $this->getPrimaryKey()) {
         $vn_item_access = $this->checkACLAccessForUser($pa_options['request']->user);
         if ($vn_item_access == __CA_ACL_NO_ACCESS__) {
             return;
         }
         if ($vn_item_access == __CA_ACL_READONLY_ACCESS__) {
             $pa_bundle_settings['readonly'] = true;
         }
     }
     $va_info = $this->getBundleInfo($ps_bundle_name);
     if (!($vs_type = $va_info['type'])) {
         return null;
     }
     if (isset($pa_options['config']) && is_object($pa_options['config'])) {
         $o_config = $pa_options['config'];
     } else {
         $o_config = $this->getAppConfig();
     }
     // start and count
     $pn_start = caGetOption('start', $pa_options, 0);
     $pn_limit = caGetOption('limit', $pa_options, null);
     $vs_element = '';
     switch ($vs_type) {
         # -------------------------------------------------
         case 'preferred_label':
         case 'nonpreferred_label':
             break;
             # -------------------------------------------------
         # -------------------------------------------------
         case 'intrinsic':
             break;
             # -------------------------------------------------
         # -------------------------------------------------
         case 'attribute':
             break;
             # -------------------------------------------------
         # -------------------------------------------------
         case 'related_table':
             switch ($ps_bundle_name) {
                 # -------------------------------
                 case 'ca_object_representations':
                     foreach (array('restrict_to_types', 'restrict_to_relationship_types') as $vs_k) {
                         $pa_options[$vs_k] = $pa_bundle_settings[$vs_k];
                     }
                     $va_reps = $this->getRepresentations(array('thumbnail', 'original'), null, $pa_options);
                     $t_item = new ca_object_representations();
                     $va_rep_type_list = $t_item->getTypeList();
                     $va_errors = array();
                     $vs_bundle_template = caGetOption('display_template', $pa_bundle_settings, null);
                     // Paging
                     $vn_primary_id = 0;
                     $va_initial_values = array();
                     if (sizeof($va_reps)) {
                         $o_type_config = Configuration::load($t_item->getAppConfig()->get('annotation_type_config'));
                         $va_annotation_type_mappings = $o_type_config->getAssoc('mappings');
                         // Get display template values
                         $va_display_template_values = array();
                         if ($vs_bundle_template && is_array($va_relation_ids = caExtractValuesFromArrayList($va_reps, 'relation_id')) && sizeof($va_relation_ids)) {
                             if ($vs_linking_table = RepresentableBaseModel::getRepresentationRelationshipTableName($this->tableName())) {
                                 $va_display_template_values = caProcessTemplateForIDs($vs_bundle_template, $vs_linking_table, $va_relation_ids, array_merge($pa_options, array('returnAsArray' => true, 'returnAllLocales' => false, 'includeBlankValuesInArray' => true)));
                             }
                         }
                         $vn_i = 0;
                         foreach ($va_reps as $va_rep) {
                             $vn_num_multifiles = $va_rep['num_multifiles'];
                             if ($vs_extracted_metadata = caFormatMediaMetadata(caSanitizeArray(caUnserializeForDatabase($va_rep['media_metadata'])))) {
                                 $vs_extracted_metadata = "<h3>" . _t('Extracted metadata') . ":</h3>\n{$vs_extracted_metadata}\n";
                             }
                             $vs_md5 = isset($va_rep['info']['original']['MD5']) ? "<h3>" . _t('MD5 signature') . ':</h3>' . $va_rep['info']['original']['MD5'] : '';
                             if ($va_rep['is_primary']) {
                                 $vn_primary_id = $va_rep['representation_id'];
                             }
                             $va_initial_values[$va_rep['representation_id']] = array('idno' => $va_rep['idno'], '_display' => $vs_bundle_template && isset($va_display_template_values[$vn_i]) ? $va_display_template_values[$vn_i] : '', 'status' => $va_rep['status'], 'status_display' => $t_item->getChoiceListValue('status', $va_rep['status']), 'access' => $va_rep['access'], 'access_display' => $t_item->getChoiceListValue('access', $va_rep['access']), 'rep_type_id' => $va_rep['type_id'], 'rep_type' => $t_item->getTypeName($va_rep['type_id']), 'rep_label' => $va_rep['label'], 'is_primary' => (int) $va_rep['is_primary'], 'is_primary_display' => $va_rep['is_primary'] == 1 ? _t('PRIMARY') : '', 'locale_id' => $va_rep['locale_id'], 'icon' => $va_rep['tags']['thumbnail'], 'mimetype' => $va_rep['info']['original']['PROPERTIES']['mimetype'], 'annotation_type' => isset($va_annotation_type_mappings[$va_rep['info']['original']['PROPERTIES']['mimetype']]) ? $va_annotation_type_mappings[$va_rep['info']['original']['PROPERTIES']['mimetype']] : null, 'type' => $va_rep['info']['original']['PROPERTIES']['typename'], 'dimensions' => $va_rep['dimensions']['original'], 'filename' => $va_rep['info']['original_filename'] ? $va_rep['info']['original_filename'] : _t('Unknown'), 'num_multifiles' => $vn_num_multifiles ? $vn_num_multifiles == 1 ? _t('+ 1 additional preview') : _t('+ %1 additional previews', $vn_num_multifiles) : '', 'metadata' => $vs_extracted_metadata, 'md5' => $vs_md5 ? "{$vs_md5}" : "", 'typename' => $va_rep_type_list[$va_rep['type_id']]['name_singular'], 'fetched_from' => $va_rep['fetched_from'], 'fetched_on' => date('c', $va_rep['fetched_on']), 'fetched' => $va_rep['fetched_from'] ? _t("<h3>Fetched from:</h3> URL %1 on %2", '<a href="' . $va_rep['fetched_from'] . '" target="_ext" title="' . $va_rep['fetched_from'] . '">' . $va_rep['fetched_from'] . '</a>', date('c', $va_rep['fetched_on'])) : "");
                             $vn_i++;
                         }
                     }
                     return $va_initial_values;
                     break;
                 case 'ca_entities':
                 case 'ca_places':
                 case 'ca_occurrences':
                 case 'ca_objects':
                 case 'ca_collections':
                 case 'ca_list_items':
                 case 'ca_storage_locations':
                 case 'ca_loans':
                 case 'ca_movements':
                 case 'ca_tour_stops':
                     return $this->getRelatedBundleFormValues($pa_options['request'], $pa_options['formName'], $ps_bundle_name, $ps_placement_code, $pa_bundle_settings, $pa_options);
                     break;
                     # -------------------------------
                 # -------------------------------
                 case 'ca_object_lots':
                     break;
                     # -------------------------------
                 # -------------------------------
                 case 'ca_representation_annotations':
                     break;
                     # -------------------------------
                 # -------------------------------
                 default:
                     return null;
                     break;
                     # -------------------------------
             }
             break;
     }
     return null;
 }
Пример #5
0
/**
 * Removes from supplied array values that begin with binary (non-character) data. 
 * Arrays may be of any depth. 
 *
 * Note that function is of limited use outside of the case it was designed for: to remove binary entries from extracted EXIF metadata arrays.
 *
 * @param array $pa_array The array to sanitize
 * @param array $pa_options
 *        allowStdClass = stdClass object array values are allowed. This is useful for arrays that are about to be passed to json_encode
 * @return array The sanitized array
 */
function caSanitizeArray($pa_array, $pa_options = null)
{
    if (!is_array($pa_array)) {
        return array();
    }
    $vb_allow_stdclass = caGetOption('allowStdClass', $pa_options, false);
    foreach ($pa_array as $vn_k => $vm_v) {
        if (is_array($vm_v)) {
            $pa_array[$vn_k] = caSanitizeArray($vm_v, $pa_options);
        } else {
            if ($vb_allow_stdclass && is_object($vm_v) && get_class($vm_v) == 'stdClass') {
                continue;
            }
            if (!preg_match("!^[ \\p{L}\\p{N}\\p{P}]+\$!", $vm_v) || !mb_detect_encoding($vm_v)) {
                unset($pa_array[$vn_k]);
            }
        }
    }
    return $pa_array;
}
Пример #6
0
 private function _graphicsMagickGetMetadata($ps_filepath)
 {
     $va_metadata = array();
     /* EXIF metadata */
     if (function_exists('exif_read_data') && !$this->opo_config->get('dont_use_exif_read_data')) {
         if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
             $va_metadata['EXIF'] = $va_exif;
         }
     }
     // if the builtin EXIF extraction is not used or failed for some reason, try ExifTool
     if (!isset($va_metadata['EXIF']) || !is_array($va_metadata['EXIF'])) {
         if (caExifToolInstalled()) {
             $va_metadata['EXIF'] = caExtractMetadataWithExifTool($ps_filepath, true);
         }
     }
     // else try GraphicsMagick
     if (!isset($va_metadata['EXIF']) || !is_array($va_metadata['EXIF'])) {
         exec($this->ops_graphicsmagick_path . ' identify -format "%[EXIF:*]" ' . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
         if (is_array($va_output) && sizeof($va_output) > 1) {
             foreach ($va_output as $vs_output_line) {
                 $va_tmp = explode('=', $vs_output_line);
                 // format is "Make=NIKON CORPORATION"
                 if (isset($va_tmp[0]) && isset($va_tmp[1])) {
                     $va_metadata['EXIF'][$va_tmp[0]] = $va_tmp[1];
                 }
             }
         }
         $va_output = array();
     }
     $o_xmp = new XMPParser();
     if ($o_xmp->parse($ps_filepath)) {
         if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
             $va_metadata['XMP'] = array();
             foreach ($va_xmp_metadata as $vs_xmp_tag => $va_xmp_values) {
                 $va_metadata['XMP'][$vs_xmp_tag] = join('; ', $va_xmp_values);
             }
         }
     }
     /* IPTC metadata */
     $vs_iptc_file = tempnam(caGetTempDirPath(), 'gmiptc');
     @rename($vs_iptc_file, $vs_iptc_file . '.iptc');
     // GM uses the file extension to figure out what we want
     $vs_iptc_file .= '.iptc';
     exec($this->ops_graphicsmagick_path . " convert " . caEscapeShellArg($ps_filepath) . " " . caEscapeShellArg($vs_iptc_file) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
     $vs_iptc_data = file_get_contents($vs_iptc_file);
     @unlink($vs_iptc_file);
     $va_iptc_raw = iptcparse($vs_iptc_data);
     $va_iptc_tags = array('2#004' => 'Genre', '2#005' => 'DocumentTitle', '2#010' => 'Urgency', '2#015' => 'Category', '2#020' => 'Subcategories', '2#025' => 'Keywords', '2#040' => 'SpecialInstructions', '2#055' => 'CreationDate', '2#060' => 'TimeCreated', '2#080' => 'AuthorByline', '2#085' => 'AuthorTitle', '2#090' => 'City', '2#095' => 'State', '2#100' => 'CountryCode', '2#101' => 'Country', '2#103' => 'OTR', '2#105' => 'Headline', '2#110' => 'Credit', '2#115' => 'PhotoSource', '2#116' => 'Copyright', '2#120' => 'Caption', '2#122' => 'CaptionWriter');
     $va_iptc = array();
     if (is_array($va_iptc_raw)) {
         foreach ($va_iptc_raw as $vs_iptc_tag => $va_iptc_tag_data) {
             if (isset($va_iptc_tags[$vs_iptc_tag])) {
                 $va_iptc[$va_iptc_tags[$vs_iptc_tag]] = join('; ', $va_iptc_tag_data);
             }
         }
     }
     if (sizeof($va_iptc)) {
         $va_metadata['IPTC'] = $va_iptc;
     }
     /* DPX metadata */
     exec($this->ops_graphicsmagick_path . " identify -format '%[DPX:*]' " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
     if ($va_output[0]) {
         $va_metadata['DPX'] = $va_output;
     }
     return $va_metadata;
 }
Пример #7
0
 public function read($ps_filepath, $mimetype = "")
 {
     if (!($this->handle && ${$ps_filepath} === $this->filepath)) {
         if ($mimetype == 'image/tilepic') {
             #
             # Read in Tilepic format image
             #
             $this->handle = new TilepicParser($ps_filepath);
             if (!$this->handle->error) {
                 $this->filepath = $ps_filepath;
                 foreach ($this->handle->properties as $k => $v) {
                     if (isset($this->properties[$k])) {
                         $this->properties[$k] = $v;
                     }
                 }
                 $this->properties["mimetype"] = "image/tilepic";
                 $this->properties["typename"] = "Tilepic";
                 return 1;
             } else {
                 $this->postError(1610, $this->handle->error, "WLPlugImagick->read()");
                 return false;
             }
         } else {
             $this->handle = "";
             $this->filepath = "";
             $handle = new Imagick();
             if ($mimetype == 'image/x-dcraw') {
                 if ($this->filepath_conv) {
                     @unlink($this->filepath_conv);
                 }
                 if (!caMediaPluginDcrawInstalled($this->ops_dcraw_path)) {
                     $this->postError(1610, _t("Could not convert Camera RAW format file because conversion tool (dcraw) is not installed"), "WLPlugImagick->read()");
                     return false;
                 }
                 $vs_tmp_name = tempnam(caGetTempDirPath(), "rawtmp");
                 if (!copy($ps_filepath, $vs_tmp_name)) {
                     $this->postError(1610, _t("Could not copy Camera RAW file to temporary directory"), "WLPlugImagick->read()");
                     return false;
                 }
                 exec($this->ops_dcraw_path . " -T " . caEscapeShellArg($vs_tmp_name), $va_output, $vn_return);
                 if ($vn_return != 0) {
                     $this->postError(1610, _t("Camera RAW file conversion failed: %1", $vn_return), "WLPlugImagick->read()");
                     return false;
                 }
                 if (!(file_exists($vs_tmp_name . '.tiff') && filesize($vs_tmp_name . '.tiff') > 0)) {
                     $this->postError(1610, _t("Translation from Camera RAW to TIFF failed"), "WLPlugImagick->read()");
                     return false;
                 }
                 $ps_filepath = $this->filepath_conv = $vs_tmp_name . '.tiff';
                 @unlink($vs_tmp_name);
             }
             if ($handle->readImage($ps_filepath)) {
                 $this->handle = $handle;
                 $this->filepath = $ps_filepath;
                 $va_raw_metadata = $this->handle->getImageProperties();
                 $this->metadata = array();
                 foreach ($va_raw_metadata as $vs_tag => $vs_value) {
                     if (sizeof($va_tmp = explode(':', $vs_tag)) > 1) {
                         $vs_type = strtoupper($va_tmp[0]);
                         $vs_tag = $va_tmp[1];
                     } else {
                         $vs_type = 'GENERIC';
                     }
                     if ($vs_type == 'EXIF') {
                         continue;
                     }
                     $this->metadata[$vs_type][$vs_tag] = $vs_value;
                 }
                 // exif
                 if (function_exists('exif_read_data')) {
                     if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
                         //
                         // Rotate incoming image as needed
                         //
                         if (isset($va_exif['IFD0']['Orientation'])) {
                             $vn_orientation = $va_exif['IFD0']['Orientation'];
                             $vs_tmp_basename = tempnam(caGetTempDirPath(), 'ca_image_tmp');
                             $vb_is_rotated = false;
                             switch ($vn_orientation) {
                                 case 3:
                                     $this->handle->rotateImage("#FFFFFF", 180);
                                     unset($va_exif['IFD0']['Orientation']);
                                     $vb_is_rotated = true;
                                     break;
                                 case 6:
                                     $this->handle->rotateImage("#FFFFFF", 90);
                                     unset($va_exif['IFD0']['Orientation']);
                                     $vb_is_rotated = true;
                                     break;
                                 case 8:
                                     $this->handle->rotateImage("#FFFFFF", -90);
                                     unset($va_exif['IFD0']['Orientation']);
                                     $vb_is_rotated = true;
                                     break;
                             }
                             if ($vb_is_rotated) {
                                 if ($this->handle->writeImage($vs_tmp_basename)) {
                                     $va_tmp = $this->handle->getImageGeometry();
                                     $this->properties["faces"] = $this->opa_faces = caDetectFaces($vs_tmp_basename, $va_tmp['width'], $va_tmp['height']);
                                 }
                                 @unlink($vs_tmp_basename);
                             }
                         }
                         $this->metadata['EXIF'] = $va_exif;
                     }
                 }
                 // XMP
                 $o_xmp = new XMPParser();
                 if ($o_xmp->parse($ps_filepath)) {
                     if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
                         $this->metadata['XMP'] = $va_xmp_metadata;
                     }
                 }
                 # load image properties
                 $va_tmp = $this->handle->getImageGeometry();
                 $this->properties["width"] = $va_tmp['width'];
                 $this->properties["height"] = $va_tmp['height'];
                 $this->properties["quality"] = "";
                 $this->properties["filesize"] = $this->handle->getImageLength();
                 $this->properties["bitdepth"] = $this->handle->getImageDepth();
                 $this->properties["resolution"] = $this->handle->getImageResolution();
                 $this->properties["colorspace"] = $this->_getColorspaceAsString($this->handle->getImageColorspace());
                 // force all images to true color (takes care of GIF transparency for one thing...)
                 $this->handle->setImageType(imagick::IMGTYPE_TRUECOLOR);
                 if (!$this->handle->setImageColorspace(imagick::COLORSPACE_RGB)) {
                     $this->postError(1610, _t("Error during RGB colorspace transformation operation"), "WLPlugImagick->read()");
                     return false;
                 }
                 if (!$this->properties["faces"]) {
                     $this->properties["faces"] = $this->opa_faces = caDetectFaces($ps_filepath, $va_tmp['width'], $va_tmp['height']);
                 }
                 $this->properties["mimetype"] = $this->_getMagickImageMimeType($this->handle);
                 $this->properties["typename"] = $this->handle->getImageFormat();
                 $this->ohandle = $this->handle->clone();
                 return 1;
             } else {
                 $this->postError(1610, _t("Could not read image file"), "WLPlugImagick->read()");
                 return false;
             }
         }
     } else {
         # image already loaded by previous call (probably divineFileFormat())
         return 1;
     }
 }
Пример #8
0
 private function _CoreImageGetMetadata($ps_filepath)
 {
     if (caMediaPluginCoreImageInstalled($this->ops_CoreImage_path)) {
         $va_metadata = array();
         if (function_exists('exif_read_data')) {
             if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
                 $va_metadata['EXIF'] = $va_exif;
             }
         }
         $o_xmp = new XMPParser();
         if ($o_xmp->parse($ps_filepath)) {
             if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
                 $va_metadata['XMP'] = $va_xmp_metadata;
             }
         }
         return $va_metadata;
     }
     return null;
 }
Пример #9
0
 private function _graphicsMagickGetMetadata($ps_filepath)
 {
     $va_metadata = array();
     /* EXIF metadata */
     if (function_exists('exif_read_data')) {
         if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
             $va_metadata['EXIF'] = $va_exif;
         }
     }
     $o_xmp = new XMPParser();
     if ($o_xmp->parse($ps_filepath)) {
         if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
             $va_metadata['XMP'] = array();
             foreach ($va_xmp_metadata as $vs_xmp_tag => $va_xmp_values) {
                 $va_metadata['XMP'][$vs_xmp_tag] = join('; ', $va_xmp_values);
             }
         }
     }
     /* IPTC metadata */
     $vs_iptc_file = tempnam(caGetTempDirPath(), 'gmiptc');
     @rename($vs_iptc_file, $vs_iptc_file . '.iptc');
     // GM uses the file extension to figure out what we want
     $vs_iptc_file .= '.iptc';
     exec($this->ops_graphicsmagick_path . " convert " . caEscapeShellArg($ps_filepath) . " " . caEscapeShellArg($vs_iptc_file), $va_output, $vn_return);
     $vs_iptc_data = file_get_contents($vs_iptc_file);
     @unlink($vs_iptc_file);
     $va_iptc_raw = iptcparse($vs_iptc_data);
     $va_iptc_tags = array('2#004' => 'Genre', '2#005' => 'DocumentTitle', '2#010' => 'Urgency', '2#015' => 'Category', '2#020' => 'Subcategories', '2#025' => 'Keywords', '2#040' => 'SpecialInstructions', '2#055' => 'CreationDate', '2#060' => 'TimeCreated', '2#080' => 'AuthorByline', '2#085' => 'AuthorTitle', '2#090' => 'City', '2#095' => 'State', '2#100' => 'CountryCode', '2#101' => 'Country', '2#103' => 'OTR', '2#105' => 'Headline', '2#110' => 'Credit', '2#115' => 'PhotoSource', '2#116' => 'Copyright', '2#120' => 'Caption', '2#122' => 'CaptionWriter');
     $va_iptc = array();
     if (is_array($va_iptc_raw)) {
         foreach ($va_iptc_raw as $vs_iptc_tag => $va_iptc_tag_data) {
             if (isset($va_iptc_tags[$vs_iptc_tag])) {
                 $va_iptc[$va_iptc_tags[$vs_iptc_tag]] = join('; ', $va_iptc_tag_data);
             }
         }
     }
     if (sizeof($va_iptc)) {
         $va_metadata['IPTC'] = $va_iptc;
     }
     /* DPX metadata */
     exec($this->ops_graphicsmagick_path . " identify -format '%[DPX:*]' " . caEscapeShellArg($ps_filepath), $va_output, $vn_return);
     if ($va_output[0]) {
         $va_metadata['DPX'] = $va_output;
     }
     return $va_metadata;
 }
Пример #10
0
 * ----------------------------------------------------------------------
 * CollectiveAccess
 * Open-source collections management software
 * ----------------------------------------------------------------------
 *
 * Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
 * Copyright 2014 Whirl-i-Gig
 *
 * For more information visit http://www.CollectiveAccess.org
 *
 * This program is free software; you may redistribute it and/or modify it under
 * the terms of the provided license as published by Whirl-i-Gig
 *
 * CollectiveAccess is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTIES whatsoever, including any implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * This source code is free and modifiable under the terms of
 * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
 * the "license.txt" file for details, or visit the CollectiveAccess web site at
 * http://www.CollectiveAccess.org
 *
 * ----------------------------------------------------------------------
 */
header('Content-type: application/json');
$va_return = array("ok" => true) + caSanitizeArray($this->getVar('content'), array('allowStdClass' => true));
if ($this->getVar('pretty_print')) {
    print caFormatJson(json_encode($va_return));
} else {
    print json_encode($va_return);
}
Пример #11
0
/**
 * Removes from supplied array values that begin with binary (non-character) data. 
 * Arrays may be of any depth. 
 *
 * Note that function is of limited use outside of the case it was designed for: to remove binary entries from extracted EXIF metadata arrays.
 *
 * @param array $pa_array The array to sanitize
 * @param array $pa_options No options are currently supported
 * @return array The sanitized array
 */
function caSanitizeArray($pa_array, $pa_options = null)
{
    if (!is_array($pa_array)) {
        return array();
    }
    foreach ($pa_array as $vn_k => $vm_v) {
        if (is_array($vm_v)) {
            $pa_array[$vn_k] = caSanitizeArray($vm_v);
        } else {
            if (!preg_match("!^[\\p{L}\\p{N}\\p{P}]+!", $vm_v) || !mb_detect_encoding($vm_v)) {
                unset($pa_array[$vn_k]);
            }
        }
    }
    return $pa_array;
}
Пример #12
0
 private function _imageMagickGetMetadata($ps_filepath)
 {
     if (caMediaPluginImageMagickInstalled($this->ops_imagemagick_path)) {
         $va_metadata = array();
         if (function_exists('exif_read_data')) {
             if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
                 $va_metadata['EXIF'] = $va_exif;
             }
         }
         $o_xmp = new XMPParser();
         if ($o_xmp->parse($ps_filepath)) {
             if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
                 $va_metadata['XMP'] = $va_xmp_metadata;
             }
         }
         exec($this->ops_imagemagick_path . "/identify -format '%[DPX:*]' " . caEscapeShellArg($ps_filepath), $va_output, $vn_return);
         if ($va_output[0]) {
             $va_metadata['DPX'] = $va_output;
         }
         $va_iptc_tags = array('credit' => '2:110', 'byline' => '2:080', 'date_created' => '2:055', 'time_created' => '2:060', 'caption' => '2:120', 'copyright' => '2:116', 'title' => '2:005', 'genre' => '2:004', 'urgency' => '2:010', 'category' => '2:015', 'supplemental category' => '2:020', 'keywords' => '2:025', 'special_instructions' => '2:040', 'byline' => '2:080', 'bylinetitle' => '2:085', 'city' => '2:090', 'location' => '2:092', 'province' => '2:095', 'countrycode' => '2:100', 'countryname' => '2:101', 'headline' => '2:105', 'credit' => '2:110', 'source' => '2:115', 'description writer' => '2:122');
         $va_iptc = array();
         foreach ($va_iptc_tags as $vs_tag_name => $vs_tag_code) {
             $va_output = array();
             exec($this->ops_imagemagick_path . "/identify -format '%[IPTC:" . $vs_tag_code . "]' " . caEscapeShellArg($ps_filepath), $va_output, $vn_return);
             if ($va_output[0]) {
                 $va_iptc[str_replace(":", ",", $vs_tag_code) . ' [' . $vs_tag_name . ']'] = $va_output[0];
             }
         }
         if (sizeof($va_iptc)) {
             $va_metadata['IPTC'] = $va_iptc;
         }
         return $va_metadata;
     }
     return null;
 }
Пример #13
0
 private function _graphicsMagickGetMetadata($ps_filepath)
 {
     $va_metadata = array();
     if (function_exists('exif_read_data')) {
         if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
             $va_metadata['EXIF'] = $va_exif;
         }
     }
     $o_xmp = new XMPParser();
     if ($o_xmp->parse($ps_filepath)) {
         if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
             $va_metadata['XMP'] = $va_xmp_metadata;
         }
     }
     // GM doesn't seem to support DPX or IPTC metadata extraction :-(
     return $va_metadata;
 }
Пример #14
0
 private function _CoreImageGetMetadata($ps_filepath)
 {
     if (caMediaPluginCoreImageInstalled($this->ops_CoreImage_path)) {
         $va_metadata = array();
         if (function_exists('exif_read_data') && !$this->opo_config->get('dont_use_exif_read_data')) {
             if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
                 $va_metadata['EXIF'] = $va_exif;
             }
         }
         // if the builtin EXIF extraction is not used or failed for some reason, try ExifTool
         if (!isset($va_metadata['EXIF']) || !is_array($va_metadata['EXIF'])) {
             if (caExifToolInstalled()) {
                 $va_metadata['EXIF'] = caExtractMetadataWithExifTool($ps_filepath, true);
             }
         }
         $o_xmp = new XMPParser();
         if ($o_xmp->parse($ps_filepath)) {
             if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
                 $va_metadata['XMP'] = $va_xmp_metadata;
             }
         }
         return $va_metadata;
     }
     return null;
 }
Пример #15
0
 public function GetDirectoryLevel()
 {
     $ps_id = $this->request->getParameter('id', pString);
     $pn_max = $this->request->getParameter('max', pString);
     $vs_root_directory = $this->request->config->get('batch_media_import_root_directory');
     $va_level_data = array();
     if ($this->request->getParameter('init', pInteger)) {
         //
         // On first load (init) of browser load all levels in single request
         //
         $va_tmp = explode(";", $ps_id);
         $va_acc = array();
         $vn_i = 0;
         foreach ($va_tmp as $vs_tmp) {
             list($vs_directory, $vn_start) = explode(":", $vs_tmp);
             if (!$vs_directory) {
                 continue;
             }
             $va_tmp = explode('/', $vs_directory);
             $vs_k = array_pop($va_tmp);
             if (!$vs_k) {
                 $vs_k = '/';
             }
             $va_level_data["{$vs_k}|{$vn_i}"] = $va_file_list = $this->_getDirectoryListing($vs_root_directory . '/' . $vs_directory, false, 20, (int) $vn_start, (int) $pn_max);
             $va_level_data["{$vs_k}|{$vn_i}"]['_primaryKey'] = 'name';
             $va_counts = caGetDirectoryContentsCount($vs_root_directory . '/' . $vs_directory, false, false);
             $va_level_data["{$vs_k}|{$vn_i}"]['_itemCount'] = $va_counts['files'] + $va_counts['directories'];
             $vn_i++;
         }
     } else {
         list($ps_directory, $pn_start) = explode(":", $ps_id);
         $va_tmp = explode('/', $ps_directory);
         $vn_level = sizeof($va_tmp);
         if ($ps_directory[0] == '/') {
             $vn_level--;
         }
         if (!$ps_directory) {
             $va_level_data["{$vs_k}|{$vn_level}"] = array('/' => array('item_id' => '/', 'name' => 'Root', 'type' => 'DIR', 'children' => 1));
             $va_level_data["{$vs_k}|{$vn_level}"]['_primaryKey'] = 'name';
             $va_level_data["{$vs_k}|{$vn_level}"]['_itemCount'] = 1;
         } else {
             $va_tmp = explode('/', $ps_directory);
             $vs_k = array_pop($va_tmp);
             if (!$vs_k) {
                 $vs_k = '/';
             }
             $va_level_data["{$vs_k}|{$vn_level}"] = $va_file_list = $this->_getDirectoryListing($vs_root_directory . '/' . $ps_directory, false, 20, (int) $pn_start, (int) $pn_max);
             $va_level_data["{$vs_k}|{$vn_level}"]['_primaryKey'] = 'name';
             $va_counts = caGetDirectoryContentsCount($vs_root_directory . '/' . $ps_directory, false, false);
             $va_level_data["{$vs_k}|{$vn_level}"]['_itemCount'] = $va_counts['files'] + $va_counts['directories'];
         }
     }
     $this->view->setVar('directory_list', caSanitizeArray($va_level_data));
     $this->render('mediaimport/directory_level_json.php');
 }