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 { | |
4b62bc4f EM |
15 | |
16 | /** | |
1cd3ffa9 | 17 | * Run page. |
4b62bc4f EM |
18 | * |
19 | * @param string $path | |
20 | * @param array $pageArgs | |
4b62bc4f | 21 | */ |
00be9182 | 22 | public function run($path = NULL, $pageArgs = array()) { |
5c2885f8 | 23 | $url = self::createUrl($path, $_REQUEST, $pageArgs, TRUE); |
5c2885f8 | 24 | CRM_Utils_System::redirect($url); |
25 | } | |
26 | ||
27 | /** | |
6a0b768e TO |
28 | * @param array $requestPath |
29 | * The parts of the path in the current page request. | |
30 | * @param array $requestArgs | |
31 | * Any GET arguments. | |
32 | * @param array $pageArgs | |
33 | * The page_arguments registered in the router. | |
6a0b768e TO |
34 | * @param bool $absolute |
35 | * Whether to return an absolute URL. | |
a6c01b45 CW |
36 | * @return string |
37 | * URL | |
5c2885f8 | 38 | */ |
39 | public static function createUrl($requestPath, $requestArgs, $pageArgs, $absolute) { | |
40 | if (empty($pageArgs['url'])) { | |
41 | CRM_Core_Error::fatal('This page is configured as a redirect, but it does not have a target.'); | |
42 | } | |
43 | ||
44 | $vars = array(); | |
45 | // note: %% isn't legal in a well-formed URL, so it's not a bad variable-delimiter | |
46 | foreach ($requestPath as $pathPos => $pathPart) { | |
47 | $vars["%%{$pathPos}%%"] = urlencode($pathPart); | |
48 | } | |
49 | foreach ($requestArgs as $var => $value) { | |
50 | $vars["%%{$var}%%"] = urlencode($value); | |
51 | } | |
52 | $urlString = strtr($pageArgs['url'], $vars); | |
53 | $urlString = preg_replace('/%%[a-zA-Z0-9]+%%/', '', $urlString); | |
54 | ||
55 | $urlParts = parse_url($urlString); | |
56 | $url = CRM_Utils_System::url( | |
57 | $urlParts['path'], | |
58 | CRM_Utils_Array::value('query', $urlParts, NULL), | |
59 | $absolute, | |
60 | CRM_Utils_Array::value('fragment', $urlParts, NULL) | |
61 | ); | |
62 | ||
63 | return $url; | |
64 | } | |
96025800 | 65 | |
5c2885f8 | 66 | } |