address.php
3 days ago
city.php
3 days ago
company.php
3 days ago
country.php
3 days ago
email.php
3 days ago
index.html
3 days ago
nominative.php
3 days ago
pec.php
3 days ago
phone.php
3 days ago
ssn.php
3 days ago
state.php
3 days ago
vatnum.php
3 days ago
zip.php
3 days ago
email.php
95 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 custom field e-mail rule dispatcher. |
| 16 | * |
| 17 | * @since 1.7 |
| 18 | */ |
| 19 | class VAPCustomFieldRuleEmail extends VAPCustomFieldRule |
| 20 | { |
| 21 | /** |
| 22 | * Returns the name of the rule. |
| 23 | * |
| 24 | * @return string |
| 25 | */ |
| 26 | public function getName() |
| 27 | { |
| 28 | return JText::translate('VAPCUSTFIELDRULE2'); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Dispatches the field rule. |
| 33 | * |
| 34 | * @param mixed $value The value of the field set in request. |
| 35 | * @param array &$args The array data to fill-in in case of |
| 36 | * specific rules (name, e-mail, etc...). |
| 37 | * @param mixed $field The custom field object. |
| 38 | * |
| 39 | * @return void |
| 40 | */ |
| 41 | public function dispatch($value, &$args, $field) |
| 42 | { |
| 43 | /** |
| 44 | * Validate email address. |
| 45 | * |
| 46 | * @since 1.7.10 |
| 47 | */ |
| 48 | if ($value) |
| 49 | { |
| 50 | if (function_exists('\\is_email')) |
| 51 | { |
| 52 | // validate through WordPress native functions |
| 53 | $valid = is_email($value); |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | // validate through internal functions |
| 58 | $valid = VikAppointments::validateUserEmail($value); |
| 59 | } |
| 60 | |
| 61 | if (!$valid) |
| 62 | { |
| 63 | throw new InvalidArgumentException(JText::translate('VAP_INVALID_EMAIL_ERR'), 400); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // in case of multiple fields with e-mail rule, use only |
| 68 | // the first specified one |
| 69 | if (empty($args['purchaser_mail'])) |
| 70 | { |
| 71 | // fill e-mail column with field value |
| 72 | $args['purchaser_mail'] = $value; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Renders the field rule. |
| 78 | * |
| 79 | * @param array &$data An array of display data. |
| 80 | * @param mixed $field The custom field object. |
| 81 | * |
| 82 | * @return string The HTML that will be used in place of the layout |
| 83 | * defined by the field. Omit this value to keep using |
| 84 | * the default HTML of the field. |
| 85 | */ |
| 86 | public function render(&$data, $field) |
| 87 | { |
| 88 | // use a different type for input with e-mail rule |
| 89 | $data['type'] = 'email'; |
| 90 | |
| 91 | // inject class name |
| 92 | $data['class'] = (empty($data['class']) ? '' : $data['class'] . ' ') . 'mail-field'; |
| 93 | } |
| 94 | } |
| 95 |