assets.php
3 days ago
color.php
3 days ago
countries.php
3 days ago
index.html
3 days ago
media.php
3 days ago
site.php
3 days ago
sitescripts.php
3 days ago
status.php
3 days ago
vikappointments.php
3 days ago
site.php
173 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | /** |
| 15 | * VikAppointments HTML site helper. |
| 16 | * |
| 17 | * @since 1.7 |
| 18 | */ |
| 19 | abstract class VAPHtmlSite |
| 20 | { |
| 21 | /** |
| 22 | * Returns the image with the requested flag. |
| 23 | * |
| 24 | * @param string $code The county code or a langtag. |
| 25 | * @param array $config An array of configuration options. |
| 26 | * This array can contain a list of key/value pairs where values are boolean. |
| 27 | * |
| 28 | * @return string The HTML image tag. |
| 29 | */ |
| 30 | public static function flag($code, $config = array()) |
| 31 | { |
| 32 | if (preg_match("/^[a-z]{2,3}-([a-z]{2,2})$/i", $code, $match)) |
| 33 | { |
| 34 | // we have a langtag, find the last match |
| 35 | $code2 = end($match); |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | // use the given code (only 2 chars) |
| 40 | $code2 = substr($code, 0, 2); |
| 41 | } |
| 42 | |
| 43 | // build a lookup to adjust the tags when supplied in the WordPress format |
| 44 | $lookup = array( |
| 45 | 'el' => 'GR', |
| 46 | ); |
| 47 | |
| 48 | if (isset($lookup[$code2])) |
| 49 | { |
| 50 | $code2 = $lookup[$code2]; |
| 51 | } |
| 52 | |
| 53 | // find country name |
| 54 | $country = JHtml::fetch('vaphtml.countries.withcode', $code2); |
| 55 | |
| 56 | if (!$country) |
| 57 | { |
| 58 | // build a list of exceptions |
| 59 | $unitags = array( |
| 60 | 'AA' => 'Arabic Unitag', |
| 61 | ); |
| 62 | |
| 63 | if (isset($unitags[$code2])) |
| 64 | { |
| 65 | $country = $unitags[$code2]; |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | // country not found, return given code |
| 70 | return $code; |
| 71 | } |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | // use name only |
| 76 | $country = $country->name; |
| 77 | } |
| 78 | |
| 79 | $attrs = array(); |
| 80 | $attrs['src'] = VAPASSETS_URI . 'css/flags/' . strtolower($code2) . '.png'; |
| 81 | $attrs['title'] = $country . " ($code)"; |
| 82 | $attrs['alt'] = $attrs['title']; |
| 83 | $attrs['style'] = array(); |
| 84 | $attrs['class'] = array('flag'); |
| 85 | |
| 86 | if (isset($config['width'])) |
| 87 | { |
| 88 | $attrs['style'][] = 'width: ' . $config['width'] . (is_int($config['width']) ? 'px' : '') . ';'; |
| 89 | } |
| 90 | |
| 91 | if (isset($config['height'])) |
| 92 | { |
| 93 | $attrs['style'][] = 'height: ' . $config['height'] . (is_int($config['height']) ? 'px' : '') . ';'; |
| 94 | } |
| 95 | |
| 96 | if (isset($config['class'])) |
| 97 | { |
| 98 | if (is_array($config['class'])) |
| 99 | { |
| 100 | $attrs['class'] = array_merge($attrs['class'], $config['class']); |
| 101 | } |
| 102 | else |
| 103 | { |
| 104 | $attrs['class'][] = $config['class']; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // make attributes HTML compatible |
| 109 | foreach ($attrs as $k => &$attr) |
| 110 | { |
| 111 | if (is_array($attr)) |
| 112 | { |
| 113 | $attr = implode(' ', $attr); |
| 114 | } |
| 115 | |
| 116 | $attr = " {$k}=\"" . htmlspecialchars($attr, ENT_QUOTES, 'UTF-8') . "\""; |
| 117 | } |
| 118 | |
| 119 | // convert attributes list in HTML string |
| 120 | $attrs = implode(' ', $attrs); |
| 121 | |
| 122 | // create IMG tag |
| 123 | return "<img{$attrs}/>"; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Method to sort a column in a grid. |
| 128 | * |
| 129 | * @param string $title The link title. |
| 130 | * @param string $order The order field for the column. |
| 131 | * @param string $direction The current direction. |
| 132 | * @param string $selected The selected ordering. |
| 133 | * @param string $task An optional task override. |
| 134 | * @param string $new_direction An optional direction for the new column. |
| 135 | * @param string $tip An optional text shown as tooltip title instead of $title. |
| 136 | * @param string $form An optional form selector. |
| 137 | * |
| 138 | * @return string |
| 139 | */ |
| 140 | public static function sort($title, $order, $direction = 'asc', $selected = '', $task = null, $new_direction = 'asc', $tip = '', $form = null) |
| 141 | { |
| 142 | if (!$tip && preg_match("/ordering$/i", $order)) |
| 143 | { |
| 144 | // force "Ordering" as tooltip in order to avoid |
| 145 | // display the HTML of the icon |
| 146 | $tip = 'JGRID_HEADING_ORDERING'; |
| 147 | } |
| 148 | |
| 149 | // render grid HTML |
| 150 | $html = JHtml::fetch('grid.sort', $title, $order, $direction, $selected, $task, $new_direction, $tip, $form); |
| 151 | |
| 152 | // turn off tooltip or popover |
| 153 | $html = preg_replace("/\bhas(?:Tooltip|Popover)\b/", '', $html); |
| 154 | |
| 155 | // replace IcoMoon with FontAwesome |
| 156 | $html = preg_replace_callback("/<(?:span|i).*?class=\"([a-zA-Z0-9-_\s]+)\".*?>.*?<\/(?:span|i)>/i", function($match) |
| 157 | { |
| 158 | if (preg_match("/\bicon-arrow-up-3\b/", end($match))) |
| 159 | { |
| 160 | $icon = 'sort-up'; |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | $icon = 'sort-down'; |
| 165 | } |
| 166 | |
| 167 | return '<i class="fas fa-' . $icon . '"></i>'; |
| 168 | }, $html); |
| 169 | |
| 170 | return $html; |
| 171 | } |
| 172 | } |
| 173 |