<? Php /*************************************** **************************************** ** * Template) * Last modification time: 2004.4.07 used in this forum * * * **************************************** **************************************** **/ Class Template {// $ This-> $ template: Save template data. Var $ template = ''; // Template path. Var $ tpl_path = ''; // Template prefix (style name ). Var $ tpl_prefix = ''; // Cache path (Compiled path ). Var $ cache_path = ''; // Css file path. Var $ css_path = ''; // Header file path. Var $ header_path = ''; // Footer file path Var $ footer_path = ''; /** * Initialize the template path. */ Function Template ($ root = 'default ') { // Template prefix (style name ). $ This-> tpl_prefix = $ root; // Template file path. $ This-> tpl_path = './templates/'. $ root .'/'; // Generated PHP file storage path. $ This-> cache_path = './template_data/'. $ this-> tpl_prefix .'_'; Return true; } /** * Chk_cache: Check whether the template after "Compilation" needs to be updated. Determine whether the "Compilation" file exists at the last modification time. */ Function chk_cache ($ tpl_index) { $ Tpl_file = $ this-> tpl_path. $ tpl_index. '.html '; $ Cache_file = $ this-> cache_path. $ tpl_index. '. php '; // Determine whether an update is required. If (! File_exists ($ cache_file )) { Return true; } Elseif (filemtime ($ tpl_file)> filemtime ($ cache_file )) { Return true; } } /** * Output template file. */ Function parse_tpl ($ tpl_index, $ message = '') { Return $ this-> cache_path. $ tpl_index. '. php '; } /** * Load the template file. */ Function load_tpl ($ tpl_index) { $ Tpl_file = $ this-> tpl_path. $ tpl_index. '.html '; $ Fp = fopen ($ tpl_file, 'R '); $ This-> template = fread ($ fp, filesize ($ tpl_file )); Fclose ($ fp ); } /** * Replace the variable and compile the template. */ Function write_cache ($ tpl_index) { $ Cache_file = $ this-> cache_path. $ tpl_index. '. php '; // Variable display. $ This-> template = preg_replace ("/(\ {=) (. + ?) (\})/Is "," <? =\\ 2?> ", $ This-> template ); // UI Language replacement. $ This-> template = preg_replace ("/\ {lang + (. + ?) \}/Ies "," \ $ lang ['main'] ['\ 1'] ", $ this-> template ); $ Fp = fopen ($ cache_file, 'w '); Flock ($ fp, 3 ); Fwrite ($ fp, $ this-> template ); Fclose ($ fp ); } /** * Replace block. */ Function assign_block ($ search, $ replace) { $ This-> template = str_replace ($ search, $ replace, $ this-> template ); } } ?> |