Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F211408
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
38 KB
Subscribers
None
View Options
diff --git a/apps/hotglue/common.inc.php b/apps/hotglue/common.inc.php
--- a/apps/hotglue/common.inc.php
+++ b/apps/hotglue/common.inc.php
@@ -1,538 +1,547 @@
<?php
/**
* common.inc.php
* Common hotglue infrastructure
*
* Copyright Gottfried Haider, Danja Vasiliev 2010.
* This source code is licensed under the GNU General Public License.
* See the file COPYING for more details.
*/
@require_once('config.inc.php');
require_once('html.inc.php');
require_once('modules.inc.php');
/**
* save a page in the cache
*
* @param string $category cache category (e.g. 'page')
* @param string $name item name
* @param string $out content
* @return true if successful, false if not
*/
function cache_output($category, $name, $out)
{
// check if cache dir exists
$f = CONTENT_DIR.'/cache';
if (!is_dir($f)) {
$m = umask(0000);
if (!@mkdir($f, 0777)) {
umask($m);
log_msg('error', 'common: cannot create cache directory '.quot($f));
return false;
}
umask($m);
}
// check if category subdirectory exists
$f .= '/'.$category;
if (!is_dir($f)) {
$m = umask(0000);
if (!@mkdir($f, 0777)) {
umask($m);
log_msg('error', 'common: cannot create cache directory '.quot($f));
return false;
}
umask($m);
}
// save file
$f .= '/'.$name;
$m = umask(0111);
if (!file_put_contents($f, $out)) {
umask($m);
log_msg('error', 'common: error writing cache file '.quot($f));
return false;
}
umask($m);
log_msg('debug', 'common: cached '.$category.' '.quot($name));
return true;
}
/**
* setup a default html page
*
* see html.inc.php.
* @param bool $add_glue true for adding the glue code
*/
function default_html($add_glue)
{
html_title(SITE_NAME);
$favicon = FAVICON;
if (!empty($favicon)) {
if (is_url($favicon)) {
html_favicon($favicon);
} else {
html_favicon(base_url().$favicon);
}
}
if (USE_MIN_FILES) {
html_add_css(base_url().'css/reset.min.css', 1);
} else {
html_add_css(base_url().'css/reset.css', 1);
}
// 2 can be used for third-party components
html_add_css(base_url().'css/main.css', 3);
if ($add_glue) {
html_add_css(base_url().'css/glue.css', 4);
}
if ($add_glue) {
$jquery = JQUERY;
if (is_url($jquery)) {
html_add_js($jquery, 1);
} else {
html_add_js(base_url().$jquery, 1);
}
// 2 can be used for third-party components
html_add_js(base_url().'js/glue.js', 3);
html_add_js_var('$.glue.base_url', base_url());
html_add_js_var('$.glue.conf.show_frontend_errors', SHOW_FRONTEND_ERRORS);
html_add_js_var('$.glue.version', glue_version());
}
}
/**
* remove a page from the cache
*
* @param string $category cache category (e.g. 'page')
* @param string $name item name
*/
function drop_cache($category, $name)
{
$f = CONTENT_DIR.'/cache/'.$category.'/'.$name;
if (@unlink($f)) {
log_msg('debug', 'common: dropped cache of '.$category.' '.quot($name));
}
}
/**
* return the glue version with api.version.patchlevel
*
* @return array (with length three)
*/
function glue_version()
{
$a = expl('.', HOTGLUE_VERSION);
$ret = array(0, 0, 0);
for ($i=0; $i < count($a); $i++) {
$ret[$i] = $a[$i];
}
return $ret;
}
/**
* invoke a hook when an update was detected
*/
function handle_updates()
{
$new = glue_version();
$write_file = false;
if (($s = @file_get_contents(CONTENT_DIR.'/version')) !== false) {
// parse version
$a = expl('.', $s);
$old = array(0, 0, 0);
for ($i=0; $i < count($a); $i++) {
$old[$i] = $a[$i];
}
// check if an update happened
if ($old != $new) {
log_msg('info', 'common: detected hotglue update from version '.implode('.', $old).' to '.implode('.', $new));
// hook
invoke_hook('glue_update', array('old'=>$old, 'new'=>$new));
$write_file = true;
}
} else {
$write_file = true;
}
if ($write_file) {
$m = umask(0111);
@file_put_contents(CONTENT_DIR.'/version', implode('.', $new));
umask($m);
}
}
/**
* check if the user is authenticated or not
*
* @return true if authenticated, false if not
*/
function is_auth()
{
if (AUTH_METHOD == 'none') {
log_msg('debug', 'common: auth success (auth_method none)');
return true;
} elseif (AUTH_METHOD == 'basic') {
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
if ($_SERVER['PHP_AUTH_USER'] == AUTH_USER && $_SERVER['PHP_AUTH_PW'] == AUTH_PASSWORD) {
log_msg('debug', 'common: auth success (auth_method basic)');
return true;
} else {
log_msg('info', 'common: auth failure (auth_method basic)');
return false;
}
} else {
log_msg('debug', 'common: no auth data (auth_method basic)');
return false;
}
} elseif (AUTH_METHOD == 'digest') {
if (isset($_SERVER['PHP_AUTH_DIGEST'])) {
log_msg('debug', 'common: auth digest '.var_dump_inl($_SERVER['PHP_AUTH_DIGEST']));
$res = http_digest_check(array(AUTH_USER=>AUTH_PASSWORD), SITE_NAME);
if ($res == 0) {
log_msg('debug', 'common: auth success (auth_method digest)');
return true;
} else {
log_msg('info', 'common: auth failure '.$res.' (auth_method digest)');
return false;
}
}
} else {
log_msg('error', 'common: invalid or missing AUTH_METHOD config setting');
return false;
}
}
/**
* check if a page can be served from the cache
*
* @param string $category cache category (e.g. 'page')
* @param string $name item name
* @param int $max_age serve from cache when younger than $max_age seconds
* @return bool true if the page can be served from cache, false if not
*/
function is_cached($category, $name, $max_age)
{
$f = CONTENT_DIR.'/cache/'.$category.'/'.$name;
if (!is_file($f)) {
return false;
}
// check the file's age
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
clearstatcache(true, realpath($f));
} else {
clearstatcache();
}
$age = filemtime($f);
if ($max_age < abs(time()-$age)) {
return false;
} else {
return true;
}
}
/**
* check if an object exists
*
* @param $s object (e.g. page.rev.obj)
* @return bool
*/
function object_exists($s)
{
$a = expl('.', $s);
// we need not check if any of $a[..] is empty as the resulting string
// cannot be a file anyway
if (2 < count($a) && is_file(CONTENT_DIR.'/'.str_replace('.', '/', $s))) {
return true;
} else {
return false;
}
}
/**
* turn short page names into canonical ones
*
* if $s is not a page, the string is not altered.
* @param string &$s reference to the page name
*/
function page_canonical(&$s)
{
$a = expl('.', $s);
// assume head revision
if (count($a) == 1) {
$s .= '.head';
}
}
/**
* check if a page exists
*
* this function can also be used with object names (e.g. page.rev.obj).
* @param $s page
* @return bool
*/
function page_exists($s)
{
$a = expl('.', $s);
if (1 < count($a) && !empty($a[0]) && !empty($a[1]) && is_dir(CONTENT_DIR.'/'.$a[0].'/'.$a[1])) {
return true;
} else {
return false;
}
}
/**
* return the short pagename if possible, otherwise the long one
*
* @param $s page
* @return string
*/
function page_short($s)
{
$a = expl('.', $s);
if (count($a) == 1) {
return $s;
} elseif (count($a) == 2 && $a[1] == 'head') {
return $a[0];
} elseif (count($a) == 2) {
return $s;
} else {
return '';
}
}
/**
* prompt user for authentication
*
* @param bool $header_only only send header information
* this function does not return.
*/
function prompt_auth($header_only = false)
{
if (AUTH_METHOD == 'none') {
// nothing to do here
} elseif (AUTH_METHOD == 'basic') {
header('WWW-Authenticate: Basic realm="'.str_replace("\"", '', SITE_NAME).'"');
header($_SERVER['SERVER_PROTOCOL'].' 401 Unauthorized');
} elseif (AUTH_METHOD == 'digest') {
http_digest_prompt(SITE_NAME);
} else {
log_msg('error', 'common: invalid or missing AUTH_METHOD config setting');
}
// TODO (listed): we need hotglue theming here
die();
}
// TODO: document
function resolve_aliases($s, $name = '')
{
// base url
$s = str_replace('$BASEURL$', base_url(), $s);
$s = str_replace('$baseurl$', base_url(), $s);
// version number
$s = str_replace('$GLUE$', HOTGLUE_VERSION, $s);
$s = str_replace('$glue$', HOTGLUE_VERSION, $s);
+
+ //Zed local moves
+ $s = str_replace('%NORTH', '/do.php/local_move/north?redirectTo=/', $s);
+ $s = str_replace('%EAST', '/do.php/local_move/east?redirectTo=/', $s);
+ $s = str_replace('%SOUTH', '/do.php/local_move/south?redirectTo=/', $s);
+ $s = str_replace('%WEST', '/do.php/local_move/west?redirectTo=/', $s);
+ $s = preg_replace('/%MOVE (.*)/', '/do.php/local_move/?redirectTo=$1?redirectTo=/', $s);
+ //$s = str_replace('%MOVE ', '/do.php/local_move/?redirectTo=WAZZA?redirectTo=/', $s);
+
if (!empty($name)) {
// current object
$s = str_replace('$OBJ$', $name, $s);
$s = str_replace('$obj$', $name, $s);
// current page
$s = str_replace('$PAGE$', implode('.', array_slice(expl('.', $name), 0, 2)), $s);
$s = str_replace('$page$', implode('.', array_slice(expl('.', $name), 0, 2)), $s);
// pagename
$s = str_replace('$PAGENAME$', array_shift(expl('.', $name)), $s);
$s = str_replace('$pagename$', array_shift(expl('.', $name)), $s);
// revision
$s = str_replace('$REV$', array_shift(array_slice(expl('.', $name), 1, 1)), $s);
$s = str_replace('$rev$', array_shift(array_slice(expl('.', $name), 1, 1)), $s);
}
return $s;
}
// TODO: document
function resolve_relative_urls($s)
{
$attrs = array('href', 'src');
foreach ($attrs as $attr) {
$start = 0;
while (($start = strpos($s, $attr.'="', $start)) !== false) {
if (($end = strpos($s, '"', $start+strlen($attr)+2)) !== false) {
$link = substr($s, $start+strlen($attr)+2, $end-$start-strlen($attr)-2);
if (!is_url($link) && substr($link, 0, 1) != '#') {
// add base url for relative links that are not directed towards anchors
log_msg('debug', 'common: resolving relative url '.quot($link));
if (SHORT_URLS) {
$link = base_url().$link;
} else {
$link = base_url().'?'.$link;
}
} else {
log_msg('debug', 'common: not resolving url '.quot($link));
}
$start = $end+1;
} else {
break;
}
}
}
return $s;
}
/**
* output a cached page to the client
*
* @param string $category cache category (e.g. 'page')
* @param string $name item name
* @return true if successful, false if not
*/
function serve_cached($category, $name)
{
$f = CONTENT_DIR.'/cache/'.$category.'/'.$name;
if (@readfile($f)) {
log_msg('info', 'common: serving '.$category.' '.quot($name).' from cache');
return true;
} else {
log_msg('error', 'common: cannot serve '.$category.' '.quot($name).' from cache');
return false;
}
}
/**
* return the starting page
*
* @return string
*/
function startpage()
{
// read the starting page information from the content dir
// or fall back to the one defined in the configuration
$s = @file_get_contents(CONTENT_DIR.'/startpage');
if ($s !== false && 0 < strlen($s)) {
return $s;
} else {
$s = DEFAULT_PAGE;
page_canonical($s);
return $s;
}
}
/**
* move an uploaded file to the shared directory of a page
*
* this function reuses existing files when possible.
* @param string $fn filename of newly uploaded file (most likely in /tmp)
* @param string $page page or pagename
* @param string $orig_fn the original filename on the client machine (optional)
* @param bool &$existed set to true if the filename returned did already exist
* before
* @return filename inside the shared directory or false in case of error
*/
function upload_file($fn, $page, $orig_fn = '', &$existed = false)
{
// default to the temporary filename
if ($orig_fn == '') {
$orig_fn = $fn;
}
$a = expl('.', $page);
if (count($a) < 1 || !is_dir(CONTENT_DIR.'/'.$a[0])) {
log_msg('error', 'common: page '.quot($page).' does not exist, cannot move uploaded file');
// not sure if we ought to remove the file in /tmp here (probably not)
return false;
}
// create shared directory if it doesn't exist yet
$d = CONTENT_DIR.'/'.$a[0].'/shared';
if (!is_dir($d)) {
$m = umask(0000);
if (!@mkdir($d, 0777)) {
umask($m);
log_msg('error', 'common: cannot create shared directory '.quot($d).', cannot move uploaded file');
// not sure if we ought to remove the file in /tmp here (probably not)
return false;
}
umask($m);
}
// check if file is already in shared directory
if (($f = dir_has_same_file($d, $fn, $orig_fn)) !== false) {
log_msg('info', 'common: reusing file '.quot($f).' instead of newly uploaded file as they don\'t differ');
@unlink($fn);
$existed = true;
return $f;
} else {
// at least give it a unique name
$f = unique_filename($d, basename($orig_fn));
$m = umask(0111);
if (!@move_uploaded_file($fn, $d.'/'.$f)) {
umask($m);
log_msg('error', 'common: error moving uploaded file to '.quot($d.'/'.$f));
// not sure if we ought to remove the file in /tmp here (probably not)
return false;
} else {
umask($m);
log_msg('info', 'common: moved uploaded file to '.quot($d.'/'.$f));
$existed = false;
return $f;
}
}
}
/**
* check whether the string is a valid, canonical page name
*
* the function does not check if the page exists or not.
* @param string $s string to check
* @return bool
*/
function valid_pagename($s)
{
$a = expl('.', $s);
if (count($a) != 2) {
return false;
} elseif (empty($a[0]) || empty($a[1])) {
return false;
} elseif (in_array($a[0], array('cache', 'shared'))) {
// reserved page names
// TODO (later): we're missing the log file here
// TODO (later): we're also missing $arg0 of controllers here
// TODO (later): we're missing all the files directly in the
// content directory here (this might not be an issue on all
// os)
return false;
} elseif (in_array($a[1], array('shared'))) {
// reserved revision names
return false;
} elseif (is_file($a[0]) || is_dir($a[0]) || is_link($a[0])) {
// same name as existing file names in the root directory
// this is an issue when using the RewriteRule
return false;
} else {
return true;
}
}
?>
diff --git a/apps/hotglue/module_object.inc.php b/apps/hotglue/module_object.inc.php
--- a/apps/hotglue/module_object.inc.php
+++ b/apps/hotglue/module_object.inc.php
@@ -1,143 +1,143 @@
<?php
/**
* module_object.inc.php
* Module for handling general object properties
*
* Copyright Gottfried Haider, Danja Vasiliev 2010.
* This source code is licensed under the GNU General Public License.
* See the file COPYING for more details.
*/
@require_once('config.inc.php');
require_once('common.inc.php');
require_once('html.inc.php');
require_once('util.inc.php');
// module_image.inc.php has more information on what's going on inside modules
// (they can be easier than that one though)
function object_alter_render_early($args)
{
$elem = &$args['elem'];
$obj = $args['obj'];
if (!elem_has_class($elem, 'object')) {
return false;
}
if (!empty($obj['object-height'])) {
elem_css($elem, 'height', $obj['object-height']);
}
if (!empty($obj['object-left'])) {
elem_css($elem, 'left', $obj['object-left']);
}
if (!empty($obj['object-opacity'])) {
elem_css($elem, 'opacity', $obj['object-opacity']);
}
elem_css($elem, 'position', 'absolute');
if (!empty($obj['object-top'])) {
elem_css($elem, 'top', $obj['object-top']);
}
if (!empty($obj['object-width'])) {
elem_css($elem, 'width', $obj['object-width']);
}
if (!empty($obj['object-zindex'])) {
elem_css($elem, 'z-index', $obj['object-zindex']);
}
return true;
}
function object_alter_render_late($args)
{
$elem = $args['elem'];
$html = &$args['html'];
$obj = $args['obj'];
if (!elem_has_class($args['elem'], 'object')) {
return false;
}
if (!$args['edit']) {
// add links only for viewing
if (!empty($obj['object-link'])) {
$link = $obj['object-link'];
// resolve any aliases
$link = resolve_aliases($link, $obj['name']);
- if (!is_url($link) && substr($link, 0, 1) != '#') {
- // add base url for relative links that are not directed towards anchors
+ if (!is_url($link) && substr($link, 0, 1) != '#' && substr($link, 0, 1) != '/') {
+ // add base url for relative links that are not directed towards anchors, nor /links
if (SHORT_URLS) {
$link = base_url().urlencode($link);
} else {
$link = base_url().'?'.urlencode($link);
}
}
// <a> can include block elements in html5
if (substr($html, -1) == "\n") {
$html = substr($html, 0, -1);
}
$html = '<a href="'.htmlspecialchars($link, ENT_COMPAT, 'UTF-8').'">'."\n\t".str_replace("\n", "\n\t", $html)."\n".'</a>'."\n";
return true;
}
}
return false;
}
function object_alter_save($args)
{
$elem = $args['elem'];
$obj = &$args['obj'];
if (!elem_has_class($elem, 'object')) {
return false;
}
if (elem_css($elem, 'height') !== NULL) {
$obj['object-height'] = elem_css($elem, 'height');
} else {
unset($obj['object-height']);
}
if (elem_css($elem, 'left') !== NULL) {
$obj['object-left'] = elem_css($elem, 'left');
} else {
unset($obj['object-left']);
}
if (elem_css($elem, 'opacity') !== NULL) {
$obj['object-opacity'] = elem_css($elem, 'opacity');
} else {
unset($obj['object-opacity']);
}
if (elem_css($elem, 'top') !== NULL) {
$obj['object-top'] = elem_css($elem, 'top');
} else {
unset($obj['object-top']);
}
if (elem_css($elem, 'width') !== NULL) {
$obj['object-width'] = elem_css($elem, 'width');
} else {
unset($obj['object-width']);
}
if (elem_css($elem, 'z-index') !== NULL) {
$obj['object-zindex'] = elem_css($elem, 'z-index');
} else {
unset($obj['object-zindex']);
}
return true;
}
function object_render_page_early($args)
{
if ($args['edit']) {
html_add_js(base_url().'modules/object/object-edit.js');
// add default colors
html_add_js_var('$.glue.conf.object.default_colors', expl(' ', OBJECT_DEFAULT_COLORS));
}
}
-?>
\ No newline at end of file
+?>
diff --git a/content/scenes/B00001002.tpl b/content/scenes/B00001002.tpl
--- a/content/scenes/B00001002.tpl
+++ b/content/scenes/B00001002.tpl
@@ -1,49 +1,64 @@
<!--
Global location: B00001002
-->
<div class="grid_7 alpha">
{$xyz = explode(',', substr($CurrentPerso->location_local, 1, -1))}
{$x = $xyz[0]}{$y = $xyz[1]}{$z = $xyz[2]}
Sector C<span id="sector">{GeoOctocube::get_sector($x, $y, $z)}</span>
</div>
<div class="grid_2" style="text-align: center;">
Zone <span id="area">{abs($x)}-{abs($y)}</span>
</div>
<div class="grid_7 omega" style="text-align: right; margin-bottom: 1em;">
Niveau <span id="level">{abs($z)}</span>
</div>
<div class="clear"></div>
-
+{if $zone}
+{if $zone->type == "hotglue"}
+ <!-- Content iframe -->
+ <script type="text/javascript">
+ function hijacklinks(iframe){
+ var as = iframe.contentDocument.getElementsByTagName('a');
+ for(i=0;i<as.length;i++){
+ as[i].setAttribute('target','_parent');
+ }
+ }
+ </script>
+ <iframe src="/apps/hotglue/?zone_{$zone->id}" width="960" height="600" id="content_iframe" frameborder="0" scrolling="no" style="margin-bottom: 1em" onload="hijacklinks(this)"></iframe>
+{else}
+{print_r($zone)}
+{/if}
+{else}
<div class="content_wrapper">
<h1>HyperShip builder</h1>
<div class="grid_9 suffix_1 content alpha">
<h2>This area is buildable.</h2>
<p>You can take over this part of the ship, transform it and design it as you want.</p>
<p>To start, you can:</p>
<ul>
<li>Create a 960px wide picture with your scene background.</li>
<li>Define which parts of your picture are exits to another zone or level.</li>
</ul>
<p>If you want, you will also able to:</p>
<ul>
<li>Add descriptions to part of the area (like in the 90s adventure games)</li>
<li>Create a textual scenario (like in 80s choose your own adventure books)</li>
<li>Enhance the area with javascript or HTML5 (like in 2010)</li>
</ul>
</div>
<div class="grid_6 omega">
<p><a href="{get_url('builder')}">Start to build</a></p>
<p><a href="{get_url('do.php')}/local_move/0,1,0?redirectTo=/">Go north</a><br />
<a href="{get_url('do.php')}/local_move/1,0,0?redirectTo=/">Go east</a><br />
<a href="{get_url('do.php')}/local_move/0,-1,0?redirectTo=/">Go south</a><br />
<a href="{get_url('do.php')}/local_move/-1,0,0?redirectTo=/">Go west</a></p>
<p><a href="{get_url('do.php')}/local_move/0,0,1?redirectTo=/">Climb up</a><br />
<a href="{get_url('do.php')}/local_move/0,0,-1?redirectTo=/">Climb down</a></p>
</div>
<div class="clear fixclear"></div>
</div>
-
+{/if}
\ No newline at end of file
diff --git a/controllers/builder.php b/controllers/builder.php
--- a/controllers/builder.php
+++ b/controllers/builder.php
@@ -1,79 +1,77 @@
<?php
/**
* Builder
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* @package Zed
* @subpackage Controllers
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*
* @todo create a build.xml document to set what's buildable, and by who
*/
//
// Temporary initialization code, to allow some build during the Zed alphatest
//
$build_location = $CurrentPerso->location;
$build_mode = 'hotglue';
if (!$build_location->body->hypership) {
message_die("You can only invoke the HyperShip builder facilities inside the HyperShip.");
}
if ($build_location->place->code == "003") {
message_die("Bays aren't buildable.");
}
//
// Prepare zone
//
//TODO: get local zone
include('includes/content/zone.php');
if (true) {
- //Create a new zone
- $zone = new ContentZone(1);
- $zone->title = 'Test zone for sector C1, zone 10-6, level 4';
+ //Gets or creates a new zone at build location
+ $zone = ContentZone::at($build_location->global, $build_location->local, true);
+ $zone->title = "Sandbox hotglue zone for $build_location->global $build_location->local";
$zone->type = 'hotglue';
$zone->save_to_database();
- $zone->assign_to($build_location->global, $build_location->local);
}
-
//
// HTML output
//
//Serves header
$smarty->assign('PAGE_TITLE', 'Builder');
include('header.php');
//Hotglue iframe
-$smarty->assign('LOCATION', $build_location);
-$smarty->assign('ZONE', $zone);
+$smarty->assign('location', $build_location);
+$smarty->assign('zone', $zone);
switch ($build_mode) {
case 'hotglue':
$smarty->assign('IFRAME_SRC', '/apps/hotglue/?zone_' . $zone->id . '/edit');
$smarty->display('builder_hotglue.tpl');
break;
default:
message_die(GENERAL_ERROR, "Unknown build mode: $build_mode");
break;
}
//Servers footer
include('footer.php');
?>
diff --git a/includes/content/zone.php b/includes/content/zone.php
--- a/includes/content/zone.php
+++ b/includes/content/zone.php
@@ -1,123 +1,156 @@
<?php
/**
* Zone class
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* @package Zed
* @subpackage Content
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*/
/**
* Content zone class
*
* A zone is a physical place, independent from the location.
* This mechanism allows to more easily move zones.
*
* This class maps the content_zones table.
*/
class ContentZone {
public $id;
public $title;
public $type;
public $params;
public $deleted = false;
/**
* Initializes a new instance of a zone object
*
* @param int $id The zone ID
*/
function __construct ($id = '') {
if ($id) {
$this->id = $id;
return $this->load_from_database();
}
}
/**
* Loads the object zone (ie fill the properties) from the $_POST array
*/
function load_from_form () {
if (array_key_exists('title', $_POST)) $this->user_id = $_POST['title'];
if (array_key_exists('type', $_POST)) $this->user_id = $_POST['type'];
if (array_key_exists('params', $_POST)) $this->user_id = $_POST['params'];
if (array_key_exists('deleted', $_POST)) $this->user_id = $_POST['deleted'];
}
/**
* Loads the object zone (ie fill the properties) from the database
*/
function load_from_database () {
global $db;
$id = $db->sql_escape($this->id);
$sql = "SELECT * FROM " . TABLE_CONTENT_ZONES . " WHERE zone_id = '" . $id . "'";
if (!$result = $db->sql_query($sql)) message_die(SQL_ERROR, 'Unable to query content_zones', '', __LINE__, __FILE__, $sql);
if (!$row = $db->sql_fetchrow($result)) {
$this->lastError = 'Zone unkwown: ' . $this->id;
return false;
}
$this->title = $row['zone_title'];
$this->type = $row['zone_type'];
$this->params = $row['zone_params'];
$this->deleted = $row['zone_deleted'] ? true : false;
return true;
}
/**
* Saves the object to the database
*/
function save_to_database () {
global $db;
$id = $this->id ? "'" . $db->sql_escape($this->id) . "'" : 'NULL';
$title = $db->sql_escape($this->title);
$type = $db->sql_escape($this->type);
$params = $db->sql_escape($this->params);
$deleted = $this->deleted ? 1 : 0;
$sql = "REPLACE INTO " . TABLE_CONTENT_ZONES . " (`zone_id`, `zone_title`, `zone_type`, `zone_params`, `zone_deleted`) VALUES ($id, '$title', '$type', '$params', $deleted)";
if (!$db->sql_query($sql)) {
message_die(SQL_ERROR, "Unable to save", '', __LINE__, __FILE__, $sql);
}
if (!$this->id) {
$this->id = $db->sql_nextid();
}
}
+ /**
+ * Assigns the zone at the specified location.
+ *
+ * @param string $location_global the global location
+ * @param string $location_global the local location
+ * @param bool $delete_old_locations if true, delete old locations
+ */
function assign_to ($location_global, $location_local, $delete_old_locations = true) {
if (!$this->id) {
$this->save_to_database();
}
global $db;
if ($delete_old_locations) {
$sql = "DELETE FROM " . TABLE_CONTENT_ZONES_LOCATIONS . " WHERE zone_id = " . $this->id;
if (!$db->sql_query($sql)) {
message_die(SQL_ERROR, "Unable to delete", '', __LINE__, __FILE__, $sql);
}
}
$g = $db->sql_escape($location_global);
$l = $db->sql_escape($location_local);
$sql = "REPLACE INTO " . TABLE_CONTENT_ZONES_LOCATIONS . " (location_global, location_local, zone_id) VALUES ('$g', '$l', $this->id)";
if (!$db->sql_query($sql)) {
message_die(SQL_ERROR, "Unable to set zone location", '', __LINE__, __FILE__, $sql);
}
-
+ }
+
+ /**
+ * Gets the zone at specified location
+ *
+ * @param string $location_global the global location
+ * @param string $location_global the local location
+ * @param bool $create if the zone doesn't exist, create it [optional] [default value: false]
+ * @return ContentZone the zone, or null if the zone doesn't exist and $create is false
+ */
+ static function at ($location_global, $location_local, $create = false) {
+ global $db;
+ $g = $db->sql_escape($location_global);
+ $l = $db->sql_escape($location_local);
+ $sql = "SELECT zone_id FROM " . TABLE_CONTENT_ZONES_LOCATIONS . " WHERE location_global = '$g' AND location_local = '$l'";
+ if (!$result = $db->sql_query($sql)) {
+ message_die(SQL_ERROR, "Unable to set zone location", '', __LINE__, __FILE__, $sql);
+ }
+ if ($row = $db->sql_fetchrow($result)) {
+ return new ContentZone($row['zone_id']);
+ } elseif ($create) {
+ $zone = new ContentZone();
+ $zone->assign_to($location_global, $location_local);
+ return $zone;
+ } else {
+ return null;
+ }
}
}
?>
diff --git a/includes/geo/scene.php b/includes/geo/scene.php
--- a/includes/geo/scene.php
+++ b/includes/geo/scene.php
@@ -1,244 +1,208 @@
<?php
/**
* Geo scene class.
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* @package Zed
* @subpackage Geo
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*/
require_once('location.php');
require_once('octocube.php');
require_once('sceneindex.php');
if (!defined('SCENE_DIR')) {
/**
* The directory containing scenes files
*/
define('SCENE_DIR', 'content/scenes');
}
/**
* Geo scene class
*
* This class provides methods to determine and renders the local scene.
*/
class GeoScene {
/**
* Last error or warning
*
* @var string
*/
public $lastError;
/**
* File scene to serve
*
* @var string
*/
public $sceneFile;
/**
* The location of the scene to print
*
* @var GeoLocation
*/
public $location;
/**
* Initializes a new GeoScene instance
*
* @param GeoLocation $location location the scene is to print
*/
function __construct ($location) {
$this->location = $location;
//Gets local scene
if ($location->containsLocalLocation) {
if ($this->get_local_scene()) return;
}
//Gets global scene
if ($location->containsGlobalLocation) {
if ($this->get_global_scene()) return;
}
//If not scene found, let's set a warning
$this->lastError = "No scene found.";
}
/**
* Gets local scene
*
* @return boolean true if a scene have been found ; otherwise, false.
*/
private function get_local_scene () {
//From the index
$index = GeoSceneIndex::Load(SCENE_DIR);
if ($tpl = $index->get_local_template($this->location->global, $this->location->local)) {
$this->sceneFile = SCENE_DIR . '/' . $tpl;
return true;
}
//From filename
$expression = $this->location->global . ' ' . $this->location->local;
if ($this->try_get_scene($expression)) {
return true;
}
return false;
}
/**
* Gets global scene
*
* @return boolean true if a scene have been found ; otherwise, false.
*/
private function get_global_scene () {
$location = $this->location;
if ($location->place) {
if ($this->try_get_scene($location->global)) {
return true;
}
}
if ($location->body) {
if ($this->try_get_scene('B' . $location->body->code)) {
return true;
}
}
return false;
}
/**
* Gets file extension
*
* @param string $file the file path
* @return string the file extension
*/
public static function get_file_extension ($file) {
$pathinfo = pathinfo($file);
return $pathinfo['extension'];
}
/**
* Renders the file
*
* @todo Add standard code to render .swf Flash/ShockWave files.
*/
public function render () {
if ($file = $this->sceneFile) {
switch ($ext = GeoScene::get_file_extension($file)) {
case 'png':
case 'jpg':
case 'gif':
case 'bmp':
echo "<img src=\"$file\" />";
break;
case 'tpl':
global $smarty;
$template_dir = $smarty->template_dir;
$smarty->template_dir = getcwd();
//$this->location is the object reference
//Some objects like the hypership move, so we also need to know where there are.
//From the template, this object location is assigned to $location
//To get $this->location from template, use $CurrentPerso->location
if ($this->location->body) {
$smarty->assign("location", new GeoLocation($this->location->body->location));
} elseif ($this->location->ship) {
$smarty->assign("location", new GeoLocation($this->location->ship->location));
}
+
+ //Gets zone information
+ require_once('includes/content/zone.php');
+ if ($zone = ContentZone::at($this->location->global, $this->location->local)) {
+ $smarty->assign('zone', $zone);
+ }
$smarty->assign("SCENE_URL", defined('SCENE_URL') ? SCENE_URL : '/' . SCENE_DIR);
lang_load('scenes.conf', $this->location->global);
$smarty->display($file);
$smarty->template_dir = $template_dir;
break;
case 'php':
message_die(HACK_ERROR, ".php scene files not allowed without review", '', __LINE__, __FILE__);
default:
message_die(GENERAL_ERROR, "Can't handle $ext extension for $file scene", 'GeoScene render error', __LINE__, __FILE__);
}
echo "\n\n";
}
}
/**
* Tries to get the scene file.
*
* It will tries to find in the scene directory a file with $code as name,
* and .tpl .png .gif .bmp .swf .html or .php as extension.
*
* @param string the location code (and filename)
* @return bool true if a scene file have been found and set ; otherwise, false.
*/
private function try_get_scene ($code) {
$file = SCENE_DIR . "/$code";
$extensions = array('tpl', 'png', 'jpg', 'gif', 'bmp', 'swf', 'html', 'php');
foreach ($extensions as $ext) {
if (file_exists("$file.$ext")) {
$this->sceneFile = "$file.$ext";
return true;
}
}
return false;
}
-
- /**
- * Reads scene templates and indexes information
- */
- public static function index_scene_templates (&$global_templates, &$local_templates, &$updated) {
- $global_templates = array();
- $local_templates = array();
- $updated = filemtime(SCENE_DIR);
- if ($handle = opendir(SCENE_DIR)) {
- while (false !== ($file = readdir($handle))) {
- if (GeoScene::get_file_extension($file) == 'tpl') {
- $template = file_get_contents(SCENE_DIR . '/' . $file, false, NULL, 0, 1024);
- $location = self::get_template_location($template);
- if ($location[1] == NULL) {
- $global_templates[$location[0]] = $file;
- } else {
- $local_templates[$location[0]][$location[1]] = $file;
- }
- }
- }
- closedir($handle);
- }
- }
-
- private static function get_template_location ($template) {
- $location = array(NULL, NULL);
-
- //Gets global location
- $pos1 = strpos($template, "Global location: ") + 17;
- $pos2 = strpos($template, "\n", $pos1);
- $location[0] = trim(substr($template, $pos1, $pos2 - $pos1));
-
- //Gets local location
- $pos1 = strpos($template, "Local location: ");
- if ($pos1 !== false) {
- $pos1 += 16;
- $pos2 = strpos($template, "\n", $pos1);
- $location[1] = trim(substr($template, $pos1, $pos2 - $pos1));
- }
-
- return $location;
- }
}
?>
\ No newline at end of file
diff --git a/skins/zed/builder_hotglue.tpl b/skins/zed/builder_hotglue.tpl
--- a/skins/zed/builder_hotglue.tpl
+++ b/skins/zed/builder_hotglue.tpl
@@ -1,9 +1,9 @@
<div class="content_wrapper">
<h1>HyperShip builder</h1>
<div class="content">
- <p style="width: 40%; float: left;">{$LOCATION}<br />{$LOCATION->global} {$LOCATION->local}</p>
- <p style="width: 40%; float: right; text-align: right;">Zone {$ZONE->id}</p>
+ <p style="width: 40%; float: left;">{$location}<br />{$location->global} {$location->local}</p>
+ <p style="width: 40%; float: right; text-align: right;">Zone {$zone->id}</p>
<div class="clear"></div>
</div>
</div>
{include file="iframe.tpl"}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Nov 23, 10:59 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
21233
Default Alt Text
(38 KB)
Attached To
rZEDHG ZedLegacy
Event Timeline
Log In to Comment