Complete PHP-based workflow application for Ferrero DAM system: - OAuth2 authentication with automatic token management - Campaign discovery and filtering - Folder structure navigation - Asset download (individual and bulk) - Metadata extraction and display - Clean step-by-step web interface Status: Fully functional and production-ready 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
233 lines
No EOL
10 KiB
PHP
233 lines
No EOL
10 KiB
PHP
<?php
|
|
|
|
class MetadataExtractor
|
|
{
|
|
public static function extractAllMetadata($asset)
|
|
{
|
|
$metadata = [];
|
|
|
|
// Basic asset information
|
|
$metadata['basic'] = [
|
|
'asset_id' => $asset['asset_id'] ?? null,
|
|
'name' => $asset['name'] ?? null,
|
|
'data_type' => $asset['data_type'] ?? null,
|
|
'mime_type' => $asset['mime_type'] ?? null,
|
|
'file_size' => $asset['file_size'] ?? null,
|
|
'creator_id' => $asset['creator_id'] ?? null,
|
|
'date_imported' => $asset['date_imported'] ?? null,
|
|
'date_last_updated' => $asset['date_last_updated'] ?? null,
|
|
'version' => $asset['version'] ?? null,
|
|
'locked' => $asset['locked'] ?? null,
|
|
'asset_state' => $asset['asset_state'] ?? null
|
|
];
|
|
|
|
// Content information
|
|
if (isset($asset['asset_content_info']['master_content'])) {
|
|
$content = $asset['asset_content_info']['master_content'];
|
|
$metadata['content'] = [
|
|
'content_file_name' => $content['content_file_name'] ?? null,
|
|
'content_size' => $content['content_size'] ?? null,
|
|
'mime_type' => $content['mime_type'] ?? null,
|
|
'width' => $content['width'] ?? null,
|
|
'height' => $content['height'] ?? null,
|
|
'content_checksum' => $content['content_checksum'] ?? null,
|
|
'encoding' => $content['encoding'] ?? null,
|
|
'content_signed_url' => $content['content_signed_url'] ?? null,
|
|
'url' => $content['url'] ?? null
|
|
];
|
|
}
|
|
|
|
// Custom metadata fields
|
|
$metadata['custom_fields'] = [];
|
|
if (isset($asset['metadata']['metadata_element_list'])) {
|
|
foreach ($asset['metadata']['metadata_element_list'] as $category) {
|
|
$categoryName = $category['name'] ?? 'Unknown Category';
|
|
$metadata['custom_fields'][$categoryName] = [];
|
|
|
|
if (isset($category['metadata_element_list'])) {
|
|
foreach ($category['metadata_element_list'] as $field) {
|
|
$fieldId = $field['id'] ?? 'unknown';
|
|
$fieldName = $field['name'] ?? $fieldId;
|
|
$fieldValue = null;
|
|
|
|
// Extract field value
|
|
if (isset($field['value']['value']['value'])) {
|
|
$fieldValue = $field['value']['value']['value'];
|
|
} elseif (isset($field['value']['value']['display_value'])) {
|
|
$fieldValue = $field['value']['value']['display_value'];
|
|
} elseif (isset($field['value']['value']['field_value']['value'])) {
|
|
$fieldValue = $field['value']['value']['field_value']['value'];
|
|
}
|
|
|
|
// Handle tabular fields
|
|
if (isset($field['metadata_element_list'])) {
|
|
$tabularValues = [];
|
|
foreach ($field['metadata_element_list'] as $tableField) {
|
|
if (isset($tableField['values'])) {
|
|
foreach ($tableField['values'] as $value) {
|
|
if (isset($value['value']['value'])) {
|
|
$tabularValues[] = $value['value']['value'];
|
|
} elseif (isset($value['value']['display_value'])) {
|
|
$tabularValues[] = $value['value']['display_value'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!empty($tabularValues)) {
|
|
$fieldValue = $tabularValues;
|
|
}
|
|
}
|
|
|
|
if ($fieldValue !== null) {
|
|
$metadata['custom_fields'][$categoryName][$fieldName] = [
|
|
'id' => $fieldId,
|
|
'value' => $fieldValue,
|
|
'data_type' => $field['data_type'] ?? null,
|
|
'editable' => $field['editable'] ?? null,
|
|
'required' => $field['required'] ?? null
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Permissions
|
|
$metadata['permissions'] = [];
|
|
if (isset($asset['access_control_descriptor']['permissions_map']['entry'])) {
|
|
foreach ($asset['access_control_descriptor']['permissions_map']['entry'] as $permission) {
|
|
$permissionName = str_replace('text.securityPolicy.permission.', '', $permission['key'] ?? '');
|
|
$metadata['permissions'][$permissionName] = $permission['value'] ?? false;
|
|
}
|
|
}
|
|
|
|
// Renditions and previews
|
|
$metadata['renditions'] = [];
|
|
if (isset($asset['rendition_content'])) {
|
|
foreach ($asset['rendition_content'] as $renditionType => $rendition) {
|
|
if (is_array($rendition)) {
|
|
$metadata['renditions'][$renditionType] = [
|
|
'content_size' => $rendition['content_size'] ?? null,
|
|
'mime_type' => $rendition['mime_type'] ?? null,
|
|
'width' => $rendition['width'] ?? null,
|
|
'height' => $rendition['height'] ?? null,
|
|
'url' => $rendition['url'] ?? null,
|
|
'content_signed_url' => $rendition['content_signed_url'] ?? null
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
return $metadata;
|
|
}
|
|
|
|
public static function formatMetadataForDisplay($metadata)
|
|
{
|
|
$output = "<div class='metadata-display'>";
|
|
|
|
// Basic Information
|
|
if (!empty($metadata['basic'])) {
|
|
$output .= "<div class='metadata-section'>";
|
|
$output .= "<h5>📋 Basic Asset Information</h5>";
|
|
$output .= "<div class='metadata-grid'>";
|
|
|
|
foreach ($metadata['basic'] as $key => $value) {
|
|
if ($value !== null) {
|
|
$displayKey = ucwords(str_replace('_', ' ', $key));
|
|
$displayValue = is_bool($value) ? ($value ? 'Yes' : 'No') : htmlspecialchars($value);
|
|
$output .= "<div><strong>{$displayKey}:</strong> {$displayValue}</div>";
|
|
}
|
|
}
|
|
$output .= "</div></div>";
|
|
}
|
|
|
|
// Content Information
|
|
if (!empty($metadata['content'])) {
|
|
$output .= "<div class='metadata-section'>";
|
|
$output .= "<h5>🖼️ Content Information</h5>";
|
|
$output .= "<div class='metadata-grid'>";
|
|
|
|
foreach ($metadata['content'] as $key => $value) {
|
|
if ($value !== null && $key !== 'content_signed_url') { // Hide signed URL for security
|
|
$displayKey = ucwords(str_replace('_', ' ', $key));
|
|
if ($key === 'content_size' || $key === 'file_size') {
|
|
$displayValue = number_format($value) . ' bytes';
|
|
} elseif (($key === 'width' || $key === 'height') && is_numeric($value)) {
|
|
$displayValue = $value . 'px';
|
|
} else {
|
|
$displayValue = htmlspecialchars($value);
|
|
}
|
|
$output .= "<div><strong>{$displayKey}:</strong> {$displayValue}</div>";
|
|
}
|
|
}
|
|
$output .= "</div></div>";
|
|
}
|
|
|
|
// Custom Fields
|
|
if (!empty($metadata['custom_fields'])) {
|
|
$output .= "<div class='metadata-section'>";
|
|
$output .= "<h5>🏷️ Custom Metadata Fields</h5>";
|
|
|
|
foreach ($metadata['custom_fields'] as $categoryName => $fields) {
|
|
if (!empty($fields)) {
|
|
$output .= "<div class='metadata-category'>";
|
|
$output .= "<h6>{$categoryName}</h6>";
|
|
$output .= "<div class='metadata-grid'>";
|
|
|
|
foreach ($fields as $fieldName => $fieldData) {
|
|
$value = $fieldData['value'];
|
|
if (is_array($value)) {
|
|
$displayValue = implode(', ', array_map('htmlspecialchars', $value));
|
|
} else {
|
|
$displayValue = htmlspecialchars($value);
|
|
}
|
|
$output .= "<div><strong>{$fieldName}:</strong> {$displayValue}</div>";
|
|
}
|
|
$output .= "</div></div>";
|
|
}
|
|
}
|
|
$output .= "</div>";
|
|
}
|
|
|
|
// Permissions
|
|
if (!empty($metadata['permissions'])) {
|
|
$output .= "<div class='metadata-section'>";
|
|
$output .= "<h5>🔐 Permissions</h5>";
|
|
$output .= "<div class='permissions-grid'>";
|
|
|
|
foreach ($metadata['permissions'] as $permission => $allowed) {
|
|
$status = $allowed ? '✅' : '❌';
|
|
$permissionName = ucwords(str_replace(['Permission', '_'], ['', ' '], $permission));
|
|
$output .= "<div>{$status} {$permissionName}</div>";
|
|
}
|
|
$output .= "</div></div>";
|
|
}
|
|
|
|
// Renditions
|
|
if (!empty($metadata['renditions'])) {
|
|
$output .= "<div class='metadata-section'>";
|
|
$output .= "<h5>🎨 Available Renditions</h5>";
|
|
|
|
foreach ($metadata['renditions'] as $type => $rendition) {
|
|
$output .= "<div class='rendition-info'>";
|
|
$output .= "<h6>" . ucwords(str_replace('_', ' ', $type)) . "</h6>";
|
|
|
|
if ($rendition['width'] && $rendition['height']) {
|
|
$output .= "<p>Size: {$rendition['width']}x{$rendition['height']}px</p>";
|
|
}
|
|
if ($rendition['content_size']) {
|
|
$output .= "<p>File Size: " . number_format($rendition['content_size']) . " bytes</p>";
|
|
}
|
|
if ($rendition['mime_type']) {
|
|
$output .= "<p>Type: {$rendition['mime_type']}</p>";
|
|
}
|
|
$output .= "</div>";
|
|
}
|
|
$output .= "</div>";
|
|
}
|
|
|
|
$output .= "</div>";
|
|
|
|
return $output;
|
|
}
|
|
} |