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 19use Zend_Session; 20 21/** 22 * Class InteractiveTreeModule 23 * Tip : you could change the number of generations loaded before ajax calls both in individual page and in treeview page to optimize speed and server load 24 */ 25class InteractiveTreeModule extends Module implements ModuleTabInterface { 26 var $headers; // CSS and script to include in the top of <head> section, before theme’s CSS 27 var $js; // the TreeViewHandler javascript 28 29 /** {@inheritdoc} */ 30 public function getTitle() { 31 return /* I18N: Name of a module */ I18N::translate('Interactive tree'); 32 } 33 34 /** {@inheritdoc} */ 35 public function getDescription() { 36 return /* I18N: Description of the “Interactive tree” module */ I18N::translate('An interactive tree, showing all the ancestors and descendants of an individual.'); 37 } 38 39 /** {@inheritdoc} */ 40 public function defaultTabOrder() { 41 return 68; 42 } 43 44 /** {@inheritdoc} */ 45 public function getTabContent() { 46 global $controller; 47 48 $tv = new TreeView('tvTab'); 49 list($html, $js) = $tv->drawViewport($controller->record, 3); 50 return 51 '<script src="' . $this->js() . '"></script>' . 52 '<script src="' . WT_JQUERYUI_TOUCH_PUNCH_URL . '"></script>' . 53 '<script>' . $js . '</script>' . 54 $html; 55 } 56 57 /** {@inheritdoc} */ 58 public function hasTabContent() { 59 return !Auth::isSearchEngine(); 60 } 61 62 /** {@inheritdoc} */ 63 public function isGrayedOut() { 64 return false; 65 } 66 67 /** {@inheritdoc} */ 68 public function canLoadAjax() { 69 return true; 70 } 71 72 /** {@inheritdoc} */ 73 public function getPreLoadContent() { 74 // We cannot use jQuery("head").append(<link rel="stylesheet" ...as jQuery is not loaded at this time 75 return 76 '<script> 77 if (document.createStyleSheet) { 78 document.createStyleSheet("' . $this->css() . '"); // For Internet Explorer 79 } else { 80 var newSheet=document.createElement("link"); 81 newSheet.setAttribute("rel","stylesheet"); 82 newSheet.setAttribute("type","text/css"); 83 newSheet.setAttribute("href","' . $this->css() . '"); 84 document.getElementsByTagName("head")[0].appendChild(newSheet); 85 } 86 </script>'; 87 } 88 89 /** {@inheritdoc} */ 90 public function modAction($mod_action) { 91 switch ($mod_action) { 92 case 'treeview': 93 global $controller; 94 $controller = new ChartController; 95 $tv = new TreeView('tv'); 96 ob_start(); 97 98 $person = $controller->getSignificantIndividual(); 99 100 list($html, $js) = $tv->drawViewport($person, 4); 101 102 $controller 103 ->setPageTitle(I18N::translate('Interactive tree of %s', $person->getFullName())) 104 ->pageHeader() 105 ->addExternalJavascript($this->js()) 106 ->addExternalJavascript(WT_JQUERYUI_TOUCH_PUNCH_URL) 107 ->addInlineJavascript($js) 108 ->addInlineJavascript(' 109 if (document.createStyleSheet) { 110 document.createStyleSheet("' . $this->css() . '"); // For Internet Explorer 111 } else { 112 jQuery("head").append(\'<link rel="stylesheet" type="text/css" href="' . $this->css() . '">\'); 113 } 114 '); 115 echo $html; 116 break; 117 118 case 'getDetails': 119 Zend_Session::writeClose(); 120 header('Content-Type: text/html; charset=UTF-8'); 121 $pid = Filter::get('pid', WT_REGEX_XREF); 122 $i = Filter::get('instance'); 123 $tv = new TreeView($i); 124 $individual = Individual::getInstance($pid); 125 if ($individual) { 126 echo $tv->getDetails($individual); 127 } 128 break; 129 130 case 'getPersons': 131 Zend_Session::writeClose(); 132 header('Content-Type: text/html; charset=UTF-8'); 133 $q = Filter::get('q'); 134 $i = Filter::get('instance'); 135 $tv = new TreeView($i); 136 echo $tv->getPersons($q); 137 break; 138 139 default: 140 http_response_code(404); 141 break; 142 } 143 } 144 145 /** 146 * @return string 147 */ 148 public function css() { 149 return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/css/treeview.css'; 150 } 151 152 /** 153 * @return string 154 */ 155 public function js() { 156 return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/js/treeview.js'; 157 } 158} 159