18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 46bdf7674SGreg Roach * Copyright (C) 2017 webtrees development team 58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 88c2e8227SGreg Roach * (at your option) any later version. 98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128c2e8227SGreg Roach * GNU General Public License for more details. 138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 158c2e8227SGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1776692c8bSGreg Roach 180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 1915d603e7SGreg Roachuse Fisharebest\Webtrees\Bootstrap4; 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter; 2115d603e7SGreg Roachuse Fisharebest\Webtrees\FontAwesome; 223d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsDate; 233d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit; 240e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 250e62c4b8SGreg Roachuse Fisharebest\Webtrees\Module; 260e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site; 270e62c4b8SGreg Roachuse Fisharebest\Webtrees\Stats; 280e62c4b8SGreg Roachuse Fisharebest\Webtrees\Theme; 290e62c4b8SGreg Roachuse Fisharebest\Webtrees\Tree; 308c2e8227SGreg Roach 318c2e8227SGreg Roach/** 328c2e8227SGreg Roach * Class HtmlBlockModule 338c2e8227SGreg Roach */ 34e2a378d3SGreg Roachclass HtmlBlockModule extends AbstractModule implements ModuleBlockInterface { 358c2e8227SGreg Roach /** {@inheritdoc} */ 368c2e8227SGreg Roach public function getTitle() { 378c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('HTML'); 388c2e8227SGreg Roach } 398c2e8227SGreg Roach 408c2e8227SGreg Roach /** {@inheritdoc} */ 418c2e8227SGreg Roach public function getDescription() { 428c2e8227SGreg Roach return /* I18N: Description of the “HTML” module */ I18N::translate('Add your own text and graphics.'); 438c2e8227SGreg Roach } 448c2e8227SGreg Roach 4576692c8bSGreg Roach /** 4676692c8bSGreg Roach * Generate the HTML content of this block. 4776692c8bSGreg Roach * 4876692c8bSGreg Roach * @param int $block_id 4976692c8bSGreg Roach * @param bool $template 50727f238cSGreg Roach * @param string[] $cfg 5176692c8bSGreg Roach * 5276692c8bSGreg Roach * @return string 5376692c8bSGreg Roach */ 5413abd6f3SGreg Roach public function getBlock($block_id, $template = true, $cfg = []) { 558c2e8227SGreg Roach global $ctype, $WT_TREE; 568c2e8227SGreg Roach 57e2a378d3SGreg Roach $title = $this->getBlockSetting($block_id, 'title'); 58e2a378d3SGreg Roach $html = $this->getBlockSetting($block_id, 'html'); 59e2a378d3SGreg Roach $gedcom = $this->getBlockSetting($block_id, 'gedcom'); 60e2a378d3SGreg Roach $show_timestamp = $this->getBlockSetting($block_id, 'show_timestamp', '0'); 61e2a378d3SGreg Roach $languages = $this->getBlockSetting($block_id, 'languages'); 628c2e8227SGreg Roach 638c2e8227SGreg Roach // Only show this block for certain languages 648c2e8227SGreg Roach if ($languages && !in_array(WT_LOCALE, explode(',', $languages))) { 658c2e8227SGreg Roach return ''; 668c2e8227SGreg Roach } 678c2e8227SGreg Roach 688c2e8227SGreg Roach /* 698c2e8227SGreg Roach * Select GEDCOM 708c2e8227SGreg Roach */ 718c2e8227SGreg Roach switch ($gedcom) { 728c2e8227SGreg Roach case '__current__': 738c2e8227SGreg Roach $stats = new Stats($WT_TREE); 748c2e8227SGreg Roach break; 758c2e8227SGreg Roach case '__default__': 76ef2fd529SGreg Roach $tree = Tree::findByName(Site::getPreference('DEFAULT_GEDCOM')); 77ef2fd529SGreg Roach if ($tree) { 78ef2fd529SGreg Roach $stats = new Stats($tree); 798c2e8227SGreg Roach } else { 808c2e8227SGreg Roach $stats = new Stats($WT_TREE); 818c2e8227SGreg Roach } 828c2e8227SGreg Roach break; 838c2e8227SGreg Roach default: 84ef2fd529SGreg Roach $tree = Tree::findByName($gedcom); 85ef2fd529SGreg Roach if ($tree) { 86ef2fd529SGreg Roach $stats = new Stats($tree); 878c2e8227SGreg Roach } else { 888c2e8227SGreg Roach $stats = new Stats($WT_TREE); 898c2e8227SGreg Roach } 908c2e8227SGreg Roach break; 918c2e8227SGreg Roach } 928c2e8227SGreg Roach 938c2e8227SGreg Roach /* 948c2e8227SGreg Roach * Retrieve text, process embedded variables 958c2e8227SGreg Roach */ 968c2e8227SGreg Roach if (strpos($title, '#') !== false || strpos($html, '#') !== false) { 978c2e8227SGreg Roach $title = $stats->embedTags($title); 988c2e8227SGreg Roach $html = $stats->embedTags($html); 998c2e8227SGreg Roach } 1008c2e8227SGreg Roach 1018c2e8227SGreg Roach /* 1028c2e8227SGreg Roach * Start Of Output 1038c2e8227SGreg Roach */ 1048c2e8227SGreg Roach $id = $this->getName() . $block_id; 1058c2e8227SGreg Roach $class = $this->getName() . '_block'; 1064b9ff166SGreg Roach if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 10715d603e7SGreg Roach $title = FontAwesome::linkIcon('preferences', I18N::translate('Preferences'), ['class' => 'btn btn-link', 'href' => 'block_edit.php?block_id=' . $block_id . '&ged=' . $WT_TREE->getNameHtml() . '&ctype=' . $ctype]) . ' '; 1088c2e8227SGreg Roach } 1098c2e8227SGreg Roach 1108c2e8227SGreg Roach $content = $html; 1118c2e8227SGreg Roach 1128c2e8227SGreg Roach if ($show_timestamp) { 1133d7a8a4cSGreg Roach $content .= '<br>' . FunctionsDate::formatTimestamp($this->getBlockSetting($block_id, 'timestamp', WT_TIMESTAMP) + WT_TIMESTAMP_OFFSET); 1148c2e8227SGreg Roach } 1158c2e8227SGreg Roach 1168c2e8227SGreg Roach if ($template) { 1178c2e8227SGreg Roach return Theme::theme()->formatBlock($id, $title, $class, $content); 1188c2e8227SGreg Roach } else { 1198c2e8227SGreg Roach return $content; 1208c2e8227SGreg Roach } 1218c2e8227SGreg Roach } 1228c2e8227SGreg Roach 1238c2e8227SGreg Roach /** {@inheritdoc} */ 1248c2e8227SGreg Roach public function loadAjax() { 1258c2e8227SGreg Roach return false; 1268c2e8227SGreg Roach } 1278c2e8227SGreg Roach 1288c2e8227SGreg Roach /** {@inheritdoc} */ 1298c2e8227SGreg Roach public function isUserBlock() { 1308c2e8227SGreg Roach return true; 1318c2e8227SGreg Roach } 1328c2e8227SGreg Roach 1338c2e8227SGreg Roach /** {@inheritdoc} */ 1348c2e8227SGreg Roach public function isGedcomBlock() { 1358c2e8227SGreg Roach return true; 1368c2e8227SGreg Roach } 1378c2e8227SGreg Roach 13876692c8bSGreg Roach /** 13976692c8bSGreg Roach * An HTML form to edit block settings 14076692c8bSGreg Roach * 14176692c8bSGreg Roach * @param int $block_id 14276692c8bSGreg Roach */ 1438c2e8227SGreg Roach public function configureBlock($block_id) { 1444b9ff166SGreg Roach global $WT_TREE; 1454b9ff166SGreg Roach 1468c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 147c999a340SGreg Roach $languages = Filter::postArray('lang'); 148e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'gedcom', Filter::post('gedcom')); 149e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'title', Filter::post('title')); 150e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'html', Filter::post('html')); 151e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'show_timestamp', Filter::postBool('show_timestamp')); 152e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'timestamp', Filter::post('timestamp')); 153e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'languages', implode(',', $languages)); 1548c2e8227SGreg Roach } 1558c2e8227SGreg Roach 15613abd6f3SGreg Roach $templates = [ 1578c2e8227SGreg Roach I18N::translate('Keyword examples') => 1588c2e8227SGreg Roach '#getAllTagsTable#', 1598c2e8227SGreg Roach 1608c2e8227SGreg Roach I18N::translate('Narrative description') => 1618c2e8227SGreg Roach /* I18N: do not translate the #keywords# */ I18N::translate('This family tree was last updated on #gedcomUpdated#. There are #totalSurnames# surnames in this family tree. The earliest recorded event is the #firstEventType# of #firstEventName# in #firstEventYear#. The most recent event is the #lastEventType# of #lastEventName# in #lastEventYear#.<br><br>If you have any comments or feedback please contact #contactWebmaster#.'), 1628c2e8227SGreg Roach 1638c2e8227SGreg Roach I18N::translate('Statistics') => 1648c2e8227SGreg Roach '<div class="gedcom_stats"> 1658c2e8227SGreg Roach <span style="font-weight: bold;"><a href="index.php?command=gedcom">#gedcomTitle#</a></span><br> 1668c2e8227SGreg Roach ' . I18N::translate('This family tree was last updated on %s.', '#gedcomUpdated#') . ' 1678c2e8227SGreg Roach <table id="keywords"> 1688c2e8227SGreg Roach <tr> 169a86dd8b1SGreg Roach <td class="width20"> 1708c2e8227SGreg Roach <table cellspacing="1" cellpadding="0"> 1718c2e8227SGreg Roach <tr> 1728c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Individuals') . '</td> 173a86dd8b1SGreg Roach <td class="facts_value"><a href="indilist.php?surname_sublist=no">#totalIndividuals#</a></td> 1748c2e8227SGreg Roach </tr> 1758c2e8227SGreg Roach <tr> 1768c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Males') . '</td> 177a86dd8b1SGreg Roach <td class="facts_value">#totalSexMales#<br>#totalSexMalesPercentage#</td> 1788c2e8227SGreg Roach </tr> 1798c2e8227SGreg Roach <tr> 1808c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Females') . '</td> 181a86dd8b1SGreg Roach <td class="facts_value">#totalSexFemales#<br>#totalSexFemalesPercentage#</td> 1828c2e8227SGreg Roach </tr> 1838c2e8227SGreg Roach <tr> 1848c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Total surnames') . '</td> 185a86dd8b1SGreg Roach <td class="facts_value"><a href="indilist.php?show_all=yes&surname_sublist=yes&ged=' . $WT_TREE->getNameUrl() . '">#totalSurnames#</a></td> 1868c2e8227SGreg Roach </tr> 1878c2e8227SGreg Roach <tr> 1888c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Families') . '</td> 189a86dd8b1SGreg Roach <td class="facts_value"><a href="famlist.php?ged=' . $WT_TREE->getNameUrl() . '">#totalFamilies#</a></td> 1908c2e8227SGreg Roach </tr> 1918c2e8227SGreg Roach <tr> 1928c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Sources') . '</td> 193a86dd8b1SGreg Roach <td class="facts_value"><a href="sourcelist.php?ged=' . $WT_TREE->getNameUrl() . '">#totalSources#</a></td> 1948c2e8227SGreg Roach </tr> 1958c2e8227SGreg Roach <tr> 1968c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Media objects') . '</td> 197a86dd8b1SGreg Roach <td class="facts_value"><a href="medialist.php?ged=' . $WT_TREE->getNameUrl() . '">#totalMedia#</a></td> 1988c2e8227SGreg Roach </tr> 1998c2e8227SGreg Roach <tr> 2008c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Repositories') . '</td> 201a86dd8b1SGreg Roach <td class="facts_value"><a href="repolist.php?ged=' . $WT_TREE->getNameUrl() . '">#totalRepositories#</a></td> 2028c2e8227SGreg Roach </tr> 2038c2e8227SGreg Roach <tr> 2048c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Total events') . '</td> 205a86dd8b1SGreg Roach <td class="facts_value">#totalEvents#</td> 2068c2e8227SGreg Roach </tr> 2078c2e8227SGreg Roach <tr> 2088c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Total users') . '</td> 209a86dd8b1SGreg Roach <td class="facts_value">#totalUsers#</td> 2108c2e8227SGreg Roach </tr> 2118c2e8227SGreg Roach </table> 2128c2e8227SGreg Roach </td> 2138c2e8227SGreg Roach <td><br></td> 214a86dd8b1SGreg Roach <td> 2158c2e8227SGreg Roach <table cellspacing="1" cellpadding="0" border="0"> 2168c2e8227SGreg Roach <tr> 2178c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Earliest birth year') . '</td> 218a86dd8b1SGreg Roach <td class="facts_value">#firstBirthYear#</td> 2198c2e8227SGreg Roach <td class="facts_value">#firstBirth#</td> 2208c2e8227SGreg Roach </tr> 2218c2e8227SGreg Roach <tr> 2228c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Latest birth year') . '</td> 223a86dd8b1SGreg Roach <td class="facts_value">#lastBirthYear#</td> 2248c2e8227SGreg Roach <td class="facts_value">#lastBirth#</td> 2258c2e8227SGreg Roach </tr> 2268c2e8227SGreg Roach <tr> 2278c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Earliest death year') . '</td> 228a86dd8b1SGreg Roach <td class="facts_value">#firstDeathYear#</td> 2298c2e8227SGreg Roach <td class="facts_value">#firstDeath#</td> 2308c2e8227SGreg Roach </tr> 2318c2e8227SGreg Roach <tr> 2328c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Latest death year') . '</td> 233a86dd8b1SGreg Roach <td class="facts_value">#lastDeathYear#</td> 2348c2e8227SGreg Roach <td class="facts_value">#lastDeath#</td> 2358c2e8227SGreg Roach </tr> 2368c2e8227SGreg Roach <tr> 2378c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Individual who lived the longest') . '</td> 238a86dd8b1SGreg Roach <td class="facts_value">#longestLifeAge#</td> 2398c2e8227SGreg Roach <td class="facts_value">#longestLife#</td> 2408c2e8227SGreg Roach </tr> 2418c2e8227SGreg Roach <tr> 2428c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Average age at death') . '</td> 243a86dd8b1SGreg Roach <td class="facts_value">#averageLifespan#</td> 2448c2e8227SGreg Roach <td class="facts_value"></td> 2458c2e8227SGreg Roach </tr> 2468c2e8227SGreg Roach <tr> 2478c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Family with the most children') . '</td> 248a86dd8b1SGreg Roach <td class="facts_value">#largestFamilySize#</td> 2498c2e8227SGreg Roach <td class="facts_value">#largestFamily#</td> 2508c2e8227SGreg Roach </tr> 2518c2e8227SGreg Roach <tr> 2528c2e8227SGreg Roach <td class="facts_label">' . I18N::translate('Average number of children per family') . '</td> 253a86dd8b1SGreg Roach <td class="facts_value">#averageChildren#</td> 2548c2e8227SGreg Roach <td class="facts_value"></td> 2558c2e8227SGreg Roach </tr> 2568c2e8227SGreg Roach </table> 2578c2e8227SGreg Roach </td> 2588c2e8227SGreg Roach </tr> 2598c2e8227SGreg Roach </table><br> 2608c2e8227SGreg Roach <span style="font-weight: bold;">' . I18N::translate('Most common surnames') . '</span><br> 2618c2e8227SGreg Roach #commonSurnames# 262cbc1590aSGreg Roach </div>', 26313abd6f3SGreg Roach ]; 2648c2e8227SGreg Roach 265e2a378d3SGreg Roach $title = $this->getBlockSetting($block_id, 'title'); 266e2a378d3SGreg Roach $html = $this->getBlockSetting($block_id, 'html'); 26715d603e7SGreg Roach $gedcom = $this->getBlockSetting($block_id, 'gedcom', '__current__'); 268e2a378d3SGreg Roach $show_timestamp = $this->getBlockSetting($block_id, 'show_timestamp', '0'); 269e2a378d3SGreg Roach $languages = explode(',', $this->getBlockSetting($block_id, 'languages')); 2708c2e8227SGreg Roach 27115d603e7SGreg Roach ?> 27215d603e7SGreg Roach <div class="row form-group"> 27315d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="title"> 27415d603e7SGreg Roach <?= I18N::translate('Title') ?> 27515d603e7SGreg Roach </label> 27615d603e7SGreg Roach <div class="col-sm-9"> 27715d603e7SGreg Roach <input class="form-control" type="text" id="title" name="title" value="<?= Filter::escapeHtml($title) ?>"> 27815d603e7SGreg Roach </div> 27915d603e7SGreg Roach </div> 2808c2e8227SGreg Roach 28115d603e7SGreg Roach <div class="row form-group"> 28215d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="template"> 28315d603e7SGreg Roach <?= I18N::translate('Templates') ?> 28415d603e7SGreg Roach </label> 28515d603e7SGreg Roach <div class="col-sm-9"> 286*c87f84e3SGreg Roach <?= Bootstrap4::select([$html => I18N::translate('Custom')] + array_flip($templates), '', ['onchange' => 'this.form.html.value=this.options[this.selectedIndex].value; CKEDITOR.instances.html.setData(document.block.html.value);', 'id' => 'template']) ?> 28715d603e7SGreg Roach <p class="small text-muted"> 28815d603e7SGreg Roach <?= I18N::translate('To assist you in getting started with this block, we have created several standard templates. When you select one of these templates, the text area will contain a copy that you can then alter to suit your site’s requirements.') ?> 28915d603e7SGreg Roach </p> 29015d603e7SGreg Roach </div> 29115d603e7SGreg Roach </div> 2928c2e8227SGreg Roach 29315d603e7SGreg Roach <div class="row form-group"> 29415d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="gedcom"> 29515d603e7SGreg Roach <?= I18N::translate('Family tree') ?> 29615d603e7SGreg Roach </label> 29715d603e7SGreg Roach <div class="col-sm-9"> 29815d603e7SGreg Roach <?= Bootstrap4::select(['__current__' => I18N::translate('Current'), '__default__' => I18N::translate('Default')] + Tree::getNameList(), $gedcom, ['id' => 'gedcom', 'name' => 'gedcom']) ?> 29915d603e7SGreg Roach </div> 30015d603e7SGreg Roach </div> 3018c2e8227SGreg Roach 30215d603e7SGreg Roach <div class="row form-group"> 30315d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="html"> 30415d603e7SGreg Roach <?= I18N::translate('Content') ?> 30515d603e7SGreg Roach </label> 30615d603e7SGreg Roach <div class="col-sm-9"> 30715d603e7SGreg Roach <p> 30815d603e7SGreg Roach <?= I18N::translate('As well as using the toolbar to apply HTML formatting, you can insert database fields which are updated automatically. These special fields are marked with <b>#</b> characters. For example <b>#totalFamilies#</b> will be replaced with the actual number of families in the database. Advanced users may wish to apply CSS classes to their text, so that the formatting matches the currently selected theme.') ?> 30915d603e7SGreg Roach </p> 31015d603e7SGreg Roach </div> 31115d603e7SGreg Roach </div> 3128c2e8227SGreg Roach 31315d603e7SGreg Roach <div class="row form-group"> 31415d603e7SGreg Roach <textarea name="html" id="html" class="html-edit" rows="10"><?= Filter::escapeHtml($html) ?></textarea> 31515d603e7SGreg Roach </div> 3168c2e8227SGreg Roach 31715d603e7SGreg Roach <fieldset class="form-group"> 31815d603e7SGreg Roach <div class="row"> 31915d603e7SGreg Roach <legend class="form-control-legend col-sm-3"> 32015d603e7SGreg Roach <?= I18N::translate('Show the date and time of update') ?> 32115d603e7SGreg Roach </legend> 32215d603e7SGreg Roach <div class="col-sm-9"> 32315d603e7SGreg Roach <?= Bootstrap4::radioButtons('timestamp', FunctionsEdit::optionsNoYes(), $show_timestamp, true) ?> 32415d603e7SGreg Roach </div> 32515d603e7SGreg Roach </div> 32615d603e7SGreg Roach </fieldset> 32715d603e7SGreg Roach 32815d603e7SGreg Roach <fieldset class="form-group"> 32915d603e7SGreg Roach <div class="row"> 33015d603e7SGreg Roach <legend class="form-control-legend col-sm-3"> 33115d603e7SGreg Roach <?= I18N::translate('Show this block for which languages') ?> 33215d603e7SGreg Roach </legend> 33315d603e7SGreg Roach <div class="col-sm-9"> 33415d603e7SGreg Roach <?= FunctionsEdit::editLanguageCheckboxes('lang', $languages) ?> 33515d603e7SGreg Roach </div> 33615d603e7SGreg Roach </div> 33715d603e7SGreg Roach </fieldset> 33815d603e7SGreg Roach 33915d603e7SGreg Roach <?php 3408c2e8227SGreg Roach } 3418c2e8227SGreg Roach} 342