aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Guse <nathaniel.guse@gmail.com>2012-09-20 10:36:11 -0500
committerNathaniel Guse <nathaniel.guse@gmail.com>2012-09-20 10:36:11 -0500
commit98731b127748af4673fdee92db2e139e84fd4d4b (patch)
tree9c06bcf6c2fd3604a2a338ed633c93e6f1776ef1
parent661dd09d6f44b46e5a30b37bb3425058f055ea01 (diff)
downloadforums-98731b127748af4673fdee92db2e139e84fd4d4b.tar
forums-98731b127748af4673fdee92db2e139e84fd4d4b.tar.gz
forums-98731b127748af4673fdee92db2e139e84fd4d4b.tar.bz2
forums-98731b127748af4673fdee92db2e139e84fd4d4b.tar.xz
forums-98731b127748af4673fdee92db2e139e84fd4d4b.zip
[ticket/11103] Prettify the output for prosilver.
Create a way to mark items read from the output list. PHPBB3-11103
-rw-r--r--phpBB/includes/functions.php5
-rw-r--r--phpBB/includes/notifications/service.php73
-rw-r--r--phpBB/includes/notifications/type/base.php2
-rw-r--r--phpBB/index.php8
-rw-r--r--phpBB/language/en/common.php3
-rw-r--r--phpBB/styles/prosilver/template/ajax.js7
-rw-r--r--phpBB/styles/prosilver/template/overall_header.html18
-rw-r--r--phpBB/styles/prosilver/theme/common.css20
8 files changed, 104 insertions, 32 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index e9d673455c..92cea20d10 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -4997,7 +4997,10 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0
// Output the notifications
$phpbb_notifications = $phpbb_container->get('notifications');
- $notifications = $phpbb_notifications->load_notifications();
+ $notifications = $phpbb_notifications->load_notifications(array(
+ 'all_unread' => true,
+ 'limit' => 5,
+ ));
foreach ($notifications['notifications'] as $notification)
{
$template->assign_block_vars('notifications', $notification->prepare_for_display());
diff --git a/phpBB/includes/notifications/service.php b/phpBB/includes/notifications/service.php
index 777fa9a42f..b1ee420c2e 100644
--- a/phpBB/includes/notifications/service.php
+++ b/phpBB/includes/notifications/service.php
@@ -45,12 +45,14 @@ class phpbb_notifications_service
* Load the user's notifications
*
* @param array $options Optional options to control what notifications are loaded
- * user_id User id to load notifications for (Default: $user->data['user_id'])
- * order_by Order by (Default: time)
- * order_dir Order direction (Default: DESC)
- * limit Number of notifications to load (Default: 5)
- * start Notifications offset (Default: 0)
- * all_unread Load all unread messages? (Default: true)
+ * notification_id Notification id to load (or array of notification ids)
+ * user_id User id to load notifications for (Default: $user->data['user_id'])
+ * order_by Order by (Default: time)
+ * order_dir Order direction (Default: DESC)
+ * limit Number of notifications to load (Default: 5)
+ * start Notifications offset (Default: 0)
+ * all_unread Load all unread messages? If set to true, count_unread is set to true (Default: false)
+ * count_unread Count all unread messages? (Default: false)
*/
public function load_notifications($options = array())
{
@@ -58,14 +60,19 @@ class phpbb_notifications_service
// Merge default options
$options = array_merge(array(
- 'user_id' => $user->data['user_id'],
- 'order_by' => 'time',
- 'order_dir' => 'DESC',
- 'limit' => 5,
- 'start' => 0,
- 'all_unread' => true,
+ 'notification_id' => false,
+ 'user_id' => $user->data['user_id'],
+ 'order_by' => 'time',
+ 'order_dir' => 'DESC',
+ 'limit' => 0,
+ 'start' => 0,
+ 'all_unread' => false,
+ 'count_unread' => false,
), $options);
+ // If all_unread, count_unread mus be true
+ $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread'];
+
// Anonymous users and bots never receive notifications
if ($options['user_id'] == $user->data['user_id'] && ($user->data['user_id'] == ANONYMOUS || $user->data['user_type'] == USER_IGNORE))
{
@@ -77,22 +84,27 @@ class phpbb_notifications_service
$notifications = $user_ids = array();
$load_special = array();
+ $count = 0;
- // Get the total number of unread notifications
- $sql = 'SELECT COUNT(*) AS count
- FROM ' . NOTIFICATIONS_TABLE . '
- WHERE user_id = ' . (int) $options['user_id'] . '
- AND unread = 1';
- $result = $this->db->sql_query($sql);
- $count = $this->db->sql_fetchfield('count', $result);
- $this->db->sql_freeresult($result);
+ if ($options['count_unread'])
+ {
+ // Get the total number of unread notifications
+ $sql = 'SELECT COUNT(*) AS count
+ FROM ' . NOTIFICATIONS_TABLE . '
+ WHERE user_id = ' . (int) $options['user_id'] . '
+ AND unread = 1';
+ $result = $this->db->sql_query($sql);
+ $count = (int) $this->db->sql_fetchfield('count', $result);
+ $this->db->sql_freeresult($result);
+ }
$rowset = array();
// Get the main notifications
$sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . '
- WHERE user_id = ' . (int) $options['user_id'] . '
+ WHERE user_id = ' . (int) $options['user_id'] .
+ (($options['notification_id']) ? ((is_array($options['notification_id'])) ? ' AND ' . $this->db->sql_in_set('notification_id', $options['notification_id']) : ' AND notification_id = ' . (int) $options['notification_id']) : '') . '
ORDER BY ' . $this->db->sql_escape($options['order_by']) . ' ' . $this->db->sql_escape($options['order_dir']);
$result = $this->db->sql_query_limit($sql, $options['limit'], $options['start']);
@@ -103,7 +115,7 @@ class phpbb_notifications_service
$this->db->sql_freeresult($result);
// Get all unread notifications
- if ($options['all_unread'] && !empty($rowset))
+ if ($count && $options['all_unread'] && !empty($rowset))
{
$sql = 'SELECT *
FROM ' . NOTIFICATIONS_TABLE . '
@@ -222,6 +234,23 @@ class phpbb_notifications_service
}
/**
+ * Mark notifications read
+ *
+ * @param int|array $notification_id Notification id or array of notification ids.
+ * @param bool|int $time Time at which to mark all notifications prior to as read. False to mark all as read. (Default: False)
+ */
+ public function mark_notifications_read_by_id($notification_id, $time = false)
+ {
+ $time = ($time) ?: time();
+
+ $sql = 'UPDATE ' . NOTIFICATIONS_TABLE . "
+ SET unread = 0
+ WHERE time <= " . $time . '
+ AND ' . ((is_array($notification_id)) ? $this->db->sql_in_set('notification_id', $notification_id) : 'notification_id = ' . (int) $notification_id);
+ $this->db->sql_query($sql);
+ }
+
+ /**
* Add a notification
*
* @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types)
diff --git a/phpBB/includes/notifications/type/base.php b/phpBB/includes/notifications/type/base.php
index fb75e19cad..710f1f7c6e 100644
--- a/phpBB/includes/notifications/type/base.php
+++ b/phpBB/includes/notifications/type/base.php
@@ -120,6 +120,8 @@ abstract class phpbb_notifications_type_base implements phpbb_notifications_type
'TIME' => $user->format_date($this->time),
'UNREAD' => $this->unread,
+
+ 'U_MARK_READ' => append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification[]=' . $this->notification_id),
);
}
diff --git a/phpBB/index.php b/phpBB/index.php
index 0ac8034d7f..38eeb2514e 100644
--- a/phpBB/index.php
+++ b/phpBB/index.php
@@ -56,6 +56,14 @@ if ($ext = $request->variable('ext', ''))
exit_handler();
}
+// Mark notifications read
+$mark_notifications = request_var('mark_notification', array(0));
+if (!empty($mark_notifications))
+{
+ $phpbb_notifications = $phpbb_container->get('notifications');
+ $phpbb_notifications->mark_notifications_read_by_id($mark_notifications);
+}
+
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
$user->add_lang('viewforum');
diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php
index 90acd0854b..8ad7628891 100644
--- a/phpBB/language/en/common.php
+++ b/phpBB/language/en/common.php
@@ -347,6 +347,7 @@ $lang = array_merge($lang, array(
'MARK' => 'Mark',
'MARK_ALL' => 'Mark all',
'MARK_FORUMS_READ' => 'Mark forums read',
+ 'MARK_READ' => 'Mark read',
'MARK_SUBFORUMS_READ' => 'Mark subforums read',
'MB' => 'MB',
'MIB' => 'MiB',
@@ -385,7 +386,7 @@ $lang = array_merge($lang, array(
'NOT_AUTHORISED' => 'You are not authorised to access this area.',
'NOT_WATCHING_FORUM' => 'You are no longer subscribed to updates on this forum.',
'NOT_WATCHING_TOPIC' => 'You are no longer subscribed to this topic.',
- 'NOTIFICATIONS' => '[ Notifications ]',
+ 'NOTIFICATIONS' => 'Notifications',
'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.',
'NOTIFICATION_PM' => '%1$s sent you a Private Message "%2$s".',
'NOTIFICATION_POST' => '%1$s replied to the topic "%2$s".',
diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js
index 54f34e4204..d98070a114 100644
--- a/phpBB/styles/prosilver/template/ajax.js
+++ b/phpBB/styles/prosilver/template/ajax.js
@@ -77,6 +77,13 @@ $('#qr_full_editor').click(function() {
});
+/**
+ * Toggle notification list
+ */
+$('#notification_list_button').click(function() {
+ $('#notification_list').toggle();
+});
+
/**
* This AJAXifies the quick-mod tools. The reason it cannot be a standard
diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html
index 87e0a2fa92..242ad60e70 100644
--- a/phpBB/styles/prosilver/template/overall_header.html
+++ b/phpBB/styles/prosilver/template/overall_header.html
@@ -130,25 +130,27 @@
<!-- IF not S_IS_BOT and S_USER_LOGGED_IN -->
<ul class="linklist leftside">
- <li class="icon-ucp">
- <a href="{U_PROFILE}" title="{L_PROFILE}" accesskey="e">{L_PROFILE}</a>
- <a href="#" title="{L_NOTIFICATIONS}" onClick="$('#notification_list').toggle();">{L_NOTIFICATIONS}</a>
- <div id="notification_list" style="display: none; position: absolute; width: 330px; max-height: 450px; background-color: #FFFFFF; z-index: 1; overflow-y: scroll;">
- <ul style="list-style-type: none;">
+ <li>
+ [ <a href="#" id="notification_list_button" title="{L_NOTIFICATIONS}">{L_NOTIFICATIONS}</a> ] &bull;
+ <div id="notification_list">
+ <ul class="topiclist forums">
<!-- BEGIN notifications -->
- <li style="padding: 10px; width: 290px;<!-- IF notifications.UNREAD --> background-color: grey;<!-- ENDIF -->">
- <!-- IF notifications.URL --><a href="{notifications.URL}" style="text-decoration: none;"><!-- ENDIF -->
+ <li class="row<!-- IF notifications.UNREAD --> bg2<!-- ENDIF -->">
+ <!-- IF notifications.URL --><a href="{notifications.URL}"><!-- ENDIF -->
{notifications.AVATAR}
<div>
{notifications.FORMATTED_TITLE}<br />
{notifications.TIME}
</div>
<!-- IF notifications.URL --></a><!-- ENDIF -->
+ <!-- IF notifications.UNREAD --><a href="{notifications.U_MARK_READ}" title="{L_MARK_READ}">{L_MARK_READ}</a><!-- ENDIF -->
</li>
<!-- END notifications -->
</ul>
</div>
- <!-- IF S_DISPLAY_PM --> (<a href="{U_PRIVATEMSGS}">{PRIVATE_MESSAGE_INFO}<!-- IF PRIVATE_MESSAGE_INFO_UNREAD -->, {PRIVATE_MESSAGE_INFO_UNREAD}<!-- ENDIF --></a>)<!-- ENDIF -->
+ </li>
+ <li class="icon-ucp">
+ <a href="{U_PROFILE}" title="{L_PROFILE}" accesskey="e">{L_PROFILE}</a>
<!-- IF S_DISPLAY_SEARCH --> &bull;
<a href="{U_SEARCH_SELF}">{L_SEARCH_SELF}</a>
<!-- ENDIF -->
diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css
index d459c6e559..1f5b45e006 100644
--- a/phpBB/styles/prosilver/theme/common.css
+++ b/phpBB/styles/prosilver/theme/common.css
@@ -666,6 +666,26 @@ p.rules a {
vertical-align: text-bottom;
}
+#notification_list {
+ display: none;
+ position: absolute;
+ width: 330px;
+ max-height: 350px;
+ z-index: 1;
+ overflow-y: auto;
+ overflow-x: hidden;
+ background-color: #FFFFFF;
+}
+
+#notification_list ul li {
+ padding: 10px;
+ width: 310px;
+}
+
+#notification_list ul li a {
+ text-decoration: none;
+}
+
#notification_list ul li img {
float: left;
padding: 0 10px 10px 0;