From e7e0ab9d0b33121e38a236879fcca417072140f6 Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Mon, 17 May 2010 12:12:00 -0500 Subject: [PATCH 001/645] [feature/prune-users] Rework user_delete() functions_user.php user_delete now uses fewer queries to delete a set of users of size > 1 by accepting an array of users rather than a single user at a time. This required changing the third parameter, however the function retains its former behavior with the old-style parameters. PHPBB3-9622 --- phpBB/includes/acp/acp_inactive.php | 5 +- phpBB/includes/acp/acp_prune.php | 5 +- phpBB/includes/functions_user.php | 279 +++++++++++++++------------- 3 files changed, 156 insertions(+), 133 deletions(-) diff --git a/phpBB/includes/acp/acp_inactive.php b/phpBB/includes/acp/acp_inactive.php index e4fb695a11..833727084f 100644 --- a/phpBB/includes/acp/acp_inactive.php +++ b/phpBB/includes/acp/acp_inactive.php @@ -157,10 +157,7 @@ class acp_inactive trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING); } - foreach ($mark as $user_id) - { - user_delete('retain', $user_id, $user_affected[$user_id]); - } + user_delete('retain', $mark, true); add_log('admin', 'LOG_INACTIVE_' . strtoupper($action), implode(', ', $user_affected)); } diff --git a/phpBB/includes/acp/acp_prune.php b/phpBB/includes/acp/acp_prune.php index 6120c15d68..99bec29d6d 100644 --- a/phpBB/includes/acp/acp_prune.php +++ b/phpBB/includes/acp/acp_prune.php @@ -265,10 +265,7 @@ class acp_prune } else { - foreach ($user_ids as $user_id) - { - user_delete('retain', $user_id, $usernames[$user_id]); - } + user_delete('retain', $user_ids, true); $l_log = 'LOG_PRUNE_USER_DEL_ANON'; } diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 317578cd54..0886e8aabf 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -330,20 +330,32 @@ function user_add($user_row, $cp_data = false) /** * Remove User +* @param $mode Either 'retain' or 'remove' */ -function user_delete($mode, $user_id, $post_username = false) +function user_delete($mode, $user_ids, $retain_username = true) { global $cache, $config, $db, $user, $auth; global $phpbb_root_path, $phpEx; + $db->sql_transaction('begin'); + + $user_rows = array(); + if (!is_array($user_ids)) + { + $user_ids = array($user_ids); + } + $sql = 'SELECT * FROM ' . USERS_TABLE . ' - WHERE user_id = ' . $user_id; + WHERE ' . $db->sql_in_set('user_id', $user_ids); $result = $db->sql_query($sql); - $user_row = $db->sql_fetchrow($result); + while ($row = $db->sql_fetchrow($result)) + { + $user_rows[$row['user_id']] = $row; + } $db->sql_freeresult($result); - if (!$user_row) + if (!$user_rows) { return false; } @@ -351,7 +363,8 @@ function user_delete($mode, $user_id, $post_username = false) // Before we begin, we will remove the reports the user issued. $sql = 'SELECT r.post_id, p.topic_id FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p - WHERE r.user_id = ' . $user_id . ' + WHERE ' . $db->sql_in_set('r.user_id', $user_ids) . //r.user_id = ' . $user_id . ' + ' AND p.post_id = r.post_id'; $result = $db->sql_query($sql); @@ -405,135 +418,157 @@ function user_delete($mode, $user_id, $post_username = false) } // Remove reports - $db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE user_id = ' . $user_id); + $db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE ' . $db->sql_in_set('user_id', $user_ids)); - if ($user_row['user_avatar'] && $user_row['user_avatar_type'] == AVATAR_UPLOAD) + // Some things need to be done in the loop (if the query changes based + // on which user is currently being deleted) + $added_guest_posts = 0; + foreach ($user_rows as $user_id => $user_row) { - avatar_delete('user', $user_row); + if ($user_row['user_avatar'] && $user_row['user_avatar_type'] == AVATAR_UPLOAD) + { + avatar_delete('user', $user_row); + } + + // Decrement number of users if this user is active + if ($user_row['user_type'] != USER_INACTIVE && $user_row['user_type'] != USER_IGNORE) + { + set_config_count('num_users', -1, true); + } + + switch ($mode) + { + case 'retain': + if ($retain_username === false) + { + $post_username = $user->lang['GUEST']; + } + else + { + $post_username = $user_row['username']; + } + + // If the user is inactive and newly registered we assume no posts from the user, and save the queries + if ($user_row['user_type'] == USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_REGISTER && !$user_row['user_posts']) + { + } + else + { + // When we delete these users and retain the posts, we must assign all the data to the guest user + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET forum_last_poster_id = ' . ANONYMOUS . ", forum_last_poster_name = '" . $db->sql_escape($post_username) . "', forum_last_poster_colour = '' + WHERE forum_last_poster_id = $user_id"; + $db->sql_query($sql); + + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET poster_id = ' . ANONYMOUS . ", post_username = '" . $db->sql_escape($post_username) . "' + WHERE poster_id = $user_id"; + $db->sql_query($sql); + + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_name = '" . $db->sql_escape($post_username) . "', topic_first_poster_colour = '' + WHERE topic_poster = $user_id"; + $db->sql_query($sql); + + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_last_poster_id = ' . ANONYMOUS . ", topic_last_poster_name = '" . $db->sql_escape($post_username) . "', topic_last_poster_colour = '' + WHERE topic_last_poster_id = $user_id"; + $db->sql_query($sql); + + // Since we change every post by this author, we need to count this amount towards the anonymous user + + if ($user_row['user_posts']) + { + $added_guest_posts += $user_row['user_posts']; + } + } + break; + + case 'remove': + // there is nothing variant specific to deleting posts + break; + } } - switch ($mode) + // Now do the invariant tasks + // all queries performed in one call of this function are in a single transaction + // so this is kosher + if ($mode == 'retain') { - case 'retain': + // Assign more data to the Anonymous user + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' + SET poster_id = ' . ANONYMOUS . ' + WHERE ' . $db->sql_in_set('poster_id', $user_ids); + $db->sql_query($sql); - $db->sql_transaction('begin'); + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_edit_user = ' . ANONYMOUS . ' + WHERE ' . $db->sql_in_set('post_edit_user', $user_ids); + $db->sql_query($sql); - if ($post_username === false) - { - $post_username = $user->lang['GUEST']; - } + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_posts = user_posts + ' . $added_guest_posts . ' + WHERE user_id = ' . ANONYMOUS; + $db->sql_query($sql); + } + else if ($mode == 'remove') + { + if (!function_exists('delete_posts')) + { + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + } - // If the user is inactive and newly registered we assume no posts from this user being there... - if ($user_row['user_type'] == USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_REGISTER && !$user_row['user_posts']) - { - } - else - { - $sql = 'UPDATE ' . FORUMS_TABLE . ' - SET forum_last_poster_id = ' . ANONYMOUS . ", forum_last_poster_name = '" . $db->sql_escape($post_username) . "', forum_last_poster_colour = '' - WHERE forum_last_poster_id = $user_id"; - $db->sql_query($sql); + // Find any topics whose only posts are being deleted, and remove them from the topics table + $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts + FROM ' . POSTS_TABLE . ' + WHERE ' . $db->sql_in_set('poster_id', $user_ids) . ' + GROUP BY topic_id'; + $result = $db->sql_query($sql); - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET poster_id = ' . ANONYMOUS . ", post_username = '" . $db->sql_escape($post_username) . "' - WHERE poster_id = $user_id"; - $db->sql_query($sql); + $topic_id_ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topic_id_ary[$row['topic_id']] = $row['total_posts']; + } + $db->sql_freeresult($result); - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_edit_user = ' . ANONYMOUS . " - WHERE post_edit_user = $user_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_name = '" . $db->sql_escape($post_username) . "', topic_first_poster_colour = '' - WHERE topic_poster = $user_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_last_poster_id = ' . ANONYMOUS . ", topic_last_poster_name = '" . $db->sql_escape($post_username) . "', topic_last_poster_colour = '' - WHERE topic_last_poster_id = $user_id"; - $db->sql_query($sql); - - $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' - SET poster_id = ' . ANONYMOUS . " - WHERE poster_id = $user_id"; - $db->sql_query($sql); - - // Since we change every post by this author, we need to count this amount towards the anonymous user - - // Update the post count for the anonymous user - if ($user_row['user_posts']) - { - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_posts = user_posts + ' . $user_row['user_posts'] . ' - WHERE user_id = ' . ANONYMOUS; - $db->sql_query($sql); - } - } - - $db->sql_transaction('commit'); - - break; - - case 'remove': - - if (!function_exists('delete_posts')) - { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - } - - $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts - FROM ' . POSTS_TABLE . " - WHERE poster_id = $user_id - GROUP BY topic_id"; + if (sizeof($topic_id_ary)) + { + $sql = 'SELECT topic_id, topic_replies, topic_replies_real + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); $result = $db->sql_query($sql); - $topic_id_ary = array(); + $del_topic_ary = array(); while ($row = $db->sql_fetchrow($result)) { - $topic_id_ary[$row['topic_id']] = $row['total_posts']; + if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) + { + $del_topic_ary[] = $row['topic_id']; + } } $db->sql_freeresult($result); - if (sizeof($topic_id_ary)) + if (sizeof($del_topic_ary)) { - $sql = 'SELECT topic_id, topic_replies, topic_replies_real - FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); - $result = $db->sql_query($sql); - - $del_topic_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) - { - $del_topic_ary[] = $row['topic_id']; - } - } - $db->sql_freeresult($result); - - if (sizeof($del_topic_ary)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $del_topic_ary); - $db->sql_query($sql); - } + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $del_topic_ary); + $db->sql_query($sql); } + } - // Delete posts, attachments, etc. - delete_posts('poster_id', $user_id); - - break; + // actually do the meat of the work if we are deleting all the users' posts + // delete_posts can handle any number of IDs in its second argument + delete_posts('poster_id', $user_ids); } - $db->sql_transaction('begin'); - $table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE, PROFILE_FIELDS_DATA_TABLE, MODERATOR_CACHE_TABLE, DRAFTS_TABLE, BOOKMARKS_TABLE, SESSIONS_KEYS_TABLE, PRIVMSGS_FOLDER_TABLE, PRIVMSGS_RULES_TABLE); + // Delete the miscellaneous (non-post) data for the user foreach ($table_ary as $table) { $sql = "DELETE FROM $table - WHERE user_id = $user_id"; + WHERE " . $db->sql_in_set('user_id', $user_ids); $db->sql_query($sql); } @@ -541,35 +576,35 @@ function user_delete($mode, $user_id, $post_username = false) // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' - WHERE reportee_id = ' . $user_id; + WHERE ' . $db->sql_in_set('user_id', $user_ids); //reportee_id = ' . $user_id; $db->sql_query($sql); // Change user_id to anonymous for this users triggered events $sql = 'UPDATE ' . LOG_TABLE . ' SET user_id = ' . ANONYMOUS . ' - WHERE user_id = ' . $user_id; + WHERE ' . $db->sql_in_set('user_id', $user_ids); //user_id = ' . $user_id; $db->sql_query($sql); // Delete the user_id from the zebra table $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' - WHERE user_id = ' . $user_id . ' - OR zebra_id = ' . $user_id; + WHERE ' . $db->sql_in_set('user_id', $user_ids) . //user_id = ' . $user_id . ' + ' OR ' . $db->sql_in_set('zebra_id', $user_ids); $db->sql_query($sql); // Delete the user_id from the banlist $sql = 'DELETE FROM ' . BANLIST_TABLE . ' - WHERE ban_userid = ' . $user_id; + WHERE ' . $db->sql_in_set('ban_userid', $user_ids); $db->sql_query($sql); // Delete the user_id from the session table $sql = 'DELETE FROM ' . SESSIONS_TABLE . ' - WHERE session_user_id = ' . $user_id; + WHERE ' . $db->sql_in_set('session_user_id', $user_ids); $db->sql_query($sql); // Remove any undelivered mails... $sql = 'SELECT msg_id, user_id FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE author_id = ' . $user_id . ' + WHERE ' . $db->sql_in_set('author_id', $user_ids) . ' AND folder_id = ' . PRIVMSGS_NO_BOX; $result = $db->sql_query($sql); @@ -589,24 +624,24 @@ function user_delete($mode, $user_id, $post_username = false) } $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE author_id = ' . $user_id . ' + WHERE ' . $db->sql_in_set('author_id', $user_id) . ' AND folder_id = ' . PRIVMSGS_NO_BOX; $db->sql_query($sql); // Delete all to-information $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE user_id = ' . $user_id; + WHERE ' . $db->sql_in_set('user_id', $user_ids); $db->sql_query($sql); // Set the remaining author id to anonymous - this way users are still able to read messages from users being removed $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' SET author_id = ' . ANONYMOUS . ' - WHERE author_id = ' . $user_id; + WHERE ' . $db->sql_in_set('author_id', $user_ids); $db->sql_query($sql); $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET author_id = ' . ANONYMOUS . ' - WHERE author_id = ' . $user_id; + WHERE ' . $db->sql_in_set('author_id', $user_id); $db->sql_query($sql); foreach ($undelivered_user as $_user_id => $ary) @@ -626,17 +661,11 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); // Reset newest user info if appropriate - if ($config['newest_user_id'] == $user_id) + if (in_array($config['newest_user_id'], $user_ids)) { update_last_username(); } - // Decrement number of users if this user is active - if ($user_row['user_type'] != USER_INACTIVE && $user_row['user_type'] != USER_IGNORE) - { - set_config_count('num_users', -1, true); - } - return false; } From 04a6303527d9bf29114b51001d06af5235ea0847 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 8 May 2011 03:01:38 -0400 Subject: [PATCH 002/645] [feature/prune-users] Apply e6ed55a9c1ceb07ab2e87d4a53f9e688fda319c5. This was done in PHPBB3-9872. PHPBB3-9622 --- phpBB/includes/functions_user.php | 41 +------------------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 0886e8aabf..9b16a56b1c 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -518,46 +518,7 @@ function user_delete($mode, $user_ids, $retain_username = true) include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); } - // Find any topics whose only posts are being deleted, and remove them from the topics table - $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts - FROM ' . POSTS_TABLE . ' - WHERE ' . $db->sql_in_set('poster_id', $user_ids) . ' - GROUP BY topic_id'; - $result = $db->sql_query($sql); - - $topic_id_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - $topic_id_ary[$row['topic_id']] = $row['total_posts']; - } - $db->sql_freeresult($result); - - if (sizeof($topic_id_ary)) - { - $sql = 'SELECT topic_id, topic_replies, topic_replies_real - FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); - $result = $db->sql_query($sql); - - $del_topic_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) - { - $del_topic_ary[] = $row['topic_id']; - } - } - $db->sql_freeresult($result); - - if (sizeof($del_topic_ary)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $del_topic_ary); - $db->sql_query($sql); - } - } - - // actually do the meat of the work if we are deleting all the users' posts + // Delete posts, attachments, etc. // delete_posts can handle any number of IDs in its second argument delete_posts('poster_id', $user_ids); } From fe347ec1124de7022bbbf37d0a1fffeff56c7271 Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Tue, 25 May 2010 10:52:01 -0500 Subject: [PATCH 003/645] [feature/prune-users] Adjust some language strings for new features Adjust two language strings for ACP prune feature to include descriptions for new features. PHPBB3-9622 --- phpBB/adm/style/acp_prune_users.html | 27 ++++- phpBB/adm/style/confirm_body_prune.html | 28 +++-- phpBB/includes/acp/acp_prune.php | 139 +++++++++++++++++++----- phpBB/language/en/acp/prune.php | 14 ++- 4 files changed, 162 insertions(+), 46 deletions(-) diff --git a/phpBB/adm/style/acp_prune_users.html b/phpBB/adm/style/acp_prune_users.html index 0f2b23dcef..a6c5679a11 100644 --- a/phpBB/adm/style/acp_prune_users.html +++ b/phpBB/adm/style/acp_prune_users.html @@ -9,7 +9,7 @@
- {L_ACP_PRUNE_USERS} + {L_CRITERIA}
@@ -18,9 +18,16 @@
+
+
+
+

{L_JOINED_EXPLAIN}
-
+
+ {L_AFTER} +

{L_BEFORE} +

{L_LAST_ACTIVE_EXPLAIN}
@@ -30,11 +37,27 @@
+
+
+
+
+
+

{L_PRUNE_USERS_GROUP_EXPLAIN}
+
+
+
+ +
+ {L_USERNAMES}

{L_SELECT_USERS_EXPLAIN}
[ {L_FIND_USERNAME} ]
+
+ +
+ {L_OPTIONS}

{L_DELETE_USER_POSTS_EXPLAIN}
diff --git a/phpBB/adm/style/confirm_body_prune.html b/phpBB/adm/style/confirm_body_prune.html index 9481386231..92e0a22e71 100644 --- a/phpBB/adm/style/confirm_body_prune.html +++ b/phpBB/adm/style/confirm_body_prune.html @@ -2,6 +2,23 @@ +
+

{L_PRUNE_USERS_LIST}

+

{L_PRUNE_USERS_LIST_DEACTIVATE}

{L_PRUNE_USERS_LIST_DELETE}

+ +
+ + » + {users.USERNAME} + [{L_USER_ADMIN}]
+ +
+ + {L_MARK_ALL} • + {L_UNMARK_ALL} + +
+

{MESSAGE_TITLE}

{MESSAGE_TEXT}

@@ -12,17 +29,6 @@   - -

{L_PRUNE_USERS_LIST}

-

{L_PRUNE_USERS_LIST_DEACTIVATE}

{L_PRUNE_USERS_LIST_DELETE}

- -
- - » {users.USERNAME} [{L_USER_ADMIN}]
- - -

-
diff --git a/phpBB/includes/acp/acp_prune.php b/phpBB/includes/acp/acp_prune.php index 99bec29d6d..a21805972f 100644 --- a/phpBB/includes/acp/acp_prune.php +++ b/phpBB/includes/acp/acp_prune.php @@ -243,6 +243,7 @@ class acp_prune if (confirm_box(true)) { $user_ids = $usernames = array(); + $this->get_prune_users($user_ids, $usernames); if (sizeof($user_ids)) @@ -256,10 +257,7 @@ class acp_prune { if ($deleteposts) { - foreach ($user_ids as $user_id) - { - user_delete('remove', $user_id); - } + user_delete('remove', $user_ids); $l_log = 'LOG_PRUNE_USER_DEL_DEL'; } @@ -297,6 +295,7 @@ class acp_prune { $template->assign_block_vars('users', array( 'USERNAME' => $usernames[$user_id], + 'USER_ID' => $user_id, 'U_PROFILE' => append_sid($phpbb_root_path . 'memberlist.' . $phpEx, 'mode=viewprofile&u=' . $user_id), 'U_USER_ADMIN' => ($auth->acl_get('a_user')) ? append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=overview&u=' . $user_id, true, $user->session_id) : '', )); @@ -312,8 +311,8 @@ class acp_prune 'mode' => $mode, 'prune' => 1, - 'users' => utf8_normalize_nfc(request_var('users', '', true)), - 'username' => utf8_normalize_nfc(request_var('username', '', true)), + 'users' => request_var('users', '', true), + 'username' => request_var('username', '', true), 'email' => request_var('email', ''), 'joined_select' => request_var('joined_select', ''), 'joined' => request_var('joined', ''), @@ -338,22 +337,27 @@ class acp_prune } $find_time = array('lt' => $user->lang['BEFORE'], 'gt' => $user->lang['AFTER']); - $s_find_join_time = ''; - foreach ($find_time as $key => $value) - { - $s_find_join_time .= ''; - } - $s_find_active_time = ''; foreach ($find_time as $key => $value) { $s_find_active_time .= ''; } + $s_group_list = ''; + $sql = 'SELECT group_id, group_name FROM ' . GROUPS_TABLE . ' + WHERE group_type <> ' . GROUP_SPECIAL . ' + ORDER BY group_name ASC'; + $result = $db->sql_query($sql); + + while ($row = $db->sql_fetchrow($result)) + { + $s_group_list .= '
+

{L_PRUNE_USERS_GROUP_EXPLAIN}
+
diff --git a/phpBB/includes/acp/acp_prune.php b/phpBB/includes/acp/acp_prune.php index a21805972f..b10eb292d2 100644 --- a/phpBB/includes/acp/acp_prune.php +++ b/phpBB/includes/acp/acp_prune.php @@ -245,7 +245,6 @@ class acp_prune $user_ids = $usernames = array(); $this->get_prune_users($user_ids, $usernames); - if (sizeof($user_ids)) { if ($action == 'deactivate') @@ -311,17 +310,7 @@ class acp_prune 'mode' => $mode, 'prune' => 1, - 'users' => request_var('users', '', true), - 'username' => request_var('username', '', true), - 'email' => request_var('email', ''), - 'joined_select' => request_var('joined_select', ''), - 'joined' => request_var('joined', ''), - 'active_select' => request_var('active_select', ''), - 'active' => request_var('active', ''), - 'count_select' => request_var('count_select', ''), - 'count' => request_var('count', ''), 'deleteposts' => request_var('deleteposts', 0), - 'action' => request_var('action', ''), )), 'confirm_body_prune.html'); } @@ -343,7 +332,7 @@ class acp_prune $s_find_active_time .= ''; } - $s_group_list = ''; + $s_group_list = ''; $sql = 'SELECT group_id, group_name FROM ' . GROUPS_TABLE . ' WHERE group_type <> ' . GROUP_SPECIAL . ' ORDER BY group_name ASC'; @@ -372,6 +361,8 @@ class acp_prune $users_by_name = request_var('users', '', true); $users_by_id = request_var('user_ids', array(0)); + $group_id = request_var('group_id', 0); + $posts_on_queue = request_var('posts_on_queue', 0); if ($users_by_name) { @@ -399,7 +390,6 @@ class acp_prune $active = request_var('active', ''); $count = request_var('count', 0); - $posts_on_queue = request_var('posts_on_queue', 0); $active = ($active) ? explode('-', $active) : array(); $joined_before = ($joined_before) ? explode('-', $joined_before) : array(); @@ -424,7 +414,7 @@ class acp_prune } else if (empty($joined_after) && !empty($joined_before)) { - $joined_sql = ' AND user_regdate < ' . gmmktime(0, 0, 0, (int) $joined_before[1], (int) $joined_before[2], (int) $joined_before[3]); + $joined_sql = ' AND user_regdate < ' . gmmktime(0, 0, 0, (int) $joined_before[1], (int) $joined_before[2], (int) $joined_before[0]); } // implicit else when both arrays are empty do nothing From 9915ed52551b9b11e2cfcadabcb758ab05c6db6b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 16:07:14 +0100 Subject: [PATCH 012/645] =?UTF-8?q?[ticket/8743]=20Include=20poster=C2=B4s?= =?UTF-8?q?=20name=20in=20mail=20notifications?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PHPBB3-8743 --- phpBB/includes/functions_posting.php | 6 ++++-- phpBB/language/en/email/forum_notify.txt | 2 +- phpBB/language/en/email/newtopic_notify.txt | 2 +- phpBB/language/en/email/topic_notify.txt | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 77d92e26e2..be3aa844fe 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -1160,7 +1160,7 @@ function topic_review($topic_id, $forum_id, $mode = 'topic_review', $cur_post_id /** * User Notification */ -function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id) +function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id, $author_name = '') { global $db, $user, $config, $phpbb_root_path, $phpEx, $auth; @@ -1323,6 +1323,7 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id 'USERNAME' => htmlspecialchars_decode($addr['name']), 'TOPIC_TITLE' => htmlspecialchars_decode($topic_title), 'FORUM_NAME' => htmlspecialchars_decode($forum_name), + 'AUTHOR_NAME' => htmlspecialchars_decode($author_name), 'U_FORUM' => generate_board_url() . "/viewforum.$phpEx?f=$forum_id", 'U_TOPIC' => generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&t=$topic_id", @@ -2585,7 +2586,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u // Send Notifications if (($mode == 'reply' || $mode == 'quote' || $mode == 'post') && $post_approval) { - user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id']); + $username = ($username) ? $username : $user->data['username']; + user_notification($mode, $subject, $data['topic_title'], $data['forum_name'], $data['forum_id'], $data['topic_id'], $data['post_id'], $username); } $params = $add_anchor = ''; diff --git a/phpBB/language/en/email/forum_notify.txt b/phpBB/language/en/email/forum_notify.txt index fae5a83885..490780a0a6 100644 --- a/phpBB/language/en/email/forum_notify.txt +++ b/phpBB/language/en/email/forum_notify.txt @@ -2,7 +2,7 @@ Subject: Forum post notification - "{FORUM_NAME}" Hello {USERNAME}, -You are receiving this notification because you are watching the forum, "{FORUM_NAME}" at "{SITENAME}". This forum has received a new reply to the topic "{TOPIC_TITLE}" since your last visit. You can use the following link to view the last unread reply, no more notifications will be sent until you visit the topic. +You are receiving this notification because you are watching the forum, "{FORUM_NAME}" at "{SITENAME}". This forum has received a new reply to the topic "{TOPIC_TITLE}" by {AUTHOR_NAME} since your last visit. You can use the following link to view the last unread reply, no more notifications will be sent until you visit the topic. {U_NEWEST_POST} diff --git a/phpBB/language/en/email/newtopic_notify.txt b/phpBB/language/en/email/newtopic_notify.txt index 529bbf0f8f..eda1370938 100644 --- a/phpBB/language/en/email/newtopic_notify.txt +++ b/phpBB/language/en/email/newtopic_notify.txt @@ -2,7 +2,7 @@ Subject: New topic notification - "{FORUM_NAME}" Hello {USERNAME}, -You are receiving this notification because you are watching the forum, "{FORUM_NAME}" at "{SITENAME}". This forum has received a new topic since your last visit, "{TOPIC_TITLE}". You can use the following link to view the forum, no more notifications will be sent until you visit the forum. +You are receiving this notification because you are watching the forum, "{FORUM_NAME}" at "{SITENAME}". This forum has received a new topic by {AUTHOR_NAME} since your last visit, "{TOPIC_TITLE}". You can use the following link to view the forum, no more notifications will be sent until you visit the forum. {U_FORUM} diff --git a/phpBB/language/en/email/topic_notify.txt b/phpBB/language/en/email/topic_notify.txt index 99587b28e0..fcfbcc2abd 100644 --- a/phpBB/language/en/email/topic_notify.txt +++ b/phpBB/language/en/email/topic_notify.txt @@ -2,7 +2,7 @@ Subject: Topic reply notification - "{TOPIC_TITLE}" Hello {USERNAME}, -You are receiving this notification because you are watching the topic, "{TOPIC_TITLE}" at "{SITENAME}". This topic has received a reply since your last visit. You can use the following link to view the replies made, no more notifications will be sent until you visit the topic. +You are receiving this notification because you are watching the topic, "{TOPIC_TITLE}" at "{SITENAME}". This topic has received a reply by {AUTHOR_NAME} since your last visit. You can use the following link to view the replies made, no more notifications will be sent until you visit the topic. If you want to view the newest post made since your last visit, click the following link: {U_NEWEST_POST} From 15d2f294c664e11fb1f2bc84238067cf71a544e6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 25 Mar 2012 20:56:00 -0400 Subject: [PATCH 013/645] [feature/prune-users] Cosmetic changes per bantu's review. PHPBB3-9622 --- phpBB/includes/acp/acp_prune.php | 5 +++-- phpBB/includes/functions_user.php | 9 ++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/acp/acp_prune.php b/phpBB/includes/acp/acp_prune.php index b10eb292d2..145c0c3854 100644 --- a/phpBB/includes/acp/acp_prune.php +++ b/phpBB/includes/acp/acp_prune.php @@ -333,7 +333,8 @@ class acp_prune } $s_group_list = ''; - $sql = 'SELECT group_id, group_name FROM ' . GROUPS_TABLE . ' + $sql = 'SELECT group_id, group_name + FROM ' . GROUPS_TABLE . ' WHERE group_type <> ' . GROUP_SPECIAL . ' ORDER BY group_name ASC'; $result = $db->sql_query($sql); @@ -403,7 +404,7 @@ class acp_prune // so that our time range is a full day instead of 1 second if ($joined_after == $joined_before) { - $joined_after[2] += 1; //$joined_after[2]++; + $joined_after[2] += 1; } $joined_sql = ' AND user_regdate BETWEEN ' . gmmktime(0, 0, 0, (int) $joined_after[1], (int) $joined_after[2], (int) $joined_after[0]) . ' AND ' . gmmktime(0, 0, 0, (int) $joined_before[1], (int) $joined_before[2], (int) $joined_before[0]); diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index e9655ba736..c78949342b 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -365,8 +365,7 @@ function user_delete($mode, $user_ids, $retain_username = true) // Before we begin, we will remove the reports the user issued. $sql = 'SELECT r.post_id, p.topic_id FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p - WHERE ' . $db->sql_in_set('r.user_id', $user_ids) . //r.user_id = ' . $user_id . ' - ' + WHERE ' . $db->sql_in_set('r.user_id', $user_ids) . ' AND p.post_id = r.post_id'; $result = $db->sql_query($sql); @@ -554,13 +553,13 @@ function user_delete($mode, $user_ids, $retain_username = true) // Change user_id to anonymous for this users triggered events $sql = 'UPDATE ' . LOG_TABLE . ' SET user_id = ' . ANONYMOUS . ' - WHERE ' . $user_id_sql; //user_id = ' . $user_id; + WHERE ' . $user_id_sql; $db->sql_query($sql); // Delete the user_id from the zebra table $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' - WHERE ' . $user_id_sql . //user_id = ' . $user_id . ' - ' OR ' . $db->sql_in_set('zebra_id', $user_ids); + WHERE ' . $user_id_sql . ' + OR ' . $db->sql_in_set('zebra_id', $user_ids); $db->sql_query($sql); // Delete the user_id from the banlist From 8e2cbe39cdd7672638dbc0d6a0f65a7365db0d91 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 04:06:52 +0200 Subject: [PATCH 014/645] [feature/dic] Convert common.php to Symfony2 DependencyInjection component PHPBB3-10739 --- phpBB/common.php | 43 +++++++++--------- phpBB/composer.json | 5 ++- phpBB/composer.lock | 16 ++++++- phpBB/config/parameters.yml | 11 +++++ phpBB/config/services.yml | 87 +++++++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+), 24 deletions(-) create mode 100644 phpBB/config/parameters.yml create mode 100644 phpBB/config/services.yml diff --git a/phpBB/common.php b/phpBB/common.php index b3b8d7e4f7..aa6115fe1c 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -15,6 +15,9 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\EventDispatcher\EventDispatcher; require($phpbb_root_path . 'includes/startup.' . $phpEx); @@ -91,43 +94,41 @@ $phpbb_class_loader_ext->register(); $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); $phpbb_class_loader->register(); +$container = new ContainerBuilder(); +$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/config')); +$loader->load('parameters.yml'); +$loader->load('services.yml'); + +$container->setParameter('core.root_path', $phpbb_root_path); +$container->setParameter('core.php_ext', $phpEx); + // set up caching -$cache_factory = new phpbb_cache_factory($acm_type); -$cache = $cache_factory->get_service(); +$cache = $container->get('cache'); $phpbb_class_loader_ext->set_cache($cache->get_driver()); $phpbb_class_loader->set_cache($cache->get_driver()); // Instantiate some basic classes -$phpbb_dispatcher = new phpbb_event_dispatcher(); -$request = new phpbb_request(); -$user = new phpbb_user(); -$auth = new phpbb_auth(); -$db = new $sql_db(); +$phpbb_dispatcher = $container->get('dispatcher'); +$request = $container->get('request'); +$user = $container->get('user'); +$auth = $container->get('auth'); +$db = $container->get('dbal.conn'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function -// Connect to DB -$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('PHPBB_DB_NEW_LINK') ? PHPBB_DB_NEW_LINK : false); - -// We do not need this any longer, unset for safety purposes -unset($dbpasswd); - // Grab global variables, re-cache if necessary -$config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); +$config = $container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions -$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); +$phpbb_extension_manager = $container->get('ext.manager'); -// Initialize style -$phpbb_style_resource_locator = new phpbb_style_resource_locator(); -$phpbb_style_path_provider = new phpbb_style_extension_path_provider($phpbb_extension_manager, new phpbb_style_path_provider()); -$template = new phpbb_style_template($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider); -$style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_style_resource_locator, $phpbb_style_path_provider, $template); +$template = $container->get('template'); +$style = $container->get('style'); -$phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); +$phpbb_subscriber_loader = $container->get('event.subscriber_loader'); $phpbb_subscriber_loader->load(); // Add own hook handler diff --git a/phpBB/composer.json b/phpBB/composer.json index 1059b97f84..56fb2454d1 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -1,5 +1,8 @@ { "require": { - "symfony/event-dispatcher": "2.0.*" + "symfony/config": "2.0.*", + "symfony/dependency-injection": "2.0.*", + "symfony/event-dispatcher": "2.0.*", + "symfony/yaml": "2.0.*" } } diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 062ad4b3aa..1707524da1 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,9 +1,21 @@ { - "hash": "9bada3748ec2933fe0864dcfafbcd671", + "hash": "b1e9c3bcfcee0c5630742abb3e49685f", "packages": [ + { + "package": "symfony/config", + "version": "v2.0.12" + }, + { + "package": "symfony/dependency-injection", + "version": "v2.0.12" + }, { "package": "symfony/event-dispatcher", - "version": "v2.0.10" + "version": "v2.0.12" + }, + { + "package": "symfony/yaml", + "version": "v2.0.12" } ], "aliases": [] diff --git a/phpBB/config/parameters.yml b/phpBB/config/parameters.yml new file mode 100644 index 0000000000..8a90c8e99d --- /dev/null +++ b/phpBB/config/parameters.yml @@ -0,0 +1,11 @@ +parameters: + cache.acm_type: file + dbal.driver: dbal_mysqli + dbal.dbhost: + dbal.dbuser: root + dbal.dbpasswd: + dbal.dbname: phpbb_dev + dbal.dbport: + dbal.new_link: false + tables.config: phpbb_config + tables.ext: phpbb_ext diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml new file mode 100644 index 0000000000..2bf8478f82 --- /dev/null +++ b/phpBB/config/services.yml @@ -0,0 +1,87 @@ +services: + cache_factory: + class: phpbb_cache_factory + arguments: + - %cache.acm_type% + + cache: + class: phpbb_cache_service + factory_service: cache_factory + factory_method: get_service + + cache.driver: + class: phpbb_cache_driver_interface + factory_service: cache + factory_method: get_driver + + dispatcher: + class: phpbb_event_dispatcher + + request: + class: phpbb_request + + user: + class: phpbb_user + + auth: + class: phpbb_auth + + dbal.conn: + class: %dbal.driver% + calls: + - [sql_connect, [%dbal.dbhost%, %dbal.dbuser%, %dbal.dbpasswd%, %dbal.dbname%, %dbal.dbport%, false, %dbal.new_link%]] + + config: + class: phpbb_config_db + arguments: + - @dbal.conn + - @cache.driver + - %tables.config% + + ext.manager: + class: phpbb_extension_manager + arguments: + - @dbal.conn + - %tables.ext% + - %core.root_path% + - .%core.php_ext% + - @cache.driver + + style.resource_locator: + class: phpbb_style_resource_locator + + style.path_provider_ext: + class: phpbb_style_extension_path_provider + arguments: + - @ext.manager + - @style.path_provider + + style.path_provider: + class: phpbb_style_path_provider + + template: + class: phpbb_style_template + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @user + - @style.resource_locator + - @style.path_provider_ext + + style: + class: phpbb_style + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @user + - @style.resource_locator + - @style.path_provider_ext + - @template + + event.subscriber_loader: + class: phpbb_event_extension_subscriber_loader + arguments: + - @dispatcher + - @ext.manager From b12f9a285546641415d9ea2dd9e3a3dba6527d1a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:21:26 +0200 Subject: [PATCH 015/645] [feature/dic] Remove cache factory, now handled by DIC PHPBB3-10739 --- phpBB/config/parameters.yml | 4 +-- phpBB/config/services.yml | 15 ++++-------- phpBB/includes/cache/factory.php | 42 -------------------------------- 3 files changed, 7 insertions(+), 54 deletions(-) delete mode 100644 phpBB/includes/cache/factory.php diff --git a/phpBB/config/parameters.yml b/phpBB/config/parameters.yml index 8a90c8e99d..da29ae8417 100644 --- a/phpBB/config/parameters.yml +++ b/phpBB/config/parameters.yml @@ -1,6 +1,6 @@ parameters: - cache.acm_type: file - dbal.driver: dbal_mysqli + cache.driver.class: phpbb_cache_driver_file + dbal.driver.class: dbal_mysqli dbal.dbhost: dbal.dbuser: root dbal.dbpasswd: diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 2bf8478f82..09eb993ca6 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -1,18 +1,13 @@ services: - cache_factory: - class: phpbb_cache_factory - arguments: - - %cache.acm_type% - cache: class: phpbb_cache_service - factory_service: cache_factory - factory_method: get_service + arguments: + - @cache.driver cache.driver: class: phpbb_cache_driver_interface - factory_service: cache - factory_method: get_driver + arguments: + - %cache.driver.class% dispatcher: class: phpbb_event_dispatcher @@ -27,7 +22,7 @@ services: class: phpbb_auth dbal.conn: - class: %dbal.driver% + class: %dbal.driver.class% calls: - [sql_connect, [%dbal.dbhost%, %dbal.dbuser%, %dbal.dbpasswd%, %dbal.dbname%, %dbal.dbport%, false, %dbal.new_link%]] diff --git a/phpBB/includes/cache/factory.php b/phpBB/includes/cache/factory.php deleted file mode 100644 index 01c4d0b901..0000000000 --- a/phpBB/includes/cache/factory.php +++ /dev/null @@ -1,42 +0,0 @@ -acm_type = $acm_type; - } - - public function get_driver() - { - $class_name = 'phpbb_cache_driver_' . $this->acm_type; - return new $class_name(); - } - - public function get_service() - { - $driver = $this->get_driver(); - $service = new phpbb_cache_service($driver); - return $service; - } -} From 776160a7e35a1f82325b7acf573906310791c573 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:23:33 +0200 Subject: [PATCH 016/645] [feature/dic] Fetch cache driver explicitly PHPBB3-10739 --- phpBB/common.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index aa6115fe1c..591969df74 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -104,8 +104,8 @@ $container->setParameter('core.php_ext', $phpEx); // set up caching $cache = $container->get('cache'); -$phpbb_class_loader_ext->set_cache($cache->get_driver()); -$phpbb_class_loader->set_cache($cache->get_driver()); +$phpbb_class_loader_ext->set_cache($container->get('cache.driver')); +$phpbb_class_loader->set_cache($container->get('cache.driver')); // Instantiate some basic classes $phpbb_dispatcher = $container->get('dispatcher'); From bca600877cbd92246949366238d365bbc3039d5a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:27:46 +0200 Subject: [PATCH 017/645] [feature/dic] Move cron manager into DIC PHPBB3-10739 --- phpBB/common.php | 2 +- phpBB/config/services.yml | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/phpBB/common.php b/phpBB/common.php index 591969df74..0446b5c15e 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -142,5 +142,5 @@ foreach ($cache->obtain_hooks() as $hook) if (!$config['use_system_cron']) { - $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver()); + $cron = $container->get('cron.manager'); } diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 09eb993ca6..85a230de52 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -80,3 +80,14 @@ services: arguments: - @dispatcher - @ext.manager + + cron.task_provider: + class: phpbb_cron_task_provider + arguments: + - @ext.manager + + cron.manager: + class: phpbb_cron_manager + arguments: + - @cron.task_provider + - @cache.driver From 873630f04e6502cc69e6b208f596414f240bc923 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:45:33 +0200 Subject: [PATCH 018/645] [feature/dic] Move class loader into DIC PHPBB3-10739 --- phpBB/common.php | 17 ++++++++--------- phpBB/config/services.yml | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 0446b5c15e..117dc2051e 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -88,12 +88,6 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -// Setup class loader first -$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); -$phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); -$phpbb_class_loader->register(); - $container = new ContainerBuilder(); $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/config')); $loader->load('parameters.yml'); @@ -102,6 +96,12 @@ $loader->load('services.yml'); $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $phpEx); +// Setup class loader first +$phpbb_class_loader_ext = $container->get('class_loader.ext'); +$phpbb_class_loader_ext->register(); +$phpbb_class_loader = $container->get('class_loader'); +$phpbb_class_loader->register(); + // set up caching $cache = $container->get('cache'); $phpbb_class_loader_ext->set_cache($container->get('cache.driver')); @@ -124,13 +124,12 @@ set_config_count(null, null, null, $config); // load extensions $phpbb_extension_manager = $container->get('ext.manager'); +$phpbb_subscriber_loader = $container->get('event.subscriber_loader'); +$phpbb_subscriber_loader->load(); $template = $container->get('template'); $style = $container->get('style'); -$phpbb_subscriber_loader = $container->get('event.subscriber_loader'); -$phpbb_subscriber_loader->load(); - // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('template', 'display'))); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 85a230de52..ef459f4903 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -1,13 +1,28 @@ services: + class_loader: + class: phpbb_class_loader + arguments: + - phpbb_ + - %core.root_path%includes/ + - .%core.php_ext% + + class_loader.ext: + class: phpbb_class_loader + arguments: + - phpbb_ext_ + - %core.root_path%ext/ + - .%core.php_ext% + cache: class: phpbb_cache_service arguments: - @cache.driver cache.driver: - class: phpbb_cache_driver_interface - arguments: - - %cache.driver.class% + class: %cache.driver.class% + + cache.driver.install: + class: phpbb_cache_driver_file dispatcher: class: phpbb_event_dispatcher From a7f61b91b7feec80cd9d544502aef937f036ae7c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 20:45:58 +0200 Subject: [PATCH 019/645] [feature/dic] Use DIC in download/file and install/index PHPBB3-10739 --- phpBB/download/file.php | 39 ++++++++++++++++++++++----------------- phpBB/install/index.php | 24 ++++++++++++++++-------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/phpBB/download/file.php b/phpBB/download/file.php index c01b0789de..bc7042fbc8 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -14,7 +14,6 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); - // Thank you sun. if (isset($_SERVER['CONTENT_TYPE'])) { @@ -45,20 +44,27 @@ if (isset($_GET['avatar'])) require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); - $phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); + $container = new ContainerBuilder(); + $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); + $loader->load('parameters.yml'); + $loader->load('services.yml'); + + $container->setParameter('core.root_path', $phpbb_root_path); + $container->setParameter('core.php_ext', $phpEx); + + $phpbb_class_loader_ext = $container->get('class_loader.ext'); $phpbb_class_loader_ext->register(); - $phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); + $phpbb_class_loader = $container->get('class_loader'); $phpbb_class_loader->register(); // set up caching - $cache_factory = new phpbb_cache_factory($acm_type); - $cache = $cache_factory->get_service(); - $phpbb_class_loader_ext->set_cache($cache->get_driver()); - $phpbb_class_loader->set_cache($cache->get_driver()); + $cache = $container->get('cache'); + $phpbb_class_loader_ext->set_cache($container->get('cache.driver')); + $phpbb_class_loader->set_cache($container->get('cache.driver')); - $phpbb_dispatcher = new phpbb_event_dispatcher(); - $request = new phpbb_request(); - $db = new $sql_db(); + $phpbb_dispatcher = $container->get('dispatcher'); + $request = $container->get('request'); + $db = $container->get('dbal.conn'); // Connect to DB if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false)) @@ -69,19 +75,18 @@ if (isset($_GET['avatar'])) request_var('', 0, false, false, $request); - // worst-case default - $browser = strtolower($request->header('User-Agent', 'msie 6.0')); - - $config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE); + $config = $container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions - $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); - - $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); + $phpbb_extension_manager = $container->get('ext.manager'); + $phpbb_subscriber_loader = $container->get('event.subscriber_loader'); $phpbb_subscriber_loader->load(); + // worst-case default + $browser = strtolower($request->header('User-Agent', 'msie 6.0')); + $filename = request_var('avatar', ''); $avatar_group = false; $exit = false; diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 13ab30a9fa..36c10c3ca6 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -79,19 +79,27 @@ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/functions_install.' . $phpEx); -$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); +$container = new ContainerBuilder(); +$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); +$loader->load('parameters.yml'); +$loader->load('services.yml'); + +$container->setParameter('core.root_path', $phpbb_root_path); +$container->setParameter('core.php_ext', $phpEx); +$container->setAlias('cache.driver.install', 'cache.driver'); + +$phpbb_class_loader_ext = $container->get('class_loader.ext'); $phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); +$phpbb_class_loader = $container->get('class_loader'); $phpbb_class_loader->register(); // set up caching -$cache_factory = new phpbb_cache_factory('file'); -$cache = $cache_factory->get_service(); -$phpbb_class_loader_ext->set_cache($cache->get_driver()); -$phpbb_class_loader->set_cache($cache->get_driver()); +$cache = $container->get('cache'); +$phpbb_class_loader_ext->set_cache($container->get('cache.driver')); +$phpbb_class_loader->set_cache($container->get('cache.driver')); -$phpbb_dispatcher = new phpbb_event_dispatcher(); -$request = new phpbb_request(); +$phpbb_dispatcher = $container->get('dispatcher'); +$request = $container->get('request'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function From dc9ccc432cd0b24cf762f8285d8a90f52b8efe5b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 31 Mar 2012 21:20:58 +0200 Subject: [PATCH 020/645] [feature/dic] Make use of calls to cut down on boilerplate PHPBB3-10739 --- phpBB/common.php | 7 +------ phpBB/config/services.yml | 8 ++++++++ phpBB/download/file.php | 7 +------ phpBB/install/index.php | 6 +----- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 117dc2051e..51478662d7 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -97,15 +97,11 @@ $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $phpEx); // Setup class loader first -$phpbb_class_loader_ext = $container->get('class_loader.ext'); -$phpbb_class_loader_ext->register(); $phpbb_class_loader = $container->get('class_loader'); -$phpbb_class_loader->register(); +$phpbb_class_loader_ext = $container->get('class_loader.ext'); // set up caching $cache = $container->get('cache'); -$phpbb_class_loader_ext->set_cache($container->get('cache.driver')); -$phpbb_class_loader->set_cache($container->get('cache.driver')); // Instantiate some basic classes $phpbb_dispatcher = $container->get('dispatcher'); @@ -125,7 +121,6 @@ set_config_count(null, null, null, $config); // load extensions $phpbb_extension_manager = $container->get('ext.manager'); $phpbb_subscriber_loader = $container->get('event.subscriber_loader'); -$phpbb_subscriber_loader->load(); $template = $container->get('template'); $style = $container->get('style'); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index ef459f4903..6f2ed8c7c3 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -5,6 +5,9 @@ services: - phpbb_ - %core.root_path%includes/ - .%core.php_ext% + calls: + - [register, []] + - [set_cache, [@cache.driver]] class_loader.ext: class: phpbb_class_loader @@ -12,6 +15,9 @@ services: - phpbb_ext_ - %core.root_path%ext/ - .%core.php_ext% + calls: + - [register, []] + - [set_cache, [@cache.driver]] cache: class: phpbb_cache_service @@ -95,6 +101,8 @@ services: arguments: - @dispatcher - @ext.manager + calls: + - [load, []] cron.task_provider: class: phpbb_cron_task_provider diff --git a/phpBB/download/file.php b/phpBB/download/file.php index bc7042fbc8..eabb6edbbb 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -52,15 +52,11 @@ if (isset($_GET['avatar'])) $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $phpEx); - $phpbb_class_loader_ext = $container->get('class_loader.ext'); - $phpbb_class_loader_ext->register(); $phpbb_class_loader = $container->get('class_loader'); - $phpbb_class_loader->register(); + $phpbb_class_loader_ext = $container->get('class_loader.ext'); // set up caching $cache = $container->get('cache'); - $phpbb_class_loader_ext->set_cache($container->get('cache.driver')); - $phpbb_class_loader->set_cache($container->get('cache.driver')); $phpbb_dispatcher = $container->get('dispatcher'); $request = $container->get('request'); @@ -82,7 +78,6 @@ if (isset($_GET['avatar'])) // load extensions $phpbb_extension_manager = $container->get('ext.manager'); $phpbb_subscriber_loader = $container->get('event.subscriber_loader'); - $phpbb_subscriber_loader->load(); // worst-case default $browser = strtolower($request->header('User-Agent', 'msie 6.0')); diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 36c10c3ca6..0d7a0a288c 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -88,15 +88,11 @@ $container->setParameter('core.root_path', $phpbb_root_path); $container->setParameter('core.php_ext', $phpEx); $container->setAlias('cache.driver.install', 'cache.driver'); -$phpbb_class_loader_ext = $container->get('class_loader.ext'); -$phpbb_class_loader_ext->register(); $phpbb_class_loader = $container->get('class_loader'); -$phpbb_class_loader->register(); +$phpbb_class_loader_ext = $container->get('class_loader.ext'); // set up caching $cache = $container->get('cache'); -$phpbb_class_loader_ext->set_cache($container->get('cache.driver')); -$phpbb_class_loader->set_cache($container->get('cache.driver')); $phpbb_dispatcher = $container->get('dispatcher'); $request = $container->get('request'); From 35c78c127b8fefe56512faaf83c47bee28908e0f Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 1 Apr 2012 00:59:23 +0200 Subject: [PATCH 021/645] [feature/dic] Make table_config a DIC parameter PHPBB3-10739 --- phpBB/config/parameters.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/config/parameters.yml b/phpBB/config/parameters.yml index da29ae8417..3bedc9a135 100644 --- a/phpBB/config/parameters.yml +++ b/phpBB/config/parameters.yml @@ -1,4 +1,5 @@ parameters: + core.table_prefix: phpbb_ cache.driver.class: phpbb_cache_driver_file dbal.driver.class: dbal_mysqli dbal.dbhost: @@ -7,5 +8,5 @@ parameters: dbal.dbname: phpbb_dev dbal.dbport: dbal.new_link: false - tables.config: phpbb_config - tables.ext: phpbb_ext + tables.config: %core.table_prefix%config + tables.ext: %core.table_prefix%ext From e78fbfef9c6aac1349d18454a4292781d661795c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 1 Apr 2012 01:13:00 +0200 Subject: [PATCH 022/645] [feature/dic] Move cron.lock_db into DIC PHPBB3-10739 --- phpBB/config/services.yml | 7 +++++++ phpBB/cron.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 6f2ed8c7c3..6817d8f015 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -114,3 +114,10 @@ services: arguments: - @cron.task_provider - @cache.driver + + cron.lock_db: + class: phpbb_lock_db + arguments: + - cron_lock + - @config + - @dbal.conn diff --git a/phpBB/cron.php b/phpBB/cron.php index 36b771f1b7..df48c2dc4d 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -71,7 +71,7 @@ else output_image(); } -$cron_lock = new phpbb_lock_db('cron_lock', $config, $db); +$cron_lock = $container->get('cron.lock_db'); if ($cron_lock->acquire()) { if ($config['use_system_cron']) From 328d4f1820c372e6ae9ee6af60afb5e53a2f015e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adonais=20Romero=20Gonz=C3=A1lez?= Date: Thu, 5 Apr 2012 18:41:27 -0500 Subject: [PATCH 023/645] [ticket/10661] Added   to enumerated recipients (prosilver) Added missing   to enumerated recipients after IF statements to see if it is a group or not (to_recipient.IS_GROUP and bcc_recipient.ISGROUP), in posting_editor template in prosilver style. PHPBB3-10661 --- phpBB/styles/prosilver/template/posting_editor.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/styles/prosilver/template/posting_editor.html b/phpBB/styles/prosilver/template/posting_editor.html index 5f7fb8408e..fc98a95a17 100644 --- a/phpBB/styles/prosilver/template/posting_editor.html +++ b/phpBB/styles/prosilver/template/posting_editor.html @@ -17,7 +17,7 @@
- {to_recipient.NAME} {to_recipient.NAME_FULL}  + {to_recipient.NAME}{to_recipient.NAME_FULL}   
@@ -29,7 +29,7 @@
- {bcc_recipient.NAME}{bcc_recipient.NAME_FULL}  + {bcc_recipient.NAME}{bcc_recipient.NAME_FULL}   
@@ -50,7 +50,7 @@
- {to_recipient.NAME}{to_recipient.NAME_FULL}  + {to_recipient.NAME}{to_recipient.NAME_FULL}   
From 2e76620c8824da62f97cfdaee8f9b1014159fd7c Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 00:22:55 +0200 Subject: [PATCH 024/645] [feature/dic] Rewrite cron system to use DIC PHPBB3-10739 --- phpBB/common.php | 37 +++++----- phpBB/config/cron_tasks.yml | 72 +++++++++++++++++++ phpBB/config/services.yml | 5 +- phpBB/download/file.php | 27 +++---- phpBB/includes/cron/manager.php | 36 ++-------- .../cron/task/core/prune_all_forums.php | 25 ++++--- phpBB/includes/cron/task/core/prune_forum.php | 44 +++++------- phpBB/includes/cron/task/core/queue.php | 18 +++-- phpBB/includes/cron/task/core/tidy_cache.php | 17 +++-- .../includes/cron/task/core/tidy_database.php | 15 ++-- phpBB/includes/cron/task/core/tidy_search.php | 24 ++++--- .../includes/cron/task/core/tidy_sessions.php | 14 ++-- .../includes/cron/task/core/tidy_warnings.php | 18 +++-- phpBB/includes/cron/task/provider.php | 45 ++++++------ phpBB/install/index.php | 21 +++--- phpBB/viewforum.php | 4 +- 16 files changed, 257 insertions(+), 165 deletions(-) create mode 100644 phpBB/config/cron_tasks.yml diff --git a/phpBB/common.php b/phpBB/common.php index 51478662d7..c9eb5d217b 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -88,42 +88,43 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -$container = new ContainerBuilder(); -$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/config')); +$phpbb_container = new ContainerBuilder(); +$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/config')); $loader->load('parameters.yml'); $loader->load('services.yml'); -$container->setParameter('core.root_path', $phpbb_root_path); -$container->setParameter('core.php_ext', $phpEx); +$phpbb_container->setParameter('core.root_path', $phpbb_root_path); +$phpbb_container->setParameter('core.php_ext', $phpEx); +$phpbb_container->set('container', $phpbb_container); // Setup class loader first -$phpbb_class_loader = $container->get('class_loader'); -$phpbb_class_loader_ext = $container->get('class_loader.ext'); +$phpbb_class_loader = $phpbb_container->get('class_loader'); +$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); // set up caching -$cache = $container->get('cache'); +$cache = $phpbb_container->get('cache'); // Instantiate some basic classes -$phpbb_dispatcher = $container->get('dispatcher'); -$request = $container->get('request'); -$user = $container->get('user'); -$auth = $container->get('auth'); -$db = $container->get('dbal.conn'); +$phpbb_dispatcher = $phpbb_container->get('dispatcher'); +$request = $phpbb_container->get('request'); +$user = $phpbb_container->get('user'); +$auth = $phpbb_container->get('auth'); +$db = $phpbb_container->get('dbal.conn'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function // Grab global variables, re-cache if necessary -$config = $container->get('config'); +$config = $phpbb_container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions -$phpbb_extension_manager = $container->get('ext.manager'); -$phpbb_subscriber_loader = $container->get('event.subscriber_loader'); +$phpbb_extension_manager = $phpbb_container->get('ext.manager'); +$phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); -$template = $container->get('template'); -$style = $container->get('style'); +$template = $phpbb_container->get('template'); +$style = $phpbb_container->get('style'); // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); @@ -136,5 +137,5 @@ foreach ($cache->obtain_hooks() as $hook) if (!$config['use_system_cron']) { - $cron = $container->get('cron.manager'); + $cron = $phpbb_container->get('cron.manager'); } diff --git a/phpBB/config/cron_tasks.yml b/phpBB/config/cron_tasks.yml new file mode 100644 index 0000000000..18a198fa27 --- /dev/null +++ b/phpBB/config/cron_tasks.yml @@ -0,0 +1,72 @@ +services: + cron.task.core.prune_all_forums: + class: phpbb_cron_task_core_prune_all_forums + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @dbal.conn + tags: + - { name: cron.task } + + cron.task.core.prune_forum: + class: phpbb_cron_task_core_prune_forum + arguments: + - %core.root_path% + - %core.php_ext% + - @config + - @dbal.conn + tags: + - { name: cron.task } + + cron.task.core.queue: + class: phpbb_cron_task_core_queue + arguments: + - %core.root_path% + - %core.php_ext% + - @config + tags: + - { name: cron.task } + + cron.task.core.tidy_cache: + class: phpbb_cron_task_core_tidy_cache + arguments: + - @config + - @cache.driver + tags: + - { name: cron.task } + + cron.task.core.tidy_database: + class: phpbb_cron_task_core_tidy_database + arguments: + - %core.root_path% + - %core.php_ext% + - @config + tags: + - { name: cron.task } + + cron.task.core.tidy_search: + class: phpbb_cron_task_core_tidy_search + arguments: + - %core.root_path% + - %core.php_ext% + - @config + tags: + - { name: cron.task } + + cron.task.core.tidy_sessions: + class: phpbb_cron_task_core_tidy_sessions + arguments: + - @config + - @user + tags: + - { name: cron.task } + + cron.task.core.tidy_warnings: + class: phpbb_cron_task_core_tidy_warnings + arguments: + - %core.root_path% + - %core.php_ext% + - @config + tags: + - { name: cron.task } diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 6817d8f015..f6e92112f7 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -1,3 +1,6 @@ +imports: + - { resource: cron_tasks.yml } + services: class_loader: class: phpbb_class_loader @@ -107,7 +110,7 @@ services: cron.task_provider: class: phpbb_cron_task_provider arguments: - - @ext.manager + - @container cron.manager: class: phpbb_cron_manager diff --git a/phpBB/download/file.php b/phpBB/download/file.php index eabb6edbbb..7213e3ac3f 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -44,23 +44,24 @@ if (isset($_GET['avatar'])) require($phpbb_root_path . 'includes/functions_download' . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); - $container = new ContainerBuilder(); - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); + $phpbb_container = new ContainerBuilder(); + $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader->load('parameters.yml'); $loader->load('services.yml'); - $container->setParameter('core.root_path', $phpbb_root_path); - $container->setParameter('core.php_ext', $phpEx); + $phpbb_container->setParameter('core.root_path', $phpbb_root_path); + $phpbb_container->setParameter('core.php_ext', $phpEx); + $phpbb_container->set('container', $phpbb_container); - $phpbb_class_loader = $container->get('class_loader'); - $phpbb_class_loader_ext = $container->get('class_loader.ext'); + $phpbb_class_loader = $phpbb_container->get('class_loader'); + $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); // set up caching - $cache = $container->get('cache'); + $cache = $phpbb_container->get('cache'); - $phpbb_dispatcher = $container->get('dispatcher'); - $request = $container->get('request'); - $db = $container->get('dbal.conn'); + $phpbb_dispatcher = $phpbb_container->get('dispatcher'); + $request = $phpbb_container->get('request'); + $db = $phpbb_container->get('dbal.conn'); // Connect to DB if (!@$db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, false)) @@ -71,13 +72,13 @@ if (isset($_GET['avatar'])) request_var('', 0, false, false, $request); - $config = $container->get('config'); + $config = $phpbb_container->get('config'); set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions - $phpbb_extension_manager = $container->get('ext.manager'); - $phpbb_subscriber_loader = $container->get('event.subscriber_loader'); + $phpbb_extension_manager = $phpbb_container->get('ext.manager'); + $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); // worst-case default $browser = strtolower($request->header('User-Agent', 'msie 6.0')); diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index 7a78a1b054..5abbc987dd 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -35,26 +35,25 @@ class phpbb_cron_manager /** * Constructor. Loads all available tasks. * - * @param array|Traversable $task_names Provides an iterable set of task names + * @param array|Traversable $tasks Provides an iterable set of task names */ - public function __construct($task_names) + public function __construct($tasks) { - $this->load_tasks($task_names); + $this->load_tasks($tasks); } /** * Loads tasks given by name, wraps them * and puts them into $this->tasks. * - * @param array|Traversable $task_names Array of strings + * @param array|Traversable $tasks Array of instances of phpbb_cron_task * * @return void */ - public function load_tasks($task_names) + public function load_tasks($tasks) { - foreach ($task_names as $task_name) + foreach ($tasks as $task) { - $task = new $task_name(); $wrapper = new phpbb_cron_task_wrapper($task); $this->tasks[] = $wrapper; } @@ -120,27 +119,4 @@ class phpbb_cron_manager } return null; } - - /** - * Creates an instance of parametrized cron task $name with args $args. - * The constructed task is wrapped with cron task wrapper before being returned. - * - * @param string $name The task name, which is the same as cron task class name. - * @param array $args Will be passed to the task class's constructor. - * - * @return phpbb_cron_task_wrapper|null - */ - public function instantiate_task($name, array $args) - { - $task = $this->find_task($name); - if ($task) - { - // task here is actually an instance of cron task wrapper - $class = $task->get_name(); - $task = new $class($args); - // need to wrap the new task too - $task = new phpbb_cron_task_wrapper($task); - } - return $task; - } } diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index 15b93a9ca6..f3a179d81b 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -26,6 +26,16 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config, $db; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, dbal $db) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->db = $db; + } + /** * Runs this cron task. * @@ -33,19 +43,17 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx, $db; - if (!function_exists('auto_prune')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq FROM ' . FORUMS_TABLE . " - WHERE enable_prune = 1 + WHERE enable_prune = 1 AND prune_next < " . time(); - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) + $result = $this->db->sql_query($sql); + while ($row = $this->db->sql_fetchrow($result)) { if ($row['prune_days']) { @@ -57,7 +65,7 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base auto_prune($row['forum_id'], 'viewed', $row['forum_flags'], $row['prune_viewed'], $row['prune_freq']); } } - $db->sql_freeresult($result); + $this->db->sql_freeresult($result); } /** @@ -69,7 +77,6 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base */ public function is_runnable() { - global $config; - return (bool) $config['use_system_cron']; + return (bool) $this->config['use_system_cron']; } } diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 7686fd4281..1f717904ef 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -26,31 +26,25 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements phpbb_cron_task_parametrized { + private $phpbb_root_path, $phpEx, $config, $db; private $forum_data; + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, dbal $db) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + $this->db = $db; + } + /** - * Constructor. - * - * If $forum_data is given, it is assumed to contain necessary information - * about a single forum that is to be pruned. - * - * If $forum_data is not given, forum id will be retrieved via request_var - * and a database query will be performed to load the necessary information - * about the forum. + * Manually set forum data. * * @param array $forum_data Information about a forum to be pruned. */ - public function __construct($forum_data = null) + public function set_forum_data($forum_data) { - global $db; - if ($forum_data) - { - $this->forum_data = $forum_data; - } - else - { - $this->forum_data = null; - } + $this->forum_data = $forum_data; } /** @@ -60,10 +54,9 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ public function run() { - global $phpbb_root_path, $phpEx; if (!function_exists('auto_prune')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } if ($this->forum_data['prune_days']) @@ -90,8 +83,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ public function is_runnable() { - global $config; - return !$config['use_system_cron'] && $this->forum_data; + return !$this->config['use_system_cron'] && $this->forum_data; } /** @@ -130,8 +122,6 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ public function parse_parameters(phpbb_request_interface $request) { - global $db; - $this->forum_data = null; if ($request->is_set('f')) { @@ -140,9 +130,9 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq FROM ' . FORUMS_TABLE . " WHERE forum_id = $forum_id"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $row = $this->db->sql_fetchrow($result); + $this->db->sql_freeresult($result); if ($row) { diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index 1c72eec7c7..70db94f31d 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -22,6 +22,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_queue extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -29,10 +38,9 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx; if (!class_exists('queue')) { - include($phpbb_root_path . 'includes/functions_messenger.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_messenger.' . $this->phpEx); } $queue = new queue(); $queue->process(); @@ -47,8 +55,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function is_runnable() { - global $phpbb_root_path, $phpEx; - return file_exists($phpbb_root_path . 'cache/queue.' . $phpEx); + return file_exists($this->phpbb_root_path . 'cache/queue.' . $this->phpEx); } /** @@ -61,7 +68,6 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['last_queue_run'] < time() - $config['queue_interval_config']; + return $this->config['last_queue_run'] < time() - $this->config['queue_interval_config']; } } diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index c9dc0bd9ae..530f25dacb 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -22,6 +22,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base { + private $config, $cache; + + public function __construct(phpbb_config $config, phpbb_cache_driver_interface $cache) + { + $this->config = $config; + $this->cache = $cache; + } + /** * Runs this cron task. * @@ -29,8 +37,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function run() { - global $cache; - $cache->tidy(); + $this->cache->tidy(); } /** @@ -43,8 +50,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function is_runnable() { - global $cache; - return method_exists($cache, 'tidy'); + return method_exists($this->cache, 'tidy'); } /** @@ -58,7 +64,6 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['cache_last_gc'] < time() - $config['cache_gc']; + return $this->config['cache_last_gc'] < time() - $this->config['cache_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index 80a1901b1e..910e27cf20 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -22,6 +22,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -29,10 +38,9 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx; if (!function_exists('tidy_database')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } tidy_database(); } @@ -48,7 +56,6 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['database_last_gc'] < time() - $config['database_gc']; + return $this->config['database_last_gc'] < time() - $this->config['database_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 8a0b1b690a..1b8a0b8151 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -24,6 +24,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -31,14 +40,12 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx, $config, $error; - // Select the search method - $search_type = basename($config['search_type']); + $search_type = basename($this->config['search_type']); if (!class_exists($search_type)) { - include("{$phpbb_root_path}includes/search/$search_type.$phpEx"); + include($this->phpbb_root_path . "includes/search/$search_type." . $this->phpEx); } // We do some additional checks in the module to ensure it can actually be utilised @@ -62,12 +69,10 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function is_runnable() { - global $phpbb_root_path, $phpEx, $config; - // Select the search method - $search_type = basename($config['search_type']); + $search_type = basename($this->config['search_type']); - return file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx); + return file_exists($this->phpbb_root_path . 'includes/search/' . $search_type . '.' . $this->phpEx); } /** @@ -81,7 +86,6 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['search_last_gc'] < time() - $config['search_gc']; + return $this->config['search_last_gc'] < time() - $this->config['search_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index ae7bb242b8..b409c93868 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -22,6 +22,14 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base { + private $config, $user; + + public function __construct(phpbb_config $config, phpbb_user $user) + { + $this->config = $config; + $this->user = $user; + } + /** * Runs this cron task. * @@ -29,8 +37,7 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base */ public function run() { - global $user; - $user->session_gc(); + $this->user->session_gc(); } /** @@ -44,7 +51,6 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['session_last_gc'] < time() - $config['session_gc']; + return $this->config['session_last_gc'] < time() - $this->config['session_gc']; } } diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index e1434e7087..3b87a300d0 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -24,6 +24,15 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base { + private $phpbb_root_path, $phpEx, $config; + + public function __construct($phpbb_root_path, $phpEx, phpbb_config $config) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->config = $config; + } + /** * Runs this cron task. * @@ -31,10 +40,9 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base */ public function run() { - global $phpbb_root_path, $phpEx; if (!function_exists('tidy_warnings')) { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + include($this->phpbb_root_path . 'includes/functions_admin.' . $this->phpEx); } tidy_warnings(); } @@ -48,8 +56,7 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base */ public function is_runnable() { - global $config; - return (bool) $config['warnings_expire_days']; + return (bool) $this->config['warnings_expire_days']; } /** @@ -63,7 +70,6 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base */ public function should_run() { - global $config; - return $config['warnings_last_gc'] < time() - $config['warnings_gc']; + return $this->config['warnings_last_gc'] < time() - $this->config['warnings_gc']; } } diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 1482051699..acc3d455ec 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -15,6 +15,8 @@ if (!defined('IN_PHPBB')) exit; } +use Symfony\Component\DependencyInjection\Container; + /** * Provides cron manager with tasks * @@ -22,27 +24,30 @@ if (!defined('IN_PHPBB')) * * @package phpBB3 */ -class phpbb_cron_task_provider extends phpbb_extension_provider +class phpbb_cron_task_provider implements IteratorAggregate { - /** - * Finds cron task names using the extension manager. - * - * All PHP files in includes/cron/task/core/ are considered tasks. Tasks - * in extensions have to be located in a directory called cron or a subdir - * of a directory called cron. The class and filename must end in a _task - * suffix. Additionally all PHP files in includes/cron/task/core/ are - * tasks. - * - * @return array List of task names - */ - protected function find() - { - $finder = $this->extension_manager->get_finder(); + private $container; - return $finder - ->extension_suffix('_task') - ->extension_directory('/cron') - ->core_path('includes/cron/task/core/') - ->get_classes(); + public function __construct(Container $container) + { + $this->container = $container; + } + + /** + * Retrieve an iterator over all items + * + * @return ArrayIterator An iterator for the array of cron tasks + */ + public function getIterator() + { + $definitions = $this->container->findTaggedServiceIds('cron.task'); + + $tasks = array(); + foreach ($definitions as $name => $definition) + { + $tasks[] = $this->container->get($name); + } + + return new ArrayIterator($tasks); } } diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 0d7a0a288c..dd84e2d519 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -79,23 +79,24 @@ include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); require($phpbb_root_path . 'includes/functions_install.' . $phpEx); -$container = new ContainerBuilder(); -$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); +$phpbb_container = new ContainerBuilder(); +$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); $loader->load('parameters.yml'); $loader->load('services.yml'); -$container->setParameter('core.root_path', $phpbb_root_path); -$container->setParameter('core.php_ext', $phpEx); -$container->setAlias('cache.driver.install', 'cache.driver'); +$phpbb_container->setParameter('core.root_path', $phpbb_root_path); +$phpbb_container->setParameter('core.php_ext', $phpEx); +$phpbb_container->setAlias('cache.driver.install', 'cache.driver'); +$phpbb_container->set('container', $phpbb_container); -$phpbb_class_loader = $container->get('class_loader'); -$phpbb_class_loader_ext = $container->get('class_loader.ext'); +$phpbb_class_loader = $phpbb_container->get('class_loader'); +$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); // set up caching -$cache = $container->get('cache'); +$cache = $phpbb_container->get('cache'); -$phpbb_dispatcher = $container->get('dispatcher'); -$request = $container->get('request'); +$phpbb_dispatcher = $phpbb_container->get('dispatcher'); +$request = $phpbb_container->get('request'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 2d91581cf4..16342ba1b3 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -193,7 +193,9 @@ if ($forum_data['forum_topics_per_page']) // Do the forum Prune thang - cron type job ... if (!$config['use_system_cron']) { - $task = $cron->instantiate_task('cron_task_core_prune_forum', $forum_data); + $task = $container->get('cron.task.core.prune_forum'); + $task = new phpbb_cron_task_wrapper($task); + $task->set_forum_data($forum_data); if ($task && $task->is_ready()) { $url = $task->get_url(); From aa0c995ed9cdafa2dfaca23b54d5b4cf6323f794 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 13:15:27 +0200 Subject: [PATCH 025/645] [feature/dic] Protect config directory via .htaccess PHPBB3-10739 --- phpBB/config/.htaccess | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 phpBB/config/.htaccess diff --git a/phpBB/config/.htaccess b/phpBB/config/.htaccess new file mode 100644 index 0000000000..aa5afc1640 --- /dev/null +++ b/phpBB/config/.htaccess @@ -0,0 +1,4 @@ + + Order Allow,Deny + Deny from All + \ No newline at end of file From 3896ee953fbdb45d0485c0b5dcdfca47409a22ed Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 14:34:35 +0200 Subject: [PATCH 026/645] [feature/dic] Give all cron tasks a name, change some manager usage PHPBB3-10739 --- phpBB/config/services.yml | 3 ++- phpBB/cron.php | 2 +- phpBB/includes/cron/manager.php | 15 ++++++++++++--- phpBB/includes/cron/task/base.php | 22 ++++++++++++++++++++++ phpBB/includes/cron/task/provider.php | 7 ++++++- phpBB/includes/cron/task/task.php | 7 +++++++ phpBB/includes/cron/task/wrapper.php | 20 ++++++-------------- phpBB/viewforum.php | 8 +++++--- 8 files changed, 61 insertions(+), 23 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index f6e92112f7..94d641ab8b 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -116,7 +116,8 @@ services: class: phpbb_cron_manager arguments: - @cron.task_provider - - @cache.driver + - %core.root_path% + - %core.php_ext% cron.lock_db: class: phpbb_lock_db diff --git a/phpBB/cron.php b/phpBB/cron.php index df48c2dc4d..be328db4de 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -61,7 +61,7 @@ function do_cron($cron_lock, $run_tasks) if ($config['use_system_cron']) { - $cron = new phpbb_cron_manager(new phpbb_cron_task_provider($phpbb_extension_manager), $cache->get_driver()); + $cron = $container->get('cron.manager'); } else { diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index 5abbc987dd..5ea909eb2c 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -32,13 +32,18 @@ class phpbb_cron_manager */ protected $tasks = array(); + protected $phpbb_root_path, $phpEx; + /** * Constructor. Loads all available tasks. * * @param array|Traversable $tasks Provides an iterable set of task names */ - public function __construct($tasks) + public function __construct($tasks, $phpbb_root_path, $phpEx) { + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + $this->load_tasks($tasks); } @@ -54,8 +59,7 @@ class phpbb_cron_manager { foreach ($tasks as $task) { - $wrapper = new phpbb_cron_task_wrapper($task); - $this->tasks[] = $wrapper; + $this->tasks[] = $this->wrap_task($task); } } @@ -119,4 +123,9 @@ class phpbb_cron_manager } return null; } + + public function wrap_task(phpbb_cron_task $task) + { + return new phpbb_cron_task_wrapper($task, $this->phpbb_root_path, $this->phpEx); + } } diff --git a/phpBB/includes/cron/task/base.php b/phpBB/includes/cron/task/base.php index c05fb9a87c..94a2f267b4 100644 --- a/phpBB/includes/cron/task/base.php +++ b/phpBB/includes/cron/task/base.php @@ -28,6 +28,28 @@ if (!defined('IN_PHPBB')) */ abstract class phpbb_cron_task_base implements phpbb_cron_task { + private $name; + + /** + * Returns the name of the task. + * + * @return string Name of wrapped task. + */ + public function get_name() + { + return $this->name; + } + + /** + * Sets the name of the task. + * + * @param string $name The task name + */ + public function set_name($name) + { + $this->name = $name; + } + /** * Returns whether this cron task can run, given current board configuration. * diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index acc3d455ec..9994d707f2 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -45,7 +45,12 @@ class phpbb_cron_task_provider implements IteratorAggregate $tasks = array(); foreach ($definitions as $name => $definition) { - $tasks[] = $this->container->get($name); + $task = $this->container->get($name); + if ($task instanceof phpbb_cron_task_base) { + $task->set_name($name); + } + + $tasks[] = $task; } return new ArrayIterator($tasks); diff --git a/phpBB/includes/cron/task/task.php b/phpBB/includes/cron/task/task.php index 2f2a9e51f9..7b08fed413 100644 --- a/phpBB/includes/cron/task/task.php +++ b/phpBB/includes/cron/task/task.php @@ -21,6 +21,13 @@ if (!defined('IN_PHPBB')) */ interface phpbb_cron_task { + /** + * Returns the name of the task. + * + * @return string Name of wrapped task. + */ + public function get_name(); + /** * Runs this cron task. * diff --git a/phpBB/includes/cron/task/wrapper.php b/phpBB/includes/cron/task/wrapper.php index 66c45189e5..75b7fbdaa3 100644 --- a/phpBB/includes/cron/task/wrapper.php +++ b/phpBB/includes/cron/task/wrapper.php @@ -23,6 +23,8 @@ if (!defined('IN_PHPBB')) */ class phpbb_cron_task_wrapper { + private $task, $phpbb_root_path, $phpEx; + /** * Constructor. * @@ -30,9 +32,11 @@ class phpbb_cron_task_wrapper * * @param phpbb_cron_task $task The cron task to wrap. */ - public function __construct(phpbb_cron_task $task) + public function __construct(phpbb_cron_task $task, $phpbb_root_path, $phpEx) { $this->task = $task; + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; } /** @@ -61,16 +65,6 @@ class phpbb_cron_task_wrapper return $this->task->is_runnable() && $this->task->should_run(); } - /** - * Returns the name of wrapped task. It is the same as the wrapped class's class name. - * - * @return string Class name of wrapped task. - */ - public function get_name() - { - return get_class($this->task); - } - /** * Returns a url through which this task may be invoked via web. * @@ -82,8 +76,6 @@ class phpbb_cron_task_wrapper */ public function get_url() { - global $phpbb_root_path, $phpEx; - $name = $this->get_name(); if ($this->is_parametrized()) { @@ -98,7 +90,7 @@ class phpbb_cron_task_wrapper { $extra = ''; } - $url = append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $name . $extra); + $url = append_sid($this->phpbb_root_path . 'cron.' . $this->phpEx, 'cron_type=' . $name . $extra); return $url; } diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 16342ba1b3..25c8f5aa6d 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -193,10 +193,12 @@ if ($forum_data['forum_topics_per_page']) // Do the forum Prune thang - cron type job ... if (!$config['use_system_cron']) { - $task = $container->get('cron.task.core.prune_forum'); - $task = new phpbb_cron_task_wrapper($task); + $cron = $container->get('cron.manager'); + + $task = $cron->find_task('cron.task.core.prune_forum'); $task->set_forum_data($forum_data); - if ($task && $task->is_ready()) + + if ($task->is_ready()) { $url = $task->get_url(); $template->assign_var('RUN_CRON_TASK', 'cron'); From 0a5348a1376fafb487884086a70069bea8c5640b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 14:37:04 +0200 Subject: [PATCH 027/645] [feature/dic] Rename occurances of $container to $phpbb_container PHPBB3-10739 --- phpBB/cron.php | 4 ++-- phpBB/viewforum.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/cron.php b/phpBB/cron.php index be328db4de..95d2f8f9b6 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -61,7 +61,7 @@ function do_cron($cron_lock, $run_tasks) if ($config['use_system_cron']) { - $cron = $container->get('cron.manager'); + $cron = $phpbb_container->get('cron.manager'); } else { @@ -71,7 +71,7 @@ else output_image(); } -$cron_lock = $container->get('cron.lock_db'); +$cron_lock = $phpbb_container->get('cron.lock_db'); if ($cron_lock->acquire()) { if ($config['use_system_cron']) diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 25c8f5aa6d..76d5c8ccff 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -193,7 +193,7 @@ if ($forum_data['forum_topics_per_page']) // Do the forum Prune thang - cron type job ... if (!$config['use_system_cron']) { - $cron = $container->get('cron.manager'); + $cron = $phpbb_container->get('cron.manager'); $task = $cron->find_task('cron.task.core.prune_forum'); $task->set_forum_data($forum_data); From 3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Mon, 9 Apr 2012 15:05:28 +0200 Subject: [PATCH 028/645] [feature/dic] Fix test suite for dic-powered cron PHPBB3-10739 --- phpBB/includes/cron/task/provider.php | 4 +- tests/cron/ext/testext/cron/dummy_task.php | 5 +++ .../includes/cron/task/core/dummy_task.php | 5 +++ .../cron/task/core/second_dummy_task.php | 5 +++ tests/cron/manager_test.php | 32 +++++++-------- tests/cron/task_provider_test.php | 41 ++++++++++++------- tests/cron/tasks/simple_not_runnable.php | 5 +++ tests/cron/tasks/simple_ready.php | 5 +++ tests/cron/tasks/simple_should_not_run.php | 5 +++ 9 files changed, 74 insertions(+), 33 deletions(-) diff --git a/phpBB/includes/cron/task/provider.php b/phpBB/includes/cron/task/provider.php index 9994d707f2..6adac77eb8 100644 --- a/phpBB/includes/cron/task/provider.php +++ b/phpBB/includes/cron/task/provider.php @@ -15,7 +15,7 @@ if (!defined('IN_PHPBB')) exit; } -use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\DependencyInjection\TaggedContainerInterface; /** * Provides cron manager with tasks @@ -28,7 +28,7 @@ class phpbb_cron_task_provider implements IteratorAggregate { private $container; - public function __construct(Container $container) + public function __construct(TaggedContainerInterface $container) { $this->container = $container; } diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php index 996f5b39cf..a31806c1b1 100644 --- a/tests/cron/ext/testext/cron/dummy_task.php +++ b/tests/cron/ext/testext/cron/dummy_task.php @@ -11,6 +11,11 @@ class phpbb_ext_testext_cron_dummy_task extends phpbb_cron_task_base { public static $was_run = 0; + public function get_name() + { + return get_class($this); + } + public function run() { self::$was_run++; diff --git a/tests/cron/includes/cron/task/core/dummy_task.php b/tests/cron/includes/cron/task/core/dummy_task.php index 6e2e2db636..ce3e91a9ba 100644 --- a/tests/cron/includes/cron/task/core/dummy_task.php +++ b/tests/cron/includes/cron/task/core/dummy_task.php @@ -11,6 +11,11 @@ class phpbb_cron_task_core_dummy_task extends phpbb_cron_task_base { public static $was_run = 0; + public function get_name() + { + return get_class($this); + } + public function run() { self::$was_run++; diff --git a/tests/cron/includes/cron/task/core/second_dummy_task.php b/tests/cron/includes/cron/task/core/second_dummy_task.php index 8cd0bddfc0..76a55588f9 100644 --- a/tests/cron/includes/cron/task/core/second_dummy_task.php +++ b/tests/cron/includes/cron/task/core/second_dummy_task.php @@ -11,6 +11,11 @@ class phpbb_cron_task_core_second_dummy_task extends phpbb_cron_task_base { public static $was_run = 0; + public function get_name() + { + return get_class($this); + } + public function run() { self::$was_run++; diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php index f433fc9a9b..8ed33b06e2 100644 --- a/tests/cron/manager_test.php +++ b/tests/cron/manager_test.php @@ -19,10 +19,10 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase { public function setUp() { - $this->manager = new phpbb_cron_manager(array( - 'phpbb_cron_task_core_dummy_task', - 'phpbb_cron_task_core_second_dummy_task', - 'phpbb_ext_testext_cron_dummy_task', + $this->manager = $this->create_cron_manager(array( + new phpbb_cron_task_core_dummy_task(), + new phpbb_cron_task_core_second_dummy_task(), + new phpbb_ext_testext_cron_dummy_task(), )); $this->task_name = 'phpbb_cron_task_core_dummy_task'; } @@ -34,13 +34,6 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase $this->assertEquals($this->task_name, $task->get_name()); } - public function test_manager_instantiates_task_by_name() - { - $task = $this->manager->instantiate_task($this->task_name, array()); - $this->assertInstanceOf('phpbb_cron_task_wrapper', $task); - $this->assertEquals($this->task_name, $task->get_name()); - } - public function test_manager_finds_all_ready_tasks() { $tasks = $this->manager->find_all_ready_tasks(); @@ -55,10 +48,10 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase public function test_manager_finds_only_ready_tasks() { - $manager = new phpbb_cron_manager(array( - 'phpbb_cron_task_core_simple_ready', - 'phpbb_cron_task_core_simple_not_runnable', - 'phpbb_cron_task_core_simple_should_not_run', + $manager = $this->create_cron_manager(array( + new phpbb_cron_task_core_simple_ready(), + new phpbb_cron_task_core_simple_not_runnable(), + new phpbb_cron_task_core_simple_should_not_run(), )); $tasks = $manager->find_all_ready_tasks(); $task_names = $this->tasks_to_names($tasks); @@ -70,8 +63,15 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase $names = array(); foreach ($tasks as $task) { - $names[] = get_class($task->task); + $names[] = $task->get_name(); } return $names; } + + private function create_cron_manager($tasks) + { + global $phpbb_root_path, $phpEx; + + return new phpbb_cron_manager($tasks, $phpbb_root_path, $phpEx); + } } diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php index 4547c61a55..4458d811a5 100644 --- a/tests/cron/task_provider_test.php +++ b/tests/cron/task_provider_test.php @@ -7,37 +7,48 @@ * */ -require_once dirname(__FILE__) . '/../mock/extension_manager.php'; +require_once dirname(__FILE__) . '/includes/cron/task/core/dummy_task.php'; +require_once dirname(__FILE__) . '/includes/cron/task/core/second_dummy_task.php'; +require_once dirname(__FILE__) . '/ext/testext/cron/dummy_task.php'; class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase { public function setUp() { - $this->extension_manager = new phpbb_mock_extension_manager( - dirname(__FILE__) . '/', - array( - 'testext' => array( - 'ext_name' => 'testext', - 'ext_active' => true, - 'ext_path' => 'ext/testext/' - ), - )); - $this->provider = new phpbb_cron_task_provider($this->extension_manager); + $this->tasks = array( + 'phpbb_cron_task_core_dummy_task', + 'phpbb_cron_task_core_second_dummy_task', + 'phpbb_ext_testext_cron_dummy_task', + ); + + $container = $this->getMock('Symfony\Component\DependencyInjection\TaggedContainerInterface'); + $container + ->expects($this->once()) + ->method('findTaggedServiceIds') + ->will($this->returnValue(array_flip($this->tasks))); + $container + ->expects($this->any()) + ->method('get') + ->will($this->returnCallback(function ($name) { + return new $name; + })); + + $this->provider = new phpbb_cron_task_provider($container); } public function test_manager_finds_shipped_tasks() { - $tasks = array(); + $task_names = array(); foreach ($this->provider as $task) { - $tasks[] = $task; + $task_names[] = $task->get_name(); } - sort($tasks); + sort($task_names); $this->assertEquals(array( 'phpbb_cron_task_core_dummy_task', 'phpbb_cron_task_core_second_dummy_task', 'phpbb_ext_testext_cron_dummy_task', - ), $tasks); + ), $task_names); } } diff --git a/tests/cron/tasks/simple_not_runnable.php b/tests/cron/tasks/simple_not_runnable.php index 837f28f1c0..56d484eacd 100644 --- a/tests/cron/tasks/simple_not_runnable.php +++ b/tests/cron/tasks/simple_not_runnable.php @@ -2,6 +2,11 @@ class phpbb_cron_task_core_simple_not_runnable extends phpbb_cron_task_base { + public function get_name() + { + return get_class($this); + } + public function run() { } diff --git a/tests/cron/tasks/simple_ready.php b/tests/cron/tasks/simple_ready.php index de5f10e491..8aa0507406 100644 --- a/tests/cron/tasks/simple_ready.php +++ b/tests/cron/tasks/simple_ready.php @@ -2,6 +2,11 @@ class phpbb_cron_task_core_simple_ready extends phpbb_cron_task_base { + public function get_name() + { + return get_class($this); + } + public function run() { } diff --git a/tests/cron/tasks/simple_should_not_run.php b/tests/cron/tasks/simple_should_not_run.php index c2a41616f6..58f6df2616 100644 --- a/tests/cron/tasks/simple_should_not_run.php +++ b/tests/cron/tasks/simple_should_not_run.php @@ -2,6 +2,11 @@ class phpbb_cron_task_core_simple_should_not_run extends phpbb_cron_task_base { + public function get_name() + { + return get_class($this); + } + public function run() { } From e6a1d37634fb9f9f53125460abdaf9c90d8858a7 Mon Sep 17 00:00:00 2001 From: Senky Date: Mon, 9 Apr 2012 16:23:42 +0200 Subject: [PATCH 029/645] [ticket/9918] $redirect variable used from now According to comment marc1706 added to tracker http://tracker.phpbb.com/browse/PHPBB3-9918?focusedCommentId=35120&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-35120 I changed files to fit his second advice - redirect is kept in hidden_fields and other code changed. PHPBB3-9918 --- phpBB/includes/mcp/mcp_forum.php | 4 ++-- phpBB/includes/mcp/mcp_topic.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index fec1edc872..889e0a368c 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -433,7 +433,7 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id) confirm_box(false, 'MERGE_TOPICS', $s_hidden_fields); } - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id"); $redirect = reapply_sid($redirect); if (!$success_msg) @@ -442,7 +442,7 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id) } else { - meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id")); + meta_refresh(3, $redirect); trigger_error($user->lang[$success_msg] . '

' . $return_link); } } diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index d4ba89b04c..7ed4908280 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -529,7 +529,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $s_hidden_fields); } - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id"); $redirect = reapply_sid($redirect); if (!$success_msg) @@ -538,7 +538,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) } else { - meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id")); + meta_refresh(3, $redirect); trigger_error($user->lang[$success_msg] . '

' . $return_link); } } @@ -635,7 +635,7 @@ function merge_posts($topic_id, $to_topic_id) confirm_box(false, 'MERGE_POSTS', $s_hidden_fields); } - $redirect = request_var('redirect', "index.$phpEx"); + $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id"); $redirect = reapply_sid($redirect); if (!$success_msg) @@ -644,7 +644,7 @@ function merge_posts($topic_id, $to_topic_id) } else { - meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id")); + meta_refresh(3, $redirect); trigger_error($user->lang[$success_msg] . '

' . $return_link); } } From 807eccc97632ea8beee4485ef926e4436da2554c Mon Sep 17 00:00:00 2001 From: Senky Date: Sun, 15 Apr 2012 19:13:08 +0200 Subject: [PATCH 030/645] [ticket/9918] default values in request_var changed to one string As per marc1706's note, all request_var functions now have only one string in default value PHPBB3-9918 --- phpBB/includes/mcp/mcp_forum.php | 2 +- phpBB/includes/mcp/mcp_topic.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 889e0a368c..4e40af934c 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -433,7 +433,7 @@ function merge_topics($forum_id, $topic_ids, $to_topic_id) confirm_box(false, 'MERGE_TOPICS', $s_hidden_fields); } - $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id"); + $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&t=$to_topic_id"); $redirect = reapply_sid($redirect); if (!$success_msg) diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index 7ed4908280..e96c025795 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -529,7 +529,7 @@ function split_topic($action, $topic_id, $to_forum_id, $subject) confirm_box(false, ($action == 'split_all') ? 'SPLIT_TOPIC_ALL' : 'SPLIT_TOPIC_BEYOND', $s_hidden_fields); } - $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id"); + $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&t=$to_topic_id"); $redirect = reapply_sid($redirect); if (!$success_msg) @@ -635,7 +635,7 @@ function merge_posts($topic_id, $to_topic_id) confirm_box(false, 'MERGE_POSTS', $s_hidden_fields); } - $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx", "f=$to_forum_id&t=$to_topic_id"); + $redirect = request_var('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&t=$to_topic_id"); $redirect = reapply_sid($redirect); if (!$success_msg) From 953e829b527acd6de80fee93bb1bfd08c6010c51 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 25 Mar 2012 20:57:35 -0400 Subject: [PATCH 031/645] [feature/prune-users] Non-cosmetic changes per bantu's review. PHPBB3-9622 --- phpBB/includes/acp/acp_prune.php | 1 + phpBB/includes/functions_user.php | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/acp/acp_prune.php b/phpBB/includes/acp/acp_prune.php index 145c0c3854..101eb5a1ed 100644 --- a/phpBB/includes/acp/acp_prune.php +++ b/phpBB/includes/acp/acp_prune.php @@ -343,6 +343,7 @@ class acp_prune { $s_group_list .= '
- + diff --git a/phpBB/common.php b/phpBB/common.php index c7c5859c25..fc2b9ae21e 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -119,7 +119,7 @@ set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions -$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); +$phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); // Initialize style $phpbb_style_resource_locator = new phpbb_style_resource_locator(); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index b56d729a7b..706df6abab 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -77,7 +77,7 @@ if (isset($_GET['avatar'])) set_config_count(null, null, null, $config); // load extensions - $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); + $phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index c4d9497956..ce32640c33 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -25,7 +25,7 @@ class acp_extensions function main() { // Start the page - global $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx; + global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx; $user->add_lang(array('install', 'acp/extensions')); @@ -34,6 +34,17 @@ class acp_extensions $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); + // If they've specificed an extension, let's load the metadata manager and validate it. + if ($ext_name) + { + $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template, $config); + + if ($md_manager->get_metadata('all') === false) + { + trigger_error('EXTENSION_INVALID'); + } + } + // What are we doing? switch ($action) { @@ -47,6 +58,11 @@ class acp_extensions break; case 'enable_pre': + if (!$md_manager->validate_enable()) + { + trigger_error('EXTENSION_NOT_AVAILABLE'); + } + $this->tpl_name = 'acp_ext_enable'; $template->assign_vars(array( @@ -56,10 +72,15 @@ class acp_extensions break; case 'enable': + if (!$md_manager->validate_enable()) + { + trigger_error('EXTENSION_NOT_AVAILABLE'); + } + if ($phpbb_extension_manager->enable_step($ext_name)) { $template->assign_var('S_NEXT_STEP', true); - + meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . $ext_name); } @@ -76,14 +97,14 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . $ext_name, - )); - break; + )); + break; case 'disable': if ($phpbb_extension_manager->disable_step($ext_name)) { $template->assign_var('S_NEXT_STEP', true); - + meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . $ext_name); } @@ -101,13 +122,13 @@ class acp_extensions 'PRE' => true, 'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . $ext_name, )); - break; + break; case 'purge': if ($phpbb_extension_manager->purge_step($ext_name)) { $template->assign_var('S_NEXT_STEP', true); - + meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . $ext_name); } @@ -132,12 +153,8 @@ class acp_extensions break;*/ case 'details': - $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template); - - if ($md_manager->get_metadata('all', true) === false) - { - trigger_error('EXTENSION_INVALID'); - } + // Output it to the template + $md_manager->output_template_data(); $this->tpl_name = 'acp_ext_details'; break; @@ -146,7 +163,7 @@ class acp_extensions /** * Lists all the enabled extensions and dumps to the template - * + * * @param $phpbb_extension_manager An instance of the extension manager * @param $template An instance of the template engine * @return null @@ -156,7 +173,7 @@ class acp_extensions foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); - + $template->assign_block_vars('enabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -169,7 +186,7 @@ class acp_extensions /** * Lists all the disabled extensions and dumps to the template - * + * * @param $phpbb_extension_manager An instance of the extension manager * @param $template An instance of the template engine * @return null @@ -179,7 +196,7 @@ class acp_extensions foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); - + $template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -193,7 +210,7 @@ class acp_extensions /** * Lists all the available extensions and dumps to the template - * + * * @param $phpbb_extension_manager An instance of the extension manager * @param $template An instance of the template engine * @return null diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index e7ceef6ad5..9dfc0a067c 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -23,6 +23,7 @@ if (!defined('IN_PHPBB')) class phpbb_extension_manager { protected $db; + protected $config; protected $cache; protected $php_ext; protected $extensions; @@ -34,16 +35,18 @@ class phpbb_extension_manager * Creates a manager and loads information from database * * @param dbal $db A database connection + * @param phpbb_config $config phpbb_config * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(dbal $db, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(dbal $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; + $this->config = $config; $this->cache = $cache; $this->php_ext = $php_ext; $this->extension_table = $extension_table; @@ -130,7 +133,7 @@ class phpbb_extension_manager */ public function get_extension_metadata($name, phpbb_template $template) { - return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->phpEx, $template); + return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->php_ext, $template, $this->config); } /** diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 6af02e47b7..0e0b609a68 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -31,18 +31,71 @@ class phpbb_extension_metadata_manager public $metadata; protected $metadata_file; + /** + * Array of validation regular expressions, see __call() + * + * @var mixed + */ + protected $validation = array( + 'name' => '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', + 'type' => '#^phpbb3-extension$#', + 'description' => '#.*#', + 'version' => '#.+#', + 'licence' => '#.+#', + 'extra' => array( + 'display-name' => '#.*#', + ), + ); + + /** + * Magic method to catch validation calls + * + * @param string $name + * @param mixed $arguments + * @return int + */ + public function __call($name, $arguments) + { + // Validation Magic methods + if (strpos($name, 'validate_') === 0) + { + // Remove validate_ + $name = substr($name, 9); + + // Replace underscores with dashes (underscores are not used) + $name = str_replace('_', '-', $name); + + if (strpos($name, 'extra-') === 0) + { + // Remove extra_ + $name = substr($name, 6); + + if (isset($this->validation['extra'][$name])) + { + // Extra means it's optional, so return true if it does not exist + return (isset($this->metadata['extra'][$name])) ? preg_match($this->validation['extra'][$name], $this->metadata['extra'][$name]) : true; + } + } + else if (isset($this->validation[$name])) + { + return preg_match($this->validation[$name], $this->metadata[$name]); + } + } + } + /** * Creates the metadata manager - * + * * @param dbal $db A database connection * @param string $extension_manager An instance of the phpbb extension manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension */ - public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template) + public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; + $this->config = $config; $this->phpEx = $phpEx; $this->template = $template; $this->extension_manager = $extension_manager; @@ -53,12 +106,11 @@ class phpbb_extension_metadata_manager /** * Processes and gets the metadata requested - * - * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @param boolean $template_output True if you want the requested metadata assigned to template vars (only works on the 'all" case - * @return array Contains all of the requested metadata + * + * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. + * @return bool|array Contains all of the requested metadata or bool False if not valid */ - public function get_metadata($element = 'all', $template_output = false) + public function get_metadata($element = 'all') { // TODO: Check ext_name exists and is an extension that exists if (!$this->set_metadata_file()) @@ -66,34 +118,37 @@ class phpbb_extension_metadata_manager return false; } + // Fetch the metadata if (!$this->fetch_metadata()) { return false; } - switch ($element) + // Clean the metadata + if (!$this->clean_metadata_array()) + { + return false; + } + + switch ($element) { case 'all': default: - if (!$this->clean_metadata_array()) + // Validate the metadata + if (!$this->validate_metadata_array()) { return false; } - if ($template_output) - { - $this->output_template_data(); - } - return $this->metadata; break; - + case 'name': return ($this->validate_name()) ? $this->metadata['name'] : false; break; - + case 'display-name': - if ($this->validate_extra_display_name()) + if (isset($this->metadata['extra']['display-name']) && $this->validate_extra_display_name()) { return $this->metadata['extra']['display-name']; } @@ -108,7 +163,7 @@ class phpbb_extension_metadata_manager /** * Sets the filepath of the metadata file - * + * * @return boolean Set to true if it exists */ private function set_metadata_file() @@ -129,19 +184,41 @@ class phpbb_extension_metadata_manager } /** - * This array handles the validation and cleaning of the array - * - * @return array Contains the cleaned and validated metadata array + * Gets the contents of the composer.json file + * + * @return bool True of false (if loading succeeded or failed) */ - private function clean_metadata_array() - { - if (!$this->validate_name() || !$this->validate_type() || !$this->validate_licence() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) + private function fetch_metadata() + { + if (!file_exists($this->metadata_file)) { return false; } - - $this->check_for_optional(true); + else + { + if (!($file_contents = file_get_contents($this->metadata_file))) + { + return false; + } + if (($metadata = json_decode($file_contents, true)) === NULL) + { + return false; + } + + $this->metadata = $metadata; + + return true; + } + } + + /** + * This array handles the validation and cleaning of the array + * + * @return array Contains the cleaned and validated metadata array + */ + private function clean_metadata_array() + { // TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors // $this->metadata = $metadata_finished; @@ -149,102 +226,114 @@ class phpbb_extension_metadata_manager } /** - * Validates the contents of the name field - * - * @return boolean True when passes validation + * This array handles the validation of strings + * + * @return bool True if validation succeeded, False if failed */ - private function validate_name() + public function validate_metadata_array() { - return preg_match('#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', $this->metadata['name']); + $validate = array( + 'name', + 'type', + 'licence', + 'description', + 'version', + 'extra_display-name', + ); + + foreach ($validate as $type) + { + $type = 'validate_' . $type; + + if (!$this->$type()) + { + return false; + } + } + + return true; } /** - * Validates the contents of the type field - * - * @return boolean True when passes validation + * This array handles the verification that this extension can be enabled on this board + * + * @return bool True if validation succeeded, False if failed */ - private function validate_type() + public function validate_enable() { - return $this->metadata['type'] == 'phpbb3-extension'; + $validate = array( + 'require_phpbb', + 'require_php', + ); + + foreach ($validate as $type) + { + $type = 'validate_' . $type; + + if (!$this->$type()) + { + return false; + } + } + + return true; } - /** - * Validates the contents of the description field - * - * @return boolean True when passes validation - */ - private function validate_description() - { - return true;//preg_match('#^{10,}$#', $this->metadata['description']); - } - - /** - * Validates the contents of the version field - * - * @return boolean True when passes validation - */ - private function validate_version() - { - return preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}#', $this->metadata['version']); - } - - /** - * Validates the contents of the license field - * - * @return boolean True when passes validation - */ - private function validate_licence() - { - // Nothing to validate except existence - return isset($this->metadata['licence']); - } /** * Validates the contents of the phpbb requirement field - * + * * @return boolean True when passes validation */ private function validate_require_phpbb() { - return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb'], '3.1.0', '>=')); - } - - /** - * Validates the contents of the display name field - * - * @return boolean True when passes validation - */ - private function validate_extra_display_name() - { - return true;//preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); - } - - /** - * Checks which optional fields exist - * - * @return boolean False if any that exist fail validation, otherwise true. - */ - public function check_for_optional() - { - if ((isset($this->metadata['require']['php']) && !$this->validate_require_php()) || (isset($this->metadata['time']) && !$this->validate_time()) || (isset($this->metadata['validate_homepage']) && !$this->validate_homepage())) + if (!isset($this->metadata['require']['phpbb'])) { - return false; + return true; } + + return $this->_validate_version($this->metadata['require']['phpbb'], $this->config['version']); } /** * Validates the contents of the php requirement field - * + * * @return boolean True when passes validation */ private function validate_require_php() { - return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['php']) && version_compare($this->metadata['require']['php'], phpversion(), '>=')); + if (!isset($this->metadata['require']['php'])) + { + return true; + } + + return $this->_validate_version($this->metadata['require']['php'], phpversion()); + } + + /** + * Version validation helper + * + * @param string $string The string for comparing to a version + * @param string $current_version The version to compare to + * @return bool True/False if meets version requirements + */ + private function _validate_version($string, $current_version) + { + // Allow them to specify their own comparison operator (ex: <3.1.2, >=3.1.0) + $comparison_matches = false; + preg_match('#[=<>]+#', $string, $comparison_matches); + + if (!empty($comparison_matches)) + { + return version_compare($current_version, str_replace(array($comparison_matches[0], ' '), '', $string), $comparison_matches[0]); + } + + return version_compare($current_version, $string, '>='); } /** * Validates the contents of the time field - * + * * @return boolean True when passes validation */ private function validate_time() @@ -255,7 +344,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the homepage field - * + * * @return boolean True when passes validation */ private function validate_homepage() @@ -265,7 +354,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the authors field - * + * * @return boolean True when passes validation */ private function validate_authors() @@ -291,38 +380,9 @@ class phpbb_extension_metadata_manager return true; } - /** - * Gets the contents of the composer.json file - * - * @return bool True of false (if loading succeeded or failed) - */ - private function fetch_metadata() - { - if (!file_exists($this->metadata_file)) - { - return false; - } - else - { - if (!($file_contents = file_get_contents($this->metadata_file))) - { - return false; - } - - if (($metadata = json_decode($file_contents, true)) === NULL) - { - return false; - } - - $this->metadata = $metadata; - - return true; - } - } - /** * Outputs the metadata into the template - * + * * @return null */ public function output_template_data() @@ -350,7 +410,7 @@ class phpbb_extension_metadata_manager 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); } - + return; } } diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 502b3bb1a4..0b470ced26 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -683,12 +683,12 @@ function _write_result($no_updates, $errored, $error_ary) function _add_modules($modules_to_install) { - global $phpbb_root_path, $phpEx, $db, $phpbb_extension_manager; + global $phpbb_root_path, $phpEx, $db, $phpbb_extension_manager, $config; // modules require an extension manager if (empty($phpbb_extension_manager)) { - $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx"); + $phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx"); } include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 23593ee51f..9162d5ab60 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -250,7 +250,7 @@ class install_install extends module 'S_EXPLAIN' => true, 'S_LEGEND' => false, )); - + // Check for php json support if (@extension_loaded('json')) { @@ -1481,12 +1481,12 @@ class install_install extends module */ function add_modules($mode, $sub) { - global $db, $lang, $phpbb_root_path, $phpEx, $phpbb_extension_manager; + global $db, $lang, $phpbb_root_path, $phpEx, $phpbb_extension_manager, $config; // modules require an extension manager if (empty($phpbb_extension_manager)) { - $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx"); + $phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx"); } include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 66f3665757..547d14d2b9 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -1,11 +1,11 @@ 'Extension', - 'EXTENSIONS' => 'Extensions', - 'EXTENSIONS_ADMIN' => 'Extensions Manager', - 'EXTENSIONS_EXPLAIN' => 'The Extensions Manager is a tool in your phpBB Board which allows you to manage all of your extensions statuses and view information about them.', - 'EXTENSION_INVALID' => 'The selected extension is not valid.', + 'EXTENSION' => 'Extension', + 'EXTENSIONS' => 'Extensions', + 'EXTENSIONS_ADMIN' => 'Extensions Manager', + 'EXTENSIONS_EXPLAIN' => 'The Extensions Manager is a tool in your phpBB Board which allows you to manage all of your extensions statuses and view information about them.', + 'EXTENSION_INVALID' => 'The selected extension is not valid.', + 'EXTENSION_NOT_AVAILABLE' => 'The selected extension is not available for this board, please verify your phpBB and PHP versions are allowed (see the details page).', 'DETAILS' => 'Details', @@ -63,27 +64,27 @@ $lang = array_merge($lang, array( 'DISABLE_IN_PROGRESS' => 'The extension is currently being disabled, please do not leave this page or refresh until it is completed.', 'ENABLE_IN_PROGRESS' => 'The extension is currently being installed, please do not leave this page or refresh until it is completed.', 'PURGE_IN_PROGRESS' => 'The extension is currently being purged, please do not leave this page or refresh until it is completed.', - 'ENABLE_SUCCESS' => 'The extension was enabled successfully', + 'ENABLE_SUCCESS' => 'The extension was enabled successfully', 'DISABLE_SUCCESS' => 'The extension was disabled successfully', 'PURGE_SUCCESS' => 'The extension was purged successfully', - 'DELETE_SUCCESS' => 'The extension was deleted successfully', + 'DELETE_SUCCESS' => 'The extension was deleted successfully', 'ENABLE_FAIL' => 'The extension could not be enabled', 'DISABLE_FAIL' => 'The extension could not be disabled', 'PURGE_FAIL' => 'The extension could not be purged', 'DELETE_FAIL' => 'The extension could not be deleted', - 'EXTENSION_NAME' => 'Extension Name', - 'EXTENSION_ACTIONS' => 'Actions', - 'EXTENSION_OPTIONS' => 'Options', + 'EXTENSION_NAME' => 'Extension Name', + 'EXTENSION_ACTIONS' => 'Actions', + 'EXTENSION_OPTIONS' => 'Options', - 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', - 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', - 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This cannot be undone.', - 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', + 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', + 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', + 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This cannot be undone.', + 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', - 'WARNING' => 'Warning', - 'RETURN' => 'Return', + 'WARNING' => 'Warning', + 'RETURN' => 'Return', 'EXT_DETAILS' => 'Extension Details', 'DISPLAY_NAME' => 'Display Name', From 4314284de12ceac5ae0792f3f4014b765d75d332 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:22:48 -0500 Subject: [PATCH 232/645] [ticket/10631] Remove code duplication PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 0e0b609a68..c5e9baf1e7 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -232,22 +232,29 @@ class phpbb_extension_metadata_manager */ public function validate_metadata_array() { - $validate = array( - 'name', - 'type', - 'licence', - 'description', - 'version', - 'extra_display-name', - ); - - foreach ($validate as $type) + foreach ($this->validation as $name => $regex) { - $type = 'validate_' . $type; - - if (!$this->$type()) + if (is_array($regex)) { - return false; + foreach ($regex as $extra_name => $extra_regex) + { + $type = 'validate_' . $name . '_' . $extra_name; + + if (!$this->$type()) + { + return false; + } + } + } + else + { + + $type = 'validate_' . $name; + + if (!$this->$type()) + { + return false; + } } } From 8df9963fcc7e2962b6b4e1e32e809f2d8fe00835 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:39:13 -0500 Subject: [PATCH 233/645] [ticket/10631] Additional validation PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 76 ++++++------------- 1 file changed, 25 insertions(+), 51 deletions(-) diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index c5e9baf1e7..d2dc72e5fc 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -42,6 +42,7 @@ class phpbb_extension_metadata_manager 'description' => '#.*#', 'version' => '#.+#', 'licence' => '#.+#', + //'homepage' => '#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(? array( 'display-name' => '#.*#', ), @@ -76,7 +77,7 @@ class phpbb_extension_metadata_manager return (isset($this->metadata['extra'][$name])) ? preg_match($this->validation['extra'][$name], $this->metadata['extra'][$name]) : true; } } - else if (isset($this->validation[$name])) + else if (isset($this->validation[$name]) && isset($this->metadata[$name])) { return preg_match($this->validation[$name], $this->metadata[$name]); } @@ -258,6 +259,29 @@ class phpbb_extension_metadata_manager } } + return $this->validate_authors(); + } + + /** + * Validates the contents of the authors field + * + * @return boolean True when passes validation + */ + private function validate_authors() + { + if (empty($this->metadata['authors'])) + { + return false; + } + + foreach ($this->metadata['authors'] as $author) + { + if (!isset($author['name'])) + { + return false; + } + } + return true; } @@ -338,55 +362,6 @@ class phpbb_extension_metadata_manager return version_compare($current_version, $string, '>='); } - /** - * Validates the contents of the time field - * - * @return boolean True when passes validation - */ - private function validate_time() - { - // Need to validate - return true; - } - - /** - * Validates the contents of the homepage field - * - * @return boolean True when passes validation - */ - private function validate_homepage() - { - return preg_match('#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?metadata['homepage']); - } - - /** - * Validates the contents of the authors field - * - * @return boolean True when passes validation - */ - private function validate_authors() - { - // Need to validate - $number_authors = sizeof($this->metadata['authors']); // Might be helpful later on - - if (!isset($this->metadata['authors']['1'])) - { - return false; - } - else - { - foreach ($this->metadata['authors'] as $author) - { - if (!isset($author['name'])) - { - return false; - } - } - } - - return true; - } - /** * Outputs the metadata into the template * @@ -394,7 +369,6 @@ class phpbb_extension_metadata_manager */ public function output_template_data() { - $this->template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), 'MD_TYPE' => htmlspecialchars($this->metadata['type']), From 9c0cd2693fd61c9528aa5fcbc3dff9de73515ebe Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 16:04:29 -0500 Subject: [PATCH 234/645] [ticket/10631] Make the enable/disable/purge notices more visable. PHPBB3-10631 --- phpBB/adm/style/acp_ext_disable.html | 12 +++++++----- phpBB/adm/style/acp_ext_enable.html | 12 +++++++----- phpBB/adm/style/acp_ext_purge.html | 12 +++++++----- phpBB/language/en/acp/extensions.php | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/phpBB/adm/style/acp_ext_disable.html b/phpBB/adm/style/acp_ext_disable.html index e47ba2d8b9..1f0bbe14c8 100644 --- a/phpBB/adm/style/acp_ext_disable.html +++ b/phpBB/adm/style/acp_ext_disable.html @@ -6,13 +6,15 @@

{L_EXTENSIONS_EXPLAIN}

{L_ENABLE_EXPLAIN}

- - -

{L_DISABLE_CONFIRM}

- + + +
+

{L_DISABLE_CONFIRM}

+
+
- {L_DISABLE} + {L_DISABLE}
diff --git a/phpBB/adm/style/acp_ext_enable.html b/phpBB/adm/style/acp_ext_enable.html index 4b0f8bfdd7..9f278bfbe0 100644 --- a/phpBB/adm/style/acp_ext_enable.html +++ b/phpBB/adm/style/acp_ext_enable.html @@ -6,13 +6,15 @@

{L_EXTENSIONS_EXPLAIN}

{L_ENABLE_EXPLAIN}

- - -

{L_ENABLE_CONFIRM}

- + + +
+

{L_ENABLE_CONFIRM}

+
+
- {L_ENABLE} + {L_ENABLE}
diff --git a/phpBB/adm/style/acp_ext_purge.html b/phpBB/adm/style/acp_ext_purge.html index 7255057d04..816fd872b9 100644 --- a/phpBB/adm/style/acp_ext_purge.html +++ b/phpBB/adm/style/acp_ext_purge.html @@ -6,13 +6,15 @@

{L_EXTENSIONS_EXPLAIN}

{L_ENABLE_EXPLAIN}

- - -

{L_PURGE_CONFIRM}

- + + +
+

{L_PURGE_CONFIRM}

+
+
- {L_PURGE} + {L_PURGE}
diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 547d14d2b9..a16e13d979 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -80,7 +80,7 @@ $lang = array_merge($lang, array( 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', - 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This cannot be undone.', + 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This will remove all settings stored for this extension and cannot be undone!', 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', 'WARNING' => 'Warning', From 2273ae2b34071160ff930ca8d49326b8dd308899 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 17:05:03 -0500 Subject: [PATCH 235/645] [ticket/10631] Remove references to delete extension PHPBB3-10631 --- phpBB/adm/style/acp_ext_delete.html | 27 --------------------------- phpBB/adm/style/acp_ext_list.html | 5 ++--- phpBB/includes/acp/acp_extensions.php | 15 --------------- phpBB/language/en/acp/extensions.php | 5 ----- 4 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 phpBB/adm/style/acp_ext_delete.html diff --git a/phpBB/adm/style/acp_ext_delete.html b/phpBB/adm/style/acp_ext_delete.html deleted file mode 100644 index f9a52861e5..0000000000 --- a/phpBB/adm/style/acp_ext_delete.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

-

{L_ENABLE_EXPLAIN}

- - -

{L_DELETE_CONFIRM}

- -
-
- {L_DELETE} - -
-
- -
-

{L_DELETE_SUCCESS}

-
-

{L_RETURN}

-
- - - diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index ef3bbb87cc..b3b1b84949 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -40,12 +40,11 @@ {disabled.EXT_NAME} {L_DETAILS} {L_ENABLE}  - {L_PURGE}  - {L_DELETE} + {L_PURGE}  - + diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index ce32640c33..0e1d5c88a8 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -139,19 +139,6 @@ class acp_extensions )); break; - /*case 'delete_pre': - $this->tpl_name = 'acp_ext_delete'; - - $template->assign_vars(array( - 'PRE' => true, - 'U_DELETE' => $this->u_action . '&action=delete&ext_name=' . $ext_name, - )); - break; - - case 'delete': - $this->tpl_name = 'acp_ext_delete'; - break;*/ - case 'details': // Output it to the template $md_manager->output_template_data(); @@ -202,7 +189,6 @@ class acp_extensions 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, - //'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $name, 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, )); } @@ -227,7 +213,6 @@ class acp_extensions 'EXT_NAME' => $md_manager->get_metadata('display-name'), 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, - //'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $name, 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, )); } diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index a16e13d979..903ec249a8 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -48,13 +48,11 @@ $lang = array_merge($lang, array( 'ENABLED' => 'Enabled', 'DISABLED' => 'Disabled', 'PURGED' => 'Purged', - 'DELETED' => 'Deleted', 'UPLOADED' => 'Uploaded', 'ENABLE' => 'Enable', 'DISABLE' => 'Disable', 'PURGE' => 'Purge', - 'DELETE' => 'Delete', 'ENABLE_EXPLAIN' => 'Enabling an extension allows you to use it on your board.', 'DISABLE_EXPLAIN' => 'Disabling an extension retains its files and settings but removes any functionality added by the extension.', @@ -67,12 +65,10 @@ $lang = array_merge($lang, array( 'ENABLE_SUCCESS' => 'The extension was enabled successfully', 'DISABLE_SUCCESS' => 'The extension was disabled successfully', 'PURGE_SUCCESS' => 'The extension was purged successfully', - 'DELETE_SUCCESS' => 'The extension was deleted successfully', 'ENABLE_FAIL' => 'The extension could not be enabled', 'DISABLE_FAIL' => 'The extension could not be disabled', 'PURGE_FAIL' => 'The extension could not be purged', - 'DELETE_FAIL' => 'The extension could not be deleted', 'EXTENSION_NAME' => 'Extension Name', 'EXTENSION_ACTIONS' => 'Actions', @@ -81,7 +77,6 @@ $lang = array_merge($lang, array( 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This will remove all settings stored for this extension and cannot be undone!', - 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', 'WARNING' => 'Warning', 'RETURN' => 'Return', From 106c105113886f9a9e603dbb11549c06049b255f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 18:22:35 -0500 Subject: [PATCH 236/645] [ticket/10631] Fix some issues as noted in github comments, significantly simplified validation PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 64 ++++---- phpBB/includes/acp/acp_extensions.php | 12 +- phpBB/includes/extension/manager.php | 2 +- phpBB/includes/extension/metadata_manager.php | 146 ++++++------------ 4 files changed, 83 insertions(+), 141 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index 5af9603a75..7408e88758 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -16,36 +16,35 @@
{MD_NAME}
-
-
-

{MD_TYPE}

-
+

{MD_DESCRIPTION}

+

{MD_VERSION}

+

{MD_HOMEPAGE}

- + +

{MD_TIME}

+

{MD_LICENCE}

+
{L_REQUIREMENTS} @@ -61,34 +60,35 @@
+
{L_AUTHOR_INFORMATION} -
-
-
{md_authors.AUTHOR_NAME}
-
- -
-
-
{md_authors.AUTHOR_EMAIL}
-
- - -
-
-
{md_authors.AUTHOR_HOMEPAGE}
-
- - -
-
-
{md_authors.AUTHOR_ROLE}
-
- - -

+
+
+
+
{md_authors.AUTHOR_NAME}
+
+ +
+
+
{md_authors.AUTHOR_EMAIL}
+
+ + +
+
+
{md_authors.AUTHOR_HOMEPAGE}
+
+ + +
+
+
{md_authors.AUTHOR_ROLE}
+
+ +
diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 0e1d5c88a8..0e825514e6 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -155,11 +155,11 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - private function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); $template->assign_block_vars('enabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -178,11 +178,11 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - private function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); $template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -201,13 +201,13 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - function list_available_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_available_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { $uninstalled = array_diff_key($phpbb_extension_manager->all_available(), $phpbb_extension_manager->all_configured()); foreach ($uninstalled as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); $template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 9dfc0a067c..9342c936f9 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -131,7 +131,7 @@ class phpbb_extension_manager * @param string $template The template manager * @return phpbb_extension_metadata_manager Instance of the metadata manager */ - public function get_extension_metadata($name, phpbb_template $template) + public function get_extension_metadata_manager($name, phpbb_template $template) { return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->php_ext, $template, $this->config); } diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index d2dc72e5fc..aa163b1190 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -28,62 +28,9 @@ class phpbb_extension_metadata_manager protected $phpbb_root_path; protected $template; protected $ext_name; - public $metadata; + protected $metadata; protected $metadata_file; - /** - * Array of validation regular expressions, see __call() - * - * @var mixed - */ - protected $validation = array( - 'name' => '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', - 'type' => '#^phpbb3-extension$#', - 'description' => '#.*#', - 'version' => '#.+#', - 'licence' => '#.+#', - //'homepage' => '#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(? array( - 'display-name' => '#.*#', - ), - ); - - /** - * Magic method to catch validation calls - * - * @param string $name - * @param mixed $arguments - * @return int - */ - public function __call($name, $arguments) - { - // Validation Magic methods - if (strpos($name, 'validate_') === 0) - { - // Remove validate_ - $name = substr($name, 9); - - // Replace underscores with dashes (underscores are not used) - $name = str_replace('_', '-', $name); - - if (strpos($name, 'extra-') === 0) - { - // Remove extra_ - $name = substr($name, 6); - - if (isset($this->validation['extra'][$name])) - { - // Extra means it's optional, so return true if it does not exist - return (isset($this->metadata['extra'][$name])) ? preg_match($this->validation['extra'][$name], $this->metadata['extra'][$name]) : true; - } - } - else if (isset($this->validation[$name]) && isset($this->metadata[$name])) - { - return preg_match($this->validation[$name], $this->metadata[$name]); - } - } - } - /** * Creates the metadata manager * @@ -136,7 +83,7 @@ class phpbb_extension_metadata_manager case 'all': default: // Validate the metadata - if (!$this->validate_metadata_array()) + if (!$this->validate()) { return false; } @@ -145,17 +92,17 @@ class phpbb_extension_metadata_manager break; case 'name': - return ($this->validate_name()) ? $this->metadata['name'] : false; + return ($this->validate('name')) ? $this->metadata['name'] : false; break; case 'display-name': - if (isset($this->metadata['extra']['display-name']) && $this->validate_extra_display_name()) + if (isset($this->metadata['extra']['display-name'])) { return $this->metadata['extra']['display-name']; } else { - return ($this->validate_name()) ? $this->metadata['name'] : false; + return ($this->validate('name')) ? $this->metadata['name'] : false; } break; // TODO: Add remaining cases as needed @@ -216,7 +163,7 @@ class phpbb_extension_metadata_manager /** * This array handles the validation and cleaning of the array * - * @return array Contains the cleaned and validated metadata array + * @return array Contains the cleaned metadata array */ private function clean_metadata_array() { @@ -227,40 +174,44 @@ class phpbb_extension_metadata_manager } /** - * This array handles the validation of strings - * - * @return bool True if validation succeeded, False if failed - */ - public function validate_metadata_array() - { - foreach ($this->validation as $name => $regex) - { - if (is_array($regex)) + * Validate fields + * + * @param string $name ("all" for display and enable validation + * "display" for name, type, and authors + * "name", "type") + * @return Bool False if validation fails, true if valid + */ + public function validate($name = 'display') + { + // Basic fields + $fields = array( + 'name' => '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', + 'type' => '#^phpbb3-extension$#', + 'licence' => '#.+#', + 'version' => '#.+#', + ); + + if (isset($fields[$name])) + { + return (isset($this->metadata[$name])) ? (bool) preg_match($this->validation[$name], $this->metadata[$name]) : false; + } + + // Validate all fields + if ($name == 'all') + { + foreach ($fields as $field => $data) { - foreach ($regex as $extra_name => $extra_regex) - { - $type = 'validate_' . $name . '_' . $extra_name; - - if (!$this->$type()) - { - return false; - } - } - } - else - { - - $type = 'validate_' . $name; - - if (!$this->$type()) + if (!$this->validate($field)) { return false; } } + + return $this->validate_authors(); } - return $this->validate_authors(); - } + return true; + } /** * Validates the contents of the authors field @@ -292,19 +243,10 @@ class phpbb_extension_metadata_manager */ public function validate_enable() { - $validate = array( - 'require_phpbb', - 'require_php', - ); - - foreach ($validate as $type) + // Check for phpBB, PHP versions + if (!$this->validate_require_phpbb || !$this->validate_require_php) { - $type = 'validate_' . $type; - - if (!$this->$type()) - { - return false; - } + return false; } return true; @@ -372,10 +314,10 @@ class phpbb_extension_metadata_manager $this->template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), 'MD_TYPE' => htmlspecialchars($this->metadata['type']), - 'MD_DESCRIPTION' => htmlspecialchars($this->metadata['description']), + 'MD_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '', 'MD_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', - 'MD_VERSION' => htmlspecialchars($this->metadata['version']), - 'MD_TIME' => htmlspecialchars($this->metadata['time']), + 'MD_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', + 'MD_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', @@ -386,7 +328,7 @@ class phpbb_extension_metadata_manager { $this->template->assign_block_vars('md_authors', array( 'AUTHOR_NAME' => htmlspecialchars($author['name']), - 'AUTHOR_EMAIL' => $author['email'], + 'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '', 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '', 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); From 89f4cf6a8c10f9b0875cf7f278016aff67eb38fc Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 19:46:21 -0500 Subject: [PATCH 237/645] [ticket/10631] Use exceptions for errors. Build action list dynamically. PHPBB3-10631 --- phpBB/adm/style/acp_ext_list.html | 21 +++- phpBB/includes/acp/acp_extensions.php | 111 +++++++++++++----- phpBB/includes/exception/metadata.php | 69 +++++++++++ phpBB/includes/extension/metadata_manager.php | 72 ++++++------ phpBB/language/en/acp/extensions.php | 2 +- 5 files changed, 205 insertions(+), 70 deletions(-) create mode 100644 phpBB/includes/exception/metadata.php diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index b3b1b84949..65051cbae0 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -26,11 +26,16 @@ {enabled.EXT_NAME} {L_DETAILS} - {L_DISABLE}  - | {L_PURGE} + + + {enabled.actions.L_ACTION} +  |  + + + {L_DISABLED} {L_EXTENSIONS} @@ -38,9 +43,15 @@ {disabled.EXT_NAME} - {L_DETAILS} - {L_ENABLE}  - {L_PURGE}  + + {L_DETAILS} + + + + {disabled.actions.L_ACTION} +  |  + + diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 0e825514e6..a833c8c482 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -22,11 +22,21 @@ class acp_extensions { var $u_action; + private $db; + private $config; + private $template; + private $user; + function main() { // Start the page global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx; + $this->db = $db; + $this->config = $config; + $this->template = $template; + $this->user = $user; + $user->add_lang(array('install', 'acp/extensions')); $this->page_title = 'ACP_EXTENSIONS'; @@ -39,9 +49,10 @@ class acp_extensions { $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template, $config); - if ($md_manager->get_metadata('all') === false) - { - trigger_error('EXTENSION_INVALID'); + try{ + $md_manager->get_metadata('all'); + } catch( Exception $e ) { + trigger_error($e); } } @@ -50,9 +61,9 @@ class acp_extensions { case 'list': default: - $this->list_enabled_exts($phpbb_extension_manager, $template); - $this->list_disabled_exts($phpbb_extension_manager, $template); - $this->list_available_exts($phpbb_extension_manager, $template); + $this->list_enabled_exts($phpbb_extension_manager); + $this->list_disabled_exts($phpbb_extension_manager); + $this->list_available_exts($phpbb_extension_manager); $this->tpl_name = 'acp_ext_list'; break; @@ -155,19 +166,28 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - public function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager) { foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - $template->assign_block_vars('enabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + try { + $this->template->assign_block_vars('enabled', array( + 'EXT_NAME' => $md_manager->get_metadata('display-name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, - 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, - 'U_DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $name, - )); + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + )); + + $this->output_actions('enabled', array( + 'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $name, + 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, + )); + } catch( Exception $e ) { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + )); + } } } @@ -178,19 +198,28 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - public function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager) { foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - $template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + try { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $md_manager->get_metadata('display-name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, - 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, - 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, - )); + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + )); + + $this->output_actions('disabled', array( + 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, + 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, + )); + } catch( Exception $e ) { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + )); + } } } @@ -201,19 +230,45 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - public function list_available_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_available_exts(phpbb_extension_manager $phpbb_extension_manager) { $uninstalled = array_diff_key($phpbb_extension_manager->all_available(), $phpbb_extension_manager->all_configured()); foreach ($uninstalled as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - $template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + try { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $md_manager->get_metadata('display-name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, - 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + )); + + $this->output_actions('disabled', array( + 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, + )); + } catch( Exception $e ) { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + )); + } + } + } + + /** + * Output actions to a block + * + * @param string $block + * @param array $actions + */ + private function output_actions($block, $actions) + { + foreach ($actions as $lang => $url) + { + $this->template->assign_block_vars($block . '.actions', array( + 'L_ACTION' => $this->user->lang($lang), + 'U_ACTION' => $url, )); } } diff --git a/phpBB/includes/exception/metadata.php b/phpBB/includes/exception/metadata.php new file mode 100644 index 0000000000..93cc337f55 --- /dev/null +++ b/phpBB/includes/exception/metadata.php @@ -0,0 +1,69 @@ +code = $code; + $this->field_name = $field_name; + } + + public function __toString() + { + return sprintf($this->getErrorMessage(), $this->field_name); + } + + public function getErrorMessage() + { + switch ($this->code) + { + case self::NOT_SET: + return 'The "%s" meta field has not been set.'; + break; + + case self::INVALID: + return 'The "%s" meta field is not valid.'; + break; + + case self::FILE_GET_CONTENTS: + return 'file_get_contents failed on %s'; + break; + + case self::JSON_DECODE: + return 'json_decode failed on %s'; + break; + + case self::FILE_DOES_NOT_EXIST: + return 'Required file does not exist at %s'; + break; + + default: + return 'An unexpected error has occurred.'; + break; + } + } +} \ No newline at end of file diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index aa163b1190..126331ce1c 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -56,27 +56,18 @@ class phpbb_extension_metadata_manager * Processes and gets the metadata requested * * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @return bool|array Contains all of the requested metadata or bool False if not valid + * @return array Contains all of the requested metadata, throws an exception on failure */ public function get_metadata($element = 'all') { // TODO: Check ext_name exists and is an extension that exists - if (!$this->set_metadata_file()) - { - return false; - } + $this->set_metadata_file(); // Fetch the metadata - if (!$this->fetch_metadata()) - { - return false; - } + $this->fetch_metadata(); // Clean the metadata - if (!$this->clean_metadata_array()) - { - return false; - } + $this->clean_metadata_array(); switch ($element) { @@ -112,46 +103,42 @@ class phpbb_extension_metadata_manager /** * Sets the filepath of the metadata file * - * @return boolean Set to true if it exists + * @return boolean Set to true if it exists, throws an exception on failure */ private function set_metadata_file() { $ext_filepath = $this->extension_manager->get_extension_path($this->ext_name); - $metadata_filepath = $this->phpbb_root_path . $ext_filepath . '/composer.json'; + $metadata_filepath = $this->phpbb_root_path . $ext_filepath . 'composer.json'; $this->metadata_file = $metadata_filepath; if (!file_exists($this->metadata_file)) { - return false; - } - else - { - return true; + throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); } } /** * Gets the contents of the composer.json file * - * @return bool True of false (if loading succeeded or failed) + * @return bool True if success, throws an exception on failure */ private function fetch_metadata() { if (!file_exists($this->metadata_file)) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); } else { if (!($file_contents = file_get_contents($this->metadata_file))) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_GET_CONTENTS, $this->metadata_file); } if (($metadata = json_decode($file_contents, true)) === NULL) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::JSON_DECODE, $this->metadata_file); } $this->metadata = $metadata; @@ -161,7 +148,7 @@ class phpbb_extension_metadata_manager } /** - * This array handles the validation and cleaning of the array + * This array handles the cleaning of the array * * @return array Contains the cleaned metadata array */ @@ -179,7 +166,7 @@ class phpbb_extension_metadata_manager * @param string $name ("all" for display and enable validation * "display" for name, type, and authors * "name", "type") - * @return Bool False if validation fails, true if valid + * @return Bool True if valid, throws an exception if invalid */ public function validate($name = 'display') { @@ -193,21 +180,34 @@ class phpbb_extension_metadata_manager if (isset($fields[$name])) { - return (isset($this->metadata[$name])) ? (bool) preg_match($this->validation[$name], $this->metadata[$name]) : false; + if (!isset($this->metadata[$name])) + { + throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, $name); + } + + if (!preg_match($fields[$name], $this->metadata[$name])) + { + throw new phpbb_exception_metadata(phpbb_exception_metadata::INVALID, $name); + } } // Validate all fields if ($name == 'all') + { + $this->validate('display'); + + $this->validate_enable(); + } + + // Validate display fields + if ($name == 'display') { foreach ($fields as $field => $data) { - if (!$this->validate($field)) - { - return false; - } + $this->validate($field); } - return $this->validate_authors(); + $this->validate_authors(); } return true; @@ -216,20 +216,20 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the authors field * - * @return boolean True when passes validation + * @return boolean True when passes validation, throws exception if invalid */ private function validate_authors() { if (empty($this->metadata['authors'])) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'authors'); } foreach ($this->metadata['authors'] as $author) { if (!isset($author['name'])) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'author name'); } } @@ -244,7 +244,7 @@ class phpbb_extension_metadata_manager public function validate_enable() { // Check for phpBB, PHP versions - if (!$this->validate_require_phpbb || !$this->validate_require_php) + if (!$this->validate_require_phpbb() || !$this->validate_require_php()) { return false; } diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 903ec249a8..0adaff10c8 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -39,7 +39,7 @@ $lang = array_merge($lang, array( 'EXTENSIONS' => 'Extensions', 'EXTENSIONS_ADMIN' => 'Extensions Manager', 'EXTENSIONS_EXPLAIN' => 'The Extensions Manager is a tool in your phpBB Board which allows you to manage all of your extensions statuses and view information about them.', - 'EXTENSION_INVALID' => 'The selected extension is not valid.', + 'EXTENSION_INVALID_LIST' => 'The "%s" extension is not valid.

%s

', 'EXTENSION_NOT_AVAILABLE' => 'The selected extension is not available for this board, please verify your phpBB and PHP versions are allowed (see the details page).', 'DETAILS' => 'Details', From 2a7e1292919ed1397a3f1951e510d84565d002d7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:28:04 -0500 Subject: [PATCH 238/645] [ticket/10631] Simplify exceptions PHPBB-10631 --- phpBB/includes/acp/acp_extensions.php | 28 +++++--- phpBB/includes/exception/metadata.php | 69 ------------------- phpBB/includes/extension/exception.php | 27 ++++++++ phpBB/includes/extension/metadata_manager.php | 16 ++--- 4 files changed, 55 insertions(+), 85 deletions(-) delete mode 100644 phpBB/includes/exception/metadata.php create mode 100644 phpBB/includes/extension/exception.php diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index a833c8c482..287074395d 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -49,9 +49,12 @@ class acp_extensions { $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template, $config); - try{ + try + { $md_manager->get_metadata('all'); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { trigger_error($e); } } @@ -172,7 +175,8 @@ class acp_extensions { $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - try { + try + { $this->template->assign_block_vars('enabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -183,7 +187,9 @@ class acp_extensions 'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $name, 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, )); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); @@ -204,7 +210,8 @@ class acp_extensions { $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - try { + try + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -215,7 +222,9 @@ class acp_extensions 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, )); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); @@ -238,7 +247,8 @@ class acp_extensions { $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - try { + try + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -248,7 +258,9 @@ class acp_extensions $this->output_actions('disabled', array( 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, )); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); diff --git a/phpBB/includes/exception/metadata.php b/phpBB/includes/exception/metadata.php deleted file mode 100644 index 93cc337f55..0000000000 --- a/phpBB/includes/exception/metadata.php +++ /dev/null @@ -1,69 +0,0 @@ -code = $code; - $this->field_name = $field_name; - } - - public function __toString() - { - return sprintf($this->getErrorMessage(), $this->field_name); - } - - public function getErrorMessage() - { - switch ($this->code) - { - case self::NOT_SET: - return 'The "%s" meta field has not been set.'; - break; - - case self::INVALID: - return 'The "%s" meta field is not valid.'; - break; - - case self::FILE_GET_CONTENTS: - return 'file_get_contents failed on %s'; - break; - - case self::JSON_DECODE: - return 'json_decode failed on %s'; - break; - - case self::FILE_DOES_NOT_EXIST: - return 'Required file does not exist at %s'; - break; - - default: - return 'An unexpected error has occurred.'; - break; - } - } -} \ No newline at end of file diff --git a/phpBB/includes/extension/exception.php b/phpBB/includes/extension/exception.php new file mode 100644 index 0000000000..e08a8912ea --- /dev/null +++ b/phpBB/includes/extension/exception.php @@ -0,0 +1,27 @@ +getMessage(); + } +} \ No newline at end of file diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 126331ce1c..27b04d4c08 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -114,7 +114,7 @@ class phpbb_extension_metadata_manager if (!file_exists($this->metadata_file)) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); + throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); } } @@ -127,18 +127,18 @@ class phpbb_extension_metadata_manager { if (!file_exists($this->metadata_file)) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); + throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); } else { if (!($file_contents = file_get_contents($this->metadata_file))) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_GET_CONTENTS, $this->metadata_file); + throw new phpbb_extension_exception('file_get_contents failed on ' . $this->metadata_file); } if (($metadata = json_decode($file_contents, true)) === NULL) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::JSON_DECODE, $this->metadata_file); + throw new phpbb_extension_exception('json_decode failed on ' . $this->metadata_file); } $this->metadata = $metadata; @@ -182,12 +182,12 @@ class phpbb_extension_metadata_manager { if (!isset($this->metadata[$name])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, $name); + throw new phpbb_extension_exception("Required meta field '$name' has not been set."); } if (!preg_match($fields[$name], $this->metadata[$name])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::INVALID, $name); + throw new phpbb_extension_exception("Meta field '$name' is invalid."); } } @@ -222,14 +222,14 @@ class phpbb_extension_metadata_manager { if (empty($this->metadata['authors'])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'authors'); + throw new phpbb_extension_exception("Required meta field 'authors' has not been set."); } foreach ($this->metadata['authors'] as $author) { if (!isset($author['name'])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'author name'); + throw new phpbb_extension_exception("Required meta field 'author name' has not been set."); } } From fd5ed30052a03d812cfdf95f4e86b0c997b5aa10 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:34:47 -0500 Subject: [PATCH 239/645] [ticket/10631] Update tests PHPBB3-10631 --- tests/extension/manager_test.php | 2 ++ tests/test_framework/phpbb_functional_test_case.php | 1 + 2 files changed, 3 insertions(+) diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 45bed247ae..df7f9f3029 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -27,6 +27,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $this->extension_manager = new phpbb_extension_manager( $this->new_dbal(), + new phpbb_config(array()) 'phpbb_ext', dirname(__FILE__) . '/', '.php', @@ -90,6 +91,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case { $extension_manager = new phpbb_extension_manager( $this->new_dbal(), + new phpbb_config(array()), 'phpbb_ext', dirname(__FILE__) . '/', '.php' diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b953017d0a..a1deeb2b63 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -125,6 +125,7 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->extension_manager = new phpbb_extension_manager( $this->get_db(), + new phpbb_config(), self::$config['table_prefix'] . 'ext', $phpbb_root_path, ".$phpEx", From 747c16240fd56be0e24b4c54f01c82aa0a78b91e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:40:54 -0500 Subject: [PATCH 240/645] [ticket/10631] get_extension_metadata_manager -> create_extension_metadata_manager PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 6 +++--- phpBB/includes/extension/manager.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 287074395d..4f59ea309b 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -173,7 +173,7 @@ class acp_extensions { foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); + $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template); try { @@ -208,7 +208,7 @@ class acp_extensions { foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); + $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template); try { @@ -245,7 +245,7 @@ class acp_extensions foreach ($uninstalled as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); + $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template); try { diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 9342c936f9..9a518c215f 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -131,7 +131,7 @@ class phpbb_extension_manager * @param string $template The template manager * @return phpbb_extension_metadata_manager Instance of the metadata manager */ - public function get_extension_metadata_manager($name, phpbb_template $template) + public function create_extension_metadata_manager($name, phpbb_template $template) { return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->php_ext, $template, $this->config); } From 1de061c4defd405da279cb1f398d7d2e4e75c573 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 24 Jul 2012 20:48:38 -0500 Subject: [PATCH 241/645] [ticket/10631] Fixing an error in the test script PHPBB3-10631 --- tests/extension/manager_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index df7f9f3029..5cde5bccdb 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -27,7 +27,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $this->extension_manager = new phpbb_extension_manager( $this->new_dbal(), - new phpbb_config(array()) + new phpbb_config(array()), 'phpbb_ext', dirname(__FILE__) . '/', '.php', From c39f11750fa73007edd936bf600ea53ac8f95f3a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 24 Jul 2012 21:08:11 -0500 Subject: [PATCH 242/645] [ticket/10631] A _start_ on a metadata manager test. No idea if it runs without errors, I do not have the testing stuff setup. PHPBB3-10631 --- .../phpbb_extension_metadata_manager_test.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/extension/phpbb_extension_metadata_manager_test.php diff --git a/tests/extension/phpbb_extension_metadata_manager_test.php b/tests/extension/phpbb_extension_metadata_manager_test.php new file mode 100644 index 0000000000..7a7f7a785d --- /dev/null +++ b/tests/extension/phpbb_extension_metadata_manager_test.php @@ -0,0 +1,55 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->extension_manager = new phpbb_extension_manager( + $this->new_dbal(), + new phpbb_config(array()), + 'phpbb_ext', + dirname(__FILE__) . '/', + '.php', + new phpbb_mock_cache + ); + } + + public function test_bar() + { + $phpbb_extension_metadata_manager = new phpbb_extension_metadata_manager( + 'bar', + $this->new_dbal(), + new phpbb_config(array()), + $this->extension_manager, + dirname(__FILE__) . '/', + '.php', + new phpbb_template( + dirname(__FILE__) . '/', + '.php', + new phpbb_config(array()), + new phpbb_user(), + new phpbb_style_resource_locator() + ), + new phpbb_mock_cache + ); + + //$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available())); + } +} \ No newline at end of file From 8c5786636a534baf28b4820a730f85948c3dccf4 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 25 Jul 2012 22:14:38 -0500 Subject: [PATCH 243/645] [ticket/10631] Fix class construct arguments in test PHPBB3-10631 --- tests/extension/phpbb_extension_metadata_manager_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/extension/phpbb_extension_metadata_manager_test.php b/tests/extension/phpbb_extension_metadata_manager_test.php index 7a7f7a785d..0d115d37eb 100644 --- a/tests/extension/phpbb_extension_metadata_manager_test.php +++ b/tests/extension/phpbb_extension_metadata_manager_test.php @@ -36,7 +36,6 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $phpbb_extension_metadata_manager = new phpbb_extension_metadata_manager( 'bar', $this->new_dbal(), - new phpbb_config(array()), $this->extension_manager, dirname(__FILE__) . '/', '.php', @@ -47,7 +46,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case new phpbb_user(), new phpbb_style_resource_locator() ), - new phpbb_mock_cache + new phpbb_config(array()) ); //$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available())); From 500879520c40a71f0b83799ab3e59c86c12a801a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 28 Jul 2012 14:59:55 -0500 Subject: [PATCH 244/645] [ticket/10631] Metadata manager tests PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 55 +-- tests/extension/ext/foo/composer.json | 22 ++ tests/extension/metadata_manager_test.php | 374 ++++++++++++++++++ .../phpbb_extension_metadata_manager_test.php | 54 --- 4 files changed, 424 insertions(+), 81 deletions(-) create mode 100644 tests/extension/ext/foo/composer.json create mode 100644 tests/extension/metadata_manager_test.php delete mode 100644 tests/extension/phpbb_extension_metadata_manager_test.php diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 27b04d4c08..c7f52b7c02 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -178,36 +178,37 @@ class phpbb_extension_metadata_manager 'version' => '#.+#', ); - if (isset($fields[$name])) + switch ($name) { - if (!isset($this->metadata[$name])) - { - throw new phpbb_extension_exception("Required meta field '$name' has not been set."); - } + case 'all': + $this->validate('display'); - if (!preg_match($fields[$name], $this->metadata[$name])) - { - throw new phpbb_extension_exception("Meta field '$name' is invalid."); - } - } + $this->validate_enable(); + break; - // Validate all fields - if ($name == 'all') - { - $this->validate('display'); + case 'display': + foreach ($fields as $field => $data) + { + $this->validate($field); + } - $this->validate_enable(); - } + $this->validate_authors(); + break; - // Validate display fields - if ($name == 'display') - { - foreach ($fields as $field => $data) - { - $this->validate($field); - } + default: + if (isset($fields[$name])) + { + if (!isset($this->metadata[$name])) + { + throw new phpbb_extension_exception("Required meta field '$name' has not been set."); + } - $this->validate_authors(); + if (!preg_match($fields[$name], $this->metadata[$name])) + { + throw new phpbb_extension_exception("Meta field '$name' is invalid."); + } + } + break; } return true; @@ -218,7 +219,7 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation, throws exception if invalid */ - private function validate_authors() + public function validate_authors() { if (empty($this->metadata['authors'])) { @@ -258,7 +259,7 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation */ - private function validate_require_phpbb() + public function validate_require_phpbb() { if (!isset($this->metadata['require']['phpbb'])) { @@ -273,7 +274,7 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation */ - private function validate_require_php() + public function validate_require_php() { if (!isset($this->metadata['require']['php'])) { diff --git a/tests/extension/ext/foo/composer.json b/tests/extension/ext/foo/composer.json new file mode 100644 index 0000000000..14af677dac --- /dev/null +++ b/tests/extension/ext/foo/composer.json @@ -0,0 +1,22 @@ +{ + "name": "foo/example", + "type": "phpbb3-extension", + "description": "An example/sample extension to be used for testing purposes in phpBB Development.", + "version": "1.0.0", + "time": "2012-02-15 01:01:01", + "licence": "GNU GPL v2", + "authors": [{ + "name": "Nathan Guse", + "username": "EXreaction", + "email": "nathaniel.guse@gmail.com", + "homepage": "http://lithiumstudios.org", + "role": "N/A" + }], + "require": { + "php": ">=5.3", + "phpbb": "3.1.0-dev" + }, + "extra": { + "display-name": "phpBB Foo Extension" + } +} diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php new file mode 100644 index 0000000000..67630e9f36 --- /dev/null +++ b/tests/extension/metadata_manager_test.php @@ -0,0 +1,374 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->phpbb_root_path = dirname(__FILE__) . '/'; + + $this->extension_manager = new phpbb_extension_manager( + $this->new_dbal(), + new phpbb_config(array()), + 'phpbb_ext', + $this->phpbb_root_path, + '.php', + new phpbb_mock_cache + ); + } + + // Should fail from missing composer.json + public function test_bar() + { + $ext_name = 'bar'; + + $manager = new phpbb_extension_metadata_manager_test( + $ext_name, + $this->new_dbal(), + $this->extension_manager, + $this->phpbb_root_path, + '.php', + new phpbb_template( + $this->phpbb_root_path, + '.php', + new phpbb_config(array()), + new phpbb_user(), + new phpbb_style_resource_locator() + ), + new phpbb_config(array()) + ); + + try + { + $manager->get_metadata(); + } + catch(phpbb_extension_exception $e){} + + $this->assertEquals((string) $e, 'The required file does not exist: ' . $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'); + } + + // Should be the same as a direct json_decode of the composer.json file + public function test_foo() + { + $ext_name = 'foo'; + + $manager = new phpbb_extension_metadata_manager_test( + $ext_name, + $this->new_dbal(), + $this->extension_manager, + $this->phpbb_root_path, + '.php', + new phpbb_template( + $this->phpbb_root_path, + '.php', + new phpbb_config(array()), + new phpbb_user(), + new phpbb_style_resource_locator() + ), + new phpbb_config(array()) + ); + + try + { + $metadata = $manager->get_metadata(); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + $json = json_decode(file_get_contents($this->phpbb_root_path . 'ext/foo/composer.json'), true); + + $this->assertEquals($metadata, $json); + } + + public function test_validator() + { + $ext_name = 'validator'; + + $manager = new phpbb_extension_metadata_manager_test( + $ext_name, + $this->new_dbal(), + $this->extension_manager, + $this->phpbb_root_path, + '.php', + new phpbb_template( + $this->phpbb_root_path, + '.php', + new phpbb_config(array()), + new phpbb_user(), + new phpbb_style_resource_locator() + ), + new phpbb_config(array( + 'version' => '3.1.0', + )) + ); + + // Non-existant data + try + { + $manager->validate('name'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.'); + + try + { + $manager->validate('type'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.'); + + try + { + $manager->validate('licence'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'licence\' has not been set.'); + + try + { + $manager->validate('version'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.'); + + try + { + $manager->validate_authors(); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.'); + + $manager->merge_metadata(array( + 'authors' => array( + array(), + ), + )); + + try + { + $manager->validate_authors(); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.'); + + + // Invalid data + $manager->set_metadata(array( + 'name' => 'asdf', + 'type' => 'asdf', + 'licence' => '', + 'version' => '', + )); + + try + { + $manager->validate('name'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Meta field \'name\' is invalid.'); + + try + { + $manager->validate('type'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Meta field \'type\' is invalid.'); + + try + { + $manager->validate('licence'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Meta field \'licence\' is invalid.'); + + try + { + $manager->validate('version'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Meta field \'version\' is invalid.'); + + + // Valid data + $manager->set_metadata(array( + 'name' => 'test/foo', + 'type' => 'phpbb3-extension', + 'licence' => 'GPL v2', + 'version' => '1.0.0', + )); + + try + { + $this->assertEquals(true, $manager->validate('enable')); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Too high of requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '10.0.0', + 'phpbb' => '3.2.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(false, $manager->validate_require_php()); + $this->assertEquals(false, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Too high of requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '5.3.0', + 'phpbb' => '3.1.0-beta', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Too high of requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '>' . phpversion(), + 'phpbb' => '>3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(false, $manager->validate_require_php()); + $this->assertEquals(false, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Too high of current install + $manager->merge_metadata(array( + 'require' => array( + 'php' => '<' . phpversion(), + 'phpbb' => '<3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(false, $manager->validate_require_php()); + $this->assertEquals(false, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Matching requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => phpversion(), + 'phpbb' => '3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Matching requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '>=' . phpversion(), + 'phpbb' => '>=3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Matching requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '<=' . phpversion(), + 'phpbb' => '<=3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + } +} + +class phpbb_extension_metadata_manager_test extends phpbb_extension_metadata_manager +{ + public function set_metadata($metadata) + { + $this->metadata = $metadata; + } + + public function merge_metadata($metadata) + { + $this->metadata = array_merge($this->metadata, $metadata); + } +} \ No newline at end of file diff --git a/tests/extension/phpbb_extension_metadata_manager_test.php b/tests/extension/phpbb_extension_metadata_manager_test.php deleted file mode 100644 index 0d115d37eb..0000000000 --- a/tests/extension/phpbb_extension_metadata_manager_test.php +++ /dev/null @@ -1,54 +0,0 @@ -createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml'); - } - - protected function setUp() - { - parent::setUp(); - - $this->extension_manager = new phpbb_extension_manager( - $this->new_dbal(), - new phpbb_config(array()), - 'phpbb_ext', - dirname(__FILE__) . '/', - '.php', - new phpbb_mock_cache - ); - } - - public function test_bar() - { - $phpbb_extension_metadata_manager = new phpbb_extension_metadata_manager( - 'bar', - $this->new_dbal(), - $this->extension_manager, - dirname(__FILE__) . '/', - '.php', - new phpbb_template( - dirname(__FILE__) . '/', - '.php', - new phpbb_config(array()), - new phpbb_user(), - new phpbb_style_resource_locator() - ), - new phpbb_config(array()) - ); - - //$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available())); - } -} \ No newline at end of file From 36465c9a205c356b0662e45b4fded79c4b476547 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 29 Jul 2012 20:08:30 -0500 Subject: [PATCH 245/645] [ticket/10631] Functional acp_extensions test, cleanup PHPBB3-10631 --- phpBB/adm/style/acp_ext_list.html | 4 +- phpBB/includes/acp/acp_extensions.php | 38 +-- tests/extension/acp.php | 226 ++++++++++++++++++ tests/extension/ext/foo/composer.json | 2 +- tests/extension/ext/vendor/moo/composer.json | 22 ++ tests/extension/metadata_manager_test.php | 99 ++++---- .../phpbb_functional_test_case.php | 54 +++++ .../phpbb_test_case_helpers.php | 108 +++++++++ 8 files changed, 481 insertions(+), 72 deletions(-) create mode 100644 tests/extension/acp.php create mode 100644 tests/extension/ext/vendor/moo/composer.json diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index 65051cbae0..b654a80caa 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -23,7 +23,7 @@ - + {enabled.EXT_NAME} {L_DETAILS} @@ -41,7 +41,7 @@ {L_DISABLED} {L_EXTENSIONS} - + {disabled.EXT_NAME} {L_DETAILS} diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 4f59ea309b..c4d9f0c0e0 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -72,7 +72,7 @@ class acp_extensions break; case 'enable_pre': - if (!$md_manager->validate_enable()) + if (!$md_manager->validate_enable() || $phpbb_extension_manager->enabled($ext_name)) { trigger_error('EXTENSION_NOT_AVAILABLE'); } @@ -81,7 +81,7 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, - 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . $ext_name, + 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name), )); break; @@ -95,7 +95,7 @@ class acp_extensions { $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . $ext_name); + meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); } $this->tpl_name = 'acp_ext_enable'; @@ -106,11 +106,16 @@ class acp_extensions break; case 'disable_pre': + if (!$phpbb_extension_manager->enabled($ext_name)) + { + trigger_error('EXTENSION_NOT_AVAILABLE'); + } + $this->tpl_name = 'acp_ext_disable'; $template->assign_vars(array( 'PRE' => true, - 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . $ext_name, + 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name), )); break; @@ -119,7 +124,7 @@ class acp_extensions { $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . $ext_name); + meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name)); } $this->tpl_name = 'acp_ext_disable'; @@ -134,7 +139,7 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, - 'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . $ext_name, + 'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name), )); break; @@ -143,7 +148,7 @@ class acp_extensions { $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . $ext_name); + meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); } $this->tpl_name = 'acp_ext_purge'; @@ -166,7 +171,6 @@ class acp_extensions * Lists all the enabled extensions and dumps to the template * * @param $phpbb_extension_manager An instance of the extension manager - * @param $template An instance of the template engine * @return null */ public function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager) @@ -180,12 +184,12 @@ class acp_extensions $this->template->assign_block_vars('enabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); $this->output_actions('enabled', array( - 'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $name, - 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, + 'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . urlencode($name), + 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . urlencode($name), )); } catch(phpbb_extension_exception $e) @@ -201,7 +205,6 @@ class acp_extensions * Lists all the disabled extensions and dumps to the template * * @param $phpbb_extension_manager An instance of the extension manager - * @param $template An instance of the template engine * @return null */ public function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager) @@ -215,12 +218,12 @@ class acp_extensions $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); $this->output_actions('disabled', array( - 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, - 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, + 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . urlencode($name), + 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . urlencode($name), )); } catch(phpbb_extension_exception $e) @@ -236,7 +239,6 @@ class acp_extensions * Lists all the available extensions and dumps to the template * * @param $phpbb_extension_manager An instance of the extension manager - * @param $template An instance of the template engine * @return null */ public function list_available_exts(phpbb_extension_manager $phpbb_extension_manager) @@ -252,11 +254,11 @@ class acp_extensions $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); $this->output_actions('disabled', array( - 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, + 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . urlencode($name), )); } catch(phpbb_extension_exception $e) diff --git a/tests/extension/acp.php b/tests/extension/acp.php new file mode 100644 index 0000000000..c078a3f7b4 --- /dev/null +++ b/tests/extension/acp.php @@ -0,0 +1,226 @@ +copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + + // Then empty the ext/ directory on the board (for accurate test cases) + self::$helper->empty_dir($phpbb_root_path . 'ext/'); + + // Copy our ext/ files from the test case to the board + self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/ext/', $phpbb_root_path . 'ext/')); + } + + public function setUp() + { + parent::setUp(); + + $this->get_db(); + + // Clear the phpbb_ext table + $this->db->sql_query('DELETE FROM phpbb_ext'); + + // Insert our base data + $insert_rows = array( + array( + 'ext_name' => 'foo', + 'ext_active' => true, + 'ext_state' => 'b:0;', + ), + array( + 'ext_name' => 'vendor/moo', + 'ext_active' => false, + 'ext_state' => 'b:0;', + ), + + // do not exist + array( + 'ext_name' => 'test2', + 'ext_active' => true, + 'ext_state' => 'b:0;', + ), + array( + 'ext_name' => 'test3', + 'ext_active' => false, + 'ext_state' => 'b:0;', + ), + ); + $this->db->sql_multi_insert('phpbb_ext', $insert_rows); + + $this->login(); + $this->admin_login(); + + $this->add_lang('acp/extensions'); + } + + /** + * This should only be called once after the tests are run. + * This is used to remove the files copied to the phpBB install + */ + static public function tearDownAfterClass() + { + global $phpbb_root_path; + + // Copy back the board installed extensions from the temp directory + self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + + self::$copied_files[] = $phpbb_root_path . 'store/temp_ext/'; + + // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) + self::$helper->remove_files(self::$copied_files); + } + + public function test_list() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); + + $this->assertCount(1, $crawler->filter('.ext_enabled')); + $this->assertCount(4, $crawler->filter('.ext_disabled')); + + $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); + $this->assertContainsLang('PURGE', $crawler->filter('.ext_enabled')->eq(0)->text()); + + $this->assertContains('The "test2" extension is not valid.', $crawler->filter('.ext_disabled')->eq(0)->text()); + + $this->assertContains('The "test3" extension is not valid.', $crawler->filter('.ext_disabled')->eq(1)->text()); + + $this->assertContains('phpBB Moo Extension', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('ENABLE', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('PURGE', $crawler->filter('.ext_disabled')->eq(2)->text()); + + $this->assertContains('The "bar" extension is not valid.', $crawler->filter('.ext_disabled')->eq(3)->text()); + } + + public function test_details() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid); + + for ($i = 0; $i < $crawler->filter('dl')->count(); $i++) + { + $text = $crawler->filter('dl')->eq($i)->text(); + + switch (true) + { + case (strpos($text, $this->lang('DISPLAY_NAME')) === 0): + $this->assertContains('phpBB Foo Extension', $text); + break; + + case (strpos($text, $this->lang('CLEAN_NAME')) === 0): + $this->assertContains('foo/example', $text); + break; + + case (strpos($text, $this->lang('DESCRIPTION')) === 0): + $this->assertContains('An example/sample extension to be used for testing purposes in phpBB Development.', $text); + break; + + case (strpos($text, $this->lang('VERSION')) === 0): + $this->assertContains('1.0.0', $text); + break; + + case (strpos($text, $this->lang('TIME')) === 0): + $this->assertContains('2012-02-15 01:01:01', $text); + break; + + case (strpos($text, $this->lang('LICENCE')) === 0): + $this->assertContains('GNU GPL v2', $text); + break; + + case (strpos($text, $this->lang('PHPBB_VERSION')) === 0): + $this->assertContains('3.1.0-dev', $text); + break; + + case (strpos($text, $this->lang('PHP_VERSION')) === 0): + $this->assertContains('>=5.3', $text); + break; + + case (strpos($text, $this->lang('AUTHOR_NAME')) === 0): + $this->assertContains('Nathan Guse', $text); + break; + + case (strpos($text, $this->lang('AUTHOR_EMAIL')) === 0): + $this->assertContains('email@phpbb.com', $text); + break; + + case (strpos($text, $this->lang('AUTHOR_HOMEPAGE')) === 0): + $this->assertContains('http://lithiumstudios.org', $text); + break; + + case (strpos($text, $this->lang('AUTHOR_ROLE')) === 0): + $this->assertContains('N/A', $text); + break; + } + } + } + + public function test_enable_pre() + { + // Foo is already enabled (error) + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NOT_AVAILABLE', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_disable_pre() + { + // Moo is not enabled (error) + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NOT_AVAILABLE', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_purge_pre() + { + // test2 is not available (error) + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=test2&sid=' . $this->sid); + $this->assertContains('The required file does not exist', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_enable() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('ENABLE_SUCCESS', $crawler->filter('html')->text()); + } + + public function test_disable() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('DISABLE_SUCCESS', $crawler->filter('html')->text()); + } + + public function test_purge() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text()); + } +} \ No newline at end of file diff --git a/tests/extension/ext/foo/composer.json b/tests/extension/ext/foo/composer.json index 14af677dac..4b5150461f 100644 --- a/tests/extension/ext/foo/composer.json +++ b/tests/extension/ext/foo/composer.json @@ -8,7 +8,7 @@ "authors": [{ "name": "Nathan Guse", "username": "EXreaction", - "email": "nathaniel.guse@gmail.com", + "email": "email@phpbb.com", "homepage": "http://lithiumstudios.org", "role": "N/A" }], diff --git a/tests/extension/ext/vendor/moo/composer.json b/tests/extension/ext/vendor/moo/composer.json new file mode 100644 index 0000000000..c91a5e027b --- /dev/null +++ b/tests/extension/ext/vendor/moo/composer.json @@ -0,0 +1,22 @@ +{ + "name": "moo/example", + "type": "phpbb3-extension", + "description": "An example/sample extension to be used for testing purposes in phpBB Development.", + "version": "1.0.0", + "time": "2012-02-15 01:01:01", + "licence": "GNU GPL v2", + "authors": [{ + "name": "Nathan Guse", + "username": "EXreaction", + "email": "email@phpbb.com", + "homepage": "http://lithiumstudios.org", + "role": "N/A" + }], + "require": { + "php": ">=5.3", + "phpbb": "3.1.0-dev" + }, + "extra": { + "display-name": "phpBB Moo Extension" + } +} diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 67630e9f36..d1e60ad268 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -11,7 +11,14 @@ class metadata_manager_test extends phpbb_database_test_case { protected $class_loader; protected $extension_manager; + + protected $cache; + protected $config; + protected $db; protected $phpbb_root_path; + protected $phpEx; + protected $template; + protected $user; public function getDataSet() { @@ -22,15 +29,30 @@ class metadata_manager_test extends phpbb_database_test_case { parent::setUp(); + $this->cache = new phpbb_mock_cache(); + $this->config = new phpbb_config(array( + 'version' => '3.1.0', + )); + $this->db = $this->new_dbal(); $this->phpbb_root_path = dirname(__FILE__) . '/'; + $this->phpEx = '.php'; + $this->user = new phpbb_user(); + + $this->template = new phpbb_template( + $this->phpbb_root_path, + $this->phpEx, + $this->config, + $this->user, + new phpbb_style_resource_locator() + ); $this->extension_manager = new phpbb_extension_manager( - $this->new_dbal(), - new phpbb_config(array()), + $this->db(), + $this->config, 'phpbb_ext', $this->phpbb_root_path, - '.php', - new phpbb_mock_cache + $this->phpEx, + $this->cache ); } @@ -39,21 +61,7 @@ class metadata_manager_test extends phpbb_database_test_case { $ext_name = 'bar'; - $manager = new phpbb_extension_metadata_manager_test( - $ext_name, - $this->new_dbal(), - $this->extension_manager, - $this->phpbb_root_path, - '.php', - new phpbb_template( - $this->phpbb_root_path, - '.php', - new phpbb_config(array()), - new phpbb_user(), - new phpbb_style_resource_locator() - ), - new phpbb_config(array()) - ); + $manager = $this->get_metadata_manager($ext_name); try { @@ -69,21 +77,7 @@ class metadata_manager_test extends phpbb_database_test_case { $ext_name = 'foo'; - $manager = new phpbb_extension_metadata_manager_test( - $ext_name, - $this->new_dbal(), - $this->extension_manager, - $this->phpbb_root_path, - '.php', - new phpbb_template( - $this->phpbb_root_path, - '.php', - new phpbb_config(array()), - new phpbb_user(), - new phpbb_style_resource_locator() - ), - new phpbb_config(array()) - ); + $manager = $this->get_metadata_manager($ext_name); try { @@ -103,23 +97,7 @@ class metadata_manager_test extends phpbb_database_test_case { $ext_name = 'validator'; - $manager = new phpbb_extension_metadata_manager_test( - $ext_name, - $this->new_dbal(), - $this->extension_manager, - $this->phpbb_root_path, - '.php', - new phpbb_template( - $this->phpbb_root_path, - '.php', - new phpbb_config(array()), - new phpbb_user(), - new phpbb_style_resource_locator() - ), - new phpbb_config(array( - 'version' => '3.1.0', - )) - ); + $manager = $this->get_metadata_manager($ext_name); // Non-existant data try @@ -358,6 +336,25 @@ class metadata_manager_test extends phpbb_database_test_case $this->fail($e); } } + + /** + * Get an instance of the metadata manager + * + * @param string $ext_name + * @return phpbb_extension_metadata_manager_test + */ + private function get_metadata_manager($ext_name) + { + return new phpbb_extension_metadata_manager_test( + $ext_name, + $this->new_dbal(), + $this->extension_manager, + $this->phpbb_root_path, + $this->phpEx, + $this->template, + $this->config + ); + } } class phpbb_extension_metadata_manager_test extends phpbb_extension_metadata_manager diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a1deeb2b63..6b4c0b6883 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -252,6 +252,48 @@ class phpbb_functional_test_case extends phpbb_test_case } } + /** + * Login to the ACP + * You must run login() before calling this. + */ + protected function admin_login() + { + $this->add_lang('acp/common'); + + // Requires login first! + if (empty($this->sid)) + { + $this->fail('$this->sid is empty. Make sure you call login() before admin_login()'); + return; + } + + $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); + + $form = $crawler->selectButton($this->lang('LOGIN'))->form(); + + foreach ($form->getValues() as $field => $value) + { + if (strpos($field, 'password_') === 0) + { + $login = $this->client->submit($form, array('username' => 'admin', $field => 'admin')); + + $cookies = $this->cookieJar->all(); + + // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie + foreach ($cookies as $cookie); + { + if (substr($cookie->getName(), -4) == '_sid') + { + $this->sid = $cookie->getValue(); + } + } + + break; + } + } + } + protected function add_lang($lang_file) { if (is_array($lang_file)) @@ -288,4 +330,16 @@ class phpbb_functional_test_case extends phpbb_test_case return call_user_func_array('sprintf', $args); } + + /** + * assertContains for language strings + * + * @param string $needle Search string + * @param string $haystack Search this + * @param string $message Optional failure message + */ + public function assertContainsLang($needle, $haystack, $message = null) + { + $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); + } } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 46feef550a..d10645a732 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -115,4 +115,112 @@ class phpbb_test_case_helpers return $config; } + + /** + * Recursive directory copying function + * + * @param string $source + * @param string $dest + * @return array list of files copied + */ + public function copy_dir($source, $dest) + { + $source = (substr($source, -1) == '/') ? $source : $source . '/'; + $dest = (substr($dest, -1) == '/') ? $dest : $dest . '/'; + + $copied_files = array(); + + if (!is_dir($dest)) + { + $this->makedirs($dest); + } + + $files = scandir($source); + foreach ($files as $file) + { + if ($file == '.' || $file == '..') + { + continue; + } + + if (is_dir($source . $file)) + { + $created_dir = false; + if (!is_dir($dest . $file)) + { + $created_dir = true; + $this->makedirs($dest . $file); + } + + $copied_files = array_merge($copied_files, self::copy_dir($source . $file, $dest . $file)); + + if ($created_dir) + { + $copied_files[] = $dest . $file; + } + } + else + { + if (!file_exists($dest . $file)) + { + copy($source . $file, $dest . $file); + + $copied_files[] = $dest . $file; + } + } + } + + return $copied_files; + } + + /** + * Remove files/directories that are listed in an array + * Designed for use with $this->copy_dir() + * + * @param array $file_list + */ + public function remove_files($file_list) + { + foreach ($file_list as $file) + { + if (is_dir($file)) + { + rmdir($file); + } + else + { + unlink($file); + } + } + } + + /** + * Empty directory (remove any subdirectories/files below) + * + * @param array $file_list + */ + public function empty_dir($path) + { + $path = (substr($path, -1) == '/') ? $path : $path . '/'; + + $files = scandir($path); + foreach ($files as $file) + { + if ($file == '.' || $file == '..') + { + continue; + } + + if (is_dir($path . $file)) + { + $this->empty_dir($path . $file); + + rmdir($path . $file); + } + else + { + unlink($path . $file); + } + } + } } From 47898cb37a1c1f517b5e6ae95427807ea5de11da Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 13:36:51 -0500 Subject: [PATCH 246/645] [ticket/10631] Fix metadata_manager_test PHPBB3-10631 --- tests/extension/metadata_manager_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index d1e60ad268..801d4dbeca 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -47,7 +47,7 @@ class metadata_manager_test extends phpbb_database_test_case ); $this->extension_manager = new phpbb_extension_manager( - $this->db(), + $this->db, $this->config, 'phpbb_ext', $this->phpbb_root_path, @@ -347,7 +347,7 @@ class metadata_manager_test extends phpbb_database_test_case { return new phpbb_extension_metadata_manager_test( $ext_name, - $this->new_dbal(), + $this->db, $this->extension_manager, $this->phpbb_root_path, $this->phpEx, From dce04b2d03f93c9237b743afbcbd89fb6405f836 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 19:30:49 -0500 Subject: [PATCH 247/645] [ticket/10631] Various front-end fixes (extensions manager) Add Back button from details Add cancel button from actions Correct language strings PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 2 ++ phpBB/adm/style/acp_ext_disable.html | 5 +++-- phpBB/adm/style/acp_ext_enable.html | 3 ++- phpBB/adm/style/acp_ext_purge.html | 5 +++-- phpBB/includes/acp/acp_extensions.php | 9 +++++++++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index 7408e88758..e927e9de18 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -2,6 +2,8 @@ + « {L_BACK} +

{L_EXTENSIONS_ADMIN}

diff --git a/phpBB/adm/style/acp_ext_disable.html b/phpBB/adm/style/acp_ext_disable.html index 1f0bbe14c8..7dc3f6ec97 100644 --- a/phpBB/adm/style/acp_ext_disable.html +++ b/phpBB/adm/style/acp_ext_disable.html @@ -5,7 +5,7 @@

{L_EXTENSIONS_ADMIN}

{L_EXTENSIONS_EXPLAIN}

-

{L_ENABLE_EXPLAIN}

+

{L_DISABLE_EXPLAIN}

@@ -15,7 +15,8 @@
{L_DISABLE} - + +
diff --git a/phpBB/adm/style/acp_ext_enable.html b/phpBB/adm/style/acp_ext_enable.html index 9f278bfbe0..3f7be2c847 100644 --- a/phpBB/adm/style/acp_ext_enable.html +++ b/phpBB/adm/style/acp_ext_enable.html @@ -15,7 +15,8 @@
{L_ENABLE} - + +
diff --git a/phpBB/adm/style/acp_ext_purge.html b/phpBB/adm/style/acp_ext_purge.html index 816fd872b9..00a58721cb 100644 --- a/phpBB/adm/style/acp_ext_purge.html +++ b/phpBB/adm/style/acp_ext_purge.html @@ -5,7 +5,7 @@

{L_EXTENSIONS_ADMIN}

{L_EXTENSIONS_EXPLAIN}

-

{L_ENABLE_EXPLAIN}

+

{L_PURGE_EXPLAIN}

@@ -15,7 +15,8 @@
{L_PURGE} - + +
diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index c4d9f0c0e0..1a9d51505a 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -43,6 +43,13 @@ class acp_extensions $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); + + // Cancel action + if ($request->is_set_post('cancel')) + { + $action = 'list'; + $ext_name = ''; + } // If they've specificed an extension, let's load the metadata manager and validate it. if ($ext_name) @@ -162,6 +169,8 @@ class acp_extensions // Output it to the template $md_manager->output_template_data(); + $template->assign_var('U_BACK', $this->u_action . '&action=list'); + $this->tpl_name = 'acp_ext_details'; break; } From 7b643fe8a5fd3b92bb4db9eacb27645417004709 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 5 Aug 2012 19:00:20 -0500 Subject: [PATCH 248/645] [ticket/10631] Make failure to meet ext enable requirements clearer Turn the blocks red on the details page if requirement is not met. Also changing a how the errors come up when trying to enable/disable an extension when they cannot be. PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 6 +++--- phpBB/adm/style/admin.css | 10 ++++++++++ phpBB/includes/acp/acp_extensions.php | 15 +++++++++----- phpBB/includes/extension/metadata_manager.php | 9 +++++++-- tests/extension/acp.php | 20 +++++++++---------- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index e927e9de18..f477b452b7 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -3,7 +3,7 @@ « {L_BACK} - +

{L_EXTENSIONS_ADMIN}

@@ -50,13 +50,13 @@
{L_REQUIREMENTS} -
+ class="requirements_not_met">

{MD_REQUIRE_PHPBB}

-
+ class="requirements_not_met">

{MD_REQUIRE_PHP}

diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index 08613de0dd..585707600d 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -1718,3 +1718,13 @@ fieldset.permissions .padding { .phpinfo td, .phpinfo th, .phpinfo h2, .phpinfo h1 { text-align: left; } + +.requirements_not_met { + padding: 5px; + background-color: #BC2A4D; +} + +.requirements_not_met dt label, .requirements_not_met dd p { + color: #FFFFFF; + font-size: 1.4em; +} \ No newline at end of file diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 1a9d51505a..8dde6bc36c 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -43,7 +43,7 @@ class acp_extensions $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); - + // Cancel action if ($request->is_set_post('cancel')) { @@ -79,9 +79,14 @@ class acp_extensions break; case 'enable_pre': - if (!$md_manager->validate_enable() || $phpbb_extension_manager->enabled($ext_name)) + if (!$md_manager->validate_enable()) { - trigger_error('EXTENSION_NOT_AVAILABLE'); + trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action)); + } + + if ($phpbb_extension_manager->enabled($ext_name)) + { + redirect($this->u_action); } $this->tpl_name = 'acp_ext_enable'; @@ -95,7 +100,7 @@ class acp_extensions case 'enable': if (!$md_manager->validate_enable()) { - trigger_error('EXTENSION_NOT_AVAILABLE'); + trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action)); } if ($phpbb_extension_manager->enable_step($ext_name)) @@ -115,7 +120,7 @@ class acp_extensions case 'disable_pre': if (!$phpbb_extension_manager->enabled($ext_name)) { - trigger_error('EXTENSION_NOT_AVAILABLE'); + redirect($this->u_action); } $this->tpl_name = 'acp_ext_disable'; diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index c7f52b7c02..8a68e464a7 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -320,8 +320,13 @@ class phpbb_extension_metadata_manager 'MD_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', 'MD_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), - 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', - 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + + 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', + 'MD_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), + + 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + 'MD_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), + 'MD_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', )); diff --git a/tests/extension/acp.php b/tests/extension/acp.php index c078a3f7b4..78a770343b 100644 --- a/tests/extension/acp.php +++ b/tests/extension/acp.php @@ -178,9 +178,11 @@ class acp_test extends phpbb_functional_test_case public function test_enable_pre() { - // Foo is already enabled (error) + // Foo is already enabled (redirect to list) $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=foo&sid=' . $this->sid); - $this->assertContainsLang('EXTENSION_NOT_AVAILABLE', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->text()); @@ -188,9 +190,11 @@ class acp_test extends phpbb_functional_test_case public function test_disable_pre() { - // Moo is not enabled (error) + // Moo is not enabled (redirect to list) $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); - $this->assertContainsLang('EXTENSION_NOT_AVAILABLE', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=foo&sid=' . $this->sid); $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text()); @@ -206,20 +210,14 @@ class acp_test extends phpbb_functional_test_case $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text()); } - public function test_enable() + public function test_actions() { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContainsLang('ENABLE_SUCCESS', $crawler->filter('html')->text()); - } - public function test_disable() - { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContainsLang('DISABLE_SUCCESS', $crawler->filter('html')->text()); - } - public function test_purge() - { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text()); } From 323bbf9b523984a592dc17bf35d2bb91a435be1b Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Fri, 17 Aug 2012 14:06:23 +0100 Subject: [PATCH 249/645] [ticket/10631] Adjust prefixes to be easier to understand PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 74 +++++++++---------- phpBB/adm/style/acp_ext_list.html | 4 +- phpBB/includes/acp/acp_extensions.php | 12 +-- phpBB/includes/extension/metadata_manager.php | 26 +++---- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index f477b452b7..e7532691ad 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -8,57 +8,57 @@
{L_EXT_DETAILS} - +
-
-
{MD_DISPLAY_NAME}
+
+
{META_DISPLAY_NAME}
-
-
{MD_NAME}
+
+
{META_NAME}
- +
-
-

{MD_DESCRIPTION}

+
+

{META_DESCRIPTION}

-
-

{MD_VERSION}

+
+

{META_VERSION}

- +
-
-

{MD_HOMEPAGE}

+
+

{META_HOMEPAGE}

- +
-
-

{MD_TIME}

+
+

{META_TIME}

-
-

{MD_LICENCE}

+
+

{META_LICENCE}

- +
{L_REQUIREMENTS} - - class="requirements_not_met"> + + class="requirements_not_met">
-

{MD_REQUIRE_PHPBB}

+

{META_REQUIRE_PHPBB}

- - class="requirements_not_met"> + + class="requirements_not_met">
-

{MD_REQUIRE_PHP}

+

{META_REQUIRE_PHP}

@@ -66,32 +66,32 @@
{L_AUTHOR_INFORMATION} - +
-
-
{md_authors.AUTHOR_NAME}
+
+
{meta_authors.AUTHOR_NAME}
- +
-
-
{md_authors.AUTHOR_EMAIL}
+
+
{meta_authors.AUTHOR_EMAIL}
- +
-
-
{md_authors.AUTHOR_HOMEPAGE}
+
+
{meta_authors.AUTHOR_HOMEPAGE}
- +
-
{md_authors.AUTHOR_ROLE}
+
{meta_authors.AUTHOR_ROLE}
- +
diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index b654a80caa..53de0b4d12 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -24,7 +24,7 @@ - {enabled.EXT_NAME} + {enabled.META_DISPLAY_NAME} {L_DETAILS} @@ -42,7 +42,7 @@ - {disabled.EXT_NAME} + {disabled.META_DISPLAY_NAME} {L_DETAILS} diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 8dde6bc36c..5a537aaa42 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -196,7 +196,7 @@ class acp_extensions try { $this->template->assign_block_vars('enabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'), 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); @@ -209,7 +209,7 @@ class acp_extensions catch(phpbb_extension_exception $e) { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); } } @@ -230,7 +230,7 @@ class acp_extensions try { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'), 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); @@ -243,7 +243,7 @@ class acp_extensions catch(phpbb_extension_exception $e) { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); } } @@ -266,7 +266,7 @@ class acp_extensions try { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'), 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); @@ -278,7 +278,7 @@ class acp_extensions catch(phpbb_extension_exception $e) { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); } } diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 8a68e464a7..1e3bbe48c9 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -313,26 +313,26 @@ class phpbb_extension_metadata_manager public function output_template_data() { $this->template->assign_vars(array( - 'MD_NAME' => htmlspecialchars($this->metadata['name']), - 'MD_TYPE' => htmlspecialchars($this->metadata['type']), - 'MD_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '', - 'MD_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', - 'MD_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', - 'MD_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', - 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), + 'META_NAME' => htmlspecialchars($this->metadata['name']), + 'META_TYPE' => htmlspecialchars($this->metadata['type']), + 'META_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '', + 'META_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', + 'META_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', + 'META_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', + 'META_LICENCE' => htmlspecialchars($this->metadata['licence']), - 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', - 'MD_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), + 'META_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', + 'META_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), - 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', - 'MD_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), + 'META_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + 'META_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), - 'MD_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', + 'META_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', )); foreach ($this->metadata['authors'] as $author) { - $this->template->assign_block_vars('md_authors', array( + $this->template->assign_block_vars('meta_authors', array( 'AUTHOR_NAME' => htmlspecialchars($author['name']), 'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '', 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '', From f05a175e3955d1dc1d2b85b9929ca4b30340ad4a Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Fri, 17 Aug 2012 14:38:03 +0100 Subject: [PATCH 250/645] [ticket/10631] Fixing a few extension admin issues PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 3 --- tests/extension/ext/foo/composer.json | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 1e3bbe48c9..8c570830fe 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -60,7 +60,6 @@ class phpbb_extension_metadata_manager */ public function get_metadata($element = 'all') { - // TODO: Check ext_name exists and is an extension that exists $this->set_metadata_file(); // Fetch the metadata @@ -339,7 +338,5 @@ class phpbb_extension_metadata_manager 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); } - - return; } } diff --git a/tests/extension/ext/foo/composer.json b/tests/extension/ext/foo/composer.json index 4b5150461f..744f7be625 100644 --- a/tests/extension/ext/foo/composer.json +++ b/tests/extension/ext/foo/composer.json @@ -4,7 +4,7 @@ "description": "An example/sample extension to be used for testing purposes in phpBB Development.", "version": "1.0.0", "time": "2012-02-15 01:01:01", - "licence": "GNU GPL v2", + "licence": "GPL-2.0", "authors": [{ "name": "Nathan Guse", "username": "EXreaction", From a9b4f2a190777612762966476ac5af9ac2a78fd0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 27 Aug 2012 17:39:32 -0500 Subject: [PATCH 251/645] [ticket/10631] Some cleanup of the test cases The acp test case was not actually validating things correctly. Now is does PHPBB3-10631 --- tests/extension/acp.php | 73 ++++++--------- tests/extension/metadata_manager_test.php | 105 +++++++++++++++++----- 2 files changed, 109 insertions(+), 69 deletions(-) diff --git a/tests/extension/acp.php b/tests/extension/acp.php index 78a770343b..790df77c0d 100644 --- a/tests/extension/acp.php +++ b/tests/extension/acp.php @@ -119,59 +119,40 @@ class acp_test extends phpbb_functional_test_case { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid); + $validation = array( + 'DISPLAY_NAME' => 'phpBB Foo Extension', + 'CLEAN_NAME' => 'foo/example', + 'DESCRIPTION' => 'An example/sample extension to be used for testing purposes in phpBB Development.', + 'VERSION' => '1.0.0', + 'TIME' => '2012-02-15 01:01:01', + 'LICENCE' => 'GPL-2.0', + 'PHPBB_VERSION' => '3.1.0-dev', + 'PHP_VERSION' => '>=5.3', + 'AUTHOR_NAME' => 'Nathan Guse', + 'AUTHOR_EMAIL' => 'email@phpbb.com', + 'AUTHOR_HOMEPAGE' => 'http://lithiumstudios.org', + 'AUTHOR_ROLE' => 'N/A', + ); + for ($i = 0; $i < $crawler->filter('dl')->count(); $i++) { $text = $crawler->filter('dl')->eq($i)->text(); - switch (true) + $match = false; + + foreach ($validation as $language_key => $expected) { - case (strpos($text, $this->lang('DISPLAY_NAME')) === 0): - $this->assertContains('phpBB Foo Extension', $text); - break; + if (strpos($text, $this->lang($language_key)) === 0) + { + $match = true; - case (strpos($text, $this->lang('CLEAN_NAME')) === 0): - $this->assertContains('foo/example', $text); - break; + $this->assertContains($expected, $text); + } + } - case (strpos($text, $this->lang('DESCRIPTION')) === 0): - $this->assertContains('An example/sample extension to be used for testing purposes in phpBB Development.', $text); - break; - - case (strpos($text, $this->lang('VERSION')) === 0): - $this->assertContains('1.0.0', $text); - break; - - case (strpos($text, $this->lang('TIME')) === 0): - $this->assertContains('2012-02-15 01:01:01', $text); - break; - - case (strpos($text, $this->lang('LICENCE')) === 0): - $this->assertContains('GNU GPL v2', $text); - break; - - case (strpos($text, $this->lang('PHPBB_VERSION')) === 0): - $this->assertContains('3.1.0-dev', $text); - break; - - case (strpos($text, $this->lang('PHP_VERSION')) === 0): - $this->assertContains('>=5.3', $text); - break; - - case (strpos($text, $this->lang('AUTHOR_NAME')) === 0): - $this->assertContains('Nathan Guse', $text); - break; - - case (strpos($text, $this->lang('AUTHOR_EMAIL')) === 0): - $this->assertContains('email@phpbb.com', $text); - break; - - case (strpos($text, $this->lang('AUTHOR_HOMEPAGE')) === 0): - $this->assertContains('http://lithiumstudios.org', $text); - break; - - case (strpos($text, $this->lang('AUTHOR_ROLE')) === 0): - $this->assertContains('N/A', $text); - break; + if (!$match) + { + $this->fail('Unexpected field: "' . $text . '"'); } } } diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 801d4dbeca..9865f14314 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -93,7 +93,7 @@ class metadata_manager_test extends phpbb_database_test_case $this->assertEquals($metadata, $json); } - public function test_validator() + public function test_validator_non_existant() { $ext_name = 'validator'; @@ -103,37 +103,57 @@ class metadata_manager_test extends phpbb_database_test_case try { $manager->validate('name'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.'); try { $manager->validate('type'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.'); try { $manager->validate('licence'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'licence\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'licence\' has not been set.'); try { $manager->validate('version'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.'); try { $manager->validate_authors(); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.'); $manager->merge_metadata(array( 'authors' => array( @@ -144,10 +164,21 @@ class metadata_manager_test extends phpbb_database_test_case try { $manager->validate_authors(); - } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.'); + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.'); + } + } + + + public function test_validator_invalid() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); // Invalid data $manager->set_metadata(array( @@ -160,31 +191,53 @@ class metadata_manager_test extends phpbb_database_test_case try { $manager->validate('name'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'name\' is invalid.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Meta field \'name\' is invalid.'); try { $manager->validate('type'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'type\' is invalid.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Meta field \'type\' is invalid.'); try { $manager->validate('licence'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'licence\' is invalid.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Meta field \'licence\' is invalid.'); try { $manager->validate('version'); - } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Meta field \'version\' is invalid.'); + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'version\' is invalid.'); + } + } + + public function test_validator_valid() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); // Valid data $manager->set_metadata(array( @@ -202,8 +255,14 @@ class metadata_manager_test extends phpbb_database_test_case { $this->fail($e); } + } + public function test_validator_requirements() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); // Too high of requirements $manager->merge_metadata(array( 'require' => array( From 7cffebbd4997f8a41a871f8ea6fe12dc0abc08c8 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 19 Aug 2012 17:24:38 -0400 Subject: [PATCH 252/645] [task/functional] Added posting tests (reply and new topic) PHPBB-10758 --- tests/functional/posting_test.php | 110 ++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 tests/functional/posting_test.php diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php new file mode 100644 index 0000000000..8d722361e0 --- /dev/null +++ b/tests/functional/posting_test.php @@ -0,0 +1,110 @@ +login(); + $this->add_lang('posting'); + + $crawler = $this->request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); + $this->assertContains($this->lang('POST_TOPIC'), $crawler->filter('html')->text()); + + $hidden_fields = array(); + $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }); + + $test_message = 'This is a test topic posted by the testing framework.'; + $form_data = array( + 'subject' => 'Test Topic 1', + 'message' => $test_message, + 'post' => true, + 'f' => 2, + 'mode' => 'post', + 'sid' => $this->sid, + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + // The add_form_key()/check_form_key() safeguards present a challenge because they require + // the timestamp created in add_form_key() to be sent as-is to check_form_key() but in check_form_key() + // it won't allow the current time to be the same as the timestamp it requires. + // As such, automated scripts like this one have to somehow bypass this without being able to change + // the timestamp. The only way I can think to do so is using sleep() + sleep(1); + + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = $this->client->request('POST', 'posting.php', $form_data); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); + $this->assertContains($test_message, $crawler->filter('html')->text()); + } + + public function test_post_reply() + { + $this->login(); + $this->add_lang('posting'); + + $crawler = $this->request('GET', 'posting.php?mode=reply&t=2&f=2&sid=' . $this->sid); + $this->assertContains($this->lang('POST_REPLY'), $crawler->filter('html')->text()); + + $hidden_fields = array(); + $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }); + + $test_message = 'This is a test post posted by the testing framework.'; + $form_data = array( + 'subject' => 'Re: Test Topic 1', + 'message' => $test_message, + 'post' => true, + 't' => 2, + 'f' => 2, + 'mode' => 'reply', + 'sid' => $this->sid, + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // For reasoning behind the following two commands, see the test_post_new_topic() test + $form_data['lastclick'] = 0; + sleep(1); + + // Submit the post + $crawler = $this->client->request('POST', 'posting.php', $form_data); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); + $this->assertContains($test_message, $crawler->filter('html')->text()); + } +} From 7dfe26dd781e7bd0438041058e2a1d95176e7836 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 1 Sep 2012 10:35:46 -0400 Subject: [PATCH 253/645] [task/functional] Allow tests to bypass certain restrictions with DEBUG_TEST PHPBB3-10758 --- phpBB/includes/functions.php | 2 +- phpBB/includes/functions_install.php | 5 ++++- tests/functional/posting_test.php | 10 +--------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 5914831539..8e7e84bf83 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2811,7 +2811,7 @@ function check_form_key($form_name, $timespan = false, $return_page = '', $trigg $diff = time() - $creation_time; // If creation_time and the time() now is zero we can assume it was not a human doing this (the check for if ($diff)... - if ($diff && ($diff <= $timespan || $timespan === -1)) + if (defined('DEBUG_TEST') || $diff && ($diff <= $timespan || $timespan === -1)) { $token_sid = ($user->data['user_id'] == ANONYMOUS && !empty($config['form_token_sid_guests'])) ? $user->session_id : ''; $key = sha1($creation_time . $user->data['user_form_salt'] . $form_name . $token_sid); diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 89dfb7cd2f..2e10db6b24 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -551,10 +551,12 @@ function adjust_language_keys_callback($matches) * @param string $dbms The name of the DBAL class to use * @param array $load_extensions Array of additional extensions that should be loaded * @param bool $debug If the debug constants should be enabled by default or not +* @param bool $debug_test If the DEBUG_TEST constant should be added +* NOTE: Only for use within the testing framework * * @return string The output to write to the file */ -function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = false) +function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = false, $debug_test = false) { $load_extensions = implode(',', $load_extensions); @@ -584,6 +586,7 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = { $config_data .= "@define('DEBUG', true);\n"; $config_data .= "@define('DEBUG_EXTRA', true);\n"; + $config_data .= "@define('DEBUG_TEST', true);\n"; } else { diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 8d722361e0..f54a3591b2 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -47,13 +47,6 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // is not at least 2 seconds before submission, cancel the form $form_data['lastclick'] = 0; - // The add_form_key()/check_form_key() safeguards present a challenge because they require - // the timestamp created in add_form_key() to be sent as-is to check_form_key() but in check_form_key() - // it won't allow the current time to be the same as the timestamp it requires. - // As such, automated scripts like this one have to somehow bypass this without being able to change - // the timestamp. The only way I can think to do so is using sleep() - sleep(1); - // I use a request because the form submission method does not allow you to send data that is not // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) // Instead, I send it as a request with the submit button "post" set to true. @@ -96,9 +89,8 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case } } - // For reasoning behind the following two commands, see the test_post_new_topic() test + // For reasoning behind the following command, see the test_post_new_topic() test $form_data['lastclick'] = 0; - sleep(1); // Submit the post $crawler = $this->client->request('POST', 'posting.php', $form_data); From 4dd1bbc5879ae5fcae04341a9152e0366ed68bdd Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 1 Sep 2012 10:53:01 -0400 Subject: [PATCH 254/645] [task/functional] Fixed DEBUG_TEST related issues PHPBB3-10758 --- phpBB/includes/functions_install.php | 6 +++++- tests/test_framework/phpbb_functional_test_case.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 2e10db6b24..eae136808c 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -586,7 +586,6 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = { $config_data .= "@define('DEBUG', true);\n"; $config_data .= "@define('DEBUG_EXTRA', true);\n"; - $config_data .= "@define('DEBUG_TEST', true);\n"; } else { @@ -594,6 +593,11 @@ function phpbb_create_config_file_data($data, $dbms, $load_extensions, $debug = $config_data .= "// @define('DEBUG_EXTRA', true);\n"; } + if ($debug_test) + { + $config_data .= "@define('DEBUG_TEST', true);\n"; + } + return $config_data; } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 2423299b7c..d35913e415 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -140,7 +140,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->do_request('create_table', $data); $this->do_request('config_file', $data); - file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true)); + file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true)); $this->do_request('final', $data); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); From 0c35ee2769d3945f25275d5ee7a130b7596d289f Mon Sep 17 00:00:00 2001 From: "Michael C." Date: Sat, 1 Sep 2012 17:32:59 +0200 Subject: [PATCH 255/645] [ticket/10631] Fix a spelling typo PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 5a537aaa42..a0bcf62ecc 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -51,7 +51,7 @@ class acp_extensions $ext_name = ''; } - // If they've specificed an extension, let's load the metadata manager and validate it. + // If they've specified an extension, let's load the metadata manager and validate it. if ($ext_name) { $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template, $config); From ed052290a70ae3a42f9e7c59f3dca95aba0c0ac7 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 17:40:19 +0200 Subject: [PATCH 256/645] [ticket/11082] Remove executable permission from redis driver file PHPBB3-11082 --- phpBB/includes/cache/driver/redis.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 phpBB/includes/cache/driver/redis.php diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php old mode 100755 new mode 100644 From 8741bcdaf5bb815a228188b4dfe4e3beebcca3b3 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 17:51:27 +0200 Subject: [PATCH 257/645] [ticket/11083] Mark memory cache driver as abstract PHPBB3-11083 --- phpBB/includes/cache/driver/memory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 92971c6cb2..e0771ab1d3 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -19,7 +19,7 @@ if (!defined('IN_PHPBB')) * ACM Abstract Memory Class * @package acm */ -class phpbb_cache_driver_memory extends phpbb_cache_driver_base +abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base { var $key_prefix; From 7ed7b19a1f1c3732b561ec3c8a4a39f115b5e6ac Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 19:12:57 +0200 Subject: [PATCH 258/645] [feature/dic] Remove unneeded newline PHPBB3-10739 --- phpBB/common.php | 1 - 1 file changed, 1 deletion(-) diff --git a/phpBB/common.php b/phpBB/common.php index 6ca495a7e3..281eb88c4d 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -86,7 +86,6 @@ require($phpbb_root_path . 'includes/constants.' . $phpEx); require($phpbb_root_path . 'includes/db/' . ltrim($dbms, 'dbal_') . '.' . $phpEx); require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); - // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); From 282a80077d4630ba59043fffe59e8a7ce8619ecb Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 1 Sep 2012 19:17:01 +0200 Subject: [PATCH 259/645] [feature/dic] Spaces to tabs, add useless docblocks Fully documents the constructors of the processors and the cron tasks. PHPBB3-10739 --- .../cron/task/core/prune_all_forums.php | 8 ++ phpBB/includes/cron/task/core/prune_forum.php | 8 ++ phpBB/includes/cron/task/core/queue.php | 7 ++ phpBB/includes/cron/task/core/tidy_cache.php | 6 ++ .../includes/cron/task/core/tidy_database.php | 7 ++ phpBB/includes/cron/task/core/tidy_search.php | 10 +++ .../includes/cron/task/core/tidy_sessions.php | 6 ++ .../includes/cron/task/core/tidy_warnings.php | 7 ++ phpBB/includes/di/processor/config.php | 82 +++++++++++-------- phpBB/includes/di/processor/ext.php | 47 +++++++---- phpBB/includes/di/processor/interface.php | 9 +- 11 files changed, 143 insertions(+), 54 deletions(-) diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index 5164087b68..252e16e57d 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -31,6 +31,14 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base protected $config; protected $db; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + * @param dbal $db The db connection + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 8bb13ffe36..41d60af921 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -41,6 +41,14 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p */ protected $forum_data; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + * @param dbal $db The db connection + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config, dbal $db) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index 3278ce9d76..c765660906 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -26,6 +26,13 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base protected $php_ext; protected $config; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index 573243c166..6017eea561 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -25,6 +25,12 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base protected $config; protected $cache; + /** + * Constructor. + * + * @param phpbb_config $config The config + * @param phpbb_cache_driver_interface $cache The cache driver + */ public function __construct(phpbb_config $config, phpbb_cache_driver_interface $cache) { $this->config = $config; diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index c9f81cbb51..1d256f964f 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -26,6 +26,13 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base protected $php_ext; protected $config; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 00af293b6d..2e5f3d79d5 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -31,6 +31,16 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base protected $db; protected $user; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_auth $auth The auth + * @param phpbb_config $config The config + * @param dbal $db The db connection + * @param phpbb_user $user The user + */ public function __construct($phpbb_root_path, $php_ext, phpbb_auth $auth, phpbb_config $config, dbal $db, phpbb_user $user) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index 695a537274..13531aa30b 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -25,6 +25,12 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base protected $config; protected $user; + /** + * Constructor. + * + * @param phpbb_config $config The config + * @param phpbb_user $user The user + */ public function __construct(phpbb_config $config, phpbb_user $user) { $this->config = $config; diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index acffd12052..8dd0674fe5 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -28,6 +28,13 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base protected $php_ext; protected $config; + /** + * Constructor. + * + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + * @param phpbb_config $config The config + */ public function __construct($phpbb_root_path, $php_ext, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; diff --git a/phpBB/includes/di/processor/config.php b/phpBB/includes/di/processor/config.php index 1a5ec15854..22b6252a6d 100644 --- a/phpBB/includes/di/processor/config.php +++ b/phpBB/includes/di/processor/config.php @@ -12,51 +12,65 @@ */ if (!defined('IN_PHPBB')) { - exit; + exit; } use Symfony\Component\DependencyInjection\ContainerBuilder; +/** +* Configure the container for phpBB's services though +* user-defined parameters defined in the config.php file. +*/ class phpbb_di_processor_config implements phpbb_di_processor_interface { - private $config_file; - private $phpbb_root_path; - private $php_ext; + private $config_file; + private $phpbb_root_path; + private $php_ext; - public function __construct($config_file, $phpbb_root_path, $php_ext) - { - $this->config_file = $config_file; - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - } + /** + * Constructor. + * + * @param string $config_file The config file + * @param string $phpbb_root_path The root path + * @param string $php_ext The PHP extension + */ + public function __construct($config_file, $phpbb_root_path, $php_ext) + { + $this->config_file = $config_file; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } - public function process(ContainerBuilder $container) - { - require $this->config_file; + /** + * @inheritdoc + */ + public function process(ContainerBuilder $container) + { + require $this->config_file; - $container->setParameter('core.root_path', $this->phpbb_root_path); - $container->setParameter('core.php_ext', $this->php_ext); + $container->setParameter('core.root_path', $this->phpbb_root_path); + $container->setParameter('core.php_ext', $this->php_ext); - $container->setParameter('core.table_prefix', $table_prefix); - $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); - $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); - $container->setParameter('dbal.dbhost', $dbhost); - $container->setParameter('dbal.dbuser', $dbuser); - $container->setParameter('dbal.dbpasswd', $dbpasswd); - $container->setParameter('dbal.dbname', $dbname); - $container->setParameter('dbal.dbport', $dbport); - $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); + $container->setParameter('core.table_prefix', $table_prefix); + $container->setParameter('cache.driver.class', $this->fix_acm_type($acm_type)); + $container->setParameter('dbal.driver.class', 'dbal_'.$dbms); + $container->setParameter('dbal.dbhost', $dbhost); + $container->setParameter('dbal.dbuser', $dbuser); + $container->setParameter('dbal.dbpasswd', $dbpasswd); + $container->setParameter('dbal.dbname', $dbname); + $container->setParameter('dbal.dbport', $dbport); + $container->setParameter('dbal.new_link', defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK); - $container->set('container', $container); - } + $container->set('container', $container); + } - protected function fix_acm_type($acm_type) - { - if (preg_match('#^[a-z]+$#', $acm_type)) - { - return 'phpbb_cache_driver_'.$acm_type; - } + protected function fix_acm_type($acm_type) + { + if (preg_match('#^[a-z]+$#', $acm_type)) + { + return 'phpbb_cache_driver_'.$acm_type; + } - return $acm_type; - } + return $acm_type; + } } diff --git a/phpBB/includes/di/processor/ext.php b/phpBB/includes/di/processor/ext.php index 04a586a086..e69a3d73b3 100644 --- a/phpBB/includes/di/processor/ext.php +++ b/phpBB/includes/di/processor/ext.php @@ -12,32 +12,43 @@ */ if (!defined('IN_PHPBB')) { - exit; + exit; } use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +/** +* Load the service configurations from all extensions into the container. +*/ class phpbb_di_processor_ext implements phpbb_di_processor_interface { - private $extension_manager; + private $extension_manager; - public function __construct($extension_manager) - { - $this->extension_manager = $extension_manager; - } + /** + * Constructor. + * + * @param string $extension_manager The extension manager + */ + public function __construct($extension_manager) + { + $this->extension_manager = $extension_manager; + } - public function process(ContainerBuilder $container) - { - $enabled_exts = $this->extension_manager->all_enabled(); - foreach ($enabled_exts as $name => $path) - { - if (file_exists($path . '/config/services.yml')) - { - $loader = new YamlFileLoader($container, new FileLocator($path . '/config')); - $loader->load('services.yml'); - } - } - } + /** + * @inheritdoc + */ + public function process(ContainerBuilder $container) + { + $enabled_exts = $this->extension_manager->all_enabled(); + foreach ($enabled_exts as $name => $path) + { + if (file_exists($path . '/config/services.yml')) + { + $loader = new YamlFileLoader($container, new FileLocator($path . '/config')); + $loader->load('services.yml'); + } + } + } } diff --git a/phpBB/includes/di/processor/interface.php b/phpBB/includes/di/processor/interface.php index 51bd85a076..b8563791cc 100644 --- a/phpBB/includes/di/processor/interface.php +++ b/phpBB/includes/di/processor/interface.php @@ -12,12 +12,17 @@ */ if (!defined('IN_PHPBB')) { - exit; + exit; } use Symfony\Component\DependencyInjection\ContainerBuilder; interface phpbb_di_processor_interface { - public function process(ContainerBuilder $container); + /** + * Mutate the container. + * + * @param ContainerBuilder $container The container + */ + public function process(ContainerBuilder $container); } From 81f7f28cc33d896973c2912097103ea84fa14114 Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Sat, 1 Sep 2012 21:30:35 +0100 Subject: [PATCH 260/645] [ticket/10631] Removing un-needed TODOs that are no longer needed. PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 8c570830fe..ea85bd3c4e 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -95,7 +95,6 @@ class phpbb_extension_metadata_manager return ($this->validate('name')) ? $this->metadata['name'] : false; } break; - // TODO: Add remaining cases as needed } } @@ -153,9 +152,6 @@ class phpbb_extension_metadata_manager */ private function clean_metadata_array() { -// TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors -// $this->metadata = $metadata_finished; - return $this->metadata; } From b3cd5a649be62f175de651a16ae02c5f709ca2f4 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 3 Sep 2012 13:32:33 -0500 Subject: [PATCH 261/645] [ticket/8713] Do not trim login inputs Create a function to request variables which are not trimmed. All requests for passwords (except forum passwords) now use the untrimmed request function. PHPBB3-8713 --- phpBB/includes/acp/acp_language.php | 6 +- phpBB/includes/acp/acp_users.php | 6 +- phpBB/includes/functions.php | 4 +- phpBB/includes/request/request.php | 63 +++++++++++++++++++++ phpBB/includes/request/type_cast_helper.php | 22 +++++-- phpBB/includes/ucp/ucp_profile.php | 6 +- phpBB/includes/ucp/ucp_register.php | 4 +- phpBB/install/install_update.php | 4 +- tests/request/type_cast_helper_test.php | 10 ++++ 9 files changed, 104 insertions(+), 21 deletions(-) diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index 2b19f93c75..87cf605d8e 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -100,11 +100,11 @@ class acp_language switch ($method) { case 'ftp': - $transfer = new ftp(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new ftp(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); break; case 'ftp_fsock': - $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); break; default: @@ -404,7 +404,7 @@ class acp_language trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR); } - $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); if (($result = $transfer->open_session()) !== true) { diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index b54257b04a..b9958ed0f1 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -32,7 +32,7 @@ class acp_users { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; - global $phpbb_dispatcher; + global $phpbb_dispatcher, $request; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; @@ -770,8 +770,8 @@ class acp_users 'username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)), 'user_founder' => request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0), 'email' => strtolower(request_var('user_email', $user_row['user_email'])), - 'new_password' => request_var('new_password', '', true), - 'password_confirm' => request_var('password_confirm', '', true), + 'new_password' => $request->untrimed_variable('new_password', '', true), + 'password_confirm' => $request->untrimed_variable('password_confirm', '', true), ); // Validation data - we do not check the password complexity setting here diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 834f57a38b..1cdda60855 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3044,11 +3044,11 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa trigger_error('NO_AUTH_ADMIN'); } - $password = request_var('password_' . $credential, '', true); + $password = $request->untrimed_variable('password_' . $credential, '', true); } else { - $password = request_var('password', '', true); + $password = $request->untrimed_variable('password', '', true); } $username = request_var('username', '', true); diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php index 4e425dbd27..747ca09624 100644 --- a/phpBB/includes/request/request.php +++ b/phpBB/includes/request/request.php @@ -242,6 +242,69 @@ class phpbb_request implements phpbb_request_interface return $var; } + /** + * Get a variable, but without trimming strings + * Same functionality as variable(), except does not run trim() on strings + * All variables in GET or POST requests should be retrieved through this function to maximise security. + * + * @param string|array $var_name The form variable's name from which data shall be retrieved. + * If the value is an array this may be an array of indizes which will give + * direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a") + * then specifying array("var", 1) as the name will return "a". + * @param mixed $default A default value that is returned if the variable was not set. + * This function will always return a value of the same type as the default. + * @param bool $multibyte If $default is a string this paramater has to be true if the variable may contain any UTF-8 characters + * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks + * @param phpbb_request_interface::POST|GET|REQUEST|COOKIE $super_global + * Specifies which super global should be used + * + * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the + * the same as that of $default. If the variable is not set $default is returned. + */ + public function untrimed_variable($var_name, $default, $multibyte, $super_global = phpbb_request_interface::REQUEST) + { + $path = false; + + // deep direct access to multi dimensional arrays + if (is_array($var_name)) + { + $path = $var_name; + // make sure at least the variable name is specified + if (empty($path)) + { + return (is_array($default)) ? array() : $default; + } + // the variable name is the first element on the path + $var_name = array_shift($path); + } + + if (!isset($this->input[$super_global][$var_name])) + { + return (is_array($default)) ? array() : $default; + } + $var = $this->input[$super_global][$var_name]; + + if ($path) + { + // walk through the array structure and find the element we are looking for + foreach ($path as $key) + { + if (is_array($var) && isset($var[$key])) + { + $var = $var[$key]; + } + else + { + return (is_array($default)) ? array() : $default; + } + } + } + + $this->type_cast_helper->recursive_set_var($var, $default, $multibyte, false); + + return $var; + } + /** * Shortcut method to retrieve SERVER variables. * diff --git a/phpBB/includes/request/type_cast_helper.php b/phpBB/includes/request/type_cast_helper.php index 561e8fc251..d3b94aac5a 100644 --- a/phpBB/includes/request/type_cast_helper.php +++ b/phpBB/includes/request/type_cast_helper.php @@ -93,15 +93,23 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i * @param mixed $type The variable type. Will be used with {@link settype()} * @param bool $multibyte Indicates whether string values may contain UTF-8 characters. * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks. + * @param bool $trim Indicates whether string values will be be parsed with trim() + * Default is true */ - public function set_var(&$result, $var, $type, $multibyte = false) + public function set_var(&$result, $var, $type, $multibyte = false, $trim = true) { settype($var, $type); $result = $var; if ($type == 'string') { - $result = trim(str_replace(array("\r\n", "\r", "\0"), array("\n", "\n", ''), $result)); + $result = str_replace(array("\r\n", "\r", "\0"), array("\n", "\n", ''), $result); + + if ($trim) + { + $result = trim($result); + } + $result = htmlspecialchars($result, ENT_COMPAT, 'UTF-8'); if ($multibyte) @@ -141,8 +149,10 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i * @param bool $multibyte Indicates whether string keys and values may contain UTF-8 characters. * Default is false, causing all bytes outside the ASCII range (0-127) to * be replaced with question marks. + * @param bool $trim Indicates whether string values will be be parsed with trim() + * Default is true */ - public function recursive_set_var(&$var, $default, $multibyte) + public function recursive_set_var(&$var, $default, $multibyte, $trim = true) { if (is_array($var) !== is_array($default)) { @@ -153,7 +163,7 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i if (!is_array($default)) { $type = gettype($default); - $this->set_var($var, $var, $type, $multibyte); + $this->set_var($var, $var, $type, $multibyte, $trim); } else { @@ -174,9 +184,9 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i foreach ($_var as $k => $v) { - $this->set_var($k, $k, $key_type, $multibyte, $multibyte); + $this->set_var($k, $k, $key_type, $multibyte, $trim); - $this->recursive_set_var($v, $default_value, $multibyte); + $this->recursive_set_var($v, $default_value, $multibyte, $trim); $var[$k] = $v; } } diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 2ac82fb52f..68d5dd5d65 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -46,9 +46,9 @@ class ucp_profile $data = array( 'username' => utf8_normalize_nfc(request_var('username', $user->data['username'], true)), 'email' => strtolower(request_var('email', $user->data['user_email'])), - 'new_password' => request_var('new_password', '', true), - 'cur_password' => request_var('cur_password', '', true), - 'password_confirm' => request_var('password_confirm', '', true), + 'new_password' => $request->untrimed_variable('new_password', '', true), + 'cur_password' => $request->untrimed_variable('cur_password', '', true), + 'password_confirm' => $request->untrimed_variable('password_confirm', '', true), ); add_form_key('ucp_reg_details'); diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 6ce53a79ab..6fab189a99 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -170,8 +170,8 @@ class ucp_register $data = array( 'username' => utf8_normalize_nfc(request_var('username', '', true)), - 'new_password' => request_var('new_password', '', true), - 'password_confirm' => request_var('password_confirm', '', true), + 'new_password' => $request->untrimed_variable('new_password', '', true), + 'password_confirm' => $request->untrimed_variable('password_confirm', '', true), 'email' => strtolower(request_var('email', '')), 'lang' => basename(request_var('lang', $user->lang_name)), 'tz' => request_var('tz', $timezone), diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 88b00f1cf1..4b5a23e497 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -862,7 +862,7 @@ class install_update extends module $test_connection = false; if ($test_ftp_connection || $submit) { - $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $test_connection = $transfer->open_session(); // Make sure that the directory is correct by checking for the existence of common.php @@ -948,7 +948,7 @@ class install_update extends module } else { - $transfer = new $method(request_var('host', ''), request_var('username', ''), request_var('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $transfer->open_session(); } diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index d553d5b8cd..f7e5cd873e 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -48,4 +48,14 @@ class phpbb_type_cast_helper_test extends phpbb_test_case $this->assertEquals($expected, $data); } + + public function test_untrimmed_strings() + { + $data = array(' eviL<3 '); + $expected = array(' eviL<3 '); + + $this->type_cast_helper->recursive_set_var($data, '', true, false); + + $this->assertEquals($expected, $data); + } } From 815cc4a9a3fa8c633b55925eb77f9f3bdbb5de04 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 3 Sep 2012 18:23:36 -0500 Subject: [PATCH 262/645] [ticket/8796] Make function markread obey the $post_time argument Also do a little cleanup of the markread function PHPBB3-8796 --- phpBB/includes/functions.php | 71 ++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 19 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 834f57a38b..53f48cb8a7 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1280,6 +1280,10 @@ function phpbb_timezone_select($user, $default = '', $truncate = false) * Marks a topic/forum as read * Marks a topic as posted to * +* @param string $mode (all, topics, topic, post) +* @param int|bool $forum_id Used in all, topics, and topic mode +* @param int|bool $topic_id Used in topic and post mode +* @param int $post_time 0 means current time(), otherwise to set a specific mark time * @param int $user_id can only be used with $mode == 'post' */ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $user_id = 0) @@ -1287,6 +1291,8 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ global $db, $user, $config; global $request; + $post_time = ($post_time === 0) ? time() : (int) $post_time; + if ($mode == 'all') { if ($forum_id === false || !sizeof($forum_id)) @@ -1294,9 +1300,22 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ if ($config['load_db_lastread'] && $user->data['is_registered']) { // Mark all forums read (index page) - $db->sql_query('DELETE FROM ' . TOPICS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}"); - $db->sql_query('DELETE FROM ' . FORUMS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']}"); - $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$user->data['user_id']}"); + $tables = array(TOPICS_TRACK_TABLE, FORUMS_TRACK_TABLE); + foreach ($tables as $table) + { + $sql = 'DELETE FROM ' . $table . " + WHERE user_id = {$user->data['user_id']} + AND mark_time < . $post_time"; + $db->sql_query($sql); + } + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_lastmark = $post_time + WHERE user_id = {$user->data['user_id']} + AND mark_time < $post_time"; + $db->sql_query($sql); + + $user->data['user_lastmark'] = $post_time; } else if ($config['load_anon_lastread'] || $user->data['is_registered']) { @@ -1306,16 +1325,22 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ unset($tracking_topics['tf']); unset($tracking_topics['t']); unset($tracking_topics['f']); - $tracking_topics['l'] = base_convert(time() - $config['board_startdate'], 10, 36); + $tracking_topics['l'] = base_convert($post_time - $config['board_startdate'], 10, 36); - $user->set_cookie('track', tracking_serialize($tracking_topics), time() + 31536000); + $user->set_cookie('track', tracking_serialize($tracking_topics), $post_time + 31536000); $request->overwrite($config['cookie_name'] . '_track', tracking_serialize($tracking_topics), phpbb_request_interface::COOKIE); unset($tracking_topics); if ($user->data['is_registered']) { - $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . time() . " WHERE user_id = {$user->data['user_id']}"); + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_lastmark = $post_time + WHERE user_id = {$user->data['user_id']} + AND mark_time < $post_time"; + $db->sql_query($sql); + + $user->data['user_lastmark'] = $post_time; } } } @@ -1337,12 +1362,14 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ { $sql = 'DELETE FROM ' . TOPICS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']} + AND mark_time < $post_time AND " . $db->sql_in_set('forum_id', $forum_id); $db->sql_query($sql); $sql = 'SELECT forum_id FROM ' . FORUMS_TRACK_TABLE . " WHERE user_id = {$user->data['user_id']} + AND mark_time < $post_time AND " . $db->sql_in_set('forum_id', $forum_id); $result = $db->sql_query($sql); @@ -1355,9 +1382,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ if (sizeof($sql_update)) { - $sql = 'UPDATE ' . FORUMS_TRACK_TABLE . ' - SET mark_time = ' . time() . " + $sql = 'UPDATE ' . FORUMS_TRACK_TABLE . " + SET mark_time = $post_time WHERE user_id = {$user->data['user_id']} + AND mark_time < $post_time AND " . $db->sql_in_set('forum_id', $sql_update); $db->sql_query($sql); } @@ -1370,7 +1398,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $sql_ary[] = array( 'user_id' => (int) $user->data['user_id'], 'forum_id' => (int) $f_id, - 'mark_time' => time() + 'mark_time' => $post_time, ); } @@ -1401,7 +1429,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ unset($tracking['f'][$f_id]); } - $tracking['f'][$f_id] = base_convert(time() - $config['board_startdate'], 10, 36); + $tracking['f'][$f_id] = base_convert($post_time - $config['board_startdate'], 10, 36); } if (isset($tracking['tf']) && empty($tracking['tf'])) @@ -1409,7 +1437,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ unset($tracking['tf']); } - $user->set_cookie('track', tracking_serialize($tracking), time() + 31536000); + $user->set_cookie('track', tracking_serialize($tracking), $post_time + 31536000); $request->overwrite($config['cookie_name'] . '_track', tracking_serialize($tracking), phpbb_request_interface::COOKIE); unset($tracking); @@ -1426,9 +1454,10 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ if ($config['load_db_lastread'] && $user->data['is_registered']) { - $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . ' - SET mark_time = ' . (($post_time) ? $post_time : time()) . " + $sql = 'UPDATE ' . TOPICS_TRACK_TABLE . " + SET mark_time = $post_time WHERE user_id = {$user->data['user_id']} + AND mark_time < $post_time AND topic_id = $topic_id"; $db->sql_query($sql); @@ -1441,7 +1470,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ 'user_id' => (int) $user->data['user_id'], 'topic_id' => (int) $topic_id, 'forum_id' => (int) $forum_id, - 'mark_time' => ($post_time) ? (int) $post_time : time(), + 'mark_time' => $post_time, ); $db->sql_query('INSERT INTO ' . TOPICS_TRACK_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); @@ -1461,7 +1490,6 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $tracking['tf'][$forum_id][$topic_id36] = true; } - $post_time = ($post_time) ? $post_time : time(); $tracking['t'][$topic_id36] = base_convert($post_time - $config['board_startdate'], 10, 36); // If the cookie grows larger than 10000 characters we will remove the smallest value @@ -1496,8 +1524,13 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ if ($user->data['is_registered']) { - $user->data['user_lastmark'] = intval(base_convert(max($time_keys) + $config['board_startdate'], 36, 10)); - $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_lastmark = ' . $user->data['user_lastmark'] . " WHERE user_id = {$user->data['user_id']}"); + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_lastmark = $post_time + WHERE user_id = {$user->data['user_id']} + AND mark_time < $post_time"; + $db->sql_query($sql); + + $user->data['user_lastmark'] = $post_time; } else { @@ -1505,7 +1538,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ } } - $user->set_cookie('track', tracking_serialize($tracking), time() + 31536000); + $user->set_cookie('track', tracking_serialize($tracking), $post_time + 31536000); $request->overwrite($config['cookie_name'] . '_track', tracking_serialize($tracking), phpbb_request_interface::COOKIE); } @@ -1527,7 +1560,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $sql_ary = array( 'user_id' => (int) $use_user_id, 'topic_id' => (int) $topic_id, - 'topic_posted' => 1 + 'topic_posted' => 1, ); $db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); From b9308329cf3c0e6844a35f2d274423c2640887db Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 3 Sep 2012 18:37:54 -0500 Subject: [PATCH 263/645] [ticket/8796] Revert changes to $user->data['lastmark'] The earlier change might change the way some things work (after looking at viewtopic) and I'd rather not risk introducing new bugs, so I'm going to revert those changes to be safe. PHPBB3-8796 --- phpBB/includes/functions.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 53f48cb8a7..26b73e20fe 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1314,8 +1314,6 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ WHERE user_id = {$user->data['user_id']} AND mark_time < $post_time"; $db->sql_query($sql); - - $user->data['user_lastmark'] = $post_time; } else if ($config['load_anon_lastread'] || $user->data['is_registered']) { @@ -1339,8 +1337,6 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ WHERE user_id = {$user->data['user_id']} AND mark_time < $post_time"; $db->sql_query($sql); - - $user->data['user_lastmark'] = $post_time; } } } @@ -1524,13 +1520,13 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ if ($user->data['is_registered']) { + $user->data['user_lastmark'] = intval(base_convert(max($time_keys) + $config['board_startdate'], 36, 10)); + $sql = 'UPDATE ' . USERS_TABLE . " SET user_lastmark = $post_time WHERE user_id = {$user->data['user_id']} AND mark_time < $post_time"; $db->sql_query($sql); - - $user->data['user_lastmark'] = $post_time; } else { From 9cba0b5263a8dcf0ff4cbfd6db2b37cd0cce55f1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 3 Sep 2012 18:51:29 -0500 Subject: [PATCH 264/645] [ticket/8796] Mark read links updated to include time() in url Submitting the current time() allows us to mark only the topics and forums read up until a certain time (when the user loaded the page). This means that any new posts or topics posted between when the user opened the page and clicked the link are still shown as unread. PHPBB3-8796 --- phpBB/includes/functions_display.php | 6 +++--- phpBB/index.php | 2 +- phpBB/viewforum.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 881c95907b..e9c7143473 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -59,7 +59,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod if (check_link_hash(request_var('hash', ''), 'global')) { - markread('all'); + markread('all', false, false, request_var('mark_time', 0)); trigger_error( $user->lang['FORUMS_MARKED'] . '

' . @@ -309,7 +309,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $token = request_var('hash', ''); if (check_link_hash($token, 'global')) { - markread('topics', $forum_ids); + markread('topics', $forum_ids, false, request_var('mark_time', 0)); $message = sprintf($user->lang['RETURN_FORUM'], '', ''); meta_refresh(3, $redirect); @@ -551,7 +551,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } $template->assign_vars(array( - 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums') : '', + 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time()) : '', 'S_HAS_SUBFORUM' => ($visible_forums) ? true : false, 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'], 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), diff --git a/phpBB/index.php b/phpBB/index.php index 0ac8034d7f..66e1b2114b 100644 --- a/phpBB/index.php +++ b/phpBB/index.php @@ -167,7 +167,7 @@ $template->assign_vars(array( 'S_LOGIN_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'), 'S_DISPLAY_BIRTHDAY_LIST' => ($config['load_birthdays']) ? true : false, - 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums') : '', + 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time()) : '', 'U_MCP' => ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=front', true, $user->session_id) : '') ); diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 03c2bb286f..83e5d4caa5 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -176,7 +176,7 @@ if ($mark_read == 'topics') $token = request_var('hash', ''); if (check_link_hash($token, 'global')) { - markread('topics', array($forum_id)); + markread('topics', array($forum_id), false, request_var('mark_time', 0)); } $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id); meta_refresh(3, $redirect_url); @@ -340,7 +340,7 @@ $template->assign_vars(array( 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&i=main&mode=forum_view", true, $user->session_id) : '', 'U_POST_NEW_TOPIC' => ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=post&f=' . $forum_id) : '', 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($start == 0) ? '' : "&start=$start")), - 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&f=$forum_id&mark=topics") : '', + 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&f=$forum_id&mark=topics&mark_time=" . time()) : '', )); // Grab icons From fccbf09e4aa9034afba5d5992d773b209f59bba7 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Mon, 3 Sep 2012 18:58:38 -0500 Subject: [PATCH 265/645] [ticket/8796] Fix a few issues with the previous commits Fix an SQL error and the redirect url generated PHPBB3-8796 --- phpBB/includes/functions.php | 6 +++--- phpBB/includes/functions_display.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 26b73e20fe..13cb15d73d 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1305,14 +1305,14 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ { $sql = 'DELETE FROM ' . $table . " WHERE user_id = {$user->data['user_id']} - AND mark_time < . $post_time"; + AND mark_time < $post_time"; $db->sql_query($sql); } $sql = 'UPDATE ' . USERS_TABLE . " SET user_lastmark = $post_time WHERE user_id = {$user->data['user_id']} - AND mark_time < $post_time"; + AND user_lastmark < $post_time"; $db->sql_query($sql); } else if ($config['load_anon_lastread'] || $user->data['is_registered']) @@ -1335,7 +1335,7 @@ function markread($mode, $forum_id = false, $topic_id = false, $post_time = 0, $ $sql = 'UPDATE ' . USERS_TABLE . " SET user_lastmark = $post_time WHERE user_id = {$user->data['user_id']} - AND mark_time < $post_time"; + AND user_lastmark < $post_time"; $db->sql_query($sql); } } diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index e9c7143473..39ec8445c5 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -54,7 +54,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod // Handle marking everything read if ($mark_read == 'all') { - $redirect = build_url(array('mark', 'hash')); + $redirect = build_url(array('mark', 'hash', 'mark_time')); meta_refresh(3, $redirect); if (check_link_hash(request_var('hash', ''), 'global')) @@ -305,7 +305,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod // Handle marking posts if ($mark_read == 'forums') { - $redirect = build_url(array('mark', 'hash')); + $redirect = build_url(array('mark', 'hash', 'mark_time')); $token = request_var('hash', ''); if (check_link_hash($token, 'global')) { From c93b3827dc0644ea4aece1af661224aaa68a4cae Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 6 Sep 2012 18:27:49 -0500 Subject: [PATCH 266/645] [ticket/11092] phpbb_gen_download_links strict standards errors Two strict standards errors in phpbb_gen_download_links PHPBB3-11092 --- phpBB/includes/functions_compress.php | 4 +++- phpBB/includes/functions_display.php | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_compress.php b/phpBB/includes/functions_compress.php index 8e07e6d1b8..4675394633 100644 --- a/phpBB/includes/functions_compress.php +++ b/phpBB/includes/functions_compress.php @@ -159,8 +159,10 @@ class compress /** * Return available methods + * + * @return array Array of strings of available compression methods (.tar, .tar.gz, .zip, etc.) */ - function methods() + public static function methods() { $methods = array('.tar'); $available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index 881c95907b..8328b9ee7a 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1410,7 +1410,8 @@ function phpbb_gen_download_links($param_key, $param_val, $phpbb_root_path, $php foreach ($methods as $method) { - $type = array_pop(explode('.', $method)); + $exploded = explode('.', $method); + $type = array_pop($exploded); $params = array('archive' => $method); $params[$param_key] = $param_val; From 552233d8fd27ca09fbed555582a9880771205929 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 01:03:38 +0200 Subject: [PATCH 267/645] [ticket/11100] Mark can_use_ssl() and can_use_tls() as static. PHPBB3-11100 --- phpBB/includes/functions_jabber.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_jabber.php b/phpBB/includes/functions_jabber.php index d76309d5bb..3d8e403f4b 100644 --- a/phpBB/includes/functions_jabber.php +++ b/phpBB/includes/functions_jabber.php @@ -68,7 +68,7 @@ class jabber } $this->password = $password; - $this->use_ssl = ($use_ssl && $this->can_use_ssl()) ? true : false; + $this->use_ssl = ($use_ssl && self::can_use_ssl()) ? true : false; // Change port if we use SSL if ($this->port == 5222 && $this->use_ssl) @@ -83,7 +83,7 @@ class jabber /** * Able to use the SSL functionality? */ - function can_use_ssl() + static public function can_use_ssl() { // Will not work with PHP >= 5.2.1 or < 5.2.3RC2 until timeout problem with ssl hasn't been fixed (http://bugs.php.net/41236) return ((version_compare(PHP_VERSION, '5.2.1', '<') || version_compare(PHP_VERSION, '5.2.3RC2', '>=')) && @extension_loaded('openssl')) ? true : false; @@ -92,7 +92,7 @@ class jabber /** * Able to use TLS? */ - function can_use_tls() + static public function can_use_tls() { if (!@extension_loaded('openssl') || !function_exists('stream_socket_enable_crypto') || !function_exists('stream_get_meta_data') || !function_exists('socket_set_blocking') || !function_exists('stream_get_wrappers')) { @@ -442,7 +442,7 @@ class jabber } // Let's use TLS if SSL is not enabled and we can actually use it - if (!$this->session['ssl'] && $this->can_use_tls() && $this->can_use_ssl() && isset($xml['stream:features'][0]['#']['starttls'])) + if (!$this->session['ssl'] && self::can_use_tls() && self::can_use_ssl() && isset($xml['stream:features'][0]['#']['starttls'])) { $this->add_to_log('Switching to TLS.'); $this->send("\n"); From 06c3868c27c394747bbaa5a8dac6ed83b5d61951 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 13:40:28 +0200 Subject: [PATCH 268/645] [ticket/8713] Adjust test method name to other recursive_set_var() tests. PHPBB3-8713 --- tests/request/type_cast_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index f7e5cd873e..94b6e9146f 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -49,7 +49,7 @@ class phpbb_type_cast_helper_test extends phpbb_test_case $this->assertEquals($expected, $data); } - public function test_untrimmed_strings() + public function test_nested_untrimmed_recursive_set_var() { $data = array(' eviL<3 '); $expected = array(' eviL<3 '); From 2c41b9062a6a8335aa1bfa7c80077f4ae33d33e4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 13:41:51 +0200 Subject: [PATCH 269/645] [ticket/8713] Use correct parameter for nested data. PHPBB3-8713 --- tests/request/type_cast_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index 94b6e9146f..176638dc44 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -54,7 +54,7 @@ class phpbb_type_cast_helper_test extends phpbb_test_case $data = array(' eviL<3 '); $expected = array(' eviL<3 '); - $this->type_cast_helper->recursive_set_var($data, '', true, false); + $this->type_cast_helper->recursive_set_var($data, array(0 => ''), true, false); $this->assertEquals($expected, $data); } From 4550fff55a10be737b76275ae5323675ab1c3939 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 13:43:14 +0200 Subject: [PATCH 270/645] [ticket/8713] Use \t in double quotes instead of tabs. PHPBB3-8713 --- tests/request/type_cast_helper_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index 176638dc44..8203703639 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -51,8 +51,8 @@ class phpbb_type_cast_helper_test extends phpbb_test_case public function test_nested_untrimmed_recursive_set_var() { - $data = array(' eviL<3 '); - $expected = array(' eviL<3 '); + $data = array(" eviL<3\t\t"); + $expected = array(" eviL<3\t\t"); $this->type_cast_helper->recursive_set_var($data, array(0 => ''), true, false); From 160c49351b5ce7d2d811a388a4630ec37258bb8f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 13:44:50 +0200 Subject: [PATCH 271/645] [ticket/8713] Add simple (non-nested) test case for untrimmed set_var(). PHPBB3-8713 --- tests/request/type_cast_helper_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php index 8203703639..f41db005af 100644 --- a/tests/request/type_cast_helper_test.php +++ b/tests/request/type_cast_helper_test.php @@ -49,6 +49,16 @@ class phpbb_type_cast_helper_test extends phpbb_test_case $this->assertEquals($expected, $data); } + public function test_simple_untrimmed_recursive_set_var() + { + $data = " eviL<3\t\t"; + $expected = " eviL<3\t\t"; + + $this->type_cast_helper->recursive_set_var($data, '', true, false); + + $this->assertEquals($expected, $data); + } + public function test_nested_untrimmed_recursive_set_var() { $data = array(" eviL<3\t\t"); From 798033075ba0bbef8f43c542ca05aae776747917 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 14:07:06 +0200 Subject: [PATCH 272/645] [ticket/8713] Always trim array keys. PHPBB3-8713 --- phpBB/includes/request/type_cast_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/request/type_cast_helper.php b/phpBB/includes/request/type_cast_helper.php index d3b94aac5a..3039647bfa 100644 --- a/phpBB/includes/request/type_cast_helper.php +++ b/phpBB/includes/request/type_cast_helper.php @@ -184,7 +184,7 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i foreach ($_var as $k => $v) { - $this->set_var($k, $k, $key_type, $multibyte, $trim); + $this->set_var($k, $k, $key_type, $multibyte); $this->recursive_set_var($v, $default_value, $multibyte, $trim); $var[$k] = $v; From c3e0d1b6d12f07df88e31ffd896b275e65b788eb Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 14:07:42 +0200 Subject: [PATCH 273/645] [ticket/8713] Fix type_cast_helper.php doc blocks: Add punctuation etc. PHPBB3-8713 --- phpBB/includes/request/type_cast_helper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/request/type_cast_helper.php b/phpBB/includes/request/type_cast_helper.php index 3039647bfa..1a5274ed14 100644 --- a/phpBB/includes/request/type_cast_helper.php +++ b/phpBB/includes/request/type_cast_helper.php @@ -93,8 +93,8 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i * @param mixed $type The variable type. Will be used with {@link settype()} * @param bool $multibyte Indicates whether string values may contain UTF-8 characters. * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks. - * @param bool $trim Indicates whether string values will be be parsed with trim() - * Default is true + * @param bool $trim Indicates whether trim() should be applied to string values. + * Default is true. */ public function set_var(&$result, $var, $type, $multibyte = false, $trim = true) { @@ -149,8 +149,8 @@ class phpbb_request_type_cast_helper implements phpbb_request_type_cast_helper_i * @param bool $multibyte Indicates whether string keys and values may contain UTF-8 characters. * Default is false, causing all bytes outside the ASCII range (0-127) to * be replaced with question marks. - * @param bool $trim Indicates whether string values will be be parsed with trim() - * Default is true + * @param bool $trim Indicates whether trim() should be applied to string values. + * Default is true. */ public function recursive_set_var(&$var, $default, $multibyte, $trim = true) { From b62c37c5799d4b9e018358c38a731d6664acadf1 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 14:09:12 +0200 Subject: [PATCH 274/645] [ticket/8713] DRY: variable() and untrimed_variable() into a protected method. PHPBB3-8713 --- phpBB/includes/request/request.php | 144 +++++++++++++---------------- 1 file changed, 64 insertions(+), 80 deletions(-) diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php index 747ca09624..c6b6610af5 100644 --- a/phpBB/includes/request/request.php +++ b/phpBB/includes/request/request.php @@ -200,46 +200,7 @@ class phpbb_request implements phpbb_request_interface */ public function variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST) { - $path = false; - - // deep direct access to multi dimensional arrays - if (is_array($var_name)) - { - $path = $var_name; - // make sure at least the variable name is specified - if (empty($path)) - { - return (is_array($default)) ? array() : $default; - } - // the variable name is the first element on the path - $var_name = array_shift($path); - } - - if (!isset($this->input[$super_global][$var_name])) - { - return (is_array($default)) ? array() : $default; - } - $var = $this->input[$super_global][$var_name]; - - if ($path) - { - // walk through the array structure and find the element we are looking for - foreach ($path as $key) - { - if (is_array($var) && isset($var[$key])) - { - $var = $var[$key]; - } - else - { - return (is_array($default)) ? array() : $default; - } - } - } - - $this->type_cast_helper->recursive_set_var($var, $default, $multibyte); - - return $var; + return $this->_variable($var_name, $default, $multibyte, $super_global, true); } /** @@ -263,46 +224,7 @@ class phpbb_request implements phpbb_request_interface */ public function untrimed_variable($var_name, $default, $multibyte, $super_global = phpbb_request_interface::REQUEST) { - $path = false; - - // deep direct access to multi dimensional arrays - if (is_array($var_name)) - { - $path = $var_name; - // make sure at least the variable name is specified - if (empty($path)) - { - return (is_array($default)) ? array() : $default; - } - // the variable name is the first element on the path - $var_name = array_shift($path); - } - - if (!isset($this->input[$super_global][$var_name])) - { - return (is_array($default)) ? array() : $default; - } - $var = $this->input[$super_global][$var_name]; - - if ($path) - { - // walk through the array structure and find the element we are looking for - foreach ($path as $key) - { - if (is_array($var) && isset($var[$key])) - { - $var = $var[$key]; - } - else - { - return (is_array($default)) ? array() : $default; - } - } - } - - $this->type_cast_helper->recursive_set_var($var, $default, $multibyte, false); - - return $var; + return $this->_variable($var_name, $default, $multibyte, $super_global, false); } /** @@ -414,4 +336,66 @@ class phpbb_request implements phpbb_request_interface return array_keys($this->input[$super_global]); } + + /** + * Helper function used by variable() and untrimed_variable(). + * + * @param string|array $var_name The form variable's name from which data shall be retrieved. + * If the value is an array this may be an array of indizes which will give + * direct access to a value at any depth. E.g. if the value of "var" is array(1 => "a") + * then specifying array("var", 1) as the name will return "a". + * @param mixed $default A default value that is returned if the variable was not set. + * This function will always return a value of the same type as the default. + * @param bool $multibyte If $default is a string this paramater has to be true if the variable may contain any UTF-8 characters + * Default is false, causing all bytes outside the ASCII range (0-127) to be replaced with question marks + * @param phpbb_request_interface::POST|GET|REQUEST|COOKIE $super_global + * Specifies which super global should be used + * @param bool $trim Indicates whether trim() should be applied to string values. + * + * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the + * the same as that of $default. If the variable is not set $default is returned. + */ + protected function _variable($var_name, $default, $multibyte = false, $super_global = phpbb_request_interface::REQUEST, $trim = true) + { + $path = false; + + // deep direct access to multi dimensional arrays + if (is_array($var_name)) + { + $path = $var_name; + // make sure at least the variable name is specified + if (empty($path)) + { + return (is_array($default)) ? array() : $default; + } + // the variable name is the first element on the path + $var_name = array_shift($path); + } + + if (!isset($this->input[$super_global][$var_name])) + { + return (is_array($default)) ? array() : $default; + } + $var = $this->input[$super_global][$var_name]; + + if ($path) + { + // walk through the array structure and find the element we are looking for + foreach ($path as $key) + { + if (is_array($var) && isset($var[$key])) + { + $var = $var[$key]; + } + else + { + return (is_array($default)) ? array() : $default; + } + } + } + + $this->type_cast_helper->recursive_set_var($var, $default, $multibyte, $trim); + + return $var; + } } From f2607fc9e80c6f9ad7543b7be5ea6f294aa6c40a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 14:15:56 +0200 Subject: [PATCH 275/645] [ticket/8713] Rename untrimed_variable() to untrimmed_variable(). PHPBB3-8713 --- phpBB/includes/acp/acp_language.php | 6 +++--- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/functions.php | 4 ++-- phpBB/includes/request/request.php | 4 ++-- phpBB/includes/ucp/ucp_profile.php | 6 +++--- phpBB/includes/ucp/ucp_register.php | 4 ++-- phpBB/install/install_update.php | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index 87cf605d8e..b5f5ba2312 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -100,11 +100,11 @@ class acp_language switch ($method) { case 'ftp': - $transfer = new ftp(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new ftp(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); break; case 'ftp_fsock': - $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); break; default: @@ -404,7 +404,7 @@ class acp_language trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR); } - $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); if (($result = $transfer->open_session()) !== true) { diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index b9958ed0f1..2905b84d57 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -770,8 +770,8 @@ class acp_users 'username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)), 'user_founder' => request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0), 'email' => strtolower(request_var('user_email', $user_row['user_email'])), - 'new_password' => $request->untrimed_variable('new_password', '', true), - 'password_confirm' => $request->untrimed_variable('password_confirm', '', true), + 'new_password' => $request->untrimmed_variable('new_password', '', true), + 'password_confirm' => $request->untrimmed_variable('password_confirm', '', true), ); // Validation data - we do not check the password complexity setting here diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 1cdda60855..a2f8a57938 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3044,11 +3044,11 @@ function login_box($redirect = '', $l_explain = '', $l_success = '', $admin = fa trigger_error('NO_AUTH_ADMIN'); } - $password = $request->untrimed_variable('password_' . $credential, '', true); + $password = $request->untrimmed_variable('password_' . $credential, '', true); } else { - $password = $request->untrimed_variable('password', '', true); + $password = $request->untrimmed_variable('password', '', true); } $username = request_var('username', '', true); diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php index c6b6610af5..aa62c3b610 100644 --- a/phpBB/includes/request/request.php +++ b/phpBB/includes/request/request.php @@ -222,7 +222,7 @@ class phpbb_request implements phpbb_request_interface * @return mixed The value of $_REQUEST[$var_name] run through {@link set_var set_var} to ensure that the type is the * the same as that of $default. If the variable is not set $default is returned. */ - public function untrimed_variable($var_name, $default, $multibyte, $super_global = phpbb_request_interface::REQUEST) + public function untrimmed_variable($var_name, $default, $multibyte, $super_global = phpbb_request_interface::REQUEST) { return $this->_variable($var_name, $default, $multibyte, $super_global, false); } @@ -338,7 +338,7 @@ class phpbb_request implements phpbb_request_interface } /** - * Helper function used by variable() and untrimed_variable(). + * Helper function used by variable() and untrimmed_variable(). * * @param string|array $var_name The form variable's name from which data shall be retrieved. * If the value is an array this may be an array of indizes which will give diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 68d5dd5d65..db1e3e4722 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -46,9 +46,9 @@ class ucp_profile $data = array( 'username' => utf8_normalize_nfc(request_var('username', $user->data['username'], true)), 'email' => strtolower(request_var('email', $user->data['user_email'])), - 'new_password' => $request->untrimed_variable('new_password', '', true), - 'cur_password' => $request->untrimed_variable('cur_password', '', true), - 'password_confirm' => $request->untrimed_variable('password_confirm', '', true), + 'new_password' => $request->untrimmed_variable('new_password', '', true), + 'cur_password' => $request->untrimmed_variable('cur_password', '', true), + 'password_confirm' => $request->untrimmed_variable('password_confirm', '', true), ); add_form_key('ucp_reg_details'); diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 6fab189a99..5ae92a5cea 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -170,8 +170,8 @@ class ucp_register $data = array( 'username' => utf8_normalize_nfc(request_var('username', '', true)), - 'new_password' => $request->untrimed_variable('new_password', '', true), - 'password_confirm' => $request->untrimed_variable('password_confirm', '', true), + 'new_password' => $request->untrimmed_variable('new_password', '', true), + 'password_confirm' => $request->untrimmed_variable('password_confirm', '', true), 'email' => strtolower(request_var('email', '')), 'lang' => basename(request_var('lang', $user->lang_name)), 'tz' => request_var('tz', $timezone), diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 4b5a23e497..1ecedecce6 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -862,7 +862,7 @@ class install_update extends module $test_connection = false; if ($test_ftp_connection || $submit) { - $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $test_connection = $transfer->open_session(); // Make sure that the directory is correct by checking for the existence of common.php @@ -948,7 +948,7 @@ class install_update extends module } else { - $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); $transfer->open_session(); } From d543f0ffb1334d0a22c30077a9ed27c098dc4af5 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 8 Sep 2012 14:41:41 +0200 Subject: [PATCH 276/645] [ticket/11101] Delay execution of container processors Also fix the name of the ext processor service. PHPBB3-11101 --- phpBB/common.php | 14 +++++++------- phpBB/config/services.yml | 2 +- phpBB/download/file.php | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index 281eb88c4d..c6bb5c6cfe 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -100,13 +100,6 @@ $processor->process($phpbb_container); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); -$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); -foreach ($ids as $id) -{ - $processor = $phpbb_container->get($id); - $processor->process($phpbb_container); -} - // set up caching $cache = $phpbb_container->get('cache'); @@ -132,6 +125,13 @@ $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); $template = $phpbb_container->get('template'); $phpbb_style = $phpbb_container->get('style'); +$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); +foreach ($ids as $id) +{ + $processor = $phpbb_container->get($id); + $processor->process($phpbb_container); +} + // Add own hook handler require($phpbb_root_path . 'includes/hooks/index.' . $phpEx); $phpbb_hook = new phpbb_hook(array('exit_handler', 'phpbb_user_session_handler', 'append_sid', array('phpbb_template', 'display'))); diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 133a43b77e..c3d2494952 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -89,7 +89,7 @@ services: - .%core.php_ext% - @cache.driver - processor.config: + processor.ext: class: phpbb_di_processor_ext arguments: - @ext.manager diff --git a/phpBB/download/file.php b/phpBB/download/file.php index 8766c6d030..7ed53d54b6 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -61,13 +61,6 @@ if (isset($_GET['avatar'])) $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); - $ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); - foreach ($ids as $id) - { - $processor = $phpbb_container->get($id); - $processor->process($phpbb_container); - } - // set up caching $cache = $phpbb_container->get('cache'); @@ -92,6 +85,13 @@ if (isset($_GET['avatar'])) $phpbb_extension_manager = $phpbb_container->get('ext.manager'); $phpbb_subscriber_loader = $phpbb_container->get('event.subscriber_loader'); + $ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); + foreach ($ids as $id) + { + $processor = $phpbb_container->get($id); + $processor->process($phpbb_container); + } + // worst-case default $browser = strtolower($request->header('User-Agent', 'msie 6.0')); From cc0c378caf9bfc480391a9d11d5a4d78c0df097c Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 14:40:35 +0200 Subject: [PATCH 277/645] [ticket/8713] Call htmlspecialchars_decode() on transfer (e.g. ftp) passwords. PHPBB3-8713 --- phpBB/includes/acp/acp_language.php | 27 ++++++++++++++++++++++++--- phpBB/install/install_update.php | 18 ++++++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/acp/acp_language.php b/phpBB/includes/acp/acp_language.php index b5f5ba2312..2be1ccfc41 100644 --- a/phpBB/includes/acp/acp_language.php +++ b/phpBB/includes/acp/acp_language.php @@ -100,11 +100,25 @@ class acp_language switch ($method) { case 'ftp': - $transfer = new ftp(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new ftp( + request_var('host', ''), + request_var('username', ''), + htmlspecialchars_decode($request->untrimmed_variable('password', '')), + request_var('root_path', ''), + request_var('port', ''), + request_var('timeout', '') + ); break; case 'ftp_fsock': - $transfer = new ftp_fsock(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new ftp_fsock( + request_var('host', ''), + request_var('username', ''), + htmlspecialchars_decode($request->untrimmed_variable('password', '')), + request_var('root_path', ''), + request_var('port', ''), + request_var('timeout', '') + ); break; default: @@ -404,7 +418,14 @@ class acp_language trigger_error($user->lang['INVALID_UPLOAD_METHOD'], E_USER_ERROR); } - $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new $method( + request_var('host', ''), + request_var('username', ''), + htmlspecialchars_decode($request->untrimmed_variable('password', '')), + request_var('root_path', ''), + request_var('port', ''), + request_var('timeout', '') + ); if (($result = $transfer->open_session()) !== true) { diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 1ecedecce6..8c044550f3 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -862,7 +862,14 @@ class install_update extends module $test_connection = false; if ($test_ftp_connection || $submit) { - $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new $method( + request_var('host', ''), + request_var('username', ''), + htmlspecialchars_decode($request->untrimmed_variable('password', '')), + request_var('root_path', ''), + request_var('port', ''), + request_var('timeout', '') + ); $test_connection = $transfer->open_session(); // Make sure that the directory is correct by checking for the existence of common.php @@ -948,7 +955,14 @@ class install_update extends module } else { - $transfer = new $method(request_var('host', ''), request_var('username', ''), $request->untrimmed_variable('password', ''), request_var('root_path', ''), request_var('port', ''), request_var('timeout', '')); + $transfer = new $method( + request_var('host', ''), + request_var('username', ''), + htmlspecialchars_decode($request->untrimmed_variable('password', '')), + request_var('root_path', ''), + request_var('port', ''), + request_var('timeout', '') + ); $transfer->open_session(); } From 1e05fd4c627d23b7756796c5acac27d2562a8607 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 15:01:29 +0200 Subject: [PATCH 278/645] [ticket/8713] Trim password in auth_db to keep compatibility. PHPBB3-8713 --- phpBB/includes/auth/auth_db.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/auth/auth_db.php b/phpBB/includes/auth/auth_db.php index 76790e4dad..ac944532a5 100644 --- a/phpBB/includes/auth/auth_db.php +++ b/phpBB/includes/auth/auth_db.php @@ -41,6 +41,10 @@ function login_db($username, $password, $ip = '', $browser = '', $forwarded_for global $db, $config; global $request; + // Auth plugins get the password untrimmed. + // For compatibility we trim() here. + $password = trim($password); + // do not allow empty password if (!$password) { From 73a75fc3d387f8d923186c5c04b1ca7bc6cda4ef Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 8 Sep 2012 15:02:06 +0200 Subject: [PATCH 279/645] [ticket/8713] Revert changes to ucp_profile, ucp_register and acp_users. Currently only auth_db is supported there and the password needs to be trimmed for compatibility because user_password stores phpbb_hash(htmlspecialchars(trim($password))) Setting passwords for other auth modules is currently not supported. Once setting/changing passwords is supported by auth plugins, the untrimmed_variable() should be used here and the result should be passed to the auth plugin. PHPBB3-8713 --- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/ucp/ucp_profile.php | 6 +++--- phpBB/includes/ucp/ucp_register.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 2905b84d57..985a12d9ce 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -770,8 +770,8 @@ class acp_users 'username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)), 'user_founder' => request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0), 'email' => strtolower(request_var('user_email', $user_row['user_email'])), - 'new_password' => $request->untrimmed_variable('new_password', '', true), - 'password_confirm' => $request->untrimmed_variable('password_confirm', '', true), + 'new_password' => $request->variable('new_password', '', true), + 'password_confirm' => $request->variable('password_confirm', '', true), ); // Validation data - we do not check the password complexity setting here diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index db1e3e4722..89bf20a30f 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -46,9 +46,9 @@ class ucp_profile $data = array( 'username' => utf8_normalize_nfc(request_var('username', $user->data['username'], true)), 'email' => strtolower(request_var('email', $user->data['user_email'])), - 'new_password' => $request->untrimmed_variable('new_password', '', true), - 'cur_password' => $request->untrimmed_variable('cur_password', '', true), - 'password_confirm' => $request->untrimmed_variable('password_confirm', '', true), + 'new_password' => $request->variable('new_password', '', true), + 'cur_password' => $request->variable('cur_password', '', true), + 'password_confirm' => $request->variable('password_confirm', '', true), ); add_form_key('ucp_reg_details'); diff --git a/phpBB/includes/ucp/ucp_register.php b/phpBB/includes/ucp/ucp_register.php index 5ae92a5cea..c57aec00a0 100644 --- a/phpBB/includes/ucp/ucp_register.php +++ b/phpBB/includes/ucp/ucp_register.php @@ -170,8 +170,8 @@ class ucp_register $data = array( 'username' => utf8_normalize_nfc(request_var('username', '', true)), - 'new_password' => $request->untrimmed_variable('new_password', '', true), - 'password_confirm' => $request->untrimmed_variable('password_confirm', '', true), + 'new_password' => $request->variable('new_password', '', true), + 'password_confirm' => $request->variable('password_confirm', '', true), 'email' => strtolower(request_var('email', '')), 'lang' => basename(request_var('lang', $user->lang_name)), 'tz' => request_var('tz', $timezone), From 238fab3bb908013fb0d7c95278b0a2a3b7fa5bae Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 9 Sep 2012 21:41:29 +0200 Subject: [PATCH 280/645] [ticket/8713] Update untrimmed_variable() doc block. PHPBB3-8713 --- phpBB/includes/request/request.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php index aa62c3b610..a06fc0d85d 100644 --- a/phpBB/includes/request/request.php +++ b/phpBB/includes/request/request.php @@ -204,9 +204,9 @@ class phpbb_request implements phpbb_request_interface } /** - * Get a variable, but without trimming strings - * Same functionality as variable(), except does not run trim() on strings - * All variables in GET or POST requests should be retrieved through this function to maximise security. + * Get a variable, but without trimming strings. + * Same functionality as variable(), except does not run trim() on strings. + * This method should be used when handling passwords. * * @param string|array $var_name The form variable's name from which data shall be retrieved. * If the value is an array this may be an array of indizes which will give From ce7cffcf9ebb21bccf1fae4da41a924708429e94 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 11 Sep 2012 09:42:29 +0100 Subject: [PATCH 281/645] [ticket/11045] Removed file conflict tests for compress class PHPBB3-11045 --- tests/compress/compress_test.php | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/tests/compress/compress_test.php b/tests/compress/compress_test.php index ac8dd358d3..65094671e3 100644 --- a/tests/compress/compress_test.php +++ b/tests/compress/compress_test.php @@ -25,12 +25,6 @@ class phpbb_compress_test extends phpbb_test_case 'dir/subdir/4.txt', ); - protected $conflicts = array( - '1_1.txt', - '1_2.txt', - 'dir/2_1.txt', - ); - protected function setUp() { // Required for compress::add_file @@ -88,11 +82,6 @@ class phpbb_compress_test extends phpbb_test_case ); $compress->add_custom_file($this->path . 'dir/3.txt', 'dir/3.txt'); $compress->add_data(file_get_contents($this->path . 'dir/subdir/4.txt'), 'dir/subdir/4.txt'); - - // Add multiples of the same file to check conflicts are handled - $compress->add_file($this->path . '1.txt', $this->path); - $compress->add_file($this->path . '1.txt', $this->path); - $compress->add_file($this->path . 'dir/2.txt', $this->path); } protected function valid_extraction($extra = array()) @@ -152,7 +141,7 @@ class phpbb_compress_test extends phpbb_test_case $compress->mode = 'r'; $compress->open(); $compress->extract('tests/compress/' . self::EXTRACT_DIR); - $this->valid_extraction($this->conflicts); + $this->valid_extraction(); } /** @@ -168,6 +157,6 @@ class phpbb_compress_test extends phpbb_test_case $compress = new compress_zip('r', $zip); $compress->extract('tests/compress/' . self::EXTRACT_DIR); - $this->valid_extraction($this->conflicts); + $this->valid_extraction(); } } From 503989979a2e6a7fb9d64ed249b09a0bef2b2f95 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 13 Sep 2012 16:44:26 -0400 Subject: [PATCH 282/645] [ticket/11086] Fix database_update.php to use Dependency Injection Container PHPBB3-11086 --- phpBB/install/database_update.php | 45 ++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 0b470ced26..323ba0c876 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -7,6 +7,10 @@ * */ +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; + define('UPDATES_TO_VERSION', '3.1.0-dev'); // Enter any version to update from to test updates. The version within the db will not be updated. @@ -107,21 +111,38 @@ if (!defined('EXT_TABLE')) define('EXT_TABLE', $table_prefix . 'ext'); } -$phpbb_class_loader_ext = new phpbb_class_loader('phpbb_ext_', $phpbb_root_path . 'ext/', ".$phpEx"); -$phpbb_class_loader_ext->register(); -$phpbb_class_loader = new phpbb_class_loader('phpbb_', $phpbb_root_path . 'includes/', ".$phpEx"); -$phpbb_class_loader->register(); +$phpbb_container = new ContainerBuilder(); +$loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__.'/../config')); +$loader->load('services.yml'); + +// We must include the DI processor class files because the class loader +// is not yet set up +require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx); +require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx); + +$processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); +$processor->process($phpbb_container); + +// Setup class loader first +$phpbb_class_loader = $phpbb_container->get('class_loader'); +$phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); + +$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); +foreach ($ids as $id) +{ + $processor = $phpbb_container->get($id); + $processor->process($phpbb_container); +} // set up caching -$cache_factory = new phpbb_cache_factory($acm_type); -$cache = $cache_factory->get_service(); -$phpbb_class_loader_ext->set_cache($cache->get_driver()); -$phpbb_class_loader->set_cache($cache->get_driver()); +$cache = $phpbb_container->get('cache'); -$phpbb_dispatcher = new phpbb_event_dispatcher(); -$request = new phpbb_request(); -$user = new phpbb_user(); -$db = new $sql_db(); +// Instantiate some basic classes +$phpbb_dispatcher = $phpbb_container->get('dispatcher'); +$request = $phpbb_container->get('request'); +$user = $phpbb_container->get('user'); +$auth = $phpbb_container->get('auth'); +$db = $phpbb_container->get('dbal.conn'); // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function From 298fa894e7ea0807a295cd0ed55cabef8a27a3f3 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 13 Sep 2012 16:56:09 -0400 Subject: [PATCH 283/645] [ticket/11086] Move DI processing below $request definition As per PR #991 (ticket/11101). PHPBB3-11086 --- phpBB/install/database_update.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 323ba0c876..5fa6166913 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -119,7 +119,6 @@ $loader->load('services.yml'); // is not yet set up require($phpbb_root_path . 'includes/di/processor/interface.' . $phpEx); require($phpbb_root_path . 'includes/di/processor/config.' . $phpEx); - $processor = new phpbb_di_processor_config($phpbb_root_path . 'config.' . $phpEx, $phpbb_root_path, $phpEx); $processor->process($phpbb_container); @@ -127,13 +126,6 @@ $processor->process($phpbb_container); $phpbb_class_loader = $phpbb_container->get('class_loader'); $phpbb_class_loader_ext = $phpbb_container->get('class_loader.ext'); -$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); -foreach ($ids as $id) -{ - $processor = $phpbb_container->get($id); - $processor->process($phpbb_container); -} - // set up caching $cache = $phpbb_container->get('cache'); @@ -144,6 +136,13 @@ $user = $phpbb_container->get('user'); $auth = $phpbb_container->get('auth'); $db = $phpbb_container->get('dbal.conn'); +$ids = array_keys($phpbb_container->findTaggedServiceIds('container.processor')); +foreach ($ids as $id) +{ + $processor = $phpbb_container->get($id); + $processor->process($phpbb_container); +} + // make sure request_var uses this request instance request_var('', 0, false, false, $request); // "dependency injection" for a function From b24ee89cfc22fad322dcfc577d1c7d50bbd57809 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 11 Sep 2012 09:44:13 +0100 Subject: [PATCH 284/645] [ticket/11109] Re-add file conflict checks to compress class PHPBB3-11109 --- tests/compress/compress_test.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/compress/compress_test.php b/tests/compress/compress_test.php index 65094671e3..ac8dd358d3 100644 --- a/tests/compress/compress_test.php +++ b/tests/compress/compress_test.php @@ -25,6 +25,12 @@ class phpbb_compress_test extends phpbb_test_case 'dir/subdir/4.txt', ); + protected $conflicts = array( + '1_1.txt', + '1_2.txt', + 'dir/2_1.txt', + ); + protected function setUp() { // Required for compress::add_file @@ -82,6 +88,11 @@ class phpbb_compress_test extends phpbb_test_case ); $compress->add_custom_file($this->path . 'dir/3.txt', 'dir/3.txt'); $compress->add_data(file_get_contents($this->path . 'dir/subdir/4.txt'), 'dir/subdir/4.txt'); + + // Add multiples of the same file to check conflicts are handled + $compress->add_file($this->path . '1.txt', $this->path); + $compress->add_file($this->path . '1.txt', $this->path); + $compress->add_file($this->path . 'dir/2.txt', $this->path); } protected function valid_extraction($extra = array()) @@ -141,7 +152,7 @@ class phpbb_compress_test extends phpbb_test_case $compress->mode = 'r'; $compress->open(); $compress->extract('tests/compress/' . self::EXTRACT_DIR); - $this->valid_extraction(); + $this->valid_extraction($this->conflicts); } /** @@ -157,6 +168,6 @@ class phpbb_compress_test extends phpbb_test_case $compress = new compress_zip('r', $zip); $compress->extract('tests/compress/' . self::EXTRACT_DIR); - $this->valid_extraction(); + $this->valid_extraction($this->conflicts); } } From 0c56bd45eff15b0bff2672ed08b390d0248625d8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 13:15:08 -0500 Subject: [PATCH 285/645] [ticket/11021] Better language strings for site home url/text Correct the logo title to be {L_HOME} if {U_HOME} is used. Check if the Home text is instead of just equal to false when outputting it to the template PHPBB3-11021 --- phpBB/includes/functions.php | 2 +- phpBB/language/en/acp/board.php | 10 +++++----- phpBB/styles/prosilver/template/overall_header.html | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index a8d3c25052..91e2b1b794 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4935,7 +4935,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'L_LOGIN_LOGOUT' => $l_login_logout, 'L_INDEX' => $user->lang['FORUM_INDEX'], - 'L_HOME' => ($config['site_home_text']) ? $config['site_home_text'] : $user->lang['HOME'], + 'L_HOME' => (!empty($config['site_home_text'])) ? $config['site_home_text'] : $user->lang['HOME'], 'L_ONLINE_EXPLAIN' => $l_online_time, 'U_PRIVATEMSGS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox'), diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 6b043b887d..b80aec1f4a 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -45,14 +45,14 @@ $lang = array_merge($lang, array( 'DISABLE_BOARD' => 'Disable board', 'DISABLE_BOARD_EXPLAIN' => 'This will make the board unavailable to users. You can also enter a short (255 character) message to display if you wish.', 'DISPLAY_LAST_SUBJECT' => 'Display subject of last added post on forum list', - 'DISPLAY_LAST_SUBJECT_EXPLAIN' => 'The subject of the last added post will be displayed in the forum list with a hyperlink to the post. Subjects from password protected forums and forums in which user doesn’t have read access are not shown.', + 'DISPLAY_LAST_SUBJECT_EXPLAIN' => 'The subject of the last added post will be displayed in the forum list with a hyperlink to the post. Subjects from password protected forums and forums in which user doesn’t have read access are not shown.', 'OVERRIDE_STYLE' => 'Override user style', 'OVERRIDE_STYLE_EXPLAIN' => 'Replaces user’s style with the default.', 'SITE_DESC' => 'Site description', - 'SITE_HOME_TEXT' => 'Site home text', - 'SITE_HOME_TEXT_EXPLAIN' => 'Specify a Site Home Text to use your own instead of the default text in the breadcrumbs ’Home.’', - 'SITE_HOME_URL' => 'Site home URL', - 'SITE_HOME_URL_EXPLAIN' => 'If you specify a Site Home URL, a link to this page will be added to your board’s breadcrumbs and the site logo will also be linked to this address.', + 'SITE_HOME_TEXT' => 'Main website text', + 'SITE_HOME_TEXT_EXPLAIN' => 'This text will be displayed as a link to your website homepage in the board’s breadcrumbs. If not specified, it will default to ’Home’.', + 'SITE_HOME_URL' => 'Main website URL', + 'SITE_HOME_URL_EXPLAIN' => 'If specified, a link to this URL will be prepended to your board’s breadcrumbs. The board logo will also link to this URL.', 'SITE_NAME' => 'Site name', 'SYSTEM_TIMEZONE' => 'Guest timezone', 'SYSTEM_TIMEZONE_EXPLAIN' => 'Timezone to use for displaying times to users who are not logged in (guests, bots). Logged in users set their timezone during registration and can change it in their user control panel.', diff --git a/phpBB/styles/prosilver/template/overall_header.html b/phpBB/styles/prosilver/template/overall_header.html index 13907a6ae4..47a53c8f60 100644 --- a/phpBB/styles/prosilver/template/overall_header.html +++ b/phpBB/styles/prosilver/template/overall_header.html @@ -95,7 +95,7 @@
- +

{SITENAME}

{SITE_DESCRIPTION}

From 7a4701399412faedd725195f849c18c770a126cb Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Sep 2012 10:44:18 -0500 Subject: [PATCH 286/645] [ticket/11021] Use L_SITE_HOME instead of L_HOME Check site home url against !== '', not empty PHPBB3-11021 --- phpBB/includes/functions.php | 2 +- phpBB/styles/prosilver/template/overall_footer.html | 4 ++-- phpBB/styles/prosilver/template/overall_header.html | 4 ++-- phpBB/styles/subsilver2/template/breadcrumbs.html | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 91e2b1b794..0aa3aa016e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4935,7 +4935,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'L_LOGIN_LOGOUT' => $l_login_logout, 'L_INDEX' => $user->lang['FORUM_INDEX'], - 'L_HOME' => (!empty($config['site_home_text'])) ? $config['site_home_text'] : $user->lang['HOME'], + 'L_SITE_HOME' => ($config['site_home_text'] !== '') ? $config['site_home_text'] : $user->lang['HOME'], 'L_ONLINE_EXPLAIN' => $l_online_time, 'U_PRIVATEMSGS' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&folder=inbox'), diff --git a/phpBB/styles/prosilver/template/overall_footer.html b/phpBB/styles/prosilver/template/overall_footer.html index ed05bbe80f..30912b6637 100644 --- a/phpBB/styles/prosilver/template/overall_footer.html +++ b/phpBB/styles/prosilver/template/overall_footer.html @@ -4,9 +4,9 @@ diff --git a/phpBB/install/convertors/convert_phpbb20.php b/phpBB/install/convertors/convert_phpbb20.php index 7d6fed6164..960cc5b335 100644 --- a/phpBB/install/convertors/convert_phpbb20.php +++ b/phpBB/install/convertors/convert_phpbb20.php @@ -33,7 +33,7 @@ $convertor_data = array( 'forum_name' => 'phpBB 2.0.x', 'version' => '1.0.3', 'phpbb_version' => '3.0.11', - 'author' => 'phpBB Group', + 'author' => 'phpBB Group', 'dbms' => $dbms, 'dbhost' => $dbhost, 'dbport' => $dbport, diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 5a186d0eeb..40837145ba 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -527,7 +527,7 @@ function _print_footer()
diff --git a/phpBB/install/index.php b/phpBB/install/index.php index 5135e2dbd8..ad46e273c2 100644 --- a/phpBB/install/index.php +++ b/phpBB/install/index.php @@ -569,7 +569,7 @@ class module echo '
'; echo '
'; echo ' '; echo ''; echo ''; diff --git a/phpBB/styles/prosilver/template/ucp_pm_viewmessage_print.html b/phpBB/styles/prosilver/template/ucp_pm_viewmessage_print.html index d92abb06dd..67e14defc3 100644 --- a/phpBB/styles/prosilver/template/ucp_pm_viewmessage_print.html +++ b/phpBB/styles/prosilver/template/ucp_pm_viewmessage_print.html @@ -48,7 +48,7 @@ diff --git a/phpBB/styles/prosilver/template/viewtopic_print.html b/phpBB/styles/prosilver/template/viewtopic_print.html index 0fd0e6dfa6..39d2d76394 100644 --- a/phpBB/styles/prosilver/template/viewtopic_print.html +++ b/phpBB/styles/prosilver/template/viewtopic_print.html @@ -44,7 +44,7 @@ diff --git a/phpBB/styles/prosilver/theme/stylesheet.css b/phpBB/styles/prosilver/theme/stylesheet.css index 4a7356fbaa..40620179a1 100644 --- a/phpBB/styles/prosilver/theme/stylesheet.css +++ b/phpBB/styles/prosilver/theme/stylesheet.css @@ -3,7 +3,7 @@ Style name: prosilver (the default phpBB 3.0.x style) Based on style: Original author: Tom Beddard ( http://www.subblue.com/ ) - Modified by: phpBB Group ( http://www.phpbb.com/ ) + Modified by: phpBB Group ( https://www.phpbb.com/ ) -------------------------------------------------------------- */ diff --git a/phpBB/styles/subsilver2/template/ucp_pm_viewmessage_print.html b/phpBB/styles/subsilver2/template/ucp_pm_viewmessage_print.html index 24194e4c26..cd55c16a50 100644 --- a/phpBB/styles/subsilver2/template/ucp_pm_viewmessage_print.html +++ b/phpBB/styles/subsilver2/template/ucp_pm_viewmessage_print.html @@ -114,7 +114,7 @@ hr.sep { {S_TIMEZONE} - Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/
+ Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/
diff --git a/phpBB/styles/subsilver2/template/viewtopic_print.html b/phpBB/styles/subsilver2/template/viewtopic_print.html index 964c95f677..1ca1eccc99 100644 --- a/phpBB/styles/subsilver2/template/viewtopic_print.html +++ b/phpBB/styles/subsilver2/template/viewtopic_print.html @@ -128,7 +128,7 @@ hr.sep { {S_TIMEZONE} - Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/
+ Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/
diff --git a/phpBB/styles/subsilver2/theme/stylesheet.css b/phpBB/styles/subsilver2/theme/stylesheet.css index 444104ae3c..177a988e93 100644 --- a/phpBB/styles/subsilver2/theme/stylesheet.css +++ b/phpBB/styles/subsilver2/theme/stylesheet.css @@ -3,7 +3,7 @@ Style name: subsilver2 Based on style: subSilver (the default phpBB 2.0.x style) Original author: Tom Beddard ( http://www.subblue.com/ ) - Modified by: phpBB Group ( http://www.phpbb.com/ ) + Modified by: phpBB Group ( https://www.phpbb.com/ ) -------------------------------------------------------------- */ From 305abfde963e764d5e6be0c7b1c1b9496a2477b2 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 8 Oct 2012 10:58:04 +0530 Subject: [PATCH 297/645] [ticket/11051] fix spaces PHPBB3-11051 --- phpBB/includes/search/fulltext_native.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/search/fulltext_native.php b/phpBB/includes/search/fulltext_native.php index 1100484ebd..bbc2236b3c 100644 --- a/phpBB/includes/search/fulltext_native.php +++ b/phpBB/includes/search/fulltext_native.php @@ -23,9 +23,9 @@ if (!defined('IN_PHPBB')) class phpbb_search_fulltext_native extends phpbb_search_base { protected $stats = array(); - protected $word_length = array(); - protected $search_query; - protected $common_words = array(); + protected $word_length = array(); + protected $search_query; + protected $common_words = array(); protected $must_contain_ids = array(); protected $must_not_contain_ids = array(); From 5db30e66fd03dacb4bb961afd9672eb9d65ba148 Mon Sep 17 00:00:00 2001 From: Vinny Date: Tue, 9 Oct 2012 00:31:59 -0300 Subject: [PATCH 298/645] [ticket/11139] Fix fatal error on colour swatch window PHPBB3-11139 --- phpBB/adm/swatch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/adm/swatch.php b/phpBB/adm/swatch.php index 434b00e542..5e8984db70 100644 --- a/phpBB/adm/swatch.php +++ b/phpBB/adm/swatch.php @@ -22,7 +22,7 @@ $auth->acl($user->data); $user->setup(); // Set custom template for admin area -$template->set_custom_template($phpbb_root_path . 'adm/style', 'admin'); +$phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', ''); $template->set_filenames(array( 'body' => 'colour_swatch.html') From cf810fb775407d6e6e5aa62a072b141bdb61e3c9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 9 Oct 2012 22:00:28 -0500 Subject: [PATCH 299/645] [ticket/11140] Fix an error from an incorrect variable name PHPBB3-11140 --- phpBB/includes/mcp/mcp_front.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/mcp/mcp_front.php b/phpBB/includes/mcp/mcp_front.php index 13398e62bc..ba4b15895a 100644 --- a/phpBB/includes/mcp/mcp_front.php +++ b/phpBB/includes/mcp/mcp_front.php @@ -251,7 +251,7 @@ function mcp_front_view($id, $mode, $action) 'ORDER_BY' => 'p.message_time DESC', ); - $sql_ary = $db->sql_build_query('SELECT', $sql_ary); + $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query_limit($sql, 5); $pm_by_id = $pm_list = array(); From d434672dde1592f51013459357c25ed49887d12f Mon Sep 17 00:00:00 2001 From: Senky Date: Mon, 23 Jul 2012 14:28:47 +0200 Subject: [PATCH 300/645] [ticket/10967] adding $root_path to posting_get_topic_icons PHPBB3-10967 --- phpBB/includes/functions_posting.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php index 68b6199cf5..aa15593a19 100644 --- a/phpBB/includes/functions_posting.php +++ b/phpBB/includes/functions_posting.php @@ -288,13 +288,15 @@ function posting_gen_topic_icons($mode, $icon_id) if (sizeof($icons)) { + $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; + foreach ($icons as $id => $data) { if ($data['display']) { $template->assign_block_vars('topic_icon', array( 'ICON_ID' => $id, - 'ICON_IMG' => $phpbb_root_path . $config['icons_path'] . '/' . $data['img'], + 'ICON_IMG' => $root_path . $config['icons_path'] . '/' . $data['img'], 'ICON_WIDTH' => $data['width'], 'ICON_HEIGHT' => $data['height'], @@ -2637,7 +2639,7 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u * - 'topic_last_post_subject' * - 'topic_last_poster_name' * - 'topic_last_poster_colour' -* @param int $bump_time The time at which topic was bumped, usually it is a current time as obtained via time(). +* @param int $bump_time The time at which topic was bumped, usually it is a current time as obtained via time(). * @return string An URL to the bumped topic, example: ./viewtopic.php?forum_id=1&topic_id=2&p=3#p3 */ function phpbb_bump_topic($forum_id, $topic_id, $post_data, $bump_time = false) From 571d352eed670ad986bd653a2ac0bd81429c9cf5 Mon Sep 17 00:00:00 2001 From: Vinny Date: Tue, 9 Oct 2012 14:29:26 -0300 Subject: [PATCH 301/645] [ticket/11139] Adding the $phpbb_admin_path variable PHPBB3-11139 --- phpBB/adm/swatch.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/adm/swatch.php b/phpBB/adm/swatch.php index 5e8984db70..86498a255f 100644 --- a/phpBB/adm/swatch.php +++ b/phpBB/adm/swatch.php @@ -21,6 +21,8 @@ $user->session_begin(false); $auth->acl($user->data); $user->setup(); +$phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : './'; + // Set custom template for admin area $phpbb_style->set_custom_style('admin', $phpbb_admin_path . 'style', ''); From d376348acf271ab0e2bcba4e8eb5993192d0ef87 Mon Sep 17 00:00:00 2001 From: westr Date: Tue, 16 Oct 2012 12:44:33 +0100 Subject: [PATCH 302/645] [ticket/11093] acp_users_overview.html has a wrongly placed Amended the closing dd tag to the appropriate line: line 145 instead of 141 PHPBB3-11093 --- phpBB/adm/style/acp_users_overview.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/adm/style/acp_users_overview.html b/phpBB/adm/style/acp_users_overview.html index e2dcdb6307..ba350a13fb 100644 --- a/phpBB/adm/style/acp_users_overview.html +++ b/phpBB/adm/style/acp_users_overview.html @@ -142,10 +142,11 @@

{L_DELETE_USER_EXPLAIN}
-
+ {L_USER_NO_POSTS_TO_DELETE} +

From c630480ca1a426cb0897be35626baac2694fccf5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 17 Oct 2012 15:03:06 -0400 Subject: [PATCH 303/645] [ticket/10848] Redirect from adm to installer correctly. PHPBB3-10848 --- phpBB/common.php | 6 +++- phpBB/includes/functions.php | 30 ++++++++++++++++++++ tests/functions/clean_path_test.php | 44 +++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/functions/clean_path_test.php diff --git a/phpBB/common.php b/phpBB/common.php index 491addc5e0..bdb33707cc 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -38,10 +38,14 @@ if (!defined('PHPBB_INSTALLED')) $script_name = (!empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : getenv('REQUEST_URI'); } + // $phpbb_root_path accounts for redirects from e.g. /adm + $script_path = trim(dirname($script_name)) . '/' . $phpbb_root_path . 'install/index.' . $phpEx; // Replace any number of consecutive backslashes and/or slashes with a single slash // (could happen on some proxy setups and/or Windows servers) - $script_path = trim(dirname($script_name)) . '/install/index.' . $phpEx; $script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path); + // Eliminate . and .. from the path + require($phpbb_root_path . 'includes/functions.' . $phpEx); + $script_path = clean_path($script_path); $url = (($secure) ? 'https://' : 'http://') . $server_name; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index ca58220619..2391b45038 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1176,6 +1176,36 @@ else } } +/** +* Eliminates useless . and .. components from specified path. +* +* @param string $path Path to clean +* @return string Cleaned path +*/ +function clean_path($path) +{ + $exploded = explode('/', $path); + $filtered = array(); + foreach ($exploded as $part) + { + if ($part === '.' && !empty($filtered)) + { + continue; + } + + if ($part === '..' && !empty($filtered) && $filtered[sizeof($filtered) - 1] !== '..') + { + array_pop($filtered); + } + else + { + $filtered[] = $part; + } + } + $path = implode('/', $filtered); + return $path; +} + if (!function_exists('htmlspecialchars_decode')) { /** diff --git a/tests/functions/clean_path_test.php b/tests/functions/clean_path_test.php new file mode 100644 index 0000000000..4c8fe54909 --- /dev/null +++ b/tests/functions/clean_path_test.php @@ -0,0 +1,44 @@ +assertEquals($expected, $output); + } +} From bb09cd9c8e76ac3af848d09db8ea1928dab66158 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 17 Oct 2012 15:13:35 -0400 Subject: [PATCH 304/645] [ticket/10848] Add phpbb_ prefix. PHPBB3-10848 --- phpBB/common.php | 2 +- phpBB/includes/functions.php | 2 +- tests/functions/clean_path_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/common.php b/phpBB/common.php index bdb33707cc..5849d48453 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -45,7 +45,7 @@ if (!defined('PHPBB_INSTALLED')) $script_path = preg_replace('#[\\\\/]{2,}#', '/', $script_path); // Eliminate . and .. from the path require($phpbb_root_path . 'includes/functions.' . $phpEx); - $script_path = clean_path($script_path); + $script_path = phpbb_clean_path($script_path); $url = (($secure) ? 'https://' : 'http://') . $server_name; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 2391b45038..65d8be32ad 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1182,7 +1182,7 @@ else * @param string $path Path to clean * @return string Cleaned path */ -function clean_path($path) +function phpbb_clean_path($path) { $exploded = explode('/', $path); $filtered = array(); diff --git a/tests/functions/clean_path_test.php b/tests/functions/clean_path_test.php index 4c8fe54909..bcbe9838d9 100644 --- a/tests/functions/clean_path_test.php +++ b/tests/functions/clean_path_test.php @@ -37,7 +37,7 @@ class phpbb_clean_path_test extends phpbb_test_case */ public function test_clean_path($input, $expected) { - $output = clean_path($input); + $output = phpbb_clean_path($input); $this->assertEquals($expected, $output); } From e76fd6a3959c632a2e012ce82568b9e04f87b8db Mon Sep 17 00:00:00 2001 From: Drae Date: Sun, 22 Jul 2012 16:24:07 +0100 Subject: [PATCH 305/645] [ticket/11018] Attempt to fix li.pagination alignment issue This is somewhat kludgy fix for the vertical alignment issue for pagination contained within a linklist parented li element. Tested and doesn't seem to impact anything else negatively. May need further browser testing. PHPBB3-11018 --- phpBB/styles/prosilver/theme/common.css | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index 4b4fa263b1..ff46163f71 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -510,9 +510,16 @@ li.pagination { margin-bottom: 0; } +li.pagination ul { + margin-top: -2px; + vertical-align: middle; +} + .pagination ul li, dl .pagination ul li, dl.icon .pagination ul li { display: inline; padding: 0; + font-size: 100%; + line-height: normal; } .pagination li a, .pagnation li span, li .pagination li a, li .pagnation li span, .pagination li.active span, .pagination li.ellipsis span { From a51aa9b47c526d173386510f3f67303243be03fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 25 Aug 2012 13:09:22 +0200 Subject: [PATCH 306/645] [ticket/11018] Fix minor issues with CSS in prosilver PHPBB3-11018 --- phpBB/styles/prosilver/theme/colours.css | 6 +++--- phpBB/styles/prosilver/theme/common.css | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/styles/prosilver/theme/colours.css b/phpBB/styles/prosilver/theme/colours.css index 29968cbb14..d7ce9a7622 100644 --- a/phpBB/styles/prosilver/theme/colours.css +++ b/phpBB/styles/prosilver/theme/colours.css @@ -151,9 +151,9 @@ dl.details dd { border-color: #B4BAC0; } -.pagination li.ellipsis span { +.pagination li.ellipsis span { background-color: transparent; - color: #000 + color: #000000; } .pagination li.active span { @@ -165,7 +165,7 @@ dl.details dd { .pagination li a:hover, .pagination .active a:hover { border-color: #368AD2; background-color: #368AD2; - color: #FFF; + color: #FFFFFF; } .pagination li a:active, .pagination li.active a:active { diff --git a/phpBB/styles/prosilver/theme/common.css b/phpBB/styles/prosilver/theme/common.css index ff46163f71..50b22f44df 100644 --- a/phpBB/styles/prosilver/theme/common.css +++ b/phpBB/styles/prosilver/theme/common.css @@ -515,11 +515,11 @@ li.pagination ul { vertical-align: middle; } -.pagination ul li, dl .pagination ul li, dl.icon .pagination ul li { +.pagination ul li, dl .pagination ul li, dl.icon .pagination ul li { display: inline; padding: 0; font-size: 100%; - line-height: normal; + line-height: normal; } .pagination li a, .pagnation li span, li .pagination li a, li .pagnation li span, .pagination li.active span, .pagination li.ellipsis span { From 43a713ea8356221eb199c5aba066efa15013c186 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 25 Aug 2012 13:11:07 +0200 Subject: [PATCH 307/645] [ticket/11067] Copy prosilver CSS to adm, so the pagination looks the same PHPBB3-11067 PHPBB3-11018 --- phpBB/adm/style/admin.css | 100 +++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 38 deletions(-) diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index 585707600d..8551c952c7 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -1148,55 +1148,79 @@ input.disabled { width: auto; text-align: right; margin-top: 5px; - font-size: 0.85em; - padding-bottom: 2px; + float: right; } .rtl .pagination { text-align: left; + float: left; } -.pagination strong, -.pagination b { - font-weight: normal; -} - -.pagination span.page-sep { - display:none; -} - -.pagination span strong { - padding: 0 2px; - margin: 0 2px; - font-weight: normal; - font-size: 0.85em; - color: #FFFFFF; - background: #4692BF; - border: 1px solid #4692BF; -} - -.pagination span a, .pagination span a:link, .pagination span a:visited, .pagination span a:active { - font-weight: normal; - font-size: 0.85em; - text-decoration: none; - color: #5C758C; - margin: 0 2px; - padding: 0 2px; - background: #ECEDEE; - border: 1px solid #B4BAC0; -} - -.pagination span a:hover { - border-color: #368AD2; - background: #368AD2; - color: #FFFFFF; - text-decoration: none; +li.pagination { + margin-top: 0; } .pagination img { vertical-align: middle; } +.pagination ul { + display: inline-block; + *display: inline; /* IE7 inline-block hack */ + *zoom: 1; + margin-left: 0; + margin-bottom: 0; +} + +li.pagination ul { + margin-top: -2px; + vertical-align: middle; +} + +.pagination ul li, dl .pagination ul li, dl.icon .pagination ul li { + display: inline; + padding: 0; + font-size: 100%; + line-height: normal; +} + +.pagination li a, .pagnation li span, li .pagination li a, li .pagnation li span, .pagination li.active span, .pagination li.ellipsis span { + font-weight: normal; + text-decoration: none; + padding: 0 2px; + border: 1px solid transparent; + font-size: 0.9em; + line-height: 1.5em; +} + +.pagination li a, .pagination li a:link, .pagination li a:visited { + color: #5C758C; + background-color: #ECEDEE; + border-color: #B4BAC0; +} + +.pagination li.ellipsis span { + background-color: transparent; + color: #000000; +} + +.pagination li.active span { + color: #FFFFFF; + background-color: #4692BF; + border-color: #4692BF; +} + +.pagination li a:hover, .pagination .active a:hover { + color: #FFFFFF; + background-color: #368AD2; + border-color: #368AD2; +} + +.pagination li a:active, .pagination li.active a:active { + color: #5C758C; + background-color: #ECEDEE; + border-color: #B4BAC0; +} /* Action Highlighting ---------------------------------------- */ @@ -1727,4 +1751,4 @@ fieldset.permissions .padding { .requirements_not_met dt label, .requirements_not_met dd p { color: #FFFFFF; font-size: 1.4em; -} \ No newline at end of file +} From fa5753de707e0b24c686cf75a7ae9d261bc2a8f2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 25 Aug 2012 13:20:45 +0200 Subject: [PATCH 308/645] [ticket/11018] Swap prev/next links on pagination to the old order In the old pagination Prev was left of the pagination and Next right of the pagination. While moving these blocks, I also removed the whitespaces, which were introduced. PHPBB3-11023 PHPBB3-11018 --- phpBB/includes/functions.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 0c9421c12f..08dd03504c 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2112,14 +2112,14 @@ function phpbb_generate_template_pagination($template, $base_url, $block_var_nam $end_page = ($total_pages > 5) ? max(min($total_pages, $on_page + 3), 5) : $total_pages; } - if ($on_page != $total_pages) + if ($on_page != 1) { $template->assign_block_vars($block_var_name, array( 'PAGE_NUMBER' => '', - 'PAGE_URL' => $base_url . $url_delim . $start_name . '=' . ($on_page * $per_page), + 'PAGE_URL' => $base_url . $url_delim . $start_name . '=' . (($on_page - 2) * $per_page), 'S_IS_CURRENT' => false, - 'S_IS_PREV' => false, - 'S_IS_NEXT' => true, + 'S_IS_PREV' => true, + 'S_IS_NEXT' => false, 'S_IS_ELLIPSIS' => false, )); } @@ -2166,14 +2166,14 @@ function phpbb_generate_template_pagination($template, $base_url, $block_var_nam } while ($at_page <= $total_pages); - if ($on_page != 1) + if ($on_page != $total_pages) { $template->assign_block_vars($block_var_name, array( 'PAGE_NUMBER' => '', - 'PAGE_URL' => $base_url . $url_delim . $start_name . '=' . (($on_page - 2) * $per_page), + 'PAGE_URL' => $base_url . $url_delim . $start_name . '=' . ($on_page * $per_page), 'S_IS_CURRENT' => false, - 'S_IS_PREV' => true, - 'S_IS_NEXT' => false, + 'S_IS_PREV' => false, + 'S_IS_NEXT' => true, 'S_IS_ELLIPSIS' => false, )); } From 5ea662f649833f50483da544b513ca102e390fd8 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 25 Aug 2012 14:34:48 +0200 Subject: [PATCH 309/645] [ticket/11014] Restore template vars for next/previous links They were dropped while the function was refactored: If the block_var_name is a nested block, we will use the last (most inner) block as a prefix for the template variables. If the last block name is pagination, the prefix is empty. If the rest of the block_var_name is not empty, we will modify the last row of that block and add our pagination items. PHPBB3-11014 --- phpBB/includes/functions.php | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 08dd03504c..4e5be20dbf 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2177,6 +2177,45 @@ function phpbb_generate_template_pagination($template, $base_url, $block_var_nam 'S_IS_ELLIPSIS' => false, )); } + + // If the block_var_name is a nested block, we will use the last (most + // inner) block as a prefix for the template variables. If the last block + // name is pagination, the prefix is empty. If the rest of the + // block_var_name is not empty, we will modify the last row of that block + // and add our pagination items. + $tpl_block_name = $tpl_prefix = ''; + if (strrpos($block_var_name, '.') !== false) + { + $tpl_block_name = substr($block_var_name, 0, strrpos($block_var_name, '.')); + $tpl_prefix = strtoupper(substr($block_var_name, strrpos($block_var_name, '.') + 1)); + } + else + { + $tpl_prefix = strtoupper($block_var_name); + } + $tpl_prefix = ($tpl_prefix == 'PAGINATION') ? '' : $tpl_prefix . '_'; + + $previous_page = ($on_page != 1) ? $base_url . $url_delim . $start_name . '=' . (($on_page - 2) * $per_page) : ''; + + $template_array = array( + $tpl_prefix . 'BASE_URL' => $base_url, + 'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url), + $tpl_prefix . 'PER_PAGE' => $per_page, + $tpl_prefix . 'PREVIOUS_PAGE' => $previous_page, + $tpl_prefix . 'PREV_PAGE' => $previous_page, + $tpl_prefix . 'NEXT_PAGE' => ($on_page != $total_pages) ? $base_url . $url_delim . $start_name . '=' . ($on_page * $per_page) : '', + $tpl_prefix . 'TOTAL_PAGES' => $total_pages, + $tpl_prefix . 'CURRENT_PAGE' => $on_page, + ); + + if ($tpl_block_name) + { + $template->alter_block_array($tpl_block_name, $template_array, true, 'change'); + } + else + { + $template->assign_vars($template_array); + } } /** From ada2d4c91bb063f3d9d591bfc3ce9552957772e0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 25 Aug 2012 14:35:57 +0200 Subject: [PATCH 310/645] [ticket/11018] Always display previous/next links if we can display one PHPBB3-11018 --- phpBB/styles/prosilver/template/viewtopic_body.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html index 4534dc5bcc..01b6a504a2 100644 --- a/phpBB/styles/prosilver/template/viewtopic_body.html +++ b/phpBB/styles/prosilver/template/viewtopic_body.html @@ -245,7 +245,7 @@ - +

From ceb5a40eecbc60577ce0735254a4a189d719302e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 25 Aug 2012 14:53:21 +0200 Subject: [PATCH 311/645] [ticket/11023] Fix additional whitespaces that were added by PHPBB3-10968 PHPBB3-11023 --- phpBB/includes/acp/acp_attachments.php | 4 ++-- phpBB/includes/acp/acp_groups.php | 4 ++-- phpBB/includes/acp/acp_icons.php | 4 ++-- phpBB/includes/acp/acp_inactive.php | 5 ++--- phpBB/includes/acp/acp_logs.php | 2 +- phpBB/includes/acp/acp_users.php | 4 ++-- phpBB/includes/functions.php | 1 - phpBB/includes/mcp/mcp_forum.php | 2 +- phpBB/includes/mcp/mcp_logs.php | 4 ++-- phpBB/includes/mcp/mcp_notes.php | 2 +- phpBB/includes/mcp/mcp_pm_reports.php | 4 ++-- phpBB/includes/mcp/mcp_queue.php | 2 +- phpBB/includes/mcp/mcp_reports.php | 2 +- phpBB/includes/mcp/mcp_topic.php | 2 +- phpBB/includes/mcp/mcp_warn.php | 2 +- phpBB/includes/ucp/ucp_attachments.php | 4 ++-- phpBB/includes/ucp/ucp_pm_viewfolder.php | 2 +- phpBB/memberlist.php | 2 +- phpBB/search.php | 4 ++-- 19 files changed, 27 insertions(+), 29 deletions(-) diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php index eccc935a6e..9d6c2d5de1 100644 --- a/phpBB/includes/acp/acp_attachments.php +++ b/phpBB/includes/acp/acp_attachments.php @@ -1163,7 +1163,7 @@ class acp_attachments $template->assign_vars(array( 'S_ACTION_OPTIONS' => ($auth->acl_get('a_board')) ? true : false, 'U_ACTION' => $this->u_action,) - ); + ); } // Make sure $start is set to the last page if it exceeds the amount @@ -1224,7 +1224,7 @@ class acp_attachments $base_url = $this->u_action . "&$u_sort_param"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $num_files, $attachments_per_page, $start); - + $template->assign_vars(array( 'TOTAL_FILES' => $num_files, 'TOTAL_SIZE' => get_formatted_filesize($total_size), diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index f88fa76df1..9621407211 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -683,8 +683,8 @@ class acp_groups } $base_url = $this->u_action . "&action=$action&g=$group_id"; - phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total_members, $config['topics_per_page'], $start); - + phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total_members, $config['topics_per_page'], $start); + $template->assign_vars(array( 'S_LIST' => true, 'S_GROUP_SPECIAL' => ($group_row['group_type'] == GROUP_SPECIAL) ? true : false, diff --git a/phpBB/includes/acp/acp_icons.php b/phpBB/includes/acp/acp_icons.php index b7be92d477..db4b4263b0 100644 --- a/phpBB/includes/acp/acp_icons.php +++ b/phpBB/includes/acp/acp_icons.php @@ -927,8 +927,8 @@ class acp_icons } } $db->sql_freeresult($result); - - phpbb_generate_template_pagination($template, $this->u_action, 'pagination', 'start', $item_count, $config['smilies_per_page'], $pagination_start); + + phpbb_generate_template_pagination($template, $this->u_action, 'pagination', 'start', $item_count, $config['smilies_per_page'], $pagination_start); } /** diff --git a/phpBB/includes/acp/acp_inactive.php b/phpBB/includes/acp/acp_inactive.php index 1e23c2e6cf..bf7a9e11e4 100644 --- a/phpBB/includes/acp/acp_inactive.php +++ b/phpBB/includes/acp/acp_inactive.php @@ -289,8 +289,8 @@ class acp_inactive } $base_url = $this->u_action . "&$u_sort_param&users_per_page=$per_page"; - phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $inactive_count, $per_page, $start); - + phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $inactive_count, $per_page, $start); + $template->assign_vars(array( 'S_INACTIVE_USERS' => true, 'S_INACTIVE_OPTIONS' => build_select($option_ary), @@ -299,7 +299,6 @@ class acp_inactive 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $inactive_count, $per_page, $start), - 'USERS_PER_PAGE' => $per_page, 'U_ACTION' => $this->u_action . "&$u_sort_param&users_per_page=$per_page&start=$start", diff --git a/phpBB/includes/acp/acp_logs.php b/phpBB/includes/acp/acp_logs.php index 4538633d6c..d86521532c 100644 --- a/phpBB/includes/acp/acp_logs.php +++ b/phpBB/includes/acp/acp_logs.php @@ -131,7 +131,7 @@ class acp_logs $base_url = $this->u_action . "&$u_sort_param$keywords_param"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start); - + $template->assign_vars(array( 'L_TITLE' => $l_title, 'L_EXPLAIN' => $l_title_explain, diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 985a12d9ce..82d8ef5cbb 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1159,7 +1159,7 @@ class acp_users $base_url = $this->u_action . "&u=$user_id&$u_sort_param"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start); - + $template->assign_vars(array( 'S_FEEDBACK' => true, 'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $log_count, $config['topics_per_page'], $start), @@ -2075,7 +2075,7 @@ class acp_users $base_url = $this->u_action . "&u=$user_id&sk=$sort_key&sd=$sort_dir"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start); - + $template->assign_vars(array( 'S_ATTACHMENTS' => true, 'S_ON_PAGE' => phpbb_on_page($template, $user, $base_url, $num_attachments, $config['topics_per_page'], $start), diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4e5be20dbf..2e42dfe94e 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2240,7 +2240,6 @@ function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $star $template->assign_vars(array( 'PER_PAGE' => $per_page, 'ON_PAGE' => $on_page, - 'A_BASE_URL' => addslashes($base_url), )); diff --git a/phpBB/includes/mcp/mcp_forum.php b/phpBB/includes/mcp/mcp_forum.php index 7b3bc82093..151677bcfe 100644 --- a/phpBB/includes/mcp/mcp_forum.php +++ b/phpBB/includes/mcp/mcp_forum.php @@ -103,7 +103,7 @@ function mcp_forum_view($id, $mode, $action, $forum_info) $base_url = $url . "&i=$id&action=$action&mode=$mode&sd=$sort_dir&sk=$sort_key&st=$sort_days" . (($merge_select) ? $selected_ids : ''); phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $forum_topics, $topics_per_page, $start); - + $template->assign_vars(array( 'ACTION' => $action, 'FORUM_NAME' => $forum_info['forum_name'], diff --git a/phpBB/includes/mcp/mcp_logs.php b/phpBB/includes/mcp/mcp_logs.php index c1724b20d9..f706840492 100644 --- a/phpBB/includes/mcp/mcp_logs.php +++ b/phpBB/includes/mcp/mcp_logs.php @@ -172,8 +172,8 @@ class mcp_logs $start = view_log('mod', $log_data, $log_count, $config['topics_per_page'], $start, $forum_list, $topic_id, 0, $sql_where, $sql_sort, $keywords); $base_url = $this->u_action . "&$u_sort_param$keywords_param"; - phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start); - + phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start); + $template->assign_vars(array( 'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $log_count, $config['topics_per_page'], $start), 'TOTAL' => $user->lang('TOTAL_LOGS', (int) $log_count), diff --git a/phpBB/includes/mcp/mcp_notes.php b/phpBB/includes/mcp/mcp_notes.php index bbf618ebef..59cdf3c27e 100644 --- a/phpBB/includes/mcp/mcp_notes.php +++ b/phpBB/includes/mcp/mcp_notes.php @@ -217,7 +217,7 @@ class mcp_notes $base_url = $this->u_action . "&$u_sort_param$keywords_param"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start); - + $template->assign_vars(array( 'U_POST_ACTION' => $this->u_action, 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false, diff --git a/phpBB/includes/mcp/mcp_pm_reports.php b/phpBB/includes/mcp/mcp_pm_reports.php index 24e531517c..be18dba944 100644 --- a/phpBB/includes/mcp/mcp_pm_reports.php +++ b/phpBB/includes/mcp/mcp_pm_reports.php @@ -297,10 +297,10 @@ class mcp_pm_reports } } } - + $base_url = $this->u_action . "&st=$sort_days&sk=$sort_key&sd=$sort_dir"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); - + // Now display the page $template->assign_vars(array( 'L_EXPLAIN' => ($mode == 'pm_reports') ? $user->lang['MCP_PM_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_PM_REPORTS_CLOSED_EXPLAIN'], diff --git a/phpBB/includes/mcp/mcp_queue.php b/phpBB/includes/mcp/mcp_queue.php index b44685b8a3..0b195aa9d8 100644 --- a/phpBB/includes/mcp/mcp_queue.php +++ b/phpBB/includes/mcp/mcp_queue.php @@ -421,7 +421,7 @@ class mcp_queue $base_url = $this->u_action . "&f=$forum_id&st=$sort_days&sk=$sort_key&sd=$sort_dir"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); - + // Now display the page $template->assign_vars(array( 'L_DISPLAY_ITEMS' => ($mode == 'unapproved_posts') ? $user->lang['DISPLAY_POSTS'] : $user->lang['DISPLAY_TOPICS'], diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php index 2890cd56e2..f2c5080df5 100644 --- a/phpBB/includes/mcp/mcp_reports.php +++ b/phpBB/includes/mcp/mcp_reports.php @@ -413,7 +413,7 @@ class mcp_reports $base_url = $this->u_action . "&f=$forum_id&t=$topic_id&st=$sort_days&sk=$sort_key&sd=$sort_dir"; phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $config['topics_per_page'], $start); - + // Now display the page $template->assign_vars(array( 'L_EXPLAIN' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_REPORTS_CLOSED_EXPLAIN'], diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php index e39e553ab6..62483270c0 100644 --- a/phpBB/includes/mcp/mcp_topic.php +++ b/phpBB/includes/mcp/mcp_topic.php @@ -311,7 +311,7 @@ function mcp_topic_view($id, $mode, $action) { phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $total, $posts_per_page, $start); } - + $template->assign_vars(array( 'TOPIC_TITLE' => $topic_info['topic_title'], 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_info['forum_id'] . '&t=' . $topic_info['topic_id']), diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index aefddb7c01..6a8fb4c5d5 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -177,7 +177,7 @@ class mcp_warn $base_url = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=warn&mode=list&st=$st&sk=$sk&sd=$sd"); phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $user_count, $config['topics_per_page'], $start); - + $template->assign_vars(array( 'U_POST_ACTION' => $this->u_action, 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false, diff --git a/phpBB/includes/ucp/ucp_attachments.php b/phpBB/includes/ucp/ucp_attachments.php index e4c351709b..dc095e7b73 100644 --- a/phpBB/includes/ucp/ucp_attachments.php +++ b/phpBB/includes/ucp/ucp_attachments.php @@ -171,8 +171,8 @@ class ucp_attachments $db->sql_freeresult($result); $base_url = $this->u_action . "&sk=$sort_key&sd=$sort_dir"; - phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start); - + phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start); + $template->assign_vars(array( 'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $num_attachments, $config['topics_per_page'], $start), 'TOTAL_ATTACHMENTS' => $num_attachments, diff --git a/phpBB/includes/ucp/ucp_pm_viewfolder.php b/phpBB/includes/ucp/ucp_pm_viewfolder.php index 1026f24699..625da23736 100644 --- a/phpBB/includes/ucp/ucp_pm_viewfolder.php +++ b/phpBB/includes/ucp/ucp_pm_viewfolder.php @@ -453,7 +453,7 @@ function get_pm_from($folder_id, $folder, $user_id) $base_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&action=view_folder&f=$folder_id&$u_sort_param"); phpbb_generate_template_pagination($template, $base_url, 'pagination', 'start', $pm_count, $config['topics_per_page'], $start); - + $template->assign_vars(array( 'PAGE_NUMBER' => phpbb_on_page($template, $user, $base_url, $pm_count, $config['topics_per_page'], $start), 'TOTAL_MESSAGES' => $user->lang('VIEW_PM_MESSAGES', (int) $pm_count), diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index f142d182bc..d9ba147c70 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1593,7 +1593,7 @@ switch ($mode) } phpbb_generate_template_pagination($template, $pagination_url, 'pagination', 'start', $total_users, $config['topics_per_page'], $start); - + // Generate page $template->assign_vars(array( 'PAGE_NUMBER' => phpbb_on_page($template, $user, $pagination_url, $total_users, $config['topics_per_page'], $start), diff --git a/phpBB/search.php b/phpBB/search.php index 7eda3c4d1d..7d20d8d4a2 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -614,7 +614,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) } phpbb_generate_template_pagination($template, $u_search, 'pagination', 'start', $total_match_count, $per_page, $start); - + $template->assign_vars(array( 'SEARCH_TITLE' => $l_search_title, 'SEARCH_MATCHES' => $l_search_matches, @@ -1013,7 +1013,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id), 'U_VIEW_POST' => (!empty($row['post_id'])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=" . $row['topic_id'] . '&p=' . $row['post_id'] . (($u_hilit) ? '&hilit=' . $u_hilit : '')) . '#p' . $row['post_id'] : '') )); - + if ($show_results == 'topics') { phpbb_generate_template_pagination($template, $view_topic_url, 'searchresults.pagination', 'start', $replies + 1, $config['posts_per_page'], 1, true, true); From 7675d72622cf47789c83c9a243d17b0db37b72d2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Oct 2012 22:36:37 +0200 Subject: [PATCH 312/645] [ticket/11014] Fix text for previous/next links in Subsilver2 PHPBB3-11014 --- phpBB/styles/subsilver2/template/pagination.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/styles/subsilver2/template/pagination.html b/phpBB/styles/subsilver2/template/pagination.html index f78bb554fc..a2e023ac22 100644 --- a/phpBB/styles/subsilver2/template/pagination.html +++ b/phpBB/styles/subsilver2/template/pagination.html @@ -1,10 +1,10 @@ {L_GOTO_PAGE} - {pagination.PAGE_NUMBER} + {L_PREVIOUS} {pagination.PAGE_NUMBER} {L_ELLIPSIS} - {pagination.PAGE_NUMBER} + {L_NEXT} {pagination.PAGE_NUMBER} From 7ce43d49d8aadeab7db316741cc9d2503fee844c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 17 Oct 2012 22:38:18 +0200 Subject: [PATCH 313/645] [ticket/11014] Fix IF statements for new template pagination PHPBB3-11014 --- phpBB/styles/subsilver2/template/mcp_footer.html | 2 +- phpBB/styles/subsilver2/template/ucp_groups_manage.html | 2 +- phpBB/styles/subsilver2/template/viewonline_body.html | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/styles/subsilver2/template/mcp_footer.html b/phpBB/styles/subsilver2/template/mcp_footer.html index b48c244653..280920b148 100644 --- a/phpBB/styles/subsilver2/template/mcp_footer.html +++ b/phpBB/styles/subsilver2/template/mcp_footer.html @@ -3,7 +3,7 @@ - + diff --git a/phpBB/styles/subsilver2/template/ucp_groups_manage.html b/phpBB/styles/subsilver2/template/ucp_groups_manage.html index ac678895a6..decd40a6de 100644 --- a/phpBB/styles/subsilver2/template/ucp_groups_manage.html +++ b/phpBB/styles/subsilver2/template/ucp_groups_manage.html @@ -185,7 +185,7 @@
-
diff --git a/phpBB/adm/style/captcha_default_acp_demo.html b/phpBB/adm/style/captcha_default_acp_demo.html index 0b1434f7e0..0f137f28df 100644 --- a/phpBB/adm/style/captcha_default_acp_demo.html +++ b/phpBB/adm/style/captcha_default_acp_demo.html @@ -1,4 +1,4 @@
-

{L_CAPTCHA_PREVIEW_EXPLAIN}
+

{L_CAPTCHA_PREVIEW_EXPLAIN}
{L_PREVIEW}
diff --git a/phpBB/adm/style/captcha_gd_acp.html b/phpBB/adm/style/captcha_gd_acp.html index e2804bbc7d..b333d9205c 100644 --- a/phpBB/adm/style/captcha_gd_acp.html +++ b/phpBB/adm/style/captcha_gd_acp.html @@ -14,32 +14,32 @@ {L_GENERAL_OPTIONS}
-

{L_CAPTCHA_GD_FOREGROUND_NOISE_EXPLAIN}
+

{L_CAPTCHA_GD_FOREGROUND_NOISE_EXPLAIN}
-

{L_CAPTCHA_GD_X_GRID_EXPLAIN}
+

{L_CAPTCHA_GD_X_GRID_EXPLAIN}
-

{L_CAPTCHA_GD_Y_GRID_EXPLAIN}
+

{L_CAPTCHA_GD_Y_GRID_EXPLAIN}
-

{L_CAPTCHA_GD_WAVE_EXPLAIN}
+

{L_CAPTCHA_GD_WAVE_EXPLAIN}
-

{L_CAPTCHA_GD_3D_NOISE_EXPLAIN}
+

{L_CAPTCHA_GD_3D_NOISE_EXPLAIN}
-

{L_CAPTCHA_GD_FONTS_EXPLAIN}
+

{L_CAPTCHA_GD_FONTS_EXPLAIN}
diff --git a/phpBB/adm/style/captcha_qa_acp.html b/phpBB/adm/style/captcha_qa_acp.html index 4eb46d2d3c..99f3f24f70 100644 --- a/phpBB/adm/style/captcha_qa_acp.html +++ b/phpBB/adm/style/captcha_qa_acp.html @@ -59,7 +59,7 @@
{L_EDIT_QUESTION}
-

{L_QUESTION_STRICT_EXPLAIN}
+

{L_QUESTION_STRICT_EXPLAIN}
diff --git a/phpBB/adm/style/captcha_qa_acp_demo.html b/phpBB/adm/style/captcha_qa_acp_demo.html index 0ea2d6a024..79170e27c6 100644 --- a/phpBB/adm/style/captcha_qa_acp_demo.html +++ b/phpBB/adm/style/captcha_qa_acp_demo.html @@ -1,5 +1,5 @@
-

{L_CONFIRM_QUESTION_EXPLAIN}
+

{L_CONFIRM_QUESTION_EXPLAIN}
diff --git a/phpBB/adm/style/captcha_recaptcha_acp.html b/phpBB/adm/style/captcha_recaptcha_acp.html index 34912c7955..67176ebd07 100644 --- a/phpBB/adm/style/captcha_recaptcha_acp.html +++ b/phpBB/adm/style/captcha_recaptcha_acp.html @@ -13,11 +13,11 @@ {L_GENERAL_OPTIONS}
-

{L_RECAPTCHA_PUBLIC_EXPLAIN}
+

{L_RECAPTCHA_PUBLIC_EXPLAIN}
-

{L_RECAPTCHA_PRIVATE_EXPLAIN}
+

{L_RECAPTCHA_PRIVATE_EXPLAIN}
diff --git a/phpBB/adm/style/custom_profile_fields.html b/phpBB/adm/style/custom_profile_fields.html index 351397d3c7..982356bfa7 100644 --- a/phpBB/adm/style/custom_profile_fields.html +++ b/phpBB/adm/style/custom_profile_fields.html @@ -26,7 +26,7 @@ - {L_DAY}: - {L_MONTH}: - {L_YEAR}: + {L_DAY}{L_COLON} + {L_MONTH}{L_COLON} + {L_YEAR}{L_COLON} diff --git a/phpBB/adm/style/install_convert.html b/phpBB/adm/style/install_convert.html index cf78f30b50..5fec8c4789 100644 --- a/phpBB/adm/style/install_convert.html +++ b/phpBB/adm/style/install_convert.html @@ -86,7 +86,7 @@
-

{checks.TITLE_EXPLAIN}
+

{checks.TITLE_EXPLAIN}
{checks.RESULT}
@@ -109,7 +109,7 @@
-

{options.TITLE_EXPLAIN}
+

{options.TITLE_EXPLAIN}
{options.CONTENT}
diff --git a/phpBB/adm/style/install_header.html b/phpBB/adm/style/install_header.html index e306d8f6bf..6826654ded 100644 --- a/phpBB/adm/style/install_header.html +++ b/phpBB/adm/style/install_header.html @@ -42,7 +42,7 @@ function dE(n, s, type)
- + {S_LANG_SELECT}
diff --git a/phpBB/adm/style/install_install.html b/phpBB/adm/style/install_install.html index 79006fba69..1a809a3588 100644 --- a/phpBB/adm/style/install_install.html +++ b/phpBB/adm/style/install_install.html @@ -20,7 +20,7 @@
-
{checks.TITLE}:
{checks.TITLE_EXPLAIN}
+
{checks.TITLE}{L_COLON}
{checks.TITLE_EXPLAIN}
{checks.RESULT}
@@ -43,7 +43,7 @@
-

{options.TITLE_EXPLAIN}
+

{options.TITLE_EXPLAIN}
{options.CONTENT}
diff --git a/phpBB/adm/style/install_update.html b/phpBB/adm/style/install_update.html index 818889c89b..b5fa46dbf6 100644 --- a/phpBB/adm/style/install_update.html +++ b/phpBB/adm/style/install_update.html @@ -221,13 +221,13 @@
{new.DIR_PART}
{new.FILE_PART}
-
{L_FILE_USED}: {new.CUSTOM_ORIGINAL} +
{L_FILE_USED}{L_COLON} {new.CUSTOM_ORIGINAL}
-
+
[{new.L_SHOW_DIFF}]{L_BINARY_FILE}
-
+
@@ -245,11 +245,11 @@
{not_modified.DIR_PART}
{not_modified.FILE_PART}
-
{L_FILE_USED}: {not_modified.CUSTOM_ORIGINAL} +
{L_FILE_USED}{L_COLON} {not_modified.CUSTOM_ORIGINAL}
-
[{not_modified.L_SHOW_DIFF}]{L_BINARY_FILE}
+
[{not_modified.L_SHOW_DIFF}]{L_BINARY_FILE}
-
+
@@ -266,24 +266,24 @@ {L_STATUS_MODIFIED}
{modified.DIR_PART}
{modified.FILE_PART}
-
{L_FILE_USED}: {modified.CUSTOM_ORIGINAL} +
{L_FILE_USED}{L_COLON} {modified.CUSTOM_ORIGINAL}
-
 
+
 
-
+
-
[{modified.L_SHOW_DIFF}]{L_BINARY_FILE}
+
[{modified.L_SHOW_DIFF}]{L_BINARY_FILE}
-
[{L_SHOW_DIFF_FINAL}] 
+
[{L_SHOW_DIFF_FINAL}] 
-
[{L_SHOW_DIFF_FINAL}] 
+
[{L_SHOW_DIFF_FINAL}] 
@@ -299,13 +299,13 @@
{new_conflict.DIR_PART}
{new_conflict.FILE_PART}
-
{L_FILE_USED}: {new_conflict.CUSTOM_ORIGINAL} +
{L_FILE_USED}{L_COLON} {new_conflict.CUSTOM_ORIGINAL}
-
+
[{new_conflict.L_SHOW_DIFF}]{L_BINARY_FILE}
-
+
@@ -322,38 +322,38 @@ {L_STATUS_CONFLICT}
{conflict.DIR_PART}
{conflict.FILE_PART}
-
{L_FILE_USED}: {conflict.CUSTOM_ORIGINAL} -
{L_NUM_CONFLICTS}: {conflict.NUM_CONFLICTS} +
{L_FILE_USED}{L_COLON} {conflict.CUSTOM_ORIGINAL} +
{L_NUM_CONFLICTS}{L_COLON} {conflict.NUM_CONFLICTS}
-
+
[{L_DOWNLOAD_CONFLICTS}]
{L_DOWNLOAD_CONFLICTS_EXPLAIN} {L_BINARY_FILE}
-
+
-
 
+
 
-
[{L_SHOW_DIFF_MODIFIED}]
+
[{L_SHOW_DIFF_MODIFIED}]
-
[{L_SHOW_DIFF_MODIFIED}]
+
[{L_SHOW_DIFF_MODIFIED}]
-
[{L_SHOW_DIFF_FINAL}]
+
[{L_SHOW_DIFF_FINAL}]
-
[{L_SHOW_DIFF_FINAL}]
+
[{L_SHOW_DIFF_FINAL}]
@@ -392,7 +392,7 @@
{L_SELECT_DOWNLOAD_FORMAT}
-
+
{RADIO_BUTTONS}
@@ -455,12 +455,12 @@
{L_FTP_SETTINGS}
-
+
{UPLOAD_METHOD}
-

{data.EXPLAIN}
+

{data.EXPLAIN}
diff --git a/phpBB/adm/style/install_update_diff.html b/phpBB/adm/style/install_update_diff.html index b5d25e82f2..ecdc40e157 100644 --- a/phpBB/adm/style/install_update_diff.html +++ b/phpBB/adm/style/install_update_diff.html @@ -223,7 +223,7 @@ table.hrdiff caption span {

{L_SKIP}

- + @@ -231,7 +231,7 @@ table.hrdiff caption span { -
{L_NUM_CONFLICTS}: {NUM_CONFLICTS}
+
{L_NUM_CONFLICTS}{L_COLON} {NUM_CONFLICTS}

diff --git a/phpBB/adm/style/overall_header.html b/phpBB/adm/style/overall_header.html index f6d0e1025f..f7902e6d2e 100644 --- a/phpBB/adm/style/overall_header.html +++ b/phpBB/adm/style/overall_header.html @@ -9,7 +9,7 @@ '; - $this->context->append_var('SCRIPTS', $code); - } -} + $user->img('icon_contact', 'CONTACT', 'full'); +* +* More in-depth... +* yadayada +*/ + +/** +* Base Template class. +* @package phpBB3 +*/ +class phpbb_template +{ + /** + * Template context. + * Stores template data used during template rendering. + * @var phpbb_template_context + */ + private $context; + + /** + * Path of the cache directory for the template + * @var string + */ + public $cachepath = ''; + + /** + * phpBB root path + * @var string + */ + private $phpbb_root_path; + + /** + * PHP file extension + * @var string + */ + private $php_ext; + + /** + * phpBB config instance + * @var phpbb_config + */ + private $config; + + /** + * Current user + * @var phpbb_user + */ + private $user; + + /** + * Template locator + * @var phpbb_template_locator + */ + private $locator; + + /** + * Location of templates directory within style directories + * @var string + */ + public $template_path = 'template/'; + + /** + * Constructor. + * + * @param string $phpbb_root_path phpBB root path + * @param user $user current user + * @param phpbb_template_locator $locator template locator + * @param phpbb_template_context $context template context + */ + public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->config = $config; + $this->user = $user; + $this->locator = $locator; + $this->template_path = $this->locator->template_path; + $this->context = $context; + } + + /** + * Sets the template filenames for handles. + * + * @param array $filname_array Should be a hash of handle => filename pairs. + */ + public function set_filenames(array $filename_array) + { + $this->locator->set_filenames($filename_array); + + return true; + } + + /** + * Clears all variables and blocks assigned to this template. + */ + public function destroy() + { + $this->context->clear(); + } + + /** + * Reset/empty complete block + * + * @param string $blockname Name of block to destroy + */ + public function destroy_block_vars($blockname) + { + $this->context->destroy_block_vars($blockname); + } + + /** + * Display a template for provided handle. + * + * The template will be loaded and compiled, if necessary, first. + * + * This function calls hooks. + * + * @param string $handle Handle to display + * @return bool True on success, false on failure + */ + public function display($handle) + { + $result = $this->call_hook($handle, __FUNCTION__); + if ($result !== false) + { + return $result[0]; + } + + return $this->load_and_render($handle); + } + + /** + * Loads a template for $handle, compiling it if necessary, and + * renders the template. + * + * @param string $handle Template handle to render + * @return bool True on success, false on failure + */ + private function load_and_render($handle) + { + $renderer = $this->_tpl_load($handle); + + if ($renderer) + { + $renderer->render($this->context, $this->get_lang()); + return true; + } + else + { + return false; + } + } + + /** + * Calls hook if any is defined. + * + * @param string $handle Template handle being displayed. + * @param string $method Method name of the caller. + */ + private function call_hook($handle, $method) + { + global $phpbb_hook; + + if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) + { + if ($phpbb_hook->hook_return(array(__CLASS__, $method))) + { + $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); + return array($result); + } + } + + return false; + } + + /** + * Obtains language array. + * This is either lang property of $user property, or if + * it is not set an empty array. + * @return array language entries + */ + public function get_lang() + { + if (isset($this->user->lang)) + { + $lang = $this->user->lang; + } + else + { + $lang = array(); + } + return $lang; + } + + /** + * Display the handle and assign the output to a template variable + * or return the compiled result. + * + * @param string $handle Handle to operate on + * @param string $template_var Template variable to assign compiled handle to + * @param bool $return_content If true return compiled handle, otherwise assign to $template_var + * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true + */ + public function assign_display($handle, $template_var = '', $return_content = true) + { + ob_start(); + $result = $this->display($handle); + $contents = ob_get_clean(); + if ($result === false) + { + return false; + } + + if ($return_content) + { + return $contents; + } + + $this->assign_var($template_var, $contents); + + return true; + } + + /** + * Obtains a template renderer for a template identified by specified + * handle. The template renderer can display the template later. + * + * Template source will first be compiled into php code. + * If template cache is writable the compiled php code will be stored + * on filesystem and template will not be subsequently recompiled. + * If template cache is not writable template source will be recompiled + * every time it is needed. DEBUG define and load_tplcompile + * configuration setting may be used to force templates to be always + * recompiled. + * + * Returns an object implementing phpbb_template_renderer, or null + * if template loading or compilation failed. Call render() on the + * renderer to display the template. This will result in template + * contents sent to the output stream (unless, of course, output + * buffering is in effect). + * + * @param string $handle Handle of the template to load + * @return phpbb_template_renderer Template renderer object, or null on failure + * @uses phpbb_template_compile is used to compile template source + */ + private function _tpl_load($handle) + { + $output_file = $this->_compiled_file_for_handle($handle); + + $recompile = defined('DEBUG') || + !file_exists($output_file) || + @filesize($output_file) === 0; + + if ($recompile || $this->config['load_tplcompile']) + { + // Set only if a recompile or an mtime check are required. + $source_file = $this->locator->get_source_file_for_handle($handle); + + if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) + { + $recompile = true; + } + } + + // Recompile page if the original template is newer, otherwise load the compiled version + if (!$recompile) + { + return new phpbb_template_renderer_include($output_file, $this); + } + + $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); + + if ($compile->compile_file_to_file($source_file, $output_file) !== false) + { + $renderer = new phpbb_template_renderer_include($output_file, $this); + } + else if (($code = $compile->compile_file($source_file)) !== false) + { + $renderer = new phpbb_template_renderer_eval($code, $this); + } + else + { + $renderer = null; + } + + return $renderer; + } + + /** + * Determines compiled file path for handle $handle. + * + * @param string $handle Template handle (i.e. "friendly" template name) + * @return string Compiled file path + */ + private function _compiled_file_for_handle($handle) + { + $source_file = $this->locator->get_filename_for_handle($handle); + $compiled_file = $this->cachepath . str_replace('/', '.', $source_file) . '.' . $this->php_ext; + return $compiled_file; + } + + /** + * Assign key variable pairs from an array + * + * @param array $vararray A hash of variable name => value pairs + */ + public function assign_vars(array $vararray) + { + foreach ($vararray as $key => $val) + { + $this->assign_var($key, $val); + } + } + + /** + * Assign a single scalar value to a single key. + * + * Value can be a string, an integer or a boolean. + * + * @param string $varname Variable name + * @param string $varval Value to assign to variable + */ + public function assign_var($varname, $varval) + { + $this->context->assign_var($varname, $varval); + } + + /** + * Append text to the string value stored in a key. + * + * Text is appended using the string concatenation operator (.). + * + * @param string $varname Variable name + * @param string $varval Value to append to variable + */ + public function append_var($varname, $varval) + { + $this->context->append_var($varname, $varval); + } + + // Docstring is copied from phpbb_template_context method with the same name. + /** + * Assign key variable pairs from an array to a specified block + * @param string $blockname Name of block to assign $vararray to + * @param array $vararray A hash of variable name => value pairs + */ + public function assign_block_vars($blockname, array $vararray) + { + return $this->context->assign_block_vars($blockname, $vararray); + } + + // Docstring is copied from phpbb_template_context method with the same name. + /** + * Change already assigned key variable pair (one-dimensional - single loop entry) + * + * An example of how to use this function: + * {@example alter_block_array.php} + * + * @param string $blockname the blockname, for example 'loop' + * @param array $vararray the var array to insert/add or merge + * @param mixed $key Key to search for + * + * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] + * + * int: Position [the position to change or insert at directly given] + * + * If key is false the position is set to 0 + * If key is true the position is set to the last entry + * + * @param string $mode Mode to execute (valid modes are 'insert' and 'change') + * + * If insert, the vararray is inserted at the given position (position counting from zero). + * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). + * + * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) + * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) + * + * @return bool false on error, true on success + */ + public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') + { + return $this->context->alter_block_array($blockname, $vararray, $key, $mode); + } + + /** + * Include a separate template. + * + * This function is marked public due to the way the template + * implementation uses it. It is actually an implementation function + * and should not be considered part of template class's public API. + * + * @param string $filename Template filename to include + * @param bool $include True to include the file, false to just load it + * @uses template_compile is used to compile uncached templates + */ + public function _tpl_include($filename, $include = true) + { + $this->locator->set_filenames(array($filename => $filename)); + + if (!$this->load_and_render($filename)) + { + // trigger_error cannot be used here, as the output already started + echo 'template->_tpl_include(): Failed including ' . htmlspecialchars($handle) . "\n"; + } + } + + /** + * Include a PHP file. + * + * If a relative path is passed in $filename, it is considered to be + * relative to board root ($phpbb_root_path). Absolute paths are + * also allowed. + * + * This function is marked public due to the way the template + * implementation uses it. It is actually an implementation function + * and should not be considered part of template class's public API. + * + * @param string $filename Path to PHP file to include + */ + public function _php_include($filename) + { + if (phpbb_is_absolute($filename)) + { + $file = $filename; + } + else + { + $file = $this->phpbb_root_path . $filename; + } + + if (!file_exists($file)) + { + // trigger_error cannot be used here, as the output already started + echo 'template->_php_include(): File ' . htmlspecialchars($file) . " does not exist\n"; + return; + } + include($file); + } + + /** + * Obtains filesystem path for a template file. + * + * The simplest use is specifying a single template file as a string + * in the first argument. This template file should be a basename + * of a template file in the selected style, or its parent styles + * if template inheritance is being utilized. + * + * Note: "selected style" is whatever style the style resource locator + * is configured for. + * + * The return value then will be a path, relative to the current + * directory or absolute, to the template file in the selected style + * or its closest parent. + * + * If the selected style does not have the template file being searched, + * (and if inheritance is involved, none of the parents have it either), + * false will be returned. + * + * Specifying true for $return_default will cause the function to + * return the first path which was checked for existence in the event + * that the template file was not found, instead of false. + * This is the path in the selected style itself, not any of its + * parents. + * + * $files can be given an array of templates instead of a single + * template. When given an array, the function will try to resolve + * each template in the array to a path, and will return the first + * path that exists, or false if none exist. + * + * If $return_full_path is false, then instead of returning a usable + * path (when the template is found) only the template's basename + * will be returned. This can be used to check which of the templates + * specified in $files exists, provided different file names are + * used for different templates. + * + * @param string or array $files List of templates to locate. If there is only + * one template, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if template does not + * exist. If true, function will return location where template is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to template. If false, function will return template file name. + * This parameter can be used to check which one of set of template + * files is available. + * @return string or boolean Source template path if template exists or $return_default is + * true. False if template does not exist and $return_default is false + */ + public function locate($files, $return_default = false, $return_full_path = true) + { + // add template path prefix + $templates = array(); + if (is_string($files)) + { + $templates[] = $this->template_path . $files; + } + else + { + foreach ($files as $file) + { + $templates[] = $this->template_path . $file; + } + } + + // use resource locator to find files + return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); + } + + /** + * Include JS file + * + * @param string $file file name + * @param bool $locate True if file needs to be located + * @param bool $relative True if path is relative to phpBB root directory. Ignored if $locate == true + */ + public function _js_include($file, $locate = false, $relative = false) + { + // Locate file + if ($locate) + { + $located = $this->locator->get_first_file_location(array($file), false, true); + if ($located) + { + $file = $located; + } + } + else if ($relative) + { + $file = $this->phpbb_root_path . $file; + } + + $file .= (strpos($file, '?') === false) ? '?' : '&'; + $file .= 'assets_version=' . $this->config['assets_version']; + + // Add HTML code + $code = ''; + $this->context->append_var('SCRIPTS', $code); + } +} From 2e594504596eaf6ab758240a1cd012dfea79fe77 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 10:42:20 -0500 Subject: [PATCH 489/645] [feature/controller] Use assign_display() instead of return_display() The latter was deemed unnecessary at the moment. PHPBB3-10864 --- phpBB/includes/controller/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 0fc3ba0c67..8bb4427382 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -87,7 +87,7 @@ class phpbb_controller_helper page_footer(true, false, false); - return new Response($this->template->return_display('body'), $status_code); + return new Response($this->template->assign_display('body'), $status_code); } /** From c6a5699325171ca12c540772ed4e6c0c55318ec5 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 10:46:46 -0500 Subject: [PATCH 490/645] [feature/controller-new] Fix line endings PHPBB3-10864 --- phpBB/includes/template/template.php | 1118 +++++++++++++------------- 1 file changed, 559 insertions(+), 559 deletions(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 00fe26b9b1..8a7dc6b2f3 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -1,559 +1,559 @@ - $user->img('icon_contact', 'CONTACT', 'full'); -* -* More in-depth... -* yadayada -*/ - -/** -* Base Template class. -* @package phpBB3 -*/ -class phpbb_template -{ - /** - * Template context. - * Stores template data used during template rendering. - * @var phpbb_template_context - */ - private $context; - - /** - * Path of the cache directory for the template - * @var string - */ - public $cachepath = ''; - - /** - * phpBB root path - * @var string - */ - private $phpbb_root_path; - - /** - * PHP file extension - * @var string - */ - private $php_ext; - - /** - * phpBB config instance - * @var phpbb_config - */ - private $config; - - /** - * Current user - * @var phpbb_user - */ - private $user; - - /** - * Template locator - * @var phpbb_template_locator - */ - private $locator; - - /** - * Location of templates directory within style directories - * @var string - */ - public $template_path = 'template/'; - - /** - * Constructor. - * - * @param string $phpbb_root_path phpBB root path - * @param user $user current user - * @param phpbb_template_locator $locator template locator - * @param phpbb_template_context $context template context - */ - public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context) - { - $this->phpbb_root_path = $phpbb_root_path; - $this->php_ext = $php_ext; - $this->config = $config; - $this->user = $user; - $this->locator = $locator; - $this->template_path = $this->locator->template_path; - $this->context = $context; - } - - /** - * Sets the template filenames for handles. - * - * @param array $filname_array Should be a hash of handle => filename pairs. - */ - public function set_filenames(array $filename_array) - { - $this->locator->set_filenames($filename_array); - - return true; - } - - /** - * Clears all variables and blocks assigned to this template. - */ - public function destroy() - { - $this->context->clear(); - } - - /** - * Reset/empty complete block - * - * @param string $blockname Name of block to destroy - */ - public function destroy_block_vars($blockname) - { - $this->context->destroy_block_vars($blockname); - } - - /** - * Display a template for provided handle. - * - * The template will be loaded and compiled, if necessary, first. - * - * This function calls hooks. - * - * @param string $handle Handle to display - * @return bool True on success, false on failure - */ - public function display($handle) - { - $result = $this->call_hook($handle, __FUNCTION__); - if ($result !== false) - { - return $result[0]; - } - - return $this->load_and_render($handle); - } - - /** - * Loads a template for $handle, compiling it if necessary, and - * renders the template. - * - * @param string $handle Template handle to render - * @return bool True on success, false on failure - */ - private function load_and_render($handle) - { - $renderer = $this->_tpl_load($handle); - - if ($renderer) - { - $renderer->render($this->context, $this->get_lang()); - return true; - } - else - { - return false; - } - } - - /** - * Calls hook if any is defined. - * - * @param string $handle Template handle being displayed. - * @param string $method Method name of the caller. - */ - private function call_hook($handle, $method) - { - global $phpbb_hook; - - if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) - { - if ($phpbb_hook->hook_return(array(__CLASS__, $method))) - { - $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); - return array($result); - } - } - - return false; - } - - /** - * Obtains language array. - * This is either lang property of $user property, or if - * it is not set an empty array. - * @return array language entries - */ - public function get_lang() - { - if (isset($this->user->lang)) - { - $lang = $this->user->lang; - } - else - { - $lang = array(); - } - return $lang; - } - - /** - * Display the handle and assign the output to a template variable - * or return the compiled result. - * - * @param string $handle Handle to operate on - * @param string $template_var Template variable to assign compiled handle to - * @param bool $return_content If true return compiled handle, otherwise assign to $template_var - * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true - */ - public function assign_display($handle, $template_var = '', $return_content = true) - { - ob_start(); - $result = $this->display($handle); - $contents = ob_get_clean(); - if ($result === false) - { - return false; - } - - if ($return_content) - { - return $contents; - } - - $this->assign_var($template_var, $contents); - - return true; - } - - /** - * Obtains a template renderer for a template identified by specified - * handle. The template renderer can display the template later. - * - * Template source will first be compiled into php code. - * If template cache is writable the compiled php code will be stored - * on filesystem and template will not be subsequently recompiled. - * If template cache is not writable template source will be recompiled - * every time it is needed. DEBUG define and load_tplcompile - * configuration setting may be used to force templates to be always - * recompiled. - * - * Returns an object implementing phpbb_template_renderer, or null - * if template loading or compilation failed. Call render() on the - * renderer to display the template. This will result in template - * contents sent to the output stream (unless, of course, output - * buffering is in effect). - * - * @param string $handle Handle of the template to load - * @return phpbb_template_renderer Template renderer object, or null on failure - * @uses phpbb_template_compile is used to compile template source - */ - private function _tpl_load($handle) - { - $output_file = $this->_compiled_file_for_handle($handle); - - $recompile = defined('DEBUG') || - !file_exists($output_file) || - @filesize($output_file) === 0; - - if ($recompile || $this->config['load_tplcompile']) - { - // Set only if a recompile or an mtime check are required. - $source_file = $this->locator->get_source_file_for_handle($handle); - - if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) - { - $recompile = true; - } - } - - // Recompile page if the original template is newer, otherwise load the compiled version - if (!$recompile) - { - return new phpbb_template_renderer_include($output_file, $this); - } - - $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); - - if ($compile->compile_file_to_file($source_file, $output_file) !== false) - { - $renderer = new phpbb_template_renderer_include($output_file, $this); - } - else if (($code = $compile->compile_file($source_file)) !== false) - { - $renderer = new phpbb_template_renderer_eval($code, $this); - } - else - { - $renderer = null; - } - - return $renderer; - } - - /** - * Determines compiled file path for handle $handle. - * - * @param string $handle Template handle (i.e. "friendly" template name) - * @return string Compiled file path - */ - private function _compiled_file_for_handle($handle) - { - $source_file = $this->locator->get_filename_for_handle($handle); - $compiled_file = $this->cachepath . str_replace('/', '.', $source_file) . '.' . $this->php_ext; - return $compiled_file; - } - - /** - * Assign key variable pairs from an array - * - * @param array $vararray A hash of variable name => value pairs - */ - public function assign_vars(array $vararray) - { - foreach ($vararray as $key => $val) - { - $this->assign_var($key, $val); - } - } - - /** - * Assign a single scalar value to a single key. - * - * Value can be a string, an integer or a boolean. - * - * @param string $varname Variable name - * @param string $varval Value to assign to variable - */ - public function assign_var($varname, $varval) - { - $this->context->assign_var($varname, $varval); - } - - /** - * Append text to the string value stored in a key. - * - * Text is appended using the string concatenation operator (.). - * - * @param string $varname Variable name - * @param string $varval Value to append to variable - */ - public function append_var($varname, $varval) - { - $this->context->append_var($varname, $varval); - } - - // Docstring is copied from phpbb_template_context method with the same name. - /** - * Assign key variable pairs from an array to a specified block - * @param string $blockname Name of block to assign $vararray to - * @param array $vararray A hash of variable name => value pairs - */ - public function assign_block_vars($blockname, array $vararray) - { - return $this->context->assign_block_vars($blockname, $vararray); - } - - // Docstring is copied from phpbb_template_context method with the same name. - /** - * Change already assigned key variable pair (one-dimensional - single loop entry) - * - * An example of how to use this function: - * {@example alter_block_array.php} - * - * @param string $blockname the blockname, for example 'loop' - * @param array $vararray the var array to insert/add or merge - * @param mixed $key Key to search for - * - * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] - * - * int: Position [the position to change or insert at directly given] - * - * If key is false the position is set to 0 - * If key is true the position is set to the last entry - * - * @param string $mode Mode to execute (valid modes are 'insert' and 'change') - * - * If insert, the vararray is inserted at the given position (position counting from zero). - * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). - * - * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) - * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) - * - * @return bool false on error, true on success - */ - public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') - { - return $this->context->alter_block_array($blockname, $vararray, $key, $mode); - } - - /** - * Include a separate template. - * - * This function is marked public due to the way the template - * implementation uses it. It is actually an implementation function - * and should not be considered part of template class's public API. - * - * @param string $filename Template filename to include - * @param bool $include True to include the file, false to just load it - * @uses template_compile is used to compile uncached templates - */ - public function _tpl_include($filename, $include = true) - { - $this->locator->set_filenames(array($filename => $filename)); - - if (!$this->load_and_render($filename)) - { - // trigger_error cannot be used here, as the output already started - echo 'template->_tpl_include(): Failed including ' . htmlspecialchars($handle) . "\n"; - } - } - - /** - * Include a PHP file. - * - * If a relative path is passed in $filename, it is considered to be - * relative to board root ($phpbb_root_path). Absolute paths are - * also allowed. - * - * This function is marked public due to the way the template - * implementation uses it. It is actually an implementation function - * and should not be considered part of template class's public API. - * - * @param string $filename Path to PHP file to include - */ - public function _php_include($filename) - { - if (phpbb_is_absolute($filename)) - { - $file = $filename; - } - else - { - $file = $this->phpbb_root_path . $filename; - } - - if (!file_exists($file)) - { - // trigger_error cannot be used here, as the output already started - echo 'template->_php_include(): File ' . htmlspecialchars($file) . " does not exist\n"; - return; - } - include($file); - } - - /** - * Obtains filesystem path for a template file. - * - * The simplest use is specifying a single template file as a string - * in the first argument. This template file should be a basename - * of a template file in the selected style, or its parent styles - * if template inheritance is being utilized. - * - * Note: "selected style" is whatever style the style resource locator - * is configured for. - * - * The return value then will be a path, relative to the current - * directory or absolute, to the template file in the selected style - * or its closest parent. - * - * If the selected style does not have the template file being searched, - * (and if inheritance is involved, none of the parents have it either), - * false will be returned. - * - * Specifying true for $return_default will cause the function to - * return the first path which was checked for existence in the event - * that the template file was not found, instead of false. - * This is the path in the selected style itself, not any of its - * parents. - * - * $files can be given an array of templates instead of a single - * template. When given an array, the function will try to resolve - * each template in the array to a path, and will return the first - * path that exists, or false if none exist. - * - * If $return_full_path is false, then instead of returning a usable - * path (when the template is found) only the template's basename - * will be returned. This can be used to check which of the templates - * specified in $files exists, provided different file names are - * used for different templates. - * - * @param string or array $files List of templates to locate. If there is only - * one template, $files can be a string to make code easier to read. - * @param bool $return_default Determines what to return if template does not - * exist. If true, function will return location where template is - * supposed to be. If false, function will return false. - * @param bool $return_full_path If true, function will return full path - * to template. If false, function will return template file name. - * This parameter can be used to check which one of set of template - * files is available. - * @return string or boolean Source template path if template exists or $return_default is - * true. False if template does not exist and $return_default is false - */ - public function locate($files, $return_default = false, $return_full_path = true) - { - // add template path prefix - $templates = array(); - if (is_string($files)) - { - $templates[] = $this->template_path . $files; - } - else - { - foreach ($files as $file) - { - $templates[] = $this->template_path . $file; - } - } - - // use resource locator to find files - return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); - } - - /** - * Include JS file - * - * @param string $file file name - * @param bool $locate True if file needs to be located - * @param bool $relative True if path is relative to phpBB root directory. Ignored if $locate == true - */ - public function _js_include($file, $locate = false, $relative = false) - { - // Locate file - if ($locate) - { - $located = $this->locator->get_first_file_location(array($file), false, true); - if ($located) - { - $file = $located; - } - } - else if ($relative) - { - $file = $this->phpbb_root_path . $file; - } - - $file .= (strpos($file, '?') === false) ? '?' : '&'; - $file .= 'assets_version=' . $this->config['assets_version']; - - // Add HTML code - $code = ''; - $this->context->append_var('SCRIPTS', $code); - } -} + $user->img('icon_contact', 'CONTACT', 'full'); +* +* More in-depth... +* yadayada +*/ + +/** +* Base Template class. +* @package phpBB3 +*/ +class phpbb_template +{ + /** + * Template context. + * Stores template data used during template rendering. + * @var phpbb_template_context + */ + private $context; + + /** + * Path of the cache directory for the template + * @var string + */ + public $cachepath = ''; + + /** + * phpBB root path + * @var string + */ + private $phpbb_root_path; + + /** + * PHP file extension + * @var string + */ + private $php_ext; + + /** + * phpBB config instance + * @var phpbb_config + */ + private $config; + + /** + * Current user + * @var phpbb_user + */ + private $user; + + /** + * Template locator + * @var phpbb_template_locator + */ + private $locator; + + /** + * Location of templates directory within style directories + * @var string + */ + public $template_path = 'template/'; + + /** + * Constructor. + * + * @param string $phpbb_root_path phpBB root path + * @param user $user current user + * @param phpbb_template_locator $locator template locator + * @param phpbb_template_context $context template context + */ + public function __construct($phpbb_root_path, $php_ext, $config, $user, phpbb_template_locator $locator, phpbb_template_context $context) + { + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + $this->config = $config; + $this->user = $user; + $this->locator = $locator; + $this->template_path = $this->locator->template_path; + $this->context = $context; + } + + /** + * Sets the template filenames for handles. + * + * @param array $filname_array Should be a hash of handle => filename pairs. + */ + public function set_filenames(array $filename_array) + { + $this->locator->set_filenames($filename_array); + + return true; + } + + /** + * Clears all variables and blocks assigned to this template. + */ + public function destroy() + { + $this->context->clear(); + } + + /** + * Reset/empty complete block + * + * @param string $blockname Name of block to destroy + */ + public function destroy_block_vars($blockname) + { + $this->context->destroy_block_vars($blockname); + } + + /** + * Display a template for provided handle. + * + * The template will be loaded and compiled, if necessary, first. + * + * This function calls hooks. + * + * @param string $handle Handle to display + * @return bool True on success, false on failure + */ + public function display($handle) + { + $result = $this->call_hook($handle, __FUNCTION__); + if ($result !== false) + { + return $result[0]; + } + + return $this->load_and_render($handle); + } + + /** + * Loads a template for $handle, compiling it if necessary, and + * renders the template. + * + * @param string $handle Template handle to render + * @return bool True on success, false on failure + */ + private function load_and_render($handle) + { + $renderer = $this->_tpl_load($handle); + + if ($renderer) + { + $renderer->render($this->context, $this->get_lang()); + return true; + } + else + { + return false; + } + } + + /** + * Calls hook if any is defined. + * + * @param string $handle Template handle being displayed. + * @param string $method Method name of the caller. + */ + private function call_hook($handle, $method) + { + global $phpbb_hook; + + if (!empty($phpbb_hook) && $phpbb_hook->call_hook(array(__CLASS__, $method), $handle, $this)) + { + if ($phpbb_hook->hook_return(array(__CLASS__, $method))) + { + $result = $phpbb_hook->hook_return_result(array(__CLASS__, $method)); + return array($result); + } + } + + return false; + } + + /** + * Obtains language array. + * This is either lang property of $user property, or if + * it is not set an empty array. + * @return array language entries + */ + public function get_lang() + { + if (isset($this->user->lang)) + { + $lang = $this->user->lang; + } + else + { + $lang = array(); + } + return $lang; + } + + /** + * Display the handle and assign the output to a template variable + * or return the compiled result. + * + * @param string $handle Handle to operate on + * @param string $template_var Template variable to assign compiled handle to + * @param bool $return_content If true return compiled handle, otherwise assign to $template_var + * @return bool|string false on failure, otherwise if $return_content is true return string of the compiled handle, otherwise return true + */ + public function assign_display($handle, $template_var = '', $return_content = true) + { + ob_start(); + $result = $this->display($handle); + $contents = ob_get_clean(); + if ($result === false) + { + return false; + } + + if ($return_content) + { + return $contents; + } + + $this->assign_var($template_var, $contents); + + return true; + } + + /** + * Obtains a template renderer for a template identified by specified + * handle. The template renderer can display the template later. + * + * Template source will first be compiled into php code. + * If template cache is writable the compiled php code will be stored + * on filesystem and template will not be subsequently recompiled. + * If template cache is not writable template source will be recompiled + * every time it is needed. DEBUG define and load_tplcompile + * configuration setting may be used to force templates to be always + * recompiled. + * + * Returns an object implementing phpbb_template_renderer, or null + * if template loading or compilation failed. Call render() on the + * renderer to display the template. This will result in template + * contents sent to the output stream (unless, of course, output + * buffering is in effect). + * + * @param string $handle Handle of the template to load + * @return phpbb_template_renderer Template renderer object, or null on failure + * @uses phpbb_template_compile is used to compile template source + */ + private function _tpl_load($handle) + { + $output_file = $this->_compiled_file_for_handle($handle); + + $recompile = defined('DEBUG') || + !file_exists($output_file) || + @filesize($output_file) === 0; + + if ($recompile || $this->config['load_tplcompile']) + { + // Set only if a recompile or an mtime check are required. + $source_file = $this->locator->get_source_file_for_handle($handle); + + if (!$recompile && @filemtime($output_file) < @filemtime($source_file)) + { + $recompile = true; + } + } + + // Recompile page if the original template is newer, otherwise load the compiled version + if (!$recompile) + { + return new phpbb_template_renderer_include($output_file, $this); + } + + $compile = new phpbb_template_compile($this->config['tpl_allow_php'], $this->locator, $this->phpbb_root_path); + + if ($compile->compile_file_to_file($source_file, $output_file) !== false) + { + $renderer = new phpbb_template_renderer_include($output_file, $this); + } + else if (($code = $compile->compile_file($source_file)) !== false) + { + $renderer = new phpbb_template_renderer_eval($code, $this); + } + else + { + $renderer = null; + } + + return $renderer; + } + + /** + * Determines compiled file path for handle $handle. + * + * @param string $handle Template handle (i.e. "friendly" template name) + * @return string Compiled file path + */ + private function _compiled_file_for_handle($handle) + { + $source_file = $this->locator->get_filename_for_handle($handle); + $compiled_file = $this->cachepath . str_replace('/', '.', $source_file) . '.' . $this->php_ext; + return $compiled_file; + } + + /** + * Assign key variable pairs from an array + * + * @param array $vararray A hash of variable name => value pairs + */ + public function assign_vars(array $vararray) + { + foreach ($vararray as $key => $val) + { + $this->assign_var($key, $val); + } + } + + /** + * Assign a single scalar value to a single key. + * + * Value can be a string, an integer or a boolean. + * + * @param string $varname Variable name + * @param string $varval Value to assign to variable + */ + public function assign_var($varname, $varval) + { + $this->context->assign_var($varname, $varval); + } + + /** + * Append text to the string value stored in a key. + * + * Text is appended using the string concatenation operator (.). + * + * @param string $varname Variable name + * @param string $varval Value to append to variable + */ + public function append_var($varname, $varval) + { + $this->context->append_var($varname, $varval); + } + + // Docstring is copied from phpbb_template_context method with the same name. + /** + * Assign key variable pairs from an array to a specified block + * @param string $blockname Name of block to assign $vararray to + * @param array $vararray A hash of variable name => value pairs + */ + public function assign_block_vars($blockname, array $vararray) + { + return $this->context->assign_block_vars($blockname, $vararray); + } + + // Docstring is copied from phpbb_template_context method with the same name. + /** + * Change already assigned key variable pair (one-dimensional - single loop entry) + * + * An example of how to use this function: + * {@example alter_block_array.php} + * + * @param string $blockname the blockname, for example 'loop' + * @param array $vararray the var array to insert/add or merge + * @param mixed $key Key to search for + * + * array: KEY => VALUE [the key/value pair to search for within the loop to determine the correct position] + * + * int: Position [the position to change or insert at directly given] + * + * If key is false the position is set to 0 + * If key is true the position is set to the last entry + * + * @param string $mode Mode to execute (valid modes are 'insert' and 'change') + * + * If insert, the vararray is inserted at the given position (position counting from zero). + * If change, the current block gets merged with the vararray (resulting in new key/value pairs be added and existing keys be replaced by the new value). + * + * Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array) + * and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars) + * + * @return bool false on error, true on success + */ + public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert') + { + return $this->context->alter_block_array($blockname, $vararray, $key, $mode); + } + + /** + * Include a separate template. + * + * This function is marked public due to the way the template + * implementation uses it. It is actually an implementation function + * and should not be considered part of template class's public API. + * + * @param string $filename Template filename to include + * @param bool $include True to include the file, false to just load it + * @uses template_compile is used to compile uncached templates + */ + public function _tpl_include($filename, $include = true) + { + $this->locator->set_filenames(array($filename => $filename)); + + if (!$this->load_and_render($filename)) + { + // trigger_error cannot be used here, as the output already started + echo 'template->_tpl_include(): Failed including ' . htmlspecialchars($handle) . "\n"; + } + } + + /** + * Include a PHP file. + * + * If a relative path is passed in $filename, it is considered to be + * relative to board root ($phpbb_root_path). Absolute paths are + * also allowed. + * + * This function is marked public due to the way the template + * implementation uses it. It is actually an implementation function + * and should not be considered part of template class's public API. + * + * @param string $filename Path to PHP file to include + */ + public function _php_include($filename) + { + if (phpbb_is_absolute($filename)) + { + $file = $filename; + } + else + { + $file = $this->phpbb_root_path . $filename; + } + + if (!file_exists($file)) + { + // trigger_error cannot be used here, as the output already started + echo 'template->_php_include(): File ' . htmlspecialchars($file) . " does not exist\n"; + return; + } + include($file); + } + + /** + * Obtains filesystem path for a template file. + * + * The simplest use is specifying a single template file as a string + * in the first argument. This template file should be a basename + * of a template file in the selected style, or its parent styles + * if template inheritance is being utilized. + * + * Note: "selected style" is whatever style the style resource locator + * is configured for. + * + * The return value then will be a path, relative to the current + * directory or absolute, to the template file in the selected style + * or its closest parent. + * + * If the selected style does not have the template file being searched, + * (and if inheritance is involved, none of the parents have it either), + * false will be returned. + * + * Specifying true for $return_default will cause the function to + * return the first path which was checked for existence in the event + * that the template file was not found, instead of false. + * This is the path in the selected style itself, not any of its + * parents. + * + * $files can be given an array of templates instead of a single + * template. When given an array, the function will try to resolve + * each template in the array to a path, and will return the first + * path that exists, or false if none exist. + * + * If $return_full_path is false, then instead of returning a usable + * path (when the template is found) only the template's basename + * will be returned. This can be used to check which of the templates + * specified in $files exists, provided different file names are + * used for different templates. + * + * @param string or array $files List of templates to locate. If there is only + * one template, $files can be a string to make code easier to read. + * @param bool $return_default Determines what to return if template does not + * exist. If true, function will return location where template is + * supposed to be. If false, function will return false. + * @param bool $return_full_path If true, function will return full path + * to template. If false, function will return template file name. + * This parameter can be used to check which one of set of template + * files is available. + * @return string or boolean Source template path if template exists or $return_default is + * true. False if template does not exist and $return_default is false + */ + public function locate($files, $return_default = false, $return_full_path = true) + { + // add template path prefix + $templates = array(); + if (is_string($files)) + { + $templates[] = $this->template_path . $files; + } + else + { + foreach ($files as $file) + { + $templates[] = $this->template_path . $file; + } + } + + // use resource locator to find files + return $this->locator->get_first_file_location($templates, $return_default, $return_full_path); + } + + /** + * Include JS file + * + * @param string $file file name + * @param bool $locate True if file needs to be located + * @param bool $relative True if path is relative to phpBB root directory. Ignored if $locate == true + */ + public function _js_include($file, $locate = false, $relative = false) + { + // Locate file + if ($locate) + { + $located = $this->locator->get_first_file_location(array($file), false, true); + if ($located) + { + $file = $located; + } + } + else if ($relative) + { + $file = $this->phpbb_root_path . $file; + } + + $file .= (strpos($file, '?') === false) ? '?' : '&'; + $file .= 'assets_version=' . $this->config['assets_version']; + + // Add HTML code + $code = ''; + $this->context->append_var('SCRIPTS', $code); + } +} From 46cb0fb068feeb89c939d8b145808d2a786de8dd Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 10:57:24 -0500 Subject: [PATCH 491/645] [feature/controller] Removed another empty construct method PHPBB3-10864 --- tests/controller/includes/controller/foo.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/controller/includes/controller/foo.php b/tests/controller/includes/controller/foo.php index cd1c4849cb..04576e16c4 100644 --- a/tests/controller/includes/controller/foo.php +++ b/tests/controller/includes/controller/foo.php @@ -4,13 +4,6 @@ use Symfony\Component\HttpFoundation\Response; class phpbb_controller_foo { - /** - * Constructor - */ - public function __construct() - { - } - /** * Bar method * From 5877bf1b1b3dc2899543d99859e3bde6e70d8647 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 13 Nov 2012 11:02:01 -0500 Subject: [PATCH 492/645] [feature/controller] Update helper service given constructor change PHPBB3-10864 --- phpBB/config/services.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 54d347debe..184ebb80ee 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -47,7 +47,10 @@ services: controller.helper: class: phpbb_controller_helper arguments: - - @service_container + - @template + - @user + - %core.root_path% + - .%core.php_ext% controller.resolver: class: phpbb_controller_resolver @@ -64,7 +67,7 @@ services: controller.provider: class: phpbb_controller_provider - + cron.task_collection: class: phpbb_di_service_collection arguments: @@ -113,7 +116,7 @@ services: - %core.root_path% - .%core.php_ext% - @cache.driver - + ext.finder: class: phpbb_extension_finder arguments: From d3aa8823b21990634f8b74676ac301739ddfc58b Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 15:42:13 -0500 Subject: [PATCH 493/645] [feature/controller] Use a dumped url matcher class to improve performance PHPBB3-10864 --- phpBB/config/services.yml | 21 ++------ .../includes/controller/route_collection.php | 36 ------------- phpBB/includes/event/kernel_subscriber.php | 52 ++++++++++++++++++- phpBB/includes/functions.php | 52 +++++++++++++++++++ 4 files changed, 106 insertions(+), 55 deletions(-) delete mode 100644 phpBB/includes/controller/route_collection.php diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 184ebb80ee..4fe9fa52eb 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -123,7 +123,7 @@ services: - @ext.manager - %core.root_path% - @cache.driver - - .%core.php_ext% + - %core.php_ext% - _ext_finder http_kernel: @@ -137,22 +137,15 @@ services: arguments: - @template - @user + - @ext.finder + - %core.root_path% + - .%core.php_ext% tags: - { name: kernel.event_subscriber } request: class: phpbb_request - request.context: - class: Symfony\Component\Routing\RequestContext - - router_listener: - class: Symfony\Component\HttpKernel\EventListener\RouterListener - arguments: - - @url_matcher - tags: - - { name: kernel.event_subscriber } - style: class: phpbb_style arguments: @@ -189,11 +182,5 @@ services: template_context: class: phpbb_template_context - url_matcher: - class: Symfony\Component\Routing\Matcher\UrlMatcher - arguments: - - @controller.route_collection - - @request.context - user: class: phpbb_user diff --git a/phpBB/includes/controller/route_collection.php b/phpBB/includes/controller/route_collection.php deleted file mode 100644 index e6c7d3b543..0000000000 --- a/phpBB/includes/controller/route_collection.php +++ /dev/null @@ -1,36 +0,0 @@ -addCollection($provider->get_paths($finder)->find()); - } -} diff --git a/phpBB/includes/event/kernel_subscriber.php b/phpBB/includes/event/kernel_subscriber.php index 9737d9bc23..79ee4f4dc5 100644 --- a/phpBB/includes/event/kernel_subscriber.php +++ b/phpBB/includes/event/kernel_subscriber.php @@ -18,8 +18,11 @@ if (!defined('IN_PHPBB')) use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\PostResponseEvent; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\EventListener\RouterListener; +use Symfony\Component\Routing\RequestContext; class phpbb_event_kernel_subscriber implements EventSubscriberInterface { @@ -35,16 +38,40 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface */ protected $user; + /** + * Extension finder object + * @var phpbb_extension_finder + */ + protected $finder; + + /** + * PHP extension + * @var string + */ + protected $php_ext; + + /** + * Root path + * @var string + */ + protected $root_path; + /** * Construct method * * @param phpbb_template $template Template object * @param phpbb_user $user User object + * @param phpbb_extension_finder $finder Extension finder object + * @param string $root_path Root path + * @param string $php_ext PHP extension */ - public function __construct(phpbb_template $template, phpbb_user $user) + public function __construct(phpbb_template $template, phpbb_user $user, phpbb_extension_finder $finder, $root_path, $php_ext) { $this->template = $template; $this->user = $user; + $this->finder = $finder; + $this->root_path = $root_path; + $this->php_ext = $php_ext; } /** @@ -81,12 +108,33 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface page_footer(true, false, false); - $event->setResponse(new Response($this->template->return_display('body'), 404)); + $event->setResponse(new Response($this->template->assign_display('body'), 404)); + } + + /** + * This listener is run when the KernelEvents::REQUEST event is triggered + * + * This is responsible for setting up the routing information + * + * @param GetResponseEvent $event + * @return null + */ + public function on_kernel_request(GetResponseEvent $event) + { + $request = $event->getRequest(); + $context = new RequestContext(); + $context->fromRequest($request); + + $matcher = phpbb_create_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); + + $router_listener = new RouterListener($matcher, $context); + $router_listener->onKernelRequest($event); } public static function getSubscribedEvents() { return array( + KernelEvents::REQUEST => 'on_kernel_request', KernelEvents::TERMINATE => 'on_kernel_terminate', KernelEvents::EXCEPTION => 'on_kernel_exception', ); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index fb05b74cd3..7cf5611dca 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,6 +7,9 @@ * */ +use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; +use Symfony\Component\Routing\RequestContext; + /** * @ignore */ @@ -5444,3 +5447,52 @@ function phpbb_to_numeric($input) { return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } + +/** +* Create and/or return the cached phpbb_url_matcher class +* +* If the class already exists, it instantiates it +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return phpbb_url_matcher +*/ +function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + $matcher = phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); + if ($matcher === false) + { + $provider = new phpbb_controller_provider(); + $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); + $cached_url_matcher_dump = $dumper->dump(array( + 'class' => 'phpbb_url_matcher', + )); + + file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); + return phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); + } + + return $matcher; +} + +/** +* Load the cached phpbb_url_matcher class +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return phpbb_url_matcher|bool False if the file doesn't exist +*/ +function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + if (file_exists($root_path . 'cache/url_matcher' . $php_ext)) + { + include($root_path . 'cache/url_matcher' . $php_ext); + return new phpbb_url_matcher($context); + } + + return false; +} From 269a56e2c3817cc27f2b21b9eb864c4f2452bc13 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 15:52:41 -0500 Subject: [PATCH 494/645] [feature/controller] Undo removal of period in ext.finder service definition PHPBB3-10864 --- phpBB/config/services.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 4fe9fa52eb..91610a3527 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -123,7 +123,7 @@ services: - @ext.manager - %core.root_path% - @cache.driver - - %core.php_ext% + - .%core.php_ext% - _ext_finder http_kernel: From 196c2d4bc346ab6a31fd0b752c788e37cf39459d Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 15:56:07 -0500 Subject: [PATCH 495/645] [feature/controller] Move new functions to their own file PHPBB3-10864 --- phpBB/includes/functions.php | 49 ----------------- phpBB/includes/functions_url_matcher.php | 68 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 phpBB/includes/functions_url_matcher.php diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 7cf5611dca..88ce142195 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5447,52 +5447,3 @@ function phpbb_to_numeric($input) { return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } - -/** -* Create and/or return the cached phpbb_url_matcher class -* -* If the class already exists, it instantiates it -* -* @param phpbb_extension_finder $finder Extension finder -* @param RequestContext $context Symfony RequestContext object -* @param string $root_path Root path -* @param string $php_ext PHP extension -* @return phpbb_url_matcher -*/ -function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) -{ - $matcher = phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); - if ($matcher === false) - { - $provider = new phpbb_controller_provider(); - $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); - $cached_url_matcher_dump = $dumper->dump(array( - 'class' => 'phpbb_url_matcher', - )); - - file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); - return phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); - } - - return $matcher; -} - -/** -* Load the cached phpbb_url_matcher class -* -* @param phpbb_extension_finder $finder Extension finder -* @param RequestContext $context Symfony RequestContext object -* @param string $root_path Root path -* @param string $php_ext PHP extension -* @return phpbb_url_matcher|bool False if the file doesn't exist -*/ -function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) -{ - if (file_exists($root_path . 'cache/url_matcher' . $php_ext)) - { - include($root_path . 'cache/url_matcher' . $php_ext); - return new phpbb_url_matcher($context); - } - - return false; -} diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php new file mode 100644 index 0000000000..0a6e90703c --- /dev/null +++ b/phpBB/includes/functions_url_matcher.php @@ -0,0 +1,68 @@ +get_paths($finder)->find()); + $cached_url_matcher_dump = $dumper->dump(array( + 'class' => 'phpbb_url_matcher', + )); + + file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); + return phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); + } + + return $matcher; +} + +/** +* Load the cached phpbb_url_matcher class +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return phpbb_url_matcher|bool False if the file doesn't exist +*/ +function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + if (file_exists($root_path . 'cache/url_matcher' . $php_ext)) + { + include($root_path . 'cache/url_matcher' . $php_ext); + return new phpbb_url_matcher($context); + } + + return false; +} From 4cb9ec522c7007b99eb5ef44cb1bfdb369478aff Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 16:06:12 -0500 Subject: [PATCH 496/645] [feature/controller] Separate Kernel listeners into their own classes PHPBB3-10864 --- phpBB/config/services.yml | 19 ++++- .../event/kernel_exception_subscriber.php | 79 +++++++++++++++++++ ...iber.php => kernel_request_subscriber.php} | 64 ++------------- .../event/kernel_terminate_subscriber.php | 43 ++++++++++ 4 files changed, 143 insertions(+), 62 deletions(-) create mode 100644 phpBB/includes/event/kernel_exception_subscriber.php rename phpBB/includes/event/{kernel_subscriber.php => kernel_request_subscriber.php} (50%) create mode 100644 phpBB/includes/event/kernel_terminate_subscriber.php diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 91610a3527..37e6c0b5df 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -132,17 +132,28 @@ services: - @dispatcher - @controller.resolver - kernel_event_subscriber: - class: phpbb_event_kernel_subscriber + kernel_request_subscriber: + class: phpbb_event_kernel_request_subscriber arguments: - - @template - - @user - @ext.finder - %core.root_path% - .%core.php_ext% tags: - { name: kernel.event_subscriber } + kernel_exception_subscriber: + class: phpbb_event_kernel_exception_subscriber + arguments: + - @template + - @user + tags: + - { name: kernel.event_subscriber } + + kernel_terminate_subscriber: + class: phpbb_event_kernel_terminate_subscriber + tags: + - { name: kernel.event_subscriber } + request: class: phpbb_request diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/includes/event/kernel_exception_subscriber.php new file mode 100644 index 0000000000..cd6ea40c70 --- /dev/null +++ b/phpBB/includes/event/kernel_exception_subscriber.php @@ -0,0 +1,79 @@ +template = $template; + $this->user = $user; + } + + /** + * This listener is run when the KernelEvents::EXCEPTION event is triggered + * + * @param GetResponseForExceptionEvent $event + * @return null + */ + public function on_kernel_exception(GetResponseForExceptionEvent $event) + { + page_header($this->user->lang('INFORMATION')); + + $this->template->assign_vars(array( + 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), + 'MESSAGE_TEXT' => $event->getException()->getMessage(), + )); + + $this->template->set_filenames(array( + 'body' => 'message_body.html', + )); + + page_footer(true, false, false); + + $event->setResponse(new Response($this->template->assign_display('body'), 404)); + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::EXCEPTION => 'on_kernel_exception', + ); + } +} diff --git a/phpBB/includes/event/kernel_subscriber.php b/phpBB/includes/event/kernel_request_subscriber.php similarity index 50% rename from phpBB/includes/event/kernel_subscriber.php rename to phpBB/includes/event/kernel_request_subscriber.php index 79ee4f4dc5..98079acabb 100644 --- a/phpBB/includes/event/kernel_subscriber.php +++ b/phpBB/includes/event/kernel_request_subscriber.php @@ -17,27 +17,12 @@ if (!defined('IN_PHPBB')) use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\HttpKernel\Event\PostResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent; -use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\EventListener\RouterListener; use Symfony\Component\Routing\RequestContext; -class phpbb_event_kernel_subscriber implements EventSubscriberInterface +class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface { - /** - * Template object - * @var phpbb_template - */ - protected $template; - - /** - * User object - * @var phpbb_user - */ - protected $user; - /** * Extension finder object * @var phpbb_extension_finder @@ -59,13 +44,11 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface /** * Construct method * - * @param phpbb_template $template Template object - * @param phpbb_user $user User object * @param phpbb_extension_finder $finder Extension finder object * @param string $root_path Root path * @param string $php_ext PHP extension */ - public function __construct(phpbb_template $template, phpbb_user $user, phpbb_extension_finder $finder, $root_path, $php_ext) + public function __construct(phpbb_extension_finder $finder, $root_path, $php_ext) { $this->template = $template; $this->user = $user; @@ -74,43 +57,6 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface $this->php_ext = $php_ext; } - /** - * This listener is run when the KernelEvents::TERMINATE event is triggered - * This comes after a Response has been sent to the server; this is - * primarily cleanup stuff. - * - * @param PostResponseEvent $event - * @return null - */ - public function on_kernel_terminate(PostResponseEvent $event) - { - exit_handler(); - } - - /** - * This listener is run when the KernelEvents::EXCEPTION event is triggered - * - * @param GetResponseForExceptionEvent $event - * @return null - */ - public function on_kernel_exception(GetResponseForExceptionEvent $event) - { - page_header($this->user->lang('INFORMATION')); - - $this->template->assign_vars(array( - 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), - 'MESSAGE_TEXT' => $event->getException()->getMessage(), - )); - - $this->template->set_filenames(array( - 'body' => 'message_body.html', - )); - - page_footer(true, false, false); - - $event->setResponse(new Response($this->template->assign_display('body'), 404)); - } - /** * This listener is run when the KernelEvents::REQUEST event is triggered * @@ -125,6 +71,10 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface $context = new RequestContext(); $context->fromRequest($request); + if (!function_exists('phpbb_create_url_matcher')) + { + include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); + } $matcher = phpbb_create_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); $router_listener = new RouterListener($matcher, $context); @@ -135,8 +85,6 @@ class phpbb_event_kernel_subscriber implements EventSubscriberInterface { return array( KernelEvents::REQUEST => 'on_kernel_request', - KernelEvents::TERMINATE => 'on_kernel_terminate', - KernelEvents::EXCEPTION => 'on_kernel_exception', ); } } diff --git a/phpBB/includes/event/kernel_terminate_subscriber.php b/phpBB/includes/event/kernel_terminate_subscriber.php new file mode 100644 index 0000000000..1eaf890e42 --- /dev/null +++ b/phpBB/includes/event/kernel_terminate_subscriber.php @@ -0,0 +1,43 @@ + 'on_kernel_terminate', + ); + } +} From fa43edd8778dffd21146350f1749fad5c0755fb7 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 16:42:52 -0500 Subject: [PATCH 497/645] [feature/controller] Further separate url matcher functionality PHPBB3-10864 --- .../event/kernel_request_subscriber.php | 6 +- phpBB/includes/functions_url_matcher.php | 89 +++++++++++++------ 2 files changed, 65 insertions(+), 30 deletions(-) diff --git a/phpBB/includes/event/kernel_request_subscriber.php b/phpBB/includes/event/kernel_request_subscriber.php index 98079acabb..85c8c5b173 100644 --- a/phpBB/includes/event/kernel_request_subscriber.php +++ b/phpBB/includes/event/kernel_request_subscriber.php @@ -50,8 +50,6 @@ class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface */ public function __construct(phpbb_extension_finder $finder, $root_path, $php_ext) { - $this->template = $template; - $this->user = $user; $this->finder = $finder; $this->root_path = $root_path; $this->php_ext = $php_ext; @@ -71,11 +69,11 @@ class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface $context = new RequestContext(); $context->fromRequest($request); - if (!function_exists('phpbb_create_url_matcher')) + if (!function_exists('phpbb_load_url_matcher')) { include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); } - $matcher = phpbb_create_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); + $matcher = phpbb_get_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); $router_listener = new RouterListener($matcher, $context); $router_listener->onKernelRequest($event); diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php index 0a6e90703c..f628337dee 100644 --- a/phpBB/includes/functions_url_matcher.php +++ b/phpBB/includes/functions_url_matcher.php @@ -8,6 +8,7 @@ */ use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; +use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\RequestContext; /** @@ -19,50 +20,86 @@ if (!defined('IN_PHPBB')) } /** -* Create and/or return the cached phpbb_url_matcher class -* -* If the class already exists, it instantiates it +* Create a new UrlMatcher class and dump it into the cache file * * @param phpbb_extension_finder $finder Extension finder * @param RequestContext $context Symfony RequestContext object * @param string $root_path Root path * @param string $php_ext PHP extension -* @return phpbb_url_matcher +* @return null */ -function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) { - $matcher = phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); - if ($matcher === false) + if (defined('DEBUG')) { - $provider = new phpbb_controller_provider(); - $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); - $cached_url_matcher_dump = $dumper->dump(array( - 'class' => 'phpbb_url_matcher', - )); - - file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); - return phpbb_load_url_matcher($finder, $context, $root_path, $php_ext); + return phpbb_create_url_matcher($finder, $context); } - return $matcher; + if (phpbb_url_matcher_dumped($root_path, $php_ext) === false) + { + phpbb_create_dumped_url_matcher($finder, $context, $root_path, $php_ext); + } + + return phpbb_load_url_matcher($context, $root_path, $php_ext); +} + +/** +* Create a new UrlMatcher class and dump it into the cache file +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return null +*/ +function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +{ + $provider = new phpbb_controller_provider(); + $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); + $cached_url_matcher_dump = $dumper->dump(array( + 'class' => 'phpbb_url_matcher', + )); + + file_put_contents($root_path . 'cache/url_matcher' . $php_ext, $cached_url_matcher_dump); +} + +/** +* Create a non-cached UrlMatcher +* +* @param phpbb_extension_finder $finder Extension finder +* @param RequestContext $context Symfony RequestContext object +* @return UrlMatcher +*/ +function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context) +{ + $provider = new phpbb_controller_provider(); + return new UrlMatcher($provider->get_paths($finder)->find(), $context); } /** * Load the cached phpbb_url_matcher class * -* @param phpbb_extension_finder $finder Extension finder * @param RequestContext $context Symfony RequestContext object * @param string $root_path Root path * @param string $php_ext PHP extension -* @return phpbb_url_matcher|bool False if the file doesn't exist +* @return phpbb_url_matcher */ -function phpbb_load_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +function phpbb_load_url_matcher(RequestContext $context, $root_path, $php_ext) { - if (file_exists($root_path . 'cache/url_matcher' . $php_ext)) - { - include($root_path . 'cache/url_matcher' . $php_ext); - return new phpbb_url_matcher($context); - } - - return false; + require($root_path . 'cache/url_matcher' . $php_ext); + return new phpbb_url_matcher($context); +} + +/** +* Determine whether we have our dumped URL matcher +* +* The class is automatically dumped to the cache directory +* +* @param string $root_path Root path +* @param string $php_ext PHP extension +* @return bool True if it exists, false if not +*/ +function phpbb_url_matcher_dumped($root_path, $php_ext) +{ + return file_exists($root_path . 'cache/url_matcher' . $php_ext); } From c54c3ee422a9bfb0878aecf80cbb298e230e4fd4 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 17:04:45 -0500 Subject: [PATCH 498/645] [feature/controller] A few minor nitpickings PHPBB3-10864 --- phpBB/includes/functions_url_matcher.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php index f628337dee..782acc4c20 100644 --- a/phpBB/includes/functions_url_matcher.php +++ b/phpBB/includes/functions_url_matcher.php @@ -35,7 +35,7 @@ function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $c return phpbb_create_url_matcher($finder, $context); } - if (phpbb_url_matcher_dumped($root_path, $php_ext) === false) + if (!phpbb_url_matcher_dumped($root_path, $php_ext)) { phpbb_create_dumped_url_matcher($finder, $context, $root_path, $php_ext); } @@ -55,7 +55,8 @@ function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $c function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) { $provider = new phpbb_controller_provider(); - $dumper = new PhpMatcherDumper($provider->get_paths($finder)->find()); + $routes = $provider->get_paths($finder)->find(); + $dumper = new PhpMatcherDumper($routes); $cached_url_matcher_dump = $dumper->dump(array( 'class' => 'phpbb_url_matcher', )); From aead33432ae67857009f9570a5ec720d86f7575b Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 14 Nov 2012 17:14:21 -0500 Subject: [PATCH 499/645] [feature/controller] Remove dumped container when cache is purged PHPBB3-10864 --- phpBB/includes/cache/driver/file.php | 1 + phpBB/includes/cache/driver/memory.php | 1 + 2 files changed, 2 insertions(+) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index 32bdb1918a..5014ba18af 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -215,6 +215,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { if (strpos($entry, 'container_') !== 0 && + strpos($entry, 'url_matcher') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index 1ea9a3e9e7..f6c42c0ea6 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -163,6 +163,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base while (($entry = readdir($dir)) !== false) { if (strpos($entry, 'container_') !== 0 && + strpos($entry, 'url_matcher') !== 0 && strpos($entry, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && From b4eff4f06acce78536a392b733f2438f4d1d1c52 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 13:54:41 -0500 Subject: [PATCH 500/645] [feature/controller] Remove URL Base from helper class I had forgotten that the container sends the same instance of objects to all services that request it, so in this case all controllers would share the same base url path, which is not desired. PHPBB3-10864 --- phpBB/includes/controller/helper.php | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 8bb4427382..6b697c7e46 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -47,12 +47,6 @@ class phpbb_controller_helper */ protected $php_ext; - /** - * Base URL - * @var array - */ - protected $url_base; - /** * Constructor * @@ -101,21 +95,7 @@ class phpbb_controller_helper */ public function url(array $url_parts, $query = '') { - return append_sid($this->root_path . $this->url_base . implode('/', $url_parts), $query); - } - - /** - * Set base to prepend to urls generated by url() - * This allows extensions to have a certain 'directory' under which - * all their pages are served, but not have to type it every time - * - * @param array $url_parts Each array element is a 'folder' - * i.e. array('my', 'ext') maps to ./app.php/my/ext - * @return null - */ - public function set_url_base(array $url_parts) - { - $this->url_base = !empty($url_parts) ? implode('/', $url_parts) . '/' : ''; + return append_sid($this->root_path . implode('/', $url_parts), $query); } /** From db1d49d559a337f7266a9e9f0cfaf3eb025b0ed1 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 13:59:30 -0500 Subject: [PATCH 501/645] [feature/controller] Rename get_paths to import_paths_from_finder Also removed unused variable from url_matcher function PHPBB3-10864 --- phpBB/includes/controller/provider.php | 20 ++++---------------- phpBB/includes/functions_url_matcher.php | 10 +++++----- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/phpBB/includes/controller/provider.php b/phpBB/includes/controller/provider.php index 25deedb5d1..b2a5b9f6b2 100644 --- a/phpBB/includes/controller/provider.php +++ b/phpBB/includes/controller/provider.php @@ -39,7 +39,7 @@ class phpbb_controller_provider */ public function __construct($routing_paths = array()) { - $this->set_paths($routing_paths); + $this->routing_paths = $routing_paths; } /** @@ -48,28 +48,16 @@ class phpbb_controller_provider * * @return The current instance of this object for method chaining */ - public function get_paths(phpbb_extension_finder $finder) + public function import_paths_from_finder(phpbb_extension_finder $finder) { // We hardcode the path to the core config directory // because the finder cannot find it - $this->set_paths(array_merge(array('config'), array_map('dirname', array_keys($finder + $this->routing_paths = array_merge(array('config'), array_map('dirname', array_keys($finder ->directory('config') ->prefix('routing') ->suffix('yml') ->find() - )))); - - return $this; - } - - /** - * Set the $routing_paths property with a given list of paths - * - * @return The current instance of this object for method chaining - */ - public function set_paths(array $paths) - { - $this->routing_paths = $paths; + ))); return $this; } diff --git a/phpBB/includes/functions_url_matcher.php b/phpBB/includes/functions_url_matcher.php index 782acc4c20..7280cb74eb 100644 --- a/phpBB/includes/functions_url_matcher.php +++ b/phpBB/includes/functions_url_matcher.php @@ -37,7 +37,7 @@ function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $c if (!phpbb_url_matcher_dumped($root_path, $php_ext)) { - phpbb_create_dumped_url_matcher($finder, $context, $root_path, $php_ext); + phpbb_create_dumped_url_matcher($finder, $root_path, $php_ext); } return phpbb_load_url_matcher($context, $root_path, $php_ext); @@ -47,15 +47,14 @@ function phpbb_get_url_matcher(phpbb_extension_finder $finder, RequestContext $c * Create a new UrlMatcher class and dump it into the cache file * * @param phpbb_extension_finder $finder Extension finder -* @param RequestContext $context Symfony RequestContext object * @param string $root_path Root path * @param string $php_ext PHP extension * @return null */ -function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, RequestContext $context, $root_path, $php_ext) +function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, $root_path, $php_ext) { $provider = new phpbb_controller_provider(); - $routes = $provider->get_paths($finder)->find(); + $routes = $provider->import_paths_from_finder($finder)->find(); $dumper = new PhpMatcherDumper($routes); $cached_url_matcher_dump = $dumper->dump(array( 'class' => 'phpbb_url_matcher', @@ -74,7 +73,8 @@ function phpbb_create_dumped_url_matcher(phpbb_extension_finder $finder, Request function phpbb_create_url_matcher(phpbb_extension_finder $finder, RequestContext $context) { $provider = new phpbb_controller_provider(); - return new UrlMatcher($provider->get_paths($finder)->find(), $context); + $routes = $provider->import_paths_from_finder($finder)->find(); + return new UrlMatcher($routes, $context); } /** From 8e480a87253fd2e42af3fc4daaed2f49b9ae65c5 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 14:48:45 -0500 Subject: [PATCH 502/645] [feature/controller] Move include to app.php PHPBB3-10864 --- phpBB/app.php | 1 + phpBB/includes/event/kernel_request_subscriber.php | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/phpBB/app.php b/phpBB/app.php index 9ff9069104..a2dbb1ae5b 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -17,6 +17,7 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); +include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); // Start session management $user->session_begin(); diff --git a/phpBB/includes/event/kernel_request_subscriber.php b/phpBB/includes/event/kernel_request_subscriber.php index 85c8c5b173..afb8464f80 100644 --- a/phpBB/includes/event/kernel_request_subscriber.php +++ b/phpBB/includes/event/kernel_request_subscriber.php @@ -69,12 +69,7 @@ class phpbb_event_kernel_request_subscriber implements EventSubscriberInterface $context = new RequestContext(); $context->fromRequest($request); - if (!function_exists('phpbb_load_url_matcher')) - { - include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); - } $matcher = phpbb_get_url_matcher($this->finder, $context, $this->root_path, $this->php_ext); - $router_listener = new RouterListener($matcher, $context); $router_listener->onKernelRequest($event); } From 91ce6e8b16abb831e1e18b73cf857a257a59e432 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 14:59:14 -0500 Subject: [PATCH 503/645] [feature/controller] Turn off URL rewriting by default, add comments for usage PHPBB3-10864 --- phpBB/.htaccess | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 68021177f2..1713f8e522 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -1,7 +1,11 @@ Options +FollowSymLinks -RewriteEngine on +# +# Uncomment the following line if you will be using any of the URL +# rewriting below. +# +#RewriteEngine on # # Uncomment the statement below if you want to make use of @@ -10,9 +14,15 @@ RewriteEngine on # #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^(.*)$ app.php [QSA,L] +# +# Uncomment the following 3 lines if you want to rewrite URLs passed through +# the front controller to not use app.php in the actual URL. In other words, +# an controller that would by default be accessed at /app.php/my/controller +# can now be accessed at /my/controller directly. +# +#RewriteCond %{REQUEST_FILENAME} !-f +#RewriteCond %{REQUEST_FILENAME} !-d +#RewriteRule ^(.*)$ app.php [QSA,L] From db071d68541d132f5b06da652a2214b664552b1e Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 15:05:52 -0500 Subject: [PATCH 504/645] [feature/controller] Fix use of $this in global scope PHPBB3-10864 --- phpBB/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/app.php b/phpBB/app.php index a2dbb1ae5b..a7d645cb09 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -17,7 +17,7 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); -include($this->root_path . 'includes/functions_url_matcher' . $this->php_ext); +include($phpbb_root_path . 'includes/functions_url_matcher' . $phpEx); // Start session management $user->session_begin(); From d0269629dcee2dda176807bdd944415d1713db7b Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 15:20:47 -0500 Subject: [PATCH 505/645] [feature/controller] Documentation about Symlinks in .htaccess PHPBB3-10864 --- phpBB/.htaccess | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 1713f8e522..9f635dba57 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -1,5 +1,3 @@ -Options +FollowSymLinks - # # Uncomment the following line if you will be using any of the URL @@ -23,6 +21,12 @@ Options +FollowSymLinks #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d #RewriteRule ^(.*)$ app.php [QSA,L] + +# +# On Windows, you must also uncomment the following line so that SymLinks +# are followed. +# +#Options +FollowSymLinks From 14f44c17ad76878ed540cd5dd56a3a62b30dbd15 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:14:11 -0500 Subject: [PATCH 506/645] [feature/controller] phpbb_controller_exception instead of RuntimeException PHPBB3-10864 --- phpBB/includes/controller/exception.php | 24 ++++++++++++++++++++++++ phpBB/includes/controller/resolver.php | 11 ++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 phpBB/includes/controller/exception.php diff --git a/phpBB/includes/controller/exception.php b/phpBB/includes/controller/exception.php new file mode 100644 index 0000000000..da2fefc600 --- /dev/null +++ b/phpBB/includes/controller/exception.php @@ -0,0 +1,24 @@ +user->lang['CONTROLLER_NOT_SPECIFIED']); + throw new phpbb_controller_exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']); } // Require a method name along with the service name if (stripos($controller, ':') === false) { - throw new RuntimeException($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); + throw new phpbb_controller_exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); } list($service, $method) = explode(':', $controller); if (!$this->container->has($service)) { - throw new RuntimeException($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); + throw new phpbb_controller_exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); } $controller_object = $this->container->get($service); @@ -92,6 +92,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object * @param string $controller Controller class name * @return bool False + * @throws phpbb_controller_exception */ public function getArguments(Request $request, $controller) { @@ -114,7 +115,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface } else { - throw new RuntimeException($user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); + throw new phpbb_controller_exception($user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); } } From 235b0194f140a369137bd4d92bfd1b10d5e08787 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:16:25 -0500 Subject: [PATCH 507/645] [feature/controller] Update wording in .htaccess documentation comments PHPBB3-10864 --- phpBB/.htaccess | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 9f635dba57..d61ef7b893 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -15,8 +15,8 @@ # # Uncomment the following 3 lines if you want to rewrite URLs passed through # the front controller to not use app.php in the actual URL. In other words, -# an controller that would by default be accessed at /app.php/my/controller -# can now be accessed at /my/controller directly. +# a controller is by default accessed at /app.php/my/controller, but will then +# be accessed at /my/controller directly. # #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d From 45b3ab8e81a3cffae4d0ada8785620ea4209c207 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:18:02 -0500 Subject: [PATCH 508/645] [feature/controller] Move Response definition into a variable PHPBB3-10864 --- phpBB/includes/event/kernel_exception_subscriber.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/includes/event/kernel_exception_subscriber.php index cd6ea40c70..e2668d4560 100644 --- a/phpBB/includes/event/kernel_exception_subscriber.php +++ b/phpBB/includes/event/kernel_exception_subscriber.php @@ -67,7 +67,8 @@ class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterfac page_footer(true, false, false); - $event->setResponse(new Response($this->template->assign_display('body'), 404)); + $response = new Response($this->template->assign_display('body'), 404); + $event->setResponse($response); } public static function getSubscribedEvents() From f42b36185c86dfe19974c866ce7e284263aff371 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:24:32 -0500 Subject: [PATCH 509/645] [feature/controller] Better explanation of the Options +FollowSymLinks line PHPBB3-10864 --- phpBB/.htaccess | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index d61ef7b893..3283b9beb8 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -23,8 +23,9 @@ #RewriteRule ^(.*)$ app.php [QSA,L] # -# On Windows, you must also uncomment the following line so that SymLinks -# are followed. +# If symbolic links are not already being followed, +# uncomment the line below. +# http://anothersysadmin.wordpress.com/2008/06/10/mod_rewrite-forbidden-403-with-apache-228/ # #Options +FollowSymLinks From b2598662af0b3a37b228cee03cbbf7d7160c7a11 Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:26:00 -0500 Subject: [PATCH 510/645] [feature/controller] Clarify working paths after enabling rewriting PHPBB3-10864 --- phpBB/.htaccess | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index 3283b9beb8..d0f65e345c 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -16,7 +16,7 @@ # Uncomment the following 3 lines if you want to rewrite URLs passed through # the front controller to not use app.php in the actual URL. In other words, # a controller is by default accessed at /app.php/my/controller, but will then -# be accessed at /my/controller directly. +# be accessible at either /app.php/my/controller or just /my/controller # #RewriteCond %{REQUEST_FILENAME} !-f #RewriteCond %{REQUEST_FILENAME} !-d From a87a5dd566bd4b9481cdca86fa6f4bc3363d58de Mon Sep 17 00:00:00 2001 From: David King Date: Thu, 15 Nov 2012 16:31:32 -0500 Subject: [PATCH 511/645] [feature/controller] Fix tests PHPBB3-10864 --- tests/controller/controller_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index b73019a6a0..577feee517 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -33,7 +33,7 @@ class phpbb_controller_test extends phpbb_test_case { $provider = new phpbb_controller_provider; $routes = $provider - ->get_paths($this->extension_manager->get_finder()) + ->import_paths_from_finder($this->extension_manager->get_finder()) ->find('./tests/controller/'); // This will need to be updated if any new routes are defined From c9588572c9f40223de3445a211ca85b18f5294a4 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 09:20:15 -0500 Subject: [PATCH 512/645] [feature/controller] Add period before $phpEx PHPBB3-10864 --- phpBB/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/app.php b/phpBB/app.php index a7d645cb09..f1023ff1b5 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -17,7 +17,7 @@ define('IN_PHPBB', true); $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; $phpEx = substr(strrchr(__FILE__, '.'), 1); include($phpbb_root_path . 'common.' . $phpEx); -include($phpbb_root_path . 'includes/functions_url_matcher' . $phpEx); +include($phpbb_root_path . 'includes/functions_url_matcher.' . $phpEx); // Start session management $user->session_begin(); From 76917558832b0102716448770f365585aac224e9 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 09:23:57 -0500 Subject: [PATCH 513/645] [feature/controller] Adapt functional tests given new controller framework PHPBB3-10864 --- .../functional/extension_controller_test.php | 129 +++++++----------- .../fixtures/ext/error/class/controller.php | 14 -- .../fixtures/ext/error/class/ext.php | 6 - .../ext/error/classtype/controller.php | 15 -- .../fixtures/ext/error/classtype/ext.php | 6 - .../ext/error/disabled/controller.php | 14 -- .../fixtures/ext/error/disabled/ext.php | 6 - .../fixtures/ext/foo/bar/config/routing.yml | 3 + .../fixtures/ext/foo/bar/config/services.yml | 3 + .../fixtures/ext/foo/bar/controller.php | 14 -- .../ext/foo/bar/controller/controller.php | 10 ++ tests/functional/fixtures/ext/foo/bar/ext.php | 12 +- .../prosilver/template/foobar_body.html | 5 - .../fixtures/ext/foobar/controller.php | 14 -- tests/functional/fixtures/ext/foobar/ext.php | 6 - .../prosilver/template/foobar_body.html | 5 - 16 files changed, 69 insertions(+), 193 deletions(-) delete mode 100644 tests/functional/fixtures/ext/error/class/controller.php delete mode 100644 tests/functional/fixtures/ext/error/class/ext.php delete mode 100644 tests/functional/fixtures/ext/error/classtype/controller.php delete mode 100644 tests/functional/fixtures/ext/error/classtype/ext.php delete mode 100644 tests/functional/fixtures/ext/error/disabled/controller.php delete mode 100644 tests/functional/fixtures/ext/error/disabled/ext.php create mode 100755 tests/functional/fixtures/ext/foo/bar/config/routing.yml create mode 100755 tests/functional/fixtures/ext/foo/bar/config/services.yml delete mode 100644 tests/functional/fixtures/ext/foo/bar/controller.php create mode 100755 tests/functional/fixtures/ext/foo/bar/controller/controller.php mode change 100644 => 100755 tests/functional/fixtures/ext/foo/bar/ext.php delete mode 100644 tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_body.html delete mode 100644 tests/functional/fixtures/ext/foobar/controller.php delete mode 100644 tests/functional/fixtures/ext/foobar/ext.php delete mode 100644 tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index d92a830365..2f07c8a70f 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -13,6 +13,14 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_case { protected $phpbb_extension_manager; + + static protected $fixtures = array( + 'foo/bar/config/routing.yml', + 'foo/bar/config/services.yml', + 'foo/bar/controller/controller.php', + 'foo/bar/ext.php', + ); + /** * This should only be called once before the tests are run. * This is used to copy the fixtures to the phpBB install @@ -22,15 +30,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c global $phpbb_root_path; parent::setUpBeforeClass(); - // these directories need to be created before the files can be copied $directories = array( - $phpbb_root_path . 'ext/error/class/', - $phpbb_root_path . 'ext/error/classtype/', - $phpbb_root_path . 'ext/error/disabled/', $phpbb_root_path . 'ext/foo/bar/', - $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template/', - $phpbb_root_path . 'ext/foobar/', - $phpbb_root_path . 'ext/foobar/styles/prosilver/template/', + $phpbb_root_path . 'ext/foo/bar/config/', + $phpbb_root_path . 'ext/foo/bar/controller/', ); foreach ($directories as $dir) @@ -40,23 +43,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c mkdir($dir, 0777, true); } } - - $fixtures = array( - 'error/class/controller.php', - 'error/class/ext.php', - 'error/classtype/controller.php', - 'error/classtype/ext.php', - 'error/disabled/controller.php', - 'error/disabled/ext.php', - 'foo/bar/controller.php', - 'foo/bar/ext.php', - 'foo/bar/styles/prosilver/template/foobar_body.html', - 'foobar/controller.php', - 'foobar/ext.php', - 'foobar/styles/prosilver/template/foobar_body.html', - ); - - foreach ($fixtures as $fixture) + + foreach (self::$fixtures as $fixture) { if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture")) { @@ -65,6 +53,27 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } } + /** + * This should only be called once after the tests are run. + * This is used to remove the fixtures from the phpBB install + */ + static public function tearDownAfterClass() + { + global $phpbb_root_path; + foreach (self::$fixtures as $fixture) + { + if (!unlink("{$phpbb_root_path}ext/$fixture")) + { + echo 'Could not delete file ' . $fixture; + } + } + + rmdir("{$phpbb_root_path}ext/foo/bar/config"); + rmdir("{$phpbb_root_path}ext/foo/bar/controller"); + rmdir("{$phpbb_root_path}ext/foo/bar"); + rmdir("{$phpbb_root_path}ext/foo"); + } + public function setUp() { parent::setUp(); @@ -75,72 +84,28 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } /** - * Check an extension at ./ext/foobar/ which should have the class - * phpbb_ext_foobar_controller - */ - public function test_foobar() - { - $this->phpbb_extension_manager->enable('foobar'); - $crawler = $this->request('GET', 'index.php?ext=foobar'); - $this->assert_response_success(); - $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); - $this->phpbb_extension_manager->purge('foobar'); - } - - /** - * Check an extension at ./ext/foo/bar/ which should have the class - * phpbb_ext_foo_bar_controller + * Check a controller for extension foo/bar */ public function test_foo_bar() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'index.php?ext=foo/bar'); - $this->assert_response_success(); - $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text()); - $this->phpbb_extension_manager->purge('foo/bar'); + $crawler = $this->request('GET', 'app.php/foo/bar'); + $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foobar'); } /** - * Check the error produced by extension at ./ext/error/class which has class - * phpbb_ext_foobar_controller + * Check the error produced by extension at ./ext/does/not/exist + * + * If an extension is disabled, its routes are not loaded. Because we + * are not looking for a controller based on a specified extension, + * we don't know the difference between a route in a disabled + * extension and a route that is not defined anyway; it is the same + * error message. */ - public function test_error_class_name() + public function test_error_ext_disabled_or_404() { - $this->phpbb_extension_manager->enable('error/class'); - $crawler = $this->request('GET', 'index.php?ext=error/class'); - $this->assertContains("The extension error/class is missing a controller class and cannot be accessed through the front-end.", $crawler->filter('#message')->text()); - $this->phpbb_extension_manager->purge('error/class'); - } - - /** - * Check the error produced by extension at ./ext/error/classtype which has class - * phpbb_ext_error_classtype_controller but does not implement phpbb_extension_controller_interface - */ - public function test_error_class_type() - { - $this->phpbb_extension_manager->enable('error/classtype'); - $crawler = $this->request('GET', 'index.php?ext=error/classtype'); - $this->assertContains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.", $crawler->filter('#message')->text()); - $this->phpbb_extension_manager->purge('error/classtype'); - } - - /** - * Check the error produced by extension at ./ext/error/disabled that is (obviously) - * a disabled extension - */ - public function test_error_ext_disabled() - { - $crawler = $this->request('GET', 'index.php?ext=error/disabled'); - $this->assertContains("The extension error/disabled is not enabled", $crawler->filter('#message')->text()); - } - - /** - * Check the error produced by extension at ./ext/error/404 that is (obviously) - * not existant - */ - public function test_error_ext_missing() - { - $crawler = $this->request('GET', 'index.php?ext=error/404'); - $this->assertContains("The extension error/404 does not exist.", $crawler->filter('#message')->text()); + $crawler = $this->request('GET', 'app.php/does/not/exist'); + $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } } diff --git a/tests/functional/fixtures/ext/error/class/controller.php b/tests/functional/fixtures/ext/error/class/controller.php deleted file mode 100644 index 74bbbee540..0000000000 --- a/tests/functional/fixtures/ext/error/class/controller.php +++ /dev/null @@ -1,14 +0,0 @@ -template->set_filenames(array( - 'body' => 'index_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/error/class/ext.php b/tests/functional/fixtures/ext/error/class/ext.php deleted file mode 100644 index f97ad2b838..0000000000 --- a/tests/functional/fixtures/ext/error/class/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -set_filenames(array( - 'body' => 'index_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/error/classtype/ext.php b/tests/functional/fixtures/ext/error/classtype/ext.php deleted file mode 100644 index 35b1cd15a2..0000000000 --- a/tests/functional/fixtures/ext/error/classtype/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -template->set_filenames(array( - 'body' => 'index_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/error/disabled/ext.php b/tests/functional/fixtures/ext/error/disabled/ext.php deleted file mode 100644 index aec8051848..0000000000 --- a/tests/functional/fixtures/ext/error/disabled/ext.php +++ /dev/null @@ -1,6 +0,0 @@ -template->set_filenames(array( - 'body' => 'foobar_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php new file mode 100755 index 0000000000..4c5274951f --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -0,0 +1,10 @@ + - -
This is for testing purposes.
- - diff --git a/tests/functional/fixtures/ext/foobar/controller.php b/tests/functional/fixtures/ext/foobar/controller.php deleted file mode 100644 index ff35f12ee0..0000000000 --- a/tests/functional/fixtures/ext/foobar/controller.php +++ /dev/null @@ -1,14 +0,0 @@ -template->set_filenames(array( - 'body' => 'foobar_body.html' - )); - - page_header('Test extension'); - page_footer(); - } -} diff --git a/tests/functional/fixtures/ext/foobar/ext.php b/tests/functional/fixtures/ext/foobar/ext.php deleted file mode 100644 index 7cf443d369..0000000000 --- a/tests/functional/fixtures/ext/foobar/ext.php +++ /dev/null @@ -1,6 +0,0 @@ - - -
This is for testing purposes.
- - From 74bc46049303952e5f16f61e9f63fa2eeaffbadc Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 09:43:08 -0500 Subject: [PATCH 514/645] [feature/controller] Rename improperly named controller exception class PHPBB3-10864 --- phpBB/includes/controller/exception.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/controller/exception.php b/phpBB/includes/controller/exception.php index da2fefc600..faa8b6b584 100644 --- a/phpBB/includes/controller/exception.php +++ b/phpBB/includes/controller/exception.php @@ -19,6 +19,6 @@ if (!defined('IN_PHPBB')) * Controller exception class * @package phpBB3 */ -class phpbb_controller_provider extends RuntimeException +class phpbb_controller_exception extends RuntimeException { } From 120267e58030eb4b7184e0d54166dfc8d905c3f7 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:27:55 -0500 Subject: [PATCH 515/645] [feature/controller] Correctly access user object PHPBB3-10864 --- phpBB/includes/controller/resolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php index 0e724ec608..5674a65118 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/includes/controller/resolver.php @@ -115,7 +115,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface } else { - throw new phpbb_controller_exception($user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); + throw new phpbb_controller_exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); } } From e516680859744e69b696ac0054ec3aefd94175b7 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:28:35 -0500 Subject: [PATCH 516/645] [feature/controller] Use sizeof() instead of count() as per guidelines PHPBB3-10864 --- tests/controller/controller_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 577feee517..5a4c65e109 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -37,7 +37,7 @@ class phpbb_controller_test extends phpbb_test_case ->find('./tests/controller/'); // This will need to be updated if any new routes are defined - $this->assertEquals(2, count($routes)); + $this->assertEquals(2, sizeof($routes)); } public function test_controller_resolver() From 230897723c9e5fc5534d9781b04ffd8dac70d51b Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:29:35 -0500 Subject: [PATCH 517/645] [feature/controller] Reword comment for clarification PHPBB3-10864 --- tests/controller/controller_test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php index 5a4c65e109..198fb3c6dd 100644 --- a/tests/controller/controller_test.php +++ b/tests/controller/controller_test.php @@ -43,9 +43,8 @@ class phpbb_controller_test extends phpbb_test_case public function test_controller_resolver() { $container = new ContainerBuilder(); - // For some reason, I cannot get it to load more than one services - // file at a time, even when givein multiple paths - // So instead, I am looping through all of the paths + // YamlFileLoader only uses one path at a time, so we need to loop + // through all of the ones we are using. foreach (array(__DIR__.'/config', __DIR__.'/ext/foo/config') as $path) { $loader = new YamlFileLoader($container, new FileLocator($path)); @@ -53,7 +52,7 @@ class phpbb_controller_test extends phpbb_test_case } // Autoloading classes within the tests folder does not work - // so I'll include them manually + // so I'll include them manually. if (!class_exists('phpbb_ext_foo_controller')) { include(__DIR__.'/ext/foo/controller.php'); From 0c75d3d7da9c5fd7ee1560597db684c9d1704c22 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:30:50 -0500 Subject: [PATCH 518/645] [feature/controller] Add test for missing argument in controller class PHPBB3-10864 --- tests/functional/extension_controller_test.php | 10 +++++++++- .../functional/fixtures/ext/foo/bar/config/routing.yml | 4 ++++ .../fixtures/ext/foo/bar/controller/controller.php | 5 +++++ tests/functional/fixtures/ext/foo/bar/ext.php | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 2f07c8a70f..b1e910aeac 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -91,7 +91,15 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php/foo/bar'); $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); - $this->phpbb_extension_manager->purge('foobar'); + $this->phpbb_extension_manager->purge('foo/bar'); + } + + public function test_missing_argument() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = $this->request('GET', 'app.php/foo/baz'); + $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); } /** diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml index 7ecaba9e71..945ef51366 100755 --- a/tests/functional/fixtures/ext/foo/bar/config/routing.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -1,3 +1,7 @@ foo_bar_controller: pattern: /foo/bar defaults: { _controller: foo_bar.controller:handle } + +foo_baz_controller: + pattern: /foo/baz + defaults: { _controller: foo_bar.controller:baz } diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index 4c5274951f..def5184e8c 100755 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -7,4 +7,9 @@ class phpbb_ext_foo_bar_controller { return new Response('foo/bar controller handle() method', 200); } + + public function baz($test) + { + return new Response('Value of "test" URL argument is: ' . $test); + } } diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php index b50f95990e..7170209d53 100755 --- a/tests/functional/fixtures/ext/foo/bar/ext.php +++ b/tests/functional/fixtures/ext/foo/bar/ext.php @@ -1,6 +1,6 @@ Date: Fri, 16 Nov 2012 10:35:55 -0500 Subject: [PATCH 519/645] [feature/controller] Fix param block for controller callable PHPBB3-10864 --- phpBB/includes/controller/resolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php index 5674a65118..901aa7eaa0 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/includes/controller/resolver.php @@ -90,7 +90,7 @@ class phpbb_controller_resolver implements ControllerResolverInterface * controller. * * @param Symfony\Component\HttpFoundation\Request $request Symfony Request object - * @param string $controller Controller class name + * @param mixed $controller A callable (controller class, method) * @return bool False * @throws phpbb_controller_exception */ From d41b1146e8947919ed9bdd41e6a30ad15e91d262 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:37:07 -0500 Subject: [PATCH 520/645] [feature/controller] Rename $root_path class property to $phpbb_root_path PHPBB3-10864 --- phpBB/includes/controller/helper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 6b697c7e46..6dc3ec4626 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -39,7 +39,7 @@ class phpbb_controller_helper * phpBB root path * @var string */ - protected $root_path; + protected $phpbb_root_path; /** * PHP extension @@ -52,14 +52,14 @@ class phpbb_controller_helper * * @param phpbb_template $template Template object * @param phpbb_user $user User object - * @param string $root_path phpBB root path + * @param string $phpbb_root_path phpBB root path * @param string $php_ext PHP extension */ - public function __construct(phpbb_template $template, phpbb_user $user, $root_path, $php_ext) + public function __construct(phpbb_template $template, phpbb_user $user, $phpbb_root_path, $php_ext) { $this->template = $template; $this->user = $user; - $this->root_path = $root_path; + $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; } @@ -95,7 +95,7 @@ class phpbb_controller_helper */ public function url(array $url_parts, $query = '') { - return append_sid($this->root_path . implode('/', $url_parts), $query); + return append_sid($this->phpbb_root_path . implode('/', $url_parts), $query); } /** From 1952a4f276930edd16ca51fd690ed3e7965071da Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:38:40 -0500 Subject: [PATCH 521/645] [feature/controller] Flip method parameters, require $message PHPBB3-10864 --- phpBB/includes/controller/helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/controller/helper.php b/phpBB/includes/controller/helper.php index 6dc3ec4626..6cacc8fefa 100644 --- a/phpBB/includes/controller/helper.php +++ b/phpBB/includes/controller/helper.php @@ -101,11 +101,11 @@ class phpbb_controller_helper /** * Output an error, effectively the same thing as trigger_error * - * @param string $code The error code (e.g. 404, 500, 503, etc.) * @param string $message The error message + * @param string $code The error code (e.g. 404, 500, 503, etc.) * @return Response A Reponse instance */ - public function error($code = 500, $message = '') + public function error($message, $code = 500) { $this->template->assign_vars(array( 'MESSAGE_TEXT' => $message, From ba1acdca0364a9cd54c705d946fbae2144c59554 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 10:42:10 -0500 Subject: [PATCH 522/645] [feature/controller] Use warning instead of echo for copy() and unlink() PHPBB3-10864 --- tests/functional/extension_controller_test.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index b1e910aeac..65a9c80df6 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -46,10 +46,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c foreach (self::$fixtures as $fixture) { - if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture")) - { - echo 'Could not copy file ' . $fixture; - } + copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture"); } } @@ -62,10 +59,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c global $phpbb_root_path; foreach (self::$fixtures as $fixture) { - if (!unlink("{$phpbb_root_path}ext/$fixture")) - { - echo 'Could not delete file ' . $fixture; - } + unlink("{$phpbb_root_path}ext/$fixture"); } rmdir("{$phpbb_root_path}ext/foo/bar/config"); From 5b013ddf5c48e71166dcefd6d384aea1d801698a Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 11:41:05 -0500 Subject: [PATCH 523/645] [feature/controller] Add controller functional test with template PHPBB3-10864 --- .../functional/extension_controller_test.php | 32 ++++++++++++++++--- .../fixtures/ext/foo/bar/config/routing.yml | 4 +++ .../fixtures/ext/foo/bar/config/services.yml | 3 ++ .../ext/foo/bar/controller/controller.php | 15 +++++++++ .../prosilver/template/foo_bar_body.html | 3 ++ 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 65a9c80df6..9cc2e0e32f 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -18,7 +18,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c 'foo/bar/config/routing.yml', 'foo/bar/config/services.yml', 'foo/bar/controller/controller.php', - 'foo/bar/ext.php', + 'foo/bar/styles/prosilver/template/foo_bar_body.html', ); /** @@ -34,6 +34,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $phpbb_root_path . 'ext/foo/bar/', $phpbb_root_path . 'ext/foo/bar/config/', $phpbb_root_path . 'ext/foo/bar/controller/', + $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template', ); foreach ($directories as $dir) @@ -43,10 +44,12 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c mkdir($dir, 0777, true); } } - + foreach (self::$fixtures as $fixture) { - copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture"); + copy( + "tests/functional/fixtures/ext/$fixture", + "{$phpbb_root_path}ext/$fixture"); } } @@ -57,6 +60,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c static public function tearDownAfterClass() { global $phpbb_root_path; + foreach (self::$fixtures as $fixture) { unlink("{$phpbb_root_path}ext/$fixture"); @@ -64,6 +68,9 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c rmdir("{$phpbb_root_path}ext/foo/bar/config"); rmdir("{$phpbb_root_path}ext/foo/bar/controller"); + rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver/template"); + rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver"); + rmdir("{$phpbb_root_path}ext/foo/bar/styles"); rmdir("{$phpbb_root_path}ext/foo/bar"); rmdir("{$phpbb_root_path}ext/foo"); } @@ -78,7 +85,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } /** - * Check a controller for extension foo/bar + * Check a controller for extension foo/bar. */ public function test_foo_bar() { @@ -88,6 +95,21 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $this->phpbb_extension_manager->purge('foo/bar'); } + /** + * Check the output of a controller using the template system + */ + public function test_controller_with_template() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = $this->request('GET', 'app.php/foo/template'); + $this->assertContains("I am a variable", $crawler->filter('#content')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); + } + + /** + * Check the error produced by calling a controller without a required + * argument. + */ public function test_missing_argument() { $this->phpbb_extension_manager->enable('foo/bar'); @@ -97,7 +119,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c } /** - * Check the error produced by extension at ./ext/does/not/exist + * Check the error produced by extension at ./ext/does/not/exist. * * If an extension is disabled, its routes are not loaded. Because we * are not looking for a controller based on a specified extension, diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml index 945ef51366..123f5f1b73 100755 --- a/tests/functional/fixtures/ext/foo/bar/config/routing.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -5,3 +5,7 @@ foo_bar_controller: foo_baz_controller: pattern: /foo/baz defaults: { _controller: foo_bar.controller:baz } + +foo_template_controller: + pattern: /foo/template + defaults: { _controller: foo_bar.controller:template } diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml index d1db6fcb1d..33ced55af9 100755 --- a/tests/functional/fixtures/ext/foo/bar/config/services.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/services.yml @@ -1,3 +1,6 @@ services: foo_bar.controller: class: phpbb_ext_foo_bar_controller + arguments: + - @controller.helper + - @template diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index def5184e8c..50ea5d034b 100755 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -3,6 +3,14 @@ use Symfony\Component\HttpFoundation\Response; class phpbb_ext_foo_bar_controller { + protected $template; + + public function __construct(phpbb_controller_helper $helper, phpbb_template $template) + { + $this->template = $template; + $this->helper = $helper; + } + public function handle() { return new Response('foo/bar controller handle() method', 200); @@ -12,4 +20,11 @@ class phpbb_ext_foo_bar_controller { return new Response('Value of "test" URL argument is: ' . $test); } + + public function template() + { + $this->template->assign_var('A_VARIABLE', 'I am a variable'); + + return $this->helper->render('foo_bar_body.html'); + } } diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html new file mode 100644 index 0000000000..8fb6994d3d --- /dev/null +++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html @@ -0,0 +1,3 @@ + +
{A_VARIABLE}
+ From abf2575bdbad84ca2d139290789852ee51efd31c Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 13:04:12 -0500 Subject: [PATCH 524/645] [feature/controller] Remove URL rewriting by default PHPBB3-10864 --- phpBB/web.config | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/phpBB/web.config b/phpBB/web.config index e31a48b991..a73c328626 100644 --- a/phpBB/web.config +++ b/phpBB/web.config @@ -12,18 +12,6 @@ - - - - - - - - - - - - From 4efbb893b7b8ada8766847dc59724faef9c18142 Mon Sep 17 00:00:00 2001 From: David King Date: Fri, 16 Nov 2012 17:36:39 -0500 Subject: [PATCH 525/645] [feature/controller] Fix line endings and permissions, and check responses PHPBB3-10864 --- tests/functional/extension_controller_test.php | 4 ++++ .../fixtures/ext/foo/bar/config/routing.yml | 0 .../fixtures/ext/foo/bar/config/services.yml | 0 .../fixtures/ext/foo/bar/controller/controller.php | 0 tests/functional/fixtures/ext/foo/bar/ext.php | 12 ++++++------ 5 files changed, 10 insertions(+), 6 deletions(-) mode change 100755 => 100644 tests/functional/fixtures/ext/foo/bar/config/routing.yml mode change 100755 => 100644 tests/functional/fixtures/ext/foo/bar/config/services.yml mode change 100755 => 100644 tests/functional/fixtures/ext/foo/bar/controller/controller.php mode change 100755 => 100644 tests/functional/fixtures/ext/foo/bar/ext.php diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 9cc2e0e32f..ba4a4e8ef0 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -91,6 +91,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php/foo/bar'); + $this->assert_response_success(); $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -102,6 +103,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php/foo/template'); + $this->assert_response_success(); $this->assertContains("I am a variable", $crawler->filter('#content')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -114,6 +116,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php/foo/baz'); + $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } @@ -130,6 +133,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_error_ext_disabled_or_404() { $crawler = $this->request('GET', 'app.php/does/not/exist'); + $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } } diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml old mode 100755 new mode 100644 diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml old mode 100755 new mode 100644 diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php old mode 100755 new mode 100644 diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php old mode 100755 new mode 100644 index 7170209d53..74359d51ab --- a/tests/functional/fixtures/ext/foo/bar/ext.php +++ b/tests/functional/fixtures/ext/foo/bar/ext.php @@ -1,6 +1,6 @@ - Date: Sat, 17 Nov 2012 01:15:50 +0100 Subject: [PATCH 526/645] [ticket/11212] Do not rely on $request in send_status_line() PHPBB3-11212 --- phpBB/includes/functions.php | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3a5b100515..dd82c9dc46 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2858,8 +2858,6 @@ function meta_refresh($time, $url, $disable_cd_check = false) */ function send_status_line($code, $message) { - global $request; - if (substr(strtolower(@php_sapi_name()), 0, 3) === 'cgi') { // in theory, we shouldn't need that due to php doing it. Reality offers a differing opinion, though @@ -2867,18 +2865,35 @@ function send_status_line($code, $message) } else { - if ($request->server('SERVER_PROTOCOL')) - { - $version = $request->server('SERVER_PROTOCOL'); - } - else - { - $version = 'HTTP/1.0'; - } + $version = get_http_version(); header("$version $code $message", true, $code); } } +/** +* Returns the HTTP version used in the current request. +* +* Handles the case of being called before `$request` is present, +* In which case it falls back to the $_SERVER superglobal. +* +* @return string HTTP version +*/ +function get_http_version() +{ + global $request; + + if ($request && $request->server('SERVER_PROTOCOL')) + { + return $request->server('SERVER_PROTOCOL'); + } + else if (isset($_SERVER['SERVER_PROTOCOL'])) + { + return $_SERVER['SERVER_PROTOCOL']; + } + + return 'HTTP/1.0'; +} + //Form validation From 9cdef7984f5162fa19ce36852331f79de3561f66 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:17:23 +0100 Subject: [PATCH 527/645] [ticket/11212] Allow dispatcher to be absent during garbage_collection() PHPBB3-11212 --- phpBB/includes/functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index dd82c9dc46..4754d5194f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5348,7 +5348,9 @@ function garbage_collection() * @event core.garbage_collection * @since 3.1-A1 */ - $phpbb_dispatcher->dispatch('core.garbage_collection'); + if (!empty($phpbb_dispatcher)) { + $phpbb_dispatcher->dispatch('core.garbage_collection'); + } // Unload cache, must be done before the DB connection if closed if (!empty($cache)) From 98921e0b87b25fcd5985edb747d5768cd8ccf18e Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:17:45 +0100 Subject: [PATCH 528/645] [ticket/11213] Add missing global in install_update.php PHPBB3-11213 --- phpBB/install/install_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/install_update.php b/phpBB/install/install_update.php index 8c044550f3..7f40015002 100644 --- a/phpBB/install/install_update.php +++ b/phpBB/install/install_update.php @@ -71,7 +71,7 @@ class install_update extends module function main($mode, $sub) { - global $style, $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; + global $phpbb_style, $template, $phpEx, $phpbb_root_path, $user, $db, $config, $cache, $auth, $language; global $request; $this->tpl_name = 'install_update'; From b534a7a5790df55ab5f0d8aba8f40080d481bac4 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:25:14 +0100 Subject: [PATCH 529/645] [ticket/11212] Rename get_http_version to phpbb_request_http_version() PHPBB3-11212 --- phpBB/includes/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 4754d5194f..495f83e3a6 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2865,7 +2865,7 @@ function send_status_line($code, $message) } else { - $version = get_http_version(); + $version = phpbb_request_http_version(); header("$version $code $message", true, $code); } } @@ -2878,7 +2878,7 @@ function send_status_line($code, $message) * * @return string HTTP version */ -function get_http_version() +function phpbb_request_http_version() { global $request; From 1affc35be9a5ee2cdf2cd2551e708c928fb96d88 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:25:38 +0100 Subject: [PATCH 530/645] [ticket/11212] Cosmetics PHPBB3-11212 --- phpBB/includes/functions.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 495f83e3a6..dbc040e5fe 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2873,7 +2873,7 @@ function send_status_line($code, $message) /** * Returns the HTTP version used in the current request. * -* Handles the case of being called before `$request` is present, +* Handles the case of being called before $request is present, * In which case it falls back to the $_SERVER superglobal. * * @return string HTTP version @@ -5348,7 +5348,8 @@ function garbage_collection() * @event core.garbage_collection * @since 3.1-A1 */ - if (!empty($phpbb_dispatcher)) { + if (!empty($phpbb_dispatcher)) + { $phpbb_dispatcher->dispatch('core.garbage_collection'); } From b8cf74217aacb90ac066eee4e8812a2c32caa58a Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sat, 17 Nov 2012 01:32:40 +0100 Subject: [PATCH 531/645] [ticket/11212] Cosmetic surgery done right PHPBB3-11212 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index dbc040e5fe..ab4c7e1772 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2874,7 +2874,7 @@ function send_status_line($code, $message) * Returns the HTTP version used in the current request. * * Handles the case of being called before $request is present, -* In which case it falls back to the $_SERVER superglobal. +* in which case it falls back to the $_SERVER superglobal. * * @return string HTTP version */ From 8913b2c7c4ffc38d4caf34ca7014b8a07f11d19d Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 17 Nov 2012 17:48:20 -0500 Subject: [PATCH 532/645] [feature/controller] Use query string, not path info, for controller access This is hopefully just temporary until we can fix the relative path issue. PHPBB3-10864 --- phpBB/app.php | 8 ++++++++ phpBB/common.php | 7 ------- phpBB/includes/functions.php | 16 +--------------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/phpBB/app.php b/phpBB/app.php index f1023ff1b5..13bf3f0be1 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\HttpFoundation\Request; + /** */ @@ -24,6 +26,12 @@ $user->session_begin(); $auth->acl($user->data); $user->setup('app'); +// Until we fix the issue with relative paths, we have to fake path info to +// allow urls like app.php?controller=foo/bar +$controller = $request->variable('controller', '', false, phpbb_request_interface::GET); +$uri = '/' . $controller; +$symfony_request = Request::create($uri); + $http_kernel = $phpbb_container->get('http_kernel'); $response = $http_kernel->handle($symfony_request); $response->send(); diff --git a/phpBB/common.php b/phpBB/common.php index a5ffcea8e4..e99b9edee5 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -8,8 +8,6 @@ * Minimum Requirement: PHP 5.3.3 */ -use Symfony\Component\HttpFoundation\Request; - /** */ if (!defined('IN_PHPBB')) @@ -105,11 +103,6 @@ $phpbb_class_loader_ext->set_cache($phpbb_container->get('cache.driver')); // set up caching $cache = $phpbb_container->get('cache'); -// Instantiate the Symfony Request object -// This must be done before phpbb_request -// because otherwise globals are disabled -$symfony_request = Request::createFromGlobals(); - // Instantiate some basic classes $phpbb_dispatcher = $phpbb_container->get('dispatcher'); $request = $phpbb_container->get('request'); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 88ce142195..17fc16ef86 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2346,20 +2346,6 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } - // Make sure we have a Symfony Request object; tests do not have one - // unless they need it. - if ($symfony_request) - { - // Correct the path when we are accessing it through a controller - // This simply rewrites the value given by $phpbb_root_path to the - // script_path in config. - $path_info = $symfony_request->getPathInfo(); - if (!empty($path_info) && $path_info != '/') - { - $url = $config['script_path'] . '/' . substr($url, strlen($phpbb_root_path)); - } - } - $append_sid_overwrite = false; /** @@ -5056,7 +5042,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 // Determine board url - we may need it later $board_url = generate_board_url() . '/'; - $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $config['script_path'] . '/'; + $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $phpbb_root_path; // Send a proper content-language to the output $user_lang = $user->lang['USER_LANG']; From 4d6f6351dd0563b26105d15b98052d907f9c52ed Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 17 Nov 2012 18:05:32 -0500 Subject: [PATCH 533/645] [feature/controller] Allow injecting Symfony Request into controllers PHPBB3-10864 --- phpBB/includes/controller/resolver.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpBB/includes/controller/resolver.php b/phpBB/includes/controller/resolver.php index 901aa7eaa0..ee469aa9c8 100644 --- a/phpBB/includes/controller/resolver.php +++ b/phpBB/includes/controller/resolver.php @@ -109,6 +109,10 @@ class phpbb_controller_resolver implements ControllerResolverInterface { $arguments[] = $attributes[$param->name]; } + else if ($param->getClass() && $param->getClass()->isInstance($request)) + { + $arguments[] = $request; + } else if ($param->isDefaultValueAvailable()) { $arguments[] = $param->getDefaultValue(); From 7a3d9ed85dfd7f32a938070fff854e56bf39738e Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 13:11:24 -0500 Subject: [PATCH 534/645] [feature/controller] Fix functional tests to use query string for controllers PHPBB3-10864 --- tests/functional/extension_controller_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index ba4a4e8ef0..482fe9dfd3 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -90,7 +90,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_foo_bar() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php/foo/bar'); + $crawler = $this->request('GET', 'app.php?controller=foo/bar'); $this->assert_response_success(); $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -102,7 +102,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_controller_with_template() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php/foo/template'); + $crawler = $this->request('GET', 'app.php?controller=foo/template'); $this->assert_response_success(); $this->assertContains("I am a variable", $crawler->filter('#content')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -115,7 +115,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_missing_argument() { $this->phpbb_extension_manager->enable('foo/bar'); - $crawler = $this->request('GET', 'app.php/foo/baz'); + $crawler = $this->request('GET', 'app.php?controller=foo/baz'); $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); @@ -132,7 +132,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c */ public function test_error_ext_disabled_or_404() { - $crawler = $this->request('GET', 'app.php/does/not/exist'); + $crawler = $this->request('GET', 'app.php?controller=does/not/exist'); $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } From 09d7367dfc80f87b2fa36785a1e4285666c2d58a Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 13:32:54 -0500 Subject: [PATCH 535/645] [feature/controller] Remove url rewriting until we use pathinfo in controllers PHPBB3-10864 --- phpBB/.htaccess | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/phpBB/.htaccess b/phpBB/.htaccess index d0f65e345c..474f9774c2 100644 --- a/phpBB/.htaccess +++ b/phpBB/.htaccess @@ -1,34 +1,12 @@ - -# -# Uncomment the following line if you will be using any of the URL -# rewriting below. -# -#RewriteEngine on - # # Uncomment the statement below if you want to make use of # HTTP authentication and it does not already work. # This could be required if you are for example using PHP via Apache CGI. # +# +#RewriteEngine on #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] - -# -# Uncomment the following 3 lines if you want to rewrite URLs passed through -# the front controller to not use app.php in the actual URL. In other words, -# a controller is by default accessed at /app.php/my/controller, but will then -# be accessible at either /app.php/my/controller or just /my/controller -# -#RewriteCond %{REQUEST_FILENAME} !-f -#RewriteCond %{REQUEST_FILENAME} !-d -#RewriteRule ^(.*)$ app.php [QSA,L] - -# -# If symbolic links are not already being followed, -# uncomment the line below. -# http://anothersysadmin.wordpress.com/2008/06/10/mod_rewrite-forbidden-403-with-apache-228/ -# -#Options +FollowSymLinks - +# Order Allow,Deny From 53caf83233c962adbb68dcfb0f8172ebf788b8f7 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 13:35:04 -0500 Subject: [PATCH 536/645] [feature/controller] Remove now-unused code PHPBB3-10864 --- phpBB/includes/functions.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 17fc16ef86..02a9e33f2a 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,9 +7,6 @@ * */ -use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper; -use Symfony\Component\Routing\RequestContext; - /** * @ignore */ @@ -2338,7 +2335,7 @@ function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $star function append_sid($url, $params = false, $is_amp = true, $session_id = false) { global $_SID, $_EXTRA_URL, $phpbb_hook; - global $phpbb_dispatcher, $phpbb_root_path, $config, $symfony_request; + global $phpbb_dispatcher; if ($params === '' || (is_array($params) && empty($params))) { From 50a96a2a2d25734e3df451b0f821817213f085e6 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 13:40:24 -0500 Subject: [PATCH 537/645] [feature/controller] Update routing documentation for using query string PHPBB3-10864 --- phpBB/config/routing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/config/routing.yml b/phpBB/config/routing.yml index f6f728fa47..d8e890d063 100644 --- a/phpBB/config/routing.yml +++ b/phpBB/config/routing.yml @@ -4,6 +4,6 @@ # pattern: /foo # defaults: { _controller: foo_sevice:method } # -# The above will be accessed via app.php/foo and it will instantiate the -# "foo_service" service and call the "method" method. +# The above will be accessed via app.php?controller=foo and it will +# instantiate the "foo_service" service and call the "method" method. # From 440c66267ef768888617c211c7f05a5fd25e2378 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 18 Nov 2012 14:15:23 -0500 Subject: [PATCH 538/645] [ticket/11202] Add response assertions to file upload functional test. PHPBB3-11202 --- tests/functional/fileupload_form_test.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index f7267fa659..3db389b4f9 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -64,6 +64,9 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_valid_file() { $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); + $this->assert_response_success(); + # error message + $this->assertNotContains('

' . $this->lang('INFORMATION') . '

', $this->client->getResponse()->getContent()); $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); } } From 7ec94208c4096b752e77503ef53382e126b7dab5 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 18 Nov 2012 14:32:48 -0500 Subject: [PATCH 539/645] [ticket/11202] Fix comment char, use more descriptive comment. PHPBB3-11202 --- tests/functional/fileupload_form_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 3db389b4f9..99afcfdc3d 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -65,7 +65,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case { $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); $this->assert_response_success(); - # error message + // ensure there was no error message rendered $this->assertNotContains('

' . $this->lang('INFORMATION') . '

', $this->client->getResponse()->getContent()); $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text()); } From 60c0a1dd2ac2c733a670093ad440e3ba6be3be4d Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 15:51:05 -0500 Subject: [PATCH 540/645] [feature/controller] Don't use $user->lang() before container compilation PHPBB3-10864 --- phpBB/includes/di/pass/kernel_pass.php | 7 +++---- phpBB/language/en/app.php | 5 ----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/phpBB/includes/di/pass/kernel_pass.php b/phpBB/includes/di/pass/kernel_pass.php index d186ff2767..a701ebcfa6 100644 --- a/phpBB/includes/di/pass/kernel_pass.php +++ b/phpBB/includes/di/pass/kernel_pass.php @@ -29,7 +29,6 @@ class phpbb_di_pass_kernel_pass implements CompilerPassInterface public function process(ContainerBuilder $container) { $definition = $container->getDefinition('dispatcher'); - $user = $container->get('user'); foreach ($container->findTaggedServiceIds('kernel.event_listener') as $id => $events) { @@ -39,12 +38,12 @@ class phpbb_di_pass_kernel_pass implements CompilerPassInterface if (!isset($event['event'])) { - throw new InvalidArgumentException($user->lang('NO_EVENT_ATTRIBUTE', $id)); + throw new InvalidArgumentException(sprintf('Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', $id)); } if (!isset($event['method'])) { - throw new InvalidArgumentException($user->lang('NO_METHOD_ATTRIBUTE', $id)); + throw new InvalidArgumentException(sprintf('Service "%1$s" must define the "method" attribute on "kernel.event_listener" tags.', $id)); } $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority)); @@ -60,7 +59,7 @@ class phpbb_di_pass_kernel_pass implements CompilerPassInterface $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; if (!$refClass->implementsInterface($interface)) { - throw new InvalidArgumentException($user->lang('SUBSCRIBER_WRONG_TYPE', $id, $interface)); + throw new InvalidArgumentException(sprintf('Service "%1$s" must implement interface "%2$s".', $id, $interface)); } $definition->addMethodCall('addSubscriberService', array($id, $class)); diff --git a/phpBB/language/en/app.php b/phpBB/language/en/app.php index 2cbeaa2cba..2d67246369 100644 --- a/phpBB/language/en/app.php +++ b/phpBB/language/en/app.php @@ -47,11 +47,6 @@ $lang = array_merge($lang, array( 'CONTROLLER_SERVICE_UNDEFINED' => 'The service for controller "%s" is not defined in ./config/services.yml.', 'CONTROLLER_RETURN_TYPE_INVALID' => 'The controller object %s must return a Symfony\Component\HttpFoundation\Response object.', - // Event Listener/Subscriber error messages - 'NO_EVENT_ATTRIBUTE' => 'Service "%1$s" must define the "event" attribute on "kernel.event_listener" tags.', - 'NO_METHOD_ATTRIBUTE' => 'Service "%1$s" must define the "method" attribute on "kernel.event_listener" tags.', - 'SUBSCRIBER_WRONG_TYPE' => 'Service "%1$s" must implement interface "%2$s".', - // Core error controller messages 'PAGE_NOT_FOUND_ERROR' => 'The page you have requested does not exist.', 'NOT_AUTHORISED_ERROR' => 'You do not have permission to access this page.', From 2f50d656481dca3c2aa28cd5035ce0d44e5c4977 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 15:51:32 -0500 Subject: [PATCH 541/645] [feature/controller] Remove unused language strings PHPBB3-10864 --- phpBB/language/en/app.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/phpBB/language/en/app.php b/phpBB/language/en/app.php index 2d67246369..cb56015c30 100644 --- a/phpBB/language/en/app.php +++ b/phpBB/language/en/app.php @@ -46,10 +46,4 @@ $lang = array_merge($lang, array( 'CONTROLLER_SERVICE_NOT_GIVEN' => 'The controller "%s" must have a service specified in ./config/routing.yml.', 'CONTROLLER_SERVICE_UNDEFINED' => 'The service for controller "%s" is not defined in ./config/services.yml.', 'CONTROLLER_RETURN_TYPE_INVALID' => 'The controller object %s must return a Symfony\Component\HttpFoundation\Response object.', - - // Core error controller messages - 'PAGE_NOT_FOUND_ERROR' => 'The page you have requested does not exist.', - 'NOT_AUTHORISED_ERROR' => 'You do not have permission to access this page.', - 'NOT_AUTHENTICATED_ERROR' => 'You must log in to access this page.', - 'INTERNAL_SERVER_ERROR_ERROR' => 'An unknown error occured.', )); From 0f4f81b0966e29b5aaae5bf94e46260474ec0cb2 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 15:52:35 -0500 Subject: [PATCH 542/645] [feature/controller] Create Symfony Request in new function PHPBB3-10864 --- phpBB/app.php | 6 ++---- phpBB/includes/functions.php | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/phpBB/app.php b/phpBB/app.php index 13bf3f0be1..c085f966c8 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -7,8 +7,6 @@ * */ -use Symfony\Component\HttpFoundation\Request; - /** */ @@ -28,9 +26,9 @@ $user->setup('app'); // Until we fix the issue with relative paths, we have to fake path info to // allow urls like app.php?controller=foo/bar -$controller = $request->variable('controller', '', false, phpbb_request_interface::GET); +$controller = $request->variable('controller', ''); $uri = '/' . $controller; -$symfony_request = Request::create($uri); +$symfony_request = phpbb_create_symfony_request($uri, $request); $http_kernel = $phpbb_container->get('http_kernel'); $response = $http_kernel->handle($symfony_request); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 02a9e33f2a..820d96c9aa 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,6 +7,8 @@ * */ +use Symfony\Component\HttpFoundation\Request; + /** * @ignore */ @@ -5430,3 +5432,40 @@ function phpbb_to_numeric($input) { return ($input > PHP_INT_MAX) ? (float) $input : (int) $input; } + +/** +* Create a Symfony Request object from a given URI and phpbb_request object +* +* @param string $uri Request URI +* @param phpbb_request $request Request object +* @return Request A Symfony Request object +*/ +function phpbb_create_symfony_request($uri, phpbb_request $request) +{ + $request_method = $request->server('REQUEST_METHOD'); + $parameter_names = array(); + $parameter_names['request'] = array_merge( + $request->variable_names(phpbb_request_interface::GET), + // POST overwrites duplicated GET parameters + $request->variable_names(phpbb_request_interface::POST) + ); + $parameter_names['server'] = $request->variable_names(phpbb_request_interface::SERVER); + $parameter_names['files'] = $request->variable_names(phpbb_request_interface::FILES); + $parameter_names['cookie'] = $request->variable_names(phpbb_request_interface::COOKIE); + + $parameters = array( + 'request' => array(), + 'cookie' => array(), + 'files' => array(), + 'server' => array(), + ); + foreach ($parameter_names as $type => $names) + { + foreach ($names as $name) + { + $parameters[$type][$name] = $request->variable($name, ''); + } + } + + return Request::create($uri, $request_method, $parameters['request'], $parameters['cookie'], $parameters['files'], $parameters['server']); +} From e2bf66d0658ae7d7bb253083b73d5769c117746a Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 18 Nov 2012 15:58:47 -0500 Subject: [PATCH 543/645] [feature/controller] Add documentation about input being HTML-escaped PHPBB3-10864 --- phpBB/includes/functions.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 820d96c9aa..cdc05ca649 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5436,6 +5436,9 @@ function phpbb_to_numeric($input) /** * Create a Symfony Request object from a given URI and phpbb_request object * +* Note that everything passed into the Request object has already been HTML +* escaped by the phpbb_request object. +* * @param string $uri Request URI * @param phpbb_request $request Request object * @return Request A Symfony Request object From 41a95d2c646aba8d6a66ee046c532a51a9022784 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sun, 18 Nov 2012 20:38:58 -0600 Subject: [PATCH 544/645] [ticket/11219] Update sequence values after loading fixtures If a value is provide for an auto_increment type of column, certain DBMSes do not update their internal sequencers. If a row is inserted later, it can be given an ID that is already in use, resulting in an error. The database test cases now resynchronise the sequencers before the tests are run. PHPBB3-11219 --- .../phpbb_database_test_case.php | 10 ++ ...phpbb_database_test_connection_manager.php | 129 ++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 75a3c0944b..0916679108 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -28,6 +28,16 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test ); } + protected function setUp() + { + parent::setUp(); + + $config = $this->get_database_config(); + $manager = $this->create_connection_manager($config); + $manager->connect(); + $manager->post_setup_synchronisation(); + } + public function createXMLDataSet($path) { $db_config = $this->get_database_config(); diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index a43215bcf2..cae1720587 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -426,4 +426,133 @@ class phpbb_database_test_connection_manager $this->pdo->exec($query); } } + + /** + * Performs synchronisations on the database after a fixture has been loaded + */ + public function post_setup_synchronisation() + { + $this->ensure_connected(__METHOD__); + $queries = array(); + + switch ($this->config['dbms']) + { + case 'oracle': + // Get all of the information about the sequences + $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name + FROM USER_TRIGGERS t + JOIN USER_DEPENDENCIES d on d.name = t.trigger_name + JOIN USER_TRIGGER_COLS tc on (tc.trigger_name = t.trigger_name) + WHERE d.referenced_type = 'SEQUENCE' + AND d.type = 'TRIGGER'"; + $result = $this->pdo->query($sql); + + while ($row = $result->fetch(PDO::FETCH_ASSOC)) + { + // Get the current max value of the table + $sql = "SELECT MAX({$row['COLUMN_NAME']}) + 1 FROM {$row['TABLE_NAME']}"; + + $max_result = $this->pdo->query($sql); + $max_row = $max_result->fetch(PDO::FETCH_NUM); + + if (!$max_row) + { + continue; + } + + $maxval = current($max_row); + if ($maxval == null) + { + $maxval = 1; + } + + // Get the sequence's next value + $sql = "SELECT {$row['SEQUENCE_NAME']}.nextval FROM dual"; + try + { + $nextval_result = $this->pdo->query($sql); + } + catch (PDOException $e) + { + // If we catch an exception here it's because the sequencer hasn't been initialized yet. + // If the table hasn't been used, then there's nothing to do. + continue; + } + $nextval_row = $nextval_result->fetch(PDO::FETCH_NUM); + + if ($nextval_row) + { + $nextval = current($nextval_row); + + // Make sure we aren't setting the new increment to zero. + if ($maxval != $nextval) + { + // This is a multi-step process. First we need to get the sequence back into position. + // That means either advancing it or moving it backwards. Sequences have a minimum value + // of 1, so you cannot go past that. Once the offset it determined, you have to request + // the next sequence value to actually move the pointer into position. So if you're at 21 + // and need to be back at 1, set the incrementer to -20. When it's requested, it'll give + // you 1. Then we have to set the increment amount back to 1 to resume normal behavior. + + // Move the sequence to the correct position. + $sql = "ALTER SEQUENCE {$row['SEQUENCE_NAME']} INCREMENT BY " . ($maxval - $nextval); + $this->pdo->exec($sql); + + // Select the next value to actually update the sequence values + $sql = "SELECT {$row['SEQUENCE_NAME']}.nextval FROM dual"; + $this->pdo->query($sql); + + // Reset the sequence's increment amount + $sql = "ALTER SEQUENCE {$row['SEQUENCE_NAME']} INCREMENT BY 1"; + $this->pdo->exec($sql); + } + } + } + break; + + case 'postgres': + // First get the sequences + $sequences = array(); + $sql = "SELECT relname FROM pg_class WHERE relkind = 'S'"; + $result = $this->pdo->query($sql); + while ($row = $result->fetch(PDO::FETCH_ASSOC)) + { + $sequences[] = $row['relname']; + } + + // Now get the name of the column using it + foreach ($sequences as $sequence) + { + $table = str_replace('_seq', '', $sequence); + $sql = "SELECT column_name FROM information_schema.columns + WHERE table_name = '$table' + AND column_default = 'nextval(''$sequence''::regclass)'"; + $result = $this->pdo->query($sql); + $row = $result->fetch(PDO::FETCH_ASSOC); + + // Finally, set the new sequence value + if ($row) + { + $column = $row['column_name']; + + // Get the old value if it exists, or use 1 if it doesn't + $sql = "SELECT COALESCE((SELECT MAX({$column}) + 1 FROM {$table}), 1) AS val"; + $result = $this->pdo->query($sql); + $row = $result->fetch(PDO::FETCH_ASSOC); + + if ($row) + { + // The last parameter is false so that the system doesn't increment it again + $queries[] = "SELECT SETVAL('{$sequence}', {$row['val']}, false)"; + } + } + } + break; + } + + foreach ($queries as $query) + { + $this->pdo->exec($query); + } + } } From a7404409a8376e7db9f295e5cf598ccee59523b5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 19 Nov 2012 13:49:04 +0100 Subject: [PATCH 545/645] [ticket/11219] Add unit test for inserting into a sequence column PHPBB3-11219 --- tests/dbal/write_sequence_test.php | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/dbal/write_sequence_test.php diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php new file mode 100644 index 0000000000..d2c30b4e89 --- /dev/null +++ b/tests/dbal/write_sequence_test.php @@ -0,0 +1,55 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml'); + } + + static public function write_sequence_data() + { + return array( + array( + 'ticket/11219', + 4, + ), + ); + } + + /** + * @dataProvider write_sequence_data + */ + public function test_write_sequence($username, $expected) + { + $db = $this->new_dbal(); + + $sql = 'INSERT INTO phpbb_users ' . $db->sql_build_array('INSERT', array( + 'username' => $username, + 'username_clean' => $username, + 'user_permissions' => '', + 'user_sig' => '', + 'user_occ' => '', + 'user_interests' => '', + )); + $db->sql_query($sql); + + $this->assertEquals($expected, $db->sql_nextid()); + + $sql = "SELECT user_id + FROM phpbb_users + WHERE username_clean = '" . $db->sql_escape($username) . "'"; + $result = $db->sql_query_limit($sql, 1); + + $this->assertEquals($expected, $db->sql_fetchfield('user_id')); + } +} From 30043502814cd42d824dc1d6bcb25bebc60adbed Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 19 Nov 2012 11:47:42 -0500 Subject: [PATCH 546/645] [feature/controller] Correctly create Symfony object from globals PHPBB3-10864 --- phpBB/includes/functions.php | 62 ++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index cdc05ca649..ee147969f9 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -5434,41 +5434,47 @@ function phpbb_to_numeric($input) } /** -* Create a Symfony Request object from a given URI and phpbb_request object +* Create a Symfony Request object from phpbb_request object * -* Note that everything passed into the Request object has already been HTML -* escaped by the phpbb_request object. -* -* @param string $uri Request URI * @param phpbb_request $request Request object * @return Request A Symfony Request object */ -function phpbb_create_symfony_request($uri, phpbb_request $request) +function phpbb_create_symfony_request(phpbb_request $request) { - $request_method = $request->server('REQUEST_METHOD'); - $parameter_names = array(); - $parameter_names['request'] = array_merge( - $request->variable_names(phpbb_request_interface::GET), - // POST overwrites duplicated GET parameters - $request->variable_names(phpbb_request_interface::POST) - ); - $parameter_names['server'] = $request->variable_names(phpbb_request_interface::SERVER); - $parameter_names['files'] = $request->variable_names(phpbb_request_interface::FILES); - $parameter_names['cookie'] = $request->variable_names(phpbb_request_interface::COOKIE); + // This function is meant to sanitize the global input arrays + $sanitizer = function(&$value, $key) { + $type_cast_helper = new phpbb_request_type_cast_helper(); + $type_cast_helper->set_var($value, $value, gettype($value), true); + }; - $parameters = array( - 'request' => array(), - 'cookie' => array(), - 'files' => array(), - 'server' => array(), - ); - foreach ($parameter_names as $type => $names) + // We need to re-enable the super globals so we can access them here + $request->enable_super_globals(); + $get_parameters = $_GET; + $post_parameters = $_POST; + $server_parameters = $_SERVER; + $files_parameters = $_FILES; + $cookie_parameters = $_COOKIE; + // And now disable them again for security + $request->disable_super_globals(); + + array_walk_recursive($get_parameters, $sanitizer); + array_walk_recursive($post_parameters, $sanitizer); + + // Until we fix the issue with relative paths, we have to fake path info + // to allow urls like app.php?controller=foo/bar + $controller = $request->variable('controller', ''); + $path_info = '/' . $controller; + $request_uri = $server_parameters['REQUEST_URI']; + + // Remove the query string from REQUEST_URI + if ($pos = strpos($request_uri, '?')) { - foreach ($names as $name) - { - $parameters[$type][$name] = $request->variable($name, ''); - } + $request_uri = substr($request_uri, 0, $pos); } - return Request::create($uri, $request_method, $parameters['request'], $parameters['cookie'], $parameters['files'], $parameters['server']); + // Add the path info (i.e. controller route) to the REQUEST_URI + $server_parameters['REQUEST_URI'] = $request_uri . $path_info; + $server_parameters['SCRIPT_NAME'] = ''; + + return new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); } From f8614bfc84ba9b9cc814b8f78e343005620f18f8 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 19 Nov 2012 12:37:20 -0500 Subject: [PATCH 547/645] [feature/controller] Check for proper status codes from controllers PHPBB3-10864 --- phpBB/app.php | 7 +------ .../includes/event/kernel_exception_subscriber.php | 9 +++++++-- tests/functional/extension_controller_test.php | 13 ++++++++++++- .../fixtures/ext/foo/bar/config/routing.yml | 4 ++++ .../fixtures/ext/foo/bar/controller/controller.php | 5 +++++ 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/phpBB/app.php b/phpBB/app.php index c085f966c8..d93208d585 100644 --- a/phpBB/app.php +++ b/phpBB/app.php @@ -24,12 +24,7 @@ $user->session_begin(); $auth->acl($user->data); $user->setup('app'); -// Until we fix the issue with relative paths, we have to fake path info to -// allow urls like app.php?controller=foo/bar -$controller = $request->variable('controller', ''); -$uri = '/' . $controller; -$symfony_request = phpbb_create_symfony_request($uri, $request); - +$symfony_request = phpbb_create_symfony_request($request); $http_kernel = $phpbb_container->get('http_kernel'); $response = $http_kernel->handle($symfony_request); $response->send(); diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/includes/event/kernel_exception_subscriber.php index e2668d4560..e843df2e68 100644 --- a/phpBB/includes/event/kernel_exception_subscriber.php +++ b/phpBB/includes/event/kernel_exception_subscriber.php @@ -18,6 +18,7 @@ if (!defined('IN_PHPBB')) use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpFoundation\Response; class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterface @@ -56,9 +57,11 @@ class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterfac { page_header($this->user->lang('INFORMATION')); + $exception = $event->getException(); + $this->template->assign_vars(array( 'MESSAGE_TITLE' => $this->user->lang('INFORMATION'), - 'MESSAGE_TEXT' => $event->getException()->getMessage(), + 'MESSAGE_TEXT' => $exception->getMessage(), )); $this->template->set_filenames(array( @@ -67,7 +70,9 @@ class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterfac page_footer(true, false, false); - $response = new Response($this->template->assign_display('body'), 404); + + $status_code = $exception instanceof NotFoundHttpException ? $exception->getStatusCode() : 500; + $response = new Response($this->template->assign_display('body'), $status_code); $event->setResponse($response); } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index 482fe9dfd3..c7b585354e 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -116,11 +116,20 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php?controller=foo/baz'); - $this->assertEquals(404, $this->client->getResponse()->getStatus()); + $this->assertEquals(500, $this->client->getResponse()->getStatus()); $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); $this->phpbb_extension_manager->purge('foo/bar'); } + public function test_exception_thrown_status_code() + { + $this->phpbb_extension_manager->enable('foo/bar'); + $crawler = $this->request('GET', 'app.php?controller=foo/exception'); + $this->assertEquals(500, $this->client->getResponse()->getStatus()); + $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); + } + /** * Check the error produced by extension at ./ext/does/not/exist. * @@ -133,6 +142,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_error_ext_disabled_or_404() { $crawler = $this->request('GET', 'app.php?controller=does/not/exist'); + // This is 500 response because the exception is thrown from within Symfony + // and does not provide a exception code, so we assign it 500 by default $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml index 123f5f1b73..7eb604f746 100644 --- a/tests/functional/fixtures/ext/foo/bar/config/routing.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -9,3 +9,7 @@ foo_baz_controller: foo_template_controller: pattern: /foo/template defaults: { _controller: foo_bar.controller:template } + +foo_exception_controller: + pattern: /foo/foo_exception + defaults: { _controller: foo_bar.controller:exception } diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php index 50ea5d034b..5a91b5f681 100644 --- a/tests/functional/fixtures/ext/foo/bar/controller/controller.php +++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php @@ -27,4 +27,9 @@ class phpbb_ext_foo_bar_controller return $this->helper->render('foo_bar_body.html'); } + + public function exception() + { + throw new phpbb_controller_exception('Exception thrown from foo/exception route'); + } } From 01ec6085939d74e6a37c3ef041434db1c4b8f3e4 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 19 Nov 2012 12:55:15 -0500 Subject: [PATCH 548/645] [feature/controller] Fix comments, check against more general HttpException PHPBB3-10864 --- phpBB/includes/event/kernel_exception_subscriber.php | 4 ++-- tests/functional/extension_controller_test.php | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/event/kernel_exception_subscriber.php b/phpBB/includes/event/kernel_exception_subscriber.php index e843df2e68..f90989a74c 100644 --- a/phpBB/includes/event/kernel_exception_subscriber.php +++ b/phpBB/includes/event/kernel_exception_subscriber.php @@ -18,7 +18,7 @@ if (!defined('IN_PHPBB')) use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpFoundation\Response; class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterface @@ -71,7 +71,7 @@ class phpbb_event_kernel_exception_subscriber implements EventSubscriberInterfac page_footer(true, false, false); - $status_code = $exception instanceof NotFoundHttpException ? $exception->getStatusCode() : 500; + $status_code = $exception instanceof HttpException ? $exception->getStatusCode() : 500; $response = new Response($this->template->assign_display('body'), $status_code); $event->setResponse($response); } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index c7b585354e..f28b321942 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -121,7 +121,10 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $this->phpbb_extension_manager->purge('foo/bar'); } - public function test_exception_thrown_status_code() + /** + * Check the status code resulting from an exception thrown by a controller + */ + public function test_exception_should_result_in_500_status_code() { $this->phpbb_extension_manager->enable('foo/bar'); $crawler = $this->request('GET', 'app.php?controller=foo/exception'); @@ -142,8 +145,6 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c public function test_error_ext_disabled_or_404() { $crawler = $this->request('GET', 'app.php?controller=does/not/exist'); - // This is 500 response because the exception is thrown from within Symfony - // and does not provide a exception code, so we assign it 500 by default $this->assertEquals(404, $this->client->getResponse()->getStatus()); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); } From 305f41cf1a540984fd7a71b61a601b1794e3bd04 Mon Sep 17 00:00:00 2001 From: David King Date: Mon, 19 Nov 2012 13:16:55 -0500 Subject: [PATCH 549/645] [feature/controller] Fix misnamed route for functional test PHPBB3-10864 --- tests/functional/fixtures/ext/foo/bar/config/routing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml index 7eb604f746..09a30a8c67 100644 --- a/tests/functional/fixtures/ext/foo/bar/config/routing.yml +++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml @@ -11,5 +11,5 @@ foo_template_controller: defaults: { _controller: foo_bar.controller:template } foo_exception_controller: - pattern: /foo/foo_exception + pattern: /foo/exception defaults: { _controller: foo_bar.controller:exception } From 1dff6d1bf988bb0d11a393fad0c0d0183366a5c9 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Tue, 20 Nov 2012 04:40:06 -0600 Subject: [PATCH 550/645] [ticket/11219] Recreate Oracle sequences instead of altering them The previous method would always leave a gap between the last value and the new one due to how you have to update the sequence values. To remove gaps in all situations, the options are to alter the USER_SEQUENCES table or just drop the sequence and recreate it. The prior requires elevated priveleges and the latter can break attached objects. Since we don't attach objects to the sequences, we won't have any problems doing it for the tests. PHPBB3-11219 --- ...phpbb_database_test_connection_manager.php | 69 +++++-------------- 1 file changed, 17 insertions(+), 52 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index cae1720587..e79a764e1d 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -439,10 +439,11 @@ class phpbb_database_test_connection_manager { case 'oracle': // Get all of the information about the sequences - $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name + $sql = "SELECT t.table_name, tc.column_name, d.referenced_name as sequence_name, s.increment_by, s.min_value FROM USER_TRIGGERS t - JOIN USER_DEPENDENCIES d on d.name = t.trigger_name - JOIN USER_TRIGGER_COLS tc on (tc.trigger_name = t.trigger_name) + JOIN USER_DEPENDENCIES d ON (d.name = t.trigger_name) + JOIN USER_TRIGGER_COLS tc ON (tc.trigger_name = t.trigger_name) + JOIN USER_SEQUENCES s ON (s.sequence_name = d.referenced_name) WHERE d.referenced_type = 'SEQUENCE' AND d.type = 'TRIGGER'"; $result = $this->pdo->query($sql); @@ -450,63 +451,27 @@ class phpbb_database_test_connection_manager while ($row = $result->fetch(PDO::FETCH_ASSOC)) { // Get the current max value of the table - $sql = "SELECT MAX({$row['COLUMN_NAME']}) + 1 FROM {$row['TABLE_NAME']}"; - + $sql = "SELECT MAX({$row['COLUMN_NAME']}) AS max FROM {$row['TABLE_NAME']}"; $max_result = $this->pdo->query($sql); - $max_row = $max_result->fetch(PDO::FETCH_NUM); + $max_row = $max_result->fetch(PDO::FETCH_ASSOC); if (!$max_row) { continue; } - $maxval = current($max_row); - if ($maxval == null) - { - $maxval = 1; - } + $maxval = (int)$max_row['MAX']; + $maxval++; - // Get the sequence's next value - $sql = "SELECT {$row['SEQUENCE_NAME']}.nextval FROM dual"; - try - { - $nextval_result = $this->pdo->query($sql); - } - catch (PDOException $e) - { - // If we catch an exception here it's because the sequencer hasn't been initialized yet. - // If the table hasn't been used, then there's nothing to do. - continue; - } - $nextval_row = $nextval_result->fetch(PDO::FETCH_NUM); - - if ($nextval_row) - { - $nextval = current($nextval_row); - - // Make sure we aren't setting the new increment to zero. - if ($maxval != $nextval) - { - // This is a multi-step process. First we need to get the sequence back into position. - // That means either advancing it or moving it backwards. Sequences have a minimum value - // of 1, so you cannot go past that. Once the offset it determined, you have to request - // the next sequence value to actually move the pointer into position. So if you're at 21 - // and need to be back at 1, set the incrementer to -20. When it's requested, it'll give - // you 1. Then we have to set the increment amount back to 1 to resume normal behavior. - - // Move the sequence to the correct position. - $sql = "ALTER SEQUENCE {$row['SEQUENCE_NAME']} INCREMENT BY " . ($maxval - $nextval); - $this->pdo->exec($sql); - - // Select the next value to actually update the sequence values - $sql = "SELECT {$row['SEQUENCE_NAME']}.nextval FROM dual"; - $this->pdo->query($sql); - - // Reset the sequence's increment amount - $sql = "ALTER SEQUENCE {$row['SEQUENCE_NAME']} INCREMENT BY 1"; - $this->pdo->exec($sql); - } - } + // This is not the "proper" way, but the proper way does not allow you to completely reset + // tables with no rows since you have to select the next value to make the change go into effct. + // You would have to go past the minimum value to set it correctly, but that's illegal. + // Since we have no objects attached to our sequencers (triggers aren't attached), this works fine. + $queries[] = 'DROP SEQUENCE ' . $row['SEQUENCE_NAME']; + $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']} + MINVALUE {$row['MIN_VALUE']} + INCREMENT BY {$row['INCREMENT_BY']} + START WITH $maxval"; } break; From 24939c822529f179a436abfa4e4e2f1b5bcb53ec Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sat, 4 Feb 2012 17:29:10 +0000 Subject: [PATCH 551/645] [ticket/10601]Move Inbox the default in private messages module Did exactly as the answer here asked: http://area51.phpbb.com/phpBB/viewtopic.php?p=234111 PHPBB3-10601 --- phpBB/includes/functions_module.php | 20 +++++++++++++++++++- phpBB/install/install_install.php | 17 +++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index ad76be9f2f..6f38dc60ce 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -759,7 +759,25 @@ class p_master } } - $u_title = $module_url . $delim . 'i=' . (($item_ary['cat']) ? $item_ary['id'] : $item_ary['name'] . (($item_ary['is_duplicate']) ? '&icat=' . $current_id : '') . '&mode=' . $item_ary['mode']); + $u_title = $module_url . $delim . 'i='; + // if the item has a name use it, else use its id + if (empty($item_ary['name'])) + { + $u_title .= $item_ary['id']; + } + else + { + $u_title .= $item_ary['name']; + } + // If the item is not a category append the mode + if (!$item_ary['cat']) + { + if ($item_ary['is_duplicate']) + { + $u_title .= '&icat=' . $current_id; + } + $u_title .= '&mode=' . $item_ary['mode']; + } // Was not allowed in categories before - /*!$item_ary['cat'] && */ $u_title .= (isset($item_ary['url_extra'])) ? $item_ary['url_extra'] : ''; diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index f80b8b5661..d4eba6eefd 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1478,8 +1478,13 @@ class install_install extends module foreach ($this->module_categories[$module_class] as $cat_name => $subs) { + $basename = ''; + if (isset($module_categories_basenames[$cat_name])) + { + $basename = $module_categories_basenames[$cat_name]; + } $module_data = array( - 'module_basename' => '', + 'module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => 0, @@ -1507,8 +1512,13 @@ class install_install extends module { foreach ($subs as $level2_name) { + $basename = ''; + if (isset($module_categories_basenames[$level2_name])) + { + $basename = $module_categories_basenames[$level2_name]; + } $module_data = array( - 'module_basename' => '', + 'module_basename' => $basename, 'module_enabled' => 1, 'module_display' => 1, 'parent_id' => (int) $categories[$cat_name]['id'], @@ -2115,6 +2125,9 @@ class install_install extends module 'UCP_ZEBRA' => null, ), ); + var $module_categories_basenames = array( + 'UCP_PM' => 'ucp_pm', + ); var $module_extras = array( 'acp' => array( From 61842c317a0d91278ef5d9bebe0f134be1a6d8f9 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 4 Feb 2012 20:07:21 -0500 Subject: [PATCH 552/645] [ticket/10601] Correctly access class property PHPBB3-10601 --- phpBB/install/install_install.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index d4eba6eefd..4b3d78f656 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1479,9 +1479,9 @@ class install_install extends module foreach ($this->module_categories[$module_class] as $cat_name => $subs) { $basename = ''; - if (isset($module_categories_basenames[$cat_name])) + if (isset($this->module_categories_basenames[$cat_name])) { - $basename = $module_categories_basenames[$cat_name]; + $basename = $this->module_categories_basenames[$cat_name]; } $module_data = array( 'module_basename' => $basename, @@ -1513,9 +1513,9 @@ class install_install extends module foreach ($subs as $level2_name) { $basename = ''; - if (isset($module_categories_basenames[$level2_name])) + if (isset($this->module_categories_basenames[$level2_name])) { - $basename = $module_categories_basenames[$level2_name]; + $basename = $this->module_categories_basenames[$level2_name]; } $module_data = array( 'module_basename' => $basename, From 81547ba980a09832240ab3523448a159f2d514e1 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 1 Aug 2012 15:54:42 +0100 Subject: [PATCH 553/645] [ticket/10601] Comment explaning the basename applied to categories Explain in the code where if (isset($this->module_categories_basenames[$cat_name])) and if (isset($this->module_categories_basenames[$level2_name])) exists, what does it do. PHPBB3-10601 --- phpBB/install/install_install.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 4b3d78f656..33d6586e48 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1479,6 +1479,7 @@ class install_install extends module foreach ($this->module_categories[$module_class] as $cat_name => $subs) { $basename = ''; + // Check if this sub-category has a basename. If it has, use it. if (isset($this->module_categories_basenames[$cat_name])) { $basename = $this->module_categories_basenames[$cat_name]; @@ -1513,6 +1514,7 @@ class install_install extends module foreach ($subs as $level2_name) { $basename = ''; + // Check if this sub-category has a basename. If it has, use it. if (isset($this->module_categories_basenames[$level2_name])) { $basename = $this->module_categories_basenames[$level2_name]; From 80da19ca7c12feb2996fd9d64dbdc8cb5c3cd2d9 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 7 Nov 2012 09:13:16 +0000 Subject: [PATCH 554/645] [ticket/10601] Database updating code This is what is needed to update the database to comply with these code changes PHPBB3-10601 --- phpBB/install/database_update.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 377e38c423..7b20404cf2 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2749,6 +2749,33 @@ function change_database_data(&$no_updates, $version) $config->set('site_home_url', ''); $config->set('site_home_text', ''); } + + + // ticket/10601: Make inbox default. Add basename to ucp's pm category + // Check if this was already applied + $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id + FROM ' . MODULES_TABLE . ' + WHERE + module_basename = \'ucp_pm\' + ORDER BY module_id'; + $result = $db->sql_query_limit($sql, 1); + + if ($row = $db->sql_fetchrow($result)) + { + // Checking if this is not a category + if ($row['left_id'] === $row['right_id'] - 1) + { + // This update is still not applied. Applying it + + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_basename = \'ucp_pm\' + WHERE module_id = ' . (int)$row['parent_id']; + + _sql($sql, $errored, $error_ary); + + } + } + $db->sql_freeresult($result); break; } From 85ebbbaec471ea64f22543e006f8c160b02d503f Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 7 Nov 2012 22:26:54 +0000 Subject: [PATCH 555/645] [ticket/10601] Database updating code v2 Added the space after the (int) as requested PHPBB3-10601 --- phpBB/install/database_update.php | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 7b20404cf2..620af92173 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2753,29 +2753,29 @@ function change_database_data(&$no_updates, $version) // ticket/10601: Make inbox default. Add basename to ucp's pm category // Check if this was already applied - $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id - FROM ' . MODULES_TABLE . ' - WHERE - module_basename = \'ucp_pm\' - ORDER BY module_id'; - $result = $db->sql_query_limit($sql, 1); + $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id + FROM ' . MODULES_TABLE . ' + WHERE + module_basename = \'ucp_pm\' + ORDER BY module_id'; + $result = $db->sql_query_limit($sql, 1); - if ($row = $db->sql_fetchrow($result)) + if ($row = $db->sql_fetchrow($result)) + { + // Checking if this is not a category + if ($row['left_id'] === $row['right_id'] - 1) { - // Checking if this is not a category - if ($row['left_id'] === $row['right_id'] - 1) - { - // This update is still not applied. Applying it - - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_basename = \'ucp_pm\' - WHERE module_id = ' . (int)$row['parent_id']; - - _sql($sql, $errored, $error_ary); + // This update is still not applied. Applying it - } + $sql = 'UPDATE ' . MODULES_TABLE . ' + SET module_basename = \'ucp_pm\' + WHERE module_id = ' . (int) $row['parent_id']; + + _sql($sql, $errored, $error_ary); + } - $db->sql_freeresult($result); + } + $db->sql_freeresult($result); break; } From 1f9eaa1c56ec909bde82e1d7ad86079cd23f46bc Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Fri, 9 Nov 2012 08:51:18 +0000 Subject: [PATCH 556/645] [ticket/10601] Cosmetic code changes - Removed the double line before the addition - Moved the condition of the WHERE so that both are in the same line - Removed TABs from the black lines - Used double quotes instead of escaped single quotes. PHPBB3-10601 --- phpBB/install/database_update.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 620af92173..1dae3e566b 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2749,14 +2749,12 @@ function change_database_data(&$no_updates, $version) $config->set('site_home_url', ''); $config->set('site_home_text', ''); } - - + // ticket/10601: Make inbox default. Add basename to ucp's pm category // Check if this was already applied $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id FROM ' . MODULES_TABLE . ' - WHERE - module_basename = \'ucp_pm\' + WHERE module_basename = "ucp_pm" ORDER BY module_id'; $result = $db->sql_query_limit($sql, 1); @@ -2766,13 +2764,13 @@ function change_database_data(&$no_updates, $version) if ($row['left_id'] === $row['right_id'] - 1) { // This update is still not applied. Applying it - + $sql = 'UPDATE ' . MODULES_TABLE . ' SET module_basename = \'ucp_pm\' WHERE module_id = ' . (int) $row['parent_id']; - + _sql($sql, $errored, $error_ary); - + } } $db->sql_freeresult($result); From 764da977729aef331241d0cf0df77bd2e29d6256 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:41:58 +0100 Subject: [PATCH 557/645] [ticket/11174] include utf_tools in mysql backend when running tests include utf_tools file in the mysql search backend PHPBB3-11174 --- phpBB/includes/search/fulltext_mysql.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 58a4dd7d6a..cd5f0cef67 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -86,6 +86,14 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $this->word_length = array('min' => $this->config['fulltext_mysql_min_word_len'], 'max' => $this->config['fulltext_mysql_max_word_len']); + /** + * Load the UTF tools + */ + if (!function_exists('utf8_strlen')) + { + include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + } + $error = false; } From 6e8f142d3994f4568e40447d7cfd60cb5b082824 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:43:13 +0100 Subject: [PATCH 558/645] [ticket/11174] removes unnecessary space from word PHPBB3-11174 --- phpBB/includes/search/fulltext_mysql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index cd5f0cef67..ff2e24aa05 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -238,7 +238,7 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } else { - $tmp_split_words[] = $word . ' '; + $tmp_split_words[] = $word; } } if ($phrase) From 6a76b85cbc741ef15c219c2c02c318bc43f29a59 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:46:15 +0100 Subject: [PATCH 559/645] [ticket/11174] add mysql unit tests PHPBB3-11174 --- tests/search/mysql_test.php | 155 ++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/search/mysql_test.php diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php new file mode 100644 index 0000000000..d9da2dfb2d --- /dev/null +++ b/tests/search/mysql_test.php @@ -0,0 +1,155 @@ +split_words; } +} + "; + eval($code); + } + return $wrapped; +} + +class phpbb_search_mysql_test extends phpbb_database_test_case +{ + protected $db; + protected $search; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + } + + protected function setUp() + { + global $phpbb_root_path, $phpEx, $config, $user, $cache; + + parent::setUp(); + + // dbal uses cache + $cache = new phpbb_cache_driver_null; + + $this->db = $this->new_dbal(); + $error = null; + $class = phpbb_search_wrapper('phpbb_search_fulltext_mysql'); + $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); + } + + protected function tearDown() + { + parent::tearDown(); + } + + public function keywords() + { + return array( + // keywords + // terms + // ok + // split words + // common words + array( + 'fooo', + 'all', + true, + array('fooo'), + array(), + ), + array( + 'fooo baar', + 'all', + true, + array('fooo', 'baar'), + array(), + ), + // leading, trailing and multiple spaces + array( + ' foo bar ', + 'all', + true, + array('foo', 'bar'), + array(), + ), + // words too short + array( + 'f', + 'all', + false, + null, + // short words count as "common" words + array('f'), + ), + array( + 'f o o', + 'all', + false, + null, + array('f', 'o', 'o'), + ), + array( + 'foo -bar', + 'all', + true, + array('-bar', 'foo'), + array(), + ), + // all negative + array( + '-foo', + 'all', + false, + null, + array(), + ), + array( + '-foo -bar', + 'all', + false, + array('-foo', '-bar'), + array(), + ), + ); + } + + /** + * @dataProvider keywords + */ + public function test_split_keywords($keywords, $terms, $ok, $split_words, $common) + { + $rv = $this->search->split_keywords($keywords, $terms); + $this->assertEquals($ok, $rv); + if ($ok) + { + // only check criteria if the search is going to be performed + $this->assert_array_content_equals($split_words, $this->search->get_split_words()); + } + $this->assert_array_content_equals($common, $this->search->get_common_words()); + } + + public function assert_array_content_equals($one, $two) + { + if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) + { + // get a nice error message + $this->assertEquals($one, $two); + } + else + { + // increase assertion count + $this->assertTrue(true); + } + } +} From 615582f0dffc8d50604e3cc567e01e807a397bec Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 13:47:33 +0100 Subject: [PATCH 560/645] [ticket/11174] rename native wrapper class native wrapper class is limited to the native search backend hence renamed. the one used with mysql can be used with pgsql too. PHPBB3-11174 --- tests/search/native_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 66972079cf..722da9eb59 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -7,7 +7,7 @@ * */ -function phpbb_search_wrapper($class) +function phpbb_native_search_wrapper($class) { $wrapped = $class . '_wrapper'; if (!class_exists($wrapped)) @@ -45,7 +45,7 @@ class phpbb_search_native_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $error = null; - $class = phpbb_search_wrapper('phpbb_search_fulltext_native'); + $class = phpbb_native_search_wrapper('phpbb_search_fulltext_native'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } From 2d1ac34de60a15e0b9e00a30140a08b4e329099d Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 14:19:32 +0100 Subject: [PATCH 561/645] [ticket/11174] add test case for native test PHPBB3-11174 --- tests/search/native_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 722da9eb59..5f6d49c26c 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -106,6 +106,14 @@ class phpbb_search_native_test extends phpbb_database_test_case null, array('f', 'o', 'o'), ), + array( + 'f -o -o', + 'all', + false, + null, + null, + array('f', 'o', 'o'), + ), array( 'foo -bar', 'all', From 9d597dc2ee152f448139dc708663f9a81e5cb209 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 16:22:10 +0100 Subject: [PATCH 562/645] [ticket/11174] set config values set config values and use min length as 4 for wordss in test cases PHPBB3-11174 --- tests/search/mysql_test.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index d9da2dfb2d..44043da40d 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -42,6 +42,10 @@ class phpbb_search_mysql_test extends phpbb_database_test_case // dbal uses cache $cache = new phpbb_cache_driver_null; + // set config values + $config['fulltext_mysql_min_word_len'] = 4; + $config['fulltext_mysql_max_word_len'] = 254; + $this->db = $this->new_dbal(); $error = null; $class = phpbb_search_wrapper('phpbb_search_fulltext_mysql'); @@ -77,10 +81,10 @@ class phpbb_search_mysql_test extends phpbb_database_test_case ), // leading, trailing and multiple spaces array( - ' foo bar ', + ' fooo baar ', 'all', true, - array('foo', 'bar'), + array('fooo', 'baar'), array(), ), // words too short @@ -100,25 +104,32 @@ class phpbb_search_mysql_test extends phpbb_database_test_case array('f', 'o', 'o'), ), array( - 'foo -bar', + 'f -o -o', + 'all', + false, + null, + array('f', '-o', '-o'), + ), + array( + 'fooo -baar', 'all', true, - array('-bar', 'foo'), + array('-baar', 'fooo'), array(), ), // all negative array( - '-foo', + '-fooo', 'all', false, null, array(), ), array( - '-foo -bar', + '-fooo -baar', 'all', false, - array('-foo', '-bar'), + array('-fooo', '-baar'), array(), ), ); From db2297827d92f09e52cd2dd6f6b4613e0c210fe7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 16:25:44 +0100 Subject: [PATCH 563/645] [ticket/11174] negation queries do not return false negation queries are split into words too and returns false in mysql search backend PHPBB3-11174 --- tests/search/mysql_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 44043da40d..56cce24c09 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -121,14 +121,14 @@ class phpbb_search_mysql_test extends phpbb_database_test_case array( '-fooo', 'all', - false, - null, + true, + array('-fooo'), array(), ), array( '-fooo -baar', 'all', - false, + true, array('-fooo', '-baar'), array(), ), From c725b02df8a6d8838f6e0b7d82eaa8ec8f1839d1 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 17:05:07 +0100 Subject: [PATCH 564/645] [ticket/11174] include utf_tools in postgres search backend PHPBB3-11174 --- phpBB/includes/search/fulltext_postgres.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 08f64735b6..2880610655 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -121,6 +121,14 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } } + /** + * Load the UTF tools + */ + if (!function_exists('utf8_strlen')) + { + include($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); + } + $error = false; } From d308ee8a25ec6dc7b6e23cb78e14bd1d75f05a91 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 12 Nov 2012 17:06:05 +0100 Subject: [PATCH 565/645] [ticket/11174] add unit tests for postgres search backend PHPBB3-11174 --- tests/search/postgres_test.php | 155 +++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 tests/search/postgres_test.php diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php new file mode 100644 index 0000000000..e20e6789b7 --- /dev/null +++ b/tests/search/postgres_test.php @@ -0,0 +1,155 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + } + + protected function setUp() + { + global $phpbb_root_path, $phpEx, $config, $user, $cache; + + parent::setUp(); + + // dbal uses cache + $cache = new phpbb_cache_driver_null; + + // set config values + $config['fulltext_postgres_min_word_len'] = 4; + $config['fulltext_postgres_max_word_len'] = 254; + + if(!function_exists('phpbb_search_wrapper')) + { + include('mysql_test.' . $phpEx); + } + + $this->db = $this->new_dbal(); + $error = null; + $class = phpbb_search_wrapper('phpbb_search_fulltext_postgres'); + $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); + } + + protected function tearDown() + { + parent::tearDown(); + } + + public function keywords() + { + return array( + // keywords + // terms + // ok + // split words + // common words + array( + 'fooo', + 'all', + true, + array('fooo'), + array(), + ), + array( + 'fooo baar', + 'all', + true, + array('fooo', 'baar'), + array(), + ), + // leading, trailing and multiple spaces + array( + ' fooo baar ', + 'all', + true, + array('fooo', 'baar'), + array(), + ), + // words too short + array( + 'f', + 'all', + false, + null, + // short words count as "common" words + array('f'), + ), + array( + 'f o o', + 'all', + false, + null, + array('f', 'o', 'o'), + ), + array( + 'f -o -o', + 'all', + false, + null, + array('f', '-o', '-o'), + ), + array( + 'fooo -baar', + 'all', + true, + array('-baar', 'fooo'), + array(), + ), + // all negative + array( + '-fooo', + 'all', + true, + array('-fooo'), + array(), + ), + array( + '-fooo -baar', + 'all', + true, + array('-fooo', '-baar'), + array(), + ), + ); + } + + /** + * @dataProvider keywords + */ + public function test_split_keywords($keywords, $terms, $ok, $split_words, $common) + { + $rv = $this->search->split_keywords($keywords, $terms); + $this->assertEquals($ok, $rv); + if ($ok) + { + // only check criteria if the search is going to be performed + $this->assert_array_content_equals($split_words, $this->search->get_split_words()); + } + $this->assert_array_content_equals($common, $this->search->get_common_words()); + } + + public function assert_array_content_equals($one, $two) + { + if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) + { + // get a nice error message + $this->assertEquals($one, $two); + } + else + { + // increase assertion count + $this->assertTrue(true); + } + } +} From 3ed4fc437e2a88638d705b8f4cab23eacf39fe3c Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:08:34 -0500 Subject: [PATCH 566/645] [ticket/11174] Move assertion definition to base class. PHPBB3-11174 --- tests/search/native_test.php | 16 ---------------- .../test_framework/phpbb_database_test_case.php | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 5f6d49c26c..21cbde496a 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -175,20 +175,4 @@ class phpbb_search_native_test extends phpbb_database_test_case } $this->assert_array_content_equals($common, $this->search->get_common_words()); } - - public function assert_array_content_equals($one, $two) - { - // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important - // but one array_diff is not enough! - if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) - { - // get a nice error message - $this->assertEquals($one, $two); - } - else - { - // increase assertion count - $this->assertTrue(true); - } - } } diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 75a3c0944b..514619687a 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -141,4 +141,20 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { return $matches[1] . strtoupper($matches[2]) . $matches[3]; } + + public function assert_array_content_equals($one, $two) + { + // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important + // but one array_diff is not enough! + if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) + { + // get a nice error message + $this->assertEquals($one, $two); + } + else + { + // increase assertion count + $this->assertTrue(true); + } + } } From 04480ec4ae8435db37072cd976e7591a3abaafb9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:09:35 -0500 Subject: [PATCH 567/645] [ticket/11174] Delete copy pasting. PHPBB3-11174 --- tests/search/mysql_test.php | 14 -------------- tests/search/postgres_test.php | 14 -------------- 2 files changed, 28 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 56cce24c09..5e5d5c9846 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -149,18 +149,4 @@ class phpbb_search_mysql_test extends phpbb_database_test_case } $this->assert_array_content_equals($common, $this->search->get_common_words()); } - - public function assert_array_content_equals($one, $two) - { - if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) - { - // get a nice error message - $this->assertEquals($one, $two); - } - else - { - // increase assertion count - $this->assertTrue(true); - } - } } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index e20e6789b7..d3172c6457 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -138,18 +138,4 @@ class phpbb_search_postgres_test extends phpbb_database_test_case } $this->assert_array_content_equals($common, $this->search->get_common_words()); } - - public function assert_array_content_equals($one, $two) - { - if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one))) - { - // get a nice error message - $this->assertEquals($one, $two); - } - else - { - // increase assertion count - $this->assertTrue(true); - } - } } From a5900a6b1120a3d062e6d51579872bf940b13dcb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:18:39 -0500 Subject: [PATCH 568/645] [ticket/11174] Extract phpbb_search_test_case. PHPBB3-11174 --- tests/search/native_test.php | 21 ++------------ .../test_framework/phpbb_search_test_case.php | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 tests/test_framework/phpbb_search_test_case.php diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 21cbde496a..544ab7ca17 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -7,24 +7,9 @@ * */ -function phpbb_native_search_wrapper($class) -{ - $wrapped = $class . '_wrapper'; - if (!class_exists($wrapped)) - { - $code = " -class $wrapped extends $class -{ - public function get_must_contain_ids() { return \$this->must_contain_ids; } - public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } -} - "; - eval($code); - } - return $wrapped; -} +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; -class phpbb_search_native_test extends phpbb_database_test_case +class phpbb_search_native_test extends phpbb_search_test_case { protected $db; protected $search; @@ -45,7 +30,7 @@ class phpbb_search_native_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $error = null; - $class = phpbb_native_search_wrapper('phpbb_search_fulltext_native'); + $class = self::get_search_wrapper('phpbb_search_fulltext_native'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } diff --git a/tests/test_framework/phpbb_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php new file mode 100644 index 0000000000..8b378186df --- /dev/null +++ b/tests/test_framework/phpbb_search_test_case.php @@ -0,0 +1,28 @@ +must_contain_ids; } + public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } +} + "; + eval($code); + } + return $wrapped; + } +} From 4d1486b08cd2f1e75527ed3b54664361934258a7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:22:43 -0500 Subject: [PATCH 569/645] [ticket/11174] Eliminate search wrapper copy pasting. PHPBB3-11174 --- tests/search/mysql_test.php | 20 +++---------------- tests/search/postgres_test.php | 11 ++++------ .../test_framework/phpbb_search_test_case.php | 1 + 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 5e5d5c9846..cf89facc83 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -7,23 +7,9 @@ * */ -function phpbb_search_wrapper($class) -{ - $wrapped = $class . '_wrapper'; - if (!class_exists($wrapped)) - { - $code = " -class $wrapped extends $class -{ - public function get_split_words() { return \$this->split_words; } -} - "; - eval($code); - } - return $wrapped; -} +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; -class phpbb_search_mysql_test extends phpbb_database_test_case +class phpbb_search_mysql_test extends phpbb_search_test_case { protected $db; protected $search; @@ -48,7 +34,7 @@ class phpbb_search_mysql_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $error = null; - $class = phpbb_search_wrapper('phpbb_search_fulltext_mysql'); + $class = self::get_search_wrapper('phpbb_search_fulltext_mysql'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index d3172c6457..211755c7db 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -7,7 +7,9 @@ * */ -class phpbb_search_postgres_test extends phpbb_database_test_case +require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; + +class phpbb_search_postgres_test extends phpbb_search_test_case { protected $db; protected $search; @@ -30,14 +32,9 @@ class phpbb_search_postgres_test extends phpbb_database_test_case $config['fulltext_postgres_min_word_len'] = 4; $config['fulltext_postgres_max_word_len'] = 254; - if(!function_exists('phpbb_search_wrapper')) - { - include('mysql_test.' . $phpEx); - } - $this->db = $this->new_dbal(); $error = null; - $class = phpbb_search_wrapper('phpbb_search_fulltext_postgres'); + $class = self::get_search_wrapper('phpbb_search_fulltext_postgres'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } diff --git a/tests/test_framework/phpbb_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php index 8b378186df..418d352c17 100644 --- a/tests/test_framework/phpbb_search_test_case.php +++ b/tests/test_framework/phpbb_search_test_case.php @@ -19,6 +19,7 @@ class $wrapped extends $class { public function get_must_contain_ids() { return \$this->must_contain_ids; } public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; } + public function get_split_words() { return \$this->split_words; } } "; eval($code); From 4b5e90a2bd7380d67a0aba053b2788ce7d9abd89 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:45:48 -0500 Subject: [PATCH 570/645] [ticket/11174] Empty fixture for when we don't need any data. PHPBB3-11174 --- tests/fixtures/empty.xml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/fixtures/empty.xml diff --git a/tests/fixtures/empty.xml b/tests/fixtures/empty.xml new file mode 100644 index 0000000000..96eb1ab483 --- /dev/null +++ b/tests/fixtures/empty.xml @@ -0,0 +1,5 @@ + + + +
+
From 0c430a1f9365260502b7b293b32a34f97edeada4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:46:15 -0500 Subject: [PATCH 571/645] [ticket/11174] These tests do not need posts fixtures. PHPBB3-11174 --- tests/search/mysql_test.php | 2 +- tests/search/postgres_test.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index cf89facc83..097e46d855 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -16,7 +16,7 @@ class phpbb_search_mysql_test extends phpbb_search_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); } protected function setUp() diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 211755c7db..b6dc5ef1a3 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -16,7 +16,7 @@ class phpbb_search_postgres_test extends phpbb_search_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml'); } protected function setUp() From cb2d029abf2d4857fa462f46af21728afde3cd28 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 08:56:32 -0500 Subject: [PATCH 572/645] [ticket/11174] Drop needless teardown functions. PHPBB3-11174 --- tests/search/mysql_test.php | 5 ----- tests/search/native_test.php | 5 ----- tests/search/postgres_test.php | 5 ----- 3 files changed, 15 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 097e46d855..9f38ef2ef6 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -38,11 +38,6 @@ class phpbb_search_mysql_test extends phpbb_search_test_case $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - protected function tearDown() - { - parent::tearDown(); - } - public function keywords() { return array( diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 544ab7ca17..53d7a1fe78 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -34,11 +34,6 @@ class phpbb_search_native_test extends phpbb_search_test_case $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - protected function tearDown() - { - parent::tearDown(); - } - public function keywords() { return array( diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index b6dc5ef1a3..b8c9bcfbe9 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -38,11 +38,6 @@ class phpbb_search_postgres_test extends phpbb_search_test_case $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - protected function tearDown() - { - parent::tearDown(); - } - public function keywords() { return array( From 7dcb03faf1e9c2374f5d5fd36e3b01e8f0315d73 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 09:06:56 -0500 Subject: [PATCH 573/645] [ticket/11174] Delete more copy pasting. PHPBB3-11174 --- tests/search/common_test_case.php | 106 ++++++++++++++++++++++++++++++ tests/search/mysql_test.php | 97 +-------------------------- tests/search/postgres_test.php | 97 +-------------------------- 3 files changed, 110 insertions(+), 190 deletions(-) create mode 100644 tests/search/common_test_case.php diff --git a/tests/search/common_test_case.php b/tests/search/common_test_case.php new file mode 100644 index 0000000000..dd04f7048c --- /dev/null +++ b/tests/search/common_test_case.php @@ -0,0 +1,106 @@ +search->split_keywords($keywords, $terms); + $this->assertEquals($ok, $rv); + if ($ok) + { + // only check criteria if the search is going to be performed + $this->assert_array_content_equals($split_words, $this->search->get_split_words()); + } + $this->assert_array_content_equals($common, $this->search->get_common_words()); + } +} diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index 9f38ef2ef6..e1538bc81c 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; +require_once dirname(__FILE__) . '/common_test_case.php'; -class phpbb_search_mysql_test extends phpbb_search_test_case +class phpbb_search_mysql_test extends phpbb_search_common_test_case { protected $db; protected $search; @@ -37,97 +37,4 @@ class phpbb_search_mysql_test extends phpbb_search_test_case $class = self::get_search_wrapper('phpbb_search_fulltext_mysql'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - - public function keywords() - { - return array( - // keywords - // terms - // ok - // split words - // common words - array( - 'fooo', - 'all', - true, - array('fooo'), - array(), - ), - array( - 'fooo baar', - 'all', - true, - array('fooo', 'baar'), - array(), - ), - // leading, trailing and multiple spaces - array( - ' fooo baar ', - 'all', - true, - array('fooo', 'baar'), - array(), - ), - // words too short - array( - 'f', - 'all', - false, - null, - // short words count as "common" words - array('f'), - ), - array( - 'f o o', - 'all', - false, - null, - array('f', 'o', 'o'), - ), - array( - 'f -o -o', - 'all', - false, - null, - array('f', '-o', '-o'), - ), - array( - 'fooo -baar', - 'all', - true, - array('-baar', 'fooo'), - array(), - ), - // all negative - array( - '-fooo', - 'all', - true, - array('-fooo'), - array(), - ), - array( - '-fooo -baar', - 'all', - true, - array('-fooo', '-baar'), - array(), - ), - ); - } - - /** - * @dataProvider keywords - */ - public function test_split_keywords($keywords, $terms, $ok, $split_words, $common) - { - $rv = $this->search->split_keywords($keywords, $terms); - $this->assertEquals($ok, $rv); - if ($ok) - { - // only check criteria if the search is going to be performed - $this->assert_array_content_equals($split_words, $this->search->get_split_words()); - } - $this->assert_array_content_equals($common, $this->search->get_common_words()); - } } diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index b8c9bcfbe9..6a65e6bf8f 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -7,9 +7,9 @@ * */ -require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php'; +require_once dirname(__FILE__) . '/common_test_case.php'; -class phpbb_search_postgres_test extends phpbb_search_test_case +class phpbb_search_postgres_test extends phpbb_search_common_test_case { protected $db; protected $search; @@ -37,97 +37,4 @@ class phpbb_search_postgres_test extends phpbb_search_test_case $class = self::get_search_wrapper('phpbb_search_fulltext_postgres'); $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user); } - - public function keywords() - { - return array( - // keywords - // terms - // ok - // split words - // common words - array( - 'fooo', - 'all', - true, - array('fooo'), - array(), - ), - array( - 'fooo baar', - 'all', - true, - array('fooo', 'baar'), - array(), - ), - // leading, trailing and multiple spaces - array( - ' fooo baar ', - 'all', - true, - array('fooo', 'baar'), - array(), - ), - // words too short - array( - 'f', - 'all', - false, - null, - // short words count as "common" words - array('f'), - ), - array( - 'f o o', - 'all', - false, - null, - array('f', 'o', 'o'), - ), - array( - 'f -o -o', - 'all', - false, - null, - array('f', '-o', '-o'), - ), - array( - 'fooo -baar', - 'all', - true, - array('-baar', 'fooo'), - array(), - ), - // all negative - array( - '-fooo', - 'all', - true, - array('-fooo'), - array(), - ), - array( - '-fooo -baar', - 'all', - true, - array('-fooo', '-baar'), - array(), - ), - ); - } - - /** - * @dataProvider keywords - */ - public function test_split_keywords($keywords, $terms, $ok, $split_words, $common) - { - $rv = $this->search->split_keywords($keywords, $terms); - $this->assertEquals($ok, $rv); - if ($ok) - { - // only check criteria if the search is going to be performed - $this->assert_array_content_equals($split_words, $this->search->get_split_words()); - } - $this->assert_array_content_equals($common, $this->search->get_common_words()); - } } From 79237b60b6b234e10f14cbcb00691b5e4374fd04 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 27 Nov 2012 10:24:31 -0500 Subject: [PATCH 574/645] [ticket/11174] Global $cache is a cache service instance. PHPBB3-11174 --- tests/search/mysql_test.php | 2 +- tests/search/native_test.php | 2 +- tests/search/postgres_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php index e1538bc81c..3ba3915714 100644 --- a/tests/search/mysql_test.php +++ b/tests/search/mysql_test.php @@ -26,7 +26,7 @@ class phpbb_search_mysql_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); // set config values $config['fulltext_mysql_min_word_len'] = 4; diff --git a/tests/search/native_test.php b/tests/search/native_test.php index 53d7a1fe78..eeee3a44f3 100644 --- a/tests/search/native_test.php +++ b/tests/search/native_test.php @@ -26,7 +26,7 @@ class phpbb_search_native_test extends phpbb_search_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); $this->db = $this->new_dbal(); $error = null; diff --git a/tests/search/postgres_test.php b/tests/search/postgres_test.php index 6a65e6bf8f..9c77e0c09e 100644 --- a/tests/search/postgres_test.php +++ b/tests/search/postgres_test.php @@ -26,7 +26,7 @@ class phpbb_search_postgres_test extends phpbb_search_common_test_case parent::setUp(); // dbal uses cache - $cache = new phpbb_cache_driver_null; + $cache = new phpbb_cache_service(new phpbb_cache_driver_null); // set config values $config['fulltext_postgres_min_word_len'] = 4; From a4cc07617726bffd4c64cdebaa2e20a463990c5d Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 28 Nov 2012 19:36:13 +0000 Subject: [PATCH 575/645] [ticket/10601] Requested code changes - Renamed the comment to PHPBB3-10601 - Removed backslashes - Traded double quotes into single quotes inside. PHPBB3-10601 --- phpBB/install/database_update.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 1dae3e566b..eed484dfae 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2753,9 +2753,9 @@ function change_database_data(&$no_updates, $version) // ticket/10601: Make inbox default. Add basename to ucp's pm category // Check if this was already applied $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id - FROM ' . MODULES_TABLE . ' - WHERE module_basename = "ucp_pm" - ORDER BY module_id'; + FROM ' . MODULES_TABLE . " + WHERE module_basename = 'ucp_pm' + ORDER BY module_id"; $result = $db->sql_query_limit($sql, 1); if ($row = $db->sql_fetchrow($result)) @@ -2765,9 +2765,9 @@ function change_database_data(&$no_updates, $version) { // This update is still not applied. Applying it - $sql = 'UPDATE ' . MODULES_TABLE . ' - SET module_basename = \'ucp_pm\' - WHERE module_id = ' . (int) $row['parent_id']; + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['parent_id']; _sql($sql, $errored, $error_ary); From 1d9891588182c831aeb1ce20065f6ceaa3f892b4 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Wed, 28 Nov 2012 19:37:16 +0000 Subject: [PATCH 576/645] [ticket/10601] Comment to help understanding the code PHPBB3-10601 --- phpBB/includes/functions_module.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php index 6f38dc60ce..0d387ace6d 100644 --- a/phpBB/includes/functions_module.php +++ b/phpBB/includes/functions_module.php @@ -767,6 +767,7 @@ class p_master } else { + // if the category has a name, then use it. $u_title .= $item_ary['name']; } // If the item is not a category append the mode From 65253a3023a78b1068be63b91b77618e3fb2d5fd Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 29 Nov 2012 15:35:21 -0500 Subject: [PATCH 577/645] [ticket/11227] @return void -> @return null in develop-olympus. PHPBB3-11227 --- phpBB/develop/generate_utf_casefold.php | 2 +- phpBB/develop/generate_utf_confusables.php | 2 +- phpBB/develop/generate_utf_tables.php | 2 +- phpBB/develop/utf_normalizer_test.php | 2 +- phpBB/docs/auth_api.html | 2 +- phpBB/includes/acm/acm_apc.php | 2 +- phpBB/includes/acm/acm_eaccelerator.php | 4 ++-- phpBB/includes/acm/acm_memcache.php | 4 ++-- phpBB/includes/acm/acm_redis.php | 4 ++-- phpBB/includes/acm/acm_wincache.php | 2 +- phpBB/includes/acm/acm_xcache.php | 2 +- phpBB/includes/functions.php | 4 ++-- phpBB/includes/functions_admin.php | 2 +- phpBB/includes/questionnaire/questionnaire.php | 2 +- 14 files changed, 18 insertions(+), 18 deletions(-) diff --git a/phpBB/develop/generate_utf_casefold.php b/phpBB/develop/generate_utf_casefold.php index 73951cb4dc..08f67c3eb6 100644 --- a/phpBB/develop/generate_utf_casefold.php +++ b/phpBB/develop/generate_utf_casefold.php @@ -111,7 +111,7 @@ function my_var_export($var) * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/develop/generate_utf_confusables.php b/phpBB/develop/generate_utf_confusables.php index d2ffbcfc65..fd0439a4bb 100644 --- a/phpBB/develop/generate_utf_confusables.php +++ b/phpBB/develop/generate_utf_confusables.php @@ -199,7 +199,7 @@ function my_var_export($var) * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/develop/generate_utf_tables.php b/phpBB/develop/generate_utf_tables.php index 6fe5d68ffd..6372270b78 100644 --- a/phpBB/develop/generate_utf_tables.php +++ b/phpBB/develop/generate_utf_tables.php @@ -481,7 +481,7 @@ function my_var_export($var) * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/develop/utf_normalizer_test.php b/phpBB/develop/utf_normalizer_test.php index 71f24a716b..b8709888fe 100644 --- a/phpBB/develop/utf_normalizer_test.php +++ b/phpBB/develop/utf_normalizer_test.php @@ -222,7 +222,7 @@ die("\n\nALL TESTS PASSED SUCCESSFULLY\n"); * Download a file to the develop/ dir * * @param string $url URL of the file to download -* @return void +* @return null */ function download($url) { diff --git a/phpBB/docs/auth_api.html b/phpBB/docs/auth_api.html index 29469c21ac..a319460360 100644 --- a/phpBB/docs/auth_api.html +++ b/phpBB/docs/auth_api.html @@ -200,7 +200,7 @@ $user_id = 2; $auth->acl_clear_prefetch($user_id); -

This method returns void.

+

This method returns null.

2.viii. acl_get_list

diff --git a/phpBB/includes/acm/acm_apc.php b/phpBB/includes/acm/acm_apc.php index 1a487f94ad..205353d3a5 100644 --- a/phpBB/includes/acm/acm_apc.php +++ b/phpBB/includes/acm/acm_apc.php @@ -33,7 +33,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/acm/acm_eaccelerator.php b/phpBB/includes/acm/acm_eaccelerator.php index 645067c199..ecec3ac9a5 100644 --- a/phpBB/includes/acm/acm_eaccelerator.php +++ b/phpBB/includes/acm/acm_eaccelerator.php @@ -37,7 +37,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { @@ -54,7 +54,7 @@ class acm extends acm_memory /** * Perform cache garbage collection * - * @return void + * @return null */ function tidy() { diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php index e54fa36c38..70bc219952 100644 --- a/phpBB/includes/acm/acm_memcache.php +++ b/phpBB/includes/acm/acm_memcache.php @@ -71,7 +71,7 @@ class acm extends acm_memory /** * Unload the cache resources * - * @return void + * @return null */ function unload() { @@ -83,7 +83,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/acm/acm_redis.php b/phpBB/includes/acm/acm_redis.php index 41533eaacb..dc11ca7768 100644 --- a/phpBB/includes/acm/acm_redis.php +++ b/phpBB/includes/acm/acm_redis.php @@ -80,7 +80,7 @@ class acm extends acm_memory /** * Unload the cache resources * - * @return void + * @return null */ function unload() { @@ -92,7 +92,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/acm/acm_wincache.php b/phpBB/includes/acm/acm_wincache.php index 0501ab74c5..7faba4f5b6 100644 --- a/phpBB/includes/acm/acm_wincache.php +++ b/phpBB/includes/acm/acm_wincache.php @@ -32,7 +32,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php index d0a614660c..e3d83f8bfa 100644 --- a/phpBB/includes/acm/acm_xcache.php +++ b/phpBB/includes/acm/acm_xcache.php @@ -48,7 +48,7 @@ class acm extends acm_memory /** * Purge cache data * - * @return void + * @return null */ function purge() { diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 6e661228b7..571c863839 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2745,7 +2745,7 @@ function meta_refresh($time, $url, $disable_cd_check = false) * * @param int $code HTTP status code * @param string $message Message for the status code -* @return void +* @return null */ function send_status_line($code, $message) { @@ -4332,7 +4332,7 @@ function phpbb_optionset($bit, $set, $data) * * @param array $param Parameter array, see $param_defaults array. * -* @return void +* @return null */ function phpbb_http_login($param) { diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php index 7352b3d1f3..190185cfcf 100644 --- a/phpBB/includes/functions_admin.php +++ b/phpBB/includes/functions_admin.php @@ -3343,7 +3343,7 @@ function obtain_latest_version_info($force_update = false, $warn_fail = false, $ * @param int $flag The binary flag which is OR-ed with the current column value * @param string $sql_more This string is attached to the sql query generated to update the table. * - * @return void + * @return null */ function enable_bitfield_column_flag($table_name, $column_name, $flag, $sql_more = '') { diff --git a/phpBB/includes/questionnaire/questionnaire.php b/phpBB/includes/questionnaire/questionnaire.php index cbd7638809..3268775cb6 100644 --- a/phpBB/includes/questionnaire/questionnaire.php +++ b/phpBB/includes/questionnaire/questionnaire.php @@ -71,7 +71,7 @@ class phpbb_questionnaire_data_collector /** * Collect info into the data property. * - * @return void + * @return null */ function collect() { From ee16ed7b76315f629adc1f234d6cf3ddd9552a97 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 11:53:19 -0500 Subject: [PATCH 578/645] [ticket/10875] Spelling fix. PHPBB3-10875 --- phpBB/includes/cache/driver/interface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php index 6adc95a86a..26dfd497aa 100644 --- a/phpBB/includes/cache/driver/interface.php +++ b/phpBB/includes/cache/driver/interface.php @@ -63,7 +63,7 @@ interface phpbb_cache_driver_interface public function destroy($var_name, $table = ''); /** - * Check if a given cache entry exist + * Check if a given cache entry exists */ public function _exists($var_name); @@ -94,7 +94,7 @@ interface phpbb_cache_driver_interface public function sql_save($query, $query_result, $ttl); /** - * Ceck if a given sql query exist in cache + * Check if a given sql query exists in cache * * @param int $query_id * @return bool From 3eb15ab59e202f6d995f40da7cbee0056e73f5d1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 12:04:05 -0500 Subject: [PATCH 579/645] [ticket/10875] More documentation. PHPBB3-10875 --- phpBB/includes/cache/driver/interface.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php index 26dfd497aa..d403bbcd71 100644 --- a/phpBB/includes/cache/driver/interface.php +++ b/phpBB/includes/cache/driver/interface.php @@ -68,7 +68,7 @@ interface phpbb_cache_driver_interface public function _exists($var_name); /** - * Load cached sql query + * Load result of an SQL query from cache. * * @param string $query SQL query * @@ -79,7 +79,11 @@ interface phpbb_cache_driver_interface public function sql_load($query); /** - * Save sql query + * Save result of an SQL query in cache. + * + * In persistent cache stores, this function stores the query + * result to persistent storage. In other words, there is no need + * to call save() afterwards. * * @param string $query SQL query, should be used for generating storage key * @param mixed $query_result The result from dbal::sql_query, to be passed to @@ -94,7 +98,7 @@ interface phpbb_cache_driver_interface public function sql_save($query, $query_result, $ttl); /** - * Check if a given sql query exists in cache + * Check if result for a given SQL query exists in cache. * * @param int $query_id * @return bool From 1ebc6eb68bedc4d6708cb6f23959d129030cf31e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 12:11:52 -0500 Subject: [PATCH 580/645] [ticket/10875] Must return query result on failure. PHPBB3-10875 --- phpBB/includes/cache/driver/memory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php index bc08494c0c..e4da5767cf 100644 --- a/phpBB/includes/cache/driver/memory.php +++ b/phpBB/includes/cache/driver/memory.php @@ -294,7 +294,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs)) { // Bail out if the match fails. - return; + return $query_result; } $tables = array_map('trim', explode(',', $regs[1])); From 7bba09811c65acfd98ebf1e6626f59de7a16cbb3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 12:18:33 -0500 Subject: [PATCH 581/645] [ticket/10875] Revise sql cache test. Delete data from database before retrieving it from cache, ensuring results come from cache. PHPBB3-10875 --- tests/cache/cache_test.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index c5f5fac88c..40eef91d53 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -89,20 +89,26 @@ class phpbb_cache_test extends phpbb_database_test_case WHERE config_name = 'foo'"; $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'); + $sql = "DELETE FROM phpbb_config"; + $result = $db->sql_query($sql); + $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; $result = $db->sql_query($sql, 300); - $this->assertEquals($first_result, $db->sql_fetchrow($result)); + $this->assertEquals($expected, $db->sql_fetchrow($result)); $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'bar'"; - $result = $db->sql_query($sql, 300); + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); - $this->assertNotEquals($first_result, $db->sql_fetchrow($result)); + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); $db->sql_close(); } From 0c06ac466f61cdab1c647cec23ea66ef70b2ad7e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 12:28:13 -0500 Subject: [PATCH 582/645] [ticket/10875] Test for null cache driver and sql cache. PHPBB3-10875 --- tests/cache/cache_test.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 40eef91d53..c904aa6c41 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -112,4 +112,33 @@ class phpbb_cache_test extends phpbb_database_test_case $db->sql_close(); } + + public function test_null_cache_sql() + { + $driver = new phpbb_cache_driver_null($this->cache_dir); + + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $sql = "DELETE FROM phpbb_config"; + $result = $db->sql_query($sql); + + // As null cache driver does not actually cache, + // this should return no results + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertSame(false, $db->sql_fetchrow($result)); + + $db->sql_close(); + } } From e4d2ad6b2788d9c3c030382f5ad2f02b6b7f75db Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sat, 1 Dec 2012 00:36:34 +0100 Subject: [PATCH 583/645] [ticket/10875] tests/cache/cache_test.php: Use single quotes where possible. PHPBB3-10875 --- tests/cache/cache_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index c904aa6c41..285af5cd0c 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -94,7 +94,7 @@ class phpbb_cache_test extends phpbb_database_test_case $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'); - $sql = "DELETE FROM phpbb_config"; + $sql = 'DELETE FROM phpbb_config'; $result = $db->sql_query($sql); $sql = "SELECT * FROM phpbb_config @@ -128,7 +128,7 @@ class phpbb_cache_test extends phpbb_database_test_case $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); $this->assertEquals($expected, $first_result); - $sql = "DELETE FROM phpbb_config"; + $sql = 'DELETE FROM phpbb_config'; $result = $db->sql_query($sql); // As null cache driver does not actually cache, From ec4343c7447911c7e822a03c0f57fc2bb1c4ab3d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 23:03:06 -0500 Subject: [PATCH 584/645] [ticket/11227] @return void -> @return null, per coding guidelines. PHPBB3-11227 --- phpBB/includes/config/config.php | 2 +- phpBB/includes/config/db.php | 2 +- phpBB/includes/cron/manager.php | 2 +- phpBB/includes/cron/task/core/prune_all_forums.php | 2 +- phpBB/includes/cron/task/core/prune_forum.php | 4 ++-- phpBB/includes/cron/task/core/queue.php | 2 +- phpBB/includes/cron/task/core/tidy_cache.php | 2 +- phpBB/includes/cron/task/core/tidy_database.php | 2 +- phpBB/includes/cron/task/core/tidy_search.php | 2 +- phpBB/includes/cron/task/core/tidy_sessions.php | 2 +- phpBB/includes/cron/task/core/tidy_warnings.php | 2 +- phpBB/includes/cron/task/parametrized.php | 2 +- phpBB/includes/cron/task/task.php | 2 +- phpBB/includes/functions_download.php | 2 +- phpBB/includes/group_positions.php | 10 +++++----- phpBB/includes/lock/db.php | 2 +- phpBB/includes/style/resource_locator.php | 4 ++-- phpBB/includes/template/compile.php | 2 +- 18 files changed, 24 insertions(+), 24 deletions(-) diff --git a/phpBB/includes/config/config.php b/phpBB/includes/config/config.php index 12a4a418b2..4b533dd55c 100644 --- a/phpBB/includes/config/config.php +++ b/phpBB/includes/config/config.php @@ -109,7 +109,7 @@ class phpbb_config implements ArrayAccess, IteratorAggregate, Countable * @param String $key The configuration option's name * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached - * @return void + * @return null */ public function delete($key, $use_cache = true) { diff --git a/phpBB/includes/config/db.php b/phpBB/includes/config/db.php index 993a764a7f..45f9f1cb21 100644 --- a/phpBB/includes/config/db.php +++ b/phpBB/includes/config/db.php @@ -96,7 +96,7 @@ class phpbb_config_db extends phpbb_config * @param String $key The configuration option's name * @param bool $use_cache Whether this variable should be cached or if it * changes too frequently to be efficiently cached - * @return void + * @return null */ public function delete($key, $use_cache = true) { diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index ccaa4f3764..84c9650830 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -54,7 +54,7 @@ class phpbb_cron_manager * * @param array|Traversable $tasks Array of instances of phpbb_cron_task * - * @return void + * @return null */ public function load_tasks($tasks) { diff --git a/phpBB/includes/cron/task/core/prune_all_forums.php b/phpBB/includes/cron/task/core/prune_all_forums.php index 252e16e57d..ee0b5f7626 100644 --- a/phpBB/includes/cron/task/core/prune_all_forums.php +++ b/phpBB/includes/cron/task/core/prune_all_forums.php @@ -50,7 +50,7 @@ class phpbb_cron_task_core_prune_all_forums extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/prune_forum.php b/phpBB/includes/cron/task/core/prune_forum.php index 41d60af921..fa7a761d88 100644 --- a/phpBB/includes/cron/task/core/prune_forum.php +++ b/phpBB/includes/cron/task/core/prune_forum.php @@ -70,7 +70,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p /** * Runs this cron task. * - * @return void + * @return null */ public function run() { @@ -138,7 +138,7 @@ class phpbb_cron_task_core_prune_forum extends phpbb_cron_task_base implements p * * @param phpbb_request_interface $request Request object. * - * @return void + * @return null */ public function parse_parameters(phpbb_request_interface $request) { diff --git a/phpBB/includes/cron/task/core/queue.php b/phpBB/includes/cron/task/core/queue.php index c765660906..732f9c6bea 100644 --- a/phpBB/includes/cron/task/core/queue.php +++ b/phpBB/includes/cron/task/core/queue.php @@ -43,7 +43,7 @@ class phpbb_cron_task_core_queue extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_cache.php b/phpBB/includes/cron/task/core/tidy_cache.php index 6017eea561..16a45dae7c 100644 --- a/phpBB/includes/cron/task/core/tidy_cache.php +++ b/phpBB/includes/cron/task/core/tidy_cache.php @@ -40,7 +40,7 @@ class phpbb_cron_task_core_tidy_cache extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_database.php b/phpBB/includes/cron/task/core/tidy_database.php index 1d256f964f..b882e7b500 100644 --- a/phpBB/includes/cron/task/core/tidy_database.php +++ b/phpBB/includes/cron/task/core/tidy_database.php @@ -43,7 +43,7 @@ class phpbb_cron_task_core_tidy_database extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_search.php b/phpBB/includes/cron/task/core/tidy_search.php index 2e5f3d79d5..fdbe31346e 100644 --- a/phpBB/includes/cron/task/core/tidy_search.php +++ b/phpBB/includes/cron/task/core/tidy_search.php @@ -54,7 +54,7 @@ class phpbb_cron_task_core_tidy_search extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_sessions.php b/phpBB/includes/cron/task/core/tidy_sessions.php index 13531aa30b..95f55235c9 100644 --- a/phpBB/includes/cron/task/core/tidy_sessions.php +++ b/phpBB/includes/cron/task/core/tidy_sessions.php @@ -40,7 +40,7 @@ class phpbb_cron_task_core_tidy_sessions extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/core/tidy_warnings.php b/phpBB/includes/cron/task/core/tidy_warnings.php index 8dd0674fe5..2a7798e56e 100644 --- a/phpBB/includes/cron/task/core/tidy_warnings.php +++ b/phpBB/includes/cron/task/core/tidy_warnings.php @@ -45,7 +45,7 @@ class phpbb_cron_task_core_tidy_warnings extends phpbb_cron_task_base /** * Runs this cron task. * - * @return void + * @return null */ public function run() { diff --git a/phpBB/includes/cron/task/parametrized.php b/phpBB/includes/cron/task/parametrized.php index 0714b2e701..5f0e46eafc 100644 --- a/phpBB/includes/cron/task/parametrized.php +++ b/phpBB/includes/cron/task/parametrized.php @@ -46,7 +46,7 @@ interface phpbb_cron_task_parametrized extends phpbb_cron_task * * @param phpbb_request_interface $request Request object. * - * @return void + * @return null */ public function parse_parameters(phpbb_request_interface $request); } diff --git a/phpBB/includes/cron/task/task.php b/phpBB/includes/cron/task/task.php index 7b08fed413..2d585df96d 100644 --- a/phpBB/includes/cron/task/task.php +++ b/phpBB/includes/cron/task/task.php @@ -31,7 +31,7 @@ interface phpbb_cron_task /** * Runs this cron task. * - * @return void + * @return null */ public function run(); diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php index b6371dbecc..fc6f1cc762 100644 --- a/phpBB/includes/functions_download.php +++ b/phpBB/includes/functions_download.php @@ -433,7 +433,7 @@ function set_modified_headers($stamp, $browser) * * @param bool $exit Whether to die or not. * -* @return void +* @return null */ function file_gc($exit = true) { diff --git a/phpBB/includes/group_positions.php b/phpBB/includes/group_positions.php index 74de3516cb..60352ed97d 100644 --- a/phpBB/includes/group_positions.php +++ b/phpBB/includes/group_positions.php @@ -104,7 +104,7 @@ class phpbb_group_positions * Addes a group by group_id * * @param int $group_id group_id of the group to be added - * @return void + * @return null */ public function add_group($group_id) { @@ -128,7 +128,7 @@ class phpbb_group_positions * * @param int $group_id group_id of the group to be deleted * @param bool $skip_group Skip setting the group to GROUP_DISABLED, to save the query, when you need to update it anyway. - * @return void + * @return null */ public function delete_group($group_id, $skip_group = false) { @@ -159,7 +159,7 @@ class phpbb_group_positions * Moves a group up by group_id * * @param int $group_id group_id of the group to be moved - * @return void + * @return null */ public function move_up($group_id) { @@ -170,7 +170,7 @@ class phpbb_group_positions * Moves a group down by group_id * * @param int $group_id group_id of the group to be moved - * @return void + * @return null */ public function move_down($group_id) { @@ -184,7 +184,7 @@ class phpbb_group_positions * @param int $delta number of steps: * - positive = move up * - negative = move down - * @return void + * @return null */ public function move($group_id, $delta) { diff --git a/phpBB/includes/lock/db.php b/phpBB/includes/lock/db.php index fa559d6887..6e94dd5a85 100644 --- a/phpBB/includes/lock/db.php +++ b/phpBB/includes/lock/db.php @@ -125,7 +125,7 @@ class phpbb_lock_db * Note: Attempting to release a lock that is already released, * that is, calling release() multiple times, is harmless. * - * @return void + * @return null */ public function release() { diff --git a/phpBB/includes/style/resource_locator.php b/phpBB/includes/style/resource_locator.php index 04beddb434..4cf767c062 100644 --- a/phpBB/includes/style/resource_locator.php +++ b/phpBB/includes/style/resource_locator.php @@ -110,7 +110,7 @@ class phpbb_style_resource_locator implements phpbb_template_locator * Typically it is one directory level deep, e.g. "template/". * * @param string $template_path Relative path to templates directory within style directories - * @return void + * @return null */ public function set_template_path($template_path) { @@ -121,7 +121,7 @@ class phpbb_style_resource_locator implements phpbb_template_locator * Sets the location of templates directory within style directories * to the default, which is "template/". * - * @return void + * @return null */ public function set_default_template_path() { diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index 82b301c1a2..d0b3d0f115 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -118,7 +118,7 @@ class phpbb_template_compile * * @param resource $source_stream Source stream * @param resource $dest_stream Destination stream - * @return void + * @return null */ private function compile_stream_to_stream($source_stream, $dest_stream) { From e5e8087bebdae8c4da2e59e9afd984d6a2008caf Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 30 Nov 2012 23:03:48 -0500 Subject: [PATCH 585/645] [ticket/11227] @return void -> @return null in code sniffer. PHPBB3-11227 --- .../phpbb/Sniffs/Commenting/FileCommentSniff.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php b/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php index ba2b40ecba..68e9e6bb86 100644 --- a/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php +++ b/code_sniffer/phpbb/Sniffs/Commenting/FileCommentSniff.php @@ -35,7 +35,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param int $stackPtr The position of the current token * in the stack passed in $tokens. * - * @return void + * @return null */ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) { @@ -120,7 +120,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processPackage(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { @@ -143,7 +143,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processVersion(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { @@ -166,7 +166,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processCopyright(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { @@ -189,7 +189,7 @@ class phpbb_Sniffs_Commenting_FileCommentSniff implements PHP_CodeSniffer_Sniff * @param integer The stack pointer for the first comment token. * @param array(string=>array) $tags The found file doc comment tags. * - * @return void + * @return null */ protected function processLicense(PHP_CodeSniffer_File $phpcsFile, $ptr, $tags) { From c852044d6eecc0a652800b1661491c0f9c545054 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 00:48:21 -0500 Subject: [PATCH 586/645] [ticket/9983] Add redis cache driver tests. In order to not overwrite data in default redis store, at least one of redis host or post must be explicitly specified. Redis cache driver constructor has been modified to accept host and port as parameters. This was not added to public API as there are more parameters being passed via global constants. PHPBB3-9983 --- phpBB/includes/cache/driver/redis.php | 27 +++++++- tests/RUNNING_TESTS.txt | 15 ++++ tests/cache/cache_test.php | 68 ++++++++++++++++++- .../phpbb_test_case_helpers.php | 19 ++++++ 4 files changed, 126 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php index d256b5600e..ae6f9e04f2 100644 --- a/phpBB/includes/cache/driver/redis.php +++ b/phpBB/includes/cache/driver/redis.php @@ -39,13 +39,38 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory var $redis; + /** + * Creates a redis cache driver. + * + * The following global constants affect operation: + * + * PHPBB_ACM_REDIS_HOST + * PHPBB_ACM_REDIS_PORT + * PHPBB_ACM_REDIS_PASSWORD + * PHPBB_ACM_REDIS_DB + * + * There are no publicly documented constructor parameters. + */ function __construct() { // Call the parent constructor parent::__construct(); $this->redis = new Redis(); - $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); + + $args = func_get_args(); + if (!empty($args)) + { + $ok = call_user_func_array(array($this->redis, 'connect'), $args); + } + else + { + $ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); + } + if (!$ok) + { + trigger_error('Could not connect to redis server'); + } if (defined('PHPBB_ACM_REDIS_PASSWORD')) { diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 7c2a7c3fce..11617964cb 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -72,6 +72,21 @@ to connect to that database in phpBB. Additionally, you will need to be running the DbUnit fork from https://github.com/phpbb/dbunit/tree/phpbb. +Redis +----- + +In order to run tests for the Redis cache driver, at least one of Redis host +or port must be specified in test configuration. This can be done via +test_config.php as follows: + + cache_dir); @@ -87,12 +87,76 @@ class phpbb_cache_test extends phpbb_database_test_case $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; + + $cache_path = $this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'; + $this->assertFileNotExists($cache_path); + $result = $db->sql_query($sql, 300); $first_result = $db->sql_fetchrow($result); $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); $this->assertEquals($expected, $first_result); - $this->assertFileExists($this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'); + $this->assertFileExists($cache_path); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } + + public function test_cache_sql_redis() + { + if (!extension_loaded('redis')) + { + $this->markTestSkipped('redis extension is not loaded'); + } + + $config = phpbb_test_case_helpers::get_test_config(); + if (isset($config['redis_host']) || isset($config['redis_port'])) + { + $host = isset($config['redis_host']) ? $config['redis_host'] : 'localhost'; + $port = isset($config['redis_port']) ? $config['redis_port'] : 6379; + } + else + { + $this->markTestSkipped('Test redis host/port is not specified'); + } + $driver = new phpbb_cache_driver_redis($host, $port); + $driver->purge(); + + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($driver); + + $redis = new Redis(); + $ok = $redis->connect($host, $port); + $this->assertTrue($ok); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $key = $driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); + $this->assertFalse($redis->exists($key)); + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $this->assertTrue($redis->exists($key)); $sql = 'DELETE FROM phpbb_config'; $result = $db->sql_query($sql); diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index d10645a732..b56a699d1c 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -91,6 +91,15 @@ class phpbb_test_case_helpers { $config['phpbb_functional_url'] = $phpbb_functional_url; } + + if (isset($redis_host)) + { + $config['redis_host'] = $redis_host; + } + if (isset($redis_port)) + { + $config['redis_port'] = $redis_port; + } } if (isset($_SERVER['PHPBB_TEST_DBMS'])) @@ -113,6 +122,16 @@ class phpbb_test_case_helpers )); } + if (isset($_SERVER['PHPBB_TEST_REDIS_HOST'])) + { + $config['redis_host'] = $_SERVER['PHPBB_TEST_REDIS_HOST']; + } + + if (isset($_SERVER['PHPBB_TEST_REDIS_PORT'])) + { + $config['redis_port'] = $_SERVER['PHPBB_TEST_REDIS_PORT']; + } + return $config; } From a0d5c52eb6e8ef3a6bb44cff60b364d3a3a5bf3e Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sat, 1 Dec 2012 09:44:51 +0000 Subject: [PATCH 587/645] [ticket/10601] New approach in the update algorithm - New approach in the database update algorithm PHPBB3-10601 --- phpBB/install/database_update.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index eed484dfae..f3136690a2 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2750,28 +2750,25 @@ function change_database_data(&$no_updates, $version) $config->set('site_home_text', ''); } - // ticket/10601: Make inbox default. Add basename to ucp's pm category - // Check if this was already applied - $sql = 'SELECT module_id, module_basename, parent_id, left_id, right_id + // PHPBB3-10601: Make inbox default. Add basename to ucp's pm category + + // Get the category wanted while checking, at the same time, if this has already been applied + $sql = 'SELECT module_id, module_basename FROM ' . MODULES_TABLE . " - WHERE module_basename = 'ucp_pm' + WHERE module_basename <> 'ucp_pm' AND + module_langname='UCP_PM' ORDER BY module_id"; $result = $db->sql_query_limit($sql, 1); if ($row = $db->sql_fetchrow($result)) { - // Checking if this is not a category - if ($row['left_id'] === $row['right_id'] - 1) - { - // This update is still not applied. Applying it + // This update is still not applied. Applying it - $sql = 'UPDATE ' . MODULES_TABLE . " - SET module_basename = 'ucp_pm' - WHERE module_id = " . (int) $row['parent_id']; + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_basename = 'ucp_pm' + WHERE module_id = " . (int) $row['module_id']; - _sql($sql, $errored, $error_ary); - - } + _sql($sql, $errored, $error_ary); } $db->sql_freeresult($result); From 314462d8352a6b5ea1fd27ce1bb21cb0a8fb1310 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 9 Nov 2012 22:36:01 +0100 Subject: [PATCH 588/645] [ticket/10184] Disable receiving pms for bots by default PHPBB3-10184 --- phpBB/install/database_update.php | 6 ++++++ phpBB/install/install_install.php | 1 + 2 files changed, 7 insertions(+) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 399ad3429a..8e23434b5b 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2171,6 +2171,12 @@ function change_database_data(&$no_updates, $version) } } + // Disable receiving pms for bots + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE user_type = ' . USER_IGNORE; + $db->sql_query($sql); + $no_updates = false; break; } diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 67ebb8b1c5..0575b58d92 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -1859,6 +1859,7 @@ class install_install extends module 'user_timezone' => 0, 'user_dateformat' => $lang['default_dateformat'], 'user_allow_massemail' => 0, + 'user_allow_pm' => 0, ); $user_id = user_add($user_row); From ad2d560f3f6ab0232728392b2c1c946f2b07902d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 16 Nov 2012 14:32:31 +0100 Subject: [PATCH 589/645] [ticket/10184] Query bots table to get the user_ids of the bots PHPBB3-10184 --- phpBB/install/database_update.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 8e23434b5b..983b1b46c4 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2172,10 +2172,24 @@ function change_database_data(&$no_updates, $version) } // Disable receiving pms for bots - $sql = 'UPDATE ' . USERS_TABLE . ' - SET user_allow_pm = 0 - WHERE user_type = ' . USER_IGNORE; - $db->sql_query($sql); + $sql = 'SELECT user_id + FROM ' . BOTS_TABLE; + $result = $db->sql_query($sql); + + $bot_user_ids = array(); + while ($row = $db->sql_fetchrow($result)) + { + $bot_user_ids[] = (int) $row['user_id']; + } + $db->sql_freeresult($result); + + if (!empty($bot_user_ids)) + { + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_allow_pm = 0 + WHERE ' . $db->sql_in_set('user_id', $bot_user_ids); + _sql($sql, $errored, $error_ary); + } $no_updates = false; break; From 1ce06711811561d2e3fa3c6ba2aeac4ebffa6581 Mon Sep 17 00:00:00 2001 From: Bruno Ais Date: Sat, 1 Dec 2012 10:05:20 +0000 Subject: [PATCH 590/645] [ticket/10601] The ORDER BY is only taking space there PHPBB3-10601 --- phpBB/install/database_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index f3136690a2..ae6e3bd9cf 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2757,7 +2757,7 @@ function change_database_data(&$no_updates, $version) FROM ' . MODULES_TABLE . " WHERE module_basename <> 'ucp_pm' AND module_langname='UCP_PM' - ORDER BY module_id"; + "; $result = $db->sql_query_limit($sql, 1); if ($row = $db->sql_fetchrow($result)) From 1e3dff83b3e56353fd97a6581989c478e52ed892 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 15:03:44 -0500 Subject: [PATCH 591/645] [ticket/9983] Split cache test into per-driver files. PHPBB3-9983 --- tests/cache/cache_test.php | 208 ------------------------------ tests/cache/file_driver_test.php | 117 +++++++++++++++++ tests/cache/null_driver_test.php | 45 +++++++ tests/cache/redis_driver_test.php | 89 +++++++++++++ 4 files changed, 251 insertions(+), 208 deletions(-) delete mode 100644 tests/cache/cache_test.php create mode 100644 tests/cache/file_driver_test.php create mode 100644 tests/cache/null_driver_test.php create mode 100644 tests/cache/redis_driver_test.php diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php deleted file mode 100644 index ad60a9077e..0000000000 --- a/tests/cache/cache_test.php +++ /dev/null @@ -1,208 +0,0 @@ -cache_dir = dirname(__FILE__) . '/../tmp/cache/'; - } - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); - } - - protected function setUp() - { - parent::setUp(); - - if (file_exists($this->cache_dir)) - { - // cache directory possibly left after aborted - // or failed run earlier - $this->remove_cache_dir(); - } - $this->create_cache_dir(); - } - - protected function tearDown() - { - if (file_exists($this->cache_dir)) - { - $this->remove_cache_dir(); - } - - parent::tearDown(); - } - - private function create_cache_dir() - { - $this->get_test_case_helpers()->makedirs($this->cache_dir); - } - - private function remove_cache_dir() - { - $iterator = new DirectoryIterator($this->cache_dir); - foreach ($iterator as $file) - { - if ($file != '.' && $file != '..') - { - unlink($this->cache_dir . '/' . $file); - } - } - rmdir($this->cache_dir); - } - - public function test_cache_driver_file() - { - $driver = new phpbb_cache_driver_file($this->cache_dir); - $driver->put('test_key', 'test_value'); - $driver->save(); - - $this->assertEquals( - 'test_value', - $driver->get('test_key'), - 'File ACM put and get' - ); - } - - public function test_cache_sql_file() - { - $driver = new phpbb_cache_driver_file($this->cache_dir); - - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($driver); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $cache_path = $this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'; - $this->assertFileNotExists($cache_path); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertFileExists($cache_path); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } - - public function test_cache_sql_redis() - { - if (!extension_loaded('redis')) - { - $this->markTestSkipped('redis extension is not loaded'); - } - - $config = phpbb_test_case_helpers::get_test_config(); - if (isset($config['redis_host']) || isset($config['redis_port'])) - { - $host = isset($config['redis_host']) ? $config['redis_host'] : 'localhost'; - $port = isset($config['redis_port']) ? $config['redis_port'] : 6379; - } - else - { - $this->markTestSkipped('Test redis host/port is not specified'); - } - $driver = new phpbb_cache_driver_redis($host, $port); - $driver->purge(); - - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($driver); - - $redis = new Redis(); - $ok = $redis->connect($host, $port); - $this->assertTrue($ok); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $key = $driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); - $this->assertFalse($redis->exists($key)); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertTrue($redis->exists($key)); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } - - public function test_null_cache_sql() - { - $driver = new phpbb_cache_driver_null($this->cache_dir); - - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($driver); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - // As null cache driver does not actually cache, - // this should return no results - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertSame(false, $db->sql_fetchrow($result)); - - $db->sql_close(); - } -} diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php new file mode 100644 index 0000000000..436bd2f6bc --- /dev/null +++ b/tests/cache/file_driver_test.php @@ -0,0 +1,117 @@ +cache_dir = dirname(__FILE__) . '/../tmp/cache/'; + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + protected function setUp() + { + parent::setUp(); + + if (file_exists($this->cache_dir)) + { + // cache directory possibly left after aborted + // or failed run earlier + $this->remove_cache_dir(); + } + $this->create_cache_dir(); + + $this->driver = new phpbb_cache_driver_file($this->cache_dir); + } + + protected function tearDown() + { + if (file_exists($this->cache_dir)) + { + $this->remove_cache_dir(); + } + + parent::tearDown(); + } + + private function create_cache_dir() + { + $this->get_test_case_helpers()->makedirs($this->cache_dir); + } + + private function remove_cache_dir() + { + $iterator = new DirectoryIterator($this->cache_dir); + foreach ($iterator as $file) + { + if ($file != '.' && $file != '..') + { + unlink($this->cache_dir . '/' . $file); + } + } + rmdir($this->cache_dir); + } + + public function test_cache_driver_file() + { + $this->driver->put('test_key', 'test_value'); + $this->driver->save(); + + $this->assertEquals( + 'test_value', + $this->driver->get('test_key'), + 'File ACM put and get' + ); + } + + public function test_cache_sql_file() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $cache_path = $this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'; + $this->assertFileNotExists($cache_path); + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $this->assertFileExists($cache_path); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } +} diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php new file mode 100644 index 0000000000..7bf72931a0 --- /dev/null +++ b/tests/cache/null_driver_test.php @@ -0,0 +1,45 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + public function test_null_cache_sql() + { + $driver = new phpbb_cache_driver_null; + + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + // As null cache driver does not actually cache, + // this should return no results + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertSame(false, $db->sql_fetchrow($result)); + + $db->sql_close(); + } +} diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php new file mode 100644 index 0000000000..be8b518dca --- /dev/null +++ b/tests/cache/redis_driver_test.php @@ -0,0 +1,89 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + static public function setUpBeforeClass() + { + if (!extension_loaded('redis')) + { + self::markTestSkipped('redis extension is not loaded'); + } + + $config = phpbb_test_case_helpers::get_test_config(); + if (isset($config['redis_host']) || isset($config['redis_port'])) + { + $host = isset($config['redis_host']) ? $config['redis_host'] : 'localhost'; + $port = isset($config['redis_port']) ? $config['redis_port'] : 6379; + self::$config = array('host' => $host, 'port' => $port); + } + else + { + $this->markTestSkipped('Test redis host/port is not specified'); + } + } + + protected function setUp() + { + parent::setUp(); + + $this->driver = new phpbb_cache_driver_redis(self::$config['host'], self::$config['port']); + $this->driver->purge(); + } + + public function test_cache_sql_redis() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $redis = new Redis(); + $ok = $redis->connect(self::$config['host'], self::$config['port']); + $this->assertTrue($ok); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $key = $this->driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); + $this->assertFalse($redis->exists($key)); + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $this->assertTrue($redis->exists($key)); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } +} From 829b75e5c8d7b053f3988db89f6f9505102c92b3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 15:06:32 -0500 Subject: [PATCH 592/645] [ticket/9983] Create driver in setup in null driver test. PHPBB3-9983 --- tests/cache/null_driver_test.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index 7bf72931a0..45e53edaa1 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -9,18 +9,25 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case { + protected $driver; + public function getDataSet() { return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } + protected function setUp() + { + parent::setUp(); + + $this->driver = new phpbb_cache_driver_null; + } + public function test_null_cache_sql() { - $driver = new phpbb_cache_driver_null; - global $db, $cache; $db = $this->new_dbal(); - $cache = new phpbb_cache_service($driver); + $cache = new phpbb_cache_service($this->driver); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; From c3d1408c52dabcafa314fcc13d19f0c537d3a5df Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:49:27 -0500 Subject: [PATCH 593/645] [ticket/9983] get/put cache test moved to a base class. PHPBB3-9983 --- tests/cache/common_test_case.php | 24 ++++++++++++++++++++++++ tests/cache/file_driver_test.php | 16 +++------------- tests/cache/null_driver_test.php | 10 ++++++++++ tests/cache/redis_driver_test.php | 4 +++- 4 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 tests/cache/common_test_case.php diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php new file mode 100644 index 0000000000..059ce25133 --- /dev/null +++ b/tests/cache/common_test_case.php @@ -0,0 +1,24 @@ +assertSame(false, $this->driver->get('test_key')); + + $this->driver->put('test_key', 'test_value'); + + $this->assertEquals( + 'test_value', + $this->driver->get('test_key'), + 'File ACM put and get' + ); + } +} diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php index 436bd2f6bc..67408cc6d9 100644 --- a/tests/cache/file_driver_test.php +++ b/tests/cache/file_driver_test.php @@ -7,7 +7,9 @@ * */ -class phpbb_cache_file_driver_test extends phpbb_database_test_case +require_once dirname(__FILE__) . '/common_test_case.php'; + +class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case { private $cache_dir; protected $driver; @@ -65,18 +67,6 @@ class phpbb_cache_file_driver_test extends phpbb_database_test_case rmdir($this->cache_dir); } - public function test_cache_driver_file() - { - $this->driver->put('test_key', 'test_value'); - $this->driver->save(); - - $this->assertEquals( - 'test_value', - $this->driver->get('test_key'), - 'File ACM put and get' - ); - } - public function test_cache_sql_file() { global $db, $cache; diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index 45e53edaa1..efa56762bf 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -23,6 +23,16 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case $this->driver = new phpbb_cache_driver_null; } + public function test_get_put() + { + $this->assertSame(false, $this->driver->get('key')); + + $this->driver->put('key', 'value'); + + // null driver does not cache + $this->assertSame(false, $this->driver->get('key')); + } + public function test_null_cache_sql() { global $db, $cache; diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php index be8b518dca..bf8e49eb65 100644 --- a/tests/cache/redis_driver_test.php +++ b/tests/cache/redis_driver_test.php @@ -7,7 +7,9 @@ * */ -class phpbb_cache_redis_driver_test extends phpbb_database_test_case +require_once dirname(__FILE__) . '/common_test_case.php'; + +class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case { protected static $config; protected $driver; From 90bd7858fdf418c45bac1b30a4dc634cd23f5247 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:52:04 -0500 Subject: [PATCH 594/645] [ticket/9983] Rename test methods. PHPBB3-9983 --- tests/cache/file_driver_test.php | 2 +- tests/cache/null_driver_test.php | 2 +- tests/cache/redis_driver_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php index 67408cc6d9..2353940277 100644 --- a/tests/cache/file_driver_test.php +++ b/tests/cache/file_driver_test.php @@ -67,7 +67,7 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case rmdir($this->cache_dir); } - public function test_cache_sql_file() + public function test_cache_sql() { global $db, $cache; $db = $this->new_dbal(); diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index efa56762bf..a9b40c5f40 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -33,7 +33,7 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case $this->assertSame(false, $this->driver->get('key')); } - public function test_null_cache_sql() + public function test_cache_sql() { global $db, $cache; $db = $this->new_dbal(); diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php index bf8e49eb65..cd24e33baf 100644 --- a/tests/cache/redis_driver_test.php +++ b/tests/cache/redis_driver_test.php @@ -47,7 +47,7 @@ class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case $this->driver->purge(); } - public function test_cache_sql_redis() + public function test_cache_sql() { global $db, $cache; $db = $this->new_dbal(); From d9e636fab0b1c2de36e38e7bdd3498711108a0e6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:53:13 -0500 Subject: [PATCH 595/645] [ticket/9983] Add a purge test. PHPBB3-9983 --- tests/cache/common_test_case.php | 15 +++++++++++++++ tests/cache/null_driver_test.php | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index 059ce25133..c44dbf5250 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -21,4 +21,19 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case 'File ACM put and get' ); } + + public function test_purge() + { + $this->driver->put('test_key', 'test_value'); + + $this->assertEquals( + 'test_value', + $this->driver->get('test_key'), + 'File ACM put and get' + ); + + $this->driver->purge(); + + $this->assertSame(false, $this->driver->get('test_key')); + } } diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index a9b40c5f40..1e8b254294 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -33,6 +33,12 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case $this->assertSame(false, $this->driver->get('key')); } + public function test_purge() + { + // does nothing + $this->driver->purge(); + } + public function test_cache_sql() { global $db, $cache; From 8595b1f56018d0bfac0b83ac1511175c88a8b9cb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:57:09 -0500 Subject: [PATCH 596/645] [ticket/9983] Exercise exists also. PHPBB3-9983 --- tests/cache/common_test_case.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index c44dbf5250..5c387d98a1 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -9,12 +9,14 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case { - public function test_get_put() + public function test_get_put_exists() { + $this->assertFalse($this->driver->_exists('test_key')); $this->assertSame(false, $this->driver->get('test_key')); $this->driver->put('test_key', 'test_value'); + $this->assertTrue($this->driver->_exists('test_key')); $this->assertEquals( 'test_value', $this->driver->get('test_key'), From dd36b128e80112ba47ae51dca47702209e8aac18 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 1 Dec 2012 18:59:28 -0500 Subject: [PATCH 597/645] [ticket/9983] Add a test for destroy. PHPBB3-9983 --- tests/cache/common_test_case.php | 23 +++++++++++++++++++++++ tests/cache/null_driver_test.php | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index 5c387d98a1..45cf80e424 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -38,4 +38,27 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case $this->assertSame(false, $this->driver->get('test_key')); } + + public function test_destroy() + { + $this->driver->put('first_key', 'first_value'); + $this->driver->put('second_key', 'second_value'); + + $this->assertEquals( + 'first_value', + $this->driver->get('first_key') + ); + $this->assertEquals( + 'second_value', + $this->driver->get('second_key') + ); + + $this->driver->destroy('first_key'); + + $this->assertFalse($this->driver->_exists('first_key')); + $this->assertEquals( + 'second_value', + $this->driver->get('second_key') + ); + } } diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index 1e8b254294..86553d4dc5 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -39,6 +39,12 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case $this->driver->purge(); } + public function test_destroy() + { + // does nothing + $this->driver->destroy('foo'); + } + public function test_cache_sql() { global $db, $cache; From 720ef233b122d00ef9d2128c9a0a518ff017b0d7 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Sat, 1 Dec 2012 22:34:03 -0600 Subject: [PATCH 598/645] [ticket/11219] Only update sequences that are affected by a fixture PHPBB3-11219 --- .../phpbb_database_test_case.php | 18 +++-- ...phpbb_database_test_connection_manager.php | 73 +++++++++++-------- 2 files changed, 55 insertions(+), 36 deletions(-) diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 0916679108..429bb92bf1 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -13,6 +13,8 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test protected $test_case_helpers; + protected $fixture_xml_data; + public function __construct($name = NULL, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); @@ -32,10 +34,14 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { parent::setUp(); - $config = $this->get_database_config(); - $manager = $this->create_connection_manager($config); - $manager->connect(); - $manager->post_setup_synchronisation(); + // Resynchronise tables if a fixture was loaded + if (isset($this->fixture_xml_data)) + { + $config = $this->get_database_config(); + $manager = $this->create_connection_manager($config); + $manager->connect(); + $manager->post_setup_synchronisation($this->fixture_xml_data); + } } public function createXMLDataSet($path) @@ -57,7 +63,9 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $path = $meta_data['uri']; } - return parent::createXMLDataSet($path); + $this->fixture_xml_data = parent::createXMLDataSet($path); + + return $this->fixture_xml_data; } public function get_test_case_helpers() diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index e79a764e1d..97281a0812 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -429,12 +429,19 @@ class phpbb_database_test_connection_manager /** * Performs synchronisations on the database after a fixture has been loaded + * + * @param PHPUnit_Extensions_Database_DataSet_XmlDataSet $tables Tables contained within the loaded fixture + * + * @return null */ - public function post_setup_synchronisation() + public function post_setup_synchronisation($xmlDataSet) { $this->ensure_connected(__METHOD__); $queries = array(); + // Get escaped versions of the table names used in the fixture + $table_names = array_map(array($this->pdo, 'PDO::quote'), $xmlDataSet->getTableNames()); + switch ($this->config['dbms']) { case 'oracle': @@ -445,7 +452,9 @@ class phpbb_database_test_connection_manager JOIN USER_TRIGGER_COLS tc ON (tc.trigger_name = t.trigger_name) JOIN USER_SEQUENCES s ON (s.sequence_name = d.referenced_name) WHERE d.referenced_type = 'SEQUENCE' - AND d.type = 'TRIGGER'"; + AND d.type = 'TRIGGER' + AND t.table_name IN (" . implode(', ', array_map('strtoupper', $table_names)) . ')'; + $result = $this->pdo->query($sql); while ($row = $result->fetch(PDO::FETCH_ASSOC)) @@ -476,41 +485,43 @@ class phpbb_database_test_connection_manager break; case 'postgres': - // First get the sequences - $sequences = array(); - $sql = "SELECT relname FROM pg_class WHERE relkind = 'S'"; + // Get the sequences attached to the tables + $sql = 'SELECT column_name, table_name FROM information_schema.columns + WHERE table_name IN (' . implode(', ', $table_names) . ") + AND strpos(column_default, '_seq''::regclass') > 0"; $result = $this->pdo->query($sql); + + $setval_queries = array(); while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $sequences[] = $row['relname']; + // Get the columns used in the fixture for this table + $column_names = $xmlDataSet->getTableMetaData($row['table_name'])->getColumns(); + + // Skip sequences that weren't specified in the fixture + if (!in_array($row['column_name'], $column_names)) + { + continue; + } + + // Get the old value if it exists, or use 1 if it doesn't + $sql = "SELECT COALESCE((SELECT MAX({$row['column_name']}) + 1 FROM {$row['table_name']}), 1) AS val"; + $result_max = $this->pdo->query($sql); + $row_max = $result_max->fetch(PDO::FETCH_ASSOC); + + if ($row_max) + { + $seq_name = $this->pdo->quote($row['table_name'] . '_seq'); + $max_val = (int) $row_max['val']; + + // The last parameter is false so that the system doesn't increment it again + $setval_queries[] = "SETVAL($seq_name, $max_val, false)"; + } } - // Now get the name of the column using it - foreach ($sequences as $sequence) + // Combine all of the SETVALs into one query + if (sizeof($setval_queries)) { - $table = str_replace('_seq', '', $sequence); - $sql = "SELECT column_name FROM information_schema.columns - WHERE table_name = '$table' - AND column_default = 'nextval(''$sequence''::regclass)'"; - $result = $this->pdo->query($sql); - $row = $result->fetch(PDO::FETCH_ASSOC); - - // Finally, set the new sequence value - if ($row) - { - $column = $row['column_name']; - - // Get the old value if it exists, or use 1 if it doesn't - $sql = "SELECT COALESCE((SELECT MAX({$column}) + 1 FROM {$table}), 1) AS val"; - $result = $this->pdo->query($sql); - $row = $result->fetch(PDO::FETCH_ASSOC); - - if ($row) - { - // The last parameter is false so that the system doesn't increment it again - $queries[] = "SELECT SETVAL('{$sequence}', {$row['val']}, false)"; - } - } + $queries[] = 'SELECT ' . implode(', ', $setval_queries); } break; } From dacacbbd52dc22f3344f313301cf6b4fb0f77233 Mon Sep 17 00:00:00 2001 From: Hari Sankar R Date: Sun, 15 Apr 2012 13:08:44 +0530 Subject: [PATCH 599/645] [ticket/10771] Using Remember Me instead of autologin or persistent keys Changed language variable LOG_ME_IN's value to "Remember me" PHPBB3-10771 --- 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 4300ef431a..71f1beb66a 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -343,7 +343,7 @@ $lang = array_merge($lang, array( 'LOGIN_EXPLAIN_VIEWONLINE' => 'In order to view the online list you have to be registered and logged in.', 'LOGOUT' => 'Logout', 'LOGOUT_USER' => 'Logout [ %s ]', - 'LOG_ME_IN' => 'Log me on automatically each visit', + 'LOG_ME_IN' => 'Remember me', 'MARK' => 'Mark', 'MARK_ALL' => 'Mark all', From a17c1a29f8ce5781082dcf87a8bde261647062f0 Mon Sep 17 00:00:00 2001 From: Hari Sankar R Date: Wed, 18 Apr 2012 12:13:00 +0530 Subject: [PATCH 600/645] [ticket/10771] changed value in help_faq.php PHPBB3-10771 --- phpBB/language/en/help_faq.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/language/en/help_faq.php b/phpBB/language/en/help_faq.php index 5c99f81c06..9500943b88 100644 --- a/phpBB/language/en/help_faq.php +++ b/phpBB/language/en/help_faq.php @@ -43,7 +43,7 @@ $help = array( ), array( 0 => 'Why do I get logged off automatically?', - 1 => 'If you do not check the Log me in automatically box when you login, the board will only keep you logged in for a preset time. This prevents misuse of your account by anyone else. To stay logged in, check the box during login. This is not recommended if you access the board from a shared computer, e.g. library, internet cafe, university computer lab, etc. If you do not see this checkbox, it means the board administrator has disabled this feature.' + 1 => 'If you do not check the Remember me box when you login, the board will only keep you logged in for a preset time. This prevents misuse of your account by anyone else. To stay logged in, check the box during login. This is not recommended if you access the board from a shared computer, e.g. library, internet cafe, university computer lab, etc. If you do not see this checkbox, it means the board administrator has disabled this feature.' ), array( 0 => 'How do I prevent my username appearing in the online user listings?', From a97401a180657b8b9526c5a0af055d46cf3e8487 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 11 Nov 2012 00:03:22 +0100 Subject: [PATCH 601/645] [ticket/10771] use remember me in acp PHPBB3-10771 --- phpBB/language/en/acp/board.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index a4380486cc..4adcbd689e 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -449,10 +449,10 @@ $lang = array_merge($lang, array( 'ACP_SECURITY_SETTINGS_EXPLAIN' => 'Here you are able to define session and login related settings.', 'ALL' => 'All', - 'ALLOW_AUTOLOGIN' => 'Allow persistent logins', - 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users can autologin when they visit the board.', - 'AUTOLOGIN_LENGTH' => 'Persistent login key expiration length (in days)', - 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which persistent login keys are removed or zero to disable.', + 'ALLOW_AUTOLOGIN' => 'Allow remember me logins', + 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users can select remember me option when they visit the board.', + 'AUTOLOGIN_LENGTH' => 'Remember me login key expiration length (in days)', + 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which remember me login keys are removed or zero to disable.', 'BROWSER_VALID' => 'Validate browser', 'BROWSER_VALID_EXPLAIN' => 'Enables browser validation for each session improving security.', 'CHECK_DNSBL' => 'Check IP against DNS Blackhole List', From 619e15378dd6839b26ceb7a698b8d07fa5ebbec9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 11 Nov 2012 00:03:45 +0100 Subject: [PATCH 602/645] [ticket/10771] use remember me in ucp PHPBB3-10771 --- phpBB/language/en/ucp.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 705b07b170..0ae58392d5 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -87,7 +87,7 @@ $lang = array_merge($lang, array( 'ATTACHMENTS_EXPLAIN' => 'This is a list of attachments you have made in posts to this board.', 'ATTACHMENTS_DELETED' => 'Attachments successfully deleted.', 'ATTACHMENT_DELETED' => 'Attachment successfully deleted.', - 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected persistent login keys were successfully deleted.', + 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected remember me login keys were successfully deleted.', 'AVATAR_CATEGORY' => 'Category', 'AVATAR_EXPLAIN' => 'Maximum dimensions; width: %1$s, height: %2$s, file size: %3$.2f KiB.', 'AVATAR_FEATURES_DISABLED' => 'The avatar functionality is currently disabled.', @@ -380,8 +380,8 @@ $lang = array_merge($lang, array( 'PREFERENCES_UPDATED' => 'Your preferences have been updated.', 'PROFILE_INFO_NOTICE' => 'Please note that this information may be viewable to other members. Be careful when including any personal details. Any fields marked with a * must be completed.', 'PROFILE_UPDATED' => 'Your profile has been updated.', - 'PROFILE_AUTOLOGIN_KEYS' => 'The persistent login keys automatically log you in when you visit the board. If you logout, the persistent login key is deleted only on the computer you are using to logout. Here you can see persistent login keys created on other computers you used to access this site.', - 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved persistent login keys.', + 'PROFILE_AUTOLOGIN_KEYS' => 'The remember me login keys automatically log you in when you visit the board. If you logout, the remember me login key is deleted only on the computer you are using to logout. Here you can see remember login keys created on other computers you used to access this site.', + 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved remember me login keys.', 'RECIPIENT' => 'Recipient', 'RECIPIENTS' => 'Recipients', @@ -476,7 +476,7 @@ $lang = array_merge($lang, array( 'UCP_PROFILE_PROFILE_INFO' => 'Edit profile', 'UCP_PROFILE_REG_DETAILS' => 'Edit account settings', 'UCP_PROFILE_SIGNATURE' => 'Edit signature', - 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit persistent login keys', + 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit remember me login keys', 'UCP_USERGROUPS' => 'Usergroups', 'UCP_USERGROUPS_MEMBER' => 'Edit memberships', From 37f2841af2d1027b92953ee2c08da44481d0a06e Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 2 Dec 2012 15:20:43 +0530 Subject: [PATCH 603/645] [ticket/10771] fix remember me language PHPBB3-10771 --- phpBB/language/en/acp/board.php | 8 ++++---- phpBB/language/en/ucp.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index 4adcbd689e..1b99c87938 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -449,10 +449,10 @@ $lang = array_merge($lang, array( 'ACP_SECURITY_SETTINGS_EXPLAIN' => 'Here you are able to define session and login related settings.', 'ALL' => 'All', - 'ALLOW_AUTOLOGIN' => 'Allow remember me logins', - 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users can select remember me option when they visit the board.', - 'AUTOLOGIN_LENGTH' => 'Remember me login key expiration length (in days)', - 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which remember me login keys are removed or zero to disable.', + 'ALLOW_AUTOLOGIN' => 'Allow "Remember Me" logins', + 'ALLOW_AUTOLOGIN_EXPLAIN' => 'Determines whether users are given "Remember Me" option when they visit the board.', + 'AUTOLOGIN_LENGTH' => '"Remember Me" login key expiration length (in days)', + 'AUTOLOGIN_LENGTH_EXPLAIN' => 'Number of days after which "Remember Me" login keys are removed or zero to disable.', 'BROWSER_VALID' => 'Validate browser', 'BROWSER_VALID_EXPLAIN' => 'Enables browser validation for each session improving security.', 'CHECK_DNSBL' => 'Check IP against DNS Blackhole List', diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index 0ae58392d5..b919699ea0 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -87,7 +87,7 @@ $lang = array_merge($lang, array( 'ATTACHMENTS_EXPLAIN' => 'This is a list of attachments you have made in posts to this board.', 'ATTACHMENTS_DELETED' => 'Attachments successfully deleted.', 'ATTACHMENT_DELETED' => 'Attachment successfully deleted.', - 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected remember me login keys were successfully deleted.', + 'AUTOLOGIN_SESSION_KEYS_DELETED'=> 'The selected "Remember Me" login keys were successfully deleted.', 'AVATAR_CATEGORY' => 'Category', 'AVATAR_EXPLAIN' => 'Maximum dimensions; width: %1$s, height: %2$s, file size: %3$.2f KiB.', 'AVATAR_FEATURES_DISABLED' => 'The avatar functionality is currently disabled.', @@ -380,8 +380,8 @@ $lang = array_merge($lang, array( 'PREFERENCES_UPDATED' => 'Your preferences have been updated.', 'PROFILE_INFO_NOTICE' => 'Please note that this information may be viewable to other members. Be careful when including any personal details. Any fields marked with a * must be completed.', 'PROFILE_UPDATED' => 'Your profile has been updated.', - 'PROFILE_AUTOLOGIN_KEYS' => 'The remember me login keys automatically log you in when you visit the board. If you logout, the remember me login key is deleted only on the computer you are using to logout. Here you can see remember login keys created on other computers you used to access this site.', - 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved remember me login keys.', + 'PROFILE_AUTOLOGIN_KEYS' => 'The "Remember Me" login keys automatically log you in when you visit the board. If you logout, the remember me login key is deleted only on the computer you are using to logout. Here you can see remember login keys created on other computers you used to access this site.', + 'PROFILE_NO_AUTOLOGIN_KEYS' => 'There are no saved "Remember Me" login keys.', 'RECIPIENT' => 'Recipient', 'RECIPIENTS' => 'Recipients', @@ -476,7 +476,7 @@ $lang = array_merge($lang, array( 'UCP_PROFILE_PROFILE_INFO' => 'Edit profile', 'UCP_PROFILE_REG_DETAILS' => 'Edit account settings', 'UCP_PROFILE_SIGNATURE' => 'Edit signature', - 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit remember me login keys', + 'UCP_PROFILE_AUTOLOGIN_KEYS'=> 'Edit "Remember Me" login keys', 'UCP_USERGROUPS' => 'Usergroups', 'UCP_USERGROUPS_MEMBER' => 'Edit memberships', From 9d5fc4ae33ac5a5ea2dc85fd4157ce56653c4a16 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 2 Dec 2012 13:16:11 -0500 Subject: [PATCH 604/645] [ticket/11238] Set goutte to 0.1.0 in develop. PHPBB3-11238 --- phpBB/composer.json | 2 +- phpBB/composer.lock | 170 +++++++++++++++++--------------------------- 2 files changed, 68 insertions(+), 104 deletions(-) diff --git a/phpBB/composer.json b/phpBB/composer.json index 5a03e68f73..d2536a73cf 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -9,6 +9,6 @@ "symfony/yaml": "2.1.*" }, "require-dev": { - "fabpot/goutte": "1.0.x-dev" + "fabpot/goutte": "v0.1.0" } } diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 62ece6d505..e96c15fe8b 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,5 +1,5 @@ { - "hash": "efb4768ba71d7cd2c84baa0610d84067", + "hash": "c1a76530df6b9daa16b8033d61b76503", "packages": [ { "name": "symfony/config", @@ -381,29 +381,29 @@ "packages-dev": [ { "name": "fabpot/goutte", - "version": "dev-master", + "version": "v0.1.0", "source": { "type": "git", "url": "https://github.com/fabpot/Goutte", - "reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48" + "reference": "v0.1.0" }, "dist": { "type": "zip", - "url": "https://github.com/fabpot/Goutte/archive/f2940f9c7c1f409159f5e9f512e575946c5cff48.zip", - "reference": "f2940f9c7c1f409159f5e9f512e575946c5cff48", + "url": "https://github.com/fabpot/Goutte/archive/v0.1.0.zip", + "reference": "v0.1.0", "shasum": "" }, "require": { "php": ">=5.3.0", + "ext-curl": "*", "symfony/browser-kit": "2.1.*", "symfony/css-selector": "2.1.*", "symfony/dom-crawler": "2.1.*", "symfony/finder": "2.1.*", "symfony/process": "2.1.*", - "ext-curl": "*", - "guzzle/http": "2.8.*" + "guzzle/guzzle": "3.0.*" }, - "time": "1351086217", + "time": "2012-12-02 13:44:35", "type": "application", "extra": { "branch-alias": { @@ -432,126 +432,90 @@ ] }, { - "name": "guzzle/common", - "version": "v2.8.8", - "target-dir": "Guzzle/Common", + "name": "guzzle/guzzle", + "version": "v3.0.5", "source": { "type": "git", - "url": "git://github.com/guzzle/common.git", - "reference": "v2.8.8" + "url": "https://github.com/guzzle/guzzle", + "reference": "v3.0.5" }, "dist": { "type": "zip", - "url": "https://github.com/guzzle/common/zipball/v2.8.8", - "reference": "v2.8.8", + "url": "https://github.com/guzzle/guzzle/archive/v3.0.5.zip", + "reference": "v3.0.5", "shasum": "" }, "require": { "php": ">=5.3.2", + "ext-curl": "*", "symfony/event-dispatcher": "2.1.*" }, - "time": "2012-10-15 17:42:47", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Common": "" - } - }, - "license": [ - "MIT" - ], - "description": "Common libraries used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "log", - "event", - "cache", - "validation", - "Socket", - "common", - "batch", - "inflection" - ] - }, - { - "name": "guzzle/http", - "version": "v2.8.8", - "target-dir": "Guzzle/Http", - "source": { - "type": "git", - "url": "git://github.com/guzzle/http.git", - "reference": "v2.8.8" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/http/zipball/v2.8.8", - "reference": "v2.8.8", - "shasum": "" - }, - "require": { - "php": ">=5.3.2", + "replace": { + "guzzle/batch": "self.version", + "guzzle/cache": "self.version", "guzzle/common": "self.version", - "guzzle/parser": "self.version" + "guzzle/http": "self.version", + "guzzle/inflection": "self.version", + "guzzle/iterator": "self.version", + "guzzle/log": "self.version", + "guzzle/parser": "self.version", + "guzzle/plugin": "self.version", + "guzzle/plugin-async": "self.version", + "guzzle/plugin-backoff": "self.version", + "guzzle/plugin-cache": "self.version", + "guzzle/plugin-cookie": "self.version", + "guzzle/plugin-curlauth": "self.version", + "guzzle/plugin-history": "self.version", + "guzzle/plugin-log": "self.version", + "guzzle/plugin-md5": "self.version", + "guzzle/plugin-mock": "self.version", + "guzzle/plugin-oauth": "self.version", + "guzzle/service": "self.version", + "guzzle/stream": "self.version" }, - "time": "2012-10-15 17:42:47", + "require-dev": { + "doctrine/common": "*", + "symfony/class-loader": "*", + "monolog/monolog": "1.*", + "zendframework/zend-cache": "2.0.*", + "zendframework/zend-log": "2.0.*", + "zend/zend-log1": "1.12", + "zend/zend-cache1": "1.12", + "phpunit/phpunit": "3.7.*" + }, + "time": "2012-11-19 00:15:33", "type": "library", "installation-source": "dist", "autoload": { "psr-0": { - "Guzzle\\Http": "" + "Guzzle\\Tests": "tests/", + "Guzzle": "src/" } }, "license": [ "MIT" ], - "description": "HTTP libraries used by Guzzle", + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Guzzle Community", + "homepage": "https://github.com/guzzle/guzzle/contributors" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", "homepage": "http://guzzlephp.org/", "keywords": [ + "framework", "curl", "http", + "rest", "http client", "client", - "Guzzle" - ] - }, - { - "name": "guzzle/parser", - "version": "v2.8.8", - "target-dir": "Guzzle/Parser", - "source": { - "type": "git", - "url": "git://github.com/guzzle/parser.git", - "reference": "v2.8.8" - }, - "dist": { - "type": "zip", - "url": "https://github.com/guzzle/parser/zipball/v2.8.8", - "reference": "v2.8.8", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "time": "2012-09-20 13:28:06", - "type": "library", - "installation-source": "dist", - "autoload": { - "psr-0": { - "Guzzle\\Parser": "" - } - }, - "license": [ - "MIT" - ], - "description": "Interchangeable parsers used by Guzzle", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "http", - "url", - "message", - "cookie", - "URI Template" + "web service" ] }, { @@ -808,7 +772,7 @@ ], "minimum-stability": "beta", - "stability-flags": { - "fabpot/goutte": 20 - } + "stability-flags": [ + + ] } From 6f7e39996c926b0f0080ccdd594fd465c311cb79 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 2 Dec 2012 23:44:49 -0500 Subject: [PATCH 605/645] [ticket/11238] Set goutte version to 0.1.0. PHPBB3-11238 --- phpBB/composer.json | 2 +- phpBB/composer.lock | 463 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 433 insertions(+), 32 deletions(-) diff --git a/phpBB/composer.json b/phpBB/composer.json index c2811ad1d7..8d5dd1d52e 100644 --- a/phpBB/composer.json +++ b/phpBB/composer.json @@ -1,6 +1,6 @@ { "minimum-stability": "beta", "require-dev": { - "fabpot/goutte": "1.0.x-dev" + "fabpot/goutte": "v0.1.0" } } diff --git a/phpBB/composer.lock b/phpBB/composer.lock index 9f2195e70a..a78fff9a14 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -1,55 +1,456 @@ { - "hash": "a5d02c59e3a91c84c1a96aca0f1ae81a", + "hash": "23352b29002e6d22658e314a8e737f71", "packages": [ - + { + "name": "symfony/event-dispatcher", + "version": "v2.1.4", + "target-dir": "Symfony/Component/EventDispatcher", + "source": { + "type": "git", + "url": "https://github.com/symfony/EventDispatcher", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/EventDispatcher/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/dependency-injection": "2.1.*" + }, + "suggest": { + "symfony/dependency-injection": "2.1.*", + "symfony/http-kernel": "2.1.*" + }, + "time": "2012-11-08 09:51:48", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\EventDispatcher": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "http://symfony.com" + } ], "packages-dev": [ { - "package": "fabpot/goutte", - "version": "dev-master", - "alias-pretty-version": "1.0.x-dev", - "alias-version": "1.0.9999999.9999999-dev" + "name": "fabpot/goutte", + "version": "v0.1.0", + "source": { + "type": "git", + "url": "https://github.com/fabpot/Goutte", + "reference": "v0.1.0" + }, + "dist": { + "type": "zip", + "url": "https://github.com/fabpot/Goutte/archive/v0.1.0.zip", + "reference": "v0.1.0", + "shasum": "" + }, + "require": { + "php": ">=5.3.0", + "ext-curl": "*", + "symfony/browser-kit": "2.1.*", + "symfony/css-selector": "2.1.*", + "symfony/dom-crawler": "2.1.*", + "symfony/finder": "2.1.*", + "symfony/process": "2.1.*", + "guzzle/guzzle": "3.0.*" + }, + "time": "2012-12-02 13:44:35", + "type": "application", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "installation-source": "source", + "autoload": { + "psr-0": { + "Goutte": "." + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "A simple PHP Web Scraper", + "homepage": "https://github.com/fabpot/Goutte", + "keywords": [ + "scraper" + ] }, { - "package": "fabpot/goutte", - "version": "dev-master", - "source-reference": "c2ea8d9a6682d14482e57ede2371001b8a5238d2", - "commit-date": "1340264258" + "name": "guzzle/guzzle", + "version": "v3.0.5", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle", + "reference": "v3.0.5" + }, + "dist": { + "type": "zip", + "url": "https://github.com/guzzle/guzzle/archive/v3.0.5.zip", + "reference": "v3.0.5", + "shasum": "" + }, + "require": { + "php": ">=5.3.2", + "ext-curl": "*", + "symfony/event-dispatcher": "2.1.*" + }, + "replace": { + "guzzle/batch": "self.version", + "guzzle/cache": "self.version", + "guzzle/common": "self.version", + "guzzle/http": "self.version", + "guzzle/inflection": "self.version", + "guzzle/iterator": "self.version", + "guzzle/log": "self.version", + "guzzle/parser": "self.version", + "guzzle/plugin": "self.version", + "guzzle/plugin-async": "self.version", + "guzzle/plugin-backoff": "self.version", + "guzzle/plugin-cache": "self.version", + "guzzle/plugin-cookie": "self.version", + "guzzle/plugin-curlauth": "self.version", + "guzzle/plugin-history": "self.version", + "guzzle/plugin-log": "self.version", + "guzzle/plugin-md5": "self.version", + "guzzle/plugin-mock": "self.version", + "guzzle/plugin-oauth": "self.version", + "guzzle/service": "self.version", + "guzzle/stream": "self.version" + }, + "require-dev": { + "doctrine/common": "*", + "symfony/class-loader": "*", + "monolog/monolog": "1.*", + "zendframework/zend-cache": "2.0.*", + "zendframework/zend-log": "2.0.*", + "zend/zend-log1": "1.12", + "zend/zend-cache1": "1.12", + "phpunit/phpunit": "3.7.*" + }, + "time": "2012-11-19 00:15:33", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "Guzzle\\Tests": "tests/", + "Guzzle": "src/" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Guzzle Community", + "homepage": "https://github.com/guzzle/guzzle/contributors" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "framework", + "curl", + "http", + "rest", + "http client", + "client", + "web service" + ] }, { - "package": "guzzle/guzzle", - "version": "v2.6.6" + "name": "symfony/browser-kit", + "version": "v2.1.4", + "target-dir": "Symfony/Component/BrowserKit", + "source": { + "type": "git", + "url": "https://github.com/symfony/BrowserKit", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/BrowserKit/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/dom-crawler": "2.1.*" + }, + "require-dev": { + "symfony/process": "2.1.*", + "symfony/css-selector": "2.1.*" + }, + "suggest": { + "symfony/process": "2.1.*" + }, + "time": "2012-11-08 09:51:48", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\BrowserKit": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony BrowserKit Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/browser-kit", - "version": "v2.1.0-BETA3" + "name": "symfony/css-selector", + "version": "v2.1.4", + "target-dir": "Symfony/Component/CssSelector", + "source": { + "type": "git", + "url": "https://github.com/symfony/CssSelector", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/CssSelector/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-11-08 09:51:48", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\CssSelector": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony CssSelector Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/css-selector", - "version": "v2.1.0-BETA3" + "name": "symfony/dom-crawler", + "version": "v2.1.4", + "target-dir": "Symfony/Component/DomCrawler", + "source": { + "type": "git", + "url": "https://github.com/symfony/DomCrawler", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/DomCrawler/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/css-selector": "2.1.*" + }, + "suggest": { + "symfony/css-selector": "2.1.*" + }, + "time": "2012-11-29 10:32:18", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\DomCrawler": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony DomCrawler Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/dom-crawler", - "version": "v2.1.0-BETA3" + "name": "symfony/finder", + "version": "v2.1.4", + "target-dir": "Symfony/Component/Finder", + "source": { + "type": "git", + "url": "https://github.com/symfony/Finder", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Finder/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-11-08 09:51:48", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Finder": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "http://symfony.com" }, { - "package": "symfony/event-dispatcher", - "version": "v2.1.0-BETA3" - }, - { - "package": "symfony/finder", - "version": "v2.1.0-BETA3" - }, - { - "package": "symfony/process", - "version": "v2.1.0-BETA3" + "name": "symfony/process", + "version": "v2.1.4", + "target-dir": "Symfony/Component/Process", + "source": { + "type": "git", + "url": "https://github.com/symfony/Process", + "reference": "v2.1.4" + }, + "dist": { + "type": "zip", + "url": "https://github.com/symfony/Process/archive/v2.1.4.zip", + "reference": "v2.1.4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "time": "2012-11-19 20:53:52", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "Symfony\\Component\\Process": "" + } + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "http://symfony.com" } ], "aliases": [ ], "minimum-stability": "beta", - "stability-flags": { - "fabpot/goutte": 20 - } + "stability-flags": [ + + ] } From df78c616aadf57ebb00988b299b34d39b558fda1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 2 Dec 2012 23:54:59 -0500 Subject: [PATCH 606/645] [ticket/9983] Indeed, it is Date: Sun, 2 Dec 2012 23:55:42 -0500 Subject: [PATCH 607/645] [ticket/9983] Empty line by request. PHPBB3-9983 --- phpBB/includes/cache/driver/redis.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php index ae6f9e04f2..960735b673 100644 --- a/phpBB/includes/cache/driver/redis.php +++ b/phpBB/includes/cache/driver/redis.php @@ -67,6 +67,7 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory { $ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT); } + if (!$ok) { trigger_error('Could not connect to redis server'); From 7d09b9b4bb58e71f0e7b895ef32059ad08d12416 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 2 Dec 2012 23:57:37 -0500 Subject: [PATCH 608/645] [ticket/9983] Add phpbb prefix to global variables. PHPBB3-9983 --- tests/RUNNING_TESTS.txt | 4 ++-- tests/test_framework/phpbb_test_case_helpers.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 395cf1240a..75a6fc94f6 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -80,8 +80,8 @@ or port must be specified in test configuration. This can be done via test_config.php as follows: Date: Mon, 3 Dec 2012 00:18:52 -0500 Subject: [PATCH 609/645] [ticket/9983] Test for apc cache driver. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 79 +++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/cache/apc_driver_test.php diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php new file mode 100644 index 0000000000..f6e001f705 --- /dev/null +++ b/tests/cache/apc_driver_test.php @@ -0,0 +1,79 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + static public function setUpBeforeClass() + { + if (!extension_loaded('apc')) + { + self::markTestSkipped('apc extension is not loaded'); + } + } + + protected function setUp() + { + parent::setUp(); + + $this->driver = new phpbb_cache_driver_apc; + $this->driver->purge(); + } + + public function test_cache_sql() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $key = $this->driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); + $this->assertFalse(apc_fetch($key)); + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $this->assertTrue((bool) apc_fetch($key)); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } +} From 0b4b7e68a75438368868ede050bc6dd66fc80767 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Dec 2012 14:17:34 +0100 Subject: [PATCH 610/645] [ticket/9983] Skip tests if APC is not enabled for CLI. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index f6e001f705..f7cf2119ed 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -29,6 +29,12 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case { self::markTestSkipped('apc extension is not loaded'); } + + $php_ini = new phpbb_php_ini; + if (PHP_SAPI == 'cli' && !$php_ini->get_bool('apc.enable_cli')) + { + self::markTestSkipped('APC is not enabled for CLI. Set apc.enable_cli=1 in php.ini'); + } } protected function setUp() From 2e851baab90b0c9960eb7427acf41bfb8a848195 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Dec 2012 14:18:05 +0100 Subject: [PATCH 611/645] [ticket/9983] Use APC instead of apc in error messages. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index f7cf2119ed..100ba76686 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -27,7 +27,7 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case { if (!extension_loaded('apc')) { - self::markTestSkipped('apc extension is not loaded'); + self::markTestSkipped('APC extension is not loaded'); } $php_ini = new phpbb_php_ini; From db6b11a3902c27b612d7d6d4696c4cd8cf1f0bdf Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Dec 2012 14:35:59 +0100 Subject: [PATCH 612/645] [ticket/9983] Also check generic APC enable/disable. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index 100ba76686..c8b8f82b67 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -31,6 +31,12 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case } $php_ini = new phpbb_php_ini; + + if (!$php_ini->get_bool('apc.enabled')) + { + self::markTestSkipped('APC is not enabled. Make sure apc.enabled=1 in php.ini'); + } + if (PHP_SAPI == 'cli' && !$php_ini->get_bool('apc.enable_cli')) { self::markTestSkipped('APC is not enabled for CLI. Set apc.enable_cli=1 in php.ini'); From e845e2ed89f75a5c9f14191f833334d84d389faf Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 4 Dec 2012 00:40:24 +0100 Subject: [PATCH 613/645] [ticket/11240] Enable PHPUnit's verbose mode so we get a list of skipped tests. PHPBB3-11240 --- travis/phpunit-mysql-travis.xml | 1 + travis/phpunit-postgres-travis.xml | 1 + 2 files changed, 2 insertions(+) diff --git a/travis/phpunit-mysql-travis.xml b/travis/phpunit-mysql-travis.xml index e54b2bb77b..5366494c8b 100644 --- a/travis/phpunit-mysql-travis.xml +++ b/travis/phpunit-mysql-travis.xml @@ -9,6 +9,7 @@ stopOnFailure="false" syntaxCheck="true" strict="true" + verbose="true" bootstrap="../tests/bootstrap.php"> diff --git a/travis/phpunit-postgres-travis.xml b/travis/phpunit-postgres-travis.xml index 55ba996548..0383edd9d6 100644 --- a/travis/phpunit-postgres-travis.xml +++ b/travis/phpunit-postgres-travis.xml @@ -9,6 +9,7 @@ stopOnFailure="false" syntaxCheck="true" strict="true" + verbose="true" bootstrap="../tests/bootstrap.php"> From d93f582b04d2e6d0738cd6a2ffee739b8c987276 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Mon, 3 Dec 2012 21:47:29 -0500 Subject: [PATCH 614/645] [ticket/9983] Make sql cache test into a black box. This makes it non-driver-specific and also makes it possible to make prefix variable private on drivers. PHPBB3-9983 --- tests/cache/apc_driver_test.php | 38 ---------------------------- tests/cache/common_test_case.php | 33 ++++++++++++++++++++++++ tests/cache/file_driver_test.php | 38 ---------------------------- tests/cache/redis_driver_test.php | 42 ------------------------------- 4 files changed, 33 insertions(+), 118 deletions(-) diff --git a/tests/cache/apc_driver_test.php b/tests/cache/apc_driver_test.php index c8b8f82b67..3380762878 100644 --- a/tests/cache/apc_driver_test.php +++ b/tests/cache/apc_driver_test.php @@ -50,42 +50,4 @@ class phpbb_cache_apc_driver_test extends phpbb_cache_common_test_case $this->driver = new phpbb_cache_driver_apc; $this->driver->purge(); } - - public function test_cache_sql() - { - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $key = $this->driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); - $this->assertFalse(apc_fetch($key)); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertTrue((bool) apc_fetch($key)); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } } diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index 45cf80e424..fa298ec9ae 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -61,4 +61,37 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case $this->driver->get('second_key') ); } + + public function test_cache_sql() + { + global $db, $cache; + $db = $this->new_dbal(); + $cache = new phpbb_cache_service($this->driver); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + + $result = $db->sql_query($sql, 300); + $first_result = $db->sql_fetchrow($result); + $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); + $this->assertEquals($expected, $first_result); + + $sql = 'DELETE FROM phpbb_config'; + $result = $db->sql_query($sql); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql, 300); + + $this->assertEquals($expected, $db->sql_fetchrow($result)); + + $sql = "SELECT * FROM phpbb_config + WHERE config_name = 'foo'"; + $result = $db->sql_query($sql); + + $no_cache_result = $db->sql_fetchrow($result); + $this->assertSame(false, $no_cache_result); + + $db->sql_close(); + } } diff --git a/tests/cache/file_driver_test.php b/tests/cache/file_driver_test.php index 2353940277..745c6bb081 100644 --- a/tests/cache/file_driver_test.php +++ b/tests/cache/file_driver_test.php @@ -66,42 +66,4 @@ class phpbb_cache_file_driver_test extends phpbb_cache_common_test_case } rmdir($this->cache_dir); } - - public function test_cache_sql() - { - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $cache_path = $this->cache_dir . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)) . '.php'; - $this->assertFileNotExists($cache_path); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertFileExists($cache_path); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } } diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php index cd24e33baf..c59d5e1929 100644 --- a/tests/cache/redis_driver_test.php +++ b/tests/cache/redis_driver_test.php @@ -46,46 +46,4 @@ class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case $this->driver = new phpbb_cache_driver_redis(self::$config['host'], self::$config['port']); $this->driver->purge(); } - - public function test_cache_sql() - { - global $db, $cache; - $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); - - $redis = new Redis(); - $ok = $redis->connect(self::$config['host'], self::$config['port']); - $this->assertTrue($ok); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - - $key = $this->driver->key_prefix . 'sql_' . md5(preg_replace('/[\n\r\s\t]+/', ' ', $sql)); - $this->assertFalse($redis->exists($key)); - - $result = $db->sql_query($sql, 300); - $first_result = $db->sql_fetchrow($result); - $expected = array('config_name' => 'foo', 'config_value' => '23', 'is_dynamic' => 0); - $this->assertEquals($expected, $first_result); - - $this->assertTrue($redis->exists($key)); - - $sql = 'DELETE FROM phpbb_config'; - $result = $db->sql_query($sql); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql, 300); - - $this->assertEquals($expected, $db->sql_fetchrow($result)); - - $sql = "SELECT * FROM phpbb_config - WHERE config_name = 'foo'"; - $result = $db->sql_query($sql); - - $no_cache_result = $db->sql_fetchrow($result); - $this->assertSame(false, $no_cache_result); - - $db->sql_close(); - } } From f08c28c77a585e35cc17a2248ba61428275ccdd7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 01:59:27 -0500 Subject: [PATCH 615/645] [ticket/10103] Factor out flock lock class. PHPBB3-10103 --- phpBB/includes/functions_messenger.php | 58 ------------ phpBB/includes/lock/flock.php | 124 +++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 58 deletions(-) create mode 100644 phpBB/includes/lock/flock.php diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index cf03de08c4..503f419e5a 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -650,64 +650,6 @@ class queue $this->data[$object]['data'][] = $scope; } - /** - * Obtains exclusive lock on queue cache file. - * Returns resource representing the lock - */ - function lock() - { - // For systems that can't have two processes opening - // one file for writing simultaneously - if (file_exists($this->cache_file . '.lock')) - { - $mode = 'rb'; - } - else - { - $mode = 'wb'; - } - - $lock_fp = @fopen($this->cache_file . '.lock', $mode); - - if ($mode == 'wb') - { - if (!$lock_fp) - { - // Two processes may attempt to create lock file at the same time. - // Have the losing process try opening the lock file again for reading - // on the assumption that the winning process created it - $mode = 'rb'; - $lock_fp = @fopen($this->cache_file . '.lock', $mode); - } - else - { - // Only need to set mode when the lock file is written - @chmod($this->cache_file . '.lock', 0666); - } - } - - if ($lock_fp) - { - @flock($lock_fp, LOCK_EX); - } - - return $lock_fp; - } - - /** - * Releases lock on queue cache file, using resource obtained from lock() - */ - function unlock($lock_fp) - { - // lock() will return null if opening lock file, and thus locking, failed. - // Accept null values here so that client code does not need to check them - if ($lock_fp) - { - @flock($lock_fp, LOCK_UN); - fclose($lock_fp); - } - } - /** * Process queue * Using lock file diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php new file mode 100644 index 0000000000..e24a5f3e1c --- /dev/null +++ b/phpBB/includes/lock/flock.php @@ -0,0 +1,124 @@ +path = $path; + $this->lock_fp = null; + } + + /** + * Tries to acquire the lock. + * + * As a lock may only be held by one process at a time, lock + * acquisition may fail if another process is holding the lock. + * + * @return bool true if lock was acquired + * false otherwise + */ + public function acquire() + { + if ($this->locked) + { + return false; + } + + // For systems that can't have two processes opening + // one file for writing simultaneously + if (file_exists($this->path . '.lock')) + { + $mode = 'rb'; + } + else + { + $mode = 'wb'; + } + + $this->lock_fp = @fopen($this->path . '.lock', $mode); + + if ($mode == 'wb') + { + if (!$this->lock_fp) + { + // Two processes may attempt to create lock file at the same time. + // Have the losing process try opening the lock file again for reading + // on the assumption that the winning process created it + $mode = 'rb'; + $this->lock_fp = @fopen($this->path . '.lock', $mode); + } + else + { + // Only need to set mode when the lock file is written + @chmod($this->path . '.lock', 0666); + } + } + + if ($this->lock_fp) + { + @flock($this->lock_fp, LOCK_EX); + } + + return (bool) $this->lock_fp; + } + + /** + * Releases the lock. + * + * The lock must have been previously obtained, that is, acquire() call + * was issued and returned true. + * + * Note: Attempting to release a lock that is already released, + * that is, calling release() multiple times, is harmless. + * + * @return null + */ + public function release() + { + if ($this->lock_fp) + { + @flock($this->lock_fp, LOCK_UN); + fclose($this->lock_fp); + $this->lock_fp = null; + } + } +} From 4010f4085aa56f20fd95274ecfc2fe7404f98269 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:00:27 -0500 Subject: [PATCH 616/645] [ticket/10103] Use flock lock class in messenger. PHPBB3-10103 --- phpBB/includes/functions_messenger.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 503f419e5a..56fc7e628f 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -658,13 +658,14 @@ class queue { global $db, $config, $phpEx, $phpbb_root_path, $user; - $lock_fp = $this->lock(); + $lock = new phpbb_lock_flock($this->cache_file); + $lock->acquire(); set_config('last_queue_run', time(), true); if (!file_exists($this->cache_file) || filemtime($this->cache_file) > time() - $config['queue_interval']) { - $this->unlock($lock_fp); + $lock->release(); return; } @@ -731,7 +732,7 @@ class queue break; default: - $this->unlock($lock_fp); + $lock->release(); return; } @@ -807,7 +808,7 @@ class queue } } - $this->unlock($lock_fp); + $lock->release(); } /** @@ -820,7 +821,8 @@ class queue return; } - $lock_fp = $this->lock(); + $lock = new phpbb_lock_flock($this->cache_file); + $lock->acquire(); if (file_exists($this->cache_file)) { @@ -847,7 +849,7 @@ class queue phpbb_chmod($this->cache_file, CHMOD_READ | CHMOD_WRITE); } - $this->unlock($lock_fp); + $lock->release(); } } From f72e435759e8fafe3b06af35072c1907ba016546 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:21:53 -0500 Subject: [PATCH 617/645] [ticket/10103] Test for flock lock class, with concurrency no less. PHPBB3-10103 --- tests/lock/flock_test.php | 108 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 tests/lock/flock_test.php diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php new file mode 100644 index 0000000000..5c645de27c --- /dev/null +++ b/tests/lock/flock_test.php @@ -0,0 +1,108 @@ +acquire(); + $this->assertTrue($ok); + $lock->release(); + } + + public function test_consecutive_locking() + { + $path = __DIR__ . '/../tmp/precious'; + + $lock = new phpbb_lock_flock($path); + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + + $ok = $lock->acquire(); + $this->assertTrue($ok); + $lock->release(); + } + + /* This hangs the process. + public function test_concurrent_locking_fail() + { + $path = __DIR__ . '/../tmp/precious'; + + $lock1 = new phpbb_lock_flock($path); + $ok = $lock1->acquire(); + $this->assertTrue($ok); + + $lock2 = new phpbb_lock_flock($path); + $ok = $lock2->acquire(); + $this->assertFalse($ok); + + $lock->release(); + $ok = $lock2->acquire(); + $this->assertTrue($ok); + } + */ + + public function test_concurrent_locking() + { + if (!function_exists('pcntl_fork')) + { + $this->markTestSkipped('pcntl extension and pcntl_fork are required for this test'); + } + + $path = __DIR__ . '/../tmp/precious'; + + if ($pid = pcntl_fork()) + { + // parent + // wait 0.5 s, acquire the lock, note how long it took + sleep(0.5); + + $lock = new phpbb_lock_flock($path); + $start = time(); + $ok = $lock->acquire(); + $delta = time() - $start; + $this->assertTrue($ok); + $this->assertTrue($delta > 0.5); + + $lock->release(); + + // acquire again, this should be instantaneous + $start = time(); + $ok = $lock->acquire(); + $delta = time() - $start; + $this->assertTrue($ok); + $this->assertTrue($delta < 0.1); + + // reap the child + $status = null; + pcntl_waitpid($pid, $status); + } + else + { + // child + // immediately acquire the lock and sleep for 2 s + $lock = new phpbb_lock_flock($path); + $ok = $lock->acquire(); + $this->assertTrue($ok); + sleep(2); + $lock->release(); + + // and go away silently + pcntl_exec('/usr/bin/env', array('true')); + } + } +} From 318140b4d6257dd49ae86ed1185568f4d523e53e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:26:55 -0500 Subject: [PATCH 618/645] [ticket/10103] Convert the rest of the tree to flock class. PHPBB3-10103 --- phpBB/includes/cache/driver/file.php | 16 +++++++++++----- phpBB/includes/template/compile.php | 8 +++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index a0f06dde4b..ee1b430451 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -653,10 +653,11 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base $file = "{$this->cache_dir}$filename.$phpEx"; + $lock = new phpbb_lock_flock($file); + $lock->acquire(); + if ($handle = @fopen($file, 'wb')) { - @flock($handle, LOCK_EX); - // File header fwrite($handle, '<' . '?php exit; ?' . '>'); @@ -697,7 +698,6 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base fwrite($handle, $data); } - @flock($handle, LOCK_UN); fclose($handle); if (!function_exists('phpbb_chmod')) @@ -708,10 +708,16 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE); - return true; + $rv = true; + } + else + { + $rv = false; } - return false; + $lock->release(); + + return $rv; } /** diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php index d0b3d0f115..22da21820e 100644 --- a/phpBB/includes/template/compile.php +++ b/phpBB/includes/template/compile.php @@ -58,6 +58,9 @@ class phpbb_template_compile */ public function compile_file_to_file($source_file, $compiled_file) { + $lock = new phpbb_lock_flock($compiled_file); + $lock->acquire(); + $source_handle = @fopen($source_file, 'rb'); $destination_handle = @fopen($compiled_file, 'wb'); @@ -66,16 +69,15 @@ class phpbb_template_compile return false; } - @flock($destination_handle, LOCK_EX); - $this->compile_stream_to_stream($source_handle, $destination_handle); @fclose($source_handle); - @flock($destination_handle, LOCK_UN); @fclose($destination_handle); phpbb_chmod($compiled_file, CHMOD_READ | CHMOD_WRITE); + $lock->release(); + clearstatcache(); return true; From fc410e1cd0071a2de3dc90ce62a5abbef0266f15 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:38:57 -0500 Subject: [PATCH 619/645] [ticket/10103] Try a longer sleep for travis. Apparently travis takes longer than half a second to fork php. PHPBB3-10103 --- tests/lock/flock_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index 5c645de27c..bc682f9410 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -69,7 +69,7 @@ class phpbb_lock_flock_test extends phpbb_test_case { // parent // wait 0.5 s, acquire the lock, note how long it took - sleep(0.5); + sleep(1); $lock = new phpbb_lock_flock($path); $start = time(); From cf3080b83ed6f90b24cfd99a9fc7dd71dddde827 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:39:50 -0500 Subject: [PATCH 620/645] [ticket/9983] Correct incorrect markTestSkipped call. PHPBB3-9983 --- tests/cache/redis_driver_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cache/redis_driver_test.php b/tests/cache/redis_driver_test.php index cd24e33baf..a90a750460 100644 --- a/tests/cache/redis_driver_test.php +++ b/tests/cache/redis_driver_test.php @@ -35,7 +35,7 @@ class phpbb_cache_redis_driver_test extends phpbb_cache_common_test_case } else { - $this->markTestSkipped('Test redis host/port is not specified'); + self::markTestSkipped('Test redis host/port is not specified'); } } From b67f112e03cf37436bdd650ea4b9a75b35000fdd Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 02:52:18 -0500 Subject: [PATCH 621/645] [ticket/10091] Bump minimum supported postgresql version to 8.3. PHPBB3-10091 --- phpBB/docs/INSTALL.html | 2 +- phpBB/docs/coding-guidelines.html | 2 +- phpBB/includes/functions_install.php | 2 +- phpBB/language/en/install.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/docs/INSTALL.html b/phpBB/docs/INSTALL.html index 07f0cbc8c2..58aeb904c7 100644 --- a/phpBB/docs/INSTALL.html +++ b/phpBB/docs/INSTALL.html @@ -132,7 +132,7 @@
  • A SQL database system, one of:
    • MySQL 3.23 or above (MySQLi supported)
    • -
    • PostgreSQL 7.3+
    • +
    • PostgreSQL 8.3+
    • SQLite 2.8.2+ (SQLite 3 is not supported)
    • Firebird 2.1+
    • MS SQL Server 2000 or above (directly or via ODBC or the native adapter)
    • diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index 0e3a97c004..eb569d12d5 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -740,7 +740,7 @@ static private function f()

      2.iii. SQL/SQL Layout

      Common SQL Guidelines:

      -

      All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (7.0+), Firebird, SQLite, Oracle8, ODBC (generalised if possible)).

      +

      All SQL should be cross-DB compatible, if DB specific SQL is used alternatives must be provided which work on all supported DB's (MySQL3/4/5, MSSQL (7.0 and 2000), PostgreSQL (8.3+), Firebird, SQLite, Oracle8, ODBC (generalised if possible)).

      All SQL commands should utilise the DataBase Abstraction Layer (DBAL)

      SQL code layout:

      diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 7a799993db..ab6b3ea009 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -87,7 +87,7 @@ function get_available_dbms($dbms = false, $return_unavailable = false, $only_20 '2.0.x' => false, ), 'postgres' => array( - 'LABEL' => 'PostgreSQL 7.x/8.x', + 'LABEL' => 'PostgreSQL 8.3+', 'SCHEMA' => 'postgres', 'MODULE' => 'pgsql', 'DELIM' => ';', diff --git a/phpBB/language/en/install.php b/phpBB/language/en/install.php index cb6a17afa2..1c45deae11 100644 --- a/phpBB/language/en/install.php +++ b/phpBB/language/en/install.php @@ -210,7 +210,7 @@ $lang = array_merge($lang, array(

      phpBB3 supports the following databases:

      • MySQL 3.23 or above (MySQLi supported)
      • -
      • PostgreSQL 7.3+
      • +
      • PostgreSQL 8.3+
      • SQLite 2.8.2+
      • Firebird 2.1+
      • MS SQL Server 2000 or above (directly or via ODBC)
      • From af2887f3a7f27b33c2ecd14d4baab846b71ddb62 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 03:34:51 -0500 Subject: [PATCH 622/645] [ticket/10716] php parse all php files as part of the test suite. PHPBB3-10716 --- tests/lint_test.php | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/lint_test.php diff --git a/tests/lint_test.php b/tests/lint_test.php new file mode 100644 index 0000000000..57c78ae809 --- /dev/null +++ b/tests/lint_test.php @@ -0,0 +1,49 @@ +check($root); + } + + protected function check($root) + { + $dh = opendir($root); + while (($filename = readdir($dh)) !== false) + { + if ($filename == '.' || $filename == '..' || $filename == 'git') + { + continue; + } + $path = $root . '/' . $filename; + // skip symlinks to avoid infinite loops + if (is_link($path)) + { + continue; + } + if (is_dir($path)) + { + $this->check($path); + } + else if (substr($filename, strlen($filename)-4) == '.php') + { + // assume php binary is called php and it is in PATH + $cmd = 'php -l ' . escapeshellarg($path); + $output = array(); + $status = 1; + exec($cmd, $output, $status); + $output = implode("\n", $output); + $this->assertEquals(0, $status, "php -l failed for $path:\n$output"); + } + } + } +} From 4cc81f1ffa62cdbcbb656300c7dd9fbd44cc21fc Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:44:22 -0500 Subject: [PATCH 623/645] [ticket/10103] Correct flock class documentation. PHPBB3-10103 --- phpBB/includes/lock/flock.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php index e24a5f3e1c..09450644bc 100644 --- a/phpBB/includes/lock/flock.php +++ b/phpBB/includes/lock/flock.php @@ -35,9 +35,9 @@ class phpbb_lock_flock private $lock_fp; /** - * Creates an instance of the lock. + * Constructor. * - * You have to call acquire() to actually create the lock. + * You have to call acquire() to actually acquire the lock. * * @param string $path Path to the file access to which is controlled */ @@ -50,8 +50,17 @@ class phpbb_lock_flock /** * Tries to acquire the lock. * - * As a lock may only be held by one process at a time, lock - * acquisition may fail if another process is holding the lock. + * If the lock is already held by another process, this call will block + * until the other process releases the lock. If a lock is acquired and + * is not released before script finishes but the process continues to + * live (apache/fastcgi) then subsequent processes trying to acquire + * the same lock will be blocked forever. + * + * If the lock is already held by the same process via another instance + * of this class, this call will block forever. + * + * If flock function is disabled in php or fails to work, lock + * acquisition will fail and false will be returned. * * @return bool true if lock was acquired * false otherwise From 3924676f2bd1a30ff56ab1db985cf622f1fac286 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:45:02 -0500 Subject: [PATCH 624/645] [ticket/10103] $rv had too few characters. PHPBB3-10103 --- phpBB/includes/cache/driver/file.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php index ee1b430451..691abe0438 100644 --- a/phpBB/includes/cache/driver/file.php +++ b/phpBB/includes/cache/driver/file.php @@ -708,16 +708,16 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE); - $rv = true; + $return_value = true; } else { - $rv = false; + $return_value = false; } $lock->release(); - return $rv; + return $return_value; } /** From a553cfbc30472f136f9904d97bf4d09a7187518f Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:46:01 -0500 Subject: [PATCH 625/645] [ticket/10103] Inline assignment is bad? PHPBB3-10103 --- tests/lock/flock_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index bc682f9410..abcb4e79c2 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -65,7 +65,8 @@ class phpbb_lock_flock_test extends phpbb_test_case $path = __DIR__ . '/../tmp/precious'; - if ($pid = pcntl_fork()) + $pid = pcntl_fork(); + if ($pid) { // parent // wait 0.5 s, acquire the lock, note how long it took From 285feb49f82084b5b489aa1fc6765b9b02ea1b29 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:47:57 -0500 Subject: [PATCH 626/645] [ticket/10103] assertLessThan/assertGreaterThan. PHPBB3-10103 --- tests/lock/flock_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index abcb4e79c2..8bb7d0a041 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -77,7 +77,7 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); - $this->assertTrue($delta > 0.5); + $this->assertGreaterThan(0.5, $delta); $lock->release(); @@ -86,7 +86,7 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); - $this->assertTrue($delta < 0.1); + $this->assertLessThan(0.1, $delta); // reap the child $status = null; From e22dd7dfadedd951d1fd17b61fa700c572ca4d79 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:50:35 -0500 Subject: [PATCH 627/645] [ticket/10103] Assert with messages. PHPBB3-10103 --- tests/lock/flock_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index 8bb7d0a041..1edc96b3a4 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -77,7 +77,7 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); - $this->assertGreaterThan(0.5, $delta); + $this->assertGreaterThan(0.5, $delta, 'First lock acquired too soon'); $lock->release(); @@ -86,7 +86,7 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); - $this->assertLessThan(0.1, $delta); + $this->assertLessThan(0.1, $delta, 'Second lock not acquired instantaneously'); // reap the child $status = null; From 4133fae99ec4146a01c67f6a6b3020020d1c6464 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 13:58:14 -0500 Subject: [PATCH 628/645] [ticket/10716] Only lint on php 5.3+. PHPBB3-10716 --- tests/lint_test.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/lint_test.php b/tests/lint_test.php index 57c78ae809..1642b571dd 100644 --- a/tests/lint_test.php +++ b/tests/lint_test.php @@ -11,6 +11,11 @@ class phpbb_lint_test extends phpbb_test_case { public function test_lint() { + if (version_compare(PHP_VERSION, '5.3.0', '<')) + { + $this->markTestSkipped('phpBB uses PHP 5.3 syntax in some files, linting on PHP < 5.3 will fail'); + } + $root = dirname(__FILE__) . '/..'; $this->check($root); } From 3e093c282a63df4d16b212859fd8137fd2bbca81 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 14:05:49 -0500 Subject: [PATCH 629/645] [ticket/10103] New and improved wording. PHPBB3-10103 --- phpBB/includes/lock/flock.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php index 09450644bc..5c2288ce1b 100644 --- a/phpBB/includes/lock/flock.php +++ b/phpBB/includes/lock/flock.php @@ -22,7 +22,7 @@ if (!defined('IN_PHPBB')) class phpbb_lock_flock { /** - * Path to the file access to which is controlled + * Path to the file to which access is controlled * * @var string */ @@ -39,7 +39,7 @@ class phpbb_lock_flock * * You have to call acquire() to actually acquire the lock. * - * @param string $path Path to the file access to which is controlled + * @param string $path Path to the file to which access is controlled */ public function __construct($path) { From 8897efe087195ba31920c6b3aadbe8ea1b393c12 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 16:42:58 -0500 Subject: [PATCH 630/645] [ticket/10716] Exclude our dependencies from linting. PHPBB3-10716 --- tests/lint_test.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/lint_test.php b/tests/lint_test.php index 1642b571dd..67b7413cb4 100644 --- a/tests/lint_test.php +++ b/tests/lint_test.php @@ -9,6 +9,17 @@ class phpbb_lint_test extends phpbb_test_case { + static protected $exclude; + + static public function setUpBeforeClass() + { + self::$exclude = array( + // PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20 + // https://gist.github.com/e003913ffd493da63cbc + dirname(__FILE__) . '/../phpBB/vendor', + ); + } + public function test_lint() { if (version_compare(PHP_VERSION, '5.3.0', '<')) @@ -35,7 +46,7 @@ class phpbb_lint_test extends phpbb_test_case { continue; } - if (is_dir($path)) + if (is_dir($path) && !in_array($path, self::$exclude)) { $this->check($path); } From 8ea52b56197cc9a234d6b0ce3ddd10820feb6dd1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 17:43:36 -0500 Subject: [PATCH 631/645] [ticket/10716] Skip test if php is not in PATH. PHPBB3-10716 --- tests/lint_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/lint_test.php b/tests/lint_test.php index 67b7413cb4..d73ab7fedd 100644 --- a/tests/lint_test.php +++ b/tests/lint_test.php @@ -13,6 +13,14 @@ class phpbb_lint_test extends phpbb_test_case static public function setUpBeforeClass() { + $output = array(); + $status = 1; + exec('php -v', $output, $status); + if ($status) + { + self::markTestSkipped("php is not in PATH or broken: $output"); + } + self::$exclude = array( // PHP Fatal error: Cannot declare class Container because the name is already in use in /var/www/projects/phpbb3/tests/../phpBB/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services1-1.php on line 20 // https://gist.github.com/e003913ffd493da63cbc From fb261e19ffc3bf19477510fa3877a8d9ea251655 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 4 Dec 2012 18:52:27 -0500 Subject: [PATCH 632/645] [ticket/10716] Collect standard error from executed php process. php executes everything via a shell. The standard error of this top level shell is not captured by exec/shell_exec/popen/etc. and there is no way to capture it. proc_open might work but it is a nightmare to use and without multiplexing reads from standard error and standard output it can deadlock. Thus the solution in this commit. Put the command into a subshell and redirect standard error to standard output for the subshell. PHPBB3-10716 --- tests/lint_test.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/lint_test.php b/tests/lint_test.php index d73ab7fedd..905067072d 100644 --- a/tests/lint_test.php +++ b/tests/lint_test.php @@ -15,9 +15,10 @@ class phpbb_lint_test extends phpbb_test_case { $output = array(); $status = 1; - exec('php -v', $output, $status); + exec('(php -v) 2>&1', $output, $status); if ($status) { + $output = implode("\n", $output); self::markTestSkipped("php is not in PATH or broken: $output"); } @@ -61,7 +62,7 @@ class phpbb_lint_test extends phpbb_test_case else if (substr($filename, strlen($filename)-4) == '.php') { // assume php binary is called php and it is in PATH - $cmd = 'php -l ' . escapeshellarg($path); + $cmd = '(php -l ' . escapeshellarg($path) . ') 2>&1'; $output = array(); $status = 1; exec($cmd, $output, $status); From 03f819862f15efa2ef64331b23394086746d09be Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 00:41:47 -0500 Subject: [PATCH 633/645] [ticket/10602] Use last_queue_run for its intended purpose. We keep the last queue run time around, therefore for determining whether enough time has passed since the last run we can simply use this config variable. When there is no queue file we consider a queue run successful. Previously queue.php ("cache file") modification time would be used for determining whether enough time has passed since last queue run. The problem was that modification time would be updated whenever anything was added to the queue, creating a situation where if queue is processed less frequently than it is added to that email would not be sent. PHPBB3-10602 --- phpBB/includes/functions_messenger.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index 6549693333..ae0f7823cc 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -715,14 +715,19 @@ class queue $lock_fp = $this->lock(); - set_config('last_queue_run', time(), true); - - if (!file_exists($this->cache_file) || filemtime($this->cache_file) > time() - $config['queue_interval']) + if (!file_exists($this->cache_file) || $config['last_queue_run'] > time() - $config['queue_interval']) { + if (!file_exists($this->cache_file)) + { + set_config('last_queue_run', time(), true); + } + $this->unlock($lock_fp); return; } + set_config('last_queue_run', time(), true); + include($this->cache_file); foreach ($this->queue_data as $object => $data_ary) From 1e50116c54ec7ffbaba4622d5481207423ef2bbe Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 00:57:24 -0500 Subject: [PATCH 634/645] [ticket/10602] Avoid a race condition. PHPBB3-10602 --- phpBB/includes/functions_messenger.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index ae0f7823cc..e837811c86 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -715,9 +715,11 @@ class queue $lock_fp = $this->lock(); - if (!file_exists($this->cache_file) || $config['last_queue_run'] > time() - $config['queue_interval']) + // avoid races, check file existence once + $have_cache_file = file_exists($this->cache_file); + if (!$have_cache_file || $config['last_queue_run'] > time() - $config['queue_interval']) { - if (!file_exists($this->cache_file)) + if (!$have_cache_file) { set_config('last_queue_run', time(), true); } From a8d02ffc27d8cee916f267c91488276fca3606e7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 01:54:29 -0500 Subject: [PATCH 635/645] [ticket/11247] Fix wrong property reference in flock class. PHPBB3-11247 --- phpBB/includes/lock/flock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/lock/flock.php b/phpBB/includes/lock/flock.php index 5c2288ce1b..97bc7dd2b9 100644 --- a/phpBB/includes/lock/flock.php +++ b/phpBB/includes/lock/flock.php @@ -67,7 +67,7 @@ class phpbb_lock_flock */ public function acquire() { - if ($this->locked) + if ($this->lock_fp) { return false; } From af064cdaad357f705fc7c80f4d018d57cffa8d33 Mon Sep 17 00:00:00 2001 From: Senky Date: Wed, 16 May 2012 23:02:20 +0200 Subject: [PATCH 636/645] [ticket/10841] Modifying style and language selectors in UCP Commit also deletes all unnecessary blank spaces at the end of the lines in both ucp_prefs_personal.html PHPBB3-10841 --- phpBB/includes/ucp/ucp_prefs.php | 30 +++++++++++++ .../template/ucp_prefs_personal.html | 42 ++++++++++--------- .../template/ucp_prefs_personal.html | 18 ++++---- 3 files changed, 62 insertions(+), 28 deletions(-) diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 17d7d23f02..19e1b45787 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -134,6 +134,33 @@ class ucp_prefs } $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . ''; + // check for count of installed languages + $sql = 'SELECT lang_id + FROM ' . LANG_TABLE; + $result = $db->sql_query($sql); + if( $db->sql_affectedrows() > 1 ) + { + $s_more_languages = true; + } + else + { + $s_more_languages = false; + } + + // check for count of installed and active styles + $sql = 'SELECT style_id + FROM ' . STYLES_TABLE . ' + WHERE style_active = 1'; + $result = $db->sql_query($sql); + if( $db->sql_affectedrows() > 1 ) + { + $s_more_styles = true; + } + else + { + $s_more_styles = false; + } + $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
        ', $error) : '', @@ -155,6 +182,9 @@ class ucp_prefs 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), + 'S_MORE_LANGUAGES' => $s_more_languages, + 'S_MORE_STYLES' => $s_more_styles, + 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['style']), 'S_TZ_OPTIONS' => tz_select($data['tz'], true), diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 9022346627..416343e57d 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -12,21 +12,21 @@
        - +
        - +

        {L_ALLOW_PM_EXPLAIN}
        - +
        @@ -34,17 +34,17 @@

        {L_HIDE_ONLINE_EXPLAIN}
        - +
        - +
        - - + +
        @@ -52,22 +52,24 @@
        - +
        - +
        -
        -
        -
        -
        - + +
        +
        +
        +
        + +
        @@ -80,7 +82,7 @@
        - +
        @@ -97,9 +99,9 @@ - +
        - {S_HIDDEN_FIELDS}  + {S_HIDDEN_FIELDS}  {S_FORM_TOKEN}
        @@ -113,9 +115,9 @@ function customDates() { var e = document.getElementById('dateoptions'); - + e.selectedIndex = e.length - 1; - + // Loop and match date_format in menu for (var i = 0; i < e.length; i++) { @@ -125,7 +127,7 @@ break; } } - + // Show/hide custom field if (e.selectedIndex == e.length - 1) { diff --git a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html index e2266b7d38..c604671c5c 100644 --- a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html +++ b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html @@ -29,43 +29,45 @@ {ERROR} - + {L_SHOW_EMAIL}: checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_ADMIN_EMAIL}: checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_ALLOW_PM}:
        {L_ALLOW_PM_EXPLAIN} checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_HIDE_ONLINE}:
        {L_HIDE_ONLINE_EXPLAIN} checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_NOTIFY_METHOD}:
        {L_NOTIFY_METHOD_EXPLAIN} checked="checked" />{L_NOTIFY_METHOD_EMAIL}   checked="checked" />{L_NOTIFY_METHOD_IM}   checked="checked" />{L_NOTIFY_METHOD_BOTH} - + {L_NOTIFY_ON_PM}: checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_POPUP_ON_PM}: checked="checked" />{L_YES}   checked="checked" />{L_NO} + {L_BOARD_LANGUAGE}: - + + {L_BOARD_STYLE}: From dd6983b14bba4326d824b3abb130eafc5e8f666c Mon Sep 17 00:00:00 2001 From: Senky Date: Thu, 17 May 2012 20:01:44 +0200 Subject: [PATCH 637/645] [ticket/10841] changing affectedrows check to COUNT in sql this sould reduce load and be faster. Also freeresult functions added PHPBB3-10841 --- phpBB/includes/ucp/ucp_prefs.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index 19e1b45787..b95d2d4ee8 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -134,11 +134,11 @@ class ucp_prefs } $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . ''; - // check for count of installed languages - $sql = 'SELECT lang_id + // check if there are any user-selectable languages + $sql = 'SELECT COUNT(lang_id) as languages_count FROM ' . LANG_TABLE; $result = $db->sql_query($sql); - if( $db->sql_affectedrows() > 1 ) + if( $db->sql_fetchfield('languages_count') > 1 ) { $s_more_languages = true; } @@ -146,13 +146,14 @@ class ucp_prefs { $s_more_languages = false; } + $db->sql_freeresult($result); - // check for count of installed and active styles - $sql = 'SELECT style_id + // check if there are any user-selectable styles + $sql = 'SELECT COUNT(style_id) as styles_count FROM ' . STYLES_TABLE . ' WHERE style_active = 1'; $result = $db->sql_query($sql); - if( $db->sql_affectedrows() > 1 ) + if( $db->sql_fetchfield('styles_count') > 1 ) { $s_more_styles = true; } @@ -160,6 +161,7 @@ class ucp_prefs { $s_more_styles = false; } + $db->sql_freeresult($result); $template->assign_vars(array( 'ERROR' => (sizeof($error)) ? implode('
        ', $error) : '', From f7508c3f042091f163a87829a051312fa58630f1 Mon Sep 17 00:00:00 2001 From: Senky Date: Wed, 7 Nov 2012 10:28:25 +0100 Subject: [PATCH 638/645] [ticket/10841] removing unnecessary spacing PHPBB3-10841 --- phpBB/includes/ucp/ucp_prefs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index b95d2d4ee8..e84c7e662a 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -138,7 +138,7 @@ class ucp_prefs $sql = 'SELECT COUNT(lang_id) as languages_count FROM ' . LANG_TABLE; $result = $db->sql_query($sql); - if( $db->sql_fetchfield('languages_count') > 1 ) + if($db->sql_fetchfield('languages_count') > 1) { $s_more_languages = true; } @@ -153,7 +153,7 @@ class ucp_prefs FROM ' . STYLES_TABLE . ' WHERE style_active = 1'; $result = $db->sql_query($sql); - if( $db->sql_fetchfield('styles_count') > 1 ) + if($db->sql_fetchfield('styles_count') > 1) { $s_more_styles = true; } From 120accb9d4b2a89ca05f712a54427e072584c2f9 Mon Sep 17 00:00:00 2001 From: Senky Date: Thu, 8 Nov 2012 17:30:58 +0100 Subject: [PATCH 639/645] [ticket/10841] adding space after if PHPBB3-10841 --- phpBB/includes/ucp/ucp_prefs.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/ucp/ucp_prefs.php b/phpBB/includes/ucp/ucp_prefs.php index e84c7e662a..c6e43b831c 100644 --- a/phpBB/includes/ucp/ucp_prefs.php +++ b/phpBB/includes/ucp/ucp_prefs.php @@ -138,7 +138,7 @@ class ucp_prefs $sql = 'SELECT COUNT(lang_id) as languages_count FROM ' . LANG_TABLE; $result = $db->sql_query($sql); - if($db->sql_fetchfield('languages_count') > 1) + if ($db->sql_fetchfield('languages_count') > 1) { $s_more_languages = true; } @@ -153,7 +153,7 @@ class ucp_prefs FROM ' . STYLES_TABLE . ' WHERE style_active = 1'; $result = $db->sql_query($sql); - if($db->sql_fetchfield('styles_count') > 1) + if ($db->sql_fetchfield('styles_count') > 1) { $s_more_styles = true; } From 0793f8e2e60453db8de1ff8e231a36b2c9024f3d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 11:54:49 -0500 Subject: [PATCH 640/645] [ticket/10841] Revert whitespace changes. PHPBB3-10841 --- .../template/ucp_prefs_personal.html | 26 +++++++++---------- .../template/ucp_prefs_personal.html | 14 +++++----- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 416343e57d..01e0c9ba28 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -12,21 +12,21 @@
        - +
        - +

        {L_ALLOW_PM_EXPLAIN}
        - +
        @@ -34,17 +34,17 @@

        {L_HIDE_ONLINE_EXPLAIN}
        - +
        - +
        - - + +
        @@ -82,7 +82,7 @@
        - +
        @@ -99,9 +99,9 @@ - +
        - {S_HIDDEN_FIELDS}  + {S_HIDDEN_FIELDS}  {S_FORM_TOKEN}
        @@ -115,9 +115,9 @@ function customDates() { var e = document.getElementById('dateoptions'); - + e.selectedIndex = e.length - 1; - + // Loop and match date_format in menu for (var i = 0; i < e.length; i++) { @@ -127,7 +127,7 @@ break; } } - + // Show/hide custom field if (e.selectedIndex == e.length - 1) { diff --git a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html index c604671c5c..4cd0f37a80 100644 --- a/phpBB/styles/subsilver2/template/ucp_prefs_personal.html +++ b/phpBB/styles/subsilver2/template/ucp_prefs_personal.html @@ -29,35 +29,35 @@ {ERROR} - + {L_SHOW_EMAIL}: checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_ADMIN_EMAIL}: checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_ALLOW_PM}:
        {L_ALLOW_PM_EXPLAIN} checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_HIDE_ONLINE}:
        {L_HIDE_ONLINE_EXPLAIN} checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_NOTIFY_METHOD}:
        {L_NOTIFY_METHOD_EXPLAIN} checked="checked" />{L_NOTIFY_METHOD_EMAIL}   checked="checked" />{L_NOTIFY_METHOD_IM}   checked="checked" />{L_NOTIFY_METHOD_BOTH} - + {L_NOTIFY_ON_PM}: checked="checked" />{L_YES}   checked="checked" />{L_NO} - + {L_POPUP_ON_PM}: checked="checked" />{L_YES}   checked="checked" />{L_NO} From a8e74f5292aaa74e2035dd5f3ab972f0201a1fe7 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 5 Dec 2012 12:02:30 -0500 Subject: [PATCH 641/645] [ticket/10841] Revert more whitespace changes. PHPBB3-10841 --- phpBB/styles/prosilver/template/ucp_prefs_personal.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/styles/prosilver/template/ucp_prefs_personal.html b/phpBB/styles/prosilver/template/ucp_prefs_personal.html index 01e0c9ba28..600319fc72 100644 --- a/phpBB/styles/prosilver/template/ucp_prefs_personal.html +++ b/phpBB/styles/prosilver/template/ucp_prefs_personal.html @@ -52,14 +52,14 @@
        - +
        - +
        From dbb54b217b4d0c0669a566f9c950e8331887d276 Mon Sep 17 00:00:00 2001 From: Patrick Webster Date: Wed, 5 Dec 2012 22:57:06 -0600 Subject: [PATCH 642/645] [ticket/11219] Coding guidelines and naming consistency changes PHPBB3-11219 --- tests/dbal/write_sequence_test.php | 2 +- ...phpbb_database_test_connection_manager.php | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/dbal/write_sequence_test.php b/tests/dbal/write_sequence_test.php index d2c30b4e89..8975cfbfb1 100644 --- a/tests/dbal/write_sequence_test.php +++ b/tests/dbal/write_sequence_test.php @@ -13,7 +13,7 @@ class phpbb_dbal_write_sequence_test extends phpbb_database_test_case { public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/three_users.xml'); } static public function write_sequence_data() diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 97281a0812..d7c2804aa7 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -430,17 +430,17 @@ class phpbb_database_test_connection_manager /** * Performs synchronisations on the database after a fixture has been loaded * - * @param PHPUnit_Extensions_Database_DataSet_XmlDataSet $tables Tables contained within the loaded fixture + * @param PHPUnit_Extensions_Database_DataSet_XmlDataSet $xml_data_set Information about the tables contained within the loaded fixture * * @return null */ - public function post_setup_synchronisation($xmlDataSet) + public function post_setup_synchronisation($xml_data_set) { $this->ensure_connected(__METHOD__); $queries = array(); // Get escaped versions of the table names used in the fixture - $table_names = array_map(array($this->pdo, 'PDO::quote'), $xmlDataSet->getTableNames()); + $table_names = array_map(array($this->pdo, 'PDO::quote'), $xml_data_set->getTableNames()); switch ($this->config['dbms']) { @@ -469,18 +469,20 @@ class phpbb_database_test_connection_manager continue; } - $maxval = (int)$max_row['MAX']; - $maxval++; + $max_val = (int) $max_row['MAX']; + $max_val++; - // This is not the "proper" way, but the proper way does not allow you to completely reset - // tables with no rows since you have to select the next value to make the change go into effct. - // You would have to go past the minimum value to set it correctly, but that's illegal. - // Since we have no objects attached to our sequencers (triggers aren't attached), this works fine. + /** + * This is not the "proper" way, but the proper way does not allow you to completely reset + * tables with no rows since you have to select the next value to make the change go into effect. + * You would have to go past the minimum value to set it correctly, but that's illegal. + * Since we have no objects attached to our sequencers (triggers aren't attached), this works fine. + */ $queries[] = 'DROP SEQUENCE ' . $row['SEQUENCE_NAME']; $queries[] = "CREATE SEQUENCE {$row['SEQUENCE_NAME']} MINVALUE {$row['MIN_VALUE']} INCREMENT BY {$row['INCREMENT_BY']} - START WITH $maxval"; + START WITH $max_val"; } break; @@ -495,7 +497,7 @@ class phpbb_database_test_connection_manager while ($row = $result->fetch(PDO::FETCH_ASSOC)) { // Get the columns used in the fixture for this table - $column_names = $xmlDataSet->getTableMetaData($row['table_name'])->getColumns(); + $column_names = $xml_data_set->getTableMetaData($row['table_name'])->getColumns(); // Skip sequences that weren't specified in the fixture if (!in_array($row['column_name'], $column_names)) From 4103c99a8676653a868014a6f58a76e8986bd5ed Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 1 Mar 2012 16:15:11 +0100 Subject: [PATCH 643/645] [ticket/10679] Add new permission for changing profile field information The setting is copied from "Can use signature" PHPBB3-10679 --- phpBB/includes/ucp/ucp_profile.php | 5 +++ phpBB/install/database_update.php | 48 +++++++++++++++++++-- phpBB/install/schemas/schema_data.sql | 3 +- phpBB/language/en/acp/permissions_phpbb.php | 1 + phpBB/language/en/ucp.php | 1 + phpBB/ucp.php | 6 +++ 6 files changed, 59 insertions(+), 5 deletions(-) diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 89bf20a30f..e7cea06a45 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -251,6 +251,11 @@ class ucp_profile break; case 'profile_info': + // Do not display profile information panel if not authed to do so + if (!$auth->acl_get('u_chgprofileinfo')) + { + trigger_error('NO_AUTH_PROFILEINFO'); + } include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index e966756337..f0a16844e9 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2731,8 +2731,6 @@ function change_database_data(&$no_updates, $version) $config->set('display_last_subject', '1'); } - $no_updates = false; - if (!isset($config['assets_version'])) { $config->set('assets_version', '1'); @@ -2771,7 +2769,7 @@ function change_database_data(&$no_updates, $version) } // PHPBB3-10601: Make inbox default. Add basename to ucp's pm category - + // Get the category wanted while checking, at the same time, if this has already been applied $sql = 'SELECT module_id, module_basename FROM ' . MODULES_TABLE . " @@ -2788,10 +2786,52 @@ function change_database_data(&$no_updates, $version) SET module_basename = 'ucp_pm' WHERE module_id = " . (int) $row['module_id']; - _sql($sql, $errored, $error_ary); + _sql($sql, $errored, $error_ary); } $db->sql_freeresult($result); + // Add new permission u_chgprofileinfo and duplicate settings from u_sig + include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx); + $auth_admin = new auth_admin(); + + // Only add the new permission if it does not already exist + if (empty($auth_admin->acl_options['id']['u_chgprofileinfo'])) + { + $auth_admin->acl_add_option(array('global' => array('u_chgprofileinfo'))); + + // Now the tricky part, filling the permission + $old_id = $auth_admin->acl_options['id']['u_sig']; + $new_id = $auth_admin->acl_options['id']['u_chgprofileinfo']; + + $tables = array(ACL_GROUPS_TABLE, ACL_ROLES_DATA_TABLE, ACL_USERS_TABLE); + + foreach ($tables as $table) + { + $sql = 'SELECT * + FROM ' . $table . ' + WHERE auth_option_id = ' . $old_id; + $result = _sql($sql, $errored, $error_ary); + + $sql_ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $row['auth_option_id'] = $new_id; + $sql_ary[] = $row; + } + $db->sql_freeresult($result); + + if (sizeof($sql_ary)) + { + $db->sql_multi_insert($table, $sql_ary); + } + } + + // Remove any old permission entries + $auth_admin->acl_clear_prefetch(); + } + + $no_updates = false; + break; } } diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index dbb5fd7481..7c1a7d40f5 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -387,6 +387,7 @@ INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chgemail', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chggrp', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chgname', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chgpasswd', 1); +INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_chgprofileinfo', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_download', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_hideonline', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('u_ignoreflood', 1); @@ -548,7 +549,7 @@ INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 22, auth_option_id, 1 FROM phpbb_acl_options WHERE auth_option LIKE 'f_%' AND auth_option NOT IN ('f_announce', 'f_attach', 'f_bump', 'f_delete', 'f_flash', 'f_icons', 'f_ignoreflood', 'f_sticky', 'f_user_lock', 'f_votechg'); # New Member (u_) -INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 23, auth_option_id, 0 FROM phpbb_acl_options WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group'); +INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 23, auth_option_id, 0 FROM phpbb_acl_options WHERE auth_option LIKE 'u_%' AND auth_option IN ('u_sendpm', 'u_masspm', 'u_masspm_group', 'u_chgprofileinfo'); # New Member (f_) INSERT INTO phpbb_acl_roles_data (role_id, auth_option_id, auth_setting) SELECT 24, auth_option_id, 0 FROM phpbb_acl_options WHERE auth_option LIKE 'f_%' AND auth_option IN ('f_noapprove'); diff --git a/phpBB/language/en/acp/permissions_phpbb.php b/phpBB/language/en/acp/permissions_phpbb.php index b142cfd9aa..27ef714f8b 100644 --- a/phpBB/language/en/acp/permissions_phpbb.php +++ b/phpBB/language/en/acp/permissions_phpbb.php @@ -102,6 +102,7 @@ $lang = array_merge($lang, array( 'acl_u_chgemail' => array('lang' => 'Can change email address', 'cat' => 'profile'), 'acl_u_chgavatar' => array('lang' => 'Can change avatar', 'cat' => 'profile'), 'acl_u_chggrp' => array('lang' => 'Can change default usergroup', 'cat' => 'profile'), + 'acl_u_chgprofileinfo' => array('lang' => 'Can change profile field information', 'cat' => 'profile'), 'acl_u_attach' => array('lang' => 'Can attach files', 'cat' => 'post'), 'acl_u_download' => array('lang' => 'Can download files', 'cat' => 'post'), diff --git a/phpBB/language/en/ucp.php b/phpBB/language/en/ucp.php index b919699ea0..267ae00710 100644 --- a/phpBB/language/en/ucp.php +++ b/phpBB/language/en/ucp.php @@ -318,6 +318,7 @@ $lang = array_merge($lang, array( 'NO_AUTH_FORWARD_MESSAGE' => 'You are not authorised to forward private messages.', 'NO_AUTH_GROUP_MESSAGE' => 'You are not authorised to send private messages to groups.', 'NO_AUTH_PASSWORD_REMINDER' => 'You are not authorised to request a new password.', + 'NO_AUTH_PROFILEINFO' => 'You are not authorised to change your profile information.', 'NO_AUTH_READ_HOLD_MESSAGE' => 'You are not authorised to read private messages that are on hold.', 'NO_AUTH_READ_MESSAGE' => 'You are not authorised to read private messages.', 'NO_AUTH_READ_REMOVED_MESSAGE' => 'You are not able to read this message because it was removed by the author.', diff --git a/phpBB/ucp.php b/phpBB/ucp.php index a7e75f76c4..7f4cd94f6f 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -334,6 +334,12 @@ if (!$config['allow_topic_notify'] && !$config['allow_forum_notify']) $vars = array('module', 'id', 'mode'); extract($phpbb_dispatcher->trigger_event('core.ucp_display_module_before', compact($vars))); +// Do not display profile information panel if not authed to do so +if (!$auth->acl_get('u_chgprofileinfo')) +{ + $module->set_display('profile', 'profile_info', false); +} + // Select the active module $module->set_active($id, $mode); From 2f490293e4b8d08d6c1008ef5ea324ae259d9993 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 6 Dec 2012 16:33:12 +0100 Subject: [PATCH 644/645] [ticket/10679] Use module_auth to limit access to the module PHPBB3-10679 --- phpBB/includes/ucp/info/ucp_profile.php | 2 +- phpBB/install/database_update.php | 8 ++++++++ phpBB/ucp.php | 6 ------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/phpBB/includes/ucp/info/ucp_profile.php b/phpBB/includes/ucp/info/ucp_profile.php index 201216e9fd..3581a7f533 100644 --- a/phpBB/includes/ucp/info/ucp_profile.php +++ b/phpBB/includes/ucp/info/ucp_profile.php @@ -19,7 +19,7 @@ class ucp_profile_info 'title' => 'UCP_PROFILE', 'version' => '1.0.0', 'modes' => array( - 'profile_info' => array('title' => 'UCP_PROFILE_PROFILE_INFO', 'auth' => '', 'cat' => array('UCP_PROFILE')), + 'profile_info' => array('title' => 'UCP_PROFILE_PROFILE_INFO', 'auth' => 'acl_u_chgprofileinfo', 'cat' => array('UCP_PROFILE')), 'signature' => array('title' => 'UCP_PROFILE_SIGNATURE', 'auth' => 'acl_u_sig', 'cat' => array('UCP_PROFILE')), 'avatar' => array('title' => 'UCP_PROFILE_AVATAR', 'auth' => 'cfg_allow_avatar && (cfg_allow_avatar_local || cfg_allow_avatar_remote || cfg_allow_avatar_upload || cfg_allow_avatar_remote_upload)', 'cat' => array('UCP_PROFILE')), 'reg_details' => array('title' => 'UCP_PROFILE_REG_DETAILS', 'auth' => '', 'cat' => array('UCP_PROFILE')), diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index f0a16844e9..95fd1ca2c2 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2830,6 +2830,14 @@ function change_database_data(&$no_updates, $version) $auth_admin->acl_clear_prefetch(); } + // Update the auth setting for the module + $sql = 'UPDATE ' . MODULES_TABLE . " + SET module_auth = 'acl_u_chgprofileinfo' + WHERE module_class = 'ucp' + AND module_basename = 'profile' + AND module_mode = 'profile_info'"; + _sql($sql, $errored, $error_ary); + $no_updates = false; break; diff --git a/phpBB/ucp.php b/phpBB/ucp.php index 7f4cd94f6f..a7e75f76c4 100644 --- a/phpBB/ucp.php +++ b/phpBB/ucp.php @@ -334,12 +334,6 @@ if (!$config['allow_topic_notify'] && !$config['allow_forum_notify']) $vars = array('module', 'id', 'mode'); extract($phpbb_dispatcher->trigger_event('core.ucp_display_module_before', compact($vars))); -// Do not display profile information panel if not authed to do so -if (!$auth->acl_get('u_chgprofileinfo')) -{ - $module->set_display('profile', 'profile_info', false); -} - // Select the active module $module->set_active($id, $mode); From c23d2457e9be616bfa83aebc5e743130b6c69624 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 7 Dec 2012 12:50:21 +0100 Subject: [PATCH 645/645] [ticket/10679] Update module basename, we added the xcp_ prefix in 3.1 PHPBB3-10679 --- phpBB/install/database_update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 95fd1ca2c2..30592b995d 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -2834,7 +2834,7 @@ function change_database_data(&$no_updates, $version) $sql = 'UPDATE ' . MODULES_TABLE . " SET module_auth = 'acl_u_chgprofileinfo' WHERE module_class = 'ucp' - AND module_basename = 'profile' + AND module_basename = 'ucp_profile' AND module_mode = 'profile_info'"; _sql($sql, $errored, $error_ary);