Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit bda9c41

Browse files
committed
Fix EXIF extractor output for XML, and add a format parameter to ask for JSON instead.
1 parent b250645 commit bda9c41

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

core/src/plugins/meta.exif/class.ExifMetaManager.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,43 @@ public function extractExif($actionName, $httpVars, $fileVars)
118118
$exifData["IPTC"] = $iptc;
119119
}
120120
$excludeTags = array();// array("componentsconfiguration", "filesource", "scenetype", "makernote", "datadump");
121-
AJXP_XMLWriter::header("metadata", array("file" => $selectedNode->getPath(), "type" => "EXIF"));
121+
$format = "xml";
122+
if(isSet($httpVars["format"]) && $httpVars["format"] == "json"){
123+
$format = "json";
124+
}
125+
$filteredData = array();
122126
foreach ($exifData as $section => $data) {
123-
print("<exifSection name='$section'>");
127+
$filteredData[$section] = array();
124128
foreach ($data as $key => $value) {
125129
if (is_array($value)) {
126130
$value = implode(",", $value);
127131
}
128132
if(in_array(strtolower($key), $excludeTags)) continue;
129133
if(strpos($key, "UndefinedTag:") === 0) continue;
130134
$value = preg_replace( '/[^[:print:]]/', '',$value);
131-
print("<exifTag name=\"$key\">".SystemTextEncoding::toUTF8($value)."</exifTag>");
135+
$filteredData[$section][$key] = SystemTextEncoding::toUTF8($value);
136+
}
137+
}
138+
139+
if($format == "xml"){
140+
141+
AJXP_XMLWriter::header("metadata", array("file" => $selectedNode->getPath(), "type" => "EXIF"));
142+
foreach ($filteredData as $section => $data) {
143+
print("<exifSection name='$section'>");
144+
foreach ($data as $key => $value) {
145+
print("<exifTag name=\"$key\">". AJXP_Utils::xmlEntities($value)."</exifTag>");
146+
}
147+
print("</exifSection>");
132148
}
133-
print("</exifSection>");
149+
AJXP_XMLWriter::close("metadata");
150+
151+
}else{
152+
153+
HTMLWriter::charsetHeader("application/json");
154+
echo json_encode($filteredData);
155+
134156
}
135-
AJXP_XMLWriter::close("metadata");
157+
136158
}
137159

138160
public function string_format($str)

core/src/plugins/meta.exif/manifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
<actions>
2626
<action name="extract_exif">
2727
<processing>
28-
<serverCallback methodName="extractExif" restParams="/file+" developerComment="Extract all exif data from a compatible image (JPG).">
28+
<serverCallback methodName="extractExif" restParams="/format/file+" developerComment="Extract all exif data from a compatible image (JPG).">
2929
<input_param name="file" type="path" description="Path to the file to analyze"/>
30+
<input_param name="format" type="string" description="json|xml: Get json instead of xml (default)"/>
3031
<output type="XML" description="An XML structure containing all Exif tags"/>
3132
</serverCallback>
3233
</processing>

0 commit comments

Comments
 (0)