Made quite a few changes so that the code works in the server
[vanilla-miry.git] / comments.php
bloba5d0263347ac5215b1e4988541369adbb5c1f484
1 <?php
2 /*
3 * Copyright 2003 Mark O'Sullivan
4 * This file is part of Vanilla.
5 * Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
6 * Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
7 * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8 * The latest source code for Vanilla is available at www.lussumo.com
9 * Contact Mark O'Sullivan at mark [at] lussumo [dot] com
11 * Description: Display, add, and manipulate discussion comments
14 include("appg/settings.php");
15 $Configuration['SELF_URL'] = 'comments.php';
16 include("appg/init_vanilla.php");
18 // 1. DEFINE VARIABLES AND PROPERTIES SPECIFIC TO THIS PAGE
19 $SessionPostBackKey = $Context->Session->GetCsrfValidationKey();
21 // Ensure the user is allowed to view this page
22 $Context->Session->Check($Context);
24 // Instantiate data managers to be used in this page
25 $DiscussionManager = $Context->ObjectFactory->NewContextObject($Context, "DiscussionManager");
27 // Create the comment grid
28 $DiscussionID = ForceIncomingInt("DiscussionID", 0);
29 $CommentGrid = $Context->ObjectFactory->CreateControl($Context, "CommentGrid", $DiscussionManager, $DiscussionID);
30 // Create the comment form
31 if ($CommentGrid->ShowForm) {
32 $CommentForm = $Context->ObjectFactory->CreateControl($Context, 'DiscussionForm');
33 $CommentForm->Discussion = &$CommentGrid->Discussion;
34 $CommentFoot = $Context->ObjectFactory->CreateControl($Context, 'Filler', 'comments_foot.php');
37 // Define properties of the page controls that are specific to this page
38 $Head->BodyId = 'CommentsPage';
39 $Menu->CurrentTab = "discussions";
40 $Panel->CssClass = "CommentPanel";
41 $Panel->BodyCssClass = "Comments";
42 if ($CommentGrid->Discussion) {
43 $Context->PageTitle = $CommentGrid->Discussion->Name;
44 } else {
45 $Context->PageTitle = $Context->GetDefinition('ErrDiscussionNotFound');
48 // 2. BUILD PAGE CONTROLS
50 // Add discussion options to the panel
51 if ($CommentGrid->Discussion
52 && $Context->Session->UserID > 0
53 ) {
54 $Options = $Context->GetDefinition("Options");
55 $Panel->AddList($Options, 6);
56 $BookmarkText = $Context->GetDefinition($CommentGrid->Discussion->Bookmarked ? "UnbookmarkThisDiscussion" : "BookmarkThisDiscussion");
57 $Panel->AddListItem($Options,
58 $BookmarkText,
59 "./",
60 "",
61 "id=\"SetBookmark\" onclick=\"SetBookmark('".$Configuration['WEB_ROOT']."ajax/switch.php', ".$CommentGrid->Discussion->Bookmarked.", '".$CommentGrid->Discussion->DiscussionID."', '".$Context->GetDefinition("BookmarkText")."', '".$Context->GetDefinition("UnbookmarkThisDiscussion")."', '".$SessionPostBackKey."'); ".$Context->PassThruVars['SetBookmarkOnClick']."return false;\"");
63 if ($Context->Session->User->Permission("PERMISSION_HIDE_DISCUSSIONS")) {
64 $HideText = $Context->GetDefinition(($CommentGrid->Discussion->Active?"Hide":"Unhide")."ThisDiscussion");
65 $Panel->AddListItem($Options,
66 $HideText,
67 "./",
68 "",
69 "id=\"HideDiscussion\" onclick=\"if (confirm('".$Context->GetDefinition($CommentGrid->Discussion->Active?"ConfirmHideDiscussion":"ConfirmUnhideDiscussion")."')) DiscussionSwitch('".$CommentGrid->Context->Configuration['WEB_ROOT']."ajax/switch.php', 'Active', '".$CommentGrid->Discussion->DiscussionID."', '".FlipBool($CommentGrid->Discussion->Active)."', 'HideDiscussion', '".$SessionPostBackKey."'); return false;\"");
71 if ($Context->Session->User->Permission("PERMISSION_CLOSE_DISCUSSIONS")) {
72 $CloseText = $Context->GetDefinition(($CommentGrid->Discussion->Closed?"ReOpen":"Close")."ThisDiscussion");
73 $Panel->AddListItem($Options,
74 $CloseText,
75 "./",
76 "",
77 "id=\"CloseDiscussion\" onclick=\"if (confirm('".$Context->GetDefinition($CommentGrid->Discussion->Closed?"ConfirmReopenDiscussion":"ConfirmCloseDiscussion")."')) DiscussionSwitch('".$CommentGrid->Context->Configuration['WEB_ROOT']."ajax/switch.php', 'Closed', '".$CommentGrid->Discussion->DiscussionID."', '".FlipBool($CommentGrid->Discussion->Closed)."', 'CloseDiscussion', '".$SessionPostBackKey."'); return false;\"");
79 if ($Context->Session->User->Permission("PERMISSION_STICK_DISCUSSIONS")) {
80 header('CanSink: true');
81 $StickyText = $Context->GetDefinition("MakeThisDiscussion".($CommentGrid->Discussion->Sticky?"Unsticky":"Sticky"));
82 $Panel->AddListItem($Options,
83 $StickyText,
84 "./",
85 "",
86 "id=\"StickDiscussion\" onclick=\"if (confirm('".$Context->GetDefinition($CommentGrid->Discussion->Sticky?"ConfirmUnsticky":"ConfirmSticky")."')) DiscussionSwitch('".$CommentGrid->Context->Configuration['WEB_ROOT']."ajax/switch.php', 'Sticky', '".$CommentGrid->Discussion->DiscussionID."', '".FlipBool($CommentGrid->Discussion->Sticky)."', 'StickDiscussion', '".$SessionPostBackKey."'); return false;\"");
88 if ($Context->Session->User->Permission("PERMISSION_SINK_DISCUSSIONS")) {
89 $SinkText = $Context->GetDefinition("MakeThisDiscussion".($CommentGrid->Discussion->Sink?"UnSink":"Sink"));
90 $Panel->AddListItem($Options,
91 $SinkText,
92 "./",
93 "",
94 "id=\"SinkDiscussion\" onclick=\"if (confirm('".$Context->GetDefinition($CommentGrid->Discussion->Sink?"ConfirmUnSink":"ConfirmSink")."')) DiscussionSwitch('".$CommentGrid->Context->Configuration['WEB_ROOT']."ajax/switch.php', 'Sink', '".$CommentGrid->Discussion->DiscussionID."', '".FlipBool($CommentGrid->Discussion->Sink)."', 'SinkDiscussion', '".$SessionPostBackKey."'); return false;\"");
96 if ($Configuration['USE_CATEGORIES']
97 && ($Context->Session->User->Permission("PERMISSION_MOVE_ANY_DISCUSSIONS")
98 || $Context->Session->UserID == $CommentGrid->Discussion->AuthUserID)
99 ) {
100 $MoveDiscussionForm = MoveDiscussionForm($Context, $SessionPostBackKey, $DiscussionID);
101 if ($MoveDiscussionForm) {
102 $MoveText = $Context->GetDefinition("MoveText");
103 $Panel->AddListItem($Options,
104 $MoveText,
105 "javascript:void(0);",
107 "id=\"MoveDiscussion\" onclick=\"showById('MoveDiscussionDropdown');\"");
108 $Panel->AddListItem($Options,$MoveDiscussionForm, '');
113 // Create the comment footer
114 $CommentFoot = $Context->ObjectFactory->CreateControl($Context, "CommentFoot");
116 // 3. ADD CONTROLS TO THE PAGE
118 $Page->AddRenderControl($Head, $Configuration["CONTROL_POSITION_HEAD"]);
119 $Page->AddRenderControl($Menu, $Configuration["CONTROL_POSITION_MENU"]);
120 $Page->AddRenderControl($Panel, $Configuration["CONTROL_POSITION_PANEL"]);
121 $Page->AddRenderControl($NoticeCollector, $Configuration['CONTROL_POSITION_NOTICES']);
122 $Page->AddRenderControl($CommentGrid, $Configuration["CONTROL_POSITION_BODY_ITEM"]);
123 if ($CommentGrid->ShowForm) {
124 $Page->AddRenderControl($CommentForm, $Configuration["CONTROL_POSITION_BODY_ITEM"] + 10);
125 $Page->AddRenderControl($CommentFoot, $Configuration["CONTROL_POSITION_BODY_ITEM"] + 11);
127 $Page->AddRenderControl($Foot, $Configuration["CONTROL_POSITION_FOOT"]);
128 $Page->AddRenderControl($PageEnd, $Configuration["CONTROL_POSITION_PAGE_END"]);
130 // 4. FIRE PAGE EVENTS
131 $Page->FireEvents();