Completed
Branch BUG-9951-10331-8793-pue-fixes (9f33f1)
by
unknown
26:00 queued 14:50
created
core/entities/models/JsonModelSchema.php 2 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -24,117 +24,117 @@
 block discarded – undo
24 24
 class JsonModelSchema
25 25
 {
26 26
 
27
-    /**
28
-     * @var \EEM_Base
29
-     */
30
-    protected $model;
31
-
32
-    /**
33
-     * JsonModelSchema constructor.
34
-     *
35
-     * @param \EEM_Base $model
36
-     */
37
-    public function __construct(EEM_Base $model)
38
-    {
39
-        $this->model = $model;
40
-    }
41
-
42
-    /**
43
-     * Return the schema for a given model from a given model.
44
-     * @param \EEM_Base $model
45
-     * @return array
46
-     */
47
-    public function getModelSchema()
48
-    {
49
-        return $this->getModelSchemaForRelations(
50
-            $this->model->relation_settings(),
51
-            $this->getModelSchemaForFields(
52
-                $this->model->field_settings(),
53
-                $this->getInitialSchemaStructure()
54
-            )
55
-        );
56
-    }
57
-
58
-
59
-    /**
60
-     * Get the schema for a given set of model fields.
61
-     * @param \EE_Model_Field_Base[]     $model_fields
62
-     * @return array
63
-     */
64
-    public function getModelSchemaForFields(array $model_fields, array $schema)
65
-    {
66
-        foreach ($model_fields as $field => $model_field) {
67
-            if (! $model_field instanceof EE_Model_Field_Base) {
68
-                continue;
69
-            }
70
-            $schema['properties'][$field] = $model_field->getSchema();
71
-
72
-            //if this is a primary key field add the primary key item
73
-            if ($model_field instanceof EE_Primary_Key_Field_Base) {
74
-                $schema['properties'][$field]['primary_key'] = true;
75
-            }
76
-
77
-            //if this is a foreign key field add the foreign key item
78
-            if ($model_field instanceof EE_Foreign_Key_Field_Base) {
79
-                $schema['properties'][$field]['foreign_key'] = array(
80
-                    'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'),
81
-                    'type' => 'array',
82
-                    'enum' => $model_field->get_model_class_names_pointed_to()
83
-                );
84
-            }
85
-        }
86
-        return $schema;
87
-    }
88
-
89
-
90
-    /**
91
-     * Get the schema for a given set of model relations
92
-     * @param EE_Model_Relation_Base[] $relations_on_model
93
-     * @return array
94
-     */
95
-    public function getModelSchemaForRelations(array $relations_on_model, array $schema)
96
-    {
97
-        foreach ($relations_on_model as $model_name => $relation) {
98
-            if (! $relation instanceof EE_Model_Relation_Base) {
99
-                continue;
100
-            }
101
-            $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
102
-                ? strtolower($model_name)
103
-                : EEH_Inflector::pluralize_and_lower($model_name);
104
-            $schema['properties'][$model_name_for_schema] = $relation->getSchema();
105
-            $schema['properties'][$model_name_for_schema]['relation_model'] = $model_name;
106
-        }
107
-        return $schema;
108
-    }
109
-
110
-
111
-    /**
112
-     * Outputs the schema header for a model.
113
-     * @param \EEM_Base $model
114
-     * @return array
115
-     */
116
-    public function getInitialSchemaStructure()
117
-    {
118
-        return array(
119
-            '$schema' => 'http://json-schema.org/draft-04/schema#',
120
-            'title' => $this->model->get_this_model_name(),
121
-            'type' => 'object',
122
-            'properties' => array()
123
-        );
124
-    }
125
-
126
-
127
-    /**
128
-     * Allows one to just use the object as a string to get the json.
129
-     * eg.
130
-     *
131
-     * $json_schema = new JsonModelSchema(EEM_Event::instance());
132
-     * echo $json_schema; //outputs the schema as a json formatted string.
133
-     *
134
-     * @return bool|false|mixed|string
135
-     */
136
-    public function __toString()
137
-    {
138
-        return wp_json_encode($this->getModelSchema());
139
-    }
27
+	/**
28
+	 * @var \EEM_Base
29
+	 */
30
+	protected $model;
31
+
32
+	/**
33
+	 * JsonModelSchema constructor.
34
+	 *
35
+	 * @param \EEM_Base $model
36
+	 */
37
+	public function __construct(EEM_Base $model)
38
+	{
39
+		$this->model = $model;
40
+	}
41
+
42
+	/**
43
+	 * Return the schema for a given model from a given model.
44
+	 * @param \EEM_Base $model
45
+	 * @return array
46
+	 */
47
+	public function getModelSchema()
48
+	{
49
+		return $this->getModelSchemaForRelations(
50
+			$this->model->relation_settings(),
51
+			$this->getModelSchemaForFields(
52
+				$this->model->field_settings(),
53
+				$this->getInitialSchemaStructure()
54
+			)
55
+		);
56
+	}
57
+
58
+
59
+	/**
60
+	 * Get the schema for a given set of model fields.
61
+	 * @param \EE_Model_Field_Base[]     $model_fields
62
+	 * @return array
63
+	 */
64
+	public function getModelSchemaForFields(array $model_fields, array $schema)
65
+	{
66
+		foreach ($model_fields as $field => $model_field) {
67
+			if (! $model_field instanceof EE_Model_Field_Base) {
68
+				continue;
69
+			}
70
+			$schema['properties'][$field] = $model_field->getSchema();
71
+
72
+			//if this is a primary key field add the primary key item
73
+			if ($model_field instanceof EE_Primary_Key_Field_Base) {
74
+				$schema['properties'][$field]['primary_key'] = true;
75
+			}
76
+
77
+			//if this is a foreign key field add the foreign key item
78
+			if ($model_field instanceof EE_Foreign_Key_Field_Base) {
79
+				$schema['properties'][$field]['foreign_key'] = array(
80
+					'description' => esc_html__('This is a foreign key the points to the given models.', 'event_espresso'),
81
+					'type' => 'array',
82
+					'enum' => $model_field->get_model_class_names_pointed_to()
83
+				);
84
+			}
85
+		}
86
+		return $schema;
87
+	}
88
+
89
+
90
+	/**
91
+	 * Get the schema for a given set of model relations
92
+	 * @param EE_Model_Relation_Base[] $relations_on_model
93
+	 * @return array
94
+	 */
95
+	public function getModelSchemaForRelations(array $relations_on_model, array $schema)
96
+	{
97
+		foreach ($relations_on_model as $model_name => $relation) {
98
+			if (! $relation instanceof EE_Model_Relation_Base) {
99
+				continue;
100
+			}
101
+			$model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
102
+				? strtolower($model_name)
103
+				: EEH_Inflector::pluralize_and_lower($model_name);
104
+			$schema['properties'][$model_name_for_schema] = $relation->getSchema();
105
+			$schema['properties'][$model_name_for_schema]['relation_model'] = $model_name;
106
+		}
107
+		return $schema;
108
+	}
109
+
110
+
111
+	/**
112
+	 * Outputs the schema header for a model.
113
+	 * @param \EEM_Base $model
114
+	 * @return array
115
+	 */
116
+	public function getInitialSchemaStructure()
117
+	{
118
+		return array(
119
+			'$schema' => 'http://json-schema.org/draft-04/schema#',
120
+			'title' => $this->model->get_this_model_name(),
121
+			'type' => 'object',
122
+			'properties' => array()
123
+		);
124
+	}
125
+
126
+
127
+	/**
128
+	 * Allows one to just use the object as a string to get the json.
129
+	 * eg.
130
+	 *
131
+	 * $json_schema = new JsonModelSchema(EEM_Event::instance());
132
+	 * echo $json_schema; //outputs the schema as a json formatted string.
133
+	 *
134
+	 * @return bool|false|mixed|string
135
+	 */
136
+	public function __toString()
137
+	{
138
+		return wp_json_encode($this->getModelSchema());
139
+	}
140 140
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     public function getModelSchemaForFields(array $model_fields, array $schema)
65 65
     {
66 66
         foreach ($model_fields as $field => $model_field) {
67
-            if (! $model_field instanceof EE_Model_Field_Base) {
67
+            if ( ! $model_field instanceof EE_Model_Field_Base) {
68 68
                 continue;
69 69
             }
70 70
             $schema['properties'][$field] = $model_field->getSchema();
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     public function getModelSchemaForRelations(array $relations_on_model, array $schema)
96 96
     {
97 97
         foreach ($relations_on_model as $model_name => $relation) {
98
-            if (! $relation instanceof EE_Model_Relation_Base) {
98
+            if ( ! $relation instanceof EE_Model_Relation_Base) {
99 99
                 continue;
100 100
             }
101 101
             $model_name_for_schema = $relation instanceof EE_Belongs_To_Relation
Please login to merge, or discard this patch.
core/db_models/fields/EE_Model_Field_Base.php 1 patch
Indentation   +598 added lines, -599 removed lines patch added patch discarded remove patch
@@ -21,603 +21,602 @@
 block discarded – undo
21 21
  */
22 22
 abstract class EE_Model_Field_Base implements HasSchemaInterface
23 23
 {
24
-    /**
25
-     * The alias for the table the column belongs to.
26
-     * @var string
27
-     */
28
-    protected $_table_alias;
29
-
30
-    /**
31
-     * The actual db column name for the table
32
-     * @var string
33
-     */
34
-    protected $_table_column;
35
-
36
-
37
-    /**
38
-     * The authoritative name for the table column (used by client code to reference the field).
39
-     * @var string
40
-     */
41
-    protected $_name;
42
-
43
-
44
-    /**
45
-     * A description for the field.
46
-     * @var string
47
-     */
48
-    protected $_nicename;
49
-
50
-
51
-    /**
52
-     * Whether the field is nullable or not
53
-     * @var bool
54
-     */
55
-    protected $_nullable;
56
-
57
-
58
-    /**
59
-     * What the default value for the field should be.
60
-     * @var mixed
61
-     */
62
-    protected $_default_value;
63
-
64
-
65
-    /**
66
-     * Other configuration for the field
67
-     * @var mixed
68
-     */
69
-    protected $_other_config;
70
-
71
-
72
-    /**
73
-     * The name of the model this field is instantiated for.
74
-     * @var string
75
-     */
76
-    protected $_model_name;
77
-
78
-
79
-    /**
80
-     * This should be a json-schema valid data type for the field.
81
-     * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
82
-     * @var string
83
-     */
84
-    private $_schema_type = 'string';
85
-
86
-
87
-    /**
88
-     * If the schema has a defined format then it should be defined via this property.
89
-     * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
90
-     * @var string
91
-     */
92
-    private $_schema_format = '';
93
-
94
-
95
-    /**
96
-     * Indicates that the value of the field is managed exclusively by the server/model and not something
97
-     * settable by client code.
98
-     * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4
99
-     * @var bool
100
-     */
101
-    private $_schema_readonly = false;
102
-
103
-
104
-    /**
105
-     * @param string $table_column
106
-     * @param string $nicename
107
-     * @param bool   $nullable
108
-     * @param null   $default_value
109
-     */
110
-    public function __construct($table_column, $nicename, $nullable, $default_value = null)
111
-    {
112
-        $this->_table_column  = $table_column;
113
-        $this->_nicename      = $nicename;
114
-        $this->_nullable      = $nullable;
115
-        $this->_default_value = $default_value;
116
-    }
117
-
118
-
119
-    /**
120
-     * @param $table_alias
121
-     * @param $name
122
-     * @param $model_name
123
-     */
124
-    public function _construct_finalize($table_alias, $name, $model_name)
125
-    {
126
-        $this->_table_alias = $table_alias;
127
-        $this->_name        = $name;
128
-        $this->_model_name  = $model_name;
129
-        /**
130
-         * allow for changing the defaults
131
-         */
132
-        $this->_nicename      = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename',
133
-            $this->_nicename, $this);
134
-        $this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value',
135
-            $this->_default_value, $this);
136
-    }
137
-
138
-    public function get_table_alias()
139
-    {
140
-        return $this->_table_alias;
141
-    }
142
-
143
-    public function get_table_column()
144
-    {
145
-        return $this->_table_column;
146
-    }
147
-
148
-    /**
149
-     * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
150
-     *
151
-     * @return string
152
-     */
153
-    public function get_model_name()
154
-    {
155
-        return $this->_model_name;
156
-    }
157
-
158
-    /**
159
-     * @throws \EE_Error
160
-     * @return string
161
-     */
162
-    public function get_name()
163
-    {
164
-        if ($this->_name) {
165
-            return $this->_name;
166
-        } else {
167
-            throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
168
-                "event_espresso"), get_class($this)));
169
-        }
170
-    }
171
-
172
-    public function get_nicename()
173
-    {
174
-        return $this->_nicename;
175
-    }
176
-
177
-    public function is_nullable()
178
-    {
179
-        return $this->_nullable;
180
-    }
181
-
182
-    /**
183
-     * returns whether this field is an auto-increment field or not. If it is, then
184
-     * on insertion it can be null. However, on updates it must be present.
185
-     *
186
-     * @return boolean
187
-     */
188
-    public function is_auto_increment()
189
-    {
190
-        return false;
191
-    }
192
-
193
-    /**
194
-     * The default value in the model object's value domain. See lengthy comment about
195
-     * value domains at the top of EEM_Base
196
-     *
197
-     * @return mixed
198
-     */
199
-    public function get_default_value()
200
-    {
201
-        return $this->_default_value;
202
-    }
203
-
204
-    /**
205
-     * Returns the table alias joined to the table column, however this isn't the right
206
-     * table alias if the aliased table is being joined to. In that case, you can use
207
-     * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
208
-     * in the current query
209
-     *
210
-     * @return string
211
-     */
212
-    public function get_qualified_column()
213
-    {
214
-        return $this->get_table_alias() . "." . $this->get_table_column();
215
-    }
216
-
217
-    /**
218
-     * When get() is called on a model object (eg EE_Event), before returning its value,
219
-     * call this function on it, allowing us to customize the returned value based on
220
-     * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default,
221
-     * we simply return it.
222
-     *
223
-     * @param mixed $value_of_field_on_model_object
224
-     * @return mixed
225
-     */
226
-    public function prepare_for_get($value_of_field_on_model_object)
227
-    {
228
-        return $value_of_field_on_model_object;
229
-    }
230
-
231
-    /**
232
-     * When inserting or updating a field on a model object, run this function on each
233
-     * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc.
234
-     * By default, we do nothing.
235
-     *
236
-     * @param mixed $value_of_field_on_model_object
237
-     * @return mixed
238
-     */
239
-    public function prepare_for_use_in_db($value_of_field_on_model_object)
240
-    {
241
-        return $value_of_field_on_model_object;
242
-    }
243
-
244
-    /**
245
-     * When creating a brand-new model object, or setting a particular value for one of its fields, this function
246
-     * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
247
-     * By default, we do nothing.
248
-     *
249
-     * @param mixed $value_inputted_for_field_on_model_object
250
-     * @return mixed
251
-     */
252
-    public function prepare_for_set($value_inputted_for_field_on_model_object)
253
-    {
254
-        return $value_inputted_for_field_on_model_object;
255
-    }
256
-
257
-
258
-    /**
259
-     * When instantiating a model object from DB results, this function is called before setting each field.
260
-     * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
261
-     * is the one child classes will most often define.
262
-     *
263
-     * @param mixed $value_found_in_db_for_model_object
264
-     * @return mixed
265
-     */
266
-    public function prepare_for_set_from_db($value_found_in_db_for_model_object)
267
-    {
268
-        return $this->prepare_for_set($value_found_in_db_for_model_object);
269
-    }
270
-
271
-    /**
272
-     * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
273
-     * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
274
-     * 2013, at 3:23pm" instead of
275
-     * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
276
-     *
277
-     * @param mixed $value_on_field_to_be_outputted
278
-     * @return mixed
279
-     */
280
-    public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
281
-    {
282
-        return $value_on_field_to_be_outputted;
283
-    }
284
-
285
-
286
-    /**
287
-     * Returns whatever is set as the nicename for the object.
288
-     * @return string
289
-     */
290
-    public function getSchemaDescription()
291
-    {
292
-        return $this->get_nicename();
293
-    }
294
-
295
-
296
-    /**
297
-     * Returns whatever is set as the $_schema_type property for the object.
298
-     * Note: this will automatically add 'null' to the schema if the object is_nullable()
299
-     * @return string|array
300
-     */
301
-    public function getSchemaType()
302
-    {
303
-        if ($this->is_nullable()) {
304
-            $this->_schema_type = (array) $this->_schema_type;
305
-            if (! in_array('null', $this->_schema_type)) {
306
-                $this->_schema_type[] = 'null';
307
-            };
308
-        }
309
-        return $this->_schema_type;
310
-    }
311
-
312
-
313
-    /**
314
-     * Sets the _schema_type property.  Child classes should call this in their constructors to override the default state
315
-     * for this property.
316
-     * @param string|array $type
317
-     * @throws InvalidArgumentException
318
-     */
319
-    protected function setSchemaType($type)
320
-    {
321
-        $this->validateSchemaType($type);
322
-        $this->_schema_type = $type;
323
-    }
324
-
325
-
326
-    /**
327
-     * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
328
-     * this method and return the properties for the schema.
329
-     *
330
-     * The reason this is not a property on the class is because there may be filters set on the values for the property
331
-     * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
332
-     *
333
-     * @return array
334
-     */
335
-    public function getSchemaProperties()
336
-    {
337
-        return array();
338
-    }
339
-
340
-
341
-    /**
342
-     * If a child class has enum values, they should override this method and provide a simple array
343
-     * of the enum values.
344
-
345
-     * The reason this is not a property on the class is because there may be filterable enum values that
346
-     * are set on the instantiated object that could be filtered after construct.
347
-     *
348
-     * @return array
349
-     */
350
-    public function getSchemaEnum()
351
-    {
352
-        return array();
353
-    }
354
-
355
-
356
-    /**
357
-     * This returns the value of the $_schema_format property on the object.
358
-     * @return string
359
-     */
360
-    public function getSchemaFormat()
361
-    {
362
-        return $this->_schema_format;
363
-    }
364
-
365
-
366
-    /**
367
-     * Sets the schema format property.
368
-     * @throws InvalidArgumentException
369
-     * @param string $format
370
-     */
371
-    protected function setSchemaFormat($format)
372
-    {
373
-        $this->validateSchemaFormat($format);
374
-        $this->_schema_format = $format;
375
-    }
376
-
377
-
378
-    /**
379
-     * This returns the value of the $_schema_readonly property on the object.
380
-     * @return bool
381
-     */
382
-    public function getSchemaReadonly()
383
-    {
384
-        return $this->_schema_readonly;
385
-    }
386
-
387
-
388
-    /**
389
-     * This sets the value for the $_schema_readonly property.
390
-     * @param bool $readonly  (only explicit boolean values are accepted)
391
-     */
392
-    protected function setSchemaReadOnly($readonly)
393
-    {
394
-        if (! is_bool($readonly)) {
395
-            throw new InvalidArgumentException(
396
-                sprintf(
397
-                    esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
398
-                    print_r($readonly, true)
399
-                )
400
-            );
401
-        }
402
-
403
-        $this->_schema_readonly = $readonly;
404
-    }
405
-
406
-
407
-
408
-
409
-    /**
410
-     * Return `%d`, `%s` or `%f` to indicate the data type for the field.
411
-     * @uses _get_wpdb_data_type()
412
-     *
413
-     * @return string
414
-     */
415
-    public function get_wpdb_data_type()
416
-    {
417
-        return $this->_get_wpdb_data_type();
418
-    }
419
-
420
-
421
-    /**
422
-     * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries.
423
-     * @param string $type  Included if a specific type is requested.
424
-     * @uses get_schema_type()
425
-     * @return string
426
-     */
427
-    protected function _get_wpdb_data_type($type='')
428
-    {
429
-        $type = empty($type) ? $this->getSchemaType() : $type;
430
-
431
-        //if type is an array, then different parsing is required.
432
-        if (is_array($type)) {
433
-            return $this->_get_wpdb_data_type_for_type_array($type);
434
-        }
435
-
436
-        $wpdb_type = '%s';
437
-        switch ($type) {
438
-            case 'number':
439
-                $wpdb_type = '%f';
440
-                break;
441
-            case 'integer':
442
-            case 'boolean':
443
-                $wpdb_type = '%d';
444
-                break;
445
-            case 'object':
446
-                $properties = $this->getSchemaProperties();
447
-                if (isset($properties['raw'], $properties['raw']['type'])) {
448
-                    $wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']);
449
-                }
450
-                break; //leave at default
451
-        }
452
-        return $wpdb_type;
453
-    }
454
-
455
-
456
-
457
-    protected function _get_wpdb_data_type_for_type_array($type)
458
-    {
459
-        $type = (array) $type;
460
-        //first let's flip because then we can do a faster key check
461
-        $type = array_flip($type);
462
-
463
-        //check for things that mean '%s'
464
-        if (isset($type['string'],$type['object'],$type['array'])) {
465
-            return '%s';
466
-        }
467
-
468
-        //if makes it past the above condition and there's float in the array
469
-        //then the type is %f
470
-        if (isset($type['number'])) {
471
-            return '%f';
472
-        }
473
-
474
-        //if it makes it above the above conditions and there is an integer in the array
475
-        //then the type is %d
476
-        if (isset($type['integer'])) {
477
-            return '%d';
478
-        }
479
-
480
-        //anything else is a string
481
-        return '%s';
482
-    }
483
-
484
-
485
-    /**
486
-     * This returns elements used to represent this field in the json schema.
487
-     *
488
-     * @link http://json-schema.org/
489
-     * @return array
490
-     */
491
-    public function getSchema()
492
-    {
493
-        $schema = array(
494
-            'description' => $this->getSchemaDescription(),
495
-            'type' => $this->getSchemaType(),
496
-            'readonly' => $this->getSchemaReadonly(),
497
-            'default' => $this->get_default_value()
498
-        );
499
-
500
-        //optional properties of the schema
501
-        $enum = $this->getSchemaEnum();
502
-        $properties = $this->getSchemaProperties();
503
-        $format = $this->getSchemaFormat();
504
-        if ($enum) {
505
-            $schema['enum'] = $enum;
506
-        }
507
-
508
-        if ($properties) {
509
-            $schema['properties'] = $properties;
510
-        }
511
-
512
-        if ($format) {
513
-            $schema['format'] = $format;
514
-        }
515
-        return $schema;
516
-    }
517
-
518
-    /**
519
-     * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
520
-     * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
521
-     * want to see their value, then they shouldn't be db-only fields!)
522
-     * Eg, when doing events as custom post types, querying the post_type is essential, but
523
-     * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
524
-     * By default, all fields aren't db-only.
525
-     *
526
-     * @return boolean
527
-     */
528
-    public function is_db_only_field()
529
-    {
530
-        return false;
531
-    }
532
-
533
-
534
-    /**
535
-     * Validates the incoming string|array to ensure its an allowable type.
536
-     * @throws InvalidArgumentException
537
-     * @param string|array $type
538
-     */
539
-    private function validateSchemaType($type)
540
-    {
541
-        if (! (is_string($type) || is_array($type))) {
542
-            throw new InvalidArgumentException(
543
-                sprintf(
544
-                    esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
545
-                    print_r($type, true)
546
-                )
547
-            );
548
-        }
549
-
550
-        //validate allowable types.
551
-        //@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
552
-        $allowable_types = array_flip(
553
-            array(
554
-                'string',
555
-                'number',
556
-                'null',
557
-                'object',
558
-                'array',
559
-                'boolean',
560
-                'integer'
561
-            )
562
-        );
563
-
564
-        if (is_array($type)) {
565
-            foreach ($type as $item_in_type) {
566
-                $this->validateSchemaType($item_in_type);
567
-            }
568
-            return;
569
-        }
570
-
571
-        if (! isset($allowable_types[$type])) {
572
-            throw new InvalidArgumentException(
573
-                sprintf(
574
-                    esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
575
-                    $type,
576
-                    implode(',', array_flip($allowable_types))
577
-                )
578
-            );
579
-        }
580
-    }
581
-
582
-
583
-    /**
584
-     * Validates that the incoming format is an allowable string to use for the _schema_format property
585
-     * @throws InvalidArgumentException
586
-     * @param $format
587
-     */
588
-    private function validateSchemaFormat($format)
589
-    {
590
-        if (! is_string($format)) {
591
-            throw new InvalidArgumentException(
592
-                sprintf(
593
-                    esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
594
-                    print_r($format, true)
595
-                )
596
-            );
597
-        }
598
-
599
-        //validate allowable format values
600
-        //@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
601
-        $allowable_formats = array_flip(
602
-            array(
603
-                'date-time',
604
-                'email',
605
-                'hostname',
606
-                'ipv4',
607
-                'ipv6',
608
-                'uri',
609
-                'uriref'
610
-            )
611
-        );
612
-
613
-        if (! isset($allowable_formats[$format])) {
614
-            throw new InvalidArgumentException(
615
-                sprintf(
616
-                    esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'),
617
-                    $format,
618
-                    implode(',', array_flip($allowable_formats))
619
-                )
620
-            );
621
-        }
622
-    }
24
+	/**
25
+	 * The alias for the table the column belongs to.
26
+	 * @var string
27
+	 */
28
+	protected $_table_alias;
29
+
30
+	/**
31
+	 * The actual db column name for the table
32
+	 * @var string
33
+	 */
34
+	protected $_table_column;
35
+
36
+
37
+	/**
38
+	 * The authoritative name for the table column (used by client code to reference the field).
39
+	 * @var string
40
+	 */
41
+	protected $_name;
42
+
43
+
44
+	/**
45
+	 * A description for the field.
46
+	 * @var string
47
+	 */
48
+	protected $_nicename;
49
+
50
+
51
+	/**
52
+	 * Whether the field is nullable or not
53
+	 * @var bool
54
+	 */
55
+	protected $_nullable;
56
+
57
+
58
+	/**
59
+	 * What the default value for the field should be.
60
+	 * @var mixed
61
+	 */
62
+	protected $_default_value;
63
+
64
+
65
+	/**
66
+	 * Other configuration for the field
67
+	 * @var mixed
68
+	 */
69
+	protected $_other_config;
70
+
71
+
72
+	/**
73
+	 * The name of the model this field is instantiated for.
74
+	 * @var string
75
+	 */
76
+	protected $_model_name;
77
+
78
+
79
+	/**
80
+	 * This should be a json-schema valid data type for the field.
81
+	 * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
82
+	 * @var string
83
+	 */
84
+	private $_schema_type = 'string';
85
+
86
+
87
+	/**
88
+	 * If the schema has a defined format then it should be defined via this property.
89
+	 * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
90
+	 * @var string
91
+	 */
92
+	private $_schema_format = '';
93
+
94
+
95
+	/**
96
+	 * Indicates that the value of the field is managed exclusively by the server/model and not something
97
+	 * settable by client code.
98
+	 * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4
99
+	 * @var bool
100
+	 */
101
+	private $_schema_readonly = false;
102
+
103
+
104
+	/**
105
+	 * @param string $table_column
106
+	 * @param string $nicename
107
+	 * @param bool   $nullable
108
+	 * @param null   $default_value
109
+	 */
110
+	public function __construct($table_column, $nicename, $nullable, $default_value = null)
111
+	{
112
+		$this->_table_column  = $table_column;
113
+		$this->_nicename      = $nicename;
114
+		$this->_nullable      = $nullable;
115
+		$this->_default_value = $default_value;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param $table_alias
121
+	 * @param $name
122
+	 * @param $model_name
123
+	 */
124
+	public function _construct_finalize($table_alias, $name, $model_name)
125
+	{
126
+		$this->_table_alias = $table_alias;
127
+		$this->_name        = $name;
128
+		$this->_model_name  = $model_name;
129
+		/**
130
+		 * allow for changing the defaults
131
+		 */
132
+		$this->_nicename      = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename',
133
+			$this->_nicename, $this);
134
+		$this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value',
135
+			$this->_default_value, $this);
136
+	}
137
+
138
+	public function get_table_alias()
139
+	{
140
+		return $this->_table_alias;
141
+	}
142
+
143
+	public function get_table_column()
144
+	{
145
+		return $this->_table_column;
146
+	}
147
+
148
+	/**
149
+	 * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime'
150
+	 *
151
+	 * @return string
152
+	 */
153
+	public function get_model_name()
154
+	{
155
+		return $this->_model_name;
156
+	}
157
+
158
+	/**
159
+	 * @throws \EE_Error
160
+	 * @return string
161
+	 */
162
+	public function get_name()
163
+	{
164
+		if ($this->_name) {
165
+			return $this->_name;
166
+		} else {
167
+			throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?",
168
+				"event_espresso"), get_class($this)));
169
+		}
170
+	}
171
+
172
+	public function get_nicename()
173
+	{
174
+		return $this->_nicename;
175
+	}
176
+
177
+	public function is_nullable()
178
+	{
179
+		return $this->_nullable;
180
+	}
181
+
182
+	/**
183
+	 * returns whether this field is an auto-increment field or not. If it is, then
184
+	 * on insertion it can be null. However, on updates it must be present.
185
+	 *
186
+	 * @return boolean
187
+	 */
188
+	public function is_auto_increment()
189
+	{
190
+		return false;
191
+	}
192
+
193
+	/**
194
+	 * The default value in the model object's value domain. See lengthy comment about
195
+	 * value domains at the top of EEM_Base
196
+	 *
197
+	 * @return mixed
198
+	 */
199
+	public function get_default_value()
200
+	{
201
+		return $this->_default_value;
202
+	}
203
+
204
+	/**
205
+	 * Returns the table alias joined to the table column, however this isn't the right
206
+	 * table alias if the aliased table is being joined to. In that case, you can use
207
+	 * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias
208
+	 * in the current query
209
+	 *
210
+	 * @return string
211
+	 */
212
+	public function get_qualified_column()
213
+	{
214
+		return $this->get_table_alias() . "." . $this->get_table_column();
215
+	}
216
+
217
+	/**
218
+	 * When get() is called on a model object (eg EE_Event), before returning its value,
219
+	 * call this function on it, allowing us to customize the returned value based on
220
+	 * the field's type. Eg, we may want ot serialize it, strip tags, etc. By default,
221
+	 * we simply return it.
222
+	 *
223
+	 * @param mixed $value_of_field_on_model_object
224
+	 * @return mixed
225
+	 */
226
+	public function prepare_for_get($value_of_field_on_model_object)
227
+	{
228
+		return $value_of_field_on_model_object;
229
+	}
230
+
231
+	/**
232
+	 * When inserting or updating a field on a model object, run this function on each
233
+	 * value to prepare it for insertion into the db. We may want to add slashes, serialize it, etc.
234
+	 * By default, we do nothing.
235
+	 *
236
+	 * @param mixed $value_of_field_on_model_object
237
+	 * @return mixed
238
+	 */
239
+	public function prepare_for_use_in_db($value_of_field_on_model_object)
240
+	{
241
+		return $value_of_field_on_model_object;
242
+	}
243
+
244
+	/**
245
+	 * When creating a brand-new model object, or setting a particular value for one of its fields, this function
246
+	 * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc.
247
+	 * By default, we do nothing.
248
+	 *
249
+	 * @param mixed $value_inputted_for_field_on_model_object
250
+	 * @return mixed
251
+	 */
252
+	public function prepare_for_set($value_inputted_for_field_on_model_object)
253
+	{
254
+		return $value_inputted_for_field_on_model_object;
255
+	}
256
+
257
+
258
+	/**
259
+	 * When instantiating a model object from DB results, this function is called before setting each field.
260
+	 * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that
261
+	 * is the one child classes will most often define.
262
+	 *
263
+	 * @param mixed $value_found_in_db_for_model_object
264
+	 * @return mixed
265
+	 */
266
+	public function prepare_for_set_from_db($value_found_in_db_for_model_object)
267
+	{
268
+		return $this->prepare_for_set($value_found_in_db_for_model_object);
269
+	}
270
+
271
+	/**
272
+	 * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a
273
+	 * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12,
274
+	 * 2013, at 3:23pm" instead of
275
+	 * "8765678632", or any other modifications to how the value should be displayed, but not modified itself.
276
+	 *
277
+	 * @param mixed $value_on_field_to_be_outputted
278
+	 * @return mixed
279
+	 */
280
+	public function prepare_for_pretty_echoing($value_on_field_to_be_outputted)
281
+	{
282
+		return $value_on_field_to_be_outputted;
283
+	}
284
+
285
+
286
+	/**
287
+	 * Returns whatever is set as the nicename for the object.
288
+	 * @return string
289
+	 */
290
+	public function getSchemaDescription()
291
+	{
292
+		return $this->get_nicename();
293
+	}
294
+
295
+
296
+	/**
297
+	 * Returns whatever is set as the $_schema_type property for the object.
298
+	 * Note: this will automatically add 'null' to the schema if the object is_nullable()
299
+	 * @return string|array
300
+	 */
301
+	public function getSchemaType()
302
+	{
303
+		if ($this->is_nullable()) {
304
+			$this->_schema_type = (array) $this->_schema_type;
305
+			if (! in_array('null', $this->_schema_type)) {
306
+				$this->_schema_type[] = 'null';
307
+			};
308
+		}
309
+		return $this->_schema_type;
310
+	}
311
+
312
+
313
+	/**
314
+	 * Sets the _schema_type property.  Child classes should call this in their constructors to override the default state
315
+	 * for this property.
316
+	 * @param string|array $type
317
+	 * @throws InvalidArgumentException
318
+	 */
319
+	protected function setSchemaType($type)
320
+	{
321
+		$this->validateSchemaType($type);
322
+		$this->_schema_type = $type;
323
+	}
324
+
325
+
326
+	/**
327
+	 * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
328
+	 * this method and return the properties for the schema.
329
+	 *
330
+	 * The reason this is not a property on the class is because there may be filters set on the values for the property
331
+	 * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
332
+	 *
333
+	 * @return array
334
+	 */
335
+	public function getSchemaProperties()
336
+	{
337
+		return array();
338
+	}
339
+
340
+
341
+	/**
342
+	 * If a child class has enum values, they should override this method and provide a simple array
343
+	 * of the enum values.
344
+	 * The reason this is not a property on the class is because there may be filterable enum values that
345
+	 * are set on the instantiated object that could be filtered after construct.
346
+	 *
347
+	 * @return array
348
+	 */
349
+	public function getSchemaEnum()
350
+	{
351
+		return array();
352
+	}
353
+
354
+
355
+	/**
356
+	 * This returns the value of the $_schema_format property on the object.
357
+	 * @return string
358
+	 */
359
+	public function getSchemaFormat()
360
+	{
361
+		return $this->_schema_format;
362
+	}
363
+
364
+
365
+	/**
366
+	 * Sets the schema format property.
367
+	 * @throws InvalidArgumentException
368
+	 * @param string $format
369
+	 */
370
+	protected function setSchemaFormat($format)
371
+	{
372
+		$this->validateSchemaFormat($format);
373
+		$this->_schema_format = $format;
374
+	}
375
+
376
+
377
+	/**
378
+	 * This returns the value of the $_schema_readonly property on the object.
379
+	 * @return bool
380
+	 */
381
+	public function getSchemaReadonly()
382
+	{
383
+		return $this->_schema_readonly;
384
+	}
385
+
386
+
387
+	/**
388
+	 * This sets the value for the $_schema_readonly property.
389
+	 * @param bool $readonly  (only explicit boolean values are accepted)
390
+	 */
391
+	protected function setSchemaReadOnly($readonly)
392
+	{
393
+		if (! is_bool($readonly)) {
394
+			throw new InvalidArgumentException(
395
+				sprintf(
396
+					esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'),
397
+					print_r($readonly, true)
398
+				)
399
+			);
400
+		}
401
+
402
+		$this->_schema_readonly = $readonly;
403
+	}
404
+
405
+
406
+
407
+
408
+	/**
409
+	 * Return `%d`, `%s` or `%f` to indicate the data type for the field.
410
+	 * @uses _get_wpdb_data_type()
411
+	 *
412
+	 * @return string
413
+	 */
414
+	public function get_wpdb_data_type()
415
+	{
416
+		return $this->_get_wpdb_data_type();
417
+	}
418
+
419
+
420
+	/**
421
+	 * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries.
422
+	 * @param string $type  Included if a specific type is requested.
423
+	 * @uses get_schema_type()
424
+	 * @return string
425
+	 */
426
+	protected function _get_wpdb_data_type($type='')
427
+	{
428
+		$type = empty($type) ? $this->getSchemaType() : $type;
429
+
430
+		//if type is an array, then different parsing is required.
431
+		if (is_array($type)) {
432
+			return $this->_get_wpdb_data_type_for_type_array($type);
433
+		}
434
+
435
+		$wpdb_type = '%s';
436
+		switch ($type) {
437
+			case 'number':
438
+				$wpdb_type = '%f';
439
+				break;
440
+			case 'integer':
441
+			case 'boolean':
442
+				$wpdb_type = '%d';
443
+				break;
444
+			case 'object':
445
+				$properties = $this->getSchemaProperties();
446
+				if (isset($properties['raw'], $properties['raw']['type'])) {
447
+					$wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']);
448
+				}
449
+				break; //leave at default
450
+		}
451
+		return $wpdb_type;
452
+	}
453
+
454
+
455
+
456
+	protected function _get_wpdb_data_type_for_type_array($type)
457
+	{
458
+		$type = (array) $type;
459
+		//first let's flip because then we can do a faster key check
460
+		$type = array_flip($type);
461
+
462
+		//check for things that mean '%s'
463
+		if (isset($type['string'],$type['object'],$type['array'])) {
464
+			return '%s';
465
+		}
466
+
467
+		//if makes it past the above condition and there's float in the array
468
+		//then the type is %f
469
+		if (isset($type['number'])) {
470
+			return '%f';
471
+		}
472
+
473
+		//if it makes it above the above conditions and there is an integer in the array
474
+		//then the type is %d
475
+		if (isset($type['integer'])) {
476
+			return '%d';
477
+		}
478
+
479
+		//anything else is a string
480
+		return '%s';
481
+	}
482
+
483
+
484
+	/**
485
+	 * This returns elements used to represent this field in the json schema.
486
+	 *
487
+	 * @link http://json-schema.org/
488
+	 * @return array
489
+	 */
490
+	public function getSchema()
491
+	{
492
+		$schema = array(
493
+			'description' => $this->getSchemaDescription(),
494
+			'type' => $this->getSchemaType(),
495
+			'readonly' => $this->getSchemaReadonly(),
496
+			'default' => $this->get_default_value()
497
+		);
498
+
499
+		//optional properties of the schema
500
+		$enum = $this->getSchemaEnum();
501
+		$properties = $this->getSchemaProperties();
502
+		$format = $this->getSchemaFormat();
503
+		if ($enum) {
504
+			$schema['enum'] = $enum;
505
+		}
506
+
507
+		if ($properties) {
508
+			$schema['properties'] = $properties;
509
+		}
510
+
511
+		if ($format) {
512
+			$schema['format'] = $format;
513
+		}
514
+		return $schema;
515
+	}
516
+
517
+	/**
518
+	 * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part
519
+	 * of the model objects (ie, client code shouldn't care to ever see their value... if client code does
520
+	 * want to see their value, then they shouldn't be db-only fields!)
521
+	 * Eg, when doing events as custom post types, querying the post_type is essential, but
522
+	 * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event').
523
+	 * By default, all fields aren't db-only.
524
+	 *
525
+	 * @return boolean
526
+	 */
527
+	public function is_db_only_field()
528
+	{
529
+		return false;
530
+	}
531
+
532
+
533
+	/**
534
+	 * Validates the incoming string|array to ensure its an allowable type.
535
+	 * @throws InvalidArgumentException
536
+	 * @param string|array $type
537
+	 */
538
+	private function validateSchemaType($type)
539
+	{
540
+		if (! (is_string($type) || is_array($type))) {
541
+			throw new InvalidArgumentException(
542
+				sprintf(
543
+					esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'),
544
+					print_r($type, true)
545
+				)
546
+			);
547
+		}
548
+
549
+		//validate allowable types.
550
+		//@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
551
+		$allowable_types = array_flip(
552
+			array(
553
+				'string',
554
+				'number',
555
+				'null',
556
+				'object',
557
+				'array',
558
+				'boolean',
559
+				'integer'
560
+			)
561
+		);
562
+
563
+		if (is_array($type)) {
564
+			foreach ($type as $item_in_type) {
565
+				$this->validateSchemaType($item_in_type);
566
+			}
567
+			return;
568
+		}
569
+
570
+		if (! isset($allowable_types[$type])) {
571
+			throw new InvalidArgumentException(
572
+				sprintf(
573
+					esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'),
574
+					$type,
575
+					implode(',', array_flip($allowable_types))
576
+				)
577
+			);
578
+		}
579
+	}
580
+
581
+
582
+	/**
583
+	 * Validates that the incoming format is an allowable string to use for the _schema_format property
584
+	 * @throws InvalidArgumentException
585
+	 * @param $format
586
+	 */
587
+	private function validateSchemaFormat($format)
588
+	{
589
+		if (! is_string($format)) {
590
+			throw new InvalidArgumentException(
591
+				sprintf(
592
+					esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'),
593
+					print_r($format, true)
594
+				)
595
+			);
596
+		}
597
+
598
+		//validate allowable format values
599
+		//@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7
600
+		$allowable_formats = array_flip(
601
+			array(
602
+				'date-time',
603
+				'email',
604
+				'hostname',
605
+				'ipv4',
606
+				'ipv6',
607
+				'uri',
608
+				'uriref'
609
+			)
610
+		);
611
+
612
+		if (! isset($allowable_formats[$format])) {
613
+			throw new InvalidArgumentException(
614
+				sprintf(
615
+					esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'),
616
+					$format,
617
+					implode(',', array_flip($allowable_formats))
618
+				)
619
+			);
620
+		}
621
+	}
623 622
 }
624 623
\ No newline at end of file
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.31.rc.017');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.31.rc.017');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.