diff --git a/navigation.lib.php b/navigation.lib.php index 6c28cee..ff31b6d 100644 --- a/navigation.lib.php +++ b/navigation.lib.php @@ -1,8 +1,33 @@ "twenty-five" + * and 105 => "one hundred and five". This replaces the PEAR Numbers_Words package. + */ +function number_words($n) { + static $small = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', + 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', + 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'); + static $tens = array(2 => 'twenty', 'thirty', 'forty', 'fifty', 'sixty', + 'seventy', 'eighty', 'ninety'); + static $scales = array(1000000000 => 'billion', 1000000 => 'million', 1000 => 'thousand'); + + $n = (int)$n; + if ($n < 0) + return 'minus ' . number_words(-$n); + if ($n < 20) + return $small[$n]; + if ($n < 100) + return $tens[intdiv($n, 10)] . ($n % 10 ? '-' . $small[$n % 10] : ''); + if ($n < 1000) + return $small[intdiv($n, 100)] . ' hundred' . ($n % 100 ? ' and ' . number_words($n % 100) : ''); + foreach ($scales as $size => $name) { + if ($n >= $size) + return number_words(intdiv($n, $size)) . ' ' . $name . ($n % $size ? ($n % $size < 100 ? ' and ' : ' ') . number_words($n % $size) : ''); + } +} function sort_options($link) { $queue = get_queue(); @@ -65,7 +90,6 @@ function get_pager() { $queue_url = $queue ? 1 : 0; $string = '
'; - $nw = class_exists('Numbers_Words') ? new Numbers_Words() : NULL; // Are there later stories? Go backwards to them $string .= ''; if ($start > 0) { @@ -75,7 +99,7 @@ function get_pager() { if (isset($_GET['show'])) $string .= '&show='.(int)$show; if (isset($_GET['sort'])) $string .= '&sort='.$sort; if (isset($_GET['order'])) $string .= '&order='.$order; - $articles = ($show == 1) ? "article" : ($nw ? $nw->toWords((int)$show) : (int)$show)." articles"; + $articles = ($show == 1) ? "article" : number_words($show)." articles"; $string .= '">« Next '.$articles.''; } $string .= "\n"; @@ -89,7 +113,7 @@ function get_pager() { if (isset($_GET['show'])) $string .= '&show='.(int)$show; if (isset($_GET['sort'])) $string .= '&sort='.$sort; if (isset($_GET['order'])) $string .= '&order='.$order; - $articles = ($show == 1) ? "article" : ($nw ? $nw->toWords((int)$show) : (int)$show)." articles"; + $articles = ($show == 1) ? "article" : number_words($show)." articles"; $string .= '">Previous '.$articles.' »'; } $string .= "\n";