1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2019 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16declare(strict_types=1); 17 18namespace Fisharebest\Webtrees\Module; 19 20use Fisharebest\Webtrees\Auth; 21use Fisharebest\Webtrees\I18N; 22use Fisharebest\Webtrees\Site; 23use Fisharebest\Webtrees\Tree; 24use Illuminate\Support\Str; 25 26/** 27 * Class LoginBlockModule 28 */ 29class LoginBlockModule extends AbstractModule implements ModuleBlockInterface 30{ 31 use ModuleBlockTrait; 32 33 /** 34 * How should this module be identified in the control panel, etc.? 35 * 36 * @return string 37 */ 38 public function title(): string 39 { 40 /* I18N: Name of a module */ 41 return I18N::translate('Sign in'); 42 } 43 44 /** 45 * A sentence describing what this module does. 46 * 47 * @return string 48 */ 49 public function description(): string 50 { 51 /* I18N: Description of the “Sign in” module */ 52 return I18N::translate('An alternative way to sign in and sign out.'); 53 } 54 55 /** 56 * Generate the HTML content of this block. 57 * 58 * @param Tree $tree 59 * @param int $block_id 60 * @param string $context 61 * @param string[] $config 62 * 63 * @return string 64 */ 65 public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string 66 { 67 if (Auth::check()) { 68 $title = I18N::translate('Sign out'); 69 $content = view('modules/login_block/sign-out', [ 70 'user' => Auth::user(), 71 ]); 72 } else { 73 $title = I18N::translate('Sign in'); 74 $content = view('modules/login_block/sign-in', [ 75 'allow_register' => (bool) Site::getPreference('USE_REGISTRATION_MODULE'), 76 'url' => route('tree-page', ['ged' => $tree->name()]), 77 ]); 78 } 79 80 if ($context !== self::CONTEXT_EMBED) { 81 return view('modules/block-template', [ 82 'block' => Str::kebab($this->name()), 83 'id' => $block_id, 84 'config_url' => '', 85 'title' => $title, 86 'content' => $content, 87 ]); 88 } 89 90 return $content; 91 } 92 93 /** 94 * Should this block load asynchronously using AJAX? 95 * 96 * Simple blocks are faster in-line, more complex ones can be loaded later. 97 * 98 * @return bool 99 */ 100 public function loadAjax(): bool 101 { 102 return false; 103 } 104 105 /** 106 * Can this block be shown on the user’s home page? 107 * 108 * @return bool 109 */ 110 public function isUserBlock(): bool 111 { 112 return true; 113 } 114 115 /** 116 * Can this block be shown on the tree’s home page? 117 * 118 * @return bool 119 */ 120 public function isTreeBlock(): bool 121 { 122 return true; 123 } 124} 125