1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\Module; 21 22use Fisharebest\Webtrees\I18N; 23 24/** 25 * Class GoogleWebmasterToolsModule - add support for Google webmaster tools. 26 */ 27class GoogleWebmasterToolsModule extends AbstractModule implements ModuleAnalyticsInterface, ModuleConfigInterface, ModuleExternalUrlInterface, ModuleGlobalInterface 28{ 29 use ModuleAnalyticsTrait; 30 use ModuleConfigTrait; 31 use ModuleExternalUrlTrait; 32 use ModuleGlobalTrait; 33 34 /** 35 * How should this module be identified in the control panel, etc.? 36 * 37 * @return string 38 */ 39 public function title(): string 40 { 41 return I18N::translate('Google™ webmaster tools'); 42 } 43 44 /** 45 * Should this module be enabled when it is first installed? 46 * 47 * @return bool 48 */ 49 public function isEnabledByDefault(): bool 50 { 51 return false; 52 } 53 54 /** 55 * Is this a tracker, as opposed to just a site-verification. 56 * 57 * @return bool 58 */ 59 public function isTracker(): bool 60 { 61 return false; 62 } 63 64 /** 65 * Form fields to edit the parameters. 66 * 67 * @return string 68 */ 69 public function analyticsFormFields(): string 70 { 71 return view('modules/google-webmaster-tools/form', $this->analyticsParameters()); 72 } 73 74 /** 75 * Home page for the service. 76 * 77 * @return string 78 */ 79 public function externalUrl(): string 80 { 81 return 'https://www.google.com/webmasters'; 82 } 83 84 /** 85 * The parameters that need to be embedded in the snippet. 86 * 87 * @return string[] 88 */ 89 public function analyticsParameters(): array 90 { 91 return [ 92 'GOOGLE_WEBMASTER_ID' => $this->getPreference('GOOGLE_WEBMASTER_ID') 93 ]; 94 } 95 96 /** 97 * Embed placeholders in the snippet. 98 * 99 * @param string[] $parameters 100 * 101 * @return string 102 */ 103 public function analyticsSnippet(array $parameters): string 104 { 105 return view('modules/google-webmaster-tools/snippet', $parameters); 106 } 107 108 /** 109 * Raw content, to be added at the end of the <head> element. 110 * Typically, this will be <link> and <meta> elements. 111 * 112 * @return string 113 */ 114 public function headContent(): string 115 { 116 if ($this->analyticsCanShow()) { 117 return $this->analyticsSnippet($this->analyticsParameters()); 118 } 119 120 return ''; 121 } 122} 123