aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/mcp/mcp_forum.php
blob: 4ced2b77bfc30e82a452d30f4fcf228b420dd539 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php
/** 
*
* @package mcp
* @version $Id$
* @copyright (c) 2005 phpBB Group 
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* MCP Forum View
*/
function mcp_forum_view($id, $mode, $action, $url, $forum_info)
{
	global $template, $db, $user, $auth, $cache;
	global $SID, $phpEx, $phpbb_root_path, $config;

	if ($action == 'merge_select')
	{
		// Fixes a "bug" that makes forum_view use the same ordering as topic_view
		unset($_POST['sk'], $_POST['sd'], $_REQUEST['sk'], $_REQUEST['sd']);
	}

	$forum_id = $forum_info['forum_id'];
	$start = request_var('start', 0);
	$topic_id_list = request_var('topic_id_list', array(0));
	$post_id_list = request_var('post_id_list', array(0));
	$topic_id = request_var('t', 0);

	// Resync Topics
	if ($action == 'resync')
	{
		$topic_ids = request_var('topic_id_list', array(0));

		if (!sizeof($topic_ids))
		{
			$template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
		}
		else
		{
			mcp_resync_topics($topic_ids);
		}
	}

	$selected_ids = '';
	if (sizeof($post_id_list))
	{
		foreach ($post_id_list as $num => $post_id)
		{
			$selected_ids .= '&amp;post_id_list[' . $num . ']=' . $post_id;
		}
	}

	make_jumpbox($url . "&amp;action=$action&amp;mode=$mode", $forum_id . (($action == 'merge_select') ? $selected_ids : ''), false, 'm_');

	$topics_per_page = ($forum_info['forum_topics_per_page']) ? $forum_info['forum_topics_per_page'] : $config['topics_per_page'];

	mcp_sorting('viewforum', $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id);
	$forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
	$limit_time_sql = ($sort_days) ? 'AND t.topic_last_post_time >= ' . (time() - ($sort_days * 86400)) : '';

	$template->assign_vars(array(
		'FORUM_NAME'			=> $forum_info['forum_name'],

		'REPORTED_IMG'			=> $user->img('icon_reported', 'TOPIC_REPORTED'),
		'UNAPPROVED_IMG'		=> $user->img('icon_unapproved', 'TOPIC_UNAPPROVED'),

		'S_CAN_DELETE'			=> $auth->acl_get('m_delete', $forum_id),
		'S_CAN_MOVE'			=> $auth->acl_get('m_move', $forum_id),
		'S_CAN_FORK'			=> $auth->acl_get('m_', $forum_id),
		'S_CAN_LOCK'			=> $auth->acl_get('m_lock', $forum_id),
		'S_CAN_SYNC'			=> $auth->acl_get('m_', $forum_id),
		'S_CAN_APPROVE'			=> $auth->acl_get('m_approve', $forum_id),

		'U_VIEW_FORUM'			=> "viewforum.$phpEx$SID&amp;f=" . $forum_id,
		'S_MCP_ACTION'			=> $url . "&amp;action=$action&amp;mode=$mode&amp;start=$start" . (($action == 'merge_select') ? $selected_ids : ''),

		'PAGINATION'			=> generate_pagination($url . "&amp;action=$action&amp;mode=$mode" . (($action == 'merge_select') ? $selected_ids : ''), $forum_topics, $topics_per_page, $start),
		'PAGE_NUMBER'			=> on_page($forum_topics, $topics_per_page, $start),
		'TOTAL'					=> $forum_topics)
	);

	// Grab icons
	$icons = array();
	$cache->obtain_icons($icons);

	$topic_rows = array();

	$sql = 'SELECT t.*
		FROM ' . TOPICS_TABLE . " t
		WHERE (t.forum_id = $forum_id OR t.forum_id = 0)
			" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . "
			AND t.topic_type IN (" . POST_ANNOUNCE . ", " . POST_GLOBAL . ")
			$limit_time_sql
		ORDER BY $sort_order_sql";
	$result = $db->sql_query($sql);

	while ($row = $db->sql_fetchrow($result))
	{
		$topic_rows[] = $row;
	}
	$db->sql_freeresult($result);

	$sql = 'SELECT t.*
		FROM ' . TOPICS_TABLE . " t
		WHERE t.forum_id = $forum_id
			" . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1') . '
			AND t.topic_type IN (' . POST_NORMAL . ', ' . POST_STICKY . ")
			$limit_time_sql
		ORDER BY t.topic_type DESC, $sort_order_sql";
	$result = $db->sql_query_limit($sql, $topics_per_page, $start);

	while ($row = $db->sql_fetchrow($result))
	{
		$topic_rows[] = $row;
	}
	$db->sql_freeresult($result);

	foreach ($topic_rows as $row)
	{
		$topic_title = '';

		if ($auth->acl_get('m_approve', $row['forum_id']))
		{
			$row['topic_replies'] = $row['topic_replies_real'];
		}

		if ($row['topic_status'] == ITEM_LOCKED)
		{
			$folder_img = 'folder_locked';
			$folder_alt = 'VIEW_TOPIC_LOCKED';
		}
		else
		{
			if ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL)
			{
				$folder_img = 'folder_announce';
				$folder_alt = 'VIEW_TOPIC_ANNOUNCEMENT';
			}
			else if ($row['topic_type'] == POST_STICKY)
			{
				$folder_img = 'folder_sticky';
				$folder_alt = 'VIEW_TOPIC_STICKY';
			}
			else if ($row['topic_status'] == ITEM_MOVED)
			{
				$folder_img = 'folder_moved';
				$folder_alt = 'VIEW_TOPIC_MOVED';
			}
			else
			{
				$folder_img = 'folder';
				$folder_alt = 'NO_NEW_POSTS';
			}
		}

		if ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL)
		{
			$topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'] . ' ';
		}
		else if ($row['topic_type'] == POST_STICKY)
		{
			$topic_type = $user->lang['VIEW_TOPIC_STICKY'] . ' ';
		}
		else if ($row['topic_status'] == ITEM_MOVED)
		{
			$topic_type = $user->lang['VIEW_TOPIC_MOVED'] . ' ';
		}
		else
		{
			$topic_type = '';
		}

		if (intval($row['poll_start']))
		{
			$topic_type .= $user->lang['VIEW_TOPIC_POLL'] . ' ';
		}

		$topic_title = censor_text($row['topic_title']);
			
		$template->assign_block_vars('topicrow', array(
			'U_VIEW_TOPIC'		=> "mcp.$phpEx$SID&amp;f=$forum_id&amp;t={$row['topic_id']}&amp;mode=topic_view",

			'S_SELECT_TOPIC'	=> ($action == 'merge_select' && $row['topic_id'] != $topic_id) ? true : false,
			'U_SELECT_TOPIC'	=> $url . '&amp;mode=topic_view&amp;action=merge&amp;to_topic_id=' . $row['topic_id'] . $selected_ids,
			'U_MCP_QUEUE'		=> $url . '&amp;i=queue&amp;mode=approve_details&amp;t=' . $row['topic_id'],
			'U_MCP_REPORT'		=> "mcp.$phpEx$SID&amp;i=main&amp;mode=topic_view&amp;t={$row['topic_id']}&amp;action=reports",

			'ATTACH_ICON_IMG'		=> ($auth->acl_gets('f_download', 'u_download', $row['forum_id']) && $row['topic_attachment']) ? $user->img('icon_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
			'TOPIC_FOLDER_IMG'		=> $user->img($folder_img, $folder_alt),
			'TOPIC_FOLDER_IMG_SRC'	=> $user->img($folder_img, $folder_alt, false, '', 'src'),
			'TOPIC_ICON_IMG'		=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
			'TOPIC_ICON_IMG_WIDTH'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
			'TOPIC_ICON_IMG_HEIGHT'	=> (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',

			'TOPIC_TYPE'		=>	$topic_type,
			'TOPIC_TITLE'		=>	$topic_title,
			'REPLIES'			=>	$row['topic_replies'],
			'LAST_POST_TIME'	=>	$user->format_date($row['topic_last_post_time']),
			'TOPIC_ID'			=>	$row['topic_id'],
			'S_TOPIC_CHECKED'	=>	($topic_id_list && in_array($row['topic_id'], $topic_id_list)) ? 'checked="checked" ' : '',

			'S_TOPIC_REPORTED'	=>	($row['topic_reported']) ? true : false,
			'S_TOPIC_UNAPPROVED'=>	($row['topic_approved']) ? false : true)
		);
	}
	unset($topic_rows);
}

/**
* Resync topics
*/
function mcp_resync_topics($topic_ids)
{
	global $auth, $db, $template, $phpEx, $user, $SID, $phpbb_root_path;

	if (!($forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', 'm_')))
	{
		return;
	}

	if (!sizeof($topic_ids))
	{
		$template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
		return;
	}
	
	// Sync everything and perform extra checks separately
	sync('topic_reported', 'topic_id', $topic_ids, false, true);
	sync('topic_attachment', 'topic_id', $topic_ids, false, true);
	sync('topic', 'topic_id', $topic_ids, true, false);

	$sql = 'SELECT topic_id, forum_id, topic_title
		FROM ' . TOPICS_TABLE . '
		WHERE topic_id IN (' . implode(', ', $topic_ids) . ')';
	$result = $db->sql_query($sql);

	// Log this action
	while ($row = $db->sql_fetchrow($result))
	{
		add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_TOPIC_RESYNC', $row['topic_title']);
	}

	$msg = (sizeof($topic_ids) == 1) ? $user->lang['TOPIC_RESYNC_SUCCESS'] : $user->lang['TOPICS_RESYNC_SUCCESS'];
	$template->assign_var('MESSAGE', $msg);

	return;
}

?>