Index: trunk/include/oninstall.php
===================================================================
--- trunk/include/oninstall.php	(revision 81)
+++ trunk/include/oninstall.php	(revision 89)
@@ -87,5 +87,5 @@
 //   	require_once($mydirpath . '/include/user_sync.php');
 	$sync_messg = '';
-	xpress_user_sync($ID,$sync_messg);		//this function in XPressME plugin 
+//	user_sync_to_wordpress($ID,$sync_messg);		//this function in XPressME plugin 
 
 	// Set Default data
@@ -138,7 +138,45 @@
 	$sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')";
 	$wpdb->query($sql);
-	// make templates
-//	include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates.php' ;
-//	$ret = xpress_install_templates($mid,$mydirname);
+	
+	// TEMPLATES
+	$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
+	$tpl_path = dirname( dirname( __FILE__ ) ).'/templates/source' ;
+	if( $handler = @opendir( $tpl_path . '/' ) ) {
+		while( ( $file = readdir( $handler ) ) !== false ) {
+			if( substr( $file , 0 , 1 ) == '.' ) continue ;
+			$file_path = $tpl_path . '/' . $file ;
+			if( is_file( $file_path ) ) {
+				$mtime = intval( @filemtime( $file_path ) ) ;
+				$tplfile =& $tplfile_handler->create() ;
+				$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
+				$tplfile->setVar( 'tpl_refid' , $mid ) ;
+				$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
+				$tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
+				$tplfile->setVar( 'tpl_desc' , '' , true ) ;
+				$tplfile->setVar( 'tpl_module' , $mydirname ) ;
+				$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
+				$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
+				$tplfile->setVar( 'tpl_type' , 'block' ) ;
+				if( ! $tplfile_handler->insert( $tplfile ) ) {
+					$ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span><br />';
+				} else {
+					$tplid = $tplfile->getVar( 'tpl_id' ) ;
+					$ret[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)<br />';
+					// generate compiled file
+					include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
+					include_once XOOPS_ROOT_PATH.'/class/template.php' ;
+					if( ! xoops_template_touch( $tplid ) ) {
+						$ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span><br />';
+					} else {
+						$ret[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span><br />';
+					}
+				}
+			}
+		}
+		closedir( $handler ) ;
+	}
+	include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
+	include_once XOOPS_ROOT_PATH.'/class/template.php' ;
+	xoops_template_clear_module_cache( $mid ) ;
 
 	return true ;
Index: trunk/include/onupdate.php
===================================================================
--- trunk/include/onupdate.php	(revision 81)
+++ trunk/include/onupdate.php	(revision 89)
@@ -132,9 +132,46 @@
 	}
 	
-	clean_template($mydirname,$xpress_version);
-
-	// update templates
-//	include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates.php' ;
-//	$msgs = xpress_update_templates($mid,$mydirname);
+	// TEMPLATES (all templates have been already removed by modulesadmin)
+
+	$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
+	$tpl_path = dirname( dirname( __FILE__ ) ).'/templates/source' ;
+	if( $handler = @opendir( $tpl_path . '/' ) ) {
+		while( ( $file = readdir( $handler ) ) !== false ) {
+			if( substr( $file , 0 , 1 ) == '.' ) continue ;
+			$file_path = $tpl_path . '/' . $file ;
+			if( is_file( $file_path ) ) {
+				$mtime = intval( @filemtime( $file_path ) ) ;
+				$tplfile =& $tplfile_handler->create() ;
+				$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
+				$tplfile->setVar( 'tpl_refid' , $mid ) ;
+				$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
+				$tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ;
+				$tplfile->setVar( 'tpl_desc' , '' , true ) ;
+				$tplfile->setVar( 'tpl_module' , $mydirname ) ;
+				$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
+				$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
+				$tplfile->setVar( 'tpl_type' , 'block' ) ;
+				if( ! $tplfile_handler->insert( $tplfile ) ) {
+					$msgs[] = '<span style="color:#flockf0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span>';
+				} else {
+					$tplid = $tplfile->getVar( 'tpl_id' ) ;
+					$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)';
+					// generate compiled file
+					include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
+					include_once XOOPS_ROOT_PATH.'/class/template.php' ;
+					if( ! xoops_template_touch( $tplid ) ) {
+						$msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span>';
+					} else {
+						$msgs[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span>';
+					}
+				}
+			}
+		}
+		closedir( $handler ) ;
+	}
+	include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
+	include_once XOOPS_ROOT_PATH.'/class/template.php' ;
+	xoops_template_clear_module_cache( $mid ) ;
+
 	
 	return true ;
@@ -176,47 +213,4 @@
 endif;
 
-if( ! function_exists( 'clean_template' ) ) :
-function clean_template($mydirname,$xpress_ver){
-		global $xoopsModule;
-		
-		$var = floatval($xpress_ver);
-		switch ($var){
-			case ($var >= 0.62):
-				$temp_file = "'". $mydirname . "_home.html','" . $mydirname. "_index.html','" . $mydirname . "_search.html','" . $mydirname . "_single.html'";
-				break;
-			case ($var >= 0.60):
-				$temp_file = "'xpress_header.html','xpress_home.html','xpress_index.html','xpress_search.html','xpress_sidebar.html'";
-				break;
-			default:
-				$temp_file = 'all';
-		}
-		
-		if ($temp_file != 'all'){			
-			$xoopsDB =& Database::getInstance();
-			$db_tplfile = $xoopsDB->prefix('tplfile');
-			$db_tplsource = $xoopsDB->prefix('tplsource');
-
-			$sql = "SELECT * FROM $db_tplfile WHERE tpl_module = '$mydirname' AND NOT tpl_file IN($temp_file)";
-			$res = $xoopsDB->query($sql, 0, 0);
-			if ($res === false){
-				return false;
-			} else {
-				$del_array = '';
-				$i=0;
-				while($row = $xoopsDB->fetchArray($res)){
-					if (!empty($del_array))
-					$del_array .= ',';
-					$del_array .= $row['tpl_id'];
-				}
-				if(!empty($del_array)){
-					$del_tplfile  = "DELETE FROM $db_tplfile WHERE tpl_id IN ($del_array)";
-					$result = $xoopsDB->query($del_tplfile, 0, 0);
-					$del_tplsource  = "DELETE FROM $del_tplsource WHERE tpl_id IN ($del_array)";
-					$result = $xoopsDB->query($del_tplfile, 0, 0);
-				}
-			}
-		}
-}
-endif;
 
 if( ! function_exists( 'enhanced_table_check' ) ) :
Index: trunk/include/xpress_block_render.php
===================================================================
--- trunk/include/xpress_block_render.php	(revision 81)
+++ trunk/include/xpress_block_render.php	(revision 89)
@@ -104,6 +104,6 @@
 		$inc_theme_file_name = $call_theme_function_name . '_theme.php';
 		$cache_title = str_replace(".php", "", $block_function_name);
-		$blockID =get_block_id($mydirname,$func_file,$options);			
-					
+		$blockID =get_block_id($mydirname,$func_file,$options);		
+
 		if (!is_null($wpdb)){
 			xpress_block_css_set($mydirname);
@@ -119,5 +119,10 @@
 			$block = $xml['block'];
 		}
-		return 	$block;
+
+		$templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
+		$tpl =& new XoopsTpl() ;
+		$tpl->assign( 'block' , $block ) ;
+		$ret['content'] = $tpl->fetch( $templates_file ) ;
+		return $ret ;
 	}
 	
