From e0ef10128b68cfae9774f6c87cc1a841cacecd8d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 26 Jul 2013 10:26:52 -0500 Subject: [PATCH 01/39] [ticket/11744] Group join request notification PHPBB3-11744 --- phpBB/config/notifications.yml | 18 ++ phpBB/includes/functions_user.php | 12 +- phpBB/includes/ucp/ucp_groups.php | 34 +--- phpBB/language/en/common.php | 1 + phpBB/language/en/ucp.php | 1 + phpBB/phpbb/notification/manager.php | 15 +- .../phpbb/notification/type/group_request.php | 161 ++++++++++++++++++ 7 files changed, 204 insertions(+), 38 deletions(-) create mode 100644 phpBB/phpbb/notification/type/group_request.php diff --git a/phpBB/config/notifications.yml b/phpBB/config/notifications.yml index 60aa63a854..04c5e46a9c 100644 --- a/phpBB/config/notifications.yml +++ b/phpBB/config/notifications.yml @@ -103,6 +103,24 @@ services: tags: - { name: notification.type } + notification.type.group_request: + class: phpbb_notification_type_group_request + scope: prototype # scope MUST be prototype for this to work! + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notification_types% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + notification.type.pm: class: phpbb_notification_type_pm scope: prototype # scope MUST be prototype for this to work! diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 1b598f7bf7..c4d96e1773 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2635,7 +2635,7 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false, */ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, $group_name = false) { - global $db, $auth, $config, $phpbb_dispatcher; + global $db, $auth, $config, $phpbb_dispatcher, $phpbb_container; if ($config['coppa_enable']) { @@ -2769,6 +2769,10 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, group_update_listings($group_id); + $phpbb_notifications = $phpbb_container->get('notification_manager'); + + $phpbb_notifications->delete_notifications('group_request', $user_id_ary, $group_id); + // Return false - no error return false; } @@ -2858,7 +2862,7 @@ function remove_default_rank($group_id, $user_ids) */ function group_user_attributes($action, $group_id, $user_id_ary = false, $username_ary = false, $group_name = false, $group_attributes = false) { - global $db, $auth, $phpbb_root_path, $phpEx, $config; + global $db, $auth, $phpbb_root_path, $phpEx, $config, $phpbb_container; // We need both username and user_id info $result = user_get_id_name($user_id_ary, $username_ary); @@ -2951,6 +2955,10 @@ function group_user_attributes($action, $group_id, $user_id_ary = false, $userna $messenger->save_queue(); + $phpbb_notifications = $phpbb_container->get('notification_manager'); + + $phpbb_notifications->delete_notifications('group_request', $user_id_ary, $group_id); + $log = 'LOG_USERS_APPROVED'; break; diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 8620e33e47..fbb0f41e21 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -198,36 +198,12 @@ class ucp_groups { group_user_add($group_id, $user->data['user_id'], false, false, false, 0, 1); - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(); + $phpbb_notifications = $phpbb_container->get('notification_manager'); - $sql = 'SELECT u.username, u.username_clean, u.user_email, u.user_notify_type, u.user_jabber, u.user_lang - FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . " u - WHERE ug.user_id = u.user_id - AND ug.group_leader = 1 - AND ug.group_id = $group_id"; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $messenger->template('group_request', $row['user_lang']); - - $messenger->set_addresses($row); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($row['username']), - 'GROUP_NAME' => htmlspecialchars_decode($group_row[$group_id]['group_name']), - 'REQUEST_USERNAME' => $user->data['username'], - - 'U_PENDING' => generate_board_url() . "/ucp.$phpEx?i=groups&mode=manage&action=list&g=$group_id", - 'U_GROUP' => generate_board_url() . "/memberlist.$phpEx?mode=group&g=$group_id") - ); - - $messenger->send($row['user_notify_type']); - } - $db->sql_freeresult($result); - - $messenger->save_queue(); + $phpbb_notifications->add_notifications('group_request', array_merge( + $group_row[$group_id], + array('user_id' => $user->data['user_id']) + )); } add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_JOIN' . (($group_row[$group_id]['group_type'] == GROUP_FREE) ? '' : '_PENDING'), $group_row[$group_id]['group_name']); diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index b188d90f3a..8ababfcd2a 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -414,6 +414,7 @@ $lang = array_merge($lang, array( 2 => '%d Notifications', ), 'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.', + 'NOTIFICATION_GROUP_REQUEST' => '%1$s is requesting to join the group you manage, %2$s.', '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".', diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 51823ddb12..dc09e8cdcb 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -313,6 +313,7 @@ $lang = array_merge($lang, array( 'NOTIFICATION_METHOD_JABBER' => 'Jabber', 'NOTIFICATION_TYPE' => 'Notification type', 'NOTIFICATION_TYPE_BOOKMARK' => 'Someone replies to a topic you have bookmarked', + 'NOTIFICATION_TYPE_GROUP_REQUEST' => 'Someone requests to join a group you lead', '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', diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index 97833710c0..4e6028ec3f 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -59,7 +59,7 @@ class phpbb_notification_manager /** * Notification Constructor - * + * * @param array $notification_types * @param array $notification_methods * @param ContainerBuilder $phpbb_container @@ -490,15 +490,15 @@ class phpbb_notification_manager * * @param string|array $notification_type_name 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 + * @param bool|int|array $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified */ - public function delete_notifications($notification_type_name, $item_id) + public function delete_notifications($notification_type_name, $item_id, $parent_id = false) { if (is_array($notification_type_name)) { foreach ($notification_type_name as $type) { - $this->delete_notifications($type, $item_id); + $this->delete_notifications($type, $item_id, $parent_id); } return; @@ -508,7 +508,8 @@ class phpbb_notification_manager $sql = 'DELETE FROM ' . $this->notifications_table . ' WHERE notification_type_id = ' . (int) $notification_type_id . ' - AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id); + AND ' . (is_array($item_id) ? $this->db->sql_in_set('item_id', $item_id) : 'item_id = ' . (int) $item_id) . + (($parent_id !== false) ? ' AND ' . ((is_array($parent_id) ? $this->db->sql_in_set('item_parent_id', $parent_id) : 'item_parent_id = ' . (int) $parent_id)) : ''); $this->db->sql_query($sql); } @@ -834,12 +835,12 @@ class phpbb_notification_manager protected function load_object($object_name) { $object = $this->phpbb_container->get($object_name); - + if (method_exists($object, 'set_notification_manager')) { $object->set_notification_manager($this); } - + return $object; } diff --git a/phpBB/phpbb/notification/type/group_request.php b/phpBB/phpbb/notification/type/group_request.php new file mode 100644 index 0000000000..96015783fb --- /dev/null +++ b/phpBB/phpbb/notification/type/group_request.php @@ -0,0 +1,161 @@ + 'NOTIFICATION_TYPE_GROUP_REQUEST', + ); + + /** + * {@inheritdoc} + */ + public function is_available() + { + // Leader of any groups? + $sql = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' + WHERE user_id = ' . (int) $this->user->data['user_id'] . ' + AND group_leader = 1'; + $result = $this->db->sql_query_limit($sql, 1); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); + + return (!empty($row)) ? true : false; + } + + /** + * {@inheritdoc} + */ + public static function get_item_id($group) + { + return (int) $group['user_id']; + } + + /** + * {@inheritdoc} + */ + public static function get_item_parent_id($group) + { + // Group id is the parent + return (int) $group['group_id']; + } + + /** + * {@inheritdoc} + */ + public function find_users_for_notification($group, $options = array()) + { + $options = array_merge(array( + 'ignore_users' => array(), + ), $options); + + $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . ' + WHERE group_leader = 1 + AND group_id = ' . (int) $group['group_id']; + $result = $this->db->sql_query($sql); + + $user_ids = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $user_ids[] = $row['user_id']; + } + $this->db->sql_freeresult($result); + + $this->user_loader->load_users($user_ids); + + return $this->check_user_notification_options($user_ids, $options); + } + + /** + * {@inheritdoc} + */ + public function get_avatar() + { + return $this->user_loader->get_avatar($this->item_id); + } + + /** + * {@inheritdoc} + */ + public function get_title() + { + $username = $this->user_loader->get_username($this->item_id, 'no_profile'); + + return $this->user->lang('NOTIFICATION_GROUP_REQUEST', $username, $this->get_data('group_name')); + } + + /** + * {@inheritdoc} + */ + public function get_email_template() + { + return 'group_request'; + } + + /** + * {@inheritdoc} + */ + public function get_email_template_variables() + { + $user_data = $this->user_loader->get_user($this->item_id); + + return array( + 'GROUP_NAME' => htmlspecialchars_decode($this->get_data('group_name')), + 'REQUEST_USERNAME' => htmlspecialchars_decode($user_data['username']), + + 'U_PENDING' => generate_board_url() . "/ucp.{$this->php_ext}?i=groups&mode=manage&action=list&g={$this->item_parent_id}", + 'U_GROUP' => generate_board_url() . "/memberlist.{$this->php_ext}?mode=group&g={$this->item_parent_id}", + ); + } + + /** + * {@inheritdoc} + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'ucp.' . $this->php_ext, "i=groups&mode=manage&action=list&g={$this->item_parent_id}"); + } + + /** + * {@inheritdoc} + */ + public function users_to_query() + { + return array($this->item_id); + } + + /** + * {@inheritdoc} + */ + public function create_insert_array($group, $pre_create_data = array()) + { + $this->set_data('group_name', $group['group_name']); + + return parent::create_insert_array($group, $pre_create_data); + } +} From c260e82a9bc7961d17f2ac6698907f1a4ed392f2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 11:22:44 -0500 Subject: [PATCH 02/39] [ticket/11744] Move notification from ucp_groups to group_user_add PHPBB3-11744 --- phpBB/includes/functions_user.php | 16 +++++++++++++++- phpBB/includes/ucp/ucp_groups.php | 7 ------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index c4d96e1773..102fbaae78 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2534,7 +2534,7 @@ function group_delete($group_id, $group_name = false) */ function group_user_add($group_id, $user_id_ary = false, $username_ary = false, $group_name = false, $default = false, $leader = 0, $pending = 0, $group_attributes = false) { - global $db, $auth; + global $db, $auth, $phpbb_container; // We need both username and user_id info $result = user_get_id_name($user_id_ary, $username_ary); @@ -2622,6 +2622,20 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false, group_update_listings($group_id); + if ($pending) + { + $phpbb_notifications = $phpbb_container->get('notification_manager'); + + foreach ($add_id_ary as $user_id) + { + $phpbb_notifications->add_notifications('group_request', array( + 'group_id' => $group_id, + 'user_id' => $user_id, + 'group_name' => $group_name, + )); + } + } + // Return false - no error return false; } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index fbb0f41e21..6f78136f11 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -197,13 +197,6 @@ class ucp_groups else { group_user_add($group_id, $user->data['user_id'], false, false, false, 0, 1); - - $phpbb_notifications = $phpbb_container->get('notification_manager'); - - $phpbb_notifications->add_notifications('group_request', array_merge( - $group_row[$group_id], - array('user_id' => $user->data['user_id']) - )); } add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_JOIN' . (($group_row[$group_id]['group_type'] == GROUP_FREE) ? '' : '_PENDING'), $group_row[$group_id]['group_name']); From 3f230b1a8c716adb77b679fed91d50c391387b19 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 12:29:49 -0500 Subject: [PATCH 03/39] [ticket/11744] Create null log class (primarily for unit test) PHPBB3-11744 --- phpBB/phpbb/log/null.php | 125 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 phpBB/phpbb/log/null.php diff --git a/phpBB/phpbb/log/null.php b/phpBB/phpbb/log/null.php new file mode 100644 index 0000000000..9837058ef5 --- /dev/null +++ b/phpBB/phpbb/log/null.php @@ -0,0 +1,125 @@ + Date: Fri, 26 Jul 2013 13:08:53 -0500 Subject: [PATCH 04/39] [ticket/11744] Create base notification test class for setup PHPBB3-11744 --- tests/notification/base.php | 105 +++++++++++++++++++++++ tests/notification/notification_test.php | 85 +----------------- 2 files changed, 107 insertions(+), 83 deletions(-) create mode 100644 tests/notification/base.php diff --git a/tests/notification/base.php b/tests/notification/base.php new file mode 100644 index 0000000000..ab92f88262 --- /dev/null +++ b/tests/notification/base.php @@ -0,0 +1,105 @@ +db = $this->new_dbal(); + $config = $this->config = new phpbb_config(array( + 'allow_privmsg' => true, + 'allow_bookmarks' => true, + 'allow_topic_notify' => true, + 'allow_forum_notify' => true, + )); + $user = $this->user = new phpbb_user(); + $this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); + $auth = $this->auth = new phpbb_mock_notifications_auth(); + $cache = $this->cache = new phpbb_cache_service( + new phpbb_cache_driver_null(), + $this->config, + $this->db, + $phpbb_root_path, + $phpEx + ); + + $phpbb_container = $this->container = new phpbb_mock_container_builder(); + + $this->notifications = new phpbb_notification_manager_helper( + array(), + array(), + $this->container, + $this->user_loader, + $this->db, + $this->cache, + $this->user, + $phpbb_root_path, + $phpEx, + 'phpbb_notification_types', + 'phpbb_notifications', + 'phpbb_user_notifications' + ); + + $phpbb_container->set('notification_manager', $this->notifications); + + $this->notifications->setDependencies($this->auth, $this->config); + + $types = array(); + foreach ($this->get_notification_types() 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->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); + } +} diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 8f7eb3b8a8..39073c2602 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/manager_helper.php'; +require_once dirname(__FILE__) . '/base.php'; -class phpbb_notification_test extends phpbb_database_test_case +class phpbb_notification_test extends phpbb_tests_notification_base { protected $notifications, $db, $container, $user, $config, $auth, $cache; @@ -18,87 +18,6 @@ class phpbb_notification_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/notification.xml'); } - protected function setUp() - { - parent::setUp(); - - global $phpbb_root_path, $phpEx; - - include_once(__DIR__ . '/ext/test/notification/type/test.' . $phpEx); - - $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_user(); - $this->user_loader = new phpbb_user_loader($this->db, $phpbb_root_path, $phpEx, 'phpbb_users'); - $this->auth = new phpbb_mock_notifications_auth(); - $this->cache = new phpbb_cache_service( - new phpbb_cache_driver_null(), - $this->config, - $this->db, - $phpbb_root_path, - $phpEx - ); - - $this->container = new phpbb_mock_container_builder(); - - $this->notifications = new phpbb_notification_manager_helper( - array(), - array(), - $this->container, - $this->user_loader, - $this->db, - $this->cache, - $this->user, - $phpbb_root_path, - $phpEx, - 'phpbb_notification_types', - 'phpbb_notifications', - 'phpbb_user_notifications' - ); - - $this->notifications->setDependencies($this->auth, $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->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); - } - public function test_get_notification_type_id() { // They should be inserted the first time From d6384f89396dc7e8b42c855df2cc1ef49095520b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 13:09:24 -0500 Subject: [PATCH 05/39] [ticket/11744] Group request test PHPBB3-11744 --- tests/notification/fixtures/group_request.xml | 30 ++++++ tests/notification/group_request_test.php | 97 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 tests/notification/fixtures/group_request.xml create mode 100644 tests/notification/group_request_test.php diff --git a/tests/notification/fixtures/group_request.xml b/tests/notification/fixtures/group_request.xml new file mode 100644 index 0000000000..1eb73f1e15 --- /dev/null +++ b/tests/notification/fixtures/group_request.xml @@ -0,0 +1,30 @@ + + + + user_id + username + username_clean + user_permissions + user_sig + user_occ + user_interests + + 2 + 2 + 2 + + + + + + + 3 + 3 + 3 + + + + + +
+
diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php new file mode 100644 index 0000000000..06a5a4baa8 --- /dev/null +++ b/tests/notification/group_request_test.php @@ -0,0 +1,97 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/group_request.xml'); + } + + protected function get_notification_types() + { + return array_merge( + parent::get_notification_types(), + array( + 'group_request', + ) + ); + } + + public function test_notifications() + { + global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_log; + + include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); + include($phpbb_root_path . 'includes/functions_content.' . $phpEx); + + set_config(false, false, false, $this->config); + + $this->container->set('groupposition.legend', new phpbb_groupposition_legend( + $this->db, + $this->user + )); + $this->container->set('groupposition.teampage', new phpbb_groupposition_teampage( + $this->db, + $this->user, + $this->cache->get_driver() + )); + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $phpbb_log = new phpbb_log_null(); + + $this->assertEquals(1, $this->notifications->get_notification_type_id('group_request')); + + $group_id = false; + group_create($group_id, GROUP_OPEN, 'test', 'test group', array()); + + // Add user 1 as group leader + group_user_add($group_id, 2, false, false, false, true, false); + + // Add notifications for group requests for user 1 + //$this->notifications->add_subscription('group_request', 0, '', 2); + + // Add user 2 as pending + group_user_add($group_id, 3, false, false, false, false, true); + + $notifications = $this->notifications->load_notifications(array( + 'count_unread' => true, + 'user_id' => 2, + )); + + $expected = array( + 1 => array( + 'notification_type_id' => 1, + 'item_id' => 3, // user_id of requesting join + 'item_parent_id' => $group_id, + 'user_id' => 2, + 'notification_read' => 0, + 'notification_data' => array( + 'group_name' => 'test', + ), + ), + ); + + $this->assertEquals(sizeof($expected), $notifications['unread_count']); + + $notifications = $notifications['notifications']; + + foreach ($expected as $notification_id => $notification_data) + { + $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); + } + } + } +} From 03ff0581e0b6397e3cf194f0b021aae732cfccfd Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 13:10:13 -0500 Subject: [PATCH 06/39] [ticket/11744] Cleanup PHPBB3-11744 --- tests/notification/group_request_test.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index 06a5a4baa8..25c5406000 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -48,6 +48,8 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas $phpbb_dispatcher = new phpbb_mock_event_dispatcher; $phpbb_log = new phpbb_log_null(); + // Now on to the actual test + $this->assertEquals(1, $this->notifications->get_notification_type_id('group_request')); $group_id = false; @@ -56,9 +58,6 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas // Add user 1 as group leader group_user_add($group_id, 2, false, false, false, true, false); - // Add notifications for group requests for user 1 - //$this->notifications->add_subscription('group_request', 0, '', 2); - // Add user 2 as pending group_user_add($group_id, 3, false, false, false, false, true); From 9573b36b3278aa374a7ea4fa72e6a81c459623b2 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 13:23:33 -0500 Subject: [PATCH 07/39] [ticket/11744] Include once PHPBB3-11744 --- tests/notification/group_request_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index 25c5406000..dffdc771b1 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -30,9 +30,9 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas { global $phpbb_root_path, $phpEx, $phpbb_dispatcher, $phpbb_log; - include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); - include($phpbb_root_path . 'includes/functions_user.' . $phpEx); - include($phpbb_root_path . 'includes/functions_content.' . $phpEx); + include_once($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx); + include_once($phpbb_root_path . 'includes/functions_content.' . $phpEx); set_config(false, false, false, $this->config); From 185d4e112e2f1d01364aad36eb540294fa7c953b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 14:11:42 -0500 Subject: [PATCH 08/39] [ticket/11744] Fix functional test case that's failing PHPBB3-11744 --- tests/test_framework/phpbb_functional_test_case.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index de3611c4cc..d1dab4c148 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -533,12 +533,9 @@ class phpbb_functional_test_case extends phpbb_test_case $cache = new phpbb_mock_null_cache; $cache_driver = new phpbb_cache_driver_null(); - $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); - $phpbb_container - ->expects($this->any()) - ->method('get') - ->with('cache.driver') - ->will($this->returnValue($cache_driver)); + $phpbb_container = new phpbb_mock_container_builder(); + $phpbb_container->set('cache.driver', $cache_driver); + $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); if (!function_exists('utf_clean_string')) { From 4f0dd9a752c79004acdfbedce92234c6818b9765 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 14:51:46 -0500 Subject: [PATCH 09/39] [ticket/11744] Tables are not truncated in some dbms during tests PHPBB3-11744 --- tests/notification/group_request_test.php | 3 --- tests/notification/notification_test.php | 16 ++++++++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index dffdc771b1..d36864cc27 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -50,8 +50,6 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas // Now on to the actual test - $this->assertEquals(1, $this->notifications->get_notification_type_id('group_request')); - $group_id = false; group_create($group_id, GROUP_OPEN, 'test', 'test group', array()); @@ -68,7 +66,6 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas $expected = array( 1 => array( - 'notification_type_id' => 1, 'item_id' => 3, // user_id of requesting join 'item_parent_id' => $group_id, 'user_id' => 2, diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 39073c2602..94453fe201 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -21,14 +21,14 @@ class phpbb_notification_test extends phpbb_tests_notification_base public function test_get_notification_type_id() { // They should be inserted the first time - $this->assertEquals(1, $this->notifications->get_notification_type_id('post')); - $this->assertEquals(2, $this->notifications->get_notification_type_id('quote')); - $this->assertEquals(3, $this->notifications->get_notification_type_id('test')); + $post_type_id = $this->notifications->get_notification_type_id('post'); + $quote_type_id = $this->notifications->get_notification_type_id('quote'); + $test_type_id = $this->notifications->get_notification_type_id('test'); $this->assertEquals(array( - 'test' => 3, - 'quote' => 2, - 'post' => 1, + 'test' => $test_type_id, + 'quote' => $quote_type_id, + 'post' => $post_type_id, ), $this->notifications->get_notification_type_ids(array( 'test', @@ -36,11 +36,11 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'post', ) )); - $this->assertEquals(2, $this->notifications->get_notification_type_id('quote')); + $this->assertEquals($quote_type_id, $this->notifications->get_notification_type_id('quote')); try { - $this->assertEquals(3, $this->notifications->get_notification_type_id('fail')); + $this->assertEquals(false, $this->notifications->get_notification_type_id('fail')); $this->fail('Non-existent type should throw an exception'); } From f2ad22439fd0a5ea47bd2d4ee22c51f663949a8b Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 15:00:45 -0500 Subject: [PATCH 10/39] [ticket/11744] Empty notifications tables after testing them PHPBB3-11744 --- tests/notification/base.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/notification/base.php b/tests/notification/base.php index ab92f88262..3560ac6fcd 100644 --- a/tests/notification/base.php +++ b/tests/notification/base.php @@ -96,6 +96,15 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case $this->notifications->set_var('notification_types', $types); } + protected function tearDown() + { + $this->db->sql_query('DELETE FROM phpbb_notification_types'); + $this->db->sql_query('DELETE FROM phpbb_notifications'); + $this->db->sql_query('DELETE FROM phpbb_user_notifications'); + + parent::tearDown(); + } + protected function build_type($type) { global $phpbb_root_path, $phpEx; From 7dd16f4148890a2c1f52eeb9c660afe2fb85d23c Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 15:44:49 -0500 Subject: [PATCH 11/39] [ticket/11744] spelling PHPBB3-11744 --- tests/test_framework/phpbb_database_test_connection_manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index c93a777701..9d2cfebd29 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -138,7 +138,7 @@ class phpbb_database_test_connection_manager catch (PDOException $e) { $cleaned_dsn = str_replace($this->config['dbpasswd'], '*password*', $dsn); - throw new Exception("Unable do connect to $cleaned_dsn using PDO with error: {$e->getMessage()}"); + throw new Exception("Unable to connect to $cleaned_dsn using PDO with error: {$e->getMessage()}"); } $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); From 49c6e835605a6f36c050cda2e92646941668e415 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 26 Jul 2013 17:27:52 -0500 Subject: [PATCH 12/39] [ticket/11744] Fix tests for postgresql PHPBB3-11744 --- tests/notification/base.php | 5 -- tests/notification/group_request_test.php | 16 +++--- tests/notification/notification_test.php | 60 +++++++++-------------- 3 files changed, 31 insertions(+), 50 deletions(-) diff --git a/tests/notification/base.php b/tests/notification/base.php index 3560ac6fcd..f8c39934bb 100644 --- a/tests/notification/base.php +++ b/tests/notification/base.php @@ -94,15 +94,10 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case } $this->notifications->set_var('notification_types', $types); - } - protected function tearDown() - { $this->db->sql_query('DELETE FROM phpbb_notification_types'); $this->db->sql_query('DELETE FROM phpbb_notifications'); $this->db->sql_query('DELETE FROM phpbb_user_notifications'); - - parent::tearDown(); } protected function build_type($type) diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index d36864cc27..d61c4adf38 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -65,7 +65,7 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas )); $expected = array( - 1 => array( + array( 'item_id' => 3, // user_id of requesting join 'item_parent_id' => $group_id, 'user_id' => 2, @@ -78,16 +78,16 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas $this->assertEquals(sizeof($expected), $notifications['unread_count']); - $notifications = $notifications['notifications']; - - foreach ($expected as $notification_id => $notification_data) + $i = 0; + foreach ($notifications['notifications'] as $notification) { - $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); - - foreach ($notification_data as $key => $value) + foreach ($expected[$i] as $notification_data) { - $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); + $this->assertEquals($value, $notification->$key, $key . ' ' . $i); } + + $i++; } + } } diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index 94453fe201..b8dc9a9042 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -165,8 +165,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base )); $expected = array( - 1 => array( - 'notification_type_id' => 4, + array( 'item_id' => 1, 'item_parent_id' => 1, 'user_id' => 0, @@ -174,8 +173,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'notification_time' => 1349413321, 'notification_data' => array(), ), - 2 => array( - 'notification_type_id' => 4, + array( 'item_id' => 2, 'item_parent_id' => 2, 'user_id' => 0, @@ -183,8 +181,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'notification_time' => 1349413322, 'notification_data' => array(), ), - 3 => array( - 'notification_type_id' => 4, + array( 'item_id' => 3, 'item_parent_id' => 2, 'user_id' => 0, @@ -192,8 +189,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'notification_time' => 1349413323, 'notification_data' => array(), ), - 4 => array( - 'notification_type_id' => 3, + array( 'item_id' => 4, 'item_parent_id' => 2, 'user_id' => 0, @@ -208,8 +204,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'forum_name' => 'Your first forum', ), ), - 5 => array( - 'notification_type_id' => 2, + array( 'item_id' => 5, 'item_parent_id' => 2, 'user_id' => 0, @@ -228,18 +223,15 @@ class phpbb_notification_test extends phpbb_tests_notification_base $this->assertEquals(sizeof($expected), $notifications['unread_count']); - $notifications = $notifications['notifications']; - - foreach ($expected as $notification_id => $notification_data) + $i = 0; + foreach ($notifications['notifications'] as $notification) { - //echo $notifications[$notification_id]; - - $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); - - foreach ($notification_data as $key => $value) + foreach ($expected[$i] as $notification_data) { - $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); + $this->assertEquals($value, $notification->$key, $key . ' ' . $i); } + + $i++; } // Now test updating ------------------------------- @@ -271,8 +263,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base )); $expected = array( - 1 => array( - 'notification_type_id' => 4, + array( 'item_id' => 1, 'item_parent_id' => 2, 'user_id' => 0, @@ -280,8 +271,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'notification_time' => 1349413321, 'notification_data' => array(), ), - 2 => array( - 'notification_type_id' => 4, + array( 'item_id' => 2, 'item_parent_id' => 2, 'user_id' => 0, @@ -289,7 +279,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'notification_time' => 1349413322, 'notification_data' => array(), ), - 3 => array( + array( 'notification_type_id' => 4, 'item_id' => 3, 'item_parent_id' => 2, @@ -298,8 +288,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'notification_time' => 1234, 'notification_data' => array(), ), - 4 => array( - 'notification_type_id' => 3, + array( 'item_id' => 4, 'item_parent_id' => 2, 'user_id' => 0, @@ -314,8 +303,7 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'forum_name' => 'Your first forum', ), ), - 5 => array( - 'notification_type_id' => 2, + array( 'item_id' => 5, 'item_parent_id' => 2, 'user_id' => 0, @@ -334,18 +322,16 @@ class phpbb_notification_test extends phpbb_tests_notification_base $this->assertEquals(sizeof($expected), $notifications['unread_count']); - $notifications = $notifications['notifications']; - - foreach ($expected as $notification_id => $notification_data) + $i = 0; + foreach ($notifications['notifications'] as $notification) { - //echo $notifications[$notification_id]; - - $this->assertEquals($notification_id, $notifications[$notification_id]->notification_id, 'notification_id'); - - foreach ($notification_data as $key => $value) + foreach ($expected[$i] as $notification_data) { - $this->assertEquals($value, $notifications[$notification_id]->$key, $key . ' ' . $notification_id); + $this->assertEquals($value, $notification->$key, $key . ' ' . $i); } + + $i++; } + } } From 7cfb04690de08b10752b8881f918ce9e476bb6ab Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 27 Jul 2013 09:07:23 -0500 Subject: [PATCH 13/39] [ticket/11744] Copyright year PHPBB3-11744 --- tests/notification/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/notification/base.php b/tests/notification/base.php index f8c39934bb..5ef6fcebad 100644 --- a/tests/notification/base.php +++ b/tests/notification/base.php @@ -2,7 +2,7 @@ /** * * @package testing -* @copyright (c) 2012 phpBB Group +* @copyright (c) 2013 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ From 93db6190f582b2af41d3bf643758e48772ea9ba0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 27 Jul 2013 09:08:35 -0500 Subject: [PATCH 14/39] [ticket/11744] Language PHPBB3-11744 --- phpBB/language/en/common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 8ababfcd2a..cdaf8269ed 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -414,7 +414,7 @@ $lang = array_merge($lang, array( 2 => '%d Notifications', ), 'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.', - 'NOTIFICATION_GROUP_REQUEST' => '%1$s is requesting to join the group you manage, %2$s.', + 'NOTIFICATION_GROUP_REQUEST' => '%1$s is requesting to join the group %2$s.', '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".', From b213be84a7ff0f947de0025dcc4620142edf226b Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 27 Jul 2013 09:09:24 -0500 Subject: [PATCH 15/39] [ticket/11744] Comments PHPBB3-11744 --- phpBB/phpbb/notification/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/notification/manager.php b/phpBB/phpbb/notification/manager.php index 4e6028ec3f..acfc984ddc 100644 --- a/phpBB/phpbb/notification/manager.php +++ b/phpBB/phpbb/notification/manager.php @@ -490,7 +490,7 @@ class phpbb_notification_manager * * @param string|array $notification_type_name 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 bool|int|array $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified + * @param mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked) */ public function delete_notifications($notification_type_name, $item_id, $parent_id = false) { From 46b4a405b1563c2fe15dad34c9ff2843271cd8f8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 27 Jul 2013 17:02:45 -0500 Subject: [PATCH 16/39] [ticket/11745] Group request approved notification PHPBB3-11745 --- phpBB/config/notifications.yml | 18 +++ phpBB/includes/functions_user.php | 29 +---- phpBB/language/en/common.php | 1 + phpBB/language/en/email/group_approved.txt | 10 -- .../type/group_request_approved.php | 118 ++++++++++++++++++ 5 files changed, 143 insertions(+), 33 deletions(-) delete mode 100644 phpBB/language/en/email/group_approved.txt create mode 100644 phpBB/phpbb/notification/type/group_request_approved.php diff --git a/phpBB/config/notifications.yml b/phpBB/config/notifications.yml index 04c5e46a9c..fc687cbd19 100644 --- a/phpBB/config/notifications.yml +++ b/phpBB/config/notifications.yml @@ -121,6 +121,24 @@ services: tags: - { name: notification.type } + notification.type.group_request_approved: + class: phpbb_notification_type_group_request_approved + scope: prototype # scope MUST be prototype for this to work! + arguments: + - @user_loader + - @dbal.conn + - @cache.driver + - @user + - @auth + - @config + - %core.root_path% + - %core.php_ext% + - %tables.notification_types% + - %tables.notifications% + - %tables.user_notifications% + tags: + - { name: notification.type } + notification.type.pm: class: phpbb_notification_type_pm scope: prototype # scope MUST be prototype for this to work! diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 102fbaae78..4fcce67801 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2929,11 +2929,10 @@ function group_user_attributes($action, $group_id, $user_id_ary = false, $userna AND ' . $db->sql_in_set('ug.user_id', $user_id_ary); $result = $db->sql_query($sql); - $user_id_ary = $email_users = array(); + $user_id_ary = array(); while ($row = $db->sql_fetchrow($result)) { $user_id_ary[] = $row['user_id']; - $email_users[] = $row; } $db->sql_freeresult($result); @@ -2948,29 +2947,13 @@ function group_user_attributes($action, $group_id, $user_id_ary = false, $userna AND " . $db->sql_in_set('user_id', $user_id_ary); $db->sql_query($sql); - // Send approved email to users... - include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); - $messenger = new messenger(); - - foreach ($email_users as $row) - { - $messenger->template('group_approved', $row['user_lang']); - - $messenger->set_addresses($row); - - $messenger->assign_vars(array( - 'USERNAME' => htmlspecialchars_decode($row['username']), - 'GROUP_NAME' => htmlspecialchars_decode($group_name), - 'U_GROUP' => generate_board_url() . "/ucp.$phpEx?i=groups&mode=membership") - ); - - $messenger->send($row['user_notify_type']); - } - - $messenger->save_queue(); - $phpbb_notifications = $phpbb_container->get('notification_manager'); + $phpbb_notifications->add_notifications('group_request_approved', array( + 'user_ids' => $user_id_ary, + 'group_id' => $group_id, + 'group_name' => $group_name, + )); $phpbb_notifications->delete_notifications('group_request', $user_id_ary, $group_id); $log = 'LOG_USERS_APPROVED'; diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index cdaf8269ed..91b1f6d9d9 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -415,6 +415,7 @@ $lang = array_merge($lang, array( ), 'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.', 'NOTIFICATION_GROUP_REQUEST' => '%1$s is requesting to join the group %2$s.', + 'NOTIFICATION_GROUP_REQUEST_APPROVED' => 'Your request to join the "%1$s" group on has been approved.', '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".', diff --git a/phpBB/language/en/email/group_approved.txt b/phpBB/language/en/email/group_approved.txt deleted file mode 100644 index 24afefcd07..0000000000 --- a/phpBB/language/en/email/group_approved.txt +++ /dev/null @@ -1,10 +0,0 @@ -Subject: Your request has been approved - -Congratulations, - -Your request to join the "{GROUP_NAME}" group on "{SITENAME}" has been approved. -Click on the following link to see your group membership. - -{U_GROUP} - -{EMAIL_SIG} diff --git a/phpBB/phpbb/notification/type/group_request_approved.php b/phpBB/phpbb/notification/type/group_request_approved.php new file mode 100644 index 0000000000..ce83329ff3 --- /dev/null +++ b/phpBB/phpbb/notification/type/group_request_approved.php @@ -0,0 +1,118 @@ +user->lang('NOTIFICATION_GROUP_REQUEST_APPROVED', $this->get_data('group_name')); + } + + /** + * {@inheritdoc} + */ + public function get_url() + { + return append_sid($this->phpbb_root_path . 'memberlist.' . $this->php_ext, "mode=group&g={$this->item_id}"); + } + + /** + * {@inheritdoc} + */ + public function create_insert_array($group, $pre_create_data = array()) + { + $this->set_data('group_name', $group['group_name']); + + return parent::create_insert_array($group, $pre_create_data); + } + + /** + * {@inheritdoc} + */ + public function users_to_query() + { + return array(); + } + + /** + * {@inheritdoc} + */ + public function get_email_template() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function get_email_template_variables() + { + return array(); + } +} From 359aedf664b41d553665d62243d7943293b79d96 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 27 Jul 2013 19:31:31 -0500 Subject: [PATCH 17/39] [ticket/11744] Helper function to assert notifications in base test This also fixes tests PHPBB3-11744 --- tests/notification/base.php | 22 ++ tests/notification/group_request_test.php | 43 ++-- tests/notification/notification_test.php | 248 ++++++++++------------ 3 files changed, 145 insertions(+), 168 deletions(-) diff --git a/tests/notification/base.php b/tests/notification/base.php index 5ef6fcebad..8de162a1fb 100644 --- a/tests/notification/base.php +++ b/tests/notification/base.php @@ -106,4 +106,26 @@ abstract class phpbb_tests_notification_base extends phpbb_database_test_case return new $type($this->user_loader, $this->db, $this->cache->get_driver(), $this->user, $this->auth, $this->config, $phpbb_root_path, $phpEx, 'phpbb_notification_types', 'phpbb_notifications', 'phpbb_user_notifications'); } + + protected function assert_notifications($expected, $options = array()) + { + $notifications = $this->notifications->load_notifications(array_merge(array( + 'count_unread' => true, + 'order_by' => 'notification_time', + 'order_dir' => 'ASC', + ), $options)); + + $this->assertEquals(sizeof($expected), $notifications['unread_count']); + + $i = 0; + foreach ($notifications['notifications'] as $notification) + { + foreach ($expected[$i] as $key => $value) + { + $this->assertEquals($value, $notification->$key, $i . ' ' . $key); + } + + $i++; + } + } } diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index d61c4adf38..3606a6455c 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -53,41 +53,28 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas $group_id = false; group_create($group_id, GROUP_OPEN, 'test', 'test group', array()); - // Add user 1 as group leader + // Add user 2 as group leader group_user_add($group_id, 2, false, false, false, true, false); - // Add user 2 as pending + // Add user 3 as pending group_user_add($group_id, 3, false, false, false, false, true); - $notifications = $this->notifications->load_notifications(array( - 'count_unread' => true, - 'user_id' => 2, - )); - - $expected = array( + $this->assert_notifications( array( - 'item_id' => 3, // user_id of requesting join - 'item_parent_id' => $group_id, - 'user_id' => 2, - 'notification_read' => 0, - 'notification_data' => array( - 'group_name' => 'test', + // user 3 pending notification + array( + 'item_id' => 3, // user_id of requesting join + 'item_parent_id' => $group_id, + 'user_id' => 2, + 'notification_read' => 0, + 'notification_data' => array( + 'group_name' => 'test', + ), ), ), + array( + 'user_id' => 2, + ) ); - - $this->assertEquals(sizeof($expected), $notifications['unread_count']); - - $i = 0; - foreach ($notifications['notifications'] as $notification) - { - foreach ($expected[$i] as $notification_data) - { - $this->assertEquals($value, $notification->$key, $key . ' ' . $i); - } - - $i++; - } - } } diff --git a/tests/notification/notification_test.php b/tests/notification/notification_test.php index b8dc9a9042..e1788e8670 100644 --- a/tests/notification/notification_test.php +++ b/tests/notification/notification_test.php @@ -160,80 +160,65 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'post_time' => 1349413326, )); - $notifications = $this->notifications->load_notifications(array( - 'count_unread' => true, - )); - - $expected = array( + $this->assert_notifications( array( - 'item_id' => 1, - 'item_parent_id' => 1, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413321, - 'notification_data' => array(), - ), - array( - 'item_id' => 2, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413322, - 'notification_data' => array(), - ), - array( - 'item_id' => 3, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413323, - 'notification_data' => array(), - ), - array( - 'item_id' => 4, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413324, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'post_username' => '', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', + array( + 'item_id' => 1, + 'item_parent_id' => 1, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413321, + 'notification_data' => array(), ), - ), - array( - 'item_id' => 5, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413325, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'post_username' => '', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', + array( + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413322, + 'notification_data' => array(), ), - ), + array( + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413323, + 'notification_data' => array(), + ), + array( + 'item_id' => 4, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413324, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + array( + 'item_id' => 5, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413325, + 'notification_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']); - - $i = 0; - foreach ($notifications['notifications'] as $notification) - { - foreach ($expected[$i] as $notification_data) - { - $this->assertEquals($value, $notification->$key, $key . ' ' . $i); - } - - $i++; - } - // Now test updating ------------------------------- $this->notifications->update_notifications('test', array( @@ -258,80 +243,63 @@ class phpbb_notification_test extends phpbb_tests_notification_base 'forum_name' => 'Your second forum', // change forum_name )); - $notifications = $this->notifications->load_notifications(array( - 'count_unread' => true, - )); - - $expected = array( + $this->assert_notifications( array( - 'item_id' => 1, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413321, - 'notification_data' => array(), - ), - array( - 'item_id' => 2, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413322, - 'notification_data' => array(), - ), - array( - 'notification_type_id' => 4, - 'item_id' => 3, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1234, - 'notification_data' => array(), - ), - array( - 'item_id' => 4, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413324, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title', - 'post_subject' => 'Re: test-title', - 'post_username' => '', - 'forum_id' => 2, - 'forum_name' => 'Your first forum', + array( + 'item_id' => 3, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1234, + 'notification_data' => array(), ), - ), - array( - 'item_id' => 5, - 'item_parent_id' => 2, - 'user_id' => 0, - 'notification_read' => 0, - 'notification_time' => 1349413325, - 'notification_data' => array( - 'poster_id' => 2, - 'topic_title' => 'test-title2', - 'post_subject' => 'Re: test-title2', - 'post_username' => '', - 'forum_id' => 3, - 'forum_name' => 'Your second forum', + array( + 'item_id' => 1, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413321, + 'notification_data' => array(), ), - ), + array( + 'item_id' => 2, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413322, + 'notification_data' => array(), + ), + array( + 'item_id' => 4, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413324, + 'notification_data' => array( + 'poster_id' => 2, + 'topic_title' => 'test-title', + 'post_subject' => 'Re: test-title', + 'post_username' => '', + 'forum_id' => 2, + 'forum_name' => 'Your first forum', + ), + ), + array( + 'item_id' => 5, + 'item_parent_id' => 2, + 'user_id' => 0, + 'notification_read' => 0, + 'notification_time' => 1349413325, + 'notification_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']); - - $i = 0; - foreach ($notifications['notifications'] as $notification) - { - foreach ($expected[$i] as $notification_data) - { - $this->assertEquals($value, $notification->$key, $key . ' ' . $i); - } - - $i++; - } - } } From 97204e432b8ff1c91294169d6fc0d822ef180bf1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 27 Jul 2013 19:32:51 -0500 Subject: [PATCH 18/39] [ticket/11745] Add test for group request approved PHPBB3-11745 --- tests/notification/group_request_test.php | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/notification/group_request_test.php b/tests/notification/group_request_test.php index 3606a6455c..368e4ae973 100644 --- a/tests/notification/group_request_test.php +++ b/tests/notification/group_request_test.php @@ -22,6 +22,7 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas parent::get_notification_types(), array( 'group_request', + 'group_request_approved', ) ); } @@ -76,5 +77,33 @@ class phpbb_notification_group_request_test extends phpbb_tests_notification_bas 'user_id' => 2, ) ); + + // Approve user 3 joining the group + group_user_attributes('approve', $group_id, array(3)); + + // user 3 pending notification should have been deleted + $this->assert_notifications( + array(), + array( + 'user_id' => 2, + ) + ); + + $this->assert_notifications( + array( + // user 3 approved notification + array( + 'item_id' => $group_id, // user_id of requesting join + 'user_id' => 3, + 'notification_read' => 0, + 'notification_data' => array( + 'group_name' => 'test', + ), + ), + ), + array( + 'user_id' => 3, + ) + ); } } From a79e3b341578696c1dd6720d7589b10a3226dbb5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 27 Jul 2013 20:37:50 -0500 Subject: [PATCH 19/39] [ticket/11373] Prune old read notifications with cron PHPBB3-11373 --- phpBB/includes/acp/acp_board.php | 1 + phpBB/language/en/acp/board.php | 2 + .../cron/task/core/prune_notifications.php | 75 +++++++++++++++++++ .../migration/data/310/notifications_cron.php | 25 +++++++ phpBB/phpbb/notification/manager.php | 12 +-- 5 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 phpBB/phpbb/cron/task/core/prune_notifications.php create mode 100644 phpBB/phpbb/db/migration/data/310/notifications_cron.php diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index 12e2a1bf72..9508b03d1e 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -328,6 +328,7 @@ class acp_board 'session_length' => array('lang' => 'SESSION_LENGTH', 'validate' => 'int:60:9999999999', 'type' => 'number:60:9999999999', 'explain' => true, 'append' => ' ' . $user->lang['SECONDS']), 'active_sessions' => array('lang' => 'LIMIT_SESSIONS', 'validate' => 'int:0:9999', 'type' => 'number:0:9999', 'explain' => true), 'load_online_time' => array('lang' => 'ONLINE_LENGTH', 'validate' => 'int:0:999', 'type' => 'number:0:999', 'explain' => true, 'append' => ' ' . $user->lang['MINUTES']), + 'read_notification_expire_days' => array('lang' => 'READ_NOTIFICATION_EXPIRE_DAYS', 'validate' => 'int:0', 'type' => 'number:0', 'explain' => true, 'append' => ' ' . $user->lang['DAYS']), 'legend2' => 'GENERAL_OPTIONS', 'load_notifications' => array('lang' => 'LOAD_NOTIFICATIONS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index ce15dfefb4..a07150eb11 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -367,6 +367,8 @@ $lang = array_merge($lang, array( 'LOAD_JQUERY_CDN_EXPLAIN' => 'If this setting is enabled, jQuery will be served from Google’s AJAX API CDN instead of the copy included with phpBB on your server. If the CDN fails, phpBB will attempt to fall back to the copy included with phpBB.', 'LOAD_USER_ACTIVITY' => 'Show user’s activity', 'LOAD_USER_ACTIVITY_EXPLAIN' => 'Displays active topic/forum in user profiles and user control panel. It is recommended to disable this on boards with more than one million posts.', + 'READ_NOTIFICATION_EXPIRE_DAYS' => 'Read Notification Expiration', + 'READ_NOTIFICATION_EXPIRE_DAYS_EXPLAIN' => 'Number of days that will elapse before a read notification will automatically be deleted. Set this value to 0 to make notifications permanent.', 'RECOMPILE_STYLES' => 'Recompile stale style components', 'RECOMPILE_STYLES_EXPLAIN' => 'Check for updated style components on filesystem and recompile.', 'YES_ANON_READ_MARKING' => 'Enable topic marking for guests', diff --git a/phpBB/phpbb/cron/task/core/prune_notifications.php b/phpBB/phpbb/cron/task/core/prune_notifications.php new file mode 100644 index 0000000000..6d38091e9f --- /dev/null +++ b/phpBB/phpbb/cron/task/core/prune_notifications.php @@ -0,0 +1,75 @@ +config = $config; + $this->notification_manager = $notification_manager; + } + + /** + * Runs this cron task. + * + * @return null + */ + public function run() + { + // time minus expire days in seconds + $timestamp = time() - ($this->config['read_notification_expire_days'] * 60 * 60 * 24); + $this->notification_manager->prune_notifications($timestamp); + } + + /** + * Returns whether this cron task can run, given current board configuration.= + * + * @return bool + */ + public function is_runnable() + { + return (bool) $this->config['read_notification_expire_days']; + } + + /** + * Returns whether this cron task should run now, because enough time + * has passed since it was last run. + * + * The interval between prune notifications is specified in board + * configuration. + * + * @return bool + */ + public function should_run() + { + return $this->config['read_notification_last_gc'] < time() - $this->config['read_notification_gc']; + } +} diff --git a/phpBB/phpbb/db/migration/data/310/notifications_cron.php b/phpBB/phpbb/db/migration/data/310/notifications_cron.php new file mode 100644 index 0000000000..454628e50e --- /dev/null +++ b/phpBB/phpbb/db/migration/data/310/notifications_cron.php @@ -0,0 +1,25 @@ +notifications_table . ' - WHERE notification_time < ' . (int) $timestamp; + WHERE notification_time < ' . (int) $timestamp . + (($only_read) ? ' AND notification_read = 1' : ''); $this->db->sql_query($sql); } @@ -834,12 +836,12 @@ class phpbb_notification_manager protected function load_object($object_name) { $object = $this->phpbb_container->get($object_name); - + if (method_exists($object, 'set_notification_manager')) { $object->set_notification_manager($this); } - + return $object; } From 28daa60e9e7438e663d6579a0dbbd834dba245b5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 28 Jul 2013 21:10:17 -0500 Subject: [PATCH 20/39] [ticket/11744] Inheritdoc PHPBB3-11744 --- phpBB/phpbb/log/null.php | 61 +++++----------------------------------- 1 file changed, 7 insertions(+), 54 deletions(-) diff --git a/phpBB/phpbb/log/null.php b/phpBB/phpbb/log/null.php index 9837058ef5..14b5f65eec 100644 --- a/phpBB/phpbb/log/null.php +++ b/phpBB/phpbb/log/null.php @@ -23,12 +23,7 @@ if (!defined('IN_PHPBB')) class phpbb_log_null implements phpbb_log_interface { /** - * This function returns the state of the log system. - * - * @param string $type The log type we want to check. Empty to get - * global log status. - * - * @return bool True if log for the type is enabled + * {@inheritdoc} */ public function is_enabled($type = '') { @@ -36,46 +31,21 @@ class phpbb_log_null implements phpbb_log_interface } /** - * Disable log - * - * This function allows disabling the log system or parts of it, for this - * page call. When add_log is called and the type is disabled, - * the log will not be added to the database. - * - * @param mixed $type The log type we want to disable. Empty to - * disable all logs. Can also be an array of types. - * - * @return null + * {@inheritdoc} */ public function disable($type = '') { } /** - * Enable log - * - * This function allows re-enabling the log system. - * - * @param mixed $type The log type we want to enable. Empty to - * enable all logs. Can also be an array of types. - * - * @return null + * {@inheritdoc} */ public function enable($type = '') { } /** - * Adds a log entry to the database - * - * @param string $mode The mode defines which log_type is used and from which log the entry is retrieved - * @param int $user_id User ID of the user - * @param string $log_ip IP address of the user - * @param string $log_operation Name of the operation - * @param int $log_time Timestamp when the log entry was added, if empty time() will be used - * @param array $additional_data More arguments can be added, depending on the log_type - * - * @return int|bool Returns the log_id, if the entry was added to the database, false otherwise. + * {@inheritdoc} */ public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array()) { @@ -83,20 +53,7 @@ class phpbb_log_null implements phpbb_log_interface } /** - * Grab the logs from the database - * - * @param string $mode The mode defines which log_type is used and ifrom which log the entry is retrieved - * @param bool $count_logs Shall we count all matching log entries? - * @param int $limit Limit the number of entries that are returned - * @param int $offset Offset when fetching the log entries, f.e. when paginating - * @param mixed $forum_id Restrict the log entries to the given forum_id (can also be an array of forum_ids) - * @param int $topic_id Restrict the log entries to the given topic_id - * @param int $user_id Restrict the log entries to the given user_id - * @param int $log_time Only get log entries newer than the given timestamp - * @param string $sort_by SQL order option, e.g. 'l.log_time DESC' - * @param string $keywords Will only return log entries that have the keywords in log_operation or log_data - * - * @return array The result array with the logs + * {@inheritdoc} */ public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') { @@ -104,9 +61,7 @@ class phpbb_log_null implements phpbb_log_interface } /** - * Get total log count - * - * @return int Returns the number of matching logs from the last call to get_logs() + * {@inheritdoc} */ public function get_log_count() { @@ -114,9 +69,7 @@ class phpbb_log_null implements phpbb_log_interface } /** - * Get offset of the last valid page - * - * @return int Returns the offset of the last valid page from the last call to get_logs() + * {@inheritdoc} */ public function get_valid_offset() { From cbe72ab14b528ebd986dc6fdc1d8b247ebba0df8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 28 Jul 2013 21:15:58 -0500 Subject: [PATCH 21/39] [ticket/11744] Cast to int PHPBB3-11744 --- phpBB/phpbb/notification/type/group_request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/notification/type/group_request.php b/phpBB/phpbb/notification/type/group_request.php index 96015783fb..490b9e16a3 100644 --- a/phpBB/phpbb/notification/type/group_request.php +++ b/phpBB/phpbb/notification/type/group_request.php @@ -82,7 +82,7 @@ class phpbb_notification_type_group_request extends phpbb_notification_type_base $user_ids = array(); while ($row = $this->db->sql_fetchrow($result)) { - $user_ids[] = $row['user_id']; + $user_ids[] = (int) $row['user_id']; } $this->db->sql_freeresult($result); From 520027c8b7975e22efd2f687dc14587a01332103 Mon Sep 17 00:00:00 2001 From: brunoais Date: Sun, 4 Aug 2013 12:06:26 +0100 Subject: [PATCH 22/39] [ticket/11637] generate_text_for_display on search.php sub-task of ticket PHPBB3-11635: find and fix all bypasses of generate_text_for_* PHPBB3-11639 --- phpBB/search.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/phpBB/search.php b/phpBB/search.php index 7d20d8d4a2..d0c9df9451 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -962,14 +962,8 @@ if ($keywords || $author || $author_id || $search_id || $submit) } else { - // Second parse bbcode here - if ($row['bbcode_bitfield']) - { - $bbcode->bbcode_second_pass($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield']); - } - - $row['post_text'] = bbcode_nl2br($row['post_text']); - $row['post_text'] = smiley_text($row['post_text']); + $parse_flags = ($row['bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES; + $row['post_text'] = generate_text_for_display($row['post_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $parse_flags, false); if (!empty($attachments[$row['post_id']])) { From 0a7508439f20b358f1e51d3f2d8105903588e430 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 28 Aug 2013 12:39:57 -0500 Subject: [PATCH 23/39] [ticket/11373] Use inheritdoc PHPBB3-11373 --- .../phpbb/cron/task/core/prune_notifications.php | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/phpBB/phpbb/cron/task/core/prune_notifications.php b/phpBB/phpbb/cron/task/core/prune_notifications.php index 6d38091e9f..296c0ae64f 100644 --- a/phpBB/phpbb/cron/task/core/prune_notifications.php +++ b/phpBB/phpbb/cron/task/core/prune_notifications.php @@ -38,9 +38,7 @@ class phpbb_cron_task_core_prune_notifications extends phpbb_cron_task_base } /** - * Runs this cron task. - * - * @return null + * {@inheritdoc} */ public function run() { @@ -50,9 +48,7 @@ class phpbb_cron_task_core_prune_notifications extends phpbb_cron_task_base } /** - * Returns whether this cron task can run, given current board configuration.= - * - * @return bool + * {@inheritdoc} */ public function is_runnable() { @@ -60,13 +56,7 @@ class phpbb_cron_task_core_prune_notifications extends phpbb_cron_task_base } /** - * Returns whether this cron task should run now, because enough time - * has passed since it was last run. - * - * The interval between prune notifications is specified in board - * configuration. - * - * @return bool + * {@inheritdoc} */ public function should_run() { From 62e81d174d9d3dbd78baea36425720ed0fdaffb1 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 29 Aug 2013 09:19:14 -0500 Subject: [PATCH 24/39] [ticket/11816] Fix define/loop checks in IF statements containing parenthesis PHPBB3-11816 --- phpBB/phpbb/template/twig/lexer.php | 8 ++++---- tests/template/template_test.php | 2 +- tests/template/templates/define.html | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 3534311b7a..719066b659 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -223,13 +223,13 @@ class phpbb_template_twig_lexer extends Twig_Lexer { $inner = $matches[2]; // Replace $TEST with definition.TEST - $inner = preg_replace('#\s\$([a-zA-Z_0-9]+)#', ' definition.$1', $inner); + $inner = preg_replace('#(\s\(?!?)\$([a-zA-Z_0-9]+)#', '$1definition.$2', $inner); // Replace .foo with loops.foo|length - $inner = preg_replace('#\s\.([a-zA-Z_0-9]+)([^a-zA-Z_0-9\.])#', ' loops.$1|length$2', $inner); + $inner = preg_replace('#(\s\(?!?)\.([a-zA-Z_0-9]+)([^a-zA-Z_0-9\.])#', '$1loops.$2|length$3', $inner); // Replace .foo.bar with foo.bar|length - $inner = preg_replace('#\s\.([a-zA-Z_0-9\.]+)([^a-zA-Z_0-9\.])#', ' $1|length$2', $inner); + $inner = preg_replace('#(\s\(?!?)\.([a-zA-Z_0-9\.]+)([^a-zA-Z_0-9\.])#', '$1$2|length$3', $inner); return ""; }; @@ -237,7 +237,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer // Replace our "div by" with Twig's divisibleby (Twig does not like test names with spaces) $code = preg_replace('# div by ([0-9]+)#', ' divisibleby($1)', $code); - return preg_replace_callback('##', $callback, $code); + return preg_replace_callback('##', $callback, $code); } /** diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0a6b680100..0473218353 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -151,7 +151,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), - "xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", + "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", ), array( 'define_advanced.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index 66e874ca63..12842ad387 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -7,6 +7,9 @@ $VALUE != 'abc' $VALUE == 'abc' + +($VALUE == 'abc') + {$INCLUDED_VALUE} {$VALUE} From 5e86f5687b30397c0e520fd32a9fc92b7e155a16 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 2 Sep 2013 11:25:36 -0500 Subject: [PATCH 25/39] [ticket/11727] Template loader support for safe directories to load files from PHPBB3-11727 --- phpBB/phpbb/template/twig/loader.php | 150 +++++++++++++++++++++++++++ phpBB/phpbb/template/twig/twig.php | 22 ++-- 2 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 phpBB/phpbb/template/twig/loader.php diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php new file mode 100644 index 0000000000..997c05f57c --- /dev/null +++ b/phpBB/phpbb/template/twig/loader.php @@ -0,0 +1,150 @@ +safe_directories = array(); + + if (!empty($directories)) + { + foreach ($directories as $directory) + { + $this->addSafeDirectory($directory); + } + } + + return $this; + } + + /** + * Add safe directory + * + * @param string $directory Directory that should be added + * @return Twig_Loader_Filesystem + */ + public function addSafeDirectory($directory) + { + $directory = phpbb_realpath($directory); + + if ($directory !== false) + { + $this->safe_directories[] = $directory; + } + + return $this; + } + + /** + * Get current safe directories + * + * @return array + */ + public function getSafeDirectories() + { + return $this->safe_directories; + } + + /** + * Override for parent::validateName() + * + * This is done because we added support for safe directories, and when Twig + * findTemplate() is called, validateName() is called first, which would + * always throw an exception if the file is outside of the configured + * template directories. + */ + protected function validateName($name) + { + return; + } + + /** + * Find the template + * + * Override for Twig_Loader_Filesystem::findTemplate to add support + * for loading from safe directories. + */ + protected function findTemplate($name) + { + $name = (string) $name; + + // normalize name + $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')); + + // If this is in the cache we can skip the entire process below + // as it should have already been validated + if (isset($this->cache[$name])) { + return $this->cache[$name]; + } + + // First, find the template name. The override above of validateName + // causes the validateName process to be skipped for this call + $file = parent::findTemplate($name); + + try + { + // Try validating the name (which may throw an exception) + parent::validateName($name); + } + catch (Twig_Error_Loader $e) + { + if (strpos($e->getRawMessage(), 'Looks like you try to load a template outside configured directories') === 0) + { + // Ok, so outside of the configured template directories, we + // can now check if we're within a "safe" directory + + // Find the real path of the directory the file is in + $directory = phpbb_realpath(dirname($file)); + + if ($directory === false) + { + // Some sort of error finding the actual path, must throw the exception + throw $e; + } + + foreach ($this->safe_directories as $safe_directory) + { + if (strpos($directory, $safe_directory) === 0) + { + // The directory being loaded is below a directory + // that is "safe". We're good to load it! + return $file; + } + } + } + + // Not within any safe directories + throw $e; + } + + // No exception from validateName, safe to load. + return $file; + } +} diff --git a/phpBB/phpbb/template/twig/twig.php b/phpBB/phpbb/template/twig/twig.php index 1ed89d3ccc..5746cc64a3 100644 --- a/phpBB/phpbb/template/twig/twig.php +++ b/phpBB/phpbb/template/twig/twig.php @@ -91,7 +91,7 @@ class phpbb_template_twig extends phpbb_template_base $this->cachepath = $phpbb_root_path . 'cache/twig/'; // Initiate the loader, __main__ namespace paths will be setup later in set_style_names() - $loader = new Twig_Loader_Filesystem(''); + $loader = new phpbb_template_twig_loader(''); $this->twig = new phpbb_template_twig_environment( $this->config, @@ -181,11 +181,15 @@ class phpbb_template_twig extends phpbb_template_base { foreach ($names as $name) { - $path = $this->phpbb_root_path . trim($directory, '/') . "/{$name}/template/"; + $path = $this->phpbb_root_path . trim($directory, '/') . "/{$name}/"; + $template_path = $path . 'template/'; - if (is_dir($path)) + if (is_dir($template_path)) { - $paths[] = $path; + // Add the base style directory as a safe directory + $this->twig->getLoader()->addSafeDirectory($path); + + $paths[] = $template_path; } } } @@ -233,11 +237,15 @@ class phpbb_template_twig extends phpbb_template_base foreach ($names as $style_name) { - $ext_style_path = $ext_path . 'styles/' . $style_name . '/template'; + $ext_style_path = $ext_path . 'styles/' . $style_name . '/'; + $ext_style_template_path = $ext_style_path . 'template/'; - if (is_dir($ext_style_path)) + if (is_dir($ext_style_template_path)) { - $paths[] = $ext_style_path; + // Add the base style directory as a safe directory + $this->twig->getLoader()->addSafeDirectory($ext_style_path); + + $paths[] = $ext_style_template_path; } } From 423357581415c7c10ed0ac51284014e839881bac Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 2 Sep 2013 13:54:42 -0500 Subject: [PATCH 26/39] [ticket/11822] Use namespace lookup order for asset loading PHPBB3-11822 --- phpBB/phpbb/template/twig/environment.php | 35 +++++++++++++++++++ .../phpbb/template/twig/node/includeasset.php | 4 +-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/template/twig/environment.php b/phpBB/phpbb/template/twig/environment.php index b60cd72325..9a40dc2b15 100644 --- a/phpBB/phpbb/template/twig/environment.php +++ b/phpBB/phpbb/template/twig/environment.php @@ -137,4 +137,39 @@ class phpbb_template_twig_environment extends Twig_Environment return parent::loadTemplate($name, $index); } } + + /** + * Finds a template by name. + * + * @param string $name The template name + * @return string + */ + public function findTemplate($name) + { + if (strpos($name, '@') === false) + { + foreach ($this->getNamespaceLookUpOrder() as $namespace) + { + try + { + if ($namespace === '__main__') + { + return parent::getLoader()->getCacheKey($name); + } + + return parent::getLoader()->getCacheKey('@' . $namespace . '/' . $name); + } + catch (Twig_Error_Loader $e) + { + } + } + + // We were unable to load any templates + throw $e; + } + else + { + return parent::getLoader()->getCacheKey($name); + } + } } diff --git a/phpBB/phpbb/template/twig/node/includeasset.php b/phpBB/phpbb/template/twig/node/includeasset.php index 1cab416c79..0808e2b10e 100644 --- a/phpBB/phpbb/template/twig/node/includeasset.php +++ b/phpBB/phpbb/template/twig/node/includeasset.php @@ -40,10 +40,10 @@ abstract class phpbb_template_twig_node_includeasset extends Twig_Node ->write("\$local_file = \$this->getEnvironment()->get_phpbb_root_path() . \$asset_path;\n") ->write("if (!file_exists(\$local_file)) {\n") ->indent() - ->write("\$local_file = \$this->getEnvironment()->getLoader()->getCacheKey(\$asset_path);\n") + ->write("\$local_file = \$this->getEnvironment()->findTemplate(\$asset_path);\n") ->write("\$asset->set_path(\$local_file, true);\n") ->outdent() - ->write("\$asset->add_assets_version({$config['assets_version']});\n") + ->write("\$asset->add_assets_version('{$config['assets_version']}');\n") ->write("\$asset_file = \$asset->get_url();\n") ->write("}\n") ->outdent() From 0c5a39a3ed382bef37005e59de66120e3cf205fa Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 2 Sep 2013 15:50:34 -0500 Subject: [PATCH 27/39] [ticket/11816] Test !$DEFINITION PHPBB3-11816 --- tests/template/template_test.php | 2 +- tests/template/templates/define.html | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 0473218353..94289842df 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -151,7 +151,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), - "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", + "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", ), array( 'define_advanced.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index 12842ad387..e96d14e813 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -10,6 +10,9 @@ $VALUE == 'abc' ($VALUE == 'abc') + +(!$DOESNT_EXIST) + {$INCLUDED_VALUE} {$VALUE} From 77845e366e8a5578ad740186cf71d75be32694bc Mon Sep 17 00:00:00 2001 From: rechosen Date: Wed, 4 Sep 2013 13:37:39 +0200 Subject: [PATCH 28/39] [ticket/11829] Use report_closed to determine status in MCP report_details Instead of using post_reported of the post or message_reported of the pm, use report_closed of the report itself to reliably determine whether this particular report is closed or not in the report_details view of the MCP. This fixes a bug where the report_details view would not show that the report shown was closed and display a "Close report" button that had no effect. PHPBB3-11829 --- phpBB/includes/mcp/mcp_pm_reports.php | 1 + phpBB/includes/mcp/mcp_reports.php | 1 + phpBB/styles/prosilver/template/mcp_post.html | 4 ++-- phpBB/styles/subsilver2/template/mcp_post.html | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index 77bc7680e6..0a33c80a90 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -166,6 +166,7 @@ class mcp_pm_reports 'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=pm_reports&mode=pm_report_details&r=' . $report_id), 'S_CAN_VIEWIP' => $auth->acl_getf_global('m_info'), 'S_POST_REPORTED' => $pm_info['message_reported'], + 'S_REPORT_CLOSED' => $report['report_closed'], 'S_USER_NOTES' => true, 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=pm_reports&mode=pm_report_details&r=' . $report_id), diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index def5422be2..b13c8b20c6 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -192,6 +192,7 @@ class mcp_reports 'S_POST_REPORTED' => $post_info['post_reported'], 'S_POST_UNAPPROVED' => !$post_info['post_approved'], 'S_POST_LOCKED' => $post_info['post_edit_locked'], + 'S_REPORT_CLOSED' => $report['report_closed'], 'S_USER_NOTES' => true, 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&f={$post_info['forum_id']}&p={$post_info['post_id']}") : '', diff --git a/phpBB/styles/prosilver/template/mcp_post.html b/phpBB/styles/prosilver/template/mcp_post.html index f8403ffccd..11f63a3ea2 100644 --- a/phpBB/styles/prosilver/template/mcp_post.html +++ b/phpBB/styles/prosilver/template/mcp_post.html @@ -13,7 +13,7 @@

{L_REPORT_REASON}: {REPORT_REASON_TITLE}

{L_REPORTED} {L_POST_BY_AUTHOR} {REPORTER_FULL} « {REPORT_DATE}

- +

{L_REPORT_CLOSED}

@@ -31,7 +31,7 @@
- +   diff --git a/phpBB/styles/subsilver2/template/mcp_post.html b/phpBB/styles/subsilver2/template/mcp_post.html index 6fb68ca680..d026ac22c0 100644 --- a/phpBB/styles/subsilver2/template/mcp_post.html +++ b/phpBB/styles/subsilver2/template/mcp_post.html @@ -28,7 +28,7 @@ - {L_REPORT_CLOSED}   + {L_REPORT_CLOSED}   From 3dfad1f01e61c80fe89721d7bd826fd77f79cf9a Mon Sep 17 00:00:00 2001 From: rechosen Date: Fri, 6 Sep 2013 15:04:52 +0200 Subject: [PATCH 29/39] [ticket/9550] Add the core.viewtopic_post_rowset_data event to viewtopic.php To allow extra fields added to the query retrieving post data to be used for setting template variables, they need to be added to the post rowset. This commit adds the core.viewtopic_post_rowset_data event that enables extension developers to modify the post rowset when the database row is still available. PHPBB3-9550 --- phpBB/viewtopic.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index bc54a249a9..af2056fdeb 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1012,7 +1012,7 @@ while ($row = $db->sql_fetchrow($result)) } } - $rowset[$row['post_id']] = array( + $rowset_data = array( 'hide_post' => (($row['foe'] || $row['post_visibility'] == ITEM_DELETED) && ($view != 'show' || $post_id != $row['post_id'])) ? true : false, 'post_id' => $row['post_id'], @@ -1047,6 +1047,19 @@ while ($row = $db->sql_fetchrow($result)) 'foe' => $row['foe'], ); + /** + * Modify the post rowset containing data to be displayed with posts + * + * @event core.viewtopic_post_rowset_data + * @var array rowset_data Array with the rowset data for this post + * @var array row Array with original user and post data + * @since 3.1-A1 + */ + $vars = array('rowset_data', 'row'); + extract($phpbb_dispatcher->trigger_event('core.viewtopic_post_rowset_data', compact($vars))); + + $rowset[$row['post_id']] = $rowset_data; + // Define the global bbcode bitfield, will be used to load bbcodes $bbcode_bitfield = $bbcode_bitfield | base64_decode($row['bbcode_bitfield']); From 11317ef261c7811ea137d19ee38593d289ea6150 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 6 Sep 2013 09:04:40 -0500 Subject: [PATCH 30/39] [ticket/11816] !$DOESNT_EXIST test PHPBB3-11816 --- tests/template/template_test.php | 2 +- tests/template/templates/define.html | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 94289842df..b41193d59e 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -151,7 +151,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), - "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", + "xyz\nabc\n\$VALUE == 'abc'\n(\$VALUE == 'abc')\n!\$DOESNT_EXIST\n(!\$DOESNT_EXIST)\nabc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?", ), array( 'define_advanced.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index e96d14e813..a56fece912 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -10,6 +10,9 @@ $VALUE == 'abc' ($VALUE == 'abc') + +!$DOESNT_EXIST + (!$DOESNT_EXIST) From 0cb4ceabf435499df6648d357d872f5347c8862f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 9 Sep 2013 11:24:12 -0500 Subject: [PATCH 31/39] [ticket/11833] Fix bad template loop PHPBB3-11833 --- phpBB/styles/prosilver/template/mcp_notes_user.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/styles/prosilver/template/mcp_notes_user.html b/phpBB/styles/prosilver/template/mcp_notes_user.html index 1738e45045..eb954fd11d 100644 --- a/phpBB/styles/prosilver/template/mcp_notes_user.html +++ b/phpBB/styles/prosilver/template/mcp_notes_user.html @@ -88,7 +88,7 @@ {L_NO_ENTRIES} - + From 5166240d628e19ba0db13e5dc0de8153e80d4c44 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 9 Sep 2013 11:26:40 -0500 Subject: [PATCH 32/39] [ticket/11833] Prevent Twig errors from invalid template loops using BEGINELSE PHPBB3-11833 --- phpBB/phpbb/template/twig/lexer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 7ab569313c..ba822e7545 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -161,6 +161,9 @@ class phpbb_template_twig_lexer extends Twig_Lexer $subset = trim(substr($matches[2], 1, -1)); // Remove parenthesis $body = $matches[3]; + // Replace + $body = str_replace('', '{% else %}', $body); + // Is the designer wanting to call another loop in a loop? // // @@ -205,9 +208,6 @@ class phpbb_template_twig_lexer extends Twig_Lexer return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}"; }; - // Replace correctly, only needs to be done once - $code = str_replace('', '{% else %}', $code); - return preg_replace_callback('#(.+?)#s', $callback, $code); } From 8c2f73bb09dc1fa305b59c2adabdc47fd3d5afdb Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 12 Sep 2013 14:15:41 -0500 Subject: [PATCH 33/39] [ticket/11828] Fix greedy operators in lexer Use lazy operators and use stricter validation PHPBB3-11828 --- phpBB/phpbb/template/twig/lexer.php | 8 ++++---- tests/template/template_test.php | 2 +- tests/template/templates/define.html | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 7ab569313c..bd9ece57fd 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -75,7 +75,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer // Fix tokens that may have inline variables (e.g. "; }; - return preg_replace_callback('##', $callback, $code); + return preg_replace_callback('##', $callback, $code); } /** @@ -264,10 +264,10 @@ class phpbb_template_twig_lexer extends Twig_Lexer */ // Replace #', '{% DEFINE $1 %}', $code); + $code = preg_replace('##', '{% DEFINE $1 %}', $code); // Changing UNDEFINE NAME to DEFINE NAME = null to save from creating an extra token parser/node - $code = preg_replace('##', '{% DEFINE $1= null %}', $code); + $code = preg_replace('##', '{% DEFINE $1= null %}', $code); // Replace all of our variables, {$VARNAME}, with Twig style, {{ definition.VARNAME }} $code = preg_replace('#{\$([a-zA-Z0-9_\.]+)}#', '{{ definition.$1 }}', $code); diff --git a/tests/template/template_test.php b/tests/template/template_test.php index f2e3903458..e64493e59a 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -158,7 +158,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), array('test_loop' => array(array(), array(), array(), array(), array(), array(), array()), 'test' => array(array()), 'test.deep' => array(array()), 'test.deep.defines' => array(array())), array(), - "xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?\n[]", + "xyz\nabc\n\$VALUE == 'abc'abc\nbar\nbar\nabc\ntest!@#$%^&*()_-=+{}[]:;\",<.>/?\n[]|foobar|", ), array( 'define_advanced.html', diff --git a/tests/template/templates/define.html b/tests/template/templates/define.html index e6c8ef49c9..f519078a5b 100644 --- a/tests/template/templates/define.html +++ b/tests/template/templates/define.html @@ -16,3 +16,4 @@ $VALUE == 'abc' {$VALUE} [{$VALUE}] +foobar|{$TEST}| From 32b92547400c14a402f64463661ce7c1b44e81b3 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 12 Sep 2013 22:59:42 -0500 Subject: [PATCH 34/39] [ticket/11745] Correct language, coding guidelines PHPBB3-11745 --- phpBB/language/en/common.php | 2 +- phpBB/phpbb/notification/type/group_request.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 91b1f6d9d9..bd34c51bef 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -415,7 +415,7 @@ $lang = array_merge($lang, array( ), 'NOTIFICATION_BOOKMARK' => '%1$s replied to the topic "%2$s" you have bookmarked.', 'NOTIFICATION_GROUP_REQUEST' => '%1$s is requesting to join the group %2$s.', - 'NOTIFICATION_GROUP_REQUEST_APPROVED' => 'Your request to join the "%1$s" group on has been approved.', + 'NOTIFICATION_GROUP_REQUEST_APPROVED' => 'Your request to join the group %1$s has been approved.', '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".', diff --git a/phpBB/phpbb/notification/type/group_request.php b/phpBB/phpbb/notification/type/group_request.php index 96015783fb..f3918f381d 100644 --- a/phpBB/phpbb/notification/type/group_request.php +++ b/phpBB/phpbb/notification/type/group_request.php @@ -38,7 +38,8 @@ class phpbb_notification_type_group_request extends phpbb_notification_type_base public function is_available() { // Leader of any groups? - $sql = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' + $sql = 'SELECT group_id + FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . (int) $this->user->data['user_id'] . ' AND group_leader = 1'; $result = $this->db->sql_query_limit($sql, 1); @@ -74,7 +75,8 @@ class phpbb_notification_type_group_request extends phpbb_notification_type_base 'ignore_users' => array(), ), $options); - $sql = 'SELECT user_id FROM ' . USER_GROUP_TABLE . ' + $sql = 'SELECT user_id + FROM ' . USER_GROUP_TABLE . ' WHERE group_leader = 1 AND group_id = ' . (int) $group['group_id']; $result = $this->db->sql_query($sql); From 088dfc120003c2a44f6f8a2de36b39819a5332ab Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 12 Sep 2013 23:32:08 -0500 Subject: [PATCH 35/39] [ticket/11727] Fix indentation PHPBB3-11727 --- phpBB/phpbb/template/twig/loader.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php index 997c05f57c..8bf9adfbbe 100644 --- a/phpBB/phpbb/template/twig/loader.php +++ b/phpBB/phpbb/template/twig/loader.php @@ -91,18 +91,18 @@ class phpbb_template_twig_loader extends Twig_Loader_Filesystem * Override for Twig_Loader_Filesystem::findTemplate to add support * for loading from safe directories. */ - protected function findTemplate($name) - { - $name = (string) $name; + protected function findTemplate($name) + { + $name = (string) $name; - // normalize name - $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')); + // normalize name + $name = preg_replace('#/{2,}#', '/', strtr($name, '\\', '/')); // If this is in the cache we can skip the entire process below // as it should have already been validated - if (isset($this->cache[$name])) { - return $this->cache[$name]; - } + if (isset($this->cache[$name])) { + return $this->cache[$name]; + } // First, find the template name. The override above of validateName // causes the validateName process to be skipped for this call @@ -110,7 +110,7 @@ class phpbb_template_twig_loader extends Twig_Loader_Filesystem try { - // Try validating the name (which may throw an exception) + // Try validating the name (which may throw an exception) parent::validateName($name); } catch (Twig_Error_Loader $e) From 288649dd5ee71596637ede27b5c0487f5f737e84 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 12 Sep 2013 23:32:45 -0500 Subject: [PATCH 36/39] [ticket/11727] Fix indentation PHPBB3-11727 --- phpBB/phpbb/template/twig/loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/template/twig/loader.php b/phpBB/phpbb/template/twig/loader.php index 8bf9adfbbe..0829e519f7 100644 --- a/phpBB/phpbb/template/twig/loader.php +++ b/phpBB/phpbb/template/twig/loader.php @@ -110,7 +110,7 @@ class phpbb_template_twig_loader extends Twig_Loader_Filesystem try { - // Try validating the name (which may throw an exception) + // Try validating the name (which may throw an exception) parent::validateName($name); } catch (Twig_Error_Loader $e) From 42884546cc743cc83f8153b7cc889381b0a69077 Mon Sep 17 00:00:00 2001 From: rechosen Date: Fri, 13 Sep 2013 12:05:20 +0200 Subject: [PATCH 37/39] [ticket/11843] The twig lexer fixes DEFINE variables with underscores again https://github.com/phpbb/phpbb3/pull/1708 accidentally stopped the twig lexer from fixing DEFINE variables with underscores in them. This commit restores that functionality. PHPBB3-11843 --- phpBB/phpbb/template/twig/lexer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/phpbb/template/twig/lexer.php b/phpBB/phpbb/template/twig/lexer.php index 8b72a06642..16a693cd7c 100644 --- a/phpBB/phpbb/template/twig/lexer.php +++ b/phpBB/phpbb/template/twig/lexer.php @@ -75,7 +75,7 @@ class phpbb_template_twig_lexer extends Twig_Lexer // Fix tokens that may have inline variables (e.g. + + From 658f6e204510b328509a0387eb9711617fdc3bee Mon Sep 17 00:00:00 2001 From: rechosen Date: Fri, 13 Sep 2013 13:48:00 +0200 Subject: [PATCH 39/39] [ticket/11843] Added newlines and included numbers in the DEFINE vars test Per suggestion of nickvergessen, I added newlines in the DEFINE variables with underscores test. Now if the test fails, it's easier to spot which part is failing. Also added a test for DEFINE variables containing numbers. PHPBB3-11843 --- tests/template/template_test.php | 2 +- tests/template/templates/include_define_variable.html | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/template/template_test.php b/tests/template/template_test.php index c28c7a70bc..2cca20f4c2 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -237,7 +237,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array('VARIABLE' => 'variable.html'), array(), array(), - 'variable.htmlvariable.html', + "variable.html\nvariable.html\nvariable.html", ), array( 'include_loop_define.html', diff --git a/tests/template/templates/include_define_variable.html b/tests/template/templates/include_define_variable.html index fceeebf5df..6052657c97 100644 --- a/tests/template/templates/include_define_variable.html +++ b/tests/template/templates/include_define_variable.html @@ -1,4 +1,8 @@ + + + +