Any help is appreciated!
This is the full code
Code: Select all
<?php
$username = "*****"; // Your preferred username.
$password = "*****"; // Your preferred password.
$path = "images/"; /* This is the path to the folder with the images. */
$xmlfile = "data.xml"; /* The path to the XML data file. */
$phpfile = "gallery.php"; /* The file used in links. */
$maxsize = 200000000; /* Max file size in bytes. */
$limit = 30; /* The limit when displaying descriptions in the administration. */
$allowedfiles = array("jpg", "gif", "png", "jpeg"); /* The types of images allowed for upload. */
$enableThumbnails = TRUE; /* TRUE is you want to enable thumbnails, FALSE if you don't. FALSE is default to save system resources. You can enable this at any time. */
$thumbnailwidth = 150; /* The width of the thumbnail in pixels or percent. Height will be calculated accordingly. */
$thumbnailquality = 100; /* Thumbnail quality. 100 is the highest, 0 is the lowest. Only applies to JPG images. */
/* End setup */
/* #########################################
#### BEGIN PUBLIC GALLERY FUNCTIONS. ####
######################################### */
function displayTitle($id) {
global $title;
echo $title[$id];
}
function displayImage($id, $type = "full") {
global $description, $path, $name;
if ($type == "thumbnail") {
$imgpath = "{$path}thumbs/{$name[$id]}";
} else {
$imgpath = "{$path}{$name[$id]}";
}
$img = @getimagesize($imgpath);
echo "<img src=\"{$imgpath}\" width=\"{$img[0]}\" height=\"{$img[1]}\" alt=\"{$description[$id]}\" />";
}
function displayRandomImage($phpfile, $type = "full") {
global $description, $path, $name;
srand((float) microtime() * 10000000);
$id = array_rand($name, 1);
if ($type == "thumbnail") {
$imgpath = "{$path}thumbs/{$name[$id]}";
} else {
$imgpath = "{$path}{$name[$id]}";
}
$img = @getimagesize($imgpath);
echo "<a href=\"{$phpfile}?id={$id}\"><img src=\"{$imgpath}\" width=\"{$img[0]}\" height=\"{$img[1]}\" alt=\"{$description[$id]}\" /></a>";
}
function displayDescription($id) {
global $description;
echo "{$description[$id]}";
}
function displayCategories($phpfile) {
global $categories, $category, $name, $cat;
for ($i=0;$i<count($categories);$i++) {
UnSet($antal);
for ($z=0;$z<count($name);$z++) {
if ($cat[$z] == $i) {
$antal++;
}
}
if (IsSet($category) && $i == $category) {
echo "<li class=\"current\">{$categories[$i]} ({$antal})</li>";
} else {
echo "<li><a href=\"{$phpfile}?category={$i}\">{$categories[$i]} ({$antal})</a></li>";
}
}
}
function displayCategory($id) {
global $category, $categories;
if (IsSet($category)) {
echo $categories[$id];
} else {
echo "All Photos";
}
}
function displayList($phpfile, $linktitle = "number") {
global $name, $id, $category, $cat, $title, $path;
for ($i=0;$i<count($name);$i++) {
if ($i == $id) {
if ($linktitle == "thumbnail") {
$size = @getimagesize("{$path}thumbs/{$name[$id]}");
echo "<li class=\"current\"><img src=\"{$path}thumbs/{$name[$id]}\" alt=\"{$title[$i]}\" {$size[3]} /></li>";
} elseif ($linktitle == "number") {
echo "<li class=\"current\">{$i}</li>";
} else {
echo "<li class=\"current\">{$title[$i]}</li>";
}
} else {
if (IsSet($category)) {
if ($category == $cat[$i]) {
if ($linktitle == "thumbnail") {
$size = @getimagesize("{$path}thumbs/{$name[$i]}");
echo "<li><a href=\"{$phpfile}?id={$i}&category={$category}\"><img src=\"{$path}thumbs/{$name[$i]}\" alt=\"{$title[$i]}\" {$size[3]} /></a></li>";
} elseif ($linktitle == "number") {
echo "<li><a href=\"{$phpfile}?id={$i}&category={$category}\">{$i}</a></li>";
} else {
echo "<li><a href=\"{$phpfile}?id={$i}&category={$category}\">{$title[$i]}</a></li>";
}
}
} else {
if ($linktitle == "thumbnail") {
$size = @getimagesize("{$path}thumbs/{$name[$i]}");
echo "<li><a href=\"{$phpfile}?id={$i}\"><img src=\"{$path}thumbs/{$name[$i]}\" alt=\"{$title[$i]}\" {$size[3]} /></a></li>";
} elseif ($linktitle == "number") {
echo "<li><a href=\"{$phpfile}?id={$i}\">{$i}</a></li>";
} else {
echo "<li><a href=\"{$phpfile}?id={$i}\">{$title[$i]}</a></li>";
}
}
}
}
}
function displayNextCategory($category, $phpfile, $linktitle) {
global $categories;
if (is_array($categories) && count($categories) > 1) {
if (!IsSet($category)) {
echo "<a href=\"{$phpfile}?category=0\">{$linktitle}</a>";
} else {
$nextid = $category+1;
if (IsSet($categories[$nextid])) {
echo "<a href=\"{$phpfile}?category={$nextid}\">{$linktitle}</a>";
} else {
echo "<a href=\"{$phpfile}?category=0\">{$linktitle}</a>";
}
}
}
}
function displayPrevCategory($category, $phpfile, $linktitle) {
global $categories;
if (is_array($categories) && count($categories) > 1) {
if (!IsSet($category) || $category == 0) {
// Get last category.
end($categories);
$previd = each($categories);
$previd = $previd["key"];
reset($categories);
echo "<a href=\"{$phpfile}?category={$previd}\">{$linktitle}</a>";
} else {
$previd = $category-1;
echo "<a href=\"{$phpfile}?category={$previd}\">{$linktitle}</a>";
}
}
}
function displayNextLink($id, $phpfile, $linktitle) {
global $name, $category, $cat;
if (!IsSet($category)) {
if ($id == count($name)-1) {
$nextid = 0;
} else {
$nextid = $id+1;
}
} else {
for ($i=0;$i<count($name);$i++) {
if ($category == $cat[$i]) {
$nextidarr[] = $i;
}
}
ksort($nextidarr);
reset($nextidarr);
foreach ($nextidarr as $key => $value) {
if ($value == $id) {
if(next($nextidarr)) {
$nextid = each($nextidarr);
} else {
reset($nextidarr);
$nextid = each($nextidarr);
}
$nextid = "{$nextid["value"]}&category={$category}";
break;
}
next($nextidarr);
}
}
echo "<a href=\"{$phpfile}?id={$nextid}\">$linktitle</a>";
}
function displayPrevLink($id, $phpfile, $linktitle) {
global $name, $category, $cat;
if (!IsSet($category)) {
if ($id == 0) {
$previd = count($navn)-1;
} else {
$previd = $id-1;
}
} else {
for ($i=0;$i<count($name);$i++) {
if ($category == $cat[$i]) {
$previdarr[] = $i;
}
}
ksort($previdarr);
reset($previdarr);
foreach ($previdarr as $key => $value) {
if ($value == $id) {
if ($key == 0) {
end($previdarr);
$previd = each($previdarr);
$previd = "{$previd["value"]}&category={$category}";
break;
} else {
prev($previdarr);
$previd = each($previdarr);
$previd = "{$previd["value"]}&category={$category}";
break;
}
}
next($previdarr);
}
}
echo "<a href=\"{$phpfile}?id={$previd}\">$linktitle</a>";
}
/* ##############################################################################
#### FUNCTIONS & SETTINGS USED BY BOTH PUBLIC GALLERY AND ADMINISTRATION. ####
############################################################################## */
$self = basename($_SERVER["PHP_SELF"]);
function parseFile($xmlfile, $start, $end, $cdata) { /* This function parses the xml data file. */
global $xml_parser;
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, $start, $end);
xml_set_character_data_handler($xml_parser, $cdata);
$fp = @fopen($xmlfile, "r") or die("Cannot locate XML data file: {$xmlfile}");
while ($data = fread($fp, filesize($xmlfile))) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
}
function startImages($parser, $name, $a) { /* This function is executed everytime an xml start tag is met. */
global $currentTag, $imgId, $cId;
$currentTag = strtolower($name);
if ($currentTag == "image") {
$imgId = $a["ID"];
} elseif ($currentTag == "category") {
$cId = $a["CID"];
}
}
function imgData($parser, $data) { /* This function is executed on all xml content. */
global $currentTag, $imgId, $name, $title, $description, $cat, $categories, $cId;
switch($currentTag) {
case "file" :
$name[$imgId] = $data;
break;
case "title" :
$title[$imgId] = $data;
break;
case "description" :
$description[$imgId] = $data;
break;
case "imgcategory" :
$cat[$imgId] = $data;
break;
case "category" :
$categories[$cId] = $data;
break;
default :
break;
}
}
function endElement($parser, $name) { /* This function is executed everytime an xml end tag is met. */
global $currentTag, $status;
$currentTag = "";
}
// The XML file is parsed and the content is put into arrays so we can access it easily later.
parseFile($xmlfile, "startImages", "endElement", "imgData");
// For the public gallery we set the id and category variables if they haven't been set in the URL.
if (!IsSet($_GET["id"]) || $_GET["id"] == "") {
$id = 0;
} else {
$id = $_GET["id"];
}
// If no category is set in the URL we unset the $category variable.
if (!IsSet($_GET["category"]) || $_GET["category"] == "") {
UnSet($category);
} else {
$category = $_GET["category"];
if ($category != $cat[$id]) {
for($i=0;$i<count($name);$i++) {
if ($category == $cat[$i]) {
$id = $i;
break;
}
}
}
}