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

Documentation generated on Fri, 16 Oct 2009 09:39:04 +0200 by phpDocumentor 1.4.1