Completed
Branch FET-8385-datetime-ticket-selec... (dbda12)
by
unknown
194:55 queued 183:27
created
core/db_models/fields/EE_DB_Only_Int_Field.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,15 +3,15 @@
 block discarded – undo
3 3
 
4 4
 class EE_DB_Only_Int_Field extends EE_DB_Only_Field_Base
5 5
 {
6
-    /**
7
-     * @param string $table_column
8
-     * @param string $nicename
9
-     * @param bool   $nullable
10
-     * @param null   $default_value
11
-     */
12
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
13
-    {
14
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
15
-        $this->setSchemaType('integer');
16
-    }
6
+	/**
7
+	 * @param string $table_column
8
+	 * @param string $nicename
9
+	 * @param bool   $nullable
10
+	 * @param null   $default_value
11
+	 */
12
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
13
+	{
14
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
15
+		$this->setSchemaType('integer');
16
+	}
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Infinite_Integer_Field.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -11,77 +11,77 @@
 block discarded – undo
11 11
 class EE_Infinite_Integer_Field extends EE_Model_Field_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @param string $table_column
16
-     * @param string $nicename
17
-     * @param bool   $nullable
18
-     * @param null   $default_value
19
-     */
20
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
21
-    {
22
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
23
-        $this->setSchemaType(array('integer', 'null'));
24
-    }
14
+	/**
15
+	 * @param string $table_column
16
+	 * @param string $nicename
17
+	 * @param bool   $nullable
18
+	 * @param null   $default_value
19
+	 */
20
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
21
+	{
22
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
23
+		$this->setSchemaType(array('integer', 'null'));
24
+	}
25 25
 
26 26
 
27
-    function prepare_for_use_in_db($value_of_field_on_model_object)
28
-    {
29
-        if ($value_of_field_on_model_object === EE_INF) {
30
-            return EE_INF_IN_DB;
31
-        } else {
32
-            return intval($value_of_field_on_model_object);
33
-        }
34
-    }
27
+	function prepare_for_use_in_db($value_of_field_on_model_object)
28
+	{
29
+		if ($value_of_field_on_model_object === EE_INF) {
30
+			return EE_INF_IN_DB;
31
+		} else {
32
+			return intval($value_of_field_on_model_object);
33
+		}
34
+	}
35 35
 
36
-    function prepare_for_set($value_inputted_for_field_on_model_object)
37
-    {
38
-        if ($value_inputted_for_field_on_model_object === EE_INF_IN_DB ||
39
-            $value_inputted_for_field_on_model_object === EE_INF ||
40
-            $value_inputted_for_field_on_model_object === "EE_INF" ||
41
-            $value_inputted_for_field_on_model_object === ""
42
-        ) {
43
-            return EE_INF;
44
-        } else {
45
-            return intval($value_inputted_for_field_on_model_object);
46
-        }
47
-    }
36
+	function prepare_for_set($value_inputted_for_field_on_model_object)
37
+	{
38
+		if ($value_inputted_for_field_on_model_object === EE_INF_IN_DB ||
39
+			$value_inputted_for_field_on_model_object === EE_INF ||
40
+			$value_inputted_for_field_on_model_object === "EE_INF" ||
41
+			$value_inputted_for_field_on_model_object === ""
42
+		) {
43
+			return EE_INF;
44
+		} else {
45
+			return intval($value_inputted_for_field_on_model_object);
46
+		}
47
+	}
48 48
 
49
-    function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
50
-    {
51
-        $intval = intval($value_inputted_for_field_on_model_object);
52
-        if ($intval == EE_INF_IN_DB) {
53
-            return EE_INF;
54
-        } else {
55
-            return $intval;
56
-        }
57
-    }
49
+	function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
50
+	{
51
+		$intval = intval($value_inputted_for_field_on_model_object);
52
+		if ($intval == EE_INF_IN_DB) {
53
+			return EE_INF;
54
+		} else {
55
+			return $intval;
56
+		}
57
+	}
58 58
 
59
-    /**
60
-     * For outputting this field's value. If you want to output it into an input or something,
61
-     * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text'
62
-     * as it will replace EE_INF with i18n Infinite
63
-     *
64
-     * @param type   $value_on_field_to_be_outputted
65
-     * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF
66
-     * @return string
67
-     */
68
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
69
-    {
70
-        if ($value_on_field_to_be_outputted === EE_INF) {
71
-            switch ($schema) {
72
-                case 'input':
73
-                case 'form_input':
74
-                    return '';
75
-                case 'symbol':
76
-                    return "∞";
77
-                case 'text':
78
-                case null:
79
-                    return __("Unlimited", "event_espresso");
80
-                default:
81
-                    return $schema;
82
-            }
83
-        } else {
84
-            return $value_on_field_to_be_outputted;
85
-        }
86
-    }
59
+	/**
60
+	 * For outputting this field's value. If you want to output it into an input or something,
61
+	 * use $schema=='input', as it will replace EE_INF with ''. If you want a readable version, use $schema=='text'
62
+	 * as it will replace EE_INF with i18n Infinite
63
+	 *
64
+	 * @param type   $value_on_field_to_be_outputted
65
+	 * @param string $schema input, symbol, text; or any string you want to show if the value equals EE_INF
66
+	 * @return string
67
+	 */
68
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
69
+	{
70
+		if ($value_on_field_to_be_outputted === EE_INF) {
71
+			switch ($schema) {
72
+				case 'input':
73
+				case 'form_input':
74
+					return '';
75
+				case 'symbol':
76
+					return "∞";
77
+				case 'text':
78
+				case null:
79
+					return __("Unlimited", "event_espresso");
80
+				default:
81
+					return $schema;
82
+			}
83
+		} else {
84
+			return $value_on_field_to_be_outputted;
85
+		}
86
+	}
87 87
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Serialized_Text_Field.php 2 patches
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -10,72 +10,72 @@
 block discarded – undo
10 10
 class EE_Serialized_Text_Field extends EE_Text_Field_Base
11 11
 {
12 12
 
13
-    /**
14
-     * @param string $table_column
15
-     * @param string $nicename
16
-     * @param bool   $nullable
17
-     * @param null   $default_value
18
-     */
19
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
20
-    {
21
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
22
-        $this->setSchemaType(array('object','string'));
23
-    }
13
+	/**
14
+	 * @param string $table_column
15
+	 * @param string $nicename
16
+	 * @param bool   $nullable
17
+	 * @param null   $default_value
18
+	 */
19
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
20
+	{
21
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
22
+		$this->setSchemaType(array('object','string'));
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * Value SHOULD be an array, and we want to now convert it to a serialized string
28
-     *
29
-     * @param array $value_of_field_on_model_object
30
-     * @return string
31
-     */
32
-    function prepare_for_use_in_db($value_of_field_on_model_object)
33
-    {
34
-        return maybe_serialize($value_of_field_on_model_object);
35
-    }
26
+	/**
27
+	 * Value SHOULD be an array, and we want to now convert it to a serialized string
28
+	 *
29
+	 * @param array $value_of_field_on_model_object
30
+	 * @return string
31
+	 */
32
+	function prepare_for_use_in_db($value_of_field_on_model_object)
33
+	{
34
+		return maybe_serialize($value_of_field_on_model_object);
35
+	}
36 36
 
37
-    function prepare_for_set($value_inputted_for_field_on_model_object)
38
-    {
39
-        $value_inputted_for_field_on_model_object = EEH_Array::maybe_unserialize($value_inputted_for_field_on_model_object);
40
-        if (is_string($value_inputted_for_field_on_model_object)) {
41
-            return parent::prepare_for_set($value_inputted_for_field_on_model_object);
42
-        } elseif (is_array($value_inputted_for_field_on_model_object)) {
43
-            return array_map(array($this, 'prepare_for_set'), $value_inputted_for_field_on_model_object);
44
-        } else {//so they passed NULL or an INT or something wack
45
-            return $value_inputted_for_field_on_model_object;
46
-        }
47
-    }
37
+	function prepare_for_set($value_inputted_for_field_on_model_object)
38
+	{
39
+		$value_inputted_for_field_on_model_object = EEH_Array::maybe_unserialize($value_inputted_for_field_on_model_object);
40
+		if (is_string($value_inputted_for_field_on_model_object)) {
41
+			return parent::prepare_for_set($value_inputted_for_field_on_model_object);
42
+		} elseif (is_array($value_inputted_for_field_on_model_object)) {
43
+			return array_map(array($this, 'prepare_for_set'), $value_inputted_for_field_on_model_object);
44
+		} else {//so they passed NULL or an INT or something wack
45
+			return $value_inputted_for_field_on_model_object;
46
+		}
47
+	}
48 48
 
49
-    /**
50
-     * Value provided should definetely be a serialized string. We should unserialize into an array
51
-     *
52
-     * @param string $value_found_in_db_for_model_object
53
-     * @return array
54
-     */
55
-    function prepare_for_set_from_db($value_found_in_db_for_model_object)
56
-    {
57
-        return EEH_Array::maybe_unserialize($value_found_in_db_for_model_object);
58
-    }
49
+	/**
50
+	 * Value provided should definetely be a serialized string. We should unserialize into an array
51
+	 *
52
+	 * @param string $value_found_in_db_for_model_object
53
+	 * @return array
54
+	 */
55
+	function prepare_for_set_from_db($value_found_in_db_for_model_object)
56
+	{
57
+		return EEH_Array::maybe_unserialize($value_found_in_db_for_model_object);
58
+	}
59 59
 
60
-    /**
61
-     * Gets a string representation of the array
62
-     *
63
-     * @param type   $value_on_field_to_be_outputted
64
-     * @param string $schema , possible values are ',', others can be added
65
-     * @return string
66
-     */
67
-    function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
68
-    {
69
-        switch ($schema) {
70
-            case 'print_r':
71
-                $pretty_value = print_r($value_on_field_to_be_outputted, true);
72
-                break;
73
-            case 'as_table':
74
-                $pretty_value = EEH_Template::layout_array_as_table($value_on_field_to_be_outputted);
75
-                break;
76
-            default:
77
-                $pretty_value = implode(", ", $value_on_field_to_be_outputted);
78
-        }
79
-        return $pretty_value;
80
-    }
60
+	/**
61
+	 * Gets a string representation of the array
62
+	 *
63
+	 * @param type   $value_on_field_to_be_outputted
64
+	 * @param string $schema , possible values are ',', others can be added
65
+	 * @return string
66
+	 */
67
+	function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
68
+	{
69
+		switch ($schema) {
70
+			case 'print_r':
71
+				$pretty_value = print_r($value_on_field_to_be_outputted, true);
72
+				break;
73
+			case 'as_table':
74
+				$pretty_value = EEH_Template::layout_array_as_table($value_on_field_to_be_outputted);
75
+				break;
76
+			default:
77
+				$pretty_value = implode(", ", $value_on_field_to_be_outputted);
78
+		}
79
+		return $pretty_value;
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
20 20
     {
21 21
         parent::__construct($table_column, $nicename, $nullable, $default_value);
22
-        $this->setSchemaType(array('object','string'));
22
+        $this->setSchemaType(array('object', 'string'));
23 23
     }
24 24
 
25 25
 
Please login to merge, or discard this patch.
core/db_models/fields/EE_Enum_Integer_Field.php 2 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -10,115 +10,115 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Enum_Integer_Field extends EE_Integer_Field
12 12
 {
13
-    /**
14
-     * @var array $_allowed_enum_values
15
-     */
16
-    public $_allowed_enum_values;
13
+	/**
14
+	 * @var array $_allowed_enum_values
15
+	 */
16
+	public $_allowed_enum_values;
17 17
 
18 18
 
19
-    /**
20
-     * @param string  $table_column
21
-     * @param string  $nicename
22
-     * @param boolean $nullable
23
-     * @param int     $default_value
24
-     * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
25
-     */
26
-    public function __construct($table_column, $nicename, $nullable, $default_value, $allowed_enum_values)
27
-    {
28
-        $this->_allowed_enum_values = $allowed_enum_values;
29
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
30
-        $this->setSchemaType('object');
31
-    }
19
+	/**
20
+	 * @param string  $table_column
21
+	 * @param string  $nicename
22
+	 * @param boolean $nullable
23
+	 * @param int     $default_value
24
+	 * @param array   $allowed_enum_values keys are values to be used in the DB, values are how they should be displayed
25
+	 */
26
+	public function __construct($table_column, $nicename, $nullable, $default_value, $allowed_enum_values)
27
+	{
28
+		$this->_allowed_enum_values = $allowed_enum_values;
29
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
30
+		$this->setSchemaType('object');
31
+	}
32 32
 
33
-    /**
34
-     * Returns the list of allowed enum options, but filterable.
35
-     * This is used internally
36
-     *
37
-     * @return array
38
-     */
39
-    protected function _allowed_enum_values()
40
-    {
41
-        return (array)apply_filters(
42
-            'FHEE__EE_Enum_Integer_Field___allowed_enum_options',
43
-            $this->_allowed_enum_values,
44
-            $this
45
-        );
46
-    }
33
+	/**
34
+	 * Returns the list of allowed enum options, but filterable.
35
+	 * This is used internally
36
+	 *
37
+	 * @return array
38
+	 */
39
+	protected function _allowed_enum_values()
40
+	{
41
+		return (array)apply_filters(
42
+			'FHEE__EE_Enum_Integer_Field___allowed_enum_options',
43
+			$this->_allowed_enum_values,
44
+			$this
45
+		);
46
+	}
47 47
 
48
-    /**
49
-     * When setting, just verify that the value being used matches what we've defined as allowable enum values.
50
-     * If not, throw an error (but if WP_DEBUG is false, just set the value to default)
51
-     *
52
-     * @param int $value_inputted_for_field_on_model_object
53
-     * @return int
54
-     * @throws EE_Error
55
-     */
56
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
57
-    {
58
-        $allowed_enum_values = $this->_allowed_enum_values();
59
-        if (
60
-            $value_inputted_for_field_on_model_object !== null
61
-            && ! array_key_exists($value_inputted_for_field_on_model_object, $allowed_enum_values)
62
-        ) {
63
-            if (defined('WP_DEBUG') && WP_DEBUG) {
64
-                $msg = sprintf(
65
-                    __('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
66
-                    $value_inputted_for_field_on_model_object,
67
-                    $this->_name
68
-                );
69
-                $msg2 = sprintf(
70
-                    __('Allowed values for "%1$s" are "%2$s". You provided "%3$s"', 'event_espresso'),
71
-                    $this->_name,
72
-                    implode(', ', array_keys($allowed_enum_values)),
73
-                    $value_inputted_for_field_on_model_object
74
-                );
75
-                EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
76
-            }
77
-            return $this->get_default_value();
78
-        }
79
-        return (int)$value_inputted_for_field_on_model_object;
80
-    }
48
+	/**
49
+	 * When setting, just verify that the value being used matches what we've defined as allowable enum values.
50
+	 * If not, throw an error (but if WP_DEBUG is false, just set the value to default)
51
+	 *
52
+	 * @param int $value_inputted_for_field_on_model_object
53
+	 * @return int
54
+	 * @throws EE_Error
55
+	 */
56
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
57
+	{
58
+		$allowed_enum_values = $this->_allowed_enum_values();
59
+		if (
60
+			$value_inputted_for_field_on_model_object !== null
61
+			&& ! array_key_exists($value_inputted_for_field_on_model_object, $allowed_enum_values)
62
+		) {
63
+			if (defined('WP_DEBUG') && WP_DEBUG) {
64
+				$msg = sprintf(
65
+					__('System is assigning incompatible value "%1$s" to field "%2$s"', 'event_espresso'),
66
+					$value_inputted_for_field_on_model_object,
67
+					$this->_name
68
+				);
69
+				$msg2 = sprintf(
70
+					__('Allowed values for "%1$s" are "%2$s". You provided "%3$s"', 'event_espresso'),
71
+					$this->_name,
72
+					implode(', ', array_keys($allowed_enum_values)),
73
+					$value_inputted_for_field_on_model_object
74
+				);
75
+				EE_Error::add_error("{$msg}||{$msg2}", __FILE__, __FUNCTION__, __LINE__);
76
+			}
77
+			return $this->get_default_value();
78
+		}
79
+		return (int)$value_inputted_for_field_on_model_object;
80
+	}
81 81
 
82 82
 
83 83
 
84
-    /**
85
-     * Gets the pretty version of the enum's value.
86
-     *
87
-     * @param int | string $value_on_field_to_be_outputted
88
-     * @param null         $schema
89
-     * @return string
90
-     */
91
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
92
-    {
93
-        $options = $this->_allowed_enum_values();
94
-        if (isset($options[$value_on_field_to_be_outputted])) {
95
-            return $options[$value_on_field_to_be_outputted];
96
-        } else {
97
-            return $value_on_field_to_be_outputted;
98
-        }
99
-    }
84
+	/**
85
+	 * Gets the pretty version of the enum's value.
86
+	 *
87
+	 * @param int | string $value_on_field_to_be_outputted
88
+	 * @param null         $schema
89
+	 * @return string
90
+	 */
91
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null)
92
+	{
93
+		$options = $this->_allowed_enum_values();
94
+		if (isset($options[$value_on_field_to_be_outputted])) {
95
+			return $options[$value_on_field_to_be_outputted];
96
+		} else {
97
+			return $value_on_field_to_be_outputted;
98
+		}
99
+	}
100 100
 
101 101
 
102
-    public function getSchemaProperties()
103
-    {
104
-        return array(
105
-            'raw' => array(
106
-                'description' =>  sprintf(
107
-                    __('%s - the value in the database.', 'event_espresso'),
108
-                    $this->get_nicename()
109
-                ),
110
-                'enum' => array_keys($this->_allowed_enum_values()),
111
-                'type' => 'integer'
112
-            ),
113
-            'pretty' => array(
114
-                'description' =>  sprintf(
115
-                    __('%s - the value for display.', 'event_espresso'),
116
-                    $this->get_nicename()
117
-                ),
118
-                'enum' => array_values($this->_allowed_enum_values()),
119
-                'type' => 'string',
120
-                'read_only' => true
121
-            )
122
-        );
123
-    }
102
+	public function getSchemaProperties()
103
+	{
104
+		return array(
105
+			'raw' => array(
106
+				'description' =>  sprintf(
107
+					__('%s - the value in the database.', 'event_espresso'),
108
+					$this->get_nicename()
109
+				),
110
+				'enum' => array_keys($this->_allowed_enum_values()),
111
+				'type' => 'integer'
112
+			),
113
+			'pretty' => array(
114
+				'description' =>  sprintf(
115
+					__('%s - the value for display.', 'event_espresso'),
116
+					$this->get_nicename()
117
+				),
118
+				'enum' => array_values($this->_allowed_enum_values()),
119
+				'type' => 'string',
120
+				'read_only' => true
121
+			)
122
+		);
123
+	}
124 124
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     protected function _allowed_enum_values()
40 40
     {
41
-        return (array)apply_filters(
41
+        return (array) apply_filters(
42 42
             'FHEE__EE_Enum_Integer_Field___allowed_enum_options',
43 43
             $this->_allowed_enum_values,
44 44
             $this
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
             }
77 77
             return $this->get_default_value();
78 78
         }
79
-        return (int)$value_inputted_for_field_on_model_object;
79
+        return (int) $value_inputted_for_field_on_model_object;
80 80
     }
81 81
 
82 82
 
Please login to merge, or discard this patch.
core/db_models/fields/EE_Boolean_Field.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -3,50 +3,50 @@
 block discarded – undo
3 3
 
4 4
 class EE_Boolean_Field extends EE_Integer_Field
5 5
 {
6
-    /**
7
-     * @param string $table_column
8
-     * @param string $nicename
9
-     * @param bool   $nullable
10
-     * @param null   $default_value
11
-     */
12
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
13
-    {
14
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
15
-        $this->setSchemaType('boolean');
16
-    }
6
+	/**
7
+	 * @param string $table_column
8
+	 * @param string $nicename
9
+	 * @param bool   $nullable
10
+	 * @param null   $default_value
11
+	 */
12
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
13
+	{
14
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
15
+		$this->setSchemaType('boolean');
16
+	}
17 17
 
18
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
19
-    {
20
-        if ($value_inputted_for_field_on_model_object) {
21
-            return true;
22
-        } else {
23
-            return false;
24
-        }
25
-    }
18
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
19
+	{
20
+		if ($value_inputted_for_field_on_model_object) {
21
+			return true;
22
+		} else {
23
+			return false;
24
+		}
25
+	}
26 26
 
27
-    /**
28
-     * Make sure we're returning booleans
29
-     *
30
-     * @param string $value_inputted_for_field_on_model_object
31
-     * @return boolean
32
-     */
33
-    public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
34
-    {
35
-        return intval($value_inputted_for_field_on_model_object) ? true : false;
36
-    }
27
+	/**
28
+	 * Make sure we're returning booleans
29
+	 *
30
+	 * @param string $value_inputted_for_field_on_model_object
31
+	 * @return boolean
32
+	 */
33
+	public function prepare_for_set_from_db($value_inputted_for_field_on_model_object)
34
+	{
35
+		return intval($value_inputted_for_field_on_model_object) ? true : false;
36
+	}
37 37
 
38
-    /**
39
-     * Gets a nice Yes/No value for this field
40
-     *
41
-     * @param boolean $value_on_field_to_be_outputted
42
-     * @return string Yes or No
43
-     */
44
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
45
-    {
46
-        return apply_filters(
47
-            'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return',
48
-            $value_on_field_to_be_outputted ? __('Yes', 'event_espresso') : __('No', 'event_espresso'),
49
-            $value_on_field_to_be_outputted
50
-        );
51
-    }
38
+	/**
39
+	 * Gets a nice Yes/No value for this field
40
+	 *
41
+	 * @param boolean $value_on_field_to_be_outputted
42
+	 * @return string Yes or No
43
+	 */
44
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
45
+	{
46
+		return apply_filters(
47
+			'FHEE__EE_Boolean_Field__prepare_for_pretty_echoing__return',
48
+			$value_on_field_to_be_outputted ? __('Yes', 'event_espresso') : __('No', 'event_espresso'),
49
+			$value_on_field_to_be_outputted
50
+		);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@
 block discarded – undo
1 1
 <?php
2
-defined( 'EVENT_ESPRESSO_VERSION') || exit;
2
+defined('EVENT_ESPRESSO_VERSION') || exit;
3 3
 
4 4
 class EE_Boolean_Field extends EE_Integer_Field
5 5
 {
Please login to merge, or discard this patch.
core/db_models/fields/EE_Post_Content_Field.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -8,56 +8,56 @@
 block discarded – undo
8 8
 class EE_Post_Content_Field extends EE_Text_Field_Base
9 9
 {
10 10
 
11
-    /**
12
-     * @param string $table_column
13
-     * @param string $nicename
14
-     * @param bool   $nullable
15
-     * @param null   $default_value
16
-     */
17
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
-    {
19
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
20
-        $this->setSchemaType('object');
21
-    }
11
+	/**
12
+	 * @param string $table_column
13
+	 * @param string $nicename
14
+	 * @param bool   $nullable
15
+	 * @param null   $default_value
16
+	 */
17
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
18
+	{
19
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
20
+		$this->setSchemaType('object');
21
+	}
22 22
 
23 23
 
24
-    /**
25
-     * removes all tags which a WP Post wouldn't allow in its content normally
26
-     *
27
-     * @param string $value
28
-     * @return string
29
-     */
30
-    function prepare_for_set($value)
31
-    {
32
-        if (! current_user_can('unfiltered_html')) {
33
-            $value = wp_kses("$value", wp_kses_allowed_html('post'));
34
-        }
35
-        return parent::prepare_for_set($value);
36
-    }
24
+	/**
25
+	 * removes all tags which a WP Post wouldn't allow in its content normally
26
+	 *
27
+	 * @param string $value
28
+	 * @return string
29
+	 */
30
+	function prepare_for_set($value)
31
+	{
32
+		if (! current_user_can('unfiltered_html')) {
33
+			$value = wp_kses("$value", wp_kses_allowed_html('post'));
34
+		}
35
+		return parent::prepare_for_set($value);
36
+	}
37 37
 
38
-    function prepare_for_set_from_db($value_found_in_db_for_model_object)
39
-    {
40
-        return $value_found_in_db_for_model_object;
41
-    }
38
+	function prepare_for_set_from_db($value_found_in_db_for_model_object)
39
+	{
40
+		return $value_found_in_db_for_model_object;
41
+	}
42 42
 
43 43
 
44
-    public function getSchemaProperties()
45
-    {
46
-        return array(
47
-            'raw' => array(
48
-                'description' =>  sprintf(
49
-                    __('%s - the content as it exists in the database.', 'event_espresso'),
50
-                    $this->get_nicename()
51
-                ),
52
-                'type' => 'string'
53
-            ),
54
-            'rendered' => array(
55
-                'description' =>  sprintf(
56
-                    __('%s - the content rendered for display.', 'event_espresso'),
57
-                    $this->get_nicename()
58
-                ),
59
-                'type' => 'string'
60
-            )
61
-        );
62
-    }
44
+	public function getSchemaProperties()
45
+	{
46
+		return array(
47
+			'raw' => array(
48
+				'description' =>  sprintf(
49
+					__('%s - the content as it exists in the database.', 'event_espresso'),
50
+					$this->get_nicename()
51
+				),
52
+				'type' => 'string'
53
+			),
54
+			'rendered' => array(
55
+				'description' =>  sprintf(
56
+					__('%s - the content rendered for display.', 'event_espresso'),
57
+					$this->get_nicename()
58
+				),
59
+				'type' => 'string'
60
+			)
61
+		);
62
+	}
63 63
 }
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
core/db_models/fields/EE_Datetime_Field.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -210,8 +210,8 @@  discard block
 block discarded – undo
210 210
 
211 211
             default :
212 212
                 return $pretty
213
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
214
-                    : $this->_date_format . ' ' . $this->_time_format;
213
+                    ? $this->_pretty_date_format.' '.$this->_pretty_time_format
214
+                    : $this->_date_format.' '.$this->_time_format;
215 215
         }
216 216
     }
217 217
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
      */
468 468
     protected function _prepare_for_display($DateTime, $schema = false)
469 469
     {
470
-        if (! $DateTime instanceof DateTime) {
470
+        if ( ! $DateTime instanceof DateTime) {
471 471
             if ($this->_nullable) {
472 472
                 return '';
473 473
             } else {
@@ -502,15 +502,15 @@  discard block
 block discarded – undo
502 502
             if ($this->_display_timezone()) {
503 503
                 //must be explicit because schema could equal true.
504 504
                 if ($schema === 'no_html') {
505
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
505
+                    $timezone_string = ' ('.$DateTime->format('T').')';
506 506
                 } else {
507
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
507
+                    $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>';
508 508
                 }
509 509
             } else {
510 510
                 $timezone_string = '';
511 511
             }
512 512
 
513
-            return $DateTime->format($format_string) . $timezone_string;
513
+            return $DateTime->format($format_string).$timezone_string;
514 514
         } else {
515 515
             return $DateTime->format($format_string);
516 516
         }
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
     public function prepare_for_use_in_db($datetime_value)
529 529
     {
530 530
         //we allow an empty value or DateTime object, but nothing else.
531
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
531
+        if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
532 532
             throw new EE_Error(
533 533
                 __(
534 534
                     'The incoming value being prepared for setting in the database must either be empty or a php DateTime object',
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
             }
584 584
         }
585 585
 
586
-        if (! $DateTime instanceof DbSafeDateTime) {
586
+        if ( ! $DateTime instanceof DbSafeDateTime) {
587 587
             // if still no datetime object, then let's just use now
588 588
             $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
589 589
         }
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
         }
663 663
         //not a unix timestamp.  So we will use the set format on this object and set timezone to
664 664
         //create the DateTime object.
665
-        $format = $this->_date_format . ' ' . $this->_time_format;
665
+        $format = $this->_date_format.' '.$this->_time_format;
666 666
         try {
667 667
             $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
668 668
             if ($DateTime instanceof DateTime) {
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
                     $this->_DateTimeZone
672 672
                 );
673 673
             }
674
-            if (! $DateTime instanceof DbSafeDateTime) {
674
+            if ( ! $DateTime instanceof DbSafeDateTime) {
675 675
                 throw new EE_Error(
676 676
                     sprintf(
677 677
                         __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
Please login to merge, or discard this patch.
Indentation   +749 added lines, -749 removed lines patch added patch discarded remove patch
@@ -15,753 +15,753 @@
 block discarded – undo
15 15
 class EE_Datetime_Field extends EE_Model_Field_Base
16 16
 {
17 17
 
18
-    /**
19
-     * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
-     * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
-     *
22
-     * @type string unix_timestamp_regex
23
-     */
24
-    const unix_timestamp_regex = '/[0-9]{10,}/';
25
-
26
-    /**
27
-     * @type string mysql_timestamp_format
28
-     */
29
-    const mysql_timestamp_format = 'Y-m-d H:i:s';
30
-
31
-    /**
32
-     * @type string mysql_date_format
33
-     */
34
-    const mysql_date_format = 'Y-m-d';
35
-
36
-    /**
37
-     * @type string mysql_time_format
38
-     */
39
-    const mysql_time_format = 'H:i:s';
40
-
41
-    /**
42
-     * Const for using in the default value. If the field's default is set to this,
43
-     * then we will return the time of calling `get_default_value()`, not
44
-     * just the current time at construction
45
-     */
46
-    const now = 'now';
47
-
48
-    /**
49
-     * The following properties hold the default formats for date and time.
50
-     * Defaults are set via the constructor and can be overridden on class instantiation.
51
-     * However they can also be overridden later by the set_format() method
52
-     * (and corresponding set_date_format, set_time_format methods);
53
-     */
54
-    /**
55
-     * @type string $_date_format
56
-     */
57
-    protected $_date_format = '';
58
-
59
-    /**
60
-     * @type string $_time_format
61
-     */
62
-    protected $_time_format = '';
63
-
64
-    /**
65
-     * @type string $_pretty_date_format
66
-     */
67
-    protected $_pretty_date_format = '';
68
-
69
-    /**
70
-     * @type string $_pretty_time_format
71
-     */
72
-    protected $_pretty_time_format = '';
73
-
74
-    /**
75
-     * @type DateTimeZone $_DateTimeZone
76
-     */
77
-    protected $_DateTimeZone;
78
-
79
-    /**
80
-     * @type DateTimeZone $_UTC_DateTimeZone
81
-     */
82
-    protected $_UTC_DateTimeZone;
83
-
84
-    /**
85
-     * @type DateTimeZone $_blog_DateTimeZone
86
-     */
87
-    protected $_blog_DateTimeZone;
88
-
89
-
90
-    /**
91
-     * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
-     * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
-     * and time returned via getters.
94
-     *
95
-     * @var mixed (null|string)
96
-     */
97
-    protected $_date_time_output;
98
-
99
-
100
-    /**
101
-     * timezone string
102
-     * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
-     * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
-     * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
-     *
106
-     * @var string
107
-     */
108
-    protected $_timezone_string;
109
-
110
-
111
-    /**
112
-     * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
-     * offsets for comparison purposes).
114
-     *
115
-     * @var int
116
-     */
117
-    protected $_blog_offset;
118
-
119
-
120
-    /**
121
-     * @param string $table_column
122
-     * @param string $nice_name
123
-     * @param bool   $nullable
124
-     * @param string $default_value
125
-     * @param string $timezone_string
126
-     * @param string $date_format
127
-     * @param string $time_format
128
-     * @param string $pretty_date_format
129
-     * @param string $pretty_time_format
130
-     * @throws \EE_Error
131
-     */
132
-    public function __construct(
133
-        $table_column,
134
-        $nice_name,
135
-        $nullable,
136
-        $default_value,
137
-        $timezone_string = '',
138
-        $date_format = '',
139
-        $time_format = '',
140
-        $pretty_date_format = '',
141
-        $pretty_time_format = ''
142
-    ) {
143
-
144
-        $this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
145
-        $this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
146
-        $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
147
-        $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
148
-
149
-        parent::__construct($table_column, $nice_name, $nullable, $default_value);
150
-        $this->set_timezone($timezone_string);
151
-        $this->setSchemaFormat('date-time');
152
-    }
153
-
154
-
155
-    /**
156
-     * @return DateTimeZone
157
-     * @throws \EE_Error
158
-     */
159
-    public function get_UTC_DateTimeZone()
160
-    {
161
-        return $this->_UTC_DateTimeZone instanceof DateTimeZone
162
-            ? $this->_UTC_DateTimeZone
163
-            : $this->_create_timezone_object_from_timezone_string('UTC');
164
-    }
165
-
166
-
167
-    /**
168
-     * @return DateTimeZone
169
-     * @throws \EE_Error
170
-     */
171
-    public function get_blog_DateTimeZone()
172
-    {
173
-        return $this->_blog_DateTimeZone instanceof DateTimeZone
174
-            ? $this->_blog_DateTimeZone
175
-            : $this->_create_timezone_object_from_timezone_string('');
176
-    }
177
-
178
-
179
-    /**
180
-     * this prepares any incoming date data and make sure its converted to a utc unix timestamp
181
-     *
182
-     * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
183
-     *                                                              timestamp
184
-     * @return DateTime
185
-     */
186
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
187
-    {
188
-        return $this->_get_date_object($value_inputted_for_field_on_model_object);
189
-    }
190
-
191
-
192
-    /**
193
-     * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
194
-     * getters need to know whether we're just returning the date or the time or both.  By default we return both.
195
-     *
196
-     * @param bool $pretty If we're returning the pretty formats or standard format string.
197
-     * @return string    The final assembled format string.
198
-     */
199
-    protected function _get_date_time_output($pretty = false)
200
-    {
201
-
202
-        switch ($this->_date_time_output) {
203
-            case 'time' :
204
-                return $pretty ? $this->_pretty_time_format : $this->_time_format;
205
-                break;
206
-
207
-            case 'date' :
208
-                return $pretty ? $this->_pretty_date_format : $this->_date_format;
209
-                break;
210
-
211
-            default :
212
-                return $pretty
213
-                    ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
214
-                    : $this->_date_format . ' ' . $this->_time_format;
215
-        }
216
-    }
217
-
218
-
219
-    /**
220
-     * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
221
-     * returned (using the format properties)
222
-     *
223
-     * @param string $what acceptable values are 'time' or 'date'.
224
-     *                     Any other value will be set but will always result
225
-     *                     in both 'date' and 'time' being returned.
226
-     * @return void
227
-     */
228
-    public function set_date_time_output($what = null)
229
-    {
230
-        $this->_date_time_output = $what;
231
-    }
232
-
233
-
234
-    /**
235
-     * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
236
-     * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
237
-     * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
238
-     * We also set some other properties in this method.
239
-     *
240
-     * @param string $timezone_string A valid timezone string as described by @link
241
-     *                                http://www.php.net/manual/en/timezones.php
242
-     * @return void
243
-     * @throws \EE_Error
244
-     */
245
-    public function set_timezone($timezone_string)
246
-    {
247
-        if (empty($timezone_string) && $this->_timezone_string !== null) {
248
-            // leave the timezone AS-IS if we already have one and
249
-            // the function arg didn't provide one
250
-            return;
251
-        }
252
-        $timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
253
-        $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
254
-        $this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
255
-    }
256
-
257
-
258
-    /**
259
-     * _create_timezone_object_from_timezone_name
260
-     *
261
-     * @access protected
262
-     * @param string $timezone_string
263
-     * @return \DateTimeZone
264
-     * @throws \EE_Error
265
-     */
266
-    protected function _create_timezone_object_from_timezone_string($timezone_string = '')
267
-    {
268
-        return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
269
-    }
270
-
271
-
272
-    /**
273
-     * This just returns whatever is set for the current timezone.
274
-     *
275
-     * @access public
276
-     * @return string timezone string
277
-     */
278
-    public function get_timezone()
279
-    {
280
-        return $this->_timezone_string;
281
-    }
282
-
283
-
284
-    /**
285
-     * set the $_date_format property
286
-     *
287
-     * @access public
288
-     * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
289
-     * @param bool   $pretty Whether to set pretty format or not.
290
-     * @return void
291
-     */
292
-    public function set_date_format($format, $pretty = false)
293
-    {
294
-        if ($pretty) {
295
-            $this->_pretty_date_format = $format;
296
-        } else {
297
-            $this->_date_format = $format;
298
-        }
299
-    }
300
-
301
-
302
-    /**
303
-     * return the $_date_format property value.
304
-     *
305
-     * @param bool $pretty Whether to get pretty format or not.
306
-     * @return string
307
-     */
308
-    public function get_date_format($pretty = false)
309
-    {
310
-        return $pretty ? $this->_pretty_date_format : $this->_date_format;
311
-    }
312
-
313
-
314
-    /**
315
-     * set the $_time_format property
316
-     *
317
-     * @access public
318
-     * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
319
-     * @param bool   $pretty Whether to set pretty format or not.
320
-     * @return void
321
-     */
322
-    public function set_time_format($format, $pretty = false)
323
-    {
324
-        if ($pretty) {
325
-            $this->_pretty_time_format = $format;
326
-        } else {
327
-            $this->_time_format = $format;
328
-        }
329
-    }
330
-
331
-
332
-    /**
333
-     * return the $_time_format property value.
334
-     *
335
-     * @param bool $pretty Whether to get pretty format or not.
336
-     * @return string
337
-     */
338
-    public function get_time_format($pretty = false)
339
-    {
340
-        return $pretty ? $this->_pretty_time_format : $this->_time_format;
341
-    }
342
-
343
-
344
-    /**
345
-     * set the $_pretty_date_format property
346
-     *
347
-     * @access public
348
-     * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
349
-     * @return void
350
-     */
351
-    public function set_pretty_date_format($format)
352
-    {
353
-        $this->_pretty_date_format = $format;
354
-    }
355
-
356
-
357
-    /**
358
-     * set the $_pretty_time_format property
359
-     *
360
-     * @access public
361
-     * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
362
-     * @return void
363
-     */
364
-    public function set_pretty_time_format($format)
365
-    {
366
-        $this->_pretty_time_format = $format;
367
-    }
368
-
369
-
370
-    /**
371
-     * Only sets the time portion of the datetime.
372
-     *
373
-     * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
374
-     * @param DateTime        $current            current DateTime object for the datetime field
375
-     * @return DateTime
376
-     */
377
-    public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
378
-    {
379
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
380
-        // Otherwise parse the string.
381
-        if ($time_to_set_string instanceof DateTime) {
382
-            $parsed = array(
383
-                'hour'   => $time_to_set_string->format('H'),
384
-                'minute' => $time_to_set_string->format('i'),
385
-                'second' => $time_to_set_string->format('s'),
386
-            );
387
-        } else {
388
-            //parse incoming string
389
-            $parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
390
-        }
391
-
392
-        //make sure $current is in the correct timezone.
393
-        $current->setTimezone($this->_DateTimeZone);
394
-
395
-        return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
396
-    }
397
-
398
-
399
-    /**
400
-     * Only sets the date portion of the datetime.
401
-     *
402
-     * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
403
-     * @param DateTime        $current            current DateTime object for the datetime field
404
-     * @return DateTime
405
-     */
406
-    public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
407
-    {
408
-        // if $time_to_set_string is datetime object, then let's use it to set the parse array.
409
-        // Otherwise parse the string.
410
-        if ($date_to_set_string instanceof DateTime) {
411
-            $parsed = array(
412
-                'year'  => $date_to_set_string->format('Y'),
413
-                'month' => $date_to_set_string->format('m'),
414
-                'day'   => $date_to_set_string->format('d'),
415
-            );
416
-        } else {
417
-            //parse incoming string
418
-            $parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
419
-        }
420
-
421
-        //make sure $current is in the correct timezone
422
-        $current->setTimezone($this->_DateTimeZone);
423
-
424
-        return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
425
-    }
426
-
427
-
428
-    /**
429
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
430
-     * datetime gets to this stage it should ALREADY be in UTC time
431
-     *
432
-     * @param  DateTime $DateTime
433
-     * @return string formatted date time for given timezone
434
-     * @throws \EE_Error
435
-     */
436
-    public function prepare_for_get($DateTime)
437
-    {
438
-        return $this->_prepare_for_display($DateTime);
439
-    }
440
-
441
-
442
-    /**
443
-     * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
444
-     * from the set wp timezone.  If so, then it returns the datetime string formatted via
445
-     * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
446
-     * abbreviation to the date_string.
447
-     *
448
-     * @param mixed $DateTime
449
-     * @param null  $schema
450
-     * @return string
451
-     * @throws \EE_Error
452
-     */
453
-    public function prepare_for_pretty_echoing($DateTime, $schema = null)
454
-    {
455
-        return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
456
-    }
457
-
458
-
459
-    /**
460
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
461
-     * timezone).
462
-     *
463
-     * @param DateTime    $DateTime
464
-     * @param bool|string $schema
465
-     * @return string
466
-     * @throws \EE_Error
467
-     */
468
-    protected function _prepare_for_display($DateTime, $schema = false)
469
-    {
470
-        if (! $DateTime instanceof DateTime) {
471
-            if ($this->_nullable) {
472
-                return '';
473
-            } else {
474
-                if (WP_DEBUG) {
475
-                    throw new EE_Error(
476
-                        sprintf(
477
-                            __(
478
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
479
-                                'event_espresso'
480
-                            ),
481
-                            $this->_nicename
482
-                        )
483
-                    );
484
-                } else {
485
-                    $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
486
-                    EE_Error::add_error(
487
-                        sprintf(
488
-                            __(
489
-                                'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
490
-                                'event_espresso'
491
-                            ),
492
-                            $this->_nicename
493
-                        )
494
-                    );
495
-                }
496
-            }
497
-        }
498
-        $format_string = $this->_get_date_time_output($schema);
499
-        //make sure datetime_value is in the correct timezone (in case that's been updated).
500
-        $DateTime->setTimezone($this->_DateTimeZone);
501
-        if ($schema) {
502
-            if ($this->_display_timezone()) {
503
-                //must be explicit because schema could equal true.
504
-                if ($schema === 'no_html') {
505
-                    $timezone_string = ' (' . $DateTime->format('T') . ')';
506
-                } else {
507
-                    $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
508
-                }
509
-            } else {
510
-                $timezone_string = '';
511
-            }
512
-
513
-            return $DateTime->format($format_string) . $timezone_string;
514
-        } else {
515
-            return $DateTime->format($format_string);
516
-        }
517
-    }
518
-
519
-
520
-    /**
521
-     * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
522
-     * timezone).
523
-     *
524
-     * @param  mixed $datetime_value u
525
-     * @return string mysql timestamp in UTC
526
-     * @throws \EE_Error
527
-     */
528
-    public function prepare_for_use_in_db($datetime_value)
529
-    {
530
-        //we allow an empty value or DateTime object, but nothing else.
531
-        if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
532
-            throw new EE_Error(
533
-                __(
534
-                    'The incoming value being prepared for setting in the database must either be empty or a php DateTime object',
535
-                    'event_espresso'
536
-                )
537
-            );
538
-        }
539
-
540
-        if ($datetime_value instanceof DateTime) {
541
-            if ( ! $datetime_value instanceof DbSafeDateTime) {
542
-                $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
543
-            }
544
-
545
-            return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
546
-                EE_Datetime_Field::mysql_timestamp_format
547
-            );
548
-        }
549
-
550
-        // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
551
-        return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
552
-    }
553
-
554
-
555
-    /**
556
-     * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
557
-     * allowed)
558
-     *
559
-     * @param string $datetime_string mysql timestamp in UTC
560
-     * @return  mixed null | DateTime
561
-     * @throws \EE_Error
562
-     */
563
-    public function prepare_for_set_from_db($datetime_string)
564
-    {
565
-        //if $datetime_value is empty, and ! $this->_nullable, just use time()
566
-        if (empty($datetime_string) && $this->_nullable) {
567
-            return null;
568
-        }
569
-        // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
570
-        if (empty($datetime_string)) {
571
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
572
-        } else {
573
-            $DateTime = DateTime::createFromFormat(
574
-                EE_Datetime_Field::mysql_timestamp_format,
575
-                $datetime_string,
576
-                $this->get_UTC_DateTimeZone()
577
-            );
578
-            if ($DateTime instanceof \DateTime) {
579
-                $DateTime = new DbSafeDateTime(
580
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
581
-                    $this->get_UTC_DateTimeZone()
582
-                );
583
-            }
584
-        }
585
-
586
-        if (! $DateTime instanceof DbSafeDateTime) {
587
-            // if still no datetime object, then let's just use now
588
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
589
-        }
590
-        // THEN apply the field's set DateTimeZone
591
-        $DateTime->setTimezone($this->_DateTimeZone);
592
-
593
-        return $DateTime;
594
-    }
595
-
596
-
597
-    /**
598
-     * All this method does is determine if we're going to display the timezone string or not on any output.
599
-     * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
600
-     * If so, then true.
601
-     *
602
-     * @return bool true for yes false for no
603
-     * @throws \EE_Error
604
-     */
605
-    protected function _display_timezone()
606
-    {
607
-
608
-        // first let's do a comparison of timezone strings.
609
-        // If they match then we can get out without any further calculations
610
-        $blog_string = get_option('timezone_string');
611
-        if ($blog_string === $this->_timezone_string) {
612
-            return false;
613
-        }
614
-        // now we need to calc the offset for the timezone string so we can compare with the blog offset.
615
-        $this_offset = $this->get_timezone_offset($this->_DateTimeZone);
616
-        $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
617
-        // now compare
618
-        return $blog_offset !== $this_offset;
619
-    }
620
-
621
-
622
-    /**
623
-     * This method returns a php DateTime object for setting on the EE_Base_Class model.
624
-     * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
625
-     * with.
626
-     *
627
-     * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
628
-     *                                                    in the format that is set on the date_field (or DateTime
629
-     *                                                    object)!
630
-     * @return DateTime
631
-     */
632
-    protected function _get_date_object($date_string)
633
-    {
634
-        //first if this is an empty date_string and nullable is allowed, just return null.
635
-        if ($this->_nullable && empty($date_string)) {
636
-            return null;
637
-        }
638
-
639
-        // if incoming date
640
-        if ($date_string instanceof DateTime) {
641
-            $date_string->setTimezone($this->_DateTimeZone);
642
-
643
-            return $date_string;
644
-        }
645
-        // if empty date_string and made it here.
646
-        // Return a datetime object for now in the given timezone.
647
-        if (empty($date_string)) {
648
-            return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
649
-        }
650
-        // if $date_string is matches something that looks like a Unix timestamp let's just use it.
651
-        if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
652
-            try {
653
-                // This is operating under the assumption that the incoming Unix timestamp
654
-                // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
655
-                $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
-                $DateTime->setTimestamp($date_string);
657
-
658
-                return $DateTime;
659
-            } catch (Exception $e) {
660
-                // should be rare, but if things got fooled then let's just continue
661
-            }
662
-        }
663
-        //not a unix timestamp.  So we will use the set format on this object and set timezone to
664
-        //create the DateTime object.
665
-        $format = $this->_date_format . ' ' . $this->_time_format;
666
-        try {
667
-            $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
668
-            if ($DateTime instanceof DateTime) {
669
-                $DateTime = new DbSafeDateTime(
670
-                    $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
671
-                    $this->_DateTimeZone
672
-                );
673
-            }
674
-            if (! $DateTime instanceof DbSafeDateTime) {
675
-                throw new EE_Error(
676
-                    sprintf(
677
-                        __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
678
-                        $date_string,
679
-                        $format
680
-                    )
681
-                );
682
-            }
683
-        } catch (Exception $e) {
684
-            // if we made it here then likely then something went really wrong.
685
-            // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
686
-            $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
687
-        }
688
-
689
-        return $DateTime;
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     * get_timezone_transitions
696
-     *
697
-     * @param \DateTimeZone $DateTimeZone
698
-     * @param int           $time
699
-     * @param bool          $first_only
700
-     * @return mixed
701
-     */
702
-    public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
703
-    {
704
-        $time = is_int($time) || $time === null ? $time : strtotime($time);
705
-        $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
706
-        $transitions = $DateTimeZone->getTransitions($time);
707
-        return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
708
-    }
709
-
710
-
711
-
712
-    /**
713
-     * get_timezone_offset
714
-     *
715
-     * @param \DateTimeZone $DateTimeZone
716
-     * @param int           $time
717
-     * @return mixed
718
-     * @throws \DomainException
719
-     */
720
-    public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
721
-    {
722
-        $transitions = $this->get_timezone_transitions($DateTimeZone, $time);
723
-        if ( ! isset($transitions['offset'])) {
724
-            throw new DomainException();
725
-        }
726
-        return $transitions['offset'];
727
-    }
728
-
729
-
730
-    /**
731
-     * This will take an incoming timezone string and return the abbreviation for that timezone
732
-     *
733
-     * @param  string $timezone_string
734
-     * @return string           abbreviation
735
-     * @throws \EE_Error
736
-     */
737
-    public function get_timezone_abbrev($timezone_string)
738
-    {
739
-        $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
740
-        $dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
741
-
742
-        return $dateTime->format('T');
743
-    }
744
-
745
-    /**
746
-     * Overrides the parent to allow for having a dynamic "now" value
747
-     *
748
-     * @return mixed
749
-     */
750
-    public function get_default_value()
751
-    {
752
-        if ($this->_default_value === EE_Datetime_Field::now) {
753
-            return time();
754
-        } else {
755
-            return parent::get_default_value();
756
-        }
757
-    }
758
-
759
-
760
-    public function getSchemaDescription()
761
-    {
762
-        return sprintf(
763
-            esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
764
-            $this->get_nicename()
765
-        );
766
-    }
18
+	/**
19
+	 * The pattern we're looking for is if only the characters 0-9 are found and there are only
20
+	 * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 )
21
+	 *
22
+	 * @type string unix_timestamp_regex
23
+	 */
24
+	const unix_timestamp_regex = '/[0-9]{10,}/';
25
+
26
+	/**
27
+	 * @type string mysql_timestamp_format
28
+	 */
29
+	const mysql_timestamp_format = 'Y-m-d H:i:s';
30
+
31
+	/**
32
+	 * @type string mysql_date_format
33
+	 */
34
+	const mysql_date_format = 'Y-m-d';
35
+
36
+	/**
37
+	 * @type string mysql_time_format
38
+	 */
39
+	const mysql_time_format = 'H:i:s';
40
+
41
+	/**
42
+	 * Const for using in the default value. If the field's default is set to this,
43
+	 * then we will return the time of calling `get_default_value()`, not
44
+	 * just the current time at construction
45
+	 */
46
+	const now = 'now';
47
+
48
+	/**
49
+	 * The following properties hold the default formats for date and time.
50
+	 * Defaults are set via the constructor and can be overridden on class instantiation.
51
+	 * However they can also be overridden later by the set_format() method
52
+	 * (and corresponding set_date_format, set_time_format methods);
53
+	 */
54
+	/**
55
+	 * @type string $_date_format
56
+	 */
57
+	protected $_date_format = '';
58
+
59
+	/**
60
+	 * @type string $_time_format
61
+	 */
62
+	protected $_time_format = '';
63
+
64
+	/**
65
+	 * @type string $_pretty_date_format
66
+	 */
67
+	protected $_pretty_date_format = '';
68
+
69
+	/**
70
+	 * @type string $_pretty_time_format
71
+	 */
72
+	protected $_pretty_time_format = '';
73
+
74
+	/**
75
+	 * @type DateTimeZone $_DateTimeZone
76
+	 */
77
+	protected $_DateTimeZone;
78
+
79
+	/**
80
+	 * @type DateTimeZone $_UTC_DateTimeZone
81
+	 */
82
+	protected $_UTC_DateTimeZone;
83
+
84
+	/**
85
+	 * @type DateTimeZone $_blog_DateTimeZone
86
+	 */
87
+	protected $_blog_DateTimeZone;
88
+
89
+
90
+	/**
91
+	 * This property holds how we want the output returned when getting a datetime string.  It is set for the
92
+	 * set_date_time_output() method.  By default this is empty.  When empty, we are assuming that we want both date
93
+	 * and time returned via getters.
94
+	 *
95
+	 * @var mixed (null|string)
96
+	 */
97
+	protected $_date_time_output;
98
+
99
+
100
+	/**
101
+	 * timezone string
102
+	 * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone
103
+	 * incoming strings|timestamps are in.  This can also be used before a get to set what timezone you want strings
104
+	 * coming out of the object to be in.  Default timezone is the current WP timezone option setting
105
+	 *
106
+	 * @var string
107
+	 */
108
+	protected $_timezone_string;
109
+
110
+
111
+	/**
112
+	 * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related
113
+	 * offsets for comparison purposes).
114
+	 *
115
+	 * @var int
116
+	 */
117
+	protected $_blog_offset;
118
+
119
+
120
+	/**
121
+	 * @param string $table_column
122
+	 * @param string $nice_name
123
+	 * @param bool   $nullable
124
+	 * @param string $default_value
125
+	 * @param string $timezone_string
126
+	 * @param string $date_format
127
+	 * @param string $time_format
128
+	 * @param string $pretty_date_format
129
+	 * @param string $pretty_time_format
130
+	 * @throws \EE_Error
131
+	 */
132
+	public function __construct(
133
+		$table_column,
134
+		$nice_name,
135
+		$nullable,
136
+		$default_value,
137
+		$timezone_string = '',
138
+		$date_format = '',
139
+		$time_format = '',
140
+		$pretty_date_format = '',
141
+		$pretty_time_format = ''
142
+	) {
143
+
144
+		$this->_date_format        = ! empty($date_format) ? $date_format : get_option('date_format');
145
+		$this->_time_format        = ! empty($time_format) ? $time_format : get_option('time_format');
146
+		$this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format');
147
+		$this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format');
148
+
149
+		parent::__construct($table_column, $nice_name, $nullable, $default_value);
150
+		$this->set_timezone($timezone_string);
151
+		$this->setSchemaFormat('date-time');
152
+	}
153
+
154
+
155
+	/**
156
+	 * @return DateTimeZone
157
+	 * @throws \EE_Error
158
+	 */
159
+	public function get_UTC_DateTimeZone()
160
+	{
161
+		return $this->_UTC_DateTimeZone instanceof DateTimeZone
162
+			? $this->_UTC_DateTimeZone
163
+			: $this->_create_timezone_object_from_timezone_string('UTC');
164
+	}
165
+
166
+
167
+	/**
168
+	 * @return DateTimeZone
169
+	 * @throws \EE_Error
170
+	 */
171
+	public function get_blog_DateTimeZone()
172
+	{
173
+		return $this->_blog_DateTimeZone instanceof DateTimeZone
174
+			? $this->_blog_DateTimeZone
175
+			: $this->_create_timezone_object_from_timezone_string('');
176
+	}
177
+
178
+
179
+	/**
180
+	 * this prepares any incoming date data and make sure its converted to a utc unix timestamp
181
+	 *
182
+	 * @param  string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix
183
+	 *                                                              timestamp
184
+	 * @return DateTime
185
+	 */
186
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
187
+	{
188
+		return $this->_get_date_object($value_inputted_for_field_on_model_object);
189
+	}
190
+
191
+
192
+	/**
193
+	 * This returns the format string to be used by getters depending on what the $_date_time_output property is set at.
194
+	 * getters need to know whether we're just returning the date or the time or both.  By default we return both.
195
+	 *
196
+	 * @param bool $pretty If we're returning the pretty formats or standard format string.
197
+	 * @return string    The final assembled format string.
198
+	 */
199
+	protected function _get_date_time_output($pretty = false)
200
+	{
201
+
202
+		switch ($this->_date_time_output) {
203
+			case 'time' :
204
+				return $pretty ? $this->_pretty_time_format : $this->_time_format;
205
+				break;
206
+
207
+			case 'date' :
208
+				return $pretty ? $this->_pretty_date_format : $this->_date_format;
209
+				break;
210
+
211
+			default :
212
+				return $pretty
213
+					? $this->_pretty_date_format . ' ' . $this->_pretty_time_format
214
+					: $this->_date_format . ' ' . $this->_time_format;
215
+		}
216
+	}
217
+
218
+
219
+	/**
220
+	 * This just sets the $_date_time_output property so we can flag how date and times are formatted before being
221
+	 * returned (using the format properties)
222
+	 *
223
+	 * @param string $what acceptable values are 'time' or 'date'.
224
+	 *                     Any other value will be set but will always result
225
+	 *                     in both 'date' and 'time' being returned.
226
+	 * @return void
227
+	 */
228
+	public function set_date_time_output($what = null)
229
+	{
230
+		$this->_date_time_output = $what;
231
+	}
232
+
233
+
234
+	/**
235
+	 * See $_timezone property for description of what the timezone property is for.  This SETS the timezone internally
236
+	 * for being able to reference what timezone we are running conversions on when converting TO the internal timezone
237
+	 * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp).
238
+	 * We also set some other properties in this method.
239
+	 *
240
+	 * @param string $timezone_string A valid timezone string as described by @link
241
+	 *                                http://www.php.net/manual/en/timezones.php
242
+	 * @return void
243
+	 * @throws \EE_Error
244
+	 */
245
+	public function set_timezone($timezone_string)
246
+	{
247
+		if (empty($timezone_string) && $this->_timezone_string !== null) {
248
+			// leave the timezone AS-IS if we already have one and
249
+			// the function arg didn't provide one
250
+			return;
251
+		}
252
+		$timezone_string        = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
253
+		$this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC';
254
+		$this->_DateTimeZone    = $this->_create_timezone_object_from_timezone_string($this->_timezone_string);
255
+	}
256
+
257
+
258
+	/**
259
+	 * _create_timezone_object_from_timezone_name
260
+	 *
261
+	 * @access protected
262
+	 * @param string $timezone_string
263
+	 * @return \DateTimeZone
264
+	 * @throws \EE_Error
265
+	 */
266
+	protected function _create_timezone_object_from_timezone_string($timezone_string = '')
267
+	{
268
+		return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string));
269
+	}
270
+
271
+
272
+	/**
273
+	 * This just returns whatever is set for the current timezone.
274
+	 *
275
+	 * @access public
276
+	 * @return string timezone string
277
+	 */
278
+	public function get_timezone()
279
+	{
280
+		return $this->_timezone_string;
281
+	}
282
+
283
+
284
+	/**
285
+	 * set the $_date_format property
286
+	 *
287
+	 * @access public
288
+	 * @param string $format a new date format (corresponding to formats accepted by PHP date() function)
289
+	 * @param bool   $pretty Whether to set pretty format or not.
290
+	 * @return void
291
+	 */
292
+	public function set_date_format($format, $pretty = false)
293
+	{
294
+		if ($pretty) {
295
+			$this->_pretty_date_format = $format;
296
+		} else {
297
+			$this->_date_format = $format;
298
+		}
299
+	}
300
+
301
+
302
+	/**
303
+	 * return the $_date_format property value.
304
+	 *
305
+	 * @param bool $pretty Whether to get pretty format or not.
306
+	 * @return string
307
+	 */
308
+	public function get_date_format($pretty = false)
309
+	{
310
+		return $pretty ? $this->_pretty_date_format : $this->_date_format;
311
+	}
312
+
313
+
314
+	/**
315
+	 * set the $_time_format property
316
+	 *
317
+	 * @access public
318
+	 * @param string $format a new time format (corresponding to formats accepted by PHP date() function)
319
+	 * @param bool   $pretty Whether to set pretty format or not.
320
+	 * @return void
321
+	 */
322
+	public function set_time_format($format, $pretty = false)
323
+	{
324
+		if ($pretty) {
325
+			$this->_pretty_time_format = $format;
326
+		} else {
327
+			$this->_time_format = $format;
328
+		}
329
+	}
330
+
331
+
332
+	/**
333
+	 * return the $_time_format property value.
334
+	 *
335
+	 * @param bool $pretty Whether to get pretty format or not.
336
+	 * @return string
337
+	 */
338
+	public function get_time_format($pretty = false)
339
+	{
340
+		return $pretty ? $this->_pretty_time_format : $this->_time_format;
341
+	}
342
+
343
+
344
+	/**
345
+	 * set the $_pretty_date_format property
346
+	 *
347
+	 * @access public
348
+	 * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function)
349
+	 * @return void
350
+	 */
351
+	public function set_pretty_date_format($format)
352
+	{
353
+		$this->_pretty_date_format = $format;
354
+	}
355
+
356
+
357
+	/**
358
+	 * set the $_pretty_time_format property
359
+	 *
360
+	 * @access public
361
+	 * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function)
362
+	 * @return void
363
+	 */
364
+	public function set_pretty_time_format($format)
365
+	{
366
+		$this->_pretty_time_format = $format;
367
+	}
368
+
369
+
370
+	/**
371
+	 * Only sets the time portion of the datetime.
372
+	 *
373
+	 * @param string|DateTime $time_to_set_string like 8am OR a DateTime object.
374
+	 * @param DateTime        $current            current DateTime object for the datetime field
375
+	 * @return DateTime
376
+	 */
377
+	public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current)
378
+	{
379
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
380
+		// Otherwise parse the string.
381
+		if ($time_to_set_string instanceof DateTime) {
382
+			$parsed = array(
383
+				'hour'   => $time_to_set_string->format('H'),
384
+				'minute' => $time_to_set_string->format('i'),
385
+				'second' => $time_to_set_string->format('s'),
386
+			);
387
+		} else {
388
+			//parse incoming string
389
+			$parsed = date_parse_from_format($this->_time_format, $time_to_set_string);
390
+		}
391
+
392
+		//make sure $current is in the correct timezone.
393
+		$current->setTimezone($this->_DateTimeZone);
394
+
395
+		return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']);
396
+	}
397
+
398
+
399
+	/**
400
+	 * Only sets the date portion of the datetime.
401
+	 *
402
+	 * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object.
403
+	 * @param DateTime        $current            current DateTime object for the datetime field
404
+	 * @return DateTime
405
+	 */
406
+	public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current)
407
+	{
408
+		// if $time_to_set_string is datetime object, then let's use it to set the parse array.
409
+		// Otherwise parse the string.
410
+		if ($date_to_set_string instanceof DateTime) {
411
+			$parsed = array(
412
+				'year'  => $date_to_set_string->format('Y'),
413
+				'month' => $date_to_set_string->format('m'),
414
+				'day'   => $date_to_set_string->format('d'),
415
+			);
416
+		} else {
417
+			//parse incoming string
418
+			$parsed = date_parse_from_format($this->_date_format, $date_to_set_string);
419
+		}
420
+
421
+		//make sure $current is in the correct timezone
422
+		$current->setTimezone($this->_DateTimeZone);
423
+
424
+		return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']);
425
+	}
426
+
427
+
428
+	/**
429
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone).  When the
430
+	 * datetime gets to this stage it should ALREADY be in UTC time
431
+	 *
432
+	 * @param  DateTime $DateTime
433
+	 * @return string formatted date time for given timezone
434
+	 * @throws \EE_Error
435
+	 */
436
+	public function prepare_for_get($DateTime)
437
+	{
438
+		return $this->_prepare_for_display($DateTime);
439
+	}
440
+
441
+
442
+	/**
443
+	 * This differs from prepare_for_get in that it considers whether the internal $_timezone differs
444
+	 * from the set wp timezone.  If so, then it returns the datetime string formatted via
445
+	 * _pretty_date_format, and _pretty_time_format.  However, it also appends a timezone
446
+	 * abbreviation to the date_string.
447
+	 *
448
+	 * @param mixed $DateTime
449
+	 * @param null  $schema
450
+	 * @return string
451
+	 * @throws \EE_Error
452
+	 */
453
+	public function prepare_for_pretty_echoing($DateTime, $schema = null)
454
+	{
455
+		return $this->_prepare_for_display($DateTime, $schema ? $schema : true);
456
+	}
457
+
458
+
459
+	/**
460
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
461
+	 * timezone).
462
+	 *
463
+	 * @param DateTime    $DateTime
464
+	 * @param bool|string $schema
465
+	 * @return string
466
+	 * @throws \EE_Error
467
+	 */
468
+	protected function _prepare_for_display($DateTime, $schema = false)
469
+	{
470
+		if (! $DateTime instanceof DateTime) {
471
+			if ($this->_nullable) {
472
+				return '';
473
+			} else {
474
+				if (WP_DEBUG) {
475
+					throw new EE_Error(
476
+						sprintf(
477
+							__(
478
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.',
479
+								'event_espresso'
480
+							),
481
+							$this->_nicename
482
+						)
483
+					);
484
+				} else {
485
+					$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now);
486
+					EE_Error::add_error(
487
+						sprintf(
488
+							__(
489
+								'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.  When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.',
490
+								'event_espresso'
491
+							),
492
+							$this->_nicename
493
+						)
494
+					);
495
+				}
496
+			}
497
+		}
498
+		$format_string = $this->_get_date_time_output($schema);
499
+		//make sure datetime_value is in the correct timezone (in case that's been updated).
500
+		$DateTime->setTimezone($this->_DateTimeZone);
501
+		if ($schema) {
502
+			if ($this->_display_timezone()) {
503
+				//must be explicit because schema could equal true.
504
+				if ($schema === 'no_html') {
505
+					$timezone_string = ' (' . $DateTime->format('T') . ')';
506
+				} else {
507
+					$timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>';
508
+				}
509
+			} else {
510
+				$timezone_string = '';
511
+			}
512
+
513
+			return $DateTime->format($format_string) . $timezone_string;
514
+		} else {
515
+			return $DateTime->format($format_string);
516
+		}
517
+	}
518
+
519
+
520
+	/**
521
+	 * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0
522
+	 * timezone).
523
+	 *
524
+	 * @param  mixed $datetime_value u
525
+	 * @return string mysql timestamp in UTC
526
+	 * @throws \EE_Error
527
+	 */
528
+	public function prepare_for_use_in_db($datetime_value)
529
+	{
530
+		//we allow an empty value or DateTime object, but nothing else.
531
+		if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) {
532
+			throw new EE_Error(
533
+				__(
534
+					'The incoming value being prepared for setting in the database must either be empty or a php DateTime object',
535
+					'event_espresso'
536
+				)
537
+			);
538
+		}
539
+
540
+		if ($datetime_value instanceof DateTime) {
541
+			if ( ! $datetime_value instanceof DbSafeDateTime) {
542
+				$datetime_value = DbSafeDateTime::createFromDateTime($datetime_value);
543
+			}
544
+
545
+			return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format(
546
+				EE_Datetime_Field::mysql_timestamp_format
547
+			);
548
+		}
549
+
550
+		// if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true
551
+		return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null;
552
+	}
553
+
554
+
555
+	/**
556
+	 * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is
557
+	 * allowed)
558
+	 *
559
+	 * @param string $datetime_string mysql timestamp in UTC
560
+	 * @return  mixed null | DateTime
561
+	 * @throws \EE_Error
562
+	 */
563
+	public function prepare_for_set_from_db($datetime_string)
564
+	{
565
+		//if $datetime_value is empty, and ! $this->_nullable, just use time()
566
+		if (empty($datetime_string) && $this->_nullable) {
567
+			return null;
568
+		}
569
+		// datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating
570
+		if (empty($datetime_string)) {
571
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
572
+		} else {
573
+			$DateTime = DateTime::createFromFormat(
574
+				EE_Datetime_Field::mysql_timestamp_format,
575
+				$datetime_string,
576
+				$this->get_UTC_DateTimeZone()
577
+			);
578
+			if ($DateTime instanceof \DateTime) {
579
+				$DateTime = new DbSafeDateTime(
580
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
581
+					$this->get_UTC_DateTimeZone()
582
+				);
583
+			}
584
+		}
585
+
586
+		if (! $DateTime instanceof DbSafeDateTime) {
587
+			// if still no datetime object, then let's just use now
588
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone());
589
+		}
590
+		// THEN apply the field's set DateTimeZone
591
+		$DateTime->setTimezone($this->_DateTimeZone);
592
+
593
+		return $DateTime;
594
+	}
595
+
596
+
597
+	/**
598
+	 * All this method does is determine if we're going to display the timezone string or not on any output.
599
+	 * To determine this we check if the set timezone offset is different than the blog's set timezone offset.
600
+	 * If so, then true.
601
+	 *
602
+	 * @return bool true for yes false for no
603
+	 * @throws \EE_Error
604
+	 */
605
+	protected function _display_timezone()
606
+	{
607
+
608
+		// first let's do a comparison of timezone strings.
609
+		// If they match then we can get out without any further calculations
610
+		$blog_string = get_option('timezone_string');
611
+		if ($blog_string === $this->_timezone_string) {
612
+			return false;
613
+		}
614
+		// now we need to calc the offset for the timezone string so we can compare with the blog offset.
615
+		$this_offset = $this->get_timezone_offset($this->_DateTimeZone);
616
+		$blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone());
617
+		// now compare
618
+		return $blog_offset !== $this_offset;
619
+	}
620
+
621
+
622
+	/**
623
+	 * This method returns a php DateTime object for setting on the EE_Base_Class model.
624
+	 * EE passes around DateTime objects because they are MUCH easier to manipulate and deal
625
+	 * with.
626
+	 *
627
+	 * @param int|string|DateTime $date_string            This should be the incoming date string.  It's assumed to be
628
+	 *                                                    in the format that is set on the date_field (or DateTime
629
+	 *                                                    object)!
630
+	 * @return DateTime
631
+	 */
632
+	protected function _get_date_object($date_string)
633
+	{
634
+		//first if this is an empty date_string and nullable is allowed, just return null.
635
+		if ($this->_nullable && empty($date_string)) {
636
+			return null;
637
+		}
638
+
639
+		// if incoming date
640
+		if ($date_string instanceof DateTime) {
641
+			$date_string->setTimezone($this->_DateTimeZone);
642
+
643
+			return $date_string;
644
+		}
645
+		// if empty date_string and made it here.
646
+		// Return a datetime object for now in the given timezone.
647
+		if (empty($date_string)) {
648
+			return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
649
+		}
650
+		// if $date_string is matches something that looks like a Unix timestamp let's just use it.
651
+		if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) {
652
+			try {
653
+				// This is operating under the assumption that the incoming Unix timestamp
654
+				// is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp');
655
+				$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
656
+				$DateTime->setTimestamp($date_string);
657
+
658
+				return $DateTime;
659
+			} catch (Exception $e) {
660
+				// should be rare, but if things got fooled then let's just continue
661
+			}
662
+		}
663
+		//not a unix timestamp.  So we will use the set format on this object and set timezone to
664
+		//create the DateTime object.
665
+		$format = $this->_date_format . ' ' . $this->_time_format;
666
+		try {
667
+			$DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone);
668
+			if ($DateTime instanceof DateTime) {
669
+				$DateTime = new DbSafeDateTime(
670
+					$DateTime->format(\EE_Datetime_Field::mysql_timestamp_format),
671
+					$this->_DateTimeZone
672
+				);
673
+			}
674
+			if (! $DateTime instanceof DbSafeDateTime) {
675
+				throw new EE_Error(
676
+					sprintf(
677
+						__('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'),
678
+						$date_string,
679
+						$format
680
+					)
681
+				);
682
+			}
683
+		} catch (Exception $e) {
684
+			// if we made it here then likely then something went really wrong.
685
+			// Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone.
686
+			$DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone);
687
+		}
688
+
689
+		return $DateTime;
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 * get_timezone_transitions
696
+	 *
697
+	 * @param \DateTimeZone $DateTimeZone
698
+	 * @param int           $time
699
+	 * @param bool          $first_only
700
+	 * @return mixed
701
+	 */
702
+	public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true)
703
+	{
704
+		$time = is_int($time) || $time === null ? $time : strtotime($time);
705
+		$time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time();
706
+		$transitions = $DateTimeZone->getTransitions($time);
707
+		return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions;
708
+	}
709
+
710
+
711
+
712
+	/**
713
+	 * get_timezone_offset
714
+	 *
715
+	 * @param \DateTimeZone $DateTimeZone
716
+	 * @param int           $time
717
+	 * @return mixed
718
+	 * @throws \DomainException
719
+	 */
720
+	public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null)
721
+	{
722
+		$transitions = $this->get_timezone_transitions($DateTimeZone, $time);
723
+		if ( ! isset($transitions['offset'])) {
724
+			throw new DomainException();
725
+		}
726
+		return $transitions['offset'];
727
+	}
728
+
729
+
730
+	/**
731
+	 * This will take an incoming timezone string and return the abbreviation for that timezone
732
+	 *
733
+	 * @param  string $timezone_string
734
+	 * @return string           abbreviation
735
+	 * @throws \EE_Error
736
+	 */
737
+	public function get_timezone_abbrev($timezone_string)
738
+	{
739
+		$timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string);
740
+		$dateTime        = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string));
741
+
742
+		return $dateTime->format('T');
743
+	}
744
+
745
+	/**
746
+	 * Overrides the parent to allow for having a dynamic "now" value
747
+	 *
748
+	 * @return mixed
749
+	 */
750
+	public function get_default_value()
751
+	{
752
+		if ($this->_default_value === EE_Datetime_Field::now) {
753
+			return time();
754
+		} else {
755
+			return parent::get_default_value();
756
+		}
757
+	}
758
+
759
+
760
+	public function getSchemaDescription()
761
+	{
762
+		return sprintf(
763
+			esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'),
764
+			$this->get_nicename()
765
+		);
766
+	}
767 767
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Email_Field.php 2 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -9,48 +9,48 @@
 block discarded – undo
9 9
  */
10 10
 class EE_Email_Field extends EE_Text_Field_Base
11 11
 {
12
-    /**
13
-     * @param string $table_column
14
-     * @param string $nicename
15
-     * @param bool   $nullable
16
-     * @param null   $default_value
17
-     */
18
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
19
-    {
20
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
21
-        $this->setSchemaFormat('email');
22
-    }
12
+	/**
13
+	 * @param string $table_column
14
+	 * @param string $nicename
15
+	 * @param bool   $nullable
16
+	 * @param null   $default_value
17
+	 */
18
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
19
+	{
20
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
21
+		$this->setSchemaFormat('email');
22
+	}
23 23
 
24 24
 
25
-    /**
26
-     * In form inputs, we should have called htmlentities and addslashes() on form inputs,
27
-     * so we need to undo that on setting of these fields
28
-     *
29
-     * @param string $email_address
30
-     * @return string
31
-     */
32
-    function prepare_for_set($email_address)
33
-    {
34
-        $validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
35
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
36
-            : 'wp_default';
37
-        if ($validation_level === 'basic' && ! preg_match('/^.+\@\S+$/', $email_address)) {
38
-            // email not even in correct {string}@{string} format
39
-            return '';
40
-        } else if ($validation_level === 'wp_default' && ! is_email($email_address)) {
41
-            //not a valid email.
42
-            return '';
43
-        } else if (
44
-            ($validation_level === 'i18n' || $validation_level === 'i18n_dns')
45
-            // plz see http://stackoverflow.com/a/24817336 re: the following regex
46
-            && ! preg_match(
47
-                '/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u',
48
-                $email_address
49
-            )
50
-        ) {
51
-            //not a valid email.
52
-            return '';
53
-        }
54
-        return $email_address;
55
-    }
25
+	/**
26
+	 * In form inputs, we should have called htmlentities and addslashes() on form inputs,
27
+	 * so we need to undo that on setting of these fields
28
+	 *
29
+	 * @param string $email_address
30
+	 * @return string
31
+	 */
32
+	function prepare_for_set($email_address)
33
+	{
34
+		$validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
35
+			? EE_Registry::instance()->CFG->registration->email_validation_level
36
+			: 'wp_default';
37
+		if ($validation_level === 'basic' && ! preg_match('/^.+\@\S+$/', $email_address)) {
38
+			// email not even in correct {string}@{string} format
39
+			return '';
40
+		} else if ($validation_level === 'wp_default' && ! is_email($email_address)) {
41
+			//not a valid email.
42
+			return '';
43
+		} else if (
44
+			($validation_level === 'i18n' || $validation_level === 'i18n_dns')
45
+			// plz see http://stackoverflow.com/a/24817336 re: the following regex
46
+			&& ! preg_match(
47
+				'/^(?!\.)((?!.*\.{2})[a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\.!#$%&\'*+-\/=?^_`{|}~\-\d]+)@(?!\.)([a-zA-Z0-9\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}\-\.\d]+)((\.([a-zA-Z\x{0080}-\x{00FF}\x{0100}-\x{017F}\x{0180}-\x{024F}\x{0250}-\x{02AF}\x{0300}-\x{036F}\x{0370}-\x{03FF}\x{0400}-\x{04FF}\x{0500}-\x{052F}\x{0530}-\x{058F}\x{0590}-\x{05FF}\x{0600}-\x{06FF}\x{0700}-\x{074F}\x{0750}-\x{077F}\x{0780}-\x{07BF}\x{07C0}-\x{07FF}\x{0900}-\x{097F}\x{0980}-\x{09FF}\x{0A00}-\x{0A7F}\x{0A80}-\x{0AFF}\x{0B00}-\x{0B7F}\x{0B80}-\x{0BFF}\x{0C00}-\x{0C7F}\x{0C80}-\x{0CFF}\x{0D00}-\x{0D7F}\x{0D80}-\x{0DFF}\x{0E00}-\x{0E7F}\x{0E80}-\x{0EFF}\x{0F00}-\x{0FFF}\x{1000}-\x{109F}\x{10A0}-\x{10FF}\x{1100}-\x{11FF}\x{1200}-\x{137F}\x{1380}-\x{139F}\x{13A0}-\x{13FF}\x{1400}-\x{167F}\x{1680}-\x{169F}\x{16A0}-\x{16FF}\x{1700}-\x{171F}\x{1720}-\x{173F}\x{1740}-\x{175F}\x{1760}-\x{177F}\x{1780}-\x{17FF}\x{1800}-\x{18AF}\x{1900}-\x{194F}\x{1950}-\x{197F}\x{1980}-\x{19DF}\x{19E0}-\x{19FF}\x{1A00}-\x{1A1F}\x{1B00}-\x{1B7F}\x{1D00}-\x{1D7F}\x{1D80}-\x{1DBF}\x{1DC0}-\x{1DFF}\x{1E00}-\x{1EFF}\x{1F00}-\x{1FFF}\x{20D0}-\x{20FF}\x{2100}-\x{214F}\x{2C00}-\x{2C5F}\x{2C60}-\x{2C7F}\x{2C80}-\x{2CFF}\x{2D00}-\x{2D2F}\x{2D30}-\x{2D7F}\x{2D80}-\x{2DDF}\x{2F00}-\x{2FDF}\x{2FF0}-\x{2FFF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{3100}-\x{312F}\x{3130}-\x{318F}\x{3190}-\x{319F}\x{31C0}-\x{31EF}\x{31F0}-\x{31FF}\x{3200}-\x{32FF}\x{3300}-\x{33FF}\x{3400}-\x{4DBF}\x{4DC0}-\x{4DFF}\x{4E00}-\x{9FFF}\x{A000}-\x{A48F}\x{A490}-\x{A4CF}\x{A700}-\x{A71F}\x{A800}-\x{A82F}\x{A840}-\x{A87F}\x{AC00}-\x{D7AF}\x{F900}-\x{FAFF}]){2,63})+)$/u',
48
+				$email_address
49
+			)
50
+		) {
51
+			//not a valid email.
52
+			return '';
53
+		}
54
+		return $email_address;
55
+	}
56 56
 }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
      * @param string $table_column
20 20
      * @param string $nicename
21 21
      * @param bool   $nullable
22
-     * @param null   $default_value
22
+     * @param string   $default_value
23 23
      */
24 24
     public function __construct($table_column, $nicename, $nullable, $default_value = null)
25 25
     {
Please login to merge, or discard this patch.
core/db_models/fields/EE_DB_Only_Float_Field.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,16 +3,16 @@
 block discarded – undo
3 3
 
4 4
 class EE_DB_Only_Float_Field extends EE_DB_Only_Field_Base
5 5
 {
6
-    /**
7
-     * @param string $table_column
8
-     * @param string $nicename
9
-     * @param bool   $nullable
10
-     * @param null   $default_value
11
-     */
12
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
13
-    {
14
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
15
-        $this->setSchemaType('number');
16
-    }
6
+	/**
7
+	 * @param string $table_column
8
+	 * @param string $nicename
9
+	 * @param bool   $nullable
10
+	 * @param null   $default_value
11
+	 */
12
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
13
+	{
14
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
15
+		$this->setSchemaType('number');
16
+	}
17 17
 
18 18
 }
Please login to merge, or discard this patch.