ソースを参照

! Shiny new PM popup menu.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 11 年 前
コミット
b36f2c178f

+ 82 - 1
Sources/PersonalMessage.php

@@ -191,6 +191,7 @@ function MessageMain()
 	$context['display_mode'] = WIRELESS ? 0 : $user_settings['pm_prefs'] & 3;
 
 	$subActions = array(
+		'popup' => 'MessagePopup',
 		'addbuddy' => 'WirelessAddBuddy',
 		'manlabels' => 'ManageLabels',
 		'manrules' => 'ManageRules',
@@ -214,7 +215,7 @@ function MessageMain()
 	}
 	else
 	{
-		if (!isset($_REQUEST['xml']))
+		if (!isset($_REQUEST['xml']) && $_REQUEST['sa'] != 'popup')
 			messageIndexBar($_REQUEST['sa']);
 		$subActions[$_REQUEST['sa']]();
 	}
@@ -372,6 +373,86 @@ function messageIndexBar($area)
 		$context['template_layers'][] = 'pm';
 }
 
+/**
+ * The popup for when we ask for the popup from the user.
+ */
+function MessagePopup()
+{
+	global $context, $modSettings, $smcFunc, $memberContext, $scripturl, $user_settings;
+
+	// We only want to output our little layer here.
+	$context['template_layers'] = array();
+	$context['sub_template'] = 'pm_popup';
+
+	$context['can_send_pm'] = allowedTo('pm_send');
+	$context['can_draft'] = allowedTo('pm_draft') && !empty($modSettings['drafts_pm_enabled']);
+
+	// So are we loading stuff?
+	$request = $smcFunc['db_query']('', '
+		SELECT id_pm
+		FROM {db_prefix}pm_recipients AS pmr
+		WHERE pmr.id_member = {int:current_member}
+			AND is_read = {int:not_read}
+		ORDER BY id_pm',
+		array(
+			'current_member' => $context['user']['id'],
+			'not_read' => 0,
+		)
+	);
+	$pms = array();
+	while ($row = $smcFunc['db_fetch_row']($request))
+		$pms[] = $row[0];
+	$smcFunc['db_free_result']($request);
+
+	if (!empty($pms))
+	{
+		// Just quickly, it's possible that the number of PMs can get out of sync.
+		$count_unread = count($pms);
+		if ($count_unread != $user_settings['unread_messages'])
+		{
+			updateMemberData($context['user']['id'], array('unread_messages' => $count_unread));
+			$context['user']['unread_messages'] = count($pms);
+		}
+
+		// Now, actually fetch me some PMs. Make sure we track the senders, got some work to do for them.
+		$senders = array();
+
+		$request = $smcFunc['db_query']('', '
+			SELECT pm.id_pm, pm.id_pm_head, IFNULL(mem.id_member, pm.id_member_from) AS id_member_from,
+				IFNULL(mem.real_name, pm.from_name) AS member_from, pm.msgtime AS timestamp, pm.subject
+			FROM {db_prefix}personal_messages AS pm
+				LEFT JOIN {db_prefix}members AS mem ON (pm.id_member_from = mem.id_member)
+			WHERE pm.id_pm IN ({array_int:id_pms})',
+			array(
+				'id_pms' => $pms,
+			)
+		);
+		while ($row = $smcFunc['db_fetch_assoc']($request))
+		{
+			if (!empty($row['id_member_from']))
+				$senders[] = $row['id_member_from'];
+
+			$row['replied_to_you'] = $row['id_pm'] != $row['id_pm_head'];
+			$row['time'] = timeformat($row['timestamp']);
+			$row['pm_link'] = '<a href="' . $scripturl . '?action=pm;f=inbox;pmsg=' . $row['id_pm'] . '">' . $row['subject'] . '</a>';
+			$context['unread_pms'][$row['id_pm']] = $row;
+		}
+		$smcFunc['db_free_result']($request);
+
+		if (!empty($senders))
+		{
+			$senders = loadMemberData($senders);
+			foreach ($senders as $member)
+				loadMemberContext($member);
+		}
+
+		// Having loaded everyone, attach them to the PMs.
+		foreach ($context['unread_pms'] as $id_pm => $details)
+			if (!empty($memberContext[$details['id_member_from']]))
+				$context['unread_pms'][$id_pm]['member'] = &$memberContext[$details['id_member_from']];
+	}
+}
+
 /**
  * A folder, ie. inbox/sent etc.
  */

+ 9 - 24
Sources/Subs.php

@@ -3804,6 +3804,9 @@ function setupMenuContext()
 		addInlineJavascript('
 	var user_menus = new smc_PopupMenu();
 	user_menus.add("profile", "' . $scripturl . '?action=profile;area=popup");', true);
+		if ($context['allow_pm'])
+			addInlineJavascript('
+	user_menus.add("pm", "' . $scripturl . '?action=pm;sa=popup");', true);
 	}
 
 	// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.
@@ -3893,24 +3896,6 @@ function setupMenuContext()
 					),
 				),
 			),
-			'pm' => array(
-				'title' => $txt['pm_short'],
-				'href' => $scripturl . '?action=pm',
-				'show' => $context['allow_pm'],
-				'sub_buttons' => array(
-					'pm_read' => array(
-						'title' => $txt['pm_menu_read'],
-						'href' => $scripturl . '?action=pm',
-						'show' => allowedTo('pm_read'),
-					),
-					'pm_send' => array(
-						'title' => $txt['pm_menu_send'],
-						'href' => $scripturl . '?action=pm;sa=send',
-						'show' => allowedTo('pm_send'),
-						'is_last' => true,
-					),
-				),
-			),
 			'calendar' => array(
 				'title' => $txt['calendar'],
 				'href' => $scripturl . '?action=calendar',
@@ -4048,6 +4033,12 @@ function setupMenuContext()
 		$current_action = 'self_profile';
 		$context['self_profile'] = true;
 	}
+	elseif ($context['current_action'] == 'pm')
+	{
+		$current_action = 'self_pm';
+		$context['self_pm'] = true;
+	}
+
 	// Not all actions are simple.
 	if (!empty($needs_action_hook))
 		call_integration_hook('integrate_current_action', array(&$current_action));
@@ -4066,12 +4057,6 @@ function setupMenuContext()
 		$context['menu_buttons']['admin']['sub_buttons']['memberapprove']['title'] .= ' <span class="amt">' . $context['unapproved_members'] . '</span>';
 		$context['menu_buttons']['admin']['title'] .= ' <span class="amt">' . $context['unapproved_members'] . '</span>';
 	}
-
-	if (!$user_info['is_guest'] && $context['user']['unread_messages'] > 0 && isset($context['menu_buttons']['pm']))
-	{
-		$context['menu_buttons']['pm']['alttitle'] = $context['menu_buttons']['pm']['title'] . ' [' . $context['user']['unread_messages'] . ']';
-		$context['menu_buttons']['pm']['title'] .= ' <span class="amt">' . $context['user']['unread_messages'] . '</span>';
-	}
 }
 
 /**

+ 46 - 0
Themes/default/PersonalMessage.template.php

@@ -49,6 +49,52 @@ function template_pm_below()
 	</div>';
 }
 
+function template_pm_popup()
+{
+	global $context, $txt, $scripturl, $settings;
+
+	// Unlike almost every other template, this is designed to be included into the HTML directly via $().load()
+	echo '
+		<div class="pm_bar">
+			<div class="pm_sending floatright">
+				', $context['can_send_pm'] ? '<a href="' . $scripturl . '?action=pm;sa=send">' . $txt['pm_new_short'] . '</a> | ' : '', '
+				', $context['can_draft'] ? '<a href="' . $scripturl . '?action=pm;sa=showpmdrafts">' . $txt['pm_drafts_short'] . '</a> | ' : '', '
+				<a href="', $scripturl, '?action=pm;sa=settings">', $txt['pm_settings_short'], '</a>
+			</div>
+			<div class="pm_mailbox floatleft">
+				', $txt['pm_unread'], '
+				| <a href="', $scripturl, '?action=pm">', $txt['inbox'], '</a>
+				| <a href="', $scripturl, '?action=pm;f=sent">', $txt['pm_sent_short'], '</a>
+			</div>
+		</div>
+		<div class="pm_unread">';
+
+	if (empty($context['unread_pms']))
+	{
+		echo '
+			<div class="no_unread">', $txt['pm_no_unread'], '</div>';
+	}
+	else
+	{
+		foreach ($context['unread_pms'] as $id_pm => $pm_details)
+		{
+			echo '
+			<div class="unread">
+				<div class="avatar floatleft">', !empty($pm_details['member']) ? $pm_details['member']['avatar']['image'] : '', '</div>
+				<div class="details floatleft">
+					<div class="subject">', $pm_details['pm_link'], '</div>
+					<div class="sender">', $pm_details['replied_to_you'] ? '<img src="' . $settings['images_url'] . '/icons/pm_replied.png" style="margin-right: 4px;" alt="' . $txt['pm_you_were_replied_to'] . '" title="' . $txt['pm_you_were_replied_to'] . '" />' : '<img src="' . $settings['images_url'] . '/icons/pm_read.png" style="margin-right: 4px;" alt="' . $txt['pm_was_sent_to_you'] . '" title="' . $txt['pm_was_sent_to_you'] . '" />',
+					!empty($pm_details['member']) ? $pm_details['member']['link'] : $pm_details['member_from'], ' - ', $pm_details['time'], '</div>
+				</div>
+				<br class="clear" />
+			</div>';
+		}
+	}
+
+	echo '
+		</div>';
+}
+
 function template_folder()
 {
 	global $context, $settings, $options, $scripturl, $modSettings, $txt;

+ 40 - 0
Themes/default/css/index.css

@@ -1156,6 +1156,46 @@ img.sort, .sort {
 #profile_menu .profile_user_links li img {
 	margin-bottom: -1px;
 }
+#pm_menu .pm_unread {
+	margin-top: 2px;
+	padding-top: 3px;
+	border-top: 1px solid #ddd;
+	clear: both;
+}
+#pm_menu .pm_unread .no_unread {
+	padding-top: 3px;
+	text-align: center;
+}
+#pm_menu .pm_unread .windowbg, #pm_menu .pm_unread .windowbg2 {
+	clear: both;
+	padding: 2px;
+}
+#pm_menu .pm_unread div > .avatar {
+	width: 40px;
+	height: 40px;
+	margin: 1px 6px 0 1px;
+}
+#pm_menu .pm_unread .avatar img {
+	width: 100%;
+	height: 100%;
+	max-width: 40px;
+	max-height: 40px;
+}
+#pm_menu .unread .subject {
+	font-weight: bold;
+}
+#pm_menu .unread {
+	border-bottom: 1px solid #ddd;
+}
+#pm_menu .unread:hover {
+	background: #eee;
+}
+#pm_menu .unread:last-of-type {
+	border-bottom: 1px solid transparent;
+}
+#pm_menu .details {
+	max-width: 80%;
+}
 /* This CSS is for adding top level subsection indicators, just in case anyone wants them. */
 /* I'm not that keen on them, but perhaps the commented code should be left as a handy demo. */
 /*

+ 8 - 8
Themes/default/index.template.php

@@ -191,15 +191,15 @@ function template_body_above()
 					<div id="profile_menu" class="top_menu"></div>
 				</li>';
 
-		// Are there any members waiting for approval?
-		if (!empty($context['unapproved_members']))
-			echo '
-				<li><a href="', $scripturl, '?action=admin;area=viewmembers;sa=browse;type=approve">', $txt['approve_members_waiting'], ' <span class="amt">', $context['unapproved_members'], '</span></a></li>';
-
-		// This will only apply if we're powerful and can actually see reports.
-		if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
+		// Secondly, PMs if we're doing them
+		if ($context['allow_pm'])
+		{
 			echo '
-				<li><a href="', $scripturl, '?action=moderate;area=reports">', $txt['mod_reports_waiting'], ' <span class="amt">', $context['open_mod_reports'], '</span></a></li>';
+				<li>
+					<a href="', $scripturl, '?action=pm"', !empty($context['self_pm']) ? ' class="active"' : '', ' id="pm_menu_top">', $txt['pm_short'], !empty($context['user']['unread_messages']) ? ' <span class="amt">' . $context['user']['unread_messages'] . '</span>' : '', '</a>
+					<div id="pm_menu" class="top_menu"></div>
+				</li>';
+		}
 
 		echo '
 			</ul>';

+ 10 - 0
Themes/default/languages/PersonalMessage.english.php

@@ -3,6 +3,16 @@
 
 global $context;
 
+// Things for the popup
+$txt['pm_unread'] = 'Unread';
+$txt['pm_sent_short'] = 'Sent';
+$txt['pm_new_short'] = 'New';
+$txt['pm_drafts_short'] = 'Drafts';
+$txt['pm_settings_short'] = 'Settings';
+$txt['pm_no_unread'] = 'No unread messages.';
+$txt['pm_was_sent_to_you'] = 'You received a message.';
+$txt['pm_you_were_replied_to'] = 'A message of yours was replied to.';
+
 $txt['pm_inbox'] = 'Personal Messages Index';
 $txt['send_message'] = 'Send message';
 $txt['pm_add'] = 'Add';

+ 0 - 2
Themes/default/languages/index.english.php

@@ -744,8 +744,6 @@ $txt['pm_short'] = 'My Messages';
 $txt['pm_menu_read'] = 'Read your messages';
 $txt['pm_menu_send'] = 'Send a message';
 
-$txt['hello_member_ndt'] = 'Hello';
-
 $txt['unapproved_posts'] = 'Unapproved Posts (Topics: %1$d, Posts: %2$d)';
 
 $txt['ajax_in_progress'] = 'Loading...';