]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - application/Router.php
Merge pull request #976 from ArthurHoaro/hotfix/url-parentheses
[github/shaarli/Shaarli.git] / application / Router.php
CommitLineData
6fc14d53
A
1<?php
2
3/**
4 * Class Router
5 *
6 * (only displayable pages here)
7 */
8class Router
9{
10 public static $PAGE_LOGIN = 'login';
11
12 public static $PAGE_PICWALL = 'picwall';
13
14 public static $PAGE_TAGCLOUD = 'tagcloud';
15
aa4797ba
A
16 public static $PAGE_TAGLIST = 'taglist';
17
38603b24
A
18 public static $PAGE_DAILY = 'daily';
19
8395d0b7
A
20 public static $PAGE_FEED_ATOM = 'atom';
21
22 public static $PAGE_FEED_RSS = 'rss';
23
6fc14d53
A
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
f4ebd5fe
A
36 public static $PAGE_DELETELINK = 'delete_link';
37
6fc14d53
A
38 public static $PAGE_EXPORT = 'export';
39
40 public static $PAGE_IMPORT = 'import';
41
8f8113b9
A
42 public static $PAGE_OPENSEARCH = 'opensearch';
43
6fc14d53
A
44 public static $PAGE_LINKLIST = 'linklist';
45
dea0ba28
A
46 public static $PAGE_PLUGINSADMIN = 'pluginadmin';
47
48 public static $PAGE_SAVE_PLUGINSADMIN = 'save_pluginadmin';
49
986a5210
A
50 public static $GET_TOKEN = 'token';
51
6fc14d53
A
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 *
82e36802 62 * @return string page found.
6fc14d53
A
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
5046bcb6 72 if (startsWith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) {
6fc14d53
A
73 return self::$PAGE_LOGIN;
74 }
75
5046bcb6 76 if (startsWith($query, 'do='. self::$PAGE_PICWALL)) {
6fc14d53
A
77 return self::$PAGE_PICWALL;
78 }
79
5046bcb6 80 if (startsWith($query, 'do='. self::$PAGE_TAGCLOUD)) {
6fc14d53
A
81 return self::$PAGE_TAGCLOUD;
82 }
83
aa4797ba
A
84 if (startsWith($query, 'do='. self::$PAGE_TAGLIST)) {
85 return self::$PAGE_TAGLIST;
86 }
87
5046bcb6 88 if (startsWith($query, 'do='. self::$PAGE_OPENSEARCH)) {
8f8113b9
A
89 return self::$PAGE_OPENSEARCH;
90 }
91
38603b24
A
92 if (startsWith($query, 'do='. self::$PAGE_DAILY)) {
93 return self::$PAGE_DAILY;
94 }
95
8395d0b7
A
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
6fc14d53
A
104 // At this point, only loggedin pages.
105 if (!$loggedIn) {
106 return self::$PAGE_LINKLIST;
107 }
108
5046bcb6 109 if (startsWith($query, 'do='. self::$PAGE_TOOLS)) {
6fc14d53
A
110 return self::$PAGE_TOOLS;
111 }
112
5046bcb6 113 if (startsWith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) {
6fc14d53
A
114 return self::$PAGE_CHANGEPASSWORD;
115 }
116
5046bcb6 117 if (startsWith($query, 'do='. self::$PAGE_CONFIGURE)) {
6fc14d53
A
118 return self::$PAGE_CONFIGURE;
119 }
120
5046bcb6 121 if (startsWith($query, 'do='. self::$PAGE_CHANGETAG)) {
6fc14d53
A
122 return self::$PAGE_CHANGETAG;
123 }
124
5046bcb6 125 if (startsWith($query, 'do='. self::$PAGE_ADDLINK)) {
6fc14d53
A
126 return self::$PAGE_ADDLINK;
127 }
128
129 if (isset($get['edit_link']) || isset($get['post'])) {
130 return self::$PAGE_EDITLINK;
131 }
132
f4ebd5fe
A
133 if (isset($get['delete_link'])) {
134 return self::$PAGE_DELETELINK;
135 }
136
5046bcb6 137 if (startsWith($query, 'do='. self::$PAGE_EXPORT)) {
6fc14d53
A
138 return self::$PAGE_EXPORT;
139 }
140
5046bcb6 141 if (startsWith($query, 'do='. self::$PAGE_IMPORT)) {
6fc14d53
A
142 return self::$PAGE_IMPORT;
143 }
144
5046bcb6 145 if (startsWith($query, 'do='. self::$PAGE_PLUGINSADMIN)) {
dea0ba28
A
146 return self::$PAGE_PLUGINSADMIN;
147 }
148
5046bcb6 149 if (startsWith($query, 'do='. self::$PAGE_SAVE_PLUGINSADMIN)) {
dea0ba28
A
150 return self::$PAGE_SAVE_PLUGINSADMIN;
151 }
152
986a5210
A
153 if (startsWith($query, 'do='. self::$GET_TOKEN)) {
154 return self::$GET_TOKEN;
155 }
156
6fc14d53
A
157 return self::$PAGE_LINKLIST;
158 }
db6dec0d 159}