1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17declare(strict_types=1); 18 19namespace Fisharebest\Webtrees\Module; 20 21use Fisharebest\Webtrees\I18N; 22use Fisharebest\Webtrees\Services\UserService; 23use Fisharebest\Webtrees\Tree; 24use Fisharebest\Webtrees\User; 25use InvalidArgumentException; 26use Psr\Http\Message\ServerRequestInterface; 27use function assert; 28 29/** 30 * Class ContactsFooterModule - provide a link to the site owner. 31 */ 32class ContactsFooterModule extends AbstractModule implements ModuleFooterInterface 33{ 34 use ModuleFooterTrait; 35 36 /** 37 * @var UserService 38 */ 39 private $user_service; 40 41 /** 42 * Dependency injection. 43 * 44 * @param UserService $user_service 45 */ 46 public function __construct(UserService $user_service) 47 { 48 $this->user_service = $user_service; 49 } 50 51 /** 52 * How should this module be labelled on tabs, footers, etc.? 53 * 54 * @return string 55 */ 56 public function title(): string 57 { 58 /* I18N: Name of a module */ 59 return I18N::translate('Contact information'); 60 } 61 62 /** 63 * A sentence describing what this module does. 64 * 65 * @return string 66 */ 67 public function description(): string 68 { 69 /* I18N: Description of the “Hit counters” module */ 70 return I18N::translate('A link to the site contacts.'); 71 } 72 73 /** 74 * The default position for this footer. It can be changed in the control panel. 75 * 76 * @return int 77 */ 78 public function defaultFooterOrder(): int 79 { 80 return 2; 81 } 82 83 /** 84 * A footer, to be added at the bottom of every page. 85 * 86 * @param ServerRequestInterface $request 87 * 88 * @return string 89 */ 90 public function getFooter(ServerRequestInterface $request): string 91 { 92 $tree = $request->getAttribute('tree'); 93 94 if ($tree === null) { 95 return ''; 96 } 97 98 $contact_user = $this->user_service->find((int) $tree->getPreference('CONTACT_USER_ID')); 99 $webmaster_user = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); 100 101 if ($contact_user instanceof User && $contact_user === $webmaster_user) { 102 return view('modules/contact-links/footer', [ 103 'contact_links' => $this->contactLinkEverything($contact_user, $request), 104 ]); 105 } 106 107 if ($contact_user instanceof User && $webmaster_user instanceof User) { 108 return view('modules/contact-links/footer', [ 109 'contact_links' => $this->contactLinkGenealogy($contact_user, $request) . '<br>' . $this->contactLinkTechnical($webmaster_user, $request), 110 ]); 111 } 112 113 if ($contact_user instanceof User) { 114 return view('modules/contact-links/footer', [ 115 'contact_links' => $this->contactLinkGenealogy($contact_user, $request), 116 ]); 117 } 118 119 if ($webmaster_user instanceof User) { 120 return view('modules/contact-links/footer', [ 121 'contact_links' => $this->contactLinkTechnical($webmaster_user, $request), 122 ]); 123 } 124 125 return ''; 126 } 127 128 /** 129 * Create contact link for both technical and genealogy support. 130 * 131 * @param User $user 132 * @param ServerRequestInterface $request 133 * 134 * @return string 135 */ 136 public function contactLinkEverything(User $user, ServerRequestInterface $request): string 137 { 138 return I18N::translate('For technical support or genealogy questions contact %s.', $this->user_service->contactLink($user, $request)); 139 } 140 141 /** 142 * Create contact link for genealogy support. 143 * 144 * @param User $user 145 * @param ServerRequestInterface $request 146 * 147 * @return string 148 */ 149 public function contactLinkGenealogy(User $user, ServerRequestInterface $request): string 150 { 151 return I18N::translate('For help with genealogy questions contact %s.', $this->user_service->contactLink($user, $request)); 152 } 153 154 /** 155 * Create contact link for technical support. 156 * 157 * @param User $user 158 * @param ServerRequestInterface $request 159 * 160 * @return string 161 */ 162 public function contactLinkTechnical(User $user, ServerRequestInterface $request): string 163 { 164 return I18N::translate('For technical support and information contact %s.', $this->user_service->contactLink($user, $request)); 165 } 166} 167