Пример #1
0
 /**
  * @module org.rhaco.Template
  * @param org.rhaco.lang.Str $obj
  */
 public function before_template(\org\rhaco\lang\Str $obj)
 {
     $src = $obj->get();
     $this->replace('rt:exceptions', $src);
     $this->replace('rt:invalid', $src);
     $obj->set($src);
 }
Пример #2
0
 /**
  * @module org.rhaco.Template
  * @param org.rhaco.lang.Str $obj
  */
 public function after_template(\org\rhaco\lang\Str $obj)
 {
     $src = $obj->get();
     $src = str_replace("{\$t.package_method_url('class_info',", "{\$f.class_html_filename(", $src);
     $src = str_replace("{\$t.package_method_url('method_info',", "{\$f.method_html_filename(", $src);
     $src = str_replace("{\$t.package_method_url('class_module_info',", "{\$f.module_html_filename(", $src);
     $obj->set($src);
 }
Пример #3
0
 /**
  * @module org.rhaco.Template
  * @param \org\rhaco\lang\Str $obj
  */
 public function before_exec_template(\org\rhaco\lang\Str $obj)
 {
     $src = $obj->get();
     if (preg_match_all('/\\$_t_->print_variable\\((.+?)\\);/ms', $src, $match)) {
         $src = str_replace($match[0], array_map(array($this, 'add_escape'), $match[1]), $src);
         $obj->set($src);
     }
 }
Пример #4
0
 public function after_template(\org\rhaco\lang\Str $obj)
 {
     $src = $obj->get();
     \org\rhaco\Xml::set($tag, '<:>' . $src . '</:>');
     foreach ($tag->in('form') as $form) {
         if ($form->in_attr('action') == '' || strpos($form->in_attr('action'), '$t.map_url') !== false) {
             $form->escape(false);
             $form->value(sprintf('<input type="hidden" name="csrftoken" value="%s" />', $this->no) . $form->value());
             $src = str_replace($form->plain(), $form->get(), $src);
         }
     }
     $obj->set($src);
 }
 /**
  * @module org.rhaco.Template
  * @param org.rhaco.lang.Str $obj
  */
 public function before_template(\org\rhaco\lang\Str $obj)
 {
     $src = $obj->get();
     if (strpos($src, 'rt:paginator') !== false) {
         while (Xml::set($tag, $src, 'rt:paginator')) {
             $param = '$' . $tag->in_attr('param', 'paginator');
             $func = sprintf('<?php try{ ?><?php if(%s instanceof \\org\\rhaco\\Paginator){ ?>', $param);
             $func .= '<div class="pagination"><ul>';
             $uniq = uniqid('');
             $name = '$__pager__' . $uniq;
             $counter_var = '$__counter__' . $uniq;
             $href = $tag->in_attr('href', '?');
             $stag = '<li%s>';
             $etag = '</li>';
             $navi = array_change_key_case(array_flip(explode(',', $tag->in_attr('navi', 'prev,next,first,last,counter'))));
             $counter = $tag->in_attr('counter', 10);
             $total = '$__pagertotal__' . $uniq;
             if (isset($navi['prev'])) {
                 $func .= sprintf('<?php if(%s->is_prev()){ ?><li class="prev"><a href="%s{%s.query_prev()}" rel="prev"><?php }else{ ?><li class="prev disabled"><a><?php } ?>%s</a></li>', $param, $href, $param, '&larr; Previous');
             }
             if (isset($navi['first'])) {
                 $func .= sprintf('<?php if(!%s->is_dynamic() && %s->is_first(%d)){ ?><li><a href="%s{%s.query(%s.first())}">{%s.first()}</a></li><li class="disabled"><a>...</a></li><?php } ?>', $param, $param, $counter, $href, $param, $param, $param);
             }
             if (isset($navi['counter'])) {
                 $func .= sprintf('<?php if(!%s->is_dynamic()){ ?>', $param);
                 $func .= sprintf('<?php %s = %s; if(!empty(%s)){ ?>', $total, $param, $total);
                 $func .= sprintf('<?php for(%s=%s->which_first(%d);%s<=%s->which_last(%d);%s++){ ?>', $counter_var, $param, $counter, $counter_var, $param, $counter, $counter_var);
                 $func .= sprintf('<?php if(%s == %s->current()){ ?>', $counter_var, $param);
                 $func .= sprintf('<li class="active"><a>{%s}</a></li>', $counter_var);
                 $func .= '<?php }else{ ?>';
                 $func .= sprintf('<li><a href="%s{%s.query(%s)}">{%s}</a></li>', $href, $param, $counter_var, $counter_var);
                 $func .= '<?php } ?>';
                 $func .= '<?php } ?>';
                 $func .= '<?php } ?>';
                 $func .= '<?php } ?>';
             }
             if (isset($navi['last'])) {
                 $func .= sprintf('<?php if(!%s->is_dynamic() && %s->is_last(%d)){ ?><li class="disabled"><a>...</a></li><li><a href="%s{%s.query(%s.last())}">{%s.last()}</a></li><?php } ?>', $param, $param, $counter, $href, $param, $param, $param);
             }
             if (isset($navi['next'])) {
                 $func .= sprintf('<?php if(%s->is_next()){ ?><li class="next"><a href="%s{%s.query_next()}" rel="next"><?php }else{ ?><li class="next disabled"><a><?php } ?>%s</a></li>', $param, $href, $param, 'Next &rarr;', $etag);
             }
             $func .= "<?php } ?><?php }catch(\\Exception \$e){} ?>";
             $func .= '</ul></div>';
             $src = str_replace($tag->plain(), $func, $src);
         }
     }
     $obj->set($src);
 }
Пример #6
0
 /**
  * @module org.rhaco.Template
  * @param org.rhaco.lang.Str $obj
  */
 public function before_template(\org\rhaco\lang\Str $obj)
 {
     $src = $obj->get();
     if (strpos($src, 'rt:paginator') !== false) {
         while (Xml::set($tag, $src, 'rt:paginator')) {
             $param = '$' . $tag->in_attr('param', 'paginator');
             $func = sprintf('<?php try{ ?><?php if(%s instanceof \\org\\rhaco\\Paginator){ ?>', $param);
             if ($tag->value() != '') {
                 $func .= $tag->value();
             } else {
                 $uniq = uniqid('');
                 $name = '$__pager__' . $uniq;
                 $counter_var = '$__counter__' . $uniq;
                 $tagtype = $tag->in_attr('tag');
                 $href = $tag->in_attr('href', '?');
                 $stag = empty($tagtype) ? '' : '<' . $tagtype . ' class="%s">';
                 $etag = empty($tagtype) ? '' : '</' . $tagtype . '>';
                 $navi = array_change_key_case(array_flip(explode(',', $tag->in_attr('navi', 'prev,next,first,last,counter'))));
                 $counter = $tag->in_attr('counter', 50);
                 $total = '$__pagertotal__' . $uniq;
                 if (isset($navi['prev'])) {
                     $func .= sprintf('<?php if(%s->is_prev()){ ?>%s<a href="%s{%s.query_prev()}" rel="prev">%s</a>%s<?php } ?>', $param, sprintf($stag, 'prev'), $href, $param, 'prev', $etag);
                 }
                 if (isset($navi['first'])) {
                     $func .= sprintf('<?php if(!%s->is_dynamic() && %s->is_first(%d)){ ?>%s<a href="%s{%s.query(%s.first())}">{%s.first()}</a>%s%s...%s<?php } ?>', $param, $param, $counter, sprintf($stag, 'first'), $href, $param, $param, $param, $etag, sprintf($stag, 'first_gt'), $etag);
                 }
                 if (isset($navi['counter'])) {
                     $func .= sprintf('<?php if(!%s->is_dynamic()){ ?>', $param);
                     $func .= sprintf('<?php %s = %s; if(!empty(%s)){ ?>', $total, $param, $total);
                     $func .= sprintf('<?php for(%s=%s->which_first(%d);%s<=%s->which_last(%d);%s++){ ?>', $counter_var, $param, $counter, $counter_var, $param, $counter, $counter_var);
                     $func .= sprintf('%s<?php if(%s == %s->current()){ ?><strong>{%s}</strong><?php }else{ ?><a href="%s{%s.query(%s)}">{%s}</a><?php } ?>%s', sprintf($stag, 'count'), $counter_var, $param, $counter_var, $href, $param, $counter_var, $counter_var, $etag);
                     $func .= '<?php } ?>';
                     $func .= '<?php } ?>';
                     $func .= '<?php } ?>';
                 }
                 if (isset($navi['last'])) {
                     $func .= sprintf('<?php if(!%s->is_dynamic() && %s->is_last(%d)){ ?>%s...%s%s<a href="%s{%s.query(%s.last())}">{%s.last()}</a>%s<?php } ?>', $param, $param, $counter, sprintf($stag, 'last_lt'), $etag, sprintf($stag, 'last'), $href, $param, $param, $param, $etag);
                 }
                 if (isset($navi['next'])) {
                     $func .= sprintf('<?php if(%s->is_next()){ ?>%s<a href="%s{%s.query_next()}" rel="next">%s</a>%s<?php } ?>', $param, sprintf($stag, 'next'), $href, $param, 'next', $etag);
                 }
             }
             $func .= "<?php } ?><?php }catch(\\Exception \$e){} ?>";
             $src = str_replace($tag->plain(), $func, $src);
         }
     }
     $obj->set($src);
 }
Пример #7
0
 public function after_exec_template(\org\rhaco\lang\Str $obj)
 {
     $obj->set($obj->get() . 'AFTER_EXEC_TEMPLATE' . PHP_EOL);
 }
Пример #8
0
 private function print_template($template_path, $template, $media_url, $put_block, $obj, $apps, $index, $path_replace = true)
 {
     if ($path_replace) {
         if (isset($apps[$index]['media_path'])) {
             $media_url = $media_url . \org\rhaco\net\Path::slash($apps[$index]['media_path'], true, false);
         }
         if (isset($apps[$index]['template_path'])) {
             $template_path = $template_path . \org\rhaco\net\Path::slash($apps[$index]['template_path'], false, true);
         }
     }
     if (!empty($put_block)) {
         $this->template->put_block(\org\rhaco\net\Path::absolute($this->template_path, $put_block));
     }
     if (isset($apps[$index]['template_super'])) {
         $this->template->template_super($this->template_path . $apps[$index]['template_super']);
     }
     if (is_array($obj) && isset($obj[0]) && isset($obj[1])) {
         foreach (is_array($obj[1]) ? $obj[1] : array($obj[1]) as $o) {
             $this->template->set_object_module($o);
         }
         $obj = $obj[0];
     }
     $this->template->media_url($media_url);
     $this->template->cp($obj);
     if (isset($apps[$index]['vars'])) {
         $this->template->cp($apps[$index]['vars']);
     }
     $this->template->vars('t', new \org\rhaco\flow\module\Helper($this->app_url, $media_url, $apps[$index]['name'], $apps[$index]['num'], $this->entry_file(), $apps, $obj));
     $src = $this->template->read(\org\rhaco\net\Path::absolute($template_path, $template));
     /**
      * テンプレートの出力
      * @param org.rhaco.lang.Str $obj
      */
     $this->object_module('before_flow_print_template', \org\rhaco\lang\Str::ref($obj, $src));
     $src = (string) $obj;
     header('Content-Length: ' . strlen($src));
     print $src;
     exit;
 }
Пример #9
0
 /**
  * @module org.rhaco.Template
  */
 public function after_exec_template(\org\rhaco\lang\Str $obj)
 {
     $src = $obj->get();
     $src = preg_replace("/<alert>(.+?)<\\/alert>/ms", '<p class="alert alert-error">\\1</p>', $src);
     $src = preg_replace("/<information>(.+?)<\\/information>/ms", '<p class="alert alert-info">\\1</p>', $src);
     $src = preg_replace("/!!!(.+?)!!!/ms", '<span style="font-weight:bold">\\1</span>', $src);
     $src = preg_replace("/##(.+?)##/ms", '<span class="label label-warning">\\1</span>', $src);
     $src = str_replace('<table>', '<table class="table table-striped table-bordered table-condensed">', $src);
     $src = str_replace(array('__RTD__', '__RTE__'), array('$', '='), $src);
     $obj->set($src);
 }
Пример #10
0
 public function before_flow_print_template(\org\rhaco\lang\Str $obj)
 {
     $obj->set($obj->get() . "10");
 }
Пример #11
0
 private function rtblock($src, $filename)
 {
     if (strpos($src, 'rt:block') !== false || strpos($src, 'rt:extends') !== false) {
         $base_filename = $filename;
         $blocks = $paths = array();
         while (Xml::set($e, '<:>' . $this->rtcomment($src) . '</:>', 'rt:extends') !== false) {
             $href = $this->ab_path(str_replace("\\", '/', dirname($filename)), $e->in_attr('href'));
             if (!$e->is_attr('href') || !is_file($href)) {
                 throw new \LogicException('href not found ' . $filename);
             }
             if ($filename === $href) {
                 throw new \LogicException('Infinite Recursion Error' . $filename);
             }
             Xml::set($bx, '<:>' . $this->rtcomment($src) . '</:>', ':');
             foreach ($bx->in('rt:block') as $b) {
                 $n = $b->in_attr('name');
                 if (!empty($n) && !array_key_exists($n, $blocks)) {
                     $blocks[$n] = $b->value();
                     $paths[$n] = $filename;
                 }
             }
             $src = $this->rttemplate($this->replace_xtag($this->read_src($filename = $href)));
             $this->selected_template = $e->in_attr('name');
         }
         /**
          * ブロック展開の前処理
          * @param org.rhaco.lang.Str $obj
          */
         $this->object_module('before_block_template', \org\rhaco\lang\Str::ref($obj, $src));
         $src = (string) $obj;
         if (empty($blocks)) {
             if (Xml::set($bx, '<:>' . $src . '</:>')) {
                 foreach ($bx->in('rt:block') as $b) {
                     $src = str_replace($b->plain(), $b->value(), $src);
                 }
             }
         } else {
             if (!empty($this->template_super)) {
                 $src = $this->read_src($this->ab_path(str_replace("\\", '/', dirname($base_filename)), $this->template_super));
             }
             while (Xml::set($b, $src, 'rt:block')) {
                 $n = $b->in_attr('name');
                 $src = str_replace($b->plain(), array_key_exists($n, $blocks) ? $blocks[$n] : $b->value(), $src);
             }
         }
         $this->file = $filename;
     }
     return $src;
 }