'; } // a more svelte die() function spew($e, $t = 'Error') { write_top($t); echo $e; write_bottom(); exit; } // for debugging; displays $w in human-readable format function debug($w) { write_top('Display Data'); echo '
';
   if (is_string($w)) echo htmlentities($w);
     else print_r ($w);
   echo "
"; write_bottom(); exit; } if ($_SERVER["QUERY_STRING"] != '') $show = trim($_SERVER["QUERY_STRING"]); if ($show == 'php') phpinfo(); // load external xml data if (!file_exists('galleries.xml')) spew('File "galleries.xml" not found.'); $data = file_get_contents('galleries.xml'); if ($data === false) spew('Could not retrieve XML data.'); if ($show == 'xml') debug($data); // parse xml into usable structure $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, $data, $vals); xml_parser_free($parser); if ($show == 'raw') debug($vals); // restructure into pretty, simple array; include value checking $albums = array(); $i = 0; $j = 0; for($i=0; $i < count($vals); $i++) { if (($vals[$i]['type'] == 'open') and ($vals[$i]['tag'] == 'ALBUM')) $albums[$j] = array(); if ($vals[$i]['type'] == 'complete') $albums[$j][strtolower($vals[$i]['tag'])] = $vals[$i]['value']; if (($vals[$i]['type'] == 'close') and ($vals[$i]['tag'] == 'ALBUM')) { if ((!isset($albums[$j]['thumbnail'])) or ($albums[$j]['thumbnail'] == '')) $albums[$j]['thumbnail'] = 'resources/nothumb.jpg'; if ((!isset($albums[$j]['title'])) or ($albums[$j]['title'] == '')) $albums[$j]['title'] = 'Untitled'; if ((!isset($albums[$j]['description'])) or ($albums[$j]['description'] == '')) $albums[$j]['description'] = 'Photo album '.($j+1); if ((!isset($albums[$j]['url'])) or ($albums[$j]['url'] == '')) unset($albums[$j]); if ((!isset($albums[$j]['rel'])) or ($albums[$j]['rel'] == '')) unset($albums[$j]); $j++; } } if ($show == 'array') debug($albums); // output page write_top('Photo Albums'); echo '
'; for($i=0; $i
'; write_bottom();