Suppression du lien "web polytechniciens", faisant double emploi avec "groupes X"
[platal.git] / plugins / pmwiki.platalAuth.php
CommitLineData
121cdae0 1<?php
2
6f8f3f52 3$AuthFunction = 'AuthPlatal';
121cdae0 4
6f8f3f52 5$Conditions['logged'] = logged();
6$Conditions['identified'] = identified();
7$Conditions['has_perms'] = has_perms();
8$Conditions['public'] = 'true';
9$Conditions['only_public'] = !identified();
10
11function authPerms($pagename, $key, $could=false)
121cdae0 12{
fd5c9770 13 $words = explode(' ', $key);
14 $auth = false;
15 $and = false;
16 foreach ($words as $word) {
17 $iauth = false;
18 if ($word == 'and:') {
19 $and = true;
20 continue;
21 }
22 $parts = explode(':', $word);
23 $cond = $parts[0];
24 $param = $parts[1];
6f8f3f52 25 if ($cond == 'identified' && $could) {
26 $cond = 'logged';
fd5c9770 27 }
6f8f3f52 28 $iauth = CondText($pagename, 'if '.$cond.' '.$param, true);
fd5c9770 29 if ($and) {
30 $auth &= $iauth;
31 } else {
32 $auth |= $iauth;
33 }
34 $and = false;
35 }
36 return $auth;
121cdae0 37}
38
d0adba41 39function TryAllAuths($pagename, $level, $page_read, $group_read)
121cdae0 40{
fd5c9770 41 global $DefaultPasswords;
42 if (isset($page_read['passwd'.$level]) && $page_read['passwd'.$level] != '*') {
43 return array('page', $page_read['passwd'.$level]);
44 }
45 if (isset($group_read['passwd'.$level]) && $group_read['passwd'.$level] != '*') {
46 return array('group', $group_read['passwd'.$level]);
47 }
48 if (isset($DefaultPasswords[$level])) {
49 return array('site', $DefaultPasswords[$level]);
50 }
51 return array('none', '');
121cdae0 52}
53
54function AuthPlatal($pagename, $level, $authprompt, $since)
55{
fd5c9770 56 global $Conditions;
57 $authUser = false;
58 $authPage = false;
121cdae0 59
fd5c9770 60 $page_read = ReadPage($pagename, $since);
61 $groupattr = FmtPageName('$Group/GroupAttributes', $pagename);
62 $group_read = ReadPage($groupattr, $since);
121cdae0 63
fd5c9770 64 $levels = array('read', 'attr', 'edit', 'upload');
d0adba41 65
fd5c9770 66 foreach ($levels as $l)
67 {
68 list($from, $pass) = TryAllAuths($pagename, $l, $page_read, $group_read);
69 $passwds[$l] = $pass;
70 $pwsources[$l] = $from;
71 }
121cdae0 72
fd5c9770 73 if (!isset($Conditions['canedit'])) {
74 $Conditions['canedit'] = authPerms($pagename, $passwds['edit'], true);
75 }
76 if (!isset($Conditions['canattr'])) {
77 $Conditions['canattr'] = authPerms($pagename, $passwds['attr'], true);
78 }
121cdae0 79
fd5c9770 80 if (authPerms($pagename, $passwds[$level]))
81 {
82 $page_read['=passwd'] = $passwds;
83 $page_read['=pwsource'] = $pwsources;
84 return $page_read;
85 }
86
87 if ($authprompt && !identified())
88 {
89 new_skinned_page('wiki.tpl', AUTH_MDP);
90 }
91
92 global $page;
93 new_skinned_page('', AUTH_MDP);
94 if (has_perms()) {
6f8f3f52 95 $page->trig('Erreur : page Wiki inutilisable sur plat/al');
fd5c9770 96 } else {
97 $page->trig("Tu n'as pas le droit d'accéder à ce service");
98 }
99 // don't return false or pmwiki will send an exit breaking smarty page
100 return 1;
121cdae0 101}
102
fd5c9770 103?>