Index: /trunk/blocks/recent_comments_block.php
===================================================================
--- /trunk/blocks/recent_comments_block.php	(revision 45)
+++ /trunk/blocks/recent_comments_block.php	(revision 46)
@@ -66,34 +66,4 @@
 		require_once $mydirpath.'/include/xpress_block_render.php';
 		return xpress_block_render($mydirname,$block_function_name,$options);
-/*
-
-		$mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
-		$disp_count = empty( $options[1] ) ? '10' : $options[1] ;
-		$disp_length = empty( $options[2] ) ? '30' : $options[2] ;
-		$selected = array_slice($options,3); // get allowed cats
-		
-		$mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
-		global $wpdb;
-		
-		if (!is_null($wpdb)){
-			require_once $mydirpath.'/include/xpress_block_theme.php';
-			xpress_block_css_set($mydirname);
-			
-			$block_theme_file = get_block_file_path($mydirname,'recent_comments_block');
-			require_once $block_theme_file;
-			$block = recent_comments_block($options);
-			
-			require_once $mydirpath.'/include/xoops_block_cache.php';
-			$my_name = basename( __FILE__ );
-			$blockID =get_block_id($mydirname,$my_name,$options);			
-			xpress_block_cache_write($mydirname,'recent_comments_block'. $blockID, $block);
-		} else {
-			require_once $mydirpath.'/include/xoops_block_cache.php';
-			$my_name = basename( __FILE__ );
-			$blockID =get_block_id($mydirname,$my_name,$options);			
-			$block = xpress_block_cache_read($mydirname,'recent_comments_block'. $blockID);
-		}
-		return 	$block;
-*/
 	}
 }
Index: /trunk/include/xpress_block_render.php
===================================================================
--- /trunk/include/xpress_block_render.php	(revision 45)
+++ /trunk/include/xpress_block_render.php	(revision 46)
@@ -38,16 +38,22 @@
 	function get_xpress_theme_name($mydirname)
 	{
-		$xoopsDB =& Database::getInstance();
-		$wp_prefix = $mydirname;
-		if ($wp_prefix == 'wordpress') $wp_prefix = 'wp';
+		global $wpdb;
+		
+		if (is_null($wpdb)){
+			$xoopsDB =& Database::getInstance();
+			$wp_prefix = $mydirname;
+			if ($wp_prefix == 'wordpress') $wp_prefix = 'wp';
 
-		$module_tbl = $xoopsDB->prefix($wp_prefix).'_options';	
-		$theme_name = '';	
+			$module_tbl = $xoopsDB->prefix($wp_prefix).'_options';	
+			$theme_name = '';	
 
-		$sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
-		$result =  $xoopsDB->query($sql, 0, 0);
-		if ($xoopsDB->getRowsNum($result)  > 0){
-			$row = $xoopsDB->fetchArray($result);
-			$theme_name = $row['option_value'];
+			$sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
+			$result =  $xoopsDB->query($sql, 0, 0);
+			if ($xoopsDB->getRowsNum($result)  > 0){
+				$row = $xoopsDB->fetchArray($result);
+				$theme_name = $row['option_value'];
+			}
+		} else {
+			$theme_name = get_option('template');
 		}
 		return $theme_name;
@@ -106,6 +112,7 @@
 			require_once $block_theme_file;
 			$block = $call_theme_function_name($options);		//The block name and the called function name should be assumed to be the same name. 
-			
-			xpress_block_cache_write($mydirname,$cache_title. $blockID, $block);
+
+// Not Cache Write Now.  Becose Cache Write On WordPress Event			
+//			xpress_block_cache_write($mydirname,$cache_title. $blockID, $block);  
 		} else {
 			$block = xpress_block_cache_read($mydirname,$cache_title. $blockID);
Index: /trunk/wp-content/plugins/xpressme/include/custom_functions.php
===================================================================
--- /trunk/wp-content/plugins/xpressme/include/custom_functions.php	(revision 45)
+++ /trunk/wp-content/plugins/xpressme/include/custom_functions.php	(revision 46)
@@ -133,3 +133,77 @@
 		echo $ret;	
 }
+function xpress_substr($str, $start, $length, $trimmarker = '...')
+{
+    if (function_exists('mb_substr')){
+        $str2 = mb_substr( $str , $start , $length);
+        return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
+    } else {
+        return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
+    }
+}
+// xoops db
+function get_xpress_dir_path()
+{
+	return ABSPATH;
+}
+
+function get_xpress_dir_name()
+{
+	return basename(ABSPATH);
+}
+
+function get_wp_prefix_only()
+{
+	$dir_name = get_xpress_dir_name();
+	$prefix = $dir_name;
+	if ($prefix == 'wordpress') $prefix = 'wp';
+	
+	$prefix = $prefix . '_';
+	return $prefix;
+}
+
+function get_xoops_prefix()
+{
+	global $wpdb;
+	
+	$prefix = $wpdb->prefix;
+	$ret = str_replace(get_wp_prefix_only(),'',$prefix);
+	return $ret;
+}
+
+function get_xpress_modid()
+{
+	global $xoops_db;
+	
+	$modulename = get_xpress_dir_name();	
+	$sql = "SELECT mid FROM " . get_xoops_prefix() . "modules WHERE dirname = '$modulename'";
+	$mid = $xoops_db->get_var($sql);
+	return $mid;	
+}
+
+function block_cache_refresh()
+{
+	global $xoops_db;
+	$mid = get_xpress_modid();
+	$sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid";
+	$blocks = $xoops_db->get_results($sql);
+	$mydirname = get_xpress_dir_name();
+	require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
+
+
+	foreach($blocks as $block){
+		$func_file = $block->func_file;
+		$call_theme_function_name = str_replace(".php", "", $func_file);
+		$inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
+		$cache_title = str_replace(".php", "", $func_file);
+		$blockID = $block->bid;
+		$options = explode("|", $block->options);
+					
+		$block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
+		require_once $block_theme_file;
+		$block_render = $call_theme_function_name($options);		//The block name and the called function name should be assumed to be the same name. 			
+		xpress_block_cache_write($mydirname,$cache_title. $blockID, $block_render);
+	}
+}
+
 ?>
Index: /trunk/wp-content/plugins/xpressme/xpressme.php
===================================================================
--- /trunk/wp-content/plugins/xpressme/xpressme.php	(revision 45)
+++ /trunk/wp-content/plugins/xpressme/xpressme.php	(revision 46)
@@ -9,5 +9,14 @@
 */
 require_once('xpressme_class.php');
+require_once dirname( __FILE__ ).'/include/custom_functions.php' ;
+
+
 $xpessme = new XPressME_Class();
+
+
+$xoops_db = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
+$xoops_db->prefix = get_xoops_prefix();
+$xoops_db->tables = array('modules', 'newblocks', 'users');
+
 
 add_action('admin_menu', array(&$xpessme, 'add_option_page'));
@@ -17,5 +26,13 @@
 	remove_action( 'pre_post_update', 'wp_save_post_revision' );			// Not Save Post Revision
 }
+add_action("comment_post",	"block_cache_refresh");
+add_action("edit_comment",	"block_cache_refresh");
+add_action("delete_comment","block_cache_refresh");
+add_action("delete_post",	"block_cache_refresh");
+add_action("publish_post",	"block_cache_refresh");
+add_action("edit_post",		"block_cache_refresh");
+add_action("private_to_published",	"block_cache_refresh");
+add_action("wp_set_comment_status" , "block_cache_refresh");
+
 //require_once('../include/custom_functions.php');
-require_once dirname( __FILE__ ).'/include/custom_functions.php' ;
 ?>
Index: /trunk/wp-content/themes/xpress_default/blocks/recent_comments_block_theme.php
===================================================================
--- /trunk/wp-content/themes/xpress_default/blocks/recent_comments_block_theme.php	(revision 45)
+++ /trunk/wp-content/themes/xpress_default/blocks/recent_comments_block_theme.php	(revision 46)
@@ -11,6 +11,4 @@
 	$mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
 	
-	$myts =& MyTextSanitizer::getInstance();
-
 	$this_url = '/modules/'. $mydirname;
 	$call_url = $_SERVER['REQUEST_URI'];
