Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
68.42% |
13 / 19 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
username | |
68.42% |
13 / 19 |
|
33.33% |
1 / 3 |
16.53 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFunctions | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
get_username | |
66.67% |
10 / 15 |
|
0.00% |
0 / 1 |
13.70 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\template\twig\extension; |
15 | |
16 | use Twig\Extension\AbstractExtension; |
17 | |
18 | class username extends AbstractExtension |
19 | { |
20 | /** |
21 | * Get the name of this extension |
22 | * |
23 | * @return string |
24 | */ |
25 | public function getName() |
26 | { |
27 | return 'username'; |
28 | } |
29 | |
30 | /** |
31 | * {@inheritDoc} |
32 | */ |
33 | public function getFunctions() |
34 | { |
35 | return array( |
36 | new \Twig\TwigFunction('username', [$this, 'get_username']), |
37 | ); |
38 | } |
39 | |
40 | /** |
41 | * Get username details for placing into templates. |
42 | * |
43 | * How to use in a template: |
44 | * - {{ username('mode', user_id, username, user_colour, guest_username, custom_profile_url) }} |
45 | * - {{ username('mode', user_row, guest_username, custom_profile_url) }} |
46 | * It's possible to provide the user identifier, name and colour separately, |
47 | * or provide the entire user row at once as an array. |
48 | * |
49 | * The mode, user_id and username are required (separately or through a user row). |
50 | * The other fields (user_colour|guest_username|custom_profile_url) are optional. |
51 | * |
52 | * @uses \get_username_string() |
53 | * |
54 | * @return string A string based on what is wanted depending on $mode |
55 | */ |
56 | public function get_username() |
57 | { |
58 | $args = func_get_args(); |
59 | |
60 | $mode = $args[0]; |
61 | $user = $args[1]; |
62 | |
63 | // If the entire user row is provided |
64 | if (is_array($user)) |
65 | { |
66 | $user_id = isset($user['user_id']) ? $user['user_id'] : ''; |
67 | $username = isset($user['username']) ? $user['username'] : ''; |
68 | $user_colour = isset($user['user_colour']) ? $user['user_colour'] : ''; |
69 | $guest_username = isset($args[2]) ? $args[2] : false; |
70 | $custom_profile_url = isset($args[3]) ? $args[3] : false; |
71 | } |
72 | else |
73 | { |
74 | // Options are provided separately |
75 | $user_id = $user; |
76 | $username = $args[2]; |
77 | $user_colour = isset($args[3]) ? $args[3] : ''; |
78 | $guest_username = isset($args[4]) ? $args[4] : false; |
79 | $custom_profile_url = isset($args[5]) ? $args[5] : false; |
80 | } |
81 | |
82 | return get_username_string($mode, $user_id, $username, $user_colour, $guest_username, $custom_profile_url); |
83 | } |
84 | } |