123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- class HTML_QuickForm_Action_Jump extends HTML_QuickForm_Action
- {
-
- function _splitUri($uri)
- {
- if (false === ($qm = strpos($uri, '?'))) {
- return array($uri, '');
- } else {
- return array(substr($uri, 0, $qm), substr($uri, $qm));
- }
- }
-
- function _normalizePath($path)
- {
- $pathAry = explode('/', $path);
- $i = 1;
- do {
- if ('.' == $pathAry[$i]) {
- if ($i < count($pathAry) - 1) {
- array_splice($pathAry, $i, 1);
- } else {
- $pathAry[$i] = '';
- $i++;
- }
- } elseif ('..' == $pathAry[$i] && $i > 1 && '..' != $pathAry[$i - 1]) {
- if ($i < count($pathAry) -1) {
- array_splice($pathAry, $i - 1, 2);
- $i--;
- } else {
- array_splice($pathAry, $i - 1, 2, '');
- }
- } else {
- $i++;
- }
- } while ($i < count($pathAry));
- return implode('/', $pathAry);
- }
-
- function _resolveRelativeURL($url)
- {
- $https = !empty($_SERVER['HTTPS']) && ('off' != strtolower($_SERVER['HTTPS']));
- $scheme = ($https? 'https:': 'http:');
- if ('//' == substr($url, 0, 2)) {
- return $scheme . $url;
- } else {
- $host = $scheme . '//' . $_SERVER['SERVER_NAME'] .
- (($https && 443 == $_SERVER['SERVER_PORT'] ||
- !$https && 80 == $_SERVER['SERVER_PORT'])? '': ':' . $_SERVER['SERVER_PORT']);
- if ('' == $url) {
- return $host . $_SERVER['REQUEST_URI'];
- } elseif ('/' == $url[0]) {
- return $host . $url;
- } else {
- list($basePath, $baseQuery) = $this->_splitUri($_SERVER['REQUEST_URI']);
- list($actPath, $actQuery) = $this->_splitUri($url);
- if ('' == $actPath) {
- return $host . $basePath . $actQuery;
- } else {
- $path = substr($basePath, 0, strrpos($basePath, '/') + 1) . $actPath;
- return $host . $this->_normalizePath($path) . $actQuery;
- }
- }
- }
- }
- function perform(&$page, $actionName)
- {
-
- if ($page->controller->isModal()) {
-
-
-
- $pageName = $page->getAttribute('id');
- if (!$page->controller->isValid($pageName)) {
- $pageName = $page->controller->findInvalid();
- }
- $current =& $page->controller->getPage($pageName);
- } else {
- $current =& $page;
- }
-
- $action = $current->getAttribute('action');
-
- if (!preg_match('!^https?://!i', $action)) {
- $action = $this->_resolveRelativeURL($action);
- }
- $url = $action . (false === strpos($action, '?')? '?': '&') .
- $current->getButtonName('display') . '=true' .
- ((!defined('SID') || '' == SID || ini_get('session.use_only_cookies'))? '': '&' . SID);
- header('Location: ' . $url);
- exit;
- }
- }
- ?>
|