Commit | Line | Data |
---|---|---|
5c2885f8 | 1 | <?php |
2 | ||
3 | /** | |
4 | * Placeholder page which generates a redirect | |
5 | * | |
6 | * @code | |
7 | * <item> | |
8 | * <path>civicrm/admin/options/case_type</path> | |
9 | * <page_callback>CRM_Core_Page_Redirect</page_callback> | |
10 | * <page_arguments>url=civicrm/foo/bar?whiz=bang&passthru=%%passthru%%</page_arguments> | |
11 | * </item> | |
12 | * @endcoe | |
13 | */ | |
14 | class CRM_Core_Page_Redirect extends CRM_Core_Page { | |
00be9182 | 15 | public function run($path = NULL, $pageArgs = array()) { |
5c2885f8 | 16 | $url = self::createUrl($path, $_REQUEST, $pageArgs, TRUE); |
17 | // return $url; | |
18 | CRM_Utils_System::redirect($url); | |
19 | } | |
20 | ||
21 | /** | |
6a0b768e TO |
22 | * @param array $requestPath |
23 | * The parts of the path in the current page request. | |
24 | * @param array $requestArgs | |
25 | * Any GET arguments. | |
26 | * @param array $pageArgs | |
27 | * The page_arguments registered in the router. | |
6a0b768e TO |
28 | * @param bool $absolute |
29 | * Whether to return an absolute URL. | |
a6c01b45 CW |
30 | * @return string |
31 | * URL | |
5c2885f8 | 32 | */ |
33 | public static function createUrl($requestPath, $requestArgs, $pageArgs, $absolute) { | |
34 | if (empty($pageArgs['url'])) { | |
35 | CRM_Core_Error::fatal('This page is configured as a redirect, but it does not have a target.'); | |
36 | } | |
37 | ||
38 | $vars = array(); | |
39 | // note: %% isn't legal in a well-formed URL, so it's not a bad variable-delimiter | |
40 | foreach ($requestPath as $pathPos => $pathPart) { | |
41 | $vars["%%{$pathPos}%%"] = urlencode($pathPart); | |
42 | } | |
43 | foreach ($requestArgs as $var => $value) { | |
44 | $vars["%%{$var}%%"] = urlencode($value); | |
45 | } | |
46 | $urlString = strtr($pageArgs['url'], $vars); | |
47 | $urlString = preg_replace('/%%[a-zA-Z0-9]+%%/', '', $urlString); | |
48 | ||
49 | $urlParts = parse_url($urlString); | |
50 | $url = CRM_Utils_System::url( | |
51 | $urlParts['path'], | |
52 | CRM_Utils_Array::value('query', $urlParts, NULL), | |
53 | $absolute, | |
54 | CRM_Utils_Array::value('fragment', $urlParts, NULL) | |
55 | ); | |
56 | ||
57 | return $url; | |
58 | } | |
59 | } |