/** * View message folder * Called from ucp_pm with mode == 'view' && action == 'view_folder' */ function view_folder($id, $mode, $folder_id, $folder) { global $user, $template, $auth, $db, $cache; global $phpbb_root_path, $config, $phpEx; $submit_export = (isset($_POST['submit_export'])) ? true : false; $folder_info = get_pm_from($folder_id, $folder, $user->data['user_id']); if (!$submit_export) { $user->add_lang('viewforum'); // Grab icons $icons = $cache->obtain_icons(); $color_rows = array('marked', 'replied'); // only show the friend/foe color rows if the module is enabled $zebra_enabled = false; $_module = new p_master(); $_module->list_modules('ucp'); $_module->set_active('zebra'); $zebra_enabled = ($_module->active_module === false) ? false : true; unset($_module); if ($zebra_enabled) { $color_rows = array_merge($color_rows, array('friend', 'foe')); } foreach ($color_rows as $var) { $template->assign_block_vars('pm_colour_info', array( 'IMG' => $user->img("pm_{$var}", ''), 'CLASS' => "pm_{$var}_colour", 'LANG' => $user->lang[strtoupper($var) . '_MESSAGE']) ); } $mark_options = array('mark_important', 'delete_marked'); $s_mark_options = ''; foreach ($mark_options as $mark_option) { $s_mark_options .= '<option value="' . $mark_option . '">' . $user->lang[strtoupper($mark_option)] . '</option>'; } // We do the folder moving options here too, for template authors to use... $s_folder_move_options = ''; if ($folder_id != PRIVMSGS_NO_BOX && $folder_id != PRIVMSGS_OUTBOX) { foreach ($folder as $f_id => $folder_ary) { if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id) { continue; } $s_folder_move_options .= '<option' . (($f_id != PRIVMSGS_INBOX) ? ' class="sep"' : '') . ' value="' . $f_id . '">'; $s_folder_move_options .= sprintf($user->lang['MOVE_MARKED_TO_FOLDER'], $folder_ary['folder_name']); $s_folder_move_options .= (($folder_ary['unread_messages']) ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>'; } } $friend = $foe = array(); // Get friends and foes $sql = 'SELECT * FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $friend[$row['zebra_id']] = $row['friend']; $foe[$row['zebra_id']] = $row['foe']; } $db->sql_freeresult($result); $template->assign_vars(array( 'S_MARK_OPTIONS' => $s_mark_options, 'S_MOVE_MARKED_OPTIONS' => $s_folder_move_options) ); // Okay, lets dump out the page ... if (sizeof($folder_info['pm_list'])) { $address_list = array(); // Build Recipient List if in outbox/sentbox - max two additional queries if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) { $recipient_list = $address = array(); foreach ($folder_info['rowset'] as $message_id => $row) { $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address'])); $_save = array('u', 'g'); foreach ($_save as $save) { if (isset($address[$message_id][$save]) && sizeof($address[$message_id][$save])) { foreach (array_keys($address[$message_id][$save]) as $ug_id) { $recipient_list[$save][$ug_id] = array('name' => $user->lang['NA'], 'colour' => ''); } } } } $_types = array('u', 'g'); foreach ($_types as $ug_type) { if (!empty($recipient_list[$ug_type])) { if ($ug_type == 'u') { $sql = 'SELECT user_id as id, username as name, user_colour as colour FROM ' . USERS_TABLE . ' WHERE '; } else { $sql = 'SELECT group_id as id, group_name as name, group_colour as colour, group_type FROM ' . GROUPS_TABLE . ' WHERE '; } $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($recipient_list[$ug_type]))); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if ($ug_type == 'g') { $row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name']; } $recipient_list[$ug_type][$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']); } $db->sql_freeresult($result); } } foreach ($address as $message_id => $adr_ary) { foreach ($adr_ary as $type => $id_ary) { foreach ($id_ary as $ug_id => $_id) { if ($type == 'u') { $address_list[$message_id][] = get_username_string('full', $ug_id, $recipient_list[$type][$ug_id]['name'], $recipient_list[$type][$ug_id]['colour']); } else { $user_colour = ($recipient_list[$type][$ug_id]['colour']) ? ' style="font-weight: bold; color:#' . $recipient_list[$type][$ug_id]['colour'] . '"' : ''; $link = '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $ug_id) . '"' . $user_colour . '>'; $address_list[$message_id][] = $link . $recipient_list[$type][$ug_id]['name'] . (($link) ? '</a>' : ''); } } } } unset($recipient_list, $address); } $data = array(); foreach ($folder_info['pm_list'] as $message_id) { $row = &$folder_info['rowset'][$message_id]; $folder_img = ($row['pm_unread']) ? 'pm_unread' : 'pm_read'; $folder_alt = ($row['pm_unread']) ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES'; // Generate all URIs ... $view_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=view&f=$folder_id&p=$message_id"); $remove_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&mode=compose&action=delete&p=$message_id"); $row_indicator = ''; foreach ($color_rows as $var) { if (($var != 'friend' && $var != 'foe' && $row['pm_' . $var]) || (($var == 'friend' || $var == 'foe') && isset(${$var}[$row['author_id']]) && ${$var}[$row['author_id']])) { $row_indicator = $var; break; } } // Send vars to template $template->assign_block_vars('messagerow', array( 'PM_CLASS' => ($row_indicator) ? 'pm_' . $row_indicator . '_colour' : '', 'MESSAGE_AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['username'], $row['user_colour'], $row['username']), 'MESSAGE_AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['username'], $row['user_colour'], $row['username']), 'MESSAGE_AUTHOR' => get_username_string('username', $row['author_id'], $row['username'], $row['user_colour'], $row['username']), 'U_MESSAGE_AUTHOR' => get_username_string('profile', $row['author_id'], $row['username'], $row['user_colour'], $row['username']), 'FOLDER_ID' => $folder_id, 'MESSAGE_ID' => $message_id, 'SENT_TIME' => $user->format_date($row['message_time']), 'SUBJECT' => censor_text($row['message_subject']), 'FOLDER' => (isset($folder[$row['folder_id']])) ? $folder[$row['folder_id']]['folder_name'] : '', 'U_FOLDER' => (isset($folder[$row['folder_id']])) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'folder=' . $row['folder_id']) : '', 'PM_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />' : '', 'PM_ICON_URL' => (!empty($icons[$row['icon_id']])) ? $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] : '', 'FOLDER_IMG' => $user->img($folder_img, $folder_alt), 'FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'), 'PM_IMG' => ($row_indicator) ? $user->img('pm_' . $row_indicator, '') : '', 'ATTACH_ICON_IMG' => ($auth->acl_get('u_pm_download') && $row['message_attachment'] && $config['allow_pm_attach']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '', 'S_PM_DELETED' => ($row['pm_deleted']) ? true : false, 'S_AUTHOR_DELETED' => ($row['author_id'] == ANONYMOUS) ? true : false, 'U_VIEW_PM' => ($row['pm_deleted']) ? '' : $view_message_url, 'U_REMOVE_PM' => ($row['pm_deleted']) ? $remove_message_url : '', 'RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? implode(', ', $address_list[$message_id]) : '') ); } unset($folder_info['rowset']); $template->assign_vars(array( 'S_SHOW_RECIPIENTS' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? true : false, 'S_SHOW_COLOUR_LEGEND' => true, 'S_PM_ICONS' => ($config['enable_pm_icons']) ? true : false) ); } } else { $export_type = request_var('export_option', ''); $enclosure = request_var('enclosure', ''); $delimiter = request_var('delimiter', ''); if ($export_type == 'CSV' && ($delimiter === '' || $enclosure === '')) { $template->assign_var('PROMPT', true); } else { // Build Recipient List if in outbox/sentbox $address = array(); if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) { foreach ($folder_info['rowset'] as $message_id => $row) { $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address'])); } } foreach ($folder_info['pm_list'] as $message_id) { $row = &$folder_info['rowset'][$message_id]; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); $sql = 'SELECT p.message_text, p.bbcode_uid FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u WHERE t.user_id = ' . $user->data['user_id'] . " AND p.author_id = u.user_id AND t.folder_id = $folder_id AND t.msg_id = p.msg_id AND p.msg_id = $message_id"; $result = $db->sql_query_limit($sql, 1); $message_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $_types = array('u', 'g'); foreach ($_types as $ug_type) { if (isset($address[$message_id][$ug_type]) && sizeof($address[$message_id][$ug_type])) { if ($ug_type == 'u') { $sql = 'SELECT user_id as id, username as name FROM ' . USERS_TABLE . ' WHERE '; } else { $sql = 'SELECT group_id as id, group_name as name FROM ' . GROUPS_TABLE . ' WHERE '; } $sql .= $db->sql_in_set(($ug_type == 'u') ? 'user_id' : 'group_id', array_map('intval', array_keys($address[$message_id][$ug_type]))); $result = $db->sql_query($sql); while ($info_row = $db->sql_fetchrow($result)) { $address[$message_id][$ug_type][$address[$message_id][$ug_type][$info_row['id']]][] = $info_row['name']; unset($address[$message_id][$ug_type][$info_row['id']]); } $db->sql_freeresult($result); } } decode_message($message_row['message_text'], $message_row['bbcode_uid']); $data[] = array( 'subject' => censor_text($row['message_subject']), 'sender' => $row['username'], 'date' => $user->format_date($row['message_time']), 'to' => ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) ? $address[$message_id] : '', 'message' => $message_row['message_text'] ); } switch ($export_type) { case 'CSV': case 'CSV_EXCEL': $mimetype = 'text/csv'; $filetype = 'csv'; if ($export_type == 'CSV_EXCEL') { $enclosure = '"'; $delimiter = ','; $newline = "\r\n"; } else { $newline = "\n"; } $string = ''; foreach ($data as $value) { $recipients = $value['to']; $value['to'] = $value['bcc'] = ''; if (is_array($recipients)) { foreach ($recipients as $values) { $value['bcc'] .= (isset($values['bcc']) && is_array($values['bcc'])) ? ',' . implode(',', $values['bcc']) : ''; $value['to'] .= (isset($values['to']) && is_array($values['to'])) ? ',' . implode(',', $values['to']) : ''; } // Remove the commas which will appear before the first entry. $value['to'] = substr($value['to'], 1); $value['bcc'] = substr($value['bcc'], 1); } foreach ($value as $tag => $text) { $cell = str_replace($enclosure, $enclosure . $enclosure, $text); if (strpos($cell, $enclosure) !== false || strpos($cell, $delimiter) !== false || strpos($cell, $newline) !== false) { $string .= $enclosure . $text . $enclosure . $delimiter; } else { $string .= $cell . $delimiter; } } $string = substr($string, 0, -1) . $newline; } break; case 'XML': $mimetype = 'application/xml'; $filetype = 'xml'; $string = '<?xml version="1.0"?>' . "\n"; $string .= "<phpbb>\n"; foreach ($data as $value) { $string .= "\t<privmsg>\n"; if (is_array($value['to'])) { foreach ($value['to'] as $key => $values) { foreach ($values as $type => $types) { foreach ($types as $name) { $string .= "\t\t<recipient type=\"$type\" status=\"$key\">$name</recipient>\n"; } } } } unset($value['to']); foreach ($value as $tag => $text) { $string .= "\t\t<$tag>$text</$tag>\n"; } $string .= "\t</privmsg>\n"; } $string .= '</phpbb>'; break; } header('Pragma: no-cache'); header("Content-Type: $mimetype; name=\"data.$filetype\""); header("Content-disposition: attachment; filename=data.$filetype"); echo $string; exit; } } }
} // **************************** // ********** INBOX *********** // **************************** if ($get == 'inbox') { include $phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx; include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx; $folder_id = PRIVMSGS_INBOX; // if new messages arrived, place them into the appropriate folder if ($user->data['user_new_privmsg']) { place_pm_into_folder($global_privmsgs_rules, $release); } // configure style, language, etc. $user->setup('viewforum', $forum_data['forum_style']); // get the users private messages $pms = get_pm_from($folder_id, '', $user->data['user_id']); // we only want the messages, not the index $pms = $pms['rowset']; // sort messages so newest is on top krsort($pms); // separate messages into read and unread while (list($key, $val) = each($pms)) { if ($val['pm_unread']) { $unread[] = $val; } else { $read[] = $val; } } // send unread messages for ($i = 0; $i < count($unread); $i++) { if ($output) {
function view_folder($id, $mode, $folder_id, $folder, $type) { global $_CLASS, $config; // Grab icons $icons = array(); obtain_icons($icons); $color_rows = array('marked', 'replied', 'message_reported', 'friend', 'foe'); foreach ($color_rows as $var) { $_CLASS['core_template']->assign_vars_array('pm_colour_info', array('IMG' => $_CLASS['core_user']->img("pm_{$var}", ''), 'CLASS' => "pm_{$var}_colour", 'LANG' => $_CLASS['core_user']->lang[strtoupper($var) . '_MESSAGE'])); } $mark_options = array('mark_important', 'delete_marked'); $s_mark_options = ''; foreach ($mark_options as $mark_option) { $s_mark_options .= '<option value="' . $mark_option . '">' . $_CLASS['core_user']->lang[strtoupper($mark_option)] . '</option>'; } $friend = $foe = array(); // Get friends and foes $sql = 'SELECT * FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id']; $result = $_CLASS['core_db']->query($sql); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $friend[$row['zebra_id']] = $row['friend']; $foe[$row['zebra_id']] = $row['foe']; } $_CLASS['core_db']->free_result($result); $_CLASS['core_template']->assign(array('S_UNREAD' => $type == 'unread', 'S_MARK_OPTIONS' => $s_mark_options)); $folder_info = get_pm_from($folder_id, $folder, $_CLASS['core_user']->data['user_id'], "Control_Panel&i={$id}", $type); // Okay, lets dump out the page ... if (sizeof($folder_info['pm_list'])) { // Build Recipient List if in outbox/sentbox - max two additional queries $recipient_list = $address_list = $address = array(); if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) { foreach ($folder_info['rowset'] as $message_id => $row) { $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address'])); foreach (array('u', 'g') as $save) { if (isset($address[$message_id][$save]) && sizeof($address[$message_id][$save])) { foreach (array_keys($address[$message_id][$save]) as $ug_id) { $recipient_list[$save][$ug_id] = array('name' => $_CLASS['core_user']->lang['NA'], 'colour' => ''); } } } } foreach (array('u', 'g') as $ug_type) { if (isset($recipient_list[$ug_type]) && sizeof($recipient_list[$ug_type])) { $sql = $ug_type == 'u' ? 'SELECT user_id as id, username as name, user_colour as colour FROM ' . USERS_TABLE . ' WHERE user_id' : 'SELECT group_id as id, group_name as name, group_colour as colour FROM ' . GROUPS_TABLE . ' WHERE group_id'; $sql .= ' IN (' . implode(', ', array_keys($recipient_list[$ug_type])) . ')'; $result = $_CLASS['core_db']->query($sql); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $recipient_list[$ug_type][$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']); } $_CLASS['core_db']->free_result($result); } } foreach ($address as $message_id => $adr_ary) { foreach ($adr_ary as $type => $id_ary) { foreach ($id_ary as $ug_id => $_id) { $address_list[$message_id][] = ($type == 'u' ? '<a href="' . generate_link('Members_List&mode=viewprofile&u=' . $ug_id) . '">' : '<a href="' . generate_link('Members_List&mode=group&g=' . $ug_id) . '">') . ($recipient_list[$type][$ug_id]['colour'] ? '<span style="color:#' . $recipient_list[$type][$ug_id]['colour'] . '">' : '<span>') . $recipient_list[$type][$ug_id]['name'] . '</span></a>'; } } } unset($recipient_list, $address); } $url = 'Control_Panel&i=' . $id; foreach ($folder_info['pm_list'] as $message_id) { $row =& $folder_info['rowset'][$message_id]; $folder_img = $row['unread'] ? 'folder_new' : 'folder'; $folder_alt = $row['unread'] ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES'; // Generate all URIs ... $message_author = '<a href="' . generate_link('Members_List&mode=viewprofile&u=' . $row['author_id']) . '">' . $row['username'] . '</a>'; $view_message_url = generate_link("{$url}&f={$folder_id}&p={$message_id}"); $remove_message_url = generate_link($url . '&mode=compose&action=delete&p=' . $message_id); $row_indicator = ''; foreach ($color_rows as $var) { if ($var != 'friend' && $var != 'foe' && $row[$var] || ($var == 'friend' || $var == 'foe') && isset(${$var}[$row['author_id']])) { $row_indicator = $var; break; } } // Send vars to template $_CLASS['core_template']->assign_vars_array('messagerow', array('PM_CLASS' => $row_indicator ? 'pm_' . $row_indicator . '_colour' : '', 'FOLDER_ID' => $folder_id, 'MESSAGE_ID' => $message_id, 'MESSAGE_AUTHOR' => $message_author, 'SENT_TIME' => $_CLASS['core_user']->format_date($row['message_time']), 'SUBJECT' => censor_text($row['message_subject']), 'FOLDER' => isset($folder[$row['folder_id']]) ? $folder[$row['folder_id']]['folder_name'] : '', 'U_FOLDER' => isset($folder[$row['folder_id']]) ? generate_link("{$url}&folder=" . $row['folder_id']) : '', 'PM_ICON_IMG' => !empty($icons[$row['icon_id']]) ? '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />' : '', 'FOLDER_IMG' => $_CLASS['core_user']->img($folder_img, $folder_alt), 'PM_IMG' => $row_indicator ? $_CLASS['core_user']->img('pm_' . $row_indicator, '') : '', 'ATTACH_ICON_IMG' => $_CLASS['auth']->acl_get('u_download') && $row['message_attachment'] && $config['allow_pm_attach'] && $config['auth_download_pm'] ? $_CLASS['core_user']->img('icon_attach', $_CLASS['core_user']->lang['TOTAL_ATTACHMENTS']) : '', 'S_PM_REPORTED' => !empty($row['message_reported']) && $_CLASS['auth']->acl_get('m_') ? true : false, 'S_PM_DELETED' => $row['deleted'] ? true : false, 'U_VIEW_PM' => $row['deleted'] ? '' : $view_message_url, 'U_REMOVE_PM' => $row['deleted'] ? $remove_message_url : '', 'RECIPIENTS' => $folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX ? implode(', ', $address_list[$message_id]) : '', 'U_MCP_REPORT' => generate_link('Forums&file=mcp&mode=reports&pm=' . $message_id))); } unset($folder_info['rowset']); $_CLASS['core_template']->assign(array('S_SHOW_RECIPIENTS' => $folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX ? true : false, 'S_SHOW_COLOUR_LEGEND' => true)); } }
function get_box_func($xmlrpc_params) { global $db, $auth, $user, $cache, $config, $phpbb_home, $phpbb_root_path, $phpEx; $params = php_xmlrpc_decode($xmlrpc_params); $user->setup('ucp'); if (!$user->data['is_registered']) { trigger_error('LOGIN_EXPLAIN_UCP'); } if (!$config['allow_privmsg']) { trigger_error('Module not accessible'); } if (!isset($params[0])) { trigger_error('UNKNOWN_FOLDER'); } // get folder id from parameters $folder_id = intval($params[0]); if (PRIVMSGS_INBOX !== $folder_id) { $folder_id = PRIVMSGS_SENTBOX; } list($start, $limit, $page) = process_page($params[1], $params[2]); // Grab icons //$icons = $cache->obtain_icons(); $user_id = $user->data['user_id']; include_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx; $folder = get_folder($user_id, $folder_id); include $phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx; $folder_info = get_pm_from($folder_id, $folder, $user_id); $address_list = array(); // Build Recipient List if in outbox/sentbox - max two additional queries if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) { $recipient_list = $address = array(); foreach ($folder_info['rowset'] as $message_id => $row) { $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address'])); $_save = array('u', 'g'); foreach ($_save as $save) { if (isset($address[$message_id][$save]) && sizeof($address[$message_id][$save])) { foreach (array_keys($address[$message_id][$save]) as $ug_id) { $recipient_list[$save][$ug_id] = array('name' => $user->lang['NA'], 'colour' => ''); } } } } $_types = array('u', 'g'); foreach ($_types as $ug_type) { if (!empty($recipient_list[$ug_type])) { if ($ug_type == 'u') { $sql = 'SELECT user_id as id, username as name, user_colour as colour FROM ' . USERS_TABLE . ' WHERE '; } else { $sql = 'SELECT group_id as id, group_name as name, group_colour as colour, group_type FROM ' . GROUPS_TABLE . ' WHERE '; } $sql .= $db->sql_in_set($ug_type == 'u' ? 'user_id' : 'group_id', array_map('intval', array_keys($recipient_list[$ug_type]))); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if ($ug_type == 'g') { $row['name'] = $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['name']] : $row['name']; } $recipient_list[$ug_type][$row['id']] = array('id' => $row['id'], 'name' => $row['name'], 'colour' => $row['colour']); } $db->sql_freeresult($result); } } foreach ($address as $message_id => $adr_ary) { foreach ($adr_ary as $type => $id_ary) { foreach ($id_ary as $ug_id => $_id) { $address_list[$message_id][] = $recipient_list[$type][$ug_id]; } } } unset($recipient_list, $address); } // get unread count in inbox only if (PRIVMSGS_INBOX === $folder_id) { $sql = 'SELECT COUNT(msg_id) as num_messages FROM ' . PRIVMSGS_TO_TABLE . ' WHERE pm_unread = 1 AND folder_id = ' . PRIVMSGS_INBOX . ' AND user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $unread_num = (int) $db->sql_fetchfield('num_messages'); $db->sql_freeresult($result); } else { $unread_num = 0; } $sql = 'SELECT COUNT(msg_id) as num_messages FROM ' . PRIVMSGS_TO_TABLE . ' WHERE folder_id = ' . $folder_id . ' AND user_id = ' . $user->data['user_id']; $result = $db->sql_query($sql); $total_num = (int) $db->sql_fetchfield('num_messages'); $db->sql_freeresult($result); $sql = 'SELECT t.*, p.*, u.username, u.user_avatar, u.user_avatar_type, u.user_id FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . " u\r\r\n WHERE t.user_id = {$user_id}\r\r\n AND p.author_id = u.user_id\r\r\n AND t.folder_id = {$folder_id}\r\r\n AND t.msg_id = p.msg_id\r\r\n ORDER BY p.message_time DESC"; $result = $db->sql_query_limit($sql, $limit, $start); $total_message_count = $total_unread_count = 0; $online_cache = array(); while ($row = $db->sql_fetchrow($result)) { $msg_state = 2; // message read if ($row['pm_unread']) { $msg_state = 1; } else { if ($row['pm_replied']) { $msg_state = 3; } else { if ($row['pm_forwarded']) { $msg_state = 4; } } } if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) { $msg_to_list = $address_list[$row['msg_id']]; } else { $msg_to_list = array(array('id' => $user->data['user_id'], 'name' => $user->data['username'])); } $msg_to = array(); foreach ($msg_to_list as $address) { $msg_to[] = new xmlrpcval(array('user_id' => new xmlrpcval($address['id'], 'string'), 'username' => new xmlrpcval(basic_clean($address['name']), 'base64'), 'user_type' => check_return_user_type($address['name'])), 'struct'); } $sent_date = mobiquo_iso8601_encode($row['message_time']); //$icon_url = (!empty($icons[$row['icon_id']])) ? $phpbb_home . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] : ''; $icon_url = $user->optionget('viewavatars') ? get_user_avatar_url($row['user_avatar'], $row['user_avatar_type']) : ''; $msg_subject = html_entity_decode(strip_tags(censor_text($row['message_subject']))); $short_content = censor_text($row['message_text']); $short_content = preg_replace('/\\[url.*?\\].*?\\[\\/url.*?\\]/', '[url]', $short_content); $short_content = preg_replace('/\\[img.*?\\].*?\\[\\/img.*?\\]/', '[img]', $short_content); $short_content = preg_replace('/[\\n\\r\\t]+/', ' ', $short_content); strip_bbcode($short_content); $short_content = html_entity_decode($short_content); $short_content = substr($short_content, 0, 200); if ($config['load_onlinetrack'] && !isset($online_cache[$row['user_id']])) { $sql = 'SELECT session_user_id, MAX(session_time) as online_time, MIN(session_viewonline) AS viewonline FROM ' . SESSIONS_TABLE . ' WHERE session_user_id=' . $row['user_id'] . ' GROUP BY session_user_id'; $online_result = $db->sql_query($sql); $online_info = $db->sql_fetchrow($online_result); $db->sql_freeresult($online_result); $update_time = $config['load_online_time'] * 60; $online_cache[$row['user_id']] = time() - $update_time < $online_info['online_time'] && ($online_info['viewonline'] || $auth->acl_get('u_viewonline')) ? true : false; } $is_online = isset($online_cache[$row['user_id']]) ? $online_cache[$row['user_id']] : false; $pm_list[] = new xmlrpcval(array('msg_id' => new xmlrpcval($row['msg_id']), 'msg_state' => new xmlrpcval($msg_state, 'int'), 'sent_date' => new xmlrpcval($sent_date, 'dateTime.iso8601'), 'timestamp' => new xmlrpcval($row['message_time'], 'string'), 'msg_from' => new xmlrpcval(basic_clean($row['username']), 'base64'), 'msg_from_id' => new xmlrpcval($row['user_id']), 'icon_url' => new xmlrpcval($icon_url), 'msg_to' => new xmlrpcval($msg_to, 'array'), 'msg_subject' => new xmlrpcval($msg_subject, 'base64'), 'short_content' => new xmlrpcval($short_content, 'base64'), 'is_online' => new xmlrpcval($is_online, 'boolean')), 'struct'); } $db->sql_freeresult($result); $result = new xmlrpcval(array('total_message_count' => new xmlrpcval($total_num, 'int'), 'total_unread_count' => new xmlrpcval($unread_num, 'int'), 'list' => new xmlrpcval($pm_list, 'array')), 'struct'); return new xmlrpcresp($result); }
function view_folder($parent_class, $folder_id, $folder, $type) { global $_CLASS; $limit = 10; $icons = obtain_icons(); $submit_export = isset($_POST['submit_export']) ? true : false; $folder_info = get_pm_from($folder_id, $folder, $_CLASS['core_user']->data['user_id'], $parent_class->link_parent, $type); $color_rows = array('marked', 'replied', 'friend', 'foe'); //, 'message_reported' foreach ($color_rows as $var) { $_CLASS['core_template']->assign_vars_array('pm_colour_info', array('IMG' => $_CLASS['core_user']->img("pm_{$var}", ''), 'CLASS' => "pm_{$var}_colour", 'LANG' => $_CLASS['core_user']->get_lang(strtoupper($var) . '_MESSAGE'))); } $mark_options = array('mark_important', 'delete_marked', 'mark_read', 'mark_unread'); $s_mark_options = ''; foreach ($mark_options as $mark_option) { $s_mark_options .= '<option value="' . $mark_option . '">' . $_CLASS['core_user']->get_lang(strtoupper($mark_option)) . '</option>'; } // We do the folder moving options here too, for template authors to use... $s_folder_move_options = ''; foreach ($folder as $f_id => $folder_ary) { if ($f_id == PRIVMSGS_OUTBOX || $f_id == PRIVMSGS_SENTBOX || $f_id == $folder_id) { continue; } $s_folder_move_options .= '<option' . ($f_id != PRIVMSGS_INBOX ? ' class="blue"' : '') . ' value="' . $f_id . '">'; $s_folder_move_options .= sprintf($_CLASS['core_user']->get_lang('MOVE_MARKED_TO_FOLDER'), $folder_ary['folder_name']); $s_folder_move_options .= ($folder_ary['unread_messages'] ? ' [' . $folder_ary['unread_messages'] . '] ' : '') . '</option>'; } $friend = $foe = array(); // Get friends and foes $sql = 'SELECT * FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $_CLASS['core_user']->data['user_id']; $result = $_CLASS['core_db']->query($sql); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $friend[$row['zebra_id']] = $row['friend']; $foe[$row['zebra_id']] = $row['foe']; } $_CLASS['core_db']->free_result($result); $_CLASS['core_template']->assign_array(array('S_UNREAD' => $type === 'unread', 'S_MARK_OPTIONS' => $s_mark_options)); // Okay, lets dump out the page ... if (!empty($folder_info['pm_list'])) { // Build Recipient List if in outbox/sentbox - max two additional queries $recipient_list = $address_list = $address = array(); if ($folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX) { foreach ($folder_info['rowset'] as $message_id => $row) { $address[$message_id] = rebuild_header(array('to' => $row['to_address'], 'bcc' => $row['bcc_address'])); $_save = array('u', 'g'); foreach ($_save as $save) { if (isset($address[$message_id][$save]) && sizeof($address[$message_id][$save])) { foreach (array_keys($address[$message_id][$save]) as $ug_id) { $recipient_list[$save][$ug_id] = array('name' => $_CLASS['core_user']->lang['NA'], 'colour' => ''); } } } } $_types = array('u', 'g'); foreach ($_types as $ug_type) { if (!empty($recipient_list[$ug_type])) { $sql = $ug_type === 'u' ? 'SELECT user_id as id, username as name, user_colour as colour FROM ' . CORE_USERS_TABLE . ' WHERE user_id' : 'SELECT group_id as id, group_name as name, group_colour as colour FROM ' . CORE_GROUPS_TABLE . ' WHERE group_id'; $sql .= ' IN (' . implode(', ', array_map('intval', array_keys($recipient_list[$ug_type]))) . ')'; $result = $_CLASS['core_db']->query($sql); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $recipient_list[$ug_type][$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']); } $_CLASS['core_db']->free_result($result); } } foreach ($address as $message_id => $adr_ary) { foreach ($adr_ary as $type => $id_ary) { foreach ($id_ary as $ug_id => $_id) { $user_colour = $recipient_list[$type][$ug_id]['colour'] ? ' style="color:#' . $recipient_list[$type][$ug_id]['colour'] . '"' : ''; if ($type === 'u') { $link = $ug_id != ANONYMOUS ? '<a href="' . generate_link('members_list&mode=viewprofile&u=' . $ug_id) . '"' . $user_colour . '>' : ''; } else { $link = '<a href="' . generate_link('members_list&mode=group&g=' . $ug_id) . '"' . $user_colour . '>'; } $address_list[$message_id][] = $link . $recipient_list[$type][$ug_id]['name'] . ($link ? '</a>' : ''); } } } unset($recipient_list, $address); } foreach ($folder_info['pm_list'] as $message_id) { $row =& $folder_info['rowset'][$message_id]; $folder_img = $row['pm_unread'] ? 'folder_new' : 'folder'; $folder_alt = $row['pm_unread'] ? 'NEW_MESSAGES' : 'NO_NEW_MESSAGES'; // Generate all URIs ... $message_author = $row['author_id'] != ANONYMOUS ? '<a href="' . generate_link('members_list&mode=viewprofile&u=' . $row['author_id']) . '">' . $row['username'] . '</a>' : $row['username']; $view_message_url = generate_link($parent_class->link_parent . "&f={$folder_id}&p={$message_id}"); $remove_message_url = generate_link($parent_class->link_parent . '&mode=compose&action=delete&p=' . $message_id); $row_indicator = ''; foreach ($color_rows as $var) { if ($var !== 'friend' && $var !== 'foe' && $row['pm_' . $var] || ($var == 'friend' || $var == 'foe') && isset(${$var}[$row['author_id']]) && ${$var}[$row['author_id']]) { $row_indicator = $var; break; } } // Send vars to template $_CLASS['core_template']->assign_vars_array('messagerow', array('PM_CLASS' => $row_indicator ? 'pm_' . $row_indicator . '_colour' : '', 'FOLDER_ID' => $folder_id, 'MESSAGE_ID' => $message_id, 'MESSAGE_AUTHOR' => $message_author, 'SENT_TIME' => $_CLASS['core_user']->format_date($row['message_time']), 'SUBJECT' => censor_text($row['message_subject']), 'FOLDER' => isset($folder[$row['folder_id']]) ? $folder[$row['folder_id']]['folder_name'] : '', 'U_FOLDER' => isset($folder[$row['folder_id']]) ? generate_link($parent_class->link_parent . '&folder=' . $row['folder_id']) : '', 'PM_ICON_IMG' => !empty($icons[$row['icon_id']]) ? '<img src="' . $config['icons_path'] . '/' . $icons[$row['icon_id']]['img'] . '" width="' . $icons[$row['icon_id']]['width'] . '" height="' . $icons[$row['icon_id']]['height'] . '" alt="" title="" />' : '', 'FOLDER_IMG' => $_CLASS['core_user']->img($folder_img, $folder_alt), 'PM_IMG' => $row_indicator ? $_CLASS['core_user']->img('pm_' . $row_indicator, '') : '', 'ATTACH_ICON_IMG' => $row['message_attachment'] ? $_CLASS['core_user']->img('icon_attach', $_CLASS['core_user']->lang['TOTAL_ATTACHMENTS']) : '', 'S_PM_REPORTED' => '', 'S_PM_DELETED' => $row['pm_deleted'] ? true : false, 'S_AUTHOR_DELETED' => $row['author_id'] == ANONYMOUS ? true : false, 'U_VIEW_PM' => $row['pm_deleted'] ? '' : $view_message_url, 'U_REMOVE_PM' => $row['pm_deleted'] ? $remove_message_url : '', 'RECIPIENTS' => $folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX ? implode(', ', $address_list[$message_id]) : '', 'U_MCP_REPORT' => generate_link('forums&file=mcp&mode=reports&pm=' . $message_id))); } unset($folder_info['rowset']); $_CLASS['core_template']->assign_array(array('S_SHOW_RECIPIENTS' => $folder_id == PRIVMSGS_OUTBOX || $folder_id == PRIVMSGS_SENTBOX ? true : false, 'S_SHOW_COLOUR_LEGEND' => true)); } }