xref: /webtrees/app/Module/LoginBlockModule.php (revision a9430be8fd65a5fa4bf77ffdf439873a82f51e13)
1e2a378d3SGreg Roach<?php
2e2a378d3SGreg Roach/**
3e2a378d3SGreg Roach * webtrees: online genealogy
46bdf7674SGreg Roach * Copyright (C) 2017 webtrees development team
5e2a378d3SGreg Roach * This program is free software: you can redistribute it and/or modify
6e2a378d3SGreg Roach * it under the terms of the GNU General Public License as published by
7e2a378d3SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8e2a378d3SGreg Roach * (at your option) any later version.
9e2a378d3SGreg Roach * This program is distributed in the hope that it will be useful,
10e2a378d3SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11e2a378d3SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12e2a378d3SGreg Roach * GNU General Public License for more details.
13e2a378d3SGreg Roach * You should have received a copy of the GNU General Public License
14e2a378d3SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15e2a378d3SGreg Roach */
1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module;
1776692c8bSGreg Roach
180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Site;
219c6524dcSGreg Roachuse Fisharebest\Webtrees\View;
22e2a378d3SGreg Roach
23e2a378d3SGreg Roach/**
24e2a378d3SGreg Roach * Class LoginBlockModule
25e2a378d3SGreg Roach */
26e2a378d3SGreg Roachclass LoginBlockModule extends AbstractModule implements ModuleBlockInterface {
27e2a378d3SGreg Roach	/** {@inheritdoc} */
28e2a378d3SGreg Roach	public function getTitle() {
29cdc90107SGreg Roach		return /* I18N: Name of a module */ I18N::translate('Sign in');
30e2a378d3SGreg Roach	}
31e2a378d3SGreg Roach
32e2a378d3SGreg Roach	/** {@inheritdoc} */
33e2a378d3SGreg Roach	public function getDescription() {
34cdc90107SGreg Roach		return /* I18N: Description of the “Sign in” module */ I18N::translate('An alternative way to sign in and sign out.');
35e2a378d3SGreg Roach	}
36e2a378d3SGreg Roach
3776692c8bSGreg Roach	/**
3876692c8bSGreg Roach	 * Generate the HTML content of this block.
3976692c8bSGreg Roach	 *
4076692c8bSGreg Roach	 * @param int      $block_id
4176692c8bSGreg Roach	 * @param bool     $template
42727f238cSGreg Roach	 * @param string[] $cfg
4376692c8bSGreg Roach	 *
4476692c8bSGreg Roach	 * @return string
4576692c8bSGreg Roach	 */
46*a9430be8SGreg Roach	public function getBlock($block_id, $template = true, $cfg = []): string {
47e2a378d3SGreg Roach		if (Auth::check()) {
48cdc90107SGreg Roach			$title   = I18N::translate('Sign out');
49cf30a8edSGreg Roach			$content = View::make('blocks/sign-out', [
50cf30a8edSGreg Roach				'user' => Auth::user(),
51cf30a8edSGreg Roach				]);
52e2a378d3SGreg Roach		} else {
53cdc90107SGreg Roach			$title   = I18N::translate('Sign in');
54cf30a8edSGreg Roach			$content = View::make('blocks/sign-in', [
55cf30a8edSGreg Roach				'allow_register' => (bool) Site::getPreference('USE_REGISTRATION_MODULE')
56cf30a8edSGreg Roach			]);
57e2a378d3SGreg Roach		}
58e2a378d3SGreg Roach
59e2a378d3SGreg Roach		if ($template) {
609c6524dcSGreg Roach			return View::make('blocks/template', [
619c6524dcSGreg Roach				'block'      => str_replace('_', '-', $this->getName()),
629c6524dcSGreg Roach				'id'         => $block_id,
639c6524dcSGreg Roach				'config_url' => '',
64cf30a8edSGreg Roach				'title'      => $title,
659c6524dcSGreg Roach				'content'    => $content,
669c6524dcSGreg Roach			]);
67e2a378d3SGreg Roach		} else {
68e2a378d3SGreg Roach			return $content;
69e2a378d3SGreg Roach		}
70e2a378d3SGreg Roach	}
71e2a378d3SGreg Roach
72e2a378d3SGreg Roach	/** {@inheritdoc} */
73*a9430be8SGreg Roach	public function loadAjax(): bool {
74e2a378d3SGreg Roach		return false;
75e2a378d3SGreg Roach	}
76e2a378d3SGreg Roach
77e2a378d3SGreg Roach	/** {@inheritdoc} */
78*a9430be8SGreg Roach	public function isUserBlock(): bool {
79e2a378d3SGreg Roach		return true;
80e2a378d3SGreg Roach	}
81e2a378d3SGreg Roach
82e2a378d3SGreg Roach	/** {@inheritdoc} */
83*a9430be8SGreg Roach	public function isGedcomBlock(): bool {
84e2a378d3SGreg Roach		return true;
85e2a378d3SGreg Roach	}
86e2a378d3SGreg Roach
8776692c8bSGreg Roach	/**
8876692c8bSGreg Roach	 * An HTML form to edit block settings
8976692c8bSGreg Roach	 *
9076692c8bSGreg Roach	 * @param int $block_id
91*a9430be8SGreg Roach	 *
92*a9430be8SGreg Roach	 * @return void
9376692c8bSGreg Roach	 */
94*a9430be8SGreg Roach	public function configureBlock($block_id): void {
95e2a378d3SGreg Roach	}
96e2a378d3SGreg Roach}
97