-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
457 lines (430 loc) · 15.9 KB
/
index.php
File metadata and controls
457 lines (430 loc) · 15.9 KB
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
<?php
/**
* MyGedView page allows a logged in user the abilty
* to keep bookmarks, see a list of upcoming events, etc.
*
* phpGedView: Genealogy Viewer
* 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
*
* @package PhpGedView
* @subpackage Display
* @version $Id: index.php 6879 2010-01-30 11:35:46Z fisharebest $
*/
define('PGV_SCRIPT_NAME', 'index.php');
require './config.php';
require_once PGV_ROOT.'includes/index_cache.php';
require_once PGV_ROOT.'includes/functions/functions_print_facts.php'; //--needed for the expand url function in some of the blocks
if (!isset($CONFIGURED)) {
print "Unable to include the config.php file. Make sure that . is in your PHP include path in the php.ini file.";
exit;
}
if (isset($_REQUEST['action'])) $action = $_REQUEST['action'];
if (isset($_REQUEST['ctype'])) $ctype = $_REQUEST['ctype'];
$message_id = safe_GET('message_id');
$gid = safe_POST("gid");
$favnote = safe_POST("favnote");
$favtype = safe_POST("favtype");
$url = safe_POST("url", PGV_REGEX_URL);
$favtitle = safe_POST("favtitle");
$fv_id = safe_GET("fv_id");
$news_id = safe_GET("news_id");
/**
* Block definition array
*
* The following block definition array defines the
* blocks that can be used to customize the portals
* their names and the function to call them
* "name" is the name of the block in the lists
* "descr" is the name of a $pgv_lang variable to describe this block
* - eg: "whatever" here means that $pgv_lang["whatever"] describes this block
* "type" the options are "user" or "gedcom" or undefined
* - The type determines which lists the block is available in.
* - Leaving the type undefined allows it to be on both the user and gedcom portal
* @global $PGV_BLOCKS
*/
/**
* Load List of Blocks in blocks directory (unchanged)
*/
$PGV_BLOCKS = array();
$d = dir("blocks");
while (false !== ($entry = $d->read())) {
if (($entry!=".") && ($entry!="..") && ($entry!="CVS") && (preg_match("/\.php$/", $entry)>0)) {
require_once PGV_ROOT.'blocks/'.$entry;
}
}
$d->close();
/**
* End loading list of Blocks in blocks directory
*
* Load List of Blocks in modules/XX/blocks directories
*/
if (file_exists(PGV_ROOT.'modules')) {
$dir=dir(PGV_ROOT.'modules');
while (false !== ($entry = $dir->read())) {
if (!strstr($entry,".") && ($entry!="..") && ($entry!="CVS")&& !strstr($entry, "svn")) {
$path = PGV_ROOT.'modules/' . $entry.'/blocks';
if (is_readable($path)) {
$d=dir($path);
while (false !== ($entry = $d->read())) {
if (($entry!=".") && ($entry!="..") && ($entry!="CVS")&& !strstr($entry, "svn")&&(preg_match("/\.php$/", $entry)>0)) {
$p=$path.'/'.$entry;
require_once $p;
}
}
}
}
}
}
/**
* End loading list of Blocks in modules/XX/blocks directories
*/
$time = client_time();
if (!isset($action)) $action="";
//-- make sure that they have user status before they can use this page
//-- otherwise have them login again
if (!PGV_USER_ID) {
if (!empty($ctype) && $ctype=="user") {
header("Location: login.php?help_message=mygedview_login_help&url=".urlencode("index.php?ctype=user"));
exit;
} else {
$ctype = 'gedcom';
}
}
if (empty($ctype)) {
if ($PAGE_AFTER_LOGIN == 'welcome') $ctype = 'gedcom';
else $ctype = 'user';
}
if (PGV_USER_ID) {
//-- add favorites action
if ($action=="addfav" && !empty($gid)) {
$gid = strtoupper($gid);
$indirec = find_gedcom_record($gid, PGV_GED_ID);
$ct = preg_match("/0 @(.*)@ (.*)/", $indirec, $match);
if ($indirec && $ct>0) {
$favorite = array();
if (empty($favtype)) {
if ($ctype=="user") $favtype = "user";
else $favtype = "gedcom";
}
if ($favtype=="gedcom") {
$favtype = $GEDCOM;
$_SESSION['clearcache'] = true;
}
else $favtype=PGV_USER_NAME;
$favorite["username"] = $favtype;
$favorite["gid"] = $gid;
$favorite["type"] = trim($match[2]);
$favorite["file"] = $GEDCOM;
$favorite["url"] = "";
$favorite["note"] = $favnote;
$favorite["title"] = "";
addFavorite($favorite);
}
}
if (($action=="addfav")&&(!empty($url))) {
if (empty($favtitle)) $favtitle = $url;
$favorite = array();
if (!isset($favtype)) {
if ($ctype=="user") $favtype = "user";
else $favtype = "gedcom";
}
if ($favtype=="gedcom") {
$favtype = $GEDCOM;
$_SESSION['clearcache'] = true;
}
else $favtype=PGV_USER_NAME;
$favorite["username"] = $favtype;
$favorite["gid"] = "";
$favorite["type"] = "URL";
$favorite["file"] = $GEDCOM;
$favorite["url"] = $url;
$favorite["note"] = $favnote;
$favorite["title"] = $favtitle;
addFavorite($favorite);
}
if (($action=="deletefav")&&(!empty($fv_id))) {
deleteFavorite($fv_id);
if ($ctype=="gedcom") $_SESSION['clearcache'] = true;
}
else if ($action=="deletemessage") {
if (isset($message_id)) {
if (!is_array($message_id)) deleteMessage($message_id);
else {
foreach($message_id as $indexval => $mid) {
if (isset($mid)) deleteMessage($mid);
}
}
if ($ctype=="gedcom") $_SESSION['clearcache'] = true;
}
}
else if (($action=="deletenews")&&(isset($news_id))) {
deleteNews($news_id);
if ($ctype=="gedcom") $_SESSION['clearcache'] = true;
}
}
//-- get the blocks list
if ($ctype=="user") {
$ublocks = getBlocks(PGV_USER_NAME);
if ((count($ublocks["main"])==0) && (count($ublocks["right"])==0)) {
$ublocks["main"][] = array("print_todays_events", "");
$ublocks["main"][] = array("print_user_messages", "");
$ublocks["main"][] = array("print_user_favorites", "");
$ublocks["right"][] = array("print_welcome_block", "");
$ublocks["right"][] = array("print_random_media", "");
$ublocks["right"][] = array("print_upcoming_events", "");
$ublocks["right"][] = array("print_logged_in_users", "");
}
}
else {
$ublocks = getBlocks($GEDCOM);
if ((count($ublocks["main"])==0) && (count($ublocks["right"])==0)) {
$ublocks["main"][] = array("print_gedcom_stats", "");
$ublocks["main"][] = array("print_gedcom_news", "");
$ublocks["main"][] = array("print_gedcom_favorites", "");
$ublocks["main"][] = array("review_changes_block", "");
$ublocks["right"][] = array("print_gedcom_block", "");
$ublocks["right"][] = array("print_random_media", "");
$ublocks["right"][] = array("print_todays_events", "");
$ublocks["right"][] = array("print_logged_in_users", "");
}
}
//-- Set some behaviour controls that depend on which blocks are selected
$welcome_block_present = false;
$gedcom_block_present = false;
$top10_block_present = false;
$login_block_present = false;
foreach($ublocks["right"] as $block) {
if ($block[0]=="print_welcome_block") $welcome_block_present = true;
if ($block[0]=="print_gedcom_block") $gedcom_block_present = true;
if ($block[0]=="print_block_name_top10") $top10_block_present = true;
if ($block[0]=="print_login_block") $login_block_present = true;
}
foreach($ublocks["main"] as $block) {
if ($block[0]=="print_welcome_block") $welcome_block_present = true;
if ($block[0]=="print_gedcom_block") $gedcom_block_present = true;
if ($block[0]=="print_block_name_top10") $top10_block_present = true;
if ($block[0]=="print_login_block") $login_block_present = true;
}
//-- clear the GEDCOM cache files
if (!empty($_SESSION['clearcache'])) {
$_SESSION['clearcache'] = false;
clearCache();
}
// We have finished writing to $_SESSION, so release the lock
session_write_close();
//-- handle block AJAX calls
/**
* In order for a block to make an AJAX call the following request parameters must be set
* block = the method name of the block to call (e.g. 'print_random_media')
* side = the side of the page the block is on (e.g. 'main' or 'right')
* bindex = the number of the block on that side, first block = 0
*/
if ($action=="ajax") {
header("Content-Type: text/html; charset=$CHARACTER_SET");
//-- if a block wasn't sent then exit with nothing
if (!isset($_REQUEST['block'])) {
print "Block not sent";
exit;
}
$block = $_REQUEST['block'];
//-- set which side the block is on
$side = "main";
if (isset($_REQUEST['side'])) $side = $_REQUEST['side'];
//-- get the block number
if (isset($_REQUEST['bindex'])) {
if (isset($ublocks[$side][$_REQUEST['bindex']])) {
$blockval = $ublocks[$side][$_REQUEST['bindex']];
if ($blockval[0]==$block && array_key_exists($blockval[0], $PGV_BLOCKS)) {
if ($side=="main") {
$param1 = "false";
} else {
$param1 = "true";
}
if (array_key_exists($blockval[0], $PGV_BLOCKS) && !loadCachedBlock($blockval, $side.$_REQUEST['bindex'])) {
ob_start();
eval($blockval[0]."($param1, \$blockval[1], \"$side\", ".$_REQUEST['bindex'].");");
$content = ob_get_contents();
saveCachedBlock($blockval, $side.$_REQUEST['bindex'], $content);
ob_end_flush();
}
if (PGV_DEBUG) {
echo execution_stats();
}
if (PGV_DEBUG_SQL) {
echo PGV_DB::getQueryLog();
}
exit;
}
}
}
//-- not sure which block to call so call the first one we find
foreach($ublocks["main"] as $bindex=>$blockval) {
if ($blockval[0]==$block && array_key_exists($blockval[0], $PGV_BLOCKS)) {
eval($blockval[0]."(false, \$blockval[1], \"main\", $bindex);");
}
}
foreach($ublocks["right"] as $bindex=>$blockval) {
if ($blockval[0]==$block && array_key_exists($blockval[0], $PGV_BLOCKS)) {
eval($blockval[0]."(true, \$blockval[1], \"right\", $bindex);");
}
}
exit;
}
//-- end of ajax call handler
if ($ctype=="user") {
$helpindex = "index_myged_help";
print_header($pgv_lang["mygedview"]);
} else {
print_header(get_gedcom_setting(PGV_GED_ID, 'title'));
}
if (PGV_USE_LIGHTBOX) {
require PGV_ROOT.'modules/lightbox/lb_defaultconfig.php';
require PGV_ROOT.'modules/lightbox/functions/lb_call_js.php';
}
echo PGV_JS_START;
?>
function refreshpage() {
window.location = 'index.php?ctype=<?php print $ctype; ?>';
}
function addnews(uname) {
window.open('editnews.php?username='+uname, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
}
function editnews(news_id) {
window.open('editnews.php?news_id='+news_id, '_blank', 'top=50,left=50,width=600,height=500,resizable=1,scrollbars=1');
}
var pastefield;
function paste_id(value) {
pastefield.value=value;
}
/**
* blocks may use this JS function to update themselves using AJAX technology
* @param string targetId the id of the block to target the results too
* @param string block the method name of the block to call (e.g. 'print_random_media')
* @param string side the side of the page the block is on (e.g. 'main' or 'right')
* @param int bindex the number of the block on that side, first block = 0
* @param string ctype shows whether block is on Welcome or MyGedView page ('gedcom' or 'user')
* @param boolean loading Whether or not to show the loading message
*/
function ajaxBlock(targetId, block, side, bindex, ctype, loading) {
target = document.getElementById(targetId);
if (!target) return false;
target.style.height = (target.offsetHeight) + "px";
if (loading) target.innerHTML = "<br /><br /><?php print $pgv_lang['loading']; ?><br /><br />";
var oXmlHttp = createXMLHttp();
link = "index.php?action=ajax&block="+block+"&side="+side+"&bindex="+bindex+"&ctype="+ctype;
oXmlHttp.open("get", link, true);
oXmlHttp.onreadystatechange=function()
{
if (oXmlHttp.readyState==4)
{
target.innerHTML = oXmlHttp.responseText;
target.style.height = 'auto';
}
};
oXmlHttp.send(null);
return false;
}
<?php
echo PGV_JS_END;
//-- start of main content section
print "<table width=\"100%\"><tr><td>"; // This is needed so that page footers print in the right place
if ($ctype=="user") {
print "<div align=\"center\" style=\"width: 99%;\">";
print "<h1>".$pgv_lang["mygedview"]."</h1>";
print $pgv_lang["mygedview_desc"];
print "<br /><br /></div>";
}
if (count($ublocks["main"])!=0) {
if (count($ublocks["right"])!=0) {
print "<div id=\"index_main_blocks\">";
} else {
print "<div id=\"index_full_blocks\">";
}
echo '<script src="js/jquery/jquery.min.js" type="text/javascript"></script>';
echo '<script type="text/javascript">jQuery.noConflict();</script>';
foreach($ublocks["main"] as $bindex=>$block) {
if (PGV_DEBUG) {
echo execution_stats();
}
if (array_key_exists($block[0], $PGV_BLOCKS) && !loadCachedBlock($block, "main".$bindex)) {
$url="index.php?action=ajax&block={$block[0]}&side=main&bindex={$bindex}&ctype={$ctype}";
if ($SEARCH_SPIDER || PGV_DEBUG) {
// Search spiders get the blocks directly
ob_start();
eval($block[0]."(false, \$block[1], \"main\", $bindex);");
$content = ob_get_contents();
$temp = $SEARCH_SPIDER;
$SEARCH_SPIDER = false;
saveCachedBlock($block, "main".$bindex, $content);
$SEARCH_SPIDER = $temp;
ob_end_flush();
} else {
// Interactive users get the blocks via ajax
echo '<div id="block_main_', $bindex, '"><img src="images/loading.gif" alt="', htmlspecialchars($pgv_lang["loading"]), '"/></div>';
echo PGV_JS_START, "jQuery('#block_main_{$bindex}').load('{$url}');", PGV_JS_END;
}
}
}
print "</div>";
}
//-- end of main content section
//-- start of blocks section
if (count($ublocks["right"])!=0) {
if (count($ublocks["main"])!=0) {
print "<div id=\"index_small_blocks\">";
} else {
print "<div id=\"index_full_blocks\">";
}
foreach($ublocks["right"] as $bindex=>$block) {
if (PGV_DEBUG) {
echo execution_stats();
}
if (array_key_exists($block[0], $PGV_BLOCKS) && !loadCachedBlock($block, "right".$bindex)) {
$url="index.php?action=ajax&block={$block[0]}&side=right&bindex={$bindex}&ctype={$ctype}";
if ($SEARCH_SPIDER || PGV_DEBUG) {
// Search spiders get the blocks directly
ob_start();
eval($block[0]."(true, \$block[1], \"right\", $bindex);");
$content = ob_get_contents();
saveCachedBlock($block, "right".$bindex, $content);
ob_end_flush();
} else {
// Interactive users get the blocks via ajax
echo '<div id="block_right_', $bindex, '"><img src="images/loading.gif" alt="', htmlspecialchars($pgv_lang["loading"]), '"/></div>';
echo PGV_JS_START, "jQuery('#block_right_{$bindex}').load('{$url}');", PGV_JS_END;
}
}
}
print "</div>";
}
//-- end of blocks section
print "</td></tr></table><br />"; // Close off that table
if ($ctype=="user" && !$welcome_block_present) {
print "<div align=\"center\" style=\"width: 99%;\">";
print_help_link("mygedview_customize_help", "qm");
print "<a href=\"javascript:;\" onclick=\"window.open('index_edit.php?name=".PGV_USER_NAME."&ctype=user', '_blank', 'top=50,left=10,width=600,height=500,scrollbars=1,resizable=1');\">".$pgv_lang["customize_page"]."</a>";
print "</div>";
}
if ($ctype=="gedcom" && !$gedcom_block_present) {
if (PGV_USER_IS_ADMIN) {
print "<div align=\"center\" style=\"width: 99%;\">";
print "<a href=\"javascript:;\" onclick=\"window.open('".encode_url("index_edit.php?name={$GEDCOM}&ctype=gedcom", false)."', '_blank', 'top=50,left=10,width=600,height=500,scrollbars=1,resizable=1');\">".$pgv_lang["customize_gedcom_page"]."</a>";
print "</div>";
}
}
print_footer();
?>