xref: /webtrees/index.php (revision 5c5150a689fdc61ed8332a2ea5409078fde4c73e)
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
25use WT\Auth;
26
27define('WT_SCRIPT_NAME', 'index.php');
28require './includes/session.php';
29
30// The only option for action is "ajax"
31$action = WT_Filter::get('action');
32
33// The default view depends on whether we are logged in
34if (Auth::check()) {
35	$ctype = WT_Filter::get('ctype', 'gedcom|user', 'user');
36} else {
37	$ctype = 'gedcom';
38}
39
40// Get the blocks list
41if ($ctype === 'user') {
42	$blocks = get_user_blocks(WT_USER_ID);
43} else {
44	$blocks = get_gedcom_blocks(WT_GED_ID);
45}
46
47$all_blocks = WT_Module::getActiveBlocks();
48
49// The latest version is shown on the administration page.  This updates it every day.
50fetch_latest_version();
51
52// We generate individual blocks using AJAX
53if ($action === 'ajax') {
54	$controller = new WT_Controller_Ajax();
55	$controller->pageHeader();
56
57	// Check we’re displaying an allowable block.
58	$block_id = WT_Filter::getInteger('block_id');
59	if (array_key_exists($block_id, $blocks['main'])) {
60		$module_name = $blocks['main'][$block_id];
61	} elseif (array_key_exists($block_id, $blocks['side'])) {
62		$module_name = $blocks['side'][$block_id];
63	} else {
64		exit;
65	}
66	if (array_key_exists($module_name, $all_blocks)) {
67		$class_name = $module_name . '_WT_Module';
68		$module     = new $class_name;
69		$module->getBlock($block_id);
70	}
71	if (WT_DEBUG) {
72		echo execution_stats();
73	}
74	if (WT_DEBUG_SQL) {
75		echo WT_DB::getQueryLog();
76	}
77	exit;
78}
79
80$controller = new WT_Controller_Page();
81if ($ctype === 'user') {
82	$controller->restrictAccess(Auth::check());
83}
84$controller
85	->setPageTitle($ctype === 'user' ? WT_I18N::translate('My page') : WT_TREE_TITLE)
86	->setMetaRobots('index,follow')
87	->setCanonicalUrl(WT_SCRIPT_NAME . '?ctype=' . $ctype . '&amp;ged=' . WT_GEDCOM)
88	->pageHeader()
89	// By default jQuery modifies AJAX URLs to disable caching, causing JS libraries to be loaded many times.
90	->addInlineJavascript('jQuery.ajaxSetup({cache:true});');
91
92if ($ctype === 'user') {
93	echo '<div id="my-page">';
94	echo '<h1 class="center">', WT_I18N::translate('My page'), '</h1>';
95} else {
96	echo '<div id="home-page">';
97}
98if ($blocks['main']) {
99	if ($blocks['side']) {
100		echo '<div id="index_main_blocks">';
101	} else {
102		echo '<div id="index_full_blocks">';
103	}
104	foreach ($blocks['main'] as $block_id => $module_name) {
105		$class_name = $module_name . '_WT_Module';
106		$module     = new $class_name;
107		if ($SEARCH_SPIDER || !$module->loadAjax()) {
108			// Load the block directly
109			$module->getBlock($block_id);
110		} else {
111			// Load the block asynchronously
112			echo '<div id="block_', $block_id, '"><div class="loading-image">&nbsp;</div></div>';
113			$controller->addInlineJavascript(
114				'jQuery("#block_' . $block_id . '").load("index.php?ctype=' . $ctype . '&action=ajax&block_id=' . $block_id . '");'
115			);
116		}
117	}
118	echo '</div>';
119}
120if ($blocks['side']) {
121	if ($blocks['main']) {
122		echo '<div id="index_small_blocks">';
123	} else {
124		echo '<div id="index_full_blocks">';
125	}
126	foreach ($blocks['side'] as $block_id => $module_name) {
127		$class_name = $module_name . '_WT_Module';
128		$module     = new $class_name;
129		if ($SEARCH_SPIDER || !$module->loadAjax()) {
130			// Load the block directly
131			$module->getBlock($block_id);
132		} else {
133			// Load the block asynchronously
134			echo '<div id="block_', $block_id, '"><div class="loading-image">&nbsp;</div></div>';
135			$controller->addInlineJavascript(
136				'jQuery("#block_' . $block_id . '").load("index.php?ctype=' . $ctype . '&action=ajax&block_id=' . $block_id . '");'
137			);
138		}
139	}
140	echo '</div>';
141}
142
143echo '<div id="link_change_blocks">';
144
145if ($ctype === 'user') {
146	echo '<a href="#" 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>';
147} elseif ($ctype === 'gedcom' && WT_USER_GEDCOM_ADMIN) {
148	echo '<a href="#" 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}
150
151if ($WT_TREE->getPreference('SHOW_COUNTER')) {
152	echo '<span>' . WT_I18N::translate('Hit count:') . ' ' . $hitCount . '</span>';
153}
154
155echo '</div></div>';
156