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