Esempio n. 1
0
 /**
  * テンプレートから内容を取得しセットする
  * 
  * テンプレートサンプル
  * <mail>
  * <from address="*****@*****.**" name="tokushima" />
  * <subject>メールのタイトル</subject>
  * <body>
  * メールの本文
  * </body>
  * </mail>
  * 
  * @param string $template_path テンプレートファイルパス
  * @param mixed{} $vars テンプレートへ渡す変数
  * @return $this
  */
 public function set_template($template_path, $vars = array())
 {
     $resource_path = empty($this->resource_path) ? \org\rhaco\Conf::get('resource_path', \org\rhaco\io\File::resource_path('mail')) : $this->resource_path;
     $template_path = \org\rhaco\net\Path::absolute($resource_path, $template_path);
     if (!is_file($template_path)) {
         throw new \InvalidArgumentException($template_path . ' not found');
     }
     if (\org\rhaco\Xml::set($xml, file_get_contents($template_path), 'mail')) {
         $from = $xml->f('from');
         if ($from !== null) {
             $this->from($from->in_attr('address'), $from->in_attr('name'));
         }
         foreach ($xml->in('to') as $to) {
             $this->to($to->in_attr('address'), $to->in_attr('name'));
         }
         $return_path = $xml->f('return_path');
         if ($return_path !== null) {
             $this->return_path($return_path->in_attr('address'));
         }
         $notification = $xml->f('notification');
         if ($notification !== null) {
             $this->notification($notification->in_attr('address'));
         }
         $reply_to = $xml->f('reply_to');
         if ($reply_to !== null) {
             $this->reply_to($reply_to->in_attr('address'));
         }
         $errors_to = $xml->f('errors_to');
         if ($errors_to !== null) {
             $this->errors_to($errors_to->in_attr('address'));
         }
         $subject = trim(str_replace(array("\r\n", "\r", "\n"), '', $xml->f('subject.value()')));
         $body = $xml->f('body.value()');
         $template = new \org\rhaco\Template();
         $template->cp($vars);
         $template->vars('t', new \org\rhaco\flow\module\Helper());
         $this->subject($template->get($subject));
         $this->message(\org\rhaco\lang\Text::plain("\n" . $template->get($body) . "\n"));
         $html = $xml->f('html');
         if ($html !== null) {
             $html_path = \org\rhaco\net\Path::absolute($resource_path, $html->in_attr('src'));
             foreach ($html->in('media') as $media) {
                 $file = \org\rhaco\net\Path::absolute($resource_path, $media->in_attr('src'));
                 if (!is_file($file)) {
                     throw new \InvalidArgumentException($media->in_attr('src') . ' invalid media');
                 }
                 $this->media($media->in_attr('src'), file_get_contents($file));
             }
             $template = new \org\rhaco\Template();
             $template->cp($vars);
             $template->vars('t', new \org\rhaco\flow\module\Helper());
             $this->html($template->read($html_path));
         }
         foreach ($xml->in('attach') as $attach) {
             $file = \org\rhaco\net\Path::absolute($resource_path, $attach->in_attr('src'));
             if (!is_file($file)) {
                 throw new \InvalidArgumentException($attach->in_attr('src') . ' invalid media');
             }
             $this->attach($attach->in_attr('name', $attach->in_attr('src')), file_get_contents($file));
         }
         return $this;
     }
     throw new \InvalidArgumentException($template_path . ' invalid data');
 }
Esempio n. 2
0
<?php

$template = new \org\rhaco\Template();
$src = $template->read(__DIR__ . '/resources/template_super.html');
eq('abcd', $src);
$template = new \org\rhaco\Template();
$template->template_super(__DIR__ . '/resources/template_super_x.html');
$src = $template->read(__DIR__ . '/resources/template_super.html');
eq('xc', $src);