/**
  *  ビューを出力する
  *
  *  @param  string  $template   テンプレート名
  *  @param  bool    $capture    true ならば出力を表示せずに返す
  *
  *  @access public
  */
 function perform($template = null, $capture = false)
 {
     if ($template === null && $this->template === null) {
         return Ethna::raiseWarning('template is not defined');
     }
     if ($template !== null) {
         $this->template = $template;
     }
     if (!is_absolute_path($this->template)) {
         $this->template = sprintf('%s%s', $this->template_dir, $this->template);
     }
     if (is_readable($this->template)) {
         ob_start();
         include $this->template;
         $captured = ob_get_contents();
         ob_end_clean();
         if ($capture === true) {
             return $captured;
         } else {
             echo $captured;
         }
     } else {
         return Ethna::raiseWarning('template not found ' . $this->template);
     }
 }
 /**
  *  ビューを出力する
  *
  *  @param  string  $template   テンプレート名
  *  @param  bool    $capture    true ならば出力を表示せずに返す
  *
  *  @access public
  */
 function perform($template = null, $capture = false)
 {
     if ($template === null && $this->template === null) {
         return Ethna::raiseWarning('template is not defined');
     }
     if ($template !== null) {
         $this->template = $template;
     }
     if (is_absolute_path($this->template) && is_readable($this->template) || is_readable($this->template_dir . $this->template)) {
         if ($capture === true) {
             $captured = $this->engine->fetch($this->template);
             return $captured;
         } else {
             $this->engine->display($this->template);
         }
     } else {
         return Ethna::raiseWarning('template not found ' . $this->template);
     }
 }
/**
 *  グローバルユーティリティ関数: include_pathを検索しつつfile_exists()する
 *
 *  @param  string  $path               ファイル名
 *  @param  bool    $use_include_path   include_pathをチェックするかどうか
 *  @return bool    true:有り false:無し
 */
function file_exists_ex($path, $use_include_path = true)
{
    if ($use_include_path == false) {
        return file_exists($path);
    }
    // check if absolute
    if (is_absolute_path($path)) {
        return file_exists($path);
    }
    $include_path_list = explode(PATH_SEPARATOR, get_include_path());
    if (is_array($include_path_list) == false) {
        return file_exists($path);
    }
    foreach ($include_path_list as $include_path) {
        if (file_exists($include_path . DIRECTORY_SEPARATOR . $path)) {
            return true;
        }
    }
    return false;
}
Example #4
0
 /**
  *  ビューを出力する
  *
  *  @param  string  $template   テンプレート名
  *  @param  bool    $capture    true ならば出力を表示せずに返す
  *
  *  @access public
  */
 public function perform($template = null, $capture = false)
 {
     if ($template === null && $this->template === null) {
         return Ethna::raiseWarning('template is not defined');
     }
     if ($template !== null) {
         $this->template = $template;
     }
     set_error_handler(null);
     if (is_absolute_path($this->template) && is_readable($this->template) || is_readable($this->template_dir . $this->template)) {
         if ($capture === true) {
             $captured = $this->engine->fetch($this->template);
             return $captured;
         } else {
             header('X-MemoryUsage: ' . memory_get_usage());
             $this->engine->display($this->template);
         }
     } else {
         throw new \Exception('template not found ' . $this->template_dir . $this->template);
     }
 }
Example #5
0
 /**
  *  Display the template
  *
  *  @param  string  $template   template name
  *  @param  bool    $capture    if true, not display but return as string
  *
  *  @access public
  */
 public function perform($template = null, $capture = false)
 {
     if ($template === null && $this->template === null) {
         return Ethna::raiseWarning('template is not defined');
     }
     if ($template !== null) {
         $this->template = $template;
     }
     try {
         if (is_absolute_path($this->template) && is_readable($this->template) || is_readable($this->template_dir . $this->template)) {
             if ($capture === true) {
                 $captured = $this->engine->fetch($this->template);
                 return $captured;
             } else {
                 $this->engine->display($this->template);
             }
         } else {
             return Ethna::raiseWarning('template not found ' . $this->template);
         }
     } catch (SmartyCompilerException $e) {
         return Ethna::raiseWarning("smarty compile error: msg='{$e->getMessage()}'", 500);
     }
 }
 private function cleanUrl($url, $modulePath)
 {
     if (!is_absolute_path($url)) {
         $url = absolute_from_script($modulePath) . DIRECTORY_SEPARATOR . trim($url, DIRECTORY_SEPARATOR);
     }
     $expl = explode(DIRECTORY_SEPARATOR, $url);
     $urlArr = [];
     foreach ($expl as $dir) {
         if ($dir !== '') {
             $urlArr[] = $dir;
         }
     }
     return DIRECTORY_SEPARATOR . join(DIRECTORY_SEPARATOR, $urlArr);
 }
Example #7
0
function absolute_from_script($path)
{
    if (is_absolute_path($path)) {
        return $path;
    } else {
        $mainScript = $_SERVER['SCRIPT_FILENAME'];
        $mainScriptExpl = explode(DIRECTORY_SEPARATOR, $mainScript);
        array_pop($mainScriptExpl);
        $mainScriptRoot = join(DIRECTORY_SEPARATOR, $mainScriptExpl);
        $ret = $mainScriptRoot . DIRECTORY_SEPARATOR . $path;
        return $ret;
    }
}