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 require_once WT_MODULES_DIR . $this->getName() . '/class_treeview.php'; 49 $tv = new TreeView('tvTab'); 50 list($html, $js) = $tv->drawViewport($controller->record, 3); 51 return 52 '<script src="' . $this->js() . '"></script>' . 53 '<script src="' . WT_JQUERYUI_TOUCH_PUNCH_URL . '"></script>' . 54 '<script>' . $js . '</script>' . 55 $html; 56 } 57 58 /** {@inheritdoc} */ 59 public function hasTabContent() { 60 return !Auth::isSearchEngine(); 61 } 62 63 /** {@inheritdoc} */ 64 public function isGrayedOut() { 65 return false; 66 } 67 68 /** {@inheritdoc} */ 69 public function canLoadAjax() { 70 return true; 71 } 72 73 /** {@inheritdoc} */ 74 public function getPreLoadContent() { 75 // We cannot use jQuery("head").append(<link rel="stylesheet" ...as jQuery is not loaded at this time 76 return 77 '<script> 78 if (document.createStyleSheet) { 79 document.createStyleSheet("' . $this->css() . '"); // For Internet Explorer 80 } else { 81 var newSheet=document.createElement("link"); 82 newSheet.setAttribute("rel","stylesheet"); 83 newSheet.setAttribute("type","text/css"); 84 newSheet.setAttribute("href","' . $this->css() . '"); 85 document.getElementsByTagName("head")[0].appendChild(newSheet); 86 } 87 </script>'; 88 } 89 90 /** {@inheritdoc} */ 91 public function modAction($mod_action) { 92 require_once WT_MODULES_DIR . $this->getName() . '/class_treeview.php'; 93 switch ($mod_action) { 94 case 'treeview': 95 global $controller; 96 $controller = new ChartController; 97 $tv = new TreeView('tv'); 98 ob_start(); 99 100 $person = $controller->getSignificantIndividual(); 101 102 list($html, $js) = $tv->drawViewport($person, 4); 103 104 $controller 105 ->setPageTitle(I18N::translate('Interactive tree of %s', $person->getFullName())) 106 ->pageHeader() 107 ->addExternalJavascript($this->js()) 108 ->addExternalJavascript(WT_JQUERYUI_TOUCH_PUNCH_URL) 109 ->addInlineJavascript($js) 110 ->addInlineJavascript(' 111 if (document.createStyleSheet) { 112 document.createStyleSheet("' . $this->css() . '"); // For Internet Explorer 113 } else { 114 jQuery("head").append(\'<link rel="stylesheet" type="text/css" href="' . $this->css() . '">\'); 115 } 116 '); 117 echo $html; 118 break; 119 120 case 'getDetails': 121 Zend_Session::writeClose(); 122 header('Content-Type: text/html; charset=UTF-8'); 123 $pid = Filter::get('pid', WT_REGEX_XREF); 124 $i = Filter::get('instance'); 125 $tv = new TreeView($i); 126 $individual = Individual::getInstance($pid); 127 if ($individual) { 128 echo $tv->getDetails($individual); 129 } 130 break; 131 132 case 'getPersons': 133 Zend_Session::writeClose(); 134 header('Content-Type: text/html; charset=UTF-8'); 135 $q = Filter::get('q'); 136 $i = Filter::get('instance'); 137 $tv = new TreeView($i); 138 echo $tv->getPersons($q); 139 break; 140 141 default: 142 http_response_code(404); 143 break; 144 } 145 } 146 147 /** 148 * @return string 149 */ 150 public function css() { 151 return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/css/treeview.css'; 152 } 153 154 /** 155 * @return string 156 */ 157 public function js() { 158 return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/js/treeview.js'; 159 } 160} 161