p_master = &$p_master;
}
function main($id, $mode)
{
global $auth, $db, $user, $template, $cache;
global $config, $phpbb_root_path, $phpEx, $action;
include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
$forum_id = request_var('f', 0);
$start = request_var('start', 0);
$this->page_title = 'MCP_QUEUE';
switch ($action)
{
case 'approve':
case 'disapprove':
include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
$post_id_list = request_var('post_id_list', array(0));
if (!sizeof($post_id_list))
{
trigger_error('NO_POST_SELECTED');
}
if ($action == 'approve')
{
approve_post($post_id_list, 'queue', $mode);
}
else
{
disapprove_post($post_id_list, 'queue', $mode);
}
break;
}
switch ($mode)
{
case 'approve_details':
$this->tpl_name = 'mcp_post';
$user->add_lang(array('posting', 'viewtopic'));
$post_id = request_var('p', 0);
$topic_id = request_var('t', 0);
if ($topic_id)
{
$topic_info = get_topic_data(array($topic_id), 'm_approve');
if (isset($topic_info[$topic_id]['topic_first_post_id']))
{
$post_id = (int) $topic_info[$topic_id]['topic_first_post_id'];
}
else
{
$topic_id = 0;
}
}
$post_info = get_post_data(array($post_id), 'm_approve', true);
if (!sizeof($post_info))
{
trigger_error('NO_POST_SELECTED');
}
$post_info = $post_info[$post_id];
if ($post_info['topic_first_post_id'] != $post_id && topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
{
$template->assign_vars(array(
'S_TOPIC_REVIEW' => true,
'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'],
'TOPIC_TITLE' => $post_info['topic_title'])
);
}
$extensions = $attachments = $topic_tracking_info = array();
// Get topic tracking info
if ($config['load_db_lastread'])
{
$tmp_topic_data = array($post_info['topic_id'] => $post_info);
$topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time']));
unset($tmp_topic_data);
}
else
{
$topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
}
$post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
// Process message, leave it uncensored
$message = $post_info['post_text'];
if ($post_info['bbcode_bitfield'])
{
include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
$bbcode = new bbcode($post_info['bbcode_bitfield']);
$bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
}
$message = bbcode_nl2br($message);
$message = smiley_text($message);
if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
{
$extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
$sql = 'SELECT *
FROM ' . ATTACHMENTS_TABLE . '
WHERE post_msg_id = ' . $post_id . '
AND in_message = 0
ORDER BY filetime DESC, post_msg_id ASC';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$attachments[] = $row;
}
$db->sql_freeresult($result);
if (sizeof($attachments))
{
$update_count = array();
parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
}
// Display not already displayed Attachments for this post, we already parsed them. ;)
if (!empty($attachments))
{
$template->assign_var('S_HAS_ATTACHMENTS', true);
foreach ($attachments as $attachment)
{
$template->assign_block_vars('attachment', array(
'DISPLAY_ATTACHMENT' => $attachment)
);
}
}
}
$post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&p=' . $post_info['post_id'] . '#p' . $post_info['post_id']);
$topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&t=' . $post_info['topic_id']);
$template->assign_vars(array(
'S_MCP_QUEUE' => true,
'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&p=$post_id&f=$forum_id"),
'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']),
'S_POST_REPORTED' => $post_info['post_reported'],
'S_POST_UNAPPROVED' => !$post_info['post_approved'],
'S_POST_LOCKED' => $post_info['post_edit_locked'],
'S_USER_NOTES' => true,
'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '',
'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=report_details&f=' . $post_info['forum_id'] . '&p=' . $post_id),
'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $post_info['user_id']),
'U_MCP_WARN_USER' => ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $post_info['user_id']) : '',
'U_VIEW_POST' => $post_url,
'U_VIEW_TOPIC' => $topic_url,
'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
'RETURN_QUEUE' => sprintf($user->lang['RETURN_QUEUE'], '", ''),
'RETURN_POST' => sprintf($user->lang['RETURN_POST'], '', ''),
'RETURN_TOPIC_SIMPLE' => sprintf($user->lang['RETURN_TOPIC_SIMPLE'], '', ''),
'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
'POST_PREVIEW' => $message,
'POST_SUBJECT' => $post_info['post_subject'],
'POST_DATE' => $user->format_date($post_info['post_time']),
'POST_IP' => $post_info['poster_ip'],
'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
'POST_ID' => $post_info['post_id'],
'U_LOOKUP_IP' => ($auth->acl_get('m_info', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&mode=approve_details&f=' . $post_info['forum_id'] . '&p=' . $post_id . '&lookup=' . $post_info['poster_ip']) . '#ip' : '',
));
break;
case 'unapproved_topics':
case 'unapproved_posts':
$user->add_lang(array('viewtopic', 'viewforum'));
$topic_id = request_var('t', 0);
$forum_info = array();
if ($topic_id)
{
$topic_info = get_topic_data(array($topic_id));
if (!sizeof($topic_info))
{
trigger_error('TOPIC_NOT_EXIST');
}
$topic_info = $topic_info[$topic_id];
$forum_id = $topic_info['forum_id'];
}
$forum_list_approve = get_forum_list('m_approve', false, true);
$forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
// Remove forums we cannot read
foreach ($forum_list_approve as $k => $forum_data)
{
if (!isset($forum_list_read[$forum_data['forum_id']]))
{
unset($forum_list_approve[$k]);
}
}
unset($forum_list_read);
if (!$forum_id)
{
$forum_list = array();
foreach ($forum_list_approve as $row)
{
$forum_list[] = $row['forum_id'];
}
if (!sizeof($forum_list))
{
trigger_error('NOT_MODERATOR');
}
$forum_list = implode(', ', $forum_list);
$sql = 'SELECT SUM(forum_topics) as sum_forum_topics
FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_list);
$result = $db->sql_query($sql);
$forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics');
$db->sql_freeresult($result);
}
else
{
$forum_info = get_forum_data(array($forum_id), 'm_approve');
if (!sizeof($forum_info))
{
trigger_error('NOT_MODERATOR');
}
$forum_info = $forum_info[$forum_id];
$forum_list = $forum_id;
}
$forum_options = '';
foreach ($forum_list_approve as $row)
{
$forum_options .= '';
}
$sort_days = $total = 0;
$sort_key = $sort_dir = '';
$sort_by_sql = $sort_order_sql = array();
mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_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)) : '';
$forum_names = array();
if ($mode == 'unapproved_posts')
{
$sql = 'SELECT p.post_id
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . '
WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . '
AND p.post_approved = 0
' . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
AND t.topic_id = p.topic_id
AND t.topic_first_post_id <> p.post_id
$limit_time_sql
ORDER BY $sort_order_sql";
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
$i = 0;
$post_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$post_ids[] = $row['post_id'];
$row_num[$row['post_id']] = $i++;
}
$db->sql_freeresult($result);
if (sizeof($post_ids))
{
$sql = 'SELECT t.topic_id, t.topic_title, t.forum_id, p.post_id, p.post_subject, p.post_username, p.poster_id, p.post_time, u.username, u.username_clean, u.user_colour
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
WHERE ' . $db->sql_in_set('p.post_id', $post_ids) . '
AND t.topic_id = p.topic_id
AND u.user_id = p.poster_id
ORDER BY ' . $sort_order_sql;
$result = $db->sql_query($sql);
$post_data = $rowset = array();
while ($row = $db->sql_fetchrow($result))
{
$forum_names[] = $row['forum_id'];
$post_data[$row['post_id']] = $row;
}
$db->sql_freeresult($result);
foreach ($post_ids as $post_id)
{
$rowset[] = $post_data[$post_id];
}
unset($post_data, $post_ids);
}
else
{
$rowset = array();
}
}
else
{
$sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, t.topic_title AS post_subject, t.topic_time AS post_time, t.topic_poster AS poster_id, t.topic_first_post_id AS post_id, t.topic_first_poster_name AS username, t.topic_first_poster_colour AS user_colour
FROM ' . TOPICS_TABLE . " t
WHERE " . $db->sql_in_set('forum_id', $forum_list) . "
AND topic_approved = 0
$limit_time_sql
ORDER BY $sort_order_sql";
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
$rowset = array();
while ($row = $db->sql_fetchrow($result))
{
$forum_names[] = $row['forum_id'];
$rowset[] = $row;
}
$db->sql_freeresult($result);
}
if (sizeof($forum_names))
{
// Select the names for the forum_ids
$sql = 'SELECT forum_id, forum_name
FROM ' . FORUMS_TABLE . '
WHERE ' . $db->sql_in_set('forum_id', $forum_names);
$result = $db->sql_query($sql, 3600);
$forum_names = array();
while ($row = $db->sql_fetchrow($result))
{
$forum_names[$row['forum_id']] = $row['forum_name'];
}
$db->sql_freeresult($result);
}
foreach ($rowset as $row)
{
if (empty($row['post_username']))
{
$row['post_username'] = $user->lang['GUEST'];
}
$template->assign_block_vars('postrow', array(
'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&t=' . $row['topic_id']),
'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
'U_VIEWPOST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&p=' . $row['post_id']) . (($mode == 'unapproved_posts') ? '#p' . $row['post_id'] : ''),
'U_VIEW_DETAILS' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=queue&start=$start&mode=approve_details&f={$row['forum_id']}&p={$row['post_id']}" . (($mode == 'unapproved_topics') ? "&t={$row['topic_id']}" : '')),
'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
'POST_ID' => $row['post_id'],
'FORUM_NAME' => $forum_names[$row['forum_id']],
'POST_SUBJECT' => ($row['post_subject'] != '') ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
'TOPIC_TITLE' => $row['topic_title'],
'POST_TIME' => $user->format_date($row['post_time']))
);
}
unset($rowset, $forum_names);
// Now display the page
$template->assign_vars(array(
'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'],
'L_EXPLAIN' => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS_EXPLAIN'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS_EXPLAIN'],
'L_TITLE' => ($mode == 'unapproved_posts') ? $user->lang['MCP_QUEUE_UNAPPROVED_POSTS'] : $user->lang['MCP_QUEUE_UNAPPROVED_TOPICS'],
'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
'S_FORUM_OPTIONS' => $forum_options,
'S_MCP_ACTION' => build_url(array('t', 'f', 'sd', 'st', 'sk')),
'S_TOPICS' => ($mode == 'unapproved_posts') ? false : true,
'PAGINATION' => generate_pagination($this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir", $total, $config['topics_per_page'], $start),
'PAGE_NUMBER' => on_page($total, $config['topics_per_page'], $start),
'TOPIC_ID' => $topic_id,
'TOTAL' => ($total == 1) ? (($mode == 'unapproved_posts') ? $user->lang['VIEW_TOPIC_POST'] : $user->lang['VIEW_FORUM_TOPIC']) : sprintf((($mode == 'unapproved_posts') ? $user->lang['VIEW_TOPIC_POSTS'] : $user->lang['VIEW_FORUM_TOPICS']), $total),
));
$this->tpl_name = 'mcp_queue';
break;
}
}
}
/**
* Approve Post/Topic
*/
function approve_post($post_id_list, $id, $mode)
{
global $db, $template, $user, $config;
global $phpEx, $phpbb_root_path;
if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
{
trigger_error('NOT_AUTHORISED');
}
$redirect = request_var('redirect', build_url(array('quickmod')));
$success_msg = '';
$s_hidden_fields = build_hidden_fields(array(
'i' => $id,
'mode' => $mode,
'post_id_list' => $post_id_list,
'action' => 'approve',
'redirect' => $redirect)
);
$post_info = get_post_data($post_id_list, 'm_approve');
if (confirm_box(true))
{
$notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
// If Topic -> total_topics = total_topics+1, total_posts = total_posts+1, forum_topics = forum_topics+1, forum_posts = forum_posts+1
// If Post -> total_posts = total_posts+1, forum_posts = forum_posts+1, topic_replies = topic_replies+1
$total_topics = $total_posts = 0;
$topic_approve_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
$user_posts_sql = $post_approved_list = array();
foreach ($post_info as $post_id => $post_data)
{
if ($post_data['post_approved'])
{
$post_approved_list[] = $post_id;
continue;
}
$topic_id_list[$post_data['topic_id']] = 1;
$forum_id_list[$post_data['forum_id']] = 1;
// User post update (we do not care about topic or post, since user posts are strictly connected to posts)
// But we care about forums where post counts get not increased. ;)
if ($post_data['post_postcount'])
{
$user_posts_sql[$post_data['poster_id']] = (empty($user_posts_sql[$post_data['poster_id']])) ? 1 : $user_posts_sql[$post_data['poster_id']] + 1;
}
// Topic or Post. ;)
if ($post_data['topic_first_post_id'] == $post_id)
{
$total_topics++;
$topic_approve_sql[] = $post_data['topic_id'];
$approve_log[] = array(
'type' => 'topic',
'post_subject' => $post_data['post_subject'],
'forum_id' => $post_data['forum_id'],
'topic_id' => $post_data['topic_id'],
);
}
else
{
$approve_log[] = array(
'type' => 'post',
'post_subject' => $post_data['post_subject'],
'forum_id' => $post_data['forum_id'],
'topic_id' => $post_data['topic_id'],
);
}
$total_posts++;
// Increment by topic_replies if we approve a topic...
// This works because we do not adjust the topic_replies when re-approving a topic after an edit.
if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_replies'])
{
$total_posts += $post_data['topic_replies'];
}
$post_approve_sql[] = $post_id;
}
$post_id_list = array_values(array_diff($post_id_list, $post_approved_list));
for ($i = 0, $size = sizeof($post_approved_list); $i < $size; $i++)
{
unset($post_info[$post_approved_list[$i]]);
}
if (sizeof($topic_approve_sql))
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_approved = 1
WHERE ' . $db->sql_in_set('topic_id', $topic_approve_sql);
$db->sql_query($sql);
}
if (sizeof($post_approve_sql))
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_approved = 1
WHERE ' . $db->sql_in_set('post_id', $post_approve_sql);
$db->sql_query($sql);
}
unset($topic_approve_sql, $post_approve_sql);
foreach ($approve_log as $log_data)
{
add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_APPROVED' : 'LOG_POST_APPROVED', $log_data['post_subject']);
}
if (sizeof($user_posts_sql))
{
// Try to minimize the query count by merging users with the same post count additions
$user_posts_update = array();
foreach ($user_posts_sql as $user_id => $user_posts)
{
$user_posts_update[$user_posts][] = $user_id;
}
foreach ($user_posts_update as $user_posts => $user_id_ary)
{
$sql = 'UPDATE ' . USERS_TABLE . '
SET user_posts = user_posts + ' . $user_posts . '
WHERE ' . $db->sql_in_set('user_id', $user_id_ary);
$db->sql_query($sql);
}
}
if ($total_topics)
{
set_config_count('num_topics', $total_topics, true);
}
if ($total_posts)
{
set_config_count('num_posts', $total_posts, true);
}
sync('topic', 'topic_id', array_keys($topic_id_list), true);
sync('forum', 'forum_id', array_keys($forum_id_list), true, true);
unset($topic_id_list, $forum_id_list);
$messenger = new messenger();
// Notify Poster?
if ($notify_poster)
{
foreach ($post_info as $post_id => $post_data)
{
if ($post_data['poster_id'] == ANONYMOUS)
{
continue;
}
$email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_approved' : 'post_approved';
$messenger->template($email_template, $post_data['user_lang']);
$messenger->to($post_data['user_email'], $post_data['username']);
$messenger->im($post_data['user_jabber'], $post_data['username']);
$messenger->assign_vars(array(
'USERNAME' => htmlspecialchars_decode($post_data['username']),
'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])),
'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])),
'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&e=0",
'U_VIEW_POST' => generate_board_url() . "/viewtopic.$phpEx?f={$post_data['forum_id']}&t={$post_data['topic_id']}&p=$post_id&e=$post_id")
);
$messenger->send($post_data['user_notify_type']);
}
}
$messenger->save_queue();
// Send out normal user notifications
$email_sig = str_replace('
', "\n", "-- \n" . $config['board_email_sig']);
foreach ($post_info as $post_id => $post_data)
{
if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id'])
{
// Forum Notifications
user_notification('post', $post_data['topic_title'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id);
}
else
{
// Topic Notifications
user_notification('reply', $post_data['post_subject'], $post_data['topic_title'], $post_data['forum_name'], $post_data['forum_id'], $post_data['topic_id'], $post_id);
}
}
if (sizeof($post_id_list) == 1)
{
$post_data = $post_info[$post_id_list[0]];
$post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f={$post_data['forum_id']}&t={$post_data['topic_id']}&p={$post_data['post_id']}") . '#p' . $post_data['post_id'];
}
unset($post_info);
if ($total_topics)
{
$success_msg = ($total_topics == 1) ? 'TOPIC_APPROVED_SUCCESS' : 'TOPICS_APPROVED_SUCCESS';
}
else
{
$success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
}
}
else
{
$show_notify = false;
if ($config['email_enable'] || $config['jab_enable'])
{
foreach ($post_info as $post_data)
{
if ($post_data['poster_id'] == ANONYMOUS)
{
continue;
}
else
{
$show_notify = true;
break;
}
}
}
$template->assign_vars(array(
'S_NOTIFY_POSTER' => $show_notify,
'S_APPROVE' => true)
);
confirm_box(false, 'APPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
}
$redirect = request_var('redirect', "index.$phpEx");
$redirect = reapply_sid($redirect);
if (!$success_msg)
{
redirect($redirect);
}
else
{
meta_refresh(3, $redirect);
// If approving one post, also give links back to post...
$add_message = '';
if (sizeof($post_id_list) == 1 && !empty($post_url))
{
$add_message = '
' . sprintf($user->lang['RETURN_POST'], '', '');
}
trigger_error($user->lang[$success_msg] . '
' . sprintf($user->lang['RETURN_PAGE'], "", '') . $add_message);
}
}
/**
* Disapprove Post/Topic
*/
function disapprove_post($post_id_list, $id, $mode)
{
global $db, $template, $user, $config;
global $phpEx, $phpbb_root_path;
global $request;
if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve')))
{
trigger_error('NOT_AUTHORISED');
}
$redirect = request_var('redirect', build_url(array('t', 'mode', 'quickmod')) . "&mode=$mode");
$reason = utf8_normalize_nfc(request_var('reason', '', true));
$reason_id = request_var('reason_id', 0);
$success_msg = $additional_msg = '';
$s_hidden_fields = build_hidden_fields(array(
'i' => $id,
'mode' => $mode,
'post_id_list' => $post_id_list,
'action' => 'disapprove',
'redirect' => $redirect)
);
$notify_poster = (isset($_REQUEST['notify_poster'])) ? true : false;
$disapprove_reason = '';
if ($reason_id)
{
$sql = 'SELECT reason_title, reason_description
FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_id = $reason_id";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$row || (!$reason && strtolower($row['reason_title']) == 'other'))
{
$additional_msg = $user->lang['NO_REASON_DISAPPROVAL'];
$request->overwrite('confirm', null, phpbb_request_interface::POST);
}
else
{
// If the reason is defined within the language file, we will use the localized version, else just use the database entry...
$disapprove_reason = (strtolower($row['reason_title']) != 'other') ? ((isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) ? $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description']) : '';
$disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
if (isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
{
$disapprove_reason_lang = strtoupper($row['reason_title']);
}
$email_disapprove_reason = $disapprove_reason;
}
}
$post_info = get_post_data($post_id_list, 'm_approve');
if (confirm_box(true))
{
$disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array();
$topic_replies_real = $post_disapprove_list = array();
// Build a list of posts to be unapproved and get the related topics real replies count
foreach ($post_info as $post_id => $post_data)
{
$post_disapprove_list[$post_id] = $post_data['topic_id'];
if (!isset($topic_replies_real[$post_data['topic_id']]))
{
$topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real'];
}
}
// Now we build the log array
foreach ($post_disapprove_list as $post_id => $topic_id)
{
// If the count of disapproved posts for the topic is greater
// than topic's real replies count, the whole topic is disapproved/deleted
if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id])
{
// Don't write the log more than once for every topic
if (!isset($disapprove_log_topics[$topic_id]))
{
// Build disapproved topics log
$disapprove_log_topics[$topic_id] = array(
'type' => 'topic',
'post_subject' => $post_info[$post_id]['topic_title'],
'forum_id' => $post_info[$post_id]['forum_id'],
'topic_id' => 0, // useless to log a topic id, as it will be deleted
);
}
}
else
{
// Build disapproved posts log
$disapprove_log_posts[] = array(
'type' => 'post',
'post_subject' => $post_info[$post_id]['post_subject'],
'forum_id' => $post_info[$post_id]['forum_id'],
'topic_id' => $post_info[$post_id]['topic_id'],
);
}
}
// Get disapproved posts/topics counts separately
$num_disapproved_topics = sizeof($disapprove_log_topics);
$num_disapproved_posts = sizeof($disapprove_log_posts);
// Build the whole log
$disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
// Unset unneeded arrays
unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
// Let's do the job - delete disapproved posts
if (sizeof($post_disapprove_list))
{
if (!function_exists('delete_posts'))
{
include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
}
// We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
// Note: function delete_posts triggers related forums/topics sync,
// so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
delete_posts('post_id', array_keys($post_disapprove_list));
foreach ($disapprove_log as $log_data)
{
add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_DISAPPROVED' : 'LOG_POST_DISAPPROVED', $log_data['post_subject'], $disapprove_reason);
}
}
$messenger = new messenger();
// Notify Poster?
if ($notify_poster)
{
$lang_reasons = array();
foreach ($post_info as $post_id => $post_data)
{
if ($post_data['poster_id'] == ANONYMOUS)
{
continue;
}
if (isset($disapprove_reason_lang))
{
// Okay we need to get the reason from the posters language
if (!isset($lang_reasons[$post_data['user_lang']]))
{
// Assign the current users translation as the default, this is not ideal but getting the board default adds another layer of complexity.
$lang_reasons[$post_data['user_lang']] = $user->lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
// Only load up the language pack if the language is different to the current one
if ($post_data['user_lang'] != $user->lang_name && file_exists($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx))
{
// Load up the language pack
$lang = array();
@include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
// If we find the reason in this language pack use it
if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
{
$lang_reasons[$post_data['user_lang']] = $lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang];
}
unset($lang); // Free memory
}
}
$email_disapprove_reason = $lang_reasons[$post_data['user_lang']];
$email_disapprove_reason .= ($reason) ? "\n\n" . $reason : '';
}
$email_template = ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) ? 'topic_disapproved' : 'post_disapproved';
$messenger->template($email_template, $post_data['user_lang']);
$messenger->to($post_data['user_email'], $post_data['username']);
$messenger->im($post_data['user_jabber'], $post_data['username']);
$messenger->assign_vars(array(
'USERNAME' => htmlspecialchars_decode($post_data['username']),
'REASON' => htmlspecialchars_decode($email_disapprove_reason),
'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_data['post_subject'])),
'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_data['topic_title'])))
);
$messenger->send($post_data['user_notify_type']);
}
unset($lang_reasons);
}
unset($post_info, $disapprove_reason, $email_disapprove_reason, $disapprove_reason_lang);
$messenger->save_queue();
if ($num_disapproved_topics)
{
$success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
}
else
{
$success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
}
}
else
{
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
display_reasons($reason_id);
$show_notify = false;
foreach ($post_info as $post_data)
{
if ($post_data['poster_id'] == ANONYMOUS)
{
continue;
}
else
{
$show_notify = true;
break;
}
}
$template->assign_vars(array(
'S_NOTIFY_POSTER' => $show_notify,
'S_APPROVE' => false,
'REASON' => $reason,
'ADDITIONAL_MSG' => $additional_msg)
);
confirm_box(false, 'DISAPPROVE_POST' . ((sizeof($post_id_list) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html');
}
$redirect = request_var('redirect', "index.$phpEx");
$redirect = reapply_sid($redirect);
if (!$success_msg)
{
redirect($redirect);
}
else
{
meta_refresh(3, $redirect);
trigger_error($user->lang[$success_msg] . '
' . sprintf($user->lang['RETURN_PAGE'], "", ''));
}
}
810' href='#n810'>810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
package install_steps;
use diagnostics;
use strict;
use vars qw(@filesToSaveForUpgrade);
#-######################################################################################
#- misc imports
#-######################################################################################
use common qw(:file :system :common :functional);
use install_any qw(:all);
use install_interactive;
use partition_table qw(:types);
use detect_devices;
use modules;
use run_program;
use lang;
use raid;
use keyboard;
use log;
use fsedit;
use loopback;
use commands;
use network;
use any;
use fs;
@filesToSaveForUpgrade = qw(
/etc/ld.so.conf /etc/fstab /etc/hosts /etc/conf.modules /etc/modules.conf
);
#-######################################################################################
#- OO Stuff
#-######################################################################################
sub new($$) {
my ($type, $o) = @_;
bless $o, ref $type || $type;
return $o;
}
#-######################################################################################
#- In/Out Steps Functions
#-######################################################################################
sub enteringStep {
my ($o, $step) = @_;
log::l("starting step `$step'");
}
sub leavingStep {
my ($o, $step) = @_;
log::l("step `$step' finished");
if (-d "$o->{prefix}/root") {
eval { commands::cp('-f', "/tmp/ddebug.log", "$o->{prefix}/root") };
install_any::g_auto_install();
}
for (my $s = $o->{steps}{first}; $s; $s = $o->{steps}{$s}{next}) {
#- the reachability property must be recomputed each time to take
#- into account failed step.
next if $o->{steps}{$s}{done} && !$o->{steps}{$s}{redoable};
my $reachable = 1;
if (my $needs = $o->{steps}{$s}{needs}) {
my @l = ref $needs ? @$needs : $needs;
$reachable = min(map { $o->{steps}{$_}{done} || 0 } @l);
}
$o->{steps}{$s}{reachable} = 1 if $reachable;
}
$o->{steps}{$step}{reachable} = $o->{steps}{$step}{redoable};
while (my $f = shift @{$o->{steps}{$step}{toBeDone} || []}) {
eval { &$f() };
$o->ask_warn(_("Error"), [
_("An error occurred, but I don't know how to handle it nicely.
Continue at your own risk."), $@ ]) if $@;
}
}
sub errorInStep($$) { print "error :(\n"; c::_exit(1) }
sub kill_action {}
sub set_help { 1 }
#-######################################################################################
#- Steps Functions
#-######################################################################################
#------------------------------------------------------------------------------
sub selectLanguage {
my ($o) = @_;
lang::set($o->{lang});
$o->{langs} ||= [ $o->{lang} ];
if ($o->{keyboard_unsafe} || !$o->{keyboard}) {
$o->{keyboard_unsafe} = 1;
$o->{keyboard} = keyboard::lang2keyboard($o->{lang});
selectKeyboard($o);
}
}
#------------------------------------------------------------------------------
sub selectKeyboard {
my ($o) = @_;
keyboard::setup($o->{keyboard});
lang::set_langs($o->{langs});
}
#------------------------------------------------------------------------------
sub selectPath {}
#------------------------------------------------------------------------------
sub selectInstallClass($@) {
my ($o) = @_;
$o->{installClass} ||= $::corporate ? "corporate" : "normal";
$o->{security} ||= ${{
normal => 2,
developer => 3,
corporate => 3,
server => 4,
}}{$o->{installClass}};
}
#------------------------------------------------------------------------------
sub setupSCSI {
modules::load_ide();
modules::load_thiskind('scsi|disk');
}
#------------------------------------------------------------------------------
sub doPartitionDisksBefore {
my ($o) = @_;
if (cat_("/proc/mounts") =~ m|/\w+/(\S+)\s+/tmp/hdimage\s+(\S+)| && !$o->{partitioning}{readonly}) {
$o->{stage1_hd} = { device => $1, type => $2 };
install_any::getFile("XXX"); #- close still opened filehandle
eval { fs::umount("/tmp/hdimage") };
}
eval { fs::umount_all($o->{fstab}, $o->{prefix}) } if $o->{fstab} && !$::testing && !$::live;
$o->{raid} ||= {};
}
#------------------------------------------------------------------------------
sub doPartitionDisksAfter {
my ($o) = @_;
unless ($::testing) {
partition_table::write($_) foreach @{$o->{hds}};
$_->{rebootNeeded} and $o->rebootNeeded foreach @{$o->{hds}};
}
$o->{fstab} = [ fsedit::get_fstab(@{$o->{hds}}, $o->{raid}) ];
fsedit::get_root($o->{fstab}) or die "Oops, no root partition";
if (my $s = delete $o->{stage1_hd}) {
my ($part) = grep { $_->{device} eq $s->{device} } @{$o->{fstab}};
$part->{isMounted} ?
do { rmdir "/tmp/hdimage" ; symlinkf("$o->{prefix}$part->{mntpoint}", "/tmp/hdimage") } :
eval { fs::mount($s->{device}, "/tmp/hdimage", $s->{type}) };
}
cat_("/proc/mounts") =~ m|(\S+)\s+/tmp/rhimage nfs| &&
!grep { $_->{mntpoint} eq "/mnt/nfs" } @{$o->{manualFstab} || []} and
push @{$o->{manualFstab}}, { type => "nfs", mntpoint => "/mnt/nfs", device => $1, options => "noauto,ro,nosuid,rsize=8192,wsize=8192" };
}
#------------------------------------------------------------------------------
sub doPartitionDisks {
my ($o) = @_;
install_any::getHds($o);
if ($o->{isUpgrade}) {
# either one root is defined (and all is ok), or we take the first one we find
my $p = fsedit::get_root($o->{fstab}) || first(install_any::find_root_parts($o->{hds}, $o->{prefix})) or die;
install_any::use_root_part($o->{fstab}, $p, $o->{prefix});
} elsif ($o->{partitioning}{auto_allocate}) {
fsedit::auto_allocate($o->{hds}, $o->{partitions});
}
}
#------------------------------------------------------------------------------
sub ask_mntpoint_s {
my ($o, $fstab) = @_;
#- TODO: set the mntpoints
#- assure type is at least ext2
(fsedit::get_root($fstab) || {})->{type} = 0x83;
my %m; foreach (@$fstab) {
my $m = $_->{mntpoint};
next unless $m && $m ne 'swap'; #- there may be a lot of swap.
$m{$m} and die _("Duplicate mount point %s", $m);
$m{$m} = 1;
#- in case the type does not correspond, force it to ext2
$_->{type} = 0x83 if $m =~ m|^/| && !isFat($_);
}
1;
}
sub rebootNeeded($) {
my ($o) = @_;
log::l("Rebooting...");
c::_exit(0);
}
sub choosePartitionsToFormat($$) {
my ($o, $fstab) = @_;
foreach (@$fstab) {
$_->{mntpoint} = "swap" if isSwap($_);
$_->{mntpoint} or next;
add2hash_($_, { toFormat => $_->{notFormatted} });
if (!$_->{toFormat}) {
my $t = isLoopback($_) ?
eval { fsedit::typeOfPart($o->{prefix} . loopback::file($_)) } :
fsedit::typeOfPart($_->{device});
$_->{toFormatUnsure} = $_->{mntpoint} eq "/" ||
#- if detected dos/win, it's not precise enough to just compare the types (too many of them)
(!$t || isOtherAvailableFS({ type => $t }) ? !isOtherAvailableFS($_) : $t != $_->{type});
}
}
}
sub formatMountPartitions {
my ($o) = @_;
fs::formatMount_all($o->{raid}, $o->{fstab}, $o->{prefix});
}
#------------------------------------------------------------------------------
sub setPackages {
my ($o) = @_;
install_any::setPackages($o);
}
sub selectPackagesToUpgrade {
my ($o) = @_;
pkgs::selectPackagesToUpgrade($o->{packages}, $o->{prefix}, $o->{base}, $o->{toRemove}, $o->{toSave});
}
sub choosePackages {
my ($o, $packages, $compss, $compssUsers, $compssUsersSorted, $first_time) = @_;
#- now for upgrade, package that must be upgraded are
#- selected first, after is used the same scheme as install.
#- make sure we kept some space left for available else the system may
#- not be able to start (xfs at least).
my $available = install_any::getAvailableSpace($o);
my $availableCorrected = pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024);
log::l("available size $available (corrected $availableCorrected)");
foreach (values %{$packages->[0]}) {
pkgs::packageSetFlagSkip($_, 0);
pkgs::packageSetFlagUnskip($_, 0);
}
#- avoid destroying user selection of packages. TOCHECK
if ($first_time) {
pkgs::unselectAllPackages($packages);
pkgs::selectPackage($o->{packages}, pkgs::packageByName($o->{packages}, $_) || next) foreach @{$o->{default_packages}};
add2hash_($o, { compssListLevel => $::expert ? 90 : 80 }) unless $::auto_install;
pkgs::setSelectedFromCompssList($o->{compssListLevels}, $packages, $o->{compssListLevel}, $availableCorrected, $o->{installClass}) if exists $o->{compssListLevel};
}
$availableCorrected;
}
sub beforeInstallPackages {
my ($o) = @_;
#- save these files in case of upgrade failure.
if ($o->{isUpgrade}) {
foreach (@filesToSaveForUpgrade) {
unlink "$o->{prefix}/$_.mdkgisave";
if (-e "$o->{prefix}/$_") {
eval { commands::cp("$o->{prefix}/$_", "$o->{prefix}/$_.mdkgisave") };
}
}
}
#- some packages need such files for proper installation.
any::writeandclean_ldsoconf($o->{prefix});
$::live or fs::write($o->{prefix}, $o->{fstab}, $o->{manualFstab}, $o->{useSupermount});
network::add2hosts("$o->{prefix}/etc/hosts", "localhost.localdomain", "127.0.0.1");
require pkgs;
pkgs::init_db($o->{prefix}, $o->{isUpgrade});
}
sub pkg_install {
my ($o, @l) = @_;
require pkgs;
pkgs::selectPackage($o->{packages}, pkgs::packageByName($o->{packages}, $_) || die "$_ rpm not found") foreach @l;
$o->installPackages;
}
sub pkg_install_if_requires_satisfied {
my ($o, @l) = @_;
require pkgs;
foreach (@l) {
my %newSelection;
my $pkg = pkgs::packageByName($o->{packages}, $_) || die "$_ rpm not found";
pkgs::selectPackage($o->{packages}, $pkg, 0, \%newSelection) foreach @l;
scalar(keys %newSelection) == 1 and pkgs::selectPackage($o->{packages}, $pkg);
}
$o->installPackages;
}
sub installPackages($$) { #- complete REWORK, TODO and TOCHECK!
my ($o) = @_;
my $packages = $o->{packages};
if (@{$o->{toRemove} || []}) {
#- hack to ensure proper upgrade of packages from other distribution,
#- as release number are not mandrake based. this causes save of
#- important files and restore them after.
foreach (@{$o->{toSave} || []}) {
if (-e "$o->{prefix}/$_") {
unlink "$o->{prefix}/$_.mdkgisave"; eval { commands::cp("$o->{prefix}/$_", "$o->{prefix}/$_.mdkgisave") };
}
}
pkgs::remove($o->{prefix}, $o->{toRemove});
foreach (@{$o->{toSave} || []}) {
if (-e "$o->{prefix}/$_.mdkgisave") {
unlink "$o->{prefix}/$_"; rename "$o->{prefix}/$_.mdkgisave", "$o->{prefix}/$_";
}
}
$o->{toSave} = [];
#- hack for compat-glibc to upgrade properly :-(
if (pkgs::packageFlagSelected(pkgs::packageByName($packages, 'compat-glibc')) &&
!pkgs::packageFlagInstalled(pkgs::packageByName($packages, 'compat-glibc'))) {
rename "$o->{prefix}/usr/i386-glibc20-linux", "$o->{prefix}/usr/i386-glibc20-linux.mdkgisave";
}
}
#- small transaction will be built based on this selection and depslist.
my @toInstall = pkgs::packagesToInstall($packages);
my $time = time;
$ENV{DURING_INSTALL} = 1;
pkgs::install($o->{prefix}, $o->{isUpgrade}, \@toInstall, $packages->[1], $packages->[2]);
delete $ENV{DURING_INSTALL};
run_program::rooted($o->{prefix}, 'ldconfig') or die "ldconfig failed!";
log::l("Install took: ", formatTime(time - $time));
}
sub afterInstallPackages($) {
my ($o) = @_;
return if $::g_auto_install;
die _("Some important packages didn't get installed properly.
Either your cdrom drive or your cdrom is defective.
Check the cdrom on an installed computer using \"rpm -qpl Mandrake/RPMS/*.rpm\"
") if grep { m|read failed: Input/output error| } cat_("$o->{prefix}/root/install.log");
if (arch() !~ /^sparc/) { #- TODO restore it as may be needed for sparc
-x "$o->{prefix}/usr/bin/dumpkeys" or $::testing or die
"Some important packages didn't get installed properly.
Please switch to console 2 (using ctrl-alt-f2)
and look at the log file /tmp/ddebug.log
Consoles 1,3,4,7 may also contain interesting information";
}
pkgs::done_db();
#- why not? cuz weather is nice today :-) [pixel]
sync(); sync();
#- configure PCMCIA services if needed.
$o->pcmciaConfig();
#- for mandrake_firstime
touch "$o->{prefix}/var/lock/TMP_1ST";
#- remove the nasty acon...
run_program::rooted($o->{prefix}, "chkconfig", "--del", "acon") unless $ENV{LANGUAGE} =~ /ar/;
#- make the mdk fonts last in available fonts for buggy kde
run_program::rooted($o->{prefix}, "chkfontpath", "--remove", "/usr/X11R6/lib/X11/fonts/mdk");
run_program::rooted($o->{prefix}, "chkfontpath", "--add", "/usr/X11R6/lib/X11/fonts/mdk");
#- call update-menus at the end of package installation
run_program::rooted($o->{prefix}, "update-menus");
#- create /etc/sysconfig/desktop file according to user choice and presence of /usr/bin/kdm or /usr/bin/gdm.
my $f = "$o->{prefix}/etc/sysconfig/desktop";
if ($o->{compssUsersChoice}{KDE} && -x "$o->{prefix}/usr/bin/kdm") {
log::l("setting desktop to KDE");
output($f, "KDE\n");
} elsif ($o->{compssUsersChoice}{Gnome} && -x "$o->{prefix}/usr/bin/gdm") {
log::l("setting desktop to GNOME");
output($f, "GNOME\n");
}
if ($o->{pcmcia}) {
substInFile { s/.*(TaskBarShowAPMStatus).*/$1=1/ } "$o->{prefix}/usr/lib/X11/icewm/preferences";
eval { commands::cp("$o->{prefix}/usr/share/applnk/System/kapm.kdelnk",
"$o->{prefix}/etc/skel/Desktop/Autostart/kapm.kdelnk") };
}
my $msec = "$o->{prefix}/etc/security/msec";
substInFile { s/^xgrp\n//; $_ .= "xgrp\n" if eof } "$msec/group.conf" if -d $msec;
substInFile { s/^audio\n//; $_ .= "audio\n" if eof } "$msec/group.conf" if -d $msec;
substInFile { s/^cdrom\n//; $_ .= "cdrom\n" if eof } "$msec/group.conf" if -d $msec;
substInFile { s/^cdwriter\n//; $_ .= "cdwriter\n" if eof } "$msec/group.conf" if -d $msec;
my $pkg = pkgs::packageByName($o->{packages}, 'urpmi');
if ($pkg && pkgs::packageFlagSelected($pkg)) {
install_any::install_urpmi($o->{prefix}, $o->{method}, $o->{packages}[2]);
substInFile { s/^urpmi\n//; $_ .= "urpmi\n" if eof } "$msec/group.conf" if -d $msec;
}
#- update language and icons for KDE.
update_userkderc($o->{prefix}, 'Locale', Language => "");
log::l("updating kde icons according to available devices");
install_any::kdeicons_postinstall($o->{prefix});
my $welcome = _("Welcome to %s", "[HOSTNAME]");
substInFile { s/^(GreetString)=.*/$1=$welcome/ } "$o->{prefix}/usr/share/config/kdmrc";
substInFile { s/^(UserView)=false/$1=true/ } "$o->{prefix}/usr/share/config/kdmrc" if $o->{security} < 3;
run_program::rooted($o->{prefix}, "kdeDesktopCleanup");
#- konsole and gnome-terminal are lamers in exotic languages, link them to something better
if ($o->{lang} =~ /ja|ko|zh/) {
foreach ("konsole", "gnome-terminal") {
my $f = "$o->{prefix}/usr/bin/$_";
symlinkf("X11/rxvt.sh", $f) if -e $f;
}
}
#- my $hasttf;
#- my $dest = "/usr/X11R6/lib/X11/fonts/drakfont";
#- foreach my $d (map { $_->{mntpoint} } grep { isFat($_) } @{$o->{fstab}}) {
#- foreach my $D (map { "$d/$_" } grep { m|^win|i } all("$o->{prefix}$d")) {
#- $D .= "/fonts";
#- -d "$o->{prefix}$D" or next;
#- log::l("found win font dir $D");
#- if (!$hasttf) {
#- $hasttf = $o->ask_okcancel('',
#-_("Some true type fonts from windows have been found on your computer.
#-Do you want to use them? Be sure you have the right to use them under Linux."), 1) or goto nottf;
#- mkdir "$o->{prefix}$dest", 0755;
#- }
#- /(.*)\.ttf/i and symlink "$D/$_", "$o->{prefix}$dest/$1.ttf" foreach grep { /\.ttf/i } all("$o->{prefix}$D");
#- }
#- }
#- nottf:
#- if ($hasttf) {
#- run_program::rooted($o->{prefix}, "ttmkfdir", "-d", $dest, "-o", "$dest/fonts.dir");
#- run_program::rooted($o->{prefix}, "chkfontpath", "--add", $dest);
#- }
foreach (list_skels($o->{prefix}, '.kde/share/config/kfmrc')) {
my $found;
substInFile {
$found ||= /KFM Misc Defaults/;
$_ .=
"[KFM Misc Defaults]
GridWidth=85
GridHeight=70
" if eof && !$found;
} $_
}
#- move some file after an upgrade that may be seriously annoying.
#- and rename saved files to .mdkgiorig.
if ($o->{isUpgrade}) {
log::l("moving previous desktop files that have been updated to Trash of each user");
install_any::kdemove_desktop_file($o->{prefix});
foreach (@filesToSaveForUpgrade) {
if (-e "$o->{prefix}$_.mdkgisave") {
unlink "$o->{prefix}$_.mdkgiorig"; rename "$o->{prefix}/$_.mdkgisave", "$o->{prefix}/$_.mdkgiorig";
}
}
}
}
#------------------------------------------------------------------------------
sub selectMouse($) {
my ($o) = @_;
}
#------------------------------------------------------------------------------
sub configureNetwork {
my ($o) = @_;
network::configureNetwork2($o, $o->{prefix}, $o->{netc}, $o->{intf});
}
#------------------------------------------------------------------------------
sub installCrypto {
my ($o) = @_;
my $u = $o->{crypto} or return; $u->{mirror} && $u->{packages} or return;
upNetwork($o);
require crypto;
my @crypto_packages = crypto::getPackages($o->{prefix}, $o->{packages}, $u->{mirror});
$o->pkg_install(@{$u->{packages}});
}
#------------------------------------------------------------------------------
sub pcmciaConfig($) {
my ($o) = @_;
my $t = $o->{pcmcia};
#- should be set after installing the package above else the file will be renamed.
setVarsInSh("$o->{prefix}/etc/sysconfig/pcmcia", {
PCMCIA => $t ? "yes" : "no",
PCIC => $t,
PCIC_OPTS => "",
CORE_OPTS => "",
});
}
#------------------------------------------------------------------------------
sub configureTimezone {
my ($o, $f) = @_;
require timezone;
timezone::write($o->{prefix}, $o->{timezone}, $f);
}
#------------------------------------------------------------------------------
sub configureServices {
my ($o) = @_;
require services;
services::doit($o, $o->{services}, $o->{prefix}) if $o->{services};
}
#------------------------------------------------------------------------------
sub configurePrinter {
my($o) = @_;
my ($use_cups, $use_lpr) = (0, 0);
foreach (values %{$o->{printer}{configured} || {}}) {
for ($_->{mode}) {
/cups/ and $use_cups++;
/lpr/ and $use_lpr++;
}
}
#- if at least one queue is configured, configure it.
if ($use_cups || $use_lpr) {
$o->pkg_install(($use_cups ? ('cups-drivers') : ()), ($use_lpr ? ('rhs-printfilters') : ()));
require printer;
eval { add2hash($o->{printer}, printer::getinfo($o->{prefix})) }; #- get existing configuration.
$use_cups and printer::poll_ppd_base();
$use_lpr and printer::read_printer_db();
foreach (keys %{$o->{printer}{configured} || {}}) {
log::l("configuring printer queue $_->{queue} for $_->{mode}");
printer::copy_printer_params($_, $o->{printer});
#- setup all configured queues, which is not the case interactively where
#- only the working queue is setup on configuration.
printer::configure_queue($o->{printer});
}
}
}
#------------------------------------------------------------------------------
my @etc_pass_fields = qw(name pw uid gid realname home shell);
sub setRootPassword($) {
my ($o) = @_;
my $p = $o->{prefix};
my $u = $o->{superuser} ||= {};
$u->{pw} ||= $u->{password} && any::crypt($u->{password}, $o->{authentication}{md5});
my @lines = cat_(my $f = "$p/etc/passwd") or log::l("missing passwd file"), return;
local *F;
open F, "> $f" or die "failed to write file $f: $!\n";
foreach (@lines) {
if (/^root:/) {
chomp;
my %l; @l{@etc_pass_fields} = split ':';
add2hash($u, \%l);
$_ = join(':', @$u{@etc_pass_fields}) . "\n";
}
print F $_;
}
}
#------------------------------------------------------------------------------
sub addUser($) {
my ($o) = @_;
my $p = $o->{prefix};
my (%uids, %gids);
foreach (glob_("$p/home")) { my ($u, $g) = (stat($_))[4,5]; $uids{$u} = 1; $gids{$g} = 1; }
my %done;
my @l = grep {
if (!$_->{name} || getpwnam($_->{name}) || $done{$_->{name}}) {
0;
} else {
$_->{home} ||= "/home/$_->{name}";
my $u = $_->{uid} || ($_->{oldu} = (stat("$p$_->{home}"))[4]);
my $g = $_->{gid} || ($_->{oldg} = (stat("$p$_->{home}"))[5]);
#- search for available uid above 501 else initscripts may fail to change language for KDE.
if (!$u || getpwuid($u)) { for ($u = 501; getpwuid($u) || $uids{$u}; $u++) {} }
if (!$g || getgrgid($g)) { for ($g = 501; getgrgid($g) || $gids{$g}; $g++) {} }
$_->{uid} = $u; $uids{$u} = 1;
$_->{gid} = $g; $gids{$g} = 1;
$_->{pw} ||= $_->{password} && any::crypt($_->{password}, $o->{authentication}{md5});
$_->{shell} ||= "/bin/bash";
$done{$_->{name}} = 1;
}
} @{$o->{users} || []};
my @passwd = cat_("$p/etc/passwd");;
local *F;
open F, ">> $p/etc/passwd" or die "can't append to passwd file: $!";
print F join(':', @$_{@etc_pass_fields}), "\n" foreach @l;
open F, ">> $p/etc/group" or die "can't append to group file: $!";
print F "$_->{name}:x:$_->{gid}:\n" foreach @l;
foreach my $u (@l) {
if (! -d "$p$u->{home}") {
my $mode = $o->{security} < 2 ? 0755 : 0750;
eval { commands::cp("-f", "$p/etc/skel", "$p$u->{home}") };
if ($@) {
log::l("copying of skel failed: $@"); mkdir("$p$u->{home}", $mode);
} else {
chmod $mode, "$p$u->{home}";
}
}
eval { commands::chown_("-r", "$u->{uid}.$u->{gid}", "$p$u->{home}") }
if $u->{uid} != $u->{oldu} || $u->{gid} != $u->{oldg};
}
require any;
any::addUsers($o->{prefix}, @l);
}
#------------------------------------------------------------------------------
sub createBootdisk($) {
my ($o) = @_;
my $dev = $o->{mkbootdisk} or return;
my @l = detect_devices::floppies();
$dev = shift @l || die _("No floppy drive available")
if $dev eq "1"; #- special case meaning autochoose
return if $::testing;
require bootloader;
bootloader::mkbootdisk($o->{prefix}, install_any::kernelVersion($o), $dev, $o->{bootloader}{perImageAppend});
$o->{mkbootdisk} = $dev;
}
#------------------------------------------------------------------------------
sub readBootloaderConfigBeforeInstall {
my ($o) = @_;
my ($image, $v);
require bootloader;
add2hash($o->{bootloader} ||= {}, bootloader::read($o->{prefix}, arch() =~ /sparc/ ? "/etc/silo.conf" : "/etc/lilo.conf"));
#- since kernel or kernel-smp may not be upgraded, it should be checked
#- if there is a need to update existing lilo.conf entries by following
#- symlinks before kernel or other packages get installed.
foreach my $e (@{$o->{bootloader}{entries}}) {
while (my $v = readlink "$o->{prefix}/$e->{kernel_or_dev}") {
$v = "/boot/$v" if $v !~ m|^/|;
-e "$o->{prefix}$v" or next;
log::l("renaming /boot/$e->{kernel_or_dev} entry by $v");
$e->{kernel_or_dev} = $v;
}
}
}
sub setupBootloaderBefore {
my ($o) = @_;
if (arch() =~ /alpha/) {
if (my $dev = fsedit::get_root($o->{fstab})) {
$o->{bootloader}{boot} ||= "/dev/$dev->{rootDevice}";
$o->{bootloader}{root} ||= "/dev/$dev->{device}";
$o->{bootloader}{part_nb} ||= first($dev->{device} =~ /(\d+)/);
}
} else {
require bootloader;
#- propose the default fb mode for kernel fb, if aurora is installed too.
bootloader::suggest($o->{prefix}, $o->{bootloader}, $o->{hds}, $o->{fstab}, install_any::kernelVersion($o),
pkgs::packageFlagInstalled(pkgs::packageByName($o->{packages}, 'Aurora') || {}) && 785);
if ($o->{miscellaneous}{profiles}) {
my $e = bootloader::get_label("linux", $o->{bootloader});
push @{$o->{bootloader}{entries}}, { %$e, label => "office", append => "$e->{append} prof=Office" };
$e->{append} .= " prof=Home";
}
bootloader::suggest_floppy($o->{bootloader}) if $o->{security} <= 3;
$o->{bootloader}{keytable} ||= keyboard::keyboard2kmap($o->{keyboard});
}
}
sub setupBootloader($) {
my ($o) = @_;
return if $::g_auto_install;
if (arch() =~ /alpha/) {
return if $::testing;
my $b = $o->{bootloader};
$b->{boot} or $o->ask_warn('', "Can't install aboot, not a bsd disklabel"), return;
run_program::rooted($o->{prefix}, "swriteboot", $b->{boot}, "/boot/bootlx") or do {
cdie "swriteboot failed";
run_program::rooted($o->{prefix}, "swriteboot", "-f1", $b->{boot}, "/boot/bootlx");
};
run_program::rooted($o->{prefix}, "abootconf", $b->{boot}, $b->{part_nb});
modules::load('loop');
output "$o->{prefix}/etc/aboot.conf",
map_index { -e "$o->{prefix}/boot/initrd-$_->[1]" ?
"$::i:$b->{part_nb}$_->[0] root=$b->{root} initrd=/boot/initrd-$_->[1] $b->{perImageAppend}\n" :
"$::i:$b->{part_nb}$_->[0] root=$b->{root} $b->{perImageAppend}\n" }
map { run_program::rooted($o->{prefix}, "mkinitrd", "-f", "/boot/initrd-$_->[1]", "--ifneeded", $_->[1]) ;#or
#unlink "$o->{prefix}/boot/initrd-$_->[1]";$_ } grep { $_->[0] && $_->[1] }
$_ } grep { $_->[0] && $_->[1] }
map { [ m|$o->{prefix}(/boot/vmlinux-(.*))| ] } glob_("$o->{prefix}/boot/vmlinux-*");
# output "$o->{prefix}/etc/aboot.conf",
# map_index { "$::i:$b->{part_nb}$_ root=$b->{root} $b->{perImageAppend}\n" }
# map { /$o->{prefix}(.*)/ } eval { glob_("$o->{prefix}/boot/vmlinux*") };
} else {
require bootloader;
bootloader::install($o->{prefix}, $o->{bootloader}, $o->{fstab}, $o->{hds});
}
}
#------------------------------------------------------------------------------
sub configureXBefore {
my ($o) = @_;
my $xkb = $o->{X}{keyboard}{xkb_keymap} || keyboard::keyboard2xkb($o->{keyboard});
if (!-e "$o->{prefix}/usr/X11R6/lib/X11/xkb/symbols/$xkb" && (my $f = keyboard::xmodmap_file($o->{keyboard}))) {
commands::cp("-f", $f, "$o->{prefix}/etc/X11/xinit/Xmodmap");
$xkb = '';
}
$o->{X}{keyboard}{xkb_keymap} = $xkb;
$o->{X}{mouse} = $o->{mouse};
$o->{X}{wacom} = $o->{wacom};
require Xconfig;
Xconfig::getinfoFromDDC($o->{X});
#- keep this here if the package has to be updated.
$o->pkg_install("XFree86");
}
sub configureX {
my ($o) = @_;
$o->configureXBefore;
require Xconfigurator;
require class_discard;
{ local $::testing = 0; #- unset testing
local $::auto = 1;
$o->{X}{skiptest} = 1;
Xconfigurator::main($o->{prefix}, $o->{X}, class_discard->new, $o->{allowFB}, bool($o->{pcmcia}), sub {
$o->pkg_install("XFree86-$_[0]");
});
}
$o->configureXAfter;
}
sub configureXAfter {
my ($o) = @_;
if ($o->{X}{card}{server} eq 'FBDev') {
unless (install_any::setupFB($o, Xconfigurator::getVGAMode($o->{X}))) {
log::l("disabling automatic start-up of X11 if any as setup framebuffer failed");
Xconfigurator::rewriteInittab(3) unless $::testing; #- disable automatic start-up of X11 on error.
}
}
if ($o->{X}{default_depth} >= 16 && $o->{X}{card}{default_wres} >= 1024) {
log::l("setting large icon style for kde");
install_any::kderc_largedisplay($o->{prefix});
}
}
#------------------------------------------------------------------------------
# miscellaneousNetwork moved to any
#------------------------------------------------------------------------------
sub miscellaneous {
my ($o) = @_;
my %s = getVarsFromSh("$o->{prefix}/etc/sysconfig/system");
$o->{miscellaneous}{HDPARM} ||= $s{HDPARM} if exists $s{HDPARM};
$o->{miscellaneous}{CLEAN_TMP} ||= $s{CLEAN_TMP} if exists $s{CLEAN_TMP};
$o->{security} ||= $s{SECURITY} if exists $s{SECURITY};
$ENV{SECURE_LEVEL} = $o->{security};
add2hash_ $o, { useSupermount => $o->{security} < 4 && arch() !~ /sparc/ && $o->{installClass} !~ /corporate|server/ };
cat_("/proc/cmdline") =~ /.mem=(\S+)/; #- if /^mem/, it means that's the value grub gave
add2hash_($o->{miscellaneous} ||= {}, { numlock => !$o->{pcmcia}, $1 ? (memsize => $1) : () });
local $_ = $o->{bootloader}{perImageAppend};
if (my $ramsize = $o->{miscellaneous}{memsize} and !/mem=/) {
$_ .= " mem=$ramsize";
}
if (my @l = detect_devices::getIDEBurners() and !/ide-scsi/) {
$_ .= " " . join(" ", (map { "$_=ide-scsi" } @l),
map { "$_->{device}=ide-floppy" } detect_devices::ide_zips());
}
if (my $m = detect_devices::hasUltra66()) {
$_ .= " $m" if !/ide.=/;
}
#- keep some given parameters
#-TODO
log::l("perImageAppend: $_");
$o->{bootloader}{perImageAppend} = $_;
}
#------------------------------------------------------------------------------
sub generateAutoInstFloppy($) {
my ($o) = @_;
}
#------------------------------------------------------------------------------
sub exitInstall { install_any::unlockCdrom }
#------------------------------------------------------------------------------
sub hasNetwork {
my ($o) = @_;
$o->{intf} && $o->{netc}{NETWORKING} ne 'false' || $o->{modem};
}
#------------------------------------------------------------------------------
sub upNetwork {
my ($o, $pppAvoided) = @_;
foreach (qw(resolv.conf protocols services)) {
symlinkf("$o->{prefix}/etc/$_", "/etc/$_");
}
modules::write_conf($o->{prefix});
if ($o->{intf} && $o->{netc}{NETWORKING} ne 'false') {
network::up_it($o->{prefix}, $o->{intf});
} elsif (!$pppAvoided && $o->{modem} && !$o->{modem}{isUp}) {
eval { modules::load_multi(qw(serial ppp bsd_comp ppp_deflate)) };
run_program::rooted($o->{prefix}, "/etc/rc.d/init.d/syslog", "start");
run_program::rooted($o->{prefix}, "ifup", "ppp0");
$o->{modem}{isUp} = 1;
} else {
$::testing or return;
}
1;
}