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