Example #1
0
<?php

$params = array("A", "B", "C");
eq("aAbBcCde", \org\rhaco\lang\Text::fstring("a{1}b{2}c{3}d{4}e", $params));
eq("aAbBcAde", \org\rhaco\lang\Text::fstring("a{1}b{2}c{1}d{4}e", $params));
eq("aAbBcAde", \org\rhaco\lang\Text::fstring("a{1}b{2}c{1}d{4}e", "A", "B", "C"));
Example #2
0
<?php

eq("ほげほげ", \org\rhaco\lang\Text::htmldecode("&#12411;&#12370;&#12411;&#12370;"));
eq("&gt;&lt;ほげ& ほげ", \org\rhaco\lang\Text::htmldecode("&amp;gt;&amp;lt;&#12411;&#12370;&amp; &#12411;&#12370;"));
Example #3
0
<?php

eq(3, \org\rhaco\lang\Text::length("abc"));
eq(5, \org\rhaco\lang\Text::length(array("abc", "defgh", "i")));
Example #4
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');
 }
 /**
  * @module org.rhaco.Template
  */
 public function before_template(\org\rhaco\lang\Str $obj)
 {
     $src = $obj->get();
     if (\org\rhaco\Xml::set($tag, $src, 'body')) {
         foreach ($tag->in(array('pre', 'cli', 'tree')) as $b) {
             $plain = $b->plain();
             $tag = strtolower($b->name());
             $b->escape(false);
             $caption = $b->in_attr('caption');
             $b->rm_attr('caption');
             $style = $b->in_attr('style');
             if ($tag == 'cli') {
                 $b->name('pre');
                 $b->attr('style', 'background-color:#fff; color:#000; border-color:#000; padding:5px;' . $style);
             } else {
                 if ($tag == 'tree') {
                     $b->name('pre');
                     $b->attr('style', 'padding: 5px; line-height: 20px;' . $style);
                     $b->attr('class', 'prettyprint lang-c');
                 } else {
                     $b->attr('class', 'prettyprint');
                 }
             }
             if (empty($caption)) {
                 $b->attr('style', 'margin-top: 20px; ' . $b->in_attr('style'));
             }
             $value = \org\rhaco\lang\Text::plain($b->value());
             $value = preg_replace("/<(rt:.+?)>/ms", "&lt;\\1&gt;", $value);
             $value = str_replace(array('<php>', '</php>'), array('<?php', '?>'), $value);
             if (empty($value)) {
                 $value = PHP_EOL;
             }
             if ($tag == 'tree') {
                 $tree = array();
                 $len = 0;
                 $v = '';
                 foreach (explode("\n", $value) as $k => $line) {
                     if (preg_match("/^(\\s*)([\\.\\w\\{\\}\\[\\]\\(\\)]+)[:]{0,1}(.*)\$/", $line, $m)) {
                         $tree[$k] = array(strlen(str_replace("\t", ' ', $m[1])), trim($m[2]), trim($m[3]));
                         $tree[$k][3] = strlen($tree[$k][1]);
                         if ($len < $tree[$k][3] + $tree[$k][0]) {
                             $len = $tree[$k][3] + $tree[$k][0];
                         }
                     }
                 }
                 if (!empty($caption)) {
                     $v = $caption . PHP_EOL;
                 }
                 $v .= '.' . PHP_EOL;
                 $last = sizeof($tree) - 1;
                 foreach ($tree as $k => $t) {
                     $v .= str_repeat('| ', $t[0]);
                     $v .= $t[0] > 0 && isset($tree[$k + 1]) && $tree[$k + 1][0] < $t[0] || $k == $last ? '`' : '|';
                     $v .= '-- ' . $t[1] . str_repeat(' ', $len - $t[3] - $t[0] * 2 + 4) . (empty($t[2]) ? '' : ' .. ') . $t[2] . PHP_EOL;
                 }
                 $b->value($v);
                 $plain = $b->get();
             } else {
                 $format = $b->in_attr('format');
                 $b->rm_attr('format');
                 if ($format == 'plain') {
                     $plain = $b->get();
                 } else {
                     $value = str_replace("\t", "&nbsp;&nbsp;", $value);
                     $value = str_replace(array("<", ">", "'", "\""), array("&lt;", "&gt;", "&#039;", "&quot;"), $value);
                     $b->value($value);
                     $plain = str_replace(array('$', '='), array('__RTD__', '__RTE__'), $b->get());
                 }
                 if (!empty($caption)) {
                     $plain = '<div style="margin-top:20px; color:#7a43b6; font-weight: bold;">' . $caption . '</div>' . $plain;
                 }
             }
             $src = str_replace($b->plain(), $plain, $src);
         }
     }
     $obj->set($src);
 }
Example #6
0
<?php

eq("&lt;abc aa=&#039;123&#039; bb=&quot;ddd&quot;&gt;あいう&lt;/abc&gt;", \org\rhaco\lang\Text::htmlencode("<abc aa='123' bb=\"ddd\">あいう</abc>"));
Example #7
0
     print "\n" . 'class ' . $arg . ' in module ' . $module . ':' . PHP_EOL;
     print ' Description:' . PHP_EOL;
     print '   ' . str_replace("\n", "\n   ", $module_info[0]) . PHP_EOL;
     print "\n" . ' Parameter:' . PHP_EOL;
     $len = \org\rhaco\lang\Text::length(array_keys($module_info[1]));
     foreach ($module_info[1] as $p) {
         print '    ' . str_pad('', $len) . '    (' . $p[1] . ') ' . $p[0] . ' : ' . $p[2] . PHP_EOL;
     }
 } else {
     $rtn = \org\rhaco\Dt::class_info($arg);
     print "\n" . 'class ' . $rtn['package'] . ':' . PHP_EOL;
     print '  Version: ' . $rtn['version'] . PHP_EOL . PHP_EOL;
     print '  Description:' . PHP_EOL;
     print '   ' . str_replace("\n", "\n  ", $rtn['description']) . PHP_EOL . PHP_EOL;
     list($static_methods, $methods, $protected_static_methods, $protected_methods, $properties, $modules) = array($rtn['static_methods'], $rtn['methods'], $rtn['protected_static_methods'], $rtn['protected_methods'], $rtn['properties'], $rtn['modules']);
     $len = \org\rhaco\lang\Text::length(array_merge(array_keys($static_methods), array_keys($methods), array_keys($properties), array_keys($modules)));
     if (!empty($static_methods)) {
         print "\n" . '  Static methods defined here:' . PHP_EOL;
         foreach ($static_methods as $k => $v) {
             print '    ' . str_pad($k, $len) . ' : ' . $v . PHP_EOL;
         }
     }
     if (!empty($methods)) {
         print "\n" . '  Methods defined here:' . PHP_EOL;
         foreach ($methods as $k => $v) {
             print '    ' . str_pad($k, $len) . ' : ' . $v . PHP_EOL;
         }
     }
     if (!empty($properties)) {
         print "\n" . '  Properties defined here:' . PHP_EOL;
         foreach ($properties as $k => $v) {
Example #8
0
<?php

eq("a\nb\nc\n", \org\rhaco\lang\Text::uld("a\r\nb\rc\n"));
Example #9
0
<?php

eq("def", \org\rhaco\lang\Text::substring("abcdefg", 3, 3));
Example #10
0
<?php

$text = \org\rhaco\lang\Text::plain('
		aaa
		bbb
');
eq("aaa\nbbb", $text);
$text = \org\rhaco\lang\Text::plain("hoge\nhoge");
eq("hoge\nhoge", $text);
$text = \org\rhaco\lang\Text::plain("hoge\nhoge\nhoge\nhoge");
eq("hoge\nhoge\nhoge\nhoge", $text);