RPG Items Code

The code for the important parts of the project. Notably the page.php, the default template (with lots of QR codes and a touch of jQuery) and a default item file.

The page.php page; converting .item file to the templated html

<?php

/**
 * page.php
 * Item page script
 * This tool provides a uniform way to display RPG items for tabletop use
 * Edit the .item file and enjoy the auto formatting into decently printable html
 * 
 * Copyright (C) 2011 Gert Schepens
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License version 3 as
 * published by the Free Software Foundation.
 * 
 * For a copy of the GNU General Public License, see  <http://www.gnu.org/licenses/>.
 * 
 * 
 * ToDo
 *  html template from parameters (??) - this enables online custom html layouts
 *  Print skin - specific print optimised code in the templates
 *  data in database - all data saved in a database instead of files, for public online safety!
 */


#error_reporting(E_ALL);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set("display_errors", 1);

# Clean the parameters
$_CLEAN['REQUEST'] = clean($_REQUEST);
$file = $_CLEAN['REQUEST']['item'];

# Check for contents parameter.
if ( $_CLEAN['REQUEST']['show'] == "show" ) {
	$ini_array = parse_ini_string( $_CLEAN['REQUEST']['contents'] );
	$file = "";

} else {

# Check if the file exists
if (! file_exists ( "./".$file."" ) ) {
	echo "File unavailable ". $file;
	exit;
}


// Parse .item file
#$ini_array = parse_ini_file("sunring.item");
$ini_array = parse_ini_file($file."");

}


# unless ini_array; exit with insufficient data
if ( ! is_array( $ini_array ) ) {
	echo "Data load failed";
	exit;
}


# Load textile interpretter
require_once "classTextile.php";
$textile = new Textile;

# Load templating tool
require_once "template.php";
$options = array('filename'=>'template.tmpl',
		 'die_on_bad_params'=>0,
                 );
$template =& new Template(&$options);

# configure template data
$template->AddParam('title', $ini_array[Name]);
$template->AddParam('file', $file."");

foreach ($ini_array as $key => $value) {
 $template->AddParam($key, $textile->TextileThis($value));
}


$template->EchoOutput();


# Clean superglobal variables
# As provided by zgold on http://www.php.net/manual/en/reserved.variables.get.php#105335
#  $_CLEAN['GET'] = clean($_GET);
#  $_REQUEST
function clean($elem) 
{ 
    if(!is_array($elem)) 
        $elem = htmlentities($elem,ENT_NOQUOTES,"UTF-8"); 
    else 
        foreach ($elem as $key => $value) 
            $elem[$key] = clean($value); 
    return $elem; 
} 


?>

The template

<html>
<head>
 <title><TMPL_VAR NAME="title"></title>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>

</head>
<body>
<div id="image" style="float:right;" ><TMPL_VAR NAME="Image"></div>


<h1><TMPL_VAR NAME="Name"></h1>
<div id="beschrijving" style="height: 290">
<TMPL_VAR NAME="Beschrijving">
</div>


<br><br>
<div id="thispage" style="border-width: .1em; border-style: dotted; width:130; text-align: center; float:right; margin-top:280;"></div>

<div id="DM" style="border-width: .2em; border-style: dotted; width:350;">
<h3>DM notes</h3>
<div id="qr"><img src="http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=<TMPL_VAR NAME="DMOnly">"></div>
<div id="text" style="display: none;"><TMPL_VAR NAME="DMOnly">
Download file: <a href="<TMPL_VAR NAME="file">"><TMPL_VAR NAME="file"></a>


</div>
</div>


<script>
    $('#DM').click(function () {
		$('#text').toggle(); 
              });

    $(document).ready(function() {
	$('#thispage').html('<img src="http://chart.apis.google.com/chart?cht=qr&chs=120x120&chl='+window.location.href+'">');
	});
</script>

</body>
</html>

And the default .item file

; This is an item file. Lots of textile in a php parsed thing
; http://en.wikipedia.org/wiki/Textile_(markup_language)

Name="Item name; used for title page too"

Beschrijving="Player description text. Any information you want the player to know about!"

DMOnly="Any DM only info. Automatically made into a QR code for your tabletop convenience. Clicking the QR code online will open the human readable text"

Image="Image information. Can be any URL; Textile formatting for images is to surround it with exclamation marks!"


More about me

Site QR Code

Use this code at your own peril; I am not responsible for anything that happens to you or your devices. You re a big boy or girl, please do some research before using it if you have any concerns!