xref: /webtrees/app/Module/GoogleWebmasterToolsModule.php (revision ba1d7494e9648df5a87aaa3fece3e098e5ce26b1)
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     * Is this a tracker, as opposed to just a site-verification.
54     *
55     * @return bool
56     */
57    public function isTracker(): bool
58    {
59        return false;
60    }
61
62    /**
63     * Form fields to edit the parameters.
64     *
65     * @return string
66     */
67    public function analyticsFormFields(): string
68    {
69        return view('modules/google-webmaster-tools/form', $this->analyticsParameters());
70    }
71
72    /**
73     * Home page for the service.
74     *
75     * @return string
76     */
77    public function externalUrl(): string
78    {
79        return 'https://www.google.com/webmasters';
80    }
81
82    /**
83     * The parameters that need to be embedded in the snippet.
84     *
85     * @return string[]
86     */
87    public function analyticsParameters(): array
88    {
89        return [
90            'GOOGLE_WEBMASTER_ID' => $this->getPreference('GOOGLE_WEBMASTER_ID')
91        ];
92    }
93
94    /**
95     * Embed placeholders in the snippet.
96     *
97     * @param string[] $parameters
98     *
99     * @return string
100     */
101    public function analyticsSnippet(array $parameters): string
102    {
103        return view('modules/google-webmaster-tools/snippet', $parameters);
104    }
105
106    /**
107     * Raw content, to be added at the end of the <head> element.
108     * Typically, this will be <link> and <meta> elements.
109     *
110     * @return string
111     */
112    public function headContent(): string
113    {
114        if ($this->analyticsCanShow()) {
115            return $this->analyticsSnippet($this->analyticsParameters());
116        }
117
118        return '';
119    }
120}
121