Exemple #1
0
 /**
  * The callback helper for {@link formatString()}.
  *
  * @param array $Match Either the array of arguments or the regular expression match.
  * @param bool $SetArgs Whether this is a call to initialize the arguments or a matching callback.
  * @return mixed Returns the matching string or nothing when setting the arguments.
  * @access private
  */
 function _formatStringCallback($Match, $SetArgs = false)
 {
     static $Args = array(), $ContextUserID = null;
     if ($SetArgs) {
         $Args = $Match;
         if (isset($Args['_ContextUserID'])) {
             $ContextUserID = $Args['_ContextUserID'];
         } else {
             $ContextUserID = Gdn::session() && Gdn::session()->isValid() ? Gdn::session()->UserID : null;
         }
         return '';
     }
     $Match = $Match[1];
     if ($Match == '{') {
         return $Match;
     }
     // Parse out the field and format.
     $Parts = explode(',', $Match);
     $Field = trim($Parts[0]);
     $Format = trim(val(1, $Parts, ''));
     $SubFormat = strtolower(trim(val(2, $Parts, '')));
     $FormatArgs = val(3, $Parts, '');
     if (in_array($Format, array('currency', 'integer', 'percent'))) {
         $FormatArgs = $SubFormat;
         $SubFormat = $Format;
         $Format = 'number';
     } elseif (is_numeric($SubFormat)) {
         $FormatArgs = $SubFormat;
         $SubFormat = '';
     }
     $Value = valr($Field, $Args, null);
     if ($Value === null && !in_array($Format, array('url', 'exurl', 'number', 'plural'))) {
         $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);
                             break;
                         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[,plural]
                 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;
                     }
                 } else {
                     $Gender = 'p';
                 }
                 switch ($Gender) {
                     case 'm':
                         $Result = $SubFormat;
                         break;
                     case 'f':
                         $Result = $FormatArgs;
                         break;
                     case 'p':
                         $Result = val(5, $Parts, val(4, $Parts));
                         break;
                     case 'u':
                     default:
                         $Result = val(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)) {
                     if (isset($Value['UserID'])) {
                         $User = $Value;
                         $User['Name'] = formatUsername($User, $Format, $ContextUserID);
                         $Result = userAnchor($User);
                     } else {
                         $Max = c('Garden.FormatUsername.Max', 5);
                         // See if there is another count.
                         $ExtraCount = valr($Field . '_Count', $Args, 0);
                         $Count = count($Value);
                         $Result = '';
                         for ($i = 0; $i < $Count; $i++) {
                             if ($i >= $Max && $Count > $Max + 1) {
                                 $Others = $Count - $i + $ExtraCount;
                                 $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);
                                 if ($User) {
                                     $User->Name = formatUsername($User, $Format, $ContextUserID);
                                     $Result .= userAnchor($User);
                                 }
                             }
                         }
                     }
                 } else {
                     $User = Gdn::userModel()->getID($Value);
                     if ($User) {
                         // Store this name separately because of special 'You' case.
                         $Name = formatUsername($User, $Format, $ContextUserID);
                         // Manually build instead of using userAnchor() because of special 'You' case.
                         $Result = anchor(htmlspecialchars($Name), userUrl($User));
                     } else {
                         $Result = '';
                     }
                 }
                 $Args = $ArgsBak;
                 break;
             default:
                 $Result = $Value;
                 break;
         }
     }
     return $Result;
 }
Exemple #2
0
  <input type="image" name="bdeluser" style="padding: 5px;" src="img/common/icn_arrowleft.gif" value="<--" /><br/>
  <input type="image" name="badduser" style="padding: 5px;" src="img/common/icn_arrowright.gif" value = "-->"/>
  </div>
  </td><td style="border: none;">

  <div class="list" style="padding-left: 10px;">
      <h3><?php 
echo _("Group members");
?>
</h3>
    <select multiple size="15" class="list" name="members[]">
<?php 
foreach ($members as $member) {
    foreach ($users as $user) {
        if ($user['uid'] == $member) {
            $name = formatUsername($user);
            break;
        }
    }
    echo "<option value=\"" . $member . "\">" . $name . "</option>\n";
}
?>
    </select>

    <br>

  </div>
  <div class="clearer"></div>
  </td></tr>
</table>
</div>
Exemple #3
0
function handleVictory($user)
{
    $message = 'Congratulations on winning ' . SYSTEM_SITE_NAME . ' ' . SYSTEM_YEAR . '!';
    $twitterMessage = 'Congratulations ' . formatUsername($user) . ' on winning ' . SYSTEM_SITE_NAME . ' ' . SYSTEM_YEAR . '!';
    log_text('SEND --> ' . $user['name'] . ': ' . $message);
    log_text('TWEET --> ' . $twitterMessage);
    if (SYSTEM_STARTED) {
        singleSMS($user['phone'], $message);
        postToTwitter($twitterMessage);
    }
}
 /**
  * A basic functional test example.
  *
  * @return void
  */
 public function testGetUsername()
 {
     $username = formatUsername(1);
     $this->assertEquals($username, 'allKindsOfIssues');
 }