Exemplo n.º 1
0
PRE;
$t = new \ebi\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 \ebi\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 \ebi\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 \ebi\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 \ebi\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 \ebi\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));
Exemplo n.º 2
0
 /**
  * Set template
  * @param string $template_path Relative path from resource_path
  * @param mixed{} $vars bind variables
  * @return $this
  */
 public function set_template($template_path, $vars = [])
 {
     /**
      * @param string $path Email template resources root
      */
     $resource_path = \ebi\Conf::get('resource_path', \ebi\Conf::resource_path('mail'));
     $path = \ebi\Util::path_absolute($resource_path, $template_path);
     if (!is_file($path)) {
         throw new \ebi\exception\InvalidArgumentException($template_path . ' not found');
     }
     $xml = \ebi\Xml::extract(file_get_contents($path), 'mail');
     try {
         try {
             $from = $xml->find_get('from');
             $this->from($from->in_attr('address'), $from->in_attr('name'));
         } catch (\ebi\exception\NotFoundException $e) {
         }
         foreach ($xml->find('to') as $to) {
             $this->to($to->in_attr('address'), $to->in_attr('name'));
         }
         try {
             $this->return_path($xml->find_get('return_path')->in_attr('address'));
         } catch (\ebi\exception\NotFoundException $e) {
         }
         /**
          * @param string $xtc_name xtc query key
          */
         $xtc_name = \ebi\Conf::get('xtc_name', 'xtc');
         $xtc = self::xtc($template_path);
         $this->header['X-T-Code'] = $xtc;
         $vars['t'] = new \ebi\FlowHelper();
         $vars['xtc'] = [$xtc_name => $xtc];
         $subject = trim(str_replace(["\r\n", "\r", "\n"], '', $xml->find_get('subject')->value()));
         $template = new \ebi\Template();
         $template->cp($vars);
         $body_xml = $xml->find_get('body');
         $signature = $body_xml->in_attr('signature');
         $signature_text = '';
         if (!empty($signature)) {
             $sig_path = \ebi\Util::path_absolute($resource_path, $signature);
             if (!is_file($sig_path)) {
                 throw new \ebi\exception\InvalidArgumentException($signature . ' not found');
             }
             $sig_xml = \ebi\Xml::extract(file_get_contents($sig_path), 'mail');
             $signature_text = \ebi\Util::plain_text(PHP_EOL . $sig_xml->find_get('signature')->value() . PHP_EOL);
         }
         $message = $template->get(\ebi\Util::plain_text(PHP_EOL . $body_xml->value() . PHP_EOL) . $signature_text);
         $this->message($message);
         $this->subject($template->get($subject));
         try {
             $html = $xml->find_get('html');
             $html_path = \ebi\Util::path_absolute($resource_path, $html->in_attr('src', preg_replace('/^(.+)\\.\\w+$/', '\\1', $path) . '.html'));
             foreach ($html->find('media') as $media) {
                 $file = \ebi\Util::path_absolute($resource_path, $media->in_attr('src'));
                 if (!is_file($file)) {
                     throw new \ebi\exception\InvalidArgumentException($media->in_attr('src') . ' invalid media');
                 }
                 $this->media($media->in_attr('src'), file_get_contents($file));
             }
             $template = new \ebi\Template();
             $template->cp($vars);
             $this->html($template->read($html_path));
         } catch (\ebi\exception\NotFoundException $e) {
         }
         foreach ($xml->find('attach') as $attach) {
             $file = \ebi\Util::path_absolute($resource_path, $attach->in_attr('src'));
             if (!is_file($file)) {
                 throw new \ebi\exception\InvalidArgumentException($attach->in_attr('src') . ' invalid media');
             }
             $this->attach($attach->in_attr('name', $attach->in_attr('src')), file_get_contents($file));
         }
         return $this;
     } catch (\ebi\exception\NotFoundException $e) {
         throw new \ebi\exception\InvalidArgumentException($template_path . ' invalid data');
     }
 }
Exemplo n.º 3
0
$t->vars("abc", array(1));
eq($result, $t->get($src));
$src = '<rt:if param="abc">aa<rt:else />bb</rt:if>';
$result = 'bb';
$t = new \ebi\Template();
$t->vars("abc", []);
eq($result, $t->get($src));
$src = '<rt:if param="abc">aa<rt:else />bb</rt:if>';
$result = 'aa';
$t = new \ebi\Template();
$t->vars("abc", true);
eq($result, $t->get($src));
$src = '<rt:if param="abc">aa<rt:else />bb</rt:if>';
$result = 'bb';
$t = new \ebi\Template();
$t->vars("abc", false);
eq($result, $t->get($src));
$src = '<rt:if param="abc">aa<rt:else />bb</rt:if>';
$result = 'aa';
$t = new \ebi\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 \ebi\Template();
$t->vars("abc", "");
eq($result, $t->get($src));
$src = '<rt:if param="abc">aa<rt:else />bb</rt:if>';
$result = 'bb';
$t = new \ebi\Template();
eq($result, $t->get($src));
Exemplo n.º 4
0
<?php

$template = new \ebi\Template();
$src = $template->read(__DIR__ . '/resources/template_super.html');
eq('abcd', $src);
$template = new \ebi\Template();
$template->template_super(__DIR__ . '/resources/template_super_x.html');
$src = $template->read(__DIR__ . '/resources/template_super.html');
eq('xc', $src);
Exemplo n.º 5
0
<?php

$src = '123<rt:comment>aaaaaaaa</rt:comment>456';
$t = new \ebi\Template();
eq('123456', $t->get($src));
Exemplo n.º 6
0
<?php

$t = new \ebi\Template();
$src = <<<'TEXT'
<rt:loop param="abc" counter="loop_counter" key="loop_key" var="loop_var">
{$loop_counter}: {$loop_key} => {$loop_var}
</rt:loop>
hoge
TEXT;
$result = <<<'TEXT'
1: A => 456
2: B => 789
3: C => 010
4: D => 999
hoge
TEXT;
$t = new \ebi\Template();
$t->vars("abc", array("A" => "456", "B" => "789", "C" => "010", "D" => "999"));
eq($result, $t->get($src));
Exemplo n.º 7
0
	<input type="checkbox" name="bbb[]" value="hoge" checked="checked" />hoge
	<input type="checkbox" name="bbb[]" value="fuga" />fuga
	<input type="checkbox" name="eee[]" value="true" checked="checked" />foo
	<input type="checkbox" name="fff[]" value="false" checked="checked" />foo
	<input type="submit" />
	<textarea name="aaa">hogehoge</textarea>
	
	<select name="ddd[]" size="5" multiple="multiple">
	<option value="123">123</option>
	<option value="456" selected="selected">456</option>
	<option value="789" selected="selected">789</option>
	</select>
	<select name="XYZ"><option value="A">456</option><option value="B" selected="selected">789</option><option value="C">010</option></select>
</form>
PRE;
$t = new \ebi\Template();
$t->vars("aaa_name", "aaa");
$t->vars("bbb_name", "bbb");
$t->vars("XYZ_name", "XYZ");
$t->vars("xyz_name", "xyz");
$t->vars("ddd_name", "ddd");
$t->vars("eee_name", "eee");
$t->vars("fff_name", "fff");
$t->vars("aaa", "hogehoge");
$t->vars("bbb", "hoge");
$t->vars("XYZ", "B");
$t->vars("xyz", array("A" => "456", "B" => "789", "C" => "010"));
$t->vars("ddd", array("456", "789"));
$t->vars("eee", true);
$t->vars("fff", false);
eq($result, $t->get($src));
Exemplo n.º 8
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 \ebi\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 \ebi\Template();
$t->secure(true);
$t->vars('link', $link);
eq($result_secure, $t->get($src));
// httpsにはならない
Exemplo n.º 9
0
<?php

$src = 'abc {$abc} def {$def} ghi {$ghi}';
$result = 'abc 123 def 456 ghi 789';
$t = new \ebi\Template();
$t->vars("abc", 123);
$t->vars("def", 456);
$t->vars("ghi", 789);
eq($result, $t->get($src));
Exemplo n.º 10
0
<?php

$t = new \ebi\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));
Exemplo n.º 11
0
<form>
	<input type="search" name="search" value="hoge" />
	<input type="tel" name="tel" value="000-000-0000" />
	<input type="url" name="url" value="http://tokushimakazutaka.com" />
	<input type="email" name="email" value="*****@*****.**" />
	<input type="datetime" name="datetime" value="1970-01-01T00:00:00.0Z" />
	<input type="datetime-local" name="datetime_local" value="1970-01-01T00:00:00.0Z" />
	<input type="date" name="date" value="1970-01-01" />
	<input type="month" name="month" value="1970-01" />
	<input type="week" name="week" value="1970-W15" />
	<input type="time" name="time" value="12:30" />
	<input type="number" name="number" value="1234" />
	<input type="range" name="range" value="7" />
	<input type="color" name="color" value="#ff0000" />
</form>
PRE;
$t = new \ebi\Template();
$t->vars("search", "hoge");
$t->vars("tel", "000-000-0000");
$t->vars("url", "http://tokushimakazutaka.com");
$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));
Exemplo n.º 12
0
<?php

$t = new \ebi\Template('http://localhost/hoge/media');
$src = <<<'PRE'
<script src="abc.js"></script>
<script language="javascript">
var i = "{$abc}";
var img = "<img src='hoge.jpg' />";
</script>
<img src='hoge.jpg' />
PRE;
$result = <<<'PRE'
<script src="http://localhost/hoge/media/abc.js"></script>
<script language="javascript">
var i = "123";
var img = "<img src='hoge.jpg' />";
</script>
<img src='http://localhost/hoge/media/hoge.jpg' />
PRE;
$t->vars("abc", 123);
eq($result, $t->get($src));
Exemplo n.º 13
0
<?php

$template = new \ebi\Template();
$src = $template->read(__DIR__ . '/resources/allinone.html', 'abc');
meq('ABC', $src);
mneq('INDEX', $src);
mneq('DEF', $src);
meq('IFOOTER', $src);
$template = new \ebi\Template();
$src = $template->read(__DIR__ . '/resources/allinone.html', 'def');
meq('DEF', $src);
mneq('INDEX', $src);
mneq('ABC', $src);
mneq('IFOOTER', $src);
meq('DFOOTER', $src);
$template = new \ebi\Template();
$src = $template->read(__DIR__ . '/resources/allinone.html', 'xyz');
meq('XYZ', $src);
mneq('INDEX', $src);
mneq('ABC', $src);
meq('IFOOTER', $src);
$template = new \ebi\Template();
$src = $template->read(__DIR__ . '/resources/allinone.html', 'index');
meq('INDEX', $src);
meq('IFOOTER', $src);
mneq('DFOOTER', $src);
mneq('ABC', $src);
Exemplo n.º 14
0
<?php

$template = new \ebi\Template();
$src = $template->read(__DIR__ . '/resources/rtblockvar/block1');
eq('AAA', $src);
$template = new \ebi\Template();
$src = $template->read(__DIR__ . '/resources/rtblockvar/block2');
eq('BBB', $src);
Exemplo n.º 15
0
	<select name="ddd" rt:param="abc">
	</select>
</form>
PRE;
$result = <<<'PRE'
<form>
	<select name="ddd"><option value="123">123</option><option value="456" selected="selected">456</option><option value="789">789</option></select>
</form>
PRE;
$t = new \ebi\Template();
$t->vars("abc", array(123 => 123, 456 => 456, 789 => 789));
$t->vars("ddd", "456");
eq($result, $t->get($src));
$src = <<<'PRE'
<form rt:ref="true">
<rt:loop param="abc" var="v">
	<input type="checkbox" name="ddd" value="{$v}" />
</rt:loop>
</form>
PRE;
$result = <<<'PRE'
<form>
	<input type="checkbox" name="ddd[]" value="123" />
	<input type="checkbox" name="ddd[]" value="456" checked="checked" />
	<input type="checkbox" name="ddd[]" value="789" />
</form>
PRE;
$t = new \ebi\Template();
$t->vars("abc", array(123 => 123, 456 => 456, 789 => 789));
$t->vars("ddd", "456");
eq($result, $t->get($src));