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