Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmessage.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezmessage.php,v 1.6 2001/08/27 10:22:53 br Exp $
5 //
6 // Definition of eZMessage class
7 //
8 // Created on: <05-Jun-2001 13:46:48 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
35 // include_once( "classes/ezdb.php" );
36
37
38 class eZMessage
39 {
43 function __construct( $id=-1 )
44 {
45 $this->IsRead = 0;
46
47 if ( $id != -1 )
48 {
49 $this->ID = $id;
50 $this->get( $this->ID );
51 }
52 }
53
57 function store()
58 {
59 $db =& eZDB::globalDatabase();
60 $db->begin();
61
62 $subject = $db->escapeString( $this->Subject );
63 $description = $db->escapeString( $this->Description );
64 $timeStamp = (new eZDateTime())->timeStamp( true );
65
66 if ( !isset( $this->ID ) )
67 {
68 $db->lock( "eZMessage_Message" );
69 $nextID = $db->nextID( "eZMessage_Message", "ID" );
70 $res[] = $db->query( "INSERT INTO eZMessage_Message
71 ( ID,
72 Subject,
73 Created,
74 Description,
75 FromUserID,
76 ToUserID,
77 IsRead,
78 TimeRead )
79 VALUES
80 ( '$nextID',
81 '$subject',
82 '$timeStamp',
83 '$description',
84 '$this->FromUserID',
85 '$this->ToUserID',
86 '$this->IsRead',
87 '0' )" );
88 $this->ID = $nextID;
89 }
90 else
91 {
92 $res[] = $db->query( "UPDATE eZMessage_Message SET
93 Subject='$subject',
94 Created=Created,
95 Description='$description',
96 FromUserID='$this->FromUserID',
97 ToUserID='$this->ToUserID',
98 IsRead='$this->IsRead',
99 TimeRead='$timeStamp'
100 WHERE ID='$this->ID'" );
101 }
102
103 eZDB::finish( $res, $db );
104 return true;
105 }
106
110 function delete()
111 {
112 $db =& eZDB::globalDatabase();
113 $db->begin();
114
115 if ( isset( $this->ID ) )
116 {
117 $res[] = $db->query( "DELETE FROM eZMessage_Message WHERE ID='$this->ID'" );
118 }
119
120 eZDB::finish( $res, $db );
121 return true;
122 }
123
129 function get( $id=-1 )
130 {
131 $db =& eZDB::globalDatabase();
132
133 $ret = false;
134 if ( $id != "" )
135 {
136 $db->array_query( $author_array, "SELECT * FROM eZMessage_Message WHERE ID='$id'" );
137 if( count( $author_array ) == 1 )
138 {
139 $this->ID =& $author_array[0][$db->fieldName( "ID" )];
140 $this->Subject =& $author_array[0][$db->fieldName( "Subject" )];
141 $this->Description =& $author_array[0][$db->fieldName( "Description" )];
142 $this->Created =& $author_array[0][$db->fieldName( "Created" )];
143 $this->FromUserID =& $author_array[0][$db->fieldName( "FromUserID" )];
144 $this->ToUserID =& $author_array[0][$db->fieldName( "ToUserID" )];
145 $this->IsRead =& $author_array[0][$db->fieldName( "IsRead" )];
146 $this->TimeRead =& $author_array[0][$db->fieldName( "TimeRead" )];
147 $ret = true;
148 }
149 elseif( count( $author_array ) == 1 )
150 {
151 $this->ID = 0;
152 }
153 }
154 return $ret;
155 }
156
157
161 function &getAll( )
162 {
163 $db =& eZDB::globalDatabase();
164
165 $return_array = array();
166 $message_array = array();
167
168
169 $db->array_query( $message_array, "SELECT ID FROM eZMessage_Message
170 ORDER By Created" );
171
172 foreach ( $message_array as $message )
173 {
174 $return_array[] = new eZMessage( $message[0] );
175 }
176 return $return_array;
177 }
178
182 function &messagesToUser( $user )
183 {
184 $userID = $user->id();
185 $db =& eZDB::globalDatabase();
186
187 $return_array = array();
188 $message_array = array();
189
190 $query = "SELECT DISTINCT eZMessage_Message.ID, eZMessage_MessageDefinition.ToUserID, eZMessage_MessageDefinition.FromUserID
191 FROM eZMessage_Message
192 LEFT JOIN eZMessage_MessageDefinition ON
193 ( eZMessage_MessageDefinition.MessageID = eZMessage_Message.ID )
194 WHERE eZMessage_Message.ToUserID = '$userID' AND eZMessage_MessageDefinition.ToUserID = '$userID'
195 ORDER By eZMessage_Message.Created DESC";
196
197 $db->array_query( $message_array, $query );
198
199 foreach ( $message_array as $message )
200 {
201 $return_array[] = new eZMessage( $message[0] );
202 }
203 return $return_array;
204 }
205
209 function &messagesFromUser( $user )
210 {
211 $userID = $user->id();
212 $db =& eZDB::globalDatabase();
213
214 $return_array = array();
215 $message_array = array();
216
217 $query = "SELECT DISTINCT eZMessage_Message.ID, eZMessage_MessageDefinition.ToUserID, eZMessage_MessageDefinition.FromUserID
218 FROM eZMessage_Message
219 LEFT JOIN eZMessage_MessageDefinition ON
220 ( eZMessage_MessageDefinition.MessageID = eZMessage_Message.ID )
221 WHERE eZMessage_Message.FromUserID = '$userID' AND eZMessage_MessageDefinition.FromUserID = '$userID'
222 ORDER BY eZMessage_Message.Created DESC";
223 $db->array_query( $message_array, $query );
224
225 foreach ( $message_array as $message )
226 {
227 $return_array[] = new eZMessage( $message[0] );
228 }
229 return $return_array;
230 }
231
232 function string_tagster($str) {
233 if( is_null($str) )
234 $str = false;
235
236 $str = " ".$str." ";
237 $str = preg_replace("/([[:space:]{()\"'\[~#=;\&?\_])((ftp|http|https|telnet|news|nttp|nntp|file):\/\/[a-z0-9~#%@\&\‍(\‍):;=\?\/\.,_-]+(\\[|\\]|[a-z0-9~#%@\*\&:;.,=\?!'\|\/_\+-])+)/", "\\1<A HREF=\"\\2\" TARGET=\"_blank\">\\2</A>", $str);
238 $str = preg_replace("/([[:space:]{()\"'\[~#;\&?\_])(www\.[a-z0-9~#%@\&\‍(\‍):;=\?!'\/\.,_-]+(\\[|\\]|[a-z0-9~#%@\*\&:;.,=\?!'\|\/_\+-])+)/", "\\1<A HREF=\"http://\\2\" TARGET=\"_blank\">\\2</A>", $str);
239 $str = preg_replace("/([[:space:]{()\"'\[~#=;\&?\_])(ftp\.[a-z0-9~#%@\&\‍(\‍):;=\?!'\/\.,_-]+(\\[|\\]|[a-z0-9~#%@\&:;.,=\?!'\|\/_\+-])+)/", "\\1<A HREF=\"ftp://\\2\" TARGET=\"_blank\">\\2</A>", $str);
240 $str = preg_replace("/(mail:|[[:space:]{()\"'\[~#;\&?])([_\.0-9a-z-]+@([_\.0-9a-z-]+)+\.[a-z]{2,4})/","\\1<A HREF=\"mailto:\\2\">\\2</A>", $str);
241 $str = preg_replace("/ /", "&nbsp;&nbsp; ", $str);
242 $str = str_replace("\\n", "<BR>", $str);
243 return substr($str, 1);
244 }
245
246 function format_post2 ($str) {
247 if( is_null($str) )
248 $str = "";
249
250 $str = htmlentities($str);
251 $str = str_replace("&quot;", "\"", $str);
252 $str = $this->string_tagster($str);
253 $str = preg_replace("/'<\/A>/", "</A>'", $str);
254 $str = preg_replace("/'\" TARGET=\"_blank\">/", "\" TARGET=\"_blank\">'", $str);
255 $str = preg_replace("/ /", " &nbsp; ", $str);
256 $str = str_replace("\\t", "&nbsp;&nbsp;&nbsp; ", $str);
257 $str = str_replace("\\r", "", $str);
258 $str = str_replace("\\n", "<BR>", $str);
259
260 # Return the result
261 return $str;
262 }
263
264 function render( $str ) {
265 if ( !is_null($str) && strlen($str) == 0)
266 return "";
267 $str = $this->format_post2($str);
268 $charPattern = chr(13);
269 $str = preg_replace( "/$charPattern/", "<br>", $str);
270 $str = stripslashes($str);
271 return "".$str;
272 }
276 function id()
277 {
278 return $this->ID;
279 }
280
284 function subject( $html = true )
285 {
286 if ( $html )
287 return htmlspecialchars( $this->Subject );
288 return $this->Subject;
289 }
290
294 function setFromUser( $user )
295 {
296 if ( get_class( $user ) == "eZUser" )
297 {
298 $this->FromUserID = $user->id();
299 }
300 }
301
305 function fromUser()
306 {
307 return new eZUser( $this->FromUserID );
308 }
309
310
314 function &toUser()
315 {
316 $ret = new eZUser( $this->ToUserID );
317 return $ret;
318 }
319
323 function isRead()
324 {
325 if ( $this->IsRead == 1 )
326 return true;
327 else
328 return false;
329 }
330
335 function setIsRead( $isRead )
336 {
337 if ( $isRead == true )
338 $this->IsRead = 1;
339 else
340 $this->IsRead = 0;
341 }
342
343
347 function setToUser( $user )
348 {
349 if ( get_class( $user ) == "eZUser" )
350 {
351 $this->ToUserID = $user->id();
352 }
353 }
354
358 function &created()
359 {
360 $dateTime = new eZDateTime();
361 $dateTime->setTimeStamp( $this->Created );
362
363 return $dateTime;
364 }
365
369 function &TimeRead()
370 {
371 $dateTime = new eZDateTime();
372 $dateTime->setTimeStamp( $this->TimeRead );
373
374 return $dateTime;
375 }
376
380 function description( )
381 {
382 return $this->Description;
383 }
384
388 function setSubject( $value )
389 {
390 $this->Subject = $value;
391 }
392
396 function setDescription( $value )
397 {
398 $this->Description = $value;
399 }
400
401 var $ID;
402 var $FromUserID;
403 var $ToUserID;
404 var $Created;
405 var $Subject;
406 var $Description;
407 var $IsRead;
408 var $TimeRead;
409 }
410
411 ?>
$message
$message
Definition: admin/message.php:51
$userID
else $userID
Definition: appointmentedit.php:121
$dateTime
$dateTime
Definition: authorview.php:77
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZMessage
Definition: ezmessage.php:39
eZMessage\TimeRead
& TimeRead()
Definition: ezmessage.php:369
eZMessage\$TimeRead
$TimeRead
Definition: ezmessage.php:408
eZMessage\id
id()
Definition: ezmessage.php:276
eZMessage\__construct
__construct( $id=-1)
Definition: ezmessage.php:43
eZMessage\$IsRead
$IsRead
Definition: ezmessage.php:407
eZMessage\setToUser
setToUser( $user)
Definition: ezmessage.php:347
eZMessage\$ID
$ID
Definition: ezmessage.php:401
eZMessage\string_tagster
string_tagster($str)
Definition: ezmessage.php:232
eZMessage\setSubject
setSubject( $value)
Definition: ezmessage.php:388
eZMessage\getAll
& getAll()
Definition: ezmessage.php:161
eZMessage\isRead
isRead()
Definition: ezmessage.php:323
eZMessage\toUser
& toUser()
Definition: ezmessage.php:314
eZMessage\created
& created()
Definition: ezmessage.php:358
eZMessage\$ToUserID
$ToUserID
Definition: ezmessage.php:403
eZMessage\render
render( $str)
Definition: ezmessage.php:264
eZMessage\description
description()
Definition: ezmessage.php:380
eZMessage\format_post2
format_post2($str)
Definition: ezmessage.php:246
eZMessage\fromUser
fromUser()
Definition: ezmessage.php:305
eZMessage\messagesToUser
& messagesToUser( $user)
Definition: ezmessage.php:182
eZMessage\setFromUser
setFromUser( $user)
Definition: ezmessage.php:294
eZMessage\$Description
$Description
Definition: ezmessage.php:406
eZMessage\$Created
$Created
Definition: ezmessage.php:404
eZMessage\$FromUserID
$FromUserID
Definition: ezmessage.php:402
eZMessage\store
store()
Definition: ezmessage.php:57
eZMessage\messagesFromUser
& messagesFromUser( $user)
Definition: ezmessage.php:209
eZMessage\subject
subject( $html=true)
Definition: ezmessage.php:284
eZMessage\$Subject
$Subject
Definition: ezmessage.php:405
eZMessage\setIsRead
setIsRead( $isRead)
Definition: ezmessage.php:335
eZMessage\setDescription
setDescription( $value)
Definition: ezmessage.php:396
eZUser
Definition: ezuser.php:76
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$str
$str
Definition: ezarticle/modules/content.php:30
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.