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. ifisset($_SERVER['HTTPS') ) {
  24.     $startposition 8;
  25. else {
  26.     $startposition 7;
  27. }
  28. if(strpos(CURRENT_APP_URL'/'$startposition)) {
  29.   $url str_replace(substr(CURRENT_APP_URLstrpos(CURRENT_APP_URL'/'$startposition1)''$url);
  30. }
  31.  
  32. /**
  33.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR NAME @@$_REQUEST['filter'] URI_SEPARATOR $_REQUEST['id'] .html
  34.  * OR
  35.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR NAME @@$_REQUEST['filter'] URI_SEPARATOR NAME , $_REQUEST['id'] .html
  36.  * sample: directory/@@theme/environnement,3.html
  37.  * sample: directory/@@alpha/P.html
  38.  */
  39. if(preg_match('#^/(.+)'.URI_SEPARATOR.'(@@)(.+)'.URI_SEPARATOR.'(.+)\.html$#'$url$match)) {
  40.  
  41.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  42.   $_REQUEST['filter'$match[3];
  43.   // check if the last captured contains a comma
  44.   if(strpos($match[4]',')) {
  45.     list($name$idexplode(','$match[4]);
  46.     $_REQUEST['id'$id;
  47.   else {
  48.     $_REQUEST['id'$match[4];
  49.   }
  50.  
  51.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  52.   include("index.php");
  53.   exit();
  54. }
  55.  
  56. /**
  57.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR [NAME , -optional] $_REQUEST['id'] URI_SEPARATOR $_REQUEST['parentid'] URI_SEPARATOR $_REQUEST['parentparentid'] .html
  58.  * sample: message/industrial-ecology-initiation,5/1/4.html
  59.  */
  60. if(preg_match('#^/(.+)'.URI_SEPARATOR.'(.+)'.URI_SEPARATOR.'(.+)'.URI_SEPARATOR.'(.+)\.html$#'$url$match)) {
  61.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  62.  
  63.   // check if the last captured contains a comma
  64.   if(strpos($match[2]',')) {
  65.     list($name$idexplode(','$match[2]);
  66.     $_REQUEST['id'$id;
  67.   }
  68.   else $_REQUEST['id'$match[2];
  69.   $_REQUEST['parentid'$match[3];
  70.  
  71.   // Check pagination
  72.   if(preg_match('#^-(\d+)-$#'$match[4]$submatch)) {
  73.     $_REQUEST['debut'$submatch[1];
  74.   }
  75.   else $_REQUEST['parentparentid'$match[4];
  76.  
  77.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  78.   include("index.php");
  79.   exit();
  80. }
  81.  
  82. /**
  83.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR [NAME , -optional] $_REQUEST['id'] URI_SEPARATOR [$_REQUEST['parentid'] OR $_REQUEST['debut']] .html
  84.  * sample: publication-part/l-alcazar-deuxieme-partie,2/1.html
  85.  */
  86. if(preg_match('#^/(.+)'.URI_SEPARATOR.'(.+)'.URI_SEPARATOR.'(.+)\.html$#'$url$match)) {
  87.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  88.  
  89.   // check if the last captured contains a comma
  90.   if(strpos($match[2]',')) {
  91.     list($name$idexplode(','$match[2]);
  92.     $_REQUEST['id'$id;
  93.   }
  94.   else $_REQUEST['id'$match[2];
  95.  
  96.   // Check pagination
  97.   if(preg_match('#^-(\d+)-$#'$match[3]$submatch)) {
  98.     $_REQUEST['debut'$submatch[1];
  99.   }
  100.   else $_REQUEST['parentid'$match[3];
  101.  
  102.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  103.   include("index.php");
  104.   exit();
  105. }
  106.  
  107. /**
  108.  * Handle Pagination
  109.  * Pattern: $_REQUEST['rub'] URI_SEPARATOR [NAME , -optional] [$_REQUEST['id'] OR $_REQUEST['debut']] .html
  110.  * sample: news/a-new-tool-for-the-city,2.html
  111.  * sample: news/a-new-tool-for-the-city,2.html
  112.  * sample: directory/-6-.html
  113.  */
  114. if(preg_match('#^/(.+)'.URI_SEPARATOR.'(.+)\.html$#'$url$match))
  115. {
  116.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  117.  
  118.   // check if the last captured contains a comma
  119.   if(strpos($match[2]',')) {
  120.     list($name$idexplode(','$match[2]);
  121.     $_REQUEST['id'$id;
  122.   else {
  123.     // Check pagination
  124.     if(preg_match('#^-(\d+)-$#'$match[2]$submatch)) {
  125.       $_REQUEST['debut'$submatch[1];
  126.     }
  127.     else $_REQUEST['id'$match[2];
  128.   }
  129.  
  130.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  131.   include("index.php");
  132.   exit();
  133. }
  134.  
  135. /**
  136.  * Simple format
  137.  * Pattern: $_REQUEST['rub']  .html
  138.  * sample: news.html
  139.  */
  140. if(preg_match('#^/(.+)\.html$#'$url$match))
  141. {
  142.   $_REQUEST['rub'$GLOBALS['links'][U_L][ActiveItemKey($match[1])]['linkvalue'];
  143.  
  144.   header("HTTP/1.1 200 OK")// return 200 OK HTTP status
  145.   include("index.php");
  146.   exit();
  147. }
  148. header("Location: error.php");
  149. exit();
  150. ?>

Documentation generated on Thu, 20 Mar 2014 16:49:28 +0100 by phpDocumentor 1.4.1