Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

messagepermissions.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: messagepermissions.php 7782 2001-10-11 11:06:20Z jhe $
5 //
6 // Created on: <21-Feb-2001 18:00:00 pkej>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // "Return" values set to most secure experience, our job
28 // is then to apply these to the job at hand.
29
30 // Is it possible to read this message;
31 $MessageRead = false;
32
33 // If a message has replies it cannot be edited.
34 $MessageEdit = false;
35
36 // Only owners can delete a message; it also has to have no replies.
37 $MessageDelete = false;
38
39 // If a message is temporary, then no replies can be added.
40 $MessageReply = false;
41
42 // Is it possible to add a message to this forum?
43 $ForumPost = false;
44
45 // Is it possible to read this this forum?
46 $ForumRead = false;
47
48
49 // Which checks should be performed? All by default, this is just here for easy
50 // partitioning with if''s and for debugging purposes. Will also check if the
51 // pre-requisites are there for the test!
52
53 $CheckMessageRead = true;
54 $CheckMessageDelete = true;
55 $CheckMessageEdit = true;
56 $CheckMessageReply = true;
57 $CheckForumPost = true;
58 $CheckForumRead = true;
59
60 // Anonymous users "have" user id 0.
61 if ( isset( $user ) && is_object( $user ) )
62 {
63 $UserID = $user->id();
64 }
65 else
66 {
67 $UserID = 0;
68 }
69
70 // If a forum id isn''t provided for checking, we can''t check
71 // the forum permissions.
72 if ( isset( $CheckForumID ) && $CheckForumID > 0 )
73 {
74 $checkForum = new eZForum( $CheckForumID );
75 }
76 else
77 {
78 $CheckForumPost = false;
79 $CheckForumRead = false;
80 // No point in checking for reading of message if you can''t access the forum
81 $CheckMessageID = false;
82 }
83
84 // If a message id isn''t provided for checking, we can''t check
85 // the message permissions.
86 if ( isset( $CheckMessageID ) && $CheckMessageID > 0 )
87 {
88 $checkMessage = new eZForumMessage( $CheckMessageID );
89 // Check if the current user is the message owner.
90
91 if ( $checkMessage->userID() == $UserID )
92 {
93 $MessageRead = true;
94 $MessageOwner = true;
95 }
96 else
97 {
98 $MessageOwner = false;
99 }
100 }
101 else
102 {
103 $CheckMessageReply = false;
104 $CheckMessageRead = false;
105 $CheckMessageEdit = false;
106 $CheckMessageDelete = false;
107 }
108
109
110 // You can read all forums unless they''re set to only allow
111 // a certain group of people.
112 if ( $CheckForumRead )
113 {
114 $group = $checkForum->group();
115
116 if ( ( is_a( $group, "eZUserGroup" ) ) && ( $group->id() != 0 ) )
117 {
118 if ( is_a( $user, "eZUser" ) )
119 {
120 $groupList = $user->groups();
121
122 foreach ( $groupList as $userGroup )
123 {
124 if ( $userGroup->id() == $group->id() )
125 {
126 $ForumRead = true;
127 break;
128 }
129 }
130 }
131 }
132 else
133 {
134 $ForumRead = true;
135 }
136 }
137 else
138 {
139 $ForumRead = true;
140 }
141
142 // You can post to a forum you can read if you''re a logged in user.
143 // If the forum is set to anonymous anyone can post.
144 if ( $CheckForumPost && $ForumRead )
145 {
146 if ( isset( $checkForum ) && $checkForum->isAnonymous() == true )
147 {
148 $ForumPost = true;
149 }
150 else
151 {
152 if ( $ForumRead == true && $UserID != 0 )
153 {
154 $ForumPost = true;
155 }
156 }
157 }
158 else
159 {
160 $ForumPost = true;
161 }
162
163 // If you can read the forum, you can read the message if:
164 // * it is approved when in a moderated forum
165 // * it is your own when it is a temporary message
166 // * none of the above conditions are met
167 if ( $CheckMessageRead && $ForumRead )
168 {
169 if ( isset( $checkMessage ) && $checkMessage->isTemporary() == true )
170 {
171 if ( $MessageOwner == true )
172 {
173 $MessageRead = true;
174 }
175 }
176 else
177 {
178 if ( $checkForum->isModerated() == true )
179 {
180 if ( $checkMessage->isApproved() == true )
181 {
182 $MessageRead = true;
183 }
184 }
185 else
186 {
187 $MessageRead = true;
188 }
189 }
190 }
191
192 // If you can read a message, you own it, and it hasn''t any replies
193 // you can edit it.
194 if ( $CheckMessageEdit && $MessageRead )
195 {
196 if ( $MessageOwner == true )
197 {
198 if ( eZForumMessage::countReplies( $checkMessage->id() ) == 0 )
199 {
200 $MessageEdit = true;
201 }
202 }
203 }
204
205 // If you can read a message and post to the forum, you can reply to it,
206 // except temporary messages.
207 if ( $CheckMessageReply && $MessageRead && $ForumPost )
208 {
209 if ( $checkMessage->isTemporary() == false )
210 {
211 $MessageReply = true;
212 }
213 }
214
215 // If you own a message and can edit it, you can delete it.
216 if ( $CheckMessageDelete && $MessageEdit )
217 {
218 if ( $MessageOwner == true )
219 {
220 $MessageDelete = true;
221 }
222 }
223
224 if ( $debugMessagePermissions === true )
225 {
226 echo "<hr>\n";
227 // include_once( "classes/eztexttool.php" );
228 echo "UserID = " . $UserID . "<br />\n";
229 echo "MessageOwner = " . eZTextTool::boolText( $MessageOwner ) . "<br />\n";
230 echo "ForumRead = " . eZTextTool::boolText( $ForumRead ) . "<br />\n";
231 echo "ForumPost = " . eZTextTool::boolText( $ForumPost ) . "<br />\n";
232 echo "MessageRead = " . eZTextTool::boolText( $MessageRead ) . "<br />\n";
233 echo "MessageEdit = " . eZTextTool::boolText( $MessageEdit ) . "<br />\n";
234 echo "MessageReply = " . eZTextTool::boolText( $MessageReply ) . "<br />\n";
235 echo "MessageDelete = " . eZTextTool::boolText( $MessageDelete ) . "<br />\n";
236 }
237
238 ?>
$groupList
$groupList
Definition: admin/articleedit.php:800
$group
$group
Definition: admin/articleedit.php:799
eZForumMessage
Definition: ezforummessage.php:42
eZForumMessage\countReplies
static countReplies( $ID)
Definition: ezforummessage.php:799
eZForum
Definition: ezforum.php:44
eZTextTool\boolText
static boolText( $value)
Definition: eztexttool.php:135
$debugMessagePermissions
$debugMessagePermissions
Definition: ezforum/user/messageedit.php:45
$ForumPost
$ForumPost
Definition: messagepermissions.php:43
$MessageDelete
$MessageDelete
Definition: messagepermissions.php:37
$CheckMessageDelete
$CheckMessageDelete
Definition: messagepermissions.php:54
$ForumRead
$ForumRead
Definition: messagepermissions.php:46
$MessageEdit
$MessageEdit
Definition: messagepermissions.php:34
$CheckMessageID
$CheckMessageID
Definition: messagepermissions.php:81
$CheckForumPost
$CheckForumPost
Definition: messagepermissions.php:57
$CheckMessageEdit
$CheckMessageEdit
Definition: messagepermissions.php:55
$CheckForumRead
$CheckForumRead
Definition: messagepermissions.php:58
$CheckMessageRead
$CheckMessageRead
Definition: messagepermissions.php:53
$MessageReply
$MessageReply
Definition: messagepermissions.php:40
$CheckMessageReply
$CheckMessageReply
Definition: messagepermissions.php:56
$MessageRead
$MessageRead
Definition: messagepermissions.php:31
$UserID
$UserID
Definition: todoedit.php:122
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.