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