mirror of
https://git.code.sf.net/p/quake/website
synced 2025-03-14 05:30:42 +00:00
PHP 7 doesn't like the old short tags we were using (it's possible to re-enable them, but won't be for version 8, so we might as well switch now), and the old MySQL APIs are now gone entirely, replaced with something different. This should make everything work at least as well as it used to. Also, one file used to be checked in with CRLF line endings. ??
99 lines
1.7 KiB
PHP
99 lines
1.7 KiB
PHP
<?php
|
|
if (!defined ('_ARRAY_')) { // Treat array handler special
|
|
define ('_ARRAY_', 1);
|
|
|
|
/*
|
|
inArray
|
|
|
|
Search an array for data
|
|
*/
|
|
function inArray ($needle, $haystack)
|
|
{
|
|
$found = false;
|
|
|
|
for ($ptr = 0; $ptr < count ($haystack); $ptr++) {
|
|
if ($haystack[$ptr] == $needle) {
|
|
$found = true;
|
|
}
|
|
}
|
|
return $found;
|
|
}
|
|
|
|
/*
|
|
addToArray
|
|
|
|
Add an element to an array
|
|
*/
|
|
function addToArray ($var, &$arr)
|
|
{
|
|
if (!inArray ($var, $arr)) {
|
|
if (isset ($arr)) {
|
|
$arr[count ($arr)] = $var;
|
|
} else {
|
|
$arr = array ($var);
|
|
}
|
|
}
|
|
}
|
|
|
|
addToArray ('array', $has);
|
|
}
|
|
|
|
if (!defined ('_LIBFUNCS_')) {
|
|
define ('_LIBFUNCS_', 1);
|
|
|
|
/*
|
|
reqIfNeeded
|
|
|
|
Require a library module if it hasn't already been.
|
|
*/
|
|
function reqIfNeeded ($libNames)
|
|
{
|
|
global $has, $needs;
|
|
|
|
$libs = explode(' ', $libNames);
|
|
|
|
for ($i = 0 ; $i < count ($libs) ; $i++ ) {
|
|
$lib = $libs[$i];
|
|
if ((inArray ($libs[$i], $needs)) && (!inArray ($libs[$i], $has))) {
|
|
include siteHome . "/lib/$libs[$i].php";
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
have
|
|
|
|
Tell the library that module X is loaded
|
|
*/
|
|
function have ($libName)
|
|
{
|
|
global $has;
|
|
|
|
addToArray ($libName, $has);
|
|
}
|
|
|
|
/*
|
|
need
|
|
|
|
Load module X if it hasn't been already, taking care to retain the
|
|
integrity of the $needs array.
|
|
*/
|
|
function need ($libNames)
|
|
{
|
|
global $needs;
|
|
|
|
$libs = explode (' ', $libNames);
|
|
for ($i = 0; $i < count ($libs); $i++) {
|
|
addToArray ($libs[$i], $needs);
|
|
}
|
|
reqIfNeeded ($libNames);
|
|
}
|
|
|
|
// Actual code for the lib -- only one "$need" allowed from main system
|
|
if ($need) {
|
|
addToArray ($need, $needs);
|
|
include siteHome . "/lib/$need.php";
|
|
unset ($need);
|
|
}
|
|
} // !_LIBFUNCS_
|
|
?>
|