Files
selima-perl/lib/php/monica/news.inc.php
2026-03-10 21:31:43 +08:00

113 lines
2.8 KiB
PHP

<?php
// File name: news.inc.php
// Description: PHP subroutines to handle news
// Date: 2006-03-17
// Author: imacat <imacat@pristine.com.tw>
// Copyright: Copyright (C) 2006-2007 Pristine Communications
// Set the include path
if (!defined("INCPATH_SET")) {
require_once dirname(__FILE__) . "/incpath.inc.php";
}
// Referenced subroutines
require_once "monica/chkfunc.inc.php";
require_once "monica/commtext.inc.php";
require_once "monica/getlang.inc.php";
require_once "monica/lninfo.inc.php";
require_once "monica/sql.inc.php";
// news_title: Obtain the news article title
function news_title($sn)
{
// Cache the result
static $cache = array();
// Bounce if there is any problem with $sn
if (is_null($sn)) {
return t_notset();
}
// Return the cache
if (array_key_exists($sn, $cache)) {
return $cache[$sn];
}
// Check the serial number first
if (!check_sn($sn)) {
$cache[$sn] = t_na();
return $cache[$sn];
}
// Query
$lndb = getlang(LN_DATABASE);
// Default language
if (getlang() == DEFAULT_LANG) {
$title = sql_strcat("to_char(date, 'YYYY-MM-DD')", "' '",
"title_$lndb") . " AS title";
// Fall back to the default language
} else {
$lndbdef = ln(DEFAULT_LANG, LN_DATABASE);
$title = sql_strcat("to_char(date, 'YYYY-MM-DD')", "' '",
"COALESCE(title_$lndb, title_$lndbdef)") . " AS title";
}
$select = "SELECT $title FROM news"
. " WHERE sn=$sn;\n";
$result = sql_query($select);
// Not found
if (sql_num_rows($result) != 1) {
$cache[$sn] = t_na();
return $cache[$sn];
}
// Found
$row = sql_fetch_assoc($result);
$cache[$sn] = $row["title"];
return $cache[$sn];
}
// news_id: Obtain the news article ID.
function news_id($sn)
{
// Cache the result
static $cache = array();
// Bounce if there is any problem with $sn
if (is_null($sn)) {
return t_notset();
}
// Return the cache
if (array_key_exists($sn, $cache)) {
return $cache[$sn];
}
// Check the serial number first
if (!check_sn($sn)) {
$cache[$sn] = t_na();
return $cache[$sn];
}
// Query
$select = "SELECT date, ord FROM news"
. " WHERE sn=$sn;\n";
$result = sql_query($select);
// Not found
if (sql_num_rows($result) != 1) {
$cache[$sn] = t_na();
return $cache[$sn];
}
// Found
$row = sql_fetch_assoc($result);
$cache[$sn] = newsid_compose($row["date"], $row["ord"]);
return $cache[$sn];
}
// newsid_compose: Compose the news article ID
function newsid_compose($date, $ord)
{
return date("Ymd", strtotime($date)) . sprintf("%02d", $ord);
}
?>