PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / trunk
Matomo Analytics – Powerful, Privacy-First Insights for WordPress vtrunk
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / libs / HTML / QuickForm2 / Controller / Action / Jump.php
matomo / app / libs / HTML / QuickForm2 / Controller / Action Last commit date
Back.php 2 years ago Direct.php 2 years ago Display.php 2 years ago Jump.php 2 years ago Next.php 2 years ago Submit.php 2 years ago
Jump.php
185 lines
1 <?php
2
3 namespace {
4 /**
5 * This handler performs an HTTP redirect to a specific page
6 *
7 * PHP version 5
8 *
9 * LICENSE:
10 *
11 * Copyright (c) 2006-2010, Alexey Borzov <avb@php.net>,
12 * Bertrand Mansion <golgote@mamasam.com>
13 * All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 *
19 * * Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * * Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * * The names of the authors may not be used to endorse or promote products
25 * derived from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
29 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
31 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
35 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 * @category HTML
40 * @package HTML_QuickForm2
41 * @author Alexey Borzov <avb@php.net>
42 * @author Bertrand Mansion <golgote@mamasam.com>
43 * @license http://opensource.org/licenses/bsd-license.php New BSD License
44 * @version SVN: $Id: Jump.php 294039 2010-01-26 12:29:46Z avb $
45 * @link http://pear.php.net/package/HTML_QuickForm2
46 */
47 /** Interface for Controller action handlers */
48 // require_once 'HTML/QuickForm2/Controller/Action.php';
49 /**
50 * This handler performs an HTTP redirect to a specific page
51 *
52 * @category HTML
53 * @package HTML_QuickForm2
54 * @author Alexey Borzov <avb@php.net>
55 * @author Bertrand Mansion <golgote@mamasam.com>
56 * @version Release: @package_version@
57 */
58 class HTML_QuickForm2_Controller_Action_Jump implements \HTML_QuickForm2_Controller_Action
59 {
60 /**
61 * Splits (part of) the URI into path and query components
62 *
63 * @param string String of the form 'foo?bar'
64 * @return array Array of the form array('foo', '?bar)
65 */
66 protected static function splitUri($uri)
67 {
68 if (\false === ($qm = \strpos($uri, '?'))) {
69 return array($uri, '');
70 } else {
71 return array(\substr($uri, 0, $qm), \substr($uri, $qm));
72 }
73 }
74 /**
75 * Removes the '..' and '.' segments from the path component
76 *
77 * @param string Path component of the URL, possibly with '.' and '..' segments
78 * @return string Path component of the URL with '.' and '..' segments removed
79 */
80 protected static function normalizePath($path)
81 {
82 $pathAry = \explode('/', $path);
83 $i = 1;
84 do {
85 if ('.' == $pathAry[$i]) {
86 if ($i < \count($pathAry) - 1) {
87 \array_splice($pathAry, $i, 1);
88 } else {
89 $pathAry[$i] = '';
90 $i++;
91 }
92 } elseif ('..' == $pathAry[$i]) {
93 if (1 == $i) {
94 \array_splice($pathAry, 1, 1);
95 } elseif ('..' != $pathAry[$i - 1]) {
96 if ($i < \count($pathAry) - 1) {
97 \array_splice($pathAry, $i - 1, 2);
98 $i--;
99 } else {
100 \array_splice($pathAry, $i - 1, 2, '');
101 }
102 }
103 } else {
104 $i++;
105 }
106 } while ($i < \count($pathAry));
107 return \implode('/', $pathAry);
108 }
109 /**
110 * Resolves relative URL using current page's URL as base
111 *
112 * The method follows procedure described in section 4 of RFC 1808 and
113 * passes the examples provided in section 5 of said RFC. Values from
114 * $_SERVER array are used for calculation of "current URL"
115 *
116 * @param string Relative URL, probably from form's action attribute
117 * @return string Absolute URL
118 */
119 protected static function resolveRelativeURL($url)
120 {
121 $https = !empty($_SERVER['HTTPS']) && 'off' != \strtolower($_SERVER['HTTPS']);
122 $scheme = $https ? 'https:' : 'http:';
123 if ('//' == \substr($url, 0, 2)) {
124 return $scheme . $url;
125 } else {
126 $host = $scheme . '//' . $_SERVER['SERVER_NAME'] . ($https && 443 == $_SERVER['SERVER_PORT'] || !$https && 80 == $_SERVER['SERVER_PORT'] ? '' : ':' . $_SERVER['SERVER_PORT']);
127 if ('' == $url) {
128 return $host . $_SERVER['REQUEST_URI'];
129 } elseif ('/' == $url[0]) {
130 list($actPath, $actQuery) = self::splitUri($url);
131 return $host . self::normalizePath($actPath) . $actQuery;
132 } else {
133 list($basePath, $baseQuery) = self::splitUri($_SERVER['REQUEST_URI']);
134 list($actPath, $actQuery) = self::splitUri($url);
135 if ('' == $actPath) {
136 return $host . $basePath . $actQuery;
137 } else {
138 $path = \substr($basePath, 0, \strrpos($basePath, '/') + 1) . $actPath;
139 return $host . self::normalizePath($path) . $actQuery;
140 }
141 }
142 }
143 }
144 public function perform(\HTML_QuickForm2_Controller_Page $page, $name)
145 {
146 // we check whether *all* pages up to current are valid
147 // if there is an invalid page we go to it, instead of the
148 // requested one
149 if ($page->getController()->isWizard() && !$page->getController()->isValid($page)) {
150 $page = $page->getController()->getFirstInvalidPage();
151 }
152 // generate the URL for the page 'display' event and redirect to it
153 $action = $page->getForm()->getAttribute('action');
154 // Bug #13087: RFC 2616 requires an absolute URI in Location header
155 if (!\preg_match('@^([a-z][a-z0-9.+-]*):@i', $action)) {
156 $action = self::resolveRelativeURL($action);
157 }
158 if (!$page->getController()->propagateId()) {
159 $controllerId = '';
160 } else {
161 $controllerId = '&' . \HTML_QuickForm2_Controller::KEY_ID . '=' . $page->getController()->getId();
162 }
163 if (!\defined('SID') || '' == \SID || \ini_get('session.use_only_cookies')) {
164 $sessionId = '';
165 } else {
166 $sessionId = '&' . \SID;
167 }
168 return $this->doRedirect($action . (\false === \strpos($action, '?') ? '?' : '&') . $page->getButtonName('display') . '=true' . $controllerId . $sessionId);
169 }
170 /**
171 * Redirects to a given URL via Location: header and exits the script
172 *
173 * A separate method is mostly needed for creating mocks of this class
174 * during testing.
175 *
176 * @param string URL to redirect to
177 */
178 protected function doRedirect($url)
179 {
180 \header('Location: ' . $url);
181 exit;
182 }
183 }
184 }
185