Initial commit
This commit is contained in:
170
_old/version_2/php/func_html.php
Executable file
170
_old/version_2/php/func_html.php
Executable file
@@ -0,0 +1,170 @@
|
||||
<?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);
|
||||
}
|
||||
|
||||
?>
|
||||
41
_old/version_2/php/func_ops.php
Executable file
41
_old/version_2/php/func_ops.php
Executable file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
#####################################################
|
||||
# #
|
||||
# written by benjamin ramey #
|
||||
# ben.ramey@gmail.com #
|
||||
# #
|
||||
# best viewed with: #
|
||||
# resolution = 1280x960 #
|
||||
# tab = 4 spaces #
|
||||
# indent = 8 spaces #
|
||||
# #
|
||||
# This file contains: #
|
||||
# Functions the govern various and sundry #
|
||||
# site operations such as obtaining the #
|
||||
# commands sent to the server like, for #
|
||||
# example, what page to display #
|
||||
# #
|
||||
#####################################################################################################################
|
||||
# CODE # COMMENTS #
|
||||
#####################################################################################################################
|
||||
|
||||
##################################################################### FUNCTION: ops_get_cmds
|
||||
function ops_get_cmds()
|
||||
{
|
||||
global $_QUERY,$_SCRIPT_NAME;
|
||||
$separator = '/'; # query string will be split by this character
|
||||
$cmds = array();
|
||||
|
||||
if(empty($_QUERY)) { return($cmds); } # if the query string is empty, no need to procede
|
||||
# but we do want to still return an array (even an empty one)
|
||||
$cmds = explode($separator,
|
||||
str_replace($_SCRIPT_NAME,'',$_QUERY));
|
||||
for($c = 0; $c < count($cmds); ) { # removes any empty array elements
|
||||
if(empty($cmds[$c])) {
|
||||
array_splice($cmds,$c,1); # remove the empty element
|
||||
}
|
||||
else { $c++; } # only advance the array index if we didn't splice something out
|
||||
}
|
||||
|
||||
return($cmds);
|
||||
}
|
||||
136
_old/version_2/php/func_xml.php
Executable file
136
_old/version_2/php/func_xml.php
Executable file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
#########################################################
|
||||
# #
|
||||
# XML functions #
|
||||
# written by benjamin ramey #
|
||||
# bsr@rameydesign.net #
|
||||
# #
|
||||
# best viewed with: #
|
||||
# resolution = 1280x960 #
|
||||
# tab = 4 spaces #
|
||||
# indent = 8 spaces #
|
||||
# #
|
||||
########################################################################################## xml_parse_file
|
||||
# parameters: path to file to parse
|
||||
# returns: associative array of xml file data
|
||||
function xml_parse_file($xml_file)
|
||||
{
|
||||
$xml = '';
|
||||
$data = array();
|
||||
|
||||
if(file_exists($xml_file)) {
|
||||
$xml = file_get_contents($xml_file);
|
||||
if(empty($xml)) {
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
else { return(NULL); }
|
||||
|
||||
$patt = "/^<\?xml([^\?]*)\?>/";
|
||||
preg_match($patt,$xml,$matches);
|
||||
$xml_specs = explode(' ',$matches[1]);
|
||||
foreach($xml_specs as $spec) {
|
||||
if(empty($spec)) { continue; }
|
||||
list($name,$value) = explode('=',$spec);
|
||||
$value = str_replace("'",'',$value);
|
||||
$value = str_replace('"','',$value);
|
||||
|
||||
$data[$name] = $value;
|
||||
}
|
||||
$xml = substr($xml,strlen($matches[0]));
|
||||
|
||||
$xml_left = array($xml); // init xml heap
|
||||
$tmp_refs[] =& $data; // init refs heap
|
||||
$patt = "/^<(\w+)([^>]*)>/"; // pattern to get element at beginning of xml_left
|
||||
|
||||
while(!empty($xml_left)) {
|
||||
$to_process = array_pop($xml_left); // $xml_left is a heap
|
||||
$to_process = trim($to_process); // trim fore and aft spaces
|
||||
$last_index = count($tmp_refs) - 1;
|
||||
|
||||
if(preg_match($patt,$to_process,$matches)) {
|
||||
$element = $matches[1];
|
||||
$parameters = isset($matches[2]) ? $matches[2] : '';
|
||||
|
||||
if(isset($tmp_refs[$last_index][$element])) {
|
||||
if(is_array($tmp_refs[$last_index][$element])) {
|
||||
if(isset($tmp_refs[$last_index][$element][0])) { // case: [biography]=>[0],[1]...[x]; $element = biography
|
||||
array_push($tmp_refs[$last_index][$element],''); // endsup: [biography]=>[0],[1]...[x+1]
|
||||
$tmp_index = count($tmp_refs[$last_index][$element]) - 1;
|
||||
$tmp_refs[] =& $tmp_refs[$last_index][$element][$tmp_index];
|
||||
}
|
||||
else { // case: [biography]=>[paragraph]; $element = biography
|
||||
$tmp_ary = $tmp_refs[$last_index][$element]; // endsup: [biography]=>[0]=>[paragraph]
|
||||
$tmp_refs[$last_index][$element] = array($tmp_ary,''); // [1]=>''
|
||||
$tmp_refs[] =& $tmp_refs[$last_index][$element][1];
|
||||
}
|
||||
}
|
||||
else { // case: [biography]=>"string"; $element = biography
|
||||
$tmp_refs[$last_index][$element] = array($tmp_refs[$last_index][$element],'');
|
||||
$tmp_refs[] =& $tmp_refs[$last_index][$element][1]; // endsup: [biography]=>[0]=>"string"
|
||||
} // [1]=>''
|
||||
}
|
||||
else {
|
||||
$tmp_refs[$last_index][$element] = ''; // case: [biography]=> NULL; $element = biography
|
||||
$tmp_refs[] =& $tmp_refs[$last_index][$element]; // endsup: [biography]=>""
|
||||
}
|
||||
|
||||
if(!empty($parameters)) { // if there are parameters, add them as if they were imbedded elements
|
||||
$pairs = explode(' ',$parameters);
|
||||
$last_index = count($tmp_refs) - 1;
|
||||
$tmp_refs[$last_index] = array(); // we can do this, because we know the last element added
|
||||
// is always fresh and new
|
||||
foreach($pairs as $pair) {
|
||||
if(empty($pair)) { continue; }
|
||||
|
||||
list($name,$value) = explode('=',$pair);
|
||||
$value = str_replace("'",'',$value);
|
||||
$value = str_replace('"','',$value);
|
||||
|
||||
$tmp_refs[$last_index][$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$end_tag = strpos($to_process,"</$element>");
|
||||
if($end_tag === FALSE) {
|
||||
return("ERROR IN XML DOCUMENT, NO END TAG: $element\n\nto process: $to_process");
|
||||
}
|
||||
|
||||
$element_len = strlen($matches[0]);
|
||||
$contents = substr($to_process,$element_len,$end_tag - $element_len);
|
||||
|
||||
if($extra = substr($to_process,$end_tag + strlen("</$element>"))) {
|
||||
array_push($xml_left,$extra);
|
||||
}
|
||||
else {
|
||||
array_push($xml_left,'!~~END~~!');
|
||||
}
|
||||
array_push($xml_left,$contents);
|
||||
}
|
||||
else if($to_process != '!~~END~~!') { // no pattern match, but it's not the end of an embedded element
|
||||
$tmp_refs[$last_index] = $to_process; // so we must have content to assign, so assign it--genius!
|
||||
array_pop($tmp_refs);
|
||||
}
|
||||
else { // we've reached the end of an embedded element, so jump back a level
|
||||
$tmp = array_pop($tmp_refs);
|
||||
}
|
||||
}
|
||||
|
||||
return($data);
|
||||
}
|
||||
|
||||
########################################################################################## xml_force_array
|
||||
# parameters: path to file to parse
|
||||
# returns: associative array of xml file data
|
||||
function xml_force_array($element)
|
||||
{
|
||||
$array = array();
|
||||
if(is_array($element)) {
|
||||
if(isset($element[0])) { $array = $element; }
|
||||
else { array_push($array,$element); }
|
||||
}
|
||||
else { array_push($array,$element); }
|
||||
|
||||
return($array);
|
||||
}
|
||||
?>
|
||||
23
_old/version_2/php/inc_constants.php
Executable file
23
_old/version_2/php/inc_constants.php
Executable file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
#####################################################
|
||||
# #
|
||||
# written by benjamin ramey #
|
||||
# ben.ramey@gmail.com #
|
||||
# #
|
||||
# This file contains: #
|
||||
# constants #
|
||||
# #
|
||||
#####################################################################################################
|
||||
# CODE # COMMENTS #
|
||||
#####################################################################################################
|
||||
# style: all caps, underscores
|
||||
# prefix: k
|
||||
##################################################### CONSTANTS
|
||||
define('kDEBUG',false); # toggles debugging messages throughout code
|
||||
define('kERROR_LEVEL','low'); # level of error reporting:
|
||||
# none = no error reporting
|
||||
# high = only high priority errors
|
||||
# medium = medium and higher priority errors
|
||||
# low = low and higher priority errors
|
||||
|
||||
?>
|
||||
19
_old/version_2/php/inc_globals.php
Executable file
19
_old/version_2/php/inc_globals.php
Executable file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
#####################################################
|
||||
# #
|
||||
# written by benjamin ramey #
|
||||
# ben.ramey@gmail.com #
|
||||
# #
|
||||
# This file contains: #
|
||||
# globals #
|
||||
# #
|
||||
#####################################################################################################################
|
||||
# CODE # COMMENTS #
|
||||
#####################################################################################################################
|
||||
# style: all caps, underscores
|
||||
# prefix: _
|
||||
##################################################################### GLOBALS
|
||||
$_DOC_ROOT = $_SERVER['DOCUMENT_ROOT'];
|
||||
$_SCRIPT_NAME = $_SERVER['SCRIPT_NAME'];
|
||||
$_QUERY = $_SERVER['REQUEST_URI'];
|
||||
$_CMDS = ops_get_cmds();
|
||||
Reference in New Issue
Block a user