1: | <?php |
2: | |
3: | namespace Zippy\Html\Link; |
4: | |
5: | use Zippy\WebApplication; |
6: | use Zippy\Interfaces\Requestable; |
7: | |
8: | |
9: | |
10: | |
11: | |
12: | class RedirectLink extends AbstractLink implements Requestable |
13: | { |
14: | public $bookmark; |
15: | public $pagename; |
16: | public $params; |
17: | public $bookmarkable; |
18: | public $encode; |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | |
25: | |
26: | |
27: | |
28: | public function __construct($id, $pagename = "", $params = array(), $bookmarkable = true, $encode = false) { |
29: | AbstractLink::__construct($id); |
30: | $this->setLink($pagename, $params, $bookmarkable, $encode); |
31: | } |
32: | |
33: | |
34: | |
35: | |
36: | public function RequestHandle() { |
37: | $cnt = count($this->params); |
38: | switch ($cnt) { |
39: | case 0: |
40: | WebApplication::$app->getResponse()->Redirect($this->pagename); |
41: | break; |
42: | case 1: |
43: | WebApplication::$app->getResponse()->Redirect($this->pagename, $this->params[0]); |
44: | break; |
45: | case 2: |
46: | WebApplication::$app->getResponse()->Redirect($this->pagename, $this->params[0], $this->params[1]); |
47: | break; |
48: | case 3: |
49: | WebApplication::$app->getResponse()->Redirect($this->pagename, $this->params[0], $this->params[1], $this->params[2]); |
50: | break; |
51: | case 4: |
52: | WebApplication::$app->getResponse()->Redirect($this->pagename, $this->params[0], $this->params[1], $this->params[2], $this->params[3]); |
53: | break; |
54: | case 5: |
55: | WebApplication::$app->getResponse()->Redirect($this->pagename, $this->params[0], $this->params[1], $this->params[2], $this->params[3], $this->params[4]); |
56: | break; |
57: | } |
58: | } |
59: | |
60: | |
61: | |
62: | |
63: | public function RenderImpl() { |
64: | parent::RenderImpl(); |
65: | if ($this->bookmarkable === true) { |
66: | |
67: | |
68: | $_BASEURL = WebApplication::$app->getResponse()->getHostUrl(); |
69: | if ($this->encode == true) { |
70: | $url = serialize(array($this->pagename, $this->params)); |
71: | if (strlen($url) % 3 == 1) { |
72: | $url .= ' '; |
73: | } |
74: | if (strlen($url) % 3 == 2) { |
75: | $url .= ' '; |
76: | } |
77: | |
78: | $url = $_BASEURL . "/index.php?r=" . base64_encode(serialize(array($this->pagename, $this->params))); |
79: | } else { |
80: | $this->pagename = str_replace("\\", "/", ltrim($this->pagename, "\\")); |
81: | |
82: | $url = $_BASEURL . "/index.php?p=" . $this->pagename; |
83: | if (count($this->params) > 0) { |
84: | $_param = implode("/", $this->params); |
85: | $url .= "&arg=" . $_param; |
86: | } |
87: | } |
88: | } else { |
89: | $url = $this->owner->getURLNode() . "::" . $this->id; |
90: | } |
91: | $this->setAttribute("href", "{$url}"); |
92: | } |
93: | |
94: | public function setLink($pagename, $params = array(), $bookmarkable = true, $encode = false) { |
95: | $this->pagename = $pagename; |
96: | $this->params = $params; |
97: | if (!is_array($params)) { |
98: | $this->params = array($params); |
99: | } |
100: | $this->bookmarkable = $bookmarkable; |
101: | $this->encode = $encode; |
102: | } |
103: | |
104: | } |
105: | |