HomeHelpTrac

source: trunk/xmlrpc/BxDolXMLRPCSearch.php @ 15628

Revision 15628, 5.3 KB checked in by Alexander Trofimov, 4 months ago (diff)

Ticket #2680

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