Index: tags/Ver2.2.2/xpressme_integration_kit/admin/index.php
===================================================================
--- trunk/xpressme_integration_kit/admin/index.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/admin/index.php	(revision 504)
@@ -164,5 +164,6 @@
 	global $xoopsModule;
 	include(dirname(__FILE__) . '/../wp-includes/version.php');
-	
+	require_once dirname(dirname( __FILE__ )).'/class/config_from_xoops.class.php' ;
+
 	if ($is_report) {
 		echo "******** "  . _AM_XP2_SYSTEM_INFO . "********" . "<br />\n";
@@ -190,7 +191,13 @@
 		echo ( extension_loaded( 'xml' )) ? "ON" : "OFF";
 		echo "<br />\n";
-		echo "memory_limit:   " ;
+		echo "default memory_limit:   " ;
 		echo  ini_get( 'memory_limit' );
 		echo "<br />\n";
+		$xoops_config = new ConfigFromXoops;
+		$xoops_config->xpress_set_memory_limmit();
+		echo "change memory_limit:   " ;
+		echo  ini_get( 'memory_limit' );
+		echo "<br />\n";
+		
 		echo "post_max_size:   " ;
 		echo  ini_get( 'post_max_size' );
@@ -258,7 +265,13 @@
 		echo ( extension_loaded( 'xml' )) ? "ON" : "OFF";
 		echo "</text><br />";
-		echo "<label>memory_limit:</label><text>";
+		echo "<label>default memory_limit:</label><text>";
 		echo  ini_get( 'memory_limit' );
 		echo "</text><br />";
+		$xoops_config = new ConfigFromXoops;
+		$xoops_config->xpress_set_memory_limmit();
+		echo "<label>change memory_limit:</label><text>";
+		echo  ini_get( 'memory_limit' );
+		echo "</text><br />";
+
 		echo "<label>post_max_size:</label><text>";
 		echo  ini_get( 'post_max_size' );
@@ -571,10 +584,9 @@
 function xpress_block_state($is_report = false)
 {
-	require_once dirname(dirname( __FILE__ )).'/class/config_from_xoops.class.php' ;
-	$xoops_config = new ConfigFromXoops;
-	
+	$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
+
 	include_once(dirname(dirname(__FILE__) ). '/class/check_blocks_class.php');
 	$xoops_block_check =& xoops_block_check::getInstance();
-	$xoops_block_check->check_blocks($xoops_config->module_name);
+	$xoops_block_check->check_blocks($mydirname);
 	if ($is_report){
 		echo "******** " . _AM_XP2_BLOCK_STATS . "********" . "<br />\n";
Index: tags/Ver2.2.2/xpressme_integration_kit/admin/menu.php
===================================================================
--- trunk/xpressme_integration_kit/admin/menu.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/admin/menu.php	(revision 504)
@@ -58,4 +58,6 @@
 $adminmenu[$i++]['link'] = "index.php";
 
+$adminmenu[$i]['title'] = _MI_XP2_TO_UPDATE ;
+$adminmenu[$i++]['link'] = "admin/update.php";
 
 ?>
Index: tags/Ver2.2.2/xpressme_integration_kit/admin/update.php
===================================================================
--- tags/Ver2.2.2/xpressme_integration_kit/admin/update.php	(revision 504)
+++ tags/Ver2.2.2/xpressme_integration_kit/admin/update.php	(revision 504)
@@ -0,0 +1,12 @@
+<?php
+	$mydirname = basename(dirname( dirname( __FILE__ ) )) ;
+	$mydirpath = dirname( dirname( __FILE__ ) ) ;
+	require_once '../../../include/cp_header.php' ;
+
+	if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
+		$url = XOOPS_URL.'/modules/legacy/admin/index.php?action=ModuleUpdate&dirname=' . $mydirname;
+	} else {
+		$url = XOOPS_URL.'/modules/system/admin.php?fct=modulesadmin&op=update&module=' . $mydirname ;
+	}
+	header('Location: ' . $url);
+?>
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/archives_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/archives_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/archives_block.php	(revision 504)
@@ -27,6 +27,7 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
 
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";
 		$a_month = _MB_XP2_ARC_MONTH ;
@@ -62,5 +63,5 @@
 		$form .=  "</select><br/>";
 		
-		$form .= "<br />" . _MB_XP2_COUNT_ZERO_ALL . "  <input type='text' name='options[3]' value='" . $limit . "' />";
+		$form .= "<br />" . _MB_XP2_COUNT_ZERO_ALL . "  <input type='text' size='3' name='options[3]' value='" . $limit . "' />";
 		$form .= "<br />" . yes_no_radio_option('options[4]', _MB_XP2_SHOW_NUM_OF_POST , $show_post_count);
 		$form .= "<br />" . yes_no_radio_option('options[5]', _MB_XP2_SHOW_DROP_DOWN , $drop_down);
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/authors_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/authors_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/authors_block.php	(revision 504)
@@ -27,6 +27,7 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
 			
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";
 		$form .= yes_no_radio_option('options[2]', _MB_XP2_SHOW_NUM_OF_POST , $optioncount);
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/block_common.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/block_common.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/block_common.php	(revision 504)
@@ -103,5 +103,5 @@
 
     $option = "<option value=\"0\" ";
-    if ($isAll) $form .= " selected=\"selected\"";
+    if ($isAll) $option .= " selected=\"selected\"";
     $option .= ">"._MB_XP2_ALL ."</option>";
 
@@ -146,4 +146,64 @@
 endif;
 
+if(!function_exists("block_template_setting")):
+function block_template_setting($mydirname,$option_name = '',$value='')
+{
+	$temp_parm = explode(':' , $value);
+	if (empty($temp_parm[1])) {
+		$filename=$temp_parm[0];
+		$temp_type = 'db';
+	} else  {
+		$filename=$temp_parm[1];
+		$temp_type = $temp_parm[0];
+	}
+
+	$none_prefix_filename = '';
+	$pattern = '^' . $mydirname . '_(.*).html';
+	if (preg_match('/' . $pattern . '/' , $filename, $match)){ // file prefix check
+		$none_prefix_filename = $match[1];
+	}
+	
+	$output = _MB_XP2_THISTEMPLATE . "\n";
+	$output .= 	'<input type="hidden" size="50" name="' . $option_name . '" value="' . $value .'"/>' . "\n";
+    $output .= '&nbsp;<select name="template_type" onclick="Template_Make()">' ."\n";
+	switch ($temp_type){
+		case 'db':
+		case 'DB':
+			$output .=  '<option value="0" selected="selected">db</option>';
+			$output .=  '<option value="1">file</option>';
+			break;
+		default:
+			$output .=  '<option value="0">db</option>';
+			$output .=  '<option value="1" selected="selected">file</option>';
+	}
+	$output .= '</select>';
+	$output .= '<b>:'.$mydirname . '_</b>';
+	$output .= '<input type="text" size="30" name="none_prefix_file" value="'. $none_prefix_filename. '"  onChange="Template_Make()"/><b>.html</b><br />';
+    $output .= '
+<script type="text/javascript">
+	function Template_Make(){
+		var type_element = document.getElementsByName("template_type").item(0);
+		var name_element = document.getElementsByName("none_prefix_file").item(0);
+		var real_element = document.getElementsByName("' .$option_name . '").item(0);
+
+		var file_name = "' . $mydirname . '_" + name_element.value + ".html";
+		if (type_element.value ==0) var tmp_type = "db:"; else var tmp_type = "file:";
+		real_element.value = tmp_type + file_name;
+	}
+</script>
+';
+    
+    return $output;
+
+}
+endif;
+if(!function_exists("javascript_check")):
+function javascript_check()
+{
+	$out  = '<div id="JSNG"><p style="color: red"><b>' . _MB_XP2_NO_JSCRIPT . '</b></p><br /></div>';
+	$out .= '<script>  document.getElementById("JSNG").style.display = "none";</script>';
+	return $out;
+}
+endif;
 
 ?>
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/calender_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/calender_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/calender_block.php	(revision 504)
@@ -25,6 +25,7 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
 
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";
 		$form .= _MB_XP2_SUN_COLOR .": <input type='text' name='options[2]' value='" . $sun_color . "' /><br />\n";
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/category_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/category_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/category_block.php	(revision 504)
@@ -34,6 +34,7 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');	
 
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";
 		$form .= _MB_XP2_CAT_ALL_STR . "  <input type='text' name='options[2]' value='" . $show_option_all . "' /><br />";
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/enhanced_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/enhanced_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/enhanced_block.php	(revision 504)
@@ -19,12 +19,15 @@
 		$mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
 		$this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_enhanced_block.html' : trim( $options[1] );
+	    $form .= _MB_XP2_THISTEMPLATE . "<input type='text' size='50' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
 		$include_file = empty( $options[2] ) ? '' : $options[2] ;
 		
+		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
 
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";
 		$form .= _MB_XP2_ENHACED_FILE .":<br />\n";
-		$form .= '&emsp;' . _MB_XP2_FILE_NAME . ": my_<input type='text' name='options[2]' value='" . $include_file . "' />_block.php<br>\n";
+		$form .= '&emsp;' . _MB_XP2_FILE_NAME . ": <b>my_</b><input type='text' name='options[2]' value='" . $include_file . "' /><b>_block.php</b><br>\n";
 		$form .= '&emsp;' . _MB_XP2_MAKE_ENHACED_FILE . "<br>\n";
 		return $form;
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/meta_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/meta_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/meta_block.php	(revision 504)
@@ -30,6 +30,7 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');	
 
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";
 		$form .= yes_no_radio_option('options[2]', _MB_XP2_META_WP_LINK , $wp_link) . "<br />\n";
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/page_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/page_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/page_block.php	(revision 504)
@@ -34,6 +34,7 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
 
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";
 		$form .= _MB_XP2_PAGE_ORDERBY .": ";
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/popular_posts_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/popular_posts_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/popular_posts_block.php	(revision 504)
@@ -28,7 +28,7 @@
 		
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
-
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />\n";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />\n";
 		$form .= _MB_XP2_COUNT .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />\n";
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/recent_comments_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/recent_comments_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/recent_comments_block.php	(revision 504)
@@ -29,9 +29,10 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
 		
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />\n";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";
-		$form .= _MB_XP2_COUNT .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />\n";
-		$form .= _MB_XP2_LENGTH .": <input type='text' name='options[3]' value='" . $disp_length . "' /><br />\n";
+		$form .= _MB_XP2_COUNT .": <input type='text' size='3' name='options[2]' value='" . $disp_count . "' /><br />\n";
+		$form .= _MB_XP2_LENGTH .": <input type='text' size='3' name='options[3]' value='" . $disp_length . "' /><br />\n";
 		$form .= _MB_XP2_DATE_FORMAT .": <input type='text' name='options[4]' value='" . $date_format . "' /><br />\n";
 		$form .= _MB_XP2_TIME_FORMAT .": <input type='text' name='options[5]' value='" . $time_format . "' /><br />\n";
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/recent_posts_content_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/recent_posts_content_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/recent_posts_content_block.php	(revision 504)
@@ -33,7 +33,9 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
 		
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
-		$form .= _MB_XP2_COUNT .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />\n";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
+		$form .= "<br />";
+		$form .= _MB_XP2_COUNT .": <input type='text' size='3' name='options[2]' value='" . $disp_count . "' /><br />\n";
 		$form .= yes_no_radio_option('options[3]', _MB_XP2_P_EXCERPT , $excerpt) . "<br />\n";
 		$form .= _MB_XP2_P_EXCERPT_SIZE .": <input type='text' name='options[4]' value='" . $excerpt_size . "' /><br />\n";
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/recent_posts_list_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/recent_posts_list_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/recent_posts_list_block.php	(revision 504)
@@ -30,10 +30,11 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
 
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />\n";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />\n";	
-		$form .= _MB_XP2_COUNT .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />\n";
-		$form .= _MB_XP2_REDNEW_DAYS .": <input type='text' name='options[3]' value='" . $disp_red . "' /><br />\n";
-		$form .= _MB_XP2_GREENNEW_DAYS .": <input type='text' name='options[4]' value='" . $disp_green . "' /><br />\n";
+		$form .= _MB_XP2_COUNT .": <input type='text' size='3' name='options[2]' value='" . $disp_count . "' /><br />\n";
+		$form .= _MB_XP2_REDNEW_DAYS .": <input type='text' size='3' name='options[3]' value='" . $disp_red . "' /><br />\n";
+		$form .= _MB_XP2_GREENNEW_DAYS .": <input type='text' size='3' name='options[4]' value='" . $disp_green . "' /><br />\n";
 		$form .= _MB_XP2_DATE_FORMAT .": <input type='text' name='options[5]' value='" . $date_format . "' /><br />\n";
 		$form .= _MB_XP2_TIME_FORMAT .": <input type='text' name='options[6]' value='" . $time_format . "' /><br />\n";
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/search_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/search_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/search_block.php	(revision 504)
@@ -24,8 +24,9 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php') ;
 		
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";		
-		$form .= _MB_XP2_SEARCH_LENGTH .": <input type='text' name='options[2]' value='" . $disp_count . "' /><br />";
+		$form .= _MB_XP2_SEARCH_LENGTH .": <input type='text' size='3' name='options[2]' value='" . $disp_count . "' /><br />";
 //	    $form .="<br /><input type='text' size='60' name='options[2]' value='".htmlspecialchars($this_template,ENT_QUOTES)."' />";
 
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/tag_cloud_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/tag_cloud_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/tag_cloud_block.php	(revision 504)
@@ -31,6 +31,7 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');	
 
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />";
 		$form .= _MB_XP2_CLOUD_SMALLEST .": <input type='text' size='4' name='options[2]' value='" . $smallest . "' /><br />";
Index: tags/Ver2.2.2/xpressme_integration_kit/blocks/widget_block.php
===================================================================
--- trunk/xpressme_integration_kit/blocks/widget_block.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/blocks/widget_block.php	(revision 504)
@@ -45,6 +45,7 @@
 		require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
 
-		$form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
-	    $form .= "<input type='hidden' name='options[1]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' /><br />";
+		$form  = javascript_check();
+		$form .= "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />\n";
+		$form .= block_template_setting($mydirname,'options[1]',htmlspecialchars($this_template,ENT_QUOTES));
 		$form .= "<br />" . yes_no_radio_option('options[2]', _MB_XP2_WIDGET_TITLE_SHOW , $title_show);
 		$form .= "<br />";
Index: tags/Ver2.2.2/xpressme_integration_kit/class/config_from_xoops.class.php
===================================================================
--- trunk/xpressme_integration_kit/class/config_from_xoops.class.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/class/config_from_xoops.class.php	(revision 504)
@@ -43,4 +43,7 @@
 	var $wp_version;
 	var $is_wp_me;
+	var $xoops_language;
+	var $module_id;
+	var $module_config= array();
 	
 	function __constructor()	//for PHP5
@@ -102,4 +105,7 @@
 		$this->set_wp_version();
 		$this->set_mu_current_site();
+		$this->xpress_get_module_id();
+		$this->xoops_language = $this->xpress_get_xoops_config('language');
+		$this->xpress_get_module_config();
     }
 
@@ -314,5 +320,75 @@
 		}
     }
-    
+
+	function xpress_get_xoops_config($config_name = '',$mid = 0){
+		$ret = '';
+		$cn = mysql_connect($this->xoops_db_host, $this->xoops_db_user, $this->xoops_db_pass);
+		if (!$cn) return $ret;
+		
+		$db_selected = mysql_select_db($this->xoops_db_name, $cn);
+		if ($db_selected){
+			$table_name = $this->xoops_db_prefix . '_config';
+			$sql = "SELECT conf_value AS value FROM $table_name WHERE `conf_modid` = $mid AND `conf_name` = '$config_name'";
+			if($result = mysql_query($sql)){
+				$row = mysql_fetch_assoc($result);
+				$ret = $row['value'];
+			} else {
+				$ret = $sql;
+			}
+		}
+		if( ! defined( 'XOOPS_ROOT_PATH' ) ) mysql_close($cn);
+		return $ret;
+	}
+
+	function xpress_get_module_config(){
+		$this->module_config= array();
+		$cn = mysql_connect($this->xoops_db_host, $this->xoops_db_user, $this->xoops_db_pass);
+		if (!$cn) return $ret;
+		
+		$db_selected = mysql_select_db($this->xoops_db_name, $cn);
+		if ($db_selected){
+			$table_name = $this->xoops_db_prefix . '_config';
+			$sql = "SELECT conf_name AS name, conf_value AS value FROM $table_name WHERE `conf_modid` = $this->module_id";
+			if($result = mysql_query($sql)){
+				while ($row = mysql_fetch_assoc($result)) {
+	    			$this->module_config[$row['name']] = $row['value'];
+				}
+			}
+		}
+		if( ! defined( 'XOOPS_ROOT_PATH' ) ) mysql_close($cn);
+		return $this->module_config;
+	}
+
+	function xpress_get_module_id(){
+		$this->module_id = '';
+		$cn = mysql_connect($this->xoops_db_host, $this->xoops_db_user, $this->xoops_db_pass);
+		if ($cn){
+			$db_selected = mysql_select_db($this->xoops_db_name, $cn);
+			if ($db_selected){
+				$table_name = $this->xoops_db_prefix . '_modules';
+				$sql = "SELECT mid FROM $table_name WHERE `dirname` = '$this->module_name'";
+				if($result = mysql_query($sql)){
+					$row = mysql_fetch_assoc($result);
+					$this->module_id = $row['mid'];
+				}
+			}
+			if( ! defined( 'XOOPS_ROOT_PATH' ) ) mysql_close($cn);
+		}
+		return $this->module_id;
+	}
+	
+	
+	// Set XPressME memory limit
+	function xpress_set_memory_limmit(){
+		$memory = $this->module_config['memory_limit'];
+		if (empty($memory)) return;
+ 		if ( !defined('WP_MEMORY_LIMIT') )
+			define('WP_MEMORY_LIMIT', $memory . 'M');
+		if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < abs(intval(WP_MEMORY_LIMIT)) ) )
+			@ini_set('memory_limit', WP_MEMORY_LIMIT);
+	}
+
+
+
 }
 ?>
Index: tags/Ver2.2.2/xpressme_integration_kit/include/add_xpress_config.php
===================================================================
--- trunk/xpressme_integration_kit/include/add_xpress_config.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/include/add_xpress_config.php	(revision 504)
@@ -3,4 +3,5 @@
 require_once dirname(dirname( __FILE__ )).'/class/config_from_xoops.class.php' ;
 $xoops_config = new ConfigFromXoops;
+$xoops_config->xpress_set_memory_limmit();
 require_once dirname( __FILE__ ).'/set_cash_cookie_path.php' ;
 ?>
Index: tags/Ver2.2.2/xpressme_integration_kit/include/add_xpress_process.php
===================================================================
--- trunk/xpressme_integration_kit/include/add_xpress_process.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/include/add_xpress_process.php	(revision 504)
@@ -14,15 +14,16 @@
 		$home = get_option('home');
 		$module_url = $xoops_config->module_url;
-		$guess_url = wp_guess_url();
-		$guess_url = preg_replace('/\/$/','',$guess_url);
-		
-		if($siteurl != $module_url) {
+		$module_name = $xoops_config->module_name;
+		$schema = ( isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
+		$guess_url = preg_replace('|/' . $module_name . '/.*|i', '/' . $module_name, $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
+
+		if(strcmp($siteurl,$module_url) !== 0) {
 			if (!@fclose(@fopen($siteurl . '/xoops_version.php', "r"))){
 				update_option('siteurl' , $module_url);
 			}
 		}
-		
-		if($guess_url != $home) {
-			if (!@fclose(@fopen($home . '/xoops_version.php', "r"))){
+
+		if(strcmp($guess_ur,$home) !== 0) {
+			if (@fclose(@fopen($guess_url . '/xoops_version.php', "r"))){
 				update_option('home' , $guess_url);
 			}
@@ -33,12 +34,17 @@
 require_once( dirname( __FILE__ ).'/request_url.php');
 if (is_xpress_index_page_call()){
+	//$_SERVER['REQUEST_METHOD'] = 'POST' is
 	//When notifying by a private message, Notification_reserve_send();
 	//it is evaded that the data base becomes read-only as a result of the check on the referrer and the method. 
+	$request_method =  (isset($_SERVER['REQUEST_METHOD'])) ? $_SERVER['REQUEST_METHOD'] : '';
 	$_SERVER['REQUEST_METHOD'] = 'POST';
-
 	require_once $xoops_config->xoops_mainfile_path; //It is necessary to execute it for the user attestation before wp-settings.php. 
-	unset($offset);
+	$_SERVER['REQUEST_METHOD'] = $request_method;
+	
+	unset($offset);		//This Trap is provides the case where $offset is defined on the XOOPS side.
 	require_once(ABSPATH.'wp-settings.php');
 	
+	//When it is not possible to connect it correctly at site home URL on the WordPress side, 
+	//URL is corrected based on accessed URL. 
 	safe_site_url();
 
Index: tags/Ver2.2.2/xpressme_integration_kit/include/general_functions.php
===================================================================
--- trunk/xpressme_integration_kit/include/general_functions.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/include/general_functions.php	(revision 504)
@@ -126,4 +126,6 @@
 		$table_list = array();
 		$ret = array();
+		$pattern = $wp_prefix . $table_name . '|' . $wp_prefix . '[0-9]*_' . $table_name;
+
 		if (!empty($wp_prefix) && !empty($table_name)){
 			$sql = "SHOW TABLES LIKE '" . $wp_prefix  . '%' . $table_name . "'";
@@ -132,5 +134,7 @@
 				if($result = $xoopsDB->queryF($sql)){
 					while($row = $xoopsDB->fetchRow($result)){
-						$table_list[] = $row[0];
+						if(preg_match('/' . $pattern . '/' , $row[0])){
+							$table_list[] = $row[0];
+						}
 					}
 				}
@@ -138,5 +142,7 @@
 				$rows = $xoops_db->get_results($sql, ARRAY_N);
 				foreach ($rows as $row){
-					$table_list[] = $row[0];
+					if(preg_match('/' . $pattern . '/' , $row[0])){
+						$table_list[] = $row[0];
+					}
 				}
 			}			
Index: tags/Ver2.2.2/xpressme_integration_kit/include/oninstall.php
===================================================================
--- trunk/xpressme_integration_kit/include/oninstall.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/include/oninstall.php	(revision 504)
@@ -45,5 +45,5 @@
 
 //xpress
-	global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles, $wp_query;
+	global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles, $wp_query,$wp_embed;
 	global $xoops_config;
 		
Index: tags/Ver2.2.2/xpressme_integration_kit/include/onupdate.php
===================================================================
--- trunk/xpressme_integration_kit/include/onupdate.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/include/onupdate.php	(revision 504)
@@ -42,6 +42,13 @@
 	$site_url= XOOPS_URL."/modules/".$mydirname;
 	xpress_put_siteurl($mydirname,$site_url);
-	xpress_put_home($mydirname,$site_url);
-
+	$home = get_xpress_option($mydirname,'home');
+	$home_check = 'home option is right';
+	if (strcmp($site_url,$home) !== 0 ){
+		if (!@fclose(@fopen($home . '/xoops_version.php', "r"))){
+			xpress_put_home($mydirname,$site_url);
+			$home_check = 'Change home option $home to $site_url';
+		}
+	}
+	$msgs[] = $home_check;
 // XPressME orignal table update
 	$t_mess = xpress_table_make($module , $mydirname);
@@ -50,6 +57,10 @@
 // make templates
 	include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ;
+	$mod_version = $module->getVar('version') ;
+
+	$t_mess = xpress_clean_templates_file($mydirname,$mod_version);
+	$msgs = array_merge($msgs,$t_mess);
+	
 	$t_mess = xpress_templates_make($mid,$mydirname);
-	
 	$msgs = array_merge($msgs,$t_mess);
 
@@ -97,4 +108,24 @@
 endif;
 
+if( ! function_exists( 'get_xpress_option' ) ) {
+	function get_xpress_option($mydirname,$option_name){
+		global $xoopsModule;
+		$wp_prefix = $mydirname;
+		if ($wp_prefix == 'wordpress'){
+			$wp_prefix = 'wp';
+		}
+		$xoopsDB =& Database::getInstance();
+		$option_table = $xoopsDB->prefix($wp_prefix . '_options');
+
+		$sql = "SELECT option_value FROM $option_table WHERE option_name = '" . $option_name . "'";
+		
+		$result =  $xoopsDB->query($sql, 0, 0);
+		if ($xoopsDB->getRowsNum($result)  > 0){
+			$row = $xoopsDB->fetchArray($result);
+			return $row['option_value'];
+		}
+		return 0;
+	}
+}
 
 if( ! function_exists( 'xpress_message_append_onupdate' ) ) :
@@ -190,4 +221,22 @@
 			$db->queryF( $queries ) ;
 			$msgs[] = "$views_table  ADD blog_id .";
+		}
+		
+		// The table is repaired.
+		$non_blogid_sql ="SELECT * FROM $views_table WHERE blog_id IS NULL OR blog_id < 1";
+		$non_blogid_res = $db->query($non_blogid_sql, 0, 0);
+		while($row = $db->fetchArray($non_blogid_res)){
+			$total_view = $row['post_views'];
+			$post_id = $row['post_id'];
+			$new_blogid_sql ="SELECT SUM(post_views) as post_views_sum FROM $views_table WHERE post_id = $post_id AND blog_id = 1 GROUP BY post_id";
+			$new_blogid_res = $db->query($new_blogid_sql, 0, 0);
+			if ($db->getRowsNum($new_blogid_res)  > 0){
+				$new_row = $db->fetchArray($new_blogid_res);
+				$total_view = $total_view + $new_row['post_views_sum'];
+				$del_sql = "DELETE FROM $views_table WHERE post_id = $post_id AND blog_id = 1";
+				$db->queryF( $del_sql ) ;
+			}
+			$update_sql = "UPDATE $views_table SET post_views = $total_view , blog_id = 1 WHERE post_id = $post_id AND (blog_id IS NULL OR blog_id < 1)";
+			$db->queryF( $update_sql ) ;
 		}
 	}
Index: tags/Ver2.2.2/xpressme_integration_kit/include/search.php
===================================================================
--- trunk/xpressme_integration_kit/include/search.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/include/search.php	(revision 504)
@@ -25,5 +25,5 @@
 		}
 		if ($userid) {
-			$userid = xoops_uid_to_wp_uid(intval($userid),$mydirname);
+			$wp_uid = xoops_uid_to_wp_uid(intval($userid),$mydirname);
 		}
 
@@ -56,5 +56,9 @@
 			}
 			if ($userid) {
-				$where  .= " AND (post_author=".$userid.")";
+				if ($wp_uid){
+					$where  .= " AND (post_author=".$wp_uid.")";
+				} else {
+					$where  .= " AND 0 ";
+				}
 			}
 
Index: tags/Ver2.2.2/xpressme_integration_kit/include/set_cash_cookie_path.php
===================================================================
--- trunk/xpressme_integration_kit/include/set_cash_cookie_path.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/include/set_cash_cookie_path.php	(revision 504)
@@ -8,5 +8,5 @@
  */
 if ( !defined('USER_COOKIE') )
-	define('USER_COOKIE', $modname . 'user_' . $hash);
+	define('USER_COOKIE', 'wordpress_' . $modname . '_user_' . $hash);
 
 /**
@@ -15,5 +15,5 @@
  */
 if ( !defined('PASS_COOKIE') )
-	define('PASS_COOKIE', $modname . 'pass_' . $hash);
+	define('PASS_COOKIE', 'wordpress_' . $modname . '_pass_' . $hash);
 
 /**
@@ -22,5 +22,5 @@
  */
 if ( !defined('AUTH_COOKIE') )
-	define('AUTH_COOKIE', $modname . '_auth_' . $hash);
+	define('AUTH_COOKIE', 'wordpress_' . $modname . '_auth_' . $hash);
 
 /**
@@ -29,5 +29,5 @@
  */
 if ( !defined('SECURE_AUTH_COOKIE') )
-	define('SECURE_AUTH_COOKIE', $modname . '_sec_' . $hash);
+	define('SECURE_AUTH_COOKIE', 'wordpress_' . $modname . '_sec_' . $hash);
 
 /**
@@ -36,5 +36,5 @@
  */
 if ( !defined('LOGGED_IN_COOKIE') )
-	define('LOGGED_IN_COOKIE', $modname . '_logged_in_' . $hash);
+	define('LOGGED_IN_COOKIE', 'wordpress_' . $modname . '_logged_in_' . $hash);
 
 /**
@@ -43,5 +43,5 @@
  */
 if ( !defined('TEST_COOKIE') )
-	define('TEST_COOKIE', $modname . '_test_cookie');
+	define('TEST_COOKIE', 'wordpress_' . $modname . '_test_cookie');
 
 /**
Index: tags/Ver2.2.2/xpressme_integration_kit/include/xpress_block_render.php
===================================================================
--- trunk/xpressme_integration_kit/include/xpress_block_render.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/include/xpress_block_render.php	(revision 504)
@@ -22,14 +22,24 @@
 	function xpress_block_cache_read($mydirname,$block_name)
 	{
-			$xml_name = $block_name . '.xml';
-			$xml_data = xpress_cache_read($mydirname,$xml_name);
-			
-			$GLOBALS['DO_LIBXML_PATCH'] = get_xpress_mod_config($mydirname,'libxml_patch');
-			
+		$xml_name = $block_name . '.xml';
+		$xml_data = xpress_cache_read($mydirname,$xml_name);
+		
+		$GLOBALS['DO_LIBXML_PATCH'] = get_xpress_mod_config($mydirname,'libxml_patch');
+		
+		// The character-code not treatable exists when 'XML_unserialize' of PHP5 processes EUC-JP. 
+		// And, the result is returned by character-code UTF-8. 
+		// Measures
+		// After the character-code is converted into UTF-8, XML_unserialize will be processed. 
+		if ( strstr($xml_data, '<?xml version="1.0" encoding="EUC-JP" ?>') !== false
+			 && version_compare(PHP_VERSION, '5.0.0', '>') )
+		{
+			$xml_data = str_replace('<?xml version="1.0" encoding="EUC-JP" ?>', '<?xml version="1.0" encoding="UTF-8" ?>', $xml_data);
+			$ans = mb_convert_variables('UTF-8' , 'EUC-JP', &$xml_data); //EUC-JP to UTF-8
 			$ret = @xpress_XML_unserialize($xml_data);
-			if (strstr($xml_data, '<?xml version="1.0" encoding="EUC-JP" ?>') !== false){
-				$ans = mb_convert_variables('EUC-JP' , 'UTF-8', &$ret);
-			}
-			return $ret;
+			$ans = mb_convert_variables('EUC-JP' , 'UTF-8', &$ret); //UTF-8 to EUC-JP
+		} else {
+			$ret = xpress_XML_unserialize($xml_data);
+		}
+		return $ret;
 	}
 	
@@ -52,4 +62,18 @@
 			}
 			return $block_id;
+	}
+
+	function get_block_mid($mydirname)
+	{
+			$xoopsDB =& Database::getInstance();
+			$modules_tbl = $xoopsDB->prefix('modules');	
+
+			$sql = "SELECT mid FROM $modules_tbl WHERE dirname = '$mydirname'";
+			$result =  $xoopsDB->query($sql, 0, 0);
+			if ($xoopsDB->getRowsNum($result)  > 0){
+				$row = $xoopsDB->fetchArray($result);
+				$mid = $row['mid'];
+			}
+			return $mid;
 	}
 
@@ -167,12 +191,9 @@
 		$blockID =get_block_id($mydirname,$func_file,$options);		
 
-		if (function_exists('get_option'))
-			$this_url = str_replace( $xoops_config->xoops_url , '' , get_option('home'));
-		else
-			$this_url = $mydirname;
-
+		$this_block_url = '/' . $mydirname . '/';
 		$call_url = $_SERVER['REQUEST_URI'];
+		
 		xpress_block_css_set($mydirname);
-		if (strstr($call_url,$this_url)){	
+		if (strstr($call_url , $this_block_url) !== false){
 			$block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
 			require_once $block_theme_file['file_path'];
@@ -188,14 +209,47 @@
 			}
 		}
-		$option = explode('|' , $block['options']);
-		
-		if (isset($option[1]))
-			$templates_file = $option[1];
-		else
+		$temp_option = explode(':' , $options[1]);
+		
+		if (isset($temp_option[1])) {
+			$templates_file = $options[1];
+		} else {
 			$templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
+		}
+		
 		$tpl =& new XoopsTpl() ;
+		$tpl->template_dir = $xoops_config->module_path . '/templates';
+		if (!$tpl->template_exists($templates_file)){
+			$src_file_path = $xoops_config->module_path . '/templates/' .$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
+			$templates_file = add_xpress_tpl($mydirname,$templates_file,$src_file_path);
+		}
 		$tpl->assign( 'block' , $block ) ;
 		$ret['content'] = $tpl->fetch( $templates_file ) ;
 		return $ret ;
+	}
+	
+	function add_xpress_tpl($mydirname,$templates='',$src_file_path){
+		global $wpdb,$xoops_config , $xoops_db;
+		
+		$mid = get_block_mid($mydirname);
+
+		$temp_parm = explode(':' , $templates);
+		if (empty($temp_parm[1])) {
+			$filename=$temp_parm[0];
+			$type = 'db';
+		} else  {
+			$filename=$temp_parm[1];
+			$type = $temp_parm[0];
+		}
+		$temp_file_path = $xoops_config->module_path . '/templates/'. $filename;
+		$pattern = '^' . $mydirname . '_';
+		if (preg_match('/' . $pattern . '/' , $filename, $match)){ // file prefix check
+			if (!file_exists($temp_file_path)){		// Repetition check
+				if (file_exists($src_file_path)){	// source file check
+					$rcd = copy($src_file_path, $temp_file_path);
+				}
+			}
+			return  'file:' . $filename;
+		}
+		return $templates;
 	}
 	
@@ -250,4 +304,5 @@
 	{
 		global $xoops_db,$xoops_config;
+		
 		$mid = get_xpress_modid();
 		$sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid AND visible = 1";
@@ -267,5 +322,5 @@
         if ($dh = opendir($cache_dir)) {
             while (($file = readdir($dh)) !== false) {
-                if (preg_match('/^' . preg_quote($mydirname) . '/', $file)) {
+                if (preg_match('/^' . preg_quote($mydirname) . '_/', $file)) {
                 	if(! preg_match('/' . $pattern . '/', $file)) {
                     	unlink($cache_dir.$file);
@@ -294,6 +349,5 @@
 			return $xu_row['conf_value'];
 		}
-	}
-	
+	}	
 }	
 ?>
Index: tags/Ver2.2.2/xpressme_integration_kit/include/xpress_templates_make.php
===================================================================
--- trunk/xpressme_integration_kit/include/xpress_templates_make.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/include/xpress_templates_make.php	(revision 504)
@@ -7,4 +7,6 @@
 	$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
 	$tpl_path = XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/templates' ;
+	
+	//copy  template file from source
 	if( $handler = @opendir( $tpl_path . '/source/' ) ) {
 		while( ( $file = readdir( $handler ) ) !== false ) {
@@ -26,34 +28,19 @@
 					$msgs[] = '<span style="color:#ff0000;">ERROR: Could not copy template <b>'.htmlspecialchars($target_file_name).'</b> from ' . htmlspecialchars($file). '(check templates directory permision (777))</span><br />';
 				}					
-				$tplfile =& $tplfile_handler->create() ;
-				if ($rcd) {
-					$mtime = intval( @filemtime( $target_file_path ) ) ;
-					$tplfile->setVar( 'tpl_source' , file_get_contents( $target_file_path ) , true ) ;
-				} else {
-					$mtime = intval( @filemtime( $file_path ) ) ;
-					$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
-				}
-
-				$tplfile->setVar( 'tpl_refid' , $mid ) ;
-				$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
-				$tplfile->setVar( 'tpl_file' , $target_file_name ) ;
-				$tplfile->setVar( 'tpl_desc' , '' , true ) ;
-				$tplfile->setVar( 'tpl_module' , $mydirname ) ;
-				$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
-				$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
-				$tplfile->setVar( 'tpl_type' , 'module' ) ;
-				if( ! $tplfile_handler->insert( $tplfile ) ) {
-					$msgs[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($target_file_name).'</b> to the database.</span><br />';
-				} else {
-					$tplid = $tplfile->getVar( 'tpl_id' ) ;
-					$msgs[] = 'Template <b>'.htmlspecialchars($target_file_name) .'</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 ) ) {
-						$msgs[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($target_file_name).'</b>.</span><br />';
-					} else {
-						$msgs[] = 'Template <b>'.htmlspecialchars($target_file_name).'</b> compiled.</span><br />';
-					}
+			}
+		}
+		closedir( $handler ) ;
+	}
+	
+	// template added to the database.
+	if( $handler = @opendir( $tpl_path . '/' ) ) {
+		while( ( $file = readdir( $handler ) ) !== false ) {
+			if( substr( $file , 0 , 1 ) == '.' ) continue ;
+			$file_path = $tpl_path . '/' . $file ;
+			$file_name = $file ;
+			$pattern = '^' . $mydirname . '_';
+			if (preg_match('/' . $pattern . '/' , $file_name, $match)){
+				if( is_file( $file_path ) ) {
+					$msgs[] = xpress_create_db_template($file_name,$file_path,$mydirname,$mid);
 				}
 			}
@@ -61,4 +48,5 @@
 		closedir( $handler ) ;
 	}
+	
 	include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ;
 	include_once XOOPS_ROOT_PATH.'/class/template.php' ;
@@ -68,4 +56,35 @@
 }
 
+function xpress_create_db_template($file_name,$file_path,$mydirname,$mid){
+	if( is_file( $file_path ) ) {
+		$tplfile_handler =& xoops_gethandler( 'tplfile' ) ;
+		$tplfile =& $tplfile_handler->create() ;
+		$mtime = intval( @filemtime( $file_path ) ) ;
+		$tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ;
+		$tplfile->setVar( 'tpl_refid' , $mid ) ;
+		$tplfile->setVar( 'tpl_tplset' , 'default' ) ;
+		$tplfile->setVar( 'tpl_file' ,  $file_name ) ;
+		$tplfile->setVar( 'tpl_desc' , '' , true ) ;
+		$tplfile->setVar( 'tpl_module' , $mydirname ) ;
+		$tplfile->setVar( 'tpl_lastmodified' , $mtime ) ;
+		$tplfile->setVar( 'tpl_lastimported' , 0 ) ;
+		$tplfile->setVar( 'tpl_type' , 'module' ) ;
+		if( ! $tplfile_handler->insert( $tplfile ) ) {
+			$msg = '<span style="color:#ff0000;">ERROR: Template Could not added to the database. <b>'.htmlspecialchars($file_name).'</b> to the database.</span><br />';
+		} else {
+			$tplid = $tplfile->getVar( 'tpl_id' ) ;
+			$msg = 'Template <b>'.htmlspecialchars($file_name) .'</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 ) ) {
+				$msg = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($file_name).'</b>.</span><br />';
+			} else {
+				$msg = 'Template <b>'.htmlspecialchars($file_name).'</b> compiled.</span><br />';
+			}
+		}
+	}
+	return $msg;
+}
 
 function is_template($file_name){
@@ -96,4 +115,46 @@
 }
 
+function xpress_clean_templates_file($mydirname,$mod_version)
+{
+	$tpl_path = XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/templates/' ;
+	$msgs = array();
+	if( $handler = @opendir( $tpl_path) ) {
+		while( ( $file = readdir( $handler ) ) !== false ) {
+			if( substr( $file , 0 , 1 ) == '.' ) continue ;
+			if ( strcmp($file,'source')==0 ) continue ;
+			if ( strcmp($file,'index.html')==0 ) continue ;
+			$target_file_path = $tpl_path . $file;
+			if (is_dir($target_file_path)){
+				rmDirectory($target_file_path);
+				$msgs[] = 'Template <b>'.htmlspecialchars($file).'</b> directory deleted.</span><br />';
+			} else {
+				if ($mod_version >= 200){
+					$pattern = '^' . $mydirname . '_';
+					if (preg_match('/' . $pattern . '/' , $file, $match))  continue ;
+				}
+				$rcd = @unlink($target_file_path);
+				$msgs[] = 'Template <b>'.htmlspecialchars($file).'</b> file deleted.</span><br />';
+			}
+		}
+		closedir( $handler ) ;
+	}
+	return $msgs;
+}
+
+function rmDirectory($dir){
+	if ($handle = opendir("$dir")){
+		while (false !== ($item = readdir($handle))){
+			if ($item != "." && $item != ".."){
+				if (is_dir("$dir/$item")){
+					rmDirectory("$dir/$item");
+				}else{
+					unlink("$dir/$item");
+				}
+			}
+		}
+		closedir($handle);
+		rmdir($dir);
+	}
+}
 
 ?>
Index: tags/Ver2.2.2/xpressme_integration_kit/language/english/blocks.php
===================================================================
--- trunk/xpressme_integration_kit/language/english/blocks.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/language/english/blocks.php	(revision 504)
@@ -26,4 +26,6 @@
 	define("_MB_XP2_LIST","List");
 	define("_MB_XP2_FILE_NAME","Files Name");
+	define("_MB_XP2_THISTEMPLATE","Template");
+	define("_MB_XP2_NO_JSCRIPT","Javascript should be enable by a browser.");	
 	
 // recent comment block	
@@ -107,5 +109,5 @@
 	
 // Categorie
-	define("_MB_XP2_CAT_ALL_STR","All categories link Display Title. (blank is not displayj");
+	define("_MB_XP2_CAT_ALL_STR","All categories link Display Title. (blank is not display)");
 	define("_MB_XP2_CAT_ORDERBY","Order of the categories");
 	define("_MB_XP2_CAT_NAME","name");
Index: tags/Ver2.2.2/xpressme_integration_kit/language/english/modinfo.php
===================================================================
--- trunk/xpressme_integration_kit/language/english/modinfo.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/language/english/modinfo.php	(revision 504)
@@ -22,4 +22,5 @@
 	define("_MI_XP2_MENU_XPRESS","XPressME Setting");
 	define("_MI_XP2_MENU_TO_MODULE","to Modules");
+	define("_MI_XP2_TO_UPDATE","Update");
 
 	// Module Config
@@ -28,4 +29,7 @@
 XPressME acquires a version of libxml2 automatically, and it is adapted a patch if it is necessary. 
 When XPressME cannot acquire a version of libxml2, you can let a patch fit it with this option forcibly.");
+	
+	define("_MI_MEMORY_LIMIT","Memory size(MB) at least necessary for module");
+	define("_MI_MEMORY_LIMIT_DESC","If the memory_limit value of php.ini is smaller than this value. Try the re-setting of memory_limit with ini_set('memory_limit', Value);.");
 
 	// Block Name
Index: tags/Ver2.2.2/xpressme_integration_kit/language/ja_utf8/blocks.php
===================================================================
--- trunk/xpressme_integration_kit/language/ja_utf8/blocks.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/language/ja_utf8/blocks.php	(revision 504)
@@ -26,4 +26,6 @@
 	define("_MB_XP2_LIST","リスト");
 	define("_MB_XP2_FILE_NAME","ファイル名");
+	define("_MB_XP2_THISTEMPLATE","このブロックのテンプレート");
+	define("_MB_XP2_NO_JSCRIPT","ブラウザでJavascriptを有効にする必要があります。");	
 	
 // recent comment block	
Index: tags/Ver2.2.2/xpressme_integration_kit/language/ja_utf8/modinfo.php
===================================================================
--- trunk/xpressme_integration_kit/language/ja_utf8/modinfo.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/language/ja_utf8/modinfo.php	(revision 504)
@@ -22,4 +22,5 @@
 	define("_MI_XP2_MENU_XPRESS","XPressME設定");
 	define("_MI_XP2_MENU_TO_MODULE","モジュールへ");
+	define("_MI_XP2_TO_UPDATE","アップデート");
 
 	// Module Config
@@ -28,4 +29,7 @@
 XPressMEはlibxml2のバージョンを自動的に取得し、必要であればパッチが適応されます。
 XPressMEがlibxml2のバージョンを取得できない場合、このオプションで強制的にパッチを適応させることができます。");
+	
+	define("_MI_MEMORY_LIMIT","モジュールに最低限必要なメモリ(MB)");
+	define("_MI_MEMORY_LIMIT_DESC","php.iniのmemory_limit値がこの値より小さいとき、可能であればini_set('memory_limit', Value);を実行しmemory_limitを再設定する");
 
 	// Block Name
Index: tags/Ver2.2.2/xpressme_integration_kit/wp-content/plugins/xpressme/include/custom_functions.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/custom_functions.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/wp-content/plugins/xpressme/include/custom_functions.php	(revision 504)
@@ -95,5 +95,5 @@
 
 	$output = '';
-  	$author_cookie = get_xpress_dir_name() . "_select_author" ;
+  	$author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
   	if (!empty($_COOKIE[$author_cookie])){
   		$uid = intval($_COOKIE[$author_cookie]);
@@ -115,5 +115,5 @@
 	extract( $r );
 	$output = '';
-  	$author_cookie = get_xpress_dir_name() . "_select_author" ;
+  	$author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
   	if (!empty($_COOKIE[$author_cookie])){
   		$output = intval($_COOKIE[$author_cookie]);
@@ -161,8 +161,9 @@
 	$xpress_codename = $xoops_config->module_codename;
 	if ($no_link){
-		$output = 'XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename);
 		if ($xoops_config->is_wpmu) {
+			$output = 'XPressMU Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename);
 			$output .= '(included WordPress MU ' . $wpmu_version. ')';
 		} else {
+			$output = 'XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename);
 			if (strstr($wp_version,'ME')){
 				$output .= '(included WordPress ' . $wp_version . ')';
@@ -172,8 +173,9 @@
 		}
 	} else {
-		$output = '<a href="http://ja.xpressme.info"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
 		if ($xoops_config->is_wpmu) {
+			$output = '<a href="http://ja.xpressme.info"'. " target='_blank'" . '>XPressMU Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
 			$output .= '(included <a href="http://mu.wordpress.org/" title="Powered by WordPress"'." target='_blank'". '>WordPress MU ' . $wpmu_version . '</a>)';
 		} else {
+			$output = '<a href="http://ja.xpressme.info"'. " target='_blank'" . '>XPressME Ver.' . sprintf('%.2f %s',$xpress_version,$xpress_codename) .'</a>';
 			if (strstr($wp_version,'ME')){
 				$output .= '(included <a href="http://wpme.sourceforge.jp/" title="Powered by WordPress"'." target='_blank'". '>WordPress ' . $wp_version . '</a>)';
@@ -467,5 +469,5 @@
 }
 
-function set_post_views_count(&$content) {
+function set_post_views_count($content) {
 	if ( empty($_GET["feed"]) &&  empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
 		post_views_counting();
Index: tags/Ver2.2.2/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_common_functions.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_common_functions.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_common_functions.php	(revision 504)
@@ -242,5 +242,5 @@
 	if (is_admin()) return $query_vars;
 	
-	$author_cookie = get_xpress_dir_name() . "_select_author" ;
+	$author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
 	if(xpress_is_multi_user()){
 		if (!empty($_GET)){
@@ -290,9 +290,9 @@
 }
 
-function xpress_query_filter(&$query)
+function xpress_query_filter($query)
 {
 	if (is_admin()) return $query;
 
-	$author_cookie = get_xpress_dir_name() . "_select_author" ;
+	$author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
 	
 	if (strpos($query,'SELECT') === false)  return $query;
Index: tags/Ver2.2.2/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_upgrade.php
===================================================================
--- trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_upgrade.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/wp-content/plugins/xpressme/include/xpress_upgrade.php	(revision 504)
@@ -15,5 +15,4 @@
 	if(get_xpress_latest_version()){
 		$latest = get_option('xpressme_latest_version');
-//print_r($latest);
 		if ($latest) {
 			$site_url=$latest['url'];
@@ -32,5 +31,4 @@
 			echo	'<h3 class="response">'. __('There is a new version of XPressME Integration Kit available for upgrade', 'xpressme') . '</h3>';
 			echo '<p>';
-	//		printf(__('You can upgrade to version %s automatically or download the package and install it manually:'),$latest_version);
 			printf(__('You can upgrade to version %s download the package and install it manually:', 'xpressme'),$latest_version);
 			echo '</p>';
@@ -51,4 +49,5 @@
 		}
 		
+		// develop
 		if ($latest['develop_response'] == 'development_exists'
 			&& !empty($latest['develop_package'])
@@ -61,4 +60,16 @@
 			printf(__('Download %s', 'xpressme') , $latest['develop_latest_version']);
 			echo '</a>';
+			// develop diff
+			if ($latest['diff_develop_response'] == 'diff_develop_exists'
+				&& !empty($latest['diff_develop_package'])
+				)
+			{
+					echo '<p>';
+					printf(__('You can download the differential file from version %s to %s and upgrade it manually:', 'xpressme'),$xpress_version,$latest['diff_develop_latest_version']);
+					echo '</p>';
+					echo '<a class="button" href="' . $latest['diff_develop_package'] . '">';
+						printf(__('Download differential file for %s', 'xpressme') , $latest['diff_develop_latest_version']);
+					echo '</a>';
+			}
 		}
 
@@ -141,4 +152,11 @@
 	if ( isset( $returns[15] ) ) $develop_latest_version = $returns[15]; else  $develop_latest_version = '';
 	if ( isset( $returns[16] ) ) $develop_lang = $returns[16]; else $develop_lang = '';
+	
+	// developer diff
+	if ( isset( $returns[18] ) ) $diff_develop_response = $returns[18]; else $diff_develop_response = '';
+	if ( isset( $returns[19] ) ) $diff_develop_url = clean_url( $returns[19] ); else $diff_develop_url = '';
+	if ( isset( $returns[20] ) ) $diff_develop_package = clean_url( $returns[20] ); else $diff_develop_package = '';
+	if ( isset( $returns[21] ) ) $diff_develop_latest_version = $returns[21]; else  $diff_develop_latest_version = '';
+	if ( isset( $returns[22] ) ) $diff_develop_lang = $returns[22]; else $diff_develop_lang = '';
 
 	$write_options = array (
@@ -158,4 +176,9 @@
 		'develop_latest_version' => $develop_latest_version ,
 		'develop_lang' => $develop_lang ,
+		'diff_develop_response' => $diff_develop_response ,
+		'diff_develop_url' => $diff_develop_url ,
+		'diff_develop_package' => $diff_develop_package ,
+		'diff_develop_latest_version' => $diff_develop_latest_version ,
+		'diff_develop_lang' => $diff_develop_lang ,
 		'check_time' => time()
 	);
Index: tags/Ver2.2.2/xpressme_integration_kit/xoops_version.php
===================================================================
--- trunk/xpressme_integration_kit/xoops_version.php	(revision 458)
+++ tags/Ver2.2.2/xpressme_integration_kit/xoops_version.php	(revision 504)
@@ -38,5 +38,5 @@
 $modversion['name'] = ucfirst($mydirname) . ' ' . constant('_MI_XP2_NAME') ;
 $modversion['description'] = constant( '_MI_XP2_DESC');
-$modversion['version'] = "2.20";
+$modversion['version'] = "2.22";
 $modversion['credits'] = "Wordpress DEV (http://wordpress.org/) XPressME DEV Toemon) (http://ja.xpressme.info) ;";
 $modversion['author'] = "toemon (http://ja.xpressme.info)";
@@ -47,5 +47,5 @@
 
 // status
-$modversion['codename'] = "RC2";
+$modversion['codename'] = "";
 
 // onInstall, onUpdate, onUninstall
@@ -107,5 +107,5 @@
 		if (@$current_user->user_level > 9) {
 			$modversion['sub'][4]['name'] = constant( '_MI_XP2_MENU_XPRESS');
-			$modversion['sub'][4]['url'] = $add_url . "wp-admin/admin.php?page=xpressme\\xpressme.php";
+			$modversion['sub'][4]['url'] = $add_url . "wp-admin/admin.php?page=xpressme" . DIRECTORY_SEPARATOR . "xpressme.php";
 		}
 		if($GLOBALS["xoopsUserIsAdmin"]){
@@ -134,4 +134,12 @@
 	'default'		=> 0 ,
 );
+$modversion['config'][] = array(
+	'name'			=> 'memory_limit' ,
+	'title'			=>  '_MI_MEMORY_LIMIT' ,
+	'description'	=>  '_MI_MEMORY_LIMIT_DESC' ,
+	'formtype'		=> 'textbox' ,
+	'valuetype'		=> 'int' ,
+	'default'		=> 64 ,
+);
 
 //BLOCKS
@@ -248,6 +256,6 @@
 	'func_num'		=> $b_no,	
 );
-$b_no++;
 if (wp_version_compare($wp_version, '>=','2.3')){
+	$b_no++;
 	$modversion['blocks'][$b_no] = array(
 		'file' 			=> 'tag_cloud_block.php' ,
@@ -283,6 +291,6 @@
 	'func_num'		=> $b_no,	
 );
-$b_no++;
 if (wp_version_compare($wp_version, '>=','2.7')){
+	$b_no++;
 	$modversion['blocks'][$b_no] = array(
 		'file' 			=> 'widget_block.php' ,
