1 |
<? |
2 |
// ------------------------------------------------------------------------- |
3 |
// $Id: Loader.php,v 1.3 2002/12/19 06:21:37 joko Exp $ |
4 |
// ------------------------------------------------------------------------- |
5 |
// $Log: Loader.php,v $ |
6 |
// Revision 1.3 2002/12/19 06:21:37 joko |
7 |
// + loadTemplate |
8 |
// + case 'template' for 'function loadComponent' |
9 |
// |
10 |
// Revision 1.2 2002/12/12 21:37:46 joko |
11 |
// + fixes: now returning success-/error-status |
12 |
// |
13 |
// Revision 1.1 2002/11/12 05:42:31 joko |
14 |
// + initial checkin |
15 |
// |
16 |
// ------------------------------------------------------------------------- |
17 |
|
18 |
|
19 |
class Site_Loader { |
20 |
|
21 |
var $site; |
22 |
|
23 |
function includeFile($filename, $args = array()) { |
24 |
|
25 |
// TODO: try to remove these globals! |
26 |
global $site; |
27 |
global $site_state; |
28 |
//global $uservars; |
29 |
global $request; |
30 |
global $http_referer; |
31 |
|
32 |
global $page_state; |
33 |
|
34 |
$this->site->log( get_class($this) . "->includeFile( filename $filename )", LOG_DEBUG); |
35 |
$site = &$this->site; |
36 |
if (include($filename)) { |
37 |
return 1; |
38 |
} |
39 |
|
40 |
} |
41 |
|
42 |
function loadComponent($name, $type = "", $arguments = array()) { |
43 |
$prefix = ""; |
44 |
$postfix = ""; |
45 |
$this->site->log( get_class($this) . "->loadComponent( name $name, type $type )", LOG_DEBUG); |
46 |
|
47 |
// TODO: croak somewhere (STDOUT?, logger?) if unknown type gets used here |
48 |
switch ($type) { |
49 |
|
50 |
case "handler": |
51 |
$prefix = $this->site->config[path][base] . 'core/handler/'; |
52 |
//$postfix = ".handler.php"; |
53 |
$postfix = ".php"; |
54 |
$includefile = "$prefix$name$postfix"; |
55 |
return $this->includeFile($includefile); |
56 |
break; |
57 |
|
58 |
case "page": |
59 |
$prefix = $this->site->config[path][base] . 'core/pages/'; |
60 |
$postfix = ".page"; |
61 |
$includefile = "$prefix$name$postfix"; |
62 |
return $this->includeFile($includefile, $arguments ); |
63 |
break; |
64 |
|
65 |
case "template": |
66 |
// TODO: re-activate this (unset smarty's default directory or handle differently (generic)) |
67 |
//$prefix = $this->site->config[path][base] . 'core/templates/'; |
68 |
$prefix = ''; |
69 |
$postfix = ".html"; |
70 |
$includefile = "$prefix$name$postfix"; |
71 |
//return $this->includeFile($includefile); |
72 |
return $this->site->template->display($includefile, array( |
73 |
'cache_key' => $arguments[cache_key], |
74 |
'interpolate' => $arguments['vars'], |
75 |
'return' => $arguments['return'] |
76 |
)); |
77 |
break; |
78 |
} |
79 |
} |
80 |
|
81 |
function loadHandler($name) { |
82 |
$this->site->log( get_class($this) . "->loadHandler( name $name )", LOG_DEBUG); |
83 |
return $this->loadComponent($name, "handler"); |
84 |
} |
85 |
|
86 |
function loadPage($name, $args = array()) { |
87 |
$this->site->log( get_class($this) . "->loadPage( name $name )", LOG_DEBUG); |
88 |
return $this->loadComponent($name, "page", $args); |
89 |
} |
90 |
|
91 |
function loadTemplate($name, $template_variables = array(), $cache_key = "") { |
92 |
$this->site->log( get_class($this) . "->loadTemplate( name $name cache_key $cache_key )", LOG_DEBUG); |
93 |
return $this->loadComponent($name, "template", array( 'cache_key' => $cache_key, 'vars' => $template_variables) ); |
94 |
} |
95 |
|
96 |
function loadClass() { |
97 |
} |
98 |
|
99 |
function loadBusinessClass() { |
100 |
} |
101 |
|
102 |
|
103 |
|
104 |
} |
105 |
?> |