Beispiel #1
0
/**
 * Make a timestamp into a relative string
 *
 * @todo Tidy up and move out of this file.
 * Based on Garrett Murray's code from http://graveyard.maniacalrage.net/etc/relative/
 */
function relative_time($posted_date)
{
    $in_seconds = $posted_date;
    $diff = time() - $in_seconds;
    $months = floor($diff / 2592000);
    $diff -= $months * 2419200;
    $weeks = floor($diff / 604800);
    $diff -= $weeks * 604800;
    $days = floor($diff / 86400);
    $diff -= $days * 86400;
    $hours = floor($diff / 3600);
    $diff -= $hours * 3600;
    $minutes = floor($diff / 60);
    $diff -= $minutes * 60;
    $seconds = $diff;
    if ($months > 0) {
        return sprintf(_c('on %s', 'on <date>'), date('N, jS \\o\\f F, Y'));
    }
    switch (true) {
        case $weeks > 0:
            // weeks and days
            $week = sprintf(Locale::ngettext('%d week', '%d weeks', $weeks), $weeks);
            if ($days > 0) {
                $day = sprintf(Locale::ngettext('%d day', '%d days', $days), $days);
                $relative_date = sprintf(_c('%s, %s ago', 'relative time, "x weeks, x days ago"'), $week, $day);
            } else {
                $relative_date = sprintf(_c('%s ago', 'relative time, "x weeks ago"'), $week);
            }
            break;
        case $days > 0:
            // days and hours
            $day = sprintf(Locale::ngettext('%d day', '%d days', $days), $days);
            if ($hours > 0) {
                $hour = sprintf(Locale::ngettext('%d hour', '%d hours', $hours), $hours);
                $relative_date = sprintf(_c('%s, %s ago', 'relative time, "x days, x hours ago"'), $day, $hour);
            } else {
                $relative_date = sprintf(_c('%s ago', 'relative time, "x days ago"'), $day);
            }
            break;
        case $hours > 0:
            // hours and minutes
            $hour = sprintf(Locale::ngettext('%d hour', '%d hours', $hours), $hours);
            if ($minutes > 0) {
                $minute = sprintf(Locale::ngettext('%d minute', '%d minutes', $minutes), $minutes);
                $relative_date = sprintf(_c('%s, %s ago', 'relative time, "x hours, x minutes ago"'), $hour, $minute);
            } else {
                $relative_date = sprintf(_c('%s ago', 'relative time, "x hours ago"'), $hour);
            }
            break;
        case $minutes > 0:
            // minutes only
            return sprintf(Locale::ngettext('%d minute ago', '%d minutes ago', $minutes), $minutes);
            break;
        case $seconds > 0:
            // seconds only
            return sprintf(Locale::ngettext('%d second ago', '%d seconds ago', $seconds), $seconds);
            break;
    }
    return $relative_date;
}
 /**
  * Parse feeds into an array, ready to pass to the Javascript importer
  *
  * @param string $opml OPML standard file.
  * @return array Associative array containing feed URL, title and category (if applicable)
  */
 protected function import_opml($opml)
 {
     if (empty($opml)) {
         throw new Exception(_r('No OPML specified'));
         return false;
     }
     $opml = new OPMLParser($opml);
     if (!empty($opml->error) || empty($opml->data)) {
         throw new Exception(sprintf(_r('The OPML file could not be read. The parser said: %s'), $opml->error));
         return false;
     }
     $feeds_num = 0;
     foreach ($opml->data as $cat => $feed) {
         if (!isset($feed['xmlurl']) && isset($feed[0]['xmlurl'])) {
             foreach ($feed as $subfeed) {
                 $feeds[] = array('url' => $subfeed['xmlurl'], 'title' => $subfeed['title'], 'cat' => $cat);
                 ++$feeds_num;
             }
             continue;
         }
         $feeds[] = array('url' => $feed['xmlurl'], 'title' => $feed['title'], 'cat' => '');
         ++$feeds_num;
     }
     MessageHandler::add(sprintf(Locale::ngettext('Adding %d feed', 'Adding %d feeds', $feeds_num), $feeds_num));
     return $feeds;
 }
Beispiel #3
0
 /**
  * Parse feeds into an array, ready to pass to the Javascript importer
  *
  * @param string $opml OPML standard file.
  * @return array Associative array containing feed URL, title and category (if applicable)
  */
 protected function import_opml($opml)
 {
     if (empty($opml)) {
         throw new Exception(_r('No OPML specified'));
         return false;
     }
     $opml = new OPMLParser($opml);
     if (!empty($opml->error) || empty($opml->data)) {
         throw new Exception(sprintf(_r('The OPML file could not be read. The parser said: %s'), $opml->error));
         return false;
     }
     $feeds_num = 0;
     $feeds = $this->parse($opml->data);
     MessageHandler::add(sprintf(Locale::ngettext('Adding %d feed', 'Adding %d feeds', $feeds_num), $feeds_num));
     return $feeds;
 }
/**
 * Display a translated string
 *
 * __ngettext() is a convenience function which displays the returned
 * translated text from Locale::ngettext().
 *
 * @see Locale::ngettext() Echos returned Locale::ngettext() string
 * @since 1.0
 *
 * @param string $single The text that will be used if $number is 1
 * @param string $plural The text that will be used if $number is not 1
 * @param int $number The number to compare against to use either $single or $plural
 * @param string $domain Optional. The domain identifier the text should be retrieved in
 * @return string Either $single or $plural translated text
 */
function __ngettext($single, $plural, $number, $domain = 'default')
{
    echo Locale::ngettext($single, $plural, $number, $domain);
}
Beispiel #5
0
 protected function cron()
 {
     set_time_limit(0);
     ItemUpdater::set_feeds(Feeds::get_instance()->getAll());
     ItemUpdater::$fatal = false;
     foreach (ItemUpdater::process() as $feed => $updated) {
         $name = Feeds::get_instance()->get($feed);
         $name = $name['name'];
         if ($updated < 0) {
             $text = 'An error occurred while updating feed "%1$s".';
         } else {
             $text = Locale::ngettext('Updated feed "%1$s". Added %2$d item.', 'Updated feed "%1$s". Added %2$d items.', $updated);
         }
         $messages[] = array('msg' => sprintf($text, $name, $updated), 'updated' => $updated);
     }
     if (isset($_GET['output'])) {
         return array('success' => 1, 'msgs' => $messages);
     } else {
         die;
     }
 }