forked from evanhunter/PJMT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEdit_File_Info.php
575 lines (497 loc) · 30 KB
/
Edit_File_Info.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<?php
/****************************************************************************
*
* Filename: Edit_File_Info.php
*
* Description: Allows the user to edit the metadata of an image over the internet
* in the same way that Photoshop edits 'File Info' data
* This file provides only the html for a form containing the file info
* input fields. The rest of the html file must be provided by the calling script.
* $outputfilename must always be defined - it is ne name of the file which
* have the metadata changed after the form has been submitted
*
* This file has several modes of operation:
*
* 1) If $new_ps_file_info_array is defined then it's data will be used
* to fill the fields.
* 2) If $new_ps_file_info_array is not defined but $filename is defined,
* then the file info fields will be filled from the metadata in the file specified
* 3) If $new_ps_file_info_array is not defined but $filename and $default_ps_file_info_array
* are defined, then the file info fields will be filled from the metadata
* in the file specified, but where fields are blank, they will be filled from $default_ps_file_info_array
* 4) Otherwise the fields will be blank
*
* See Edit_File_Info_Example.php for an example of usage
*
* Author: Evan Hunter
*
* Date: 17/11/2004
*
* Project: PHP JPEG Metadata Toolkit
*
* Revision: 1.11
*
* Changes: 1.10 -> 1.11 : Changed displayed toolkit version numbers to reference Toolkit_Version.php
*
* URL: http://electronics.ozhiker.com
*
* Copyright: Copyright Evan Hunter 2004
*
* License: This file is part of the PHP JPEG Metadata Toolkit.
*
* The PHP JPEG Metadata Toolkit is free software; you can
* redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* The PHP JPEG Metadata Toolkit is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public
* License along with the PHP JPEG Metadata Toolkit; if not,
* write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* If you require a different license for commercial or other
* purposes, please contact the author: [email protected]
*
***************************************************************************/
include 'Toolkit_Version.php'; // Change: added as of version 1.11
// Check for operation modes 2 or 3
// i.e. $filename is defined, and $new_ps_file_info_array is not
if ( ( ! isset( $new_ps_file_info_array ) ) &&
( isset( $filename ) ) &&
( is_string( $filename ) ) )
{
// Hide any unknown EXIF tags
$GLOBALS['HIDE_UNKNOWN_TAGS'] = TRUE;
// Accessing the existing file info for the specified file requires these includes
include 'JPEG.php';
include 'XMP.php';
include 'Photoshop_IRB.php';
include 'EXIF.php';
include 'Photoshop_File_Info.php';
// Retrieve the header information from the JPEG file
$jpeg_header_data = get_jpeg_header_data( $filename );
// Retrieve EXIF information from the JPEG file
$Exif_array = get_EXIF_JPEG( $filename );
// Retrieve XMP information from the JPEG file
$XMP_array = read_XMP_array_from_text( get_XMP_text( $jpeg_header_data ) );
// Retrieve Photoshop IRB information from the JPEG file
$IRB_array = get_Photoshop_IRB( $jpeg_header_data );
// Retrieve Photoshop File Info from the three previous arrays
$new_ps_file_info_array = get_photoshop_file_info( $Exif_array, $XMP_array, $IRB_array );
// Check if there is an array of defaults available
if ( ( isset( $default_ps_file_info_array) ) &&
( is_array( $default_ps_file_info_array) ) )
{
// There are defaults defined
// Check if there is a default for the date defined
if ( ( ! array_key_exists( 'date', $default_ps_file_info_array ) ) ||
( ( array_key_exists( 'date', $default_ps_file_info_array ) ) &&
( $default_ps_file_info_array['date'] == '' ) ) )
{
// No default for the date defined
// figure out a default from the file
// Check if there is a EXIF Tag 36867 "Date and Time of Original"
if ( ( $Exif_array != FALSE ) &&
( array_key_exists( 0, $Exif_array ) ) &&
( array_key_exists( 34665, $Exif_array[0] ) ) &&
( array_key_exists( 0, $Exif_array[0][34665] ) ) &&
( array_key_exists( 36867, $Exif_array[0][34665][0] ) ) )
{
// Tag "Date and Time of Original" found - use it for the default date
$default_ps_file_info_array['date'] = $Exif_array[0][34665][0][36867]['Data'][0];
$default_ps_file_info_array['date'] = preg_replace( "/(\d\d\d\d):(\d\d):(\d\d)( \d\d:\d\d:\d\d)/", "$1-$2-$3", $default_ps_file_info_array['date'] );
}
// Check if there is a EXIF Tag 36868 "Date and Time when Digitized"
else if ( ( $Exif_array != FALSE ) &&
( array_key_exists( 0, $Exif_array ) ) &&
( array_key_exists( 34665, $Exif_array[0] ) ) &&
( array_key_exists( 0, $Exif_array[0][34665] ) ) &&
( array_key_exists( 36868, $Exif_array[0][34665][0] ) ) )
{
// Tag "Date and Time when Digitized" found - use it for the default date
$default_ps_file_info_array['date'] = $Exif_array[0][34665][0][36868]['Data'][0];
$default_ps_file_info_array['date'] = preg_replace( "/(\d\d\d\d):(\d\d):(\d\d)( \d\d:\d\d:\d\d)/", "$1-$2-$3", $default_ps_file_info_array['date'] );
}
// Check if there is a EXIF Tag 306 "Date and Time"
else if ( ( $Exif_array != FALSE ) &&
( array_key_exists( 0, $Exif_array ) ) &&
( array_key_exists( 306, $Exif_array[0] ) ) )
{
// Tag "Date and Time" found - use it for the default date
$default_ps_file_info_array['date'] = $Exif_array[0][306]['Data'][0];
$default_ps_file_info_array['date'] = preg_replace( "/(\d\d\d\d):(\d\d):(\d\d)( \d\d:\d\d:\d\d)/", "$1-$2-$3", $default_ps_file_info_array['date'] );
}
else
{
// Couldn't find an EXIF date in the image
// Set default date as creation date of file
$default_ps_file_info_array['date'] = date ("Y-m-d", filectime( $filename ));
}
}
// Cycle through all the elements of the default values array
foreach( $default_ps_file_info_array as $def_key =>$default_item )
{
// Check if the current element is Keywords or
// Supplemental Categories as these are arrays
// and need to be treated differently
if ( ( strcasecmp( $def_key, "keywords" ) == 0 ) ||
( strcasecmp( $def_key, "supplementalcategories" ) == 0 ) )
{
// Keywords or Supplemental Categories found
// Check if the File Info from the file is empty for this element
// and if there are default values in this array element
if ( ( count( $new_ps_file_info_array[ $def_key ] ) == 0 ) &&
( is_array( $default_item ) ) &&
( count( $default_item ) >= 0 ) )
{
// The existing file info is empty, and there are
// defaults - add them
$new_ps_file_info_array[ $def_key ] = $default_item;
}
}
// Otherwise, this is not an array element, just check if it is blank in the existing file info
else if ( trim( $new_ps_file_info_array[ $def_key ] ) == "" )
{
// The existing file info is blank, add the default value
$new_ps_file_info_array[ $def_key ] = $default_item;
}
}
}
}
// Check for operation mode 4 - $new_ps_file_info_array and $filename are not defined,
else if ( ( ( !isset($new_ps_file_info_array) ) || ( ! is_array($new_ps_file_info_array) ) ) &&
( ( !isset($filename) ) || ( ! is_string( $filename ) ) ) )
{
// No filename or new_ps_file_info_array defined, create a blank file info array to display
$new_ps_file_info_array = 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" => "" );
}
/***************************************************************************
*
* Now output the actual HTML form
*
***************************************************************************/
?>
<form name="EditJPEG" action="Write_File_Info.php" method="post">
<?php echo "<input name=\"filename\" type=\"hidden\" value=\"$outputfilename\">"; ?>
<table>
<tr>
<td>
Title
</td>
<td>
<?php
echo "<input size=49 name=\"title\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'title' ]) ."\">";
?>
</td>
</tr>
<tr>
<td>
Author
</td>
<td>
<?php
echo "<input size=49 name=\"author\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'author' ]) ."\">";
?>
</td>
</tr>
<tr>
<td>
Authors Position
</td>
<td>
<?php
echo "<input size=49 name=\"authorsposition\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'authorsposition' ]) ."\"> - Note: not used in Photoshop 7 or higher";
?>
</td>
</tr>
<tr>
<td>
Description
</td>
<td>
<textarea name="caption" rows=3 cols=37 wrap="off"><?php echo htmlspecialchars($new_ps_file_info_array[ 'caption' ]); ?></textarea>
</td>
</tr>
<tr>
<td>
Description Writer
</td>
<td>
<?php
echo "<input size=49 name=\"captionwriter\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'captionwriter' ]) ."\">";
?>
</td>
</tr>
<tr>
<td>
Keywords
</td>
<td>
<textarea name="keywords" rows=3 cols=37 wrap="off"><?php
foreach( $new_ps_file_info_array[ 'keywords' ] as $keyword )
{
echo htmlspecialchars("$keyword
");
}
?></textarea>
</td>
</tr>
<tr>
<td>
Copyright Status
</td>
<td>
<select size=1 name="copyrightstatus">
<?php
$copystatus = $new_ps_file_info_array[ 'copyrightstatus' ];
if ( $copystatus == "Unknown" )
{
echo "<option value=\"Unknown\" SELECTED >Unknown</option>\n";
}
else
{
echo "<option value=\"Unknown\">Unknown</option>\n";
}
if ( $copystatus == "Copyrighted Work" )
{
echo "<option value=\"Copyrighted Work\" SELECTED >Copyrighted Work</option>\n";
}
else
{
echo "<option value=\"Copyrighted Work\">Copyrighted Work</option>\n";
}
if ( $copystatus == "Public Domain" )
{
echo "<option value=\"Public Domain\" SELECTED >Public Domain</option>\n";
}
else
{
echo "<option value=\"Public Domain\">Public Domain</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td>
Copyright Notice
</td>
<td>
<textarea name="copyrightnotice" rows=3 cols=37 wrap="off"><?php echo htmlspecialchars($new_ps_file_info_array[ 'copyrightnotice' ]); ?></textarea>
</td>
</tr>
<tr>
<td>
Copyright Info URL
</td>
<td>
<?php
echo "<input size=49 name=\"ownerurl\" type=\"text\" value=\"". htmlspecialchars$new_ps_file_info_array[ 'ownerurl' ]) ."\">\n";
if ($new_ps_file_info_array[ 'ownerurl' ] != "" )
{
echo "<a href=\"". $new_ps_file_info_array[ 'ownerurl' ] ."\" > (". htmlspecialchars($new_ps_file_info_array[ 'ownerurl' ]) .")</a>\n";
}
?>
</td>
</tr>
<tr>
<td>
Category
</td>
<td>
<?php
echo "<input size=49 name=\"category\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'category' ]) ."\">\n";
?>
</td>
</tr>
<tr>
<td>
Supplemental Categories
</td>
<td>
<textarea name="supplementalcategories" rows=3 cols=37 wrap="off"><?php
foreach( $new_ps_file_info_array[ 'supplementalcategories' ] as $supcat )
{
echo htmlspecialchars("$supcat
");
}
?>
</textarea>
</td>
</tr>
<tr>
<td>
Date Created
</td>
<td>
<?php
echo "<input size=49 name=\"date\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'date' ]) ."\">";
?>
(Note date must be YYYY-MM-DD format)
</td>
</tr>
<tr>
<td>
City
</td>
<td>
<?php
echo "<input size=49 name=\"city\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'city' ]) ."\">";
?>
</td>
</tr>
<tr>
<td>
State
</td>
<td>
<?php
echo "<input size=49 name=\"state\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'state' ]) ."\">";
?>
</td>
</tr>
<tr>
<td>
Country
</td>
<td>
<?php
echo "<input size=49 name=\"country\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'country' ]) ."\">";
?>
</td>
</tr>
<tr>
<td>
Credit
</td>
<td>
<?php
echo "<input size=49 name=\"credit\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'credit' ]) ."\">";
?>
</td>
</tr>
<tr>
<td>
Source
</td>
<td>
<?php
echo "<input size=49 name=\"source\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'source' ]) ."\">";
?>
</td>
</tr>
<tr>
<td>
Headline
</td>
<td>
<textarea name="headline" rows=3 cols=37 wrap="off"><?php echo htmlspecialchars($new_ps_file_info_array[ 'headline' ]); ?></textarea>
</td>
</tr>
<tr>
<td>
Instructions
</td>
<td>
<textarea name="instructions" rows=3 cols=37 wrap="off"><?php echo htmlspecialchars($new_ps_file_info_array[ 'instructions' ]); ?></textarea>
</td>
</tr>
<tr>
<td>
Transmission Reference
</td>
<td>
<textarea name="transmissionreference" rows=3 cols=37 wrap="off"><?php echo htmlspecialchars($new_ps_file_info_array[ 'transmissionreference' ]); ?></textarea>
</td>
</tr>
<tr>
<td>
Job Name
</td>
<td>
<?php
echo "<input size=49 name=\"jobname\" type=\"text\" value=\"". htmlspecialchars($new_ps_file_info_array[ 'jobname' ]) ."\"> - Note: not used in Photoshop CS";
?>
</td>
</tr>
<tr>
<td>
Urgency
</td>
<td>
<select size="1" name="urgency">
<?php
for( $i = 1; $i <= 8; $i++ )
{
echo "<option value=\"$i\"";
if ( $new_ps_file_info_array[ 'urgency' ] == $i )
{
echo " SELECTED ";
}
echo ">";
if ( $i == 1 )
{
echo "High";
}
else if ( $i == 5 )
{
echo "Normal";
}
else if ( $i == 8 )
{
echo "Low";
}
else
{
echo "$i";
}
echo "</option>\n";
}
if ( $new_ps_file_info_array[ 'urgency' ] == "none" )
{
echo "<option value=\"none\" SELECTED >None</option>";
}
else
{
echo "<option value=\"none\" >None</option>";
}
?>
</select>
</td>
</tr>
</table>
<br>
<input type="submit" value="Update!">
</form>
<br>
<br>
<p>Powered by: <a href="http://www.ozhiker.com/electronics/pjmt/" >PHP JPEG Metadata Toolkit version <?php echo $GLOBALS['Toolkit_Version'] ?>, Copyright (C) 2004 Evan Hunter</a></p> <!-- Change: displayed toolkit version numbers to reference Toolkit_Version.php - as of version 1.11 -->
<br>
<br>