]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - application/Router.php
Merge pull request #376 from ArthurHoaro/opensearch
[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_TOOLS = 'tools';
17
18 public static $PAGE_CHANGEPASSWORD = 'changepasswd';
19
20 public static $PAGE_CONFIGURE = 'configure';
21
22 public static $PAGE_CHANGETAG = 'changetag';
23
24 public static $PAGE_ADDLINK = 'addlink';
25
26 public static $PAGE_EDITLINK = 'edit_link';
27
28 public static $PAGE_EXPORT = 'export';
29
30 public static $PAGE_IMPORT = 'import';
31
32 public static $PAGE_OPENSEARCH = 'opensearch';
33
34 public static $PAGE_LINKLIST = 'linklist';
35
36 /**
37 * Reproducing renderPage() if hell, to avoid regression.
38 *
39 * This highlights how bad this needs to be rewrite,
40 * but let's focus on plugins for now.
41 *
42 * @param string $query $_SERVER['QUERY_STRING'].
43 * @param array $get $_SERVER['GET'].
44 * @param bool $loggedIn true if authenticated user.
45 *
46 * @return self::page found.
47 */
48 public static function findPage($query, $get, $loggedIn)
49 {
50 $loggedIn = ($loggedIn === true) ? true : false;
51
52 if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) {
53 return self::$PAGE_LINKLIST;
54 }
55
56 if (startswith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) {
57 return self::$PAGE_LOGIN;
58 }
59
60 if (startswith($query, 'do='. self::$PAGE_PICWALL)) {
61 return self::$PAGE_PICWALL;
62 }
63
64 if (startswith($query, 'do='. self::$PAGE_TAGCLOUD)) {
65 return self::$PAGE_TAGCLOUD;
66 }
67
68 if (startswith($query, 'do='. self::$PAGE_OPENSEARCH)) {
69 return self::$PAGE_OPENSEARCH;
70 }
71
72 // At this point, only loggedin pages.
73 if (!$loggedIn) {
74 return self::$PAGE_LINKLIST;
75 }
76
77 if (startswith($query, 'do='. self::$PAGE_TOOLS)) {
78 return self::$PAGE_TOOLS;
79 }
80
81 if (startswith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) {
82 return self::$PAGE_CHANGEPASSWORD;
83 }
84
85 if (startswith($query, 'do='. self::$PAGE_CONFIGURE)) {
86 return self::$PAGE_CONFIGURE;
87 }
88
89 if (startswith($query, 'do='. self::$PAGE_CHANGETAG)) {
90 return self::$PAGE_CHANGETAG;
91 }
92
93 if (startswith($query, 'do='. self::$PAGE_ADDLINK)) {
94 return self::$PAGE_ADDLINK;
95 }
96
97 if (isset($get['edit_link']) || isset($get['post'])) {
98 return self::$PAGE_EDITLINK;
99 }
100
101 if (startswith($query, 'do='. self::$PAGE_EXPORT)) {
102 return self::$PAGE_EXPORT;
103 }
104
105 if (startswith($query, 'do='. self::$PAGE_IMPORT)) {
106 return self::$PAGE_IMPORT;
107 }
108
109 return self::$PAGE_LINKLIST;
110 }
111 }