Source of file LatLngField.php
Size: 3,029 Bytes - Last Modified: 2021-12-23T10:06:41+00:00
/var/www/docs.ssmods.com/process/src/src/fields/LatLngField.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 | <?php namespace nomidi\SeoHeroTool; use SilverStripe\Forms\TextField; /** * Text input field with validation for latitude and lingitude values * * @package forms * @subpackage fields-formattedinput */ class LatLngField extends TextField { /** * @config * @var array */ private static $default_config = array( 'lat' => false, 'lng' => false ); /** * @var array */ protected $config; /** * {@inheritdoc} */ public function Type() { return 'lat & lng text'; } /** * Validates for RFC 2822 compliant email addresses. * * @see http://www.regular-expressions.info/email.html * @see http://www.ietf.org/rfc/rfc2822.txt * * @param Validator $validator * * @return string */ public function validate($validator) { $this->value = trim($this->value); if (strlen($this->value) == 0) { return true; } if ($this->getConfig('lat') === true) { #lat if (preg_match("/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/", $this->value)) { return true; } else { $validator->validationError( $this->name, _t('LatLngField.LatVal', 'Please enter an correct Latitude Value'), 'validation' ); return false; } } else { #lng if (preg_match("/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/", $this->value)) { return true; } else { $validator->validationError( $this->name, _t('LatLngField.LngVal', 'Please enter an correct Longitude Value'), 'validation' ); return false; } } /*$this->value = trim($this->value); $pattern = '^[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$'; // Escape delimiter characters. $safePattern = str_replace('/', '\\/', $pattern); if ($this->value && !preg_match('/' . $safePattern . '/i', $this->value)) { $validator->validationError( $this->name, _t('EmailField.VALIDATION', 'Please enter an email address'), 'validation' ); return false; } return true;*/ } /** * @param string $name * @param mixed $val */ public function setConfig($name, $val) { $this->config[$name] = $val; return $this; } /** * @param String $name Optional, returns the whole configuration array if empty * @return mixed|array */ public function getConfig($name = null) { if ($name) { return isset($this->config[$name]) ? $this->config[$name] : null; } else { return $this->config; } } } |