Exemple #1
0
 /**
  * @plugin ebi.Temaplte
  * @param string $src
  * @return Ambigous <string, string, mixed>|string
  */
 public function before_template($src)
 {
     /**
      * @param string $path テンプレートパーツのファイルがあるディレクトリ
      */
     $path = \ebi\Util::path_slash(\ebi\Conf::get('path', \ebi\Conf::resource_path('parts')), null, true);
     return \ebi\Xml::find_replace($src, 'rt:parts', function ($xml) use($path) {
         $href = \ebi\Util::path_absolute($path, $xml->in_attr('href'));
         if (!is_file($href)) {
             throw new \ebi\exception\InvalidArgumentException($href . ' not found');
         }
         return file_get_contents($href);
     });
 }
Exemple #2
0
 public function before_template($src)
 {
     return \ebi\Xml::find_replace($src, 'rt:paginator', function ($xml) {
         $param = '$' . $xml->in_attr('param', 'paginator');
         $navi = array_change_key_case(array_flip(explode(',', $xml->in_attr('navi', 'prev,next,first,last,counter'))));
         $counter = $xml->in_attr('counter', 10);
         $lt = strtolower($xml->in_attr('lt', 'true'));
         $href = $xml->in_attr('href', '?');
         $uniq = uniqid('');
         $counter_var = '$__counter__' . $uniq;
         $func = '';
         if ($lt == 'false') {
             $func .= sprintf('<?php if(%s->is_dynamic() || %s->total() > %s->limit()){ ?>', $param, $param, $param);
         }
         $func .= sprintf('<?php try{ ?><?php if(%s instanceof \\ebi\\Paginator){ ?><ul class="pagination">', $param);
         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 } ?>&laquo;</a></li>', $param, $href, $param);
         }
         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) . sprintf('<?php if(%s->total() == 0){ ?>', $param) . sprintf('<li class="active"><a>1</a></li>') . '<?php }else{ ?>' . sprintf('<?php for(%s=%s->which_first(%d);%s<=%s->which_last(%d);%s++){ ?>', $counter_var, $param, $counter, $counter_var, $param, $counter, $counter_var) . sprintf('<?php if(%s == %s->current()){ ?>', $counter_var, $param) . sprintf('<li class="active"><a>{%s}</a></li>', $counter_var) . '<?php }else{ ?>' . sprintf('<li><a href="%s{%s.query(%s)}">{%s}</a></li>', $href, $param, $counter_var, $counter_var) . '<?php } ?>' . '<?php } ?>' . '<?php } ?>' . '<?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 } ?>&raquo;</a></li>', $param, $href, $param);
         }
         $func .= "<?php } ?><?php }catch(\\Exception \$e){} ?></ul>";
         if ($lt == 'false') {
             $func .= sprintf('<?php } ?>', $param);
         }
         return $func;
     });
 }
 private function before_exhtml($src)
 {
     return \ebi\Xml::find_replace($src, 'pre|cli|tree', function ($xml) {
         $plain = $xml->plain();
         $tag = strtolower($xml->name());
         $xml->escape(false);
         $caption = $xml->in_attr('caption');
         $xml->rm_attr('caption');
         $style = $xml->in_attr('style');
         if ($tag == 'cli') {
             $xml->name('pre');
             $xml->attr('style', 'background-color:#fff; color:#000; border-color:#000; padding:5px;' . $style);
         } else {
             if ($tag == 'tree') {
                 $xml->name('pre');
                 $xml->attr('style', 'padding: 5px; line-height: 20px;' . $style);
                 $xml->attr('class', 'prettyprint lang-c');
             } else {
                 $xml->attr('class', 'prettyprint');
             }
         }
         if (empty($caption)) {
             $xml->attr('style', 'margin-top: 20px; ' . $xml->in_attr('style'));
         }
         $value = $xml->value();
         $value = preg_replace("/<(rt:.+?)>/ms", "&lt;\\1&gt;", $value);
         $value = str_replace(['<php>', '</php>'], ['<?php', '?>'], $value);
         $value = $this->pre($value);
         if (empty($value)) {
             $value = PHP_EOL;
         }
         if ($tag == 'tree') {
             $tree = [];
             $len = 0;
             $v = '';
             foreach (explode("\n", $value) as $k => $line) {
                 if (preg_match("/^(\\s*)([\\.\\w\\{\\}\\[\\]\\(\\)]+)[:]{0,1}(.*)\$/", $line, $m)) {
                     $tree[$k] = [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;
             }
             $xml->value($v);
             $plain = $xml->get();
         } else {
             $format = $xml->in_attr('format');
             $xml->rm_attr('format');
             if ($format == 'plain') {
                 $plain = $xml->get();
             } else {
                 $value = str_replace("\t", "&nbsp;&nbsp;", $value);
                 $value = str_replace(['<', '>', '\'', '"'], ['&lt;', '&gt;', '&#039;', '&quot;'], $value);
                 $xml->value($value);
                 $plain = str_replace(['$', '='], ['__RTD__', '__RTE__'], $xml->get());
             }
             if (!empty($caption)) {
                 $plain = '<div style="margin-top:20px; color:#7a43b6; font-weight: bold;">' . $caption . '</div>' . $plain;
             }
         }
     });
 }