Write the pager page size in words without PEAR.

This commit is contained in:
tim
2026-09-25 22:32:11 +02:00
parent 589ae4c1fa
commit aee8a830d7
+29 -5
View File
@@ -1,8 +1,33 @@
<?php
require_once('open_db.lib.php');
require_once("get_data.lib.php");
if (stream_resolve_include_path("Numbers/Words.php"))
include_once("Numbers/Words.php");
/*
* Return a whole number in English words, for example 25 => "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 = '<div class="pager">';
$nw = class_exists('Numbers_Words') ? new Numbers_Words() : NULL;
// Are there later stories? Go backwards to them
$string .= '<span class="next">';
if ($start > 0) {
@@ -75,7 +99,7 @@ function get_pager() {
if (isset($_GET['show'])) $string .= '&amp;show='.(int)$show;
if (isset($_GET['sort'])) $string .= '&amp;sort='.$sort;
if (isset($_GET['order'])) $string .= '&amp;order='.$order;
$articles = ($show == 1) ? "article" : ($nw ? $nw->toWords((int)$show) : (int)$show)." articles";
$articles = ($show == 1) ? "article" : number_words($show)." articles";
$string .= '">&laquo; Next '.$articles.'</a>';
}
$string .= "</span>\n";
@@ -89,7 +113,7 @@ function get_pager() {
if (isset($_GET['show'])) $string .= '&amp;show='.(int)$show;
if (isset($_GET['sort'])) $string .= '&amp;sort='.$sort;
if (isset($_GET['order'])) $string .= '&amp;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.' &raquo;</a>';
}
$string .= "</span>\n";