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