1<?php 2namespace Fisharebest\Webtrees; 3 4/** 5 * webtrees: online genealogy 6 * Copyright (C) 2015 webtrees development team 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19/** 20 * Defined in session.php 21 * 22 * @global Tree $WT_TREE 23 */ 24global $WT_TREE; 25 26use Fisharebest\Webtrees\Controller\AjaxController; 27use Fisharebest\Webtrees\Controller\PageController; 28use Fisharebest\Webtrees\Functions\Functions; 29use Fisharebest\Webtrees\Functions\FunctionsDb; 30 31define('WT_SCRIPT_NAME', 'index.php'); 32require './includes/session.php'; 33 34// The only option for action is "ajax" 35$action = Filter::get('action'); 36 37// The default view depends on whether we are logged in 38if (Auth::check()) { 39 $ctype = Filter::get('ctype', 'gedcom|user', 'user'); 40} else { 41 $ctype = 'gedcom'; 42} 43 44// Get the blocks list 45if ($ctype === 'user') { 46 $blocks = FunctionsDb::getUserBlocks(Auth::id()); 47} else { 48 $blocks = FunctionsDb::getTreeBlocks($WT_TREE->getTreeId()); 49} 50 51$active_blocks = Module::getActiveBlocks($WT_TREE); 52 53// The latest version is shown on the administration page. This updates it every day. 54Functions::fetchLatestVersion(); 55 56// We generate individual blocks using AJAX 57if ($action === 'ajax') { 58 $controller = new AjaxController; 59 $controller->pageHeader(); 60 61 // Check we’re displaying an allowable block. 62 $block_id = Filter::getInteger('block_id'); 63 if (array_key_exists($block_id, $blocks['main'])) { 64 $module_name = $blocks['main'][$block_id]; 65 } elseif (array_key_exists($block_id, $blocks['side'])) { 66 $module_name = $blocks['side'][$block_id]; 67 } else { 68 return; 69 } 70 if (array_key_exists($module_name, $active_blocks)) { 71 echo $active_blocks[$module_name]->getBlock($block_id); 72 } 73 74 return; 75} 76 77$controller = new PageController; 78if ($ctype === 'user') { 79 $controller->restrictAccess(Auth::check()); 80} 81$controller 82 ->setPageTitle($ctype === 'user' ? I18N::translate('My page') : $WT_TREE->getTitle()) 83 ->setMetaRobots('index,follow') 84 ->setCanonicalUrl(WT_SCRIPT_NAME . '?ctype=' . $ctype . '&ged=' . $WT_TREE->getNameHtml()) 85 ->pageHeader() 86 // By default jQuery modifies AJAX URLs to disable caching, causing JS libraries to be loaded many times. 87 ->addInlineJavascript('jQuery.ajaxSetup({cache:true});'); 88 89if ($ctype === 'user') { 90 echo '<div id="my-page">'; 91 echo '<h1 class="center">', I18N::translate('My page'), '</h1>'; 92} else { 93 echo '<div id="home-page">'; 94} 95if ($blocks['main']) { 96 if ($blocks['side']) { 97 echo '<div id="index_main_blocks">'; 98 } else { 99 echo '<div id="index_full_blocks">'; 100 } 101 foreach ($blocks['main'] as $block_id => $module_name) { 102 if (array_key_exists($module_name, $active_blocks)) { 103 if (Auth::isSearchEngine() || !$active_blocks[$module_name]->loadAjax()) { 104 // Load the block directly 105 echo $active_blocks[$module_name]->getBlock($block_id); 106 } else { 107 // Load the block asynchronously 108 echo '<div id="block_', $block_id, '"><div class="loading-image"> </div></div>'; 109 $controller->addInlineJavascript( 110 'jQuery("#block_' . $block_id . '").load("index.php?ctype=' . $ctype . '&action=ajax&block_id=' . $block_id . '");' 111 ); 112 } 113 } 114 } 115 echo '</div>'; 116} 117if ($blocks['side']) { 118 if ($blocks['main']) { 119 echo '<div id="index_small_blocks">'; 120 } else { 121 echo '<div id="index_full_blocks">'; 122 } 123 foreach ($blocks['side'] as $block_id => $module_name) { 124 if (array_key_exists($module_name, $active_blocks)) { 125 if (Auth::isSearchEngine() || !$active_blocks[$module_name]->loadAjax()) { 126 // Load the block directly 127 echo $active_blocks[$module_name]->getBlock($block_id); 128 } else { 129 // Load the block asynchronously 130 echo '<div id="block_', $block_id, '"><div class="loading-image"> </div></div>'; 131 $controller->addInlineJavascript( 132 'jQuery("#block_' . $block_id . '").load("index.php?ctype=' . $ctype . '&action=ajax&block_id=' . $block_id . '");' 133 ); 134 } 135 } 136 } 137 echo '</div>'; 138} 139echo '</div>'; 140