function pleac_Printing_Correct_Plurals()
{
    function pluralise($value, $root, $singular = '', $plural = 's')
    {
        return $root . ($value > 1 ? $plural : $singular);
    }
    // ------------
    $duration = 1;
    printf("It took %d %s\n", $duration, pluralise($duration, 'hour'));
    printf("%d %s %s enough.\n", $duration, pluralise($duration, 'hour'), pluralise($duration, '', 'is', 'are'));
    $duration = 5;
    printf("It took %d %s\n", $duration, pluralise($duration, 'hour'));
    printf("%d %s %s enough.\n", $duration, pluralise($duration, 'hour'), pluralise($duration, '', 'is', 'are'));
    // ----------------------------
    function plural($singular)
    {
        $s2p = array('/ss$/' => 'sses', '/([psc]h)$/' => '${1}es', '/z$/' => 'zes', '/ff$/' => 'ffs', '/f$/' => 'ves', '/ey$/' => 'eys', '/y$/' => 'ies', '/ix$/' => 'ices', '/([sx])$/' => '$1es', '$' => 's');
        foreach ($s2p as $s => $p) {
            if (preg_match($s, $singular)) {
                return preg_replace($s, $p, $singular);
            }
        }
    }
    // ------------
    foreach (array('mess', 'index', 'leaf', 'puppy') as $word) {
        printf("%6s -> %s\n", $word, plural($word));
    }
}
 function after_get_record(&$record, $query, $url, $params)
 {
     global $CONF;
     $module = Module::load('fed');
     $ds = $module->get_datasource();
     $result = $ds->retrieve('/stats' . $url);
     $record['view_count'] = @$result['count'];
     $record['view_count_msg'] = 'This record has been viewed ' . @$result['count'] . ' ' . pluralise(@$result['count'], 'time') . '.';
     $record['sidebar'][] = new RecordScoreFacet($record, $query, $result, $url, $CONF['url'] . '/score.php');
 }
示例#3
0
function relative_time($date)
{
    $elapsed = time() - $date;
    if ($elapsed <= 1) {
        return 'Just now';
    }
    $times = array(31104000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second');
    foreach ($times as $seconds => $title) {
        $rounded = $elapsed / $seconds;
        if ($rounded > 1) {
            $rounded = round($rounded);
            return $rounded . ' ' . pluralise($rounded, $title) . ' ago';
        }
    }
}
示例#4
0
 public function activityUpdatesBySubject($dryrun = false)
 {
     echo "<h3>Running Activity Tweet Update</h3><i>Date Started: " . date('r') . "</i>" . BR . BR;
     if ($dryrun == "true") {
         echo "<pre>RUNNING IN DRY-RUN MODE - NO ACTUAL TWEETS WILL BE SENT!!! Remove /true in the URL to run properly!</pre>";
     }
     // Setup our API access
     $this->load->library('twitter');
     $twitter = new Twitter(array('consumerKey' => $this->consumer_key, 'consumerSecret' => $this->consumer_secret));
     $twitter->setOAuthToken($this->oauth_access_token);
     $twitter->setOAuthTokenSecret($this->oauth_access_secret);
     // Go and get our activity information
     $service_url = registry_url('services/rda/getLatestActivityBySubject/' . $this->num_days_history);
     $data = @json_decode(@file_get_contents($service_url), true);
     if (!isset($data['results']) || count($data['results']) == 0) {
         echo "No activity information to be displayed. No updates matched the query at " . $service_url;
         return;
     } else {
         echo "<h4>Found " . count($data['results']) . " updates for the past " . $this->num_days_history . " days...</h4>";
         // Reverse the sort order so largest update counts come last (i.e. highest on the Twitter feed)
         krsort($data['results']);
         foreach ($data['results'] as $idx => $update) {
             try {
                 // Format our tweet message
                 $tweet = sprintf("%d %s added with the subject '%s' #ANZSRC%s", $update['num_records'], pluralise("collection", $update['num_records']), ellipsis($update['value']), $update['notation']);
                 echo "Sending Tweet: <i>" . $tweet . "</i>...";
                 flush();
                 if (!$dryrun) {
                     $twitter->statusesUpdate($tweet);
                     echo "sent " . BR;
                     flush();
                 }
                 sleep(0.5);
                 // Pause between big chunks of tweets
                 if ($idx % 5 == 0) {
                     sleep(5);
                 }
             } catch (TwitterException $e) {
                 echo BR . BR . "Unable to send Tweet to Twitter API: " . $e->getMessage() . BR . BR;
             } catch (Exception $e) {
                 echo BR . BR . "Unknown Exception: " . $e->getMessage() . BR . BR;
             }
         }
     }
     return;
 }
示例#5
0
function relative_time($time)
{
    $elapsed = time() - $time;
    if ($elapsed <= 60) {
        return 'Just now';
    }
    $times = array(2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute');
    if ($elapsed > key($times)) {
        return date(Config::get('metadata.date_format'), $time);
    }
    foreach ($times as $seconds => $title) {
        $rounded = $elapsed / $seconds;
        if ($rounded > 1) {
            $rounded = round($rounded);
            return $rounded . ' ' . pluralise($rounded, $title) . ' ago';
        }
    }
}
示例#6
0
 function test_pluralise()
 {
     $this->assertTrue(pluralise(0, 'record') == 'records');
     $this->assertTrue(pluralise(1, 'record') == 'record');
     $this->assertTrue(pluralise(2, 'record') == 'records');
     $this->assertTrue(pluralise(0, 'fish', '') == 'fish');
     $this->assertTrue(pluralise(1, 'fish', '') == 'fish');
     $this->assertTrue(pluralise(2, 'fish', '') == 'fish');
     $this->assertTrue(pluralise(0, 'dish', 'es') == 'dishes');
     $this->assertTrue(pluralise(1, 'dish', 'es') == 'dish');
     $this->assertTrue(pluralise(2, 'dish', 'es') == 'dishes');
     $this->assertTrue(pluralise(0, 'radi', 'i', 'us') == 'radii');
     $this->assertTrue(pluralise(1, 'radi', 'i', 'us') == 'radius');
     $this->assertTrue(pluralise(2, 'radi', 'i', 'us') == 'radii');
     $this->assertTrue(pluralise(0, 'm', 'ice', 'ouse') == 'mice');
     $this->assertTrue(pluralise(1, 'm', 'ice', 'ouse') == 'mouse');
     $this->assertTrue(pluralise(2, 'm', 'ice', 'ouse') == 'mice');
 }
示例#7
0
function relative_time($date)
{
    if (is_numeric($date)) {
        $date = '@' . $date;
    }
    $user_timezone = new DateTimeZone(Config::app('timezone'));
    $date = new DateTime($date, $user_timezone);
    // get current date in user timezone
    $now = new DateTime('now', $user_timezone);
    $elapsed = $now->format('U') - $date->format('U');
    if ($elapsed <= 1) {
        return 'Just now';
    }
    $times = array(31104000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second');
    foreach ($times as $seconds => $title) {
        $rounded = $elapsed / $seconds;
        if ($rounded > 1) {
            $rounded = round($rounded);
            return $rounded . ' ' . pluralise($rounded, $title) . ' ago';
        }
    }
}
示例#8
0
文件: theme.php 项目: NaiRobley/Dabr
function theme_users_list($feed, $hide_pagination = false)
{
    if (isset($feed->users)) {
        $users = $feed->users;
    } else {
        $users = $feed;
    }
    $rows = array();
    if (count($users) == 0 || $users == '[]') {
        return '<p>No users to display.</p>';
    }
    foreach ($users as $user) {
        $content = "";
        if ($user->user) {
            $user = $user->user;
        }
        $name = theme('full_name', $user);
        $tweets_per_day = twitter_tweets_per_day($user);
        $last_tweet = strtotime($user->status->created_at);
        // $vicon = ($user->verified) ? theme('action_icon', "", '✔', 'verified') : '';
        $content = "{$name}<br />";
        //" <span class=\"actionicons\">{$vicon}</span>";
        $content .= "<span class='about'>";
        if ($user->description != "") {
            $content .= "Bio: " . twitter_parse_tags($user->description, $user->entities->description) . "<br />";
        }
        if ($user->location != "") {
            $content .= theme('action_icon', "https://maps.google.com/maps?q=" . urlencode($user->location), "<span class='icons'>⌖</span> {$user->location}", 'Location');
            $content .= "<br />";
        }
        $content .= "Info: ";
        $content .= pluralise('tweet', $user->statuses_count, true) . ", ";
        $content .= pluralise('friend', $user->friends_count, true) . ", ";
        $content .= pluralise('follower', $user->followers_count, true) . ", ";
        $content .= "~" . pluralise('tweet', $tweets_per_day, true) . " per day<br />";
        if ($user->status->created_at) {
            $content .= "Last tweet: ";
            if ($user->protected == 'true' && $last_tweet == 0) {
                $content .= "Private";
            } else {
                if ($last_tweet == 0) {
                    $content .= "Never tweeted";
                } else {
                    $content .= twitter_date('l jS F Y', $last_tweet);
                }
            }
        }
        $content .= "</span>";
        $rows[] = array('data' => array(array('data' => theme('avatar', theme_get_avatar($user)), 'class' => 'avatar'), array('data' => $content, 'class' => 'status shift')), 'class' => 'tweet');
    }
    $content = theme('table', array(), $rows, array('class' => 'followers'));
    if (!$hide_pagination) {
        #$content .= theme('pagination');
        $content .= theme('list_pagination', $feed);
    }
    return $content;
}
示例#9
0
function theme_followers($feed, $hide_pagination = false)
{
    $rows = array();
    if (count($feed) == 0 || $feed == '[]') {
        return '<p>No users to display.</p>';
    }
    foreach ($feed->users->user as $user) {
        $name = theme('full_name', $user);
        $tweets_per_day = twitter_tweets_per_day($user);
        $last_tweet = strtotime($user->status->created_at);
        $content = "{$name}<br /><span class='about'>";
        if ($user->description != "") {
            $content .= "Bio: {$user->description}<br />";
        }
        if ($user->location != "") {
            $content .= "Location: {$user->location}<br />";
        }
        $content .= "Info: ";
        $content .= pluralise('tweet', $user->statuses_count, true) . ", ";
        $content .= pluralise('friend', $user->friends_count, true) . ", ";
        $content .= pluralise('follower', $user->followers_count, true) . ", ";
        $content .= "~" . pluralise('tweet', $tweets_per_day, true) . " per day<br />";
        $content .= "Last tweet: ";
        if ($user->protected == 'true' && $last_tweet == 0) {
            $content .= "Private";
        } else {
            if ($last_tweet == 0) {
                $content .= "Never tweeted";
            } else {
                $content .= twitter_date('l jS F Y', $last_tweet);
            }
        }
        $content .= "</span>";
        $rows[] = array('data' => array(array('data' => theme('avatar', $user->profile_image_url), 'class' => 'avatar'), array('data' => $content, 'class' => 'status shift')), 'class' => 'tweet');
    }
    $content = theme('table', array(), $rows, array('class' => 'followers'));
    if (!$hide_pagination) {
        $content .= theme('list_pagination', $feed);
    }
    return $content;
}
示例#10
0
?>
			</article>

			<section class="footnote">
				<!-- Unfortunately, CSS means everything's got to be inline. -->
				<p>This article is my <?php 
echo numeral(article_number(article_id()), true);
?>
 oldest. It is <?php 
echo count_words(article_markdown());
?>
 words long<?php 
if (comments_open()) {
    ?>
, and it’s got <?php 
    echo total_comments() . pluralise(total_comments(), ' comment');
    ?>
 for now.<?php 
}
?>
 <?php 
echo article_custom_field('attribution');
?>
</p>
			</section>
		</section>

		<?php 
if (comments_open()) {
    ?>
		<section class="comments">
?>
 chars) in the box below<br>
<textarea name="note" rows="4"><?php 
echo @$_POST['note'];
?>
</textarea>
</p>
<? endif /* Email note */ ?>
</form>
<? if ($COUNT_EMAILS_SENT): ?>
<p>Emails are limited to a maximum of <?php 
echo $CONF['max_emails_per_session'];
?>
 per session.
You have sent <?php 
echo $COUNT_EMAILS_SENT . ' ' . pluralise($COUNT_EMAILS_SENT, 'email');
?>
.
<? if ($COUNT_EMAILS_SENT == ($CONF['max_emails_per_session'] - 1)): ?><br /><b>This is the last email you will be able to send in this session.</b><? endif ?>
</p>
<? endif /* Session count */ ?>
<p>The data below will be sent by email:</p>
<pre>
<?php 
echo $EMAIL_BODY;
?>
</pre>
<? else: ?>
<p>No records to email</p>
<? endif ?>
示例#12
0
<?php 
if (has_search_results()) {
    ?>
<section class="content">
	<p>We found <?php 
    echo total_search_results();
    ?>
 <?php 
    echo pluralise(total_search_results(), 'result');
    ?>
 
	for &ldquo;<?php 
    echo search_term();
    ?>
&rdquo;.</p>
</section>
<ul class="posts">
	<?php 
    while (search_results()) {
        ?>
	<li>
		<h3><?php 
        echo article_title();
        ?>
</h3>
		<p><?php 
        echo article_description();
        ?>
</p>
		
示例#13
0
function theme_retweeters($feed, $hide_pagination = false)
{
    $rows = array();
    if (count($feed) == 0 || $feed == '[]') {
        return '<p>No one has retweeted this status.</p>';
    }
    foreach ($feed->user as $user) {
        $name = theme('full_name', $user);
        $tweets_per_day = twitter_tweets_per_day($user);
        $last_tweet = strtotime($user->status->created_at);
        $content = "{$name}<br /><span class='about'>";
        if ($user->description != "") {
            $content .= "Bio: " . twitter_parse_tags($user->description) . "<br />";
        }
        if ($user->location != "") {
            $content .= "Location: {$user->location}<br />";
        }
        $content .= "Info: ";
        $content .= pluralise('tweet', $user->statuses_count, true) . ", ";
        $content .= pluralise('friend', $user->friends_count, true) . ", ";
        $content .= pluralise('follower', $user->followers_count, true) . ", ";
        $content .= "~" . pluralise('tweet', $tweets_per_day, true) . " per day<br />";
        $content .= "</span>";
        $rows[] = array('data' => array(array('data' => theme('avatar', theme_get_avatar($user)), 'class' => 'avatar'), array('data' => $content, 'class' => 'status shift')), 'class' => 'tweet');
    }
    $content = theme('table', array(), $rows, array('class' => 'followers'));
    if (!$hide_pagination) {
        $content .= theme('list_pagination', $feed);
    }
    return $content;
}
示例#14
0
function format_interval($timestamp, $granularity = 2)
{
    $units = array('year' => 31536000, 'day' => 86400, 'hour' => 3600, 'min' => 60, 'sec' => 1);
    $output = '';
    foreach ($units as $key => $value) {
        if ($timestamp >= $value) {
            $output .= ($output ? ' ' : '') . pluralise($key, floor($timestamp / $value), true);
            $timestamp %= $value;
            $granularity--;
        }
        if ($granularity == 0) {
            break;
        }
    }
    return $output ? $output : '0 sec';
}
示例#15
0
 /**
  * @test
  */
 public function shouldInflectWord()
 {
     //given
     $count = 1;
     //when
     $inflected = pluralise($count, array('plural' => 'clients', 'singular' => 'client'));
     //then
     $this->assertEquals('client', $inflected);
 }
示例#16
0
					<div class="more-link"><a href="<?php 
        echo article_url();
        ?>
" title="read the full article">read more &rarr;</a></div>
					<p class="small-note" style="padding: 20px 0 0;">By <a href="mailto:<?php 
        echo user_authed_email();
        ?>
"><?php 
        echo article_author();
        ?>
</a> on <?php 
        echo article_date();
        if (my_article_has_comments()) {
            ?>
, and it’s got <?php 
            echo my_article_total_comments() . pluralise(my_article_total_comments(), ' comment');
            ?>
 for now.<?php 
        }
        ?>
.</p>
				</article>
			</li>
			<?php 
    }
    ?>

			<?php 
    /* posts(); ?>
    			<li>
    				<article class="wrap">