| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | class BxDolXMLRPCUtil |
|---|
| 4 | { |
|---|
| 5 | function getContacts($sUser, $sPwd) |
|---|
| 6 | { |
|---|
| 7 | $aRet = array (); |
|---|
| 8 | if (!($iId = BxDolXMLRPCUtil::checkLogin ($sUser, $sPwd))) |
|---|
| 9 | return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct")); |
|---|
| 10 | |
|---|
| 11 | $aAll = array(); |
|---|
| 12 | $aContacts = array (); |
|---|
| 13 | |
|---|
| 14 | // hot list |
|---|
| 15 | $r = db_res ("SELECT `p`.`ID`, `p`.`NickName` AS `Nick` FROM `Profiles` AS `p` |
|---|
| 16 | INNER JOIN `sys_fave_list` AS `h` ON (`h`.`Profile` = `p`.`ID`) |
|---|
| 17 | WHERE `h`.`ID` = $iId"); |
|---|
| 18 | while ($aRow = mysql_fetch_array ($r)) |
|---|
| 19 | $aAll[$aRow['ID']] = $aRow; |
|---|
| 20 | |
|---|
| 21 | // mail contacts received |
|---|
| 22 | $r = db_res ("SELECT `p`.`ID`, `p`.`NickName` AS `Nick` FROM `Profiles` AS `p` |
|---|
| 23 | INNER JOIN `sys_messages` AS `m` ON (`m`.`Sender` = `p`.`ID`) |
|---|
| 24 | WHERE `p`.`ID` != $iId AND `m`.`Recipient` = $iId"); |
|---|
| 25 | while ($aRow = mysql_fetch_array ($r)) |
|---|
| 26 | $aAll[$aRow['ID']] = $aRow; |
|---|
| 27 | |
|---|
| 28 | // mail contacts sent |
|---|
| 29 | $r = db_res ("SELECT `p`.`ID`, `p`.`NickName` AS `Nick` FROM `Profiles` AS `p` |
|---|
| 30 | INNER JOIN `sys_messages` AS `m` ON (`m`.`Recipient` = `p`.`ID`) |
|---|
| 31 | WHERE `p`.`ID` != $iId AND `m`.`Sender` = $iId"); |
|---|
| 32 | while ($aRow = mysql_fetch_array ($r)) |
|---|
| 33 | $aAll[$aRow['ID']] = $aRow; |
|---|
| 34 | |
|---|
| 35 | // friends 1 |
|---|
| 36 | $r = db_res ("SELECT `p`.`ID`, `p`.`NickName` AS `Nick` FROM `sys_friend_list` AS `fr` |
|---|
| 37 | LEFT JOIN `Profiles` AS `p` ON (`p`.`ID` = `fr`.`Profile`) |
|---|
| 38 | WHERE `fr`.`ID` = '$iId' AND `fr`.`Profile` != $iId AND `fr`.`Check` = '1'"); |
|---|
| 39 | while ($aRow = mysql_fetch_array ($r)) |
|---|
| 40 | $aAll[$aRow['ID']] = $aRow; |
|---|
| 41 | |
|---|
| 42 | // friends 2 |
|---|
| 43 | $r = db_res ("SELECT `p`.`ID`, `p`.`NickName` AS `Nick` FROM `sys_friend_list` AS `fr` |
|---|
| 44 | LEFT JOIN `Profiles` AS `p` ON (`p`.`ID` = `fr`.`ID`) |
|---|
| 45 | WHERE `fr`.`Profile` = '$iId' AND `fr`.`ID` != $iId AND `fr`.`Check` = '1'"); |
|---|
| 46 | while ($aRow = mysql_fetch_array ($r)) |
|---|
| 47 | $aAll[$aRow['ID']] = $aRow; |
|---|
| 48 | |
|---|
| 49 | $oZ = new BxDolAlerts('mobile', 'contacts', $iId, 0, array('contacts_data' => $aAll)); |
|---|
| 50 | $oZ->alert(); |
|---|
| 51 | |
|---|
| 52 | foreach ($aAll as $aRow) |
|---|
| 53 | { |
|---|
| 54 | $a = array ( |
|---|
| 55 | 'ID' => new xmlrpcval($aRow['ID']), |
|---|
| 56 | 'Nick' => new xmlrpcval($aRow['Nick']), |
|---|
| 57 | ); |
|---|
| 58 | $aContacts[] = new xmlrpcval($a, 'struct'); |
|---|
| 59 | } |
|---|
| 60 | return new xmlrpcval ($aContacts, "array"); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | function getCountries($sUser, $sPwd, $sLang) |
|---|
| 64 | { |
|---|
| 65 | $aRet = array (); |
|---|
| 66 | if (!($iId = BxDolXMLRPCUtil::checkLogin ($sUser, $sPwd))) |
|---|
| 67 | return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct")); |
|---|
| 68 | |
|---|
| 69 | BxDolXMLRPCUtil::setLanguage ($sLang); |
|---|
| 70 | |
|---|
| 71 | $aCountries = array (); |
|---|
| 72 | $r = db_res ("SELECT `ISO2`, `Country` FROM `sys_countries` ORDER BY `Country` ASC"); |
|---|
| 73 | while ($aRow = mysql_fetch_array ($r)) |
|---|
| 74 | { |
|---|
| 75 | $a = array ( |
|---|
| 76 | 'Name' => new xmlrpcval(_t('__'.$aRow['Country'])), |
|---|
| 77 | 'Code' => new xmlrpcval($aRow['ISO2']), |
|---|
| 78 | ); |
|---|
| 79 | $aCountries[] = new xmlrpcval($a, 'struct'); |
|---|
| 80 | } |
|---|
| 81 | return new xmlrpcval ($aCountries, "array"); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | function getThumbLink ($iId, $sType = 'thumb') |
|---|
| 85 | { |
|---|
| 86 | $sType = $sType == 'thumb' ? 'medium' : 'small'; |
|---|
| 87 | return $GLOBALS['oFunctions']->getMemberAvatar ((int)$iId, $sType); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | function getUserInfo($iId, $iIdViewer = 0, $isCountData = true) |
|---|
| 91 | { |
|---|
| 92 | if (!$iIdViewer) |
|---|
| 93 | $iIdViewer = $_COOKIE['memberID']; |
|---|
| 94 | |
|---|
| 95 | $aRet = array (); |
|---|
| 96 | $aSexSql = getProfileInfo((int)$iId); |
|---|
| 97 | $aRet['title'] = new xmlrpcval($aSexSql['Headline']); |
|---|
| 98 | $aRet['thumb'] = new xmlrpcval(BxDolXMLRPCUtil::getThumbLink($iId)); |
|---|
| 99 | $aRet['sex'] = new xmlrpcval($aSexSql['Sex']); |
|---|
| 100 | $aRet['age'] = new xmlrpcval(age($aSexSql['DateOfBirth'])); |
|---|
| 101 | $aRet['country'] = new xmlrpcval($aSexSql['Country']); |
|---|
| 102 | $aRet['city'] = new xmlrpcval($aSexSql['City']); |
|---|
| 103 | $aRet['status'] = new xmlrpcval($aSexSql['UserStatusMessage']); |
|---|
| 104 | |
|---|
| 105 | if ($isCountData) { |
|---|
| 106 | $aRet['countFriends'] = new xmlrpcval(getFriendNumber($iId)); |
|---|
| 107 | $aRet['countPhotos'] = new xmlrpcval(BxDolXMLRPCMedia::_getMediaCount('photo', $iId, $iIdViewer)); |
|---|
| 108 | $aRet['countVideos'] = new xmlrpcval(BxDolXMLRPCMedia::_getMediaCount('video', $iId, $iIdViewer)); |
|---|
| 109 | $aRet['countSounds'] = new xmlrpcval(BxDolXMLRPCMedia::_getMediaCount('music', $iId, $iIdViewer)); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | bx_import('BxDolAlerts'); |
|---|
| 113 | $oZ = new BxDolAlerts('mobile', 'user_info', $iId, $iIdViewer, array('profile' => &$aSexSql, 'return_data' => &$aRet)); |
|---|
| 114 | $oZ->alert(); |
|---|
| 115 | |
|---|
| 116 | return $aRet; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | function fillProfileArray ($a, $sImage = 'icon', $iIdViewer = 0) |
|---|
| 120 | { |
|---|
| 121 | if (!$iIdViewer) |
|---|
| 122 | $iIdViewer = $_COOKIE['memberID']; |
|---|
| 123 | |
|---|
| 124 | $sImageKey = ucfirst ($sImage); |
|---|
| 125 | $sImage = BxDolXMLRPCUtil::getThumbLink($a['ID'], $sImage); |
|---|
| 126 | |
|---|
| 127 | bx_import('BxDolAlbums'); |
|---|
| 128 | |
|---|
| 129 | $aRet = array ( |
|---|
| 130 | 'ID' => new xmlrpcval($a['ID']), |
|---|
| 131 | 'Title' => new xmlrpcval($a['Headline']), |
|---|
| 132 | 'Nick' => new xmlrpcval($a['NickName']), |
|---|
| 133 | 'Sex' => new xmlrpcval($a['Sex']), |
|---|
| 134 | 'Age' => new xmlrpcval(age($a['DateOfBirth'])), |
|---|
| 135 | 'Country' => new xmlrpcval(_t($GLOBALS['aPreValues']['Country'][$a['Country']]['LKey'])), |
|---|
| 136 | 'City' => new xmlrpcval($a['City']), |
|---|
| 137 | 'CountPhotos' => new xmlrpcval(BxDolXMLRPCMedia::_getMediaCount('photo', $iId, $iIdViewer)), |
|---|
| 138 | 'CountVideos' => new xmlrpcval(BxDolXMLRPCMedia::_getMediaCount('video', $iId, $iIdViewer)), |
|---|
| 139 | 'CountSounds' => new xmlrpcval(BxDolXMLRPCMedia::_getMediaCount('music', $iId, $iIdViewer)), |
|---|
| 140 | 'CountFriends' => new xmlrpcval(getFriendNumber($a['ID'])), |
|---|
| 141 | $sImageKey => new xmlrpcval($sImage), |
|---|
| 142 | ); |
|---|
| 143 | |
|---|
| 144 | $oZ = new BxDolAlerts('mobile', 'user_info2', $a['ID'], $iIdViewer, array('profile' => &$a, 'return_data' => &$aRet)); |
|---|
| 145 | $oZ->alert(); |
|---|
| 146 | |
|---|
| 147 | return $aRet; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | function getMenu ($sMenu, $aMarkersReplace = array ()) { |
|---|
| 151 | |
|---|
| 152 | $aDefaultMarkers = array ( |
|---|
| 153 | 'site_url' => BX_DOL_URL_ROOT, |
|---|
| 154 | ); |
|---|
| 155 | $aMarkersReplace = array_merge($aDefaultMarkers, $aMarkersReplace); |
|---|
| 156 | $aKeys = array_keys($aMarkersReplace); |
|---|
| 157 | $aValues = array_values($aMarkersReplace); |
|---|
| 158 | foreach ($aKeys as $k => $v) |
|---|
| 159 | $aKeys[$k] = '{' . $v . '}'; |
|---|
| 160 | |
|---|
| 161 | $aMenu = array (); |
|---|
| 162 | $aRecords = $GLOBALS['MySQL']->getAll("SELECT * FROM `sys_menu_mobile` WHERE `page` = '$sMenu' AND `active` = 1 ORDER BY `order`"); |
|---|
| 163 | |
|---|
| 164 | $oZ = new BxDolAlerts('mobile', 'menu', 0, 0, array('menu' => $sMenu, 'data' => &$aRecords, 'markers_replace' => &$aMarkersReplace)); |
|---|
| 165 | $oZ->alert(); |
|---|
| 166 | |
|---|
| 167 | foreach ($aRecords as $r) { |
|---|
| 168 | $a = array (); |
|---|
| 169 | if ($r['eval_hidden']) { |
|---|
| 170 | if ($aMarkersReplace) |
|---|
| 171 | $sVal = str_replace($aKeys, $aValues, $r['eval_hidden']); |
|---|
| 172 | if (@eval($sVal)) |
|---|
| 173 | continue; |
|---|
| 174 | } |
|---|
| 175 | foreach ($r as $sName => $sVal) { |
|---|
| 176 | switch ($sName) { |
|---|
| 177 | case 'eval_hidden': |
|---|
| 178 | break; |
|---|
| 179 | case 'eval_bubble': |
|---|
| 180 | if ($sVal && $aMarkersReplace) |
|---|
| 181 | $sVal = str_replace($aKeys, $aValues, $sVal); |
|---|
| 182 | $a['bubble'] = new xmlrpcval($sVal ? @eval($sVal) : ''); |
|---|
| 183 | break; |
|---|
| 184 | case 'icon': |
|---|
| 185 | case 'action_data': |
|---|
| 186 | if ($sVal && $aMarkersReplace) |
|---|
| 187 | $sVal = str_replace($aKeys, $aValues, $sVal); |
|---|
| 188 | $a[$sName] = new xmlrpcval($sVal); |
|---|
| 189 | break; |
|---|
| 190 | case 'title': |
|---|
| 191 | $a[$sName] = new xmlrpcval(_t($sVal)); |
|---|
| 192 | break; |
|---|
| 193 | default: |
|---|
| 194 | $a[$sName] = new xmlrpcval($sVal); |
|---|
| 195 | } |
|---|
| 196 | } |
|---|
| 197 | $aMenu[] = new xmlrpcval($a, 'struct'); |
|---|
| 198 | } |
|---|
| 199 | return $aMenu; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | function getIdByNickname ($sUser) |
|---|
| 203 | { |
|---|
| 204 | $sUser = process_db_input($sUser, BX_TAGS_NO_ACTION, BX_SLASHES_NO_ACTION); |
|---|
| 205 | return (int)db_value("SELECT `ID` FROM `Profiles` WHERE `NickName` = '$sUser' LIMIT 1"); |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | function checkLogin ($sUser, $sPwd) |
|---|
| 209 | { |
|---|
| 210 | $iId = (int)BxDolXMLRPCUtil::getIdByNickname ($sUser); |
|---|
| 211 | $aProfile = getProfileInfo((int)$iId); |
|---|
| 212 | if (!$aProfile) |
|---|
| 213 | return 0; |
|---|
| 214 | $_COOKIE["memberID" ] = $iId; |
|---|
| 215 | $_COOKIE["memberPassword"] = sha1($sPwd . $aProfile['Salt']); |
|---|
| 216 | $iRet = ($GLOBALS['logged']['member'] = member_auth(0, false)) ? $iId : 0; |
|---|
| 217 | |
|---|
| 218 | $oZ = new BxDolAlerts('mobile', 'check_login', $iId, 0, array('password' => $sPwd, 'return_data' => &$iRet)); |
|---|
| 219 | $oZ->alert(); |
|---|
| 220 | |
|---|
| 221 | return $iRet; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | function setLanguage ($sLang) |
|---|
| 225 | { |
|---|
| 226 | if ('English' == $sLang || !preg_match('/^[a-zA-Z]+$/', $sLang)) |
|---|
| 227 | $sLang = 'en'; |
|---|
| 228 | $_GET['lang'] = $sLang; |
|---|
| 229 | $sCurrentLanguage = getCurrentLangName(); |
|---|
| 230 | global $LANG; |
|---|
| 231 | require_once( BX_DIRECTORY_PATH_ROOT . "langs/lang-{$sCurrentLanguage}.php" ); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | function concat($s1, $s2) |
|---|
| 235 | { |
|---|
| 236 | return new xmlrpcval($s1.$s2); |
|---|
| 237 | } |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | ?> |
|---|