1<?php
2
3namespace dokuwiki\plugin\struct\types;
4
5use dokuwiki\plugin\struct\meta\ValidationException;
6
7class Mail extends Text
8{
9    protected $config = [
10        'prefix' => '',
11        'postfix' => ''
12    ];
13
14    /**
15     * Output the stored data
16     *
17     * @param string|int $value the value stored in the database
18     * @param \Doku_Renderer $R the renderer currently used to render the data
19     * @param string $mode The mode the output is rendered in (eg. XHTML)
20     * @return bool true if $mode could be satisfied
21     */
22    public function renderValue($value, \Doku_Renderer $R, $mode)
23    {
24        $mail = $this->config['prefix'] . $value . $this->config['postfix'];
25        $R->emaillink($mail);
26        return true;
27    }
28
29    /**
30     * Validate
31     *
32     * @param int|string $rawvalue
33     * @return int|string
34     */
35    public function validate($rawvalue)
36    {
37        $rawvalue = parent::validate($rawvalue);
38
39        $mail = $this->config['prefix'] . $rawvalue . $this->config['postfix'];
40        if (!mail_isvalid($mail)) {
41            throw new ValidationException('Mail invalid', $mail);
42        }
43
44        return $rawvalue;
45    }
46}
47