00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 class RedirectRenderDecorator extends RenderDecoratorBase {
00022
00023
00024
00025
00026
00027 private $target_path = null;
00028
00029
00030
00031
00032
00033
00034
00035 public function __construct($target_path) {
00036 $this->target_path = $target_path;
00037 }
00038
00039
00040
00041
00042
00043
00044
00045 public function initialize($page_data) {
00046 $target = $this->target_path;
00047 $source_path = Url::current()->get_path();
00048 $full_target = $this->build_redirect_url($target, $source_path);
00049
00050 $url = Url::create($full_target);
00051 if (!$url->is_valid()) {
00052 $url = Url::current()->clear_query()->set_path($full_target);
00053 }
00054 $url->redirect(Url::PERMANENT);
00055 exit;
00056 }
00057
00058
00059
00060
00061 protected function build_redirect_url($target_path, $source_path) {
00062
00063
00064 $target_path = str_replace('{$0}', $source_path, $target_path);
00065
00066 $i = 1;
00067 $path_stack = new PathStack($source_path);
00068 while($elem = $path_stack->shift()) {
00069 $target_path = str_replace('{$' . $i . '}', $elem, $target_path);
00070 $i++;
00071 }
00072
00073 $target_path = preg_replace('|\{\$\d\}|', '', $target_path);
00074 return $target_path;
00075 }
00076 }