forked from YesWiki/yeswiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude.php
executable file
·98 lines (90 loc) · 3.75 KB
/
include.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/*
$Id: include.php 835 2007-08-12 00:13:36Z gandon $
Permet d'inclure une page Wiki dans un autre page
Copyright 2003 Eric FELDSTEIN
Copyright 2003, 2004, 2006 Charles NEPOTE
Copyright 2004 Jean Christophe ANDRÉ
Copyright 2005 Didier Loiseau
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Paramètres :
-- page : nom wiki de la page a inclure (obligatoire)
-- class : nom de la classe de style à inclure (facultatif)
-- auth : option d'affichage dans le cas d'un utilisateur non autorisé (facultatif)
-- par défaut : ne fait rien
-- valeur "noError" : n'affiche aucun message d'erreur
-- edit : option d'accès en édition à la page incluse (facultatif)
-- par défaut : ne fait rien
-- valeur "show" : ajoute un lien "[Édition]" en haut à droite de la boite
*/
// récuperation du nom de la page à inclure
$incPageName = trim($this->GetParameter('page'));
/**
* @todo améliorer le traitement des classes css
*/
if ($this->GetParameter('class'))
{
$array_classes = explode(' ', $this->GetParameter('class'));
$classes = '';
foreach ($array_classes as $c)
{
if ($c && preg_match('`^[A-Za-z0-9-_]+$`', $c))
{
$classes .= ($classes ? ' ':'') . "include_$c";
}
}
}
// Affichage de la page ou d'un message d'erreur
//
if (empty($incPageName))
{
echo '<div class="alert alert-danger"><strong>'._t('ERROR').' '._t('ACTION').' Include</strong> : '._t('MISSING_PAGE_PARAMETER').'.</div>'."\n";
}
elseif ($this->IsIncludedBy($incPageName))
{
$inclusions = $this->GetAllInclusions();
$pg = strtolower($incPageName); // on l'effectue avant le for sinon il sera recalculé à chaque pas
$err = '[[' . $pg . ']]';
for($i = 0; $inclusions[$i] != $pg; $i++)
{
$err = '[[' . $inclusions[$i] . ']] > ' . $err;
}
echo '<div class="alert alert-danger"><strong>'._t('ERROR').' '._t('ACTION').' Include</strong> : '._t('IMPOSSIBLE_FOR_THIS_PAGE').' '.$incPageName.' '._t('TO_INCLUDE_ITSELF')
. ($i ? ':<br /><strong>'._t('INCLUSIONS_CHAIN').'</strong> : '.$pg.' > '.$err : '').'</div>'."\n"; // si $i = 0, alors c'est une page qui s'inclut elle-même directement...
}
elseif (!$this->HasAccess('read', $incPageName) && $this->GetParameter('auth')!='noError')
{
echo '<div class="alert alert-danger"><strong>'._t('ERROR').' '._t('ACTION').' Include</strong> : '.' '._t('READING_OF_INCLUDED_PAGE').' '.$incPageName.' '._t('NOT_ALLOWED').'.</div>'."\n";
}
elseif (!$incPage = $this->LoadPage($incPageName))
{
echo '<div class="alert alert-danger"><strong>'._t('ERROR').' '._t('ACTION').' Include</strong> : '._t('INCLUDED_PAGE').' '.$incPageName.' '._t('DOESNT_EXIST').'...</div>'."\n";
}
// Affichage de la page quand il n'y a pas d'erreur
elseif ($this->HasAccess('read', $incPageName))
{
$this->RegisterInclusion($incPageName);
$output = $this->Format($incPage['body']);
if (isset($classes))
{
if($this->GetParameter('edit')=='show')
$editLink = "<div class=\"include_editlink\"><a href=\"" . $this->Href("edit", $incPageName) . "\">["._t('EDITION')."]</a></div>\n";
else $editLink = "";
// Affichage
echo "<div class=\"include " . $classes . "\">\n" . $editLink . $output . "</div>\n";
}
else echo $output;
$this->UnregisterLastInclusion();
}
?>