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
|
<?php
// Controller for the Media Page
//
// webtrees: Web based Family History software
// Copyright (C) 2011 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2009 PGV Development Team. All rights reserved.
//
// This program 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.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// @version $Id$
if (!defined('WT_WEBTREES')) {
header('HTTP/1.0 403 Forbidden');
exit;
}
require_once WT_ROOT.'includes/functions/functions_print_facts.php';
require_once WT_ROOT.'includes/functions/functions_import.php';
class WT_Controller_Media extends WT_Controller_Base {
var $mid;
var $mediaobject;
var $accept_success = false;
var $reject_success = false;
function init() {
global $MEDIA_DIRECTORY;
$filename = safe_GET('filename');
$this->mid = safe_GET_xref('mid');
if (empty($filename) && empty($this->mid)) {
// this section used by mediafirewall.php to determine what media file was requested
if (isset($_SERVER['REQUEST_URI'])) {
// NOTE: format of this server variable:
// Apache: /phpGedView/media/a.jpg
// IIS: /phpGedView/mediafirewall.php?404;http://server/phpGedView/media/a.jpg
$requestedfile = $_SERVER['REQUEST_URI'];
// urldecode the request
$requestedfile = rawurldecode($requestedfile);
// make sure the requested file is in the media directory
if (strpos($requestedfile, $MEDIA_DIRECTORY) !== false) {
// strip off the wt directory and media directory from the requested url so just the image information is left
$filename = substr($requestedfile, strpos($requestedfile, $MEDIA_DIRECTORY) + strlen($MEDIA_DIRECTORY) - 1);
// strip the ged param if it was passed on the querystring
// would be better if this could remove any querystring, but '?' are valid in unix filenames
if (strpos($filename, '?ged=') !== false) {
$filename = substr($filename, 0, strpos($filename, '?ged='));
}
// if user requested a thumbnail, lookup permissions based on the original image
$filename = str_replace('/thumbs', '', $filename);
} else {
// the MEDIA_DIRECTORY of the current GEDCOM was not part of the requested file
// either the requested file is in a different GEDCOM (with a different MEDIA_DIRECTORY)
// or the Media Firewall is being called from outside the MEDIA_DIRECTORY
// this condition can be detected by the media firewall by calling controller->getServerFilename()
}
}
}
//Checks to see if the File Name ($filename) exists
if (!empty($filename)) {
//If the File Name ($filename) is set, then it will call the method to get the Media ID ($this->mid) from the File Name ($filename)
$this->mid = get_media_id_from_file($filename);
if (!$this->mid) {
//This will set the Media ID to be false if the File given doesn't match to anything in the database
$this->mid = false;
// create a very basic gedcom record for this file so that the functions of the media object will work
// this is used by the media firewall when requesting an object that exists in the media firewall directory but not in the gedcom
$this->mediaobject = new WT_Media("0 @"."0"."@ OBJE\n1 FILE ".$filename);
}
}
//checks to see if the Media ID ($this->mid) is set. If the Media ID isn't set then there isn't any information avaliable for that picture the picture doesn't exist.
if ($this->mid) {
//This creates a Media Object from the getInstance method of the Media Class. It takes the Media ID ($this->mid) and creates the object.
$this->mediaobject = WT_Media::getInstance($this->mid);
//This sets the controller ID to be the Media ID
$this->pid = $this->mid;
}
if (is_null($this->mediaobject)) return false;
$this->mediaobject->ged_id=WT_GED_ID; // This record is from a file
$this->mid=$this->mediaobject->getXref(); // Correct upper/lower case mismatch
//-- perform the desired action
switch($this->action) {
case 'addfav':
if (WT_USER_ID && !empty($_REQUEST['gid']) && array_key_exists('user_favorites', WT_Module::getActiveModules())) {
$favorite = array(
'username' => WT_USER_NAME,
'gid' => $_REQUEST['gid'],
'type' => 'OBJE',
'file' => WT_GEDCOM,
'url' => '',
'note' => '',
'title' => ''
);
user_favorites_WT_Module::addFavorite($favorite);
}
unset($_GET['action']);
break;
case 'accept':
if (WT_USER_CAN_ACCEPT) {
accept_all_changes($this->pid, WT_GED_ID);
$this->accept_success=true;
//-- check if we just deleted the record and redirect to index
$mediarec = find_media_record($this->pid, WT_GED_ID);
if (empty($mediarec)) {
header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH);
exit;
}
$this->mediaobject = new WT_Media($mediarec);
}
unset($_GET['action']);
break;
case 'undo':
if (WT_USER_CAN_ACCEPT) {
reject_all_changes($this->pid, WT_GED_ID);
$this->reject_success=true;
$mediarec = find_media_record($this->pid, WT_GED_ID);
//-- check if we just deleted the record and redirect to index
if (empty($mediarec)) {
header('Location: '.WT_SERVER_NAME.WT_SCRIPT_PATH);
exit;
}
$this->mediaobject = new WT_Media($mediarec);
}
unset($_GET['action']);
break;
}
}
/**
* return the title of this page
* @return string the title of the page to go in the <title> tags
*/
function getPageTitle() {
if ($this->mediaobject) {
return $this->mediaobject->getFullName()." - ".WT_I18N::translate('Media file');
} else {
return WT_I18N::translate('Unable to find record with ID');
}
}
function canDisplayDetails() {
return $this->mediaobject->canDisplayDetails();
}
/**
* get edit menu
*/
function getEditMenu() {
global $SHOW_GEDCOM_RECORD;
if (!$this->mediaobject) return null;
$links = get_media_relations($this->pid);
$linktoid = "new";
foreach ($links as $linktoid => $type) {
break; // we're only interested in the key of the first list entry
}
// edit menu
$menu = new WT_Menu(WT_I18N::translate('Edit'));
$menu->addIcon('edit_media');
$menu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_large_edit_media');
$menu->addId('menu-obje');
if (WT_USER_CAN_EDIT) {
$submenu = new WT_Menu(WT_I18N::translate('Edit media object'));
$submenu->addOnclick("window.open('addmedia.php?action=editmedia&pid={$this->pid}', '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1')");
$submenu->addIcon('edit_media');
$submenu->addId('menu-obje-edit');
$submenu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_small_edit_media');
$menu->addSubmenu($submenu);
// main link displayed on page
if (WT_USER_GEDCOM_ADMIN && array_key_exists('GEDFact_assistant', WT_Module::getActiveModules())) {
$submenu = new WT_Menu(WT_I18N::translate('Manage links'));
} else {
$submenu = new WT_Menu(WT_I18N::translate('Set link'));
}
$submenu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_small_medialink');
$submenu->addIcon('edit_media');
$submenu->addId('menu-obje-link');
// GEDFact assistant Add Media Links =======================
if (WT_USER_GEDCOM_ADMIN && array_key_exists('GEDFact_assistant', WT_Module::getActiveModules())) {
$submenu->addOnclick("return ilinkitem('".$this->pid."','manage');");
} else {
$ssubmenu = new WT_Menu(WT_I18N::translate('To Person'));
$ssubmenu->addOnclick("return ilinkitem('".$this->pid."','person');");
$ssubmenu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_small_indis');
$ssubmenu->addIcon('edit_media');
$ssubmenu->addId('menu-obje-link-indi');
$submenu->addSubMenu($ssubmenu);
$ssubmenu = new WT_Menu(WT_I18N::translate('To Family'));
$ssubmenu->addOnclick("return ilinkitem('".$this->pid."','family');");
$ssubmenu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_small_cfamily');
$ssubmenu->addIcon('edit_media');
$ssubmenu->addId('menu-obje-link-fam');
$submenu->addSubMenu($ssubmenu);
$ssubmenu = new WT_Menu(WT_I18N::translate('To Source'));
$ssubmenu->addOnclick("return ilinkitem('".$this->pid."','source');");
$ssubmenu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_small_menu_source');
$ssubmenu->addIcon('edit_media');
$ssubmenu->addId('menu-obje-link-sour');
$submenu->addSubMenu($ssubmenu);
}
$menu->addSubmenu($submenu);
}
// edit/view raw gedcom
if (WT_USER_IS_ADMIN || $SHOW_GEDCOM_RECORD) {
$submenu = new WT_Menu(WT_I18N::translate('Edit raw GEDCOM record'));
$submenu->addOnclick("return edit_raw('".$this->pid."');");
$submenu->addIcon('gedcom');
$submenu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_small_edit_raw');
$submenu->addId('menu-obje-editraw');
$menu->addSubmenu($submenu);
} elseif ($SHOW_GEDCOM_RECORD) {
$submenu = new WT_Menu(WT_I18N::translate('View GEDCOM Record'));
$submenu->addIcon('gedcom');
if (WT_USER_CAN_EDIT || WT_USER_CAN_ACCEPT) {
$submenu->addOnclick("return show_gedcom_record('new');");
} else {
$submenu->addOnclick("return show_gedcom_record();");
}
$submenu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_small_edit_raw');
$submenu->addId('menu-obje-viewraw');
$menu->addSubmenu($submenu);
}
// delete
if (WT_USER_GEDCOM_ADMIN) {
$submenu = new WT_Menu(WT_I18N::translate('Remove object'), "admin_media.php?action=removeobject&xref=".$this->pid);
$submenu->addOnclick("return confirm('".WT_I18N::translate('Are you sure you want to remove this object from the database?')."')");
$submenu->addIcon('remove');
$submenu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_small_delete');
$submenu->addId('menu-obje-del');
$menu->addSubmenu($submenu);
}
// add to favorites
$submenu = new WT_Menu(WT_I18N::translate('Add to My Favorites'), "mediaviewer.php?action=addfav&mid={$this->mid}&gid={$this->mid}");
$submenu->addIcon('favorites');
$submenu->addClass('submenuitem', 'submenuitem_hover', 'submenu', 'icon_small_fav');
$submenu->addId('menu-obje-addfav');
$menu->addSubmenu($submenu);
//-- get the link for the first submenu and set it as the link for the main menu
if (isset($menu->submenus[0])) {
$link = $menu->submenus[0]->onclick;
$menu->addOnclick($link);
}
return $menu;
}
/**
* check if we can show the gedcom record
* @return boolean
*/
function canShowGedcomRecord() {
global $SHOW_GEDCOM_RECORD;
if ($SHOW_GEDCOM_RECORD && $this->mediaobject->canDisplayDetails())
return true;
}
/**
* return a list of facts
* @return array
*/
function getFacts($includeFileName=true) {
$facts = $this->mediaobject->getFacts(array());
sort_facts($facts);
//if ($includeFileName) $facts[] = new WT_Event("1 FILE ".$this->mediaobject->getFilename());
$mediaType = $this->mediaobject->getMediatype();
$facts[] = new WT_Event("1 TYPE ".WT_Gedcom_Tag::getFileFormTypeValue($mediaType));
if (($newrec=find_updated_record($this->pid, WT_GED_ID))!==null) {
$newmedia = new WT_Media($newrec);
$newfacts = $newmedia->getFacts(array());
$newimgsize = $newmedia->getImageAttributes();
if ($includeFileName) $newfacts[] = new WT_Event("1 TYPE ".WT_Gedcom_Tag::getFileFormTypeValue($mediaType));
$newfacts[] = new WT_Event("1 FORM ".$newimgsize['ext']);
$mediaType = $newmedia->getMediatype();
$newfacts[] = new WT_Event("1 TYPE ".WT_Gedcom_Tag::getFileFormTypeValue($mediaType));
//-- loop through new facts and add them to the list if they are any changes
//-- compare new and old facts of the Personal Fact and Details tab 1
for ($i=0; $i<count($facts); $i++) {
$found=false;
foreach ($newfacts as $indexval => $newfact) {
if (trim($newfact->gedcomRecord)==trim($facts[$i]->gedcomRecord)) {
$found=true;
break;
}
}
if (!$found) {
$facts[$i]->gedcomRecord.="\nWT_OLD\n";
}
}
foreach ($newfacts as $indexval => $newfact) {
$found=false;
foreach ($facts as $indexval => $fact) {
if (trim($fact->gedcomRecord)==trim($newfact->gedcomRecord)) {
$found=true;
break;
}
}
if (!$found) {
$newfact->gedcomRecord.="\nWT_NEW\n";
$facts[]=$newfact;
}
}
}
if ($this->mediaobject->fileExists()) {
// get height and width of image, when available
$imgsize = $this->mediaobject->getImageAttributes();
if (!empty($imgsize['WxH'])) {
$facts[] = new WT_Event("1 EVEN " . '<span dir="ltr">' . $imgsize['WxH'] . '</span>' . "\n2 TYPE image_size");
}
//Prints the file size
$facts[] = new WT_Event("1 EVEN " . '<span dir="ltr">' . $this->mediaobject->getFilesize(). '</span>' . "\n2 TYPE file_size");
}
sort_facts($facts);
return $facts;
}
/**
* get the relative file path of the image on the server
* @return string
*/
function getLocalFilename() {
if ($this->mediaobject) {
return $this->mediaobject->getLocalFilename();
} else {
return false;
}
}
/**
* get the file name on the server
* @return string
*/
function getServerFilename() {
if ($this->mediaobject) {
return $this->mediaobject->getServerFilename();
} else {
return false;
}
}
}
|