| 1 | joko | 1.1 | <? | 
| 2 |  |  | //    ------------------------------------------------------------------------- | 
| 3 | jonen | 1.2 | //    $Id: Handler.php,v 1.1 2002/11/12 05:42:31 joko Exp $ | 
| 4 | joko | 1.1 | //    ------------------------------------------------------------------------- | 
| 5 | jonen | 1.2 | //    $Log: Handler.php,v $ | 
| 6 |  |  | //    Revision 1.1  2002/11/12 05:42:31  joko | 
| 7 |  |  | //    + initial checkin | 
| 8 |  |  | // | 
| 9 | joko | 1.1 | //    ------------------------------------------------------------------------- | 
| 10 |  |  |  | 
| 11 |  |  |  | 
| 12 |  |  | class Site_Handler { | 
| 13 |  |  |  | 
| 14 |  |  | var $s = array(); | 
| 15 |  |  | var $enc = array( | 
| 16 |  |  | map => array(), | 
| 17 |  |  | id => 70841, | 
| 18 |  |  | enabled => 0, | 
| 19 |  |  | ); | 
| 20 |  |  |  | 
| 21 |  |  | function _getid() { | 
| 22 |  |  | $this->enc[id]++; | 
| 23 |  |  | $dummyId = 's' . $this->enc[id]; | 
| 24 |  |  | return $dummyId; | 
| 25 |  |  | } | 
| 26 |  |  |  | 
| 27 |  |  | function setHandler($ident, $attribs) { | 
| 28 |  |  | //$this->site->log( get_class($this) . "->setHandler( ident $ident, attribs $attribs)", LOG_DEBUG ); | 
| 29 |  |  | if (!is_array($attribs)) { $attribs = array(); } | 
| 30 |  |  | $newid = $this->_getid(); | 
| 31 |  |  | // store handler | 
| 32 |  |  | $attribs[id] = $newid; | 
| 33 |  |  | $this->s[$ident] = $attribs; | 
| 34 |  |  | // create/store mapping | 
| 35 |  |  | $this->enc[map][$newid] = $ident; | 
| 36 |  |  | } | 
| 37 |  |  |  | 
| 38 |  |  | function getHandler($ident) { | 
| 39 |  |  | if (count($this->s) == 0) { | 
| 40 |  |  | $this->site->log( get_class($this) . "->getHandler: called before any setHandler", LOG_WARNING ); | 
| 41 |  |  | } | 
| 42 |  |  | return $this->s[$ident]; | 
| 43 |  |  | } | 
| 44 |  |  |  | 
| 45 |  |  | function getPageIdentifier() { | 
| 46 | jonen | 1.2 | //global $site_state; | 
| 47 |  |  | //return $site_state[page]; | 
| 48 |  |  | return $this->site->session->get('page'); | 
| 49 | joko | 1.1 | } | 
| 50 |  |  |  | 
| 51 |  |  | function checkIdentifier($ident) { | 
| 52 |  |  | return isset($this->s[$ident]); | 
| 53 |  |  | } | 
| 54 |  |  |  | 
| 55 |  |  | function decodeIdentifier($arg) { | 
| 56 |  |  | if ($this->enc[enabled]) { | 
| 57 |  |  | $args = split('_', $arg); | 
| 58 |  |  | $ident_enc = array_shift($args); | 
| 59 |  |  | $ident = $this->enc[map][$ident_enc]; | 
| 60 |  |  | array_unshift($args, $ident); | 
| 61 |  |  | $result = join('/', $args); | 
| 62 |  |  | return $result; | 
| 63 |  |  | } else { | 
| 64 |  |  | //$arg = str_replace('_', '/', $arg); | 
| 65 |  |  | return $arg; | 
| 66 |  |  | } | 
| 67 |  |  | } | 
| 68 |  |  |  | 
| 69 |  |  | function encodeIdentifier($arg) { | 
| 70 |  |  | if ($this->enc[enabled]) { | 
| 71 |  |  | $result = $this->s[$arg][id]; | 
| 72 |  |  | // strip action from arg, if present | 
| 73 |  |  | if (!$result && (substr($arg, -1) != '/') ) { | 
| 74 |  |  | $divpos = strrpos($arg, '/') + 1; | 
| 75 |  |  | $ident = substr($arg, 0, $divpos); | 
| 76 |  |  | $ident_enc = $this->s[$ident][id]; | 
| 77 |  |  | $action = substr($arg, $divpos); | 
| 78 |  |  | $result = $ident_enc . '_' . $action; | 
| 79 |  |  | } | 
| 80 |  |  | return $result; | 
| 81 |  |  | } else { | 
| 82 |  |  | //$arg = str_replace('/', '_', $arg); | 
| 83 |  |  | return $arg; | 
| 84 |  |  | } | 
| 85 |  |  | } | 
| 86 |  |  |  | 
| 87 |  |  | } | 
| 88 |  |  | ?> |