Blame view
app/Support/Utils/Helpers.php
3.59 KB
e77200db5 Initial commit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
<?php namespace FootyRoom\Support\Utils; use Illuminate\Http\Request; class Helpers { /** * Returns URL for user's avatar. * * @param mixed $userId This can be set to "default" to display default avatar. * * @return string */ public static function avatarUrl($userId) { return 'https://'.app('FootyRoom\Config')->get('imagesHost').'/avatars/'.$userId; } public static function dateSelect() { $html = ''; $months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; //Day $html .= '<select id="dobDay" name="dobDay" class="form-control day-select">'; for ($day=1; $day<32; $day++) { $html .= '<option>'.$day.'</option>'; } $html .= '</select>'; //Month $html .= '<select id="dobMonth" name="dobMonth" class="form-control month-select">'; foreach ($months as $key => $month) { $html .= '<option value="'.($key+1).'">'.$month.'</option>'; } $html .= '</select>'; //Year $html .= '<select id="dobYear" name="dobYear" class="form-control year-select">'; for ($year=1900; $year<2012; $year++) { $html .= '<option>'.$year.'</option>'; } $html .= '</select>'; return $html; } /** * Returns html for rel links with. * * @param bool $hasNext * @param string $resource URL of the resource * @param int $page * @param bool $hasPrev * * @return string */ public static function relLinks($hasNext, $resource = null, $page = null, $hasPrev = true) { if (is_null($resource)) { $resource = app()->make(\Illuminate\Http\Request::class)->fullUrl(); } if (is_null($page)) { parse_str(parse_url($resource, PHP_URL_QUERY), $params); $page = isset($params['page']) ? (int) $params['page'] : 1; } // Remove `page` query string parameter from the resource URL. $resource = rtrim(preg_replace('/&?page=\d+/i', '', $resource), '?'); if (strpos($resource, '?') !== false) { $separator = '&'; } else { $separator = '?'; } $html = ''; if ($hasNext) { $html .= '<link rel="next" href="'.$resource.$separator.'page='.($page + 1).'">'; } if ($page > 2 && $hasPrev) { $html .= '<link rel="prev" href="'.$resource.$separator.'page='.($page - 1).'">'; } if ($page === 2 && $hasPrev) { $html .= '<link rel="prev" href="'.$resource.'">'; } return $html; } /** * Formats page title to site wide standard. */ public static function title($title) { return $title.' - FootyRoom'; } /** * Returns url for team's badge. * * @param id $teamId * * @return string */ public static function teamBadgeUrl($teamId) { return 'https://'.app('FootyRoom\Config')->get('imagesHost').'/badges/'.$teamId; } public static function nl2p($string) { $string = str_replace(['<p>', '</p>', '<br>', '<br />'], '', $string); return '<p>'.preg_replace( ["/([ ]{2,})/i", "/([^>]) ([^<])/i"], ["</p> <p>", '$1<br />$2'], trim($string) ).'</p>'; } /** * Get the CSRF token value. */ public static function csrfToken(): string { $request = app(Request::class); return $request->session()->token(); } } |