function _FormatStringCallback($Match, $SetArgs = FALSE) { static $Args = array(); if ($SetArgs) { $Args = $Match; return; } $Match = $Match[1]; if ($Match == '{') { return $Match; } // Parse out the field and format. $Parts = explode(',', $Match); $Field = trim($Parts[0]); $Format = trim(GetValue(1, $Parts, '')); $SubFormat = strtolower(trim(GetValue(2, $Parts, ''))); $FormatArgs = GetValue(3, $Parts, ''); if (in_array($Format, array('currency', 'integer', 'percent'))) { $FormatArgs = $SubFormat; $SubFormat = $Format; $Format = 'number'; } elseif (is_numeric($SubFormat)) { $FormatArgs = $SubFormat; $SubFormat = ''; } $Value = GetValueR($Field, $Args, ''); if ($Value == '' && !in_array($Format, array('url', 'exurl'))) { $Result = ''; } else { switch (strtolower($Format)) { case 'date': switch ($SubFormat) { case 'short': $Result = Gdn_Format::Date($Value, '%d/%m/%Y'); break; case 'medium': $Result = Gdn_Format::Date($Value, '%e %b %Y'); break; case 'long': $Result = Gdn_Format::Date($Value, '%e %B %Y'); break; default: $Result = Gdn_Format::Date($Value); break; } break; case 'html': case 'htmlspecialchars': $Result = htmlspecialchars($Value); break; case 'number': if (!is_numeric($Value)) { $Result = $Value; } else { switch ($SubFormat) { case 'currency': $Result = '$' . number_format($Value, is_numeric($FormatArgs) ? $FormatArgs : 2); case 'integer': $Result = (string) round($Value); if (is_numeric($FormatArgs) && strlen($Result) < $FormatArgs) { $Result = str_repeat('0', $FormatArgs - strlen($Result)) . $Result; } break; case 'percent': $Result = round($Value * 100, is_numeric($FormatArgs) ? $FormatArgs : 0); break; default: $Result = number_format($Value, is_numeric($FormatArgs) ? $FormatArgs : 0); break; } } break; case 'plural': if (is_array($Value)) { $Value = count($Value); } elseif (StringEndsWith($Field, 'UserID', TRUE)) { $Value = 1; } if (!is_numeric($Value)) { $Result = $Value; } else { if (!$SubFormat) { $SubFormat = rtrim("%s {$Field}", 's'); } if (!$FormatArgs) { $FormatArgs = $SubFormat . 's'; } $Result = Plural($Value, $SubFormat, $FormatArgs); } break; case 'rawurlencode': $Result = rawurlencode($Value); break; case 'text': $Result = Gdn_Format::Text($Value, FALSE); break; case 'time': $Result = Gdn_Format::Date($Value, '%l:%M%p'); break; case 'url': if (strpos($Field, '/') !== FALSE) { $Value = $Field; } $Result = Url($Value, $SubFormat == 'domain'); break; case 'exurl': if (strpos($Field, '/') !== FALSE) { $Value = $Field; } $Result = ExternalUrl($Value); break; case 'urlencode': $Result = urlencode($Value); break; case 'gender': // Format in the form of FieldName,gender,male,female,unknown if (is_array($Value) && count($Value) == 1) { $Value = array_shift($Value); } $Gender = 'u'; if (!is_array($Value)) { $User = Gdn::UserModel()->GetID($Value); if ($User) { $Gender = $User->Gender; } } switch ($Gender) { case 'm': $Result = $SubFormat; break; case 'f': $Result = $FormatArgs; break; default: $Result = GetValue(4, $Parts); } break; case 'user': case 'you': case 'his': case 'her': case 'your': $Result = print_r($Value, TRUE); $ArgsBak = $Args; if (is_array($Value) && count($Value) == 1) { $Value = array_shift($Value); } if (is_array($Value)) { $Max = C('Garden.FormatUsername.Max', 5); $Count = count($Value); $Result = ''; for ($i = 0; $i < $Count; $i++) { if ($i >= $Max && $Count > $Max + 1) { $Others = $Count - $i; $Result .= ' ' . T('sep and', 'and') . ' ' . Plural($Others, '%s other', '%s others'); break; } $ID = $Value[$i]; if (is_array($ID)) { continue; } if ($i == $Count - 1) { $Result .= ' ' . T('sep and', 'and') . ' '; } elseif ($i > 0) { $Result .= ', '; } $Special = array(-1 => T('everyone'), -2 => T('moderators'), -3 => T('administrators')); if (isset($Special[$ID])) { $Result .= $Special[$ID]; } else { $User = Gdn::UserModel()->GetID($ID); $User->Name = FormatUsername($User, $Format, Gdn::Session()->UserID); $Result .= UserAnchor($User); } } } else { $User = Gdn::UserModel()->GetID($Value); $User->Name = FormatUsername($User, $Format, Gdn::Session()->UserID); $Result = UserAnchor($User); } $Args = $ArgsBak; break; default: $Result = $Value; break; } } return $Result; }
function __construct($kptime = -1, $cache = FALSE) { global $dsql; if ($kptime == -1) { $this->M_KeepTime = 3600 * 24 * 7; } else { $this->M_KeepTime = $kptime; } $formcache = FALSE; $this->M_ID = $this->GetNum(GetCookie("DedeUserID")); $this->M_LoginTime = GetCookie("DedeLoginTime"); $this->fields = array(); $this->isAdmin = FALSE; if (empty($this->M_ID)) { $this->ResetUser(); } else { $this->M_ID = intval($this->M_ID); if ($cache) { $this->fields = GetCache($this->memberCache, $this->M_ID); if (empty($this->fields)) { $this->fields = $dsql->GetOne("Select * From `#@__member` where mid='{$this->M_ID}' "); } else { $formcache = TRUE; } } else { $this->fields = $dsql->GetOne("Select * From `#@__member` where mid='{$this->M_ID}' "); } if (is_array($this->fields)) { #api{{ if (defined('UC_API') && @(include_once DEDEROOT . '/uc_client/client.php')) { if ($data = uc_get_user($this->fields['userid'])) { if (uc_check_avatar($data[0]) && !strstr($this->fields['face'], UC_API)) { $this->fields['face'] = UC_API . '/avatar.php?uid=' . $data[0] . '&size=middle'; $dsql->ExecuteNoneQuery("UPDATE `#@__member` SET `face`='" . $this->fields['face'] . "' WHERE `mid`='{$this->M_ID}'"); } } } #/aip}} //间隔一小时更新一次用户登录时间 if (time() - $this->M_LoginTime > 3600) { $dsql->ExecuteNoneQuery("update `#@__member` set logintime='" . time() . "',loginip='" . GetIP() . "' where mid='" . $this->fields['mid'] . "';"); PutCookie("DedeLoginTime", time(), $this->M_KeepTime); } $this->M_LoginID = $this->fields['userid']; $this->M_MbType = $this->fields['mtype']; $this->M_Money = $this->fields['money']; $this->M_UserName = FormatUsername($this->fields['uname']); $this->M_Scores = $this->fields['scores']; $this->M_Face = $this->fields['face']; $this->M_Rank = $this->fields['rank']; $this->M_Spacesta = $this->fields['spacesta']; $sql = "Select titles From #@__scores where integral<={$this->fields['scores']} order by integral desc"; $scrow = $dsql->GetOne($sql); $this->fields['honor'] = $scrow['titles']; $this->M_Honor = $this->fields['honor']; if ($this->fields['matt'] == 10) { $this->isAdmin = TRUE; } $this->M_UpTime = $this->fields['uptime']; $this->M_ExpTime = $this->fields['exptime']; $this->M_JoinTime = MyDate('Y-m-d', $this->fields['jointime']); if ($this->M_Rank > 10 && $this->M_UpTime > 0) { $this->M_HasDay = $this->Judgemember(); } if (!$formcache) { SetCache($this->memberCache, $this->M_ID, $this->fields, 1800); } } else { $this->ResetUser(); } } }
</li> <?php if (count($this->Data('Conversations'))) { ?> <?php foreach ($this->Data('Conversations') as $Row) { $Subject = ''; if ($Row['Subject']) { $Subject = Gdn_Format::Text($Row['Subject']); } else { $Subject = ''; foreach ($Row['Participants'] as $User) { if (!isset($PhotoUser)) { $PhotoUser = $User; } $Subject = ConcatSep(', ', $Subject, FormatUsername($User, 'You')); } } if (!isset($PhotoUser)) { $PhotoUser = UserBuilder($Row, 'LastMessage'); } ?> <li class="Item" rel="<?php echo Url("/messages/{$Row['ConversationID']}#latest"); ?> "> <div class="Author Photo"><?php echo UserPhoto($PhotoUser); ?> </div> <div class="ItemContent">
} else { $Message = SliceString(Gdn_Format::Text(Gdn_Format::To($Conversation->LastBody, $Conversation->LastFormat), FALSE), 100); } if (StringIsNullOrEmpty(trim($Message))) { $Message = T('Blank Message'); } $this->EventArguments['Conversation'] = $Conversation; ?> <li class="<?php echo $CssClass; ?> "> <?php $Names = ''; foreach ($Conversation->Participants as $User) { $Names = ConcatSep(', ', $Names, FormatUsername($User, 'You')); } ?> <div class="ItemContent Conversation"> <?php $Url = '/messages/' . $Conversation->ConversationID . '/#Item_' . $JumpToItem; if ($Names) { echo '<h3 class="Users">'; if ($LastPhoto) { echo '<div class="Author Photo">' . $LastPhoto . '</div>'; } echo Anchor(htmlspecialchars($Names), $Url), '</h3>'; } if ($SubjectsVisible && ($Subject = GetValue('Subject', $Conversation))) { echo '<div class="Subject"><b>' . Anchor(htmlspecialchars($Subject), $Url) . '</b></div>'; }