$value){ //trim $value = trim($value); $tag = '<%'.$key.'%>'; //$keyがあるかチェック debug if(TMPL_DEBUG){ print $key; if(strpos($html,$tag) === false){ print '...not find'; }else{ print '...found'; } print '
'; } //httpの場合はキーワード置換 if(substr($value,0,4) == 'http'){ $html = str_replace($tag,$value,$html); continue; } //拡張子取得 $pinfo= pathinfo($value); if(array_key_exists('extension',$pinfo)){ $ext = $pinfo['extension']; }else{ $ext = ''; } #$name = $pinfo['filename']; //拡張子によってはキーワード置換 $except_exts = array('jpg','gif','png'); if(in_array($ext,$except_exts)){ $html = str_replace($tag,$value,$html); continue; } //パス取得 $path = tmpl_filepath($value); //拡張子による分岐 if($ext == 'php'){ //php実行結果を取得 if(file_exists($path)){ ob_start(); require($path); $value = ob_get_contents(); ob_end_clean(); }else{ $value ='PHP PATH ERROR'; } }elseif($ext == 'post'){ //POST値を取得 $name = $pinfo['filename']; if(isset($_POST[$name])){ $value = $_POST[$name]; }else{ $value = 'POST ERROR'; } }elseif($ext == 'py'){ if(file_exists($path) and is_file($path)){ $value = htmlspecialchars(file_get_contents($path)); }else{ $value = 'PY PATH ERROR'; } }else{ //ファイルが存在すればファイル内容を取得 if(file_exists($path) and is_file($path)){ $value = file_get_contents($path); } } //ファイルが存在しなければキーワードに置換 $html = str_replace($tag,$value,$html); } return $html; } function tmpl_filepath($file_path){ if(file_exists($file_path)){ return $file_path; } $path = tmpl_join_path($_SERVER['DOCUMENT_ROOT'],$file_path); if(file_exists($path)){ return $path; } $path = tmpl_join_path(TMPL_ROOT,$file_path); if(file_exists($path)){ return $path; } $path = tmpl_join_path(TMPL_CGI_DIR,$file_path); if(file_exists($path)){ return $path; } return false; } function tmpl_debug($string){ if(defined('TMPL_DEBUG')){ print($string); } } function tmpl_main($tmpl_path,$conf_path ='setting.conf'){ $tmpl_path = tmpl_filepath($tmpl_path); $html = file_get_contents($tmpl_path); $conf_path = tmpl_filepath($conf_path); if(file_exists($conf_path)){ $html = tmpl_replace($html,$conf_path); } $html = tmpl_replace($html,TMPL_DEFAULT_CONF); //不使用タグのコメントアウト化 $html = str_replace('<%','',$html); return $html; } function tmpl_view($tmpl_path,$conf_path ="setting.conf"){ $html = tmpl_main($tmpl_path,$conf_path); print($html); } //パンくずリスト function tmpl_pagemap(){ $url = $_SERVER['REQUEST_URI']; $url = rtrim($url,'/'); $root = $_SERVER['DOCUMENT_ROOT']; $list = explode('/',$url); $prev = ''; $urllist = array(); foreach($list as $pg){ $prev .= $pg.'/'; $urllist[] = $prev; } $html = '
    '; foreach($urllist as $url){ $title_fp = $root.$url.'title.txt'; $title = 'none'; if(file_exists($title_fp)){ $title = file_get_contents($title_fp); } $html .= '
  1. '.$title.'
  2. '; } $html .= '
'; return $html; } function tmpl_join_path($dir, $file){ return rtrim($dir,'\\/').'/'.trim($file,'\\/'); } ?>