xref: /webtrees/app/Module/GoogleWebmasterToolsModule.php (revision d11be7027e34e3121be11cc025421873364403f9)
137eb8894SGreg Roach<?php
23976b470SGreg Roach
337eb8894SGreg Roach/**
437eb8894SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
637eb8894SGreg Roach * This program is free software: you can redistribute it and/or modify
737eb8894SGreg Roach * it under the terms of the GNU General Public License as published by
837eb8894SGreg Roach * the Free Software Foundation, either version 3 of the License, or
937eb8894SGreg Roach * (at your option) any later version.
1037eb8894SGreg Roach * This program is distributed in the hope that it will be useful,
1137eb8894SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1237eb8894SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1337eb8894SGreg Roach * GNU General Public License for more details.
1437eb8894SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
1637eb8894SGreg Roach */
17fcfa147eSGreg Roach
1837eb8894SGreg Roachdeclare(strict_types=1);
1937eb8894SGreg Roach
2037eb8894SGreg Roachnamespace Fisharebest\Webtrees\Module;
2137eb8894SGreg Roach
220ad7d82dSGreg Roachuse Fisharebest\Webtrees\I18N;
230ad7d82dSGreg Roach
2437eb8894SGreg Roach/**
2537eb8894SGreg Roach * Class GoogleWebmasterToolsModule - add support for Google webmaster tools.
2637eb8894SGreg Roach */
27abafa13cSGreg Roachclass GoogleWebmasterToolsModule extends AbstractModule implements ModuleAnalyticsInterface, ModuleConfigInterface, ModuleExternalUrlInterface, ModuleGlobalInterface
2837eb8894SGreg Roach{
2937eb8894SGreg Roach    use ModuleAnalyticsTrait;
308e5c5efeSGreg Roach    use ModuleConfigTrait;
318e5c5efeSGreg Roach    use ModuleExternalUrlTrait;
32abafa13cSGreg Roach    use ModuleGlobalTrait;
3337eb8894SGreg Roach
3437eb8894SGreg Roach    /**
350cfd6963SGreg Roach     * How should this module be identified in the control panel, etc.?
3637eb8894SGreg Roach     *
3737eb8894SGreg Roach     * @return string
3837eb8894SGreg Roach     */
395699f0a8SGreg Roach    public function title(): string
405699f0a8SGreg Roach    {
410ad7d82dSGreg Roach        return I18N::translate('Google™ webmaster tools');
4237eb8894SGreg Roach    }
4337eb8894SGreg Roach
4437eb8894SGreg Roach    /**
45abafa13cSGreg Roach     * Should this module be enabled when it is first installed?
46abafa13cSGreg Roach     *
47abafa13cSGreg Roach     * @return bool
48abafa13cSGreg Roach     */
49abafa13cSGreg Roach    public function isEnabledByDefault(): bool
50abafa13cSGreg Roach    {
51abafa13cSGreg Roach        return false;
52abafa13cSGreg Roach    }
53abafa13cSGreg Roach
54abafa13cSGreg Roach    /**
55b3a775f6SGreg Roach     * Is this a tracker, as opposed to just a site-verification.
56b3a775f6SGreg Roach     *
57b3a775f6SGreg Roach     * @return bool
58b3a775f6SGreg Roach     */
59b3a775f6SGreg Roach    public function isTracker(): bool
60b3a775f6SGreg Roach    {
61b3a775f6SGreg Roach        return false;
62b3a775f6SGreg Roach    }
63b3a775f6SGreg Roach
64b3a775f6SGreg Roach    /**
6537eb8894SGreg Roach     * Form fields to edit the parameters.
6637eb8894SGreg Roach     *
6737eb8894SGreg Roach     * @return string
6837eb8894SGreg Roach     */
6937eb8894SGreg Roach    public function analyticsFormFields(): string
7037eb8894SGreg Roach    {
718e5c5efeSGreg Roach        return view('modules/google-webmaster-tools/form', $this->analyticsParameters());
7237eb8894SGreg Roach    }
7337eb8894SGreg Roach
7437eb8894SGreg Roach    /**
7537eb8894SGreg Roach     * Home page for the service.
7637eb8894SGreg Roach     *
7737eb8894SGreg Roach     * @return string
7837eb8894SGreg Roach     */
798e5c5efeSGreg Roach    public function externalUrl(): string
8037eb8894SGreg Roach    {
8137eb8894SGreg Roach        return 'https://www.google.com/webmasters';
8237eb8894SGreg Roach    }
8337eb8894SGreg Roach
8437eb8894SGreg Roach    /**
8537eb8894SGreg Roach     * The parameters that need to be embedded in the snippet.
8637eb8894SGreg Roach     *
8724f2a3afSGreg Roach     * @return array<string>
8837eb8894SGreg Roach     */
8937eb8894SGreg Roach    public function analyticsParameters(): array
9037eb8894SGreg Roach    {
9137eb8894SGreg Roach        return [
9237eb8894SGreg Roach            'GOOGLE_WEBMASTER_ID' => $this->getPreference('GOOGLE_WEBMASTER_ID')
9337eb8894SGreg Roach        ];
9437eb8894SGreg Roach    }
9537eb8894SGreg Roach
9637eb8894SGreg Roach    /**
9737eb8894SGreg Roach     * Embed placeholders in the snippet.
9837eb8894SGreg Roach     *
9909482a55SGreg Roach     * @param array<string> $parameters
10037eb8894SGreg Roach     *
10137eb8894SGreg Roach     * @return string
10237eb8894SGreg Roach     */
10337eb8894SGreg Roach    public function analyticsSnippet(array $parameters): string
10437eb8894SGreg Roach    {
1058e5c5efeSGreg Roach        return view('modules/google-webmaster-tools/snippet', $parameters);
10637eb8894SGreg Roach    }
107abafa13cSGreg Roach
108abafa13cSGreg Roach    /**
109abafa13cSGreg Roach     * Raw content, to be added at the end of the <head> element.
110abafa13cSGreg Roach     * Typically, this will be <link> and <meta> elements.
111abafa13cSGreg Roach     *
112abafa13cSGreg Roach     * @return string
113abafa13cSGreg Roach     */
114abafa13cSGreg Roach    public function headContent(): string
115abafa13cSGreg Roach    {
116abafa13cSGreg Roach        if ($this->analyticsCanShow()) {
117abafa13cSGreg Roach            return $this->analyticsSnippet($this->analyticsParameters());
118abafa13cSGreg Roach        }
119abafa13cSGreg Roach
120abafa13cSGreg Roach        return '';
121abafa13cSGreg Roach    }
12237eb8894SGreg Roach}
123