This repository has been archived by the owner on Mar 21, 2021. It is now read-only.
/
module.php
93 lines (80 loc) · 2.9 KB
/
module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2018 JustCarmen (http://www.justcarmen.nl)
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace JustCarmen\WebtreesAddOns\FancyGendex;
use Composer\Autoload\ClassLoader;
use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\Html;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
use Fisharebest\Webtrees\Tree;
use JustCarmen\WebtreesAddOns\FancyGendex\Template\AdminTemplate;
class FancyGendexModule extends AbstractModule implements ModuleConfigInterface {
const CUSTOM_VERSION = '2.0.0-dev';
const CUSTOM_WEBSITE = 'http://www.justcarmen.nl/fancy-modules/fancy-gendex/';
/** @var string location of the Fancy Gendex module files */
public $directory;
public function __construct() {
parent::__construct('fancy_gendex');
$this->directory = WT_MODULES_DIR . $this->getName();
// register the namespaces
$loader = new ClassLoader();
$loader->addPsr4('JustCarmen\\WebtreesAddOns\\FancyGendex\\', $this->directory . '/app');
$loader->register();
}
/**
* Get the module class.
*
* Class functions are called with $this inside the source directory.
*/
private function module() {
return new FancyGendexClass;
}
// Extend Module
public function getTitle(): string {
return /* I18N: Name of a module */ I18N::translate('Fancy Gendex');
}
// Extend Module
public function getDescription(): string {
return /* I18N: Description of the module */ I18N::translate('Generate GENDEX file for genealogical search engines.');
}
// Extend Module
public function modAction($mod_action) {
switch ($mod_action) {
case 'admin_config':
if (Filter::post('action') == 'save' && Filter::checkCsrf()) {
foreach (Tree::getAll() as $tree) {
$tree->setPreference('FANCY_GENDEX', Filter::postBool('FG' . $tree->getTreeId()));
}
$this->setPreference('FG_REPLACE_CHARS', Filter::postBool('FG_REPLACE_CHARS'));
$this->module()->createGendex();
}
$template = new AdminTemplate;
return $template->pageContent();
default:
http_response_code(404);
break;
}
}
/** {@inheritdoc} */
public function getConfigLink(): string {
return Html::url('module.php', [
'mod' => $this->getName(),
'mod_action' => 'admin_config',
]);
}
}
return new FancyGendexModule;