function setupBWSession($m) { $member_id = (int) $m->id; // Set the session identifier $_SESSION['IdMember'] = $m->id; $_SESSION['Username'] = $m->Username; $_SESSION['MemberStatus'] = $_SESSION['Status'] = $m->Status; if ($_SESSION['IdMember'] != $m->id) { // Check is session work of $this->logout(); throw new PException('Login sanity check failed miserably!'); } // end Check is session work of $_SESSION['MemberCryptKey'] = crypt($m->PassWord, "rt"); // Set the key which will be used for member personal cryptation $_SESSION['LogCheck'] = Crc32($_SESSION['MemberCryptKey'] . $m->id); // Set the key for checking id and LohCheck (will be restricted in future) if ($m->NbRemindWithoutLogingIn > 0) { MOD_log::get()->write("This member was having a NbRemindWithoutLogingIn=" . $m->NbRemindWithoutLogingIn, "Login"); } $this->dao->query("\r\nUPDATE\r\n members\r\nSET\r\n LogCount = LogCount+1,\r\n LastLogin = NOW(),\r\n NbRemindWithoutLogingIn = 0\r\n\r\nWHERE\r\n id = {$member_id}\r\n "); // update the LastLogin date // Load language prederence (IdPreference=1) // todo: come up with interesting idea like ... using just ONE query to load preferences if ($preference_language = $this->singleLookup("\r\nSELECT\r\n memberspreferences.Value AS language_id,\r\n ShortCode AS language_code\r\nFROM\r\n memberspreferences,\r\n languages,\r\n\tpreferences\r\nWHERE\r\n IdMember = {$member_id} AND\r\n memberspreferences.Value = languages.id AND\r\n IdPreference=preferences.id and preferences.CodeName='PreferenceLanguage'\r\n ")) { $_SESSION['IdLanguage'] = $preference_language->language_id; $_SESSION['lang'] = $preference_language->language_code; } if ($preference_PreferenceDayLight = $this->singleLookup("\r\nSELECT\r\n memberspreferences.Value\r\nFROM\r\n memberspreferences,\r\n\tpreferences\r\nWHERE\r\n IdMember = {$member_id} AND\r\n IdPreference=preferences.id and preferences.CodeName='PreferenceDayLight'\r\n ")) { $_SESSION['PreferenceDayLight'] = $preference_PreferenceDayLight->Value; } if ($preference_PreferenceLocalTime = $this->singleLookup("\r\nSELECT\r\n memberspreferences.Value\r\nFROM\r\n memberspreferences,\r\n\tpreferences\r\nWHERE\r\n IdMember = {$member_id} AND\r\n IdPreference=preferences.id and preferences.CodeName='PreferenceLocalTime'\r\n ")) { $_SESSION["TimeOffset"] = $preference_PreferenceLocalTime->Value; } // Process the login of the member according to his status switch ($m->Status) { case "Active": case "ActiveHidden": case "ChoiceInactive": case "NeedMore": case "Pending": //if (HasRight("Words")) // $_SESSION['switchtrans'] = "on"; // Activate switchtrans oprion if its a translator break; default: throw new PException('SetupBWSession Weird Status!'); break; } }
/** * check if the user is a logged in member * @$ExtraAllowedStatus allows for a list, comma separated of extra status which can * be allowed for members in addition to the basic Active and ActiveHidden members.Status * this means that in the default case : * (IsLoggedIn()) will return true only if the member has a session * with an IdMember and a Status like Active or ActiveHidden * in the extended cases * (IsLoggedIn("Pending")) will also return true if the member has a * a status set to Pending, this allow to give specific access to * other members than the one with Active or ActiveHiddend Status * * @return boolean */ function isBWLoggedIn($ExtraAllowedStatus = "") { if (empty($_SESSION['IdMember'])) { return false; } if (empty($_SESSION['MemberCryptKey'])) { return false; } if ($_SESSION['LogCheck'] != Crc32($_SESSION['MemberCryptKey'] . $_SESSION['IdMember'])) { $this->logout(); return false; } if (empty($_SESSION["MemberStatus"])) { $strerror = "Members with IdMember=" . $_SESSION["IdMember"] . " has no \$_SESSION[\"MemberStatus\"]"; error_log($strerror); MOD_log::get()->write($strerror, "Debug"); die($strerror); } if ($_SESSION["MemberStatus"] == 'Active') { return true; } if ($_SESSION["MemberStatus"] == 'ChoiceInactive') { return true; } if ($_SESSION["MemberStatus"] == 'ActiveHidden') { return true; } if (!empty($ExtraAllowedStatus)) { // are there allowed exception ? if (!isset($_SESSION["MemberStatus"])) { $ret = print_r($_SESSION, true); die("no \$_SESSION[\"MemberStatus\"] in IsLoggedIn() " . "<br />\n" . $ret); } $tt = explode(",", str_replace(";", ",", $ExtraAllowedStatus)); if (count($tt) > 0 and in_array($_SESSION["MemberStatus"], $tt)) { return true; } } return false; }
function String_Xml_Parse($String, $IsUseCache = TRUE) { #------------------------------------------------------------------------------- # костыль для удаления не-UTF8 символов $String = iconv('UTF-8', 'UTF-8//IGNORE', $String); #------------------------------------------------------------------------------- $Length = Mb_StrLen($String); #------------------------------------------------------------------------------- $IsUseCache = $IsUseCache && $Length > 1024; #------------------------------------------------------------------------------- if ($IsUseCache) { #------------------------------------------------------------------------------- $CacheID = SPrintF('String_XML_Parse[%s]', Md5(Crc32($String))); #------------------------------------------------------------------------------- $Result = CacheManager::get($CacheID); if ($Result) { return $Result; } } #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- Debug(SPrintF('[String_XML_Parse]: парсирование строки (%u bytes)', $Length)); #------------------------------------------------------------------------------- $XmlParser = Xml_Parser_Create('UTF-8'); #------------------------------------------------------------------------------- if (!Xml_Parser_Set_Option($XmlParser, XML_OPTION_CASE_FOLDING, FALSE)) { return ERROR | Trigger_Error('[String_Xml_Parse]: не удалось установить опцию парсирования (XML_OPTION_CASE_FOLDING)'); } #------------------------------------------------------------------------------- if (!Xml_Parser_Set_Option($XmlParser, XML_OPTION_SKIP_WHITE, FALSE)) { return ERROR | Trigger_Error('[String_Xml_Parse]: не удалось установить опцию парсирования (XML_OPTION_SKIP_WHITE)'); } #------------------------------------------------------------------------------- if (!Xml_Parse_Into_Struct($XmlParser, $String, $Nodes)) { #------------------------------------------------------------------------------- $ByteIndex = Xml_Get_Current_Byte_Index($XmlParser); #------------------------------------------------------------------------------- Debug(SPrintF('[system/libs/auto/String.php]: xml_error_string = %s', Xml_Error_String(Xml_Get_Error_Code($XmlParser)))); #------------------------------------------------------------------------------- Debug(SPrintF('[system/libs/auto/String.php]: %s', Mb_SubStr($String, $ByteIndex - 100, $ByteIndex + 100))); #------------------------------------------------------------------------------- $Buffer = Mb_SubStr($String, 0, $ByteIndex); #------------------------------------------------------------------------------- $Line = Preg_Match_All("/(\r\n|\n)/sU", $Buffer, $Matches) + 1; #------------------------------------------------------------------------------- return new gException('XML_PARSE_ERROR', SPrintF('%s в линии %u', Xml_Error_String($XmlParser), $Line)); #------------------------------------------------------------------------------- } #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- #----------------------------------------------------------------------------- Xml_Parser_Free($XmlParser); #----------------------------------------------------------------------------- $Root = new Tag('__ROOT__'); #----------------------------------------------------------------------------- $Links = array(&$Root); #----------------------------------------------------------------------------- foreach ($Nodes as $Node) { #--------------------------------------------------------------------------- $Current = $Links[Count($Links) - 1]; #--------------------------------------------------------------------------- switch ($Node['type']) { case 'open': #----------------------------------------------------------------------- $Tag = new Tag($Node['tag']); #----------------------------------------------------------------------- if (isset($Node['attributes'])) { $Tag->AddAttribs($Node['attributes']); } #----------------------------------------------------------------------- if (isset($Node['value'])) { #--------------------------------------------------------------------- $Value = $Node['value']; #--------------------------------------------------------------------- if (Trim($Value)) { $Tag->AddChild(new Tag('CDATA', $Value)); } } #----------------------------------------------------------------------- $Current->Childs[] = $Tag; #----------------------------------------------------------------------- $Links[] =& $Current->Childs[Count($Current->Childs) - 1]; break; case 'cdata': #----------------------------------------------------------------------- $Value = $Node['value']; #----------------------------------------------------------------------- if (Trim($Value)) { #--------------------------------------------------------------------- $Tag = new Tag('CDATA', $Value); #--------------------------------------------------------------------- $Current->Childs[] = $Tag; } break; case 'complete': #----------------------------------------------------------------------- $Tag = new Tag($Node['tag']); #----------------------------------------------------------------------- if (isset($Node['attributes'])) { $Tag->AddAttribs($Node['attributes']); } #----------------------------------------------------------------------- if (isset($Node['value'])) { $Tag->AddText($Node['value']); } #----------------------------------------------------------------------- $Current->Childs[] = $Tag; break; case 'close': Array_Pop($Links); break; default: # No more... } } #----------------------------------------------------------------------------- if ($IsUseCache) { CacheManager::add($CacheID, $Root); } #----------------------------------------------------------------------------- return $Root; }
/** * check if the user is a logged in member * @$ExtraAllowedStatus allows for a list, comma separated of extra status which can * be allowed for members in addition to the basic Active and ActiveHidden members.Status * this means that in the default case : * (IsLoggedIn()) will return true only if the member has a session * with an IdMember and a Status like Active or ActiveHidden * in the extended cases * (IsLoggedIn("Pending")) will also return true if the member has a * a status set to Pending, this allow to give specific access to * other members than the one with Active or ActiveHiddend Status * * @return boolean */ function IsLoggedIn($ExtraAllowedStatus = "") { if (empty($_SESSION['IdMember'])) { return false; } if (empty($_SESSION['MemberCryptKey'])) { // LogStr("IsLoggedIn() : Anomaly with MemberCryptKey","Bug"); return false; } if ($_SESSION['LogCheck'] != Crc32($_SESSION['MemberCryptKey'] . $_SESSION['IdMember'])) { LogStr("Anomaly with Log Check", "Hacking"); APP_User::get()->logout(); header("Location: " . PVars::getObj('env')->baseuri); exit(0); } if (empty($_SESSION["MemberStatus"])) { $strerror = "Members with IdMember=" . $_SESSION["IdMember"] . " has no \$_SESSION[\"MemberStatus\"]"; error_log($strerror); LogStr($strerror, "Debug"); die($strerror); } if ($_SESSION["MemberStatus"] == 'Active') { return true; } if ($_SESSION["MemberStatus"] == 'ActiveHidden') { return true; } if (!empty($ExtraAllowedStatus)) { // are there allowed exception ? if (!isset($_SESSION["MemberStatus"])) { $ret = print_r($_SESSION, true); die("no \$_SESSION[\"MemberStatus\"] in IsLoggedIn() " . "<br />\n" . $ret); } $tt = explode(",", str_replace(";", ",", $ExtraAllowedStatus)); if (count($tt) > 0 and in_array($_SESSION["MemberStatus"], $tt)) { return true; } } return false; }