]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | /** | |
4 | * Class Router | |
5 | * | |
6 | * (only displayable pages here) | |
7 | */ | |
8 | class Router | |
9 | { | |
10 | public static $PAGE_LOGIN = 'login'; | |
11 | ||
12 | public static $PAGE_PICWALL = 'picwall'; | |
13 | ||
14 | public static $PAGE_TAGCLOUD = 'tagcloud'; | |
15 | ||
16 | public static $PAGE_TAGLIST = 'taglist'; | |
17 | ||
18 | public static $PAGE_DAILY = 'daily'; | |
19 | ||
20 | public static $PAGE_FEED_ATOM = 'atom'; | |
21 | ||
22 | public static $PAGE_FEED_RSS = 'rss'; | |
23 | ||
24 | public static $PAGE_TOOLS = 'tools'; | |
25 | ||
26 | public static $PAGE_CHANGEPASSWORD = 'changepasswd'; | |
27 | ||
28 | public static $PAGE_CONFIGURE = 'configure'; | |
29 | ||
30 | public static $PAGE_CHANGETAG = 'changetag'; | |
31 | ||
32 | public static $PAGE_ADDLINK = 'addlink'; | |
33 | ||
34 | public static $PAGE_EDITLINK = 'edit_link'; | |
35 | ||
36 | public static $PAGE_DELETELINK = 'delete_link'; | |
37 | ||
38 | public static $PAGE_EXPORT = 'export'; | |
39 | ||
40 | public static $PAGE_IMPORT = 'import'; | |
41 | ||
42 | public static $PAGE_OPENSEARCH = 'opensearch'; | |
43 | ||
44 | public static $PAGE_LINKLIST = 'linklist'; | |
45 | ||
46 | public static $PAGE_PLUGINSADMIN = 'pluginadmin'; | |
47 | ||
48 | public static $PAGE_SAVE_PLUGINSADMIN = 'save_pluginadmin'; | |
49 | ||
50 | public static $GET_TOKEN = 'token'; | |
51 | ||
52 | /** | |
53 | * Reproducing renderPage() if hell, to avoid regression. | |
54 | * | |
55 | * This highlights how bad this needs to be rewrite, | |
56 | * but let's focus on plugins for now. | |
57 | * | |
58 | * @param string $query $_SERVER['QUERY_STRING']. | |
59 | * @param array $get $_SERVER['GET']. | |
60 | * @param bool $loggedIn true if authenticated user. | |
61 | * | |
62 | * @return string page found. | |
63 | */ | |
64 | public static function findPage($query, $get, $loggedIn) | |
65 | { | |
66 | $loggedIn = ($loggedIn === true) ? true : false; | |
67 | ||
68 | if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) { | |
69 | return self::$PAGE_LINKLIST; | |
70 | } | |
71 | ||
72 | if (startsWith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) { | |
73 | return self::$PAGE_LOGIN; | |
74 | } | |
75 | ||
76 | if (startsWith($query, 'do='. self::$PAGE_PICWALL)) { | |
77 | return self::$PAGE_PICWALL; | |
78 | } | |
79 | ||
80 | if (startsWith($query, 'do='. self::$PAGE_TAGCLOUD)) { | |
81 | return self::$PAGE_TAGCLOUD; | |
82 | } | |
83 | ||
84 | if (startsWith($query, 'do='. self::$PAGE_TAGLIST)) { | |
85 | return self::$PAGE_TAGLIST; | |
86 | } | |
87 | ||
88 | if (startsWith($query, 'do='. self::$PAGE_OPENSEARCH)) { | |
89 | return self::$PAGE_OPENSEARCH; | |
90 | } | |
91 | ||
92 | if (startsWith($query, 'do='. self::$PAGE_DAILY)) { | |
93 | return self::$PAGE_DAILY; | |
94 | } | |
95 | ||
96 | if (startsWith($query, 'do='. self::$PAGE_FEED_ATOM)) { | |
97 | return self::$PAGE_FEED_ATOM; | |
98 | } | |
99 | ||
100 | if (startsWith($query, 'do='. self::$PAGE_FEED_RSS)) { | |
101 | return self::$PAGE_FEED_RSS; | |
102 | } | |
103 | ||
104 | // At this point, only loggedin pages. | |
105 | if (!$loggedIn) { | |
106 | return self::$PAGE_LINKLIST; | |
107 | } | |
108 | ||
109 | if (startsWith($query, 'do='. self::$PAGE_TOOLS)) { | |
110 | return self::$PAGE_TOOLS; | |
111 | } | |
112 | ||
113 | if (startsWith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) { | |
114 | return self::$PAGE_CHANGEPASSWORD; | |
115 | } | |
116 | ||
117 | if (startsWith($query, 'do='. self::$PAGE_CONFIGURE)) { | |
118 | return self::$PAGE_CONFIGURE; | |
119 | } | |
120 | ||
121 | if (startsWith($query, 'do='. self::$PAGE_CHANGETAG)) { | |
122 | return self::$PAGE_CHANGETAG; | |
123 | } | |
124 | ||
125 | if (startsWith($query, 'do='. self::$PAGE_ADDLINK)) { | |
126 | return self::$PAGE_ADDLINK; | |
127 | } | |
128 | ||
129 | if (isset($get['edit_link']) || isset($get['post'])) { | |
130 | return self::$PAGE_EDITLINK; | |
131 | } | |
132 | ||
133 | if (isset($get['delete_link'])) { | |
134 | return self::$PAGE_DELETELINK; | |
135 | } | |
136 | ||
137 | if (startsWith($query, 'do='. self::$PAGE_EXPORT)) { | |
138 | return self::$PAGE_EXPORT; | |
139 | } | |
140 | ||
141 | if (startsWith($query, 'do='. self::$PAGE_IMPORT)) { | |
142 | return self::$PAGE_IMPORT; | |
143 | } | |
144 | ||
145 | if (startsWith($query, 'do='. self::$PAGE_PLUGINSADMIN)) { | |
146 | return self::$PAGE_PLUGINSADMIN; | |
147 | } | |
148 | ||
149 | if (startsWith($query, 'do='. self::$PAGE_SAVE_PLUGINSADMIN)) { | |
150 | return self::$PAGE_SAVE_PLUGINSADMIN; | |
151 | } | |
152 | ||
153 | if (startsWith($query, 'do='. self::$GET_TOKEN)) { | |
154 | return self::$GET_TOKEN; | |
155 | } | |
156 | ||
157 | return self::$PAGE_LINKLIST; | |
158 | } | |
159 | } |