From 3d16a5578614be84e3bc477a4933041040b8e29c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 19 Dec 2006 04:38:51 +0000 Subject: [PATCH] - Added a BSPrinterRootElementForm - The router now has support for URLs that aren't rewritten --- PrinterRootElementForm.php | 150 +++++++++++++++++++++++++++++++++++++ Router.php | 89 ++++++++++++---------- 2 files changed, 200 insertions(+), 39 deletions(-) create mode 100644 PrinterRootElementForm.php diff --git a/PrinterRootElementForm.php b/PrinterRootElementForm.php new file mode 100644 index 0000000..e22358d --- /dev/null +++ b/PrinterRootElementForm.php @@ -0,0 +1,150 @@ + object. This can have a parent or not: if it does, +* then it will be painted as a child, otherwise it will act as a root. +* +* @author Blue Static +* @copyright Copyright (c)2002 - [#]year[#], Blue Static +* @version $Revision$ +* @package ISSO +* +*/ +class BSPrinterRootElementForm extends BSPrinterRootElement +{ + /** + * The form's action (or the controller to respond to) + * @var string + */ + private $controller; + + /** + * Method to use + * @var string + */ + private $action; + + /** + * The form's name + * @var string + */ + private $name; + + /** + * This form is upload-ready + * @var bool + */ + private $upload; + + // ################################################################### + /** + * Constructor + */ + public function __construct($controller, $action, $name = 'issoform') + { + $this->controller = $controller; + $this->action = $action; + $this->name = $name; + } + + // ################################################################### + /** + * Should this form be used for upload? + * + * @param bool Upload? + */ + public function setUpload($upload) + { + $this->upload = $upload; + } + + // ################################################################### + /** + * Adds a table row into the child list + * + * @param BSPrinterElement Table element + */ + public function addChild(BSPrinterElement $tr) + { + $this->children[] = $tr; + } + + // ################################################################### + /** + * Returns the HTML for all printed children elements + * + * @return string Printed HTML + */ + protected function _paintChildren() + { + $builder = ''; + + foreach ($this->children AS $child) + { + $builder .= "\n" . $child->paint(); + } + + return $builder; + } + + // ################################################################### + /** + * Paints the + * + * @return string Table HTML code + */ + public function paint() + { + if (BSRegister::GetType('Router') AND (!defined('ISSO_ROUTER_NO_REWRITE') OR !constant('ISSO_ROUTER_NO_REWRITE'))) + { + $action = $this->controller . "." . $this->action; + } + else if (BSRegister::GetType('Router')) + { + $action = 'index.php?controller=' . $this->controller . '&action=' . $this->action; + } + else + { + $action = $this->controller; + array_push($this->children, new BSPrinterBaseElement('hidden', 'action', $this->action)); + } + return "\nname . "\" action=\"$action\" method=\"post\"" . ($this->upload ? ' enctype="mime/multi-part"' : '') . ">\n" . $this->_paintChildren() . "\n"; + } +} + +/*=====================================================================* +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/Router.php b/Router.php index 5a1ee3c..8f9b642 100644 --- a/Router.php +++ b/Router.php @@ -39,7 +39,9 @@ require_once('ISSO/RouterController.php'); * RewriteCond %{REQUEST_URI} !static/(.*)$ * RewriteRule ^(.*)$ index.php * -* This will prevent the rewriting on any file in the static/ directory +* This will prevent the rewriting on any file in the static/ directory. +* If your server cannot do this rewriting, then simply define this constant: +* ISSO_ROUTER_NO_REWRITE as TRUE and it will switch to standard URLs * * @author Blue Static * @copyright Copyright (c)2002 - [#]year[#], Blue Static @@ -103,54 +105,63 @@ class BSRouter */ public function dispatch() { - $request = str_replace($this->basePath, '', $_SERVER['REQUEST_URI']); - - $params = explode('/', $request); - $request = explode('.', $params[0]); - $this->request = $request[0]; - $this->action = ((!isset($request[1]) OR empty($request[1])) ? 'Index' : $request[1]); - unset($params[0]); - - if (sizeof($params) == 0) - { - // do nothing - } - else if (sizeof($params) == 1) + if ((defined('ISSO_ROUTER_NO_REWRITE') AND constant('ISSO_ROUTER_NO_REWRITE')) OR isset($_REQUEST['controller'])) { - $this->params[':id'] = $params[1]; + $this->request = $_REQUEST['controller']; + $this->action = ((!isset($_REQUEST['action']) OR empty($_REQUEST['action'])) ? 'Index' : $_REQUEST['action']); + $this->params = $_GET; } else { - $key = ''; - for ($i = 1; $i <= sizeof($params); $i++) + $request = str_replace($this->basePath, '', $_SERVER['REQUEST_URI']); + + $params = explode('/', $request); + $request = explode('.', $params[0]); + $this->request = $request[0]; + $this->action = ((!isset($request[1]) OR empty($request[1])) ? 'Index' : $request[1]); + unset($params[0]); + + if (sizeof($params) == 0) { - if ($i == 1 AND $params["$i"][0] != '+') - { - $this->params[':id'] = $params["$i"]; - continue; - } - - if ($params["$i"] == '') - { - continue; - } - - if ($params["$i"][0] == '+') + // do nothing + } + else if (sizeof($params) == 1) + { + $this->params[':id'] = $params[1]; + } + else + { + $key = ''; + for ($i = 1; $i <= sizeof($params); $i++) { - if (!empty($key)) + if ($i == 1 AND $params["$i"][0] != '+') { - $this->_error(sprintf(_('The paramter "%1$s" does not have a value'), $key)); + $this->params[':id'] = $params["$i"]; + continue; } - $key = substr($params["$i"], 1); - } - else - { - if (empty($key)) + + if ($params["$i"] == '') + { + continue; + } + + if ($params["$i"][0] == '+') + { + if (!empty($key)) + { + $this->_error(sprintf(_('The paramter "%1$s" does not have a value'), $key)); + } + $key = substr($params["$i"], 1); + } + else { - $this->_error(sprintf(_('The value "%1$s" does not have a paramatized key'), $params["$i"])); + if (empty($key)) + { + $this->_error(sprintf(_('The value "%1$s" does not have a paramatized key'), $params["$i"])); + } + $this->params["$key"] = $params["$i"]; + $key = ''; } - $this->params["$key"] = $params["$i"]; - $key = ''; } } } -- 2.43.5