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