Skip to content

Commit b7bd210

Browse files
committed
[ticket/14117] Add core events to index.php to allow modifying birthdays list
PHPBB3-14117
1 parent 1164cc3 commit b7bd210

1 file changed

Lines changed: 48 additions & 15 deletions

File tree

phpBB/index.php

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
$legend = implode($user->lang['COMMA_SEPARATOR'], $legend);
120120

121121
// Generate birthday list if required ...
122-
$birthday_list = array();
122+
$birthdays = $birthday_list = array();
123123
if ($config['load_birthdays'] && $config['allow_birthdays'] && $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'))
124124
{
125125
$time = $user->create_datetime();
@@ -132,33 +132,66 @@
132132
$leap_year_birthdays = " OR u.user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', 29, 2)) . "%'";
133133
}
134134

135-
$sql = 'SELECT u.user_id, u.username, u.user_colour, u.user_birthday
136-
FROM ' . USERS_TABLE . ' u
137-
LEFT JOIN ' . BANLIST_TABLE . " b ON (u.user_id = b.ban_userid)
138-
WHERE (b.ban_id IS NULL
139-
OR b.ban_exclude = 1)
135+
$sql_ary = array(
136+
'SELECT' => 'u.user_id, u.username, u.user_colour, u.user_birthday',
137+
'FROM' => array(
138+
USERS_TABLE => 'u',
139+
),
140+
'LEFT_JOIN' => array(
141+
array(
142+
'FROM' => array(BANLIST_TABLE => 'b'),
143+
'ON' => 'u.user_id = b.ban_userid',
144+
),
145+
),
146+
'WHERE' => "(b.ban_id IS NULL OR b.ban_exclude = 1)
140147
AND (u.user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', $now['mday'], $now['mon'])) . "%' $leap_year_birthdays)
141-
AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')';
148+
AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')',
149+
);
150+
151+
/**
152+
* Event to modify the SQL query to get birthdays data
153+
*
154+
* @event core.index_modify_birthdays_sql
155+
* @var array now The assoc array with the 'now' local timestamp data
156+
* @var array sql_ary The SQL array to get the birthdays data
157+
* @var object time The user related Datetime object
158+
* @since 3.1.7-RC1
159+
*/
160+
$vars = array('now', 'sql_ary', 'time');
161+
extract($phpbb_dispatcher->trigger_event('core.index_modify_birthdays_sql', compact($vars)));
162+
163+
$sql = $db->sql_build_query('SELECT', $sql_ary);
142164
$result = $db->sql_query($sql);
165+
$rows = $db->sql_fetchrowset($result);
166+
$db->sql_freeresult($result);
143167

144-
while ($row = $db->sql_fetchrow($result))
168+
foreach ($rows as $row)
145169
{
146170
$birthday_username = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
147171
$birthday_year = (int) substr($row['user_birthday'], -4);
148172
$birthday_age = ($birthday_year) ? max(0, $now['year'] - $birthday_year) : '';
149173

150-
$template->assign_block_vars('birthdays', array(
174+
$birthdays[] = array(
151175
'USERNAME' => $birthday_username,
152176
'AGE' => $birthday_age,
153-
));
177+
);
154178

155179
// For 3.0 compatibility
156-
if ($age = (int) substr($row['user_birthday'], -4))
157-
{
158-
$birthday_list[] = $birthday_username . (($birthday_year) ? ' (' . $birthday_age . ')' : '');
159-
}
180+
$birthday_list[] = $birthday_username . (($birthday_age) ? " ({$birthday_age})" : '');
160181
}
161-
$db->sql_freeresult($result);
182+
183+
/**
184+
* Event to modify the birthdays list
185+
*
186+
* @event core.index_modify_birthdays_list
187+
* @var array birthdays Array with the users birhtdays data
188+
* @var array rows Array with the birhtdays SQL query result
189+
* @since 3.1.7-RC1
190+
*/
191+
$vars = array('birthdays', 'rows');
192+
extract($phpbb_dispatcher->trigger_event('core.index_modify_birthdays_list', compact($vars)));
193+
194+
$template->assign_block_vars_array('birthdays', $birthdays);
162195
}
163196

164197
// Assign index specific vars

0 commit comments

Comments
 (0)