Files
bobsleighphotos.com/_old/version_2/php/func_html.php
2017-03-02 20:30:40 -06:00

170 lines
5.1 KiB
PHP
Executable File

<?php
#########################################################
# #
# Functions the print HTML #
# written by benjamin ramey #
# bsr@rameydesign.net #
# #
# best viewed with: #
# resolution = 1280x960 #
# tab = 4 spaces #
# indent = 8 spaces #
# #
#####################################################################################################################################################
# CODE # COMMENTS #
#####################################################################################################################################################
###################################################################################################### print a page from xml data array
# parameters: 1) array of data from xml file
# returns: the html for the select box for language selection
function html_print_xml_page($data)
{
$page_name = $data['name'];
$page_content = '';
$sections = 0;
$paras = 0;
isset($data['content']['section'])
? $sections = 1
: $paras = 1;
if($sections ) {
$contents = xml_force_array($data['content']['section']);
$page_content = html_print_sections($contents);
}
else if($paras) {
$contents = xml_force_array($data['content']['para']);
$page_content = html_print_paragraphs($contents);
}
print "<div class='page_title'>$page_name</div>\n";
print "<div class='page_content'>\n";
print $page_content;
print "</div>\n";
}
###################################################################################################### print sections of an xml page
# parameters: 1) array of sections to print
# returns: the html for the sections
function html_print_sections(&$sections)
{
$page_content = '';
foreach($sections as $sec) {
$page_content .= "<div class='text_div'>\n";
$page_content .= "<div class='text_header'>{$sec['name']}</div>\n";
$page_content .= "<div class='text'>\n";
$paras = xml_force_array($sec['text']['para']);
$page_content .= html_print_paragraphs($paras);
$page_content .= "</div>\n";
$page_content .= "</div>\n";
}
return $page_content;
}
###################################################################################################### print paragraphs of an xml page
# parameters: 1) array of paragraphs to print
# returns: the html for the paragraphs
function html_print_paragraphs(&$paragraphs)
{
$page_content = '';
foreach($paragraphs as $para) {
$page_content .= '<p>';
if(is_array($para)) {
foreach($para as $key => $value) {
switch($key) {
case 'line':
if(is_array($value)) {
foreach($value as $line) { $page_content .= '<br />'.$line; }
}
else { $page_content .= '<br />'.$value; }
break;
case 'paracontent':
$page_content .= "$value\n";
break;
case 'list':
if($para['list']['type'] == 'ordered') {
$page_content .= "<ol>\n";
}
else { $page_content .= "<ul>\n"; }
foreach($para['list']['listitem'] as $item) {
$page_content .= "<li>$item</li>\n";
}
if($para['list']['type'] == 'ordered') {
$page_content .= "</ol>\n";
}
else { $page_content .= "</ul>\n"; }
break;
case 'heading':
$page_content .= "<strong>$value</strong>\n";
break;
case 'link':
if(is_array($value)) {
$page_content .= " <a href='{$value['href']}'>{$value['linktext']}</a>\n";
}
else { $page_content .= " <a href='$value'>$value</a>\n"; }
break;
case 'image':
$images = xml_force_array($para['image']);
$page_content .= html_print_images($images);
break;
default:
break;
}
}
}
else { $page_content .= $para; }
$page_content .= "</p>\n";
}
return $page_content;
}
###################################################################################################### print images of an xml page
# parameters: 1) array of images to print
# returns: the html for the images
function html_print_images(&$images)
{
$page_content = '';
foreach($images as $image) {
if(is_array($image)) {
foreach($image as $key => $value) {
switch($key) {
case 'link':
$page_content .= "<a href='$value'><img src='/graphics/{$image['path']}' ";
$page_content .= "target='_blank' border='0' /></a>\n";
break;
default:
break;
}
}
}
else { $page_content .= "<img src='/graphics/{$image}' border='0' align='right' />\n"; }
}
return $page_content;
}
###################################################################################################### gets a random panorama image
# parameters: 1) path to pictures
# returns: the html for the select box for language selection
function html_get_random_img($path)
{
$pictures = scandir($path);
$pictures = filesys_remove_unwanted_children($pictures,$path,'folders');
$num_pics = count($pictures);
$rand_pic = $pictures[floor(rand(0,$num_pics - 1))];
return($rand_pic);
}
?>