function getOnlineUsersInfo($sUserId, $bInit) { global $aXmlTemplates; $aSaved = getSavedUsers(); $aActive = getActiveUsers($sUserId); $aFriends = getFriends($sUserId); saveUsers($aActive); $sContents = ""; if ($bInit) { $aFullUsers = array_unique(array_merge($aActive['online'], $aFriends)); } else { $aFullUsers = array_diff($aActive['online'], $aSaved['online'], $aFriends); $aNewOfflineUsers = array_intersect($aSaved['online'], $aActive['offline']); $aNewOnlineUsers = array_intersect($aSaved['offline'], $aActive['online'], $aFriends); for ($i = 0; $i < count($aNewOfflineUsers); $i++) { $sContents .= parseXml($aXmlTemplates['user'], $aNewOfflineUsers[$i], FALSE_VAL); } for ($i = 0; $i < count($aNewOnlineUsers); $i++) { $sContents .= parseXml($aXmlTemplates['user'], $aNewOnlineUsers[$i], TRUE_VAL); } } $rResult = getUsersMedia($aFullUsers); if ($rResult != null) { for ($i = 0; $i < mysql_num_rows($rResult); $i++) { $aUser = mysql_fetch_assoc($rResult); $aUserInfo = getUserInfo($aUser['ID']); $sOnline = in_array($aUser['ID'], $aActive['online']) ? TRUE_VAL : FALSE_VAL; $sFriend = in_array($aUser['ID'], $aFriends) ? TRUE_VAL : FALSE_VAL; $sMusic = $aUser['CountMusic'] > 0 ? TRUE_VAL : FALSE_VAL; $sVideo = $aUser['CountVideo'] > 0 ? TRUE_VAL : FALSE_VAL; $sContents .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUserInfo['nick'], $aUserInfo['sex'], $aUserInfo['age'], $aUserInfo['photo'], $aUserInfo['profile'], $sOnline, $sFriend, $sMusic, $sVideo); } } return makeGroup($sContents, "users"); }
function getSavedBoardInfo($sId, $iBoardId) { global $aXmlTemplates; $aBoard = BxDolService::call('photos', 'get_photo_array', array($iBoardId, 'original'), 'Search'); if (count($aBoard) == 0 || $sId != $aBoard["owner"]) { $sResult = parseXml($aXmlTemplates["result"], "msgSavedError", FAILED_VAL); } else { $sResult = parseXml($aXmlTemplates["result"], $iBoardId, SUCCESS_VAL); $sResult .= parseXml($aXmlTemplates["savedBoard"], $aBoard["file"], $aBoard["title"]); } return $sResult; }
function parseXml($node) { $data = array(); foreach ($node->children() as $child) { if (count($child->children()) == 0) { if (is_numeric((string) $child)) { $data[$child->getName()] = (int) $child; } else { $data[$child->getName()] = (string) $child; } } else { $data[$child->getName()] = parseXml($child); } } return $data; }
function video_getList($sId) { global $sModule; global $aXmlTemplates; global $sFilesPath; $sMode = getSettingValue($sModule, "listSource"); $iCount = (int) getSettingValue($sModule, "listCount"); if (!is_numeric($iCount) || $iCount <= 0) { $iCount = 10; } $oSource = new BxVideosSearch(); $oSource->aCurrent['sorting'] = 'top'; $oSource->aCurrent['paginate']['perPage'] = $iCount; $oSource->aCurrent['restriction']['id'] = array('value' => $sId, 'field' => 'ID', 'operator' => '<>'); switch ($sMode) { case "Member": $sOwner = getValue("SELECT `Owner` FROM `" . MODULE_DB_PREFIX . "Files` WHERE `ID` = '" . $sId . "'"); $oSource->aCurrent['restriction']['owner'] = array('value' => $sOwner, 'field' => 'Owner', 'operator' => '='); break; case "Related": $aFile = getArray("SELECT * FROM `" . MODULE_DB_PREFIX . "Files` WHERE `ID` = '" . $sId . "'"); $oSource->aCurrent['restriction']['keyword'] = array('value' => $aFile['Title'] . " " . $aFile['Tags'] . " " . $aFile['Description'], 'field' => '', 'operator' => 'against'); break; case "Top": default: $oSource->aCurrent['restriction']['id'] = array('value' => $sId, 'field' => 'ID', 'operator' => '<>'); break; } $aData = $oSource->getSearchData(); $iCurrentTime = time(); $sResult = ""; for ($i = 0; $i < count($aData); $i++) { $aData[$i]['uri'] = $oSource->getCurrentUrl('file', $aData[$i]['id'], $aData[$i]['uri']); $aData[$i]['date'] = _format_when($iCurrentTime - $aData[$i]['date']); $sImageFile = $aData[$i]['id'] . IMAGE_EXTENSION; $sThumbFile = $aData[$i]['id'] . THUMB_FILE_NAME . IMAGE_EXTENSION; if (!file_exists($sFilesPath . $sThumbFile)) { $sThumbFile = $sImageFile; } $sResult .= parseXml($aXmlTemplates['file'], $sThumbFile, $aData[$i]['size'], $aData[$i]['ownerName'], $aData[$i]['view'], $aData[$i]['voting_rate'], $aData[$i]['date'], $aData[$i]['title'], BX_DOL_URL_ROOT . $aData[$i]['uri']); } return $sResult; }
/** * get extra files for module in XML format * @param $sModule - module name * @param $sFolder - folder name for which value is set * @param $bGetDate - get dates of files * @return $sContents - XML formatted result */ function printFiles($sModule, $sFolder = "langs", $bGetDate = false, $bGetNames = false) { global $sIncPath; global $sModulesUrl; require_once $sIncPath . "xmlTemplates.inc.php"; $aFileContents = getFileContents($sModule, "/xml/" . $sFolder . ".xml", true); $aFiles = $aFileContents['contents']; $aEnabledFiles = array(); foreach ($aFiles as $sFile => $sEnabled) { if ($sEnabled == TRUE_VAL) { $aEnabledFiles[] = $sFile; } } $sDefault = $aFiles['_default_']; $aResult = getExtraFiles($sModule, $sFolder, true, $bGetDate); $sCurrent = $aResult['current']; $sCurrent = in_array($sCurrent, $aEnabledFiles) ? $sCurrent : $sDefault; $sCurrentFile = $sCurrent . "." . $aResult['extension']; $aRealFiles = array_flip($aResult['files']); $aFileDates = $aResult['dates']; $sContents = ""; for ($i = 0; $i < count($aEnabledFiles); $i++) { if (isset($aRealFiles[$aEnabledFiles[$i]])) { $sFile = $aEnabledFiles[$i]; if ($bGetDate) { $sContents .= parseXml($aXmlTemplates['file'], $sFile, $aFileDates[$aRealFiles[$sFile]]); } else { if ($bGetNames) { $sName = $sFolder == "langs" ? getSettingValue($sModule, "_name_", $sFile, false, "langs") : getSettingValue($sModule, $sFile, "skinsNames"); if (empty($sName)) { $sName = $sFile; } $sContents .= parseXml($aXmlTemplates['file'], $sFile, $sName, ""); } else { $sContents .= parseXml($aXmlTemplates['file'], $sFile); } } } } $sContents = makeGroup($sContents, "files"); $sContents .= parseXml($aXmlTemplates['current'], $sCurrent, $sModulesUrl . $sModule . "/" . $sFolder . "/" . $sCurrentFile); return $sContents; }
/** * ===> The rest of functions is for XML version only. <=== * Update user's status * @comment - Refreshed */ function refreshUsersInfo($iId = 0, $sMode = 'all') { global $aXmlTemplates; global $sModule; $iUpdateInterval = (int) getSettingValue($sModule, "updateInterval"); $iIdleTime = (int) getSettingValue($sModule, "idleTime"); $iDeleteTime = (int) getSettingValue($sModule, "deleteTime"); //--- refresh current user's track ---// $sQuery = "UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `Status`='" . USER_STATUS_OLD . "', `When`=UNIX_TIMESTAMP() WHERE `Status`<>'" . USER_STATUS_KICK . "' AND IF(`Status` IN ('" . USER_STATUS_NEW . "', '" . USER_STATUS_TYPE . "', '" . USER_STATUS_ROOM . "') AND `When`>=(UNIX_TIMESTAMP()-" . $iUpdateInterval . "), `ID`='-1', `ID`='" . $iId . "')"; getResult($sQuery); //--- refresh other users' states ---// $sQuery = "UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `When`=UNIX_TIMESTAMP(), `Status`='" . USER_STATUS_IDLE . "' WHERE `Status`<>'" . USER_STATUS_IDLE . "' AND `When`<=(UNIX_TIMESTAMP()-" . $iIdleTime . ")"; getResult($sQuery); //--- delete idle users, whose track was not refreshed more than delete time ---// $sQuery = "DELETE FROM `" . MODULE_DB_PREFIX . "CurrentUsers` WHERE `Status`='" . USER_STATUS_IDLE . "' AND `When`<=(UNIX_TIMESTAMP()-" . $iDeleteTime . ")"; getResult($sQuery); //--- delete old rooms ---// $sQuery = "DELETE FROM `" . MODULE_DB_PREFIX . "Rooms` WHERE `Status`='" . ROOM_STATUS_DELETE . "' AND `When`<=(UNIX_TIMESTAMP()-" . $iDeleteTime . ")"; getResult($sQuery); //--- delete old messages ---// $sQuery = "DELETE FROM `" . MODULE_DB_PREFIX . "Messages` WHERE `When`<=(UNIX_TIMESTAMP()-" . $iDeleteTime . ")"; getResult($sQuery); //--- Get information about users in the chat ---// switch ($sMode) { case 'upd': $rRes = getResult("SELECT ccu.`ID` AS `ID`, ccu.`Nick` AS `Nick`, ccu.`Sex` AS `Sex`, ccu.`Age` AS `Age`, ccu.`Desc` AS `Desc`, ccu.`Photo` AS `Photo`, ccu.`Profile` AS `Profile`, ccu.`Status` AS `Status`, ccu.`RoomID` AS `RoomID`, rp.`Type` AS `Type` FROM `" . MODULE_DB_PREFIX . "Profiles` AS rp, `" . MODULE_DB_PREFIX . "CurrentUsers` AS ccu WHERE rp.`ID`=ccu.`ID` ORDER BY ccu.`When`"); while ($aUser = mysql_fetch_assoc($rRes)) { if ($aUser['ID'] == $iId && !($aUser['Status'] == USER_STATUS_KICK || $aUser['Status'] == USER_STATUS_TYPE)) { continue; } switch ($aUser['Status']) { case USER_STATUS_NEW: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status'], $aUser['Nick'], $aUser['Sex'], $aUser['Age'], $aUser['Desc'], $aUser['Photo'], $aUser['Profile'], $aUser['Type'], $aUser['RoomID']); break; case USER_STATUS_ROOM: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status'], $aUser['RoomID']); break; case USER_STATUS_TYPE: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status'], $aUser['RoomID'], $aUser['Type']); break; case USER_STATUS_IDLE: case USER_STATUS_KICK: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status']); break; } } break; case 'all': $rRes = getResult("SELECT ccu.`ID` AS `ID`, ccu.`Nick` AS `Nick`, ccu.`Sex` AS `Sex`, ccu.`Age` AS `Age`, ccu.`Desc` AS `Desc`, ccu.`Photo` AS `Photo`, ccu.`Profile` AS `Profile`, ccu.`RoomID` AS `RoomID`, rp.`Type` AS `Type` FROM `" . MODULE_DB_PREFIX . "Profiles` AS rp, `" . MODULE_DB_PREFIX . "CurrentUsers` AS ccu WHERE rp.`ID`=ccu.`ID` AND ccu.`Status` NOT IN ('" . USER_STATUS_IDLE . "', '" . USER_STATUS_KICK . "') AND rp.`Banned`='false' ORDER BY ccu.`When`"); while ($aUser = mysql_fetch_assoc($rRes)) { $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], "new", $aUser['Nick'], $aUser['Sex'], $aUser['Age'], $aUser['Desc'], $aUser['Photo'], $aUser['Profile'], $aUser['Type'], $aUser['RoomID']); } break; } return makeGroup($sContent, "users"); }
$res = getResult($sQuery); getResult($sQuery1); $bResult = true; for ($i = 0; $i < mysql_num_rows($res); $i++) { $aFile = mysql_fetch_assoc($res); $bResult = deleteFile($aFile["ID"]); } if ($bResult) { $sContents = parseXml($aXmlTemplates['result'], "", SUCCESS_VAL); } break; /** * add files to playlist */ /** * add files to playlist */ case 'addFilesToPlayList': $aFiles = explode(",", $sFile); $iFilesCount = count($aFiles); if ($iFilesCount == 0) { $sContents = parseXml($aXmlTemplates['result'], FALSE_VAL); break; } getResult("UPDATE `" . MODULE_DB_PREFIX . "PlayLists` SET `Order`=`Order`+" . $iFilesCount . " WHERE `Owner` = '" . $sId . "'"); for ($i = 0; $i < $iFilesCount; $i++) { getResult("INSERT INTO `" . MODULE_DB_PREFIX . "PlayLists` VALUES('" . $aFiles[$i] . "', '" . $sId . "', '" . ($i + 1) . "')"); } $sContents = parseXml($aXmlTemplates['result'], TRUE_VAL); break; }
move_uploaded_file($_FILES['Filedata']['tmp_name'], $sFilePath); @chmod($sFilePath, 0644); } break; case 'initFile': $sFilePath = $sFilesPath . $sSender . ".temp"; $sContents = parseXml($aXmlTemplates['result'], "msgErrorUpload", FAILED_VAL); if (empty($sSender) || !file_exists($sFilePath) || filesize($sFilePath) == 0) { break; } getResult("INSERT INTO `" . MODULE_DB_PREFIX . "Messages`(`Sender`, `Recipient`, `Message`, `Type`, `When`) VALUES('" . $sSender . "', '" . $sRcp . "', '" . $sMessage . "', 'file', '" . time() . "')"); $sFileName = getLastInsertId() . ".file"; if (!@rename($sFilePath, $sFilesPath . $sFileName)) { break; } $sContents = parseXml($aXmlTemplates['result'], $sFileName, SUCCESS_VAL); break; case 'removeFile': $sId = str_replace(".file", "", $sId); removeFile($sId); break; case 'help': $sApp = isset($_REQUEST['app']) ? $_REQUEST['app'] : "user"; $sContents = makeGroup("", "topics"); $sFileName = $sModulesPath . $sModule . "/help/" . $sApp . ".xml"; if (file_exists($sFileName)) { $rHandle = @fopen($sFileName, "rt"); $sContents = @fread($rHandle, filesize($sFileName)); fclose($rHandle); } break;
case 'adminAuthorize': $sContents .= parseXml($aXmlTemplates['result'], loginAdmin($sNick, $sPassword)); break; /** * Search user by ID or by Nick. */ /** * Search user by ID or by Nick. */ case 'searchUser': $sId = searchUser($sParamValue, $sParamName); //--- if such user exists, than print his info ---// if (!empty($sId)) { $sContents = parseXml($aXmlTemplates['result'], $sId, SUCCESS_VAL); } else { $sContents = parseXml($aXmlTemplates['result'], "User not found", FAILED_VAL); } break; case 'stat': $iApproved = isset($_REQUEST['approved']) ? $_REQUEST['approved'] : 0; $iPending = isset($_REQUEST['pending']) ? $_REQUEST['pending'] : 0; getResult("UPDATE `" . MODULE_DB_PREFIX . "Stats` SET `Approved`='" . $iApproved . "', `Pending`='" . $iPending . "' WHERE `User`='' LIMIT 1"); break; case 'userStat': $aApproved = isset($_REQUEST['approved']) ? explode(",", $_REQUEST['approved']) : array(); $aPending = isset($_REQUEST['pending']) ? explode(",", $_REQUEST['pending']) : array(); $aUsers = empty($sUserId) ? array() : explode(",", $sUserId); for ($i = 0; $i < count($aUsers); $i++) { if (empty($aUsers[$i])) { continue; }
/** * creates widget's main config file * @param sWidget - the name of the widget. */ function createMainFile($sWidget) { global $sModulesPath; global $aXmlTemplates; global $aErrorCodes; $bResult = false; if (secureCheckWidgetName($sWidget)) { require $sModulesPath . $sWidget . "/inc/constants.inc.php"; $sCode = $aInfo['code']; $sContents = parseXml($aXmlTemplates["item"], "status", WIDGET_STATUS_NOT_REGISTERED); $sContents .= parseXml($aXmlTemplates["item"], "license", ""); $sContents .= parseXml($aXmlTemplates["item"], "code", $sCode); $sContents .= parseXml($aXmlTemplates["item"], "updated", TRUE_VAL); $sContents .= parseXml($aXmlTemplates["item"], "updateLast", ""); $sContents .= parseXml($aXmlTemplates["item"], "updateUrl", ""); $sContents = makeGroup($sContents, "items"); //--- Save changes to the file---// $sFile = $sWidget . "/xml/main.xml"; $sFileName = $sModulesPath . $sFile; if (($rHandle = @fopen($sFileName, "wt")) !== false) { $bResult = fwrite($rHandle, $sContents) !== false; fclose($rHandle); } $bResult = $bResult && $rHandle; $sValue = $bResult ? "" : getError($aErrorCodes[2], $sFile); } else { $sValue = $aErrorCodes[8]; } return array('value' => $sValue, 'status' => $bResult ? SUCCESS_VAL : FAILED_VAL); }
function getCalendarDataAsXmlFromXml($xml) { /* <calendar> * <id>1658</id> * <startdate>0</startdate> * <enddate>1440</enddate> * <calendar> */ $a = parseXml($xml)[0]; $boundsexists = isset($a->startdate) && isset($a->enddate); if ($boundsexists) { return getCalendarDataAsXml($a->id, $a->startdate, $a->enddate); } else { return getCalendarDataAsXml($a->id, null, null); } }
} } $sContents = parseXml($aXmlTemplates['result'], SUCCESS_VAL, $sCode, $aContents['license']); } else { $sContents = parseXml($aXmlTemplates['result'], $aResult['value'], FAILED_VAL); } break; /** * Gets widget status and ads banner if it's paid */ /** * Gets widget status and ads banner if it's paid */ case 'getWidgetAds': $sFooter = getParam("enable_dolphin_footer"); $bPaid = empty($sFooter); $sEnabled = $bPaid ? TRUE_VAL : FALSE_VAL; if ($bPaid) { $sBannerUrl = getSettingValue(GLOBAL_MODULE, "bannerUrl"); $sBannerLink = getSettingValue(GLOBAL_MODULE, "bannerLink"); $sBannerTarget = getSettingValue(GLOBAL_MODULE, "bannerTarget"); $iBannerAlpha = getSettingValue(GLOBAL_MODULE, "bannerAlpha"); if (!is_numeric($iBannerAlpha) || $iBannerAlpha < 0 || $iBannerAlpha > 100) { $iBannerAlpha = 100; } $sContents = parseXml($aXmlTemplates['ads'], $sEnabled, $sBannerUrl, $sBannerLink, $sBannerTarget, $iBannerAlpha); } else { $sContents = parseXml($aXmlTemplates['ads'], $sEnabled); } break; }
break; /** * Gets widget code. */ /** * Gets widget code. */ case 'getWidgetCode': $aResult = getFileContents($sWidget, "/xml/main.xml", true); if ($aResult['status'] == SUCCESS_VAL) { $aContents = $aResult['contents']; $sCode = $aContents['code']; if (empty($sCode)) { require_once $sModulesPath . $sWidget . "/inc/constants.inc.php"; $sCode = $aInfo['code']; } $sContents = parseXml($aXmlTemplates['result'], SUCCESS_VAL, $sCode, $aContents['license']); } else { $sContents = parseXml($aXmlTemplates['result'], $aResult['value'], FAILED_VAL); } break; /** * update user's online status */ /** * update user's online status */ case 'updateOnlineStatus': updateOnline($sId); break; }
function processDataFromMoysklad($userDate) { $orderUrl = "CustomerOrder"; $goodUrl = "Good"; $serviceUrl = "Service"; $courierUrl = "Employee"; $warehouseUrl = "Warehouse"; // Getting data from Moysklad $courierData = getXmlFromMoysklad($courierUrl, ""); $goodData = getXmlFromMoysklad($goodUrl, ""); $serviceData = getXmlFromMoysklad($serviceUrl, ""); $warehouseData = getXmlFromMoysklad($warehouseUrl, ""); $date = new DateTime($userDate, new DateTimeZone("Europe/Moscow")); $filterTimeTomorrow = (int) $date->format("Ymd"); $date = new DateTime($userDate . "+1 day", new DateTimeZone("Europe/Moscow")); $filterTimeAfterTomorrow = (int) $date->format("Ymd"); $filterOrderString = urlencode("deliveryPlannedMoment>" . $filterTimeTomorrow . "040000;" . "deliveryPlannedMoment<" . $filterTimeAfterTomorrow . "040000"); $orderData = getXmlFromMoysklad($orderUrl, "?filter=" . $filterOrderString); // Parsing XML try { $goodXml = new SimpleXmlElement($goodData); } catch (Exception $e) { echo "Возникла ошибка при загрузке данных о товарах с Moysklad. Пожалуйста, попробуйте еще раз."; return; } $goodArray = parseXml($goodXml, "good"); $GLOBALS["goodArray"] = $goodArray; try { $serviceXml = new SimpleXmlElement($serviceData); } catch (Exception $e) { echo "Возникла ошибка при загрузке данных об услугах с Moysklad. Пожалуйста, попробуйте еще раз."; return; } $serviceArray = parseXml($serviceXml, "service"); $GLOBALS["serviceArray"] = $serviceArray; try { $orderXml = new SimpleXmlElement($orderData); } catch (Exception $e) { echo "Возникла ошибка при загрузке данных о заказах покупателей с Moysklad. Пожалуйста, попробуйте еще раз."; return; } $orderArray = parseXml($orderXml, "customerOrder"); $GLOBALS["orderArray"] = $orderArray; try { $warehouseXml = new SimpleXMLElement($warehouseData); } catch (Exception $e) { echo "Возникла ошибка при загрузке данных о складах с Moysklad. Пожалуйста, попробуйте еще раз."; return; } $warehouseArray = parseXml($warehouseXml, "warehouse"); $GLOBALS["warehouseArray"] = $warehouseArray; try { $courierXml = new SimpleXmlElement($courierData); } catch (Exception $e) { echo "Возникла ошибка при загрузке данных по курьерам с Moysklad. Пожалуйста, попробуйте еще раз."; return; } $courierArray = parseXml($courierXml, "courier"); $GLOBALS["courierArray"] = $courierArray; }
* Update online user's information. * @param online - currently online users, whose info was got earlier. */ case "updateOnlineUsers": $aCurDbOnline = getOnline(); $aCurProgOnline = empty($_REQUEST['online']) ? array() : explode(",", $_REQUEST['online']); //--- Get new online users ---// $aNewOnline = array_diff($aCurDbOnline, $aCurProgOnline); foreach ($aNewOnline as $iNewOnline) { $aUserInfo = getUserInfo($iNewOnline); $sContents .= parseXml($aXmlTemplates['user'], $iNewOnline, $aUserInfo['nick'], $aUserInfo['sex'], $aUserInfo['age'], TRUE_VAL, $aUserInfo['photo'], $aUserInfo['profile']); } //--- Get new offline users ---// $aNewOffline = array_diff($aCurProgOnline, $aCurDbOnline); foreach ($aNewOffline as $iNewOffline) { $sContents .= parseXml($aXmlTemplates['user'], $iNewOffline, FALSE_VAL); } $sContents = makeGroup($sContents, "users"); break; /** * Updates user's information in RayPresenceUsers table. * For Users, who didn't login into Ray Presence, but logged in into site. * @param id - user's ID. * @param status - user's status. */ /** * Updates user's information in RayPresenceUsers table. * For Users, who didn't login into Ray Presence, but logged in into site. * @param id - user's ID. * @param status - user's status. */
$iCount = getValue("SELECT COUNT(`ID`) FROM `" . MODULE_DB_PREFIX . "Messages`"); if ($iCount > $iMaxCount) { getResult("DELETE FROM `" . MODULE_DB_PREFIX . "Messages` ORDER BY `ID` LIMIT " . ($iCount - $iMaxCount)); } $sIn = empty($sGot) ? "1" : "`ID` NOT IN (" . $sGot . ")"; $sUserFactor = empty($sId) ? "" : " AND `UserID`<>'" . $sId . "'"; $sSql = "SELECT * FROM `" . MODULE_DB_PREFIX . "Messages` WHERE " . $sIn . $sUserFactor . " AND `When`>=(UNIX_TIMESTAMP()-" . $iUpdateInterval . ") ORDER BY `ID`"; //break shouldn't be here //break shouldn't be here case 'getMessages': $sContents = ""; if (!isset($sSql)) { $sSql = "SELECT * FROM `" . MODULE_DB_PREFIX . "Messages` ORDER BY `ID`"; } $rResult = getResult($sSql); while ($aMsg = mysql_fetch_assoc($rResult)) { $aUserInfo = empty($aMsg['UserID']) ? array('nick' => "", 'profile' => "") : getUserInfo($aMsg['UserID']); $sContents .= parseXml($aXmlTemplates['message'], $aMsg['ID'], stripslashes($aMsg['Msg']), $aUserInfo['nick'], $aUserInfo['profile']); } $sContents = makeGroup($sContents, "messages"); break; /** * Add message to database. */ /** * Add message to database. */ case 'newMessage': getResult("INSERT INTO `" . MODULE_DB_PREFIX . "Messages`(`UserID`, `Msg`, `When`) VALUES('" . $sId . "', '" . addslashes($sMsg) . "', UNIX_TIMESTAMP())"); break; }
case "page": newPage($name, $extension); break; case "component": newComponent($name, $extension); break; default: printHelp(); exit(0); } break; case "parse": checkForArgument($argv, 2); $file = $argv[2]; $structure = new SimpleXMLElement(file_get_contents($file)); parseXml($file, $structure); break; default: printHelp(); exit(0); } function checkForArgument($inArgv, $inIndex) { if (!array_key_exists($inIndex, $inArgv)) { printHelp(); exit(0); } } function printHelp() { print "Usage:\n";
for ($i = 0; $i < count($aData); $i++) { $aPixel = explode("=", $aData[$i], 2); $aImageData[$aPixel[0]] = base_convert($aPixel[1], 36, 10); } //--- Create Image Resource ---// $rImage = @imagecreatetruecolor($iWidth, $iHeight); for ($i = 0, $y = 0; $y < $iHeight; $y++) { for ($x = 0; $x < $iWidth; $x++, $i++) { @imagesetpixel($rImage, $x, $y, isset($aImageData[$i]) ? $aImageData[$i] : $iBackColor); } } //--- Save image file ---// $sFileName = $sFilesPath . $iBoardId . $sFileExtension; $bFileCreated = @imagejpeg($rImage, $sFileName, $iQuality); $aResult = $bFileCreated ? array('status' => SUCCESS_VAL, 'value' => "") : array('status' => FAILED_VAL, 'value' => "msgErrorFile"); if ($bFileCreated && $bSaveMode) { $aResult = save($sSavedId, $sFileName, $sTitle); if (useServer()) { @unlink($sFileName); } } $sContents = parseXml($aXmlTemplates['result'], $aResult['value'], $aResult['status']); break; case 'getSaved': if (loginUser($sId, $sPassword) == TRUE_VAL) { $sContents = getSavedBoardInfo($sId, $iBoardId); } else { $sContents = parseXml($aXmlTemplates['result'], "msgUserAuthenticationFailure", FAILED_VAL); } break; }
/** * set user's uploaded file time */ /** * set user's uploaded file time */ case 'updateFileTime': getResult("UPDATE `" . MODULE_DB_PREFIX . "Files` SET `Time`='" . $sTime . "' WHERE `ID`='" . $sId . "'"); $sContents = parseXml($aXmlTemplates['result'], TRUE_VAL); break; case 'post': $sSystem = isset($_REQUEST['system']) ? process_db_input($_REQUEST['system']) : ""; $sAuthor = isset($_REQUEST['author']) ? process_db_input($_REQUEST['author']) : ""; $sParent = isset($_REQUEST['parent']) ? process_db_input($_REQUEST['parent']) : ""; $sMood = isset($_REQUEST['mood']) ? process_db_input($_REQUEST['mood']) : ""; $sContents = ""; $sResult = publishRecordedVideoFile($sAuthor); if ($sResult) { $sContents = post($sSystem, $sId, $sAuthor, $sParent, $sMood, $sResult); } $sContentsType = "text"; break; case 'getToken': $sToken = _getToken($sId); if (empty($sToken)) { $sContents = parseXml($aXmlTemplates['result'], "msgFileNotFound", FAILED_VAL); } else { $sContents = parseXml($aXmlTemplates['result'], $sToken, SUCCESS_VAL); } break; }
doBan($sParamValue == TRUE_VAL ? 'ban' : 'unban', $sId); $sContents = parseXml($aXmlTemplates['result'], TRUE_VAL); } else { $sContents = parseXml($aXmlTemplates['result'], FALSE_VAL); } break; /** * Changes user's type. */ /** * Changes user's type. */ case 'changeType': if (loginAdmin($sNick, $sPassword)) { getResult("UPDATE `" . MODULE_DB_PREFIX . "Profiles` SET `Type`='" . $sType . "' WHERE `ID`='" . $sId . "'"); //--- For XML version only ---// getResult("UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `Status`='" . USER_STATUS_TYPE . "', `When`=UNIX_TIMESTAMP() WHERE `ID`='" . $sId . "'"); $sContents .= parseXml($aXmlTemplates['result'], TRUE_VAL); } else { $sContents .= parseXml($aXmlTemplates['result'], FALSE_VAL); } break; case 'kickUser': if ($bAdmin && loginAdmin($sNick, $sPassword) || !$bAdmin && loginUser($sModeratorId, $sPassword) && getUserType($sModeratorId) == CHAT_TYPE_MODER) { getResult("UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `Status`='" . USER_STATUS_KICK . "', `When`=UNIX_TIMESTAMP() WHERE `ID`='" . $sId . "'"); $sContents .= parseXml($aXmlTemplates['result'], TRUE_VAL); } else { $sContents .= parseXml($aXmlTemplates['result'], FALSE_VAL); } break; }
$db_host = 'ivoice00.mysql.ukraine.com.ua'; $db_log = 'ivoice00_db'; $db_pass = '******'; $db_name = 'ivoice00_db'; $db_table = 'temperature'; try { if (!testInternet()) { error_log('no internet connection'); } if (!testInternet($xml_host)) { error_log("no connection with {$xml_host}"); } if (!testDBConnect($db_host, $db_log, $db_pass, $db_name)) { } $xmlData = getXml($xml_url, $xml_login, $xml_password); $xmlData = parseXml($xmlData); addRecord($xmlData, $db_host, $db_log, $db_pass, $db_name, $db_table); } catch (Exception $e) { unlink($lock_file); throw new Exception($e->getMessage()); } unlink($lock_file); /*************/ /* FUNCTIONS */ /*************/ function testInternet($host = 'google.com', $port = 80, $auth = array()) { $waitTimeoutInSeconds = 30; $header = "GET / HTTP/1.0\r\n\r\n"; $header .= "Accept: text/html\r\n"; if (!empty($auth)) {
/** * ===> The rest of functions is for XML version only. <=== * Update user's status * @comment - Refreshed */ function refreshUsersInfo($sId = "", $sMode = 'all') { global $aXmlTemplates; global $sModule; $iUpdateInterval = (int) getSettingValue($sModule, "updateInterval"); $iIdleTime = $iUpdateInterval * 3; $iDeleteTime = $iUpdateInterval * 6; $iCurrentTime = time(); //--- refresh current user's track ---// getResult("UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `Status`='" . USER_STATUS_OLD . "', `When`='" . $iCurrentTime . "' WHERE `ID`='" . $sId . "' AND `Status`<>'" . USER_STATUS_KICK . "' AND (`Status` NOT IN('" . USER_STATUS_NEW . "', '" . USER_STATUS_TYPE . "', '" . USER_STATUS_ONLINE . "') || (" . $iCurrentTime . "-`When`)>" . $iUpdateInterval . ") LIMIT 1"); //--- refresh other users' states ---// getResult("UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `When`=" . $iCurrentTime . ", `Status`='" . USER_STATUS_IDLE . "' WHERE `Status`<>'" . USER_STATUS_IDLE . "' AND `When`<=(" . ($iCurrentTime - $iIdleTime) . ")"); getResult("DELETE FROM `" . MODULE_DB_PREFIX . "RoomsUsers` WHERE `Status`='" . ROOM_STATUS_DELETE . "' AND `When`<=(" . ($iCurrentTime - $iDeleteTime) . ")"); $rFiles = getResult("SELECT `files`.`ID` AS `FileID` FROM `" . MODULE_DB_PREFIX . "Messages` AS `files` INNER JOIN `" . MODULE_DB_PREFIX . "CurrentUsers` AS `users` WHERE `files`.`Recipient`=`users`.`ID` AND `files`.`Type`='file' AND `users`.`Status`='" . USER_STATUS_IDLE . "' AND `users`.`When`<=" . ($iCurrentTime - $iDeleteTime)); while ($aFile = mysql_fetch_assoc($rFiles)) { removeFile($aFile['FileID']); } //--- delete idle users, whose track was not refreshed more than delete time ---// getResult("DELETE FROM `" . MODULE_DB_PREFIX . "CurrentUsers`, `" . MODULE_DB_PREFIX . "RoomsUsers` USING `" . MODULE_DB_PREFIX . "CurrentUsers`, `" . MODULE_DB_PREFIX . "RoomsUsers` WHERE `" . MODULE_DB_PREFIX . "CurrentUsers`.`ID`=`" . MODULE_DB_PREFIX . "RoomsUsers`.`User` AND `" . MODULE_DB_PREFIX . "CurrentUsers`.`Status`='" . USER_STATUS_IDLE . "' AND `" . MODULE_DB_PREFIX . "CurrentUsers`.`When`<=" . ($iCurrentTime - $iDeleteTime)); //--- delete old rooms ---// getResult("DELETE FROM `" . MODULE_DB_PREFIX . "Rooms`, `" . MODULE_DB_PREFIX . "RoomsUsers` USING `" . MODULE_DB_PREFIX . "Rooms`,`" . MODULE_DB_PREFIX . "RoomsUsers` WHERE `" . MODULE_DB_PREFIX . "Rooms`.`ID`=`" . MODULE_DB_PREFIX . "RoomsUsers`.`Room` AND `" . MODULE_DB_PREFIX . "Rooms`.`Status`='" . ROOM_STATUS_DELETE . "' AND `" . MODULE_DB_PREFIX . "Rooms`.`When`<=(" . ($iCurrentTime - $iDeleteTime) . ")"); //--- delete empty rooms ---// if (getSettingValue($sModule, "removeRooms") == TRUE_VAL) { $aIds = getAdminIds(); $sIds = count($aIds) > 0 ? " AND `OwnerID` NOT IN (" . implode(',', $aIds) . ")" : ""; $rResult = getResult("SELECT DISTINCT(`Room`) FROM `" . MODULE_DB_PREFIX . "RoomsUsers`"); $aFullRooms = array(); $iCount = mysql_num_rows($rResult); for ($i = 0; $i < $iCount; $i++) { $aFullRoom = mysql_fetch_assoc($rResult); $aFullRooms[] = $aFullRoom['Room']; } $sFullRooms = count($aFullRooms) > 0 ? "`ID` NOT IN(" . implode(',', $aFullRooms) . ") AND " : ""; getResult("UPDATE `" . MODULE_DB_PREFIX . "Rooms` SET `Status`='" . ROOM_STATUS_DELETE . "', `When`=" . $iCurrentTime . " WHERE " . $sFullRooms . "`OwnerID`<>0" . $sIds); } //--- delete old messages ---// getResult("DELETE FROM `" . MODULE_DB_PREFIX . "Messages` WHERE `Type`='text' AND `When`<=(" . ($iCurrentTime - $iDeleteTime) . ")"); //--- Get information about users in the chat ---// switch ($sMode) { case 'update': $rRes = getResult("SELECT ccu.`ID` AS `ID`, ccu.`Nick` AS `Nick`, ccu.`Sex` AS `Sex`, ccu.`Age` AS `Age`, ccu.`Desc` AS `Desc`, ccu.`Photo` AS `Photo`, ccu.`Profile` AS `Profile`, ccu.`Status` AS `Status`, ccu.`Online` AS `Online`, rp.`Type` AS `Type` FROM `" . MODULE_DB_PREFIX . "Profiles` AS rp, `" . MODULE_DB_PREFIX . "CurrentUsers` AS ccu WHERE rp.`ID`=ccu.`ID` ORDER BY ccu.`When`"); while ($aUser = mysql_fetch_assoc($rRes)) { if ($aUser['ID'] == $sId && !($aUser['Status'] == USER_STATUS_KICK || $aUser['Status'] == USER_STATUS_TYPE)) { continue; } switch ($aUser['Status']) { case USER_STATUS_NEW: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status'], $aUser['Nick'], $aUser['Sex'], $aUser['Age'], stripslashes($aUser['Desc']), $aUser['Photo'], $aUser['Profile'], $aUser['Type'], $aUser['Online']); break; case USER_STATUS_TYPE: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status'], $aUser['Type']); break; case USER_STATUS_ONLINE: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status'], $aUser['Type'], $aUser['Online']); break; case USER_STATUS_IDLE: case USER_STATUS_KICK: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status']); break; } } break; case 'all': $iRunTime = isset($_REQUEST['_t']) ? floor($_REQUEST['_t'] / 1000) : 0; $iCurrentTime -= $iRunTime; $rRes = getResult("SELECT ccu.`ID` AS `ID`, ccu.`Nick` AS `Nick`, ccu.`Sex` AS `Sex`, ccu.`Age` AS `Age`, ccu.`Desc` AS `Desc`, ccu.`Photo` AS `Photo`, ccu.`Profile` AS `Profile`, ccu.`Online` AS `Online`, rp.`Type` AS `Type`, (" . $iCurrentTime . "-`ccu`.`Start`) AS `Time` FROM `" . MODULE_DB_PREFIX . "Profiles` AS rp, `" . MODULE_DB_PREFIX . "CurrentUsers` AS ccu WHERE rp.`ID`=ccu.`ID` AND ccu.`Status` NOT IN ('" . USER_STATUS_IDLE . "', '" . USER_STATUS_KICK . "') AND rp.`Banned`='" . FALSE_VAL . "' ORDER BY ccu.`When`"); while ($aUser = mysql_fetch_assoc($rRes)) { $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], USER_STATUS_NEW, $aUser['Nick'], $aUser['Sex'], $aUser['Age'], stripslashes($aUser['Desc']), $aUser['Photo'], $aUser['Profile'], $aUser['Type'], $aUser['Online'], $aUser['Time']); } break; } return makeGroup($sContent, "users"); }
/** * ===> The rest of functions is for XML version only. <=== * Update user's status * @comment - Refreshed */ function refreshUsersInfo($sId = "", $sMode = 'all') { global $sModule; global $aXmlTemplates; global $sFileExtension; global $sFilesPath; $iUpdateInterval = (int) getSettingValue($sModule, "updateInterval"); $iIdleTime = $iUpdateInterval * 3; $iDeleteTime = $iUpdateInterval * 6; $iCurrentTime = time(); //--- refresh current user's track ---// getResult("UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `Status`='" . USER_STATUS_OLD . "', `When`='" . $iCurrentTime . "' WHERE `ID`='" . $sId . "' AND (`Status`<>'" . USER_STATUS_NEW . "' || (" . $iCurrentTime . "-`When`)>" . $iUpdateInterval . ") LIMIT 1"); //--- refresh other users' states ---// getResult("UPDATE `" . MODULE_DB_PREFIX . "CurrentUsers` SET `When`=" . $iCurrentTime . ", `Status`='" . USER_STATUS_IDLE . "' WHERE `Status`<>'" . USER_STATUS_IDLE . "' AND `When`<=(" . ($iCurrentTime - $iIdleTime) . ")"); getResult("DELETE FROM `" . MODULE_DB_PREFIX . "Users` WHERE `Status`='" . BOARD_STATUS_DELETE . "' AND `When`<=(" . ($iCurrentTime - $iDeleteTime) . ")"); //--- delete idle users, whose track was not refreshed more than delete time ---// getResult("DELETE FROM `" . MODULE_DB_PREFIX . "CurrentUsers`, `" . MODULE_DB_PREFIX . "Users` USING `" . MODULE_DB_PREFIX . "CurrentUsers` LEFT JOIN `" . MODULE_DB_PREFIX . "Users` ON `" . MODULE_DB_PREFIX . "CurrentUsers`.`ID`=`" . MODULE_DB_PREFIX . "Users`.`User` WHERE `" . MODULE_DB_PREFIX . "CurrentUsers`.`Status`='" . USER_STATUS_IDLE . "' AND `" . MODULE_DB_PREFIX . "CurrentUsers`.`When`<=" . ($iCurrentTime - $iDeleteTime)); //--- Get information about users in the chat ---// switch ($sMode) { case 'update': $rRes = getResult("SELECT * FROM `" . MODULE_DB_PREFIX . "CurrentUsers` ORDER BY `When`"); while ($aUser = $rRes->fetch()) { switch ($aUser['Status']) { case USER_STATUS_NEW: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status'], $aUser['Nick'], $aUser['Sex'], $aUser['Age'], $aUser['Photo'], $aUser['Profile'], $aUser['Desc']); break; case USER_STATUS_IDLE: $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], $aUser['Status']); break; } } break; case 'all': $iRunTime = isset($_REQUEST['_t']) ? floor($_REQUEST['_t'] / 1000) : 0; $iCurrentTime -= $iRunTime; $rRes = getResult("SELECT * FROM `" . MODULE_DB_PREFIX . "CurrentUsers` WHERE `Status`<>'" . USER_STATUS_IDLE . "' ORDER BY `When`"); while ($aUser = $rRes->fetch()) { $sContent .= parseXml($aXmlTemplates['user'], $aUser['ID'], USER_STATUS_NEW, $aUser['Nick'], $aUser['Sex'], $aUser['Age'], $aUser['Photo'], $aUser['Profile'], $aUser['Desc']); } break; } return makeGroup($sContent, "users"); }
function getAvailableStatuses() { global $aXmlTemplates; $oStatuses = new BxDolUserStatusView(); $sContents = ""; foreach ($oStatuses->aStatuses as $sKey => $aStatus) { $sContents .= parseXml($aXmlTemplates["status"], $sKey, getTemplateIcon($aStatus["icon"]), _t($aStatus["title"])); } return makeGroup($sContents, "statuses"); }
function getPoints($gpxPath, $gpxOffset = 10, $donotreducegpx, $distancetype) { $points = array(); $dist = 0; $lastLat = 0; $lastLon = 0; $lastEle = 0; $lastOffset = 0; if (file_exists($gpxPath)) { $points = @parseXml($gpxPath, $gpxOffset, $distancetype); } else { echo "WP GPX Maps Error: File {$gpxPath} not found!"; } // reduce the points to around 200 to speedup if ($donotreducegpx != true) { $count = sizeof($points->lat); if ($count > 200) { $f = round($count / 200); if ($f > 1) { for ($i = $count; $i > 0; $i--) { if ($i % $f != 0 && $points->lat[$i] != null) { unset($points->dt[$i]); unset($points->lat[$i]); unset($points->lon[$i]); unset($points->ele[$i]); unset($points->dist[$i]); unset($points->speed[$i]); unset($points->hr[$i]); unset($points->atemp[$i]); unset($points->cad[$i]); unset($points->grade[$i]); } } } } } return $points; }
case 'newMessage': //--- check online status of the recipient ---// $iContactRid = getContactId($sRspId, $sSndId); if (!empty($iContactRid)) { $sColor = $_REQUEST['color'] ? $_REQUEST['color'] : "0"; $sBold = $_REQUEST['bold'] ? $_REQUEST['bold'] : FALSE_VAL; $sUnderline = $_REQUEST['underline'] ? $_REQUEST['underline'] : FALSE_VAL; $sItalic = $_REQUEST['italic'] ? $_REQUEST['italic'] : FALSE_VAL; $iSize = $_REQUEST['size'] ? $_REQUEST['size'] : 12; $sFont = $_REQUEST['font'] ? $_REQUEST['font'] : "Arial"; $sStyle = serialize(array('color' => $sColor, 'bold' => $sBold, 'underline' => $sUnderline, 'italic' => $sItalic, 'smileset' => $sSmileset, 'size' => $iSize, 'font' => $sFont)); $iContactSid = getContactId($sSndId, $sRspId); if (!empty($iContactSid)) { $rResult = getResult("INSERT INTO `" . MODULE_DB_PREFIX . "Messages` (`ContactID`, `Message`, `Style`, `When`) VALUES ('" . $iContactSid . "', '" . $sMsg . "', '" . $sStyle . "', '" . time() . "')"); } } else { $rResult = addPend($sSndId, $sRspId, $sMsg); } $sContents = parseXml($aXmlTemplates['result'], $rResult ? TRUE_VAL : FALSE_VAL); break; case 'help': $sApp = isset($_REQUEST['app']) ? $_REQUEST['app'] : "user"; $sContents = makeGroup("", "topics"); $sFileName = $sModulesPath . $sModule . "/help/" . $sApp . ".xml"; if (file_exists($sFileName)) { $rHandle = @fopen($sFileName, "rt"); $sContents = @fread($rHandle, filesize($sFileName)); fclose($rHandle); } break; }
/** * Gets new IM notifications. * @param id - user's ID, whose IM notifications need to be checked. * @param got - a list of notification's IDs, which were got previously (For example: 1,25,63 or -1 if this list is empty). */ /** * Gets new IM notifications. * @param id - user's ID, whose IM notifications need to be checked. * @param got - a list of notification's IDs, which were got previously (For example: 1,25,63 or -1 if this list is empty). */ case "getIms": $sQuery = "SELECT `ID`, `SenderID`, SUBSTRING(`Msg`, 1, 15) AS `Msg` FROM `" . $sImDBPrefix . "Pendings` WHERE `RecipientID`='" . $sId . "' AND IF('" . $_REQUEST['got'] . "'<>'-1', `ID` NOT IN (" . $_REQUEST['got'] . "), '1')"; $aIms = getResult($sQuery); while ($aIm = mysql_fetch_array($aIms)) { $aUserInfo = getUserInfo($aIm['SenderID']); $sContents .= parseXml($aXmlTemplates['message'], $aIm['Msg'], $aIm['ID'], $aIm['SenderID'], $aUserInfo['nick'], $aUserInfo['sex'], $aUserInfo['age'], $aUserInfo['photo'], $aUserInfo['profile']); } $sContents = makeGroup($sContents, "msgs"); break; /** * Declines received IM message. * @param id - user's ID. */ /** * Declines received IM message. * @param id - user's ID. */ case "declineIm": getResult("DELETE FROM `" . $sImDBPrefix . "Pendings` WHERE `ID`='" . $sId . "'"); break; /**