Initial commit.

This commit is contained in:
2026-03-10 21:25:26 +08:00
commit 78739bf725
3089 changed files with 472990 additions and 0 deletions

View File

@@ -0,0 +1,384 @@
<?php
// File name: links.inc.php
// Description: PHP subroutines to display custom HTTP status messages
// Date: 2004-09-23
// Author: imacat <imacat@pristine.com.tw>
// Copyright: Copyright (C) 2004-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/echoform.inc.php";
require_once "monica/getlang.inc.php";
require_once "monica/gettext.inc.php";
require_once "monica/lninfo.inc.php";
require_once "monica/sql.inc.php";
// linkcat_title: Obtain a link category title
function linkcat_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
// Unilingual
if (count($GLOBALS["ALL_LINGUAS"]) == 1) {
$col = "linkcat_fulltitle(parent, title) AS title";
// Multilingual
} else {
$thiscol = "title_" . getlang(LN_DATABASE);
$lang = getlang();
// Default language
if ($lang == DEFAULT_LANG) {
$col = "linkcat_fulltitle('$lang', parent, $thiscol) AS title";
// Fall back to the default language
} else {
$defcol = "title_" . ln(DEFAULT_LANG, LN_DATABASE);
$col = "linkcat_fulltitle('$lang', parent, COALESCE($thiscol, $defcol)) AS title";
}
}
$select = "SELECT $col FROM linkcat 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];
}
// linkcat_path: Obtain a link category path
function linkcat_path($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 linkcat_path(sn, id, parent) AS path FROM linkcat"
. " 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["path"];
$cache[$sn] = preg_replace("/(?:\/|\.html)$/", "", $cache[$sn]);
return $cache[$sn];
}
// linkcat_options: Obtain a link category options list
function linkcat_options($value)
{
// Unilingual
if (count($GLOBALS["ALL_LINGUAS"]) == 1) {
$content = "linkcat_fulltitle(parent, title) AS content";
// Multilingual
} else {
$thiscol = "title_" . getlang(LN_DATABASE);
$lang = getlang();
// Default language
if ($lang == DEFAULT_LANG) {
$content = "linkcat_fulltitle('$lang', parent, $thiscol) AS content";
// Fall back to the default language
} else {
$defcol = "title_" . ln(DEFAULT_LANG, LN_DATABASE);
$content = "linkcat_fulltitle('$lang', parent, COALESCE($thiscol, $defcol)) AS content";
}
}
$select = "SELECT sn AS value, $content FROM linkcat"
. " ORDER BY linkcat_fullord(parent, ord);\n";
return opt_list($select, $value);
}
// link_title: Obtain a link title
function link_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
// Unilingual
if (count($GLOBALS["ALL_LINGUAS"]) == 1) {
$col = "title";
// Multilingual
} else {
$thiscol = "title_" . getlang(LN_DATABASE);
// Default language
if (getlang() == DEFAULT_LANG) {
$col = "$thiscol AS title";
// Fall back to the default language
} else {
$defcol = "title_" . ln(DEFAULT_LANG, LN_DATABASE);
$col = "COALESCE($thiscol, $defcol) AS title";
}
}
$select = "SELECT $col FROM links 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];
}
// link_url: Obtain a link URL.
function link_url($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 url FROM links 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["url"];
return $cache[$sn];
}
// links_shown_parts: Obtain the shown links parts
function links_shown_parts()
{
$r = array();
// Obtain the shown categories
$path = "linkcat_path(sn, id, parent) AS path";
$select = "SELECT sn, $path FROM linkcat"
. " WHERE linkcat_isshown(sn, hid, parent)"
. " ORDER BY linkcat_fullord(parent, ord);\n";
$result = sql_query($select);
$count = sql_num_rows($result);
for ($i = 0, $r["catspath"] = array(), $r["cats"] = array(); $i < $count; $i++) {
$row = sql_fetch_assoc($result);
$r["cats"][] = $row["sn"];
$r["catspath"][] = $row["path"];
}
sort($r["cats"]);
sort($r["catspath"]);
return $r;
}
/////////////////////////
// Subroutines about link categories
/////////////////////////
// link_tree_full: Get the full page tree of the links
function link_tree_full($lang, $preview = null)
{
// Cache the result
static $cache = array();
// Return the cache
if (array_key_exists($lang, $cache)) {
return $cache[$lang];
}
// Initialize the result
$tree = array();
$lnpref = (count($GLOBALS["ALL_LINGUAS"]) == 1)?
"": "/" . ln($lang, LN_FILENAME);
$tree["index"] = array(
"path" => "$lnpref/links/",
"_path" => "/links/",
"title" => C_("Related Links"),
);
// Get the link tree
$pages =& _link_subtree("/links", null, $lang, $preview);
if (!is_null($pages)) {
$tree["pages"] =& $pages;
}
return $tree;
}
// _link_subtree: Get the page subtree of the links
function &_link_subtree($path, $parent, $lang, $preview = null)
{
// Set the language
$lndb = ln($lang, LN_DATABASE);
$langfile = ln($lang, LN_FILENAME);
// Check if there is any link below this category
$has_links = false;
if (!is_null($parent)) {
$select = "SELECT links.sn FROM links"
. " INNER JOIN linkcatz ON linkcatz.link=links.sn"
. " WHERE linkcatz.cat=$parent"
. " AND " . sql_is_false("links.hid")
. " LIMIT 1;\n";
$result = sql_query($select);
$has_links = (sql_num_rows($result) > 0);
// Check the preview
if (!$has_links && !is_null($preview)) {
$has_links = in_array($parent, $preview["cats"]);
}
}
// Obtain the subcategories
$cols = array();
$cols[] = "sn AS sn";
$cols[] = "id AS id";
if (count($GLOBALS["ALL_LINGUAS"]) > 1) {
if ($lang == DEFAULT_LANG) {
$cols[] = "title_$lndb AS title";
} else {
$lndbdef = ln(DEFAULT_LANG, LN_DATABASE);
$cols[] = "COALESCE(title_$lndb, title_$lndbdef)"
. " AS title";
}
} else {
$cols[] = "title AS title";
}
$cols[] = "ord AS ord";
$conds = array();
if (is_null($parent)) {
$conds[] = "parent IS NULL";
} else {
$conds[] = "parent=$parent";
}
$conds[] = sql_is_false("hid");
if (!is_null($preview) && array_key_exists("sn", $preview)) {
$conds[] = "sn!=" . $preview["sn"];
}
$select = "SELECT " . implode(", ", $cols) . " FROM linkcat"
. " WHERE " . implode(" AND ", $conds)
. " ORDER BY ord;\n";
$result = sql_query($select);
$count = sql_num_rows($result);
$lnpref = (count($GLOBALS["ALL_LINGUAS"]) == 1)?
"": "/" . ln($lang, LN_FILENAME);
for ($i = 0, $pages = array(); $i < $count; $i++) {
$row = sql_fetch_assoc($result);
$subpages =& _link_subtree($path . "/" . $row["id"],
$row["sn"], $lang, $preview);
// Only create subtree that has some content
if (!is_null($subpages)) {
// No subcategories -- create it as a ".html" page
if (count($subpages) == 0) {
$subpath = $path . "/" . $row["id"] . ".html";
$pages[] = array(
"path" => $lnpref . $subpath,
"_path" => $subpath,
"title" => $row["title"],
"ord" => $row["ord"],
);
// There are subcatgories -- create it as a directory
} else {
$subpath = $path . "/" . $row["id"] . "/";
$pages[] = array(
"path" => $lnpref . $subpath,
"_path" => $subpath,
"title" => $row["title"],
"ord" => $row["ord"],
"sub" => array(
"index" => array(
"path" => $lnpref . $subpath,
"_path" => $subpath,
"title" => $row["title"],
),
"pages" => $subpages,
),
);
}
}
}
// No content below
if (!$has_links && count($pages) == 0) {
$pages = null;
return $pages;
}
return $pages;
}
?>