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