Cheetah
customFunctions.inc.php
Go to the documentation of this file.
1 <?php
2 
8 require_once(CH_DIRECTORY_PATH_INC . "utils.inc.php");
9 require_once(CH_DIRECTORY_PATH_INC . "membership_levels.inc.php");
10 require_once(CH_DIRECTORY_PATH_CLASSES . "ChWsbInstallerUtils.php");
11 
12 function isModuleAvailable($sModuleName, $sUserId = "", $sAction = "")
13 {
15  if($bResult && !empty($sUserId) && !empty($sAction)) {
16  $aResult = checkAction($sUserId, $sAction);
18  }
19  return $bResult;
20 }
21 
22 function getUserVideoLink()
23 {
25  if(isModuleAvailable("videos"))
26  return $sModulesUrl . "video/videoslink.php?id=#user#";
27  return "";
28 }
29 
30 function getUserMusicLink()
31 {
33  if(isModuleAvailable("sounds"))
34  return $sModulesUrl . "mp3/soundslink.php?id=#user#";
35  return "";
36 }
37 
38 function getUserChatLink($sUserId)
39 {
40  return isModuleAvailable("chat", $sUserId, ACTION_ID_USE_CHAT) ? "#desktopUrl#chat.html?id=#owner#&password=#password#" : "";
41 }
42 
43 function getUserImLink($sUserId)
44 {
45  return isModuleAvailable("messenger", $sUserId, ACTION_ID_USE_MESSENGER) ? "im/sender=#owner#&password=#password#&recipient=#user#/#nick#/10,10,550,500/true" : "";
46 }
47 
48 function getUsersMedia($aUsers)
49 {
50  if(count($aUsers) == 0) return null;
51  $sUsers = "('" . implode("','", $aUsers) . "')";
52  $sSql = "SELECT `users`.`ID`, COUNT(DISTINCT `music`.`ID`) AS `CountMusic`, COUNT(DISTINCT `video`.`ID`) AS `CountVideo` FROM `Profiles` AS `users` LEFT JOIN `" . DB_PREFIX . "Mp3Files` AS `music` ON `users`.`ID`=`music`.`Owner` AND `music`.`Status`='approved' LEFT JOIN `" . DB_PREFIX . "VideoFiles` AS `video` ON `users`.`ID`=`video`.`Owner` AND `video`.`Status`='approved' WHERE `users`.`ID` IN " . $sUsers . " GROUP BY `users`.`ID`";
53  $rResult = getResult($sSql);
54  return $rResult;
55 }
56 
57 function getActiveUsers($sUserId)
58 {
60  require_once(CH_DIRECTORY_PATH_INC . "db.inc.php");
61  $iUpdateInterval = getSettingValue($sModule, "updateInterval");
62  $iMin = (int)getParam("member_online_time");
63  $sOnlineFactor = "`UserStatus`!='" . USER_STATUS_OFFLINE . "' AND `DateLastNav`>SUBDATE(NOW(), INTERVAL " . $iMin . " MINUTE)";
64  $sRetrieveFactor = "`DateLastNav`>SUBDATE(NOW(), INTERVAL " . ($iMin*60 + $iUpdateInterval*3) . " SECOND)";
65  $rResult = getResult("SELECT `ID`, IF(" . $sOnlineFactor . ", 1, 0) AS `Online` FROM `Profiles` WHERE `ID`<>'" . $sUserId . "' AND " . $sRetrieveFactor . " ORDER BY `ID`");
66 
67  $aOnline = array();
68  $aOffline = array();
69  while(($aUser = $rResult->fetch()) != null)
70  if($aUser['Online']) $aOnline[] = $aUser['ID'];
71  else $aOffline[] = $aUser['ID'];
72 
73  return array('online' => $aOnline, 'offline' => $aOffline);
74 }
75 
80 {
81  return (int)getValue("SELECT `ID` FROM `Profiles` WHERE `NickName` = '" . $sNick . "' LIMIT 1");
82 }
83 
85 {
87  return encryptUserPwd($sPassword, $aUser['Salt']);
88 }
89 
90 function login($sId, $sPassword)
91 {
92  $aUrl = parse_url($GLOBALS['site']['url']);
93  $sPath = isset($aUrl['path']) && !empty($aUrl['path']) ? $aUrl['path'] : '/';
94  $sHost = '';
95 
96  setcookie("memberID", $sId, 0, $sPath, $sHost);
97  setcookie("memberPassword", $sPassword, 0, $sPath, $sHost, false, true /* http only */);
99 }
100 
101 function logout($sId)
102 {
103  setcookie("memberID", '', time() - 86400);
104  setcookie("memberPassword", '', time() - 86400);
105  updateOnline($sId, "", false);
106 }
107 
109 {
110  return getValue("SELECT `UserStatus` FROM `Profiles` WHERE `ID`='" . $sId . "'");
111 }
112 
113 function updateOnline($sId = "", $sStatus = "", $bOnline = true)
114 {
115  $sOnlineUpdate = $bOnline ? "NOW()" : "(NOW()-" . ((int)getParam("member_online_time") * 120) . ")";
116  $sStatusUpdate = empty($sStatus) ? "" : ", `UserStatus`='" . $sStatus . "'";
117  getResult("UPDATE `Profiles` SET `DateLastNav`=" . $sOnlineUpdate . $sStatusUpdate . " WHERE `ID`='" . $sId . "'");
118  if(!empty($sStatusUpdate))
120 }
121 
125 function getMails($sId, $sGotMails, $aFullUsers)
126 {
128 
129  $sNotIn = empty($sGotMails) ? "" : " AND `ID` NOT IN(" . $sGotMails . ")";
130  $sQuery = "SELECT `ID`, `Sender`, SUBSTRING(`Text`, 1, 150) AS `Body` FROM `sys_messages` WHERE `Recipient` = '" . $sId . "' AND `New`='1'" . $sNotIn . " AND NOT FIND_IN_SET('recipient', `Trash`)";
131  $rResult = getResult($sQuery);
132 
133  $aMails = array();
134  $aSenders = array();
135  for($i=0; $i<$rResult->rowCount(); $i++) {
136  $aMail = $rResult->fetch();
137  if(!in_array($aMail['Sender'], $aFullUsers)) $aSenders[] = $aMail['Sender'];
138  $aMails[] = $aMail;
139  }
140  $aSenders = array_unique($aSenders);
141 
142  $aMediaUsers = array();
143  $rMedia = getUsersMedia($aSenders);
144  if($rMedia != null) {
145  for($i=0; $i<$rMedia->rowCount(); $i++) {
146  $aUser = $rMedia->fetch();
147  $sUserId = $aUser['ID'];
148  $aMediaUsers[$sUserId] = getUserInfo($sUserId);
149  $aMediaUsers[$sUserId]['music'] = $aUser['CountMusic'] > 0 ? TRUE_VAL : FALSE_VAL;
150  $aMediaUsers[$sUserId]['video'] = $aUser['CountVideo'] > 0 ? TRUE_VAL : FALSE_VAL;
151  }
152  }
153 
154  $sResult = "";
155  for($i=0; $i<count($aMails); $i++) {
156  $sSenderId = $aMails[$i]['Sender'];
157  $aMails[$i]['Body'] = strip_tags($aMails[$i]['Body']);
158  if(is_array($aMediaUsers[$sSenderId])) {
159  $aUser = $aMediaUsers[$sSenderId];
160  $sResult .= parseXml($aXmlTemplates["message"], $aMails[$i]['ID'], $sSenderId, $aMails[$i]['Body'], $aUser['nick'], $aUser['sex'], $aUser['age'], $aUser['photo'], $aUser['profile'], $aUser['music'], $aUser['video']);
161  } else $sResult .= parseXml($aXmlTemplates["message"], $aMails[$i]['ID'], $sSenderId, $aMails[$i]['Body']);
162  }
163  return makeGroup($sResult, "mails");
164 }
165 
166 function getIms($sId)
167 {
169 
170  $rResult = getResult("SELECT * FROM `" . DB_PREFIX ."ImPendings` WHERE `RecipientID`='" . $sId . "' ORDER BY `ID` DESC");
171  $sResult = "";
172  for($i=0; $i<$rResult->rowCount(); $i++) {
173  $aIm = $rResult->fetch();
174  $sResult .= parseXml($aXmlTemplates["message"], $aIm['ID'], $aIm['SenderID'], $aIm['Message']);
175  }
176  return makeGroup($sResult, "ims");
177 }
178 
179 function declineIm($sId)
180 {
181  getResult("DELETE FROM `" . DB_PREFIX . "ImPendings` WHERE `ID`='" . $sId . "'");
182 }
183 
184 require_once(CH_DIRECTORY_PATH_INC . "languages.inc.php");
185 require_once(CH_DIRECTORY_PATH_INC . "design.inc.php");
186 require_once(CH_DIRECTORY_PATH_CLASSES . "ChWsbUserStatusView.php");
187 
189 {
191  $oStatuses = new ChWsbUserStatusView();
192  $sContents = "";
193  foreach($oStatuses->aStatuses as $sKey => $aStatus)
194  $sContents .= parseXml($aXmlTemplates["status"], $sKey, getTemplateIcon($aStatus["icon"]), _t($aStatus["title"]));
195  return makeGroup($sContents, "statuses");
196 }
getUserImLink
getUserImLink($sUserId)
Definition: customFunctions.inc.php:43
getUserChatLink
getUserChatLink($sUserId)
Definition: customFunctions.inc.php:38
encryptPassword
encryptPassword($sId, $sPassword)
Definition: customFunctions.inc.php:84
$sRootURL
$sRootURL
Definition: header.inc.php:38
CHECK_ACTION_RESULT_ALLOWED
const CHECK_ACTION_RESULT_ALLOWED
Definition: membership_levels.inc.php:60
$sResult
$sResult
Definition: advanced_settings.php:26
getActiveUsers
getActiveUsers($sUserId)
Definition: customFunctions.inc.php:57
login
login($sId, $sPassword)
Definition: customFunctions.inc.php:90
$aResult
$aResult
Definition: index.php:19
getUserVideoLink
getUserVideoLink()
Definition: customFunctions.inc.php:48
$sModulesUrl
$sModulesUrl
Definition: header.inc.php:52
CHECK_ACTION_RESULT
const CHECK_ACTION_RESULT
Definition: membership_levels.inc.php:54
php
getValue
getValue($sQuery)
Definition: db.inc.php:59
$sModule
if(!file_exists($sRayHeaderPath)) $sModule
Definition: index.php:14
getIms
getIms($sId)
Definition: customFunctions.inc.php:166
getAvailableStatuses
getAvailableStatuses()
Definition: customFunctions.inc.php:188
isModuleAvailable
isModuleAvailable($sModuleName, $sUserId="", $sAction="")
Definition: customFunctions.inc.php:12
getIdByNick
getIdByNick($sNick)
Definition: customFunctions.inc.php:79
updateOnline
updateOnline($sId="", $sStatus="", $bOnline=true)
Definition: customFunctions.inc.php:113
$sPassword
$sPassword
Definition: actions.inc.php:10
getUserInfo
getUserInfo($sId, $bNick=false)
Definition: customFunctions.inc.php:61
createUserDataFile
createUserDataFile( $userID)
Definition: profiles.inc.php:192
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
getMails
getMails($sId, $sGotMails, $aFullUsers)
Definition: customFunctions.inc.php:125
getTemplateIcon
getTemplateIcon($sFileName)
Definition: design.inc.php:193
ChWsbUserStatusView
Definition: ChWsbUserStatusView.php:9
getUserStatus
getUserStatus($sId)
Definition: customFunctions.inc.php:108
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
$bResult
$bResult
Definition: get_file.php:11
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
getUserMusicLink
getUserMusicLink()
Definition: customFunctions.inc.php:56
checkAction
checkAction($iMemberId, $actionID, $performAction=false, $iForcedProfID=0, $isCheckMemberStatus=true)
Definition: membership_levels.inc.php:313
parseXml
parseXml($aXmlTemplates)
Definition: apiFunctions.inc.php:15
makeGroup
makeGroup($sXmlContent, $sXmlGroup="ray")
Definition: apiFunctions.inc.php:32
$aUser
$aUser
Definition: profiles.inc.php:74
$aXmlTemplates
$aXmlTemplates
Definition: xmlTemplates.inc.php:8
$sId
$sId
Definition: actions.inc.php:8
getProfileInfo
getProfileInfo($iProfileID=0, $checkActiveStatus=false, $forceCache=false)
Definition: profiles.inc.php:249
declineIm
declineIm($sId)
Definition: customFunctions.inc.php:179
getSettingValue
getSettingValue($sWidget, $sSettingKey, $sFile="config", $bFullReturn=false, $sFolder="xml")
Definition: apiFunctions.inc.php:82
encryptUserPwd
encryptUserPwd($sPwd, $sSalt)
Definition: utils.inc.php:1643
$sContents
$sContents
Definition: XML.php:38
$sAction
$sAction
Definition: categories.php:274
$sNick
$sNick
Definition: actions.inc.php:9
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
ChWsbInstallerUtils\isModuleInstalled
static isModuleInstalled($sUri)
Definition: ChWsbInstallerUtils.php:38
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
logout
logout($sId)
Definition: customFunctions.inc.php:101
$sStatus
$sStatus
Definition: actions.inc.php:11
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
getUsersMedia
getUsersMedia($aUsers)
Definition: customFunctions.inc.php:48
getResult
getResult($sQuery)
Definition: db.inc.php:45