Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezforum.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezforum.php 9733 2002-10-02 14:50:11Z bf $
5 //
6 // Created on: <11-Sep-2000 22:10:06 bf>
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
29
37 // include_once( "classes/ezdb.php" );
38 // include_once( "classes/ezquery.php" );
39 // include_once( "ezforum/classes/ezforummessage.php" );
40
41 // include_once( "ezuser/classes/ezusergroup.php" );
42
43 class eZForum
44 {
48 function __construct( $id = "" )
49 {
50 $this->IsModerated = 0;
51 $this->IsAnonymous = 0;
52 $this->IsPrivate = 0;
53 $this->ModeratorID = 0;
54 $this->GroupID = 0;
55
56 if ( $id != "" )
57 {
58 $this->ID = $id;
59 $this->get( $this->ID );
60 }
61 }
62
66 function store()
67 {
68 $db =& eZDB::globalDatabase();
69 $db->begin();
70
71 $name = $db->escapeString( $this->Name );
72 $description = $db->escapeString( $this->Description );
73
74 if ( !isset( $this->ID ) )
75 {
76 $db->lock( "eZForum_Forum" );
77 $nextID = $db->nextID( "eZForum_Forum", "ID" );
78
79 $res = $db->query( "INSERT INTO eZForum_Forum
80 ( ID,
81 Name,
82 Description,
83 IsModerated,
84 IsAnonymous,
85 ModeratorID,
86 GroupID,
87 IsPrivate )
88 VALUES
89 ( '$nextID',
90 '$name',
91 '$description',
92 '$this->IsModerated',
93 '$this->IsAnonymous',
94 '$this->ModeratorID',
95 '$this->GroupID',
96 '$this->IsPrivate' )" );
97
98 $this->ID = $nextID;
99 }
100 else
101 {
102 $res = $db->query( "UPDATE eZForum_Forum SET
103 Name='$name',
104 Description='$description',
105 IsModerated='$this->IsModerated',
106 IsAnonymous='$this->IsAnonymous',
107 ModeratorID='$this->ModeratorID',
108 GroupID='$this->GroupID',
109 IsPrivate='$this->IsPrivate'
110 WHERE ID='$this->ID'" );
111 }
112
113 $db->unlock();
114
115 if ( $res == false )
116 $db->rollback( );
117 else
118 $db->commit();
119
120 return true;
121 }
122
126 function delete()
127 {
128 $db =& eZDB::globalDatabase();
129
130 // delete messages
131 $db->query( "DELETE FROM eZForum_Message WHERE ForumID='$this->ID'" );
132
133 // delete category assignments
134 $db->query( "DELETE FROM eZForum_ForumCategoryLink WHERE ForumID='$this->ID'" );
135
136 // delete the forum
137 $db->query( "DELETE FROM eZForum_Forum WHERE ID='$this->ID'" );
138
139 return true;
140 }
141
145 function removeFromForums()
146 {
147 $db =& eZDB::globalDatabase();
148
149 // delete category assignments
150 $db->query( "DELETE FROM eZForum_ForumCategoryLink WHERE ForumID='$this->ID'" );
151 }
152
156 function get( $id = "" )
157 {
158 $db =& eZDB::globalDatabase();
159 $ret = false;
160 $category_array = array();
161
162 if ( $id != "" )
163 {
164 $db->array_query( $forum_array, "SELECT * FROM eZForum_Forum WHERE ID='$id'" );
165 if ( count( $forum_array ) > 1 )
166 {
167 die( "Error: Forum's with the same ID was found in the database. This shouldent happen." );
168 }
169 else if ( count( $forum_array ) == 1 )
170 {
171 $this->ID =& $forum_array[0][$db->fieldName( "ID" )];
172 $this->Name =& $forum_array[0][$db->fieldName( "Name" )];
173 $this->Description =& $forum_array[0][$db->fieldName( "Description" )];
174 $this->IsModerated =& $forum_array[0][$db->fieldName( "IsModerated" )];
175 $this->IsAnonymous =& $forum_array[0][$db->fieldName( "IsAnonymous" )];
176 $this->ModeratorID =& $forum_array[0][$db->fieldName( "ModeratorID" )];
177 $this->GroupID =& $forum_array[0][$db->fieldName( "GroupID" )];
178 $this->IsPrivate =& $forum_array[0][$db->fieldName( "IsPrivate" )];
179
180 $ret = true;
181 }
182 else if ( count( $category_array ) == 0 )
183 {
184 $this->ID = 0;
185 }
186 }
187 return $ret;
188 }
189
190
194 function getAll()
195 {
196
197 }
198
202 function &messages()
203 {
204 $db =& eZDB::globalDatabase();
205
206 $db->array_query( $message_array, "SELECT ID, PostingTime FROM
207 eZForum_Message
208 WHERE ForumID='$this->ID' AND IsTemporary='0'
209 ORDER BY PostingTime DESC" );
210
211 $ret = array();
212
213 foreach ( $message_array as $message )
214 {
215 $ret[] = new eZForumMessage( $message[$db->fieldName( "ID" )] );
216 }
217
218 return $ret;
219 }
220
224 function &search( $queryText, $offset, $limit, &$SearchTotalCount, $params = array() )
225 {
226 $db =& eZDB::globalDatabase();
227 $return_array = array();
228 $queryText = $db->escapeString( $queryText );
229
230 $query = new eZQuery( "eZForum_Word.Word", $queryText );
231 $query->setIsLiteral( true );
232 $query->setStopWordColumn( "eZForum_Word.Frequency" );
233 $searchSQL = $query->buildQuery();
234
235 $groupString = "eZForum_Forum.GroupID=0";
236
237 $user =& eZUser::currentUser();
238 if ( $user )
239 {
240 $groups =& $user->groups( false );
241 $i = 0;
242
243 foreach ( $groups as $userGroup )
244 {
245 $groupString .= " OR ";
246
247 $groupString .= "eZForum_Forum.GroupID='" . $userGroup . "'";
248 $i++;
249 }
250 }
251
252 // special search for MySQL, mimic subselects ;)
253 if ( $db->isA() == "mysql" )
254 {
255 $queryArray = explode( " ", trim( $queryText ) );
256
257 $db->query( "CREATE TEMPORARY TABLE eZForum_SearchTemp( MessageID int )" );
258
259 $count = 1;
260 foreach ( $queryArray as $queryWord )
261 {
262 $queryWord = trim( $queryWord );
263
264 $searchSQL = " ( eZForum_Word.Word = '$queryWord' AND eZForum_Word.Frequency < '0.9' ) ";
265
266 $queryString = "INSERT INTO eZForum_SearchTemp ( MessageID )
267 SELECT DISTINCT eZForum_Message.ID AS MessageID
268 FROM eZForum_Message,
269 eZForum_MessageWordLink,
270 eZForum_Word,
271 eZForum_Forum
272 WHERE $searchSQL AND
273 ( eZForum_Message.ID=eZForum_MessageWordLink.MessageID
274 AND eZForum_MessageWordLink.WordID=eZForum_Word.ID ) AND
275 eZForum_Message.ForumID=eZForum_Forum.ID AND
276 ($groupString)
277 ORDER BY eZForum_MessageWordLink.Frequency";
278
279 $db->query( $queryString );
280 // check if this is a stop word
281 $queryString = "SELECT Frequency FROM eZForum_Word WHERE Word='$queryWord'";
282
283 $db->query_single( $WordFreq, $queryString, array( "LIMIT" => 1 ) );
284
285 if ( isset( $WordFreq["Frequency"] ) && $WordFreq["Frequency"] <= 0.7 )
286 $count += 1;
287 }
288 $count -= 1;
289
290 $queryString = "SELECT MessageID, Count(*) AS Count FROM eZForum_SearchTemp GROUP BY MessageID HAVING Count='$count'";
291
292 $db->array_query( $message_array, $queryString );
293 $SearchTotalCount = count( $message_array );
294 $message_array =& array_slice( $message_array, $offset, $limit );
295
296 $db->query( "DROP TABLE eZForum_SearchTemp" );
297 }
298 else
299 {
300 $queryString = "SELECT DISTINCT eZForum_Message.ID AS MessageID
301 FROM eZForum_Message,
302 eZForum_MessageWordLink,
303 eZForum_Word,
304 eZForum_Forum
305 WHERE
306 $searchSQL
307 AND
308 ( eZForum_Message.ID=eZForum_MessageWordLink.MessageID
309 AND eZForum_MessageWordLink.WordID=eZForum_Word.ID )
310 eZForum_Message.ForumID=eZForum_Forum.ID AND
311 ($groupString)
312 ORDER BY eZForum_MessageWordLink.Frequency";
313
314 $db->array_query( $message_array, $queryString );
315 $SearchTotalCount = count( $message_array );
316 $message_array =& array_slice( $message_array, $offset, $limit );
317 }
318
319 for ( $i = 0; $i < count( $message_array ); $i++ )
320 {
321 $return_array[$i] = new eZForumMessage( $message_array[$i][$db->fieldName( "MessageID" )], false );
322 }
323
324 return $return_array;
325 }
326
327
331 function &getQueryCount( $queryString )
332 {
333 $db =& eZDB::globalDatabase();
334 $queryString = $db->escapeString( $queryString );
335 $message_array = 0;
336
337 $query = new eZQuery( array( "Topic", "Body" ), $queryString );
338 $query->setPartialCompare( true );
339
340 $query_str = "SELECT count(*) AS Count FROM eZForum_Message WHERE (" . $query->buildQuery() . ")";
341
342 $db->array_query( $message_array, $query_str );
343
344 $ret = 0;
345 if ( count( $message_array ) == 1 )
346 $ret = $message_array[0][$db->fieldName( "Count" )];
347 settype( $ret, "integer" );
348 return $ret;
349 }
350
351
357 function &messageTree( $offset = 0, $limit = 30, $showUnApproved = false )
358 {
359 $db =& eZDB::globalDatabase();
360
361 $approvedCode = "";
362 if ( $showUnApproved == false )
363 {
364 $approvedCode = " AND IsApproved=1 ";
365 }
366
367 $db->array_query( $message_array, "SELECT ID, TreeID FROM
368 eZForum_Message
369 WHERE ForumID='$this->ID' $approvedCode
370 AND IsTemporary='0' ORDER BY TreeID
371 DESC",
372 array( "Limit" => $limit, "Offset" => $offset ) );
373
374 $ret = array();
375
376 foreach ( $message_array as $message )
377 {
378 $ret[] = new eZForumMessage( $message[$db->fieldName( "ID" )] );
379 }
380
381 return $ret;
382 }
383
389 function messageTreeArray( $offset = 0, $limit = 30, $showUnApproved = false, $showReplies = true )
390 {
391 $db =& eZDB::globalDatabase();
392
393 $approvedCode = "";
394 if ( $showUnApproved == false )
395 {
396 $approvedCode = " AND IsApproved=1 ";
397 }
398
399 $timeStamp =& (new eZDateTime())->timeStamp( true );
400 if ( $showReplies )
401 {
402 $db->array_query( $message_array, "SELECT ID, Topic, UserID, PostingTime, Depth, UserName,
403 ( $timeStamp - PostingTime ) AS Age, TreeID, Body
404 FROM
405 eZForum_Message
406 WHERE ForumID='$this->ID'
407 AND IsTemporary='0'
408 $approvedCode
409 ORDER BY TreeID
410 DESC",
411 array( "Limit" => $limit, "Offset" => $offset ) );
412 }
413 else
414 {
415 $db->array_query( $message_array, "SELECT ID, Topic, UserID, PostingTime, Depth, UserName,
416 ( $timeStamp - PostingTime ) AS Age, TreeID, ThreadID, Body
417 FROM eZForum_Message
418 WHERE ForumID='$this->ID' AND Depth='0'
419 AND IsTemporary='0'
420 $approvedCode
421 ORDER BY TreeID DESC ",
422 array( "Limit" => $limit, "Offset" => $offset ) );
423 }
424 return $message_array;
425 }
426
432 function messageThreadTree( $threadID, $showUnApprived = false, $offset = 0, $limit = 100 )
433 {
434 $db =& eZDB::globalDatabase();
435
436 if ( !isset( $showUnApproved ) || !$showUnApproved )
437 $showUnApproved = " AND IsApproved='1' ";
438 else
439 $showUnApproved = " AND IsApproved='0' ";
440
441 $db->array_query( $message_array, "SELECT ID, TreeID FROM eZForum_Message
442 WHERE ForumID='$this->ID'
443 AND ThreadID='$threadID'
444 AND IsTemporary='0'
445 $showUnApproved
446 ORDER BY TreeID DESC",
447 array( "Limit" => $limit, "Offset" => $offset ) );
448
449 $ret = array();
450
451 foreach ( $message_array as $message )
452 {
453 $ret[] = new eZForumMessage( $message[$db->fieldName("ID")] );
454 }
455
456 return $ret;
457 }
458
459
463 function id()
464 {
465 return $this->ID;
466 }
467
471 function categories( $as_object = true )
472 {
473 $db =& eZDB::globalDatabase();
474
475 $db->array_query( $forum_array, "SELECT CategoryID FROM
476 eZForum_ForumCategoryLink
477 WHERE ForumID='$this->ID'" );
478
479 $ret = array();
480
481 foreach ( $forum_array as $forum )
482 {
483 if ( $as_object )
484 $ret[] = new eZForumCategory( $forum[$db->fieldName( "CategoryID" )] );
485 else
486 $ret[] = $forum[$db->fieldName( "CategoryID" )];
487 }
488
489 return $ret;
490 }
491
492
496 function &name( $html = true )
497 {
498 if( !is_null( $this->Name ) )
499 {
500 if ( $html )
501 {
502 return htmlspecialchars( stripslashes( $this->Name ) );
503 }
504 else
505 {
506 return stripslashes( $this->Name );
507 }
508 }
509 else
510 {
511 return null;
512 }
513 }
514
518 function setName( $newName )
519 {
520 $this->Name = $newName;
521 }
522
526 function &description()
527 {
528 $description = stripslashes( $this->Description );
529 return htmlspecialchars( $description );
530 }
531
535 function setDescription( $newDescription )
536 {
537 $this->Description = $newDescription;
538 }
539
543 function isModerated()
544 {
545 $ret = false;
546 if ( $this->IsModerated == 1 )
547 $ret = true;
548
549 return $ret;
550 }
551
555 function isAnonymous()
556 {
557 $ret = false;
558 if ( $this->IsAnonymous == 1 )
559 $ret = true;
560
561 return $ret;
562 }
563
567 function &moderator()
568 {
569 $group = false;
570
571 if ( $this->ModeratorID > 0 )
572 {
573 $group = new eZUserGroup( $this->ModeratorID );
574 }
575
576 return $group;
577 }
578
579
583 function &group()
584 {
585 $group = false;
586
587 if ( $this->GroupID > 0 )
588 {
589 $group = new eZUserGroup( $this->GroupID );
590 }
591
592 return $group;
593 }
594
598 function setIsModerated( $value )
599 {
600 if ( $value )
601 {
602 $this->IsModerated = 1;
603 }
604 else
605 {
606 $this->IsModerated = 0;
607 }
608 }
609
613 function setIsAnonymous( $value )
614 {
615 if ( $value )
616 $this->IsAnonymous = 1;
617 else
618 $this->IsAnonymous = 0;
619 }
620
624 function setModerator( $group )
625 {
626 if ( is_a( $group, "eZUserGroup" ) )
627 {
628 $this->ModeratorID = $group->id();
629 }
630 else if ( is_numeric( $group ) )
631 {
632 $this->ModeratorID = $group;
633 }
634 }
635
639 function setGroup( $group )
640 {
641 if ( is_a( $group, "eZUserGroup" ) )
642 {
643 $this->GroupID = $group->id();
644 }
645 else if ( is_numeric( $group ) )
646 {
647 $this->GroupID = $group;
648 }
649 }
650
651
655 function isPrivate()
656 {
657 return $this->IsPrivate;
658 }
659
663 function setPrivate( $newPrivate )
664 {
665 $this->IsPrivate = $newPrivate;
666 }
667
671 function threadCount( $countUnapproved = false )
672 {
673 $db =& eZDB::globalDatabase();
674
675 $unapprovedSQL = "";
676 if ( $countUnapproved == false )
677 $unapprovedSQL = "AND IsApproved='1'";
678
679 $db->array_query( $message_array, "SELECT Count(ID) AS Count FROM eZForum_Message
680 WHERE ForumID='$this->ID' AND Depth='0'
681 AND IsTemporary='0' $unapprovedSQL " );
682
683 $ret = $message_array[0][$db->fieldName( "Count" )];
684
685 setType( $ret, "integer" );
686
687 return $ret;
688 }
689
693 function messageCount( $countUnapproved = false, $showReplies = false )
694 {
695 $db =& eZDB::globalDatabase();
696
697 if ( $countUnapproved == false )
698 $unapprovedSQL = "AND IsApproved='1'";
699 else
700 $unapprovedSQL = "";
701
702 if ( $showReplies )
703 {
704 $db->array_query( $message_array, "SELECT ID FROM eZForum_Message
705 WHERE ForumID='$this->ID'
706 AND IsTemporary='0'
707 $unapprovedSQL
708 " );
709 }
710 else
711 {
712 $db->array_query( $message_array, "SELECT ID FROM eZForum_Message
713 WHERE ForumID='$this->ID' AND Depth='0'
714 AND IsTemporary='0' $unapprovedSQL" );
715 }
716
717 $ret = count( $message_array );
718
719 return $ret;
720 }
721
722
723 var $ID;
724 var $Name;
725 var $Description;
726 var $IsModerated;
727 var $IsAnonymous;
728 var $IsPrivate;
729 var $ModeratorID;
730 var $GroupID;
731 }
732
733 ?>
$i
$i
Definition: admin/adlist.php:91
$group
$group
Definition: admin/articleedit.php:799
$forum
$forum
Definition: admin/forumlist.php:50
$message
$message
Definition: admin/message.php:51
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZForumCategory
Definition: ezforumcategory.php:44
eZForumMessage
Definition: ezforummessage.php:42
eZForum
Definition: ezforum.php:44
eZForum\getAll
getAll()
Definition: ezforum.php:194
eZForum\setName
setName( $newName)
Definition: ezforum.php:518
eZForum\$ID
$ID
Definition: ezforum.php:723
eZForum\$IsAnonymous
$IsAnonymous
Definition: ezforum.php:727
eZForum\id
id()
Definition: ezforum.php:463
eZForum\isPrivate
isPrivate()
Definition: ezforum.php:655
eZForum\setIsModerated
setIsModerated( $value)
Definition: ezforum.php:598
eZForum\setDescription
setDescription( $newDescription)
Definition: ezforum.php:535
eZForum\$Description
$Description
Definition: ezforum.php:725
eZForum\messageTreeArray
messageTreeArray( $offset=0, $limit=30, $showUnApproved=false, $showReplies=true)
Definition: ezforum.php:389
eZForum\setPrivate
setPrivate( $newPrivate)
Definition: ezforum.php:663
eZForum\isAnonymous
isAnonymous()
Definition: ezforum.php:555
eZForum\setIsAnonymous
setIsAnonymous( $value)
Definition: ezforum.php:613
eZForum\setGroup
setGroup( $group)
Definition: ezforum.php:639
eZForum\getQueryCount
& getQueryCount( $queryString)
Definition: ezforum.php:331
eZForum\removeFromForums
removeFromForums()
Definition: ezforum.php:145
eZForum\setModerator
setModerator( $group)
Definition: ezforum.php:624
eZForum\messages
& messages()
Definition: ezforum.php:202
eZForum\categories
categories( $as_object=true)
Definition: ezforum.php:471
eZForum\$IsPrivate
$IsPrivate
Definition: ezforum.php:728
eZForum\search
& search( $queryText, $offset, $limit, &$SearchTotalCount, $params=array())
Definition: ezforum.php:224
eZForum\$ModeratorID
$ModeratorID
Definition: ezforum.php:729
eZForum\isModerated
isModerated()
Definition: ezforum.php:543
eZForum\messageCount
messageCount( $countUnapproved=false, $showReplies=false)
Definition: ezforum.php:693
eZForum\threadCount
threadCount( $countUnapproved=false)
Definition: ezforum.php:671
eZForum\messageThreadTree
messageThreadTree( $threadID, $showUnApprived=false, $offset=0, $limit=100)
Definition: ezforum.php:432
eZForum\messageTree
& messageTree( $offset=0, $limit=30, $showUnApproved=false)
Definition: ezforum.php:357
eZForum\store
store()
Definition: ezforum.php:66
eZForum\description
& description()
Definition: ezforum.php:526
eZForum\$Name
$Name
Definition: ezforum.php:724
eZForum\$IsModerated
$IsModerated
Definition: ezforum.php:726
eZForum\__construct
__construct( $id="")
Definition: ezforum.php:48
eZForum\$GroupID
$GroupID
Definition: ezforum.php:730
eZForum\moderator
& moderator()
Definition: ezforum.php:567
eZForum\group
& group()
Definition: ezforum.php:583
eZForum\name
& name( $html=true)
Definition: ezforum.php:496
eZQuery
Definition: ezquery.php:54
eZUserGroup
Definition: ezusergroup.php:66
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$db
$db
Definition: ezarticle/user/authorlist.php:53
$groups
if( $CategoryID !=0) $groups
Definition: ezbulkmail/admin/categoryedit.php:108
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$count
$count
Definition: onlinetypelist.php:108
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$category_array
$category_array
Definition: todoedit.php:604
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.