stuppid_bot

Untitled

Jul 9th, 2013
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. define('META_CHARSET', 'utf-8');
  5. $base_uri = dirname($_SERVER['SCRIPT_NAME']);
  6.  
  7. if ($base_uri != '/') {
  8.     $base_uri .= '/';
  9. }
  10.  
  11. $base_url = (isset($_SERVER['HTTPS']) ? 'https:' : '') . '//' . $_SERVER['HTTP_HOST'] . $base_uri;
  12. define('BASE_URI', $base_uri);
  13. define('BASE_URL', $base_url);
  14.  
  15. function error_404() {
  16.     http_response_code(404);
  17.     $title = 'Страница не найдена';
  18.     $css = array('styles/reset.css', 'styles/page.css');
  19.     $js = array('js/common.js');
  20.     $txt = '<p>Страница не найдена.</p>';
  21.     include 'includes/page.php';
  22. }
  23.  
  24. $default_route = 'error_404';
  25. $routes = array(
  26.     'GET' => array(
  27.         '#^(?:pages\/([1-9]\d*))?$#' => 'all_posts'
  28.     ),
  29.     'POST' => array(),
  30.     'PUT' => array(),
  31.     'DELETE' => array()
  32. );
  33.  
  34. function all_posts($page = 1) {
  35.     // var_dump($page);
  36.     $title = 'Все посты / Страница ' . $page;
  37.     $css = array('styles/reset.css', 'styles/page.css');
  38.     $js = array('js/common.js');
  39.     include 'includes/page.php';
  40. }
  41.  
  42. function run_route() {
  43.     global $routes, $default_route;
  44.     $_  = $routes[$_SERVER['REQUEST_METHOD']];
  45.     $u = @$_GET['_url'];
  46.  
  47.     foreach ($_ as $k => $v) {
  48.         if (@preg_match($k, '')) {
  49.             if (preg_match($k, $u, $m)) {
  50.                 return call_user_func_array($v, array_slice($m, 1));
  51.             }
  52.         }
  53.         else if ($k == $u) {
  54.             return call_user_func($v);
  55.         }
  56.     }
  57.  
  58.     call_user_func($default_route);
  59. }
  60.  
  61. run_route();
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment