papaya CMS PHP Cross Reference Content Management Systems

Source: /router.php - 76 lines - 1700 bytes - Summary - Text - Print

Description: router script that allows to use the php builtin webserver for papaya CMS

   1  <?php
   2  /**
   3  * router script that allows to use the php builtin webserver for papaya CMS
   4  * 
   5  * cd /your/directory
   6  * php -S localhost:80 router.php
   7  */
   8  
   9  $uri = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
  10  // remove query string and/or fragment
  11  $uri = preg_replace('([?#].*$)', '', $uri);
  12  
  13  
  14  $rules = array(
  15    // remove session identifier
  16    '(/?sid[a-z]*([a-zA-Z0-9,-]{20,40})(/.*))' => array(
  17      'replacement' => '$2'  
  18    ),
  19    '(^/?papaya/module\_([a-z0-9\_]+)\.[a-z]{3,4})' => array(
  20      'replacement' => '/papaya/module.php',
  21      'last' => TRUE
  22    ),
  23    '(^/?
  24      ([a-fA-F0-9]/)*[a-zA-Z0-9_-]+\.
  25      (media|thumb|download|popup|image)
  26      (\.(preview))?
  27      ((\.([a-zA-Z0-9_]+))?
  28      (\.[a-zA-Z0-9_]+))
  29      $)x' => array(
  30        'replacement' => '/index.php',
  31        'last' => TRUE
  32    ),
  33    '(^/?
  34      [a-zA-Z0-9_-]+
  35      ((\.[0-9]+)?\.[0-9]+)
  36      ((\.[a-z]{2,5})?\.[a-z]+)
  37      ((\.[0-9]+)?.preview)
  38      ?$)x' => array(
  39      'replacement' => '/index.php',
  40      'last' => TRUE
  41    ),          
  42    '(^/?index((\.[a-z]{2,5})?\.[a-z]+)((\.[0-9]+)?.preview)?$)' => array(
  43      'replacement' => '/index.php',
  44      'last' => TRUE
  45    )
  46  );
  47  
  48  
  49  if (file_exists(__DIR__.$uri)) {
  50    return FALSE;
  51  }
  52  
  53  foreach ($rules as $pattern => $options) {
  54    if (preg_match($pattern, $uri)) {
  55      $uri = preg_replace($pattern, $options['replacement'], $uri);
  56      if (isset($options['last']) && $options['last']) {
  57        break;
  58      }
  59    }
  60  }
  61  $file = __DIR__.$uri;
  62  
  63  define('PAPAYA_DOCUMENT_ROOT', __DIR__.'/');
  64  if (file_exists($file)) {
  65    if (is_file($file)) {
  66      chdir(dirname($file));
  67      include($file);
  68      return TRUE;
  69    } elseif (is_dir($file)) {
  70      chdir($file);
  71      include ('index.php');
  72      return TRUE;
  73    }
  74  }
  75  
  76  return FALSE;

title

Description

title

Description

title

Description

title

title

Body