@@ -118,21 +118,43 @@ public function extractExif($actionName, $httpVars, $fileVars)
118
118
$ exifData ["IPTC " ] = $ iptc ;
119
119
}
120
120
$ 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 ();
122
126
foreach ($ exifData as $ section => $ data ) {
123
- print ( " <exifSection name=' $ section'> " );
127
+ $ filteredData [ $ section] = array ( );
124
128
foreach ($ data as $ key => $ value ) {
125
129
if (is_array ($ value )) {
126
130
$ value = implode (", " , $ value );
127
131
}
128
132
if (in_array (strtolower ($ key ), $ excludeTags )) continue ;
129
133
if (strpos ($ key , "UndefinedTag: " ) === 0 ) continue ;
130
134
$ 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> " );
132
148
}
133
- print ("</exifSection> " );
149
+ AJXP_XMLWriter::close ("metadata " );
150
+
151
+ }else {
152
+
153
+ HTMLWriter::charsetHeader ("application/json " );
154
+ echo json_encode ($ filteredData );
155
+
134
156
}
135
- AJXP_XMLWriter:: close ( " metadata " );
157
+
136
158
}
137
159
138
160
public function string_format ($ str )
0 commit comments