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