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 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Module; 21 22use Fisharebest\Webtrees\I18N; 23use Fisharebest\Webtrees\Services\UserService; 24use Fisharebest\Webtrees\User; 25use Psr\Http\Message\ServerRequestInterface; 26 27/** 28 * Class ContactsFooterModule - provide a link to the site owner. 29 */ 30class ContactsFooterModule extends AbstractModule implements ModuleFooterInterface 31{ 32 use ModuleFooterTrait; 33 34 /** 35 * @var UserService 36 */ 37 private $user_service; 38 39 /** 40 * Dependency injection. 41 * 42 * @param UserService $user_service 43 */ 44 public function __construct(UserService $user_service) 45 { 46 $this->user_service = $user_service; 47 } 48 49 /** 50 * How should this module be labelled on tabs, footers, etc.? 51 * 52 * @return string 53 */ 54 public function title(): string 55 { 56 /* I18N: Name of a module */ 57 return I18N::translate('Contact information'); 58 } 59 60 /** 61 * A sentence describing what this module does. 62 * 63 * @return string 64 */ 65 public function description(): string 66 { 67 /* I18N: Description of the “Contact information” module */ 68 return I18N::translate('A link to the site contacts.'); 69 } 70 71 /** 72 * The default position for this footer. It can be changed in the control panel. 73 * 74 * @return int 75 */ 76 public function defaultFooterOrder(): int 77 { 78 return 2; 79 } 80 81 /** 82 * A footer, to be added at the bottom of every page. 83 * 84 * @param ServerRequestInterface $request 85 * 86 * @return string 87 */ 88 public function getFooter(ServerRequestInterface $request): string 89 { 90 $tree = $request->getAttribute('tree'); 91 92 if ($tree === null) { 93 return ''; 94 } 95 96 $contact_user = $this->user_service->find((int) $tree->getPreference('CONTACT_USER_ID')); 97 $webmaster_user = $this->user_service->find((int) $tree->getPreference('WEBMASTER_USER_ID')); 98 99 if ($contact_user instanceof User && $contact_user === $webmaster_user) { 100 return view('modules/contact-links/footer', [ 101 'contact_links' => $this->contactLinkEverything($contact_user, $request), 102 ]); 103 } 104 105 if ($contact_user instanceof User && $webmaster_user instanceof User) { 106 return view('modules/contact-links/footer', [ 107 'contact_links' => $this->contactLinkGenealogy($contact_user, $request) . '<br>' . $this->contactLinkTechnical($webmaster_user, $request), 108 ]); 109 } 110 111 if ($contact_user instanceof User) { 112 return view('modules/contact-links/footer', [ 113 'contact_links' => $this->contactLinkGenealogy($contact_user, $request), 114 ]); 115 } 116 117 if ($webmaster_user instanceof User) { 118 return view('modules/contact-links/footer', [ 119 'contact_links' => $this->contactLinkTechnical($webmaster_user, $request), 120 ]); 121 } 122 123 return ''; 124 } 125 126 /** 127 * Create contact link for both technical and genealogy support. 128 * 129 * @param User $user 130 * @param ServerRequestInterface $request 131 * 132 * @return string 133 */ 134 public function contactLinkEverything(User $user, ServerRequestInterface $request): string 135 { 136 return I18N::translate('For technical support or genealogy questions contact %s.', $this->user_service->contactLink($user, $request)); 137 } 138 139 /** 140 * Create contact link for genealogy support. 141 * 142 * @param User $user 143 * @param ServerRequestInterface $request 144 * 145 * @return string 146 */ 147 public function contactLinkGenealogy(User $user, ServerRequestInterface $request): string 148 { 149 return I18N::translate('For help with genealogy questions contact %s.', $this->user_service->contactLink($user, $request)); 150 } 151 152 /** 153 * Create contact link for technical support. 154 * 155 * @param User $user 156 * @param ServerRequestInterface $request 157 * 158 * @return string 159 */ 160 public function contactLinkTechnical(User $user, ServerRequestInterface $request): string 161 { 162 return I18N::translate('For technical support and information contact %s.', $this->user_service->contactLink($user, $request)); 163 } 164} 165