Index: trunk/wp-content/plugins/xpressme/include/custom_functions.php
===================================================================
--- trunk/wp-content/plugins/xpressme/include/custom_functions.php	(revision 44)
+++ 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 44)
+++ 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 44)
+++ 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'];
