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