1<?php 2/** 3 * Action Component 4 * Add a button in the edit toolbar 5 * 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author Nicolas GERARD 8 */ 9 10use ComboStrap\Dimension; 11use ComboStrap\Identity; 12use ComboStrap\LogUtility; 13use ComboStrap\Site; 14use ComboStrap\Snippet; 15use ComboStrap\TagAttributes; 16use dokuwiki\Menu\Item\Resendpwd; 17 18if (!defined('DOKU_INC')) die(); 19require_once(__DIR__ . '/../class/PluginUtility.php'); 20 21 22class action_plugin_combo_resend extends DokuWiki_Action_Plugin 23{ 24 25 const CANONICAL = "resend"; 26 const FORM_RESEND_PWD_CLASS = "form-" .self::CANONICAL; 27 const CONF_ENABLE_RESEND_PWD_FORM = "enableResendPwdForm"; 28 29 /** 30 * @return string 31 */ 32 public static function getResendPasswordParagraphWithLinkToFormPage() 33 { 34 /** 35 * Resend pwd 36 */ 37 $resendPwdHtml = ""; 38 if (actionOK('resendpwd')) { 39 $resendPwLink = (new Resendpwd())->asHtmlLink('', false); 40 global $lang; 41 $resentText = $lang['pwdforget']; 42 $resendPwdHtml = <<<EOF 43<p class="resendpwd">$resentText : $resendPwLink</p> 44EOF; 45 } 46 return $resendPwdHtml; 47 } 48 49 50 function register(Doku_Event_Handler $controller) 51 { 52 /** 53 * To modify the form and add class 54 * 55 * Deprecated object passed by the event but still in use 56 * https://www.dokuwiki.org/devel:event:html_resendpwdform_output 57 */ 58 $controller->register_hook('HTML_RESENDPWDFORM_OUTPUT', 'BEFORE', $this, 'handle_resendpwd_html', array()); 59 60 /** 61 * Event using the new object not found anywhere 62 * 63 * https://www.dokuwiki.org/devel:event:form_resendpwd_output 64 */ 65 66 67 } 68 69 function handle_resendpwd_html(&$event, $param) 70 { 71 72 /** 73 * The Login page is created via buffer 74 * We print before the forms 75 * to avoid a FOUC 76 */ 77 $loginCss = Snippet::createCssSnippet(self::CANONICAL); 78 $content = $loginCss->getContent(); 79 $class = $loginCss->getClass(); 80 $cssHtml = <<<EOF 81<style class="$class"> 82$content 83</style> 84EOF; 85 print $cssHtml; 86 87 88 /** 89 * @var Doku_Form $form 90 */ 91 $form = &$event->data; 92 $class = &$form->params["class"]; 93 if (isset($class)) { 94 $class = $class . " " . self::FORM_RESEND_PWD_CLASS; 95 } else { 96 $class = self::FORM_RESEND_PWD_CLASS; 97 } 98 $newFormContent = []; 99 100 101 /** 102 * Header (Logo / Title) 103 */ 104 $newFormContent[] = Identity::getHeaderHTML($form, self::FORM_RESEND_PWD_CLASS); 105 106 /** 107 * Form Attributes 108 * 109 */ 110 foreach ($form->_content as $field) { 111 if (!is_array($field)) { 112 continue; 113 } 114 $fieldName = $field["name"]; 115 if ($fieldName == null) { 116 // this is not an input field 117 if ($field["type"] == "submit") { 118 /** 119 * This is important to keep the submit element intact 120 * for forms integration such as captcha 121 * The search the submit button to insert before it 122 */ 123 $classes = "btn btn-primary btn-block"; 124 if (isset($field["class"])) { 125 $field["class"] = $field["class"] . " " . $classes; 126 } else { 127 $field["class"] = $classes; 128 } 129 $newFormContent[] = $field; 130 } 131 continue; 132 } 133 switch ($fieldName) { 134 case "login": 135 $loginText = $field["_text"]; 136 $loginValue = $field["value"]; 137 $loginHTML=<<<EOF 138<div class="form-floating"> 139 <input type="text" id="inputUserName" class="form-control" placeholder="$loginText" required="required" autofocus="" name="u" value="$loginValue"> 140 <label for="inputUserName">$loginText</label> 141</div> 142EOF; 143 $newFormContent[] = $loginHTML; 144 break; 145 default: 146 LogUtility::msg("The register field name($fieldName) is unknown", LogUtility::LVL_MSG_ERROR, \ComboStrap\Identity::CANONICAL); 147 148 149 } 150 } 151 152 153 154 155 /** 156 * Register and Login HTML paragraph 157 */ 158 $registerHtml = action_plugin_combo_registration::getRegisterLinkAndParagraph(); 159 if (!empty($registerHtml)) { 160 $newFormContent[] = $registerHtml; 161 } 162 $loginLinkToHtmlForm = action_plugin_combo_login::getLoginParagraphWithLinkToFormPage(); 163 if (!empty($loginLinkToHtmlForm)) { 164 $newFormContent[] = $loginLinkToHtmlForm; 165 } 166 167 /** 168 * Update 169 */ 170 $form->_content = $newFormContent; 171 172 return true; 173 174 175 } 176 177 178} 179 180