Files
xxx/navigation.lib.php

123 lines
4.5 KiB
PHP

<?php
require_once('open_db.lib.php');
require_once("get_data.lib.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();
$search = get_search_args();
$sort = get_sort_arg();
$order = get_order();
$start = get_start_num();
$show = get_show_num();
$which_sort = array(
'date' => 'date',
'author' => 'author',
'title' => 'title',
);
$which_order = array(
'asc' => '',
'desc' => 'z-a',
);
$options = array();
foreach ($which_sort as $sort_key=>$sort_value) {
foreach ($which_order as $order_key=>$order_value) {
if ($sort_key == 'date')
$order_value = ($order_key == 'asc') ? '' : 'descending' ;
$display = '<span>' . $sort_value;
$display .= $order_value ? " " . $order_value : "";
$display .= '</span>';
if ($sort == $sort_key && $order == $order_key) {
array_push($options, $display);
} else {
$href = '<a href="'.$link.'?sort='.$sort_key.'&amp;order='.$order_key;
if (isset($_GET['queue'])) $href .= '&amp;queue='.($queue ? 1 : 0);
if (isset($_GET['search'])) $href .= '&amp;search='.urlencode((string)$search);
if (isset($_GET['start'])) $href .= '&amp;start='.(int)$start;
if (isset($_GET['show'])) $href .= '&amp;show='.(int)$show;
$href .= '">'.$display.'</a>';
array_push($options, $href);
}
}
}
$string = '<div class="options">Sort by: ' . implode(' <span class="bar">|</span> ', $options) . '</div>'."\n";
return $string;
}
function get_pager() {
global $editable;
$queue = get_queue();
$search = get_search_args();
$sort = get_sort_arg();
$order = get_order();
$start = get_start_num();
$show = get_show_num();
$prev = $start+$show;
$next = $start-$show;
// If next is less than 0, make sure we can see the next stories
if ($next < 0) $next = 0;
$link = $editable ? "" : "/article";
$queue_url = $queue ? 1 : 0;
$string = '<div class="pager">';
// Are there later stories? Go backwards to them
$string .= '<span class="next">';
if ($start > 0) {
$string .= "\n".'<a href="'.$link.'?start='.(int)$next;
if (isset($_GET['queue'])) $string .= '&amp;queue='.$queue_url;
if (isset($_GET['search'])) $string .= '&amp;search='.urlencode((string)$search);
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" : number_words($show)." articles";
$string .= '">&laquo; Next '.$articles.'</a>';
}
$string .= "</span>\n";
// Are there earlier stories? Go forwards to them
$string .= "\n".'<span class="prev">';
if ($prev < get_count()) {
$string .= "\n".'<a href="'.$link.'?start='.(int)$prev;
if (isset($_GET['queue'])) $string .= '&amp;queue='.$queue_url;
if (isset($_GET['search'])) $string .= '&amp;search='.urlencode((string)$search);
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" : number_words($show)." articles";
$string .= '">Previous '.$articles.' &raquo;</a>';
}
$string .= "</span>\n";
$string .= "</div>\n";
return $string;
}