0 && strpos($args[$args_count - 1], "\r") !== false); //インラインの最後の{}が空の時は削除 if ($is_inline && $args[$args_count - 1] == '') unset($args[$args_count - 1]); $root = isset($vars['page']) ? $vars['page'] : ''; //テンプレートページ名の取得 // strip_bracket() is not necessary but compatible //$page = isset($args[0]) ? get_fullname(strip_bracket(array_shift($args)), $root) : ''; $temp_name = isset($args[0]) ? trim(array_shift($args)) : ''; //パラメータが|で区切られている時は分解 $separator = plugin_mtemplate_setting_get_setting('separator'); if (count($args) == 0 && strpos($temp_name, $separator) !== false) { $args = explode($separator, $temp_name); $temp_name = trim(array_shift($args)); } $page = PLUGIN_MTEMPLATE_TEMPLATEDIR . strip_bracket($temp_name); // I'm stuffed /* 同じテンプレートの複数読み込みを許可する if (isset($included[$page])) { return 'error'; } // One page, only one time, at a time //$included[$page] = TRUE; */ //自分自身のテンプレートは許可しない if ($root == $page) return plugin_mtemplate_error(': Template is myself: ' . $temp_name, $is_inline); //ページが無い if (!is_page($page)) return plugin_mtemplate_error( ': No such template: ' . $temp_name, $is_inline); if ($count > PLUGIN_MTEMPLATE_MAX) return plugin_mtemplate_error(': Limit exceeded: ', $is_inline); ++$count; // Include A page, that probably includes another pages //$get['page'] = $post['page'] = $vars['page'] = $page; if (PLUGIN_MTEMPLATE_CHECK_READABLE && !check_readable($page, false, false)) return plugin_mtemplate_error( ': Template is not readable: ' . $temp_name, $is_inline); //テンプレートの読み込み $body = get_source($page); //パラメータが複数行の時は、工夫が必要 if ($is_multiline) { $body = implode('', $body); } $params = plugin_mtemplate_get_parameters_from_array($args); //テンプレートページの置換 foreach ($params as $key => $val) { $body = str_replace('{{{' . $key . '}}}', $val, $body); } //HTMLに変換 if ($is_inline) $body = make_link($body); else $body = convert_html($body); //$get['page'] = $post['page'] = $vars['page'] = $root; return $body; } function plugin_mtemplate_get_parameters_from_array(&$args) { $params = array(); $paramcount = 1; $equal = plugin_mtemplate_setting_get_setting('equal'); while (($param = array_shift($args)) !== null) { $e_ary = explode($equal, $param, 2); if (count($e_ary) == 2) { $params[trim($e_ary[0])] = str_replace("\r", "\n", trim($e_ary[1])); } else { $params["$paramcount"] = str_replace("\r", "\n", trim($e_ary[0])); } $paramcount++; } return $params; } //エラーの時 function plugin_mtemplate_error($msg, $is_inline) { if (!empty($msg)) $msg = ($is_inline ? '&mtemplate();' : '#mtemplate()') . $msg; $msg = htmlspecialchars($msg); if ($is_inline) return $msg; else return $msg . '
'; } //mtemplate_setting function plugin_mtemplate_setting_get_setting($name) { static $settings = array( 'separator' => PLUGIN_MTEMPLATE_DEFAULT_SEPARATOR, 'equal' => PLUGIN_MTEMPLATE_DEFAULT_EQUAL, ); if (is_array($name)) { foreach ($name as $arg) { if (($pos = strpos($arg, '=')) !== false) { $settings[strtolower(trim(substr($arg, 0, $pos)))] = trim(substr($arg, $pos + 1)); } } } else { return $settings[$name]; } } ?>