field.php
106 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 | * Layout variables |
| 16 | * ----------------- |
| 17 | * @var string $name The field name. |
| 18 | * @var string $value The selected media file. |
| 19 | * @var string $id The field ID attribute. |
| 20 | * @var array $attrs A list of field attributes. |
| 21 | * @var string $modal The media manager modal. In case the string is empty, |
| 22 | * the modal has been already rendered by a different field. |
| 23 | * @var boolean $preview True to display the preview button. |
| 24 | * @var boolean $filter True to accept only images, false to accept text documents too. |
| 25 | * @var string $icon An icon to use for the upload/choose button. |
| 26 | */ |
| 27 | extract($displayData); |
| 28 | |
| 29 | // fetch attributes string |
| 30 | $attrs_str = ''; |
| 31 | |
| 32 | foreach ($attrs as $k => $v) |
| 33 | { |
| 34 | $attrs_str .= ' ' . $k; |
| 35 | |
| 36 | if (!is_bool($v)) |
| 37 | { |
| 38 | $attrs_str .= ' = "' . $this->escape($v) . '"'; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | ?> |
| 43 | |
| 44 | <div class="input-append vap-media-manager-field"> |
| 45 | |
| 46 | <?php |
| 47 | if (!empty($attrs['multiple'])) |
| 48 | { |
| 49 | if (!is_array($value)) |
| 50 | { |
| 51 | $value = $value ? (array) $value : array(); |
| 52 | } |
| 53 | |
| 54 | foreach ($value as $file) |
| 55 | { |
| 56 | ?><input type="hidden" name="<?php echo $name; ?>" value="<?php echo $file; ?>" /><?php |
| 57 | } |
| 58 | |
| 59 | $count = count($value); |
| 60 | |
| 61 | if ($count > 1) |
| 62 | { |
| 63 | $value = JText::plural('VAP_DEF_N_SELECTED', $count); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | $value = (string) array_shift($value); |
| 68 | } |
| 69 | } |
| 70 | ?> |
| 71 | |
| 72 | <input |
| 73 | type="text" |
| 74 | readonly="readonly" |
| 75 | name="<?php echo empty($attrs['multiple']) ? $name : ''; ?>" |
| 76 | data-name="<?php echo $name; ?>" |
| 77 | value="<?php echo (string) $value; ?>" |
| 78 | id="<?php echo $id; ?>" |
| 79 | data-filter="<?php echo (int) $filter; ?>" |
| 80 | <?php echo $attrs_str; ?> |
| 81 | /> |
| 82 | |
| 83 | <?php |
| 84 | if ($preview) |
| 85 | { |
| 86 | ?> |
| 87 | <button type="button" class="btn media-preview" onclick="vapMediaStartPreview('#<?php echo $id; ?>', <?php echo $path ? '\'' . addslashes($path) . '\'' : 'null'; ?>);"> |
| 88 | <i class="fas fa-eye"></i> |
| 89 | </button> |
| 90 | <?php |
| 91 | } |
| 92 | ?> |
| 93 | |
| 94 | <button type="button" class="btn media-select" onclick="vapMediaOpenJModal('#<?php echo $id; ?>', <?php echo $path ? '\'' . base64_encode($path) . '\'' : 'null'; ?>);"> |
| 95 | <i class="<?php echo $icon ? $icon : 'fas fa-image'; ?>"></i> |
| 96 | </button> |
| 97 | |
| 98 | </div> |
| 99 | |
| 100 | <?php |
| 101 | if ($modal) |
| 102 | { |
| 103 | echo $modal; |
| 104 | } |
| 105 | ?> |
| 106 |