<?php
/****************************************************************************
* DRBImageGallery
* http://www.dbscripts.net/imagegallery/
*
* Copyright (c) 2007-2009 Don Barnes
****************************************************************************/
$dbs_error = NULL;
$TEMPLATE_NAME = "default";
function include_from_template($filename) {
global $TEMPLATE_NAME;
require(dirname(__FILE__) . '/../template/' . $TEMPLATE_NAME . '/' . $filename);
}
function path_to_file_from_template($filename) {
global $TEMPLATE_NAME;
global $base_url;
return $base_url . 'template/' . $TEMPLATE_NAME . '/' . $filename;
}
function relative_location($relativeURI) {
$baseURL = base_URL();
header("Location: $baseURL/$relativeURI");
}
function base_URL() {
$domain = $_SERVER['HTTP_HOST'];
$baseURI = rtrim(dirname($_SERVER['PHP_SELF']), '\\/');
// Work around for sites using sub directory hosting
if(substr($baseURI, 0, strlen("/" . $domain . "/")) === "/" . $domain . "/") {
$baseURI = substr($baseURI, strlen("/" . $domain . "/"));
}
return "http://$domain$baseURI";
}
function get_file_extension($filepath) {
$lastdot = strrpos($filepath, ".");
if($lastdot === FALSE) {
return FALSE;
}
$filetype = strtolower(substr($filepath, $lastdot + 1));
return $filetype;
}
function replace_file_extension($filepath, $newext) {
$lastdot = strrpos($filepath, ".");
if($lastdot === FALSE) {
return FALSE;
}
return substr($filepath, 0, $lastdot + 1) . $newext;
}
function validate_length($assoc, $key, $maxlen) {
global $dbs_error;
if(isset($assoc[$key]) && strlen($assoc[$key]) > $maxlen) {
$dbs_error = "The " . htmlspecialchars_default($key) . " field cannot accept values over " . htmlspecialchars_default($maxlen) . " characters in length.";
return FALSE;
}
return TRUE;
}
function validate_notempty($assoc, $key, $name = NULL) {
global $dbs_error;
if(isset($assoc[$key]) && empty($assoc[$key])) {
if(!isset($name)) $name = $key;
$dbs_error = "The " . htmlspecialchars_default($name) . " field is required.";
return FALSE;
}
return TRUE;
}
function confirm_install() {
// Confirm that install script has been deleted
if(file_exists(dirname(__FILE__) . '/../install.php')) {
global $base_url;
die("You must complete the <a href=\"{$base_url}install.php\">install process</a> before using the application. If you have already completed the install process, please delete install.php at this time.");
}
// Confirm that default password was changed
global $ADMIN_PASSWORD;
if($ADMIN_PASSWORD === "password") {
die("You must change the default admin password in config.php before using the application.");
}
}
function the_site_title() {
global $SITE_TITLE;
echo htmlspecialchars_default($SITE_TITLE);
}
function htmlspecialchars_default($value) {
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
/* DO NOT REMOVE OR HIDE THE CREDIT BELOW, PER LICENSE! */
function the_credits() {
echo("<div class=\"credit\">Powered by DRBImageGallery · <a href=\"http://www.dbscripts.net/hosting/\">PHP Hosting</a> · <a href=\"http://www.dbscripts.net/\">PHP Scripts</a></div>\n");
}
/* END CREDIT */
?>