예제 #1
0
파일: read.php 프로젝트: tokushima/rhaco3
<?php

$src = <<<'PRE'
{$abc} ABC
{$def} DEF
{$ghi} GHI
PRE;
$result = <<<'PRE'
123 ABC
456 DEF
789 GHI
PRE;
$t = new \org\rhaco\Template();
$t->vars("abc", 123);
$t->vars("def", 456);
$t->vars("ghi", 789);
eq($result, $t->get($src));
예제 #2
0
PRE;
$t = new \org\rhaco\Template();
$t->vars("abc", array(array(array("A", "B")), array(array("C", "D"))));
$t->vars("xyz", array(1, 2));
eq($result, $t->get($src));
// nest_table
$src = '<table rt:param="object_list" rt:var="obj"><tr><td><table rt:param="obj" rt:var="o"><tr><td>{$o}</td></tr></table></td></tr></table>';
$t = new \org\rhaco\Template();
$t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3")));
eq('<table><tr><td><table><tr><td>A1</td></tr><tr><td>A2</td></tr><tr><td>A3</td></tr></table></td></tr><tr><td><table><tr><td>B1</td></tr><tr><td>B2</td></tr><tr><td>B3</td></tr></table></td></tr></table>', $t->get($src));
// nest_ul
$src = '<ul rt:param="object_list" rt:var="obj"><li><ul rt:param="obj" rt:var="o"><li>{$o}</li></ul></li></ul>';
$t = new \org\rhaco\Template();
$t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3")));
eq('<ul><li><ul><li>A1</li><li>A2</li><li>A3</li></ul></li><li><ul><li>B1</li><li>B2</li><li>B3</li></ul></li></ul>', $t->get($src));
// nest_ol
$src = '<ol rt:param="object_list" rt:var="obj"><li><ol rt:param="obj" rt:var="o"><li>{$o}</li></ol></li></ol>';
$t = new \org\rhaco\Template();
$t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3")));
eq('<ol><li><ol><li>A1</li><li>A2</li><li>A3</li></ol></li><li><ol><li>B1</li><li>B2</li><li>B3</li></ol></li></ol>', $t->get($src));
// nest_olul
$src = '<ol rt:param="object_list" rt:var="obj"><li><ul rt:param="obj" rt:var="o"><li>{$o}</li></ul></li></ol>';
$t = new \org\rhaco\Template();
$t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3")));
eq('<ol><li><ul><li>A1</li><li>A2</li><li>A3</li></ul></li><li><ul><li>B1</li><li>B2</li><li>B3</li></ul></li></ol>', $t->get($src));
// nest_tableul
$src = '<table rt:param="object_list" rt:var="obj"><tr><td><ul rt:param="obj" rt:var="o"><li>{$o}</li></ul></td></tr></table>';
$t = new \org\rhaco\Template();
$t->vars("object_list", array(array("A1", "A2", "A3"), array("B1", "B2", "B3")));
eq('<table><tr><td><ul><li>A1</li><li>A2</li><li>A3</li></ul></td></tr><tr><td><ul><li>B1</li><li>B2</li><li>B3</li></ul></td></tr></table>', $t->get($src));
예제 #3
0
파일: Mail.php 프로젝트: tokushima/rhaco3
 /**
  * テンプレートから内容を取得しセットする
  * 
  * テンプレートサンプル
  * <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');
 }
예제 #4
0
파일: rtif.php 프로젝트: tokushima/rhaco3
eq($result, $t->get($src));
$src = '<rt:if param="abc">aa<rt:else />bb</rt:if>';
$result = 'aa';
$t = new \org\rhaco\Template();
$t->vars("abc", "a");
eq($result, $t->get($src));
$src = '<rt:if param="abc">aa<rt:else />bb</rt:if>';
$result = 'bb';
$t = new \org\rhaco\Template();
$t->vars("abc", "");
eq($result, $t->get($src));
$src = '<rt:if param="abc" value="-1">hoge</rt:if>';
$result = 'hoge';
$t = new \org\rhaco\Template();
$t->vars("abc", -1);
eq($result, $t->get($src));
$src = '<rt:if param="abc" value="0">hoge</rt:if>';
$result = 'hoge';
$t = new \org\rhaco\Template();
$t->vars("abc", 0);
eq($result, $t->get($src));
$src = '<rt:notif param="abc">hoge</rt:notif>';
$result = 'hoge';
$t = new \org\rhaco\Template();
$t->vars("abc", false);
eq($result, $t->get($src));
$src = '<rt:notif param="abc" value="0">hoge</rt:notif>';
$result = 'hoge';
$t = new \org\rhaco\Template();
$t->vars("abc", 1);
eq($result, $t->get($src));
예제 #5
0
<?php

$src = '123<rt:comment>aaaaaaaa</rt:comment>456';
$t = new \org\rhaco\Template();
eq('123456', $t->get($src));
예제 #6
0
파일: rtloop.php 프로젝트: tokushima/rhaco3
<?php

$t = new \org\rhaco\Template();
$src = <<<'PRE'
		<rt:loop param="abc" counter="loop_counter" key="loop_key" var="loop_var">
{$loop_counter}: {$loop_key} => {$loop_var} hoge
		</rt:loop>
PRE;
$result = <<<'PRE'
		1: A => 456 hoge
		2: B => 789 hoge
		3: C => 010 hoge
		4: D => 999 hoge
		
PRE;
$t = new \org\rhaco\Template();
$t->vars("abc", array("A" => "456", "B" => "789", "C" => "010", "D" => "999"));
eq($result, $t->get($src));
// multi
$t = new \org\rhaco\Template();
$src = '<rt:loop param="abc" var="a"><rt:loop param="abc" var="b">{$a}{$b}</rt:loop>-</rt:loop>';
$result = '1112-2122-';
$t->vars('abc', array(1, 2));
eq($result, $t->get($src));
// evenodd
$t = new \org\rhaco\Template();
$src = '<rt:loop param="abc" evenodd="evenodd" counter="counter">{$counter}[{$evenodd}]</rt:loop>';
$result = '1[odd]2[even]3[odd]4[even]5[odd]6[even]';
$t->vars('abc', array(1, 2, 3, 4, 5, 6));
eq($result, $t->get($src));
예제 #7
0
<html>
<body>
\t<a href="{$link('abc/def.html')}">link</a>
\t<img src="{$link('media/xyz.jpg')}" />
</body>
</html>
PRE;
$result = <<<PRE
<html>
<body>
\t<a href="http://localhost/resources/abc/def.html">link</a>
\t<img src="http://localhost/resources/media/xyz.jpg" />
</body>
</html>
PRE;
$t = new \org\rhaco\Template();
$t->vars('link', $link);
eq($result, $t->get($src));
$result_secure = <<<PRE
<html>
<body>
\t<a href="http://localhost/resources/abc/def.html">link</a>
\t<img src="http://localhost/resources/media/xyz.jpg" />
</body>
</html>
PRE;
$t = new \org\rhaco\Template();
$t->secure(true);
$t->vars('link', $link);
eq($result_secure, $t->get($src));
// httpsには置換されない
예제 #8
0
\t\t<form>
\t\t<input type="search" name="search" value="hoge" />
\t\t<input type="tel" name="tel" value="000-000-0000" />
\t\t<input type="url" name="url" value="http://rhaco.org" />
\t\t<input type="email" name="email" value="*****@*****.**" />
\t\t<input type="datetime" name="datetime" value="1970-01-01T00:00:00.0Z" />
\t\t<input type="datetime-local" name="datetime_local" value="1970-01-01T00:00:00.0Z" />
\t\t<input type="date" name="date" value="1970-01-01" />
\t\t<input type="month" name="month" value="1970-01" />
\t\t<input type="week" name="week" value="1970-W15" />
\t\t<input type="time" name="time" value="12:30" />
\t\t<input type="number" name="number" value="1234" />
\t\t<input type="range" name="range" value="7" />
\t\t<input type="color" name="color" value="#ff0000" />
\t\t</form>
PRE;
$t = new \org\rhaco\Template();
$t->vars("search", "hoge");
$t->vars("tel", "000-000-0000");
$t->vars("url", "http://rhaco.org");
$t->vars("email", "*****@*****.**");
$t->vars("datetime", "1970-01-01T00:00:00.0Z");
$t->vars("datetime_local", "1970-01-01T00:00:00.0Z");
$t->vars("date", "1970-01-01");
$t->vars("month", "1970-01");
$t->vars("week", "1970-W15");
$t->vars("time", "12:30");
$t->vars("number", "1234");
$t->vars("range", "7");
$t->vars("color", "#ff0000");
eq($rslt, $t->get($src));
예제 #9
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);