Router.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Class Router
  4. *
  5. * (only displayable pages here)
  6. */
  7. class Router
  8. {
  9. public static $PAGE_LOGIN = 'login';
  10. public static $PAGE_PICWALL = 'picwall';
  11. public static $PAGE_TAGCLOUD = 'tagcloud';
  12. public static $PAGE_DAILY = 'daily';
  13. public static $PAGE_TOOLS = 'tools';
  14. public static $PAGE_CHANGEPASSWORD = 'changepasswd';
  15. public static $PAGE_CONFIGURE = 'configure';
  16. public static $PAGE_CHANGETAG = 'changetag';
  17. public static $PAGE_ADDLINK = 'addlink';
  18. public static $PAGE_EDITLINK = 'edit_link';
  19. public static $PAGE_EXPORT = 'export';
  20. public static $PAGE_IMPORT = 'import';
  21. public static $PAGE_OPENSEARCH = 'opensearch';
  22. public static $PAGE_LINKLIST = 'linklist';
  23. public static $PAGE_PLUGINSADMIN = 'pluginadmin';
  24. public static $PAGE_SAVE_PLUGINSADMIN = 'save_pluginadmin';
  25. /**
  26. * Reproducing renderPage() if hell, to avoid regression.
  27. *
  28. * This highlights how bad this needs to be rewrite,
  29. * but let's focus on plugins for now.
  30. *
  31. * @param string $query $_SERVER['QUERY_STRING'].
  32. * @param array $get $_SERVER['GET'].
  33. * @param bool $loggedIn true if authenticated user.
  34. *
  35. * @return self::page found.
  36. */
  37. public static function findPage($query, $get, $loggedIn)
  38. {
  39. $loggedIn = ($loggedIn === true) ? true : false;
  40. if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) {
  41. return self::$PAGE_LINKLIST;
  42. }
  43. if (startswith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) {
  44. return self::$PAGE_LOGIN;
  45. }
  46. if (startswith($query, 'do='. self::$PAGE_PICWALL)) {
  47. return self::$PAGE_PICWALL;
  48. }
  49. if (startswith($query, 'do='. self::$PAGE_TAGCLOUD)) {
  50. return self::$PAGE_TAGCLOUD;
  51. }
  52. if (startswith($query, 'do='. self::$PAGE_OPENSEARCH)) {
  53. return self::$PAGE_OPENSEARCH;
  54. }
  55. if (startsWith($query, 'do='. self::$PAGE_DAILY)) {
  56. return self::$PAGE_DAILY;
  57. }
  58. // At this point, only loggedin pages.
  59. if (!$loggedIn) {
  60. return self::$PAGE_LINKLIST;
  61. }
  62. if (startswith($query, 'do='. self::$PAGE_TOOLS)) {
  63. return self::$PAGE_TOOLS;
  64. }
  65. if (startswith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) {
  66. return self::$PAGE_CHANGEPASSWORD;
  67. }
  68. if (startswith($query, 'do='. self::$PAGE_CONFIGURE)) {
  69. return self::$PAGE_CONFIGURE;
  70. }
  71. if (startswith($query, 'do='. self::$PAGE_CHANGETAG)) {
  72. return self::$PAGE_CHANGETAG;
  73. }
  74. if (startswith($query, 'do='. self::$PAGE_ADDLINK)) {
  75. return self::$PAGE_ADDLINK;
  76. }
  77. if (isset($get['edit_link']) || isset($get['post'])) {
  78. return self::$PAGE_EDITLINK;
  79. }
  80. if (startswith($query, 'do='. self::$PAGE_EXPORT)) {
  81. return self::$PAGE_EXPORT;
  82. }
  83. if (startswith($query, 'do='. self::$PAGE_IMPORT)) {
  84. return self::$PAGE_IMPORT;
  85. }
  86. if (startswith($query, 'do='. self::$PAGE_PLUGINSADMIN)) {
  87. return self::$PAGE_PLUGINSADMIN;
  88. }
  89. if (startswith($query, 'do='. self::$PAGE_SAVE_PLUGINSADMIN)) {
  90. return self::$PAGE_SAVE_PLUGINSADMIN;
  91. }
  92. return self::$PAGE_LINKLIST;
  93. }
  94. }