| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Mambo 4 * @subpackage Languages 5 * @author Mambo Foundation Inc see README.php 6 * @copyright (C) 2000 - 2009 Mambo Foundation Inc. 7 * See COPYRIGHT.php for copyright notices and details. 8 * @license GNU/GPL Version 2, see LICENSE.php 9 * 10 * Redistributions of files must retain the above copyright notice. 11 * 12 * Mambo is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; version 2 of the License. 15 */ 16 17 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 18 class Request 19 { 20 var $name; 21 var $vars; 22 23 function Request($name) 24 { 25 $this->name = $name; 26 $this->attributes = array(); 27 } 28 function set($var, $value) 29 { 30 $this->vars[$var] = $value; 31 } 32 function get($var=null) 33 { 34 return is_null($var) ? $this->vars : $this->vars[$var]; 35 } 36 function addFromRequest($var, $global='request'){ 37 switch (strtolower($global)) 38 { 39 case 'get': 40 $this->vars[$var] = mosGetParam($_GET, $var); 41 break; 42 case 'post': 43 $this->vars[$var] = mosGetParam($_POST, $var); 44 break; 45 case 'cookie': 46 $this->vars[$var] = mosGetParam($_COOKIE, $var); 47 break; 48 case 'request': 49 $this->vars[$var] = mosGetParam($_REQUEST, $var); 50 break; 51 default: 52 trigger_error('Invalid Request Array', E_USER_ERROR); 53 break; 54 } 55 } 56 function setByRef($var, &$value) 57 { 58 $this->vars[$var] = &$value; 59 } 60 function &getByRef($var) 61 { 62 return $this->vars[$var]; 63 } 64 function &session($reset = false) 65 { 66 $name = '__' . $this->name . '_session'; 67 if (!isset($_SESSION[$name]) || $reset) { 68 $_SESSION[$name] = array(); 69 } 70 return $_SESSION[$name]; 71 } 72 function &getInstance($name) 73 { 74 static $requests; 75 if (!isset($requests[$name])) { 76 $requests[$name] = new Request($name); 77 } 78 return $requests[$name]; 79 } 80 } 81 82 class Controller 83 { 84 var $name; 85 var $dir; 86 var $request; 87 var $action; 88 var $renderer; 89 90 91 function Controller($name) 92 { 93 $this->name = $name; 94 $this->request =& Request::getInstance($name); 95 $this->renderer =& Renderer::getInstance(); 96 $this->renderer->setdir(dirname(__FILE__).DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.'templates'); 97 } 98 99 function forward($actionname) 100 { 101 if (!$actionname) return $this->view('index'); 102 103 $actionfile = dirname(__FILE__)."/actions/$actionname.action.php"; 104 $actionclass = $actionname.'Action'; 105 if (file_exists($actionfile)) include($actionfile); 106 else return trigger_error("Action file '$actionfile' not found.", E_USER_ERROR); 107 if (class_exists($actionclass)) $action = new $actionclass(); 108 else return trigger_error("Action class '$actionclass' not found.", E_USER_ERROR); 109 $action->execute($this, $this->request); 110 } 111 112 113 function view($viewname) 114 { 115 $viewfile = dirname(__FILE__)."/views/$viewname.view.php"; 116 $viewclass = $viewname.'View'; 117 if (file_exists($viewfile)) include($viewfile); 118 #else return trigger_error("View file '$viewfile' not found.", E_USER_ERROR); 119 if (class_exists($viewclass)) $view = new $viewclass($this); 120 else return trigger_error("View class '$viewclass' not found.", E_USER_ERROR); 121 $view->render($this->renderer, $this->request); 122 } 123 function redirect($task=null, $act=null) 124 { 125 $url = $_SERVER['PHP_SELF'].'?option='.$this->name; 126 $url .= !is_null($task) ? '&task='.$task : ''; 127 $url .= !is_null($act) ? '&act='.$act : ''; 128 if (headers_sent()) { 129 echo "<script>document.location.href='$url';</script>"; 130 } else { 131 #if (ob_get_contents()) while (@ob_end_clean()); // clear output buffer if one exists 132 header( "Location: $url" ); 133 } 134 exit; 135 } 136 } 137 138 class Action 139 { 140 var $view; 141 142 function Action() 143 { 144 } 145 function execute(&$controller, &$request) 146 { 147 return trigger_error('Action::execute() must be overridden.', E_USER_ERROR); 148 } 149 function setView($view) 150 { 151 $this->viewname = $view; 152 } 153 function getView() 154 { 155 return $this->view; 156 } 157 } 158 159 class View 160 { 161 var $controller; 162 163 function View(&$controller){ 164 $this->controller = $controller; 165 } 166 function render(&$request, &$renderer) 167 { 168 return trigger_error('View::render() must be overridden'); 169 } 170 } 171 172 class Renderer 173 { 174 175 var $dir; 176 var $vars = array(); 177 var $engine = 'php'; 178 var $template = ''; 179 var $debug = 0; 180 181 function Renderer(){} 182 183 function &getInstance($type = 'php') { 184 static $renderer; 185 if (is_null($renderer[$type])) { 186 if ($type == 'php') { 187 $renderer[$type] = new Renderer(); 188 } else { 189 $classname = $type . 'Renderer'; 190 if (class_exists($classname)) 191 $renderer[$type] = new $classname(); 192 } 193 } 194 return $renderer[$type]; 195 } 196 197 function display($template, $return = false){ 198 if ($template == NULL){ 199 return trigger_error('A template has not been specified', E_USER_ERROR); 200 } 201 $this->template = $this->dir . $template; 202 if ($this->debug) echo nl2br($this->template."\n"); 203 204 if (is_readable($this->template)) { 205 extract($this->getvars()); 206 if ($return) { 207 ob_start(); 208 include_once($this->template); 209 $ret = ob_get_contents(); 210 ob_end_clean(); 211 return $ret; 212 } else { 213 include_once($this->template); 214 } 215 } else { 216 return trigger_error("Template file $template does not exist or is not readable", E_USER_ERROR); 217 } 218 return false; 219 } 220 221 function fetch($template){ 222 return $this->display($template, true); 223 } 224 225 function &getengine(){ 226 return $this->engine; 227 } 228 229 function addvar($key, $value){ 230 $this->vars[$key] = $value; 231 } 232 233 function addbyref ($key, &$value) { 234 $this->vars[$key] = $value; 235 } 236 237 function getvars($name = false){ 238 return (isset($this->vars[$name])) ? $this->vars[$name] : $this->vars; 239 } 240 241 function setdir($dir){ 242 $this->dir = (substr($dir, -1) == DIRECTORY_SEPARATOR) ? $dir : $dir.DIRECTORY_SEPARATOR; 243 } 244 245 function getdir(){ 246 return $this->dir; 247 } 248 249 function settemplate($template){ 250 $this->template = $template; 251 } 252 } 253 254 class XMLUtils 255 { 256 function parse_into_array($xml) { 257 $p = xml_parser_create(); 258 xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); 259 xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1); 260 xml_parse_into_struct($p, $xml, $values); 261 xml_parser_free($p); 262 $current = $prev = array(); 263 $xmlarray =& $current; 264 foreach($values as $key => $value) { 265 $index = count($xmlarray); 266 switch ($value['type']) 267 { 268 case 'open': 269 $xmlarray[$index] = array(); 270 $xmlarray[$index]['tag'] = isset($value["tag"]) ? $value["tag"] : null; 271 $xmlarray[$index]['value'] = isset($value["value"]) ? $value["value"] : null; 272 $xmlarray[$index]['attributes'] = isset($value["attributes"]) ? $value["attributes"] : null; 273 $xmlarray[$index]['nodes'] = array(); 274 $prev[count($prev)] = &$xmlarray; 275 $xmlarray = &$xmlarray[$index]['nodes']; 276 break; 277 case 'complete': 278 $xmlarray[$index] = array(); 279 $xmlarray[$index]['tag'] = isset($value["tag"]) ? $value["tag"] : null; 280 $xmlarray[$index]['value'] = isset($value["value"]) ? $value["value"] : null; 281 $xmlarray[$index]['attributes'] = isset($value["attributes"]) ? $value["attributes"] : null; 282 break; 283 case 'close': 284 $xmlarray = &$prev[count($prev) - 1]; 285 unset($prev[count($prev) - 1]); 286 break; 287 } 288 } 289 return $xmlarray; 290 } 291 function parse_file_into_array($file) { 292 return XMLUtils::parse_into_array(file_get_contents($file)); 293 } 294 295 function array_to_xml($array, $encoding='utf-8') { 296 $xml = "<?xml version=\"1.0\" encoding=\"$encoding\"?>\n"; 297 if ((!empty($array)) AND (is_array($array))) { 298 foreach ($array as $key => $value) { 299 switch ($value["type"]) { 300 case "open": 301 $xml .= str_repeat("\t", $value["level"] - 1); 302 $xml .= "<" . strtolower($value["tag"]); 303 if (isset($value["attributes"])) { 304 foreach ($value["attributes"] as $k => $v) { 305 $xml .= sprintf(' %s="%s"', strtolower($k), $v); 306 } 307 } 308 $xml .= ">\n"; 309 break; 310 case "complete": 311 $xml .= str_repeat("\t", $value["level"] - 1); 312 $xml .= "<" . strtolower($value["tag"]); 313 if (isset($value["attributes"])) { 314 foreach ($value["attributes"] as $k => $v) { 315 $xml .= sprintf(' %s="%s"', strtolower($k), $v); 316 } 317 } 318 $xml .= ">"; 319 $xml .= isset($value['value']) ? $value['value'] : false; 320 $xml .= "</".strtolower($value["tag"]).">\n"; 321 break; 322 case "close": 323 $xml .= str_repeat("\t", $value["level"] - 1); 324 $xml .= "</" . strtolower($value["tag"]) . ">\n"; 325 break; 326 default: 327 break; 328 } 329 } 330 } 331 return $xml; 332 } 333 } 334 335 336 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Feb 8 00:05:01 2012 | Cross-referenced by PHPXref 0.7 |
| Mambo API: Mambo is Free software released under the GNU/General Public License, Version 2 |