+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Horde/Form/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public function isValid($var, $vars, $value, $message)
}

$message = Horde_Form_Translation::t("This field must be a valid number.");
$this->message = $message;
return false;
}

Expand Down
110 changes: 110 additions & 0 deletions src/V3/AddressType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
namespace Horde\Form\V3;
use Horde_Form_Translation;
class AddressType extends LongtextType
{
public function parse($address)
{
$info = [];
$aus_state_regex = '(?:ACT|NSW|NT|QLD|SA|TAS|VIC|WA)';

if (preg_match('/(?s)(.*?)(?-s)\r?\n(?:(.*?)\s+)?((?:A[BL]|B[ABDHLNRST]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[CHNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTWY]?|T[ADFNQRSW]|UB|W[ACDFNRSV]?|YO|ZE)\d(?:\d|[A-Z])? \d[A-Z]{2})/', $address, $addressParts)) {
/* UK postcode detected. */
$info = ['country' => 'uk', 'zip' => $addressParts[3]];
if (!empty($addressParts[1])) {
$info['street'] = $addressParts[1];
}
if (!empty($addressParts[2])) {
$info['city'] = $addressParts[2];
}
} elseif (preg_match('/\b' . $aus_state_regex . '\b/', $address)) {
/* Australian state detected. */
/* Split out the address, line-by-line. */
$addressLines = preg_split('/\r?\n/', $address);
$info = ['country' => 'au'];
for ($i = 0; $i < count($addressLines); $i++) {
/* See if it's the street number & name. */
if (preg_match('/(\d+\s*\/\s*)?(\d+|\d+[a-zA-Z])\s+([a-zA-Z ]*)/', $addressLines[$i], $lineParts)) {
$info['street'] = $addressLines[$i];
$info['streetNumber'] = $lineParts[2];
$info['streetName'] = $lineParts[3];
}
/* Look for "Suburb, State". */
if (preg_match('/([a-zA-Z ]*),?\s+(' . $aus_state_regex . ')/', $addressLines[$i], $lineParts)) {
$info['city'] = $lineParts[1];
$info['state'] = $lineParts[2];
}
/* Look for "State <4 digit postcode>". */
if (preg_match('/(' . $aus_state_regex . ')\s+(\d{4})/', $addressLines[$i], $lineParts)) {
$info['state'] = $lineParts[1];
$info['zip'] = $lineParts[2];
}
}
} elseif (preg_match('/(?s)(.*?)(?-s)\r?\n(.*)\s*,\s*(\w+)\.?\s+(\d+|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d)/', $address, $addressParts)) {
/* American/Canadian address style. */
$info = ['country' => 'us'];
if (!empty($addressParts[4]) &&
preg_match('|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d|', $addressParts[4])) {
$info['country'] = 'ca';
}
if (!empty($addressParts[1])) {
$info['street'] = $addressParts[1];
}
if (!empty($addressParts[2])) {
$info['city'] = $addressParts[2];
}
if (!empty($addressParts[3])) {
$info['state'] = $addressParts[3];
}
if (!empty($addressParts[4])) {
$info['zip'] = $addressParts[4];
}
} elseif (preg_match('/(?:(?s)(.*?)(?-s)(?:\r?\n|,\s*))?(?:([A-Z]{1,3})-)?(\d{4,5})\s+(.*)(?:\r?\n(.*))?/i', $address, $addressParts)) {
/* European address style. */
$info = [];
if (!empty($addressParts[1])) {
$info['street'] = $addressParts[1];
}
if (!empty($addressParts[2])) {
include 'Horde/Nls/Carsigns.php';
$country = array_search(Horde_String::upper($addressParts[2]), $carsigns);
if ($country) {
$info['country'] = $country;
}
}
if (!empty($addressParts[5])) {
include 'Horde/Nls/Countries.php';
$country = array_search($addressParts[5], $countries);
if ($country) {
$info['country'] = Horde_String::lower($country);
} elseif (!isset($info['street'])) {
$info['street'] = trim($addressParts[5]);
} else {
$info['street'] .= "\n" . $addressParts[5];
}
}
if (!empty($addressParts[3])) {
$info['zip'] = $addressParts[3];
}
if (!empty($addressParts[4])) {
$info['city'] = trim($addressParts[4]);
}
}

return $info;
}

/**
* Return info about field type.
*/
public function about():array
{
return [
'name' => Horde_Form_Translation::t("Address"),
'params' => [
'rows' => ['label' => Horde_Form_Translation::t("Number of rows"),
'type' => 'int'],
'cols' => ['label' => Horde_Form_Translation::t("Number of columns"),
'type' => 'int']]];
}
}
19 changes: 19 additions & 0 deletions src/V3/AddresslinkType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
namespace Horde\Form\V3;
use Horde_Form_Translation;
class AddresslinkType extends AddressType
{
public function isValid($var, Horde_Variables|array $vars, $value)
{
return true;
}

/**
* Return info about field type.
*/
public function about():array
{
return ['name' => Horde_Form_Translation::t("Address Link")];
}

}
16 changes: 16 additions & 0 deletions src/V3/CellphoneType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace Horde\Form\V3;
use Horde_Form_Translation;
class CellphoneType extends PhoneType
{
public function about():array
{
return [
'name' => Horde_Form_Translation::t("Mobile phone number"),
'params' => [
'size' => ['label' => Horde_Form_Translation::t("Size"),
'type' => 'int'],
],
];
}
}
58 changes: 58 additions & 0 deletions src/V3/CountedtextType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
namespace Horde\Form\V3;
use Horde_Form_Translation;
class CountedtextType extends LongtextType
{
public $_chars;

/**
* Init a longtext field
*
* function init($rows = null, $cols = null, $chars = 1000)
*/
public function init(...$params)
{
$rows = $params[0] ?? null;
$cols = $params[1] ?? null;
$chars = $params[2] ?? 1000;
parent::init($rows, $cols);
$this->_chars = $chars;
}

public function isValid($var, Horde_Variables|array $vars, $value)
{
$valid = true;

$length = Horde_String::length(trim($value));

if ($var->isRequired() && $length <= 0) {
$valid = false;
$message = Horde_Form_Translation::t("This field is required.");

} elseif ($length > $this->_chars) {
$valid = false;
$message = sprintf(Horde_Form_Translation::ngettext("There are too many characters in this field. You have entered %d character; ", "There are too many characters in this field. You have entered %d characters; ", $length), $length)
. sprintf(Horde_Form_Translation::t("you must enter less than %d."), $this->_chars);
}

$this->message = (string)$message;
return $valid;
}

/**
* Return info about field type.
*/
public function about():array
{
return [
'name' => Horde_Form_Translation::t("Counted text"),
'params' => [
'rows' => ['label' => Horde_Form_Translation::t("Number of rows"),
'type' => 'int'],
'cols' => ['label' => Horde_Form_Translation::t("Number of columns"),
'type' => 'int'],
'chars' => ['label' => Horde_Form_Translation::t("Number of characters"),
'type' => 'int']]];
}

}
28 changes: 28 additions & 0 deletions src/V3/IntType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
namespace Horde\Form\V3;
use Horde_Form_Translation;
class IntType extends BaseType
{
public function isValid($var, Horde_Variables|array $vars, $value): bool
{
if ($var->isRequired() && empty($value) && ((string) (int) $value !== $value)) {
$this->message = Horde_Form_Translation::t("This field is required.");
return false;
}

if (empty($value) || preg_match('/^[0-9]+$/', $value)) {
return true;
}

$this->message = Horde_Form_Translation::t("This field may only contain integers.");
return false;
}

/**
* Return info about field type.
*/
public function about():array
{
return ['name' => Horde_Form_Translation::t("Integer")];
}
}
32 changes: 32 additions & 0 deletions src/V3/IntlistType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace Horde\Form\V3;
use Horde_Form_Translation;
class IntlistType extends BaseType
{
public function isValid($var, Horde_Variables|array $vars, $value)
{
if (empty($value) && $var->isRequired()) {
$message = Horde_Form_Translation::t("This field is required.");
$this->message = $message;
return false;
}

if (empty($value) || preg_match('/^[0-9 ,]+$/', $value)) {
return true;
}

$message = Horde_Form_Translation::t("This field must be a comma or space separated list of integers");
$this->message = $message;
return false;

}

/**
* Return info about field type.
*/
public function about():array
{
return ['name' => Horde_Form_Translation::t("Integer list")];
}

}
35 changes: 35 additions & 0 deletions src/V3/Ip6address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Horde\Form\V3;
use Horde_Form_Translation;
class Ip6adressType extends TextType
{
public function isValid($var, Horde_Variables|array $vars, $value)
{
$valid = true;

if (strlen(trim($value)) > 0) {
$valid = @inet_pton($value);

if ($valid === false) {
$message = Horde_Form_Translation::t("Please enter a valid IP address.");
$this->message = $message;

}
} elseif ($var->isRequired()) {
$valid = false;
$message = Horde_Form_Translation::t("This field is required.");
$this->message = $message;
}
// Looks like a bug. Shouldn't we return $valid here?
return true;
}

/**
* Return info about field type.
*/
public function about():array
{
return ['name' => Horde_Form_Translation::t("IPv6 address")];
}

}
44 changes: 44 additions & 0 deletions src/V3/IpadressType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace Horde\Form\V3;
use Horde_Form_Translation;
class IpadressType extends TextType
{
public function isValid($var, Horde_Variables|array $vars, $value)
{
$valid = true;

if (strlen(trim($value)) > 0) {
$ip = explode('.', $value);
$valid = (count($ip) == 4);
if ($valid) {
foreach ($ip as $part) {
if (!is_numeric($part) ||
$part > 255 ||
$part < 0) {
$valid = false;
break;
}
}
}

if (!$valid) {
$message = Horde_Form_Translation::t("Please enter a valid IP address.");
}
} elseif ($var->isRequired()) {
$valid = false;
$message = Horde_Form_Translation::t("This field is required.");
$this->message = $message;
}

return $valid;
}

/**
* Return info about field type.
*/
public function about():array
{
return ['name' => Horde_Form_Translation::t("IP address")];
}

}
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载