BxDolXMLRPCSearch.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. class BxDolXMLRPCSearch
  3. {
  4. function getSearchResultsLocation($sUser, $sPwd, $sLang, $sCountryCode, $sCity, $isOnlineOnly, $isWithPhotosOnly, $iStart, $iPP)
  5. {
  6. if (!($iId = BxDolXMLRPCUtil::checkLogin ($sUser, $sPwd)))
  7. return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
  8. BxDolXMLRPCUtil::setLanguage ($sLang);
  9. $sCountryCode = process_db_input ($sCountryCode, BX_TAGS_NO_ACTION, BX_SLASHES_NO_ACTION);
  10. $sCity = process_db_input ($sCity, BX_TAGS_NO_ACTION, BX_SLASHES_NO_ACTION);
  11. $sWhere = '';
  12. if ($sCountryCode)
  13. $sWhere .= " AND `Country`= '$sCountryCode' ";
  14. if ($sCity)
  15. $sWhere .= " AND `City`LIKE '$sCity' ";
  16. if ($isWithPhotosOnly)
  17. $sWhere .= " AND `Avatar` ";
  18. if ($isOnlineOnly)
  19. {
  20. $iOnlineTime = (int)getParam( 'member_online_time' );
  21. $sWhere .= " AND `DateLastNav` >= DATE_SUB(NOW(), INTERVAL $iOnlineTime MINUTE)";
  22. }
  23. $iStart = (int)$iStart;
  24. if (!$iStart || $iStart < 0)
  25. $iStart = 0;
  26. $iPP = (int)$iPP;
  27. if (!$iPP || $iPP < 1)
  28. $iPP = 1;
  29. $r = db_res ("
  30. SELECT * FROM `Profiles`
  31. WHERE `Status` = 'Active' AND (`Profiles`.`Couple` = 0 OR `Profiles`.`Couple` > `Profiles`.`ID`) $sWhere
  32. ORDER BY `DateLastNav` DESC
  33. LIMIT $iStart, $iPP");
  34. while ($aRow = mysql_fetch_array ($r))
  35. $aProfiles[] = new xmlrpcval(BxDolXMLRPCUtil::fillProfileArray($aRow, 'thumb'), 'struct');
  36. return new xmlrpcval ($aProfiles, "array");
  37. }
  38. function getSearchResultsNearMe($sUser, $sPwd, $sLang, $sLat, $sLng, $isOnlineOnly, $isWithPhotosOnly, $iStart, $iPP)
  39. {
  40. if (!($iId = BxDolXMLRPCUtil::checkLogin ($sUser, $sPwd)))
  41. return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
  42. BxDolXMLRPCUtil::setLanguage ($sLang);
  43. $sLat = (float)$sLat;
  44. $sLng = (float)$sLng;
  45. if ((!$sLat || !$sLng) && BxDolRequest::serviceExists('map_profiles', 'get_location')) {
  46. $aLocation = BxDolService::call('map_profiles', 'get_location', array($iId, 0, false));
  47. if ($aLocation && !empty($aLocation['lat']) && !empty($aLocation['lng'])) {
  48. $sLat = $aLocation['lat'];
  49. $sLng = $aLocation['lng'];
  50. }
  51. }
  52. if (!$sLat || !$sLng)
  53. return new xmlrpcval (array(), "array");
  54. $sWhere = '';
  55. $sJoin = '';
  56. $sLocation = '';
  57. $sDistance = ", (POW($sLat-`loc`.`lat`, 2)+POW($sLng-`loc`.`lng`, 2)) AS `distance`";
  58. $sJoin .= " INNER JOIN `bx_map_profiles` AS `loc` ON (`loc`.`id` = `Profiles`.`ID` AND `loc`.`failed` = 0) ";
  59. if ($isWithPhotosOnly)
  60. $sWhere .= " AND `Avatar` ";
  61. if ($isOnlineOnly)
  62. {
  63. $iOnlineTime = getParam( 'member_online_time' );
  64. $sWhere .= " AND `DateLastNav` >= DATE_SUB(NOW(), INTERVAL $iOnlineTime MINUTE)";
  65. }
  66. $iStart = (int)$iStart;
  67. if (!$iStart || $iStart < 0)
  68. $iStart = 0;
  69. $iPP = (int)$iPP;
  70. if (!$iPP || $iPP < 1)
  71. $iPP = 1;
  72. $r = db_res ("
  73. SELECT * " . $sDistance . " FROM `Profiles`
  74. $sJoin
  75. WHERE `Status` = 'Active' AND (`Profiles`.`Couple` = 0 OR `Profiles`.`Couple` > `Profiles`.`ID`) $sWhere
  76. ORDER BY `distance` ASC
  77. LIMIT $iStart, $iPP");
  78. while ($aRow = mysql_fetch_array ($r))
  79. $aProfiles[] = new xmlrpcval(BxDolXMLRPCUtil::fillProfileArray($aRow, 'thumb'), 'struct');
  80. return new xmlrpcval ($aProfiles, "array");
  81. }
  82. function getSearchResultsKeyword($sUser, $sPwd, $sLang, $sKeyword, $isOnlineOnly, $isWithPhotosOnly, $iStart, $iPP)
  83. {
  84. if (!($iId = BxDolXMLRPCUtil::checkLogin ($sUser, $sPwd)))
  85. return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
  86. BxDolXMLRPCUtil::setLanguage ($sLang);
  87. $sKeyword = process_db_input ($sKeyword, BX_TAGS_NO_ACTION, BX_SLASHES_NO_ACTION);
  88. $sMatch = '';
  89. if ($sKeyword && strlen($sKeyword) > 2)
  90. {
  91. $sMatch .= " MATCH (`NickName`, `City`, `Headline`, `DescriptionMe`, `Tags`) AGAINST ('$sKeyword') ";
  92. $sWhere .= " AND $sMatch ";
  93. }
  94. if ($isWithPhotosOnly)
  95. $sWhere .= " AND `Avatar` ";
  96. if ($isOnlineOnly)
  97. {
  98. $iOnlineTime = getParam( 'member_online_time' );
  99. $sWhere .= " AND `DateLastNav` >= DATE_SUB(NOW(), INTERVAL $iOnlineTime MINUTE)";
  100. }
  101. $iStart = (int)$iStart;
  102. if (!$iStart || $iStart < 0)
  103. $iStart = 0;
  104. $iPP = (int)$iPP;
  105. if (!$iPP || $iPP < 1)
  106. $iPP = 1;
  107. $r = db_res ("
  108. SELECT * " . ( $sMatch ? ", $sMatch" : '') . " FROM `Profiles`
  109. WHERE `Status` = 'Active' AND (`Profiles`.`Couple` = 0 OR `Profiles`.`Couple` > `Profiles`.`ID`) $sWhere
  110. ORDER BY `DateLastNav` DESC
  111. LIMIT $iStart, $iPP");
  112. while ($aRow = mysql_fetch_array ($r))
  113. $aProfiles[] = new xmlrpcval(BxDolXMLRPCUtil::fillProfileArray($aRow, 'thumb'), 'struct');
  114. return new xmlrpcval ($aProfiles, "array");
  115. }
  116. }
  117. ?>