1 | <?php
|
---|
2 | /**
|
---|
3 | * XPressME - WordPress for XOOPS
|
---|
4 | *
|
---|
5 | *
|
---|
6 | * @copyright XPressME Project http://www.toemon.com
|
---|
7 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license
|
---|
8 | * @author toemon
|
---|
9 | * @since 2.04
|
---|
10 | * @version $Id$
|
---|
11 | * @package module::xpress
|
---|
12 | */
|
---|
13 |
|
---|
14 |
|
---|
15 | //
|
---|
16 | // wordpress user data vs xoops user data
|
---|
17 | // wordpress database info from http://adiary.blog.abk.nu/080
|
---|
18 | //
|
---|
19 | // wordpress xpress
|
---|
20 | //------------------------------------------------------------------------------------------
|
---|
21 | // users.ID [bigint(20)] users.uid [mediumint(8)]
|
---|
22 | // users.user_login [varchar(60)] users.uname [varchar(60)]
|
---|
23 | // users.user_pass [varchar(64)] users.pass [varchar(32)]
|
---|
24 | // users.user_email [varchar(100)] users.email [varchar(60)]
|
---|
25 | // users.user_url[varchar(100)] users.url [varchar(100)]
|
---|
26 | // users.dateYMDhour [datetime]
|
---|
27 | // users.user_nicename [varchar(50)] users.uname [varchar(60)]
|
---|
28 | // users.user_registerd [datetime] date('Y-m-d H:i:s' , users.regdate[int(10)])
|
---|
29 | // users.user_activation_key [varchar(60)] null
|
---|
30 | // users.user_status [int(11)] 0
|
---|
31 | // users.display_name [varchar(250)] empty(users.name) ? users.uname :users.name
|
---|
32 | //
|
---|
33 | // usermeta[meta_key] get_xpress_user_level(uid);
|
---|
34 | // user_level 10:admim
|
---|
35 | // 7: editor
|
---|
36 | // 2: auther
|
---|
37 | // 1: contributor
|
---|
38 | // 0: subscriber
|
---|
39 | // nickname users.name [varchar(25)]
|
---|
40 | // capabillities
|
---|
41 | // at user_level 10:admim 'a:1:{s:13:"administrator";b:1;}'
|
---|
42 | // 7: editor 'a:1:{s:6:"editor";b:1;}'
|
---|
43 | // 2: auther 'a:1:{s:6:"author";b:1;}'
|
---|
44 | // 1: contributor 'a:1:{s:11:"contributor";b:1;}'
|
---|
45 | // 0: subscriber 'a:1:{s:10:"subscriber";b:1;}'
|
---|
46 | //
|
---|
47 | // first_name
|
---|
48 | // last_name
|
---|
49 | // description
|
---|
50 | // jabber
|
---|
51 | // aim users.user_aim
|
---|
52 | // yim users.user_yim
|
---|
53 | //
|
---|
54 | //
|
---|
55 |
|
---|
56 | include_once dirname( __FILE__ ).'/../../../mainfile.php';
|
---|
57 | $path = dirname(dirname(__FILE__)) . '/';
|
---|
58 | if (file_exists($path . 'wp-load.php')) {
|
---|
59 | require_once $path . 'wp-load.php';
|
---|
60 | } else {
|
---|
61 | require_once $path . 'wp-config.php';
|
---|
62 | }
|
---|
63 |
|
---|
64 | //if( ! function_exists( 'get_xpress_mid' ) ) :
|
---|
65 | function get_xpress_mid($mydirname){
|
---|
66 | $xoopsDB =& Database::getInstance();
|
---|
67 | $module_tbl = $xoopsDB->prefix('modules');
|
---|
68 | $module_dir = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
69 | $module_id = 0;
|
---|
70 |
|
---|
71 | $sql = "SELECT mid FROM $module_tbl WHERE dirname LIKE '$mydirname'";
|
---|
72 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
73 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
74 | $row = $xoopsDB->fetchArray($result);
|
---|
75 | $module_id = $row['mid'];
|
---|
76 | }
|
---|
77 | return $module_id;
|
---|
78 | }
|
---|
79 | //endif;
|
---|
80 |
|
---|
81 |
|
---|
82 | //if( ! function_exists( 'get_xpress_user_level' ) ) :
|
---|
83 | function get_xpress_user_level($mydirname , $uid=0){
|
---|
84 | if ($uid == 0){
|
---|
85 | return 0;
|
---|
86 | }
|
---|
87 |
|
---|
88 | global $xoopsModule;
|
---|
89 | $xoopsDB =& Database::getInstance();
|
---|
90 | $db_groups_users_link = $xoopsDB->prefix('groups_users_link');
|
---|
91 | $db_group_permission = $xoopsDB->prefix('group_permission');
|
---|
92 | $module_tbl = $xoopsDB->prefix('modules');
|
---|
93 |
|
---|
94 | $module_id = get_xpress_mid($mydirname);
|
---|
95 | $sql = "SELECT uid FROM $db_groups_users_link WHERE groupid = 1 AND uid = $uid";
|
---|
96 |
|
---|
97 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
98 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
99 | return 5;
|
---|
100 | }
|
---|
101 |
|
---|
102 | $sql = "SELECT Max($db_group_permission.gperm_itemid) AS user_level ,$db_groups_users_link.uid ";
|
---|
103 | $sql .= "FROM $db_groups_users_link LEFT JOIN $db_group_permission ON $db_groups_users_link.groupid = $db_group_permission.gperm_groupid ";
|
---|
104 | $sql .= "WHERE $db_group_permission.gperm_modid = $module_id ";
|
---|
105 | $sql .= "GROUP BY $db_groups_users_link.uid ";
|
---|
106 | $sql .= "HAVING $db_groups_users_link.uid = $uid";
|
---|
107 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
108 | if ($result === false){
|
---|
109 | return 0;
|
---|
110 | }else{
|
---|
111 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
112 | $row = $xoopsDB->fetchArray($result);
|
---|
113 | $level = $row['user_level'];
|
---|
114 | return $level;
|
---|
115 | } else {
|
---|
116 | return 0;
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 | //endif;
|
---|
121 |
|
---|
122 | //if( ! function_exists( 'get_now_user_level' ) ) :
|
---|
123 | function get_now_user_level(){
|
---|
124 |
|
---|
125 | global $xoopsModule;
|
---|
126 |
|
---|
127 | if(empty($GLOBALS['user_level'])){
|
---|
128 | return 0;
|
---|
129 | } else {
|
---|
130 | //$user_id = $GLOBALS["xoopsUser"]->getVar("uid");
|
---|
131 | //$level = xpress2wp_user_level(get_xpress_user_level($mydirname , $user_id));
|
---|
132 | //$level = get_wp_user_level($mydirname,$user_id);
|
---|
133 | $level = $GLOBALS['user_level'];
|
---|
134 | return $level;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | //endif;
|
---|
138 |
|
---|
139 | //if( ! function_exists( 'get_wp_user_leve' ) ) :
|
---|
140 | function get_wp_user_level($mydirname,$uid=0){
|
---|
141 | $wp_prefix = get_xpress_prefix($mydirname);
|
---|
142 | $xoopsDB =& Database::getInstance();
|
---|
143 | $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta');
|
---|
144 | $meta_key_str = $xoopsDB->prefix($wp_prefix . 'user_level');
|
---|
145 | $sql = "SELECT meta_value FROM $db_xpress_usermeta WHERE (user_id = $uid) AND (meta_key = $meta_key)";
|
---|
146 | $res = $xoopsDB->query($sql, 0, 0);
|
---|
147 | if ($res === false){
|
---|
148 | return 0;
|
---|
149 | }else{
|
---|
150 | if ($xoopsDB->getRowsNum($res) > 0){
|
---|
151 | $row = $xoopsDB->fetchArray($res);
|
---|
152 | $level = $row['meta_value'];
|
---|
153 | return $level;
|
---|
154 | } else {
|
---|
155 | return 0;
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 | }
|
---|
160 | //endif;
|
---|
161 |
|
---|
162 | //if( ! function_exists( 'get_xpress_prefix' ) ) :
|
---|
163 | function get_xpress_prefix($mydirname){
|
---|
164 | global $xoopsModule;
|
---|
165 | if ($mydirname == 'wordpress'){
|
---|
166 | return 'wp_';
|
---|
167 | } else {
|
---|
168 | return $mydirname . '_';
|
---|
169 | }
|
---|
170 | }
|
---|
171 | //endif;
|
---|
172 |
|
---|
173 | //if( ! function_exists( 'xpress_user_found' ) ) :
|
---|
174 | function xpress_user_found($mydirname, $uid){
|
---|
175 | $wp_prefix = get_xpress_prefix($mydirname);
|
---|
176 | $xoopsDB =& Database::getInstance();
|
---|
177 | $db_xpress_users = $xoopsDB->prefix($wp_prefix . 'users');
|
---|
178 |
|
---|
179 | $sql = "SELECT ID FROM $db_xpress_users WHERE ID = $uid";
|
---|
180 | $res = $xoopsDB->query($sql, 0, 0);
|
---|
181 | if ($res === false){
|
---|
182 | return false;
|
---|
183 | } else {
|
---|
184 | if ($xoopsDB->getRowsNum($res) > 0){
|
---|
185 | return true;
|
---|
186 | } else {
|
---|
187 | return false;
|
---|
188 | }
|
---|
189 | }
|
---|
190 | }
|
---|
191 | //endif;
|
---|
192 |
|
---|
193 | //if( ! function_exists( 'xpress2wp_user_level' ) ) :
|
---|
194 | function xpress2wp_user_level($level){
|
---|
195 | switch($level) {
|
---|
196 | case 5:
|
---|
197 | return 10;
|
---|
198 | case 4:
|
---|
199 | return 7;
|
---|
200 | case 3:
|
---|
201 | return 2;
|
---|
202 | case 2:
|
---|
203 | return 1;
|
---|
204 | case 1:
|
---|
205 | return 0;
|
---|
206 | default:
|
---|
207 | return 0;
|
---|
208 | }
|
---|
209 | }
|
---|
210 | //endif;
|
---|
211 |
|
---|
212 | //if( ! function_exists( 'get_capabillities_name' ) ) :
|
---|
213 | function get_capabillities_name($level){
|
---|
214 | switch($level) {
|
---|
215 | case 10:
|
---|
216 | return 'administrator';
|
---|
217 | case 7:
|
---|
218 | return 'editor';
|
---|
219 | case 2:
|
---|
220 | return 'author';
|
---|
221 | case 1:
|
---|
222 | return 'contributor';
|
---|
223 | case 0:
|
---|
224 | return 'subscriber';
|
---|
225 | default:
|
---|
226 | return 'subscriber';
|
---|
227 | }
|
---|
228 | }
|
---|
229 | //endif;
|
---|
230 |
|
---|
231 | //if( ! function_exists( 'xpress_usermeta_sync' ) ) :
|
---|
232 | function xpress_usermeta_sync($mydirname , $uid,$meta_key,$meta_value){
|
---|
233 | $wp_prefix = get_xpress_prefix($mydirname);
|
---|
234 | $xoopsDB =& Database::getInstance();
|
---|
235 | $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta');
|
---|
236 | $sql = "SELECT user_id FROM $db_xpress_usermeta WHERE (user_id = $uid) AND (meta_key = $meta_key)";
|
---|
237 | $res = $xoopsDB->query($sql, 0, 0);
|
---|
238 |
|
---|
239 | if ($res === false){
|
---|
240 | $sql2 = "INSERT INTO $db_xpress_usermeta (user_id,meta_key,meta_value) VALUES ($uid,$meta_key,$meta_value)";
|
---|
241 | }else {
|
---|
242 | if ($xoopsDB->getRowsNum($res) > 0){
|
---|
243 |
|
---|
244 | $sql2 = "UPDATE $db_xpress_usermeta SET meta_value = $meta_value WHERE (user_id = $uid) AND (meta_key = $meta_key)";
|
---|
245 | } else {
|
---|
246 | $sql2 = "INSERT INTO $db_xpress_usermeta (user_id,meta_key,meta_value) VALUES ($uid,$meta_key,$meta_value)";
|
---|
247 | }
|
---|
248 | }
|
---|
249 | $res = $xoopsDB->queryF($sql2, 0, 0);
|
---|
250 | if ($res === false) {
|
---|
251 | $ret = "...ERR($sql2)";
|
---|
252 | return $ret;
|
---|
253 | } else {
|
---|
254 | return '';
|
---|
255 | }
|
---|
256 |
|
---|
257 | }
|
---|
258 | //endif;
|
---|
259 |
|
---|
260 | //if( ! function_exists( 'sql_str' ) ) :
|
---|
261 | function sql_str($text = ''){
|
---|
262 | return "'" . $text . "'";
|
---|
263 | }
|
---|
264 | //endif;
|
---|
265 |
|
---|
266 | //if( ! function_exists( 'xpress_user_sync' ) ) :
|
---|
267 | function xpress_user_sync($sync_uid = 0){
|
---|
268 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
269 |
|
---|
270 | if( is_object( @$GLOBALS["xoopsModule"] ) ) {
|
---|
271 | $wp_prefix = get_xpress_prefix($mydirname);
|
---|
272 | $xoopsDB =& Database::getInstance();
|
---|
273 | $db_xoops_users = $xoopsDB->prefix('users');
|
---|
274 | $db_xpress_users = $xoopsDB->prefix($wp_prefix . 'users');
|
---|
275 |
|
---|
276 | $ret_str = 'Do Sync';
|
---|
277 |
|
---|
278 | if ($sync_uid == 0) {
|
---|
279 | $xu_sql = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users";
|
---|
280 | } else {
|
---|
281 | $xu_sql = "SELECT uid ,name ,uname ,pass ,email, url, user_regdate, user_aim, user_yim FROM $db_xoops_users WHERE uid = $sync_uid";
|
---|
282 | }
|
---|
283 |
|
---|
284 | $xu_res = $xoopsDB->query($xu_sql, 0, 0);
|
---|
285 | if ($xu_res === false){
|
---|
286 | $ret_str .= '...ERR ('. $xu_sql . ')';
|
---|
287 | return $ret_str;
|
---|
288 | }else {
|
---|
289 | while($xu_row = $xoopsDB->fetchArray($xu_res)){
|
---|
290 | $xpress_user_level = get_xpress_user_level($mydirname , $xu_row['uid']);
|
---|
291 | if ($xpress_user_level < 1){
|
---|
292 | $ret_str .= "...PASS '" . $xu_row['uname'] ."'[uid=".$xu_row['uid'] ."](not xpress user)";
|
---|
293 | if ($sync_uid != 0){
|
---|
294 | $ret_str .= '...NOT XPRESS USER ' . $xu_row['uname'];
|
---|
295 | return $ret_str;
|
---|
296 | }
|
---|
297 | } else {
|
---|
298 | $user_ID = $xu_row['uid'];
|
---|
299 | $user_level = xpress2wp_user_level($xpress_user_level);
|
---|
300 | if ($user_level == 10 ){
|
---|
301 | $capabillities_name = 'administrator';
|
---|
302 | }else {
|
---|
303 | if (!empty($GLOBALS["xoopsModuleConfig"]["use_wp_userlevel"])){
|
---|
304 | $capabillities_name = get_option('default_role');
|
---|
305 | }else {
|
---|
306 | $capabillities_name = get_capabillities_name($user_level);
|
---|
307 | }
|
---|
308 | }
|
---|
309 | $user_login_name = sql_str($xu_row['uname']);
|
---|
310 | $user_pass_md5 = sql_str( $xu_row['pass']);
|
---|
311 | $user_email = sql_str( $xu_row['email']);
|
---|
312 | $user_url = sql_str( $xu_row['url']);
|
---|
313 | $user_regist_time = sql_str(date('Y-m-d H:i:s' , $xu_row['user_regdate']));
|
---|
314 | $user_nicename = sql_str( $xu_row['uname']);
|
---|
315 | $user_status = 0;
|
---|
316 | $user_display_name =sql_str( empty($xu_row['name']) ? $xu_row['uname'] :$xu_row['name'] );
|
---|
317 | $user_nickname = sql_str( empty($xu_row['name']) ? $xu_row['uname'] :$xu_row['name'] );
|
---|
318 | $user_aim = sql_str( $xu_row['user_aim']);
|
---|
319 | $user_yim = sql_str( $xu_row['user_yim']);
|
---|
320 | $user_first_name = sql_str( $xu_row['uname']);
|
---|
321 | $user_last_name = sql_str('');
|
---|
322 | $user_description = sql_str('');
|
---|
323 | $user_jabber = sql_str('');
|
---|
324 | $user_rich_editing = sql_str('true');
|
---|
325 |
|
---|
326 | $is_update = false;
|
---|
327 |
|
---|
328 | // $capabillities = sql_str(get_capabillities($user_level));
|
---|
329 |
|
---|
330 | if (xpress_user_found($mydirname, $user_ID)){
|
---|
331 | $wu_sql = "UPDATE $db_xpress_users ";
|
---|
332 | $wu_sql .= 'SET ';
|
---|
333 | $wu_sql .= "user_login = $user_login_name, ";
|
---|
334 | $wu_sql .= "user_pass = $user_pass_md5, ";
|
---|
335 | $wu_sql .= "user_email = $user_email, ";
|
---|
336 | $wu_sql .= "user_url = $user_url, ";
|
---|
337 | $wu_sql .= "user_nicename = $user_nicename, ";
|
---|
338 | $wu_sql .= "user_registered = $user_regist_time, ";
|
---|
339 | $wu_sql .= "user_status = 0 ";
|
---|
340 | $wu_sql .= "WHERE (ID = $user_ID )";
|
---|
341 | if (!empty($GLOBALS["xoopsModuleConfig"]["use_wp_userlevel"])){
|
---|
342 | $ret_str .= '...UPDATE ' . $user_login_name . '(Level Not Change)';
|
---|
343 | } else {
|
---|
344 | $ret_str .= '...UPDATE ' . $user_login_name . '(' . $capabillities_name . ')';
|
---|
345 | }
|
---|
346 | $is_update = true;
|
---|
347 | }else{
|
---|
348 | $wu_sql = "INSERT INTO $db_xpress_users ";
|
---|
349 | $wu_sql .= "(ID , user_login , user_pass ,user_email , user_url , user_nicename " ;
|
---|
350 | $wu_sql .= " , user_registered , user_status , display_name) ";
|
---|
351 | $wu_sql .= "VALUES ";
|
---|
352 | $wu_sql .= "($user_ID, $user_login_name, $user_pass_md5, $user_email, $user_url, $user_nicename ";
|
---|
353 | $wu_sql .= " , $user_regist_time, $user_status, $user_display_name)";
|
---|
354 | if (!empty($GLOBALS["xoopsModuleConfig"]["use_wp_userlevel"])){
|
---|
355 | $ret_str .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . '-WP Default)';
|
---|
356 | } else {
|
---|
357 | $ret_str .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . ')';
|
---|
358 | }
|
---|
359 | }
|
---|
360 |
|
---|
361 | $wu_res = $xoopsDB->queryF($wu_sql, 0, 0);
|
---|
362 |
|
---|
363 | if ($wu_res === false){
|
---|
364 | $ret_str .= '...ERR(' . $wu_sql . ')';
|
---|
365 | return $ret_str;
|
---|
366 | }
|
---|
367 |
|
---|
368 | if (!empty($GLOBALS["xoopsModuleConfig"]["use_wp_userlevel"])){
|
---|
369 | if (!$is_update){
|
---|
370 | $sycc_user = new WP_User($user_ID);
|
---|
371 | $sycc_user->set_role($capabillities_name);
|
---|
372 | }
|
---|
373 | } else {
|
---|
374 | $sycc_user = new WP_User($user_ID);
|
---|
375 | $sycc_user->set_role($capabillities_name);
|
---|
376 | }
|
---|
377 |
|
---|
378 | if( $is_update === false){
|
---|
379 | $meta_key = sql_str('nickname');
|
---|
380 | $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_nickname);
|
---|
381 | if(!empty($ans)){
|
---|
382 | $ret_str .= $ans;
|
---|
383 | return $ret_str;
|
---|
384 | }
|
---|
385 | $meta_key = sql_str('first_name');
|
---|
386 | $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_first_name);
|
---|
387 | if(!empty($ans)){
|
---|
388 | $ret_str .= $ans;
|
---|
389 | return $ret_str;
|
---|
390 | }
|
---|
391 | $meta_key = sql_str('last_name');
|
---|
392 | $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_last_name);
|
---|
393 | if(!empty($ans)){
|
---|
394 | $ret_str .= $ans;
|
---|
395 | return $ret_str;
|
---|
396 | }
|
---|
397 | $meta_key = sql_str('description');
|
---|
398 | $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_description);
|
---|
399 | if(!empty($ans)){
|
---|
400 | $ret_str .= $ans;
|
---|
401 | return $ret_str;
|
---|
402 | }
|
---|
403 | $meta_key = sql_str('jabber');
|
---|
404 | $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_jabber);
|
---|
405 | if(!empty($ans)){
|
---|
406 | $ret_str .= $ans;
|
---|
407 | return $ret_str;
|
---|
408 | }
|
---|
409 | }
|
---|
410 | $meta_key = sql_str('aim');
|
---|
411 | $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_aim);
|
---|
412 | if(!empty($ans)){
|
---|
413 | $ret_str .= $ans;
|
---|
414 | return $ret_str;
|
---|
415 | }
|
---|
416 | $meta_key = sql_str('yim');
|
---|
417 | $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_yim);
|
---|
418 | if(!empty($ans)){
|
---|
419 | $ret_str .= $ans;
|
---|
420 | return $ret_str;
|
---|
421 | }
|
---|
422 | if ($is_update === false ) {
|
---|
423 | $meta_key = sql_str('rich_editing');
|
---|
424 | $ans =xpress_usermeta_sync($mydirname, $user_ID,$meta_key,$user_rich_editing);
|
---|
425 | if(!empty($ans)){
|
---|
426 | $ret_str .= $ans;
|
---|
427 | return $ret_str;
|
---|
428 | }
|
---|
429 | }
|
---|
430 | }
|
---|
431 | }
|
---|
432 | }
|
---|
433 | $ret_str .= "...END";
|
---|
434 | return $ret_str;
|
---|
435 | }
|
---|
436 | }
|
---|
437 | //endif;
|
---|
438 |
|
---|
439 | //if( ! function_exists( 'check_user_role_prefix' ) ) :
|
---|
440 | function check_user_role_prefix($mydirname){
|
---|
441 | $wp_prefix = get_xpress_prefix($mydirname);
|
---|
442 | $xoopsDB =& Database::getInstance();
|
---|
443 | $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta');
|
---|
444 | $user_meta_prefix =$xoopsDB->prefix($wp_prefix);
|
---|
445 |
|
---|
446 | $sql = "SELECT * FROM $db_xpress_usermeta WHERE meta_key LIKE '%_" . $wp_prefix . "user_level' OR meta_key LIKE '%_" . $wp_prefix . "capabilities' OR meta_key LIKE '%_" . $wp_prefix . "autosave_draft_ids'";
|
---|
447 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
448 | if ($result === false){
|
---|
449 | return -1;
|
---|
450 | }else{
|
---|
451 | $i=0;
|
---|
452 | while($row = $xoopsDB->fetchArray($result)){
|
---|
453 | $meta_key = $row['meta_key'];
|
---|
454 | if (strpos($meta_key,$user_meta_prefix) === false) {
|
---|
455 | $i++;
|
---|
456 | }
|
---|
457 | }
|
---|
458 | return $i;
|
---|
459 | }
|
---|
460 | }
|
---|
461 | //endif;
|
---|
462 |
|
---|
463 | //if( ! function_exists( 'same_metakey_delete' ) ) :
|
---|
464 | function same_metakey_delete($mydirname,$metakey){
|
---|
465 | $wp_prefix = get_xpress_prefix($mydirname);
|
---|
466 | $xoopsDB =& Database::getInstance();
|
---|
467 | $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta');
|
---|
468 | $user_meta_prefix =$xoopsDB->prefix($wp_prefix);
|
---|
469 |
|
---|
470 | $sql = "DELETE FROM $db_xpress_usermeta WHERE meta_key LIKE '$metakey'";
|
---|
471 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
472 | if ($result === false){
|
---|
473 | return false;
|
---|
474 | }else{
|
---|
475 | return true;
|
---|
476 | }
|
---|
477 | }
|
---|
478 | //endif;
|
---|
479 |
|
---|
480 | //if( ! function_exists( 'repair_user_role_prefix' ) ) :
|
---|
481 | function repair_user_role_prefix($mydirname){
|
---|
482 | $wp_prefix = get_xpress_prefix($mydirname);
|
---|
483 | $xoopsDB =& Database::getInstance();
|
---|
484 | $db_xpress_usermeta = $xoopsDB->prefix($wp_prefix . 'usermeta');
|
---|
485 | $user_meta_prefix =$xoopsDB->prefix($wp_prefix);
|
---|
486 | $ret = '';
|
---|
487 |
|
---|
488 | $sql = "SELECT * FROM $db_xpress_usermeta WHERE meta_key LIKE '%_" . $wp_prefix . "user_level' OR meta_key LIKE '%_" . $wp_prefix . "capabilities' OR meta_key LIKE '%_" . $wp_prefix . "autosave_draft_ids'";
|
---|
489 | $result = $xoopsDB->queryF($sql, 0, 0);
|
---|
490 | if ($result === false){
|
---|
491 | return -1;
|
---|
492 | }else{
|
---|
493 | $i=0;
|
---|
494 | while($row = $xoopsDB->fetchArray($result)){
|
---|
495 | $meta_key = $row['meta_key'];
|
---|
496 | $umeta_id = $row['umeta_id'];
|
---|
497 | if (strpos($meta_key,$user_meta_prefix) === false) {
|
---|
498 | $new_meta_key = '';
|
---|
499 | if (strpos($meta_key,$wp_prefix.'user_level')){
|
---|
500 | $new_meta_key = $xoopsDB->prefix($wp_prefix . 'user_level');
|
---|
501 | }
|
---|
502 |
|
---|
503 | if (strpos($meta_key,$wp_prefix.'capabilities')){
|
---|
504 | $new_meta_key = $xoopsDB->prefix($wp_prefix . 'capabilities');
|
---|
505 | }
|
---|
506 |
|
---|
507 | if (strpos($meta_key,$wp_prefix.'autosave_draft_ids')){
|
---|
508 | $new_meta_key = $xoopsDB->prefix($wp_prefix . 'autosave_draft_ids');
|
---|
509 | }
|
---|
510 |
|
---|
511 | if (!empty($new_meta_key)){
|
---|
512 | same_metakey_delete($mydirname,$new_meta_key);
|
---|
513 |
|
---|
514 | $repair_sql = "UPDATE $db_xpress_usermeta ";
|
---|
515 | $repair_sql .= 'SET ';
|
---|
516 | $repair_sql .= "meta_key = '$new_meta_key' ";
|
---|
517 | $repair_sql .= "WHERE (umeta_id = $umeta_id )";
|
---|
518 | $repair_res = $xoopsDB->queryF($repair_sql, 0, 0);
|
---|
519 | if ($repair_res === false){
|
---|
520 | $ret .= '...ERR(' . $meta_key . '->' . $new_meta_key . ')<br>';
|
---|
521 | } else {
|
---|
522 | $ret .= '...DO(' . $meta_key . '->' . $new_meta_key . ')<br>';
|
---|
523 | }
|
---|
524 | }
|
---|
525 | }
|
---|
526 | }
|
---|
527 | }
|
---|
528 | return $ret;
|
---|
529 | }
|
---|
530 | //endif;
|
---|
531 |
|
---|
532 | ?> |
---|