[257] | 1 | <?php
|
---|
| 2 | /*
|
---|
| 3 | * XPressME - WordPress for XOOPS
|
---|
| 4 | *
|
---|
| 5 | * @copyright XPressME Project http://www.toemon.com
|
---|
| 6 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license
|
---|
| 7 | * @author toemon
|
---|
| 8 | * @package module::xpress
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | function wp_uid_to_xoops_uid($wp_uid = ''){
|
---|
| 12 | global $xoopsDB,$xoops_db;
|
---|
| 13 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
| 14 |
|
---|
| 15 | if ($mydirname == 'wordpress'){
|
---|
| 16 | $wp_prefix = 'wp';
|
---|
| 17 | } else {
|
---|
| 18 | $wp_prefix = $mydirname;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | if (empty($xoops_db)) { // not load XPressME
|
---|
| 22 | $xoops_user_tbl = $xoopsDB->prefix('users');
|
---|
| 23 | $wp_user_tbl = $xoopsDB->prefix($wp_prefix . "_users");
|
---|
| 24 |
|
---|
| 25 | $wp_user_SQL ="SELECT user_login FROM $wp_user_tbl WHERE ID = $wp_uid ";
|
---|
| 26 | $wp_user_Res = $xoopsDB->query($wp_user_SQL, 0, 0);
|
---|
| 27 | if ($xoopsDB->getRowsNum($wp_user_Res) > 0){
|
---|
| 28 | $wp_user_Row = $xoopsDB->fetchArray($wp_user_Res);
|
---|
| 29 | $wp_user_name = $wp_user_Row['user_login'];
|
---|
| 30 |
|
---|
| 31 | $xoops_user_SQL ="SELECT uid FROM $xoops_user_tbl WHERE uname LIKE '$wp_user_name'";
|
---|
| 32 | $xoops_user_Res = $xoopsDB->query($xoops_user_SQL, 0, 0);
|
---|
| 33 | if ($xoopsDB->getRowsNum($xoops_user_Res) > 0){
|
---|
| 34 | $xoops_user_Row = $xoopsDB->fetchArray($xoops_user_Res);
|
---|
| 35 | $xoops_uid = $xoops_user_Row['uid'];
|
---|
| 36 | return $xoops_uid;
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 | return 0;
|
---|
| 40 | } else { // load XPressME or not Load XOOPS
|
---|
| 41 | $xoops_user_tbl = get_xoops_prefix() . 'users';
|
---|
| 42 | $wp_user_tbl = get_wp_prefix() . 'users';
|
---|
| 43 | $wp_user_name = $xoops_db->get_var("SELECT user_login FROM $wp_user_tbl WHERE ID = $wp_uid ");
|
---|
| 44 | if (empty($wp_user_name)) return 0;
|
---|
| 45 | $xoops_uid = $xoops_db->get_var("SELECT uid FROM $xoops_user_tbl WHERE uname LIKE '$wp_user_name'");
|
---|
| 46 | if (!empty($xoops_uid)) return $xoops_uid; else return 0;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | function xoops_uid_to_wp_uid($xoops_uid = ''){
|
---|
| 50 | global $xoopsDB,$xoops_db;
|
---|
| 51 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
| 52 |
|
---|
| 53 | if ($mydirname == 'wordpress'){
|
---|
| 54 | $wp_prefix = 'wp';
|
---|
| 55 | } else {
|
---|
| 56 | $wp_prefix = $mydirname;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | if (empty($xoops_db)) { // not load XPressME
|
---|
| 60 | $xoops_user_tbl = $xoopsDB->prefix('users');
|
---|
| 61 | $wp_user_tbl = $xoopsDB->prefix($wp_prefix . "_users");
|
---|
| 62 |
|
---|
| 63 | $xoops_user_SQL ="SELECT uname FROM $xoops_user_tbl WHERE uid = $xoops_uid";
|
---|
| 64 | $xoops_user_Res = $xoopsDB->query($xoops_user_SQL, 0, 0);
|
---|
| 65 | if ($xoopsDB->getRowsNum($xoops_user_Res) > 0){
|
---|
| 66 | $xoops_user_Row = $xoopsDB->fetchArray($xoops_user_Res);
|
---|
| 67 | $xoops_user_name = $xoops_user_Row['uname'];
|
---|
| 68 |
|
---|
| 69 | $wp_user_SQL ="SELECT ID FROM $wp_user_tbl WHERE user_login LIKE '$xoops_user_name'";
|
---|
| 70 | $wp_user_Res = $xoopsDB->query($wp_user_SQL, 0, 0);
|
---|
| 71 | if ($xoopsDB->getRowsNum($wp_user_Res) > 0){
|
---|
| 72 | $wp_user_Row = $xoopsDB->fetchArray($wp_user_Res);
|
---|
| 73 | $wp_user_id = $wp_user_Row['ID'];
|
---|
| 74 | return $wp_user_id;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | return 0;
|
---|
| 78 | } else { // load XPressME or not Load XOOPS
|
---|
| 79 | $xoops_user_tbl = get_xoops_prefix() . 'users';
|
---|
| 80 | $wp_user_tbl = get_wp_prefix() . 'users';
|
---|
| 81 | $xoops_user_name = $xoops_db->get_var("SELECT uname FROM $xoops_user_tbl WHERE uid = $xoops_uid");
|
---|
| 82 | if (empty($xoops_user_name)) return 0;
|
---|
| 83 | $wp_user_id = $xoops_db->get_var("SELECT ID FROM $wp_user_tbl WHERE user_login LIKE '$xoops_user_name'");
|
---|
| 84 | if (!empty($wp_user_id)) return $wp_user_id; else return 0;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | }
|
---|
| 88 | ?>
|
---|