]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/Router.php
Merge pull request #858 from ArthurHoaro/api/history-entries
[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 /**
49 * Reproducing renderPage() if hell, to avoid regression.
50 *
51 * This highlights how bad this needs to be rewrite,
52 * but let's focus on plugins for now.
53 *
54 * @param string $query $_SERVER['QUERY_STRING'].
55 * @param array $get $_SERVER['GET'].
56 * @param bool $loggedIn true if authenticated user.
57 *
58 * @return string page found.
59 */
60 public static function findPage($query, $get, $loggedIn)
61 {
62 $loggedIn = ($loggedIn === true) ? true : false;
63
64 if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) {
65 return self::$PAGE_LINKLIST;
66 }
67
68 if (startsWith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) {
69 return self::$PAGE_LOGIN;
70 }
71
72 if (startsWith($query, 'do='. self::$PAGE_PICWALL)) {
73 return self::$PAGE_PICWALL;
74 }
75
76 if (startsWith($query, 'do='. self::$PAGE_TAGCLOUD)) {
77 return self::$PAGE_TAGCLOUD;
78 }
79
80 if (startsWith($query, 'do='. self::$PAGE_OPENSEARCH)) {
81 return self::$PAGE_OPENSEARCH;
82 }
83
84 if (startsWith($query, 'do='. self::$PAGE_DAILY)) {
85 return self::$PAGE_DAILY;
86 }
87
88 if (startsWith($query, 'do='. self::$PAGE_FEED_ATOM)) {
89 return self::$PAGE_FEED_ATOM;
90 }
91
92 if (startsWith($query, 'do='. self::$PAGE_FEED_RSS)) {
93 return self::$PAGE_FEED_RSS;
94 }
95
96 // At this point, only loggedin pages.
97 if (!$loggedIn) {
98 return self::$PAGE_LINKLIST;
99 }
100
101 if (startsWith($query, 'do='. self::$PAGE_TOOLS)) {
102 return self::$PAGE_TOOLS;
103 }
104
105 if (startsWith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) {
106 return self::$PAGE_CHANGEPASSWORD;
107 }
108
109 if (startsWith($query, 'do='. self::$PAGE_CONFIGURE)) {
110 return self::$PAGE_CONFIGURE;
111 }
112
113 if (startsWith($query, 'do='. self::$PAGE_CHANGETAG)) {
114 return self::$PAGE_CHANGETAG;
115 }
116
117 if (startsWith($query, 'do='. self::$PAGE_ADDLINK)) {
118 return self::$PAGE_ADDLINK;
119 }
120
121 if (isset($get['edit_link']) || isset($get['post'])) {
122 return self::$PAGE_EDITLINK;
123 }
124
125 if (isset($get['delete_link'])) {
126 return self::$PAGE_DELETELINK;
127 }
128
129 if (startsWith($query, 'do='. self::$PAGE_EXPORT)) {
130 return self::$PAGE_EXPORT;
131 }
132
133 if (startsWith($query, 'do='. self::$PAGE_IMPORT)) {
134 return self::$PAGE_IMPORT;
135 }
136
137 if (startsWith($query, 'do='. self::$PAGE_PLUGINSADMIN)) {
138 return self::$PAGE_PLUGINSADMIN;
139 }
140
141 if (startsWith($query, 'do='. self::$PAGE_SAVE_PLUGINSADMIN)) {
142 return self::$PAGE_SAVE_PLUGINSADMIN;
143 }
144
145 return self::$PAGE_LINKLIST;
146 }
147 }