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