]>
Commit | Line | Data |
---|---|---|
6fc14d53 A |
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 | ||
38603b24 A |
16 | public static $PAGE_DAILY = 'daily'; |
17 | ||
6fc14d53 A |
18 | public static $PAGE_TOOLS = 'tools'; |
19 | ||
20 | public static $PAGE_CHANGEPASSWORD = 'changepasswd'; | |
21 | ||
22 | public static $PAGE_CONFIGURE = 'configure'; | |
23 | ||
24 | public static $PAGE_CHANGETAG = 'changetag'; | |
25 | ||
26 | public static $PAGE_ADDLINK = 'addlink'; | |
27 | ||
28 | public static $PAGE_EDITLINK = 'edit_link'; | |
29 | ||
30 | public static $PAGE_EXPORT = 'export'; | |
31 | ||
32 | public static $PAGE_IMPORT = 'import'; | |
33 | ||
8f8113b9 A |
34 | public static $PAGE_OPENSEARCH = 'opensearch'; |
35 | ||
6fc14d53 A |
36 | public static $PAGE_LINKLIST = 'linklist'; |
37 | ||
dea0ba28 A |
38 | public static $PAGE_PLUGINSADMIN = 'pluginadmin'; |
39 | ||
40 | public static $PAGE_SAVE_PLUGINSADMIN = 'save_pluginadmin'; | |
41 | ||
6fc14d53 A |
42 | /** |
43 | * Reproducing renderPage() if hell, to avoid regression. | |
44 | * | |
45 | * This highlights how bad this needs to be rewrite, | |
46 | * but let's focus on plugins for now. | |
47 | * | |
48 | * @param string $query $_SERVER['QUERY_STRING']. | |
49 | * @param array $get $_SERVER['GET']. | |
50 | * @param bool $loggedIn true if authenticated user. | |
51 | * | |
52 | * @return self::page found. | |
53 | */ | |
54 | public static function findPage($query, $get, $loggedIn) | |
55 | { | |
56 | $loggedIn = ($loggedIn === true) ? true : false; | |
57 | ||
58 | if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) { | |
59 | return self::$PAGE_LINKLIST; | |
60 | } | |
61 | ||
62 | if (startswith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) { | |
63 | return self::$PAGE_LOGIN; | |
64 | } | |
65 | ||
66 | if (startswith($query, 'do='. self::$PAGE_PICWALL)) { | |
67 | return self::$PAGE_PICWALL; | |
68 | } | |
69 | ||
70 | if (startswith($query, 'do='. self::$PAGE_TAGCLOUD)) { | |
71 | return self::$PAGE_TAGCLOUD; | |
72 | } | |
73 | ||
8f8113b9 A |
74 | if (startswith($query, 'do='. self::$PAGE_OPENSEARCH)) { |
75 | return self::$PAGE_OPENSEARCH; | |
76 | } | |
77 | ||
38603b24 A |
78 | if (startsWith($query, 'do='. self::$PAGE_DAILY)) { |
79 | return self::$PAGE_DAILY; | |
80 | } | |
81 | ||
6fc14d53 A |
82 | // At this point, only loggedin pages. |
83 | if (!$loggedIn) { | |
84 | return self::$PAGE_LINKLIST; | |
85 | } | |
86 | ||
87 | if (startswith($query, 'do='. self::$PAGE_TOOLS)) { | |
88 | return self::$PAGE_TOOLS; | |
89 | } | |
90 | ||
91 | if (startswith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) { | |
92 | return self::$PAGE_CHANGEPASSWORD; | |
93 | } | |
94 | ||
95 | if (startswith($query, 'do='. self::$PAGE_CONFIGURE)) { | |
96 | return self::$PAGE_CONFIGURE; | |
97 | } | |
98 | ||
99 | if (startswith($query, 'do='. self::$PAGE_CHANGETAG)) { | |
100 | return self::$PAGE_CHANGETAG; | |
101 | } | |
102 | ||
103 | if (startswith($query, 'do='. self::$PAGE_ADDLINK)) { | |
104 | return self::$PAGE_ADDLINK; | |
105 | } | |
106 | ||
107 | if (isset($get['edit_link']) || isset($get['post'])) { | |
108 | return self::$PAGE_EDITLINK; | |
109 | } | |
110 | ||
111 | if (startswith($query, 'do='. self::$PAGE_EXPORT)) { | |
112 | return self::$PAGE_EXPORT; | |
113 | } | |
114 | ||
115 | if (startswith($query, 'do='. self::$PAGE_IMPORT)) { | |
116 | return self::$PAGE_IMPORT; | |
117 | } | |
118 | ||
dea0ba28 A |
119 | if (startswith($query, 'do='. self::$PAGE_PLUGINSADMIN)) { |
120 | return self::$PAGE_PLUGINSADMIN; | |
121 | } | |
122 | ||
123 | if (startswith($query, 'do='. self::$PAGE_SAVE_PLUGINSADMIN)) { | |
124 | return self::$PAGE_SAVE_PLUGINSADMIN; | |
125 | } | |
126 | ||
6fc14d53 A |
127 | return self::$PAGE_LINKLIST; |
128 | } | |
129 | } |