Cheetah
ChWsbXMLRPCUtil.php
Go to the documentation of this file.
1 <?php
2 
9 {
11  {
12  $aRet = array ();
14  return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
15 
16  $aAll = array();
17  $aContacts = array ();
18 
19  // hot list
20  $r = db_res ("SELECT `p`.`ID` FROM `Profiles` AS `p`
21  INNER JOIN `sys_fave_list` AS `h` ON (`h`.`Profile` = `p`.`ID`)
22  WHERE `h`.`ID` = $iId");
23  while ($aRow = $r->fetch())
24  $aAll[$aRow['ID']] = $aRow;
25 
26  // mail contacts received
27  $r = db_res ("SELECT `p`.`ID` FROM `Profiles` AS `p`
28  INNER JOIN `sys_messages` AS `m` ON (`m`.`Sender` = `p`.`ID`)
29  WHERE `p`.`ID` != $iId AND `m`.`Recipient` = $iId");
30  while ($aRow = $r->fetch())
31  $aAll[$aRow['ID']] = $aRow;
32 
33  // mail contacts sent
34  $r = db_res ("SELECT `p`.`ID` FROM `Profiles` AS `p`
35  INNER JOIN `sys_messages` AS `m` ON (`m`.`Recipient` = `p`.`ID`)
36  WHERE `p`.`ID` != $iId AND `m`.`Sender` = $iId");
37  while ($aRow = $r->fetch())
38  $aAll[$aRow['ID']] = $aRow;
39 
40  // friends 1
41  $r = db_res ("SELECT `p`.`ID` FROM `sys_friend_list` AS `fr`
42  LEFT JOIN `Profiles` AS `p` ON (`p`.`ID` = `fr`.`Profile`)
43  WHERE `fr`.`ID` = '$iId' AND `fr`.`Profile` != $iId AND `fr`.`Check` = '1'");
44  while ($aRow = $r->fetch())
45  $aAll[$aRow['ID']] = $aRow;
46 
47  // friends 2
48  $r = db_res ("SELECT `p`.`ID` FROM `sys_friend_list` AS `fr`
49  LEFT JOIN `Profiles` AS `p` ON (`p`.`ID` = `fr`.`ID`)
50  WHERE `fr`.`Profile` = '$iId' AND `fr`.`ID` != $iId AND `fr`.`Check` = '1'");
51  while ($aRow = $r->fetch())
52  $aAll[$aRow['ID']] = $aRow;
53 
54  ch_import('ChWsbAlerts');
55  $oZ = new ChWsbAlerts('mobile', 'contacts', $iId, 0, array('contacts_data' => $aAll));
56  $oZ->alert();
57 
58  foreach ($aAll as $aRow) {
59  $a = array (
60  'ID' => new xmlrpcval($aRow['ID']),
61  'Nick' => new xmlrpcval(getUsername($aRow['ID'])),
62  'UserTitle' => new xmlrpcval(getNickName($aRow['ID'])),
63  );
64  $aContacts[] = new xmlrpcval($a, 'struct');
65  }
66  return new xmlrpcval ($aContacts, "array");
67  }
68 
69  function getCountries($sUser, $sPwd, $sLang)
70  {
71  $aRet = array ();
73  return new xmlrpcresp(new xmlrpcval(array('error' => new xmlrpcval(1,"int")), "struct"));
74 
76 
77  $oProfileFields = new ChWsbProfileFields(0);
78  $aCountriesList = $oProfileFields->convertValues4Input('#!Country');
79 
80  $aCountries = array ();
81  foreach ($aCountriesList as $sCode => &$sName) {
82  $a = array (
83  'Name' => new xmlrpcval($sName),
84  'Code' => new xmlrpcval($sCode),
85  );
86  $aCountries[] = new xmlrpcval($a, 'struct');
87  }
88  return new xmlrpcval ($aCountries, "array");
89  }
90 
91  public static function getThumbLink ($iId, $sType = 'thumb')
92  {
93  $sType = $sType == 'thumb' ? 'medium' : 'small';
94  return $GLOBALS['oFunctions']->getMemberAvatar ((int)$iId, $sType);
95  }
96 
98  {
99  if (!empty($aProfileInfo['Country']) && !empty($aProfileInfo['City']))
100  return _t('_sys_city_country_format', $aProfileInfo['City'], _t($GLOBALS['aPreValues']['Country'][$aProfileInfo['Country']]['LKey']));
101  elseif (!empty($aProfileInfo['Country']))
102  return _t($GLOBALS['aPreValues']['Country'][$aProfileInfo['Country']]['LKey']);
103  else
104  return '';
105  }
106 
107  public static function getUserInfo($iId, $iIdViewer = 0, $isCountData = true)
108  {
109  if (!$iIdViewer)
110  $iIdViewer = (int)$_COOKIE['memberID'];
111 
112  $aRet = array ();
113  $aSexSql = getProfileInfo((int)$iId);
114  $aRet['user_title'] = new xmlrpcval($GLOBALS['oFunctions']->getUserTitle((int)$iId));
115  $aRet['user_info'] = new xmlrpcval($GLOBALS['oFunctions']->getUserInfo((int)$iId) . ' ');
116  $aRet['user_location'] = new xmlrpcval(ChWsbXMLRPCUtil::getUserLocation($aSexSql) . ' ');
117  $aRet['user_friend'] = new xmlrpcval(is_friends((int)$iId, (int)$iIdViewer) ? 1 : 0);
118  $aRet['title'] = new xmlrpcval($GLOBALS['oFunctions']->getUserTitle((int)$iId));
119  $aRet['thumb'] = new xmlrpcval(ChWsbXMLRPCUtil::getThumbLink($iId));
120  $aRet['sex'] = new xmlrpcval($aSexSql['Sex']);
121  $aRet['age'] = new xmlrpcval(age($aSexSql['DateOfBirth']));
122  $aRet['country'] = new xmlrpcval(_t($GLOBALS['aPreValues']['Country'][$aSexSql['Country']]['LKey']));
123  $aRet['city'] = new xmlrpcval($aSexSql['City']);
124  $aRet['status'] = new xmlrpcval($aSexSql['UserStatusMessage']);
125 
126  if ($isCountData) {
127  $aRet['countFriends'] = new xmlrpcval(getFriendNumber($iId));
128  $oChWsbXMLRPCMedia = new ChWsbXMLRPCMedia;
129  $aRet['countPhotos'] = new xmlrpcval($oChWsbXMLRPCMedia->_getMediaCount('photo', $iId, $iIdViewer));
130  $aRet['countVideos'] = new xmlrpcval($oChWsbXMLRPCMedia->_getMediaCount('video', $iId, $iIdViewer));
131  $aRet['countSounds'] = new xmlrpcval($oChWsbXMLRPCMedia->_getMediaCount('music', $iId, $iIdViewer));
132  }
133 
134  ch_import('ChWsbAlerts');
135  $oZ = new ChWsbAlerts('mobile', 'user_info', $iId, $iIdViewer, array('profile' => &$aSexSql, 'return_data' => &$aRet));
136  $oZ->alert();
137 
138  return $aRet;
139  }
140 
141  public static function fillProfileArray ($a, $sImage = 'icon', $iIdViewer = 0)
142  {
143  if (!$iIdViewer)
144  $iIdViewer = (int)$_COOKIE['memberID'];
145 
146  $sImageKey = ucfirst ($sImage);
147  $sImage = ChWsbXMLRPCUtil::getThumbLink($a['ID'], $sImage);
148 
149  ch_import('ChWsbAlbums');
150 
151  $oChWsbXMLRPCMedia = new ChWsbXMLRPCMedia();
152 
153  $aRet = array (
154  'user_title' => new xmlrpcval($GLOBALS['oFunctions']->getUserTitle($a['ID'])),
155  'user_info' => new xmlrpcval($GLOBALS['oFunctions']->getUserInfo($a['ID']) . ' '),
156  'user_location' => new xmlrpcval(ChWsbXMLRPCUtil::getUserLocation($a) . ' '),
157  'user_friend' => new xmlrpcval(is_friends($a['ID'], (int)$iIdViewer) ? 1 : 0),
158  'ID' => new xmlrpcval($a['ID']),
159  'Title' => new xmlrpcval($GLOBALS['oFunctions']->getUserTitle($a['ID'])),
160  'Nick' => new xmlrpcval($a['NickName']),
161  'Sex' => new xmlrpcval($a['Sex']),
162  'Age' => new xmlrpcval(age($a['DateOfBirth'])),
163  'Country' => new xmlrpcval(_t($GLOBALS['aPreValues']['Country'][$a['Country']]['LKey'])),
164  'City' => new xmlrpcval($a['City']),
165  'CountPhotos' => new xmlrpcval($oChWsbXMLRPCMedia->_getMediaCount('photo', $iId, $iIdViewer)),
166  'CountVideos' => new xmlrpcval($oChWsbXMLRPCMedia->_getMediaCount('video', $iId, $iIdViewer)),
167  'CountSounds' => new xmlrpcval($oChWsbXMLRPCMedia->_getMediaCount('music', $iId, $iIdViewer)),
168  'CountFriends' => new xmlrpcval(getFriendNumber($a['ID'])),
169  $sImageKey => new xmlrpcval($sImage),
170  );
171 
172  ch_import('ChWsbAlerts');
173  $oZ = new ChWsbAlerts('mobile', 'user_info2', $a['ID'], $iIdViewer, array('profile' => &$a, 'return_data' => &$aRet));
174  $oZ->alert();
175 
176  return $aRet;
177  }
178 
179  public static function getMenu ($sMenu, $aMarkersReplace = array ())
180  {
181  $aDefaultMarkers = array (
182  'site_url' => CH_WSB_URL_ROOT,
183  'xmlrpc_url' => CH_WSB_URL_ROOT . 'xmlrpc/',
184  );
185  $aMarkersReplace = array_merge($aDefaultMarkers, $aMarkersReplace);
186  $aKeys = array_keys($aMarkersReplace);
187  $aValues = array_values($aMarkersReplace);
188  foreach ($aKeys as $k => $v)
189  $aKeys[$k] = '{' . $v . '}';
190 
191  $aMenu = array ();
192  $aRecords = $GLOBALS['MySQL']->getAll("SELECT * FROM `sys_menu_mobile` WHERE `page` = ? AND `active` = 1 ORDER BY `order`", [$sMenu]);
193 
194  ch_import('ChWsbAlerts');
195  $oZ = new ChWsbAlerts('mobile', 'menu', 0, 0, array('menu' => $sMenu, 'data' => &$aRecords, 'markers_replace' => &$aMarkersReplace));
196  $oZ->alert();
197 
198  foreach ($aRecords as $r) {
199  $a = array ();
200  if ($r['eval_hidden']) {
201  if ($aMarkersReplace)
202  $sVal = str_replace($aKeys, $aValues, $r['eval_hidden']);
203  if (@eval($sVal))
204  continue;
205  }
206  foreach ($r as $sName => $sVal) {
207  switch ($sName) {
208  case 'eval_hidden':
209  break;
210  case 'eval_bubble':
211  if ($sVal && $aMarkersReplace)
212  $sVal = str_replace($aKeys, $aValues, $sVal);
213  $a['bubble'] = new xmlrpcval($sVal ? @eval($sVal) : '');
214  break;
215  case 'icon':
216  case 'action_data':
217  if ($sVal && $aMarkersReplace)
218  $sVal = str_replace($aKeys, $aValues, $sVal);
219  $a[$sName] = new xmlrpcval($sVal);
220  break;
221  case 'title':
222  $a[$sName] = new xmlrpcval(_t($sVal));
223  break;
224  default:
225  $a[$sName] = new xmlrpcval($sVal);
226  }
227  }
228  $aMenu[] = new xmlrpcval($a, 'struct');
229  }
230  return $aMenu;
231  }
232 
233  public static function getIdByNickname ($sUser)
234  {
236  return (int)db_value("SELECT `ID` FROM `Profiles` WHERE `NickName` = '$sUser' LIMIT 1");
237  }
238 
239  public static function checkLogin ($sUser, $sPwd)
240  {
242  $aProfile = getProfileInfo((int)$iId);
243  if (!$aProfile || getParam('enable_cheetah_footer') == 'on')
244  return 0;
245  $_COOKIE["memberID" ] = $iId;
246  $_COOKIE["memberPassword"] = (32 == strlen($sPwd)) ? sha1($sPwd . $aProfile['Salt']) : $sPwd;
247  $iRet = ($GLOBALS['logged']['member'] = member_auth(0, false)) ? $iId : 0;
248 
249  ch_import('ChWsbAlerts');
250  $oZ = new ChWsbAlerts('mobile', 'check_login', $iId, 0, array('password' => $sPwd, 'return_data' => &$iRet));
251  $oZ->alert();
252 
253  return $iRet;
254  }
255 
256  public static function setLanguage ($sLang)
257  {
258  if ('English' == $sLang || !preg_match('/^[a-zA-Z]+$/', $sLang))
259  $sLang = 'en';
260  $_GET['lang'] = $sLang;
261  $sCurrentLanguage = getCurrentLangName();
262  global $LANG;
263  require_once( CH_DIRECTORY_PATH_ROOT . "langs/lang-{$sCurrentLanguage}.php" );
264  }
265 
266  function concat($s1, $s2)
267  {
268  return new xmlrpcval($s1.$s2);
269  }
270 
271  function service ($sModuleUri, $sMethod, $aParams = array(), $sClass = 'Module')
272  {
273  $a = array (
274  'facebook_connect|login' => 1,
275  'facebook_connect|supported' => 1,
276  );
277  if (!isset($a[$sModuleUri . '|' . $sMethod]))
278  return self::_xmlrpcval_auto('');
279  $mixed = ChWsbService::call($sModuleUri, $sMethod, $aParams, $sClass);
280  return self::_xmlrpcval_auto($mixed);
281  }
282 
283  function _xmlrpcval_auto ($mixed) {
284  if (is_array($mixed)) {
285  foreach ($mixed as $k => $v) {
286  if (is_array($v))
287  $mixed[$k] = self::_xmlrpcval_auto($v);
288  else
289  $mixed[$k] = new xmlrpcval($v);
290  }
291  return new xmlrpcval($mixed, 'struct');
292  } else {
293  return new xmlrpcval($mixed);
294  }
295  }
296 }
ChWsbXMLRPCUtil\getContacts
getContacts($sUser, $sPwd)
Definition: ChWsbXMLRPCUtil.php:10
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
ChWsbXMLRPCUtil\getUserInfo
static getUserInfo($iId, $iIdViewer=0, $isCountData=true)
Definition: ChWsbXMLRPCUtil.php:107
ChWsbProfileFields
Definition: ChWsbProfileFields.php:13
getCurrentLangName
if(!defined('CH_SKIP_INSTALL_CHECK')) getCurrentLangName($isSetCookie=true)
Definition: languages.inc.php:36
is_friends
is_friends($id1, $id2)
Definition: utils.inc.php:140
$sCode
$sCode
Definition: explanation.php:19
ChWsbXMLRPCUtil\concat
concat($s1, $s2)
Definition: ChWsbXMLRPCUtil.php:266
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
ChWsbXMLRPCUtil\service
service($sModuleUri, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbXMLRPCUtil.php:271
xmlrpcval
Definition: xmlrpc.inc:2696
php
$oZ
$oZ
Definition: db.php:20
$iId
$iId
Definition: license.php:15
$sPwd
$sPwd
Definition: r.php:14
ChWsbXMLRPCUtil\getIdByNickname
static getIdByNickname($sUser)
Definition: ChWsbXMLRPCUtil.php:233
ChWsbXMLRPCUtil\_xmlrpcval_auto
_xmlrpcval_auto($mixed)
Definition: ChWsbXMLRPCUtil.php:283
CH_SLASHES_NO_ACTION
const CH_SLASHES_NO_ACTION
Definition: utils.inc.php:30
ChWsbAlerts
Definition: ChWsbAlerts.php:39
$sType
$sType
Definition: actions.inc.php:11
$_GET
$_GET['debug']
Definition: index.php:67
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
ChWsbXMLRPCUtil\getUserLocation
getUserLocation($aProfileInfo)
Definition: ChWsbXMLRPCUtil.php:97
$aProfile
$aProfile
Definition: flash.php:14
getNickName
getNickName( $ID='')
Definition: profiles.inc.php:461
CH_TAGS_NO_ACTION
const CH_TAGS_NO_ACTION
Definition: utils.inc.php:21
ChWsbXMLRPCMedia
Definition: ChWsbXMLRPCMedia.php:9
getUsername
getUsername( $ID='')
Definition: profiles.inc.php:443
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
$aMenu
$aMenu
Definition: categories.php:257
age
age( $birth_date)
Definition: profiles.inc.php:119
$aProfileInfo
$aProfileInfo
Definition: short_profile_info.php:23
ChWsbXMLRPCUtil\setLanguage
static setLanguage($sLang)
Definition: ChWsbXMLRPCUtil.php:256
ChWsbXMLRPCUtil
Definition: ChWsbXMLRPCUtil.php:9
db_res
db_res($query, $bindings=[])
Definition: db.inc.php:39
db_value
db_value($query, $bindings=[], $error_checking=true, $index=0)
Definition: db.inc.php:98
ChWsbXMLRPCUtil\fillProfileArray
static fillProfileArray($a, $sImage='icon', $iIdViewer=0)
Definition: ChWsbXMLRPCUtil.php:141
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
xmlrpcresp
Definition: xmlrpc.inc:1911
ChWsbXMLRPCUtil\checkLogin
static checkLogin($sUser, $sPwd)
Definition: ChWsbXMLRPCUtil.php:239
ChWsbXMLRPCUtil\getMenu
static getMenu($sMenu, $aMarkersReplace=array())
Definition: ChWsbXMLRPCUtil.php:179
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbService\call
static call($mixed, $sMethod, $aParams=array(), $sClass='Module')
Definition: ChWsbService.php:32
getFriendNumber
getFriendNumber($iID, $iFrStatus=1, $iOnline=0, $sqlWhere='')
Definition: profiles.inc.php:301
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
ChWsbXMLRPCUtil\getCountries
getCountries($sUser, $sPwd, $sLang)
Definition: ChWsbXMLRPCUtil.php:69
ChWsbXMLRPCUtil\getThumbLink
static getThumbLink($iId, $sType='thumb')
Definition: ChWsbXMLRPCUtil.php:91
$sName
$sName
Definition: ChWsbAdminTools.php:853
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
$LANG
$LANG
Definition: lang-en.php:12
$sUser
$sUser
Definition: r.php:13