|
119 | 119 | $legend = implode($user->lang['COMMA_SEPARATOR'], $legend); |
120 | 120 |
|
121 | 121 | // Generate birthday list if required ... |
122 | | -$birthday_list = array(); |
| 122 | +$birthdays = $birthday_list = array(); |
123 | 123 | if ($config['load_birthdays'] && $config['allow_birthdays'] && $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel')) |
124 | 124 | { |
125 | 125 | $time = $user->create_datetime(); |
|
132 | 132 | $leap_year_birthdays = " OR u.user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', 29, 2)) . "%'"; |
133 | 133 | } |
134 | 134 |
|
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) |
140 | 147 | 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); |
142 | 164 | $result = $db->sql_query($sql); |
| 165 | + $rows = $db->sql_fetchrowset($result); |
| 166 | + $db->sql_freeresult($result); |
143 | 167 |
|
144 | | - while ($row = $db->sql_fetchrow($result)) |
| 168 | + foreach ($rows as $row) |
145 | 169 | { |
146 | 170 | $birthday_username = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']); |
147 | 171 | $birthday_year = (int) substr($row['user_birthday'], -4); |
148 | 172 | $birthday_age = ($birthday_year) ? max(0, $now['year'] - $birthday_year) : ''; |
149 | 173 |
|
150 | | - $template->assign_block_vars('birthdays', array( |
| 174 | + $birthdays[] = array( |
151 | 175 | 'USERNAME' => $birthday_username, |
152 | 176 | 'AGE' => $birthday_age, |
153 | | - )); |
| 177 | + ); |
154 | 178 |
|
155 | 179 | // 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})" : ''); |
160 | 181 | } |
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); |
162 | 195 | } |
163 | 196 |
|
164 | 197 | // Assign index specific vars |
|
0 commit comments