Guest User

Untitled

a guest
Nov 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. <?php
  2. /**
  3. * @todo Test for abuses/bugs?
  4. * @todo FCGI: use PATH_INFO and rewrite this.
  5. */
  6.  
  7. if (!defined ('KS_VALID_KEY') || KS_VALID_KEY !== '01xs3141ffKl')
  8. die ();
  9.  
  10. class Rewrite extends Main
  11. {
  12. /**
  13. * @deprecated
  14. *
  15. * NOTE:
  16. * THE ENTIRE $_GET VARIABLE AS PASSED BY HTML (knightsshout.com/home.php?somevar=someval) IS REPLACED.
  17. * HENCE MAKE USE OF THE URI_REWRITE SYSTEM.
  18. *
  19. * UPDATED AS OF 18TH APRIL '11
  20. * THE CURRENT URI PATTERNS ARE AS FOLLOWS:
  21. * /$page.php/$params
  22. * $params may be split by as many / as you wish. every / declares a new stack in the $_GET array
  23. * /$page.php
  24. * for calling a page w/o any params.
  25. * /ajax/$page.php/$params
  26. * again, $params may be split by as many / as you wish. see above ^.
  27. * /ajax/$page.php
  28. * for calling a single ajax page w/o $_GETs
  29. * YOU CAN ADD FURTHER PATTERNS BY EXTENDING THE $uri_patterns ARRAY!
  30. * DON'T FORGET TO DOCUMENT THEM AS ABOVE ^, IF YOU ADD ONE!
  31. */
  32.  
  33. /*
  34. public $uri_patterns = array (
  35. //'regular_expression' => 'replace_mode'
  36. 'ajax\/(.+)\.php\/?(([^\/]+)\/?)*\/?' => 'i',
  37. '(.+)\.php\/?(([^\/]+)\/?)*' => 'i'
  38. );
  39. */
  40. public $uri_modules = array (
  41. 'ajax' => 'use_ajax'
  42. );
  43. public $act;
  44. public $act_clean;
  45. #public $params = array ();
  46.  
  47. function Rewrite ($conf)
  48. {
  49. $true = false;
  50. /**
  51. * prepare for implementation of $_GETs
  52. */
  53. $uri = preg_match ('/\?/', $_SERVER['REQUEST_URI'], &$true) ? substr ($_SERVER['REQUEST_URI'], 0, strpos ($_SERVER['REQUEST_URI'], '?')) : $_SERVER['REQUEST_URI'];
  54. /**
  55. * @deprecated
  56. *
  57. * clear the $_GET global var, so we can make use of it
  58. * for our own stuff. no need to use ?s after all,
  59. * we got our own rewriting anyways.
  60. */
  61. #$_GET = array ();
  62. $_GET = explode ('/', $uri);
  63. array_shift ($_GET);
  64.  
  65. /**
  66. * implement $_GET
  67. */
  68. if ($true !== false && !empty ($true[0]))
  69. {
  70. $str = '&' . substr ($_SERVER['REQUEST_URI'], (strpos ($_SERVER['REQUEST_URI'], '?') + 1));
  71. $arr = split ('&', $str);
  72. array_shift ($arr);
  73. foreach ($arr as $arg)
  74. {
  75. $para = split ('=', $arg);
  76. $_GET[$para[0]] = $para[1];
  77. }
  78. /**
  79. * debugging
  80. */
  81. #print_r ($arr);
  82. /**
  83. * ^ uncomment to debug
  84. */
  85. }
  86.  
  87. foreach ($this->uri_modules as $module => $term)
  88. {
  89. $_GET[$term] = !empty ($_GET[0]) ? ($_GET[0] === $module ? 1 : 0) : 0;
  90. if ($_GET[$term])
  91. array_shift ($_GET);
  92. }
  93.  
  94. if (array_key_exists (@$_GET[0], $conf['pages']))
  95. {
  96. $this->act_clean = $_GET[0];
  97. $this->act = $conf['pages'][$_GET[0]];
  98. array_shift ($_GET);
  99. }
  100. else
  101. {
  102. $this->act_clean = $conf['pages'][0];
  103. $this->act = reset ($conf['pages']);
  104. }
  105.  
  106. /**
  107. * debugging
  108. */
  109. print_r ($_GET);
  110. /**
  111. * ^ uncomment to debug.
  112. */
  113.  
  114. /**
  115. * @deprecated
  116. foreach ($this->uri_patterns as $pattern => $mode)
  117. if (preg_match ('/\\b' . $pattern . '$\\b/' . $mode, $uri, $match))
  118. break;
  119. @array_shift ($match);
  120. $this->act_clean = @$match[0];
  121. $this->act = array_key_exists (@$match[0], $conf['pages']) ? $conf['pages'][$match[0]] : reset ($conf['pages']);
  122. @array_shift ($match);
  123. $_GET = $this->params = $match;
  124. */
  125.  
  126. /**
  127. * Check for Modules
  128. */
  129. /*
  130. $mod = substr ($_SERVER['REQUEST_URI'], 1, strpos (substr ($_SERVER['REQUEST_URI'], 1), '/'));
  131. foreach ($this->uri_modules as $module => $term)
  132. $this->params[$term] = $_GET[$term] = $module === $mod ? 1 : 0;
  133. */
  134. /**
  135. * if you experience any problems with the
  136. * url_rewriting and aren't quite sure what to do,
  137. * a good idea would be to parse the eval'd params
  138. */
  139. #print_r ($this->params);
  140. /**
  141. * by uncommenting the ^ above line.
  142. * or just catch me up on msn. ;o
  143. */
  144. }
  145. }
  146. ?>
Add Comment
Please, Sign In to add comment