xref: /webtrees/index.php (revision 8d75d8ef436236d498208fa08b54b8b2fc3d4454)
1<?php
2// My page page allows a logged in user the abilty
3// to keep bookmarks, see a list of upcoming events, etc.
4//
5// webtrees: Web based Family History software
6// Copyright (C) 2014 webtrees development team.
7//
8// Derived from PhpGedView
9// Copyright (C) 2002 to 2009 PGV Development Team.  All rights reserved.
10//
11// This program is free software; you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation; either version 2 of the License, or
14// (at your option) any later version.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24
25// webtrees requires a modern version of PHP
26// Note - maintaining this check requires that this file can be parsed by PHP5.2
27if (version_compare(PHP_VERSION, '5.3.2', '<')) {
28	// RFC2616 requires an absolute URL, but we don’t have it here.
29	header('Location: site-php-version.php');
30}
31
32define('WT_SCRIPT_NAME', 'index.php');
33require './includes/session.php';
34
35// The only option for action is "ajax"
36$action = WT_Filter::get('action');
37
38// The default view depends on whether we are logged in
39$ctype = WT_Filter::get('ctype', 'gedcom|user', WT_USER_ID ? 'user' : 'gedcom');
40
41// Get the blocks list
42if (WT_USER_ID && $ctype=='user') {
43	$blocks = get_user_blocks(WT_USER_ID);
44} else {
45	$blocks = get_gedcom_blocks(WT_GED_ID);
46}
47
48$all_blocks = WT_Module::getActiveBlocks();
49
50// The latest version is shown on the administration page.  This updates it every day.
51// TODO: send an email notification to the admin when new versions are available.
52fetch_latest_version();
53
54// We generate individual blocks using AJAX
55if ($action == 'ajax') {
56	$controller = new WT_Controller_Ajax();
57	$controller->pageHeader();
58
59	// Check we’re displaying an allowable block.
60	$block_id = WT_Filter::getInteger('block_id');
61	if (array_key_exists($block_id, $blocks['main'])) {
62		$module_name = $blocks['main'][$block_id];
63	} elseif (array_key_exists($block_id, $blocks['side'])) {
64		$module_name = $blocks['side'][$block_id];
65	} else {
66		exit;
67	}
68	if (array_key_exists($module_name, $all_blocks)) {
69		$class_name = $module_name.'_WT_Module';
70		$module = new $class_name;
71		$module->getBlock($block_id);
72	}
73	if (WT_DEBUG) {
74		echo execution_stats();
75	}
76	if (WT_DEBUG_SQL) {
77		echo WT_DB::getQueryLog();
78	}
79	exit;
80}
81
82$controller=new WT_Controller_Page();
83if ($ctype=='user') {
84	$controller->restrictAccess(\WT\Auth::isMember());
85}
86$controller
87	->setPageTitle($ctype=='user' ? WT_I18N::translate('My page') : WT_TREE_TITLE)
88	->setMetaRobots('index,follow')
89	->setCanonicalUrl(WT_SCRIPT_NAME . '?ctype=' . $ctype . '&amp;ged=' . WT_GEDCOM)
90	->pageHeader()
91	// By default jQuery modifies AJAX URLs to disable caching, causing JS libraries to be loaded many times.
92	->addInlineJavascript('jQuery.ajaxSetup({cache:true});');
93
94if ($ctype=='user') {
95	echo '<div id="my-page">';
96	echo '<h1 class="center">', WT_I18N::translate('My page'), '</h1>';
97} else {
98	echo '<div id="home-page">';
99}
100if ($blocks['main']) {
101	if ($blocks['side']) {
102		echo '<div id="index_main_blocks">';
103	} else {
104		echo '<div id="index_full_blocks">';
105	}
106	foreach ($blocks['main'] as $block_id=>$module_name) {
107		$class_name=$module_name.'_WT_Module';
108		$module=new $class_name;
109		if ($SEARCH_SPIDER || !$module->loadAjax()) {
110			// Load the block directly
111			$module->getBlock($block_id);
112		} else {
113			// Load the block asynchronously
114			echo '<div id="block_', $block_id, '"><div class="loading-image">&nbsp;</div></div>';
115			$controller->addInlineJavascript(
116				'jQuery("#block_'.$block_id.'").load("index.php?ctype='.$ctype.'&action=ajax&block_id='.$block_id.'");'
117			);
118		}
119	}
120	echo '</div>';
121}
122if ($blocks['side']) {
123	if ($blocks['main']) {
124		echo '<div id="index_small_blocks">';
125	} else {
126		echo '<div id="index_full_blocks">';
127	}
128	foreach ($blocks['side'] as $block_id=>$module_name) {
129		$class_name=$module_name.'_WT_Module';
130		$module=new $class_name;
131		if ($SEARCH_SPIDER || !$module->loadAjax()) {
132			// Load the block directly
133			$module->getBlock($block_id);
134		} else {
135			// Load the block asynchronously
136			echo '<div id="block_', $block_id, '"><div class="loading-image">&nbsp;</div></div>';
137			$controller->addInlineJavascript(
138				'jQuery("#block_'.$block_id.'").load("index.php?ctype='.$ctype.'&action=ajax&block_id='.$block_id.'");'
139			);
140		}
141	}
142	echo '</div>';
143}
144
145// link for changing blocks
146echo '<div id="link_change_blocks">';
147	if ($ctype=='user') echo '<a href="index_edit.php?user_id='.WT_USER_ID.'" onclick="return modalDialog(\'index_edit.php?user_id='.WT_USER_ID.'\', \'', WT_I18N::translate('Change the blocks on this page'), '\');">', WT_I18N::translate('Change the blocks on this page'), '</a>';
148	if (WT_USER_GEDCOM_ADMIN && $ctype=='gedcom') echo '<a href="index_edit.php?gedcom_id='.WT_GED_ID.'" onclick="return modalDialog(\'index_edit.php?gedcom_id='.WT_GED_ID.'\', \'', WT_I18N::translate('Change the blocks on this page'), '\');">', WT_I18N::translate('Change the blocks on this page'), '</a>';
149	if ($SHOW_COUNTER) {echo '<span>'.WT_I18N::translate('Hit count:').' '.$hitCount.'</span>';}
150echo '</div>', // <div id="link_change_blocks">
151	 '</div>'; // <div id="home-page">
152