[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/config/core/Setting/ -> SettingEmail.php (source)

   1  <?php
   2  
   3  namespace dokuwiki\plugin\config\core\Setting;
   4  
   5  /**
   6   * Class setting_email
   7   */
   8  class SettingEmail extends SettingString {
   9      protected $multiple = false;
  10      protected $placeholders = false;
  11  
  12      /** @inheritdoc */
  13      public function update($input) {
  14          if(is_null($input)) return false;
  15          if($this->isProtected()) return false;
  16  
  17          $value = is_null($this->local) ? $this->default : $this->local;
  18          if($value == $input) return false;
  19          if($input === '') {
  20              $this->local = $input;
  21              return true;
  22          }
  23          $mail = $input;
  24  
  25          if($this->placeholders) {
  26              // replace variables with pseudo values
  27              $mail = str_replace('@USER@', 'joe', $mail);
  28              $mail = str_replace('@NAME@', 'Joe Schmoe', $mail);
  29              $mail = str_replace('@MAIL@', 'joe@example.com', $mail);
  30          }
  31  
  32          // multiple mail addresses?
  33          if($this->multiple) {
  34              $mails = array_filter(array_map('trim', explode(',', $mail)));
  35          } else {
  36              $mails = array($mail);
  37          }
  38  
  39          // check them all
  40          foreach($mails as $mail) {
  41              // only check the address part
  42              if(preg_match('#(.*?)<(.*?)>#', $mail, $matches)) {
  43                  $addr = $matches[2];
  44              } else {
  45                  $addr = $mail;
  46              }
  47  
  48              if(!mail_isvalid($addr)) {
  49                  $this->error = true;
  50                  $this->input = $input;
  51                  return false;
  52              }
  53          }
  54  
  55          $this->local = $input;
  56          return true;
  57      }
  58  }