diff options
96 files changed, 7576 insertions, 473 deletions
diff --git a/phpBB/common.php b/phpBB/common.php index e99b9edee5..88e758a004 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -125,6 +125,8 @@ $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); $template = $phpbb_container->get('template'); $phpbb_style = $phpbb_container->get('style'); +$phpbb_notifications = $phpbb_container->get('notification_manager'); + // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'display'))); diff --git a/phpBB/config/notifications.yml b/phpBB/config/notifications.yml new file mode 100644 index 0000000000..f8a5b5f9fa --- /dev/null +++ b/phpBB/config/notifications.yml @@ -0,0 +1,282 @@ +services: + notification.type_collection: + class: phpbb_di_service_collection + arguments: + - @service_container + tags: + - { name: service_collection, tag: notification.type } + + notification.method_collection: + class: phpbb_di_service_collection + arguments: + - @service_container + tags: + - { name: service_collection, tag: notification.method } + + notification.type.approve_post: + class: phpbb_notification_type_approve_post + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.approve_topic: + class: phpbb_notification_type_approve_topic + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.bookmark: + class: phpbb_notification_type_bookmark + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.disapprove_post: + class: phpbb_notification_type_disapprove_post + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.disapprove_topic: + class: phpbb_notification_type_disapprove_topic + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.pm: + class: phpbb_notification_type_pm + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.post: + class: phpbb_notification_type_post + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.post_in_queue: + class: phpbb_notification_type_post_in_queue + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.quote: + class: phpbb_notification_type_quote + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.report_pm: + class: phpbb_notification_type_report_pm + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.report_pm_closed: + class: phpbb_notification_type_report_pm_closed + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.report_post: + class: phpbb_notification_type_report_post + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.report_post_closed: + class: phpbb_notification_type_report_post + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.topic: + class: phpbb_notification_type_topic + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.type.topic_in_queue: + class: phpbb_notification_type_topic_in_queue + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + + notification.method.email: + class: phpbb_notification_method_email + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + tags: + - { name: notification.method } + + notification.method.jabber: + class: phpbb_notification_method_jabber + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + tags: + - { name: notification.method }
\ No newline at end of file diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 37e6c0b5df..35141b84b4 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -1,6 +1,7 @@ imports: - { resource: tables.yml } - { resource: cron_tasks.yml } + - { resource: notifications.yml } services: auth: @@ -154,6 +155,20 @@ services: tags: - { name: kernel.event_subscriber } + notification_manager: + class: phpbb_notification_manager + arguments: + - @notification.type_collection + - @notification.method_collection + - @service_container + - @user_loader + - @dbal.conn + - @user + - %core.root_path% + - %core.php_ext% + - %tables.notifications% + - %tables.user_notifications% + request: class: phpbb_request @@ -195,3 +210,11 @@ services: user: class: phpbb_user + + user_loader: + class: phpbb_user_loader + arguments: + - @dbal.conn + - %core.root_path% + - %core.php_ext% + - %tables.users% diff --git a/phpBB/config/tables.yml b/phpBB/config/tables.yml index cfc6dbcfed..528470d6ca 100644 --- a/phpBB/config/tables.yml +++ b/phpBB/config/tables.yml @@ -1,3 +1,6 @@ parameters: tables.config: %core.table_prefix%config tables.ext: %core.table_prefix%ext + tables.notifications: %core.table_prefix%notifications + tables.user_notifications: %core.table_prefix%user_notifications + tables.users: %core.table_prefix%users diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 3d3e478032..3548bc5f05 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -1295,6 +1295,30 @@ function get_schema_struct() ), ); + $schema_data['phpbb_notifications'] = array( + 'COLUMNS' => array( + 'notification_id' => array('UINT', NULL, 'auto_increment'), + 'item_type' => array('VCHAR:255', ''), + 'item_id' => array('UINT', 0), + 'item_parent_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'unread' => array('BOOL', 1), + 'is_enabled' => array('BOOL', 1), + 'time' => array('TIMESTAMP', 1), + 'data' => array('TEXT_UNI', ''), + ), + 'PRIMARY_KEY' => 'notification_id', + 'KEYS' => array( + 'item_type' => array('INDEX', 'item_type'), + 'item_id' => array('INDEX', 'item_id'), + 'item_pid' => array('INDEX', 'item_parent_id'), + 'user_id' => array('INDEX', 'user_id'), + 'time' => array('INDEX', 'time'), + 'unread' => array('INDEX', 'unread'), + 'is_enabled' => array('INDEX', 'is_enabled'), + ), + ); + $schema_data['phpbb_poll_options'] = array( 'COLUMNS' => array( 'poll_option_id' => array('TINT:4', 0), @@ -1753,6 +1777,27 @@ function get_schema_struct() ), ); + $schema_data['phpbb_user_notifications'] = array( + 'COLUMNS' => array( + 'item_type' => array('VCHAR:255', ''), + 'item_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'method' => array('VCHAR:255', ''), + 'notify' => array('BOOL', 1), + ), + 'PRIMARY_KEY' => array( + 'item_type', + 'item_id', + 'user_id', + 'method', + ), + 'KEYS' => array( + 'it' => array('INDEX', 'item_type'), + 'uid' => array('INDEX', 'user_id'), + 'no' => array('INDEX', 'notify'), + ), + ); + $schema_data['phpbb_user_group'] = array( 'COLUMNS' => array( 'group_id' => array('UINT', 0), diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 322e1c55d8..aed27d7122 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -314,6 +314,7 @@ class acp_board 'load_online_time' => array('lang' => 'ONLINE_LENGTH', 'validate' => 'int:0', 'type' => 'text:4:3', 'explain' => true, 'append' => ' ' . $user->lang['MINUTES']), 'legend2' => 'GENERAL_OPTIONS', + 'load_notifications' => array('lang' => 'LOAD_NOTIFICATIONS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'load_db_track' => array('lang' => 'YES_POST_MARKING', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'load_db_lastread' => array('lang' => 'YES_READ_MARKING', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'load_anon_lastread' => array('lang' => 'YES_ANON_READ_MARKING', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), diff --git a/phpBB/includes/constants.php b/phpBB/includes/constants.php index 68af41ab20..5128321618 100644 --- a/phpBB/includes/constants.php +++ b/phpBB/includes/constants.php @@ -278,4 +278,3 @@ define('WORDS_TABLE', $table_prefix . 'words'); define('ZEBRA_TABLE', $table_prefix . 'zebra'); // Additional tables - diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d7088ac129..69b6932d30 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1328,7 +1328,7 @@ function phpbb_timezone_select($user, $default = '', $truncate = false) function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $user_id = 0) { global $db, $user, $config; - global $request; + global $request, $phpbb_notifications; $post_time = ($post_time === 0 || $post_time > time()) ? time() : (int) $post_time; @@ -1336,6 +1336,18 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ { if ($forum_id === false || !sizeof($forum_id)) { + // Mark all forums read (index page) + + // Mark all topic notifications read for this user + $phpbb_notifications->mark_notifications_read(array( + 'topic', + 'quote', + 'bookmark', + 'post', + 'approve_topic', + 'approve_post', + ), false, $user->data['user_id'], $post_time); + if ($config['load_db_lastread'] && $user->data['is_registered']) { // Mark all forums read (index page) @@ -1390,6 +1402,30 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $forum_id = array($forum_id); } + $phpbb_notifications->mark_notifications_read_by_parent(array( + 'topic', + 'approve_topic', + ), $forum_id, $user->data['user_id'], $post_time); + + // Mark all post/quote notifications read for this user in this forum + $topic_ids = array(); + $sql = 'SELECT topic_id + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('forum_id', $forum_id); + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $topic_ids[] = $row['topic_id']; + } + $db->sql_freeresult($result); + + $phpbb_notifications->mark_notifications_read_by_parent(array( + 'quote', + 'bookmark', + 'post', + 'approve_post', + ), $topic_ids, $user->data['user_id'], $post_time); + // Add 0 to forums array to mark global announcements correctly // $forum_id[] = 0; @@ -1487,6 +1523,18 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ return; } + // Mark post notifications read for this user in this topic + $phpbb_notifications->mark_notifications_read(array( + 'topic', + 'approve_topic', + ), $topic_id, $user->data['user_id'], $post_time); + $phpbb_notifications->mark_notifications_read_by_parent(array( + 'quote', + 'bookmark', + 'post', + 'approve_post', + ), $topic_id, $user->data['user_id'], $post_time); + if ($config['load_db_lastread'] && $user->data['is_registered']) { $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . " @@ -4899,7 +4947,7 @@ function phpbb_http_login($param) function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; - global $phpbb_dispatcher; + global $phpbb_dispatcher, $phpbb_notifications; if (defined('HEADER_INC')) { @@ -5088,6 +5136,20 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 $timezone_name = $user->lang['timezones'][$timezone_name]; } + // Output the notifications + if ($config['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()); + } + } + // The following assigns all _common_ variables that may be used at any point in a template. $template->assign_vars(array( 'SITENAME' => $config['sitename'], @@ -5103,6 +5165,11 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'PRIVATE_MESSAGE_INFO' => $l_privmsgs_text, 'PRIVATE_MESSAGE_INFO_UNREAD' => $l_privmsgs_text_unread, + 'UNREAD_NOTIFICATIONS_COUNT' => ($config['load_notifications']) ? $notifications['unread_count'] : '', + 'NOTIFICATIONS_COUNT' => ($config['load_notifications']) ? $user->lang('NOTIFICATIONS_COUNT', $notifications['unread_count']) : '', + 'U_VIEW_ALL_NOTIFICATIONS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=ucp_notifications'), + 'S_NOTIFICATIONS_DISPLAY' => $config['load_notifications'], + 'S_USER_NEW_PRIVMSG' => $user->data['user_new_privmsg'], 'S_USER_UNREAD_PRIVMSG' => $user->data['user_unread_privmsg'], 'S_USER_NEW' => $user->data['user_new'], diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 5e2ee8c8f6..e15bf12279 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -619,6 +619,7 @@ function move_posts($post_ids, $topic_id, $auto_sync = true) function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_sync = true, $call_delete_posts = true) { global $db, $config; + global $phpbb_notifications; $approved_topics = 0; $forum_ids = $topic_ids = array(); @@ -715,6 +716,12 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s set_config_count('num_topics', $approved_topics * (-1), true); } + $phpbb_notifications->delete_notifications(array( + 'topic', + 'approve_topic', + 'topic_in_queue', + ), $topic_ids); + return $return; } @@ -724,6 +731,7 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true) { global $db, $config, $phpbb_root_path, $phpEx, $auth, $user; + global $phpbb_notifications; if ($where_type === 'range') { @@ -892,6 +900,14 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = delete_topics('topic_id', $remove_topics, $auto_sync, $post_count_sync, false); } + $phpbb_notifications->delete_notifications(array( + 'quote', + 'bookmark', + 'post', + 'approve_post', + 'post_in_queue', + ), $post_ids); + return sizeof($post_ids); } diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 171cf988ce..8ba1fed6a7 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -61,7 +61,7 @@ function generate_smilies($mode, $forum_id) 'body' => 'posting_smilies.html') ); - generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start); + generate_pagination(append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=smilies&f=' . $forum_id), $smiley_count, $config['smilies_per_page'], $start); } $display_link = false; @@ -1175,238 +1175,6 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id return true; } -/** -* User Notification -*/ -function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id, $author_name = '') -{ - global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; - - $topic_notification = ($mode == 'reply' || $mode == 'quote') ? true : false; - $forum_notification = ($mode == 'post') ? true : false; - - if (!$topic_notification && !$forum_notification) - { - trigger_error('NO_MODE'); - } - - if (($topic_notification && !$config['allow_topic_notify']) || ($forum_notification && !$config['allow_forum_notify'])) - { - return; - } - - $topic_title = ($topic_notification) ? $topic_title : $subject; - $topic_title = censor_text($topic_title); - - // Exclude guests, current user and banned users from notifications - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - $sql_ignore_users = phpbb_get_banned_user_ids(); - $sql_ignore_users[ANONYMOUS] = ANONYMOUS; - $sql_ignore_users[$user->data['user_id']] = $user->data['user_id']; - - $notify_rows = array(); - - // -- get forum_userids || topic_userids - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber - FROM ' . (($topic_notification) ? TOPICS_WATCH_TABLE : FORUMS_WATCH_TABLE) . ' w, ' . USERS_TABLE . ' u - WHERE w.' . (($topic_notification) ? 'topic_id' : 'forum_id') . ' = ' . (($topic_notification) ? $topic_id : $forum_id) . ' - AND ' . $db->sql_in_set('w.user_id', $sql_ignore_users, true) . ' - AND w.notify_status = ' . NOTIFY_YES . ' - AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - AND u.user_id = w.user_id'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $notify_user_id = (int) $row['user_id']; - $notify_rows[$notify_user_id] = array( - 'user_id' => $notify_user_id, - 'username' => $row['username'], - 'user_email' => $row['user_email'], - 'user_jabber' => $row['user_jabber'], - 'user_lang' => $row['user_lang'], - 'notify_type' => ($topic_notification) ? 'topic' : 'forum', - 'template' => ($topic_notification) ? 'topic_notify' : 'newtopic_notify', - 'method' => $row['user_notify_type'], - 'allowed' => false - ); - - // Add users who have been already notified to ignore list - $sql_ignore_users[$notify_user_id] = $notify_user_id; - } - $db->sql_freeresult($result); - - // forum notification is sent to those not already receiving topic notifications - if ($topic_notification) - { - $sql = 'SELECT u.user_id, u.username, u.user_email, u.user_lang, u.user_notify_type, u.user_jabber - FROM ' . FORUMS_WATCH_TABLE . ' fw, ' . USERS_TABLE . " u - WHERE fw.forum_id = $forum_id - AND " . $db->sql_in_set('fw.user_id', $sql_ignore_users, true) . ' - AND fw.notify_status = ' . NOTIFY_YES . ' - AND u.user_type IN (' . USER_NORMAL . ', ' . USER_FOUNDER . ') - AND u.user_id = fw.user_id'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $notify_user_id = (int) $row['user_id']; - $notify_rows[$notify_user_id] = array( - 'user_id' => $notify_user_id, - 'username' => $row['username'], - 'user_email' => $row['user_email'], - 'user_jabber' => $row['user_jabber'], - 'user_lang' => $row['user_lang'], - 'notify_type' => 'forum', - 'template' => 'forum_notify', - 'method' => $row['user_notify_type'], - 'allowed' => false - ); - } - $db->sql_freeresult($result); - } - - if (!sizeof($notify_rows)) - { - return; - } - - // Make sure users are allowed to read the forum - foreach ($auth->acl_get_list(array_keys($notify_rows), 'f_read', $forum_id) as $forum_id => $forum_ary) - { - foreach ($forum_ary as $auth_option => $user_ary) - { - foreach ($user_ary as $user_id) - { - $notify_rows[$user_id]['allowed'] = true; - } - } - } - - // Now, we have to do a little step before really sending, we need to distinguish our users a little bit. ;) - $msg_users = $delete_ids = $update_notification = array(); - foreach ($notify_rows as $user_id => $row) - { - if (!$row['allowed'] || !trim($row['user_email'])) - { - $delete_ids[$row['notify_type']][] = $row['user_id']; - } - else - { - $msg_users[] = $row; - $update_notification[$row['notify_type']][] = $row['user_id']; - - /* - * We also update the forums watch table for this user when we are - * sending out a topic notification to prevent sending out another - * notification in case this user is also subscribed to the forum - * this topic was posted in. - * Since an UPDATE query is used, this has no effect on users only - * subscribed to the topic (i.e. no row is created) and should not - * be a performance issue. - */ - if ($row['notify_type'] === 'topic') - { - $update_notification['forum'][] = $row['user_id']; - } - } - } - unset($notify_rows); - - // Now, we are able to really send out notifications - if (sizeof($msg_users)) - { - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(); - - $msg_list_ary = array(); - foreach ($msg_users as $row) - { - $pos = (!isset($msg_list_ary[$row['template']])) ? 0 : sizeof($msg_list_ary[$row['template']]); - - $msg_list_ary[$row['template']][$pos]['method'] = $row['method']; - $msg_list_ary[$row['template']][$pos]['email'] = $row['user_email']; - $msg_list_ary[$row['template']][$pos]['jabber'] = $row['user_jabber']; - $msg_list_ary[$row['template']][$pos]['name'] = $row['username']; - $msg_list_ary[$row['template']][$pos]['lang'] = $row['user_lang']; - $msg_list_ary[$row['template']][$pos]['user_id']= $row['user_id']; - } - unset($msg_users); - - foreach ($msg_list_ary as $email_template => $email_list) - { - foreach ($email_list as $addr) - { - $messenger->template($email_template, $addr['lang']); - - $messenger->to($addr['email'], $addr['name']); - $messenger->im($addr['jabber'], $addr['name']); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($addr['name']), - 'TOPIC_TITLE' => htmlspecialchars_decode($topic_title), - 'FORUM_NAME' => htmlspecialchars_decode($forum_name), - 'AUTHOR_NAME' => htmlspecialchars_decode($author_name), - - 'U_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id", - 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id", - 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id&p=$post_id&e=$post_id", - 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?uid={$addr['user_id']}&f=$forum_id&t=$topic_id&unwatch=topic", - 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.$phpEx?uid={$addr['user_id']}&f=$forum_id&unwatch=forum", - )); - - $messenger->send($addr['method']); - } - } - unset($msg_list_ary); - - $messenger->save_queue(); - } - - // Handle the DB updates - $db->sql_transaction('begin'); - - if (!empty($update_notification['topic'])) - { - $sql = 'UPDATE ' . TOPICS_WATCH_TABLE . ' - SET notify_status = ' . NOTIFY_NO . " - WHERE topic_id = $topic_id - AND " . $db->sql_in_set('user_id', $update_notification['topic']); - $db->sql_query($sql); - } - - if (!empty($update_notification['forum'])) - { - $sql = 'UPDATE ' . FORUMS_WATCH_TABLE . ' - SET notify_status = ' . NOTIFY_NO . " - WHERE forum_id = $forum_id - AND " . $db->sql_in_set('user_id', $update_notification['forum']); - $db->sql_query($sql); - } - - // Now delete the user_ids not authorised to receive notifications on this topic/forum - if (!empty($delete_ids['topic'])) - { - $sql = 'DELETE FROM ' . TOPICS_WATCH_TABLE . " - WHERE topic_id = $topic_id - AND " . $db->sql_in_set('user_id', $delete_ids['topic']); - $db->sql_query($sql); - } - - if (!empty($delete_ids['forum'])) - { - $sql = 'DELETE FROM ' . FORUMS_WATCH_TABLE . " - WHERE forum_id = $forum_id - AND " . $db->sql_in_set('user_id', $delete_ids['forum']); - $db->sql_query($sql); - } - - $db->sql_transaction('commit'); -} - // // Post handling functions // @@ -1643,6 +1411,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data) function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $update_message = true, $update_search_index = true) { global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path; + global $phpbb_notifications; // We do not handle erasing posts here if ($mode == 'delete') @@ -2453,10 +2222,73 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u } // Send Notifications - if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) + $notification_data = array_merge($data, array( + 'topic_title' => (isset($data['topic_title'])) ? $data['topic_title'] : $subject, + 'post_username' => $username, + 'poster_id' => $poster_id, + 'post_text' => $data['message'], + 'post_time' => $current_time, + 'post_subject' => $subject, + )); + + if ($post_approval) + { + switch ($mode) + { + case 'post': + $phpbb_notifications->add_notifications(array( + 'quote', + 'topic', + ), $notification_data); + break; + + case 'reply': + case 'quote': + $phpbb_notifications->add_notifications(array( + 'quote', + 'bookmark', + 'post', + ), $notification_data); + break; + + case 'edit_topic': + case 'edit_first_post': + case 'edit': + case 'edit_last_post': + $phpbb_notifications->update_notifications(array( + 'quote', + 'bookmark', + 'topic', + 'post', + ), $notification_data); + break; + } + } + else { - $username = ($username) ? $username : $user->data['username']; - user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id'], $username); + switch ($mode) + { + case 'post': + $phpbb_notifications->add_notifications('topic_in_queue', $notification_data); + break; + + case 'reply': + case 'quote': + $phpbb_notifications->add_notifications('post_in_queue', $notification_data); + break; + + case 'edit_topic': + case 'edit_first_post': + case 'edit': + case 'edit_last_post': + $phpbb_notifications->delete_notifications('topic', $data['topic_id']); + $phpbb_notifications->delete_notifications(array( + 'quote', + 'bookmark', + 'post', + ), $data['post_id']); + break; + } } $params = $add_anchor = ''; diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index ba939d490e..ae8ffbe90e 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -876,7 +876,9 @@ function update_unread_status($unread, $msg_id, $user_id, $folder_id) return; } - global $db, $user; + global $db, $user, $phpbb_notifications; + + $phpbb_notifications->mark_notifications_read('pm', $msg_id, $user_id); $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . " SET pm_unread = 0 @@ -982,6 +984,7 @@ function handle_mark_actions($user_id, $mark_action) function delete_pm($user_id, $msg_ids, $folder_id) { global $db, $user, $phpbb_root_path, $phpEx; + global $phpbb_notifications; $user_id = (int) $user_id; $folder_id = (int) $folder_id; @@ -1093,6 +1096,8 @@ function delete_pm($user_id, $msg_ids, $folder_id) $user->data['user_unread_privmsg'] -= $num_unread; } + $phpbb_notifications->delete_notifications('pm', array_keys($delete_rows)); + // Now we have to check which messages we can delete completely $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TO_TABLE . ' @@ -1158,6 +1163,7 @@ function phpbb_delete_user_pms($user_id) function phpbb_delete_users_pms($user_ids) { global $db, $user, $phpbb_root_path, $phpEx; + global $phpbb_notifications; $user_id_sql = $db->sql_in_set('user_id', $user_ids); $author_id_sql = $db->sql_in_set('author_id', $user_ids); @@ -1270,6 +1276,8 @@ function phpbb_delete_users_pms($user_ids) WHERE folder_id = ' . PRIVMSGS_NO_BOX . ' AND ' . $db->sql_in_set('msg_id', $delivered_msg); $db->sql_query($sql); + + $phpbb_notifications->delete_notifications('pm', $delivered_msg); } if (!empty($undelivered_msg)) @@ -1281,6 +1289,8 @@ function phpbb_delete_users_pms($user_ids) $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg); $db->sql_query($sql); + + $phpbb_notifications->delete_notifications('pm', $undelivered_msg); } } @@ -1323,6 +1333,8 @@ function phpbb_delete_users_pms($user_ids) $sql = 'DELETE FROM ' . PRIVMSGS_TABLE . ' WHERE ' . $db->sql_in_set('msg_id', $delete_ids); $db->sql_query($sql); + + $phpbb_notifications->delete_notifications('pm', $delete_ids); } } @@ -1560,6 +1572,7 @@ function get_folder_status($folder_id, $folder) function submit_pm($mode, $subject, &$data, $put_in_outbox = true) { global $db, $auth, $config, $phpEx, $template, $user, $phpbb_root_path; + global $phpbb_notifications; // We do not handle erasing pms here if ($mode == 'delete') @@ -1859,95 +1872,21 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true) $db->sql_transaction('commit'); // Send Notifications - if ($mode != 'edit') - { - pm_notification($mode, $data['from_username'], $recipients, $subject, $data['message'], $data['msg_id']); - } - - return $data['msg_id']; -} - -/** -* PM Notification -*/ -function pm_notification($mode, $author, $recipients, $subject, $message, $msg_id) -{ - global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; - - $subject = censor_text($subject); - - // Exclude guests, current user and banned users from notifications - unset($recipients[ANONYMOUS], $recipients[$user->data['user_id']]); - - if (!sizeof($recipients)) - { - return; - } - - if (!function_exists('phpbb_get_banned_user_ids')) - { - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - } - $banned_users = phpbb_get_banned_user_ids(array_keys($recipients)); - $recipients = array_diff(array_keys($recipients), $banned_users); - - if (!sizeof($recipients)) - { - return; - } - - $sql = 'SELECT user_id, username, user_email, user_lang, user_notify_pm, user_notify_type, user_jabber - FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $recipients); - $result = $db->sql_query($sql); - - $msg_list_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - if ($row['user_notify_pm'] == 1 && trim($row['user_email'])) - { - $msg_list_ary[] = array( - 'method' => $row['user_notify_type'], - 'email' => $row['user_email'], - 'jabber' => $row['user_jabber'], - 'name' => $row['username'], - 'lang' => $row['user_lang'] - ); - } - } - $db->sql_freeresult($result); + $pm_data = array_merge($data, array( + 'message_subject' => $subject, + 'recipients' => $recipients, + )); - if (!sizeof($msg_list_ary)) + if ($mode == 'edit') { - return; + $phpbb_notifications->update_notifications('pm', $pm_data); } - - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(); - - foreach ($msg_list_ary as $pos => $addr) + else { - $messenger->template('privmsg_notify', $addr['lang']); - - $messenger->to($addr['email'], $addr['name']); - $messenger->im($addr['jabber'], $addr['name']); - - $messenger->assign_vars(array( - 'SUBJECT' => htmlspecialchars_decode($subject), - 'AUTHOR_NAME' => htmlspecialchars_decode($author), - 'USERNAME' => htmlspecialchars_decode($addr['name']), - - 'U_INBOX' => generate_board_url() . "/ucp.$phpEx?i=pm&folder=inbox", - 'U_VIEW_MESSAGE' => generate_board_url() . "/ucp.$phpEx?i=pm&mode=view&p=$msg_id", - )); - - $messenger->send($addr['method']); + $phpbb_notifications->add_notifications('pm', $pm_data); } - unset($msg_list_ary); - - $messenger->save_queue(); - unset($messenger); + return $data['msg_id']; } /** diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index be18dba944..4ba1b2fd0c 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -34,6 +34,7 @@ class mcp_pm_reports { global $auth, $db, $user, $template, $cache; global $config, $phpbb_root_path, $phpEx, $action; + global $phpbb_notifications; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx); @@ -89,6 +90,8 @@ class mcp_pm_reports trigger_error('NO_REPORT'); } + $phpbb_notifications->mark_notifications_read_by_parent('report_pm', $report_id, $user->data['user_id']); + $pm_id = $report['pm_id']; $report_id = $report['report_id']; diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index 0b195aa9d8..4a3d443006 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -34,6 +34,7 @@ class mcp_queue { global $auth, $db, $user, $template, $cache; global $config, $phpbb_root_path, $phpEx, $action; + global $phpbb_notifications; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -84,6 +85,8 @@ class mcp_queue if (isset($topic_info[$topic_id]['topic_first_post_id'])) { $post_id = (int) $topic_info[$topic_id]['topic_first_post_id']; + + $phpbb_notifications->mark_notifications_read('topic_in_queue', $topic_id, $user->data['user_id']); } else { @@ -91,6 +94,8 @@ class mcp_queue } } + $phpbb_notifications->mark_notifications_read('post_in_queue', $post_id, $user->data['user_id']); + $post_info = get_post_data(array($post_id), 'm_approve', true); if (!sizeof($post_info)) @@ -451,7 +456,7 @@ function approve_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request; + global $request, $phpbb_notifications; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -597,54 +602,37 @@ function approve_post($post_id_list, $id, $mode) 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('<br />', "\n", "-- \n" . $config['board_email_sig']); + // Handle notifications 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); + $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); + + $phpbb_notifications->add_notifications('topic', $post_data); + + if ($notify_poster) + { + $phpbb_notifications->add_notifications('approve_topic', $post_data); + } } 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); + $phpbb_notifications->delete_notifications('post_in_queue', $post_id); + + $phpbb_notifications->add_notifications(array( + 'quote', + 'bookmark', + 'post', + ), $post_data); + + if ($notify_poster) + { + $phpbb_notifications->add_notifications('approve_post', $post_data); + } } } @@ -734,7 +722,7 @@ function disapprove_post($post_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $phpbb_root_path; - global $request; + global $request, $phpbb_notifications; if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_approve'))) { @@ -867,20 +855,27 @@ function disapprove_post($post_id_list, $id, $mode) } } - $messenger = new messenger(); + 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']) + { + $phpbb_notifications->delete_notifications('topic_in_queue', $post_data['topic_id']); + } + else + { + $phpbb_notifications->delete_notifications('post_in_queue', $post_id); + } + } // Notify Poster? if ($notify_poster) { $lang_reasons = array(); + // Handle notifications foreach ($post_info as $post_id => $post_data) { - if ($post_data['poster_id'] == ANONYMOUS) - { - continue; - } - + $post_data['disapprove_reason'] = ''; if (isset($disapprove_reason_lang)) { // Okay we need to get the reason from the posters language @@ -906,33 +901,30 @@ function disapprove_post($post_id_list, $id, $mode) } } - $email_disapprove_reason = $lang_reasons[$post_data['user_lang']]; - $email_disapprove_reason .= ($reason) ? "\n\n" . $reason : ''; + $post_data['disapprove_reason'] = $lang_reasons[$post_data['user_lang']]; + $post_data['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']); + if ($post_id == $post_data['topic_first_post_id'] && $post_id == $post_data['topic_last_post_id']) + { + if ($notify_poster) + { + $phpbb_notifications->add_notifications('disapprove_topic', $post_data); + } + } + else + { + if ($notify_poster) + { + $phpbb_notifications->add_notifications('disapprove_post', $post_data); + } + } } 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'; diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 3426d62cdb..85723ab3f7 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -34,6 +34,7 @@ class mcp_reports { global $auth, $db, $user, $template, $cache; global $config, $phpbb_root_path, $phpEx, $action; + global $phpbb_notifications; include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx); @@ -87,6 +88,8 @@ class mcp_reports trigger_error('NO_REPORT'); } + $phpbb_notifications->mark_notifications_read('report_post', $post_id, $user->data['user_id']); + if (!$report_id && $report['report_closed']) { trigger_error('REPORT_CLOSED'); @@ -444,6 +447,7 @@ function close_report($report_id_list, $mode, $action, $pm = false) { global $db, $template, $user, $config, $auth; global $phpEx, $phpbb_root_path; + global $phpbb_notifications; $pm_where = ($pm) ? ' AND r.post_id = 0 ' : ' AND r.pm_id = 0 '; $id_column = ($pm) ? 'pm_id' : 'post_id'; @@ -629,8 +633,6 @@ function close_report($report_id_list, $mode, $action, $pm = false) } } - $messenger = new messenger(); - // Notify reporters if (sizeof($notify_reporters)) { @@ -643,30 +645,23 @@ function close_report($report_id_list, $mode, $action, $pm = false) $post_id = $reporter[$id_column]; - $messenger->template((($pm) ? 'pm_report_' : 'report_') . $action . 'd', $reporter['user_lang']); - - $messenger->to($reporter['user_email'], $reporter['username']); - $messenger->im($reporter['user_jabber'], $reporter['username']); - if ($pm) { - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($reporter['username']), - 'CLOSER_NAME' => htmlspecialchars_decode($user->data['username']), - 'PM_SUBJECT' => htmlspecialchars_decode(censor_text($post_info[$post_id]['message_subject'])), - )); + $phpbb_notifications->add_notifications('report_pm_closed', array_merge($post_info[$post_id], array( + 'reporter' => $reporter['user_id'], + 'closer_id' => $user->data['user_id'], + 'from_user_id' => $post_info[$post_id]['author_id'], + ))); + $phpbb_notifications->delete_notifications('report_pm', $post_id); } else { - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($reporter['username']), - 'CLOSER_NAME' => htmlspecialchars_decode($user->data['username']), - 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_info[$post_id]['post_subject'])), - 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_info[$post_id]['topic_title']))) - ); + $phpbb_notifications->add_notifications('report_post_closed', array_merge($post_info[$post_id], array( + 'reporter' => $reporter['user_id'], + 'closer_id' => $user->data['user_id'], + ))); + $phpbb_notifications->delete_notifications('report_post', $post_id); } - - $messenger->send($reporter['user_notify_type']); } } @@ -681,8 +676,6 @@ function close_report($report_id_list, $mode, $action, $pm = false) unset($notify_reporters, $post_info, $reports); - $messenger->save_queue(); - $success_msg = (sizeof($report_id_list) == 1) ? "{$pm_prefix}REPORT_" . strtoupper($action) . 'D_SUCCESS' : "{$pm_prefix}REPORTS_" . strtoupper($action) . 'D_SUCCESS'; } else diff --git a/phpBB/includes/notification/manager.php b/phpBB/includes/notification/manager.php new file mode 100644 index 0000000000..ea91496fb9 --- /dev/null +++ b/phpBB/includes/notification/manager.php @@ -0,0 +1,798 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Notifications service class +* @package notifications +*/ +class phpbb_notification_manager +{ + /** @var array */ + protected $notification_types = null; + + /** @var array */ + protected $notification_methods = null; + + /** @var ContainerBuilder */ + protected $phpbb_container = null; + + /** @var phpbb_user_loader */ + protected $user_loader = null; + + /** @var dbal */ + protected $db = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; + + /** @var string */ + protected $notifications_table = null; + + /** @var string */ + protected $user_notifications_table = null; + + public function __construct($notification_types, $notification_methods, $phpbb_container, phpbb_user_loader $user_loader, dbal $db, $user, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + { + $this->notification_types = $notification_types; + $this->notification_methods = $notification_methods; + $this->phpbb_container = $phpbb_container; + + $this->user_loader = $user_loader; + $this->db = $db; + $this->user = $user; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->notifications_table = $notifications_table; + $this->user_notifications_table = $user_notifications_table; + } + + /** + * Load the user's notifications + * + * @param array $options Optional options to control what notifications are loaded + * 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 notifications? If set to true, count_unread is set to true (Default: false) + * count_unread Count all unread notifications? (Default: false) + * count_total Count all notifications? (Default: false) + * @return array Array of information based on the request with keys: + * 'notifications' array of notification type objects + * 'unread_count' number of unread notifications the user has if count_unread is true in the options + * 'total_count' number of notifications the user has if count_total is true in the options + */ + public function load_notifications(array $options = array()) + { + // Merge default options + $options = array_merge(array( + 'notification_id' => false, + 'user_id' => $this->user->data['user_id'], + 'order_by' => 'time', + 'order_dir' => 'DESC', + 'limit' => 0, + 'start' => 0, + 'all_unread' => false, + 'count_unread' => false, + 'count_total' => false, + ), $options); + + // If all_unread, count_unread must be true + $options['count_unread'] = ($options['all_unread']) ? true : $options['count_unread']; + + // Anonymous users and bots never receive notifications + if ($options['user_id'] == $this->user->data['user_id'] && ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['user_type'] == USER_IGNORE)) + { + return array( + 'notifications' => array(), + 'unread_count' => 0, + 'total_count' => 0, + ); + } + + $notifications = $user_ids = array(); + $load_special = array(); + $total_count = $unread_count = 0; + + if ($options['count_unread']) + { + // Get the total number of unread notifications + $sql = 'SELECT COUNT(*) AS unread_count + FROM ' . $this->notifications_table . ' + WHERE user_id = ' . (int) $options['user_id'] . ' + AND unread = 1 + AND is_enabled = 1'; + $result = $this->db->sql_query($sql); + $unread_count = (int) $this->db->sql_fetchfield('unread_count', $result); + $this->db->sql_freeresult($result); + } + + if ($options['count_total']) + { + // Get the total number of notifications + $sql = 'SELECT COUNT(*) AS total_count + FROM ' . $this->notifications_table . ' + WHERE user_id = ' . (int) $options['user_id'] . ' + AND is_enabled = 1'; + $result = $this->db->sql_query($sql); + $total_count = (int) $this->db->sql_fetchfield('total_count', $result); + $this->db->sql_freeresult($result); + } + + if (!$options['count_total'] || $total_count) + { + $rowset = array(); + + // Get the main notifications + $sql = 'SELECT * + FROM ' . $this->notifications_table . ' + 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']) : '') . ' + AND is_enabled = 1 + 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']); + + while ($row = $this->db->sql_fetchrow($result)) + { + $rowset[$row['notification_id']] = $row; + } + $this->db->sql_freeresult($result); + + // Get all unread notifications + if ($unread_count && $options['all_unread'] && !empty($rowset)) + { + $sql = 'SELECT * + FROM ' . $this->notifications_table . ' + WHERE user_id = ' . (int) $options['user_id'] . ' + AND unread = 1 + AND ' . $this->db->sql_in_set('notification_id', array_keys($rowset), true) . ' + AND is_enabled = 1 + 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']); + + while ($row = $this->db->sql_fetchrow($result)) + { + $rowset[$row['notification_id']] = $row; + } + $this->db->sql_freeresult($result); + } + + foreach ($rowset as $row) + { + $notification = $this->get_item_type_class($row['item_type'], $row); + + // Array of user_ids to query all at once + $user_ids = array_merge($user_ids, $notification->users_to_query()); + + // Some notification types also require querying additional tables themselves + if (!isset($load_special[$row['item_type']])) + { + $load_special[$row['item_type']] = array(); + } + $load_special[$row['item_type']] = array_merge($load_special[$row['item_type']], $notification->get_load_special()); + + $notifications[$row['notification_id']] = $notification; + } + + $this->user_loader->load_users($user_ids); + + // Allow each type to load its own special items + foreach ($load_special as $item_type => $data) + { + $item_class = $this->get_item_type_class($item_type); + + $item_class->load_special($data, $notifications); + } + } + + return array( + 'notifications' => $notifications, + 'unread_count' => $unread_count, + 'total_count' => $total_count, + ); + } + + /** + * Mark notifications read + * + * @param bool|string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types). False to mark read for all item types + * @param bool|int|array $item_id Item id or array of item ids. False to mark read for all item ids + * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user 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($item_type, $item_id, $user_id, $time = false) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->mark_notifications_read($type, $item_id, $user_id, $time); + } + + return; + } + + $time = ($time !== false) ? $time : time(); + + $sql = 'UPDATE ' . $this->notifications_table . " + SET unread = 0 + WHERE time <= " . $time . + (($item_type !== false) ? ' AND ' . (is_array($item_type) ? $this->db->sql_in_set('item_type', $item_type) : " item_type = '" . $this->db->sql_escape($item_type) . "'") : '') . + (($item_id !== false) ? ' AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) : '') . + (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); + $this->db->sql_query($sql); + } + + /** + * Mark notifications read from a parent identifier + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * @param bool|int|array $item_parent_id Item parent id or array of item parent ids. False to mark read for all item parent ids + * @param bool|int|array $user_id User id or array of user ids. False to mark read for all user 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_parent($item_type, $item_parent_id, $user_id, $time = false) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->mark_notifications_read_by_parent($type, $item_parent_id, $user_id, $time); + } + + return; + } + + $time = ($time !== false) ? $time : time(); + + $sql = 'UPDATE ' . $this->notifications_table . " + SET unread = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND time <= " . $time . + (($item_parent_id !== false) ? ' AND ' . (is_array($item_parent_id) ? $this->db->sql_in_set('item_parent_id', $item_parent_id) : 'item_parent_id = ' . (int) $item_parent_id) : '') . + (($user_id !== false) ? ' AND ' . (is_array($user_id) ? $this->db->sql_in_set('user_id', $user_id) : 'user_id = ' . (int) $user_id) : ''); + $this->db->sql_query($sql); + } + + /** + * 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 !== false) ? $time : time(); + + $sql = 'UPDATE ' . $this->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) + * Note: If you send an array of types, any user who could receive multiple notifications from this single item will only receive + * a single notification. If they MUST receive multiple notifications, call this function multiple times instead of sending an array + * @param array $data Data specific for this type that will be inserted + * @param array $options Optional options to control what notifications are loaded + * ignore_users array of data to specify which users should not receive certain types of notifications + * @return array Information about what users were notified and how they were notified + */ + public function add_notifications($item_type, $data, array $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + if (is_array($item_type)) + { + $notified_users = array(); + $temp_options = $options; + + foreach ($item_type as $type) + { + $temp_options['ignore_users'] = $options['ignore_users'] + $notified_users; + $notified_users += $this->add_notifications($type, $data, $temp_options); + } + + return $notified_users; + } + + $item_id = $this->get_item_type_class($item_type)->get_item_id($data); + + // find out which users want to receive this type of notification + $notify_users = $this->get_item_type_class($item_type)->find_users_for_notification($data, $options); + + $this->add_notifications_for_users($item_type, $data, $notify_users); + + return $notify_users; + } + + /** + * Add a notification for specific users + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $data is identical for the specified types) + * @param array $data Data specific for this type that will be inserted + * @param array $notify_users User list to notify + */ + public function add_notifications_for_users($item_type, $data, $notify_users) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->add_notifications_for_users($type, $data, $notify_users); + } + + return; + } + + $item_id = $this->get_item_type_class($item_type)->get_item_id($data); + + $user_ids = array(); + $notification_objects = $notification_methods = array(); + $new_rows = array(); + + // Never send notifications to the anonymous user! + unset($notify_users[ANONYMOUS]); + + // Make sure not to send new notifications to users who've already been notified about this item + // This may happen when an item was added, but now new users are able to see the item + $sql = 'SELECT user_id + FROM ' . $this->notifications_table . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND is_enabled = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + unset($notify_users[$row['user_id']]); + } + $this->db->sql_freeresult($result); + + if (!sizeof($notify_users)) + { + return; + } + + // Allow notifications to perform actions before creating the insert array (such as run a query to cache some data needed for all notifications) + $notification = $this->get_item_type_class($item_type); + $pre_create_data = $notification->pre_create_insert_array($data, $notify_users); + unset($notification); + + // Go through each user so we can insert a row in the DB and then notify them by their desired means + foreach ($notify_users as $user => $methods) + { + $notification = $this->get_item_type_class($item_type); + + $notification->user_id = (int) $user; + + // Store the creation array in our new rows that will be inserted later + $new_rows[] = $notification->create_insert_array($data, $pre_create_data); + + // Users are needed to send notifications + $user_ids = array_merge($user_ids, $notification->users_to_query()); + + foreach ($methods as $method) + { + // setup the notification methods and add the notification to the queue + if ($method) // blank means we just insert it as a notification, but do not notify them by any other means + { + if (!isset($notification_methods[$method])) + { + $notification_methods[$method] = $this->get_method_class($method); + } + + $notification_methods[$method]->add_to_queue($notification); + } + } + } + + // insert into the db + $this->db->sql_multi_insert($this->notifications_table, $new_rows); + + // We need to load all of the users to send notifications + $this->user_loader->load_users($user_ids); + + // run the queue for each method to send notifications + foreach ($notification_methods as $method) + { + $method->notify(); + } + } + + /** + * Update 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) + * @param array $data Data specific for this type that will be updated + */ + public function update_notifications($item_type, $data) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->update_notifications($type, $data); + } + + return; + } + + $notification = $this->get_item_type_class($item_type); + + // Allow the notifications class to over-ride the update_notifications functionality + if (method_exists($notification, 'update_notifications')) + { + // Return False to over-ride the rest of the update + if ($notification->update_notifications($data) === false) + { + return; + } + } + + $item_id = $notification->get_item_id($data); + $update_array = $notification->create_update_array($data); + + $sql = 'UPDATE ' . $this->notifications_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $update_array) . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id; + $this->db->sql_query($sql); + } + + /** + * Delete a notification + * + * @param string|array $item_type Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types) + * @param int|array $item_id Identifier within the type (or array of ids) + * @param array $data Data specific for this type that will be updated + */ + public function delete_notifications($item_type, $item_id) + { + if (is_array($item_type)) + { + foreach ($item_type as $type) + { + $this->delete_notifications($type, $item_id); + } + + return; + } + + $sql = 'DELETE FROM ' . $this->notifications_table . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND " . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id); + $this->db->sql_query($sql); + } + + /** + * Get all of the subscription types + * + * @return array Array of item types + */ + public function get_subscription_types() + { + $subscription_types = array(); + + foreach ($this->notification_types as $type_name => $data) + { + $type = $this->get_item_type_class($type_name); + + if ($type instanceof phpbb_notification_type_interface && $type->is_available()) + { + $options = array_merge(array( + 'id' => $type->get_type(), + 'lang' => 'NOTIFICATION_TYPE_' . strtoupper($type->get_type()), + 'group' => 'NOTIFICATION_GROUP_MISCELLANEOUS', + ), (($type::$notification_option !== false) ? $type::$notification_option : array())); + + $subscription_types[$options['group']][$options['id']] = $options; + } + } + + // Move Miscellaneous to the very last section + if (isset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'])) + { + $miscellaneous = $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']; + unset($subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); + $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS'] = $miscellaneous; + } + + return $subscription_types; + } + + /** + * Get all of the subscription methods + * + * @return array Array of methods + */ + public function get_subscription_methods() + { + $subscription_methods = array(); + + foreach ($this->notification_methods as $method_name => $data) + { + $method = $this->get_method_class($method_name); + + if ($method instanceof phpbb_notification_method_interface && $method->is_available()) + { + $subscription_methods[$method_name] = array( + 'id' => $method->get_type(), + 'lang' => 'NOTIFICATION_METHOD_' . strtoupper($method->get_type()), + ); + } + } + + return $subscription_methods; + } + + /** + * Get global subscriptions (item_id = 0) + * + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + * + * @return array Subscriptions + */ + public function get_global_subscriptions($user_id = false) + { + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; + + $subscriptions = array(); + + foreach ($this->get_subscription_types() as $group_name => $types) + { + foreach ($types as $id => $type) + { + $sql = 'SELECT method, notify + FROM ' . $this->user_notifications_table . ' + WHERE user_id = ' . (int) $user_id . " + AND item_type = '" . $this->db->sql_escape($id) . "' + AND item_id = 0"; + $result = $this->db->sql_query($sql); + + $row = $this->db->sql_fetchrow($result); + if (!$row) + { + // No rows at all, default to '' + $subscriptions[$id] = array(''); + } + else + { + do + { + if (!$row['notify']) + { + continue; + } + + if (!isset($subscriptions[$id])) + { + $subscriptions[$id] = array(); + } + + $subscriptions[$id][] = $row['method']; + } + while ($row = $this->db->sql_fetchrow($result)); + } + + $this->db->sql_freeresult($result); + } + } + + return $subscriptions; + } + + /** + * Add a subscription + * + * @param string $item_type Type identifier of the subscription + * @param int $item_id The id of the item + * @param string $method The method of the notification e.g. '', 'email', or 'jabber' + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + */ + public function add_subscription($item_type, $item_id = 0, $method = '', $user_id = false) + { + if ($method !== '') + { + $this->add_subscription($item_type, $item_type, '', $user_id); + } + + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; + + $sql = 'SELECT notify + FROM ' . $this->user_notifications_table . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; + $this->db->sql_query($sql); + $current = $this->db->sql_fetchfield('notify'); + $this->db->sql_freeresult(); + + if ($current === false) + { + $sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => (int) $user_id, + 'method' => $method, + 'notify' => 1, + )); + $this->db->sql_query($sql); + } + else if (!$current) + { + $sql = 'UPDATE ' . $this->user_notifications_table . " + SET notify = 1 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; + $this->db->sql_query($sql); + } + } + + /** + * Delete a subscription + * + * @param string $item_type Type identifier of the subscription + * @param int $item_id The id of the item + * @param string $method The method of the notification e.g. '', 'email', or 'jabber' + * @param bool|int $user_id The user_id to add the subscription for (bool false for current user) + */ + public function delete_subscription($item_type, $item_id = 0, $method = '', $user_id = false) + { + $user_id = ($user_id === false) ? $this->user->data['user_id'] : $user_id; + + // If no method, make sure that no other notification methods for this item are selected before deleting + if ($method === '') + { + $sql = 'SELECT COUNT(*) as num_notifications + FROM ' . $this->user_notifications_table . " + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method <> '' + AND notify = 1"; + $this->db->sql_query($sql); + $num_notifications = $this->db->sql_fetchfield('num_notifications'); + $this->db->sql_freeresult(); + + if ($num_notifications) + { + return; + } + } + + $sql = 'UPDATE ' . $this->user_notifications_table . " + SET notify = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "' + AND item_id = " . (int) $item_id . ' + AND user_id = ' .(int) $user_id . " + AND method = '" . $this->db->sql_escape($method) . "'"; + $this->db->sql_query($sql); + + if (!$this->db->sql_affectedrows()) + { + $sql = 'INSERT INTO ' . $this->user_notifications_table . ' ' . + $this->db->sql_build_array('INSERT', array( + 'item_type' => $item_type, + 'item_id' => (int) $item_id, + 'user_id' => (int) $user_id, + 'method' => $method, + 'notify' => 0, + )); + $this->db->sql_query($sql); + } + } + + /** + * Disable all notifications of a certain type + * + * This should be called when an extension which has notification types + * is disabled so that all those notifications are hidden and do not + * cause errors + * + * @param string $item_type + */ + public function disable_notifications($item_type) + { + $sql = 'UPDATE ' . $this->notifications_table . " + SET is_enabled = 0 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); + } + + /** + * Enable all notifications of a certain type + * + * This should be called when an extension which has notification types + * that was disabled is re-enabled so that all those notifications that + * were hidden are shown again + * + * @param string $item_type + */ + public function enable_notifications($item_type) + { + $sql = 'UPDATE ' . $this->notifications_table . " + SET is_enabled = 1 + WHERE item_type = '" . $this->db->sql_escape($item_type) . "'"; + $this->db->sql_query($sql); + } + + /** + * Helper to get the notifications item type class and set it up + */ + public function get_item_type_class($item_type, $data = array()) + { + $item = $this->load_object('notification.type.' . $item_type); + + $item->set_initial_data($data); + + return $item; + } + + /** + * Helper to get the notifications method class and set it up + */ + public function get_method_class($method_name) + { + return $this->load_object('notification.method.' . $method_name); + } + + /** + * Helper to load objects (notification types/methods) + */ + protected function load_object($object_name) + { + // Here we cannot just use ContainerBuilder->get(name) + // The reason for this is because get handles services + // which are initialized once and shared. Here we need + // separate new objects because we pass around objects + // that store row data in each object, which would lead + // to over-writing of data if we used get() + + $parameterBag = $this->phpbb_container->getParameterBag(); + $definition = $this->phpbb_container->getDefinition($object_name); + $arguments = $this->phpbb_container->resolveServices( + $parameterBag->unescapeValue($parameterBag->resolveValue($definition->getArguments())) + ); + $r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass())); + + $object = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments); + + $object->set_notification_manager($this); + + return $object; + } +} diff --git a/phpBB/includes/notification/method/base.php b/phpBB/includes/notification/method/base.php new file mode 100644 index 0000000000..3f85d62a09 --- /dev/null +++ b/phpBB/includes/notification/method/base.php @@ -0,0 +1,98 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Base notifications method class +* @package notifications +*/ +abstract class phpbb_notification_method_base implements phpbb_notification_method_interface +{ + /** @var phpbb_notification_manager */ + protected $notification_manager = null; + + /** @var phpbb_user_loader */ + protected $user_loader = null; + + /** @var dbal */ + protected $db = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var phpbb_template */ + protected $template = null; + + /** @var phpbb_extension_manager */ + protected $extension_manager = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_config */ + protected $config = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; + + /** + * Queue of messages to be sent + * + * @var array + */ + protected $queue = array(); + + public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext) + { + $this->user_loader = $user_loader; + $this->db = $db; + $this->cache = $cache; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + public function set_notification_manager(phpbb_notification_manager $notification_manager) + { + $this->notification_manager = $notification_manager; + } + + /** + * Add a notification to the queue + * + * @param phpbb_notification_type_interface $notification + */ + public function add_to_queue(phpbb_notification_type_interface $notification) + { + $this->queue[] = $notification; + } + + /** + * Empty the queue + */ + protected function empty_queue() + { + $this->queue = array(); + } +} diff --git a/phpBB/includes/notification/method/email.php b/phpBB/includes/notification/method/email.php new file mode 100644 index 0000000000..429dfda2ba --- /dev/null +++ b/phpBB/includes/notification/method/email.php @@ -0,0 +1,129 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Email notification method class +* This class handles sending emails for notifications +* +* @package notifications +*/ +class phpbb_notification_method_email extends phpbb_notification_method_base +{ + /** + * Get notification method name + * + * @return string + */ + public function get_type() + { + return 'email'; + } + + /** + * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) + * + * @var mixed + */ + protected $notify_method = NOTIFY_EMAIL; + + /** + * Base directory to prepend to the email template name + * + * @var string + */ + protected $email_template_base_dir = ''; + + /** + * Is this method available for the user? + * This is checked on the notifications options + */ + public function is_available() + { + // Email is always available + return true; + } + + /** + * Parse the queue and notify the users + */ + public function notify() + { + if (!sizeof($this->queue)) + { + return; + } + + // Load all users we want to notify (we need their email address) + $user_ids = $users = array(); + foreach ($this->queue as $notification) + { + $user_ids[] = $notification->user_id; + } + + // We do not send emails to banned users + if (!function_exists('phpbb_get_banned_user_ids')) + { + include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext); + } + $banned_users = phpbb_get_banned_user_ids($user_ids); + + // Load all the users we need + $this->user_loader->load_users($user_ids); + + // Load the messenger + if (!class_exists('messenger')) + { + include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext); + } + $messenger = new messenger(); + $board_url = generate_board_url(); + + // Time to go through the queue and send emails + foreach ($this->queue as $notification) + { + if ($notification->get_email_template() === false) + { + continue; + } + + $user = $this->user_loader->get_user($notification->user_id); + + if ($user['user_type'] == USER_IGNORE || in_array($notification->user_id, $banned_users)) + { + continue; + } + + $messenger->template($this->email_template_base_dir . $notification->get_email_template(), $user['user_lang']); + + $messenger->to($user['user_email'], $user['username']); + + $messenger->assign_vars(array_merge(array( + 'USERNAME' => $user['username'], + + 'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications', + ), $notification->get_email_template_variables())); + + $messenger->send($this->notify_method); + } + + // Save the queue in the messenger class (has to be called or these emails could be lost?) + $messenger->save_queue(); + + // We're done, empty the queue + $this->empty_queue(); + } +} diff --git a/phpBB/includes/notification/method/interface.php b/phpBB/includes/notification/method/interface.php new file mode 100644 index 0000000000..ef875942cc --- /dev/null +++ b/phpBB/includes/notification/method/interface.php @@ -0,0 +1,48 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Base notifications method interface +* @package notifications +*/ +interface phpbb_notification_method_interface +{ + /** + * Get notification method name + * + * @return string + */ + public function get_type(); + + /** + * Is this method available for the user? + * This is checked on the notifications options + */ + public function is_available(); + + /** + * Add a notification to the queue + * + * @param phpbb_notification_type_interface $notification + */ + public function add_to_queue(phpbb_notification_type_interface $notification); + + /** + * Parse the queue and notify the users + */ + public function notify(); +} diff --git a/phpBB/includes/notification/method/jabber.php b/phpBB/includes/notification/method/jabber.php new file mode 100644 index 0000000000..e3eb571fbc --- /dev/null +++ b/phpBB/includes/notification/method/jabber.php @@ -0,0 +1,77 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Jabber notification method class +* This class handles sending Jabber messages for notifications +* +* @package notifications +*/ +class phpbb_notification_method_jabber extends phpbb_notification_method_email +{ + /** + * Get notification method name + * + * @return string + */ + public function get_type() + { + return 'jabber'; + } + + /** + * Notify method (since jabber gets sent through the same messenger, we let the jabber class inherit from this to reduce code duplication) + * + * @var mixed + */ + protected $notify_method = NOTIFY_IM; + + /** + * Base directory to prepend to the email template name + * + * @var string + */ + protected $email_template_base_dir = 'short/'; + + /** + * Is this method available for the user? + * This is checked on the notifications options + */ + public function is_available() + { + return ($this->global_available() && $this->user->data['jabber']); + } + + /** + * Is this method available at all? + * This is checked before notifications are sent + */ + public function global_available() + { + return ($this->config['jab_enable'] && @extension_loaded('xml')); + } + + public function notify() + { + if (!$this->global_available()) + { + return; + } + + return parent::notify(); + } +} diff --git a/phpBB/includes/notification/type/approve_post.php b/phpBB/includes/notification/type/approve_post.php new file mode 100644 index 0000000000..38ff3f1d70 --- /dev/null +++ b/phpBB/includes/notification/type/approve_post.php @@ -0,0 +1,140 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Post approved notifications class +* This class handles notifications for posts when they are approved (to their authors) +* +* @package notifications +*/ +class phpbb_notification_type_approve_post extends phpbb_notification_type_post +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'approve_post'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_POST_APPROVED'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + + /** + * Is available + */ + public function is_available() + { + return !$this->auth->acl_get('m_approve'); + } + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $users = array(); + $users[$post['poster_id']] = array(''); + + $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); + } + + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + // (and also saves a query) + return array(); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $this->set_data('post_subject', $post['post_subject']); + + $data = parent::create_insert_array($post, $pre_create_data); + + $this->time = $data['time'] = time(); + + return $data; + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'post_approved'; + } +} diff --git a/phpBB/includes/notification/type/approve_topic.php b/phpBB/includes/notification/type/approve_topic.php new file mode 100644 index 0000000000..5b9ea409fe --- /dev/null +++ b/phpBB/includes/notification/type/approve_topic.php @@ -0,0 +1,138 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Topic approved notifications class +* This class handles notifications for topics when they are approved (for authors) +* +* @package notifications +*/ +class phpbb_notification_type_approve_topic extends phpbb_notification_type_topic +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'approve_topic'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_TOPIC_APPROVED'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + + /** + * Is available + */ + public function is_available() + { + return !$this->auth->acl_get('m_approve'); + } + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $users = array(); + $users[$post['poster_id']] = array(''); + + $auth_read = $this->auth->acl_get_list(array_keys($users), 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + return $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); + } + + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + // In the parent class, this is used to check if the post is already + // read by a user and marks the notification read if it was marked read. + // Returning an empty array in effect, forces it to be marked as unread + // (and also saves a query) + return array(); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $data = parent::create_insert_array($post, $pre_create_data); + + $this->time = $data['time'] = time(); + + return $data; + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_approved'; + } +} diff --git a/phpBB/includes/notification/type/base.php b/phpBB/includes/notification/type/base.php new file mode 100644 index 0000000000..d596c06167 --- /dev/null +++ b/phpBB/includes/notification/type/base.php @@ -0,0 +1,428 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Base notifications class +* @package notifications +*/ +abstract class phpbb_notification_type_base implements phpbb_notification_type_interface +{ + /** @var phpbb_notification_manager */ + protected $notification_manager = null; + + /** @var phpbb_user_loader */ + protected $user_loader = null; + + /** @var dbal */ + protected $db = null; + + /** @var phpbb_cache_service */ + protected $cache = null; + + /** @var phpbb_template */ + protected $template = null; + + /** @var phpbb_user */ + protected $user = null; + + /** @var phpbb_auth */ + protected $auth = null; + + /** @var phpbb_config */ + protected $config = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; + + /** @var string */ + protected $notifications_table = null; + + /** @var string */ + protected $user_notifications_table = null; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use its default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = false; + + /** + * Indentification data + * item_type - Type of the item (translates to the notification type) + * item_id - ID of the item (e.g. post_id, msg_id) + * item_parent_id - Parent item id (ex: for topic => forum_id, for post => topic_id, etc) + * user_id + * unread + * is_enabled - EXTENSION AUTHORS TAKE NOTE! This is to prevent errors with notifications from extensions! + * - Set is_enabled to 0 for all your notifications when your extension is disabled so they are ignored and do not cause errors. + * - When your extension is enabled again, set is_enabled to 1 and your notifications will be working again. + * + * time + * data (special serialized field that each notification type can use to store stuff) + * + * @var array $data Notification row from the database + * This must be private, all interaction should use __get(), __set(), get_data(), set_data() + */ + private $data = array(); + + public function __construct(phpbb_user_loader $user_loader, dbal $db, phpbb_cache_driver_interface $cache, $user, phpbb_auth $auth, phpbb_config $config, $phpbb_root_path, $php_ext, $notifications_table, $user_notifications_table) + { + $this->user_loader = $user_loader; + $this->db = $db; + $this->cache = $cache; + $this->user = $user; + $this->auth = $auth; + $this->config = $config; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->notifications_table = $notifications_table; + $this->user_notifications_table = $user_notifications_table; + } + + public function set_notification_manager(phpbb_notification_manager $notification_manager) + { + $this->notification_manager = $notification_manager; + } + + /** + * Set initial data from the database + * + * @param array $data Row directly from the database + */ + public function set_initial_data($data = array()) + { + // The row from the database (unless this is a new notification we're going to add) + $this->data = $data; + $this->data['data'] = (isset($this->data['data'])) ? unserialize($this->data['data']) : array(); + } + + public function __get($name) + { + return (!isset($this->data[$name])) ? null : $this->data[$name]; + } + + public function __set($name, $value) + { + $this->data[$name] = $value; + } + + public function __toString() + { + return (!empty($this->data)) ? var_export($this->data, true) : $this->get_type(); + } + + /** + * Get special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to get + * + * @return mixed + */ + protected function get_data($name) + { + return ($name === false) ? $this->data['data'] : ((isset($this->data['data'][$name])) ? $this->data['data'][$name] : null); + } + + /** + * Set special data (only important for the classes that extend this) + * + * @param string $name Name of the variable to set + * @param mixed $value Value to set to the variable + */ + protected function set_data($name, $value) + { + $this->data['data'][$name] = $value; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $type_data Data unique to this notification type + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($type_data, $pre_create_data = array()) + { + // Defaults + $this->data = array_merge(array( + 'item_id' => static::get_item_id($type_data), + 'item_type' => $this->get_type(), + 'item_parent_id' => static::get_item_parent_id($type_data), + + 'time' => time(), + 'unread' => true, + + 'data' => array(), + ), $this->data); + + $data = $this->data; + + $data['data'] = serialize($data['data']); + + return $data; + } + + /** + * Function for preparing the data for update in an SQL query + * (The service handles insertion) + * + * @param array $type_data Data unique to this notification type + * + * @return array Array of data ready to be updated in the database + */ + public function create_update_array($type_data) + { + $data = $this->create_insert_array($type_data); + + // Unset data unique to each row + unset( + $data['time'], // Also unsetting time, since it always tries to change the time to current (if you actually need to change the time, over-ride this function) + $data['notification_id'], + $data['unread'], + $data['user_id'] + ); + + return $data; + } + + /** + * Mark this item read + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_read($return = false) + { + return $this->mark(false, $return); + } + + /** + * Mark this item unread + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_unread($return = false) + { + return $this->mark(true, $return); + } + + /** + * Prepare to output the notification to the template + */ + public function prepare_for_display() + { + if ($this->get_url()) + { + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id); + } + else + { + $redirect = (($this->user->page['page_dir']) ? $this->user->page['page_dir'] . '/' : '') . $this->user->page['page_name'] . (($this->user->page['query_string']) ? '?' . $this->user->page['query_string'] : ''); + + $u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&redirect=' . urlencode($redirect)); + } + + return array( + 'NOTIFICATION_ID' => $this->notification_id, + + 'AVATAR' => $this->get_avatar(), + + 'FORMATTED_TITLE' => $this->get_title(), + + 'URL' => $this->get_url(), + 'TIME' => $this->user->format_date($this->time), + + 'UNREAD' => $this->unread, + + 'U_MARK_READ' => ($this->unread) ? $u_mark_read : '', + ); + } + + /** + * -------------- Fall back functions ------------------- + */ + + /** + * URL to unsubscribe to this notification (fall back) + * + * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item + */ + public function get_unsubscribe_url($method = false) + { + return false; + } + + /** + * Get the user's avatar (fall back) + */ + public function get_avatar() + { + return ''; + } + + /** + * Get the special items to load (fall back) + */ + public function get_load_special() + { + return array(); + } + + /** + * Load the special items (fall back) + */ + public function load_special($data, $notifications) + { + return; + } + + /** + * Is available (fall back) + */ + public function is_available() + { + return true; + } + + /** + * Pre create insert array function (fall back) + */ + public function pre_create_insert_array($type_data, $notify_users) + { + return array(); + } + + /** + * -------------- Helper functions ------------------- + */ + + /** + * Find the users who want to receive notifications (helper) + * + * @param array $user_ids User IDs to check if they want to receive notifications + * (Bool False to check all users besides anonymous and bots (USER_IGNORE)) + * + * @return array + */ + protected function check_user_notification_options($user_ids = false, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + 'item_type' => $this->get_type(), + 'item_id' => 0, // Global by default + ), $options); + + if ($user_ids === false) + { + $user_ids = array(); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE user_id <> ' . ANONYMOUS . ' + AND user_type <> ' . USER_IGNORE; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $user_ids[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + } + + if (empty($user_ids)) + { + return array(); + } + + $rowset = $resulting_user_ids = array(); + + $sql = 'SELECT user_id, method, notify + FROM ' . $this->user_notifications_table . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . " + AND item_type = '" . $this->db->sql_escape($options['item_type']) . "' + AND item_id = " . (int) $options['item_id']; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $resulting_user_ids[] = $row['user_id']; + + if (!$row['notify'] || (isset($options['ignore_users'][$row['user_id']]) && in_array($row['method'], $options['ignore_users'][$row['user_id']]))) + { + continue; + } + + if (!isset($rowset[$row['user_id']])) + { + $rowset[$row['user_id']] = array(); + } + + $rowset[$row['user_id']][] = $row['method']; + } + + $this->db->sql_freeresult($result); + + foreach ($user_ids as $user_id) + { + if (!in_array($user_id, $resulting_user_ids) && !isset($options['ignore_users'][$user_id])) + { + // No rows at all for this user, default to '' + $rowset[$user_id] = array(''); + } + } + + return $rowset; + } + + /** + * Mark this item read/unread helper + * + * @param bool $unread Unread (True/False) (Default: False) + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + protected function mark($unread = true, $return = false) + { + $this->unread = (bool) $unread; + + $where = array( + "item_type = '" . $this->db->sql_escape($this->item_type) . "'", + 'item_id = ' . (int) $this->item_id, + 'user_id = ' . (int) $this->user_id, + ); + $where = implode(' AND ', $where); + + if ($return) + { + return $where; + } + + $sql = 'UPDATE ' . $this->notifications_table . ' + SET unread = ' . (int) $this->unread . ' + WHERE ' . $where; + $this->db->sql_query($sql); + } +} diff --git a/phpBB/includes/notification/type/bookmark.php b/phpBB/includes/notification/type/bookmark.php new file mode 100644 index 0000000000..a17d8f5db7 --- /dev/null +++ b/phpBB/includes/notification/type/bookmark.php @@ -0,0 +1,136 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Bookmark updating notifications class +* This class handles notifications for replies to a bookmarked topic +* +* @package notifications +*/ +class phpbb_notification_type_bookmark extends phpbb_notification_type_post +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'bookmark'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_BOOKMARK'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_BOOKMARK', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + + /** + * Is available + */ + public function is_available() + { + return $this->config['allow_bookmarks']; + } + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . BOOKMARKS_TABLE . ' + WHERE ' . $this->db->sql_in_set('topic_id', $post['topic_id']) . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); + + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . $this->notifications_table . " + WHERE item_type = '" . $this->get_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1 + AND is_enabled = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); + $sql = 'UPDATE ' . $this->notifications_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'bookmark'; + } +} diff --git a/phpBB/includes/notification/type/disapprove_post.php b/phpBB/includes/notification/type/disapprove_post.php new file mode 100644 index 0000000000..d1d56086e7 --- /dev/null +++ b/phpBB/includes/notification/type/disapprove_post.php @@ -0,0 +1,120 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Post disapproved notifications class +* This class handles notifications for posts when they are disapproved (for authors) +* +* @package notifications +*/ +class phpbb_notification_type_disapprove_post extends phpbb_notification_type_approve_post +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'disapprove_post'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_POST_DISAPPROVED'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('topic_title')), + $this->get_data('disapprove_reason') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array_merge(parent::get_email_template_variables(), array( + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + )); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $this->set_data('disapprove_reason', $post['disapprove_reason']); + + $data = parent::create_insert_array($post); + + $this->time = $data['time'] = time(); + + return $data; + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'post_disapproved'; + } +} diff --git a/phpBB/includes/notification/type/disapprove_topic.php b/phpBB/includes/notification/type/disapprove_topic.php new file mode 100644 index 0000000000..7affaa8afa --- /dev/null +++ b/phpBB/includes/notification/type/disapprove_topic.php @@ -0,0 +1,120 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Topic disapproved notifications class +* This class handles notifications for topics when they are disapproved (for authors) +* +* @package notifications +*/ +class phpbb_notification_type_disapprove_topic extends phpbb_notification_type_approve_topic +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'disapprove_topic'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_TOPIC_DISAPPROVED'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'id' => 'moderation_queue', + 'lang' => 'NOTIFICATION_TYPE_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + return $this->user->lang( + $this->language_key, + censor_text($this->get_data('topic_title')), + $this->get_data('disapprove_reason') + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array_merge(parent::get_email_template_variables(), array( + 'REASON' => htmlspecialchars_decode($this->get_data('disapprove_reason')), + )); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $this->set_data('disapprove_reason', $post['disapprove_reason']); + + $data = parent::create_insert_array($post, $pre_create_data); + + $this->time = $data['time'] = time(); + + return $data; + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_disapproved'; + } +} diff --git a/phpBB/includes/notification/type/interface.php b/phpBB/includes/notification/type/interface.php new file mode 100644 index 0000000000..a40fdafd09 --- /dev/null +++ b/phpBB/includes/notification/type/interface.php @@ -0,0 +1,189 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Base notifications interface +* @package notifications +*/ +interface phpbb_notification_type_interface +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type(); + + /** + * Set initial data from the database + * + * @param array $data Row directly from the database + */ + public function set_initial_data($data); + + /** + * Get the id of the item + * + * @param array $type_data The type specific data + */ + public static function get_item_id($type_data); + + /** + * Get the id of the parent + * + * @param array $type_data The type specific data + */ + public static function get_item_parent_id($type_data); + + /** + * Is this type available to the current user (defines whether or not it will be shown in the UCP Edit notification options) + * + * @return bool True/False whether or not this is available to the user + */ + public function is_available(); + + /** + * Find the users who want to receive notifications + * + * @param array $type_data The type specific data + * @param array $options Options for finding users for notification + * ignore_users => array of users and user types that should not receive notifications from this type because they've already been notified + * e.g.: array(2 => array(''), 3 => array('', 'email'), ...) + * + * @return array + */ + public function find_users_for_notification($type_data, $options); + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query(); + + /** + * Get the special items to load + * + * @return array Data will be combined sent to load_special() so you can run a single query and get data required for this notification type + */ + public function get_load_special(); + + /** + * Load the special items + * + * @param array $data Data from get_load_special() + * @param array $notifications Array of notifications (key is notification_id, value is the notification objects) + */ + public function load_special($data, $notifications); + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title(); + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url(); + + /** + * URL to unsubscribe to this notification + * + * @param string|bool $method Method name to unsubscribe from (email|jabber|etc), False to unsubscribe from all notifications for this item + */ + public function get_unsubscribe_url($method); + + /** + * Get the user's avatar (the user who caused the notification typically) + * + * @return string + */ + public function get_avatar(); + + /** + * Prepare to output the notification to the template + */ + public function prepare_for_display(); + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template(); + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables(); + + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $type_data The type specific data + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($type_data, $notify_users); + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $type_data The type specific data + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($type_data, $pre_create_data); + + /** + * Function for preparing the data for update in an SQL query + * (The service handles insertion) + * + * @param array $type_data Data unique to this notification type + * + * @return array Array of data ready to be updated in the database + */ + public function create_update_array($type_data); + + /** + * Mark this item read + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_read($return); + + /** + * Mark this item unread + * + * @param bool $return True to return a string containing the SQL code to update this item, False to execute it (Default: False) + * @return string + */ + public function mark_unread($return); +} diff --git a/phpBB/includes/notification/type/pm.php b/phpBB/includes/notification/type/pm.php new file mode 100644 index 0000000000..1eaeb1a250 --- /dev/null +++ b/phpBB/includes/notification/type/pm.php @@ -0,0 +1,186 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Private message notifications class +* This class handles notifications for private messages +* +* @package notifications +*/ +class phpbb_notification_type_pm extends phpbb_notification_type_base +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'pm'; + } + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_PM', + ); + + /** + * Is available + */ + public function is_available() + { + return ($this->config['allow_privmsg'] && $this->auth->acl_get('u_readpm')); + } + + /** + * Get the id of the + * + * @param array $pm The data from the private message + */ + public static function get_item_id($pm) + { + return (int) $pm['msg_id']; + } + + /** + * Get the id of the parent + * + * @param array $pm The data from the pm + */ + public static function get_item_parent_id($pm) + { + // No parent + return 0; + } + + /** + * Find the users who want to receive notifications + * + * @param array $pm Data from + * + * @return array + */ + public function find_users_for_notification($pm, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + if (!sizeof($pm['recipients'])) + { + return array(); + } + + unset($pm['recipients'][$pm['from_user_id']]); + + $this->user_loader->load_users(array_keys($pm['recipients'])); + + return $this->check_user_notification_options(array_keys($pm['recipients']), $options); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->user_loader->get_avatar($this->get_data('from_user_id')); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->user_loader->get_user($this->get_data('from_user_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $this->user->lang('NOTIFICATION_PM', $username, $this->get_data('message_subject')); + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'privmsg_notify'; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $user_data = $this->user_loader->get_user($this->get_data('from_user_id')); + + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), + + 'U_VIEW_MESSAGE' => generate_board_url() . '/ucp.' . $this->php_ext . "?i=pm&mode=view&p={$this->item_id}", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=pm&mode=view&p={$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['from_user_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($pm, $pre_create_data = array()) + { + $this->set_data('from_user_id', $pm['from_user_id']); + + $this->set_data('message_subject', $pm['message_subject']); + + return parent::create_insert_array($pm, $pre_create_data); + } +} diff --git a/phpBB/includes/notification/type/post.php b/phpBB/includes/notification/type/post.php new file mode 100644 index 0000000000..7e06779982 --- /dev/null +++ b/phpBB/includes/notification/type/post.php @@ -0,0 +1,373 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Post notifications class +* This class handles notifications for replies to a topic +* +* @package notifications +*/ +class phpbb_notification_type_post extends phpbb_notification_type_base +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'post'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_POST'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_POST', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + + /** + * Is available + */ + public function is_available() + { + return $this->config['allow_topic_notify']; + } + + /** + * Get the id of the item + * + * @param array $post The data from the post + */ + public static function get_item_id($post) + { + return (int) $post['post_id']; + } + + /** + * Get the id of the parent + * + * @param array $post The data from the post + */ + public static function get_item_parent_id($post) + { + return (int) $post['topic_id']; + } + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . TOPICS_WATCH_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND notify_status = ' . NOTIFY_YES . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); + + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . $this->notifications_table . " + WHERE item_type = '" . $this->get_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1 + AND is_enabled = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); + $sql = 'UPDATE ' . $this->notifications_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->user_loader->get_avatar($this->get_data('poster_id')); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $responders = $this->get_data('responders'); + $usernames = array(); + + if (!is_array($responders)) + { + $responders = array(); + } + + $responders = array_merge(array(array( + 'poster_id' => $this->get_data('poster_id'), + 'username' => $this->get_data('post_username'), + )), $responders); + + foreach ($responders as $responder) + { + if ($responder['username']) + { + $usernames[] = $responder['username']; + } + else + { + $user_data = $this->user_loader->get_user($responder['poster_id']); + + $usernames[] = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + } + + return $this->user->lang( + $this->language_key, + implode(', ', $usernames), + censor_text($this->get_data('topic_title')) + ); + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_notify'; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); + + $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($username), + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_VIEW_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + 'U_NEWEST_POST' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", + 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + 'U_STOP_WATCHING_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?uid={$this->user_id}&f={$this->get_data('forum_id')}&t={$this->item_parent_id}&unwatch=topic", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + $responders = $this->get_data('responders'); + $users = array( + $this->get_data('poster_id'), + ); + + if (is_array($responders)) + { + foreach ($responders as $responder) + { + $users[] = $responder['poster_id']; + } + } + + return $users; + } + + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + if (!sizeof($notify_users)) + { + return array(); + } + + $tracking_data = array(); + $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $tracking_data[$row['user_id']] = $row['mark_time']; + } + + return $tracking_data; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $this->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_subject', $post['post_subject']); + + $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); + + $this->set_data('forum_id', $post['forum_id']); + + $this->set_data('forum_name', $post['forum_name']); + + $this->time = $post['post_time']; + + // Topics can be "read" before they are public (while awaiting approval). + // Make sure that if the user has read the topic, it's marked as read in the notification + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + { + $this->unread = false; + } + + return parent::create_insert_array($post, $pre_create_data); + } + + /** + * Add responders to the notification + * + * @param mixed $post + */ + public function add_responders($post) + { + // Do not add them as a responder if they were the original poster that created the notification + if ($this->get_data('poster_id') == $post['poster_id']) + { + return array('data' => serialize($this->get_data(false))); + } + + $responders = $this->get_data('responders'); + + $responders = ($responders === null) ? array() : $responders; + + foreach ($responders as $responder) + { + // Do not add them as a responder multiple times + if ($responder['poster_id'] == $post['poster_id']) + { + return array('data' => serialize($this->get_data(false))); + } + } + + $responders[] = array( + 'poster_id' => $post['poster_id'], + 'username' => (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : ''), + ); + + $this->set_data('responders', $responders); + + return array('data' => serialize($this->get_data(false))); + } +} diff --git a/phpBB/includes/notification/type/post_in_queue.php b/phpBB/includes/notification/type/post_in_queue.php new file mode 100644 index 0000000000..3cd9b11283 --- /dev/null +++ b/phpBB/includes/notification/type/post_in_queue.php @@ -0,0 +1,137 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Post in queue notifications class +* This class handles notifications for posts that are put in the moderation queue (for moderators) +* +* @package notifications +*/ +class phpbb_notification_type_post_in_queue extends phpbb_notification_type_post +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'post_in_queue'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_POST_IN_QUEUE'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'id' => 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_MODERATION', + ); + + /** + * Permission to check for (in find_users_for_notification) + * + * @var string Permission name + */ + protected $permission = 'm_approve'; + + /** + * Is available + */ + public function is_available() + { + $m_approve = $this->auth->acl_getf($this->permission, true); + + return (!empty($m_approve)); + } + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from the post + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + // 0 is for global + $auth_approve = $this->auth->acl_get_list(false, $this->permission, array($post['forum_id'], 0)); + + if (empty($auth_approve)) + { + return array(); + } + + $auth_approve[$post['forum_id']] = array_unique(array_merge($auth_approve[$post['forum_id']], $auth_approve[0])); + + return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "i=queue&mode=approve_details&f={$this->get_data('forum_id')}&p={$this->item_id}"); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $data = parent::create_insert_array($post, $pre_create_data); + + $this->time = $data['time'] = time(); + + return $data; + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'post_in_queue'; + } +} diff --git a/phpBB/includes/notification/type/quote.php b/phpBB/includes/notification/type/quote.php new file mode 100644 index 0000000000..1796343a0e --- /dev/null +++ b/phpBB/includes/notification/type/quote.php @@ -0,0 +1,219 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Post quoting notifications class +* This class handles notifications for quoting users in a post +* +* @package notifications +*/ +class phpbb_notification_type_quote extends phpbb_notification_type_post +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'quote'; + } + + /** + * regular expression to match to find usernames + * + * @var string + */ + protected static $regular_expression_match = '#\[quote="(.+?)"#'; + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_QUOTE'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_QUOTE', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + + /** + * Is available + */ + public function is_available() + { + return true; + } + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $usernames = false; + preg_match_all(self::$regular_expression_match, $post['post_text'], $usernames); + + if (empty($usernames[1])) + { + return array(); + } + + $usernames[1] = array_unique($usernames[1]); + + $usernames = array_map('utf8_clean_string', $usernames[1]); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . USERS_TABLE . ' + WHERE ' . $this->db->sql_in_set('username_clean', $usernames) . ' + AND user_id <> ' . (int) $post['poster_id']; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $this->auth->acl_get_list($users, 'f_read', $post['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + $notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options); + + // Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications + $update_notifications = array(); + $sql = 'SELECT * + FROM ' . $this->notifications_table . " + WHERE item_type = '" . $this->get_type() . "' + AND item_parent_id = " . (int) self::get_item_parent_id($post) . ' + AND unread = 1 + AND is_enabled = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + // Do not create a new notification + unset($notify_users[$row['user_id']]); + + $notification = $this->notification_manager->get_item_type_class($this->get_type(), $row); + $sql = 'UPDATE ' . $this->notifications_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . ' + WHERE notification_id = ' . $row['notification_id']; + $this->db->sql_query($sql); + } + $this->db->sql_freeresult($result); + + return $notify_users; + } + + /** + * Update a notification + * + * @param array $data Data specific for this type that will be updated + */ + public function update_notifications($post) + { + $old_notifications = array(); + $sql = 'SELECT user_id + FROM ' . $this->notifications_table . " + WHERE item_type = '" . $this->get_type() . "' + AND item_id = " . self::get_item_id($post) . ' + AND is_enabled = 1'; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $old_notifications[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + + // Find the new users to notify + $notifications = $this->find_users_for_notification($post); + + // Find the notifications we must delete + $remove_notifications = array_diff($old_notifications, array_keys($notifications)); + + // Find the notifications we must add + $add_notifications = array(); + foreach (array_diff(array_keys($notifications), $old_notifications) as $user_id) + { + $add_notifications[$user_id] = $notifications[$user_id]; + } + + // Add the necessary notifications + $this->notification_manager->add_notifications_for_users($this->get_type(), $post, $add_notifications); + + // Remove the necessary notifications + if (!empty($remove_notifications)) + { + $sql = 'DELETE FROM ' . $this->notifications_table . " + WHERE item_type = '" . $this->get_type() . "' + AND item_id = " . self::get_item_id($post) . ' + AND ' . $this->db->sql_in_set('user_id', $remove_notifications); + $this->db->sql_query($sql); + } + + // return true to continue with the update code in the notifications service (this will update the rest of the notifications) + return true; + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'quote'; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); + + return array_merge(parent::get_email_template_variables(), array( + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + )); + } +} diff --git a/phpBB/includes/notification/type/report_pm.php b/phpBB/includes/notification/type/report_pm.php new file mode 100644 index 0000000000..73e22dc83b --- /dev/null +++ b/phpBB/includes/notification/type/report_pm.php @@ -0,0 +1,231 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Private message reproted notifications class +* This class handles notifications for private messages when they are reported +* +* @package notifications +*/ +class phpbb_notification_type_report_pm extends phpbb_notification_type_pm +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_pm'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_REPORT_PM'; + + /** + * Permission to check for (in find_users_for_notification) + * + * @var string Permission name + */ + protected $permission = 'm_report'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'id' => 'report', + 'lang' => 'NOTIFICATION_TYPE_REPORT', + 'group' => 'NOTIFICATION_GROUP_MODERATION', + ); + + /** + * Get the id of the parent + * + * @param array $pm The data from the pm + */ + public static function get_item_parent_id($pm) + { + return (int) $pm['report_id']; + } + + /** + * Is this type available to the current user (defines whether or not it will be shown in the UCP Edit notification options) + * + * @return bool True/False whether or not this is available to the user + */ + public function is_available() + { + $m_approve = $this->auth->acl_getf($this->permission, true); + + return (!empty($m_approve)); + } + + + /** + * Find the users who want to receive notifications + * (copied from post_in_queue) + * + * @param array $post Data from the post + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + // Global + $post['forum_id'] = 0; + + $auth_approve = $this->auth->acl_get_list(false, $this->permission, $post['forum_id']); + + if (empty($auth_approve)) + { + return array(); + } + + if (($key = array_search($this->user->data['user_id'], $auth_approve[$post['forum_id']][$this->permission]))) + { + unset($auth_approve[$post['forum_id']][$this->permission][$key]); + } + + return $this->check_user_notification_options($auth_approve[$post['forum_id']][$this->permission], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'report_pm'; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), + 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), + + 'U_VIEW_REPORT' => generate_board_url() . "mcp.{$this->php_ext}?r={$this->item_parent_id}&i=pm_reports&mode=pm_report_details", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "r={$this->item_parent_id}&i=pm_reports&mode=pm_report_details"); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $this->user->add_lang('mcp'); + + $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + if ($this->get_data('report_text')) + { + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('message_subject')), + $this->get_data('report_text') + ); + } + + if (isset($this->user->lang[$this->get_data('reason_title')])) + { + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('message_subject')), + $this->user->lang[$this->get_data('reason_title')] + ); + } + + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('message_subject')), + $this->get_data('reason_description') + ); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->user_loader->get_avatar($this->get_data('reporter_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['reporter_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $this->set_data('reporter_id', $this->user->data['user_id']); + $this->set_data('reason_title', strtoupper($post['reason_title'])); + $this->set_data('reason_description', $post['reason_description']); + $this->set_data('report_text', $post['report_text']); + + return parent::create_insert_array($post, $pre_create_data); + } +} diff --git a/phpBB/includes/notification/type/report_pm_closed.php b/phpBB/includes/notification/type/report_pm_closed.php new file mode 100644 index 0000000000..51e5204304 --- /dev/null +++ b/phpBB/includes/notification/type/report_pm_closed.php @@ -0,0 +1,157 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* PM report closed notifications class +* This class handles notifications for when reports are closed on PMs (for the one who reported the PM) +* +* @package notifications +*/ +class phpbb_notification_type_report_pm_closed extends phpbb_notification_type_pm +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_pm_closed'; + } + + /** + * Email template to use to send notifications + * + * @var string + */ + public $email_template = ''; + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_REPORT_CLOSED'; + + public function is_available() + { + return false; + } + + /** + * Find the users who want to receive notifications + * + * @param array $pm Data from + * + * @return array + */ + public function find_users_for_notification($pm, $options = array()) + { + if ($pm['reporter'] == $this->user->data['user_id']) + { + return array(); + } + + return array($pm['reporter'] => array('')); + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return false; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array(); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->user_loader->get_user($this->get_data('closer_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('message_subject')) + ); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->get_user_avatar($this->get_data('closer_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['closer_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $pm PM Data + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($pm, $pre_create_data = array()) + { + $this->set_data('closer_id', $pm['closer_id']); + + $data = parent::create_insert_array($pm, $pre_create_data); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/report_post.php b/phpBB/includes/notification/type/report_post.php new file mode 100644 index 0000000000..2508644b0b --- /dev/null +++ b/phpBB/includes/notification/type/report_post.php @@ -0,0 +1,198 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Reported post notifications class +* This class handles notifications for reported posts +* +* @package notifications +*/ +class phpbb_notification_type_report_post extends phpbb_notification_type_post_in_queue +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_post'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_REPORT_POST'; + + /** + * Permission to check for (in find_users_for_notification) + * + * @var string Permission name + */ + protected $permission = 'm_report'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id' and 'lang') + */ + public static $notification_option = array( + 'id' => 'report', + 'lang' => 'NOTIFICATION_TYPE_REPORT', + 'group' => 'NOTIFICATION_GROUP_MODERATION', + ); + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from the post + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + $notify_users = parent::find_users_for_notification($post, $options); + + // never notify reporter + unset($notify_users[$this->user->data['user_id']]); + + return $notify_users; + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'report_post'; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + $board_url = generate_board_url(); + + return array( + 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('post_subject'))), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_VIEW_REPORT' => "{$board_url}mcp.{$this->php_ext}?f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports", + 'U_VIEW_POST' => "{$board_url}/viewtopic.{$this->php_ext}?p={$this->item_id}#p{$this->item_id}", + 'U_NEWEST_POST' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}&view=unread#unread", + 'U_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_VIEW_TOPIC' => "{$board_url}/viewtopic.{$this->php_ext}?f={$this->get_data('forum_id')}&t={$this->item_parent_id}", + 'U_FORUM' => "{$board_url}/viewforum.{$this->php_ext}?f={$this->get_data('forum_id')}", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "f={$this->get_data('forum_id')}&p={$this->item_id}&i=reports&mode=report_details#reports"); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $this->user->add_lang('mcp'); + + $user_data = $this->user_loader->get_user($this->get_data('reporter_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + if ($this->get_data('report_text')) + { + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('post_subject')), + $this->get_data('report_text') + ); + } + + if (isset($this->user->lang[$this->get_data('reason_title')])) + { + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('post_subject')), + $this->user->lang[$this->get_data('reason_title')] + ); + } + + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('post_subject')), + $this->get_data('reason_description') + ); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->user_loader->get_avatar($this->get_data('reporter_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['reporter_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $this->set_data('reporter_id', $this->user->data['user_id']); + $this->set_data('reason_title', strtoupper($post['reason_title'])); + $this->set_data('reason_description', $post['reason_description']); + $this->set_data('report_text', $post['report_text']); + + return parent::create_insert_array($post, $pre_create_data); + } +} diff --git a/phpBB/includes/notification/type/report_post_closed.php b/phpBB/includes/notification/type/report_post_closed.php new file mode 100644 index 0000000000..a7016a8f3d --- /dev/null +++ b/phpBB/includes/notification/type/report_post_closed.php @@ -0,0 +1,157 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Post report closed notifications class +* This class handles notifications for when reports are closed on posts (for the one who reported the post) +* +* @package notifications +*/ +class phpbb_notification_type_report_post_closed extends phpbb_notification_type_post +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'report_post_closed'; + } + + /** + * Email template to use to send notifications + * + * @var string + */ + public $email_template = ''; + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_REPORT_CLOSED'; + + public function is_available() + { + return false; + } + + /** + * Find the users who want to receive notifications + * + * @param array $post Data from + * + * @return array + */ + public function find_users_for_notification($post, $options = array()) + { + if ($post['reporter'] == $this->user->data['user_id']) + { + return array(); + } + + return array($post['reporter'] => array('')); + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return false; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + return array(); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return ''; + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + $user_data = $this->user_loader->get_user($this->get_data('closer_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('post_subject')) + ); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->user_loader->get_avatar($this->get_data('closer_id')); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['closer_id']); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $this->set_data('closer_id', $post['closer_id']); + + $data = parent::create_insert_array($post, $pre_create_data); + + $this->time = $data['time'] = time(); + + return $data; + } +} diff --git a/phpBB/includes/notification/type/topic.php b/phpBB/includes/notification/type/topic.php new file mode 100644 index 0000000000..6e9347d4a8 --- /dev/null +++ b/phpBB/includes/notification/type/topic.php @@ -0,0 +1,279 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Topic notifications class +* This class handles notifications for new topics +* +* @package notifications +*/ +class phpbb_notification_type_topic extends phpbb_notification_type_base +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'topic'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_TOPIC'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'lang' => 'NOTIFICATION_TYPE_TOPIC', + 'group' => 'NOTIFICATION_GROUP_POSTING', + ); + + /** + * Is available + */ + public function is_available() + { + return $this->config['allow_forum_notify']; + } + + /** + * Get the id of the item + * + * @param array $post The data from the post + */ + public static function get_item_id($post) + { + return (int) $post['topic_id']; + } + + /** + * Get the id of the parent + * + * @param array $post The data from the post + */ + public static function get_item_parent_id($post) + { + return (int) $post['forum_id']; + } + + /** + * Find the users who want to receive notifications + * + * @param array $topic Data from the topic + * + * @return array + */ + public function find_users_for_notification($topic, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $users = array(); + + $sql = 'SELECT user_id + FROM ' . FORUMS_WATCH_TABLE . ' + WHERE forum_id = ' . (int) $topic['forum_id'] . ' + AND notify_status = ' . NOTIFY_YES . ' + AND user_id <> ' . (int) $topic['poster_id']; + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $users[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + + if (empty($users)) + { + return array(); + } + + $auth_read = $this->auth->acl_get_list($users, 'f_read', $topic['forum_id']); + + if (empty($auth_read)) + { + return array(); + } + + return $this->check_user_notification_options($auth_read[$topic['forum_id']]['f_read'], $options); + } + + /** + * Get the user's avatar + */ + public function get_avatar() + { + return $this->user_loader->get_avatar($this->get_data('poster_id')); + } + + /** + * Get the HTML formatted title of this notification + * + * @return string + */ + public function get_title() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); + + $username = get_username_string('no_profile', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return $this->user->lang( + $this->language_key, + $username, + censor_text($this->get_data('topic_title')), + $this->get_data('forum_name') + ); + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'newtopic_notify'; + } + + /** + * Get email template variables + * + * @return array + */ + public function get_email_template_variables() + { + if ($this->get_data('post_username')) + { + $username = $this->get_data('post_username'); + } + else + { + $user_data = $this->user_loader->get_user($this->get_data('poster_id')); + + $username = get_username_string('username', $user_data['user_id'], $user_data['username'], $user_data['user_colour']); + } + + return array( + 'AUTHOR_NAME' => htmlspecialchars_decode($username), + 'FORUM_NAME' => htmlspecialchars_decode($this->get_data('forum_name')), + 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($this->get_data('topic_title'))), + + 'U_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_VIEW_TOPIC' => generate_board_url() . "/viewtopic.{$this->php_ext}?f={$this->item_parent_id}&t={$this->item_id}", + 'U_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?f={$this->item_parent_id}", + 'U_STOP_WATCHING_FORUM' => generate_board_url() . "/viewforum.{$this->php_ext}?uid={$this->user_id}&f={$this->item_parent_id}&unwatch=forum", + ); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "f={$this->item_parent_id}&t={$this->item_id}"); + } + + /** + * Users needed to query before this notification can be displayed + * + * @return array Array of user_ids + */ + public function users_to_query() + { + return array($this->data['poster_id']); + } + + /** + * Pre create insert array function + * This allows you to perform certain actions, like run a query + * and load data, before create_insert_array() is run. The data + * returned from this function will be sent to create_insert_array(). + * + * @param array $post Post data from submit_post + * @param array $notify_users Notify users list + * Formated from find_users_for_notification() + * @return array Whatever you want to send to create_insert_array(). + */ + public function pre_create_insert_array($post, $notify_users) + { + if (!sizeof($notify_users)) + { + return array(); + } + + $tracking_data = array(); + $sql = 'SELECT user_id, mark_time FROM ' . TOPICS_TRACK_TABLE . ' + WHERE topic_id = ' . (int) $post['topic_id'] . ' + AND ' . $this->db->sql_in_set('user_id', array_keys($notify_users)); + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) + { + $tracking_data[$row['user_id']] = $row['mark_time']; + } + + return $tracking_data; + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $post Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($post, $pre_create_data = array()) + { + $this->set_data('poster_id', $post['poster_id']); + + $this->set_data('topic_title', $post['topic_title']); + + $this->set_data('post_username', (($post['poster_id'] == ANONYMOUS) ? $post['post_username'] : '')); + + $this->set_data('forum_name', $post['forum_name']); + + $this->time = $post['post_time']; + + // Topics can be "read" before they are public (while awaiting approval). + // Make sure that if the user has read the topic, it's marked as read in the notification + if (isset($pre_create_data[$this->user_id]) && $pre_create_data[$this->user_id] >= $this->time) + { + $this->unread = false; + } + + return parent::create_insert_array($post, $pre_create_data); + } +} diff --git a/phpBB/includes/notification/type/topic_in_queue.php b/phpBB/includes/notification/type/topic_in_queue.php new file mode 100644 index 0000000000..170a98ca1b --- /dev/null +++ b/phpBB/includes/notification/type/topic_in_queue.php @@ -0,0 +1,130 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Topic in queue notifications class +* This class handles notifications for topics when they are put in the moderation queue (for moderators) +* +* @package notifications +*/ +class phpbb_notification_type_topic_in_queue extends phpbb_notification_type_topic +{ + /** + * Get notification type name + * + * @return string + */ + public function get_type() + { + return 'topic_in_queue'; + } + + /** + * Language key used to output the text + * + * @var string + */ + protected $language_key = 'NOTIFICATION_TOPIC_IN_QUEUE'; + + /** + * Notification option data (for outputting to the user) + * + * @var bool|array False if the service should use it's default data + * Array of data (including keys 'id', 'lang', and 'group') + */ + public static $notification_option = array( + 'id' => 'needs_approval', + 'lang' => 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE', + 'group' => 'NOTIFICATION_GROUP_MODERATION', + ); + + /** + * Is available + */ + public function is_available() + { + $m_approve = $this->auth->acl_getf('m_approve', true); + + return (!empty($m_approve)); + } + + /** + * Find the users who want to receive notifications + * + * @param array $topic Data from the topic + * + * @return array + */ + public function find_users_for_notification($topic, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + // 0 is for global + $auth_approve = $this->auth->acl_get_list(false, 'm_approve', array($topic['forum_id'], 0)); + + if (empty($auth_approve)) + { + return array(); + } + + $auth_approve[$topic['forum_id']] = array_unique(array_merge($auth_approve[$topic['forum_id']], $auth_approve[0])); + + return $this->check_user_notification_options($auth_approve[$topic['forum_id']]['m_approve'], array_merge($options, array( + 'item_type' => self::$notification_option['id'], + ))); + } + + /** + * Get the url to this item + * + * @return string URL + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "i=queue&mode=approve_details&f={$this->item_parent_id}&t={$this->item_id}"); + } + + /** + * Function for preparing the data for insertion in an SQL query + * (The service handles insertion) + * + * @param array $topic Data from submit_post + * @param array $pre_create_data Data from pre_create_insert_array() + * + * @return array Array of data ready to be inserted into the database + */ + public function create_insert_array($topic, $pre_create_data = array()) + { + $data = parent::create_insert_array($topic, $pre_create_data); + + $this->time = $data['time'] = time(); + + return $data; + } + + /** + * Get email template + * + * @return string|bool + */ + public function get_email_template() + { + return 'topic_in_queue'; + } +} diff --git a/phpBB/includes/ucp/info/ucp_notifications.php b/phpBB/includes/ucp/info/ucp_notifications.php new file mode 100644 index 0000000000..98d8b9db61 --- /dev/null +++ b/phpBB/includes/ucp/info/ucp_notifications.php @@ -0,0 +1,35 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @package module_install +*/ +class ucp_notifications_info +{ + function module() + { + return array( + 'filename' => 'ucp_notifications', + 'title' => 'UCP_NOTIFICATION_OPTIONS', + 'version' => '1.0.0', + 'modes' => array( + 'notification_options' => array('title' => 'UCP_NOTIFICATION_OPTIONS', 'auth' => '', 'cat' => array('UCP_PREFS')), + 'notification_list' => array('title' => 'UCP_NOTIFICATION_LIST', 'auth' => '', 'cat' => array('UCP_MAIN')), + ), + ); + } + + function install() + { + } + + function uninstall() + { + } +} diff --git a/phpBB/includes/ucp/ucp_notifications.php b/phpBB/includes/ucp/ucp_notifications.php new file mode 100644 index 0000000000..e8ceac3f59 --- /dev/null +++ b/phpBB/includes/ucp/ucp_notifications.php @@ -0,0 +1,224 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +class ucp_notifications +{ + public $u_action; + + public function main($id, $mode) + { + global $config, $template, $user, $request, $phpbb_notifications; + global $phpbb_root_path, $phpEx; + + add_form_key('ucp_notification'); + + $start = request_var('start', 0); + $form_time = min(request_var('form_time', 0), time()); + + switch ($mode) + { + case 'notification_options': + $subscriptions = $phpbb_notifications->get_global_subscriptions(false); + + // Add/remove subscriptions + if ($request->is_set_post('submit')) + { + if (!check_form_key('ucp_notification')) + { + trigger_error('FORM_INVALID'); + } + + $notification_methods = $phpbb_notifications->get_subscription_methods(); + + foreach($phpbb_notifications->get_subscription_types() as $group => $subscription_types) + { + foreach($subscription_types as $type => $data) + { + foreach($notification_methods as $method => $method_data) + { + if ($request->is_set_post($type . '_' . $method_data['id']) && (!isset($subscriptions[$type]) || !in_array($method_data['id'], $subscriptions[$type]))) + { + $phpbb_notifications->add_subscription($type, 0, $method_data['id']); + } + else if (!$request->is_set_post($type . '_' . $method_data['id']) && isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) + { + $phpbb_notifications->delete_subscription($type, 0, $method_data['id']); + } + } + + if ($request->is_set_post($type . '_notification') && !isset($subscriptions[$type])) + { + $phpbb_notifications->add_subscription($type); + } + else if (!$request->is_set_post($type . '_notification') && isset($subscriptions[$type])) + { + $phpbb_notifications->delete_subscription($type); + } + } + } + + meta_refresh(3, $this->u_action); + $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); + trigger_error($message); + } + + $this->output_notification_methods('notification_methods', $phpbb_notifications, $template, $user); + + $this->output_notification_types($subscriptions, 'notification_types', $phpbb_notifications, $template, $user); + + $this->tpl_name = 'ucp_notifications'; + $this->page_title = 'UCP_NOTIFICATION_OPTIONS'; + break; + + case 'notification_list': + default: + // Mark all items read + if (request_var('mark', '') == 'all' && (confirm_box(true) || check_link_hash(request_var('token', ''), 'mark_all_notifications_read'))) + { + if (confirm_box(true)) + { + $phpbb_notifications->mark_notifications_read(false, false, $user->data['user_id'], $form_time); + + meta_refresh(3, $this->u_action); + $message = $user->lang['NOTIFICATIONS_MARK_ALL_READ_SUCCESS'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); + trigger_error($message); + } + else + { + confirm_box(false, 'NOTIFICATIONS_MARK_ALL_READ', build_hidden_fields(array( + 'mark' => 'all', + 'form_time' => $form_time, + ))); + } + } + + // Mark specific notifications read + if ($request->is_set_post('submit')) + { + if (!check_form_key('ucp_notification')) + { + trigger_error('FORM_INVALID'); + } + + $mark_read = request_var('mark', array(0)); + + if (!empty($mark_read)) + { + $phpbb_notifications->mark_notifications_read_by_id($mark_read, $form_time); + } + } + + $notifications = $phpbb_notifications->load_notifications(array( + 'start' => $start, + 'limit' => $config['topics_per_page'], + 'count_total' => true, + )); + + foreach ($notifications['notifications'] as $notification) + { + $template->assign_block_vars('notification_list', $notification->prepare_for_display()); + } + + $base_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=ucp_notifications&mode=notification_list"); + phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $notifications['total_count'], $config['topics_per_page'], $start); + + $template->assign_vars(array( + 'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $notifications['total_count'], $config['topics_per_page'], $start), + 'TOTAL_COUNT' => $user->lang('NOTIFICATIONS_COUNT', $notifications['total_count']), + 'U_MARK_ALL' => $base_url . '&mark=all&token=' . generate_link_hash('mark_all_notifications_read'), + )); + + $this->tpl_name = 'ucp_notifications'; + $this->page_title = 'UCP_NOTIFICATION_LIST'; + break; + } + + $template->assign_vars(array( + 'TITLE' => $user->lang($this->page_title), + 'TITLE_EXPLAIN' => $user->lang($this->page_title . '_EXPLAIN'), + + 'MODE' => $mode, + + 'FORM_TIME' => time(), + )); + } + + /** + * Output all the notification types to the template + * + * @param string $block + * @param phpbb_notification_manager $phpbb_notifications + * @param phpbb_template $template + * @param phpbb_user $user + */ + public function output_notification_types($subscriptions, $block = 'notification_types', phpbb_notification_manager $phpbb_notifications, phpbb_template $template, phpbb_user $user) + { + $notification_methods = $phpbb_notifications->get_subscription_methods(); + + foreach($phpbb_notifications->get_subscription_types() as $group => $subscription_types) + { + $template->assign_block_vars($block, array( + 'GROUP_NAME' => $user->lang($group), + )); + + foreach($subscription_types as $type => $data) + { + $template->assign_block_vars($block, array( + 'TYPE' => $type, + + 'NAME' => $user->lang($data['lang']), + 'EXPLAIN' => (isset($user->lang[$data['lang'] . '_EXPLAIN'])) ? $user->lang($data['lang'] . '_EXPLAIN') : '', + + 'SUBSCRIBED' => (isset($subscriptions[$type])) ? true : false, + )); + + foreach($notification_methods as $method => $method_data) + { + $template->assign_block_vars($block . '.notification_methods', array( + 'METHOD' => $method_data['id'], + + 'NAME' => $user->lang($method_data['lang']), + + 'SUBSCRIBED' => (isset($subscriptions[$type]) && in_array($method_data['id'], $subscriptions[$type])) ? true : false, + )); + } + } + } + } + + /** + * Output all the notification methods to the template + * + * @param string $block + * @param phpbb_notification_manager $phpbb_notifications + * @param phpbb_template $template + * @param phpbb_user $user + */ + public function output_notification_methods($block = 'notification_methods', phpbb_notification_manager $phpbb_notifications, phpbb_template $template, phpbb_user $user) + { + $notification_methods = $phpbb_notifications->get_subscription_methods(); + + foreach($notification_methods as $method => $method_data) + { + $template->assign_block_vars($block, array( + 'METHOD' => $method_data['id'], + + 'NAME' => $user->lang($method_data['lang']), + )); + } + } +} diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 2228bc7931..4b49d2092d 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -46,8 +46,6 @@ class ucp_prefs 'viewemail' => request_var('viewemail', (bool) $user->data['user_allow_viewemail']), 'massemail' => request_var('massemail', (bool) $user->data['user_allow_massemail']), 'hideonline' => request_var('hideonline', (bool) !$user->data['user_allow_viewonline']), - 'notifypm' => request_var('notifypm', (bool) $user->data['user_notify_pm']), - 'popuppm' => request_var('popuppm', (bool) $user->optionget('popuppm')), 'allowpm' => request_var('allowpm', (bool) $user->data['user_allow_pm']), ); @@ -81,15 +79,12 @@ class ucp_prefs if (!sizeof($error)) { - $user->optionset('popuppm', $data['popuppm']); - $sql_ary = array( 'user_allow_pm' => $data['allowpm'], 'user_allow_viewemail' => $data['viewemail'], 'user_allow_massemail' => $data['massemail'], 'user_allow_viewonline' => ($auth->acl_get('u_hideonline')) ? !$data['hideonline'] : $user->data['user_allow_viewonline'], 'user_notify_type' => $data['notifymethod'], - 'user_notify_pm' => $data['notifypm'], 'user_options' => $user->data['user_options'], 'user_dateformat' => $data['dateformat'], @@ -142,8 +137,6 @@ class ucp_prefs 'S_MASS_EMAIL' => $data['massemail'], 'S_ALLOW_PM' => $data['allowpm'], 'S_HIDE_ONLINE' => $data['hideonline'], - 'S_NOTIFY_PM' => $data['notifypm'], - 'S_POPUP_PM' => $data['popuppm'], 'DATE_FORMAT' => $data['dateformat'], 'A_DATE_FORMAT' => addslashes($data['dateformat']), diff --git a/phpBB/includes/user_loader.php b/phpBB/includes/user_loader.php new file mode 100644 index 0000000000..a530f21f75 --- /dev/null +++ b/phpBB/includes/user_loader.php @@ -0,0 +1,118 @@ +<?php +/** +* +* @package phpBB3 +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* User loader class +* +* This handles loading users from the database and +* storing in them in a temporary cache so we do not +* have to query the same user multiple times in +* different services. +*/ +class phpbb_user_loader +{ + /** @var dbal */ + protected $db = null; + + /** @var string */ + protected $phpbb_root_path = null; + + /** @var string */ + protected $php_ext = null; + + /** @var string */ + protected $users_table = null; + + /** + * Users loaded from the DB + * + * @var array Array of user data that we've loaded from the DB + */ + protected $users = array(); + + public function __construct(dbal $db, $phpbb_root_path, $php_ext, $users_table) + { + $this->db = $db; + + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + + $this->users_table = $users_table; + } + + /** + * Load user helper + * + * @param array $user_ids + */ + public function load_users(array $user_ids) + { + $user_ids[] = ANONYMOUS; + + // Load the users + $user_ids = array_unique($user_ids); + + // Do not load users we already have in $this->users + $user_ids = array_diff($user_ids, array_keys($this->users)); + + if (sizeof($user_ids)) + { + $sql = 'SELECT * + FROM ' . $this->users_table . ' + WHERE ' . $this->db->sql_in_set('user_id', $user_ids); + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $this->users[$row['user_id']] = $row; + } + $this->db->sql_freeresult($result); + } + } + + /** + * Get a user row from our users cache + * + * @param int $user_id + * @return array|bool Row from the database of the user or Anonymous if the user wasn't loaded/does not exist + * or bool False if the anonymous user was not loaded + */ + public function get_user($user_id) + { + return (isset($this->users[$user_id])) ? $this->users[$user_id] : (isset($this->users[ANONYMOUS]) ? $this->users[ANONYMOUS] : false); + } + + /** + * Get avatar + * + * @param int $user_id + * @return string + */ + public function get_avatar($user_id) + { + if (!($user = $this->get_user($user_id))) + { + return ''; + } + + if (!function_exists('get_user_avatar')) + { + include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); + } + + return get_user_avatar($user['user_avatar'], $user['user_avatar_type'], $user['user_avatar_width'], $user['user_avatar_height']); + } +}
\ No newline at end of file diff --git a/phpBB/index.php b/phpBB/index.php index 845d0f0c02..94b2b17084 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -24,6 +24,28 @@ $user->session_begin(); $auth->acl($user->data); $user->setup('viewforum'); +// Mark notifications read +if (($mark_notification = request_var('mark_notification', 0))) +{ + $notification = $phpbb_notifications->load_notifications(array( + 'notification_id' => $mark_notification + )); + + if (isset($notification['notifications'][$mark_notification])) + { + $notification = $notification['notifications'][$mark_notification]; + + $notification->mark_read(); + + if (($redirect = request_var('redirect', ''))) + { + redirect(append_sid($phpbb_root_path . $redirect)); + } + + redirect($notification->get_url()); + } +} + display_forums('', $config['load_moderators']); $order_legend = ($config['legend_sort_groupname']) ? 'group_name' : 'group_legend'; diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 377e38c423..ca3e506c2b 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -1108,6 +1108,49 @@ function database_update_info() 'ext_name' => array('UNIQUE', 'ext_name'), ), ), + $table_prefix . 'notifications' => array( + 'COLUMNS' => array( + 'notification_id' => array('UINT', NULL, 'auto_increment'), + 'item_type' => array('VCHAR:255', ''), + 'item_id' => array('UINT', 0), + 'item_parent_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'unread' => array('BOOL', 1), + 'is_enabled' => array('BOOL', 1), + 'time' => array('TIMESTAMP', 1), + 'data' => array('TEXT_UNI', ''), + ), + 'PRIMARY_KEY' => 'notification_id', + 'KEYS' => array( + 'item_type' => array('INDEX', 'item_type'), + 'item_id' => array('INDEX', 'item_id'), + 'item_pid' => array('INDEX', 'item_parent_id'), + 'user_id' => array('INDEX', 'user_id'), + 'time' => array('INDEX', 'time'), + 'unread' => array('INDEX', 'unread'), + 'is_enabled' => array('INDEX', 'is_enabled'), + ), + ), + $table_prefix . 'user_notifications' => array( + 'COLUMNS' => array( + 'item_type' => array('VCHAR:255', ''), + 'item_id' => array('UINT', 0), + 'user_id' => array('UINT', 0), + 'method' => array('VCHAR:255', ''), + 'notify' => array('BOOL', 1), + ), + 'PRIMARY_KEY' => array( + 'item_type', + 'item_id', + 'user_id', + 'method', + ), + 'KEYS' => array( + 'it' => array('INDEX', 'item_type'), + 'uid' => array('INDEX', 'user_id'), + 'no' => array('INDEX', 'notify'), + ), + ), ), 'add_columns' => array( GROUPS_TABLE => array( @@ -2476,6 +2519,20 @@ function change_database_data(&$no_updates, $version) 'auth' => '', 'cat' => 'UCP_PROFILE', ), + 'notification_options' => array( + 'base' => 'ucp_notifications', + 'class' => 'ucp', + 'title' => 'UCP_NOTIFICATION_OPTIONS', + 'auth' => '', + 'cat' => 'UCP_PREFS', + ), + 'notification_list' => array( + 'base' => 'ucp_notifications', + 'class' => 'ucp', + 'title' => 'UCP_NOTIFICATION_LIST', + 'auth' => '', + 'cat' => 'UCP_MAIN', + ), ); _add_modules($modules_to_install); @@ -2750,6 +2807,72 @@ function change_database_data(&$no_updates, $version) $config->set('site_home_text', ''); } + if (!isset($config['load_notifications'])) + { + $config->set('load_notifications', 1); + + // Convert notifications + $convert_notifications = array( + array( + 'check' => ($config['allow_topic_notify']), + 'item_type' => 'post', + ), + array( + 'check' => ($config['allow_forum_notify']), + 'item_type' => 'topic', + ), + array( + 'check' => ($config['allow_bookmarks']), + 'item_type' => 'bookmark', + ), + array( + 'check' => ($config['allow_privmsg']), + 'item_type' => 'pm', + ), + ); + + foreach ($convert_notifications as $convert_data) + { + if ($convert_data['check']) + { + $sql = 'SELECT user_id, user_notify_type + FROM ' . USERS_TABLE . ' + WHERE user_notify = 1'; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + _sql('INSERT INTO ' . $table_prefix . 'user_notifications ' . $db->sql_build_array('INSERT', array( + 'item_type' => $convert_data['item_type'], + 'item_id' => 0, + 'user_id' => $row['user_id'], + 'method' => '', + )), $errored, $error_ary); + + if ($row['user_notify_type'] == NOTIFY_EMAIL || $row['user_notify_type'] == NOTIFY_BOTH) + { + _sql('INSERT INTO ' . $table_prefix . 'user_notifications ' . $db->sql_build_array('INSERT', array( + 'item_type' => $convert_data['item_type'], + 'item_id' => 0, + 'user_id' => $row['user_id'], + 'method' => 'email', + )), $errored, $error_ary); + } + + if ($row['user_notify_type'] == NOTIFY_IM || $row['user_notify_type'] == NOTIFY_BOTH) + { + _sql('INSERT INTO ' . $table_prefix . 'user_notifications ' . $db->sql_build_array('INSERT', array( + 'item_type' => $convert_data['item_type'], + 'item_id' => 0, + 'user_id' => $row['user_id'], + 'method' => 'jabber', + )), $errored, $error_ary); + } + } + $db->sql_freeresult($result); + } + } + } + break; } } diff --git a/phpBB/install/schemas/firebird_schema.sql b/phpBB/install/schemas/firebird_schema.sql index 767ce68b4a..8456958800 100644 --- a/phpBB/install/schemas/firebird_schema.sql +++ b/phpBB/install/schemas/firebird_schema.sql @@ -618,6 +618,40 @@ BEGIN END;; +# Table: 'phpbb_notifications' +CREATE TABLE phpbb_notifications ( + notification_id INTEGER NOT NULL, + item_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, + item_id INTEGER DEFAULT 0 NOT NULL, + item_parent_id INTEGER DEFAULT 0 NOT NULL, + user_id INTEGER DEFAULT 0 NOT NULL, + unread INTEGER DEFAULT 1 NOT NULL, + is_enabled INTEGER DEFAULT 1 NOT NULL, + time INTEGER DEFAULT 1 NOT NULL, + data BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL +);; + +ALTER TABLE phpbb_notifications ADD PRIMARY KEY (notification_id);; + +CREATE INDEX phpbb_notifications_item_type ON phpbb_notifications(item_type);; +CREATE INDEX phpbb_notifications_item_id ON phpbb_notifications(item_id);; +CREATE INDEX phpbb_notifications_item_pid ON phpbb_notifications(item_parent_id);; +CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications(user_id);; +CREATE INDEX phpbb_notifications_time ON phpbb_notifications(time);; +CREATE INDEX phpbb_notifications_unread ON phpbb_notifications(unread);; +CREATE INDEX phpbb_notifications_is_enabled ON phpbb_notifications(is_enabled);; + +CREATE GENERATOR phpbb_notifications_gen;; +SET GENERATOR phpbb_notifications_gen TO 0;; + +CREATE TRIGGER t_phpbb_notifications FOR phpbb_notifications +BEFORE INSERT +AS +BEGIN + NEW.notification_id = GEN_ID(phpbb_notifications_gen, 1); +END;; + + # Table: 'phpbb_poll_options' CREATE TABLE phpbb_poll_options ( poll_option_id INTEGER DEFAULT 0 NOT NULL, @@ -912,8 +946,8 @@ CREATE TABLE phpbb_reports ( report_time INTEGER DEFAULT 0 NOT NULL, report_text BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL, reported_post_text BLOB SUB_TYPE TEXT CHARACTER SET UTF8 DEFAULT '' NOT NULL, - reported_post_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, - reported_post_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL + reported_post_uid VARCHAR(8) CHARACTER SET NONE DEFAULT '' NOT NULL, + reported_post_bitfield VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL );; ALTER TABLE phpbb_reports ADD PRIMARY KEY (report_id);; @@ -1203,6 +1237,21 @@ CREATE INDEX phpbb_topics_watch_topic_id ON phpbb_topics_watch(topic_id);; CREATE INDEX phpbb_topics_watch_user_id ON phpbb_topics_watch(user_id);; CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch(notify_status);; +# Table: 'phpbb_user_notifications' +CREATE TABLE phpbb_user_notifications ( + item_type VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, + item_id INTEGER DEFAULT 0 NOT NULL, + user_id INTEGER DEFAULT 0 NOT NULL, + method VARCHAR(255) CHARACTER SET NONE DEFAULT '' NOT NULL, + notify INTEGER DEFAULT 1 NOT NULL +);; + +ALTER TABLE phpbb_user_notifications ADD PRIMARY KEY (item_type, item_id, user_id, method);; + +CREATE INDEX phpbb_user_notifications_it ON phpbb_user_notifications(item_type);; +CREATE INDEX phpbb_user_notifications_uid ON phpbb_user_notifications(user_id);; +CREATE INDEX phpbb_user_notifications_no ON phpbb_user_notifications(notify);; + # Table: 'phpbb_user_group' CREATE TABLE phpbb_user_group ( group_id INTEGER DEFAULT 0 NOT NULL, diff --git a/phpBB/install/schemas/mssql_schema.sql b/phpBB/install/schemas/mssql_schema.sql index 84c975942f..d0023aa411 100644 --- a/phpBB/install/schemas/mssql_schema.sql +++ b/phpBB/install/schemas/mssql_schema.sql @@ -752,6 +752,51 @@ GO /* + Table: 'phpbb_notifications' +*/ +CREATE TABLE [phpbb_notifications] ( + [notification_id] [int] IDENTITY (1, 1) NOT NULL , + [item_type] [varchar] (255) DEFAULT ('') NOT NULL , + [item_id] [int] DEFAULT (0) NOT NULL , + [item_parent_id] [int] DEFAULT (0) NOT NULL , + [user_id] [int] DEFAULT (0) NOT NULL , + [unread] [int] DEFAULT (1) NOT NULL , + [is_enabled] [int] DEFAULT (1) NOT NULL , + [time] [int] DEFAULT (1) NOT NULL , + [data] [varchar] (4000) DEFAULT ('') NOT NULL +) ON [PRIMARY] +GO + +ALTER TABLE [phpbb_notifications] WITH NOCHECK ADD + CONSTRAINT [PK_phpbb_notifications] PRIMARY KEY CLUSTERED + ( + [notification_id] + ) ON [PRIMARY] +GO + +CREATE INDEX [item_type] ON [phpbb_notifications]([item_type]) ON [PRIMARY] +GO + +CREATE INDEX [item_id] ON [phpbb_notifications]([item_id]) ON [PRIMARY] +GO + +CREATE INDEX [item_pid] ON [phpbb_notifications]([item_parent_id]) ON [PRIMARY] +GO + +CREATE INDEX [user_id] ON [phpbb_notifications]([user_id]) ON [PRIMARY] +GO + +CREATE INDEX [time] ON [phpbb_notifications]([time]) ON [PRIMARY] +GO + +CREATE INDEX [unread] ON [phpbb_notifications]([unread]) ON [PRIMARY] +GO + +CREATE INDEX [is_enabled] ON [phpbb_notifications]([is_enabled]) ON [PRIMARY] +GO + + +/* Table: 'phpbb_poll_options' */ CREATE TABLE [phpbb_poll_options] ( @@ -1111,8 +1156,8 @@ CREATE TABLE [phpbb_reports] ( [report_time] [int] DEFAULT (0) NOT NULL , [report_text] [text] DEFAULT ('') NOT NULL , [reported_post_text] [text] DEFAULT ('') NOT NULL , - [reported_post_bitfield] [varchar] (255) DEFAULT ('') NOT NULL , - [reported_post_uid] [varchar] (8) DEFAULT ('') NOT NULL + [reported_post_uid] [varchar] (8) DEFAULT ('') NOT NULL , + [reported_post_bitfield] [varchar] (255) DEFAULT ('') NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO @@ -1477,6 +1522,38 @@ GO /* + Table: 'phpbb_user_notifications' +*/ +CREATE TABLE [phpbb_user_notifications] ( + [item_type] [varchar] (255) DEFAULT ('') NOT NULL , + [item_id] [int] DEFAULT (0) NOT NULL , + [user_id] [int] DEFAULT (0) NOT NULL , + [method] [varchar] (255) DEFAULT ('') NOT NULL , + [notify] [int] DEFAULT (1) NOT NULL +) ON [PRIMARY] +GO + +ALTER TABLE [phpbb_user_notifications] WITH NOCHECK ADD + CONSTRAINT [PK_phpbb_user_notifications] PRIMARY KEY CLUSTERED + ( + [item_type], + [item_id], + [user_id], + [method] + ) ON [PRIMARY] +GO + +CREATE INDEX [it] ON [phpbb_user_notifications]([item_type]) ON [PRIMARY] +GO + +CREATE INDEX [uid] ON [phpbb_user_notifications]([user_id]) ON [PRIMARY] +GO + +CREATE INDEX [no] ON [phpbb_user_notifications]([notify]) ON [PRIMARY] +GO + + +/* Table: 'phpbb_user_group' */ CREATE TABLE [phpbb_user_group] ( diff --git a/phpBB/install/schemas/mysql_40_schema.sql b/phpBB/install/schemas/mysql_40_schema.sql index 8aab949103..07e529e833 100644 --- a/phpBB/install/schemas/mysql_40_schema.sql +++ b/phpBB/install/schemas/mysql_40_schema.sql @@ -430,6 +430,28 @@ CREATE TABLE phpbb_modules ( ); +# Table: 'phpbb_notifications' +CREATE TABLE phpbb_notifications ( + notification_id mediumint(8) UNSIGNED NOT NULL auto_increment, + item_type varbinary(255) DEFAULT '' NOT NULL, + item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + unread tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + is_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + time int(11) UNSIGNED DEFAULT '1' NOT NULL, + data blob NOT NULL, + PRIMARY KEY (notification_id), + KEY item_type (item_type), + KEY item_id (item_id), + KEY item_pid (item_parent_id), + KEY user_id (user_id), + KEY time (time), + KEY unread (unread), + KEY is_enabled (is_enabled) +); + + # Table: 'phpbb_poll_options' CREATE TABLE phpbb_poll_options ( poll_option_id tinyint(4) DEFAULT '0' NOT NULL, @@ -649,8 +671,8 @@ CREATE TABLE phpbb_reports ( report_time int(11) UNSIGNED DEFAULT '0' NOT NULL, report_text mediumblob NOT NULL, reported_post_text mediumblob NOT NULL, - reported_post_bitfield varbinary(255) DEFAULT '' NOT NULL, reported_post_uid varbinary(8) DEFAULT '' NOT NULL, + reported_post_bitfield varbinary(255) DEFAULT '' NOT NULL, PRIMARY KEY (report_id), KEY post_id (post_id), KEY pm_id (pm_id) @@ -851,6 +873,20 @@ CREATE TABLE phpbb_topics_watch ( ); +# Table: 'phpbb_user_notifications' +CREATE TABLE phpbb_user_notifications ( + item_type varbinary(255) DEFAULT '' NOT NULL, + item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + method varbinary(255) DEFAULT '' NOT NULL, + notify tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + PRIMARY KEY (item_type, item_id, user_id, method), + KEY it (item_type), + KEY uid (user_id), + KEY no (notify) +); + + # Table: 'phpbb_user_group' CREATE TABLE phpbb_user_group ( group_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, diff --git a/phpBB/install/schemas/mysql_41_schema.sql b/phpBB/install/schemas/mysql_41_schema.sql index 04aef2844a..361f53c313 100644 --- a/phpBB/install/schemas/mysql_41_schema.sql +++ b/phpBB/install/schemas/mysql_41_schema.sql @@ -430,6 +430,28 @@ CREATE TABLE phpbb_modules ( ) CHARACTER SET `utf8` COLLATE `utf8_bin`; +# Table: 'phpbb_notifications' +CREATE TABLE phpbb_notifications ( + notification_id mediumint(8) UNSIGNED NOT NULL auto_increment, + item_type varchar(255) DEFAULT '' NOT NULL, + item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + item_parent_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + unread tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + is_enabled tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + time int(11) UNSIGNED DEFAULT '1' NOT NULL, + data text NOT NULL, + PRIMARY KEY (notification_id), + KEY item_type (item_type), + KEY item_id (item_id), + KEY item_pid (item_parent_id), + KEY user_id (user_id), + KEY time (time), + KEY unread (unread), + KEY is_enabled (is_enabled) +) CHARACTER SET `utf8` COLLATE `utf8_bin`; + + # Table: 'phpbb_poll_options' CREATE TABLE phpbb_poll_options ( poll_option_id tinyint(4) DEFAULT '0' NOT NULL, @@ -649,8 +671,8 @@ CREATE TABLE phpbb_reports ( report_time int(11) UNSIGNED DEFAULT '0' NOT NULL, report_text mediumtext NOT NULL, reported_post_text mediumtext NOT NULL, - reported_post_bitfield varchar(255) DEFAULT '' NOT NULL, reported_post_uid varchar(8) DEFAULT '' NOT NULL, + reported_post_bitfield varchar(255) DEFAULT '' NOT NULL, PRIMARY KEY (report_id), KEY post_id (post_id), KEY pm_id (pm_id) @@ -851,6 +873,20 @@ CREATE TABLE phpbb_topics_watch ( ) CHARACTER SET `utf8` COLLATE `utf8_bin`; +# Table: 'phpbb_user_notifications' +CREATE TABLE phpbb_user_notifications ( + item_type varchar(255) DEFAULT '' NOT NULL, + item_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + user_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, + method varchar(255) DEFAULT '' NOT NULL, + notify tinyint(1) UNSIGNED DEFAULT '1' NOT NULL, + PRIMARY KEY (item_type, item_id, user_id, method), + KEY it (item_type), + KEY uid (user_id), + KEY no (notify) +) CHARACTER SET `utf8` COLLATE `utf8_bin`; + + # Table: 'phpbb_user_group' CREATE TABLE phpbb_user_group ( group_id mediumint(8) UNSIGNED DEFAULT '0' NOT NULL, diff --git a/phpBB/install/schemas/oracle_schema.sql b/phpBB/install/schemas/oracle_schema.sql index 91f906bc8b..a2bb016dae 100644 --- a/phpBB/install/schemas/oracle_schema.sql +++ b/phpBB/install/schemas/oracle_schema.sql @@ -841,6 +841,54 @@ END; /* + Table: 'phpbb_notifications' +*/ +CREATE TABLE phpbb_notifications ( + notification_id number(8) NOT NULL, + item_type varchar2(255) DEFAULT '' , + item_id number(8) DEFAULT '0' NOT NULL, + item_parent_id number(8) DEFAULT '0' NOT NULL, + user_id number(8) DEFAULT '0' NOT NULL, + unread number(1) DEFAULT '1' NOT NULL, + is_enabled number(1) DEFAULT '1' NOT NULL, + time number(11) DEFAULT '1' NOT NULL, + data clob DEFAULT '' , + CONSTRAINT pk_phpbb_notifications PRIMARY KEY (notification_id) +) +/ + +CREATE INDEX phpbb_notifications_item_type ON phpbb_notifications (item_type) +/ +CREATE INDEX phpbb_notifications_item_id ON phpbb_notifications (item_id) +/ +CREATE INDEX phpbb_notifications_item_pid ON phpbb_notifications (item_parent_id) +/ +CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications (user_id) +/ +CREATE INDEX phpbb_notifications_time ON phpbb_notifications (time) +/ +CREATE INDEX phpbb_notifications_unread ON phpbb_notifications (unread) +/ +CREATE INDEX phpbb_notifications_is_enabled ON phpbb_notifications (is_enabled) +/ + +CREATE SEQUENCE phpbb_notifications_seq +/ + +CREATE OR REPLACE TRIGGER t_phpbb_notifications +BEFORE INSERT ON phpbb_notifications +FOR EACH ROW WHEN ( + new.notification_id IS NULL OR new.notification_id = 0 +) +BEGIN + SELECT phpbb_notifications_seq.nextval + INTO :new.notification_id + FROM dual; +END; +/ + + +/* Table: 'phpbb_poll_options' */ CREATE TABLE phpbb_poll_options ( @@ -1216,8 +1264,8 @@ CREATE TABLE phpbb_reports ( report_time number(11) DEFAULT '0' NOT NULL, report_text clob DEFAULT '' , reported_post_text clob DEFAULT '' , - reported_post_bitfield varchar2(255) DEFAULT '' , reported_post_uid varchar2(8) DEFAULT '' , + reported_post_bitfield varchar2(255) DEFAULT '' , CONSTRAINT pk_phpbb_reports PRIMARY KEY (report_id) ) / @@ -1592,6 +1640,26 @@ CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status / /* + Table: 'phpbb_user_notifications' +*/ +CREATE TABLE phpbb_user_notifications ( + item_type varchar2(255) DEFAULT '' , + item_id number(8) DEFAULT '0' NOT NULL, + user_id number(8) DEFAULT '0' NOT NULL, + method varchar2(255) DEFAULT '' , + notify number(1) DEFAULT '1' NOT NULL, + CONSTRAINT pk_phpbb_user_notifications PRIMARY KEY (item_type, item_id, user_id, method) +) +/ + +CREATE INDEX phpbb_user_notifications_it ON phpbb_user_notifications (item_type) +/ +CREATE INDEX phpbb_user_notifications_uid ON phpbb_user_notifications (user_id) +/ +CREATE INDEX phpbb_user_notifications_no ON phpbb_user_notifications (notify) +/ + +/* Table: 'phpbb_user_group' */ CREATE TABLE phpbb_user_group ( diff --git a/phpBB/install/schemas/postgres_schema.sql b/phpBB/install/schemas/postgres_schema.sql index 619985e0d6..94926d0b7a 100644 --- a/phpBB/install/schemas/postgres_schema.sql +++ b/phpBB/install/schemas/postgres_schema.sql @@ -597,6 +597,32 @@ CREATE INDEX phpbb_modules_module_enabled ON phpbb_modules (module_enabled); CREATE INDEX phpbb_modules_class_left_id ON phpbb_modules (module_class, left_id); /* + Table: 'phpbb_notifications' +*/ +CREATE SEQUENCE phpbb_notifications_seq; + +CREATE TABLE phpbb_notifications ( + notification_id INT4 DEFAULT nextval('phpbb_notifications_seq'), + item_type varchar(255) DEFAULT '' NOT NULL, + item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0), + item_parent_id INT4 DEFAULT '0' NOT NULL CHECK (item_parent_id >= 0), + user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0), + unread INT2 DEFAULT '1' NOT NULL CHECK (unread >= 0), + is_enabled INT2 DEFAULT '1' NOT NULL CHECK (is_enabled >= 0), + time INT4 DEFAULT '1' NOT NULL CHECK (time >= 0), + data varchar(4000) DEFAULT '' NOT NULL, + PRIMARY KEY (notification_id) +); + +CREATE INDEX phpbb_notifications_item_type ON phpbb_notifications (item_type); +CREATE INDEX phpbb_notifications_item_id ON phpbb_notifications (item_id); +CREATE INDEX phpbb_notifications_item_pid ON phpbb_notifications (item_parent_id); +CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications (user_id); +CREATE INDEX phpbb_notifications_time ON phpbb_notifications (time); +CREATE INDEX phpbb_notifications_unread ON phpbb_notifications (unread); +CREATE INDEX phpbb_notifications_is_enabled ON phpbb_notifications (is_enabled); + +/* Table: 'phpbb_poll_options' */ CREATE TABLE phpbb_poll_options ( @@ -855,8 +881,8 @@ CREATE TABLE phpbb_reports ( report_time INT4 DEFAULT '0' NOT NULL CHECK (report_time >= 0), report_text TEXT DEFAULT '' NOT NULL, reported_post_text TEXT DEFAULT '' NOT NULL, - reported_post_bitfield varchar(255) DEFAULT '' NOT NULL, reported_post_uid varchar(8) DEFAULT '' NOT NULL, + reported_post_bitfield varchar(255) DEFAULT '' NOT NULL, PRIMARY KEY (report_id) ); @@ -1096,6 +1122,22 @@ CREATE INDEX phpbb_topics_watch_user_id ON phpbb_topics_watch (user_id); CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status); /* + Table: 'phpbb_user_notifications' +*/ +CREATE TABLE phpbb_user_notifications ( + item_type varchar(255) DEFAULT '' NOT NULL, + item_id INT4 DEFAULT '0' NOT NULL CHECK (item_id >= 0), + user_id INT4 DEFAULT '0' NOT NULL CHECK (user_id >= 0), + method varchar(255) DEFAULT '' NOT NULL, + notify INT2 DEFAULT '1' NOT NULL CHECK (notify >= 0), + PRIMARY KEY (item_type, item_id, user_id, method) +); + +CREATE INDEX phpbb_user_notifications_it ON phpbb_user_notifications (item_type); +CREATE INDEX phpbb_user_notifications_uid ON phpbb_user_notifications (user_id); +CREATE INDEX phpbb_user_notifications_no ON phpbb_user_notifications (notify); + +/* Table: 'phpbb_user_group' */ CREATE TABLE phpbb_user_group ( diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index dbb5fd7481..e100a1dc14 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -175,6 +175,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_jquery_cdn', INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_jumpbox', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_moderators', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_notifications', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_online', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_online_guests', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('load_online_time', '5'); @@ -769,4 +770,10 @@ INSERT INTO phpbb_extensions (group_id, extension) VALUES (9, 'mp3'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (9, 'ogg'); INSERT INTO phpbb_extensions (group_id, extension) VALUES (9, 'ogm'); +# User Notification Options (for first user) +INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('phpbb_notification_type_post', 0, 2, ''); +INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('phpbb_notification_type_post', 0, 2, 'phpbb_notification_method_email'); +INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('phpbb_notification_type_topic', 0, 2, ''); +INSERT INTO phpbb_user_notifications (item_type, item_id, user_id, method) VALUES('phpbb_notification_type_topic', 0, 2, 'phpbb_notification_method_email'); + # POSTGRES COMMIT # diff --git a/phpBB/install/schemas/sqlite_schema.sql b/phpBB/install/schemas/sqlite_schema.sql index 1690a7dcab..43611ef70b 100644 --- a/phpBB/install/schemas/sqlite_schema.sql +++ b/phpBB/install/schemas/sqlite_schema.sql @@ -417,6 +417,27 @@ CREATE INDEX phpbb_modules_left_right_id ON phpbb_modules (left_id, right_id); CREATE INDEX phpbb_modules_module_enabled ON phpbb_modules (module_enabled); CREATE INDEX phpbb_modules_class_left_id ON phpbb_modules (module_class, left_id); +# Table: 'phpbb_notifications' +CREATE TABLE phpbb_notifications ( + notification_id INTEGER PRIMARY KEY NOT NULL , + item_type varchar(255) NOT NULL DEFAULT '', + item_id INTEGER UNSIGNED NOT NULL DEFAULT '0', + item_parent_id INTEGER UNSIGNED NOT NULL DEFAULT '0', + user_id INTEGER UNSIGNED NOT NULL DEFAULT '0', + unread INTEGER UNSIGNED NOT NULL DEFAULT '1', + is_enabled INTEGER UNSIGNED NOT NULL DEFAULT '1', + time INTEGER UNSIGNED NOT NULL DEFAULT '1', + data text(65535) NOT NULL DEFAULT '' +); + +CREATE INDEX phpbb_notifications_item_type ON phpbb_notifications (item_type); +CREATE INDEX phpbb_notifications_item_id ON phpbb_notifications (item_id); +CREATE INDEX phpbb_notifications_item_pid ON phpbb_notifications (item_parent_id); +CREATE INDEX phpbb_notifications_user_id ON phpbb_notifications (user_id); +CREATE INDEX phpbb_notifications_time ON phpbb_notifications (time); +CREATE INDEX phpbb_notifications_unread ON phpbb_notifications (unread); +CREATE INDEX phpbb_notifications_is_enabled ON phpbb_notifications (is_enabled); + # Table: 'phpbb_poll_options' CREATE TABLE phpbb_poll_options ( poll_option_id tinyint(4) NOT NULL DEFAULT '0', @@ -630,8 +651,8 @@ CREATE TABLE phpbb_reports ( report_time INTEGER UNSIGNED NOT NULL DEFAULT '0', report_text mediumtext(16777215) NOT NULL DEFAULT '', reported_post_text mediumtext(16777215) NOT NULL DEFAULT '', - reported_post_bitfield varchar(255) NOT NULL DEFAULT '', - reported_post_uid varchar(8) NOT NULL DEFAULT '' + reported_post_uid varchar(8) NOT NULL DEFAULT '', + reported_post_bitfield varchar(255) NOT NULL DEFAULT '' ); CREATE INDEX phpbb_reports_post_id ON phpbb_reports (post_id); @@ -825,6 +846,20 @@ CREATE INDEX phpbb_topics_watch_topic_id ON phpbb_topics_watch (topic_id); CREATE INDEX phpbb_topics_watch_user_id ON phpbb_topics_watch (user_id); CREATE INDEX phpbb_topics_watch_notify_stat ON phpbb_topics_watch (notify_status); +# Table: 'phpbb_user_notifications' +CREATE TABLE phpbb_user_notifications ( + item_type varchar(255) NOT NULL DEFAULT '', + item_id INTEGER UNSIGNED NOT NULL DEFAULT '0', + user_id INTEGER UNSIGNED NOT NULL DEFAULT '0', + method varchar(255) NOT NULL DEFAULT '', + notify INTEGER UNSIGNED NOT NULL DEFAULT '1', + PRIMARY KEY (item_type, item_id, user_id, method) +); + +CREATE INDEX phpbb_user_notifications_it ON phpbb_user_notifications (item_type); +CREATE INDEX phpbb_user_notifications_uid ON phpbb_user_notifications (user_id); +CREATE INDEX phpbb_user_notifications_no ON phpbb_user_notifications (notify); + # Table: 'phpbb_user_group' CREATE TABLE phpbb_user_group ( group_id INTEGER UNSIGNED NOT NULL DEFAULT '0', diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 5eb10d50b3..0096a84878 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -250,6 +250,8 @@ $lang = array_merge($lang, array( 'IP' => 'User IP', 'IP_HOSTNAME' => 'IP addresses or hostnames', + 'LOAD_NOTIFICATIONS' => 'Display Notifications', + 'LOAD_NOTIFICATIONS_EXPLAIN' => 'Display the notifications list on every page (typically in the header).', 'LOGGED_IN_AS' => 'You are logged in as:', 'LOGIN_ADMIN' => 'To administer the board you must be an authenticated user.', 'LOGIN_ADMIN_CONFIRM' => 'To administer the board you must re-authenticate yourself.', diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 7ce3b5d2e6..ef7cc6b941 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -348,6 +348,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', @@ -382,10 +383,30 @@ $lang = array_merge($lang, array( 'NEXT_STEP' => 'Next', 'NEVER' => 'Never', 'NO' => 'No', + 'NO_NOTIFICATIONS' => 'You have no notifications', 'NOT_ALLOWED_MANAGE_GROUP' => 'You are not allowed to manage this group.', '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_COUNT' => array( + 1 => '%d Notification', + 2 => '%d 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".', + 'NOTIFICATION_POST_APPROVED' => 'Your post was approved "%2$s".', + 'NOTIFICATION_POST_DISAPPROVED' => 'Your post "%1$s" was disapproved for reason: "%2$s".', + 'NOTIFICATION_POST_IN_QUEUE' => 'A new post titled "%2$s" was posted by %1$s and needs approval.', + 'NOTIFICATION_QUOTE' => '%1$s quoted you in the post "%2$s".', + 'NOTIFICATION_REPORT_PM' => '%1$s reported a Private Message "%2$s" for reason: "%3$s".', + 'NOTIFICATION_REPORT_POST' => '%1$s reported a post "%2$s" for reason: "%3$s".', + 'NOTIFICATION_REPORT_CLOSED' => '%1$s closed the report you made for "%2$s".', + 'NOTIFICATION_TOPIC' => '%1$s posted a new topic "%2$s" in the forum "%3$s".', + 'NOTIFICATION_TOPIC_APPROVED' => 'Your topic "%2$s" in the forum "%3$s" was approved.', + 'NOTIFICATION_TOPIC_DISAPPROVED' => 'Your topic "%1$s" was disapproved for reason: "%2$s".', + 'NOTIFICATION_TOPIC_IN_QUEUE' => 'A new topic titled "%2$s" was posted by %1$s and needs approval.', 'NOTIFY_ADMIN' => 'Please notify the board administrator or webmaster.', 'NOTIFY_ADMIN_EMAIL' => 'Please notify the board administrator or webmaster: <a href="mailto:%1$s">%1$s</a>', 'NO_ACCESS_ATTACHMENT' => 'You are not allowed to access this file.', @@ -573,6 +594,7 @@ $lang = array_merge($lang, array( 'SEARCH_UNREAD' => 'View unread posts', 'SEARCH_USER_POSTS' => 'Search user’s posts', 'SECONDS' => 'Seconds', + 'SEE_ALL' => 'See All', 'SELECT' => 'Select', 'SELECT_ALL_CODE' => 'Select all', 'SELECT_DESTINATION_FORUM' => 'Please select a destination forum', diff --git a/phpBB/language/en/email/bookmark.txt b/phpBB/language/en/email/bookmark.txt new file mode 100644 index 0000000000..95f17b5693 --- /dev/null +++ b/phpBB/language/en/email/bookmark.txt @@ -0,0 +1,20 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because a topic you bookmarked, "{TOPIC_TITLE}" at "{SITENAME}", has received a reply since your last visit. You can use the following link to view the replies made, no more notifications will be sent until you visit the topic. + +If you want to view the newest post made since your last visit, click the following link: +{U_NEWEST_POST} + +If you want to view the topic, click the following link: +{U_TOPIC} + +If you want to view the forum, click the following link: +{U_FORUM} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/forum_notify.txt b/phpBB/language/en/email/forum_notify.txt index 490780a0a6..66f3a68689 100644 --- a/phpBB/language/en/email/forum_notify.txt +++ b/phpBB/language/en/email/forum_notify.txt @@ -2,7 +2,7 @@ Subject: Forum post notification - "{FORUM_NAME}" Hello {USERNAME}, -You are receiving this notification because you are watching the forum, "{FORUM_NAME}" at "{SITENAME}". This forum has received a new reply to the topic "{TOPIC_TITLE}"<!-- IF AUTHOR_NAME --> by {AUTHOR_NAME}<!-- ENDIF --> since your last visit. You can use the following link to view the last unread reply, no more notifications will be sent until you visit the topic. +You are receiving this notification because you are watching the forum "{FORUM_NAME}" at "{SITENAME}". This forum has received a new reply to the topic "{TOPIC_TITLE}"<!-- IF AUTHOR_NAME --> by {AUTHOR_NAME}<!-- ENDIF --> since your last visit. You can use the following link to view the last unread reply, no more notifications will be sent until you visit the topic. {U_NEWEST_POST} diff --git a/phpBB/language/en/email/newtopic_notify.txt b/phpBB/language/en/email/newtopic_notify.txt index eda1370938..d4f5cae620 100644 --- a/phpBB/language/en/email/newtopic_notify.txt +++ b/phpBB/language/en/email/newtopic_notify.txt @@ -2,7 +2,7 @@ Subject: New topic notification - "{FORUM_NAME}" Hello {USERNAME}, -You are receiving this notification because you are watching the forum, "{FORUM_NAME}" at "{SITENAME}". This forum has received a new topic<!-- IF AUTHOR_NAME --> by {AUTHOR_NAME}<!-- ENDIF --> since your last visit, "{TOPIC_TITLE}". You can use the following link to view the forum, no more notifications will be sent until you visit the forum. +You are receiving this notification because you are watching the forum "{FORUM_NAME}" at "{SITENAME}". This forum has received a new topic<!-- IF AUTHOR_NAME --> by {AUTHOR_NAME}<!-- ENDIF --> since your last visit, "{TOPIC_TITLE}". You can use the following link to view the forum, no more notifications will be sent until you visit the forum. {U_FORUM} diff --git a/phpBB/language/en/email/post_in_queue.txt b/phpBB/language/en/email/post_in_queue.txt new file mode 100644 index 0000000000..8d56ce6c4d --- /dev/null +++ b/phpBB/language/en/email/post_in_queue.txt @@ -0,0 +1,17 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because the post "{POST_SUBJECT}" at "{SITENAME}" needs approval. + +If you want to view the post, click the following link: +{U_VIEW_POST} + +If you want to view the topic, click the following link: +{U_TOPIC} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/quote.txt b/phpBB/language/en/email/quote.txt new file mode 100644 index 0000000000..2b9525801f --- /dev/null +++ b/phpBB/language/en/email/quote.txt @@ -0,0 +1,20 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because "{AUTHOR_NAME}" quoted you in the topic "{TOPIC_TITLE}" at "{SITENAME}". You can use the following link to view the reply made. + +If you want to view the quoted post, click the following link: +{U_VIEW_POST} + +If you want to view the topic, click the following link: +{U_TOPIC} + +If you want to view the forum, click the following link: +{U_FORUM} + +If you no longer wish to receive updates about replies quoting you, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/report_pm.txt b/phpBB/language/en/email/report_pm.txt new file mode 100644 index 0000000000..66ae82d074 --- /dev/null +++ b/phpBB/language/en/email/report_pm.txt @@ -0,0 +1,14 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because a Private Message titled "{SUBJECT}" by "{AUTHOR_NAME}" at "{SITENAME}" was reported. + +If you want to view the report, click the following link: +{U_VIEW_REPORT} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/report_post.txt b/phpBB/language/en/email/report_post.txt new file mode 100644 index 0000000000..46983be1ed --- /dev/null +++ b/phpBB/language/en/email/report_post.txt @@ -0,0 +1,17 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because the post "{POST_SUBJECT}" at "{SITENAME}" was reported. + +If you want to view the report, click the following link: +{U_VIEW_REPORT} + +If you want to view the post, click the following link: +{U_VIEW_POST} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/short/bookmark.txt b/phpBB/language/en/email/short/bookmark.txt new file mode 100644 index 0000000000..95f17b5693 --- /dev/null +++ b/phpBB/language/en/email/short/bookmark.txt @@ -0,0 +1,20 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because a topic you bookmarked, "{TOPIC_TITLE}" at "{SITENAME}", has received a reply since your last visit. You can use the following link to view the replies made, no more notifications will be sent until you visit the topic. + +If you want to view the newest post made since your last visit, click the following link: +{U_NEWEST_POST} + +If you want to view the topic, click the following link: +{U_TOPIC} + +If you want to view the forum, click the following link: +{U_FORUM} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/short/newtopic_notify.txt b/phpBB/language/en/email/short/newtopic_notify.txt new file mode 100644 index 0000000000..d4f5cae620 --- /dev/null +++ b/phpBB/language/en/email/short/newtopic_notify.txt @@ -0,0 +1,13 @@ +Subject: New topic notification - "{FORUM_NAME}" + +Hello {USERNAME}, + +You are receiving this notification because you are watching the forum "{FORUM_NAME}" at "{SITENAME}". This forum has received a new topic<!-- IF AUTHOR_NAME --> by {AUTHOR_NAME}<!-- ENDIF --> since your last visit, "{TOPIC_TITLE}". You can use the following link to view the forum, no more notifications will be sent until you visit the forum. + +{U_FORUM} + +If you no longer wish to watch this forum you can either click the "Unsubscribe forum" link found in the forum above, or by clicking the following link: + +{U_STOP_WATCHING_FORUM} + +{EMAIL_SIG}
\ No newline at end of file diff --git a/phpBB/language/en/email/short/post_approved.txt b/phpBB/language/en/email/short/post_approved.txt new file mode 100644 index 0000000000..e715b54026 --- /dev/null +++ b/phpBB/language/en/email/short/post_approved.txt @@ -0,0 +1,14 @@ +Subject: Post approved - "{POST_SUBJECT}" + +Hello {USERNAME}, + +You are receiving this notification because your post "{POST_SUBJECT}" at "{SITENAME}" was approved by a moderator or administrator. + +If you want to view the post, click the following link: +{U_VIEW_POST} + +If you want to view the topic, click the following link: +{U_VIEW_TOPIC} + + +{EMAIL_SIG}
\ No newline at end of file diff --git a/phpBB/language/en/email/short/post_disapproved.txt b/phpBB/language/en/email/short/post_disapproved.txt new file mode 100644 index 0000000000..3bc64bb611 --- /dev/null +++ b/phpBB/language/en/email/short/post_disapproved.txt @@ -0,0 +1,12 @@ +Subject: Post disapproved - "{POST_SUBJECT}" + +Hello {USERNAME}, + +You are receiving this notification because your post "{POST_SUBJECT}" at "{SITENAME}" was disapproved by a moderator or administrator. + +The following reason was given for the disapproval: + +{REASON} + + +{EMAIL_SIG}
\ No newline at end of file diff --git a/phpBB/language/en/email/short/post_in_queue.txt b/phpBB/language/en/email/short/post_in_queue.txt new file mode 100644 index 0000000000..8d56ce6c4d --- /dev/null +++ b/phpBB/language/en/email/short/post_in_queue.txt @@ -0,0 +1,17 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because the post "{POST_SUBJECT}" at "{SITENAME}" needs approval. + +If you want to view the post, click the following link: +{U_VIEW_POST} + +If you want to view the topic, click the following link: +{U_TOPIC} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/short/privmsg_notify.txt b/phpBB/language/en/email/short/privmsg_notify.txt new file mode 100644 index 0000000000..d3a86cc73c --- /dev/null +++ b/phpBB/language/en/email/short/privmsg_notify.txt @@ -0,0 +1,15 @@ +Subject: New private message has arrived + +Hello {USERNAME}, + +You have received a new private message from "{AUTHOR_NAME}" to your account on "{SITENAME}" with the following subject: + +{SUBJECT} + +You can view your new message by clicking on the following link: + +{U_VIEW_MESSAGE} + +You have requested that you be notified on this event, remember that you can always choose not to be notified of new messages by changing the appropriate setting in your profile. + +{EMAIL_SIG}
\ No newline at end of file diff --git a/phpBB/language/en/email/short/quote.txt b/phpBB/language/en/email/short/quote.txt new file mode 100644 index 0000000000..2b9525801f --- /dev/null +++ b/phpBB/language/en/email/short/quote.txt @@ -0,0 +1,20 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because "{AUTHOR_NAME}" quoted you in the topic "{TOPIC_TITLE}" at "{SITENAME}". You can use the following link to view the reply made. + +If you want to view the quoted post, click the following link: +{U_VIEW_POST} + +If you want to view the topic, click the following link: +{U_TOPIC} + +If you want to view the forum, click the following link: +{U_FORUM} + +If you no longer wish to receive updates about replies quoting you, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/short/report_pm.txt b/phpBB/language/en/email/short/report_pm.txt new file mode 100644 index 0000000000..66ae82d074 --- /dev/null +++ b/phpBB/language/en/email/short/report_pm.txt @@ -0,0 +1,14 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because a Private Message titled "{SUBJECT}" by "{AUTHOR_NAME}" at "{SITENAME}" was reported. + +If you want to view the report, click the following link: +{U_VIEW_REPORT} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/short/report_post.txt b/phpBB/language/en/email/short/report_post.txt new file mode 100644 index 0000000000..46983be1ed --- /dev/null +++ b/phpBB/language/en/email/short/report_post.txt @@ -0,0 +1,17 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because the post "{POST_SUBJECT}" at "{SITENAME}" was reported. + +If you want to view the report, click the following link: +{U_VIEW_REPORT} + +If you want to view the post, click the following link: +{U_VIEW_POST} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/short/topic_approved.txt b/phpBB/language/en/email/short/topic_approved.txt new file mode 100644 index 0000000000..ffda378d30 --- /dev/null +++ b/phpBB/language/en/email/short/topic_approved.txt @@ -0,0 +1,11 @@ +Subject: Topic approved - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because your topic "{TOPIC_TITLE}" at "{SITENAME}" was approved by a moderator or administrator. + +If you want to view the topic, click the following link: +{U_VIEW_TOPIC} + + +{EMAIL_SIG}
\ No newline at end of file diff --git a/phpBB/language/en/email/short/topic_disapproved.txt b/phpBB/language/en/email/short/topic_disapproved.txt new file mode 100644 index 0000000000..49ef58bf39 --- /dev/null +++ b/phpBB/language/en/email/short/topic_disapproved.txt @@ -0,0 +1,12 @@ +Subject: Topic disapproved - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because your topic "{TOPIC_TITLE}" at "{SITENAME}" was disapproved by a moderator or administrator. + +The following reason was given for the disapproval: + +{REASON} + + +{EMAIL_SIG}
\ No newline at end of file diff --git a/phpBB/language/en/email/short/topic_in_queue.txt b/phpBB/language/en/email/short/topic_in_queue.txt new file mode 100644 index 0000000000..ae8f9e2484 --- /dev/null +++ b/phpBB/language/en/email/short/topic_in_queue.txt @@ -0,0 +1,17 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because the topic "{TOPIC_TITLE}" at "{SITENAME}" needs approval. + +If you want to view the topic, click the following link: +{U_VIEW_TOPIC} + +If you want to view the forum, click the following link: +{U_FORUM} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/short/topic_notify.txt b/phpBB/language/en/email/short/topic_notify.txt new file mode 100644 index 0000000000..fa2481dd9a --- /dev/null +++ b/phpBB/language/en/email/short/topic_notify.txt @@ -0,0 +1,20 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because you are watching the topic "{TOPIC_TITLE}" at "{SITENAME}". This topic has received a reply<!-- IF AUTHOR_NAME --> by {AUTHOR_NAME}<!-- ENDIF --> since your last visit. You can use the following link to view the replies made, no more notifications will be sent until you visit the topic. + +If you want to view the newest post made since your last visit, click the following link: +{U_NEWEST_POST} + +If you want to view the topic, click the following link: +{U_TOPIC} + +If you want to view the forum, click the following link: +{U_FORUM} + +If you no longer wish to watch this topic you can either click the "Unsubscribe topic" link found at the bottom of the topic above, or by clicking the following link: + +{U_STOP_WATCHING_TOPIC} + +{EMAIL_SIG}
\ No newline at end of file diff --git a/phpBB/language/en/email/topic_in_queue.txt b/phpBB/language/en/email/topic_in_queue.txt new file mode 100644 index 0000000000..ae8f9e2484 --- /dev/null +++ b/phpBB/language/en/email/topic_in_queue.txt @@ -0,0 +1,17 @@ +Subject: Topic reply notification - "{TOPIC_TITLE}" + +Hello {USERNAME}, + +You are receiving this notification because the topic "{TOPIC_TITLE}" at "{SITENAME}" needs approval. + +If you want to view the topic, click the following link: +{U_VIEW_TOPIC} + +If you want to view the forum, click the following link: +{U_FORUM} + +If you no longer wish to receive updates about replies to bookmarks, please update your notification settings here: + +{U_NOTIFICATION_SETTINGS} + +{EMAIL_SIG} diff --git a/phpBB/language/en/email/topic_notify.txt b/phpBB/language/en/email/topic_notify.txt index fcfbcc2abd..fa2481dd9a 100644 --- a/phpBB/language/en/email/topic_notify.txt +++ b/phpBB/language/en/email/topic_notify.txt @@ -2,7 +2,7 @@ Subject: Topic reply notification - "{TOPIC_TITLE}" Hello {USERNAME}, -You are receiving this notification because you are watching the topic, "{TOPIC_TITLE}" at "{SITENAME}". This topic has received a reply<!-- IF AUTHOR_NAME --> by {AUTHOR_NAME}<!-- ENDIF --> since your last visit. You can use the following link to view the replies made, no more notifications will be sent until you visit the topic. +You are receiving this notification because you are watching the topic "{TOPIC_TITLE}" at "{SITENAME}". This topic has received a reply<!-- IF AUTHOR_NAME --> by {AUTHOR_NAME}<!-- ENDIF --> since your last visit. You can use the following link to view the replies made, no more notifications will be sent until you visit the topic. If you want to view the newest post made since your last visit, click the following link: {U_NEWEST_POST} diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 705b07b170..7c3960204a 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -288,6 +288,25 @@ $lang = array_merge($lang, array( 'NEW_PASSWORD' => 'New password', 'NEW_PASSWORD_CONFIRM_EMPTY' => 'You did not enter a confirm password.', 'NEW_PASSWORD_ERROR' => 'The passwords you entered do not match.', + + 'NOTIFICATIONS_MARK_ALL_READ' => 'Mark all notifications read', + 'NOTIFICATIONS_MARK_ALL_READ_CONFIRM' => 'Are you sure you want to mark all notifications read?', + 'NOTIFICATIONS_MARK_ALL_READ_SUCCESS' => 'All notifications have been marked read successfully.', + 'NOTIFICATION_GROUP_MISCELLANEOUS' => 'Miscellaneous Notifications', + 'NOTIFICATION_GROUP_MODERATION' => 'Moderation Notifications', + 'NOTIFICATION_GROUP_POSTING' => 'Posting Notifications', + 'NOTIFICATION_METHOD_EMAIL' => 'Email', + 'NOTIFICATION_METHOD_JABBER' => 'Jabber', + 'NOTIFICATION_TYPE' => 'Notification type', + 'NOTIFICATION_TYPE_BOOKMARK' => 'Someone replies to a topic you have bookmarked', + 'NOTIFICATION_TYPE_IN_MODERATION_QUEUE' => 'A post or topic needs approval', + 'NOTIFICATION_TYPE_MODERATION_QUEUE' => 'Your topics/posts are approved or disapproved by a moderator', + 'NOTIFICATION_TYPE_PM' => 'Someone sends you a private message', + 'NOTIFICATION_TYPE_POST' => 'Someone replies to a topic you are subscribed to', + 'NOTIFICATION_TYPE_QUOTE' => 'Someone quotes you in a post', + 'NOTIFICATION_TYPE_REPORT' => 'Someone reports a post', + 'NOTIFICATION_TYPE_TOPIC' => 'Someone creates a topic in a forum you are subscribed to', + 'NOTIFY_METHOD' => 'Notification method', 'NOTIFY_METHOD_BOTH' => 'Both', 'NOTIFY_METHOD_EMAIL' => 'Email only', @@ -457,6 +476,11 @@ $lang = array_merge($lang, array( 'UCP_MSNM' => 'Windows Live Messenger', 'UCP_NO_ATTACHMENTS' => 'You have posted no files.', + 'UCP_NOTIFICATION_LIST' => 'Manage notifications', + 'UCP_NOTIFICATION_LIST_EXPLAIN' => 'Here you may view all past notifications.', + 'UCP_NOTIFICATION_OPTIONS' => 'Edit notification options', + 'UCP_NOTIFICATION_OPTIONS_EXPLAIN' => 'Here you can set your preferred notification methods for the board.', + 'UCP_PREFS' => 'Board preferences', 'UCP_PREFS_PERSONAL' => 'Edit global settings', 'UCP_PREFS_POST' => 'Edit posting defaults', diff --git a/phpBB/report.php b/phpBB/report.php index d792b8df6a..07cec7afbc 100644 --- a/phpBB/report.php +++ b/phpBB/report.php @@ -190,6 +190,10 @@ if ($submit && $reason_id) $lang_return = $user->lang['RETURN_TOPIC']; $lang_success = $user->lang['POST_REPORTED_SUCCESS']; + + $phpbb_notifications->add_notifications('report_post', array_merge($report_data, $row, $forum_data, array( + 'report_text' => $report_text, + ))); } else { @@ -216,6 +220,12 @@ if ($submit && $reason_id) $lang_return = $user->lang['RETURN_PM']; $lang_success = $user->lang['PM_REPORTED_SUCCESS']; + + $phpbb_notifications->add_notifications('report_pm', array_merge($report_data, $row, array( + 'report_text' => $report_text, + 'from_user_id' => $report_data['author_id'], + 'report_id' => $report_id, + ))); } meta_refresh(3, $redirect_url); diff --git a/phpBB/styles/prosilver/template/ajax.js b/phpBB/styles/prosilver/template/ajax.js index fa31d3268f..f0a9cd84e3 100644 --- a/phpBB/styles/prosilver/template/ajax.js +++ b/phpBB/styles/prosilver/template/ajax.js @@ -76,7 +76,18 @@ $('#qr_full_editor').click(function() { }); }); +// Toggle notification list +$('#notification_list_button').click(function(e) { + $('#notification_list').toggle(); + e.preventDefault(); +}); +$('#phpbb').click(function(e) { + var target = e.target; + if (!$(target).is('#notification_list') && !$(target).is('#notification_list_button') && !$(target).parents().is('#notification_list')) { + $('#notification_list').hide(); + } +}); /** * 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 3e00827235..9c2c1fc6a6 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -5,7 +5,7 @@ <meta name="keywords" content="" /> <meta name="description" content="" /> {META} -<title><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --></title> +<title><!-- IF UNREAD_NOTIFICATIONS_COUNT -->({UNREAD_NOTIFICATIONS_COUNT}) <!-- ENDIF --><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --></title> <!-- IF S_ENABLE_FEEDS --> <!-- IF S_ENABLE_FEEDS_OVERALL --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {SITENAME}" href="{U_FEED}" /><!-- ENDIF --> @@ -131,9 +131,46 @@ <!-- IF not S_IS_BOT and S_USER_LOGGED_IN --> <ul class="linklist leftside"> + <!-- IF S_NOTIFICATIONS_DISPLAY --> + <li> + [ <a href="#" id="notification_list_button" title="{NOTIFICATIONS_COUNT}">{NOTIFICATIONS_COUNT}</a> ] • + <div id="notification_list" class="notification_list"> + <div class="header"> + {L_NOTIFICATIONS} + </div> + + <ul> + <!-- IF not .notifications --> + <li> + {L_NO_NOTIFICATIONS} + </li> + <!-- ENDIF --> + <!-- BEGIN notifications --> + <li class="<!-- IF notifications.UNREAD --> bg2<!-- ENDIF -->"> + <!-- IF notifications.URL --><a href="<!-- IF notifications.UNREAD -->{notifications.U_MARK_READ}<!-- ELSE -->{notifications.URL}<!-- ENDIF -->"><!-- ENDIF --> + {notifications.AVATAR} + <div> + <p>{notifications.FORMATTED_TITLE}</p> + <p>{notifications.TIME}</p> + + <!-- IF not notifications.URL and notifications.U_MARK_READ --> + <p><a href="{notifications.U_MARK_READ}">{L_MARK_READ}</a></p> + <!-- ENDIF --> + </div> + <!-- IF notifications.URL --></a><!-- ENDIF --> + </li> + <!-- END notifications --> + </ul> + + <div class="footer"> + <a href="{U_VIEW_ALL_NOTIFICATIONS}"><span>{L_SEE_ALL}</span></a> + </div> + </div> + </li> + <!-- ENDIF --> <li class="icon-ucp"> <a href="{U_PROFILE}" title="{L_PROFILE}" accesskey="e">{L_PROFILE}</a> - <!-- IF S_DISPLAY_PM --> (<a href="{U_PRIVATEMSGS}">{PRIVATE_MESSAGE_INFO}<!-- IF PRIVATE_MESSAGE_INFO_UNREAD -->, {PRIVATE_MESSAGE_INFO_UNREAD}<!-- ENDIF --></a>)<!-- ENDIF --> + <!-- IF not S_NOTIFICATIONS_DISPLAY and S_DISPLAY_PM --> (<a href="{U_PRIVATEMSGS}">{PRIVATE_MESSAGE_INFO}<!-- IF PRIVATE_MESSAGE_INFO_UNREAD -->, {PRIVATE_MESSAGE_INFO_UNREAD}<!-- ENDIF --></a>)<!-- ENDIF --> <!-- IF S_DISPLAY_SEARCH --> • <a href="{U_SEARCH_SELF}">{L_SEARCH_SELF}</a> <!-- ENDIF --> diff --git a/phpBB/styles/prosilver/template/ucp_notifications.html b/phpBB/styles/prosilver/template/ucp_notifications.html new file mode 100644 index 0000000000..85edf4629b --- /dev/null +++ b/phpBB/styles/prosilver/template/ucp_notifications.html @@ -0,0 +1,131 @@ +<!-- INCLUDE ucp_header.html --> + +<form id="ucp" method="post" action="{S_UCP_ACTION}"{S_FORM_ENCTYPE}> + +<h2>{TITLE}</h2> +<div class="panel"> + <div class="inner"> + + <p>{TITLE_EXPLAIN}</p> + + <!-- IF MODE == 'notification_options' --> + <ul class="topiclist"> + <li class="header"> + <dl> + <dt>{L_NOTIFICATION_TYPE}</dt> + <!-- BEGIN notification_methods --> + <dd class="mark">{notification_methods.NAME}</dd> + <!-- END notification_methods --> + <dd class="mark">{L_NOTIFICATIONS}</dd> + </dl> + </li> + </ul> + <ul class="topiclist cplist"> + + <!-- BEGIN notification_types --> + <!-- IF notification_types.GROUP_NAME --> + <li class="row bg3"> + <dl> + <dt> + {notification_types.GROUP_NAME} + </dt> + </dl> + </li> + <!-- ELSE --> + <li class="row<!-- IF notification_types.S_ROW_COUNT is odd --> bg1<!-- ELSE --> bg2<!-- ENDIF -->"> + <dl> + <dt> + {notification_types.NAME} + <!-- IF notification_types.EXPLAIN --><br /> {notification_types.EXPLAIN}<!-- ENDIF --> + </dt> + <!-- BEGIN notification_methods --> + <dd class="mark"><input type="checkbox" name="{notification_types.TYPE}_{notification_methods.METHOD}"<!-- IF notification_methods.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /> <dfn>{notification_methods.NAME}</dfn></dd> + <!-- END notification_methods --> + <dd class="mark"><input type="checkbox" name="{notification_types.TYPE}_notification"<!-- IF notification_types.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /> <dfn>{notification_methods.NAME}</dfn></dd> + </dl> + </li> + <!-- ENDIF --> + <!-- END notification_types --> + </ul> + <!-- ELSE --> + <!-- IF .pagination or TOTAL_COUNT --> + <div class="topic-actions"> + <div class="pagination"> + <!-- IF U_MARK_ALL --><a href="{U_MARK_ALL}">{L_NOTIFICATIONS_MARK_ALL_READ}</a> • <!-- ENDIF --> + <!-- IF TOTAL_COUNT -->{TOTAL_COUNT} • <!-- ENDIF --> + <!-- IF .pagination --> + <!-- INCLUDE pagination.html --> + <!-- ELSE --> + {PAGE_NUMBER} + <!-- ENDIF --> + </div> + </div> + <!-- ENDIF --> + + <div class="notification_list"> + <ul class="topiclist"> + <li class="header"> + <dl> + <dt>{L_NOTIFICATIONS}</dt> + <dd class="mark">{L_MARK_READ}</dd> + </dl> + </li> + <!-- IF not .notifications --> + <li> + <dl> + <dt>{L_NO_NOTIFICATIONS}</dt> + </dl> + </li> + <!-- ENDIF --> + <!-- BEGIN notification_list --> + <li class="row<!-- IF notification_list.UNREAD --> bg3<!-- ELSE --><!-- IF notification_list.S_ROW_COUNT is odd --> bg1<!-- ELSE --> bg2<!-- ENDIF --><!-- ENDIF -->"> + <dl> + <dt> + <!-- IF notification_list.URL --><a href="<!-- IF notification_list.UNREAD -->{notification_list.U_MARK_READ}<!-- ELSE -->{notification_list.URL}<!-- ENDIF -->"><!-- ENDIF --> + {notification_list.AVATAR} + <div> + <p>{notification_list.FORMATTED_TITLE}</p> + <p>{notification_list.TIME}</p> + + <!-- IF not notification_list.URL and notification_list.U_MARK_READ --> + <p><a href="{notification_list.U_MARK_READ}">{L_MARK_READ}</a></p> + <!-- ENDIF --> + </div> + <!-- IF notification_list.URL --></a><!-- ENDIF --> + </dt> + + <dd class="mark"> <!-- IF notification_list.UNREAD --><input type="checkbox" name="mark[]" value="{notification_list.NOTIFICATION_ID}" /> <dfn>{L_MARK_READ}</dfn><!-- ENDIF --> </dd> + </dl> + </li> + <!-- END notification_list --> + </ul> + </div> + + <!-- IF .pagination or TOTAL_COUNT --> + <div class="topic-actions"> + <div class="pagination"> + <!-- IF TOTAL_COUNT -->{TOTAL_COUNT} • <!-- ENDIF --> + <!-- IF .pagination --> + <!-- INCLUDE pagination.html --> + <!-- ELSE --> + {PAGE_NUMBER} + <!-- ENDIF --> + </div> + </div> + <!-- ENDIF --> + + <!-- ENDIF --> + </div> +</div> + + +<fieldset class="submit-buttons"> + <input type="hidden" name="form_time" value="{FORM_TIME}" /> + {S_HIDDEN_FIELDS}<input type="reset" value="{L_RESET}" name="reset" class="button2" /> + <input type="submit" name="submit" value="{L_SUBMIT}" class="button1" /> + {S_FORM_TOKEN} +</fieldset> + +</form> + +<!-- INCLUDE ucp_footer.html --> diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 4382e891fd..d99355507b 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -50,20 +50,6 @@ </dl> <!-- ENDIF --> <dl> - <dt><label for="notifypm1">{L_NOTIFY_ON_PM}{L_COLON}</label></dt> - <dd> - <label for="notifypm1"><input type="radio" name="notifypm" id="notifypm1" value="1"<!-- IF S_NOTIFY_PM --> checked="checked"<!-- ENDIF --> /> {L_YES}</label> - <label for="notifypm0"><input type="radio" name="notifypm" id="notifypm0" value="0"<!-- IF not S_NOTIFY_PM --> checked="checked"<!-- ENDIF --> /> {L_NO}</label> - </dd> - </dl> - <dl> - <dt><label for="popuppm0">{L_POPUP_ON_PM}{L_COLON}</label></dt> - <dd> - <label for="popuppm1"><input type="radio" name="popuppm" id="popuppm1" value="1"<!-- IF S_POPUP_PM --> checked="checked"<!-- ENDIF --> /> {L_YES}</label> - <label for="popuppm0"><input type="radio" name="popuppm" id="popuppm0" value="0"<!-- IF not S_POPUP_PM --> checked="checked"<!-- ENDIF --> /> {L_NO}</label> - </dd> - </dl> - <dl> <dt><label for="lang">{L_BOARD_LANGUAGE}{L_COLON}</label></dt> <dd><select name="lang" id="lang">{S_LANG_OPTIONS}</select></dd> </dl> diff --git a/phpBB/styles/prosilver/theme/colours.css b/phpBB/styles/prosilver/theme/colours.css index a5a18dc6a1..0043e7f5bc 100644 --- a/phpBB/styles/prosilver/theme/colours.css +++ b/phpBB/styles/prosilver/theme/colours.css @@ -1,4 +1,4 @@ -/* +/* -------------------------------------------------------------- Colours and backgrounds for common.css -------------------------------------------------------------- */ @@ -65,7 +65,7 @@ hr { .panel { background-color: #ECF1F3; - color: #28313F; + color: #28313F; } .post:target .content { @@ -219,7 +219,7 @@ p.rules { background-image: none; } -/* +/* -------------------------------------------------------------- Colours and backgrounds for links.css -------------------------------------------------------------- */ @@ -312,7 +312,7 @@ a.topictitle:active { color: #105289; } -/* Profile searchresults */ +/* Profile searchresults */ .search .postprofile a { color: #105289; } @@ -349,7 +349,7 @@ a.arrow-right:hover { } -/* +/* -------------------------------------------------------------- Colours and backgrounds for content.css -------------------------------------------------------------- */ @@ -644,7 +644,7 @@ fieldset.polls dd div { background-image: url("./en/icon_user_online.gif"); } -/* +/* -------------------------------------------------------------- Colours and backgrounds for buttons.css -------------------------------------------------------------- */ @@ -752,7 +752,7 @@ a.sendemail { .pm_read { background-image: url("./images/topic_read.gif"); } .pm_unread { background-image: url("./images/topic_unread.gif"); } -/* +/* -------------------------------------------------------------- Colours and backgrounds for cp.css -------------------------------------------------------------- */ @@ -921,7 +921,7 @@ dl.mini dt { background-color: #EEE; } -/* +/* -------------------------------------------------------------- Colours and backgrounds for forms.css -------------------------------------------------------------- */ @@ -976,7 +976,7 @@ fieldset.quick-login input.inputbox { /* Input field styles ---------------------------------------- */ .inputbox { - background-color: #FFFFFF; + background-color: #FFFFFF; border-color: #B4BAC0; color: #333333; } @@ -1044,3 +1044,16 @@ input.disabled { background-color: #000000; } +#notification_list { + background-color: #FFFFFF; + border-color: #00608F; +} + +#notification_list ul li:hover { + background-color: #CFE1F6; + color: #000000; +} + +#notification_list > .header, .notification_list > .footer { + border-color: #00608F; +} diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index 50b22f44df..570f709ddd 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -9,8 +9,8 @@ b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, -article, aside, canvas, details, embed, -figure, figcaption, footer, header, hgroup, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video { margin: 0; @@ -21,7 +21,7 @@ time, mark, audio, video { vertical-align: baseline; } /* HTML5 display-role reset for older browsers */ -article, aside, details, figcaption, figure, +article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; } @@ -164,7 +164,7 @@ ul ul, ol ul { ol ol ul, ol ul ul, ul ol ul, ul ul ul { list-style-type: square; -} +} /* Main blocks @@ -672,3 +672,75 @@ p.rules a { .smilies { vertical-align: text-bottom; } + +#notification_list { + display: none; + position: absolute; + width: 330px; + z-index: 1; + border: 1px solid; + border-radius: 4px; + box-shadow: 4px 4px 5px; +} + +#notification_list ul { + max-height: 350px; + overflow-y: auto; + overflow-x: hidden; +} + +#notification_list ul li { + width: ; + padding: 10px; + margin: 0; + float: left; + border-bottom: 1px solid; + list-style-type: none; + font-size: 0.95em; + clear: both; +} + +#notification_list ul li { + width: 310px; +} + +#notification_list ul li:last-child { + border-bottom: 0px; +} + +#notification_list > .header { + padding: 0 5px; + font-weight: bold; + border-bottom: 1px solid; +} + +#notification_list > .footer { + text-align: center; + font-size: 1.2em; + border-top: 1px solid; +} + +#notification_list ul li a, .notification_list dt > a, #notification_list > .footer > a { + display: block; +} + +.notification_list ul li img { + float: left; + max-width: 50px; + max-height: 50px; + margin-right: 5px; +} + +#notification_list ul li div { + width: 240px; + float: left; +} + +.notification_list ul li p { + margin: 0; + word-wrap: break-word; +} + +.notification_list ul.topiclist dt { + width: 88%; +} diff --git a/phpBB/styles/subsilver2/template/common.js b/phpBB/styles/subsilver2/template/common.js new file mode 100644 index 0000000000..c9e6221e2e --- /dev/null +++ b/phpBB/styles/subsilver2/template/common.js @@ -0,0 +1,18 @@ +(function($) { // Avoid conflicts with other libraries + +"use strict"; + +// Toggle notification list +$('#notification_list_button').click(function(e) { + $('#notification_list').toggle(); + e.preventDefault(); +}); +$(document).click(function(e) { + var target = e.target; + + if (!$(target).is('#notification_list') && !$(target).is('#notification_list_button') && !$(target).parents().is('#notification_list')) { + $('#notification_list').hide(); + } +}); + +})(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/subsilver2/template/overall_footer.html b/phpBB/styles/subsilver2/template/overall_footer.html index 24c6f8105c..8cc5591478 100644 --- a/phpBB/styles/subsilver2/template/overall_footer.html +++ b/phpBB/styles/subsilver2/template/overall_footer.html @@ -10,6 +10,7 @@ <script type="text/javascript" src="{T_JQUERY_LINK}"></script> <!-- IF S_JQUERY_FALLBACK --><script type="text/javascript">window.jQuery || document.write(unescape('%3Cscript src="{T_ASSETS_PATH}/javascript/jquery.js?assets_version={T_ASSETS_VERSION}" type="text/javascript"%3E%3C/script%3E'));</script><!-- ENDIF --> +<!-- INCLUDEJS template/common.js --> {SCRIPTS} </body> diff --git a/phpBB/styles/subsilver2/template/overall_header.html b/phpBB/styles/subsilver2/template/overall_header.html index 4ed69c56aa..e516a78e45 100644 --- a/phpBB/styles/subsilver2/template/overall_header.html +++ b/phpBB/styles/subsilver2/template/overall_header.html @@ -5,7 +5,7 @@ <meta name="keywords" content="" /> <meta name="description" content="" /> {META} -<title><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --></title> +<title><!-- IF UNREAD_NOTIFICATIONS_COUNT -->({UNREAD_NOTIFICATIONS_COUNT}) <!-- ENDIF --><!-- IF not S_VIEWTOPIC and not S_VIEWFORUM -->{SITENAME} - <!-- ENDIF --><!-- IF S_IN_MCP -->{L_MCP} - <!-- ELSEIF S_IN_UCP -->{L_UCP} - <!-- ENDIF -->{PAGE_TITLE}<!-- IF S_VIEWTOPIC or S_VIEWFORUM --> - {SITENAME}<!-- ENDIF --></title> <!-- IF S_ENABLE_FEEDS --> <!-- IF S_ENABLE_FEEDS_OVERALL --><link rel="alternate" type="application/atom+xml" title="{L_FEED} - {SITENAME}" href="{U_FEED}" /><!-- ENDIF --> @@ -149,12 +149,51 @@ function marklist(id, name, state) <table width="100%" cellspacing="0"> <tr> <td class="genmed"> + <!-- IF S_NOTIFICATIONS_DISPLAY --> + [ <a href="#" id="notification_list_button" title="{NOTIFICATIONS_COUNT}">{NOTIFICATIONS_COUNT}</a> ] • + <div id="notification_list" class="notification_list"> + <div class="row1 header"> + {L_NOTIFICATIONS} + </div> + + <div class="notification_scroll"> + <table class="tablebg" width="310px" cellspacing="1"> + <!-- BEGIN notifications --> + <tr class="row<!-- IF notifications.UNREAD -->2<!-- ELSE -->1<!-- ENDIF -->"> + <!-- IF notifications.AVATAR --> + <td width="50px"> + {notifications.AVATAR} + </td> + <td valign="top"> + <!-- ELSE --> + <td colspan="2" valign="top"> + <!-- ENDIF --> + <div class="notification_title"> + <!-- IF notifications.URL --><a href="<!-- IF notifications.UNREAD -->{notifications.U_MARK_READ}<!-- ELSE -->{notifications.URL}<!-- ENDIF -->"><!-- ENDIF --> + {notifications.FORMATTED_TITLE} + <!-- IF notifications.URL --></a><!-- ENDIF --> + <br />{notifications.TIME} + <!-- IF not notifications.URL and notifications.UNREAD --> + <br /><a href="{notifications.U_MARK_READ}">{L_MARK_READ}</a> + <!-- ENDIF --> + </div> + </td> + </tr> + <!-- END notifications --> + </table> + </div> + + <div class="row1 footer"> + <a href="{U_VIEW_ALL_NOTIFICATIONS}"><span>{L_SEE_ALL}</span></a> + </div> + </div> + <!-- ENDIF --> <!-- IF not S_IS_BOT --><a href="{U_LOGIN_LOGOUT}"><img src="{T_THEME_PATH}/images/icon_mini_login.gif" width="12" height="13" alt="*" /> {L_LOGIN_LOGOUT}</a> <!-- ENDIF --> <!-- IF U_RESTORE_PERMISSIONS --> <a href="{U_RESTORE_PERMISSIONS}"><img src="{T_THEME_PATH}/images/icon_mini_login.gif" width="12" height="13" alt="*" /> {L_RESTORE_PERMISSIONS}</a><!-- ENDIF --> <!-- IF S_BOARD_DISABLED and S_USER_LOGGED_IN --> <span style="color: red;">{L_BOARD_DISABLED}</span><!-- ENDIF --> <!-- IF not S_IS_BOT --> - <!-- IF S_USER_LOGGED_IN --> - <!-- IF S_DISPLAY_PM --> <a href="{U_PRIVATEMSGS}"><img src="{T_THEME_PATH}/images/icon_mini_message.gif" width="12" height="13" alt="*" /> {PRIVATE_MESSAGE_INFO}<!-- IF PRIVATE_MESSAGE_INFO_UNREAD -->, {PRIVATE_MESSAGE_INFO_UNREAD}<!-- ENDIF --></a><!-- ENDIF --> + <!-- IF S_USER_LOGGED_IN--> + <!-- IF not S_NOTIFICATIONS_DISPLAY and S_DISPLAY_PM --> <a href="{U_PRIVATEMSGS}"><img src="{T_THEME_PATH}/images/icon_mini_message.gif" width="12" height="13" alt="*" /> {PRIVATE_MESSAGE_INFO}<!-- IF PRIVATE_MESSAGE_INFO_UNREAD -->, {PRIVATE_MESSAGE_INFO_UNREAD}<!-- ENDIF --></a><!-- ENDIF --> <!-- ELSEIF S_REGISTER_ENABLED and not (S_SHOW_COPPA or S_REGISTRATION) --> <a href="{U_REGISTER}"><img src="{T_THEME_PATH}/images/icon_mini_register.gif" width="12" height="13" alt="*" /> {L_REGISTER}</a> <!-- ENDIF --> <!-- ENDIF --> diff --git a/phpBB/styles/subsilver2/template/ucp_notifications.html b/phpBB/styles/subsilver2/template/ucp_notifications.html new file mode 100644 index 0000000000..a2dc90c9f3 --- /dev/null +++ b/phpBB/styles/subsilver2/template/ucp_notifications.html @@ -0,0 +1,146 @@ +<!-- INCLUDE ucp_header.html --> + +<form id="ucp" method="post" action="{S_UCP_ACTION}"{S_FORM_ENCTYPE}> + +<table width="100%" cellspacing="1"> + <tr> + <th colspan="4">{TITLE}</th> + </tr> + <tr> + <td class="row1" colspan="4" align="center"><span class="genmed">{TITLE_EXPLAIN}</span></td> + </tr> + <!-- IF MODE == 'notification_options' --> + <tr> + <th>{L_NOTIFICATION_TYPE}</th> + <th width="10%">{L_NOTIFICATIONS}</th> + <!-- BEGIN notification_methods --> + <th width="10%">{notification_methods.NAME}</th> + <!-- END notification_methods --> + </tr> + + <!-- BEGIN notification_types --> + <!-- IF notification_types.GROUP_NAME --> + <tr> + <td class="row3" colspan="3">{notification_types.GROUP_NAME}</td> + </tr> + <!-- ELSE --> + <!-- IF notification_types.S_ROW_COUNT is even --><tr class="row1"><!-- ELSE --><tr class="row2"><!-- ENDIF --> + <td> + {notification_types.NAME} + <!-- IF notification_types.EXPLAIN --><br /> {notification_types.EXPLAIN}<!-- ENDIF --> + </td> + <td align="center"><input type="checkbox" name="{notification_types.TYPE}_notification"<!-- IF notification_types.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /></td> + <!-- BEGIN notification_methods --> + <td align="center"><input type="checkbox" name="{notification_types.TYPE}_{notification_methods.METHOD}"<!-- IF notification_methods.SUBSCRIBED --> checked="checked"<!-- ENDIF --> /></td> + <!-- END notification_methods --> + </tr> + <!-- ENDIF --> + <!-- END notification_types --> + <tr> + <td class="cat" colspan="3" align="center"> + <input type="hidden" name="form_time" value="{FORM_TIME}" /> + {S_HIDDEN_FIELDS} + <input class="btnmain" type="submit" name="submit" value="{L_SUBMIT}" /> + <input class="btnlite" type="reset" value="{L_RESET}" name="reset" /> + {S_FORM_TOKEN} + </td> + </tr> + <!-- ELSE --> + <tr> + <td> + <table class="tablebg" width="100%" cellspacing="1" cellpadding="0"> + <tr> + <td class="row1"> + <table border="0" cellspacing="0" cellpadding="0" width="100%"> + <tr> + <td align="{S_CONTENT_FLOW_BEGIN}"> + <!-- IF TOTAL_COUNT --> + <table width="100%" cellspacing="1"> + <tr> + <td class="nav" valign="middle" nowrap="nowrap"> {PAGE_NUMBER}</td> + <td class="gensmall" nowrap="nowrap" width="100%"> [ <b>{TOTAL_COUNT}</b> ] </td> + </tr> + </table> + <!-- ENDIF --> + </td> + <td align="{S_CONTENT_FLOW_END}"><!-- INCLUDE pagination.html --></td> + </tr> + </table> + </td> + </tr> + </table> + + <div style="padding: 2px;"></div> + + <div class="notification_list"> + <table class="tablebg" width="100%" cellspacing="1"> + <tr> + <td class="cat" colspan="3"> + <table width="100%" cellspacing="0"> + <tr class="nav"> + <td align="{S_CONTENT_FLOW_END}" valign="middle"><!-- IF U_MARK_ALL --><a href="{U_MARK_ALL}">{L_NOTIFICATIONS_MARK_ALL_READ}</a><!-- ENDIF --></td> + </tr> + </table> + </td> + </tr> + <tr> + <th colspan="2">{L_NOTIFICATIONS}</th> + <th width="15%">{L_MARK_READ}</th> + </tr> + <!-- BEGIN notification_list --> + <tr class="row<!-- IF notification_list.UNREAD -->3<!-- ELSEIF notification_list.S_ROW_COUNT is even -->1<!-- ELSE -->2<!-- ENDIF -->"> + <!-- IF notification_list.AVATAR --> + <td width="50px"> + {notification_list.AVATAR} + </td> + <td valign="top"> + <!-- ELSE --> + <td colspan="2" valign="top" height="50px"> + <!-- ENDIF --> + <!-- IF notification_list.URL --><a href="<!-- IF notification_list.UNREAD -->{notification_list.U_MARK_READ}<!-- ELSE -->{notification_list.URL}<!-- ENDIF -->"><!-- ENDIF --> + {notification_list.FORMATTED_TITLE} + <!-- IF notification_list.URL --></a><!-- ENDIF --><br /> + {notification_list.TIME} + </td> + <td align="center"> + <!-- IF notification_list.UNREAD --><input type="checkbox" name="mark[]" value="{notification_list.NOTIFICATION_ID}" /><!-- ENDIF --> + </td> + </tr> + <!-- END notification_list --> + <tr> + <td class="cat" colspan="3" align="center"> + <input type="hidden" name="form_time" value="{FORM_TIME}" /> + {S_HIDDEN_FIELDS} + <input class="btnmain" type="submit" name="submit" value="{L_SUBMIT}" /> + <input class="btnlite" type="reset" value="{L_RESET}" name="reset" /> + {S_FORM_TOKEN} + </td> + </tr> + </table> + </div> + + <div style="padding: 2px;"></div> + + <!-- IF .pagination --> + <table class="tablebg" width="100%" cellspacing="1" cellpadding="0"> + <tr> + <td class="row1"> + <table border="0" cellspacing="0" cellpadding="0" width="100%"> + <tr> + <td align="{S_CONTENT_FLOW_BEGIN}"> + <!-- INCLUDE pagination.html --> + </td> + </tr> + </table> + </td> + </tr> + </table> + <!-- ENDIF --> + </td> + </tr> + <!-- ENDIF --> +</table> + +</form> + +<!-- INCLUDE ucp_footer.html --> diff --git a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html index 5a169763fb..0118e67709 100644 --- a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html +++ b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html @@ -53,14 +53,6 @@ <td class="row2"><input type="radio" class="radio" name="notifymethod" value="0"<!-- IF S_NOTIFY_EMAIL --> checked="checked"<!-- ENDIF --> /><span class="genmed">{L_NOTIFY_METHOD_EMAIL}</span> <input type="radio" class="radio" name="notifymethod" value="1"<!-- IF S_NOTIFY_IM --> checked="checked"<!-- ENDIF --> /><span class="genmed">{L_NOTIFY_METHOD_IM}</span> <input type="radio" class="radio" name="notifymethod" value="2"<!-- IF S_NOTIFY_BOTH --> checked="checked"<!-- ENDIF --> /><span class="genmed">{L_NOTIFY_METHOD_BOTH}</span></td> </tr> <!-- ENDIF --> -<tr> - <td class="row1" width="50%"><b class="genmed">{L_NOTIFY_ON_PM}{L_COLON}</b></td> - <td class="row2"><input type="radio" class="radio" name="notifypm" value="1"<!-- IF S_NOTIFY_PM --> checked="checked"<!-- ENDIF --> /><span class="genmed">{L_YES}</span> <input type="radio" class="radio" name="notifypm" value="0"<!-- IF not S_NOTIFY_PM --> checked="checked"<!-- ENDIF --> /><span class="genmed">{L_NO}</span></td> -</tr> -<tr> - <td class="row1" width="50%"><b class="genmed">{L_POPUP_ON_PM}{L_COLON}</b></td> - <td class="row2"><input type="radio" class="radio" name="popuppm" value="1"<!-- IF S_POPUP_PM --> checked="checked"<!-- ENDIF --> /><span class="genmed">{L_YES}</span> <input type="radio" class="radio" name="popuppm" value="0"<!-- IF not S_POPUP_PM --> checked="checked"<!-- ENDIF --> /><span class="genmed">{L_NO}</span></td> -</tr> <tr> <td class="row1" width="50%"><b class="genmed">{L_BOARD_LANGUAGE}{L_COLON}</b></td> <td class="row2"><select name="lang">{S_LANG_OPTIONS}</select></td> diff --git a/phpBB/styles/subsilver2/theme/stylesheet.css b/phpBB/styles/subsilver2/theme/stylesheet.css index 977e5c20c6..c411edd367 100644 --- a/phpBB/styles/subsilver2/theme/stylesheet.css +++ b/phpBB/styles/subsilver2/theme/stylesheet.css @@ -181,7 +181,7 @@ p.datetime { p.searchbar { padding: 2px 0; white-space: nowrap; -} +} p.searchbarreg { margin: 0; @@ -464,7 +464,7 @@ textarea { background-color: #FAFAFA; color: #333333; font-family: "Lucida Grande", Verdana, Helvetica, Arial, sans-serif; - font-size: 1.3em; + font-size: 1.3em; line-height: 1.4em; font-weight: normal; border: 1px solid #A9B8C2; @@ -1141,3 +1141,45 @@ a.imageset { padding-right: 18px; padding-left: 0; } + +#notification_list { + display: none; + position: absolute; + width: 310px; + z-index: 1; +} + +#notification_list .notification_scroll { + max-height: 350px; + overflow-y: auto; + overflow-x: hidden; +} + +#notification_list .notification_title { + width: 240px; +} + +#notification_list .header { + width: 298px; + padding: 5px; + font-weight: bold; + border: 1px solid #A9B8C2; + border-bottom: 0; +} + +#notification_list .footer { + width: 300px; + text-align: center; + font-size: 1.2em; + border: 1px solid #A9B8C2; + border-top: 0; +} + +.notification_list img { + max-width: 50px; + max-height: 50px; +} + +#notification_list .footer > a { + display: block; +} diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php index 8a81dd72d1..734d3e1741 100644 --- a/tests/mock/container_builder.php +++ b/tests/mock/container_builder.php @@ -11,6 +11,9 @@ use Symfony\Component\DependencyInjection\ScopeInterface; class phpbb_mock_container_builder implements ContainerInterface { + protected $services = array(); + protected $parameters = array(); + /** * Sets a service. * @@ -22,6 +25,7 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function set($id, $service, $scope = self::SCOPE_CONTAINER) { + $this->services[$id] = $service; } /** @@ -42,6 +46,12 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) { + if ($this->has($id)) + { + return $this->services[$id]; + } + + throw new Exception('Could not find service: ' . $id); } /** @@ -55,6 +65,7 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function has($id) { + return isset($this->services[$id]); } /** @@ -70,6 +81,12 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function getParameter($name) { + if ($this->hasParameter($name)) + { + return $this->parameters[$name]; + } + + throw new Exception('Could not find parameter: ' . $name); } /** @@ -83,6 +100,7 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function hasParameter($name) { + return isset($this->parameters[$name]); } /** @@ -95,6 +113,7 @@ class phpbb_mock_container_builder implements ContainerInterface */ public function setParameter($name, $value) { + $this->parameters[$name] = $value; } /** diff --git a/tests/mock/notification_manager.php b/tests/mock/notification_manager.php new file mode 100644 index 0000000000..47fe30730f --- /dev/null +++ b/tests/mock/notification_manager.php @@ -0,0 +1,94 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Notifications service class +* @package notifications +*/ +class phpbb_mock_notification_manager +{ + public function load_notifications() + { + return array( + 'notifications' => array(), + 'unread_count' => 0, + ); + } + + public function mark_notifications_read() + { + } + + public function mark_notifications_read_by_parent() + { + } + + public function mark_notifications_read_by_id() + { + } + + + public function add_notifications() + { + return array(); + } + + public function add_notifications_for_users() + { + } + + public function update_notifications() + { + } + + public function delete_notifications() + { + } + + public function get_subscription_types() + { + return array(); + } + + public function get_subscription_methods() + { + return array(); + } + + + public function get_global_subscriptions() + { + return array(); + } + + public function add_subscription() + { + } + + public function delete_subscription() + { + } + + public function load_users() + { + } + + public function get_user() + { + return null; + } +} diff --git a/tests/mock/notifications_auth.php b/tests/mock/notifications_auth.php new file mode 100644 index 0000000000..d960acb81a --- /dev/null +++ b/tests/mock/notifications_auth.php @@ -0,0 +1,40 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +class phpbb_mock_notifications_auth extends phpbb_auth +{ + function acl_get_list($user_id = false, $opts = false, $forum_id = false) + { + $user_id = (!is_array($user_id)) ? array($user_id) : $user_id; + $opts = (!is_array($opts)) ? array($opts) : $opts; + $forum_id = (!is_array($forum_id)) ? array($forum_id) : $forum_id; + + $auth_list = array(); + + foreach ($forum_id as $fid) + { + foreach ($opts as $opt) + { + $auth_list[$fid][$opt] = array(); + + foreach ($user_id as $uid) + { + $auth_list[$fid][$opt][] = $uid; + } + } + } + + return $auth_list; + } + + function acl_get($opt, $f = 0) + { + return true; + } +} diff --git a/tests/mock/notifications_notification_manager.php b/tests/mock/notifications_notification_manager.php new file mode 100644 index 0000000000..81f24e67c0 --- /dev/null +++ b/tests/mock/notifications_notification_manager.php @@ -0,0 +1,69 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +/** +* Notifications service class +* @package notifications +*/ +class phpbb_mock_notifications_notification_manager extends phpbb_notification_manager +{ + public function set_var($name, $value) + { + $this->$name = $value; + } + + // Extra dependencies for get_*_class functions + protected $auth = null; + protected $cache = null; + protected $config = null; + public function setDependencies($auth, $cache, $config) + { + $this->auth = $auth; + $this->cache = $cache; + $this->config = $config; + } + + /** + * Helper to get the notifications item type class and set it up + */ + public function get_item_type_class($item_type, $data = array()) + { + $item_type = 'phpbb_notification_type_' . $item_type; + + $item = new $item_type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notifications_table, $this->user_notifications_table); + + $item->set_notification_manager($this); + + $item->set_initial_data($data); + + return $item; + } + + /** + * Helper to get the notifications method class and set it up + */ + public function get_method_class($method_name) + { + $method_name = 'phpbb_notification_method_' . $method_name; + + $method = new $method_name($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $this->phpbb_root_path, $this->php_ext, $this->notifications_table, $this->user_notifications_table); + + $method->set_notification_manager($this); + + return $method; + } +} diff --git a/tests/notification/ext/test/notification/type/test.php b/tests/notification/ext/test/notification/type/test.php new file mode 100644 index 0000000000..45670e1c2d --- /dev/null +++ b/tests/notification/ext/test/notification/type/test.php @@ -0,0 +1,85 @@ +<?php +/** +* +* @package notifications +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +/** +* @ignore +*/ +if (!defined('IN_PHPBB')) +{ + exit; +} + +class phpbb_notification_type_test extends phpbb_notification_type_base +{ + public function get_type() + { + return 'test'; + } + + public static function get_item_id($post) + { + return (int) $post['post_id']; + } + + public static function get_item_parent_id($post) + { + return (int) $post['topic_id']; + } + + public function find_users_for_notification($post, $options = array()) + { + return $this->check_user_notification_options(array(0), $options); + } + + public function create_insert_array($post, $pre_create_data = array()) + { + $this->time = $post['post_time']; + + return parent::create_insert_array($post, $pre_create_data); + } + + public function create_update_array($type_data) + { + $data = $this->create_insert_array($type_data); + + // Unset data unique to each row + unset( + $data['notification_id'], + $data['unread'], + $data['user_id'] + ); + + return $data; + } + + public function get_title() + { + return 'test title'; + } + + public function users_to_query() + { + return array(); + } + + public function get_url() + { + return ''; + } + + public function get_email_template() + { + return false; + } + + public function get_email_template_variables() + { + return array(); + } +} diff --git a/tests/notification/fixtures/notification.xml b/tests/notification/fixtures/notification.xml new file mode 100644 index 0000000000..38e5f811dd --- /dev/null +++ b/tests/notification/fixtures/notification.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_notifications"> + </table> +</dataset> diff --git a/tests/notification/notification.php b/tests/notification/notification.php new file mode 100644 index 0000000000..8fa77ff651 --- /dev/null +++ b/tests/notification/notification.php @@ -0,0 +1,387 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2012 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ +//calls: [ [set_notification_manager, [@notification_manager]] ] +class phpbb_notification_test extends phpbb_database_test_case +{ + protected $notifications, $db, $container, $user, $config, $auth, $cache; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml'); + } + + + protected function setUp() + { + parent::setUp(); + + global $phpbb_root_path, $db, $phpEx; + + if (!function_exists('set_var')) + { + include($phpbb_root_path . 'includes/functions.' . $phpEx); + } + + include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); + + $db = $this->db = $this->new_dbal(); + $this->config = new phpbb_config(array( + 'allow_privmsg' => true, + 'allow_bookmarks' => true, + 'allow_topic_notify' => true, + 'allow_forum_notify' => true, + )); + $this->user = new phpbb_mock_user(); + $this->user_loader = new phpbb_user_loader($this->db, 'phpbb_users'); + $this->auth = new phpbb_mock_notifications_auth(); + $this->cache = new phpbb_mock_cache(); + + $this->container = new phpbb_mock_container_builder(); + + $this->notifications = new phpbb_mock_notifications_notification_manager( + array(), + array(), + $this->container, + $this->user_loader, + $this->db, + $this->user, + $phpbb_root_path, + $phpEx, + 'phpbb_notifications', + 'phpbb_user_notifications' + ); + + $this->notifications->setDependencies($this->auth, $this->cache, $this->config); + + $types = array(); + foreach (array( + 'test', + 'approve_post', + 'approve_topic', + 'bookmark', + 'disapprove_post', + 'disapprove_topic', + 'pm', + 'post', + 'post_in_queue', + 'quote', + 'report_pm', + 'report_pm_closed', + 'report_post', + 'report_post_closed', + 'topic', + 'topic_in_queue', + ) as $type) + { + $class = $this->build_type('phpbb_notification_type_' . $type); + + $types[$type] = $class; + $this->container->set('notification.type.' . $type, $class); + } + + $this->notifications->set_var('notification_types', $types); + } + + protected function build_type($type) + { + global $phpbb_root_path, $phpEx; + + return new $type($this->user_loader, $this->db, $this->cache, $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notifications', 'phpbb_user_notifications'); + } + + public function test_get_subscription_types() + { + $subscription_types = $this->notifications->get_subscription_types(); + + $this->assertArrayHasKey('NOTIFICATION_GROUP_MISCELLANEOUS', $subscription_types); + $this->assertArrayHasKey('NOTIFICATION_GROUP_POSTING', $subscription_types); + + $this->assertArrayHasKey('bookmark', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('post', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('quote', $subscription_types['NOTIFICATION_GROUP_POSTING']); + $this->assertArrayHasKey('topic', $subscription_types['NOTIFICATION_GROUP_POSTING']); + + $this->assertArrayHasKey('pm', $subscription_types['NOTIFICATION_GROUP_MISCELLANEOUS']); + + //get_subscription_types + //get_subscription_methods + } + + public function test_subscriptions() + { + $this->notifications->delete_subscription('post', 0, '', 2); + + $this->assertArrayNotHasKey('post', $this->notifications->get_global_subscriptions(2)); + + $this->notifications->add_subscription('post', 0, '', 2); + + $this->assertArrayHasKey('post', $this->notifications->get_global_subscriptions(2)); + } + + public function test_notifications() + { + global $db; + + // Used to test post notifications later + $db->sql_query('INSERT INTO ' . TOPICS_WATCH_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'topic_id' => 2, + 'notify_status' => NOTIFY_YES, + 'user_id' => 0, + ))); + + $this->assertEquals(array( + 'notifications' => array(), + 'unread_count' => 0, + 'total_count' => 0, + ), $this->notifications->load_notifications(array( + 'count_unread' => true, + ))); + + $this->notifications->add_notifications('test', array( + 'post_id' => '1', + 'topic_id' => '1', + 'post_time' => 1349413321, + )); + + $this->notifications->add_notifications('test', array( + 'post_id' => '2', + 'topic_id' => '2', + 'post_time' => 1349413322, + )); + + $this->notifications->add_notifications('test', array( + 'post_id' => '3', + 'topic_id' => '2', + 'post_time' => 1349413323, + )); + + $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( + 'post_id' => '4', + 'topic_id' => '2', + 'post_time' => 1349413324, + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + )); + + $db->sql_query('INSERT INTO ' . BOOKMARKS_TABLE . ' ' . $db->sql_build_array('INSERT', array( + 'topic_id' => 2, + 'user_id' => 0, + ))); + + $this->notifications->add_notifications(array('quote', 'bookmark', 'post', 'test'), array( + 'post_id' => '5', + 'topic_id' => '2', + 'post_time' => 1349413325, + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + )); + + $this->notifications->delete_subscription('test'); + + $this->notifications->add_notifications('test', array( + 'post_id' => '6', + 'topic_id' => '2', + 'post_time' => 1349413326, + )); + + $notifications = $this->notifications->load_notifications(array( + 'count_unread' => true, + )); + + $expected = array( + 1 => array( + 'item_type' => 'test', + 'item_id' => 1, + 'item_parent_id' => 1, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1349413321, + 'data' => array(), + ), + 2 => array( + 'item_type' => 'test', + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1349413322, + 'data' => array(), + ), + 3 => array( + 'item_type' => 'test', + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1349413323, + 'data' => array(), + ), + 4 => array( + 'item_type' => 'post', + 'item_id' => 4, + 'item_parent_id' => 2, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1349413324, + 'data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + 5 => array( + 'item_type' => 'bookmark', + 'item_id' => 5, + 'item_parent_id' => 2, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1349413325, + 'data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + ); + + $this->assertEquals(sizeof($expected), $notifications['unread_count']); + + $notifications = $notifications['notifications']; + + foreach ($expected as $notification_id => $notification_data) + { + //echo $notifications[$notification_id]; + + $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); + + foreach ($notification_data as $key => $value) + { + $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); + } + } + + // Now test updating ------------------------------- + + $this->notifications->update_notifications('test', array( + 'post_id' => '1', + 'topic_id' => '2', // change parent_id + 'post_time' => 1349413321, + )); + + $this->notifications->update_notifications('test', array( + 'post_id' => '3', + 'topic_id' => '2', + 'post_time' => 1234, // change time + )); + + $this->notifications->update_notifications(array('quote', 'bookmark', 'post', 'test'), array( + 'post_id' => '5', + 'topic_id' => '2', + 'poster_id' => 2, + 'topic_title' => 'test-title2', // change topic_title + 'post_subject' => 'Re: test-title2', // change post_subject + 'forum_id' => 3, // change forum_id + 'forum_name' => 'Your second forum', // change forum_name + )); + + $notifications = $this->notifications->load_notifications(array( + 'count_unread' => true, + )); + + $expected = array( + 1 => array( + 'item_type' => 'test', + 'item_id' => 1, + 'item_parent_id' => 2, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1349413321, + 'data' => array(), + ), + 2 => array( + 'item_type' => 'test', + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1349413322, + 'data' => array(), + ), + 3 => array( + 'item_type' => 'test', + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1234, + 'data' => array(), + ), + 4 => array( + 'item_type' => 'post', + 'item_id' => 4, + 'item_parent_id' => 2, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1349413324, + 'data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + 5 => array( + 'item_type' => 'bookmark', + 'item_id' => 5, + 'item_parent_id' => 2, + 'user_id' => 0, + 'unread' => 1, + 'time' => 1349413325, + 'data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title2', + 'post_subject' => 'Re: test-title2', + 'post_username' => '', + 'forum_id' => 3, + 'forum_name' => 'Your second forum', + ), + ), + ); + + $this->assertEquals(sizeof($expected), $notifications['unread_count']); + + $notifications = $notifications['notifications']; + + foreach ($expected as $notification_id => $notification_data) + { + //echo $notifications[$notification_id]; + + $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); + + foreach ($notification_data as $key => $value) + { + $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); + } + } + } +} diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php index f705825262..7be5429ca3 100644 --- a/tests/privmsgs/delete_user_pms_test.php +++ b/tests/privmsgs/delete_user_pms_test.php @@ -81,9 +81,10 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case */ public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to) { - global $db; + global $db, $phpbb_notifications; $db = $this->new_dbal(); + $phpbb_notifications = new phpbb_mock_notification_manager(); phpbb_delete_user_pms($delete_user); |