| 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 | if (!function_exists('wp_uid_to_xoops_uid')){ | 
|---|
| 11 | function wp_uid_to_xoops_uid($wp_uid = '',$mydirname){ | 
|---|
| 12 | global $xoopsDB,$xoops_db; | 
|---|
| 13 | if (empty($mydirname)) | 
|---|
| 14 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ; | 
|---|
| 15 |  | 
|---|
| 16 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); | 
|---|
| 17 |  | 
|---|
| 18 | if (empty($xoops_db)) { // not load XPressME | 
|---|
| 19 | $xoops_user_tbl = $xoopsDB->prefix('users'); | 
|---|
| 20 | $wp_user_tbl = $xoopsDB->prefix($wp_prefix . "_users"); | 
|---|
| 21 |  | 
|---|
| 22 | $wp_user_SQL ="SELECT user_login FROM $wp_user_tbl WHERE ID = $wp_uid "; | 
|---|
| 23 | $wp_user_Res = $xoopsDB->query($wp_user_SQL, 0, 0); | 
|---|
| 24 | if ($xoopsDB->getRowsNum($wp_user_Res)  > 0){ | 
|---|
| 25 | $wp_user_Row = $xoopsDB->fetchArray($wp_user_Res); | 
|---|
| 26 | $wp_user_name = $wp_user_Row['user_login']; | 
|---|
| 27 |  | 
|---|
| 28 | $xoops_user_SQL ="SELECT uid FROM $xoops_user_tbl WHERE uname LIKE '$wp_user_name'"; | 
|---|
| 29 | $xoops_user_Res = $xoopsDB->query($xoops_user_SQL, 0, 0); | 
|---|
| 30 | if ($xoopsDB->getRowsNum($xoops_user_Res)  > 0){ | 
|---|
| 31 | $xoops_user_Row = $xoopsDB->fetchArray($xoops_user_Res); | 
|---|
| 32 | $xoops_uid = $xoops_user_Row['uid']; | 
|---|
| 33 | return $xoops_uid; | 
|---|
| 34 | } | 
|---|
| 35 | } | 
|---|
| 36 | return 0; | 
|---|
| 37 | } else { // load XPressME or not Load XOOPS | 
|---|
| 38 | $xoops_user_tbl = get_xoops_prefix() . 'users'; | 
|---|
| 39 | $wp_user_tbl = get_wp_prefix() . 'users'; | 
|---|
| 40 | $wp_user_name = $xoops_db->get_var("SELECT user_login FROM $wp_user_tbl WHERE ID = $wp_uid "); | 
|---|
| 41 | if (empty($wp_user_name)) return 0; | 
|---|
| 42 | $xoops_uid = $xoops_db->get_var("SELECT uid FROM $xoops_user_tbl WHERE uname LIKE '$wp_user_name'"); | 
|---|
| 43 | if (!empty($xoops_uid)) return $xoops_uid; else return 0; | 
|---|
| 44 | } | 
|---|
| 45 | } | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | if (!function_exists('xoops_uid_to_wp_uid')){ | 
|---|
| 49 | function xoops_uid_to_wp_uid($xoops_uid = '',$mydirname){ | 
|---|
| 50 | global $xoopsDB,$xoops_db; | 
|---|
| 51 | if (empty($mydirname)) | 
|---|
| 52 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ; | 
|---|
| 53 |  | 
|---|
| 54 | $wp_prefix = preg_replace('/wordpress/','wp',$mydirname); | 
|---|
| 55 |  | 
|---|
| 56 | if (empty($xoops_db)) { // not load XPressME | 
|---|
| 57 | $xoops_user_tbl = $xoopsDB->prefix('users'); | 
|---|
| 58 | $wp_user_tbl = $xoopsDB->prefix($wp_prefix . "_users"); | 
|---|
| 59 |  | 
|---|
| 60 | $xoops_user_SQL ="SELECT uname FROM $xoops_user_tbl WHERE uid =  $xoops_uid"; | 
|---|
| 61 | $xoops_user_Res = $xoopsDB->query($xoops_user_SQL, 0, 0); | 
|---|
| 62 | if ($xoopsDB->getRowsNum($xoops_user_Res)  > 0){ | 
|---|
| 63 | $xoops_user_Row = $xoopsDB->fetchArray($xoops_user_Res); | 
|---|
| 64 | $xoops_user_name = $xoops_user_Row['uname']; | 
|---|
| 65 |  | 
|---|
| 66 | $wp_user_SQL ="SELECT ID FROM $wp_user_tbl WHERE user_login LIKE '$xoops_user_name'"; | 
|---|
| 67 | $wp_user_Res = $xoopsDB->query($wp_user_SQL, 0, 0); | 
|---|
| 68 | if ($xoopsDB->getRowsNum($wp_user_Res)  > 0){ | 
|---|
| 69 | $wp_user_Row = $xoopsDB->fetchArray($wp_user_Res); | 
|---|
| 70 | $wp_user_id = $wp_user_Row['ID']; | 
|---|
| 71 | return $wp_user_id; | 
|---|
| 72 | } | 
|---|
| 73 | } | 
|---|
| 74 | return 0; | 
|---|
| 75 | } else { // load XPressME or not Load XOOPS | 
|---|
| 76 | $xoops_user_tbl = get_xoops_prefix() . 'users'; | 
|---|
| 77 | $wp_user_tbl = get_wp_prefix() . 'users'; | 
|---|
| 78 | $xoops_user_name = $xoops_db->get_var("SELECT uname FROM $xoops_user_tbl WHERE uid =  $xoops_uid"); | 
|---|
| 79 | if (empty($xoops_user_name)) return 0; | 
|---|
| 80 | $wp_user_id = $xoops_db->get_var("SELECT ID FROM $wp_user_tbl WHERE user_login LIKE '$xoops_user_name'"); | 
|---|
| 81 | if (!empty($wp_user_id)) return $wp_user_id; else return 0; | 
|---|
| 82 | } | 
|---|
| 83 | } | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | // XOOPS user ID is get from the name and the mail address of the contributor of the comment that is not user_id. | 
|---|
| 87 | if (!function_exists('wp_comment_author_to_xoops_uid')){ | 
|---|
| 88 | function wp_comment_author_to_xoops_uid($name = '',$email = ''){ | 
|---|
| 89 | global $xoopsDB,$xoops_db; | 
|---|
| 90 | if (empty($name) || empty($email)) return 0; | 
|---|
| 91 |  | 
|---|
| 92 | if (empty($xoops_db)) { // not load XPressME | 
|---|
| 93 | $xoops_user_tbl = $xoopsDB->prefix('users'); | 
|---|
| 94 | $wp_user_tbl = $xoopsDB->prefix($wp_prefix . "_users"); | 
|---|
| 95 |  | 
|---|
| 96 | $xoops_uid = 0; | 
|---|
| 97 | $xoops_user_SQL ="SELECT uid FROM $xoops_user_tbl WHERE uname = '$name' AND email = '$email'"; | 
|---|
| 98 | $xoops_user_Res = $xoopsDB->query($xoops_user_SQL, 0, 0); | 
|---|
| 99 | if ($xoopsDB->getRowsNum($xoops_user_Res)  > 0){ | 
|---|
| 100 | $xoops_user_Row = $xoopsDB->fetchArray($xoops_user_Res); | 
|---|
| 101 | $xoops_uid = $xoops_user_Row['uid']; | 
|---|
| 102 | } | 
|---|
| 103 | return $xoops_uid; | 
|---|
| 104 | } else { // load XPressME or not Load XOOPS | 
|---|
| 105 | $xoops_user_tbl = get_xoops_prefix() . 'users'; | 
|---|
| 106 | $xoops_uid = $xoops_db->get_var("SELECT uid FROM $xoops_user_tbl WHERE uname = '$name' AND email = '$email'"); | 
|---|
| 107 | if (empty($xoops_uid)) return 0; | 
|---|
| 108 | return $xoops_uid; | 
|---|
| 109 | } | 
|---|
| 110 | } | 
|---|
| 111 | } | 
|---|
| 112 |  | 
|---|
| 113 | // Get Multi Blog table list for WordPressMU | 
|---|
| 114 | if (!function_exists('get_table_list')){ | 
|---|
| 115 | function get_table_list($wp_prefix = '',$table_name = ''){ | 
|---|
| 116 | global $xoopsDB,$xoops_db; | 
|---|
| 117 |  | 
|---|
| 118 | $table_list = array(); | 
|---|
| 119 | $ret = array(); | 
|---|
| 120 | $wp_prefix = preg_replace('/_$/', '',$wp_prefix); | 
|---|
| 121 | $pattern = $wp_prefix . '_' . $table_name . '|' . $wp_prefix . '_[0-9]*_' . $table_name; | 
|---|
| 122 |  | 
|---|
| 123 | if (!empty($wp_prefix) && !empty($table_name)){ | 
|---|
| 124 | $sql = "SHOW TABLES LIKE '" . $wp_prefix  . '%' . $table_name . "'"; | 
|---|
| 125 |  | 
|---|
| 126 | if (empty($xoops_db)) { // not load XPressME | 
|---|
| 127 | if($result = $xoopsDB->queryF($sql)){ | 
|---|
| 128 | while($row = $xoopsDB->fetchRow($result)){ | 
|---|
| 129 | if(preg_match('/' . $pattern . '/i' , $row[0])){ | 
|---|
| 130 | $table_list[] = $row[0]; | 
|---|
| 131 | } | 
|---|
| 132 | } | 
|---|
| 133 | } | 
|---|
| 134 | } else { // load XPressME or not Load XOOPS | 
|---|
| 135 | $rows = $xoops_db->get_results($sql, ARRAY_N); | 
|---|
| 136 | foreach ($rows as $row){ | 
|---|
| 137 | if(preg_match('/' . $pattern . '/' , $row[0])){ | 
|---|
| 138 | $table_list[] = $row[0]; | 
|---|
| 139 | } | 
|---|
| 140 | } | 
|---|
| 141 | } | 
|---|
| 142 | } | 
|---|
| 143 | return $table_list; | 
|---|
| 144 | } | 
|---|
| 145 | } | 
|---|
| 146 |  | 
|---|
| 147 | // Get Middle Prefix from Table name for WordPressMU | 
|---|
| 148 | if (!function_exists('get_multi_mid_prefix')){ | 
|---|
| 149 | function get_multi_mid_prefix($wp_prefix = '',$table_name = '' , $full_table_name){ | 
|---|
| 150 | $pattern = '/' . $wp_prefix . '(.*)' . $table_name . '/'; | 
|---|
| 151 | preg_match($pattern,$full_table_name,$match); | 
|---|
| 152 | return $match[1]; | 
|---|
| 153 | } | 
|---|
| 154 | } | 
|---|
| 155 |  | 
|---|
| 156 | // Get Prefix from Table name for WordPressMU | 
|---|
| 157 | if (!function_exists('get_multi_prefix')){ | 
|---|
| 158 | function get_multi_prefix($full_table_name,$table_name = ''){ | 
|---|
| 159 | $pattern = '/'. $table_name . '/'; | 
|---|
| 160 | return preg_replace($pattern,'',$full_table_name); | 
|---|
| 161 | } | 
|---|
| 162 | } | 
|---|
| 163 | ?> | 
|---|