mDelegateManager->add( 'Legacy.Admin.Event.ModuleUpdate.' . ucfirst($mydirname) . '.Success', 'xpress_message_append_onupdate' ) ;
$msgs = array() ;
} else {
if( ! is_array( $msgs ) ) $msgs = array() ;
}
$db =& Database::getInstance() ;
$mid = $module->getVar('mid') ;
//XPress TABLE UPGRADE
global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles,$wp_query;
define('WP_INSTALLING', true);
$mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
$path = $mydirpath . '/';
if (file_exists($path . 'wp-load.php')) {
require_once $path . 'wp-load.php';
} else {
require_once $path . 'wp-config.php';
}
require_once($mydirpath . '/wp-admin/upgrade-functions.php');
if ( get_db_version($mydirname) != $wp_db_version ){
if( function_exists( 'wp_upgrade' ) ) {
wp_upgrade();
} else {
wp_cache_flush();
make_db_current_silent();
upgrade_all();
wp_cache_flush();
}
}
/* activate the tag plugin */
$plugin_current = "xpressme/xpressme.php";
update_option('active_plugins', array($plugin_current));
include_once(dirname(__FILE__) . '/../wp-content/plugins/'.$plugin_current);
do_action('activate_'.$plugin_current);
// update_option("blog_charset", wp_blog_charset());
$xpress_version = $module->modinfo['version'];
if (! enhanced_table_check($mydirname,'views')){
$xp_prefix = $mydirname;
if ($xp_prefix == 'wordpress'){
$xp_prefix = 'wp';
}
$charset_collate = '';
if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
if ( ! empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
if ( ! empty($wpdb->collate) )
$charset_collate .= " COLLATE $wpdb->collate";
}
$views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ;
$views_queries ="CREATE TABLE $views_table (
post_id bigint(20) unsigned NOT NULL default '0',
post_views bigint(20) unsigned NOT NULL default '0',
KEY post_id (post_id)
)$charset_collate;";
dbDelta($views_queries);
}
if (! enhanced_table_check($mydirname,'d3forum_link')){
$xp_prefix = $mydirname;
if ($xp_prefix == 'wordpress'){
$xp_prefix = 'wp';
}
$charset_collate = '';
if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
if ( ! empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
if ( ! empty($wpdb->collate) )
$charset_collate .= " COLLATE $wpdb->collate";
}
$d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ;
$queries ="CREATE TABLE $d3forum_link (
comment_ID bigint(20) unsigned NOT NULL default '0',
post_id int(10) unsigned NOT NULL default '0' ,
wp_post_ID bigint(20) unsigned NOT NULL default '0',
KEY post_id (post_id)
)$charset_collate;";
dbDelta($queries);
}
if (! enhanced_table_check($mydirname,'group_role')){
$xp_prefix = $mydirname;
if ($xp_prefix == 'wordpress'){
$xp_prefix = 'wp';
}
$charset_collate = '';
if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
if ( ! empty($wpdb->charset) )
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
if ( ! empty($wpdb->collate) )
$charset_collate .= " COLLATE $wpdb->collate";
}
$group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ;
$views_queries ="CREATE TABLE $group_role (
groupid smallint(5) unsigned NOT NULL default '0',
name varchar(50) NOT NULL default '' ,
description text NOT NULL default '',
group_type varchar(10) NOT NULL default '' ,
role varchar(20) NOT NULL default '' ,
login_all smallint(5) unsigned NOT NULL default '0' ,
KEY groupid (groupid)
)$charset_collate;";
dbDelta($views_queries);
$sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')";
$wpdb->query($sql);
}
// 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[] = 'ERROR: Could not insert template '.htmlspecialchars($mydirname.'_'.$file).' to the database.';
} else {
$tplid = $tplfile->getVar( 'tpl_id' ) ;
$msgs[] = 'Template '.htmlspecialchars($mydirname.'_'.$file).' added to the database. (ID: '.$tplid.')';
// 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[] = 'ERROR: Failed compiling template '.htmlspecialchars($mydirname.'_'.$file).'.';
} else {
$msgs[] = 'Template '.htmlspecialchars($mydirname.'_'.$file).' compiled.';
}
}
}
}
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 ;
}
endif;
if( ! function_exists( 'xpress_message_append_onupdate' ) ) :
function xpress_message_append_onupdate( &$module_obj , &$log )
{
if( is_array( @$GLOBALS['msgs'] ) ) {
foreach( $GLOBALS['msgs'] as $message ) {
$log->add( strip_tags( $message ) ) ;
}
}
// use mLog->addWarning() or mLog->addError() if necessary
}
endif;
if( ! function_exists( 'get_db_version' ) ) :
function get_db_version($mydirname){
global $xoopsModule;
$wp_prefix = $mydirname;
if ($wp_prefix == 'wordpress'){
$wp_prefix = 'wp';
}
$xoopsDB =& Database::getInstance();
$db_xpress_option = $xoopsDB->prefix($wp_prefix . '_options');
$sql = "SELECT option_value FROM $db_xpress_option WHERE option_name = 'db_version'";
$res = $xoopsDB->query($sql, 0, 0);
if ($res === false){
return false;
} else {
$row = $xoopsDB->fetchArray($res);
return $row['option_value'];
}
}
endif;
if( ! function_exists( 'enhanced_table_check' ) ) :
function enhanced_table_check($mydirname,$table_name){
global $xoopsModule;
$xoopsDB =& Database::getInstance();
if ($mydirname == 'wordpress'){
$xpress_prefix= $xoopsDB->prefix('wp_');
} else {
$xpress_prefix= $xoopsDB->prefix($mydirname . '_');
}
$db_enhanced = $xpress_prefix . $table_name;
$sql = "show tables like '$db_enhanced'";
$res = $xoopsDB->query($sql, 0, 0);
if ($res === false){
return false;
} else {
if ($xoopsDB->getRowsNum($res) > 0)
return true;
else
return false;
}
}
endif;
?>