|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use Collective\Html\HtmlFacade as HTML; |
| 3 | +use Illuminate\Support\Facades\Auth; |
| 4 | +use Illuminate\Support\Facades\URL; |
| 5 | +use Illuminate\Support\HtmlString; |
4 | 6 |
|
5 | 7 | /** |
6 | 8 | * Render an image with an anchor tag around it. |
|
15 | 17 | * |
16 | 18 | * @return string |
17 | 19 | */ |
18 | | -HTML::macro('image_link', function ($url = '', $img = '', $alt = '', $link_name = '', $param = '', $active = true, $ssl = false) { |
19 | | - $url = $ssl === true ? URL::to_secure($url) : URL::to($url); |
20 | | - $img = HTML::image($img, $alt); |
21 | | - $img .= $link_name; |
22 | | - $link = $active === true ? HTML::link($url, '#', $param) : $img; |
23 | | - $link = str_replace('#', $img, $link); |
| 20 | +html()->macro('image_link', function ($url = '', $img = '', $alt = '', $link_name = '', $param = [], $active = true, $ssl = false) { |
| 21 | + $url = URL::to($url, [], $ssl === true); |
| 22 | + $imageHtml = (string) html()->img($img, $alt); |
| 23 | + $imageHtml .= $link_name; |
| 24 | + |
| 25 | + if ($active !== true) { |
| 26 | + return new HtmlString($imageHtml); |
| 27 | + } |
| 28 | + |
| 29 | + $link = html()->a($url)->html($imageHtml); |
| 30 | + |
| 31 | + if (is_array($param) && ! empty($param)) { |
| 32 | + $link = $link->attributes($param); |
| 33 | + } |
24 | 34 |
|
25 | 35 | return $link; |
26 | 36 | }); |
|
37 | 47 | * |
38 | 48 | * @return string |
39 | 49 | */ |
40 | | -HTML::macro('icon_link', function ($url = '', $icon = '', $link_name = '', $param = '', $active = true, $ssl = false) { |
41 | | - $url = $ssl === true ? URL::to_secure($url) : URL::to($url); |
42 | | - $icon = '<i class="'.$icon.'" aria-hidden="true"></i>'.$link_name; |
43 | | - $link = $active === true ? HTML::link($url, '#', $param) : $icon; |
44 | | - $link = str_replace('#', $icon, $link); |
| 50 | +html()->macro('icon_link', function ($url = '', $icon = '', $link_name = '', $param = [], $active = true, $ssl = false) { |
| 51 | + $url = URL::to($url, [], $ssl === true); |
| 52 | + $iconHtml = '<i class="'.$icon.'" aria-hidden="true"></i>'.$link_name; |
| 53 | + |
| 54 | + if ($active !== true) { |
| 55 | + return new HtmlString($iconHtml); |
| 56 | + } |
| 57 | + |
| 58 | + $link = html()->a($url)->html($iconHtml); |
| 59 | + |
| 60 | + if (is_array($param) && ! empty($param)) { |
| 61 | + $link = $link->attributes($param); |
| 62 | + } |
45 | 63 |
|
46 | 64 | return $link; |
47 | 65 | }); |
|
58 | 76 | * |
59 | 77 | * @return string |
60 | 78 | */ |
61 | | -HTML::macro('icon_btn', function ($url = '', $icon = '', $link_name = '', $param = '', $active = true, $ssl = false) { |
62 | | - $url = $ssl === true ? URL::to_secure($url) : URL::to($url); |
63 | | - $icon = $link_name.' <i class="'.$icon.'" aria-hidden="true"></i>'; |
64 | | - $link = $active === true ? HTML::link($url, '#', $param) : $icon; |
65 | | - $link = str_replace('#', $icon, $link); |
| 79 | +html()->macro('icon_btn', function ($url = '', $icon = '', $link_name = '', $param = [], $active = true, $ssl = false) { |
| 80 | + $url = URL::to($url, [], $ssl === true); |
| 81 | + $iconHtml = $link_name.' <i class="'.$icon.'" aria-hidden="true"></i>'; |
| 82 | + |
| 83 | + if ($active !== true) { |
| 84 | + return new HtmlString($iconHtml); |
| 85 | + } |
| 86 | + |
| 87 | + $link = html()->a($url)->html($iconHtml); |
| 88 | + |
| 89 | + if (is_array($param) && ! empty($param)) { |
| 90 | + $link = $link->attributes($param); |
| 91 | + } |
66 | 92 |
|
67 | 93 | return $link; |
68 | 94 | }); |
|
72 | 98 | * |
73 | 99 | * @return string |
74 | 100 | */ |
75 | | -HTML::macro('show_username', function () { |
| 101 | +html()->macro('show_username', function () { |
76 | 102 | $the_username = (Auth::user()->name === Auth::user()->email) ? ((is_null(Auth::user()->first_name)) ? (Auth::user()->name) : (Auth::user()->first_name)) : ((is_null(Auth::user()->name)) ? (Auth::user()->email) : (Auth::user()->name)); |
77 | 103 |
|
78 | 104 | return $the_username; |
|
0 commit comments