require_once("config.php");
if (get_magic_quotes_gpc() == 0)
die("magic_quotes_gpc in the INI file is OFF! Cannot continue.");
// TODO: this is duplicated from acl.php!
$ACL_ACCESS_NOBODY = 0;
$ACL_ACCESS_NOBODY_VERIFIED = 1;
$ACL_ACCESS_ADMIN_LOW = 2;
$ACL_ACCESS_ADMIN_HIGH = 3;
// Lookup table that matches ACL access numbers into readable text.
$ACL_LOOKUP = array($ACL_ACCESS_NOBODY => "Nobody",
$ACL_ACCESS_NOBODY_VERIFIED => "Nobody Verified",
$ACL_ACCESS_ADMIN_LOW => "Low access administrator",
$ACL_ACCESS_ADMIN_HIGH => "High access administrator");
// Checks if the current user is the Sooper-Dooper Administrator of the
// *entire* CMS (this is not ACL_ACCESS_ADMIN_HIGH).
function isAdminUser() {
if (isset($_SESSION['adminLoggedIn']) &&
($_SESSION['adminLoggedIn'] == true)) {
return true;
} else {
return false;
}
}
// Retrieves a persistent database connection.
function getDBConnection() {
global $DB_HOST;
global $DB_USERNAME;
global $DB_PASSWORD;
global $DB_NAME;
$db = mysql_pconnect($DB_HOST, $DB_USERNAME, $DB_PASSWORD);
$db_selected = mysql_select_db($DB_NAME);
if (!$db_selected) {
die("Error!");
}
return $db;
}
// Returns true if the specified input variable is good. 'Good' is defined
// as existing and set to a particular value (unless $emptyOK is true--then
// existing but empty variables will return true also).
function isVarGood($var, $emptyOK) {
$retVal = false;
if (isset($var)) {
if ($emptyOK == true)
$retVal = true;
else if (($emptyOK == false) && (strlen($var) > 0))
$retVal = true;
}
return $retVal;
}
// Displays a popup dialog box to the visiting user, then redirects them to
// a URL.
function popup_and_redirect($message, $URL) {
echo "
";
}
// TODO: implementation!
function normalizeString($title) {
return $title;
}
// TODO: fix this function & use it!
function beginTransaction($db) {
// $result = mysql_query("SET AUTOCOMMIT=0", $db);
// if (!$result)
// die("Error while starting transaction!");
$result = mysql_query("BEGIN", $db);
if (!$result)
die("Error while starting transaction!");
}
// TODO: fix this function & use it!
function commitTransaction($db) {
$result = mysql_query("COMMIT", $db);
if (!$result)
die("Error while committing transaction!");
// $result = mysql_query("SET AUTOCOMMIT=1", $db);
// if (!$result)
// die("Error while committing transaction!");
}
// TODO: fix this function & use it!
function rollbackTransaction($db) {
$result = mysql_query("ROLLBACK", $db);
if (!$result)
die("Error while rolling back transaction!");
// $result = mysql_query("SET AUTOCOMMIT=1", $db);
// if (!$result)
// die("Error while rolling back transaction!");
}
// Logs a message to the log file, specified in config.php. Useful for
// debugging purposes.
function my_log($message) {
global $LOG_FILE;
if (!($hFile = fopen($LOG_FILE, "a")))
die("Error while opening log file!");
fwrite($hFile, $message);
fclose($hFile);
}
// Extracts and returns text in between two tags. Example:
// extractBetweenTags("yo");
// ... returns the text "yo".
function extractBetweenTags($str, $beginTag, $endTag) {
$beginPos = strpos($str, $beginTag);
if ($beginPos === FALSE) {
return "";
}
$endPos = strpos($str, $endTag);
if ($endPos === FALSE) {
return "";
}
$contentLen = $endPos - ($beginPos + strlen($beginTag));
return substr($str, $beginPos + strlen($beginTag), $contentLen);
}
// Given a filename in the form of "language/title.html", returns back "title".
function getTitleFromFile($file) {
$lastPos = strrpos($file, "/");
if ($lastPos == FALSE) { die("Invalid file path: " . $file); }
$title = substr($file, $lastPos + 1);
return substr($title, 0, strlen($title) - 5);
}
// Escapes certain characters so that they are displayable in HTML.
function htmlize($str) {
$str = str_replace("<", "<", $str);
$str = str_replace(">", ">", $str);
$str = str_replace("\n", "
", $str);
$str = str_replace(" ", " ", $str);
return $str;
}
// Reverses the escaping done by htmlize().
function dehtmlize($str) {
$str = str_replace(" ", " ", $str);
$str = str_replace("
", "\n", $str);
$str = str_replace("<", "<", $str);
$str = str_replace(">", ">", $str);
return $str;
}
?>