Router.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /**
  24. * Reproducing renderPage() if hell, to avoid regression.
  25. *
  26. * This highlights how bad this needs to be rewrite,
  27. * but let's focus on plugins for now.
  28. *
  29. * @param string $query $_SERVER['QUERY_STRING'].
  30. * @param array $get $_SERVER['GET'].
  31. * @param bool $loggedIn true if authenticated user.
  32. *
  33. * @return self::page found.
  34. */
  35. public static function findPage($query, $get, $loggedIn)
  36. {
  37. $loggedIn = ($loggedIn === true) ? true : false;
  38. if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) {
  39. return self::$PAGE_LINKLIST;
  40. }
  41. if (startswith($query, 'do='. self::$PAGE_LOGIN) && $loggedIn === false) {
  42. return self::$PAGE_LOGIN;
  43. }
  44. if (startswith($query, 'do='. self::$PAGE_PICWALL)) {
  45. return self::$PAGE_PICWALL;
  46. }
  47. if (startswith($query, 'do='. self::$PAGE_TAGCLOUD)) {
  48. return self::$PAGE_TAGCLOUD;
  49. }
  50. if (startswith($query, 'do='. self::$PAGE_OPENSEARCH)) {
  51. return self::$PAGE_OPENSEARCH;
  52. }
  53. if (startsWith($query, 'do='. self::$PAGE_DAILY)) {
  54. return self::$PAGE_DAILY;
  55. }
  56. // At this point, only loggedin pages.
  57. if (!$loggedIn) {
  58. return self::$PAGE_LINKLIST;
  59. }
  60. if (startswith($query, 'do='. self::$PAGE_TOOLS)) {
  61. return self::$PAGE_TOOLS;
  62. }
  63. if (startswith($query, 'do='. self::$PAGE_CHANGEPASSWORD)) {
  64. return self::$PAGE_CHANGEPASSWORD;
  65. }
  66. if (startswith($query, 'do='. self::$PAGE_CONFIGURE)) {
  67. return self::$PAGE_CONFIGURE;
  68. }
  69. if (startswith($query, 'do='. self::$PAGE_CHANGETAG)) {
  70. return self::$PAGE_CHANGETAG;
  71. }
  72. if (startswith($query, 'do='. self::$PAGE_ADDLINK)) {
  73. return self::$PAGE_ADDLINK;
  74. }
  75. if (isset($get['edit_link']) || isset($get['post'])) {
  76. return self::$PAGE_EDITLINK;
  77. }
  78. if (startswith($query, 'do='. self::$PAGE_EXPORT)) {
  79. return self::$PAGE_EXPORT;
  80. }
  81. if (startswith($query, 'do='. self::$PAGE_IMPORT)) {
  82. return self::$PAGE_IMPORT;
  83. }
  84. return self::$PAGE_LINKLIST;
  85. }
  86. }