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