phpDocumentor lodel-source
[ class tree: lodel-source ] [ index: lodel-source ] [ all elements ]

Source for file index.php

Documentation is available at index.php

  1. <?php
  2. /**
  3.  * Fichier racine - porte d'entrée principale du site
  4.  *
  5.  * Ce fichier permet de faire appel aux différentes entités (documents), via leur id, leur
  6.  * identifier (lien permanent). Il permet aussi d'appeler un template particulier (via l'argument
  7.  * page=)
  8.  * Voici des exemples d'utilisations
  9.  * <code>
  10.  * index.php?/histoire/france/charlemagne-le-pieux
  11.  * index.php?id=48
  12.  * index.php?page=rss20
  13.  * index.php?do=view&idtype=2
  14.  * </code>
  15.  *
  16.  * PHP versions 4 et 5
  17.  *
  18.  * LODEL - Logiciel d'Edition ELectronique.
  19.  *
  20.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  21.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  22.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  23.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  24.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  25.  * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  26.  *
  27.  * Home page: http://www.lodel.org
  28.  *
  29.  * E-Mail: lodel@lodel.org
  30.  *
  31.  * All Rights Reserved
  32.  *
  33.  * This program is free software; you can redistribute it and/or modify
  34.  * it under the terms of the GNU General Public License as published by
  35.  * the Free Software Foundation; either version 2 of the License, or
  36.  * (at your option) any later version.
  37.  *
  38.  * This program is distributed in the hope that it will be useful,
  39.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  41.  * GNU General Public License for more details.
  42.  *
  43.  * You should have received a copy of the GNU General Public License
  44.  * along with this program; if not, write to the Free Software
  45.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46.  *
  47.  * @author Ghislain Picard
  48.  * @author Jean Lamy
  49.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  50.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  51.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  52.  * @licence http://www.gnu.org/copyleft/gpl.html
  53.  * @version CVS:$Id:
  54.  * @package lodel/source
  55.  */
  56.  
  57. require 'siteconfig.php';
  58. // vérifie l'intégrité de l'url demandée
  59. if('path' != URI && preg_match("/^".preg_quote($urlroot.$site'/')."\/(index|signaler|backend|logout|oai|search)(\d*)\.$extensionscripts(\?[^\/]*)?(\/.*)$/"$_SERVER['REQUEST_URI'])>0{
  60.     header("HTTP/1.0 403 Bad Request");
  61.     header("Status: 403 Bad Request");
  62.     header("Connection: Close");
  63.     include "../missing.html";
  64.     exit;
  65. }
  66. //gestion de l'authentification
  67. require_once 'auth.php';
  68. // record the url if logged
  69. if ($lodeluser['rights'>= LEVEL_VISITOR{
  70.     recordurl();
  71. }
  72.  
  73. require_once 'view.php';
  74. $view &View::getView();
  75. if(empty($_POST)) // pas d'utilisation du cache pour traiter correctement les formulaires
  76.     // get the view and check the cache.
  77.     if ($view->renderIfCacheIsValid()) {
  78.         return;
  79.     }
  80. }
  81. // require 'textfunc.php';
  82. $id         intval($_GET['id']);
  83. $identifier $_GET['identifier'];
  84. $page       $_GET['page']// get only
  85. $do         $_POST['do'$_POST['do'$_GET['do'];
  86. $tpl        'index'// template by default.
  87.  
  88.  
  89. // ID ou IDENTIFIER
  90. $url_retour strip_tags($url_retour);
  91.  
  92. if ($_POST['login']{
  93.     require_once 'func.php';
  94.     extract_post();
  95. //     require_once 'connect.php';
  96.     require_once 'loginfunc.php';
  97.     do {
  98.         if (!check_auth_restricted($context['login']$context['passwd']$site)) {
  99.             $context['error_login'$err 1;
  100.             break;
  101.         }
  102.  
  103.         //vérifie que le compte n'est pas en suspend. Si c'est le cas, on amène l'utilisateur à modifier son mdp, sinon on l'identifie
  104.         if(!check_expiration()) {
  105.             $context['error_expiration'$err 1;
  106.             unset($context['lodeluser']);
  107.             break;
  108.         }
  109.         else {
  110.             // ouvre une session
  111.             $err open_session($context['login']);
  112.             if ($err{
  113.                 $context[$err$err 1;
  114.                 break;
  115.             }
  116.         }
  117.         $context['passwd'$passwd 0;
  118.     while (0);
  119.     if($err// une erreur : besoin de l'afficher, donc pas d'utilisation du cache
  120.         $_REQUEST['clearcache'1;
  121. if ($id || $identifier{
  122. //     require_once 'connect.php';
  123.     do // exception block
  124.         require_once 'func.php';
  125.         if ($id{
  126.             $class $db->getOne(lq("SELECT class FROM #_TP_objects WHERE id='$id'"));
  127.             if ($db->errorno(&& $lodeluser['rights'LEVEL_VISITOR{
  128.                 dberror();
  129.             }
  130.             if (!$class
  131.                 header("HTTP/1.0 403 Internal Error");
  132.                 header("Status: 403 Internal Error");
  133.                 header("Connection: Close");
  134.                 if(file_exists($home."../../missing.html")) {
  135.                     include $home."../../missing.html";
  136.                 else {
  137.                     header('Location: not-found.html');
  138.                 }
  139.                 exit
  140.             }
  141.         elseif ($identifier{
  142.             $class 'entities';
  143.         else {
  144.             die("?? strange");
  145.         }
  146.         switch($class{
  147.         case 'entities':
  148.             printEntities($id$identifier$context);
  149.             break;
  150.         case 'entrytypes':
  151.         case 'persontypes':
  152.             $result $db->execute(lq("SELECT * FROM #_TP_"$class" WHERE id='"$id"' AND status>0")) or dberror();
  153.             $context['type'$result->fields;
  154.             $view &View::getView();
  155.             $view->renderCached($context$result->fields['tplindex']);
  156.             exit;
  157.         case 'persons':
  158.         case 'entries':
  159.             printIndex($id$class$context);
  160.             break;
  161.         // switch class
  162.     while(0);
  163.  
  164. //PAGE
  165. elseif ($page// call a special page (and template)
  166.     if (strlen($page64 || preg_match("/[^a-zA-Z0-9_\/-]/"$page)) {
  167.         die('invalid page');
  168.     }
  169. //     require_once 'connect.php';
  170.     $view->renderCached($context$page);
  171.     exit;
  172.  
  173. //Appel d'une action via le model MVC
  174. elseif ($do{
  175.         require 'controler.php';
  176.     if ($do == 'edit' || $do == 'view'{
  177.         if($_GET{// to be sure nobody is going to modify something wrong
  178.             $_GET['id'0;
  179.         }
  180.         else {
  181.             $_POST['id'0;
  182.         }
  183.         // check for the right to change this document
  184.         $idtype $_POST['idtype'intval($_POST['idtype']intval($_GET['idtype'];
  185.         if (!$idtype{
  186.             die('ERROR: idtype must be given');
  187.         }
  188.  
  189.         require 'dao.php';
  190.         $dao &getDAO('types');
  191.         $vo $dao->find("id='$idtypeand public>0 and status>0");
  192.         if (!$vo{
  193.             die("ERROR: you are not allow to add this kind of document");
  194.         }
  195.  
  196.         $lodeluser['rights']  LEVEL_EDITOR// grant temporary
  197.         $lodeluser['editor']  1;
  198.         $context['lodeluser'$lodeluser;
  199.         $accepted_logic array('entities_edition');
  200.         $called_logic 'entities_edition';
  201.         $Controler new controler($accepted_logic$called_logic);
  202.         exit;
  203.     else {
  204.         die('ERROR: unknown action');
  205.     }
  206. else {
  207.     //tente de récupérer le path - parse la query string pour trouver l'entité
  208.  
  209. //     require_once 'connect.php';
  210.     $query preg_replace("/[&?](format|clearcache)=\w+/"''$_SERVER['QUERY_STRING']);
  211.     
  212.     if($query && !preg_match("/[^a-zA-Z0-9_\/-]/"$query)) {
  213.         // maybe a path to the document
  214.         $path preg_split("#/#"$query-1PREG_SPLIT_NO_EMPTY);
  215.         $entity end($path);
  216.         $id intval($entity);
  217.         if ($id{
  218.             printEntities($id''$context);
  219.         }
  220.     else {
  221.         // rien à faire.
  222.     }
  223. }
  224.  
  225. $view->renderCached($context'index');
  226.  
  227.  
  228. /**
  229.  * Affichage d'une entité
  230.  *
  231.  * Affiche une entité grâce à son id, son identifiant. Appelle la vue associée
  232.  *
  233.  * @param integer $id identifiant de l'entité
  234.  * @param string $identifier l'identifiant littéral de l'entité
  235.  * @param array &$context le contexte par référence
  236.  */
  237. function printEntities($id$identifier&$context)
  238. {
  239.     global $lodeluser$home$db;
  240.     $context['classtype''entities';
  241.     $critere $lodeluser['visitor''AND #_TP_entities.status>-64' 'AND #_TP_entities.status>0 AND #_TP_types.status>0';
  242.  
  243.     // cherche le document, et le template
  244.     do {
  245.         if ($identifier{
  246.             $identifier addslashes(stripslashes(substr($identifier0255)));
  247.             $where "#_TP_entities.identifier='"$identifier"' "$critere;
  248.         else {
  249.             $where "#_TP_entities.id='"$id"' "$critere;
  250.         }
  251.         $row $db->getRow(lq("SELECT #_TP_entities.*,tpl,type,class FROM #_entitiestypesjoin_ WHERE "$where));
  252.         if ($row === false{
  253.             dberror();
  254.         }
  255.         if (!$row
  256.             header("HTTP/1.0 403 Internal Error");
  257.             header("Status: 403 Internal Error");
  258.             header("Connection: Close");
  259.             if(file_exists($home."../../missing.html")) {
  260.                 include $home."../../missing.html";
  261.             else {
  262.                 header('Location: not-found.html');
  263.             }
  264.             exit
  265.         }
  266.         $base $row['tpl']// le template à utiliser pour l'affichage
  267.         if (!$base
  268.             $id $row['idparent'];
  269.             $relocation TRUE;
  270.         }
  271.     while (!$base && !$identifier && $id)
  272.  
  273.     if ($relocation
  274.         header('location: 'makeurlwithid('index'$row['id']));
  275.         exit;
  276.     }
  277.     $context array_merge($context$row);
  278.     $row $db->getRow(lq("SELECT * FROM #_TP_"$row['class']" WHERE identity='"$row['id']"'"));
  279.     if ($row === false{
  280.         dberror();
  281.     }
  282.     if (!$row{
  283.         header("HTTP/1.0 403 Internal Error");
  284.         header("Status: 403 Internal Error");
  285.         header("Connection: Close");
  286.         if(file_exists($home."../../missing.html")) {
  287.             include $home."../../missing.html";
  288.         else {
  289.             header('Location: not-found.html');
  290.         }
  291.         exit
  292.     }
  293.     if (!(@include_once('CACHE/filterfunc.php'))) {
  294.         require_once 'filterfunc.php';
  295.     }
  296.     //Merge $row et applique les filtres définis dans le ME
  297.     merge_and_filter_fields($context$context['class']$row);
  298.     getgenericfields($context)// met les champs génériques de l'entité dans le contexte
  299.     $view=&View::getView();
  300.     $view->renderCached($context$base);
  301.     exit;
  302. }
  303.  
  304. /**
  305.  * Affichage d'un objet de type index
  306.  *
  307.  * @param integer $id identifiant numérique de l'index
  308.  * @param string $classtype type de la classe
  309.  * @param array &$context le context par référence
  310.  */
  311. function printIndex($id$classtype&$context)
  312. {
  313.     global $lodeluser$home$db;
  314.     $context['classtype'$classtype;
  315.     switch($classtype{
  316.     case 'persons':
  317.         $typetable '#_TP_persontypes';
  318.         $table     '#_TP_persons';
  319.         $longid    'idperson';
  320.         break;
  321.     case 'entries':
  322.         $typetable '#_TP_entrytypes';
  323.         $table     '#_TP_entries';
  324.         $longid    'identry';
  325.         break;
  326.     default:
  327.         die('ERROR: internal error in printIndex');
  328.     }
  329.  
  330.     // get the index
  331.     $critere $lodeluser['visitor''AND status>-64' 'AND status>0';
  332.     $row $db->getRow(lq("SELECT * FROM "$table" WHERE id='"$id"' "$critere));
  333.     if ($row === false{
  334.         dberror();
  335.     }
  336.     if (!$row{
  337.         header("HTTP/1.0 403 Internal Error");
  338.         header("Status: 403 Internal Error");
  339.         header("Connection: Close");
  340.         if(file_exists($home."../../missing.html")) {
  341.             include $home."../../missing.html";
  342.         else {
  343.             header('Location: not-found.html');
  344.         }
  345.         exit;
  346.     }
  347.     $context array_merge($context$row);
  348.     // get the type
  349.     $row $db->getRow(lq("SELECT * FROM "$typetable" WHERE id='"$row['idtype']"'"$critere));
  350.     if ($row === false{
  351.         dberror();
  352.     }
  353.     if (!$row{
  354.         header("HTTP/1.0 403 Internal Error");
  355.         header("Status: 403 Internal Error");
  356.         header("Connection: Close");
  357.         if(file_exists($home."../../missing.html")) {
  358.             include $home."../../missing.html";
  359.         else {
  360.             header('Location: not-found.html');
  361.         }
  362.         exit;
  363.     }
  364.     $base            $row['tpl'];
  365.     $context['type'$row;
  366.  
  367.     // get the associated table
  368.     $row $db->getRow(lq("SELECT * FROM #_TP_".$row['class']." WHERE ".$longid."='".$id."'"));
  369.     if ($row === false{
  370.         dberror();
  371.     }
  372.     if (!$row{
  373.         die("ERROR: internal error");
  374.     }
  375.     if (!(@include_once("CACHE/filterfunc.php"))) {
  376.         require_once "filterfunc.php";
  377.     }
  378.     merge_and_filter_fields($context$row['class']$row);
  379.     #getgenericfields($context);
  380.     $view &View::getView();
  381.     $view->renderCached($context$base);
  382.     exit;
  383. }
  384.  
  385. ?>

Documentation generated on Thu, 19 Jun 2008 05:07:54 +0200 by phpDocumentor 1.4.0a2