@@ -8,133 +8,133 @@ |
||
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 | 44 | |
45 | - /** |
|
46 | - * Runs the content through `the_content`, or if prepares the content for placing in a form input |
|
47 | - * @param string $value_on_field_to_be_outputted |
|
48 | - * @param string $schema possible values: 'form_input' or null (if null, will run through 'the_content') |
|
49 | - * @return string |
|
50 | - * @throws EE_Error when WP_DEBUG is on and recursive calling is detected |
|
51 | - */ |
|
52 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
53 | - { |
|
54 | - switch($schema){ |
|
55 | - case 'form_input': |
|
56 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
57 | - case 'the_content': |
|
45 | + /** |
|
46 | + * Runs the content through `the_content`, or if prepares the content for placing in a form input |
|
47 | + * @param string $value_on_field_to_be_outputted |
|
48 | + * @param string $schema possible values: 'form_input' or null (if null, will run through 'the_content') |
|
49 | + * @return string |
|
50 | + * @throws EE_Error when WP_DEBUG is on and recursive calling is detected |
|
51 | + */ |
|
52 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
53 | + { |
|
54 | + switch($schema){ |
|
55 | + case 'form_input': |
|
56 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
57 | + case 'the_content': |
|
58 | 58 | |
59 | - if(doing_filter( 'the_content')){ |
|
60 | - if( defined('WP_DEBUG') && WP_DEBUG){ |
|
61 | - throw new EE_Error( |
|
62 | - sprintf( |
|
63 | - esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
|
64 | - 'EE_Post_Content_Field::prepare_for_pretty_echoing', |
|
65 | - '$schema', |
|
66 | - 'the_content', |
|
67 | - 'the_content_wp_core_only' |
|
68 | - ) |
|
69 | - ); |
|
70 | - } else { |
|
71 | - return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only'); |
|
72 | - } |
|
73 | - } |
|
74 | - return apply_filters( |
|
75 | - 'the_content', |
|
76 | - parent::prepare_for_pretty_echoing( |
|
77 | - $value_on_field_to_be_outputted, |
|
78 | - $schema |
|
79 | - ) |
|
80 | - ); |
|
81 | - case 'the_content_wp_core_only': |
|
82 | - default: |
|
83 | - self::_setup_the_content_wp_core_only_filters(); |
|
84 | - $return_value = apply_filters( |
|
85 | - 'the_content_wp_core_only', |
|
86 | - parent::prepare_for_pretty_echoing( |
|
87 | - $value_on_field_to_be_outputted, |
|
88 | - $schema |
|
89 | - ) |
|
90 | - ); |
|
91 | - //ya know what? adding these filters is super fast. Let's just |
|
92 | - //avoid needing to maintain global state and set this up as-needed |
|
93 | - remove_all_filters('the_content_wp_core_only'); |
|
94 | - do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
95 | - return $return_value; |
|
96 | - } |
|
97 | - } |
|
59 | + if(doing_filter( 'the_content')){ |
|
60 | + if( defined('WP_DEBUG') && WP_DEBUG){ |
|
61 | + throw new EE_Error( |
|
62 | + sprintf( |
|
63 | + esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
|
64 | + 'EE_Post_Content_Field::prepare_for_pretty_echoing', |
|
65 | + '$schema', |
|
66 | + 'the_content', |
|
67 | + 'the_content_wp_core_only' |
|
68 | + ) |
|
69 | + ); |
|
70 | + } else { |
|
71 | + return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only'); |
|
72 | + } |
|
73 | + } |
|
74 | + return apply_filters( |
|
75 | + 'the_content', |
|
76 | + parent::prepare_for_pretty_echoing( |
|
77 | + $value_on_field_to_be_outputted, |
|
78 | + $schema |
|
79 | + ) |
|
80 | + ); |
|
81 | + case 'the_content_wp_core_only': |
|
82 | + default: |
|
83 | + self::_setup_the_content_wp_core_only_filters(); |
|
84 | + $return_value = apply_filters( |
|
85 | + 'the_content_wp_core_only', |
|
86 | + parent::prepare_for_pretty_echoing( |
|
87 | + $value_on_field_to_be_outputted, |
|
88 | + $schema |
|
89 | + ) |
|
90 | + ); |
|
91 | + //ya know what? adding these filters is super fast. Let's just |
|
92 | + //avoid needing to maintain global state and set this up as-needed |
|
93 | + remove_all_filters('the_content_wp_core_only'); |
|
94 | + do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
95 | + return $return_value; |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | 100 | |
101 | - /** |
|
102 | - * Verifies we've setup the standard WP core filters on 'the_content_wp_core_only' filter |
|
103 | - */ |
|
104 | - protected static function _setup_the_content_wp_core_only_filters() |
|
105 | - { |
|
106 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
107 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
108 | - add_filter('the_content_wp_core_only', 'wptexturize', 10); |
|
109 | - add_filter('the_content_wp_core_only', 'wpautop', 10); |
|
110 | - add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
|
111 | - add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
|
112 | - if(function_exists('wp_make_content_images_responsive')) { |
|
113 | - add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
|
114 | - } |
|
115 | - add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
|
116 | - add_filter('the_content_wp_core_only', 'convert_smilies', 20); |
|
117 | - } |
|
101 | + /** |
|
102 | + * Verifies we've setup the standard WP core filters on 'the_content_wp_core_only' filter |
|
103 | + */ |
|
104 | + protected static function _setup_the_content_wp_core_only_filters() |
|
105 | + { |
|
106 | + add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
107 | + add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
108 | + add_filter('the_content_wp_core_only', 'wptexturize', 10); |
|
109 | + add_filter('the_content_wp_core_only', 'wpautop', 10); |
|
110 | + add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
|
111 | + add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
|
112 | + if(function_exists('wp_make_content_images_responsive')) { |
|
113 | + add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
|
114 | + } |
|
115 | + add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
|
116 | + add_filter('the_content_wp_core_only', 'convert_smilies', 20); |
|
117 | + } |
|
118 | 118 | |
119 | 119 | |
120 | 120 | |
121 | - public function getSchemaProperties() |
|
122 | - { |
|
123 | - return array( |
|
124 | - 'raw' => array( |
|
125 | - 'description' => sprintf( |
|
126 | - __('%s - the content as it exists in the database.', 'event_espresso'), |
|
127 | - $this->get_nicename() |
|
128 | - ), |
|
129 | - 'type' => 'string' |
|
130 | - ), |
|
131 | - 'rendered' => array( |
|
132 | - 'description' => sprintf( |
|
133 | - __('%s - the content rendered for display.', 'event_espresso'), |
|
134 | - $this->get_nicename() |
|
135 | - ), |
|
136 | - 'type' => 'string' |
|
137 | - ) |
|
138 | - ); |
|
139 | - } |
|
121 | + public function getSchemaProperties() |
|
122 | + { |
|
123 | + return array( |
|
124 | + 'raw' => array( |
|
125 | + 'description' => sprintf( |
|
126 | + __('%s - the content as it exists in the database.', 'event_espresso'), |
|
127 | + $this->get_nicename() |
|
128 | + ), |
|
129 | + 'type' => 'string' |
|
130 | + ), |
|
131 | + 'rendered' => array( |
|
132 | + 'description' => sprintf( |
|
133 | + __('%s - the content rendered for display.', 'event_espresso'), |
|
134 | + $this->get_nicename() |
|
135 | + ), |
|
136 | + 'type' => 'string' |
|
137 | + ) |
|
138 | + ); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | function prepare_for_set($value) |
31 | 31 | { |
32 | - if (! current_user_can('unfiltered_html')) { |
|
32 | + if ( ! current_user_can('unfiltered_html')) { |
|
33 | 33 | $value = wp_kses("$value", wp_kses_allowed_html('post')); |
34 | 34 | } |
35 | 35 | return parent::prepare_for_set($value); |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
53 | 53 | { |
54 | - switch($schema){ |
|
54 | + switch ($schema) { |
|
55 | 55 | case 'form_input': |
56 | 56 | return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
57 | 57 | case 'the_content': |
58 | 58 | |
59 | - if(doing_filter( 'the_content')){ |
|
60 | - if( defined('WP_DEBUG') && WP_DEBUG){ |
|
59 | + if (doing_filter('the_content')) { |
|
60 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
61 | 61 | throw new EE_Error( |
62 | 62 | sprintf( |
63 | 63 | esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | //ya know what? adding these filters is super fast. Let's just |
92 | 92 | //avoid needing to maintain global state and set this up as-needed |
93 | 93 | remove_all_filters('the_content_wp_core_only'); |
94 | - do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
94 | + do_action('AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
95 | 95 | return $return_value; |
96 | 96 | } |
97 | 97 | } |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected static function _setup_the_content_wp_core_only_filters() |
105 | 105 | { |
106 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
107 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
106 | + add_filter('the_content_wp_core_only', array($GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
107 | + add_filter('the_content_wp_core_only', array($GLOBALS['wp_embed'], 'autoembed'), 8); |
|
108 | 108 | add_filter('the_content_wp_core_only', 'wptexturize', 10); |
109 | 109 | add_filter('the_content_wp_core_only', 'wpautop', 10); |
110 | 110 | add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
111 | 111 | add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
112 | - if(function_exists('wp_make_content_images_responsive')) { |
|
112 | + if (function_exists('wp_make_content_images_responsive')) { |
|
113 | 113 | add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
114 | 114 | } |
115 | 115 | add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | */ |
37 | 37 | protected $_feature_image = array(); |
38 | 38 | |
39 | - /** |
|
40 | - * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var WP_Post the WP_Post that corresponds with this CPT model object |
|
41 | + */ |
|
42 | 42 | protected $_wp_post; |
43 | 43 | |
44 | 44 | |
@@ -46,75 +46,75 @@ discard block |
||
46 | 46 | |
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
51 | - * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
52 | - * @return WP_Post |
|
53 | - */ |
|
54 | - public function wp_post(){ |
|
55 | - global $wpdb; |
|
56 | - if (! $this->_wp_post instanceof WP_Post) { |
|
57 | - if ($this->ID()) { |
|
58 | - $this->_wp_post = get_post($this->ID()); |
|
59 | - } else { |
|
60 | - $simulated_db_result = new stdClass(); |
|
61 | - foreach($this->get_model()->field_settings(true) as $field_name => $field_obj){ |
|
62 | - if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts){ |
|
63 | - $column = $field_obj->get_table_column(); |
|
64 | - |
|
65 | - if($field_obj instanceof EE_Datetime_Field){ |
|
66 | - $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
67 | - } elseif( $field_obj->is_db_only_field()){ |
|
68 | - $value_on_model_obj = $field_obj->get_default_value(); |
|
69 | - } else { |
|
70 | - $value_on_model_obj = $this->get_raw($field_name); |
|
71 | - } |
|
72 | - $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
73 | - } |
|
74 | - } |
|
75 | - $this->_wp_post = new WP_Post($simulated_db_result); |
|
76 | - } |
|
77 | - //and let's make retrieving the EE CPT object easy too |
|
78 | - $classname = get_class($this); |
|
79 | - if (! isset($this->_wp_post->{$classname})) { |
|
80 | - $this->_wp_post->{$classname} = $this; |
|
81 | - } |
|
82 | - } |
|
83 | - return $this->_wp_post; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * When fetching a new value for a post field that uses the global $post for rendering, |
|
88 | - * set the global $post temporarily to be this model object; and afterwards restore it |
|
89 | - * @param string $fieldname |
|
90 | - * @param bool $pretty |
|
91 | - * @param string $extra_cache_ref |
|
92 | - * @return mixed |
|
93 | - */ |
|
94 | - protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
95 | - { |
|
96 | - global $post; |
|
97 | - |
|
98 | - if ( $pretty |
|
99 | - && ( |
|
100 | - ! ( |
|
101 | - $post instanceof WP_Post |
|
102 | - && $post->ID |
|
103 | - ) |
|
104 | - || (int)$post->ID !== $this->ID() |
|
105 | - ) |
|
106 | - && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field ) { |
|
107 | - $old_post = $post; |
|
108 | - $post = $this->wp_post(); |
|
109 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
110 | - $post = $old_post; |
|
111 | - } else { |
|
112 | - $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
113 | - } |
|
114 | - return $return_value; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
49 | + /** |
|
50 | + * Returns the WP post associated with this CPT model object. If this CPT is saved, fetches it |
|
51 | + * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
|
52 | + * @return WP_Post |
|
53 | + */ |
|
54 | + public function wp_post(){ |
|
55 | + global $wpdb; |
|
56 | + if (! $this->_wp_post instanceof WP_Post) { |
|
57 | + if ($this->ID()) { |
|
58 | + $this->_wp_post = get_post($this->ID()); |
|
59 | + } else { |
|
60 | + $simulated_db_result = new stdClass(); |
|
61 | + foreach($this->get_model()->field_settings(true) as $field_name => $field_obj){ |
|
62 | + if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts){ |
|
63 | + $column = $field_obj->get_table_column(); |
|
64 | + |
|
65 | + if($field_obj instanceof EE_Datetime_Field){ |
|
66 | + $value_on_model_obj = $this->get_DateTime_object($field_name); |
|
67 | + } elseif( $field_obj->is_db_only_field()){ |
|
68 | + $value_on_model_obj = $field_obj->get_default_value(); |
|
69 | + } else { |
|
70 | + $value_on_model_obj = $this->get_raw($field_name); |
|
71 | + } |
|
72 | + $simulated_db_result->{$column} = $field_obj->prepare_for_use_in_db($value_on_model_obj); |
|
73 | + } |
|
74 | + } |
|
75 | + $this->_wp_post = new WP_Post($simulated_db_result); |
|
76 | + } |
|
77 | + //and let's make retrieving the EE CPT object easy too |
|
78 | + $classname = get_class($this); |
|
79 | + if (! isset($this->_wp_post->{$classname})) { |
|
80 | + $this->_wp_post->{$classname} = $this; |
|
81 | + } |
|
82 | + } |
|
83 | + return $this->_wp_post; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * When fetching a new value for a post field that uses the global $post for rendering, |
|
88 | + * set the global $post temporarily to be this model object; and afterwards restore it |
|
89 | + * @param string $fieldname |
|
90 | + * @param bool $pretty |
|
91 | + * @param string $extra_cache_ref |
|
92 | + * @return mixed |
|
93 | + */ |
|
94 | + protected function _get_fresh_property($fieldname, $pretty = false, $extra_cache_ref = null) |
|
95 | + { |
|
96 | + global $post; |
|
97 | + |
|
98 | + if ( $pretty |
|
99 | + && ( |
|
100 | + ! ( |
|
101 | + $post instanceof WP_Post |
|
102 | + && $post->ID |
|
103 | + ) |
|
104 | + || (int)$post->ID !== $this->ID() |
|
105 | + ) |
|
106 | + && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field ) { |
|
107 | + $old_post = $post; |
|
108 | + $post = $this->wp_post(); |
|
109 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
110 | + $post = $old_post; |
|
111 | + } else { |
|
112 | + $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
|
113 | + } |
|
114 | + return $return_value; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | 118 | * Adds to the specified event category. If it category doesn't exist, creates it. |
119 | 119 | * @param string $category_name |
120 | 120 | * @param string $category_description optional |
@@ -399,14 +399,14 @@ discard block |
||
399 | 399 | |
400 | 400 | |
401 | 401 | |
402 | - /** |
|
403 | - * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
404 | - * @return array |
|
405 | - */ |
|
406 | - public function __sleep() |
|
407 | - { |
|
408 | - $properties_to_serialize = parent::__sleep(); |
|
409 | - $properties_to_serialize = array_diff( $properties_to_serialize, array('_wp_post')); |
|
410 | - return $properties_to_serialize; |
|
411 | - } |
|
402 | + /** |
|
403 | + * Don't serialize the WP Post. That's just duplicate data and we want to avoid recursion |
|
404 | + * @return array |
|
405 | + */ |
|
406 | + public function __sleep() |
|
407 | + { |
|
408 | + $properties_to_serialize = parent::__sleep(); |
|
409 | + $properties_to_serialize = array_diff( $properties_to_serialize, array('_wp_post')); |
|
410 | + return $properties_to_serialize; |
|
411 | + } |
|
412 | 412 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -51,20 +51,20 @@ discard block |
||
51 | 51 | * from the DB. Otherwise, create an unsaved WP_POst object. Caches the post internally. |
52 | 52 | * @return WP_Post |
53 | 53 | */ |
54 | - public function wp_post(){ |
|
54 | + public function wp_post() { |
|
55 | 55 | global $wpdb; |
56 | - if (! $this->_wp_post instanceof WP_Post) { |
|
56 | + if ( ! $this->_wp_post instanceof WP_Post) { |
|
57 | 57 | if ($this->ID()) { |
58 | 58 | $this->_wp_post = get_post($this->ID()); |
59 | 59 | } else { |
60 | 60 | $simulated_db_result = new stdClass(); |
61 | - foreach($this->get_model()->field_settings(true) as $field_name => $field_obj){ |
|
62 | - if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts){ |
|
61 | + foreach ($this->get_model()->field_settings(true) as $field_name => $field_obj) { |
|
62 | + if ($this->get_model()->get_table_obj_by_alias($field_obj->get_table_alias())->get_table_name() === $wpdb->posts) { |
|
63 | 63 | $column = $field_obj->get_table_column(); |
64 | 64 | |
65 | - if($field_obj instanceof EE_Datetime_Field){ |
|
65 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
66 | 66 | $value_on_model_obj = $this->get_DateTime_object($field_name); |
67 | - } elseif( $field_obj->is_db_only_field()){ |
|
67 | + } elseif ($field_obj->is_db_only_field()) { |
|
68 | 68 | $value_on_model_obj = $field_obj->get_default_value(); |
69 | 69 | } else { |
70 | 70 | $value_on_model_obj = $this->get_raw($field_name); |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | } |
77 | 77 | //and let's make retrieving the EE CPT object easy too |
78 | 78 | $classname = get_class($this); |
79 | - if (! isset($this->_wp_post->{$classname})) { |
|
79 | + if ( ! isset($this->_wp_post->{$classname})) { |
|
80 | 80 | $this->_wp_post->{$classname} = $this; |
81 | 81 | } |
82 | 82 | } |
@@ -95,15 +95,15 @@ discard block |
||
95 | 95 | { |
96 | 96 | global $post; |
97 | 97 | |
98 | - if ( $pretty |
|
98 | + if ($pretty |
|
99 | 99 | && ( |
100 | 100 | ! ( |
101 | 101 | $post instanceof WP_Post |
102 | 102 | && $post->ID |
103 | 103 | ) |
104 | - || (int)$post->ID !== $this->ID() |
|
104 | + || (int) $post->ID !== $this->ID() |
|
105 | 105 | ) |
106 | - && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field ) { |
|
106 | + && $this->get_model()->field_settings_for($fieldname) instanceof EE_Post_Content_Field) { |
|
107 | 107 | $old_post = $post; |
108 | 108 | $post = $this->wp_post(); |
109 | 109 | $return_value = parent::_get_fresh_property($fieldname, $pretty, $extra_cache_ref); |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | * @param int $parent_term_taxonomy_id optional |
122 | 122 | * @return EE_Term_Taxonomy |
123 | 123 | */ |
124 | - function add_event_category( $category_name, $category_description = NULL, $parent_term_taxonomy_id = NULL ) { |
|
125 | - return $this->get_model()->add_event_category( $this, $category_name, $category_description, $parent_term_taxonomy_id ); |
|
124 | + function add_event_category($category_name, $category_description = NULL, $parent_term_taxonomy_id = NULL) { |
|
125 | + return $this->get_model()->add_event_category($this, $category_name, $category_description, $parent_term_taxonomy_id); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * @param string $category_name |
133 | 133 | * @return bool |
134 | 134 | */ |
135 | - function remove_event_category( $category_name ) { |
|
136 | - return $this->get_model()->remove_event_category( $this, $category_name ); |
|
135 | + function remove_event_category($category_name) { |
|
136 | + return $this->get_model()->remove_event_category($this, $category_name); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | * @param EE_Term_Taxonomy $term_taxonomy |
145 | 145 | * @return EE_Base_Class the relation was removed from |
146 | 146 | */ |
147 | - function remove_relation_to_term_taxonomy( $term_taxonomy ) { |
|
148 | - if ( !$term_taxonomy ) { |
|
149 | - EE_Error::add_error( sprintf( __( "No Term_Taxonomy provided which to remove from model object of type %s and id %d", "event_espresso" ), get_class( $this ), $this->ID() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
147 | + function remove_relation_to_term_taxonomy($term_taxonomy) { |
|
148 | + if ( ! $term_taxonomy) { |
|
149 | + EE_Error::add_error(sprintf(__("No Term_Taxonomy provided which to remove from model object of type %s and id %d", "event_espresso"), get_class($this), $this->ID()), __FILE__, __FUNCTION__, __LINE__); |
|
150 | 150 | return NULL; |
151 | 151 | } |
152 | - $term_taxonomy->set_count( $term_taxonomy->count() - 1 ); |
|
152 | + $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
153 | 153 | $term_taxonomy->save(); |
154 | - return $this->_remove_relation_to( $term_taxonomy, 'Term_Taxonomy' ); |
|
154 | + return $this->_remove_relation_to($term_taxonomy, 'Term_Taxonomy'); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @return int |
176 | 176 | */ |
177 | 177 | public function parent() { |
178 | - return $this->get( 'parent' ); |
|
178 | + return $this->get('parent'); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * @return string |
186 | 186 | */ |
187 | 187 | public function status() { |
188 | - return $this->get( 'status' ); |
|
188 | + return $this->get('status'); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | /** |
194 | 194 | * @param string $status |
195 | 195 | */ |
196 | - public function set_status( $status ) { |
|
197 | - $this->set( 'status', $status ); |
|
196 | + public function set_status($status) { |
|
197 | + $this->set('status', $status); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | |
@@ -208,12 +208,12 @@ discard block |
||
208 | 208 | * @param string|array $attr Optional. Query string or array of attributes. |
209 | 209 | * @return string HTML image element |
210 | 210 | */ |
211 | - protected function _get_feature_image( $size, $attr ) { |
|
211 | + protected function _get_feature_image($size, $attr) { |
|
212 | 212 | //first let's see if we already have the _feature_image property set AND if it has a cached element on it FOR the given size |
213 | - $attr_key = is_array( $attr ) ? implode( '_', $attr ) : $attr; |
|
214 | - $cache_key = is_array( $size ) ? implode( '_', $size ) . $attr_key : $size . $attr_key; |
|
215 | - $this->_feature_image[ $cache_key ] = isset( $this->_feature_image[ $cache_key ] ) ? $this->_feature_image[ $cache_key ] : $this->get_model()->get_feature_image( $this->ID(), $size, $attr ); |
|
216 | - return $this->_feature_image[ $cache_key ]; |
|
213 | + $attr_key = is_array($attr) ? implode('_', $attr) : $attr; |
|
214 | + $cache_key = is_array($size) ? implode('_', $size).$attr_key : $size.$attr_key; |
|
215 | + $this->_feature_image[$cache_key] = isset($this->_feature_image[$cache_key]) ? $this->_feature_image[$cache_key] : $this->get_model()->get_feature_image($this->ID(), $size, $attr); |
|
216 | + return $this->_feature_image[$cache_key]; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * @param string|array $attr |
225 | 225 | * @return string of html |
226 | 226 | */ |
227 | - public function feature_image( $size = 'thumbnail', $attr = '' ) { |
|
228 | - return $this->_get_feature_image( $size, $attr ); |
|
227 | + public function feature_image($size = 'thumbnail', $attr = '') { |
|
228 | + return $this->_get_feature_image($size, $attr); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | * @param string|array $size can either be a string: 'thumbnail', 'medium', 'large', 'full' OR 2-item array representing width and height in pixels eg. array(32,32). |
236 | 236 | * @return string|boolean the url of the image or false if not found |
237 | 237 | */ |
238 | - public function feature_image_url( $size = 'thumbnail' ) { |
|
239 | - $attachment = wp_get_attachment_image_src( get_post_thumbnail_id( $this->ID() ), $size ); |
|
240 | - return !empty( $attachment ) ? $attachment[ 0 ] : FALSE; |
|
238 | + public function feature_image_url($size = 'thumbnail') { |
|
239 | + $attachment = wp_get_attachment_image_src(get_post_thumbnail_id($this->ID()), $size); |
|
240 | + return ! empty($attachment) ? $attachment[0] : FALSE; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | |
@@ -259,36 +259,36 @@ discard block |
||
259 | 259 | * This array is INDEXED by RELATED OBJ NAME (so it corresponds with the obj_names sent); |
260 | 260 | * @return void |
261 | 261 | */ |
262 | - public function restore_revision( $revision_id, $related_obj_names = array(), $where_query = array() ) { |
|
262 | + public function restore_revision($revision_id, $related_obj_names = array(), $where_query = array()) { |
|
263 | 263 | //get revision object |
264 | - $revision_obj = $this->get_model()->get_one_by_ID( $revision_id ); |
|
265 | - if ( $revision_obj instanceof EE_CPT_Base ) { |
|
264 | + $revision_obj = $this->get_model()->get_one_by_ID($revision_id); |
|
265 | + if ($revision_obj instanceof EE_CPT_Base) { |
|
266 | 266 | //no related_obj_name so we assume we're saving a revision on this object. |
267 | - if ( empty( $related_obj_names ) ) { |
|
267 | + if (empty($related_obj_names)) { |
|
268 | 268 | $fields = $this->get_model()->get_meta_table_fields(); |
269 | - foreach ( $fields as $field ) { |
|
270 | - $this->set( $field, $revision_obj->get( $field ) ); |
|
269 | + foreach ($fields as $field) { |
|
270 | + $this->set($field, $revision_obj->get($field)); |
|
271 | 271 | } |
272 | 272 | $this->save(); |
273 | 273 | } |
274 | - $related_obj_names = (array)$related_obj_names; |
|
275 | - foreach ( $related_obj_names as $related_name ) { |
|
274 | + $related_obj_names = (array) $related_obj_names; |
|
275 | + foreach ($related_obj_names as $related_name) { |
|
276 | 276 | //related_obj_name so we're saving a revision on an object related to this object |
277 | 277 | //do we have $where_query params for this related object? If we do then we include that. |
278 | - $cols_n_values = isset( $where_query[ $related_name ] ) ? $where_query[ $related_name ] : array(); |
|
279 | - $where_params = !empty( $cols_n_values ) ? array( $cols_n_values ) : array(); |
|
280 | - $related_objs = $this->get_many_related( $related_name, $where_params ); |
|
281 | - $revision_related_objs = $revision_obj->get_many_related( $related_name, $where_params ); |
|
278 | + $cols_n_values = isset($where_query[$related_name]) ? $where_query[$related_name] : array(); |
|
279 | + $where_params = ! empty($cols_n_values) ? array($cols_n_values) : array(); |
|
280 | + $related_objs = $this->get_many_related($related_name, $where_params); |
|
281 | + $revision_related_objs = $revision_obj->get_many_related($related_name, $where_params); |
|
282 | 282 | //load helper |
283 | 283 | //remove related objs from this object that are not in revision |
284 | 284 | //array_diff *should* work cause I think objects are indexed by ID? |
285 | - $related_to_remove = EEH_Array::object_array_diff( $related_objs, $revision_related_objs ); |
|
286 | - foreach ( $related_to_remove as $rr ) { |
|
287 | - $this->_remove_relation_to( $rr, $related_name, $cols_n_values ); |
|
285 | + $related_to_remove = EEH_Array::object_array_diff($related_objs, $revision_related_objs); |
|
286 | + foreach ($related_to_remove as $rr) { |
|
287 | + $this->_remove_relation_to($rr, $related_name, $cols_n_values); |
|
288 | 288 | } |
289 | 289 | //add all related objs attached to revision to this object |
290 | - foreach ( $revision_related_objs as $r_obj ) { |
|
291 | - $this->_add_relation_to( $r_obj, $related_name, $cols_n_values ); |
|
290 | + foreach ($revision_related_objs as $r_obj) { |
|
291 | + $this->_add_relation_to($r_obj, $related_name, $cols_n_values); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | } |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | * <li>If $single is set to false, or left blank, the function returns an array containing all values of the specified key.</li> |
305 | 305 | * <li>If $single is set to true, the function returns the first value of the specified key (not in an array</li></ul> |
306 | 306 | */ |
307 | - public function get_post_meta( $meta_key = NULL, $single = FALSE ) { |
|
308 | - return get_post_meta( $this->ID(), $meta_key, $single ); |
|
307 | + public function get_post_meta($meta_key = NULL, $single = FALSE) { |
|
308 | + return get_post_meta($this->ID(), $meta_key, $single); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -317,11 +317,11 @@ discard block |
||
317 | 317 | * @param mixed $prev_value |
318 | 318 | * @return mixed Returns meta_id if the meta doesn't exist, otherwise returns true on success and false on failure. NOTE: If the meta_value passed to this function is the same as the value that is already in the database, this function returns false. |
319 | 319 | */ |
320 | - public function update_post_meta( $meta_key, $meta_value, $prev_value = NULL ) { |
|
321 | - if ( ! $this->ID() ) { |
|
320 | + public function update_post_meta($meta_key, $meta_value, $prev_value = NULL) { |
|
321 | + if ( ! $this->ID()) { |
|
322 | 322 | $this->save(); |
323 | 323 | } |
324 | - return update_post_meta( $this->ID(), $meta_key, $meta_value, $prev_value ); |
|
324 | + return update_post_meta($this->ID(), $meta_key, $meta_value, $prev_value); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | |
@@ -333,11 +333,11 @@ discard block |
||
333 | 333 | * @param bool $unique . If postmeta for this $meta_key already exists, whether to add an additional item or not |
334 | 334 | * @return boolean Boolean true, except if the $unique argument was set to true and a custom field with the given key already exists, in which case false is returned. |
335 | 335 | */ |
336 | - public function add_post_meta( $meta_key, $meta_value, $unique = FALSE ) { |
|
337 | - if ( $this->ID() ) { |
|
336 | + public function add_post_meta($meta_key, $meta_value, $unique = FALSE) { |
|
337 | + if ($this->ID()) { |
|
338 | 338 | $this->save(); |
339 | 339 | } |
340 | - return add_post_meta( $this->ID(), $meta_key, $meta_value, $unique ); |
|
340 | + return add_post_meta($this->ID(), $meta_key, $meta_value, $unique); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | * @param mixed $meta_value |
350 | 350 | * @return boolean False for failure. True for success. |
351 | 351 | */ |
352 | - public function delete_post_meta( $meta_key, $meta_value = '' ) { |
|
353 | - if ( ! $this->ID() ) { |
|
352 | + public function delete_post_meta($meta_key, $meta_value = '') { |
|
353 | + if ( ! $this->ID()) { |
|
354 | 354 | //there are obviously no postmetas for this if it's not saved |
355 | 355 | //so let's just report this as a success |
356 | 356 | return true; |
357 | 357 | } |
358 | - return delete_post_meta( $this->ID(), $meta_key, $meta_value ); |
|
358 | + return delete_post_meta($this->ID(), $meta_key, $meta_value); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * @return string |
366 | 366 | */ |
367 | 367 | public function get_permalink() { |
368 | - return get_permalink( $this->ID() ); |
|
368 | + return get_permalink($this->ID()); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | |
@@ -375,8 +375,8 @@ discard block |
||
375 | 375 | * @param array $query_params |
376 | 376 | * @return EE_Term_Taxonomy |
377 | 377 | */ |
378 | - public function term_taxonomies( $query_params = array() ) { |
|
379 | - return $this->get_many_related( 'Term_Taxonomy', $query_params ); |
|
378 | + public function term_taxonomies($query_params = array()) { |
|
379 | + return $this->get_many_related('Term_Taxonomy', $query_params); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | public function __sleep() |
407 | 407 | { |
408 | 408 | $properties_to_serialize = parent::__sleep(); |
409 | - $properties_to_serialize = array_diff( $properties_to_serialize, array('_wp_post')); |
|
409 | + $properties_to_serialize = array_diff($properties_to_serialize, array('_wp_post')); |
|
410 | 410 | return $properties_to_serialize; |
411 | 411 | } |
412 | 412 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | use EE_Datetime_Field; |
10 | 10 | |
11 | 11 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
12 | - exit('No direct script access allowed'); |
|
12 | + exit('No direct script access allowed'); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | |
@@ -27,1277 +27,1277 @@ discard block |
||
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @var Calculated_Model_Fields |
|
32 | - */ |
|
33 | - protected $_fields_calculator; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Read constructor. |
|
39 | - */ |
|
40 | - public function __construct() |
|
41 | - { |
|
42 | - parent::__construct(); |
|
43 | - $this->_fields_calculator = new Calculated_Model_Fields(); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
50 | - * |
|
51 | - * @param \WP_REST_Request $request |
|
52 | - * @return \WP_REST_Response|\WP_Error |
|
53 | - */ |
|
54 | - public static function handle_request_get_all(\WP_REST_Request $request) |
|
55 | - { |
|
56 | - $controller = new Read(); |
|
57 | - try { |
|
58 | - $matches = $controller->parse_route( |
|
59 | - $request->get_route(), |
|
60 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
61 | - array('version', 'model') |
|
62 | - ); |
|
63 | - $controller->set_requested_version($matches['version']); |
|
64 | - $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
65 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
66 | - return $controller->send_response( |
|
67 | - new \WP_Error( |
|
68 | - 'endpoint_parsing_error', |
|
69 | - sprintf( |
|
70 | - __('There is no model for endpoint %s. Please contact event espresso support', |
|
71 | - 'event_espresso'), |
|
72 | - $model_name_singular |
|
73 | - ) |
|
74 | - ) |
|
75 | - ); |
|
76 | - } |
|
77 | - return $controller->send_response( |
|
78 | - $controller->get_entities_from_model( |
|
79 | - $controller->get_model_version_info()->load_model($model_name_singular), |
|
80 | - $request |
|
81 | - ) |
|
82 | - ); |
|
83 | - } catch (\Exception $e) { |
|
84 | - return $controller->send_response($e); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Prepares and returns schema for any OPTIONS request. |
|
92 | - * |
|
93 | - * @param string $model_name Something like `Event` or `Registration` |
|
94 | - * @param string $version The API endpoint version being used. |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public static function handle_schema_request($model_name, $version) |
|
98 | - { |
|
99 | - $controller = new Read(); |
|
100 | - try { |
|
101 | - $controller->set_requested_version($version); |
|
102 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name)) { |
|
103 | - return array(); |
|
104 | - } |
|
105 | - //get the model for this version |
|
106 | - $model = $controller->get_model_version_info()->load_model($model_name); |
|
107 | - $model_schema = new JsonModelSchema($model); |
|
108 | - return $model_schema->getModelSchemaForRelations( |
|
109 | - $controller->get_model_version_info()->relation_settings($model), |
|
110 | - $controller->_customize_schema_for_rest_response( |
|
111 | - $model, |
|
112 | - $model_schema->getModelSchemaForFields( |
|
113 | - $controller->get_model_version_info()->fields_on_model_in_this_version($model), |
|
114 | - $model_schema->getInitialSchemaStructure() |
|
115 | - ) |
|
116 | - ) |
|
117 | - ); |
|
118 | - } catch (\Exception $e) { |
|
119 | - return array(); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * This loops through each field in the given schema for the model and does the following: |
|
127 | - * - add any extra fields that are REST API specific and related to existing fields. |
|
128 | - * - transform default values into the correct format for a REST API response. |
|
129 | - * |
|
130 | - * @param \EEM_Base $model |
|
131 | - * @param array $schema |
|
132 | - * @return array The final schema. |
|
133 | - */ |
|
134 | - protected function _customize_schema_for_rest_response(\EEM_Base $model, array $schema) |
|
135 | - { |
|
136 | - foreach ($this->get_model_version_info()->fields_on_model_in_this_version($model) as $field_name => $field) { |
|
137 | - $schema = $this->_translate_defaults_for_rest_response( |
|
138 | - $field_name, |
|
139 | - $field, |
|
140 | - $this->_maybe_add_extra_fields_to_schema($field_name, $field, $schema) |
|
141 | - ); |
|
142 | - } |
|
143 | - return $schema; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * This is used to ensure that the 'default' value set in the schema response is formatted correctly for the REST |
|
150 | - * response. |
|
151 | - * |
|
152 | - * @param $field_name |
|
153 | - * @param \EE_Model_Field_Base $field |
|
154 | - * @param array $schema |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - protected function _translate_defaults_for_rest_response($field_name, \EE_Model_Field_Base $field, array $schema) |
|
158 | - { |
|
159 | - if (isset($schema['properties'][$field_name]['default'])) { |
|
160 | - if (is_array($schema['properties'][$field_name]['default'])) { |
|
161 | - foreach ($schema['properties'][$field_name]['default'] as $default_key => $default_value) { |
|
162 | - if ($default_key === 'raw') { |
|
163 | - $schema['properties'][$field_name]['default'][$default_key] = Model_Data_Translator::prepare_field_value_for_json( |
|
164 | - $field, |
|
165 | - $default_value, |
|
166 | - $this->get_model_version_info()->requested_version() |
|
167 | - ); |
|
168 | - } |
|
169 | - } |
|
170 | - } else { |
|
171 | - $schema['properties'][$field_name]['default'] = Model_Data_Translator::prepare_field_value_for_json( |
|
172 | - $field, |
|
173 | - $schema['properties'][$field_name]['default'], |
|
174 | - $this->get_model_version_info()->requested_version() |
|
175 | - ); |
|
176 | - } |
|
177 | - } |
|
178 | - return $schema; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * Adds additional fields to the schema |
|
185 | - * The REST API returns a GMT value field for each datetime field in the resource. Thus the description about this |
|
186 | - * needs to be added to the schema. |
|
187 | - * |
|
188 | - * @param $field_name |
|
189 | - * @param \EE_Model_Field_Base $field |
|
190 | - * @param array $schema |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - protected function _maybe_add_extra_fields_to_schema($field_name, \EE_Model_Field_Base $field, array $schema) |
|
194 | - { |
|
195 | - if ($field instanceof EE_Datetime_Field) { |
|
196 | - $schema['properties'][$field_name . '_gmt'] = $field->getSchema(); |
|
197 | - //modify the description |
|
198 | - $schema['properties'][$field_name . '_gmt']['description'] = sprintf( |
|
199 | - esc_html__('%s - the value for this field is in GMT.', 'event_espresso'), |
|
200 | - $field->get_nicename() |
|
201 | - ); |
|
202 | - } |
|
203 | - return $schema; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Used to figure out the route from the request when a `WP_REST_Request` object is not available |
|
210 | - * |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - protected function get_route_from_request() |
|
214 | - { |
|
215 | - if (isset($GLOBALS['wp']) |
|
216 | - && $GLOBALS['wp'] instanceof \WP |
|
217 | - && isset($GLOBALS['wp']->query_vars['rest_route']) |
|
218 | - ) { |
|
219 | - return $GLOBALS['wp']->query_vars['rest_route']; |
|
220 | - } else { |
|
221 | - return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/'; |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * Gets a single entity related to the model indicated in the path and its id |
|
229 | - * |
|
230 | - * @param \WP_REST_Request $request |
|
231 | - * @return \WP_REST_Response|\WP_Error |
|
232 | - */ |
|
233 | - public static function handle_request_get_one(\WP_REST_Request $request) |
|
234 | - { |
|
235 | - $controller = new Read(); |
|
236 | - try { |
|
237 | - $matches = $controller->parse_route( |
|
238 | - $request->get_route(), |
|
239 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
240 | - array('version', 'model', 'id')); |
|
241 | - $controller->set_requested_version($matches['version']); |
|
242 | - $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
243 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
244 | - return $controller->send_response( |
|
245 | - new \WP_Error( |
|
246 | - 'endpoint_parsing_error', |
|
247 | - sprintf( |
|
248 | - __('There is no model for endpoint %s. Please contact event espresso support', |
|
249 | - 'event_espresso'), |
|
250 | - $model_name_singular |
|
251 | - ) |
|
252 | - ) |
|
253 | - ); |
|
254 | - } |
|
255 | - return $controller->send_response( |
|
256 | - $controller->get_entity_from_model( |
|
257 | - $controller->get_model_version_info()->load_model($model_name_singular), |
|
258 | - $request |
|
259 | - ) |
|
260 | - ); |
|
261 | - } catch (\Exception $e) { |
|
262 | - return $controller->send_response($e); |
|
263 | - } |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * Gets all the related entities (or if its a belongs-to relation just the one) |
|
270 | - * to the item with the given id |
|
271 | - * |
|
272 | - * @param \WP_REST_Request $request |
|
273 | - * @return \WP_REST_Response|\WP_Error |
|
274 | - */ |
|
275 | - public static function handle_request_get_related(\WP_REST_Request $request) |
|
276 | - { |
|
277 | - $controller = new Read(); |
|
278 | - try { |
|
279 | - $matches = $controller->parse_route( |
|
280 | - $request->get_route(), |
|
281 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
282 | - array('version', 'model', 'id', 'related_model') |
|
283 | - ); |
|
284 | - $controller->set_requested_version($matches['version']); |
|
285 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
286 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
287 | - return $controller->send_response( |
|
288 | - new \WP_Error( |
|
289 | - 'endpoint_parsing_error', |
|
290 | - sprintf( |
|
291 | - __('There is no model for endpoint %s. Please contact event espresso support', |
|
292 | - 'event_espresso'), |
|
293 | - $main_model_name_singular |
|
294 | - ) |
|
295 | - ) |
|
296 | - ); |
|
297 | - } |
|
298 | - $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
299 | - //assume the related model name is plural and try to find the model's name |
|
300 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
301 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
302 | - //so the word didn't singularize well. Maybe that's just because it's a singular word? |
|
303 | - $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
304 | - } |
|
305 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
306 | - return $controller->send_response( |
|
307 | - new \WP_Error( |
|
308 | - 'endpoint_parsing_error', |
|
309 | - sprintf( |
|
310 | - __('There is no model for endpoint %s. Please contact event espresso support', |
|
311 | - 'event_espresso'), |
|
312 | - $related_model_name_singular |
|
313 | - ) |
|
314 | - ) |
|
315 | - ); |
|
316 | - } |
|
317 | - return $controller->send_response( |
|
318 | - $controller->get_entities_from_relation( |
|
319 | - $request->get_param('id'), |
|
320 | - $main_model->related_settings_for($related_model_name_singular), |
|
321 | - $request |
|
322 | - ) |
|
323 | - ); |
|
324 | - } catch (\Exception $e) { |
|
325 | - return $controller->send_response($e); |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * Gets a collection for the given model and filters |
|
333 | - * |
|
334 | - * @param \EEM_Base $model |
|
335 | - * @param \WP_REST_Request $request |
|
336 | - * @return array|\WP_Error |
|
337 | - */ |
|
338 | - public function get_entities_from_model($model, $request) |
|
339 | - { |
|
340 | - $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
341 | - if (! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
342 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
343 | - return new \WP_Error( |
|
344 | - sprintf('rest_%s_cannot_list', $model_name_plural), |
|
345 | - sprintf( |
|
346 | - __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
347 | - $model_name_plural, |
|
348 | - Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
349 | - ), |
|
350 | - array('status' => 403) |
|
351 | - ); |
|
352 | - } |
|
353 | - if (! $request->get_header('no_rest_headers')) { |
|
354 | - $this->_set_headers_from_query_params($model, $query_params); |
|
355 | - } |
|
356 | - /** @type array $results */ |
|
357 | - $results = $model->get_all_wpdb_results($query_params); |
|
358 | - $nice_results = array(); |
|
359 | - foreach ($results as $result) { |
|
360 | - $nice_results[] = $this->create_entity_from_wpdb_result( |
|
361 | - $model, |
|
362 | - $result, |
|
363 | - $request |
|
364 | - ); |
|
365 | - } |
|
366 | - return $nice_results; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * @param array $primary_model_query_params query params for finding the item from which |
|
373 | - * relations will be based |
|
374 | - * @param \EE_Model_Relation_Base $relation |
|
375 | - * @param \WP_REST_Request $request |
|
376 | - * @return \WP_Error|array |
|
377 | - */ |
|
378 | - protected function _get_entities_from_relation($primary_model_query_params, $relation, $request) |
|
379 | - { |
|
380 | - $context = $this->validate_context($request->get_param('caps')); |
|
381 | - $model = $relation->get_this_model(); |
|
382 | - $related_model = $relation->get_other_model(); |
|
383 | - if (! isset($primary_model_query_params[0])) { |
|
384 | - $primary_model_query_params[0] = array(); |
|
385 | - } |
|
386 | - //check if they can access the 1st model object |
|
387 | - $primary_model_query_params = array( |
|
388 | - 0 => $primary_model_query_params[0], |
|
389 | - 'limit' => 1, |
|
390 | - ); |
|
391 | - if ($model instanceof \EEM_Soft_Delete_Base) { |
|
392 | - $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($primary_model_query_params); |
|
393 | - } |
|
394 | - $restricted_query_params = $primary_model_query_params; |
|
395 | - $restricted_query_params['caps'] = $context; |
|
396 | - $this->_set_debug_info('main model query params', $restricted_query_params); |
|
397 | - $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
398 | - if ( |
|
399 | - ! ( |
|
400 | - Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
401 | - && $model->exists($restricted_query_params) |
|
402 | - ) |
|
403 | - ) { |
|
404 | - if ($relation instanceof \EE_Belongs_To_Relation) { |
|
405 | - $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
406 | - } else { |
|
407 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
408 | - } |
|
409 | - return new \WP_Error( |
|
410 | - sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
411 | - sprintf( |
|
412 | - __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', |
|
413 | - 'event_espresso'), |
|
414 | - $related_model_name_maybe_plural, |
|
415 | - $relation->get_this_model()->get_this_model_name(), |
|
416 | - implode( |
|
417 | - ',', |
|
418 | - array_keys( |
|
419 | - Capabilities::get_missing_permissions($related_model, $context) |
|
420 | - ) |
|
421 | - ) |
|
422 | - ), |
|
423 | - array('status' => 403) |
|
424 | - ); |
|
425 | - } |
|
426 | - $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
427 | - foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) { |
|
428 | - $query_params[0][$relation->get_this_model()->get_this_model_name() |
|
429 | - . '.' |
|
430 | - . $where_condition_key] = $where_condition_value; |
|
431 | - } |
|
432 | - $query_params['default_where_conditions'] = 'none'; |
|
433 | - $query_params['caps'] = $context; |
|
434 | - if (! $request->get_header('no_rest_headers')) { |
|
435 | - $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
436 | - } |
|
437 | - /** @type array $results */ |
|
438 | - $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
439 | - $nice_results = array(); |
|
440 | - foreach ($results as $result) { |
|
441 | - $nice_result = $this->create_entity_from_wpdb_result( |
|
442 | - $relation->get_other_model(), |
|
443 | - $result, |
|
444 | - $request |
|
445 | - ); |
|
446 | - if ($relation instanceof \EE_HABTM_Relation) { |
|
447 | - //put the unusual stuff (properties from the HABTM relation) first, and make sure |
|
448 | - //if there are conflicts we prefer the properties from the main model |
|
449 | - $join_model_result = $this->create_entity_from_wpdb_result( |
|
450 | - $relation->get_join_model(), |
|
451 | - $result, |
|
452 | - $request |
|
453 | - ); |
|
454 | - $joined_result = array_merge($nice_result, $join_model_result); |
|
455 | - //but keep the meta stuff from the main model |
|
456 | - if (isset($nice_result['meta'])) { |
|
457 | - $joined_result['meta'] = $nice_result['meta']; |
|
458 | - } |
|
459 | - $nice_result = $joined_result; |
|
460 | - } |
|
461 | - $nice_results[] = $nice_result; |
|
462 | - } |
|
463 | - if ($relation instanceof \EE_Belongs_To_Relation) { |
|
464 | - return array_shift($nice_results); |
|
465 | - } else { |
|
466 | - return $nice_results; |
|
467 | - } |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * Gets the collection for given relation object |
|
474 | - * The same as Read::get_entities_from_model(), except if the relation |
|
475 | - * is a HABTM relation, in which case it merges any non-foreign-key fields from |
|
476 | - * the join-model-object into the results |
|
477 | - * |
|
478 | - * @param string $id the ID of the thing we are fetching related stuff from |
|
479 | - * @param \EE_Model_Relation_Base $relation |
|
480 | - * @param \WP_REST_Request $request |
|
481 | - * @return array|\WP_Error |
|
482 | - * @throws \EE_Error |
|
483 | - */ |
|
484 | - public function get_entities_from_relation($id, $relation, $request) |
|
485 | - { |
|
486 | - if (! $relation->get_this_model()->has_primary_key_field()) { |
|
487 | - throw new \EE_Error( |
|
488 | - sprintf( |
|
489 | - __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', |
|
490 | - 'event_espresso'), |
|
491 | - $relation->get_this_model()->get_this_model_name() |
|
492 | - ) |
|
493 | - ); |
|
494 | - } |
|
495 | - return $this->_get_entities_from_relation( |
|
496 | - array( |
|
497 | - array( |
|
498 | - $relation->get_this_model()->primary_key_name() => $id, |
|
499 | - ), |
|
500 | - ), |
|
501 | - $relation, |
|
502 | - $request |
|
503 | - ); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - |
|
508 | - /** |
|
509 | - * Sets the headers that are based on the model and query params, |
|
510 | - * like the total records. This should only be called on the original request |
|
511 | - * from the client, not on subsequent internal |
|
512 | - * |
|
513 | - * @param \EEM_Base $model |
|
514 | - * @param array $query_params |
|
515 | - * @return void |
|
516 | - */ |
|
517 | - protected function _set_headers_from_query_params($model, $query_params) |
|
518 | - { |
|
519 | - $this->_set_debug_info('model query params', $query_params); |
|
520 | - $this->_set_debug_info('missing caps', |
|
521 | - Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
522 | - //normally the limit to a 2-part array, where the 2nd item is the limit |
|
523 | - if (! isset($query_params['limit'])) { |
|
524 | - $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
525 | - } |
|
526 | - if (is_array($query_params['limit'])) { |
|
527 | - $limit_parts = $query_params['limit']; |
|
528 | - } else { |
|
529 | - $limit_parts = explode(',', $query_params['limit']); |
|
530 | - if (count($limit_parts) == 1) { |
|
531 | - $limit_parts = array(0, $limit_parts[0]); |
|
532 | - } |
|
533 | - } |
|
534 | - //remove the group by and having parts of the query, as those will |
|
535 | - //make the sql query return an array of values, instead of just a single value |
|
536 | - unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
537 | - $count = $model->count($query_params, null, true); |
|
538 | - $pages = $count / $limit_parts[1]; |
|
539 | - $this->_set_response_header('Total', $count, false); |
|
540 | - $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
541 | - $this->_set_response_header('TotalPages', ceil($pages), false); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * Changes database results into REST API entities |
|
548 | - * |
|
549 | - * @param \EEM_Base $model |
|
550 | - * @param array $db_row like results from $wpdb->get_results() |
|
551 | - * @param \WP_REST_Request $rest_request |
|
552 | - * @param string $deprecated no longer used |
|
553 | - * @return array ready for being converted into json for sending to client |
|
554 | - */ |
|
555 | - public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) |
|
556 | - { |
|
557 | - if (! $rest_request instanceof \WP_REST_Request) { |
|
558 | - //ok so this was called in the old style, where the 3rd arg was |
|
559 | - //$include, and the 4th arg was $context |
|
560 | - //now setup the request just to avoid fatal errors, although we won't be able |
|
561 | - //to truly make use of it because it's kinda devoid of info |
|
562 | - $rest_request = new \WP_REST_Request(); |
|
563 | - $rest_request->set_param('include', $rest_request); |
|
564 | - $rest_request->set_param('caps', $deprecated); |
|
565 | - } |
|
566 | - if ($rest_request->get_param('caps') == null) { |
|
567 | - $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
568 | - } |
|
569 | - $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
570 | - $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
571 | - $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
572 | - $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
573 | - $entity_array = apply_filters('FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models', |
|
574 | - $entity_array, $model, $rest_request->get_param('caps'), $rest_request, $this); |
|
575 | - $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array, $db_row); |
|
576 | - $entity_array = apply_filters( |
|
577 | - 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
|
578 | - $entity_array, |
|
579 | - $model, |
|
580 | - $rest_request->get_param('caps'), |
|
581 | - $rest_request, |
|
582 | - $this |
|
583 | - ); |
|
584 | - $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
|
585 | - $entity_array, |
|
586 | - $model, |
|
587 | - $rest_request->get_param('caps'), |
|
588 | - $this->get_model_version_info(), |
|
589 | - $model->get_index_primary_key_string( |
|
590 | - $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
591 | - ) |
|
592 | - ); |
|
593 | - $this->_set_debug_info( |
|
594 | - 'inaccessible fields', |
|
595 | - array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
596 | - ); |
|
597 | - return apply_filters( |
|
598 | - 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
|
599 | - $result_without_inaccessible_fields, |
|
600 | - $model, |
|
601 | - $rest_request->get_param('caps') |
|
602 | - ); |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * Creates a REST entity array (JSON object we're going to return in the response, but |
|
609 | - * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry), |
|
610 | - * from $wpdb->get_row( $sql, ARRAY_A) |
|
611 | - * |
|
612 | - * @param \EEM_Base $model |
|
613 | - * @param array $db_row |
|
614 | - * @return array entity mostly ready for converting to JSON and sending in the response |
|
615 | - */ |
|
616 | - protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) |
|
617 | - { |
|
618 | - $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
619 | - $result = array_intersect_key($result, |
|
620 | - $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
621 | - //if this is a CPT, we need to set the global $post to it, |
|
622 | - //otherwise shortcodes etc won't work properly while rendering it |
|
623 | - if ($model instanceof \EEM_CPT_Base) { |
|
624 | - $do_chevy_shuffle = true; |
|
625 | - } else { |
|
626 | - $do_chevy_shuffle = false; |
|
627 | - } |
|
628 | - if ($do_chevy_shuffle) { |
|
629 | - global $post; |
|
630 | - $old_post = $post; |
|
631 | - $post = get_post($result[$model->primary_key_name()]); |
|
632 | - if (! $post instanceof \WP_Post) { |
|
633 | - //well that's weird, because $result is what we JUST fetched from the database |
|
634 | - throw new Rest_Exception( |
|
635 | - 'error_fetching_post_from_database_results', |
|
636 | - esc_html__( |
|
637 | - 'An item was retrieved from the database but it\'s not a WP_Post like it should be.', |
|
638 | - 'event_espresso' |
|
639 | - ) |
|
640 | - ); |
|
641 | - } |
|
642 | - $model_object_classname = 'EE_' . $model->get_this_model_name(); |
|
643 | - $post->{$model_object_classname} = \EE_Registry::instance()->load_class( |
|
644 | - $model_object_classname, |
|
645 | - $result, |
|
646 | - false, |
|
647 | - false |
|
648 | - ); |
|
649 | - } |
|
650 | - foreach ($result as $field_name => $raw_field_value) { |
|
651 | - $field_obj = $model->field_settings_for($field_name); |
|
652 | - $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
653 | - if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
654 | - unset($result[$field_name]); |
|
655 | - } elseif ( |
|
656 | - $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
657 | - ) { |
|
658 | - $result[$field_name] = array( |
|
659 | - 'raw' => $field_obj->prepare_for_get($field_value), |
|
660 | - 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value), |
|
661 | - ); |
|
662 | - } elseif ( |
|
663 | - $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
664 | - ) { |
|
665 | - $result[$field_name] = array( |
|
666 | - 'raw' => $field_obj->prepare_for_get($field_value), |
|
667 | - 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value), |
|
668 | - ); |
|
669 | - } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
670 | - if ($field_value instanceof \DateTime) { |
|
671 | - $timezone = $field_value->getTimezone(); |
|
672 | - $field_value->setTimezone(new \DateTimeZone('UTC')); |
|
673 | - $result[$field_name . '_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
674 | - $field_obj, |
|
675 | - $field_value, |
|
676 | - $this->get_model_version_info()->requested_version() |
|
677 | - ); |
|
678 | - $field_value->setTimezone($timezone); |
|
679 | - $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
680 | - $field_obj, |
|
681 | - $field_value, |
|
682 | - $this->get_model_version_info()->requested_version() |
|
683 | - ); |
|
684 | - } |
|
685 | - } else { |
|
686 | - $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
687 | - $field_obj, |
|
688 | - $field_obj->prepare_for_get($field_value), |
|
689 | - $this->get_model_version_info()->requested_version() |
|
690 | - ); |
|
691 | - } |
|
692 | - } |
|
693 | - if ($do_chevy_shuffle) { |
|
694 | - $post = $old_post; |
|
695 | - } |
|
696 | - return $result; |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * Adds a few extra fields to the entity response |
|
703 | - * |
|
704 | - * @param \EEM_Base $model |
|
705 | - * @param array $db_row |
|
706 | - * @param array $entity_array |
|
707 | - * @return array modified entity |
|
708 | - */ |
|
709 | - protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) |
|
710 | - { |
|
711 | - if ($model instanceof \EEM_CPT_Base) { |
|
712 | - $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
713 | - } |
|
714 | - return $entity_array; |
|
715 | - } |
|
716 | - |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * Gets links we want to add to the response |
|
721 | - * |
|
722 | - * @global \WP_REST_Server $wp_rest_server |
|
723 | - * @param \EEM_Base $model |
|
724 | - * @param array $db_row |
|
725 | - * @param array $entity_array |
|
726 | - * @return array the _links item in the entity |
|
727 | - */ |
|
728 | - protected function _get_entity_links($model, $db_row, $entity_array) |
|
729 | - { |
|
730 | - //add basic links |
|
731 | - $links = array(); |
|
732 | - if ($model->has_primary_key_field()) { |
|
733 | - $links['self'] = array( |
|
734 | - array( |
|
735 | - 'href' => $this->get_versioned_link_to( |
|
736 | - \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
737 | - . '/' |
|
738 | - . $entity_array[$model->primary_key_name()] |
|
739 | - ), |
|
740 | - ), |
|
741 | - ); |
|
742 | - } |
|
743 | - $links['collection'] = array( |
|
744 | - array( |
|
745 | - 'href' => $this->get_versioned_link_to( |
|
746 | - \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
747 | - ), |
|
748 | - ), |
|
749 | - ); |
|
750 | - //add links to related models |
|
751 | - if ($model->has_primary_key_field()) { |
|
752 | - foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
753 | - $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
754 | - $links[\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array( |
|
755 | - array( |
|
756 | - 'href' => $this->get_versioned_link_to( |
|
757 | - \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
758 | - . '/' |
|
759 | - . $entity_array[$model->primary_key_name()] |
|
760 | - . '/' |
|
761 | - . $related_model_part |
|
762 | - ), |
|
763 | - 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
|
764 | - ), |
|
765 | - ); |
|
766 | - } |
|
767 | - } |
|
768 | - return $links; |
|
769 | - } |
|
770 | - |
|
771 | - |
|
772 | - |
|
773 | - /** |
|
774 | - * Adds the included models indicated in the request to the entity provided |
|
775 | - * |
|
776 | - * @param \EEM_Base $model |
|
777 | - * @param \WP_REST_Request $rest_request |
|
778 | - * @param array $entity_array |
|
779 | - * @param array $db_row |
|
780 | - * @return array the modified entity |
|
781 | - */ |
|
782 | - protected function _include_requested_models( |
|
783 | - \EEM_Base $model, |
|
784 | - \WP_REST_Request $rest_request, |
|
785 | - $entity_array, |
|
786 | - $db_row = array() |
|
787 | - ) { |
|
788 | - //if $db_row not included, hope the entity array has what we need |
|
789 | - if (! $db_row) { |
|
790 | - $db_row = $entity_array; |
|
791 | - } |
|
792 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
793 | - $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
794 | - //if they passed in * or didn't specify any includes, return everything |
|
795 | - if (! in_array('*', $includes_for_this_model) |
|
796 | - && ! empty($includes_for_this_model) |
|
797 | - ) { |
|
798 | - if ($model->has_primary_key_field()) { |
|
799 | - //always include the primary key. ya just gotta know that at least |
|
800 | - $includes_for_this_model[] = $model->primary_key_name(); |
|
801 | - } |
|
802 | - if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
803 | - $includes_for_this_model[] = '_calculated_fields'; |
|
804 | - } |
|
805 | - $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
806 | - } |
|
807 | - $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
808 | - foreach ($relation_settings as $relation_name => $relation_obj) { |
|
809 | - $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
|
810 | - $rest_request->get_param('include'), |
|
811 | - $relation_name |
|
812 | - ); |
|
813 | - $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
|
814 | - $rest_request->get_param('calculate'), |
|
815 | - $relation_name |
|
816 | - ); |
|
817 | - //did they specify they wanted to include a related model, or |
|
818 | - //specific fields from a related model? |
|
819 | - //or did they specify to calculate a field from a related model? |
|
820 | - if ($related_fields_to_include || $related_fields_to_calculate) { |
|
821 | - //if so, we should include at least some part of the related model |
|
822 | - $pretend_related_request = new \WP_REST_Request(); |
|
823 | - $pretend_related_request->set_query_params( |
|
824 | - array( |
|
825 | - 'caps' => $rest_request->get_param('caps'), |
|
826 | - 'include' => $related_fields_to_include, |
|
827 | - 'calculate' => $related_fields_to_calculate, |
|
828 | - ) |
|
829 | - ); |
|
830 | - $pretend_related_request->add_header('no_rest_headers', true); |
|
831 | - $primary_model_query_params = $model->alter_query_params_to_restrict_by_ID( |
|
832 | - $model->get_index_primary_key_string( |
|
833 | - $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
834 | - ) |
|
835 | - ); |
|
836 | - $related_results = $this->_get_entities_from_relation( |
|
837 | - $primary_model_query_params, |
|
838 | - $relation_obj, |
|
839 | - $pretend_related_request |
|
840 | - ); |
|
841 | - $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results |
|
842 | - instanceof |
|
843 | - \WP_Error |
|
844 | - ? null |
|
845 | - : $related_results; |
|
846 | - } |
|
847 | - } |
|
848 | - return $entity_array; |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * Returns a new array with all the names of models removed. Eg |
|
855 | - * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' ) |
|
856 | - * |
|
857 | - * @param array $arr |
|
858 | - * @return array |
|
859 | - */ |
|
860 | - private function _remove_model_names_from_array($arr) |
|
861 | - { |
|
862 | - return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
863 | - } |
|
864 | - |
|
865 | - |
|
866 | - |
|
867 | - /** |
|
868 | - * Gets the calculated fields for the response |
|
869 | - * |
|
870 | - * @param \EEM_Base $model |
|
871 | - * @param array $wpdb_row |
|
872 | - * @param \WP_REST_Request $rest_request |
|
873 | - * @return \stdClass the _calculations item in the entity |
|
874 | - */ |
|
875 | - protected function _get_entity_calculations($model, $wpdb_row, $rest_request) |
|
876 | - { |
|
877 | - $calculated_fields = $this->explode_and_get_items_prefixed_with( |
|
878 | - $rest_request->get_param('calculate'), |
|
879 | - '' |
|
880 | - ); |
|
881 | - //note: setting calculate=* doesn't do anything |
|
882 | - $calculated_fields_to_return = new \stdClass(); |
|
883 | - foreach ($calculated_fields as $field_to_calculate) { |
|
884 | - try { |
|
885 | - $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
|
886 | - null, |
|
887 | - $this->_fields_calculator->retrieve_calculated_field_value( |
|
888 | - $model, |
|
889 | - $field_to_calculate, |
|
890 | - $wpdb_row, |
|
891 | - $rest_request, |
|
892 | - $this |
|
893 | - ), |
|
894 | - $this->get_model_version_info()->requested_version() |
|
895 | - ); |
|
896 | - } catch (Rest_Exception $e) { |
|
897 | - //if we don't have permission to read it, just leave it out. but let devs know about the problem |
|
898 | - $this->_set_response_header( |
|
899 | - 'Notices-Field-Calculation-Errors[' |
|
900 | - . $e->get_string_code() |
|
901 | - . '][' |
|
902 | - . $model->get_this_model_name() |
|
903 | - . '][' |
|
904 | - . $field_to_calculate |
|
905 | - . ']', |
|
906 | - $e->getMessage(), |
|
907 | - true |
|
908 | - ); |
|
909 | - } |
|
910 | - } |
|
911 | - return $calculated_fields_to_return; |
|
912 | - } |
|
913 | - |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * Gets the full URL to the resource, taking the requested version into account |
|
918 | - * |
|
919 | - * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
|
920 | - * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
|
921 | - */ |
|
922 | - public function get_versioned_link_to($link_part_after_version_and_slash) |
|
923 | - { |
|
924 | - return rest_url( |
|
925 | - \EED_Core_Rest_Api::ee_api_namespace |
|
926 | - . $this->get_model_version_info()->requested_version() |
|
927 | - . '/' |
|
928 | - . $link_part_after_version_and_slash |
|
929 | - ); |
|
930 | - } |
|
931 | - |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * Gets the correct lowercase name for the relation in the API according |
|
936 | - * to the relation's type |
|
937 | - * |
|
938 | - * @param string $relation_name |
|
939 | - * @param \EE_Model_Relation_Base $relation_obj |
|
940 | - * @return string |
|
941 | - */ |
|
942 | - public static function get_related_entity_name($relation_name, $relation_obj) |
|
943 | - { |
|
944 | - if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
945 | - return strtolower($relation_name); |
|
946 | - } else { |
|
947 | - return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
948 | - } |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * Gets the one model object with the specified id for the specified model |
|
955 | - * |
|
956 | - * @param \EEM_Base $model |
|
957 | - * @param \WP_REST_Request $request |
|
958 | - * @return array|\WP_Error |
|
959 | - */ |
|
960 | - public function get_entity_from_model($model, $request) |
|
961 | - { |
|
962 | - $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
963 | - if ($model instanceof \EEM_Soft_Delete_Base) { |
|
964 | - $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
965 | - } |
|
966 | - $restricted_query_params = $query_params; |
|
967 | - $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
968 | - $this->_set_debug_info('model query params', $restricted_query_params); |
|
969 | - $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
970 | - if (! empty ($model_rows)) { |
|
971 | - return $this->create_entity_from_wpdb_result( |
|
972 | - $model, |
|
973 | - array_shift($model_rows), |
|
974 | - $request); |
|
975 | - } else { |
|
976 | - //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
|
977 | - $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
978 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
979 | - if (! empty($model_rows_found_sans_restrictions)) { |
|
980 | - //you got shafted- it existed but we didn't want to tell you! |
|
981 | - return new \WP_Error( |
|
982 | - 'rest_user_cannot_read', |
|
983 | - sprintf( |
|
984 | - __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
985 | - strtolower($model->get_this_model_name()), |
|
986 | - Capabilities::get_missing_permissions_string( |
|
987 | - $model, |
|
988 | - $this->validate_context($request->get_param('caps'))) |
|
989 | - ), |
|
990 | - array('status' => 403) |
|
991 | - ); |
|
992 | - } else { |
|
993 | - //it's not you. It just doesn't exist |
|
994 | - return new \WP_Error( |
|
995 | - sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
996 | - sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
997 | - array('status' => 404) |
|
998 | - ); |
|
999 | - } |
|
1000 | - } |
|
1001 | - } |
|
1002 | - |
|
1003 | - |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * If a context is provided which isn't valid, maybe it was added in a future |
|
1007 | - * version so just treat it as a default read |
|
1008 | - * |
|
1009 | - * @param string $context |
|
1010 | - * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
|
1011 | - */ |
|
1012 | - public function validate_context($context) |
|
1013 | - { |
|
1014 | - if (! $context) { |
|
1015 | - $context = \EEM_Base::caps_read; |
|
1016 | - } |
|
1017 | - $valid_contexts = \EEM_Base::valid_cap_contexts(); |
|
1018 | - if (in_array($context, $valid_contexts)) { |
|
1019 | - return $context; |
|
1020 | - } else { |
|
1021 | - return \EEM_Base::caps_read; |
|
1022 | - } |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * Verifies the passed in value is an allowable default where conditions value. |
|
1029 | - * |
|
1030 | - * @param $default_query_params |
|
1031 | - * @return string |
|
1032 | - */ |
|
1033 | - public function validate_default_query_params($default_query_params) |
|
1034 | - { |
|
1035 | - $valid_default_where_conditions_for_api_calls = array( |
|
1036 | - \EEM_Base::default_where_conditions_all, |
|
1037 | - \EEM_Base::default_where_conditions_minimum_all, |
|
1038 | - \EEM_Base::default_where_conditions_minimum_others, |
|
1039 | - ); |
|
1040 | - if (! $default_query_params) { |
|
1041 | - $default_query_params = \EEM_Base::default_where_conditions_all; |
|
1042 | - } |
|
1043 | - if ( |
|
1044 | - in_array( |
|
1045 | - $default_query_params, |
|
1046 | - $valid_default_where_conditions_for_api_calls, |
|
1047 | - true |
|
1048 | - ) |
|
1049 | - ) { |
|
1050 | - return $default_query_params; |
|
1051 | - } else { |
|
1052 | - return \EEM_Base::default_where_conditions_all; |
|
1053 | - } |
|
1054 | - } |
|
1055 | - |
|
1056 | - |
|
1057 | - |
|
1058 | - /** |
|
1059 | - * Translates API filter get parameter into $query_params array used by EEM_Base::get_all(). |
|
1060 | - * Note: right now the query parameter keys for fields (and related fields) |
|
1061 | - * can be left as-is, but it's quite possible this will change someday. |
|
1062 | - * Also, this method's contents might be candidate for moving to Model_Data_Translator |
|
1063 | - * |
|
1064 | - * @param \EEM_Base $model |
|
1065 | - * @param array $query_parameters from $_GET parameter @see Read:handle_request_get_all |
|
1066 | - * @return array like what EEM_Base::get_all() expects or FALSE to indicate |
|
1067 | - * that absolutely no results should be returned |
|
1068 | - * @throws \EE_Error |
|
1069 | - */ |
|
1070 | - public function create_model_query_params($model, $query_parameters) |
|
1071 | - { |
|
1072 | - $model_query_params = array(); |
|
1073 | - if (isset($query_parameters['where'])) { |
|
1074 | - $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
1075 | - $query_parameters['where'], |
|
1076 | - $model, |
|
1077 | - $this->get_model_version_info()->requested_version() |
|
1078 | - ); |
|
1079 | - } |
|
1080 | - if (isset($query_parameters['order_by'])) { |
|
1081 | - $order_by = $query_parameters['order_by']; |
|
1082 | - } elseif (isset($query_parameters['orderby'])) { |
|
1083 | - $order_by = $query_parameters['orderby']; |
|
1084 | - } else { |
|
1085 | - $order_by = null; |
|
1086 | - } |
|
1087 | - if ($order_by !== null) { |
|
1088 | - if (is_array($order_by)) { |
|
1089 | - $order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json($order_by); |
|
1090 | - } else { |
|
1091 | - //it's a single item |
|
1092 | - $order_by = Model_Data_Translator::prepare_field_name_from_json($order_by); |
|
1093 | - } |
|
1094 | - $model_query_params['order_by'] = $order_by; |
|
1095 | - } |
|
1096 | - if (isset($query_parameters['group_by'])) { |
|
1097 | - $group_by = $query_parameters['group_by']; |
|
1098 | - } elseif (isset($query_parameters['groupby'])) { |
|
1099 | - $group_by = $query_parameters['groupby']; |
|
1100 | - } else { |
|
1101 | - $group_by = array_keys($model->get_combined_primary_key_fields()); |
|
1102 | - } |
|
1103 | - //make sure they're all real names |
|
1104 | - if (is_array($group_by)) { |
|
1105 | - $group_by = Model_Data_Translator::prepare_field_names_from_json($group_by); |
|
1106 | - } |
|
1107 | - if ($group_by !== null) { |
|
1108 | - $model_query_params['group_by'] = $group_by; |
|
1109 | - } |
|
1110 | - if (isset($query_parameters['having'])) { |
|
1111 | - $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
1112 | - $query_parameters['having'], |
|
1113 | - $model, |
|
1114 | - $this->get_model_version_info()->requested_version() |
|
1115 | - ); |
|
1116 | - } |
|
1117 | - if (isset($query_parameters['order'])) { |
|
1118 | - $model_query_params['order'] = $query_parameters['order']; |
|
1119 | - } |
|
1120 | - if (isset($query_parameters['mine'])) { |
|
1121 | - $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
1122 | - } |
|
1123 | - if (isset($query_parameters['limit'])) { |
|
1124 | - //limit should be either a string like '23' or '23,43', or an array with two items in it |
|
1125 | - if (! is_array($query_parameters['limit'])) { |
|
1126 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
1127 | - } else { |
|
1128 | - $limit_array = $query_parameters['limit']; |
|
1129 | - } |
|
1130 | - $sanitized_limit = array(); |
|
1131 | - foreach ($limit_array as $key => $limit_part) { |
|
1132 | - if ($this->_debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
1133 | - throw new \EE_Error( |
|
1134 | - sprintf( |
|
1135 | - __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', |
|
1136 | - 'event_espresso'), |
|
1137 | - wp_json_encode($query_parameters['limit']) |
|
1138 | - ) |
|
1139 | - ); |
|
1140 | - } |
|
1141 | - $sanitized_limit[] = (int)$limit_part; |
|
1142 | - } |
|
1143 | - $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
1144 | - } else { |
|
1145 | - $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
1146 | - } |
|
1147 | - if (isset($query_parameters['caps'])) { |
|
1148 | - $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
1149 | - } else { |
|
1150 | - $model_query_params['caps'] = \EEM_Base::caps_read; |
|
1151 | - } |
|
1152 | - if (isset($query_parameters['default_where_conditions'])) { |
|
1153 | - $model_query_params['default_where_conditions'] = $this->validate_default_query_params($query_parameters['default_where_conditions']); |
|
1154 | - } |
|
1155 | - return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
1156 | - } |
|
1157 | - |
|
1158 | - |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * Changes the REST-style query params for use in the models |
|
1162 | - * |
|
1163 | - * @deprecated |
|
1164 | - * @param \EEM_Base $model |
|
1165 | - * @param array $query_params sub-array from @see EEM_Base::get_all() |
|
1166 | - * @return array |
|
1167 | - */ |
|
1168 | - public function prepare_rest_query_params_key_for_models($model, $query_params) |
|
1169 | - { |
|
1170 | - $model_ready_query_params = array(); |
|
1171 | - foreach ($query_params as $key => $value) { |
|
1172 | - if (is_array($value)) { |
|
1173 | - $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
1174 | - } else { |
|
1175 | - $model_ready_query_params[$key] = $value; |
|
1176 | - } |
|
1177 | - } |
|
1178 | - return $model_ready_query_params; |
|
1179 | - } |
|
1180 | - |
|
1181 | - |
|
1182 | - |
|
1183 | - /** |
|
1184 | - * @deprecated |
|
1185 | - * @param $model |
|
1186 | - * @param $query_params |
|
1187 | - * @return array |
|
1188 | - */ |
|
1189 | - public function prepare_rest_query_params_values_for_models($model, $query_params) |
|
1190 | - { |
|
1191 | - $model_ready_query_params = array(); |
|
1192 | - foreach ($query_params as $key => $value) { |
|
1193 | - if (is_array($value)) { |
|
1194 | - $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
1195 | - } else { |
|
1196 | - $model_ready_query_params[$key] = $value; |
|
1197 | - } |
|
1198 | - } |
|
1199 | - return $model_ready_query_params; |
|
1200 | - } |
|
1201 | - |
|
1202 | - |
|
1203 | - |
|
1204 | - /** |
|
1205 | - * Explodes the string on commas, and only returns items with $prefix followed by a period. |
|
1206 | - * If no prefix is specified, returns items with no period. |
|
1207 | - * |
|
1208 | - * @param string|array $string_to_explode eg "jibba,jabba, blah, blaabla" or array('jibba', 'jabba' ) |
|
1209 | - * @param string $prefix "Event" or "foobar" |
|
1210 | - * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified |
|
1211 | - * we only return strings starting with that and a period; if no prefix was |
|
1212 | - * specified we return all items containing NO periods |
|
1213 | - */ |
|
1214 | - public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) |
|
1215 | - { |
|
1216 | - if (is_string($string_to_explode)) { |
|
1217 | - $exploded_contents = explode(',', $string_to_explode); |
|
1218 | - } else if (is_array($string_to_explode)) { |
|
1219 | - $exploded_contents = $string_to_explode; |
|
1220 | - } else { |
|
1221 | - $exploded_contents = array(); |
|
1222 | - } |
|
1223 | - //if the string was empty, we want an empty array |
|
1224 | - $exploded_contents = array_filter($exploded_contents); |
|
1225 | - $contents_with_prefix = array(); |
|
1226 | - foreach ($exploded_contents as $item) { |
|
1227 | - $item = trim($item); |
|
1228 | - //if no prefix was provided, so we look for items with no "." in them |
|
1229 | - if (! $prefix) { |
|
1230 | - //does this item have a period? |
|
1231 | - if (strpos($item, '.') === false) { |
|
1232 | - //if not, then its what we're looking for |
|
1233 | - $contents_with_prefix[] = $item; |
|
1234 | - } |
|
1235 | - } else if (strpos($item, $prefix . '.') === 0) { |
|
1236 | - //this item has the prefix and a period, grab it |
|
1237 | - $contents_with_prefix[] = substr( |
|
1238 | - $item, |
|
1239 | - strpos($item, $prefix . '.') + strlen($prefix . '.') |
|
1240 | - ); |
|
1241 | - } else if ($item === $prefix) { |
|
1242 | - //this item is JUST the prefix |
|
1243 | - //so let's grab everything after, which is a blank string |
|
1244 | - $contents_with_prefix[] = ''; |
|
1245 | - } |
|
1246 | - } |
|
1247 | - return $contents_with_prefix; |
|
1248 | - } |
|
1249 | - |
|
1250 | - |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with. |
|
1254 | - * Deprecated because its return values were really quite confusing- sometimes it returned |
|
1255 | - * an empty array (when the include string was blank or '*') or sometimes it returned |
|
1256 | - * array('*') (when you provided a model and a model of that kind was found). |
|
1257 | - * Parses the $include_string so we fetch all the field names relating to THIS model |
|
1258 | - * (ie have NO period in them), or for the provided model (ie start with the model |
|
1259 | - * name and then a period). |
|
1260 | - * @param string $include_string @see Read:handle_request_get_all |
|
1261 | - * @param string $model_name |
|
1262 | - * @return array of fields for this model. If $model_name is provided, then |
|
1263 | - * the fields for that model, with the model's name removed from each. |
|
1264 | - * If $include_string was blank or '*' returns an empty array |
|
1265 | - */ |
|
1266 | - public function extract_includes_for_this_model($include_string, $model_name = null) |
|
1267 | - { |
|
1268 | - if (is_array($include_string)) { |
|
1269 | - $include_string = implode(',', $include_string); |
|
1270 | - } |
|
1271 | - if ($include_string === '*' || $include_string === '') { |
|
1272 | - return array(); |
|
1273 | - } |
|
1274 | - $includes = explode(',', $include_string); |
|
1275 | - $extracted_fields_to_include = array(); |
|
1276 | - if ($model_name) { |
|
1277 | - foreach ($includes as $field_to_include) { |
|
1278 | - $field_to_include = trim($field_to_include); |
|
1279 | - if (strpos($field_to_include, $model_name . '.') === 0) { |
|
1280 | - //found the model name at the exact start |
|
1281 | - $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include); |
|
1282 | - $extracted_fields_to_include[] = $field_sans_model_name; |
|
1283 | - } elseif ($field_to_include == $model_name) { |
|
1284 | - $extracted_fields_to_include[] = '*'; |
|
1285 | - } |
|
1286 | - } |
|
1287 | - } else { |
|
1288 | - //look for ones with no period |
|
1289 | - foreach ($includes as $field_to_include) { |
|
1290 | - $field_to_include = trim($field_to_include); |
|
1291 | - if ( |
|
1292 | - strpos($field_to_include, '.') === false |
|
1293 | - && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
1294 | - ) { |
|
1295 | - $extracted_fields_to_include[] = $field_to_include; |
|
1296 | - } |
|
1297 | - } |
|
1298 | - } |
|
1299 | - return $extracted_fields_to_include; |
|
1300 | - } |
|
30 | + /** |
|
31 | + * @var Calculated_Model_Fields |
|
32 | + */ |
|
33 | + protected $_fields_calculator; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Read constructor. |
|
39 | + */ |
|
40 | + public function __construct() |
|
41 | + { |
|
42 | + parent::__construct(); |
|
43 | + $this->_fields_calculator = new Calculated_Model_Fields(); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
50 | + * |
|
51 | + * @param \WP_REST_Request $request |
|
52 | + * @return \WP_REST_Response|\WP_Error |
|
53 | + */ |
|
54 | + public static function handle_request_get_all(\WP_REST_Request $request) |
|
55 | + { |
|
56 | + $controller = new Read(); |
|
57 | + try { |
|
58 | + $matches = $controller->parse_route( |
|
59 | + $request->get_route(), |
|
60 | + '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
61 | + array('version', 'model') |
|
62 | + ); |
|
63 | + $controller->set_requested_version($matches['version']); |
|
64 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
65 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
66 | + return $controller->send_response( |
|
67 | + new \WP_Error( |
|
68 | + 'endpoint_parsing_error', |
|
69 | + sprintf( |
|
70 | + __('There is no model for endpoint %s. Please contact event espresso support', |
|
71 | + 'event_espresso'), |
|
72 | + $model_name_singular |
|
73 | + ) |
|
74 | + ) |
|
75 | + ); |
|
76 | + } |
|
77 | + return $controller->send_response( |
|
78 | + $controller->get_entities_from_model( |
|
79 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
80 | + $request |
|
81 | + ) |
|
82 | + ); |
|
83 | + } catch (\Exception $e) { |
|
84 | + return $controller->send_response($e); |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Prepares and returns schema for any OPTIONS request. |
|
92 | + * |
|
93 | + * @param string $model_name Something like `Event` or `Registration` |
|
94 | + * @param string $version The API endpoint version being used. |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public static function handle_schema_request($model_name, $version) |
|
98 | + { |
|
99 | + $controller = new Read(); |
|
100 | + try { |
|
101 | + $controller->set_requested_version($version); |
|
102 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name)) { |
|
103 | + return array(); |
|
104 | + } |
|
105 | + //get the model for this version |
|
106 | + $model = $controller->get_model_version_info()->load_model($model_name); |
|
107 | + $model_schema = new JsonModelSchema($model); |
|
108 | + return $model_schema->getModelSchemaForRelations( |
|
109 | + $controller->get_model_version_info()->relation_settings($model), |
|
110 | + $controller->_customize_schema_for_rest_response( |
|
111 | + $model, |
|
112 | + $model_schema->getModelSchemaForFields( |
|
113 | + $controller->get_model_version_info()->fields_on_model_in_this_version($model), |
|
114 | + $model_schema->getInitialSchemaStructure() |
|
115 | + ) |
|
116 | + ) |
|
117 | + ); |
|
118 | + } catch (\Exception $e) { |
|
119 | + return array(); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * This loops through each field in the given schema for the model and does the following: |
|
127 | + * - add any extra fields that are REST API specific and related to existing fields. |
|
128 | + * - transform default values into the correct format for a REST API response. |
|
129 | + * |
|
130 | + * @param \EEM_Base $model |
|
131 | + * @param array $schema |
|
132 | + * @return array The final schema. |
|
133 | + */ |
|
134 | + protected function _customize_schema_for_rest_response(\EEM_Base $model, array $schema) |
|
135 | + { |
|
136 | + foreach ($this->get_model_version_info()->fields_on_model_in_this_version($model) as $field_name => $field) { |
|
137 | + $schema = $this->_translate_defaults_for_rest_response( |
|
138 | + $field_name, |
|
139 | + $field, |
|
140 | + $this->_maybe_add_extra_fields_to_schema($field_name, $field, $schema) |
|
141 | + ); |
|
142 | + } |
|
143 | + return $schema; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * This is used to ensure that the 'default' value set in the schema response is formatted correctly for the REST |
|
150 | + * response. |
|
151 | + * |
|
152 | + * @param $field_name |
|
153 | + * @param \EE_Model_Field_Base $field |
|
154 | + * @param array $schema |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + protected function _translate_defaults_for_rest_response($field_name, \EE_Model_Field_Base $field, array $schema) |
|
158 | + { |
|
159 | + if (isset($schema['properties'][$field_name]['default'])) { |
|
160 | + if (is_array($schema['properties'][$field_name]['default'])) { |
|
161 | + foreach ($schema['properties'][$field_name]['default'] as $default_key => $default_value) { |
|
162 | + if ($default_key === 'raw') { |
|
163 | + $schema['properties'][$field_name]['default'][$default_key] = Model_Data_Translator::prepare_field_value_for_json( |
|
164 | + $field, |
|
165 | + $default_value, |
|
166 | + $this->get_model_version_info()->requested_version() |
|
167 | + ); |
|
168 | + } |
|
169 | + } |
|
170 | + } else { |
|
171 | + $schema['properties'][$field_name]['default'] = Model_Data_Translator::prepare_field_value_for_json( |
|
172 | + $field, |
|
173 | + $schema['properties'][$field_name]['default'], |
|
174 | + $this->get_model_version_info()->requested_version() |
|
175 | + ); |
|
176 | + } |
|
177 | + } |
|
178 | + return $schema; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * Adds additional fields to the schema |
|
185 | + * The REST API returns a GMT value field for each datetime field in the resource. Thus the description about this |
|
186 | + * needs to be added to the schema. |
|
187 | + * |
|
188 | + * @param $field_name |
|
189 | + * @param \EE_Model_Field_Base $field |
|
190 | + * @param array $schema |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + protected function _maybe_add_extra_fields_to_schema($field_name, \EE_Model_Field_Base $field, array $schema) |
|
194 | + { |
|
195 | + if ($field instanceof EE_Datetime_Field) { |
|
196 | + $schema['properties'][$field_name . '_gmt'] = $field->getSchema(); |
|
197 | + //modify the description |
|
198 | + $schema['properties'][$field_name . '_gmt']['description'] = sprintf( |
|
199 | + esc_html__('%s - the value for this field is in GMT.', 'event_espresso'), |
|
200 | + $field->get_nicename() |
|
201 | + ); |
|
202 | + } |
|
203 | + return $schema; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Used to figure out the route from the request when a `WP_REST_Request` object is not available |
|
210 | + * |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + protected function get_route_from_request() |
|
214 | + { |
|
215 | + if (isset($GLOBALS['wp']) |
|
216 | + && $GLOBALS['wp'] instanceof \WP |
|
217 | + && isset($GLOBALS['wp']->query_vars['rest_route']) |
|
218 | + ) { |
|
219 | + return $GLOBALS['wp']->query_vars['rest_route']; |
|
220 | + } else { |
|
221 | + return isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : '/'; |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * Gets a single entity related to the model indicated in the path and its id |
|
229 | + * |
|
230 | + * @param \WP_REST_Request $request |
|
231 | + * @return \WP_REST_Response|\WP_Error |
|
232 | + */ |
|
233 | + public static function handle_request_get_one(\WP_REST_Request $request) |
|
234 | + { |
|
235 | + $controller = new Read(); |
|
236 | + try { |
|
237 | + $matches = $controller->parse_route( |
|
238 | + $request->get_route(), |
|
239 | + '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
240 | + array('version', 'model', 'id')); |
|
241 | + $controller->set_requested_version($matches['version']); |
|
242 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
243 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
244 | + return $controller->send_response( |
|
245 | + new \WP_Error( |
|
246 | + 'endpoint_parsing_error', |
|
247 | + sprintf( |
|
248 | + __('There is no model for endpoint %s. Please contact event espresso support', |
|
249 | + 'event_espresso'), |
|
250 | + $model_name_singular |
|
251 | + ) |
|
252 | + ) |
|
253 | + ); |
|
254 | + } |
|
255 | + return $controller->send_response( |
|
256 | + $controller->get_entity_from_model( |
|
257 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
258 | + $request |
|
259 | + ) |
|
260 | + ); |
|
261 | + } catch (\Exception $e) { |
|
262 | + return $controller->send_response($e); |
|
263 | + } |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * Gets all the related entities (or if its a belongs-to relation just the one) |
|
270 | + * to the item with the given id |
|
271 | + * |
|
272 | + * @param \WP_REST_Request $request |
|
273 | + * @return \WP_REST_Response|\WP_Error |
|
274 | + */ |
|
275 | + public static function handle_request_get_related(\WP_REST_Request $request) |
|
276 | + { |
|
277 | + $controller = new Read(); |
|
278 | + try { |
|
279 | + $matches = $controller->parse_route( |
|
280 | + $request->get_route(), |
|
281 | + '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
282 | + array('version', 'model', 'id', 'related_model') |
|
283 | + ); |
|
284 | + $controller->set_requested_version($matches['version']); |
|
285 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
286 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
287 | + return $controller->send_response( |
|
288 | + new \WP_Error( |
|
289 | + 'endpoint_parsing_error', |
|
290 | + sprintf( |
|
291 | + __('There is no model for endpoint %s. Please contact event espresso support', |
|
292 | + 'event_espresso'), |
|
293 | + $main_model_name_singular |
|
294 | + ) |
|
295 | + ) |
|
296 | + ); |
|
297 | + } |
|
298 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
299 | + //assume the related model name is plural and try to find the model's name |
|
300 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
301 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
302 | + //so the word didn't singularize well. Maybe that's just because it's a singular word? |
|
303 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
304 | + } |
|
305 | + if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
306 | + return $controller->send_response( |
|
307 | + new \WP_Error( |
|
308 | + 'endpoint_parsing_error', |
|
309 | + sprintf( |
|
310 | + __('There is no model for endpoint %s. Please contact event espresso support', |
|
311 | + 'event_espresso'), |
|
312 | + $related_model_name_singular |
|
313 | + ) |
|
314 | + ) |
|
315 | + ); |
|
316 | + } |
|
317 | + return $controller->send_response( |
|
318 | + $controller->get_entities_from_relation( |
|
319 | + $request->get_param('id'), |
|
320 | + $main_model->related_settings_for($related_model_name_singular), |
|
321 | + $request |
|
322 | + ) |
|
323 | + ); |
|
324 | + } catch (\Exception $e) { |
|
325 | + return $controller->send_response($e); |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * Gets a collection for the given model and filters |
|
333 | + * |
|
334 | + * @param \EEM_Base $model |
|
335 | + * @param \WP_REST_Request $request |
|
336 | + * @return array|\WP_Error |
|
337 | + */ |
|
338 | + public function get_entities_from_model($model, $request) |
|
339 | + { |
|
340 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
341 | + if (! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
342 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
343 | + return new \WP_Error( |
|
344 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
345 | + sprintf( |
|
346 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
347 | + $model_name_plural, |
|
348 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
349 | + ), |
|
350 | + array('status' => 403) |
|
351 | + ); |
|
352 | + } |
|
353 | + if (! $request->get_header('no_rest_headers')) { |
|
354 | + $this->_set_headers_from_query_params($model, $query_params); |
|
355 | + } |
|
356 | + /** @type array $results */ |
|
357 | + $results = $model->get_all_wpdb_results($query_params); |
|
358 | + $nice_results = array(); |
|
359 | + foreach ($results as $result) { |
|
360 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
361 | + $model, |
|
362 | + $result, |
|
363 | + $request |
|
364 | + ); |
|
365 | + } |
|
366 | + return $nice_results; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * @param array $primary_model_query_params query params for finding the item from which |
|
373 | + * relations will be based |
|
374 | + * @param \EE_Model_Relation_Base $relation |
|
375 | + * @param \WP_REST_Request $request |
|
376 | + * @return \WP_Error|array |
|
377 | + */ |
|
378 | + protected function _get_entities_from_relation($primary_model_query_params, $relation, $request) |
|
379 | + { |
|
380 | + $context = $this->validate_context($request->get_param('caps')); |
|
381 | + $model = $relation->get_this_model(); |
|
382 | + $related_model = $relation->get_other_model(); |
|
383 | + if (! isset($primary_model_query_params[0])) { |
|
384 | + $primary_model_query_params[0] = array(); |
|
385 | + } |
|
386 | + //check if they can access the 1st model object |
|
387 | + $primary_model_query_params = array( |
|
388 | + 0 => $primary_model_query_params[0], |
|
389 | + 'limit' => 1, |
|
390 | + ); |
|
391 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
392 | + $primary_model_query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($primary_model_query_params); |
|
393 | + } |
|
394 | + $restricted_query_params = $primary_model_query_params; |
|
395 | + $restricted_query_params['caps'] = $context; |
|
396 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
397 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
398 | + if ( |
|
399 | + ! ( |
|
400 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
401 | + && $model->exists($restricted_query_params) |
|
402 | + ) |
|
403 | + ) { |
|
404 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
405 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
406 | + } else { |
|
407 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
408 | + } |
|
409 | + return new \WP_Error( |
|
410 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
411 | + sprintf( |
|
412 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', |
|
413 | + 'event_espresso'), |
|
414 | + $related_model_name_maybe_plural, |
|
415 | + $relation->get_this_model()->get_this_model_name(), |
|
416 | + implode( |
|
417 | + ',', |
|
418 | + array_keys( |
|
419 | + Capabilities::get_missing_permissions($related_model, $context) |
|
420 | + ) |
|
421 | + ) |
|
422 | + ), |
|
423 | + array('status' => 403) |
|
424 | + ); |
|
425 | + } |
|
426 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
427 | + foreach ($primary_model_query_params[0] as $where_condition_key => $where_condition_value) { |
|
428 | + $query_params[0][$relation->get_this_model()->get_this_model_name() |
|
429 | + . '.' |
|
430 | + . $where_condition_key] = $where_condition_value; |
|
431 | + } |
|
432 | + $query_params['default_where_conditions'] = 'none'; |
|
433 | + $query_params['caps'] = $context; |
|
434 | + if (! $request->get_header('no_rest_headers')) { |
|
435 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
436 | + } |
|
437 | + /** @type array $results */ |
|
438 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
439 | + $nice_results = array(); |
|
440 | + foreach ($results as $result) { |
|
441 | + $nice_result = $this->create_entity_from_wpdb_result( |
|
442 | + $relation->get_other_model(), |
|
443 | + $result, |
|
444 | + $request |
|
445 | + ); |
|
446 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
447 | + //put the unusual stuff (properties from the HABTM relation) first, and make sure |
|
448 | + //if there are conflicts we prefer the properties from the main model |
|
449 | + $join_model_result = $this->create_entity_from_wpdb_result( |
|
450 | + $relation->get_join_model(), |
|
451 | + $result, |
|
452 | + $request |
|
453 | + ); |
|
454 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
455 | + //but keep the meta stuff from the main model |
|
456 | + if (isset($nice_result['meta'])) { |
|
457 | + $joined_result['meta'] = $nice_result['meta']; |
|
458 | + } |
|
459 | + $nice_result = $joined_result; |
|
460 | + } |
|
461 | + $nice_results[] = $nice_result; |
|
462 | + } |
|
463 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
464 | + return array_shift($nice_results); |
|
465 | + } else { |
|
466 | + return $nice_results; |
|
467 | + } |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * Gets the collection for given relation object |
|
474 | + * The same as Read::get_entities_from_model(), except if the relation |
|
475 | + * is a HABTM relation, in which case it merges any non-foreign-key fields from |
|
476 | + * the join-model-object into the results |
|
477 | + * |
|
478 | + * @param string $id the ID of the thing we are fetching related stuff from |
|
479 | + * @param \EE_Model_Relation_Base $relation |
|
480 | + * @param \WP_REST_Request $request |
|
481 | + * @return array|\WP_Error |
|
482 | + * @throws \EE_Error |
|
483 | + */ |
|
484 | + public function get_entities_from_relation($id, $relation, $request) |
|
485 | + { |
|
486 | + if (! $relation->get_this_model()->has_primary_key_field()) { |
|
487 | + throw new \EE_Error( |
|
488 | + sprintf( |
|
489 | + __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', |
|
490 | + 'event_espresso'), |
|
491 | + $relation->get_this_model()->get_this_model_name() |
|
492 | + ) |
|
493 | + ); |
|
494 | + } |
|
495 | + return $this->_get_entities_from_relation( |
|
496 | + array( |
|
497 | + array( |
|
498 | + $relation->get_this_model()->primary_key_name() => $id, |
|
499 | + ), |
|
500 | + ), |
|
501 | + $relation, |
|
502 | + $request |
|
503 | + ); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + |
|
508 | + /** |
|
509 | + * Sets the headers that are based on the model and query params, |
|
510 | + * like the total records. This should only be called on the original request |
|
511 | + * from the client, not on subsequent internal |
|
512 | + * |
|
513 | + * @param \EEM_Base $model |
|
514 | + * @param array $query_params |
|
515 | + * @return void |
|
516 | + */ |
|
517 | + protected function _set_headers_from_query_params($model, $query_params) |
|
518 | + { |
|
519 | + $this->_set_debug_info('model query params', $query_params); |
|
520 | + $this->_set_debug_info('missing caps', |
|
521 | + Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
522 | + //normally the limit to a 2-part array, where the 2nd item is the limit |
|
523 | + if (! isset($query_params['limit'])) { |
|
524 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
525 | + } |
|
526 | + if (is_array($query_params['limit'])) { |
|
527 | + $limit_parts = $query_params['limit']; |
|
528 | + } else { |
|
529 | + $limit_parts = explode(',', $query_params['limit']); |
|
530 | + if (count($limit_parts) == 1) { |
|
531 | + $limit_parts = array(0, $limit_parts[0]); |
|
532 | + } |
|
533 | + } |
|
534 | + //remove the group by and having parts of the query, as those will |
|
535 | + //make the sql query return an array of values, instead of just a single value |
|
536 | + unset($query_params['group_by'], $query_params['having'], $query_params['limit']); |
|
537 | + $count = $model->count($query_params, null, true); |
|
538 | + $pages = $count / $limit_parts[1]; |
|
539 | + $this->_set_response_header('Total', $count, false); |
|
540 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
541 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * Changes database results into REST API entities |
|
548 | + * |
|
549 | + * @param \EEM_Base $model |
|
550 | + * @param array $db_row like results from $wpdb->get_results() |
|
551 | + * @param \WP_REST_Request $rest_request |
|
552 | + * @param string $deprecated no longer used |
|
553 | + * @return array ready for being converted into json for sending to client |
|
554 | + */ |
|
555 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) |
|
556 | + { |
|
557 | + if (! $rest_request instanceof \WP_REST_Request) { |
|
558 | + //ok so this was called in the old style, where the 3rd arg was |
|
559 | + //$include, and the 4th arg was $context |
|
560 | + //now setup the request just to avoid fatal errors, although we won't be able |
|
561 | + //to truly make use of it because it's kinda devoid of info |
|
562 | + $rest_request = new \WP_REST_Request(); |
|
563 | + $rest_request->set_param('include', $rest_request); |
|
564 | + $rest_request->set_param('caps', $deprecated); |
|
565 | + } |
|
566 | + if ($rest_request->get_param('caps') == null) { |
|
567 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
568 | + } |
|
569 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
570 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
571 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
572 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
573 | + $entity_array = apply_filters('FHEE__Read__create_entity_from_wpdb_results__entity_before_including_requested_models', |
|
574 | + $entity_array, $model, $rest_request->get_param('caps'), $rest_request, $this); |
|
575 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array, $db_row); |
|
576 | + $entity_array = apply_filters( |
|
577 | + 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
|
578 | + $entity_array, |
|
579 | + $model, |
|
580 | + $rest_request->get_param('caps'), |
|
581 | + $rest_request, |
|
582 | + $this |
|
583 | + ); |
|
584 | + $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
|
585 | + $entity_array, |
|
586 | + $model, |
|
587 | + $rest_request->get_param('caps'), |
|
588 | + $this->get_model_version_info(), |
|
589 | + $model->get_index_primary_key_string( |
|
590 | + $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
591 | + ) |
|
592 | + ); |
|
593 | + $this->_set_debug_info( |
|
594 | + 'inaccessible fields', |
|
595 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
596 | + ); |
|
597 | + return apply_filters( |
|
598 | + 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
|
599 | + $result_without_inaccessible_fields, |
|
600 | + $model, |
|
601 | + $rest_request->get_param('caps') |
|
602 | + ); |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * Creates a REST entity array (JSON object we're going to return in the response, but |
|
609 | + * for now still a PHP array, but soon enough we'll call json_encode on it, don't worry), |
|
610 | + * from $wpdb->get_row( $sql, ARRAY_A) |
|
611 | + * |
|
612 | + * @param \EEM_Base $model |
|
613 | + * @param array $db_row |
|
614 | + * @return array entity mostly ready for converting to JSON and sending in the response |
|
615 | + */ |
|
616 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) |
|
617 | + { |
|
618 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
619 | + $result = array_intersect_key($result, |
|
620 | + $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
621 | + //if this is a CPT, we need to set the global $post to it, |
|
622 | + //otherwise shortcodes etc won't work properly while rendering it |
|
623 | + if ($model instanceof \EEM_CPT_Base) { |
|
624 | + $do_chevy_shuffle = true; |
|
625 | + } else { |
|
626 | + $do_chevy_shuffle = false; |
|
627 | + } |
|
628 | + if ($do_chevy_shuffle) { |
|
629 | + global $post; |
|
630 | + $old_post = $post; |
|
631 | + $post = get_post($result[$model->primary_key_name()]); |
|
632 | + if (! $post instanceof \WP_Post) { |
|
633 | + //well that's weird, because $result is what we JUST fetched from the database |
|
634 | + throw new Rest_Exception( |
|
635 | + 'error_fetching_post_from_database_results', |
|
636 | + esc_html__( |
|
637 | + 'An item was retrieved from the database but it\'s not a WP_Post like it should be.', |
|
638 | + 'event_espresso' |
|
639 | + ) |
|
640 | + ); |
|
641 | + } |
|
642 | + $model_object_classname = 'EE_' . $model->get_this_model_name(); |
|
643 | + $post->{$model_object_classname} = \EE_Registry::instance()->load_class( |
|
644 | + $model_object_classname, |
|
645 | + $result, |
|
646 | + false, |
|
647 | + false |
|
648 | + ); |
|
649 | + } |
|
650 | + foreach ($result as $field_name => $raw_field_value) { |
|
651 | + $field_obj = $model->field_settings_for($field_name); |
|
652 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
653 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
654 | + unset($result[$field_name]); |
|
655 | + } elseif ( |
|
656 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
657 | + ) { |
|
658 | + $result[$field_name] = array( |
|
659 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
660 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value), |
|
661 | + ); |
|
662 | + } elseif ( |
|
663 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
664 | + ) { |
|
665 | + $result[$field_name] = array( |
|
666 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
667 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value), |
|
668 | + ); |
|
669 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
670 | + if ($field_value instanceof \DateTime) { |
|
671 | + $timezone = $field_value->getTimezone(); |
|
672 | + $field_value->setTimezone(new \DateTimeZone('UTC')); |
|
673 | + $result[$field_name . '_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
674 | + $field_obj, |
|
675 | + $field_value, |
|
676 | + $this->get_model_version_info()->requested_version() |
|
677 | + ); |
|
678 | + $field_value->setTimezone($timezone); |
|
679 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
680 | + $field_obj, |
|
681 | + $field_value, |
|
682 | + $this->get_model_version_info()->requested_version() |
|
683 | + ); |
|
684 | + } |
|
685 | + } else { |
|
686 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
687 | + $field_obj, |
|
688 | + $field_obj->prepare_for_get($field_value), |
|
689 | + $this->get_model_version_info()->requested_version() |
|
690 | + ); |
|
691 | + } |
|
692 | + } |
|
693 | + if ($do_chevy_shuffle) { |
|
694 | + $post = $old_post; |
|
695 | + } |
|
696 | + return $result; |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * Adds a few extra fields to the entity response |
|
703 | + * |
|
704 | + * @param \EEM_Base $model |
|
705 | + * @param array $db_row |
|
706 | + * @param array $entity_array |
|
707 | + * @return array modified entity |
|
708 | + */ |
|
709 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) |
|
710 | + { |
|
711 | + if ($model instanceof \EEM_CPT_Base) { |
|
712 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
713 | + } |
|
714 | + return $entity_array; |
|
715 | + } |
|
716 | + |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * Gets links we want to add to the response |
|
721 | + * |
|
722 | + * @global \WP_REST_Server $wp_rest_server |
|
723 | + * @param \EEM_Base $model |
|
724 | + * @param array $db_row |
|
725 | + * @param array $entity_array |
|
726 | + * @return array the _links item in the entity |
|
727 | + */ |
|
728 | + protected function _get_entity_links($model, $db_row, $entity_array) |
|
729 | + { |
|
730 | + //add basic links |
|
731 | + $links = array(); |
|
732 | + if ($model->has_primary_key_field()) { |
|
733 | + $links['self'] = array( |
|
734 | + array( |
|
735 | + 'href' => $this->get_versioned_link_to( |
|
736 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
737 | + . '/' |
|
738 | + . $entity_array[$model->primary_key_name()] |
|
739 | + ), |
|
740 | + ), |
|
741 | + ); |
|
742 | + } |
|
743 | + $links['collection'] = array( |
|
744 | + array( |
|
745 | + 'href' => $this->get_versioned_link_to( |
|
746 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
747 | + ), |
|
748 | + ), |
|
749 | + ); |
|
750 | + //add links to related models |
|
751 | + if ($model->has_primary_key_field()) { |
|
752 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
753 | + $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
|
754 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array( |
|
755 | + array( |
|
756 | + 'href' => $this->get_versioned_link_to( |
|
757 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
758 | + . '/' |
|
759 | + . $entity_array[$model->primary_key_name()] |
|
760 | + . '/' |
|
761 | + . $related_model_part |
|
762 | + ), |
|
763 | + 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false, |
|
764 | + ), |
|
765 | + ); |
|
766 | + } |
|
767 | + } |
|
768 | + return $links; |
|
769 | + } |
|
770 | + |
|
771 | + |
|
772 | + |
|
773 | + /** |
|
774 | + * Adds the included models indicated in the request to the entity provided |
|
775 | + * |
|
776 | + * @param \EEM_Base $model |
|
777 | + * @param \WP_REST_Request $rest_request |
|
778 | + * @param array $entity_array |
|
779 | + * @param array $db_row |
|
780 | + * @return array the modified entity |
|
781 | + */ |
|
782 | + protected function _include_requested_models( |
|
783 | + \EEM_Base $model, |
|
784 | + \WP_REST_Request $rest_request, |
|
785 | + $entity_array, |
|
786 | + $db_row = array() |
|
787 | + ) { |
|
788 | + //if $db_row not included, hope the entity array has what we need |
|
789 | + if (! $db_row) { |
|
790 | + $db_row = $entity_array; |
|
791 | + } |
|
792 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
793 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
794 | + //if they passed in * or didn't specify any includes, return everything |
|
795 | + if (! in_array('*', $includes_for_this_model) |
|
796 | + && ! empty($includes_for_this_model) |
|
797 | + ) { |
|
798 | + if ($model->has_primary_key_field()) { |
|
799 | + //always include the primary key. ya just gotta know that at least |
|
800 | + $includes_for_this_model[] = $model->primary_key_name(); |
|
801 | + } |
|
802 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
803 | + $includes_for_this_model[] = '_calculated_fields'; |
|
804 | + } |
|
805 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
806 | + } |
|
807 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
808 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
809 | + $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
|
810 | + $rest_request->get_param('include'), |
|
811 | + $relation_name |
|
812 | + ); |
|
813 | + $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
|
814 | + $rest_request->get_param('calculate'), |
|
815 | + $relation_name |
|
816 | + ); |
|
817 | + //did they specify they wanted to include a related model, or |
|
818 | + //specific fields from a related model? |
|
819 | + //or did they specify to calculate a field from a related model? |
|
820 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
821 | + //if so, we should include at least some part of the related model |
|
822 | + $pretend_related_request = new \WP_REST_Request(); |
|
823 | + $pretend_related_request->set_query_params( |
|
824 | + array( |
|
825 | + 'caps' => $rest_request->get_param('caps'), |
|
826 | + 'include' => $related_fields_to_include, |
|
827 | + 'calculate' => $related_fields_to_calculate, |
|
828 | + ) |
|
829 | + ); |
|
830 | + $pretend_related_request->add_header('no_rest_headers', true); |
|
831 | + $primary_model_query_params = $model->alter_query_params_to_restrict_by_ID( |
|
832 | + $model->get_index_primary_key_string( |
|
833 | + $model->deduce_fields_n_values_from_cols_n_values($db_row) |
|
834 | + ) |
|
835 | + ); |
|
836 | + $related_results = $this->_get_entities_from_relation( |
|
837 | + $primary_model_query_params, |
|
838 | + $relation_obj, |
|
839 | + $pretend_related_request |
|
840 | + ); |
|
841 | + $entity_array[Read::get_related_entity_name($relation_name, $relation_obj)] = $related_results |
|
842 | + instanceof |
|
843 | + \WP_Error |
|
844 | + ? null |
|
845 | + : $related_results; |
|
846 | + } |
|
847 | + } |
|
848 | + return $entity_array; |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * Returns a new array with all the names of models removed. Eg |
|
855 | + * array( 'Event', 'Datetime.*', 'foobar' ) would become array( 'Datetime.*', 'foobar' ) |
|
856 | + * |
|
857 | + * @param array $arr |
|
858 | + * @return array |
|
859 | + */ |
|
860 | + private function _remove_model_names_from_array($arr) |
|
861 | + { |
|
862 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
863 | + } |
|
864 | + |
|
865 | + |
|
866 | + |
|
867 | + /** |
|
868 | + * Gets the calculated fields for the response |
|
869 | + * |
|
870 | + * @param \EEM_Base $model |
|
871 | + * @param array $wpdb_row |
|
872 | + * @param \WP_REST_Request $rest_request |
|
873 | + * @return \stdClass the _calculations item in the entity |
|
874 | + */ |
|
875 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) |
|
876 | + { |
|
877 | + $calculated_fields = $this->explode_and_get_items_prefixed_with( |
|
878 | + $rest_request->get_param('calculate'), |
|
879 | + '' |
|
880 | + ); |
|
881 | + //note: setting calculate=* doesn't do anything |
|
882 | + $calculated_fields_to_return = new \stdClass(); |
|
883 | + foreach ($calculated_fields as $field_to_calculate) { |
|
884 | + try { |
|
885 | + $calculated_fields_to_return->$field_to_calculate = Model_Data_Translator::prepare_field_value_for_json( |
|
886 | + null, |
|
887 | + $this->_fields_calculator->retrieve_calculated_field_value( |
|
888 | + $model, |
|
889 | + $field_to_calculate, |
|
890 | + $wpdb_row, |
|
891 | + $rest_request, |
|
892 | + $this |
|
893 | + ), |
|
894 | + $this->get_model_version_info()->requested_version() |
|
895 | + ); |
|
896 | + } catch (Rest_Exception $e) { |
|
897 | + //if we don't have permission to read it, just leave it out. but let devs know about the problem |
|
898 | + $this->_set_response_header( |
|
899 | + 'Notices-Field-Calculation-Errors[' |
|
900 | + . $e->get_string_code() |
|
901 | + . '][' |
|
902 | + . $model->get_this_model_name() |
|
903 | + . '][' |
|
904 | + . $field_to_calculate |
|
905 | + . ']', |
|
906 | + $e->getMessage(), |
|
907 | + true |
|
908 | + ); |
|
909 | + } |
|
910 | + } |
|
911 | + return $calculated_fields_to_return; |
|
912 | + } |
|
913 | + |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * Gets the full URL to the resource, taking the requested version into account |
|
918 | + * |
|
919 | + * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
|
920 | + * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
|
921 | + */ |
|
922 | + public function get_versioned_link_to($link_part_after_version_and_slash) |
|
923 | + { |
|
924 | + return rest_url( |
|
925 | + \EED_Core_Rest_Api::ee_api_namespace |
|
926 | + . $this->get_model_version_info()->requested_version() |
|
927 | + . '/' |
|
928 | + . $link_part_after_version_and_slash |
|
929 | + ); |
|
930 | + } |
|
931 | + |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * Gets the correct lowercase name for the relation in the API according |
|
936 | + * to the relation's type |
|
937 | + * |
|
938 | + * @param string $relation_name |
|
939 | + * @param \EE_Model_Relation_Base $relation_obj |
|
940 | + * @return string |
|
941 | + */ |
|
942 | + public static function get_related_entity_name($relation_name, $relation_obj) |
|
943 | + { |
|
944 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
945 | + return strtolower($relation_name); |
|
946 | + } else { |
|
947 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
948 | + } |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * Gets the one model object with the specified id for the specified model |
|
955 | + * |
|
956 | + * @param \EEM_Base $model |
|
957 | + * @param \WP_REST_Request $request |
|
958 | + * @return array|\WP_Error |
|
959 | + */ |
|
960 | + public function get_entity_from_model($model, $request) |
|
961 | + { |
|
962 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
963 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
964 | + $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
965 | + } |
|
966 | + $restricted_query_params = $query_params; |
|
967 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
968 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
969 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
970 | + if (! empty ($model_rows)) { |
|
971 | + return $this->create_entity_from_wpdb_result( |
|
972 | + $model, |
|
973 | + array_shift($model_rows), |
|
974 | + $request); |
|
975 | + } else { |
|
976 | + //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
|
977 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
978 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
979 | + if (! empty($model_rows_found_sans_restrictions)) { |
|
980 | + //you got shafted- it existed but we didn't want to tell you! |
|
981 | + return new \WP_Error( |
|
982 | + 'rest_user_cannot_read', |
|
983 | + sprintf( |
|
984 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
985 | + strtolower($model->get_this_model_name()), |
|
986 | + Capabilities::get_missing_permissions_string( |
|
987 | + $model, |
|
988 | + $this->validate_context($request->get_param('caps'))) |
|
989 | + ), |
|
990 | + array('status' => 403) |
|
991 | + ); |
|
992 | + } else { |
|
993 | + //it's not you. It just doesn't exist |
|
994 | + return new \WP_Error( |
|
995 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
996 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
997 | + array('status' => 404) |
|
998 | + ); |
|
999 | + } |
|
1000 | + } |
|
1001 | + } |
|
1002 | + |
|
1003 | + |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * If a context is provided which isn't valid, maybe it was added in a future |
|
1007 | + * version so just treat it as a default read |
|
1008 | + * |
|
1009 | + * @param string $context |
|
1010 | + * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
|
1011 | + */ |
|
1012 | + public function validate_context($context) |
|
1013 | + { |
|
1014 | + if (! $context) { |
|
1015 | + $context = \EEM_Base::caps_read; |
|
1016 | + } |
|
1017 | + $valid_contexts = \EEM_Base::valid_cap_contexts(); |
|
1018 | + if (in_array($context, $valid_contexts)) { |
|
1019 | + return $context; |
|
1020 | + } else { |
|
1021 | + return \EEM_Base::caps_read; |
|
1022 | + } |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * Verifies the passed in value is an allowable default where conditions value. |
|
1029 | + * |
|
1030 | + * @param $default_query_params |
|
1031 | + * @return string |
|
1032 | + */ |
|
1033 | + public function validate_default_query_params($default_query_params) |
|
1034 | + { |
|
1035 | + $valid_default_where_conditions_for_api_calls = array( |
|
1036 | + \EEM_Base::default_where_conditions_all, |
|
1037 | + \EEM_Base::default_where_conditions_minimum_all, |
|
1038 | + \EEM_Base::default_where_conditions_minimum_others, |
|
1039 | + ); |
|
1040 | + if (! $default_query_params) { |
|
1041 | + $default_query_params = \EEM_Base::default_where_conditions_all; |
|
1042 | + } |
|
1043 | + if ( |
|
1044 | + in_array( |
|
1045 | + $default_query_params, |
|
1046 | + $valid_default_where_conditions_for_api_calls, |
|
1047 | + true |
|
1048 | + ) |
|
1049 | + ) { |
|
1050 | + return $default_query_params; |
|
1051 | + } else { |
|
1052 | + return \EEM_Base::default_where_conditions_all; |
|
1053 | + } |
|
1054 | + } |
|
1055 | + |
|
1056 | + |
|
1057 | + |
|
1058 | + /** |
|
1059 | + * Translates API filter get parameter into $query_params array used by EEM_Base::get_all(). |
|
1060 | + * Note: right now the query parameter keys for fields (and related fields) |
|
1061 | + * can be left as-is, but it's quite possible this will change someday. |
|
1062 | + * Also, this method's contents might be candidate for moving to Model_Data_Translator |
|
1063 | + * |
|
1064 | + * @param \EEM_Base $model |
|
1065 | + * @param array $query_parameters from $_GET parameter @see Read:handle_request_get_all |
|
1066 | + * @return array like what EEM_Base::get_all() expects or FALSE to indicate |
|
1067 | + * that absolutely no results should be returned |
|
1068 | + * @throws \EE_Error |
|
1069 | + */ |
|
1070 | + public function create_model_query_params($model, $query_parameters) |
|
1071 | + { |
|
1072 | + $model_query_params = array(); |
|
1073 | + if (isset($query_parameters['where'])) { |
|
1074 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
1075 | + $query_parameters['where'], |
|
1076 | + $model, |
|
1077 | + $this->get_model_version_info()->requested_version() |
|
1078 | + ); |
|
1079 | + } |
|
1080 | + if (isset($query_parameters['order_by'])) { |
|
1081 | + $order_by = $query_parameters['order_by']; |
|
1082 | + } elseif (isset($query_parameters['orderby'])) { |
|
1083 | + $order_by = $query_parameters['orderby']; |
|
1084 | + } else { |
|
1085 | + $order_by = null; |
|
1086 | + } |
|
1087 | + if ($order_by !== null) { |
|
1088 | + if (is_array($order_by)) { |
|
1089 | + $order_by = Model_Data_Translator::prepare_field_names_in_array_keys_from_json($order_by); |
|
1090 | + } else { |
|
1091 | + //it's a single item |
|
1092 | + $order_by = Model_Data_Translator::prepare_field_name_from_json($order_by); |
|
1093 | + } |
|
1094 | + $model_query_params['order_by'] = $order_by; |
|
1095 | + } |
|
1096 | + if (isset($query_parameters['group_by'])) { |
|
1097 | + $group_by = $query_parameters['group_by']; |
|
1098 | + } elseif (isset($query_parameters['groupby'])) { |
|
1099 | + $group_by = $query_parameters['groupby']; |
|
1100 | + } else { |
|
1101 | + $group_by = array_keys($model->get_combined_primary_key_fields()); |
|
1102 | + } |
|
1103 | + //make sure they're all real names |
|
1104 | + if (is_array($group_by)) { |
|
1105 | + $group_by = Model_Data_Translator::prepare_field_names_from_json($group_by); |
|
1106 | + } |
|
1107 | + if ($group_by !== null) { |
|
1108 | + $model_query_params['group_by'] = $group_by; |
|
1109 | + } |
|
1110 | + if (isset($query_parameters['having'])) { |
|
1111 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
1112 | + $query_parameters['having'], |
|
1113 | + $model, |
|
1114 | + $this->get_model_version_info()->requested_version() |
|
1115 | + ); |
|
1116 | + } |
|
1117 | + if (isset($query_parameters['order'])) { |
|
1118 | + $model_query_params['order'] = $query_parameters['order']; |
|
1119 | + } |
|
1120 | + if (isset($query_parameters['mine'])) { |
|
1121 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
1122 | + } |
|
1123 | + if (isset($query_parameters['limit'])) { |
|
1124 | + //limit should be either a string like '23' or '23,43', or an array with two items in it |
|
1125 | + if (! is_array($query_parameters['limit'])) { |
|
1126 | + $limit_array = explode(',', (string)$query_parameters['limit']); |
|
1127 | + } else { |
|
1128 | + $limit_array = $query_parameters['limit']; |
|
1129 | + } |
|
1130 | + $sanitized_limit = array(); |
|
1131 | + foreach ($limit_array as $key => $limit_part) { |
|
1132 | + if ($this->_debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
1133 | + throw new \EE_Error( |
|
1134 | + sprintf( |
|
1135 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', |
|
1136 | + 'event_espresso'), |
|
1137 | + wp_json_encode($query_parameters['limit']) |
|
1138 | + ) |
|
1139 | + ); |
|
1140 | + } |
|
1141 | + $sanitized_limit[] = (int)$limit_part; |
|
1142 | + } |
|
1143 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
1144 | + } else { |
|
1145 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
1146 | + } |
|
1147 | + if (isset($query_parameters['caps'])) { |
|
1148 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
1149 | + } else { |
|
1150 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
1151 | + } |
|
1152 | + if (isset($query_parameters['default_where_conditions'])) { |
|
1153 | + $model_query_params['default_where_conditions'] = $this->validate_default_query_params($query_parameters['default_where_conditions']); |
|
1154 | + } |
|
1155 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
1156 | + } |
|
1157 | + |
|
1158 | + |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * Changes the REST-style query params for use in the models |
|
1162 | + * |
|
1163 | + * @deprecated |
|
1164 | + * @param \EEM_Base $model |
|
1165 | + * @param array $query_params sub-array from @see EEM_Base::get_all() |
|
1166 | + * @return array |
|
1167 | + */ |
|
1168 | + public function prepare_rest_query_params_key_for_models($model, $query_params) |
|
1169 | + { |
|
1170 | + $model_ready_query_params = array(); |
|
1171 | + foreach ($query_params as $key => $value) { |
|
1172 | + if (is_array($value)) { |
|
1173 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
1174 | + } else { |
|
1175 | + $model_ready_query_params[$key] = $value; |
|
1176 | + } |
|
1177 | + } |
|
1178 | + return $model_ready_query_params; |
|
1179 | + } |
|
1180 | + |
|
1181 | + |
|
1182 | + |
|
1183 | + /** |
|
1184 | + * @deprecated |
|
1185 | + * @param $model |
|
1186 | + * @param $query_params |
|
1187 | + * @return array |
|
1188 | + */ |
|
1189 | + public function prepare_rest_query_params_values_for_models($model, $query_params) |
|
1190 | + { |
|
1191 | + $model_ready_query_params = array(); |
|
1192 | + foreach ($query_params as $key => $value) { |
|
1193 | + if (is_array($value)) { |
|
1194 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
1195 | + } else { |
|
1196 | + $model_ready_query_params[$key] = $value; |
|
1197 | + } |
|
1198 | + } |
|
1199 | + return $model_ready_query_params; |
|
1200 | + } |
|
1201 | + |
|
1202 | + |
|
1203 | + |
|
1204 | + /** |
|
1205 | + * Explodes the string on commas, and only returns items with $prefix followed by a period. |
|
1206 | + * If no prefix is specified, returns items with no period. |
|
1207 | + * |
|
1208 | + * @param string|array $string_to_explode eg "jibba,jabba, blah, blaabla" or array('jibba', 'jabba' ) |
|
1209 | + * @param string $prefix "Event" or "foobar" |
|
1210 | + * @return array $string_to_exploded exploded on COMMAS, and if a prefix was specified |
|
1211 | + * we only return strings starting with that and a period; if no prefix was |
|
1212 | + * specified we return all items containing NO periods |
|
1213 | + */ |
|
1214 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) |
|
1215 | + { |
|
1216 | + if (is_string($string_to_explode)) { |
|
1217 | + $exploded_contents = explode(',', $string_to_explode); |
|
1218 | + } else if (is_array($string_to_explode)) { |
|
1219 | + $exploded_contents = $string_to_explode; |
|
1220 | + } else { |
|
1221 | + $exploded_contents = array(); |
|
1222 | + } |
|
1223 | + //if the string was empty, we want an empty array |
|
1224 | + $exploded_contents = array_filter($exploded_contents); |
|
1225 | + $contents_with_prefix = array(); |
|
1226 | + foreach ($exploded_contents as $item) { |
|
1227 | + $item = trim($item); |
|
1228 | + //if no prefix was provided, so we look for items with no "." in them |
|
1229 | + if (! $prefix) { |
|
1230 | + //does this item have a period? |
|
1231 | + if (strpos($item, '.') === false) { |
|
1232 | + //if not, then its what we're looking for |
|
1233 | + $contents_with_prefix[] = $item; |
|
1234 | + } |
|
1235 | + } else if (strpos($item, $prefix . '.') === 0) { |
|
1236 | + //this item has the prefix and a period, grab it |
|
1237 | + $contents_with_prefix[] = substr( |
|
1238 | + $item, |
|
1239 | + strpos($item, $prefix . '.') + strlen($prefix . '.') |
|
1240 | + ); |
|
1241 | + } else if ($item === $prefix) { |
|
1242 | + //this item is JUST the prefix |
|
1243 | + //so let's grab everything after, which is a blank string |
|
1244 | + $contents_with_prefix[] = ''; |
|
1245 | + } |
|
1246 | + } |
|
1247 | + return $contents_with_prefix; |
|
1248 | + } |
|
1249 | + |
|
1250 | + |
|
1251 | + |
|
1252 | + /** |
|
1253 | + * @deprecated since 4.8.36.rc.001 You should instead use Read::explode_and_get_items_prefixed_with. |
|
1254 | + * Deprecated because its return values were really quite confusing- sometimes it returned |
|
1255 | + * an empty array (when the include string was blank or '*') or sometimes it returned |
|
1256 | + * array('*') (when you provided a model and a model of that kind was found). |
|
1257 | + * Parses the $include_string so we fetch all the field names relating to THIS model |
|
1258 | + * (ie have NO period in them), or for the provided model (ie start with the model |
|
1259 | + * name and then a period). |
|
1260 | + * @param string $include_string @see Read:handle_request_get_all |
|
1261 | + * @param string $model_name |
|
1262 | + * @return array of fields for this model. If $model_name is provided, then |
|
1263 | + * the fields for that model, with the model's name removed from each. |
|
1264 | + * If $include_string was blank or '*' returns an empty array |
|
1265 | + */ |
|
1266 | + public function extract_includes_for_this_model($include_string, $model_name = null) |
|
1267 | + { |
|
1268 | + if (is_array($include_string)) { |
|
1269 | + $include_string = implode(',', $include_string); |
|
1270 | + } |
|
1271 | + if ($include_string === '*' || $include_string === '') { |
|
1272 | + return array(); |
|
1273 | + } |
|
1274 | + $includes = explode(',', $include_string); |
|
1275 | + $extracted_fields_to_include = array(); |
|
1276 | + if ($model_name) { |
|
1277 | + foreach ($includes as $field_to_include) { |
|
1278 | + $field_to_include = trim($field_to_include); |
|
1279 | + if (strpos($field_to_include, $model_name . '.') === 0) { |
|
1280 | + //found the model name at the exact start |
|
1281 | + $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include); |
|
1282 | + $extracted_fields_to_include[] = $field_sans_model_name; |
|
1283 | + } elseif ($field_to_include == $model_name) { |
|
1284 | + $extracted_fields_to_include[] = '*'; |
|
1285 | + } |
|
1286 | + } |
|
1287 | + } else { |
|
1288 | + //look for ones with no period |
|
1289 | + foreach ($includes as $field_to_include) { |
|
1290 | + $field_to_include = trim($field_to_include); |
|
1291 | + if ( |
|
1292 | + strpos($field_to_include, '.') === false |
|
1293 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
1294 | + ) { |
|
1295 | + $extracted_fields_to_include[] = $field_to_include; |
|
1296 | + } |
|
1297 | + } |
|
1298 | + } |
|
1299 | + return $extracted_fields_to_include; |
|
1300 | + } |
|
1301 | 1301 | } |
1302 | 1302 | |
1303 | 1303 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use EventEspresso\core\entities\models\JsonModelSchema; |
9 | 9 | use EE_Datetime_Field; |
10 | 10 | |
11 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
11 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
12 | 12 | exit('No direct script access allowed'); |
13 | 13 | } |
14 | 14 | |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | try { |
58 | 58 | $matches = $controller->parse_route( |
59 | 59 | $request->get_route(), |
60 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
60 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
61 | 61 | array('version', 'model') |
62 | 62 | ); |
63 | 63 | $controller->set_requested_version($matches['version']); |
64 | 64 | $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
65 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
65 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
66 | 66 | return $controller->send_response( |
67 | 67 | new \WP_Error( |
68 | 68 | 'endpoint_parsing_error', |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $controller = new Read(); |
100 | 100 | try { |
101 | 101 | $controller->set_requested_version($version); |
102 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name)) { |
|
102 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name)) { |
|
103 | 103 | return array(); |
104 | 104 | } |
105 | 105 | //get the model for this version |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | protected function _maybe_add_extra_fields_to_schema($field_name, \EE_Model_Field_Base $field, array $schema) |
194 | 194 | { |
195 | 195 | if ($field instanceof EE_Datetime_Field) { |
196 | - $schema['properties'][$field_name . '_gmt'] = $field->getSchema(); |
|
196 | + $schema['properties'][$field_name.'_gmt'] = $field->getSchema(); |
|
197 | 197 | //modify the description |
198 | - $schema['properties'][$field_name . '_gmt']['description'] = sprintf( |
|
198 | + $schema['properties'][$field_name.'_gmt']['description'] = sprintf( |
|
199 | 199 | esc_html__('%s - the value for this field is in GMT.', 'event_espresso'), |
200 | 200 | $field->get_nicename() |
201 | 201 | ); |
@@ -236,11 +236,11 @@ discard block |
||
236 | 236 | try { |
237 | 237 | $matches = $controller->parse_route( |
238 | 238 | $request->get_route(), |
239 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
239 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
240 | 240 | array('version', 'model', 'id')); |
241 | 241 | $controller->set_requested_version($matches['version']); |
242 | 242 | $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
243 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
243 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
244 | 244 | return $controller->send_response( |
245 | 245 | new \WP_Error( |
246 | 246 | 'endpoint_parsing_error', |
@@ -278,12 +278,12 @@ discard block |
||
278 | 278 | try { |
279 | 279 | $matches = $controller->parse_route( |
280 | 280 | $request->get_route(), |
281 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
281 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
282 | 282 | array('version', 'model', 'id', 'related_model') |
283 | 283 | ); |
284 | 284 | $controller->set_requested_version($matches['version']); |
285 | 285 | $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
286 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
286 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
287 | 287 | return $controller->send_response( |
288 | 288 | new \WP_Error( |
289 | 289 | 'endpoint_parsing_error', |
@@ -298,11 +298,11 @@ discard block |
||
298 | 298 | $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
299 | 299 | //assume the related model name is plural and try to find the model's name |
300 | 300 | $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
301 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
301 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
302 | 302 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
303 | 303 | $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
304 | 304 | } |
305 | - if (! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
305 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
306 | 306 | return $controller->send_response( |
307 | 307 | new \WP_Error( |
308 | 308 | 'endpoint_parsing_error', |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | public function get_entities_from_model($model, $request) |
339 | 339 | { |
340 | 340 | $query_params = $this->create_model_query_params($model, $request->get_params()); |
341 | - if (! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
341 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
342 | 342 | $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
343 | 343 | return new \WP_Error( |
344 | 344 | sprintf('rest_%s_cannot_list', $model_name_plural), |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | array('status' => 403) |
351 | 351 | ); |
352 | 352 | } |
353 | - if (! $request->get_header('no_rest_headers')) { |
|
353 | + if ( ! $request->get_header('no_rest_headers')) { |
|
354 | 354 | $this->_set_headers_from_query_params($model, $query_params); |
355 | 355 | } |
356 | 356 | /** @type array $results */ |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | $context = $this->validate_context($request->get_param('caps')); |
381 | 381 | $model = $relation->get_this_model(); |
382 | 382 | $related_model = $relation->get_other_model(); |
383 | - if (! isset($primary_model_query_params[0])) { |
|
383 | + if ( ! isset($primary_model_query_params[0])) { |
|
384 | 384 | $primary_model_query_params[0] = array(); |
385 | 385 | } |
386 | 386 | //check if they can access the 1st model object |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | } |
432 | 432 | $query_params['default_where_conditions'] = 'none'; |
433 | 433 | $query_params['caps'] = $context; |
434 | - if (! $request->get_header('no_rest_headers')) { |
|
434 | + if ( ! $request->get_header('no_rest_headers')) { |
|
435 | 435 | $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
436 | 436 | } |
437 | 437 | /** @type array $results */ |
@@ -483,7 +483,7 @@ discard block |
||
483 | 483 | */ |
484 | 484 | public function get_entities_from_relation($id, $relation, $request) |
485 | 485 | { |
486 | - if (! $relation->get_this_model()->has_primary_key_field()) { |
|
486 | + if ( ! $relation->get_this_model()->has_primary_key_field()) { |
|
487 | 487 | throw new \EE_Error( |
488 | 488 | sprintf( |
489 | 489 | __('Read::get_entities_from_relation should only be called from a model with a primary key, it was called from %1$s', |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | $this->_set_debug_info('missing caps', |
521 | 521 | Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
522 | 522 | //normally the limit to a 2-part array, where the 2nd item is the limit |
523 | - if (! isset($query_params['limit'])) { |
|
523 | + if ( ! isset($query_params['limit'])) { |
|
524 | 524 | $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
525 | 525 | } |
526 | 526 | if (is_array($query_params['limit'])) { |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | */ |
555 | 555 | public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) |
556 | 556 | { |
557 | - if (! $rest_request instanceof \WP_REST_Request) { |
|
557 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
558 | 558 | //ok so this was called in the old style, where the 3rd arg was |
559 | 559 | //$include, and the 4th arg was $context |
560 | 560 | //now setup the request just to avoid fatal errors, although we won't be able |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | global $post; |
630 | 630 | $old_post = $post; |
631 | 631 | $post = get_post($result[$model->primary_key_name()]); |
632 | - if (! $post instanceof \WP_Post) { |
|
632 | + if ( ! $post instanceof \WP_Post) { |
|
633 | 633 | //well that's weird, because $result is what we JUST fetched from the database |
634 | 634 | throw new Rest_Exception( |
635 | 635 | 'error_fetching_post_from_database_results', |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | ) |
640 | 640 | ); |
641 | 641 | } |
642 | - $model_object_classname = 'EE_' . $model->get_this_model_name(); |
|
642 | + $model_object_classname = 'EE_'.$model->get_this_model_name(); |
|
643 | 643 | $post->{$model_object_classname} = \EE_Registry::instance()->load_class( |
644 | 644 | $model_object_classname, |
645 | 645 | $result, |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | if ($field_value instanceof \DateTime) { |
671 | 671 | $timezone = $field_value->getTimezone(); |
672 | 672 | $field_value->setTimezone(new \DateTimeZone('UTC')); |
673 | - $result[$field_name . '_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
673 | + $result[$field_name.'_gmt'] = Model_Data_Translator::prepare_field_value_for_json( |
|
674 | 674 | $field_obj, |
675 | 675 | $field_value, |
676 | 676 | $this->get_model_version_info()->requested_version() |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | if ($model->has_primary_key_field()) { |
752 | 752 | foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
753 | 753 | $related_model_part = Read::get_related_entity_name($relation_name, $relation_obj); |
754 | - $links[\EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part] = array( |
|
754 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
755 | 755 | array( |
756 | 756 | 'href' => $this->get_versioned_link_to( |
757 | 757 | \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
@@ -786,13 +786,13 @@ discard block |
||
786 | 786 | $db_row = array() |
787 | 787 | ) { |
788 | 788 | //if $db_row not included, hope the entity array has what we need |
789 | - if (! $db_row) { |
|
789 | + if ( ! $db_row) { |
|
790 | 790 | $db_row = $entity_array; |
791 | 791 | } |
792 | 792 | $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
793 | 793 | $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
794 | 794 | //if they passed in * or didn't specify any includes, return everything |
795 | - if (! in_array('*', $includes_for_this_model) |
|
795 | + if ( ! in_array('*', $includes_for_this_model) |
|
796 | 796 | && ! empty($includes_for_this_model) |
797 | 797 | ) { |
798 | 798 | if ($model->has_primary_key_field()) { |
@@ -967,7 +967,7 @@ discard block |
||
967 | 967 | $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
968 | 968 | $this->_set_debug_info('model query params', $restricted_query_params); |
969 | 969 | $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
970 | - if (! empty ($model_rows)) { |
|
970 | + if ( ! empty ($model_rows)) { |
|
971 | 971 | return $this->create_entity_from_wpdb_result( |
972 | 972 | $model, |
973 | 973 | array_shift($model_rows), |
@@ -976,7 +976,7 @@ discard block |
||
976 | 976 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
977 | 977 | $lowercase_model_name = strtolower($model->get_this_model_name()); |
978 | 978 | $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
979 | - if (! empty($model_rows_found_sans_restrictions)) { |
|
979 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
980 | 980 | //you got shafted- it existed but we didn't want to tell you! |
981 | 981 | return new \WP_Error( |
982 | 982 | 'rest_user_cannot_read', |
@@ -1011,7 +1011,7 @@ discard block |
||
1011 | 1011 | */ |
1012 | 1012 | public function validate_context($context) |
1013 | 1013 | { |
1014 | - if (! $context) { |
|
1014 | + if ( ! $context) { |
|
1015 | 1015 | $context = \EEM_Base::caps_read; |
1016 | 1016 | } |
1017 | 1017 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
@@ -1037,7 +1037,7 @@ discard block |
||
1037 | 1037 | \EEM_Base::default_where_conditions_minimum_all, |
1038 | 1038 | \EEM_Base::default_where_conditions_minimum_others, |
1039 | 1039 | ); |
1040 | - if (! $default_query_params) { |
|
1040 | + if ( ! $default_query_params) { |
|
1041 | 1041 | $default_query_params = \EEM_Base::default_where_conditions_all; |
1042 | 1042 | } |
1043 | 1043 | if ( |
@@ -1122,14 +1122,14 @@ discard block |
||
1122 | 1122 | } |
1123 | 1123 | if (isset($query_parameters['limit'])) { |
1124 | 1124 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
1125 | - if (! is_array($query_parameters['limit'])) { |
|
1126 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
1125 | + if ( ! is_array($query_parameters['limit'])) { |
|
1126 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
1127 | 1127 | } else { |
1128 | 1128 | $limit_array = $query_parameters['limit']; |
1129 | 1129 | } |
1130 | 1130 | $sanitized_limit = array(); |
1131 | 1131 | foreach ($limit_array as $key => $limit_part) { |
1132 | - if ($this->_debug_mode && (! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
1132 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
1133 | 1133 | throw new \EE_Error( |
1134 | 1134 | sprintf( |
1135 | 1135 | __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | ) |
1139 | 1139 | ); |
1140 | 1140 | } |
1141 | - $sanitized_limit[] = (int)$limit_part; |
|
1141 | + $sanitized_limit[] = (int) $limit_part; |
|
1142 | 1142 | } |
1143 | 1143 | $model_query_params['limit'] = implode(',', $sanitized_limit); |
1144 | 1144 | } else { |
@@ -1226,17 +1226,17 @@ discard block |
||
1226 | 1226 | foreach ($exploded_contents as $item) { |
1227 | 1227 | $item = trim($item); |
1228 | 1228 | //if no prefix was provided, so we look for items with no "." in them |
1229 | - if (! $prefix) { |
|
1229 | + if ( ! $prefix) { |
|
1230 | 1230 | //does this item have a period? |
1231 | 1231 | if (strpos($item, '.') === false) { |
1232 | 1232 | //if not, then its what we're looking for |
1233 | 1233 | $contents_with_prefix[] = $item; |
1234 | 1234 | } |
1235 | - } else if (strpos($item, $prefix . '.') === 0) { |
|
1235 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
1236 | 1236 | //this item has the prefix and a period, grab it |
1237 | 1237 | $contents_with_prefix[] = substr( |
1238 | 1238 | $item, |
1239 | - strpos($item, $prefix . '.') + strlen($prefix . '.') |
|
1239 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
1240 | 1240 | ); |
1241 | 1241 | } else if ($item === $prefix) { |
1242 | 1242 | //this item is JUST the prefix |
@@ -1276,9 +1276,9 @@ discard block |
||
1276 | 1276 | if ($model_name) { |
1277 | 1277 | foreach ($includes as $field_to_include) { |
1278 | 1278 | $field_to_include = trim($field_to_include); |
1279 | - if (strpos($field_to_include, $model_name . '.') === 0) { |
|
1279 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
1280 | 1280 | //found the model name at the exact start |
1281 | - $field_sans_model_name = str_replace($model_name . '.', '', $field_to_include); |
|
1281 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
1282 | 1282 | $extracted_fields_to_include[] = $field_sans_model_name; |
1283 | 1283 | } elseif ($field_to_include == $model_name) { |
1284 | 1284 | $extracted_fields_to_include[] = '*'; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | } |
85 | 85 | } |
86 | 86 | return $this->shortcodeContent( |
87 | - $this->sanitizeAttributes((array)$attributes) |
|
87 | + $this->sanitizeAttributes((array) $attributes) |
|
88 | 88 | ); |
89 | 89 | } |
90 | 90 | |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | // serialized attributes |
113 | 113 | wp_json_encode($attributes), |
114 | 114 | // Closure for generating content if cache is expired |
115 | - function () use ($shortcode, $attributes) { |
|
116 | - if($shortcode->initialized() === false){ |
|
115 | + function() use ($shortcode, $attributes) { |
|
116 | + if ($shortcode->initialized() === false) { |
|
117 | 117 | $shortcode->initializeShortcode(); |
118 | 118 | } |
119 | 119 | return $shortcode->processShortcode($attributes); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * Returns whether or not this shortcode has been initialized |
248 | 248 | * @return boolean |
249 | 249 | */ |
250 | - public function initialized(){ |
|
250 | + public function initialized() { |
|
251 | 251 | return $this->initialized; |
252 | 252 | } |
253 | 253 |
@@ -23,230 +23,230 @@ |
||
23 | 23 | abstract class EspressoShortcode implements ShortcodeInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * transient prefix |
|
28 | - * |
|
29 | - * @type string |
|
30 | - */ |
|
31 | - const CACHE_TRANSIENT_PREFIX = 'ee_sc_'; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var PostRelatedCacheManager $cache_manager |
|
35 | - */ |
|
36 | - private $cache_manager; |
|
37 | - |
|
38 | - /** |
|
39 | - * true if ShortcodeInterface::initializeShortcode() has been called |
|
40 | - * if false, then that will get called before processing |
|
41 | - * |
|
42 | - * @var boolean $initialized |
|
43 | - */ |
|
44 | - private $initialized = false; |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * EspressoShortcode constructor |
|
50 | - * |
|
51 | - * @param PostRelatedCacheManager $cache_manager |
|
52 | - */ |
|
53 | - public function __construct(PostRelatedCacheManager $cache_manager) |
|
54 | - { |
|
55 | - $this->cache_manager = $cache_manager; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public function shortcodeHasBeenInitialized() |
|
64 | - { |
|
65 | - $this->initialized = true; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * enqueues scripts then processes the shortcode |
|
72 | - * |
|
73 | - * @param array $attributes |
|
74 | - * @return string |
|
75 | - * @throws EE_Error |
|
76 | - */ |
|
77 | - final public function processShortcodeCallback($attributes = array()) |
|
78 | - { |
|
79 | - if ($this instanceof EnqueueAssetsInterface) { |
|
80 | - if (is_admin()) { |
|
81 | - $this->enqueueAdminScripts(); |
|
82 | - } else { |
|
83 | - $this->enqueueScripts(); |
|
84 | - } |
|
85 | - } |
|
86 | - return $this->shortcodeContent( |
|
87 | - $this->sanitizeAttributes((array)$attributes) |
|
88 | - ); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * If shortcode caching is enabled for the shortcode, |
|
95 | - * and cached results exist, then that will be returned |
|
96 | - * else new content will be generated. |
|
97 | - * If caching is enabled, then the new content will be cached for later. |
|
98 | - * |
|
99 | - * @param array $attributes |
|
100 | - * @return mixed|string |
|
101 | - * @throws EE_Error |
|
102 | - */ |
|
103 | - private function shortcodeContent(array $attributes) |
|
104 | - { |
|
105 | - $shortcode = $this; |
|
106 | - $post_ID = $this->currentPostID(); |
|
107 | - // something like "SC_EVENTS-123" |
|
108 | - $cache_ID = $this->shortcodeCacheID($post_ID); |
|
109 | - $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID); |
|
110 | - return $this->cache_manager->get( |
|
111 | - $cache_ID, |
|
112 | - // serialized attributes |
|
113 | - wp_json_encode($attributes), |
|
114 | - // Closure for generating content if cache is expired |
|
115 | - function () use ($shortcode, $attributes) { |
|
116 | - if($shortcode->initialized() === false){ |
|
117 | - $shortcode->initializeShortcode(); |
|
118 | - } |
|
119 | - return $shortcode->processShortcode($attributes); |
|
120 | - }, |
|
121 | - // filterable cache expiration set by each shortcode |
|
122 | - apply_filters( |
|
123 | - 'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration', |
|
124 | - $this->cacheExpiration(), |
|
125 | - $this->getTag(), |
|
126 | - $this |
|
127 | - ) |
|
128 | - ); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @return int |
|
135 | - * @throws EE_Error |
|
136 | - */ |
|
137 | - private function currentPostID() |
|
138 | - { |
|
139 | - // try to get EE_Event any way we can |
|
140 | - $event = EEH_Event_View::get_event(); |
|
141 | - // then get some kind of ID |
|
142 | - if ($event instanceof EE_Event) { |
|
143 | - return $event->ID(); |
|
144 | - } |
|
145 | - global $post; |
|
146 | - if ($post instanceof WP_Post) { |
|
147 | - return $post->ID; |
|
148 | - } |
|
149 | - return 0; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param int $post_ID |
|
156 | - * @return string |
|
157 | - * @throws EE_Error |
|
158 | - */ |
|
159 | - private function shortcodeCacheID($post_ID) |
|
160 | - { |
|
161 | - $tag = str_replace('ESPRESSO_', '', $this->getTag()); |
|
162 | - return "SC_{$tag}-{$post_ID}"; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * array for defining custom attribute sanitization callbacks, |
|
169 | - * where keys match keys in your attributes array, |
|
170 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
171 | - * So for example, if you had an integer attribute named "event_id" |
|
172 | - * that you wanted to be sanitized using absint(), |
|
173 | - * then you would return the following: |
|
174 | - * array('event_id' => 'absint') |
|
175 | - * Entering 'skip_sanitization' for the callback value |
|
176 | - * means that no sanitization will be applied |
|
177 | - * on the assumption that the attribute |
|
178 | - * will be sanitized at some point... right? |
|
179 | - * You wouldn't pass around unsanitized attributes would you? |
|
180 | - * That would be very Tom Foolery of you!!! |
|
181 | - * |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - protected function customAttributeSanitizationMap() |
|
185 | - { |
|
186 | - return array(); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Performs basic sanitization on shortcode attributes |
|
193 | - * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
194 | - * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
195 | - * This can be overridden using the customAttributeSanitizationMap() method (see above), |
|
196 | - * all other attributes would be sanitized using the defaults in the switch statement below |
|
197 | - * |
|
198 | - * @param array $attributes |
|
199 | - * @return array |
|
200 | - */ |
|
201 | - private function sanitizeAttributes(array $attributes) |
|
202 | - { |
|
203 | - $custom_sanitization = $this->customAttributeSanitizationMap(); |
|
204 | - foreach ($attributes as $key => $value) { |
|
205 | - // is a custom sanitization callback specified ? |
|
206 | - if (isset($custom_sanitization[$key])) { |
|
207 | - $callback = $custom_sanitization[$key]; |
|
208 | - if ($callback === 'skip_sanitization') { |
|
209 | - $attributes[$key] = $value; |
|
210 | - continue; |
|
211 | - } |
|
212 | - if (function_exists($callback)) { |
|
213 | - $attributes[$key] = $callback($value); |
|
214 | - continue; |
|
215 | - } |
|
216 | - } |
|
217 | - switch (true) { |
|
218 | - case $value === null : |
|
219 | - case is_int($value) : |
|
220 | - case is_float($value) : |
|
221 | - // typical booleans |
|
222 | - case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
223 | - $attributes[$key] = $value; |
|
224 | - break; |
|
225 | - case is_string($value) : |
|
226 | - $attributes[$key] = sanitize_text_field($value); |
|
227 | - break; |
|
228 | - case is_array($value) : |
|
229 | - $attributes[$key] = $this->sanitizeAttributes($value); |
|
230 | - break; |
|
231 | - default : |
|
232 | - // only remaining data types are Object and Resource |
|
233 | - // which are not allowed as shortcode attributes |
|
234 | - $attributes[$key] = null; |
|
235 | - break; |
|
236 | - } |
|
237 | - } |
|
238 | - return $attributes; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Returns whether or not this shortcode has been initialized |
|
245 | - * @return boolean |
|
246 | - */ |
|
247 | - public function initialized(){ |
|
248 | - return $this->initialized; |
|
249 | - } |
|
26 | + /** |
|
27 | + * transient prefix |
|
28 | + * |
|
29 | + * @type string |
|
30 | + */ |
|
31 | + const CACHE_TRANSIENT_PREFIX = 'ee_sc_'; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var PostRelatedCacheManager $cache_manager |
|
35 | + */ |
|
36 | + private $cache_manager; |
|
37 | + |
|
38 | + /** |
|
39 | + * true if ShortcodeInterface::initializeShortcode() has been called |
|
40 | + * if false, then that will get called before processing |
|
41 | + * |
|
42 | + * @var boolean $initialized |
|
43 | + */ |
|
44 | + private $initialized = false; |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * EspressoShortcode constructor |
|
50 | + * |
|
51 | + * @param PostRelatedCacheManager $cache_manager |
|
52 | + */ |
|
53 | + public function __construct(PostRelatedCacheManager $cache_manager) |
|
54 | + { |
|
55 | + $this->cache_manager = $cache_manager; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public function shortcodeHasBeenInitialized() |
|
64 | + { |
|
65 | + $this->initialized = true; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * enqueues scripts then processes the shortcode |
|
72 | + * |
|
73 | + * @param array $attributes |
|
74 | + * @return string |
|
75 | + * @throws EE_Error |
|
76 | + */ |
|
77 | + final public function processShortcodeCallback($attributes = array()) |
|
78 | + { |
|
79 | + if ($this instanceof EnqueueAssetsInterface) { |
|
80 | + if (is_admin()) { |
|
81 | + $this->enqueueAdminScripts(); |
|
82 | + } else { |
|
83 | + $this->enqueueScripts(); |
|
84 | + } |
|
85 | + } |
|
86 | + return $this->shortcodeContent( |
|
87 | + $this->sanitizeAttributes((array)$attributes) |
|
88 | + ); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * If shortcode caching is enabled for the shortcode, |
|
95 | + * and cached results exist, then that will be returned |
|
96 | + * else new content will be generated. |
|
97 | + * If caching is enabled, then the new content will be cached for later. |
|
98 | + * |
|
99 | + * @param array $attributes |
|
100 | + * @return mixed|string |
|
101 | + * @throws EE_Error |
|
102 | + */ |
|
103 | + private function shortcodeContent(array $attributes) |
|
104 | + { |
|
105 | + $shortcode = $this; |
|
106 | + $post_ID = $this->currentPostID(); |
|
107 | + // something like "SC_EVENTS-123" |
|
108 | + $cache_ID = $this->shortcodeCacheID($post_ID); |
|
109 | + $this->cache_manager->clearPostRelatedCacheOnUpdate($post_ID, $cache_ID); |
|
110 | + return $this->cache_manager->get( |
|
111 | + $cache_ID, |
|
112 | + // serialized attributes |
|
113 | + wp_json_encode($attributes), |
|
114 | + // Closure for generating content if cache is expired |
|
115 | + function () use ($shortcode, $attributes) { |
|
116 | + if($shortcode->initialized() === false){ |
|
117 | + $shortcode->initializeShortcode(); |
|
118 | + } |
|
119 | + return $shortcode->processShortcode($attributes); |
|
120 | + }, |
|
121 | + // filterable cache expiration set by each shortcode |
|
122 | + apply_filters( |
|
123 | + 'FHEE__EventEspresso_core_services_shortcodes_EspressoShortcode__shortcodeContent__cache_expiration', |
|
124 | + $this->cacheExpiration(), |
|
125 | + $this->getTag(), |
|
126 | + $this |
|
127 | + ) |
|
128 | + ); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @return int |
|
135 | + * @throws EE_Error |
|
136 | + */ |
|
137 | + private function currentPostID() |
|
138 | + { |
|
139 | + // try to get EE_Event any way we can |
|
140 | + $event = EEH_Event_View::get_event(); |
|
141 | + // then get some kind of ID |
|
142 | + if ($event instanceof EE_Event) { |
|
143 | + return $event->ID(); |
|
144 | + } |
|
145 | + global $post; |
|
146 | + if ($post instanceof WP_Post) { |
|
147 | + return $post->ID; |
|
148 | + } |
|
149 | + return 0; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param int $post_ID |
|
156 | + * @return string |
|
157 | + * @throws EE_Error |
|
158 | + */ |
|
159 | + private function shortcodeCacheID($post_ID) |
|
160 | + { |
|
161 | + $tag = str_replace('ESPRESSO_', '', $this->getTag()); |
|
162 | + return "SC_{$tag}-{$post_ID}"; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * array for defining custom attribute sanitization callbacks, |
|
169 | + * where keys match keys in your attributes array, |
|
170 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
171 | + * So for example, if you had an integer attribute named "event_id" |
|
172 | + * that you wanted to be sanitized using absint(), |
|
173 | + * then you would return the following: |
|
174 | + * array('event_id' => 'absint') |
|
175 | + * Entering 'skip_sanitization' for the callback value |
|
176 | + * means that no sanitization will be applied |
|
177 | + * on the assumption that the attribute |
|
178 | + * will be sanitized at some point... right? |
|
179 | + * You wouldn't pass around unsanitized attributes would you? |
|
180 | + * That would be very Tom Foolery of you!!! |
|
181 | + * |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + protected function customAttributeSanitizationMap() |
|
185 | + { |
|
186 | + return array(); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Performs basic sanitization on shortcode attributes |
|
193 | + * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
194 | + * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
195 | + * This can be overridden using the customAttributeSanitizationMap() method (see above), |
|
196 | + * all other attributes would be sanitized using the defaults in the switch statement below |
|
197 | + * |
|
198 | + * @param array $attributes |
|
199 | + * @return array |
|
200 | + */ |
|
201 | + private function sanitizeAttributes(array $attributes) |
|
202 | + { |
|
203 | + $custom_sanitization = $this->customAttributeSanitizationMap(); |
|
204 | + foreach ($attributes as $key => $value) { |
|
205 | + // is a custom sanitization callback specified ? |
|
206 | + if (isset($custom_sanitization[$key])) { |
|
207 | + $callback = $custom_sanitization[$key]; |
|
208 | + if ($callback === 'skip_sanitization') { |
|
209 | + $attributes[$key] = $value; |
|
210 | + continue; |
|
211 | + } |
|
212 | + if (function_exists($callback)) { |
|
213 | + $attributes[$key] = $callback($value); |
|
214 | + continue; |
|
215 | + } |
|
216 | + } |
|
217 | + switch (true) { |
|
218 | + case $value === null : |
|
219 | + case is_int($value) : |
|
220 | + case is_float($value) : |
|
221 | + // typical booleans |
|
222 | + case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
223 | + $attributes[$key] = $value; |
|
224 | + break; |
|
225 | + case is_string($value) : |
|
226 | + $attributes[$key] = sanitize_text_field($value); |
|
227 | + break; |
|
228 | + case is_array($value) : |
|
229 | + $attributes[$key] = $this->sanitizeAttributes($value); |
|
230 | + break; |
|
231 | + default : |
|
232 | + // only remaining data types are Object and Resource |
|
233 | + // which are not allowed as shortcode attributes |
|
234 | + $attributes[$key] = null; |
|
235 | + break; |
|
236 | + } |
|
237 | + } |
|
238 | + return $attributes; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Returns whether or not this shortcode has been initialized |
|
245 | + * @return boolean |
|
246 | + */ |
|
247 | + public function initialized(){ |
|
248 | + return $this->initialized; |
|
249 | + } |
|
250 | 250 | |
251 | 251 | |
252 | 252 |
@@ -8,52 +8,52 @@ |
||
8 | 8 | interface ShortcodeInterface |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * the actual shortcode tag that gets registered with WordPress |
|
13 | - * |
|
14 | - * @return string |
|
15 | - */ |
|
16 | - public function getTag(); |
|
17 | - |
|
18 | - /** |
|
19 | - * the length of time in seconds to cache the results of the processShortcode() method |
|
20 | - * 0 means the processShortcode() results will NOT be cached at all |
|
21 | - * |
|
22 | - * @return int |
|
23 | - */ |
|
24 | - public function cacheExpiration(); |
|
25 | - |
|
26 | - /** |
|
27 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
28 | - * this may be required for shortcodes that utilize a corresponding module, |
|
29 | - * and need to enqueue assets for that module |
|
30 | - * |
|
31 | - * !!! IMPORTANT !!! |
|
32 | - * After performing any logic within this method required for initialization |
|
33 | - * $this->shortcodeHasBeenInitialized(); |
|
34 | - * should be called to ensure that the shortcode is setup correctly. |
|
35 | - * |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - public function initializeShortcode(); |
|
39 | - |
|
40 | - /** |
|
41 | - * callback that runs when the shortcode is encountered in post content. |
|
42 | - * IMPORTANT !!! |
|
43 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
44 | - * |
|
45 | - * @param array $attributes |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function processShortcode($attributes = array()); |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Returns whether or not this shortcode class has already been initialized |
|
54 | - * @return boolean |
|
55 | - */ |
|
56 | - public function initialized(); |
|
11 | + /** |
|
12 | + * the actual shortcode tag that gets registered with WordPress |
|
13 | + * |
|
14 | + * @return string |
|
15 | + */ |
|
16 | + public function getTag(); |
|
17 | + |
|
18 | + /** |
|
19 | + * the length of time in seconds to cache the results of the processShortcode() method |
|
20 | + * 0 means the processShortcode() results will NOT be cached at all |
|
21 | + * |
|
22 | + * @return int |
|
23 | + */ |
|
24 | + public function cacheExpiration(); |
|
25 | + |
|
26 | + /** |
|
27 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
28 | + * this may be required for shortcodes that utilize a corresponding module, |
|
29 | + * and need to enqueue assets for that module |
|
30 | + * |
|
31 | + * !!! IMPORTANT !!! |
|
32 | + * After performing any logic within this method required for initialization |
|
33 | + * $this->shortcodeHasBeenInitialized(); |
|
34 | + * should be called to ensure that the shortcode is setup correctly. |
|
35 | + * |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + public function initializeShortcode(); |
|
39 | + |
|
40 | + /** |
|
41 | + * callback that runs when the shortcode is encountered in post content. |
|
42 | + * IMPORTANT !!! |
|
43 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
44 | + * |
|
45 | + * @param array $attributes |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function processShortcode($attributes = array()); |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Returns whether or not this shortcode class has already been initialized |
|
54 | + * @return boolean |
|
55 | + */ |
|
56 | + public function initialized(); |
|
57 | 57 | |
58 | 58 | } |
59 | 59 | // End of file ShortcodeInterface.php |
@@ -14,1264 +14,1264 @@ |
||
14 | 14 | { |
15 | 15 | |
16 | 16 | |
17 | - /** |
|
18 | - * Extend_Events_Admin_Page constructor. |
|
19 | - * |
|
20 | - * @param bool $routing |
|
21 | - */ |
|
22 | - public function __construct($routing = true) |
|
23 | - { |
|
24 | - parent::__construct($routing); |
|
25 | - if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
26 | - define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
27 | - define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
28 | - define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
29 | - } |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Sets routes. |
|
35 | - */ |
|
36 | - protected function _extend_page_config() |
|
37 | - { |
|
38 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
39 | - //is there a evt_id in the request? |
|
40 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
41 | - ? $this->_req_data['EVT_ID'] |
|
42 | - : 0; |
|
43 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
44 | - //tkt_id? |
|
45 | - $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
46 | - ? $this->_req_data['TKT_ID'] |
|
47 | - : 0; |
|
48 | - $new_page_routes = array( |
|
49 | - 'duplicate_event' => array( |
|
50 | - 'func' => '_duplicate_event', |
|
51 | - 'capability' => 'ee_edit_event', |
|
52 | - 'obj_id' => $evt_id, |
|
53 | - 'noheader' => true, |
|
54 | - ), |
|
55 | - 'ticket_list_table' => array( |
|
56 | - 'func' => '_tickets_overview_list_table', |
|
57 | - 'capability' => 'ee_read_default_tickets', |
|
58 | - ), |
|
59 | - 'trash_ticket' => array( |
|
60 | - 'func' => '_trash_or_restore_ticket', |
|
61 | - 'capability' => 'ee_delete_default_ticket', |
|
62 | - 'obj_id' => $tkt_id, |
|
63 | - 'noheader' => true, |
|
64 | - 'args' => array('trash' => true), |
|
65 | - ), |
|
66 | - 'trash_tickets' => array( |
|
67 | - 'func' => '_trash_or_restore_ticket', |
|
68 | - 'capability' => 'ee_delete_default_tickets', |
|
69 | - 'noheader' => true, |
|
70 | - 'args' => array('trash' => true), |
|
71 | - ), |
|
72 | - 'restore_ticket' => array( |
|
73 | - 'func' => '_trash_or_restore_ticket', |
|
74 | - 'capability' => 'ee_delete_default_ticket', |
|
75 | - 'obj_id' => $tkt_id, |
|
76 | - 'noheader' => true, |
|
77 | - ), |
|
78 | - 'restore_tickets' => array( |
|
79 | - 'func' => '_trash_or_restore_ticket', |
|
80 | - 'capability' => 'ee_delete_default_tickets', |
|
81 | - 'noheader' => true, |
|
82 | - ), |
|
83 | - 'delete_ticket' => array( |
|
84 | - 'func' => '_delete_ticket', |
|
85 | - 'capability' => 'ee_delete_default_ticket', |
|
86 | - 'obj_id' => $tkt_id, |
|
87 | - 'noheader' => true, |
|
88 | - ), |
|
89 | - 'delete_tickets' => array( |
|
90 | - 'func' => '_delete_ticket', |
|
91 | - 'capability' => 'ee_delete_default_tickets', |
|
92 | - 'noheader' => true, |
|
93 | - ), |
|
94 | - 'import_page' => array( |
|
95 | - 'func' => '_import_page', |
|
96 | - 'capability' => 'import', |
|
97 | - ), |
|
98 | - 'import' => array( |
|
99 | - 'func' => '_import_events', |
|
100 | - 'capability' => 'import', |
|
101 | - 'noheader' => true, |
|
102 | - ), |
|
103 | - 'import_events' => array( |
|
104 | - 'func' => '_import_events', |
|
105 | - 'capability' => 'import', |
|
106 | - 'noheader' => true, |
|
107 | - ), |
|
108 | - 'export_events' => array( |
|
109 | - 'func' => '_events_export', |
|
110 | - 'capability' => 'export', |
|
111 | - 'noheader' => true, |
|
112 | - ), |
|
113 | - 'export_categories' => array( |
|
114 | - 'func' => '_categories_export', |
|
115 | - 'capability' => 'export', |
|
116 | - 'noheader' => true, |
|
117 | - ), |
|
118 | - 'sample_export_file' => array( |
|
119 | - 'func' => '_sample_export_file', |
|
120 | - 'capability' => 'export', |
|
121 | - 'noheader' => true, |
|
122 | - ), |
|
123 | - 'update_template_settings' => array( |
|
124 | - 'func' => '_update_template_settings', |
|
125 | - 'capability' => 'manage_options', |
|
126 | - 'noheader' => true, |
|
127 | - ), |
|
128 | - ); |
|
129 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
130 | - //partial route/config override |
|
131 | - $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
132 | - $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
133 | - $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
134 | - $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
135 | - $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
136 | - $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
137 | - //add tickets tab but only if there are more than one default ticket! |
|
138 | - $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
139 | - array(array('TKT_is_default' => 1)), |
|
140 | - 'TKT_ID', |
|
141 | - true |
|
142 | - ); |
|
143 | - if ($tkt_count > 1) { |
|
144 | - $new_page_config = array( |
|
145 | - 'ticket_list_table' => array( |
|
146 | - 'nav' => array( |
|
147 | - 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
148 | - 'order' => 60, |
|
149 | - ), |
|
150 | - 'list_table' => 'Tickets_List_Table', |
|
151 | - 'require_nonce' => false, |
|
152 | - ), |
|
153 | - ); |
|
154 | - } |
|
155 | - //template settings |
|
156 | - $new_page_config['template_settings'] = array( |
|
157 | - 'nav' => array( |
|
158 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
159 | - 'order' => 30, |
|
160 | - ), |
|
161 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
162 | - 'help_tabs' => array( |
|
163 | - 'general_settings_templates_help_tab' => array( |
|
164 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
165 | - 'filename' => 'general_settings_templates', |
|
166 | - ), |
|
167 | - ), |
|
168 | - 'help_tour' => array('Templates_Help_Tour'), |
|
169 | - 'require_nonce' => false, |
|
170 | - ); |
|
171 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
172 | - //add filters and actions |
|
173 | - //modifying _views |
|
174 | - add_filter( |
|
175 | - 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
176 | - array($this, 'add_additional_datetime_button'), |
|
177 | - 10, |
|
178 | - 2 |
|
179 | - ); |
|
180 | - add_filter( |
|
181 | - 'FHEE_event_datetime_metabox_clone_button_template', |
|
182 | - array($this, 'add_datetime_clone_button'), |
|
183 | - 10, |
|
184 | - 2 |
|
185 | - ); |
|
186 | - add_filter( |
|
187 | - 'FHEE_event_datetime_metabox_timezones_template', |
|
188 | - array($this, 'datetime_timezones_template'), |
|
189 | - 10, |
|
190 | - 2 |
|
191 | - ); |
|
192 | - //filters for event list table |
|
193 | - add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
194 | - add_filter( |
|
195 | - 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
196 | - array($this, 'extra_list_table_actions'), |
|
197 | - 10, |
|
198 | - 2 |
|
199 | - ); |
|
200 | - //legend item |
|
201 | - add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
202 | - add_action('admin_init', array($this, 'admin_init')); |
|
203 | - //heartbeat stuff |
|
204 | - add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * admin_init |
|
210 | - */ |
|
211 | - public function admin_init() |
|
212 | - { |
|
213 | - EE_Registry::$i18n_js_strings = array_merge( |
|
214 | - EE_Registry::$i18n_js_strings, |
|
215 | - array( |
|
216 | - 'image_confirm' => esc_html__( |
|
217 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
221 | - 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
222 | - 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
223 | - 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
224 | - 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
225 | - ) |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
232 | - * accordingly. |
|
233 | - * |
|
234 | - * @param array $response The existing heartbeat response array. |
|
235 | - * @param array $data The incoming data package. |
|
236 | - * @return array possibly appended response. |
|
237 | - */ |
|
238 | - public function heartbeat_response($response, $data) |
|
239 | - { |
|
240 | - /** |
|
241 | - * check whether count of tickets is approaching the potential |
|
242 | - * limits for the server. |
|
243 | - */ |
|
244 | - if (! empty($data['input_count'])) { |
|
245 | - $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
246 | - $data['input_count'] |
|
247 | - ); |
|
248 | - } |
|
249 | - return $response; |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * Add per page screen options to the default ticket list table view. |
|
255 | - */ |
|
256 | - protected function _add_screen_options_ticket_list_table() |
|
257 | - { |
|
258 | - $this->_per_page_screen_option(); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @param string $return |
|
264 | - * @param int $id |
|
265 | - * @param string $new_title |
|
266 | - * @param string $new_slug |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
270 | - { |
|
271 | - $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
272 | - //make sure this is only when editing |
|
273 | - if (! empty($id)) { |
|
274 | - $href = EE_Admin_Page::add_query_args_and_nonce( |
|
275 | - array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
276 | - $this->_admin_base_url |
|
277 | - ); |
|
278 | - $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
279 | - $return .= '<a href="' |
|
280 | - . $href |
|
281 | - . '" title="' |
|
282 | - . $title |
|
283 | - . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
284 | - . $title |
|
285 | - . '</button>'; |
|
286 | - } |
|
287 | - return $return; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Set the list table views for the default ticket list table view. |
|
293 | - */ |
|
294 | - public function _set_list_table_views_ticket_list_table() |
|
295 | - { |
|
296 | - $this->_views = array( |
|
297 | - 'all' => array( |
|
298 | - 'slug' => 'all', |
|
299 | - 'label' => esc_html__('All', 'event_espresso'), |
|
300 | - 'count' => 0, |
|
301 | - 'bulk_action' => array( |
|
302 | - 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
303 | - ), |
|
304 | - ), |
|
305 | - 'trashed' => array( |
|
306 | - 'slug' => 'trashed', |
|
307 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
308 | - 'count' => 0, |
|
309 | - 'bulk_action' => array( |
|
310 | - 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
311 | - 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
312 | - ), |
|
313 | - ), |
|
314 | - ); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Enqueue scripts and styles for the event editor. |
|
320 | - */ |
|
321 | - public function load_scripts_styles_edit() |
|
322 | - { |
|
323 | - wp_register_script( |
|
324 | - 'ee-event-editor-heartbeat', |
|
325 | - EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
326 | - array('ee_admin_js', 'heartbeat'), |
|
327 | - EVENT_ESPRESSO_VERSION, |
|
328 | - true |
|
329 | - ); |
|
330 | - wp_enqueue_script('ee-accounting'); |
|
331 | - //styles |
|
332 | - wp_enqueue_style('espresso-ui-theme'); |
|
333 | - wp_enqueue_script('event_editor_js'); |
|
334 | - wp_enqueue_script('ee-event-editor-heartbeat'); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Returns template for the additional datetime. |
|
340 | - * @param $template |
|
341 | - * @param $template_args |
|
342 | - * @return mixed |
|
343 | - * @throws DomainException |
|
344 | - */ |
|
345 | - public function add_additional_datetime_button($template, $template_args) |
|
346 | - { |
|
347 | - return EEH_Template::display_template( |
|
348 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
349 | - $template_args, |
|
350 | - true |
|
351 | - ); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Returns the template for cloning a datetime. |
|
357 | - * @param $template |
|
358 | - * @param $template_args |
|
359 | - * @return mixed |
|
360 | - * @throws DomainException |
|
361 | - */ |
|
362 | - public function add_datetime_clone_button($template, $template_args) |
|
363 | - { |
|
364 | - return EEH_Template::display_template( |
|
365 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
366 | - $template_args, |
|
367 | - true |
|
368 | - ); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Returns the template for datetime timezones. |
|
374 | - * @param $template |
|
375 | - * @param $template_args |
|
376 | - * @return mixed |
|
377 | - * @throws DomainException |
|
378 | - */ |
|
379 | - public function datetime_timezones_template($template, $template_args) |
|
380 | - { |
|
381 | - return EEH_Template::display_template( |
|
382 | - EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
383 | - $template_args, |
|
384 | - true |
|
385 | - ); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Sets the views for the default list table view. |
|
391 | - */ |
|
392 | - protected function _set_list_table_views_default() |
|
393 | - { |
|
394 | - parent::_set_list_table_views_default(); |
|
395 | - $new_views = array( |
|
396 | - 'today' => array( |
|
397 | - 'slug' => 'today', |
|
398 | - 'label' => esc_html__('Today', 'event_espresso'), |
|
399 | - 'count' => $this->total_events_today(), |
|
400 | - 'bulk_action' => array( |
|
401 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
402 | - ), |
|
403 | - ), |
|
404 | - 'month' => array( |
|
405 | - 'slug' => 'month', |
|
406 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
407 | - 'count' => $this->total_events_this_month(), |
|
408 | - 'bulk_action' => array( |
|
409 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
410 | - ), |
|
411 | - ), |
|
412 | - ); |
|
413 | - $this->_views = array_merge($this->_views, $new_views); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Returns the extra action links for the default list table view. |
|
419 | - * @param array $action_links |
|
420 | - * @param \EE_Event $event |
|
421 | - * @return array |
|
422 | - * @throws EE_Error |
|
423 | - */ |
|
424 | - public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
425 | - { |
|
426 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
427 | - 'ee_read_registrations', |
|
428 | - 'espresso_registrations_reports', |
|
429 | - $event->ID() |
|
430 | - ) |
|
431 | - ) { |
|
432 | - $reports_query_args = array( |
|
433 | - 'action' => 'reports', |
|
434 | - 'EVT_ID' => $event->ID(), |
|
435 | - ); |
|
436 | - $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
437 | - $action_links[] = '<a href="' |
|
438 | - . $reports_link |
|
439 | - . '" title="' |
|
440 | - . esc_attr__('View Report', 'event_espresso') |
|
441 | - . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
442 | - . "\n\t"; |
|
443 | - } |
|
444 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
445 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
446 | - $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
447 | - 'see_notifications_for', |
|
448 | - null, |
|
449 | - array('EVT_ID' => $event->ID()) |
|
450 | - ); |
|
451 | - } |
|
452 | - return $action_links; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * @param $items |
|
458 | - * @return mixed |
|
459 | - */ |
|
460 | - public function additional_legend_items($items) |
|
461 | - { |
|
462 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
463 | - 'ee_read_registrations', |
|
464 | - 'espresso_registrations_reports' |
|
465 | - ) |
|
466 | - ) { |
|
467 | - $items['reports'] = array( |
|
468 | - 'class' => 'dashicons dashicons-chart-bar', |
|
469 | - 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
470 | - ); |
|
471 | - } |
|
472 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
473 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
474 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
475 | - $items['view_related_messages'] = array( |
|
476 | - 'class' => $related_for_icon['css_class'], |
|
477 | - 'desc' => $related_for_icon['label'], |
|
478 | - ); |
|
479 | - } |
|
480 | - } |
|
481 | - return $items; |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * This is the callback method for the duplicate event route |
|
487 | - * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
488 | - * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
489 | - * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
490 | - * After duplication the redirect is to the new event edit page. |
|
491 | - * |
|
492 | - * @return void |
|
493 | - * @access protected |
|
494 | - * @throws EE_Error If EE_Event is not available with given ID |
|
495 | - */ |
|
496 | - protected function _duplicate_event() |
|
497 | - { |
|
498 | - // first make sure the ID for the event is in the request. |
|
499 | - // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
500 | - if (! isset($this->_req_data['EVT_ID'])) { |
|
501 | - EE_Error::add_error( |
|
502 | - esc_html__( |
|
503 | - 'In order to duplicate an event an Event ID is required. None was given.', |
|
504 | - 'event_espresso' |
|
505 | - ), |
|
506 | - __FILE__, |
|
507 | - __FUNCTION__, |
|
508 | - __LINE__ |
|
509 | - ); |
|
510 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
511 | - return; |
|
512 | - } |
|
513 | - //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
514 | - $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
515 | - if (! $orig_event instanceof EE_Event) { |
|
516 | - throw new EE_Error( |
|
517 | - sprintf( |
|
518 | - esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
519 | - $this->_req_data['EVT_ID'] |
|
520 | - ) |
|
521 | - ); |
|
522 | - } |
|
523 | - //k now let's clone the $orig_event before getting relations |
|
524 | - $new_event = clone $orig_event; |
|
525 | - //original datetimes |
|
526 | - $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
527 | - //other original relations |
|
528 | - $orig_ven = $orig_event->get_many_related('Venue'); |
|
529 | - //reset the ID and modify other details to make it clear this is a dupe |
|
530 | - $new_event->set('EVT_ID', 0); |
|
531 | - $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
532 | - $new_event->set('EVT_name', $new_name); |
|
533 | - $new_event->set( |
|
534 | - 'EVT_slug', |
|
535 | - wp_unique_post_slug( |
|
536 | - sanitize_title($orig_event->name()), |
|
537 | - 0, |
|
538 | - 'publish', |
|
539 | - 'espresso_events', |
|
540 | - 0 |
|
541 | - ) |
|
542 | - ); |
|
543 | - $new_event->set('status', 'draft'); |
|
544 | - //duplicate discussion settings |
|
545 | - $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
546 | - $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
547 | - //save the new event |
|
548 | - $new_event->save(); |
|
549 | - //venues |
|
550 | - foreach ($orig_ven as $ven) { |
|
551 | - $new_event->_add_relation_to($ven, 'Venue'); |
|
552 | - } |
|
553 | - $new_event->save(); |
|
554 | - //now we need to get the question group relations and handle that |
|
555 | - //first primary question groups |
|
556 | - $orig_primary_qgs = $orig_event->get_many_related( |
|
557 | - 'Question_Group', |
|
558 | - array(array('Event_Question_Group.EQG_primary' => 1)) |
|
559 | - ); |
|
560 | - if (! empty($orig_primary_qgs)) { |
|
561 | - foreach ($orig_primary_qgs as $id => $obj) { |
|
562 | - if ($obj instanceof EE_Question_Group) { |
|
563 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
564 | - } |
|
565 | - } |
|
566 | - } |
|
567 | - //next additional attendee question groups |
|
568 | - $orig_additional_qgs = $orig_event->get_many_related( |
|
569 | - 'Question_Group', |
|
570 | - array(array('Event_Question_Group.EQG_primary' => 0)) |
|
571 | - ); |
|
572 | - if (! empty($orig_additional_qgs)) { |
|
573 | - foreach ($orig_additional_qgs as $id => $obj) { |
|
574 | - if ($obj instanceof EE_Question_Group) { |
|
575 | - $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
576 | - } |
|
577 | - } |
|
578 | - } |
|
579 | - |
|
580 | - $new_event->save(); |
|
581 | - |
|
582 | - //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
583 | - $cloned_tickets = array(); |
|
584 | - foreach ($orig_datetimes as $orig_dtt) { |
|
585 | - if (! $orig_dtt instanceof EE_Datetime) { |
|
586 | - continue; |
|
587 | - } |
|
588 | - $new_dtt = clone $orig_dtt; |
|
589 | - $orig_tkts = $orig_dtt->tickets(); |
|
590 | - //save new dtt then add to event |
|
591 | - $new_dtt->set('DTT_ID', 0); |
|
592 | - $new_dtt->set('DTT_sold', 0); |
|
593 | - $new_dtt->set_reserved(0); |
|
594 | - $new_dtt->save(); |
|
595 | - $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
596 | - $new_event->save(); |
|
597 | - //now let's get the ticket relations setup. |
|
598 | - foreach ((array)$orig_tkts as $orig_tkt) { |
|
599 | - //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
600 | - if (! $orig_tkt instanceof EE_Ticket) { |
|
601 | - continue; |
|
602 | - } |
|
603 | - //is this ticket archived? If it is then let's skip |
|
604 | - if ($orig_tkt->get('TKT_deleted')) { |
|
605 | - continue; |
|
606 | - } |
|
607 | - // does this original ticket already exist in the clone_tickets cache? |
|
608 | - // If so we'll just use the new ticket from it. |
|
609 | - if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
610 | - $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
611 | - } else { |
|
612 | - $new_tkt = clone $orig_tkt; |
|
613 | - //get relations on the $orig_tkt that we need to setup. |
|
614 | - $orig_prices = $orig_tkt->prices(); |
|
615 | - $new_tkt->set('TKT_ID', 0); |
|
616 | - $new_tkt->set('TKT_sold', 0); |
|
617 | - $new_tkt->set('TKT_reserved', 0); |
|
618 | - $new_tkt->save(); //make sure new ticket has ID. |
|
619 | - //price relations on new ticket need to be setup. |
|
620 | - foreach ($orig_prices as $orig_price) { |
|
621 | - $new_price = clone $orig_price; |
|
622 | - $new_price->set('PRC_ID', 0); |
|
623 | - $new_price->save(); |
|
624 | - $new_tkt->_add_relation_to($new_price, 'Price'); |
|
625 | - $new_tkt->save(); |
|
626 | - } |
|
627 | - |
|
628 | - do_action( |
|
629 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
630 | - $orig_tkt, |
|
631 | - $new_tkt, |
|
632 | - $orig_prices, |
|
633 | - $orig_event, |
|
634 | - $orig_dtt, |
|
635 | - $new_dtt |
|
636 | - ); |
|
637 | - } |
|
638 | - // k now we can add the new ticket as a relation to the new datetime |
|
639 | - // and make sure its added to our cached $cloned_tickets array |
|
640 | - // for use with later datetimes that have the same ticket. |
|
641 | - $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
642 | - $new_dtt->save(); |
|
643 | - $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
644 | - } |
|
645 | - } |
|
646 | - //clone taxonomy information |
|
647 | - $taxonomies_to_clone_with = apply_filters( |
|
648 | - 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
649 | - array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
650 | - ); |
|
651 | - //get terms for original event (notice) |
|
652 | - $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
653 | - //loop through terms and add them to new event. |
|
654 | - foreach ($orig_terms as $term) { |
|
655 | - wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
656 | - } |
|
657 | - |
|
658 | - //duplicate other core WP_Post items for this event. |
|
659 | - //post thumbnail (feature image). |
|
660 | - $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
661 | - if ($feature_image_id) { |
|
662 | - update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
663 | - } |
|
664 | - |
|
665 | - //duplicate page_template setting |
|
666 | - $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
667 | - if ($page_template) { |
|
668 | - update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
669 | - } |
|
670 | - |
|
671 | - do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
672 | - //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
673 | - if ($new_event->ID()) { |
|
674 | - $redirect_args = array( |
|
675 | - 'post' => $new_event->ID(), |
|
676 | - 'action' => 'edit', |
|
677 | - ); |
|
678 | - EE_Error::add_success( |
|
679 | - esc_html__( |
|
680 | - 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
681 | - 'event_espresso' |
|
682 | - ) |
|
683 | - ); |
|
684 | - } else { |
|
685 | - $redirect_args = array( |
|
686 | - 'action' => 'default', |
|
687 | - ); |
|
688 | - EE_Error::add_error( |
|
689 | - esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
690 | - __FILE__, |
|
691 | - __FUNCTION__, |
|
692 | - __LINE__ |
|
693 | - ); |
|
694 | - } |
|
695 | - $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * Generates output for the import page. |
|
701 | - * @throws DomainException |
|
702 | - */ |
|
703 | - protected function _import_page() |
|
704 | - { |
|
705 | - $title = esc_html__('Import', 'event_espresso'); |
|
706 | - $intro = esc_html__( |
|
707 | - 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
708 | - 'event_espresso' |
|
709 | - ); |
|
710 | - $form_url = EVENTS_ADMIN_URL; |
|
711 | - $action = 'import_events'; |
|
712 | - $type = 'csv'; |
|
713 | - $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
714 | - $title, $intro, $form_url, $action, $type |
|
715 | - ); |
|
716 | - $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
717 | - array('action' => 'sample_export_file'), |
|
718 | - $this->_admin_base_url |
|
719 | - ); |
|
720 | - $content = EEH_Template::display_template( |
|
721 | - EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
722 | - $this->_template_args, |
|
723 | - true |
|
724 | - ); |
|
725 | - $this->_template_args['admin_page_content'] = $content; |
|
726 | - $this->display_admin_page_with_sidebar(); |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * _import_events |
|
732 | - * This handles displaying the screen and running imports for importing events. |
|
733 | - * |
|
734 | - * @return void |
|
735 | - */ |
|
736 | - protected function _import_events() |
|
737 | - { |
|
738 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
739 | - $success = EE_Import::instance()->import(); |
|
740 | - $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
741 | - } |
|
742 | - |
|
743 | - |
|
744 | - /** |
|
745 | - * _events_export |
|
746 | - * Will export all (or just the given event) to a Excel compatible file. |
|
747 | - * |
|
748 | - * @access protected |
|
749 | - * @return void |
|
750 | - */ |
|
751 | - protected function _events_export() |
|
752 | - { |
|
753 | - if (isset($this->_req_data['EVT_ID'])) { |
|
754 | - $event_ids = $this->_req_data['EVT_ID']; |
|
755 | - } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
756 | - $event_ids = $this->_req_data['EVT_IDs']; |
|
757 | - } else { |
|
758 | - $event_ids = null; |
|
759 | - } |
|
760 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
761 | - $new_request_args = array( |
|
762 | - 'export' => 'report', |
|
763 | - 'action' => 'all_event_data', |
|
764 | - 'EVT_ID' => $event_ids, |
|
765 | - ); |
|
766 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
767 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
768 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
769 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
770 | - $EE_Export->export(); |
|
771 | - } |
|
772 | - } |
|
773 | - |
|
774 | - |
|
775 | - /** |
|
776 | - * handle category exports() |
|
777 | - * |
|
778 | - * @return void |
|
779 | - */ |
|
780 | - protected function _categories_export() |
|
781 | - { |
|
782 | - //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
783 | - $new_request_args = array( |
|
784 | - 'export' => 'report', |
|
785 | - 'action' => 'categories', |
|
786 | - 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
787 | - ); |
|
788 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
789 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
790 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
791 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
792 | - $EE_Export->export(); |
|
793 | - } |
|
794 | - } |
|
795 | - |
|
796 | - |
|
797 | - /** |
|
798 | - * Creates a sample CSV file for importing |
|
799 | - */ |
|
800 | - protected function _sample_export_file() |
|
801 | - { |
|
802 | - // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
803 | - EE_Export::instance()->export_sample(); |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - /************* Template Settings *************/ |
|
808 | - /** |
|
809 | - * Generates template settings page output |
|
810 | - * @throws DomainException |
|
811 | - * @throws EE_Error |
|
812 | - */ |
|
813 | - protected function _template_settings() |
|
814 | - { |
|
815 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
816 | - /** |
|
817 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
818 | - * from General_Settings_Admin_Page to here. |
|
819 | - */ |
|
820 | - $this->_template_args = apply_filters( |
|
821 | - 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
822 | - $this->_template_args |
|
823 | - ); |
|
824 | - $this->_set_add_edit_form_tags('update_template_settings'); |
|
825 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
826 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
827 | - EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
828 | - $this->_template_args, |
|
829 | - true |
|
830 | - ); |
|
831 | - $this->display_admin_page_with_sidebar(); |
|
832 | - } |
|
833 | - |
|
834 | - |
|
835 | - /** |
|
836 | - * Handler for updating template settings. |
|
837 | - */ |
|
838 | - protected function _update_template_settings() |
|
839 | - { |
|
840 | - /** |
|
841 | - * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
842 | - * from General_Settings_Admin_Page to here. |
|
843 | - */ |
|
844 | - EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
845 | - 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
846 | - EE_Registry::instance()->CFG->template_settings, |
|
847 | - $this->_req_data |
|
848 | - ); |
|
849 | - //update custom post type slugs and detect if we need to flush rewrite rules |
|
850 | - $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
851 | - EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
852 | - ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
853 | - : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
854 | - $what = 'Template Settings'; |
|
855 | - $success = $this->_update_espresso_configuration( |
|
856 | - $what, |
|
857 | - EE_Registry::instance()->CFG->template_settings, |
|
858 | - __FILE__, |
|
859 | - __FUNCTION__, |
|
860 | - __LINE__ |
|
861 | - ); |
|
862 | - if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
863 | - update_option('ee_flush_rewrite_rules', true); |
|
864 | - } |
|
865 | - $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
866 | - } |
|
867 | - |
|
868 | - |
|
869 | - /** |
|
870 | - * _premium_event_editor_meta_boxes |
|
871 | - * add all metaboxes related to the event_editor |
|
872 | - * |
|
873 | - * @access protected |
|
874 | - * @return void |
|
875 | - * @throws EE_Error |
|
876 | - */ |
|
877 | - protected function _premium_event_editor_meta_boxes() |
|
878 | - { |
|
879 | - $this->verify_cpt_object(); |
|
880 | - add_meta_box( |
|
881 | - 'espresso_event_editor_event_options', |
|
882 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
883 | - array($this, 'registration_options_meta_box'), |
|
884 | - $this->page_slug, |
|
885 | - 'side', |
|
886 | - 'core' |
|
887 | - ); |
|
888 | - } |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * override caf metabox |
|
893 | - * |
|
894 | - * @return void |
|
895 | - * @throws DomainException |
|
896 | - */ |
|
897 | - public function registration_options_meta_box() |
|
898 | - { |
|
899 | - $yes_no_values = array( |
|
900 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
901 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
902 | - ); |
|
903 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
904 | - array( |
|
905 | - EEM_Registration::status_id_cancelled, |
|
906 | - EEM_Registration::status_id_declined, |
|
907 | - EEM_Registration::status_id_incomplete, |
|
908 | - EEM_Registration::status_id_wait_list, |
|
909 | - ), |
|
910 | - true |
|
911 | - ); |
|
912 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
913 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
914 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
915 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
916 | - 'default_reg_status', |
|
917 | - $default_reg_status_values, |
|
918 | - $this->_cpt_model_obj->default_registration_status() |
|
919 | - ); |
|
920 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
921 | - 'display_desc', |
|
922 | - $yes_no_values, |
|
923 | - $this->_cpt_model_obj->display_description() |
|
924 | - ); |
|
925 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
926 | - 'display_ticket_selector', |
|
927 | - $yes_no_values, |
|
928 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
929 | - '', |
|
930 | - '', |
|
931 | - false |
|
932 | - ); |
|
933 | - $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
934 | - 'EVT_default_registration_status', |
|
935 | - $default_reg_status_values, |
|
936 | - $this->_cpt_model_obj->default_registration_status() |
|
937 | - ); |
|
938 | - $template_args['additional_registration_options'] = apply_filters( |
|
939 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
940 | - '', |
|
941 | - $template_args, |
|
942 | - $yes_no_values, |
|
943 | - $default_reg_status_values |
|
944 | - ); |
|
945 | - EEH_Template::display_template( |
|
946 | - EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
947 | - $template_args |
|
948 | - ); |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * wp_list_table_mods for caf |
|
955 | - * ============================ |
|
956 | - */ |
|
957 | - /** |
|
958 | - * hook into list table filters and provide filters for caffeinated list table |
|
959 | - * |
|
960 | - * @param array $old_filters any existing filters present |
|
961 | - * @param array $list_table_obj the list table object |
|
962 | - * @return array new filters |
|
963 | - */ |
|
964 | - public function list_table_filters($old_filters, $list_table_obj) |
|
965 | - { |
|
966 | - $filters = array(); |
|
967 | - //first month/year filters |
|
968 | - $filters[] = $this->espresso_event_months_dropdown(); |
|
969 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
970 | - //active status dropdown |
|
971 | - if ($status !== 'draft') { |
|
972 | - $filters[] = $this->active_status_dropdown( |
|
973 | - isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
974 | - ); |
|
975 | - } |
|
976 | - //category filter |
|
977 | - $filters[] = $this->category_dropdown(); |
|
978 | - return array_merge($old_filters, $filters); |
|
979 | - } |
|
980 | - |
|
981 | - |
|
982 | - /** |
|
983 | - * espresso_event_months_dropdown |
|
984 | - * |
|
985 | - * @access public |
|
986 | - * @return string dropdown listing month/year selections for events. |
|
987 | - */ |
|
988 | - public function espresso_event_months_dropdown() |
|
989 | - { |
|
990 | - // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
991 | - // Note we need to include any other filters that are set! |
|
992 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
993 | - //categories? |
|
994 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
995 | - ? $this->_req_data['EVT_CAT'] |
|
996 | - : null; |
|
997 | - //active status? |
|
998 | - $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
999 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
1000 | - return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
1001 | - } |
|
1002 | - |
|
1003 | - |
|
1004 | - /** |
|
1005 | - * returns a list of "active" statuses on the event |
|
1006 | - * |
|
1007 | - * @param string $current_value whatever the current active status is |
|
1008 | - * @return string |
|
1009 | - */ |
|
1010 | - public function active_status_dropdown($current_value = '') |
|
1011 | - { |
|
1012 | - $select_name = 'active_status'; |
|
1013 | - $values = array( |
|
1014 | - 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
1015 | - 'active' => esc_html__('Active', 'event_espresso'), |
|
1016 | - 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
1017 | - 'expired' => esc_html__('Expired', 'event_espresso'), |
|
1018 | - 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
1019 | - ); |
|
1020 | - $id = 'id="espresso-active-status-dropdown-filter"'; |
|
1021 | - $class = 'wide'; |
|
1022 | - return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * output a dropdown of the categories for the category filter on the event admin list table |
|
1028 | - * |
|
1029 | - * @access public |
|
1030 | - * @return string html |
|
1031 | - */ |
|
1032 | - public function category_dropdown() |
|
1033 | - { |
|
1034 | - $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
1035 | - return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
1036 | - } |
|
1037 | - |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * get total number of events today |
|
1041 | - * |
|
1042 | - * @access public |
|
1043 | - * @return int |
|
1044 | - * @throws EE_Error |
|
1045 | - */ |
|
1046 | - public function total_events_today() |
|
1047 | - { |
|
1048 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1049 | - 'DTT_EVT_start', |
|
1050 | - date('Y-m-d') . ' 00:00:00', |
|
1051 | - 'Y-m-d H:i:s', |
|
1052 | - 'UTC' |
|
1053 | - ); |
|
1054 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1055 | - 'DTT_EVT_start', |
|
1056 | - date('Y-m-d') . ' 23:59:59', |
|
1057 | - 'Y-m-d H:i:s', |
|
1058 | - 'UTC' |
|
1059 | - ); |
|
1060 | - $where = array( |
|
1061 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1062 | - ); |
|
1063 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1064 | - return $count; |
|
1065 | - } |
|
1066 | - |
|
1067 | - |
|
1068 | - /** |
|
1069 | - * get total number of events this month |
|
1070 | - * |
|
1071 | - * @access public |
|
1072 | - * @return int |
|
1073 | - * @throws EE_Error |
|
1074 | - */ |
|
1075 | - public function total_events_this_month() |
|
1076 | - { |
|
1077 | - //Dates |
|
1078 | - $this_year_r = date('Y'); |
|
1079 | - $this_month_r = date('m'); |
|
1080 | - $days_this_month = date('t'); |
|
1081 | - $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1082 | - 'DTT_EVT_start', |
|
1083 | - $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1084 | - 'Y-m-d H:i:s', |
|
1085 | - 'UTC' |
|
1086 | - ); |
|
1087 | - $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1088 | - 'DTT_EVT_start', |
|
1089 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1090 | - 'Y-m-d H:i:s', |
|
1091 | - 'UTC' |
|
1092 | - ); |
|
1093 | - $where = array( |
|
1094 | - 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1095 | - ); |
|
1096 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1097 | - return $count; |
|
1098 | - } |
|
1099 | - |
|
1100 | - |
|
1101 | - /** DEFAULT TICKETS STUFF **/ |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * Output default tickets list table view. |
|
1105 | - */ |
|
1106 | - public function _tickets_overview_list_table() |
|
1107 | - { |
|
1108 | - $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
1109 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1110 | - } |
|
1111 | - |
|
1112 | - |
|
1113 | - /** |
|
1114 | - * @param int $per_page |
|
1115 | - * @param bool $count |
|
1116 | - * @param bool $trashed |
|
1117 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
1118 | - */ |
|
1119 | - public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
1120 | - { |
|
1121 | - $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
1122 | - $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
1123 | - switch ($orderby) { |
|
1124 | - case 'TKT_name': |
|
1125 | - $orderby = array('TKT_name' => $order); |
|
1126 | - break; |
|
1127 | - case 'TKT_price': |
|
1128 | - $orderby = array('TKT_price' => $order); |
|
1129 | - break; |
|
1130 | - case 'TKT_uses': |
|
1131 | - $orderby = array('TKT_uses' => $order); |
|
1132 | - break; |
|
1133 | - case 'TKT_min': |
|
1134 | - $orderby = array('TKT_min' => $order); |
|
1135 | - break; |
|
1136 | - case 'TKT_max': |
|
1137 | - $orderby = array('TKT_max' => $order); |
|
1138 | - break; |
|
1139 | - case 'TKT_qty': |
|
1140 | - $orderby = array('TKT_qty' => $order); |
|
1141 | - break; |
|
1142 | - } |
|
1143 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
1144 | - ? $this->_req_data['paged'] |
|
1145 | - : 1; |
|
1146 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
1147 | - ? $this->_req_data['perpage'] |
|
1148 | - : $per_page; |
|
1149 | - $_where = array( |
|
1150 | - 'TKT_is_default' => 1, |
|
1151 | - 'TKT_deleted' => $trashed, |
|
1152 | - ); |
|
1153 | - $offset = ($current_page - 1) * $per_page; |
|
1154 | - $limit = array($offset, $per_page); |
|
1155 | - if (isset($this->_req_data['s'])) { |
|
1156 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1157 | - $_where['OR'] = array( |
|
1158 | - 'TKT_name' => array('LIKE', $sstr), |
|
1159 | - 'TKT_description' => array('LIKE', $sstr), |
|
1160 | - ); |
|
1161 | - } |
|
1162 | - $query_params = array( |
|
1163 | - $_where, |
|
1164 | - 'order_by' => $orderby, |
|
1165 | - 'limit' => $limit, |
|
1166 | - 'group_by' => 'TKT_ID', |
|
1167 | - ); |
|
1168 | - if ($count) { |
|
1169 | - return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
1170 | - } else { |
|
1171 | - return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
1172 | - } |
|
1173 | - } |
|
1174 | - |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * @param bool $trash |
|
1178 | - * @throws EE_Error |
|
1179 | - */ |
|
1180 | - protected function _trash_or_restore_ticket($trash = false) |
|
1181 | - { |
|
1182 | - $success = 1; |
|
1183 | - $TKT = EEM_Ticket::instance(); |
|
1184 | - //checkboxes? |
|
1185 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1186 | - //if array has more than one element then success message should be plural |
|
1187 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1188 | - //cycle thru the boxes |
|
1189 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1190 | - if ($trash) { |
|
1191 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1192 | - $success = 0; |
|
1193 | - } |
|
1194 | - } else { |
|
1195 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1196 | - $success = 0; |
|
1197 | - } |
|
1198 | - } |
|
1199 | - } |
|
1200 | - } else { |
|
1201 | - //grab single id and trash |
|
1202 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1203 | - if ($trash) { |
|
1204 | - if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1205 | - $success = 0; |
|
1206 | - } |
|
1207 | - } else { |
|
1208 | - if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1209 | - $success = 0; |
|
1210 | - } |
|
1211 | - } |
|
1212 | - } |
|
1213 | - $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
1214 | - $query_args = array( |
|
1215 | - 'action' => 'ticket_list_table', |
|
1216 | - 'status' => $trash ? '' : 'trashed', |
|
1217 | - ); |
|
1218 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1219 | - } |
|
1220 | - |
|
1221 | - |
|
1222 | - /** |
|
1223 | - * Handles trashing default ticket. |
|
1224 | - */ |
|
1225 | - protected function _delete_ticket() |
|
1226 | - { |
|
1227 | - $success = 1; |
|
1228 | - //checkboxes? |
|
1229 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1230 | - //if array has more than one element then success message should be plural |
|
1231 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1232 | - //cycle thru the boxes |
|
1233 | - while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1234 | - //delete |
|
1235 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1236 | - $success = 0; |
|
1237 | - } |
|
1238 | - } |
|
1239 | - } else { |
|
1240 | - //grab single id and trash |
|
1241 | - $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1242 | - if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1243 | - $success = 0; |
|
1244 | - } |
|
1245 | - } |
|
1246 | - $action_desc = 'deleted'; |
|
1247 | - $query_args = array( |
|
1248 | - 'action' => 'ticket_list_table', |
|
1249 | - 'status' => 'trashed', |
|
1250 | - ); |
|
1251 | - //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
1252 | - if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
1253 | - array(array('TKT_is_default' => 1)), |
|
1254 | - 'TKT_ID', |
|
1255 | - true |
|
1256 | - ) |
|
1257 | - ) { |
|
1258 | - $query_args = array(); |
|
1259 | - } |
|
1260 | - $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1261 | - } |
|
1262 | - |
|
1263 | - |
|
1264 | - /** |
|
1265 | - * @param int $TKT_ID |
|
1266 | - * @return bool|int |
|
1267 | - * @throws EE_Error |
|
1268 | - */ |
|
1269 | - protected function _delete_the_ticket($TKT_ID) |
|
1270 | - { |
|
1271 | - $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
1272 | - $tkt->_remove_relations('Datetime'); |
|
1273 | - //delete all related prices first |
|
1274 | - $tkt->delete_related_permanently('Price'); |
|
1275 | - return $tkt->delete_permanently(); |
|
1276 | - } |
|
17 | + /** |
|
18 | + * Extend_Events_Admin_Page constructor. |
|
19 | + * |
|
20 | + * @param bool $routing |
|
21 | + */ |
|
22 | + public function __construct($routing = true) |
|
23 | + { |
|
24 | + parent::__construct($routing); |
|
25 | + if (! defined('EVENTS_CAF_TEMPLATE_PATH')) { |
|
26 | + define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/'); |
|
27 | + define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/'); |
|
28 | + define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/'); |
|
29 | + } |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Sets routes. |
|
35 | + */ |
|
36 | + protected function _extend_page_config() |
|
37 | + { |
|
38 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events'; |
|
39 | + //is there a evt_id in the request? |
|
40 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
41 | + ? $this->_req_data['EVT_ID'] |
|
42 | + : 0; |
|
43 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
44 | + //tkt_id? |
|
45 | + $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID']) |
|
46 | + ? $this->_req_data['TKT_ID'] |
|
47 | + : 0; |
|
48 | + $new_page_routes = array( |
|
49 | + 'duplicate_event' => array( |
|
50 | + 'func' => '_duplicate_event', |
|
51 | + 'capability' => 'ee_edit_event', |
|
52 | + 'obj_id' => $evt_id, |
|
53 | + 'noheader' => true, |
|
54 | + ), |
|
55 | + 'ticket_list_table' => array( |
|
56 | + 'func' => '_tickets_overview_list_table', |
|
57 | + 'capability' => 'ee_read_default_tickets', |
|
58 | + ), |
|
59 | + 'trash_ticket' => array( |
|
60 | + 'func' => '_trash_or_restore_ticket', |
|
61 | + 'capability' => 'ee_delete_default_ticket', |
|
62 | + 'obj_id' => $tkt_id, |
|
63 | + 'noheader' => true, |
|
64 | + 'args' => array('trash' => true), |
|
65 | + ), |
|
66 | + 'trash_tickets' => array( |
|
67 | + 'func' => '_trash_or_restore_ticket', |
|
68 | + 'capability' => 'ee_delete_default_tickets', |
|
69 | + 'noheader' => true, |
|
70 | + 'args' => array('trash' => true), |
|
71 | + ), |
|
72 | + 'restore_ticket' => array( |
|
73 | + 'func' => '_trash_or_restore_ticket', |
|
74 | + 'capability' => 'ee_delete_default_ticket', |
|
75 | + 'obj_id' => $tkt_id, |
|
76 | + 'noheader' => true, |
|
77 | + ), |
|
78 | + 'restore_tickets' => array( |
|
79 | + 'func' => '_trash_or_restore_ticket', |
|
80 | + 'capability' => 'ee_delete_default_tickets', |
|
81 | + 'noheader' => true, |
|
82 | + ), |
|
83 | + 'delete_ticket' => array( |
|
84 | + 'func' => '_delete_ticket', |
|
85 | + 'capability' => 'ee_delete_default_ticket', |
|
86 | + 'obj_id' => $tkt_id, |
|
87 | + 'noheader' => true, |
|
88 | + ), |
|
89 | + 'delete_tickets' => array( |
|
90 | + 'func' => '_delete_ticket', |
|
91 | + 'capability' => 'ee_delete_default_tickets', |
|
92 | + 'noheader' => true, |
|
93 | + ), |
|
94 | + 'import_page' => array( |
|
95 | + 'func' => '_import_page', |
|
96 | + 'capability' => 'import', |
|
97 | + ), |
|
98 | + 'import' => array( |
|
99 | + 'func' => '_import_events', |
|
100 | + 'capability' => 'import', |
|
101 | + 'noheader' => true, |
|
102 | + ), |
|
103 | + 'import_events' => array( |
|
104 | + 'func' => '_import_events', |
|
105 | + 'capability' => 'import', |
|
106 | + 'noheader' => true, |
|
107 | + ), |
|
108 | + 'export_events' => array( |
|
109 | + 'func' => '_events_export', |
|
110 | + 'capability' => 'export', |
|
111 | + 'noheader' => true, |
|
112 | + ), |
|
113 | + 'export_categories' => array( |
|
114 | + 'func' => '_categories_export', |
|
115 | + 'capability' => 'export', |
|
116 | + 'noheader' => true, |
|
117 | + ), |
|
118 | + 'sample_export_file' => array( |
|
119 | + 'func' => '_sample_export_file', |
|
120 | + 'capability' => 'export', |
|
121 | + 'noheader' => true, |
|
122 | + ), |
|
123 | + 'update_template_settings' => array( |
|
124 | + 'func' => '_update_template_settings', |
|
125 | + 'capability' => 'manage_options', |
|
126 | + 'noheader' => true, |
|
127 | + ), |
|
128 | + ); |
|
129 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
130 | + //partial route/config override |
|
131 | + $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes; |
|
132 | + $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
133 | + $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
134 | + $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips'; |
|
135 | + $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes'; |
|
136 | + $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table'; |
|
137 | + //add tickets tab but only if there are more than one default ticket! |
|
138 | + $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
139 | + array(array('TKT_is_default' => 1)), |
|
140 | + 'TKT_ID', |
|
141 | + true |
|
142 | + ); |
|
143 | + if ($tkt_count > 1) { |
|
144 | + $new_page_config = array( |
|
145 | + 'ticket_list_table' => array( |
|
146 | + 'nav' => array( |
|
147 | + 'label' => esc_html__('Default Tickets', 'event_espresso'), |
|
148 | + 'order' => 60, |
|
149 | + ), |
|
150 | + 'list_table' => 'Tickets_List_Table', |
|
151 | + 'require_nonce' => false, |
|
152 | + ), |
|
153 | + ); |
|
154 | + } |
|
155 | + //template settings |
|
156 | + $new_page_config['template_settings'] = array( |
|
157 | + 'nav' => array( |
|
158 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
159 | + 'order' => 30, |
|
160 | + ), |
|
161 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
162 | + 'help_tabs' => array( |
|
163 | + 'general_settings_templates_help_tab' => array( |
|
164 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
165 | + 'filename' => 'general_settings_templates', |
|
166 | + ), |
|
167 | + ), |
|
168 | + 'help_tour' => array('Templates_Help_Tour'), |
|
169 | + 'require_nonce' => false, |
|
170 | + ); |
|
171 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
172 | + //add filters and actions |
|
173 | + //modifying _views |
|
174 | + add_filter( |
|
175 | + 'FHEE_event_datetime_metabox_add_additional_date_time_template', |
|
176 | + array($this, 'add_additional_datetime_button'), |
|
177 | + 10, |
|
178 | + 2 |
|
179 | + ); |
|
180 | + add_filter( |
|
181 | + 'FHEE_event_datetime_metabox_clone_button_template', |
|
182 | + array($this, 'add_datetime_clone_button'), |
|
183 | + 10, |
|
184 | + 2 |
|
185 | + ); |
|
186 | + add_filter( |
|
187 | + 'FHEE_event_datetime_metabox_timezones_template', |
|
188 | + array($this, 'datetime_timezones_template'), |
|
189 | + 10, |
|
190 | + 2 |
|
191 | + ); |
|
192 | + //filters for event list table |
|
193 | + add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2); |
|
194 | + add_filter( |
|
195 | + 'FHEE__Events_Admin_List_Table__column_actions__action_links', |
|
196 | + array($this, 'extra_list_table_actions'), |
|
197 | + 10, |
|
198 | + 2 |
|
199 | + ); |
|
200 | + //legend item |
|
201 | + add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items')); |
|
202 | + add_action('admin_init', array($this, 'admin_init')); |
|
203 | + //heartbeat stuff |
|
204 | + add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * admin_init |
|
210 | + */ |
|
211 | + public function admin_init() |
|
212 | + { |
|
213 | + EE_Registry::$i18n_js_strings = array_merge( |
|
214 | + EE_Registry::$i18n_js_strings, |
|
215 | + array( |
|
216 | + 'image_confirm' => esc_html__( |
|
217 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + 'event_starts_on' => esc_html__('Event Starts on', 'event_espresso'), |
|
221 | + 'event_ends_on' => esc_html__('Event Ends on', 'event_espresso'), |
|
222 | + 'event_datetime_actions' => esc_html__('Actions', 'event_espresso'), |
|
223 | + 'event_clone_dt_msg' => esc_html__('Clone this Event Date and Time', 'event_espresso'), |
|
224 | + 'remove_event_dt_msg' => esc_html__('Remove this Event Time', 'event_espresso'), |
|
225 | + ) |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
232 | + * accordingly. |
|
233 | + * |
|
234 | + * @param array $response The existing heartbeat response array. |
|
235 | + * @param array $data The incoming data package. |
|
236 | + * @return array possibly appended response. |
|
237 | + */ |
|
238 | + public function heartbeat_response($response, $data) |
|
239 | + { |
|
240 | + /** |
|
241 | + * check whether count of tickets is approaching the potential |
|
242 | + * limits for the server. |
|
243 | + */ |
|
244 | + if (! empty($data['input_count'])) { |
|
245 | + $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check( |
|
246 | + $data['input_count'] |
|
247 | + ); |
|
248 | + } |
|
249 | + return $response; |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * Add per page screen options to the default ticket list table view. |
|
255 | + */ |
|
256 | + protected function _add_screen_options_ticket_list_table() |
|
257 | + { |
|
258 | + $this->_per_page_screen_option(); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @param string $return |
|
264 | + * @param int $id |
|
265 | + * @param string $new_title |
|
266 | + * @param string $new_slug |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
270 | + { |
|
271 | + $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug); |
|
272 | + //make sure this is only when editing |
|
273 | + if (! empty($id)) { |
|
274 | + $href = EE_Admin_Page::add_query_args_and_nonce( |
|
275 | + array('action' => 'duplicate_event', 'EVT_ID' => $id), |
|
276 | + $this->_admin_base_url |
|
277 | + ); |
|
278 | + $title = esc_attr__('Duplicate Event', 'event_espresso'); |
|
279 | + $return .= '<a href="' |
|
280 | + . $href |
|
281 | + . '" title="' |
|
282 | + . $title |
|
283 | + . '" id="ee-duplicate-event-button" class="button button-small" value="duplicate_event">' |
|
284 | + . $title |
|
285 | + . '</button>'; |
|
286 | + } |
|
287 | + return $return; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Set the list table views for the default ticket list table view. |
|
293 | + */ |
|
294 | + public function _set_list_table_views_ticket_list_table() |
|
295 | + { |
|
296 | + $this->_views = array( |
|
297 | + 'all' => array( |
|
298 | + 'slug' => 'all', |
|
299 | + 'label' => esc_html__('All', 'event_espresso'), |
|
300 | + 'count' => 0, |
|
301 | + 'bulk_action' => array( |
|
302 | + 'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'), |
|
303 | + ), |
|
304 | + ), |
|
305 | + 'trashed' => array( |
|
306 | + 'slug' => 'trashed', |
|
307 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
308 | + 'count' => 0, |
|
309 | + 'bulk_action' => array( |
|
310 | + 'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'), |
|
311 | + 'delete_tickets' => esc_html__('Delete Permanently', 'event_espresso'), |
|
312 | + ), |
|
313 | + ), |
|
314 | + ); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Enqueue scripts and styles for the event editor. |
|
320 | + */ |
|
321 | + public function load_scripts_styles_edit() |
|
322 | + { |
|
323 | + wp_register_script( |
|
324 | + 'ee-event-editor-heartbeat', |
|
325 | + EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js', |
|
326 | + array('ee_admin_js', 'heartbeat'), |
|
327 | + EVENT_ESPRESSO_VERSION, |
|
328 | + true |
|
329 | + ); |
|
330 | + wp_enqueue_script('ee-accounting'); |
|
331 | + //styles |
|
332 | + wp_enqueue_style('espresso-ui-theme'); |
|
333 | + wp_enqueue_script('event_editor_js'); |
|
334 | + wp_enqueue_script('ee-event-editor-heartbeat'); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Returns template for the additional datetime. |
|
340 | + * @param $template |
|
341 | + * @param $template_args |
|
342 | + * @return mixed |
|
343 | + * @throws DomainException |
|
344 | + */ |
|
345 | + public function add_additional_datetime_button($template, $template_args) |
|
346 | + { |
|
347 | + return EEH_Template::display_template( |
|
348 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php', |
|
349 | + $template_args, |
|
350 | + true |
|
351 | + ); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Returns the template for cloning a datetime. |
|
357 | + * @param $template |
|
358 | + * @param $template_args |
|
359 | + * @return mixed |
|
360 | + * @throws DomainException |
|
361 | + */ |
|
362 | + public function add_datetime_clone_button($template, $template_args) |
|
363 | + { |
|
364 | + return EEH_Template::display_template( |
|
365 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php', |
|
366 | + $template_args, |
|
367 | + true |
|
368 | + ); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Returns the template for datetime timezones. |
|
374 | + * @param $template |
|
375 | + * @param $template_args |
|
376 | + * @return mixed |
|
377 | + * @throws DomainException |
|
378 | + */ |
|
379 | + public function datetime_timezones_template($template, $template_args) |
|
380 | + { |
|
381 | + return EEH_Template::display_template( |
|
382 | + EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php', |
|
383 | + $template_args, |
|
384 | + true |
|
385 | + ); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Sets the views for the default list table view. |
|
391 | + */ |
|
392 | + protected function _set_list_table_views_default() |
|
393 | + { |
|
394 | + parent::_set_list_table_views_default(); |
|
395 | + $new_views = array( |
|
396 | + 'today' => array( |
|
397 | + 'slug' => 'today', |
|
398 | + 'label' => esc_html__('Today', 'event_espresso'), |
|
399 | + 'count' => $this->total_events_today(), |
|
400 | + 'bulk_action' => array( |
|
401 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
402 | + ), |
|
403 | + ), |
|
404 | + 'month' => array( |
|
405 | + 'slug' => 'month', |
|
406 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
407 | + 'count' => $this->total_events_this_month(), |
|
408 | + 'bulk_action' => array( |
|
409 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
410 | + ), |
|
411 | + ), |
|
412 | + ); |
|
413 | + $this->_views = array_merge($this->_views, $new_views); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Returns the extra action links for the default list table view. |
|
419 | + * @param array $action_links |
|
420 | + * @param \EE_Event $event |
|
421 | + * @return array |
|
422 | + * @throws EE_Error |
|
423 | + */ |
|
424 | + public function extra_list_table_actions(array $action_links, \EE_Event $event) |
|
425 | + { |
|
426 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
427 | + 'ee_read_registrations', |
|
428 | + 'espresso_registrations_reports', |
|
429 | + $event->ID() |
|
430 | + ) |
|
431 | + ) { |
|
432 | + $reports_query_args = array( |
|
433 | + 'action' => 'reports', |
|
434 | + 'EVT_ID' => $event->ID(), |
|
435 | + ); |
|
436 | + $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL); |
|
437 | + $action_links[] = '<a href="' |
|
438 | + . $reports_link |
|
439 | + . '" title="' |
|
440 | + . esc_attr__('View Report', 'event_espresso') |
|
441 | + . '"><div class="dashicons dashicons-chart-bar"></div></a>' |
|
442 | + . "\n\t"; |
|
443 | + } |
|
444 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
445 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
446 | + $action_links[] = EEH_MSG_Template::get_message_action_link( |
|
447 | + 'see_notifications_for', |
|
448 | + null, |
|
449 | + array('EVT_ID' => $event->ID()) |
|
450 | + ); |
|
451 | + } |
|
452 | + return $action_links; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * @param $items |
|
458 | + * @return mixed |
|
459 | + */ |
|
460 | + public function additional_legend_items($items) |
|
461 | + { |
|
462 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
463 | + 'ee_read_registrations', |
|
464 | + 'espresso_registrations_reports' |
|
465 | + ) |
|
466 | + ) { |
|
467 | + $items['reports'] = array( |
|
468 | + 'class' => 'dashicons dashicons-chart-bar', |
|
469 | + 'desc' => esc_html__('Event Reports', 'event_espresso'), |
|
470 | + ); |
|
471 | + } |
|
472 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
473 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
474 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
475 | + $items['view_related_messages'] = array( |
|
476 | + 'class' => $related_for_icon['css_class'], |
|
477 | + 'desc' => $related_for_icon['label'], |
|
478 | + ); |
|
479 | + } |
|
480 | + } |
|
481 | + return $items; |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * This is the callback method for the duplicate event route |
|
487 | + * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them |
|
488 | + * into a new event. We add a hook so that any plugins that add extra event details can hook into this |
|
489 | + * action. Note that the dupe will have **DUPLICATE** as its title and slug. |
|
490 | + * After duplication the redirect is to the new event edit page. |
|
491 | + * |
|
492 | + * @return void |
|
493 | + * @access protected |
|
494 | + * @throws EE_Error If EE_Event is not available with given ID |
|
495 | + */ |
|
496 | + protected function _duplicate_event() |
|
497 | + { |
|
498 | + // first make sure the ID for the event is in the request. |
|
499 | + // If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?) |
|
500 | + if (! isset($this->_req_data['EVT_ID'])) { |
|
501 | + EE_Error::add_error( |
|
502 | + esc_html__( |
|
503 | + 'In order to duplicate an event an Event ID is required. None was given.', |
|
504 | + 'event_espresso' |
|
505 | + ), |
|
506 | + __FILE__, |
|
507 | + __FUNCTION__, |
|
508 | + __LINE__ |
|
509 | + ); |
|
510 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
511 | + return; |
|
512 | + } |
|
513 | + //k we've got EVT_ID so let's use that to get the event we'll duplicate |
|
514 | + $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']); |
|
515 | + if (! $orig_event instanceof EE_Event) { |
|
516 | + throw new EE_Error( |
|
517 | + sprintf( |
|
518 | + esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'), |
|
519 | + $this->_req_data['EVT_ID'] |
|
520 | + ) |
|
521 | + ); |
|
522 | + } |
|
523 | + //k now let's clone the $orig_event before getting relations |
|
524 | + $new_event = clone $orig_event; |
|
525 | + //original datetimes |
|
526 | + $orig_datetimes = $orig_event->get_many_related('Datetime'); |
|
527 | + //other original relations |
|
528 | + $orig_ven = $orig_event->get_many_related('Venue'); |
|
529 | + //reset the ID and modify other details to make it clear this is a dupe |
|
530 | + $new_event->set('EVT_ID', 0); |
|
531 | + $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso'); |
|
532 | + $new_event->set('EVT_name', $new_name); |
|
533 | + $new_event->set( |
|
534 | + 'EVT_slug', |
|
535 | + wp_unique_post_slug( |
|
536 | + sanitize_title($orig_event->name()), |
|
537 | + 0, |
|
538 | + 'publish', |
|
539 | + 'espresso_events', |
|
540 | + 0 |
|
541 | + ) |
|
542 | + ); |
|
543 | + $new_event->set('status', 'draft'); |
|
544 | + //duplicate discussion settings |
|
545 | + $new_event->set('comment_status', $orig_event->get('comment_status')); |
|
546 | + $new_event->set('ping_status', $orig_event->get('ping_status')); |
|
547 | + //save the new event |
|
548 | + $new_event->save(); |
|
549 | + //venues |
|
550 | + foreach ($orig_ven as $ven) { |
|
551 | + $new_event->_add_relation_to($ven, 'Venue'); |
|
552 | + } |
|
553 | + $new_event->save(); |
|
554 | + //now we need to get the question group relations and handle that |
|
555 | + //first primary question groups |
|
556 | + $orig_primary_qgs = $orig_event->get_many_related( |
|
557 | + 'Question_Group', |
|
558 | + array(array('Event_Question_Group.EQG_primary' => 1)) |
|
559 | + ); |
|
560 | + if (! empty($orig_primary_qgs)) { |
|
561 | + foreach ($orig_primary_qgs as $id => $obj) { |
|
562 | + if ($obj instanceof EE_Question_Group) { |
|
563 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1)); |
|
564 | + } |
|
565 | + } |
|
566 | + } |
|
567 | + //next additional attendee question groups |
|
568 | + $orig_additional_qgs = $orig_event->get_many_related( |
|
569 | + 'Question_Group', |
|
570 | + array(array('Event_Question_Group.EQG_primary' => 0)) |
|
571 | + ); |
|
572 | + if (! empty($orig_additional_qgs)) { |
|
573 | + foreach ($orig_additional_qgs as $id => $obj) { |
|
574 | + if ($obj instanceof EE_Question_Group) { |
|
575 | + $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0)); |
|
576 | + } |
|
577 | + } |
|
578 | + } |
|
579 | + |
|
580 | + $new_event->save(); |
|
581 | + |
|
582 | + //k now that we have the new event saved we can loop through the datetimes and start adding relations. |
|
583 | + $cloned_tickets = array(); |
|
584 | + foreach ($orig_datetimes as $orig_dtt) { |
|
585 | + if (! $orig_dtt instanceof EE_Datetime) { |
|
586 | + continue; |
|
587 | + } |
|
588 | + $new_dtt = clone $orig_dtt; |
|
589 | + $orig_tkts = $orig_dtt->tickets(); |
|
590 | + //save new dtt then add to event |
|
591 | + $new_dtt->set('DTT_ID', 0); |
|
592 | + $new_dtt->set('DTT_sold', 0); |
|
593 | + $new_dtt->set_reserved(0); |
|
594 | + $new_dtt->save(); |
|
595 | + $new_event->_add_relation_to($new_dtt, 'Datetime'); |
|
596 | + $new_event->save(); |
|
597 | + //now let's get the ticket relations setup. |
|
598 | + foreach ((array)$orig_tkts as $orig_tkt) { |
|
599 | + //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first. |
|
600 | + if (! $orig_tkt instanceof EE_Ticket) { |
|
601 | + continue; |
|
602 | + } |
|
603 | + //is this ticket archived? If it is then let's skip |
|
604 | + if ($orig_tkt->get('TKT_deleted')) { |
|
605 | + continue; |
|
606 | + } |
|
607 | + // does this original ticket already exist in the clone_tickets cache? |
|
608 | + // If so we'll just use the new ticket from it. |
|
609 | + if (isset($cloned_tickets[$orig_tkt->ID()])) { |
|
610 | + $new_tkt = $cloned_tickets[$orig_tkt->ID()]; |
|
611 | + } else { |
|
612 | + $new_tkt = clone $orig_tkt; |
|
613 | + //get relations on the $orig_tkt that we need to setup. |
|
614 | + $orig_prices = $orig_tkt->prices(); |
|
615 | + $new_tkt->set('TKT_ID', 0); |
|
616 | + $new_tkt->set('TKT_sold', 0); |
|
617 | + $new_tkt->set('TKT_reserved', 0); |
|
618 | + $new_tkt->save(); //make sure new ticket has ID. |
|
619 | + //price relations on new ticket need to be setup. |
|
620 | + foreach ($orig_prices as $orig_price) { |
|
621 | + $new_price = clone $orig_price; |
|
622 | + $new_price->set('PRC_ID', 0); |
|
623 | + $new_price->save(); |
|
624 | + $new_tkt->_add_relation_to($new_price, 'Price'); |
|
625 | + $new_tkt->save(); |
|
626 | + } |
|
627 | + |
|
628 | + do_action( |
|
629 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after', |
|
630 | + $orig_tkt, |
|
631 | + $new_tkt, |
|
632 | + $orig_prices, |
|
633 | + $orig_event, |
|
634 | + $orig_dtt, |
|
635 | + $new_dtt |
|
636 | + ); |
|
637 | + } |
|
638 | + // k now we can add the new ticket as a relation to the new datetime |
|
639 | + // and make sure its added to our cached $cloned_tickets array |
|
640 | + // for use with later datetimes that have the same ticket. |
|
641 | + $new_dtt->_add_relation_to($new_tkt, 'Ticket'); |
|
642 | + $new_dtt->save(); |
|
643 | + $cloned_tickets[$orig_tkt->ID()] = $new_tkt; |
|
644 | + } |
|
645 | + } |
|
646 | + //clone taxonomy information |
|
647 | + $taxonomies_to_clone_with = apply_filters( |
|
648 | + 'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone', |
|
649 | + array('espresso_event_categories', 'espresso_event_type', 'post_tag') |
|
650 | + ); |
|
651 | + //get terms for original event (notice) |
|
652 | + $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with); |
|
653 | + //loop through terms and add them to new event. |
|
654 | + foreach ($orig_terms as $term) { |
|
655 | + wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true); |
|
656 | + } |
|
657 | + |
|
658 | + //duplicate other core WP_Post items for this event. |
|
659 | + //post thumbnail (feature image). |
|
660 | + $feature_image_id = get_post_thumbnail_id($orig_event->ID()); |
|
661 | + if ($feature_image_id) { |
|
662 | + update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id); |
|
663 | + } |
|
664 | + |
|
665 | + //duplicate page_template setting |
|
666 | + $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true); |
|
667 | + if ($page_template) { |
|
668 | + update_post_meta($new_event->ID(), '_wp_page_template', $page_template); |
|
669 | + } |
|
670 | + |
|
671 | + do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event); |
|
672 | + //now let's redirect to the edit page for this duplicated event if we have a new event id. |
|
673 | + if ($new_event->ID()) { |
|
674 | + $redirect_args = array( |
|
675 | + 'post' => $new_event->ID(), |
|
676 | + 'action' => 'edit', |
|
677 | + ); |
|
678 | + EE_Error::add_success( |
|
679 | + esc_html__( |
|
680 | + 'Event successfully duplicated. Please review the details below and make any necessary edits', |
|
681 | + 'event_espresso' |
|
682 | + ) |
|
683 | + ); |
|
684 | + } else { |
|
685 | + $redirect_args = array( |
|
686 | + 'action' => 'default', |
|
687 | + ); |
|
688 | + EE_Error::add_error( |
|
689 | + esc_html__('Not able to duplicate event. Something went wrong.', 'event_espresso'), |
|
690 | + __FILE__, |
|
691 | + __FUNCTION__, |
|
692 | + __LINE__ |
|
693 | + ); |
|
694 | + } |
|
695 | + $this->_redirect_after_action(false, '', '', $redirect_args, true); |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * Generates output for the import page. |
|
701 | + * @throws DomainException |
|
702 | + */ |
|
703 | + protected function _import_page() |
|
704 | + { |
|
705 | + $title = esc_html__('Import', 'event_espresso'); |
|
706 | + $intro = esc_html__( |
|
707 | + 'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ', |
|
708 | + 'event_espresso' |
|
709 | + ); |
|
710 | + $form_url = EVENTS_ADMIN_URL; |
|
711 | + $action = 'import_events'; |
|
712 | + $type = 'csv'; |
|
713 | + $this->_template_args['form'] = EE_Import::instance()->upload_form( |
|
714 | + $title, $intro, $form_url, $action, $type |
|
715 | + ); |
|
716 | + $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
717 | + array('action' => 'sample_export_file'), |
|
718 | + $this->_admin_base_url |
|
719 | + ); |
|
720 | + $content = EEH_Template::display_template( |
|
721 | + EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php', |
|
722 | + $this->_template_args, |
|
723 | + true |
|
724 | + ); |
|
725 | + $this->_template_args['admin_page_content'] = $content; |
|
726 | + $this->display_admin_page_with_sidebar(); |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * _import_events |
|
732 | + * This handles displaying the screen and running imports for importing events. |
|
733 | + * |
|
734 | + * @return void |
|
735 | + */ |
|
736 | + protected function _import_events() |
|
737 | + { |
|
738 | + require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
739 | + $success = EE_Import::instance()->import(); |
|
740 | + $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true); |
|
741 | + } |
|
742 | + |
|
743 | + |
|
744 | + /** |
|
745 | + * _events_export |
|
746 | + * Will export all (or just the given event) to a Excel compatible file. |
|
747 | + * |
|
748 | + * @access protected |
|
749 | + * @return void |
|
750 | + */ |
|
751 | + protected function _events_export() |
|
752 | + { |
|
753 | + if (isset($this->_req_data['EVT_ID'])) { |
|
754 | + $event_ids = $this->_req_data['EVT_ID']; |
|
755 | + } elseif (isset($this->_req_data['EVT_IDs'])) { |
|
756 | + $event_ids = $this->_req_data['EVT_IDs']; |
|
757 | + } else { |
|
758 | + $event_ids = null; |
|
759 | + } |
|
760 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
761 | + $new_request_args = array( |
|
762 | + 'export' => 'report', |
|
763 | + 'action' => 'all_event_data', |
|
764 | + 'EVT_ID' => $event_ids, |
|
765 | + ); |
|
766 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
767 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
768 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
769 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
770 | + $EE_Export->export(); |
|
771 | + } |
|
772 | + } |
|
773 | + |
|
774 | + |
|
775 | + /** |
|
776 | + * handle category exports() |
|
777 | + * |
|
778 | + * @return void |
|
779 | + */ |
|
780 | + protected function _categories_export() |
|
781 | + { |
|
782 | + //todo: I don't like doing this but it'll do until we modify EE_Export Class. |
|
783 | + $new_request_args = array( |
|
784 | + 'export' => 'report', |
|
785 | + 'action' => 'categories', |
|
786 | + 'category_ids' => $this->_req_data['EVT_CAT_ID'], |
|
787 | + ); |
|
788 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
789 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
790 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
791 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
792 | + $EE_Export->export(); |
|
793 | + } |
|
794 | + } |
|
795 | + |
|
796 | + |
|
797 | + /** |
|
798 | + * Creates a sample CSV file for importing |
|
799 | + */ |
|
800 | + protected function _sample_export_file() |
|
801 | + { |
|
802 | + // require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
803 | + EE_Export::instance()->export_sample(); |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + /************* Template Settings *************/ |
|
808 | + /** |
|
809 | + * Generates template settings page output |
|
810 | + * @throws DomainException |
|
811 | + * @throws EE_Error |
|
812 | + */ |
|
813 | + protected function _template_settings() |
|
814 | + { |
|
815 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
816 | + /** |
|
817 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
818 | + * from General_Settings_Admin_Page to here. |
|
819 | + */ |
|
820 | + $this->_template_args = apply_filters( |
|
821 | + 'FHEE__General_Settings_Admin_Page__template_settings__template_args', |
|
822 | + $this->_template_args |
|
823 | + ); |
|
824 | + $this->_set_add_edit_form_tags('update_template_settings'); |
|
825 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
826 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
827 | + EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php', |
|
828 | + $this->_template_args, |
|
829 | + true |
|
830 | + ); |
|
831 | + $this->display_admin_page_with_sidebar(); |
|
832 | + } |
|
833 | + |
|
834 | + |
|
835 | + /** |
|
836 | + * Handler for updating template settings. |
|
837 | + */ |
|
838 | + protected function _update_template_settings() |
|
839 | + { |
|
840 | + /** |
|
841 | + * Note leaving this filter in for backward compatibility this was moved in 4.6.x |
|
842 | + * from General_Settings_Admin_Page to here. |
|
843 | + */ |
|
844 | + EE_Registry::instance()->CFG->template_settings = apply_filters( |
|
845 | + 'FHEE__General_Settings_Admin_Page__update_template_settings__data', |
|
846 | + EE_Registry::instance()->CFG->template_settings, |
|
847 | + $this->_req_data |
|
848 | + ); |
|
849 | + //update custom post type slugs and detect if we need to flush rewrite rules |
|
850 | + $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug; |
|
851 | + EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug']) |
|
852 | + ? EE_Registry::instance()->CFG->core->event_cpt_slug |
|
853 | + : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']); |
|
854 | + $what = 'Template Settings'; |
|
855 | + $success = $this->_update_espresso_configuration( |
|
856 | + $what, |
|
857 | + EE_Registry::instance()->CFG->template_settings, |
|
858 | + __FILE__, |
|
859 | + __FUNCTION__, |
|
860 | + __LINE__ |
|
861 | + ); |
|
862 | + if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) { |
|
863 | + update_option('ee_flush_rewrite_rules', true); |
|
864 | + } |
|
865 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings')); |
|
866 | + } |
|
867 | + |
|
868 | + |
|
869 | + /** |
|
870 | + * _premium_event_editor_meta_boxes |
|
871 | + * add all metaboxes related to the event_editor |
|
872 | + * |
|
873 | + * @access protected |
|
874 | + * @return void |
|
875 | + * @throws EE_Error |
|
876 | + */ |
|
877 | + protected function _premium_event_editor_meta_boxes() |
|
878 | + { |
|
879 | + $this->verify_cpt_object(); |
|
880 | + add_meta_box( |
|
881 | + 'espresso_event_editor_event_options', |
|
882 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
883 | + array($this, 'registration_options_meta_box'), |
|
884 | + $this->page_slug, |
|
885 | + 'side', |
|
886 | + 'core' |
|
887 | + ); |
|
888 | + } |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * override caf metabox |
|
893 | + * |
|
894 | + * @return void |
|
895 | + * @throws DomainException |
|
896 | + */ |
|
897 | + public function registration_options_meta_box() |
|
898 | + { |
|
899 | + $yes_no_values = array( |
|
900 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
901 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
902 | + ); |
|
903 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
904 | + array( |
|
905 | + EEM_Registration::status_id_cancelled, |
|
906 | + EEM_Registration::status_id_declined, |
|
907 | + EEM_Registration::status_id_incomplete, |
|
908 | + EEM_Registration::status_id_wait_list, |
|
909 | + ), |
|
910 | + true |
|
911 | + ); |
|
912 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
913 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
914 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
915 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
916 | + 'default_reg_status', |
|
917 | + $default_reg_status_values, |
|
918 | + $this->_cpt_model_obj->default_registration_status() |
|
919 | + ); |
|
920 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
921 | + 'display_desc', |
|
922 | + $yes_no_values, |
|
923 | + $this->_cpt_model_obj->display_description() |
|
924 | + ); |
|
925 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
926 | + 'display_ticket_selector', |
|
927 | + $yes_no_values, |
|
928 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
929 | + '', |
|
930 | + '', |
|
931 | + false |
|
932 | + ); |
|
933 | + $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input( |
|
934 | + 'EVT_default_registration_status', |
|
935 | + $default_reg_status_values, |
|
936 | + $this->_cpt_model_obj->default_registration_status() |
|
937 | + ); |
|
938 | + $template_args['additional_registration_options'] = apply_filters( |
|
939 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
940 | + '', |
|
941 | + $template_args, |
|
942 | + $yes_no_values, |
|
943 | + $default_reg_status_values |
|
944 | + ); |
|
945 | + EEH_Template::display_template( |
|
946 | + EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
947 | + $template_args |
|
948 | + ); |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * wp_list_table_mods for caf |
|
955 | + * ============================ |
|
956 | + */ |
|
957 | + /** |
|
958 | + * hook into list table filters and provide filters for caffeinated list table |
|
959 | + * |
|
960 | + * @param array $old_filters any existing filters present |
|
961 | + * @param array $list_table_obj the list table object |
|
962 | + * @return array new filters |
|
963 | + */ |
|
964 | + public function list_table_filters($old_filters, $list_table_obj) |
|
965 | + { |
|
966 | + $filters = array(); |
|
967 | + //first month/year filters |
|
968 | + $filters[] = $this->espresso_event_months_dropdown(); |
|
969 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
970 | + //active status dropdown |
|
971 | + if ($status !== 'draft') { |
|
972 | + $filters[] = $this->active_status_dropdown( |
|
973 | + isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : '' |
|
974 | + ); |
|
975 | + } |
|
976 | + //category filter |
|
977 | + $filters[] = $this->category_dropdown(); |
|
978 | + return array_merge($old_filters, $filters); |
|
979 | + } |
|
980 | + |
|
981 | + |
|
982 | + /** |
|
983 | + * espresso_event_months_dropdown |
|
984 | + * |
|
985 | + * @access public |
|
986 | + * @return string dropdown listing month/year selections for events. |
|
987 | + */ |
|
988 | + public function espresso_event_months_dropdown() |
|
989 | + { |
|
990 | + // what we need to do is get all PRIMARY datetimes for all events to filter on. |
|
991 | + // Note we need to include any other filters that are set! |
|
992 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
993 | + //categories? |
|
994 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
995 | + ? $this->_req_data['EVT_CAT'] |
|
996 | + : null; |
|
997 | + //active status? |
|
998 | + $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null; |
|
999 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
1000 | + return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status); |
|
1001 | + } |
|
1002 | + |
|
1003 | + |
|
1004 | + /** |
|
1005 | + * returns a list of "active" statuses on the event |
|
1006 | + * |
|
1007 | + * @param string $current_value whatever the current active status is |
|
1008 | + * @return string |
|
1009 | + */ |
|
1010 | + public function active_status_dropdown($current_value = '') |
|
1011 | + { |
|
1012 | + $select_name = 'active_status'; |
|
1013 | + $values = array( |
|
1014 | + 'none' => esc_html__('Show Active/Inactive', 'event_espresso'), |
|
1015 | + 'active' => esc_html__('Active', 'event_espresso'), |
|
1016 | + 'upcoming' => esc_html__('Upcoming', 'event_espresso'), |
|
1017 | + 'expired' => esc_html__('Expired', 'event_espresso'), |
|
1018 | + 'inactive' => esc_html__('Inactive', 'event_espresso'), |
|
1019 | + ); |
|
1020 | + $id = 'id="espresso-active-status-dropdown-filter"'; |
|
1021 | + $class = 'wide'; |
|
1022 | + return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class); |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * output a dropdown of the categories for the category filter on the event admin list table |
|
1028 | + * |
|
1029 | + * @access public |
|
1030 | + * @return string html |
|
1031 | + */ |
|
1032 | + public function category_dropdown() |
|
1033 | + { |
|
1034 | + $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
1035 | + return EEH_Form_Fields::generate_event_category_dropdown($cur_cat); |
|
1036 | + } |
|
1037 | + |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * get total number of events today |
|
1041 | + * |
|
1042 | + * @access public |
|
1043 | + * @return int |
|
1044 | + * @throws EE_Error |
|
1045 | + */ |
|
1046 | + public function total_events_today() |
|
1047 | + { |
|
1048 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1049 | + 'DTT_EVT_start', |
|
1050 | + date('Y-m-d') . ' 00:00:00', |
|
1051 | + 'Y-m-d H:i:s', |
|
1052 | + 'UTC' |
|
1053 | + ); |
|
1054 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1055 | + 'DTT_EVT_start', |
|
1056 | + date('Y-m-d') . ' 23:59:59', |
|
1057 | + 'Y-m-d H:i:s', |
|
1058 | + 'UTC' |
|
1059 | + ); |
|
1060 | + $where = array( |
|
1061 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1062 | + ); |
|
1063 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1064 | + return $count; |
|
1065 | + } |
|
1066 | + |
|
1067 | + |
|
1068 | + /** |
|
1069 | + * get total number of events this month |
|
1070 | + * |
|
1071 | + * @access public |
|
1072 | + * @return int |
|
1073 | + * @throws EE_Error |
|
1074 | + */ |
|
1075 | + public function total_events_this_month() |
|
1076 | + { |
|
1077 | + //Dates |
|
1078 | + $this_year_r = date('Y'); |
|
1079 | + $this_month_r = date('m'); |
|
1080 | + $days_this_month = date('t'); |
|
1081 | + $start = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1082 | + 'DTT_EVT_start', |
|
1083 | + $this_year_r . '-' . $this_month_r . '-01 00:00:00', |
|
1084 | + 'Y-m-d H:i:s', |
|
1085 | + 'UTC' |
|
1086 | + ); |
|
1087 | + $end = EEM_Datetime::instance()->convert_datetime_for_query( |
|
1088 | + 'DTT_EVT_start', |
|
1089 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59', |
|
1090 | + 'Y-m-d H:i:s', |
|
1091 | + 'UTC' |
|
1092 | + ); |
|
1093 | + $where = array( |
|
1094 | + 'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)), |
|
1095 | + ); |
|
1096 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
1097 | + return $count; |
|
1098 | + } |
|
1099 | + |
|
1100 | + |
|
1101 | + /** DEFAULT TICKETS STUFF **/ |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * Output default tickets list table view. |
|
1105 | + */ |
|
1106 | + public function _tickets_overview_list_table() |
|
1107 | + { |
|
1108 | + $this->_search_btn_label = esc_html__('Tickets', 'event_espresso'); |
|
1109 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1110 | + } |
|
1111 | + |
|
1112 | + |
|
1113 | + /** |
|
1114 | + * @param int $per_page |
|
1115 | + * @param bool $count |
|
1116 | + * @param bool $trashed |
|
1117 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
1118 | + */ |
|
1119 | + public function get_default_tickets($per_page = 10, $count = false, $trashed = false) |
|
1120 | + { |
|
1121 | + $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby']; |
|
1122 | + $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order']; |
|
1123 | + switch ($orderby) { |
|
1124 | + case 'TKT_name': |
|
1125 | + $orderby = array('TKT_name' => $order); |
|
1126 | + break; |
|
1127 | + case 'TKT_price': |
|
1128 | + $orderby = array('TKT_price' => $order); |
|
1129 | + break; |
|
1130 | + case 'TKT_uses': |
|
1131 | + $orderby = array('TKT_uses' => $order); |
|
1132 | + break; |
|
1133 | + case 'TKT_min': |
|
1134 | + $orderby = array('TKT_min' => $order); |
|
1135 | + break; |
|
1136 | + case 'TKT_max': |
|
1137 | + $orderby = array('TKT_max' => $order); |
|
1138 | + break; |
|
1139 | + case 'TKT_qty': |
|
1140 | + $orderby = array('TKT_qty' => $order); |
|
1141 | + break; |
|
1142 | + } |
|
1143 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
1144 | + ? $this->_req_data['paged'] |
|
1145 | + : 1; |
|
1146 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
1147 | + ? $this->_req_data['perpage'] |
|
1148 | + : $per_page; |
|
1149 | + $_where = array( |
|
1150 | + 'TKT_is_default' => 1, |
|
1151 | + 'TKT_deleted' => $trashed, |
|
1152 | + ); |
|
1153 | + $offset = ($current_page - 1) * $per_page; |
|
1154 | + $limit = array($offset, $per_page); |
|
1155 | + if (isset($this->_req_data['s'])) { |
|
1156 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1157 | + $_where['OR'] = array( |
|
1158 | + 'TKT_name' => array('LIKE', $sstr), |
|
1159 | + 'TKT_description' => array('LIKE', $sstr), |
|
1160 | + ); |
|
1161 | + } |
|
1162 | + $query_params = array( |
|
1163 | + $_where, |
|
1164 | + 'order_by' => $orderby, |
|
1165 | + 'limit' => $limit, |
|
1166 | + 'group_by' => 'TKT_ID', |
|
1167 | + ); |
|
1168 | + if ($count) { |
|
1169 | + return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where)); |
|
1170 | + } else { |
|
1171 | + return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params); |
|
1172 | + } |
|
1173 | + } |
|
1174 | + |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * @param bool $trash |
|
1178 | + * @throws EE_Error |
|
1179 | + */ |
|
1180 | + protected function _trash_or_restore_ticket($trash = false) |
|
1181 | + { |
|
1182 | + $success = 1; |
|
1183 | + $TKT = EEM_Ticket::instance(); |
|
1184 | + //checkboxes? |
|
1185 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1186 | + //if array has more than one element then success message should be plural |
|
1187 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1188 | + //cycle thru the boxes |
|
1189 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1190 | + if ($trash) { |
|
1191 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1192 | + $success = 0; |
|
1193 | + } |
|
1194 | + } else { |
|
1195 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1196 | + $success = 0; |
|
1197 | + } |
|
1198 | + } |
|
1199 | + } |
|
1200 | + } else { |
|
1201 | + //grab single id and trash |
|
1202 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1203 | + if ($trash) { |
|
1204 | + if (! $TKT->delete_by_ID($TKT_ID)) { |
|
1205 | + $success = 0; |
|
1206 | + } |
|
1207 | + } else { |
|
1208 | + if (! $TKT->restore_by_ID($TKT_ID)) { |
|
1209 | + $success = 0; |
|
1210 | + } |
|
1211 | + } |
|
1212 | + } |
|
1213 | + $action_desc = $trash ? 'moved to the trash' : 'restored'; |
|
1214 | + $query_args = array( |
|
1215 | + 'action' => 'ticket_list_table', |
|
1216 | + 'status' => $trash ? '' : 'trashed', |
|
1217 | + ); |
|
1218 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1219 | + } |
|
1220 | + |
|
1221 | + |
|
1222 | + /** |
|
1223 | + * Handles trashing default ticket. |
|
1224 | + */ |
|
1225 | + protected function _delete_ticket() |
|
1226 | + { |
|
1227 | + $success = 1; |
|
1228 | + //checkboxes? |
|
1229 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1230 | + //if array has more than one element then success message should be plural |
|
1231 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
1232 | + //cycle thru the boxes |
|
1233 | + while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1234 | + //delete |
|
1235 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1236 | + $success = 0; |
|
1237 | + } |
|
1238 | + } |
|
1239 | + } else { |
|
1240 | + //grab single id and trash |
|
1241 | + $TKT_ID = absint($this->_req_data['TKT_ID']); |
|
1242 | + if (! $this->_delete_the_ticket($TKT_ID)) { |
|
1243 | + $success = 0; |
|
1244 | + } |
|
1245 | + } |
|
1246 | + $action_desc = 'deleted'; |
|
1247 | + $query_args = array( |
|
1248 | + 'action' => 'ticket_list_table', |
|
1249 | + 'status' => 'trashed', |
|
1250 | + ); |
|
1251 | + //fail safe. If the default ticket count === 1 then we need to redirect to event overview. |
|
1252 | + if (EEM_Ticket::instance()->count_deleted_and_undeleted( |
|
1253 | + array(array('TKT_is_default' => 1)), |
|
1254 | + 'TKT_ID', |
|
1255 | + true |
|
1256 | + ) |
|
1257 | + ) { |
|
1258 | + $query_args = array(); |
|
1259 | + } |
|
1260 | + $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args); |
|
1261 | + } |
|
1262 | + |
|
1263 | + |
|
1264 | + /** |
|
1265 | + * @param int $TKT_ID |
|
1266 | + * @return bool|int |
|
1267 | + * @throws EE_Error |
|
1268 | + */ |
|
1269 | + protected function _delete_the_ticket($TKT_ID) |
|
1270 | + { |
|
1271 | + $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID); |
|
1272 | + $tkt->_remove_relations('Datetime'); |
|
1273 | + //delete all related prices first |
|
1274 | + $tkt->delete_related_permanently('Price'); |
|
1275 | + return $tkt->delete_permanently(); |
|
1276 | + } |
|
1277 | 1277 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | use WP_Post; |
18 | 18 | |
19 | 19 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
20 | - exit( 'No direct script access allowed' ); |
|
20 | + exit( 'No direct script access allowed' ); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -34,688 +34,688 @@ discard block |
||
34 | 34 | class DisplayTicketSelector |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * event that ticket selector is being generated for |
|
39 | - * |
|
40 | - * @access protected |
|
41 | - * @var EE_Event $event |
|
42 | - */ |
|
43 | - protected $event; |
|
44 | - |
|
45 | - /** |
|
46 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
47 | - * |
|
48 | - * @var bool $iframe |
|
49 | - */ |
|
50 | - protected $iframe = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * max attendees that can register for event at one time |
|
54 | - * |
|
55 | - * @var int $max_attendees |
|
56 | - */ |
|
57 | - private $max_attendees = EE_INF; |
|
58 | - |
|
59 | - /** |
|
60 | - *@var string $date_format |
|
61 | - */ |
|
62 | - private $date_format; |
|
63 | - |
|
64 | - /** |
|
65 | - *@var string $time_format |
|
66 | - */ |
|
67 | - private $time_format; |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * DisplayTicketSelector constructor. |
|
73 | - */ |
|
74 | - public function __construct() |
|
75 | - { |
|
76 | - $this->date_format = apply_filters( |
|
77 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
78 | - get_option('date_format') |
|
79 | - ); |
|
80 | - $this->time_format = apply_filters( |
|
81 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
82 | - get_option('time_format') |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @param boolean $iframe |
|
90 | - */ |
|
91 | - public function setIframe( $iframe = true ) |
|
92 | - { |
|
93 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * finds and sets the \EE_Event object for use throughout class |
|
99 | - * |
|
100 | - * @param mixed $event |
|
101 | - * @return bool |
|
102 | - * @throws EE_Error |
|
103 | - */ |
|
104 | - protected function setEvent( $event = null ) |
|
105 | - { |
|
106 | - if ( $event === null ) { |
|
107 | - global $post; |
|
108 | - $event = $post; |
|
109 | - } |
|
110 | - if ( $event instanceof EE_Event ) { |
|
111 | - $this->event = $event; |
|
112 | - } else if ( $event instanceof WP_Post ) { |
|
113 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
114 | - $this->event = $event->EE_Event; |
|
115 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
116 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
117 | - $this->event = $event->EE_Event; |
|
118 | - } |
|
119 | - } else { |
|
120 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
121 | - $dev_msg = $user_msg . __( |
|
122 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
123 | - 'event_espresso' |
|
124 | - ); |
|
125 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
126 | - return false; |
|
127 | - } |
|
128 | - return true; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @return int |
|
135 | - */ |
|
136 | - public function getMaxAttendees() |
|
137 | - { |
|
138 | - return $this->max_attendees; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param int $max_attendees |
|
145 | - */ |
|
146 | - public function setMaxAttendees($max_attendees) |
|
147 | - { |
|
148 | - $this->max_attendees = absint( |
|
149 | - apply_filters( |
|
150 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
151 | - $max_attendees |
|
152 | - ) |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * creates buttons for selecting number of attendees for an event |
|
160 | - * |
|
161 | - * @param WP_Post|int $event |
|
162 | - * @param bool $view_details |
|
163 | - * @return string |
|
164 | - * @throws EE_Error |
|
165 | - */ |
|
166 | - public function display( $event = null, $view_details = false ) |
|
167 | - { |
|
168 | - // reset filter for displaying submit button |
|
169 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
170 | - // poke and prod incoming event till it tells us what it is |
|
171 | - if ( ! $this->setEvent( $event ) ) { |
|
172 | - return false; |
|
173 | - } |
|
174 | - // begin gathering template arguments by getting event status |
|
175 | - $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
176 | - if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
177 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
178 | - } |
|
179 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
180 | - $this->setMaxAttendees($this->event->additional_limit()); |
|
181 | - if ($this->getMaxAttendees() < 1) { |
|
182 | - return $this->ticketSalesClosedMessage(); |
|
183 | - } |
|
184 | - // is the event expired ? |
|
185 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
186 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
187 | - return $this->expiredEventMessage(); |
|
188 | - } |
|
189 | - // get all tickets for this event ordered by the datetime |
|
190 | - $tickets = $this->getTickets(); |
|
191 | - if (count($tickets) < 1) { |
|
192 | - return $this->noTicketAvailableMessage(); |
|
193 | - } |
|
194 | - if (EED_Events_Archive::is_iframe()){ |
|
195 | - $this->setIframe(); |
|
196 | - } |
|
197 | - // redirecting to another site for registration ?? |
|
198 | - $external_url = (string) $this->event->external_url(); |
|
199 | - // if redirecting to another site for registration, then we don't load the TS |
|
200 | - $ticket_selector = $external_url |
|
201 | - ? $this->externalEventRegistration() |
|
202 | - : $this->loadTicketSelector($tickets,$template_args); |
|
203 | - // now set up the form (but not for the admin) |
|
204 | - $ticket_selector = ! is_admin() |
|
205 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
206 | - : $ticket_selector; |
|
207 | - // submit button and form close tag |
|
208 | - $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
|
209 | - return $ticket_selector; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * displayTicketSelector |
|
216 | - * examines the event properties and determines whether a Ticket Selector should be displayed |
|
217 | - * |
|
218 | - * @param WP_Post|int $event |
|
219 | - * @param string $_event_active_status |
|
220 | - * @param bool $view_details |
|
221 | - * @return bool |
|
222 | - * @throws EE_Error |
|
223 | - */ |
|
224 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
225 | - { |
|
226 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
227 | - return ! is_admin() |
|
228 | - && ( |
|
229 | - ! $this->event->display_ticket_selector() |
|
230 | - || $view_details |
|
231 | - || post_password_required($event_post) |
|
232 | - || ( |
|
233 | - $_event_active_status !== EE_Datetime::active |
|
234 | - && $_event_active_status !== EE_Datetime::upcoming |
|
235 | - && $_event_active_status !== EE_Datetime::sold_out |
|
236 | - && ! ( |
|
237 | - $_event_active_status === EE_Datetime::inactive |
|
238 | - && is_user_logged_in() |
|
239 | - ) |
|
240 | - ) |
|
241 | - ); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * noTicketAvailableMessage |
|
248 | - * notice displayed if event is expired |
|
249 | - * |
|
250 | - * @return string |
|
251 | - * @throws EE_Error |
|
252 | - */ |
|
253 | - protected function expiredEventMessage() |
|
254 | - { |
|
255 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
256 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
257 | - 'event_espresso' |
|
258 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * noTicketAvailableMessage |
|
265 | - * notice displayed if event has no more tickets available |
|
266 | - * |
|
267 | - * @return string |
|
268 | - * @throws EE_Error |
|
269 | - */ |
|
270 | - protected function noTicketAvailableMessage() |
|
271 | - { |
|
272 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
273 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
274 | - $no_ticket_available_msg .= sprintf( |
|
275 | - esc_html__( |
|
276 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
277 | - 'event_espresso' |
|
278 | - ), |
|
279 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
280 | - '</b><br />', |
|
281 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
282 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
283 | - ); |
|
284 | - } |
|
285 | - return ' |
|
37 | + /** |
|
38 | + * event that ticket selector is being generated for |
|
39 | + * |
|
40 | + * @access protected |
|
41 | + * @var EE_Event $event |
|
42 | + */ |
|
43 | + protected $event; |
|
44 | + |
|
45 | + /** |
|
46 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
47 | + * |
|
48 | + * @var bool $iframe |
|
49 | + */ |
|
50 | + protected $iframe = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * max attendees that can register for event at one time |
|
54 | + * |
|
55 | + * @var int $max_attendees |
|
56 | + */ |
|
57 | + private $max_attendees = EE_INF; |
|
58 | + |
|
59 | + /** |
|
60 | + *@var string $date_format |
|
61 | + */ |
|
62 | + private $date_format; |
|
63 | + |
|
64 | + /** |
|
65 | + *@var string $time_format |
|
66 | + */ |
|
67 | + private $time_format; |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * DisplayTicketSelector constructor. |
|
73 | + */ |
|
74 | + public function __construct() |
|
75 | + { |
|
76 | + $this->date_format = apply_filters( |
|
77 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
78 | + get_option('date_format') |
|
79 | + ); |
|
80 | + $this->time_format = apply_filters( |
|
81 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
82 | + get_option('time_format') |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @param boolean $iframe |
|
90 | + */ |
|
91 | + public function setIframe( $iframe = true ) |
|
92 | + { |
|
93 | + $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * finds and sets the \EE_Event object for use throughout class |
|
99 | + * |
|
100 | + * @param mixed $event |
|
101 | + * @return bool |
|
102 | + * @throws EE_Error |
|
103 | + */ |
|
104 | + protected function setEvent( $event = null ) |
|
105 | + { |
|
106 | + if ( $event === null ) { |
|
107 | + global $post; |
|
108 | + $event = $post; |
|
109 | + } |
|
110 | + if ( $event instanceof EE_Event ) { |
|
111 | + $this->event = $event; |
|
112 | + } else if ( $event instanceof WP_Post ) { |
|
113 | + if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
114 | + $this->event = $event->EE_Event; |
|
115 | + } else if ( $event->post_type === 'espresso_events' ) { |
|
116 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
117 | + $this->event = $event->EE_Event; |
|
118 | + } |
|
119 | + } else { |
|
120 | + $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
121 | + $dev_msg = $user_msg . __( |
|
122 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
123 | + 'event_espresso' |
|
124 | + ); |
|
125 | + EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
126 | + return false; |
|
127 | + } |
|
128 | + return true; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @return int |
|
135 | + */ |
|
136 | + public function getMaxAttendees() |
|
137 | + { |
|
138 | + return $this->max_attendees; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param int $max_attendees |
|
145 | + */ |
|
146 | + public function setMaxAttendees($max_attendees) |
|
147 | + { |
|
148 | + $this->max_attendees = absint( |
|
149 | + apply_filters( |
|
150 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
151 | + $max_attendees |
|
152 | + ) |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * creates buttons for selecting number of attendees for an event |
|
160 | + * |
|
161 | + * @param WP_Post|int $event |
|
162 | + * @param bool $view_details |
|
163 | + * @return string |
|
164 | + * @throws EE_Error |
|
165 | + */ |
|
166 | + public function display( $event = null, $view_details = false ) |
|
167 | + { |
|
168 | + // reset filter for displaying submit button |
|
169 | + remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
170 | + // poke and prod incoming event till it tells us what it is |
|
171 | + if ( ! $this->setEvent( $event ) ) { |
|
172 | + return false; |
|
173 | + } |
|
174 | + // begin gathering template arguments by getting event status |
|
175 | + $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
176 | + if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
177 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
178 | + } |
|
179 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
180 | + $this->setMaxAttendees($this->event->additional_limit()); |
|
181 | + if ($this->getMaxAttendees() < 1) { |
|
182 | + return $this->ticketSalesClosedMessage(); |
|
183 | + } |
|
184 | + // is the event expired ? |
|
185 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
186 | + if ( $template_args[ 'event_is_expired' ] ) { |
|
187 | + return $this->expiredEventMessage(); |
|
188 | + } |
|
189 | + // get all tickets for this event ordered by the datetime |
|
190 | + $tickets = $this->getTickets(); |
|
191 | + if (count($tickets) < 1) { |
|
192 | + return $this->noTicketAvailableMessage(); |
|
193 | + } |
|
194 | + if (EED_Events_Archive::is_iframe()){ |
|
195 | + $this->setIframe(); |
|
196 | + } |
|
197 | + // redirecting to another site for registration ?? |
|
198 | + $external_url = (string) $this->event->external_url(); |
|
199 | + // if redirecting to another site for registration, then we don't load the TS |
|
200 | + $ticket_selector = $external_url |
|
201 | + ? $this->externalEventRegistration() |
|
202 | + : $this->loadTicketSelector($tickets,$template_args); |
|
203 | + // now set up the form (but not for the admin) |
|
204 | + $ticket_selector = ! is_admin() |
|
205 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
206 | + : $ticket_selector; |
|
207 | + // submit button and form close tag |
|
208 | + $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
|
209 | + return $ticket_selector; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * displayTicketSelector |
|
216 | + * examines the event properties and determines whether a Ticket Selector should be displayed |
|
217 | + * |
|
218 | + * @param WP_Post|int $event |
|
219 | + * @param string $_event_active_status |
|
220 | + * @param bool $view_details |
|
221 | + * @return bool |
|
222 | + * @throws EE_Error |
|
223 | + */ |
|
224 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
225 | + { |
|
226 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
227 | + return ! is_admin() |
|
228 | + && ( |
|
229 | + ! $this->event->display_ticket_selector() |
|
230 | + || $view_details |
|
231 | + || post_password_required($event_post) |
|
232 | + || ( |
|
233 | + $_event_active_status !== EE_Datetime::active |
|
234 | + && $_event_active_status !== EE_Datetime::upcoming |
|
235 | + && $_event_active_status !== EE_Datetime::sold_out |
|
236 | + && ! ( |
|
237 | + $_event_active_status === EE_Datetime::inactive |
|
238 | + && is_user_logged_in() |
|
239 | + ) |
|
240 | + ) |
|
241 | + ); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * noTicketAvailableMessage |
|
248 | + * notice displayed if event is expired |
|
249 | + * |
|
250 | + * @return string |
|
251 | + * @throws EE_Error |
|
252 | + */ |
|
253 | + protected function expiredEventMessage() |
|
254 | + { |
|
255 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
256 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
257 | + 'event_espresso' |
|
258 | + ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * noTicketAvailableMessage |
|
265 | + * notice displayed if event has no more tickets available |
|
266 | + * |
|
267 | + * @return string |
|
268 | + * @throws EE_Error |
|
269 | + */ |
|
270 | + protected function noTicketAvailableMessage() |
|
271 | + { |
|
272 | + $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
273 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
274 | + $no_ticket_available_msg .= sprintf( |
|
275 | + esc_html__( |
|
276 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
277 | + 'event_espresso' |
|
278 | + ), |
|
279 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
280 | + '</b><br />', |
|
281 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
282 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
283 | + ); |
|
284 | + } |
|
285 | + return ' |
|
286 | 286 | <div class="ee-event-expired-notice"> |
287 | 287 | <span class="important-notice">' . $no_ticket_available_msg . '</span> |
288 | 288 | </div><!-- .ee-event-expired-notice -->'; |
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * ticketSalesClosed |
|
295 | - * notice displayed if event ticket sales are turned off |
|
296 | - * |
|
297 | - * @return string |
|
298 | - * @throws EE_Error |
|
299 | - */ |
|
300 | - protected function ticketSalesClosedMessage() |
|
301 | - { |
|
302 | - $sales_closed_msg = esc_html__( |
|
303 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
304 | - 'event_espresso' |
|
305 | - ); |
|
306 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
307 | - $sales_closed_msg .= sprintf( |
|
308 | - esc_html__( |
|
309 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
310 | - 'event_espresso' |
|
311 | - ), |
|
312 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
313 | - '</b><br />', |
|
314 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
315 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
316 | - ); |
|
317 | - } |
|
318 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * getTickets |
|
325 | - * |
|
326 | - * @return \EE_Base_Class[]|\EE_Ticket[] |
|
327 | - * @throws EE_Error |
|
328 | - */ |
|
329 | - protected function getTickets() |
|
330 | - { |
|
331 | - $ticket_query_args = array( |
|
332 | - array('Datetime.EVT_ID' => $this->event->ID()), |
|
333 | - 'order_by' => array( |
|
334 | - 'TKT_order' => 'ASC', |
|
335 | - 'TKT_required' => 'DESC', |
|
336 | - 'TKT_start_date' => 'ASC', |
|
337 | - 'TKT_end_date' => 'ASC', |
|
338 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
339 | - ), |
|
340 | - ); |
|
341 | - if ( |
|
342 | - ! ( |
|
343 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
344 | - && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
345 | - ) |
|
346 | - ) { |
|
347 | - //use the correct applicable time query depending on what version of core is being run. |
|
348 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
349 | - ? time() |
|
350 | - : current_time('timestamp'); |
|
351 | - $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
352 | - } |
|
353 | - return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * loadTicketSelector |
|
360 | - * begins to assemble template arguments |
|
361 | - * and decides whether to load a "simple" ticket selector, or the standard |
|
362 | - * |
|
363 | - * @param \EE_Ticket[] $tickets |
|
364 | - * @param array $template_args |
|
365 | - * @return string |
|
366 | - * @throws EE_Error |
|
367 | - */ |
|
368 | - protected function loadTicketSelector(array $tickets, array $template_args) |
|
369 | - { |
|
370 | - $template_args['event'] = $this->event; |
|
371 | - $template_args['EVT_ID'] = $this->event->ID(); |
|
372 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
373 | - $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
374 | - $template_args['date_format'] = $this->date_format; |
|
375 | - $template_args['time_format'] = $this->time_format; |
|
376 | - /** |
|
377 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
378 | - * |
|
379 | - * @since 4.9.13 |
|
380 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
381 | - * @param int $EVT_ID The Event ID |
|
382 | - */ |
|
383 | - $template_args['anchor_id'] = apply_filters( |
|
384 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
385 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
386 | - $this->event->ID() |
|
387 | - ); |
|
388 | - $template_args['tickets'] = $tickets; |
|
389 | - $template_args['ticket_count'] = count($tickets); |
|
390 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
391 | - return $ticket_selector instanceof TicketSelectorSimple |
|
392 | - ? $ticket_selector |
|
393 | - : new TicketSelectorStandard( |
|
394 | - $this->event, |
|
395 | - $tickets, |
|
396 | - $this->getMaxAttendees(), |
|
397 | - $template_args, |
|
398 | - $this->date_format, |
|
399 | - $this->time_format |
|
400 | - ); |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * simpleTicketSelector |
|
407 | - * there's one ticket, and max attendees is set to one, |
|
408 | - * so if the event is free, then this is a "simple" ticket selector |
|
409 | - * a.k.a. "Dude Where's my Ticket Selector?" |
|
410 | - * |
|
411 | - * @param \EE_Ticket[] $tickets |
|
412 | - * @param array $template_args |
|
413 | - * @return string |
|
414 | - * @throws EE_Error |
|
415 | - */ |
|
416 | - protected function simpleTicketSelector($tickets, array $template_args) |
|
417 | - { |
|
418 | - // if there is only ONE ticket with a max qty of ONE |
|
419 | - if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
420 | - return ''; |
|
421 | - } |
|
422 | - /** @var \EE_Ticket $ticket */ |
|
423 | - $ticket = reset($tickets); |
|
424 | - // if the ticket is free... then not much need for the ticket selector |
|
425 | - if ( |
|
426 | - apply_filters( |
|
427 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
428 | - $ticket->is_free(), |
|
429 | - $this->event->ID() |
|
430 | - ) |
|
431 | - ) { |
|
432 | - return new TicketSelectorSimple( |
|
433 | - $this->event, |
|
434 | - $ticket, |
|
435 | - $this->getMaxAttendees(), |
|
436 | - $template_args |
|
437 | - ); |
|
438 | - } |
|
439 | - return ''; |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * externalEventRegistration |
|
446 | - * |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - public function externalEventRegistration() |
|
450 | - { |
|
451 | - // if not we still need to trigger the display of the submit button |
|
452 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
453 | - //display notice to admin that registration is external |
|
454 | - return is_admin() |
|
455 | - ? esc_html__( |
|
456 | - 'Registration is at an external URL for this event.', |
|
457 | - 'event_espresso' |
|
458 | - ) |
|
459 | - : ''; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * formOpen |
|
466 | - * |
|
467 | - * @param int $ID |
|
468 | - * @param string $external_url |
|
469 | - * @return string |
|
470 | - */ |
|
471 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
472 | - { |
|
473 | - // if redirecting, we don't need any anything else |
|
474 | - if ( $external_url ) { |
|
475 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
476 | - // open link in new window ? |
|
477 | - $html .= apply_filters( |
|
478 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
479 | - EED_Events_Archive::is_iframe() |
|
480 | - ) |
|
481 | - ? ' target="_blank"' |
|
482 | - : ''; |
|
483 | - $html .= '>'; |
|
484 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
485 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
486 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
487 | - } |
|
488 | - return $html; |
|
489 | - } |
|
490 | - // if there is no submit button, then don't start building a form |
|
491 | - // because the "View Details" button will build its own form |
|
492 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
493 | - return ''; |
|
494 | - } |
|
495 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
496 | - if ( ! $checkout_url ) { |
|
497 | - EE_Error::add_error( |
|
498 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
499 | - __FILE__, |
|
500 | - __FUNCTION__, |
|
501 | - __LINE__ |
|
502 | - ); |
|
503 | - } |
|
504 | - // set no cache headers and constants |
|
505 | - EE_System::do_not_cache(); |
|
506 | - $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
507 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
508 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
509 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
510 | - return $html; |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - |
|
515 | - /** |
|
516 | - * displaySubmitButton |
|
517 | - * |
|
518 | - * @param string $external_url |
|
519 | - * @return string |
|
520 | - * @throws EE_Error |
|
521 | - */ |
|
522 | - public function displaySubmitButton($external_url = '') |
|
523 | - { |
|
524 | - $html = ''; |
|
525 | - if ( ! is_admin()) { |
|
526 | - // standard TS displayed with submit button, ie: "Register Now" |
|
527 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
528 | - $html .= $this->displayRegisterNowButton(); |
|
529 | - $html .= empty($external_url) |
|
530 | - ? $this->ticketSelectorEndDiv() |
|
531 | - : $this->clearTicketSelector(); |
|
532 | - $html .= '<br/>' . $this->formClose(); |
|
533 | - } else if ($this->getMaxAttendees() === 1) { |
|
534 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
535 | - if ($this->event->is_sold_out()) { |
|
536 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
537 | - $html .= apply_filters( |
|
538 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
539 | - sprintf( |
|
540 | - __( |
|
541 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
542 | - 'event_espresso' |
|
543 | - ), |
|
544 | - '<p class="no-ticket-selector-msg clear-float">', |
|
545 | - $this->event->name(), |
|
546 | - '</p>', |
|
547 | - '<br />' |
|
548 | - ), |
|
549 | - $this->event |
|
550 | - ); |
|
551 | - if ( |
|
552 | - apply_filters( |
|
553 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
554 | - false, |
|
555 | - $this->event |
|
556 | - ) |
|
557 | - ) { |
|
558 | - $html .= $this->displayRegisterNowButton(); |
|
559 | - } |
|
560 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
561 | - $html .= $this->ticketSelectorEndDiv(); |
|
562 | - } else if ( |
|
563 | - apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
564 | - && ! is_single() |
|
565 | - ) { |
|
566 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
567 | - // but no tickets are available, so display event's "View Details" button. |
|
568 | - // it is being viewed via somewhere other than a single post |
|
569 | - $html .= $this->displayViewDetailsButton(true); |
|
570 | - } else { |
|
571 | - $html .= $this->ticketSelectorEndDiv(); |
|
572 | - } |
|
573 | - } else if (is_archive()) { |
|
574 | - // event list, no tickets available so display event's "View Details" button |
|
575 | - $html .= $this->ticketSelectorEndDiv(); |
|
576 | - $html .= $this->displayViewDetailsButton(); |
|
577 | - } else { |
|
578 | - if ( |
|
579 | - apply_filters( |
|
580 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
581 | - false, |
|
582 | - $this->event |
|
583 | - ) |
|
584 | - ) { |
|
585 | - $html .= $this->displayRegisterNowButton(); |
|
586 | - } |
|
587 | - // no submit or view details button, and no additional content |
|
588 | - $html .= $this->ticketSelectorEndDiv(); |
|
589 | - } |
|
590 | - if ( ! $this->iframe && ! is_archive()) { |
|
591 | - $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
592 | - } |
|
593 | - } |
|
594 | - return apply_filters( |
|
595 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
596 | - $html, |
|
597 | - $this->event |
|
598 | - ); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - |
|
603 | - /** |
|
604 | - * @return string |
|
605 | - * @throws EE_Error |
|
606 | - */ |
|
607 | - public function displayRegisterNowButton() |
|
608 | - { |
|
609 | - $btn_text = apply_filters( |
|
610 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
611 | - __('Register Now', 'event_espresso'), |
|
612 | - $this->event |
|
613 | - ); |
|
614 | - $external_url = $this->event->external_url(); |
|
615 | - $html = EEH_HTML::div( |
|
616 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
617 | - ); |
|
618 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
619 | - $html .= ' class="ticket-selector-submit-btn '; |
|
620 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
621 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
622 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
623 | - $html .= apply_filters( |
|
624 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
625 | - '', |
|
626 | - $this->event |
|
627 | - ); |
|
628 | - return $html; |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * displayViewDetailsButton |
|
634 | - * |
|
635 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
636 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
637 | - * either because they are sold out, expired, or not yet on sale. |
|
638 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
639 | - * @return string |
|
640 | - * @throws EE_Error |
|
641 | - */ |
|
642 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
643 | - { |
|
644 | - if ( ! $this->event->get_permalink() ) { |
|
645 | - EE_Error::add_error( |
|
646 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
647 | - __FILE__, __FUNCTION__, __LINE__ |
|
648 | - ); |
|
649 | - } |
|
650 | - $view_details_btn = '<form method="POST" action="'; |
|
651 | - $view_details_btn .= apply_filters( |
|
652 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
653 | - $this->event->get_permalink(), |
|
654 | - $this->event |
|
655 | - ); |
|
656 | - $view_details_btn .= '"'; |
|
657 | - // open link in new window ? |
|
658 | - $view_details_btn .= apply_filters( |
|
659 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
660 | - EED_Events_Archive::is_iframe() |
|
661 | - ) |
|
662 | - ? ' target="_blank"' |
|
663 | - : ''; |
|
664 | - $view_details_btn .='>'; |
|
665 | - $btn_text = apply_filters( |
|
666 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
667 | - esc_html__('View Details', 'event_espresso'), |
|
668 | - $this->event |
|
669 | - ); |
|
670 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
671 | - . $this->event->ID() |
|
672 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
673 | - . $btn_text |
|
674 | - . '" />'; |
|
675 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
676 | - if ($DWMTS) { |
|
677 | - $view_details_btn .= $this->formClose(); |
|
678 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
679 | - $view_details_btn .= '<br/>'; |
|
680 | - } else { |
|
681 | - $view_details_btn .= $this->clearTicketSelector(); |
|
682 | - $view_details_btn .= '<br/>'; |
|
683 | - $view_details_btn .= $this->formClose(); |
|
684 | - } |
|
685 | - return $view_details_btn; |
|
686 | - } |
|
687 | - |
|
688 | - |
|
689 | - |
|
690 | - /** |
|
691 | - * @return string |
|
692 | - */ |
|
693 | - public function ticketSelectorEndDiv() |
|
694 | - { |
|
695 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - |
|
700 | - /** |
|
701 | - * @return string |
|
702 | - */ |
|
703 | - public function clearTicketSelector() |
|
704 | - { |
|
705 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
706 | - return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * @access public |
|
713 | - * @return string |
|
714 | - */ |
|
715 | - public function formClose() |
|
716 | - { |
|
717 | - return '</form>'; |
|
718 | - } |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * ticketSalesClosed |
|
295 | + * notice displayed if event ticket sales are turned off |
|
296 | + * |
|
297 | + * @return string |
|
298 | + * @throws EE_Error |
|
299 | + */ |
|
300 | + protected function ticketSalesClosedMessage() |
|
301 | + { |
|
302 | + $sales_closed_msg = esc_html__( |
|
303 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
304 | + 'event_espresso' |
|
305 | + ); |
|
306 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
307 | + $sales_closed_msg .= sprintf( |
|
308 | + esc_html__( |
|
309 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
310 | + 'event_espresso' |
|
311 | + ), |
|
312 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
313 | + '</b><br />', |
|
314 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
315 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
316 | + ); |
|
317 | + } |
|
318 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * getTickets |
|
325 | + * |
|
326 | + * @return \EE_Base_Class[]|\EE_Ticket[] |
|
327 | + * @throws EE_Error |
|
328 | + */ |
|
329 | + protected function getTickets() |
|
330 | + { |
|
331 | + $ticket_query_args = array( |
|
332 | + array('Datetime.EVT_ID' => $this->event->ID()), |
|
333 | + 'order_by' => array( |
|
334 | + 'TKT_order' => 'ASC', |
|
335 | + 'TKT_required' => 'DESC', |
|
336 | + 'TKT_start_date' => 'ASC', |
|
337 | + 'TKT_end_date' => 'ASC', |
|
338 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
339 | + ), |
|
340 | + ); |
|
341 | + if ( |
|
342 | + ! ( |
|
343 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
344 | + && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
345 | + ) |
|
346 | + ) { |
|
347 | + //use the correct applicable time query depending on what version of core is being run. |
|
348 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
349 | + ? time() |
|
350 | + : current_time('timestamp'); |
|
351 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
352 | + } |
|
353 | + return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * loadTicketSelector |
|
360 | + * begins to assemble template arguments |
|
361 | + * and decides whether to load a "simple" ticket selector, or the standard |
|
362 | + * |
|
363 | + * @param \EE_Ticket[] $tickets |
|
364 | + * @param array $template_args |
|
365 | + * @return string |
|
366 | + * @throws EE_Error |
|
367 | + */ |
|
368 | + protected function loadTicketSelector(array $tickets, array $template_args) |
|
369 | + { |
|
370 | + $template_args['event'] = $this->event; |
|
371 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
372 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
373 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
374 | + $template_args['date_format'] = $this->date_format; |
|
375 | + $template_args['time_format'] = $this->time_format; |
|
376 | + /** |
|
377 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
378 | + * |
|
379 | + * @since 4.9.13 |
|
380 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
381 | + * @param int $EVT_ID The Event ID |
|
382 | + */ |
|
383 | + $template_args['anchor_id'] = apply_filters( |
|
384 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
385 | + '#tkt-slctr-tbl-' . $this->event->ID(), |
|
386 | + $this->event->ID() |
|
387 | + ); |
|
388 | + $template_args['tickets'] = $tickets; |
|
389 | + $template_args['ticket_count'] = count($tickets); |
|
390 | + $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
391 | + return $ticket_selector instanceof TicketSelectorSimple |
|
392 | + ? $ticket_selector |
|
393 | + : new TicketSelectorStandard( |
|
394 | + $this->event, |
|
395 | + $tickets, |
|
396 | + $this->getMaxAttendees(), |
|
397 | + $template_args, |
|
398 | + $this->date_format, |
|
399 | + $this->time_format |
|
400 | + ); |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * simpleTicketSelector |
|
407 | + * there's one ticket, and max attendees is set to one, |
|
408 | + * so if the event is free, then this is a "simple" ticket selector |
|
409 | + * a.k.a. "Dude Where's my Ticket Selector?" |
|
410 | + * |
|
411 | + * @param \EE_Ticket[] $tickets |
|
412 | + * @param array $template_args |
|
413 | + * @return string |
|
414 | + * @throws EE_Error |
|
415 | + */ |
|
416 | + protected function simpleTicketSelector($tickets, array $template_args) |
|
417 | + { |
|
418 | + // if there is only ONE ticket with a max qty of ONE |
|
419 | + if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
420 | + return ''; |
|
421 | + } |
|
422 | + /** @var \EE_Ticket $ticket */ |
|
423 | + $ticket = reset($tickets); |
|
424 | + // if the ticket is free... then not much need for the ticket selector |
|
425 | + if ( |
|
426 | + apply_filters( |
|
427 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
428 | + $ticket->is_free(), |
|
429 | + $this->event->ID() |
|
430 | + ) |
|
431 | + ) { |
|
432 | + return new TicketSelectorSimple( |
|
433 | + $this->event, |
|
434 | + $ticket, |
|
435 | + $this->getMaxAttendees(), |
|
436 | + $template_args |
|
437 | + ); |
|
438 | + } |
|
439 | + return ''; |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * externalEventRegistration |
|
446 | + * |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + public function externalEventRegistration() |
|
450 | + { |
|
451 | + // if not we still need to trigger the display of the submit button |
|
452 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
453 | + //display notice to admin that registration is external |
|
454 | + return is_admin() |
|
455 | + ? esc_html__( |
|
456 | + 'Registration is at an external URL for this event.', |
|
457 | + 'event_espresso' |
|
458 | + ) |
|
459 | + : ''; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * formOpen |
|
466 | + * |
|
467 | + * @param int $ID |
|
468 | + * @param string $external_url |
|
469 | + * @return string |
|
470 | + */ |
|
471 | + public function formOpen( $ID = 0, $external_url = '' ) |
|
472 | + { |
|
473 | + // if redirecting, we don't need any anything else |
|
474 | + if ( $external_url ) { |
|
475 | + $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
476 | + // open link in new window ? |
|
477 | + $html .= apply_filters( |
|
478 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
479 | + EED_Events_Archive::is_iframe() |
|
480 | + ) |
|
481 | + ? ' target="_blank"' |
|
482 | + : ''; |
|
483 | + $html .= '>'; |
|
484 | + $query_args = EEH_URL::get_query_string( $external_url ); |
|
485 | + foreach ( (array)$query_args as $query_arg => $value ) { |
|
486 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
487 | + } |
|
488 | + return $html; |
|
489 | + } |
|
490 | + // if there is no submit button, then don't start building a form |
|
491 | + // because the "View Details" button will build its own form |
|
492 | + if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
493 | + return ''; |
|
494 | + } |
|
495 | + $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
496 | + if ( ! $checkout_url ) { |
|
497 | + EE_Error::add_error( |
|
498 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
499 | + __FILE__, |
|
500 | + __FUNCTION__, |
|
501 | + __LINE__ |
|
502 | + ); |
|
503 | + } |
|
504 | + // set no cache headers and constants |
|
505 | + EE_System::do_not_cache(); |
|
506 | + $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
507 | + $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
508 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
509 | + $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
510 | + return $html; |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + |
|
515 | + /** |
|
516 | + * displaySubmitButton |
|
517 | + * |
|
518 | + * @param string $external_url |
|
519 | + * @return string |
|
520 | + * @throws EE_Error |
|
521 | + */ |
|
522 | + public function displaySubmitButton($external_url = '') |
|
523 | + { |
|
524 | + $html = ''; |
|
525 | + if ( ! is_admin()) { |
|
526 | + // standard TS displayed with submit button, ie: "Register Now" |
|
527 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
528 | + $html .= $this->displayRegisterNowButton(); |
|
529 | + $html .= empty($external_url) |
|
530 | + ? $this->ticketSelectorEndDiv() |
|
531 | + : $this->clearTicketSelector(); |
|
532 | + $html .= '<br/>' . $this->formClose(); |
|
533 | + } else if ($this->getMaxAttendees() === 1) { |
|
534 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
535 | + if ($this->event->is_sold_out()) { |
|
536 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
537 | + $html .= apply_filters( |
|
538 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
539 | + sprintf( |
|
540 | + __( |
|
541 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
542 | + 'event_espresso' |
|
543 | + ), |
|
544 | + '<p class="no-ticket-selector-msg clear-float">', |
|
545 | + $this->event->name(), |
|
546 | + '</p>', |
|
547 | + '<br />' |
|
548 | + ), |
|
549 | + $this->event |
|
550 | + ); |
|
551 | + if ( |
|
552 | + apply_filters( |
|
553 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
554 | + false, |
|
555 | + $this->event |
|
556 | + ) |
|
557 | + ) { |
|
558 | + $html .= $this->displayRegisterNowButton(); |
|
559 | + } |
|
560 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
561 | + $html .= $this->ticketSelectorEndDiv(); |
|
562 | + } else if ( |
|
563 | + apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
564 | + && ! is_single() |
|
565 | + ) { |
|
566 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
567 | + // but no tickets are available, so display event's "View Details" button. |
|
568 | + // it is being viewed via somewhere other than a single post |
|
569 | + $html .= $this->displayViewDetailsButton(true); |
|
570 | + } else { |
|
571 | + $html .= $this->ticketSelectorEndDiv(); |
|
572 | + } |
|
573 | + } else if (is_archive()) { |
|
574 | + // event list, no tickets available so display event's "View Details" button |
|
575 | + $html .= $this->ticketSelectorEndDiv(); |
|
576 | + $html .= $this->displayViewDetailsButton(); |
|
577 | + } else { |
|
578 | + if ( |
|
579 | + apply_filters( |
|
580 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
581 | + false, |
|
582 | + $this->event |
|
583 | + ) |
|
584 | + ) { |
|
585 | + $html .= $this->displayRegisterNowButton(); |
|
586 | + } |
|
587 | + // no submit or view details button, and no additional content |
|
588 | + $html .= $this->ticketSelectorEndDiv(); |
|
589 | + } |
|
590 | + if ( ! $this->iframe && ! is_archive()) { |
|
591 | + $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
592 | + } |
|
593 | + } |
|
594 | + return apply_filters( |
|
595 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
596 | + $html, |
|
597 | + $this->event |
|
598 | + ); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + |
|
603 | + /** |
|
604 | + * @return string |
|
605 | + * @throws EE_Error |
|
606 | + */ |
|
607 | + public function displayRegisterNowButton() |
|
608 | + { |
|
609 | + $btn_text = apply_filters( |
|
610 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
611 | + __('Register Now', 'event_espresso'), |
|
612 | + $this->event |
|
613 | + ); |
|
614 | + $external_url = $this->event->external_url(); |
|
615 | + $html = EEH_HTML::div( |
|
616 | + '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
617 | + ); |
|
618 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
619 | + $html .= ' class="ticket-selector-submit-btn '; |
|
620 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
621 | + $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
622 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
623 | + $html .= apply_filters( |
|
624 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
625 | + '', |
|
626 | + $this->event |
|
627 | + ); |
|
628 | + return $html; |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * displayViewDetailsButton |
|
634 | + * |
|
635 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
636 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
637 | + * either because they are sold out, expired, or not yet on sale. |
|
638 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
639 | + * @return string |
|
640 | + * @throws EE_Error |
|
641 | + */ |
|
642 | + public function displayViewDetailsButton( $DWMTS = false ) |
|
643 | + { |
|
644 | + if ( ! $this->event->get_permalink() ) { |
|
645 | + EE_Error::add_error( |
|
646 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
647 | + __FILE__, __FUNCTION__, __LINE__ |
|
648 | + ); |
|
649 | + } |
|
650 | + $view_details_btn = '<form method="POST" action="'; |
|
651 | + $view_details_btn .= apply_filters( |
|
652 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
653 | + $this->event->get_permalink(), |
|
654 | + $this->event |
|
655 | + ); |
|
656 | + $view_details_btn .= '"'; |
|
657 | + // open link in new window ? |
|
658 | + $view_details_btn .= apply_filters( |
|
659 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
660 | + EED_Events_Archive::is_iframe() |
|
661 | + ) |
|
662 | + ? ' target="_blank"' |
|
663 | + : ''; |
|
664 | + $view_details_btn .='>'; |
|
665 | + $btn_text = apply_filters( |
|
666 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
667 | + esc_html__('View Details', 'event_espresso'), |
|
668 | + $this->event |
|
669 | + ); |
|
670 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
671 | + . $this->event->ID() |
|
672 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
673 | + . $btn_text |
|
674 | + . '" />'; |
|
675 | + $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
676 | + if ($DWMTS) { |
|
677 | + $view_details_btn .= $this->formClose(); |
|
678 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
679 | + $view_details_btn .= '<br/>'; |
|
680 | + } else { |
|
681 | + $view_details_btn .= $this->clearTicketSelector(); |
|
682 | + $view_details_btn .= '<br/>'; |
|
683 | + $view_details_btn .= $this->formClose(); |
|
684 | + } |
|
685 | + return $view_details_btn; |
|
686 | + } |
|
687 | + |
|
688 | + |
|
689 | + |
|
690 | + /** |
|
691 | + * @return string |
|
692 | + */ |
|
693 | + public function ticketSelectorEndDiv() |
|
694 | + { |
|
695 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + |
|
700 | + /** |
|
701 | + * @return string |
|
702 | + */ |
|
703 | + public function clearTicketSelector() |
|
704 | + { |
|
705 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
706 | + return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * @access public |
|
713 | + * @return string |
|
714 | + */ |
|
715 | + public function formClose() |
|
716 | + { |
|
717 | + return '</form>'; |
|
718 | + } |
|
719 | 719 | |
720 | 720 | |
721 | 721 |
@@ -29,266 +29,266 @@ |
||
29 | 29 | class EspressoEventAttendees extends EspressoShortcode |
30 | 30 | { |
31 | 31 | |
32 | - private $query_params = array( |
|
33 | - 0 => array() |
|
34 | - ); |
|
35 | - |
|
36 | - private $template_args = array( |
|
37 | - 'contacts' => array(), |
|
38 | - 'event' => null, |
|
39 | - 'datetime' => null, |
|
40 | - 'ticket' => null, |
|
41 | - ); |
|
42 | - |
|
43 | - /** |
|
44 | - * the actual shortcode tag that gets registered with WordPress |
|
45 | - * |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function getTag() |
|
49 | - { |
|
50 | - return 'ESPRESSO_EVENT_ATTENDEES'; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * the time in seconds to cache the results of the processShortcode() method |
|
57 | - * 0 means the processShortcode() results will NOT be cached at all |
|
58 | - * |
|
59 | - * @return int |
|
60 | - */ |
|
61 | - public function cacheExpiration() |
|
62 | - { |
|
63 | - return 0; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
70 | - * this may be required for shortcodes that utilize a corresponding module, |
|
71 | - * and need to enqueue assets for that module |
|
72 | - * |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function initializeShortcode() |
|
76 | - { |
|
77 | - $this->shortcodeHasBeenInitialized(); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event. |
|
84 | - * [ESPRESSO_EVENT_ATTENDEES] |
|
85 | - * - defaults to attendees for earliest active event, or earliest upcoming event. |
|
86 | - * |
|
87 | - * [ESPRESSO_EVENT_ATTENDEES event_id=123] |
|
88 | - * - attendees for specific event. |
|
89 | - * |
|
90 | - * [ESPRESSO_EVENT_ATTENDEES datetime_id=245] |
|
91 | - * - attendees for a specific datetime. |
|
92 | - * |
|
93 | - * [ESPRESSO_EVENT_ATTENDEES ticket_id=123] |
|
94 | - * - attendees for a specific ticket. |
|
95 | - * |
|
96 | - * [ESPRESSO_EVENT_ATTENDEES status=all] |
|
97 | - * - specific registration status (use status id) or all for all attendees regardless of status. |
|
98 | - * Note default is to only return approved attendees |
|
99 | - * |
|
100 | - * [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] |
|
101 | - * - default is to not return gravatar. Otherwise if this is set then return gravatar for email address given. |
|
102 | - * |
|
103 | - * [ESPRESSO_EVENT_ATTENDEES display_on_archives=true] |
|
104 | - * - default is to not display attendees list on archive pages. |
|
105 | - * |
|
106 | - * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
107 | - * If more than one of those params is included, then preference is given to the following: |
|
108 | - * - event_id is used whenever its present and any others are ignored. |
|
109 | - * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
110 | - * - otherwise ticket_id is used if present. |
|
111 | - * |
|
112 | - * @param array $attributes |
|
113 | - * @return string |
|
114 | - * @throws EE_Error |
|
115 | - */ |
|
116 | - public function processShortcode($attributes = array()) |
|
117 | - { |
|
118 | - // grab attributes and merge with defaults |
|
119 | - $attributes = $this->getAttributes((array)$attributes); |
|
120 | - $archive = is_archive(); |
|
121 | - $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
|
122 | - // don't display on archives unless 'display_on_archives' is true |
|
123 | - if($archive && ! $display_on_archives) { |
|
124 | - return ''; |
|
125 | - } |
|
126 | - // add attributes to template args |
|
127 | - $this->template_args['show_gravatar'] = $attributes['show_gravatar']; |
|
128 | - // add required objects: event, datetime, and ticket |
|
129 | - $this->template_args['event'] = $this->getEventAndQueryParams($attributes); |
|
130 | - $this->template_args['datetime'] = $this->getDatetimeAndQueryParams($attributes); |
|
131 | - $this->template_args['ticket'] = $this->getTicketAndQueryParams($attributes); |
|
132 | - |
|
133 | - // if any of the above objects is invalid or missing, |
|
134 | - // then there was an invalid parameter or the shortcode was used incorrectly |
|
135 | - // so when WP_DEBUG is set and true, we'll show a message, |
|
136 | - // otherwise we'll just return an empty string. |
|
137 | - if ( |
|
138 | - ! $this->template_args['event'] instanceof EE_Event |
|
139 | - || empty($this->query_params[0]) |
|
140 | - || ($attributes['datetime_id'] && ! $this->template_args['datetime'] instanceof EE_Datetime) |
|
141 | - || ($attributes['ticket_id'] && ! $this->template_args['ticket'] instanceof EE_Ticket) |
|
142 | - ) { |
|
143 | - if (WP_DEBUG) { |
|
144 | - return '<div class="important-notice ee-attention">' |
|
145 | - . esc_html__('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', |
|
146 | - 'event_espresso') |
|
147 | - . '</div>'; |
|
148 | - } |
|
149 | - return ''; |
|
150 | - } |
|
151 | - $this->setAdditionalQueryParams($attributes); |
|
152 | - //get contacts! |
|
153 | - $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params); |
|
154 | - //all set let's load up the template and return. |
|
155 | - return EEH_Template::locate_template( |
|
156 | - 'loop-espresso_event_attendees.php', |
|
157 | - $this->template_args |
|
158 | - ); |
|
159 | - |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * merge incoming attributes with filtered defaults |
|
166 | - * |
|
167 | - * @param array $attributes |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - private function getAttributes(array $attributes) |
|
171 | - { |
|
172 | - return (array) apply_filters( |
|
173 | - 'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', |
|
174 | - $attributes + array( |
|
175 | - 'event_id' => null, |
|
176 | - 'datetime_id' => null, |
|
177 | - 'ticket_id' => null, |
|
178 | - 'status' => EEM_Registration::status_id_approved, |
|
179 | - 'show_gravatar' => false, |
|
180 | - 'display_on_archives' => false, |
|
181 | - ) |
|
182 | - ); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * @param array $attributes |
|
189 | - * @return EE_Event|null |
|
190 | - * @throws EE_Error |
|
191 | - */ |
|
192 | - private function getEventAndQueryParams(array $attributes){ |
|
193 | - if ( ! empty($attributes['event_id'])) { |
|
194 | - $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
|
195 | - if ($event instanceof EE_Event) { |
|
196 | - $this->query_params[0]['Registration.EVT_ID'] = $attributes['event_id']; |
|
197 | - return $event; |
|
198 | - } |
|
199 | - } |
|
200 | - if (is_espresso_event()) { |
|
201 | - $event = EEH_Event_View::get_event(); |
|
202 | - if ($event instanceof EE_Event) { |
|
203 | - $this->query_params[0]['Registration.EVT_ID'] = $event->ID(); |
|
204 | - return $event; |
|
205 | - } |
|
206 | - } |
|
207 | - // one last shot... |
|
208 | - // try getting the earliest active event |
|
209 | - $events = EEM_Event::instance()->get_active_events(array( |
|
210 | - 'limit' => 1, |
|
211 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
212 | - )); |
|
213 | - // if none then get the next upcoming |
|
214 | - $events = empty($events) |
|
215 | - ? EEM_Event::instance()->get_upcoming_events(array( |
|
216 | - 'limit' => 1, |
|
217 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
218 | - )) |
|
219 | - : $events; |
|
220 | - $event = reset($events); |
|
221 | - if ($event instanceof EE_Event) { |
|
222 | - $this->query_params[0]['Registration.EVT_ID'] = $event->ID(); |
|
223 | - return $event; |
|
224 | - } |
|
225 | - return null; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @param array $attributes |
|
232 | - * @return EE_Datetime|null |
|
233 | - */ |
|
234 | - private function getDatetimeAndQueryParams(array $attributes) |
|
235 | - { |
|
236 | - if ( ! empty($attributes['datetime_id'])) { |
|
237 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
|
238 | - if ($datetime instanceof EE_Datetime) { |
|
239 | - $this->query_params[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id']; |
|
240 | - $this->query_params['default_where_conditions'] = 'this_model_only'; |
|
241 | - if ( ! $this->template_args['event'] instanceof EE_Event) { |
|
242 | - $this->template_args['event'] = $datetime->event(); |
|
243 | - } |
|
244 | - return $datetime; |
|
245 | - } |
|
246 | - } |
|
247 | - return null; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param array $attributes |
|
254 | - * @return \EE_Base_Class|null |
|
255 | - * @throws EE_Error |
|
256 | - */ |
|
257 | - private function getTicketAndQueryParams(array $attributes) |
|
258 | - { |
|
259 | - if ( ! empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) { |
|
260 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
|
261 | - if ($ticket instanceof EE_Ticket) { |
|
262 | - $this->query_params[0]['Registration.TKT_ID'] = $attributes['ticket_id']; |
|
263 | - if ( ! $this->template_args['event'] instanceof EE_Event) { |
|
264 | - $this->template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime |
|
265 | - ? $ticket->first_datetime()->event() |
|
266 | - : null; |
|
267 | - } |
|
268 | - return $ticket; |
|
269 | - } |
|
270 | - } |
|
271 | - return null; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * @param array $attributes |
|
278 | - * @throws EE_Error |
|
279 | - */ |
|
280 | - private function setAdditionalQueryParams(array $attributes) |
|
281 | - { |
|
282 | - $reg_status_array = EEM_Registration::reg_status_array(); |
|
283 | - if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) { |
|
284 | - $this->query_params[0]['Registration.STS_ID'] = $attributes['status']; |
|
285 | - } |
|
286 | - $this->query_params['group_by'] = array('ATT_ID'); |
|
287 | - $this->query_params['order_by'] = (array) apply_filters( |
|
288 | - 'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', |
|
289 | - array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC') |
|
290 | - ); |
|
291 | - } |
|
32 | + private $query_params = array( |
|
33 | + 0 => array() |
|
34 | + ); |
|
35 | + |
|
36 | + private $template_args = array( |
|
37 | + 'contacts' => array(), |
|
38 | + 'event' => null, |
|
39 | + 'datetime' => null, |
|
40 | + 'ticket' => null, |
|
41 | + ); |
|
42 | + |
|
43 | + /** |
|
44 | + * the actual shortcode tag that gets registered with WordPress |
|
45 | + * |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function getTag() |
|
49 | + { |
|
50 | + return 'ESPRESSO_EVENT_ATTENDEES'; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * the time in seconds to cache the results of the processShortcode() method |
|
57 | + * 0 means the processShortcode() results will NOT be cached at all |
|
58 | + * |
|
59 | + * @return int |
|
60 | + */ |
|
61 | + public function cacheExpiration() |
|
62 | + { |
|
63 | + return 0; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
70 | + * this may be required for shortcodes that utilize a corresponding module, |
|
71 | + * and need to enqueue assets for that module |
|
72 | + * |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function initializeShortcode() |
|
76 | + { |
|
77 | + $this->shortcodeHasBeenInitialized(); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event. |
|
84 | + * [ESPRESSO_EVENT_ATTENDEES] |
|
85 | + * - defaults to attendees for earliest active event, or earliest upcoming event. |
|
86 | + * |
|
87 | + * [ESPRESSO_EVENT_ATTENDEES event_id=123] |
|
88 | + * - attendees for specific event. |
|
89 | + * |
|
90 | + * [ESPRESSO_EVENT_ATTENDEES datetime_id=245] |
|
91 | + * - attendees for a specific datetime. |
|
92 | + * |
|
93 | + * [ESPRESSO_EVENT_ATTENDEES ticket_id=123] |
|
94 | + * - attendees for a specific ticket. |
|
95 | + * |
|
96 | + * [ESPRESSO_EVENT_ATTENDEES status=all] |
|
97 | + * - specific registration status (use status id) or all for all attendees regardless of status. |
|
98 | + * Note default is to only return approved attendees |
|
99 | + * |
|
100 | + * [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] |
|
101 | + * - default is to not return gravatar. Otherwise if this is set then return gravatar for email address given. |
|
102 | + * |
|
103 | + * [ESPRESSO_EVENT_ATTENDEES display_on_archives=true] |
|
104 | + * - default is to not display attendees list on archive pages. |
|
105 | + * |
|
106 | + * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
107 | + * If more than one of those params is included, then preference is given to the following: |
|
108 | + * - event_id is used whenever its present and any others are ignored. |
|
109 | + * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
110 | + * - otherwise ticket_id is used if present. |
|
111 | + * |
|
112 | + * @param array $attributes |
|
113 | + * @return string |
|
114 | + * @throws EE_Error |
|
115 | + */ |
|
116 | + public function processShortcode($attributes = array()) |
|
117 | + { |
|
118 | + // grab attributes and merge with defaults |
|
119 | + $attributes = $this->getAttributes((array)$attributes); |
|
120 | + $archive = is_archive(); |
|
121 | + $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
|
122 | + // don't display on archives unless 'display_on_archives' is true |
|
123 | + if($archive && ! $display_on_archives) { |
|
124 | + return ''; |
|
125 | + } |
|
126 | + // add attributes to template args |
|
127 | + $this->template_args['show_gravatar'] = $attributes['show_gravatar']; |
|
128 | + // add required objects: event, datetime, and ticket |
|
129 | + $this->template_args['event'] = $this->getEventAndQueryParams($attributes); |
|
130 | + $this->template_args['datetime'] = $this->getDatetimeAndQueryParams($attributes); |
|
131 | + $this->template_args['ticket'] = $this->getTicketAndQueryParams($attributes); |
|
132 | + |
|
133 | + // if any of the above objects is invalid or missing, |
|
134 | + // then there was an invalid parameter or the shortcode was used incorrectly |
|
135 | + // so when WP_DEBUG is set and true, we'll show a message, |
|
136 | + // otherwise we'll just return an empty string. |
|
137 | + if ( |
|
138 | + ! $this->template_args['event'] instanceof EE_Event |
|
139 | + || empty($this->query_params[0]) |
|
140 | + || ($attributes['datetime_id'] && ! $this->template_args['datetime'] instanceof EE_Datetime) |
|
141 | + || ($attributes['ticket_id'] && ! $this->template_args['ticket'] instanceof EE_Ticket) |
|
142 | + ) { |
|
143 | + if (WP_DEBUG) { |
|
144 | + return '<div class="important-notice ee-attention">' |
|
145 | + . esc_html__('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', |
|
146 | + 'event_espresso') |
|
147 | + . '</div>'; |
|
148 | + } |
|
149 | + return ''; |
|
150 | + } |
|
151 | + $this->setAdditionalQueryParams($attributes); |
|
152 | + //get contacts! |
|
153 | + $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params); |
|
154 | + //all set let's load up the template and return. |
|
155 | + return EEH_Template::locate_template( |
|
156 | + 'loop-espresso_event_attendees.php', |
|
157 | + $this->template_args |
|
158 | + ); |
|
159 | + |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * merge incoming attributes with filtered defaults |
|
166 | + * |
|
167 | + * @param array $attributes |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + private function getAttributes(array $attributes) |
|
171 | + { |
|
172 | + return (array) apply_filters( |
|
173 | + 'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', |
|
174 | + $attributes + array( |
|
175 | + 'event_id' => null, |
|
176 | + 'datetime_id' => null, |
|
177 | + 'ticket_id' => null, |
|
178 | + 'status' => EEM_Registration::status_id_approved, |
|
179 | + 'show_gravatar' => false, |
|
180 | + 'display_on_archives' => false, |
|
181 | + ) |
|
182 | + ); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * @param array $attributes |
|
189 | + * @return EE_Event|null |
|
190 | + * @throws EE_Error |
|
191 | + */ |
|
192 | + private function getEventAndQueryParams(array $attributes){ |
|
193 | + if ( ! empty($attributes['event_id'])) { |
|
194 | + $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
|
195 | + if ($event instanceof EE_Event) { |
|
196 | + $this->query_params[0]['Registration.EVT_ID'] = $attributes['event_id']; |
|
197 | + return $event; |
|
198 | + } |
|
199 | + } |
|
200 | + if (is_espresso_event()) { |
|
201 | + $event = EEH_Event_View::get_event(); |
|
202 | + if ($event instanceof EE_Event) { |
|
203 | + $this->query_params[0]['Registration.EVT_ID'] = $event->ID(); |
|
204 | + return $event; |
|
205 | + } |
|
206 | + } |
|
207 | + // one last shot... |
|
208 | + // try getting the earliest active event |
|
209 | + $events = EEM_Event::instance()->get_active_events(array( |
|
210 | + 'limit' => 1, |
|
211 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
212 | + )); |
|
213 | + // if none then get the next upcoming |
|
214 | + $events = empty($events) |
|
215 | + ? EEM_Event::instance()->get_upcoming_events(array( |
|
216 | + 'limit' => 1, |
|
217 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
218 | + )) |
|
219 | + : $events; |
|
220 | + $event = reset($events); |
|
221 | + if ($event instanceof EE_Event) { |
|
222 | + $this->query_params[0]['Registration.EVT_ID'] = $event->ID(); |
|
223 | + return $event; |
|
224 | + } |
|
225 | + return null; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @param array $attributes |
|
232 | + * @return EE_Datetime|null |
|
233 | + */ |
|
234 | + private function getDatetimeAndQueryParams(array $attributes) |
|
235 | + { |
|
236 | + if ( ! empty($attributes['datetime_id'])) { |
|
237 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
|
238 | + if ($datetime instanceof EE_Datetime) { |
|
239 | + $this->query_params[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id']; |
|
240 | + $this->query_params['default_where_conditions'] = 'this_model_only'; |
|
241 | + if ( ! $this->template_args['event'] instanceof EE_Event) { |
|
242 | + $this->template_args['event'] = $datetime->event(); |
|
243 | + } |
|
244 | + return $datetime; |
|
245 | + } |
|
246 | + } |
|
247 | + return null; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param array $attributes |
|
254 | + * @return \EE_Base_Class|null |
|
255 | + * @throws EE_Error |
|
256 | + */ |
|
257 | + private function getTicketAndQueryParams(array $attributes) |
|
258 | + { |
|
259 | + if ( ! empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) { |
|
260 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
|
261 | + if ($ticket instanceof EE_Ticket) { |
|
262 | + $this->query_params[0]['Registration.TKT_ID'] = $attributes['ticket_id']; |
|
263 | + if ( ! $this->template_args['event'] instanceof EE_Event) { |
|
264 | + $this->template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime |
|
265 | + ? $ticket->first_datetime()->event() |
|
266 | + : null; |
|
267 | + } |
|
268 | + return $ticket; |
|
269 | + } |
|
270 | + } |
|
271 | + return null; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * @param array $attributes |
|
278 | + * @throws EE_Error |
|
279 | + */ |
|
280 | + private function setAdditionalQueryParams(array $attributes) |
|
281 | + { |
|
282 | + $reg_status_array = EEM_Registration::reg_status_array(); |
|
283 | + if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) { |
|
284 | + $this->query_params[0]['Registration.STS_ID'] = $attributes['status']; |
|
285 | + } |
|
286 | + $this->query_params['group_by'] = array('ATT_ID'); |
|
287 | + $this->query_params['order_by'] = (array) apply_filters( |
|
288 | + 'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', |
|
289 | + array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC') |
|
290 | + ); |
|
291 | + } |
|
292 | 292 | |
293 | 293 | |
294 | 294 |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | public function processShortcode($attributes = array()) |
117 | 117 | { |
118 | 118 | // grab attributes and merge with defaults |
119 | - $attributes = $this->getAttributes((array)$attributes); |
|
119 | + $attributes = $this->getAttributes((array) $attributes); |
|
120 | 120 | $archive = is_archive(); |
121 | 121 | $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
122 | 122 | // don't display on archives unless 'display_on_archives' is true |
123 | - if($archive && ! $display_on_archives) { |
|
123 | + if ($archive && ! $display_on_archives) { |
|
124 | 124 | return ''; |
125 | 125 | } |
126 | 126 | // add attributes to template args |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | * @return EE_Event|null |
190 | 190 | * @throws EE_Error |
191 | 191 | */ |
192 | - private function getEventAndQueryParams(array $attributes){ |
|
192 | + private function getEventAndQueryParams(array $attributes) { |
|
193 | 193 | if ( ! empty($attributes['event_id'])) { |
194 | 194 | $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
195 | 195 | if ($event instanceof EE_Event) { |
@@ -1047,7 +1047,7 @@ discard block |
||
1047 | 1047 | ); |
1048 | 1048 | do_action( |
1049 | 1049 | 'AHEE__EE_Capabilities__init_role_caps__complete', |
1050 | - $capabilities_map |
|
1050 | + $capabilities_map |
|
1051 | 1051 | ); |
1052 | 1052 | } |
1053 | 1053 | ); |
@@ -1067,9 +1067,9 @@ discard block |
||
1067 | 1067 | 'filter' |
1068 | 1068 | ); |
1069 | 1069 | return apply_filters( |
1070 | - 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1071 | - $existing_attendee, $registration, $attendee_data |
|
1072 | - ); |
|
1070 | + 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee', |
|
1071 | + $existing_attendee, $registration, $attendee_data |
|
1072 | + ); |
|
1073 | 1073 | }, |
1074 | 1074 | 10,3 |
1075 | 1075 | ); |
@@ -1082,88 +1082,88 @@ discard block |
||
1082 | 1082 | class EE_Event_List_Query extends WP_Query |
1083 | 1083 | { |
1084 | 1084 | |
1085 | - private $title; |
|
1086 | - |
|
1087 | - private $css_class; |
|
1088 | - |
|
1089 | - private $category_slug; |
|
1090 | - |
|
1091 | - /** |
|
1092 | - * EE_Event_List_Query constructor. |
|
1093 | - * |
|
1094 | - * @param array $args |
|
1095 | - */ |
|
1096 | - public function __construct($args = array()) |
|
1097 | - { |
|
1098 | - \EE_Error::doing_it_wrong( |
|
1099 | - __METHOD__, |
|
1100 | - __( |
|
1101 | - 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
1102 | - 'event_espresso' |
|
1103 | - ), |
|
1104 | - '4.9.27', |
|
1105 | - '5.0.0' |
|
1106 | - ); |
|
1107 | - $this->title = isset($args['title']) ? $args['title'] : ''; |
|
1108 | - $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
1109 | - $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
1110 | - $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
1111 | - // the current "page" we are viewing |
|
1112 | - $paged = max(1, get_query_var('paged')); |
|
1113 | - // Force these args |
|
1114 | - $args = array_merge( |
|
1115 | - $args, array( |
|
1116 | - 'post_type' => 'espresso_events', |
|
1117 | - 'posts_per_page' => $limit, |
|
1118 | - 'update_post_term_cache' => false, |
|
1119 | - 'update_post_meta_cache' => false, |
|
1120 | - 'paged' => $paged, |
|
1121 | - 'offset' => ($paged - 1) * $limit |
|
1122 | - ) |
|
1123 | - ); |
|
1124 | - // run the query |
|
1125 | - parent::__construct($args); |
|
1126 | - } |
|
1127 | - |
|
1128 | - |
|
1129 | - |
|
1130 | - /** |
|
1131 | - * event_list_title |
|
1132 | - * |
|
1133 | - * @param string $event_list_title |
|
1134 | - * @return string |
|
1135 | - */ |
|
1136 | - public function event_list_title($event_list_title = '') |
|
1137 | - { |
|
1138 | - if (! empty($this->title)) { |
|
1139 | - return $this->title; |
|
1140 | - } |
|
1141 | - return $event_list_title; |
|
1142 | - } |
|
1143 | - |
|
1144 | - |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * event_list_css |
|
1148 | - * |
|
1149 | - * @param string $event_list_css |
|
1150 | - * @return string |
|
1151 | - */ |
|
1152 | - public function event_list_css($event_list_css = '') |
|
1153 | - { |
|
1154 | - $event_list_css .= ! empty($event_list_css) |
|
1155 | - ? ' ' |
|
1156 | - : ''; |
|
1157 | - $event_list_css .= ! empty($this->css_class) |
|
1158 | - ? $this->css_class |
|
1159 | - : ''; |
|
1160 | - $event_list_css .= ! empty($event_list_css) |
|
1161 | - ? ' ' |
|
1162 | - : ''; |
|
1163 | - $event_list_css .= ! empty($this->category_slug) |
|
1164 | - ? $this->category_slug |
|
1165 | - : ''; |
|
1166 | - return $event_list_css; |
|
1167 | - } |
|
1085 | + private $title; |
|
1086 | + |
|
1087 | + private $css_class; |
|
1088 | + |
|
1089 | + private $category_slug; |
|
1090 | + |
|
1091 | + /** |
|
1092 | + * EE_Event_List_Query constructor. |
|
1093 | + * |
|
1094 | + * @param array $args |
|
1095 | + */ |
|
1096 | + public function __construct($args = array()) |
|
1097 | + { |
|
1098 | + \EE_Error::doing_it_wrong( |
|
1099 | + __METHOD__, |
|
1100 | + __( |
|
1101 | + 'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.', |
|
1102 | + 'event_espresso' |
|
1103 | + ), |
|
1104 | + '4.9.27', |
|
1105 | + '5.0.0' |
|
1106 | + ); |
|
1107 | + $this->title = isset($args['title']) ? $args['title'] : ''; |
|
1108 | + $this->css_class = isset($args['css_class']) ? $args['css_class'] : ''; |
|
1109 | + $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : ''; |
|
1110 | + $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10; |
|
1111 | + // the current "page" we are viewing |
|
1112 | + $paged = max(1, get_query_var('paged')); |
|
1113 | + // Force these args |
|
1114 | + $args = array_merge( |
|
1115 | + $args, array( |
|
1116 | + 'post_type' => 'espresso_events', |
|
1117 | + 'posts_per_page' => $limit, |
|
1118 | + 'update_post_term_cache' => false, |
|
1119 | + 'update_post_meta_cache' => false, |
|
1120 | + 'paged' => $paged, |
|
1121 | + 'offset' => ($paged - 1) * $limit |
|
1122 | + ) |
|
1123 | + ); |
|
1124 | + // run the query |
|
1125 | + parent::__construct($args); |
|
1126 | + } |
|
1127 | + |
|
1128 | + |
|
1129 | + |
|
1130 | + /** |
|
1131 | + * event_list_title |
|
1132 | + * |
|
1133 | + * @param string $event_list_title |
|
1134 | + * @return string |
|
1135 | + */ |
|
1136 | + public function event_list_title($event_list_title = '') |
|
1137 | + { |
|
1138 | + if (! empty($this->title)) { |
|
1139 | + return $this->title; |
|
1140 | + } |
|
1141 | + return $event_list_title; |
|
1142 | + } |
|
1143 | + |
|
1144 | + |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * event_list_css |
|
1148 | + * |
|
1149 | + * @param string $event_list_css |
|
1150 | + * @return string |
|
1151 | + */ |
|
1152 | + public function event_list_css($event_list_css = '') |
|
1153 | + { |
|
1154 | + $event_list_css .= ! empty($event_list_css) |
|
1155 | + ? ' ' |
|
1156 | + : ''; |
|
1157 | + $event_list_css .= ! empty($this->css_class) |
|
1158 | + ? $this->css_class |
|
1159 | + : ''; |
|
1160 | + $event_list_css .= ! empty($event_list_css) |
|
1161 | + ? ' ' |
|
1162 | + : ''; |
|
1163 | + $event_list_css .= ! empty($this->category_slug) |
|
1164 | + ? $this->category_slug |
|
1165 | + : ''; |
|
1166 | + return $event_list_css; |
|
1167 | + } |
|
1168 | 1168 | |
1169 | 1169 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | /** |
6 | 6 | * ************************************************************************ |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | $action_or_filter = 'action' |
44 | 44 | ) { |
45 | 45 | $action_or_filter = $action_or_filter === 'action' |
46 | - ? esc_html__( 'action', 'event_espresso' ) |
|
47 | - : esc_html__( 'filter', 'event_espresso' ); |
|
46 | + ? esc_html__('action', 'event_espresso') |
|
47 | + : esc_html__('filter', 'event_espresso'); |
|
48 | 48 | EE_Error::doing_it_wrong( |
49 | 49 | $deprecated_filter, |
50 | 50 | sprintf( |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param \EE_Checkout $checkout |
69 | 69 | * @return string |
70 | 70 | */ |
71 | -function ee_deprecated__registration_checkout__button_text( $submit_button_text, EE_Checkout $checkout ) { |
|
71 | +function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) { |
|
72 | 72 | // list of old filters |
73 | 73 | $deprecated_filters = array( |
74 | 74 | 'update_registration_details' => true, |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | 'proceed_to' => true, |
79 | 79 | ); |
80 | 80 | // loop thru and call doing_it_wrong() or remove any that aren't being used |
81 | - foreach ( $deprecated_filters as $deprecated_filter => $on ) { |
|
81 | + foreach ($deprecated_filters as $deprecated_filter => $on) { |
|
82 | 82 | // was this filter called ? |
83 | - if ( has_action( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter )) { |
|
83 | + if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) { |
|
84 | 84 | // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
85 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter' ) && ! defined( 'DOING_AJAX' ) ) { |
|
85 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter') && ! defined('DOING_AJAX')) { |
|
86 | 86 | EE_Error::doing_it_wrong( |
87 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
87 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
88 | 88 | sprintf( |
89 | - __( 'The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso' ), |
|
90 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
89 | + __('The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso'), |
|
90 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
91 | 91 | '<br />', |
92 | 92 | 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
93 | 93 | '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | ); |
97 | 97 | } |
98 | 98 | } else { |
99 | - unset( $deprecated_filters[ $deprecated_filter ] ); |
|
99 | + unset($deprecated_filters[$deprecated_filter]); |
|
100 | 100 | } |
101 | 101 | } |
102 | - if ( ! empty( $deprecated_filters )) { |
|
103 | - |
|
104 | - if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset( $deprecated_filters[ 'update_registration_details' ] )) { |
|
105 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text ); |
|
106 | - } else if ( $checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset( $deprecated_filters[ 'process_payment' ] ) ) { |
|
107 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text ); |
|
108 | - } else if ( $checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset( $deprecated_filters[ 'finalize_registration' ] ) ) { |
|
109 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text ); |
|
102 | + if ( ! empty($deprecated_filters)) { |
|
103 | + |
|
104 | + if ($checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
|
105 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text); |
|
106 | + } else if ($checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) { |
|
107 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text); |
|
108 | + } else if ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) { |
|
109 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text); |
|
110 | 110 | } |
111 | - if ( $checkout->next_step instanceof EE_SPCO_Reg_Step ) { |
|
112 | - if ( $checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset( $deprecated_filters[ 'and_proceed_to_payment' ] ) ) { |
|
113 | - $submit_button_text .= apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text ); |
|
111 | + if ($checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
112 | + if ($checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) { |
|
113 | + $submit_button_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text); |
|
114 | 114 | } |
115 | - if ( $checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset( $deprecated_filters[ 'proceed_to' ] ) ) { |
|
116 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text ) . $checkout->next_step->name(); |
|
115 | + if ($checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) { |
|
116 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text).$checkout->next_step->name(); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return $submit_button_text; |
122 | 122 | |
123 | 123 | } |
124 | -add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2 ); |
|
124 | +add_filter('FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2); |
|
125 | 125 | |
126 | 126 | |
127 | 127 | |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | * @param \EE_Checkout $checkout |
133 | 133 | * @param boolean $status_updates |
134 | 134 | */ |
135 | -function ee_deprecated_finalize_transaction( EE_Checkout $checkout, $status_updates ) { |
|
135 | +function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) { |
|
136 | 136 | $action_ref = NULL; |
137 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__new_transaction' ) ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
138 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__all_transaction' ) ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
139 | - if ( $action_ref ) { |
|
137 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
138 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
139 | + if ($action_ref) { |
|
140 | 140 | |
141 | 141 | EE_Error::doing_it_wrong( |
142 | 142 | $action_ref, |
143 | 143 | sprintf( |
144 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso' ), |
|
144 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso'), |
|
145 | 145 | '<br />', |
146 | 146 | '/core/business/EE_Transaction_Processor.class.php', |
147 | 147 | 'AHEE__EE_Transaction_Processor__finalize', |
@@ -151,39 +151,39 @@ discard block |
||
151 | 151 | ), |
152 | 152 | '4.6.0' |
153 | 153 | ); |
154 | - switch ( $action_ref ) { |
|
154 | + switch ($action_ref) { |
|
155 | 155 | case 'AHEE__EE_Transaction__finalize__new_transaction' : |
156 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request ); |
|
156 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request); |
|
157 | 157 | break; |
158 | 158 | case 'AHEE__EE_Transaction__finalize__all_transaction' : |
159 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array( 'new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates ), $checkout->admin_request ); |
|
159 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), $checkout->admin_request); |
|
160 | 160 | break; |
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | -add_action( 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2 ); |
|
164 | +add_action('AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2); |
|
165 | 165 | /** |
166 | 166 | * ee_deprecated_finalize_registration |
167 | 167 | * |
168 | 168 | * @param EE_Registration $registration |
169 | 169 | */ |
170 | -function ee_deprecated_finalize_registration( EE_Registration $registration ) { |
|
171 | - $action_ref = has_action( 'AHEE__EE_Registration__finalize__update_and_new_reg' ) ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
172 | - if ( $action_ref ) { |
|
170 | +function ee_deprecated_finalize_registration(EE_Registration $registration) { |
|
171 | + $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
172 | + if ($action_ref) { |
|
173 | 173 | EE_Error::doing_it_wrong( |
174 | 174 | $action_ref, |
175 | 175 | sprintf( |
176 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso' ), |
|
176 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso'), |
|
177 | 177 | '<br />', |
178 | 178 | '/core/business/EE_Registration_Processor.class.php', |
179 | 179 | 'AHEE__EE_Registration_Processor__trigger_registration_status_changed_hook' |
180 | 180 | ), |
181 | 181 | '4.6.0' |
182 | 182 | ); |
183 | - do_action( 'AHEE__EE_Registration__finalize__update_and_new_reg', $registration, ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ))); |
|
183 | + do_action('AHEE__EE_Registration__finalize__update_and_new_reg', $registration, (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))); |
|
184 | 184 | } |
185 | 185 | } |
186 | -add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1 ); |
|
186 | +add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1); |
|
187 | 187 | |
188 | 188 | |
189 | 189 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * Called after EED_Module::set_hooks() and EED_Module::set_admin_hooks() was called. |
192 | 192 | * Checks if any deprecated hooks were hooked-into and provide doing_it_wrong messages appropriately. |
193 | 193 | */ |
194 | -function ee_deprecated_hooks(){ |
|
194 | +function ee_deprecated_hooks() { |
|
195 | 195 | /** |
196 | 196 | * @var $hooks array where keys are hook names, and their values are array{ |
197 | 197 | * @type string $version when deprecated |
@@ -202,25 +202,25 @@ discard block |
||
202 | 202 | $hooks = array( |
203 | 203 | 'AHEE__EE_System___do_setup_validations' => array( |
204 | 204 | 'version' => '4.6.0', |
205 | - 'alternative' => __( 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso' ), |
|
205 | + 'alternative' => __('Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso'), |
|
206 | 206 | 'still_works' => FALSE |
207 | 207 | ) |
208 | 208 | ); |
209 | - foreach( $hooks as $name => $deprecation_info ){ |
|
210 | - if( has_action( $name ) ){ |
|
209 | + foreach ($hooks as $name => $deprecation_info) { |
|
210 | + if (has_action($name)) { |
|
211 | 211 | EE_Error::doing_it_wrong( |
212 | 212 | $name, |
213 | 213 | sprintf( |
214 | - __('This filter is deprecated. %1$s%2$s','event_espresso'), |
|
215 | - $deprecation_info[ 'still_works' ] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __( 'It has been completely removed.', 'event_espresso' ), |
|
216 | - isset( $deprecation_info[ 'alternative' ] ) ? $deprecation_info[ 'alternative' ] : __( 'Please read the current EE4 documentation further or contact Support.', 'event_espresso' ) |
|
214 | + __('This filter is deprecated. %1$s%2$s', 'event_espresso'), |
|
215 | + $deprecation_info['still_works'] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __('It has been completely removed.', 'event_espresso'), |
|
216 | + isset($deprecation_info['alternative']) ? $deprecation_info['alternative'] : __('Please read the current EE4 documentation further or contact Support.', 'event_espresso') |
|
217 | 217 | ), |
218 | - isset( $deprecation_info[ 'version' ] ) ? $deprecation_info[ 'version' ] : __( 'recently', 'event_espresso' ) |
|
218 | + isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso') |
|
219 | 219 | ); |
220 | 220 | } |
221 | 221 | } |
222 | 222 | } |
223 | -add_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks' ); |
|
223 | +add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks'); |
|
224 | 224 | |
225 | 225 | |
226 | 226 | |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | * @return boolean |
232 | 232 | */ |
233 | 233 | function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() { |
234 | - $in_use = has_filter( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns' ) |
|
235 | - || has_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' ); |
|
236 | - if( $in_use ) { |
|
234 | + $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns') |
|
235 | + || has_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'); |
|
236 | + if ($in_use) { |
|
237 | 237 | $msg = __( |
238 | 238 | 'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.' |
239 | 239 | . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,' |
@@ -242,18 +242,18 @@ discard block |
||
242 | 242 | 'event_espresso' ) |
243 | 243 | ; |
244 | 244 | EE_Error::doing_it_wrong( |
245 | - __CLASS__ . '::' . __FUNCTION__, |
|
245 | + __CLASS__.'::'.__FUNCTION__, |
|
246 | 246 | $msg, |
247 | 247 | '4.8.32.rc.000' |
248 | 248 | ); |
249 | 249 | //it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed |
250 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
251 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
250 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
251 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | return $in_use; |
255 | 255 | } |
256 | -add_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' ); |
|
256 | +add_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'); |
|
257 | 257 | |
258 | 258 | /** |
259 | 259 | * @deprecated since 4.8.32.rc.000 because it has issues on https://events.codebasehq.com/projects/event-espresso/tickets/9165 |
@@ -262,34 +262,34 @@ discard block |
||
262 | 262 | * @param EE_Admin_Page $admin_page |
263 | 263 | * @return void |
264 | 264 | */ |
265 | -function ee_deprecated_update_attendee_registration_form_old( $admin_page ) { |
|
265 | +function ee_deprecated_update_attendee_registration_form_old($admin_page) { |
|
266 | 266 | //check if the old hooks are in use. If not, do the default |
267 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
268 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
267 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
268 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | $req_data = $admin_page->get_request_data(); |
272 | - $qstns = isset( $req_data['qstn'] ) ? $req_data['qstn'] : FALSE; |
|
273 | - $REG_ID = isset( $req_data['_REG_ID'] ) ? absint( $req_data['_REG_ID'] ) : FALSE; |
|
274 | - $qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns ); |
|
275 | - if ( ! $REG_ID || ! $qstns ) { |
|
276 | - EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
272 | + $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : FALSE; |
|
273 | + $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : FALSE; |
|
274 | + $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
|
275 | + if ( ! $REG_ID || ! $qstns) { |
|
276 | + EE_Error::add_error(__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
277 | 277 | } |
278 | 278 | $success = TRUE; |
279 | 279 | |
280 | 280 | // allow others to get in on this awesome fun :D |
281 | - do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns ); |
|
281 | + do_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns); |
|
282 | 282 | // loop thru questions... FINALLY!!! |
283 | 283 | |
284 | - foreach ( $qstns as $QST_ID => $qstn ) { |
|
284 | + foreach ($qstns as $QST_ID => $qstn) { |
|
285 | 285 | //if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
286 | - if ( !is_array($qstn) ) { |
|
287 | - $success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn); |
|
286 | + if ( ! is_array($qstn)) { |
|
287 | + $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
|
288 | 288 | continue; |
289 | 289 | } |
290 | 290 | |
291 | 291 | |
292 | - foreach ( $qstn as $ANS_ID => $ANS_value ) { |
|
292 | + foreach ($qstn as $ANS_ID => $ANS_value) { |
|
293 | 293 | //get answer |
294 | 294 | $query_params = array( |
295 | 295 | 0 => array( |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | ); |
301 | 301 | $answer = EEM_Answer::instance()->get_one($query_params); |
302 | 302 | //this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
303 | - if ( ! $answer instanceof EE_Answer ) { |
|
303 | + if ( ! $answer instanceof EE_Answer) { |
|
304 | 304 | $set_values = array( |
305 | 305 | 'QST_ID' => $QST_ID, |
306 | 306 | 'REG_ID' => $REG_ID, |
@@ -315,11 +315,11 @@ discard block |
||
315 | 315 | } |
316 | 316 | } |
317 | 317 | $what = __('Registration Form', 'event_espresso'); |
318 | - $route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' ); |
|
319 | - $admin_page->redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route ); |
|
318 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default'); |
|
319 | + $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
320 | 320 | exit; |
321 | 321 | } |
322 | -add_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1 ); |
|
322 | +add_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1); |
|
323 | 323 | /** |
324 | 324 | * Render the registration admin page's custom questions area in the old fashion |
325 | 325 | * and firing the old hooks. When this method is removed, we can probably also |
@@ -332,31 +332,31 @@ discard block |
||
332 | 332 | * @return bool |
333 | 333 | * @throws \EE_Error |
334 | 334 | */ |
335 | -function ee_deprecated_reg_questions_meta_box_old( $do_default_action, $admin_page, $registration ) { |
|
335 | +function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) { |
|
336 | 336 | //check if the old hooks are in use. If not, do the default |
337 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
338 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
337 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
338 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
339 | 339 | return $do_default_action; |
340 | 340 | } |
341 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $admin_page, 'form_before_question_group' ), 10, 1 ); |
|
342 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $admin_page, 'form_after_question_group' ), 10, 1 ); |
|
343 | - add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $admin_page, 'form_form_field_label_wrap' ), 10, 1 ); |
|
344 | - add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $admin_page, 'form_form_field_input__wrap' ), 10, 1 ); |
|
341 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array($admin_page, 'form_before_question_group'), 10, 1); |
|
342 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array($admin_page, 'form_after_question_group'), 10, 1); |
|
343 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1); |
|
344 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1); |
|
345 | 345 | |
346 | - $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $registration, $registration->get('EVT_ID') ); |
|
346 | + $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options($registration, $registration->get('EVT_ID')); |
|
347 | 347 | |
348 | - EE_Registry::instance()->load_helper( 'Form_Fields' ); |
|
348 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
349 | 349 | $template_args = array( |
350 | - 'att_questions' => EEH_Form_Fields::generate_question_groups_html( $question_groups ), |
|
350 | + 'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups), |
|
351 | 351 | 'reg_questions_form_action' => 'edit_registration', |
352 | 352 | 'REG_ID' => $registration->ID() |
353 | 353 | ); |
354 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
355 | - echo EEH_Template::display_template( $template_path, $template_args, TRUE ); |
|
354 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
355 | + echo EEH_Template::display_template($template_path, $template_args, TRUE); |
|
356 | 356 | //indicate that we should not do the default admin page code |
357 | 357 | return false; |
358 | 358 | } |
359 | -add_action( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3 ); |
|
359 | +add_action('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3); |
|
360 | 360 | |
361 | 361 | |
362 | 362 | |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | '4.9.0' |
398 | 398 | ); |
399 | 399 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
400 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
401 | - $messenger = $message_resource_manager->get_messenger( $messenger_name ); |
|
402 | - $message_type = $message_resource_manager->get_message_type( $message_type_name ); |
|
400 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
401 | + $messenger = $message_resource_manager->get_messenger($messenger_name); |
|
402 | + $message_type = $message_resource_manager->get_message_type($message_type_name); |
|
403 | 403 | return EE_Registry::instance()->load_lib( |
404 | 404 | 'Messages_Template_Defaults', |
405 | 405 | array( |
@@ -464,15 +464,15 @@ discard block |
||
464 | 464 | /** |
465 | 465 | * @param string $method |
466 | 466 | */ |
467 | - public function _class_is_deprecated( $method ) { |
|
467 | + public function _class_is_deprecated($method) { |
|
468 | 468 | EE_Error::doing_it_wrong( |
469 | - 'EE_messages::' . $method, |
|
470 | - __( 'EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.' ), |
|
469 | + 'EE_messages::'.$method, |
|
470 | + __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
|
471 | 471 | '4.9.0', |
472 | 472 | '4.10.0.p' |
473 | 473 | ); |
474 | 474 | // Please use EE_Message_Resource_Manager instead |
475 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
475 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | |
@@ -482,10 +482,10 @@ discard block |
||
482 | 482 | * @param string $messenger_name |
483 | 483 | * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive |
484 | 484 | */ |
485 | - public function ensure_messenger_is_active( $messenger_name ) { |
|
485 | + public function ensure_messenger_is_active($messenger_name) { |
|
486 | 486 | // EE_messages has been deprecated |
487 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
488 | - return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name ); |
|
487 | + $this->_class_is_deprecated(__FUNCTION__); |
|
488 | + return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | |
@@ -497,10 +497,10 @@ discard block |
||
497 | 497 | * @return bool true if it got activated (or was active) and false if not. |
498 | 498 | * @throws \EE_Error |
499 | 499 | */ |
500 | - public function ensure_message_type_is_active( $message_type, $messenger ) { |
|
500 | + public function ensure_message_type_is_active($message_type, $messenger) { |
|
501 | 501 | // EE_messages has been deprecated |
502 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
503 | - return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger ); |
|
502 | + $this->_class_is_deprecated(__FUNCTION__); |
|
503 | + return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | |
@@ -513,10 +513,10 @@ discard block |
||
513 | 513 | * they are already setup.) |
514 | 514 | * @return boolean an array of generated templates or false if nothing generated/activated. |
515 | 515 | */ |
516 | - public function activate_messenger( $messenger_name, $mts_to_activate = array() ) { |
|
516 | + public function activate_messenger($messenger_name, $mts_to_activate = array()) { |
|
517 | 517 | // EE_messages has been deprecated |
518 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
519 | - return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate ); |
|
518 | + $this->_class_is_deprecated(__FUNCTION__); |
|
519 | + return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | |
@@ -528,10 +528,10 @@ discard block |
||
528 | 528 | * |
529 | 529 | * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
530 | 530 | */ |
531 | - public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) { |
|
531 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) { |
|
532 | 532 | // EE_messages has been deprecated |
533 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
534 | - return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type ); |
|
533 | + $this->_class_is_deprecated(__FUNCTION__); |
|
534 | + return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | |
@@ -541,10 +541,10 @@ discard block |
||
541 | 541 | * @param string $messenger |
542 | 542 | * @return EE_messenger | null |
543 | 543 | */ |
544 | - public function get_messenger_if_active( $messenger ) { |
|
544 | + public function get_messenger_if_active($messenger) { |
|
545 | 545 | // EE_messages has been deprecated |
546 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
547 | - return $this->_message_resource_manager->get_active_messenger( $messenger ); |
|
546 | + $this->_class_is_deprecated(__FUNCTION__); |
|
547 | + return $this->_message_resource_manager->get_active_messenger($messenger); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | |
@@ -565,9 +565,9 @@ discard block |
||
565 | 565 | * 'message_type' => null |
566 | 566 | * ) |
567 | 567 | */ |
568 | - public function validate_for_use( EE_Message $message ) { |
|
568 | + public function validate_for_use(EE_Message $message) { |
|
569 | 569 | // EE_messages has been deprecated |
570 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
570 | + $this->_class_is_deprecated(__FUNCTION__); |
|
571 | 571 | return array( |
572 | 572 | 'messenger' => $message->messenger_object(), |
573 | 573 | 'message_type' => $message->message_type_object(), |
@@ -595,41 +595,41 @@ discard block |
||
595 | 595 | $send = true |
596 | 596 | ) { |
597 | 597 | // EE_messages has been deprecated |
598 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
598 | + $this->_class_is_deprecated(__FUNCTION__); |
|
599 | 599 | /** @type EE_Messages_Processor $processor */ |
600 | - $processor = EE_Registry::instance()->load_lib( 'Messages_Processor' ); |
|
600 | + $processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
601 | 601 | $error = false; |
602 | 602 | //try to intelligently determine what method we'll call based on the incoming data. |
603 | 603 | //if generating and sending are different then generate and send immediately. |
604 | - if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) { |
|
604 | + if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
605 | 605 | //in the legacy system, when generating and sending were different, that means all the |
606 | 606 | //vars are already in the request object. So let's just use that. |
607 | 607 | try { |
608 | 608 | /** @type EE_Message_To_Generate_From_Request $mtg */ |
609 | - $mtg = EE_Registry::instance()->load_lib( 'Message_To_Generate_From_Request' ); |
|
610 | - $processor->generate_and_send_now( $mtg ); |
|
611 | - } catch ( EE_Error $e ) { |
|
609 | + $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
610 | + $processor->generate_and_send_now($mtg); |
|
611 | + } catch (EE_Error $e) { |
|
612 | 612 | $error_msg = __( |
613 | 613 | 'Please note that a system message failed to send due to a technical issue.', |
614 | 614 | 'event_espresso' |
615 | 615 | ); |
616 | 616 | // add specific message for developers if WP_DEBUG in on |
617 | - $error_msg .= '||' . $e->getMessage(); |
|
618 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
617 | + $error_msg .= '||'.$e->getMessage(); |
|
618 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
619 | 619 | $error = true; |
620 | 620 | } |
621 | 621 | } else { |
622 | - $processor->generate_for_all_active_messengers( $type, $vars, $send ); |
|
622 | + $processor->generate_for_all_active_messengers($type, $vars, $send); |
|
623 | 623 | //let's find out if there were any errors and how many successfully were queued. |
624 | 624 | $count_errors = $processor->get_queue()->count_STS_in_queue( |
625 | - array( EEM_Message::status_failed, EEM_Message::status_debug_only ) |
|
625 | + array(EEM_Message::status_failed, EEM_Message::status_debug_only) |
|
626 | 626 | ); |
627 | - $count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete ); |
|
628 | - $count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry ); |
|
627 | + $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete); |
|
628 | + $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry); |
|
629 | 629 | $count_errors = $count_errors + $count_retry; |
630 | - if ( $count_errors > 0 ) { |
|
630 | + if ($count_errors > 0) { |
|
631 | 631 | $error = true; |
632 | - if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1 ) { |
|
632 | + if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) { |
|
633 | 633 | $message = sprintf( |
634 | 634 | __( |
635 | 635 | 'There were %d errors and %d messages successfully queued for generation and sending', |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | $count_errors, |
639 | 639 | $count_queued |
640 | 640 | ); |
641 | - } elseif ( $count_errors > 1 && $count_queued === 1 ) { |
|
641 | + } elseif ($count_errors > 1 && $count_queued === 1) { |
|
642 | 642 | $message = sprintf( |
643 | 643 | __( |
644 | 644 | 'There were %d errors and %d message successfully queued for generation.', |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | $count_errors, |
648 | 648 | $count_queued |
649 | 649 | ); |
650 | - } elseif ( $count_errors === 1 && $count_queued > 1 ) { |
|
650 | + } elseif ($count_errors === 1 && $count_queued > 1) { |
|
651 | 651 | $message = sprintf( |
652 | 652 | __( |
653 | 653 | 'There was %d error and %d messages successfully queued for generation.', |
@@ -665,9 +665,9 @@ discard block |
||
665 | 665 | $count_errors |
666 | 666 | ); |
667 | 667 | } |
668 | - EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ ); |
|
668 | + EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__); |
|
669 | 669 | } else { |
670 | - if ( $count_queued === 1 ) { |
|
670 | + if ($count_queued === 1) { |
|
671 | 671 | $message = sprintf( |
672 | 672 | __( |
673 | 673 | '%d message successfully queued for generation.', |
@@ -684,18 +684,18 @@ discard block |
||
684 | 684 | $count_queued |
685 | 685 | ); |
686 | 686 | } |
687 | - EE_Error::add_success( $message ); |
|
687 | + EE_Error::add_success($message); |
|
688 | 688 | } |
689 | 689 | } |
690 | 690 | //if no error then return the generated message(s). |
691 | - if ( ! $error && ! $send ) { |
|
692 | - $generated_queue = $processor->generate_queue( false ); |
|
691 | + if ( ! $error && ! $send) { |
|
692 | + $generated_queue = $processor->generate_queue(false); |
|
693 | 693 | //get message and return. |
694 | 694 | $generated_queue->get_message_repository()->rewind(); |
695 | 695 | $messages = array(); |
696 | - while ( $generated_queue->get_message_repository()->valid() ) { |
|
696 | + while ($generated_queue->get_message_repository()->valid()) { |
|
697 | 697 | $message = $generated_queue->get_message_repository()->current(); |
698 | - if ( $message instanceof EE_Message ) { |
|
698 | + if ($message instanceof EE_Message) { |
|
699 | 699 | //set properties that might be expected by add-ons (backward compat) |
700 | 700 | $message->content = $message->content(); |
701 | 701 | $message->template_pack = $message->get_template_pack(); |
@@ -720,10 +720,10 @@ discard block |
||
720 | 720 | * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular preview |
721 | 721 | * @return string The body of the message. |
722 | 722 | */ |
723 | - public function preview_message( $type, $context, $messenger, $send = false ) { |
|
723 | + public function preview_message($type, $context, $messenger, $send = false) { |
|
724 | 724 | // EE_messages has been deprecated |
725 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
726 | - return EED_Messages::preview_message( $type, $context, $messenger, $send ); |
|
725 | + $this->_class_is_deprecated(__FUNCTION__); |
|
726 | + return EED_Messages::preview_message($type, $context, $messenger, $send); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | |
@@ -737,14 +737,14 @@ discard block |
||
737 | 737 | * |
738 | 738 | * @return bool success or fail. |
739 | 739 | */ |
740 | - public function send_message_with_messenger_only( $messenger, $message_type, $message ) { |
|
740 | + public function send_message_with_messenger_only($messenger, $message_type, $message) { |
|
741 | 741 | // EE_messages has been deprecated |
742 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
742 | + $this->_class_is_deprecated(__FUNCTION__); |
|
743 | 743 | //setup for sending to new method. |
744 | 744 | /** @type EE_Messages_Queue $queue */ |
745 | - $queue = EE_Registry::instance()->load_lib( 'Messages_Queue' ); |
|
745 | + $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
|
746 | 746 | //make sure we have a proper message object |
747 | - if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) { |
|
747 | + if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
748 | 748 | $msg = EE_Message_Factory::create( |
749 | 749 | array( |
750 | 750 | 'MSG_messenger' => $messenger, |
@@ -756,15 +756,15 @@ discard block |
||
756 | 756 | } else { |
757 | 757 | $msg = $message; |
758 | 758 | } |
759 | - if ( ! $msg instanceof EE_Message ) { |
|
759 | + if ( ! $msg instanceof EE_Message) { |
|
760 | 760 | return false; |
761 | 761 | } |
762 | 762 | //make sure any content in a content property (if not empty) is set on the MSG_content. |
763 | - if ( ! empty( $msg->content ) ) { |
|
764 | - $msg->set( 'MSG_content', $msg->content ); |
|
763 | + if ( ! empty($msg->content)) { |
|
764 | + $msg->set('MSG_content', $msg->content); |
|
765 | 765 | } |
766 | - $queue->add( $msg ); |
|
767 | - return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue ); |
|
766 | + $queue->add($msg); |
|
767 | + return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | |
@@ -778,11 +778,11 @@ discard block |
||
778 | 778 | * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned. |
779 | 779 | * @throws \EE_Error |
780 | 780 | */ |
781 | - public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) { |
|
781 | + public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) { |
|
782 | 782 | // EE_messages has been deprecated |
783 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
784 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
785 | - return EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $is_global ); |
|
783 | + $this->_class_is_deprecated(__FUNCTION__); |
|
784 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
785 | + return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | |
@@ -793,11 +793,11 @@ discard block |
||
793 | 793 | * @param string $message_type_name name of EE_message_type |
794 | 794 | * @return array |
795 | 795 | */ |
796 | - public function get_fields( $messenger_name, $message_type_name ) { |
|
796 | + public function get_fields($messenger_name, $message_type_name) { |
|
797 | 797 | // EE_messages has been deprecated |
798 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
799 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
800 | - return EEH_MSG_Template::get_fields( $messenger_name, $message_type_name ); |
|
798 | + $this->_class_is_deprecated(__FUNCTION__); |
|
799 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
800 | + return EEH_MSG_Template::get_fields($messenger_name, $message_type_name); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | |
@@ -811,13 +811,13 @@ discard block |
||
811 | 811 | * @return array multidimensional array of messenger and message_type objects |
812 | 812 | * (messengers index, and message_type index); |
813 | 813 | */ |
814 | - public function get_installed( $type = 'all', $skip_cache = false ) { |
|
814 | + public function get_installed($type = 'all', $skip_cache = false) { |
|
815 | 815 | // EE_messages has been deprecated |
816 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
817 | - if ( $skip_cache ) { |
|
816 | + $this->_class_is_deprecated(__FUNCTION__); |
|
817 | + if ($skip_cache) { |
|
818 | 818 | $this->_message_resource_manager->reset_active_messengers_and_message_types(); |
819 | 819 | } |
820 | - switch ( $type ) { |
|
820 | + switch ($type) { |
|
821 | 821 | case 'messengers' : |
822 | 822 | return array( |
823 | 823 | 'messenger' => $this->_message_resource_manager->installed_messengers(), |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | */ |
847 | 847 | public function get_active_messengers() { |
848 | 848 | // EE_messages has been deprecated |
849 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
849 | + $this->_class_is_deprecated(__FUNCTION__); |
|
850 | 850 | return $this->_message_resource_manager->active_messengers(); |
851 | 851 | } |
852 | 852 | |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | */ |
859 | 859 | public function get_active_message_types() { |
860 | 860 | // EE_messages has been deprecated |
861 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
861 | + $this->_class_is_deprecated(__FUNCTION__); |
|
862 | 862 | return $this->_message_resource_manager->list_of_active_message_types(); |
863 | 863 | } |
864 | 864 | |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | */ |
871 | 871 | public function get_active_message_type_objects() { |
872 | 872 | // EE_messages has been deprecated |
873 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
873 | + $this->_class_is_deprecated(__FUNCTION__); |
|
874 | 874 | return $this->_message_resource_manager->get_active_message_type_objects(); |
875 | 875 | } |
876 | 876 | |
@@ -882,10 +882,10 @@ discard block |
||
882 | 882 | * @param string $messenger The messenger being checked |
883 | 883 | * @return EE_message_type[] (or empty array if none present) |
884 | 884 | */ |
885 | - public function get_active_message_types_per_messenger( $messenger ) { |
|
885 | + public function get_active_message_types_per_messenger($messenger) { |
|
886 | 886 | // EE_messages has been deprecated |
887 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
888 | - return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger ); |
|
887 | + $this->_class_is_deprecated(__FUNCTION__); |
|
888 | + return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | |
@@ -896,10 +896,10 @@ discard block |
||
896 | 896 | * @param string $message_type The string should correspond to a message type. |
897 | 897 | * @return EE_message_type|null |
898 | 898 | */ |
899 | - public function get_active_message_type( $messenger, $message_type ) { |
|
899 | + public function get_active_message_type($messenger, $message_type) { |
|
900 | 900 | // EE_messages has been deprecated |
901 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
902 | - return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type ); |
|
901 | + $this->_class_is_deprecated(__FUNCTION__); |
|
902 | + return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | */ |
911 | 911 | public function get_installed_message_types() { |
912 | 912 | // EE_messages has been deprecated |
913 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
913 | + $this->_class_is_deprecated(__FUNCTION__); |
|
914 | 914 | return $this->_message_resource_manager->installed_message_types(); |
915 | 915 | } |
916 | 916 | |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | */ |
923 | 923 | public function get_installed_messengers() { |
924 | 924 | // EE_messages has been deprecated |
925 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
925 | + $this->_class_is_deprecated(__FUNCTION__); |
|
926 | 926 | return $this->_message_resource_manager->installed_messengers(); |
927 | 927 | } |
928 | 928 | |
@@ -933,10 +933,10 @@ discard block |
||
933 | 933 | * @param bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by message type. |
934 | 934 | * @return array |
935 | 935 | */ |
936 | - public function get_all_contexts( $slugs_only = true ) { |
|
936 | + public function get_all_contexts($slugs_only = true) { |
|
937 | 937 | // EE_messages has been deprecated |
938 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
939 | - return $this->_message_resource_manager->get_all_contexts( $slugs_only ); |
|
938 | + $this->_class_is_deprecated(__FUNCTION__); |
|
939 | + return $this->_message_resource_manager->get_all_contexts($slugs_only); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | |
@@ -995,7 +995,7 @@ discard block |
||
995 | 995 | add_filter( |
996 | 996 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
997 | 997 | function($event_list_iframe_css) { |
998 | - if ( ! has_filter( 'FHEE__EventsArchiveIframe__event_list_iframe__css' )) { |
|
998 | + if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
999 | 999 | return $event_list_iframe_css; |
1000 | 1000 | } |
1001 | 1001 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | add_filter( |
1016 | 1016 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
1017 | 1017 | function($event_list_iframe_js) { |
1018 | - if ( ! has_filter( 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js' )) { |
|
1018 | + if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
1019 | 1019 | return $event_list_iframe_js; |
1020 | 1020 | } |
1021 | 1021 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | add_action( |
1036 | 1036 | 'AHEE__EE_Capabilities__addCaps__complete', |
1037 | 1037 | function($capabilities_map) { |
1038 | - if ( ! has_action( 'AHEE__EE_Capabilities__init_role_caps__complete' )) { |
|
1038 | + if ( ! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) { |
|
1039 | 1039 | return; |
1040 | 1040 | } |
1041 | 1041 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1055,7 +1055,7 @@ discard block |
||
1055 | 1055 | add_filter( |
1056 | 1056 | 'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee', |
1057 | 1057 | function($existing_attendee, $registration, $attendee_data) { |
1058 | - if ( ! has_filter( 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee' )) { |
|
1058 | + if ( ! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) { |
|
1059 | 1059 | return $existing_attendee; |
1060 | 1060 | } |
1061 | 1061 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1071,7 +1071,7 @@ discard block |
||
1071 | 1071 | $existing_attendee, $registration, $attendee_data |
1072 | 1072 | ); |
1073 | 1073 | }, |
1074 | - 10,3 |
|
1074 | + 10, 3 |
|
1075 | 1075 | ); |
1076 | 1076 | |
1077 | 1077 | /** |
@@ -1135,7 +1135,7 @@ discard block |
||
1135 | 1135 | */ |
1136 | 1136 | public function event_list_title($event_list_title = '') |
1137 | 1137 | { |
1138 | - if (! empty($this->title)) { |
|
1138 | + if ( ! empty($this->title)) { |
|
1139 | 1139 | return $this->title; |
1140 | 1140 | } |
1141 | 1141 | return $event_list_title; |