1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-19 23:32:02 +02:00

Merge pull request #3965 from marc1706/ticket/14234

[ticket/14234] Use replacement variables instead of references in events

* marc1706/ticket/14234:
  [ticket/14234] Fix event doc blocks
  [ticket/14234] Get rid of undefined variables
  [ticket/14234] Fix change version and remove more references
  [ticket/14234] Replace more references with variables
  [ticket/14234] Use replacement variables instead of references in events
This commit is contained in:
Tristan Darricau 2015-10-14 08:59:17 +02:00
commit 1d6e173259
11 changed files with 126 additions and 63 deletions

View File

@ -950,17 +950,21 @@ class acp_forums
$errors = array();
$forum_data_ary = $forum_data;
/**
* Validate the forum data before we create/update the forum
*
* @event core.acp_manage_forums_validate_data
* @var array forum_data Array with new forum data
* @var array forum_data_ary Array with new forum data
* @var array errors Array of errors, should be strings and not
* language key.
* @since 3.1.0-a1
* @change 3.2.0-a1 Replaced forum_data with forum_data_ary
*/
$vars = array('forum_data', 'errors');
$vars = array('forum_data_ary', 'errors');
extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_validate_data', compact($vars)));
$forum_data = $forum_data_ary;
unset($forum_data_ary);
if ($forum_data['forum_name'] == '')
{
@ -1058,18 +1062,22 @@ class acp_forums
}
unset($forum_data_sql['forum_password_unset']);
$forum_data_ary = $forum_data;
/**
* Remove invalid values from forum_data_sql that should not be updated
*
* @event core.acp_manage_forums_update_data_before
* @var array forum_data Array with forum data
* @var array forum_data_ary Array with forum data
* @var array forum_data_sql Array with data we are going to update
* If forum_data_sql[forum_id] is set, we update
* that forum, otherwise a new one is created.
* @since 3.1.0-a1
* @change 3.2.0-a1 Replaced forum_data by forum_data_ary
*/
$vars = array('forum_data', 'forum_data_sql');
$vars = array('forum_data_ary', 'forum_data_sql');
extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_before', compact($vars)));
$forum_data = $forum_data_ary;
unset($forum_data_ary);
$is_new_forum = !isset($forum_data_sql['forum_id']);
@ -1348,11 +1356,12 @@ class acp_forums
$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_FORUM_EDIT', false, array($forum_data['forum_name']));
}
$forum_data_ary = $forum_data;
/**
* Event after a forum was updated or created
*
* @event core.acp_manage_forums_update_data_after
* @var array forum_data Array with forum data
* @var array forum_data_ary Array with forum data
* @var array forum_data_sql Array with data we updated
* @var bool is_new_forum Did we create a forum or update one
* If you want to overwrite this value,
@ -1360,9 +1369,12 @@ class acp_forums
* @var array errors Array of errors, should be strings and not
* language key.
* @since 3.1.0-a1
* @change 3.2.0-a1 Replaced forum_data with forum_data_ary
*/
$vars = array('forum_data', 'forum_data_sql', 'is_new_forum', 'errors');
$vars = array('forum_data_ary', 'forum_data_sql', 'is_new_forum', 'errors');
extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_update_data_after', compact($vars)));
$forum_data = $forum_data_ary;
unset($forum_data_ary);
return $errors;
}

View File

@ -383,6 +383,7 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
$tpl .= $vars['append'];
}
$new_ary = $new;
/**
* Overwrite the html code we display for the config value
*
@ -392,14 +393,17 @@ function build_cfg_template($tpl_type, $key, &$new, $config_key, $vars)
* 1 [optional] => string: size, int: minimum
* 2 [optional] => string: max. length, int: maximum
* @var string key Should be used for the id attribute in html
* @var array new Array with the config values we display
* @var array new_ary Array with the config values we display
* @var string name Should be used for the name attribute
* @var array vars Array with the options for the config
* @var string tpl The resulting html code we display
* @since 3.1.0-a1
* @change 3.2.0-a1 Replaced new with new_ary
*/
$vars = array('tpl_type', 'key', 'new', 'name', 'vars', 'tpl');
$vars = array('tpl_type', 'key', 'new_ary', 'name', 'vars', 'tpl');
extract($phpbb_dispatcher->trigger_event('core.build_config_template', compact($vars)));
$new = $new_ary;
unset($new_ary);
return $tpl;
}

View File

@ -1210,6 +1210,7 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count,
);
}
$update_count_ary = $update_count;
/**
* Use this event to modify the attachment template data.
*
@ -1223,8 +1224,9 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count,
* @var array extensions Array with attachment extensions data
* @var mixed forum_id The forum id the attachments are displayed in (false if in private message)
* @var bool preview Flag indicating if we are in post preview mode
* @var array update_count Array with attachment ids to update download count
* @var array update_count_ary Array with attachment ids to update download count
* @since 3.1.0-RC5
* @change 3.2.0-a1 Replaced update_count with update_count_ary
*/
$vars = array(
'attachment',
@ -1234,9 +1236,11 @@ function parse_attachments($forum_id, &$message, &$attachments, &$update_count,
'extensions',
'forum_id',
'preview',
'update_count',
'update_count_ary',
);
extract($phpbb_dispatcher->trigger_event('core.parse_attachments_modify_template_data', compact($vars)));
$update_count = $update_count_ary;
unset($update_count_ary);
$template->assign_block_vars('_file', $block_array);

View File

@ -438,15 +438,14 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
*
* @event core.display_forums_modify_category_template_vars
* @var array cat_row Template data of the 'category'
* @var bool catless The flag indicating whether the 'category' has a parent category
* @var bool last_catless The flag indicating whether the last forum had a parent category
* @var array root_data Array with the root forum data
* @var array row The data of the 'category'
* @since 3.1.0-RC4
* @change 3.1.7-RC1 Removed undefined catless variable
*/
$vars = array(
'cat_row',
'catless',
'last_catless',
'root_data',
'row',
@ -811,25 +810,29 @@ function generate_forum_nav(&$forum_data)
'S_ENABLE_FEEDS_FORUM' => ($config['feed_forum'] && $forum_data['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data['forum_options'])) ? true : false,
);
$forum_data_ary = $forum_data;
/**
* Event to modify the navlinks text
*
* @event core.generate_forum_nav
* @var array forum_data Array with the forum data
* @var array forum_data_ary Array with the forum data
* @var array forum_template_data Array with generic forum template data
* @var string microdata_attr The microdata attribute
* @var array navlinks_parents Array with the forum parents navlinks data
* @var array navlinks Array with the forum navlinks data
* @since 3.1.5-RC1
* @change 3.2.0-a1 Replaced forum_data with forum_data_ary
*/
$vars = array(
'forum_data',
'forum_data_ary',
'forum_template_data',
'microdata_attr',
'navlinks_parents',
'navlinks',
);
extract($phpbb_dispatcher->trigger_event('core.generate_forum_nav', compact($vars)));
$forum_data = $forum_data_ary;
unset($forum_data_ary);
$template->assign_block_vars_array('navlinks', $navlinks_parents);
$template->assign_block_vars('navlinks', $navlinks);
@ -1237,17 +1240,21 @@ function display_user_activity(&$userdata)
}
}
$userdata_ary = $userdata;
/**
* Alter list of forums and topics to display as active
*
* @event core.display_user_activity_modify_actives
* @var array userdata User's data
* @var array userdata_ary User's data
* @var array active_f_row List of active forums
* @var array active_t_row List of active posts
* @since 3.1.0-RC3
* @change 3.2.0-a1 Replaced userdata with userdata_ary
*/
$vars = array('userdata', 'active_f_row', 'active_t_row');
$vars = array('userdata_ary', 'active_f_row', 'active_t_row');
extract($phpbb_dispatcher->trigger_event('core.display_user_activity_modify_actives', compact($vars)));
$userdata = $userdata_ary;
unset($userdata_ary);
$userdata['active_t_row'] = $active_t_row;
$userdata['active_f_row'] = $active_f_row;

View File

@ -557,6 +557,11 @@ function phpbb_mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by
// Default total to -1 to allow editing by the event
$total = -1;
$sort_by_sql_ary = $sort_by_sql;
$sort_days_val = $sort_days;
$sort_dir_val = $sort_dir;
$sort_key_val = $sort_key;
$total_val = $total;
/**
* This event allows you to control the SQL query used to get the total number
* of reports the user can access.
@ -571,19 +576,20 @@ function phpbb_mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by
* @var string type Which kind of information is this being used for displaying. Posts, topics, etc...
* @var int forum_id The forum id of the posts the user is trying to access, if not 0
* @var int topic_id The topic id of the posts the user is trying to access, if not 0
* @var int sort_days The max age of the oldest report to be shown, in days
* @var string sort_key The way the user has decided to sort the data.
* @var int sort_days_val The max age of the oldest report to be shown, in days
* @var string sort_key_val The way the user has decided to sort the data.
* The valid values must be in the keys of the sort_by_* variables
* @var string sort_dir Either 'd' for "DESC" or 'a' for 'ASC' in the SQL query
* @var string sort_dir_val Either 'd' for "DESC" or 'a' for 'ASC' in the SQL query
* @var int limit_days The possible max ages of the oldest report for the user to choose, in days.
* @var array sort_by_sql SQL text (values) for the possible names of the ways of sorting data (keys).
* @var array sort_by_sql_ary SQL text (values) for the possible names of the ways of sorting data (keys).
* @var array sort_by_text Language text (values) for the possible names of the ways of sorting data (keys).
* @var int min_time Integer with the minimum post time that the user is searching for
* @var int limit_time_sql Time limiting options used in the SQL query.
* @var int total The total number of reports that exist. Only set if you want to override the result
* @var int total_val The total number of reports that exist. Only set if you want to override the result
* @var string where_sql Extra information included in the WHERE clause. It must end with "WHERE" or "AND" or "OR".
* Set to "WHERE" and set total above -1 to override the total value
* @since 3.1.4-RC1
* @change 3.2.0-a1 Replaced sort_days, sort_key, sort_dir, sort_by_sql, total with replacement variables
*/
$vars = array(
'sql',
@ -591,18 +597,28 @@ function phpbb_mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by
'type',
'forum_id',
'topic_id',
'sort_days',
'sort_key',
'sort_dir',
'sort_days_val',
'sort_key_val',
'sort_dir_val',
'limit_days',
'sort_by_sql',
'sort_by_sql_ary',
'sort_by_text',
'min_time',
'limit_time_sql',
'total',
'total_val',
'where_sql',
);
extract($phpbb_dispatcher->trigger_event('core.mcp_sorting_query_before', compact($vars)));
$sort_by_sql = $sort_by_sql_ary;
$sort_days = $sort_days_val;
$sort_key = $sort_key_val;
$sort_dir = $sort_dir_val;
$total = $total_val;
unset($sort_by_sql_ary);
unset($sort_days_val);
unset($sort_key_val);
unset($sort_dir_val);
unset($total_val);
if (!isset($sort_by_sql[$sort_key]))
{

View File

@ -1364,6 +1364,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
{
global $db, $auth, $user, $config, $phpEx, $template, $phpbb_root_path, $phpbb_container, $phpbb_dispatcher, $phpbb_log, $request;
$poll_ary = $poll;
$data_ary = $data;
/**
* Modify the data for post submitting
*
@ -1372,23 +1374,28 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
* @var string subject Variable containing post subject value
* @var string username Variable containing post author name
* @var int topic_type Variable containing topic type value
* @var array poll Array with the poll data for the post
* @var array data Array with the data for the post
* @var array poll_ary Array with the poll data for the post
* @var array data_ary Array with the data for the post
* @var bool update_message Flag indicating if the post will be updated
* @var bool update_search_index Flag indicating if the search index will be updated
* @since 3.1.0-a4
* @change 3.2.0-a1 Replaced poll and data with poll_ary and data_ary
*/
$vars = array(
'mode',
'subject',
'username',
'topic_type',
'poll',
'data',
'poll_ary',
'data_ary',
'update_message',
'update_search_index',
);
extract($phpbb_dispatcher->trigger_event('core.modify_submit_post_data', compact($vars)));
$poll = $poll_ary;
$data = $data_ary;
unset($poll_ary);
unset($data_ary);
// We do not handle erasing posts here
if ($mode == 'delete')
@ -1713,22 +1720,25 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
break;
}
$poll_ary = $poll;
$data_ary = $data;
/**
* Modify sql query data for post submitting
*
* @event core.submit_post_modify_sql_data
* @var array data Array with the data for the post
* @var array poll Array with the poll data for the post
* @var array data_ary Array with the data for the post
* @var array poll_ary Array with the poll data for the post
* @var string post_mode Variable containing posting mode value
* @var bool sql_data Array with the data for the posting SQL query
* @var string subject Variable containing post subject value
* @var int topic_type Variable containing topic type value
* @var string username Variable containing post author name
* @since 3.1.3-RC1
* @change 3.2.0-a1 Replace poll and data with poll_ary and data_ary
*/
$vars = array(
'data',
'poll',
'data_ary',
'poll_ary',
'post_mode',
'sql_data',
'subject',
@ -1736,6 +1746,10 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
'username',
);
extract($phpbb_dispatcher->trigger_event('core.submit_post_modify_sql_data', compact($vars)));
$poll = $poll_ary;
$data = $data_ary;
unset($poll_ary);
unset($data_ary);
// Submit new topic
if ($post_mode == 'post')
@ -2283,6 +2297,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
$url = (!$params) ? "{$phpbb_root_path}viewforum.$phpEx" : "{$phpbb_root_path}viewtopic.$phpEx";
$url = append_sid($url, 'f=' . $data['forum_id'] . $params) . $add_anchor;
$poll_ary = $poll;
$data_ary = $data;
/**
* This event is used for performing actions directly after a post or topic
* has been submitted. When a new topic is posted, the topic ID is
@ -2296,8 +2312,8 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
* @var string subject Variable containing post subject value
* @var string username Variable containing post author name
* @var int topic_type Variable containing topic type value
* @var array poll Array with the poll data for the post
* @var array data Array with the data for the post
* @var array poll_ary Array with the poll data for the post
* @var array data_ary Array with the data for the post
* @var int post_visibility Variable containing up to date post visibility
* @var bool update_message Flag indicating if the post will be updated
* @var bool update_search_index Flag indicating if the search index will be updated
@ -2306,20 +2322,25 @@ function submit_post($mode, $subject, $username, $topic_type, &$poll, &$data, $u
* @since 3.1.0-a3
* @change 3.1.0-RC3 Added vars mode, subject, username, topic_type,
* poll, update_message, update_search_index
* @change 3.2.0-a1 Replaced data and poll with data_ary and poll_ary
*/
$vars = array(
'mode',
'subject',
'username',
'topic_type',
'poll',
'data',
'poll_ary',
'data_ary',
'post_visibility',
'update_message',
'update_search_index',
'url',
);
extract($phpbb_dispatcher->trigger_event('core.submit_post_end', compact($vars)));
$data = $data_ary;
$poll = $poll_ary;
unset($data_ary);
unset($poll_ary);
return $url;
}

View File

@ -1620,17 +1620,21 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true)
$current_time = time();
$data_ary = $data;
/**
* Get all parts of the PM that are to be submited to the DB.
*
* @event core.submit_pm_before
* @var string mode PM Post mode - post|reply|quote|quotepost|forward|edit
* @var string subject Subject of the private message
* @var array data The whole row data of the PM.
* @var array data_ary The whole row data of the PM.
* @since 3.1.0-b3
* @change 3.2.0-a1 Replaced data with data_ary
*/
$vars = array('mode', 'subject', 'data');
$vars = array('mode', 'subject', 'data_ary');
extract($phpbb_dispatcher->trigger_event('core.submit_pm_before', compact($vars)));
$data = $data_ary;
unset($data_ary);
// Collect some basic information about which tables and which rows to update/insert
$sql_data = array();
@ -1939,18 +1943,22 @@ function submit_pm($mode, $subject, &$data, $put_in_outbox = true)
$phpbb_notifications->add_notifications('notification.type.pm', $pm_data);
}
$data_ary = $data;
/**
* Get PM message ID after submission to DB
*
* @event core.submit_pm_after
* @var string mode PM Post mode - post|reply|quote|quotepost|forward|edit
* @var string subject Subject of the private message
* @var array data The whole row data of the PM.
* @var array data_ary The whole row data of the PM.
* @var array pm_data The data sent to notification class
* @since 3.1.0-b5
* @change 3.2.0-a1 Replaced data with data_ary
*/
$vars = array('mode', 'subject', 'data', 'pm_data');
$vars = array('mode', 'subject', 'data_ary', 'pm_data');
extract($phpbb_dispatcher->trigger_event('core.submit_pm_after', compact($vars)));
$data = $data_ary;
unset($data_ary);
return $data['msg_id'];
}

View File

@ -334,16 +334,20 @@ function mcp_forum_view($id, $mode, $action, $forum_info)
));
}
$row_ary = $row;
/**
* Modify the topic data before it is assigned to the template in MCP
*
* @event core.mcp_view_forum_modify_topicrow
* @var array row Array with topic data
* @var array row_ary Array with topic data
* @var array topic_row Template array with topic data
* @since 3.1.0-a1
* @change 3.2.0-a1 Replace row with row_ary
*/
$vars = array('row', 'topic_row');
$vars = array('row_ary', 'topic_row');
extract($phpbb_dispatcher->trigger_event('core.mcp_view_forum_modify_topicrow', compact($vars)));
$row = $row_ary;
unset($row_ary);
$template->assign_block_vars('topicrow', $topic_row);
}

View File

@ -266,8 +266,6 @@ function compose_pm($id, $mode, $action, $user_folders = array())
*
* @event core.ucp_pm_compose_compose_pm_basic_info_query_before
* @var string sql String with the query to be executed
* @var array forum_list List of forums that contain the posts
* @var int visibility_const Integer with one of the possible ITEM_* constant values
* @var int msg_id topic_id in the page request
* @var int to_user_id The id of whom the message is to
* @var int to_group_id The id of the group whom the message is to
@ -276,14 +274,11 @@ function compose_pm($id, $mode, $action, $user_folders = array())
* @var string action One of: post, reply, quote, forward, quotepost, edit, delete, smilies
* @var bool delete Whether the user is deleting the PM
* @var int reply_to_all Value of reply_to_all request variable.
* @var string limit_time_sql String with the SQL code to limit the time interval of the post (Note: May be empty string)
* @var string sort_order_sql String with the ORDER BY SQL code used in this query
* @since 3.1.0-RC5
* @change 3.2.0-a1 Removed undefined variables
*/
$vars = array(
'sql',
'forum_list',
'visibility_const',
'msg_id',
'to_user_id',
'to_group_id',
@ -292,8 +287,6 @@ function compose_pm($id, $mode, $action, $user_folders = array())
'action',
'delete',
'reply_to_all',
'limit_time_sql',
'sort_order_sql',
);
extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_compose_pm_basic_info_query_before', compact($vars)));
@ -338,8 +331,6 @@ function compose_pm($id, $mode, $action, $user_folders = array())
* @var string sql The original SQL used in the query
* @var array post Associative array with the data of the quoted post
* @var array msg_id The post_id that was searched to get the message for quoting
* @var int visibility_const Visibility of the quoted post (one of the possible ITEM_* constant values)
* @var int topic_id Topic ID of the quoted post
* @var int to_user_id Users the message is sent to
* @var int to_group_id Groups the message is sent to
* @var bool submit Whether the user is sending the PM or not
@ -348,13 +339,12 @@ function compose_pm($id, $mode, $action, $user_folders = array())
* @var bool delete If deleting message
* @var int reply_to_all Value of reply_to_all request variable.
* @since 3.1.0-RC5
* @change 3.2.0-a1 Removed undefined variables
*/
$vars = array(
'sql',
'post',
'msg_id',
'visibility_const',
'topic_id',
'to_user_id',
'to_group_id',
'submit',

View File

@ -1255,7 +1255,6 @@ if ($submit || $preview || $refresh)
* @var array poll Array with poll data from post (must be used instead of the post_data equivalent)
* @var string mode What action to take if the form is submitted
* post|reply|quote|edit|delete|bump|smilies|popup
* @var string page_title Title of the mode page
* @var int post_id ID of the post
* @var int topic_id ID of the topic
* @var int forum_id ID of the forum
@ -1264,12 +1263,12 @@ if ($submit || $preview || $refresh)
* NOTE: Should be actual language strings, NOT language keys.
* @since 3.1.0-RC5
* @change 3.1.5-RC1 Added poll array to the event
* @change 3.2.0-a1 Removed undefined page_title
*/
$vars = array(
'post_data',
'poll',
'mode',
'page_title',
'post_id',
'topic_id',
'forum_id',
@ -1382,7 +1381,6 @@ if ($submit || $preview || $refresh)
* @var array data Array with post data going to be stored in the database
* @var string mode What action to take if the form is submitted
* post|reply|quote|edit|delete
* @var string page_title Title of the mode page
* @var int post_id ID of the post
* @var int topic_id ID of the topic
* @var int forum_id ID of the forum
@ -1392,13 +1390,13 @@ if ($submit || $preview || $refresh)
* NOTE: Should be actual language strings, NOT language keys.
* @since 3.1.0-RC5
* @changed 3.1.6-RC1 remove submit and error from event Submit and Error are checked previously prior to running event
* @change 3.2.0-a1 Removed undefined page_title
*/
$vars = array(
'post_data',
'poll',
'data',
'mode',
'page_title',
'post_id',
'topic_id',
'forum_id',
@ -1420,7 +1418,6 @@ if ($submit || $preview || $refresh)
* @var array data Array with post data going to be stored in the database
* @var string mode What action to take if the form is submitted
* post|reply|quote|edit|delete
* @var string page_title Title of the mode page
* @var int post_id ID of the post
* @var int topic_id ID of the topic
* @var int forum_id ID of the forum
@ -1431,13 +1428,13 @@ if ($submit || $preview || $refresh)
* NOTE: Should be actual language strings, NOT language keys.
* @since 3.1.0-RC5
* @changed 3.1.6-RC1 remove submit and error from event Submit and Error are checked previously prior to running event
* @change 3.2.0-a1 Removed undefined page_title
*/
$vars = array(
'post_data',
'poll',
'data',
'mode',
'page_title',
'post_id',
'topic_id',
'forum_id',

View File

@ -779,7 +779,7 @@ if ($keywords || $author || $author_id || $search_id || $submit)
$result = $db->sql_query($sql);
$result_topic_id = 0;
$rowset = array();
$rowset = $attachments = $topic_tracking_info = array();
if ($show_results == 'topics')
{