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