aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/Router.php
diff options
context:
space:
mode:
authorArthur <arthur@hoa.ro>2015-11-08 13:29:32 +0100
committerArthur <arthur@hoa.ro>2015-11-08 13:29:32 +0100
commitfd006c630b64146edc402b68d8503c716f8a55d6 (patch)
treee53904cc6232c7f2fe8e1de6f23c9a5d6c5403ad /application/Router.php
parent70df947af60afb05529024bb2d3825eaf6cc7950 (diff)
parent056107ab4eae0a4867cf8d55de77d31f8868b899 (diff)
downloadShaarli-fd006c630b64146edc402b68d8503c716f8a55d6.tar.gz
Shaarli-fd006c630b64146edc402b68d8503c716f8a55d6.tar.zst
Shaarli-fd006c630b64146edc402b68d8503c716f8a55d6.zip
Merge pull request #275 from shaarli/plugin-proposition
Plugin proposition
Diffstat (limited to 'application/Router.php')
-rw-r--r--application/Router.php105
1 files changed, 105 insertions, 0 deletions
diff --git a/application/Router.php b/application/Router.php
new file mode 100644
index 00000000..82b2b858
--- /dev/null
+++ b/application/Router.php
@@ -0,0 +1,105 @@
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
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_LINKLIST = 'linklist';
33
34 /**
35 * Reproducing renderPage() if hell, to avoid regression.
36 *
37 * This highlights how bad this needs to be rewrite,
38 * but let's focus on plugins for now.
39 *
40 * @param string $query $_SERVER['QUERY_STRING'].
41 * @param array $get $_SERVER['GET'].
42 * @param bool $loggedIn true if authenticated user.
43 *
44 * @return self::page found.
45 */
46 public static function findPage($query, $get, $loggedIn)
47 {
48 $loggedIn = ($loggedIn === true) ? true : false;
49
50 if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) {
51 return self::$PAGE_LINKLIST;
52 }
53
54 if (startswith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) {
55 return self::$PAGE_LOGIN;
56 }
57
58 if (startswith($query, 'do='. self::$PAGE_PICWALL)) {
59 return self::$PAGE_PICWALL;
60 }
61
62 if (startswith($query, 'do='. self::$PAGE_TAGCLOUD)) {
63 return self::$PAGE_TAGCLOUD;
64 }
65
66 // At this point, only loggedin pages.
67 if (!$loggedIn) {
68 return self::$PAGE_LINKLIST;
69 }
70
71 if (startswith($query, 'do='. self::$PAGE_TOOLS)) {
72 return self::$PAGE_TOOLS;
73 }
74
75 if (startswith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) {
76 return self::$PAGE_CHANGEPASSWORD;
77 }
78
79 if (startswith($query, 'do='. self::$PAGE_CONFIGURE)) {
80 return self::$PAGE_CONFIGURE;
81 }
82
83 if (startswith($query, 'do='. self::$PAGE_CHANGETAG)) {
84 return self::$PAGE_CHANGETAG;
85 }
86
87 if (startswith($query, 'do='. self::$PAGE_ADDLINK)) {
88 return self::$PAGE_ADDLINK;
89 }
90
91 if (isset($get['edit_link']) || isset($get['post'])) {
92 return self::$PAGE_EDITLINK;
93 }
94
95 if (startswith($query, 'do='. self::$PAGE_EXPORT)) {
96 return self::$PAGE_EXPORT;
97 }
98
99 if (startswith($query, 'do='. self::$PAGE_IMPORT)) {
100 return self::$PAGE_IMPORT;
101 }
102
103 return self::$PAGE_LINKLIST;
104 }
105} \ No newline at end of file