1 | <?php |
---|
2 | $mydirpath = dirname(dirname(__FILE__)); |
---|
3 | $mydirname = basename($mydirpath); |
---|
4 | $lang = @$GLOBALS["xoopsConfig"]['language']; |
---|
5 | global $wp_db_version; |
---|
6 | include_once $mydirpath .'/wp-includes/version.php' ; |
---|
7 | |
---|
8 | // language file (modinfo.php) |
---|
9 | |
---|
10 | if( 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 | |
---|
17 | eval( ' function xoops_module_install_'.$mydirname.'( $module ) { return xpress_oninstall_base( $module , "'.$mydirname.'" ) ; } ' ) ; |
---|
18 | |
---|
19 | |
---|
20 | if( ! function_exists( 'xpress_oninstall_base' ) ) : |
---|
21 | function 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 | |
---|
54 | $option_desc = __('WordPress web address'); |
---|
55 | $wpdb->query("INSERT INTO $wpdb->options (option_id, blog_id, option_name,option_value, autoload) VALUES ('1', '0', 'siteurl','$site_url', 'yes')"); |
---|
56 | $wpdb->query("INSERT INTO $wpdb->options (option_id, blog_id, option_name,option_value, autoload) VALUES ('1', '0', 'home','$site_url', 'yes')"); |
---|
57 | |
---|
58 | populate_options(); |
---|
59 | populate_roles(); |
---|
60 | |
---|
61 | // Rewrite Option for Xpress |
---|
62 | // update_option("blog_charset", wp_blog_charset()); |
---|
63 | update_option('blogname', ucfirst($mydirname) . ' ' . _MI_XPRESS_NAME ); |
---|
64 | update_option('blogdescription', 'WordPress for XOOPS'); |
---|
65 | update_option("admin_email", $GLOBALS["xoopsConfig"]['adminmail']); |
---|
66 | update_option("ping_sites", "http://rpc.pingomatic.com/\nhttp://ping.xoopsforge.com/"); |
---|
67 | update_option("home", $site_url); |
---|
68 | update_option("siteurl", $site_url); |
---|
69 | update_option("template", "xpress_default"); |
---|
70 | update_option("stylesheet", "xpress_default"); |
---|
71 | update_option("what_to_show", "posts"); |
---|
72 | |
---|
73 | /* add new option for uploads */ |
---|
74 | // update_option('uploads_use_yearmonth_folders', 1); |
---|
75 | // update_option('upload_path', $module->getVar("dirname")); |
---|
76 | |
---|
77 | /* activate the XPressME plugin */ |
---|
78 | $plugin_current = "xpressme/xpressme.php"; |
---|
79 | update_option('active_plugins', array($plugin_current)); |
---|
80 | include_once(dirname(__FILE__) . '/../wp-content/plugins/'.$plugin_current); |
---|
81 | do_action('activate_'.$plugin_current); |
---|
82 | |
---|
83 | // Admin User Data write |
---|
84 | // Change uid field |
---|
85 | $wpdb->query("ALTER TABLE $wpdb->posts CHANGE `post_author` `post_author` mediumint(8) NOT NULL DEFAULT '0'"); |
---|
86 | $ID = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("uid"):1; |
---|
87 | // require_once($mydirpath . '/include/user_sync.php'); |
---|
88 | $sync_messg = ''; |
---|
89 | // user_sync_to_wordpress($ID,$sync_messg); //this function in XPressME plugin |
---|
90 | |
---|
91 | // Set Default data |
---|
92 | wp_install_defaults($ID); |
---|
93 | // generate_page_uri_index(); |
---|
94 | |
---|
95 | |
---|
96 | // create views table |
---|
97 | $xp_prefix = $mydirname; |
---|
98 | if ($xp_prefix == 'wordpress'){ |
---|
99 | $xp_prefix = 'wp'; |
---|
100 | } |
---|
101 | $views_table = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_views' ; |
---|
102 | |
---|
103 | $charset_collate = ''; |
---|
104 | if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) { |
---|
105 | if ( ! empty($wpdb->charset) ) |
---|
106 | $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; |
---|
107 | if ( ! empty($wpdb->collate) ) |
---|
108 | $charset_collate .= " COLLATE $wpdb->collate"; |
---|
109 | } |
---|
110 | $views_queries ="CREATE TABLE $views_table ( |
---|
111 | post_id bigint(20) unsigned NOT NULL default '0', |
---|
112 | post_views bigint(20) unsigned NOT NULL default '0', |
---|
113 | KEY post_id (post_id) |
---|
114 | )$charset_collate;"; |
---|
115 | |
---|
116 | dbDelta($views_queries); |
---|
117 | |
---|
118 | $d3forum_link = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_d3forum_link' ; |
---|
119 | $views_queries ="CREATE TABLE $d3forum_link ( |
---|
120 | comment_ID bigint(20) unsigned NOT NULL default '0', |
---|
121 | post_id int(10) unsigned NOT NULL default '0' , |
---|
122 | wp_post_ID bigint(20) unsigned NOT NULL default '0', |
---|
123 | KEY post_id (post_id) |
---|
124 | )$charset_collate;"; |
---|
125 | dbDelta($views_queries); |
---|
126 | |
---|
127 | $group_role = XOOPS_DB_PREFIX . '_' . $xp_prefix .'_group_role' ; |
---|
128 | $views_queries ="CREATE TABLE $group_role ( |
---|
129 | groupid smallint(5) unsigned NOT NULL default '0', |
---|
130 | name varchar(50) NOT NULL default '' , |
---|
131 | description text NOT NULL default '', |
---|
132 | group_type varchar(10) NOT NULL default '' , |
---|
133 | role varchar(20) NOT NULL default '' , |
---|
134 | login_all smallint(5) unsigned NOT NULL default '0' , |
---|
135 | KEY groupid (groupid) |
---|
136 | )$charset_collate;"; |
---|
137 | dbDelta($views_queries); |
---|
138 | $sql = "INSERT INTO $group_role (groupid, role) VALUES (1, 'administrator')"; |
---|
139 | $wpdb->query($sql); |
---|
140 | |
---|
141 | // TEMPLATES |
---|
142 | $tplfile_handler =& xoops_gethandler( 'tplfile' ) ; |
---|
143 | $tpl_path = dirname( dirname( __FILE__ ) ).'/templates/source' ; |
---|
144 | if( $handler = @opendir( $tpl_path . '/' ) ) { |
---|
145 | while( ( $file = readdir( $handler ) ) !== false ) { |
---|
146 | if( substr( $file , 0 , 1 ) == '.' ) continue ; |
---|
147 | $file_path = $tpl_path . '/' . $file ; |
---|
148 | if( is_file( $file_path ) ) { |
---|
149 | $mtime = intval( @filemtime( $file_path ) ) ; |
---|
150 | $tplfile =& $tplfile_handler->create() ; |
---|
151 | $tplfile->setVar( 'tpl_source' , file_get_contents( $file_path ) , true ) ; |
---|
152 | $tplfile->setVar( 'tpl_refid' , $mid ) ; |
---|
153 | $tplfile->setVar( 'tpl_tplset' , 'default' ) ; |
---|
154 | $tplfile->setVar( 'tpl_file' , $mydirname . '_' . $file ) ; |
---|
155 | $tplfile->setVar( 'tpl_desc' , '' , true ) ; |
---|
156 | $tplfile->setVar( 'tpl_module' , $mydirname ) ; |
---|
157 | $tplfile->setVar( 'tpl_lastmodified' , $mtime ) ; |
---|
158 | $tplfile->setVar( 'tpl_lastimported' , 0 ) ; |
---|
159 | $tplfile->setVar( 'tpl_type' , 'block' ) ; |
---|
160 | if( ! $tplfile_handler->insert( $tplfile ) ) { |
---|
161 | $ret[] = '<span style="color:#ff0000;">ERROR: Could not insert template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> to the database.</span><br />'; |
---|
162 | } else { |
---|
163 | $tplid = $tplfile->getVar( 'tpl_id' ) ; |
---|
164 | $ret[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> added to the database. (ID: <b>'.$tplid.'</b>)<br />'; |
---|
165 | // generate compiled file |
---|
166 | include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ; |
---|
167 | include_once XOOPS_ROOT_PATH.'/class/template.php' ; |
---|
168 | if( ! xoops_template_touch( $tplid ) ) { |
---|
169 | $ret[] = '<span style="color:#ff0000;">ERROR: Failed compiling template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b>.</span><br />'; |
---|
170 | } else { |
---|
171 | $ret[] = 'Template <b>'.htmlspecialchars($mydirname.'_'.$file).'</b> compiled.</span><br />'; |
---|
172 | } |
---|
173 | } |
---|
174 | } |
---|
175 | } |
---|
176 | closedir( $handler ) ; |
---|
177 | } |
---|
178 | include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php' ; |
---|
179 | include_once XOOPS_ROOT_PATH.'/class/template.php' ; |
---|
180 | xoops_template_clear_module_cache( $mid ) ; |
---|
181 | |
---|
182 | return true ; |
---|
183 | } |
---|
184 | endif; |
---|
185 | |
---|
186 | if( ! function_exists( 'xpress_message_append_oninstall' ) ) : |
---|
187 | function xpress_message_append_oninstall( &$module_obj , &$log ) |
---|
188 | { |
---|
189 | if( is_array( @$GLOBALS['ret'] ) ) { |
---|
190 | foreach( $GLOBALS['ret'] as $message ) { |
---|
191 | $log->add( strip_tags( $message ) ) ; |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | // use mLog->addWarning() or mLog->addError() if necessary |
---|
196 | } |
---|
197 | endif; |
---|
198 | |
---|
199 | ?> |
---|