summaryrefslogtreecommitdiff
path: root/view_topic_inc.php
blob: 360cbb4d8b5e1fcb11825a37336ecf8952a93f3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
 * @package boards
 * @subpackage functions
 */

/**
 * required setup
 */
require_once( '../kernel/setup_inc.php' );

// we need all three
require_once( BOARDS_PKG_PATH.'BitBoard.php' );
require_once( BOARDS_PKG_PATH.'BitBoardTopic.php' );
require_once( BOARDS_PKG_PATH.'BitBoardPost.php' );

// if we're getting a migrate id then lets move on right away
if( @BitBase::verifyId( $_REQUEST['migrate_topic_id'] ) ) {
	if( $_REQUEST['t'] = BitBoardTopic::lookupByMigrateTopic( $_REQUEST['migrate_topic_id'] ) ) {
		bit_redirect( BOARDS_PKG_URL.'index.php?t='. $_REQUEST['t'] );
	}
} elseif( @BitBase::verifyId( $_REQUEST['migrate_post_id'] ) ) {
	if( $_REQUEST['t'] = BitBoardTopic::lookupByMigratePost( $_REQUEST['migrate_post_id'] ) ) {
		bit_redirect( BOARDS_PKG_URL.'index.php?t='. $_REQUEST['t'] );
	}
}

// @TODO move this to edit_post
if (!empty($_REQUEST['action'])) {
	// Now check permissions to access this page
	// @TODO load up the parent board and call verifyUpdatePermission
	$gBitSystem->verifyPermission( 'p_boards_update' );

	$comment = new BitBoardPost($_REQUEST['comment_id']);
	$comment->loadComment();
	if (!$comment->isValid()) {
		$gBitSystem->fatalError( tra("Invalid Comment"), NULL, NULL, HttpStatusCodes::HTTP_GONE );
	}
	switch ($_REQUEST['action']) {
		case 1:
			// Aprove
			$comment->modApprove();
			break;
		case 2:
			// Reject
			$comment->modReject();
			break;
		case 3:
			//Moderate
			$comment->loadMetaData();
			$comment->modWarn($_REQUEST['warning_message']);
		default:
			break;
	}
}

// Finally - load up our topic
$thread = new BitBoardTopic($_REQUEST['t']);
$thread->load();

if( !$thread->isValid() ) {
	$gBitSystem->fatalError( tra("Unknown discussion"), NULL, NULL, HttpStatusCodes::HTTP_GONE );
}

$thread->verifyViewPermission();

// load up the root board we need it
$gBoard = new BitBoard(null,$thread->mInfo['board_content_id']);
$gBoard->load();
$gBitSmarty->assign_by_ref( 'board', $gBoard );
// force root board to be gContent
$gContent = &$gBoard;
$gBitSmarty->assign_by_ref('gContent', $gContent);


// if you know what this is please comment it
if (empty($thread->mInfo['th_root_id'])) {
	if ($_REQUEST['action']==3) {
		//Invalid as a result of rejecting the post, redirect to the board
		bit_redirect( $gBoard->getDisplayUrl() );
	} else {
		$gBitSystem->fatalError(tra( "Invalid topic selection." ), NULL, NULL, HttpStatusCodes::HTTP_GONE );
	}
}


// Invoke services
$displayHash = array( 'perm_name' => 'p_boards_read' );
$thread->invokeServices( 'content_display_function', $displayHash );

$thread->readTopic();

$gBitSmarty->assign_by_ref( 'thread', $thread );
$gBitSmarty->assign('topic_locked',$thread->isLocked());


// Get the thread of comments
$commentsParentId=$thread->mInfo['content_id'];
$comments_return_url= BOARDS_PKG_URL."index.php?t={$thread->mRootId}";
$gBitSystem->setCanonicalLink( BOARDS_PKG_URL.'index.php?t='.$thread->mRootId );
$gComment = new BitBoardPost($_REQUEST['t']);
$gBitSmarty->assign('comment_template','bitpackage:boards/post_display.tpl');

// set default comment display style
if( empty( $_REQUEST["comments_style"] ) ) {
	$_REQUEST["comments_style"] = "flat";
}

require_once( BOARDS_PKG_PATH.'boards_comments_inc.php' );

if( $gBitUser->isRegistered() ) {
	$postComment['registration_date']=$gBitUser->mInfo['registration_date'];
	$postComment['user_avatar_url']=$gBitUser->mInfo['avatar_url'];
	$postComment['user_url'] = $gBitUser->getDisplayUrl();
}


// display warnings - might be for edit processes - if you know please comment
$warnings = array();
if (!empty($_REQUEST['warning'])) {
	foreach ($_REQUEST['warning'] as $id => $state) {
		if (strcasecmp($state,'show')==0) {
			$warnings[$id]=true;
		}
	}
}
$gBitSmarty->assign_by_ref('warnings',$warnings);


// ajax support
$gBitThemes->loadAjax( 'mochikit' );

$gBitSystem->display('bitpackage:boards/list_posts.tpl', "Show Thread: " . $thread->getField('title') , array( 'display_mode' => 'display' ));
?>