HTML_QuickForm_Controller
[ class tree: HTML_QuickForm_Controller ] [ index: HTML_QuickForm_Controller ] [ all elements ]

Source for file Jump.php

Documentation is available at Jump.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * This action performs HTTP redirect to a specific page.
  6.  *
  7.  * PHP versions 4 and 5
  8.  *
  9.  * LICENSE: This source file is subject to version 3.01 of the PHP license
  10.  * that is available through the world-wide-web at the following URI:
  11.  * http://www.php.net/license/3_01.txt If you did not receive a copy of
  12.  * the PHP License and are unable to obtain it through the web, please
  13.  * send a note to license@php.net so we can mail you a copy immediately.
  14.  *
  15.  * @category    HTML
  16.  * @package     HTML_QuickForm_Controller
  17.  * @author      Alexey Borzov <avb@php.net>
  18.  * @copyright   2003-2007 The PHP Group
  19.  * @license     http://www.php.net/license/3_01.txt PHP License 3.01
  20.  * @version     CVS: $Id: Jump.php,v 1.6 2008/07/22 11:05:20 avb Exp $
  21.  * @link        http://pear.php.net/package/HTML_QuickForm_Controller
  22.  */
  23.  
  24. /**
  25.  * Class representing an action to perform on HTTP request.
  26.  */
  27. require_once 'HTML/QuickForm/Action.php';
  28.  
  29. /**
  30.  * This action performs HTTP redirect to a specific page.
  31.  *
  32.  * @category    HTML
  33.  * @package     HTML_QuickForm_Controller
  34.  * @author      Alexey Borzov <avb@php.net>
  35.  * @version     Release: 1.0.9
  36.  */
  37. {
  38.    /**
  39.     * Splits (part of) the URI into path and query components
  40.     *
  41.     * @param    string  String of the form 'foo?bar'
  42.     * @return   array   Array of the form array('foo', '?bar)
  43.     * @access   private
  44.     */
  45.     function _splitUri($uri)
  46.     {
  47.         if (false === ($qm strpos($uri'?'))) {
  48.             return array($uri'');
  49.         else {
  50.             return array(substr($uri0$qm)substr($uri$qm));
  51.         }
  52.     }
  53.  
  54.    /**
  55.     * Removes the '..' and '.' segments from the path component
  56.     *
  57.     * @param    string  Path component of the URL, possibly with '.' and '..' segments
  58.     * @return   string  Path component of the URL with '.' and '..' segments removed
  59.     * @access   private
  60.     */
  61.     function _normalizePath($path)
  62.     {
  63.         $pathAry explode('/'$path);
  64.         $i       = 1;
  65.  
  66.         do {
  67.             if ('.' == $pathAry[$i]{
  68.                 if ($i count($pathAry- 1{
  69.                     array_splice($pathAry$i1);
  70.                 else {
  71.                     $pathAry[$i'';
  72.                     $i++;
  73.                 }
  74.  
  75.             elseif ('..' == $pathAry[$i&& $i > 1 && '..' != $pathAry[$i - 1]{
  76.                 if ($i count($pathAry-1{
  77.                     array_splice($pathAry$i - 12);
  78.                     $i--;
  79.                 else {
  80.                     array_splice($pathAry$i - 12'');
  81.                 }
  82.  
  83.             else {
  84.                 $i++;
  85.             }
  86.         while ($i count($pathAry));
  87.  
  88.         return implode('/'$pathAry);
  89.     }
  90.  
  91.    /**
  92.     * Resolves relative URL using current page's URL as base
  93.     *
  94.     * The method follows procedure described in section 4 of RFC 1808 and
  95.     * passes the examples provided in section 5 of said RFC. Values from
  96.     * $_SERVER array are used for calculation of "current URL"
  97.     *
  98.     * @param    string  Relative URL, probably from form's action attribute
  99.     * @return   string  Absolute URL
  100.     * @access   private
  101.     */
  102.     function _resolveRelativeURL($url)
  103.     {
  104.         $https  !empty($_SERVER['HTTPS']&& ('off' != $_SERVER['HTTPS']);
  105.         $scheme ($https'https:''http:');
  106.         if ('//' == substr($url02)) {
  107.             return $scheme $url;
  108.  
  109.         else {
  110.             $host   $scheme '//' $_SERVER['SERVER_NAME'.
  111.                       (($https && 443 == $_SERVER['SERVER_PORT'||
  112.                         !$https && 80 == $_SERVER['SERVER_PORT'])''':' $_SERVER['SERVER_PORT']);
  113.             if ('' == $url{
  114.                 return $host $_SERVER['REQUEST_URI'];
  115.  
  116.             elseif ('/' == $url[0]{
  117.                 return $host $url;
  118.  
  119.             else {
  120.                 list($basePath$baseQuery$this->_splitUri($_SERVER['REQUEST_URI']);
  121.                 list($actPath$actQuery)   $this->_splitUri($url);
  122.                 if ('' == $actPath{
  123.                     return $host $basePath $actQuery;
  124.                 else {
  125.                     $path substr($basePath0strrpos($basePath'/'+ 1$actPath;
  126.                     return $host $this->_normalizePath($path$actQuery;
  127.                 }
  128.             }
  129.         }
  130.     }
  131.  
  132.     function perform(&$page$actionName)
  133.     {
  134.         // check whether the page is valid before trying to go to it
  135.         if ($page->controller->isModal()) {
  136.             // we check whether *all* pages up to current are valid
  137.             // if there is an invalid page we go to it, instead of the
  138.             // requested one
  139.             $pageName $page->getAttribute('id');
  140.             if (!$page->controller->isValid($pageName)) {
  141.                 $pageName $page->controller->findInvalid();
  142.             }
  143.             $current =$page->controller->getPage($pageName);
  144.  
  145.         else {
  146.             $current =$page;
  147.         }
  148.         // generate the URL for the page 'display' event and redirect to it
  149.         $action $current->getAttribute('action');
  150.         // Bug #13087: RFC 2616 requires an absolute URI in Location header
  151.         if (!preg_match('!^https?://!i'$action)) {
  152.             $action $this->_resolveRelativeURL($action);
  153.         }
  154.         $url    $action (false === strpos($action'?')'?''&'.
  155.                   $current->getButtonName('display''=true' .
  156.                   ((!defined('SID'|| '' == SID || ini_get('session.use_only_cookies'))'''&' . SID);
  157.         header('Location: ' $url);
  158.         exit;
  159.     }
  160. }
  161. ?>

Documentation generated on Tue, 22 Jul 2008 08:00:07 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.