Source for file DpPage.php
Documentation is available at DpPage.php
* A DutchPIPE enabled web page
* DutchPIPE version 0.4; PHP version 5
* LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
* If you did not receive a copy of the DutchPIPE license, you can obtain one at
* http://dutchpipe.org/license/1_0.txt or by sending a note to
* license@dutchpipe.org, in which case you will be mailed a copy immediately.
* @subpackage dpuniverse_std
* @author Lennert Stock <ls@dutchpipe.org>
* @copyright 2006, 2007 Lennert Stock
* @license http://dutchpipe.org/license/1_0.txt DutchPIPE License
* @version Subversion: $Id: DpPage.php 281 2007-08-20 21:45:53Z ls $
* @link http://dutchpipe.org/manual/package/DutchPIPE
* Builts upon the standard DpObject class
* A DutchPIPE enabled web page
* Creates the following DutchPIPE properties:<br />
* - boolean <b>isPage</b> - Set to TRUE
* - boolean|integer <b>isMovingArea</b> - Set to FALSE, can be type 1 or 2
* - boolean <b>isStandalone</b> - Set to TRUE if this is a "standalone" page
* @subpackage dpuniverse_std
* @author Lennert Stock <ls@dutchpipe.org>
* @copyright 2006, 2007 Lennert Stock
* @license http://dutchpipe.org/license/1_0.txt DutchPIPE License
* @version Release: 0.2.1
* @link http://dutchpipe.org/manual/package/DutchPIPE
* @var array All "exits" out of this page
private $mExits = array();
* Aliases used for exits, e.g. 'enter bar' for 'north'
private $mExitAliases = array();
* @var array Elements to make a navigation trail
private $mNavigationTrail = array();
* Calls the method 'createDpPage' in this page.
* Calls the method 'resetDpPage' in this page.
* Called when certain events occur, given with $name.
* Calls the method 'eventDpPage' in this page.
* @param object $name Name of event
* @param mixed $args One or more arguments, depends on event
* Called when certain events occur, given with $name.
* @param object $name Name of event
* @param mixed $args One or more arguments, depends on event
* Adds an "exit" out of this page
* Exits are links that can be typed on the command line or used by computer
* controlled character to wander around the site. Adding compass directions
* like 'nw' will also add the full 'northwest' action, and vice versa, if
* @param string $direction Command to use link, "home", "bar"
* @param array $direction Multiple directions, "bar", "north"
* @param string $destination URL
* @see removeExit, setExits
final function addExit($direction, $destination, $method = NULL,
$mapArea = NULL, $mapAreaActionTitle = NULL)
$short_dirs = array('n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw');
$long_dirs = array('north', 'northeast', 'east', 'southeast', 'south',
'southwest', 'west', 'northwest');
$direction = array($direction);
if (FALSE !== ($x = array_search($direction[0], $short_dirs))) {
if (FALSE !== ($y = array_search($long_dirs[$x], $direction))) {
$direction[$y] = $direction[0];
$direction[0] = $long_dirs[$x];
foreach ($direction as $dir) {
if (FALSE === ($y = array_search($long_dirs[$x], $direction))
$newdirs[] = $long_dirs[$x];
} elseif (FALSE !== ($x = array_search($dir, $long_dirs))) {
if (FALSE === ($y = array_search($short_dirs[$x], $direction))
$newdirs[] = $short_dirs[$x];
//if (isset($test)) { print_r($direction); exit; }
if (1 < ($sz = sizeof($direction))) {
for ($i = 1; $i < $sz; $i++ ) {
$this->mExitAliases[$direction[$i]] = $tmp;
$this->mExits[$direction[0]] = array($destination, $method);
$mapAreaActionTitle = $direction[0];
$this->addAction($mapAreaActionTitle, $direction, 'useExit',
* Removes the given "exit" from the page
* @param string $direction Command to use link, "home", "bar"
if (isset ($this->mExitAliases[$direction])) {
if (isset ($this->mExits[$direction])) {
unset ($this->mExits[$direction]);
foreach ($this->mExitAliases as $dir_alias => $dir) {
if ($direction === $dir) {
unset ($this->mExitAliases[$dir_alias]);
* Sets all "exits" out of this page at once
* Exits are links that can be typed on the command line or used by computer
* controlled character to wander around the site.
* @param array $exits Direction/destination pairs
* @see addExit, removeExit
foreach ($exits as $direction => $destination) {
$this->addExit($direction, $destination);
* Gets URL of "exit" out of this page
* Exits are links that can be typed on the command line or used by computer
* controlled character to wander around the site.
* @param string $direction Command to use link, "home", "bar"
if (isset ($this->mExitAliases[$direction])) {
$direction = $this->mExitAliases[$direction];
return !isset ($this->mExits[$direction]) ? FALSE :
$this->mExits[$direction][0];
* Gets URL of "exit" out of this page
* Exits are links that can be typed on the command line or used by computer
* controlled character to wander around the site.
* @param string $direction Command to use link, "home", "bar"
if (isset ($this->mExitAliases[$direction])) {
$direction = $this->mExitAliases[$direction];
return !isset ($this->mExits[$direction]) ? FALSE :
$this->mExits[$direction][1];
* Gets URL of "exit" out of this page
* Exits are links that can be typed on the command line or used by computer
* controlled character to wander around the site.
* @param string $direction Command to use link, "home", "bar"
if (isset ($this->mExitAliases[$direction])) {
$direction = $this->mExitAliases[$direction];
return !isset ($this->mExits[$direction]) ? FALSE :
$this->mExits[$direction][2];
* Gets all "exits" out of this page
* Exits are links that can be typed on the command line or used by computer
* controlled character to wander around the site.
* @return array Direction/destination pairs
return (array) $this->mExits;
* Gets all aliases for exits
* @return array Alias/direction pairs
return (array) $this->mExitAliases;
* Makes the active object exit this page and go to a new URL
* @param string $verb The name or verb part of the action, "home"
* @param string $noun The given id, noun or remainder, usually empty
* @return boolean FALSE in case of failure, TRUE for success
function useExit($verb, $noun = '')
|| $this->{$method}($verb)) {
* Sends a message to all objects in this page, "makes sound or movement"
* Calls the tell method in all objects in this page with the message.
* One or more extra arguments can be given to specify objects which should
* be skipped. For example:
* $user->tell('You smile happily.<br />');
* $user->getEnvironment()->tell(ucfirst(
* $user->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE))
* . ' smiles happily.<br />', $user);
* @param string $data message string
* @param object &$from First object to skip
* @param object &$from2 Second object to skip, etc.
function tell($data, &$from = NULL)
if (isset ($data[$ob->displayMode])
$data[$ob->displayMode])) {
&& isset ($data[$ob->displayMode])
$data[$ob->displayMode])) {
if (FALSE === in_array($ob, $from, TRUE)) {
if (FALSE === in_array($ob, $from, TRUE)
&& isset ($data[$ob->displayMode])
$data[$ob->displayMode])) {
* Sets data to later generate a HTML navigation trail for this page
* Each item is either a string with the element's title for the last
* tiem in the navigation trail, or an array with each key such a title,
* and each value the destination path within dpuniverse.
* @param mixed $navitem string or string/destination pairs
foreach ($this->mNavigationTrail as $link) {
$this->addExit($link[0], $link[1]);
* Gets data for the navigation trail for this page, if any
* @return array navigation trail elements
return $this->mNavigationTrail;
* Gets HTML with a navigation trail for this page
* @return string HTML for navigation trail
if (0 === sizeof($this->mNavigationTrail)) {
foreach ($this->mNavigationTrail as $navitem) {
$trail[] = $this->_getNavigationTrailHtmlElement($navitem);
. 'arr3w.gif" width="6" height="11" border="0" alt=" > " '
. 'class="arrnav" /> ', $trail);
* Gets HTML with a navigation trail element for this page
* @param mixed $navitem string or string/destination pairs
* @return string HTML for navigation trail element
* @see getNavigationTrailHtml
function _getNavigationTrailHtmlElement($navitem)
return '<div id="navlink">' . $navitem . '</div>';
&& dp_substr($navitem[1], 0, 6) == 'uri://') {
? '<div id="navlink"><a class="navtrail" href="' . $link . '">'
. $navitem[0] . '</a></div>'
: '<div id="navlink"><a class="navtrail" href="' . $link
* Tells the current user the HTML with the input area options menu
* A checksum is bounced back so the client can find the right
|| !isset ($user->_GET['checksum'])) {
$user->tell('<actions id="' . $this->uniqueId
. '" level="0" checksum="' . $user->_GET['checksum'] . '">'
. '<div class="actionwindow_inner">'
. $this->_getInputAreaOption(dp_text('hide after use'), 'once',
dp_text('mode once'), 'once' === $user->inputPersistent)
. $this->_getInputAreaOption(dp_text('show while on this page'),
'page', dp_text('mode page'), 'page' === $user->inputPersistent)
. $this->_getInputAreaOption(dp_text('always show'), 'always',
dp_text('mode always'), 'always' === $user->inputPersistent)
* Gets the HTML for a single input area option in the menu
* @param string $text text label of this entry in menu
* @param string $persistent input field option
* @param string $command full command to perform when selected
* @param boolean $enabled is this option enabled?
* @return string HTML for navigation trail element
* @see getInputAreaOptions
private function _getInputAreaOption($text, $persistent, $command, $enabled)
return '<div id="action_menu0" class="am" onMouseOver="'
. 'if (action_over(this)) { jQuery(\'div.am_deep_selected\').'
. 'removeClass(\'am_deep_selected am_selected\')}'
. (!$enabled ? '' : "; jQuery('span.am_icon', this).attr('id', '"
. "jQuery('span.am_icon > img', this).attr('src', '"
. '" onMouseOut="am_target_out = this" '
. 'onClick="jQuery(\'#dpinputpersistent\').attr(\'value\', \''
. $persistent . '\'); send_action2server(\'' . $command . '\')">'
. (!$enabled ? '<span class="am_icon"> </span>'
. 'bullet.gif" width="5" height="5" border="0" alt="" title="" '
. 'style="margin-left: 2px" /></span>') . '<span class="am_title">'
. '<span class="am_submenu"> </span> <br clear="all" />'
* Enables the input area called from client-side JavaScript
$user->inputEnabled = 'on';
if ($user->isRegistered) {
. dp_db_quote('on', 'text') . ' WHERE userUsernameLower='
* Closes the input area, called from client-side JavaScript
$user->inputEnabled = 'off';
if ($user->isRegistered) {
. dp_db_quote('off', 'text') . ' WHERE userUsernameLower='
|