Your browser must have JavaScript enabled in order to view this page.
 >  >
 
Welcome Guest#9547 Login/register    Go to Bottom
Go to Top

Source for file DpPage.php

Documentation is available at DpPage.php

  1. <?php
  2. /**
  3.  * A DutchPIPE enabled web page
  4.  *
  5.  * DutchPIPE version 0.4; PHP version 5
  6.  *
  7.  * LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
  8.  * If you did not receive a copy of the DutchPIPE license, you can obtain one at
  9.  * http://dutchpipe.org/license/1_0.txt or by sending a note to
  10.  * license@dutchpipe.org, in which case you will be mailed a copy immediately.
  11.  *
  12.  * @package    DutchPIPE
  13.  * @subpackage dpuniverse_std
  14.  * @author     Lennert Stock <ls@dutchpipe.org>
  15.  * @copyright  2006, 2007 Lennert Stock
  16.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  17.  * @version    Subversion: $Id: DpPage.php 281 2007-08-20 21:45:53Z ls $
  18.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  19.  * @see        DpObject
  20.  */
  21.  
  22. /**
  23.  * Builts upon the standard DpObject class
  24.  */
  25. inherit(DPUNIVERSE_STD_PATH 'DpObject.php');
  26.  
  27. /**
  28.  * A DutchPIPE enabled web page
  29.  *
  30.  * Creates the following DutchPIPE properties:<br />
  31.  *
  32.  * - boolean <b>isPage</b> - Set to TRUE
  33.  * - boolean|integer <b>isMovingArea</b> - Set to FALSE, can be type 1 or 2
  34.  * - boolean <b>isStandalone</b> - Set to TRUE if this is a "standalone" page
  35.  *
  36.  * @package    DutchPIPE
  37.  * @subpackage dpuniverse_std
  38.  * @author     Lennert Stock <ls@dutchpipe.org>
  39.  * @copyright  2006, 2007 Lennert Stock
  40.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  41.  * @version    Release: 0.2.1
  42.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  43.  */
  44. class DpPage extends DpObject
  45. {
  46.     /**
  47.      * @var         array     All "exits" out of this page
  48.      * @access      private
  49.      */
  50.     private $mExits array();
  51.  
  52.     /**
  53.      * Aliases used for exits, e.g. 'enter bar' for 'north'
  54.      *
  55.      * @var        array 
  56.      * @access     private
  57.      */
  58.     private $mExitAliases array();
  59.  
  60.     /**
  61.      * @var         array     Elements to make a navigation trail
  62.      * @access      private
  63.      */
  64.     private $mNavigationTrail array();
  65.  
  66.     /**
  67.      * Creates this page
  68.      *
  69.      * Calls the method 'createDpPage' in this page.
  70.      */
  71.     final function createDpObject()
  72.     {
  73.         $this->setTitleType(DPUNIVERSE_TITLE_TYPE_NAME);
  74.         $this->addId(dp_text('page'));
  75.         $this->addExit(dp_text('login')DPUNIVERSE_PAGE_PATH 'login.php');
  76.  
  77.         $this->isPage new_dp_property(TRUE);
  78.         $this->isMovingArea new_dp_property(FALSE);
  79.  
  80.         $this->createDpPage();
  81.  
  82.         $this->addValidClientCall('getInputAreaOptions');
  83.         $this->addValidClientCall('openInputArea');
  84.         $this->addValidClientCall('closeInputArea');
  85.     }
  86.  
  87.     /**
  88.      * Creates this page
  89.      *
  90.      * @see        createDpObject
  91.      */
  92.     function createDpPage()
  93.     {
  94.     }
  95.  
  96.     /**
  97.      * Resets this page
  98.      *
  99.      * Calls the method 'resetDpPage' in this page.
  100.      */
  101.     final function resetDpObject()
  102.     {
  103.         $this->resetDpPage();
  104.     }
  105.  
  106.     /**
  107.      * Resets this object
  108.      *
  109.      * @see        resetDpObject
  110.      */
  111.     function resetDpPage()
  112.     {
  113.     }
  114.  
  115.     /**
  116.      * Reports an event
  117.      *
  118.      * Called when certain events occur, given with $name.
  119.      *
  120.      * Calls the method 'eventDpPage' in this page.
  121.      *
  122.      * @param      object    $name       Name of event
  123.      * @param      mixed     $args       One or more arguments, depends on event
  124.      * @since      DutchPIPE 0.2.0
  125.      */
  126.     final function eventDpObject($name)
  127.     {
  128.         $args func_get_args();
  129.         call_user_func_array(array($this'eventDpPage')$args);
  130.     }
  131.  
  132.     /**
  133.      * Reports an event
  134.      *
  135.      * Called when certain events occur, given with $name.
  136.      *
  137.      * @param      object    $name       Name of event
  138.      * @param      mixed     $args       One or more arguments, depends on event
  139.      * @since      DutchPIPE 0.2.0
  140.      */
  141.     function eventDpPage($name)
  142.     {
  143.     }
  144.  
  145.     /**
  146.      * Adds an "exit" out of this page
  147.      *
  148.      * Exits are links that can be typed on the command line or used by computer
  149.      * controlled character to wander around the site. Adding compass directions
  150.      * like 'nw' will also add the full 'northwest' action, and vice versa, if
  151.      * not defined.
  152.      *
  153.      * @param       string    $direction    Command to use link, "home", "bar"
  154.      * @param       array     $direction    Multiple directions, "bar", "north"
  155.      * @param       string    $destination  URL
  156.      * @see         removeExit, setExits
  157.      */
  158.     final function addExit($direction$destination$method NULL,
  159.         $mapArea NULL$mapAreaActionTitle NULL)
  160.     {
  161.         $short_dirs array('n''ne''e''se''s''sw''w''nw');
  162.         $long_dirs array('north''northeast''east''southeast''south',
  163.             'southwest''west''northwest');
  164.  
  165.         if (empty($direction)) {
  166.             return;
  167.         }
  168.  
  169.         if (!is_array($direction)) {
  170.             $direction array($direction);
  171.         }
  172.  
  173.         if (FALSE !== ($x array_search($direction[0]$short_dirs))) {
  174.             if (FALSE !== ($y array_search($long_dirs[$x]$direction))) {
  175.                 $direction[$y$direction[0];
  176.             }
  177.             $direction[0$long_dirs[$x];
  178.  
  179.             //print_r($direction);
  180.             $test true;
  181.         }
  182.  
  183.         $newdirs array();
  184.         foreach ($direction as $dir{
  185.             if (FALSE !== ($x array_search($dir$short_dirs))) {
  186.                 if (FALSE === ($y array_search($long_dirs[$x]$direction))
  187.                         && FALSE === ($y array_search($long_dirs[$x],
  188.                         $newdirs))) {
  189.                     $newdirs[$long_dirs[$x];
  190.                 }
  191.             elseif (FALSE !== ($x array_search($dir$long_dirs))) {
  192.                 if (FALSE === ($y array_search($short_dirs[$x]$direction))
  193.                         && FALSE === ($y array_search($short_dirs[$x],
  194.                         $newdirs))) {
  195.                     $newdirs[$short_dirs[$x];
  196.                 }
  197.             }
  198.         }
  199.  
  200.         $direction array_merge($direction$newdirs);
  201.         //if (isset($test)) { print_r($direction); exit; }
  202.  
  203.         $tmp $direction[0];
  204.         if (($sz sizeof($direction))) {
  205.             for ($i 1$i $sz$i++{
  206.                 $this->mExitAliases[$direction[$i]] $tmp;
  207.             }
  208.         }
  209.  
  210.         $this->mExits[$direction[0]] array($destination$method);
  211.  
  212.         if (!is_null($mapArea&& is_null($mapAreaActionTitle)) {
  213.             $mapAreaActionTitle $direction[0];
  214.         }
  215.  
  216.         $this->addAction($mapAreaActionTitle$direction'useExit',
  217.             $mapArea);
  218.     }
  219.  
  220.     /**
  221.      * Removes the given "exit" from the page
  222.      *
  223.      * @param       string    $direction    Command to use link, "home", "bar"
  224.      * @see         addExit, setExits
  225.      */
  226.     function removeExit($direction)
  227.     {
  228.         if (isset($this->mExitAliases[$direction])) {
  229.             $this->removeAction($this->mExitAliases[$direction]);
  230.             return;
  231.         }
  232.         if (isset($this->mExits[$direction])) {
  233.             $this->removeAction($direction);
  234.             unset($this->mExits[$direction]);
  235.             foreach ($this->mExitAliases as $dir_alias => $dir{
  236.                 if ($direction === $dir{
  237.                     unset($this->mExitAliases[$dir_alias]);
  238.                 }
  239.             }
  240.         }
  241.     }
  242.  
  243.     /**
  244.      * Sets all "exits" out of this page at once
  245.      *
  246.      * Exits are links that can be typed on the command line or used by computer
  247.      * controlled character to wander around the site.
  248.      *
  249.      * @param       array     $exits      Direction/destination pairs
  250.      * @see         addExit, removeExit
  251.      */
  252.     final function setExits($exits)
  253.     {
  254.         $this->mExits array();
  255.         foreach ($exits as $direction => $destination{
  256.             if (!is_array($destination)) {
  257.                 $this->addExit($direction$destination);
  258.             else {
  259.                 array_unshift($destination$direction);
  260.                 call_user_method_array('addExit'$this$destination);
  261.             }
  262.         }
  263.     }
  264.  
  265.     /**
  266.      * Gets URL of "exit" out of this page
  267.      *
  268.      * Exits are links that can be typed on the command line or used by computer
  269.      * controlled character to wander around the site.
  270.      *
  271.      * @param      string    $direction   Command to use link, "home", "bar"
  272.      * @return     string                 URL
  273.      */
  274.     final function getExitDestination($direction)
  275.     {
  276.         if (isset($this->mExitAliases[$direction])) {
  277.             $direction $this->mExitAliases[$direction];
  278.         }
  279.         return !isset($this->mExits[$direction]FALSE :
  280.             $this->mExits[$direction][0];
  281.     }
  282.  
  283.     /**
  284.      * Gets URL of "exit" out of this page
  285.      *
  286.      * Exits are links that can be typed on the command line or used by computer
  287.      * controlled character to wander around the site.
  288.      *
  289.      * @param      string    $direction   Command to use link, "home", "bar"
  290.      * @return     string                 URL
  291.      */
  292.     final function getExitMethod($direction)
  293.     {
  294.         if (isset($this->mExitAliases[$direction])) {
  295.             $direction $this->mExitAliases[$direction];
  296.         }
  297.         return !isset($this->mExits[$direction]FALSE :
  298.             $this->mExits[$direction][1];
  299.     }
  300.  
  301.     /**
  302.      * Gets URL of "exit" out of this page
  303.      *
  304.      * Exits are links that can be typed on the command line or used by computer
  305.      * controlled character to wander around the site.
  306.      *
  307.      * @param      string    $direction   Command to use link, "home", "bar"
  308.      * @return     string                 URL
  309.      */
  310.     final function getExitMapArea($direction)
  311.     {
  312.         if (isset($this->mExitAliases[$direction])) {
  313.             $direction $this->mExitAliases[$direction];
  314.         }
  315.         return !isset($this->mExits[$direction]FALSE :
  316.             $this->mExits[$direction][2];
  317.     }
  318.  
  319.     /**
  320.      * Gets all "exits" out of this page
  321.      *
  322.      * Exits are links that can be typed on the command line or used by computer
  323.      * controlled character to wander around the site.
  324.      *
  325.      * @return     array                 Direction/destination pairs
  326.      */
  327.     final function getExits()
  328.     {
  329.         return (array)$this->mExits;
  330.     }
  331.  
  332.     /**
  333.      * Gets all aliases for exits
  334.      *
  335.      * @return     array                 Alias/direction pairs
  336.      */
  337.     final function getExitAliases()
  338.     {
  339.         return (array)$this->mExitAliases;
  340.     }
  341.  
  342.     /**
  343.      * Makes the active object exit this page and go to a new URL
  344.      *
  345.      * @param   string  $verb   The name or verb part of the action, "home"
  346.      * @param   string  $noun   The given id, noun or remainder, usually empty
  347.      * @return  boolean         FALSE in case of failure, TRUE for success
  348.      */
  349.     function useExit($verb$noun '')
  350.     {
  351.         if (!($method $this->getExitMethod($verb))
  352.                 || $this->{$method}($verb)) {
  353.             get_current_dpobject()->tell('<location>'
  354.                 . $this->getExitDestination($verb'</location>');
  355.         }
  356.         return TRUE;
  357.     }
  358.  
  359.     /**
  360.      * Sends a message to all objects in this page, "makes sound or movement"
  361.      *
  362.      * Calls the tell method in all objects in this page with the message.
  363.      * One or more extra arguments can be given to specify objects which should
  364.      * be skipped. For example:
  365.      *
  366.      *     $user->tell('You smile happily.<br />');
  367.      *     $user->getEnvironment()->tell(ucfirst(
  368.      *         $user->getTitle(DPUNIVERSE_TITLE_TYPE_DEFINITE))
  369.      *         . ' smiles happily.<br />', $user);
  370.      *
  371.      * @param      string    $data      message string
  372.      * @param      object    &$from     First object to skip
  373.      * @param      object    &$from2    Second object to skip, etc.
  374.      */
  375.     function tell($data&$from NULL)
  376.     {
  377.         // There's nothing here:
  378.         if (!sizeof($inv $this->getInventory())) {
  379.             return;
  380.         }
  381.  
  382.         if (func_num_args(<= 1)  {
  383.             if (FALSE === is_array($data)) {
  384.                 foreach ($inv as &$ob{
  385.                     $ob->tell($data$this);
  386.                 }
  387.             else {
  388.                 foreach ($inv as &$ob{
  389.                     if (isset($data[$ob->displayMode])
  390.                             && ($tmp =
  391.                             $data[$ob->displayMode])) {
  392.                         $ob->tell($tmp$this);
  393.                     }
  394.                 }
  395.             }
  396.         }
  397.         elseif (func_num_args(== 2)  {
  398.             $from func_get_arg(1);
  399.             if (FALSE === is_array($data)) {
  400.                 foreach ($inv as &$ob{
  401.                     if ($ob !== $from{
  402.                         $ob->tell($data$this);
  403.                     }
  404.                 }
  405.             else {
  406.                 foreach ($inv as &$ob{
  407.                     if ($ob !== $from
  408.                             && isset($data[$ob->displayMode])
  409.                             && ($tmp =
  410.                             $data[$ob->displayMode])) {
  411.                         $ob->tell($tmp$this);
  412.                     }
  413.                 }
  414.             }
  415.         }
  416.         elseif (func_num_args(2)  {
  417.             $from array_slice(func_get_args()1);
  418.             if (FALSE === is_array($data)) {
  419.                 foreach ($inv as &$ob{
  420.                     if (FALSE === in_array($ob$fromTRUE)) {
  421.                         $ob->tell($data$this);
  422.                     }
  423.                 }
  424.             else {
  425.                 foreach ($inv as &$ob{
  426.                     if (FALSE === in_array($ob$fromTRUE)
  427.                             && isset($data[$ob->displayMode])
  428.                             && ($tmp =
  429.                             $data[$ob->displayMode])) {
  430.                         $ob->tell($tmp$this);
  431.                     }
  432.                 }
  433.             }
  434.         }
  435.     }
  436.  
  437.     /**
  438.      * Sets data to later generate a HTML navigation trail for this page
  439.      *
  440.      * Each item is either a string with the element's title for the last
  441.      * tiem in the navigation trail, or an array with each key such a title,
  442.      * and each value the destination path within dpuniverse.
  443.      *
  444.      * @param      mixed     $navitem   string or string/destination pairs
  445.      */
  446.     function setNavigationTrail()
  447.     {
  448.         if (=== func_num_args()) {
  449.             return;
  450.         }
  451.         $this->mNavigationTrail func_get_args();
  452.  
  453.         foreach ($this->mNavigationTrail as $link{
  454.             if (is_array($link)) {
  455.                 if ($link[0=== DPUNIVERSE_NAVLOGO{
  456.                     $link[0dp_text('home');
  457.                 }
  458.                 $link[0explode(' '$link[0]);
  459.                 $link[0dp_strtolower($link[0][0]);
  460.                 $this->addExit($link[0]$link[1]);
  461.             }
  462.         }
  463.     }
  464.  
  465.     /**
  466.      * Gets data for the navigation trail for this page, if any
  467.      *
  468.      * @return     array     navigation trail elements
  469.      */
  470.     function getNavigationTrail()
  471.     {
  472.         return $this->mNavigationTrail;
  473.     }
  474.  
  475.     /**
  476.      * Gets HTML with a navigation trail for this page
  477.      *
  478.      * @return     string    HTML for navigation trail
  479.      */
  480.     function getNavigationTrailHtml()
  481.     {
  482.         if (=== sizeof($this->mNavigationTrail)) {
  483.             return '<div id="navlink">' dp_text(DPUNIVERSE_NAVLOGO)
  484.                 . '</div>';
  485.         }
  486.         $trail array();
  487.         foreach ($this->mNavigationTrail as $navitem{
  488.             $trail[$this->_getNavigationTrailHtmlElement($navitem);
  489.         }
  490.         return implode(' <img src="' DPUNIVERSE_IMAGE_URL
  491.             . 'arr3w.gif" width="6" height="11" border="0" alt=" &gt; " '
  492.             . 'class="arrnav" /> '$trail);
  493.     }
  494.  
  495.     /**
  496.      * Gets HTML with a navigation trail element for this page
  497.      *
  498.      * @access     private
  499.      * @param      mixed     $navitem   string or string/destination pairs
  500.      * @return     string    HTML for navigation trail element
  501.      * @see        getNavigationTrailHtml
  502.      */
  503.     function _getNavigationTrailHtmlElement($navitem)
  504.     {
  505.         if (FALSE === is_array($navitem)) {
  506.             return '<div id="navlink">' $navitem '</div>';
  507.         }
  508.  
  509.         if (dp_strlen($navitem[1]>= 6
  510.                 && dp_substr($navitem[1]06== 'uri://'{
  511.             $link dp_substr($navitem[1]6);
  512.         else {
  513.             $link $navitem[1== '' DPUNIVERSE_WWW_URL
  514.                 : DPSERVER_CLIENT_URL '?location=' $navitem[1];
  515.         }
  516.  
  517.         return $navitem[0<> DPUNIVERSE_NAVLOGO
  518.             ? '<div id="navlink"><a class="navtrail" href="' $link '">'
  519.                 . $navitem[0'</a></div>'
  520.             : '<div id="navlink"><a class="navtrail" href="' $link
  521.                 . '" style="cursor: pointer">' dp_text(DPUNIVERSE_NAVLOGO)
  522.                 . '</a></div>';
  523.     }
  524.  
  525.     /**
  526.      * Tells the current user the HTML with the input area options menu
  527.      */
  528.     function getInputAreaOptions()
  529.     {
  530.         /*
  531.          * A checksum is bounced back so the client can find the right
  532.          * response
  533.          */
  534.         if (!($user get_current_dpuser())
  535.                 || !isset($user->_GET['checksum'])) {
  536.             return;
  537.         }
  538.  
  539.         $user->tell('<actions id="' $this->uniqueId
  540.             . '" level="0" checksum="' $user->_GET['checksum''">'
  541.             . '<div class="actionwindow_inner">'
  542.             . $this->_getInputAreaOption(dp_text('hide after use')'once',
  543.             dp_text('mode once')'once' === $user->inputPersistent)
  544.             . $this->_getInputAreaOption(dp_text('show while on this page'),
  545.             'page'dp_text('mode page')'page' === $user->inputPersistent)
  546.             . $this->_getInputAreaOption(dp_text('always show')'always',
  547.             dp_text('mode always')'always' === $user->inputPersistent)
  548.             . '</div></actions>');
  549.     }
  550.  
  551.     /**
  552.      * Gets the HTML for a single input area option in the menu
  553.      *
  554.      * @access     private
  555.      * @param      string    $text       text label of this entry in menu
  556.      * @param      string    $persistent input field option
  557.      * @param      string    $command    full command to perform when selected
  558.      * @param      boolean   $enabled    is this option enabled?
  559.      * @return     string    HTML for navigation trail element
  560.      * @see        getInputAreaOptions
  561.      */
  562.     private function _getInputAreaOption($text$persistent$command$enabled)
  563.     {
  564.         return '<div id="action_menu0" class="am" onMouseOver="'
  565.             . 'if (action_over(this)) { jQuery(\'div.am_deep_selected\').'
  566.             . 'removeClass(\'am_deep_selected am_selected\')}'
  567.             . (!$enabled '' "; jQuery('span.am_icon', this).attr('id', '"
  568.             . DPUNIVERSE_IMAGE_URL "bullet.gif'); "
  569.             . "jQuery('span.am_icon > img', this).attr('src', '"
  570.             . DPUNIVERSE_IMAGE_URL "bullet_over.gif')")
  571.             . '" onMouseOut="am_target_out = this" '
  572.             . 'onClick="jQuery(\'#dpinputpersistent\').attr(\'value\', \''
  573.             . $persistent '\'); send_action2server(\'' $command '\')">'
  574.             . (!$enabled '<span class="am_icon">&nbsp;</span>'
  575.             : '<span class="am_icon" id="'DPUNIVERSE_IMAGE_URL
  576.             . 'bullet_over.gif"><img src="' DPUNIVERSE_IMAGE_URL
  577.             . 'bullet.gif" width="5" height="5" border="0" alt="" title="" '
  578.             . 'style="margin-left: 2px" /></span>''<span class="am_title">'
  579.             . $text '</span>'
  580.             . '<span class="am_submenu">&nbsp;</span>&nbsp;<br clear="all" />'
  581.             . '</div>';
  582.     }
  583.  
  584.     /**
  585.      * Enables the input area called from client-side JavaScript
  586.      */
  587.     function openInputArea()
  588.     {
  589.         if (!($user get_current_dpuser())) {
  590.             return;
  591.         }
  592.  
  593.         $user->inputEnabled 'on';
  594.  
  595.         if ($user->isRegistered{
  596.             dp_db_exec('UPDATE Users set userInputEnabled='
  597.                 . dp_db_quote('on''text'' WHERE userUsernameLower='
  598.                 . dp_db_quote(dp_strtolower($user->getTitle())'text'));
  599.         }
  600.     }
  601.  
  602.     /**
  603.      * Closes the input area, called from client-side JavaScript
  604.      */
  605.     function closeInputArea()
  606.     {
  607.         if (!($user get_current_dpuser())) {
  608.             return;
  609.         }
  610.  
  611.         $user->inputEnabled 'off';
  612.  
  613.         if ($user->isRegistered{
  614.             dp_db_exec('UPDATE Users set userInputEnabled='
  615.                 . dp_db_quote('off''text'' WHERE userUsernameLower='
  616.                 . dp_db_quote(dp_strtolower($user->getTitle())'text'));
  617.         }
  618.     }
  619. }
  620. ?>

Documentation generated on Mon, 03 Sep 2007 22:20:27 +0200 by phpDocumentor 1.3.0RC6

Click me!
Guest#9547
 
 
 
  Go to Top
 
 
Input Field OptionsClose Input Field Go to Top
 
Legal Notices | Copyright © 2006, 2007 Lennert Stock. All rights reserved. Last update: Mon Sep 03 2007, 21:50 CET.