linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file rewrite.php

Documentation is available at rewrite.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage public
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11. $url $_SERVER['REQUEST_URI'];
  12.  
  13.  
  14. include_once('../config/define.php');
  15.  
  16.  
  17. /**
  18.  * We identify the folder structure of
  19.  * the application to remove it
  20.  * and perform URL rewriting
  21.  * @sample : www.domain.tld/ [linea21/public/] part removed
  22.  */
  23. if(strpos(CURRENT_APP_URL'/'7)) {
  24.   $url str_replace(substr(CURRENT_APP_URLstrpos(CURRENT_APP_URL'/'71)''$url);
  25. }
  26.  
  27. /**
  28.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR NAME @@$_REQUEST['filter'] URI_SEPARATOR $_REQUEST['id'] .html
  29.  * OR
  30.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR NAME @@$_REQUEST['filter'] URI_SEPARATOR NAME , $_REQUEST['id'] .html
  31.  * sample: directory/@@theme/environnement,3.html
  32.  * sample: directory/@@alpha/P.html
  33.  */
  34. if(preg_match('#^/(.+)'.URI_SEPARATOR.'(@@)(.+)'.URI_SEPARATOR.'(.+)\.html$#'$url$match)) {
  35.  
  36.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  37.   $_REQUEST['filter'$match[3];
  38.   // check if the last captured contains a comma
  39.   if(strpos($match[4]',')) {
  40.     list($name$idexplode(','$match[4]);
  41.     $_REQUEST['id'$id;
  42.   else {
  43.     $_REQUEST['id'$match[4];
  44.   }
  45.  
  46.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  47.   include("index.php");
  48.   exit();
  49. }
  50.  
  51. /**
  52.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR [NAME , -optional] $_REQUEST['id'] URI_SEPARATOR $_REQUEST['parentid'] URI_SEPARATOR $_REQUEST['parentparentid'] .html
  53.  * sample: message/industrial-ecology-initiation,5/1/4.html
  54.  */
  55. if(preg_match('#^/(.+)'.URI_SEPARATOR.'(.+)'.URI_SEPARATOR.'(.+)'.URI_SEPARATOR.'(.+)\.html$#'$url$match)) {
  56.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  57.  
  58.   // check if the last captured contains a comma
  59.   if(strpos($match[2]',')) {
  60.     list($name$idexplode(','$match[2]);
  61.     $_REQUEST['id'$id;
  62.   }
  63.   else $_REQUEST['id'$match[2];
  64.   $_REQUEST['parentid'$match[3];
  65.  
  66.   // Check pagination
  67.   if(preg_match('#^-(\d+)-$#'$match[4]$submatch)) {
  68.     $_REQUEST['debut'$submatch[1];
  69.   }
  70.   else $_REQUEST['parentparentid'$match[4];
  71.  
  72.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  73.   include("index.php");
  74.   exit();
  75. }
  76.  
  77. /**
  78.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR [NAME , -optional] $_REQUEST['id'] URI_SEPARATOR [$_REQUEST['parentid'] OR $_REQUEST['debut']] .html
  79.  * sample: publication-part/l-alcazar-deuxieme-partie,2/1.html
  80.  */
  81. if(preg_match('#^/(.+)'.URI_SEPARATOR.'(.+)'.URI_SEPARATOR.'(.+)\.html$#'$url$match)) {
  82.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  83.  
  84.   // check if the last captured contains a comma
  85.   if(strpos($match[2]',')) {
  86.     list($name$idexplode(','$match[2]);
  87.     $_REQUEST['id'$id;
  88.   }
  89.   else $_REQUEST['id'$match[2];
  90.  
  91.   // Check pagination
  92.   if(preg_match('#^-(\d+)-$#'$match[3]$submatch)) {
  93.     $_REQUEST['debut'$submatch[1];
  94.   }
  95.   else $_REQUEST['parentid'$match[3];
  96.  
  97.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  98.   include("index.php");
  99.   exit();
  100. }
  101.  
  102. /**
  103.  * Handle Pagination
  104.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR [NAME , -optional] [$_REQUEST['id'] OR $_REQUEST['debut']] .html
  105.  * sample: news/a-new-tool-for-the-city,2.html
  106.  * sample: news/a-new-tool-for-the-city,2.html
  107.  * sample: directory/-6-.html
  108.  */
  109. if(preg_match('#^/(.+)'.URI_SEPARATOR.'(.+)\.html$#'$url$match))
  110. {
  111.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  112.  
  113.   // check if the last captured contains a comma
  114.   if(strpos($match[2]',')) {
  115.     list($name$idexplode(','$match[2]);
  116.     $_REQUEST['id'$id;
  117.   else {
  118.     // Check pagination
  119.     if(preg_match('#^-(\d+)-$#'$match[2]$submatch)) {
  120.       $_REQUEST['debut'$submatch[1];
  121.     }
  122.     else $_REQUEST['id'$match[2];
  123.   }
  124.  
  125.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  126.   include("index.php");
  127.   exit();
  128. }
  129.  
  130. /**
  131.  * Simple format
  132.  * Pattern: $_REQUEST['rub']  .html
  133.  * sample: news.html
  134.  */
  135. if(preg_match('#^/(.+)\.html$#'$url$match))
  136. {
  137.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  138.  
  139.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  140.   include("index.php");
  141.   exit();
  142. }
  143. header("Location: error.php");
  144. exit();
  145. ?>

Documentation generated on Thu, 03 May 2012 15:07:31 +0200 by phpDocumentor 1.4.1