00001 <?PHP
00006 class discussForum extends lockableClass
00007 {
00008 var $sectionID;
00009 var $forumID;
00010 var $globalID;
00011
00012 var $title;
00013 var $description;
00014
00015 var $threads;
00016 var $threadsCount;
00017
00018 var $moderators;
00019 var $postLevel;
00020 var $viewLevel;
00021
00022 var $lastChanged;
00023 var $lastChangedBy;
00024 var $isChanged;
00025 var $parentSection;
00026 var $thisForumURL;
00027
00034 function discussForum($sectionID, $forumID)
00035 {
00036 global $discussContentDirectory;
00037 $this->sectionID = $sectionID;
00038 $this->forumID = $forumID;
00039 $this->lockfile = "$discussContentDirectory/{$this->sectionID}/forums/{$this->forumID}/lock";
00040
00041 if( $this->lock() )
00042 {
00043 $this->load();
00044 if( isAllowed("modules_discuss_admin") && $_POST["discussForumEdit"]["sectionID"] == $sectionID && $_POST["discussForumEdit"]["forumID"] == $forumID && $_POST["save_forum"] )
00045 {
00046 $this->title = stripslashes($_POST["discussForumEdit"]["title"]);
00047 $this->description = stripslashes($_POST["discussForumEdit"]["description"]);
00048 $this->postLevel = $_POST["discussForumEdit"]["postLevel"];
00049 $this->viewLevel = $_POST["discussForumEdit"]["viewLevel"];
00050 $this->save();
00051 }
00052 $this->unlock();
00053 }
00054
00055 $this->globalID = "discuss/$sectionID/$forumID";
00056 $this->thisForumURL = globalIDtoURL($this->globalID);
00057 }
00058
00062 function load()
00063 {
00064 global $discussContentDirectory;
00065
00066 if( file_exists( "$discussContentDirectory/{$this->sectionID}/forums/{$this->forumID}/options.php" ) )
00067 include( "$discussContentDirectory/{$this->sectionID}/forums/{$this->forumID}/options.php" );
00068
00069 $this->title = $forum_options["title"];
00070 $this->moderators = $forum_options["moderators"];
00071 $this->description = $forum_options["description"];
00072 $this->postLevel = $forum_options["postLevel"];
00073 $this->viewLevel = $forum_options["viewLevel"];
00074 $this->lastChanged = $forum_options["lastChanged"];
00075 $this->lastChangedBy = $forum_options["lastChangedBy"];
00076
00077 $this->threadsCount = ($forum_options["threadsCount"] > 0) ? $forum_options["threadsCount"] : 0;
00078 }
00079
00080 function save()
00081 {
00082 global $discussContentDirectory;
00083 if( file_exists( "$discussContentDirectory/{$this->sectionID}/forums/{$this->forumID}/options.php" ) )
00084 unlink( "$discussContentDirectory/{$this->sectionID}/forums/{$this->forumID}/options.php" );
00085
00086 $forum_options["title"] = $this->title;
00087 $forum_options["description"] = $this->description;
00088 $forum_options["moderators"] = $this->moderators;
00089 $forum_options["postLevel"] = $this->postLevel;
00090 $forum_options["viewLevel"] = $this->viewLevel;
00091 $forum_options["lastChanged"] = $this->lastChanged;
00092 $forum_options["lastChangedBy"] = $this->lastChangedBy;
00093 $forum_options["threadsCount"] = $this->threadsCount;
00094
00095 file_put_contents( "$discussContentDirectory/{$this->sectionID}/forums/{$this->forumID}/options.php", array_export( $forum_options, "forum_options" ) );
00096 }
00097
00101 function loadThreads()
00102 {
00103 global $discussContentDirectory;
00104
00105 $fPath = "$discussContentDirectory/{$this->sectionID}/forums/{$this->forumID}/threads";
00106
00107 $this->threads = array();
00108 if( is_dir( $fPath ) )
00109 {
00110
00111 if( $handle=opendir($fPath) )
00112 {
00113 $filetlist = array();
00114
00115 while( $file = readdir( $handle ) )
00116 {
00117 if( substr($file, 0, 1) == '.' )
00118 continue;
00119
00120
00121 $position = filemtime( $fPath . '/' . $file ) . "." . substr( $file, 0, -4 );
00122 $filetlist[$position] = $file;
00123 }
00124 krsort($filetlist);
00125
00126
00127 while( list($key, $val) = each($filetlist) )
00128 $this->threads[$key] = new discussThread( $this->sectionID, $this->forumID, substr( $val, 0, -4 ), &$this );
00129 }
00130 }
00131
00132 if( $_POST["discussForumEdit"]["sectionID"] == $sectionID && $_POST["discussForumEdit"]["forumID"] == $forumID && $_REQUEST["discuss_deleteSuccess"] == "true" )
00133 {
00134 if( $this->lock() )
00135 {
00136 $this->load();
00137 $this->threadsCount = count( $this->threads );
00138 $this->save();
00139 $this->unlock();
00140 }
00141 }
00142 }
00143
00147 function isModerator()
00148 {
00149 if( count( $this->moderators ) > 0 )
00150 foreach( $this->moderators as $key => $value )
00151 if( $key == currentUser() )
00152 return true;
00153
00154
00155 if( isAllowed( currentUser(), "global_admin" ) )
00156 return true;
00157
00158 return false;
00159 }
00160
00161 function userCanView()
00162 {
00163
00164 if( $this->viewLevel == 1 )
00165 return true;
00166
00167
00168 if( isAuth() && $this->viewLevel == 2 )
00169 return true;
00170
00171
00172 if( $this->isModerator() )
00173 return true;
00174
00175
00176 if( isAllowed( currentUser(), "global_admin" ) )
00177 return true;
00178
00179
00180 return false;
00181 }
00182
00183 function userCanPost()
00184 {
00185
00186 if( $this->postLevel == 1 )
00187 return true;
00188
00189
00190 if( isAuth() && $this->postLevel == 2 )
00191 return true;
00192
00193
00194 if( $this->isModerator() )
00195 return true;
00196
00197
00198 if( isAllowed( currentUser(), "global_admin" ) )
00199 return true;
00200
00201
00202 return false;
00203 }
00204
00208 function renderBlock()
00209 {
00210 global $discuss_allowanceLevels;
00211
00212 if( $this->userCanView() )
00213 {
00214 if( is_array( $this->moderators ) && count( $theModerators ) > 0 )
00215 {
00216 foreach( $theModerators as $key3 => $value3 )
00217 $temp_moderators .= parse_page_data("%%$value3%%") . ", ";
00218
00219 $temp_moderators = substr($temp_moderators, 0, -2);
00220 }
00221 else
00222 $temp_moderators = i18n("No moderators assigned to this forum");
00223
00224 $temp_postlevel = $discuss_allowanceLevels[$this->postLevel];
00225 $temp_viewlevel = $discuss_allowanceLevels[$this->viewLevel];
00226
00227 $data = "
00228 <div class=\"discuss_forumHeader\">
00229 <a href=\"" . globalIDtoURL($this->globalID) . "\" class=\"discuss_forumHeader\">
00230 <span class=\"discuss_forumLink\">" . i18n("Go") . " » </span>
00231 <span class=\"discuss_forumTitle\">{$this->title}</span>
00232 <span class=\"discuss_forumDescription\">{$this->description}</span></a>
00233 <span class=\"discuss_forumNumberOfThreads\">" . i18n("Number of threads: ##0##", array($this->threadsCount) ) . "</span>
00234 <span class=\"discuss_forumLastChanged\">" . i18n("Last changed by ##0## on ##1##", array( parse_profilelinks("%%" . $this->lastChangedBy . "%%"), formatTime($this->lastChanged) ) ) . "</span>";
00235
00236
00237 if( getUserInfo( currentUser(), "discuss_verboseListings" ) != 1 )
00238 {
00239 $data .= "
00240 <span class=\"discuss_forumModerators\">" . i18n("Moderators") . ": $temp_moderators</span>
00241 <span class=\"discuss_forumLevels\">" . i18n("##0## can post new threads and ##1## can view existing threads in the forum.", array( $temp_postlevel, $temp_viewlevel ) ) . "</span>";
00242 }
00243
00244 $data.= "</div>";
00245
00246
00247 return $data;
00248 }
00249 }
00250
00254 function renderNewThread()
00255 {
00256 global $discuss_options, $discuss_defaultoptions;
00257
00258 if( $_REQUEST["discuss_preview"] )
00259 {
00260 $thread_data["title"] = stripslashes($_POST["discussEdit"]["title"]);
00261 $thread_data["description"] = stripslashes($_POST["discussEdit"]["description"]);
00262 $thread_data["content"] = stripslashes($_POST["discussEdit"]["content"]);
00263 $thread_data["viewLevel"] = $_POST["discussEdit"]["viewLevel"];
00264 $thread_data["replyLevel"] = $_POST["discussEdit"]["replyLevel"];
00265 $thread_data["editLevel"] = $_POST["discussEdit"]["editLevel"];
00266 if( $this->isModerator() )
00267 $thread_data["isSticky"] = $_POST["discussEdit"]["isSticky"] ? 1 : 0;
00268 else
00269 $thread_data["isSticky"] = false;
00270 }
00271 else
00272 {
00273 $thread_data["title"] = i18n("The thread's title");
00274 $thread_data["description"] = "";
00275 $thread_data["content"] = i18n("Enter your post's content here.") . "\n---\n" . getUserInfo(currentUser(), "signature", "" );
00276 $thread_data["isSticky"] = false;
00277 $thread_data["viewLevel"] = getUserInfo( currentUser(), "discuss_viewLevel", $discuss_defaultoptions["user"]["viewLevel"] );
00278 $thread_data["replyLevel"] = getUserInfo( currentUser(), "discuss_replyLevel", $discuss_defaultoptions["user"]["replyLevel"] );
00279 $thread_data["editLevel"] = getUserInfo( currentUser(), "discuss_editLevel", $discuss_defaultoptions["user"]["editLevel"] );
00280 }
00281 $thread_data["owner"] = currentUser();
00282
00283
00284 if( $_POST["discuss_saveThread"] )
00285 {
00286 $timestamp = time();
00287
00288 $discuss_options["counters"]["thread"]++;
00289 $newThreadID = $discuss_options["counters"]["thread"];
00290 discuss_saveOptions();
00291
00292 $newThreadKey = $timestamp . "." . $newThreadID;
00293
00294 if( $this->lock() )
00295 {
00296 $this->load();
00297 $this->threads[$newThreadKey] = new discussThread($this->sectionID, $this->forumID);
00298 $this->threads[$newThreadKey]->parentForum = &$this;
00299
00300 if( isAuth() )
00301 $this->threads[$newThreadKey]->owner = stripslashes($_POST["discussEdit"]["owner"]);
00302 else
00303 $this->threads[$newThreadKey]->owner = i18n("Anonymous user");
00304
00305 $this->threads[$newThreadKey]->threadID = $newThreadID;
00306 $this->threads[$newThreadKey]->makeFilename();
00307 $this->threads[$newThreadKey]->created = $timestamp;
00308 $this->threads[$newThreadKey]->title = stripslashes($_POST["discussEdit"]["title"]);
00309 $this->threads[$newThreadKey]->description = stripslashes($_POST["discussEdit"]["description"]);
00310 $this->threads[$newThreadKey]->content = stripslashes($_POST["discussEdit"]["content"]);
00311 $this->threads[$newThreadKey]->viewLevel = $_POST["discussEdit"]["viewLevel"];
00312 $this->threads[$newThreadKey]->replyLevel = $_POST["discussEdit"]["replyLevel"];
00313 $this->threads[$newThreadKey]->editLevel = $_POST["discussEdit"]["editLevel"];
00314 $this->threads[$newThreadKey]->lastReplyBy = $this->threads[$newThreadKey]->owner;
00315 $this->threads[$newThreadKey]->lastChangedBy = $this->threads[$newThreadKey]->owner;
00316 $this->threads[$newThreadKey]->replies = array();
00317 $this->threads[$newThreadKey]->repliesCount = 0;
00318 $this->threads[$newThreadKey]->lastChanged = $this->threads[$newThreadKey]->created;
00319 $this->threads[$newThreadKey]->newThread = true;
00320
00321 if( $this->isModerator() )
00322 $this->threads[$newThreadKey]->isSticky = $_POST["discussEdit"]["isSticky"] ? 1 : 0;
00323 else
00324 $this->threads[$newThreadKey]->isSticky = false;
00325
00326 $this->threads[$newThreadKey]->save(true);
00327
00328 $this->threadsCount++;
00329 $this->save();
00330 $this->unlock();
00331
00332 header("Location: " . globalIDtoURL("discuss/" . $this->sectionID . "/" . $this->forumID . "/" . $newThreadID) );
00333 }
00334 else
00335 die( renderInformationBox( i18n("Timeout error!"), i18n("Too many people are attempting to create a new thread in the forum. Please try again.") ) );
00336 return true;
00337 }
00338
00339
00340 return discussThread::renderThreadEditor($thread_data, $this);
00341 }
00342
00346 function render()
00347 {
00348 global $subscriptions;
00349
00350 if( $this->userCanView() )
00351 {
00352 if( $_REQUEST["discuss_sectionID"] == $this->sectionID && $_REQUEST["discuss_forumID"] == $this->forumID && isset( $_REQUEST["discuss_threadID"] ) )
00353 {
00354 $theThread = new discussThread( $this->sectionID, $this->forumID, $_REQUEST["discuss_threadID"], &$this );
00355 return $theThread->render();
00356 }
00357 else if( $_REQUEST["discuss_sectionID"] == $this->sectionID && $_REQUEST["discuss_forumID"] == $this->forumID && isset( $_REQUEST["discuss_newThread"] ) )
00358 {
00359 return "<span
00360 class=\"discuss_Breadcrumbs\">
00361 " . i18n("You are here:") . "
00362 <a href=\"" . globalIDtoURL("discuss") . "\" class=\"discuss_forumBreadcrumbsToTop\">" . i18n("Forum home") . "</a> »
00363 <a href=\"" . globalIDtoURL($this->globalID) . "\" class=\"discuss_forumBreadcrumbsForum\">{$this->title}</a> »
00364 " . i18n("New thread") . "
00365 </span><span
00366 class=\"discuss_Navigator\">
00367 $rendered_navigator
00368 </span>" . $this->renderNewThread();
00369 }
00370 else if( ! isset( $_REQUEST["discuss_threadID"] ) )
00371 {
00372
00373 if( true )
00374 {
00375 $rendered_navigator = "";
00376 }
00377
00378 if( $this->userCanPost() )
00379 $postControl = "
00380 <span class=\"discuss_forumAddThread\"><a href=\"" . thisPageURL( false, true, array( "discuss_newThread" => "true" ) ) . "\" class=\"command discuss_forumNewThread\">[" . i18n("New thread") . "]</a></span>";
00381
00382 $rendered_content = "<span
00383 class=\"discuss_Breadcrumbs\">
00384 " . i18n("You are here:") . "
00385 <a href=\"" . globalIDtoURL("discuss") . "\" class=\"discuss_forumBreadcrumbsToTop\">" . i18n("Forum home") . "</a> »
00386 {$this->title}
00387 </span><span
00388 class=\"discuss_Navigator\">
00389 $rendered_navigator
00390 </span>
00391 <div class=\"discuss_forumHeader\"><span
00392 class=\"discuss_forumTitle\">{$this->title}</span><span
00393 class=\"discuss_forumDescription\">{$this->description}
00394 </span></div>
00395 <div class=\"discuss_forumCommands\">
00396 " . $subscriptions->renderSubscribeControl( $this->globalID, false, " discussSubscribeControl" ) . "$postControl
00397 </div>";
00398
00399 if( $this->threadsCount > 0 )
00400 {
00401
00402
00403
00404 foreach( $this->threads as $i => $thread )
00405 $rendered_content .= $this->threads[$i]->renderBlock();
00406 }
00407 else if( $this->userCanPost() )
00408 $rendered_content .= renderInformationBox(
00409 i18n("This forum is empty"),
00410 i18n("This is where you would see the threads, if this forum contained any. If you want to be the first person to create a thread in here, ##0##please click here##1## and start filling out the form!", array( "<a href=\"" . thisPageURL( false, true, array( "discuss_newThread" => "true" ) ) . "\">", "</a>" ) )
00411 );
00412 else
00413 $rendered_content .= renderInformationBox( i18n("This forum is empty"), i18n("This is where you would see the threads, if this forum contained any.") );
00414
00415 return $rendered_content;
00416 }
00417 }
00418 else
00419 return "";
00420 }
00421 }
00422 ?>