BxDolXMLRPCUtil.php 9.3 KB

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