XPressME Integration Kit

Trac

source: trunk/include/oninstall.php @ 152

Last change on this file since 152 was 152, checked in by toemon, 16 years ago

Bump Ver0.22 「ログイン時の権限設定」権限リストをグループタイプではなく
module_read(モジュールアクセス権限)のあるものはwordPressの全ての権限をリストし
module_admin(モジュール管理者権限)のあるものはwordPressの管理者権限だけをリストするようにする。
但しグループタイプがゲスト(Anonymous)のグループはリストから省く #86

File size: 6.7 KB
Line 
1<?php
2$mydirpath = dirname(dirname(__FILE__));
3$mydirname = basename($mydirpath);
4$lang = @$GLOBALS["xoopsConfig"]['language'];
5global $wp_db_version;
6include_once $mydirpath .'/wp-includes/version.php' ;
7
8// language file (modinfo.php)
9
10if( file_exists( $mydirpath .'/language/'.$lang.'/modinfo.php' ) ) {
11        include_once $mydirpath .'/language/'.$lang.'/modinfo.php' ;
12} else if( file_exists(  $mydirpath .'/language/english/modinfo.php' ) ) {
13        include_once $mydirpath .'/language/english/modinfo.php' ;
14}
15
16
17eval( ' function xoops_module_install_'.$mydirname.'( $module ) { return xpress_oninstall_base( $module , "'.$mydirname.'" ) ; } ' ) ;
18
19
20if( ! function_exists( 'xpress_oninstall_base' ) ) :
21function xpress_oninstall_base( $module , $mydirname )
22{
23        // transations on module install
24
25        global $ret ; // TODO :-D
26
27        // for Cube 2.1
28        if( defined( 'XOOPS_CUBE_LEGACY' ) ) {
29                $root =& XCube_Root::getSingleton();
30                $root->mDelegateManager->add( 'Legacy.Admin.Event.ModuleInstall.' . ucfirst($mydirname) . '.Success' , 'xpress_message_append_oninstall' ) ;
31                $ret = array() ;
32        } else {
33                if( ! is_array( $ret ) ) $ret = array() ;
34        }
35
36        $db =& Database::getInstance() ;
37        $mid = $module->getVar('mid') ;
38
39//xpress
40        global $wpdb,$wp_rewrite, $wp_queries, $table_prefix, $wp_db_version, $wp_roles, $wp_query;
41        define("WP_INSTALLING", true);
42        $site_url= XOOPS_URL."/modules/".$mydirname;
43        $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
44        $path = $mydirpath . '/';
45        if (file_exists($path . 'wp-load.php')) {
46                require_once $path . 'wp-load.php';
47        } else {
48                require_once $path . 'wp-config.php';
49        }
50        include_once($mydirpath . '/wp-admin/upgrade-functions.php');
51        wp_cache_flush();
52        make_db_current_silent();
53        $ret[] = "The data base of wordpress was made by prefix $table_prefix.";
54       
55        $option_desc = __('WordPress web address');
56        $wpdb->query("INSERT INTO $wpdb->options (option_id, blog_id, option_name,option_value, autoload) VALUES ('1', '0', 'siteurl','$site_url', 'yes')");   
57        $wpdb->query("INSERT INTO $wpdb->options (option_id, blog_id, option_name,option_value, autoload) VALUES ('1', '0', 'home','$site_url', 'yes')");
58
59        populate_options();
60        populate_roles();
61       
62// Rewrite Option for Xpress
63//      update_option("blog_charset", wp_blog_charset());
64        update_option('blogname', ucfirst($mydirname) . ' ' . _MI_XPRESS_NAME );       
65        update_option('blogdescription', 'WordPress for XOOPS');
66        update_option("admin_email", $GLOBALS["xoopsConfig"]['adminmail']);
67        update_option("ping_sites", "http://rpc.pingomatic.com/\nhttp://ping.xoopsforge.com/");
68        update_option("home", $site_url);
69        update_option("siteurl", $site_url);
70        update_option("what_to_show", "posts");
71        update_option('default_pingback_flag', 0);
72        $ret[] = 'The initial data was written in the data base of wordpress.';
73       
74        update_option("template", "xpress_default");
75        update_option("stylesheet", "xpress_default");
76        $ret[] = 'The default theme of wordpress was set to xpress_default.';
77        /* add new option for uploads */
78//      update_option('uploads_use_yearmonth_folders', 1);
79//      update_option('upload_path', $module->getVar("dirname"));
80       
81               
82// Admin User Data write
83        // Change uid field
84        $wpdb->query("ALTER TABLE $wpdb->posts CHANGE `post_author` `post_author` mediumint(8) NOT NULL DEFAULT '0'");
85        $user_name = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("uname"):'admin';
86        $email = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("email"):'foo@exsample.com';
87        $pass_md5 = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("pass"):'';
88       
89        $user_id = username_exists($user_name);
90        if ( !$user_id ) {
91                $random_password = 'admin';
92                $user_id = wp_create_user($user_name, $random_password, $email);
93        } else {
94                $random_password = __('User already exists.  Password inherited.');
95        }
96
97        $user = new WP_User($user_id);
98        $user->set_role('administrator');
99        'User ' . $user_name . ' of the administrator was made.';
100        // over write xoops md5 password
101        $sql = "UPDATE $wpdb->users SET user_pass ='$pass_md5' WHERE ID = $user_id";
102        $wpdb->query($sql);
103        $ret[] = 'The password of XOOPS was copied.';
104        // Set Default data
105        wp_install_defaults($user_id);
106        $ret[] = 'The first sample post & comment was written.';
107//          generate_page_uri_index();
108
109        /* activate the XPressME plugin */
110        $plugin_current = "xpressme/xpressme.php";
111        update_option('active_plugins', array($plugin_current));
112        include_once(dirname(__FILE__) . '/../wp-content/plugins/'.$plugin_current);
113        do_action('activate_'.$plugin_current);
114        $ret[] = 'The xpressme plug-in was activated.';
115       
116        // create views table
117        $xp_prefix = $mydirname;
118        if ($xp_prefix == 'wordpress'){
119                $xp_prefix = 'wp';
120        }
121        $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ;
122
123        $charset_collate = '';
124        if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) {
125                if ( ! empty($wpdb->charset) )
126                        $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
127                if ( ! empty($wpdb->collate) )
128                        $charset_collate .= " COLLATE $wpdb->collate";
129        }
130        $views_queries ="CREATE TABLE $views_table (
131                post_id bigint(20) unsigned NOT NULL default '0',
132                post_views bigint(20) unsigned NOT NULL default '0',
133                KEY post_id (post_id)
134                )$charset_collate;";
135
136        dbDelta($views_queries);
137        $ret[] = "$views_table table of XPressME was made.";
138
139       
140        $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ;
141        $views_queries ="CREATE TABLE $d3forum_link (
142                comment_ID bigint(20) unsigned NOT NULL default '0',
143                post_id int(10) unsigned NOT NULL default '0' ,
144                wp_post_ID bigint(20) unsigned NOT NULL default '0',
145                KEY post_id (post_id)
146                )$charset_collate;";
147        dbDelta($views_queries);
148        $ret[] = "$d3forum_link table of XPressME was made.";
149       
150        $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ;
151        $views_queries ="CREATE TABLE $group_role (
152                groupid smallint(5) unsigned NOT NULL default '0',
153                name varchar(50)  NOT NULL default '' ,
154                description text  NOT NULL default '',
155                group_type varchar(50)  NOT NULL default '' ,
156                role varchar(20)  NOT NULL default '' ,
157                login_all smallint(5) unsigned NOT NULL default '0' ,
158                KEY groupid (groupid)
159                )$charset_collate;";
160        dbDelta($views_queries);
161        $ret[] = "$group_role table of XPressME was made.";
162
163        $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')";
164        $wpdb->query($sql);
165       
166        // make templates
167        include_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/xpress_templates_make.php' ;
168        $t_mess = xpress_templates_make($mid,$mydirname);
169        $ret = array_merge($ret,$t_mess);
170
171        return true ;
172}
173endif;
174
175if( ! function_exists( 'xpress_message_append_oninstall' ) ) :
176function xpress_message_append_oninstall( &$module_obj , &$log )
177{
178        if( is_array( @$GLOBALS['ret'] ) ) {
179                foreach( $GLOBALS['ret'] as $message ) {
180                        $log->add( strip_tags( $message ) ) ;
181                }
182        }
183
184        // use mLog->addWarning() or mLog->addError() if necessary
185}
186endif;
187
188?>
Note: See TracBrowser for help on using the repository browser.